net: emac: emac gigabit ethernet controller driver
Subsystems (5)
PATCH v4 1/2 net: emac: emac gigabit ethernet controller driver
From: Gilad Avidov <[email protected]>
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]>.
---
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 | 65 + 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 | 1782 ++++++++++++++++++++ drivers/net/ethernet/qualcomm/emac/emac-mac.h | 286 ++++ drivers/net/ethernet/qualcomm/emac/emac-phy.c | 484 ++++++ drivers/net/ethernet/qualcomm/emac/emac-phy.h | 68 + drivers/net/ethernet/qualcomm/emac/emac-sgmii.c | 683 ++++++++ drivers/net/ethernet/qualcomm/emac/emac-sgmii.h | 30 + drivers/net/ethernet/qualcomm/emac/emac.c | 1206 +++++++++++++ drivers/net/ethernet/qualcomm/emac/emac.h | 382 +++++ 12 files changed, 5006 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 +65 -0
@@ -0,0 +1,65 @@ +Qualcomm EMAC Gigabit Ethernet Controller + +Required properties: +- 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. +- 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. +Example: + emac0: qcom,emac@feb20000 { + compatible = "qcom,fsm9900-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; + phy-addr = <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"; + }; + }; + };
drivers/net/ethernet/qualcomm/Kconfig +11 -0
@@ -24,4 +24,15 @@ config QCA7000 To compile this driver as a module, choose M here. The module will be called qcaspi. +config QCOM_EMAC + tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support" + select CRC32 + ---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
@@ -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
@@ -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 +1782 -0
1,782 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 +484 -0
484 lines not on this page · raw message
drivers/net/ethernet/qualcomm/emac/emac-phy.h new file +68 -0
68 lines not on this page · raw message
drivers/net/ethernet/qualcomm/emac/emac-sgmii.c new file +683 -0
288 lines not on this page · raw message
drivers/net/ethernet/qualcomm/emac/emac-sgmii.h new file +30 -0
Lines of this file are not shown. View the raw message.
drivers/net/ethernet/qualcomm/emac/emac.c new file +1206 -0
1,206 lines not on this page · raw message
drivers/net/ethernet/qualcomm/emac/emac.h new file +382 -0
382 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
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.
Part of the diff is not shown here. View the raw message.
PATCH 2/2 MAINTAINERS: add Qualcomm EMAC network driver maintainer
The driver was originally written by Gilad Avidov, but it's now being supported by Timur Tabi.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -9128,6 +9128,13 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git S: Supported F: drivers/net/wireless/ath/ath10k/ +QUALCOMM TECHNOLOGIES EMAC NETWORK DRIVER +M: Timur Tabi <[email protected]> +R: Gilad Avidov <[email protected]> +L: [email protected] +S: Supported +F: drivers/net/ethernet/qualcomm/emac/ + QUALCOMM HEXAGON ARCHITECTURE M: Richard Kuo <[email protected]> L: [email protected]
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.
kbuild test robot
build botreproduce:
Hi Gilad,
[auto build test WARNING on net/master]
[also build test WARNING on v4.6-rc3 next-20160413]
[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/Timur-Tabi/net-emac-emac-gigabit-ethernet-controller-driver/20160414-020345 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:1076:9: warning: large integer implicitly truncated to unsigned type [-Woverflow]
writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);
^vim +1076 drivers/net/ethernet/qualcomm/emac/emac-mac.c
1060 return ret;
1061
1062 ret = request_irq(irq->irq, emac_isr, 0, EMAC_MAC_IRQ_RES, irq);
1063 if (ret) {
1064 netdev_err(adpt->netdev,
1065 "error:%d on request_irq(%d:%s flags:0)\n", ret,
1066 irq->irq, EMAC_MAC_IRQ_RES);
1067 emac_sgmii_down(adpt);
1068 return ret;
1069 }
1070
1071 emac_mac_rx_descs_refill(adpt, &adpt->rx_q);
1072
1073 napi_enable(&adpt->rx_q.napi);
1074
1075 /* enable mac irq */
> 1076 writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);
1077 writel(adpt->irq.mask, adpt->base + EMAC_INT_MASK);
1078
1079 netif_start_queue(netdev);
1080 clear_bit(EMAC_STATUS_DOWN, &adpt->status);
1081
1082 /* check link status */
1083 set_bit(EMAC_STATUS_TASK_LSC_REQ, &adpt->status);
1084 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
Quoted 4 lines · kbuild test robot
drivers/net/ethernet/qualcomm/emac/emac-mac.c: In function 'emac_mac_up':Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/ethernet/qualcomm/emac/emac-mac.c:1076:9: warning: large integer implicitly truncated to unsigned type [-Woverflow]writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);
This doesn't happen on arm64, and I don't know how to fix it. DIS_INT is defined as:
#define DIS_INT BIT(31)
It seems silly to add a typecast to DIS_INT.
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.
Quoted 10 lines · Timur Tabi
Quoted 4 lines · kbuild test robot
drivers/net/ethernet/qualcomm/emac/emac-mac.c: In function 'emac_mac_up':Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/ethernet/qualcomm/emac/emac-mac.c:1076:9: warning: large integer implicitly truncated to unsigned type [-Woverflow]writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);This doesn't happen on arm64, and I don't know how to fix it.
DIS_INTis defined as:#define DIS_INT BIT(31)
Try with (1U<<31).
Quoted 2 lines
It seems silly to add a typecast to
DIS_INT.
Signature · 3 lines
Shanker Donthineni 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
Quoted 10 lines · Shanker Donthineni
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c: In function 'emac_mac_up':Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/ethernet/qualcomm/emac/emac-mac.c:1076:9: warning: large integer implicitly truncated to unsigned type [-Woverflow]
writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);This doesn't happen on arm64, and I don't know how to fix it.
DIS_INTis defined as:#define DIS_INT BIT(31)Try with (1U<<31).
Except that Gilad was previously asked to use the BIT() macros:
https://lkml.org/lkml/2015/12/15/797
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.
Quoted 7 lines · Timur Tabi
Quoted 6 lines · Shanker Donthineni
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c: In function 'emac_mac_up':Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/ethernet/qualcomm/emac/emac-mac.c:1076:9: warning: large integer implicitly truncated to unsigned type [-Woverflow]
writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);This doesn't happen on arm64, and I don't know how to fix it.
DIS_INTis defined as:
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
#define DIS_INT BIT(31)Try with (1U<<31).
Except that Gilad was previously asked to use the
BIT()macros:https://lkml.org/lkml/2015/12/15/797
So typecast it.
writel((u32)~DIS_INT, adpt->base + EMAC_INT_STATUS);
I believe the reason you don't see this on arm64 is that the writel macro includes the typecast there. But it doesn't on x86_64
Bjørn
Rob Herring
maintainerQuoted 8 lines · Timur Tabi
Quoted 4 lines · kbuild test robot
drivers/net/ethernet/qualcomm/emac/emac-mac.c: In function 'emac_mac_up':Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/ethernet/qualcomm/emac/emac-mac.c:1076:9: warning: large integer implicitly truncated to unsigned type [-Woverflow]writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);This doesn't happen on arm64, and I don't know how to fix it.
DIS_INTis defined as:
Probably depends on the compiler version. BTW, clang seems to throw errors for this type of thing.
Quoted 4 lines
#define DIS_INT BIT(31)It seems silly to add a typecast to
DIS_INT.
BIT() should use 1U instead of 1.
Rob
Quoted 9 lines · Timur Tabi
From: Gilad Avidov <[email protected]>
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.
I think you should shoot for more simple for an initial submission:
- no offload
- no timestamping
get that accepted, and then add features one by one, it sure is more work, but it helps with the review, and makes you work off a solid base.
You will see below, but a pet peeve of mine is authors reimplementing code that exists in PHYLIB.
[snip]
Quoted 17 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +11
-0@@ -0,0 +1,65 @@ +Qualcomm EMAC Gigabit Ethernet Controller + +Required properties: +- 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.
Documentation/devicetree/bindings/net/qcom-emac.txt line 21
Quoted 10 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +10
-0+ 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. +- phy-addr : Specifies phy address on MDIO bus. + Required if the optional property "qcom,no-external-phy" + is not specified.
This is not the standard way to represent an Ethernet PHY hanging off a MDIO bus see ethernet.txt and phy.txt in D/dt/bindings/net/
Documentation/devicetree/bindings/net/qcom-emac.txt line 27
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.
If the "ptp" register range is not specified, then PTP gets disabled, so is a boolean really required here, considering that this looks like a policy decision more than anything.
Documentation/devicetree/bindings/net/qcom-emac.txt line 29
Quoted 2 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +2
-0+- mac-address : The 6-byte MAC address. If present, it is the + default MAC address.
This property is pretty much mandatory
Documentation/devicetree/bindings/net/qcom-emac.txt line 32
Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +3
-0+- 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.
How is the internal PHY accessed, is it responding on the MDIO bus at a particular address? If so, standard MDIO scanning/probing works, and you can have your PHY driver flag this device has internal. Worst case, you can do what BCMGENET does, and have a special "phy-mode" value set to "internal" when this knowledge needs to exist prior to MDIO bus scanning (e.g: to power on the PHY).
Quoted 53 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +33
-0+Example: + emac0: qcom,emac@feb20000 { + compatible = "qcom,fsm9900-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; + phy-addr = <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"; + }; + }; + };drivers/net/ethernet/qualcomm/Kconfig +11
-0@@ -24,4 +24,15 @@ config QCA7000 To compile this driver as a module, choose M here. The module will be called qcaspi. +config QCOM_EMAC + tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support" + select CRC32 + ---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
[snip]
Quoted 16 lines
drivers/net/ethernet/qualcomm/Kconfig +16
-0+/* Config MAC modes */ +void emac_mac_mode_config(struct emac_adapter *adpt) +{ + u32 mac; + + mac = readl(adpt->base + EMAC_MAC_CTRL); + + if (test_bit(EMAC_STATUS_VLANSTRIP_EN, &adpt->status)) + mac |= VLAN_STRIP; + else + mac &= ~VLAN_STRIP; + + if (test_bit(EMAC_STATUS_PROMISC_EN, &adpt->status)) + mac |= PROM_MODE; + else + mac &= ~PROM_MODE;
drivers/net/ethernet/qualcomm/Kconfig
Quoted 10 lines
drivers/net/ethernet/qualcomm/Kconfig +10
-0+ + if (test_bit(EMAC_STATUS_MULTIALL_EN, &adpt->status)) + mac |= MULTI_ALL; + else + mac &= ~MULTI_ALL; + + if (test_bit(EMAC_STATUS_LOOPBACK_EN, &adpt->status)) + mac |= MAC_LP_EN; + else + mac &= ~MAC_LP_EN;
Do you need to maintain these flags when most, if not all of them already exist in dev->flags or dev->features?
[snip]
drivers/net/ethernet/qualcomm/Kconfig
Quoted 12 lines
drivers/net/ethernet/qualcomm/Kconfig +12
-0+ /* setup link speed */ + mac &= ~SPEED_BMSK; + switch (phy->link_speed) { + case EMAC_LINK_SPEED_1GB_FULL: + mac |= ((emac_mac_speed_1000 << SPEED_SHFT) & SPEED_BMSK); + csr1 |= FREQ_MODE; + break; + default: + mac |= ((emac_mac_speed_10_100 << SPEED_SHFT) & SPEED_BMSK); + csr1 &= ~FREQ_MODE; + break; + }
If you implement the driver using PHYLIB, which you should in order to support arbitrary or internal PHYs, then this function gets invoked whenever there is a link parameter change (auto-neg, forcing, duplex/speed/no link etc.).
[snip]
drivers/net/ethernet/qualcomm/Kconfig
Quoted 7 lines
drivers/net/ethernet/qualcomm/Kconfig +7
-0+ napi_enable(&adpt->rx_q.napi); + + /* enable mac irq */ + writel(~DIS_INT, adpt->base + EMAC_INT_STATUS); + writel(adpt->irq.mask, adpt->base + EMAC_INT_MASK); + + netif_start_queue(netdev);
Starting the TX queue is typically the last ting you want to do, to avoid a transient state where the TX queue is enabled, and the link is not (which is okay if your driver is properly implemented and reflects carrier changes anyway).
drivers/net/ethernet/qualcomm/Kconfig
Quoted 6 lines
drivers/net/ethernet/qualcomm/Kconfig +6
-0+ clear_bit(EMAC_STATUS_DOWN, &adpt->status); + + /* check link status */ + set_bit(EMAC_STATUS_TASK_LSC_REQ, &adpt->status); + adpt->link_chk_timeout = jiffies + EMAC_TRY_LINK_TIMEOUT; + mod_timer(&adpt->timers, jiffies);
Please implement a PHYLIB driver and use phy_start() here.
drivers/net/ethernet/qualcomm/Kconfig
Quoted 12 lines
drivers/net/ethernet/qualcomm/Kconfig +12
-0+ + return 0; +} + +/* Bring down the interface/HW */ +void emac_mac_down(struct emac_adapter *adpt, bool reset) +{ + struct net_device *netdev = adpt->netdev; + struct emac_phy *phy = &adpt->phy; + unsigned long flags; + + set_bit(EMAC_STATUS_DOWN, &adpt->status);
Do you need to maintain that? Would not netif_running() tell you what you want if you reflect the carrier state properly?
drivers/net/ethernet/qualcomm/Kconfig
Quoted 3 lines
drivers/net/ethernet/qualcomm/Kconfig +3
-0+ + netif_stop_queue(netdev); + netif_carrier_off(netdev);
phy_stop() would take care of the latter.
[snip]
Quoted 22 lines
drivers/net/ethernet/qualcomm/Kconfig +22
-0+/* Process transmit event */ +void emac_mac_tx_process(struct emac_adapter *adpt, struct emac_tx_queue *tx_q) +{ + struct emac_buffer *tpbuf; + u32 hw_consume_idx; + u32 pkts_compl = 0, bytes_compl = 0; + u32 reg = readl_relaxed(adpt->base + tx_q->consume_reg); + + hw_consume_idx = (reg & tx_q->consume_mask) >> tx_q->consume_shift; + + while (tx_q->tpd.consume_idx != hw_consume_idx) { + tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.consume_idx); + if (tpbuf->dma_addr) { + dma_unmap_single(adpt->netdev->dev.parent, + tpbuf->dma_addr, tpbuf->length, + DMA_TO_DEVICE); + tpbuf->dma_addr = 0; + } + + if (tpbuf->skb) { + pkts_compl++; + bytes_compl += tpbuf->skb->len;
drivers/net/ethernet/qualcomm/Kconfig
Quoted 10 lines
drivers/net/ethernet/qualcomm/Kconfig +10
-0+ dev_kfree_skb_irq(tpbuf->skb); + tpbuf->skb = NULL; + } + + if (++tx_q->tpd.consume_idx == tx_q->tpd.count) + tx_q->tpd.consume_idx = 0; + } + + if (pkts_compl || bytes_compl) + netdev_completed_queue(adpt->netdev, pkts_compl, bytes_compl);
The condition can be eliminated.
[snip]
drivers/net/ethernet/qualcomm/Kconfig
Quoted 12 lines
drivers/net/ethernet/qualcomm/Kconfig +12
-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); + + /* update produce idx */ + prod_idx = (tx_q->tpd.produce_idx << tx_q->produce_shift) & + tx_q->produce_mask; + emac_reg_update32(adpt->base + tx_q->produce_reg, + tx_q->produce_mask, prod_idx);
Since you have a producer index, you should consider checking skb->xmit_more to know whether you can update the register now, or later, which could save some expensive operation and batch TX.
[snip]
drivers/net/ethernet/qualcomm/emac/emac-phy.c
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac-phy.c new file +0
-0
This file is really really ugly, and duplicates a lot of functionality provided by PHYLIB, you really need to implement a PHYLIB MDIO driver and eventually a small PHY driver for your internal PHY if it needs some baby sitting.
[snip]
Quoted 38 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +32
-0@@ -0,0 +1,1206 @@ +/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +/* Qualcomm Technologies, Inc. EMAC Gigabit Ethernet Driver +* The EMAC driver supports following features: +* 1) Receive Side Scaling (RSS). +* 2) Checksum offload. +* 3) Multiple PHY support on MDIO bus. +* 4) Runtime power management support. +* 5) Interrupt coalescing support. +* 6) SGMII phy. +* 7) SGMII direct connection (without external phy). +*/ + +#include <linux/if_ether.h> +#include <linux/if_vlan.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_net.h> +#include <linux/phy.h> +#include <linux/platform_device.h>
drivers/net/ethernet/qualcomm/emac/emac.c line 42
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+#include <linux/pm_runtime.h> +#include "emac.h" +#include "emac-mac.h" +#include "emac-phy.h" +#include "emac-sgmii.h" + +#define DRV_VERSION "1.3.0.0" + +static int debug =-1 ; +module_param (debug, int,S_IRUGO |S_IWUSR |S_IWGRP );
ethtool -s <iface> msglvl provides you with that already.
drivers/net/ethernet/qualcomm/emac/emac.c line 45
Quoted 3 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +3
-0+ +static int emac_irq_use_extended; +module_param (emac_irq_use_extended, int,S_IRUGO |S_IWUSR |S_IWGRP );
What is that module parameter used for?
drivers/net/ethernet/qualcomm/emac/emac.c line 50
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +5
-0+ +const char emac_drv_name[] ="qcom-emac" ; +const char emac_drv_description[] = +"Qualcomm Technologies, Inc. EMAC Ethernet Driver" ; +const char emac_drv_version[] =DRV_VERSION ;
Static all other the place?
[snip]
Quoted 4 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +4
-0+ +/* NAPI */ +static int emac_napi_rtx (struct napi_struct *napi,int budget) +{
drivers/net/ethernet/qualcomm/emac/emac.c line 199
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+ struct emac_rx_queue *rx_q = container_of(napi, struct emac_rx_queue, + napi); +struct emac_adapter *adpt =netdev_priv (rx_q->netdev); +struct emac_irq *irq = rx_q->irq; + +int work_done =0 ; + +/* Keep link state information with original netdev */ +if (!netif_carrier_ok (adpt->netdev)) + goto quit_polling;
I do not think this is a condition that could occur?
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+ +emac_mac_rx_process (adpt, rx_q, &work_done, budget); + +if (work_done < budget) { +quit_polling: +napi_complete (napi); + + irq->mask |= rx_q->intr; +writel (irq->mask, adpt->base +EMAC_INT_MASK ); + }
drivers/net/ethernet/qualcomm/emac/emac.c line 219
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+ +return work_done; +} + +/* Transmit the packet */ +static int emac_start_xmit (struct sk_buff *skb,struct net_device *netdev) +{ +struct emac_adapter *adpt =netdev_priv (netdev); + +return emac_mac_tx_buf_send (adpt, &adpt->tx_q, skb);
I would inline emac_mac_tx_buf_send()'s body here to make it much easier to read and audit...
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +5
-0+} + +irqreturn_t emac_isr (int _irq,void *data) +{ +struct emac_irq *irq = data;
drivers/net/ethernet/qualcomm/emac/emac.c line 234
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+ struct emac_adapter *adpt = container_of(irq, struct emac_adapter, irq); +struct emac_rx_queue *rx_q = &adpt->rx_q; + +int max_ints =1 ; +u32 isr, status; + +/* disable the interrupt */ +writel (0 , adpt->base +EMAC_INT_MASK ); + + do {
With max_ints = 1, this is essentially the same as no loop, so just inline it to reduce the indentation.
Quoted 17 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +17
-0+ isr =readl_relaxed (adpt->base +EMAC_INT_STATUS ); + status = isr & irq->mask; + +if (status ==0 ) +break ; + +if (status &ISR_ERROR ) { +netif_warn (adpt, intr, adpt->netdev, +"warning: error irq status 0x%lx\n" , + status &ISR_ERROR ); +/* reset MAC */ +set_bit (EMAC_STATUS_TASK_REINIT_REQ , &adpt->status); +emac_work_thread_reschedule (adpt); + } + +/* Schedule the napi for receive queue with interrupt +* status bit set
drivers/net/ethernet/qualcomm/emac/emac.c line 261
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+*/ +if ((status & rx_q->intr)) { +if (napi_schedule_prep (&rx_q->napi)) { + irq->mask &= ~rx_q->intr; +__napi_schedule (&rx_q->napi); + } + } + +if (status &TX_PKT_INT ) +emac_mac_tx_process (adpt, &adpt->tx_q);
You should consider using a NAPI instance for reclaiming TX buffers as well.
drivers/net/ethernet/qualcomm/emac/emac.c line 266
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +5
-0+ +if (status &ISR_OVER ) +netif_warn (adpt, intr, adpt->netdev, +"warning: TX/RX overflow status 0x%lx\n" , + status &ISR_OVER );
This should be ratelimited presumably
Quoted 20 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +20
-0+ +/* link event */ +if (status & (ISR_GPHY_LINK |SW_MAN_INT )) { +emac_lsc_schedule_check (adpt); +break ; + } + }while (--max_ints >0 ); + +/* enable the interrupt */ +writel (irq->mask, adpt->base +EMAC_INT_MASK ); + +return IRQ_HANDLED ; +} + +/* Configure VLAN tag strip/insert feature */ +static int emac_set_features (struct net_device *netdev, +netdev_features_t features) +{ +struct emac_adapter *adpt =netdev_priv (netdev); +
drivers/net/ethernet/qualcomm/emac/emac.c line 296
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+netdev_features_t changed = features ^ netdev->features; + +if (!(changed & (NETIF_F_HW_VLAN_CTAG_TX |NETIF_F_HW_VLAN_CTAG_RX ))) +return 0 ; + + netdev->features = features; +if (netdev->features &NETIF_F_HW_VLAN_CTAG_RX ) +set_bit (EMAC_STATUS_VLANSTRIP_EN , &adpt->status); +else +clear_bit (EMAC_STATUS_VLANSTRIP_EN , &adpt->status);
What about TX vlan offload?
[snip]
drivers/net/ethernet/qualcomm/emac/emac.c line 362
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +8
-0+ +/* Called when the network interface is made active */ +static int emac_open (struct net_device *netdev) +{ +struct emac_adapter *adpt =netdev_priv (netdev); +int ret; + +netif_carrier_off (netdev);
That seems unnecessary here because your close/down function does that, and with PHYLIB you would get it set correctly anyway.
[snip]
Quoted 37 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +37
-0+/* PHY related IOCTLs */ +static int emac_mii_ioctl (struct net_device *netdev, +struct ifreq *ifr,int cmd) +{ +struct emac_adapter *adpt =netdev_priv (netdev); +struct emac_phy *phy = &adpt->phy; +struct mii_ioctl_data *data =if_mii (ifr); + +switch (cmd) { +case SIOCGMIIPHY : + data->phy_id = phy->addr; +return 0 ; + +case SIOCGMIIREG : +if (!capable (CAP_NET_ADMIN )) +return -EPERM ; + +if (data->reg_num & ~(0x1F )) +return -EFAULT ; + +if (data->phy_id >=PHY_MAX_ADDR ) +return -EFAULT ; + +if (phy->external && data->phy_id != phy->addr) +return -EFAULT ; + +return emac_phy_read (adpt, data->phy_id, data->reg_num, + &data->val_out); + +case SIOCSMIIREG : +if (!capable (CAP_NET_ADMIN )) +return -EPERM ; + +if (data->reg_num & ~(0x1F )) +return -EFAULT ; + +if (data->phy_id >=PHY_MAX_ADDR )
drivers/net/ethernet/qualcomm/emac/emac.c line 449
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+return -EFAULT ; + +if (phy->external && data->phy_id != phy->addr) +return -EFAULT ; + +return emac_phy_write (adpt, data->phy_id, data->reg_num, + data->val_in); +default : +return -EFAULT ; + }
All of that can be eliminated with a PHYLIB implementation too.
[snip]
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +6
-0+/* Provide network statistics info for the interface */ +struct rtnl_link_stats64 *emac_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *net_stats) +{ +struct emac_adapter *adpt =netdev_priv (netdev); +struct emac_stats *stats = &adpt->stats;
drivers/net/ethernet/qualcomm/emac/emac.c line 491
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+u16 addr =REG_MAC_RX_STATUS_BIN ; +u64 *stats_itr = &adpt->stats.rx_ok; +u32 val; + +while (addr <=REG_MAC_RX_STATUS_END ) { + val =readl_relaxed (adpt->base + addr); + *stats_itr += val; + ++stats_itr; + addr +=sizeof (u32); + }
There is no reader locking here, what happens if two applications read the statistics at the same time?
[snip]
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +8
-0+/* Get the resources */ +static int emac_probe_resources (struct platform_device *pdev, +struct emac_adapter *adpt) +{ +struct net_device *netdev = adpt->netdev; +struct device_node *node = pdev->dev.of_node; +struct resource *res; +const void *maddr;
drivers/net/ethernet/qualcomm/emac/emac.c line 946
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+int ret =0 ; +int i; + +/* get time stamp enable flag */ + adpt->timestamp_en =of_property_read_bool (node,"qcom,emac-tstamp-en" ); + +/* get mac address */ + maddr =of_get_mac_address (node); +if (!maddr) +return -ENODEV ;
No, generate a random one, continue, but warn,
Quoted 25 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +25
-0+ +memcpy (adpt->mac_perm_addr, maddr, netdev->addr_len); + + ret =platform_get_irq_byname (pdev,EMAC_MAC_IRQ_RES ); +if (ret <0 ) { +netdev_err (adpt->netdev, +"error: missing %s resource\n" ,EMAC_MAC_IRQ_RES ); +return ret; + } + adpt->irq.irq = ret; + + ret =emac_clks_get (pdev, adpt); +if (ret) +return ret; + +/* get register addresses */ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"base" ); +if (!res) { +netdev_err (adpt->netdev,"error: missing 'base' resource\n" ); + ret = -ENXIO ; + goto err_reg_res; + } + + adpt->base =devm_ioremap_resource (&pdev->dev, res); +if (!adpt->base) {
drivers/net/ethernet/qualcomm/emac/emac.c line 981
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+ ret = -ENOMEM ; + goto err_reg_res; + } + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"csr" ); +if (!res) { +netdev_err (adpt->netdev,"error: missing 'csr' resource\n" ); + ret = -ENXIO ; + goto err_reg_res; + }
No need to check that, devm_ioremap_resource() does it too.
Quoted 37 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +37
-0+ + adpt->csr =devm_ioremap_resource (&pdev->dev, res); +if (!adpt->csr) { + ret = -ENOMEM ; + goto err_reg_res; + } + + netdev->base_addr = (unsigned long )adpt->base; +return 0 ; + +err_reg_res: +for (i =0 ; i <EMAC_CLK_CNT ; i++) { +if (adpt->clk[i]) { +clk_put (adpt->clk[i]); + adpt->clk[i] =NULL ; + } + } + +return ret; +} + +/* Release resources */ +static void emac_release_resources (struct emac_adapter *adpt) +{ +int i; + +for (i =0 ; i <EMAC_CLK_CNT ; i++) +if (adpt->clk[i]) { +clk_put (adpt->clk[i]); + adpt->clk[i] =NULL ; + } +} + +/* Probe function */ +static int emac_probe (struct platform_device *pdev) +{ +struct net_device *netdev;
drivers/net/ethernet/qualcomm/emac/emac.c line 1028
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+struct emac_adapter *adpt; +struct emac_phy *phy; +int ret =0 ; +u32 hw_ver; +u32 extended_irq_mask = emac_irq_use_extended ?IMR_EXTENDED_MASK : +IMR_NORMAL_MASK ; + + netdev =alloc_etherdev (sizeof (struct emac_adapter )); +if (!netdev) +return -ENOMEM ;
There are references to multiple queues in the code, so why not alloc_etherdev_mq() here with the correct number of queues?
drivers/net/ethernet/qualcomm/emac/emac.c line 1038
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+ +dev_set_drvdata (&pdev->dev, netdev); +SET_NETDEV_DEV (netdev, &pdev->dev); + + adpt =netdev_priv (netdev); + adpt->netdev = netdev; + phy = &adpt->phy; + adpt->msg_enable =netif_msg_init (debug,EMAC_MSG_DEFAULT ); + +dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 ));
Really, is not that supposed to run on ARM64 servers?
Signature · 1 line
Florian
Quoted 11 lines · Florian Fainelli
Quoted 9 lines · Timur Tabi
From: Gilad Avidov <[email protected]>
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.
Quoted 7 lines
I think you should shoot for more simple for an initial submission:
- no offload
- no timestampingget that accepted, and then add features one by one, it sure is more work, but it helps with the review, and makes you work off a solid base.
Unfortunately, I didn't write this driver initially, so I'm not sure how to remove these features from it. Variants of this driver have been bouncing around Qualcomm for years, and even the author of this patch (Gilad) is no longer around.
So although I have a lot of experience upstreaming code, I have little experience and knowledge with network drivers. I'm going to need a lot of hand-holding. I hope you will be patient with me.
Timestamping support seems to be just a few lines of code, so I can probably remove that. I don't know where offloading is in the driver, however. I don't know how offloading in netdev drivers works.
Quoted 2 lines
You will see below, but a pet peeve of mine is authors reimplementing code that exists in PHYLIB.
I can understand that, but the PHYs on these SOCs are non-standard. The "internal PHY" (for lack of a better name) is part of the EMAC itself, and it acts as a middle-man for the external PHY. There is an MDIO bus, but it's hard-wired to the EMAC, and most of the time you don't touch it directly. Instead you let the EMAC and/or the internal PHY send/receive commands/data to the external PHY on your behalf. The internal phy talks to the external phy via SGMII only. Only the EMAC uses the mdio bus.
I will look at PHYLIB, but I can't tell you whether it will work with this hardware (Gilad previously claim that it wouldn't work well).
Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +16
-0@@ -0,0 +1,65 @@ +Qualcomm EMAC Gigabit Ethernet Controller + +Required properties: +- 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:
Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt line 21
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5
-0+ "emac_core0" : EMAC core0 interrupt. + "sgmii_irq" : EMAC SGMII interrupt. +- phy-addr : Specifies phy address on MDIO bus. + Required if the optional property "qcom,no-external-phy" + is not specified.This is not the standard way to represent an Ethernet PHY hanging off a MDIO bus see ethernet.txt and phy.txt in D/dt/bindings/net/
The MDIO bus on these chips is not accessible as a separate entity. It is melded (for lack of a better word) into the EMAC itself. That's why there is a "qcom,no-external-phy" property. You could, in theory, wire the internal phy of one SOC directly to the internal phy of another SOC, and use that as in interconnect between SOCs. I don't know of any such use-cases however.
Quoted 9 lines
Documentation/devicetree/bindings/net/qcom-emac.txt line 27
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.If the "ptp" register range is not specified, then PTP gets disabled, so is a boolean really required here, considering that this looks like a policy decision more than anything.
It is, and I forget to remove it, since this is apparently handled via ethtool (which the driver does not currently support).
Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt line 29
Quoted 2 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +2
-0+- mac-address : The 6-byte MAC address. If present, it is the + default MAC address.This property is pretty much mandatory
Ok.
Quoted 6 lines
Documentation/devicetree/bindings/net/qcom-emac.txt line 32
Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +3
-0+- 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.How is the internal PHY accessed, is it responding on the MDIO bus at a particular address?
There is a set of memory-mapped registers. It's not connected via MDIO at all. It's mapped via the "sgmii" addresses in the device tree (see function emac_sgmii_config).
Quoted 5 lines
If so, standard MDIO scanning/probing works, and you
can have your PHY driver flag this device has internal. Worst case, you can do what BCMGENET does, and have a special "phy-mode" value set to "internal" when this knowledge needs to exist prior to MDIO bus scanning (e.g: to power on the PHY).
So the internal phy is not a real phy. It's not capable of driving an RJ45 port (there's no analog part). It's an SGMII-like device that is hard-wired to the EMAC itself.
In theory, the internal PHY is optional. You could design an SOC that has just the EMAC connected via normal MDIO to an external phy. I really wish our hardware designers has done that. But unfortunately, there are no SOCs like that, and so we have to treat the internal phy as an extension of the EMAC.
My preference would be to get rid of the "qcom,no-external-phy" property and have an external phy be required, at least until Qualcomm creates an SOC without the internal phy (which may never happen, for all I know).
Quoted 21 lines
Quoted 21 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +21
-0+/* Config MAC modes */ +void emac_mac_mode_config(struct emac_adapter *adpt) +{ + u32 mac; + + mac = readl(adpt->base + EMAC_MAC_CTRL); + + if (test_bit(EMAC_STATUS_VLANSTRIP_EN, &adpt->status)) + mac |= VLAN_STRIP; + else + mac &= ~VLAN_STRIP; + + if (test_bit(EMAC_STATUS_PROMISC_EN, &adpt->status)) + mac |= PROM_MODE; + else + mac &= ~PROM_MODE; + + if (test_bit(EMAC_STATUS_MULTIALL_EN, &adpt->status)) + mac |= MULTI_ALL; + else + mac &= ~MULTI_ALL;
Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt line 57
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5
-0+ + if (test_bit(EMAC_STATUS_LOOPBACK_EN, &adpt->status)) + mac |= MAC_LP_EN; + else + mac &= ~MAC_LP_EN;Do you need to maintain these flags when most, if not all of them already exist in
dev->flagsordev->features?
So you're saying that, for example, in emac_set_features() I should remove this:
if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) set_bit(EMAC_STATUS_VLANSTRIP_EN, &adpt->status); else clear_bit(EMAC_STATUS_VLANSTRIP_EN, &adpt->status);
and then in emac_mac_mode_config(), I should do this instead:
void emac_mac_mode_config(struct emac_adapter *adpt)
{
struct net_device *netdev = adpt->netdev;
if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
mac |= VLAN_STRIP;
else
mac &= ~VLAN_STRIP;If so, then what do I do in emac_rx_mode_set()? Should I delete this entire block:
/* Check for Promiscuous and All Multicast modes */
if (netdev->flags & IFF_PROMISC) {
set_bit(EMAC_STATUS_PROMISC_EN, &adpt->status);
} else if (netdev->flags & IFF_ALLMULTI) {
set_bit(EMAC_STATUS_MULTIALL_EN, &adpt->status);
clear_bit(EMAC_STATUS_PROMISC_EN, &adpt->status);
} else {
clear_bit(EMAC_STATUS_MULTIALL_EN, &adpt->status);
clear_bit(EMAC_STATUS_PROMISC_EN, &adpt->status);
}It does look like Gilad is just mirroring the flags/features variable into adpt->status. What I can't figure out is why. It seems completely redundant, but I have a nagging feeling that there is a good reason.
Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +9
-0+ /* setup link speed */ + mac &= ~SPEED_BMSK; + switch (phy->link_speed) { + case EMAC_LINK_SPEED_1GB_FULL: + mac |= ((emac_mac_speed_1000 << SPEED_SHFT) & SPEED_BMSK); + csr1 |= FREQ_MODE; + break; + default: + mac |= ((emac_mac_speed_10_100 << SPEED_SHFT) & SPEED_BMSK);
Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +3
-0+ csr1 &= ~FREQ_MODE; + break; + }If you implement the driver using PHYLIB, which you should in order to support arbitrary or internal PHYs, then this function gets invoked whenever there is a link parameter change (auto-neg, forcing, duplex/speed/no link etc.).
Ok, I'll probably understand this better once I figure out how to implement phylib.
Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4
-0+ napi_enable(&adpt->rx_q.napi); + + /* enable mac irq */ + writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);
Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +3
-0+ writel(adpt->irq.mask, adpt->base + EMAC_INT_MASK); + + netif_start_queue(netdev);Starting the TX queue is typically the last ting you want to do, to avoid a transient state where the TX queue is enabled, and the link is not (which is okay if your driver is properly implemented and reflects carrier changes anyway).
So I should move the netif_start_queue() to the end of this function? Sorry if that's a stupid question, but I know little about the MAC side of network drivers.
Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 6 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +6
-0+ clear_bit(EMAC_STATUS_DOWN, &adpt->status); + + /* check link status */ + set_bit(EMAC_STATUS_TASK_LSC_REQ, &adpt->status); + adpt->link_chk_timeout = jiffies + EMAC_TRY_LINK_TIMEOUT; + mod_timer(&adpt->timers, jiffies);Please implement a PHYLIB driver and use
phy_start()here.
Ok, I'll try it.
Quoted 16 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 13 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +12
-0+ + return 0; +} + +/* Bring down the interface/HW */ +void emac_mac_down(struct emac_adapter *adpt, bool reset) +{ + struct net_device *netdev = adpt->netdev; + struct emac_phy *phy = &adpt->phy; + unsigned long flags; + + set_bit(EMAC_STATUS_DOWN, &adpt->status);Do you need to maintain that? Would not
netif_running()tell you what you want if you reflect the carrier state properly?
I think that emac_work_thread_link_check() handles this. It's a timer thread that polls the link state and calls netif_carrier_off() if the link is down. Is that sufficient?
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +3
-0+ + netif_stop_queue(netdev); + netif_carrier_off(netdev);
phy_stop()would take care of the latter.
I'm beginning to see how phylib support would be useful.
Quoted 26 lines
Quoted 26 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +26
-0+/* Process transmit event */ +void emac_mac_tx_process(struct emac_adapter *adpt, struct emac_tx_queue *tx_q) +{ + struct emac_buffer *tpbuf; + u32 hw_consume_idx; + u32 pkts_compl = 0, bytes_compl = 0; + u32 reg = readl_relaxed(adpt->base + tx_q->consume_reg); + + hw_consume_idx = (reg & tx_q->consume_mask) >> tx_q->consume_shift; + + while (tx_q->tpd.consume_idx != hw_consume_idx) { + tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.consume_idx); + if (tpbuf->dma_addr) { + dma_unmap_single(adpt->netdev->dev.parent, + tpbuf->dma_addr, tpbuf->length, + DMA_TO_DEVICE); + tpbuf->dma_addr = 0; + } + + if (tpbuf->skb) { + pkts_compl++; + bytes_compl += tpbuf->skb->len; + dev_kfree_skb_irq(tpbuf->skb); + tpbuf->skb = NULL; + } +
Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 6 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +6
-0+ if (++tx_q->tpd.consume_idx == tx_q->tpd.count) + tx_q->tpd.consume_idx = 0; + } + + if (pkts_compl || bytes_compl) + netdev_completed_queue(adpt->netdev, pkts_compl, bytes_compl);The condition can be eliminated.
Ok.
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +8
-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); + + /* update produce idx */
Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4
-0+ prod_idx = (tx_q->tpd.produce_idx << tx_q->produce_shift) & + tx_q->produce_mask; + emac_reg_update32(adpt->base + tx_q->produce_reg, + tx_q->produce_mask, prod_idx);Since you have a producer index, you should consider checking
skb->xmit_moreto know whether you can update the register now, or later, which could save some expensive operation and batch TX.
I'll have to figure out what means and get back to you. When would "later" be?
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-phy.c
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac-phy.c new file +0
-0This file is really really ugly, and duplicates a lot of functionality provided by PHYLIB, you really need to implement a PHYLIB MDIO driver and eventually a small PHY driver for your internal PHY if it needs some baby sitting.
I'll try.
Quoted 42 lines
Quoted 42 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +36
-0@@ -0,0 +1,1206 @@ +/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +/* Qualcomm Technologies, Inc. EMAC Gigabit Ethernet Driver +* The EMAC driver supports following features: +* 1) Receive Side Scaling (RSS). +* 2) Checksum offload. +* 3) Multiple PHY support on MDIO bus. +* 4) Runtime power management support. +* 5) Interrupt coalescing support. +* 6) SGMII phy. +* 7) SGMII direct connection (without external phy). +*/ + +#include <linux/if_ether.h> +#include <linux/if_vlan.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_net.h> +#include <linux/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include "emac.h" +#include "emac-mac.h" +#include "emac-phy.h"
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 42
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +6
-0+#include "emac-sgmii.h" + +#define DRV_VERSION "1.3.0.0" + +static int debug =-1 ; +module_param (debug, int,S_IRUGO |S_IWUSR |S_IWGRP );ethtool -s <iface> msglvl provides you with that already.
I'll remove it. There's no ethtool support in this driver anyway, but there's no code that uses this parameter.
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 45
Quoted 4 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +3
-0+ +static int emac_irq_use_extended; +module_param (emac_irq_use_extended, int,S_IRUGO |S_IWUSR |S_IWGRP );What is that module parameter used for?
Good question. Apparently it's some IRQ mask. I'll have to study the documentation and get back to you. We don't ever set the parameter, so I think I'll just drop it.
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 50
Quoted 4 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +4
-0+const char emac_drv_name[] ="qcom-emac" ; +const char emac_drv_description[] = +"Qualcomm Technologies, Inc. EMAC Ethernet Driver" ; +const char emac_drv_version[] =DRV_VERSION ;Static all other the place?
Thanks for catching that. I'll fix it.
Quoted 19 lines
[snip]
Quoted 4 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +4
-0+ +/* NAPI */ +static int emac_napi_rtx (struct napi_struct *napi,int budget) +{drivers/net/ethernet/qualcomm/emac/emac.c line 199
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+ struct emac_rx_queue *rx_q = container_of(napi, struct emac_rx_queue, + napi); +struct emac_adapter *adpt =netdev_priv (rx_q->netdev); +struct emac_irq *irq = rx_q->irq; + +int work_done =0 ; + +/* Keep link state information with original netdev */ +if (!netif_carrier_ok (adpt->netdev)) + goto quit_polling;I do not think this is a condition that could occur?
I don't know what this code is trying to do. I'll have to study it and get back to you.
Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +15
-0+ +emac_mac_rx_process (adpt, rx_q, &work_done, budget); + +if (work_done < budget) { +quit_polling: +napi_complete (napi); + + irq->mask |= rx_q->intr; +writel (irq->mask, adpt->base +EMAC_INT_MASK ); + } + +return work_done; +} + +/* Transmit the packet */
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 219
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +5
-0+static int emac_start_xmit (struct sk_buff *skb,struct net_device *netdev) +{ +struct emac_adapter *adpt =netdev_priv (netdev); + +return emac_mac_tx_buf_send (adpt, &adpt->tx_q, skb);I would inline emac_mac_tx_buf_send()'s body here to make it much easier to read and audit...
Ok.
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+} + +irqreturn_t emac_isr (int _irq,void *data) +{ +struct emac_irq *irq = data; + struct emac_adapter *adpt = container_of(irq, struct emac_adapter, irq); +struct emac_rx_queue *rx_q = &adpt->rx_q; + +int max_ints =1 ; +u32 isr, status;
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 234
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +5
-0+ +/* disable the interrupt */ +writel (0 , adpt->base +EMAC_INT_MASK ); + + do {With
max_ints= 1, this is essentially the same as no loop, so just inline it to reduce the indentation.
In another internal version of this driver, max_ints is set to 5. Could this be some way of processing multiple packets in one interrupt? Isn't that something that NAPI already takes care of, anyway?
Quoted 21 lines
Quoted 21 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +21
-0+ isr =readl_relaxed (adpt->base +EMAC_INT_STATUS ); + status = isr & irq->mask; + +if (status ==0 ) +break ; + +if (status &ISR_ERROR ) { +netif_warn (adpt, intr, adpt->netdev, +"warning: error irq status 0x%lx\n" , + status &ISR_ERROR ); +/* reset MAC */ +set_bit (EMAC_STATUS_TASK_REINIT_REQ , &adpt->status); +emac_work_thread_reschedule (adpt); + } + +/* Schedule the napi for receive queue with interrupt +* status bit set +*/ +if ((status & rx_q->intr)) { +if (napi_schedule_prep (&rx_q->napi)) { + irq->mask &= ~rx_q->intr;
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 261
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +6
-0+__napi_schedule (&rx_q->napi); + } + } + +if (status &TX_PKT_INT ) +emac_mac_tx_process (adpt, &adpt->tx_q);You should consider using a NAPI instance for reclaiming TX buffers as well.
I'll have to figure out what means and get back to you.
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 266
Quoted 4 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +4
-0+if (status &ISR_OVER ) +netif_warn (adpt, intr, adpt->netdev, +"warning: TX/RX overflow status 0x%lx\n" , + status &ISR_OVER );This should be ratelimited presumably
Ok.
Quoted 25 lines
Quoted 25 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +24
-0+ +/* link event */ +if (status & (ISR_GPHY_LINK |SW_MAN_INT )) { +emac_lsc_schedule_check (adpt); +break ; + } + }while (--max_ints >0 ); + +/* enable the interrupt */ +writel (irq->mask, adpt->base +EMAC_INT_MASK ); + +return IRQ_HANDLED ; +} + +/* Configure VLAN tag strip/insert feature */ +static int emac_set_features (struct net_device *netdev, +netdev_features_t features) +{ +struct emac_adapter *adpt =netdev_priv (netdev); + +netdev_features_t changed = features ^ netdev->features; + +if (!(changed & (NETIF_F_HW_VLAN_CTAG_TX |NETIF_F_HW_VLAN_CTAG_RX ))) +return 0 ;
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 296
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +6
-0+ + netdev->features = features; +if (netdev->features &NETIF_F_HW_VLAN_CTAG_RX ) +set_bit (EMAC_STATUS_VLANSTRIP_EN , &adpt->status); +else +clear_bit (EMAC_STATUS_VLANSTRIP_EN , &adpt->status);What about TX vlan offload?
I don't know what that is.
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 362
Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +7
-0+/* Called when the network interface is made active */ +static int emac_open (struct net_device *netdev) +{ +struct emac_adapter *adpt =netdev_priv (netdev); +int ret; + +netif_carrier_off (netdev);That seems unnecessary here because your close/down function does that, and with PHYLIB you would get it set correctly anyway.
Ok. I'll see what I can do about it.
Quoted 41 lines
Quoted 41 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +41
-0+/* PHY related IOCTLs */ +static int emac_mii_ioctl (struct net_device *netdev, +struct ifreq *ifr,int cmd) +{ +struct emac_adapter *adpt =netdev_priv (netdev); +struct emac_phy *phy = &adpt->phy; +struct mii_ioctl_data *data =if_mii (ifr); + +switch (cmd) { +case SIOCGMIIPHY : + data->phy_id = phy->addr; +return 0 ; + +case SIOCGMIIREG : +if (!capable (CAP_NET_ADMIN )) +return -EPERM ; + +if (data->reg_num & ~(0x1F )) +return -EFAULT ; + +if (data->phy_id >=PHY_MAX_ADDR ) +return -EFAULT ; + +if (phy->external && data->phy_id != phy->addr) +return -EFAULT ; + +return emac_phy_read (adpt, data->phy_id, data->reg_num, + &data->val_out); + +case SIOCSMIIREG : +if (!capable (CAP_NET_ADMIN )) +return -EPERM ; + +if (data->reg_num & ~(0x1F )) +return -EFAULT ; + +if (data->phy_id >=PHY_MAX_ADDR ) +return -EFAULT ; + +if (phy->external && data->phy_id != phy->addr) +return -EFAULT ;
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 449
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +6
-0+ +return emac_phy_write (adpt, data->phy_id, data->reg_num, + data->val_in); +default : +return -EFAULT ; + }All of that can be eliminated with a PHYLIB implementation too.
Ok.
Quoted 14 lines
[snip]
Quoted 11 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +11
-0+/* Provide network statistics info for the interface */ +struct rtnl_link_stats64 *emac_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *net_stats) +{ +struct emac_adapter *adpt =netdev_priv (netdev); +struct emac_stats *stats = &adpt->stats; +u16 addr =REG_MAC_RX_STATUS_BIN ; +u64 *stats_itr = &adpt->stats.rx_ok; +u32 val; + +while (addr <=REG_MAC_RX_STATUS_END ) {
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 491
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +5
-0+ val =readl_relaxed (adpt->base + addr); + *stats_itr += val; + ++stats_itr; + addr +=sizeof (u32); + }There is no reader locking here, what happens if two applications read the statistics at the same time?
Ah, even though the readl is atomic, it's reading a bunch of them in a row. I'll add a lock or something.
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +12
-0+/* Get the resources */ +static int emac_probe_resources (struct platform_device *pdev, +struct emac_adapter *adpt) +{ +struct net_device *netdev = adpt->netdev; +struct device_node *node = pdev->dev.of_node; +struct resource *res; +const void *maddr; +int ret =0 ; +int i; + +/* get time stamp enable flag */
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 946
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +6
-0+ adpt->timestamp_en =of_property_read_bool (node,"qcom,emac-tstamp-en" ); + +/* get mac address */ + maddr =of_get_mac_address (node); +if (!maddr) +return -ENODEV ;No, generate a random one, continue, but warn,
Ok.
Quoted 30 lines
Quoted 30 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +29
-0+ +memcpy (adpt->mac_perm_addr, maddr, netdev->addr_len); + + ret =platform_get_irq_byname (pdev,EMAC_MAC_IRQ_RES ); +if (ret <0 ) { +netdev_err (adpt->netdev, +"error: missing %s resource\n" ,EMAC_MAC_IRQ_RES ); +return ret; + } + adpt->irq.irq = ret; + + ret =emac_clks_get (pdev, adpt); +if (ret) +return ret; + +/* get register addresses */ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"base" ); +if (!res) { +netdev_err (adpt->netdev,"error: missing 'base' resource\n" ); + ret = -ENXIO ; + goto err_reg_res; + } + + adpt->base =devm_ioremap_resource (&pdev->dev, res); +if (!adpt->base) { + ret = -ENOMEM ; + goto err_reg_res; + } +
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 981
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +6
-0+ res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"csr" ); +if (!res) { +netdev_err (adpt->netdev,"error: missing 'csr' resource\n" ); + ret = -ENXIO ; + goto err_reg_res; + }No need to check that,
devm_ioremap_resource()does it too.
Ok.
Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +9
-0+/* Probe function */ +static int emac_probe (struct platform_device *pdev) +{ +struct net_device *netdev; +struct emac_adapter *adpt; +struct emac_phy *phy; +int ret =0 ; +u32 hw_ver; + u32 extended_irq_mask = emac_irq_use_extended ? IMR_EXTENDED_MASK :
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 1028
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +5
-0+IMR_NORMAL_MASK ; + + netdev =alloc_etherdev (sizeof (struct emac_adapter )); +if (!netdev) +return -ENOMEM ;There are references to multiple queues in the code, so why not
alloc_etherdev_mq()here with the correct number of queues?
That support was removed from the driver, and on our SOC, we hard-code the number of queues to 1 anyway. I'm planning on adding multiple queue support (much) later.
Quoted 11 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 1038
Quoted 9 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +9
-0+dev_set_drvdata (&pdev->dev, netdev); +SET_NETDEV_DEV (netdev, &pdev->dev); + + adpt =netdev_priv (netdev); + adpt->netdev = netdev; + phy = &adpt->phy; + adpt->msg_enable =netif_msg_init (debug,EMAC_MSG_DEFAULT ); + +dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 ));Really, is not that supposed to run on ARM64 servers?
Well, this version of the driver isn't, which is why it supports DT and not ACPI. I'm planning on adding that support in a later patch. However, I'll add support for 64-bit masks in the next version of this patch.
Would this be okay:
retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
if (retval) {
dev_err(&pdev->dev, "failed to set DMA mask err %d\n", retval);
goto err_res;
}I've seen code like this in other drivers:
ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
if (ret) {
ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
if (ret) {
dev_err(dev, "failed to set dma mask\n");
return ret;
}
}and I've never understood why it's necessary to fall back to 32-bits if 64 bits fails. Isn't 64 bits a superset of 32 bits? The driver is saying that the hardware supports all of DDR. How could fail, and how could 32-bit succeed if 64-bits fails?
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.
Quoted 18 lines · Timur Tabi
Quoted 17 lines · Florian Fainelli
Quoted 10 lines · Timur Tabi
From: Gilad Avidov <[email protected]>
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.I think you should shoot for more simple for an initial submission:
- no offload
- no timestamping
Quoted 7 lines
Quoted 2 lines
get that accepted, and then add features one by one, it sure is more work, but it helps with the review, and makes you work off a solid base.
Unfortunately, I didn't write this driver initially, so I'm not sure how to remove these features from it. Variants of this driver have been bouncing around Qualcomm for years, and even the author of this patch (Gilad) is no longer around.
Well, good luck :)
Quoted 8 lines
So although I have a lot of experience upstreaming code, I have little experience and knowledge with network drivers. I'm going to need a lot of hand-holding. I hope you will be patient with me.
Timestamping support seems to be just a few lines of code, so I can probably remove that. I don't know where offloading is in the driver, however. I don't know how offloading in netdev drivers works.
Based on what the driver seems to do right now, it would be located in the transmit and receive paths, and would have to access mac/network/transport offsets and deal with checksums, so anything that deals with checksums, provided that the HW does not require that to transmit/receive packets, could be eliminated entirely for now and be added later.
It is not the biggest part that needs to be slightly re-architected though, the SGMII/PHY/MDIO stuff is more important as it impacts the Device Tree binding, see below.
Quoted 11 lines
Quoted 3 lines
You will see below, but a pet peeve of mine is authors reimplementing code that exists in PHYLIB.
I can understand that, but the PHYs on these SOCs are non-standard. The "internal PHY" (for lack of a better name) is part of the EMAC itself, and it acts as a middle-man for the external PHY. There is an MDIO bus, but it's hard-wired to the EMAC, and most of the time you don't touch it directly. Instead you let the EMAC and/or the internal PHY send/receive commands/data to the external PHY on your behalf. The internal phy talks to the external phy via SGMII only. Only the EMAC uses the mdio bus.
Humm OK, this PHY proxy, provided that this is really how it works, seems a bit unusual, but, is not necessarily a roadblock to having a proper MDIO implementation here which is standard and will allow you to utilize re-usable drivers and facilities that are already there.
Quoted 3 lines
I will look at PHYLIB, but I can't tell you whether it will work with this hardware (Gilad previously claim that it wouldn't work well).
Well, PHYLIB does prefer using MDIO accesses to "speak" to PHYs, built-in or external, but there is always the option of investing into some custom development with the subsystem to make it play nicely with your HW.
Quoted 34 lines
Quoted 25 lines
Quoted 25 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +15
-0@@ -0,0 +1,65 @@ +Qualcomm EMAC Gigabit Ethernet Controller + +Required properties: +- 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:Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt line 21
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5
-0+ "emac_core0" : EMAC core0 interrupt. + "sgmii_irq" : EMAC SGMII interrupt. +- phy-addr : Specifies phy address on MDIO bus. + Required if the optional property "qcom,no-external-phy" + is not specified.This is not the standard way to represent an Ethernet PHY hanging off a MDIO bus see ethernet.txt and phy.txt in D/dt/bindings/net/
Quoted 6 lines
The MDIO bus on these chips is not accessible as a separate entity. It is melded (for lack of a better word) into the EMAC itself. That's why there is a "qcom,no-external-phy" property. You could, in theory, wire the internal phy of one SOC directly to the internal phy of another SOC, and use that as in interconnect between SOCs. I don't know of any such use-cases however.
The fact the MDIO bus is built-into the MAC is really not a problem here, there are tons of drivers that deal with that just fine, yet, the DT binding needs to reflect that properly by having a sub-node of the Ethernet MAC which is a MDIO bus controller node. If external or internal PHYs are accessible through that MDIO bus, they also need to appear as child-nodes of that MDIO bus controller node.
BTW, wiring two PHYs internally is a waste of HW resource at best, if not just asking for trouble, you can do an Ethernet MAC to MAC connection, tons of HW do that too.
[snip]
Quoted 18 lines
Quoted 7 lines
Documentation/devicetree/bindings/net/qcom-emac.txt line 32
Quoted 4 lines
+- qcom,no-external-phy : Indicates there is no external PHY
connected toDocumentation/devicetree/bindings/net/qcom-emac.txt new file +2
-0+ EMAC. Include this only if the EMAC is directly + connected to the peer end without EPHY.How is the internal PHY accessed, is it responding on the MDIO bus at a particular address?
There is a set of memory-mapped registers. It's not connected via MDIO at all. It's mapped via the "sgmii" addresses in the device tree (see function
emac_sgmii_config).Quoted 5 lines
If so, standard MDIO scanning/probing works, and you
can have your PHY driver flag this device has internal. Worst case, you can do what BCMGENET does, and have a special "phy-mode" value set to "internal" when this knowledge needs to exist prior to MDIO bus scanning (e.g: to power on the PHY).
Quoted 3 lines
So the internal phy is not a real phy. It's not capable of driving an RJ45 port (there's no analog part). It's an SGMII-like device that is hard-wired to the EMAC itself.
OK, that explains things a bit, thanks, this is quite a bit of important detail actually.
Quoted 11 lines
In theory, the internal PHY is optional. You could design an SOC that has just the EMAC connected via normal MDIO to an external phy. I really wish our hardware designers has done that. But unfortunately, there are no SOCs like that, and so we have to treat the internal phy as an extension of the EMAC.
My preference would be to get rid of the "qcom,no-external-phy" property and have an external phy be required, at least until Qualcomm creates an SOC without the internal phy (which may never happen, for all I know).
Can we just say that, an absence of PHY specified in the Device Tree (no phy-handle property and PHY not a child node of the MDIO bus), means that there is no external PHY?
[snip]
Quoted 37 lines
Quoted 2 lines
Do you need to maintain these flags when most, if not all of them already exist in
dev->flagsordev->features?So you're saying that, for example, in
emac_set_features()I should remove this:if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) set_bit(EMAC_STATUS_VLANSTRIP_EN, &adpt->status); else clear_bit(EMAC_STATUS_VLANSTRIP_EN, &adpt->status);and then in
emac_mac_mode_config(), I should do this instead:void
emac_mac_mode_config(struct emac_adapter *adpt){ struct net_device *netdev = adpt->netdev; if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) mac |= VLAN_STRIP; else mac &= ~VLAN_STRIP;If so, then what do I do in
emac_rx_mode_set()? Should I delete this entire block:/* Check for Promiscuous and All Multicast modes */ if (netdev->flags & IFF_PROMISC) { set_bit(EMAC_STATUS_PROMISC_EN, &adpt->status); } else if (netdev->flags & IFF_ALLMULTI) { set_bit(EMAC_STATUS_MULTIALL_EN, &adpt->status); clear_bit(EMAC_STATUS_PROMISC_EN, &adpt->status); } else { clear_bit(EMAC_STATUS_MULTIALL_EN, &adpt->status); clear_bit(EMAC_STATUS_PROMISC_EN, &adpt->status); }
Quoted 3 lines
It does look like Gilad is just mirroring the flags/features variable into
adpt->status. What I can't figure out is why. It seems completely redundant, but I have a nagging feeling that there is a good reason.
Yes, I think your set_features and set_rx_mode functions would be greatly simplified, if each of them did take care of programming the HW immediately based on function arguments/flags. Unless absolutely required (e.g: suspend/resume, outside of the scope of the function etc..) having bookeeping variables is always something that can be out of sync, so better avoid them as much as possible.
[snip]
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4
-0+ napi_enable(&adpt->rx_q.napi); + + /* enable mac irq */ + writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +3
-0+ writel(adpt->irq.mask, adpt->base + EMAC_INT_MASK); + + netif_start_queue(netdev);Starting the TX queue is typically the last ting you want to do, to avoid a transient state where the TX queue is enabled, and the link is not (which is okay if your driver is properly implemented and reflects carrier changes anyway).
Quoted 3 lines
So I should move the
netif_start_queue()to the end of this function? Sorry if that's a stupid question, but I know little about the MAC side of network drivers.
That's fine, yes moving netif_start_queue() at the far end of the function is a good change.
[snip]
Quoted 17 lines
Quoted 16 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 13 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +12
-0+ + return 0; +} + +/* Bring down the interface/HW */ +void emac_mac_down(struct emac_adapter *adpt, bool reset) +{ + struct net_device *netdev = adpt->netdev; + struct emac_phy *phy = &adpt->phy; + unsigned long flags; + + set_bit(EMAC_STATUS_DOWN, &adpt->status);Do you need to maintain that? Would not
netif_running()tell you what you want if you reflect the carrier state properly?
Quoted 4 lines
I think that
emac_work_thread_link_check()handles this. It's a timer thread that polls the link state and callsnetif_carrier_off()if the link is down. Is that sufficient?
Probably, then again, with PHYLIB you have the option of either switching the PHY to interrupt mode (thsus saving the polling_), or it polls the PHY for link statuses every HZ.
[snip]
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +8
-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); + + /* update produce idx */Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4
-0+ prod_idx = (tx_q->tpd.produce_idx << tx_q->produce_shift) & + tx_q->produce_mask; + emac_reg_update32(adpt->base + tx_q->produce_reg, + tx_q->produce_mask, prod_idx);Since you have a producer index, you should consider checking
skb->xmit_moreto know whether you can update the register now, or later, which could save some expensive operation and batch TX.
Quoted 2 lines
I'll have to figure out what means and get back to you. When would "later" be?
After the driver gets accepted mainline for instance would seem fine. Considering how this seems to work, something like this is usally all that is needed:
if (!skb->xmit_more || netif_xmit_stopped(txq)
/* write producer index to get HW to transmit */
[snip]
Quoted 7 lines
Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 2 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +2
-0+static int debug = -1; +module_param(debug, int, S_IRUGO | S_IWUSR | S_IWGRP);ethtool -s <iface> msglvl provides you with that already.
I'll remove it. There's no ethtool support in this driver anyway, but there's no code that uses this parameter.
Adding support for changing message levels is really trivial, and will probably help you while developing this driver.
[snip]
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +6
-0+} + +irqreturn_t emac_isr(int _irq, void *data) +{ + struct emac_irq *irq = data; + struct emac_adapter *adpt = container_of(irq, struct
emac_adapter, irq);Documentation/devicetree/bindings/net/qcom-emac.txt new file +4
-0+ struct emac_rx_queue *rx_q = &adpt->rx_q; + + int max_ints = 1; + u32 isr, status;Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5
-0+ + /* disable the interrupt */ + writel(0, adpt->base + EMAC_INT_MASK); + + do {With
max_ints= 1, this is essentially the same as no loop, so just inline it to reduce the indentation.
Quoted 3 lines
In another internal version of this driver,
max_intsis set to 5. Could this be some way of processing multiple packets in one interrupt? Isn't that something that NAPI already takes care of, anyway?
Yes, NAPI is going to mitigate the cost of taking an interrupt and scheduling your bottom-half/soft IRQ for actual packet processing, it is the recommended way to mitigate the number of interrupts in the receive path (and transmit for that matter).
Quoted 32 lines
Quoted 23 lines
Quoted 23 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +22
-0+ isr = readl_relaxed(adpt->base + EMAC_INT_STATUS); + status = isr & irq->mask; + + if (status == 0) + break; + + if (status & ISR_ERROR) { + netif_warn(adpt, intr, adpt->netdev, + "warning: error irq status 0x%lx\n", + status & ISR_ERROR); + /* reset MAC */ + set_bit(EMAC_STATUS_TASK_REINIT_REQ, &adpt->status); + emac_work_thread_reschedule(adpt); + } + + /* Schedule the napi for receive queue with interrupt + * status bit set + */ + if ((status & rx_q->intr)) { + if (napi_schedule_prep(&rx_q->napi)) { + irq->mask &= ~rx_q->intr; + __napi_schedule(&rx_q->napi);Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5
-0+ } + } + + if (status & TX_PKT_INT) + emac_mac_tx_process(adpt, &adpt->tx_q);You should consider using a NAPI instance for reclaiming TX buffers as well.
Quoted 1 line
I'll have to figure out what means and get back to you.
drivers/net/ethernet/broadcom/bcmsysport.c is an example driver that reclaims transmitted buffers in NAPI. What that means is, take the TX completion interrupt, schedule a NAPI instance to run, and this NAPI instance cleans up the entire TX queue (it is not bounded, like the RX NAPI instance). It is really just moving the freeing of SKBs into softIRQ context vs. hardIRQ.
[snip]
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +9
-0+/* Configure VLAN tag strip/insert feature */ +static int emac_set_features(struct net_device *netdev, + netdev_features_t features) +{ + struct emac_adapter *adpt = netdev_priv(netdev); + + netdev_features_t changed = features ^ netdev->features; + + if (!(changed & (NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_CTAG_RX)))
+ return 0;Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 6 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +6
-0+ + netdev->features = features; + if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) + set_bit(EMAC_STATUS_VLANSTRIP_EN, &adpt->status); + else + clear_bit(EMAC_STATUS_VLANSTRIP_EN, &adpt->status);What about TX vlan offload?
Quoted 1 line
I don't know what that is.
TX VLAN offload would be that you can specify the VLAN id somewhere in a packet's descriptor and have the HW automatically build an Ethernet frame with the correct VLAN id, and all the Ethernet frame payload appropriately placed at the correct offsets, with no cost for the CPU but indicating that information (and not having to do a memmove() to insert the 802.1Q tag).
[snip]
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +9
-0+/* Probe function */ +static int emac_probe(struct platform_device *pdev) +{ + struct net_device *netdev; + struct emac_adapter *adpt; + struct emac_phy *phy; + int ret = 0; + u32 hw_ver; + u32 extended_irq_mask = emac_irq_use_extended ? IMR_EXTENDED_MASK :Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5
-0+ IMR_NORMAL_MASK; + + netdev = alloc_etherdev(sizeof(struct emac_adapter)); + if (!netdev) + return -ENOMEM;There are references to multiple queues in the code, so why not
alloc_etherdev_mq()here with the correct number of queues?
Quoted 3 lines
That support was removed from the driver, and on our SOC, we hard-code the number of queues to 1 anyway. I'm planning on adding multiple queue support (much) later.
Sounds like a good thing to do later, yes.
Quoted 37 lines
Quoted 12 lines
Documentation/devicetree/bindings/net/qcom-emac.txt
Quoted 10 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +9
-0+ dev_set_drvdata(&pdev->dev, netdev); + SET_NETDEV_DEV(netdev, &pdev->dev); + + adpt = netdev_priv(netdev); + adpt->netdev = netdev; + phy = &adpt->phy; + adpt->msg_enable = netif_msg_init(debug, EMAC_MSG_DEFAULT); + + dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));Really, is not that supposed to run on ARM64 servers?
Well, this version of the driver isn't, which is why it supports DT and not ACPI. I'm planning on adding that support in a later patch. However, I'll add support for 64-bit masks in the next version of this patch.
Would this be okay:
retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); if (retval) { dev_err(&pdev->dev, "failed to set DMA mask err %d\n", retval); goto err_res; }I've seen code like this in other drivers:
ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); if (ret) { ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); if (ret) { dev_err(dev, "failed to set dma mask\n"); return ret; } }
Quoted 4 lines
and I've never understood why it's necessary to fall back to 32-bits if 64 bits fails. Isn't 64 bits a superset of 32 bits? The driver is saying that the hardware supports all of DDR. How could fail, and how could 32-bit succeed if 64-bits fails?
I believe there could be cases where the HW is capable of addressing more physical memory than the CPU itself (usually unlikely, but it could), there could be cases where the HW is behind an IOMMMU which only has a window into the DDR, and that could prevent a higher DMA_BIT_MASK from being successfully configured.
Signature · 1 line
Florian
A couple of clarifications on the SGMII internal PHY and the DMA capability of the EMAC inline.
Quoted 27 lines · Florian Fainelli
Quoted 26 lines · Timur Tabi
Quoted 13 lines · Florian Fainelli
Quoted 10 lines · Timur Tabi
From: Gilad Avidov <[email protected]>
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.Quoted 8 lines
[snip]
Documentation/devicetree/bindings/net/qcom-emac.txt line 32
Quoted 4 lines
+- qcom,no-external-phy : Indicates there is no external PHY
connected toDocumentation/devicetree/bindings/net/qcom-emac.txt new file +2
-0+ EMAC. Include this only if the EMAC is directly + connected to the peer end without EPHY.How is the internal PHY accessed, is it responding on the MDIO bus at a particular address?
There is a set of memory-mapped registers. It's not connected via MDIO at all. It's mapped via the "sgmii" addresses in the device tree (see function
emac_sgmii_config).
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
If so, standard MDIO scanning/probing works, and you
can have your PHY driver flag this device has internal. Worst case, you can do what BCMGENET does, and have a special "phy-mode" value set to "internal" when this knowledge needs to exist prior to MDIO bus scanning (e.g: to power on the PHY).So the internal phy is not a real phy. It's not capable of driving an RJ45 port (there's no analog part). It's an SGMII-like device that is hard-wired to the EMAC itself.
There *is* an analog part to the internal SGMII PHY. Please check the SGMII specification. The only non-standard part is that it's not on MDIO.
Quoted 20 lines
OK, that explains things a bit, thanks, this is quite a bit of important detail actually.
Quoted 10 lines
In theory, the internal PHY is optional. You could design an SOC that has just the EMAC connected via normal MDIO to an external phy. I really wish our hardware designers has done that. But unfortunately, there are no SOCs like that, and so we have to treat the internal phy as an extension of the EMAC.
My preference would be to get rid of the "qcom,no-external-phy" property and have an external phy be required, at least until Qualcomm creates an SOC without the internal phy (which may never happen, for all I know).
Can we just say that, an absence of PHY specified in the Device Tree (no phy-handle property and PHY not a child node of the MDIO bus), means that there is no external PHY?
[snip]
[snip]
Quoted 15 lines
Quoted 15 lines
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c line 1038
Quoted 9 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +9
-0+dev_set_drvdata (&pdev->dev, netdev); +SET_NETDEV_DEV (netdev, &pdev->dev); + + adpt =netdev_priv (netdev); + adpt->netdev = netdev; + phy = &adpt->phy; + adpt->msg_enable =netif_msg_init (debug,EMAC_MSG_DEFAULT ); + +dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 ));Really, is not that supposed to run on ARM64 servers?
Well, this version of the driver isn't, which is why it supports DT and not ACPI. I'm planning on adding that support in a later patch. However, I'll add support for 64-bit masks in the next version of this patch.
Quoted 7 lines
Quoted 7 lines
Would this be okay:
retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); if (retval) { dev_err(&pdev->dev, "failed to set DMA mask err %d\n", retval); goto err_res; }
How can you set the mask to 64 bits when the EMAC IP on FSM9900 and QDF2432 can only do 32 bit DMA? The mask in that API is a bit mask describing which bits of an address your device supports.
Quoted 20 lines
Quoted 11 lines
I've seen code like this in other drivers:
ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); if (ret) { ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); if (ret) { dev_err(dev, "failed to set dma mask\n"); return ret; } }Quoted 4 lines
and I've never understood why it's necessary to fall back to 32-bits if 64 bits fails. Isn't 64 bits a superset of 32 bits? The driver is saying that the hardware supports all of DDR. How could fail, and how could 32-bit succeed if 64-bits fails?
I believe there could be cases where the HW is capable of addressing more physical memory than the CPU itself (usually unlikely, but it could), there could be cases where the HW is behind an IOMMMU which only has a window into the DDR, and that could prevent a higher
DMA_BIT_MASKfrom being successfully configured.
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
Quoted 7 lines · Vikram Sethi
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); if (retval) { dev_err(&pdev->dev, "failed to set DMA mask err %d\n", retval); goto err_res; }How can you set the mask to 64 bits when the EMAC IP on FSM9900 and QDF2432 can only do 32 bit DMA? The mask in that API is a bit mask describing which bits of an address your device supports.
Vikram, Shanker, and I discussed this offline, and came to a consensus.
The FSM9900 is a 32-bit platform, so the kernel will never create a DMA address above 4GB. Even if the driver sets the mask to 64 bits, it will technically work. However, the mask should be set to 32 because all address buses are 32 bits.
The QDF2432 is different. Although it's an ARM64 platform, we have the unfortunate situation that only 32 bits of that address is wired to the rest of the chip. So even though the Emac can handle 64-bit bus addresses, if it actually attempts to DMA above 4GB, the address will get truncated and corrupt memory. The mask needs to be set to 32.
There may or may not be other ARM64 chips from us that won't have this problem in the future, so these hypothetical chips would have a mask of 64.
So I think the solution is to create a device tree (and ACPI) property that holds the mask.
dma-mask = <0 0xffffffff>;
or
dma-mask = <0xffffffff 0xffffffff>;
The driver will then do this:
u64 dma_mask; device_property_read_u64(&pdev->dev, "dma-mask", &dma_mask); dma_coerce_mask_and_coherent(&pdev->dev, dma_mask);
What I'm not sure yet is whether I should call dma_coerce_mask_and_coherent() or dma_set_coherent_mask().
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.
Quoted 32 lines · Timur Tabi
Quoted 9 lines · Vikram Sethi
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); if (retval) { dev_err(&pdev->dev, "failed to set DMA mask err %d\n", retval); goto err_res; }Quoted 4 lines
How can you set the mask to 64 bits when the EMAC IP on FSM9900 and QDF2432 can only do 32 bit DMA?
The mask in that API is a bit mask describing which bits of an address your device supports.Vikram, Shanker, and I discussed this offline, and came to a consensus.
The FSM9900 is a 32-bit platform, so the kernel will never create a DMA address above 4GB. Even if the driver sets the mask to 64 bits, it will technically work. However, the mask should be set to 32 because all address buses are 32 bits.
The QDF2432 is different. Although it's an ARM64 platform, we have the unfortunate situation that only 32 bits of that address is wired to the rest of the chip. So even though the Emac can handle 64-bit bus addresses, if it actually attempts to DMA above 4GB, the address will get truncated and corrupt memory. The mask needs to be set to 32.
There may or may not be other ARM64 chips from us that won't have this problem in the future, so these hypothetical chips would have a mask of 64.
Quoted 8 lines
So I think the solution is to create a device tree (and ACPI) property that holds the mask.
dma-mask = <0 0xffffffff>;or
dma-mask = <0xffffffff 0xffffffff>;
No. See dma-ranges.
Rob
Quoted 14 lines
The driver will then do this:
u64 dma_mask; device_property_read_u64(&pdev->dev, "dma-mask", &dma_mask); dma_coerce_mask_and_coherent(&pdev->dev, dma_mask);What I'm not sure yet is whether I should call
dma_coerce_mask_and_coherent()ordma_set_coherent_mask().--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation collaborative project.
Quoted 7 lines · Rob Herring
Quoted 6 lines
Quoted 6 lines
dma-mask = <0 0xffffffff>;or
dma-mask = <0xffffffff 0xffffffff>;No. See dma-ranges.
How exactly should I use dma-ranges? I can't find any other drivers that queries that property and uses the result to call dma_set_mask. I thought the dma-ranges property is intended to specify address translation. I don't need to translate any address, I just need to know a single number.
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.
Quoted 9 lines · Timur Tabi
Quoted 8 lines · Rob Herring
Quoted 7 lines
Quoted 7 lines
dma-mask = <0 0xffffffff>;or
dma-mask = <0xffffffff 0xffffffff>;
Quoted 7 lines
Quoted 1 line
No. See dma-ranges.
How exactly should I use dma-ranges? I can't find any other drivers that queries that property and uses the result to call
dma_set_mask. I thought the dma-ranges property is intended to specify address translation. I don't need to translate any address, I just need to know a single number.
You may only care about the size, but the binding has to handle the more complex case. Here's an example
<0x0 0x2 0x0 0x1 0x0>
dma address 0 (cell 0) maps to cpu (parent) address 0x2_00000000 (cell 1-2) and the range/size is 4G (cell 3-4).
If you have the same base address, then use the same address. The core will calculate the mask based on the size. IIRC, we also handle ~0 as a special case to support 4G for #size-cell=1.
Rob
Quoted 11 lines · Rob Herring
You may only care about the size, but the binding has to handle the more complex case. Here's an example
<
0x00x20x00x10x0>dma address 0 (cell 0) maps to cpu (parent) address 0x2_00000000 (cell 1-2) and the range/size is 4G (cell 3-4).
If you have the same base address, then use the same address. The core will calculate the mask based on the size. IIRC, we also handle ~0 as a special case to support 4G for #size-cell=1.
So the first thing I noticed is that Gilad had this:
reg = <0xfeb20000 0x10000>, <0xfeb36000 0x1000>, <0xfeb3c000 0x4000>, <0xfeb38000 0x400>; #address-cells = <0>;
Shouldn't address-cells have been 1 instead?
Ok, let me see if I get this right:
32-bit:
soc {
#address-cells = <1>;
#size-cells = <1>;
emac0: qcom,emac@feb20000 {
compatible = "qcom,fsm9900-emac";
#address-cells = <1>;
#size-cells = <1>;
reg-names = "base", "csr", "ptp", "sgmii";
reg = <0xfeb20000 0x10000>,
<0xfeb36000 0x1000>,
<0xfeb3c000 0x4000>,
<0xfeb38000 0x400>;
dma-ranges = <0 0 0xffffffff>;
interrupt-parent = <&emac0>;64-bit
soc {
#address-cells = <2>;
#size-cells = <2>;
emac0: qcom,emac@feb20000 {
compatible = "qcom,fsm9900-emac";
#address-cells = <2>;
#size-cells = <2>;
reg-names = "base", "csr", "ptp", "sgmii";
reg = <0 0xfeb20000 0 0x10000>,
<0 0xfeb36000 0 0x1000>,
<0 0xfeb3c000 0 0x4000>,
<0 0xfeb38000 0 0x400>;
dma-ranges = <0 0 0 0 0xffffffff 0xffffffff>;This seems inelegant, though.
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.
On Thu 14 Apr 16:34 PDT 2016, Timur Tabi wrote:
[..]
Quoted 9 lines
So I think the solution is to create a device tree (and ACPI) property that holds the mask.
dma-mask = <0 0xffffffff>;or
dma-mask = <0xffffffff 0xffffffff>;
Quoted 9 lines
The driver will then do this:
u64 dma_mask; device_property_read_u64(&pdev->dev, "dma-mask", &dma_mask); dma_coerce_mask_and_coherent(&pdev->dev, dma_mask);What I'm not sure yet is whether I should call
dma_coerce_mask_and_coherent()ordma_set_coherent_mask().
For platform devices being populated via from DT you will pass:of_platform_bus_create()
of_platform_device_create_pdata()
of_dma_configure()
Which calls of_dma_get_range() to acquire this information from the dma-ranges property and set up the dma ops and properties.
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
Quoted 7 lines · Bjorn Andersson
For platform devices being populated via from DT you will pass:
of_platform_bus_create()
of_platform_device_create_pdata()
of_dma_configure()Which calls
of_dma_get_range()to acquire this information from the dma-ranges property and set up the dma ops and properties.
This seems excessive. I have to create a platform bus just to configure the DMA mask? Most drivers just call dma_set_mask and give it a number, and that's not device-tree specific. I also need to come up with a way to get this to work on ACPI.
I just seems like a lot of work only because I need to determine at runtime what my DMA mask is. I also don't see any drivers that call of_dma_configure().
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.
Quoted 9 lines · Timur Tabi
Quoted 7 lines · Bjorn Andersson
For platform devices being populated via from DT you will pass:
of_platform_bus_create()
of_platform_device_create_pdata()
of_dma_configure()Which calls
of_dma_get_range()to acquire this information from the dma-ranges property and set up the dma ops and properties.
Quoted 9 lines
This seems excessive. I have to create a platform bus just to configure the DMA mask? Most drivers just call
dma_set_maskand give it a number, and that's not device-tree specific. I also need to come up with a way to get this to work on ACPI.I just seems like a lot of work only because I need to determine at runtime what my DMA mask is. I also don't see any drivers that call
of_dma_configure().
Your driver is a platform driver and it's being probed from DT. As such all this is already taken care of for you, by the core.
The listing is for your reference to know why the dma-ranges property would affect your device.
Regards,
Bjorn
Quoted 5 lines · Bjorn Andersson
Your driver is a platform driver and it's being probed from DT. As such all this is already taken care of for you, by the core.
The listing is for your reference to know why the dma-ranges property would affect your device.
Ah, sorry. I misunderstood what you meant by "you will pass".
Coincidentally, it looks like Lorenzo Pieralisi has posted patches the ACPI equivalent just yesterday: https://lkml.org/lkml/2016/4/14/694
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.
Quoted 4 lines · Florian Fainelli
Well, PHYLIB does prefer using MDIO accesses to "speak" to PHYs, built-in or external, but there is always the option of investing into some custom development with the subsystem to make it play nicely with your HW.
So I've done some more research, and I believe that the internal phy is not a candidate for phylib, but the external phy (which is a real phy) might be. There's no MDIO bus to the internal phy.
Does this mean that I will need to enable a PHY driver, and that driver will control the external phy? If so, then does that mean that I would delete all to code in my driver that calls emac_phy_read() and emac_phy_write()? For example, I wouldn't need emac_phy_link_check() any more?
Quoted 7 lines
Quoted 6 lines
The MDIO bus on these chips is not accessible as a separate entity. It is melded (for lack of a better word) into the EMAC itself. That's why there is a "qcom,no-external-phy" property. You could, in theory, wire the internal phy of one SOC directly to the internal phy of another SOC, and use that as in interconnect between SOCs. I don't know of any such use-cases however.
Quoted 6 lines
The fact the MDIO bus is built-into the MAC is really not a problem here, there are tons of drivers that deal with that just fine, yet, the DT binding needs to reflect that properly by having a sub-node of the Ethernet MAC which is a MDIO bus controller node. If external or internal PHYs are accessible through that MDIO bus, they also need to appear as child-nodes of that MDIO bus controller node.
Does the compatible property of the phy node (for the external phy) need to list the actual external phy? That is, should it look like this:
phy0: ethernet-phy@0 {
compatible = "qcom,fsm9900-emac-phy";
reg = <0>;
}or this:
phy0: ethernet-phy@0 {
compatible = "athr,whatever-phy";
reg = <0>;
}Quoted 3 lines
Can we just say that, an absence of PHY specified in the Device Tree (no phy-handle property and PHY not a child node of the MDIO bus), means that there is no external PHY?
Yes, that works.
Quoted 44 lines
[snip]
Quoted 37 lines
Quoted 2 lines
Do you need to maintain these flags when most, if not all of them already exist in
dev->flagsordev->features?So you're saying that, for example, in
emac_set_features()I should remove this:if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) set_bit(EMAC_STATUS_VLANSTRIP_EN, &adpt->status); else clear_bit(EMAC_STATUS_VLANSTRIP_EN, &adpt->status);and then in
emac_mac_mode_config(), I should do this instead:void
emac_mac_mode_config(struct emac_adapter *adpt){ struct net_device *netdev = adpt->netdev; if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) mac |= VLAN_STRIP; else mac &= ~VLAN_STRIP;If so, then what do I do in
emac_rx_mode_set()? Should I delete this entire block:/* Check for Promiscuous and All Multicast modes */ if (netdev->flags & IFF_PROMISC) { set_bit(EMAC_STATUS_PROMISC_EN, &adpt->status); } else if (netdev->flags & IFF_ALLMULTI) { set_bit(EMAC_STATUS_MULTIALL_EN, &adpt->status); clear_bit(EMAC_STATUS_PROMISC_EN, &adpt->status); } else { clear_bit(EMAC_STATUS_MULTIALL_EN, &adpt->status); clear_bit(EMAC_STATUS_PROMISC_EN, &adpt->status); }Quoted 3 lines
It does look like Gilad is just mirroring the flags/features variable into
adpt->status. What I can't figure out is why. It seems completely redundant, but I have a nagging feeling that there is a good reason.
Quoted 6 lines
Yes, I think your
set_featuresandset_rx_modefunctions would be greatly simplified, if each of them did take care of programming the HW immediately based on function arguments/flags. Unless absolutely required (e.g: suspend/resume, outside of the scope of the function etc..) having bookeeping variables is always something that can be out of sync, so better avoid them as much as possible.
Ok, I'll try to clean this up.
Quoted 6 lines
Quoted 3 lines
So I should move the
netif_start_queue()to the end of this function? Sorry if that's a stupid question, but I know little about the MAC side of network drivers.That's fine, yes moving
netif_start_queue()at the far end of the function is a good change.
Ok.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1097
Quoted 8 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +8
-0+/* Bring down the interface/HW */ +void emac_mac_down (struct emac_adapter *adpt,bool reset) +{ +struct net_device *netdev = adpt->netdev; +struct emac_phy *phy = &adpt->phy; +unsigned long flags; + +set_bit (EMAC_STATUS_DOWN , &adpt->status);Do you need to maintain that? Would not
netif_running()tell you what you want if you reflect the carrier state properly?
Quoted 8 lines
Quoted 4 lines
I think that
emac_work_thread_link_check()handles this. It's a timer thread that polls the link state and callsnetif_carrier_off()if the link is down. Is that sufficient?Probably, then again, with PHYLIB you have the option of either switching the PHY to interrupt mode (thsus saving the
polling_), or it polls the PHY for link statuses every HZ.
I'll have to check and see if interrupt mode is even an option. So phylib can do the polling for me?
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Since you have a producer index, you should consider checking
skb->xmit_moreto know whether you can update the register now, or later, which could save some expensive operation and batch TX.I'll have to figure out what means and get back to you. When would "later" be?
Quoted 6 lines
After the driver gets accepted mainline for instance would seem fine. Considering how this seems to work, something like this is usally all that is needed:
if (!skb->xmit_more ||
netif_xmit_stopped(txq)/* write producer index to get HW to transmit */
Oh, I thought you meant later in the code somewhere. At a later date with another patch sounds great to me, though.
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +4
-0+irqreturn_t emac_isr (int _irq,void *data) +{ +struct emac_irq *irq = data; + struct emac_adapter *adpt = container_of(irq, struct
emac_adapter, irq);drivers/net/ethernet/qualcomm/emac/emac.c line 234
Quoted 9 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +9
-0+struct emac_rx_queue *rx_q = &adpt->rx_q; + +int max_ints =1 ; +u32 isr, status; + +/* disable the interrupt */ +writel (0 , adpt->base +EMAC_INT_MASK ); + + do {With
max_ints= 1, this is essentially the same as no loop, so just inline it to reduce the indentation.
Quoted 8 lines
Quoted 3 lines
In another internal version of this driver,
max_intsis set to 5. Could this be some way of processing multiple packets in one interrupt? Isn't that something that NAPI already takes care of, anyway?Yes, NAPI is going to mitigate the cost of taking an interrupt and scheduling your bottom-half/soft IRQ for actual packet processing, it is the recommended way to mitigate the number of interrupts in the receive path (and transmit for that matter).
I'll clean up the code and remove max_ints.
Quoted 33 lines
Quoted 33 lines
Quoted 32 lines
Quoted 19 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +17
-0+ isr =readl_relaxed (adpt->base +EMAC_INT_STATUS ); + status = isr & irq->mask; + +if (status ==0 ) +break ; + +if (status &ISR_ERROR ) { +netif_warn (adpt, intr, adpt->netdev, +"warning: error irq status 0x%lx\n" , + status &ISR_ERROR ); +/* reset MAC */ +set_bit (EMAC_STATUS_TASK_REINIT_REQ , &adpt->status); +emac_work_thread_reschedule (adpt); + } + +/* Schedule the napi for receive queue with interrupt +* status bit set drivers/net/ethernet/qualcomm/emac/emac.c line 261
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +10
-0+*/ +if ((status & rx_q->intr)) { +if (napi_schedule_prep (&rx_q->napi)) { + irq->mask &= ~rx_q->intr; +__napi_schedule (&rx_q->napi); + } + } + +if (status &TX_PKT_INT ) +emac_mac_tx_process (adpt, &adpt->tx_q);You should consider using a NAPI instance for reclaiming TX buffers as well.
Quoted 8 lines
Quoted 1 line
I'll have to figure out what means and get back to you.
drivers/net/ethernet/broadcom/bcmsysport.cis an example driver that reclaims transmitted buffers in NAPI. What that means is, take the TX completion interrupt, schedule a NAPI instance to run, and this NAPI instance cleans up the entire TX queue (it is not bounded, like the RX NAPI instance). It is really just moving the freeing of SKBs into softIRQ context vs. hardIRQ.
Thanks. I don't think I'll get to any of the NAPI fixes in v5 of this driver. I want to make sure I get the phylib conversion correct first.
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +9
-0+/* Configure VLAN tag strip/insert feature */ +static int emac_set_features (struct net_device *netdev, +netdev_features_t features) +{ +struct emac_adapter *adpt =netdev_priv (netdev); + +netdev_features_t changed = features ^ netdev->features; + + if (!(changed & (NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_CTAG_RX)))drivers/net/ethernet/qualcomm/emac/emac.c line 296
Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +7
-0+return 0 ; + + netdev->features = features; +if (netdev->features &NETIF_F_HW_VLAN_CTAG_RX ) +set_bit (EMAC_STATUS_VLANSTRIP_EN , &adpt->status); +else +clear_bit (EMAC_STATUS_VLANSTRIP_EN , &adpt->status);What about TX vlan offload?
Quoted 8 lines
Quoted 1 line
I don't know what that is.
TX VLAN offload would be that you can specify the VLAN id somewhere in a packet's descriptor and have the HW automatically build an Ethernet frame with the correct VLAN id, and all the Ethernet frame payload appropriately placed at the correct offsets, with no cost for the CPU but indicating that information (and not having to do a
memmove()to insert the 802.1Q tag).
I have no idea if our hardware supports that. I'll make a note of TX VLAN offload and submit a separate patch if I can make it work.
Quoted 10 lines
Quoted 4 lines
and I've never understood why it's necessary to fall back to 32-bits if 64 bits fails. Isn't 64 bits a superset of 32 bits? The driver is saying that the hardware supports all of DDR. How could fail, and how could 32-bit succeed if 64-bits fails?
I believe there could be cases where the HW is capable of addressing more physical memory than the CPU itself (usually unlikely, but it could),there could be cases where the HW is behind an IOMMMU which only has a window into the DDR, and that could prevent a higher
DMA_BIT_MASKfrom being successfully configured.
So, so I'm going to add dma-ranges support (I posted another patch asked for feedback, but I haven't gotten it yet).
For ACPI, we're going to depend on IORT to set the DMA mask for us.
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.
Quoted 11 lines · Timur Tabi
Quoted 1 line
So I've done some more research, and I believe that the internal phy is not a candidate for phylib, but the external phy (which is a real phy) might be. There's no MDIO bus to the internal phy.
Does this mean that I will need to enable a PHY driver, and that driver will control the external phy? If so, then does that mean that I would delete all to code in my driver that calls
emac_phy_read()andemac_phy_write()? For example, I wouldn't needemac_phy_link_check()any more?
So I think I have it partially working, but I'm not sure if I'm doing things correctly, and I'd like some help.
The external phy is an Atheros 8031, so I load the at803x driver. I added this code to my driver:
mii_bus = devm_mdiobus_alloc(&pdev->dev); mii_bus->phy_mask = ~(1 << adpt->hw.phy_addr); mii_bus->read = emac_mdio_read; mii_bus->write = emac_mdio_write; mii_bus->reset = emac_mdio_reset; mii_bus->parent = &pdev->dev; mii_bus->priv = hw; mdiobus_register(mii_bus);
When I call mdiobus_register, I can see that the at803x_probe() probe function is called, so a connection is made.
The problem is that after that point, it appears that the at803x driver is never called again. I tried bring the interface up and down, and connecting and disconnecting an Ethernet cable, but that didn't trigger anything. I would expect the PHY driver to do more than just probe.
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.
Quoted 29 lines · Timur Tabi
Quoted 11 lines · Timur Tabi
Quoted 1 line
So I've done some more research, and I believe that the internal phy is not a candidate for phylib, but the external phy (which is a real phy) might be. There's no MDIO bus to the internal phy.
Does this mean that I will need to enable a PHY driver, and that driver will control the external phy? If so, then does that mean that I would delete all to code in my driver that calls
emac_phy_read()andemac_phy_write()? For example, I wouldn't needemac_phy_link_check()any more?So I think I have it partially working, but I'm not sure if I'm doing things correctly, and I'd like some help.
The external phy is an Atheros 8031, so I load the at803x driver. I added this code to my driver:
mii_bus = devm_mdiobus_alloc(&pdev->dev); mii_bus->phy_mask = ~(1 << adpt->hw.phy_addr); mii_bus->read = emac_mdio_read; mii_bus->write = emac_mdio_write; mii_bus->reset = emac_mdio_reset; mii_bus->parent = &pdev->dev; mii_bus->priv = hw; mdiobus_register(mii_bus);
Quoted 7 lines
When I call
mdiobus_register, I can see that theat803x_probe()probe function is called, so a connection is made.The problem is that after that point, it appears that the at803x driver is never called again. I tried bring the interface up and down, and connecting and disconnecting an Ethernet cable, but that didn't trigger anything. I would expect the PHY driver to do more than just probe.
Are you utilizing the PHYLIB APIs properly? You need at least a phy_start() to start the PHY state machine, and an adjust_link callback to be provided to phy_connect() (or of_phy_connect()) to manage link state changes. And that's the very basic minimum here, there could be additional APIs that you may end up using.
There are tons of example in tree of drivers doing this, bcmgenet, bcmsysport, tg3 etc.
Signature · 1 line
Florian
Quoted 8 lines · Florian Fainelli
Are you utilizing the PHYLIB APIs properly? You need at least a
phy_start()to start the PHY state machine, and anadjust_linkcallback to be provided tophy_connect()(orof_phy_connect()) to manage link state changes. And that's the very basic minimum here, there could be additional APIs that you may end up using.There are tons of example in tree of drivers doing this, bcmgenet, bcmsysport, tg3 etc.
Thank you. I think I finally got phylib working, more or less.
Unfortunately, it seems I have some kind of race condition. The driver has a lot that's wrong with it, and I'm trying to fix it all. One crazy the driver does is it create a workqueue to handle a lot of the tasks that would normally be handled in the interrupt handler itself.
With phylib support, I know my driver can call phy_mac_interrupt() when it gets a link status change interrupt. I then have an .adjust_link callback which starts or stops the mac accordingly.
My problem is that I'm not really sure what adjust_link is supposed to be doing. In addition, it seems that I need to keep the workqueue running, otherwise the interface will not function. I bring the interface up, and the driver reports success, but pings do not work.
I'm getting really frustrated. The sample code isn't really helping a whole lot, because I lack a fundamental understanding of what needs to be done. None of the documentation I've read is helpful, and I don't know how to debug it.
Can you give me some advice on how to debug this?
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.
Quoted 10 lines · Timur Tabi
Quoted 8 lines · Florian Fainelli
Are you utilizing the PHYLIB APIs properly? You need at least a
phy_start()to start the PHY state machine, and anadjust_linkcallback to be provided tophy_connect()(orof_phy_connect()) to manage link state changes. And that's the very basic minimum here, there could be additional APIs that you may end up using.There are tons of example in tree of drivers doing this, bcmgenet, bcmsysport, tg3 etc.
Quoted 6 lines
Thank you. I think I finally got phylib working, more or less.
Unfortunately, it seems I have some kind of race condition. The driver has a lot that's wrong with it, and I'm trying to fix it all. One crazy the driver does is it create a workqueue to handle a lot of the tasks that would normally be handled in the interrupt handler itself.
That sounds like a typicall top half/bottom half split, fair enough.
Quoted 4 lines
With phylib support, I know my driver can call
phy_mac_interrupt()when it gets a link status change interrupt. I then have an .adjust_link callback which starts or stops the mac accordingly.
The Ethernet MAC should be started in ndo_open() and stopped in ndo_close(), in between, there are link state changes, but you are not supposed to stop or start your Ethernet MAC and its DMA for instance during link change, if that is a HW requirement, your HW is pretty funky.
Quoted 3 lines
My problem is that I'm not really sure what
adjust_linkis supposed to be doing.
Well, it's pretty simple, it is about re-configuring your Ethernet MAC based on what the PHY link state mandates: duplex, pause, speed changes, EEE etc is what this callback is supposed to take care of, at the Ethernet MAC level.
Quoted 8 lines
In addition, it seems that I need to keep the workqueue
running, otherwise the interface will not function. I bring the interface up, and the driver reports success, but pings do not work.I'm getting really frustrated. The sample code isn't really helping a whole lot, because I lack a fundamental understanding of what needs to be done. None of the documentation I've read is helpful, and I don't know how to debug it.
Seriously, no documentation is helpful? The PHY library seems pretty well documented to me, but I suppose I have a bias, oh, and patches are welcome of course.
Quoted 2 lines
Can you give me some advice on how to debug this?
Take a look at drivers/net/ethernet/broadcom/genet/bcmgenet.c and see how it deals with managing link state changes for instance. The code is pretty straight forward: link interrupt (and other causes) trigger a workqueue schedule, which then processes link state changes and calls phy_mac_interrupt(), which in turn makes the PHY library adjust the interface carrier state.
Signature · 1 line
Florian
Quoted 4 lines · Florian Fainelli
The Ethernet MAC should be started in
ndo_open()and stopped inndo_close(), in between, there are link state changes, but you are not supposed to stop or start your Ethernet MAC and its DMA for instance during link change, if that is a HW requirement, your HW is pretty funky.
I think the problem is that the current driver seems to be too eager to start/stop the MAC.
Please take a look at emac_work_thread_link_check() at https://lkml.org/lkml/2016/4/13/670. Every time the PHY link goes up, it does this:
if (phy->link_up) {
if (netif_carrier_ok(netdev))
goto link_task_done;
pm_runtime_get_sync(netdev->dev.parent);
netif_info(adpt, timer, adpt->netdev, "NIC Link is Up %s\n",
speed);
emac_mac_start(adpt);
netif_carrier_on(netdev);
netif_wake_queue(netdev);The call to emac_mac_start seems wrong to me here.
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.
Quoted 6 lines · Timur Tabi
I think the problem is that the current driver seems to be too eager to start/stop the MAC.
Please take a look at
emac_work_thread_link_check()at
https://lkml.org/lkml/2016/4/13/670. Every time the PHY link goes up, it does this:
Never mind, I figured out the problem. I still have a lot of work ahead of me, but at least I'm not stuck any more.
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.
Quoted 9 lines
Does the compatible property of the phy node (for the external phy) need to list the actual external phy? That is, should it look like this:
phy0: ethernet-phy@0 { compatible = "qcom,fsm9900-emac-phy"; reg = <0>; }
Quoted 7 lines
or this:
phy0: ethernet-phy@0 { compatible = "athr,whatever-phy"; reg = <0>; }
Documentation/devicetree/bindings/net/phy.txt says:
Optional Properties:
- compatible: Compatible list, may contain "ethernet-phy-ieee802.3-c22" or "ethernet-phy-ieee802.3-c45" for PHYs that implement IEEE802.3 clause 22 or IEEE802.3 clause 45 specifications. If neither of these are specified, the default is to assume clause 22.
If the phy's identifier is known then the list may contain an entry of the form: "ethernet-phy-idAAAA.BBBB" where
AAAA - The value of the 16 bit Phy Identifier 1 register as
4 hex digits. This is the chip vendor OUI bits 3:18
BBBB - The value of the 16 bit Phy Identifier 2 register as
4 hex digits. This is the chip vendor OUI bits 19:24, followed by 10 bits of a vendor specific ID.
The compatible list should not contain other values than those listed here.
Andrew
Quoted 9 lines · Florian Fainelli
Quoted 6 lines
+/* Transmit the packet */
drivers/net/ethernet/qualcomm/emac/emac.c line 219
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac.c new file +5
-0+static int emac_start_xmit (struct sk_buff *skb,struct net_device *netdev) +{ +struct emac_adapter *adpt =netdev_priv (netdev); + +return emac_mac_tx_buf_send (adpt, &adpt->tx_q, skb);I would inline emac_mac_tx_buf_send()'s body here to make it much easier to read and audit...
I'm close to submitting a v5 of this patchset. The change to phylib has resulted in significant other changes. I'm sure it's still not quite right, so I ask your patience in reviewing it.
However, I'm not sure inlining emac_mac_tx_buf_send() into emac_start_xmit() is good idea. That would result in moving several functions from emac-mac.c into emac.c. I'm concerned about maintaining the functional split between the two files.
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.
kbuild test robot
build botreproduce: 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.6-rc3 next-20160413]
[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/Timur-Tabi/net-emac-emac-gigabit-ethernet-controller-driver/20160414-020345 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:395: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:1076:2: note: in expansion of macro 'writel'
writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);
^vim +/writel +1076 drivers/net/ethernet/qualcomm/emac/emac-mac.c
1060 return ret;
1061
1062 ret = request_irq(irq->irq, emac_isr, 0, EMAC_MAC_IRQ_RES, irq);
1063 if (ret) {
1064 netdev_err(adpt->netdev,
1065 "error:%d on request_irq(%d:%s flags:0)\n", ret,
1066 irq->irq, EMAC_MAC_IRQ_RES);
1067 emac_sgmii_down(adpt);
1068 return ret;
1069 }
1070
1071 emac_mac_rx_descs_refill(adpt, &adpt->rx_q);
1072
1073 napi_enable(&adpt->rx_q.napi);
1074
1075 /* enable mac irq */
> 1076 writel(~DIS_INT, adpt->base + EMAC_INT_STATUS);
1077 writel(adpt->irq.mask, adpt->base + EMAC_INT_MASK);
1078
1079 netif_start_queue(netdev);
1080 clear_bit(EMAC_STATUS_DOWN, &adpt->status);
1081
1082 /* check link status */
1083 set_bit(EMAC_STATUS_TASK_LSC_REQ, &adpt->status);
1084 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
Rob Herring
maintainerQuoted 77 lines · Timur Tabi
From: Gilad Avidov <[email protected]>
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]>.Signed-off-by Gilad Avidov <[email protected]>Signed-off-by Timur Tabi <[email protected]>---
v4:
- add missing ipv6 header file
- correct compatible string
- fix spacing inemac_reg_writearrays
- drop unnecessary cell-index property
- remove unsupported DT properties from docs
- remove GPIO initialization and update docsv3:
- remove most of the memory barriers by using the nonxxx_relaxed()api.
- remove RSS and WOL support.
- correct comments from physical address to dma address.
- rearrange structs to make them packed.
- replace polling loops withreadl_poll_timeout().
- remove unnecessary wrapper functions from phy layer.
- add blank line before return statements.
- set to null clocks afterclk_put().
- usemodule_platform_driver()anddma_set_mask_and_coherent()
- replace long hex bitmasks withBIT()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 ofxxxxl_relaxed()io followed bymb()with a readl()/writel().--- .../devicetree/bindings/net/qcom-emac.txt | 65 + 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 | 1782 ++++++++++++++++++++ drivers/net/ethernet/qualcomm/emac/emac-mac.h | 286 ++++ drivers/net/ethernet/qualcomm/emac/emac-phy.c | 484 ++++++ drivers/net/ethernet/qualcomm/emac/emac-phy.h | 68 + drivers/net/ethernet/qualcomm/emac/emac-sgmii.c | 683 ++++++++ drivers/net/ethernet/qualcomm/emac/emac-sgmii.h | 30 + drivers/net/ethernet/qualcomm/emac/emac.c | 1206 +++++++++++++ drivers/net/ethernet/qualcomm/emac/emac.h | 382 +++++ 12 files changed, 5006 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.hDocumentation/devicetree/bindings/net/qcom-emac.txt new file +0
-0
Documentation/devicetree/bindings/net/qcom-emac.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4
-0@@ -0,0 +1,65 @@ +Qualcomm EMAC Gigabit Ethernet Controller + +Required properties: +- compatible : Should be "qcom,emac".
Come on... Can you guess what I'm going to say here.
Quoted 7 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +7
-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.
Documentation/devicetree/bindings/net/qcom-emac.txt line 21
Quoted 10 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +10
-0+ 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. +- phy-addr : Specifies phy address on MDIO bus. + Required if the optional property "qcom,no-external-phy" + is not specified.
As I mentioned in the last version, you should still describe this with a standard MDIO bus binding even if you can't use the generic code.
Documentation/devicetree/bindings/net/qcom-emac.txt line 34
Quoted 13 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +13
-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. +- 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. +Example: + emac0: qcom,emac@feb20000 {
ethernet@
Documentation/devicetree/bindings/net/qcom-emac.txt line 35
Quoted 1 line
Documentation/devicetree/bindings/net/qcom-emac.txt new file +1
-0+ compatible = "qcom,fsm9900-emac";
Ah, I see you fixed it here...
Quoted 30 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +30
-0+ 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; + phy-addr = <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"; + }; + }; + };
Quoted 7 lines · Rob Herring
Documentation/devicetree/bindings/net/qcom-emac.txt line 4
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4
-0@@ -0,0 +1,65 @@ +Qualcomm EMAC Gigabit Ethernet Controller + +Required properties: +- compatible : Should be "qcom,emac".Come on... Can you guess what I'm going to say here.
Ooops, I missed that one.
Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +12
-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. + Required interrupt resource entries are:
Quoted 8 lines
Documentation/devicetree/bindings/net/qcom-emac.txt line 21
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +5
-0+ "emac_core0" : EMAC core0 interrupt. + "sgmii_irq" : EMAC SGMII interrupt. +- phy-addr : Specifies phy address on MDIO bus. + Required if the optional property "qcom,no-external-phy" + is not specified.As I mentioned in the last version, you should still describe this with a standard MDIO bus binding even if you can't use the generic code.
You mean like this?
phy0: ethernet-phy@0 {
compatible = "qcom,fsm9900-emac-phy";
reg = <4>;
};Quoted 15 lines
Documentation/devicetree/bindings/net/qcom-emac.txt line 34
Quoted 12 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +12
-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. +- 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. +Example: + emac0: qcom,emac@feb20000 {ethernet@
Quoted 3 lines
Documentation/devicetree/bindings/net/qcom-emac.txt line 35
Quoted 1 line
Documentation/devicetree/bindings/net/qcom-emac.txt new file +1
-0+ compatible = "qcom,fsm9900-emac";Ah, I see you fixed it here...
and in the code, I just missed it in the top of the file. I'll fix it everywhere in v5.
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.
Rob Herring
maintainerQuoted 40 lines · Timur Tabi
Quoted 8 lines · Rob Herring
Documentation/devicetree/bindings/net/qcom-emac.txt line 4
Quoted 5 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4
-0@@ -0,0 +1,65 @@ +Qualcomm EMAC Gigabit Ethernet Controller + +Required properties: +- compatible : Should be "qcom,emac".Come on... Can you guess what I'm going to say here.
Ooops, I missed that one.
Quoted 22 lines
Quoted 18 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. +- phy-addr : Specifies phy address on MDIO bus. + Required if the optional propertyQuoted 2 lines
"qcom,no-external-phy"
+ is not specified.Quoted 2 lines
As I mentioned in the last version, you should still describe this with a standard MDIO bus binding even if you can't use the generic code.
Quoted 5 lines
You mean like this?
phy0: ethernet-phy@0 { compatible = "qcom,fsm9900-emac-phy"; reg = <4>;
Yes, but you mean 0 here or 4 for unit address.