Skip to contentSkip to conversation

net: emac: emac gigabit ethernet controller driver

PATCH Superseded Timur Tabi 8 participants 31 messages Aug 3, 2016 – Aug 18, 2016 8 messages not in the archive

Subsystems (5)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH v7 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]>

---

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          |   66 +
 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      | 1511 ++++++++++++++++++++
 drivers/net/ethernet/qualcomm/emac/emac-mac.h      |  251 ++++
 drivers/net/ethernet/qualcomm/emac/emac-phy.c      |  211 +++
 drivers/net/ethernet/qualcomm/emac/emac-phy.h      |   32 +
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c    |  700 +++++++++
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h    |   24 +
 drivers/net/ethernet/qualcomm/emac/emac.c          |  786 ++++++++++
 drivers/net/ethernet/qualcomm/emac/emac.h          |  356 +++++
 13 files changed, 3963 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 +66 -0
new file mode 100644
index 0000000..ecf36cc
@@ -0,0 +1,66 @@
+Qualcomm EMAC Gigabit Ethernet Controller
+
+Required properties:
+- compatible : Should be "qcom,fsm9900-emac".
+- 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.
+
+Optional properties:
+- phy-version : the version of the integrated emac phy, either 1 or 2.
+
+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>;
+		phy-version = <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 +1511 -0

1,511 lines not on this page · raw message

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

251 lines not on this page · raw message

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

211 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..03e2b74
@@ -0,0 +1,32 @@
+/* Copyright (c) 2015, 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 +700 -0

700 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..cd7db9f
@@ -0,0 +1,24 @@
+/* Copyright (c) 2015, 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 +786 -0

166 lines not on this page · raw message

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

356 lines not on this page · raw message

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

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.

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

maintainer
#1 lore raw
Quoted 141 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]>

---

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          |   66 +
 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      | 1511 ++++++++++++++++++++
 drivers/net/ethernet/qualcomm/emac/emac-mac.h      |  251 ++++
 drivers/net/ethernet/qualcomm/emac/emac-phy.c      |  211 +++
 drivers/net/ethernet/qualcomm/emac/emac-phy.h      |   32 +
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c    |  700 +++++++++
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h    |   24 +
 drivers/net/ethernet/qualcomm/emac/emac.c          |  786 ++++++++++
 drivers/net/ethernet/qualcomm/emac/emac.h          |  356 +++++
 13 files changed, 3963 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 +12 -0
new file mode 100644
index 0000000..ecf36cc
@@ -0,0 +1,66 @@
+Qualcomm EMAC Gigabit Ethernet Controller
+
+Required properties:
+- compatible : Should be "qcom,fsm9900-emac".
+- 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.

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

Quoted 10 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +10 -0
+- 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.
+
+Optional properties:
+- phy-version : the version of the integrated emac phy, either 1 or 2.

Sounds like 2 different h/w. The compatible property should distinguish this.

Rob

author
#2 lore raw
Quoted 3 lines · Rob Herring
Quoted 1 line
Quoted 1 line

+- phy-version : the version of the integrated emac phy, either 1 or 2.

Sounds like 2 different h/w. The compatible property should distinguish this.

Well, the MAC parts of the EMAC is the same. I could do qcom,fsm9900-emac for v1 and qcom,qdf2432-emac for v2. I can't really think of a reason why that wouldn't work.

For ACPI, we can assume that QCOM8070 is a v2 PHY. If Qualcomm creates another server chip with a v1 PHY, it would need a new ACPI HID.

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.
#25 lore raw
In reply to a message not in the archive

Hi Timur,

Quoted 20 lines · Timur Tabi
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +20 -0
+/* Fill up transmit descriptors */
+static void emac_tx_fill_tpd(struct emac_adapter *adpt,
+			     struct emac_tx_queue *tx_q, struct sk_buff *skb,
+			     struct emac_tpd *tpd)
+{
+	u16 nr_frags = skb_shinfo(skb)->nr_frags;
+	unsigned int len = skb_headlen(skb);
+	struct emac_buffer *tpbuf = NULL;
+	unsigned int mapped_len = 0;
+	unsigned int i;
+	int ret;
+
+	/* if Large Segment Offload is (in TCP Segmentation Offload struct) */
+	if (TPD_LSO(tpd)) {
+		mapped_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
+
+		tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
+		tpbuf->length = mapped_len;
+		tpbuf->dma_addr = dma_map_single(adpt->netdev->dev.parent,
+						 skb->data, mapped_len,

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

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +10 -0
+						 DMA_TO_DEVICE);
+		ret = dma_mapping_error(adpt->netdev->dev.parent,
+					tpbuf->dma_addr);
+		if (ret) {
+			dev_kfree_skb(skb);
+			return;
+		}
+
+		TPD_BUFFER_ADDR_L_SET(tpd, lower_32_bits(tpbuf->dma_addr));
+		TPD_BUFFER_ADDR_H_SET(tpd, upper_32_bits(tpbuf->dma_addr));

You should also take big endian systems into account. This means that if the multi-byte values in the descriptors require little-endian you have to convert from host byte order to le and vice versa. You can use cpu_to_le32() and friends for this.

Quoted 29 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +29 -0
+		TPD_BUF_LEN_SET(tpd, tpbuf->length);
+		emac_tx_tpd_create(adpt, tx_q, tpd);
+	}
+
+	if (mapped_len < len) {
+		tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
+		tpbuf->length = len - mapped_len;
+		tpbuf->dma_addr = dma_map_single(adpt->netdev->dev.parent,
+						 skb->data + mapped_len,
+						 tpbuf->length, DMA_TO_DEVICE);
+		ret = dma_mapping_error(adpt->netdev->dev.parent,
+					tpbuf->dma_addr);
+		if (ret) {
+			dev_kfree_skb(skb);
+			return;
+		}
+
+		TPD_BUFFER_ADDR_L_SET(tpd, lower_32_bits(tpbuf->dma_addr));
+		TPD_BUFFER_ADDR_H_SET(tpd, upper_32_bits(tpbuf->dma_addr));
+		TPD_BUF_LEN_SET(tpd, tpbuf->length);
+		emac_tx_tpd_create(adpt, tx_q, tpd);
+	}
+
+	for (i = 0; i < nr_frags; i++) {
+		struct skb_frag_struct *frag;
+
+		frag = &skb_shinfo(skb)->frags[i];
+
+		tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);

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

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +10 -0
+		tpbuf->length = frag->size;
+		tpbuf->dma_addr = dma_map_page(adpt->netdev->dev.parent,
+					       frag->page.p, frag->page_offset,
+					       tpbuf->length, DMA_TO_DEVICE);
+		ret = dma_mapping_error(adpt->netdev->dev.parent,
+					tpbuf->dma_addr);
+		if (ret) {
+			dev_kfree_skb(skb);
+			return;
+		}

In case of error you need to undo all mappings that you have done so far.

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

Quoted 9 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +9 -0
+
+		TPD_BUFFER_ADDR_L_SET(tpd, lower_32_bits(tpbuf->dma_addr));
+		TPD_BUFFER_ADDR_H_SET(tpd, upper_32_bits(tpbuf->dma_addr));
+		TPD_BUF_LEN_SET(tpd, tpbuf->length);
+		emac_tx_tpd_create(adpt, tx_q, tpd);
+	}
+
+	/* The last tpd */
+	emac_tx_tpd_mark_last(adpt, tx_q);

Use a wmb() here to make sure that all writes to the descriptors in dma memory are completed before you update the producer register (see memory-barriers.txt for the reason why this is needed)

Quoted 27 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +27 -0
+	/* The last buffer info contain the skb address,
+	 * so it will be freed after unmap
+	 */
+	tpbuf->skb = skb;
+}
+
+/* Transmit the packet using specified transmit queue */
+int emac_mac_tx_buf_send(struct emac_adapter *adpt, struct emac_tx_queue *tx_q,
+			 struct sk_buff *skb)
+{
+	struct emac_tpd tpd;
+	u32 prod_idx;
+
+	memset(&tpd, 0, sizeof(tpd));
+
+	if (emac_tso_csum(adpt, tx_q, skb, &tpd) != 0) {
+		dev_kfree_skb_any(skb);
+		return NETDEV_TX_OK;
+	}
+
+	if (skb_vlan_tag_present(skb)) {
+		u16 tag;
+
+		EMAC_VLAN_TO_TAG(skb_vlan_tag_get(skb), tag);
+		TPD_CVLAN_TAG_SET(&tpd, tag);
+		TPD_INSTC_SET(&tpd, 1);
+	}

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

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +10 -0
+
+	if (skb_network_offset(skb) != ETH_HLEN)
+		TPD_TYP_SET(&tpd, 1);
+
+	emac_tx_fill_tpd(adpt, tx_q, skb, &tpd);
+
+	netdev_sent_queue(adpt->netdev, skb->len);
+
+	if (emac_tpd_num_free_descs(tx_q) <= (MAX_SKB_FRAGS + 1))
+		netif_stop_queue(adpt->netdev);

Is MAX_SKB_FRAGS + 1 really the max number of descriptors required by your driver? There seem to be further descriptors needed for TSO and checksumming. Please make sure that you really check against the _max_ possible number of descriptors for a transmission.

Quoted 12 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +12 -0
+
+/* Change the Maximum Transfer Unit (MTU) */
+static int emac_change_mtu(struct net_device *netdev, int new_mtu)
+{
+	unsigned int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
+	struct emac_adapter *adpt = netdev_priv(netdev);
+
+	if ((max_frame < EMAC_MIN_ETH_FRAME_SIZE) ||
+	    (max_frame > EMAC_MAX_ETH_FRAME_SIZE)) {
+		netdev_err(adpt->netdev, "error: invalid MTU setting\n");
+		return -EINVAL;
+	}

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

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10 -0
+
+	netif_info(adpt, hw, adpt->netdev,
+		   "changing MTU from %d to %d\n", netdev->mtu,
+		   new_mtu);
+	netdev->mtu = new_mtu;
+	adpt->rxbuf_size = new_mtu > EMAC_DEF_RX_BUF_SIZE ?
+		ALIGN(max_frame, 8) : EMAC_DEF_RX_BUF_SIZE;
+
+	if (netif_running(netdev))
+		return emac_reinit_locked(adpt);

This does still not look correct. The rxbuf_size is changed while the interface is still running. If the rx buffers are refilled now, the rx buffers size does not match the size that is configured in the mac, does it?
You have to stop the rx path first, then change the rx buffer size and then restart the rx path.

Regards,
Lino

--
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
#3 lore raw
In reply to Rob Herring
Quoted 2 lines · Rob Herring

Sounds like 2 different h/w. The compatible property should distinguish this.

So I changed it to this:

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

(and changed the code to match).

However, now this doesn't work look right any more:

The external phy child node:
- compatible : Should be "qcom,fsm9900-emac-phy".
- reg : The phy address

I was never crazy about this, because the external PHY is whatever device it happens to be.

The phy driver uses of_mdiobus_register, which calls of_mdiobus_child_is_phy(). Based on my reading of the code, I think I should just drop the compatible property altogether. Because the way it is now causes of_mdiobus_child_is_phy() to return false when it parses that node.

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.
author
#26 lore raw
In reply to Lino Sanfilippo
Quoted 26 lines · Lino Sanfilippo
Quoted 26 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +26 -0
+/* Fill up transmit descriptors */
+static void emac_tx_fill_tpd(struct emac_adapter *adpt,
+			     struct emac_tx_queue *tx_q, struct sk_buff *skb,
+			     struct emac_tpd *tpd)
+{
+	u16 nr_frags = skb_shinfo(skb)->nr_frags;
+	unsigned int len = skb_headlen(skb);
+	struct emac_buffer *tpbuf = NULL;
+	unsigned int mapped_len = 0;
+	unsigned int i;
+	int ret;
+
+	/* if Large Segment Offload is (in TCP Segmentation Offload struct) */
+	if (TPD_LSO(tpd)) {
+		mapped_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
+
+		tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
+		tpbuf->length = mapped_len;
+		tpbuf->dma_addr = dma_map_single(adpt->netdev->dev.parent,
+						 skb->data, mapped_len,
+						 DMA_TO_DEVICE);
+		ret = dma_mapping_error(adpt->netdev->dev.parent,
+					tpbuf->dma_addr);
+		if (ret) {
+			dev_kfree_skb(skb);
+			return;
Quoted 8 lines

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

Quoted 4 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +4 -0
+		}
+
+		TPD_BUFFER_ADDR_L_SET(tpd, lower_32_bits(tpbuf->dma_addr));
+		TPD_BUFFER_ADDR_H_SET(tpd, upper_32_bits(tpbuf->dma_addr));

You should also take big endian systems into account. This means that if the multi-byte values in the descriptors require little-endian you have to convert from host byte order to le and vice versa. You can use cpu_to_le32() and friends for this.

I used to work on PowerPC, so I respect making things work for both endians. However, even I think that this is overkill for my driver. First, there's no way this driver will ever be used on a big-endian system. Second, I'm pretty sure there are lots of places that would need cpu_to_le32() in order to make this driver big-endian compatible. It would be a huge mess.

#define TPD_BUFFER_ADDR_H_SET(tpd, val) BITS_SET((tpd)->word[3], 18, 30, val)

This macros sets specific bits based on the definition of the register.
I could change it to this:

#define TPD_BUFFER_ADDR_H_SET(tpd, val) BITS_SET((tpd)->word[3], 18, 30, cpu_to_le32(val))

But I honestly don't see what good that will do. There are still thousands of other places that assume little-endian.

Quoted 33 lines
Quoted 33 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +33 -0
+		TPD_BUF_LEN_SET(tpd, tpbuf->length);
+		emac_tx_tpd_create(adpt, tx_q, tpd);
+	}
+
+	if (mapped_len < len) {
+		tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
+		tpbuf->length = len - mapped_len;
+		tpbuf->dma_addr = dma_map_single(adpt->netdev->dev.parent,
+						 skb->data + mapped_len,
+						 tpbuf->length, DMA_TO_DEVICE);
+		ret = dma_mapping_error(adpt->netdev->dev.parent,
+					tpbuf->dma_addr);
+		if (ret) {
+			dev_kfree_skb(skb);
+			return;
+		}
+
+		TPD_BUFFER_ADDR_L_SET(tpd, lower_32_bits(tpbuf->dma_addr));
+		TPD_BUFFER_ADDR_H_SET(tpd, upper_32_bits(tpbuf->dma_addr));
+		TPD_BUF_LEN_SET(tpd, tpbuf->length);
+		emac_tx_tpd_create(adpt, tx_q, tpd);
+	}
+
+	for (i = 0; i < nr_frags; i++) {
+		struct skb_frag_struct *frag;
+
+		frag = &skb_shinfo(skb)->frags[i];
+
+		tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
+		tpbuf->length = frag->size;
+		tpbuf->dma_addr = dma_map_page(adpt->netdev->dev.parent,
+					       frag->page.p, frag->page_offset,
+					       tpbuf->length, DMA_TO_DEVICE);
Quoted 8 lines

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

Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+		ret = dma_mapping_error(adpt->netdev->dev.parent,
+					tpbuf->dma_addr);
+		if (ret) {
+			dev_kfree_skb(skb);
+			return;
+		}

In case of error you need to undo all mappings that you have done so far.

Ok.

Quoted 14 lines

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

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +9 -0
+
+		TPD_BUFFER_ADDR_L_SET(tpd, lower_32_bits(tpbuf->dma_addr));
+		TPD_BUFFER_ADDR_H_SET(tpd, upper_32_bits(tpbuf->dma_addr));
+		TPD_BUF_LEN_SET(tpd, tpbuf->length);
+		emac_tx_tpd_create(adpt, tx_q, tpd);
+	}
+
+	/* The last tpd */
+	emac_tx_tpd_mark_last(adpt, tx_q);

Use a wmb() here to make sure that all writes to the descriptors in dma memory are completed before you update the producer register (see memory-barriers.txt for the reason why this is needed)

Ok.

Quoted 28 lines
Quoted 28 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +28 -0
+/* Transmit the packet using specified transmit queue */
+int emac_mac_tx_buf_send(struct emac_adapter *adpt, struct emac_tx_queue *tx_q,
+			 struct sk_buff *skb)
+{
+	struct emac_tpd tpd;
+	u32 prod_idx;
+
+	memset(&tpd, 0, sizeof(tpd));
+
+	if (emac_tso_csum(adpt, tx_q, skb, &tpd) != 0) {
+		dev_kfree_skb_any(skb);
+		return NETDEV_TX_OK;
+	}
+
+	if (skb_vlan_tag_present(skb)) {
+		u16 tag;
+
+		EMAC_VLAN_TO_TAG(skb_vlan_tag_get(skb), tag);
+		TPD_CVLAN_TAG_SET(&tpd, tag);
+		TPD_INSTC_SET(&tpd, 1);
+	}
+
+	if (skb_network_offset(skb) != ETH_HLEN)
+		TPD_TYP_SET(&tpd, 1);
+
+	emac_tx_fill_tpd(adpt, tx_q, skb, &tpd);
+
+	netdev_sent_queue(adpt->netdev, skb->len);
Quoted 8 lines

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

Quoted 3 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+
+	if (emac_tpd_num_free_descs(tx_q) <= (MAX_SKB_FRAGS + 1))
+		netif_stop_queue(adpt->netdev);

Is MAX_SKB_FRAGS + 1 really the max number of descriptors required by your driver? There seem to be further descriptors needed for TSO and checksumming. Please make sure that you really check against the _max_ possible number of descriptors for a transmission.

I need some help figuring that out. Like I said, I didn't write this driver initially, so there are parts that I don't really understand. I copied the above code from other drivers, but after studying your question, I think I understand what you're asking. I just don't know how to fix it.

First of all, why do other drivers test MAX_SKB_FRAGS + 1? Why the +1?

The driver originally used function emac_tx_has_enough_descs() to determine if there is enough room for the new packet. Then I changed the code as you suggested, and now it guesses how many descriptors need to be free to support the next packet.

If I'm reading emac_tx_fill_tpd() correctly, there could be as many as (2 + skb_shinfo(skb)->nr_frags) descriptors for a given packet. I don't know how big nr_frags could get, so I don't know how to calculate the number of descriptors I really need. I'm assuming I need to do something like this:

unsigned int max_desc_per_skb = 2 + ????;
unsigned int num_desc_needed = (MAX_SKB_FRAGS + 1) * max_desc_per_skb;

if (emac_tpd_num_free_descs(tx_q) < num_desc_needed)

	netif_stop_queue(adpt->netdev);
Quoted 20 lines
Quoted 20 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +20 -0
+
+/* Change the Maximum Transfer Unit (MTU) */
+static int emac_change_mtu(struct net_device *netdev, int new_mtu)
+{
+	unsigned int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
+	struct emac_adapter *adpt = netdev_priv(netdev);
+
+	if ((max_frame < EMAC_MIN_ETH_FRAME_SIZE) ||
+	    (max_frame > EMAC_MAX_ETH_FRAME_SIZE)) {
+		netdev_err(adpt->netdev, "error: invalid MTU setting\n");
+		return -EINVAL;
+	}
+
+	netif_info(adpt, hw, adpt->netdev,
+		   "changing MTU from %d to %d\n", netdev->mtu,
+		   new_mtu);
+	netdev->mtu = new_mtu;
+	adpt->rxbuf_size = new_mtu > EMAC_DEF_RX_BUF_SIZE ?
+		ALIGN(max_frame, 8) : EMAC_DEF_RX_BUF_SIZE;
+
Quoted 8 lines

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

Quoted 2 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +2 -0
+	if (netif_running(netdev))
+		return emac_reinit_locked(adpt);

This does still not look correct. The rxbuf_size is changed while the interface is still running. If the rx buffers are refilled now, the rx buffers size does not match the size that is configured in the mac, does it?
You have to stop the rx path first, then change the rx buffer size and then restart the rx path.

Ok. Thanks for catching that. I didn't notice that adpt->rxbuf_size was used in emac_mac_rx_descs_refill().

However, I'm confused about one thing. Almost every other driver just sets "netdev->mtu = new_mtu" and does nothing else. I can't find any other driver that actually stops the RX path, reprograms the hardware, and then restarts the RX path. I know this is a stupid question, but why is my driver doing that?

Can I get away with just calling netdev_update_features()?

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.
#28 lore raw
In reply to a message not in the archive
Quoted 46 lines · Timur Tabi
Quoted 34 lines · Lino Sanfilippo
Quoted 34 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+/* Fill up transmit descriptors */
+static void emac_tx_fill_tpd(struct emac_adapter *adpt,
+                            struct emac_tx_queue *tx_q, struct sk_buff

*skb,

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +10 -0
+                            struct emac_tpd *tpd)
+{
+       u16 nr_frags = skb_shinfo(skb)->nr_frags;
+       unsigned int len = skb_headlen(skb);
+       struct emac_buffer *tpbuf = NULL;
+       unsigned int mapped_len = 0;
+       unsigned int i;
+       int ret;
+
+       /* if Large Segment Offload is (in TCP Segmentation Offload

struct) */

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+       if (TPD_LSO(tpd)) {
+               mapped_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
+
+               tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
+               tpbuf->length = mapped_len;
+               tpbuf->dma_addr =

dma_map_single(adpt->netdev->dev.parent,

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +10 -0
+                                                skb->data, mapped_len,
+                                                DMA_TO_DEVICE);
+               ret = dma_mapping_error(adpt->netdev->dev.parent,
+                                       tpbuf->dma_addr);
+               if (ret) {
+                       dev_kfree_skb(skb);
+                       return;
+               }
+
+               TPD_BUFFER_ADDR_L_SET(tpd,

lower_32_bits(tpbuf->dma_addr));
+ TPD_BUFFER_ADDR_H_SET(tpd,

Quoted 8 lines
Quoted 1 line

upper_32_bits(tpbuf->dma_addr));

You should also take big endian systems into account. This means that if the multi-byte values
in the descriptors require little-endian you have to convert from host byte order to le and
vice versa. You can use cpu_to_le32() and friends for this.

Quoted 5 lines

I used to work on PowerPC, so I respect making things work for both endians. However, even I think that this is overkill for my driver. First, there's no way this driver will ever be used on a big-endian system. Second, I'm pretty sure there are lots of places that would need cpu_to_le32() in order to make this driver big-endian compatible. It would be a huge mess.

I thought that too about Calxeda systems and then someone went off and made them run BE. I was surprised it worked, but I guess when the h/w doesn't try to do swizzling of i/o things just work.

Rob
--
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

#30 lore raw
In reply to Timur Tabi
Quoted 7 lines · Timur Tabi

I need some help figuring that out. Like I said, I didn't write this driver initially, so there are parts that I don't really understand. I copied the above code from other drivers, but after studying your question, I think I understand what you're asking. I just don't know how to fix it.

First of all, why do other drivers test MAX_SKB_FRAGS + 1? Why the +1?

The 1 is for the non-fragment part of the SKB, like its head.

Quoted 5 lines

The driver originally used function emac_tx_has_enough_descs() to determine if there is enough room for the new packet. Then I changed the code as you suggested, and now it guesses how many descriptors need to be free to support the next packet.

That seems fine and expected.

Quoted 6 lines

If I'm reading emac_tx_fill_tpd() correctly, there could be as many as (2 + skb_shinfo(skb)->nr_frags) descriptors for a given packet. I don't know how big nr_frags could get, so I don't know how to calculate the number of descriptors I really need. I'm assuming I need to do something like this:

nr_frags can't be bigger than MAX_SKB_FRAGS, hence these checks all other drivers do against 1 + MAX_SKB_FRAGS.

Quoted 6 lines

However, I'm confused about one thing. Almost every other driver just sets "netdev->mtu = new_mtu" and does nothing else. I can't find any other driver that actually stops the RX path, reprograms the hardware, and then restarts the RX path. I know this is a stupid question, but why is my driver doing that?

Most drivers allocate RX buffer sizes that are usually bigger than the MTU, but would probably silently fail or expose transient behavior once the MTU changes to greater than the size pre-defined.

Quoted 2 lines

Can I get away with just calling netdev_update_features()?

MTU change is a pretty disruptive change for the HW I typically work with since we need to choose a RX buffer size that is aligned to the DRAM controller burst size, reprogram the MAC to accept packets up to that size, and potentially change the RX ring allocation strategy and typical buffer size. None of these requirements are unusual or unique, they ost likely apply to most MACs out there, my guess is that MTU change is barely tested.

Signature · 1 line
Florian
#29 lore raw
In reply to a message not in the archive
Quoted 10 lines · Timur Tabi

I used to work on PowerPC, so I respect making things work for both endians. However, even I think that this is overkill for my driver. First, there's no way this driver will ever be used on a big-endian system. Second, I'm pretty sure there are lots of places that would need cpu_to_le32() in order to make this driver big-endian compatible. It would be a huge mess.

#define TPD_BUFFER_ADDR_H_SET(tpd, val) BITS_SET((tpd)->word[3], 18,
30, val)

Quoted 8 lines

This macros sets specific bits based on the definition of the register.
I could change it to this:

#define TPD_BUFFER_ADDR_H_SET(tpd, val) BITS_SET((tpd)->word[3], 18, 30, cpu_to_le32(val))

But I honestly don't see what good that will do. There are still thousands of other places that assume little-endian.

Ok, so I took another look at this, and even though I still think that it's useless, it seems to be much less difficult to implement than I initially thought.

I think all I need to do is to modify the BITS_GET() and BITS_SET() macros in emac-mac.h, as well as any of the RRD_xxx and TPD_xxx macros that do not use BITS_GET() or BITS_SET(). This is a minor change which I will implement in v8 of the patch.

Every other hardware access uses readl/writel, which is already endian-safe.

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
#32 lore raw
In reply to a message not in the archive
Quoted 2 lines · Florian Fainelli

nr_frags can't be bigger than MAX_SKB_FRAGS, hence these checks all other drivers do against 1 + MAX_SKB_FRAGS.

Doh, I just realized something. emac_mac_tx_buf_send() just needs to make sure that there's enough room for ONE skb. For some reason I thought it had to make sure there's enough room for multiple SKBs.

Now it makes a lot more sense. Thank you.

So it looks like a given SKB can occupy 3 + nr_frags descriptors. So I need to change that line to:

	if (emac_tpd_num_free_descs(tx_q) < (MAX_SKB_FRAGS + 3))
		netif_stop_queue(adpt->netdev);

Question, some drivers do <= instead of just <, like this:

	if (ring->free_bds <= (MAX_SKB_FRAGS + 1))
		netif_tx_stop_queue(txq);

Is it necessary to stop the queue if there exactly enough descriptors to hold an SKB? Shouldn't the above be this instead:

	if (ring->free_bds < (MAX_SKB_FRAGS + 1))
		netif_tx_stop_queue(txq);
Quoted 9 lines
Quoted 5 lines

However, I'm confused about one thing. Almost every other driver just sets "netdev->mtu = new_mtu" and does nothing else. I can't find any other driver that actually stops the RX path, reprograms the hardware, and then restarts the RX path. I know this is a stupid question, but why is my driver doing that?

Most drivers allocate RX buffer sizes that are usually bigger than the MTU, but would probably silently fail or expose transient behavior once the MTU changes to greater than the size pre-defined.

So it looks like the real problem is a race condition between

	adpt->rxbuf_size = new_mtu > EMAC_DEF_RX_BUF_SIZE ?
		ALIGN(max_frame, 8) : EMAC_DEF_RX_BUF_SIZE;

and

	if (netif_running(netdev))
		return emac_reinit_locked(adpt);

That is, if the interface is running, I set rxbuf_size. If suddenly I receive some packets, then the driver will use the wrong buffer size.

Is there an easy way for me to stop the RX path before I set rxbuf_size?
Some netif_xxx function I can call?

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
#33 lore raw
Quoted 19 lines · Timur Tabi
Quoted 2 lines · Florian Fainelli

nr_frags can't be bigger than MAX_SKB_FRAGS, hence these checks all other drivers do against 1 + MAX_SKB_FRAGS.

Doh, I just realized something. emac_mac_tx_buf_send() just needs to make sure that there's enough room for ONE skb. For some reason I thought it had to make sure there's enough room for multiple SKBs.

Now it makes a lot more sense. Thank you.

So it looks like a given SKB can occupy 3 + nr_frags descriptors. So I need to change that line to:

    if (emac_tpd_num_free_descs(tx_q) < (MAX_SKB_FRAGS + 3))
        netif_stop_queue(adpt->netdev);

Question, some drivers do <= instead of just <, like this:

Quoted 8 lines
    if (ring->free_bds <= (MAX_SKB_FRAGS + 1))
        netif_tx_stop_queue(txq);

Is it necessary to stop the queue if there exactly enough descriptors to hold an SKB? Shouldn't the above be this instead:

    if (ring->free_bds < (MAX_SKB_FRAGS + 1))
        netif_tx_stop_queue(txq);

Humm, it kind of depends, but I would err on the side of strictly lesser than as a better behavior where you may still allow a full fragmented SKB to make it through on the next xmit call (I know the code you quote is exactly not doing that).

Quoted 17 lines
Quoted 11 lines
Quoted 7 lines

However, I'm confused about one thing. Almost every other driver just sets "netdev->mtu = new_mtu" and does nothing else. I can't find any other driver that actually stops the RX path, reprograms the hardware, and then restarts the RX path. I know this is a stupid question, but why is my driver doing that?

Most drivers allocate RX buffer sizes that are usually bigger than the MTU, but would probably silently fail or expose transient behavior once the MTU changes to greater than the size pre-defined.

So it looks like the real problem is a race condition between

    adpt->rxbuf_size = new_mtu > EMAC_DEF_RX_BUF_SIZE ?
        ALIGN(max_frame, 8) : EMAC_DEF_RX_BUF_SIZE;
Quoted 8 lines

and

    if (netif_running(netdev))
        return emac_reinit_locked(adpt);

That is, if the interface is running, I set rxbuf_size. If suddenly I receive some packets, then the driver will use the wrong buffer size.

Correct, and possibly other HW settings that you have may have to program to tell the MAC what the maximum packet length should be.

Quoted 3 lines

Is there an easy way for me to stop the RX path before I set rxbuf_size?
Some netif_xxx function I can call?

napi_disable() should take care of that.

Signature · 1 line
Florian
author
#34 lore raw
Quoted 3 lines · Florian Fainelli
Quoted 2 lines
Quoted 2 lines

Is there an easy way for me to stop the RX path before I set rxbuf_size?
Some netif_xxx function I can call?

napi_disable() should take care of that.

It appears that if I call netif_stop_queue() *afer* calling napi_disable(), I get a hang and/or TX timeout. Since emac_mac_down() does this:

	netif_stop_queue(netdev);
	napi_disable(&adpt->rx_q.napi);

I cannot call just napi_disable() in emac_change_mtu(), because when I then call emac_mac_down(), the first thing it does is call netif_stop_queue(), and that's when I timeout/hang.

Unfortunately, I cannot even do this:

	netif_stop_queue(netdev);
	napi_disable(&adpt->rx_q.napi);
	netif_stop_queue(netdev);
	napi_disable(&adpt->rx_q.napi);

Even though I've already called netif_stop_queue(), calling it again causes the timeout/hang.

Is this expected? I never understood why I needed to call netif_stop_queue() before napi_disable(). I do see some drivers do not call netif_stop_queue(). I even saw a driver that calls them in reverse order, so I don't understand why that sequence breaks for me but not him.

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.
#35 lore raw
Quoted 10 lines · Timur Tabi
Quoted 4 lines · Florian Fainelli
Quoted 3 lines
Quoted 1 line

Is there an easy way for me to stop the RX path before I set

rxbuf_size?

Quoted 1 line

Some netif_xxx function I can call?

napi_disable() should take care of that.

It appears that if I call netif_stop_queue() *afer* calling napi_disable(), I get a hang and/or TX timeout. Since emac_mac_down() does this:

Quoted 6 lines
    netif_stop_queue(netdev);
    napi_disable(&adpt->rx_q.napi);

I cannot call just napi_disable() in emac_change_mtu(), because when I then call emac_mac_down(), the first thing it does is call netif_stop_queue(), and that's when I timeout/hang.

Whatever emac_mac_down() does you can unroll it in the change_mtu callback anyway, so if this a problematic sequence you can work around it.

Quoted 10 lines

Unfortunately, I cannot even do this:

    netif_stop_queue(netdev);
    napi_disable(&adpt->rx_q.napi);
    netif_stop_queue(netdev);
    napi_disable(&adpt->rx_q.napi);

Even though I've already called netif_stop_queue(), calling it again causes the timeout/hang.

Buf if this is really what you copy/pasted here, why do this twice anyway?

Quoted 6 lines

Is this expected? I never understood why I needed to call netif_stop_queue() before napi_disable(). I do see some drivers do not call netif_stop_queue(). I even saw a driver that calls them in reverse order, so I don't understand why that sequence breaks for me but not him.

Not clear how the two relate with each other here, must be specific to your driver implementation somehow.

Signature · 1 line
Florian
author
#36 lore raw
Quoted 8 lines · Florian Fainelli
Quoted 6 lines
     netif_stop_queue(netdev);
Quoted 5 lines
    napi_disable(&adpt->rx_q.napi);

I cannot call just napi_disable() in emac_change_mtu(), because when I then call emac_mac_down(), the first thing it does is call netif_stop_queue(), and that's when I timeout/hang.

Whatever emac_mac_down() does you can unroll it in the change_mtu callback anyway, so if this a problematic sequence you can work around it.

I'm having difficulty coming up with an actual sequence that works. This odd interaction between netif_stop_queue() and napi_disable() is giving me inconsistent results.

The hang occurs with this loop in napi_disable():

	while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
		msleep(1);

This loop never exits. Can you give me a clue as to what could be the reason?

Quoted 11 lines
Quoted 9 lines
Quoted 9 lines

Unfortunately, I cannot even do this:

    netif_stop_queue(netdev);
    napi_disable(&adpt->rx_q.napi);
    netif_stop_queue(netdev);
    napi_disable(&adpt->rx_q.napi);

Even though I've already called netif_stop_queue(), calling it again causes the timeout/hang.

Buf if this is really what you copy/pasted here, why do this twice anyway?

Sorry, what I meant was that I was hoping that *both* emac_change_mtu() and emac_mac_down() could do

	netif_stop_queue(netdev);
	napi_disable(&adpt->rx_q.napi);

Which would have the effect of what I wrote above.

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.
author
#37 lore raw
Quoted 8 lines · Timur Tabi

The hang occurs with this loop in napi_disable():

     while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
         msleep(1);

This loop never exits. Can you give me a clue as to what could be the reason?

I figured it out. I cannot call napi_disable() twice in a row. It's not smart enough to know that NAPI is already disabled.

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.
author
#38 lore raw
Quoted 4 lines · Timur Tabi
Quoted 4 lines

The hang occurs with this loop in napi_disable():

Quoted 8 lines
Quoted 5 lines
     while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
         msleep(1);

This loop never exits. Can you give me a clue as to what could be the reason?

I figured it out. I cannot call napi_disable() twice in a row. It's not smart enough to know that NAPI is already disabled.

I realized that I was going about this the wrong way. Rather than try to protect the setting of adpt->rxbuf_size, I instead just calculate that value when RX path is configured, which is much cleaner. This ensures that adpt->rxbuf_size is changed only when the interface is down.

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.
author
#4 lore raw
In reply to Rob Herring

+ Rafael and Al, for ACPI help.

Quoted 5 lines · Rob Herring
Quoted 2 lines
Quoted 2 lines

+Optional properties:
+- phy-version : the version of the integrated emac phy, either 1 or 2.

Sounds like 2 different h/w. The compatible property should distinguish this.

So I implemented this in v8 of my driver, but it is causing problems for ACPI.

In ACPI, the equivalent to a compatible string is the HID, which is QCOM8070 for the EMAC. The problem is that it's very difficult, if not impossible, to create new HIDs for different versions of the same device.

The driver will primarily (if not exclusively) be used on ACPI platforms, not DT. In Qualcomm, DT is for mobile chips, and ACPI is for server. To my knowledge, there are no plans to use this driver on an actual DT-enabled platform, but I want to support DT anyway.

The other problem is that the "internal PHY" of the EMAC is technically a separate device, and it's interchangeable. Future versions of our chips will use different internal PHYs, but the EMAC will stay the same.

So I would like a solution that works on DT and ACPI. I suppose I could use compatible strings on DT, and a "phy-version" DSD (property) on ACPI. If that's acceptable to everyone, then I can do that. It seems clunky to me.

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.
maintainer
#5 lore raw
Quoted 12 lines · Timur Tabi

+ Rafael and Al, for ACPI help.

Quoted 7 lines · Rob Herring
Quoted 3 lines
Quoted 3 lines

+Optional properties:
+- phy-version : the version of the integrated emac phy, either 1 or 2.

Sounds like 2 different h/w. The compatible property should distinguish this.

Quoted 6 lines

So I implemented this in v8 of my driver, but it is causing problems for ACPI.

In ACPI, the equivalent to a compatible string is the HID, which is QCOM8070 for the EMAC. The problem is that it's very difficult, if not impossible, to create new HIDs for different versions of the same device.

Different versions are different devices IMO.

Quoted 8 lines

The driver will primarily (if not exclusively) be used on ACPI platforms, not DT. In Qualcomm, DT is for mobile chips, and ACPI is for server. To my knowledge, there are no plans to use this driver on an actual DT-enabled platform, but I want to support DT anyway.

The other problem is that the "internal PHY" of the EMAC is technically a separate device, and it's interchangeable. Future versions of our chips will use different internal PHYs, but the EMAC will stay the same.

How do you know? EMAC could just as easily change. It's Gigabit today, 10G tomorrow.

But if it is separate, then maybe you should model it as a separate device using the phy binding.

Quoted 3 lines

So I would like a solution that works on DT and ACPI. I suppose I could use compatible strings on DT, and a "phy-version" DSD (property) on ACPI. If that's acceptable to everyone, then I can do that. It seems clunky to me.

On one hand, why should I care about ACPI for defining DT bindings? OTOH, having a phy-version property alone would not be a big deal, but you still need distinct compatible strings regardless.

Rob

author
#6 lore raw
Quoted 5 lines · Rob Herring
Quoted 3 lines

In ACPI, the equivalent to a compatible string is the HID, which is QCOM8070 for the EMAC. The problem is that it's very difficult, if not impossible, to create new HIDs for different versions of the same device.

Different versions are different devices IMO.

Not that I disagree, but this appears to be an inherent problem with ACPI. The namespace for ACPI HIDs is very limited. We only really have control over the last two digits.

Quoted 6 lines
Quoted 3 lines

The other problem is that the "internal PHY" of the EMAC is technically a separate device, and it's interchangeable. Future versions of our chips will use different internal PHYs, but the EMAC will stay the same.

How do you know? EMAC could just as easily change. It's Gigabit today, 10G tomorrow.

My point is that the EMAC part won't change for the foreseeable future, but I know the internal PHY component will change. The new "version" of the EMAC/PHY combo on a future chip will have the same ACPI HID. So I need some other way to differentiate the two. I can't query the hardware, because the EMAC half will be identical.

Quoted 2 lines

But if it is separate, then maybe you should model it as a separate device using the phy binding.

It's only separate in hardware. The driver controls both parts as a unified whole.

Quoted 7 lines
Quoted 3 lines

So I would like a solution that works on DT and ACPI. I suppose I could use compatible strings on DT, and a "phy-version" DSD (property) on ACPI. If that's acceptable to everyone, then I can do that. It seems clunky to me.

On one hand, why should I care about ACPI for defining DT bindings? OTOH, having a phy-version property alone would not be a big deal, but you still need distinct compatible strings regardless.

So you're saying that it's okay to have separate compatible strings AND a phy-version property? That would solve the problem.

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.
#7 lore raw
Quoted 11 lines · Timur Tabi
Quoted 5 lines · Rob Herring
Quoted 3 lines

In ACPI, the equivalent to a compatible string is the HID, which is QCOM8070 for the EMAC. The problem is that it's very difficult, if not impossible, to create new HIDs for different versions of the same device.

Different versions are different devices IMO.

Not that I disagree, but this appears to be an inherent problem with ACPI. The namespace for ACPI HIDs is very limited. We only really have control over the last two digits.

My apologies if the stuff below is things you already know...I never know how much people already know about ACPI, and sometimes just don't know when to shut up :).

An _HID is a three or four character company ID followed by four digits that the company decides on. The only thing the ASWG (ACPI Spec Working Group) controls are those first characters; you can do whatever you'd like with the four digits that follow.

Not knowing enough about the products in mind here, or future plans for them, I'd recommend taking a look at section 6.1 of the spec. There's an ACPI object called _HRV (Hardware Revision) that may do what you need; there is also the _CID (Compatible ID), or if this is a PCI device, perhaps the _CLS (Class Code) can be used. I guess what I'm really trying to say is that the "name space" mentioned here [*] is not that limited and has quite a bit of flexibility.

[*] "ACPI namespace" has a fairly specific meaning that is different.

Quoted 22 lines
Quoted 6 lines
Quoted 3 lines

The other problem is that the "internal PHY" of the EMAC is technically a separate device, and it's interchangeable. Future versions of our chips will use different internal PHYs, but the EMAC will stay the same.

How do you know? EMAC could just as easily change. It's Gigabit today, 10G tomorrow.

My point is that the EMAC part won't change for the foreseeable future, but I know the internal PHY component will change. The new "version" of the EMAC/PHY combo on a future chip will have the same ACPI HID. So I need some other way to differentiate the two. I can't query the hardware, because the EMAC half will be identical.

Quoted 2 lines

But if it is separate, then maybe you should model it as a separate device using the phy binding.

It's only separate in hardware. The driver controls both parts as a unified whole.

Quoted 4 lines
Quoted 3 lines

So I would like a solution that works on DT and ACPI. I suppose I could use compatible strings on DT, and a "phy-version" DSD (property) on ACPI. If that's acceptable to everyone, then I can do that. It seems clunky to me.

Quoted 7 lines
Quoted 3 lines

On one hand, why should I care about ACPI for defining DT bindings? OTOH, having a phy-version property alone would not be a big deal, but you still need distinct compatible strings regardless.

So you're saying that it's okay to have separate compatible strings AND a phy-version property? That would solve the problem.

Does the ACPI portion of the driver *have* to know about the PHY? In general, the ACPI assumption on ARM [**] is that those have all been set up before we get to the kernel. So, does it need to be visible to the ACPI part of the driver at all?

[**] See Documentation/arm64/arm-acpi.txt.

Signature · 8 lines
ciao,
al
-----------------------------------
Al Stone
Software Engineer
Linaro Enterprise Group
[email protected]
-----------------------------------
author
#8 lore raw
Quoted 4 lines · Al Stone

Does the ACPI portion of the driver*have* to know about the PHY? In general, the ACPI assumption on ARM [**] is that those have all been set up before we get to the kernel. So, does it need to be visible to the ACPI part of the driver at all?

Yes, the driver supports both "v1" and "v2" of the PHY, and it has code like this:

	if (adpt->phy.version == 2)
		emac_sgmii_init_v2(adpt);
	else
		emac_sgmii_init_v1(adpt);

The question, how should adpt->phy.version be initialized on device tree and ACPI platforms?

The reason why this is confusing is because there are conflicting perspectives of this "internal PHY". It both is and is not part of the EMAC. It is a separate block in the chip, and can be replaced with other SGMII blocks, and in the future there will be a "v3" and maybe a "v4" or who knows what. In fact, maybe using version numbers is inappropriate and we'll need to use vendor names or something.

The problem is that the internal PHY has mechanism for self-identification. There is no ACPI or device tree node for it. There is no register you can query to see if it's there or what version it is. The MAC part of the EMAC has no knowledge of the PHY part. The driver just has to know it's there.

This is why I'm advocating a separate property (DT and ACPI) to identify the internal PHY.

The truth is that I don't really care HOW it's done, and as long as we come to a consensus soon. I want my driver to be merged into 4.9.

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.
author
#9 lore raw
Quoted 11 lines · Timur Tabi

The question, how should adpt->phy.version be initialized on device tree and ACPI platforms?

The reason why this is confusing is because there are conflicting perspectives of this "internal PHY". It both is and is not part of the EMAC. It is a separate block in the chip, and can be replaced with other SGMII blocks, and in the future there will be a "v3" and maybe a "v4" or who knows what. In fact, maybe using version numbers is inappropriate and we'll need to use vendor names or something.

Quoted 8 lines

The problem is that the internal PHY has mechanism for self-identification. There is no ACPI or device tree node for it. There is no register you can query to see if it's there or what version it is. The MAC part of the EMAC has no knowledge of the PHY part. The driver just has to know it's there.

This is why I'm advocating a separate property (DT and ACPI) to identify the internal PHY.

So we had some internal discussion on this. Different compatible properties for DT are okay, and for ACPI we'll either create a "phy-version" property (DT-like properties are called DSDs in ACPI) or use an HRV (a specific property for the hardware version).

But this speaks to the greater problem of mapping DT compatible strings to ACPI. Like I said, the ACPI equivalent of a compatible string is the HID. But unlike DT, we cannot create new HIDs whenever we feel like it.
The process for generating and assigning HIDs is much more involved,
and we do have a very limited namespace.

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.
#11 lore raw
In reply to a message not in the archive
Quoted 20 lines · Timur Tabi
Quoted 7 lines · Al Stone

Does the ACPI portion of the driver*have* to know about the PHY? In general,
the ACPI assumption on ARM [**] is that those have all been set up before we
get to the kernel. So, does it need to be visible to the ACPI part of the
driver at all?

Yes, the driver supports both "v1" and "v2" of the PHY, and it has code like this:

    if (adpt->phy.version == 2)
        emac_sgmii_init_v2(adpt);
    else
        emac_sgmii_init_v1(adpt);

The question, how should adpt->phy.version be initialized on device tree and ACPI platforms?

Quoted 6 lines

The reason why this is confusing is because there are conflicting perspectives of this "internal PHY". It both is and is not part of the EMAC. It is a separate block in the chip, and can be replaced with other SGMII blocks, and in the future there will be a "v3" and maybe a "v4" or who knows what. In fact, maybe using version numbers is inappropriate and we'll need to use vendor names or something.

If it has self identification, and the MAC is capable of knowing what kind of PHY it is internally bundled with, why does it matter to represent that specific piece of information in Device Tree or ACPI?

Quoted 6 lines

The problem is that the internal PHY has mechanism for self-identification. There is no ACPI or device tree node for it. There is no register you can query to see if it's there or what version it is. The MAC part of the EMAC has no knowledge of the PHY part. The driver just has to know it's there.

Nothing prevents you from detailing in ACPI or DT sub-components of a larger HW block, if there is such a desire, but just make it in a way that it looks like what would be done for e.g: separate discrete parts, only the parenting of nodes would change.

Quoted 7 lines

This is why I'm advocating a separate property (DT and ACPI) to identify the internal PHY

The truth is that I don't really care HOW it's done, and as long as we come to a consensus soon. I want my driver to be merged into 4.9.

Signature · 5 lines
Florian
--
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
#12 lore raw
Quoted 3 lines · Florian Fainelli

If it has self identification, and the MAC is capable of knowing what kind of PHY it is internally bundled with, why does it matter to represent that specific piece of information in Device Tree or ACPI?

That's the thing - the MAC is not capable of knowing. From a hardware perspective, the MAC and PHY are physically distinct IP blocks, and so the MAC hardware has no idea what it's really connected to. In theory, we don't even need an internal PHY, but if there is an internal PHY, we have to program it correctly.

This is why we need a DT and ACPI property (or whatever) to tell the driver what kind of PHY it's attached to.

Quoted 10 lines
Quoted 5 lines

The problem is that the internal PHY has mechanism for self-identification. There is no ACPI or device tree node for it. There is no register you can query to see if it's there or what version it is. The MAC part of the EMAC has no knowledge of the PHY part. The driver just has to know it's there.

Nothing prevents you from detailing in ACPI or DT sub-components of a larger HW block, if there is such a desire, but just make it in a way that it looks like what would be done for e.g: separate discrete parts, only the parenting of nodes would change.

So instead of just having a single property, instead create a child node just for the SGMII phy, with its own compatible string and various other properties (like interrupt and base register)? That's not a bad idea.

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.
#14 lore raw
In reply to a message not in the archive
Quoted 9 lines · Timur Tabi
Quoted 5 lines

Nothing prevents you from detailing in ACPI or DT sub-components of a larger HW block, if there is such a desire, but just make it in a way that it looks like what would be done for e.g: separate discrete parts, only the parenting of nodes would change.

So instead of just having a single property, instead create a child node just for the SGMII phy, with its own compatible string and various other properties (like interrupt and base register)? That's not a bad idea.

I need help getting this to work.

	emac0: ethernet@38800000 {
		compatible = "qcom,qdf2432-emac";
		reg-names = "base", "csr";
                reg = <0x0 0x38800000 0x0 0x10000 >,
                        <0x0 0x38816000 0x0 0x1000>,
                        <0x0 0x3881C000 0x0 0x4000>;
		interrupts = <0 0x100 0 0 0x104 0>;
		interrupt-names = "core0", "sgmii";

		sgmii-handle = <&emac_sgmii>;
		phy-handle = <&phy0>;

		#address-cells = <1>;
		#size-cells = <0>;
		phy0: ethernet-phy@4 {
			reg = <4>;
		};
	};

	emac_sgmii: ethernet-phy@410400 {
		compatible = "qcom,qdf2432-emac-phy";
		reg = <0x0 0x00410400 0x0 0x100>;
		interrupts = <0 0x104 0>;
	};

When my driver probes, the platform_device object points to the emac0 node, as always.

How do I parse the emac_sgmii node? How do I get functions like platform_get_resource() to work? How do I create a new platform_device object that points to the emac_sgmii node?

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
#16 lore raw
In reply to a message not in the archive
Quoted 29 lines · Timur Tabi
Quoted 9 lines · Timur Tabi
Quoted 5 lines

Nothing prevents you from detailing in ACPI or DT sub-components of a larger HW block, if there is such a desire, but just make it in a way that it looks like what would be done for e.g: separate discrete parts, only the parenting of nodes would change.

So instead of just having a single property, instead create a child node just for the SGMII phy, with its own compatible string and various other properties (like interrupt and base register)? That's not a bad idea.

I need help getting this to work.

    emac0: ethernet@38800000 {
        compatible = "qcom,qdf2432-emac";
        reg-names = "base", "csr";
                reg = <0x0 0x38800000 0x0 0x10000 >,
                        <0x0 0x38816000 0x0 0x1000>,
                        <0x0 0x3881C000 0x0 0x4000>;
        interrupts = <0 0x100 0 0 0x104 0>;
        interrupt-names = "core0", "sgmii";

        sgmii-handle = <&emac_sgmii>;
        phy-handle = <&phy0>;

        #address-cells = <1>;
        #size-cells = <0>;
        phy0: ethernet-phy@4 {
            reg = <4>;
Quoted 9 lines
        };
    };

    emac_sgmii: ethernet-phy@410400 {
        compatible = "qcom,qdf2432-emac-phy";
        reg = <0x0 0x00410400 0x0 0x100>;
        interrupts = <0 0x104 0>;
    };

Is this register range relative to the emac0 node here, or is this really a separate node, within the same adress space as your emac0 node?

Quoted 6 lines

When my driver probes, the platform_device object points to the emac0 node, as always.

How do I parse the emac_sgmii node? How do I get functions like platform_get_resource() to work? How do I create a new platform_device object that points to the emac_sgmii node?

Answer largely depends on whether your device is really located outside of the emac, if it located outside, then a platform device matching the compatible string would get you what you want. If the emac_sgmii block is a sub-block within the EMAC, then a few things need fixing:

- your emac_sgmii node should be a sub-node of the emac node, not a sibling
- the emac0 node should have a "ranges" property that indicates how to translate the sub-nodes' "reg" property based on the base register address of the emac0 block
- you would have to call of_platform_populate from the EMAC driver to ensure that the emac_sgmii child node and therefore platform device gets created

Signature · 5 lines
Florian
--
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
#17 lore raw
Quoted 9 lines · Florian Fainelli
Quoted 6 lines
     emac_sgmii: ethernet-phy@410400 {
         compatible = "qcom,qdf2432-emac-phy";
         reg = <0x0 0x00410400 0x0 0x100>;
         interrupts = <0 0x104 0>;
     };

Is this register range relative to the emac0 node here, or is this really a separate node, within the same adress space as your emac0 node?

It's a separate node within the same address space. We can't guarantee that it's adjacent to any other EMAC register -- it could be anywhere in memory. 0x00410400 is the real physical address of those registers.

Quoted 5 lines

Answer largely depends on whether your device is really located outside of the emac, if it located outside, then a platform device matching the compatible string would get you what you want. If the emac_sgmii block is a sub-block within the EMAC, then a few things need fixing:

Quoted 7 lines

- your emac_sgmii node should be a sub-node of the emac node, not a sibling
- the emac0 node should have a "ranges" property that indicates how to translate the sub-nodes' "reg" property based on the base register address of the emac0 block
- you would have to call of_platform_populate from the EMAC driver to ensure that the emac_sgmii child node and therefore platform device gets created

Even if the emac_sgmii block were a sub-block, wouldn't it conflict with the ethernet-phy@4 node? The #address-cells and #size-cells properties cannot be valid for both the emac_sgmii and ethernet-phy@4 nodes.

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.
#19 lore raw
In reply to a message not in the archive
Quoted 11 lines · Timur Tabi
Quoted 9 lines · Florian Fainelli
Quoted 6 lines
     emac_sgmii: ethernet-phy@410400 {
         compatible = "qcom,qdf2432-emac-phy";
         reg = <0x0 0x00410400 0x0 0x100>;
         interrupts = <0 0x104 0>;
     };

Is this register range relative to the emac0 node here, or is this really a separate node, within the same adress space as your emac0

Quoted 7 lines

node?

It's a separate node within the same address space. We can't guarantee

that it's adjacent to any other EMAC register -- it could be anywhere in
memory. 0x00410400 is the real physical address of those registers.

Ok

Quoted 17 lines
Quoted 2 lines

Answer largely depends on whether your device is really located

outside

Quoted 1 line

of the emac, if it located outside, then a platform device matching

the

Quoted 1 line

compatible string would get you what you want. If the emac_sgmii

block

Quoted 3 lines

is a sub-block within the EMAC, then a few things need fixing:

- your emac_sgmii node should be a sub-node of the emac node, not a

sibling

Quoted 1 line

- the emac0 node should have a "ranges" property that indicates how

to

Quoted 4 lines

translate the sub-nodes' "reg" property based on the base register address of the emac0 block
- you would have to call of_platform_populate from the EMAC driver to ensure that the emac_sgmii child node and therefore platform device

Quoted 8 lines

gets

Quoted 1 line

created

Even if the emac_sgmii block were a sub-block, wouldn't it conflict with
the ethernet-phy@4 node? The #address-cells and #size-cells properties

cannot be valid for both the emac_sgmii and ethernet-phy@4 nodes.

These two properties apply to subnodes within the emac0 and emac_sgmii nodes, this is standard DT stuff here.

The larger issue is that the emac_sgmii node in the form you posted is going to be backed by a platform device in Linux while you want a PHY device with a reg property that describes a MDIO address (#address-cells = 1, #size-cells = 0).

IIRC the amd xgbe driver mainline had a similar design but still implemented a PHY device anyway although it may not have been using Device Tree. It should still be possible to implement a PHY driver that you manually register and bind to its device_node pointer such that of_phy_find_device and friends still work. You would do this from the emac_sgmii platform device driver and parent devices in a way that satisfy the PHY device driver lifecycle as well.

Hope this helps.

NB: another way to do this is to give the SGMII PHY device a MDIO address, provided that it has one, and you pass the memory mapped register range as a syscon property pointing to the emac_sgmii register range. This is not really clean through.

Signature · 5 lines
Florian
--
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
#21 lore raw
In reply to a message not in the archive
Quoted 4 lines · Florian Fainelli

The larger issue is that the emac_sgmii node in the form you posted is going to be backed by a platform device in Linux while you want a PHY device with a reg property that describes a MDIO address (#address-cells = 1, #size-cells = 0).

But how do I get the platform device for the emac_sgmii node? If I create an of_device_id ID for it, like this:

static const struct of_device_id emac_dt_match[] = {
	{
		.compatible = "qcom,fsm9900-emac",
	},
	{}
};
static const struct of_device_id emac_sgmii_dt_match[] = {
	{
		.compatible = "qcom,fsm9900-emac-sgmii",
	},
	{}
};

Then the probe function will be called for qcom,fsm9900-emac-sgmii separately from qcom,fsm9900-emac, which just confuses things. So I can't create emac_sgmii_dt_match.

I know this is standard DT stuff, and I used to do a lot of work on DT so maybe I should know this already. But it seems to me that I need to manually create the platform_device for qcom,fsm9900-emac-sgmii.

Quoted 9 lines

IIRC the amd xgbe driver mainline had a similar design but still implemented a PHY device anyway although it may not have been using Device Tree. It should still be possible to implement a PHY driver that you manually register and bind to its device_node pointer such that of_phy_find_device and friends still work. You would do this from the emac_sgmii platform device driver and parent devices in a way that satisfy the PHY device driver lifecycle as well.

Hope this helps.

It doesn't, sorry. The emac_sgmii is really just another register block for the driver to program. Creating another PHY driver for it doesn't really make sense. It's not on an MDIO bus.

Signature · 7 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.
--
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
#22 lore raw
Quoted 23 lines · Timur Tabi
Quoted 4 lines · Florian Fainelli

The larger issue is that the emac_sgmii node in the form you posted is going to be backed by a platform device in Linux while you want a PHY device with a reg property that describes a MDIO address (#address-cells = 1, #size-cells = 0).

But how do I get the platform device for the emac_sgmii node? If I create an of_device_id ID for it, like this:

static const struct of_device_id emac_dt_match[] = {
	{
		.compatible = "qcom,fsm9900-emac",
	},
	{}
};
static const struct of_device_id emac_sgmii_dt_match[] = {
	{
		.compatible = "qcom,fsm9900-emac-sgmii",
	},
	{}
};
Quoted 8 lines

Then the probe function will be called for qcom,fsm9900-emac-sgmii separately from qcom,fsm9900-emac, which just confuses things. So I can't create emac_sgmii_dt_match.

I know this is standard DT stuff, and I used to do a lot of work on DT so maybe I should know this already. But it seems to me that I need to

manually create the platform_device for qcom,fsm9900-emac-sgmii.

There is a helper function to obtain the platform device associated with a device_node: of_find_device_by_node. AFAICT probe ordering is based on DT ordering, but if there was a dependency order to solve you could use EPROBE_DEFER until the emac driver finds its dependencies.

Quoted 9 lines
Quoted 9 lines

IIRC the amd xgbe driver mainline had a similar design but still implemented a PHY device anyway although it may not have been using Device Tree. It should still be possible to implement a PHY driver that you manually register and bind to its device_node pointer such that of_phy_find_device and friends still work. You would do this from the emac_sgmii platform device driver and parent devices in a way that satisfy the PHY device driver lifecycle as well.

Quoted 6 lines
Quoted 1 line

Hope this helps.

It doesn't, sorry. The emac_sgmii is really just another register block
for the driver to program. Creating another PHY driver for it doesn't really make sense. It's not on an MDIO bus.

First of a PHY does not have to be on a MDIO bus, it just happens to be the most common thing, and second, this is a PHY of some kind as far as the Ethernet MAC is concerned and this is the abstraction you want at the MAC driver level so you can plug arbitrary external PHYs or internal PHYs irrespective of their backing transport/bus layer.

As long as your DT representation is sane and accurate, however this ends up being implemented matters less. Whether the PHY device model suits you here, you need to tell the emac0 node that it is bound to the emac_sgmii node somehow since there is programming of this block required for operating and for that a phandle property of some kind is required, phy-handle is a standard one which would help with the driver acceptance IMHO.

Signature · 1 line
Florian
author
#23 lore raw
Quoted 1 line · Florian Fainelli

There is a helper function to obtain the platform device associated with a device_node: of_find_device_by_node.

Thank you, this is exactly what I needed.

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.