Skip to contentSkip to conversation

ADD DM9051 ETHERNET DRIVER

PATCH Superseded Joseph CHAMG 4 participants 6 messages Jan 25, 2022 – Feb 1, 2022

Subsystems (3)

v13 of 20 Superseded Latest is v20 →

lore
Share & tools
lore
#0 lore raw

v13 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         | 1182 +++++++++++++++++
 drivers/net/ethernet/davicom/dm9051.h         |  159 +++
 5 files changed, 1435 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
#1 lore raw

PATCH v13 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
new file mode 100644
index 000000000000..52e852fef753
@@ -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
#3 lore raw

PATCH v13 2/2 net: Add dm9051 driver

In reply to Joseph CHAMG

Add davicom dm9051 spi ethernet driver. The driver work for the device platform with spi master

Cc Jakub Kicinski <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc andy Shevchenko <[email protected]>

---

v1-v4

Test ok with raspberry pi 2 and pi 4

v5

swapped to phylib for phy connection tasks

v6

remove the redundant code that phylib has support

v7

read/write registers must return error code to the caller

v8

not parmanently set MAC by .ndo_set_mac_address

v9

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

v11

use regmap_read_poll_timeout
use corresponding regmap APIs, i.e. SPI, MDIO

v12

use mdiobus API instead of regmap MDIO APIs

v13

Simply all regmap APIs return value checked
Clear the fifo reset report
Eliminate redundant comments

Comment that DM9051_GPR register bit 0 function for power-up the internal phy, if this bit is updated from 1 to 0, then the whole dm9051 chip registers could not be accessed within 1 ms, so that has mdelay(1) to wait 1 ms

 drivers/net/ethernet/davicom/Kconfig  |   31 +
 drivers/net/ethernet/davicom/Makefile |    1 +
 drivers/net/ethernet/davicom/dm9051.c | 1182 +++++++++++++++++++++++++
 drivers/net/ethernet/davicom/dm9051.h |  159 ++++
 4 files changed, 1373 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
index 7af86b6d4150..02e0caff98e3 100644
@@ -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
index 173c87d21076..225f85bc1f53 100644
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_DM9000) += dm9000.o
+obj-$(CONFIG_DM9051) += dm9051.o
drivers/net/ethernet/davicom/dm9051.c new file +1182 -0

1,182 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
#4 lore raw

Re: [PATCH v13, 2/2] net: Add dm9051 driver

drivers/net/ethernet/davicom/dm9051.c line 238

Quoted 7 lines
drivers/net/ethernet/davicom/dm9051.c new file +7 -0
+static int dm9051_mdiobus_read(struct mii_bus *mdiobus, int phy_id, int reg)
+{
+	struct board_info *db = mdiobus->priv;
+	unsigned int val = 0;
+	int ret;
+
+	if (phy_id == DM9051_PHY_ID) {

phy_id is a poor choice of name. It normally means the value you find in register 2 and 3 of the PHY which identifies the manufacture, make and possibly revision.

If you look at the read function prototype in struct mii_bus:

https://elixir.bootlin.com/linux/v5.17-rc1/source/include/linux/phy.h#L357

the normal name is addr.

Ideally your driver needs to look similar to other drivers. Ideally you use the same variable names for the same things. That makes it easier for somebody else to read your driver and debug it. It makes it easier to review, etc. It is worth spending time reading a few other drivers and looking for common patterns, and making use of those patterns in your driver.

drivers/net/ethernet/davicom/dm9051.c line 815

Quoted 9 lines
drivers/net/ethernet/davicom/dm9051.c new file +9 -0
+static int dm9051_map_phyup(struct board_info *db)
+{
+	int ret;
+
+	/* ~BMCR_PDOWN to power-up the internal phy
+	 */
+	ret = mdiobus_modify(db->mdiobus, DM9051_PHY_ID, MII_BMCR, BMCR_PDOWN, 0);
+	if (ret < 0)
+		return ret;

You are still touching PHY registers from the MAC driver. Why is your PHY driver not going this as part of the _config() function?

Andrew

#5 lore raw

Re: [PATCH v13, 2/2] net: Add dm9051 driver

In reply to Joseph CHAMG
Quoted 3 lines · Joseph CHAMG

Add davicom dm9051 spi ethernet driver. The driver work for the device platform with spi master

This is better, but please use a grammar period as well.

Quoted 4 lines
Cc Jakub Kicinski <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc andy Shevchenko <[email protected]>

Andy

And you may utilize --cc parameter to git send-email or move this Cc block behind the cutter '--- ' line.

...

drivers/net/ethernet/davicom/dm9051.c line 18

Quoted 12 lines
drivers/net/ethernet/davicom/dm9051.c new file +12 -0
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/mii.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/phy.h>
+#include <linux/regmap.h>
+#include <linux/skbuff.h>
+#include <linux/spinlock.h>
+#include <linux/spi/spi.h>

types.h is missing

...

Quoted 4 lines

+/**
+ * struct rx_ctl_mach - rx activities record

+ *

In all similar cases remove this blank line.

Quoted 6 lines

+ * @status_err_counter: rx status error counter
+ * @large_err_counter: rx get large packet length error counter
+ * @fifo_rst_counter: reset operation counter
+ *
+ * To keep track for the driver operation statistics
+ */

...

Quoted 9 lines

+/**
+ * struct dm9051_rxhdr - rx packet data header
+ *
+ * @rxpktready: lead byte is 0x01 tell a valid packet
+ * @rxstatus: status bits for the received packet
+ * @rxlen: packet length
+ *

+ * The rx packet enter into the fifo memory is start with these four

The Rx packed, entered into the FIFO memory, starts with

Quoted 1 line

+ * bytes which is the rx header, follow this header is the ethernet

Rx header, followed by the ethernet

Quoted 1 line

+ * packet data and end with a appended 4-byte CRC data.

ends
an appended

Quoted 3 lines

+ * Both rx packet and CRC data are for check purpose and finally are
+ * dropped by this driver
+ */

...

Quoted 1 line

+ * @kw_rxctrl: kernel thread worke structure for rx control

worker?

...

drivers/net/ethernet/davicom/dm9051.c line 116

Quoted 4 lines
drivers/net/ethernet/davicom/dm9051.c new file +4 -0
+       int ret = regmap_read_poll_timeout(db->regmap_dm, DM9051_NSR, mval,
+                                          mval & (NSR_TX2END | NSR_TX1END), 1, 20);
+
+       if (ret)

Please, split the assignment and get it closer to its user, so

int ret;

ret = ...
if (ret)

This applies to all similar cases.

Actually all comments are against the entire code even if it's given only for one occurrence of the similar code block.

Quoted 3 lines
drivers/net/ethernet/davicom/dm9051.c new file +3 -0
+               netdev_err(db->ndev, "timeout in checking for tx ends\n");
+       return ret;
+}

...

drivers/net/ethernet/davicom/dm9051.c line 151

Quoted 4 lines
drivers/net/ethernet/davicom/dm9051.c new file +4 -0
+       ret = regmap_bulk_read(db->regmap_dmbulk, DM9051_EPDRL, to, 2);
+       if (ret < 0)
+               return ret;
+       return ret;
  return regmap_...(...);

Same for other similar places.

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+       /* this is a 2 bytes data written via regmap_bulk_write
+        */

Useless comments.

...

drivers/net/ethernet/davicom/dm9051.c line 235

Quoted 5 lines
drivers/net/ethernet/davicom/dm9051.c new file +4 -0
+static int dm9051_mdiobus_read(struct mii_bus *mdiobus, int phy_id, int reg)
+{
+       struct board_info *db = mdiobus->priv;
 
+       unsigned int val = 0;

You can do

  val = 0xffff;

here...

drivers/net/ethernet/davicom/dm9051.c line 244

Quoted 10 lines
drivers/net/ethernet/davicom/dm9051.c new file +9 -0
+       int ret;
+
+       if (phy_id == DM9051_PHY_ID) {
+               ret = ctrl_dm9051_phyread(db, reg, &val);
+               if (ret)
+                       return ret;
 
+               return val;
+       }
+       return 0xffff;

...and

  }
  return val;

here.

drivers/net/ethernet/davicom/dm9051.c line 273

Quoted 4 lines
drivers/net/ethernet/davicom/dm9051.c new file +2 -0
+}
 
 
+       while (count--) {

If the count is guaranteed to be greater than 0, it would be better to use

  do {
    ...
  } while (--count);
Quoted 9 lines
drivers/net/ethernet/davicom/dm9051.c new file +9 -0
+               ret = regmap_read(db->regmap_dm, reg, &rb);
+               if (ret) {
+                       netif_err(db, drv, ndev, "%s: error %d dumping read reg %02x\n",
+                                 __func__, ret, reg);
+                       break;
+               }
+       }
+       return ret;
+}

...

drivers/net/ethernet/davicom/dm9051.h line 10

Quoted 4 lines
drivers/net/ethernet/davicom/dm9051.h new file +4 -0
+#ifndef _DM9051_H_
+#define _DM9051_H_
+
+#include <linux/bitfield.h>

There is no user of this header, but missing bits.h and one that provides netdev_priv().

...

Quoted 1 line

+#define DRVNAME_9051 "dm9051"

Why is this in the header?

--
With Best Regards,
Andy Shevchenko

maintainer
#2 lore raw

Re: [PATCH v13, 1/2] yaml: Add dm9051 SPI network yaml file

In reply to Joseph CHAMG
Quoted 1 line · Joseph CHAMG

From: JosephCHANG <[email protected]>

Follow the naming convention of the subsystem for the subject line (use 'git log --oneline'):

dt-bindings: net: Add Davicom dm9051 SPI ethernet controller

Quoted 83 lines

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
new file mode 100644
index 000000000000..52e852fef753
@@ -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