Skip to contentSkip to conversation

net: emac: emac gigabit ethernet controller driver

PATCH Superseded Timur Tabi 6 participants 9 messages Aug 11, 2016 – Aug 25, 2016 1 message not in the archive

Subsystems (5)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

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

Add supports for ethernet controller HW on Qualcomm Technologies, Inc. SoC. 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]>

---

v8:
- Remove "phy-version" property, use different compatible strings to differentiate EMAC versions instead.
- fully unmap all DMA mappings upon any single DMA mapping error
- add support for 32-bit DMA masks
- Make reads/writes to hardware data structures endian-safe
- emac_mac_stop already disables interrupts, so don't do it in emac_mac_reset
- Set adpt->rxbuf_size only when initializing the MAC, not when changing MTU
- Fix the calculation of the # of free descriptors required
- Always stop the PHY before disconnecting it
- Miscellaneous cleanups (removing unused definitions, fix typos and spacing, use unsized ints, etc).

v7:
- add "phy-version" to DT docs
- remove emac_status_bits, use mutexes instead of polling a status bit
- test return code from dma_map_single() calls
- use __netdev_alloc_skb_ip_align instead of dev_alloc_skb
- add a missing free_irq on an error path
- return an error code from emac_reinit_locked
- support setting the MTU even when the interface is down
- use a spinlock not a mutex in emac_get_stats64
- don't redundantly set the ethernet device name
- remove all hardware timestamp code, since it's incomplete
- remove redundant 'reset' param to emac_mac_down()
- handle queue throttling properly

v6:
- Properly ordered local variables
- use built-in GEN_MASK instead of BITS_MASK
- remove redundant call to emac_rx_mode_set from emac_mac_up
- removed emac_rfd structure, use dma_addr_t directly instead
- removed emac_mac_speed enun, replaced with macros
- removed superfluous phy_stop from emac_mac_down(), which prevented reloading module
- add missing netif_napi_del
- set the DMA mask

v5:
- changed author to Timur, added MAINTAINERS entry
- use phylib, replacing internal phy code
- added support for EMAC internal SGMII v2
- fix ~DIS_INT warning
- update DT bindings, including removing unused properties
- removed interrupt handler for internal sgmii
- removed link status check handler/state (replaced with phylib)
- removed periodic timer handler (replaced with phylib)
- removed power management code (will be rewritten later)
- external phy is now required, not optional
- removed redundant EMAC_STATUS_DOWN status flag
- removed redundant link status and speed variables
- removed redundant status bits (vlan strip, promiscuous, loopback, etc)
- removed useless watchdog status
- removed command-line parameters
- cleaned up probe messages
- removed redundant params from emac_sgmii_link_init()
- always call netdev_completed_queue() (per review comment)
- fix emac_napi_rtx() (per review comment)
- removed max_ints loop in interrupt handler
- removed redundant mutex around phy read/write calls
- added lock for reading emac status (per review comment)
- generate random MAC address if it can't be read from firmware
- replace EMAC_DMA_ADDR_HI/LO with upper/lower_32_bits
- don't test return value from platform_get_resource (per review comment)
- use net_warn_ratelimited (per review comment)
- don't set the dma masks (will be set by DT or IORT code)
- remove unused emac_tx_tpd_ts_save()
- removed redundant local MTU variable

v4:
- add missing ipv6 header file
- correct compatible string
- fix spacing in emac_reg_write arrays
- drop unnecessary cell-index property
- remove unsupported DT properties from docs
- remove GPIO initialization and update docs

v3:
- remove most of the memory barriers by using the non xxx_relaxed() api.
- remove RSS and WOL support.
- correct comments from physical address to dma address.
- rearrange structs to make them packed.
- replace polling loops with readl_poll_timeout().
- remove unnecessary wrapper functions from phy layer.
- add blank line before return statements.
- set to null clocks after clk_put().
- use module_platform_driver() and dma_set_mask_and_coherent()
- replace long hex bitmasks with BIT() macro.

v2:
- replace hw bit fields to macros with bitwise operations.
- change all iterators to unsized types (int)
- some minor code flow improvements.
- change return type to void for functions which return value is never used.
- replace instance of xxxxl_relaxed() io followed by mb() with a readl()/writel().

 .../devicetree/bindings/net/qcom-emac.txt          |   64 +
 MAINTAINERS                                        |    6 +
 drivers/net/ethernet/qualcomm/Kconfig              |   11 +
 drivers/net/ethernet/qualcomm/Makefile             |    2 +
 drivers/net/ethernet/qualcomm/emac/Makefile        |    7 +
 drivers/net/ethernet/qualcomm/emac/emac-mac.c      | 1532 ++++++++++++++++++++
 drivers/net/ethernet/qualcomm/emac/emac-mac.h      |  250 ++++
 drivers/net/ethernet/qualcomm/emac/emac-phy.c      |  201 +++
 drivers/net/ethernet/qualcomm/emac/emac-phy.h      |   32 +
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c    |  693 +++++++++
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h    |   24 +
 drivers/net/ethernet/qualcomm/emac/emac.c          |  796 ++++++++++
 drivers/net/ethernet/qualcomm/emac/emac.h          |  335 +++++
 13 files changed, 3953 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 +64 -0
new file mode 100644
index 0000000..1381089
@@ -0,0 +1,64 @@
+Qualcomm EMAC Gigabit Ethernet Controller
+
+Required properties:
+- compatible : Should be "qcom,fsm9900-emac" or "qcom,qdf2432-emac", depending
+	on the version of the internal PHY.  "qcom,fsm9900-emac" is for v1,
+	and "qcom,qdf2432-emac" is for v2.
+- reg : Offset and length of the register regions for the device
+- reg-names : Register region names referenced in 'reg' above.
+	Required register resource entries are:
+	"base"   : EMAC controller base register block.
+	"csr"    : EMAC wrapper register block.
+	"sgmii"  : EMAC SGMII PHY register block.
+	Optional register resource entries are:
+	"ptp"    : EMAC PTP (1588) register block.
+- interrupts : Interrupt numbers used by this controller
+- interrupt-names : Interrupt resource names referenced in 'interrupts' above.
+	Required interrupt resource entries are:
+	"emac_core0"   : EMAC core0 interrupt.
+	"sgmii_irq"   : EMAC SGMII interrupt.
+- mac-address               : The 6-byte MAC address. If present, it is the
+			      default MAC address.
+
+The external phy child node:
+- compatible : Should be "qcom,fsm9900-emac-phy".
+- reg : The phy address
+
+Example:
+soc {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	dma-ranges = <0 0 0xffffffff>;
+
+	emac0: ethernet@feb20000 {
+		compatible = "qcom,fsm9900-emac";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		reg-names = "base", "csr", "ptp", "sgmii";
+		reg =   <0xfeb20000 0x10000>,
+			<0xfeb36000 0x1000>,
+			<0xfeb3c000 0x4000>,
+			<0xfeb38000 0x400>;
+		interrupt-parent = <&emac0>;
+		#interrupt-cells = <1>;
+		interrupts = <76 80>;
+		interrupt-names = "emac_core0", "sgmii_irq";
+		phy0: ethernet-phy@0 {
+			compatible = "qcom,fsm9900-emac-phy";
+			reg = <0>;
+		}
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&mdio_pins_a>;
+	};
+
+	tlmm: pinctrl@fd510000 {
+		compatible = "qcom,fsm9900-pinctrl";
+
+		mdio_pins_a: mdio {
+			state {
+				pins = "gpio123", "gpio124";
+				function = "mdio";
+			};
+		};
+	};
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 +11 -0
index a76e380..85b599f 100644
@@ -24,4 +24,15 @@ 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
+	---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..01ee144
@@ -0,0 +1,7 @@
+#
+# Makefile for the Qualcomm Technologies, Inc. EMAC Gigabit Ethernet driver
+#
+
+obj-$(CONFIG_QCOM_EMAC) += 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 +1532 -0

1,532 lines not on this page · raw message

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

250 lines not on this page · raw message

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

201 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-phy.h new file +32 -0
new file mode 100644
index 0000000..8bcc0e5
@@ -0,0 +1,32 @@
+/* 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_
+
+/* emac_phy
+ * @base register file base address space.
+ * @digital per-lane digital block
+ * @version the internal phy version
+ */
+struct emac_phy {
+	void __iomem			*base;
+	void __iomem			*digital;
+
+	unsigned int			version;
+};
+
+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 +693 -0

693 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 +796 -0

165 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.

#1 lore raw
Quoted 6 lines · Timur Tabi

Add supports for ethernet controller HW on Qualcomm Technologies, Inc. SoC. This driver supports the following features:
1) Checksum offload.
2) Interrupt coalescing support.
3) SGMII phy.
4) phylib interface for external phy

OK, so this is looking good now, just a few nits, feel free to submit as clean up patches, would this one be accepted.

[snip]

Quoted 13 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +13 -0
+Example:
+soc {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	dma-ranges = <0 0 0xffffffff>;
+
+	emac0: ethernet@feb20000 {
+		compatible = "qcom,fsm9900-emac";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		reg-names = "base", "csr", "ptp", "sgmii";
+		reg =   <0xfeb20000 0x10000>,
+			<0xfeb36000 0x1000>,

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

Quoted 10 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +10 -0
+			<0xfeb3c000 0x4000>,
+			<0xfeb38000 0x400>;
+		interrupt-parent = <&emac0>;
+		#interrupt-cells = <1>;
+		interrupts = <76 80>;
+		interrupt-names = "emac_core0", "sgmii_irq";
+		phy0: ethernet-phy@0 {
+			compatible = "qcom,fsm9900-emac-phy";
+			reg = <0>;
+		}

If this is an external PHY, the expectation is that it will be hanging off a MDIO bus controller, either the MDIO bus internal to the MAC, or an external MDIO bus (separate register range).

If such a PHY node is provided, the expectation is that your Ethernet MAC will have a phy-handle property and a phy-mode property to specify how to connect to this external PHY, so in your specific case, better remove the PHY from your example, or detail further how it should be done.

Quoted 37 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +15 -0
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&mdio_pins_a>;
+	};
+
+	tlmm: pinctrl@fd510000 {
+		compatible = "qcom,fsm9900-pinctrl";
+
+		mdio_pins_a: mdio {
+			state {
+				pins = "gpio123", "gpio124";
+				function = "mdio";
+			};
+		};
+	};
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 +0 -0
index a76e380..85b599f 100644

drivers/net/ethernet/qualcomm/Kconfig config QCA7000 · line 29

Quoted 6 lines
drivers/net/ethernet/qualcomm/Kconfig +3 -0
@@ -24,4 +24,15 @@ 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?

Quoted 14 lines
drivers/net/ethernet/qualcomm/Kconfig +8 -0
+	---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 +0 -0
index 9da2d75..1b3a0ce 100644

drivers/net/ethernet/qualcomm/Makefile line 8

Quoted 5 lines
drivers/net/ethernet/qualcomm/Makefile +2 -0
@@ -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/

Since you have a check on CONFIG_QCOM_EMAC in emac/Makefile, you could always recurse into that directory while building (use obj-y).

Quoted 11 lines
drivers/net/ethernet/qualcomm/emac/Makefile new file +5 -0
new file mode 100644
index 0000000..01ee144
@@ -0,0 +1,7 @@
+#
+# Makefile for the Qualcomm Technologies, Inc. EMAC Gigabit Ethernet driver
+#
+
+obj-$(CONFIG_QCOM_EMAC) += qcom-emac.o

[snip]

drivers/net/ethernet/qualcomm/emac/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/Makefile new file +10 -0
+
+static void emac_adjust_link(struct net_device *netdev)
+{
+	struct emac_adapter *adpt = netdev_priv(netdev);
+	struct phy_device *phydev = netdev->phydev;
+
+	if (phydev->link)
+		emac_mac_start(adpt);
+	else
+		emac_mac_stop(adpt);

This is really excessive here, you typically don't need to completely stop your transmitter/receiver/DMA/what have you, just reprogram the MAC with the appropriate link speed/duplex/pause parameters.

Signature · 1 line
Florian
maintainer Acked-by on v8 1/1
#7 lore raw
In reply to Timur Tabi
Quoted 111 lines · Timur Tabi

Add supports for ethernet controller HW on Qualcomm Technologies, Inc. SoC. 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]>

---

v8:
- Remove "phy-version" property, use different compatible strings to differentiate EMAC versions instead.
- fully unmap all DMA mappings upon any single DMA mapping error
- add support for 32-bit DMA masks
- Make reads/writes to hardware data structures endian-safe
- emac_mac_stop already disables interrupts, so don't do it in emac_mac_reset
- Set adpt->rxbuf_size only when initializing the MAC, not when changing MTU
- Fix the calculation of the # of free descriptors required
- Always stop the PHY before disconnecting it
- Miscellaneous cleanups (removing unused definitions, fix typos and spacing, use unsized ints, etc).

v7:
- add "phy-version" to DT docs
- remove emac_status_bits, use mutexes instead of polling a status bit
- test return code from dma_map_single() calls
- use __netdev_alloc_skb_ip_align instead of dev_alloc_skb
- add a missing free_irq on an error path
- return an error code from emac_reinit_locked
- support setting the MTU even when the interface is down
- use a spinlock not a mutex in emac_get_stats64
- don't redundantly set the ethernet device name
- remove all hardware timestamp code, since it's incomplete
- remove redundant 'reset' param to emac_mac_down()
- handle queue throttling properly

v6:
- Properly ordered local variables
- use built-in GEN_MASK instead of BITS_MASK
- remove redundant call to emac_rx_mode_set from emac_mac_up
- removed emac_rfd structure, use dma_addr_t directly instead
- removed emac_mac_speed enun, replaced with macros
- removed superfluous phy_stop from emac_mac_down(), which prevented reloading module
- add missing netif_napi_del
- set the DMA mask

v5:
- changed author to Timur, added MAINTAINERS entry
- use phylib, replacing internal phy code
- added support for EMAC internal SGMII v2
- fix ~DIS_INT warning
- update DT bindings, including removing unused properties
- removed interrupt handler for internal sgmii
- removed link status check handler/state (replaced with phylib)
- removed periodic timer handler (replaced with phylib)
- removed power management code (will be rewritten later)
- external phy is now required, not optional
- removed redundant EMAC_STATUS_DOWN status flag
- removed redundant link status and speed variables
- removed redundant status bits (vlan strip, promiscuous, loopback, etc)
- removed useless watchdog status
- removed command-line parameters
- cleaned up probe messages
- removed redundant params from emac_sgmii_link_init()
- always call netdev_completed_queue() (per review comment)
- fix emac_napi_rtx() (per review comment)
- removed max_ints loop in interrupt handler
- removed redundant mutex around phy read/write calls
- added lock for reading emac status (per review comment)
- generate random MAC address if it can't be read from firmware
- replace EMAC_DMA_ADDR_HI/LO with upper/lower_32_bits
- don't test return value from platform_get_resource (per review comment)
- use net_warn_ratelimited (per review comment)
- don't set the dma masks (will be set by DT or IORT code)
- remove unused emac_tx_tpd_ts_save()
- removed redundant local MTU variable

v4:
- add missing ipv6 header file
- correct compatible string
- fix spacing in emac_reg_write arrays
- drop unnecessary cell-index property
- remove unsupported DT properties from docs
- remove GPIO initialization and update docs

v3:
- remove most of the memory barriers by using the non xxx_relaxed() api.
- remove RSS and WOL support.
- correct comments from physical address to dma address.
- rearrange structs to make them packed.
- replace polling loops with readl_poll_timeout().
- remove unnecessary wrapper functions from phy layer.
- add blank line before return statements.
- set to null clocks after clk_put().
- use module_platform_driver() and dma_set_mask_and_coherent()
- replace long hex bitmasks with BIT() macro.

v2:
- replace hw bit fields to macros with bitwise operations.
- change all iterators to unsized types (int)
- some minor code flow improvements.
- change return type to void for functions which return value is never used.
- replace instance of xxxxl_relaxed() io followed by mb() with a readl()/writel().

Quoted 1 line
 .../devicetree/bindings/net/qcom-emac.txt          |   64 +
Quoted 23 lines
 MAINTAINERS                                        |    6 +
 drivers/net/ethernet/qualcomm/Kconfig              |   11 +
 drivers/net/ethernet/qualcomm/Makefile             |    2 +
 drivers/net/ethernet/qualcomm/emac/Makefile        |    7 +
 drivers/net/ethernet/qualcomm/emac/emac-mac.c      | 1532 ++++++++++++++++++++
 drivers/net/ethernet/qualcomm/emac/emac-mac.h      |  250 ++++
 drivers/net/ethernet/qualcomm/emac/emac-phy.c      |  201 +++
 drivers/net/ethernet/qualcomm/emac/emac-phy.h      |   32 +
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c    |  693 +++++++++
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h    |   24 +
 drivers/net/ethernet/qualcomm/emac/emac.c          |  796 ++++++++++
 drivers/net/ethernet/qualcomm/emac/emac.h          |  335 +++++
 13 files changed, 3953 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
#8 lore raw
In reply to Timur Tabi

Hi,

I really dont want to be a killjoy, but...

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 927

Quoted 4 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +4 -0
+		int ret;
+
+		skb = __netdev_alloc_skb_ip_align(adpt->netdev,
+						  adpt->rxbuf_size, GFP_KERNEL);

This is also called in softirq context by the napi handler in which GFP_KERNEL is not allowed.
You can either extend the refill function by one gfp_t parameter and then call it with GFP_KERNEL for the initial rx buffer allocation when the hw is brought up and then with GFP_ATOMIC for refilling in the NAPI handler. Or simply always use GFP_ATOMIC. In the latter case the additional parameter is not needed of course and you can use netdev_alloc_skb_ip_align() instead of __netdev_alloc_skb_ip_align().

Regards,
Lino

#9 lore raw
Quoted 5 lines · Lino Sanfilippo

You can either extend the refill function by one gfp_t parameter and then call it with GFP_KERNEL for the initial rx buffer allocation when the hw is brought up and then with GFP_ATOMIC for refilling in the NAPI handler. Or simply always use GFP_ATOMIC. In the latter case the additional parameter is not needed of course and you can use netdev_alloc_skb_ip_align() instead of __netdev_alloc_skb_ip_align().

I will change this to use netdev_alloc_skb_ip_align().

Thanks.

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.
#2 lore raw
In reply to Florian Fainelli
Quoted 10 lines · Florian Fainelli
Quoted 6 lines · Timur Tabi
Quoted 6 lines

Add supports for ethernet controller HW on Qualcomm Technologies, Inc. SoC. This driver supports the following features:
1) Checksum offload.
2) Interrupt coalescing support.
3) SGMII phy.
4) phylib interface for external phy

OK, so this is looking good now, just a few nits, feel free to submit as clean up patches, would this one be accepted.

I will post a v9.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +18 -0
+soc {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	dma-ranges = <0 0 0xffffffff>;
+
+	emac0: ethernet@feb20000 {
+		compatible = "qcom,fsm9900-emac";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		reg-names = "base", "csr", "ptp", "sgmii";
+		reg =   <0xfeb20000 0x10000>,
+			<0xfeb36000 0x1000>,
+			<0xfeb3c000 0x4000>,
+			<0xfeb38000 0x400>;
+		interrupt-parent = <&emac0>;
+		#interrupt-cells = <1>;
+		interrupts = <76 80>;
+		interrupt-names = "emac_core0", "sgmii_irq";
Quoted 8 lines
Quoted 4 lines

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

Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4 -0
+		phy0: ethernet-phy@0 {
+			compatible = "qcom,fsm9900-emac-phy";
+			reg = <0>;
+		}

If this is an external PHY, the expectation is that it will be hanging off a MDIO bus controller, either the MDIO bus internal to the MAC, or an external MDIO bus (separate register range).

So for starters, I forgot to delete the 'compatible' property from this document. Its presence breaks of_mdiobus_child_is_phy().

Quoted 4 lines

If such a PHY node is provided, the expectation is that your Ethernet MAC will have a phy-handle property and a phy-mode property to specify how to connect to this external PHY, so in your specific case, better remove the PHY from your example, or detail further how it should be done.

Something is odd about of_mdiobus_register().

This function scans child nodes to look for PHYs:

/* Loop over the child nodes and register a phy_device for each phy */

for_each_available_child_of_node(np, child) {
	addr = of_mdio_parse_addr(&mdio->dev, child);

And in my driver, this works. However, later when I try to call of_phy_find_device(), it fails. That's because of_phy_find_device() wants the np of the child node. But the only way to get that is with a phy-phandle property which I need to manually parse.

So what's the point of having of_mdiobus_register() parse child nodes, if you need a phy-phandle pointer anyway?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/qualcomm/Kconfig +0 -0
index a76e380..85b599f 100644
@@ -24,4 +24,15 @@ config QCA7000
 	  To compile this driver as a module, choose M here. The module
 	  will be called qcaspi.
 
Quoted 5 lines
Quoted 3 lines

drivers/net/ethernet/qualcomm/Kconfig config QCA7000 · line 29

Quoted 3 lines
drivers/net/ethernet/qualcomm/Kconfig +3 -0
+config QCOM_EMAC
+	tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support"
+	select CRC32

select PHYLIB?

Ok.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/qualcomm/Makefile +0 -0
index 9da2d75..1b3a0ce 100644
@@ -4,3 +4,5 @@
 
Quoted 7 lines
Quoted 4 lines

drivers/net/ethernet/qualcomm/Makefile line 8

Quoted 4 lines
drivers/net/ethernet/qualcomm/Makefile +2 -0
 obj-$(CONFIG_QCA7000) += qcaspi.o
 qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+
+obj-$(CONFIG_QCOM_EMAC) += emac/

Since you have a check on CONFIG_QCOM_EMAC in emac/Makefile, you could always recurse into that directory while building (use obj-y).

Obviously, having "obj-$(CONFIG_QCOM_EMAC)" in both Makefiles is redundant, but wouldn't it make more sense to change "obj-$(CONFIG_QCOM_EMAC)" to "obj-y" in drivers/net/ethernet/qualcomm/emac/Makefile, so that I only recurse if necessary?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/qualcomm/Makefile +5 -0
+static void emac_adjust_link(struct net_device *netdev)
+{
+	struct emac_adapter *adpt = netdev_priv(netdev);
+	struct phy_device *phydev = netdev->phydev;
+
Quoted 8 lines
Quoted 4 lines

drivers/net/ethernet/qualcomm/Makefile

Quoted 4 lines
drivers/net/ethernet/qualcomm/Makefile +4 -0
+	if (phydev->link)
+		emac_mac_start(adpt);
+	else
+		emac_mac_stop(adpt);

This is really excessive here, you typically don't need to completely stop your transmitter/receiver/DMA/what have you, just reprogram the MAC with the appropriate link speed/duplex/pause parameters.

Yes, I realize that a lot of the reinit code in my driver is "heavy", and that it could be optimized for specific situations. However, I'd like to save that for another patch, because it would require me to study the documentation and do extensive tests.

I can't tell you today whether emac_mac_start() is overkill for the specific link change. For all I know, the hardware does require the TX to stop before changing the link speed. Remember, the EMAC does have a weird double-phy (one internal, one external).

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 6 lines · Timur Tabi
Quoted 3 lines

If this is an external PHY, the expectation is that it will be hanging off a MDIO bus controller, either the MDIO bus internal to the MAC, or an external MDIO bus (separate register range).

So for starters, I forgot to delete the 'compatible' property from this document. Its presence breaks of_mdiobus_child_is_phy().

The MDIO devices and Ethernet PHY binding should certainly be improved, but the bulk of it is either you use ethernet-phy-ieee802.3-c22 or ethernet-phy-ieee802.3-c45, or nothing. Else, the MDIO bus probing code just assumes it can match a MDIO device (not specifically an Ethernet PHY) with its compatible string.

Quoted 11 lines
Quoted 6 lines

If such a PHY node is provided, the expectation is that your Ethernet MAC will have a phy-handle property and a phy-mode property to specify how to connect to this external PHY, so in your specific case, better remove the PHY from your example, or detail further how it should be done.

Something is odd about of_mdiobus_register().

This function scans child nodes to look for PHYs:

Quoted 8 lines

/* Loop over the child nodes and register a phy_device for each phy */

for_each_available_child_of_node(np, child) {
    addr = of_mdio_parse_addr(&mdio->dev, child);

And in my driver, this works. However, later when I try to call of_phy_find_device(), it fails. That's because of_phy_find_device() wants the np of the child node. But the only way to get that is with a phy-phandle property which I need to manually parse.

of_get_phandle() should return the device_node pointer associated with the phy-handle property which you can later use and pass to of_phy_find_device(). There are plenty of examples in the tree and the logic is almost always the same.

Quoted 3 lines

So what's the point of having of_mdiobus_register() parse child nodes, if you need a phy-phandle pointer anyway?

Not all MDIO devices are Ethernet PHYs, some of them are Ethernet switches, or any other PHY (USB, PCIE, SATA) just sitting on the same MDIO bus HW instance so you need to create device_node and struct device instances for these deviecs listed in the Device Tree since the bus is self-discoverable (like I2C).

Your Ethernet controller somehow needs to know which Ethernet PHY it is attached to since the location of the Ethernet PHY on the bus could change from design to design, let alone the actual topology (you could have a GPIO bit-banged MDIO bus or something else).

Quoted 8 lines
Quoted 2 lines

Since you have a check on CONFIG_QCOM_EMAC in emac/Makefile, you could always recurse into that directory while building (use obj-y).

Obviously, having "obj-$(CONFIG_QCOM_EMAC)" in both Makefiles is redundant, but wouldn't it make more sense to change "obj-$(CONFIG_QCOM_EMAC)" to "obj-y" in drivers/net/ethernet/qualcomm/emac/Makefile, so that I only recurse if necessary?

Whichever makes the most sense, when there is a directory involved, my preference is to always recurse in that directory and selectively compile from there, since the Kconfig/Makefile options are all located within the same hierarchical level, just a preference.

Quoted 20 lines
Quoted 14 lines
Quoted 10 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 969

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +9 -0
+static void emac_adjust_link(struct net_device *netdev)
+{
+    struct emac_adapter *adpt = netdev_priv(netdev);
+    struct phy_device *phydev = netdev->phydev;
+
+    if (phydev->link)
+        emac_mac_start(adpt);
+    else
+        emac_mac_stop(adpt);

This is really excessive here, you typically don't need to completely stop your transmitter/receiver/DMA/what have you, just reprogram the MAC with the appropriate link speed/duplex/pause parameters.

Yes, I realize that a lot of the reinit code in my driver is "heavy", and that it could be optimized for specific situations. However, I'd like to save that for another patch, because it would require me to study the documentation and do extensive tests.

Quoted 4 lines

I can't tell you today whether emac_mac_start() is overkill for the specific link change. For all I know, the hardware does require the TX to stop before changing the link speed. Remember, the EMAC does have a weird double-phy (one internal, one external).

Fair enough, not having to stop the TX from the SW perspective should be kind of basic requirement here, most drivers/HW don't seem to require that, because even if packets were inflight at the time the link went down, the MAC should sense the carrier loss and report that accordingly. Now there could be many different ways to implement and screw that up, so yes, future patch seems like a good approach.

Signature · 1 line
Florian
#6 lore raw
In reply to a message not in the archive
Quoted 4 lines

Something is odd about of_mdiobus_register().

This function scans child nodes to look for PHYs:

Quoted 8 lines

/* Loop over the child nodes and register a phy_device for each phy */

for_each_available_child_of_node(np, child) {
	addr = of_mdio_parse_addr(&mdio->dev, child);

And in my driver, this works. However, later when I try to call of_phy_find_device(), it fails. That's because of_phy_find_device() wants the np of the child node. But the only way to get that is with a phy-phandle property which I need to manually parse.

You do need the phy-handle, because you can have multiple PHYs, and ethernet switches on the MDIO bus. You need to indicate which of those PHYs is connected to this MAC.

Quoted 2 lines

So what's the point of having of_mdiobus_register() parse child nodes, if you need a phy-phandle pointer anyway?

So we know about the other phys and switches on the MDIO bus, can load the driver for them, etc. This is standard policy for a bus driver. When you instantiate the bus, you enumerate it to see what is connected to it. You do that either with of_mdiobus_register() or mdiobus_register().

However, i do agree about having a helper do the phy-handle parsing would be nice, and it should also handle fixed phys as well.

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

#4 lore raw
In reply to Florian Fainelli
Quoted 9 lines · Florian Fainelli
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Since you have a check on CONFIG_QCOM_EMAC in emac/Makefile, you could always recurse into that directory while building (use obj-y).

Obviously, having "obj-$(CONFIG_QCOM_EMAC)" in both Makefiles is redundant, but wouldn't it make more sense to change "obj-$(CONFIG_QCOM_EMAC)" to "obj-y" in drivers/net/ethernet/qualcomm/emac/Makefile, so that I only recurse if necessary?

Quoted 4 lines

Whichever makes the most sense, when there is a directory involved, my preference is to always recurse in that directory and selectively compile from there, since the Kconfig/Makefile options are all located within the same hierarchical level, just a preference.

It turns out that the way I changed it in v9 prevents the driver from being built as a module. I changed the wrong Makefile. I will have to post a v10.

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.