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>
767 lines
17 KiB
C
767 lines
17 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Driver for the Macintosh 68K onboard MACE controller with PSC
|
|
* driven DMA. The MACE driver code is derived from mace.c. The
|
|
* Mac68k theory of operation is courtesy of the MacBSD wizards.
|
|
*
|
|
* Copyright (C) 1996 Paul Mackerras.
|
|
* Copyright (C) 1998 Alan Cox <alan@lxorguk.ukuu.org.uk>
|
|
*
|
|
* Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver
|
|
*
|
|
* Copyright (C) 2007 Finn Thain
|
|
*
|
|
* Converted to DMA API, converted to unified driver model,
|
|
* sync'd some routines with mace.c and fixed various bugs.
|
|
*/
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/etherdevice.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/string.h>
|
|
#include <linux/crc32.h>
|
|
#include <linux/bitrev.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/gfp.h>
|
|
#include <linux/interrupt.h>
|
|
#include <asm/io.h>
|
|
#include <asm/macints.h>
|
|
#include <asm/mac_psc.h>
|
|
#include <asm/page.h>
|
|
#include "mace.h"
|
|
|
|
static char mac_mace_string[] = "macmace";
|
|
|
|
#define N_TX_BUFF_ORDER 0
|
|
#define N_TX_RING (1 << N_TX_BUFF_ORDER)
|
|
#define N_RX_BUFF_ORDER 3
|
|
#define N_RX_RING (1 << N_RX_BUFF_ORDER)
|
|
|
|
#define TX_TIMEOUT HZ
|
|
|
|
#define MACE_BUFF_SIZE 0x800
|
|
|
|
/* Chip rev needs workaround on HW & multicast addr change */
|
|
#define BROKEN_ADDRCHG_REV 0x0941
|
|
|
|
/* The MACE is simply wired down on a Mac68K box */
|
|
|
|
#define MACE_BASE (void *)(0x50F1C000)
|
|
#define MACE_PROM (void *)(0x50F08001)
|
|
|
|
struct mace_data {
|
|
volatile struct mace *mace;
|
|
unsigned char *tx_ring;
|
|
dma_addr_t tx_ring_phys;
|
|
unsigned char *rx_ring;
|
|
dma_addr_t rx_ring_phys;
|
|
int dma_intr;
|
|
int rx_slot, rx_tail;
|
|
int tx_slot, tx_sloti, tx_count;
|
|
int chipid;
|
|
struct device *device;
|
|
};
|
|
|
|
struct mace_frame {
|
|
u8 rcvcnt;
|
|
u8 pad1;
|
|
u8 rcvsts;
|
|
u8 pad2;
|
|
u8 rntpc;
|
|
u8 pad3;
|
|
u8 rcvcc;
|
|
u8 pad4;
|
|
u32 pad5;
|
|
u32 pad6;
|
|
u8 data[1];
|
|
/* And frame continues.. */
|
|
};
|
|
|
|
#define PRIV_BYTES sizeof(struct mace_data)
|
|
|
|
static int mace_open(struct net_device *dev);
|
|
static int mace_close(struct net_device *dev);
|
|
static netdev_tx_t mace_xmit_start(struct sk_buff *skb, struct net_device *dev);
|
|
static void mace_set_multicast(struct net_device *dev);
|
|
static int mace_set_address(struct net_device *dev, void *addr);
|
|
static void mace_reset(struct net_device *dev);
|
|
static irqreturn_t mace_interrupt(int irq, void *dev_id);
|
|
static irqreturn_t mace_dma_intr(int irq, void *dev_id);
|
|
static void mace_tx_timeout(struct net_device *dev, unsigned int txqueue);
|
|
static void __mace_set_address(struct net_device *dev, void *addr);
|
|
|
|
/*
|
|
* Load a receive DMA channel with a base address and ring length
|
|
*/
|
|
|
|
static void mace_load_rxdma_base(struct net_device *dev, int set)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
|
|
psc_write_word(PSC_ENETRD_CMD + set, 0x0100);
|
|
psc_write_long(PSC_ENETRD_ADDR + set, (u32) mp->rx_ring_phys);
|
|
psc_write_long(PSC_ENETRD_LEN + set, N_RX_RING);
|
|
psc_write_word(PSC_ENETRD_CMD + set, 0x9800);
|
|
mp->rx_tail = 0;
|
|
}
|
|
|
|
/*
|
|
* Reset the receive DMA subsystem
|
|
*/
|
|
|
|
static void mace_rxdma_reset(struct net_device *dev)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mace = mp->mace;
|
|
u8 maccc = mace->maccc;
|
|
|
|
mace->maccc = maccc & ~ENRCV;
|
|
|
|
psc_write_word(PSC_ENETRD_CTL, 0x8800);
|
|
mace_load_rxdma_base(dev, 0x00);
|
|
psc_write_word(PSC_ENETRD_CTL, 0x0400);
|
|
|
|
psc_write_word(PSC_ENETRD_CTL, 0x8800);
|
|
mace_load_rxdma_base(dev, 0x10);
|
|
psc_write_word(PSC_ENETRD_CTL, 0x0400);
|
|
|
|
mace->maccc = maccc;
|
|
mp->rx_slot = 0;
|
|
|
|
psc_write_word(PSC_ENETRD_CMD + PSC_SET0, 0x9800);
|
|
psc_write_word(PSC_ENETRD_CMD + PSC_SET1, 0x9800);
|
|
}
|
|
|
|
/*
|
|
* Reset the transmit DMA subsystem
|
|
*/
|
|
|
|
static void mace_txdma_reset(struct net_device *dev)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mace = mp->mace;
|
|
u8 maccc;
|
|
|
|
psc_write_word(PSC_ENETWR_CTL, 0x8800);
|
|
|
|
maccc = mace->maccc;
|
|
mace->maccc = maccc & ~ENXMT;
|
|
|
|
mp->tx_slot = mp->tx_sloti = 0;
|
|
mp->tx_count = N_TX_RING;
|
|
|
|
psc_write_word(PSC_ENETWR_CTL, 0x0400);
|
|
mace->maccc = maccc;
|
|
}
|
|
|
|
/*
|
|
* Disable DMA
|
|
*/
|
|
|
|
static void mace_dma_off(struct net_device *dev)
|
|
{
|
|
psc_write_word(PSC_ENETRD_CTL, 0x8800);
|
|
psc_write_word(PSC_ENETRD_CTL, 0x1000);
|
|
psc_write_word(PSC_ENETRD_CMD + PSC_SET0, 0x1100);
|
|
psc_write_word(PSC_ENETRD_CMD + PSC_SET1, 0x1100);
|
|
|
|
psc_write_word(PSC_ENETWR_CTL, 0x8800);
|
|
psc_write_word(PSC_ENETWR_CTL, 0x1000);
|
|
psc_write_word(PSC_ENETWR_CMD + PSC_SET0, 0x1100);
|
|
psc_write_word(PSC_ENETWR_CMD + PSC_SET1, 0x1100);
|
|
}
|
|
|
|
static const struct net_device_ops mace_netdev_ops = {
|
|
.ndo_open = mace_open,
|
|
.ndo_stop = mace_close,
|
|
.ndo_start_xmit = mace_xmit_start,
|
|
.ndo_tx_timeout = mace_tx_timeout,
|
|
.ndo_set_rx_mode = mace_set_multicast,
|
|
.ndo_set_mac_address = mace_set_address,
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
};
|
|
|
|
/*
|
|
* Not really much of a probe. The hardware table tells us if this
|
|
* model of Macintrash has a MACE (AV macintoshes)
|
|
*/
|
|
|
|
static int mace_probe(struct platform_device *pdev)
|
|
{
|
|
int j;
|
|
struct mace_data *mp;
|
|
unsigned char *addr;
|
|
struct net_device *dev;
|
|
unsigned char checksum = 0;
|
|
int err;
|
|
|
|
dev = alloc_etherdev(PRIV_BYTES);
|
|
if (!dev)
|
|
return -ENOMEM;
|
|
|
|
mp = netdev_priv(dev);
|
|
|
|
mp->device = &pdev->dev;
|
|
platform_set_drvdata(pdev, dev);
|
|
SET_NETDEV_DEV(dev, &pdev->dev);
|
|
|
|
dev->base_addr = (u32)MACE_BASE;
|
|
mp->mace = MACE_BASE;
|
|
|
|
dev->irq = IRQ_MAC_MACE;
|
|
mp->dma_intr = IRQ_MAC_MACE_DMA;
|
|
|
|
mp->chipid = mp->mace->chipid_hi << 8 | mp->mace->chipid_lo;
|
|
|
|
/*
|
|
* The PROM contains 8 bytes which total 0xFF when XOR'd
|
|
* together. Due to the usual peculiar apple brain damage
|
|
* the bytes are spaced out in a strange boundary and the
|
|
* bits are reversed.
|
|
*/
|
|
|
|
addr = MACE_PROM;
|
|
|
|
for (j = 0; j < 6; ++j) {
|
|
u8 v = bitrev8(addr[j<<4]);
|
|
checksum ^= v;
|
|
dev->dev_addr[j] = v;
|
|
}
|
|
for (; j < 8; ++j) {
|
|
checksum ^= bitrev8(addr[j<<4]);
|
|
}
|
|
|
|
if (checksum != 0xFF) {
|
|
free_netdev(dev);
|
|
return -ENODEV;
|
|
}
|
|
|
|
dev->netdev_ops = &mace_netdev_ops;
|
|
dev->watchdog_timeo = TX_TIMEOUT;
|
|
|
|
pr_info("Onboard MACE, hardware address %pM, chip revision 0x%04X\n",
|
|
dev->dev_addr, mp->chipid);
|
|
|
|
err = register_netdev(dev);
|
|
if (!err)
|
|
return 0;
|
|
|
|
free_netdev(dev);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Reset the chip.
|
|
*/
|
|
|
|
static void mace_reset(struct net_device *dev)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mb = mp->mace;
|
|
int i;
|
|
|
|
/* soft-reset the chip */
|
|
i = 200;
|
|
while (--i) {
|
|
mb->biucc = SWRST;
|
|
if (mb->biucc & SWRST) {
|
|
udelay(10);
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
if (!i) {
|
|
printk(KERN_ERR "macmace: cannot reset chip!\n");
|
|
return;
|
|
}
|
|
|
|
mb->maccc = 0; /* turn off tx, rx */
|
|
mb->imr = 0xFF; /* disable all intrs for now */
|
|
i = mb->ir;
|
|
|
|
mb->biucc = XMTSP_64;
|
|
mb->utr = RTRD;
|
|
mb->fifocc = XMTFW_8 | RCVFW_64 | XMTFWU | RCVFWU;
|
|
|
|
mb->xmtfc = AUTO_PAD_XMIT; /* auto-pad short frames */
|
|
mb->rcvfc = 0;
|
|
|
|
/* load up the hardware address */
|
|
__mace_set_address(dev, dev->dev_addr);
|
|
|
|
/* clear the multicast filter */
|
|
if (mp->chipid == BROKEN_ADDRCHG_REV)
|
|
mb->iac = LOGADDR;
|
|
else {
|
|
mb->iac = ADDRCHG | LOGADDR;
|
|
while ((mb->iac & ADDRCHG) != 0)
|
|
;
|
|
}
|
|
for (i = 0; i < 8; ++i)
|
|
mb->ladrf = 0;
|
|
|
|
/* done changing address */
|
|
if (mp->chipid != BROKEN_ADDRCHG_REV)
|
|
mb->iac = 0;
|
|
|
|
mb->plscc = PORTSEL_AUI;
|
|
}
|
|
|
|
/*
|
|
* Load the address on a mace controller.
|
|
*/
|
|
|
|
static void __mace_set_address(struct net_device *dev, void *addr)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mb = mp->mace;
|
|
unsigned char *p = addr;
|
|
int i;
|
|
|
|
/* load up the hardware address */
|
|
if (mp->chipid == BROKEN_ADDRCHG_REV)
|
|
mb->iac = PHYADDR;
|
|
else {
|
|
mb->iac = ADDRCHG | PHYADDR;
|
|
while ((mb->iac & ADDRCHG) != 0)
|
|
;
|
|
}
|
|
for (i = 0; i < 6; ++i)
|
|
mb->padr = dev->dev_addr[i] = p[i];
|
|
if (mp->chipid != BROKEN_ADDRCHG_REV)
|
|
mb->iac = 0;
|
|
}
|
|
|
|
static int mace_set_address(struct net_device *dev, void *addr)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mb = mp->mace;
|
|
unsigned long flags;
|
|
u8 maccc;
|
|
|
|
local_irq_save(flags);
|
|
|
|
maccc = mb->maccc;
|
|
|
|
__mace_set_address(dev, addr);
|
|
|
|
mb->maccc = maccc;
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Open the Macintosh MACE. Most of this is playing with the DMA
|
|
* engine. The ethernet chip is quite friendly.
|
|
*/
|
|
|
|
static int mace_open(struct net_device *dev)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mb = mp->mace;
|
|
|
|
/* reset the chip */
|
|
mace_reset(dev);
|
|
|
|
if (request_irq(dev->irq, mace_interrupt, 0, dev->name, dev)) {
|
|
printk(KERN_ERR "%s: can't get irq %d\n", dev->name, dev->irq);
|
|
return -EAGAIN;
|
|
}
|
|
if (request_irq(mp->dma_intr, mace_dma_intr, 0, dev->name, dev)) {
|
|
printk(KERN_ERR "%s: can't get irq %d\n", dev->name, mp->dma_intr);
|
|
free_irq(dev->irq, dev);
|
|
return -EAGAIN;
|
|
}
|
|
|
|
/* Allocate the DMA ring buffers */
|
|
|
|
mp->tx_ring = dma_alloc_coherent(mp->device,
|
|
N_TX_RING * MACE_BUFF_SIZE,
|
|
&mp->tx_ring_phys, GFP_KERNEL);
|
|
if (mp->tx_ring == NULL)
|
|
goto out1;
|
|
|
|
mp->rx_ring = dma_alloc_coherent(mp->device,
|
|
N_RX_RING * MACE_BUFF_SIZE,
|
|
&mp->rx_ring_phys, GFP_KERNEL);
|
|
if (mp->rx_ring == NULL)
|
|
goto out2;
|
|
|
|
mace_dma_off(dev);
|
|
|
|
/* Not sure what these do */
|
|
|
|
psc_write_word(PSC_ENETWR_CTL, 0x9000);
|
|
psc_write_word(PSC_ENETRD_CTL, 0x9000);
|
|
psc_write_word(PSC_ENETWR_CTL, 0x0400);
|
|
psc_write_word(PSC_ENETRD_CTL, 0x0400);
|
|
|
|
mace_rxdma_reset(dev);
|
|
mace_txdma_reset(dev);
|
|
|
|
/* turn it on! */
|
|
mb->maccc = ENXMT | ENRCV;
|
|
/* enable all interrupts except receive interrupts */
|
|
mb->imr = RCVINT;
|
|
return 0;
|
|
|
|
out2:
|
|
dma_free_coherent(mp->device, N_TX_RING * MACE_BUFF_SIZE,
|
|
mp->tx_ring, mp->tx_ring_phys);
|
|
out1:
|
|
free_irq(dev->irq, dev);
|
|
free_irq(mp->dma_intr, dev);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
/*
|
|
* Shut down the mace and its interrupt channel
|
|
*/
|
|
|
|
static int mace_close(struct net_device *dev)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mb = mp->mace;
|
|
|
|
mb->maccc = 0; /* disable rx and tx */
|
|
mb->imr = 0xFF; /* disable all irqs */
|
|
mace_dma_off(dev); /* disable rx and tx dma */
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Transmit a frame
|
|
*/
|
|
|
|
static netdev_tx_t mace_xmit_start(struct sk_buff *skb, struct net_device *dev)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
unsigned long flags;
|
|
|
|
/* Stop the queue since there's only the one buffer */
|
|
|
|
local_irq_save(flags);
|
|
netif_stop_queue(dev);
|
|
if (!mp->tx_count) {
|
|
printk(KERN_ERR "macmace: tx queue running but no free buffers.\n");
|
|
local_irq_restore(flags);
|
|
return NETDEV_TX_BUSY;
|
|
}
|
|
mp->tx_count--;
|
|
local_irq_restore(flags);
|
|
|
|
dev->stats.tx_packets++;
|
|
dev->stats.tx_bytes += skb->len;
|
|
|
|
/* We need to copy into our xmit buffer to take care of alignment and caching issues */
|
|
skb_copy_from_linear_data(skb, mp->tx_ring, skb->len);
|
|
|
|
/* load the Tx DMA and fire it off */
|
|
|
|
psc_write_long(PSC_ENETWR_ADDR + mp->tx_slot, (u32) mp->tx_ring_phys);
|
|
psc_write_long(PSC_ENETWR_LEN + mp->tx_slot, skb->len);
|
|
psc_write_word(PSC_ENETWR_CMD + mp->tx_slot, 0x9800);
|
|
|
|
mp->tx_slot ^= 0x10;
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
return NETDEV_TX_OK;
|
|
}
|
|
|
|
static void mace_set_multicast(struct net_device *dev)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mb = mp->mace;
|
|
int i;
|
|
u32 crc;
|
|
u8 maccc;
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
maccc = mb->maccc;
|
|
mb->maccc &= ~PROM;
|
|
|
|
if (dev->flags & IFF_PROMISC) {
|
|
mb->maccc |= PROM;
|
|
} else {
|
|
unsigned char multicast_filter[8];
|
|
struct netdev_hw_addr *ha;
|
|
|
|
if (dev->flags & IFF_ALLMULTI) {
|
|
for (i = 0; i < 8; i++) {
|
|
multicast_filter[i] = 0xFF;
|
|
}
|
|
} else {
|
|
for (i = 0; i < 8; i++)
|
|
multicast_filter[i] = 0;
|
|
netdev_for_each_mc_addr(ha, dev) {
|
|
crc = ether_crc_le(6, ha->addr);
|
|
/* bit number in multicast_filter */
|
|
i = crc >> 26;
|
|
multicast_filter[i >> 3] |= 1 << (i & 7);
|
|
}
|
|
}
|
|
|
|
if (mp->chipid == BROKEN_ADDRCHG_REV)
|
|
mb->iac = LOGADDR;
|
|
else {
|
|
mb->iac = ADDRCHG | LOGADDR;
|
|
while ((mb->iac & ADDRCHG) != 0)
|
|
;
|
|
}
|
|
for (i = 0; i < 8; ++i)
|
|
mb->ladrf = multicast_filter[i];
|
|
if (mp->chipid != BROKEN_ADDRCHG_REV)
|
|
mb->iac = 0;
|
|
}
|
|
|
|
mb->maccc = maccc;
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
static void mace_handle_misc_intrs(struct net_device *dev, int intr)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mb = mp->mace;
|
|
static int mace_babbles, mace_jabbers;
|
|
|
|
if (intr & MPCO)
|
|
dev->stats.rx_missed_errors += 256;
|
|
dev->stats.rx_missed_errors += mb->mpc; /* reading clears it */
|
|
if (intr & RNTPCO)
|
|
dev->stats.rx_length_errors += 256;
|
|
dev->stats.rx_length_errors += mb->rntpc; /* reading clears it */
|
|
if (intr & CERR)
|
|
++dev->stats.tx_heartbeat_errors;
|
|
if (intr & BABBLE)
|
|
if (mace_babbles++ < 4)
|
|
printk(KERN_DEBUG "macmace: babbling transmitter\n");
|
|
if (intr & JABBER)
|
|
if (mace_jabbers++ < 4)
|
|
printk(KERN_DEBUG "macmace: jabbering transceiver\n");
|
|
}
|
|
|
|
static irqreturn_t mace_interrupt(int irq, void *dev_id)
|
|
{
|
|
struct net_device *dev = (struct net_device *) dev_id;
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mb = mp->mace;
|
|
int intr, fs;
|
|
unsigned long flags;
|
|
|
|
/* don't want the dma interrupt handler to fire */
|
|
local_irq_save(flags);
|
|
|
|
intr = mb->ir; /* read interrupt register */
|
|
mace_handle_misc_intrs(dev, intr);
|
|
|
|
if (intr & XMTINT) {
|
|
fs = mb->xmtfs;
|
|
if ((fs & XMTSV) == 0) {
|
|
printk(KERN_ERR "macmace: xmtfs not valid! (fs=%x)\n", fs);
|
|
mace_reset(dev);
|
|
/*
|
|
* XXX mace likes to hang the machine after a xmtfs error.
|
|
* This is hard to reproduce, resetting *may* help
|
|
*/
|
|
}
|
|
/* dma should have finished */
|
|
if (!mp->tx_count) {
|
|
printk(KERN_DEBUG "macmace: tx ring ran out? (fs=%x)\n", fs);
|
|
}
|
|
/* Update stats */
|
|
if (fs & (UFLO|LCOL|LCAR|RTRY)) {
|
|
++dev->stats.tx_errors;
|
|
if (fs & LCAR)
|
|
++dev->stats.tx_carrier_errors;
|
|
else if (fs & (UFLO|LCOL|RTRY)) {
|
|
++dev->stats.tx_aborted_errors;
|
|
if (mb->xmtfs & UFLO) {
|
|
dev->stats.tx_fifo_errors++;
|
|
mace_txdma_reset(dev);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (mp->tx_count)
|
|
netif_wake_queue(dev);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static void mace_tx_timeout(struct net_device *dev, unsigned int txqueue)
|
|
{
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
volatile struct mace *mb = mp->mace;
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
|
|
/* turn off both tx and rx and reset the chip */
|
|
mb->maccc = 0;
|
|
printk(KERN_ERR "macmace: transmit timeout - resetting\n");
|
|
mace_txdma_reset(dev);
|
|
mace_reset(dev);
|
|
|
|
/* restart rx dma */
|
|
mace_rxdma_reset(dev);
|
|
|
|
mp->tx_count = N_TX_RING;
|
|
netif_wake_queue(dev);
|
|
|
|
/* turn it on! */
|
|
mb->maccc = ENXMT | ENRCV;
|
|
/* enable all interrupts except receive interrupts */
|
|
mb->imr = RCVINT;
|
|
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
/*
|
|
* Handle a newly arrived frame
|
|
*/
|
|
|
|
static void mace_dma_rx_frame(struct net_device *dev, struct mace_frame *mf)
|
|
{
|
|
struct sk_buff *skb;
|
|
unsigned int frame_status = mf->rcvsts;
|
|
|
|
if (frame_status & (RS_OFLO | RS_CLSN | RS_FRAMERR | RS_FCSERR)) {
|
|
dev->stats.rx_errors++;
|
|
if (frame_status & RS_OFLO)
|
|
dev->stats.rx_fifo_errors++;
|
|
if (frame_status & RS_CLSN)
|
|
dev->stats.collisions++;
|
|
if (frame_status & RS_FRAMERR)
|
|
dev->stats.rx_frame_errors++;
|
|
if (frame_status & RS_FCSERR)
|
|
dev->stats.rx_crc_errors++;
|
|
} else {
|
|
unsigned int frame_length = mf->rcvcnt + ((frame_status & 0x0F) << 8 );
|
|
|
|
skb = netdev_alloc_skb(dev, frame_length + 2);
|
|
if (!skb) {
|
|
dev->stats.rx_dropped++;
|
|
return;
|
|
}
|
|
skb_reserve(skb, 2);
|
|
skb_put_data(skb, mf->data, frame_length);
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
netif_rx(skb);
|
|
dev->stats.rx_packets++;
|
|
dev->stats.rx_bytes += frame_length;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* The PSC has passed us a DMA interrupt event.
|
|
*/
|
|
|
|
static irqreturn_t mace_dma_intr(int irq, void *dev_id)
|
|
{
|
|
struct net_device *dev = (struct net_device *) dev_id;
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
int left, head;
|
|
u16 status;
|
|
u32 baka;
|
|
|
|
/* Not sure what this does */
|
|
|
|
while ((baka = psc_read_long(PSC_MYSTERY)) != psc_read_long(PSC_MYSTERY));
|
|
if (!(baka & 0x60000000)) return IRQ_NONE;
|
|
|
|
/*
|
|
* Process the read queue
|
|
*/
|
|
|
|
status = psc_read_word(PSC_ENETRD_CTL);
|
|
|
|
if (status & 0x2000) {
|
|
mace_rxdma_reset(dev);
|
|
} else if (status & 0x0100) {
|
|
psc_write_word(PSC_ENETRD_CMD + mp->rx_slot, 0x1100);
|
|
|
|
left = psc_read_long(PSC_ENETRD_LEN + mp->rx_slot);
|
|
head = N_RX_RING - left;
|
|
|
|
/* Loop through the ring buffer and process new packages */
|
|
|
|
while (mp->rx_tail < head) {
|
|
mace_dma_rx_frame(dev, (struct mace_frame*) (mp->rx_ring
|
|
+ (mp->rx_tail * MACE_BUFF_SIZE)));
|
|
mp->rx_tail++;
|
|
}
|
|
|
|
/* If we're out of buffers in this ring then switch to */
|
|
/* the other set, otherwise just reactivate this one. */
|
|
|
|
if (!left) {
|
|
mace_load_rxdma_base(dev, mp->rx_slot);
|
|
mp->rx_slot ^= 0x10;
|
|
} else {
|
|
psc_write_word(PSC_ENETRD_CMD + mp->rx_slot, 0x9800);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Process the write queue
|
|
*/
|
|
|
|
status = psc_read_word(PSC_ENETWR_CTL);
|
|
|
|
if (status & 0x2000) {
|
|
mace_txdma_reset(dev);
|
|
} else if (status & 0x0100) {
|
|
psc_write_word(PSC_ENETWR_CMD + mp->tx_sloti, 0x0100);
|
|
mp->tx_sloti ^= 0x10;
|
|
mp->tx_count++;
|
|
}
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("Macintosh MACE ethernet driver");
|
|
MODULE_ALIAS("platform:macmace");
|
|
|
|
static int mac_mace_device_remove(struct platform_device *pdev)
|
|
{
|
|
struct net_device *dev = platform_get_drvdata(pdev);
|
|
struct mace_data *mp = netdev_priv(dev);
|
|
|
|
unregister_netdev(dev);
|
|
|
|
free_irq(dev->irq, dev);
|
|
free_irq(IRQ_MAC_MACE_DMA, dev);
|
|
|
|
dma_free_coherent(mp->device, N_RX_RING * MACE_BUFF_SIZE,
|
|
mp->rx_ring, mp->rx_ring_phys);
|
|
dma_free_coherent(mp->device, N_TX_RING * MACE_BUFF_SIZE,
|
|
mp->tx_ring, mp->tx_ring_phys);
|
|
|
|
free_netdev(dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver mac_mace_driver = {
|
|
.probe = mace_probe,
|
|
.remove = mac_mace_device_remove,
|
|
.driver = {
|
|
.name = mac_mace_string,
|
|
},
|
|
};
|
|
|
|
module_platform_driver(mac_mace_driver);
|