ADD DM9051 ETHERNET DRIVER
Subsystems (3)
v12 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 | 31 + drivers/net/ethernet/davicom/Makefile | 1 + drivers/net/ethernet/davicom/dm9051.c | 1180 +++++++++++++++++ drivers/net/ethernet/davicom/dm9051.h | 159 +++ 5 files changed, 1433 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 v12 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 v12 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.
v9
use phylib, no need 'select MII' in Kconfig, make it clear in dm9051_xfer when using spi_sync, improve the registers read/write so that error code return as far as possible up the call stack.
v10
use regmap APIs for SPI and MDIO,
modify to correcting such as include header files
and program check styles
v11
eliminate the redundant code for struct regmap_config data use regmap_read_poll_timeout
use corresponding regmap APIs, i.e. MDIO, SPI
all read/write registers by regmap
all read/write registers with mutex lock by regmap
problem: regmap MDIO and SPI has no .reg_update_bits, I write it in the driver
problem: this chip can support bulk read/write to rx/tx data, but can not support bulk read/write to continue registers, so need read/write register one by one
v12
correctly use regmap bulk read/write/update_bits APIs use mdiobus to work to phylib and to this driver fine tune to arrange the source code to better usage
--- drivers/net/ethernet/davicom/Kconfig | 31 + drivers/net/ethernet/davicom/Makefile | 1 + drivers/net/ethernet/davicom/dm9051.c | 1180 +++++++++++++++++++++++++ drivers/net/ethernet/davicom/dm9051.h | 159 ++++ 4 files changed, 1371 insertions(+) create mode 100644 drivers/net/ethernet/davicom/dm9051.c create mode 100644 drivers/net/ethernet/davicom/dm9051.h
drivers/net/ethernet/davicom/Kconfig +31 -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,21 @@ 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" + depends on SPI + select CRC32 + select MDIO + select PHYLIB + select REGMAP_SPI + 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 +1180 -0
1,180 lines not on this page · raw message
drivers/net/ethernet/davicom/dm9051.h new file +159 -0
159 lines not on this page · raw message
Signature · 1 line
2.20.1
kernel test robot
build botRe: [PATCH v12, 2/2] net: Add dm9051 driver
Thank you for the patch! Perhaps something to improve:
Hi Joseph,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on 9d922f5df53844228b9f7c62f2593f4f06c0b69b]
url: https://github.com/0day-ci/linux/commits/Joseph-CHAMG/ADD-DM9051-ETHERNET-DRIVER/20220121-121713 base: 9d922f5df53844228b9f7c62f2593f4f06c0b69b config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20220121/202201211441.KTN0V72X-lkp(a)intel.com/config) compiler: alpha-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/a6eb8dd02aed17af37a0b38fbcc250fd9ed9492d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Joseph-CHAMG/ADD-DM9051-ETHERNET-DRIVER/20220121-121713
git checkout a6eb8dd02aed17af37a0b38fbcc250fd9ed9492d
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=alpha SHELL=/bin/bash drivers/net/ethernet/davicom/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
drivers/net/ethernet/davicom/dm9051.c: In function 'dm9051_mdiobus_register':
>> drivers/net/ethernet/davicom/dm9051.c:1076:33: warning: conversion from 'long unsigned int' to 'u32' {aka 'unsigned int'} changes value from '18446744073709551613' to '4294967293' [-Woverflow]
1076 | db->mdiobus->phy_mask = ~GENMASK(1, 1);
| ^vim +1076 drivers/net/ethernet/davicom/dm9051.c
1062
1063 static int dm9051_mdiobus_register(struct board_info *db)
1064 {
1065 struct spi_device *spi = db->spidev;
1066 int ret;
1067
1068 db->mdiobus = devm_mdiobus_alloc(&spi->dev);
1069 if (!db->mdiobus)
1070 return -ENOMEM;
1071
1072 db->mdiobus->priv = db;
1073 db->mdiobus->read = dm9051_mdiobus_read;
1074 db->mdiobus->write = dm9051_mdiobus_write;
1075 db->mdiobus->name = "dm9051-mdiobus";
> 1076 db->mdiobus->phy_mask = ~GENMASK(1, 1);
1077 db->mdiobus->parent = &spi->dev;
1078 snprintf(db->mdiobus->id, MII_BUS_ID_SIZE,
1079 "dm9051-%s.%u", dev_name(&spi->dev), spi->chip_select);
1080
1081 ret = devm_mdiobus_register(&spi->dev, db->mdiobus);
1082 if (ret) {
1083 dev_err(&spi->dev, "Could not register MDIO bus\n");
1084 return ret;
1085 }
1086 return 0;
1087 }
1088
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v12, 2/2] net: Add dm9051 driver
In reply to Joseph CHAMGThank you for the patch! Perhaps something to improve:
Hi Joseph,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on 9d922f5df53844228b9f7c62f2593f4f06c0b69b]
url: https://github.com/0day-ci/linux/commits/Joseph-CHAMG/ADD-DM9051-ETHERNET-DRIVER/20220121-121713 base: 9d922f5df53844228b9f7c62f2593f4f06c0b69b config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20220121/202201211736.UtU0eL2j-lkp(a)intel.com/config) compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project d4baf3b1322b84816aa623d8e8cb45a49cb68b84)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/a6eb8dd02aed17af37a0b38fbcc250fd9ed9492d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Joseph-CHAMG/ADD-DM9051-ETHERNET-DRIVER/20220121-121713
git checkout a6eb8dd02aed17af37a0b38fbcc250fd9ed9492d
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/net/ethernet/davicom/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/net/ethernet/davicom/dm9051.c:1076:26: warning: implicit conversion from 'unsigned long' to 'u32' (aka 'unsigned int') changes value from 18446744073709551613 to 4294967293 [-Wconstant-conversion]
db->mdiobus->phy_mask = ~GENMASK(1, 1);
~ ^~~~~~~~~~~~~~1 warning generated.
vim +1076 drivers/net/ethernet/davicom/dm9051.c
1062
1063 static int dm9051_mdiobus_register(struct board_info *db)
1064 {
1065 struct spi_device *spi = db->spidev;
1066 int ret;
1067
1068 db->mdiobus = devm_mdiobus_alloc(&spi->dev);
1069 if (!db->mdiobus)
1070 return -ENOMEM;
1071
1072 db->mdiobus->priv = db;
1073 db->mdiobus->read = dm9051_mdiobus_read;
1074 db->mdiobus->write = dm9051_mdiobus_write;
1075 db->mdiobus->name = "dm9051-mdiobus";
> 1076 db->mdiobus->phy_mask = ~GENMASK(1, 1);
1077 db->mdiobus->parent = &spi->dev;
1078 snprintf(db->mdiobus->id, MII_BUS_ID_SIZE,
1079 "dm9051-%s.%u", dev_name(&spi->dev), spi->chip_select);
1080
1081 ret = devm_mdiobus_register(&spi->dev, db->mdiobus);
1082 if (ret) {
1083 dev_err(&spi->dev, "Could not register MDIO bus\n");
1084 return ret;
1085 }
1086 return 0;
1087 }
1088
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v12, 2/2] net: Add dm9051 driver
In reply to Joseph CHAMGQuoted 77 lines · Joseph CHAMG
v1-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 supportTested 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 usenetif_rx_ni.simplely queue init and wake the queues, limit the
start_xmitfunction usenetif_stop_queue.descript that schedule delay is essential
fortx_workandrxctrl_workeliminate
____cacheline_alignedand
add static intmsg_enable.v9
use phylib, no need 'select MII' in
Kconfig, make it clear indm9051_xferwhen usingspi_sync, improve the registers read/write so that error code return as far as possible up the call stack.v10
use regmap APIs for SPI and MDIO,
modify to correcting such as include header files
and program check stylesv11
eliminate the redundant code for struct
regmap_configdata useregmap_read_poll_timeout
use corresponding regmap APIs, i.e. MDIO, SPI
all read/write registers by regmap
all read/write registers with mutex lock by regmap
problem: regmap MDIO and SPI has no .reg_update_bits, I write it in the driver
problem: this chip can support bulk read/write to rx/tx data, but can not support bulk read/write to continue registers, so need read/write register one by one
Quoted 5 lines
v12
correctly use regmap bulk read/write/update_bits APIs use mdiobus to work to phylib and to this driver fine tune to arrange the source code to better usage
This is not tagged properly. Also, I specifically removed everything else to point out, please, read finally the article [1] and write a proper commit message. And move changelog under the cutter '--- ' line. Without doing these two things nobody can do anything with your contribution.
[1]: https://cbea.ms/git-commit/
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v12, 2/2] net: Add dm9051 driver
Quoted 1 line · Andy Shevchenko
On Fri, Jan 21, 2022 at 6:15 AM Joseph CHAMG <[email protected]> wrote:
...
Quoted 9 lines
Quoted 3 lines
correctly use regmap bulk read/write/update_bits APIs use mdiobus to work to phylib and to this driver fine tune to arrange the source code to better usage
This is not tagged properly. Also, I specifically removed everything else to point out, please, read finally the article [1] and write a proper commit message. And move changelog under the cutter '--- ' line. Without doing these two things nobody can do anything with your contribution.
Next comment, remove all those unlickely() calls. Otherwise you have to justify their appearance.
Quoted 1 line
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v12, 2/2] net: Add dm9051 driver
In reply to Joseph CHAMGdrivers/net/ethernet/davicom/dm9051.c line 232
Quoted 7 lines
drivers/net/ethernet/davicom/dm9051.c new file +6
-0+static int ctrl_dm9051_phywrite (void *context,unsigned int reg,unsigned int val) +{ +/* chip internal operation need wait 1 ms for if power-up phy +*/ +if (reg ==MII_BMCR && !(val &BMCR_PDOWN )) +mdelay (1 );
What PHY driver are you using? It would be much better to have this in the PHY driver. The MAC driver should not be touching the PHY.
drivers/net/ethernet/davicom/dm9051.c line 424
Quoted 11 lines
drivers/net/ethernet/davicom/dm9051.c new file +11
-0+static int dm9051_phy_connect (struct board_info *db) +{ +char phy_id[MII_BUS_ID_SIZE +3 ]; + +snprintf (phy_id,MII_BUS_ID_SIZE +3 ,PHY_ID_FMT , + db->mdiobus->id,DM9051_PHY_ID ); + + db->phydev =phy_connect (db->ndev, phy_id, dm9051_handle_link_change, +PHY_INTERFACE_MODE_MII ); +if (IS_ERR (db->phydev)) +return PTR_ERR_OR_ZERO (db->phydev);
Why PTR_ERR_OR_ZERO()
drivers/net/ethernet/davicom/dm9051.c line 575
Quoted 4 lines
drivers/net/ethernet/davicom/dm9051.c new file +4
-0+static int dm9051_direct_fifo_reset (struct board_info *db) +{ +struct net_device *ndev = db->ndev; +int rxlen =le16_to_cpu (db->eth_rxhdr.rxlen);
reverse christmas tree. There are a few more cases. Please review the whole driver.
drivers/net/ethernet/davicom/dm9051.c line 699
Quoted 13 lines
drivers/net/ethernet/davicom/dm9051.c new file +13
-0+/* transmit a packet, +* return value, +* 0 - succeed +* -ETIMEDOUT - timeout error +*/ +static int dm9051_single_tx (struct board_info *db,u8 *buff,unsigned int len) +{ +int ret; + + ret =dm9051_map_xmitpoll (db); +if (ret) +return -ETIMEDOUT ; +
If dm9051_map_xmitpoll() returns an error code, use it. There needs to be a good reason to change the error code, and if you have such a good reason, please add a comment about it.
drivers/net/ethernet/davicom/dm9051.c line 746
Quoted 6 lines
drivers/net/ethernet/davicom/dm9051.c new file +6
-0+static irqreturn_t dm9051_rx_threaded_irq (int irq,void *pw) +{ +struct board_info *db = pw; +int result, resul_tx; + +mutex_lock (&db->spi_lockm);/* mutex essential */
When are mutex's not essential? This commit seems to be meaningless. It gives the impression you don't understand mutex's and locking in general. You have just added mutex until it seems to work, not that you have a locking design.
drivers/net/ethernet/davicom/dm9051.c line 757
Quoted 11 lines
drivers/net/ethernet/davicom/dm9051.c new file +11
-0+if (netif_carrier_ok (db->ndev)) { + result =regmap_write (db->regmap_dm,DM9051_IMR ,IMR_PAR );/* disable imr */ +if (unlikely (result)) + goto spi_err; + + do { + result = dm9051_loop_rx(db); /* threaded irq rx */ + if (result < 0) + goto spi_err; + resul_tx = dm9051_loop_tx(db); /* more tx better performance */ + if (resul_tx < 0)
result_tx
^
Quoted 19 lines
drivers/net/ethernet/davicom/dm9051.c new file +17
-0+ goto spi_err; + }while (result >0 ); + + result =regmap_write (db->regmap_dm,DM9051_IMR , db->imr_all);/* enable imr */ +if (unlikely (result)) + goto spi_err; + } +spi_err: +mutex_unlock (&db->spi_lockm);/* mutex essential */ +return IRQ_HANDLED ; +} +static int dm9051_map_phyup (struct board_info *db) +{ +int ret; + +/* ~BMCR_PDOWN to power-up phyxcer +*/
drivers/net/ethernet/davicom/dm9051.c line 825
Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.c new file +10
-0+ ret =mdiobus_modify (db->mdiobus,DM9051_PHY_ID ,MII_BMCR ,BMCR_PDOWN ,0 ); +if (ret <0 ) +return ret; + +/* chip internal operation need wait 1 ms for if GPR power-up phy +*/ + ret =regmap_write (db->regmap_dm,DM9051_GPR ,0 ); +if (unlikely (ret)) +return ret; +mdelay (1 );
The phy driver should do this. Again, what PHY driver are you using?
drivers/net/ethernet/davicom/dm9051.c line 838
Quoted 9 lines
drivers/net/ethernet/davicom/dm9051.c new file +9
-0+static int dm9051_map_phydown (struct board_info *db) +{ +int ret; + + ret =regmap_write (db->regmap_dm,DM9051_GPR ,GPR_PHY_ON );/* Power-Down PHY */ +if (unlikely (ret)) +return ret; +return ret; +}
Cam you still access the PHY after this? Does it loose its configuration?
drivers/net/ethernet/davicom/dm9051.c line 903
Quoted 4 lines
drivers/net/ethernet/davicom/dm9051.c new file +4
-0+/* We may have start with auto negotiation */ + db->phydev->autoneg =AUTONEG_ENABLE ; + db->phydev->speed =0 ; + db->phydev->duplex =0 ;
If you have to touch these, something is wrong. Please explain.
Andrew