Skip to contentSkip to conversation

net: emac: emac gigabit ethernet controller driver

PATCH In review Gilad Avidov 7 participants 19 messages Dec 30, 2015 – Apr 8, 2016

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v3 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) Runtime power management support.
3) Interrupt coalescing support.
4) SGMII phy.
5) SGMII direct connection without external phy.

Based on a driver by Niranjana Vishwanathapura <[email protected]>.

Changes since v1 (https://lkml.org/lkml/2015/12/7/1088)
- 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().

Changes since v2 (https://lwn.net/Articles/667876/)
- 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.

---
 .../devicetree/bindings/net/qcom-emac.txt          |   68 +
 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      | 1808 ++++++++++++++++++++
 drivers/net/ethernet/qualcomm/emac/emac-mac.h      |  286 ++++
 drivers/net/ethernet/qualcomm/emac/emac-phy.c      |  486 ++++++
 drivers/net/ethernet/qualcomm/emac/emac-phy.h      |   69 +
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c    |  679 ++++++++
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h    |   30 +
 drivers/net/ethernet/qualcomm/emac/emac.c          | 1228 +++++++++++++
 drivers/net/ethernet/qualcomm/emac/emac.h          |  388 +++++
 12 files changed, 5062 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 +68 -0
new file mode 100644
index 0000000..8d58a40
@@ -0,0 +1,68 @@
+Qualcomm EMAC Gigabit Ethernet Controller
+
+Required properties:
+- cell-index : EMAC controller instance number.
+- compatible : Should be "qcom,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.
+	Optional register resource entries are:
+	"ptp"    : EMAC PTP (1588) register block.
+		   Required if 'qcom,emac-tstamp-en' is present.
+	"sgmii"  : EMAC SGMII PHY 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.
+- qcom,emac-gpio-mdc  : GPIO pin number of the MDC line of MDIO bus.
+- qcom,emac-gpio-mdio : GPIO pin number of the MDIO line of MDIO bus.
+- phy-addr            : Specifies phy address on MDIO bus.
+			Required if the optional property "qcom,no-external-phy"
+			is not specified.
+
+Optional properties:
+- qcom,emac-tstamp-en       : Enables the PTP (1588) timestamping feature.
+			      Include this only if PTP (1588) timestamping
+			      feature is needed. If included, "ptp" register
+			      base should be specified.
+- mac-address               : The 6-byte MAC address. If present, it is the
+			      default MAC address.
+- qcom,no-external-phy      : Indicates there is no external PHY connected to
+			      EMAC. Include this only if the EMAC is directly
+			      connected to the peer end without EPHY.
+- qcom,emac-ptp-grandmaster : Enable the PTP (1588) grandmaster mode.
+			      Include this only if PTP (1588) is configured as
+			      grandmaster.
+- qcom,emac-ptp-frac-ns-adj : The vector table to adjust the fractional ns per
+			      RTC clock cycle.
+			      Include this only if there is accuracy loss of
+			      fractional ns per RTC clock cycle. For individual
+			      table entry, the first field indicates the RTC
+			      reference clock rate. The second field indicates
+			      the number of adjustment in 2 ^ -26 ns.
+Example:
+	emac0: qcom,emac@feb20000 {
+		cell-index = <0>;
+		compatible = "qcom,emac";
+		reg-names = "base", "csr", "ptp", "sgmii";
+		reg =   <0xfeb20000 0x10000>,
+			<0xfeb36000 0x1000>,
+			<0xfeb3c000 0x4000>,
+			<0xfeb38000 0x400>;
+		#address-cells = <0>;
+		interrupt-parent = <&emac0>;
+		#interrupt-cells = <1>;
+		interrupts = <0 1>;
+		interrupt-map-mask = <0xffffffff>;
+		interrupt-map = <0 &intc 0 76 0
+				 1 &intc 0 80 0>;
+		interrupt-names = "emac_core0", "sgmii_irq";
+		qcom,emac-gpio-mdc = <&qcomgpio 123 0>;
+		qcom,emac-gpio-mdio = <&qcomgpio 124 0>;
+		qcom,emac-tstamp-en;
+		qcom,emac-ptp-frac-ns-adj = <125000000 1>;
+		phy-addr = <0>;
+	};
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..b14686e 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/
\ No newline at end of file
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 +1808 -0

1,808 lines not on this page · raw message

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

286 lines not on this page · raw message

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

486 lines not on this page · raw message

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

69 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-sgmii.c new file +679 -0

255 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-sgmii.h new file +30 -0
new file mode 100644
index 0000000..4d55915b

Lines of this file are not shown. View the raw message.

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

1,228 lines not on this page · raw message

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

388 lines not on this page · raw message

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

Signature · 7 lines
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

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

#1 lore raw
reproduce:

Hi Gilad,

[auto build test WARNING on net/master]
[also build test WARNING on v4.4-rc7 next-20151223]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Gilad-Avidov/net-emac-emac-gigabit-ethernet-controller-driver/20151230-095104
config: x86_64-allmodconfig (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

drivers/net/ethernet/qualcomm/emac/emac-mac.c: In function 'emac_mac_up':

>> drivers/net/ethernet/qualcomm/emac/emac-mac.c:1090:9: warning: large integer implicitly truncated to unsigned type [-Woverflow]
     writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);
            ^

vim +1090 drivers/net/ethernet/qualcomm/emac/emac-mac.c

1074 }
1075 }
1076
1077 ret = request_irq(irq->irq, emac_isr, 0, EMAC_MAC_IRQ_RES, irq);
1078 if (ret) {
1079 netdev_err(adpt->netdev,
1080 "error:%d on request_irq(%d:%s flags:0)\n", ret,
1081 irq->irq, EMAC_MAC_IRQ_RES);
1082 goto err_request_irq;
1083 }
1084
1085 emac_mac_rx_descs_refill(adpt, &adpt->rx_q);
1086
1087 napi_enable(&adpt->rx_q.napi);
1088
1089 /* enable mac irq */

> 1090		writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);

1091 writel(adpt->irq.mask, adpt->base + EMAC_INT_MASK);
1092
1093 netif_start_queue(netdev);
1094 clear_bit(EMAC_STATUS_DOWN, &adpt->status);
1095
1096 /* check link status */
1097 set_bit(EMAC_STATUS_TASK_LSC_REQ, &adpt->status);
1098 adpt->link_chk_timeout = jiffies + EMAC_TRY_LINK_TIMEOUT;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#2 lore raw
In reply to Gilad Avidov
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Gilad,

[auto build test WARNING on net/master]
[also build test WARNING on v4.4-rc7 next-20151223]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Gilad-Avidov/net-emac-emac-gigabit-ethernet-controller-driver/20151230-095104
config: ia64-allyesconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=ia64

All warnings (new ones prefixed by >>):

In file included from arch/ia64/include/asm/smp.h:20:0,
from include/linux/smp.h:59,
from include/linux/topology.h:33,
from include/linux/gfp.h:8,
from include/linux/slab.h:14,
from include/linux/textsearch.h:8,
from include/linux/skbuff.h:30,
from include/linux/tcp.h:21,
from drivers/net/ethernet/qualcomm/emac/emac-mac.c:16:
drivers/net/ethernet/qualcomm/emac/emac-mac.c: In function 'emac_mac_up':
arch/ia64/include/asm/io.h:394:30: warning: large integer implicitly truncated to unsigned type [-Woverflow]

    #define writel(v,a) __writel((v), (a))
                                 ^
>> drivers/net/ethernet/qualcomm/emac/emac-mac.c:1090:2: note: in expansion of macro 'writel'
     writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);
     ^

vim +/writel +1090 drivers/net/ethernet/qualcomm/emac/emac-mac.c

1074 }
1075 }
1076
1077 ret = request_irq(irq->irq, emac_isr, 0, EMAC_MAC_IRQ_RES, irq);
1078 if (ret) {
1079 netdev_err(adpt->netdev,
1080 "error:%d on request_irq(%d:%s flags:0)\n", ret,
1081 irq->irq, EMAC_MAC_IRQ_RES);
1082 goto err_request_irq;
1083 }
1084
1085 emac_mac_rx_descs_refill(adpt, &adpt->rx_q);
1086
1087 napi_enable(&adpt->rx_q.napi);
1088
1089 /* enable mac irq */

> 1090		writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);

1091 writel(adpt->irq.mask, adpt->base + EMAC_INT_MASK);
1092
1093 netif_start_queue(netdev);
1094 clear_bit(EMAC_STATUS_DOWN, &adpt->status);
1095
1096 /* check link status */
1097 set_bit(EMAC_STATUS_TASK_LSC_REQ, &adpt->status);
1098 adpt->link_chk_timeout = jiffies + EMAC_TRY_LINK_TIMEOUT;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

maintainer
#3 lore raw
In reply to Gilad Avidov
Quoted 10 lines · Gilad Avidov

Add supports for ethernet controller HW on Qualcomm Technologies, Inc. SoC. This driver supports the following features:
1) Checksum offload.
2) Runtime power management support.
3) Interrupt coalescing support.
4) SGMII phy.
5) SGMII direct connection without external phy.

Based on a driver by Niranjana Vishwanathapura
<[email protected]>.

[...]

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

Quoted 11 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5 -0
new file mode 100644
index 0000000..8d58a40
@@ -0,0 +1,68 @@
+Qualcomm EMAC Gigabit Ethernet Controller
+
+Required properties:
+- cell-index : EMAC controller instance number.
+- compatible : Should be "qcom,emac".

This should be more specific with the SOC name.

Quoted 6 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +6 -0
+- 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.
+	Optional register resource entries are:

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

Quoted 10 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +10 -0
+	"ptp"    : EMAC PTP (1588) register block.
+		   Required if 'qcom,emac-tstamp-en' is present.
+	"sgmii"  : EMAC SGMII PHY 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.
+- qcom,emac-gpio-mdc  : GPIO pin number of the MDC line of MDIO bus.
+- qcom,emac-gpio-mdio : GPIO pin number of the MDIO line of MDIO bus.

Use the standard binding for GPIO controlled MDIO bus.

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

Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +3 -0
+- phy-addr            : Specifies phy address on MDIO bus.
+			Required if the optional property "qcom,no-external-phy"
+			is not specified.

Don't you think you will need to know the specific phy device or other properties of the phy?

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

Quoted 6 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +6 -0
+
+Optional properties:
+- qcom,emac-tstamp-en       : Enables the PTP (1588) timestamping feature.
+			      Include this only if PTP (1588) timestamping
+			      feature is needed. If included, "ptp" register
+			      base should be specified.

Isn't this a user enabled feature if the h/w supports it?

Quoted 38 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +38 -0
+- mac-address               : The 6-byte MAC address. If present, it is the
+			      default MAC address.
+- qcom,no-external-phy      : Indicates there is no external PHY connected to
+			      EMAC. Include this only if the EMAC is directly
+			      connected to the peer end without EPHY.
+- qcom,emac-ptp-grandmaster : Enable the PTP (1588) grandmaster mode.
+			      Include this only if PTP (1588) is configured as
+			      grandmaster.
+- qcom,emac-ptp-frac-ns-adj : The vector table to adjust the fractional ns per
+			      RTC clock cycle.
+			      Include this only if there is accuracy loss of
+			      fractional ns per RTC clock cycle. For individual
+			      table entry, the first field indicates the RTC
+			      reference clock rate. The second field indicates
+			      the number of adjustment in 2 ^ -26 ns.
+Example:
+	emac0: qcom,emac@feb20000 {
+		cell-index = <0>;
+		compatible = "qcom,emac";
+		reg-names = "base", "csr", "ptp", "sgmii";
+		reg =   <0xfeb20000 0x10000>,
+			<0xfeb36000 0x1000>,
+			<0xfeb3c000 0x4000>,
+			<0xfeb38000 0x400>;
+		#address-cells = <0>;
+		interrupt-parent = <&emac0>;
+		#interrupt-cells = <1>;
+		interrupts = <0 1>;
+		interrupt-map-mask = <0xffffffff>;
+		interrupt-map = <0 &intc 0 76 0
+				 1 &intc 0 80 0>;
+		interrupt-names = "emac_core0", "sgmii_irq";
+		qcom,emac-gpio-mdc = <&qcomgpio 123 0>;
+		qcom,emac-gpio-mdio = <&qcomgpio 124 0>;
+		qcom,emac-tstamp-en;
+		qcom,emac-ptp-frac-ns-adj = <125000000 1>;
+		phy-addr = <0>;
+	};
#4 lore raw

Gilad is no longer working for Qualcomm, so I'm taking over (as best as I can) this driver. Let's just say it's going to be a learning experience.

Quoted 5 lines · Rob Herring
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +0 -0
new file mode 100644
index 0000000..8d58a40
Quoted 8 lines

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

Quoted 6 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5 -0
@@ -0,0 +1,68 @@
+Qualcomm EMAC Gigabit Ethernet Controller
+
+Required properties:
+- cell-index : EMAC controller instance number.
+- compatible : Should be "qcom,emac".

This should be more specific with the SOC name.

The emac is present on a lot of Qualcomm SOCs, and there are only a few variations of it. It's not really SOC-specific, and the hardware version can be queried by the driver.

What did you have in mind? I don't know even have a list of which SOCs has an emac, especially since it's mostly on MSM parts, and I work on the server SOC.

Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +10 -0
+- 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.
+	Optional register resource entries are:
+	"ptp"    : EMAC PTP (1588) register block.
+		   Required if 'qcom,emac-tstamp-en' is present.
+	"sgmii"  : EMAC SGMII PHY register block.
+- interrupts : Interrupt numbers used by this controller
Quoted 8 lines

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

Quoted 6 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +6 -0
+- interrupt-names : Interrupt resource names referenced in 'interrupts' above.
+	Required interrupt resource entries are:
+	"emac_core0"   : EMAC core0 interrupt.
+	"sgmii_irq"   : EMAC SGMII interrupt.
+- qcom,emac-gpio-mdc  : GPIO pin number of the MDC line of MDIO bus.
+- qcom,emac-gpio-mdio : GPIO pin number of the MDIO line of MDIO bus.

Use the standard binding for GPIO controlled MDIO bus.

I'm not familiar with that one. Are you talking about bindings/net/mdio-gpio.txt?

Quoted 6 lines

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

Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +3 -0
+- phy-addr            : Specifies phy address on MDIO bus.
+			Required if the optional property "qcom,no-external-phy"
+			is not specified.

Don't you think you will need to know the specific phy device or other properties of the phy?

That, I can't answer. Aren't all MDIO devices basically the same? It's been a while since I've worked on them.

Quoted 7 lines

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

Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5 -0
+Optional properties:
+- qcom,emac-tstamp-en       : Enables the PTP (1588) timestamping feature.
+			      Include this only if PTP (1588) timestamping
+			      feature is needed. If included, "ptp" register
+			      base should be specified.

Isn't this a user enabled feature if the h/w supports it?

Is there a sysfs entry for that? We were planning on having a similar ACPI property.

maintainer
#5 lore raw
Quoted 2 lines · Timur Tabi

Gilad is no longer working for Qualcomm, so I'm taking over (as best as I can) this driver. Let's just say it's going to be a learning experience.

Lucky you.

Quoted 19 lines
Quoted 16 lines · Rob Herring

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

Quoted 13 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5 -0
new file mode 100644
index 0000000..8d58a40
@@ -0,0 +1,68 @@
+Qualcomm EMAC Gigabit Ethernet Controller
+
+Required properties:
+- cell-index : EMAC controller instance number.
+- compatible : Should be "qcom,emac".

This should be more specific with the SOC name.

Quoted 3 lines

The emac is present on a lot of Qualcomm SOCs, and there are only a few variations of it. It's not really SOC-specific, and the hardware version can be queried by the driver.

Can the integration bugs be queried, too?

Come on, you know how compatible strings work.

Quoted 3 lines

What did you have in mind? I don't know even have a list of which SOCs has an emac, especially since it's mostly on MSM parts, and I work on the server SOC.

You only need the one you care about. Figure out the part number already. Or find the closest MSM part.

Quoted 19 lines
Quoted 19 lines
Quoted 17 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +11 -0
+- 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.
+       Optional register resource entries are:
+       "ptp"    : EMAC PTP (1588) register block.
+                  Required if 'qcom,emac-tstamp-en' is present.
+       "sgmii"  : EMAC SGMII PHY register block.
+- interrupts : Interrupt numbers used by this controller
+- interrupt-names : Interrupt resource names referenced in 'interrupts'

above.

Documentation/devicetree/bindings/net/qcom-emac.txt new file +5 -0
+       Required interrupt resource entries are:
+       "emac_core0"   : EMAC core0 interrupt.
+       "sgmii_irq"   : EMAC SGMII interrupt.
+- qcom,emac-gpio-mdc  : GPIO pin number of the MDC line of MDIO bus.
+- qcom,emac-gpio-mdio : GPIO pin number of the MDIO line of MDIO bus.
Quoted 5 lines
Quoted 1 line

Use the standard binding for GPIO controlled MDIO bus.

I'm not familiar with that one. Are you talking about bindings/net/mdio-gpio.txt?

Yes.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
+- phy-addr            : Specifies phy address on MDIO bus.
+                       Required if the optional property

"qcom,no-external-phy"
+ is not specified.

Quoted 6 lines
Quoted 2 lines

Don't you think you will need to know the specific phy device or other properties of the phy?

That, I can't answer. Aren't all MDIO devices basically the same? It's been a while since I've worked on them.

No. There was some discussion just this week about needing to require phy devices to have compatible strings.

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

+Optional properties:
+- qcom,emac-tstamp-en : Enables the PTP (1588) timestamping
feature.
+ Include this only if PTP (1588)
timestamping
+ feature is needed. If included, "ptp"
register
+ base should be specified.

Quoted 5 lines
Quoted 1 line

Isn't this a user enabled feature if the h/w supports it?

Is there a sysfs entry for that? We were planning on having a similar ACPI property.

It would be in ethtool I think.

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

#6 lore raw
Quoted 7 lines · Rob Herring
Quoted 3 lines

The emac is present on a lot of Qualcomm SOCs, and there are only a few variations of it. It's not really SOC-specific, and the hardware version can be queried by the driver.

Can the integration bugs be queried, too?

Come on, you know how compatible strings work.

Fine. I'll figure something out.

Quoted 6 lines
Quoted 3 lines

What did you have in mind? I don't know even have a list of which SOCs has an emac, especially since it's mostly on MSM parts, and I work on the server SOC.

You only need the one you care about. Figure out the part number already. Or find the closest MSM part.

Ironically, the only SOC I actually care about is not supported by this driver yet.

Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
+- qcom,emac-gpio-mdc  : GPIO pin number of the MDC line of MDIO bus.
+- qcom,emac-gpio-mdio : GPIO pin number of the MDIO line of MDIO bus.

Use the standard binding for GPIO controlled MDIO bus.

I'm not familiar with that one. Are you talking about bindings/net/mdio-gpio.txt?

Yes.

Thanks.

Quoted 5 lines
Quoted 2 lines

That, I can't answer. Aren't all MDIO devices basically the same? It's been a while since I've worked on them.

No. There was some discussion just this week about needing to require phy devices to have compatible strings.

Ok, I'll check it out.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Isn't this a user enabled feature if the h/w supports it?

Is there a sysfs entry for that? We were planning on having a similar ACPI property.

It would be in ethtool I think.

Ah, this driver does not support ethtool yet.

However, based on a cursory look of ethtool, it appears that there's only an option to query the current timestamp, but not actually enable/disable the feature. The e1000e driver, for example, just forces the feature by default for various chips. Is there any reason why we shouldn't enable it if the hardware supports it?

maintainer
#7 lore raw
Quoted 1 line · Timur Tabi

Rob Herring wrote:

[...]

Quoted 12 lines
Quoted 10 lines
Quoted 7 lines
Quoted 1 line

Isn't this a user enabled feature if the h/w supports it?

Is there a sysfs entry for that? We were planning on having a similar ACPI
property.

It would be in ethtool I think.

Quoted 7 lines

Ah, this driver does not support ethtool yet.

However, based on a cursory look of ethtool, it appears that there's only an option to query the current timestamp, but not actually enable/disable the feature. The e1000e driver, for example, just forces the feature by default for various chips. Is there any reason why we shouldn't enable it if the hardware supports it?

Probably not. You simply ignore the timestamp if you don't care. So then why do you want a DT property?

Rob

#8 lore raw
In reply to Rob Herring
Quoted 38 lines · Rob Herring
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 17 lines
Quoted 17 lines
+- reg : Offset and length of the register regions for the device
+- reg-names : Register region names referenced in 'reg' above.
Documentation/devicetree/bindings/net/qcom-emac.txt new file +9 -0
+       Required register resource entries are:
+       "base"   : EMAC controller base register block.
+       "csr"    : EMAC wrapper register block.
+       Optional register resource entries are:
+       "ptp"    : EMAC PTP (1588) register block.
+                  Required if 'qcom,emac-tstamp-en' is present.
+       "sgmii"  : EMAC SGMII PHY register block.
+- interrupts : Interrupt numbers used by this controller
+- interrupt-names : Interrupt resource names referenced in 'interrupts'

above.

Documentation/devicetree/bindings/net/qcom-emac.txt new file +5 -0
+       Required interrupt resource entries are:
+       "emac_core0"   : EMAC core0 interrupt.
+       "sgmii_irq"   : EMAC SGMII interrupt.
+- qcom,emac-gpio-mdc  : GPIO pin number of the MDC line of MDIO bus.
+- qcom,emac-gpio-mdio : GPIO pin number of the MDIO line of MDIO bus.
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

Use the standard binding for GPIO controlled MDIO bus.

I'm not familiar with that one. Are you talking about bindings/net/mdio-gpio.txt?

Yes.

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
+- phy-addr            : Specifies phy address on MDIO bus.
+                       Required if the optional property

"qcom,no-external-phy"
+ is not specified.

Don't you think you will need to know the specific phy device or other properties of the phy?

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

That, I can't answer. Aren't all MDIO devices basically the same? It's been a while since I've worked on them.

No. There was some discussion just this week about needing to require phy devices to have compatible strings.

I'm back to working on this driver, and I need some more help with how to handle the phy. mdio-gpio.txt doesn't really tell me much. I'm actually working on an ACPI system and not DT. I don't want to strip out the DT code, but I can't really test it. I want to keep changes to Gilad's patch to a minimum.

Part of the problem with the Emac (and Gilad tried to explain this) is that it has an internal phy. Technically, you can connect this internal phy directly to another internal phy on another SOC, and use this as an SOC interconnect. However, I don't know of anyone actually doing that.

Instead, most systems have the internal phy connect to an external phy.
This connection is how the Emac receives packets from the external phy.

So I don't understand how I'm supposed to use the binding in mdio-gpio.txt. For one thing, there is no such binding on ACPI systems.
On my ACPI system, firmware has set up the GPIOs. The driver never
actually makes any gpio_xxx calls. At this point, I'm tempted to just remove all the GPIO stuff from Gilad's patch, if I can't help enough help to figure out how to modify the driver the way you think I should.

Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
Forum, a Linux Foundation collaborative project.
#9 lore raw
Quoted 3 lines

I'm back to working on this driver, and I need some more help with how to handle the phy. mdio-gpio.txt doesn't really tell me much. I'm actually working on an ACPI system and not DT.

I can help you with DT, but not ACPI.

The MDIO bus can be a separate Linux device. Since you have GPIO lines for the MDIO bus, it makes sense for this to be a mdio-gpio device. So in DT, you would have:

mdio0: mdio {
        compatible = "virtual,mdio-gpio";
        #address-cells = <1>;
        #size-cells = <0>;
        gpios = <&qcomgpio 123 0
                 &qcomgpio 124 0>;

	phy0: ethernet-phy@8 {
        	reg = <9>;
	};
};

Here i've assumed the PHY is using address 8 on the bus. Change as needed.

In your MAC DT node, you then have phy-handle pointing to this phy:

emac0: qcom,emac@feb20000 {

  	cell-index = <0>;
	compatible = "qcom,emac";
	reg-names = "base", "csr", "ptp", "sgmii";
	reg =   <0xfeb20000 0x10000>,
	    	<0xfeb36000 0x1000>,
		<0xfeb3c000 0x4000>,
		<0xfeb38000 0x400>;
	#address-cells = <0>;
	interrupt-parent = <&emac0>;
	#interrupt-cells = <1>;
	interrupts = <0 1>;
	interrupt-map-mask = <0xffffffff>;
	interrupt-map = <0 &intc 0 76 0
	 	         1 &intc 0 80 0>;
       	interrupt-names = "emac_core0", "sgmii_irq";
  	qcom,emac-tstamp-en;
	qcom,emac-ptp-frac-ns-adj = <125000000 1>;

	phy-handle = <&phy0>
}

In the driver, you need to connect the PHY to the MAC. You do this using something like:

         if (dev->of_node) {
                 phy_np = of_parse_phandle(dev->of_node, "phy-handle", 0);
                 if (!phy_np) {
                         netdev_dbg(ndev, "No phy-handle found in DT\n");
                         return -ENODEV;
                 }
 
                 phy_dev = of_phy_connect(ndev, phy_np, &xxxx_enet_adjust_link,
                                          0, pdata->phy_mode);
                 if (!phy_dev) {
                         netdev_err(ndev, "Could not connect to PHY\n");
                         return -ENODEV;
                 }

Do you have an ACPI table describing this hardware? What does it look like?

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

#10 lore raw
Quoted 52 lines · Andrew Lunn
Quoted 3 lines

I'm back to working on this driver, and I need some more help with how to handle the phy. mdio-gpio.txt doesn't really tell me much. I'm actually working on an ACPI system and not DT.

I can help you with DT, but not ACPI.

The MDIO bus can be a separate Linux device. Since you have GPIO lines for the MDIO bus, it makes sense for this to be a mdio-gpio device. So in DT, you would have:

mdio0: mdio {
         compatible = "virtual,mdio-gpio";
         #address-cells = <1>;
         #size-cells = <0>;
         gpios = <&qcomgpio 123 0
                  &qcomgpio 124 0>;

	phy0: ethernet-phy@8 {
         	reg = <9>;
	};
};

Here i've assumed the PHY is using address 8 on the bus. Change as needed.

In your MAC DT node, you then have phy-handle pointing to this phy:

   emac0: qcom,emac@feb20000 {
   	cell-index = <0>;
	compatible = "qcom,emac";
	reg-names = "base", "csr", "ptp", "sgmii";
	reg =   <0xfeb20000 0x10000>,
	    	<0xfeb36000 0x1000>,
		<0xfeb3c000 0x4000>,
		<0xfeb38000 0x400>;
	#address-cells = <0>;
	interrupt-parent = <&emac0>;
	#interrupt-cells = <1>;
	interrupts = <0 1>;
	interrupt-map-mask = <0xffffffff>;
	interrupt-map = <0 &intc 0 76 0
	 	         1 &intc 0 80 0>;
        	interrupt-names = "emac_core0", "sgmii_irq";
   	qcom,emac-tstamp-en;
	qcom,emac-ptp-frac-ns-adj = <125000000 1>;

	phy-handle = <&phy0>
}

In the driver, you need to connect the PHY to the MAC. You do this using something like:

Quoted 13 lines
          if (dev->of_node) {
                  phy_np = of_parse_phandle(dev->of_node, "phy-handle", 0);
                  if (!phy_np) {
                          netdev_dbg(ndev, "No phy-handle found in DT\n");
                          return -ENODEV;
                  }

                  phy_dev = of_phy_connect(ndev, phy_np, &xxxx_enet_adjust_link,
                                           0, pdata->phy_mode);
                  if (!phy_dev) {
                          netdev_err(ndev, "Could not connect to PHY\n");
                          return -ENODEV;
                  }

Thank you very much. I'll study this in detail.

Quoted 2 lines

Do you have an ACPI table describing this hardware? What does it look like?

So a little background. There are several versions of this driver floating in Qualcomm, and this is the first serious attempt to upstream it. I'm trying to reconcile Gilad's driver with the one we use internally for our ACPI-enabled ARM server platform (the QDF2432).

My goal is to get Gilad's driver accepted upstream with minimal changes on my part. I will then follow up with several patches that enable ACPI and our SOC, as well as adding missing parts like ethtool and 1588 support.

On my platform, firmware (UEFI) configures all of the GPIOs. I need to get confirmation, but it appears that we don't actually make any GPIO calls at all. I see code that looks like this:

	for (i = 0; (!adpt->no_mdio_gpio) && i < EMAC_NUM_GPIO; i++) {
		gpio_info = &adpt->gpio_info[i];
		retval = of_get_named_gpio(node, gpio_info->name, 0);
		if (retval < 0)
			return retval;

And on our ACPI system, adpt->no_mdio_gpio is always true:

	/* Assume GPIOs required for MDC/MDIO are enabled in firmware */
	adpt->no_mdio_gpio = true;
Signature · 7 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, 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
#11 lore raw
Quoted 10 lines · Timur Tabi

On my platform, firmware (UEFI) configures all of the GPIOs. I need to get confirmation, but it appears that we don't actually make any GPIO calls at all. I see code that looks like this:

	for (i = 0; (!adpt->no_mdio_gpio) && i < EMAC_NUM_GPIO; i++) {
		gpio_info = &adpt->gpio_info[i];
		retval = of_get_named_gpio(node, gpio_info->name, 0);
		if (retval < 0)
			return retval;
Quoted 4 lines

And on our ACPI system, adpt->no_mdio_gpio is always true:

	/* Assume GPIOs required for MDC/MDIO are enabled in firmware */
	adpt->no_mdio_gpio = true;

There are two different things here. One is configuring the pin to be a GPIO. The second is using the GPIO as a GPIO. In this case, bit-banging the MDIO bus.

The firmware could be doing the configuration, setting the pin as a GPIO. However, the firmware cannot be doing the MDIO bit-banging to make an MDIO bus available. Linux has to do that.

Or it could be we have all completely misunderstood the hardware, and we are not doing bit-banging GPIO MDIO. There is a real MDIO controller there, we don't use these pins as GPIOs, etc....

Andrew

#12 lore raw
Quoted 11 lines · Andrew Lunn

There are two different things here. One is configuring the pin to be a GPIO. The second is using the GPIO as a GPIO. In this case, bit-banging the MDIO bus.

The firmware could be doing the configuration, setting the pin as a GPIO. However, the firmware cannot be doing the MDIO bit-banging to make an MDIO bus available. Linux has to do that.

Or it could be we have all completely misunderstood the hardware, and we are not doing bit-banging GPIO MDIO. There is a real MDIO controller there, we don't use these pins as GPIOs, etc....

Actually, I think there is a misunderstanding.

On the FSM9900 SOC (which uses device-tree), the two pins that connect to the external PHY are gpio pins. However, the driver needs to reprogram the pinmux so that those pins are wired to the Emac controller. That's what the the gpio code in this driver is doing: it's just configuring the pins so that they connect directly between the Emac and the external PHY. After that, they are no longer GPIO pins, and you cannot use the "GPIO controlled MDIO bus". There is no MDIO controller on the SOC. The external PHY is controlled directly from the Emac and also from the internal PHY. It is screwy, I know, but that's what Gilad was trying to explain.

On the QDF2432 (which uses ACPI), those two wires are now dedicated. There are not muxed GPIOs any more -- they are hard wired between Emac and the external PHY.

In both cases, you need to use Emac registers to communicate with the external PHY. Stuff like link detect and link speed are configured by programming the Emac and/or the internal phy.

And the internal phy isn't really an internal phy. It's an SGMII-like device that's connected to the Emac and handles various phy-related tasks. It has its own register block, but you still have to program it in concert with the Emac. You can't really treat it separately.

So I'm beginning to believe that Gilad's driver is actually correct as-is. There are a few minor bug fixes, but in general it's correct. I would like to post a V4 soon that has those minor fixes.

Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
Forum, a Linux Foundation collaborative project.
#13 lore raw
Quoted 10 lines · Timur Tabi
Quoted 8 lines · Andrew Lunn

There are two different things here. One is configuring the pin to be a GPIO. The second is using the GPIO as a GPIO. In this case, bit-banging the MDIO bus.

The firmware could be doing the configuration, setting the pin as a GPIO. However, the firmware cannot be doing the MDIO bit-banging to make an MDIO bus available. Linux has to do that.

Quoted 7 lines
Quoted 3 lines

Or it could be we have all completely misunderstood the hardware, and we are not doing bit-banging GPIO MDIO. There is a real MDIO controller there, we don't use these pins as GPIOs, etc....

Actually, I think there is a misunderstanding.

On the FSM9900 SOC (which uses device-tree), the two pins that connect to the external PHY are gpio pins. However, the driver needs to reprogram the pinmux so that those pins are wired to the Emac controller. That's what the the gpio code in this driver is doing: it's just configuring the pins so that they connect directly between the Emac and the external PHY. After that, they are no longer GPIO pins, and you cannot use the "GPIO controlled MDIO bus". There is no MDIO controller on the SOC. The external PHY is controlled directly from the Emac and also from the internal PHY. It is screwy, I know, but that's what Gilad was trying to explain.

It is incorrect to say there's no MDIO controller on the SoC. The EMAC Core on the SoC itself has a MDIO controller which talks to the external PHY. The internal SGMII is not on MDIO however. Please see the EMAC specification.

Quoted 4 lines

On the QDF2432 (which uses ACPI), those two wires are now dedicated. There are not muxed GPIOs any more -- they are hard wired between Emac and the external PHY.

In both cases, you need to use Emac registers to communicate with the external PHY. Stuff like link detect and link speed are configured by programming the Emac and/or the internal phy.

You need to use EMAC *MDIO* registers to communicate with external PHY.

Quoted 5 lines

And the internal phy isn't really an internal phy. It's an SGMII-like device that's connected to the Emac and handles various phy-related tasks. It has its own register block, but you still have to program it in concert with the Emac. You can't really treat it separately.

So I'm beginning to believe that Gilad's driver is actually correct as-is. There are a few minor bug fixes, but in general it's correct. I would like to post a V4 soon that has those minor fixes.

Signature · 3 lines
Vikram Sethi
Qualcomm Technologies Inc, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#14 lore raw
Quoted 3 lines · Vikram Sethi
Quoted 1 line

On the FSM9900 SOC (which uses device-tree), the two pins that connect to the external PHY are gpio pins. However, the driver needs to reprogram the pinmux so that those pins are wired to the Emac controller. That's what the the gpio code in this driver is doing: it's just configuring the pins so that they connect directly between the Emac and the external PHY. After that, they are no longer GPIO pins, and you cannot use the "GPIO controlled MDIO bus". There is no MDIO controller on the SOC. The external PHY is controlled directly from the Emac and also from the internal PHY. It is screwy, I know, but that's what Gilad was trying to explain.

It is incorrect to say there's no MDIO controller on the SoC. The EMAC Core on the SoC itself has a MDIO controller which talks to the external PHY. The internal SGMII is not on MDIO however. Please see the EMAC specification.

Sorry, I should have said that there is no *independent* MDIO controller (one that has its own driver). As you said, you can only talk to the external PHY through the Emac.

Signature · 7 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, 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
#15 lore raw
In reply to Timur Tabi
Quoted 17 lines · Timur Tabi
Quoted 11 lines · Andrew Lunn

There are two different things here. One is configuring the pin to be a GPIO. The second is using the GPIO as a GPIO. In this case, bit-banging the MDIO bus.

The firmware could be doing the configuration, setting the pin as a GPIO. However, the firmware cannot be doing the MDIO bit-banging to make an MDIO bus available. Linux has to do that.

Or it could be we have all completely misunderstood the hardware, and we are not doing bit-banging GPIO MDIO. There is a real MDIO controller there, we don't use these pins as GPIOs, etc....

Actually, I think there is a misunderstanding.

Quoted 10 lines

On the FSM9900 SOC (which uses device-tree), the two pins that connect to the external PHY are gpio pins. However, the driver needs to reprogram the pinmux so that those pins are wired to the Emac controller. That's what the the gpio code in this driver is doing: it's just configuring the pins so that they connect directly between the Emac and the external PHY. After that, they are no longer GPIO pins, and you cannot use the "GPIO controlled MDIO bus". There is no MDIO controller on the SOC. The external PHY is controlled directly from the Emac and also from the internal PHY. It is screwy, I know, but that's what Gilad was trying to explain.

It sounds like you're trying to say that the pins used can be are muxed as GPIO or MDIO, in the TLMM.

In the downstream kernel this is often seen with the drivers calling gpio_request() to "reserve" said pins, but all you should do is described the desired configuration and muxing in the pinctrl node, reference that from your driver and simply ignore the fact that those pins could have been used as GPIO pins.

Regards,
Bjorn
--
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
Quoted 2 lines · Bjorn Andersson

It sounds like you're trying to say that the pins used can be are muxed as GPIO or MDIO, in the TLMM.

I'm not 100% sure, but I think that's correct. If you don't want to have normal networking, you could connect those external pins to some GPIO device (like an LED or whatever), and then configure the pin muxing for GPIO purposes. But if that's true, it's only true on the FSM9900. On the QDF2432, those lines are not connected to the TLMM. They are instead hard-wired to the Emac.

Quoted 5 lines

In the downstream kernel this is often seen with the drivers calling gpio_request() to "reserve" said pins, but all you should do is described the desired configuration and muxing in the pinctrl node, reference that from your driver and simply ignore the fact that those pins could have been used as GPIO pins.

That makes sense, but I think the driver already does that.

https://patchwork.ozlabs.org/patch/561667/

Function emac_probe_resources() has a call to of_get_named_gpio(). And then emac_mac_up() calls gpio_request(). As far as I can tell, that's it.

I'm guessing that the of_get_named_gpio() call needs to be changed somehow, but I'm not sure how.

Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
Forum, a Linux Foundation collaborative project.
#17 lore raw
Quoted 5 lines · Timur Tabi
Quoted 2 lines · Bjorn Andersson

It sounds like you're trying to say that the pins used can be are muxed as GPIO or MDIO, in the TLMM.

Quoted 7 lines

I'm not 100% sure, but I think that's correct. If you don't want to have normal networking, you could connect those external pins to some GPIO device (like an LED or whatever), and then configure the pin muxing for GPIO purposes. But if that's true, it's only true on the FSM9900. On the QDF2432, those lines are not connected to the TLMM. They are instead hard-wired to the Emac.

Then through proper use of the pinctrl framework you should configure the FSM9900 to mux these pins appropriately and the two solutions are equivalent.

Quoted 8 lines
Quoted 5 lines

In the downstream kernel this is often seen with the drivers calling gpio_request() to "reserve" said pins, but all you should do is described the desired configuration and muxing in the pinctrl node, reference that from your driver and simply ignore the fact that those pins could have been used as GPIO pins.

That makes sense, but I think the driver already does that.

Quoted 8 lines

https://patchwork.ozlabs.org/patch/561667/

Function emac_probe_resources() has a call to of_get_named_gpio(). And then emac_mac_up() calls gpio_request(). As far as I can tell, that's it.

I'm guessing that the of_get_named_gpio() call needs to be changed somehow, but I'm not sure how.

Thanks for the link.

In short those call to the gpio framework should just be removed. They should only be there if you're using the gpiolib to control the state of those pins, and you're not as far as I can see.

The general outline of what you should have in your dts instead is:

soc {
	tlmm {
		compatible = "qcom,pinctrl-xyz";

		mdio_pins_a: mdio {
			state {
				pins = "gpio0", "gpio1";
				function = "mdio";
			};
		};
	};

	emac {
		compatible = "qcom,somthing-emac";

		pinctrl-names = "default";
		pinctrl-0 = <&mdio_pins_a>;
	};
};

Regards,
Bjorn

#18 lore raw
In reply to Gilad Avidov
Quoted 23 lines · Gilad Avidov
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +17 -0
new file mode 100644
index 0000000..36a7746
@@ -0,0 +1,1808 @@
+/* Copyright (c) 2013-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.
+ */
+
+/* Qualcomm Technologies, Inc. EMAC Ethernet Controller MAC layer support
+ */
+
+#include <linux/tcp.h>
+#include <linux/ip.h>

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

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +10 -0
+#include <linux/ipv6.h>
+#include <linux/crc32.h>
+#include <linux/if_vlan.h>
+#include <linux/jiffies.h>
+#include <linux/phy.h>
+#include <linux/of.h>
+#include <linux/gpio.h>
+#include <linux/pm_runtime.h>
+#include "emac.h"
+#include "emac-sgmii.h"

You also need

	#include <net/ip6_checksum.h>

otherwise you get this:

CC drivers/net/ethernet/qualcomm/emac/emac-mac.o
drivers/net/ethernet/qualcomm/emac/emac-mac.c: In function 'emac_tso_csum':
drivers/net/ethernet/qualcomm/emac/emac-mac.c:2045:4: error: implicit declaration of function 'csum_ipv6_magic' [-Werror=implicit-function-declaration]

    tcp_hdr(skb)->check = ~csum_ipv6_magic(
    ^