Skip to contentSkip to conversation

net: emac: emac gigabit ethernet controller driver

PATCH In review Timur Tabi 9 participants 17 messages Aug 25, 2016 – Sep 1, 2016 5 messages not in the archive

Subsystems (5)
lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH v9 1/1 net: emac: emac gigabit ethernet controller driver

Add support for the Qualcomm Technologies, Inc. EMAC gigabit Ethernet controller.

This driver supports the following features:
1) Checksum offload.
2) Interrupt coalescing support.
3) SGMII phy.
4) phylib interface for external phy

Based on original work by
Niranjana Vishwanathapura <[email protected]> Gilad Avidov <[email protected]>

---

v9:
- Define a separate DT node for the internal phy
- Kconfig option now selects required PHYLIB
- Use netdev_alloc_skb_ip_align
- Use devm functions for enabling clocks
- Remove redundancy from the Makefile
- Fix error messages and clean up error paths
- Miscellaneous reformatting

 .../devicetree/bindings/net/qcom-emac.txt          |  112 ++
 MAINTAINERS                                        |    6 +
 drivers/net/ethernet/qualcomm/Kconfig              |   12 +
 drivers/net/ethernet/qualcomm/Makefile             |    2 +
 drivers/net/ethernet/qualcomm/emac/Makefile        |    7 +
 drivers/net/ethernet/qualcomm/emac/emac-mac.c      | 1530 ++++++++++++++++++++
 drivers/net/ethernet/qualcomm/emac/emac-mac.h      |  248 ++++
 drivers/net/ethernet/qualcomm/emac/emac-phy.c      |  203 +++
 drivers/net/ethernet/qualcomm/emac/emac-phy.h      |   33 +
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c    |  722 +++++++++
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h    |   24 +
 drivers/net/ethernet/qualcomm/emac/emac.c          |  751 ++++++++++
 drivers/net/ethernet/qualcomm/emac/emac.h          |  335 +++++
 13 files changed, 3985 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/qcom-emac.txt
 create mode 100644 drivers/net/ethernet/qualcomm/emac/Makefile
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-mac.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-mac.h
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-phy.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-phy.h
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac.h
Documentation/devicetree/bindings/net/qcom-emac.txt new file +112 -0
new file mode 100644
index 0000000..4599c78
@@ -0,0 +1,112 @@
+Qualcomm Technologies EMAC Gigabit Ethernet Controller
+
+This network controller consists of two devices: a MAC and an SGMII
+internal PHY.  Each device is represented by a device tree node.  A phandle
+connects the MAC node to its corresponding internal phy node.  Another
+phandle points to the external PHY node.
+
+Required properties:
+
+MAC node:
+- compatible : Should be "qcom,fsm9900-emac".
+- reg : Offset and length of the register regions for the device
+- interrupts : Interrupt number used by this controller
+- mac-address : The 6-byte MAC address. If present, it is the default
+	MAC address.
+- internal-phy : phandle to the internal PHY node
+- phy-handle : phandle the the external PHY node
+
+Internal PHY node:
+- compatible : Should be "qcom,fsm9900-emac-sgmii" or "qcom,qdf2432-emac-sgmii".
+- reg : Offset and length of the register region(s) for the device
+- interrupts : Interrupt number used by this controller
+
+The external phy child node:
+- reg : The phy address
+
+Example:
+
+FSM9900:
+
+soc {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	emac0: ethernet@feb20000 {
+		compatible = "qcom,fsm9900-emac";
+		reg = <0xfeb20000 0x10000>,
+		      <0xfeb36000 0x1000>;
+		interrupts = <76>;
+
+		clocks = <&gcc 0>, <&gcc 1>, <&gcc 3>, <&gcc 4>, <&gcc 5>,
+			<&gcc 6>, <&gcc 7>;
+		clock-names = "axi_clk", "cfg_ahb_clk", "high_speed_clk",
+			"mdio_clk", "tx_clk", "rx_clk", "sys_clk";
+
+		internal-phy = <&emac_sgmii>;
+
+		phy-handle = <&phy0>;
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+		phy0: ethernet-phy@0 {
+			reg = <0>;
+		};
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&mdio_pins_a>;
+	};
+
+	emac_sgmii: ethernet@feb38000 {
+		compatible = "qcom,fsm9900-emac-sgmii";
+		reg = <0xfeb38000 0x1000>;
+		interrupts = <80>;
+	};
+
+	tlmm: pinctrl@fd510000 {
+		compatible = "qcom,fsm9900-pinctrl";
+
+		mdio_pins_a: mdio {
+			state {
+				pins = "gpio123", "gpio124";
+				function = "mdio";
+			};
+		};
+	};
+
+
+QDF2432:
+
+soc {
+	#address-cells = <2>;
+	#size-cells = <2>;
+
+	emac0: ethernet@38800000 {
+		compatible = "qcom,fsm9900-emac";
+                reg = <0x0 0x38800000 0x0 0x10000>,
+                      <0x0 0x38816000 0x0 0x1000>;
+		interrupts = <0 0x100 0>;
+
+		clocks = <&gcc 0>, <&gcc 1>, <&gcc 3>, <&gcc 4>, <&gcc 5>,
+			<&gcc 6>, <&gcc 7>;
+		clock-names = "axi_clk", "cfg_ahb_clk", "high_speed_clk",
+			"mdio_clk", "tx_clk", "rx_clk", "sys_clk";
+
+		internal-phy = <&emac_sgmii>;
+
+		phy-handle = <&phy0>;
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+		phy0: ethernet-phy@4 {
+			reg = <4>;
+		};
+	};
+
+	emac_sgmii: ethernet@410400 {
+		compatible = "qcom,qdf2432-emac-sgmii";
+		reg = <0x0 0x00410400 0x0 0xc00>, /* Base address */
+		      <0x0 0x00410000 0x0 0x400>; /* Pre-lane digital */
+		interrupts = <0 0x104 0>;
+	};
+
MAINTAINERS +6 -0
index 952fd2a..38dabdf 100644
@@ -9404,6 +9404,12 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git
 S:	Supported
 F:	drivers/net/wireless/ath/ath10k/
 
+QUALCOMM EMAC GIGABIT ETHERNET DRIVER
+M:	Timur Tabi <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/net/ethernet/qualcomm/emac/
+
 QUALCOMM HEXAGON ARCHITECTURE
 M:	Richard Kuo <[email protected]>
 L:	[email protected]
drivers/net/ethernet/qualcomm/Kconfig +12 -0
index a76e380..9ba568d 100644
@@ -24,4 +24,16 @@ config QCA7000
 	  To compile this driver as a module, choose M here. The module
 	  will be called qcaspi.
 
+config QCOM_EMAC
+	tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support"
+	select CRC32
+	select PHYLIB
+	---help---
+	  This driver supports the Qualcomm Technologies, Inc. Gigabit
+	  Ethernet Media Access Controller (EMAC). The controller
+	  supports IEEE 802.3-2002, half-duplex mode at 10/100 Mb/s,
+	  full-duplex mode at 10/100/1000Mb/s, Wake On LAN (WOL) for
+	  low power, Receive-Side Scaling (RSS), and IEEE 1588-2008
+	  Precision Clock Synchronization Protocol.
+
 endif # NET_VENDOR_QUALCOMM
drivers/net/ethernet/qualcomm/Makefile +2 -0
index 9da2d75..1b3a0ce 100644
@@ -4,3 +4,5 @@
 
 obj-$(CONFIG_QCA7000) += qcaspi.o
 qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+
+obj-$(CONFIG_QCOM_EMAC) += emac/
drivers/net/ethernet/qualcomm/emac/Makefile new file +7 -0
new file mode 100644
index 0000000..700ee6e
@@ -0,0 +1,7 @@
+#
+# Makefile for the Qualcomm Technologies, Inc. EMAC Gigabit Ethernet driver
+#
+
+obj-y += qcom-emac.o
+
+qcom-emac-objs := emac.o emac-mac.o emac-phy.o emac-sgmii.o
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +1530 -0

1,530 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-mac.h new file +248 -0

248 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-phy.c new file +203 -0

203 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-phy.h new file +33 -0
new file mode 100644
index 0000000..49f3701
@@ -0,0 +1,33 @@
+/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 and
+* only version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*/
+
+#ifndef _EMAC_PHY_H_
+#define _EMAC_PHY_H_
+
+typedef int (*emac_sgmii_initialize)(struct emac_adapter *adpt);
+
+/** emac_phy - internal emac phy
+ * @base base address
+ * @digital per-lane digital block
+ * @initialize initialization function
+ */
+struct emac_phy {
+	void __iomem		*base;
+	void __iomem		*digital;
+	emac_sgmii_initialize	initialize;
+};
+
+struct emac_adapter;
+
+int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt);
+
+#endif /* _EMAC_PHY_H_ */
drivers/net/ethernet/qualcomm/emac/emac-sgmii.c new file +722 -0

722 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-sgmii.h new file +24 -0
new file mode 100644
index 0000000..ce79212
@@ -0,0 +1,24 @@
+/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _EMAC_SGMII_H_
+#define _EMAC_SGMII_H_
+
+struct emac_adapter;
+struct platform_device;
+
+int emac_sgmii_init_v1(struct emac_adapter *adpt);
+int emac_sgmii_init_v2(struct emac_adapter *adpt);
+int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt);
+void emac_sgmii_reset(struct emac_adapter *adpt);
+
+#endif
drivers/net/ethernet/qualcomm/emac/emac.c new file +751 -0

88 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac.h new file +335 -0

335 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 8 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Part of the diff is not shown here. View the raw message.

maintainer
#1 lore raw

From: Timur Tabi <[email protected]>
Date: Thu, 25 Aug 2016 16:39:03 -0500

drivers/net/ethernet/qualcomm/emac/emac.c line 446

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +7 -0
+static const u8 duuid[] = {
+	0x77, 0x79, 0x60, 0xbf,
+	0x2d, 0xab,
+	0x9d, 0x4b,
+	0x94, 0xf0,
+	0xe1, 0x11, 0x98, 0x01, 0xa2, 0xba
+};

This seems to be completely unused, please remove it.

#2 lore raw
Quoted 12 lines · David Miller

From: Timur Tabi <[email protected]>
Date: Thu, 25 Aug 2016 16:39:03 -0500

drivers/net/ethernet/qualcomm/emac/emac.c line 446

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +7 -0
+static const u8 duuid[] = {
+	0x77, 0x79, 0x60, 0xbf,
+	0x2d, 0xab,
+	0x9d, 0x4b,
+	0x94, 0xf0,
+	0xe1, 0x11, 0x98, 0x01, 0xa2, 0xba
+};

This seems to be completely unused, please remove it.

Sorry, I missed that during my cleanup. I'll remove it in v10.

I wonder why my compiler didn't complain about the unused static.

Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.
#3 lore raw
Quoted 14 lines · Timur Tabi
Quoted 12 lines · David Miller

From: Timur Tabi <[email protected]>
Date: Thu, 25 Aug 2016 16:39:03 -0500

drivers/net/ethernet/qualcomm/emac/emac.c line 446

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +7 -0
+static const u8 duuid[] = {
+	0x77, 0x79, 0x60, 0xbf,
+	0x2d, 0xab,
+	0x9d, 0x4b,
+	0x94, 0xf0,
+	0xe1, 0x11, 0x98, 0x01, 0xa2, 0xba
+};

This seems to be completely unused, please remove it.

Quoted 3 lines

Sorry, I missed that during my cleanup. I'll remove it in v10.

I wonder why my compiler didn't complain about the unused static.

AFAICT this really depends on how modern your compiler is and which warnings it may now enable by default.

Since you are very close from an accepted driver, you may want to squash potential warnings (and more) with doing a sparse build (make C=) which covers a bit more than what a traditional C compiler does.

Almost there!

Signature · 1 line
Florian
maintainer
#4 lore raw
In reply to Timur Tabi

From: Timur Tabi <[email protected]>
Date: Sat, 27 Aug 2016 07:26:39 -0500

Quoted 14 lines
Quoted 12 lines · David Miller

From: Timur Tabi <[email protected]>
Date: Thu, 25 Aug 2016 16:39:03 -0500

drivers/net/ethernet/qualcomm/emac/emac.c line 446

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +7 -0
+static const u8 duuid[] = {
+	0x77, 0x79, 0x60, 0xbf,
+	0x2d, 0xab,
+	0x9d, 0x4b,
+	0x94, 0xf0,
+	0xe1, 0x11, 0x98, 0x01, 0xa2, 0xba
+};

This seems to be completely unused, please remove it.

Quoted 3 lines

Sorry, I missed that during my cleanup. I'll remove it in v10.

I wonder why my compiler didn't complain about the unused static.

Unused static "const" is not warned about.

#5 lore raw
In reply to Timur Tabi

Hi,

Shouldn't it be obj-$(CONFIG_QCOM_EMAC) instead obj-y? QCOM_EMAC is defined as tristate in the drivers/net/ethernet/qualcomm/Kconfig by this patch, so it should be possible to build it as a *.ko module also.

drivers/net/ethernet/qualcomm/emac/Makefile line 6

Quoted 12 lines
drivers/net/ethernet/qualcomm/emac/Makefile new file +6 -0
new file mode 100644
index 0000000..700ee6e
@@ -0,0 +1,7 @@
+#
+# Makefile for the Qualcomm Technologies, Inc. EMAC Gigabit Ethernet driver
+#
+
+obj-y += qcom-emac.o
+

The return type of the method emac_tx_tpd_create() should be void, as it always returns true.

Quoted 9 lines
drivers/net/ethernet/qualcomm/emac/Makefile new file +9 -0
+/* Produce new transmit descriptor */
+static bool emac_tx_tpd_create(struct emac_adapter *adpt,
+                              struct emac_tx_queue *tx_q, struct emac_tpd *tpd)
+{
+       u32 *hw_tpd;
+
+       tx_q->tpd.last_produce_idx = tx_q->tpd.produce_idx;
+       hw_tpd = EMAC_TPD(tx_q, adpt->tpd_size, tx_q->tpd.produce_idx);
+

drivers/net/ethernet/qualcomm/emac/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/Makefile new file +10 -0
+       if (++tx_q->tpd.produce_idx == tx_q->tpd.count)
+               tx_q->tpd.produce_idx = 0;
+
+       *(hw_tpd++) = tpd->word[0];
+       *(hw_tpd++) = tpd->word[1];
+       *(hw_tpd++) = tpd->word[2];
+       *hw_tpd = tpd->word[3];
+
+       return true;
+}

...
...
...

Seems that there are several unused members in the emac_stats struct:

Quoted 1 line

+struct emac_stats {

...
...
Both rx_bcast_byte_cnt and rx_mcast_byte_cnt are not used anywhere/

drivers/net/ethernet/qualcomm/emac/Makefile

Quoted 2 lines
drivers/net/ethernet/qualcomm/emac/Makefile new file +2 -0
+       u64 rx_bcast_byte_cnt;  /* broadcast packets byte count (without FCS) */
+       u64 rx_mcast_byte_cnt;  /* multicast packets byte count (without FCS) */

...
rx_err_addr is not used

Quoted 1 line

+ u64 rx_err_addr; /* packets dropped due to address filtering */

Typo: it is jabbers and not jubbers; greppping for "jubber" under drivers/net/ethernet gives
0 results, whereas:
/net-next/drivers/net/ethernet$ grep -R jabber | wc -l gives 241 results.

Quoted 1 line

+ u64 rx_jubbers; /* jubbers */

...
..
tx_rd_eop and tx_len_err are not used

drivers/net/ethernet/qualcomm/emac/Makefile

Quoted 2 lines
drivers/net/ethernet/qualcomm/emac/Makefile new file +2 -0
+       u64 tx_rd_eop;          /* count of reads beyond EOP */
+       u64 tx_len_err;         /* packets with length mismatch */

Both tx_bcast_byte and tx_mcast_byte are not used.

drivers/net/ethernet/qualcomm/emac/Makefile

Quoted 2 lines
drivers/net/ethernet/qualcomm/emac/Makefile new file +2 -0
+       u64 tx_bcast_byte;      /* broadcast packets byte count (without FCS) */
+       u64 tx_mcast_byte;      /* multicast packets byte count (without FCS) */

Thanks for your good work, it seems that the driver is almost done!

Regards,
Rami Rosen

A message that is not in the archive (sent off-list or not yet received): CAKoUAr=Z56VxzW=zHu7r9ossdXHQ6xpeYdR5jwhv38zkV_eKFQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

author
#7 lore raw
Quoted 3 lines · Rami Rosen

Hi,

Shouldn't it be obj-$(CONFIG_QCOM_EMAC) instead obj-y?

Yes, I noticed this soon after I posted this patch. I will fix it in v10.

Quoted 2 lines

The return type of the method emac_tx_tpd_create() should be void, as it always returns true.

Will fix, thanks.

Quoted 11 lines

Seems that there are several unused members in the emac_stats struct:

Quoted 1 line

+struct emac_stats {

...
...
Both rx_bcast_byte_cnt and rx_mcast_byte_cnt are not used anywhere/

drivers/net/ethernet/qualcomm/emac/emac.h line 196

Quoted 2 lines
drivers/net/ethernet/qualcomm/emac/emac.h new file +2 -0
+       u64 rx_bcast_byte_cnt;  /* broadcast packets byte count (without FCS) */
+       u64 rx_mcast_byte_cnt;  /* multicast packets byte count (without FCS) */

...
rx_err_addr is not used

Quoted 1 line

+ u64 rx_err_addr; /* packets dropped due to address filtering */

I'll go through the structure and remove the unused fields.

Quoted 8 lines

Typo: it is jabbers and not jubbers; greppping for "jubber" under drivers/net/ethernet gives
0 results, whereas:
/net-next/drivers/net/ethernet$ grep -R jabber | wc -l gives 241 results.

Quoted 1 line

+ u64 rx_jubbers; /* jubbers */

Thanks. I'll fix that in v10.

Quoted 5 lines

...
..
tx_rd_eop and tx_len_err are not used

Quoted 8 lines

drivers/net/ethernet/qualcomm/emac/emac.h line 223

Quoted 2 lines
drivers/net/ethernet/qualcomm/emac/emac.h new file +2 -0
+       u64 tx_rd_eop;          /* count of reads beyond EOP */
+       u64 tx_len_err;         /* packets with length mismatch */

Both tx_bcast_byte and tx_mcast_byte are not used.

drivers/net/ethernet/qualcomm/emac/emac.h line 226

Quoted 2 lines
drivers/net/ethernet/qualcomm/emac/emac.h new file +2 -0
+       u64 tx_bcast_byte;      /* broadcast packets byte count (without FCS) */
+       u64 tx_mcast_byte;      /* multicast packets byte count (without FCS) */

Thanks for your good work, it seems that the driver is almost done!

I'm grateful for the opportunity to improve this driver over the crappy one that's been bouncing around internally for years, and for all the people who helped me along the way.

Signature · 7 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw
Quoted 11 lines · Timur Tabi
Quoted 11 lines

Seems that there are several unused members in the emac_stats struct:

Quoted 1 line

+struct emac_stats {

...
...
Both rx_bcast_byte_cnt and rx_mcast_byte_cnt are not used anywhere/

Quoted 4 lines

+ u64 rx_bcast_byte_cnt; /* broadcast packets byte count
(without FCS) */
+ u64 rx_mcast_byte_cnt; /* multicast packets byte count
(without FCS) */

Quoted 6 lines
Quoted 4 lines

...
rx_err_addr is not used

Quoted 2 lines

+ u64 rx_err_addr; /* packets dropped due to address
filtering */

I'll go through the structure and remove the unused fields.

It turns out I cannot actually strip out those "unused" fields. They are all indirectly used in emac_get_stats64:

	u64 *stats_itr = &adpt->stats.rx_ok;

	while (addr <= REG_MAC_RX_STATUS_END) {
		val = readl_relaxed(adpt->base + addr);
		*stats_itr += val;
		stats_itr++;
		addr += sizeof(u32);
	}
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
#9 lore raw
Quoted 22 lines · Timur Tabi
Quoted 11 lines · Timur Tabi
Quoted 11 lines

Seems that there are several unused members in the emac_stats struct:

Quoted 1 line

+struct emac_stats {

...
...
Both rx_bcast_byte_cnt and rx_mcast_byte_cnt are not used anywhere/

Quoted 4 lines

+ u64 rx_bcast_byte_cnt; /* broadcast packets byte count
(without FCS) */
+ u64 rx_mcast_byte_cnt; /* multicast packets byte count
(without FCS) */

Quoted 6 lines
Quoted 4 lines

...
rx_err_addr is not used

Quoted 2 lines

+ u64 rx_err_addr; /* packets dropped due to address
filtering */

I'll go through the structure and remove the unused fields.

It turns out I cannot actually strip out those "unused" fields. They are all indirectly used in emac_get_stats64:

Quoted 8 lines
    u64 *stats_itr = &adpt->stats.rx_ok;

    while (addr <= REG_MAC_RX_STATUS_END) {
        val = readl_relaxed(adpt->base + addr);
        *stats_itr += val;
        stats_itr++;
        addr += sizeof(u32);
    }

if these are truly 64-bits stats, how come you are using a single readl_* to access them? Or is the u64 rx_err_addr just used as temporary storage and aligned to the largest size you need to deal with?

Signature · 1 line
Florian

A message that is not in the archive (sent off-list or not yet received): 60d13549-f9ea-694b-1030-0c610e0d9722-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

author
#11 lore raw
Quoted 3 lines · Florian Fainelli

if these are truly 64-bits stats, how come you are using a single readl_* to access them? Or is the u64 rx_err_addr just used as temporary storage and aligned to the largest size you need to deal with?

"*stats_itr += val;" takes the 32-bit val, zero-extends it to 64 bits, and then adds that to the corresponding 64-bit field in emac_stats.

Signature · 7 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1472161143-26417-1-git-send-email-timur-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org

#13 lore raw
Quoted 92 lines · Timur Tabi

Add support for the Qualcomm Technologies, Inc. EMAC gigabit Ethernet controller.

This driver supports the following features:
1) Checksum offload.
2) Interrupt coalescing support.
3) SGMII phy.
4) phylib interface for external phy

Based on original work by
Niranjana Vishwanathapura <[email protected]> Gilad Avidov <[email protected]>

---

v9:
- Define a separate DT node for the internal phy
- Kconfig option now selects required PHYLIB
- Use netdev_alloc_skb_ip_align
- Use devm functions for enabling clocks
- Remove redundancy from the Makefile
- Fix error messages and clean up error paths
- Miscellaneous reformatting

 .../devicetree/bindings/net/qcom-emac.txt          |  112 ++
 MAINTAINERS                                        |    6 +
 drivers/net/ethernet/qualcomm/Kconfig              |   12 +
 drivers/net/ethernet/qualcomm/Makefile             |    2 +
 drivers/net/ethernet/qualcomm/emac/Makefile        |    7 +
 drivers/net/ethernet/qualcomm/emac/emac-mac.c      | 1530 ++++++++++++++++++++
 drivers/net/ethernet/qualcomm/emac/emac-mac.h      |  248 ++++
 drivers/net/ethernet/qualcomm/emac/emac-phy.c      |  203 +++
 drivers/net/ethernet/qualcomm/emac/emac-phy.h      |   33 +
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c    |  722 +++++++++
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h    |   24 +
 drivers/net/ethernet/qualcomm/emac/emac.c          |  751 ++++++++++
 drivers/net/ethernet/qualcomm/emac/emac.h          |  335 +++++
 13 files changed, 3985 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/qcom-emac.txt
 create mode 100644 drivers/net/ethernet/qualcomm/emac/Makefile
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-mac.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-mac.h
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-phy.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-phy.h
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac.h
Documentation/devicetree/bindings/net/qcom-emac.txt new file +36 -0
new file mode 100644
index 0000000..4599c78
@@ -0,0 +1,112 @@
+Qualcomm Technologies EMAC Gigabit Ethernet Controller
+
+This network controller consists of two devices: a MAC and an SGMII
+internal PHY.  Each device is represented by a device tree node.  A phandle
+connects the MAC node to its corresponding internal phy node.  Another
+phandle points to the external PHY node.
+
+Required properties:
+
+MAC node:
+- compatible : Should be "qcom,fsm9900-emac".
+- reg : Offset and length of the register regions for the device
+- interrupts : Interrupt number used by this controller
+- mac-address : The 6-byte MAC address. If present, it is the default
+	MAC address.
+- internal-phy : phandle to the internal PHY node
+- phy-handle : phandle the the external PHY node
+
+Internal PHY node:
+- compatible : Should be "qcom,fsm9900-emac-sgmii" or "qcom,qdf2432-emac-sgmii".
+- reg : Offset and length of the register region(s) for the device
+- interrupts : Interrupt number used by this controller
+
+The external phy child node:
+- reg : The phy address
+
+Example:
+
+FSM9900:
+
+soc {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	emac0: ethernet@feb20000 {
+		compatible = "qcom,fsm9900-emac";

Documentation/devicetree/bindings/net/qcom-emac.txt line 46

Quoted 10 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +10 -0
+		reg = <0xfeb20000 0x10000>,
+		      <0xfeb36000 0x1000>;
+		interrupts = <76>;
+
+		clocks = <&gcc 0>, <&gcc 1>, <&gcc 3>, <&gcc 4>, <&gcc 5>,
+			<&gcc 6>, <&gcc 7>;
+		clock-names = "axi_clk", "cfg_ahb_clk", "high_speed_clk",
+			"mdio_clk", "tx_clk", "rx_clk", "sys_clk";
+
+		internal-phy = <&emac_sgmii>;

Can't this use the standard generic phy binding (i.e. 'phys'). It's a bit confusing as there's the ethernet phy binding (phy-handle) and the generic one.

Documentation/devicetree/bindings/net/qcom-emac.txt line 48

Quoted 2 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +2 -0
+
+		phy-handle = <&phy0>;

This is bit redundant as the phy is the child node. I guess if you had multiple devices on the mdio bus you would need it. I'd drop it if you don't envision needing it and the kernel doesn't require it.

Documentation/devicetree/bindings/net/qcom-emac.txt line 52

Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4 -0
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+		phy0: ethernet-phy@0 {

It's just an example, but don't we require compatible strings for phys now?

Documentation/devicetree/bindings/net/qcom-emac.txt line 55

Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +3 -0
+			reg = <0>;
+		};
+

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#14 lore raw
Quoted 5 lines · Rob Herring

Review

Quoted 1 line
(quoted diff) +1 -0
+		internal-phy = <&emac_sgmii>;

Can't this use the standard generic phy binding (i.e. 'phys'). It's a bit confusing as there's the ethernet phy binding (phy-handle) and the generic one.

It's not a generic phy. It's a funky "internal phy" that differs among SOCs. I call it the internal phy, but I could use another name. Internally, some people call it the "sgmii phy", but I don't think that's accurate.

I can call it "emac-phy", but I don't know if that's any better.

Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		phy-handle = <&phy0>;

This is bit redundant as the phy is the child node. I guess if you had multiple devices on the mdio bus you would need it. I'd drop it if you don't envision needing it and the kernel doesn't require it.

That's what I thought to, but without it, of_phy_find_device() won't work. I need a pointer to the phy node, and I use of_parse_phandle() to get it:

	struct device_node *phy_np;

	ret = of_mdiobus_register(mii_bus, np);
	if (ret) {
		dev_err(&pdev->dev, "could not register mdio bus\n");
		return ret;
	}

	phy_np = of_parse_phandle(np, "phy-handle", 0);
	adpt->phydev = of_phy_find_device(phy_np);
Quoted 7 lines

Documentation/devicetree/bindings/net/qcom-emac.txt line 52

Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4 -0
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+		phy0: ethernet-phy@0 {

It's just an example, but don't we require compatible strings for phys now?

Nope. I had a compatible property, but it broke of_mdiobus_child_is_phy(). I don't want to specify why kind of phy it is. I want to let phylib figure it out.

Signature · 7 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#15 lore raw
Quoted 5 lines · Timur Tabi
Quoted 3 lines · Rob Herring
Quoted 1 line

+ internal-phy = <&emac_sgmii>;

Quoted 8 lines
Quoted 3 lines

Can't this use the standard generic phy binding (i.e. 'phys'). It's a bit confusing as there's the ethernet phy binding (phy-handle) and the generic one.

It's not a generic phy. It's a funky "internal phy" that differs among SOCs. I call it the internal phy, but I could use another name. Internally, some people call it the "sgmii phy", but I don't think that's accurate.

Funky internal PHYs are precisely the types of PHYs this binding is for. It is generic in that the type is not defined. It can be USB, HDMI, DSI, LVDS, etc.

Quoted 14 lines

I can call it "emac-phy", but I don't know if that's any better.

Quoted 6 lines
Quoted 1 line

+ phy-handle = <&phy0>;

This is bit redundant as the phy is the child node. I guess if you had multiple devices on the mdio bus you would need it. I'd drop it if you don't envision needing it and the kernel doesn't require it.

That's what I thought to, but without it, of_phy_find_device() won't work. I need a pointer to the phy node, and I use of_parse_phandle() to get it:

Quoted 9 lines
        struct device_node *phy_np;

        ret = of_mdiobus_register(mii_bus, np);
        if (ret) {
                dev_err(&pdev->dev, "could not register mdio bus\n");
                return ret;
        }

        phy_np = of_parse_phandle(np, "phy-handle", 0);

You can just as easily find the child node called ethernet-phy.

Quoted 8 lines
        adpt->phydev = of_phy_find_device(phy_np);
Quoted 6 lines
Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4 -0
+
+               #address-cells = <1>;
+               #size-cells = <0>;
+               phy0: ethernet-phy@0 {
Quoted 7 lines
Quoted 2 lines

It's just an example, but don't we require compatible strings for phys now?

Nope. I had a compatible property, but it broke of_mdiobus_child_is_phy(). I don't want to specify why kind of phy it is. I want to let phylib figure it out.

Okay, I'll defer to the mdio folks.

Rob

A message that is not in the archive (sent off-list or not yet received): CAL_Jsq+BtwBtB7Vd8HB+vhucfUmn_0bxRRXmyO13GoCM82LgFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

author
#17 lore raw
Quoted 7 lines · Rob Herring
Quoted 3 lines

It's not a generic phy. It's a funky "internal phy" that differs among

Quoted 2 lines

SOCs. I call it the internal phy, but I could use another name. Internally, some people call it the "sgmii phy", but I don't think that's accurate.

Funky internal PHYs are precisely the types of PHYs this binding is for. It is generic in that the type is not defined. It can be USB, HDMI, DSI, LVDS, etc.

I don't understand what you're getting at. There are two IP blocks that have a private interconnect. One is the MAC, and the other is an internal PHY, but the driver programs them as one device.

If you want me to make some kind of change, you're going to have to be more specific.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

That's what I thought to, but without it, of_phy_find_device() won't work. I need a pointer to the phy node, and I use of_parse_phandle() to get it:

        struct device_node *phy_np;

        ret = of_mdiobus_register(mii_bus, np);
        if (ret) {
                dev_err(&pdev->dev, "could not register mdio bus\n");
                return ret;
        }
Quoted 3 lines
Quoted 1 line
Quoted 1 line
        phy_np = of_parse_phandle(np, "phy-handle", 0);

You can just as easily find the child node called ethernet-phy.

As Andrew pointed out, using phy-handle allows me to place the phy node anywhere.

I've already made changes to this design, and every change has raised objections. I don't see anything wrong with phy-handle. A lot of drivers use it.

Signature · 7 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw
Quoted 8 lines
Quoted 1 line

You can just as easily find the child node called ethernet-phy.

As Andrew pointed out, using phy-handle allows me to place the phy node anywhere.

I've already made changes to this design, and every change has raised objections. I don't see anything wrong with phy-handle. A lot of drivers use it.

Agreed. You should do the same as what all other driver do.

Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#20 lore raw
In reply to Timur Tabi
Quoted 13 lines · Timur Tabi
Quoted 10 lines · Rob Herring
Quoted 5 lines

It's not a generic phy. It's a funky "internal phy" that differs among

Quoted 3 lines

SOCs. I call it the internal phy, but I could use another name. Internally,
some people call it the "sgmii phy", but I don't think that's accurate.

Funky internal PHYs are precisely the types of PHYs this binding is for. It is generic in that the type is not defined. It can be USB, HDMI, DSI, LVDS, etc.

Quoted 6 lines

I don't understand what you're getting at. There are two IP blocks that have a private interconnect. One is the MAC, and the other is an internal PHY, but the driver programs them as one device.

If you want me to make some kind of change, you're going to have to be more specific.

The change would simply be use "phys" for the property here and add #phy-cells to the phy node. See bindings/phy/phy-binding.txt.

And just because you just the phy binding, that doesn't mean you have to use the generic phy framework in the kernel. I'm not suggesting you need to. That could change in time as this becomes more common (i.e. with 10G).

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

That's what I thought to, but without it, of_phy_find_device() won't work.
I need a pointer to the phy node, and I use of_parse_phandle() to get it:

        struct device_node *phy_np;

        ret = of_mdiobus_register(mii_bus, np);
        if (ret) {
                dev_err(&pdev->dev, "could not register mdio bus\n");
                return ret;
        }
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
        phy_np = of_parse_phandle(np, "phy-handle", 0);

You can just as easily find the child node called ethernet-phy.

As Andrew pointed out, using phy-handle allows me to place the phy node anywhere.

But you can't because the binding says (or should say) it is a child node.

Quoted 3 lines

I've already made changes to this design, and every change has raised objections. I don't see anything wrong with phy-handle. A lot of drivers use it.

You said it wouldn't work. I'm only pointing out that that is not true. As I said to begin with, if everything else is using it, then it's fine.

Rob

#21 lore raw
In reply to Rob Herring
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +12 -0
+soc {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	emac0: ethernet@feb20000 {
+		compatible = "qcom,fsm9900-emac";
+		reg = <0xfeb20000 0x10000>,
+		      <0xfeb36000 0x1000>;
+		interrupts = <76>;
+
+		clocks = <&gcc 0>, <&gcc 1>, <&gcc 3>, <&gcc 4>, <&gcc 5>,
+			<&gcc 6>, <&gcc 7>;
Quoted 8 lines

Documentation/devicetree/bindings/net/qcom-emac.txt line 46

Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4 -0
+		clock-names = "axi_clk", "cfg_ahb_clk", "high_speed_clk",
+			"mdio_clk", "tx_clk", "rx_clk", "sys_clk";
+
+		internal-phy = <&emac_sgmii>;

Can't this use the standard generic phy binding (i.e. 'phys'). It's a bit confusing as there's the ethernet phy binding (phy-handle) and the generic one.

Hi Rob

An ethernet PHY is much more complex than a generic PHY. The generic phy API basically allows you to turn on/off or power up/down. An Ethernet phy you can find out if there is anybody on the other end, what speed is being used, set parameters used to negotiate what speed to use, turn power saving features on off, find out if the other end has power saving features, change the signal delays between the MAC and the PHY, configure and handle interrupts when something changes, configure WoL, etc.

If generic PHYs would of come first, things might be different, but given that Ethernet PHYs are much much older and well entrenched into device tree bindings, i don't see them merging.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+		phy-handle = <&phy0>;

This is bit redundant as the phy is the child node.

The Internal PHY is a child node. However, there is no reason an external phy is a child. You sometimes see it connected to another devices MDIO bus.

Quoted 2 lines

I guess if you had multiple devices on the mdio bus you would need it.

And this is where people make errors. They hard code in the driver that it should use the first phy on the bus. Then some hardware engineer comes along and adds a second phy to the bus, and it breaks. It is more robust to explicitly indicate which PHY is connected to this MAC.

Quoted 6 lines

Documentation/devicetree/bindings/net/qcom-emac.txt line 52

Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +3 -0
+		#address-cells = <1>;
+		#size-cells = <0>;
+		phy0: ethernet-phy@0 {

It's just an example, but don't we require compatible strings for phys now?

We have never required compatibility strings for Ethernet PHYs. And due to the stable binding rules, we now never can. The binding documentation says it may contain compatible strings.

Andrew