lan743x: Add new lan743x driver
Subsystems (3)
Bryan Whitehead
maintainerv3 cover lan743x: Add new lan743x driver
Add new lan743x driver.
The lan743x from Microchip Technologies Inc,
is a PCIe to Gigabit Ethernet Controller.
Updates for V3:
Patch 1/2 - Applied community suggestions
removed initialization tracking flags.
converted to 64 bit statistics.
converted tx clean up tasklet to napi.
Updates for V2:
Patch 1/2 - Applied community suggestions
Bryan Whitehead (2):
lan743x: Add main source files for new lan743x driver
lan743x: Update MAINTAINERS to include lan743x driver
MAINTAINERS | 7 + drivers/net/ethernet/microchip/Kconfig | 10 + drivers/net/ethernet/microchip/Makefile | 3 + drivers/net/ethernet/microchip/lan743x_main.c | 2802 +++++++++++++++++++++++++ drivers/net/ethernet/microchip/lan743x_main.h | 597 ++++++ 5 files changed, 3419 insertions(+) create mode 100644 drivers/net/ethernet/microchip/lan743x_main.c create mode 100644 drivers/net/ethernet/microchip/lan743x_main.h
Signature · 1 line
2.7.4
Bryan Whitehead
maintainerPATCH v3 1/2 lan743x: Add main source files for new lan743x driver
Add main source files for new lan743x driver
--- drivers/net/ethernet/microchip/Kconfig | 10 + drivers/net/ethernet/microchip/Makefile | 3 + drivers/net/ethernet/microchip/lan743x_main.c | 2802 +++++++++++++++++++++++++ drivers/net/ethernet/microchip/lan743x_main.h | 597 ++++++ 4 files changed, 3412 insertions(+) create mode 100644 drivers/net/ethernet/microchip/lan743x_main.c create mode 100644 drivers/net/ethernet/microchip/lan743x_main.h
drivers/net/ethernet/microchip/Kconfig +10 -0
@@ -42,4 +42,14 @@ config ENCX24J600 To compile this driver as a module, choose M here. The module will be called encx24j600. +config LAN743X + tristate "LAN743x support" + depends on PCI + select PHYLIB + ---help--- + Support for the Microchip LAN743x PCI Express Gigabit Ethernet chip + + To compile this driver as a module, choose M here. The module will be + called lan743x. + endif # NET_VENDOR_MICROCHIP
drivers/net/ethernet/microchip/Makefile +3 -0
@@ -4,3 +4,6 @@ obj-$(CONFIG_ENC28J60) += enc28j60.o obj-$(CONFIG_ENCX24J600) += encx24j600.o encx24j600-regmap.o +obj-$(CONFIG_LAN743X) += lan743x.o + +lan743x-objs := lan743x_main.o
drivers/net/ethernet/microchip/lan743x_main.c new file +2802 -0
2,802 lines not on this page · raw message
drivers/net/ethernet/microchip/lan743x_main.h new file +597 -0
178 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
Re: [PATCH v3 net-next 1/2] lan743x: Add main source files for new lan743x driver
drivers/net/ethernet/microchip/lan743x_main.c line 925
Quoted 13 lines · Bryan Whitehead
drivers/net/ethernet/microchip/lan743x_main.c new file +13
-0+static int lan743x_phy_reset (struct lan743x_adapter *adapter) +{ +u32 data; + + data =lan743x_csr_read (adapter,PMT_CTL ); + data |=PMT_CTL_ETH_PHY_RST_ ; +lan743x_csr_write (adapter,PMT_CTL , data); + +return readx_poll_timeout (LAN743X_CSR_READ_OP ,PMT_CTL , data, + (!(data &PMT_CTL_ETH_PHY_RST_ ) && + (data &PMT_CTL_READY_ )), +50000 ,1000000 ); +}
Hi Bryan
Could you explain this a bit more. What exactly is it resetting? Do we need to tell the phylib that the PHY has been reset and that it needs to re-program it? Or by phy do you mean a SERDES interface?
Quoted 23 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +23
-0+static int lan743x_phy_open (struct lan743x_adapter *adapter) +{ +struct lan743x_phy *phy = &adapter->phy; +struct phy_device *phydev; +struct net_device *netdev; +int ret = -EIO ; +u32 mii_adv; + + netdev = adapter->netdev; + phydev =phy_find_first (adapter->mdiobus); +if (!phydev) + goto return_error; + + ret =phy_connect_direct (netdev, phydev, + lan743x_phy_link_status_change, +PHY_INTERFACE_MODE_GMII ); +if (ret) + goto return_error; + +/* MAC doesn't support 1000T Half */ + phydev->supported &= ~SUPPORTED_1000baseT_Half; + +/* support both flow controls */
drivers/net/ethernet/microchip/lan743x_main.c line 1028
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ phy->fc_request_control = (FLOW_CTRL_RX |FLOW_CTRL_TX ); + phydev->advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause); + mii_adv = (u32 )mii_advertise_flowctrl (phy->fc_request_control); + phydev->advertising |=mii_adv_to_ethtool_adv_t (mii_adv); + phy->fc_autoneg = phydev->autoneg; + +/* PHY interrupt enabled here */ +phy_start (phydev); +phy_start_aneg (phydev); +return 0 ;
Are phy interrupts really enabled here? I could of missed it, but i don't see anywhere PHY interrupts are configured. This is either done via device tree, you set phydev->irq, or mdiobus->irq[X].
drivers/net/ethernet/microchip/lan743x_main.c line 1749
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+static int lan743x_tx_open (struct lan743x_tx *tx) +{ +struct lan743x_adapter *adapter =NULL ; +u32 data =0 ; +int ret; + + adapter = tx->adapter; + ret =lan743x_tx_ring_init (tx); +if (ret) + goto return_error;
You could just return here. You don't do anything useful at return_error:
Quoted 71 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +70
-0+/* start dmac channel */ +lan743x_csr_write (adapter,DMAC_CMD , +DMAC_CMD_START_T_ (tx->channel_number)); +return 0 ; + +return_error: +return ret; +} +/* lan743x_pcidev_probe - Device Initialization Routine +* @pdev: PCI device information struct +* @id: entry in lan743x_pci_tbl +* +* Returns 0 on success, negative on failure +* +* initializes an adapter identified by a pci_dev structure. +* The OS initialization, configuring of the adapter private structure, +* and a hardware reset occur. +**/ +static int lan743x_pcidev_probe (struct pci_dev *pdev, +const struct pci_device_id *id) +{ +struct lan743x_adapter *adapter =NULL ; +struct net_device *netdev =NULL ; +int ret = -ENODEV ; + + netdev =devm_alloc_etherdev (&pdev->dev, +sizeof (struct lan743x_adapter )); +if (!netdev) + goto return_error; + +SET_NETDEV_DEV (netdev, &pdev->dev); +pci_set_drvdata (pdev, netdev); + adapter =netdev_priv (netdev); + adapter->netdev = netdev; + adapter->msg_enable =NETIF_MSG_DRV |NETIF_MSG_PROBE | +NETIF_MSG_LINK |NETIF_MSG_IFUP | +NETIF_MSG_IFDOWN |NETIF_MSG_TX_QUEUED ; + netdev->max_mtu =LAN743X_MAX_FRAME_SIZE ; + + ret =lan743x_pci_init (adapter, pdev); +if (ret) + goto return_error; + + ret =lan743x_csr_init (adapter); +if (ret) + goto cleanup_pci; + + ret =lan743x_hardware_init (adapter, pdev); +if (ret) + goto cleanup_pci; + + ret =lan743x_mdiobus_init (adapter); +if (ret) + goto cleanup_hardware; + + adapter->netdev->netdev_ops = &lan743x_netdev_ops; + adapter->netdev->features =NETIF_F_SG |NETIF_F_TSO |NETIF_F_HW_CSUM ; + adapter->netdev->hw_features = adapter->netdev->features; + +/* carrier off reporting is important to ethtool even BEFORE open */ +netif_carrier_off (netdev); + + ret =register_netdev (adapter->netdev); +if (ret <0 ) + goto cleanup_mdiobus; +return 0 ; + +cleanup_mdiobus: +lan743x_mdiobus_cleanup (adapter); +
drivers/net/ethernet/microchip/lan743x_main.c line 2727
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+cleanup_hardware: +lan743x_hardware_cleanup (adapter); + +cleanup_pci: +lan743x_pci_cleanup (adapter); + +return_error: +pr_warn ("Initialization failed\n" ); +return ret; +}
This is much nicer without all the flags. Thanks.
Quoted 18 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +18
-0+static struct pci_driver lan743x_pcidev_driver = { + .name =DRIVER_NAME , + .id_table = lan743x_pcidev_tbl, + .probe = lan743x_pcidev_probe, + .remove = lan743x_pcidev_remove, + .shutdown = lan743x_pcidev_shutdown, +}; + +static int __init lan743x_module_init (void ) +{ +int result = -EINVAL ; + +pr_info (DRIVER_DESC "\n" ); + result =pci_register_driver (&lan743x_pcidev_driver); +if (result) +pr_warn ("pci_register_driver returned error code, %d\n" , + result); +return result;
drivers/net/ethernet/microchip/lan743x_main.c line 2798
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +9
-0+} + +module_init (lan743x_module_init); + +static void __exit lan743x_module_exit(void) +{ +pci_unregister_driver (&lan743x_pcidev_driver); +} +module_exit (lan743x_module_exit);
You can replace this boilerplate code with module_pci_driver(). You don't do anything special here.
Andrew
[email protected]
maintainerRE: [PATCH v3 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 16 lines
drivers/net/ethernet/microchip/lan743x_main.c
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +8
-0+static int lan743x_phy_reset (struct lan743x_adapter *adapter) { +u32 data; + + data =lan743x_csr_read (adapter,PMT_CTL ); + data |=PMT_CTL_ETH_PHY_RST_ ; +lan743x_csr_write (adapter,PMT_CTL , data); + + return readx_poll_timeout(LAN743X_CSR_READ_OP, PMT_CTL,data,
drivers/net/ethernet/microchip/lan743x_main.c line 925
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +4
-0+ (!(data &PMT_CTL_ETH_PHY_RST_ ) && + (data &PMT_CTL_READY_ )), + 50000, 1000000); +}Hi Bryan
Quoted 3 lines
Could you explain this a bit more. What exactly is it resetting? Do we need to tell the phylib that the PHY has been reset and that it needs to re-program it? Or by phy do you mean a SERDES interface?
Hi Andrew,
This function resets the Ethernet phy. But it is called only in probe and before mdiobus_register. So I don't believe it is necessary to tell phylib.
[snip]
Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1028
Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +5
-0+ +/* PHY interrupt enabled here */ +phy_start (phydev); +phy_start_aneg (phydev); +return 0 ;Are phy interrupts really enabled here? I could of missed it, but i don't see anywhere PHY interrupts are configured. This is either done via device tree, you set
phydev->irq, or mdiobus->irq[X].
Sorry that is an obsolete comment, I will remove it. It is not using phy interrupts. It's using polling.
Quoted 13 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1749
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +9
-0+static int lan743x_tx_open (struct lan743x_tx *tx) { +struct lan743x_adapter *adapter =NULL ; +u32 data =0 ; +int ret; + + adapter = tx->adapter; + ret =lan743x_tx_ring_init (tx); +if (ret) + goto return_error;You could just return here. You don't do anything useful at
return_error:
Yes, I'll fix it.
[snip]
Quoted 1 line
This is much nicer without all the flags. Thanks.
No problem, thanks for your patients with me.
Quoted 25 lines
Quoted 25 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +23
-0+static struct pci_driver lan743x_pcidev_driver = { + .name =DRIVER_NAME , + .id_table = lan743x_pcidev_tbl, + .probe = lan743x_pcidev_probe, + .remove = lan743x_pcidev_remove, + .shutdown = lan743x_pcidev_shutdown, }; + +static int __init lan743x_module_init (void ) { +int result = -EINVAL ; + +pr_info (DRIVER_DESC "\n" ); + result =pci_register_driver (&lan743x_pcidev_driver); +if (result) +pr_warn ("pci_register_driver returned error code, %d\n" , + result); +return result; +} + +module_init (lan743x_module_init); + +static void __exit lan743x_module_exit(void) { +pci_unregister_driver (&lan743x_pcidev_driver); +}
Quoted 4 lines
Quoted 1 line
+module_exit(lan743x_module_exit);
You can replace this boilerplate code with
module_pci_driver(). You don't do anything special here.
OK
Thanks,
Bryan
Re: [PATCH v3 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 20 lines · On Fri, Mar 02, 2018 at 05:57:54AM +0000, [email protected] wrote:
Quoted 16 lines
drivers/net/ethernet/microchip/lan743x_main.c
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +8
-0+static int lan743x_phy_reset (struct lan743x_adapter *adapter) { +u32 data; + + data =lan743x_csr_read (adapter,PMT_CTL ); + data |=PMT_CTL_ETH_PHY_RST_ ; +lan743x_csr_write (adapter,PMT_CTL , data); + + return readx_poll_timeout(LAN743X_CSR_READ_OP, PMT_CTL,data,
drivers/net/ethernet/microchip/lan743x_main.c line 925
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +4
-0+ (!(data &PMT_CTL_ETH_PHY_RST_ ) && + (data &PMT_CTL_READY_ )), + 50000, 1000000); +}Hi Bryan
Quoted 3 lines
Could you explain this a bit more. What exactly is it resetting? Do we need to tell the phylib that the PHY has been reset and that it needs to re-program it? Or by phy do you mean a SERDES interface?
Quoted 5 lines
Hi Andrew,
This function resets the Ethernet phy. But it is called only in probe and before
mdiobus_register. So I don't believe it is necessary to tell phylib.
Hi Bryan
So the PHY is built in? It should be safe. Normally we have the PHY driver, or the generic layers handle any such reset via a GPIO. But built in is different.
Quoted 12 lines
[snip]
Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1028
Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +5
-0+ +/* PHY interrupt enabled here */ +phy_start (phydev); +phy_start_aneg (phydev); +return 0 ;Are phy interrupts really enabled here? I could of missed it, but i don't see anywhere PHY interrupts are configured. This is either done via device tree, you set
phydev->irq, or mdiobus->irq[X].
Quoted 2 lines
Sorry that is an obsolete comment, I will remove it. It is not using phy interrupts. It's using polling.
Assuming it is built in, does the MAC get the interrupt? phy_mac_interrupt() can be called if so.
Andrew
[email protected]
maintainerRE: [PATCH v3 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 23 lines
Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/microchip/lan743x_main.c
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +8
-0+static int lan743x_phy_reset (struct lan743x_adapter *adapter) { +u32 data; + + data =lan743x_csr_read (adapter,PMT_CTL ); + data |=PMT_CTL_ETH_PHY_RST_ ; +lan743x_csr_write (adapter,PMT_CTL , data); + + return readx_poll_timeout(LAN743X_CSR_READ_OP, PMT_CTL,data,
drivers/net/ethernet/microchip/lan743x_main.c line 925
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +4
-0+ (!(data &PMT_CTL_ETH_PHY_RST_ ) && + (data &PMT_CTL_READY_ )), + 50000, 1000000); +}Hi Bryan
Quoted 2 lines
Quoted 2 lines
Could you explain this a bit more. What exactly is it resetting? Do we need to tell the phylib that the PHY has been reset and that it needs
to re-program it?
Quoted 4 lines
Quoted 1 line
Or by phy do you mean a SERDES interface?
Hi Andrew,
Quoted 8 lines
Quoted 3 lines
This function resets the Ethernet phy. But it is called only in probe and before
mdiobus_register. So I don't believe it is necessary to tell phylib.Hi Bryan
So the PHY is built in? It should be safe. Normally we have the PHY driver, or the generic layers handle any such reset via a GPIO. But built in is different.
Hi Andrew,
The phy is built in for LAN7430, and external for LAN7431. But the same reset should work in both cases because it asserts the normal phy reset line.
Quoted 13 lines
Quoted 12 lines
[snip]
Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1028
Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +5
-0+ +/* PHY interrupt enabled here */ +phy_start (phydev); +phy_start_aneg (phydev); +return 0 ;Are phy interrupts really enabled here? I could of missed it, but i don't see anywhere PHY interrupts are configured. This is either done via device tree, you set
phydev->irq, or mdiobus->irq[X].
Quoted 5 lines
Quoted 2 lines
Sorry that is an obsolete comment, I will remove it. It is not using phy interrupts. It's using polling.
Assuming it is built in, does the MAC get the interrupt?
phy_mac_interrupt()can be called if so.
I believe the MAC does support a phy interrupt. But right now it's working well using phy polling. Is it ok if I post pone supporting phy interrupts until a future patch? I am planning a series of patches, and I can add support for phy interrupts to the list.
Bryan
Re: [PATCH v3 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 6 lines
Hi Andrew,
The phy is built in for LAN7430, and external for LAN7431. But the same reset should work in both cases because it asserts the normal phy reset line.
Assuming the PHY reset is connect to the external line, not a GPIO. So this is O.K.
Quoted 7 lines
Quoted 2 lines
Assuming it is built in, does the MAC get the interrupt?
phy_mac_interrupt()can be called if so.I believe the MAC does support a phy interrupt. But right now it's working well using phy polling. Is it ok if I post pone supporting phy interrupts until a future patch? I am planning a series of patches, and I can add support for phy interrupts to the list.
Yes, adding this later is fine.
Andrew
Bryan Whitehead
maintainerPATCH v3 2/2 lan743x: Update MAINTAINERS to include lan743x driver
In reply to Bryan WhiteheadUpdate MAINTAINERS to include lan743x driver
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -9157,6 +9157,13 @@ F: drivers/net/dsa/microchip/* F: include/linux/platform_data/microchip-ksz.h F: Documentation/devicetree/bindings/net/dsa/ksz.txt +MICROCHIP LAN743X ETHERNET DRIVER +M: Bryan Whitehead <[email protected]> +M: Microchip Linux Driver Support <[email protected]> +L: [email protected] +S: Maintained +F: drivers/net/ethernet/microchip/lan743x_* + MICROCHIP USB251XB DRIVER M: Richard Leitner <[email protected]> L: [email protected]
Signature · 1 line
2.7.4