This allows incrementing the correct timeout statistic without any mess. Down the road, devices can learn to reset just the specific queue. The patch was generated with the following script: use strict; use warnings; our $^I = '.bak'; my @work = ( ["arch/m68k/emu/nfeth.c", "nfeth_tx_timeout"], ["arch/um/drivers/net_kern.c", "uml_net_tx_timeout"], ["arch/um/drivers/vector_kern.c", "vector_net_tx_timeout"], ["arch/xtensa/platforms/iss/network.c", "iss_net_tx_timeout"], ["drivers/char/pcmcia/synclink_cs.c", "hdlcdev_tx_timeout"], ["drivers/infiniband/ulp/ipoib/ipoib_main.c", "ipoib_timeout"], ["drivers/infiniband/ulp/ipoib/ipoib_main.c", "ipoib_timeout"], ["drivers/message/fusion/mptlan.c", "mpt_lan_tx_timeout"], ["drivers/misc/sgi-xp/xpnet.c", "xpnet_dev_tx_timeout"], ["drivers/net/appletalk/cops.c", "cops_timeout"], ["drivers/net/arcnet/arcdevice.h", "arcnet_timeout"], ["drivers/net/arcnet/arcnet.c", "arcnet_timeout"], ["drivers/net/arcnet/com20020.c", "arcnet_timeout"], ["drivers/net/ethernet/3com/3c509.c", "el3_tx_timeout"], ["drivers/net/ethernet/3com/3c515.c", "corkscrew_timeout"], ["drivers/net/ethernet/3com/3c574_cs.c", "el3_tx_timeout"], ["drivers/net/ethernet/3com/3c589_cs.c", "el3_tx_timeout"], ["drivers/net/ethernet/3com/3c59x.c", "vortex_tx_timeout"], ["drivers/net/ethernet/3com/3c59x.c", "vortex_tx_timeout"], ["drivers/net/ethernet/3com/typhoon.c", "typhoon_tx_timeout"], ["drivers/net/ethernet/8390/8390.h", "ei_tx_timeout"], ["drivers/net/ethernet/8390/8390.h", "eip_tx_timeout"], ["drivers/net/ethernet/8390/8390.c", "ei_tx_timeout"], ["drivers/net/ethernet/8390/8390p.c", "eip_tx_timeout"], ["drivers/net/ethernet/8390/ax88796.c", "ax_ei_tx_timeout"], ["drivers/net/ethernet/8390/axnet_cs.c", "axnet_tx_timeout"], ["drivers/net/ethernet/8390/etherh.c", "__ei_tx_timeout"], ["drivers/net/ethernet/8390/hydra.c", "__ei_tx_timeout"], ["drivers/net/ethernet/8390/mac8390.c", "__ei_tx_timeout"], ["drivers/net/ethernet/8390/mcf8390.c", "__ei_tx_timeout"], ["drivers/net/ethernet/8390/lib8390.c", "__ei_tx_timeout"], ["drivers/net/ethernet/8390/ne2k-pci.c", "ei_tx_timeout"], ["drivers/net/ethernet/8390/pcnet_cs.c", "ei_tx_timeout"], ["drivers/net/ethernet/8390/smc-ultra.c", "ei_tx_timeout"], ["drivers/net/ethernet/8390/wd.c", "ei_tx_timeout"], ["drivers/net/ethernet/8390/zorro8390.c", "__ei_tx_timeout"], ["drivers/net/ethernet/adaptec/starfire.c", "tx_timeout"], ["drivers/net/ethernet/agere/et131x.c", "et131x_tx_timeout"], ["drivers/net/ethernet/allwinner/sun4i-emac.c", "emac_timeout"], ["drivers/net/ethernet/alteon/acenic.c", "ace_watchdog"], ["drivers/net/ethernet/amazon/ena/ena_netdev.c", "ena_tx_timeout"], ["drivers/net/ethernet/amd/7990.h", "lance_tx_timeout"], ["drivers/net/ethernet/amd/7990.c", "lance_tx_timeout"], ["drivers/net/ethernet/amd/a2065.c", "lance_tx_timeout"], ["drivers/net/ethernet/amd/am79c961a.c", "am79c961_timeout"], ["drivers/net/ethernet/amd/amd8111e.c", "amd8111e_tx_timeout"], ["drivers/net/ethernet/amd/ariadne.c", "ariadne_tx_timeout"], ["drivers/net/ethernet/amd/atarilance.c", "lance_tx_timeout"], ["drivers/net/ethernet/amd/au1000_eth.c", "au1000_tx_timeout"], ["drivers/net/ethernet/amd/declance.c", "lance_tx_timeout"], ["drivers/net/ethernet/amd/lance.c", "lance_tx_timeout"], ["drivers/net/ethernet/amd/mvme147.c", "lance_tx_timeout"], ["drivers/net/ethernet/amd/ni65.c", "ni65_timeout"], ["drivers/net/ethernet/amd/nmclan_cs.c", "mace_tx_timeout"], ["drivers/net/ethernet/amd/pcnet32.c", "pcnet32_tx_timeout"], ["drivers/net/ethernet/amd/sunlance.c", "lance_tx_timeout"], ["drivers/net/ethernet/amd/xgbe/xgbe-drv.c", "xgbe_tx_timeout"], ["drivers/net/ethernet/apm/xgene-v2/main.c", "xge_timeout"], ["drivers/net/ethernet/apm/xgene/xgene_enet_main.c", "xgene_enet_timeout"], ["drivers/net/ethernet/apple/macmace.c", "mace_tx_timeout"], ["drivers/net/ethernet/atheros/ag71xx.c", "ag71xx_tx_timeout"], ["drivers/net/ethernet/atheros/alx/main.c", "alx_tx_timeout"], ["drivers/net/ethernet/atheros/atl1c/atl1c_main.c", "atl1c_tx_timeout"], ["drivers/net/ethernet/atheros/atl1e/atl1e_main.c", "atl1e_tx_timeout"], ["drivers/net/ethernet/atheros/atlx/atl.c", "atlx_tx_timeout"], ["drivers/net/ethernet/atheros/atlx/atl1.c", "atlx_tx_timeout"], ["drivers/net/ethernet/atheros/atlx/atl2.c", "atl2_tx_timeout"], ["drivers/net/ethernet/broadcom/b44.c", "b44_tx_timeout"], ["drivers/net/ethernet/broadcom/bcmsysport.c", "bcm_sysport_tx_timeout"], ["drivers/net/ethernet/broadcom/bnx2.c", "bnx2_tx_timeout"], ["drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h", "bnx2x_tx_timeout"], ["drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c", "bnx2x_tx_timeout"], ["drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c", "bnx2x_tx_timeout"], ["drivers/net/ethernet/broadcom/bnxt/bnxt.c", "bnxt_tx_timeout"], ["drivers/net/ethernet/broadcom/genet/bcmgenet.c", "bcmgenet_timeout"], ["drivers/net/ethernet/broadcom/sb1250-mac.c", "sbmac_tx_timeout"], ["drivers/net/ethernet/broadcom/tg3.c", "tg3_tx_timeout"], ["drivers/net/ethernet/calxeda/xgmac.c", "xgmac_tx_timeout"], ["drivers/net/ethernet/cavium/liquidio/lio_main.c", "liquidio_tx_timeout"], ["drivers/net/ethernet/cavium/liquidio/lio_vf_main.c", "liquidio_tx_timeout"], ["drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c", "lio_vf_rep_tx_timeout"], ["drivers/net/ethernet/cavium/thunder/nicvf_main.c", "nicvf_tx_timeout"], ["drivers/net/ethernet/cirrus/cs89x0.c", "net_timeout"], ["drivers/net/ethernet/cisco/enic/enic_main.c", "enic_tx_timeout"], ["drivers/net/ethernet/cisco/enic/enic_main.c", "enic_tx_timeout"], ["drivers/net/ethernet/cortina/gemini.c", "gmac_tx_timeout"], ["drivers/net/ethernet/davicom/dm9000.c", "dm9000_timeout"], ["drivers/net/ethernet/dec/tulip/de2104x.c", "de_tx_timeout"], ["drivers/net/ethernet/dec/tulip/tulip_core.c", "tulip_tx_timeout"], ["drivers/net/ethernet/dec/tulip/winbond-840.c", "tx_timeout"], ["drivers/net/ethernet/dlink/dl2k.c", "rio_tx_timeout"], ["drivers/net/ethernet/dlink/sundance.c", "tx_timeout"], ["drivers/net/ethernet/emulex/benet/be_main.c", "be_tx_timeout"], ["drivers/net/ethernet/ethoc.c", "ethoc_tx_timeout"], ["drivers/net/ethernet/faraday/ftgmac100.c", "ftgmac100_tx_timeout"], ["drivers/net/ethernet/fealnx.c", "fealnx_tx_timeout"], ["drivers/net/ethernet/freescale/dpaa/dpaa_eth.c", "dpaa_tx_timeout"], ["drivers/net/ethernet/freescale/fec_main.c", "fec_timeout"], ["drivers/net/ethernet/freescale/fec_mpc52xx.c", "mpc52xx_fec_tx_timeout"], ["drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c", "fs_timeout"], ["drivers/net/ethernet/freescale/gianfar.c", "gfar_timeout"], ["drivers/net/ethernet/freescale/ucc_geth.c", "ucc_geth_timeout"], ["drivers/net/ethernet/fujitsu/fmvj18x_cs.c", "fjn_tx_timeout"], ["drivers/net/ethernet/google/gve/gve_main.c", "gve_tx_timeout"], ["drivers/net/ethernet/hisilicon/hip04_eth.c", "hip04_timeout"], ["drivers/net/ethernet/hisilicon/hix5hd2_gmac.c", "hix5hd2_net_timeout"], ["drivers/net/ethernet/hisilicon/hns/hns_enet.c", "hns_nic_net_timeout"], ["drivers/net/ethernet/hisilicon/hns3/hns3_enet.c", "hns3_nic_net_timeout"], ["drivers/net/ethernet/huawei/hinic/hinic_main.c", "hinic_tx_timeout"], ["drivers/net/ethernet/i825xx/82596.c", "i596_tx_timeout"], ["drivers/net/ethernet/i825xx/ether1.c", "ether1_timeout"], ["drivers/net/ethernet/i825xx/lib82596.c", "i596_tx_timeout"], ["drivers/net/ethernet/i825xx/sun3_82586.c", "sun3_82586_timeout"], ["drivers/net/ethernet/ibm/ehea/ehea_main.c", "ehea_tx_watchdog"], ["drivers/net/ethernet/ibm/emac/core.c", "emac_tx_timeout"], ["drivers/net/ethernet/ibm/emac/core.c", "emac_tx_timeout"], ["drivers/net/ethernet/ibm/ibmvnic.c", "ibmvnic_tx_timeout"], ["drivers/net/ethernet/intel/e100.c", "e100_tx_timeout"], ["drivers/net/ethernet/intel/e1000/e1000_main.c", "e1000_tx_timeout"], ["drivers/net/ethernet/intel/e1000e/netdev.c", "e1000_tx_timeout"], ["drivers/net/ethernet/intel/fm10k/fm10k_netdev.c", "fm10k_tx_timeout"], ["drivers/net/ethernet/intel/i40e/i40e_main.c", "i40e_tx_timeout"], ["drivers/net/ethernet/intel/iavf/iavf_main.c", "iavf_tx_timeout"], ["drivers/net/ethernet/intel/ice/ice_main.c", "ice_tx_timeout"], ["drivers/net/ethernet/intel/ice/ice_main.c", "ice_tx_timeout"], ["drivers/net/ethernet/intel/igb/igb_main.c", "igb_tx_timeout"], ["drivers/net/ethernet/intel/igbvf/netdev.c", "igbvf_tx_timeout"], ["drivers/net/ethernet/intel/ixgb/ixgb_main.c", "ixgb_tx_timeout"], ["drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c", "adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev);"], ["drivers/net/ethernet/intel/ixgbe/ixgbe_main.c", "ixgbe_tx_timeout"], ["drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c", "ixgbevf_tx_timeout"], ["drivers/net/ethernet/jme.c", "jme_tx_timeout"], ["drivers/net/ethernet/korina.c", "korina_tx_timeout"], ["drivers/net/ethernet/lantiq_etop.c", "ltq_etop_tx_timeout"], ["drivers/net/ethernet/marvell/mv643xx_eth.c", "mv643xx_eth_tx_timeout"], ["drivers/net/ethernet/marvell/pxa168_eth.c", "pxa168_eth_tx_timeout"], ["drivers/net/ethernet/marvell/skge.c", "skge_tx_timeout"], ["drivers/net/ethernet/marvell/sky2.c", "sky2_tx_timeout"], ["drivers/net/ethernet/marvell/sky2.c", "sky2_tx_timeout"], ["drivers/net/ethernet/mediatek/mtk_eth_soc.c", "mtk_tx_timeout"], ["drivers/net/ethernet/mellanox/mlx4/en_netdev.c", "mlx4_en_tx_timeout"], ["drivers/net/ethernet/mellanox/mlx4/en_netdev.c", "mlx4_en_tx_timeout"], ["drivers/net/ethernet/mellanox/mlx5/core/en_main.c", "mlx5e_tx_timeout"], ["drivers/net/ethernet/micrel/ks8842.c", "ks8842_tx_timeout"], ["drivers/net/ethernet/micrel/ksz884x.c", "netdev_tx_timeout"], ["drivers/net/ethernet/microchip/enc28j60.c", "enc28j60_tx_timeout"], ["drivers/net/ethernet/microchip/encx24j600.c", "encx24j600_tx_timeout"], ["drivers/net/ethernet/natsemi/sonic.h", "sonic_tx_timeout"], ["drivers/net/ethernet/natsemi/sonic.c", "sonic_tx_timeout"], ["drivers/net/ethernet/natsemi/jazzsonic.c", "sonic_tx_timeout"], ["drivers/net/ethernet/natsemi/macsonic.c", "sonic_tx_timeout"], ["drivers/net/ethernet/natsemi/natsemi.c", "ns_tx_timeout"], ["drivers/net/ethernet/natsemi/ns83820.c", "ns83820_tx_timeout"], ["drivers/net/ethernet/natsemi/xtsonic.c", "sonic_tx_timeout"], ["drivers/net/ethernet/neterion/s2io.h", "s2io_tx_watchdog"], ["drivers/net/ethernet/neterion/s2io.c", "s2io_tx_watchdog"], ["drivers/net/ethernet/neterion/vxge/vxge-main.c", "vxge_tx_watchdog"], ["drivers/net/ethernet/netronome/nfp/nfp_net_common.c", "nfp_net_tx_timeout"], ["drivers/net/ethernet/nvidia/forcedeth.c", "nv_tx_timeout"], ["drivers/net/ethernet/nvidia/forcedeth.c", "nv_tx_timeout"], ["drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c", "pch_gbe_tx_timeout"], ["drivers/net/ethernet/packetengines/hamachi.c", "hamachi_tx_timeout"], ["drivers/net/ethernet/packetengines/yellowfin.c", "yellowfin_tx_timeout"], ["drivers/net/ethernet/pensando/ionic/ionic_lif.c", "ionic_tx_timeout"], ["drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c", "netxen_tx_timeout"], ["drivers/net/ethernet/qlogic/qla3xxx.c", "ql3xxx_tx_timeout"], ["drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c", "qlcnic_tx_timeout"], ["drivers/net/ethernet/qualcomm/emac/emac.c", "emac_tx_timeout"], ["drivers/net/ethernet/qualcomm/qca_spi.c", "qcaspi_netdev_tx_timeout"], ["drivers/net/ethernet/qualcomm/qca_uart.c", "qcauart_netdev_tx_timeout"], ["drivers/net/ethernet/rdc/r6040.c", "r6040_tx_timeout"], ["drivers/net/ethernet/realtek/8139cp.c", "cp_tx_timeout"], ["drivers/net/ethernet/realtek/8139too.c", "rtl8139_tx_timeout"], ["drivers/net/ethernet/realtek/atp.c", "tx_timeout"], ["drivers/net/ethernet/realtek/r8169_main.c", "rtl8169_tx_timeout"], ["drivers/net/ethernet/renesas/ravb_main.c", "ravb_tx_timeout"], ["drivers/net/ethernet/renesas/sh_eth.c", "sh_eth_tx_timeout"], ["drivers/net/ethernet/renesas/sh_eth.c", "sh_eth_tx_timeout"], ["drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c", "sxgbe_tx_timeout"], ["drivers/net/ethernet/seeq/ether3.c", "ether3_timeout"], ["drivers/net/ethernet/seeq/sgiseeq.c", "timeout"], ["drivers/net/ethernet/sfc/efx.c", "efx_watchdog"], ["drivers/net/ethernet/sfc/falcon/efx.c", "ef4_watchdog"], ["drivers/net/ethernet/sgi/ioc3-eth.c", "ioc3_timeout"], ["drivers/net/ethernet/sgi/meth.c", "meth_tx_timeout"], ["drivers/net/ethernet/silan/sc92031.c", "sc92031_tx_timeout"], ["drivers/net/ethernet/sis/sis190.c", "sis190_tx_timeout"], ["drivers/net/ethernet/sis/sis900.c", "sis900_tx_timeout"], ["drivers/net/ethernet/smsc/epic100.c", "epic_tx_timeout"], ["drivers/net/ethernet/smsc/smc911x.c", "smc911x_timeout"], ["drivers/net/ethernet/smsc/smc9194.c", "smc_timeout"], ["drivers/net/ethernet/smsc/smc91c92_cs.c", "smc_tx_timeout"], ["drivers/net/ethernet/smsc/smc91x.c", "smc_timeout"], ["drivers/net/ethernet/stmicro/stmmac/stmmac_main.c", "stmmac_tx_timeout"], ["drivers/net/ethernet/sun/cassini.c", "cas_tx_timeout"], ["drivers/net/ethernet/sun/ldmvsw.c", "sunvnet_tx_timeout_common"], ["drivers/net/ethernet/sun/niu.c", "niu_tx_timeout"], ["drivers/net/ethernet/sun/sunbmac.c", "bigmac_tx_timeout"], ["drivers/net/ethernet/sun/sungem.c", "gem_tx_timeout"], ["drivers/net/ethernet/sun/sunhme.c", "happy_meal_tx_timeout"], ["drivers/net/ethernet/sun/sunqe.c", "qe_tx_timeout"], ["drivers/net/ethernet/sun/sunvnet.c", "sunvnet_tx_timeout_common"], ["drivers/net/ethernet/sun/sunvnet_common.c", "sunvnet_tx_timeout_common"], ["drivers/net/ethernet/sun/sunvnet_common.h", "sunvnet_tx_timeout_common"], ["drivers/net/ethernet/synopsys/dwc-xlgmac-net.c", "xlgmac_tx_timeout"], ["drivers/net/ethernet/ti/cpmac.c", "cpmac_tx_timeout"], ["drivers/net/ethernet/ti/cpsw.c", "cpsw_ndo_tx_timeout"], ["drivers/net/ethernet/ti/cpsw_priv.c", "cpsw_ndo_tx_timeout"], ["drivers/net/ethernet/ti/cpsw_priv.h", "cpsw_ndo_tx_timeout"], ["drivers/net/ethernet/ti/davinci_emac.c", "emac_dev_tx_timeout"], ["drivers/net/ethernet/ti/netcp_core.c", "netcp_ndo_tx_timeout"], ["drivers/net/ethernet/ti/tlan.c", "tlan_tx_timeout"], ["drivers/net/ethernet/toshiba/ps3_gelic_net.h", "gelic_net_tx_timeout"], ["drivers/net/ethernet/toshiba/ps3_gelic_net.c", "gelic_net_tx_timeout"], ["drivers/net/ethernet/toshiba/ps3_gelic_wireless.c", "gelic_net_tx_timeout"], ["drivers/net/ethernet/toshiba/spider_net.c", "spider_net_tx_timeout"], ["drivers/net/ethernet/toshiba/tc35815.c", "tc35815_tx_timeout"], ["drivers/net/ethernet/via/via-rhine.c", "rhine_tx_timeout"], ["drivers/net/ethernet/wiznet/w5100.c", "w5100_tx_timeout"], ["drivers/net/ethernet/wiznet/w5300.c", "w5300_tx_timeout"], ["drivers/net/ethernet/xilinx/xilinx_emaclite.c", "xemaclite_tx_timeout"], ["drivers/net/ethernet/xircom/xirc2ps_cs.c", "xirc_tx_timeout"], ["drivers/net/fjes/fjes_main.c", "fjes_tx_retry"], ["drivers/net/slip/slip.c", "sl_tx_timeout"], ["include/linux/usb/usbnet.h", "usbnet_tx_timeout"], ["drivers/net/usb/aqc111.c", "usbnet_tx_timeout"], ["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"], ["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"], ["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"], ["drivers/net/usb/ax88172a.c", "usbnet_tx_timeout"], ["drivers/net/usb/ax88179_178a.c", "usbnet_tx_timeout"], ["drivers/net/usb/catc.c", "catc_tx_timeout"], ["drivers/net/usb/cdc_mbim.c", "usbnet_tx_timeout"], ["drivers/net/usb/cdc_ncm.c", "usbnet_tx_timeout"], ["drivers/net/usb/dm9601.c", "usbnet_tx_timeout"], ["drivers/net/usb/hso.c", "hso_net_tx_timeout"], ["drivers/net/usb/int51x1.c", "usbnet_tx_timeout"], ["drivers/net/usb/ipheth.c", "ipheth_tx_timeout"], ["drivers/net/usb/kaweth.c", "kaweth_tx_timeout"], ["drivers/net/usb/lan78xx.c", "lan78xx_tx_timeout"], ["drivers/net/usb/mcs7830.c", "usbnet_tx_timeout"], ["drivers/net/usb/pegasus.c", "pegasus_tx_timeout"], ["drivers/net/usb/qmi_wwan.c", "usbnet_tx_timeout"], ["drivers/net/usb/r8152.c", "rtl8152_tx_timeout"], ["drivers/net/usb/rndis_host.c", "usbnet_tx_timeout"], ["drivers/net/usb/rtl8150.c", "rtl8150_tx_timeout"], ["drivers/net/usb/sierra_net.c", "usbnet_tx_timeout"], ["drivers/net/usb/smsc75xx.c", "usbnet_tx_timeout"], ["drivers/net/usb/smsc95xx.c", "usbnet_tx_timeout"], ["drivers/net/usb/sr9700.c", "usbnet_tx_timeout"], ["drivers/net/usb/sr9800.c", "usbnet_tx_timeout"], ["drivers/net/usb/usbnet.c", "usbnet_tx_timeout"], ["drivers/net/vmxnet3/vmxnet3_drv.c", "vmxnet3_tx_timeout"], ["drivers/net/wan/cosa.c", "cosa_net_timeout"], ["drivers/net/wan/farsync.c", "fst_tx_timeout"], ["drivers/net/wan/fsl_ucc_hdlc.c", "uhdlc_tx_timeout"], ["drivers/net/wan/lmc/lmc_main.c", "lmc_driver_timeout"], ["drivers/net/wan/x25_asy.c", "x25_asy_timeout"], ["drivers/net/wimax/i2400m/netdev.c", "i2400m_tx_timeout"], ["drivers/net/wireless/intel/ipw2x00/ipw2100.c", "ipw2100_tx_timeout"], ["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"], ["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"], ["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"], ["drivers/net/wireless/intersil/orinoco/main.c", "orinoco_tx_timeout"], ["drivers/net/wireless/intersil/orinoco/orinoco_usb.c", "orinoco_tx_timeout"], ["drivers/net/wireless/intersil/orinoco/orinoco.h", "orinoco_tx_timeout"], ["drivers/net/wireless/intersil/prism54/islpci_dev.c", "islpci_eth_tx_timeout"], ["drivers/net/wireless/intersil/prism54/islpci_eth.c", "islpci_eth_tx_timeout"], ["drivers/net/wireless/intersil/prism54/islpci_eth.h", "islpci_eth_tx_timeout"], ["drivers/net/wireless/marvell/mwifiex/main.c", "mwifiex_tx_timeout"], ["drivers/net/wireless/quantenna/qtnfmac/core.c", "qtnf_netdev_tx_timeout"], ["drivers/net/wireless/quantenna/qtnfmac/core.h", "qtnf_netdev_tx_timeout"], ["drivers/net/wireless/rndis_wlan.c", "usbnet_tx_timeout"], ["drivers/net/wireless/wl3501_cs.c", "wl3501_tx_timeout"], ["drivers/net/wireless/zydas/zd1201.c", "zd1201_tx_timeout"], ["drivers/s390/net/qeth_core.h", "qeth_tx_timeout"], ["drivers/s390/net/qeth_core_main.c", "qeth_tx_timeout"], ["drivers/s390/net/qeth_l2_main.c", "qeth_tx_timeout"], ["drivers/s390/net/qeth_l2_main.c", "qeth_tx_timeout"], ["drivers/s390/net/qeth_l3_main.c", "qeth_tx_timeout"], ["drivers/s390/net/qeth_l3_main.c", "qeth_tx_timeout"], ["drivers/staging/ks7010/ks_wlan_net.c", "ks_wlan_tx_timeout"], ["drivers/staging/qlge/qlge_main.c", "qlge_tx_timeout"], ["drivers/staging/rtl8192e/rtl8192e/rtl_core.c", "_rtl92e_tx_timeout"], ["drivers/staging/rtl8192u/r8192U_core.c", "tx_timeout"], ["drivers/staging/unisys/visornic/visornic_main.c", "visornic_xmit_timeout"], ["drivers/staging/wlan-ng/p80211netdev.c", "p80211knetdev_tx_timeout"], ["drivers/tty/n_gsm.c", "gsm_mux_net_tx_timeout"], ["drivers/tty/synclink.c", "hdlcdev_tx_timeout"], ["drivers/tty/synclink_gt.c", "hdlcdev_tx_timeout"], ["drivers/tty/synclinkmp.c", "hdlcdev_tx_timeout"], ["net/atm/lec.c", "lec_tx_timeout"], ["net/bluetooth/bnep/netdev.c", "bnep_net_timeout"] ); for my $p (@work) { my @pair = @$p; my $file = $pair[0]; my $func = $pair[1]; print STDERR $file , ": ", $func,"\n"; our @ARGV = ($file); while (<ARGV>) { if (m/($func\s*\(struct\s+net_device\s+\*[A-Za-z_]?[A-Za-z-0-9_]*)(\))/) { print STDERR "found $1+$2 in $file\n"; } if (s/($func\s*\(struct\s+net_device\s+\*[A-Za-z_]?[A-Za-z-0-9_]*)(\))/$1, unsigned int txqueue$2/) { print STDERR "$func found in $file\n"; } print; } } where the list of files and functions is simply from: git grep ndo_tx_timeout, with manual addition of headers in the rare cases where the function is from a header, then manually changing the few places which actually call ndo_tx_timeout. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Heiner Kallweit <hkallweit1@gmail.com> Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com> Acked-by: Shannon Nelson <snelson@pensando.io> Reviewed-by: Martin Habets <mhabets@solarflare.com> changes from v9: fixup a forward declaration changes from v9: more leftovers from v3 change changes from v8: fix up a missing direct call to timeout rebased on net-next changes from v7: fixup leftovers from v3 change changes from v6: fix typo in rtl driver changes from v5: add missing files (allow any net device argument name) changes from v4: add a missing driver header changes from v3: change queue # to unsigned Changes from v2: added headers Changes from v1: Fix errors found by kbuild: generalize the pattern a bit, to pick up a couple of instances missed by the previous version. Signed-off-by: David S. Miller <davem@davemloft.net>
746 lines
22 KiB
C
746 lines
22 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* sonic.c
|
|
*
|
|
* (C) 2005 Finn Thain
|
|
*
|
|
* Converted to DMA API, added zero-copy buffer handling, and
|
|
* (from the mac68k project) introduced dhd's support for 16-bit cards.
|
|
*
|
|
* (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de)
|
|
*
|
|
* This driver is based on work from Andreas Busse, but most of
|
|
* the code is rewritten.
|
|
*
|
|
* (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de)
|
|
*
|
|
* Core code included by system sonic drivers
|
|
*
|
|
* And... partially rewritten again by David Huggins-Daines in order
|
|
* to cope with screwed up Macintosh NICs that may or may not use
|
|
* 16-bit DMA.
|
|
*
|
|
* (C) 1999 David Huggins-Daines <dhd@debian.org>
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* Sources: Olivetti M700-10 Risc Personal Computer hardware handbook,
|
|
* National Semiconductors data sheet for the DP83932B Sonic Ethernet
|
|
* controller, and the files "8390.c" and "skeleton.c" in this directory.
|
|
*
|
|
* Additional sources: Nat Semi data sheet for the DP83932C and Nat Semi
|
|
* Application Note AN-746, the files "lance.c" and "ibmlana.c". See also
|
|
* the NetBSD file "sys/arch/mac68k/dev/if_sn.c".
|
|
*/
|
|
|
|
static unsigned int version_printed;
|
|
|
|
static int sonic_debug = -1;
|
|
module_param(sonic_debug, int, 0);
|
|
MODULE_PARM_DESC(sonic_debug, "debug message level");
|
|
|
|
static void sonic_msg_init(struct net_device *dev)
|
|
{
|
|
struct sonic_local *lp = netdev_priv(dev);
|
|
|
|
lp->msg_enable = netif_msg_init(sonic_debug, 0);
|
|
|
|
if (version_printed++ == 0)
|
|
netif_dbg(lp, drv, dev, "%s", version);
|
|
}
|
|
|
|
/*
|
|
* Open/initialize the SONIC controller.
|
|
*
|
|
* This routine should set everything up anew at each open, even
|
|
* registers that "should" only need to be set once at boot, so that
|
|
* there is non-reboot way to recover if something goes wrong.
|
|
*/
|
|
static int sonic_open(struct net_device *dev)
|
|
{
|
|
struct sonic_local *lp = netdev_priv(dev);
|
|
int i;
|
|
|
|
netif_dbg(lp, ifup, dev, "%s: initializing sonic driver\n", __func__);
|
|
|
|
for (i = 0; i < SONIC_NUM_RRS; i++) {
|
|
struct sk_buff *skb = netdev_alloc_skb(dev, SONIC_RBSIZE + 2);
|
|
if (skb == NULL) {
|
|
while(i > 0) { /* free any that were allocated successfully */
|
|
i--;
|
|
dev_kfree_skb(lp->rx_skb[i]);
|
|
lp->rx_skb[i] = NULL;
|
|
}
|
|
printk(KERN_ERR "%s: couldn't allocate receive buffers\n",
|
|
dev->name);
|
|
return -ENOMEM;
|
|
}
|
|
/* align IP header unless DMA requires otherwise */
|
|
if (SONIC_BUS_SCALE(lp->dma_bitmode) == 2)
|
|
skb_reserve(skb, 2);
|
|
lp->rx_skb[i] = skb;
|
|
}
|
|
|
|
for (i = 0; i < SONIC_NUM_RRS; i++) {
|
|
dma_addr_t laddr = dma_map_single(lp->device, skb_put(lp->rx_skb[i], SONIC_RBSIZE),
|
|
SONIC_RBSIZE, DMA_FROM_DEVICE);
|
|
if (dma_mapping_error(lp->device, laddr)) {
|
|
while(i > 0) { /* free any that were mapped successfully */
|
|
i--;
|
|
dma_unmap_single(lp->device, lp->rx_laddr[i], SONIC_RBSIZE, DMA_FROM_DEVICE);
|
|
lp->rx_laddr[i] = (dma_addr_t)0;
|
|
}
|
|
for (i = 0; i < SONIC_NUM_RRS; i++) {
|
|
dev_kfree_skb(lp->rx_skb[i]);
|
|
lp->rx_skb[i] = NULL;
|
|
}
|
|
printk(KERN_ERR "%s: couldn't map rx DMA buffers\n",
|
|
dev->name);
|
|
return -ENOMEM;
|
|
}
|
|
lp->rx_laddr[i] = laddr;
|
|
}
|
|
|
|
/*
|
|
* Initialize the SONIC
|
|
*/
|
|
sonic_init(dev);
|
|
|
|
netif_start_queue(dev);
|
|
|
|
netif_dbg(lp, ifup, dev, "%s: Initialization done\n", __func__);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/*
|
|
* Close the SONIC device
|
|
*/
|
|
static int sonic_close(struct net_device *dev)
|
|
{
|
|
struct sonic_local *lp = netdev_priv(dev);
|
|
int i;
|
|
|
|
netif_dbg(lp, ifdown, dev, "%s\n", __func__);
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
/*
|
|
* stop the SONIC, disable interrupts
|
|
*/
|
|
SONIC_WRITE(SONIC_IMR, 0);
|
|
SONIC_WRITE(SONIC_ISR, 0x7fff);
|
|
SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
|
|
|
|
/* unmap and free skbs that haven't been transmitted */
|
|
for (i = 0; i < SONIC_NUM_TDS; i++) {
|
|
if(lp->tx_laddr[i]) {
|
|
dma_unmap_single(lp->device, lp->tx_laddr[i], lp->tx_len[i], DMA_TO_DEVICE);
|
|
lp->tx_laddr[i] = (dma_addr_t)0;
|
|
}
|
|
if(lp->tx_skb[i]) {
|
|
dev_kfree_skb(lp->tx_skb[i]);
|
|
lp->tx_skb[i] = NULL;
|
|
}
|
|
}
|
|
|
|
/* unmap and free the receive buffers */
|
|
for (i = 0; i < SONIC_NUM_RRS; i++) {
|
|
if(lp->rx_laddr[i]) {
|
|
dma_unmap_single(lp->device, lp->rx_laddr[i], SONIC_RBSIZE, DMA_FROM_DEVICE);
|
|
lp->rx_laddr[i] = (dma_addr_t)0;
|
|
}
|
|
if(lp->rx_skb[i]) {
|
|
dev_kfree_skb(lp->rx_skb[i]);
|
|
lp->rx_skb[i] = NULL;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void sonic_tx_timeout(struct net_device *dev, unsigned int txqueue)
|
|
{
|
|
struct sonic_local *lp = netdev_priv(dev);
|
|
int i;
|
|
/*
|
|
* put the Sonic into software-reset mode and
|
|
* disable all interrupts before releasing DMA buffers
|
|
*/
|
|
SONIC_WRITE(SONIC_IMR, 0);
|
|
SONIC_WRITE(SONIC_ISR, 0x7fff);
|
|
SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
|
|
/* We could resend the original skbs. Easier to re-initialise. */
|
|
for (i = 0; i < SONIC_NUM_TDS; i++) {
|
|
if(lp->tx_laddr[i]) {
|
|
dma_unmap_single(lp->device, lp->tx_laddr[i], lp->tx_len[i], DMA_TO_DEVICE);
|
|
lp->tx_laddr[i] = (dma_addr_t)0;
|
|
}
|
|
if(lp->tx_skb[i]) {
|
|
dev_kfree_skb(lp->tx_skb[i]);
|
|
lp->tx_skb[i] = NULL;
|
|
}
|
|
}
|
|
/* Try to restart the adaptor. */
|
|
sonic_init(dev);
|
|
lp->stats.tx_errors++;
|
|
netif_trans_update(dev); /* prevent tx timeout */
|
|
netif_wake_queue(dev);
|
|
}
|
|
|
|
/*
|
|
* transmit packet
|
|
*
|
|
* Appends new TD during transmission thus avoiding any TX interrupts
|
|
* until we run out of TDs.
|
|
* This routine interacts closely with the ISR in that it may,
|
|
* set tx_skb[i]
|
|
* reset the status flags of the new TD
|
|
* set and reset EOL flags
|
|
* stop the tx queue
|
|
* The ISR interacts with this routine in various ways. It may,
|
|
* reset tx_skb[i]
|
|
* test the EOL and status flags of the TDs
|
|
* wake the tx queue
|
|
* Concurrently with all of this, the SONIC is potentially writing to
|
|
* the status flags of the TDs.
|
|
* Until some mutual exclusion is added, this code will not work with SMP. However,
|
|
* MIPS Jazz machines and m68k Macs were all uni-processor machines.
|
|
*/
|
|
|
|
static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)
|
|
{
|
|
struct sonic_local *lp = netdev_priv(dev);
|
|
dma_addr_t laddr;
|
|
int length;
|
|
int entry = lp->next_tx;
|
|
|
|
netif_dbg(lp, tx_queued, dev, "%s: skb=%p\n", __func__, skb);
|
|
|
|
length = skb->len;
|
|
if (length < ETH_ZLEN) {
|
|
if (skb_padto(skb, ETH_ZLEN))
|
|
return NETDEV_TX_OK;
|
|
length = ETH_ZLEN;
|
|
}
|
|
|
|
/*
|
|
* Map the packet data into the logical DMA address space
|
|
*/
|
|
|
|
laddr = dma_map_single(lp->device, skb->data, length, DMA_TO_DEVICE);
|
|
if (!laddr) {
|
|
pr_err_ratelimited("%s: failed to map tx DMA buffer.\n", dev->name);
|
|
dev_kfree_skb_any(skb);
|
|
return NETDEV_TX_OK;
|
|
}
|
|
|
|
sonic_tda_put(dev, entry, SONIC_TD_STATUS, 0); /* clear status */
|
|
sonic_tda_put(dev, entry, SONIC_TD_FRAG_COUNT, 1); /* single fragment */
|
|
sonic_tda_put(dev, entry, SONIC_TD_PKTSIZE, length); /* length of packet */
|
|
sonic_tda_put(dev, entry, SONIC_TD_FRAG_PTR_L, laddr & 0xffff);
|
|
sonic_tda_put(dev, entry, SONIC_TD_FRAG_PTR_H, laddr >> 16);
|
|
sonic_tda_put(dev, entry, SONIC_TD_FRAG_SIZE, length);
|
|
sonic_tda_put(dev, entry, SONIC_TD_LINK,
|
|
sonic_tda_get(dev, entry, SONIC_TD_LINK) | SONIC_EOL);
|
|
|
|
/*
|
|
* Must set tx_skb[entry] only after clearing status, and
|
|
* before clearing EOL and before stopping queue
|
|
*/
|
|
wmb();
|
|
lp->tx_len[entry] = length;
|
|
lp->tx_laddr[entry] = laddr;
|
|
lp->tx_skb[entry] = skb;
|
|
|
|
wmb();
|
|
sonic_tda_put(dev, lp->eol_tx, SONIC_TD_LINK,
|
|
sonic_tda_get(dev, lp->eol_tx, SONIC_TD_LINK) & ~SONIC_EOL);
|
|
lp->eol_tx = entry;
|
|
|
|
lp->next_tx = (entry + 1) & SONIC_TDS_MASK;
|
|
if (lp->tx_skb[lp->next_tx] != NULL) {
|
|
/* The ring is full, the ISR has yet to process the next TD. */
|
|
netif_dbg(lp, tx_queued, dev, "%s: stopping queue\n", __func__);
|
|
netif_stop_queue(dev);
|
|
/* after this packet, wait for ISR to free up some TDAs */
|
|
} else netif_start_queue(dev);
|
|
|
|
netif_dbg(lp, tx_queued, dev, "%s: issuing Tx command\n", __func__);
|
|
|
|
SONIC_WRITE(SONIC_CMD, SONIC_CR_TXP);
|
|
|
|
return NETDEV_TX_OK;
|
|
}
|
|
|
|
/*
|
|
* The typical workload of the driver:
|
|
* Handle the network interface interrupts.
|
|
*/
|
|
static irqreturn_t sonic_interrupt(int irq, void *dev_id)
|
|
{
|
|
struct net_device *dev = dev_id;
|
|
struct sonic_local *lp = netdev_priv(dev);
|
|
int status;
|
|
|
|
if (!(status = SONIC_READ(SONIC_ISR) & SONIC_IMR_DEFAULT))
|
|
return IRQ_NONE;
|
|
|
|
do {
|
|
if (status & SONIC_INT_PKTRX) {
|
|
netif_dbg(lp, intr, dev, "%s: packet rx\n", __func__);
|
|
sonic_rx(dev); /* got packet(s) */
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_PKTRX); /* clear the interrupt */
|
|
}
|
|
|
|
if (status & SONIC_INT_TXDN) {
|
|
int entry = lp->cur_tx;
|
|
int td_status;
|
|
int freed_some = 0;
|
|
|
|
/* At this point, cur_tx is the index of a TD that is one of:
|
|
* unallocated/freed (status set & tx_skb[entry] clear)
|
|
* allocated and sent (status set & tx_skb[entry] set )
|
|
* allocated and not yet sent (status clear & tx_skb[entry] set )
|
|
* still being allocated by sonic_send_packet (status clear & tx_skb[entry] clear)
|
|
*/
|
|
|
|
netif_dbg(lp, intr, dev, "%s: tx done\n", __func__);
|
|
|
|
while (lp->tx_skb[entry] != NULL) {
|
|
if ((td_status = sonic_tda_get(dev, entry, SONIC_TD_STATUS)) == 0)
|
|
break;
|
|
|
|
if (td_status & 0x0001) {
|
|
lp->stats.tx_packets++;
|
|
lp->stats.tx_bytes += sonic_tda_get(dev, entry, SONIC_TD_PKTSIZE);
|
|
} else {
|
|
lp->stats.tx_errors++;
|
|
if (td_status & 0x0642)
|
|
lp->stats.tx_aborted_errors++;
|
|
if (td_status & 0x0180)
|
|
lp->stats.tx_carrier_errors++;
|
|
if (td_status & 0x0020)
|
|
lp->stats.tx_window_errors++;
|
|
if (td_status & 0x0004)
|
|
lp->stats.tx_fifo_errors++;
|
|
}
|
|
|
|
/* We must free the original skb */
|
|
dev_consume_skb_irq(lp->tx_skb[entry]);
|
|
lp->tx_skb[entry] = NULL;
|
|
/* and unmap DMA buffer */
|
|
dma_unmap_single(lp->device, lp->tx_laddr[entry], lp->tx_len[entry], DMA_TO_DEVICE);
|
|
lp->tx_laddr[entry] = (dma_addr_t)0;
|
|
freed_some = 1;
|
|
|
|
if (sonic_tda_get(dev, entry, SONIC_TD_LINK) & SONIC_EOL) {
|
|
entry = (entry + 1) & SONIC_TDS_MASK;
|
|
break;
|
|
}
|
|
entry = (entry + 1) & SONIC_TDS_MASK;
|
|
}
|
|
|
|
if (freed_some || lp->tx_skb[entry] == NULL)
|
|
netif_wake_queue(dev); /* The ring is no longer full */
|
|
lp->cur_tx = entry;
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_TXDN); /* clear the interrupt */
|
|
}
|
|
|
|
/*
|
|
* check error conditions
|
|
*/
|
|
if (status & SONIC_INT_RFO) {
|
|
netif_dbg(lp, rx_err, dev, "%s: rx fifo overrun\n",
|
|
__func__);
|
|
lp->stats.rx_fifo_errors++;
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_RFO); /* clear the interrupt */
|
|
}
|
|
if (status & SONIC_INT_RDE) {
|
|
netif_dbg(lp, rx_err, dev, "%s: rx descriptors exhausted\n",
|
|
__func__);
|
|
lp->stats.rx_dropped++;
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_RDE); /* clear the interrupt */
|
|
}
|
|
if (status & SONIC_INT_RBAE) {
|
|
netif_dbg(lp, rx_err, dev, "%s: rx buffer area exceeded\n",
|
|
__func__);
|
|
lp->stats.rx_dropped++;
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_RBAE); /* clear the interrupt */
|
|
}
|
|
|
|
/* counter overruns; all counters are 16bit wide */
|
|
if (status & SONIC_INT_FAE) {
|
|
lp->stats.rx_frame_errors += 65536;
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_FAE); /* clear the interrupt */
|
|
}
|
|
if (status & SONIC_INT_CRC) {
|
|
lp->stats.rx_crc_errors += 65536;
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_CRC); /* clear the interrupt */
|
|
}
|
|
if (status & SONIC_INT_MP) {
|
|
lp->stats.rx_missed_errors += 65536;
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_MP); /* clear the interrupt */
|
|
}
|
|
|
|
/* transmit error */
|
|
if (status & SONIC_INT_TXER) {
|
|
if (SONIC_READ(SONIC_TCR) & SONIC_TCR_FU)
|
|
netif_dbg(lp, tx_err, dev, "%s: tx fifo underrun\n",
|
|
__func__);
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_TXER); /* clear the interrupt */
|
|
}
|
|
|
|
/* bus retry */
|
|
if (status & SONIC_INT_BR) {
|
|
printk(KERN_ERR "%s: Bus retry occurred! Device interrupt disabled.\n",
|
|
dev->name);
|
|
/* ... to help debug DMA problems causing endless interrupts. */
|
|
/* Bounce the eth interface to turn on the interrupt again. */
|
|
SONIC_WRITE(SONIC_IMR, 0);
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_BR); /* clear the interrupt */
|
|
}
|
|
|
|
/* load CAM done */
|
|
if (status & SONIC_INT_LCD)
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_LCD); /* clear the interrupt */
|
|
} while((status = SONIC_READ(SONIC_ISR) & SONIC_IMR_DEFAULT));
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
/*
|
|
* We have a good packet(s), pass it/them up the network stack.
|
|
*/
|
|
static void sonic_rx(struct net_device *dev)
|
|
{
|
|
struct sonic_local *lp = netdev_priv(dev);
|
|
int status;
|
|
int entry = lp->cur_rx;
|
|
|
|
while (sonic_rda_get(dev, entry, SONIC_RD_IN_USE) == 0) {
|
|
struct sk_buff *used_skb;
|
|
struct sk_buff *new_skb;
|
|
dma_addr_t new_laddr;
|
|
u16 bufadr_l;
|
|
u16 bufadr_h;
|
|
int pkt_len;
|
|
|
|
status = sonic_rda_get(dev, entry, SONIC_RD_STATUS);
|
|
if (status & SONIC_RCR_PRX) {
|
|
/* Malloc up new buffer. */
|
|
new_skb = netdev_alloc_skb(dev, SONIC_RBSIZE + 2);
|
|
if (new_skb == NULL) {
|
|
lp->stats.rx_dropped++;
|
|
break;
|
|
}
|
|
/* provide 16 byte IP header alignment unless DMA requires otherwise */
|
|
if(SONIC_BUS_SCALE(lp->dma_bitmode) == 2)
|
|
skb_reserve(new_skb, 2);
|
|
|
|
new_laddr = dma_map_single(lp->device, skb_put(new_skb, SONIC_RBSIZE),
|
|
SONIC_RBSIZE, DMA_FROM_DEVICE);
|
|
if (!new_laddr) {
|
|
dev_kfree_skb(new_skb);
|
|
printk(KERN_ERR "%s: Failed to map rx buffer, dropping packet.\n", dev->name);
|
|
lp->stats.rx_dropped++;
|
|
break;
|
|
}
|
|
|
|
/* now we have a new skb to replace it, pass the used one up the stack */
|
|
dma_unmap_single(lp->device, lp->rx_laddr[entry], SONIC_RBSIZE, DMA_FROM_DEVICE);
|
|
used_skb = lp->rx_skb[entry];
|
|
pkt_len = sonic_rda_get(dev, entry, SONIC_RD_PKTLEN);
|
|
skb_trim(used_skb, pkt_len);
|
|
used_skb->protocol = eth_type_trans(used_skb, dev);
|
|
netif_rx(used_skb);
|
|
lp->stats.rx_packets++;
|
|
lp->stats.rx_bytes += pkt_len;
|
|
|
|
/* and insert the new skb */
|
|
lp->rx_laddr[entry] = new_laddr;
|
|
lp->rx_skb[entry] = new_skb;
|
|
|
|
bufadr_l = (unsigned long)new_laddr & 0xffff;
|
|
bufadr_h = (unsigned long)new_laddr >> 16;
|
|
sonic_rra_put(dev, entry, SONIC_RR_BUFADR_L, bufadr_l);
|
|
sonic_rra_put(dev, entry, SONIC_RR_BUFADR_H, bufadr_h);
|
|
} else {
|
|
/* This should only happen, if we enable accepting broken packets. */
|
|
lp->stats.rx_errors++;
|
|
if (status & SONIC_RCR_FAER)
|
|
lp->stats.rx_frame_errors++;
|
|
if (status & SONIC_RCR_CRCR)
|
|
lp->stats.rx_crc_errors++;
|
|
}
|
|
if (status & SONIC_RCR_LPKT) {
|
|
/*
|
|
* this was the last packet out of the current receive buffer
|
|
* give the buffer back to the SONIC
|
|
*/
|
|
lp->cur_rwp += SIZEOF_SONIC_RR * SONIC_BUS_SCALE(lp->dma_bitmode);
|
|
if (lp->cur_rwp >= lp->rra_end) lp->cur_rwp = lp->rra_laddr & 0xffff;
|
|
SONIC_WRITE(SONIC_RWP, lp->cur_rwp);
|
|
if (SONIC_READ(SONIC_ISR) & SONIC_INT_RBE) {
|
|
netif_dbg(lp, rx_err, dev, "%s: rx buffer exhausted\n",
|
|
__func__);
|
|
SONIC_WRITE(SONIC_ISR, SONIC_INT_RBE); /* clear the flag */
|
|
}
|
|
} else
|
|
printk(KERN_ERR "%s: rx desc without RCR_LPKT. Shouldn't happen !?\n",
|
|
dev->name);
|
|
/*
|
|
* give back the descriptor
|
|
*/
|
|
sonic_rda_put(dev, entry, SONIC_RD_LINK,
|
|
sonic_rda_get(dev, entry, SONIC_RD_LINK) | SONIC_EOL);
|
|
sonic_rda_put(dev, entry, SONIC_RD_IN_USE, 1);
|
|
sonic_rda_put(dev, lp->eol_rx, SONIC_RD_LINK,
|
|
sonic_rda_get(dev, lp->eol_rx, SONIC_RD_LINK) & ~SONIC_EOL);
|
|
lp->eol_rx = entry;
|
|
lp->cur_rx = entry = (entry + 1) & SONIC_RDS_MASK;
|
|
}
|
|
/*
|
|
* If any worth-while packets have been received, netif_rx()
|
|
* has done a mark_bh(NET_BH) for us and will work on them
|
|
* when we get to the bottom-half routine.
|
|
*/
|
|
}
|
|
|
|
|
|
/*
|
|
* Get the current statistics.
|
|
* This may be called with the device open or closed.
|
|
*/
|
|
static struct net_device_stats *sonic_get_stats(struct net_device *dev)
|
|
{
|
|
struct sonic_local *lp = netdev_priv(dev);
|
|
|
|
/* read the tally counter from the SONIC and reset them */
|
|
lp->stats.rx_crc_errors += SONIC_READ(SONIC_CRCT);
|
|
SONIC_WRITE(SONIC_CRCT, 0xffff);
|
|
lp->stats.rx_frame_errors += SONIC_READ(SONIC_FAET);
|
|
SONIC_WRITE(SONIC_FAET, 0xffff);
|
|
lp->stats.rx_missed_errors += SONIC_READ(SONIC_MPT);
|
|
SONIC_WRITE(SONIC_MPT, 0xffff);
|
|
|
|
return &lp->stats;
|
|
}
|
|
|
|
|
|
/*
|
|
* Set or clear the multicast filter for this adaptor.
|
|
*/
|
|
static void sonic_multicast_list(struct net_device *dev)
|
|
{
|
|
struct sonic_local *lp = netdev_priv(dev);
|
|
unsigned int rcr;
|
|
struct netdev_hw_addr *ha;
|
|
unsigned char *addr;
|
|
int i;
|
|
|
|
rcr = SONIC_READ(SONIC_RCR) & ~(SONIC_RCR_PRO | SONIC_RCR_AMC);
|
|
rcr |= SONIC_RCR_BRD; /* accept broadcast packets */
|
|
|
|
if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
|
|
rcr |= SONIC_RCR_PRO;
|
|
} else {
|
|
if ((dev->flags & IFF_ALLMULTI) ||
|
|
(netdev_mc_count(dev) > 15)) {
|
|
rcr |= SONIC_RCR_AMC;
|
|
} else {
|
|
netif_dbg(lp, ifup, dev, "%s: mc_count %d\n", __func__,
|
|
netdev_mc_count(dev));
|
|
sonic_set_cam_enable(dev, 1); /* always enable our own address */
|
|
i = 1;
|
|
netdev_for_each_mc_addr(ha, dev) {
|
|
addr = ha->addr;
|
|
sonic_cda_put(dev, i, SONIC_CD_CAP0, addr[1] << 8 | addr[0]);
|
|
sonic_cda_put(dev, i, SONIC_CD_CAP1, addr[3] << 8 | addr[2]);
|
|
sonic_cda_put(dev, i, SONIC_CD_CAP2, addr[5] << 8 | addr[4]);
|
|
sonic_set_cam_enable(dev, sonic_get_cam_enable(dev) | (1 << i));
|
|
i++;
|
|
}
|
|
SONIC_WRITE(SONIC_CDC, 16);
|
|
/* issue Load CAM command */
|
|
SONIC_WRITE(SONIC_CDP, lp->cda_laddr & 0xffff);
|
|
SONIC_WRITE(SONIC_CMD, SONIC_CR_LCAM);
|
|
}
|
|
}
|
|
|
|
netif_dbg(lp, ifup, dev, "%s: setting RCR=%x\n", __func__, rcr);
|
|
|
|
SONIC_WRITE(SONIC_RCR, rcr);
|
|
}
|
|
|
|
|
|
/*
|
|
* Initialize the SONIC ethernet controller.
|
|
*/
|
|
static int sonic_init(struct net_device *dev)
|
|
{
|
|
unsigned int cmd;
|
|
struct sonic_local *lp = netdev_priv(dev);
|
|
int i;
|
|
|
|
/*
|
|
* put the Sonic into software-reset mode and
|
|
* disable all interrupts
|
|
*/
|
|
SONIC_WRITE(SONIC_IMR, 0);
|
|
SONIC_WRITE(SONIC_ISR, 0x7fff);
|
|
SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
|
|
|
|
/*
|
|
* clear software reset flag, disable receiver, clear and
|
|
* enable interrupts, then completely initialize the SONIC
|
|
*/
|
|
SONIC_WRITE(SONIC_CMD, 0);
|
|
SONIC_WRITE(SONIC_CMD, SONIC_CR_RXDIS);
|
|
|
|
/*
|
|
* initialize the receive resource area
|
|
*/
|
|
netif_dbg(lp, ifup, dev, "%s: initialize receive resource area\n",
|
|
__func__);
|
|
|
|
for (i = 0; i < SONIC_NUM_RRS; i++) {
|
|
u16 bufadr_l = (unsigned long)lp->rx_laddr[i] & 0xffff;
|
|
u16 bufadr_h = (unsigned long)lp->rx_laddr[i] >> 16;
|
|
sonic_rra_put(dev, i, SONIC_RR_BUFADR_L, bufadr_l);
|
|
sonic_rra_put(dev, i, SONIC_RR_BUFADR_H, bufadr_h);
|
|
sonic_rra_put(dev, i, SONIC_RR_BUFSIZE_L, SONIC_RBSIZE >> 1);
|
|
sonic_rra_put(dev, i, SONIC_RR_BUFSIZE_H, 0);
|
|
}
|
|
|
|
/* initialize all RRA registers */
|
|
lp->rra_end = (lp->rra_laddr + SONIC_NUM_RRS * SIZEOF_SONIC_RR *
|
|
SONIC_BUS_SCALE(lp->dma_bitmode)) & 0xffff;
|
|
lp->cur_rwp = (lp->rra_laddr + (SONIC_NUM_RRS - 1) * SIZEOF_SONIC_RR *
|
|
SONIC_BUS_SCALE(lp->dma_bitmode)) & 0xffff;
|
|
|
|
SONIC_WRITE(SONIC_RSA, lp->rra_laddr & 0xffff);
|
|
SONIC_WRITE(SONIC_REA, lp->rra_end);
|
|
SONIC_WRITE(SONIC_RRP, lp->rra_laddr & 0xffff);
|
|
SONIC_WRITE(SONIC_RWP, lp->cur_rwp);
|
|
SONIC_WRITE(SONIC_URRA, lp->rra_laddr >> 16);
|
|
SONIC_WRITE(SONIC_EOBC, (SONIC_RBSIZE >> 1) - (lp->dma_bitmode ? 2 : 1));
|
|
|
|
/* load the resource pointers */
|
|
netif_dbg(lp, ifup, dev, "%s: issuing RRRA command\n", __func__);
|
|
|
|
SONIC_WRITE(SONIC_CMD, SONIC_CR_RRRA);
|
|
i = 0;
|
|
while (i++ < 100) {
|
|
if (SONIC_READ(SONIC_CMD) & SONIC_CR_RRRA)
|
|
break;
|
|
}
|
|
|
|
netif_dbg(lp, ifup, dev, "%s: status=%x, i=%d\n", __func__,
|
|
SONIC_READ(SONIC_CMD), i);
|
|
|
|
/*
|
|
* Initialize the receive descriptors so that they
|
|
* become a circular linked list, ie. let the last
|
|
* descriptor point to the first again.
|
|
*/
|
|
netif_dbg(lp, ifup, dev, "%s: initialize receive descriptors\n",
|
|
__func__);
|
|
|
|
for (i=0; i<SONIC_NUM_RDS; i++) {
|
|
sonic_rda_put(dev, i, SONIC_RD_STATUS, 0);
|
|
sonic_rda_put(dev, i, SONIC_RD_PKTLEN, 0);
|
|
sonic_rda_put(dev, i, SONIC_RD_PKTPTR_L, 0);
|
|
sonic_rda_put(dev, i, SONIC_RD_PKTPTR_H, 0);
|
|
sonic_rda_put(dev, i, SONIC_RD_SEQNO, 0);
|
|
sonic_rda_put(dev, i, SONIC_RD_IN_USE, 1);
|
|
sonic_rda_put(dev, i, SONIC_RD_LINK,
|
|
lp->rda_laddr +
|
|
((i+1) * SIZEOF_SONIC_RD * SONIC_BUS_SCALE(lp->dma_bitmode)));
|
|
}
|
|
/* fix last descriptor */
|
|
sonic_rda_put(dev, SONIC_NUM_RDS - 1, SONIC_RD_LINK,
|
|
(lp->rda_laddr & 0xffff) | SONIC_EOL);
|
|
lp->eol_rx = SONIC_NUM_RDS - 1;
|
|
lp->cur_rx = 0;
|
|
SONIC_WRITE(SONIC_URDA, lp->rda_laddr >> 16);
|
|
SONIC_WRITE(SONIC_CRDA, lp->rda_laddr & 0xffff);
|
|
|
|
/*
|
|
* initialize transmit descriptors
|
|
*/
|
|
netif_dbg(lp, ifup, dev, "%s: initialize transmit descriptors\n",
|
|
__func__);
|
|
|
|
for (i = 0; i < SONIC_NUM_TDS; i++) {
|
|
sonic_tda_put(dev, i, SONIC_TD_STATUS, 0);
|
|
sonic_tda_put(dev, i, SONIC_TD_CONFIG, 0);
|
|
sonic_tda_put(dev, i, SONIC_TD_PKTSIZE, 0);
|
|
sonic_tda_put(dev, i, SONIC_TD_FRAG_COUNT, 0);
|
|
sonic_tda_put(dev, i, SONIC_TD_LINK,
|
|
(lp->tda_laddr & 0xffff) +
|
|
(i + 1) * SIZEOF_SONIC_TD * SONIC_BUS_SCALE(lp->dma_bitmode));
|
|
lp->tx_skb[i] = NULL;
|
|
}
|
|
/* fix last descriptor */
|
|
sonic_tda_put(dev, SONIC_NUM_TDS - 1, SONIC_TD_LINK,
|
|
(lp->tda_laddr & 0xffff));
|
|
|
|
SONIC_WRITE(SONIC_UTDA, lp->tda_laddr >> 16);
|
|
SONIC_WRITE(SONIC_CTDA, lp->tda_laddr & 0xffff);
|
|
lp->cur_tx = lp->next_tx = 0;
|
|
lp->eol_tx = SONIC_NUM_TDS - 1;
|
|
|
|
/*
|
|
* put our own address to CAM desc[0]
|
|
*/
|
|
sonic_cda_put(dev, 0, SONIC_CD_CAP0, dev->dev_addr[1] << 8 | dev->dev_addr[0]);
|
|
sonic_cda_put(dev, 0, SONIC_CD_CAP1, dev->dev_addr[3] << 8 | dev->dev_addr[2]);
|
|
sonic_cda_put(dev, 0, SONIC_CD_CAP2, dev->dev_addr[5] << 8 | dev->dev_addr[4]);
|
|
sonic_set_cam_enable(dev, 1);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
sonic_cda_put(dev, i, SONIC_CD_ENTRY_POINTER, i);
|
|
|
|
/*
|
|
* initialize CAM registers
|
|
*/
|
|
SONIC_WRITE(SONIC_CDP, lp->cda_laddr & 0xffff);
|
|
SONIC_WRITE(SONIC_CDC, 16);
|
|
|
|
/*
|
|
* load the CAM
|
|
*/
|
|
SONIC_WRITE(SONIC_CMD, SONIC_CR_LCAM);
|
|
|
|
i = 0;
|
|
while (i++ < 100) {
|
|
if (SONIC_READ(SONIC_ISR) & SONIC_INT_LCD)
|
|
break;
|
|
}
|
|
netif_dbg(lp, ifup, dev, "%s: CMD=%x, ISR=%x, i=%d\n", __func__,
|
|
SONIC_READ(SONIC_CMD), SONIC_READ(SONIC_ISR), i);
|
|
|
|
/*
|
|
* enable receiver, disable loopback
|
|
* and enable all interrupts
|
|
*/
|
|
SONIC_WRITE(SONIC_CMD, SONIC_CR_RXEN | SONIC_CR_STP);
|
|
SONIC_WRITE(SONIC_RCR, SONIC_RCR_DEFAULT);
|
|
SONIC_WRITE(SONIC_TCR, SONIC_TCR_DEFAULT);
|
|
SONIC_WRITE(SONIC_ISR, 0x7fff);
|
|
SONIC_WRITE(SONIC_IMR, SONIC_IMR_DEFAULT);
|
|
|
|
cmd = SONIC_READ(SONIC_CMD);
|
|
if ((cmd & SONIC_CR_RXEN) == 0 || (cmd & SONIC_CR_STP) == 0)
|
|
printk(KERN_ERR "sonic_init: failed, status=%x\n", cmd);
|
|
|
|
netif_dbg(lp, ifup, dev, "%s: new status=%x\n", __func__,
|
|
SONIC_READ(SONIC_CMD));
|
|
|
|
return 0;
|
|
}
|
|
|
|
MODULE_LICENSE("GPL");
|