lan743x: Add new lan743x driver
Subsystems (3)
Bryan Whitehead
maintainerv2 cover lan743x: Add new lan743x driver
Add new lan743x driver.
The lan743x from Microchip Technologies Inc,
is a PCIe to Gigabit Ethernet Controller.
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 | 2757 +++++++++++++++++++++++++ drivers/net/ethernet/microchip/lan743x_main.h | 686 ++++++ 5 files changed, 3463 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 v2 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 | 2757 +++++++++++++++++++++++++ drivers/net/ethernet/microchip/lan743x_main.h | 686 ++++++ 4 files changed, 3456 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 +2757 -0
2,757 lines not on this page · raw message
drivers/net/ethernet/microchip/lan743x_main.h new file +686 -0
223 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 v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
drivers/net/ethernet/microchip/lan743x_main.c line 397
Quoted 7 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +7
-0+static void lan743x_intr_unregister_isr (struct lan743x_adapter *adapter, +int vector_index) +{ +struct lan743x_vector *vector = &adapter->intr.vector_list + [vector_index]; + +devm_free_irq (&adapter->pci.pdev->dev, vector->irq, vector);
Hu Bryan
The point of devm_ is that you don't need to free resources you have allocated using devm_. The core will release them when the device is removed.
In this case, you might want to ensure the hardware will not generate any more interrupts, but you can leave the core to call free_irq().
Please look at all your devm_*free() like calls, and remove them if they are not needed.
drivers/net/ethernet/microchip/lan743x_main.c line 2534
Quoted 12 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +12
-0+static void lan743x_mdiobus_cleanup (struct lan743x_adapter *adapter) +{ +if (adapter->init_flags &LAN743X_INIT_FLAG_MDIOBUS_REGISTERED ) { +mdiobus_unregister (adapter->mdiobus); + adapter->init_flags &= ~LAN743X_INIT_FLAG_MDIOBUS_REGISTERED ; + } +if (adapter->init_flags &LAN743X_INIT_FLAG_MDIOBUS_ALLOCATED ) { +devm_mdiobus_free (&adapter->pci.pdev->dev, adapter->mdiobus); + adapter->mdiobus =NULL ; + adapter->init_flags &= ~LAN743X_INIT_FLAG_MDIOBUS_ALLOCATED ; + } +}
So you can delete devm_mdiobus_free(). That probably means you can also remove LAN743X_INIT_FLAG_MDIOBUS_ALLOCATED.
Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +9
-0+ +static void lan743x_full_cleanup (struct lan743x_adapter *adapter) +{ +if (adapter->init_flags &LAN743X_INIT_FLAG_NETDEV_REGISTERED ) { +unregister_netdev (adapter->netdev); + adapter->init_flags &= ~LAN743X_INIT_FLAG_NETDEV_REGISTERED ; + } +lan743x_mdiobus_cleanup (adapter); +lan743x_hardware_cleanup (adapter);
drivers/net/ethernet/microchip/lan743x_main.c line 2553
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+if (adapter->init_flags &LAN743X_COMPONENT_FLAG_PCI ) { +lan743x_pci_cleanup (adapter); + adapter->init_flags &= ~LAN743X_COMPONENT_FLAG_PCI ; + } + +/* would have freed netdev here. +* but netdev was allocated with devm_alloc_etherdev. +* and devm_free_netdev is not accessible. +* so it is expected to be freed by the devm subsystem. +*/
And this comment can go.
Andrew
[email protected]
maintainerRE: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c line 397
Quoted 7 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +7
-0+static void lan743x_intr_unregister_isr (struct lan743x_adapter *adapter, +int vector_index) +{ +struct lan743x_vector *vector = &adapter->intr.vector_list + [vector_index]; + +devm_free_irq (&adapter->pci.pdev->dev, vector->irq, vector);Hu Bryan
Quoted 3 lines
The point of
devm_is that you don't need to free resources you have allocated usingdevm_. The core will release them when the device is removed.
Hi Andrew,
When I remove the call devm_free_irq, I get a segmentation fault on close in pci_disable_msix. Did I do something else wrong?
Also I'm allocating interrupt resources on interface up, and freeing resources on interface down. So if there is an up, down, up sequence then the driver will allocate resources twice. In order for devm to work properly, should I move all resource allocation into the probe function?
Bryan
Re: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 16 lines · On 02/22/2018 01:31 PM, [email protected] wrote:
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c line 397
Quoted 7 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +7
-0+static void lan743x_intr_unregister_isr (struct lan743x_adapter *adapter, +int vector_index) +{ +struct lan743x_vector *vector = &adapter->intr.vector_list + [vector_index]; + +devm_free_irq (&adapter->pci.pdev->dev, vector->irq, vector);Hu Bryan
Quoted 3 lines
The point of
devm_is that you don't need to free resources you have allocated usingdevm_. The core will release them when the device is removed.Hi Andrew,
Quoted 7 lines
When I remove the call
devm_free_irq, I get a segmentation fault on close inpci_disable_msix. Did I do something else wrong?Also I'm allocating interrupt resources on interface up, and freeing resources on interface down. So if there is an up, down, up sequence then the driver will allocate resources twice. In order for devm to work properly, should I move all resource allocation into the probe function?
No, most network drivers request their interrupt line in the open function and free it in the close function. Because you are balancing each devm_request_irq() with a devm_free_irq(), just don't just devm_* functions, just the normal request_irq() and free_irq() functions.
Signature · 1 line
Florian
Re: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
In reply to [email protected]Quoted 4 lines
Also I'm allocating interrupt resources on interface up, and freeing resources on interface down. So if there is an up, down, up sequence then the driver will allocate resources twice. In order for devm to work properly, should I move all resource allocation into the probe function?
Hi Bryan
It is better to fail early if the resource is not available, so yes, i would register the interrupt handler in probe.
Andrew
Re: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 9 lines · Andrew Lunn
Quoted 4 lines
Also I'm allocating interrupt resources on interface up, and freeing resources on interface down. So if there is an up, down, up sequence then the driver will allocate resources twice. In order for devm to work properly, should I move all resource allocation into the probe function?
Hi Bryan
It is better to fail early if the resource is not available, so yes, i would register the interrupt handler in probe.
And we maintainers don't always agree with each other :-)
Doing irq handling in open/close without devm_ is also O.K.
Andrew
[email protected]
maintainerRE: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 9 lines · Andrew Lunn
Quoted 4 lines
Quoted 4 lines
Also I'm allocating interrupt resources on interface up, and freeing resources on interface down. So if there is an up, down, up sequence then the driver will allocate resources twice. In order for devm to work properly, should I move all resource allocation into the probe
function?
Quoted 3 lines
Hi Bryan
Quoted 8 lines
Quoted 2 lines
It is better to fail early if the resource is not available, so yes, i would register the interrupt handler in probe.
And we maintainers don't always agree with each other :-)
Doing irq handling in open/close without
devm_is also O.K.Andrew
Thanks Andrew, and Florian,
Moving irq allocation and free, to probe and remove, will require a bit of refactoring and possibly introduce new issues. For now I will keep IRQ handling in open/close without devm_.
Other resource allocations are already in probe/remove so I will apply your suggestions in the next patch revision.
Thanks,
Bryan
kbuild test robot
build botRe: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
In reply to Bryan WhiteheadThank you for the patch! Perhaps something to improve:
Hi Bryan,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Bryan-Whitehead/lan743x-Add-new-lan743x-driver/20180222-225510
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__sparse warnings: (new ones prefixed by >>)
>> drivers/net/ethernet/microchip/lan743x_main.c:68:5: sparse: symbol 'lan743x_csr_read' was not declared. Should it be >> drivers/net/ethernet/microchip/lan743x_main.c:73:6: sparse: symbol 'lan743x_csr_write' was not declared. Should it be
Please review and possibly fold the followup patch.
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build bot[RFC PATCH] lan743x: lan743x_csr_read() can be static
In reply to Bryan WhiteheadFixes: 896121de80db ("lan743x: Add main source files for new lan743x driver")
--- lan743x_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/lan743x_main.c +2 -2
@@ -65,12 +65,12 @@ static int lan743x_pci_init(struct lan743x_adapter *adapter,return ret; } -u32 lan743x_csr_read (struct lan743x_adapter *adapter,int offset) +static u32 lan743x_csr_read (struct lan743x_adapter *adapter,int offset) {return ioread32 (&adapter->csr.csr_address[offset]); } -void lan743x_csr_write (struct lan743x_adapter *adapter,int offset,u32 data) +static void lan743x_csr_write (struct lan743x_adapter *adapter,int offset,u32 data) {iowrite32 (data, &adapter->csr.csr_address[offset]); }
Re: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
In reply to Bryan WhiteheadQuoted 6 lines · Bryan Whitehead
Add main source files for new lan743x driver.
Signed-off-by Bryan Whitehead <[email protected]>---
+lan743x-objs := lan743x_main.o
Should we assume that you have additional object files you would like to contribute at a later point? If that is the case, this is fine, if this is going to be only file of this driver, consider renaming it so you don't even have to have this lan743x-objs line at all.
drivers/net/ethernet/microchip/lan743x_main.c line 2
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +2
-0@@ -0,0 +1,2757 @@ +/* +* Copyright (C) 2018 Microchip Technology
You should consider the SPDX license tags to reduce the license boilerplate standard disclaimer.
Quoted 6 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +6
-0+* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +*
drivers/net/ethernet/microchip/lan743x_main.c line 18
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "lan743x_main.h"
This is not ideal, having all your header dependencies resolved by a main header file usually leads to unnecessary inclusions when fewer are needed.
drivers/net/ethernet/microchip/lan743x_main.c line 24
Quoted 6 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +6
-0+ +static void lan743x_pci_cleanup (struct lan743x_adapter *adapter) +{ +struct lan743x_pci *pci = &adapter->pci; + +if (pci->init_flags &INIT_FLAG_PCI_REGIONS_REQUESTED ) {
There is a pattern throughout the driver of maintaining flags to track what was initialized and what was not, do you really need that, or can you check for specific book keeping private information. Maintaining flags is error prone and requires you to keep adding new ones, that does not really scale.
[snip]
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +8
-0+static void lan743x_intr_software_isr (void *context) +{ +struct lan743x_adapter *adapter = context; +struct lan743x_intr *intr = &adapter->intr; +u32 int_sts; + + int_sts =lan743x_csr_read (adapter,INT_STS ); +if (int_sts &INT_BIT_SW_GP_ ) {
drivers/net/ethernet/microchip/lan743x_main.c line 166
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+lan743x_csr_write (adapter,INT_STS ,INT_BIT_SW_GP_ ); + intr->software_isr_flag =1 ; + } +} + +static void lan743x_tx_isr (void *context,u32 int_sts,u32 flags) +{ +struct lan743x_tx *tx = context; +struct lan743x_adapter *adapter = tx->adapter; +int enable_flag =1 ;
This is inherently a boolean type.
Quoted 18 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +18
-0+u32 int_en =0 ; + + int_en =lan743x_csr_read (adapter,INT_EN_SET ); +if (flags &LAN743X_VECTOR_FLAG_SOURCE_ENABLE_CLEAR ) { +lan743x_csr_write (adapter,INT_EN_CLR , +INT_BIT_DMA_TX_ (tx->channel_number)); + } +if (int_sts &INT_BIT_DMA_TX_ (tx->channel_number)) { +u32 ioc_bit =DMAC_INT_BIT_TX_IOC_ (tx->channel_number); +u32 dmac_int_sts; +u32 dmac_int_en; + +if (flags &LAN743X_VECTOR_FLAG_SOURCE_STATUS_READ ) + dmac_int_sts =lan743x_csr_read (adapter,DMAC_INT_STS ); +else + dmac_int_sts = ioc_bit; +if (flags &LAN743X_VECTOR_FLAG_SOURCE_ENABLE_CHECK ) + dmac_int_en = lan743x_csr_read(adapter,
drivers/net/ethernet/microchip/lan743x_main.c line 194
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ DMAC_INT_EN_SET); + else + dmac_int_en = ioc_bit; + + dmac_int_en &= ioc_bit; + dmac_int_sts &= dmac_int_en; +if (dmac_int_sts & ioc_bit) { +tasklet_schedule (&tx->tx_isr_bottom_half); + enable_flag =0 ;/* tasklet will re-enable later */ + }
Consider migrating your TX buffer reclamation to a NAPI context. If you have one TX queue and one RX, the same NAPI context can be re-used, if you have separate RX/TX queues, you may create a NAPI context per RX/TX pair, or you may create separate NAPI contexts per TX queues and RX queues.
Quoted 40 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +40
-0+ } +if (enable_flag) +/* enable isr */ +lan743x_csr_write (adapter,INT_EN_SET , +INT_BIT_DMA_TX_ (tx->channel_number)); +} + +static void lan743x_rx_isr (void *context,u32 int_sts,u32 flags) +{ +struct lan743x_rx *rx = context; +struct lan743x_adapter *adapter = rx->adapter; +int enable_flag =1 ; + +if (flags &LAN743X_VECTOR_FLAG_SOURCE_ENABLE_CLEAR ) { +lan743x_csr_write (adapter,INT_EN_CLR , +INT_BIT_DMA_RX_ (rx->channel_number)); + } +if (int_sts &INT_BIT_DMA_RX_ (rx->channel_number)) { +u32 rx_frame_bit =DMAC_INT_BIT_RXFRM_ (rx->channel_number); +u32 dmac_int_sts; +u32 dmac_int_en; + +if (flags &LAN743X_VECTOR_FLAG_SOURCE_STATUS_READ ) + dmac_int_sts =lan743x_csr_read (adapter,DMAC_INT_STS ); +else + dmac_int_sts = rx_frame_bit; +if (flags &LAN743X_VECTOR_FLAG_SOURCE_ENABLE_CHECK ) + dmac_int_en =lan743x_csr_read (adapter, +DMAC_INT_EN_SET ); +else + dmac_int_en = rx_frame_bit; + + dmac_int_en &= rx_frame_bit; + dmac_int_sts &= dmac_int_en; +if (dmac_int_sts & rx_frame_bit) { +napi_schedule (&rx->napi); + enable_flag =0 ;/* poll function will re-enable later */ + } + } +if (enable_flag) {
drivers/net/ethernet/microchip/lan743x_main.c line 244
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+/* enable isr */ +lan743x_csr_write (adapter,INT_EN_SET , +INT_BIT_DMA_RX_ (rx->channel_number)); + } +} + +static void lan743x_intr_shared_isr (void *context,u32 int_sts,u32 flags) +{ +struct lan743x_adapter *adapter = context; +int channel;
unsigned int.
Quoted 59 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +59
-0+ +if (int_sts &INT_BIT_ALL_RX_ ) { +for (channel =0 ; channel <LAN743X_USED_RX_CHANNELS ; + channel++) { +u32 int_bit =INT_BIT_DMA_RX_ (channel); + +if (int_sts & int_bit) { +lan743x_rx_isr (&adapter->rx[channel], + int_bit, flags); + int_sts &= ~int_bit; + } + } + } +if (int_sts &INT_BIT_ALL_TX_ ) { +for (channel =0 ; channel <LAN743X_USED_TX_CHANNELS ; + channel++) { +u32 int_bit =INT_BIT_DMA_TX_ (channel); + +if (int_sts & int_bit) { +lan743x_tx_isr (&adapter->tx[channel], + int_bit, flags); + int_sts &= ~int_bit; + } + } + } +if (int_sts &INT_BIT_ALL_OTHER_ ) { +if (int_sts &INT_BIT_SW_GP_ ) { +lan743x_intr_software_isr (adapter); + int_sts &= ~INT_BIT_SW_GP_ ; + } + } +if (int_sts) +lan743x_csr_write (adapter,INT_EN_CLR , int_sts); +} + +static irqreturn_t lan743x_intr_entry_isr (int irq,void *ptr) +{ +struct lan743x_vector *vector = ptr; +struct lan743x_adapter *adapter = vector->adapter; +irqreturn_t result =IRQ_NONE ; +u32 int_enables; +u32 int_sts; + +if (vector->flags &LAN743X_VECTOR_FLAG_SOURCE_STATUS_READ ) { + int_sts =lan743x_csr_read (adapter,INT_STS ); + }else if (vector->flags & + (LAN743X_VECTOR_FLAG_SOURCE_STATUS_R2C | +LAN743X_VECTOR_FLAG_SOURCE_ENABLE_R2C )) { + int_sts =lan743x_csr_read (adapter,INT_STS_R2C ); + }else { +/* use mask as implied status */ + int_sts = vector->int_mask |INT_BIT_MAS_ ; + } +if (!(int_sts &INT_BIT_MAS_ )) + goto irq_done; +if (vector->flags &LAN743X_VECTOR_FLAG_VECTOR_ENABLE_ISR_CLEAR ) +/* disable vector interrupt */ + lan743x_csr_write(adapter, + INT_VEC_EN_CLR,
drivers/net/ethernet/microchip/lan743x_main.c line 313
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ INT_VEC_EN_(vector->vector_index)); +if (vector->flags &LAN743X_VECTOR_FLAG_MASTER_ENABLE_CLEAR ) +/* disable master interrupt */ +lan743x_csr_write (adapter,INT_EN_CLR ,INT_BIT_MAS_ ); +if (vector->flags &LAN743X_VECTOR_FLAG_SOURCE_ENABLE_CHECK ) { + int_enables =lan743x_csr_read (adapter,INT_EN_SET ); + }else { +/* use vector mask as implied enable mask */ + int_enables = vector->int_mask; + }
Please put spaces to logically separate what you are doing, this is barely readable.
Quoted 132 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +132
-0+/* setup auto duplex, and speed detection */ + data =lan743x_csr_read (adapter,MAC_CR ); + data |=MAC_CR_ADD_ |MAC_CR_ASD_ ; + data |=MAC_CR_CNTR_RST_ ; +lan743x_csr_write (adapter,MAC_CR , data); + mac_addr_hi =lan743x_csr_read (adapter,MAC_RX_ADDRH ); + mac_addr_lo =lan743x_csr_read (adapter,MAC_RX_ADDRL ); + mac->mac_address[0 ] = mac_addr_lo &0xFF ; + mac->mac_address[1 ] = (mac_addr_lo >>8 ) &0xFF ; + mac->mac_address[2 ] = (mac_addr_lo >>16 ) &0xFF ; + mac->mac_address[3 ] = (mac_addr_lo >>24 ) &0xFF ; + mac->mac_address[4 ] = mac_addr_hi &0xFF ; + mac->mac_address[5 ] = (mac_addr_hi >>8 ) &0xFF ; +if (((mac_addr_hi &0x0000FFFF ) ==0x0000FFFF ) && + mac_addr_lo ==0xFFFFFFFF ) { + mac_address_valid = false; + }else if (!is_valid_ether_addr (mac->mac_address)) { + mac_address_valid = false; + } +if (!mac_address_valid) +random_ether_addr (mac->mac_address); +lan743x_mac_set_address (adapter, mac->mac_address); +ether_addr_copy (netdev->dev_addr, mac->mac_address); +return 0 ; +} + +static int lan743x_mac_open (struct lan743x_adapter *adapter) +{ +int ret =0 ; +u32 temp; + + temp =lan743x_csr_read (adapter,MAC_RX ); +lan743x_csr_write (adapter,MAC_RX , temp |MAC_RX_RXEN_ ); + temp =lan743x_csr_read (adapter,MAC_TX ); +lan743x_csr_write (adapter,MAC_TX , temp |MAC_TX_TXEN_ ); +return ret; +} + +static void lan743x_mac_close (struct lan743x_adapter *adapter) +{ +u32 temp; + + temp =lan743x_csr_read (adapter,MAC_TX ); + temp &= ~MAC_TX_TXEN_ ; +lan743x_csr_write (adapter,MAC_TX , temp); +lan743x_csr_wait_for_bit (adapter,MAC_TX ,MAC_TX_TXD_ , +1 ,1000 ,20000 ,100 ); + temp =lan743x_csr_read (adapter,MAC_RX ); + temp &= ~MAC_RX_RXEN_ ; +lan743x_csr_write (adapter,MAC_RX , temp); +lan743x_csr_wait_for_bit (adapter,MAC_RX ,MAC_RX_RXD_ , +1 ,1000 ,20000 ,100 ); +} + +static void lan743x_mac_flow_ctrl_set_enables (struct lan743x_adapter *adapter, +bool tx_enable,bool rx_enable) +{ +u32 flow_setting =0 ; + +/* set maximum pause time because when fifo space frees +* up a zero value pause frame will be sent to release the pause +*/ + flow_setting =MAC_FLOW_CR_FCPT_MASK_ ; +if (tx_enable) + flow_setting |=MAC_FLOW_CR_TX_FCEN_ ; +if (rx_enable) + flow_setting |=MAC_FLOW_CR_RX_FCEN_ ; +lan743x_csr_write (adapter,MAC_FLOW , flow_setting); +} + +static int lan743x_mac_set_mtu (struct lan743x_adapter *adapter,int new_mtu) +{ +int enabled =0 ; +u32 mac_rx =0 ; + + mac_rx =lan743x_csr_read (adapter,MAC_RX ); +if (mac_rx &MAC_RX_RXEN_ ) { + enabled =1 ; +if (mac_rx &MAC_RX_RXD_ ) { +lan743x_csr_write (adapter,MAC_RX , mac_rx); + mac_rx &= ~MAC_RX_RXD_ ; + } + mac_rx &= ~MAC_RX_RXEN_ ; +lan743x_csr_write (adapter,MAC_RX , mac_rx); +lan743x_csr_wait_for_bit (adapter,MAC_RX ,MAC_RX_RXD_ , +1 ,1000 ,20000 ,100 ); +lan743x_csr_write (adapter,MAC_RX , mac_rx |MAC_RX_RXD_ ); + } + mac_rx &= ~(MAC_RX_MAX_SIZE_MASK_ ); + mac_rx |= (((new_mtu +ETH_HLEN +4 ) <<MAC_RX_MAX_SIZE_SHIFT_ ) & +MAC_RX_MAX_SIZE_MASK_ ); +lan743x_csr_write (adapter,MAC_RX , mac_rx); +if (enabled) { + mac_rx |=MAC_RX_RXEN_ ; +lan743x_csr_write (adapter,MAC_RX , mac_rx); + } +return 0 ; +} + +/* PHY */ +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 ); +} + +static void lan743x_phy_update_flowcontrol (struct lan743x_adapter *adapter, +u8 duplex,u16 local_adv, +u16 remote_adv) +{ +struct lan743x_phy *phy = &adapter->phy; +u8 cap; + +if (phy->fc_autoneg) + cap =mii_resolve_flowctrl_fdx (local_adv, remote_adv); +else + cap = phy->fc_request_control; +lan743x_mac_flow_ctrl_set_enables (adapter, + cap &FLOW_CTRL_TX , + cap &FLOW_CTRL_RX ); +} + +static int lan743x_phy_init (struct lan743x_adapter *adapter) +{
drivers/net/ethernet/microchip/lan743x_main.c line 925
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+struct net_device *netdev; +int ret; + + netdev = adapter->netdev; + ret =lan743x_phy_reset (adapter); +if (ret) +return ret; + +/* carrier off reporting is important to ethtool even BEFORE open */ +netif_carrier_off (netdev);
Move this before the register_netdev() call and let the PHY library manage the carrier state from there on.
drivers/net/ethernet/microchip/lan743x_main.c line 934
Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +9
-0+return 0 ; +} + +static void lan743x_phy_link_status_change (struct net_device *netdev) +{ +struct lan743x_adapter *adapter =netdev_priv (netdev); +struct phy_device *phydev = netdev->phydev; + +if (phydev) {
You should not allow your network device to be registered without a valid PHY device, so this test should be entirely eliminated.
Quoted 22 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +22
-0+phy_print_status (phydev); +if (phydev->state ==PHY_RUNNING ) { +struct ethtool_link_ksettings ksettings; +struct lan743x_phy *phy =NULL ; +int remote_advertisement =0 ; +int local_advertisement =0 ; + + phy = &adapter->phy; +memset (&ksettings,0 ,sizeof (ksettings)); +phy_ethtool_get_link_ksettings (netdev, &ksettings); + local_advertisement =phy_read (phydev,MII_ADVERTISE ); +if (local_advertisement <0 ) +return ; + remote_advertisement =phy_read (phydev,MII_LPA ); +if (remote_advertisement <0 ) +return ; +lan743x_phy_update_flowcontrol (adapter, + ksettings.base.duplex, + local_advertisement, + remote_advertisement); + } + }
drivers/net/ethernet/microchip/lan743x_main.c line 966
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+} + +static void lan743x_phy_close (struct lan743x_adapter *adapter) +{ +struct net_device *netdev = adapter->netdev; +struct lan743x_phy *phy = &adapter->phy; + +if (phy->flags &PHY_FLAG_OPENED ) { +netif_carrier_off (netdev); +phy_stop (netdev->phydev);
netif_carrier_off() is already taken care of by the PHY library.
drivers/net/ethernet/microchip/lan743x_main.c line 973
Quoted 7 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +7
-0+ phy->flags &= ~PHY_FLAG_OPENED ; + } +if (phy->flags &PHY_FLAG_ATTACHED ) { +phy_disconnect (netdev->phydev); + netdev->phydev =NULL ; + phy->flags &= ~PHY_FLAG_ATTACHED ; + }
Again, unnecessary proliferation of status flags to keep track of your initialization.
Quoted 22 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +22
-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) { + ret = -EIO ; + goto clean_up; + } + ret =phy_connect_direct (netdev, phydev, + lan743x_phy_link_status_change, +PHY_INTERFACE_MODE_GMII ); +if (ret) + goto clean_up; + phy->flags |=PHY_FLAG_ATTACHED ;
drivers/net/ethernet/microchip/lan743x_main.c line 1005
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ +/* MAC doesn't support 1000T Half */ + phydev->supported &= ~SUPPORTED_1000baseT_Half; + +/* support both flow controls */ + 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;
No driver does things like that, that appears to be really wrong.
Quoted 100 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +100
-0+ +/* PHY interrupt enabled here */ +phy_start (phydev); +phy_start_aneg (phydev); + phy->flags |=PHY_FLAG_OPENED ; +return 0 ; +clean_up: +lan743x_phy_close (adapter); +return ret; +} + +static void lan743x_rfe_update_mac_address (struct lan743x_adapter *adapter) +{ +u8 mac_addr[ETH_ALEN ]; +u32 mac_addr_hi =0 ; +u32 mac_addr_lo =0 ; + +/* Add mac address to perfect Filter */ +ether_addr_copy (mac_addr, adapter->mac.mac_address); + mac_addr_lo = ((((u32)(mac_addr[0 ])) <<0 ) | + (((u32)(mac_addr[1 ])) <<8 ) | + (((u32)(mac_addr[2 ])) <<16 ) | + (((u32)(mac_addr[3 ])) <<24 )); + mac_addr_hi = ((((u32)(mac_addr[4 ])) <<0 ) | + (((u32)(mac_addr[5 ])) <<8 )); +lan743x_csr_write (adapter,RFE_ADDR_FILT_LO (0 ), mac_addr_lo); +lan743x_csr_write (adapter,RFE_ADDR_FILT_HI (0 ), + mac_addr_hi |RFE_ADDR_FILT_HI_VALID_ ); +} + +static void lan743x_rfe_set_multicast (struct lan743x_adapter *adapter) +{ +struct net_device *netdev = adapter->netdev; +u32 hash_table[DP_SEL_VHF_HASH_LEN ]; +u32 rfctl; +u32 data; + + rfctl =lan743x_csr_read (adapter,RFE_CTL ); + rfctl &= ~(RFE_CTL_AU_ |RFE_CTL_AM_ | +RFE_CTL_DA_PERFECT_ |RFE_CTL_MCAST_HASH_ ); + rfctl |=RFE_CTL_AB_ ; +if (netdev->flags &IFF_PROMISC ) { + rfctl |=RFE_CTL_AM_ |RFE_CTL_AU_ ; + }else { +if (netdev->flags &IFF_ALLMULTI ) + rfctl |=RFE_CTL_AM_ ; + } +memset (hash_table,0 ,DP_SEL_VHF_HASH_LEN *sizeof (u32)); +if (netdev_mc_count (netdev)) { +struct netdev_hw_addr *ha; +int i; + + rfctl |=RFE_CTL_DA_PERFECT_ ; + i =1 ; +netdev_for_each_mc_addr (ha, netdev) { +/* set first 32 into Perfect Filter */ +if (i <33 ) { +lan743x_csr_write (adapter, +RFE_ADDR_FILT_HI (i),0 ); + data = ha->addr[3 ]; + data = ha->addr[2 ] | (data <<8 ); + data = ha->addr[1 ] | (data <<8 ); + data = ha->addr[0 ] | (data <<8 ); +lan743x_csr_write (adapter, +RFE_ADDR_FILT_LO (i), data); + data = ha->addr[5 ]; + data = ha->addr[4 ] | (data <<8 ); + data |=RFE_ADDR_FILT_HI_VALID_ ; +lan743x_csr_write (adapter, +RFE_ADDR_FILT_HI (i), data); + }else { +u32 bitnum = (ether_crc (ETH_ALEN , ha->addr) >> +23 ) &0x1FF ; + hash_table[bitnum /32 ] |= (1 << (bitnum %32 )); + rfctl |=RFE_CTL_MCAST_HASH_ ; + } + i++; + } + } +lan743x_dp_write (adapter,DP_SEL_RFE_RAM , +DP_SEL_VHF_VLAN_LEN , +DP_SEL_VHF_HASH_LEN , hash_table); +lan743x_csr_write (adapter,RFE_CTL , rfctl); +} + +static int lan743x_dmac_init (struct lan743x_adapter *adapter) +{ +struct lan743x_dmac *dmac = &adapter->dmac; +u32 data =0 ; + + dmac->flags =0 ; + dmac->descriptor_spacing =DEFAULT_DMA_DESCRIPTOR_SPACING ; +lan743x_csr_write (adapter,DMAC_CMD ,DMAC_CMD_SWR_ ); +lan743x_csr_wait_for_bit (adapter,DMAC_CMD ,DMAC_CMD_SWR_ , +0 ,1000 ,20000 ,100 ); +switch (dmac->descriptor_spacing) { +case DMA_DESCRIPTOR_SPACING_16 : + data =DMAC_CFG_MAX_DSPACE_16_ ; +break ; +case DMA_DESCRIPTOR_SPACING_32 :
drivers/net/ethernet/microchip/lan743x_main.c line 1115
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ data =DMAC_CFG_MAX_DSPACE_32_ ; +break ; +case DMA_DESCRIPTOR_SPACING_64 : + data =DMAC_CFG_MAX_DSPACE_64_ ; +break ; +case DMA_DESCRIPTOR_SPACING_128 : + data =DMAC_CFG_MAX_DSPACE_128_ ; +break ; +default : +return -EPERM ;
-EINVAL maybe?
[snip]
drivers/net/ethernet/microchip/lan743x_main.c line 1240
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +4
-0+ +done: +memset (buffer_info,0 ,sizeof (*buffer_info)); +memset (descriptor,0 ,sizeof (*descriptor));
You are likely missing barriers here, what guarantees that the buffer_info and descriptor are going to be properly maintained in a non-cache coherent architecture?
Quoted 18 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +18
-0+} + +static int lan743x_tx_next_index (struct lan743x_tx *tx,int index) +{ +return ((++index) % tx->ring_size); +} + +static void lan743x_tx_release_completed_descriptors (struct lan743x_tx *tx) +{ +while ((*tx->head_cpu_ptr) != (tx->last_head)) { +lan743x_tx_release_desc (tx, tx->last_head, false); + tx->last_head =lan743x_tx_next_index (tx, tx->last_head); + } +} + +static void lan743x_tx_release_all_descriptors (struct lan743x_tx *tx) +{ +u32 original_head =0 ;
drivers/net/ethernet/microchip/lan743x_main.c line 1268
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ + original_head = tx->last_head; +do { +lan743x_tx_release_desc (tx, tx->last_head, true); + tx->last_head =lan743x_tx_next_index (tx, tx->last_head); + }while (tx->last_head != original_head); +memset (tx->ring_cpu_ptr,0 , +sizeof (*tx->ring_cpu_ptr) * (tx->ring_size)); +memset (tx->buffer_info,0 , +sizeof (*tx->buffer_info) * (tx->ring_size));
This is coherent memory, but you still need to prevent possible re-orderings, so you need at least a write barrier to guarantee all pending writes are completed. Likely you won't ever see this as a problem on x86 platforms.
Quoted 18 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +18
-0+ tx->frame_flags |=TX_FRAME_FLAG_IN_PROGRESS ; + tx->frame_first = tx->last_tail; + tx->frame_tail = tx->frame_first; + tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; + buffer_info = &tx->buffer_info[tx->frame_tail]; + dma_ptr =dma_map_single (dev, first_buffer, first_buffer_length, +DMA_TO_DEVICE ); +if (dma_mapping_error (dev, dma_ptr)) +return -ENOMEM ; + tx_descriptor->data1 =DMA_ADDR_LOW32 (dma_ptr); + tx_descriptor->data2 =DMA_ADDR_HIGH32 (dma_ptr); + tx_descriptor->data3 = (frame_length <<16 ) & +TX_DESC_DATA3_FRAME_LENGTH_MSS_MASK_ ; + buffer_info->skb =NULL ; + buffer_info->dma_ptr = dma_ptr; + buffer_info->buffer_length = first_buffer_length; + buffer_info->flags |=TX_BUFFER_INFO_FLAG_ACTIVE ; + tx->frame_data0 = (first_buffer_length &
drivers/net/ethernet/microchip/lan743x_main.c line 1337
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ TX_DESC_DATA0_BUF_LENGTH_MASK_) | +TX_DESC_DATA0_DTYPE_DATA_ | +TX_DESC_DATA0_FS_ | +TX_DESC_DATA0_FCS_ ; +if (check_sum) + tx->frame_data0 |=TX_DESC_DATA0_ICE_ | +TX_DESC_DATA0_IPE_ | +TX_DESC_DATA0_TPE_ ; + +/* data0 will be programmed in one of other frame assembler functions */
You again need some sort of write barrier here to guarantee ordering and make sure the descriptors/buffer_info are properly written.
Quoted 23 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +23
-0+return 0 ; +} + +static void lan743x_tx_frame_add_lso (struct lan743x_tx *tx, +unsigned int frame_length) +{ +/* called only from within lan743x_tx_xmit_frame. +* assuming tx->ring_lock has already been acquired. +*/ +struct lan743x_tx_descriptor *tx_descriptor =NULL ; +struct lan743x_tx_buffer_info *buffer_info =NULL ; + +/* wrap up previous descriptor */ + tx->frame_data0 |=TX_DESC_DATA0_EXT_ ; + tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; + tx_descriptor->data0 = tx->frame_data0; + +/* move to next descriptor */ + tx->frame_tail =lan743x_tx_next_index (tx, tx->frame_tail); + tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; + buffer_info = &tx->buffer_info[tx->frame_tail]; + +/* add extension descriptor */
drivers/net/ethernet/microchip/lan743x_main.c line 1370
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ tx_descriptor->data1 =0 ; + tx_descriptor->data2 =0 ; + tx_descriptor->data3 =0 ; + buffer_info->skb =NULL ; + buffer_info->dma_ptr =0 ; + buffer_info->buffer_length =0 ; + buffer_info->flags |=TX_BUFFER_INFO_FLAG_ACTIVE ; + tx->frame_data0 = (frame_length &TX_DESC_DATA0_EXT_PAY_LENGTH_MASK_ ) | +TX_DESC_DATA0_DTYPE_EXT_ | +TX_DESC_DATA0_EXT_LSO_ ;
And here again.
Quoted 105 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +105
-0+ +/* data0 will be programmed in one of other frame assembler functions */ +} + +static int lan743x_tx_frame_add_fragment (struct lan743x_tx *tx, +const struct skb_frag_struct *fragment, +unsigned int frame_length) +{ +/* called only from within lan743x_tx_xmit_frame +* assuming tx->ring_lock has already been acquired +*/ +struct lan743x_tx_descriptor *tx_descriptor =NULL ; +struct lan743x_tx_buffer_info *buffer_info =NULL ; +struct lan743x_adapter *adapter = tx->adapter; +struct device *dev = &adapter->pci.pdev->dev; +unsigned int fragment_length =0 ; +dma_addr_t dma_ptr; + + fragment_length =skb_frag_size (fragment); +if (!fragment_length) +return 0 ; + +/* wrap up previous descriptor */ + tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; + tx_descriptor->data0 = tx->frame_data0; + +/* move to next descriptor */ + tx->frame_tail =lan743x_tx_next_index (tx, tx->frame_tail); + tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; + buffer_info = &tx->buffer_info[tx->frame_tail]; + dma_ptr =skb_frag_dma_map (dev, fragment, +0 , fragment_length, +DMA_TO_DEVICE ); +if (dma_mapping_error (dev, dma_ptr)) { +int desc_index; + +/* cleanup all previously setup descriptors */ + desc_index = tx->frame_first; +while (desc_index != tx->frame_tail) { +lan743x_tx_release_desc (tx, desc_index, true); + desc_index =lan743x_tx_next_index (tx, desc_index); + } +dma_wmb (); + tx->frame_flags &= ~TX_FRAME_FLAG_IN_PROGRESS ; + tx->frame_first =0 ; + tx->frame_data0 =0 ; + tx->frame_tail =0 ; +return -ENOMEM ; + } + tx_descriptor->data1 =DMA_ADDR_LOW32 (dma_ptr); + tx_descriptor->data2 =DMA_ADDR_HIGH32 (dma_ptr); + tx_descriptor->data3 = (frame_length <<16 ) & +TX_DESC_DATA3_FRAME_LENGTH_MSS_MASK_ ; + buffer_info->skb =NULL ; + buffer_info->dma_ptr = dma_ptr; + buffer_info->buffer_length = fragment_length; + buffer_info->flags |=TX_BUFFER_INFO_FLAG_ACTIVE ; + buffer_info->flags |=TX_BUFFER_INFO_FLAG_SKB_FRAGMENT ; + tx->frame_data0 = (fragment_length &TX_DESC_DATA0_BUF_LENGTH_MASK_ ) | +TX_DESC_DATA0_DTYPE_DATA_ | +TX_DESC_DATA0_FCS_ ; + +/* data0 will be programmed in one of other frame assembler functions */ +return 0 ; +} + +static void lan743x_tx_frame_end (struct lan743x_tx *tx, +struct sk_buff *skb, +bool ignore_sync) +{ +/* called only from within lan743x_tx_xmit_frame +* assuming tx->ring_lock has already been acquired +*/ +struct lan743x_tx_descriptor *tx_descriptor =NULL ; +struct lan743x_tx_buffer_info *buffer_info =NULL ; +struct lan743x_adapter *adapter = tx->adapter; +u32 tx_tail_flags =0 ; + +/* wrap up previous descriptor */ + tx->frame_data0 |=TX_DESC_DATA0_LS_ ; + tx->frame_data0 |=TX_DESC_DATA0_IOC_ ; + tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; + buffer_info = &tx->buffer_info[tx->frame_tail]; + buffer_info->skb = skb; +if (ignore_sync) + buffer_info->flags |=TX_BUFFER_INFO_FLAG_IGNORE_SYNC ; + tx_descriptor->data0 = tx->frame_data0; + tx->frame_tail =lan743x_tx_next_index (tx, tx->frame_tail); + tx->last_tail = tx->frame_tail; +dma_wmb (); +if (tx->vector_flags &LAN743X_VECTOR_FLAG_VECTOR_ENABLE_AUTO_SET ) + tx_tail_flags |=TX_TAIL_SET_TOP_INT_VEC_EN_ ; +if (tx->vector_flags &LAN743X_VECTOR_FLAG_SOURCE_ENABLE_AUTO_SET ) + tx_tail_flags |=TX_TAIL_SET_DMAC_INT_EN_ | +TX_TAIL_SET_TOP_INT_EN_ ; +lan743x_csr_write (adapter,TX_TAIL (tx->channel_number), + tx_tail_flags | tx->frame_tail); + tx->frame_flags &= ~TX_FRAME_FLAG_IN_PROGRESS ; +} + +static netdev_tx_t lan743x_tx_xmit_frame (struct lan743x_tx *tx, +struct sk_buff *skb) +{ +int required_number_of_descriptors =0 ; +unsigned int start_frame_length =0 ;
drivers/net/ethernet/microchip/lan743x_main.c line 1485
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+unsigned int frame_length =0 ; +unsigned int head_length =0 ; +unsigned long irq_flags =0 ; +bool ignore_sync = false; +int nr_frags =0 ; +bool gso = false; +int j; + +spin_lock_irqsave (&tx->ring_lock, irq_flags); + required_number_of_descriptors =lan743x_tx_get_desc_cnt (tx, skb);
This can certainly execute outside of the spinlock
drivers/net/ethernet/microchip/lan743x_main.c line 1487
Quoted 2 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +2
-0+if (required_number_of_descriptors > +lan743x_tx_get_avail_desc (tx)) {
This one, probably not.
drivers/net/ethernet/microchip/lan743x_main.c line 1493
Quoted 6 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +6
-0+if (required_number_of_descriptors > (tx->ring_size -1 )) { +dev_kfree_skb (skb); + }else { +/* save to overflow buffer */ + tx->overflow_skb = skb; +netif_stop_queue (tx->adapter->netdev);
What is an overflow SKB?
[snip]
drivers/net/ethernet/microchip/lan743x_main.c line 2445
Quoted 3 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +3
-0+static struct net_device_stats *lan743x_netdev_get_stats (struct net_device *nd) +{ +struct lan743x_adapter *adapter =netdev_priv (nd);
64-bit statistics please.
Signature · 1 line
Florian
[email protected]
maintainerRE: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
Hi Florian,
Thanks for your review. I have the following questions/comments.
Quoted 6 lines · Bryan Whitehead
Quoted 4 lines
Add main source files for new lan743x driver.
Signed-off-by Bryan Whitehead <[email protected]>---
Quoted 6 lines
Quoted 1 line
+lan743x-objs := lan743x_main.o
Should we assume that you have additional object files you would like to contribute at a later point? If that is the case, this is fine, if this is going to be only file of this driver, consider renaming it so you don't even have to have this lan743x-objs line at all.
I am planning to add additional source files later. At the very least there will be a lan743x_ethtool.o, and a lan743x_ptp.o. I didn't want to have to change the name of the main file later, so I gave it the expected name now.
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c line 24
Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +5
-0+ +static void lan743x_pci_cleanup (struct lan743x_adapter *adapter) { +struct lan743x_pci *pci = &adapter->pci; + +if (pci->init_flags &INIT_FLAG_PCI_REGIONS_REQUESTED ) {There is a pattern throughout the driver of maintaining flags to track what was initialized and what was not, do you really need that, or can you check for specific book keeping private information. Maintaining flags is error prone and requires you to keep adding new ones, that does not really scale.
Ok, but it seems to me that what I have is an example of "specific book keeping private information". Can you clarify the style you prefer?
In cases of allocation where I can just compare a pointer to null, I can easily remove the flags. But in other cases I need a record of which steps completed in order to clean up properly. In cases where I need some sort of a flag would you prefer I avoid a bit mask, and have a standalone variable for each flag?
[snip]
Quoted 11 lines
drivers/net/ethernet/microchip/lan743x_main.c line 194
Quoted 6 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +6
-0+ dmac_int_en &= ioc_bit; + dmac_int_sts &= dmac_int_en; +if (dmac_int_sts & ioc_bit) { +tasklet_schedule (&tx->tx_isr_bottom_half); + enable_flag =0 ;/* tasklet will re-enable later */ + }Consider migrating your TX buffer reclamation to a NAPI context. If you have one TX queue and one RX, the same NAPI context can be re-used, if you have separate RX/TX queues, you may create a NAPI context per RX/TX pair, or you may create separate NAPI contexts per TX queues and RX queues.
This may take some time to refactor, But I will see what I can do.
[snip]
Quoted 27 lines
Quoted 16 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +16
-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) { + ret = -EIO ; + goto clean_up; + } + ret =phy_connect_direct (netdev, phydev, + lan743x_phy_link_status_change, +PHY_INTERFACE_MODE_GMII );drivers/net/ethernet/microchip/lan743x_main.c
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+if (ret) + goto clean_up; + phy->flags |=PHY_FLAG_ATTACHED ; + +/* MAC doesn't support 1000T Half */ + phydev->supported &= ~SUPPORTED_1000baseT_Half; + +/* support both flow controls */ + phy->fc_request_control = (FLOW_CTRL_RX |FLOW_CTRL_TX ); + phydev->advertising &= ~(ADVERTISED_Pause |
ADVERTISED_Asym_Pause);
Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1005
Quoted 3 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +3
-0+ 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;No driver does things like that, that appears to be really wrong.
Can you clarify? What is wrong and how should it be?
[snip]
Quoted 19 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_dmac_init (struct lan743x_adapter *adapter) { +struct lan743x_dmac *dmac = &adapter->dmac; +u32 data =0 ; + + dmac->flags =0 ; + dmac->descriptor_spacing =DEFAULT_DMA_DESCRIPTOR_SPACING ; +lan743x_csr_write (adapter,DMAC_CMD ,DMAC_CMD_SWR_ ); + lan743x_csr_wait_for_bit(adapter, DMAC_CMD,
DMAC_CMD_SWR_,Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ 0, 1000, 20000, 100); +switch (dmac->descriptor_spacing) { +case DMA_DESCRIPTOR_SPACING_16 : + data =DMAC_CFG_MAX_DSPACE_16_ ; +break ; +case DMA_DESCRIPTOR_SPACING_32 : + data =DMAC_CFG_MAX_DSPACE_32_ ; +break ; +case DMA_DESCRIPTOR_SPACING_64 : + data =DMAC_CFG_MAX_DSPACE_64_ ;
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1115
Quoted 6 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +6
-0+break ; +case DMA_DESCRIPTOR_SPACING_128 : + data =DMAC_CFG_MAX_DSPACE_128_ ; +break ; +default : +return -EPERM ;
-EINVALmaybe?
I think -EPERM is more appropriate because it reflects an unresolvable error. In other words the platform is in compatible with the device. Would you prefer I use a preprocessor error instead, such as
#if invalid_setting
#error incompatible setting
#endif
Quoted 11 lines
[snip]
drivers/net/ethernet/microchip/lan743x_main.c line 1240
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +4
-0+ +done: +memset (buffer_info,0 ,sizeof (*buffer_info)); +memset (descriptor,0 ,sizeof (*descriptor));You are likely missing barriers here, what guarantees that the
buffer_infoand descriptor are going to be properly maintained in a non-cache coherent architecture?
I believe a memory barrier is only necessary just before the device is likely to access that memory. The device is only allowed to access that memory after a write to the TX_TAIL register.
This step happens in lan743x_tx_frame_end, and there is a dma_wmb just before it.
If possible I prefer to avoid unnecessary barriers so the hardware can optimize bus traffic better.
Do you agree, or am I misunderstanding something?
[snip]
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ +static void lan743x_tx_release_all_descriptors (struct lan743x_tx *tx) +{ +u32 original_head =0 ; + + original_head = tx->last_head; +do { +lan743x_tx_release_desc (tx, tx->last_head, true); + tx->last_head =lan743x_tx_next_index (tx, tx->last_head); + }while (tx->last_head != original_head);
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1268
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +4
-0+memset (tx->ring_cpu_ptr,0 , +sizeof (*tx->ring_cpu_ptr) * (tx->ring_size)); +memset (tx->buffer_info,0 , +sizeof (*tx->buffer_info) * (tx->ring_size));This is coherent memory, but you still need to prevent possible re-orderings, so you need at least a write barrier to guarantee all pending writes are completed. Likely you won't ever see this as a problem on x86 platforms.
Again, the driver is not permitting the device to access the memory yet, so I think a memory barrier is unnecessary.
Do you agree?
[snip]
Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +24
-0+ tx->frame_flags |=TX_FRAME_FLAG_IN_PROGRESS ; + tx->frame_first = tx->last_tail; + tx->frame_tail = tx->frame_first; + tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; + buffer_info = &tx->buffer_info[tx->frame_tail]; + dma_ptr =dma_map_single (dev, first_buffer, first_buffer_length, +DMA_TO_DEVICE ); +if (dma_mapping_error (dev, dma_ptr)) +return -ENOMEM ; + tx_descriptor->data1 =DMA_ADDR_LOW32 (dma_ptr); + tx_descriptor->data2 =DMA_ADDR_HIGH32 (dma_ptr); + tx_descriptor->data3 = (frame_length <<16 ) & +TX_DESC_DATA3_FRAME_LENGTH_MSS_MASK_ ; + buffer_info->skb =NULL ; + buffer_info->dma_ptr = dma_ptr; + buffer_info->buffer_length = first_buffer_length; + buffer_info->flags |=TX_BUFFER_INFO_FLAG_ACTIVE ; + tx->frame_data0 = (first_buffer_length & +TX_DESC_DATA0_BUF_LENGTH_MASK_ ) | +TX_DESC_DATA0_DTYPE_DATA_ | +TX_DESC_DATA0_FS_ | +TX_DESC_DATA0_FCS_ ; +if (check_sum) + tx->frame_data0 |= TX_DESC_DATA0_ICE_ |
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c
Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +5
-0+TX_DESC_DATA0_IPE_ | +TX_DESC_DATA0_TPE_ ; + +/* data0 will be programmed in one of other frame assembler +functions */ You again need some sort of write barrier here to guarantee ordering and make sure the descriptors/buffer_info are properly written.
Again, the driver is not permitting the device to access the memory yet, so I think a memory barrier is unnecessary.
Do you agree?
Quoted 29 lines
Quoted 18 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +18
-0+static void lan743x_tx_frame_add_lso (struct lan743x_tx *tx, +unsigned int frame_length) +{ +/* called only from within lan743x_tx_xmit_frame. +* assuming tx->ring_lock has already been acquired. +*/ +struct lan743x_tx_descriptor *tx_descriptor =NULL ; +struct lan743x_tx_buffer_info *buffer_info =NULL ; + +/* wrap up previous descriptor */ + tx->frame_data0 |=TX_DESC_DATA0_EXT_ ; + tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; + tx_descriptor->data0 = tx->frame_data0; + +/* move to next descriptor */ + tx->frame_tail =lan743x_tx_next_index (tx, tx->frame_tail); + tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; + buffer_info = &tx->buffer_info[tx->frame_tail];drivers/net/ethernet/microchip/lan743x_main.c
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+ +/* add extension descriptor */ + tx_descriptor->data1 =0 ; + tx_descriptor->data2 =0 ; + tx_descriptor->data3 =0 ; + buffer_info->skb =NULL ; + buffer_info->dma_ptr =0 ; + buffer_info->buffer_length =0 ; + buffer_info->flags |=TX_BUFFER_INFO_FLAG_ACTIVE ; + tx->frame_data0 = (frame_length &
TX_DESC_DATA0_EXT_PAY_LENGTH_MASK_) |
Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1370
Quoted 2 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +2
-0+TX_DESC_DATA0_DTYPE_EXT_ | +TX_DESC_DATA0_EXT_LSO_ ;And here again.
Again, the driver is not permitting the device to access the memory yet, so I think a memory barrier is unnecessary.
Do you agree?
[snip]
Quoted 21 lines
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+static void lan743x_tx_frame_end (struct lan743x_tx *tx, +struct sk_buff *skb, +bool ignore_sync) +{ +/* called only from within lan743x_tx_xmit_frame +* assuming tx->ring_lock has already been acquired +*/ +struct lan743x_tx_descriptor *tx_descriptor =NULL ; +struct lan743x_tx_buffer_info *buffer_info =NULL ; +struct lan743x_adapter *adapter = tx->adapter;drivers/net/ethernet/microchip/lan743x_main.c
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+u32 tx_tail_flags =0 ; + +/* wrap up previous descriptor */ + tx->frame_data0 |=TX_DESC_DATA0_LS_ ; + tx->frame_data0 |=TX_DESC_DATA0_IOC_ ; + tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; + buffer_info = &tx->buffer_info[tx->frame_tail]; + buffer_info->skb = skb; +if (ignore_sync) + buffer_info->flags |=
TX_BUFFER_INFO_FLAG_IGNORE_SYNC;
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1460
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +4
-0+ tx_descriptor->data0 = tx->frame_data0; + tx->frame_tail =lan743x_tx_next_index (tx, tx->frame_tail); + tx->last_tail = tx->frame_tail; +dma_wmb ();
Here is the barrier
Quoted 9 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ if (tx->vector_flags &
LAN743X_VECTOR_FLAG_VECTOR_ENABLE_AUTO_SET)Review
Quoted 2 lines
(quoted diff) +2
-0+ tx_tail_flags |= TX_TAIL_SET_TOP_INT_VEC_EN_; + if (tx->vector_flags &
LAN743X_VECTOR_FLAG_SOURCE_ENABLE_AUTO_SET)drivers/net/ethernet/microchip/lan743x_main.c line 1467
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +4
-0+ tx_tail_flags |=TX_TAIL_SET_DMAC_INT_EN_ | +TX_TAIL_SET_TOP_INT_EN_ ; +lan743x_csr_write (adapter,TX_TAIL (tx->channel_number), + tx_tail_flags | tx->frame_tail);
Here is TX_TAIL write that permits the device to access descriptor ring And buffers.
Quoted 20 lines
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +7
-0+ tx->frame_flags &= ~TX_FRAME_FLAG_IN_PROGRESS ; } + +static netdev_tx_t lan743x_tx_xmit_frame (struct lan743x_tx *tx, +struct sk_buff *skb) +{ +int required_number_of_descriptors =0 ; +unsigned int start_frame_length =0 ;drivers/net/ethernet/microchip/lan743x_main.c
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +10
-0+unsigned int frame_length =0 ; +unsigned int head_length =0 ; +unsigned long irq_flags =0 ; +bool ignore_sync = false; +int nr_frags =0 ; +bool gso = false; +int j; + +spin_lock_irqsave (&tx->ring_lock, irq_flags); + required_number_of_descriptors = lan743x_tx_get_desc_cnt(tx,skb);
Quoted 1 line
This can certainly execute outside of the spinlock
Will move
Quoted 6 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1487
Quoted 3 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +2
-0+if (required_number_of_descriptors > +lan743x_tx_get_avail_desc (tx)) {This one, probably not.
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c line 1493
Quoted 6 lines
drivers/net/ethernet/microchip/lan743x_main.c new file +6
-0+if (required_number_of_descriptors > (tx->ring_size -1 )) { +dev_kfree_skb (skb); + }else { +/* save to overflow buffer */ + tx->overflow_skb = skb; +netif_stop_queue (tx->adapter->netdev);What is an overflow SKB?
If the descriptor ring does not have enough descriptors for the skb then instead of dropping it, the queue is stopped, and the skb is stored in the overflow_skb.
When ring space is restored inside lan743x_tx_isr_bottom_half, the transmission of the overflow_skb is retried before the netif_wake_queue is called.
Since skb's may require an unknown number of descriptors this mechanism will stop the queue on the fly. But store it for retransmission later.
Quoted 8 lines
[snip]
Review
Quoted 3 lines
(quoted diff) +3
-0+static struct net_device_stats *lan743x_netdev_get_stats(struct +net_device *nd) { + struct lan743x_adapter *adapter = netdev_priv(nd);64-bit statistics please.
Will do.
Regards,
Bryan
Re: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 7 lines
Ok, but it seems to me that what I have is an example of "specific book keeping private information". Can you clarify the style you prefer?
In cases of allocation where I can just compare a pointer to null, I can easily remove the flags. But in other cases I need a record of which steps completed in order to clean up properly. In cases where I need some sort of a flag would you prefer I avoid a bit mask, and have a standalone variable for each flag?
Hi Bryan
Often you know some thing has been done, because if it had not been done, you would of bombed out with an error. In the release function you can assume everything done in probe has been done, otherwise the probe would not be successful. In close, you can assume everything done in open was successful, otherwise the open would of failed....
So probe does not need any flags. open does not need any flags.
Andrew
[email protected]
maintainerRE: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 17 lines
Quoted 7 lines
Ok, but it seems to me that what I have is an example of "specific book keeping private information". Can you clarify the style you prefer?
In cases of allocation where I can just compare a pointer to null, I can easily remove the flags. But in other cases I need a record of which steps completed in order to clean up properly. In cases where I need some sort of a flag would you prefer I avoid a bit mask, and have a
standalone variable for each flag?
Hi Bryan
Often you know some thing has been done, because if it had not been done, you would of bombed out with an error. In the release function you can assume everything done in probe has been done, otherwise the probe would not be successful. In close, you can assume everything done in open was successful, otherwise the open would of failed....
Quoted 3 lines
So probe does not need any flags. open does not need any flags.
Andrew
Hi Andrew,
OK, so there are two cases where clean-up is necessary. One is through call to remove or ndo_stop. For these cases I agree with you. Everything must have been set up correctly, so everything should be cleaned up, no flags required.
But the other case is when things fail anywhere during probe, or open. In these cases things are partially initialized and I assumed I needed to clean up whatever was initialized successfully before returning an error. I used flags so I could share a common clean up function for all possible error cases as well as the fully successful case. Without flags I would need to customize a clean-up sequence for each possible error point.
Or are you suggesting that I don't need to worry about clean up if an error happens during probe or open?
Bryan
Re: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 7 lines
But the other case is when things fail anywhere during probe, or open. In these cases things are partially initialized and I assumed I needed to clean up whatever was initialized successfully before returning an error. I used flags so I could share a common clean up function for all possible error cases as well as the fully successful case. Without flags I would need to customize a clean-up sequence for each possible error point.
Hi Bryan
It is good to look at other drivers and see how they work. Ideally, your driver wants to look similar to all other drivers, so making the maintenance easier.
You will find that most drivers have a set of goto statements for error handling, which jump to the end of the function, and do cleanup. No flags are maintained.
Andrew
[email protected]
maintainerRE: [PATCH v2 net-next 1/2] lan743x: Add main source files for new lan743x driver
Quoted 10 lines
Hi Bryan
It is good to look at other drivers and see how they work. Ideally, your driver wants to look similar to all other drivers, so making the maintenance easier.
You will find that most drivers have a set of goto statements for error handling, which jump to the end of the function, and do cleanup. No flags are maintained.
Andrew
Thanks Andrew,
I understand now, I'll work on it.
Bryan
Bryan Whitehead
maintainerPATCH v2 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
@@ -9149,6 +9149,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