ADD DM9051 ETHERNET DRIVER
Subsystems (3)
v8 cover ADD DM9051 ETHERNET DRIVER
DM9051 is a spi interface chip,
need cs/mosi/miso/clock with an interrupt gpio pin
Joseph CHAMG (1):
net: Add dm9051 driver
JosephCHANG (1):
yaml: Add dm9051 SPI network yaml file
.../bindings/net/davicom,dm9051.yaml | 62 + drivers/net/ethernet/davicom/Kconfig | 30 + drivers/net/ethernet/davicom/Makefile | 1 + drivers/net/ethernet/davicom/dm9051.c | 1011 +++++++++++++++++ drivers/net/ethernet/davicom/dm9051.h | 190 ++++ 5 files changed, 1294 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/davicom,dm9051.yaml create mode 100644 drivers/net/ethernet/davicom/dm9051.c create mode 100644 drivers/net/ethernet/davicom/dm9051.h
base-commit: 9d922f5df53844228b9f7c62f2593f4f06c0b69b
Signature · 1 line
2.20.1
PATCH v8 1/2 yaml: Add dm9051 SPI network yaml file
From: JosephCHANG <[email protected]>
This is a new yaml base data file for configure davicom dm9051 with device tree
--- .../bindings/net/davicom,dm9051.yaml | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/davicom,dm9051.yaml
Documentation/devicetree/bindings/net/davicom,dm9051.yaml new file +62 -0
@@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/davicom,dm9051.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Davicom DM9051 SPI Ethernet Controller + +maintainers: + - Joseph CHANG <[email protected]> + +description: | + The DM9051 is a fully integrated and cost-effective low pin count single + chip Fast Ethernet controller with a Serial Peripheral Interface (SPI). + +allOf: + - $ref: ethernet-controller.yaml# + +properties: + compatible: + const: davicom,dm9051 + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 45000000 + + interrupts: + maxItems: 1 + + local-mac-address: true + + mac-address: true + +required: + - compatible + - reg + - spi-max-frequency + - interrupts + +additionalProperties: false + +examples: + # Raspberry Pi platform + - | + /* for Raspberry Pi with pin control stuff for GPIO irq */ + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/gpio/gpio.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + ethernet@0 { + compatible = "davicom,dm9051"; + reg = <0>; /* spi chip select */ + local-mac-address = [00 00 00 00 00 00]; + interrupt-parent = <&gpio>; + interrupts = <26 IRQ_TYPE_LEVEL_LOW>; + spi-max-frequency = <31200000>; + }; + };
Signature · 1 line
2.20.1
PATCH v8 2/2 net: Add dm9051 driver
In reply to Joseph CHAMGv1-v4
Add davicom dm9051 spi ethernet driver. The driver work for the device platform with spi master
Test ok with raspberry pi 2 and pi 4, the spi configure used in my raspberry pi 4 is spi0.1, spi speed 31200000, and INT by pin 26.
v5
Work to eliminate the wrappers to be clear for read, swapped to phylib for phy connection tasks.
Tested with raspberry pi 4. Test for netwroking function, CAT5 cable unplug/plug and also ethtool detect for link state, and all are ok.
v6
remove the redundant code that phylib has support, adjust to be the reasonable sequence,
fine tune comments, add comments for pause function support
Tested with raspberry pi 4. Test for netwroking function, CAT5 cable unplug/plug and also ethtool detect for link state, and all are ok.
v7
read/write registers must return error code to the callet, add to enable pause processing
v8
not parmanently set MAC by .ndo_set_mac_address
correct rx function such as clear ISR,
inblk avoid stack buffer,
simple skb buffer process and
easy use netif_rx_ni.
simplely queue init and wake the queues, limit the start_xmit function use netif_stop_queue.
descript that schedule delay is essential
for tx_work and rxctrl_work
eliminate ____cacheline_aligned and
add static int msg_enable.
--- drivers/net/ethernet/davicom/Kconfig | 30 + drivers/net/ethernet/davicom/Makefile | 1 + drivers/net/ethernet/davicom/dm9051.c | 1011 +++++++++++++++++++++++++ drivers/net/ethernet/davicom/dm9051.h | 190 +++++ 4 files changed, 1232 insertions(+) create mode 100644 drivers/net/ethernet/davicom/dm9051.c create mode 100644 drivers/net/ethernet/davicom/dm9051.h
drivers/net/ethernet/davicom/Kconfig +30 -0
@@ -3,6 +3,19 @@ # Davicom device configuration # +config NET_VENDOR_DAVICOM + bool "Davicom devices" + default y + help + If you have a network (Ethernet) card belonging to this class, say Y. + + Note that the answer to this question doesn't directly affect the + kernel: saying N will just cause the configurator to skip all + the questions about Davicom devices. If you say Y, you will be asked + for your specific card in the following selections. + +if NET_VENDOR_DAVICOM + config DM9000 tristate "DM9000 support" depends on ARM || MIPS || COLDFIRE || NIOS2 || COMPILE_TEST
@@ -22,3 +35,20 @@ config DM9000_FORCE_SIMPLE_PHY_POLL bit to determine if the link is up or down instead of the more costly MII PHY reads. Note, this will not work if the chip is operating with an external PHY. + +config DM9051 + tristate "DM9051 SPI support" + select PHYLIB + depends on SPI + select CRC32 + select MII + help + Support for DM9051 SPI chipset. + + To compile this driver as a module, choose M here. The module + will be called dm9051. + + The SPI mode for the host's SPI master to access DM9051 is mode + 0 on the SPI bus. + +endif # NET_VENDOR_DAVICOM
drivers/net/ethernet/davicom/Makefile +1 -0
@@ -4,3 +4,4 @@ # obj-$(CONFIG_DM9000) += dm9000.o +obj-$(CONFIG_DM9051) += dm9051.o
drivers/net/ethernet/davicom/dm9051.c new file +1011 -0
1,011 lines not on this page · raw message
drivers/net/ethernet/davicom/dm9051.h new file +190 -0
190 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v8, 2/2] net: Add dm9051 driver
drivers/net/ethernet/davicom/Kconfig config DM9000_FORCE_SIMPLE_PHY_POLL · line 44
Quoted 6 lines
drivers/net/ethernet/davicom/Kconfig +6
-0+config DM9051 + tristate "DM9051 SPI support" + select PHYLIB + depends on SPI + select CRC32 + select MII
Since you are using PHYLIB, you should not require MII.
Quoted 23 lines
+ */
drivers/net/ethernet/davicom/dm9051.c new file +22
-0+ +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/interrupt.h> +#include <linux/phy.h> +#include <linux/skbuff.h> +#include <linux/spinlock.h> +#include <linux/cache.h> +#include <linux/crc32.h> +#include <linux/mii.h> +#include <linux/ethtool.h> +#include <linux/delay.h> +#include <linux/irq.h> +#include <linux/slab.h> +#include <linux/gpio.h> +#include <linux/iopoll.h> +#include <linux/of_gpio.h> +#include <linux/spi/spi.h> + +#include "dm9051.h"
drivers/net/ethernet/davicom/dm9051.c line 37
Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.c new file +10
-0+ +static int msg_enable =NETIF_MSG_PROBE | +NETIF_MSG_LINK | +NETIF_MSG_IFDOWN | +NETIF_MSG_IFUP | +NETIF_MSG_RX_ERR | +NETIF_MSG_TX_ERR ; + +module_param (msg_enable, int,0 ); +MODULE_PARM_DESC (msg_enable,"Message mask bitmapped" );
No module parameters please. You have the need ethtool ops to control this.
drivers/net/ethernet/davicom/dm9051.c line 40
Quoted 3 lines
drivers/net/ethernet/davicom/dm9051.c new file +3
-0+ +/* spi low level code */ +static inline int dm9051_xfer (struct board_info *db,u8 cmd,u8 *txb,u8 *rxb,unsigned int len)
No inline functions in C code, let the compiler decide.
Quoted 7 lines
drivers/net/ethernet/davicom/dm9051.c new file +7
-0+{ +struct device *dev = &db->spidev->dev; +int ret; + + db->cmd[0 ] = cmd; + db->spi_xfer2[0 ].tx_buf = &db->cmd[0 ]; + db->spi_xfer2[0 ].rx_buf =NULL ;
drivers/net/ethernet/davicom/dm9051.c line 57
Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.c new file +10
-0+ db->spi_xfer2[0 ].len =1 ; +if (!rxb) { + db->spi_xfer2[1 ].tx_buf = txb; + db->spi_xfer2[1 ].rx_buf =NULL ; + db->spi_xfer2[1 ].len = len; + }else { + db->spi_xfer2[1 ].tx_buf = txb; + db->spi_xfer2[1 ].rx_buf = rxb; + db->spi_xfer2[1 ].len = len; + }
Nit pick, but i would invert the logic here, to make it more natural.
Quoted 4 lines
drivers/net/ethernet/davicom/dm9051.c new file +4
-0+ ret =spi_sync (db->spidev, &db->spi_msg); +if (ret <0 ) +dev_err (dev,"spi burst cmd 0x%02x, ret=%d\n" , cmd, ret); +return ret;
drivers/net/ethernet/davicom/dm9051.c line 71
Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.c new file +10
-0+} + +static u8 dm9051_ior (struct board_info *db,unsigned int reg) +{ +int ret; +u8 rxb[1 ]; + + ret =dm9051_xfer (db,DM_SPI_RD | reg,NULL , rxb,1 ); +if (ret <0 ) +return 0xff ;
No, return the error code which dm9051_xfer() returns.
drivers/net/ethernet/davicom/dm9051.c line 80
Quoted 9 lines
drivers/net/ethernet/davicom/dm9051.c new file +9
-0+return rxb[0 ]; +} + +static void dm9051_iow (struct board_info *db,unsigned int reg,unsigned int val) +{ +u8 txb[1 ]; + + txb[0 ] = val; +dm9051_xfer (db,DM_SPI_WR | reg, txb,NULL ,1 );
This should be an int function, which returns 0, or the error code which dm9051_xfer() returns.
Quoted 5 lines
drivers/net/ethernet/davicom/dm9051.c new file +5
-0+} + +static int dm9051_inblk (struct board_info *db,u8 *buff,unsigned int len) +{ +int ret;
drivers/net/ethernet/davicom/dm9051.c line 95
Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.c new file +10
-0+u8 txb[1 ]; + + ret =dm9051_xfer (db,DM_SPI_RD |DM_SPI_MRCMD , txb, buff, len); +return ret; +} + +static void dm9051_dumpblk (struct board_info *db,unsigned int len) +{ +while (len--) +dm9051_ior (db,DM_SPI_MRCMD );
and here you need to look for an error from dm9051_ior() and return it to the caller etc.
Quoted 5 lines
drivers/net/ethernet/davicom/dm9051.c new file +5
-0+static int dm9051_phy_read (struct board_info *db,int reg,int *pvalue) +{ +int ret; +u8 check_val; +
drivers/net/ethernet/davicom/dm9051.c line 119
Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.c new file +9
-0+dm9051_iow (db,DM9051_EPAR ,DM9051_PHY | reg); +dm9051_iow (db,DM9051_EPCR ,EPCR_ERPRR |EPCR_EPOS ); + ret =read_poll_timeout (dm9051_ior, check_val, !(check_val &EPCR_ERRE ),100 ,10000 , + true, db,DM9051_EPCR ); +dm9051_iow (db,DM9051_EPCR ,0x0 ); +if (ret) { +netdev_err (db->ndev,"timeout read phy register\n" ); +return -ETIMEDOUT ; + }
You should check for an error before doing the dm9051_iow(). And don't return -ETIMEDOUT, return whatever read_poll_timeout() returns as an error code.
Your error handling in this driver needs a lot of work. Please improve it for the next submission. Error codes need returning as far as possible up the call stack.
Andrew