aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/Kconfig13
-rw-r--r--drivers/net/Makefile10
-rw-r--r--drivers/net/acenic.c3
-rw-r--r--drivers/net/arm/ep93xx_eth.c12
-rw-r--r--drivers/net/au1000_eth.c16
-rw-r--r--drivers/net/b44.c3
-rw-r--r--drivers/net/benet/be.h2
-rw-r--r--drivers/net/benet/be_cmds.c33
-rw-r--r--drivers/net/benet/be_cmds.h7
-rw-r--r--drivers/net/benet/be_ethtool.c8
-rw-r--r--drivers/net/benet/be_main.c55
-rw-r--r--drivers/net/bnx2.h9
-rw-r--r--drivers/net/bonding/bond_main.c10
-rw-r--r--drivers/net/can/Kconfig60
-rw-r--r--drivers/net/can/dev.c23
-rw-r--r--drivers/net/can/sja1000/Kconfig47
-rw-r--r--drivers/net/can/sja1000/sja1000_of_platform.c1
-rw-r--r--drivers/net/can/usb/Kconfig10
-rw-r--r--drivers/net/can/usb/Makefile2
-rw-r--r--drivers/net/can/usb/ems_usb.c5
-rw-r--r--drivers/net/cassini.c5
-rw-r--r--drivers/net/cnic.c6
-rw-r--r--drivers/net/cxgb3/sge.c4
-rw-r--r--drivers/net/davinci_emac.c67
-rw-r--r--drivers/net/dm9000.h2
-rw-r--r--drivers/net/e100.c43
-rw-r--r--drivers/net/e1000e/defines.h2
-rw-r--r--drivers/net/e1000e/e1000.h28
-rw-r--r--drivers/net/e1000e/ethtool.c12
-rw-r--r--drivers/net/e1000e/hw.h3
-rw-r--r--drivers/net/e1000e/ich8lan.c630
-rw-r--r--drivers/net/e1000e/netdev.c50
-rw-r--r--drivers/net/e1000e/phy.c540
-rw-r--r--drivers/net/ethoc.c24
-rw-r--r--drivers/net/fec.c2
-rw-r--r--drivers/net/fec_mpc52xx.c6
-rw-r--r--drivers/net/fec_mpc52xx_phy.c1
-rw-r--r--drivers/net/forcedeth.c5
-rw-r--r--drivers/net/fs_enet/fs_enet-main.c1
-rw-r--r--drivers/net/fs_enet/mii-bitbang.c1
-rw-r--r--drivers/net/fs_enet/mii-fec.c1
-rw-r--r--drivers/net/fsl_pq_mdio.c2
-rw-r--r--drivers/net/gianfar.c4
-rw-r--r--drivers/net/ibm_newemac/core.c9
-rw-r--r--drivers/net/ibm_newemac/emac.h5
-rw-r--r--drivers/net/ifb.c3
-rw-r--r--drivers/net/igb/igb_ethtool.c35
-rw-r--r--drivers/net/igbvf/ethtool.c30
-rw-r--r--drivers/net/irda/sa1100_ir.c7
-rw-r--r--drivers/net/ixgbe/ixgbe_ethtool.c22
-rw-r--r--drivers/net/ixgbe/ixgbe_main.c85
-rw-r--r--drivers/net/ixp2000/enp2611.c18
-rw-r--r--drivers/net/ixp2000/ixpdev.c11
-rw-r--r--drivers/net/ks8851.c42
-rw-r--r--drivers/net/ks8851.h1
-rw-r--r--drivers/net/ks8851_mll.c142
-rw-r--r--drivers/net/macsonic.c117
-rw-r--r--drivers/net/macvlan.c2
-rw-r--r--drivers/net/mlx4/main.c1
-rw-r--r--drivers/net/myri10ge/myri10ge.c17
-rw-r--r--drivers/net/netxen/netxen_nic.h2
-rw-r--r--drivers/net/netxen/netxen_nic_hdr.h3
-rw-r--r--drivers/net/netxen/netxen_nic_hw.c69
-rw-r--r--drivers/net/netxen/netxen_nic_init.c10
-rw-r--r--drivers/net/netxen/netxen_nic_main.c8
-rw-r--r--drivers/net/niu.c2
-rw-r--r--drivers/net/pcmcia/3c574_cs.c103
-rw-r--r--drivers/net/pcmcia/3c589_cs.c102
-rw-r--r--drivers/net/pcmcia/axnet_cs.c56
-rw-r--r--drivers/net/pcmcia/com20020_cs.c63
-rw-r--r--drivers/net/pcmcia/fmvj18x_cs.c189
-rw-r--r--drivers/net/pcmcia/ibmtr_cs.c71
-rw-r--r--drivers/net/pcmcia/nmclan_cs.c173
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c82
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c340
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c259
-rw-r--r--drivers/net/phy/mdio-gpio.c3
-rw-r--r--drivers/net/ppp_generic.c11
-rw-r--r--drivers/net/pppoe.c129
-rw-r--r--drivers/net/qlge/qlge.h11
-rw-r--r--drivers/net/qlge/qlge_main.c177
-rw-r--r--drivers/net/qlge/qlge_mpi.c118
-rw-r--r--drivers/net/r6040.c2
-rw-r--r--drivers/net/r8169.c1013
-rw-r--r--drivers/net/s2io.c1
-rw-r--r--drivers/net/sfc/rx.c9
-rw-r--r--drivers/net/sfc/sfe4001.c4
-rw-r--r--drivers/net/sh_eth.c1
-rw-r--r--drivers/net/sky2.c2
-rw-r--r--drivers/net/smc91x.c2
-rw-r--r--drivers/net/smsc911x.c2
-rw-r--r--drivers/net/smsc9420.c14
-rw-r--r--drivers/net/stmmac/Kconfig53
-rw-r--r--drivers/net/stmmac/Makefile4
-rw-r--r--drivers/net/stmmac/common.h330
-rw-r--r--drivers/net/stmmac/descs.h163
-rw-r--r--drivers/net/stmmac/gmac.c693
-rw-r--r--drivers/net/stmmac/gmac.h204
-rw-r--r--drivers/net/stmmac/mac100.c517
-rw-r--r--drivers/net/stmmac/mac100.h116
-rw-r--r--drivers/net/stmmac/stmmac.h98
-rw-r--r--drivers/net/stmmac/stmmac_ethtool.c395
-rw-r--r--drivers/net/stmmac/stmmac_main.c2210
-rw-r--r--drivers/net/stmmac/stmmac_mdio.c217
-rw-r--r--drivers/net/stmmac/stmmac_timer.c140
-rw-r--r--drivers/net/stmmac/stmmac_timer.h42
-rw-r--r--drivers/net/sungem.c10
-rw-r--r--drivers/net/tokenring/ibmtr.c11
-rw-r--r--drivers/net/usb/Kconfig2
-rw-r--r--drivers/net/usb/cdc_ether.c42
-rw-r--r--drivers/net/usb/dm9601.c4
-rw-r--r--drivers/net/usb/hso.c8
-rw-r--r--drivers/net/usb/pegasus.c13
-rw-r--r--drivers/net/usb/pegasus.h6
-rw-r--r--drivers/net/usb/rndis_host.c6
-rw-r--r--drivers/net/veth.c35
-rw-r--r--drivers/net/virtio_net.c23
-rw-r--r--drivers/net/vmxnet3/Makefile35
-rw-r--r--drivers/net/vmxnet3/upt1_defs.h96
-rw-r--r--drivers/net/vmxnet3/vmxnet3_defs.h535
-rw-r--r--drivers/net/vmxnet3/vmxnet3_drv.c2574
-rw-r--r--drivers/net/vmxnet3/vmxnet3_ethtool.c566
-rw-r--r--drivers/net/vmxnet3/vmxnet3_int.h389
-rw-r--r--drivers/net/wan/cosa.c1
-rw-r--r--drivers/net/wan/hdlc_cisco.c18
-rw-r--r--drivers/net/wireless/adm8211.h2
-rw-r--r--drivers/net/wireless/airo.c5
-rw-r--r--drivers/net/wireless/airo_cs.c55
-rw-r--r--drivers/net/wireless/ath/ath5k/base.c1
-rw-r--r--drivers/net/wireless/ath/ath5k/led.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/rc.c2
-rw-r--r--drivers/net/wireless/atmel_cs.c51
-rw-r--r--drivers/net/wireless/b43/b43.h168
-rw-r--r--drivers/net/wireless/b43/dma.c15
-rw-r--r--drivers/net/wireless/b43/leds.c4
-rw-r--r--drivers/net/wireless/b43/leds.h5
-rw-r--r--drivers/net/wireless/b43/main.c9
-rw-r--r--drivers/net/wireless/b43/pcmcia.c26
-rw-r--r--drivers/net/wireless/b43/pio.c78
-rw-r--r--drivers/net/wireless/b43/rfkill.c3
-rw-r--r--drivers/net/wireless/b43/xmit.c5
-rw-r--r--drivers/net/wireless/hostap/hostap_cs.c51
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2100.c6
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2200.c141
-rw-r--r--drivers/net/wireless/ipw2x00/libipw.h8
-rw-r--r--drivers/net/wireless/ipw2x00/libipw_module.c42
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-1000.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.c23
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.h20
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rx.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c2
-rw-r--r--drivers/net/wireless/libertas/cmdresp.c1
-rw-r--r--drivers/net/wireless/libertas/ethtool.c17
-rw-r--r--drivers/net/wireless/libertas/if_cs.c72
-rw-r--r--drivers/net/wireless/libertas/if_spi.c10
-rw-r--r--drivers/net/wireless/libertas/if_usb.c2
-rw-r--r--drivers/net/wireless/netwave_cs.c95
-rw-r--r--drivers/net/wireless/orinoco/orinoco_cs.c33
-rw-r--r--drivers/net/wireless/orinoco/spectrum_cs.c60
-rw-r--r--drivers/net/wireless/p54/p54usb.c10
-rw-r--r--drivers/net/wireless/ray_cs.c359
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c4
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00link.c11
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.c9
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c5
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187_leds.c4
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187_rfkill.c1
-rw-r--r--drivers/net/wireless/wavelan_cs.c35
-rw-r--r--drivers/net/wireless/wl3501_cs.c74
-rw-r--r--drivers/net/znet.c8
181 files changed, 13685 insertions, 2806 deletions
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 712776089b46..b2f71f79baaf 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -975,7 +975,7 @@ config ENC28J60_WRITEVERIFY
975 975
976config ETHOC 976config ETHOC
977 tristate "OpenCores 10/100 Mbps Ethernet MAC support" 977 tristate "OpenCores 10/100 Mbps Ethernet MAC support"
978 depends on NET_ETHERNET && HAS_IOMEM 978 depends on NET_ETHERNET && HAS_IOMEM && HAS_DMA
979 select MII 979 select MII
980 select PHYLIB 980 select PHYLIB
981 select CRC32 981 select CRC32
@@ -1741,6 +1741,7 @@ config KS8851
1741config KS8851_MLL 1741config KS8851_MLL
1742 tristate "Micrel KS8851 MLL" 1742 tristate "Micrel KS8851 MLL"
1743 depends on HAS_IOMEM 1743 depends on HAS_IOMEM
1744 select MII
1744 help 1745 help
1745 This platform driver is for Micrel KS8851 Address/data bus 1746 This platform driver is for Micrel KS8851 Address/data bus
1746 multiplexed network chip. 1747 multiplexed network chip.
@@ -2482,6 +2483,8 @@ config S6GMAC
2482 To compile this driver as a module, choose M here. The module 2483 To compile this driver as a module, choose M here. The module
2483 will be called s6gmac. 2484 will be called s6gmac.
2484 2485
2486source "drivers/net/stmmac/Kconfig"
2487
2485endif # NETDEV_1000 2488endif # NETDEV_1000
2486 2489
2487# 2490#
@@ -3230,4 +3233,12 @@ config VIRTIO_NET
3230 This is the virtual network driver for virtio. It can be used with 3233 This is the virtual network driver for virtio. It can be used with
3231 lguest or QEMU based VMMs (like KVM or Xen). Say Y or M. 3234 lguest or QEMU based VMMs (like KVM or Xen). Say Y or M.
3232 3235
3236config VMXNET3
3237 tristate "VMware VMXNET3 ethernet driver"
3238 depends on PCI && X86 && INET
3239 help
3240 This driver supports VMware's vmxnet3 virtual ethernet NIC.
3241 To compile this driver as a module, choose M here: the
3242 module will be called vmxnet3.
3243
3233endif # NETDEVICES 3244endif # NETDEVICES
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index d866b8cf65d1..246323d7f161 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -2,6 +2,10 @@
2# Makefile for the Linux network (ethercard) device drivers. 2# Makefile for the Linux network (ethercard) device drivers.
3# 3#
4 4
5obj-$(CONFIG_MII) += mii.o
6obj-$(CONFIG_MDIO) += mdio.o
7obj-$(CONFIG_PHYLIB) += phy/
8
5obj-$(CONFIG_TI_DAVINCI_EMAC) += davinci_emac.o 9obj-$(CONFIG_TI_DAVINCI_EMAC) += davinci_emac.o
6 10
7obj-$(CONFIG_E1000) += e1000/ 11obj-$(CONFIG_E1000) += e1000/
@@ -26,6 +30,7 @@ obj-$(CONFIG_TEHUTI) += tehuti.o
26obj-$(CONFIG_ENIC) += enic/ 30obj-$(CONFIG_ENIC) += enic/
27obj-$(CONFIG_JME) += jme.o 31obj-$(CONFIG_JME) += jme.o
28obj-$(CONFIG_BE2NET) += benet/ 32obj-$(CONFIG_BE2NET) += benet/
33obj-$(CONFIG_VMXNET3) += vmxnet3/
29 34
30gianfar_driver-objs := gianfar.o \ 35gianfar_driver-objs := gianfar.o \
31 gianfar_ethtool.o \ 36 gianfar_ethtool.o \
@@ -95,15 +100,12 @@ obj-$(CONFIG_VIA_VELOCITY) += via-velocity.o
95obj-$(CONFIG_ADAPTEC_STARFIRE) += starfire.o 100obj-$(CONFIG_ADAPTEC_STARFIRE) += starfire.o
96obj-$(CONFIG_RIONET) += rionet.o 101obj-$(CONFIG_RIONET) += rionet.o
97obj-$(CONFIG_SH_ETH) += sh_eth.o 102obj-$(CONFIG_SH_ETH) += sh_eth.o
103obj-$(CONFIG_STMMAC_ETH) += stmmac/
98 104
99# 105#
100# end link order section 106# end link order section
101# 107#
102 108
103obj-$(CONFIG_MII) += mii.o
104obj-$(CONFIG_MDIO) += mdio.o
105obj-$(CONFIG_PHYLIB) += phy/
106
107obj-$(CONFIG_SUNDANCE) += sundance.o 109obj-$(CONFIG_SUNDANCE) += sundance.o
108obj-$(CONFIG_HAMACHI) += hamachi.o 110obj-$(CONFIG_HAMACHI) += hamachi.o
109obj-$(CONFIG_NET) += Space.o loopback.o 111obj-$(CONFIG_NET) += Space.o loopback.o
diff --git a/drivers/net/acenic.c b/drivers/net/acenic.c
index 5f0b05c2d71f..d82a9a994753 100644
--- a/drivers/net/acenic.c
+++ b/drivers/net/acenic.c
@@ -1209,7 +1209,8 @@ static int __devinit ace_init(struct net_device *dev)
1209 memset(ap->info, 0, sizeof(struct ace_info)); 1209 memset(ap->info, 0, sizeof(struct ace_info));
1210 memset(ap->skb, 0, sizeof(struct ace_skb)); 1210 memset(ap->skb, 0, sizeof(struct ace_skb));
1211 1211
1212 if (ace_load_firmware(dev)) 1212 ecode = ace_load_firmware(dev);
1213 if (ecode)
1213 goto init_error; 1214 goto init_error;
1214 1215
1215 ap->fw_running = 0; 1216 ap->fw_running = 0;
diff --git a/drivers/net/arm/ep93xx_eth.c b/drivers/net/arm/ep93xx_eth.c
index 2be49c817995..b25467ac895c 100644
--- a/drivers/net/arm/ep93xx_eth.c
+++ b/drivers/net/arm/ep93xx_eth.c
@@ -628,15 +628,6 @@ static int ep93xx_open(struct net_device *dev)
628 if (ep93xx_alloc_buffers(ep)) 628 if (ep93xx_alloc_buffers(ep))
629 return -ENOMEM; 629 return -ENOMEM;
630 630
631 if (is_zero_ether_addr(dev->dev_addr)) {
632 random_ether_addr(dev->dev_addr);
633 printk(KERN_INFO "%s: generated random MAC address "
634 "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x.\n", dev->name,
635 dev->dev_addr[0], dev->dev_addr[1],
636 dev->dev_addr[2], dev->dev_addr[3],
637 dev->dev_addr[4], dev->dev_addr[5]);
638 }
639
640 napi_enable(&ep->napi); 631 napi_enable(&ep->napi);
641 632
642 if (ep93xx_start_hw(dev)) { 633 if (ep93xx_start_hw(dev)) {
@@ -877,6 +868,9 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
877 ep->mii.mdio_write = ep93xx_mdio_write; 868 ep->mii.mdio_write = ep93xx_mdio_write;
878 ep->mdc_divisor = 40; /* Max HCLK 100 MHz, min MDIO clk 2.5 MHz. */ 869 ep->mdc_divisor = 40; /* Max HCLK 100 MHz, min MDIO clk 2.5 MHz. */
879 870
871 if (is_zero_ether_addr(dev->dev_addr))
872 random_ether_addr(dev->dev_addr);
873
880 err = register_netdev(dev); 874 err = register_netdev(dev);
881 if (err) { 875 if (err) {
882 dev_err(&pdev->dev, "Failed to register netdev\n"); 876 dev_err(&pdev->dev, "Failed to register netdev\n");
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c
index 04f63c77071d..3f4b4300f533 100644
--- a/drivers/net/au1000_eth.c
+++ b/drivers/net/au1000_eth.c
@@ -34,6 +34,7 @@
34 * 34 *
35 * 35 *
36 */ 36 */
37#include <linux/capability.h>
37#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
38#include <linux/module.h> 39#include <linux/module.h>
39#include <linux/kernel.h> 40#include <linux/kernel.h>
@@ -1087,7 +1088,14 @@ static struct net_device * au1000_probe(int port_num)
1087 return NULL; 1088 return NULL;
1088 } 1089 }
1089 1090
1090 if ((err = register_netdev(dev)) != 0) { 1091 dev->base_addr = base;
1092 dev->irq = irq;
1093 dev->netdev_ops = &au1000_netdev_ops;
1094 SET_ETHTOOL_OPS(dev, &au1000_ethtool_ops);
1095 dev->watchdog_timeo = ETH_TX_TIMEOUT;
1096
1097 err = register_netdev(dev);
1098 if (err != 0) {
1091 printk(KERN_ERR "%s: Cannot register net device, error %d\n", 1099 printk(KERN_ERR "%s: Cannot register net device, error %d\n",
1092 DRV_NAME, err); 1100 DRV_NAME, err);
1093 free_netdev(dev); 1101 free_netdev(dev);
@@ -1208,12 +1216,6 @@ static struct net_device * au1000_probe(int port_num)
1208 aup->tx_db_inuse[i] = pDB; 1216 aup->tx_db_inuse[i] = pDB;
1209 } 1217 }
1210 1218
1211 dev->base_addr = base;
1212 dev->irq = irq;
1213 dev->netdev_ops = &au1000_netdev_ops;
1214 SET_ETHTOOL_OPS(dev, &au1000_ethtool_ops);
1215 dev->watchdog_timeo = ETH_TX_TIMEOUT;
1216
1217 /* 1219 /*
1218 * The boot code uses the ethernet controller, so reset it to start 1220 * The boot code uses the ethernet controller, so reset it to start
1219 * fresh. au1000_init() expects that the device is in reset state. 1221 * fresh. au1000_init() expects that the device is in reset state.
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index e046943ef29d..2a9132343b66 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -912,9 +912,6 @@ static irqreturn_t b44_interrupt(int irq, void *dev_id)
912 bp->istat = istat; 912 bp->istat = istat;
913 __b44_disable_ints(bp); 913 __b44_disable_ints(bp);
914 __napi_schedule(&bp->napi); 914 __napi_schedule(&bp->napi);
915 } else {
916 printk(KERN_ERR PFX "%s: Error, poll already scheduled\n",
917 dev->name);
918 } 915 }
919 916
920irq_ack: 917irq_ack:
diff --git a/drivers/net/benet/be.h b/drivers/net/benet/be.h
index a80da0e14a52..3b79a225628a 100644
--- a/drivers/net/benet/be.h
+++ b/drivers/net/benet/be.h
@@ -259,6 +259,8 @@ struct be_adapter {
259 u32 port_num; 259 u32 port_num;
260 bool promiscuous; 260 bool promiscuous;
261 u32 cap; 261 u32 cap;
262 u32 rx_fc; /* Rx flow control */
263 u32 tx_fc; /* Tx flow control */
262}; 264};
263 265
264extern const struct ethtool_ops be_ethtool_ops; 266extern const struct ethtool_ops be_ethtool_ops;
diff --git a/drivers/net/benet/be_cmds.c b/drivers/net/benet/be_cmds.c
index 89876ade5e33..28a0eda92680 100644
--- a/drivers/net/benet/be_cmds.c
+++ b/drivers/net/benet/be_cmds.c
@@ -243,15 +243,26 @@ static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
243 243
244int be_cmd_POST(struct be_adapter *adapter) 244int be_cmd_POST(struct be_adapter *adapter)
245{ 245{
246 u16 stage, error; 246 u16 stage;
247 int status, timeout = 0;
247 248
248 error = be_POST_stage_get(adapter, &stage); 249 do {
249 if (error || stage != POST_STAGE_ARMFW_RDY) { 250 status = be_POST_stage_get(adapter, &stage);
250 dev_err(&adapter->pdev->dev, "POST failed.\n"); 251 if (status) {
251 return -1; 252 dev_err(&adapter->pdev->dev, "POST error; stage=0x%x\n",
252 } 253 stage);
254 return -1;
255 } else if (stage != POST_STAGE_ARMFW_RDY) {
256 set_current_state(TASK_INTERRUPTIBLE);
257 schedule_timeout(2 * HZ);
258 timeout += 2;
259 } else {
260 return 0;
261 }
262 } while (timeout < 20);
253 263
254 return 0; 264 dev_err(&adapter->pdev->dev, "POST timeout; stage=0x%x\n", stage);
265 return -1;
255} 266}
256 267
257static inline void *embedded_payload(struct be_mcc_wrb *wrb) 268static inline void *embedded_payload(struct be_mcc_wrb *wrb)
@@ -729,8 +740,8 @@ int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
729/* Create an rx filtering policy configuration on an i/f 740/* Create an rx filtering policy configuration on an i/f
730 * Uses mbox 741 * Uses mbox
731 */ 742 */
732int be_cmd_if_create(struct be_adapter *adapter, u32 flags, u8 *mac, 743int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
733 bool pmac_invalid, u32 *if_handle, u32 *pmac_id) 744 u8 *mac, bool pmac_invalid, u32 *if_handle, u32 *pmac_id)
734{ 745{
735 struct be_mcc_wrb *wrb; 746 struct be_mcc_wrb *wrb;
736 struct be_cmd_req_if_create *req; 747 struct be_cmd_req_if_create *req;
@@ -746,8 +757,8 @@ int be_cmd_if_create(struct be_adapter *adapter, u32 flags, u8 *mac,
746 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, 757 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
747 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req)); 758 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req));
748 759
749 req->capability_flags = cpu_to_le32(flags); 760 req->capability_flags = cpu_to_le32(cap_flags);
750 req->enable_flags = cpu_to_le32(flags); 761 req->enable_flags = cpu_to_le32(en_flags);
751 req->pmac_invalid = pmac_invalid; 762 req->pmac_invalid = pmac_invalid;
752 if (!pmac_invalid) 763 if (!pmac_invalid)
753 memcpy(req->mac_addr, mac, ETH_ALEN); 764 memcpy(req->mac_addr, mac, ETH_ALEN);
diff --git a/drivers/net/benet/be_cmds.h b/drivers/net/benet/be_cmds.h
index a86f917f85f4..e5f9676cf1bc 100644
--- a/drivers/net/benet/be_cmds.h
+++ b/drivers/net/benet/be_cmds.h
@@ -68,7 +68,7 @@ enum {
68#define CQE_STATUS_COMPL_MASK 0xFFFF 68#define CQE_STATUS_COMPL_MASK 0xFFFF
69#define CQE_STATUS_COMPL_SHIFT 0 /* bits 0 - 15 */ 69#define CQE_STATUS_COMPL_SHIFT 0 /* bits 0 - 15 */
70#define CQE_STATUS_EXTD_MASK 0xFFFF 70#define CQE_STATUS_EXTD_MASK 0xFFFF
71#define CQE_STATUS_EXTD_SHIFT 0 /* bits 0 - 15 */ 71#define CQE_STATUS_EXTD_SHIFT 16 /* bits 16 - 31 */
72 72
73struct be_mcc_compl { 73struct be_mcc_compl {
74 u32 status; /* dword 0 */ 74 u32 status; /* dword 0 */
@@ -720,8 +720,9 @@ extern int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
720extern int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr, 720extern int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
721 u32 if_id, u32 *pmac_id); 721 u32 if_id, u32 *pmac_id);
722extern int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id); 722extern int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id);
723extern int be_cmd_if_create(struct be_adapter *adapter, u32 if_flags, u8 *mac, 723extern int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags,
724 bool pmac_invalid, u32 *if_handle, u32 *pmac_id); 724 u32 en_flags, u8 *mac, bool pmac_invalid,
725 u32 *if_handle, u32 *pmac_id);
725extern int be_cmd_if_destroy(struct be_adapter *adapter, u32 if_handle); 726extern int be_cmd_if_destroy(struct be_adapter *adapter, u32 if_handle);
726extern int be_cmd_eq_create(struct be_adapter *adapter, 727extern int be_cmd_eq_create(struct be_adapter *adapter,
727 struct be_queue_info *eq, int eq_delay); 728 struct be_queue_info *eq, int eq_delay);
diff --git a/drivers/net/benet/be_ethtool.c b/drivers/net/benet/be_ethtool.c
index cda5bf2fc50a..f0fd95b43c07 100644
--- a/drivers/net/benet/be_ethtool.c
+++ b/drivers/net/benet/be_ethtool.c
@@ -323,10 +323,12 @@ be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
323 323
324 if (ecmd->autoneg != 0) 324 if (ecmd->autoneg != 0)
325 return -EINVAL; 325 return -EINVAL;
326 adapter->tx_fc = ecmd->tx_pause;
327 adapter->rx_fc = ecmd->rx_pause;
326 328
327 status = be_cmd_set_flow_control(adapter, ecmd->tx_pause, 329 status = be_cmd_set_flow_control(adapter,
328 ecmd->rx_pause); 330 adapter->tx_fc, adapter->rx_fc);
329 if (!status) 331 if (status)
330 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n"); 332 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
331 333
332 return status; 334 return status;
diff --git a/drivers/net/benet/be_main.c b/drivers/net/benet/be_main.c
index 6d5e81f7046f..876b357101fa 100644
--- a/drivers/net/benet/be_main.c
+++ b/drivers/net/benet/be_main.c
@@ -1610,29 +1610,42 @@ static int be_open(struct net_device *netdev)
1610 1610
1611 status = be_cmd_link_status_query(adapter, &link_up); 1611 status = be_cmd_link_status_query(adapter, &link_up);
1612 if (status) 1612 if (status)
1613 return status; 1613 goto ret_sts;
1614 be_link_status_update(adapter, link_up); 1614 be_link_status_update(adapter, link_up);
1615 1615
1616 status = be_vid_config(adapter);
1617 if (status)
1618 goto ret_sts;
1619
1620 status = be_cmd_set_flow_control(adapter,
1621 adapter->tx_fc, adapter->rx_fc);
1622 if (status)
1623 goto ret_sts;
1624
1616 schedule_delayed_work(&adapter->work, msecs_to_jiffies(100)); 1625 schedule_delayed_work(&adapter->work, msecs_to_jiffies(100));
1617 return 0; 1626ret_sts:
1627 return status;
1618} 1628}
1619 1629
1620static int be_setup(struct be_adapter *adapter) 1630static int be_setup(struct be_adapter *adapter)
1621{ 1631{
1622 struct net_device *netdev = adapter->netdev; 1632 struct net_device *netdev = adapter->netdev;
1623 u32 if_flags; 1633 u32 cap_flags, en_flags;
1624 int status; 1634 int status;
1625 1635
1626 if_flags = BE_IF_FLAGS_BROADCAST | BE_IF_FLAGS_PROMISCUOUS | 1636 cap_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST |
1627 BE_IF_FLAGS_MCAST_PROMISCUOUS | BE_IF_FLAGS_UNTAGGED | 1637 BE_IF_FLAGS_MCAST_PROMISCUOUS |
1628 BE_IF_FLAGS_PASS_L3L4_ERRORS; 1638 BE_IF_FLAGS_PROMISCUOUS |
1629 status = be_cmd_if_create(adapter, if_flags, netdev->dev_addr, 1639 BE_IF_FLAGS_PASS_L3L4_ERRORS;
1630 false/* pmac_invalid */, &adapter->if_handle, 1640 en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST |
1631 &adapter->pmac_id); 1641 BE_IF_FLAGS_PASS_L3L4_ERRORS;
1642
1643 status = be_cmd_if_create(adapter, cap_flags, en_flags,
1644 netdev->dev_addr, false/* pmac_invalid */,
1645 &adapter->if_handle, &adapter->pmac_id);
1632 if (status != 0) 1646 if (status != 0)
1633 goto do_none; 1647 goto do_none;
1634 1648
1635
1636 status = be_tx_queues_create(adapter); 1649 status = be_tx_queues_create(adapter);
1637 if (status != 0) 1650 if (status != 0)
1638 goto if_destroy; 1651 goto if_destroy;
@@ -1645,17 +1658,8 @@ static int be_setup(struct be_adapter *adapter)
1645 if (status != 0) 1658 if (status != 0)
1646 goto rx_qs_destroy; 1659 goto rx_qs_destroy;
1647 1660
1648 status = be_vid_config(adapter);
1649 if (status != 0)
1650 goto mccqs_destroy;
1651
1652 status = be_cmd_set_flow_control(adapter, true, true);
1653 if (status != 0)
1654 goto mccqs_destroy;
1655 return 0; 1661 return 0;
1656 1662
1657mccqs_destroy:
1658 be_mcc_queues_destroy(adapter);
1659rx_qs_destroy: 1663rx_qs_destroy:
1660 be_rx_queues_destroy(adapter); 1664 be_rx_queues_destroy(adapter);
1661tx_qs_destroy: 1665tx_qs_destroy:
@@ -1906,6 +1910,10 @@ static void be_netdev_init(struct net_device *netdev)
1906 1910
1907 adapter->rx_csum = true; 1911 adapter->rx_csum = true;
1908 1912
1913 /* Default settings for Rx and Tx flow control */
1914 adapter->rx_fc = true;
1915 adapter->tx_fc = true;
1916
1909 netif_set_gso_max_size(netdev, 65535); 1917 netif_set_gso_max_size(netdev, 65535);
1910 1918
1911 BE_SET_NETDEV_OPS(netdev, &be_netdev_ops); 1919 BE_SET_NETDEV_OPS(netdev, &be_netdev_ops);
@@ -2055,6 +2063,10 @@ static int be_hw_up(struct be_adapter *adapter)
2055 if (status) 2063 if (status)
2056 return status; 2064 return status;
2057 2065
2066 status = be_cmd_reset_function(adapter);
2067 if (status)
2068 return status;
2069
2058 status = be_cmd_get_fw_ver(adapter, adapter->fw_ver); 2070 status = be_cmd_get_fw_ver(adapter, adapter->fw_ver);
2059 if (status) 2071 if (status)
2060 return status; 2072 return status;
@@ -2108,10 +2120,6 @@ static int __devinit be_probe(struct pci_dev *pdev,
2108 if (status) 2120 if (status)
2109 goto free_netdev; 2121 goto free_netdev;
2110 2122
2111 status = be_cmd_reset_function(adapter);
2112 if (status)
2113 goto ctrl_clean;
2114
2115 status = be_stats_init(adapter); 2123 status = be_stats_init(adapter);
2116 if (status) 2124 if (status)
2117 goto ctrl_clean; 2125 goto ctrl_clean;
@@ -2168,6 +2176,7 @@ static int be_suspend(struct pci_dev *pdev, pm_message_t state)
2168 be_close(netdev); 2176 be_close(netdev);
2169 rtnl_unlock(); 2177 rtnl_unlock();
2170 } 2178 }
2179 be_cmd_get_flow_control(adapter, &adapter->tx_fc, &adapter->rx_fc);
2171 be_clear(adapter); 2180 be_clear(adapter);
2172 2181
2173 pci_save_state(pdev); 2182 pci_save_state(pdev);
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h
index 6c7f795d12de..a4d83409f205 100644
--- a/drivers/net/bnx2.h
+++ b/drivers/net/bnx2.h
@@ -361,9 +361,12 @@ struct l2_fhdr {
361#define BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE (1<<28) 361#define BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE (1<<28)
362 362
363#define BNX2_L2CTX_HOST_BDIDX 0x00000004 363#define BNX2_L2CTX_HOST_BDIDX 0x00000004
364#define BNX2_L2CTX_STATUSB_NUM_SHIFT 16 364#define BNX2_L2CTX_L5_STATUSB_NUM_SHIFT 16
365#define BNX2_L2CTX_STATUSB_NUM(sb_id) \ 365#define BNX2_L2CTX_L2_STATUSB_NUM_SHIFT 24
366 (((sb_id) > 0) ? (((sb_id) + 7) << BNX2_L2CTX_STATUSB_NUM_SHIFT) : 0) 366#define BNX2_L2CTX_L5_STATUSB_NUM(sb_id) \
367 (((sb_id) > 0) ? (((sb_id) + 7) << BNX2_L2CTX_L5_STATUSB_NUM_SHIFT) : 0)
368#define BNX2_L2CTX_L2_STATUSB_NUM(sb_id) \
369 (((sb_id) > 0) ? (((sb_id) + 7) << BNX2_L2CTX_L2_STATUSB_NUM_SHIFT) : 0)
367#define BNX2_L2CTX_HOST_BSEQ 0x00000008 370#define BNX2_L2CTX_HOST_BSEQ 0x00000008
368#define BNX2_L2CTX_NX_BSEQ 0x0000000c 371#define BNX2_L2CTX_NX_BSEQ 0x0000000c
369#define BNX2_L2CTX_NX_BDHADDR_HI 0x00000010 372#define BNX2_L2CTX_NX_BDHADDR_HI 0x00000010
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 69c5b15e22da..40fb5eefc72e 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -691,7 +691,7 @@ static int bond_check_dev_link(struct bonding *bond,
691 struct net_device *slave_dev, int reporting) 691 struct net_device *slave_dev, int reporting)
692{ 692{
693 const struct net_device_ops *slave_ops = slave_dev->netdev_ops; 693 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
694 static int (*ioctl)(struct net_device *, struct ifreq *, int); 694 int (*ioctl)(struct net_device *, struct ifreq *, int);
695 struct ifreq ifr; 695 struct ifreq ifr;
696 struct mii_ioctl_data *mii; 696 struct mii_ioctl_data *mii;
697 697
@@ -3665,10 +3665,10 @@ static int bond_xmit_hash_policy_l23(struct sk_buff *skb,
3665 3665
3666 if (skb->protocol == htons(ETH_P_IP)) { 3666 if (skb->protocol == htons(ETH_P_IP)) {
3667 return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^ 3667 return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^
3668 (data->h_dest[5] ^ bond_dev->dev_addr[5])) % count; 3668 (data->h_dest[5] ^ data->h_source[5])) % count;
3669 } 3669 }
3670 3670
3671 return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count; 3671 return (data->h_dest[5] ^ data->h_source[5]) % count;
3672} 3672}
3673 3673
3674/* 3674/*
@@ -3695,7 +3695,7 @@ static int bond_xmit_hash_policy_l34(struct sk_buff *skb,
3695 3695
3696 } 3696 }
3697 3697
3698 return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count; 3698 return (data->h_dest[5] ^ data->h_source[5]) % count;
3699} 3699}
3700 3700
3701/* 3701/*
@@ -3706,7 +3706,7 @@ static int bond_xmit_hash_policy_l2(struct sk_buff *skb,
3706{ 3706{
3707 struct ethhdr *data = (struct ethhdr *)skb->data; 3707 struct ethhdr *data = (struct ethhdr *)skb->data;
3708 3708
3709 return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count; 3709 return (data->h_dest[5] ^ data->h_source[5]) % count;
3710} 3710}
3711 3711
3712/*-------------------------- Device entry points ----------------------------*/ 3712/*-------------------------- Device entry points ----------------------------*/
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index df32c109b7ac..772f6d2489ce 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -35,66 +35,16 @@ config CAN_CALC_BITTIMING
35 arguments "tq", "prop_seg", "phase_seg1", "phase_seg2" and "sjw". 35 arguments "tq", "prop_seg", "phase_seg1", "phase_seg2" and "sjw".
36 If unsure, say Y. 36 If unsure, say Y.
37 37
38config CAN_SJA1000
39 depends on CAN_DEV && HAS_IOMEM
40 tristate "Philips SJA1000"
41 ---help---
42 Driver for the SJA1000 CAN controllers from Philips or NXP
43
44config CAN_SJA1000_ISA
45 depends on CAN_SJA1000 && ISA
46 tristate "ISA Bus based legacy SJA1000 driver"
47 ---help---
48 This driver adds legacy support for SJA1000 chips connected to
49 the ISA bus using I/O port, memory mapped or indirect access.
50
51config CAN_SJA1000_PLATFORM
52 depends on CAN_SJA1000
53 tristate "Generic Platform Bus based SJA1000 driver"
54 ---help---
55 This driver adds support for the SJA1000 chips connected to
56 the "platform bus" (Linux abstraction for directly to the
57 processor attached devices). Which can be found on various
58 boards from Phytec (http://www.phytec.de) like the PCM027,
59 PCM038.
60
61config CAN_SJA1000_OF_PLATFORM
62 depends on CAN_SJA1000 && PPC_OF
63 tristate "Generic OF Platform Bus based SJA1000 driver"
64 ---help---
65 This driver adds support for the SJA1000 chips connected to
66 the OpenFirmware "platform bus" found on embedded systems with
67 OpenFirmware bindings, e.g. if you have a PowerPC based system
68 you may want to enable this option.
69
70config CAN_EMS_PCI
71 tristate "EMS CPC-PCI, CPC-PCIe and CPC-104P Card"
72 depends on PCI && CAN_SJA1000
73 ---help---
74 This driver is for the one, two or four channel CPC-PCI,
75 CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche
76 (http://www.ems-wuensche.de).
77
78config CAN_EMS_USB
79 tristate "EMS CPC-USB/ARM7 CAN/USB interface"
80 depends on USB && CAN_DEV
81 ---help---
82 This driver is for the one channel CPC-USB/ARM7 CAN/USB interface
83 from from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de).
84
85config CAN_KVASER_PCI
86 tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards"
87 depends on PCI && CAN_SJA1000
88 ---help---
89 This driver is for the the PCIcanx and PCIcan cards (1, 2 or
90 4 channel) from Kvaser (http://www.kvaser.com).
91
92config CAN_AT91 38config CAN_AT91
93 tristate "Atmel AT91 onchip CAN controller" 39 tristate "Atmel AT91 onchip CAN controller"
94 depends on CAN && CAN_DEV && ARCH_AT91SAM9263 40 depends on CAN_DEV && ARCH_AT91SAM9263
95 ---help--- 41 ---help---
96 This is a driver for the SoC CAN controller in Atmel's AT91SAM9263. 42 This is a driver for the SoC CAN controller in Atmel's AT91SAM9263.
97 43
44source "drivers/net/can/sja1000/Kconfig"
45
46source "drivers/net/can/usb/Kconfig"
47
98config CAN_DEBUG_DEVICES 48config CAN_DEBUG_DEVICES
99 bool "CAN devices debugging messages" 49 bool "CAN devices debugging messages"
100 depends on CAN 50 depends on CAN
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index f0b9a1e1db46..2868fe842a41 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -589,6 +589,22 @@ static int can_changelink(struct net_device *dev,
589 return 0; 589 return 0;
590} 590}
591 591
592static size_t can_get_size(const struct net_device *dev)
593{
594 struct can_priv *priv = netdev_priv(dev);
595 size_t size;
596
597 size = nla_total_size(sizeof(u32)); /* IFLA_CAN_STATE */
598 size += sizeof(struct can_ctrlmode); /* IFLA_CAN_CTRLMODE */
599 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_RESTART_MS */
600 size += sizeof(struct can_bittiming); /* IFLA_CAN_BITTIMING */
601 size += sizeof(struct can_clock); /* IFLA_CAN_CLOCK */
602 if (priv->bittiming_const) /* IFLA_CAN_BITTIMING_CONST */
603 size += sizeof(struct can_bittiming_const);
604
605 return size;
606}
607
592static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) 608static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
593{ 609{
594 struct can_priv *priv = netdev_priv(dev); 610 struct can_priv *priv = netdev_priv(dev);
@@ -613,6 +629,11 @@ nla_put_failure:
613 return -EMSGSIZE; 629 return -EMSGSIZE;
614} 630}
615 631
632static size_t can_get_xstats_size(const struct net_device *dev)
633{
634 return sizeof(struct can_device_stats);
635}
636
616static int can_fill_xstats(struct sk_buff *skb, const struct net_device *dev) 637static int can_fill_xstats(struct sk_buff *skb, const struct net_device *dev)
617{ 638{
618 struct can_priv *priv = netdev_priv(dev); 639 struct can_priv *priv = netdev_priv(dev);
@@ -639,7 +660,9 @@ static struct rtnl_link_ops can_link_ops __read_mostly = {
639 .setup = can_setup, 660 .setup = can_setup,
640 .newlink = can_newlink, 661 .newlink = can_newlink,
641 .changelink = can_changelink, 662 .changelink = can_changelink,
663 .get_size = can_get_size,
642 .fill_info = can_fill_info, 664 .fill_info = can_fill_info,
665 .get_xstats_size = can_get_xstats_size,
643 .fill_xstats = can_fill_xstats, 666 .fill_xstats = can_fill_xstats,
644}; 667};
645 668
diff --git a/drivers/net/can/sja1000/Kconfig b/drivers/net/can/sja1000/Kconfig
new file mode 100644
index 000000000000..4c674927f247
--- /dev/null
+++ b/drivers/net/can/sja1000/Kconfig
@@ -0,0 +1,47 @@
1menuconfig CAN_SJA1000
2 tristate "Philips/NXP SJA1000 devices"
3 depends on CAN_DEV && HAS_IOMEM
4
5if CAN_SJA1000
6
7config CAN_SJA1000_ISA
8 tristate "ISA Bus based legacy SJA1000 driver"
9 depends on ISA
10 ---help---
11 This driver adds legacy support for SJA1000 chips connected to
12 the ISA bus using I/O port, memory mapped or indirect access.
13
14config CAN_SJA1000_PLATFORM
15 tristate "Generic Platform Bus based SJA1000 driver"
16 ---help---
17 This driver adds support for the SJA1000 chips connected to
18 the "platform bus" (Linux abstraction for directly to the
19 processor attached devices). Which can be found on various
20 boards from Phytec (http://www.phytec.de) like the PCM027,
21 PCM038.
22
23config CAN_SJA1000_OF_PLATFORM
24 tristate "Generic OF Platform Bus based SJA1000 driver"
25 depends on PPC_OF
26 ---help---
27 This driver adds support for the SJA1000 chips connected to
28 the OpenFirmware "platform bus" found on embedded systems with
29 OpenFirmware bindings, e.g. if you have a PowerPC based system
30 you may want to enable this option.
31
32config CAN_EMS_PCI
33 tristate "EMS CPC-PCI, CPC-PCIe and CPC-104P Card"
34 depends on PCI
35 ---help---
36 This driver is for the one, two or four channel CPC-PCI,
37 CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche
38 (http://www.ems-wuensche.de).
39
40config CAN_KVASER_PCI
41 tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards"
42 depends on PCI
43 ---help---
44 This driver is for the the PCIcanx and PCIcan cards (1, 2 or
45 4 channel) from Kvaser (http://www.kvaser.com).
46
47endif
diff --git a/drivers/net/can/sja1000/sja1000_of_platform.c b/drivers/net/can/sja1000/sja1000_of_platform.c
index 3373560405ba..9dd076a626a5 100644
--- a/drivers/net/can/sja1000/sja1000_of_platform.c
+++ b/drivers/net/can/sja1000/sja1000_of_platform.c
@@ -213,6 +213,7 @@ static struct of_device_id __devinitdata sja1000_ofp_table[] = {
213 {.compatible = "nxp,sja1000"}, 213 {.compatible = "nxp,sja1000"},
214 {}, 214 {},
215}; 215};
216MODULE_DEVICE_TABLE(of, sja1000_ofp_table);
216 217
217static struct of_platform_driver sja1000_ofp_driver = { 218static struct of_platform_driver sja1000_ofp_driver = {
218 .owner = THIS_MODULE, 219 .owner = THIS_MODULE,
diff --git a/drivers/net/can/usb/Kconfig b/drivers/net/can/usb/Kconfig
new file mode 100644
index 000000000000..bbc78e0b8a15
--- /dev/null
+++ b/drivers/net/can/usb/Kconfig
@@ -0,0 +1,10 @@
1menu "CAN USB interfaces"
2 depends on USB && CAN_DEV
3
4config CAN_EMS_USB
5 tristate "EMS CPC-USB/ARM7 CAN/USB interface"
6 ---help---
7 This driver is for the one channel CPC-USB/ARM7 CAN/USB interface
8 from from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de).
9
10endmenu
diff --git a/drivers/net/can/usb/Makefile b/drivers/net/can/usb/Makefile
index c3f75ba701b1..0afd51d4c7a5 100644
--- a/drivers/net/can/usb/Makefile
+++ b/drivers/net/can/usb/Makefile
@@ -3,3 +3,5 @@
3# 3#
4 4
5obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o 5obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o
6
7ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 9012e0abc626..abdbd9c2b788 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -319,7 +319,7 @@ static void ems_usb_rx_can_msg(struct ems_usb *dev, struct ems_cpc_msg *msg)
319 319
320 cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame)); 320 cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
321 321
322 cf->can_id = msg->msg.can_msg.id; 322 cf->can_id = le32_to_cpu(msg->msg.can_msg.id);
323 cf->can_dlc = min_t(u8, msg->msg.can_msg.length, 8); 323 cf->can_dlc = min_t(u8, msg->msg.can_msg.length, 8);
324 324
325 if (msg->type == CPC_MSG_TYPE_EXT_CAN_FRAME 325 if (msg->type == CPC_MSG_TYPE_EXT_CAN_FRAME
@@ -813,6 +813,9 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
813 msg->length = CPC_CAN_MSG_MIN_SIZE + cf->can_dlc; 813 msg->length = CPC_CAN_MSG_MIN_SIZE + cf->can_dlc;
814 } 814 }
815 815
816 /* Respect byte order */
817 msg->msg.can_msg.id = cpu_to_le32(msg->msg.can_msg.id);
818
816 for (i = 0; i < MAX_TX_URBS; i++) { 819 for (i = 0; i < MAX_TX_URBS; i++) {
817 if (dev->tx_contexts[i].echo_index == MAX_TX_URBS) { 820 if (dev->tx_contexts[i].echo_index == MAX_TX_URBS) {
818 context = &dev->tx_contexts[i]; 821 context = &dev->tx_contexts[i];
diff --git a/drivers/net/cassini.c b/drivers/net/cassini.c
index 05916aafa4f1..f857afe8e488 100644
--- a/drivers/net/cassini.c
+++ b/drivers/net/cassini.c
@@ -4342,11 +4342,11 @@ static int cas_open(struct net_device *dev)
4342 cas_unlock_all_restore(cp, flags); 4342 cas_unlock_all_restore(cp, flags);
4343 } 4343 }
4344 4344
4345 err = -ENOMEM;
4345 if (cas_tx_tiny_alloc(cp) < 0) 4346 if (cas_tx_tiny_alloc(cp) < 0)
4346 return -ENOMEM; 4347 goto err_unlock;
4347 4348
4348 /* alloc rx descriptors */ 4349 /* alloc rx descriptors */
4349 err = -ENOMEM;
4350 if (cas_alloc_rxds(cp) < 0) 4350 if (cas_alloc_rxds(cp) < 0)
4351 goto err_tx_tiny; 4351 goto err_tx_tiny;
4352 4352
@@ -4386,6 +4386,7 @@ err_spare:
4386 cas_free_rxds(cp); 4386 cas_free_rxds(cp);
4387err_tx_tiny: 4387err_tx_tiny:
4388 cas_tx_tiny_free(cp); 4388 cas_tx_tiny_free(cp);
4389err_unlock:
4389 mutex_unlock(&cp->pm_mutex); 4390 mutex_unlock(&cp->pm_mutex);
4390 return err; 4391 return err;
4391} 4392}
diff --git a/drivers/net/cnic.c b/drivers/net/cnic.c
index 46c87ec7960c..3bf1b04f2cab 100644
--- a/drivers/net/cnic.c
+++ b/drivers/net/cnic.c
@@ -2264,9 +2264,9 @@ static void cnic_init_bnx2_rx_ring(struct cnic_dev *dev)
2264 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_CTX_TYPE, val); 2264 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_CTX_TYPE, val);
2265 2265
2266 if (sb_id == 0) 2266 if (sb_id == 0)
2267 val = 2 << BNX2_L2CTX_STATUSB_NUM_SHIFT; 2267 val = 2 << BNX2_L2CTX_L2_STATUSB_NUM_SHIFT;
2268 else 2268 else
2269 val = BNX2_L2CTX_STATUSB_NUM(sb_id); 2269 val = BNX2_L2CTX_L2_STATUSB_NUM(sb_id);
2270 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_HOST_BDIDX, val); 2270 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_HOST_BDIDX, val);
2271 2271
2272 rxbd = (struct rx_bd *) (cp->l2_ring + BCM_PAGE_SIZE); 2272 rxbd = (struct rx_bd *) (cp->l2_ring + BCM_PAGE_SIZE);
@@ -2423,7 +2423,7 @@ static int cnic_start_bnx2_hw(struct cnic_dev *dev)
2423 cp->int_num = 0; 2423 cp->int_num = 0;
2424 if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) { 2424 if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
2425 u32 sb_id = cp->status_blk_num; 2425 u32 sb_id = cp->status_blk_num;
2426 u32 sb = BNX2_L2CTX_STATUSB_NUM(sb_id); 2426 u32 sb = BNX2_L2CTX_L5_STATUSB_NUM(sb_id);
2427 2427
2428 cp->int_num = sb_id << BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT; 2428 cp->int_num = sb_id << BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT;
2429 cnic_ctx_wr(dev, cp->kwq_cid_addr, L5_KRNLQ_HOST_QIDX, sb); 2429 cnic_ctx_wr(dev, cp->kwq_cid_addr, L5_KRNLQ_HOST_QIDX, sb);
diff --git a/drivers/net/cxgb3/sge.c b/drivers/net/cxgb3/sge.c
index f86612857a73..6366061712f4 100644
--- a/drivers/net/cxgb3/sge.c
+++ b/drivers/net/cxgb3/sge.c
@@ -879,7 +879,7 @@ recycle:
879 pci_dma_sync_single_for_cpu(adap->pdev, dma_addr, len, 879 pci_dma_sync_single_for_cpu(adap->pdev, dma_addr, len,
880 PCI_DMA_FROMDEVICE); 880 PCI_DMA_FROMDEVICE);
881 (*sd->pg_chunk.p_cnt)--; 881 (*sd->pg_chunk.p_cnt)--;
882 if (!*sd->pg_chunk.p_cnt) 882 if (!*sd->pg_chunk.p_cnt && sd->pg_chunk.page != fl->pg_chunk.page)
883 pci_unmap_page(adap->pdev, 883 pci_unmap_page(adap->pdev,
884 sd->pg_chunk.mapping, 884 sd->pg_chunk.mapping,
885 fl->alloc_size, 885 fl->alloc_size,
@@ -2088,7 +2088,7 @@ static void lro_add_page(struct adapter *adap, struct sge_qset *qs,
2088 PCI_DMA_FROMDEVICE); 2088 PCI_DMA_FROMDEVICE);
2089 2089
2090 (*sd->pg_chunk.p_cnt)--; 2090 (*sd->pg_chunk.p_cnt)--;
2091 if (!*sd->pg_chunk.p_cnt) 2091 if (!*sd->pg_chunk.p_cnt && sd->pg_chunk.page != fl->pg_chunk.page)
2092 pci_unmap_page(adap->pdev, 2092 pci_unmap_page(adap->pdev,
2093 sd->pg_chunk.mapping, 2093 sd->pg_chunk.mapping,
2094 fl->alloc_size, 2094 fl->alloc_size,
diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index 65a2d0ba64e2..e3478314c002 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -164,16 +164,14 @@ static const char emac_version_string[] = "TI DaVinci EMAC Linux v6.1";
164# define EMAC_MBP_MCASTCHAN(ch) ((ch) & 0x7) 164# define EMAC_MBP_MCASTCHAN(ch) ((ch) & 0x7)
165 165
166/* EMAC mac_control register */ 166/* EMAC mac_control register */
167#define EMAC_MACCONTROL_TXPTYPE (0x200) 167#define EMAC_MACCONTROL_TXPTYPE BIT(9)
168#define EMAC_MACCONTROL_TXPACEEN (0x40) 168#define EMAC_MACCONTROL_TXPACEEN BIT(6)
169#define EMAC_MACCONTROL_MIIEN (0x20) 169#define EMAC_MACCONTROL_GMIIEN BIT(5)
170#define EMAC_MACCONTROL_GIGABITEN (0x80) 170#define EMAC_MACCONTROL_GIGABITEN BIT(7)
171#define EMAC_MACCONTROL_GIGABITEN_SHIFT (7) 171#define EMAC_MACCONTROL_FULLDUPLEXEN BIT(0)
172#define EMAC_MACCONTROL_FULLDUPLEXEN (0x1)
173#define EMAC_MACCONTROL_RMIISPEED_MASK BIT(15) 172#define EMAC_MACCONTROL_RMIISPEED_MASK BIT(15)
174 173
175/* GIGABIT MODE related bits */ 174/* GIGABIT MODE related bits */
176#define EMAC_DM646X_MACCONTORL_GMIIEN BIT(5)
177#define EMAC_DM646X_MACCONTORL_GIG BIT(7) 175#define EMAC_DM646X_MACCONTORL_GIG BIT(7)
178#define EMAC_DM646X_MACCONTORL_GIGFORCE BIT(17) 176#define EMAC_DM646X_MACCONTORL_GIGFORCE BIT(17)
179 177
@@ -192,10 +190,10 @@ static const char emac_version_string[] = "TI DaVinci EMAC Linux v6.1";
192#define EMAC_RX_BUFFER_OFFSET_MASK (0xFFFF) 190#define EMAC_RX_BUFFER_OFFSET_MASK (0xFFFF)
193 191
194/* MAC_IN_VECTOR (0x180) register bit fields */ 192/* MAC_IN_VECTOR (0x180) register bit fields */
195#define EMAC_DM644X_MAC_IN_VECTOR_HOST_INT (0x20000) 193#define EMAC_DM644X_MAC_IN_VECTOR_HOST_INT BIT(17)
196#define EMAC_DM644X_MAC_IN_VECTOR_STATPEND_INT (0x10000) 194#define EMAC_DM644X_MAC_IN_VECTOR_STATPEND_INT BIT(16)
197#define EMAC_DM644X_MAC_IN_VECTOR_RX_INT_VEC (0x0100) 195#define EMAC_DM644X_MAC_IN_VECTOR_RX_INT_VEC BIT(8)
198#define EMAC_DM644X_MAC_IN_VECTOR_TX_INT_VEC (0x01) 196#define EMAC_DM644X_MAC_IN_VECTOR_TX_INT_VEC BIT(0)
199 197
200/** NOTE:: For DM646x the IN_VECTOR has changed */ 198/** NOTE:: For DM646x the IN_VECTOR has changed */
201#define EMAC_DM646X_MAC_IN_VECTOR_RX_INT_VEC BIT(EMAC_DEF_RX_CH) 199#define EMAC_DM646X_MAC_IN_VECTOR_RX_INT_VEC BIT(EMAC_DEF_RX_CH)
@@ -203,7 +201,6 @@ static const char emac_version_string[] = "TI DaVinci EMAC Linux v6.1";
203#define EMAC_DM646X_MAC_IN_VECTOR_HOST_INT BIT(26) 201#define EMAC_DM646X_MAC_IN_VECTOR_HOST_INT BIT(26)
204#define EMAC_DM646X_MAC_IN_VECTOR_STATPEND_INT BIT(27) 202#define EMAC_DM646X_MAC_IN_VECTOR_STATPEND_INT BIT(27)
205 203
206
207/* CPPI bit positions */ 204/* CPPI bit positions */
208#define EMAC_CPPI_SOP_BIT BIT(31) 205#define EMAC_CPPI_SOP_BIT BIT(31)
209#define EMAC_CPPI_EOP_BIT BIT(30) 206#define EMAC_CPPI_EOP_BIT BIT(30)
@@ -333,6 +330,9 @@ static const char emac_version_string[] = "TI DaVinci EMAC Linux v6.1";
333#define EMAC_DM646X_MAC_EOI_C0_RXEN (0x01) 330#define EMAC_DM646X_MAC_EOI_C0_RXEN (0x01)
334#define EMAC_DM646X_MAC_EOI_C0_TXEN (0x02) 331#define EMAC_DM646X_MAC_EOI_C0_TXEN (0x02)
335 332
333/* EMAC Stats Clear Mask */
334#define EMAC_STATS_CLR_MASK (0xFFFFFFFF)
335
336/** net_buf_obj: EMAC network bufferdata structure 336/** net_buf_obj: EMAC network bufferdata structure
337 * 337 *
338 * EMAC network buffer data structure 338 * EMAC network buffer data structure
@@ -747,8 +747,7 @@ static void emac_update_phystatus(struct emac_priv *priv)
747 747
748 if (priv->speed == SPEED_1000 && (priv->version == EMAC_VERSION_2)) { 748 if (priv->speed == SPEED_1000 && (priv->version == EMAC_VERSION_2)) {
749 mac_control = emac_read(EMAC_MACCONTROL); 749 mac_control = emac_read(EMAC_MACCONTROL);
750 mac_control |= (EMAC_DM646X_MACCONTORL_GMIIEN | 750 mac_control |= (EMAC_DM646X_MACCONTORL_GIG |
751 EMAC_DM646X_MACCONTORL_GIG |
752 EMAC_DM646X_MACCONTORL_GIGFORCE); 751 EMAC_DM646X_MACCONTORL_GIGFORCE);
753 } else { 752 } else {
754 /* Clear the GIG bit and GIGFORCE bit */ 753 /* Clear the GIG bit and GIGFORCE bit */
@@ -2105,7 +2104,7 @@ static int emac_hw_enable(struct emac_priv *priv)
2105 2104
2106 /* Enable MII */ 2105 /* Enable MII */
2107 val = emac_read(EMAC_MACCONTROL); 2106 val = emac_read(EMAC_MACCONTROL);
2108 val |= (EMAC_MACCONTROL_MIIEN); 2107 val |= (EMAC_MACCONTROL_GMIIEN);
2109 emac_write(EMAC_MACCONTROL, val); 2108 emac_write(EMAC_MACCONTROL, val);
2110 2109
2111 /* Enable NAPI and interrupts */ 2110 /* Enable NAPI and interrupts */
@@ -2137,9 +2136,6 @@ static int emac_poll(struct napi_struct *napi, int budget)
2137 u32 status = 0; 2136 u32 status = 0;
2138 u32 num_pkts = 0; 2137 u32 num_pkts = 0;
2139 2138
2140 if (!netif_running(ndev))
2141 return 0;
2142
2143 /* Check interrupt vectors and call packet processing */ 2139 /* Check interrupt vectors and call packet processing */
2144 status = emac_read(EMAC_MACINVECTOR); 2140 status = emac_read(EMAC_MACINVECTOR);
2145 2141
@@ -2218,7 +2214,7 @@ void emac_poll_controller(struct net_device *ndev)
2218 struct emac_priv *priv = netdev_priv(ndev); 2214 struct emac_priv *priv = netdev_priv(ndev);
2219 2215
2220 emac_int_disable(priv); 2216 emac_int_disable(priv);
2221 emac_irq(ndev->irq, priv); 2217 emac_irq(ndev->irq, ndev);
2222 emac_int_enable(priv); 2218 emac_int_enable(priv);
2223} 2219}
2224#endif 2220#endif
@@ -2548,40 +2544,49 @@ static int emac_dev_stop(struct net_device *ndev)
2548static struct net_device_stats *emac_dev_getnetstats(struct net_device *ndev) 2544static struct net_device_stats *emac_dev_getnetstats(struct net_device *ndev)
2549{ 2545{
2550 struct emac_priv *priv = netdev_priv(ndev); 2546 struct emac_priv *priv = netdev_priv(ndev);
2547 u32 mac_control;
2548 u32 stats_clear_mask;
2551 2549
2552 /* update emac hardware stats and reset the registers*/ 2550 /* update emac hardware stats and reset the registers*/
2553 2551
2552 mac_control = emac_read(EMAC_MACCONTROL);
2553
2554 if (mac_control & EMAC_MACCONTROL_GMIIEN)
2555 stats_clear_mask = EMAC_STATS_CLR_MASK;
2556 else
2557 stats_clear_mask = 0;
2558
2554 priv->net_dev_stats.multicast += emac_read(EMAC_RXMCASTFRAMES); 2559 priv->net_dev_stats.multicast += emac_read(EMAC_RXMCASTFRAMES);
2555 emac_write(EMAC_RXMCASTFRAMES, EMAC_ALL_MULTI_REG_VALUE); 2560 emac_write(EMAC_RXMCASTFRAMES, stats_clear_mask);
2556 2561
2557 priv->net_dev_stats.collisions += (emac_read(EMAC_TXCOLLISION) + 2562 priv->net_dev_stats.collisions += (emac_read(EMAC_TXCOLLISION) +
2558 emac_read(EMAC_TXSINGLECOLL) + 2563 emac_read(EMAC_TXSINGLECOLL) +
2559 emac_read(EMAC_TXMULTICOLL)); 2564 emac_read(EMAC_TXMULTICOLL));
2560 emac_write(EMAC_TXCOLLISION, EMAC_ALL_MULTI_REG_VALUE); 2565 emac_write(EMAC_TXCOLLISION, stats_clear_mask);
2561 emac_write(EMAC_TXSINGLECOLL, EMAC_ALL_MULTI_REG_VALUE); 2566 emac_write(EMAC_TXSINGLECOLL, stats_clear_mask);
2562 emac_write(EMAC_TXMULTICOLL, EMAC_ALL_MULTI_REG_VALUE); 2567 emac_write(EMAC_TXMULTICOLL, stats_clear_mask);
2563 2568
2564 priv->net_dev_stats.rx_length_errors += (emac_read(EMAC_RXOVERSIZED) + 2569 priv->net_dev_stats.rx_length_errors += (emac_read(EMAC_RXOVERSIZED) +
2565 emac_read(EMAC_RXJABBER) + 2570 emac_read(EMAC_RXJABBER) +
2566 emac_read(EMAC_RXUNDERSIZED)); 2571 emac_read(EMAC_RXUNDERSIZED));
2567 emac_write(EMAC_RXOVERSIZED, EMAC_ALL_MULTI_REG_VALUE); 2572 emac_write(EMAC_RXOVERSIZED, stats_clear_mask);
2568 emac_write(EMAC_RXJABBER, EMAC_ALL_MULTI_REG_VALUE); 2573 emac_write(EMAC_RXJABBER, stats_clear_mask);
2569 emac_write(EMAC_RXUNDERSIZED, EMAC_ALL_MULTI_REG_VALUE); 2574 emac_write(EMAC_RXUNDERSIZED, stats_clear_mask);
2570 2575
2571 priv->net_dev_stats.rx_over_errors += (emac_read(EMAC_RXSOFOVERRUNS) + 2576 priv->net_dev_stats.rx_over_errors += (emac_read(EMAC_RXSOFOVERRUNS) +
2572 emac_read(EMAC_RXMOFOVERRUNS)); 2577 emac_read(EMAC_RXMOFOVERRUNS));
2573 emac_write(EMAC_RXSOFOVERRUNS, EMAC_ALL_MULTI_REG_VALUE); 2578 emac_write(EMAC_RXSOFOVERRUNS, stats_clear_mask);
2574 emac_write(EMAC_RXMOFOVERRUNS, EMAC_ALL_MULTI_REG_VALUE); 2579 emac_write(EMAC_RXMOFOVERRUNS, stats_clear_mask);
2575 2580
2576 priv->net_dev_stats.rx_fifo_errors += emac_read(EMAC_RXDMAOVERRUNS); 2581 priv->net_dev_stats.rx_fifo_errors += emac_read(EMAC_RXDMAOVERRUNS);
2577 emac_write(EMAC_RXDMAOVERRUNS, EMAC_ALL_MULTI_REG_VALUE); 2582 emac_write(EMAC_RXDMAOVERRUNS, stats_clear_mask);
2578 2583
2579 priv->net_dev_stats.tx_carrier_errors += 2584 priv->net_dev_stats.tx_carrier_errors +=
2580 emac_read(EMAC_TXCARRIERSENSE); 2585 emac_read(EMAC_TXCARRIERSENSE);
2581 emac_write(EMAC_TXCARRIERSENSE, EMAC_ALL_MULTI_REG_VALUE); 2586 emac_write(EMAC_TXCARRIERSENSE, stats_clear_mask);
2582 2587
2583 priv->net_dev_stats.tx_fifo_errors = emac_read(EMAC_TXUNDERRUN); 2588 priv->net_dev_stats.tx_fifo_errors = emac_read(EMAC_TXUNDERRUN);
2584 emac_write(EMAC_TXUNDERRUN, EMAC_ALL_MULTI_REG_VALUE); 2589 emac_write(EMAC_TXUNDERRUN, stats_clear_mask);
2585 2590
2586 return &priv->net_dev_stats; 2591 return &priv->net_dev_stats;
2587} 2592}
diff --git a/drivers/net/dm9000.h b/drivers/net/dm9000.h
index 80817c2edfb3..fb1c924d79b4 100644
--- a/drivers/net/dm9000.h
+++ b/drivers/net/dm9000.h
@@ -50,7 +50,7 @@
50#define DM9000_RCSR 0x32 50#define DM9000_RCSR 0x32
51 51
52#define CHIPR_DM9000A 0x19 52#define CHIPR_DM9000A 0x19
53#define CHIPR_DM9000B 0x1B 53#define CHIPR_DM9000B 0x1A
54 54
55#define DM9000_MRCMDX 0xF0 55#define DM9000_MRCMDX 0xF0
56#define DM9000_MRCMD 0xF2 56#define DM9000_MRCMD 0xF2
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index 5d2f48f02251..d269a68ce354 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -157,6 +157,7 @@
157#include <linux/init.h> 157#include <linux/init.h>
158#include <linux/pci.h> 158#include <linux/pci.h>
159#include <linux/dma-mapping.h> 159#include <linux/dma-mapping.h>
160#include <linux/dmapool.h>
160#include <linux/netdevice.h> 161#include <linux/netdevice.h>
161#include <linux/etherdevice.h> 162#include <linux/etherdevice.h>
162#include <linux/mii.h> 163#include <linux/mii.h>
@@ -602,6 +603,7 @@ struct nic {
602 struct mem *mem; 603 struct mem *mem;
603 dma_addr_t dma_addr; 604 dma_addr_t dma_addr;
604 605
606 struct pci_pool *cbs_pool;
605 dma_addr_t cbs_dma_addr; 607 dma_addr_t cbs_dma_addr;
606 u8 adaptive_ifs; 608 u8 adaptive_ifs;
607 u8 tx_threshold; 609 u8 tx_threshold;
@@ -1427,19 +1429,31 @@ static int e100_phy_init(struct nic *nic)
1427 } else 1429 } else
1428 DPRINTK(HW, DEBUG, "phy_addr = %d\n", nic->mii.phy_id); 1430 DPRINTK(HW, DEBUG, "phy_addr = %d\n", nic->mii.phy_id);
1429 1431
1430 /* Isolate all the PHY ids */
1431 for (addr = 0; addr < 32; addr++)
1432 mdio_write(netdev, addr, MII_BMCR, BMCR_ISOLATE);
1433 /* Select the discovered PHY */
1434 bmcr &= ~BMCR_ISOLATE;
1435 mdio_write(netdev, nic->mii.phy_id, MII_BMCR, bmcr);
1436
1437 /* Get phy ID */ 1432 /* Get phy ID */
1438 id_lo = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID1); 1433 id_lo = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID1);
1439 id_hi = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID2); 1434 id_hi = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID2);
1440 nic->phy = (u32)id_hi << 16 | (u32)id_lo; 1435 nic->phy = (u32)id_hi << 16 | (u32)id_lo;
1441 DPRINTK(HW, DEBUG, "phy ID = 0x%08X\n", nic->phy); 1436 DPRINTK(HW, DEBUG, "phy ID = 0x%08X\n", nic->phy);
1442 1437
1438 /* Select the phy and isolate the rest */
1439 for (addr = 0; addr < 32; addr++) {
1440 if (addr != nic->mii.phy_id) {
1441 mdio_write(netdev, addr, MII_BMCR, BMCR_ISOLATE);
1442 } else if (nic->phy != phy_82552_v) {
1443 bmcr = mdio_read(netdev, addr, MII_BMCR);
1444 mdio_write(netdev, addr, MII_BMCR,
1445 bmcr & ~BMCR_ISOLATE);
1446 }
1447 }
1448 /*
1449 * Workaround for 82552:
1450 * Clear the ISOLATE bit on selected phy_id last (mirrored on all
1451 * other phy_id's) using bmcr value from addr discovery loop above.
1452 */
1453 if (nic->phy == phy_82552_v)
1454 mdio_write(netdev, nic->mii.phy_id, MII_BMCR,
1455 bmcr & ~BMCR_ISOLATE);
1456
1443 /* Handle National tx phys */ 1457 /* Handle National tx phys */
1444#define NCS_PHY_MODEL_MASK 0xFFF0FFFF 1458#define NCS_PHY_MODEL_MASK 0xFFF0FFFF
1445 if ((nic->phy & NCS_PHY_MODEL_MASK) == phy_nsc_tx) { 1459 if ((nic->phy & NCS_PHY_MODEL_MASK) == phy_nsc_tx) {
@@ -1781,9 +1795,7 @@ static void e100_clean_cbs(struct nic *nic)
1781 nic->cb_to_clean = nic->cb_to_clean->next; 1795 nic->cb_to_clean = nic->cb_to_clean->next;
1782 nic->cbs_avail++; 1796 nic->cbs_avail++;
1783 } 1797 }
1784 pci_free_consistent(nic->pdev, 1798 pci_pool_free(nic->cbs_pool, nic->cbs, nic->cbs_dma_addr);
1785 sizeof(struct cb) * nic->params.cbs.count,
1786 nic->cbs, nic->cbs_dma_addr);
1787 nic->cbs = NULL; 1799 nic->cbs = NULL;
1788 nic->cbs_avail = 0; 1800 nic->cbs_avail = 0;
1789 } 1801 }
@@ -1801,8 +1813,8 @@ static int e100_alloc_cbs(struct nic *nic)
1801 nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = NULL; 1813 nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = NULL;
1802 nic->cbs_avail = 0; 1814 nic->cbs_avail = 0;
1803 1815
1804 nic->cbs = pci_alloc_consistent(nic->pdev, 1816 nic->cbs = pci_pool_alloc(nic->cbs_pool, GFP_KERNEL,
1805 sizeof(struct cb) * count, &nic->cbs_dma_addr); 1817 &nic->cbs_dma_addr);
1806 if (!nic->cbs) 1818 if (!nic->cbs)
1807 return -ENOMEM; 1819 return -ENOMEM;
1808 1820
@@ -2829,7 +2841,11 @@ static int __devinit e100_probe(struct pci_dev *pdev,
2829 DPRINTK(PROBE, ERR, "Cannot register net device, aborting.\n"); 2841 DPRINTK(PROBE, ERR, "Cannot register net device, aborting.\n");
2830 goto err_out_free; 2842 goto err_out_free;
2831 } 2843 }
2832 2844 nic->cbs_pool = pci_pool_create(netdev->name,
2845 nic->pdev,
2846 nic->params.cbs.count * sizeof(struct cb),
2847 sizeof(u32),
2848 0);
2833 DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, MAC addr %pM\n", 2849 DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, MAC addr %pM\n",
2834 (unsigned long long)pci_resource_start(pdev, use_io ? 1 : 0), 2850 (unsigned long long)pci_resource_start(pdev, use_io ? 1 : 0),
2835 pdev->irq, netdev->dev_addr); 2851 pdev->irq, netdev->dev_addr);
@@ -2859,6 +2875,7 @@ static void __devexit e100_remove(struct pci_dev *pdev)
2859 unregister_netdev(netdev); 2875 unregister_netdev(netdev);
2860 e100_free(nic); 2876 e100_free(nic);
2861 pci_iounmap(pdev, nic->csr); 2877 pci_iounmap(pdev, nic->csr);
2878 pci_pool_destroy(nic->cbs_pool);
2862 free_netdev(netdev); 2879 free_netdev(netdev);
2863 pci_release_regions(pdev); 2880 pci_release_regions(pdev);
2864 pci_disable_device(pdev); 2881 pci_disable_device(pdev);
diff --git a/drivers/net/e1000e/defines.h b/drivers/net/e1000e/defines.h
index c0f185beb8bc..1190167a8b3d 100644
--- a/drivers/net/e1000e/defines.h
+++ b/drivers/net/e1000e/defines.h
@@ -76,6 +76,7 @@
76/* Extended Device Control */ 76/* Extended Device Control */
77#define E1000_CTRL_EXT_SDP7_DATA 0x00000080 /* Value of SW Definable Pin 7 */ 77#define E1000_CTRL_EXT_SDP7_DATA 0x00000080 /* Value of SW Definable Pin 7 */
78#define E1000_CTRL_EXT_EE_RST 0x00002000 /* Reinitialize from EEPROM */ 78#define E1000_CTRL_EXT_EE_RST 0x00002000 /* Reinitialize from EEPROM */
79#define E1000_CTRL_EXT_SPD_BYPS 0x00008000 /* Speed Select Bypass */
79#define E1000_CTRL_EXT_RO_DIS 0x00020000 /* Relaxed Ordering disable */ 80#define E1000_CTRL_EXT_RO_DIS 0x00020000 /* Relaxed Ordering disable */
80#define E1000_CTRL_EXT_DMA_DYN_CLK_EN 0x00080000 /* DMA Dynamic Clock Gating */ 81#define E1000_CTRL_EXT_DMA_DYN_CLK_EN 0x00080000 /* DMA Dynamic Clock Gating */
81#define E1000_CTRL_EXT_LINK_MODE_MASK 0x00C00000 82#define E1000_CTRL_EXT_LINK_MODE_MASK 0x00C00000
@@ -347,6 +348,7 @@
347/* Extended Configuration Control and Size */ 348/* Extended Configuration Control and Size */
348#define E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP 0x00000020 349#define E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP 0x00000020
349#define E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE 0x00000001 350#define E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE 0x00000001
351#define E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE 0x00000008
350#define E1000_EXTCNF_CTRL_SWFLAG 0x00000020 352#define E1000_EXTCNF_CTRL_SWFLAG 0x00000020
351#define E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK 0x00FF0000 353#define E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK 0x00FF0000
352#define E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT 16 354#define E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT 16
diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
index 981936c1fb46..3e187b0e4203 100644
--- a/drivers/net/e1000e/e1000.h
+++ b/drivers/net/e1000e/e1000.h
@@ -141,6 +141,22 @@ struct e1000_info;
141#define HV_TNCRS_UPPER PHY_REG(778, 29) /* Transmit with no CRS */ 141#define HV_TNCRS_UPPER PHY_REG(778, 29) /* Transmit with no CRS */
142#define HV_TNCRS_LOWER PHY_REG(778, 30) 142#define HV_TNCRS_LOWER PHY_REG(778, 30)
143 143
144#define E1000_FCRTV_PCH 0x05F40 /* PCH Flow Control Refresh Timer Value */
145
146/* BM PHY Copper Specific Status */
147#define BM_CS_STATUS 17
148#define BM_CS_STATUS_LINK_UP 0x0400
149#define BM_CS_STATUS_RESOLVED 0x0800
150#define BM_CS_STATUS_SPEED_MASK 0xC000
151#define BM_CS_STATUS_SPEED_1000 0x8000
152
153/* 82577 Mobile Phy Status Register */
154#define HV_M_STATUS 26
155#define HV_M_STATUS_AUTONEG_COMPLETE 0x1000
156#define HV_M_STATUS_SPEED_MASK 0x0300
157#define HV_M_STATUS_SPEED_1000 0x0200
158#define HV_M_STATUS_LINK_UP 0x0040
159
144enum e1000_boards { 160enum e1000_boards {
145 board_82571, 161 board_82571,
146 board_82572, 162 board_82572,
@@ -519,9 +535,13 @@ extern s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw);
519extern s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw); 535extern s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw);
520extern s32 e1000e_get_phy_info_igp(struct e1000_hw *hw); 536extern s32 e1000e_get_phy_info_igp(struct e1000_hw *hw);
521extern s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data); 537extern s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data);
538extern s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset,
539 u16 *data);
522extern s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw); 540extern s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw);
523extern s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active); 541extern s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active);
524extern s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data); 542extern s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data);
543extern s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset,
544 u16 data);
525extern s32 e1000e_phy_sw_reset(struct e1000_hw *hw); 545extern s32 e1000e_phy_sw_reset(struct e1000_hw *hw);
526extern s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw); 546extern s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw);
527extern s32 e1000e_get_cfg_done(struct e1000_hw *hw); 547extern s32 e1000e_get_cfg_done(struct e1000_hw *hw);
@@ -538,7 +558,11 @@ extern s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data);
538extern s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data); 558extern s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data);
539extern void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl); 559extern void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl);
540extern s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data); 560extern s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data);
561extern s32 e1000e_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset,
562 u16 data);
541extern s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data); 563extern s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data);
564extern s32 e1000e_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset,
565 u16 *data);
542extern s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations, 566extern s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
543 u32 usec_interval, bool *success); 567 u32 usec_interval, bool *success);
544extern s32 e1000e_phy_reset_dsp(struct e1000_hw *hw); 568extern s32 e1000e_phy_reset_dsp(struct e1000_hw *hw);
@@ -546,7 +570,11 @@ extern s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data);
546extern s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data); 570extern s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data);
547extern s32 e1000e_check_downshift(struct e1000_hw *hw); 571extern s32 e1000e_check_downshift(struct e1000_hw *hw);
548extern s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data); 572extern s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data);
573extern s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset,
574 u16 *data);
549extern s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data); 575extern s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data);
576extern s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset,
577 u16 data);
550extern s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw, bool slow); 578extern s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw, bool slow);
551extern s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw); 579extern s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw);
552extern s32 e1000_copper_link_setup_82577(struct e1000_hw *hw); 580extern s32 e1000_copper_link_setup_82577(struct e1000_hw *hw);
diff --git a/drivers/net/e1000e/ethtool.c b/drivers/net/e1000e/ethtool.c
index 1bf4d2a5d34f..e82638ecae88 100644
--- a/drivers/net/e1000e/ethtool.c
+++ b/drivers/net/e1000e/ethtool.c
@@ -327,10 +327,18 @@ static int e1000_set_pauseparam(struct net_device *netdev,
327 327
328 hw->fc.current_mode = hw->fc.requested_mode; 328 hw->fc.current_mode = hw->fc.requested_mode;
329 329
330 retval = ((hw->phy.media_type == e1000_media_type_fiber) ? 330 if (hw->phy.media_type == e1000_media_type_fiber) {
331 hw->mac.ops.setup_link(hw) : e1000e_force_mac_fc(hw)); 331 retval = hw->mac.ops.setup_link(hw);
332 /* implicit goto out */
333 } else {
334 retval = e1000e_force_mac_fc(hw);
335 if (retval)
336 goto out;
337 e1000e_set_fc_watermarks(hw);
338 }
332 } 339 }
333 340
341out:
334 clear_bit(__E1000_RESETTING, &adapter->state); 342 clear_bit(__E1000_RESETTING, &adapter->state);
335 return retval; 343 return retval;
336} 344}
diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
index fd44d9f90769..aaea41ef794d 100644
--- a/drivers/net/e1000e/hw.h
+++ b/drivers/net/e1000e/hw.h
@@ -764,11 +764,13 @@ struct e1000_phy_operations {
764 s32 (*get_cable_length)(struct e1000_hw *); 764 s32 (*get_cable_length)(struct e1000_hw *);
765 s32 (*get_phy_info)(struct e1000_hw *); 765 s32 (*get_phy_info)(struct e1000_hw *);
766 s32 (*read_phy_reg)(struct e1000_hw *, u32, u16 *); 766 s32 (*read_phy_reg)(struct e1000_hw *, u32, u16 *);
767 s32 (*read_phy_reg_locked)(struct e1000_hw *, u32, u16 *);
767 void (*release_phy)(struct e1000_hw *); 768 void (*release_phy)(struct e1000_hw *);
768 s32 (*reset_phy)(struct e1000_hw *); 769 s32 (*reset_phy)(struct e1000_hw *);
769 s32 (*set_d0_lplu_state)(struct e1000_hw *, bool); 770 s32 (*set_d0_lplu_state)(struct e1000_hw *, bool);
770 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool); 771 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
771 s32 (*write_phy_reg)(struct e1000_hw *, u32, u16); 772 s32 (*write_phy_reg)(struct e1000_hw *, u32, u16);
773 s32 (*write_phy_reg_locked)(struct e1000_hw *, u32, u16);
772 s32 (*cfg_on_link_up)(struct e1000_hw *); 774 s32 (*cfg_on_link_up)(struct e1000_hw *);
773}; 775};
774 776
@@ -901,6 +903,7 @@ struct e1000_shadow_ram {
901struct e1000_dev_spec_ich8lan { 903struct e1000_dev_spec_ich8lan {
902 bool kmrn_lock_loss_workaround_enabled; 904 bool kmrn_lock_loss_workaround_enabled;
903 struct e1000_shadow_ram shadow_ram[E1000_ICH8_SHADOW_RAM_WORDS]; 905 struct e1000_shadow_ram shadow_ram[E1000_ICH8_SHADOW_RAM_WORDS];
906 bool nvm_k1_enabled;
904}; 907};
905 908
906struct e1000_hw { 909struct e1000_hw {
diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
index 99df2abf82a9..eff3f4783655 100644
--- a/drivers/net/e1000e/ich8lan.c
+++ b/drivers/net/e1000e/ich8lan.c
@@ -122,6 +122,27 @@
122 122
123#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */ 123#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
124 124
125#define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
126
127/* SMBus Address Phy Register */
128#define HV_SMB_ADDR PHY_REG(768, 26)
129#define HV_SMB_ADDR_PEC_EN 0x0200
130#define HV_SMB_ADDR_VALID 0x0080
131
132/* Strapping Option Register - RO */
133#define E1000_STRAP 0x0000C
134#define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
135#define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
136
137/* OEM Bits Phy Register */
138#define HV_OEM_BITS PHY_REG(768, 25)
139#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
140#define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
141#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
142
143#define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
144#define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
145
125/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */ 146/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
126/* Offset 04h HSFSTS */ 147/* Offset 04h HSFSTS */
127union ich8_hws_flash_status { 148union ich8_hws_flash_status {
@@ -200,6 +221,10 @@ static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
200static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw); 221static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
201static s32 e1000_led_on_pchlan(struct e1000_hw *hw); 222static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
202static s32 e1000_led_off_pchlan(struct e1000_hw *hw); 223static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
224static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
225static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
226static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
227static s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable);
203 228
204static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg) 229static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
205{ 230{
@@ -242,7 +267,11 @@ static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
242 267
243 phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan; 268 phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
244 phy->ops.read_phy_reg = e1000_read_phy_reg_hv; 269 phy->ops.read_phy_reg = e1000_read_phy_reg_hv;
270 phy->ops.read_phy_reg_locked = e1000_read_phy_reg_hv_locked;
271 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
272 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
245 phy->ops.write_phy_reg = e1000_write_phy_reg_hv; 273 phy->ops.write_phy_reg = e1000_write_phy_reg_hv;
274 phy->ops.write_phy_reg_locked = e1000_write_phy_reg_hv_locked;
246 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT; 275 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
247 276
248 phy->id = e1000_phy_unknown; 277 phy->id = e1000_phy_unknown;
@@ -303,6 +332,8 @@ static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
303 case IGP03E1000_E_PHY_ID: 332 case IGP03E1000_E_PHY_ID:
304 phy->type = e1000_phy_igp_3; 333 phy->type = e1000_phy_igp_3;
305 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT; 334 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
335 phy->ops.read_phy_reg_locked = e1000e_read_phy_reg_igp_locked;
336 phy->ops.write_phy_reg_locked = e1000e_write_phy_reg_igp_locked;
306 break; 337 break;
307 case IFE_E_PHY_ID: 338 case IFE_E_PHY_ID:
308 case IFE_PLUS_E_PHY_ID: 339 case IFE_PLUS_E_PHY_ID:
@@ -469,14 +500,6 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
469 goto out; 500 goto out;
470 } 501 }
471 502
472 if (hw->mac.type == e1000_pchlan) {
473 ret_val = e1000e_write_kmrn_reg(hw,
474 E1000_KMRNCTRLSTA_K1_CONFIG,
475 E1000_KMRNCTRLSTA_K1_ENABLE);
476 if (ret_val)
477 goto out;
478 }
479
480 /* 503 /*
481 * First we want to see if the MII Status Register reports 504 * First we want to see if the MII Status Register reports
482 * link. If so, then we want to get the current speed/duplex 505 * link. If so, then we want to get the current speed/duplex
@@ -486,6 +509,12 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
486 if (ret_val) 509 if (ret_val)
487 goto out; 510 goto out;
488 511
512 if (hw->mac.type == e1000_pchlan) {
513 ret_val = e1000_k1_gig_workaround_hv(hw, link);
514 if (ret_val)
515 goto out;
516 }
517
489 if (!link) 518 if (!link)
490 goto out; /* No link detected */ 519 goto out; /* No link detected */
491 520
@@ -568,12 +597,39 @@ static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
568static DEFINE_MUTEX(nvm_mutex); 597static DEFINE_MUTEX(nvm_mutex);
569 598
570/** 599/**
600 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
601 * @hw: pointer to the HW structure
602 *
603 * Acquires the mutex for performing NVM operations.
604 **/
605static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
606{
607 mutex_lock(&nvm_mutex);
608
609 return 0;
610}
611
612/**
613 * e1000_release_nvm_ich8lan - Release NVM mutex
614 * @hw: pointer to the HW structure
615 *
616 * Releases the mutex used while performing NVM operations.
617 **/
618static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
619{
620 mutex_unlock(&nvm_mutex);
621
622 return;
623}
624
625static DEFINE_MUTEX(swflag_mutex);
626
627/**
571 * e1000_acquire_swflag_ich8lan - Acquire software control flag 628 * e1000_acquire_swflag_ich8lan - Acquire software control flag
572 * @hw: pointer to the HW structure 629 * @hw: pointer to the HW structure
573 * 630 *
574 * Acquires the software control flag for performing NVM and PHY 631 * Acquires the software control flag for performing PHY and select
575 * operations. This is a function pointer entry point only called by 632 * MAC CSR accesses.
576 * read/write routines for the PHY and NVM parts.
577 **/ 633 **/
578static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw) 634static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
579{ 635{
@@ -582,7 +638,7 @@ static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
582 638
583 might_sleep(); 639 might_sleep();
584 640
585 mutex_lock(&nvm_mutex); 641 mutex_lock(&swflag_mutex);
586 642
587 while (timeout) { 643 while (timeout) {
588 extcnf_ctrl = er32(EXTCNF_CTRL); 644 extcnf_ctrl = er32(EXTCNF_CTRL);
@@ -599,7 +655,7 @@ static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
599 goto out; 655 goto out;
600 } 656 }
601 657
602 timeout = PHY_CFG_TIMEOUT * 2; 658 timeout = SW_FLAG_TIMEOUT;
603 659
604 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG; 660 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
605 ew32(EXTCNF_CTRL, extcnf_ctrl); 661 ew32(EXTCNF_CTRL, extcnf_ctrl);
@@ -623,7 +679,7 @@ static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
623 679
624out: 680out:
625 if (ret_val) 681 if (ret_val)
626 mutex_unlock(&nvm_mutex); 682 mutex_unlock(&swflag_mutex);
627 683
628 return ret_val; 684 return ret_val;
629} 685}
@@ -632,9 +688,8 @@ out:
632 * e1000_release_swflag_ich8lan - Release software control flag 688 * e1000_release_swflag_ich8lan - Release software control flag
633 * @hw: pointer to the HW structure 689 * @hw: pointer to the HW structure
634 * 690 *
635 * Releases the software control flag for performing NVM and PHY operations. 691 * Releases the software control flag for performing PHY and select
636 * This is a function pointer entry point only called by read/write 692 * MAC CSR accesses.
637 * routines for the PHY and NVM parts.
638 **/ 693 **/
639static void e1000_release_swflag_ich8lan(struct e1000_hw *hw) 694static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
640{ 695{
@@ -644,7 +699,9 @@ static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
644 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG; 699 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
645 ew32(EXTCNF_CTRL, extcnf_ctrl); 700 ew32(EXTCNF_CTRL, extcnf_ctrl);
646 701
647 mutex_unlock(&nvm_mutex); 702 mutex_unlock(&swflag_mutex);
703
704 return;
648} 705}
649 706
650/** 707/**
@@ -752,6 +809,327 @@ static s32 e1000_phy_force_speed_duplex_ich8lan(struct e1000_hw *hw)
752} 809}
753 810
754/** 811/**
812 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
813 * @hw: pointer to the HW structure
814 *
815 * SW should configure the LCD from the NVM extended configuration region
816 * as a workaround for certain parts.
817 **/
818static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
819{
820 struct e1000_phy_info *phy = &hw->phy;
821 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
822 s32 ret_val;
823 u16 word_addr, reg_data, reg_addr, phy_page = 0;
824
825 ret_val = hw->phy.ops.acquire_phy(hw);
826 if (ret_val)
827 return ret_val;
828
829 /*
830 * Initialize the PHY from the NVM on ICH platforms. This
831 * is needed due to an issue where the NVM configuration is
832 * not properly autoloaded after power transitions.
833 * Therefore, after each PHY reset, we will load the
834 * configuration data out of the NVM manually.
835 */
836 if ((hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) ||
837 (hw->mac.type == e1000_pchlan)) {
838 struct e1000_adapter *adapter = hw->adapter;
839
840 /* Check if SW needs to configure the PHY */
841 if ((adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
842 (adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M) ||
843 (hw->mac.type == e1000_pchlan))
844 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
845 else
846 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
847
848 data = er32(FEXTNVM);
849 if (!(data & sw_cfg_mask))
850 goto out;
851
852 /* Wait for basic configuration completes before proceeding */
853 e1000_lan_init_done_ich8lan(hw);
854
855 /*
856 * Make sure HW does not configure LCD from PHY
857 * extended configuration before SW configuration
858 */
859 data = er32(EXTCNF_CTRL);
860 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
861 goto out;
862
863 cnf_size = er32(EXTCNF_SIZE);
864 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
865 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
866 if (!cnf_size)
867 goto out;
868
869 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
870 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
871
872 if (!(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE) &&
873 (hw->mac.type == e1000_pchlan)) {
874 /*
875 * HW configures the SMBus address and LEDs when the
876 * OEM and LCD Write Enable bits are set in the NVM.
877 * When both NVM bits are cleared, SW will configure
878 * them instead.
879 */
880 data = er32(STRAP);
881 data &= E1000_STRAP_SMBUS_ADDRESS_MASK;
882 reg_data = data >> E1000_STRAP_SMBUS_ADDRESS_SHIFT;
883 reg_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
884 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR,
885 reg_data);
886 if (ret_val)
887 goto out;
888
889 data = er32(LEDCTL);
890 ret_val = e1000_write_phy_reg_hv_locked(hw,
891 HV_LED_CONFIG,
892 (u16)data);
893 if (ret_val)
894 goto out;
895 }
896 /* Configure LCD from extended configuration region. */
897
898 /* cnf_base_addr is in DWORD */
899 word_addr = (u16)(cnf_base_addr << 1);
900
901 for (i = 0; i < cnf_size; i++) {
902 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
903 &reg_data);
904 if (ret_val)
905 goto out;
906
907 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
908 1, &reg_addr);
909 if (ret_val)
910 goto out;
911
912 /* Save off the PHY page for future writes. */
913 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
914 phy_page = reg_data;
915 continue;
916 }
917
918 reg_addr &= PHY_REG_MASK;
919 reg_addr |= phy_page;
920
921 ret_val = phy->ops.write_phy_reg_locked(hw,
922 (u32)reg_addr,
923 reg_data);
924 if (ret_val)
925 goto out;
926 }
927 }
928
929out:
930 hw->phy.ops.release_phy(hw);
931 return ret_val;
932}
933
934/**
935 * e1000_k1_gig_workaround_hv - K1 Si workaround
936 * @hw: pointer to the HW structure
937 * @link: link up bool flag
938 *
939 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
940 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
941 * If link is down, the function will restore the default K1 setting located
942 * in the NVM.
943 **/
944static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
945{
946 s32 ret_val = 0;
947 u16 status_reg = 0;
948 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
949
950 if (hw->mac.type != e1000_pchlan)
951 goto out;
952
953 /* Wrap the whole flow with the sw flag */
954 ret_val = hw->phy.ops.acquire_phy(hw);
955 if (ret_val)
956 goto out;
957
958 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
959 if (link) {
960 if (hw->phy.type == e1000_phy_82578) {
961 ret_val = hw->phy.ops.read_phy_reg_locked(hw,
962 BM_CS_STATUS,
963 &status_reg);
964 if (ret_val)
965 goto release;
966
967 status_reg &= BM_CS_STATUS_LINK_UP |
968 BM_CS_STATUS_RESOLVED |
969 BM_CS_STATUS_SPEED_MASK;
970
971 if (status_reg == (BM_CS_STATUS_LINK_UP |
972 BM_CS_STATUS_RESOLVED |
973 BM_CS_STATUS_SPEED_1000))
974 k1_enable = false;
975 }
976
977 if (hw->phy.type == e1000_phy_82577) {
978 ret_val = hw->phy.ops.read_phy_reg_locked(hw,
979 HV_M_STATUS,
980 &status_reg);
981 if (ret_val)
982 goto release;
983
984 status_reg &= HV_M_STATUS_LINK_UP |
985 HV_M_STATUS_AUTONEG_COMPLETE |
986 HV_M_STATUS_SPEED_MASK;
987
988 if (status_reg == (HV_M_STATUS_LINK_UP |
989 HV_M_STATUS_AUTONEG_COMPLETE |
990 HV_M_STATUS_SPEED_1000))
991 k1_enable = false;
992 }
993
994 /* Link stall fix for link up */
995 ret_val = hw->phy.ops.write_phy_reg_locked(hw, PHY_REG(770, 19),
996 0x0100);
997 if (ret_val)
998 goto release;
999
1000 } else {
1001 /* Link stall fix for link down */
1002 ret_val = hw->phy.ops.write_phy_reg_locked(hw, PHY_REG(770, 19),
1003 0x4100);
1004 if (ret_val)
1005 goto release;
1006 }
1007
1008 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1009
1010release:
1011 hw->phy.ops.release_phy(hw);
1012out:
1013 return ret_val;
1014}
1015
1016/**
1017 * e1000_configure_k1_ich8lan - Configure K1 power state
1018 * @hw: pointer to the HW structure
1019 * @enable: K1 state to configure
1020 *
1021 * Configure the K1 power state based on the provided parameter.
1022 * Assumes semaphore already acquired.
1023 *
1024 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1025 **/
1026static s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
1027{
1028 s32 ret_val = 0;
1029 u32 ctrl_reg = 0;
1030 u32 ctrl_ext = 0;
1031 u32 reg = 0;
1032 u16 kmrn_reg = 0;
1033
1034 ret_val = e1000e_read_kmrn_reg_locked(hw,
1035 E1000_KMRNCTRLSTA_K1_CONFIG,
1036 &kmrn_reg);
1037 if (ret_val)
1038 goto out;
1039
1040 if (k1_enable)
1041 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1042 else
1043 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1044
1045 ret_val = e1000e_write_kmrn_reg_locked(hw,
1046 E1000_KMRNCTRLSTA_K1_CONFIG,
1047 kmrn_reg);
1048 if (ret_val)
1049 goto out;
1050
1051 udelay(20);
1052 ctrl_ext = er32(CTRL_EXT);
1053 ctrl_reg = er32(CTRL);
1054
1055 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1056 reg |= E1000_CTRL_FRCSPD;
1057 ew32(CTRL, reg);
1058
1059 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
1060 udelay(20);
1061 ew32(CTRL, ctrl_reg);
1062 ew32(CTRL_EXT, ctrl_ext);
1063 udelay(20);
1064
1065out:
1066 return ret_val;
1067}
1068
1069/**
1070 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1071 * @hw: pointer to the HW structure
1072 * @d0_state: boolean if entering d0 or d3 device state
1073 *
1074 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1075 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1076 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1077 **/
1078static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1079{
1080 s32 ret_val = 0;
1081 u32 mac_reg;
1082 u16 oem_reg;
1083
1084 if (hw->mac.type != e1000_pchlan)
1085 return ret_val;
1086
1087 ret_val = hw->phy.ops.acquire_phy(hw);
1088 if (ret_val)
1089 return ret_val;
1090
1091 mac_reg = er32(EXTCNF_CTRL);
1092 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
1093 goto out;
1094
1095 mac_reg = er32(FEXTNVM);
1096 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
1097 goto out;
1098
1099 mac_reg = er32(PHY_CTRL);
1100
1101 ret_val = hw->phy.ops.read_phy_reg_locked(hw, HV_OEM_BITS, &oem_reg);
1102 if (ret_val)
1103 goto out;
1104
1105 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1106
1107 if (d0_state) {
1108 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1109 oem_reg |= HV_OEM_BITS_GBE_DIS;
1110
1111 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1112 oem_reg |= HV_OEM_BITS_LPLU;
1113 } else {
1114 if (mac_reg & E1000_PHY_CTRL_NOND0A_GBE_DISABLE)
1115 oem_reg |= HV_OEM_BITS_GBE_DIS;
1116
1117 if (mac_reg & E1000_PHY_CTRL_NOND0A_LPLU)
1118 oem_reg |= HV_OEM_BITS_LPLU;
1119 }
1120 /* Restart auto-neg to activate the bits */
1121 if (!e1000_check_reset_block(hw))
1122 oem_reg |= HV_OEM_BITS_RESTART_AN;
1123 ret_val = hw->phy.ops.write_phy_reg_locked(hw, HV_OEM_BITS, oem_reg);
1124
1125out:
1126 hw->phy.ops.release_phy(hw);
1127
1128 return ret_val;
1129}
1130
1131
1132/**
755 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be 1133 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
756 * done after every PHY reset. 1134 * done after every PHY reset.
757 **/ 1135 **/
@@ -791,10 +1169,20 @@ static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
791 ret_val = hw->phy.ops.acquire_phy(hw); 1169 ret_val = hw->phy.ops.acquire_phy(hw);
792 if (ret_val) 1170 if (ret_val)
793 return ret_val; 1171 return ret_val;
1172
794 hw->phy.addr = 1; 1173 hw->phy.addr = 1;
795 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0); 1174 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
1175 if (ret_val)
1176 goto out;
796 hw->phy.ops.release_phy(hw); 1177 hw->phy.ops.release_phy(hw);
797 1178
1179 /*
1180 * Configure the K1 Si workaround during phy reset assuming there is
1181 * link so that it disables K1 if link is in 1Gbps.
1182 */
1183 ret_val = e1000_k1_gig_workaround_hv(hw, true);
1184
1185out:
798 return ret_val; 1186 return ret_val;
799} 1187}
800 1188
@@ -840,11 +1228,8 @@ static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
840 **/ 1228 **/
841static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw) 1229static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
842{ 1230{
843 struct e1000_phy_info *phy = &hw->phy; 1231 s32 ret_val = 0;
844 u32 i; 1232 u16 reg;
845 u32 data, cnf_size, cnf_base_addr, sw_cfg_mask;
846 s32 ret_val;
847 u16 word_addr, reg_data, reg_addr, phy_page = 0;
848 1233
849 ret_val = e1000e_phy_hw_reset_generic(hw); 1234 ret_val = e1000e_phy_hw_reset_generic(hw);
850 if (ret_val) 1235 if (ret_val)
@@ -859,81 +1244,20 @@ static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
859 return ret_val; 1244 return ret_val;
860 } 1245 }
861 1246
862 /* 1247 /* Dummy read to clear the phy wakeup bit after lcd reset */
863 * Initialize the PHY from the NVM on ICH platforms. This 1248 if (hw->mac.type == e1000_pchlan)
864 * is needed due to an issue where the NVM configuration is 1249 e1e_rphy(hw, BM_WUC, &reg);
865 * not properly autoloaded after power transitions.
866 * Therefore, after each PHY reset, we will load the
867 * configuration data out of the NVM manually.
868 */
869 if (hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) {
870 struct e1000_adapter *adapter = hw->adapter;
871
872 /* Check if SW needs configure the PHY */
873 if ((adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
874 (adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M))
875 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
876 else
877 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
878
879 data = er32(FEXTNVM);
880 if (!(data & sw_cfg_mask))
881 return 0;
882
883 /* Wait for basic configuration completes before proceeding */
884 e1000_lan_init_done_ich8lan(hw);
885
886 /*
887 * Make sure HW does not configure LCD from PHY
888 * extended configuration before SW configuration
889 */
890 data = er32(EXTCNF_CTRL);
891 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
892 return 0;
893
894 cnf_size = er32(EXTCNF_SIZE);
895 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
896 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
897 if (!cnf_size)
898 return 0;
899
900 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
901 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
902
903 /* Configure LCD from extended configuration region. */
904
905 /* cnf_base_addr is in DWORD */
906 word_addr = (u16)(cnf_base_addr << 1);
907
908 for (i = 0; i < cnf_size; i++) {
909 ret_val = e1000_read_nvm(hw,
910 (word_addr + i * 2),
911 1,
912 &reg_data);
913 if (ret_val)
914 return ret_val;
915
916 ret_val = e1000_read_nvm(hw,
917 (word_addr + i * 2 + 1),
918 1,
919 &reg_addr);
920 if (ret_val)
921 return ret_val;
922
923 /* Save off the PHY page for future writes. */
924 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
925 phy_page = reg_data;
926 continue;
927 }
928 1250
929 reg_addr |= phy_page; 1251 /* Configure the LCD with the extended configuration region in NVM */
1252 ret_val = e1000_sw_lcd_config_ich8lan(hw);
1253 if (ret_val)
1254 goto out;
930 1255
931 ret_val = e1e_wphy(hw, (u32)reg_addr, reg_data); 1256 /* Configure the LCD with the OEM bits in NVM */
932 if (ret_val) 1257 if (hw->mac.type == e1000_pchlan)
933 return ret_val; 1258 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
934 }
935 }
936 1259
1260out:
937 return 0; 1261 return 0;
938} 1262}
939 1263
@@ -1054,6 +1378,38 @@ static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw)
1054} 1378}
1055 1379
1056/** 1380/**
1381 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
1382 * @hw: pointer to the HW structure
1383 * @active: true to enable LPLU, false to disable
1384 *
1385 * Sets the LPLU state according to the active flag. For PCH, if OEM write
1386 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
1387 * the phy speed. This function will manually set the LPLU bit and restart
1388 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
1389 * since it configures the same bit.
1390 **/
1391static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
1392{
1393 s32 ret_val = 0;
1394 u16 oem_reg;
1395
1396 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
1397 if (ret_val)
1398 goto out;
1399
1400 if (active)
1401 oem_reg |= HV_OEM_BITS_LPLU;
1402 else
1403 oem_reg &= ~HV_OEM_BITS_LPLU;
1404
1405 oem_reg |= HV_OEM_BITS_RESTART_AN;
1406 ret_val = e1e_wphy(hw, HV_OEM_BITS, oem_reg);
1407
1408out:
1409 return ret_val;
1410}
1411
1412/**
1057 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state 1413 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
1058 * @hw: pointer to the HW structure 1414 * @hw: pointer to the HW structure
1059 * @active: TRUE to enable LPLU, FALSE to disable 1415 * @active: TRUE to enable LPLU, FALSE to disable
@@ -1314,12 +1670,11 @@ static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1314 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) || 1670 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1315 (words == 0)) { 1671 (words == 0)) {
1316 hw_dbg(hw, "nvm parameter(s) out of bounds\n"); 1672 hw_dbg(hw, "nvm parameter(s) out of bounds\n");
1317 return -E1000_ERR_NVM; 1673 ret_val = -E1000_ERR_NVM;
1674 goto out;
1318 } 1675 }
1319 1676
1320 ret_val = e1000_acquire_swflag_ich8lan(hw); 1677 nvm->ops.acquire_nvm(hw);
1321 if (ret_val)
1322 goto out;
1323 1678
1324 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank); 1679 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
1325 if (ret_val) { 1680 if (ret_val) {
@@ -1345,7 +1700,7 @@ static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1345 } 1700 }
1346 } 1701 }
1347 1702
1348 e1000_release_swflag_ich8lan(hw); 1703 nvm->ops.release_nvm(hw);
1349 1704
1350out: 1705out:
1351 if (ret_val) 1706 if (ret_val)
@@ -1603,11 +1958,15 @@ static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1603 return -E1000_ERR_NVM; 1958 return -E1000_ERR_NVM;
1604 } 1959 }
1605 1960
1961 nvm->ops.acquire_nvm(hw);
1962
1606 for (i = 0; i < words; i++) { 1963 for (i = 0; i < words; i++) {
1607 dev_spec->shadow_ram[offset+i].modified = 1; 1964 dev_spec->shadow_ram[offset+i].modified = 1;
1608 dev_spec->shadow_ram[offset+i].value = data[i]; 1965 dev_spec->shadow_ram[offset+i].value = data[i];
1609 } 1966 }
1610 1967
1968 nvm->ops.release_nvm(hw);
1969
1611 return 0; 1970 return 0;
1612} 1971}
1613 1972
@@ -1637,9 +1996,7 @@ static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1637 if (nvm->type != e1000_nvm_flash_sw) 1996 if (nvm->type != e1000_nvm_flash_sw)
1638 goto out; 1997 goto out;
1639 1998
1640 ret_val = e1000_acquire_swflag_ich8lan(hw); 1999 nvm->ops.acquire_nvm(hw);
1641 if (ret_val)
1642 goto out;
1643 2000
1644 /* 2001 /*
1645 * We're writing to the opposite bank so if we're on bank 1, 2002 * We're writing to the opposite bank so if we're on bank 1,
@@ -1657,7 +2014,7 @@ static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1657 old_bank_offset = 0; 2014 old_bank_offset = 0;
1658 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1); 2015 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
1659 if (ret_val) { 2016 if (ret_val) {
1660 e1000_release_swflag_ich8lan(hw); 2017 nvm->ops.release_nvm(hw);
1661 goto out; 2018 goto out;
1662 } 2019 }
1663 } else { 2020 } else {
@@ -1665,7 +2022,7 @@ static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1665 new_bank_offset = 0; 2022 new_bank_offset = 0;
1666 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0); 2023 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
1667 if (ret_val) { 2024 if (ret_val) {
1668 e1000_release_swflag_ich8lan(hw); 2025 nvm->ops.release_nvm(hw);
1669 goto out; 2026 goto out;
1670 } 2027 }
1671 } 2028 }
@@ -1723,7 +2080,7 @@ static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1723 if (ret_val) { 2080 if (ret_val) {
1724 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */ 2081 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
1725 hw_dbg(hw, "Flash commit failed.\n"); 2082 hw_dbg(hw, "Flash commit failed.\n");
1726 e1000_release_swflag_ich8lan(hw); 2083 nvm->ops.release_nvm(hw);
1727 goto out; 2084 goto out;
1728 } 2085 }
1729 2086
@@ -1736,7 +2093,7 @@ static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1736 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD; 2093 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
1737 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data); 2094 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
1738 if (ret_val) { 2095 if (ret_val) {
1739 e1000_release_swflag_ich8lan(hw); 2096 nvm->ops.release_nvm(hw);
1740 goto out; 2097 goto out;
1741 } 2098 }
1742 data &= 0xBFFF; 2099 data &= 0xBFFF;
@@ -1744,7 +2101,7 @@ static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1744 act_offset * 2 + 1, 2101 act_offset * 2 + 1,
1745 (u8)(data >> 8)); 2102 (u8)(data >> 8));
1746 if (ret_val) { 2103 if (ret_val) {
1747 e1000_release_swflag_ich8lan(hw); 2104 nvm->ops.release_nvm(hw);
1748 goto out; 2105 goto out;
1749 } 2106 }
1750 2107
@@ -1757,7 +2114,7 @@ static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1757 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1; 2114 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
1758 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0); 2115 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
1759 if (ret_val) { 2116 if (ret_val) {
1760 e1000_release_swflag_ich8lan(hw); 2117 nvm->ops.release_nvm(hw);
1761 goto out; 2118 goto out;
1762 } 2119 }
1763 2120
@@ -1767,7 +2124,7 @@ static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1767 dev_spec->shadow_ram[i].value = 0xFFFF; 2124 dev_spec->shadow_ram[i].value = 0xFFFF;
1768 } 2125 }
1769 2126
1770 e1000_release_swflag_ich8lan(hw); 2127 nvm->ops.release_nvm(hw);
1771 2128
1772 /* 2129 /*
1773 * Reload the EEPROM, or else modifications will not appear 2130 * Reload the EEPROM, or else modifications will not appear
@@ -1831,14 +2188,12 @@ static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
1831 **/ 2188 **/
1832void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw) 2189void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
1833{ 2190{
2191 struct e1000_nvm_info *nvm = &hw->nvm;
1834 union ich8_flash_protected_range pr0; 2192 union ich8_flash_protected_range pr0;
1835 union ich8_hws_flash_status hsfsts; 2193 union ich8_hws_flash_status hsfsts;
1836 u32 gfpreg; 2194 u32 gfpreg;
1837 s32 ret_val;
1838 2195
1839 ret_val = e1000_acquire_swflag_ich8lan(hw); 2196 nvm->ops.acquire_nvm(hw);
1840 if (ret_val)
1841 return;
1842 2197
1843 gfpreg = er32flash(ICH_FLASH_GFPREG); 2198 gfpreg = er32flash(ICH_FLASH_GFPREG);
1844 2199
@@ -1859,7 +2214,7 @@ void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
1859 hsfsts.hsf_status.flockdn = true; 2214 hsfsts.hsf_status.flockdn = true;
1860 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval); 2215 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1861 2216
1862 e1000_release_swflag_ich8lan(hw); 2217 nvm->ops.release_nvm(hw);
1863} 2218}
1864 2219
1865/** 2220/**
@@ -2229,6 +2584,8 @@ static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
2229 **/ 2584 **/
2230static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw) 2585static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2231{ 2586{
2587 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2588 u16 reg;
2232 u32 ctrl, icr, kab; 2589 u32 ctrl, icr, kab;
2233 s32 ret_val; 2590 s32 ret_val;
2234 2591
@@ -2263,6 +2620,18 @@ static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2263 ew32(PBS, E1000_PBS_16K); 2620 ew32(PBS, E1000_PBS_16K);
2264 } 2621 }
2265 2622
2623 if (hw->mac.type == e1000_pchlan) {
2624 /* Save the NVM K1 bit setting*/
2625 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &reg);
2626 if (ret_val)
2627 return ret_val;
2628
2629 if (reg & E1000_NVM_K1_ENABLE)
2630 dev_spec->nvm_k1_enabled = true;
2631 else
2632 dev_spec->nvm_k1_enabled = false;
2633 }
2634
2266 ctrl = er32(CTRL); 2635 ctrl = er32(CTRL);
2267 2636
2268 if (!e1000_check_reset_block(hw)) { 2637 if (!e1000_check_reset_block(hw)) {
@@ -2304,7 +2673,19 @@ static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2304 hw_dbg(hw, "Auto Read Done did not complete\n"); 2673 hw_dbg(hw, "Auto Read Done did not complete\n");
2305 } 2674 }
2306 } 2675 }
2676 /* Dummy read to clear the phy wakeup bit after lcd reset */
2677 if (hw->mac.type == e1000_pchlan)
2678 e1e_rphy(hw, BM_WUC, &reg);
2307 2679
2680 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2681 if (ret_val)
2682 goto out;
2683
2684 if (hw->mac.type == e1000_pchlan) {
2685 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
2686 if (ret_val)
2687 goto out;
2688 }
2308 /* 2689 /*
2309 * For PCH, this write will make sure that any noise 2690 * For PCH, this write will make sure that any noise
2310 * will be detected as a CRC error and be dropped rather than show up 2691 * will be detected as a CRC error and be dropped rather than show up
@@ -2323,6 +2704,7 @@ static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2323 if (hw->mac.type == e1000_pchlan) 2704 if (hw->mac.type == e1000_pchlan)
2324 ret_val = e1000_hv_phy_workarounds_ich8lan(hw); 2705 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2325 2706
2707out:
2326 return ret_val; 2708 return ret_val;
2327} 2709}
2328 2710
@@ -2627,14 +3009,6 @@ static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
2627 if (ret_val) 3009 if (ret_val)
2628 return ret_val; 3010 return ret_val;
2629 3011
2630 if ((hw->mac.type == e1000_pchlan) && (*speed == SPEED_1000)) {
2631 ret_val = e1000e_write_kmrn_reg(hw,
2632 E1000_KMRNCTRLSTA_K1_CONFIG,
2633 E1000_KMRNCTRLSTA_K1_DISABLE);
2634 if (ret_val)
2635 return ret_val;
2636 }
2637
2638 if ((hw->mac.type == e1000_ich8lan) && 3012 if ((hw->mac.type == e1000_ich8lan) &&
2639 (hw->phy.type == e1000_phy_igp_3) && 3013 (hw->phy.type == e1000_phy_igp_3) &&
2640 (*speed == SPEED_1000)) { 3014 (*speed == SPEED_1000)) {
@@ -2843,9 +3217,8 @@ void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw)
2843 E1000_PHY_CTRL_GBE_DISABLE; 3217 E1000_PHY_CTRL_GBE_DISABLE;
2844 ew32(PHY_CTRL, phy_ctrl); 3218 ew32(PHY_CTRL, phy_ctrl);
2845 3219
2846 /* Workaround SWFLAG unexpectedly set during S0->Sx */
2847 if (hw->mac.type == e1000_pchlan) 3220 if (hw->mac.type == e1000_pchlan)
2848 udelay(500); 3221 e1000_phy_hw_reset_ich8lan(hw);
2849 default: 3222 default:
2850 break; 3223 break;
2851 } 3224 }
@@ -3113,9 +3486,9 @@ static struct e1000_phy_operations ich8_phy_ops = {
3113}; 3486};
3114 3487
3115static struct e1000_nvm_operations ich8_nvm_ops = { 3488static struct e1000_nvm_operations ich8_nvm_ops = {
3116 .acquire_nvm = e1000_acquire_swflag_ich8lan, 3489 .acquire_nvm = e1000_acquire_nvm_ich8lan,
3117 .read_nvm = e1000_read_nvm_ich8lan, 3490 .read_nvm = e1000_read_nvm_ich8lan,
3118 .release_nvm = e1000_release_swflag_ich8lan, 3491 .release_nvm = e1000_release_nvm_ich8lan,
3119 .update_nvm = e1000_update_nvm_checksum_ich8lan, 3492 .update_nvm = e1000_update_nvm_checksum_ich8lan,
3120 .valid_led_default = e1000_valid_led_default_ich8lan, 3493 .valid_led_default = e1000_valid_led_default_ich8lan,
3121 .validate_nvm = e1000_validate_nvm_checksum_ich8lan, 3494 .validate_nvm = e1000_validate_nvm_checksum_ich8lan,
@@ -3186,6 +3559,7 @@ struct e1000_info e1000_pch_info = {
3186 | FLAG_HAS_AMT 3559 | FLAG_HAS_AMT
3187 | FLAG_HAS_FLASH 3560 | FLAG_HAS_FLASH
3188 | FLAG_HAS_JUMBO_FRAMES 3561 | FLAG_HAS_JUMBO_FRAMES
3562 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
3189 | FLAG_APME_IN_WUC, 3563 | FLAG_APME_IN_WUC,
3190 .pba = 26, 3564 .pba = 26,
3191 .max_hw_frame_size = 4096, 3565 .max_hw_frame_size = 4096,
diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c
index 0687c6aa4e46..fad8f9ea0043 100644
--- a/drivers/net/e1000e/netdev.c
+++ b/drivers/net/e1000e/netdev.c
@@ -2769,25 +2769,38 @@ void e1000e_reset(struct e1000_adapter *adapter)
2769 /* 2769 /*
2770 * flow control settings 2770 * flow control settings
2771 * 2771 *
2772 * The high water mark must be low enough to fit two full frame 2772 * The high water mark must be low enough to fit one full frame
2773 * (or the size used for early receive) above it in the Rx FIFO. 2773 * (or the size used for early receive) above it in the Rx FIFO.
2774 * Set it to the lower of: 2774 * Set it to the lower of:
2775 * - 90% of the Rx FIFO size, and 2775 * - 90% of the Rx FIFO size, and
2776 * - the full Rx FIFO size minus the early receive size (for parts 2776 * - the full Rx FIFO size minus the early receive size (for parts
2777 * with ERT support assuming ERT set to E1000_ERT_2048), or 2777 * with ERT support assuming ERT set to E1000_ERT_2048), or
2778 * - the full Rx FIFO size minus two full frames 2778 * - the full Rx FIFO size minus one full frame
2779 */ 2779 */
2780 if ((adapter->flags & FLAG_HAS_ERT) && 2780 if (hw->mac.type == e1000_pchlan) {
2781 (adapter->netdev->mtu > ETH_DATA_LEN)) 2781 /*
2782 hwm = min(((pba << 10) * 9 / 10), 2782 * Workaround PCH LOM adapter hangs with certain network
2783 ((pba << 10) - (E1000_ERT_2048 << 3))); 2783 * loads. If hangs persist, try disabling Tx flow control.
2784 else 2784 */
2785 hwm = min(((pba << 10) * 9 / 10), 2785 if (adapter->netdev->mtu > ETH_DATA_LEN) {
2786 ((pba << 10) - (2 * adapter->max_frame_size))); 2786 fc->high_water = 0x3500;
2787 fc->low_water = 0x1500;
2788 } else {
2789 fc->high_water = 0x5000;
2790 fc->low_water = 0x3000;
2791 }
2792 } else {
2793 if ((adapter->flags & FLAG_HAS_ERT) &&
2794 (adapter->netdev->mtu > ETH_DATA_LEN))
2795 hwm = min(((pba << 10) * 9 / 10),
2796 ((pba << 10) - (E1000_ERT_2048 << 3)));
2797 else
2798 hwm = min(((pba << 10) * 9 / 10),
2799 ((pba << 10) - adapter->max_frame_size));
2787 2800
2788 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ 2801 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
2789 fc->low_water = (fc->high_water - (2 * adapter->max_frame_size)); 2802 fc->low_water = fc->high_water - 8;
2790 fc->low_water &= E1000_FCRTL_RTL; /* 8-byte granularity */ 2803 }
2791 2804
2792 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) 2805 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
2793 fc->pause_time = 0xFFFF; 2806 fc->pause_time = 0xFFFF;
@@ -2813,6 +2826,10 @@ void e1000e_reset(struct e1000_adapter *adapter)
2813 if (mac->ops.init_hw(hw)) 2826 if (mac->ops.init_hw(hw))
2814 e_err("Hardware Error\n"); 2827 e_err("Hardware Error\n");
2815 2828
2829 /* additional part of the flow-control workaround above */
2830 if (hw->mac.type == e1000_pchlan)
2831 ew32(FCRTV_PCH, 0x1000);
2832
2816 e1000_update_mng_vlan(adapter); 2833 e1000_update_mng_vlan(adapter);
2817 2834
2818 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ 2835 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
@@ -3610,7 +3627,7 @@ static void e1000_watchdog_task(struct work_struct *work)
3610 case SPEED_100: 3627 case SPEED_100:
3611 txb2b = 0; 3628 txb2b = 0;
3612 netdev->tx_queue_len = 100; 3629 netdev->tx_queue_len = 100;
3613 /* maybe add some timeout factor ? */ 3630 adapter->tx_timeout_factor = 10;
3614 break; 3631 break;
3615 } 3632 }
3616 3633
@@ -4288,8 +4305,10 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4288 4305
4289 while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) 4306 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4290 msleep(1); 4307 msleep(1);
4291 /* e1000e_down has a dependency on max_frame_size */ 4308 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
4292 adapter->max_frame_size = max_frame; 4309 adapter->max_frame_size = max_frame;
4310 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
4311 netdev->mtu = new_mtu;
4293 if (netif_running(netdev)) 4312 if (netif_running(netdev))
4294 e1000e_down(adapter); 4313 e1000e_down(adapter);
4295 4314
@@ -4319,9 +4338,6 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4319 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN 4338 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
4320 + ETH_FCS_LEN; 4339 + ETH_FCS_LEN;
4321 4340
4322 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
4323 netdev->mtu = new_mtu;
4324
4325 if (netif_running(netdev)) 4341 if (netif_running(netdev))
4326 e1000e_up(adapter); 4342 e1000e_up(adapter);
4327 else 4343 else
diff --git a/drivers/net/e1000e/phy.c b/drivers/net/e1000e/phy.c
index 994401fd0664..85f955f70417 100644
--- a/drivers/net/e1000e/phy.c
+++ b/drivers/net/e1000e/phy.c
@@ -71,7 +71,6 @@ static const u16 e1000_igp_2_cable_length_table[] =
71#define I82577_CFG_ASSERT_CRS_ON_TX (1 << 15) 71#define I82577_CFG_ASSERT_CRS_ON_TX (1 << 15)
72#define I82577_CFG_ENABLE_DOWNSHIFT (3 << 10) /* auto downshift 100/10 */ 72#define I82577_CFG_ENABLE_DOWNSHIFT (3 << 10) /* auto downshift 100/10 */
73#define I82577_CTRL_REG 23 73#define I82577_CTRL_REG 23
74#define I82577_CTRL_DOWNSHIFT_MASK (7 << 10)
75 74
76/* 82577 specific PHY registers */ 75/* 82577 specific PHY registers */
77#define I82577_PHY_CTRL_2 18 76#define I82577_PHY_CTRL_2 18
@@ -95,13 +94,6 @@ static const u16 e1000_igp_2_cable_length_table[] =
95/* BM PHY Copper Specific Control 1 */ 94/* BM PHY Copper Specific Control 1 */
96#define BM_CS_CTRL1 16 95#define BM_CS_CTRL1 16
97 96
98/* BM PHY Copper Specific Status */
99#define BM_CS_STATUS 17
100#define BM_CS_STATUS_LINK_UP 0x0400
101#define BM_CS_STATUS_RESOLVED 0x0800
102#define BM_CS_STATUS_SPEED_MASK 0xC000
103#define BM_CS_STATUS_SPEED_1000 0x8000
104
105#define HV_MUX_DATA_CTRL PHY_REG(776, 16) 97#define HV_MUX_DATA_CTRL PHY_REG(776, 16)
106#define HV_MUX_DATA_CTRL_GEN_TO_MAC 0x0400 98#define HV_MUX_DATA_CTRL_GEN_TO_MAC 0x0400
107#define HV_MUX_DATA_CTRL_FORCE_SPEED 0x0004 99#define HV_MUX_DATA_CTRL_FORCE_SPEED 0x0004
@@ -164,16 +156,25 @@ s32 e1000e_get_phy_id(struct e1000_hw *hw)
164 * MDIC mode. No harm in trying again in this case since 156 * MDIC mode. No harm in trying again in this case since
165 * the PHY ID is unknown at this point anyway 157 * the PHY ID is unknown at this point anyway
166 */ 158 */
159 ret_val = phy->ops.acquire_phy(hw);
160 if (ret_val)
161 goto out;
167 ret_val = e1000_set_mdio_slow_mode_hv(hw, true); 162 ret_val = e1000_set_mdio_slow_mode_hv(hw, true);
168 if (ret_val) 163 if (ret_val)
169 goto out; 164 goto out;
165 phy->ops.release_phy(hw);
170 166
171 retry_count++; 167 retry_count++;
172 } 168 }
173out: 169out:
174 /* Revert to MDIO fast mode, if applicable */ 170 /* Revert to MDIO fast mode, if applicable */
175 if (retry_count) 171 if (retry_count) {
172 ret_val = phy->ops.acquire_phy(hw);
173 if (ret_val)
174 return ret_val;
176 ret_val = e1000_set_mdio_slow_mode_hv(hw, false); 175 ret_val = e1000_set_mdio_slow_mode_hv(hw, false);
176 phy->ops.release_phy(hw);
177 }
177 178
178 return ret_val; 179 return ret_val;
179} 180}
@@ -354,94 +355,173 @@ s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
354} 355}
355 356
356/** 357/**
357 * e1000e_read_phy_reg_igp - Read igp PHY register 358 * __e1000e_read_phy_reg_igp - Read igp PHY register
358 * @hw: pointer to the HW structure 359 * @hw: pointer to the HW structure
359 * @offset: register offset to be read 360 * @offset: register offset to be read
360 * @data: pointer to the read data 361 * @data: pointer to the read data
362 * @locked: semaphore has already been acquired or not
361 * 363 *
362 * Acquires semaphore, if necessary, then reads the PHY register at offset 364 * Acquires semaphore, if necessary, then reads the PHY register at offset
363 * and storing the retrieved information in data. Release any acquired 365 * and stores the retrieved information in data. Release any acquired
364 * semaphores before exiting. 366 * semaphores before exiting.
365 **/ 367 **/
366s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data) 368static s32 __e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
369 bool locked)
367{ 370{
368 s32 ret_val; 371 s32 ret_val = 0;
369 372
370 ret_val = hw->phy.ops.acquire_phy(hw); 373 if (!locked) {
371 if (ret_val) 374 if (!(hw->phy.ops.acquire_phy))
372 return ret_val; 375 goto out;
376
377 ret_val = hw->phy.ops.acquire_phy(hw);
378 if (ret_val)
379 goto out;
380 }
373 381
374 if (offset > MAX_PHY_MULTI_PAGE_REG) { 382 if (offset > MAX_PHY_MULTI_PAGE_REG) {
375 ret_val = e1000e_write_phy_reg_mdic(hw, 383 ret_val = e1000e_write_phy_reg_mdic(hw,
376 IGP01E1000_PHY_PAGE_SELECT, 384 IGP01E1000_PHY_PAGE_SELECT,
377 (u16)offset); 385 (u16)offset);
378 if (ret_val) { 386 if (ret_val)
379 hw->phy.ops.release_phy(hw); 387 goto release;
380 return ret_val;
381 }
382 } 388 }
383 389
384 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset, 390 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
385 data); 391 data);
386
387 hw->phy.ops.release_phy(hw);
388 392
393release:
394 if (!locked)
395 hw->phy.ops.release_phy(hw);
396out:
389 return ret_val; 397 return ret_val;
390} 398}
391 399
392/** 400/**
401 * e1000e_read_phy_reg_igp - Read igp PHY register
402 * @hw: pointer to the HW structure
403 * @offset: register offset to be read
404 * @data: pointer to the read data
405 *
406 * Acquires semaphore then reads the PHY register at offset and stores the
407 * retrieved information in data.
408 * Release the acquired semaphore before exiting.
409 **/
410s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
411{
412 return __e1000e_read_phy_reg_igp(hw, offset, data, false);
413}
414
415/**
416 * e1000e_read_phy_reg_igp_locked - Read igp PHY register
417 * @hw: pointer to the HW structure
418 * @offset: register offset to be read
419 * @data: pointer to the read data
420 *
421 * Reads the PHY register at offset and stores the retrieved information
422 * in data. Assumes semaphore already acquired.
423 **/
424s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
425{
426 return __e1000e_read_phy_reg_igp(hw, offset, data, true);
427}
428
429/**
393 * e1000e_write_phy_reg_igp - Write igp PHY register 430 * e1000e_write_phy_reg_igp - Write igp PHY register
394 * @hw: pointer to the HW structure 431 * @hw: pointer to the HW structure
395 * @offset: register offset to write to 432 * @offset: register offset to write to
396 * @data: data to write at register offset 433 * @data: data to write at register offset
434 * @locked: semaphore has already been acquired or not
397 * 435 *
398 * Acquires semaphore, if necessary, then writes the data to PHY register 436 * Acquires semaphore, if necessary, then writes the data to PHY register
399 * at the offset. Release any acquired semaphores before exiting. 437 * at the offset. Release any acquired semaphores before exiting.
400 **/ 438 **/
401s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data) 439static s32 __e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
440 bool locked)
402{ 441{
403 s32 ret_val; 442 s32 ret_val = 0;
404 443
405 ret_val = hw->phy.ops.acquire_phy(hw); 444 if (!locked) {
406 if (ret_val) 445 if (!(hw->phy.ops.acquire_phy))
407 return ret_val; 446 goto out;
447
448 ret_val = hw->phy.ops.acquire_phy(hw);
449 if (ret_val)
450 goto out;
451 }
408 452
409 if (offset > MAX_PHY_MULTI_PAGE_REG) { 453 if (offset > MAX_PHY_MULTI_PAGE_REG) {
410 ret_val = e1000e_write_phy_reg_mdic(hw, 454 ret_val = e1000e_write_phy_reg_mdic(hw,
411 IGP01E1000_PHY_PAGE_SELECT, 455 IGP01E1000_PHY_PAGE_SELECT,
412 (u16)offset); 456 (u16)offset);
413 if (ret_val) { 457 if (ret_val)
414 hw->phy.ops.release_phy(hw); 458 goto release;
415 return ret_val;
416 }
417 } 459 }
418 460
419 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset, 461 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
420 data); 462 data);
421 463
422 hw->phy.ops.release_phy(hw); 464release:
465 if (!locked)
466 hw->phy.ops.release_phy(hw);
423 467
468out:
424 return ret_val; 469 return ret_val;
425} 470}
426 471
427/** 472/**
428 * e1000e_read_kmrn_reg - Read kumeran register 473 * e1000e_write_phy_reg_igp - Write igp PHY register
474 * @hw: pointer to the HW structure
475 * @offset: register offset to write to
476 * @data: data to write at register offset
477 *
478 * Acquires semaphore then writes the data to PHY register
479 * at the offset. Release any acquired semaphores before exiting.
480 **/
481s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
482{
483 return __e1000e_write_phy_reg_igp(hw, offset, data, false);
484}
485
486/**
487 * e1000e_write_phy_reg_igp_locked - Write igp PHY register
488 * @hw: pointer to the HW structure
489 * @offset: register offset to write to
490 * @data: data to write at register offset
491 *
492 * Writes the data to PHY register at the offset.
493 * Assumes semaphore already acquired.
494 **/
495s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
496{
497 return __e1000e_write_phy_reg_igp(hw, offset, data, true);
498}
499
500/**
501 * __e1000_read_kmrn_reg - Read kumeran register
429 * @hw: pointer to the HW structure 502 * @hw: pointer to the HW structure
430 * @offset: register offset to be read 503 * @offset: register offset to be read
431 * @data: pointer to the read data 504 * @data: pointer to the read data
505 * @locked: semaphore has already been acquired or not
432 * 506 *
433 * Acquires semaphore, if necessary. Then reads the PHY register at offset 507 * Acquires semaphore, if necessary. Then reads the PHY register at offset
434 * using the kumeran interface. The information retrieved is stored in data. 508 * using the kumeran interface. The information retrieved is stored in data.
435 * Release any acquired semaphores before exiting. 509 * Release any acquired semaphores before exiting.
436 **/ 510 **/
437s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data) 511static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
512 bool locked)
438{ 513{
439 u32 kmrnctrlsta; 514 u32 kmrnctrlsta;
440 s32 ret_val; 515 s32 ret_val = 0;
441 516
442 ret_val = hw->phy.ops.acquire_phy(hw); 517 if (!locked) {
443 if (ret_val) 518 if (!(hw->phy.ops.acquire_phy))
444 return ret_val; 519 goto out;
520
521 ret_val = hw->phy.ops.acquire_phy(hw);
522 if (ret_val)
523 goto out;
524 }
445 525
446 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) & 526 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
447 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN; 527 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
@@ -452,41 +532,111 @@ s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
452 kmrnctrlsta = er32(KMRNCTRLSTA); 532 kmrnctrlsta = er32(KMRNCTRLSTA);
453 *data = (u16)kmrnctrlsta; 533 *data = (u16)kmrnctrlsta;
454 534
455 hw->phy.ops.release_phy(hw); 535 if (!locked)
536 hw->phy.ops.release_phy(hw);
456 537
538out:
457 return ret_val; 539 return ret_val;
458} 540}
459 541
460/** 542/**
461 * e1000e_write_kmrn_reg - Write kumeran register 543 * e1000e_read_kmrn_reg - Read kumeran register
544 * @hw: pointer to the HW structure
545 * @offset: register offset to be read
546 * @data: pointer to the read data
547 *
548 * Acquires semaphore then reads the PHY register at offset using the
549 * kumeran interface. The information retrieved is stored in data.
550 * Release the acquired semaphore before exiting.
551 **/
552s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
553{
554 return __e1000_read_kmrn_reg(hw, offset, data, false);
555}
556
557/**
558 * e1000e_read_kmrn_reg_locked - Read kumeran register
559 * @hw: pointer to the HW structure
560 * @offset: register offset to be read
561 * @data: pointer to the read data
562 *
563 * Reads the PHY register at offset using the kumeran interface. The
564 * information retrieved is stored in data.
565 * Assumes semaphore already acquired.
566 **/
567s32 e1000e_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
568{
569 return __e1000_read_kmrn_reg(hw, offset, data, true);
570}
571
572/**
573 * __e1000_write_kmrn_reg - Write kumeran register
462 * @hw: pointer to the HW structure 574 * @hw: pointer to the HW structure
463 * @offset: register offset to write to 575 * @offset: register offset to write to
464 * @data: data to write at register offset 576 * @data: data to write at register offset
577 * @locked: semaphore has already been acquired or not
465 * 578 *
466 * Acquires semaphore, if necessary. Then write the data to PHY register 579 * Acquires semaphore, if necessary. Then write the data to PHY register
467 * at the offset using the kumeran interface. Release any acquired semaphores 580 * at the offset using the kumeran interface. Release any acquired semaphores
468 * before exiting. 581 * before exiting.
469 **/ 582 **/
470s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data) 583static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
584 bool locked)
471{ 585{
472 u32 kmrnctrlsta; 586 u32 kmrnctrlsta;
473 s32 ret_val; 587 s32 ret_val = 0;
474 588
475 ret_val = hw->phy.ops.acquire_phy(hw); 589 if (!locked) {
476 if (ret_val) 590 if (!(hw->phy.ops.acquire_phy))
477 return ret_val; 591 goto out;
592
593 ret_val = hw->phy.ops.acquire_phy(hw);
594 if (ret_val)
595 goto out;
596 }
478 597
479 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) & 598 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
480 E1000_KMRNCTRLSTA_OFFSET) | data; 599 E1000_KMRNCTRLSTA_OFFSET) | data;
481 ew32(KMRNCTRLSTA, kmrnctrlsta); 600 ew32(KMRNCTRLSTA, kmrnctrlsta);
482 601
483 udelay(2); 602 udelay(2);
484 hw->phy.ops.release_phy(hw);
485 603
604 if (!locked)
605 hw->phy.ops.release_phy(hw);
606
607out:
486 return ret_val; 608 return ret_val;
487} 609}
488 610
489/** 611/**
612 * e1000e_write_kmrn_reg - Write kumeran register
613 * @hw: pointer to the HW structure
614 * @offset: register offset to write to
615 * @data: data to write at register offset
616 *
617 * Acquires semaphore then writes the data to the PHY register at the offset
618 * using the kumeran interface. Release the acquired semaphore before exiting.
619 **/
620s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
621{
622 return __e1000_write_kmrn_reg(hw, offset, data, false);
623}
624
625/**
626 * e1000e_write_kmrn_reg_locked - Write kumeran register
627 * @hw: pointer to the HW structure
628 * @offset: register offset to write to
629 * @data: data to write at register offset
630 *
631 * Write the data to PHY register at the offset using the kumeran interface.
632 * Assumes semaphore already acquired.
633 **/
634s32 e1000e_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
635{
636 return __e1000_write_kmrn_reg(hw, offset, data, true);
637}
638
639/**
490 * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link 640 * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
491 * @hw: pointer to the HW structure 641 * @hw: pointer to the HW structure
492 * 642 *
@@ -509,15 +659,6 @@ s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
509 phy_data |= I82577_CFG_ENABLE_DOWNSHIFT; 659 phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
510 660
511 ret_val = phy->ops.write_phy_reg(hw, I82577_CFG_REG, phy_data); 661 ret_val = phy->ops.write_phy_reg(hw, I82577_CFG_REG, phy_data);
512 if (ret_val)
513 goto out;
514
515 /* Set number of link attempts before downshift */
516 ret_val = phy->ops.read_phy_reg(hw, I82577_CTRL_REG, &phy_data);
517 if (ret_val)
518 goto out;
519 phy_data &= ~I82577_CTRL_DOWNSHIFT_MASK;
520 ret_val = phy->ops.write_phy_reg(hw, I82577_CTRL_REG, phy_data);
521 662
522out: 663out:
523 return ret_val; 664 return ret_val;
@@ -2105,6 +2246,10 @@ s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2105 u32 page = offset >> IGP_PAGE_SHIFT; 2246 u32 page = offset >> IGP_PAGE_SHIFT;
2106 u32 page_shift = 0; 2247 u32 page_shift = 0;
2107 2248
2249 ret_val = hw->phy.ops.acquire_phy(hw);
2250 if (ret_val)
2251 return ret_val;
2252
2108 /* Page 800 works differently than the rest so it has its own func */ 2253 /* Page 800 works differently than the rest so it has its own func */
2109 if (page == BM_WUC_PAGE) { 2254 if (page == BM_WUC_PAGE) {
2110 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data, 2255 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
@@ -2112,10 +2257,6 @@ s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2112 goto out; 2257 goto out;
2113 } 2258 }
2114 2259
2115 ret_val = hw->phy.ops.acquire_phy(hw);
2116 if (ret_val)
2117 goto out;
2118
2119 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset); 2260 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2120 2261
2121 if (offset > MAX_PHY_MULTI_PAGE_REG) { 2262 if (offset > MAX_PHY_MULTI_PAGE_REG) {
@@ -2135,18 +2276,15 @@ s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2135 /* Page is shifted left, PHY expects (page x 32) */ 2276 /* Page is shifted left, PHY expects (page x 32) */
2136 ret_val = e1000e_write_phy_reg_mdic(hw, page_select, 2277 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2137 (page << page_shift)); 2278 (page << page_shift));
2138 if (ret_val) { 2279 if (ret_val)
2139 hw->phy.ops.release_phy(hw);
2140 goto out; 2280 goto out;
2141 }
2142 } 2281 }
2143 2282
2144 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset, 2283 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2145 data); 2284 data);
2146 2285
2147 hw->phy.ops.release_phy(hw);
2148
2149out: 2286out:
2287 hw->phy.ops.release_phy(hw);
2150 return ret_val; 2288 return ret_val;
2151} 2289}
2152 2290
@@ -2167,6 +2305,10 @@ s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2167 u32 page = offset >> IGP_PAGE_SHIFT; 2305 u32 page = offset >> IGP_PAGE_SHIFT;
2168 u32 page_shift = 0; 2306 u32 page_shift = 0;
2169 2307
2308 ret_val = hw->phy.ops.acquire_phy(hw);
2309 if (ret_val)
2310 return ret_val;
2311
2170 /* Page 800 works differently than the rest so it has its own func */ 2312 /* Page 800 works differently than the rest so it has its own func */
2171 if (page == BM_WUC_PAGE) { 2313 if (page == BM_WUC_PAGE) {
2172 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data, 2314 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
@@ -2174,10 +2316,6 @@ s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2174 goto out; 2316 goto out;
2175 } 2317 }
2176 2318
2177 ret_val = hw->phy.ops.acquire_phy(hw);
2178 if (ret_val)
2179 goto out;
2180
2181 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset); 2319 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2182 2320
2183 if (offset > MAX_PHY_MULTI_PAGE_REG) { 2321 if (offset > MAX_PHY_MULTI_PAGE_REG) {
@@ -2197,17 +2335,14 @@ s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2197 /* Page is shifted left, PHY expects (page x 32) */ 2335 /* Page is shifted left, PHY expects (page x 32) */
2198 ret_val = e1000e_write_phy_reg_mdic(hw, page_select, 2336 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2199 (page << page_shift)); 2337 (page << page_shift));
2200 if (ret_val) { 2338 if (ret_val)
2201 hw->phy.ops.release_phy(hw);
2202 goto out; 2339 goto out;
2203 }
2204 } 2340 }
2205 2341
2206 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset, 2342 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2207 data); 2343 data);
2208 hw->phy.ops.release_phy(hw);
2209
2210out: 2344out:
2345 hw->phy.ops.release_phy(hw);
2211 return ret_val; 2346 return ret_val;
2212} 2347}
2213 2348
@@ -2226,17 +2361,17 @@ s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2226 s32 ret_val; 2361 s32 ret_val;
2227 u16 page = (u16)(offset >> IGP_PAGE_SHIFT); 2362 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2228 2363
2364 ret_val = hw->phy.ops.acquire_phy(hw);
2365 if (ret_val)
2366 return ret_val;
2367
2229 /* Page 800 works differently than the rest so it has its own func */ 2368 /* Page 800 works differently than the rest so it has its own func */
2230 if (page == BM_WUC_PAGE) { 2369 if (page == BM_WUC_PAGE) {
2231 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data, 2370 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2232 true); 2371 true);
2233 return ret_val; 2372 goto out;
2234 } 2373 }
2235 2374
2236 ret_val = hw->phy.ops.acquire_phy(hw);
2237 if (ret_val)
2238 return ret_val;
2239
2240 hw->phy.addr = 1; 2375 hw->phy.addr = 1;
2241 2376
2242 if (offset > MAX_PHY_MULTI_PAGE_REG) { 2377 if (offset > MAX_PHY_MULTI_PAGE_REG) {
@@ -2245,16 +2380,14 @@ s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2245 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT, 2380 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2246 page); 2381 page);
2247 2382
2248 if (ret_val) { 2383 if (ret_val)
2249 hw->phy.ops.release_phy(hw); 2384 goto out;
2250 return ret_val;
2251 }
2252 } 2385 }
2253 2386
2254 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset, 2387 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2255 data); 2388 data);
2389out:
2256 hw->phy.ops.release_phy(hw); 2390 hw->phy.ops.release_phy(hw);
2257
2258 return ret_val; 2391 return ret_val;
2259} 2392}
2260 2393
@@ -2272,17 +2405,17 @@ s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2272 s32 ret_val; 2405 s32 ret_val;
2273 u16 page = (u16)(offset >> IGP_PAGE_SHIFT); 2406 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2274 2407
2408 ret_val = hw->phy.ops.acquire_phy(hw);
2409 if (ret_val)
2410 return ret_val;
2411
2275 /* Page 800 works differently than the rest so it has its own func */ 2412 /* Page 800 works differently than the rest so it has its own func */
2276 if (page == BM_WUC_PAGE) { 2413 if (page == BM_WUC_PAGE) {
2277 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data, 2414 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2278 false); 2415 false);
2279 return ret_val; 2416 goto out;
2280 } 2417 }
2281 2418
2282 ret_val = hw->phy.ops.acquire_phy(hw);
2283 if (ret_val)
2284 return ret_val;
2285
2286 hw->phy.addr = 1; 2419 hw->phy.addr = 1;
2287 2420
2288 if (offset > MAX_PHY_MULTI_PAGE_REG) { 2421 if (offset > MAX_PHY_MULTI_PAGE_REG) {
@@ -2290,17 +2423,15 @@ s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2290 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT, 2423 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2291 page); 2424 page);
2292 2425
2293 if (ret_val) { 2426 if (ret_val)
2294 hw->phy.ops.release_phy(hw); 2427 goto out;
2295 return ret_val;
2296 }
2297 } 2428 }
2298 2429
2299 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset, 2430 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2300 data); 2431 data);
2301 2432
2433out:
2302 hw->phy.ops.release_phy(hw); 2434 hw->phy.ops.release_phy(hw);
2303
2304 return ret_val; 2435 return ret_val;
2305} 2436}
2306 2437
@@ -2320,6 +2451,8 @@ s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2320 * 3) Write the address using the address opcode (0x11) 2451 * 3) Write the address using the address opcode (0x11)
2321 * 4) Read or write the data using the data opcode (0x12) 2452 * 4) Read or write the data using the data opcode (0x12)
2322 * 5) Restore 769_17.2 to its original value 2453 * 5) Restore 769_17.2 to its original value
2454 *
2455 * Assumes semaphore already acquired.
2323 **/ 2456 **/
2324static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset, 2457static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
2325 u16 *data, bool read) 2458 u16 *data, bool read)
@@ -2327,20 +2460,12 @@ static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
2327 s32 ret_val; 2460 s32 ret_val;
2328 u16 reg = BM_PHY_REG_NUM(offset); 2461 u16 reg = BM_PHY_REG_NUM(offset);
2329 u16 phy_reg = 0; 2462 u16 phy_reg = 0;
2330 u8 phy_acquired = 1;
2331
2332 2463
2333 /* Gig must be disabled for MDIO accesses to page 800 */ 2464 /* Gig must be disabled for MDIO accesses to page 800 */
2334 if ((hw->mac.type == e1000_pchlan) && 2465 if ((hw->mac.type == e1000_pchlan) &&
2335 (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE))) 2466 (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
2336 hw_dbg(hw, "Attempting to access page 800 while gig enabled\n"); 2467 hw_dbg(hw, "Attempting to access page 800 while gig enabled\n");
2337 2468
2338 ret_val = hw->phy.ops.acquire_phy(hw);
2339 if (ret_val) {
2340 phy_acquired = 0;
2341 goto out;
2342 }
2343
2344 /* All operations in this function are phy address 1 */ 2469 /* All operations in this function are phy address 1 */
2345 hw->phy.addr = 1; 2470 hw->phy.addr = 1;
2346 2471
@@ -2397,8 +2522,6 @@ static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
2397 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg); 2522 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2398 2523
2399out: 2524out:
2400 if (phy_acquired == 1)
2401 hw->phy.ops.release_phy(hw);
2402 return ret_val; 2525 return ret_val;
2403} 2526}
2404 2527
@@ -2439,52 +2562,63 @@ static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2439 return 0; 2562 return 0;
2440} 2563}
2441 2564
2565/**
2566 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
2567 * @hw: pointer to the HW structure
2568 * @slow: true for slow mode, false for normal mode
2569 *
2570 * Assumes semaphore already acquired.
2571 **/
2442s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw, bool slow) 2572s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw, bool slow)
2443{ 2573{
2444 s32 ret_val = 0; 2574 s32 ret_val = 0;
2445 u16 data = 0; 2575 u16 data = 0;
2446 2576
2447 ret_val = hw->phy.ops.acquire_phy(hw);
2448 if (ret_val)
2449 return ret_val;
2450
2451 /* Set MDIO mode - page 769, register 16: 0x2580==slow, 0x2180==fast */ 2577 /* Set MDIO mode - page 769, register 16: 0x2580==slow, 0x2180==fast */
2452 hw->phy.addr = 1; 2578 hw->phy.addr = 1;
2453 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 2579 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2454 (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT)); 2580 (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2455 if (ret_val) { 2581 if (ret_val)
2456 hw->phy.ops.release_phy(hw); 2582 goto out;
2457 return ret_val; 2583
2458 }
2459 ret_val = e1000e_write_phy_reg_mdic(hw, BM_CS_CTRL1, 2584 ret_val = e1000e_write_phy_reg_mdic(hw, BM_CS_CTRL1,
2460 (0x2180 | (slow << 10))); 2585 (0x2180 | (slow << 10)));
2586 if (ret_val)
2587 goto out;
2461 2588
2462 /* dummy read when reverting to fast mode - throw away result */ 2589 /* dummy read when reverting to fast mode - throw away result */
2463 if (!slow) 2590 if (!slow)
2464 e1000e_read_phy_reg_mdic(hw, BM_CS_CTRL1, &data); 2591 ret_val = e1000e_read_phy_reg_mdic(hw, BM_CS_CTRL1, &data);
2465
2466 hw->phy.ops.release_phy(hw);
2467 2592
2593out:
2468 return ret_val; 2594 return ret_val;
2469} 2595}
2470 2596
2471/** 2597/**
2472 * e1000_read_phy_reg_hv - Read HV PHY register 2598 * __e1000_read_phy_reg_hv - Read HV PHY register
2473 * @hw: pointer to the HW structure 2599 * @hw: pointer to the HW structure
2474 * @offset: register offset to be read 2600 * @offset: register offset to be read
2475 * @data: pointer to the read data 2601 * @data: pointer to the read data
2602 * @locked: semaphore has already been acquired or not
2476 * 2603 *
2477 * Acquires semaphore, if necessary, then reads the PHY register at offset 2604 * Acquires semaphore, if necessary, then reads the PHY register at offset
2478 * and storing the retrieved information in data. Release any acquired 2605 * and stores the retrieved information in data. Release any acquired
2479 * semaphore before exiting. 2606 * semaphore before exiting.
2480 **/ 2607 **/
2481s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data) 2608static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
2609 bool locked)
2482{ 2610{
2483 s32 ret_val; 2611 s32 ret_val;
2484 u16 page = BM_PHY_REG_PAGE(offset); 2612 u16 page = BM_PHY_REG_PAGE(offset);
2485 u16 reg = BM_PHY_REG_NUM(offset); 2613 u16 reg = BM_PHY_REG_NUM(offset);
2486 bool in_slow_mode = false; 2614 bool in_slow_mode = false;
2487 2615
2616 if (!locked) {
2617 ret_val = hw->phy.ops.acquire_phy(hw);
2618 if (ret_val)
2619 return ret_val;
2620 }
2621
2488 /* Workaround failure in MDIO access while cable is disconnected */ 2622 /* Workaround failure in MDIO access while cable is disconnected */
2489 if ((hw->phy.type == e1000_phy_82577) && 2623 if ((hw->phy.type == e1000_phy_82577) &&
2490 !(er32(STATUS) & E1000_STATUS_LU)) { 2624 !(er32(STATUS) & E1000_STATUS_LU)) {
@@ -2508,63 +2642,92 @@ s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2508 goto out; 2642 goto out;
2509 } 2643 }
2510 2644
2511 ret_val = hw->phy.ops.acquire_phy(hw);
2512 if (ret_val)
2513 goto out;
2514
2515 hw->phy.addr = e1000_get_phy_addr_for_hv_page(page); 2645 hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
2516 2646
2517 if (page == HV_INTC_FC_PAGE_START) 2647 if (page == HV_INTC_FC_PAGE_START)
2518 page = 0; 2648 page = 0;
2519 2649
2520 if (reg > MAX_PHY_MULTI_PAGE_REG) { 2650 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2521 if ((hw->phy.type != e1000_phy_82578) || 2651 u32 phy_addr = hw->phy.addr;
2522 ((reg != I82578_ADDR_REG) && 2652
2523 (reg != I82578_ADDR_REG + 1))) { 2653 hw->phy.addr = 1;
2524 u32 phy_addr = hw->phy.addr; 2654
2525 2655 /* Page is shifted left, PHY expects (page x 32) */
2526 hw->phy.addr = 1; 2656 ret_val = e1000e_write_phy_reg_mdic(hw,
2527 2657 IGP01E1000_PHY_PAGE_SELECT,
2528 /* Page is shifted left, PHY expects (page x 32) */ 2658 (page << IGP_PAGE_SHIFT));
2529 ret_val = e1000e_write_phy_reg_mdic(hw, 2659 hw->phy.addr = phy_addr;
2530 IGP01E1000_PHY_PAGE_SELECT, 2660
2531 (page << IGP_PAGE_SHIFT)); 2661 if (ret_val)
2532 if (ret_val) { 2662 goto out;
2533 hw->phy.ops.release_phy(hw);
2534 goto out;
2535 }
2536 hw->phy.addr = phy_addr;
2537 }
2538 } 2663 }
2539 2664
2540 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg, 2665 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2541 data); 2666 data);
2542 hw->phy.ops.release_phy(hw);
2543
2544out: 2667out:
2545 /* Revert to MDIO fast mode, if applicable */ 2668 /* Revert to MDIO fast mode, if applicable */
2546 if ((hw->phy.type == e1000_phy_82577) && in_slow_mode) 2669 if ((hw->phy.type == e1000_phy_82577) && in_slow_mode)
2547 ret_val = e1000_set_mdio_slow_mode_hv(hw, false); 2670 ret_val |= e1000_set_mdio_slow_mode_hv(hw, false);
2671
2672 if (!locked)
2673 hw->phy.ops.release_phy(hw);
2548 2674
2549 return ret_val; 2675 return ret_val;
2550} 2676}
2551 2677
2552/** 2678/**
2553 * e1000_write_phy_reg_hv - Write HV PHY register 2679 * e1000_read_phy_reg_hv - Read HV PHY register
2680 * @hw: pointer to the HW structure
2681 * @offset: register offset to be read
2682 * @data: pointer to the read data
2683 *
2684 * Acquires semaphore then reads the PHY register at offset and stores
2685 * the retrieved information in data. Release the acquired semaphore
2686 * before exiting.
2687 **/
2688s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2689{
2690 return __e1000_read_phy_reg_hv(hw, offset, data, false);
2691}
2692
2693/**
2694 * e1000_read_phy_reg_hv_locked - Read HV PHY register
2695 * @hw: pointer to the HW structure
2696 * @offset: register offset to be read
2697 * @data: pointer to the read data
2698 *
2699 * Reads the PHY register at offset and stores the retrieved information
2700 * in data. Assumes semaphore already acquired.
2701 **/
2702s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
2703{
2704 return __e1000_read_phy_reg_hv(hw, offset, data, true);
2705}
2706
2707/**
2708 * __e1000_write_phy_reg_hv - Write HV PHY register
2554 * @hw: pointer to the HW structure 2709 * @hw: pointer to the HW structure
2555 * @offset: register offset to write to 2710 * @offset: register offset to write to
2556 * @data: data to write at register offset 2711 * @data: data to write at register offset
2712 * @locked: semaphore has already been acquired or not
2557 * 2713 *
2558 * Acquires semaphore, if necessary, then writes the data to PHY register 2714 * Acquires semaphore, if necessary, then writes the data to PHY register
2559 * at the offset. Release any acquired semaphores before exiting. 2715 * at the offset. Release any acquired semaphores before exiting.
2560 **/ 2716 **/
2561s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data) 2717static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
2718 bool locked)
2562{ 2719{
2563 s32 ret_val; 2720 s32 ret_val;
2564 u16 page = BM_PHY_REG_PAGE(offset); 2721 u16 page = BM_PHY_REG_PAGE(offset);
2565 u16 reg = BM_PHY_REG_NUM(offset); 2722 u16 reg = BM_PHY_REG_NUM(offset);
2566 bool in_slow_mode = false; 2723 bool in_slow_mode = false;
2567 2724
2725 if (!locked) {
2726 ret_val = hw->phy.ops.acquire_phy(hw);
2727 if (ret_val)
2728 return ret_val;
2729 }
2730
2568 /* Workaround failure in MDIO access while cable is disconnected */ 2731 /* Workaround failure in MDIO access while cable is disconnected */
2569 if ((hw->phy.type == e1000_phy_82577) && 2732 if ((hw->phy.type == e1000_phy_82577) &&
2570 !(er32(STATUS) & E1000_STATUS_LU)) { 2733 !(er32(STATUS) & E1000_STATUS_LU)) {
@@ -2588,10 +2751,6 @@ s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2588 goto out; 2751 goto out;
2589 } 2752 }
2590 2753
2591 ret_val = hw->phy.ops.acquire_phy(hw);
2592 if (ret_val)
2593 goto out;
2594
2595 hw->phy.addr = e1000_get_phy_addr_for_hv_page(page); 2754 hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
2596 2755
2597 if (page == HV_INTC_FC_PAGE_START) 2756 if (page == HV_INTC_FC_PAGE_START)
@@ -2607,50 +2766,70 @@ s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2607 ((MAX_PHY_REG_ADDRESS & reg) == 0) && 2766 ((MAX_PHY_REG_ADDRESS & reg) == 0) &&
2608 (data & (1 << 11))) { 2767 (data & (1 << 11))) {
2609 u16 data2 = 0x7EFF; 2768 u16 data2 = 0x7EFF;
2610 hw->phy.ops.release_phy(hw);
2611 ret_val = e1000_access_phy_debug_regs_hv(hw, (1 << 6) | 0x3, 2769 ret_val = e1000_access_phy_debug_regs_hv(hw, (1 << 6) | 0x3,
2612 &data2, false); 2770 &data2, false);
2613 if (ret_val) 2771 if (ret_val)
2614 goto out; 2772 goto out;
2615
2616 ret_val = hw->phy.ops.acquire_phy(hw);
2617 if (ret_val)
2618 goto out;
2619 } 2773 }
2620 2774
2621 if (reg > MAX_PHY_MULTI_PAGE_REG) { 2775 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2622 if ((hw->phy.type != e1000_phy_82578) || 2776 u32 phy_addr = hw->phy.addr;
2623 ((reg != I82578_ADDR_REG) && 2777
2624 (reg != I82578_ADDR_REG + 1))) { 2778 hw->phy.addr = 1;
2625 u32 phy_addr = hw->phy.addr; 2779
2626 2780 /* Page is shifted left, PHY expects (page x 32) */
2627 hw->phy.addr = 1; 2781 ret_val = e1000e_write_phy_reg_mdic(hw,
2628 2782 IGP01E1000_PHY_PAGE_SELECT,
2629 /* Page is shifted left, PHY expects (page x 32) */ 2783 (page << IGP_PAGE_SHIFT));
2630 ret_val = e1000e_write_phy_reg_mdic(hw, 2784 hw->phy.addr = phy_addr;
2631 IGP01E1000_PHY_PAGE_SELECT, 2785
2632 (page << IGP_PAGE_SHIFT)); 2786 if (ret_val)
2633 if (ret_val) { 2787 goto out;
2634 hw->phy.ops.release_phy(hw);
2635 goto out;
2636 }
2637 hw->phy.addr = phy_addr;
2638 }
2639 } 2788 }
2640 2789
2641 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg, 2790 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2642 data); 2791 data);
2643 hw->phy.ops.release_phy(hw);
2644 2792
2645out: 2793out:
2646 /* Revert to MDIO fast mode, if applicable */ 2794 /* Revert to MDIO fast mode, if applicable */
2647 if ((hw->phy.type == e1000_phy_82577) && in_slow_mode) 2795 if ((hw->phy.type == e1000_phy_82577) && in_slow_mode)
2648 ret_val = e1000_set_mdio_slow_mode_hv(hw, false); 2796 ret_val |= e1000_set_mdio_slow_mode_hv(hw, false);
2797
2798 if (!locked)
2799 hw->phy.ops.release_phy(hw);
2649 2800
2650 return ret_val; 2801 return ret_val;
2651} 2802}
2652 2803
2653/** 2804/**
2805 * e1000_write_phy_reg_hv - Write HV PHY register
2806 * @hw: pointer to the HW structure
2807 * @offset: register offset to write to
2808 * @data: data to write at register offset
2809 *
2810 * Acquires semaphore then writes the data to PHY register at the offset.
2811 * Release the acquired semaphores before exiting.
2812 **/
2813s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2814{
2815 return __e1000_write_phy_reg_hv(hw, offset, data, false);
2816}
2817
2818/**
2819 * e1000_write_phy_reg_hv_locked - Write HV PHY register
2820 * @hw: pointer to the HW structure
2821 * @offset: register offset to write to
2822 * @data: data to write at register offset
2823 *
2824 * Writes the data to PHY register at the offset. Assumes semaphore
2825 * already acquired.
2826 **/
2827s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
2828{
2829 return __e1000_write_phy_reg_hv(hw, offset, data, true);
2830}
2831
2832/**
2654 * e1000_get_phy_addr_for_hv_page - Get PHY adrress based on page 2833 * e1000_get_phy_addr_for_hv_page - Get PHY adrress based on page
2655 * @page: page to be accessed 2834 * @page: page to be accessed
2656 **/ 2835 **/
@@ -2671,10 +2850,9 @@ static u32 e1000_get_phy_addr_for_hv_page(u32 page)
2671 * @data: pointer to the data to be read or written 2850 * @data: pointer to the data to be read or written
2672 * @read: determines if operation is read or written 2851 * @read: determines if operation is read or written
2673 * 2852 *
2674 * Acquires semaphore, if necessary, then reads the PHY register at offset 2853 * Reads the PHY register at offset and stores the retreived information
2675 * and storing the retreived information in data. Release any acquired 2854 * in data. Assumes semaphore already acquired. Note that the procedure
2676 * semaphores before exiting. Note that the procedure to read these regs 2855 * to read these regs uses the address port and data port to read/write.
2677 * uses the address port and data port to read/write.
2678 **/ 2856 **/
2679static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset, 2857static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
2680 u16 *data, bool read) 2858 u16 *data, bool read)
@@ -2682,20 +2860,12 @@ static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
2682 s32 ret_val; 2860 s32 ret_val;
2683 u32 addr_reg = 0; 2861 u32 addr_reg = 0;
2684 u32 data_reg = 0; 2862 u32 data_reg = 0;
2685 u8 phy_acquired = 1;
2686 2863
2687 /* This takes care of the difference with desktop vs mobile phy */ 2864 /* This takes care of the difference with desktop vs mobile phy */
2688 addr_reg = (hw->phy.type == e1000_phy_82578) ? 2865 addr_reg = (hw->phy.type == e1000_phy_82578) ?
2689 I82578_ADDR_REG : I82577_ADDR_REG; 2866 I82578_ADDR_REG : I82577_ADDR_REG;
2690 data_reg = addr_reg + 1; 2867 data_reg = addr_reg + 1;
2691 2868
2692 ret_val = hw->phy.ops.acquire_phy(hw);
2693 if (ret_val) {
2694 hw_dbg(hw, "Could not acquire PHY\n");
2695 phy_acquired = 0;
2696 goto out;
2697 }
2698
2699 /* All operations in this function are phy address 2 */ 2869 /* All operations in this function are phy address 2 */
2700 hw->phy.addr = 2; 2870 hw->phy.addr = 2;
2701 2871
@@ -2718,8 +2888,6 @@ static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
2718 } 2888 }
2719 2889
2720out: 2890out:
2721 if (phy_acquired == 1)
2722 hw->phy.ops.release_phy(hw);
2723 return ret_val; 2891 return ret_val;
2724} 2892}
2725 2893
diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index 96f5b2a2d2c5..f7d9ac8324cb 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -223,24 +223,25 @@ struct ethoc_bd {
223 u32 addr; 223 u32 addr;
224}; 224};
225 225
226static u32 ethoc_read(struct ethoc *dev, loff_t offset) 226static inline u32 ethoc_read(struct ethoc *dev, loff_t offset)
227{ 227{
228 return ioread32(dev->iobase + offset); 228 return ioread32(dev->iobase + offset);
229} 229}
230 230
231static void ethoc_write(struct ethoc *dev, loff_t offset, u32 data) 231static inline void ethoc_write(struct ethoc *dev, loff_t offset, u32 data)
232{ 232{
233 iowrite32(data, dev->iobase + offset); 233 iowrite32(data, dev->iobase + offset);
234} 234}
235 235
236static void ethoc_read_bd(struct ethoc *dev, int index, struct ethoc_bd *bd) 236static inline void ethoc_read_bd(struct ethoc *dev, int index,
237 struct ethoc_bd *bd)
237{ 238{
238 loff_t offset = ETHOC_BD_BASE + (index * sizeof(struct ethoc_bd)); 239 loff_t offset = ETHOC_BD_BASE + (index * sizeof(struct ethoc_bd));
239 bd->stat = ethoc_read(dev, offset + 0); 240 bd->stat = ethoc_read(dev, offset + 0);
240 bd->addr = ethoc_read(dev, offset + 4); 241 bd->addr = ethoc_read(dev, offset + 4);
241} 242}
242 243
243static void ethoc_write_bd(struct ethoc *dev, int index, 244static inline void ethoc_write_bd(struct ethoc *dev, int index,
244 const struct ethoc_bd *bd) 245 const struct ethoc_bd *bd)
245{ 246{
246 loff_t offset = ETHOC_BD_BASE + (index * sizeof(struct ethoc_bd)); 247 loff_t offset = ETHOC_BD_BASE + (index * sizeof(struct ethoc_bd));
@@ -248,33 +249,33 @@ static void ethoc_write_bd(struct ethoc *dev, int index,
248 ethoc_write(dev, offset + 4, bd->addr); 249 ethoc_write(dev, offset + 4, bd->addr);
249} 250}
250 251
251static void ethoc_enable_irq(struct ethoc *dev, u32 mask) 252static inline void ethoc_enable_irq(struct ethoc *dev, u32 mask)
252{ 253{
253 u32 imask = ethoc_read(dev, INT_MASK); 254 u32 imask = ethoc_read(dev, INT_MASK);
254 imask |= mask; 255 imask |= mask;
255 ethoc_write(dev, INT_MASK, imask); 256 ethoc_write(dev, INT_MASK, imask);
256} 257}
257 258
258static void ethoc_disable_irq(struct ethoc *dev, u32 mask) 259static inline void ethoc_disable_irq(struct ethoc *dev, u32 mask)
259{ 260{
260 u32 imask = ethoc_read(dev, INT_MASK); 261 u32 imask = ethoc_read(dev, INT_MASK);
261 imask &= ~mask; 262 imask &= ~mask;
262 ethoc_write(dev, INT_MASK, imask); 263 ethoc_write(dev, INT_MASK, imask);
263} 264}
264 265
265static void ethoc_ack_irq(struct ethoc *dev, u32 mask) 266static inline void ethoc_ack_irq(struct ethoc *dev, u32 mask)
266{ 267{
267 ethoc_write(dev, INT_SOURCE, mask); 268 ethoc_write(dev, INT_SOURCE, mask);
268} 269}
269 270
270static void ethoc_enable_rx_and_tx(struct ethoc *dev) 271static inline void ethoc_enable_rx_and_tx(struct ethoc *dev)
271{ 272{
272 u32 mode = ethoc_read(dev, MODER); 273 u32 mode = ethoc_read(dev, MODER);
273 mode |= MODER_RXEN | MODER_TXEN; 274 mode |= MODER_RXEN | MODER_TXEN;
274 ethoc_write(dev, MODER, mode); 275 ethoc_write(dev, MODER, mode);
275} 276}
276 277
277static void ethoc_disable_rx_and_tx(struct ethoc *dev) 278static inline void ethoc_disable_rx_and_tx(struct ethoc *dev)
278{ 279{
279 u32 mode = ethoc_read(dev, MODER); 280 u32 mode = ethoc_read(dev, MODER);
280 mode &= ~(MODER_RXEN | MODER_TXEN); 281 mode &= ~(MODER_RXEN | MODER_TXEN);
@@ -508,7 +509,7 @@ static irqreturn_t ethoc_interrupt(int irq, void *dev_id)
508 return IRQ_NONE; 509 return IRQ_NONE;
509 } 510 }
510 511
511 ethoc_ack_irq(priv, INT_MASK_ALL); 512 ethoc_ack_irq(priv, pending);
512 513
513 if (pending & INT_MASK_BUSY) { 514 if (pending & INT_MASK_BUSY) {
514 dev_err(&dev->dev, "packet dropped\n"); 515 dev_err(&dev->dev, "packet dropped\n");
@@ -664,7 +665,8 @@ static int ethoc_open(struct net_device *dev)
664 return ret; 665 return ret;
665 666
666 /* calculate the number of TX/RX buffers, maximum 128 supported */ 667 /* calculate the number of TX/RX buffers, maximum 128 supported */
667 num_bd = min(128, (dev->mem_end - dev->mem_start + 1) / ETHOC_BUFSIZ); 668 num_bd = min_t(unsigned int,
669 128, (dev->mem_end - dev->mem_start + 1) / ETHOC_BUFSIZ);
668 priv->num_tx = max(min_tx, num_bd / 4); 670 priv->num_tx = max(min_tx, num_bd / 4);
669 priv->num_rx = num_bd - priv->num_tx; 671 priv->num_rx = num_bd - priv->num_tx;
670 ethoc_write(priv, TX_BD_NUM, priv->num_tx); 672 ethoc_write(priv, TX_BD_NUM, priv->num_tx);
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 29234380e6c6..16a1d58419d9 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -1654,7 +1654,7 @@ static const struct net_device_ops fec_netdev_ops = {
1654 * 1654 *
1655 * index is only used in legacy code 1655 * index is only used in legacy code
1656 */ 1656 */
1657int __init fec_enet_init(struct net_device *dev, int index) 1657static int fec_enet_init(struct net_device *dev, int index)
1658{ 1658{
1659 struct fec_enet_private *fep = netdev_priv(dev); 1659 struct fec_enet_private *fep = netdev_priv(dev);
1660 struct bufdesc *cbd_base; 1660 struct bufdesc *cbd_base;
diff --git a/drivers/net/fec_mpc52xx.c b/drivers/net/fec_mpc52xx.c
index c40113f58963..66dace6d324f 100644
--- a/drivers/net/fec_mpc52xx.c
+++ b/drivers/net/fec_mpc52xx.c
@@ -759,12 +759,6 @@ static void mpc52xx_fec_reset(struct net_device *dev)
759 759
760 mpc52xx_fec_hw_init(dev); 760 mpc52xx_fec_hw_init(dev);
761 761
762 if (priv->phydev) {
763 phy_stop(priv->phydev);
764 phy_write(priv->phydev, MII_BMCR, BMCR_RESET);
765 phy_start(priv->phydev);
766 }
767
768 bcom_fec_rx_reset(priv->rx_dmatsk); 762 bcom_fec_rx_reset(priv->rx_dmatsk);
769 bcom_fec_tx_reset(priv->tx_dmatsk); 763 bcom_fec_tx_reset(priv->tx_dmatsk);
770 764
diff --git a/drivers/net/fec_mpc52xx_phy.c b/drivers/net/fec_mpc52xx_phy.c
index 31e6d62b785d..ee0f3c6d3f88 100644
--- a/drivers/net/fec_mpc52xx_phy.c
+++ b/drivers/net/fec_mpc52xx_phy.c
@@ -155,6 +155,7 @@ static struct of_device_id mpc52xx_fec_mdio_match[] = {
155 { .compatible = "mpc5200b-fec-phy", }, 155 { .compatible = "mpc5200b-fec-phy", },
156 {} 156 {}
157}; 157};
158MODULE_DEVICE_TABLE(of, mpc52xx_fec_mdio_match);
158 159
159struct of_platform_driver mpc52xx_fec_mdio_driver = { 160struct of_platform_driver mpc52xx_fec_mdio_driver = {
160 .name = "mpc5200b-fec-phy", 161 .name = "mpc5200b-fec-phy",
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index e1da4666f204..3116601dbfea 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -5821,10 +5821,7 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
5821 dev->dev_addr); 5821 dev->dev_addr);
5822 dev_printk(KERN_ERR, &pci_dev->dev, 5822 dev_printk(KERN_ERR, &pci_dev->dev,
5823 "Please complain to your hardware vendor. Switching to a random MAC.\n"); 5823 "Please complain to your hardware vendor. Switching to a random MAC.\n");
5824 dev->dev_addr[0] = 0x00; 5824 random_ether_addr(dev->dev_addr);
5825 dev->dev_addr[1] = 0x00;
5826 dev->dev_addr[2] = 0x6c;
5827 get_random_bytes(&dev->dev_addr[3], 3);
5828 } 5825 }
5829 5826
5830 dprintk(KERN_DEBUG "%s: MAC Address %pM\n", 5827 dprintk(KERN_DEBUG "%s: MAC Address %pM\n",
diff --git a/drivers/net/fs_enet/fs_enet-main.c b/drivers/net/fs_enet/fs_enet-main.c
index 2bc2d2b20644..ec2f5034457f 100644
--- a/drivers/net/fs_enet/fs_enet-main.c
+++ b/drivers/net/fs_enet/fs_enet-main.c
@@ -1110,6 +1110,7 @@ static struct of_device_id fs_enet_match[] = {
1110#endif 1110#endif
1111 {} 1111 {}
1112}; 1112};
1113MODULE_DEVICE_TABLE(of, fs_enet_match);
1113 1114
1114static struct of_platform_driver fs_enet_driver = { 1115static struct of_platform_driver fs_enet_driver = {
1115 .name = "fs_enet", 1116 .name = "fs_enet",
diff --git a/drivers/net/fs_enet/mii-bitbang.c b/drivers/net/fs_enet/mii-bitbang.c
index 93b481b0e3c7..24ff9f43a62b 100644
--- a/drivers/net/fs_enet/mii-bitbang.c
+++ b/drivers/net/fs_enet/mii-bitbang.c
@@ -221,6 +221,7 @@ static struct of_device_id fs_enet_mdio_bb_match[] = {
221 }, 221 },
222 {}, 222 {},
223}; 223};
224MODULE_DEVICE_TABLE(of, fs_enet_mdio_bb_match);
224 225
225static struct of_platform_driver fs_enet_bb_mdio_driver = { 226static struct of_platform_driver fs_enet_bb_mdio_driver = {
226 .name = "fsl-bb-mdio", 227 .name = "fsl-bb-mdio",
diff --git a/drivers/net/fs_enet/mii-fec.c b/drivers/net/fs_enet/mii-fec.c
index a2d69c1cd07e..96eba4280c5c 100644
--- a/drivers/net/fs_enet/mii-fec.c
+++ b/drivers/net/fs_enet/mii-fec.c
@@ -219,6 +219,7 @@ static struct of_device_id fs_enet_mdio_fec_match[] = {
219#endif 219#endif
220 {}, 220 {},
221}; 221};
222MODULE_DEVICE_TABLE(of, fs_enet_mdio_fec_match);
222 223
223static struct of_platform_driver fs_enet_fec_mdio_driver = { 224static struct of_platform_driver fs_enet_fec_mdio_driver = {
224 .name = "fsl-fec-mdio", 225 .name = "fsl-fec-mdio",
diff --git a/drivers/net/fsl_pq_mdio.c b/drivers/net/fsl_pq_mdio.c
index d167090248e2..efbf67689eca 100644
--- a/drivers/net/fsl_pq_mdio.c
+++ b/drivers/net/fsl_pq_mdio.c
@@ -407,6 +407,7 @@ static struct of_device_id fsl_pq_mdio_match[] = {
407 }, 407 },
408 {}, 408 {},
409}; 409};
410MODULE_DEVICE_TABLE(of, fsl_pq_mdio_match);
410 411
411static struct of_platform_driver fsl_pq_mdio_driver = { 412static struct of_platform_driver fsl_pq_mdio_driver = {
412 .name = "fsl-pq_mdio", 413 .name = "fsl-pq_mdio",
@@ -426,3 +427,4 @@ void fsl_pq_mdio_exit(void)
426 of_unregister_platform_driver(&fsl_pq_mdio_driver); 427 of_unregister_platform_driver(&fsl_pq_mdio_driver);
427} 428}
428module_exit(fsl_pq_mdio_exit); 429module_exit(fsl_pq_mdio_exit);
430MODULE_LICENSE("GPL");
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 1e5289ffef6f..5bf31f1509c9 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -2325,9 +2325,6 @@ static irqreturn_t gfar_error(int irq, void *dev_id)
2325 return IRQ_HANDLED; 2325 return IRQ_HANDLED;
2326} 2326}
2327 2327
2328/* work with hotplug and coldplug */
2329MODULE_ALIAS("platform:fsl-gianfar");
2330
2331static struct of_device_id gfar_match[] = 2328static struct of_device_id gfar_match[] =
2332{ 2329{
2333 { 2330 {
@@ -2336,6 +2333,7 @@ static struct of_device_id gfar_match[] =
2336 }, 2333 },
2337 {}, 2334 {},
2338}; 2335};
2336MODULE_DEVICE_TABLE(of, gfar_match);
2339 2337
2340/* Structure for a device driver */ 2338/* Structure for a device driver */
2341static struct of_platform_driver gfar_driver = { 2339static struct of_platform_driver gfar_driver = {
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index 89c82c5e63e4..3fae87559791 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -24,6 +24,7 @@
24 * 24 *
25 */ 25 */
26 26
27#include <linux/module.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28#include <linux/string.h> 29#include <linux/string.h>
29#include <linux/errno.h> 30#include <linux/errno.h>
@@ -443,7 +444,7 @@ static u32 __emac_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_s
443 ret |= EMAC_MR1_TFS_2K; 444 ret |= EMAC_MR1_TFS_2K;
444 break; 445 break;
445 default: 446 default:
446 printk(KERN_WARNING "%s: Unknown Rx FIFO size %d\n", 447 printk(KERN_WARNING "%s: Unknown Tx FIFO size %d\n",
447 dev->ndev->name, tx_size); 448 dev->ndev->name, tx_size);
448 } 449 }
449 450
@@ -470,6 +471,9 @@ static u32 __emac4_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_
470 DBG2(dev, "__emac4_calc_base_mr1" NL); 471 DBG2(dev, "__emac4_calc_base_mr1" NL);
471 472
472 switch(tx_size) { 473 switch(tx_size) {
474 case 16384:
475 ret |= EMAC4_MR1_TFS_16K;
476 break;
473 case 4096: 477 case 4096:
474 ret |= EMAC4_MR1_TFS_4K; 478 ret |= EMAC4_MR1_TFS_4K;
475 break; 479 break;
@@ -477,7 +481,7 @@ static u32 __emac4_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_
477 ret |= EMAC4_MR1_TFS_2K; 481 ret |= EMAC4_MR1_TFS_2K;
478 break; 482 break;
479 default: 483 default:
480 printk(KERN_WARNING "%s: Unknown Rx FIFO size %d\n", 484 printk(KERN_WARNING "%s: Unknown Tx FIFO size %d\n",
481 dev->ndev->name, tx_size); 485 dev->ndev->name, tx_size);
482 } 486 }
483 487
@@ -2985,6 +2989,7 @@ static struct of_device_id emac_match[] =
2985 }, 2989 },
2986 {}, 2990 {},
2987}; 2991};
2992MODULE_DEVICE_TABLE(of, emac_match);
2988 2993
2989static struct of_platform_driver emac_driver = { 2994static struct of_platform_driver emac_driver = {
2990 .name = "emac", 2995 .name = "emac",
diff --git a/drivers/net/ibm_newemac/emac.h b/drivers/net/ibm_newemac/emac.h
index 0afc2cf5c52b..8a61b597a169 100644
--- a/drivers/net/ibm_newemac/emac.h
+++ b/drivers/net/ibm_newemac/emac.h
@@ -153,6 +153,7 @@ struct emac_regs {
153#define EMAC4_MR1_RFS_16K 0x00280000 153#define EMAC4_MR1_RFS_16K 0x00280000
154#define EMAC4_MR1_TFS_2K 0x00020000 154#define EMAC4_MR1_TFS_2K 0x00020000
155#define EMAC4_MR1_TFS_4K 0x00030000 155#define EMAC4_MR1_TFS_4K 0x00030000
156#define EMAC4_MR1_TFS_16K 0x00050000
156#define EMAC4_MR1_TR 0x00008000 157#define EMAC4_MR1_TR 0x00008000
157#define EMAC4_MR1_MWSW_001 0x00001000 158#define EMAC4_MR1_MWSW_001 0x00001000
158#define EMAC4_MR1_JPSM 0x00000800 159#define EMAC4_MR1_JPSM 0x00000800
@@ -262,8 +263,8 @@ struct emac_regs {
262 263
263 264
264/* EMACx_TRTR */ 265/* EMACx_TRTR */
265#define EMAC_TRTR_SHIFT_EMAC4 27 266#define EMAC_TRTR_SHIFT_EMAC4 24
266#define EMAC_TRTR_SHIFT 24 267#define EMAC_TRTR_SHIFT 27
267 268
268/* EMAC specific TX descriptor control fields (write access) */ 269/* EMAC specific TX descriptor control fields (write access) */
269#define EMAC_TX_CTRL_GFCS 0x0200 270#define EMAC_TX_CTRL_GFCS 0x0200
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index 801f088c134f..030913f8bd26 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -98,12 +98,13 @@ static void ri_tasklet(unsigned long dev)
98 stats->tx_packets++; 98 stats->tx_packets++;
99 stats->tx_bytes +=skb->len; 99 stats->tx_bytes +=skb->len;
100 100
101 skb->dev = __dev_get_by_index(&init_net, skb->iif); 101 skb->dev = dev_get_by_index(&init_net, skb->iif);
102 if (!skb->dev) { 102 if (!skb->dev) {
103 dev_kfree_skb(skb); 103 dev_kfree_skb(skb);
104 stats->tx_dropped++; 104 stats->tx_dropped++;
105 break; 105 break;
106 } 106 }
107 dev_put(skb->dev);
107 skb->iif = _dev->ifindex; 108 skb->iif = _dev->ifindex;
108 109
109 if (from & AT_EGRESS) { 110 if (from & AT_EGRESS) {
diff --git a/drivers/net/igb/igb_ethtool.c b/drivers/net/igb/igb_ethtool.c
index deaea8fa1032..b243ed3b0c36 100644
--- a/drivers/net/igb/igb_ethtool.c
+++ b/drivers/net/igb/igb_ethtool.c
@@ -732,7 +732,7 @@ static int igb_set_ringparam(struct net_device *netdev,
732{ 732{
733 struct igb_adapter *adapter = netdev_priv(netdev); 733 struct igb_adapter *adapter = netdev_priv(netdev);
734 struct igb_ring *temp_ring; 734 struct igb_ring *temp_ring;
735 int i, err; 735 int i, err = 0;
736 u32 new_rx_count, new_tx_count; 736 u32 new_rx_count, new_tx_count;
737 737
738 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) 738 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
@@ -752,18 +752,30 @@ static int igb_set_ringparam(struct net_device *netdev,
752 return 0; 752 return 0;
753 } 753 }
754 754
755 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
756 msleep(1);
757
758 if (!netif_running(adapter->netdev)) {
759 for (i = 0; i < adapter->num_tx_queues; i++)
760 adapter->tx_ring[i].count = new_tx_count;
761 for (i = 0; i < adapter->num_rx_queues; i++)
762 adapter->rx_ring[i].count = new_rx_count;
763 adapter->tx_ring_count = new_tx_count;
764 adapter->rx_ring_count = new_rx_count;
765 goto clear_reset;
766 }
767
755 if (adapter->num_tx_queues > adapter->num_rx_queues) 768 if (adapter->num_tx_queues > adapter->num_rx_queues)
756 temp_ring = vmalloc(adapter->num_tx_queues * sizeof(struct igb_ring)); 769 temp_ring = vmalloc(adapter->num_tx_queues * sizeof(struct igb_ring));
757 else 770 else
758 temp_ring = vmalloc(adapter->num_rx_queues * sizeof(struct igb_ring)); 771 temp_ring = vmalloc(adapter->num_rx_queues * sizeof(struct igb_ring));
759 if (!temp_ring)
760 return -ENOMEM;
761 772
762 while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) 773 if (!temp_ring) {
763 msleep(1); 774 err = -ENOMEM;
775 goto clear_reset;
776 }
764 777
765 if (netif_running(adapter->netdev)) 778 igb_down(adapter);
766 igb_down(adapter);
767 779
768 /* 780 /*
769 * We can't just free everything and then setup again, 781 * We can't just free everything and then setup again,
@@ -820,14 +832,11 @@ static int igb_set_ringparam(struct net_device *netdev,
820 832
821 adapter->rx_ring_count = new_rx_count; 833 adapter->rx_ring_count = new_rx_count;
822 } 834 }
823
824 err = 0;
825err_setup: 835err_setup:
826 if (netif_running(adapter->netdev)) 836 igb_up(adapter);
827 igb_up(adapter);
828
829 clear_bit(__IGB_RESETTING, &adapter->state);
830 vfree(temp_ring); 837 vfree(temp_ring);
838clear_reset:
839 clear_bit(__IGB_RESETTING, &adapter->state);
831 return err; 840 return err;
832} 841}
833 842
diff --git a/drivers/net/igbvf/ethtool.c b/drivers/net/igbvf/ethtool.c
index ee17a097d1ca..c68265bd0d1a 100644
--- a/drivers/net/igbvf/ethtool.c
+++ b/drivers/net/igbvf/ethtool.c
@@ -279,7 +279,7 @@ static int igbvf_set_ringparam(struct net_device *netdev,
279{ 279{
280 struct igbvf_adapter *adapter = netdev_priv(netdev); 280 struct igbvf_adapter *adapter = netdev_priv(netdev);
281 struct igbvf_ring *temp_ring; 281 struct igbvf_ring *temp_ring;
282 int err; 282 int err = 0;
283 u32 new_rx_count, new_tx_count; 283 u32 new_rx_count, new_tx_count;
284 284
285 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) 285 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
@@ -299,15 +299,22 @@ static int igbvf_set_ringparam(struct net_device *netdev,
299 return 0; 299 return 0;
300 } 300 }
301 301
302 temp_ring = vmalloc(sizeof(struct igbvf_ring));
303 if (!temp_ring)
304 return -ENOMEM;
305
306 while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state)) 302 while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state))
307 msleep(1); 303 msleep(1);
308 304
309 if (netif_running(adapter->netdev)) 305 if (!netif_running(adapter->netdev)) {
310 igbvf_down(adapter); 306 adapter->tx_ring->count = new_tx_count;
307 adapter->rx_ring->count = new_rx_count;
308 goto clear_reset;
309 }
310
311 temp_ring = vmalloc(sizeof(struct igbvf_ring));
312 if (!temp_ring) {
313 err = -ENOMEM;
314 goto clear_reset;
315 }
316
317 igbvf_down(adapter);
311 318
312 /* 319 /*
313 * We can't just free everything and then setup again, 320 * We can't just free everything and then setup again,
@@ -339,14 +346,11 @@ static int igbvf_set_ringparam(struct net_device *netdev,
339 346
340 memcpy(adapter->rx_ring, temp_ring,sizeof(struct igbvf_ring)); 347 memcpy(adapter->rx_ring, temp_ring,sizeof(struct igbvf_ring));
341 } 348 }
342
343 err = 0;
344err_setup: 349err_setup:
345 if (netif_running(adapter->netdev)) 350 igbvf_up(adapter);
346 igbvf_up(adapter);
347
348 clear_bit(__IGBVF_RESETTING, &adapter->state);
349 vfree(temp_ring); 351 vfree(temp_ring);
352clear_reset:
353 clear_bit(__IGBVF_RESETTING, &adapter->state);
350 return err; 354 return err;
351} 355}
352 356
diff --git a/drivers/net/irda/sa1100_ir.c b/drivers/net/irda/sa1100_ir.c
index 38bf7cf2256d..c412e8026173 100644
--- a/drivers/net/irda/sa1100_ir.c
+++ b/drivers/net/irda/sa1100_ir.c
@@ -232,8 +232,11 @@ static int sa1100_irda_startup(struct sa1100_irda *si)
232 /* 232 /*
233 * Ensure that the ports for this device are setup correctly. 233 * Ensure that the ports for this device are setup correctly.
234 */ 234 */
235 if (si->pdata->startup) 235 if (si->pdata->startup) {
236 si->pdata->startup(si->dev); 236 ret = si->pdata->startup(si->dev);
237 if (ret)
238 return ret;
239 }
237 240
238 /* 241 /*
239 * Configure PPC for IRDA - we want to drive TXD2 low. 242 * Configure PPC for IRDA - we want to drive TXD2 low.
diff --git a/drivers/net/ixgbe/ixgbe_ethtool.c b/drivers/net/ixgbe/ixgbe_ethtool.c
index fa314cb005a4..856c18c207f3 100644
--- a/drivers/net/ixgbe/ixgbe_ethtool.c
+++ b/drivers/net/ixgbe/ixgbe_ethtool.c
@@ -798,7 +798,7 @@ static int ixgbe_set_ringparam(struct net_device *netdev,
798{ 798{
799 struct ixgbe_adapter *adapter = netdev_priv(netdev); 799 struct ixgbe_adapter *adapter = netdev_priv(netdev);
800 struct ixgbe_ring *temp_tx_ring, *temp_rx_ring; 800 struct ixgbe_ring *temp_tx_ring, *temp_rx_ring;
801 int i, err; 801 int i, err = 0;
802 u32 new_rx_count, new_tx_count; 802 u32 new_rx_count, new_tx_count;
803 bool need_update = false; 803 bool need_update = false;
804 804
@@ -822,6 +822,16 @@ static int ixgbe_set_ringparam(struct net_device *netdev,
822 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) 822 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
823 msleep(1); 823 msleep(1);
824 824
825 if (!netif_running(adapter->netdev)) {
826 for (i = 0; i < adapter->num_tx_queues; i++)
827 adapter->tx_ring[i].count = new_tx_count;
828 for (i = 0; i < adapter->num_rx_queues; i++)
829 adapter->rx_ring[i].count = new_rx_count;
830 adapter->tx_ring_count = new_tx_count;
831 adapter->rx_ring_count = new_rx_count;
832 goto err_setup;
833 }
834
825 temp_tx_ring = kcalloc(adapter->num_tx_queues, 835 temp_tx_ring = kcalloc(adapter->num_tx_queues,
826 sizeof(struct ixgbe_ring), GFP_KERNEL); 836 sizeof(struct ixgbe_ring), GFP_KERNEL);
827 if (!temp_tx_ring) { 837 if (!temp_tx_ring) {
@@ -879,8 +889,7 @@ static int ixgbe_set_ringparam(struct net_device *netdev,
879 889
880 /* if rings need to be updated, here's the place to do it in one shot */ 890 /* if rings need to be updated, here's the place to do it in one shot */
881 if (need_update) { 891 if (need_update) {
882 if (netif_running(netdev)) 892 ixgbe_down(adapter);
883 ixgbe_down(adapter);
884 893
885 /* tx */ 894 /* tx */
886 if (new_tx_count != adapter->tx_ring_count) { 895 if (new_tx_count != adapter->tx_ring_count) {
@@ -897,13 +906,8 @@ static int ixgbe_set_ringparam(struct net_device *netdev,
897 temp_rx_ring = NULL; 906 temp_rx_ring = NULL;
898 adapter->rx_ring_count = new_rx_count; 907 adapter->rx_ring_count = new_rx_count;
899 } 908 }
900 }
901
902 /* success! */
903 err = 0;
904 if (netif_running(netdev))
905 ixgbe_up(adapter); 909 ixgbe_up(adapter);
906 910 }
907err_setup: 911err_setup:
908 clear_bit(__IXGBE_RESETTING, &adapter->state); 912 clear_bit(__IXGBE_RESETTING, &adapter->state);
909 return err; 913 return err;
diff --git a/drivers/net/ixgbe/ixgbe_main.c b/drivers/net/ixgbe/ixgbe_main.c
index cbb143ca1eb8..a456578b8578 100644
--- a/drivers/net/ixgbe/ixgbe_main.c
+++ b/drivers/net/ixgbe/ixgbe_main.c
@@ -44,6 +44,7 @@
44 44
45#include "ixgbe.h" 45#include "ixgbe.h"
46#include "ixgbe_common.h" 46#include "ixgbe_common.h"
47#include "ixgbe_dcb_82599.h"
47 48
48char ixgbe_driver_name[] = "ixgbe"; 49char ixgbe_driver_name[] = "ixgbe";
49static const char ixgbe_driver_string[] = 50static const char ixgbe_driver_string[] =
@@ -226,6 +227,56 @@ static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
226 /* tx_buffer_info must be completely set up in the transmit path */ 227 /* tx_buffer_info must be completely set up in the transmit path */
227} 228}
228 229
230/**
231 * ixgbe_tx_is_paused - check if the tx ring is paused
232 * @adapter: the ixgbe adapter
233 * @tx_ring: the corresponding tx_ring
234 *
235 * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the
236 * corresponding TC of this tx_ring when checking TFCS.
237 *
238 * Returns : true if paused
239 */
240static inline bool ixgbe_tx_is_paused(struct ixgbe_adapter *adapter,
241 struct ixgbe_ring *tx_ring)
242{
243 u32 txoff = IXGBE_TFCS_TXOFF;
244
245#ifdef CONFIG_IXGBE_DCB
246 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
247 int tc;
248 int reg_idx = tx_ring->reg_idx;
249 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
250
251 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
252 tc = reg_idx >> 2;
253 txoff = IXGBE_TFCS_TXOFF0;
254 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
255 tc = 0;
256 txoff = IXGBE_TFCS_TXOFF;
257 if (dcb_i == 8) {
258 /* TC0, TC1 */
259 tc = reg_idx >> 5;
260 if (tc == 2) /* TC2, TC3 */
261 tc += (reg_idx - 64) >> 4;
262 else if (tc == 3) /* TC4, TC5, TC6, TC7 */
263 tc += 1 + ((reg_idx - 96) >> 3);
264 } else if (dcb_i == 4) {
265 /* TC0, TC1 */
266 tc = reg_idx >> 6;
267 if (tc == 1) {
268 tc += (reg_idx - 64) >> 5;
269 if (tc == 2) /* TC2, TC3 */
270 tc += (reg_idx - 96) >> 4;
271 }
272 }
273 }
274 txoff <<= tc;
275 }
276#endif
277 return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff;
278}
279
229static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, 280static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
230 struct ixgbe_ring *tx_ring, 281 struct ixgbe_ring *tx_ring,
231 unsigned int eop) 282 unsigned int eop)
@@ -237,7 +288,7 @@ static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
237 adapter->detect_tx_hung = false; 288 adapter->detect_tx_hung = false;
238 if (tx_ring->tx_buffer_info[eop].time_stamp && 289 if (tx_ring->tx_buffer_info[eop].time_stamp &&
239 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && 290 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
240 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) { 291 !ixgbe_tx_is_paused(adapter, tx_ring)) {
241 /* detected Tx unit hang */ 292 /* detected Tx unit hang */
242 union ixgbe_adv_tx_desc *tx_desc; 293 union ixgbe_adv_tx_desc *tx_desc;
243 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); 294 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
@@ -412,19 +463,23 @@ static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
412 u32 txctrl; 463 u32 txctrl;
413 int cpu = get_cpu(); 464 int cpu = get_cpu();
414 int q = tx_ring - adapter->tx_ring; 465 int q = tx_ring - adapter->tx_ring;
466 struct ixgbe_hw *hw = &adapter->hw;
415 467
416 if (tx_ring->cpu != cpu) { 468 if (tx_ring->cpu != cpu) {
417 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
418 if (adapter->hw.mac.type == ixgbe_mac_82598EB) { 469 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
470 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q));
419 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; 471 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
420 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); 472 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
473 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
474 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl);
421 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { 475 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
476 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q));
422 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; 477 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
423 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << 478 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
424 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); 479 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
480 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
481 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl);
425 } 482 }
426 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
427 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
428 tx_ring->cpu = cpu; 483 tx_ring->cpu = cpu;
429 } 484 }
430 put_cpu(); 485 put_cpu();
@@ -1913,11 +1968,25 @@ static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1913 break; 1968 break;
1914 } 1969 }
1915 } 1970 }
1971
1916 if (hw->mac.type == ixgbe_mac_82599EB) { 1972 if (hw->mac.type == ixgbe_mac_82599EB) {
1973 u32 rttdcs;
1974
1975 /* disable the arbiter while setting MTQC */
1976 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
1977 rttdcs |= IXGBE_RTTDCS_ARBDIS;
1978 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
1979
1917 /* We enable 8 traffic classes, DCB only */ 1980 /* We enable 8 traffic classes, DCB only */
1918 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) 1981 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1919 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA | 1982 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1920 IXGBE_MTQC_8TC_8TQ)); 1983 IXGBE_MTQC_8TC_8TQ));
1984 else
1985 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
1986
1987 /* re-eable the arbiter */
1988 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
1989 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
1921 } 1990 }
1922} 1991}
1923 1992
@@ -2471,7 +2540,10 @@ static void ixgbe_configure(struct ixgbe_adapter *adapter)
2471 ixgbe_restore_vlan(adapter); 2540 ixgbe_restore_vlan(adapter);
2472#ifdef CONFIG_IXGBE_DCB 2541#ifdef CONFIG_IXGBE_DCB
2473 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { 2542 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2474 netif_set_gso_max_size(netdev, 32768); 2543 if (hw->mac.type == ixgbe_mac_82598EB)
2544 netif_set_gso_max_size(netdev, 32768);
2545 else
2546 netif_set_gso_max_size(netdev, 65536);
2475 ixgbe_configure_dcb(adapter); 2547 ixgbe_configure_dcb(adapter);
2476 } else { 2548 } else {
2477 netif_set_gso_max_size(netdev, 65536); 2549 netif_set_gso_max_size(netdev, 65536);
@@ -5922,6 +5994,7 @@ static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
5922 } else { 5994 } else {
5923 pci_set_master(pdev); 5995 pci_set_master(pdev);
5924 pci_restore_state(pdev); 5996 pci_restore_state(pdev);
5997 pci_save_state(pdev);
5925 5998
5926 pci_wake_from_d3(pdev, false); 5999 pci_wake_from_d3(pdev, false);
5927 6000
diff --git a/drivers/net/ixp2000/enp2611.c b/drivers/net/ixp2000/enp2611.c
index b02a981c87a8..34a6cfd17930 100644
--- a/drivers/net/ixp2000/enp2611.c
+++ b/drivers/net/ixp2000/enp2611.c
@@ -119,24 +119,9 @@ static struct ixp2400_msf_parameters enp2611_msf_parameters =
119 } 119 }
120}; 120};
121 121
122struct enp2611_ixpdev_priv
123{
124 struct ixpdev_priv ixpdev_priv;
125 struct net_device_stats stats;
126};
127
128static struct net_device *nds[3]; 122static struct net_device *nds[3];
129static struct timer_list link_check_timer; 123static struct timer_list link_check_timer;
130 124
131static struct net_device_stats *enp2611_get_stats(struct net_device *dev)
132{
133 struct enp2611_ixpdev_priv *ip = netdev_priv(dev);
134
135 pm3386_get_stats(ip->ixpdev_priv.channel, &(ip->stats));
136
137 return &(ip->stats);
138}
139
140/* @@@ Poll the SFP moddef0 line too. */ 125/* @@@ Poll the SFP moddef0 line too. */
141/* @@@ Try to use the pm3386 DOOL interrupt as well. */ 126/* @@@ Try to use the pm3386 DOOL interrupt as well. */
142static void enp2611_check_link_status(unsigned long __dummy) 127static void enp2611_check_link_status(unsigned long __dummy)
@@ -203,14 +188,13 @@ static int __init enp2611_init_module(void)
203 188
204 ports = pm3386_port_count(); 189 ports = pm3386_port_count();
205 for (i = 0; i < ports; i++) { 190 for (i = 0; i < ports; i++) {
206 nds[i] = ixpdev_alloc(i, sizeof(struct enp2611_ixpdev_priv)); 191 nds[i] = ixpdev_alloc(i, sizeof(struct ixpdev_priv));
207 if (nds[i] == NULL) { 192 if (nds[i] == NULL) {
208 while (--i >= 0) 193 while (--i >= 0)
209 free_netdev(nds[i]); 194 free_netdev(nds[i]);
210 return -ENOMEM; 195 return -ENOMEM;
211 } 196 }
212 197
213 nds[i]->get_stats = enp2611_get_stats;
214 pm3386_init_port(i); 198 pm3386_init_port(i);
215 pm3386_get_mac(i, nds[i]->dev_addr); 199 pm3386_get_mac(i, nds[i]->dev_addr);
216 } 200 }
diff --git a/drivers/net/ixp2000/ixpdev.c b/drivers/net/ixp2000/ixpdev.c
index 127243461a51..9aee0cc922c9 100644
--- a/drivers/net/ixp2000/ixpdev.c
+++ b/drivers/net/ixp2000/ixpdev.c
@@ -21,6 +21,7 @@
21#include "ixp2400_tx.ucode" 21#include "ixp2400_tx.ucode"
22#include "ixpdev_priv.h" 22#include "ixpdev_priv.h"
23#include "ixpdev.h" 23#include "ixpdev.h"
24#include "pm3386.h"
24 25
25#define DRV_MODULE_VERSION "0.2" 26#define DRV_MODULE_VERSION "0.2"
26 27
@@ -271,6 +272,15 @@ static int ixpdev_close(struct net_device *dev)
271 return 0; 272 return 0;
272} 273}
273 274
275static struct net_device_stats *ixpdev_get_stats(struct net_device *dev)
276{
277 struct ixpdev_priv *ip = netdev_priv(dev);
278
279 pm3386_get_stats(ip->channel, &(dev->stats));
280
281 return &(dev->stats);
282}
283
274static const struct net_device_ops ixpdev_netdev_ops = { 284static const struct net_device_ops ixpdev_netdev_ops = {
275 .ndo_open = ixpdev_open, 285 .ndo_open = ixpdev_open,
276 .ndo_stop = ixpdev_close, 286 .ndo_stop = ixpdev_close,
@@ -278,6 +288,7 @@ static const struct net_device_ops ixpdev_netdev_ops = {
278 .ndo_change_mtu = eth_change_mtu, 288 .ndo_change_mtu = eth_change_mtu,
279 .ndo_validate_addr = eth_validate_addr, 289 .ndo_validate_addr = eth_validate_addr,
280 .ndo_set_mac_address = eth_mac_addr, 290 .ndo_set_mac_address = eth_mac_addr,
291 .ndo_get_stats = ixpdev_get_stats,
281#ifdef CONFIG_NET_POLL_CONTROLLER 292#ifdef CONFIG_NET_POLL_CONTROLLER
282 .ndo_poll_controller = ixpdev_poll_controller, 293 .ndo_poll_controller = ixpdev_poll_controller,
283#endif 294#endif
diff --git a/drivers/net/ks8851.c b/drivers/net/ks8851.c
index 237835864357..a23f739d222f 100644
--- a/drivers/net/ks8851.c
+++ b/drivers/net/ks8851.c
@@ -171,6 +171,36 @@ static void ks8851_wrreg16(struct ks8851_net *ks, unsigned reg, unsigned val)
171} 171}
172 172
173/** 173/**
174 * ks8851_wrreg8 - write 8bit register value to chip
175 * @ks: The chip state
176 * @reg: The register address
177 * @val: The value to write
178 *
179 * Issue a write to put the value @val into the register specified in @reg.
180 */
181static void ks8851_wrreg8(struct ks8851_net *ks, unsigned reg, unsigned val)
182{
183 struct spi_transfer *xfer = &ks->spi_xfer1;
184 struct spi_message *msg = &ks->spi_msg1;
185 __le16 txb[2];
186 int ret;
187 int bit;
188
189 bit = 1 << (reg & 3);
190
191 txb[0] = cpu_to_le16(MK_OP(bit, reg) | KS_SPIOP_WR);
192 txb[1] = val;
193
194 xfer->tx_buf = txb;
195 xfer->rx_buf = NULL;
196 xfer->len = 3;
197
198 ret = spi_sync(ks->spidev, msg);
199 if (ret < 0)
200 ks_err(ks, "spi_sync() failed\n");
201}
202
203/**
174 * ks8851_rx_1msg - select whether to use one or two messages for spi read 204 * ks8851_rx_1msg - select whether to use one or two messages for spi read
175 * @ks: The device structure 205 * @ks: The device structure
176 * 206 *
@@ -322,13 +352,12 @@ static void ks8851_soft_reset(struct ks8851_net *ks, unsigned op)
322static int ks8851_write_mac_addr(struct net_device *dev) 352static int ks8851_write_mac_addr(struct net_device *dev)
323{ 353{
324 struct ks8851_net *ks = netdev_priv(dev); 354 struct ks8851_net *ks = netdev_priv(dev);
325 u16 *mcp = (u16 *)dev->dev_addr; 355 int i;
326 356
327 mutex_lock(&ks->lock); 357 mutex_lock(&ks->lock);
328 358
329 ks8851_wrreg16(ks, KS_MARL, mcp[0]); 359 for (i = 0; i < ETH_ALEN; i++)
330 ks8851_wrreg16(ks, KS_MARM, mcp[1]); 360 ks8851_wrreg8(ks, KS_MAR(i), dev->dev_addr[i]);
331 ks8851_wrreg16(ks, KS_MARH, mcp[2]);
332 361
333 mutex_unlock(&ks->lock); 362 mutex_unlock(&ks->lock);
334 363
@@ -951,7 +980,7 @@ static void ks8851_set_rx_mode(struct net_device *dev)
951 mcptr = mcptr->next; 980 mcptr = mcptr->next;
952 } 981 }
953 982
954 rxctrl.rxcr1 = RXCR1_RXME | RXCR1_RXAE | RXCR1_RXPAFMA; 983 rxctrl.rxcr1 = RXCR1_RXME | RXCR1_RXPAFMA;
955 } else { 984 } else {
956 /* just accept broadcast / unicast */ 985 /* just accept broadcast / unicast */
957 rxctrl.rxcr1 = RXCR1_RXPAFMA; 986 rxctrl.rxcr1 = RXCR1_RXPAFMA;
@@ -1239,6 +1268,9 @@ static int __devinit ks8851_probe(struct spi_device *spi)
1239 ndev->netdev_ops = &ks8851_netdev_ops; 1268 ndev->netdev_ops = &ks8851_netdev_ops;
1240 ndev->irq = spi->irq; 1269 ndev->irq = spi->irq;
1241 1270
1271 /* issue a global soft reset to reset the device. */
1272 ks8851_soft_reset(ks, GRR_GSR);
1273
1242 /* simple check for a valid chip being connected to the bus */ 1274 /* simple check for a valid chip being connected to the bus */
1243 1275
1244 if ((ks8851_rdreg16(ks, KS_CIDER) & ~CIDER_REV_MASK) != CIDER_ID) { 1276 if ((ks8851_rdreg16(ks, KS_CIDER) & ~CIDER_REV_MASK) != CIDER_ID) {
diff --git a/drivers/net/ks8851.h b/drivers/net/ks8851.h
index 85abe147afbf..f52c312cc356 100644
--- a/drivers/net/ks8851.h
+++ b/drivers/net/ks8851.h
@@ -16,6 +16,7 @@
16#define CCR_32PIN (1 << 0) 16#define CCR_32PIN (1 << 0)
17 17
18/* MAC address registers */ 18/* MAC address registers */
19#define KS_MAR(_m) 0x15 - (_m)
19#define KS_MARL 0x10 20#define KS_MARL 0x10
20#define KS_MARM 0x12 21#define KS_MARM 0x12
21#define KS_MARH 0x14 22#define KS_MARH 0x14
diff --git a/drivers/net/ks8851_mll.c b/drivers/net/ks8851_mll.c
index 0be14d702beb..c146304d8d6c 100644
--- a/drivers/net/ks8851_mll.c
+++ b/drivers/net/ks8851_mll.c
@@ -568,6 +568,16 @@ static inline void ks_outblk(struct ks_net *ks, u16 *wptr, u32 len)
568 iowrite16(*wptr++, ks->hw_addr); 568 iowrite16(*wptr++, ks->hw_addr);
569} 569}
570 570
571static void ks_disable_int(struct ks_net *ks)
572{
573 ks_wrreg16(ks, KS_IER, 0x0000);
574} /* ks_disable_int */
575
576static void ks_enable_int(struct ks_net *ks)
577{
578 ks_wrreg16(ks, KS_IER, ks->rc_ier);
579} /* ks_enable_int */
580
571/** 581/**
572 * ks_tx_fifo_space - return the available hardware buffer size. 582 * ks_tx_fifo_space - return the available hardware buffer size.
573 * @ks: The chip information 583 * @ks: The chip information
@@ -681,6 +691,47 @@ static void ks_soft_reset(struct ks_net *ks, unsigned op)
681} 691}
682 692
683 693
694void ks_enable_qmu(struct ks_net *ks)
695{
696 u16 w;
697
698 w = ks_rdreg16(ks, KS_TXCR);
699 /* Enables QMU Transmit (TXCR). */
700 ks_wrreg16(ks, KS_TXCR, w | TXCR_TXE);
701
702 /*
703 * RX Frame Count Threshold Enable and Auto-Dequeue RXQ Frame
704 * Enable
705 */
706
707 w = ks_rdreg16(ks, KS_RXQCR);
708 ks_wrreg16(ks, KS_RXQCR, w | RXQCR_RXFCTE);
709
710 /* Enables QMU Receive (RXCR1). */
711 w = ks_rdreg16(ks, KS_RXCR1);
712 ks_wrreg16(ks, KS_RXCR1, w | RXCR1_RXE);
713 ks->enabled = true;
714} /* ks_enable_qmu */
715
716static void ks_disable_qmu(struct ks_net *ks)
717{
718 u16 w;
719
720 w = ks_rdreg16(ks, KS_TXCR);
721
722 /* Disables QMU Transmit (TXCR). */
723 w &= ~TXCR_TXE;
724 ks_wrreg16(ks, KS_TXCR, w);
725
726 /* Disables QMU Receive (RXCR1). */
727 w = ks_rdreg16(ks, KS_RXCR1);
728 w &= ~RXCR1_RXE ;
729 ks_wrreg16(ks, KS_RXCR1, w);
730
731 ks->enabled = false;
732
733} /* ks_disable_qmu */
734
684/** 735/**
685 * ks_read_qmu - read 1 pkt data from the QMU. 736 * ks_read_qmu - read 1 pkt data from the QMU.
686 * @ks: The chip information 737 * @ks: The chip information
@@ -752,7 +803,7 @@ static void ks_rcv(struct ks_net *ks, struct net_device *netdev)
752 (frame_hdr->len < RX_BUF_SIZE) && frame_hdr->len)) { 803 (frame_hdr->len < RX_BUF_SIZE) && frame_hdr->len)) {
753 skb_reserve(skb, 2); 804 skb_reserve(skb, 2);
754 /* read data block including CRC 4 bytes */ 805 /* read data block including CRC 4 bytes */
755 ks_read_qmu(ks, (u16 *)skb->data, frame_hdr->len + 4); 806 ks_read_qmu(ks, (u16 *)skb->data, frame_hdr->len);
756 skb_put(skb, frame_hdr->len); 807 skb_put(skb, frame_hdr->len);
757 skb->dev = netdev; 808 skb->dev = netdev;
758 skb->protocol = eth_type_trans(skb, netdev); 809 skb->protocol = eth_type_trans(skb, netdev);
@@ -861,7 +912,7 @@ static int ks_net_open(struct net_device *netdev)
861 ks_dbg(ks, "%s - entry\n", __func__); 912 ks_dbg(ks, "%s - entry\n", __func__);
862 913
863 /* reset the HW */ 914 /* reset the HW */
864 err = request_irq(ks->irq, ks_irq, KS_INT_FLAGS, DRV_NAME, ks); 915 err = request_irq(ks->irq, ks_irq, KS_INT_FLAGS, DRV_NAME, netdev);
865 916
866 if (err) { 917 if (err) {
867 printk(KERN_ERR "Failed to request IRQ: %d: %d\n", 918 printk(KERN_ERR "Failed to request IRQ: %d: %d\n",
@@ -869,6 +920,15 @@ static int ks_net_open(struct net_device *netdev)
869 return err; 920 return err;
870 } 921 }
871 922
923 /* wake up powermode to normal mode */
924 ks_set_powermode(ks, PMECR_PM_NORMAL);
925 mdelay(1); /* wait for normal mode to take effect */
926
927 ks_wrreg16(ks, KS_ISR, 0xffff);
928 ks_enable_int(ks);
929 ks_enable_qmu(ks);
930 netif_start_queue(ks->netdev);
931
872 if (netif_msg_ifup(ks)) 932 if (netif_msg_ifup(ks))
873 ks_dbg(ks, "network device %s up\n", netdev->name); 933 ks_dbg(ks, "network device %s up\n", netdev->name);
874 934
@@ -892,19 +952,14 @@ static int ks_net_stop(struct net_device *netdev)
892 952
893 netif_stop_queue(netdev); 953 netif_stop_queue(netdev);
894 954
895 kfree(ks->frame_head_info);
896
897 mutex_lock(&ks->lock); 955 mutex_lock(&ks->lock);
898 956
899 /* turn off the IRQs and ack any outstanding */ 957 /* turn off the IRQs and ack any outstanding */
900 ks_wrreg16(ks, KS_IER, 0x0000); 958 ks_wrreg16(ks, KS_IER, 0x0000);
901 ks_wrreg16(ks, KS_ISR, 0xffff); 959 ks_wrreg16(ks, KS_ISR, 0xffff);
902 960
903 /* shutdown RX process */ 961 /* shutdown RX/TX QMU */
904 ks_wrreg16(ks, KS_RXCR1, 0x0000); 962 ks_disable_qmu(ks);
905
906 /* shutdown TX process */
907 ks_wrreg16(ks, KS_TXCR, 0x0000);
908 963
909 /* set powermode to soft power down to save power */ 964 /* set powermode to soft power down to save power */
910 ks_set_powermode(ks, PMECR_PM_SOFTDOWN); 965 ks_set_powermode(ks, PMECR_PM_SOFTDOWN);
@@ -929,17 +984,8 @@ static int ks_net_stop(struct net_device *netdev)
929 */ 984 */
930static void ks_write_qmu(struct ks_net *ks, u8 *pdata, u16 len) 985static void ks_write_qmu(struct ks_net *ks, u8 *pdata, u16 len)
931{ 986{
932 unsigned fid = ks->fid;
933
934 fid = ks->fid;
935 ks->fid = (ks->fid + 1) & TXFR_TXFID_MASK;
936
937 /* reduce the tx interrupt occurrances. */
938 if (!fid)
939 fid |= TXFR_TXIC; /* irq on completion */
940
941 /* start header at txb[0] to align txw entries */ 987 /* start header at txb[0] to align txw entries */
942 ks->txh.txw[0] = cpu_to_le16(fid); 988 ks->txh.txw[0] = 0;
943 ks->txh.txw[1] = cpu_to_le16(len); 989 ks->txh.txw[1] = cpu_to_le16(len);
944 990
945 /* 1. set sudo-DMA mode */ 991 /* 1. set sudo-DMA mode */
@@ -957,16 +1003,6 @@ static void ks_write_qmu(struct ks_net *ks, u8 *pdata, u16 len)
957 ; 1003 ;
958} 1004}
959 1005
960static void ks_disable_int(struct ks_net *ks)
961{
962 ks_wrreg16(ks, KS_IER, 0x0000);
963} /* ks_disable_int */
964
965static void ks_enable_int(struct ks_net *ks)
966{
967 ks_wrreg16(ks, KS_IER, ks->rc_ier);
968} /* ks_enable_int */
969
970/** 1006/**
971 * ks_start_xmit - transmit packet 1007 * ks_start_xmit - transmit packet
972 * @skb : The buffer to transmit 1008 * @skb : The buffer to transmit
@@ -1410,25 +1446,6 @@ static int ks_read_selftest(struct ks_net *ks)
1410 return ret; 1446 return ret;
1411} 1447}
1412 1448
1413static void ks_disable(struct ks_net *ks)
1414{
1415 u16 w;
1416
1417 w = ks_rdreg16(ks, KS_TXCR);
1418
1419 /* Disables QMU Transmit (TXCR). */
1420 w &= ~TXCR_TXE;
1421 ks_wrreg16(ks, KS_TXCR, w);
1422
1423 /* Disables QMU Receive (RXCR1). */
1424 w = ks_rdreg16(ks, KS_RXCR1);
1425 w &= ~RXCR1_RXE ;
1426 ks_wrreg16(ks, KS_RXCR1, w);
1427
1428 ks->enabled = false;
1429
1430} /* ks_disable */
1431
1432static void ks_setup(struct ks_net *ks) 1449static void ks_setup(struct ks_net *ks)
1433{ 1450{
1434 u16 w; 1451 u16 w;
@@ -1463,7 +1480,7 @@ static void ks_setup(struct ks_net *ks)
1463 w = TXCR_TXFCE | TXCR_TXPE | TXCR_TXCRC | TXCR_TCGIP; 1480 w = TXCR_TXFCE | TXCR_TXPE | TXCR_TXCRC | TXCR_TCGIP;
1464 ks_wrreg16(ks, KS_TXCR, w); 1481 ks_wrreg16(ks, KS_TXCR, w);
1465 1482
1466 w = RXCR1_RXFCE | RXCR1_RXBE | RXCR1_RXUE; 1483 w = RXCR1_RXFCE | RXCR1_RXBE | RXCR1_RXUE | RXCR1_RXME | RXCR1_RXIPFCC;
1467 1484
1468 if (ks->promiscuous) /* bPromiscuous */ 1485 if (ks->promiscuous) /* bPromiscuous */
1469 w |= (RXCR1_RXAE | RXCR1_RXINVF); 1486 w |= (RXCR1_RXAE | RXCR1_RXINVF);
@@ -1486,28 +1503,6 @@ static void ks_setup_int(struct ks_net *ks)
1486 ks->rc_ier = (IRQ_LCI | IRQ_TXI | IRQ_RXI); 1503 ks->rc_ier = (IRQ_LCI | IRQ_TXI | IRQ_RXI);
1487} /* ks_setup_int */ 1504} /* ks_setup_int */
1488 1505
1489void ks_enable(struct ks_net *ks)
1490{
1491 u16 w;
1492
1493 w = ks_rdreg16(ks, KS_TXCR);
1494 /* Enables QMU Transmit (TXCR). */
1495 ks_wrreg16(ks, KS_TXCR, w | TXCR_TXE);
1496
1497 /*
1498 * RX Frame Count Threshold Enable and Auto-Dequeue RXQ Frame
1499 * Enable
1500 */
1501
1502 w = ks_rdreg16(ks, KS_RXQCR);
1503 ks_wrreg16(ks, KS_RXQCR, w | RXQCR_RXFCTE);
1504
1505 /* Enables QMU Receive (RXCR1). */
1506 w = ks_rdreg16(ks, KS_RXCR1);
1507 ks_wrreg16(ks, KS_RXCR1, w | RXCR1_RXE);
1508 ks->enabled = true;
1509} /* ks_enable */
1510
1511static int ks_hw_init(struct ks_net *ks) 1506static int ks_hw_init(struct ks_net *ks)
1512{ 1507{
1513#define MHEADER_SIZE (sizeof(struct type_frame_head) * MAX_RECV_FRAMES) 1508#define MHEADER_SIZE (sizeof(struct type_frame_head) * MAX_RECV_FRAMES)
@@ -1612,11 +1607,9 @@ static int __devinit ks8851_probe(struct platform_device *pdev)
1612 1607
1613 ks_soft_reset(ks, GRR_GSR); 1608 ks_soft_reset(ks, GRR_GSR);
1614 ks_hw_init(ks); 1609 ks_hw_init(ks);
1615 ks_disable(ks); 1610 ks_disable_qmu(ks);
1616 ks_setup(ks); 1611 ks_setup(ks);
1617 ks_setup_int(ks); 1612 ks_setup_int(ks);
1618 ks_enable_int(ks);
1619 ks_enable(ks);
1620 memcpy(netdev->dev_addr, ks->mac_addr, 6); 1613 memcpy(netdev->dev_addr, ks->mac_addr, 6);
1621 1614
1622 data = ks_rdreg16(ks, KS_OBCR); 1615 data = ks_rdreg16(ks, KS_OBCR);
@@ -1658,6 +1651,7 @@ static int __devexit ks8851_remove(struct platform_device *pdev)
1658 struct ks_net *ks = netdev_priv(netdev); 1651 struct ks_net *ks = netdev_priv(netdev);
1659 struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1652 struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1660 1653
1654 kfree(ks->frame_head_info);
1661 unregister_netdev(netdev); 1655 unregister_netdev(netdev);
1662 iounmap(ks->hw_addr); 1656 iounmap(ks->hw_addr);
1663 free_netdev(netdev); 1657 free_netdev(netdev);
diff --git a/drivers/net/macsonic.c b/drivers/net/macsonic.c
index 61eabcac734c..b3d7d8d77f46 100644
--- a/drivers/net/macsonic.c
+++ b/drivers/net/macsonic.c
@@ -223,69 +223,73 @@ static int __devinit macsonic_init(struct net_device *dev)
223 return 0; 223 return 0;
224} 224}
225 225
226static int __devinit mac_onboard_sonic_ethernet_addr(struct net_device *dev) 226#define INVALID_MAC(mac) (memcmp(mac, "\x08\x00\x07", 3) && \
227 memcmp(mac, "\x00\xA0\x40", 3) && \
228 memcmp(mac, "\x00\x80\x19", 3) && \
229 memcmp(mac, "\x00\x05\x02", 3))
230
231static void __devinit mac_onboard_sonic_ethernet_addr(struct net_device *dev)
227{ 232{
228 struct sonic_local *lp = netdev_priv(dev); 233 struct sonic_local *lp = netdev_priv(dev);
229 const int prom_addr = ONBOARD_SONIC_PROM_BASE; 234 const int prom_addr = ONBOARD_SONIC_PROM_BASE;
230 int i; 235 unsigned short val;
231 236
232 /* On NuBus boards we can sometimes look in the ROM resources. 237 /*
233 No such luck for comm-slot/onboard. */ 238 * On NuBus boards we can sometimes look in the ROM resources.
234 for(i = 0; i < 6; i++) 239 * No such luck for comm-slot/onboard.
235 dev->dev_addr[i] = SONIC_READ_PROM(i); 240 * On the PowerBook 520, the PROM base address is a mystery.
241 */
242 if (hwreg_present((void *)prom_addr)) {
243 int i;
244
245 for (i = 0; i < 6; i++)
246 dev->dev_addr[i] = SONIC_READ_PROM(i);
247 if (!INVALID_MAC(dev->dev_addr))
248 return;
236 249
237 /* Most of the time, the address is bit-reversed. The NetBSD 250 /*
238 source has a rather long and detailed historical account of 251 * Most of the time, the address is bit-reversed. The NetBSD
239 why this is so. */ 252 * source has a rather long and detailed historical account of
240 if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) && 253 * why this is so.
241 memcmp(dev->dev_addr, "\x00\xA0\x40", 3) && 254 */
242 memcmp(dev->dev_addr, "\x00\x80\x19", 3) &&
243 memcmp(dev->dev_addr, "\x00\x05\x02", 3))
244 bit_reverse_addr(dev->dev_addr); 255 bit_reverse_addr(dev->dev_addr);
245 else 256 if (!INVALID_MAC(dev->dev_addr))
246 return 0; 257 return;
247 258
248 /* If we still have what seems to be a bogus address, we'll
249 look in the CAM. The top entry should be ours. */
250 /* Danger! This only works if MacOS has already initialized
251 the card... */
252 if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) &&
253 memcmp(dev->dev_addr, "\x00\xA0\x40", 3) &&
254 memcmp(dev->dev_addr, "\x00\x80\x19", 3) &&
255 memcmp(dev->dev_addr, "\x00\x05\x02", 3))
256 {
257 unsigned short val;
258
259 printk(KERN_INFO "macsonic: PROM seems to be wrong, trying CAM entry 15\n");
260
261 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
262 SONIC_WRITE(SONIC_CEP, 15);
263
264 val = SONIC_READ(SONIC_CAP2);
265 dev->dev_addr[5] = val >> 8;
266 dev->dev_addr[4] = val & 0xff;
267 val = SONIC_READ(SONIC_CAP1);
268 dev->dev_addr[3] = val >> 8;
269 dev->dev_addr[2] = val & 0xff;
270 val = SONIC_READ(SONIC_CAP0);
271 dev->dev_addr[1] = val >> 8;
272 dev->dev_addr[0] = val & 0xff;
273
274 printk(KERN_INFO "HW Address from CAM 15: %pM\n",
275 dev->dev_addr);
276 } else return 0;
277
278 if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) &&
279 memcmp(dev->dev_addr, "\x00\xA0\x40", 3) &&
280 memcmp(dev->dev_addr, "\x00\x80\x19", 3) &&
281 memcmp(dev->dev_addr, "\x00\x05\x02", 3))
282 {
283 /* 259 /*
284 * Still nonsense ... messed up someplace! 260 * If we still have what seems to be a bogus address, we'll
261 * look in the CAM. The top entry should be ours.
285 */ 262 */
286 printk(KERN_ERR "macsonic: ERROR (INVALID MAC)\n"); 263 printk(KERN_WARNING "macsonic: MAC address in PROM seems "
287 return -EIO; 264 "to be invalid, trying CAM\n");
288 } else return 0; 265 } else {
266 printk(KERN_WARNING "macsonic: cannot read MAC address from "
267 "PROM, trying CAM\n");
268 }
269
270 /* This only works if MacOS has already initialized the card. */
271
272 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
273 SONIC_WRITE(SONIC_CEP, 15);
274
275 val = SONIC_READ(SONIC_CAP2);
276 dev->dev_addr[5] = val >> 8;
277 dev->dev_addr[4] = val & 0xff;
278 val = SONIC_READ(SONIC_CAP1);
279 dev->dev_addr[3] = val >> 8;
280 dev->dev_addr[2] = val & 0xff;
281 val = SONIC_READ(SONIC_CAP0);
282 dev->dev_addr[1] = val >> 8;
283 dev->dev_addr[0] = val & 0xff;
284
285 if (!INVALID_MAC(dev->dev_addr))
286 return;
287
288 /* Still nonsense ... messed up someplace! */
289
290 printk(KERN_WARNING "macsonic: MAC address in CAM entry 15 "
291 "seems invalid, will use a random MAC\n");
292 random_ether_addr(dev->dev_addr);
289} 293}
290 294
291static int __devinit mac_onboard_sonic_probe(struct net_device *dev) 295static int __devinit mac_onboard_sonic_probe(struct net_device *dev)
@@ -402,8 +406,7 @@ static int __devinit mac_onboard_sonic_probe(struct net_device *dev)
402 SONIC_WRITE(SONIC_ISR, 0x7fff); 406 SONIC_WRITE(SONIC_ISR, 0x7fff);
403 407
404 /* Now look for the MAC address. */ 408 /* Now look for the MAC address. */
405 if (mac_onboard_sonic_ethernet_addr(dev) != 0) 409 mac_onboard_sonic_ethernet_addr(dev);
406 return -ENODEV;
407 410
408 /* Shared init code */ 411 /* Shared init code */
409 return macsonic_init(dev); 412 return macsonic_init(dev);
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 3aabfd9dd212..2490aa39804c 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -360,6 +360,7 @@ static int macvlan_init(struct net_device *dev)
360 dev->state = (dev->state & ~MACVLAN_STATE_MASK) | 360 dev->state = (dev->state & ~MACVLAN_STATE_MASK) |
361 (lowerdev->state & MACVLAN_STATE_MASK); 361 (lowerdev->state & MACVLAN_STATE_MASK);
362 dev->features = lowerdev->features & MACVLAN_FEATURES; 362 dev->features = lowerdev->features & MACVLAN_FEATURES;
363 dev->gso_max_size = lowerdev->gso_max_size;
363 dev->iflink = lowerdev->ifindex; 364 dev->iflink = lowerdev->ifindex;
364 dev->hard_header_len = lowerdev->hard_header_len; 365 dev->hard_header_len = lowerdev->hard_header_len;
365 366
@@ -596,6 +597,7 @@ static int macvlan_device_event(struct notifier_block *unused,
596 case NETDEV_FEAT_CHANGE: 597 case NETDEV_FEAT_CHANGE:
597 list_for_each_entry(vlan, &port->vlans, list) { 598 list_for_each_entry(vlan, &port->vlans, list) {
598 vlan->dev->features = dev->features & MACVLAN_FEATURES; 599 vlan->dev->features = dev->features & MACVLAN_FEATURES;
600 vlan->dev->gso_max_size = dev->gso_max_size;
599 netdev_features_change(vlan->dev); 601 netdev_features_change(vlan->dev);
600 } 602 }
601 break; 603 break;
diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
index 5dd7225b178e..291a505fd4fc 100644
--- a/drivers/net/mlx4/main.c
+++ b/drivers/net/mlx4/main.c
@@ -1282,6 +1282,7 @@ static struct pci_device_id mlx4_pci_table[] = {
1282 { PCI_VDEVICE(MELLANOX, 0x6372) }, /* MT25458 ConnectX EN 10GBASE-T 10GigE */ 1282 { PCI_VDEVICE(MELLANOX, 0x6372) }, /* MT25458 ConnectX EN 10GBASE-T 10GigE */
1283 { PCI_VDEVICE(MELLANOX, 0x675a) }, /* MT25458 ConnectX EN 10GBASE-T+Gen2 10GigE */ 1283 { PCI_VDEVICE(MELLANOX, 0x675a) }, /* MT25458 ConnectX EN 10GBASE-T+Gen2 10GigE */
1284 { PCI_VDEVICE(MELLANOX, 0x6764) }, /* MT26468 ConnectX EN 10GigE PCIe gen2*/ 1284 { PCI_VDEVICE(MELLANOX, 0x6764) }, /* MT26468 ConnectX EN 10GigE PCIe gen2*/
1285 { PCI_VDEVICE(MELLANOX, 0x6746) }, /* MT26438 ConnectX EN 40GigE PCIe gen2 5GT/s */
1285 { PCI_VDEVICE(MELLANOX, 0x676e) }, /* MT26478 ConnectX2 40GigE PCIe gen2 */ 1286 { PCI_VDEVICE(MELLANOX, 0x676e) }, /* MT26478 ConnectX2 40GigE PCIe gen2 */
1286 { 0, } 1287 { 0, }
1287}; 1288};
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 6930c87f362e..f3624517cb0e 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -75,7 +75,7 @@
75#include "myri10ge_mcp.h" 75#include "myri10ge_mcp.h"
76#include "myri10ge_mcp_gen_header.h" 76#include "myri10ge_mcp_gen_header.h"
77 77
78#define MYRI10GE_VERSION_STR "1.5.0-1.432" 78#define MYRI10GE_VERSION_STR "1.5.1-1.451"
79 79
80MODULE_DESCRIPTION("Myricom 10G driver (10GbE)"); 80MODULE_DESCRIPTION("Myricom 10G driver (10GbE)");
81MODULE_AUTHOR("Maintainer: help@myri.com"); 81MODULE_AUTHOR("Maintainer: help@myri.com");
@@ -1624,10 +1624,21 @@ myri10ge_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
1624 return 0; 1624 return 0;
1625 } 1625 }
1626 } 1626 }
1627 if (*ptr == 'R' || *ptr == 'Q') { 1627 if (*ptr == '2')
1628 /* We've found either an XFP or quad ribbon fiber */ 1628 ptr++;
1629 if (*ptr == 'R' || *ptr == 'Q' || *ptr == 'S') {
1630 /* We've found either an XFP, quad ribbon fiber, or SFP+ */
1629 cmd->port = PORT_FIBRE; 1631 cmd->port = PORT_FIBRE;
1632 cmd->supported |= SUPPORTED_FIBRE;
1633 cmd->advertising |= ADVERTISED_FIBRE;
1634 } else {
1635 cmd->port = PORT_OTHER;
1630 } 1636 }
1637 if (*ptr == 'R' || *ptr == 'S')
1638 cmd->transceiver = XCVR_EXTERNAL;
1639 else
1640 cmd->transceiver = XCVR_INTERNAL;
1641
1631 return 0; 1642 return 0;
1632} 1643}
1633 1644
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index 7384f59df615..e1237b802872 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -1163,6 +1163,8 @@ struct netxen_adapter {
1163 u32 int_vec_bit; 1163 u32 int_vec_bit;
1164 u32 heartbit; 1164 u32 heartbit;
1165 1165
1166 u8 mac_addr[ETH_ALEN];
1167
1166 struct netxen_adapter_stats stats; 1168 struct netxen_adapter_stats stats;
1167 1169
1168 struct netxen_recv_context recv_ctx; 1170 struct netxen_recv_context recv_ctx;
diff --git a/drivers/net/netxen/netxen_nic_hdr.h b/drivers/net/netxen/netxen_nic_hdr.h
index 7a7177421d7c..17bb3818d84e 100644
--- a/drivers/net/netxen/netxen_nic_hdr.h
+++ b/drivers/net/netxen/netxen_nic_hdr.h
@@ -419,6 +419,7 @@ enum {
419#define NETXEN_CRB_ROMUSB \ 419#define NETXEN_CRB_ROMUSB \
420 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_ROMUSB) 420 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_ROMUSB)
421#define NETXEN_CRB_I2Q NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_I2Q) 421#define NETXEN_CRB_I2Q NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_I2Q)
422#define NETXEN_CRB_I2C0 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_I2C0)
422#define NETXEN_CRB_SMB NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SMB) 423#define NETXEN_CRB_SMB NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SMB)
423#define NETXEN_CRB_MAX NETXEN_PCI_CRB_WINDOW(64) 424#define NETXEN_CRB_MAX NETXEN_PCI_CRB_WINDOW(64)
424 425
@@ -544,6 +545,8 @@ enum {
544#define NETXEN_NIU_TEST_MUX_CTL (NETXEN_CRB_NIU + 0x00094) 545#define NETXEN_NIU_TEST_MUX_CTL (NETXEN_CRB_NIU + 0x00094)
545#define NETXEN_NIU_XG_PAUSE_CTL (NETXEN_CRB_NIU + 0x00098) 546#define NETXEN_NIU_XG_PAUSE_CTL (NETXEN_CRB_NIU + 0x00098)
546#define NETXEN_NIU_XG_PAUSE_LEVEL (NETXEN_CRB_NIU + 0x000dc) 547#define NETXEN_NIU_XG_PAUSE_LEVEL (NETXEN_CRB_NIU + 0x000dc)
548#define NETXEN_NIU_FRAME_COUNT_SELECT (NETXEN_CRB_NIU + 0x000ac)
549#define NETXEN_NIU_FRAME_COUNT (NETXEN_CRB_NIU + 0x000b0)
547#define NETXEN_NIU_XG_SEL (NETXEN_CRB_NIU + 0x00128) 550#define NETXEN_NIU_XG_SEL (NETXEN_CRB_NIU + 0x00128)
548#define NETXEN_NIU_GB_PAUSE_CTL (NETXEN_CRB_NIU + 0x0030c) 551#define NETXEN_NIU_GB_PAUSE_CTL (NETXEN_CRB_NIU + 0x0030c)
549 552
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index 32314000dfcd..52a3798d8d94 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -383,24 +383,51 @@ int netxen_niu_disable_xg_port(struct netxen_adapter *adapter)
383 383
384int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode) 384int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
385{ 385{
386 __u32 reg; 386 u32 mac_cfg;
387 u32 cnt = 0;
388 __u32 reg = 0x0200;
387 u32 port = adapter->physical_port; 389 u32 port = adapter->physical_port;
390 u16 board_type = adapter->ahw.board_type;
388 391
389 if (port > NETXEN_NIU_MAX_XG_PORTS) 392 if (port > NETXEN_NIU_MAX_XG_PORTS)
390 return -EINVAL; 393 return -EINVAL;
391 394
392 reg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port)); 395 mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port));
393 if (mode == NETXEN_NIU_PROMISC_MODE) 396 mac_cfg &= ~0x4;
394 reg = (reg | 0x2000UL); 397 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
395 else
396 reg = (reg & ~0x2000UL);
397 398
398 if (mode == NETXEN_NIU_ALLMULTI_MODE) 399 if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) ||
399 reg = (reg | 0x1000UL); 400 (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ))
400 else 401 reg = (0x20 << port);
401 reg = (reg & ~0x1000UL); 402
403 NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg);
404
405 mdelay(10);
406
407 while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20)
408 mdelay(10);
409
410 if (cnt < 20) {
411
412 reg = NXRD32(adapter,
413 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port));
402 414
403 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg); 415 if (mode == NETXEN_NIU_PROMISC_MODE)
416 reg = (reg | 0x2000UL);
417 else
418 reg = (reg & ~0x2000UL);
419
420 if (mode == NETXEN_NIU_ALLMULTI_MODE)
421 reg = (reg | 0x1000UL);
422 else
423 reg = (reg & ~0x1000UL);
424
425 NXWR32(adapter,
426 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg);
427 }
428
429 mac_cfg |= 0x4;
430 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
404 431
405 return 0; 432 return 0;
406} 433}
@@ -436,7 +463,7 @@ netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
436{ 463{
437 u32 val = 0; 464 u32 val = 0;
438 u16 port = adapter->physical_port; 465 u16 port = adapter->physical_port;
439 u8 *addr = adapter->netdev->dev_addr; 466 u8 *addr = adapter->mac_addr;
440 467
441 if (adapter->mc_enabled) 468 if (adapter->mc_enabled)
442 return 0; 469 return 0;
@@ -465,7 +492,7 @@ netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
465{ 492{
466 u32 val = 0; 493 u32 val = 0;
467 u16 port = adapter->physical_port; 494 u16 port = adapter->physical_port;
468 u8 *addr = adapter->netdev->dev_addr; 495 u8 *addr = adapter->mac_addr;
469 496
470 if (!adapter->mc_enabled) 497 if (!adapter->mc_enabled)
471 return 0; 498 return 0;
@@ -660,7 +687,7 @@ void netxen_p3_nic_set_multi(struct net_device *netdev)
660 687
661 list_splice_tail_init(&adapter->mac_list, &del_list); 688 list_splice_tail_init(&adapter->mac_list, &del_list);
662 689
663 nx_p3_nic_add_mac(adapter, netdev->dev_addr, &del_list); 690 nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list);
664 nx_p3_nic_add_mac(adapter, bcast_addr, &del_list); 691 nx_p3_nic_add_mac(adapter, bcast_addr, &del_list);
665 692
666 if (netdev->flags & IFF_PROMISC) { 693 if (netdev->flags & IFF_PROMISC) {
@@ -1901,22 +1928,16 @@ netxen_setup_hwops(struct netxen_adapter *adapter)
1901 1928
1902int netxen_nic_get_board_info(struct netxen_adapter *adapter) 1929int netxen_nic_get_board_info(struct netxen_adapter *adapter)
1903{ 1930{
1904 int offset, board_type, magic, header_version; 1931 int offset, board_type, magic;
1905 struct pci_dev *pdev = adapter->pdev; 1932 struct pci_dev *pdev = adapter->pdev;
1906 1933
1907 offset = NX_FW_MAGIC_OFFSET; 1934 offset = NX_FW_MAGIC_OFFSET;
1908 if (netxen_rom_fast_read(adapter, offset, &magic)) 1935 if (netxen_rom_fast_read(adapter, offset, &magic))
1909 return -EIO; 1936 return -EIO;
1910 1937
1911 offset = NX_HDR_VERSION_OFFSET; 1938 if (magic != NETXEN_BDINFO_MAGIC) {
1912 if (netxen_rom_fast_read(adapter, offset, &header_version)) 1939 dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
1913 return -EIO; 1940 magic);
1914
1915 if (magic != NETXEN_BDINFO_MAGIC ||
1916 header_version != NETXEN_BDINFO_VERSION) {
1917 dev_err(&pdev->dev,
1918 "invalid board config, magic=%08x, version=%08x\n",
1919 magic, header_version);
1920 return -EIO; 1941 return -EIO;
1921 } 1942 }
1922 1943
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c
index 91c2bc61c8eb..8a0904368e08 100644
--- a/drivers/net/netxen/netxen_nic_init.c
+++ b/drivers/net/netxen/netxen_nic_init.c
@@ -531,6 +531,8 @@ int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose)
531 continue; 531 continue;
532 532
533 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { 533 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
534 if (off == (NETXEN_CRB_I2C0 + 0x1c))
535 continue;
534 /* do not reset PCI */ 536 /* do not reset PCI */
535 if (off == (ROMUSB_GLB + 0xbc)) 537 if (off == (ROMUSB_GLB + 0xbc))
536 continue; 538 continue;
@@ -542,6 +544,8 @@ int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose)
542 continue; 544 continue;
543 if (off == (ROMUSB_GLB + 0x1c)) /* MS clock */ 545 if (off == (ROMUSB_GLB + 0x1c)) /* MS clock */
544 continue; 546 continue;
547 if ((off & 0x0ff00000) == NETXEN_CRB_DDR_NET)
548 continue;
545 if (off == (NETXEN_CRB_PEG_NET_1 + 0x18)) 549 if (off == (NETXEN_CRB_PEG_NET_1 + 0x18))
546 buf[i].data = 0x1020; 550 buf[i].data = 0x1020;
547 /* skip the function enable register */ 551 /* skip the function enable register */
@@ -553,12 +557,6 @@ int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose)
553 continue; 557 continue;
554 } 558 }
555 559
556 if (off == NETXEN_ADDR_ERROR) {
557 printk(KERN_ERR "%s: Err: Unknown addr: 0x%08x\n",
558 netxen_nic_driver_name, buf[i].addr);
559 continue;
560 }
561
562 init_delay = 1; 560 init_delay = 1;
563 /* After writing this register, HW needs time for CRB */ 561 /* After writing this register, HW needs time for CRB */
564 /* to quiet down (else crb_window returns 0xffffffff) */ 562 /* to quiet down (else crb_window returns 0xffffffff) */
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 9b9eab107704..3bf78dbfbf0f 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -437,6 +437,7 @@ netxen_read_mac_addr(struct netxen_adapter *adapter)
437 netdev->dev_addr[i] = *(p + 5 - i); 437 netdev->dev_addr[i] = *(p + 5 - i);
438 438
439 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); 439 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
440 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
440 441
441 /* set station address */ 442 /* set station address */
442 443
@@ -459,6 +460,7 @@ int netxen_nic_set_mac(struct net_device *netdev, void *p)
459 netxen_napi_disable(adapter); 460 netxen_napi_disable(adapter);
460 } 461 }
461 462
463 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
462 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); 464 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
463 adapter->macaddr_set(adapter, addr->sa_data); 465 adapter->macaddr_set(adapter, addr->sa_data);
464 466
@@ -595,7 +597,8 @@ netxen_setup_pci_map(struct netxen_adapter *adapter)
595 void __iomem *mem_ptr2 = NULL; 597 void __iomem *mem_ptr2 = NULL;
596 void __iomem *db_ptr = NULL; 598 void __iomem *db_ptr = NULL;
597 599
598 unsigned long mem_base, mem_len, db_base, db_len = 0, pci_len0 = 0; 600 resource_size_t mem_base, db_base;
601 unsigned long mem_len, db_len = 0, pci_len0 = 0;
599 602
600 struct pci_dev *pdev = adapter->pdev; 603 struct pci_dev *pdev = adapter->pdev;
601 int pci_func = adapter->ahw.pci_func; 604 int pci_func = adapter->ahw.pci_func;
@@ -955,7 +958,7 @@ netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
955 return err; 958 return err;
956 } 959 }
957 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) 960 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
958 adapter->macaddr_set(adapter, netdev->dev_addr); 961 adapter->macaddr_set(adapter, adapter->mac_addr);
959 962
960 adapter->set_multi(netdev); 963 adapter->set_multi(netdev);
961 adapter->set_mtu(adapter, netdev->mtu); 964 adapter->set_mtu(adapter, netdev->mtu);
@@ -1918,6 +1921,7 @@ static void netxen_tx_timeout_task(struct work_struct *work)
1918 1921
1919request_reset: 1922request_reset:
1920 adapter->need_fw_reset = 1; 1923 adapter->need_fw_reset = 1;
1924 clear_bit(__NX_RESETTING, &adapter->state);
1921} 1925}
1922 1926
1923struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev) 1927struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
diff --git a/drivers/net/niu.c b/drivers/net/niu.c
index f9364d0678f2..d6c7ac68f6ea 100644
--- a/drivers/net/niu.c
+++ b/drivers/net/niu.c
@@ -3545,7 +3545,7 @@ static int niu_process_rx_pkt(struct napi_struct *napi, struct niu *np,
3545 rp->rcr_index = index; 3545 rp->rcr_index = index;
3546 3546
3547 skb_reserve(skb, NET_IP_ALIGN); 3547 skb_reserve(skb, NET_IP_ALIGN);
3548 __pskb_pull_tail(skb, min(len, NIU_RXPULL_MAX)); 3548 __pskb_pull_tail(skb, min(len, VLAN_ETH_HLEN));
3549 3549
3550 rp->rx_packets++; 3550 rp->rx_packets++;
3551 rp->rx_bytes += skb->len; 3551 rp->rx_bytes += skb->len;
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index ee8ad3e180dd..17a27225cc98 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -118,14 +118,6 @@ INT_MODULE_PARM(full_duplex, 0);
118/* Autodetect link polarity reversal? */ 118/* Autodetect link polarity reversal? */
119INT_MODULE_PARM(auto_polarity, 1); 119INT_MODULE_PARM(auto_polarity, 1);
120 120
121#ifdef PCMCIA_DEBUG
122INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
123#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
124static char *version =
125"3c574_cs.c 1.65ac1 2003/04/07 Donald Becker/David Hinds, becker@scyld.com.\n";
126#else
127#define DEBUG(n, args...)
128#endif
129 121
130/*====================================================================*/ 122/*====================================================================*/
131 123
@@ -251,6 +243,7 @@ static void el3_tx_timeout(struct net_device *dev);
251static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 243static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
252static const struct ethtool_ops netdev_ethtool_ops; 244static const struct ethtool_ops netdev_ethtool_ops;
253static void set_rx_mode(struct net_device *dev); 245static void set_rx_mode(struct net_device *dev);
246static void set_multicast_list(struct net_device *dev);
254 247
255static void tc574_detach(struct pcmcia_device *p_dev); 248static void tc574_detach(struct pcmcia_device *p_dev);
256 249
@@ -266,7 +259,7 @@ static const struct net_device_ops el3_netdev_ops = {
266 .ndo_tx_timeout = el3_tx_timeout, 259 .ndo_tx_timeout = el3_tx_timeout,
267 .ndo_get_stats = el3_get_stats, 260 .ndo_get_stats = el3_get_stats,
268 .ndo_do_ioctl = el3_ioctl, 261 .ndo_do_ioctl = el3_ioctl,
269 .ndo_set_multicast_list = set_rx_mode, 262 .ndo_set_multicast_list = set_multicast_list,
270 .ndo_change_mtu = eth_change_mtu, 263 .ndo_change_mtu = eth_change_mtu,
271 .ndo_set_mac_address = eth_mac_addr, 264 .ndo_set_mac_address = eth_mac_addr,
272 .ndo_validate_addr = eth_validate_addr, 265 .ndo_validate_addr = eth_validate_addr,
@@ -277,7 +270,7 @@ static int tc574_probe(struct pcmcia_device *link)
277 struct el3_private *lp; 270 struct el3_private *lp;
278 struct net_device *dev; 271 struct net_device *dev;
279 272
280 DEBUG(0, "3c574_attach()\n"); 273 dev_dbg(&link->dev, "3c574_attach()\n");
281 274
282 /* Create the PC card device object. */ 275 /* Create the PC card device object. */
283 dev = alloc_etherdev(sizeof(struct el3_private)); 276 dev = alloc_etherdev(sizeof(struct el3_private));
@@ -290,10 +283,8 @@ static int tc574_probe(struct pcmcia_device *link)
290 spin_lock_init(&lp->window_lock); 283 spin_lock_init(&lp->window_lock);
291 link->io.NumPorts1 = 32; 284 link->io.NumPorts1 = 32;
292 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; 285 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
293 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_HANDLE_PRESENT; 286 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
294 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
295 link->irq.Handler = &el3_interrupt; 287 link->irq.Handler = &el3_interrupt;
296 link->irq.Instance = dev;
297 link->conf.Attributes = CONF_ENABLE_IRQ; 288 link->conf.Attributes = CONF_ENABLE_IRQ;
298 link->conf.IntType = INT_MEMORY_AND_IO; 289 link->conf.IntType = INT_MEMORY_AND_IO;
299 link->conf.ConfigIndex = 1; 290 link->conf.ConfigIndex = 1;
@@ -318,7 +309,7 @@ static void tc574_detach(struct pcmcia_device *link)
318{ 309{
319 struct net_device *dev = link->priv; 310 struct net_device *dev = link->priv;
320 311
321 DEBUG(0, "3c574_detach(0x%p)\n", link); 312 dev_dbg(&link->dev, "3c574_detach()\n");
322 313
323 if (link->dev_node) 314 if (link->dev_node)
324 unregister_netdev(dev); 315 unregister_netdev(dev);
@@ -334,26 +325,23 @@ static void tc574_detach(struct pcmcia_device *link)
334 ethernet device available to the system. 325 ethernet device available to the system.
335*/ 326*/
336 327
337#define CS_CHECK(fn, ret) \
338 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
339
340static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; 328static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
341 329
342static int tc574_config(struct pcmcia_device *link) 330static int tc574_config(struct pcmcia_device *link)
343{ 331{
344 struct net_device *dev = link->priv; 332 struct net_device *dev = link->priv;
345 struct el3_private *lp = netdev_priv(dev); 333 struct el3_private *lp = netdev_priv(dev);
346 tuple_t tuple; 334 int ret, i, j;
347 __le16 buf[32];
348 int last_fn, last_ret, i, j;
349 unsigned int ioaddr; 335 unsigned int ioaddr;
350 __be16 *phys_addr; 336 __be16 *phys_addr;
351 char *cardname; 337 char *cardname;
352 __u32 config; 338 __u32 config;
339 u8 *buf;
340 size_t len;
353 341
354 phys_addr = (__be16 *)dev->dev_addr; 342 phys_addr = (__be16 *)dev->dev_addr;
355 343
356 DEBUG(0, "3c574_config(0x%p)\n", link); 344 dev_dbg(&link->dev, "3c574_config()\n");
357 345
358 link->io.IOAddrLines = 16; 346 link->io.IOAddrLines = 16;
359 for (i = j = 0; j < 0x400; j += 0x20) { 347 for (i = j = 0; j < 0x400; j += 0x20) {
@@ -362,12 +350,16 @@ static int tc574_config(struct pcmcia_device *link)
362 if (i == 0) 350 if (i == 0)
363 break; 351 break;
364 } 352 }
365 if (i != 0) { 353 if (i != 0)
366 cs_error(link, RequestIO, i); 354 goto failed;
355
356 ret = pcmcia_request_irq(link, &link->irq);
357 if (ret)
358 goto failed;
359
360 ret = pcmcia_request_configuration(link, &link->conf);
361 if (ret)
367 goto failed; 362 goto failed;
368 }
369 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
370 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
371 363
372 dev->irq = link->irq.AssignedIRQ; 364 dev->irq = link->irq.AssignedIRQ;
373 dev->base_addr = link->io.BasePort1; 365 dev->base_addr = link->io.BasePort1;
@@ -377,16 +369,14 @@ static int tc574_config(struct pcmcia_device *link)
377 /* The 3c574 normally uses an EEPROM for configuration info, including 369 /* The 3c574 normally uses an EEPROM for configuration info, including
378 the hardware address. The future products may include a modem chip 370 the hardware address. The future products may include a modem chip
379 and put the address in the CIS. */ 371 and put the address in the CIS. */
380 tuple.Attributes = 0; 372
381 tuple.TupleData = (cisdata_t *)buf; 373 len = pcmcia_get_tuple(link, 0x88, &buf);
382 tuple.TupleDataMax = 64; 374 if (buf && len >= 6) {
383 tuple.TupleOffset = 0;
384 tuple.DesiredTuple = 0x88;
385 if (pcmcia_get_first_tuple(link, &tuple) == 0) {
386 pcmcia_get_tuple_data(link, &tuple);
387 for (i = 0; i < 3; i++) 375 for (i = 0; i < 3; i++)
388 phys_addr[i] = htons(le16_to_cpu(buf[i])); 376 phys_addr[i] = htons(le16_to_cpu(buf[i * 2]));
377 kfree(buf);
389 } else { 378 } else {
379 kfree(buf); /* 0 < len < 6 */
390 EL3WINDOW(0); 380 EL3WINDOW(0);
391 for (i = 0; i < 3; i++) 381 for (i = 0; i < 3; i++)
392 phys_addr[i] = htons(read_eeprom(ioaddr, i + 10)); 382 phys_addr[i] = htons(read_eeprom(ioaddr, i + 10));
@@ -434,7 +424,8 @@ static int tc574_config(struct pcmcia_device *link)
434 mii_status = mdio_read(ioaddr, phy & 0x1f, 1); 424 mii_status = mdio_read(ioaddr, phy & 0x1f, 1);
435 if (mii_status != 0xffff) { 425 if (mii_status != 0xffff) {
436 lp->phys = phy & 0x1f; 426 lp->phys = phy & 0x1f;
437 DEBUG(0, " MII transceiver at index %d, status %x.\n", 427 dev_dbg(&link->dev, " MII transceiver at "
428 "index %d, status %x.\n",
438 phy, mii_status); 429 phy, mii_status);
439 if ((mii_status & 0x0040) == 0) 430 if ((mii_status & 0x0040) == 0)
440 mii_preamble_required = 1; 431 mii_preamble_required = 1;
@@ -456,7 +447,7 @@ static int tc574_config(struct pcmcia_device *link)
456 } 447 }
457 448
458 link->dev_node = &lp->node; 449 link->dev_node = &lp->node;
459 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 450 SET_NETDEV_DEV(dev, &link->dev);
460 451
461 if (register_netdev(dev) != 0) { 452 if (register_netdev(dev) != 0) {
462 printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n"); 453 printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n");
@@ -477,8 +468,6 @@ static int tc574_config(struct pcmcia_device *link)
477 468
478 return 0; 469 return 0;
479 470
480cs_failed:
481 cs_error(link, last_fn, last_ret);
482failed: 471failed:
483 tc574_release(link); 472 tc574_release(link);
484 return -ENODEV; 473 return -ENODEV;
@@ -737,7 +726,7 @@ static int el3_open(struct net_device *dev)
737 lp->media.expires = jiffies + HZ; 726 lp->media.expires = jiffies + HZ;
738 add_timer(&lp->media); 727 add_timer(&lp->media);
739 728
740 DEBUG(2, "%s: opened, status %4.4x.\n", 729 dev_dbg(&link->dev, "%s: opened, status %4.4x.\n",
741 dev->name, inw(dev->base_addr + EL3_STATUS)); 730 dev->name, inw(dev->base_addr + EL3_STATUS));
742 731
743 return 0; 732 return 0;
@@ -771,7 +760,7 @@ static void pop_tx_status(struct net_device *dev)
771 if (tx_status & 0x30) 760 if (tx_status & 0x30)
772 tc574_wait_for_completion(dev, TxReset); 761 tc574_wait_for_completion(dev, TxReset);
773 if (tx_status & 0x38) { 762 if (tx_status & 0x38) {
774 DEBUG(1, "%s: transmit error: status 0x%02x\n", 763 pr_debug("%s: transmit error: status 0x%02x\n",
775 dev->name, tx_status); 764 dev->name, tx_status);
776 outw(TxEnable, ioaddr + EL3_CMD); 765 outw(TxEnable, ioaddr + EL3_CMD);
777 dev->stats.tx_aborted_errors++; 766 dev->stats.tx_aborted_errors++;
@@ -787,7 +776,7 @@ static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
787 struct el3_private *lp = netdev_priv(dev); 776 struct el3_private *lp = netdev_priv(dev);
788 unsigned long flags; 777 unsigned long flags;
789 778
790 DEBUG(3, "%s: el3_start_xmit(length = %ld) called, " 779 pr_debug("%s: el3_start_xmit(length = %ld) called, "
791 "status %4.4x.\n", dev->name, (long)skb->len, 780 "status %4.4x.\n", dev->name, (long)skb->len,
792 inw(ioaddr + EL3_STATUS)); 781 inw(ioaddr + EL3_STATUS));
793 782
@@ -826,7 +815,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
826 return IRQ_NONE; 815 return IRQ_NONE;
827 ioaddr = dev->base_addr; 816 ioaddr = dev->base_addr;
828 817
829 DEBUG(3, "%s: interrupt, status %4.4x.\n", 818 pr_debug("%s: interrupt, status %4.4x.\n",
830 dev->name, inw(ioaddr + EL3_STATUS)); 819 dev->name, inw(ioaddr + EL3_STATUS));
831 820
832 spin_lock(&lp->window_lock); 821 spin_lock(&lp->window_lock);
@@ -835,7 +824,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
835 (IntLatch | RxComplete | RxEarly | StatsFull)) { 824 (IntLatch | RxComplete | RxEarly | StatsFull)) {
836 if (!netif_device_present(dev) || 825 if (!netif_device_present(dev) ||
837 ((status & 0xe000) != 0x2000)) { 826 ((status & 0xe000) != 0x2000)) {
838 DEBUG(1, "%s: Interrupt from dead card\n", dev->name); 827 pr_debug("%s: Interrupt from dead card\n", dev->name);
839 break; 828 break;
840 } 829 }
841 830
@@ -845,7 +834,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
845 work_budget = el3_rx(dev, work_budget); 834 work_budget = el3_rx(dev, work_budget);
846 835
847 if (status & TxAvailable) { 836 if (status & TxAvailable) {
848 DEBUG(3, " TX room bit was handled.\n"); 837 pr_debug(" TX room bit was handled.\n");
849 /* There's room in the FIFO for a full-sized packet. */ 838 /* There's room in the FIFO for a full-sized packet. */
850 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD); 839 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
851 netif_wake_queue(dev); 840 netif_wake_queue(dev);
@@ -885,7 +874,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
885 } 874 }
886 875
887 if (--work_budget < 0) { 876 if (--work_budget < 0) {
888 DEBUG(0, "%s: Too much work in interrupt, " 877 pr_debug("%s: Too much work in interrupt, "
889 "status %4.4x.\n", dev->name, status); 878 "status %4.4x.\n", dev->name, status);
890 /* Clear all interrupts */ 879 /* Clear all interrupts */
891 outw(AckIntr | 0xFF, ioaddr + EL3_CMD); 880 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
@@ -895,7 +884,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
895 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD); 884 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
896 } 885 }
897 886
898 DEBUG(3, "%s: exiting interrupt, status %4.4x.\n", 887 pr_debug("%s: exiting interrupt, status %4.4x.\n",
899 dev->name, inw(ioaddr + EL3_STATUS)); 888 dev->name, inw(ioaddr + EL3_STATUS));
900 889
901 spin_unlock(&lp->window_lock); 890 spin_unlock(&lp->window_lock);
@@ -1002,7 +991,7 @@ static void update_stats(struct net_device *dev)
1002 unsigned int ioaddr = dev->base_addr; 991 unsigned int ioaddr = dev->base_addr;
1003 u8 rx, tx, up; 992 u8 rx, tx, up;
1004 993
1005 DEBUG(2, "%s: updating the statistics.\n", dev->name); 994 pr_debug("%s: updating the statistics.\n", dev->name);
1006 995
1007 if (inw(ioaddr+EL3_STATUS) == 0xffff) /* No card. */ 996 if (inw(ioaddr+EL3_STATUS) == 0xffff) /* No card. */
1008 return; 997 return;
@@ -1038,7 +1027,7 @@ static int el3_rx(struct net_device *dev, int worklimit)
1038 unsigned int ioaddr = dev->base_addr; 1027 unsigned int ioaddr = dev->base_addr;
1039 short rx_status; 1028 short rx_status;
1040 1029
1041 DEBUG(3, "%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n", 1030 pr_debug("%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n",
1042 dev->name, inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus)); 1031 dev->name, inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
1043 while (!((rx_status = inw(ioaddr + RxStatus)) & 0x8000) && 1032 while (!((rx_status = inw(ioaddr + RxStatus)) & 0x8000) &&
1044 worklimit > 0) { 1033 worklimit > 0) {
@@ -1060,7 +1049,7 @@ static int el3_rx(struct net_device *dev, int worklimit)
1060 1049
1061 skb = dev_alloc_skb(pkt_len+5); 1050 skb = dev_alloc_skb(pkt_len+5);
1062 1051
1063 DEBUG(3, " Receiving packet size %d status %4.4x.\n", 1052 pr_debug(" Receiving packet size %d status %4.4x.\n",
1064 pkt_len, rx_status); 1053 pkt_len, rx_status);
1065 if (skb != NULL) { 1054 if (skb != NULL) {
1066 skb_reserve(skb, 2); 1055 skb_reserve(skb, 2);
@@ -1071,7 +1060,7 @@ static int el3_rx(struct net_device *dev, int worklimit)
1071 dev->stats.rx_packets++; 1060 dev->stats.rx_packets++;
1072 dev->stats.rx_bytes += pkt_len; 1061 dev->stats.rx_bytes += pkt_len;
1073 } else { 1062 } else {
1074 DEBUG(1, "%s: couldn't allocate a sk_buff of" 1063 pr_debug("%s: couldn't allocate a sk_buff of"
1075 " size %d.\n", dev->name, pkt_len); 1064 " size %d.\n", dev->name, pkt_len);
1076 dev->stats.rx_dropped++; 1065 dev->stats.rx_dropped++;
1077 } 1066 }
@@ -1100,7 +1089,7 @@ static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1100 struct mii_ioctl_data *data = if_mii(rq); 1089 struct mii_ioctl_data *data = if_mii(rq);
1101 int phy = lp->phys & 0x1f; 1090 int phy = lp->phys & 0x1f;
1102 1091
1103 DEBUG(2, "%s: In ioct(%-.6s, %#4.4x) %4.4x %4.4x %4.4x %4.4x.\n", 1092 pr_debug("%s: In ioct(%-.6s, %#4.4x) %4.4x %4.4x %4.4x %4.4x.\n",
1104 dev->name, rq->ifr_ifrn.ifrn_name, cmd, 1093 dev->name, rq->ifr_ifrn.ifrn_name, cmd,
1105 data->phy_id, data->reg_num, data->val_in, data->val_out); 1094 data->phy_id, data->reg_num, data->val_in, data->val_out);
1106 1095
@@ -1161,13 +1150,23 @@ static void set_rx_mode(struct net_device *dev)
1161 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD); 1150 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
1162} 1151}
1163 1152
1153static void set_multicast_list(struct net_device *dev)
1154{
1155 struct el3_private *lp = netdev_priv(dev);
1156 unsigned long flags;
1157
1158 spin_lock_irqsave(&lp->window_lock, flags);
1159 set_rx_mode(dev);
1160 spin_unlock_irqrestore(&lp->window_lock, flags);
1161}
1162
1164static int el3_close(struct net_device *dev) 1163static int el3_close(struct net_device *dev)
1165{ 1164{
1166 unsigned int ioaddr = dev->base_addr; 1165 unsigned int ioaddr = dev->base_addr;
1167 struct el3_private *lp = netdev_priv(dev); 1166 struct el3_private *lp = netdev_priv(dev);
1168 struct pcmcia_device *link = lp->p_dev; 1167 struct pcmcia_device *link = lp->p_dev;
1169 1168
1170 DEBUG(2, "%s: shutting down ethercard.\n", dev->name); 1169 dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
1171 1170
1172 if (pcmcia_dev_present(link)) { 1171 if (pcmcia_dev_present(link)) {
1173 unsigned long flags; 1172 unsigned long flags;
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 569fb06793cf..6f8d7e2e5922 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -130,14 +130,6 @@ MODULE_LICENSE("GPL");
130/* Special hook for setting if_port when module is loaded */ 130/* Special hook for setting if_port when module is loaded */
131INT_MODULE_PARM(if_port, 0); 131INT_MODULE_PARM(if_port, 0);
132 132
133#ifdef PCMCIA_DEBUG
134INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
135#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
136static char *version =
137DRV_NAME ".c " DRV_VERSION " 2001/10/13 00:08:50 (David Hinds)";
138#else
139#define DEBUG(n, args...)
140#endif
141 133
142/*====================================================================*/ 134/*====================================================================*/
143 135
@@ -189,7 +181,7 @@ static int tc589_probe(struct pcmcia_device *link)
189 struct el3_private *lp; 181 struct el3_private *lp;
190 struct net_device *dev; 182 struct net_device *dev;
191 183
192 DEBUG(0, "3c589_attach()\n"); 184 dev_dbg(&link->dev, "3c589_attach()\n");
193 185
194 /* Create new ethernet device */ 186 /* Create new ethernet device */
195 dev = alloc_etherdev(sizeof(struct el3_private)); 187 dev = alloc_etherdev(sizeof(struct el3_private));
@@ -202,10 +194,8 @@ static int tc589_probe(struct pcmcia_device *link)
202 spin_lock_init(&lp->lock); 194 spin_lock_init(&lp->lock);
203 link->io.NumPorts1 = 16; 195 link->io.NumPorts1 = 16;
204 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; 196 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
205 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_HANDLE_PRESENT; 197 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
206 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
207 link->irq.Handler = &el3_interrupt; 198 link->irq.Handler = &el3_interrupt;
208 link->irq.Instance = dev;
209 link->conf.Attributes = CONF_ENABLE_IRQ; 199 link->conf.Attributes = CONF_ENABLE_IRQ;
210 link->conf.IntType = INT_MEMORY_AND_IO; 200 link->conf.IntType = INT_MEMORY_AND_IO;
211 link->conf.ConfigIndex = 1; 201 link->conf.ConfigIndex = 1;
@@ -231,7 +221,7 @@ static void tc589_detach(struct pcmcia_device *link)
231{ 221{
232 struct net_device *dev = link->priv; 222 struct net_device *dev = link->priv;
233 223
234 DEBUG(0, "3c589_detach(0x%p)\n", link); 224 dev_dbg(&link->dev, "3c589_detach\n");
235 225
236 if (link->dev_node) 226 if (link->dev_node)
237 unregister_netdev(dev); 227 unregister_netdev(dev);
@@ -249,29 +239,20 @@ static void tc589_detach(struct pcmcia_device *link)
249 239
250======================================================================*/ 240======================================================================*/
251 241
252#define CS_CHECK(fn, ret) \
253do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
254
255static int tc589_config(struct pcmcia_device *link) 242static int tc589_config(struct pcmcia_device *link)
256{ 243{
257 struct net_device *dev = link->priv; 244 struct net_device *dev = link->priv;
258 struct el3_private *lp = netdev_priv(dev); 245 struct el3_private *lp = netdev_priv(dev);
259 tuple_t tuple;
260 __le16 buf[32];
261 __be16 *phys_addr; 246 __be16 *phys_addr;
262 int last_fn, last_ret, i, j, multi = 0, fifo; 247 int ret, i, j, multi = 0, fifo;
263 unsigned int ioaddr; 248 unsigned int ioaddr;
264 char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; 249 char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
250 u8 *buf;
251 size_t len;
265 252
266 DEBUG(0, "3c589_config(0x%p)\n", link); 253 dev_dbg(&link->dev, "3c589_config\n");
267 254
268 phys_addr = (__be16 *)dev->dev_addr; 255 phys_addr = (__be16 *)dev->dev_addr;
269 tuple.Attributes = 0;
270 tuple.TupleData = (cisdata_t *)buf;
271 tuple.TupleDataMax = sizeof(buf);
272 tuple.TupleOffset = 0;
273 tuple.Attributes = TUPLE_RETURN_COMMON;
274
275 /* Is this a 3c562? */ 256 /* Is this a 3c562? */
276 if (link->manf_id != MANFID_3COM) 257 if (link->manf_id != MANFID_3COM)
277 printk(KERN_INFO "3c589_cs: hmmm, is this really a " 258 printk(KERN_INFO "3c589_cs: hmmm, is this really a "
@@ -287,12 +268,16 @@ static int tc589_config(struct pcmcia_device *link)
287 if (i == 0) 268 if (i == 0)
288 break; 269 break;
289 } 270 }
290 if (i != 0) { 271 if (i != 0)
291 cs_error(link, RequestIO, i);
292 goto failed; 272 goto failed;
293 } 273
294 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 274 ret = pcmcia_request_irq(link, &link->irq);
295 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 275 if (ret)
276 goto failed;
277
278 ret = pcmcia_request_configuration(link, &link->conf);
279 if (ret)
280 goto failed;
296 281
297 dev->irq = link->irq.AssignedIRQ; 282 dev->irq = link->irq.AssignedIRQ;
298 dev->base_addr = link->io.BasePort1; 283 dev->base_addr = link->io.BasePort1;
@@ -301,12 +286,13 @@ static int tc589_config(struct pcmcia_device *link)
301 286
302 /* The 3c589 has an extra EEPROM for configuration info, including 287 /* The 3c589 has an extra EEPROM for configuration info, including
303 the hardware address. The 3c562 puts the address in the CIS. */ 288 the hardware address. The 3c562 puts the address in the CIS. */
304 tuple.DesiredTuple = 0x88; 289 len = pcmcia_get_tuple(link, 0x88, &buf);
305 if (pcmcia_get_first_tuple(link, &tuple) == 0) { 290 if (buf && len >= 6) {
306 pcmcia_get_tuple_data(link, &tuple); 291 for (i = 0; i < 3; i++)
307 for (i = 0; i < 3; i++) 292 phys_addr[i] = htons(le16_to_cpu(buf[i*2]));
308 phys_addr[i] = htons(le16_to_cpu(buf[i])); 293 kfree(buf);
309 } else { 294 } else {
295 kfree(buf); /* 0 < len < 6 */
310 for (i = 0; i < 3; i++) 296 for (i = 0; i < 3; i++)
311 phys_addr[i] = htons(read_eeprom(ioaddr, i)); 297 phys_addr[i] = htons(read_eeprom(ioaddr, i));
312 if (phys_addr[0] == htons(0x6060)) { 298 if (phys_addr[0] == htons(0x6060)) {
@@ -328,7 +314,7 @@ static int tc589_config(struct pcmcia_device *link)
328 printk(KERN_ERR "3c589_cs: invalid if_port requested\n"); 314 printk(KERN_ERR "3c589_cs: invalid if_port requested\n");
329 315
330 link->dev_node = &lp->node; 316 link->dev_node = &lp->node;
331 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 317 SET_NETDEV_DEV(dev, &link->dev);
332 318
333 if (register_netdev(dev) != 0) { 319 if (register_netdev(dev) != 0) {
334 printk(KERN_ERR "3c589_cs: register_netdev() failed\n"); 320 printk(KERN_ERR "3c589_cs: register_netdev() failed\n");
@@ -347,8 +333,6 @@ static int tc589_config(struct pcmcia_device *link)
347 if_names[dev->if_port]); 333 if_names[dev->if_port]);
348 return 0; 334 return 0;
349 335
350cs_failed:
351 cs_error(link, last_fn, last_ret);
352failed: 336failed:
353 tc589_release(link); 337 tc589_release(link);
354 return -ENODEV; 338 return -ENODEV;
@@ -511,24 +495,8 @@ static void netdev_get_drvinfo(struct net_device *dev,
511 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr); 495 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
512} 496}
513 497
514#ifdef PCMCIA_DEBUG
515static u32 netdev_get_msglevel(struct net_device *dev)
516{
517 return pc_debug;
518}
519
520static void netdev_set_msglevel(struct net_device *dev, u32 level)
521{
522 pc_debug = level;
523}
524#endif /* PCMCIA_DEBUG */
525
526static const struct ethtool_ops netdev_ethtool_ops = { 498static const struct ethtool_ops netdev_ethtool_ops = {
527 .get_drvinfo = netdev_get_drvinfo, 499 .get_drvinfo = netdev_get_drvinfo,
528#ifdef PCMCIA_DEBUG
529 .get_msglevel = netdev_get_msglevel,
530 .set_msglevel = netdev_set_msglevel,
531#endif /* PCMCIA_DEBUG */
532}; 500};
533 501
534static int el3_config(struct net_device *dev, struct ifmap *map) 502static int el3_config(struct net_device *dev, struct ifmap *map)
@@ -563,7 +531,7 @@ static int el3_open(struct net_device *dev)
563 lp->media.expires = jiffies + HZ; 531 lp->media.expires = jiffies + HZ;
564 add_timer(&lp->media); 532 add_timer(&lp->media);
565 533
566 DEBUG(1, "%s: opened, status %4.4x.\n", 534 dev_dbg(&link->dev, "%s: opened, status %4.4x.\n",
567 dev->name, inw(dev->base_addr + EL3_STATUS)); 535 dev->name, inw(dev->base_addr + EL3_STATUS));
568 536
569 return 0; 537 return 0;
@@ -596,7 +564,7 @@ static void pop_tx_status(struct net_device *dev)
596 if (tx_status & 0x30) 564 if (tx_status & 0x30)
597 tc589_wait_for_completion(dev, TxReset); 565 tc589_wait_for_completion(dev, TxReset);
598 if (tx_status & 0x38) { 566 if (tx_status & 0x38) {
599 DEBUG(1, "%s: transmit error: status 0x%02x\n", 567 pr_debug("%s: transmit error: status 0x%02x\n",
600 dev->name, tx_status); 568 dev->name, tx_status);
601 outw(TxEnable, ioaddr + EL3_CMD); 569 outw(TxEnable, ioaddr + EL3_CMD);
602 dev->stats.tx_aborted_errors++; 570 dev->stats.tx_aborted_errors++;
@@ -612,7 +580,7 @@ static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
612 struct el3_private *priv = netdev_priv(dev); 580 struct el3_private *priv = netdev_priv(dev);
613 unsigned long flags; 581 unsigned long flags;
614 582
615 DEBUG(3, "%s: el3_start_xmit(length = %ld) called, " 583 pr_debug("%s: el3_start_xmit(length = %ld) called, "
616 "status %4.4x.\n", dev->name, (long)skb->len, 584 "status %4.4x.\n", dev->name, (long)skb->len,
617 inw(ioaddr + EL3_STATUS)); 585 inw(ioaddr + EL3_STATUS));
618 586
@@ -654,14 +622,14 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
654 622
655 ioaddr = dev->base_addr; 623 ioaddr = dev->base_addr;
656 624
657 DEBUG(3, "%s: interrupt, status %4.4x.\n", 625 pr_debug("%s: interrupt, status %4.4x.\n",
658 dev->name, inw(ioaddr + EL3_STATUS)); 626 dev->name, inw(ioaddr + EL3_STATUS));
659 627
660 spin_lock(&lp->lock); 628 spin_lock(&lp->lock);
661 while ((status = inw(ioaddr + EL3_STATUS)) & 629 while ((status = inw(ioaddr + EL3_STATUS)) &
662 (IntLatch | RxComplete | StatsFull)) { 630 (IntLatch | RxComplete | StatsFull)) {
663 if ((status & 0xe000) != 0x2000) { 631 if ((status & 0xe000) != 0x2000) {
664 DEBUG(1, "%s: interrupt from dead card\n", dev->name); 632 pr_debug("%s: interrupt from dead card\n", dev->name);
665 handled = 0; 633 handled = 0;
666 break; 634 break;
667 } 635 }
@@ -670,7 +638,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
670 el3_rx(dev); 638 el3_rx(dev);
671 639
672 if (status & TxAvailable) { 640 if (status & TxAvailable) {
673 DEBUG(3, " TX room bit was handled.\n"); 641 pr_debug(" TX room bit was handled.\n");
674 /* There's room in the FIFO for a full-sized packet. */ 642 /* There's room in the FIFO for a full-sized packet. */
675 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD); 643 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
676 netif_wake_queue(dev); 644 netif_wake_queue(dev);
@@ -722,7 +690,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
722 690
723 lp->last_irq = jiffies; 691 lp->last_irq = jiffies;
724 spin_unlock(&lp->lock); 692 spin_unlock(&lp->lock);
725 DEBUG(3, "%s: exiting interrupt, status %4.4x.\n", 693 pr_debug("%s: exiting interrupt, status %4.4x.\n",
726 dev->name, inw(ioaddr + EL3_STATUS)); 694 dev->name, inw(ioaddr + EL3_STATUS));
727 return IRQ_RETVAL(handled); 695 return IRQ_RETVAL(handled);
728} 696}
@@ -833,7 +801,7 @@ static void update_stats(struct net_device *dev)
833{ 801{
834 unsigned int ioaddr = dev->base_addr; 802 unsigned int ioaddr = dev->base_addr;
835 803
836 DEBUG(2, "%s: updating the statistics.\n", dev->name); 804 pr_debug("%s: updating the statistics.\n", dev->name);
837 /* Turn off statistics updates while reading. */ 805 /* Turn off statistics updates while reading. */
838 outw(StatsDisable, ioaddr + EL3_CMD); 806 outw(StatsDisable, ioaddr + EL3_CMD);
839 /* Switch to the stats window, and read everything. */ 807 /* Switch to the stats window, and read everything. */
@@ -861,7 +829,7 @@ static int el3_rx(struct net_device *dev)
861 int worklimit = 32; 829 int worklimit = 32;
862 short rx_status; 830 short rx_status;
863 831
864 DEBUG(3, "%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n", 832 pr_debug("%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n",
865 dev->name, inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS)); 833 dev->name, inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
866 while (!((rx_status = inw(ioaddr + RX_STATUS)) & 0x8000) && 834 while (!((rx_status = inw(ioaddr + RX_STATUS)) & 0x8000) &&
867 worklimit > 0) { 835 worklimit > 0) {
@@ -883,7 +851,7 @@ static int el3_rx(struct net_device *dev)
883 851
884 skb = dev_alloc_skb(pkt_len+5); 852 skb = dev_alloc_skb(pkt_len+5);
885 853
886 DEBUG(3, " Receiving packet size %d status %4.4x.\n", 854 pr_debug(" Receiving packet size %d status %4.4x.\n",
887 pkt_len, rx_status); 855 pkt_len, rx_status);
888 if (skb != NULL) { 856 if (skb != NULL) {
889 skb_reserve(skb, 2); 857 skb_reserve(skb, 2);
@@ -894,7 +862,7 @@ static int el3_rx(struct net_device *dev)
894 dev->stats.rx_packets++; 862 dev->stats.rx_packets++;
895 dev->stats.rx_bytes += pkt_len; 863 dev->stats.rx_bytes += pkt_len;
896 } else { 864 } else {
897 DEBUG(1, "%s: couldn't allocate a sk_buff of" 865 pr_debug("%s: couldn't allocate a sk_buff of"
898 " size %d.\n", dev->name, pkt_len); 866 " size %d.\n", dev->name, pkt_len);
899 dev->stats.rx_dropped++; 867 dev->stats.rx_dropped++;
900 } 868 }
@@ -935,7 +903,7 @@ static int el3_close(struct net_device *dev)
935 struct pcmcia_device *link = lp->p_dev; 903 struct pcmcia_device *link = lp->p_dev;
936 unsigned int ioaddr = dev->base_addr; 904 unsigned int ioaddr = dev->base_addr;
937 905
938 DEBUG(1, "%s: shutting down ethercard.\n", dev->name); 906 dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
939 907
940 if (pcmcia_dev_present(link)) { 908 if (pcmcia_dev_present(link)) {
941 /* Turn off statistics ASAP. We update dev->stats below. */ 909 /* Turn off statistics ASAP. We update dev->stats below. */
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index 3131a59a8d32..800597b82d18 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -75,16 +75,6 @@ MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
75MODULE_DESCRIPTION("Asix AX88190 PCMCIA ethernet driver"); 75MODULE_DESCRIPTION("Asix AX88190 PCMCIA ethernet driver");
76MODULE_LICENSE("GPL"); 76MODULE_LICENSE("GPL");
77 77
78#ifdef PCMCIA_DEBUG
79#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
80
81INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
82#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
83static char *version =
84"axnet_cs.c 1.28 2002/06/29 06:27:37 (David Hinds)";
85#else
86#define DEBUG(n, args...)
87#endif
88 78
89/*====================================================================*/ 79/*====================================================================*/
90 80
@@ -167,7 +157,7 @@ static int axnet_probe(struct pcmcia_device *link)
167 struct net_device *dev; 157 struct net_device *dev;
168 struct ei_device *ei_local; 158 struct ei_device *ei_local;
169 159
170 DEBUG(0, "axnet_attach()\n"); 160 dev_dbg(&link->dev, "axnet_attach()\n");
171 161
172 dev = alloc_etherdev(sizeof(struct ei_device) + sizeof(axnet_dev_t)); 162 dev = alloc_etherdev(sizeof(struct ei_device) + sizeof(axnet_dev_t));
173 if (!dev) 163 if (!dev)
@@ -180,7 +170,6 @@ static int axnet_probe(struct pcmcia_device *link)
180 info->p_dev = link; 170 info->p_dev = link;
181 link->priv = dev; 171 link->priv = dev;
182 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING; 172 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
183 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
184 link->conf.Attributes = CONF_ENABLE_IRQ; 173 link->conf.Attributes = CONF_ENABLE_IRQ;
185 link->conf.IntType = INT_MEMORY_AND_IO; 174 link->conf.IntType = INT_MEMORY_AND_IO;
186 175
@@ -205,7 +194,7 @@ static void axnet_detach(struct pcmcia_device *link)
205{ 194{
206 struct net_device *dev = link->priv; 195 struct net_device *dev = link->priv;
207 196
208 DEBUG(0, "axnet_detach(0x%p)\n", link); 197 dev_dbg(&link->dev, "axnet_detach(0x%p)\n", link);
209 198
210 if (link->dev_node) 199 if (link->dev_node)
211 unregister_netdev(dev); 200 unregister_netdev(dev);
@@ -272,9 +261,6 @@ static int get_prom(struct pcmcia_device *link)
272 261
273======================================================================*/ 262======================================================================*/
274 263
275#define CS_CHECK(fn, ret) \
276do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
277
278static int try_io_port(struct pcmcia_device *link) 264static int try_io_port(struct pcmcia_device *link)
279{ 265{
280 int j, ret; 266 int j, ret;
@@ -341,26 +327,29 @@ static int axnet_config(struct pcmcia_device *link)
341{ 327{
342 struct net_device *dev = link->priv; 328 struct net_device *dev = link->priv;
343 axnet_dev_t *info = PRIV(dev); 329 axnet_dev_t *info = PRIV(dev);
344 int i, j, j2, last_ret, last_fn; 330 int i, j, j2, ret;
345 331
346 DEBUG(0, "axnet_config(0x%p)\n", link); 332 dev_dbg(&link->dev, "axnet_config(0x%p)\n", link);
347 333
348 /* don't trust the CIS on this; Linksys got it wrong */ 334 /* don't trust the CIS on this; Linksys got it wrong */
349 link->conf.Present = 0x63; 335 link->conf.Present = 0x63;
350 last_ret = pcmcia_loop_config(link, axnet_configcheck, NULL); 336 ret = pcmcia_loop_config(link, axnet_configcheck, NULL);
351 if (last_ret != 0) { 337 if (ret != 0)
352 cs_error(link, RequestIO, last_ret);
353 goto failed; 338 goto failed;
354 }
355 339
356 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 340 ret = pcmcia_request_irq(link, &link->irq);
341 if (ret)
342 goto failed;
357 343
358 if (link->io.NumPorts2 == 8) { 344 if (link->io.NumPorts2 == 8) {
359 link->conf.Attributes |= CONF_ENABLE_SPKR; 345 link->conf.Attributes |= CONF_ENABLE_SPKR;
360 link->conf.Status = CCSR_AUDIO_ENA; 346 link->conf.Status = CCSR_AUDIO_ENA;
361 } 347 }
362 348
363 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 349 ret = pcmcia_request_configuration(link, &link->conf);
350 if (ret)
351 goto failed;
352
364 dev->irq = link->irq.AssignedIRQ; 353 dev->irq = link->irq.AssignedIRQ;
365 dev->base_addr = link->io.BasePort1; 354 dev->base_addr = link->io.BasePort1;
366 355
@@ -410,7 +399,7 @@ static int axnet_config(struct pcmcia_device *link)
410 399
411 info->phy_id = (i < 32) ? i : -1; 400 info->phy_id = (i < 32) ? i : -1;
412 link->dev_node = &info->node; 401 link->dev_node = &info->node;
413 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 402 SET_NETDEV_DEV(dev, &link->dev);
414 403
415 if (register_netdev(dev) != 0) { 404 if (register_netdev(dev) != 0) {
416 printk(KERN_NOTICE "axnet_cs: register_netdev() failed\n"); 405 printk(KERN_NOTICE "axnet_cs: register_netdev() failed\n");
@@ -426,14 +415,12 @@ static int axnet_config(struct pcmcia_device *link)
426 dev->base_addr, dev->irq, 415 dev->base_addr, dev->irq,
427 dev->dev_addr); 416 dev->dev_addr);
428 if (info->phy_id != -1) { 417 if (info->phy_id != -1) {
429 DEBUG(0, " MII transceiver at index %d, status %x.\n", info->phy_id, j); 418 dev_dbg(&link->dev, " MII transceiver at index %d, status %x.\n", info->phy_id, j);
430 } else { 419 } else {
431 printk(KERN_NOTICE " No MII transceivers found!\n"); 420 printk(KERN_NOTICE " No MII transceivers found!\n");
432 } 421 }
433 return 0; 422 return 0;
434 423
435cs_failed:
436 cs_error(link, last_fn, last_ret);
437failed: 424failed:
438 axnet_release(link); 425 axnet_release(link);
439 return -ENODEV; 426 return -ENODEV;
@@ -543,7 +530,7 @@ static int axnet_open(struct net_device *dev)
543 struct pcmcia_device *link = info->p_dev; 530 struct pcmcia_device *link = info->p_dev;
544 unsigned int nic_base = dev->base_addr; 531 unsigned int nic_base = dev->base_addr;
545 532
546 DEBUG(2, "axnet_open('%s')\n", dev->name); 533 dev_dbg(&link->dev, "axnet_open('%s')\n", dev->name);
547 534
548 if (!pcmcia_dev_present(link)) 535 if (!pcmcia_dev_present(link))
549 return -ENODEV; 536 return -ENODEV;
@@ -572,7 +559,7 @@ static int axnet_close(struct net_device *dev)
572 axnet_dev_t *info = PRIV(dev); 559 axnet_dev_t *info = PRIV(dev);
573 struct pcmcia_device *link = info->p_dev; 560 struct pcmcia_device *link = info->p_dev;
574 561
575 DEBUG(2, "axnet_close('%s')\n", dev->name); 562 dev_dbg(&link->dev, "axnet_close('%s')\n", dev->name);
576 563
577 ax_close(dev); 564 ax_close(dev);
578 free_irq(dev->irq, dev); 565 free_irq(dev->irq, dev);
@@ -741,10 +728,8 @@ static void block_input(struct net_device *dev, int count,
741 int xfer_count = count; 728 int xfer_count = count;
742 char *buf = skb->data; 729 char *buf = skb->data;
743 730
744#ifdef PCMCIA_DEBUG
745 if ((ei_debug > 4) && (count != 4)) 731 if ((ei_debug > 4) && (count != 4))
746 printk(KERN_DEBUG "%s: [bi=%d]\n", dev->name, count+4); 732 pr_debug("%s: [bi=%d]\n", dev->name, count+4);
747#endif
748 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO); 733 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
749 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI); 734 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
750 outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD); 735 outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD);
@@ -762,10 +747,7 @@ static void block_output(struct net_device *dev, int count,
762{ 747{
763 unsigned int nic_base = dev->base_addr; 748 unsigned int nic_base = dev->base_addr;
764 749
765#ifdef PCMCIA_DEBUG 750 pr_debug("%s: [bo=%d]\n", dev->name, count);
766 if (ei_debug > 4)
767 printk(KERN_DEBUG "%s: [bo=%d]\n", dev->name, count);
768#endif
769 751
770 /* Round the count up for word writes. Do we need to do this? 752 /* Round the count up for word writes. Do we need to do this?
771 What effect will an odd byte count have on the 8390? 753 What effect will an odd byte count have on the 8390?
diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c
index 7b5c77b7bd27..21d9c9d815d1 100644
--- a/drivers/net/pcmcia/com20020_cs.c
+++ b/drivers/net/pcmcia/com20020_cs.c
@@ -53,11 +53,7 @@
53 53
54#define VERSION "arcnet: COM20020 PCMCIA support loaded.\n" 54#define VERSION "arcnet: COM20020 PCMCIA support loaded.\n"
55 55
56#ifdef PCMCIA_DEBUG 56#ifdef DEBUG
57
58static int pc_debug = PCMCIA_DEBUG;
59module_param(pc_debug, int, 0);
60#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
61 57
62static void regdump(struct net_device *dev) 58static void regdump(struct net_device *dev)
63{ 59{
@@ -92,7 +88,6 @@ static void regdump(struct net_device *dev)
92 88
93#else 89#else
94 90
95#define DEBUG(n, args...) do { } while (0)
96static inline void regdump(struct net_device *dev) { } 91static inline void regdump(struct net_device *dev) { }
97 92
98#endif 93#endif
@@ -144,7 +139,7 @@ static int com20020_probe(struct pcmcia_device *p_dev)
144 struct net_device *dev; 139 struct net_device *dev;
145 struct arcnet_local *lp; 140 struct arcnet_local *lp;
146 141
147 DEBUG(0, "com20020_attach()\n"); 142 dev_dbg(&p_dev->dev, "com20020_attach()\n");
148 143
149 /* Create new network device */ 144 /* Create new network device */
150 info = kzalloc(sizeof(struct com20020_dev_t), GFP_KERNEL); 145 info = kzalloc(sizeof(struct com20020_dev_t), GFP_KERNEL);
@@ -169,11 +164,10 @@ static int com20020_probe(struct pcmcia_device *p_dev)
169 p_dev->io.NumPorts1 = 16; 164 p_dev->io.NumPorts1 = 16;
170 p_dev->io.IOAddrLines = 16; 165 p_dev->io.IOAddrLines = 16;
171 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 166 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
172 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
173 p_dev->conf.Attributes = CONF_ENABLE_IRQ; 167 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
174 p_dev->conf.IntType = INT_MEMORY_AND_IO; 168 p_dev->conf.IntType = INT_MEMORY_AND_IO;
175 169
176 p_dev->irq.Instance = info->dev = dev; 170 info->dev = dev;
177 p_dev->priv = info; 171 p_dev->priv = info;
178 172
179 return com20020_config(p_dev); 173 return com20020_config(p_dev);
@@ -198,12 +192,12 @@ static void com20020_detach(struct pcmcia_device *link)
198 struct com20020_dev_t *info = link->priv; 192 struct com20020_dev_t *info = link->priv;
199 struct net_device *dev = info->dev; 193 struct net_device *dev = info->dev;
200 194
201 DEBUG(1,"detach...\n"); 195 dev_dbg(&link->dev, "detach...\n");
202 196
203 DEBUG(0, "com20020_detach(0x%p)\n", link); 197 dev_dbg(&link->dev, "com20020_detach\n");
204 198
205 if (link->dev_node) { 199 if (link->dev_node) {
206 DEBUG(1,"unregister...\n"); 200 dev_dbg(&link->dev, "unregister...\n");
207 201
208 unregister_netdev(dev); 202 unregister_netdev(dev);
209 203
@@ -218,16 +212,16 @@ static void com20020_detach(struct pcmcia_device *link)
218 com20020_release(link); 212 com20020_release(link);
219 213
220 /* Unlink device structure, free bits */ 214 /* Unlink device structure, free bits */
221 DEBUG(1,"unlinking...\n"); 215 dev_dbg(&link->dev, "unlinking...\n");
222 if (link->priv) 216 if (link->priv)
223 { 217 {
224 dev = info->dev; 218 dev = info->dev;
225 if (dev) 219 if (dev)
226 { 220 {
227 DEBUG(1,"kfree...\n"); 221 dev_dbg(&link->dev, "kfree...\n");
228 free_netdev(dev); 222 free_netdev(dev);
229 } 223 }
230 DEBUG(1,"kfree2...\n"); 224 dev_dbg(&link->dev, "kfree2...\n");
231 kfree(info); 225 kfree(info);
232 } 226 }
233 227
@@ -241,25 +235,22 @@ static void com20020_detach(struct pcmcia_device *link)
241 235
242======================================================================*/ 236======================================================================*/
243 237
244#define CS_CHECK(fn, ret) \
245do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
246
247static int com20020_config(struct pcmcia_device *link) 238static int com20020_config(struct pcmcia_device *link)
248{ 239{
249 struct arcnet_local *lp; 240 struct arcnet_local *lp;
250 com20020_dev_t *info; 241 com20020_dev_t *info;
251 struct net_device *dev; 242 struct net_device *dev;
252 int i, last_ret, last_fn; 243 int i, ret;
253 int ioaddr; 244 int ioaddr;
254 245
255 info = link->priv; 246 info = link->priv;
256 dev = info->dev; 247 dev = info->dev;
257 248
258 DEBUG(1,"config...\n"); 249 dev_dbg(&link->dev, "config...\n");
259 250
260 DEBUG(0, "com20020_config(0x%p)\n", link); 251 dev_dbg(&link->dev, "com20020_config\n");
261 252
262 DEBUG(1,"arcnet: baseport1 is %Xh\n", link->io.BasePort1); 253 dev_dbg(&link->dev, "baseport1 is %Xh\n", link->io.BasePort1);
263 i = -ENODEV; 254 i = -ENODEV;
264 if (!link->io.BasePort1) 255 if (!link->io.BasePort1)
265 { 256 {
@@ -276,26 +267,27 @@ static int com20020_config(struct pcmcia_device *link)
276 267
277 if (i != 0) 268 if (i != 0)
278 { 269 {
279 DEBUG(1,"arcnet: requestIO failed totally!\n"); 270 dev_dbg(&link->dev, "requestIO failed totally!\n");
280 goto failed; 271 goto failed;
281 } 272 }
282 273
283 ioaddr = dev->base_addr = link->io.BasePort1; 274 ioaddr = dev->base_addr = link->io.BasePort1;
284 DEBUG(1,"arcnet: got ioaddr %Xh\n", ioaddr); 275 dev_dbg(&link->dev, "got ioaddr %Xh\n", ioaddr);
285 276
286 DEBUG(1,"arcnet: request IRQ %d (%Xh/%Xh)\n", 277 dev_dbg(&link->dev, "request IRQ %d\n",
287 link->irq.AssignedIRQ, 278 link->irq.AssignedIRQ);
288 link->irq.IRQInfo1, link->irq.IRQInfo2);
289 i = pcmcia_request_irq(link, &link->irq); 279 i = pcmcia_request_irq(link, &link->irq);
290 if (i != 0) 280 if (i != 0)
291 { 281 {
292 DEBUG(1,"arcnet: requestIRQ failed totally!\n"); 282 dev_dbg(&link->dev, "requestIRQ failed totally!\n");
293 goto failed; 283 goto failed;
294 } 284 }
295 285
296 dev->irq = link->irq.AssignedIRQ; 286 dev->irq = link->irq.AssignedIRQ;
297 287
298 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 288 ret = pcmcia_request_configuration(link, &link->conf);
289 if (ret)
290 goto failed;
299 291
300 if (com20020_check(dev)) 292 if (com20020_check(dev))
301 { 293 {
@@ -308,26 +300,25 @@ static int com20020_config(struct pcmcia_device *link)
308 lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */ 300 lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */
309 301
310 link->dev_node = &info->node; 302 link->dev_node = &info->node;
311 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 303 SET_NETDEV_DEV(dev, &link->dev);
312 304
313 i = com20020_found(dev, 0); /* calls register_netdev */ 305 i = com20020_found(dev, 0); /* calls register_netdev */
314 306
315 if (i != 0) { 307 if (i != 0) {
316 DEBUG(1,KERN_NOTICE "com20020_cs: com20020_found() failed\n"); 308 dev_printk(KERN_NOTICE, &link->dev,
309 "com20020_cs: com20020_found() failed\n");
317 link->dev_node = NULL; 310 link->dev_node = NULL;
318 goto failed; 311 goto failed;
319 } 312 }
320 313
321 strcpy(info->node.dev_name, dev->name); 314 strcpy(info->node.dev_name, dev->name);
322 315
323 DEBUG(1,KERN_INFO "%s: port %#3lx, irq %d\n", 316 dev_dbg(&link->dev,KERN_INFO "%s: port %#3lx, irq %d\n",
324 dev->name, dev->base_addr, dev->irq); 317 dev->name, dev->base_addr, dev->irq);
325 return 0; 318 return 0;
326 319
327cs_failed:
328 cs_error(link, last_fn, last_ret);
329failed: 320failed:
330 DEBUG(1,"com20020_config failed...\n"); 321 dev_dbg(&link->dev, "com20020_config failed...\n");
331 com20020_release(link); 322 com20020_release(link);
332 return -ENODEV; 323 return -ENODEV;
333} /* com20020_config */ 324} /* com20020_config */
@@ -342,7 +333,7 @@ failed:
342 333
343static void com20020_release(struct pcmcia_device *link) 334static void com20020_release(struct pcmcia_device *link)
344{ 335{
345 DEBUG(0, "com20020_release(0x%p)\n", link); 336 dev_dbg(&link->dev, "com20020_release\n");
346 pcmcia_disable_device(link); 337 pcmcia_disable_device(link);
347} 338}
348 339
diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c
index 7e01fbdb87e0..6e3e1ced6db4 100644
--- a/drivers/net/pcmcia/fmvj18x_cs.c
+++ b/drivers/net/pcmcia/fmvj18x_cs.c
@@ -72,13 +72,6 @@ MODULE_LICENSE("GPL");
72/* 0:4KB*2 TX buffer else:8KB*2 TX buffer */ 72/* 0:4KB*2 TX buffer else:8KB*2 TX buffer */
73INT_MODULE_PARM(sram_config, 0); 73INT_MODULE_PARM(sram_config, 0);
74 74
75#ifdef PCMCIA_DEBUG
76INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
77#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
78static char *version = DRV_NAME ".c " DRV_VERSION " 2002/03/23";
79#else
80#define DEBUG(n, args...)
81#endif
82 75
83/*====================================================================*/ 76/*====================================================================*/
84/* 77/*
@@ -245,7 +238,7 @@ static int fmvj18x_probe(struct pcmcia_device *link)
245 local_info_t *lp; 238 local_info_t *lp;
246 struct net_device *dev; 239 struct net_device *dev;
247 240
248 DEBUG(0, "fmvj18x_attach()\n"); 241 dev_dbg(&link->dev, "fmvj18x_attach()\n");
249 242
250 /* Make up a FMVJ18x specific data structure */ 243 /* Make up a FMVJ18x specific data structure */
251 dev = alloc_etherdev(sizeof(local_info_t)); 244 dev = alloc_etherdev(sizeof(local_info_t));
@@ -262,10 +255,8 @@ static int fmvj18x_probe(struct pcmcia_device *link)
262 link->io.IOAddrLines = 5; 255 link->io.IOAddrLines = 5;
263 256
264 /* Interrupt setup */ 257 /* Interrupt setup */
265 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_HANDLE_PRESENT; 258 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
266 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
267 link->irq.Handler = &fjn_interrupt; 259 link->irq.Handler = &fjn_interrupt;
268 link->irq.Instance = dev;
269 260
270 /* General socket configuration */ 261 /* General socket configuration */
271 link->conf.Attributes = CONF_ENABLE_IRQ; 262 link->conf.Attributes = CONF_ENABLE_IRQ;
@@ -285,7 +276,7 @@ static void fmvj18x_detach(struct pcmcia_device *link)
285{ 276{
286 struct net_device *dev = link->priv; 277 struct net_device *dev = link->priv;
287 278
288 DEBUG(0, "fmvj18x_detach(0x%p)\n", link); 279 dev_dbg(&link->dev, "fmvj18x_detach\n");
289 280
290 if (link->dev_node) 281 if (link->dev_node)
291 unregister_netdev(dev); 282 unregister_netdev(dev);
@@ -297,9 +288,6 @@ static void fmvj18x_detach(struct pcmcia_device *link)
297 288
298/*====================================================================*/ 289/*====================================================================*/
299 290
300#define CS_CHECK(fn, ret) \
301do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
302
303static int mfc_try_io_port(struct pcmcia_device *link) 291static int mfc_try_io_port(struct pcmcia_device *link)
304{ 292{
305 int i, ret; 293 int i, ret;
@@ -341,33 +329,38 @@ static int ungermann_try_io_port(struct pcmcia_device *link)
341 return ret; /* RequestIO failed */ 329 return ret; /* RequestIO failed */
342} 330}
343 331
332static int fmvj18x_ioprobe(struct pcmcia_device *p_dev,
333 cistpl_cftable_entry_t *cfg,
334 cistpl_cftable_entry_t *dflt,
335 unsigned int vcc,
336 void *priv_data)
337{
338 return 0; /* strange, but that's what the code did already before... */
339}
340
344static int fmvj18x_config(struct pcmcia_device *link) 341static int fmvj18x_config(struct pcmcia_device *link)
345{ 342{
346 struct net_device *dev = link->priv; 343 struct net_device *dev = link->priv;
347 local_info_t *lp = netdev_priv(dev); 344 local_info_t *lp = netdev_priv(dev);
348 tuple_t tuple; 345 int i, ret;
349 cisparse_t parse;
350 u_short buf[32];
351 int i, last_fn = 0, last_ret = 0, ret;
352 unsigned int ioaddr; 346 unsigned int ioaddr;
353 cardtype_t cardtype; 347 cardtype_t cardtype;
354 char *card_name = "unknown"; 348 char *card_name = "unknown";
355 u_char *node_id; 349 u8 *buf;
350 size_t len;
351 u_char buggybuf[32];
352
353 dev_dbg(&link->dev, "fmvj18x_config\n");
356 354
357 DEBUG(0, "fmvj18x_config(0x%p)\n", link); 355 len = pcmcia_get_tuple(link, CISTPL_FUNCE, &buf);
356 kfree(buf);
358 357
359 tuple.TupleData = (u_char *)buf; 358 if (len) {
360 tuple.TupleDataMax = 64;
361 tuple.TupleOffset = 0;
362 tuple.DesiredTuple = CISTPL_FUNCE;
363 tuple.TupleOffset = 0;
364 if (pcmcia_get_first_tuple(link, &tuple) == 0) {
365 /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */ 359 /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */
366 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 360 ret = pcmcia_loop_config(link, fmvj18x_ioprobe, NULL);
367 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); 361 if (ret != 0)
368 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); 362 goto failed;
369 CS_CHECK(ParseTuple, pcmcia_parse_tuple(&tuple, &parse)); 363
370 link->conf.ConfigIndex = parse.cftable_entry.index;
371 switch (link->manf_id) { 364 switch (link->manf_id) {
372 case MANFID_TDK: 365 case MANFID_TDK:
373 cardtype = TDK; 366 cardtype = TDK;
@@ -433,17 +426,24 @@ static int fmvj18x_config(struct pcmcia_device *link)
433 426
434 if (link->io.NumPorts2 != 0) { 427 if (link->io.NumPorts2 != 0) {
435 link->irq.Attributes = 428 link->irq.Attributes =
436 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT; 429 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
437 ret = mfc_try_io_port(link); 430 ret = mfc_try_io_port(link);
438 if (ret != 0) goto cs_failed; 431 if (ret != 0) goto failed;
439 } else if (cardtype == UNGERMANN) { 432 } else if (cardtype == UNGERMANN) {
440 ret = ungermann_try_io_port(link); 433 ret = ungermann_try_io_port(link);
441 if (ret != 0) goto cs_failed; 434 if (ret != 0) goto failed;
442 } else { 435 } else {
443 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io)); 436 ret = pcmcia_request_io(link, &link->io);
437 if (ret)
438 goto failed;
444 } 439 }
445 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 440 ret = pcmcia_request_irq(link, &link->irq);
446 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 441 if (ret)
442 goto failed;
443 ret = pcmcia_request_configuration(link, &link->conf);
444 if (ret)
445 goto failed;
446
447 dev->irq = link->irq.AssignedIRQ; 447 dev->irq = link->irq.AssignedIRQ;
448 dev->base_addr = link->io.BasePort1; 448 dev->base_addr = link->io.BasePort1;
449 449
@@ -474,21 +474,21 @@ static int fmvj18x_config(struct pcmcia_device *link)
474 case CONTEC: 474 case CONTEC:
475 case NEC: 475 case NEC:
476 case KME: 476 case KME:
477 tuple.DesiredTuple = CISTPL_FUNCE;
478 tuple.TupleOffset = 0;
479 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
480 tuple.TupleOffset = 0;
481 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
482 if (cardtype == MBH10304) { 477 if (cardtype == MBH10304) {
483 /* MBH10304's CIS_FUNCE is corrupted */
484 node_id = &(tuple.TupleData[5]);
485 card_name = "FMV-J182"; 478 card_name = "FMV-J182";
486 } else { 479
487 while (tuple.TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID ) { 480 len = pcmcia_get_tuple(link, CISTPL_FUNCE, &buf);
488 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple)); 481 if (len < 11) {
489 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); 482 kfree(buf);
483 goto failed;
490 } 484 }
491 node_id = &(tuple.TupleData[2]); 485 /* Read MACID from CIS */
486 for (i = 5; i < 11; i++)
487 dev->dev_addr[i] = buf[i];
488 kfree(buf);
489 } else {
490 if (pcmcia_get_mac_from_cis(link, dev))
491 goto failed;
492 if( cardtype == TDK ) { 492 if( cardtype == TDK ) {
493 card_name = "TDK LAK-CD021"; 493 card_name = "TDK LAK-CD021";
494 } else if( cardtype == LA501 ) { 494 } else if( cardtype == LA501 ) {
@@ -501,9 +501,6 @@ static int fmvj18x_config(struct pcmcia_device *link)
501 card_name = "C-NET(PC)C"; 501 card_name = "C-NET(PC)C";
502 } 502 }
503 } 503 }
504 /* Read MACID from CIS */
505 for (i = 0; i < 6; i++)
506 dev->dev_addr[i] = node_id[i];
507 break; 504 break;
508 case UNGERMANN: 505 case UNGERMANN:
509 /* Read MACID from register */ 506 /* Read MACID from register */
@@ -513,12 +510,12 @@ static int fmvj18x_config(struct pcmcia_device *link)
513 break; 510 break;
514 case XXX10304: 511 case XXX10304:
515 /* Read MACID from Buggy CIS */ 512 /* Read MACID from Buggy CIS */
516 if (fmvj18x_get_hwinfo(link, tuple.TupleData) == -1) { 513 if (fmvj18x_get_hwinfo(link, buggybuf) == -1) {
517 printk(KERN_NOTICE "fmvj18x_cs: unable to read hardware net address.\n"); 514 printk(KERN_NOTICE "fmvj18x_cs: unable to read hardware net address.\n");
518 goto failed; 515 goto failed;
519 } 516 }
520 for (i = 0 ; i < 6; i++) { 517 for (i = 0 ; i < 6; i++) {
521 dev->dev_addr[i] = tuple.TupleData[i]; 518 dev->dev_addr[i] = buggybuf[i];
522 } 519 }
523 card_name = "FMV-J182"; 520 card_name = "FMV-J182";
524 break; 521 break;
@@ -533,7 +530,7 @@ static int fmvj18x_config(struct pcmcia_device *link)
533 530
534 lp->cardtype = cardtype; 531 lp->cardtype = cardtype;
535 link->dev_node = &lp->node; 532 link->dev_node = &lp->node;
536 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 533 SET_NETDEV_DEV(dev, &link->dev);
537 534
538 if (register_netdev(dev) != 0) { 535 if (register_netdev(dev) != 0) {
539 printk(KERN_NOTICE "fmvj18x_cs: register_netdev() failed\n"); 536 printk(KERN_NOTICE "fmvj18x_cs: register_netdev() failed\n");
@@ -551,9 +548,6 @@ static int fmvj18x_config(struct pcmcia_device *link)
551 548
552 return 0; 549 return 0;
553 550
554cs_failed:
555 /* All Card Services errors end up here */
556 cs_error(link, last_fn, last_ret);
557failed: 551failed:
558 fmvj18x_release(link); 552 fmvj18x_release(link);
559 return -ENODEV; 553 return -ENODEV;
@@ -571,16 +565,14 @@ static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
571 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 565 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
572 req.Base = 0; req.Size = 0; 566 req.Base = 0; req.Size = 0;
573 req.AccessSpeed = 0; 567 req.AccessSpeed = 0;
574 i = pcmcia_request_window(&link, &req, &link->win); 568 i = pcmcia_request_window(link, &req, &link->win);
575 if (i != 0) { 569 if (i != 0)
576 cs_error(link, RequestWindow, i);
577 return -1; 570 return -1;
578 }
579 571
580 base = ioremap(req.Base, req.Size); 572 base = ioremap(req.Base, req.Size);
581 mem.Page = 0; 573 mem.Page = 0;
582 mem.CardOffset = 0; 574 mem.CardOffset = 0;
583 pcmcia_map_mem_page(link->win, &mem); 575 pcmcia_map_mem_page(link, link->win, &mem);
584 576
585 /* 577 /*
586 * MBH10304 CISTPL_FUNCE_LAN_NODE_ID format 578 * MBH10304 CISTPL_FUNCE_LAN_NODE_ID format
@@ -605,9 +597,7 @@ static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
605 } 597 }
606 598
607 iounmap(base); 599 iounmap(base);
608 j = pcmcia_release_window(link->win); 600 j = pcmcia_release_window(link, link->win);
609 if (j != 0)
610 cs_error(link, ReleaseWindow, j);
611 return (i != 0x200) ? 0 : -1; 601 return (i != 0x200) ? 0 : -1;
612 602
613} /* fmvj18x_get_hwinfo */ 603} /* fmvj18x_get_hwinfo */
@@ -626,11 +616,9 @@ static int fmvj18x_setup_mfc(struct pcmcia_device *link)
626 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 616 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
627 req.Base = 0; req.Size = 0; 617 req.Base = 0; req.Size = 0;
628 req.AccessSpeed = 0; 618 req.AccessSpeed = 0;
629 i = pcmcia_request_window(&link, &req, &link->win); 619 i = pcmcia_request_window(link, &req, &link->win);
630 if (i != 0) { 620 if (i != 0)
631 cs_error(link, RequestWindow, i);
632 return -1; 621 return -1;
633 }
634 622
635 lp->base = ioremap(req.Base, req.Size); 623 lp->base = ioremap(req.Base, req.Size);
636 if (lp->base == NULL) { 624 if (lp->base == NULL) {
@@ -640,11 +628,10 @@ static int fmvj18x_setup_mfc(struct pcmcia_device *link)
640 628
641 mem.Page = 0; 629 mem.Page = 0;
642 mem.CardOffset = 0; 630 mem.CardOffset = 0;
643 i = pcmcia_map_mem_page(link->win, &mem); 631 i = pcmcia_map_mem_page(link, link->win, &mem);
644 if (i != 0) { 632 if (i != 0) {
645 iounmap(lp->base); 633 iounmap(lp->base);
646 lp->base = NULL; 634 lp->base = NULL;
647 cs_error(link, MapMemPage, i);
648 return -1; 635 return -1;
649 } 636 }
650 637
@@ -671,15 +658,13 @@ static void fmvj18x_release(struct pcmcia_device *link)
671 u_char __iomem *tmp; 658 u_char __iomem *tmp;
672 int j; 659 int j;
673 660
674 DEBUG(0, "fmvj18x_release(0x%p)\n", link); 661 dev_dbg(&link->dev, "fmvj18x_release\n");
675 662
676 if (lp->base != NULL) { 663 if (lp->base != NULL) {
677 tmp = lp->base; 664 tmp = lp->base;
678 lp->base = NULL; /* set NULL before iounmap */ 665 lp->base = NULL; /* set NULL before iounmap */
679 iounmap(tmp); 666 iounmap(tmp);
680 j = pcmcia_release_window(link->win); 667 j = pcmcia_release_window(link, link->win);
681 if (j != 0)
682 cs_error(link, ReleaseWindow, j);
683 } 668 }
684 669
685 pcmcia_disable_device(link); 670 pcmcia_disable_device(link);
@@ -788,8 +773,8 @@ static irqreturn_t fjn_interrupt(int dummy, void *dev_id)
788 outb(tx_stat, ioaddr + TX_STATUS); 773 outb(tx_stat, ioaddr + TX_STATUS);
789 outb(rx_stat, ioaddr + RX_STATUS); 774 outb(rx_stat, ioaddr + RX_STATUS);
790 775
791 DEBUG(4, "%s: interrupt, rx_status %02x.\n", dev->name, rx_stat); 776 pr_debug("%s: interrupt, rx_status %02x.\n", dev->name, rx_stat);
792 DEBUG(4, " tx_status %02x.\n", tx_stat); 777 pr_debug(" tx_status %02x.\n", tx_stat);
793 778
794 if (rx_stat || (inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) { 779 if (rx_stat || (inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) {
795 /* there is packet(s) in rx buffer */ 780 /* there is packet(s) in rx buffer */
@@ -809,8 +794,8 @@ static irqreturn_t fjn_interrupt(int dummy, void *dev_id)
809 } 794 }
810 netif_wake_queue(dev); 795 netif_wake_queue(dev);
811 } 796 }
812 DEBUG(4, "%s: exiting interrupt,\n", dev->name); 797 pr_debug("%s: exiting interrupt,\n", dev->name);
813 DEBUG(4, " tx_status %02x, rx_status %02x.\n", tx_stat, rx_stat); 798 pr_debug(" tx_status %02x, rx_status %02x.\n", tx_stat, rx_stat);
814 799
815 outb(D_TX_INTR, ioaddr + TX_INTR); 800 outb(D_TX_INTR, ioaddr + TX_INTR);
816 outb(D_RX_INTR, ioaddr + RX_INTR); 801 outb(D_RX_INTR, ioaddr + RX_INTR);
@@ -882,7 +867,7 @@ static netdev_tx_t fjn_start_xmit(struct sk_buff *skb,
882 return NETDEV_TX_BUSY; 867 return NETDEV_TX_BUSY;
883 } 868 }
884 869
885 DEBUG(4, "%s: Transmitting a packet of length %lu.\n", 870 pr_debug("%s: Transmitting a packet of length %lu.\n",
886 dev->name, (unsigned long)skb->len); 871 dev->name, (unsigned long)skb->len);
887 dev->stats.tx_bytes += skb->len; 872 dev->stats.tx_bytes += skb->len;
888 873
@@ -937,7 +922,7 @@ static void fjn_reset(struct net_device *dev)
937 unsigned int ioaddr = dev->base_addr; 922 unsigned int ioaddr = dev->base_addr;
938 int i; 923 int i;
939 924
940 DEBUG(4, "fjn_reset(%s) called.\n",dev->name); 925 pr_debug("fjn_reset(%s) called.\n",dev->name);
941 926
942 /* Reset controller */ 927 /* Reset controller */
943 if( sram_config == 0 ) 928 if( sram_config == 0 )
@@ -1015,13 +1000,13 @@ static void fjn_rx(struct net_device *dev)
1015 unsigned int ioaddr = dev->base_addr; 1000 unsigned int ioaddr = dev->base_addr;
1016 int boguscount = 10; /* 5 -> 10: by agy 19940922 */ 1001 int boguscount = 10; /* 5 -> 10: by agy 19940922 */
1017 1002
1018 DEBUG(4, "%s: in rx_packet(), rx_status %02x.\n", 1003 pr_debug("%s: in rx_packet(), rx_status %02x.\n",
1019 dev->name, inb(ioaddr + RX_STATUS)); 1004 dev->name, inb(ioaddr + RX_STATUS));
1020 1005
1021 while ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) { 1006 while ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) {
1022 u_short status = inw(ioaddr + DATAPORT); 1007 u_short status = inw(ioaddr + DATAPORT);
1023 1008
1024 DEBUG(4, "%s: Rxing packet mode %02x status %04x.\n", 1009 pr_debug("%s: Rxing packet mode %02x status %04x.\n",
1025 dev->name, inb(ioaddr + RX_MODE), status); 1010 dev->name, inb(ioaddr + RX_MODE), status);
1026#ifndef final_version 1011#ifndef final_version
1027 if (status == 0) { 1012 if (status == 0) {
@@ -1061,16 +1046,14 @@ static void fjn_rx(struct net_device *dev)
1061 (pkt_len + 1) >> 1); 1046 (pkt_len + 1) >> 1);
1062 skb->protocol = eth_type_trans(skb, dev); 1047 skb->protocol = eth_type_trans(skb, dev);
1063 1048
1064#ifdef PCMCIA_DEBUG 1049 {
1065 if (pc_debug > 5) {
1066 int i; 1050 int i;
1067 printk(KERN_DEBUG "%s: Rxed packet of length %d: ", 1051 pr_debug("%s: Rxed packet of length %d: ",
1068 dev->name, pkt_len); 1052 dev->name, pkt_len);
1069 for (i = 0; i < 14; i++) 1053 for (i = 0; i < 14; i++)
1070 printk(" %02x", skb->data[i]); 1054 pr_debug(" %02x", skb->data[i]);
1071 printk(".\n"); 1055 pr_debug(".\n");
1072 } 1056 }
1073#endif
1074 1057
1075 netif_rx(skb); 1058 netif_rx(skb);
1076 dev->stats.rx_packets++; 1059 dev->stats.rx_packets++;
@@ -1094,7 +1077,7 @@ static void fjn_rx(struct net_device *dev)
1094 } 1077 }
1095 1078
1096 if (i > 0) 1079 if (i > 0)
1097 DEBUG(5, "%s: Exint Rx packet with mode %02x after " 1080 pr_debug("%s: Exint Rx packet with mode %02x after "
1098 "%d ticks.\n", dev->name, inb(ioaddr + RX_MODE), i); 1081 "%d ticks.\n", dev->name, inb(ioaddr + RX_MODE), i);
1099 } 1082 }
1100*/ 1083*/
@@ -1112,24 +1095,8 @@ static void netdev_get_drvinfo(struct net_device *dev,
1112 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr); 1095 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
1113} 1096}
1114 1097
1115#ifdef PCMCIA_DEBUG
1116static u32 netdev_get_msglevel(struct net_device *dev)
1117{
1118 return pc_debug;
1119}
1120
1121static void netdev_set_msglevel(struct net_device *dev, u32 level)
1122{
1123 pc_debug = level;
1124}
1125#endif /* PCMCIA_DEBUG */
1126
1127static const struct ethtool_ops netdev_ethtool_ops = { 1098static const struct ethtool_ops netdev_ethtool_ops = {
1128 .get_drvinfo = netdev_get_drvinfo, 1099 .get_drvinfo = netdev_get_drvinfo,
1129#ifdef PCMCIA_DEBUG
1130 .get_msglevel = netdev_get_msglevel,
1131 .set_msglevel = netdev_set_msglevel,
1132#endif /* PCMCIA_DEBUG */
1133}; 1100};
1134 1101
1135static int fjn_config(struct net_device *dev, struct ifmap *map){ 1102static int fjn_config(struct net_device *dev, struct ifmap *map){
@@ -1141,7 +1108,7 @@ static int fjn_open(struct net_device *dev)
1141 struct local_info_t *lp = netdev_priv(dev); 1108 struct local_info_t *lp = netdev_priv(dev);
1142 struct pcmcia_device *link = lp->p_dev; 1109 struct pcmcia_device *link = lp->p_dev;
1143 1110
1144 DEBUG(4, "fjn_open('%s').\n", dev->name); 1111 pr_debug("fjn_open('%s').\n", dev->name);
1145 1112
1146 if (!pcmcia_dev_present(link)) 1113 if (!pcmcia_dev_present(link))
1147 return -ENODEV; 1114 return -ENODEV;
@@ -1167,7 +1134,7 @@ static int fjn_close(struct net_device *dev)
1167 struct pcmcia_device *link = lp->p_dev; 1134 struct pcmcia_device *link = lp->p_dev;
1168 unsigned int ioaddr = dev->base_addr; 1135 unsigned int ioaddr = dev->base_addr;
1169 1136
1170 DEBUG(4, "fjn_close('%s').\n", dev->name); 1137 pr_debug("fjn_close('%s').\n", dev->name);
1171 1138
1172 lp->open_time = 0; 1139 lp->open_time = 0;
1173 netif_stop_queue(dev); 1140 netif_stop_queue(dev);
diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c
index 06618af1a468..37f4a6fdc3ef 100644
--- a/drivers/net/pcmcia/ibmtr_cs.c
+++ b/drivers/net/pcmcia/ibmtr_cs.c
@@ -69,17 +69,6 @@
69#define PCMCIA 69#define PCMCIA
70#include "../tokenring/ibmtr.c" 70#include "../tokenring/ibmtr.c"
71 71
72#ifdef PCMCIA_DEBUG
73static int pc_debug = PCMCIA_DEBUG;
74module_param(pc_debug, int, 0);
75#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
76static char *version =
77"ibmtr_cs.c 1.10 1996/01/06 05:19:00 (Steve Kipisz)\n"
78" 2.2.7 1999/05/03 12:00:00 (Mike Phillips)\n"
79" 2.4.2 2001/30/28 Midnight (Burt Silverman)\n";
80#else
81#define DEBUG(n, args...)
82#endif
83 72
84/*====================================================================*/ 73/*====================================================================*/
85 74
@@ -130,6 +119,12 @@ static const struct ethtool_ops netdev_ethtool_ops = {
130 .get_drvinfo = netdev_get_drvinfo, 119 .get_drvinfo = netdev_get_drvinfo,
131}; 120};
132 121
122static irqreturn_t ibmtr_interrupt(int irq, void *dev_id) {
123 ibmtr_dev_t *info = dev_id;
124 struct net_device *dev = info->dev;
125 return tok_interrupt(irq, dev);
126};
127
133/*====================================================================== 128/*======================================================================
134 129
135 ibmtr_attach() creates an "instance" of the driver, allocating 130 ibmtr_attach() creates an "instance" of the driver, allocating
@@ -143,7 +138,7 @@ static int __devinit ibmtr_attach(struct pcmcia_device *link)
143 ibmtr_dev_t *info; 138 ibmtr_dev_t *info;
144 struct net_device *dev; 139 struct net_device *dev;
145 140
146 DEBUG(0, "ibmtr_attach()\n"); 141 dev_dbg(&link->dev, "ibmtr_attach()\n");
147 142
148 /* Create new token-ring device */ 143 /* Create new token-ring device */
149 info = kzalloc(sizeof(*info), GFP_KERNEL); 144 info = kzalloc(sizeof(*info), GFP_KERNEL);
@@ -161,14 +156,13 @@ static int __devinit ibmtr_attach(struct pcmcia_device *link)
161 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 156 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
162 link->io.NumPorts1 = 4; 157 link->io.NumPorts1 = 4;
163 link->io.IOAddrLines = 16; 158 link->io.IOAddrLines = 16;
164 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; 159 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
165 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 160 link->irq.Handler = ibmtr_interrupt;
166 link->irq.Handler = &tok_interrupt;
167 link->conf.Attributes = CONF_ENABLE_IRQ; 161 link->conf.Attributes = CONF_ENABLE_IRQ;
168 link->conf.IntType = INT_MEMORY_AND_IO; 162 link->conf.IntType = INT_MEMORY_AND_IO;
169 link->conf.Present = PRESENT_OPTION; 163 link->conf.Present = PRESENT_OPTION;
170 164
171 link->irq.Instance = info->dev = dev; 165 info->dev = dev;
172 166
173 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 167 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
174 168
@@ -190,7 +184,7 @@ static void ibmtr_detach(struct pcmcia_device *link)
190 struct net_device *dev = info->dev; 184 struct net_device *dev = info->dev;
191 struct tok_info *ti = netdev_priv(dev); 185 struct tok_info *ti = netdev_priv(dev);
192 186
193 DEBUG(0, "ibmtr_detach(0x%p)\n", link); 187 dev_dbg(&link->dev, "ibmtr_detach\n");
194 188
195 /* 189 /*
196 * When the card removal interrupt hits tok_interrupt(), 190 * When the card removal interrupt hits tok_interrupt(),
@@ -217,9 +211,6 @@ static void ibmtr_detach(struct pcmcia_device *link)
217 211
218======================================================================*/ 212======================================================================*/
219 213
220#define CS_CHECK(fn, ret) \
221do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
222
223static int __devinit ibmtr_config(struct pcmcia_device *link) 214static int __devinit ibmtr_config(struct pcmcia_device *link)
224{ 215{
225 ibmtr_dev_t *info = link->priv; 216 ibmtr_dev_t *info = link->priv;
@@ -227,9 +218,9 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
227 struct tok_info *ti = netdev_priv(dev); 218 struct tok_info *ti = netdev_priv(dev);
228 win_req_t req; 219 win_req_t req;
229 memreq_t mem; 220 memreq_t mem;
230 int i, last_ret, last_fn; 221 int i, ret;
231 222
232 DEBUG(0, "ibmtr_config(0x%p)\n", link); 223 dev_dbg(&link->dev, "ibmtr_config\n");
233 224
234 link->conf.ConfigIndex = 0x61; 225 link->conf.ConfigIndex = 0x61;
235 226
@@ -241,11 +232,15 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
241 if (i != 0) { 232 if (i != 0) {
242 /* Couldn't get 0xA20-0xA23. Try ALTERNATE at 0xA24-0xA27. */ 233 /* Couldn't get 0xA20-0xA23. Try ALTERNATE at 0xA24-0xA27. */
243 link->io.BasePort1 = 0xA24; 234 link->io.BasePort1 = 0xA24;
244 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io)); 235 ret = pcmcia_request_io(link, &link->io);
236 if (ret)
237 goto failed;
245 } 238 }
246 dev->base_addr = link->io.BasePort1; 239 dev->base_addr = link->io.BasePort1;
247 240
248 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 241 ret = pcmcia_request_irq(link, &link->irq);
242 if (ret)
243 goto failed;
249 dev->irq = link->irq.AssignedIRQ; 244 dev->irq = link->irq.AssignedIRQ;
250 ti->irq = link->irq.AssignedIRQ; 245 ti->irq = link->irq.AssignedIRQ;
251 ti->global_int_enable=GLOBAL_INT_ENABLE+((dev->irq==9) ? 2 : dev->irq); 246 ti->global_int_enable=GLOBAL_INT_ENABLE+((dev->irq==9) ? 2 : dev->irq);
@@ -256,11 +251,15 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
256 req.Base = 0; 251 req.Base = 0;
257 req.Size = 0x2000; 252 req.Size = 0x2000;
258 req.AccessSpeed = 250; 253 req.AccessSpeed = 250;
259 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win)); 254 ret = pcmcia_request_window(link, &req, &link->win);
255 if (ret)
256 goto failed;
260 257
261 mem.CardOffset = mmiobase; 258 mem.CardOffset = mmiobase;
262 mem.Page = 0; 259 mem.Page = 0;
263 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem)); 260 ret = pcmcia_map_mem_page(link, link->win, &mem);
261 if (ret)
262 goto failed;
264 ti->mmio = ioremap(req.Base, req.Size); 263 ti->mmio = ioremap(req.Base, req.Size);
265 264
266 /* Allocate the SRAM memory window */ 265 /* Allocate the SRAM memory window */
@@ -269,17 +268,23 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
269 req.Base = 0; 268 req.Base = 0;
270 req.Size = sramsize * 1024; 269 req.Size = sramsize * 1024;
271 req.AccessSpeed = 250; 270 req.AccessSpeed = 250;
272 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &info->sram_win_handle)); 271 ret = pcmcia_request_window(link, &req, &info->sram_win_handle);
272 if (ret)
273 goto failed;
273 274
274 mem.CardOffset = srambase; 275 mem.CardOffset = srambase;
275 mem.Page = 0; 276 mem.Page = 0;
276 CS_CHECK(MapMemPage, pcmcia_map_mem_page(info->sram_win_handle, &mem)); 277 ret = pcmcia_map_mem_page(link, info->sram_win_handle, &mem);
278 if (ret)
279 goto failed;
277 280
278 ti->sram_base = mem.CardOffset >> 12; 281 ti->sram_base = mem.CardOffset >> 12;
279 ti->sram_virt = ioremap(req.Base, req.Size); 282 ti->sram_virt = ioremap(req.Base, req.Size);
280 ti->sram_phys = req.Base; 283 ti->sram_phys = req.Base;
281 284
282 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 285 ret = pcmcia_request_configuration(link, &link->conf);
286 if (ret)
287 goto failed;
283 288
284 /* Set up the Token-Ring Controller Configuration Register and 289 /* Set up the Token-Ring Controller Configuration Register and
285 turn on the card. Check the "Local Area Network Credit Card 290 turn on the card. Check the "Local Area Network Credit Card
@@ -287,7 +292,7 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
287 ibmtr_hw_setup(dev, mmiobase); 292 ibmtr_hw_setup(dev, mmiobase);
288 293
289 link->dev_node = &info->node; 294 link->dev_node = &info->node;
290 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 295 SET_NETDEV_DEV(dev, &link->dev);
291 296
292 i = ibmtr_probe_card(dev); 297 i = ibmtr_probe_card(dev);
293 if (i != 0) { 298 if (i != 0) {
@@ -305,8 +310,6 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
305 dev->dev_addr); 310 dev->dev_addr);
306 return 0; 311 return 0;
307 312
308cs_failed:
309 cs_error(link, last_fn, last_ret);
310failed: 313failed:
311 ibmtr_release(link); 314 ibmtr_release(link);
312 return -ENODEV; 315 return -ENODEV;
@@ -325,12 +328,12 @@ static void ibmtr_release(struct pcmcia_device *link)
325 ibmtr_dev_t *info = link->priv; 328 ibmtr_dev_t *info = link->priv;
326 struct net_device *dev = info->dev; 329 struct net_device *dev = info->dev;
327 330
328 DEBUG(0, "ibmtr_release(0x%p)\n", link); 331 dev_dbg(&link->dev, "ibmtr_release\n");
329 332
330 if (link->win) { 333 if (link->win) {
331 struct tok_info *ti = netdev_priv(dev); 334 struct tok_info *ti = netdev_priv(dev);
332 iounmap(ti->mmio); 335 iounmap(ti->mmio);
333 pcmcia_release_window(info->sram_win_handle); 336 pcmcia_release_window(link, info->sram_win_handle);
334 } 337 }
335 pcmcia_disable_device(link); 338 pcmcia_disable_device(link);
336} 339}
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c
index 5ed6339c52bc..dae5ef6b2609 100644
--- a/drivers/net/pcmcia/nmclan_cs.c
+++ b/drivers/net/pcmcia/nmclan_cs.c
@@ -381,13 +381,6 @@ typedef struct _mace_private {
381Private Global Variables 381Private Global Variables
382---------------------------------------------------------------------------- */ 382---------------------------------------------------------------------------- */
383 383
384#ifdef PCMCIA_DEBUG
385static char rcsid[] =
386"nmclan_cs.c,v 0.16 1995/07/01 06:42:17 rpao Exp rpao";
387static char *version =
388DRV_NAME " " DRV_VERSION " (Roger C. Pao)";
389#endif
390
391static const char *if_names[]={ 384static const char *if_names[]={
392 "Auto", "10baseT", "BNC", 385 "Auto", "10baseT", "BNC",
393}; 386};
@@ -406,12 +399,6 @@ MODULE_LICENSE("GPL");
406/* 0=auto, 1=10baseT, 2 = 10base2, default=auto */ 399/* 0=auto, 1=10baseT, 2 = 10base2, default=auto */
407INT_MODULE_PARM(if_port, 0); 400INT_MODULE_PARM(if_port, 0);
408 401
409#ifdef PCMCIA_DEBUG
410INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
411#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
412#else
413#define DEBUG(n, args...)
414#endif
415 402
416/* ---------------------------------------------------------------------------- 403/* ----------------------------------------------------------------------------
417Function Prototypes 404Function Prototypes
@@ -462,8 +449,7 @@ static int nmclan_probe(struct pcmcia_device *link)
462 mace_private *lp; 449 mace_private *lp;
463 struct net_device *dev; 450 struct net_device *dev;
464 451
465 DEBUG(0, "nmclan_attach()\n"); 452 dev_dbg(&link->dev, "nmclan_attach()\n");
466 DEBUG(1, "%s\n", rcsid);
467 453
468 /* Create new ethernet device */ 454 /* Create new ethernet device */
469 dev = alloc_etherdev(sizeof(mace_private)); 455 dev = alloc_etherdev(sizeof(mace_private));
@@ -477,10 +463,8 @@ static int nmclan_probe(struct pcmcia_device *link)
477 link->io.NumPorts1 = 32; 463 link->io.NumPorts1 = 32;
478 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 464 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
479 link->io.IOAddrLines = 5; 465 link->io.IOAddrLines = 5;
480 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; 466 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
481 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
482 link->irq.Handler = &mace_interrupt; 467 link->irq.Handler = &mace_interrupt;
483 link->irq.Instance = dev;
484 link->conf.Attributes = CONF_ENABLE_IRQ; 468 link->conf.Attributes = CONF_ENABLE_IRQ;
485 link->conf.IntType = INT_MEMORY_AND_IO; 469 link->conf.IntType = INT_MEMORY_AND_IO;
486 link->conf.ConfigIndex = 1; 470 link->conf.ConfigIndex = 1;
@@ -507,7 +491,7 @@ static void nmclan_detach(struct pcmcia_device *link)
507{ 491{
508 struct net_device *dev = link->priv; 492 struct net_device *dev = link->priv;
509 493
510 DEBUG(0, "nmclan_detach(0x%p)\n", link); 494 dev_dbg(&link->dev, "nmclan_detach\n");
511 495
512 if (link->dev_node) 496 if (link->dev_node)
513 unregister_netdev(dev); 497 unregister_netdev(dev);
@@ -654,37 +638,40 @@ nmclan_config
654 ethernet device available to the system. 638 ethernet device available to the system.
655---------------------------------------------------------------------------- */ 639---------------------------------------------------------------------------- */
656 640
657#define CS_CHECK(fn, ret) \
658 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
659
660static int nmclan_config(struct pcmcia_device *link) 641static int nmclan_config(struct pcmcia_device *link)
661{ 642{
662 struct net_device *dev = link->priv; 643 struct net_device *dev = link->priv;
663 mace_private *lp = netdev_priv(dev); 644 mace_private *lp = netdev_priv(dev);
664 tuple_t tuple; 645 u8 *buf;
665 u_char buf[64]; 646 size_t len;
666 int i, last_ret, last_fn; 647 int i, ret;
667 unsigned int ioaddr; 648 unsigned int ioaddr;
668 649
669 DEBUG(0, "nmclan_config(0x%p)\n", link); 650 dev_dbg(&link->dev, "nmclan_config\n");
651
652 ret = pcmcia_request_io(link, &link->io);
653 if (ret)
654 goto failed;
655 ret = pcmcia_request_irq(link, &link->irq);
656 if (ret)
657 goto failed;
658 ret = pcmcia_request_configuration(link, &link->conf);
659 if (ret)
660 goto failed;
670 661
671 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
672 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
673 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
674 dev->irq = link->irq.AssignedIRQ; 662 dev->irq = link->irq.AssignedIRQ;
675 dev->base_addr = link->io.BasePort1; 663 dev->base_addr = link->io.BasePort1;
676 664
677 ioaddr = dev->base_addr; 665 ioaddr = dev->base_addr;
678 666
679 /* Read the ethernet address from the CIS. */ 667 /* Read the ethernet address from the CIS. */
680 tuple.DesiredTuple = 0x80 /* CISTPL_CFTABLE_ENTRY_MISC */; 668 len = pcmcia_get_tuple(link, 0x80, &buf);
681 tuple.TupleData = buf; 669 if (!buf || len < ETHER_ADDR_LEN) {
682 tuple.TupleDataMax = 64; 670 kfree(buf);
683 tuple.TupleOffset = 0; 671 goto failed;
684 tuple.Attributes = 0; 672 }
685 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); 673 memcpy(dev->dev_addr, buf, ETHER_ADDR_LEN);
686 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); 674 kfree(buf);
687 memcpy(dev->dev_addr, tuple.TupleData, ETHER_ADDR_LEN);
688 675
689 /* Verify configuration by reading the MACE ID. */ 676 /* Verify configuration by reading the MACE ID. */
690 { 677 {
@@ -693,7 +680,7 @@ static int nmclan_config(struct pcmcia_device *link)
693 sig[0] = mace_read(lp, ioaddr, MACE_CHIPIDL); 680 sig[0] = mace_read(lp, ioaddr, MACE_CHIPIDL);
694 sig[1] = mace_read(lp, ioaddr, MACE_CHIPIDH); 681 sig[1] = mace_read(lp, ioaddr, MACE_CHIPIDH);
695 if ((sig[0] == 0x40) && ((sig[1] & 0x0F) == 0x09)) { 682 if ((sig[0] == 0x40) && ((sig[1] & 0x0F) == 0x09)) {
696 DEBUG(0, "nmclan_cs configured: mace id=%x %x\n", 683 dev_dbg(&link->dev, "nmclan_cs configured: mace id=%x %x\n",
697 sig[0], sig[1]); 684 sig[0], sig[1]);
698 } else { 685 } else {
699 printk(KERN_NOTICE "nmclan_cs: mace id not found: %x %x should" 686 printk(KERN_NOTICE "nmclan_cs: mace id not found: %x %x should"
@@ -712,7 +699,7 @@ static int nmclan_config(struct pcmcia_device *link)
712 printk(KERN_NOTICE "nmclan_cs: invalid if_port requested\n"); 699 printk(KERN_NOTICE "nmclan_cs: invalid if_port requested\n");
713 700
714 link->dev_node = &lp->node; 701 link->dev_node = &lp->node;
715 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 702 SET_NETDEV_DEV(dev, &link->dev);
716 703
717 i = register_netdev(dev); 704 i = register_netdev(dev);
718 if (i != 0) { 705 if (i != 0) {
@@ -729,8 +716,6 @@ static int nmclan_config(struct pcmcia_device *link)
729 dev->dev_addr); 716 dev->dev_addr);
730 return 0; 717 return 0;
731 718
732cs_failed:
733 cs_error(link, last_fn, last_ret);
734failed: 719failed:
735 nmclan_release(link); 720 nmclan_release(link);
736 return -ENODEV; 721 return -ENODEV;
@@ -744,7 +729,7 @@ nmclan_release
744---------------------------------------------------------------------------- */ 729---------------------------------------------------------------------------- */
745static void nmclan_release(struct pcmcia_device *link) 730static void nmclan_release(struct pcmcia_device *link)
746{ 731{
747 DEBUG(0, "nmclan_release(0x%p)\n", link); 732 dev_dbg(&link->dev, "nmclan_release\n");
748 pcmcia_disable_device(link); 733 pcmcia_disable_device(link);
749} 734}
750 735
@@ -795,7 +780,7 @@ static void nmclan_reset(struct net_device *dev)
795 /* Reset Xilinx */ 780 /* Reset Xilinx */
796 reg.Action = CS_WRITE; 781 reg.Action = CS_WRITE;
797 reg.Offset = CISREG_COR; 782 reg.Offset = CISREG_COR;
798 DEBUG(1, "nmclan_reset: OrigCorValue=0x%lX, resetting...\n", 783 dev_dbg(&link->dev, "nmclan_reset: OrigCorValue=0x%lX, resetting...\n",
799 OrigCorValue); 784 OrigCorValue);
800 reg.Value = COR_SOFT_RESET; 785 reg.Value = COR_SOFT_RESET;
801 pcmcia_access_configuration_register(link, &reg); 786 pcmcia_access_configuration_register(link, &reg);
@@ -872,7 +857,7 @@ static int mace_close(struct net_device *dev)
872 mace_private *lp = netdev_priv(dev); 857 mace_private *lp = netdev_priv(dev);
873 struct pcmcia_device *link = lp->p_dev; 858 struct pcmcia_device *link = lp->p_dev;
874 859
875 DEBUG(2, "%s: shutting down ethercard.\n", dev->name); 860 dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
876 861
877 /* Mask off all interrupts from the MACE chip. */ 862 /* Mask off all interrupts from the MACE chip. */
878 outb(0xFF, ioaddr + AM2150_MACE_BASE + MACE_IMR); 863 outb(0xFF, ioaddr + AM2150_MACE_BASE + MACE_IMR);
@@ -891,24 +876,8 @@ static void netdev_get_drvinfo(struct net_device *dev,
891 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr); 876 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
892} 877}
893 878
894#ifdef PCMCIA_DEBUG
895static u32 netdev_get_msglevel(struct net_device *dev)
896{
897 return pc_debug;
898}
899
900static void netdev_set_msglevel(struct net_device *dev, u32 level)
901{
902 pc_debug = level;
903}
904#endif /* PCMCIA_DEBUG */
905
906static const struct ethtool_ops netdev_ethtool_ops = { 879static const struct ethtool_ops netdev_ethtool_ops = {
907 .get_drvinfo = netdev_get_drvinfo, 880 .get_drvinfo = netdev_get_drvinfo,
908#ifdef PCMCIA_DEBUG
909 .get_msglevel = netdev_get_msglevel,
910 .set_msglevel = netdev_set_msglevel,
911#endif /* PCMCIA_DEBUG */
912}; 881};
913 882
914/* ---------------------------------------------------------------------------- 883/* ----------------------------------------------------------------------------
@@ -946,7 +915,7 @@ static netdev_tx_t mace_start_xmit(struct sk_buff *skb,
946 915
947 netif_stop_queue(dev); 916 netif_stop_queue(dev);
948 917
949 DEBUG(3, "%s: mace_start_xmit(length = %ld) called.\n", 918 pr_debug("%s: mace_start_xmit(length = %ld) called.\n",
950 dev->name, (long)skb->len); 919 dev->name, (long)skb->len);
951 920
952#if (!TX_INTERRUPTABLE) 921#if (!TX_INTERRUPTABLE)
@@ -1008,7 +977,7 @@ static irqreturn_t mace_interrupt(int irq, void *dev_id)
1008 int IntrCnt = MACE_MAX_IR_ITERATIONS; 977 int IntrCnt = MACE_MAX_IR_ITERATIONS;
1009 978
1010 if (dev == NULL) { 979 if (dev == NULL) {
1011 DEBUG(2, "mace_interrupt(): irq 0x%X for unknown device.\n", 980 pr_debug("mace_interrupt(): irq 0x%X for unknown device.\n",
1012 irq); 981 irq);
1013 return IRQ_NONE; 982 return IRQ_NONE;
1014 } 983 }
@@ -1031,7 +1000,7 @@ static irqreturn_t mace_interrupt(int irq, void *dev_id)
1031 } 1000 }
1032 1001
1033 if (!netif_device_present(dev)) { 1002 if (!netif_device_present(dev)) {
1034 DEBUG(2, "%s: interrupt from dead card\n", dev->name); 1003 pr_debug("%s: interrupt from dead card\n", dev->name);
1035 return IRQ_NONE; 1004 return IRQ_NONE;
1036 } 1005 }
1037 1006
@@ -1039,7 +1008,7 @@ static irqreturn_t mace_interrupt(int irq, void *dev_id)
1039 /* WARNING: MACE_IR is a READ/CLEAR port! */ 1008 /* WARNING: MACE_IR is a READ/CLEAR port! */
1040 status = inb(ioaddr + AM2150_MACE_BASE + MACE_IR); 1009 status = inb(ioaddr + AM2150_MACE_BASE + MACE_IR);
1041 1010
1042 DEBUG(3, "mace_interrupt: irq 0x%X status 0x%X.\n", irq, status); 1011 pr_debug("mace_interrupt: irq 0x%X status 0x%X.\n", irq, status);
1043 1012
1044 if (status & MACE_IR_RCVINT) { 1013 if (status & MACE_IR_RCVINT) {
1045 mace_rx(dev, MACE_MAX_RX_ITERATIONS); 1014 mace_rx(dev, MACE_MAX_RX_ITERATIONS);
@@ -1158,7 +1127,7 @@ static int mace_rx(struct net_device *dev, unsigned char RxCnt)
1158 ) { 1127 ) {
1159 rx_status = inw(ioaddr + AM2150_RCV); 1128 rx_status = inw(ioaddr + AM2150_RCV);
1160 1129
1161 DEBUG(3, "%s: in mace_rx(), framecnt 0x%X, rx_status" 1130 pr_debug("%s: in mace_rx(), framecnt 0x%X, rx_status"
1162 " 0x%X.\n", dev->name, rx_framecnt, rx_status); 1131 " 0x%X.\n", dev->name, rx_framecnt, rx_status);
1163 1132
1164 if (rx_status & MACE_RCVFS_RCVSTS) { /* Error, update stats. */ 1133 if (rx_status & MACE_RCVFS_RCVSTS) { /* Error, update stats. */
@@ -1185,7 +1154,7 @@ static int mace_rx(struct net_device *dev, unsigned char RxCnt)
1185 lp->mace_stats.rfs_rcvcc += inb(ioaddr + AM2150_RCV); 1154 lp->mace_stats.rfs_rcvcc += inb(ioaddr + AM2150_RCV);
1186 /* rcv collision count */ 1155 /* rcv collision count */
1187 1156
1188 DEBUG(3, " receiving packet size 0x%X rx_status" 1157 pr_debug(" receiving packet size 0x%X rx_status"
1189 " 0x%X.\n", pkt_len, rx_status); 1158 " 0x%X.\n", pkt_len, rx_status);
1190 1159
1191 skb = dev_alloc_skb(pkt_len+2); 1160 skb = dev_alloc_skb(pkt_len+2);
@@ -1204,7 +1173,7 @@ static int mace_rx(struct net_device *dev, unsigned char RxCnt)
1204 outb(0xFF, ioaddr + AM2150_RCV_NEXT); /* skip to next frame */ 1173 outb(0xFF, ioaddr + AM2150_RCV_NEXT); /* skip to next frame */
1205 continue; 1174 continue;
1206 } else { 1175 } else {
1207 DEBUG(1, "%s: couldn't allocate a sk_buff of size" 1176 pr_debug("%s: couldn't allocate a sk_buff of size"
1208 " %d.\n", dev->name, pkt_len); 1177 " %d.\n", dev->name, pkt_len);
1209 lp->linux_stats.rx_dropped++; 1178 lp->linux_stats.rx_dropped++;
1210 } 1179 }
@@ -1220,28 +1189,28 @@ pr_linux_stats
1220---------------------------------------------------------------------------- */ 1189---------------------------------------------------------------------------- */
1221static void pr_linux_stats(struct net_device_stats *pstats) 1190static void pr_linux_stats(struct net_device_stats *pstats)
1222{ 1191{
1223 DEBUG(2, "pr_linux_stats\n"); 1192 pr_debug("pr_linux_stats\n");
1224 DEBUG(2, " rx_packets=%-7ld tx_packets=%ld\n", 1193 pr_debug(" rx_packets=%-7ld tx_packets=%ld\n",
1225 (long)pstats->rx_packets, (long)pstats->tx_packets); 1194 (long)pstats->rx_packets, (long)pstats->tx_packets);
1226 DEBUG(2, " rx_errors=%-7ld tx_errors=%ld\n", 1195 pr_debug(" rx_errors=%-7ld tx_errors=%ld\n",
1227 (long)pstats->rx_errors, (long)pstats->tx_errors); 1196 (long)pstats->rx_errors, (long)pstats->tx_errors);
1228 DEBUG(2, " rx_dropped=%-7ld tx_dropped=%ld\n", 1197 pr_debug(" rx_dropped=%-7ld tx_dropped=%ld\n",
1229 (long)pstats->rx_dropped, (long)pstats->tx_dropped); 1198 (long)pstats->rx_dropped, (long)pstats->tx_dropped);
1230 DEBUG(2, " multicast=%-7ld collisions=%ld\n", 1199 pr_debug(" multicast=%-7ld collisions=%ld\n",
1231 (long)pstats->multicast, (long)pstats->collisions); 1200 (long)pstats->multicast, (long)pstats->collisions);
1232 1201
1233 DEBUG(2, " rx_length_errors=%-7ld rx_over_errors=%ld\n", 1202 pr_debug(" rx_length_errors=%-7ld rx_over_errors=%ld\n",
1234 (long)pstats->rx_length_errors, (long)pstats->rx_over_errors); 1203 (long)pstats->rx_length_errors, (long)pstats->rx_over_errors);
1235 DEBUG(2, " rx_crc_errors=%-7ld rx_frame_errors=%ld\n", 1204 pr_debug(" rx_crc_errors=%-7ld rx_frame_errors=%ld\n",
1236 (long)pstats->rx_crc_errors, (long)pstats->rx_frame_errors); 1205 (long)pstats->rx_crc_errors, (long)pstats->rx_frame_errors);
1237 DEBUG(2, " rx_fifo_errors=%-7ld rx_missed_errors=%ld\n", 1206 pr_debug(" rx_fifo_errors=%-7ld rx_missed_errors=%ld\n",
1238 (long)pstats->rx_fifo_errors, (long)pstats->rx_missed_errors); 1207 (long)pstats->rx_fifo_errors, (long)pstats->rx_missed_errors);
1239 1208
1240 DEBUG(2, " tx_aborted_errors=%-7ld tx_carrier_errors=%ld\n", 1209 pr_debug(" tx_aborted_errors=%-7ld tx_carrier_errors=%ld\n",
1241 (long)pstats->tx_aborted_errors, (long)pstats->tx_carrier_errors); 1210 (long)pstats->tx_aborted_errors, (long)pstats->tx_carrier_errors);
1242 DEBUG(2, " tx_fifo_errors=%-7ld tx_heartbeat_errors=%ld\n", 1211 pr_debug(" tx_fifo_errors=%-7ld tx_heartbeat_errors=%ld\n",
1243 (long)pstats->tx_fifo_errors, (long)pstats->tx_heartbeat_errors); 1212 (long)pstats->tx_fifo_errors, (long)pstats->tx_heartbeat_errors);
1244 DEBUG(2, " tx_window_errors=%ld\n", 1213 pr_debug(" tx_window_errors=%ld\n",
1245 (long)pstats->tx_window_errors); 1214 (long)pstats->tx_window_errors);
1246} /* pr_linux_stats */ 1215} /* pr_linux_stats */
1247 1216
@@ -1250,48 +1219,48 @@ pr_mace_stats
1250---------------------------------------------------------------------------- */ 1219---------------------------------------------------------------------------- */
1251static void pr_mace_stats(mace_statistics *pstats) 1220static void pr_mace_stats(mace_statistics *pstats)
1252{ 1221{
1253 DEBUG(2, "pr_mace_stats\n"); 1222 pr_debug("pr_mace_stats\n");
1254 1223
1255 DEBUG(2, " xmtsv=%-7d uflo=%d\n", 1224 pr_debug(" xmtsv=%-7d uflo=%d\n",
1256 pstats->xmtsv, pstats->uflo); 1225 pstats->xmtsv, pstats->uflo);
1257 DEBUG(2, " lcol=%-7d more=%d\n", 1226 pr_debug(" lcol=%-7d more=%d\n",
1258 pstats->lcol, pstats->more); 1227 pstats->lcol, pstats->more);
1259 DEBUG(2, " one=%-7d defer=%d\n", 1228 pr_debug(" one=%-7d defer=%d\n",
1260 pstats->one, pstats->defer); 1229 pstats->one, pstats->defer);
1261 DEBUG(2, " lcar=%-7d rtry=%d\n", 1230 pr_debug(" lcar=%-7d rtry=%d\n",
1262 pstats->lcar, pstats->rtry); 1231 pstats->lcar, pstats->rtry);
1263 1232
1264 /* MACE_XMTRC */ 1233 /* MACE_XMTRC */
1265 DEBUG(2, " exdef=%-7d xmtrc=%d\n", 1234 pr_debug(" exdef=%-7d xmtrc=%d\n",
1266 pstats->exdef, pstats->xmtrc); 1235 pstats->exdef, pstats->xmtrc);
1267 1236
1268 /* RFS1--Receive Status (RCVSTS) */ 1237 /* RFS1--Receive Status (RCVSTS) */
1269 DEBUG(2, " oflo=%-7d clsn=%d\n", 1238 pr_debug(" oflo=%-7d clsn=%d\n",
1270 pstats->oflo, pstats->clsn); 1239 pstats->oflo, pstats->clsn);
1271 DEBUG(2, " fram=%-7d fcs=%d\n", 1240 pr_debug(" fram=%-7d fcs=%d\n",
1272 pstats->fram, pstats->fcs); 1241 pstats->fram, pstats->fcs);
1273 1242
1274 /* RFS2--Runt Packet Count (RNTPC) */ 1243 /* RFS2--Runt Packet Count (RNTPC) */
1275 /* RFS3--Receive Collision Count (RCVCC) */ 1244 /* RFS3--Receive Collision Count (RCVCC) */
1276 DEBUG(2, " rfs_rntpc=%-7d rfs_rcvcc=%d\n", 1245 pr_debug(" rfs_rntpc=%-7d rfs_rcvcc=%d\n",
1277 pstats->rfs_rntpc, pstats->rfs_rcvcc); 1246 pstats->rfs_rntpc, pstats->rfs_rcvcc);
1278 1247
1279 /* MACE_IR */ 1248 /* MACE_IR */
1280 DEBUG(2, " jab=%-7d babl=%d\n", 1249 pr_debug(" jab=%-7d babl=%d\n",
1281 pstats->jab, pstats->babl); 1250 pstats->jab, pstats->babl);
1282 DEBUG(2, " cerr=%-7d rcvcco=%d\n", 1251 pr_debug(" cerr=%-7d rcvcco=%d\n",
1283 pstats->cerr, pstats->rcvcco); 1252 pstats->cerr, pstats->rcvcco);
1284 DEBUG(2, " rntpco=%-7d mpco=%d\n", 1253 pr_debug(" rntpco=%-7d mpco=%d\n",
1285 pstats->rntpco, pstats->mpco); 1254 pstats->rntpco, pstats->mpco);
1286 1255
1287 /* MACE_MPC */ 1256 /* MACE_MPC */
1288 DEBUG(2, " mpc=%d\n", pstats->mpc); 1257 pr_debug(" mpc=%d\n", pstats->mpc);
1289 1258
1290 /* MACE_RNTPC */ 1259 /* MACE_RNTPC */
1291 DEBUG(2, " rntpc=%d\n", pstats->rntpc); 1260 pr_debug(" rntpc=%d\n", pstats->rntpc);
1292 1261
1293 /* MACE_RCVCC */ 1262 /* MACE_RCVCC */
1294 DEBUG(2, " rcvcc=%d\n", pstats->rcvcc); 1263 pr_debug(" rcvcc=%d\n", pstats->rcvcc);
1295 1264
1296} /* pr_mace_stats */ 1265} /* pr_mace_stats */
1297 1266
@@ -1360,7 +1329,7 @@ static struct net_device_stats *mace_get_stats(struct net_device *dev)
1360 1329
1361 update_stats(dev->base_addr, dev); 1330 update_stats(dev->base_addr, dev);
1362 1331
1363 DEBUG(1, "%s: updating the statistics.\n", dev->name); 1332 pr_debug("%s: updating the statistics.\n", dev->name);
1364 pr_linux_stats(&lp->linux_stats); 1333 pr_linux_stats(&lp->linux_stats);
1365 pr_mace_stats(&lp->mace_stats); 1334 pr_mace_stats(&lp->mace_stats);
1366 1335
@@ -1427,7 +1396,7 @@ static void BuildLAF(int *ladrf, int *adr)
1427 ladrf[byte] |= (1 << (hashcode & 7)); 1396 ladrf[byte] |= (1 << (hashcode & 7));
1428 1397
1429#ifdef PCMCIA_DEBUG 1398#ifdef PCMCIA_DEBUG
1430 if (pc_debug > 2) 1399 if (0)
1431 printk(KERN_DEBUG " adr =%pM\n", adr); 1400 printk(KERN_DEBUG " adr =%pM\n", adr);
1432 printk(KERN_DEBUG " hashcode = %d(decimal), ladrf[0:63] =", hashcode); 1401 printk(KERN_DEBUG " hashcode = %d(decimal), ladrf[0:63] =", hashcode);
1433 for (i = 0; i < 8; i++) 1402 for (i = 0; i < 8; i++)
@@ -1454,12 +1423,12 @@ static void restore_multicast_list(struct net_device *dev)
1454 unsigned int ioaddr = dev->base_addr; 1423 unsigned int ioaddr = dev->base_addr;
1455 int i; 1424 int i;
1456 1425
1457 DEBUG(2, "%s: restoring Rx mode to %d addresses.\n", 1426 pr_debug("%s: restoring Rx mode to %d addresses.\n",
1458 dev->name, num_addrs); 1427 dev->name, num_addrs);
1459 1428
1460 if (num_addrs > 0) { 1429 if (num_addrs > 0) {
1461 1430
1462 DEBUG(1, "Attempt to restore multicast list detected.\n"); 1431 pr_debug("Attempt to restore multicast list detected.\n");
1463 1432
1464 mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_LOGADDR); 1433 mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_LOGADDR);
1465 /* Poll ADDRCHG bit */ 1434 /* Poll ADDRCHG bit */
@@ -1511,11 +1480,11 @@ static void set_multicast_list(struct net_device *dev)
1511 struct dev_mc_list *dmi = dev->mc_list; 1480 struct dev_mc_list *dmi = dev->mc_list;
1512 1481
1513#ifdef PCMCIA_DEBUG 1482#ifdef PCMCIA_DEBUG
1514 if (pc_debug > 1) { 1483 {
1515 static int old; 1484 static int old;
1516 if (dev->mc_count != old) { 1485 if (dev->mc_count != old) {
1517 old = dev->mc_count; 1486 old = dev->mc_count;
1518 DEBUG(0, "%s: setting Rx mode to %d addresses.\n", 1487 pr_debug("%s: setting Rx mode to %d addresses.\n",
1519 dev->name, old); 1488 dev->name, old);
1520 } 1489 }
1521 } 1490 }
@@ -1546,7 +1515,7 @@ static void restore_multicast_list(struct net_device *dev)
1546 unsigned int ioaddr = dev->base_addr; 1515 unsigned int ioaddr = dev->base_addr;
1547 mace_private *lp = netdev_priv(dev); 1516 mace_private *lp = netdev_priv(dev);
1548 1517
1549 DEBUG(2, "%s: restoring Rx mode to %d addresses.\n", dev->name, 1518 pr_debug("%s: restoring Rx mode to %d addresses.\n", dev->name,
1550 lp->multicast_num_addrs); 1519 lp->multicast_num_addrs);
1551 1520
1552 if (dev->flags & IFF_PROMISC) { 1521 if (dev->flags & IFF_PROMISC) {
@@ -1567,11 +1536,11 @@ static void set_multicast_list(struct net_device *dev)
1567 mace_private *lp = netdev_priv(dev); 1536 mace_private *lp = netdev_priv(dev);
1568 1537
1569#ifdef PCMCIA_DEBUG 1538#ifdef PCMCIA_DEBUG
1570 if (pc_debug > 1) { 1539 {
1571 static int old; 1540 static int old;
1572 if (dev->mc_count != old) { 1541 if (dev->mc_count != old) {
1573 old = dev->mc_count; 1542 old = dev->mc_count;
1574 DEBUG(0, "%s: setting Rx mode to %d addresses.\n", 1543 pr_debug("%s: setting Rx mode to %d addresses.\n",
1575 dev->name, old); 1544 dev->name, old);
1576 } 1545 }
1577 } 1546 }
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index bd3447f04902..cbe462ed221f 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -71,15 +71,6 @@
71 71
72static const char *if_names[] = { "auto", "10baseT", "10base2"}; 72static const char *if_names[] = { "auto", "10baseT", "10base2"};
73 73
74#ifdef PCMCIA_DEBUG
75static int pc_debug = PCMCIA_DEBUG;
76module_param(pc_debug, int, 0);
77#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
78static char *version =
79"pcnet_cs.c 1.153 2003/11/09 18:53:09 (David Hinds)";
80#else
81#define DEBUG(n, args...)
82#endif
83 74
84/*====================================================================*/ 75/*====================================================================*/
85 76
@@ -265,7 +256,7 @@ static int pcnet_probe(struct pcmcia_device *link)
265 pcnet_dev_t *info; 256 pcnet_dev_t *info;
266 struct net_device *dev; 257 struct net_device *dev;
267 258
268 DEBUG(0, "pcnet_attach()\n"); 259 dev_dbg(&link->dev, "pcnet_attach()\n");
269 260
270 /* Create new ethernet device */ 261 /* Create new ethernet device */
271 dev = __alloc_ei_netdev(sizeof(pcnet_dev_t)); 262 dev = __alloc_ei_netdev(sizeof(pcnet_dev_t));
@@ -275,7 +266,6 @@ static int pcnet_probe(struct pcmcia_device *link)
275 link->priv = dev; 266 link->priv = dev;
276 267
277 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING; 268 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
278 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
279 link->conf.Attributes = CONF_ENABLE_IRQ; 269 link->conf.Attributes = CONF_ENABLE_IRQ;
280 link->conf.IntType = INT_MEMORY_AND_IO; 270 link->conf.IntType = INT_MEMORY_AND_IO;
281 271
@@ -297,7 +287,7 @@ static void pcnet_detach(struct pcmcia_device *link)
297{ 287{
298 struct net_device *dev = link->priv; 288 struct net_device *dev = link->priv;
299 289
300 DEBUG(0, "pcnet_detach(0x%p)\n", link); 290 dev_dbg(&link->dev, "pcnet_detach\n");
301 291
302 if (link->dev_node) 292 if (link->dev_node)
303 unregister_netdev(dev); 293 unregister_netdev(dev);
@@ -326,17 +316,15 @@ static hw_info_t *get_hwinfo(struct pcmcia_device *link)
326 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 316 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
327 req.Base = 0; req.Size = 0; 317 req.Base = 0; req.Size = 0;
328 req.AccessSpeed = 0; 318 req.AccessSpeed = 0;
329 i = pcmcia_request_window(&link, &req, &link->win); 319 i = pcmcia_request_window(link, &req, &link->win);
330 if (i != 0) { 320 if (i != 0)
331 cs_error(link, RequestWindow, i);
332 return NULL; 321 return NULL;
333 }
334 322
335 virt = ioremap(req.Base, req.Size); 323 virt = ioremap(req.Base, req.Size);
336 mem.Page = 0; 324 mem.Page = 0;
337 for (i = 0; i < NR_INFO; i++) { 325 for (i = 0; i < NR_INFO; i++) {
338 mem.CardOffset = hw_info[i].offset & ~(req.Size-1); 326 mem.CardOffset = hw_info[i].offset & ~(req.Size-1);
339 pcmcia_map_mem_page(link->win, &mem); 327 pcmcia_map_mem_page(link, link->win, &mem);
340 base = &virt[hw_info[i].offset & (req.Size-1)]; 328 base = &virt[hw_info[i].offset & (req.Size-1)];
341 if ((readb(base+0) == hw_info[i].a0) && 329 if ((readb(base+0) == hw_info[i].a0) &&
342 (readb(base+2) == hw_info[i].a1) && 330 (readb(base+2) == hw_info[i].a1) &&
@@ -348,9 +336,7 @@ static hw_info_t *get_hwinfo(struct pcmcia_device *link)
348 } 336 }
349 337
350 iounmap(virt); 338 iounmap(virt);
351 j = pcmcia_release_window(link->win); 339 j = pcmcia_release_window(link, link->win);
352 if (j != 0)
353 cs_error(link, ReleaseWindow, j);
354 return (i < NR_INFO) ? hw_info+i : NULL; 340 return (i < NR_INFO) ? hw_info+i : NULL;
355} /* get_hwinfo */ 341} /* get_hwinfo */
356 342
@@ -495,9 +481,6 @@ static hw_info_t *get_hwired(struct pcmcia_device *link)
495 481
496======================================================================*/ 482======================================================================*/
497 483
498#define CS_CHECK(fn, ret) \
499do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
500
501static int try_io_port(struct pcmcia_device *link) 484static int try_io_port(struct pcmcia_device *link)
502{ 485{
503 int j, ret; 486 int j, ret;
@@ -567,19 +550,19 @@ static int pcnet_config(struct pcmcia_device *link)
567{ 550{
568 struct net_device *dev = link->priv; 551 struct net_device *dev = link->priv;
569 pcnet_dev_t *info = PRIV(dev); 552 pcnet_dev_t *info = PRIV(dev);
570 int last_ret, last_fn, start_pg, stop_pg, cm_offset; 553 int ret, start_pg, stop_pg, cm_offset;
571 int has_shmem = 0; 554 int has_shmem = 0;
572 hw_info_t *local_hw_info; 555 hw_info_t *local_hw_info;
573 556
574 DEBUG(0, "pcnet_config(0x%p)\n", link); 557 dev_dbg(&link->dev, "pcnet_config\n");
575 558
576 last_ret = pcmcia_loop_config(link, pcnet_confcheck, &has_shmem); 559 ret = pcmcia_loop_config(link, pcnet_confcheck, &has_shmem);
577 if (last_ret) { 560 if (ret)
578 cs_error(link, RequestIO, last_ret);
579 goto failed; 561 goto failed;
580 }
581 562
582 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 563 ret = pcmcia_request_irq(link, &link->irq);
564 if (ret)
565 goto failed;
583 566
584 if (link->io.NumPorts2 == 8) { 567 if (link->io.NumPorts2 == 8) {
585 link->conf.Attributes |= CONF_ENABLE_SPKR; 568 link->conf.Attributes |= CONF_ENABLE_SPKR;
@@ -589,7 +572,9 @@ static int pcnet_config(struct pcmcia_device *link)
589 (link->card_id == PRODID_IBM_HOME_AND_AWAY)) 572 (link->card_id == PRODID_IBM_HOME_AND_AWAY))
590 link->conf.ConfigIndex |= 0x10; 573 link->conf.ConfigIndex |= 0x10;
591 574
592 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 575 ret = pcmcia_request_configuration(link, &link->conf);
576 if (ret)
577 goto failed;
593 dev->irq = link->irq.AssignedIRQ; 578 dev->irq = link->irq.AssignedIRQ;
594 dev->base_addr = link->io.BasePort1; 579 dev->base_addr = link->io.BasePort1;
595 if (info->flags & HAS_MISC_REG) { 580 if (info->flags & HAS_MISC_REG) {
@@ -660,7 +645,7 @@ static int pcnet_config(struct pcmcia_device *link)
660 mii_phy_probe(dev); 645 mii_phy_probe(dev);
661 646
662 link->dev_node = &info->node; 647 link->dev_node = &info->node;
663 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 648 SET_NETDEV_DEV(dev, &link->dev);
664 649
665 if (register_netdev(dev) != 0) { 650 if (register_netdev(dev) != 0) {
666 printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n"); 651 printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n");
@@ -687,8 +672,6 @@ static int pcnet_config(struct pcmcia_device *link)
687 printk(" hw_addr %pM\n", dev->dev_addr); 672 printk(" hw_addr %pM\n", dev->dev_addr);
688 return 0; 673 return 0;
689 674
690cs_failed:
691 cs_error(link, last_fn, last_ret);
692failed: 675failed:
693 pcnet_release(link); 676 pcnet_release(link);
694 return -ENODEV; 677 return -ENODEV;
@@ -706,7 +689,7 @@ static void pcnet_release(struct pcmcia_device *link)
706{ 689{
707 pcnet_dev_t *info = PRIV(link->priv); 690 pcnet_dev_t *info = PRIV(link->priv);
708 691
709 DEBUG(0, "pcnet_release(0x%p)\n", link); 692 dev_dbg(&link->dev, "pcnet_release\n");
710 693
711 if (info->flags & USE_SHMEM) 694 if (info->flags & USE_SHMEM)
712 iounmap(info->base); 695 iounmap(info->base);
@@ -960,7 +943,7 @@ static void mii_phy_probe(struct net_device *dev)
960 phyid = tmp << 16; 943 phyid = tmp << 16;
961 phyid |= mdio_read(mii_addr, i, MII_PHYID_REG2); 944 phyid |= mdio_read(mii_addr, i, MII_PHYID_REG2);
962 phyid &= MII_PHYID_REV_MASK; 945 phyid &= MII_PHYID_REV_MASK;
963 DEBUG(0, "%s: MII at %d is 0x%08x\n", dev->name, i, phyid); 946 pr_debug("%s: MII at %d is 0x%08x\n", dev->name, i, phyid);
964 if (phyid == AM79C9XX_HOME_PHY) { 947 if (phyid == AM79C9XX_HOME_PHY) {
965 info->pna_phy = i; 948 info->pna_phy = i;
966 } else if (phyid != AM79C9XX_ETH_PHY) { 949 } else if (phyid != AM79C9XX_ETH_PHY) {
@@ -976,7 +959,7 @@ static int pcnet_open(struct net_device *dev)
976 struct pcmcia_device *link = info->p_dev; 959 struct pcmcia_device *link = info->p_dev;
977 unsigned int nic_base = dev->base_addr; 960 unsigned int nic_base = dev->base_addr;
978 961
979 DEBUG(2, "pcnet_open('%s')\n", dev->name); 962 dev_dbg(&link->dev, "pcnet_open('%s')\n", dev->name);
980 963
981 if (!pcmcia_dev_present(link)) 964 if (!pcmcia_dev_present(link))
982 return -ENODEV; 965 return -ENODEV;
@@ -1008,7 +991,7 @@ static int pcnet_close(struct net_device *dev)
1008 pcnet_dev_t *info = PRIV(dev); 991 pcnet_dev_t *info = PRIV(dev);
1009 struct pcmcia_device *link = info->p_dev; 992 struct pcmcia_device *link = info->p_dev;
1010 993
1011 DEBUG(2, "pcnet_close('%s')\n", dev->name); 994 dev_dbg(&link->dev, "pcnet_close('%s')\n", dev->name);
1012 995
1013 ei_close(dev); 996 ei_close(dev);
1014 free_irq(dev->irq, dev); 997 free_irq(dev->irq, dev);
@@ -1251,10 +1234,8 @@ static void dma_block_input(struct net_device *dev, int count,
1251 int xfer_count = count; 1234 int xfer_count = count;
1252 char *buf = skb->data; 1235 char *buf = skb->data;
1253 1236
1254#ifdef PCMCIA_DEBUG
1255 if ((ei_debug > 4) && (count != 4)) 1237 if ((ei_debug > 4) && (count != 4))
1256 printk(KERN_DEBUG "%s: [bi=%d]\n", dev->name, count+4); 1238 pr_debug("%s: [bi=%d]\n", dev->name, count+4);
1257#endif
1258 if (ei_status.dmaing) { 1239 if (ei_status.dmaing) {
1259 printk(KERN_NOTICE "%s: DMAing conflict in dma_block_input." 1240 printk(KERN_NOTICE "%s: DMAing conflict in dma_block_input."
1260 "[DMAstat:%1x][irqlock:%1x]\n", 1241 "[DMAstat:%1x][irqlock:%1x]\n",
@@ -1495,7 +1476,7 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
1495 pcnet_dev_t *info = PRIV(dev); 1476 pcnet_dev_t *info = PRIV(dev);
1496 win_req_t req; 1477 win_req_t req;
1497 memreq_t mem; 1478 memreq_t mem;
1498 int i, window_size, offset, last_ret, last_fn; 1479 int i, window_size, offset, ret;
1499 1480
1500 window_size = (stop_pg - start_pg) << 8; 1481 window_size = (stop_pg - start_pg) << 8;
1501 if (window_size > 32 * 1024) 1482 if (window_size > 32 * 1024)
@@ -1509,13 +1490,17 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
1509 req.Attributes |= WIN_USE_WAIT; 1490 req.Attributes |= WIN_USE_WAIT;
1510 req.Base = 0; req.Size = window_size; 1491 req.Base = 0; req.Size = window_size;
1511 req.AccessSpeed = mem_speed; 1492 req.AccessSpeed = mem_speed;
1512 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win)); 1493 ret = pcmcia_request_window(link, &req, &link->win);
1494 if (ret)
1495 goto failed;
1513 1496
1514 mem.CardOffset = (start_pg << 8) + cm_offset; 1497 mem.CardOffset = (start_pg << 8) + cm_offset;
1515 offset = mem.CardOffset % window_size; 1498 offset = mem.CardOffset % window_size;
1516 mem.CardOffset -= offset; 1499 mem.CardOffset -= offset;
1517 mem.Page = 0; 1500 mem.Page = 0;
1518 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem)); 1501 ret = pcmcia_map_mem_page(link, link->win, &mem);
1502 if (ret)
1503 goto failed;
1519 1504
1520 /* Try scribbling on the buffer */ 1505 /* Try scribbling on the buffer */
1521 info->base = ioremap(req.Base, window_size); 1506 info->base = ioremap(req.Base, window_size);
@@ -1527,8 +1512,8 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
1527 pcnet_reset_8390(dev); 1512 pcnet_reset_8390(dev);
1528 if (i != (TX_PAGES<<8)) { 1513 if (i != (TX_PAGES<<8)) {
1529 iounmap(info->base); 1514 iounmap(info->base);
1530 pcmcia_release_window(link->win); 1515 pcmcia_release_window(link, link->win);
1531 info->base = NULL; link->win = NULL; 1516 info->base = NULL; link->win = 0;
1532 goto failed; 1517 goto failed;
1533 } 1518 }
1534 1519
@@ -1549,8 +1534,6 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
1549 info->flags |= USE_SHMEM; 1534 info->flags |= USE_SHMEM;
1550 return 0; 1535 return 0;
1551 1536
1552cs_failed:
1553 cs_error(link, last_fn, last_ret);
1554failed: 1537failed:
1555 return 1; 1538 return 1;
1556} 1539}
@@ -1760,7 +1743,7 @@ static struct pcmcia_device_id pcnet_ids[] = {
1760 PCMCIA_DEVICE_CIS_MANF_CARD(0xc00f, 0x0002, "cis/LA-PCM.cis"), 1743 PCMCIA_DEVICE_CIS_MANF_CARD(0xc00f, 0x0002, "cis/LA-PCM.cis"),
1761 PCMCIA_DEVICE_CIS_PROD_ID12("KTI", "PE520 PLUS", 0xad180345, 0x9d58d392, "PE520.cis"), 1744 PCMCIA_DEVICE_CIS_PROD_ID12("KTI", "PE520 PLUS", 0xad180345, 0x9d58d392, "PE520.cis"),
1762 PCMCIA_DEVICE_CIS_PROD_ID12("NDC", "Ethernet", 0x01c43ae1, 0x00b2e941, "cis/NE2K.cis"), 1745 PCMCIA_DEVICE_CIS_PROD_ID12("NDC", "Ethernet", 0x01c43ae1, 0x00b2e941, "cis/NE2K.cis"),
1763 PCMCIA_DEVICE_CIS_PROD_ID12("PMX ", "PE-200", 0x34f3f1c8, 0x10b59f8c, "PE-200.cis"), 1746 PCMCIA_DEVICE_CIS_PROD_ID12("PMX ", "PE-200", 0x34f3f1c8, 0x10b59f8c, "cis/PE-200.cis"),
1764 PCMCIA_DEVICE_CIS_PROD_ID12("TAMARACK", "Ethernet", 0xcf434fba, 0x00b2e941, "cis/tamarack.cis"), 1747 PCMCIA_DEVICE_CIS_PROD_ID12("TAMARACK", "Ethernet", 0xcf434fba, 0x00b2e941, "cis/tamarack.cis"),
1765 PCMCIA_DEVICE_PROD_ID12("Ethernet", "CF Size PC Card", 0x00b2e941, 0x43ac239b), 1748 PCMCIA_DEVICE_PROD_ID12("Ethernet", "CF Size PC Card", 0x00b2e941, 0x43ac239b),
1766 PCMCIA_DEVICE_PROD_ID123("Fast Ethernet", "CF Size PC Card", "1.0", 1749 PCMCIA_DEVICE_PROD_ID123("Fast Ethernet", "CF Size PC Card", "1.0",
@@ -1788,7 +1771,6 @@ static int __init init_pcnet_cs(void)
1788 1771
1789static void __exit exit_pcnet_cs(void) 1772static void __exit exit_pcnet_cs(void)
1790{ 1773{
1791 DEBUG(0, "pcnet_cs: unloading\n");
1792 pcmcia_unregister_driver(&pcnet_driver); 1774 pcmcia_unregister_driver(&pcnet_driver);
1793} 1775}
1794 1776
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 7bde2cd34c7e..9e0da370912e 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -79,14 +79,6 @@ MODULE_FIRMWARE(FIRMWARE_NAME);
79*/ 79*/
80INT_MODULE_PARM(if_port, 0); 80INT_MODULE_PARM(if_port, 0);
81 81
82#ifdef PCMCIA_DEBUG
83INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
84static const char *version =
85"smc91c92_cs.c 1.123 2006/11/09 Donald Becker, becker@scyld.com.\n";
86#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
87#else
88#define DEBUG(n, args...)
89#endif
90 82
91#define DRV_NAME "smc91c92_cs" 83#define DRV_NAME "smc91c92_cs"
92#define DRV_VERSION "1.123" 84#define DRV_VERSION "1.123"
@@ -126,12 +118,6 @@ struct smc_private {
126 int rx_ovrn; 118 int rx_ovrn;
127}; 119};
128 120
129struct smc_cfg_mem {
130 tuple_t tuple;
131 cisparse_t parse;
132 u_char buf[255];
133};
134
135/* Special definitions for Megahertz multifunction cards */ 121/* Special definitions for Megahertz multifunction cards */
136#define MEGAHERTZ_ISR 0x0380 122#define MEGAHERTZ_ISR 0x0380
137 123
@@ -329,7 +315,7 @@ static int smc91c92_probe(struct pcmcia_device *link)
329 struct smc_private *smc; 315 struct smc_private *smc;
330 struct net_device *dev; 316 struct net_device *dev;
331 317
332 DEBUG(0, "smc91c92_attach()\n"); 318 dev_dbg(&link->dev, "smc91c92_attach()\n");
333 319
334 /* Create new ethernet device */ 320 /* Create new ethernet device */
335 dev = alloc_etherdev(sizeof(struct smc_private)); 321 dev = alloc_etherdev(sizeof(struct smc_private));
@@ -343,10 +329,8 @@ static int smc91c92_probe(struct pcmcia_device *link)
343 link->io.NumPorts1 = 16; 329 link->io.NumPorts1 = 16;
344 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 330 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
345 link->io.IOAddrLines = 4; 331 link->io.IOAddrLines = 4;
346 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_HANDLE_PRESENT; 332 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
347 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
348 link->irq.Handler = &smc_interrupt; 333 link->irq.Handler = &smc_interrupt;
349 link->irq.Instance = dev;
350 link->conf.Attributes = CONF_ENABLE_IRQ; 334 link->conf.Attributes = CONF_ENABLE_IRQ;
351 link->conf.IntType = INT_MEMORY_AND_IO; 335 link->conf.IntType = INT_MEMORY_AND_IO;
352 336
@@ -377,7 +361,7 @@ static void smc91c92_detach(struct pcmcia_device *link)
377{ 361{
378 struct net_device *dev = link->priv; 362 struct net_device *dev = link->priv;
379 363
380 DEBUG(0, "smc91c92_detach(0x%p)\n", link); 364 dev_dbg(&link->dev, "smc91c92_detach\n");
381 365
382 if (link->dev_node) 366 if (link->dev_node)
383 unregister_netdev(dev); 367 unregister_netdev(dev);
@@ -408,34 +392,7 @@ static int cvt_ascii_address(struct net_device *dev, char *s)
408 return 0; 392 return 0;
409} 393}
410 394
411/*====================================================================*/ 395/*====================================================================
412
413static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
414 cisparse_t *parse)
415{
416 int i;
417
418 i = pcmcia_get_first_tuple(handle, tuple);
419 if (i != 0)
420 return i;
421 i = pcmcia_get_tuple_data(handle, tuple);
422 if (i != 0)
423 return i;
424 return pcmcia_parse_tuple(tuple, parse);
425}
426
427static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
428 cisparse_t *parse)
429{
430 int i;
431
432 if ((i = pcmcia_get_next_tuple(handle, tuple)) != 0 ||
433 (i = pcmcia_get_tuple_data(handle, tuple)) != 0)
434 return i;
435 return pcmcia_parse_tuple(tuple, parse);
436}
437
438/*======================================================================
439 396
440 Configuration stuff for Megahertz cards 397 Configuration stuff for Megahertz cards
441 398
@@ -490,19 +447,14 @@ static int mhz_mfc_config(struct pcmcia_device *link)
490{ 447{
491 struct net_device *dev = link->priv; 448 struct net_device *dev = link->priv;
492 struct smc_private *smc = netdev_priv(dev); 449 struct smc_private *smc = netdev_priv(dev);
493 struct smc_cfg_mem *cfg_mem;
494 win_req_t req; 450 win_req_t req;
495 memreq_t mem; 451 memreq_t mem;
496 int i; 452 int i;
497 453
498 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
499 if (!cfg_mem)
500 return -ENOMEM;
501
502 link->conf.Attributes |= CONF_ENABLE_SPKR; 454 link->conf.Attributes |= CONF_ENABLE_SPKR;
503 link->conf.Status = CCSR_AUDIO_ENA; 455 link->conf.Status = CCSR_AUDIO_ENA;
504 link->irq.Attributes = 456 link->irq.Attributes =
505 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT; 457 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
506 link->io.IOAddrLines = 16; 458 link->io.IOAddrLines = 16;
507 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 459 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
508 link->io.NumPorts2 = 8; 460 link->io.NumPorts2 = 8;
@@ -510,91 +462,80 @@ static int mhz_mfc_config(struct pcmcia_device *link)
510 /* The Megahertz combo cards have modem-like CIS entries, so 462 /* The Megahertz combo cards have modem-like CIS entries, so
511 we have to explicitly try a bunch of port combinations. */ 463 we have to explicitly try a bunch of port combinations. */
512 if (pcmcia_loop_config(link, mhz_mfc_config_check, NULL)) 464 if (pcmcia_loop_config(link, mhz_mfc_config_check, NULL))
513 goto free_cfg_mem; 465 return -ENODEV;
466
514 dev->base_addr = link->io.BasePort1; 467 dev->base_addr = link->io.BasePort1;
515 468
516 /* Allocate a memory window, for accessing the ISR */ 469 /* Allocate a memory window, for accessing the ISR */
517 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 470 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
518 req.Base = req.Size = 0; 471 req.Base = req.Size = 0;
519 req.AccessSpeed = 0; 472 req.AccessSpeed = 0;
520 i = pcmcia_request_window(&link, &req, &link->win); 473 i = pcmcia_request_window(link, &req, &link->win);
521 if (i != 0) 474 if (i != 0)
522 goto free_cfg_mem; 475 return -ENODEV;
476
523 smc->base = ioremap(req.Base, req.Size); 477 smc->base = ioremap(req.Base, req.Size);
524 mem.CardOffset = mem.Page = 0; 478 mem.CardOffset = mem.Page = 0;
525 if (smc->manfid == MANFID_MOTOROLA) 479 if (smc->manfid == MANFID_MOTOROLA)
526 mem.CardOffset = link->conf.ConfigBase; 480 mem.CardOffset = link->conf.ConfigBase;
527 i = pcmcia_map_mem_page(link->win, &mem); 481 i = pcmcia_map_mem_page(link, link->win, &mem);
528 482
529 if ((i == 0) 483 if ((i == 0)
530 && (smc->manfid == MANFID_MEGAHERTZ) 484 && (smc->manfid == MANFID_MEGAHERTZ)
531 && (smc->cardid == PRODID_MEGAHERTZ_EM3288)) 485 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
532 mhz_3288_power(link); 486 mhz_3288_power(link);
533 487
534free_cfg_mem: 488 return 0;
535 kfree(cfg_mem);
536 return -ENODEV;
537} 489}
538 490
539static int mhz_setup(struct pcmcia_device *link) 491static int pcmcia_get_versmac(struct pcmcia_device *p_dev,
492 tuple_t *tuple,
493 void *priv)
540{ 494{
541 struct net_device *dev = link->priv; 495 struct net_device *dev = priv;
542 struct smc_cfg_mem *cfg_mem; 496 cisparse_t parse;
543 tuple_t *tuple;
544 cisparse_t *parse;
545 u_char *buf, *station_addr;
546 int rc;
547 497
548 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); 498 if (pcmcia_parse_tuple(tuple, &parse))
549 if (!cfg_mem) 499 return -EINVAL;
550 return -1;
551 500
552 tuple = &cfg_mem->tuple; 501 if ((parse.version_1.ns > 3) &&
553 parse = &cfg_mem->parse; 502 (cvt_ascii_address(dev,
554 buf = cfg_mem->buf; 503 (parse.version_1.str + parse.version_1.ofs[3]))))
504 return 0;
555 505
556 tuple->Attributes = tuple->TupleOffset = 0; 506 return -EINVAL;
557 tuple->TupleData = (cisdata_t *)buf; 507};
558 tuple->TupleDataMax = 255; 508
509static int mhz_setup(struct pcmcia_device *link)
510{
511 struct net_device *dev = link->priv;
512 size_t len;
513 u8 *buf;
514 int rc;
559 515
560 /* Read the station address from the CIS. It is stored as the last 516 /* Read the station address from the CIS. It is stored as the last
561 (fourth) string in the Version 1 Version/ID tuple. */ 517 (fourth) string in the Version 1 Version/ID tuple. */
562 tuple->DesiredTuple = CISTPL_VERS_1; 518 if ((link->prod_id[3]) &&
563 if (first_tuple(link, tuple, parse) != 0) { 519 (cvt_ascii_address(dev, link->prod_id[3]) == 0))
564 rc = -1; 520 return 0;
565 goto free_cfg_mem; 521
566 } 522 /* Workarounds for broken cards start here. */
567 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */ 523 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
568 if (next_tuple(link, tuple, parse) != 0) 524 if (!pcmcia_loop_tuple(link, CISTPL_VERS_1, pcmcia_get_versmac, dev))
569 first_tuple(link, tuple, parse); 525 return 0;
570 if (parse->version_1.ns > 3) {
571 station_addr = parse->version_1.str + parse->version_1.ofs[3];
572 if (cvt_ascii_address(dev, station_addr) == 0) {
573 rc = 0;
574 goto free_cfg_mem;
575 }
576 }
577 526
578 /* Another possibility: for the EM3288, in a special tuple */ 527 /* Another possibility: for the EM3288, in a special tuple */
579 tuple->DesiredTuple = 0x81;
580 if (pcmcia_get_first_tuple(link, tuple) != 0) {
581 rc = -1;
582 goto free_cfg_mem;
583 }
584 if (pcmcia_get_tuple_data(link, tuple) != 0) {
585 rc = -1;
586 goto free_cfg_mem;
587 }
588 buf[12] = '\0';
589 if (cvt_ascii_address(dev, buf) == 0) {
590 rc = 0;
591 goto free_cfg_mem;
592 }
593 rc = -1; 528 rc = -1;
594free_cfg_mem: 529 len = pcmcia_get_tuple(link, 0x81, &buf);
595 kfree(cfg_mem); 530 if (buf && len >= 13) {
596 return rc; 531 buf[12] = '\0';
597} 532 if (cvt_ascii_address(dev, buf))
533 rc = 0;
534 }
535 kfree(buf);
536
537 return rc;
538};
598 539
599/*====================================================================== 540/*======================================================================
600 541
@@ -684,58 +625,21 @@ static int smc_config(struct pcmcia_device *link)
684 return i; 625 return i;
685} 626}
686 627
628
687static int smc_setup(struct pcmcia_device *link) 629static int smc_setup(struct pcmcia_device *link)
688{ 630{
689 struct net_device *dev = link->priv; 631 struct net_device *dev = link->priv;
690 struct smc_cfg_mem *cfg_mem;
691 tuple_t *tuple;
692 cisparse_t *parse;
693 cistpl_lan_node_id_t *node_id;
694 u_char *buf, *station_addr;
695 int i, rc;
696
697 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
698 if (!cfg_mem)
699 return -ENOMEM;
700
701 tuple = &cfg_mem->tuple;
702 parse = &cfg_mem->parse;
703 buf = cfg_mem->buf;
704
705 tuple->Attributes = tuple->TupleOffset = 0;
706 tuple->TupleData = (cisdata_t *)buf;
707 tuple->TupleDataMax = 255;
708 632
709 /* Check for a LAN function extension tuple */ 633 /* Check for a LAN function extension tuple */
710 tuple->DesiredTuple = CISTPL_FUNCE; 634 if (!pcmcia_get_mac_from_cis(link, dev))
711 i = first_tuple(link, tuple, parse); 635 return 0;
712 while (i == 0) { 636
713 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
714 break;
715 i = next_tuple(link, tuple, parse);
716 }
717 if (i == 0) {
718 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
719 if (node_id->nb == 6) {
720 for (i = 0; i < 6; i++)
721 dev->dev_addr[i] = node_id->id[i];
722 rc = 0;
723 goto free_cfg_mem;
724 }
725 }
726 /* Try the third string in the Version 1 Version/ID tuple. */ 637 /* Try the third string in the Version 1 Version/ID tuple. */
727 if (link->prod_id[2]) { 638 if (link->prod_id[2]) {
728 station_addr = link->prod_id[2]; 639 if (cvt_ascii_address(dev, link->prod_id[2]) == 0)
729 if (cvt_ascii_address(dev, station_addr) == 0) { 640 return 0;
730 rc = 0;
731 goto free_cfg_mem;
732 }
733 } 641 }
734 642 return -1;
735 rc = -1;
736free_cfg_mem:
737 kfree(cfg_mem);
738 return rc;
739} 643}
740 644
741/*====================================================================*/ 645/*====================================================================*/
@@ -749,7 +653,7 @@ static int osi_config(struct pcmcia_device *link)
749 link->conf.Attributes |= CONF_ENABLE_SPKR; 653 link->conf.Attributes |= CONF_ENABLE_SPKR;
750 link->conf.Status = CCSR_AUDIO_ENA; 654 link->conf.Status = CCSR_AUDIO_ENA;
751 link->irq.Attributes = 655 link->irq.Attributes =
752 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT; 656 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
753 link->io.NumPorts1 = 64; 657 link->io.NumPorts1 = 64;
754 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 658 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
755 link->io.NumPorts2 = 8; 659 link->io.NumPorts2 = 8;
@@ -794,41 +698,31 @@ static int osi_load_firmware(struct pcmcia_device *link)
794 return err; 698 return err;
795} 699}
796 700
797static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid) 701static int pcmcia_osi_mac(struct pcmcia_device *p_dev,
702 tuple_t *tuple,
703 void *priv)
798{ 704{
799 struct net_device *dev = link->priv; 705 struct net_device *dev = priv;
800 struct smc_cfg_mem *cfg_mem; 706 int i;
801 tuple_t *tuple;
802 u_char *buf;
803 int i, rc;
804 707
805 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); 708 if (tuple->TupleDataLen < 8)
806 if (!cfg_mem) 709 return -EINVAL;
807 return -1; 710 if (tuple->TupleData[0] != 0x04)
711 return -EINVAL;
712 for (i = 0; i < 6; i++)
713 dev->dev_addr[i] = tuple->TupleData[i+2];
714 return 0;
715};
808 716
809 tuple = &cfg_mem->tuple;
810 buf = cfg_mem->buf;
811 717
812 tuple->Attributes = TUPLE_RETURN_COMMON; 718static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid)
813 tuple->TupleData = (cisdata_t *)buf; 719{
814 tuple->TupleDataMax = 255; 720 struct net_device *dev = link->priv;
815 tuple->TupleOffset = 0; 721 int rc;
816 722
817 /* Read the station address from tuple 0x90, subtuple 0x04 */ 723 /* Read the station address from tuple 0x90, subtuple 0x04 */
818 tuple->DesiredTuple = 0x90; 724 if (pcmcia_loop_tuple(link, 0x90, pcmcia_osi_mac, dev))
819 i = pcmcia_get_first_tuple(link, tuple); 725 return -1;
820 while (i == 0) {
821 i = pcmcia_get_tuple_data(link, tuple);
822 if ((i != 0) || (buf[0] == 0x04))
823 break;
824 i = pcmcia_get_next_tuple(link, tuple);
825 }
826 if (i != 0) {
827 rc = -1;
828 goto free_cfg_mem;
829 }
830 for (i = 0; i < 6; i++)
831 dev->dev_addr[i] = buf[i+2];
832 726
833 if (((manfid == MANFID_OSITECH) && 727 if (((manfid == MANFID_OSITECH) &&
834 (cardid == PRODID_OSITECH_SEVEN)) || 728 (cardid == PRODID_OSITECH_SEVEN)) ||
@@ -836,20 +730,17 @@ static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid)
836 (cardid == PRODID_PSION_NET100))) { 730 (cardid == PRODID_PSION_NET100))) {
837 rc = osi_load_firmware(link); 731 rc = osi_load_firmware(link);
838 if (rc) 732 if (rc)
839 goto free_cfg_mem; 733 return rc;
840 } else if (manfid == MANFID_OSITECH) { 734 } else if (manfid == MANFID_OSITECH) {
841 /* Make sure both functions are powered up */ 735 /* Make sure both functions are powered up */
842 set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR); 736 set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR);
843 /* Now, turn on the interrupt for both card functions */ 737 /* Now, turn on the interrupt for both card functions */
844 set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR); 738 set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR);
845 DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n", 739 dev_dbg(&link->dev, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
846 inw(link->io.BasePort1 + OSITECH_AUI_PWR), 740 inw(link->io.BasePort1 + OSITECH_AUI_PWR),
847 inw(link->io.BasePort1 + OSITECH_RESET_ISR)); 741 inw(link->io.BasePort1 + OSITECH_RESET_ISR));
848 } 742 }
849 rc = 0; 743 return 0;
850free_cfg_mem:
851 kfree(cfg_mem);
852 return rc;
853} 744}
854 745
855static int smc91c92_suspend(struct pcmcia_device *link) 746static int smc91c92_suspend(struct pcmcia_device *link)
@@ -959,12 +850,6 @@ static int check_sig(struct pcmcia_device *link)
959 850
960======================================================================*/ 851======================================================================*/
961 852
962#define CS_EXIT_TEST(ret, svc, label) \
963if (ret != 0) { \
964 cs_error(link, svc, ret); \
965 goto label; \
966}
967
968static int smc91c92_config(struct pcmcia_device *link) 853static int smc91c92_config(struct pcmcia_device *link)
969{ 854{
970 struct net_device *dev = link->priv; 855 struct net_device *dev = link->priv;
@@ -974,7 +859,7 @@ static int smc91c92_config(struct pcmcia_device *link)
974 unsigned int ioaddr; 859 unsigned int ioaddr;
975 u_long mir; 860 u_long mir;
976 861
977 DEBUG(0, "smc91c92_config(0x%p)\n", link); 862 dev_dbg(&link->dev, "smc91c92_config\n");
978 863
979 smc->manfid = link->manf_id; 864 smc->manfid = link->manf_id;
980 smc->cardid = link->card_id; 865 smc->cardid = link->card_id;
@@ -990,12 +875,15 @@ static int smc91c92_config(struct pcmcia_device *link)
990 } else { 875 } else {
991 i = smc_config(link); 876 i = smc_config(link);
992 } 877 }
993 CS_EXIT_TEST(i, RequestIO, config_failed); 878 if (i)
879 goto config_failed;
994 880
995 i = pcmcia_request_irq(link, &link->irq); 881 i = pcmcia_request_irq(link, &link->irq);
996 CS_EXIT_TEST(i, RequestIRQ, config_failed); 882 if (i)
883 goto config_failed;
997 i = pcmcia_request_configuration(link, &link->conf); 884 i = pcmcia_request_configuration(link, &link->conf);
998 CS_EXIT_TEST(i, RequestConfiguration, config_failed); 885 if (i)
886 goto config_failed;
999 887
1000 if (smc->manfid == MANFID_MOTOROLA) 888 if (smc->manfid == MANFID_MOTOROLA)
1001 mot_config(link); 889 mot_config(link);
@@ -1074,7 +962,7 @@ static int smc91c92_config(struct pcmcia_device *link)
1074 } 962 }
1075 963
1076 link->dev_node = &smc->node; 964 link->dev_node = &smc->node;
1077 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 965 SET_NETDEV_DEV(dev, &link->dev);
1078 966
1079 if (register_netdev(dev) != 0) { 967 if (register_netdev(dev) != 0) {
1080 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n"); 968 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
@@ -1100,7 +988,7 @@ static int smc91c92_config(struct pcmcia_device *link)
1100 988
1101 if (smc->cfg & CFG_MII_SELECT) { 989 if (smc->cfg & CFG_MII_SELECT) {
1102 if (smc->mii_if.phy_id != -1) { 990 if (smc->mii_if.phy_id != -1) {
1103 DEBUG(0, " MII transceiver at index %d, status %x.\n", 991 dev_dbg(&link->dev, " MII transceiver at index %d, status %x.\n",
1104 smc->mii_if.phy_id, j); 992 smc->mii_if.phy_id, j);
1105 } else { 993 } else {
1106 printk(KERN_NOTICE " No MII transceivers found!\n"); 994 printk(KERN_NOTICE " No MII transceivers found!\n");
@@ -1110,7 +998,7 @@ static int smc91c92_config(struct pcmcia_device *link)
1110 998
1111config_undo: 999config_undo:
1112 unregister_netdev(dev); 1000 unregister_netdev(dev);
1113config_failed: /* CS_EXIT_TEST() calls jump to here... */ 1001config_failed:
1114 smc91c92_release(link); 1002 smc91c92_release(link);
1115 return -ENODEV; 1003 return -ENODEV;
1116} /* smc91c92_config */ 1004} /* smc91c92_config */
@@ -1125,7 +1013,7 @@ config_failed: /* CS_EXIT_TEST() calls jump to here... */
1125 1013
1126static void smc91c92_release(struct pcmcia_device *link) 1014static void smc91c92_release(struct pcmcia_device *link)
1127{ 1015{
1128 DEBUG(0, "smc91c92_release(0x%p)\n", link); 1016 dev_dbg(&link->dev, "smc91c92_release\n");
1129 if (link->win) { 1017 if (link->win) {
1130 struct net_device *dev = link->priv; 1018 struct net_device *dev = link->priv;
1131 struct smc_private *smc = netdev_priv(dev); 1019 struct smc_private *smc = netdev_priv(dev);
@@ -1222,10 +1110,10 @@ static int smc_open(struct net_device *dev)
1222 struct smc_private *smc = netdev_priv(dev); 1110 struct smc_private *smc = netdev_priv(dev);
1223 struct pcmcia_device *link = smc->p_dev; 1111 struct pcmcia_device *link = smc->p_dev;
1224 1112
1225#ifdef PCMCIA_DEBUG 1113 dev_dbg(&link->dev, "%s: smc_open(%p), ID/Window %4.4x.\n",
1226 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
1227 dev->name, dev, inw(dev->base_addr + BANK_SELECT)); 1114 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1228 if (pc_debug > 1) smc_dump(dev); 1115#ifdef PCMCIA_DEBUG
1116 smc_dump(dev);
1229#endif 1117#endif
1230 1118
1231 /* Check that the PCMCIA card is still here. */ 1119 /* Check that the PCMCIA card is still here. */
@@ -1260,7 +1148,7 @@ static int smc_close(struct net_device *dev)
1260 struct pcmcia_device *link = smc->p_dev; 1148 struct pcmcia_device *link = smc->p_dev;
1261 unsigned int ioaddr = dev->base_addr; 1149 unsigned int ioaddr = dev->base_addr;
1262 1150
1263 DEBUG(0, "%s: smc_close(), status %4.4x.\n", 1151 dev_dbg(&link->dev, "%s: smc_close(), status %4.4x.\n",
1264 dev->name, inw(ioaddr + BANK_SELECT)); 1152 dev->name, inw(ioaddr + BANK_SELECT));
1265 1153
1266 netif_stop_queue(dev); 1154 netif_stop_queue(dev);
@@ -1327,7 +1215,7 @@ static void smc_hardware_send_packet(struct net_device * dev)
1327 u_char *buf = skb->data; 1215 u_char *buf = skb->data;
1328 u_int length = skb->len; /* The chip will pad to ethernet min. */ 1216 u_int length = skb->len; /* The chip will pad to ethernet min. */
1329 1217
1330 DEBUG(2, "%s: Trying to xmit packet of length %d.\n", 1218 pr_debug("%s: Trying to xmit packet of length %d.\n",
1331 dev->name, length); 1219 dev->name, length);
1332 1220
1333 /* send the packet length: +6 for status word, length, and ctl */ 1221 /* send the packet length: +6 for status word, length, and ctl */
@@ -1382,7 +1270,7 @@ static netdev_tx_t smc_start_xmit(struct sk_buff *skb,
1382 1270
1383 netif_stop_queue(dev); 1271 netif_stop_queue(dev);
1384 1272
1385 DEBUG(2, "%s: smc_start_xmit(length = %d) called," 1273 pr_debug("%s: smc_start_xmit(length = %d) called,"
1386 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2)); 1274 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1387 1275
1388 if (smc->saved_skb) { 1276 if (smc->saved_skb) {
@@ -1429,7 +1317,7 @@ static netdev_tx_t smc_start_xmit(struct sk_buff *skb,
1429 } 1317 }
1430 1318
1431 /* Otherwise defer until the Tx-space-allocated interrupt. */ 1319 /* Otherwise defer until the Tx-space-allocated interrupt. */
1432 DEBUG(2, "%s: memory allocation deferred.\n", dev->name); 1320 pr_debug("%s: memory allocation deferred.\n", dev->name);
1433 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT); 1321 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1434 spin_unlock_irqrestore(&smc->lock, flags); 1322 spin_unlock_irqrestore(&smc->lock, flags);
1435 1323
@@ -1494,7 +1382,7 @@ static void smc_eph_irq(struct net_device *dev)
1494 1382
1495 SMC_SELECT_BANK(0); 1383 SMC_SELECT_BANK(0);
1496 ephs = inw(ioaddr + EPH); 1384 ephs = inw(ioaddr + EPH);
1497 DEBUG(2, "%s: Ethernet protocol handler interrupt, status" 1385 pr_debug("%s: Ethernet protocol handler interrupt, status"
1498 " %4.4x.\n", dev->name, ephs); 1386 " %4.4x.\n", dev->name, ephs);
1499 /* Could be a counter roll-over warning: update stats. */ 1387 /* Could be a counter roll-over warning: update stats. */
1500 card_stats = inw(ioaddr + COUNTER); 1388 card_stats = inw(ioaddr + COUNTER);
@@ -1534,7 +1422,7 @@ static irqreturn_t smc_interrupt(int irq, void *dev_id)
1534 1422
1535 ioaddr = dev->base_addr; 1423 ioaddr = dev->base_addr;
1536 1424
1537 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name, 1425 pr_debug("%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1538 irq, ioaddr); 1426 irq, ioaddr);
1539 1427
1540 spin_lock(&smc->lock); 1428 spin_lock(&smc->lock);
@@ -1543,7 +1431,7 @@ static irqreturn_t smc_interrupt(int irq, void *dev_id)
1543 if ((saved_bank & 0xff00) != 0x3300) { 1431 if ((saved_bank & 0xff00) != 0x3300) {
1544 /* The device does not exist -- the card could be off-line, or 1432 /* The device does not exist -- the card could be off-line, or
1545 maybe it has been ejected. */ 1433 maybe it has been ejected. */
1546 DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent" 1434 pr_debug("%s: SMC91c92 interrupt %d for non-existent"
1547 "/ejected device.\n", dev->name, irq); 1435 "/ejected device.\n", dev->name, irq);
1548 handled = 0; 1436 handled = 0;
1549 goto irq_done; 1437 goto irq_done;
@@ -1557,7 +1445,7 @@ static irqreturn_t smc_interrupt(int irq, void *dev_id)
1557 1445
1558 do { /* read the status flag, and mask it */ 1446 do { /* read the status flag, and mask it */
1559 status = inw(ioaddr + INTERRUPT) & 0xff; 1447 status = inw(ioaddr + INTERRUPT) & 0xff;
1560 DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev->name, 1448 pr_debug("%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1561 status, mask); 1449 status, mask);
1562 if ((status & mask) == 0) { 1450 if ((status & mask) == 0) {
1563 if (bogus_cnt == INTR_WORK) 1451 if (bogus_cnt == INTR_WORK)
@@ -1602,7 +1490,7 @@ static irqreturn_t smc_interrupt(int irq, void *dev_id)
1602 smc_eph_irq(dev); 1490 smc_eph_irq(dev);
1603 } while (--bogus_cnt); 1491 } while (--bogus_cnt);
1604 1492
1605 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x" 1493 pr_debug(" Restoring saved registers mask %2.2x bank %4.4x"
1606 " pointer %4.4x.\n", mask, saved_bank, saved_pointer); 1494 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1607 1495
1608 /* restore state register */ 1496 /* restore state register */
@@ -1610,7 +1498,7 @@ static irqreturn_t smc_interrupt(int irq, void *dev_id)
1610 outw(saved_pointer, ioaddr + POINTER); 1498 outw(saved_pointer, ioaddr + POINTER);
1611 SMC_SELECT_BANK(saved_bank); 1499 SMC_SELECT_BANK(saved_bank);
1612 1500
1613 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq); 1501 pr_debug("%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1614 1502
1615irq_done: 1503irq_done:
1616 1504
@@ -1661,7 +1549,7 @@ static void smc_rx(struct net_device *dev)
1661 rx_status = inw(ioaddr + DATA_1); 1549 rx_status = inw(ioaddr + DATA_1);
1662 packet_length = inw(ioaddr + DATA_1) & 0x07ff; 1550 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1663 1551
1664 DEBUG(2, "%s: Receive status %4.4x length %d.\n", 1552 pr_debug("%s: Receive status %4.4x length %d.\n",
1665 dev->name, rx_status, packet_length); 1553 dev->name, rx_status, packet_length);
1666 1554
1667 if (!(rx_status & RS_ERRORS)) { 1555 if (!(rx_status & RS_ERRORS)) {
@@ -1672,7 +1560,7 @@ static void smc_rx(struct net_device *dev)
1672 skb = dev_alloc_skb(packet_length+2); 1560 skb = dev_alloc_skb(packet_length+2);
1673 1561
1674 if (skb == NULL) { 1562 if (skb == NULL) {
1675 DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name); 1563 pr_debug("%s: Low memory, packet dropped.\n", dev->name);
1676 dev->stats.rx_dropped++; 1564 dev->stats.rx_dropped++;
1677 outw(MC_RELEASE, ioaddr + MMU_CMD); 1565 outw(MC_RELEASE, ioaddr + MMU_CMD);
1678 return; 1566 return;
@@ -1832,7 +1720,7 @@ static void smc_reset(struct net_device *dev)
1832 struct smc_private *smc = netdev_priv(dev); 1720 struct smc_private *smc = netdev_priv(dev);
1833 int i; 1721 int i;
1834 1722
1835 DEBUG(0, "%s: smc91c92 reset called.\n", dev->name); 1723 pr_debug("%s: smc91c92 reset called.\n", dev->name);
1836 1724
1837 /* The first interaction must be a write to bring the chip out 1725 /* The first interaction must be a write to bring the chip out
1838 of sleep mode. */ 1726 of sleep mode. */
@@ -2149,18 +2037,6 @@ static u32 smc_get_link(struct net_device *dev)
2149 return ret; 2037 return ret;
2150} 2038}
2151 2039
2152#ifdef PCMCIA_DEBUG
2153static u32 smc_get_msglevel(struct net_device *dev)
2154{
2155 return pc_debug;
2156}
2157
2158static void smc_set_msglevel(struct net_device *dev, u32 val)
2159{
2160 pc_debug = val;
2161}
2162#endif
2163
2164static int smc_nway_reset(struct net_device *dev) 2040static int smc_nway_reset(struct net_device *dev)
2165{ 2041{
2166 struct smc_private *smc = netdev_priv(dev); 2042 struct smc_private *smc = netdev_priv(dev);
@@ -2184,10 +2060,6 @@ static const struct ethtool_ops ethtool_ops = {
2184 .get_settings = smc_get_settings, 2060 .get_settings = smc_get_settings,
2185 .set_settings = smc_set_settings, 2061 .set_settings = smc_set_settings,
2186 .get_link = smc_get_link, 2062 .get_link = smc_get_link,
2187#ifdef PCMCIA_DEBUG
2188 .get_msglevel = smc_get_msglevel,
2189 .set_msglevel = smc_set_msglevel,
2190#endif
2191 .nway_reset = smc_nway_reset, 2063 .nway_reset = smc_nway_reset,
2192}; 2064};
2193 2065
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index cf8423102538..fe504b7f369f 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -211,20 +211,6 @@ enum xirc_cmd { /* Commands */
211 211
212static const char *if_names[] = { "Auto", "10BaseT", "10Base2", "AUI", "100BaseT" }; 212static const char *if_names[] = { "Auto", "10BaseT", "10Base2", "AUI", "100BaseT" };
213 213
214/****************
215 * All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
216 * you do not define PCMCIA_DEBUG at all, all the debug code will be
217 * left out. If you compile with PCMCIA_DEBUG=0, the debug code will
218 * be present but disabled -- but it can then be enabled for specific
219 * modules at load time with a 'pc_debug=#' option to insmod.
220 */
221#ifdef PCMCIA_DEBUG
222static int pc_debug = PCMCIA_DEBUG;
223module_param(pc_debug, int, 0);
224#define DEBUG(n, args...) if (pc_debug>(n)) printk(KDBG_XIRC args)
225#else
226#define DEBUG(n, args...)
227#endif
228 214
229#define KDBG_XIRC KERN_DEBUG "xirc2ps_cs: " 215#define KDBG_XIRC KERN_DEBUG "xirc2ps_cs: "
230#define KERR_XIRC KERN_ERR "xirc2ps_cs: " 216#define KERR_XIRC KERN_ERR "xirc2ps_cs: "
@@ -359,7 +345,7 @@ static void xirc_tx_timeout(struct net_device *dev);
359static void xirc2ps_tx_timeout_task(struct work_struct *work); 345static void xirc2ps_tx_timeout_task(struct work_struct *work);
360static void set_addresses(struct net_device *dev); 346static void set_addresses(struct net_device *dev);
361static void set_multicast_list(struct net_device *dev); 347static void set_multicast_list(struct net_device *dev);
362static int set_card_type(struct pcmcia_device *link, const void *s); 348static int set_card_type(struct pcmcia_device *link);
363static int do_config(struct net_device *dev, struct ifmap *map); 349static int do_config(struct net_device *dev, struct ifmap *map);
364static int do_open(struct net_device *dev); 350static int do_open(struct net_device *dev);
365static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 351static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -371,28 +357,6 @@ static void do_powerdown(struct net_device *dev);
371static int do_stop(struct net_device *dev); 357static int do_stop(struct net_device *dev);
372 358
373/*=============== Helper functions =========================*/ 359/*=============== Helper functions =========================*/
374static int
375first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
376{
377 int err;
378
379 if ((err = pcmcia_get_first_tuple(handle, tuple)) == 0 &&
380 (err = pcmcia_get_tuple_data(handle, tuple)) == 0)
381 err = pcmcia_parse_tuple(tuple, parse);
382 return err;
383}
384
385static int
386next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
387{
388 int err;
389
390 if ((err = pcmcia_get_next_tuple(handle, tuple)) == 0 &&
391 (err = pcmcia_get_tuple_data(handle, tuple)) == 0)
392 err = pcmcia_parse_tuple(tuple, parse);
393 return err;
394}
395
396#define SelectPage(pgnr) outb((pgnr), ioaddr + XIRCREG_PR) 360#define SelectPage(pgnr) outb((pgnr), ioaddr + XIRCREG_PR)
397#define GetByte(reg) ((unsigned)inb(ioaddr + (reg))) 361#define GetByte(reg) ((unsigned)inb(ioaddr + (reg)))
398#define GetWord(reg) ((unsigned)inw(ioaddr + (reg))) 362#define GetWord(reg) ((unsigned)inw(ioaddr + (reg)))
@@ -400,7 +364,7 @@ next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
400#define PutWord(reg,value) outw((value), ioaddr+(reg)) 364#define PutWord(reg,value) outw((value), ioaddr+(reg))
401 365
402/*====== Functions used for debugging =================================*/ 366/*====== Functions used for debugging =================================*/
403#if defined(PCMCIA_DEBUG) && 0 /* reading regs may change system status */ 367#if 0 /* reading regs may change system status */
404static void 368static void
405PrintRegisters(struct net_device *dev) 369PrintRegisters(struct net_device *dev)
406{ 370{
@@ -432,7 +396,7 @@ PrintRegisters(struct net_device *dev)
432 } 396 }
433 } 397 }
434} 398}
435#endif /* PCMCIA_DEBUG */ 399#endif /* 0 */
436 400
437/*============== MII Management functions ===============*/ 401/*============== MII Management functions ===============*/
438 402
@@ -576,7 +540,7 @@ xirc2ps_probe(struct pcmcia_device *link)
576 struct net_device *dev; 540 struct net_device *dev;
577 local_info_t *local; 541 local_info_t *local;
578 542
579 DEBUG(0, "attach()\n"); 543 dev_dbg(&link->dev, "attach()\n");
580 544
581 /* Allocate the device structure */ 545 /* Allocate the device structure */
582 dev = alloc_etherdev(sizeof(local_info_t)); 546 dev = alloc_etherdev(sizeof(local_info_t));
@@ -592,7 +556,6 @@ xirc2ps_probe(struct pcmcia_device *link)
592 link->conf.IntType = INT_MEMORY_AND_IO; 556 link->conf.IntType = INT_MEMORY_AND_IO;
593 link->conf.ConfigIndex = 1; 557 link->conf.ConfigIndex = 1;
594 link->irq.Handler = xirc2ps_interrupt; 558 link->irq.Handler = xirc2ps_interrupt;
595 link->irq.Instance = dev;
596 559
597 /* Fill in card specific entries */ 560 /* Fill in card specific entries */
598 dev->netdev_ops = &netdev_ops; 561 dev->netdev_ops = &netdev_ops;
@@ -615,7 +578,7 @@ xirc2ps_detach(struct pcmcia_device *link)
615{ 578{
616 struct net_device *dev = link->priv; 579 struct net_device *dev = link->priv;
617 580
618 DEBUG(0, "detach(0x%p)\n", link); 581 dev_dbg(&link->dev, "detach\n");
619 582
620 if (link->dev_node) 583 if (link->dev_node)
621 unregister_netdev(dev); 584 unregister_netdev(dev);
@@ -644,17 +607,25 @@ xirc2ps_detach(struct pcmcia_device *link)
644 * 607 *
645 */ 608 */
646static int 609static int
647set_card_type(struct pcmcia_device *link, const void *s) 610set_card_type(struct pcmcia_device *link)
648{ 611{
649 struct net_device *dev = link->priv; 612 struct net_device *dev = link->priv;
650 local_info_t *local = netdev_priv(dev); 613 local_info_t *local = netdev_priv(dev);
651 #ifdef PCMCIA_DEBUG 614 u8 *buf;
652 unsigned cisrev = ((const unsigned char *)s)[2]; 615 unsigned int cisrev, mediaid, prodid;
653 #endif 616 size_t len;
654 unsigned mediaid= ((const unsigned char *)s)[3]; 617
655 unsigned prodid = ((const unsigned char *)s)[4]; 618 len = pcmcia_get_tuple(link, CISTPL_MANFID, &buf);
619 if (len < 5) {
620 dev_err(&link->dev, "invalid CIS -- sorry\n");
621 return 0;
622 }
656 623
657 DEBUG(0, "cisrev=%02x mediaid=%02x prodid=%02x\n", 624 cisrev = buf[2];
625 mediaid = buf[3];
626 prodid = buf[4];
627
628 dev_dbg(&link->dev, "cisrev=%02x mediaid=%02x prodid=%02x\n",
658 cisrev, mediaid, prodid); 629 cisrev, mediaid, prodid);
659 630
660 local->mohawk = 0; 631 local->mohawk = 0;
@@ -761,6 +732,26 @@ xirc2ps_config_check(struct pcmcia_device *p_dev,
761 732
762} 733}
763 734
735
736static int pcmcia_get_mac_ce(struct pcmcia_device *p_dev,
737 tuple_t *tuple,
738 void *priv)
739{
740 struct net_device *dev = priv;
741 int i;
742
743 if (tuple->TupleDataLen != 13)
744 return -EINVAL;
745 if ((tuple->TupleData[0] != 2) || (tuple->TupleData[1] != 1) ||
746 (tuple->TupleData[2] != 6))
747 return -EINVAL;
748 /* another try (James Lehmer's CE2 version 4.1)*/
749 for (i = 2; i < 6; i++)
750 dev->dev_addr[i] = tuple->TupleData[i+2];
751 return 0;
752};
753
754
764/**************** 755/****************
765 * xirc2ps_config() is scheduled to run after a CARD_INSERTION event 756 * xirc2ps_config() is scheduled to run after a CARD_INSERTION event
766 * is received, to configure the PCMCIA socket, and to make the 757 * is received, to configure the PCMCIA socket, and to make the
@@ -772,33 +763,21 @@ xirc2ps_config(struct pcmcia_device * link)
772 struct net_device *dev = link->priv; 763 struct net_device *dev = link->priv;
773 local_info_t *local = netdev_priv(dev); 764 local_info_t *local = netdev_priv(dev);
774 unsigned int ioaddr; 765 unsigned int ioaddr;
775 tuple_t tuple; 766 int err;
776 cisparse_t parse; 767 u8 *buf;
777 int err, i; 768 size_t len;
778 u_char buf[64];
779 cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data;
780 769
781 local->dingo_ccr = NULL; 770 local->dingo_ccr = NULL;
782 771
783 DEBUG(0, "config(0x%p)\n", link); 772 dev_dbg(&link->dev, "config\n");
784
785 /*
786 * This reads the card's CONFIG tuple to find its configuration
787 * registers.
788 */
789 tuple.Attributes = 0;
790 tuple.TupleData = buf;
791 tuple.TupleDataMax = 64;
792 tuple.TupleOffset = 0;
793 773
794 /* Is this a valid card */ 774 /* Is this a valid card */
795 tuple.DesiredTuple = CISTPL_MANFID; 775 if (link->has_manf_id == 0) {
796 if ((err=first_tuple(link, &tuple, &parse))) {
797 printk(KNOT_XIRC "manfid not found in CIS\n"); 776 printk(KNOT_XIRC "manfid not found in CIS\n");
798 goto failure; 777 goto failure;
799 } 778 }
800 779
801 switch(parse.manfid.manf) { 780 switch (link->manf_id) {
802 case MANFID_XIRCOM: 781 case MANFID_XIRCOM:
803 local->manf_str = "Xircom"; 782 local->manf_str = "Xircom";
804 break; 783 break;
@@ -817,65 +796,44 @@ xirc2ps_config(struct pcmcia_device * link)
817 break; 796 break;
818 default: 797 default:
819 printk(KNOT_XIRC "Unknown Card Manufacturer ID: 0x%04x\n", 798 printk(KNOT_XIRC "Unknown Card Manufacturer ID: 0x%04x\n",
820 (unsigned)parse.manfid.manf); 799 (unsigned)link->manf_id);
821 goto failure; 800 goto failure;
822 } 801 }
823 DEBUG(0, "found %s card\n", local->manf_str); 802 dev_dbg(&link->dev, "found %s card\n", local->manf_str);
824 803
825 if (!set_card_type(link, buf)) { 804 if (!set_card_type(link)) {
826 printk(KNOT_XIRC "this card is not supported\n"); 805 printk(KNOT_XIRC "this card is not supported\n");
827 goto failure; 806 goto failure;
828 } 807 }
829 808
830 /* get the ethernet address from the CIS */ 809 /* get the ethernet address from the CIS */
831 tuple.DesiredTuple = CISTPL_FUNCE; 810 err = pcmcia_get_mac_from_cis(link, dev);
832 for (err = first_tuple(link, &tuple, &parse); !err; 811
833 err = next_tuple(link, &tuple, &parse)) { 812 /* not found: try to get the node-id from tuple 0x89 */
834 /* Once I saw two CISTPL_FUNCE_LAN_NODE_ID entries: 813 if (err) {
835 * the first one with a length of zero the second correct - 814 len = pcmcia_get_tuple(link, 0x89, &buf);
836 * so I skip all entries with length 0 */ 815 /* data layout looks like tuple 0x22 */
837 if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID 816 if (buf && len == 8) {
838 && ((cistpl_lan_node_id_t *)parse.funce.data)->nb) 817 if (*buf == CISTPL_FUNCE_LAN_NODE_ID) {
839 break; 818 int i;
840 } 819 for (i = 2; i < 6; i++)
841 if (err) { /* not found: try to get the node-id from tuple 0x89 */ 820 dev->dev_addr[i] = buf[i+2];
842 tuple.DesiredTuple = 0x89; /* data layout looks like tuple 0x22 */ 821 } else
843 if ((err = pcmcia_get_first_tuple(link, &tuple)) == 0 && 822 err = -1;
844 (err = pcmcia_get_tuple_data(link, &tuple)) == 0) {
845 if (tuple.TupleDataLen == 8 && *buf == CISTPL_FUNCE_LAN_NODE_ID)
846 memcpy(&parse, buf, 8);
847 else
848 err = -1;
849 }
850 }
851 if (err) { /* another try (James Lehmer's CE2 version 4.1)*/
852 tuple.DesiredTuple = CISTPL_FUNCE;
853 for (err = first_tuple(link, &tuple, &parse); !err;
854 err = next_tuple(link, &tuple, &parse)) {
855 if (parse.funce.type == 0x02 && parse.funce.data[0] == 1
856 && parse.funce.data[1] == 6 && tuple.TupleDataLen == 13) {
857 buf[1] = 4;
858 memcpy(&parse, buf+1, 8);
859 break;
860 } 823 }
861 } 824 kfree(buf);
862 } 825 }
826
827 if (err)
828 err = pcmcia_loop_tuple(link, CISTPL_FUNCE, pcmcia_get_mac_ce, dev);
829
863 if (err) { 830 if (err) {
864 printk(KNOT_XIRC "node-id not found in CIS\n"); 831 printk(KNOT_XIRC "node-id not found in CIS\n");
865 goto failure; 832 goto failure;
866 } 833 }
867 node_id = (cistpl_lan_node_id_t *)parse.funce.data;
868 if (node_id->nb != 6) {
869 printk(KNOT_XIRC "malformed node-id in CIS\n");
870 goto failure;
871 }
872 for (i=0; i < 6; i++)
873 dev->dev_addr[i] = node_id->id[i];
874 834
875 link->io.IOAddrLines =10; 835 link->io.IOAddrLines =10;
876 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; 836 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
877 link->irq.Attributes = IRQ_HANDLE_PRESENT;
878 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
879 if (local->modem) { 837 if (local->modem) {
880 int pass; 838 int pass;
881 839
@@ -916,10 +874,8 @@ xirc2ps_config(struct pcmcia_device * link)
916 goto port_found; 874 goto port_found;
917 } 875 }
918 link->io.BasePort1 = 0; /* let CS decide */ 876 link->io.BasePort1 = 0; /* let CS decide */
919 if ((err=pcmcia_request_io(link, &link->io))) { 877 if ((err=pcmcia_request_io(link, &link->io)))
920 cs_error(link, RequestIO, err);
921 goto config_error; 878 goto config_error;
922 }
923 } 879 }
924 port_found: 880 port_found:
925 if (err) 881 if (err)
@@ -929,19 +885,15 @@ xirc2ps_config(struct pcmcia_device * link)
929 * Now allocate an interrupt line. Note that this does not 885 * Now allocate an interrupt line. Note that this does not
930 * actually assign a handler to the interrupt. 886 * actually assign a handler to the interrupt.
931 */ 887 */
932 if ((err=pcmcia_request_irq(link, &link->irq))) { 888 if ((err=pcmcia_request_irq(link, &link->irq)))
933 cs_error(link, RequestIRQ, err);
934 goto config_error; 889 goto config_error;
935 }
936 890
937 /**************** 891 /****************
938 * This actually configures the PCMCIA socket -- setting up 892 * This actually configures the PCMCIA socket -- setting up
939 * the I/O windows and the interrupt mapping. 893 * the I/O windows and the interrupt mapping.
940 */ 894 */
941 if ((err=pcmcia_request_configuration(link, &link->conf))) { 895 if ((err=pcmcia_request_configuration(link, &link->conf)))
942 cs_error(link, RequestConfiguration, err);
943 goto config_error; 896 goto config_error;
944 }
945 897
946 if (local->dingo) { 898 if (local->dingo) {
947 conf_reg_t reg; 899 conf_reg_t reg;
@@ -956,17 +908,13 @@ xirc2ps_config(struct pcmcia_device * link)
956 reg.Action = CS_WRITE; 908 reg.Action = CS_WRITE;
957 reg.Offset = CISREG_IOBASE_0; 909 reg.Offset = CISREG_IOBASE_0;
958 reg.Value = link->io.BasePort2 & 0xff; 910 reg.Value = link->io.BasePort2 & 0xff;
959 if ((err = pcmcia_access_configuration_register(link, &reg))) { 911 if ((err = pcmcia_access_configuration_register(link, &reg)))
960 cs_error(link, AccessConfigurationRegister, err);
961 goto config_error; 912 goto config_error;
962 }
963 reg.Action = CS_WRITE; 913 reg.Action = CS_WRITE;
964 reg.Offset = CISREG_IOBASE_1; 914 reg.Offset = CISREG_IOBASE_1;
965 reg.Value = (link->io.BasePort2 >> 8) & 0xff; 915 reg.Value = (link->io.BasePort2 >> 8) & 0xff;
966 if ((err = pcmcia_access_configuration_register(link, &reg))) { 916 if ((err = pcmcia_access_configuration_register(link, &reg)))
967 cs_error(link, AccessConfigurationRegister, err);
968 goto config_error; 917 goto config_error;
969 }
970 918
971 /* There is no config entry for the Ethernet part which 919 /* There is no config entry for the Ethernet part which
972 * is at 0x0800. So we allocate a window into the attribute 920 * is at 0x0800. So we allocate a window into the attribute
@@ -975,17 +923,14 @@ xirc2ps_config(struct pcmcia_device * link)
975 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 923 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
976 req.Base = req.Size = 0; 924 req.Base = req.Size = 0;
977 req.AccessSpeed = 0; 925 req.AccessSpeed = 0;
978 if ((err = pcmcia_request_window(&link, &req, &link->win))) { 926 if ((err = pcmcia_request_window(link, &req, &link->win)))
979 cs_error(link, RequestWindow, err);
980 goto config_error; 927 goto config_error;
981 } 928
982 local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800; 929 local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800;
983 mem.CardOffset = 0x0; 930 mem.CardOffset = 0x0;
984 mem.Page = 0; 931 mem.Page = 0;
985 if ((err = pcmcia_map_mem_page(link->win, &mem))) { 932 if ((err = pcmcia_map_mem_page(link, link->win, &mem)))
986 cs_error(link, MapMemPage, err);
987 goto config_error; 933 goto config_error;
988 }
989 934
990 /* Setup the CCRs; there are no infos in the CIS about the Ethernet 935 /* Setup the CCRs; there are no infos in the CIS about the Ethernet
991 * part. 936 * part.
@@ -1044,7 +989,7 @@ xirc2ps_config(struct pcmcia_device * link)
1044 do_reset(dev, 1); /* a kludge to make the cem56 work */ 989 do_reset(dev, 1); /* a kludge to make the cem56 work */
1045 990
1046 link->dev_node = &local->node; 991 link->dev_node = &local->node;
1047 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 992 SET_NETDEV_DEV(dev, &link->dev);
1048 993
1049 if ((err=register_netdev(dev))) { 994 if ((err=register_netdev(dev))) {
1050 printk(KNOT_XIRC "register_netdev() failed\n"); 995 printk(KNOT_XIRC "register_netdev() failed\n");
@@ -1077,7 +1022,7 @@ xirc2ps_config(struct pcmcia_device * link)
1077static void 1022static void
1078xirc2ps_release(struct pcmcia_device *link) 1023xirc2ps_release(struct pcmcia_device *link)
1079{ 1024{
1080 DEBUG(0, "release(0x%p)\n", link); 1025 dev_dbg(&link->dev, "release\n");
1081 1026
1082 if (link->win) { 1027 if (link->win) {
1083 struct net_device *dev = link->priv; 1028 struct net_device *dev = link->priv;
@@ -1144,7 +1089,7 @@ xirc2ps_interrupt(int irq, void *dev_id)
1144 PutByte(XIRCREG_CR, 0); 1089 PutByte(XIRCREG_CR, 0);
1145 } 1090 }
1146 1091
1147 DEBUG(6, "%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr); 1092 pr_debug("%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
1148 1093
1149 saved_page = GetByte(XIRCREG_PR); 1094 saved_page = GetByte(XIRCREG_PR);
1150 /* Read the ISR to see whats the cause for the interrupt. 1095 /* Read the ISR to see whats the cause for the interrupt.
@@ -1154,7 +1099,7 @@ xirc2ps_interrupt(int irq, void *dev_id)
1154 bytes_rcvd = 0; 1099 bytes_rcvd = 0;
1155 loop_entry: 1100 loop_entry:
1156 if (int_status == 0xff) { /* card may be ejected */ 1101 if (int_status == 0xff) { /* card may be ejected */
1157 DEBUG(3, "%s: interrupt %d for dead card\n", dev->name, irq); 1102 pr_debug("%s: interrupt %d for dead card\n", dev->name, irq);
1158 goto leave; 1103 goto leave;
1159 } 1104 }
1160 eth_status = GetByte(XIRCREG_ESR); 1105 eth_status = GetByte(XIRCREG_ESR);
@@ -1167,7 +1112,7 @@ xirc2ps_interrupt(int irq, void *dev_id)
1167 PutByte(XIRCREG40_TXST0, 0); 1112 PutByte(XIRCREG40_TXST0, 0);
1168 PutByte(XIRCREG40_TXST1, 0); 1113 PutByte(XIRCREG40_TXST1, 0);
1169 1114
1170 DEBUG(3, "%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n", 1115 pr_debug("%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
1171 dev->name, int_status, eth_status, rx_status, tx_status); 1116 dev->name, int_status, eth_status, rx_status, tx_status);
1172 1117
1173 /***** receive section ******/ 1118 /***** receive section ******/
@@ -1178,14 +1123,14 @@ xirc2ps_interrupt(int irq, void *dev_id)
1178 /* too many bytes received during this int, drop the rest of the 1123 /* too many bytes received during this int, drop the rest of the
1179 * packets */ 1124 * packets */
1180 dev->stats.rx_dropped++; 1125 dev->stats.rx_dropped++;
1181 DEBUG(2, "%s: RX drop, too much done\n", dev->name); 1126 pr_debug("%s: RX drop, too much done\n", dev->name);
1182 } else if (rsr & PktRxOk) { 1127 } else if (rsr & PktRxOk) {
1183 struct sk_buff *skb; 1128 struct sk_buff *skb;
1184 1129
1185 pktlen = GetWord(XIRCREG0_RBC); 1130 pktlen = GetWord(XIRCREG0_RBC);
1186 bytes_rcvd += pktlen; 1131 bytes_rcvd += pktlen;
1187 1132
1188 DEBUG(5, "rsr=%#02x packet_length=%u\n", rsr, pktlen); 1133 pr_debug("rsr=%#02x packet_length=%u\n", rsr, pktlen);
1189 1134
1190 skb = dev_alloc_skb(pktlen+3); /* 1 extra so we can use insw */ 1135 skb = dev_alloc_skb(pktlen+3); /* 1 extra so we can use insw */
1191 if (!skb) { 1136 if (!skb) {
@@ -1253,19 +1198,19 @@ xirc2ps_interrupt(int irq, void *dev_id)
1253 dev->stats.multicast++; 1198 dev->stats.multicast++;
1254 } 1199 }
1255 } else { /* bad packet */ 1200 } else { /* bad packet */
1256 DEBUG(5, "rsr=%#02x\n", rsr); 1201 pr_debug("rsr=%#02x\n", rsr);
1257 } 1202 }
1258 if (rsr & PktTooLong) { 1203 if (rsr & PktTooLong) {
1259 dev->stats.rx_frame_errors++; 1204 dev->stats.rx_frame_errors++;
1260 DEBUG(3, "%s: Packet too long\n", dev->name); 1205 pr_debug("%s: Packet too long\n", dev->name);
1261 } 1206 }
1262 if (rsr & CRCErr) { 1207 if (rsr & CRCErr) {
1263 dev->stats.rx_crc_errors++; 1208 dev->stats.rx_crc_errors++;
1264 DEBUG(3, "%s: CRC error\n", dev->name); 1209 pr_debug("%s: CRC error\n", dev->name);
1265 } 1210 }
1266 if (rsr & AlignErr) { 1211 if (rsr & AlignErr) {
1267 dev->stats.rx_fifo_errors++; /* okay ? */ 1212 dev->stats.rx_fifo_errors++; /* okay ? */
1268 DEBUG(3, "%s: Alignment error\n", dev->name); 1213 pr_debug("%s: Alignment error\n", dev->name);
1269 } 1214 }
1270 1215
1271 /* clear the received/dropped/error packet */ 1216 /* clear the received/dropped/error packet */
@@ -1277,7 +1222,7 @@ xirc2ps_interrupt(int irq, void *dev_id)
1277 if (rx_status & 0x10) { /* Receive overrun */ 1222 if (rx_status & 0x10) { /* Receive overrun */
1278 dev->stats.rx_over_errors++; 1223 dev->stats.rx_over_errors++;
1279 PutByte(XIRCREG_CR, ClearRxOvrun); 1224 PutByte(XIRCREG_CR, ClearRxOvrun);
1280 DEBUG(3, "receive overrun cleared\n"); 1225 pr_debug("receive overrun cleared\n");
1281 } 1226 }
1282 1227
1283 /***** transmit section ******/ 1228 /***** transmit section ******/
@@ -1290,13 +1235,13 @@ xirc2ps_interrupt(int irq, void *dev_id)
1290 if (nn < n) /* rollover */ 1235 if (nn < n) /* rollover */
1291 dev->stats.tx_packets += 256 - n; 1236 dev->stats.tx_packets += 256 - n;
1292 else if (n == nn) { /* happens sometimes - don't know why */ 1237 else if (n == nn) { /* happens sometimes - don't know why */
1293 DEBUG(0, "PTR not changed?\n"); 1238 pr_debug("PTR not changed?\n");
1294 } else 1239 } else
1295 dev->stats.tx_packets += lp->last_ptr_value - n; 1240 dev->stats.tx_packets += lp->last_ptr_value - n;
1296 netif_wake_queue(dev); 1241 netif_wake_queue(dev);
1297 } 1242 }
1298 if (tx_status & 0x0002) { /* Execessive collissions */ 1243 if (tx_status & 0x0002) { /* Execessive collissions */
1299 DEBUG(0, "tx restarted due to execssive collissions\n"); 1244 pr_debug("tx restarted due to execssive collissions\n");
1300 PutByte(XIRCREG_CR, RestartTx); /* restart transmitter process */ 1245 PutByte(XIRCREG_CR, RestartTx); /* restart transmitter process */
1301 } 1246 }
1302 if (tx_status & 0x0040) 1247 if (tx_status & 0x0040)
@@ -1315,14 +1260,14 @@ xirc2ps_interrupt(int irq, void *dev_id)
1315 maxrx_bytes = 2000; 1260 maxrx_bytes = 2000;
1316 else if (maxrx_bytes > 22000) 1261 else if (maxrx_bytes > 22000)
1317 maxrx_bytes = 22000; 1262 maxrx_bytes = 22000;
1318 DEBUG(1, "set maxrx=%u (rcvd=%u ticks=%lu)\n", 1263 pr_debug("set maxrx=%u (rcvd=%u ticks=%lu)\n",
1319 maxrx_bytes, bytes_rcvd, duration); 1264 maxrx_bytes, bytes_rcvd, duration);
1320 } else if (!duration && maxrx_bytes < 22000) { 1265 } else if (!duration && maxrx_bytes < 22000) {
1321 /* now much faster */ 1266 /* now much faster */
1322 maxrx_bytes += 2000; 1267 maxrx_bytes += 2000;
1323 if (maxrx_bytes > 22000) 1268 if (maxrx_bytes > 22000)
1324 maxrx_bytes = 22000; 1269 maxrx_bytes = 22000;
1325 DEBUG(1, "set maxrx=%u\n", maxrx_bytes); 1270 pr_debug("set maxrx=%u\n", maxrx_bytes);
1326 } 1271 }
1327 } 1272 }
1328 1273
@@ -1372,7 +1317,7 @@ do_start_xmit(struct sk_buff *skb, struct net_device *dev)
1372 unsigned freespace; 1317 unsigned freespace;
1373 unsigned pktlen = skb->len; 1318 unsigned pktlen = skb->len;
1374 1319
1375 DEBUG(1, "do_start_xmit(skb=%p, dev=%p) len=%u\n", 1320 pr_debug("do_start_xmit(skb=%p, dev=%p) len=%u\n",
1376 skb, dev, pktlen); 1321 skb, dev, pktlen);
1377 1322
1378 1323
@@ -1398,7 +1343,7 @@ do_start_xmit(struct sk_buff *skb, struct net_device *dev)
1398 freespace &= 0x7fff; 1343 freespace &= 0x7fff;
1399 /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */ 1344 /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */
1400 okay = pktlen +2 < freespace; 1345 okay = pktlen +2 < freespace;
1401 DEBUG(2 + (okay ? 2 : 0), "%s: avail. tx space=%u%s\n", 1346 pr_debug("%s: avail. tx space=%u%s\n",
1402 dev->name, freespace, okay ? " (okay)":" (not enough)"); 1347 dev->name, freespace, okay ? " (okay)":" (not enough)");
1403 if (!okay) { /* not enough space */ 1348 if (!okay) { /* not enough space */
1404 return NETDEV_TX_BUSY; /* upper layer may decide to requeue this packet */ 1349 return NETDEV_TX_BUSY; /* upper layer may decide to requeue this packet */
@@ -1500,7 +1445,7 @@ do_config(struct net_device *dev, struct ifmap *map)
1500{ 1445{
1501 local_info_t *local = netdev_priv(dev); 1446 local_info_t *local = netdev_priv(dev);
1502 1447
1503 DEBUG(0, "do_config(%p)\n", dev); 1448 pr_debug("do_config(%p)\n", dev);
1504 if (map->port != 255 && map->port != dev->if_port) { 1449 if (map->port != 255 && map->port != dev->if_port) {
1505 if (map->port > 4) 1450 if (map->port > 4)
1506 return -EINVAL; 1451 return -EINVAL;
@@ -1527,7 +1472,7 @@ do_open(struct net_device *dev)
1527 local_info_t *lp = netdev_priv(dev); 1472 local_info_t *lp = netdev_priv(dev);
1528 struct pcmcia_device *link = lp->p_dev; 1473 struct pcmcia_device *link = lp->p_dev;
1529 1474
1530 DEBUG(0, "do_open(%p)\n", dev); 1475 dev_dbg(&link->dev, "do_open(%p)\n", dev);
1531 1476
1532 /* Check that the PCMCIA card is still here. */ 1477 /* Check that the PCMCIA card is still here. */
1533 /* Physical device present signature. */ 1478 /* Physical device present signature. */
@@ -1561,7 +1506,7 @@ do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1561 unsigned int ioaddr = dev->base_addr; 1506 unsigned int ioaddr = dev->base_addr;
1562 struct mii_ioctl_data *data = if_mii(rq); 1507 struct mii_ioctl_data *data = if_mii(rq);
1563 1508
1564 DEBUG(1, "%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n", 1509 pr_debug("%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
1565 dev->name, rq->ifr_ifrn.ifrn_name, cmd, 1510 dev->name, rq->ifr_ifrn.ifrn_name, cmd,
1566 data->phy_id, data->reg_num, data->val_in, data->val_out); 1511 data->phy_id, data->reg_num, data->val_in, data->val_out);
1567 1512
@@ -1610,7 +1555,7 @@ do_reset(struct net_device *dev, int full)
1610 unsigned int ioaddr = dev->base_addr; 1555 unsigned int ioaddr = dev->base_addr;
1611 unsigned value; 1556 unsigned value;
1612 1557
1613 DEBUG(0, "%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full); 1558 pr_debug("%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full);
1614 1559
1615 hardreset(dev); 1560 hardreset(dev);
1616 PutByte(XIRCREG_CR, SoftReset); /* set */ 1561 PutByte(XIRCREG_CR, SoftReset); /* set */
@@ -1648,8 +1593,8 @@ do_reset(struct net_device *dev, int full)
1648 } 1593 }
1649 msleep(40); /* wait 40 msec to let it complete */ 1594 msleep(40); /* wait 40 msec to let it complete */
1650 1595
1651 #ifdef PCMCIA_DEBUG 1596 #if 0
1652 if (pc_debug) { 1597 {
1653 SelectPage(0); 1598 SelectPage(0);
1654 value = GetByte(XIRCREG_ESR); /* read the ESR */ 1599 value = GetByte(XIRCREG_ESR); /* read the ESR */
1655 printk(KERN_DEBUG "%s: ESR is: %#02x\n", dev->name, value); 1600 printk(KERN_DEBUG "%s: ESR is: %#02x\n", dev->name, value);
@@ -1666,7 +1611,7 @@ do_reset(struct net_device *dev, int full)
1666 value |= DisableLinkPulse; 1611 value |= DisableLinkPulse;
1667 PutByte(XIRCREG1_ECR, value); 1612 PutByte(XIRCREG1_ECR, value);
1668 #endif 1613 #endif
1669 DEBUG(0, "%s: ECR is: %#02x\n", dev->name, value); 1614 pr_debug("%s: ECR is: %#02x\n", dev->name, value);
1670 1615
1671 SelectPage(0x42); 1616 SelectPage(0x42);
1672 PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */ 1617 PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */
@@ -1844,7 +1789,7 @@ do_powerdown(struct net_device *dev)
1844 1789
1845 unsigned int ioaddr = dev->base_addr; 1790 unsigned int ioaddr = dev->base_addr;
1846 1791
1847 DEBUG(0, "do_powerdown(%p)\n", dev); 1792 pr_debug("do_powerdown(%p)\n", dev);
1848 1793
1849 SelectPage(4); 1794 SelectPage(4);
1850 PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */ 1795 PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
@@ -1858,7 +1803,7 @@ do_stop(struct net_device *dev)
1858 local_info_t *lp = netdev_priv(dev); 1803 local_info_t *lp = netdev_priv(dev);
1859 struct pcmcia_device *link = lp->p_dev; 1804 struct pcmcia_device *link = lp->p_dev;
1860 1805
1861 DEBUG(0, "do_stop(%p)\n", dev); 1806 dev_dbg(&link->dev, "do_stop(%p)\n", dev);
1862 1807
1863 if (!link) 1808 if (!link)
1864 return -ENODEV; 1809 return -ENODEV;
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index 250e10f2c35b..35897134a5dd 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -139,7 +139,7 @@ out:
139 return NULL; 139 return NULL;
140} 140}
141 141
142static void __devinit mdio_gpio_bus_deinit(struct device *dev) 142static void mdio_gpio_bus_deinit(struct device *dev)
143{ 143{
144 struct mii_bus *bus = dev_get_drvdata(dev); 144 struct mii_bus *bus = dev_get_drvdata(dev);
145 struct mdio_gpio_info *bitbang = bus->priv; 145 struct mdio_gpio_info *bitbang = bus->priv;
@@ -238,6 +238,7 @@ static struct of_device_id mdio_ofgpio_match[] = {
238 }, 238 },
239 {}, 239 {},
240}; 240};
241MODULE_DEVICE_TABLE(of, mdio_ofgpio_match);
241 242
242static struct of_platform_driver mdio_ofgpio_driver = { 243static struct of_platform_driver mdio_ofgpio_driver = {
243 .name = "mdio-gpio", 244 .name = "mdio-gpio",
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 9bf2a6be9031..965adb6174c3 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -1944,8 +1944,15 @@ ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1944 } 1944 }
1945 1945
1946 /* Pull completed packets off the queue and receive them. */ 1946 /* Pull completed packets off the queue and receive them. */
1947 while ((skb = ppp_mp_reconstruct(ppp))) 1947 while ((skb = ppp_mp_reconstruct(ppp))) {
1948 ppp_receive_nonmp_frame(ppp, skb); 1948 if (pskb_may_pull(skb, 2))
1949 ppp_receive_nonmp_frame(ppp, skb);
1950 else {
1951 ++ppp->dev->stats.rx_length_errors;
1952 kfree_skb(skb);
1953 ppp_receive_error(ppp);
1954 }
1955 }
1949 1956
1950 return; 1957 return;
1951 1958
diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
index 7cbf6f9b51de..2559991eea6a 100644
--- a/drivers/net/pppoe.c
+++ b/drivers/net/pppoe.c
@@ -111,9 +111,6 @@ struct pppoe_net {
111 rwlock_t hash_lock; 111 rwlock_t hash_lock;
112}; 112};
113 113
114/* to eliminate a race btw pppoe_flush_dev and pppoe_release */
115static DEFINE_SPINLOCK(flush_lock);
116
117/* 114/*
118 * PPPoE could be in the following stages: 115 * PPPoE could be in the following stages:
119 * 1) Discovery stage (to obtain remote MAC and Session ID) 116 * 1) Discovery stage (to obtain remote MAC and Session ID)
@@ -303,45 +300,48 @@ static void pppoe_flush_dev(struct net_device *dev)
303 write_lock_bh(&pn->hash_lock); 300 write_lock_bh(&pn->hash_lock);
304 for (i = 0; i < PPPOE_HASH_SIZE; i++) { 301 for (i = 0; i < PPPOE_HASH_SIZE; i++) {
305 struct pppox_sock *po = pn->hash_table[i]; 302 struct pppox_sock *po = pn->hash_table[i];
303 struct sock *sk;
306 304
307 while (po != NULL) { 305 while (po) {
308 struct sock *sk; 306 while (po && po->pppoe_dev != dev) {
309 if (po->pppoe_dev != dev) {
310 po = po->next; 307 po = po->next;
311 continue;
312 } 308 }
309
310 if (!po)
311 break;
312
313 sk = sk_pppox(po); 313 sk = sk_pppox(po);
314 spin_lock(&flush_lock);
315 po->pppoe_dev = NULL;
316 spin_unlock(&flush_lock);
317 dev_put(dev);
318 314
319 /* We always grab the socket lock, followed by the 315 /* We always grab the socket lock, followed by the
320 * hash_lock, in that order. Since we should 316 * hash_lock, in that order. Since we should hold the
321 * hold the sock lock while doing any unbinding, 317 * sock lock while doing any unbinding, we need to
322 * we need to release the lock we're holding. 318 * release the lock we're holding. Hold a reference to
323 * Hold a reference to the sock so it doesn't disappear 319 * the sock so it doesn't disappear as we're jumping
324 * as we're jumping between locks. 320 * between locks.
325 */ 321 */
326 322
327 sock_hold(sk); 323 sock_hold(sk);
328
329 write_unlock_bh(&pn->hash_lock); 324 write_unlock_bh(&pn->hash_lock);
330 lock_sock(sk); 325 lock_sock(sk);
331 326
332 if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) { 327 if (po->pppoe_dev == dev
328 && sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) {
333 pppox_unbind_sock(sk); 329 pppox_unbind_sock(sk);
334 sk->sk_state = PPPOX_ZOMBIE; 330 sk->sk_state = PPPOX_ZOMBIE;
335 sk->sk_state_change(sk); 331 sk->sk_state_change(sk);
332 po->pppoe_dev = NULL;
333 dev_put(dev);
336 } 334 }
337 335
338 release_sock(sk); 336 release_sock(sk);
339 sock_put(sk); 337 sock_put(sk);
340 338
341 /* Restart scan at the beginning of this hash chain. 339 /* Restart the process from the start of the current
342 * While the lock was dropped the chain contents may 340 * hash chain. We dropped locks so the world may have
343 * have changed. 341 * change from underneath us.
344 */ 342 */
343
344 BUG_ON(pppoe_pernet(dev_net(dev)) == NULL);
345 write_lock_bh(&pn->hash_lock); 345 write_lock_bh(&pn->hash_lock);
346 po = pn->hash_table[i]; 346 po = pn->hash_table[i];
347 } 347 }
@@ -388,11 +388,16 @@ static int pppoe_rcv_core(struct sock *sk, struct sk_buff *skb)
388 struct pppox_sock *po = pppox_sk(sk); 388 struct pppox_sock *po = pppox_sk(sk);
389 struct pppox_sock *relay_po; 389 struct pppox_sock *relay_po;
390 390
391 /* Backlog receive. Semantics of backlog rcv preclude any code from
392 * executing in lock_sock()/release_sock() bounds; meaning sk->sk_state
393 * can't change.
394 */
395
391 if (sk->sk_state & PPPOX_BOUND) { 396 if (sk->sk_state & PPPOX_BOUND) {
392 ppp_input(&po->chan, skb); 397 ppp_input(&po->chan, skb);
393 } else if (sk->sk_state & PPPOX_RELAY) { 398 } else if (sk->sk_state & PPPOX_RELAY) {
394 relay_po = get_item_by_addr(dev_net(po->pppoe_dev), 399 relay_po = get_item_by_addr(sock_net(sk),
395 &po->pppoe_relay); 400 &po->pppoe_relay);
396 if (relay_po == NULL) 401 if (relay_po == NULL)
397 goto abort_kfree; 402 goto abort_kfree;
398 403
@@ -447,6 +452,10 @@ static int pppoe_rcv(struct sk_buff *skb, struct net_device *dev,
447 goto drop; 452 goto drop;
448 453
449 pn = pppoe_pernet(dev_net(dev)); 454 pn = pppoe_pernet(dev_net(dev));
455
456 /* Note that get_item does a sock_hold(), so sk_pppox(po)
457 * is known to be safe.
458 */
450 po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex); 459 po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
451 if (!po) 460 if (!po)
452 goto drop; 461 goto drop;
@@ -561,6 +570,7 @@ static int pppoe_release(struct socket *sock)
561 struct sock *sk = sock->sk; 570 struct sock *sk = sock->sk;
562 struct pppox_sock *po; 571 struct pppox_sock *po;
563 struct pppoe_net *pn; 572 struct pppoe_net *pn;
573 struct net *net = NULL;
564 574
565 if (!sk) 575 if (!sk)
566 return 0; 576 return 0;
@@ -571,44 +581,28 @@ static int pppoe_release(struct socket *sock)
571 return -EBADF; 581 return -EBADF;
572 } 582 }
573 583
584 po = pppox_sk(sk);
585
586 if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) {
587 dev_put(po->pppoe_dev);
588 po->pppoe_dev = NULL;
589 }
590
574 pppox_unbind_sock(sk); 591 pppox_unbind_sock(sk);
575 592
576 /* Signal the death of the socket. */ 593 /* Signal the death of the socket. */
577 sk->sk_state = PPPOX_DEAD; 594 sk->sk_state = PPPOX_DEAD;
578 595
579 /* 596 net = sock_net(sk);
580 * pppoe_flush_dev could lead to a race with 597 pn = pppoe_pernet(net);
581 * this routine so we use flush_lock to eliminate
582 * such a case (we only need per-net specific data)
583 */
584 spin_lock(&flush_lock);
585 po = pppox_sk(sk);
586 if (!po->pppoe_dev) {
587 spin_unlock(&flush_lock);
588 goto out;
589 }
590 pn = pppoe_pernet(dev_net(po->pppoe_dev));
591 spin_unlock(&flush_lock);
592 598
593 /* 599 /*
594 * protect "po" from concurrent updates 600 * protect "po" from concurrent updates
595 * on pppoe_flush_dev 601 * on pppoe_flush_dev
596 */ 602 */
597 write_lock_bh(&pn->hash_lock); 603 delete_item(pn, po->pppoe_pa.sid, po->pppoe_pa.remote,
604 po->pppoe_ifindex);
598 605
599 po = pppox_sk(sk);
600 if (stage_session(po->pppoe_pa.sid))
601 __delete_item(pn, po->pppoe_pa.sid, po->pppoe_pa.remote,
602 po->pppoe_ifindex);
603
604 if (po->pppoe_dev) {
605 dev_put(po->pppoe_dev);
606 po->pppoe_dev = NULL;
607 }
608
609 write_unlock_bh(&pn->hash_lock);
610
611out:
612 sock_orphan(sk); 606 sock_orphan(sk);
613 sock->sk = NULL; 607 sock->sk = NULL;
614 608
@@ -625,8 +619,9 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
625 struct sock *sk = sock->sk; 619 struct sock *sk = sock->sk;
626 struct sockaddr_pppox *sp = (struct sockaddr_pppox *)uservaddr; 620 struct sockaddr_pppox *sp = (struct sockaddr_pppox *)uservaddr;
627 struct pppox_sock *po = pppox_sk(sk); 621 struct pppox_sock *po = pppox_sk(sk);
628 struct net_device *dev; 622 struct net_device *dev = NULL;
629 struct pppoe_net *pn; 623 struct pppoe_net *pn;
624 struct net *net = NULL;
630 int error; 625 int error;
631 626
632 lock_sock(sk); 627 lock_sock(sk);
@@ -652,12 +647,14 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
652 /* Delete the old binding */ 647 /* Delete the old binding */
653 if (stage_session(po->pppoe_pa.sid)) { 648 if (stage_session(po->pppoe_pa.sid)) {
654 pppox_unbind_sock(sk); 649 pppox_unbind_sock(sk);
650 pn = pppoe_pernet(sock_net(sk));
651 delete_item(pn, po->pppoe_pa.sid,
652 po->pppoe_pa.remote, po->pppoe_ifindex);
655 if (po->pppoe_dev) { 653 if (po->pppoe_dev) {
656 pn = pppoe_pernet(dev_net(po->pppoe_dev));
657 delete_item(pn, po->pppoe_pa.sid,
658 po->pppoe_pa.remote, po->pppoe_ifindex);
659 dev_put(po->pppoe_dev); 654 dev_put(po->pppoe_dev);
655 po->pppoe_dev = NULL;
660 } 656 }
657
661 memset(sk_pppox(po) + 1, 0, 658 memset(sk_pppox(po) + 1, 0,
662 sizeof(struct pppox_sock) - sizeof(struct sock)); 659 sizeof(struct pppox_sock) - sizeof(struct sock));
663 sk->sk_state = PPPOX_NONE; 660 sk->sk_state = PPPOX_NONE;
@@ -666,16 +663,15 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
666 /* Re-bind in session stage only */ 663 /* Re-bind in session stage only */
667 if (stage_session(sp->sa_addr.pppoe.sid)) { 664 if (stage_session(sp->sa_addr.pppoe.sid)) {
668 error = -ENODEV; 665 error = -ENODEV;
669 dev = dev_get_by_name(sock_net(sk), sp->sa_addr.pppoe.dev); 666 net = sock_net(sk);
667 dev = dev_get_by_name(net, sp->sa_addr.pppoe.dev);
670 if (!dev) 668 if (!dev)
671 goto end; 669 goto err_put;
672 670
673 po->pppoe_dev = dev; 671 po->pppoe_dev = dev;
674 po->pppoe_ifindex = dev->ifindex; 672 po->pppoe_ifindex = dev->ifindex;
675 pn = pppoe_pernet(dev_net(dev)); 673 pn = pppoe_pernet(net);
676 write_lock_bh(&pn->hash_lock);
677 if (!(dev->flags & IFF_UP)) { 674 if (!(dev->flags & IFF_UP)) {
678 write_unlock_bh(&pn->hash_lock);
679 goto err_put; 675 goto err_put;
680 } 676 }
681 677
@@ -683,6 +679,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
683 &sp->sa_addr.pppoe, 679 &sp->sa_addr.pppoe,
684 sizeof(struct pppoe_addr)); 680 sizeof(struct pppoe_addr));
685 681
682 write_lock_bh(&pn->hash_lock);
686 error = __set_item(pn, po); 683 error = __set_item(pn, po);
687 write_unlock_bh(&pn->hash_lock); 684 write_unlock_bh(&pn->hash_lock);
688 if (error < 0) 685 if (error < 0)
@@ -696,8 +693,11 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
696 po->chan.ops = &pppoe_chan_ops; 693 po->chan.ops = &pppoe_chan_ops;
697 694
698 error = ppp_register_net_channel(dev_net(dev), &po->chan); 695 error = ppp_register_net_channel(dev_net(dev), &po->chan);
699 if (error) 696 if (error) {
697 delete_item(pn, po->pppoe_pa.sid,
698 po->pppoe_pa.remote, po->pppoe_ifindex);
700 goto err_put; 699 goto err_put;
700 }
701 701
702 sk->sk_state = PPPOX_CONNECTED; 702 sk->sk_state = PPPOX_CONNECTED;
703 } 703 }
@@ -915,6 +915,14 @@ static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
915 struct pppoe_hdr *ph; 915 struct pppoe_hdr *ph;
916 int data_len = skb->len; 916 int data_len = skb->len;
917 917
918 /* The higher-level PPP code (ppp_unregister_channel()) ensures the PPP
919 * xmit operations conclude prior to an unregistration call. Thus
920 * sk->sk_state cannot change, so we don't need to do lock_sock().
921 * But, we also can't do a lock_sock since that introduces a potential
922 * deadlock as we'd reverse the lock ordering used when calling
923 * ppp_unregister_channel().
924 */
925
918 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED)) 926 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
919 goto abort; 927 goto abort;
920 928
@@ -944,7 +952,6 @@ static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
944 po->pppoe_pa.remote, NULL, data_len); 952 po->pppoe_pa.remote, NULL, data_len);
945 953
946 dev_queue_xmit(skb); 954 dev_queue_xmit(skb);
947
948 return 1; 955 return 1;
949 956
950abort: 957abort:
diff --git a/drivers/net/qlge/qlge.h b/drivers/net/qlge/qlge.h
index 3ec6e85587a2..c2383adcd527 100644
--- a/drivers/net/qlge/qlge.h
+++ b/drivers/net/qlge/qlge.h
@@ -95,6 +95,7 @@ enum {
95 95
96 /* Misc. stuff */ 96 /* Misc. stuff */
97 MAILBOX_COUNT = 16, 97 MAILBOX_COUNT = 16,
98 MAILBOX_TIMEOUT = 5,
98 99
99 PROC_ADDR_RDY = (1 << 31), 100 PROC_ADDR_RDY = (1 << 31),
100 PROC_ADDR_R = (1 << 30), 101 PROC_ADDR_R = (1 << 30),
@@ -803,6 +804,12 @@ enum {
803 MB_CMD_SET_PORT_CFG = 0x00000122, 804 MB_CMD_SET_PORT_CFG = 0x00000122,
804 MB_CMD_GET_PORT_CFG = 0x00000123, 805 MB_CMD_GET_PORT_CFG = 0x00000123,
805 MB_CMD_GET_LINK_STS = 0x00000124, 806 MB_CMD_GET_LINK_STS = 0x00000124,
807 MB_CMD_SET_MGMNT_TFK_CTL = 0x00000160, /* Set Mgmnt Traffic Control */
808 MB_SET_MPI_TFK_STOP = (1 << 0),
809 MB_SET_MPI_TFK_RESUME = (1 << 1),
810 MB_CMD_GET_MGMNT_TFK_CTL = 0x00000161, /* Get Mgmnt Traffic Control */
811 MB_GET_MPI_TFK_STOPPED = (1 << 0),
812 MB_GET_MPI_TFK_FIFO_EMPTY = (1 << 1),
806 813
807 /* Mailbox Command Status. */ 814 /* Mailbox Command Status. */
808 MB_CMD_STS_GOOD = 0x00004000, /* Success. */ 815 MB_CMD_STS_GOOD = 0x00004000, /* Success. */
@@ -1168,7 +1175,7 @@ struct ricb {
1168#define RSS_RI6 0x40 1175#define RSS_RI6 0x40
1169#define RSS_RT6 0x80 1176#define RSS_RT6 0x80
1170 __le16 mask; 1177 __le16 mask;
1171 __le32 hash_cq_id[256]; 1178 u8 hash_cq_id[1024];
1172 __le32 ipv6_hash_key[10]; 1179 __le32 ipv6_hash_key[10];
1173 __le32 ipv4_hash_key[4]; 1180 __le32 ipv4_hash_key[4];
1174} __attribute((packed)); 1181} __attribute((packed));
@@ -1606,6 +1613,8 @@ int ql_read_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 *data);
1606int ql_mb_about_fw(struct ql_adapter *qdev); 1613int ql_mb_about_fw(struct ql_adapter *qdev);
1607void ql_link_on(struct ql_adapter *qdev); 1614void ql_link_on(struct ql_adapter *qdev);
1608void ql_link_off(struct ql_adapter *qdev); 1615void ql_link_off(struct ql_adapter *qdev);
1616int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control);
1617int ql_wait_fifo_empty(struct ql_adapter *qdev);
1609 1618
1610#if 1 1619#if 1
1611#define QL_ALL_DUMP 1620#define QL_ALL_DUMP
diff --git a/drivers/net/qlge/qlge_main.c b/drivers/net/qlge/qlge_main.c
index 61680715cde0..a2fc70a0d0cc 100644
--- a/drivers/net/qlge/qlge_main.c
+++ b/drivers/net/qlge/qlge_main.c
@@ -320,6 +320,37 @@ static int ql_set_mac_addr_reg(struct ql_adapter *qdev, u8 *addr, u32 type,
320 320
321 switch (type) { 321 switch (type) {
322 case MAC_ADDR_TYPE_MULTI_MAC: 322 case MAC_ADDR_TYPE_MULTI_MAC:
323 {
324 u32 upper = (addr[0] << 8) | addr[1];
325 u32 lower = (addr[2] << 24) | (addr[3] << 16) |
326 (addr[4] << 8) | (addr[5]);
327
328 status =
329 ql_wait_reg_rdy(qdev,
330 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
331 if (status)
332 goto exit;
333 ql_write32(qdev, MAC_ADDR_IDX, (offset++) |
334 (index << MAC_ADDR_IDX_SHIFT) |
335 type | MAC_ADDR_E);
336 ql_write32(qdev, MAC_ADDR_DATA, lower);
337 status =
338 ql_wait_reg_rdy(qdev,
339 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
340 if (status)
341 goto exit;
342 ql_write32(qdev, MAC_ADDR_IDX, (offset++) |
343 (index << MAC_ADDR_IDX_SHIFT) |
344 type | MAC_ADDR_E);
345
346 ql_write32(qdev, MAC_ADDR_DATA, upper);
347 status =
348 ql_wait_reg_rdy(qdev,
349 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
350 if (status)
351 goto exit;
352 break;
353 }
323 case MAC_ADDR_TYPE_CAM_MAC: 354 case MAC_ADDR_TYPE_CAM_MAC:
324 { 355 {
325 u32 cam_output; 356 u32 cam_output;
@@ -365,16 +396,14 @@ static int ql_set_mac_addr_reg(struct ql_adapter *qdev, u8 *addr, u32 type,
365 and possibly the function id. Right now we hardcode 396 and possibly the function id. Right now we hardcode
366 the route field to NIC core. 397 the route field to NIC core.
367 */ 398 */
368 if (type == MAC_ADDR_TYPE_CAM_MAC) { 399 cam_output = (CAM_OUT_ROUTE_NIC |
369 cam_output = (CAM_OUT_ROUTE_NIC | 400 (qdev->
370 (qdev-> 401 func << CAM_OUT_FUNC_SHIFT) |
371 func << CAM_OUT_FUNC_SHIFT) | 402 (0 << CAM_OUT_CQ_ID_SHIFT));
372 (0 << CAM_OUT_CQ_ID_SHIFT)); 403 if (qdev->vlgrp)
373 if (qdev->vlgrp) 404 cam_output |= CAM_OUT_RV;
374 cam_output |= CAM_OUT_RV; 405 /* route to NIC core */
375 /* route to NIC core */ 406 ql_write32(qdev, MAC_ADDR_DATA, cam_output);
376 ql_write32(qdev, MAC_ADDR_DATA, cam_output);
377 }
378 break; 407 break;
379 } 408 }
380 case MAC_ADDR_TYPE_VLAN: 409 case MAC_ADDR_TYPE_VLAN:
@@ -546,14 +575,14 @@ static int ql_set_routing_reg(struct ql_adapter *qdev, u32 index, u32 mask,
546 } 575 }
547 case RT_IDX_MCAST: /* Pass up All Multicast frames. */ 576 case RT_IDX_MCAST: /* Pass up All Multicast frames. */
548 { 577 {
549 value = RT_IDX_DST_CAM_Q | /* dest */ 578 value = RT_IDX_DST_DFLT_Q | /* dest */
550 RT_IDX_TYPE_NICQ | /* type */ 579 RT_IDX_TYPE_NICQ | /* type */
551 (RT_IDX_ALLMULTI_SLOT << RT_IDX_IDX_SHIFT);/* index */ 580 (RT_IDX_ALLMULTI_SLOT << RT_IDX_IDX_SHIFT);/* index */
552 break; 581 break;
553 } 582 }
554 case RT_IDX_MCAST_MATCH: /* Pass up matched Multicast frames. */ 583 case RT_IDX_MCAST_MATCH: /* Pass up matched Multicast frames. */
555 { 584 {
556 value = RT_IDX_DST_CAM_Q | /* dest */ 585 value = RT_IDX_DST_DFLT_Q | /* dest */
557 RT_IDX_TYPE_NICQ | /* type */ 586 RT_IDX_TYPE_NICQ | /* type */
558 (RT_IDX_MCAST_MATCH_SLOT << RT_IDX_IDX_SHIFT);/* index */ 587 (RT_IDX_MCAST_MATCH_SLOT << RT_IDX_IDX_SHIFT);/* index */
559 break; 588 break;
@@ -3077,6 +3106,12 @@ err_irq:
3077 3106
3078static int ql_start_rss(struct ql_adapter *qdev) 3107static int ql_start_rss(struct ql_adapter *qdev)
3079{ 3108{
3109 u8 init_hash_seed[] = {0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
3110 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f,
3111 0xb0, 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b,
3112 0x30, 0xb4, 0x77, 0xcb, 0x2d, 0xa3, 0x80,
3113 0x30, 0xf2, 0x0c, 0x6a, 0x42, 0xb7, 0x3b,
3114 0xbe, 0xac, 0x01, 0xfa};
3080 struct ricb *ricb = &qdev->ricb; 3115 struct ricb *ricb = &qdev->ricb;
3081 int status = 0; 3116 int status = 0;
3082 int i; 3117 int i;
@@ -3086,21 +3121,17 @@ static int ql_start_rss(struct ql_adapter *qdev)
3086 3121
3087 ricb->base_cq = RSS_L4K; 3122 ricb->base_cq = RSS_L4K;
3088 ricb->flags = 3123 ricb->flags =
3089 (RSS_L6K | RSS_LI | RSS_LB | RSS_LM | RSS_RI4 | RSS_RI6 | RSS_RT4 | 3124 (RSS_L6K | RSS_LI | RSS_LB | RSS_LM | RSS_RT4 | RSS_RT6);
3090 RSS_RT6); 3125 ricb->mask = cpu_to_le16((u16)(0x3ff));
3091 ricb->mask = cpu_to_le16(qdev->rss_ring_count - 1);
3092 3126
3093 /* 3127 /*
3094 * Fill out the Indirection Table. 3128 * Fill out the Indirection Table.
3095 */ 3129 */
3096 for (i = 0; i < 256; i++) 3130 for (i = 0; i < 1024; i++)
3097 hash_id[i] = i & (qdev->rss_ring_count - 1); 3131 hash_id[i] = (i & (qdev->rss_ring_count - 1));
3098 3132
3099 /* 3133 memcpy((void *)&ricb->ipv6_hash_key[0], init_hash_seed, 40);
3100 * Random values for the IPv6 and IPv4 Hash Keys. 3134 memcpy((void *)&ricb->ipv4_hash_key[0], init_hash_seed, 16);
3101 */
3102 get_random_bytes((void *)&ricb->ipv6_hash_key[0], 40);
3103 get_random_bytes((void *)&ricb->ipv4_hash_key[0], 16);
3104 3135
3105 QPRINTK(qdev, IFUP, DEBUG, "Initializing RSS.\n"); 3136 QPRINTK(qdev, IFUP, DEBUG, "Initializing RSS.\n");
3106 3137
@@ -3239,6 +3270,13 @@ static int ql_adapter_initialize(struct ql_adapter *qdev)
3239 ql_write32(qdev, SPLT_HDR, SPLT_HDR_EP | 3270 ql_write32(qdev, SPLT_HDR, SPLT_HDR_EP |
3240 min(SMALL_BUFFER_SIZE, MAX_SPLIT_SIZE)); 3271 min(SMALL_BUFFER_SIZE, MAX_SPLIT_SIZE));
3241 3272
3273 /* Set RX packet routing to use port/pci function on which the
3274 * packet arrived on in addition to usual frame routing.
3275 * This is helpful on bonding where both interfaces can have
3276 * the same MAC address.
3277 */
3278 ql_write32(qdev, RST_FO, RST_FO_RR_MASK | RST_FO_RR_RCV_FUNC_CQ);
3279
3242 /* Start up the rx queues. */ 3280 /* Start up the rx queues. */
3243 for (i = 0; i < qdev->rx_ring_count; i++) { 3281 for (i = 0; i < qdev->rx_ring_count; i++) {
3244 status = ql_start_rx_ring(qdev, &qdev->rx_ring[i]); 3282 status = ql_start_rx_ring(qdev, &qdev->rx_ring[i]);
@@ -3311,6 +3349,13 @@ static int ql_adapter_reset(struct ql_adapter *qdev)
3311 3349
3312 end_jiffies = jiffies + 3350 end_jiffies = jiffies +
3313 max((unsigned long)1, usecs_to_jiffies(30)); 3351 max((unsigned long)1, usecs_to_jiffies(30));
3352
3353 /* Stop management traffic. */
3354 ql_mb_set_mgmnt_traffic_ctl(qdev, MB_SET_MPI_TFK_STOP);
3355
3356 /* Wait for the NIC and MGMNT FIFOs to empty. */
3357 ql_wait_fifo_empty(qdev);
3358
3314 ql_write32(qdev, RST_FO, (RST_FO_FR << 16) | RST_FO_FR); 3359 ql_write32(qdev, RST_FO, (RST_FO_FR << 16) | RST_FO_FR);
3315 3360
3316 do { 3361 do {
@@ -3326,6 +3371,8 @@ static int ql_adapter_reset(struct ql_adapter *qdev)
3326 status = -ETIMEDOUT; 3371 status = -ETIMEDOUT;
3327 } 3372 }
3328 3373
3374 /* Resume management traffic. */
3375 ql_mb_set_mgmnt_traffic_ctl(qdev, MB_SET_MPI_TFK_RESUME);
3329 return status; 3376 return status;
3330} 3377}
3331 3378
@@ -3704,6 +3751,12 @@ static void ql_asic_reset_work(struct work_struct *work)
3704 status = ql_adapter_up(qdev); 3751 status = ql_adapter_up(qdev);
3705 if (status) 3752 if (status)
3706 goto error; 3753 goto error;
3754
3755 /* Restore rx mode. */
3756 clear_bit(QL_ALLMULTI, &qdev->flags);
3757 clear_bit(QL_PROMISCUOUS, &qdev->flags);
3758 qlge_set_multicast_list(qdev->ndev);
3759
3707 rtnl_unlock(); 3760 rtnl_unlock();
3708 return; 3761 return;
3709error: 3762error:
@@ -3863,6 +3916,9 @@ static int __devinit ql_init_device(struct pci_dev *pdev,
3863 goto err_out; 3916 goto err_out;
3864 } 3917 }
3865 3918
3919 /* Set PCIe reset type for EEH to fundamental. */
3920 pdev->needs_freset = 1;
3921 pci_save_state(pdev);
3866 qdev->reg_base = 3922 qdev->reg_base =
3867 ioremap_nocache(pci_resource_start(pdev, 1), 3923 ioremap_nocache(pci_resource_start(pdev, 1),
3868 pci_resource_len(pdev, 1)); 3924 pci_resource_len(pdev, 1));
@@ -4017,6 +4073,33 @@ static void __devexit qlge_remove(struct pci_dev *pdev)
4017 free_netdev(ndev); 4073 free_netdev(ndev);
4018} 4074}
4019 4075
4076/* Clean up resources without touching hardware. */
4077static void ql_eeh_close(struct net_device *ndev)
4078{
4079 int i;
4080 struct ql_adapter *qdev = netdev_priv(ndev);
4081
4082 if (netif_carrier_ok(ndev)) {
4083 netif_carrier_off(ndev);
4084 netif_stop_queue(ndev);
4085 }
4086
4087 if (test_bit(QL_ADAPTER_UP, &qdev->flags))
4088 cancel_delayed_work_sync(&qdev->asic_reset_work);
4089 cancel_delayed_work_sync(&qdev->mpi_reset_work);
4090 cancel_delayed_work_sync(&qdev->mpi_work);
4091 cancel_delayed_work_sync(&qdev->mpi_idc_work);
4092 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
4093
4094 for (i = 0; i < qdev->rss_ring_count; i++)
4095 netif_napi_del(&qdev->rx_ring[i].napi);
4096
4097 clear_bit(QL_ADAPTER_UP, &qdev->flags);
4098 ql_tx_ring_clean(qdev);
4099 ql_free_rx_buffers(qdev);
4100 ql_release_adapter_resources(qdev);
4101}
4102
4020/* 4103/*
4021 * This callback is called by the PCI subsystem whenever 4104 * This callback is called by the PCI subsystem whenever
4022 * a PCI bus error is detected. 4105 * a PCI bus error is detected.
@@ -4025,17 +4108,21 @@ static pci_ers_result_t qlge_io_error_detected(struct pci_dev *pdev,
4025 enum pci_channel_state state) 4108 enum pci_channel_state state)
4026{ 4109{
4027 struct net_device *ndev = pci_get_drvdata(pdev); 4110 struct net_device *ndev = pci_get_drvdata(pdev);
4028 struct ql_adapter *qdev = netdev_priv(ndev);
4029 4111
4030 netif_device_detach(ndev); 4112 switch (state) {
4031 4113 case pci_channel_io_normal:
4032 if (state == pci_channel_io_perm_failure) 4114 return PCI_ERS_RESULT_CAN_RECOVER;
4115 case pci_channel_io_frozen:
4116 netif_device_detach(ndev);
4117 if (netif_running(ndev))
4118 ql_eeh_close(ndev);
4119 pci_disable_device(pdev);
4120 return PCI_ERS_RESULT_NEED_RESET;
4121 case pci_channel_io_perm_failure:
4122 dev_err(&pdev->dev,
4123 "%s: pci_channel_io_perm_failure.\n", __func__);
4033 return PCI_ERS_RESULT_DISCONNECT; 4124 return PCI_ERS_RESULT_DISCONNECT;
4034 4125 }
4035 if (netif_running(ndev))
4036 ql_adapter_down(qdev);
4037
4038 pci_disable_device(pdev);
4039 4126
4040 /* Request a slot reset. */ 4127 /* Request a slot reset. */
4041 return PCI_ERS_RESULT_NEED_RESET; 4128 return PCI_ERS_RESULT_NEED_RESET;
@@ -4052,25 +4139,15 @@ static pci_ers_result_t qlge_io_slot_reset(struct pci_dev *pdev)
4052 struct net_device *ndev = pci_get_drvdata(pdev); 4139 struct net_device *ndev = pci_get_drvdata(pdev);
4053 struct ql_adapter *qdev = netdev_priv(ndev); 4140 struct ql_adapter *qdev = netdev_priv(ndev);
4054 4141
4142 pdev->error_state = pci_channel_io_normal;
4143
4144 pci_restore_state(pdev);
4055 if (pci_enable_device(pdev)) { 4145 if (pci_enable_device(pdev)) {
4056 QPRINTK(qdev, IFUP, ERR, 4146 QPRINTK(qdev, IFUP, ERR,
4057 "Cannot re-enable PCI device after reset.\n"); 4147 "Cannot re-enable PCI device after reset.\n");
4058 return PCI_ERS_RESULT_DISCONNECT; 4148 return PCI_ERS_RESULT_DISCONNECT;
4059 } 4149 }
4060
4061 pci_set_master(pdev); 4150 pci_set_master(pdev);
4062
4063 netif_carrier_off(ndev);
4064 ql_adapter_reset(qdev);
4065
4066 /* Make sure the EEPROM is good */
4067 memcpy(ndev->perm_addr, ndev->dev_addr, ndev->addr_len);
4068
4069 if (!is_valid_ether_addr(ndev->perm_addr)) {
4070 QPRINTK(qdev, IFUP, ERR, "After reset, invalid MAC address.\n");
4071 return PCI_ERS_RESULT_DISCONNECT;
4072 }
4073
4074 return PCI_ERS_RESULT_RECOVERED; 4151 return PCI_ERS_RESULT_RECOVERED;
4075} 4152}
4076 4153
@@ -4078,17 +4155,21 @@ static void qlge_io_resume(struct pci_dev *pdev)
4078{ 4155{
4079 struct net_device *ndev = pci_get_drvdata(pdev); 4156 struct net_device *ndev = pci_get_drvdata(pdev);
4080 struct ql_adapter *qdev = netdev_priv(ndev); 4157 struct ql_adapter *qdev = netdev_priv(ndev);
4158 int err = 0;
4081 4159
4082 pci_set_master(pdev); 4160 if (ql_adapter_reset(qdev))
4083 4161 QPRINTK(qdev, DRV, ERR, "reset FAILED!\n");
4084 if (netif_running(ndev)) { 4162 if (netif_running(ndev)) {
4085 if (ql_adapter_up(qdev)) { 4163 err = qlge_open(ndev);
4164 if (err) {
4086 QPRINTK(qdev, IFUP, ERR, 4165 QPRINTK(qdev, IFUP, ERR,
4087 "Device initialization failed after reset.\n"); 4166 "Device initialization failed after reset.\n");
4088 return; 4167 return;
4089 } 4168 }
4169 } else {
4170 QPRINTK(qdev, IFUP, ERR,
4171 "Device was not running prior to EEH.\n");
4090 } 4172 }
4091
4092 netif_device_attach(ndev); 4173 netif_device_attach(ndev);
4093} 4174}
4094 4175
diff --git a/drivers/net/qlge/qlge_mpi.c b/drivers/net/qlge/qlge_mpi.c
index c2e43073047e..aec05f266107 100644
--- a/drivers/net/qlge/qlge_mpi.c
+++ b/drivers/net/qlge/qlge_mpi.c
@@ -470,7 +470,8 @@ end:
470 */ 470 */
471static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp) 471static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
472{ 472{
473 int status, count; 473 int status;
474 unsigned long count;
474 475
475 476
476 /* Begin polled mode for MPI */ 477 /* Begin polled mode for MPI */
@@ -491,14 +492,14 @@ static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
491 /* Wait for the command to complete. We loop 492 /* Wait for the command to complete. We loop
492 * here because some AEN might arrive while 493 * here because some AEN might arrive while
493 * we're waiting for the mailbox command to 494 * we're waiting for the mailbox command to
494 * complete. If more than 5 arrive then we can 495 * complete. If more than 5 seconds expire we can
495 * assume something is wrong. */ 496 * assume something is wrong. */
496 count = 5; 497 count = jiffies + HZ * MAILBOX_TIMEOUT;
497 do { 498 do {
498 /* Wait for the interrupt to come in. */ 499 /* Wait for the interrupt to come in. */
499 status = ql_wait_mbx_cmd_cmplt(qdev); 500 status = ql_wait_mbx_cmd_cmplt(qdev);
500 if (status) 501 if (status)
501 goto end; 502 continue;
502 503
503 /* Process the event. If it's an AEN, it 504 /* Process the event. If it's an AEN, it
504 * will be handled in-line or a worker 505 * will be handled in-line or a worker
@@ -517,15 +518,15 @@ static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
517 MB_CMD_STS_GOOD) || 518 MB_CMD_STS_GOOD) ||
518 ((mbcp->mbox_out[0] & 0x0000f000) == 519 ((mbcp->mbox_out[0] & 0x0000f000) ==
519 MB_CMD_STS_INTRMDT)) 520 MB_CMD_STS_INTRMDT))
520 break; 521 goto done;
521 } while (--count); 522 } while (time_before(jiffies, count));
522 523
523 if (!count) { 524 QPRINTK(qdev, DRV, ERR,
524 QPRINTK(qdev, DRV, ERR, 525 "Timed out waiting for mailbox complete.\n");
525 "Timed out waiting for mailbox complete.\n"); 526 status = -ETIMEDOUT;
526 status = -ETIMEDOUT; 527 goto end;
527 goto end; 528
528 } 529done:
529 530
530 /* Now we can clear the interrupt condition 531 /* Now we can clear the interrupt condition
531 * and look at our status. 532 * and look at our status.
@@ -768,6 +769,95 @@ static int ql_idc_wait(struct ql_adapter *qdev)
768 return status; 769 return status;
769} 770}
770 771
772int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control)
773{
774 struct mbox_params mbc;
775 struct mbox_params *mbcp = &mbc;
776 int status;
777
778 memset(mbcp, 0, sizeof(struct mbox_params));
779
780 mbcp->in_count = 1;
781 mbcp->out_count = 2;
782
783 mbcp->mbox_in[0] = MB_CMD_SET_MGMNT_TFK_CTL;
784 mbcp->mbox_in[1] = control;
785
786 status = ql_mailbox_command(qdev, mbcp);
787 if (status)
788 return status;
789
790 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD)
791 return status;
792
793 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
794 QPRINTK(qdev, DRV, ERR,
795 "Command not supported by firmware.\n");
796 status = -EINVAL;
797 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
798 /* This indicates that the firmware is
799 * already in the state we are trying to
800 * change it to.
801 */
802 QPRINTK(qdev, DRV, ERR,
803 "Command parameters make no change.\n");
804 }
805 return status;
806}
807
808/* Returns a negative error code or the mailbox command status. */
809static int ql_mb_get_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 *control)
810{
811 struct mbox_params mbc;
812 struct mbox_params *mbcp = &mbc;
813 int status;
814
815 memset(mbcp, 0, sizeof(struct mbox_params));
816 *control = 0;
817
818 mbcp->in_count = 1;
819 mbcp->out_count = 1;
820
821 mbcp->mbox_in[0] = MB_CMD_GET_MGMNT_TFK_CTL;
822
823 status = ql_mailbox_command(qdev, mbcp);
824 if (status)
825 return status;
826
827 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) {
828 *control = mbcp->mbox_in[1];
829 return status;
830 }
831
832 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
833 QPRINTK(qdev, DRV, ERR,
834 "Command not supported by firmware.\n");
835 status = -EINVAL;
836 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
837 QPRINTK(qdev, DRV, ERR,
838 "Failed to get MPI traffic control.\n");
839 status = -EIO;
840 }
841 return status;
842}
843
844int ql_wait_fifo_empty(struct ql_adapter *qdev)
845{
846 int count = 5;
847 u32 mgmnt_fifo_empty;
848 u32 nic_fifo_empty;
849
850 do {
851 nic_fifo_empty = ql_read32(qdev, STS) & STS_NFE;
852 ql_mb_get_mgmnt_traffic_ctl(qdev, &mgmnt_fifo_empty);
853 mgmnt_fifo_empty &= MB_GET_MPI_TFK_FIFO_EMPTY;
854 if (nic_fifo_empty && mgmnt_fifo_empty)
855 return 0;
856 msleep(100);
857 } while (count-- > 0);
858 return -ETIMEDOUT;
859}
860
771/* API called in work thread context to set new TX/RX 861/* API called in work thread context to set new TX/RX
772 * maximum frame size values to match MTU. 862 * maximum frame size values to match MTU.
773 */ 863 */
@@ -876,6 +966,8 @@ void ql_mpi_work(struct work_struct *work)
876 int err = 0; 966 int err = 0;
877 967
878 rtnl_lock(); 968 rtnl_lock();
969 /* Begin polled mode for MPI */
970 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
879 971
880 while (ql_read32(qdev, STS) & STS_PI) { 972 while (ql_read32(qdev, STS) & STS_PI) {
881 memset(mbcp, 0, sizeof(struct mbox_params)); 973 memset(mbcp, 0, sizeof(struct mbox_params));
@@ -888,6 +980,8 @@ void ql_mpi_work(struct work_struct *work)
888 break; 980 break;
889 } 981 }
890 982
983 /* End polled mode for MPI */
984 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
891 rtnl_unlock(); 985 rtnl_unlock();
892 ql_enable_completion_interrupt(qdev, 0); 986 ql_enable_completion_interrupt(qdev, 0);
893} 987}
diff --git a/drivers/net/r6040.c b/drivers/net/r6040.c
index 7dfcb58b0eb4..8b14c6eda7c3 100644
--- a/drivers/net/r6040.c
+++ b/drivers/net/r6040.c
@@ -1085,7 +1085,7 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
1085 int bar = 0; 1085 int bar = 0;
1086 u16 *adrp; 1086 u16 *adrp;
1087 1087
1088 printk(KERN_INFO "%s\n", version); 1088 printk("%s\n", version);
1089 1089
1090 err = pci_enable_device(pdev); 1090 err = pci_enable_device(pdev);
1091 if (err) 1091 if (err)
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 50c6a3cfe439..0fe2fc90f207 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -115,7 +115,9 @@ enum mac_version {
115 RTL_GIGA_MAC_VER_22 = 0x16, // 8168C 115 RTL_GIGA_MAC_VER_22 = 0x16, // 8168C
116 RTL_GIGA_MAC_VER_23 = 0x17, // 8168CP 116 RTL_GIGA_MAC_VER_23 = 0x17, // 8168CP
117 RTL_GIGA_MAC_VER_24 = 0x18, // 8168CP 117 RTL_GIGA_MAC_VER_24 = 0x18, // 8168CP
118 RTL_GIGA_MAC_VER_25 = 0x19 // 8168D 118 RTL_GIGA_MAC_VER_25 = 0x19, // 8168D
119 RTL_GIGA_MAC_VER_26 = 0x1a, // 8168D
120 RTL_GIGA_MAC_VER_27 = 0x1b // 8168DP
119}; 121};
120 122
121#define _R(NAME,MAC,MASK) \ 123#define _R(NAME,MAC,MASK) \
@@ -150,7 +152,9 @@ static const struct {
150 _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_22, 0xff7e1880), // PCI-E 152 _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_22, 0xff7e1880), // PCI-E
151 _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_23, 0xff7e1880), // PCI-E 153 _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_23, 0xff7e1880), // PCI-E
152 _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_24, 0xff7e1880), // PCI-E 154 _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_24, 0xff7e1880), // PCI-E
153 _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_25, 0xff7e1880) // PCI-E 155 _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_25, 0xff7e1880), // PCI-E
156 _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_26, 0xff7e1880), // PCI-E
157 _R("RTL8168dp/8111dp", RTL_GIGA_MAC_VER_27, 0xff7e1880) // PCI-E
154}; 158};
155#undef _R 159#undef _R
156 160
@@ -253,6 +257,13 @@ enum rtl8168_8101_registers {
253 DBG_REG = 0xd1, 257 DBG_REG = 0xd1,
254#define FIX_NAK_1 (1 << 4) 258#define FIX_NAK_1 (1 << 4)
255#define FIX_NAK_2 (1 << 3) 259#define FIX_NAK_2 (1 << 3)
260 EFUSEAR = 0xdc,
261#define EFUSEAR_FLAG 0x80000000
262#define EFUSEAR_WRITE_CMD 0x80000000
263#define EFUSEAR_READ_CMD 0x00000000
264#define EFUSEAR_REG_MASK 0x03ff
265#define EFUSEAR_REG_SHIFT 8
266#define EFUSEAR_DATA_MASK 0xff
256}; 267};
257 268
258enum rtl_register_content { 269enum rtl_register_content {
@@ -568,6 +579,14 @@ static void mdio_patch(void __iomem *ioaddr, int reg_addr, int value)
568 mdio_write(ioaddr, reg_addr, mdio_read(ioaddr, reg_addr) | value); 579 mdio_write(ioaddr, reg_addr, mdio_read(ioaddr, reg_addr) | value);
569} 580}
570 581
582static void mdio_plus_minus(void __iomem *ioaddr, int reg_addr, int p, int m)
583{
584 int val;
585
586 val = mdio_read(ioaddr, reg_addr);
587 mdio_write(ioaddr, reg_addr, (val | p) & ~m);
588}
589
571static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, 590static void rtl_mdio_write(struct net_device *dev, int phy_id, int location,
572 int val) 591 int val)
573{ 592{
@@ -651,6 +670,24 @@ static u32 rtl_csi_read(void __iomem *ioaddr, int addr)
651 return value; 670 return value;
652} 671}
653 672
673static u8 rtl8168d_efuse_read(void __iomem *ioaddr, int reg_addr)
674{
675 u8 value = 0xff;
676 unsigned int i;
677
678 RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT);
679
680 for (i = 0; i < 300; i++) {
681 if (RTL_R32(EFUSEAR) & EFUSEAR_FLAG) {
682 value = RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK;
683 break;
684 }
685 udelay(100);
686 }
687
688 return value;
689}
690
654static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr) 691static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr)
655{ 692{
656 RTL_W16(IntrMask, 0x0000); 693 RTL_W16(IntrMask, 0x0000);
@@ -992,7 +1029,10 @@ static void rtl8169_vlan_rx_register(struct net_device *dev,
992 1029
993 spin_lock_irqsave(&tp->lock, flags); 1030 spin_lock_irqsave(&tp->lock, flags);
994 tp->vlgrp = grp; 1031 tp->vlgrp = grp;
995 if (tp->vlgrp) 1032 /*
1033 * Do not disable RxVlan on 8110SCd.
1034 */
1035 if (tp->vlgrp || (tp->mac_version == RTL_GIGA_MAC_VER_05))
996 tp->cp_cmd |= RxVlan; 1036 tp->cp_cmd |= RxVlan;
997 else 1037 else
998 tp->cp_cmd &= ~RxVlan; 1038 tp->cp_cmd &= ~RxVlan;
@@ -1243,7 +1283,10 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp,
1243 int mac_version; 1283 int mac_version;
1244 } mac_info[] = { 1284 } mac_info[] = {
1245 /* 8168D family. */ 1285 /* 8168D family. */
1246 { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_25 }, 1286 { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 },
1287 { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 },
1288 { 0x7c800000, 0x28800000, RTL_GIGA_MAC_VER_27 },
1289 { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 },
1247 1290
1248 /* 8168C family. */ 1291 /* 8168C family. */
1249 { 0x7cf00000, 0x3ca00000, RTL_GIGA_MAC_VER_24 }, 1292 { 0x7cf00000, 0x3ca00000, RTL_GIGA_MAC_VER_24 },
@@ -1648,74 +1691,903 @@ static void rtl8168c_4_hw_phy_config(void __iomem *ioaddr)
1648 rtl8168c_3_hw_phy_config(ioaddr); 1691 rtl8168c_3_hw_phy_config(ioaddr);
1649} 1692}
1650 1693
1651static void rtl8168d_hw_phy_config(void __iomem *ioaddr) 1694static void rtl8168d_1_hw_phy_config(void __iomem *ioaddr)
1652{ 1695{
1653 struct phy_reg phy_reg_init_0[] = { 1696 static struct phy_reg phy_reg_init_0[] = {
1654 { 0x1f, 0x0001 }, 1697 { 0x1f, 0x0001 },
1655 { 0x09, 0x2770 }, 1698 { 0x06, 0x4064 },
1656 { 0x08, 0x04d0 }, 1699 { 0x07, 0x2863 },
1657 { 0x0b, 0xad15 }, 1700 { 0x08, 0x059c },
1658 { 0x0c, 0x5bf0 }, 1701 { 0x09, 0x26b4 },
1659 { 0x1c, 0xf101 }, 1702 { 0x0a, 0x6a19 },
1703 { 0x0b, 0xdcc8 },
1704 { 0x10, 0xf06d },
1705 { 0x14, 0x7f68 },
1706 { 0x18, 0x7fd9 },
1707 { 0x1c, 0xf0ff },
1708 { 0x1d, 0x3d9c },
1660 { 0x1f, 0x0003 }, 1709 { 0x1f, 0x0003 },
1661 { 0x14, 0x94d7 }, 1710 { 0x12, 0xf49f },
1662 { 0x12, 0xf4d6 }, 1711 { 0x13, 0x070b },
1663 { 0x09, 0xca0f }, 1712 { 0x1a, 0x05ad },
1664 { 0x1f, 0x0002 }, 1713 { 0x14, 0x94c0 }
1665 { 0x0b, 0x0b10 }, 1714 };
1666 { 0x0c, 0xd1f7 }, 1715 static struct phy_reg phy_reg_init_1[] = {
1667 { 0x1f, 0x0002 },
1668 { 0x06, 0x5461 },
1669 { 0x1f, 0x0002 }, 1716 { 0x1f, 0x0002 },
1670 { 0x05, 0x6662 }, 1717 { 0x06, 0x5561 },
1718 { 0x1f, 0x0005 },
1719 { 0x05, 0x8332 },
1720 { 0x06, 0x5561 }
1721 };
1722 static struct phy_reg phy_reg_init_2[] = {
1723 { 0x1f, 0x0005 },
1724 { 0x05, 0xffc2 },
1725 { 0x1f, 0x0005 },
1726 { 0x05, 0x8000 },
1727 { 0x06, 0xf8f9 },
1728 { 0x06, 0xfaef },
1729 { 0x06, 0x59ee },
1730 { 0x06, 0xf8ea },
1731 { 0x06, 0x00ee },
1732 { 0x06, 0xf8eb },
1733 { 0x06, 0x00e0 },
1734 { 0x06, 0xf87c },
1735 { 0x06, 0xe1f8 },
1736 { 0x06, 0x7d59 },
1737 { 0x06, 0x0fef },
1738 { 0x06, 0x0139 },
1739 { 0x06, 0x029e },
1740 { 0x06, 0x06ef },
1741 { 0x06, 0x1039 },
1742 { 0x06, 0x089f },
1743 { 0x06, 0x2aee },
1744 { 0x06, 0xf8ea },
1745 { 0x06, 0x00ee },
1746 { 0x06, 0xf8eb },
1747 { 0x06, 0x01e0 },
1748 { 0x06, 0xf87c },
1749 { 0x06, 0xe1f8 },
1750 { 0x06, 0x7d58 },
1751 { 0x06, 0x409e },
1752 { 0x06, 0x0f39 },
1753 { 0x06, 0x46aa },
1754 { 0x06, 0x0bbf },
1755 { 0x06, 0x8290 },
1756 { 0x06, 0xd682 },
1757 { 0x06, 0x9802 },
1758 { 0x06, 0x014f },
1759 { 0x06, 0xae09 },
1760 { 0x06, 0xbf82 },
1761 { 0x06, 0x98d6 },
1762 { 0x06, 0x82a0 },
1763 { 0x06, 0x0201 },
1764 { 0x06, 0x4fef },
1765 { 0x06, 0x95fe },
1766 { 0x06, 0xfdfc },
1767 { 0x06, 0x05f8 },
1768 { 0x06, 0xf9fa },
1769 { 0x06, 0xeef8 },
1770 { 0x06, 0xea00 },
1771 { 0x06, 0xeef8 },
1772 { 0x06, 0xeb00 },
1773 { 0x06, 0xe2f8 },
1774 { 0x06, 0x7ce3 },
1775 { 0x06, 0xf87d },
1776 { 0x06, 0xa511 },
1777 { 0x06, 0x1112 },
1778 { 0x06, 0xd240 },
1779 { 0x06, 0xd644 },
1780 { 0x06, 0x4402 },
1781 { 0x06, 0x8217 },
1782 { 0x06, 0xd2a0 },
1783 { 0x06, 0xd6aa },
1784 { 0x06, 0xaa02 },
1785 { 0x06, 0x8217 },
1786 { 0x06, 0xae0f },
1787 { 0x06, 0xa544 },
1788 { 0x06, 0x4402 },
1789 { 0x06, 0xae4d },
1790 { 0x06, 0xa5aa },
1791 { 0x06, 0xaa02 },
1792 { 0x06, 0xae47 },
1793 { 0x06, 0xaf82 },
1794 { 0x06, 0x13ee },
1795 { 0x06, 0x834e },
1796 { 0x06, 0x00ee },
1797 { 0x06, 0x834d },
1798 { 0x06, 0x0fee },
1799 { 0x06, 0x834c },
1800 { 0x06, 0x0fee },
1801 { 0x06, 0x834f },
1802 { 0x06, 0x00ee },
1803 { 0x06, 0x8351 },
1804 { 0x06, 0x00ee },
1805 { 0x06, 0x834a },
1806 { 0x06, 0xffee },
1807 { 0x06, 0x834b },
1808 { 0x06, 0xffe0 },
1809 { 0x06, 0x8330 },
1810 { 0x06, 0xe183 },
1811 { 0x06, 0x3158 },
1812 { 0x06, 0xfee4 },
1813 { 0x06, 0xf88a },
1814 { 0x06, 0xe5f8 },
1815 { 0x06, 0x8be0 },
1816 { 0x06, 0x8332 },
1817 { 0x06, 0xe183 },
1818 { 0x06, 0x3359 },
1819 { 0x06, 0x0fe2 },
1820 { 0x06, 0x834d },
1821 { 0x06, 0x0c24 },
1822 { 0x06, 0x5af0 },
1823 { 0x06, 0x1e12 },
1824 { 0x06, 0xe4f8 },
1825 { 0x06, 0x8ce5 },
1826 { 0x06, 0xf88d },
1827 { 0x06, 0xaf82 },
1828 { 0x06, 0x13e0 },
1829 { 0x06, 0x834f },
1830 { 0x06, 0x10e4 },
1831 { 0x06, 0x834f },
1832 { 0x06, 0xe083 },
1833 { 0x06, 0x4e78 },
1834 { 0x06, 0x009f },
1835 { 0x06, 0x0ae0 },
1836 { 0x06, 0x834f },
1837 { 0x06, 0xa010 },
1838 { 0x06, 0xa5ee },
1839 { 0x06, 0x834e },
1840 { 0x06, 0x01e0 },
1841 { 0x06, 0x834e },
1842 { 0x06, 0x7805 },
1843 { 0x06, 0x9e9a },
1844 { 0x06, 0xe083 },
1845 { 0x06, 0x4e78 },
1846 { 0x06, 0x049e },
1847 { 0x06, 0x10e0 },
1848 { 0x06, 0x834e },
1849 { 0x06, 0x7803 },
1850 { 0x06, 0x9e0f },
1851 { 0x06, 0xe083 },
1852 { 0x06, 0x4e78 },
1853 { 0x06, 0x019e },
1854 { 0x06, 0x05ae },
1855 { 0x06, 0x0caf },
1856 { 0x06, 0x81f8 },
1857 { 0x06, 0xaf81 },
1858 { 0x06, 0xa3af },
1859 { 0x06, 0x81dc },
1860 { 0x06, 0xaf82 },
1861 { 0x06, 0x13ee },
1862 { 0x06, 0x8348 },
1863 { 0x06, 0x00ee },
1864 { 0x06, 0x8349 },
1865 { 0x06, 0x00e0 },
1866 { 0x06, 0x8351 },
1867 { 0x06, 0x10e4 },
1868 { 0x06, 0x8351 },
1869 { 0x06, 0x5801 },
1870 { 0x06, 0x9fea },
1871 { 0x06, 0xd000 },
1872 { 0x06, 0xd180 },
1873 { 0x06, 0x1f66 },
1874 { 0x06, 0xe2f8 },
1875 { 0x06, 0xeae3 },
1876 { 0x06, 0xf8eb },
1877 { 0x06, 0x5af8 },
1878 { 0x06, 0x1e20 },
1879 { 0x06, 0xe6f8 },
1880 { 0x06, 0xeae5 },
1881 { 0x06, 0xf8eb },
1882 { 0x06, 0xd302 },
1883 { 0x06, 0xb3fe },
1884 { 0x06, 0xe2f8 },
1885 { 0x06, 0x7cef },
1886 { 0x06, 0x325b },
1887 { 0x06, 0x80e3 },
1888 { 0x06, 0xf87d },
1889 { 0x06, 0x9e03 },
1890 { 0x06, 0x7dff },
1891 { 0x06, 0xff0d },
1892 { 0x06, 0x581c },
1893 { 0x06, 0x551a },
1894 { 0x06, 0x6511 },
1895 { 0x06, 0xa190 },
1896 { 0x06, 0xd3e2 },
1897 { 0x06, 0x8348 },
1898 { 0x06, 0xe383 },
1899 { 0x06, 0x491b },
1900 { 0x06, 0x56ab },
1901 { 0x06, 0x08ef },
1902 { 0x06, 0x56e6 },
1903 { 0x06, 0x8348 },
1904 { 0x06, 0xe783 },
1905 { 0x06, 0x4910 },
1906 { 0x06, 0xd180 },
1907 { 0x06, 0x1f66 },
1908 { 0x06, 0xa004 },
1909 { 0x06, 0xb9e2 },
1910 { 0x06, 0x8348 },
1911 { 0x06, 0xe383 },
1912 { 0x06, 0x49ef },
1913 { 0x06, 0x65e2 },
1914 { 0x06, 0x834a },
1915 { 0x06, 0xe383 },
1916 { 0x06, 0x4b1b },
1917 { 0x06, 0x56aa },
1918 { 0x06, 0x0eef },
1919 { 0x06, 0x56e6 },
1920 { 0x06, 0x834a },
1921 { 0x06, 0xe783 },
1922 { 0x06, 0x4be2 },
1923 { 0x06, 0x834d },
1924 { 0x06, 0xe683 },
1925 { 0x06, 0x4ce0 },
1926 { 0x06, 0x834d },
1927 { 0x06, 0xa000 },
1928 { 0x06, 0x0caf },
1929 { 0x06, 0x81dc },
1930 { 0x06, 0xe083 },
1931 { 0x06, 0x4d10 },
1932 { 0x06, 0xe483 },
1933 { 0x06, 0x4dae },
1934 { 0x06, 0x0480 },
1935 { 0x06, 0xe483 },
1936 { 0x06, 0x4de0 },
1937 { 0x06, 0x834e },
1938 { 0x06, 0x7803 },
1939 { 0x06, 0x9e0b },
1940 { 0x06, 0xe083 },
1941 { 0x06, 0x4e78 },
1942 { 0x06, 0x049e },
1943 { 0x06, 0x04ee },
1944 { 0x06, 0x834e },
1945 { 0x06, 0x02e0 },
1946 { 0x06, 0x8332 },
1947 { 0x06, 0xe183 },
1948 { 0x06, 0x3359 },
1949 { 0x06, 0x0fe2 },
1950 { 0x06, 0x834d },
1951 { 0x06, 0x0c24 },
1952 { 0x06, 0x5af0 },
1953 { 0x06, 0x1e12 },
1954 { 0x06, 0xe4f8 },
1955 { 0x06, 0x8ce5 },
1956 { 0x06, 0xf88d },
1957 { 0x06, 0xe083 },
1958 { 0x06, 0x30e1 },
1959 { 0x06, 0x8331 },
1960 { 0x06, 0x6801 },
1961 { 0x06, 0xe4f8 },
1962 { 0x06, 0x8ae5 },
1963 { 0x06, 0xf88b },
1964 { 0x06, 0xae37 },
1965 { 0x06, 0xee83 },
1966 { 0x06, 0x4e03 },
1967 { 0x06, 0xe083 },
1968 { 0x06, 0x4ce1 },
1969 { 0x06, 0x834d },
1970 { 0x06, 0x1b01 },
1971 { 0x06, 0x9e04 },
1972 { 0x06, 0xaaa1 },
1973 { 0x06, 0xaea8 },
1974 { 0x06, 0xee83 },
1975 { 0x06, 0x4e04 },
1976 { 0x06, 0xee83 },
1977 { 0x06, 0x4f00 },
1978 { 0x06, 0xaeab },
1979 { 0x06, 0xe083 },
1980 { 0x06, 0x4f78 },
1981 { 0x06, 0x039f },
1982 { 0x06, 0x14ee },
1983 { 0x06, 0x834e },
1984 { 0x06, 0x05d2 },
1985 { 0x06, 0x40d6 },
1986 { 0x06, 0x5554 },
1987 { 0x06, 0x0282 },
1988 { 0x06, 0x17d2 },
1989 { 0x06, 0xa0d6 },
1990 { 0x06, 0xba00 },
1991 { 0x06, 0x0282 },
1992 { 0x06, 0x17fe },
1993 { 0x06, 0xfdfc },
1994 { 0x06, 0x05f8 },
1995 { 0x06, 0xe0f8 },
1996 { 0x06, 0x60e1 },
1997 { 0x06, 0xf861 },
1998 { 0x06, 0x6802 },
1999 { 0x06, 0xe4f8 },
2000 { 0x06, 0x60e5 },
2001 { 0x06, 0xf861 },
2002 { 0x06, 0xe0f8 },
2003 { 0x06, 0x48e1 },
2004 { 0x06, 0xf849 },
2005 { 0x06, 0x580f },
2006 { 0x06, 0x1e02 },
2007 { 0x06, 0xe4f8 },
2008 { 0x06, 0x48e5 },
2009 { 0x06, 0xf849 },
2010 { 0x06, 0xd000 },
2011 { 0x06, 0x0282 },
2012 { 0x06, 0x5bbf },
2013 { 0x06, 0x8350 },
2014 { 0x06, 0xef46 },
2015 { 0x06, 0xdc19 },
2016 { 0x06, 0xddd0 },
2017 { 0x06, 0x0102 },
2018 { 0x06, 0x825b },
2019 { 0x06, 0x0282 },
2020 { 0x06, 0x77e0 },
2021 { 0x06, 0xf860 },
2022 { 0x06, 0xe1f8 },
2023 { 0x06, 0x6158 },
2024 { 0x06, 0xfde4 },
2025 { 0x06, 0xf860 },
2026 { 0x06, 0xe5f8 },
2027 { 0x06, 0x61fc },
2028 { 0x06, 0x04f9 },
2029 { 0x06, 0xfafb },
2030 { 0x06, 0xc6bf },
2031 { 0x06, 0xf840 },
2032 { 0x06, 0xbe83 },
2033 { 0x06, 0x50a0 },
2034 { 0x06, 0x0101 },
2035 { 0x06, 0x071b },
2036 { 0x06, 0x89cf },
2037 { 0x06, 0xd208 },
2038 { 0x06, 0xebdb },
2039 { 0x06, 0x19b2 },
2040 { 0x06, 0xfbff },
2041 { 0x06, 0xfefd },
2042 { 0x06, 0x04f8 },
2043 { 0x06, 0xe0f8 },
2044 { 0x06, 0x48e1 },
2045 { 0x06, 0xf849 },
2046 { 0x06, 0x6808 },
2047 { 0x06, 0xe4f8 },
2048 { 0x06, 0x48e5 },
2049 { 0x06, 0xf849 },
2050 { 0x06, 0x58f7 },
2051 { 0x06, 0xe4f8 },
2052 { 0x06, 0x48e5 },
2053 { 0x06, 0xf849 },
2054 { 0x06, 0xfc04 },
2055 { 0x06, 0x4d20 },
2056 { 0x06, 0x0002 },
2057 { 0x06, 0x4e22 },
2058 { 0x06, 0x0002 },
2059 { 0x06, 0x4ddf },
2060 { 0x06, 0xff01 },
2061 { 0x06, 0x4edd },
2062 { 0x06, 0xff01 },
2063 { 0x05, 0x83d4 },
2064 { 0x06, 0x8000 },
2065 { 0x05, 0x83d8 },
2066 { 0x06, 0x8051 },
2067 { 0x02, 0x6010 },
2068 { 0x03, 0xdc00 },
2069 { 0x05, 0xfff6 },
2070 { 0x06, 0x00fc },
1671 { 0x1f, 0x0000 }, 2071 { 0x1f, 0x0000 },
1672 { 0x14, 0x0060 }, 2072
1673 { 0x1f, 0x0000 }, 2073 { 0x1f, 0x0000 },
1674 { 0x0d, 0xf8a0 }, 2074 { 0x0d, 0xf880 },
2075 { 0x1f, 0x0000 }
2076 };
2077
2078 rtl_phy_write(ioaddr, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0));
2079
2080 mdio_write(ioaddr, 0x1f, 0x0002);
2081 mdio_plus_minus(ioaddr, 0x0b, 0x0010, 0x00ef);
2082 mdio_plus_minus(ioaddr, 0x0c, 0xa200, 0x5d00);
2083
2084 rtl_phy_write(ioaddr, phy_reg_init_1, ARRAY_SIZE(phy_reg_init_1));
2085
2086 if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) {
2087 struct phy_reg phy_reg_init[] = {
2088 { 0x1f, 0x0002 },
2089 { 0x05, 0x669a },
2090 { 0x1f, 0x0005 },
2091 { 0x05, 0x8330 },
2092 { 0x06, 0x669a },
2093 { 0x1f, 0x0002 }
2094 };
2095 int val;
2096
2097 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2098
2099 val = mdio_read(ioaddr, 0x0d);
2100
2101 if ((val & 0x00ff) != 0x006c) {
2102 u32 set[] = {
2103 0x0065, 0x0066, 0x0067, 0x0068,
2104 0x0069, 0x006a, 0x006b, 0x006c
2105 };
2106 int i;
2107
2108 mdio_write(ioaddr, 0x1f, 0x0002);
2109
2110 val &= 0xff00;
2111 for (i = 0; i < ARRAY_SIZE(set); i++)
2112 mdio_write(ioaddr, 0x0d, val | set[i]);
2113 }
2114 } else {
2115 struct phy_reg phy_reg_init[] = {
2116 { 0x1f, 0x0002 },
2117 { 0x05, 0x6662 },
2118 { 0x1f, 0x0005 },
2119 { 0x05, 0x8330 },
2120 { 0x06, 0x6662 }
2121 };
2122
2123 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2124 }
2125
2126 mdio_write(ioaddr, 0x1f, 0x0002);
2127 mdio_patch(ioaddr, 0x0d, 0x0300);
2128 mdio_patch(ioaddr, 0x0f, 0x0010);
2129
2130 mdio_write(ioaddr, 0x1f, 0x0002);
2131 mdio_plus_minus(ioaddr, 0x02, 0x0100, 0x0600);
2132 mdio_plus_minus(ioaddr, 0x03, 0x0000, 0xe000);
2133
2134 rtl_phy_write(ioaddr, phy_reg_init_2, ARRAY_SIZE(phy_reg_init_2));
2135}
2136
2137static void rtl8168d_2_hw_phy_config(void __iomem *ioaddr)
2138{
2139 static struct phy_reg phy_reg_init_0[] = {
2140 { 0x1f, 0x0001 },
2141 { 0x06, 0x4064 },
2142 { 0x07, 0x2863 },
2143 { 0x08, 0x059c },
2144 { 0x09, 0x26b4 },
2145 { 0x0a, 0x6a19 },
2146 { 0x0b, 0xdcc8 },
2147 { 0x10, 0xf06d },
2148 { 0x14, 0x7f68 },
2149 { 0x18, 0x7fd9 },
2150 { 0x1c, 0xf0ff },
2151 { 0x1d, 0x3d9c },
2152 { 0x1f, 0x0003 },
2153 { 0x12, 0xf49f },
2154 { 0x13, 0x070b },
2155 { 0x1a, 0x05ad },
2156 { 0x14, 0x94c0 },
2157
2158 { 0x1f, 0x0002 },
2159 { 0x06, 0x5561 },
1675 { 0x1f, 0x0005 }, 2160 { 0x1f, 0x0005 },
1676 { 0x05, 0xffc2 } 2161 { 0x05, 0x8332 },
2162 { 0x06, 0x5561 }
2163 };
2164 static struct phy_reg phy_reg_init_1[] = {
2165 { 0x1f, 0x0005 },
2166 { 0x05, 0xffc2 },
2167 { 0x1f, 0x0005 },
2168 { 0x05, 0x8000 },
2169 { 0x06, 0xf8f9 },
2170 { 0x06, 0xfaee },
2171 { 0x06, 0xf8ea },
2172 { 0x06, 0x00ee },
2173 { 0x06, 0xf8eb },
2174 { 0x06, 0x00e2 },
2175 { 0x06, 0xf87c },
2176 { 0x06, 0xe3f8 },
2177 { 0x06, 0x7da5 },
2178 { 0x06, 0x1111 },
2179 { 0x06, 0x12d2 },
2180 { 0x06, 0x40d6 },
2181 { 0x06, 0x4444 },
2182 { 0x06, 0x0281 },
2183 { 0x06, 0xc6d2 },
2184 { 0x06, 0xa0d6 },
2185 { 0x06, 0xaaaa },
2186 { 0x06, 0x0281 },
2187 { 0x06, 0xc6ae },
2188 { 0x06, 0x0fa5 },
2189 { 0x06, 0x4444 },
2190 { 0x06, 0x02ae },
2191 { 0x06, 0x4da5 },
2192 { 0x06, 0xaaaa },
2193 { 0x06, 0x02ae },
2194 { 0x06, 0x47af },
2195 { 0x06, 0x81c2 },
2196 { 0x06, 0xee83 },
2197 { 0x06, 0x4e00 },
2198 { 0x06, 0xee83 },
2199 { 0x06, 0x4d0f },
2200 { 0x06, 0xee83 },
2201 { 0x06, 0x4c0f },
2202 { 0x06, 0xee83 },
2203 { 0x06, 0x4f00 },
2204 { 0x06, 0xee83 },
2205 { 0x06, 0x5100 },
2206 { 0x06, 0xee83 },
2207 { 0x06, 0x4aff },
2208 { 0x06, 0xee83 },
2209 { 0x06, 0x4bff },
2210 { 0x06, 0xe083 },
2211 { 0x06, 0x30e1 },
2212 { 0x06, 0x8331 },
2213 { 0x06, 0x58fe },
2214 { 0x06, 0xe4f8 },
2215 { 0x06, 0x8ae5 },
2216 { 0x06, 0xf88b },
2217 { 0x06, 0xe083 },
2218 { 0x06, 0x32e1 },
2219 { 0x06, 0x8333 },
2220 { 0x06, 0x590f },
2221 { 0x06, 0xe283 },
2222 { 0x06, 0x4d0c },
2223 { 0x06, 0x245a },
2224 { 0x06, 0xf01e },
2225 { 0x06, 0x12e4 },
2226 { 0x06, 0xf88c },
2227 { 0x06, 0xe5f8 },
2228 { 0x06, 0x8daf },
2229 { 0x06, 0x81c2 },
2230 { 0x06, 0xe083 },
2231 { 0x06, 0x4f10 },
2232 { 0x06, 0xe483 },
2233 { 0x06, 0x4fe0 },
2234 { 0x06, 0x834e },
2235 { 0x06, 0x7800 },
2236 { 0x06, 0x9f0a },
2237 { 0x06, 0xe083 },
2238 { 0x06, 0x4fa0 },
2239 { 0x06, 0x10a5 },
2240 { 0x06, 0xee83 },
2241 { 0x06, 0x4e01 },
2242 { 0x06, 0xe083 },
2243 { 0x06, 0x4e78 },
2244 { 0x06, 0x059e },
2245 { 0x06, 0x9ae0 },
2246 { 0x06, 0x834e },
2247 { 0x06, 0x7804 },
2248 { 0x06, 0x9e10 },
2249 { 0x06, 0xe083 },
2250 { 0x06, 0x4e78 },
2251 { 0x06, 0x039e },
2252 { 0x06, 0x0fe0 },
2253 { 0x06, 0x834e },
2254 { 0x06, 0x7801 },
2255 { 0x06, 0x9e05 },
2256 { 0x06, 0xae0c },
2257 { 0x06, 0xaf81 },
2258 { 0x06, 0xa7af },
2259 { 0x06, 0x8152 },
2260 { 0x06, 0xaf81 },
2261 { 0x06, 0x8baf },
2262 { 0x06, 0x81c2 },
2263 { 0x06, 0xee83 },
2264 { 0x06, 0x4800 },
2265 { 0x06, 0xee83 },
2266 { 0x06, 0x4900 },
2267 { 0x06, 0xe083 },
2268 { 0x06, 0x5110 },
2269 { 0x06, 0xe483 },
2270 { 0x06, 0x5158 },
2271 { 0x06, 0x019f },
2272 { 0x06, 0xead0 },
2273 { 0x06, 0x00d1 },
2274 { 0x06, 0x801f },
2275 { 0x06, 0x66e2 },
2276 { 0x06, 0xf8ea },
2277 { 0x06, 0xe3f8 },
2278 { 0x06, 0xeb5a },
2279 { 0x06, 0xf81e },
2280 { 0x06, 0x20e6 },
2281 { 0x06, 0xf8ea },
2282 { 0x06, 0xe5f8 },
2283 { 0x06, 0xebd3 },
2284 { 0x06, 0x02b3 },
2285 { 0x06, 0xfee2 },
2286 { 0x06, 0xf87c },
2287 { 0x06, 0xef32 },
2288 { 0x06, 0x5b80 },
2289 { 0x06, 0xe3f8 },
2290 { 0x06, 0x7d9e },
2291 { 0x06, 0x037d },
2292 { 0x06, 0xffff },
2293 { 0x06, 0x0d58 },
2294 { 0x06, 0x1c55 },
2295 { 0x06, 0x1a65 },
2296 { 0x06, 0x11a1 },
2297 { 0x06, 0x90d3 },
2298 { 0x06, 0xe283 },
2299 { 0x06, 0x48e3 },
2300 { 0x06, 0x8349 },
2301 { 0x06, 0x1b56 },
2302 { 0x06, 0xab08 },
2303 { 0x06, 0xef56 },
2304 { 0x06, 0xe683 },
2305 { 0x06, 0x48e7 },
2306 { 0x06, 0x8349 },
2307 { 0x06, 0x10d1 },
2308 { 0x06, 0x801f },
2309 { 0x06, 0x66a0 },
2310 { 0x06, 0x04b9 },
2311 { 0x06, 0xe283 },
2312 { 0x06, 0x48e3 },
2313 { 0x06, 0x8349 },
2314 { 0x06, 0xef65 },
2315 { 0x06, 0xe283 },
2316 { 0x06, 0x4ae3 },
2317 { 0x06, 0x834b },
2318 { 0x06, 0x1b56 },
2319 { 0x06, 0xaa0e },
2320 { 0x06, 0xef56 },
2321 { 0x06, 0xe683 },
2322 { 0x06, 0x4ae7 },
2323 { 0x06, 0x834b },
2324 { 0x06, 0xe283 },
2325 { 0x06, 0x4de6 },
2326 { 0x06, 0x834c },
2327 { 0x06, 0xe083 },
2328 { 0x06, 0x4da0 },
2329 { 0x06, 0x000c },
2330 { 0x06, 0xaf81 },
2331 { 0x06, 0x8be0 },
2332 { 0x06, 0x834d },
2333 { 0x06, 0x10e4 },
2334 { 0x06, 0x834d },
2335 { 0x06, 0xae04 },
2336 { 0x06, 0x80e4 },
2337 { 0x06, 0x834d },
2338 { 0x06, 0xe083 },
2339 { 0x06, 0x4e78 },
2340 { 0x06, 0x039e },
2341 { 0x06, 0x0be0 },
2342 { 0x06, 0x834e },
2343 { 0x06, 0x7804 },
2344 { 0x06, 0x9e04 },
2345 { 0x06, 0xee83 },
2346 { 0x06, 0x4e02 },
2347 { 0x06, 0xe083 },
2348 { 0x06, 0x32e1 },
2349 { 0x06, 0x8333 },
2350 { 0x06, 0x590f },
2351 { 0x06, 0xe283 },
2352 { 0x06, 0x4d0c },
2353 { 0x06, 0x245a },
2354 { 0x06, 0xf01e },
2355 { 0x06, 0x12e4 },
2356 { 0x06, 0xf88c },
2357 { 0x06, 0xe5f8 },
2358 { 0x06, 0x8de0 },
2359 { 0x06, 0x8330 },
2360 { 0x06, 0xe183 },
2361 { 0x06, 0x3168 },
2362 { 0x06, 0x01e4 },
2363 { 0x06, 0xf88a },
2364 { 0x06, 0xe5f8 },
2365 { 0x06, 0x8bae },
2366 { 0x06, 0x37ee },
2367 { 0x06, 0x834e },
2368 { 0x06, 0x03e0 },
2369 { 0x06, 0x834c },
2370 { 0x06, 0xe183 },
2371 { 0x06, 0x4d1b },
2372 { 0x06, 0x019e },
2373 { 0x06, 0x04aa },
2374 { 0x06, 0xa1ae },
2375 { 0x06, 0xa8ee },
2376 { 0x06, 0x834e },
2377 { 0x06, 0x04ee },
2378 { 0x06, 0x834f },
2379 { 0x06, 0x00ae },
2380 { 0x06, 0xabe0 },
2381 { 0x06, 0x834f },
2382 { 0x06, 0x7803 },
2383 { 0x06, 0x9f14 },
2384 { 0x06, 0xee83 },
2385 { 0x06, 0x4e05 },
2386 { 0x06, 0xd240 },
2387 { 0x06, 0xd655 },
2388 { 0x06, 0x5402 },
2389 { 0x06, 0x81c6 },
2390 { 0x06, 0xd2a0 },
2391 { 0x06, 0xd6ba },
2392 { 0x06, 0x0002 },
2393 { 0x06, 0x81c6 },
2394 { 0x06, 0xfefd },
2395 { 0x06, 0xfc05 },
2396 { 0x06, 0xf8e0 },
2397 { 0x06, 0xf860 },
2398 { 0x06, 0xe1f8 },
2399 { 0x06, 0x6168 },
2400 { 0x06, 0x02e4 },
2401 { 0x06, 0xf860 },
2402 { 0x06, 0xe5f8 },
2403 { 0x06, 0x61e0 },
2404 { 0x06, 0xf848 },
2405 { 0x06, 0xe1f8 },
2406 { 0x06, 0x4958 },
2407 { 0x06, 0x0f1e },
2408 { 0x06, 0x02e4 },
2409 { 0x06, 0xf848 },
2410 { 0x06, 0xe5f8 },
2411 { 0x06, 0x49d0 },
2412 { 0x06, 0x0002 },
2413 { 0x06, 0x820a },
2414 { 0x06, 0xbf83 },
2415 { 0x06, 0x50ef },
2416 { 0x06, 0x46dc },
2417 { 0x06, 0x19dd },
2418 { 0x06, 0xd001 },
2419 { 0x06, 0x0282 },
2420 { 0x06, 0x0a02 },
2421 { 0x06, 0x8226 },
2422 { 0x06, 0xe0f8 },
2423 { 0x06, 0x60e1 },
2424 { 0x06, 0xf861 },
2425 { 0x06, 0x58fd },
2426 { 0x06, 0xe4f8 },
2427 { 0x06, 0x60e5 },
2428 { 0x06, 0xf861 },
2429 { 0x06, 0xfc04 },
2430 { 0x06, 0xf9fa },
2431 { 0x06, 0xfbc6 },
2432 { 0x06, 0xbff8 },
2433 { 0x06, 0x40be },
2434 { 0x06, 0x8350 },
2435 { 0x06, 0xa001 },
2436 { 0x06, 0x0107 },
2437 { 0x06, 0x1b89 },
2438 { 0x06, 0xcfd2 },
2439 { 0x06, 0x08eb },
2440 { 0x06, 0xdb19 },
2441 { 0x06, 0xb2fb },
2442 { 0x06, 0xfffe },
2443 { 0x06, 0xfd04 },
2444 { 0x06, 0xf8e0 },
2445 { 0x06, 0xf848 },
2446 { 0x06, 0xe1f8 },
2447 { 0x06, 0x4968 },
2448 { 0x06, 0x08e4 },
2449 { 0x06, 0xf848 },
2450 { 0x06, 0xe5f8 },
2451 { 0x06, 0x4958 },
2452 { 0x06, 0xf7e4 },
2453 { 0x06, 0xf848 },
2454 { 0x06, 0xe5f8 },
2455 { 0x06, 0x49fc },
2456 { 0x06, 0x044d },
2457 { 0x06, 0x2000 },
2458 { 0x06, 0x024e },
2459 { 0x06, 0x2200 },
2460 { 0x06, 0x024d },
2461 { 0x06, 0xdfff },
2462 { 0x06, 0x014e },
2463 { 0x06, 0xddff },
2464 { 0x06, 0x0100 },
2465 { 0x05, 0x83d8 },
2466 { 0x06, 0x8000 },
2467 { 0x03, 0xdc00 },
2468 { 0x05, 0xfff6 },
2469 { 0x06, 0x00fc },
2470 { 0x1f, 0x0000 },
2471
2472 { 0x1f, 0x0000 },
2473 { 0x0d, 0xf880 },
2474 { 0x1f, 0x0000 }
1677 }; 2475 };
1678 2476
1679 rtl_phy_write(ioaddr, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0)); 2477 rtl_phy_write(ioaddr, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0));
1680 2478
1681 if (mdio_read(ioaddr, 0x06) == 0xc400) { 2479 if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) {
1682 struct phy_reg phy_reg_init_1[] = { 2480 struct phy_reg phy_reg_init[] = {
2481 { 0x1f, 0x0002 },
2482 { 0x05, 0x669a },
1683 { 0x1f, 0x0005 }, 2483 { 0x1f, 0x0005 },
1684 { 0x01, 0x0300 }, 2484 { 0x05, 0x8330 },
1685 { 0x1f, 0x0000 }, 2485 { 0x06, 0x669a },
1686 { 0x11, 0x401c }, 2486
1687 { 0x16, 0x4100 }, 2487 { 0x1f, 0x0002 }
2488 };
2489 int val;
2490
2491 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2492
2493 val = mdio_read(ioaddr, 0x0d);
2494 if ((val & 0x00ff) != 0x006c) {
2495 u32 set[] = {
2496 0x0065, 0x0066, 0x0067, 0x0068,
2497 0x0069, 0x006a, 0x006b, 0x006c
2498 };
2499 int i;
2500
2501 mdio_write(ioaddr, 0x1f, 0x0002);
2502
2503 val &= 0xff00;
2504 for (i = 0; i < ARRAY_SIZE(set); i++)
2505 mdio_write(ioaddr, 0x0d, val | set[i]);
2506 }
2507 } else {
2508 struct phy_reg phy_reg_init[] = {
2509 { 0x1f, 0x0002 },
2510 { 0x05, 0x2642 },
1688 { 0x1f, 0x0005 }, 2511 { 0x1f, 0x0005 },
1689 { 0x07, 0x0010 }, 2512 { 0x05, 0x8330 },
1690 { 0x05, 0x83dc }, 2513 { 0x06, 0x2642 }
1691 { 0x06, 0x087d },
1692 { 0x05, 0x8300 },
1693 { 0x06, 0x0101 },
1694 { 0x06, 0x05f8 },
1695 { 0x06, 0xf9fa },
1696 { 0x06, 0xfbef },
1697 { 0x06, 0x79e2 },
1698 { 0x06, 0x835f },
1699 { 0x06, 0xe0f8 },
1700 { 0x06, 0x9ae1 },
1701 { 0x06, 0xf89b },
1702 { 0x06, 0xef31 },
1703 { 0x06, 0x3b65 },
1704 { 0x06, 0xaa07 },
1705 { 0x06, 0x81e4 },
1706 { 0x06, 0xf89a },
1707 { 0x06, 0xe5f8 },
1708 { 0x06, 0x9baf },
1709 { 0x06, 0x06ae },
1710 { 0x05, 0x83dc },
1711 { 0x06, 0x8300 },
1712 }; 2514 };
1713 2515
1714 rtl_phy_write(ioaddr, phy_reg_init_1, 2516 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
1715 ARRAY_SIZE(phy_reg_init_1));
1716 } 2517 }
1717 2518
1718 mdio_write(ioaddr, 0x1f, 0x0000); 2519 mdio_write(ioaddr, 0x1f, 0x0002);
2520 mdio_plus_minus(ioaddr, 0x02, 0x0100, 0x0600);
2521 mdio_plus_minus(ioaddr, 0x03, 0x0000, 0xe000);
2522
2523 mdio_write(ioaddr, 0x1f, 0x0001);
2524 mdio_write(ioaddr, 0x17, 0x0cc0);
2525
2526 mdio_write(ioaddr, 0x1f, 0x0002);
2527 mdio_patch(ioaddr, 0x0f, 0x0017);
2528
2529 rtl_phy_write(ioaddr, phy_reg_init_1, ARRAY_SIZE(phy_reg_init_1));
2530}
2531
2532static void rtl8168d_3_hw_phy_config(void __iomem *ioaddr)
2533{
2534 struct phy_reg phy_reg_init[] = {
2535 { 0x1f, 0x0002 },
2536 { 0x10, 0x0008 },
2537 { 0x0d, 0x006c },
2538
2539 { 0x1f, 0x0000 },
2540 { 0x0d, 0xf880 },
2541
2542 { 0x1f, 0x0001 },
2543 { 0x17, 0x0cc0 },
2544
2545 { 0x1f, 0x0001 },
2546 { 0x0b, 0xa4d8 },
2547 { 0x09, 0x281c },
2548 { 0x07, 0x2883 },
2549 { 0x0a, 0x6b35 },
2550 { 0x1d, 0x3da4 },
2551 { 0x1c, 0xeffd },
2552 { 0x14, 0x7f52 },
2553 { 0x18, 0x7fc6 },
2554 { 0x08, 0x0601 },
2555 { 0x06, 0x4063 },
2556 { 0x10, 0xf074 },
2557 { 0x1f, 0x0003 },
2558 { 0x13, 0x0789 },
2559 { 0x12, 0xf4bd },
2560 { 0x1a, 0x04fd },
2561 { 0x14, 0x84b0 },
2562 { 0x1f, 0x0000 },
2563 { 0x00, 0x9200 },
2564
2565 { 0x1f, 0x0005 },
2566 { 0x01, 0x0340 },
2567 { 0x1f, 0x0001 },
2568 { 0x04, 0x4000 },
2569 { 0x03, 0x1d21 },
2570 { 0x02, 0x0c32 },
2571 { 0x01, 0x0200 },
2572 { 0x00, 0x5554 },
2573 { 0x04, 0x4800 },
2574 { 0x04, 0x4000 },
2575 { 0x04, 0xf000 },
2576 { 0x03, 0xdf01 },
2577 { 0x02, 0xdf20 },
2578 { 0x01, 0x101a },
2579 { 0x00, 0xa0ff },
2580 { 0x04, 0xf800 },
2581 { 0x04, 0xf000 },
2582 { 0x1f, 0x0000 },
2583
2584 { 0x1f, 0x0007 },
2585 { 0x1e, 0x0023 },
2586 { 0x16, 0x0000 },
2587 { 0x1f, 0x0000 }
2588 };
2589
2590 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
1719} 2591}
1720 2592
1721static void rtl8102e_hw_phy_config(void __iomem *ioaddr) 2593static void rtl8102e_hw_phy_config(void __iomem *ioaddr)
@@ -1792,7 +2664,13 @@ static void rtl_hw_phy_config(struct net_device *dev)
1792 rtl8168cp_2_hw_phy_config(ioaddr); 2664 rtl8168cp_2_hw_phy_config(ioaddr);
1793 break; 2665 break;
1794 case RTL_GIGA_MAC_VER_25: 2666 case RTL_GIGA_MAC_VER_25:
1795 rtl8168d_hw_phy_config(ioaddr); 2667 rtl8168d_1_hw_phy_config(ioaddr);
2668 break;
2669 case RTL_GIGA_MAC_VER_26:
2670 rtl8168d_2_hw_phy_config(ioaddr);
2671 break;
2672 case RTL_GIGA_MAC_VER_27:
2673 rtl8168d_3_hw_phy_config(ioaddr);
1796 break; 2674 break;
1797 2675
1798 default: 2676 default:
@@ -2322,6 +3200,14 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2322 } 3200 }
2323 3201
2324 rtl8169_init_phy(dev, tp); 3202 rtl8169_init_phy(dev, tp);
3203
3204 /*
3205 * Pretend we are using VLANs; This bypasses a nasty bug where
3206 * Interrupts stop flowing on high load on 8110SCd controllers.
3207 */
3208 if (tp->mac_version == RTL_GIGA_MAC_VER_05)
3209 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | RxVlan);
3210
2325 device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); 3211 device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL);
2326 3212
2327out: 3213out:
@@ -2349,6 +3235,10 @@ static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
2349 flush_scheduled_work(); 3235 flush_scheduled_work();
2350 3236
2351 unregister_netdev(dev); 3237 unregister_netdev(dev);
3238
3239 /* restore original MAC address */
3240 rtl_rar_set(tp, dev->perm_addr);
3241
2352 rtl_disable_msi(pdev, tp); 3242 rtl_disable_msi(pdev, tp);
2353 rtl8169_release_board(pdev, dev, tp->mmio_addr); 3243 rtl8169_release_board(pdev, dev, tp->mmio_addr);
2354 pci_set_drvdata(pdev, NULL); 3244 pci_set_drvdata(pdev, NULL);
@@ -2357,9 +3247,9 @@ static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
2357static void rtl8169_set_rxbufsize(struct rtl8169_private *tp, 3247static void rtl8169_set_rxbufsize(struct rtl8169_private *tp,
2358 struct net_device *dev) 3248 struct net_device *dev)
2359{ 3249{
2360 unsigned int mtu = dev->mtu; 3250 unsigned int max_frame = dev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
2361 3251
2362 tp->rx_buf_sz = (mtu > RX_BUF_SIZE) ? mtu + ETH_HLEN + 8 : RX_BUF_SIZE; 3252 tp->rx_buf_sz = (max_frame > RX_BUF_SIZE) ? max_frame : RX_BUF_SIZE;
2363} 3253}
2364 3254
2365static int rtl8169_open(struct net_device *dev) 3255static int rtl8169_open(struct net_device *dev)
@@ -2493,7 +3383,7 @@ static u16 rtl_rw_cpluscmd(void __iomem *ioaddr)
2493static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz) 3383static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz)
2494{ 3384{
2495 /* Low hurts. Let's disable the filtering. */ 3385 /* Low hurts. Let's disable the filtering. */
2496 RTL_W16(RxMaxSize, rx_buf_sz); 3386 RTL_W16(RxMaxSize, rx_buf_sz + 1);
2497} 3387}
2498 3388
2499static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) 3389static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version)
@@ -2863,6 +3753,8 @@ static void rtl_hw_start_8168(struct net_device *dev)
2863 break; 3753 break;
2864 3754
2865 case RTL_GIGA_MAC_VER_25: 3755 case RTL_GIGA_MAC_VER_25:
3756 case RTL_GIGA_MAC_VER_26:
3757 case RTL_GIGA_MAC_VER_27:
2866 rtl_hw_start_8168d(ioaddr, pdev); 3758 rtl_hw_start_8168d(ioaddr, pdev);
2867 break; 3759 break;
2868 3760
@@ -3993,6 +4885,9 @@ static void rtl_shutdown(struct pci_dev *pdev)
3993 4885
3994 rtl8169_net_suspend(dev); 4886 rtl8169_net_suspend(dev);
3995 4887
4888 /* restore original MAC address */
4889 rtl_rar_set(tp, dev->perm_addr);
4890
3996 spin_lock_irq(&tp->lock); 4891 spin_lock_irq(&tp->lock);
3997 4892
3998 rtl8169_asic_down(ioaddr); 4893 rtl8169_asic_down(ioaddr);
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index ddccf5fa56b6..0dd7839322bc 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -3494,6 +3494,7 @@ static void s2io_reset(struct s2io_nic *sp)
3494 3494
3495 /* Restore the PCI state saved during initialization. */ 3495 /* Restore the PCI state saved during initialization. */
3496 pci_restore_state(sp->pdev); 3496 pci_restore_state(sp->pdev);
3497 pci_save_state(sp->pdev);
3497 pci_read_config_word(sp->pdev, 0x2, &val16); 3498 pci_read_config_word(sp->pdev, 0x2, &val16);
3498 if (check_pci_device_id(val16) != (u16)PCI_ANY_ID) 3499 if (check_pci_device_id(val16) != (u16)PCI_ANY_ID)
3499 break; 3500 break;
diff --git a/drivers/net/sfc/rx.c b/drivers/net/sfc/rx.c
index 01f9432c31ef..98bff5ada09a 100644
--- a/drivers/net/sfc/rx.c
+++ b/drivers/net/sfc/rx.c
@@ -444,7 +444,8 @@ static void efx_rx_packet__check_len(struct efx_rx_queue *rx_queue,
444 * the appropriate LRO method 444 * the appropriate LRO method
445 */ 445 */
446static void efx_rx_packet_lro(struct efx_channel *channel, 446static void efx_rx_packet_lro(struct efx_channel *channel,
447 struct efx_rx_buffer *rx_buf) 447 struct efx_rx_buffer *rx_buf,
448 bool checksummed)
448{ 449{
449 struct napi_struct *napi = &channel->napi_str; 450 struct napi_struct *napi = &channel->napi_str;
450 451
@@ -466,7 +467,8 @@ static void efx_rx_packet_lro(struct efx_channel *channel,
466 skb->len = rx_buf->len; 467 skb->len = rx_buf->len;
467 skb->data_len = rx_buf->len; 468 skb->data_len = rx_buf->len;
468 skb->truesize += rx_buf->len; 469 skb->truesize += rx_buf->len;
469 skb->ip_summed = CHECKSUM_UNNECESSARY; 470 skb->ip_summed =
471 checksummed ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE;
470 472
471 napi_gro_frags(napi); 473 napi_gro_frags(napi);
472 474
@@ -475,6 +477,7 @@ out:
475 rx_buf->page = NULL; 477 rx_buf->page = NULL;
476 } else { 478 } else {
477 EFX_BUG_ON_PARANOID(!rx_buf->skb); 479 EFX_BUG_ON_PARANOID(!rx_buf->skb);
480 EFX_BUG_ON_PARANOID(!checksummed);
478 481
479 napi_gro_receive(napi, rx_buf->skb); 482 napi_gro_receive(napi, rx_buf->skb);
480 rx_buf->skb = NULL; 483 rx_buf->skb = NULL;
@@ -570,7 +573,7 @@ void __efx_rx_packet(struct efx_channel *channel,
570 } 573 }
571 574
572 if (likely(checksummed || rx_buf->page)) { 575 if (likely(checksummed || rx_buf->page)) {
573 efx_rx_packet_lro(channel, rx_buf); 576 efx_rx_packet_lro(channel, rx_buf, checksummed);
574 goto done; 577 goto done;
575 } 578 }
576 579
diff --git a/drivers/net/sfc/sfe4001.c b/drivers/net/sfc/sfe4001.c
index cee00ad49b57..49eb91b5f50c 100644
--- a/drivers/net/sfc/sfe4001.c
+++ b/drivers/net/sfc/sfe4001.c
@@ -188,7 +188,7 @@ static int sfn4111t_reset(struct efx_nic *efx)
188 efx_oword_t reg; 188 efx_oword_t reg;
189 189
190 /* GPIO 3 and the GPIO register are shared with I2C, so block that */ 190 /* GPIO 3 and the GPIO register are shared with I2C, so block that */
191 mutex_lock(&efx->i2c_adap.bus_lock); 191 i2c_lock_adapter(&efx->i2c_adap);
192 192
193 /* Pull RST_N (GPIO 2) low then let it up again, setting the 193 /* Pull RST_N (GPIO 2) low then let it up again, setting the
194 * FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the 194 * FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the
@@ -204,7 +204,7 @@ static int sfn4111t_reset(struct efx_nic *efx)
204 falcon_write(efx, &reg, GPIO_CTL_REG_KER); 204 falcon_write(efx, &reg, GPIO_CTL_REG_KER);
205 msleep(1); 205 msleep(1);
206 206
207 mutex_unlock(&efx->i2c_adap.bus_lock); 207 i2c_unlock_adapter(&efx->i2c_adap);
208 208
209 ssleep(1); 209 ssleep(1);
210 return 0; 210 return 0;
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
index f49d0800c1d1..528b912a4b0d 100644
--- a/drivers/net/sh_eth.c
+++ b/drivers/net/sh_eth.c
@@ -30,6 +30,7 @@
30#include <linux/phy.h> 30#include <linux/phy.h>
31#include <linux/cache.h> 31#include <linux/cache.h>
32#include <linux/io.h> 32#include <linux/io.h>
33#include <asm/cacheflush.h>
33 34
34#include "sh_eth.h" 35#include "sh_eth.h"
35 36
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 2ab5c39f33ca..6a10d7ba5877 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -4538,6 +4538,8 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
4538 goto err_out_free_netdev; 4538 goto err_out_free_netdev;
4539 } 4539 }
4540 4540
4541 netif_carrier_off(dev);
4542
4541 netif_napi_add(dev, &hw->napi, sky2_poll, NAPI_WEIGHT); 4543 netif_napi_add(dev, &hw->napi, sky2_poll, NAPI_WEIGHT);
4542 4544
4543 err = request_irq(pdev->irq, sky2_intr, 4545 err = request_irq(pdev->irq, sky2_intr,
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index 05c91ee6921e..f12206bdbb75 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -2283,7 +2283,7 @@ static int __devinit smc_drv_probe(struct platform_device *pdev)
2283 2283
2284 ndev->irq = ires->start; 2284 ndev->irq = ires->start;
2285 2285
2286 if (ires->flags & IRQF_TRIGGER_MASK) 2286 if (irq_flags == -1 || ires->flags & IRQF_TRIGGER_MASK)
2287 irq_flags = ires->flags & IRQF_TRIGGER_MASK; 2287 irq_flags = ires->flags & IRQF_TRIGGER_MASK;
2288 2288
2289 ret = smc_request_attrib(pdev, ndev); 2289 ret = smc_request_attrib(pdev, ndev);
diff --git a/drivers/net/smsc911x.c b/drivers/net/smsc911x.c
index ccdd196f5297..f9cdcbcb77d4 100644
--- a/drivers/net/smsc911x.c
+++ b/drivers/net/smsc911x.c
@@ -986,7 +986,7 @@ static int smsc911x_poll(struct napi_struct *napi, int budget)
986 struct net_device *dev = pdata->dev; 986 struct net_device *dev = pdata->dev;
987 int npackets = 0; 987 int npackets = 0;
988 988
989 while (likely(netif_running(dev)) && (npackets < budget)) { 989 while (npackets < budget) {
990 unsigned int pktlength; 990 unsigned int pktlength;
991 unsigned int pktwords; 991 unsigned int pktwords;
992 struct sk_buff *skb; 992 struct sk_buff *skb;
diff --git a/drivers/net/smsc9420.c b/drivers/net/smsc9420.c
index b4909a2dec66..0f7909276237 100644
--- a/drivers/net/smsc9420.c
+++ b/drivers/net/smsc9420.c
@@ -252,6 +252,9 @@ static int smsc9420_ethtool_get_settings(struct net_device *dev,
252{ 252{
253 struct smsc9420_pdata *pd = netdev_priv(dev); 253 struct smsc9420_pdata *pd = netdev_priv(dev);
254 254
255 if (!pd->phy_dev)
256 return -ENODEV;
257
255 cmd->maxtxpkt = 1; 258 cmd->maxtxpkt = 1;
256 cmd->maxrxpkt = 1; 259 cmd->maxrxpkt = 1;
257 return phy_ethtool_gset(pd->phy_dev, cmd); 260 return phy_ethtool_gset(pd->phy_dev, cmd);
@@ -262,6 +265,9 @@ static int smsc9420_ethtool_set_settings(struct net_device *dev,
262{ 265{
263 struct smsc9420_pdata *pd = netdev_priv(dev); 266 struct smsc9420_pdata *pd = netdev_priv(dev);
264 267
268 if (!pd->phy_dev)
269 return -ENODEV;
270
265 return phy_ethtool_sset(pd->phy_dev, cmd); 271 return phy_ethtool_sset(pd->phy_dev, cmd);
266} 272}
267 273
@@ -290,6 +296,10 @@ static void smsc9420_ethtool_set_msglevel(struct net_device *netdev, u32 data)
290static int smsc9420_ethtool_nway_reset(struct net_device *netdev) 296static int smsc9420_ethtool_nway_reset(struct net_device *netdev)
291{ 297{
292 struct smsc9420_pdata *pd = netdev_priv(netdev); 298 struct smsc9420_pdata *pd = netdev_priv(netdev);
299
300 if (!pd->phy_dev)
301 return -ENODEV;
302
293 return phy_start_aneg(pd->phy_dev); 303 return phy_start_aneg(pd->phy_dev);
294} 304}
295 305
@@ -312,6 +322,10 @@ smsc9420_ethtool_getregs(struct net_device *dev, struct ethtool_regs *regs,
312 for (i = 0; i < 0x100; i += (sizeof(u32))) 322 for (i = 0; i < 0x100; i += (sizeof(u32)))
313 data[j++] = smsc9420_reg_read(pd, i); 323 data[j++] = smsc9420_reg_read(pd, i);
314 324
325 // cannot read phy registers if the net device is down
326 if (!phy_dev)
327 return;
328
315 for (i = 0; i <= 31; i++) 329 for (i = 0; i <= 31; i++)
316 data[j++] = smsc9420_mii_read(phy_dev->bus, phy_dev->addr, i); 330 data[j++] = smsc9420_mii_read(phy_dev->bus, phy_dev->addr, i);
317} 331}
diff --git a/drivers/net/stmmac/Kconfig b/drivers/net/stmmac/Kconfig
new file mode 100644
index 000000000000..35eaa5251d7f
--- /dev/null
+++ b/drivers/net/stmmac/Kconfig
@@ -0,0 +1,53 @@
1config STMMAC_ETH
2 tristate "STMicroelectronics 10/100/1000 Ethernet driver"
3 select MII
4 select PHYLIB
5 depends on NETDEVICES && CPU_SUBTYPE_ST40
6 help
7 This is the driver for the ST MAC 10/100/1000 on-chip Ethernet
8 controllers. ST Ethernet IPs are built around a Synopsys IP Core.
9
10if STMMAC_ETH
11
12config STMMAC_DA
13 bool "STMMAC DMA arbitration scheme"
14 default n
15 help
16 Selecting this option, rx has priority over Tx (only for Giga
17 Ethernet device).
18 By default, the DMA arbitration scheme is based on Round-robin
19 (rx:tx priority is 1:1).
20
21config STMMAC_DUAL_MAC
22 bool "STMMAC: dual mac support (EXPERIMENTAL)"
23 default n
24 depends on EXPERIMENTAL && STMMAC_ETH && !STMMAC_TIMER
25 help
26 Some ST SoCs (for example the stx7141 and stx7200c2) have two
27 Ethernet Controllers. This option turns on the second Ethernet
28 device on this kind of platforms.
29
30config STMMAC_TIMER
31 bool "STMMAC Timer optimisation"
32 default n
33 help
34 Use an external timer for mitigating the number of network
35 interrupts.
36
37choice
38 prompt "Select Timer device"
39 depends on STMMAC_TIMER
40
41config STMMAC_TMU_TIMER
42 bool "TMU channel 2"
43 depends on CPU_SH4
44 help
45
46config STMMAC_RTC_TIMER
47 bool "Real time clock"
48 depends on RTC_CLASS
49 help
50
51endchoice
52
53endif
diff --git a/drivers/net/stmmac/Makefile b/drivers/net/stmmac/Makefile
new file mode 100644
index 000000000000..b2d7a5564dfa
--- /dev/null
+++ b/drivers/net/stmmac/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_STMMAC_ETH) += stmmac.o
2stmmac-$(CONFIG_STMMAC_TIMER) += stmmac_timer.o
3stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o \
4 mac100.o gmac.o $(stmmac-y)
diff --git a/drivers/net/stmmac/common.h b/drivers/net/stmmac/common.h
new file mode 100644
index 000000000000..e49e5188e887
--- /dev/null
+++ b/drivers/net/stmmac/common.h
@@ -0,0 +1,330 @@
1/*******************************************************************************
2 STMMAC Common Header File
3
4 Copyright (C) 2007-2009 STMicroelectronics Ltd
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23*******************************************************************************/
24
25#include "descs.h"
26#include <linux/io.h>
27
28/* *********************************************
29 DMA CRS Control and Status Register Mapping
30 * *********************************************/
31#define DMA_BUS_MODE 0x00001000 /* Bus Mode */
32#define DMA_XMT_POLL_DEMAND 0x00001004 /* Transmit Poll Demand */
33#define DMA_RCV_POLL_DEMAND 0x00001008 /* Received Poll Demand */
34#define DMA_RCV_BASE_ADDR 0x0000100c /* Receive List Base */
35#define DMA_TX_BASE_ADDR 0x00001010 /* Transmit List Base */
36#define DMA_STATUS 0x00001014 /* Status Register */
37#define DMA_CONTROL 0x00001018 /* Ctrl (Operational Mode) */
38#define DMA_INTR_ENA 0x0000101c /* Interrupt Enable */
39#define DMA_MISSED_FRAME_CTR 0x00001020 /* Missed Frame Counter */
40#define DMA_CUR_TX_BUF_ADDR 0x00001050 /* Current Host Tx Buffer */
41#define DMA_CUR_RX_BUF_ADDR 0x00001054 /* Current Host Rx Buffer */
42
43/* ********************************
44 DMA Control register defines
45 * ********************************/
46#define DMA_CONTROL_ST 0x00002000 /* Start/Stop Transmission */
47#define DMA_CONTROL_SR 0x00000002 /* Start/Stop Receive */
48
49/* **************************************
50 DMA Interrupt Enable register defines
51 * **************************************/
52/**** NORMAL INTERRUPT ****/
53#define DMA_INTR_ENA_NIE 0x00010000 /* Normal Summary */
54#define DMA_INTR_ENA_TIE 0x00000001 /* Transmit Interrupt */
55#define DMA_INTR_ENA_TUE 0x00000004 /* Transmit Buffer Unavailable */
56#define DMA_INTR_ENA_RIE 0x00000040 /* Receive Interrupt */
57#define DMA_INTR_ENA_ERE 0x00004000 /* Early Receive */
58
59#define DMA_INTR_NORMAL (DMA_INTR_ENA_NIE | DMA_INTR_ENA_RIE | \
60 DMA_INTR_ENA_TIE)
61
62/**** ABNORMAL INTERRUPT ****/
63#define DMA_INTR_ENA_AIE 0x00008000 /* Abnormal Summary */
64#define DMA_INTR_ENA_FBE 0x00002000 /* Fatal Bus Error */
65#define DMA_INTR_ENA_ETE 0x00000400 /* Early Transmit */
66#define DMA_INTR_ENA_RWE 0x00000200 /* Receive Watchdog */
67#define DMA_INTR_ENA_RSE 0x00000100 /* Receive Stopped */
68#define DMA_INTR_ENA_RUE 0x00000080 /* Receive Buffer Unavailable */
69#define DMA_INTR_ENA_UNE 0x00000020 /* Tx Underflow */
70#define DMA_INTR_ENA_OVE 0x00000010 /* Receive Overflow */
71#define DMA_INTR_ENA_TJE 0x00000008 /* Transmit Jabber */
72#define DMA_INTR_ENA_TSE 0x00000002 /* Transmit Stopped */
73
74#define DMA_INTR_ABNORMAL (DMA_INTR_ENA_AIE | DMA_INTR_ENA_FBE | \
75 DMA_INTR_ENA_UNE)
76
77/* DMA default interrupt mask */
78#define DMA_INTR_DEFAULT_MASK (DMA_INTR_NORMAL | DMA_INTR_ABNORMAL)
79
80/* ****************************
81 * DMA Status register defines
82 * ****************************/
83#define DMA_STATUS_GPI 0x10000000 /* PMT interrupt */
84#define DMA_STATUS_GMI 0x08000000 /* MMC interrupt */
85#define DMA_STATUS_GLI 0x04000000 /* GMAC Line interface int. */
86#define DMA_STATUS_GMI 0x08000000
87#define DMA_STATUS_GLI 0x04000000
88#define DMA_STATUS_EB_MASK 0x00380000 /* Error Bits Mask */
89#define DMA_STATUS_EB_TX_ABORT 0x00080000 /* Error Bits - TX Abort */
90#define DMA_STATUS_EB_RX_ABORT 0x00100000 /* Error Bits - RX Abort */
91#define DMA_STATUS_TS_MASK 0x00700000 /* Transmit Process State */
92#define DMA_STATUS_TS_SHIFT 20
93#define DMA_STATUS_RS_MASK 0x000e0000 /* Receive Process State */
94#define DMA_STATUS_RS_SHIFT 17
95#define DMA_STATUS_NIS 0x00010000 /* Normal Interrupt Summary */
96#define DMA_STATUS_AIS 0x00008000 /* Abnormal Interrupt Summary */
97#define DMA_STATUS_ERI 0x00004000 /* Early Receive Interrupt */
98#define DMA_STATUS_FBI 0x00002000 /* Fatal Bus Error Interrupt */
99#define DMA_STATUS_ETI 0x00000400 /* Early Transmit Interrupt */
100#define DMA_STATUS_RWT 0x00000200 /* Receive Watchdog Timeout */
101#define DMA_STATUS_RPS 0x00000100 /* Receive Process Stopped */
102#define DMA_STATUS_RU 0x00000080 /* Receive Buffer Unavailable */
103#define DMA_STATUS_RI 0x00000040 /* Receive Interrupt */
104#define DMA_STATUS_UNF 0x00000020 /* Transmit Underflow */
105#define DMA_STATUS_OVF 0x00000010 /* Receive Overflow */
106#define DMA_STATUS_TJT 0x00000008 /* Transmit Jabber Timeout */
107#define DMA_STATUS_TU 0x00000004 /* Transmit Buffer Unavailable */
108#define DMA_STATUS_TPS 0x00000002 /* Transmit Process Stopped */
109#define DMA_STATUS_TI 0x00000001 /* Transmit Interrupt */
110
111/* Other defines */
112#define HASH_TABLE_SIZE 64
113#define PAUSE_TIME 0x200
114
115/* Flow Control defines */
116#define FLOW_OFF 0
117#define FLOW_RX 1
118#define FLOW_TX 2
119#define FLOW_AUTO (FLOW_TX | FLOW_RX)
120
121/* DMA STORE-AND-FORWARD Operation Mode */
122#define SF_DMA_MODE 1
123
124#define HW_CSUM 1
125#define NO_HW_CSUM 0
126
127/* GMAC TX FIFO is 8K, Rx FIFO is 16K */
128#define BUF_SIZE_16KiB 16384
129#define BUF_SIZE_8KiB 8192
130#define BUF_SIZE_4KiB 4096
131#define BUF_SIZE_2KiB 2048
132
133/* Power Down and WOL */
134#define PMT_NOT_SUPPORTED 0
135#define PMT_SUPPORTED 1
136
137/* Common MAC defines */
138#define MAC_CTRL_REG 0x00000000 /* MAC Control */
139#define MAC_ENABLE_TX 0x00000008 /* Transmitter Enable */
140#define MAC_RNABLE_RX 0x00000004 /* Receiver Enable */
141
142/* MAC Management Counters register */
143#define MMC_CONTROL 0x00000100 /* MMC Control */
144#define MMC_HIGH_INTR 0x00000104 /* MMC High Interrupt */
145#define MMC_LOW_INTR 0x00000108 /* MMC Low Interrupt */
146#define MMC_HIGH_INTR_MASK 0x0000010c /* MMC High Interrupt Mask */
147#define MMC_LOW_INTR_MASK 0x00000110 /* MMC Low Interrupt Mask */
148
149#define MMC_CONTROL_MAX_FRM_MASK 0x0003ff8 /* Maximum Frame Size */
150#define MMC_CONTROL_MAX_FRM_SHIFT 3
151#define MMC_CONTROL_MAX_FRAME 0x7FF
152
153struct stmmac_extra_stats {
154 /* Transmit errors */
155 unsigned long tx_underflow ____cacheline_aligned;
156 unsigned long tx_carrier;
157 unsigned long tx_losscarrier;
158 unsigned long tx_heartbeat;
159 unsigned long tx_deferred;
160 unsigned long tx_vlan;
161 unsigned long tx_jabber;
162 unsigned long tx_frame_flushed;
163 unsigned long tx_payload_error;
164 unsigned long tx_ip_header_error;
165 /* Receive errors */
166 unsigned long rx_desc;
167 unsigned long rx_partial;
168 unsigned long rx_runt;
169 unsigned long rx_toolong;
170 unsigned long rx_collision;
171 unsigned long rx_crc;
172 unsigned long rx_lenght;
173 unsigned long rx_mii;
174 unsigned long rx_multicast;
175 unsigned long rx_gmac_overflow;
176 unsigned long rx_watchdog;
177 unsigned long da_rx_filter_fail;
178 unsigned long sa_rx_filter_fail;
179 unsigned long rx_missed_cntr;
180 unsigned long rx_overflow_cntr;
181 unsigned long rx_vlan;
182 /* Tx/Rx IRQ errors */
183 unsigned long tx_undeflow_irq;
184 unsigned long tx_process_stopped_irq;
185 unsigned long tx_jabber_irq;
186 unsigned long rx_overflow_irq;
187 unsigned long rx_buf_unav_irq;
188 unsigned long rx_process_stopped_irq;
189 unsigned long rx_watchdog_irq;
190 unsigned long tx_early_irq;
191 unsigned long fatal_bus_error_irq;
192 /* Extra info */
193 unsigned long threshold;
194 unsigned long tx_pkt_n;
195 unsigned long rx_pkt_n;
196 unsigned long poll_n;
197 unsigned long sched_timer_n;
198 unsigned long normal_irq_n;
199};
200
201/* GMAC core can compute the checksums in HW. */
202enum rx_frame_status {
203 good_frame = 0,
204 discard_frame = 1,
205 csum_none = 2,
206};
207
208static inline void stmmac_set_mac_addr(unsigned long ioaddr, u8 addr[6],
209 unsigned int high, unsigned int low)
210{
211 unsigned long data;
212
213 data = (addr[5] << 8) | addr[4];
214 writel(data, ioaddr + high);
215 data = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0];
216 writel(data, ioaddr + low);
217
218 return;
219}
220
221static inline void stmmac_get_mac_addr(unsigned long ioaddr,
222 unsigned char *addr, unsigned int high,
223 unsigned int low)
224{
225 unsigned int hi_addr, lo_addr;
226
227 /* Read the MAC address from the hardware */
228 hi_addr = readl(ioaddr + high);
229 lo_addr = readl(ioaddr + low);
230
231 /* Extract the MAC address from the high and low words */
232 addr[0] = lo_addr & 0xff;
233 addr[1] = (lo_addr >> 8) & 0xff;
234 addr[2] = (lo_addr >> 16) & 0xff;
235 addr[3] = (lo_addr >> 24) & 0xff;
236 addr[4] = hi_addr & 0xff;
237 addr[5] = (hi_addr >> 8) & 0xff;
238
239 return;
240}
241
242struct stmmac_ops {
243 /* MAC core initialization */
244 void (*core_init) (unsigned long ioaddr) ____cacheline_aligned;
245 /* DMA core initialization */
246 int (*dma_init) (unsigned long ioaddr, int pbl, u32 dma_tx, u32 dma_rx);
247 /* Dump MAC registers */
248 void (*dump_mac_regs) (unsigned long ioaddr);
249 /* Dump DMA registers */
250 void (*dump_dma_regs) (unsigned long ioaddr);
251 /* Set tx/rx threshold in the csr6 register
252 * An invalid value enables the store-and-forward mode */
253 void (*dma_mode) (unsigned long ioaddr, int txmode, int rxmode);
254 /* To track extra statistic (if supported) */
255 void (*dma_diagnostic_fr) (void *data, struct stmmac_extra_stats *x,
256 unsigned long ioaddr);
257 /* RX descriptor ring initialization */
258 void (*init_rx_desc) (struct dma_desc *p, unsigned int ring_size,
259 int disable_rx_ic);
260 /* TX descriptor ring initialization */
261 void (*init_tx_desc) (struct dma_desc *p, unsigned int ring_size);
262
263 /* Invoked by the xmit function to prepare the tx descriptor */
264 void (*prepare_tx_desc) (struct dma_desc *p, int is_fs, int len,
265 int csum_flag);
266 /* Set/get the owner of the descriptor */
267 void (*set_tx_owner) (struct dma_desc *p);
268 int (*get_tx_owner) (struct dma_desc *p);
269 /* Invoked by the xmit function to close the tx descriptor */
270 void (*close_tx_desc) (struct dma_desc *p);
271 /* Clean the tx descriptor as soon as the tx irq is received */
272 void (*release_tx_desc) (struct dma_desc *p);
273 /* Clear interrupt on tx frame completion. When this bit is
274 * set an interrupt happens as soon as the frame is transmitted */
275 void (*clear_tx_ic) (struct dma_desc *p);
276 /* Last tx segment reports the transmit status */
277 int (*get_tx_ls) (struct dma_desc *p);
278 /* Return the transmit status looking at the TDES1 */
279 int (*tx_status) (void *data, struct stmmac_extra_stats *x,
280 struct dma_desc *p, unsigned long ioaddr);
281 /* Get the buffer size from the descriptor */
282 int (*get_tx_len) (struct dma_desc *p);
283 /* Handle extra events on specific interrupts hw dependent */
284 void (*host_irq_status) (unsigned long ioaddr);
285 int (*get_rx_owner) (struct dma_desc *p);
286 void (*set_rx_owner) (struct dma_desc *p);
287 /* Get the receive frame size */
288 int (*get_rx_frame_len) (struct dma_desc *p);
289 /* Return the reception status looking at the RDES1 */
290 int (*rx_status) (void *data, struct stmmac_extra_stats *x,
291 struct dma_desc *p);
292 /* Multicast filter setting */
293 void (*set_filter) (struct net_device *dev);
294 /* Flow control setting */
295 void (*flow_ctrl) (unsigned long ioaddr, unsigned int duplex,
296 unsigned int fc, unsigned int pause_time);
297 /* Set power management mode (e.g. magic frame) */
298 void (*pmt) (unsigned long ioaddr, unsigned long mode);
299 /* Set/Get Unicast MAC addresses */
300 void (*set_umac_addr) (unsigned long ioaddr, unsigned char *addr,
301 unsigned int reg_n);
302 void (*get_umac_addr) (unsigned long ioaddr, unsigned char *addr,
303 unsigned int reg_n);
304};
305
306struct mac_link {
307 int port;
308 int duplex;
309 int speed;
310};
311
312struct mii_regs {
313 unsigned int addr; /* MII Address */
314 unsigned int data; /* MII Data */
315};
316
317struct hw_cap {
318 unsigned int version; /* Core Version register (GMAC) */
319 unsigned int pmt; /* Power-Down mode (GMAC) */
320 struct mac_link link;
321 struct mii_regs mii;
322};
323
324struct mac_device_info {
325 struct hw_cap hw;
326 struct stmmac_ops *ops;
327};
328
329struct mac_device_info *gmac_setup(unsigned long addr);
330struct mac_device_info *mac100_setup(unsigned long addr);
diff --git a/drivers/net/stmmac/descs.h b/drivers/net/stmmac/descs.h
new file mode 100644
index 000000000000..6d2a0b2f5e57
--- /dev/null
+++ b/drivers/net/stmmac/descs.h
@@ -0,0 +1,163 @@
1/*******************************************************************************
2 Header File to describe the DMA descriptors
3 Use enhanced descriptors in case of GMAC Cores.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms and conditions of the GNU General Public License,
7 version 2, as published by the Free Software Foundation.
8
9 This program is distributed in the hope it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17
18 The full GNU General Public License is included in this distribution in
19 the file called "COPYING".
20
21 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
22*******************************************************************************/
23struct dma_desc {
24 /* Receive descriptor */
25 union {
26 struct {
27 /* RDES0 */
28 u32 reserved1:1;
29 u32 crc_error:1;
30 u32 dribbling:1;
31 u32 mii_error:1;
32 u32 receive_watchdog:1;
33 u32 frame_type:1;
34 u32 collision:1;
35 u32 frame_too_long:1;
36 u32 last_descriptor:1;
37 u32 first_descriptor:1;
38 u32 multicast_frame:1;
39 u32 run_frame:1;
40 u32 length_error:1;
41 u32 partial_frame_error:1;
42 u32 descriptor_error:1;
43 u32 error_summary:1;
44 u32 frame_length:14;
45 u32 filtering_fail:1;
46 u32 own:1;
47 /* RDES1 */
48 u32 buffer1_size:11;
49 u32 buffer2_size:11;
50 u32 reserved2:2;
51 u32 second_address_chained:1;
52 u32 end_ring:1;
53 u32 reserved3:5;
54 u32 disable_ic:1;
55 } rx;
56 struct {
57 /* RDES0 */
58 u32 payload_csum_error:1;
59 u32 crc_error:1;
60 u32 dribbling:1;
61 u32 error_gmii:1;
62 u32 receive_watchdog:1;
63 u32 frame_type:1;
64 u32 late_collision:1;
65 u32 ipc_csum_error:1;
66 u32 last_descriptor:1;
67 u32 first_descriptor:1;
68 u32 vlan_tag:1;
69 u32 overflow_error:1;
70 u32 length_error:1;
71 u32 sa_filter_fail:1;
72 u32 descriptor_error:1;
73 u32 error_summary:1;
74 u32 frame_length:14;
75 u32 da_filter_fail:1;
76 u32 own:1;
77 /* RDES1 */
78 u32 buffer1_size:13;
79 u32 reserved1:1;
80 u32 second_address_chained:1;
81 u32 end_ring:1;
82 u32 buffer2_size:13;
83 u32 reserved2:2;
84 u32 disable_ic:1;
85 } erx; /* -- enhanced -- */
86
87 /* Transmit descriptor */
88 struct {
89 /* TDES0 */
90 u32 deferred:1;
91 u32 underflow_error:1;
92 u32 excessive_deferral:1;
93 u32 collision_count:4;
94 u32 heartbeat_fail:1;
95 u32 excessive_collisions:1;
96 u32 late_collision:1;
97 u32 no_carrier:1;
98 u32 loss_carrier:1;
99 u32 reserved1:3;
100 u32 error_summary:1;
101 u32 reserved2:15;
102 u32 own:1;
103 /* TDES1 */
104 u32 buffer1_size:11;
105 u32 buffer2_size:11;
106 u32 reserved3:1;
107 u32 disable_padding:1;
108 u32 second_address_chained:1;
109 u32 end_ring:1;
110 u32 crc_disable:1;
111 u32 reserved4:2;
112 u32 first_segment:1;
113 u32 last_segment:1;
114 u32 interrupt:1;
115 } tx;
116 struct {
117 /* TDES0 */
118 u32 deferred:1;
119 u32 underflow_error:1;
120 u32 excessive_deferral:1;
121 u32 collision_count:4;
122 u32 vlan_frame:1;
123 u32 excessive_collisions:1;
124 u32 late_collision:1;
125 u32 no_carrier:1;
126 u32 loss_carrier:1;
127 u32 payload_error:1;
128 u32 frame_flushed:1;
129 u32 jabber_timeout:1;
130 u32 error_summary:1;
131 u32 ip_header_error:1;
132 u32 time_stamp_status:1;
133 u32 reserved1:2;
134 u32 second_address_chained:1;
135 u32 end_ring:1;
136 u32 checksum_insertion:2;
137 u32 reserved2:1;
138 u32 time_stamp_enable:1;
139 u32 disable_padding:1;
140 u32 crc_disable:1;
141 u32 first_segment:1;
142 u32 last_segment:1;
143 u32 interrupt:1;
144 u32 own:1;
145 /* TDES1 */
146 u32 buffer1_size:13;
147 u32 reserved3:3;
148 u32 buffer2_size:13;
149 u32 reserved4:3;
150 } etx; /* -- enhanced -- */
151 } des01;
152 unsigned int des2;
153 unsigned int des3;
154};
155
156/* Transmit checksum insertion control */
157enum tdes_csum_insertion {
158 cic_disabled = 0, /* Checksum Insertion Control */
159 cic_only_ip = 1, /* Only IP header */
160 cic_no_pseudoheader = 2, /* IP header but pseudoheader
161 * is not calculated */
162 cic_full = 3, /* IP header and pseudoheader */
163};
diff --git a/drivers/net/stmmac/gmac.c b/drivers/net/stmmac/gmac.c
new file mode 100644
index 000000000000..b624bb5bae0a
--- /dev/null
+++ b/drivers/net/stmmac/gmac.c
@@ -0,0 +1,693 @@
1/*******************************************************************************
2 This is the driver for the GMAC on-chip Ethernet controller for ST SoCs.
3 DWC Ether MAC 10/100/1000 Universal version 3.41a has been used for
4 developing this code.
5
6 Copyright (C) 2007-2009 STMicroelectronics Ltd
7
8 This program is free software; you can redistribute it and/or modify it
9 under the terms and conditions of the GNU General Public License,
10 version 2, as published by the Free Software Foundation.
11
12 This program is distributed in the hope it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 more details.
16
17 You should have received a copy of the GNU General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20
21 The full GNU General Public License is included in this distribution in
22 the file called "COPYING".
23
24 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
25*******************************************************************************/
26
27#include <linux/netdevice.h>
28#include <linux/crc32.h>
29#include <linux/mii.h>
30#include <linux/phy.h>
31
32#include "stmmac.h"
33#include "gmac.h"
34
35#undef GMAC_DEBUG
36/*#define GMAC_DEBUG*/
37#undef FRAME_FILTER_DEBUG
38/*#define FRAME_FILTER_DEBUG*/
39#ifdef GMAC_DEBUG
40#define DBG(fmt, args...) printk(fmt, ## args)
41#else
42#define DBG(fmt, args...) do { } while (0)
43#endif
44
45static void gmac_dump_regs(unsigned long ioaddr)
46{
47 int i;
48 pr_info("\t----------------------------------------------\n"
49 "\t GMAC registers (base addr = 0x%8x)\n"
50 "\t----------------------------------------------\n",
51 (unsigned int)ioaddr);
52
53 for (i = 0; i < 55; i++) {
54 int offset = i * 4;
55 pr_info("\tReg No. %d (offset 0x%x): 0x%08x\n", i,
56 offset, readl(ioaddr + offset));
57 }
58 return;
59}
60
61static int gmac_dma_init(unsigned long ioaddr, int pbl, u32 dma_tx, u32 dma_rx)
62{
63 u32 value = readl(ioaddr + DMA_BUS_MODE);
64 /* DMA SW reset */
65 value |= DMA_BUS_MODE_SFT_RESET;
66 writel(value, ioaddr + DMA_BUS_MODE);
67 do {} while ((readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET));
68
69 value = /* DMA_BUS_MODE_FB | */ DMA_BUS_MODE_4PBL |
70 ((pbl << DMA_BUS_MODE_PBL_SHIFT) |
71 (pbl << DMA_BUS_MODE_RPBL_SHIFT));
72
73#ifdef CONFIG_STMMAC_DA
74 value |= DMA_BUS_MODE_DA; /* Rx has priority over tx */
75#endif
76 writel(value, ioaddr + DMA_BUS_MODE);
77
78 /* Mask interrupts by writing to CSR7 */
79 writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
80
81 /* The base address of the RX/TX descriptor lists must be written into
82 * DMA CSR3 and CSR4, respectively. */
83 writel(dma_tx, ioaddr + DMA_TX_BASE_ADDR);
84 writel(dma_rx, ioaddr + DMA_RCV_BASE_ADDR);
85
86 return 0;
87}
88
89/* Transmit FIFO flush operation */
90static void gmac_flush_tx_fifo(unsigned long ioaddr)
91{
92 u32 csr6 = readl(ioaddr + DMA_CONTROL);
93 writel((csr6 | DMA_CONTROL_FTF), ioaddr + DMA_CONTROL);
94
95 do {} while ((readl(ioaddr + DMA_CONTROL) & DMA_CONTROL_FTF));
96}
97
98static void gmac_dma_operation_mode(unsigned long ioaddr, int txmode,
99 int rxmode)
100{
101 u32 csr6 = readl(ioaddr + DMA_CONTROL);
102
103 if (txmode == SF_DMA_MODE) {
104 DBG(KERN_DEBUG "GMAC: enabling TX store and forward mode\n");
105 /* Transmit COE type 2 cannot be done in cut-through mode. */
106 csr6 |= DMA_CONTROL_TSF;
107 /* Operating on second frame increase the performance
108 * especially when transmit store-and-forward is used.*/
109 csr6 |= DMA_CONTROL_OSF;
110 } else {
111 DBG(KERN_DEBUG "GMAC: disabling TX store and forward mode"
112 " (threshold = %d)\n", txmode);
113 csr6 &= ~DMA_CONTROL_TSF;
114 csr6 &= DMA_CONTROL_TC_TX_MASK;
115 /* Set the transmit threashold */
116 if (txmode <= 32)
117 csr6 |= DMA_CONTROL_TTC_32;
118 else if (txmode <= 64)
119 csr6 |= DMA_CONTROL_TTC_64;
120 else if (txmode <= 128)
121 csr6 |= DMA_CONTROL_TTC_128;
122 else if (txmode <= 192)
123 csr6 |= DMA_CONTROL_TTC_192;
124 else
125 csr6 |= DMA_CONTROL_TTC_256;
126 }
127
128 if (rxmode == SF_DMA_MODE) {
129 DBG(KERN_DEBUG "GMAC: enabling RX store and forward mode\n");
130 csr6 |= DMA_CONTROL_RSF;
131 } else {
132 DBG(KERN_DEBUG "GMAC: disabling RX store and forward mode"
133 " (threshold = %d)\n", rxmode);
134 csr6 &= ~DMA_CONTROL_RSF;
135 csr6 &= DMA_CONTROL_TC_RX_MASK;
136 if (rxmode <= 32)
137 csr6 |= DMA_CONTROL_RTC_32;
138 else if (rxmode <= 64)
139 csr6 |= DMA_CONTROL_RTC_64;
140 else if (rxmode <= 96)
141 csr6 |= DMA_CONTROL_RTC_96;
142 else
143 csr6 |= DMA_CONTROL_RTC_128;
144 }
145
146 writel(csr6, ioaddr + DMA_CONTROL);
147 return;
148}
149
150/* Not yet implemented --- no RMON module */
151static void gmac_dma_diagnostic_fr(void *data, struct stmmac_extra_stats *x,
152 unsigned long ioaddr)
153{
154 return;
155}
156
157static void gmac_dump_dma_regs(unsigned long ioaddr)
158{
159 int i;
160 pr_info(" DMA registers\n");
161 for (i = 0; i < 22; i++) {
162 if ((i < 9) || (i > 17)) {
163 int offset = i * 4;
164 pr_err("\t Reg No. %d (offset 0x%x): 0x%08x\n", i,
165 (DMA_BUS_MODE + offset),
166 readl(ioaddr + DMA_BUS_MODE + offset));
167 }
168 }
169 return;
170}
171
172static int gmac_get_tx_frame_status(void *data, struct stmmac_extra_stats *x,
173 struct dma_desc *p, unsigned long ioaddr)
174{
175 int ret = 0;
176 struct net_device_stats *stats = (struct net_device_stats *)data;
177
178 if (unlikely(p->des01.etx.error_summary)) {
179 DBG(KERN_ERR "GMAC TX error... 0x%08x\n", p->des01.etx);
180 if (unlikely(p->des01.etx.jabber_timeout)) {
181 DBG(KERN_ERR "\tjabber_timeout error\n");
182 x->tx_jabber++;
183 }
184
185 if (unlikely(p->des01.etx.frame_flushed)) {
186 DBG(KERN_ERR "\tframe_flushed error\n");
187 x->tx_frame_flushed++;
188 gmac_flush_tx_fifo(ioaddr);
189 }
190
191 if (unlikely(p->des01.etx.loss_carrier)) {
192 DBG(KERN_ERR "\tloss_carrier error\n");
193 x->tx_losscarrier++;
194 stats->tx_carrier_errors++;
195 }
196 if (unlikely(p->des01.etx.no_carrier)) {
197 DBG(KERN_ERR "\tno_carrier error\n");
198 x->tx_carrier++;
199 stats->tx_carrier_errors++;
200 }
201 if (unlikely(p->des01.etx.late_collision)) {
202 DBG(KERN_ERR "\tlate_collision error\n");
203 stats->collisions += p->des01.etx.collision_count;
204 }
205 if (unlikely(p->des01.etx.excessive_collisions)) {
206 DBG(KERN_ERR "\texcessive_collisions\n");
207 stats->collisions += p->des01.etx.collision_count;
208 }
209 if (unlikely(p->des01.etx.excessive_deferral)) {
210 DBG(KERN_INFO "\texcessive tx_deferral\n");
211 x->tx_deferred++;
212 }
213
214 if (unlikely(p->des01.etx.underflow_error)) {
215 DBG(KERN_ERR "\tunderflow error\n");
216 gmac_flush_tx_fifo(ioaddr);
217 x->tx_underflow++;
218 }
219
220 if (unlikely(p->des01.etx.ip_header_error)) {
221 DBG(KERN_ERR "\tTX IP header csum error\n");
222 x->tx_ip_header_error++;
223 }
224
225 if (unlikely(p->des01.etx.payload_error)) {
226 DBG(KERN_ERR "\tAddr/Payload csum error\n");
227 x->tx_payload_error++;
228 gmac_flush_tx_fifo(ioaddr);
229 }
230
231 ret = -1;
232 }
233
234 if (unlikely(p->des01.etx.deferred)) {
235 DBG(KERN_INFO "GMAC TX status: tx deferred\n");
236 x->tx_deferred++;
237 }
238#ifdef STMMAC_VLAN_TAG_USED
239 if (p->des01.etx.vlan_frame) {
240 DBG(KERN_INFO "GMAC TX status: VLAN frame\n");
241 x->tx_vlan++;
242 }
243#endif
244
245 return ret;
246}
247
248static int gmac_get_tx_len(struct dma_desc *p)
249{
250 return p->des01.etx.buffer1_size;
251}
252
253static int gmac_coe_rdes0(int ipc_err, int type, int payload_err)
254{
255 int ret = good_frame;
256 u32 status = (type << 2 | ipc_err << 1 | payload_err) & 0x7;
257
258 /* bits 5 7 0 | Frame status
259 * ----------------------------------------------------------
260 * 0 0 0 | IEEE 802.3 Type frame (lenght < 1536 octects)
261 * 1 0 0 | IPv4/6 No CSUM errorS.
262 * 1 0 1 | IPv4/6 CSUM PAYLOAD error
263 * 1 1 0 | IPv4/6 CSUM IP HR error
264 * 1 1 1 | IPv4/6 IP PAYLOAD AND HEADER errorS
265 * 0 0 1 | IPv4/6 unsupported IP PAYLOAD
266 * 0 1 1 | COE bypassed.. no IPv4/6 frame
267 * 0 1 0 | Reserved.
268 */
269 if (status == 0x0) {
270 DBG(KERN_INFO "RX Des0 status: IEEE 802.3 Type frame.\n");
271 ret = good_frame;
272 } else if (status == 0x4) {
273 DBG(KERN_INFO "RX Des0 status: IPv4/6 No CSUM errorS.\n");
274 ret = good_frame;
275 } else if (status == 0x5) {
276 DBG(KERN_ERR "RX Des0 status: IPv4/6 Payload Error.\n");
277 ret = csum_none;
278 } else if (status == 0x6) {
279 DBG(KERN_ERR "RX Des0 status: IPv4/6 Header Error.\n");
280 ret = csum_none;
281 } else if (status == 0x7) {
282 DBG(KERN_ERR
283 "RX Des0 status: IPv4/6 Header and Payload Error.\n");
284 ret = csum_none;
285 } else if (status == 0x1) {
286 DBG(KERN_ERR
287 "RX Des0 status: IPv4/6 unsupported IP PAYLOAD.\n");
288 ret = discard_frame;
289 } else if (status == 0x3) {
290 DBG(KERN_ERR "RX Des0 status: No IPv4, IPv6 frame.\n");
291 ret = discard_frame;
292 }
293 return ret;
294}
295
296static int gmac_get_rx_frame_status(void *data, struct stmmac_extra_stats *x,
297 struct dma_desc *p)
298{
299 int ret = good_frame;
300 struct net_device_stats *stats = (struct net_device_stats *)data;
301
302 if (unlikely(p->des01.erx.error_summary)) {
303 DBG(KERN_ERR "GMAC RX Error Summary... 0x%08x\n", p->des01.erx);
304 if (unlikely(p->des01.erx.descriptor_error)) {
305 DBG(KERN_ERR "\tdescriptor error\n");
306 x->rx_desc++;
307 stats->rx_length_errors++;
308 }
309 if (unlikely(p->des01.erx.overflow_error)) {
310 DBG(KERN_ERR "\toverflow error\n");
311 x->rx_gmac_overflow++;
312 }
313
314 if (unlikely(p->des01.erx.ipc_csum_error))
315 DBG(KERN_ERR "\tIPC Csum Error/Giant frame\n");
316
317 if (unlikely(p->des01.erx.late_collision)) {
318 DBG(KERN_ERR "\tlate_collision error\n");
319 stats->collisions++;
320 stats->collisions++;
321 }
322 if (unlikely(p->des01.erx.receive_watchdog)) {
323 DBG(KERN_ERR "\treceive_watchdog error\n");
324 x->rx_watchdog++;
325 }
326 if (unlikely(p->des01.erx.error_gmii)) {
327 DBG(KERN_ERR "\tReceive Error\n");
328 x->rx_mii++;
329 }
330 if (unlikely(p->des01.erx.crc_error)) {
331 DBG(KERN_ERR "\tCRC error\n");
332 x->rx_crc++;
333 stats->rx_crc_errors++;
334 }
335 ret = discard_frame;
336 }
337
338 /* After a payload csum error, the ES bit is set.
339 * It doesn't match with the information reported into the databook.
340 * At any rate, we need to understand if the CSUM hw computation is ok
341 * and report this info to the upper layers. */
342 ret = gmac_coe_rdes0(p->des01.erx.ipc_csum_error,
343 p->des01.erx.frame_type, p->des01.erx.payload_csum_error);
344
345 if (unlikely(p->des01.erx.dribbling)) {
346 DBG(KERN_ERR "GMAC RX: dribbling error\n");
347 ret = discard_frame;
348 }
349 if (unlikely(p->des01.erx.sa_filter_fail)) {
350 DBG(KERN_ERR "GMAC RX : Source Address filter fail\n");
351 x->sa_rx_filter_fail++;
352 ret = discard_frame;
353 }
354 if (unlikely(p->des01.erx.da_filter_fail)) {
355 DBG(KERN_ERR "GMAC RX : Destination Address filter fail\n");
356 x->da_rx_filter_fail++;
357 ret = discard_frame;
358 }
359 if (unlikely(p->des01.erx.length_error)) {
360 DBG(KERN_ERR "GMAC RX: length_error error\n");
361 x->rx_lenght++;
362 ret = discard_frame;
363 }
364#ifdef STMMAC_VLAN_TAG_USED
365 if (p->des01.erx.vlan_tag) {
366 DBG(KERN_INFO "GMAC RX: VLAN frame tagged\n");
367 x->rx_vlan++;
368 }
369#endif
370 return ret;
371}
372
373static void gmac_irq_status(unsigned long ioaddr)
374{
375 u32 intr_status = readl(ioaddr + GMAC_INT_STATUS);
376
377 /* Not used events (e.g. MMC interrupts) are not handled. */
378 if ((intr_status & mmc_tx_irq))
379 DBG(KERN_DEBUG "GMAC: MMC tx interrupt: 0x%08x\n",
380 readl(ioaddr + GMAC_MMC_TX_INTR));
381 if (unlikely(intr_status & mmc_rx_irq))
382 DBG(KERN_DEBUG "GMAC: MMC rx interrupt: 0x%08x\n",
383 readl(ioaddr + GMAC_MMC_RX_INTR));
384 if (unlikely(intr_status & mmc_rx_csum_offload_irq))
385 DBG(KERN_DEBUG "GMAC: MMC rx csum offload: 0x%08x\n",
386 readl(ioaddr + GMAC_MMC_RX_CSUM_OFFLOAD));
387 if (unlikely(intr_status & pmt_irq)) {
388 DBG(KERN_DEBUG "GMAC: received Magic frame\n");
389 /* clear the PMT bits 5 and 6 by reading the PMT
390 * status register. */
391 readl(ioaddr + GMAC_PMT);
392 }
393
394 return;
395}
396
397static void gmac_core_init(unsigned long ioaddr)
398{
399 u32 value = readl(ioaddr + GMAC_CONTROL);
400 value |= GMAC_CORE_INIT;
401 writel(value, ioaddr + GMAC_CONTROL);
402
403 /* STBus Bridge Configuration */
404 /*writel(0xc5608, ioaddr + 0x00007000);*/
405
406 /* Freeze MMC counters */
407 writel(0x8, ioaddr + GMAC_MMC_CTRL);
408 /* Mask GMAC interrupts */
409 writel(0x207, ioaddr + GMAC_INT_MASK);
410
411#ifdef STMMAC_VLAN_TAG_USED
412 /* Tag detection without filtering */
413 writel(0x0, ioaddr + GMAC_VLAN_TAG);
414#endif
415 return;
416}
417
418static void gmac_set_umac_addr(unsigned long ioaddr, unsigned char *addr,
419 unsigned int reg_n)
420{
421 stmmac_set_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(reg_n),
422 GMAC_ADDR_LOW(reg_n));
423}
424
425static void gmac_get_umac_addr(unsigned long ioaddr, unsigned char *addr,
426 unsigned int reg_n)
427{
428 stmmac_get_mac_addr(ioaddr, addr, GMAC_ADDR_HIGH(reg_n),
429 GMAC_ADDR_LOW(reg_n));
430}
431
432static void gmac_set_filter(struct net_device *dev)
433{
434 unsigned long ioaddr = dev->base_addr;
435 unsigned int value = 0;
436
437 DBG(KERN_INFO "%s: # mcasts %d, # unicast %d\n",
438 __func__, dev->mc_count, dev->uc_count);
439
440 if (dev->flags & IFF_PROMISC)
441 value = GMAC_FRAME_FILTER_PR;
442 else if ((dev->mc_count > HASH_TABLE_SIZE)
443 || (dev->flags & IFF_ALLMULTI)) {
444 value = GMAC_FRAME_FILTER_PM; /* pass all multi */
445 writel(0xffffffff, ioaddr + GMAC_HASH_HIGH);
446 writel(0xffffffff, ioaddr + GMAC_HASH_LOW);
447 } else if (dev->mc_count > 0) {
448 int i;
449 u32 mc_filter[2];
450 struct dev_mc_list *mclist;
451
452 /* Hash filter for multicast */
453 value = GMAC_FRAME_FILTER_HMC;
454
455 memset(mc_filter, 0, sizeof(mc_filter));
456 for (i = 0, mclist = dev->mc_list;
457 mclist && i < dev->mc_count; i++, mclist = mclist->next) {
458 /* The upper 6 bits of the calculated CRC are used to
459 index the contens of the hash table */
460 int bit_nr =
461 bitrev32(~crc32_le(~0, mclist->dmi_addr, 6)) >> 26;
462 /* The most significant bit determines the register to
463 * use (H/L) while the other 5 bits determine the bit
464 * within the register. */
465 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
466 }
467 writel(mc_filter[0], ioaddr + GMAC_HASH_LOW);
468 writel(mc_filter[1], ioaddr + GMAC_HASH_HIGH);
469 }
470
471 /* Handle multiple unicast addresses (perfect filtering)*/
472 if (dev->uc_count > GMAC_MAX_UNICAST_ADDRESSES)
473 /* Switch to promiscuous mode is more than 16 addrs
474 are required */
475 value |= GMAC_FRAME_FILTER_PR;
476 else {
477 int i;
478 struct dev_addr_list *uc_ptr = dev->uc_list;
479
480 for (i = 0; i < dev->uc_count; i++) {
481 gmac_set_umac_addr(ioaddr, uc_ptr->da_addr,
482 i + 1);
483
484 DBG(KERN_INFO "\t%d "
485 "- Unicast addr %02x:%02x:%02x:%02x:%02x:"
486 "%02x\n", i + 1,
487 uc_ptr->da_addr[0], uc_ptr->da_addr[1],
488 uc_ptr->da_addr[2], uc_ptr->da_addr[3],
489 uc_ptr->da_addr[4], uc_ptr->da_addr[5]);
490 uc_ptr = uc_ptr->next;
491 }
492 }
493
494#ifdef FRAME_FILTER_DEBUG
495 /* Enable Receive all mode (to debug filtering_fail errors) */
496 value |= GMAC_FRAME_FILTER_RA;
497#endif
498 writel(value, ioaddr + GMAC_FRAME_FILTER);
499
500 DBG(KERN_INFO "\tFrame Filter reg: 0x%08x\n\tHash regs: "
501 "HI 0x%08x, LO 0x%08x\n", readl(ioaddr + GMAC_FRAME_FILTER),
502 readl(ioaddr + GMAC_HASH_HIGH), readl(ioaddr + GMAC_HASH_LOW));
503
504 return;
505}
506
507static void gmac_flow_ctrl(unsigned long ioaddr, unsigned int duplex,
508 unsigned int fc, unsigned int pause_time)
509{
510 unsigned int flow = 0;
511
512 DBG(KERN_DEBUG "GMAC Flow-Control:\n");
513 if (fc & FLOW_RX) {
514 DBG(KERN_DEBUG "\tReceive Flow-Control ON\n");
515 flow |= GMAC_FLOW_CTRL_RFE;
516 }
517 if (fc & FLOW_TX) {
518 DBG(KERN_DEBUG "\tTransmit Flow-Control ON\n");
519 flow |= GMAC_FLOW_CTRL_TFE;
520 }
521
522 if (duplex) {
523 DBG(KERN_DEBUG "\tduplex mode: pause time: %d\n", pause_time);
524 flow |= (pause_time << GMAC_FLOW_CTRL_PT_SHIFT);
525 }
526
527 writel(flow, ioaddr + GMAC_FLOW_CTRL);
528 return;
529}
530
531static void gmac_pmt(unsigned long ioaddr, unsigned long mode)
532{
533 unsigned int pmt = 0;
534
535 if (mode == WAKE_MAGIC) {
536 DBG(KERN_DEBUG "GMAC: WOL Magic frame\n");
537 pmt |= power_down | magic_pkt_en;
538 } else if (mode == WAKE_UCAST) {
539 DBG(KERN_DEBUG "GMAC: WOL on global unicast\n");
540 pmt |= global_unicast;
541 }
542
543 writel(pmt, ioaddr + GMAC_PMT);
544 return;
545}
546
547static void gmac_init_rx_desc(struct dma_desc *p, unsigned int ring_size,
548 int disable_rx_ic)
549{
550 int i;
551 for (i = 0; i < ring_size; i++) {
552 p->des01.erx.own = 1;
553 p->des01.erx.buffer1_size = BUF_SIZE_8KiB - 1;
554 /* To support jumbo frames */
555 p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1;
556 if (i == ring_size - 1)
557 p->des01.erx.end_ring = 1;
558 if (disable_rx_ic)
559 p->des01.erx.disable_ic = 1;
560 p++;
561 }
562 return;
563}
564
565static void gmac_init_tx_desc(struct dma_desc *p, unsigned int ring_size)
566{
567 int i;
568
569 for (i = 0; i < ring_size; i++) {
570 p->des01.etx.own = 0;
571 if (i == ring_size - 1)
572 p->des01.etx.end_ring = 1;
573 p++;
574 }
575
576 return;
577}
578
579static int gmac_get_tx_owner(struct dma_desc *p)
580{
581 return p->des01.etx.own;
582}
583
584static int gmac_get_rx_owner(struct dma_desc *p)
585{
586 return p->des01.erx.own;
587}
588
589static void gmac_set_tx_owner(struct dma_desc *p)
590{
591 p->des01.etx.own = 1;
592}
593
594static void gmac_set_rx_owner(struct dma_desc *p)
595{
596 p->des01.erx.own = 1;
597}
598
599static int gmac_get_tx_ls(struct dma_desc *p)
600{
601 return p->des01.etx.last_segment;
602}
603
604static void gmac_release_tx_desc(struct dma_desc *p)
605{
606 int ter = p->des01.etx.end_ring;
607
608 memset(p, 0, sizeof(struct dma_desc));
609 p->des01.etx.end_ring = ter;
610
611 return;
612}
613
614static void gmac_prepare_tx_desc(struct dma_desc *p, int is_fs, int len,
615 int csum_flag)
616{
617 p->des01.etx.first_segment = is_fs;
618 if (unlikely(len > BUF_SIZE_4KiB)) {
619 p->des01.etx.buffer1_size = BUF_SIZE_4KiB;
620 p->des01.etx.buffer2_size = len - BUF_SIZE_4KiB;
621 } else {
622 p->des01.etx.buffer1_size = len;
623 }
624 if (likely(csum_flag))
625 p->des01.etx.checksum_insertion = cic_full;
626}
627
628static void gmac_clear_tx_ic(struct dma_desc *p)
629{
630 p->des01.etx.interrupt = 0;
631}
632
633static void gmac_close_tx_desc(struct dma_desc *p)
634{
635 p->des01.etx.last_segment = 1;
636 p->des01.etx.interrupt = 1;
637}
638
639static int gmac_get_rx_frame_len(struct dma_desc *p)
640{
641 return p->des01.erx.frame_length;
642}
643
644struct stmmac_ops gmac_driver = {
645 .core_init = gmac_core_init,
646 .dump_mac_regs = gmac_dump_regs,
647 .dma_init = gmac_dma_init,
648 .dump_dma_regs = gmac_dump_dma_regs,
649 .dma_mode = gmac_dma_operation_mode,
650 .dma_diagnostic_fr = gmac_dma_diagnostic_fr,
651 .tx_status = gmac_get_tx_frame_status,
652 .rx_status = gmac_get_rx_frame_status,
653 .get_tx_len = gmac_get_tx_len,
654 .set_filter = gmac_set_filter,
655 .flow_ctrl = gmac_flow_ctrl,
656 .pmt = gmac_pmt,
657 .init_rx_desc = gmac_init_rx_desc,
658 .init_tx_desc = gmac_init_tx_desc,
659 .get_tx_owner = gmac_get_tx_owner,
660 .get_rx_owner = gmac_get_rx_owner,
661 .release_tx_desc = gmac_release_tx_desc,
662 .prepare_tx_desc = gmac_prepare_tx_desc,
663 .clear_tx_ic = gmac_clear_tx_ic,
664 .close_tx_desc = gmac_close_tx_desc,
665 .get_tx_ls = gmac_get_tx_ls,
666 .set_tx_owner = gmac_set_tx_owner,
667 .set_rx_owner = gmac_set_rx_owner,
668 .get_rx_frame_len = gmac_get_rx_frame_len,
669 .host_irq_status = gmac_irq_status,
670 .set_umac_addr = gmac_set_umac_addr,
671 .get_umac_addr = gmac_get_umac_addr,
672};
673
674struct mac_device_info *gmac_setup(unsigned long ioaddr)
675{
676 struct mac_device_info *mac;
677 u32 uid = readl(ioaddr + GMAC_VERSION);
678
679 pr_info("\tGMAC - user ID: 0x%x, Synopsys ID: 0x%x\n",
680 ((uid & 0x0000ff00) >> 8), (uid & 0x000000ff));
681
682 mac = kzalloc(sizeof(const struct mac_device_info), GFP_KERNEL);
683
684 mac->ops = &gmac_driver;
685 mac->hw.pmt = PMT_SUPPORTED;
686 mac->hw.link.port = GMAC_CONTROL_PS;
687 mac->hw.link.duplex = GMAC_CONTROL_DM;
688 mac->hw.link.speed = GMAC_CONTROL_FES;
689 mac->hw.mii.addr = GMAC_MII_ADDR;
690 mac->hw.mii.data = GMAC_MII_DATA;
691
692 return mac;
693}
diff --git a/drivers/net/stmmac/gmac.h b/drivers/net/stmmac/gmac.h
new file mode 100644
index 000000000000..684a363120a9
--- /dev/null
+++ b/drivers/net/stmmac/gmac.h
@@ -0,0 +1,204 @@
1/*******************************************************************************
2 Copyright (C) 2007-2009 STMicroelectronics Ltd
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms and conditions of the GNU General Public License,
6 version 2, as published by the Free Software Foundation.
7
8 This program is distributed in the hope it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 more details.
12
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16
17 The full GNU General Public License is included in this distribution in
18 the file called "COPYING".
19
20 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
21*******************************************************************************/
22
23#define GMAC_CONTROL 0x00000000 /* Configuration */
24#define GMAC_FRAME_FILTER 0x00000004 /* Frame Filter */
25#define GMAC_HASH_HIGH 0x00000008 /* Multicast Hash Table High */
26#define GMAC_HASH_LOW 0x0000000c /* Multicast Hash Table Low */
27#define GMAC_MII_ADDR 0x00000010 /* MII Address */
28#define GMAC_MII_DATA 0x00000014 /* MII Data */
29#define GMAC_FLOW_CTRL 0x00000018 /* Flow Control */
30#define GMAC_VLAN_TAG 0x0000001c /* VLAN Tag */
31#define GMAC_VERSION 0x00000020 /* GMAC CORE Version */
32#define GMAC_WAKEUP_FILTER 0x00000028 /* Wake-up Frame Filter */
33
34#define GMAC_INT_STATUS 0x00000038 /* interrupt status register */
35enum gmac_irq_status {
36 time_stamp_irq = 0x0200,
37 mmc_rx_csum_offload_irq = 0x0080,
38 mmc_tx_irq = 0x0040,
39 mmc_rx_irq = 0x0020,
40 mmc_irq = 0x0010,
41 pmt_irq = 0x0008,
42 pcs_ane_irq = 0x0004,
43 pcs_link_irq = 0x0002,
44 rgmii_irq = 0x0001,
45};
46#define GMAC_INT_MASK 0x0000003c /* interrupt mask register */
47
48/* PMT Control and Status */
49#define GMAC_PMT 0x0000002c
50enum power_event {
51 pointer_reset = 0x80000000,
52 global_unicast = 0x00000200,
53 wake_up_rx_frame = 0x00000040,
54 magic_frame = 0x00000020,
55 wake_up_frame_en = 0x00000004,
56 magic_pkt_en = 0x00000002,
57 power_down = 0x00000001,
58};
59
60/* GMAC HW ADDR regs */
61#define GMAC_ADDR_HIGH(reg) (0x00000040+(reg * 8))
62#define GMAC_ADDR_LOW(reg) (0x00000044+(reg * 8))
63#define GMAC_MAX_UNICAST_ADDRESSES 16
64
65#define GMAC_AN_CTRL 0x000000c0 /* AN control */
66#define GMAC_AN_STATUS 0x000000c4 /* AN status */
67#define GMAC_ANE_ADV 0x000000c8 /* Auto-Neg. Advertisement */
68#define GMAC_ANE_LINK 0x000000cc /* Auto-Neg. link partener ability */
69#define GMAC_ANE_EXP 0x000000d0 /* ANE expansion */
70#define GMAC_TBI 0x000000d4 /* TBI extend status */
71#define GMAC_GMII_STATUS 0x000000d8 /* S/R-GMII status */
72
73/* GMAC Configuration defines */
74#define GMAC_CONTROL_TC 0x01000000 /* Transmit Conf. in RGMII/SGMII */
75#define GMAC_CONTROL_WD 0x00800000 /* Disable Watchdog on receive */
76#define GMAC_CONTROL_JD 0x00400000 /* Jabber disable */
77#define GMAC_CONTROL_BE 0x00200000 /* Frame Burst Enable */
78#define GMAC_CONTROL_JE 0x00100000 /* Jumbo frame */
79enum inter_frame_gap {
80 GMAC_CONTROL_IFG_88 = 0x00040000,
81 GMAC_CONTROL_IFG_80 = 0x00020000,
82 GMAC_CONTROL_IFG_40 = 0x000e0000,
83};
84#define GMAC_CONTROL_DCRS 0x00010000 /* Disable carrier sense during tx */
85#define GMAC_CONTROL_PS 0x00008000 /* Port Select 0:GMI 1:MII */
86#define GMAC_CONTROL_FES 0x00004000 /* Speed 0:10 1:100 */
87#define GMAC_CONTROL_DO 0x00002000 /* Disable Rx Own */
88#define GMAC_CONTROL_LM 0x00001000 /* Loop-back mode */
89#define GMAC_CONTROL_DM 0x00000800 /* Duplex Mode */
90#define GMAC_CONTROL_IPC 0x00000400 /* Checksum Offload */
91#define GMAC_CONTROL_DR 0x00000200 /* Disable Retry */
92#define GMAC_CONTROL_LUD 0x00000100 /* Link up/down */
93#define GMAC_CONTROL_ACS 0x00000080 /* Automatic Pad Stripping */
94#define GMAC_CONTROL_DC 0x00000010 /* Deferral Check */
95#define GMAC_CONTROL_TE 0x00000008 /* Transmitter Enable */
96#define GMAC_CONTROL_RE 0x00000004 /* Receiver Enable */
97
98#define GMAC_CORE_INIT (GMAC_CONTROL_JD | GMAC_CONTROL_PS | GMAC_CONTROL_ACS | \
99 GMAC_CONTROL_IPC | GMAC_CONTROL_JE | GMAC_CONTROL_BE)
100
101/* GMAC Frame Filter defines */
102#define GMAC_FRAME_FILTER_PR 0x00000001 /* Promiscuous Mode */
103#define GMAC_FRAME_FILTER_HUC 0x00000002 /* Hash Unicast */
104#define GMAC_FRAME_FILTER_HMC 0x00000004 /* Hash Multicast */
105#define GMAC_FRAME_FILTER_DAIF 0x00000008 /* DA Inverse Filtering */
106#define GMAC_FRAME_FILTER_PM 0x00000010 /* Pass all multicast */
107#define GMAC_FRAME_FILTER_DBF 0x00000020 /* Disable Broadcast frames */
108#define GMAC_FRAME_FILTER_SAIF 0x00000100 /* Inverse Filtering */
109#define GMAC_FRAME_FILTER_SAF 0x00000200 /* Source Address Filter */
110#define GMAC_FRAME_FILTER_HPF 0x00000400 /* Hash or perfect Filter */
111#define GMAC_FRAME_FILTER_RA 0x80000000 /* Receive all mode */
112/* GMII ADDR defines */
113#define GMAC_MII_ADDR_WRITE 0x00000002 /* MII Write */
114#define GMAC_MII_ADDR_BUSY 0x00000001 /* MII Busy */
115/* GMAC FLOW CTRL defines */
116#define GMAC_FLOW_CTRL_PT_MASK 0xffff0000 /* Pause Time Mask */
117#define GMAC_FLOW_CTRL_PT_SHIFT 16
118#define GMAC_FLOW_CTRL_RFE 0x00000004 /* Rx Flow Control Enable */
119#define GMAC_FLOW_CTRL_TFE 0x00000002 /* Tx Flow Control Enable */
120#define GMAC_FLOW_CTRL_FCB_BPA 0x00000001 /* Flow Control Busy ... */
121
122/*--- DMA BLOCK defines ---*/
123/* DMA Bus Mode register defines */
124#define DMA_BUS_MODE_SFT_RESET 0x00000001 /* Software Reset */
125#define DMA_BUS_MODE_DA 0x00000002 /* Arbitration scheme */
126#define DMA_BUS_MODE_DSL_MASK 0x0000007c /* Descriptor Skip Length */
127#define DMA_BUS_MODE_DSL_SHIFT 2 /* (in DWORDS) */
128/* Programmable burst length (passed thorugh platform)*/
129#define DMA_BUS_MODE_PBL_MASK 0x00003f00 /* Programmable Burst Len */
130#define DMA_BUS_MODE_PBL_SHIFT 8
131
132enum rx_tx_priority_ratio {
133 double_ratio = 0x00004000, /*2:1 */
134 triple_ratio = 0x00008000, /*3:1 */
135 quadruple_ratio = 0x0000c000, /*4:1 */
136};
137
138#define DMA_BUS_MODE_FB 0x00010000 /* Fixed burst */
139#define DMA_BUS_MODE_RPBL_MASK 0x003e0000 /* Rx-Programmable Burst Len */
140#define DMA_BUS_MODE_RPBL_SHIFT 17
141#define DMA_BUS_MODE_USP 0x00800000
142#define DMA_BUS_MODE_4PBL 0x01000000
143#define DMA_BUS_MODE_AAL 0x02000000
144
145/* DMA CRS Control and Status Register Mapping */
146#define DMA_HOST_TX_DESC 0x00001048 /* Current Host Tx descriptor */
147#define DMA_HOST_RX_DESC 0x0000104c /* Current Host Rx descriptor */
148/* DMA Bus Mode register defines */
149#define DMA_BUS_PR_RATIO_MASK 0x0000c000 /* Rx/Tx priority ratio */
150#define DMA_BUS_PR_RATIO_SHIFT 14
151#define DMA_BUS_FB 0x00010000 /* Fixed Burst */
152
153/* DMA operation mode defines (start/stop tx/rx are placed in common header)*/
154#define DMA_CONTROL_DT 0x04000000 /* Disable Drop TCP/IP csum error */
155#define DMA_CONTROL_RSF 0x02000000 /* Receive Store and Forward */
156#define DMA_CONTROL_DFF 0x01000000 /* Disaable flushing */
157/* Theshold for Activating the FC */
158enum rfa {
159 act_full_minus_1 = 0x00800000,
160 act_full_minus_2 = 0x00800200,
161 act_full_minus_3 = 0x00800400,
162 act_full_minus_4 = 0x00800600,
163};
164/* Theshold for Deactivating the FC */
165enum rfd {
166 deac_full_minus_1 = 0x00400000,
167 deac_full_minus_2 = 0x00400800,
168 deac_full_minus_3 = 0x00401000,
169 deac_full_minus_4 = 0x00401800,
170};
171#define DMA_CONTROL_TSF 0x00200000 /* Transmit Store and Forward */
172#define DMA_CONTROL_FTF 0x00100000 /* Flush transmit FIFO */
173
174enum ttc_control {
175 DMA_CONTROL_TTC_64 = 0x00000000,
176 DMA_CONTROL_TTC_128 = 0x00004000,
177 DMA_CONTROL_TTC_192 = 0x00008000,
178 DMA_CONTROL_TTC_256 = 0x0000c000,
179 DMA_CONTROL_TTC_40 = 0x00010000,
180 DMA_CONTROL_TTC_32 = 0x00014000,
181 DMA_CONTROL_TTC_24 = 0x00018000,
182 DMA_CONTROL_TTC_16 = 0x0001c000,
183};
184#define DMA_CONTROL_TC_TX_MASK 0xfffe3fff
185
186#define DMA_CONTROL_EFC 0x00000100
187#define DMA_CONTROL_FEF 0x00000080
188#define DMA_CONTROL_FUF 0x00000040
189
190enum rtc_control {
191 DMA_CONTROL_RTC_64 = 0x00000000,
192 DMA_CONTROL_RTC_32 = 0x00000008,
193 DMA_CONTROL_RTC_96 = 0x00000010,
194 DMA_CONTROL_RTC_128 = 0x00000018,
195};
196#define DMA_CONTROL_TC_RX_MASK 0xffffffe7
197
198#define DMA_CONTROL_OSF 0x00000004 /* Operate on second frame */
199
200/* MMC registers offset */
201#define GMAC_MMC_CTRL 0x100
202#define GMAC_MMC_RX_INTR 0x104
203#define GMAC_MMC_TX_INTR 0x108
204#define GMAC_MMC_RX_CSUM_OFFLOAD 0x208
diff --git a/drivers/net/stmmac/mac100.c b/drivers/net/stmmac/mac100.c
new file mode 100644
index 000000000000..625171b6062b
--- /dev/null
+++ b/drivers/net/stmmac/mac100.c
@@ -0,0 +1,517 @@
1/*******************************************************************************
2 This is the driver for the MAC 10/100 on-chip Ethernet controller
3 currently tested on all the ST boards based on STb7109 and stx7200 SoCs.
4
5 DWC Ether MAC 10/100 Universal version 4.0 has been used for developing
6 this code.
7
8 Copyright (C) 2007-2009 STMicroelectronics Ltd
9
10 This program is free software; you can redistribute it and/or modify it
11 under the terms and conditions of the GNU General Public License,
12 version 2, as published by the Free Software Foundation.
13
14 This program is distributed in the hope it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 more details.
18
19 You should have received a copy of the GNU General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc.,
21 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
22
23 The full GNU General Public License is included in this distribution in
24 the file called "COPYING".
25
26 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
27*******************************************************************************/
28
29#include <linux/netdevice.h>
30#include <linux/crc32.h>
31#include <linux/mii.h>
32#include <linux/phy.h>
33
34#include "common.h"
35#include "mac100.h"
36
37#undef MAC100_DEBUG
38/*#define MAC100_DEBUG*/
39#ifdef MAC100_DEBUG
40#define DBG(fmt, args...) printk(fmt, ## args)
41#else
42#define DBG(fmt, args...) do { } while (0)
43#endif
44
45static void mac100_core_init(unsigned long ioaddr)
46{
47 u32 value = readl(ioaddr + MAC_CONTROL);
48
49 writel((value | MAC_CORE_INIT), ioaddr + MAC_CONTROL);
50
51#ifdef STMMAC_VLAN_TAG_USED
52 writel(ETH_P_8021Q, ioaddr + MAC_VLAN1);
53#endif
54 return;
55}
56
57static void mac100_dump_mac_regs(unsigned long ioaddr)
58{
59 pr_info("\t----------------------------------------------\n"
60 "\t MAC100 CSR (base addr = 0x%8x)\n"
61 "\t----------------------------------------------\n",
62 (unsigned int)ioaddr);
63 pr_info("\tcontrol reg (offset 0x%x): 0x%08x\n", MAC_CONTROL,
64 readl(ioaddr + MAC_CONTROL));
65 pr_info("\taddr HI (offset 0x%x): 0x%08x\n ", MAC_ADDR_HIGH,
66 readl(ioaddr + MAC_ADDR_HIGH));
67 pr_info("\taddr LO (offset 0x%x): 0x%08x\n", MAC_ADDR_LOW,
68 readl(ioaddr + MAC_ADDR_LOW));
69 pr_info("\tmulticast hash HI (offset 0x%x): 0x%08x\n",
70 MAC_HASH_HIGH, readl(ioaddr + MAC_HASH_HIGH));
71 pr_info("\tmulticast hash LO (offset 0x%x): 0x%08x\n",
72 MAC_HASH_LOW, readl(ioaddr + MAC_HASH_LOW));
73 pr_info("\tflow control (offset 0x%x): 0x%08x\n",
74 MAC_FLOW_CTRL, readl(ioaddr + MAC_FLOW_CTRL));
75 pr_info("\tVLAN1 tag (offset 0x%x): 0x%08x\n", MAC_VLAN1,
76 readl(ioaddr + MAC_VLAN1));
77 pr_info("\tVLAN2 tag (offset 0x%x): 0x%08x\n", MAC_VLAN2,
78 readl(ioaddr + MAC_VLAN2));
79 pr_info("\n\tMAC management counter registers\n");
80 pr_info("\t MMC crtl (offset 0x%x): 0x%08x\n",
81 MMC_CONTROL, readl(ioaddr + MMC_CONTROL));
82 pr_info("\t MMC High Interrupt (offset 0x%x): 0x%08x\n",
83 MMC_HIGH_INTR, readl(ioaddr + MMC_HIGH_INTR));
84 pr_info("\t MMC Low Interrupt (offset 0x%x): 0x%08x\n",
85 MMC_LOW_INTR, readl(ioaddr + MMC_LOW_INTR));
86 pr_info("\t MMC High Interrupt Mask (offset 0x%x): 0x%08x\n",
87 MMC_HIGH_INTR_MASK, readl(ioaddr + MMC_HIGH_INTR_MASK));
88 pr_info("\t MMC Low Interrupt Mask (offset 0x%x): 0x%08x\n",
89 MMC_LOW_INTR_MASK, readl(ioaddr + MMC_LOW_INTR_MASK));
90 return;
91}
92
93static int mac100_dma_init(unsigned long ioaddr, int pbl, u32 dma_tx,
94 u32 dma_rx)
95{
96 u32 value = readl(ioaddr + DMA_BUS_MODE);
97 /* DMA SW reset */
98 value |= DMA_BUS_MODE_SFT_RESET;
99 writel(value, ioaddr + DMA_BUS_MODE);
100 do {} while ((readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET));
101
102 /* Enable Application Access by writing to DMA CSR0 */
103 writel(DMA_BUS_MODE_DEFAULT | (pbl << DMA_BUS_MODE_PBL_SHIFT),
104 ioaddr + DMA_BUS_MODE);
105
106 /* Mask interrupts by writing to CSR7 */
107 writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
108
109 /* The base address of the RX/TX descriptor lists must be written into
110 * DMA CSR3 and CSR4, respectively. */
111 writel(dma_tx, ioaddr + DMA_TX_BASE_ADDR);
112 writel(dma_rx, ioaddr + DMA_RCV_BASE_ADDR);
113
114 return 0;
115}
116
117/* Store and Forward capability is not used at all..
118 * The transmit threshold can be programmed by
119 * setting the TTC bits in the DMA control register.*/
120static void mac100_dma_operation_mode(unsigned long ioaddr, int txmode,
121 int rxmode)
122{
123 u32 csr6 = readl(ioaddr + DMA_CONTROL);
124
125 if (txmode <= 32)
126 csr6 |= DMA_CONTROL_TTC_32;
127 else if (txmode <= 64)
128 csr6 |= DMA_CONTROL_TTC_64;
129 else
130 csr6 |= DMA_CONTROL_TTC_128;
131
132 writel(csr6, ioaddr + DMA_CONTROL);
133
134 return;
135}
136
137static void mac100_dump_dma_regs(unsigned long ioaddr)
138{
139 int i;
140
141 DBG(KERN_DEBUG "MAC100 DMA CSR \n");
142 for (i = 0; i < 9; i++)
143 pr_debug("\t CSR%d (offset 0x%x): 0x%08x\n", i,
144 (DMA_BUS_MODE + i * 4),
145 readl(ioaddr + DMA_BUS_MODE + i * 4));
146 DBG(KERN_DEBUG "\t CSR20 (offset 0x%x): 0x%08x\n",
147 DMA_CUR_TX_BUF_ADDR, readl(ioaddr + DMA_CUR_TX_BUF_ADDR));
148 DBG(KERN_DEBUG "\t CSR21 (offset 0x%x): 0x%08x\n",
149 DMA_CUR_RX_BUF_ADDR, readl(ioaddr + DMA_CUR_RX_BUF_ADDR));
150 return;
151}
152
153/* DMA controller has two counters to track the number of
154 the receive missed frames. */
155static void mac100_dma_diagnostic_fr(void *data, struct stmmac_extra_stats *x,
156 unsigned long ioaddr)
157{
158 struct net_device_stats *stats = (struct net_device_stats *)data;
159 u32 csr8 = readl(ioaddr + DMA_MISSED_FRAME_CTR);
160
161 if (unlikely(csr8)) {
162 if (csr8 & DMA_MISSED_FRAME_OVE) {
163 stats->rx_over_errors += 0x800;
164 x->rx_overflow_cntr += 0x800;
165 } else {
166 unsigned int ove_cntr;
167 ove_cntr = ((csr8 & DMA_MISSED_FRAME_OVE_CNTR) >> 17);
168 stats->rx_over_errors += ove_cntr;
169 x->rx_overflow_cntr += ove_cntr;
170 }
171
172 if (csr8 & DMA_MISSED_FRAME_OVE_M) {
173 stats->rx_missed_errors += 0xffff;
174 x->rx_missed_cntr += 0xffff;
175 } else {
176 unsigned int miss_f = (csr8 & DMA_MISSED_FRAME_M_CNTR);
177 stats->rx_missed_errors += miss_f;
178 x->rx_missed_cntr += miss_f;
179 }
180 }
181 return;
182}
183
184static int mac100_get_tx_frame_status(void *data, struct stmmac_extra_stats *x,
185 struct dma_desc *p, unsigned long ioaddr)
186{
187 int ret = 0;
188 struct net_device_stats *stats = (struct net_device_stats *)data;
189
190 if (unlikely(p->des01.tx.error_summary)) {
191 if (unlikely(p->des01.tx.underflow_error)) {
192 x->tx_underflow++;
193 stats->tx_fifo_errors++;
194 }
195 if (unlikely(p->des01.tx.no_carrier)) {
196 x->tx_carrier++;
197 stats->tx_carrier_errors++;
198 }
199 if (unlikely(p->des01.tx.loss_carrier)) {
200 x->tx_losscarrier++;
201 stats->tx_carrier_errors++;
202 }
203 if (unlikely((p->des01.tx.excessive_deferral) ||
204 (p->des01.tx.excessive_collisions) ||
205 (p->des01.tx.late_collision)))
206 stats->collisions += p->des01.tx.collision_count;
207 ret = -1;
208 }
209 if (unlikely(p->des01.tx.heartbeat_fail)) {
210 x->tx_heartbeat++;
211 stats->tx_heartbeat_errors++;
212 ret = -1;
213 }
214 if (unlikely(p->des01.tx.deferred))
215 x->tx_deferred++;
216
217 return ret;
218}
219
220static int mac100_get_tx_len(struct dma_desc *p)
221{
222 return p->des01.tx.buffer1_size;
223}
224
225/* This function verifies if each incoming frame has some errors
226 * and, if required, updates the multicast statistics.
227 * In case of success, it returns csum_none becasue the device
228 * is not able to compute the csum in HW. */
229static int mac100_get_rx_frame_status(void *data, struct stmmac_extra_stats *x,
230 struct dma_desc *p)
231{
232 int ret = csum_none;
233 struct net_device_stats *stats = (struct net_device_stats *)data;
234
235 if (unlikely(p->des01.rx.last_descriptor == 0)) {
236 pr_warning("mac100 Error: Oversized Ethernet "
237 "frame spanned multiple buffers\n");
238 stats->rx_length_errors++;
239 return discard_frame;
240 }
241
242 if (unlikely(p->des01.rx.error_summary)) {
243 if (unlikely(p->des01.rx.descriptor_error))
244 x->rx_desc++;
245 if (unlikely(p->des01.rx.partial_frame_error))
246 x->rx_partial++;
247 if (unlikely(p->des01.rx.run_frame))
248 x->rx_runt++;
249 if (unlikely(p->des01.rx.frame_too_long))
250 x->rx_toolong++;
251 if (unlikely(p->des01.rx.collision)) {
252 x->rx_collision++;
253 stats->collisions++;
254 }
255 if (unlikely(p->des01.rx.crc_error)) {
256 x->rx_crc++;
257 stats->rx_crc_errors++;
258 }
259 ret = discard_frame;
260 }
261 if (unlikely(p->des01.rx.dribbling))
262 ret = discard_frame;
263
264 if (unlikely(p->des01.rx.length_error)) {
265 x->rx_lenght++;
266 ret = discard_frame;
267 }
268 if (unlikely(p->des01.rx.mii_error)) {
269 x->rx_mii++;
270 ret = discard_frame;
271 }
272 if (p->des01.rx.multicast_frame) {
273 x->rx_multicast++;
274 stats->multicast++;
275 }
276 return ret;
277}
278
279static void mac100_irq_status(unsigned long ioaddr)
280{
281 return;
282}
283
284static void mac100_set_umac_addr(unsigned long ioaddr, unsigned char *addr,
285 unsigned int reg_n)
286{
287 stmmac_set_mac_addr(ioaddr, addr, MAC_ADDR_HIGH, MAC_ADDR_LOW);
288}
289
290static void mac100_get_umac_addr(unsigned long ioaddr, unsigned char *addr,
291 unsigned int reg_n)
292{
293 stmmac_get_mac_addr(ioaddr, addr, MAC_ADDR_HIGH, MAC_ADDR_LOW);
294}
295
296static void mac100_set_filter(struct net_device *dev)
297{
298 unsigned long ioaddr = dev->base_addr;
299 u32 value = readl(ioaddr + MAC_CONTROL);
300
301 if (dev->flags & IFF_PROMISC) {
302 value |= MAC_CONTROL_PR;
303 value &= ~(MAC_CONTROL_PM | MAC_CONTROL_IF | MAC_CONTROL_HO |
304 MAC_CONTROL_HP);
305 } else if ((dev->mc_count > HASH_TABLE_SIZE)
306 || (dev->flags & IFF_ALLMULTI)) {
307 value |= MAC_CONTROL_PM;
308 value &= ~(MAC_CONTROL_PR | MAC_CONTROL_IF | MAC_CONTROL_HO);
309 writel(0xffffffff, ioaddr + MAC_HASH_HIGH);
310 writel(0xffffffff, ioaddr + MAC_HASH_LOW);
311 } else if (dev->mc_count == 0) { /* no multicast */
312 value &= ~(MAC_CONTROL_PM | MAC_CONTROL_PR | MAC_CONTROL_IF |
313 MAC_CONTROL_HO | MAC_CONTROL_HP);
314 } else {
315 int i;
316 u32 mc_filter[2];
317 struct dev_mc_list *mclist;
318
319 /* Perfect filter mode for physical address and Hash
320 filter for multicast */
321 value |= MAC_CONTROL_HP;
322 value &= ~(MAC_CONTROL_PM | MAC_CONTROL_PR | MAC_CONTROL_IF
323 | MAC_CONTROL_HO);
324
325 memset(mc_filter, 0, sizeof(mc_filter));
326 for (i = 0, mclist = dev->mc_list;
327 mclist && i < dev->mc_count; i++, mclist = mclist->next) {
328 /* The upper 6 bits of the calculated CRC are used to
329 * index the contens of the hash table */
330 int bit_nr =
331 ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
332 /* The most significant bit determines the register to
333 * use (H/L) while the other 5 bits determine the bit
334 * within the register. */
335 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
336 }
337 writel(mc_filter[0], ioaddr + MAC_HASH_LOW);
338 writel(mc_filter[1], ioaddr + MAC_HASH_HIGH);
339 }
340
341 writel(value, ioaddr + MAC_CONTROL);
342
343 DBG(KERN_INFO "%s: CTRL reg: 0x%08x Hash regs: "
344 "HI 0x%08x, LO 0x%08x\n",
345 __func__, readl(ioaddr + MAC_CONTROL),
346 readl(ioaddr + MAC_HASH_HIGH), readl(ioaddr + MAC_HASH_LOW));
347 return;
348}
349
350static void mac100_flow_ctrl(unsigned long ioaddr, unsigned int duplex,
351 unsigned int fc, unsigned int pause_time)
352{
353 unsigned int flow = MAC_FLOW_CTRL_ENABLE;
354
355 if (duplex)
356 flow |= (pause_time << MAC_FLOW_CTRL_PT_SHIFT);
357 writel(flow, ioaddr + MAC_FLOW_CTRL);
358
359 return;
360}
361
362/* No PMT module supported in our SoC for the Ethernet Controller. */
363static void mac100_pmt(unsigned long ioaddr, unsigned long mode)
364{
365 return;
366}
367
368static void mac100_init_rx_desc(struct dma_desc *p, unsigned int ring_size,
369 int disable_rx_ic)
370{
371 int i;
372 for (i = 0; i < ring_size; i++) {
373 p->des01.rx.own = 1;
374 p->des01.rx.buffer1_size = BUF_SIZE_2KiB - 1;
375 if (i == ring_size - 1)
376 p->des01.rx.end_ring = 1;
377 if (disable_rx_ic)
378 p->des01.rx.disable_ic = 1;
379 p++;
380 }
381 return;
382}
383
384static void mac100_init_tx_desc(struct dma_desc *p, unsigned int ring_size)
385{
386 int i;
387 for (i = 0; i < ring_size; i++) {
388 p->des01.tx.own = 0;
389 if (i == ring_size - 1)
390 p->des01.tx.end_ring = 1;
391 p++;
392 }
393 return;
394}
395
396static int mac100_get_tx_owner(struct dma_desc *p)
397{
398 return p->des01.tx.own;
399}
400
401static int mac100_get_rx_owner(struct dma_desc *p)
402{
403 return p->des01.rx.own;
404}
405
406static void mac100_set_tx_owner(struct dma_desc *p)
407{
408 p->des01.tx.own = 1;
409}
410
411static void mac100_set_rx_owner(struct dma_desc *p)
412{
413 p->des01.rx.own = 1;
414}
415
416static int mac100_get_tx_ls(struct dma_desc *p)
417{
418 return p->des01.tx.last_segment;
419}
420
421static void mac100_release_tx_desc(struct dma_desc *p)
422{
423 int ter = p->des01.tx.end_ring;
424
425 /* clean field used within the xmit */
426 p->des01.tx.first_segment = 0;
427 p->des01.tx.last_segment = 0;
428 p->des01.tx.buffer1_size = 0;
429
430 /* clean status reported */
431 p->des01.tx.error_summary = 0;
432 p->des01.tx.underflow_error = 0;
433 p->des01.tx.no_carrier = 0;
434 p->des01.tx.loss_carrier = 0;
435 p->des01.tx.excessive_deferral = 0;
436 p->des01.tx.excessive_collisions = 0;
437 p->des01.tx.late_collision = 0;
438 p->des01.tx.heartbeat_fail = 0;
439 p->des01.tx.deferred = 0;
440
441 /* set termination field */
442 p->des01.tx.end_ring = ter;
443
444 return;
445}
446
447static void mac100_prepare_tx_desc(struct dma_desc *p, int is_fs, int len,
448 int csum_flag)
449{
450 p->des01.tx.first_segment = is_fs;
451 p->des01.tx.buffer1_size = len;
452}
453
454static void mac100_clear_tx_ic(struct dma_desc *p)
455{
456 p->des01.tx.interrupt = 0;
457}
458
459static void mac100_close_tx_desc(struct dma_desc *p)
460{
461 p->des01.tx.last_segment = 1;
462 p->des01.tx.interrupt = 1;
463}
464
465static int mac100_get_rx_frame_len(struct dma_desc *p)
466{
467 return p->des01.rx.frame_length;
468}
469
470struct stmmac_ops mac100_driver = {
471 .core_init = mac100_core_init,
472 .dump_mac_regs = mac100_dump_mac_regs,
473 .dma_init = mac100_dma_init,
474 .dump_dma_regs = mac100_dump_dma_regs,
475 .dma_mode = mac100_dma_operation_mode,
476 .dma_diagnostic_fr = mac100_dma_diagnostic_fr,
477 .tx_status = mac100_get_tx_frame_status,
478 .rx_status = mac100_get_rx_frame_status,
479 .get_tx_len = mac100_get_tx_len,
480 .set_filter = mac100_set_filter,
481 .flow_ctrl = mac100_flow_ctrl,
482 .pmt = mac100_pmt,
483 .init_rx_desc = mac100_init_rx_desc,
484 .init_tx_desc = mac100_init_tx_desc,
485 .get_tx_owner = mac100_get_tx_owner,
486 .get_rx_owner = mac100_get_rx_owner,
487 .release_tx_desc = mac100_release_tx_desc,
488 .prepare_tx_desc = mac100_prepare_tx_desc,
489 .clear_tx_ic = mac100_clear_tx_ic,
490 .close_tx_desc = mac100_close_tx_desc,
491 .get_tx_ls = mac100_get_tx_ls,
492 .set_tx_owner = mac100_set_tx_owner,
493 .set_rx_owner = mac100_set_rx_owner,
494 .get_rx_frame_len = mac100_get_rx_frame_len,
495 .host_irq_status = mac100_irq_status,
496 .set_umac_addr = mac100_set_umac_addr,
497 .get_umac_addr = mac100_get_umac_addr,
498};
499
500struct mac_device_info *mac100_setup(unsigned long ioaddr)
501{
502 struct mac_device_info *mac;
503
504 mac = kzalloc(sizeof(const struct mac_device_info), GFP_KERNEL);
505
506 pr_info("\tMAC 10/100\n");
507
508 mac->ops = &mac100_driver;
509 mac->hw.pmt = PMT_NOT_SUPPORTED;
510 mac->hw.link.port = MAC_CONTROL_PS;
511 mac->hw.link.duplex = MAC_CONTROL_F;
512 mac->hw.link.speed = 0;
513 mac->hw.mii.addr = MAC_MII_ADDR;
514 mac->hw.mii.data = MAC_MII_DATA;
515
516 return mac;
517}
diff --git a/drivers/net/stmmac/mac100.h b/drivers/net/stmmac/mac100.h
new file mode 100644
index 000000000000..0f8f110d004a
--- /dev/null
+++ b/drivers/net/stmmac/mac100.h
@@ -0,0 +1,116 @@
1/*******************************************************************************
2 MAC 10/100 Header File
3
4 Copyright (C) 2007-2009 STMicroelectronics Ltd
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23*******************************************************************************/
24
25/*----------------------------------------------------------------------------
26 * MAC BLOCK defines
27 *---------------------------------------------------------------------------*/
28/* MAC CSR offset */
29#define MAC_CONTROL 0x00000000 /* MAC Control */
30#define MAC_ADDR_HIGH 0x00000004 /* MAC Address High */
31#define MAC_ADDR_LOW 0x00000008 /* MAC Address Low */
32#define MAC_HASH_HIGH 0x0000000c /* Multicast Hash Table High */
33#define MAC_HASH_LOW 0x00000010 /* Multicast Hash Table Low */
34#define MAC_MII_ADDR 0x00000014 /* MII Address */
35#define MAC_MII_DATA 0x00000018 /* MII Data */
36#define MAC_FLOW_CTRL 0x0000001c /* Flow Control */
37#define MAC_VLAN1 0x00000020 /* VLAN1 Tag */
38#define MAC_VLAN2 0x00000024 /* VLAN2 Tag */
39
40/* MAC CTRL defines */
41#define MAC_CONTROL_RA 0x80000000 /* Receive All Mode */
42#define MAC_CONTROL_BLE 0x40000000 /* Endian Mode */
43#define MAC_CONTROL_HBD 0x10000000 /* Heartbeat Disable */
44#define MAC_CONTROL_PS 0x08000000 /* Port Select */
45#define MAC_CONTROL_DRO 0x00800000 /* Disable Receive Own */
46#define MAC_CONTROL_EXT_LOOPBACK 0x00400000 /* Reserved (ext loopback?) */
47#define MAC_CONTROL_OM 0x00200000 /* Loopback Operating Mode */
48#define MAC_CONTROL_F 0x00100000 /* Full Duplex Mode */
49#define MAC_CONTROL_PM 0x00080000 /* Pass All Multicast */
50#define MAC_CONTROL_PR 0x00040000 /* Promiscuous Mode */
51#define MAC_CONTROL_IF 0x00020000 /* Inverse Filtering */
52#define MAC_CONTROL_PB 0x00010000 /* Pass Bad Frames */
53#define MAC_CONTROL_HO 0x00008000 /* Hash Only Filtering Mode */
54#define MAC_CONTROL_HP 0x00002000 /* Hash/Perfect Filtering Mode */
55#define MAC_CONTROL_LCC 0x00001000 /* Late Collision Control */
56#define MAC_CONTROL_DBF 0x00000800 /* Disable Broadcast Frames */
57#define MAC_CONTROL_DRTY 0x00000400 /* Disable Retry */
58#define MAC_CONTROL_ASTP 0x00000100 /* Automatic Pad Stripping */
59#define MAC_CONTROL_BOLMT_10 0x00000000 /* Back Off Limit 10 */
60#define MAC_CONTROL_BOLMT_8 0x00000040 /* Back Off Limit 8 */
61#define MAC_CONTROL_BOLMT_4 0x00000080 /* Back Off Limit 4 */
62#define MAC_CONTROL_BOLMT_1 0x000000c0 /* Back Off Limit 1 */
63#define MAC_CONTROL_DC 0x00000020 /* Deferral Check */
64#define MAC_CONTROL_TE 0x00000008 /* Transmitter Enable */
65#define MAC_CONTROL_RE 0x00000004 /* Receiver Enable */
66
67#define MAC_CORE_INIT (MAC_CONTROL_HBD | MAC_CONTROL_ASTP)
68
69/* MAC FLOW CTRL defines */
70#define MAC_FLOW_CTRL_PT_MASK 0xffff0000 /* Pause Time Mask */
71#define MAC_FLOW_CTRL_PT_SHIFT 16
72#define MAC_FLOW_CTRL_PASS 0x00000004 /* Pass Control Frames */
73#define MAC_FLOW_CTRL_ENABLE 0x00000002 /* Flow Control Enable */
74#define MAC_FLOW_CTRL_PAUSE 0x00000001 /* Flow Control Busy ... */
75
76/* MII ADDR defines */
77#define MAC_MII_ADDR_WRITE 0x00000002 /* MII Write */
78#define MAC_MII_ADDR_BUSY 0x00000001 /* MII Busy */
79
80/*----------------------------------------------------------------------------
81 * DMA BLOCK defines
82 *---------------------------------------------------------------------------*/
83
84/* DMA Bus Mode register defines */
85#define DMA_BUS_MODE_DBO 0x00100000 /* Descriptor Byte Ordering */
86#define DMA_BUS_MODE_BLE 0x00000080 /* Big Endian/Little Endian */
87#define DMA_BUS_MODE_PBL_MASK 0x00003f00 /* Programmable Burst Len */
88#define DMA_BUS_MODE_PBL_SHIFT 8
89#define DMA_BUS_MODE_DSL_MASK 0x0000007c /* Descriptor Skip Length */
90#define DMA_BUS_MODE_DSL_SHIFT 2 /* (in DWORDS) */
91#define DMA_BUS_MODE_BAR_BUS 0x00000002 /* Bar-Bus Arbitration */
92#define DMA_BUS_MODE_SFT_RESET 0x00000001 /* Software Reset */
93#define DMA_BUS_MODE_DEFAULT 0x00000000
94
95/* DMA Control register defines */
96#define DMA_CONTROL_SF 0x00200000 /* Store And Forward */
97
98/* Transmit Threshold Control */
99enum ttc_control {
100 DMA_CONTROL_TTC_DEFAULT = 0x00000000, /* Threshold is 32 DWORDS */
101 DMA_CONTROL_TTC_64 = 0x00004000, /* Threshold is 64 DWORDS */
102 DMA_CONTROL_TTC_128 = 0x00008000, /* Threshold is 128 DWORDS */
103 DMA_CONTROL_TTC_256 = 0x0000c000, /* Threshold is 256 DWORDS */
104 DMA_CONTROL_TTC_18 = 0x00400000, /* Threshold is 18 DWORDS */
105 DMA_CONTROL_TTC_24 = 0x00404000, /* Threshold is 24 DWORDS */
106 DMA_CONTROL_TTC_32 = 0x00408000, /* Threshold is 32 DWORDS */
107 DMA_CONTROL_TTC_40 = 0x0040c000, /* Threshold is 40 DWORDS */
108 DMA_CONTROL_SE = 0x00000008, /* Stop On Empty */
109 DMA_CONTROL_OSF = 0x00000004, /* Operate On 2nd Frame */
110};
111
112/* STMAC110 DMA Missed Frame Counter register defines */
113#define DMA_MISSED_FRAME_OVE 0x10000000 /* FIFO Overflow Overflow */
114#define DMA_MISSED_FRAME_OVE_CNTR 0x0ffe0000 /* Overflow Frame Counter */
115#define DMA_MISSED_FRAME_OVE_M 0x00010000 /* Missed Frame Overflow */
116#define DMA_MISSED_FRAME_M_CNTR 0x0000ffff /* Missed Frame Couinter */
diff --git a/drivers/net/stmmac/stmmac.h b/drivers/net/stmmac/stmmac.h
new file mode 100644
index 000000000000..6d2eae3040e5
--- /dev/null
+++ b/drivers/net/stmmac/stmmac.h
@@ -0,0 +1,98 @@
1/*******************************************************************************
2 Copyright (C) 2007-2009 STMicroelectronics Ltd
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms and conditions of the GNU General Public License,
6 version 2, as published by the Free Software Foundation.
7
8 This program is distributed in the hope it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 more details.
12
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16
17 The full GNU General Public License is included in this distribution in
18 the file called "COPYING".
19
20 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
21*******************************************************************************/
22
23#define DRV_MODULE_VERSION "Oct_09"
24
25#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
26#define STMMAC_VLAN_TAG_USED
27#include <linux/if_vlan.h>
28#endif
29
30#include "common.h"
31#ifdef CONFIG_STMMAC_TIMER
32#include "stmmac_timer.h"
33#endif
34
35struct stmmac_priv {
36 /* Frequently used values are kept adjacent for cache effect */
37 struct dma_desc *dma_tx ____cacheline_aligned;
38 dma_addr_t dma_tx_phy;
39 struct sk_buff **tx_skbuff;
40 unsigned int cur_tx;
41 unsigned int dirty_tx;
42 unsigned int dma_tx_size;
43 int tx_coe;
44 int tx_coalesce;
45
46 struct dma_desc *dma_rx ;
47 unsigned int cur_rx;
48 unsigned int dirty_rx;
49 struct sk_buff **rx_skbuff;
50 dma_addr_t *rx_skbuff_dma;
51 struct sk_buff_head rx_recycle;
52
53 struct net_device *dev;
54 int is_gmac;
55 dma_addr_t dma_rx_phy;
56 unsigned int dma_rx_size;
57 int rx_csum;
58 unsigned int dma_buf_sz;
59 struct device *device;
60 struct mac_device_info *mac_type;
61
62 struct stmmac_extra_stats xstats;
63 struct napi_struct napi;
64
65 phy_interface_t phy_interface;
66 int pbl;
67 int bus_id;
68 int phy_addr;
69 int phy_mask;
70 int (*phy_reset) (void *priv);
71 void (*fix_mac_speed) (void *priv, unsigned int speed);
72 void *bsp_priv;
73
74 int phy_irq;
75 struct phy_device *phydev;
76 int oldlink;
77 int speed;
78 int oldduplex;
79 unsigned int flow_ctrl;
80 unsigned int pause;
81 struct mii_bus *mii;
82
83 u32 msg_enable;
84 spinlock_t lock;
85 int wolopts;
86 int wolenabled;
87 int shutdown;
88#ifdef CONFIG_STMMAC_TIMER
89 struct stmmac_timer *tm;
90#endif
91#ifdef STMMAC_VLAN_TAG_USED
92 struct vlan_group *vlgrp;
93#endif
94};
95
96extern int stmmac_mdio_unregister(struct net_device *ndev);
97extern int stmmac_mdio_register(struct net_device *ndev);
98extern void stmmac_set_ethtool_ops(struct net_device *netdev);
diff --git a/drivers/net/stmmac/stmmac_ethtool.c b/drivers/net/stmmac/stmmac_ethtool.c
new file mode 100644
index 000000000000..694ebe6a0758
--- /dev/null
+++ b/drivers/net/stmmac/stmmac_ethtool.c
@@ -0,0 +1,395 @@
1/*******************************************************************************
2 STMMAC Ethtool support
3
4 Copyright (C) 2007-2009 STMicroelectronics Ltd
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23*******************************************************************************/
24
25#include <linux/etherdevice.h>
26#include <linux/ethtool.h>
27#include <linux/mii.h>
28#include <linux/phy.h>
29
30#include "stmmac.h"
31
32#define REG_SPACE_SIZE 0x1054
33#define MAC100_ETHTOOL_NAME "st_mac100"
34#define GMAC_ETHTOOL_NAME "st_gmac"
35
36struct stmmac_stats {
37 char stat_string[ETH_GSTRING_LEN];
38 int sizeof_stat;
39 int stat_offset;
40};
41
42#define STMMAC_STAT(m) \
43 { #m, FIELD_SIZEOF(struct stmmac_extra_stats, m), \
44 offsetof(struct stmmac_priv, xstats.m)}
45
46static const struct stmmac_stats stmmac_gstrings_stats[] = {
47 STMMAC_STAT(tx_underflow),
48 STMMAC_STAT(tx_carrier),
49 STMMAC_STAT(tx_losscarrier),
50 STMMAC_STAT(tx_heartbeat),
51 STMMAC_STAT(tx_deferred),
52 STMMAC_STAT(tx_vlan),
53 STMMAC_STAT(rx_vlan),
54 STMMAC_STAT(tx_jabber),
55 STMMAC_STAT(tx_frame_flushed),
56 STMMAC_STAT(tx_payload_error),
57 STMMAC_STAT(tx_ip_header_error),
58 STMMAC_STAT(rx_desc),
59 STMMAC_STAT(rx_partial),
60 STMMAC_STAT(rx_runt),
61 STMMAC_STAT(rx_toolong),
62 STMMAC_STAT(rx_collision),
63 STMMAC_STAT(rx_crc),
64 STMMAC_STAT(rx_lenght),
65 STMMAC_STAT(rx_mii),
66 STMMAC_STAT(rx_multicast),
67 STMMAC_STAT(rx_gmac_overflow),
68 STMMAC_STAT(rx_watchdog),
69 STMMAC_STAT(da_rx_filter_fail),
70 STMMAC_STAT(sa_rx_filter_fail),
71 STMMAC_STAT(rx_missed_cntr),
72 STMMAC_STAT(rx_overflow_cntr),
73 STMMAC_STAT(tx_undeflow_irq),
74 STMMAC_STAT(tx_process_stopped_irq),
75 STMMAC_STAT(tx_jabber_irq),
76 STMMAC_STAT(rx_overflow_irq),
77 STMMAC_STAT(rx_buf_unav_irq),
78 STMMAC_STAT(rx_process_stopped_irq),
79 STMMAC_STAT(rx_watchdog_irq),
80 STMMAC_STAT(tx_early_irq),
81 STMMAC_STAT(fatal_bus_error_irq),
82 STMMAC_STAT(threshold),
83 STMMAC_STAT(tx_pkt_n),
84 STMMAC_STAT(rx_pkt_n),
85 STMMAC_STAT(poll_n),
86 STMMAC_STAT(sched_timer_n),
87 STMMAC_STAT(normal_irq_n),
88};
89#define STMMAC_STATS_LEN ARRAY_SIZE(stmmac_gstrings_stats)
90
91void stmmac_ethtool_getdrvinfo(struct net_device *dev,
92 struct ethtool_drvinfo *info)
93{
94 struct stmmac_priv *priv = netdev_priv(dev);
95
96 if (!priv->is_gmac)
97 strcpy(info->driver, MAC100_ETHTOOL_NAME);
98 else
99 strcpy(info->driver, GMAC_ETHTOOL_NAME);
100
101 strcpy(info->version, DRV_MODULE_VERSION);
102 info->fw_version[0] = '\0';
103 info->n_stats = STMMAC_STATS_LEN;
104 return;
105}
106
107int stmmac_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
108{
109 struct stmmac_priv *priv = netdev_priv(dev);
110 struct phy_device *phy = priv->phydev;
111 int rc;
112 if (phy == NULL) {
113 pr_err("%s: %s: PHY is not registered\n",
114 __func__, dev->name);
115 return -ENODEV;
116 }
117 if (!netif_running(dev)) {
118 pr_err("%s: interface is disabled: we cannot track "
119 "link speed / duplex setting\n", dev->name);
120 return -EBUSY;
121 }
122 cmd->transceiver = XCVR_INTERNAL;
123 spin_lock_irq(&priv->lock);
124 rc = phy_ethtool_gset(phy, cmd);
125 spin_unlock_irq(&priv->lock);
126 return rc;
127}
128
129int stmmac_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd)
130{
131 struct stmmac_priv *priv = netdev_priv(dev);
132 struct phy_device *phy = priv->phydev;
133 int rc;
134
135 spin_lock(&priv->lock);
136 rc = phy_ethtool_sset(phy, cmd);
137 spin_unlock(&priv->lock);
138
139 return rc;
140}
141
142u32 stmmac_ethtool_getmsglevel(struct net_device *dev)
143{
144 struct stmmac_priv *priv = netdev_priv(dev);
145 return priv->msg_enable;
146}
147
148void stmmac_ethtool_setmsglevel(struct net_device *dev, u32 level)
149{
150 struct stmmac_priv *priv = netdev_priv(dev);
151 priv->msg_enable = level;
152
153}
154
155int stmmac_check_if_running(struct net_device *dev)
156{
157 if (!netif_running(dev))
158 return -EBUSY;
159 return 0;
160}
161
162int stmmac_ethtool_get_regs_len(struct net_device *dev)
163{
164 return REG_SPACE_SIZE;
165}
166
167void stmmac_ethtool_gregs(struct net_device *dev,
168 struct ethtool_regs *regs, void *space)
169{
170 int i;
171 u32 *reg_space = (u32 *) space;
172
173 struct stmmac_priv *priv = netdev_priv(dev);
174
175 memset(reg_space, 0x0, REG_SPACE_SIZE);
176
177 if (!priv->is_gmac) {
178 /* MAC registers */
179 for (i = 0; i < 12; i++)
180 reg_space[i] = readl(dev->base_addr + (i * 4));
181 /* DMA registers */
182 for (i = 0; i < 9; i++)
183 reg_space[i + 12] =
184 readl(dev->base_addr + (DMA_BUS_MODE + (i * 4)));
185 reg_space[22] = readl(dev->base_addr + DMA_CUR_TX_BUF_ADDR);
186 reg_space[23] = readl(dev->base_addr + DMA_CUR_RX_BUF_ADDR);
187 } else {
188 /* MAC registers */
189 for (i = 0; i < 55; i++)
190 reg_space[i] = readl(dev->base_addr + (i * 4));
191 /* DMA registers */
192 for (i = 0; i < 22; i++)
193 reg_space[i + 55] =
194 readl(dev->base_addr + (DMA_BUS_MODE + (i * 4)));
195 }
196
197 return;
198}
199
200int stmmac_ethtool_set_tx_csum(struct net_device *netdev, u32 data)
201{
202 if (data)
203 netdev->features |= NETIF_F_HW_CSUM;
204 else
205 netdev->features &= ~NETIF_F_HW_CSUM;
206
207 return 0;
208}
209
210u32 stmmac_ethtool_get_rx_csum(struct net_device *dev)
211{
212 struct stmmac_priv *priv = netdev_priv(dev);
213
214 return priv->rx_csum;
215}
216
217static void
218stmmac_get_pauseparam(struct net_device *netdev,
219 struct ethtool_pauseparam *pause)
220{
221 struct stmmac_priv *priv = netdev_priv(netdev);
222
223 spin_lock(&priv->lock);
224
225 pause->rx_pause = 0;
226 pause->tx_pause = 0;
227 pause->autoneg = priv->phydev->autoneg;
228
229 if (priv->flow_ctrl & FLOW_RX)
230 pause->rx_pause = 1;
231 if (priv->flow_ctrl & FLOW_TX)
232 pause->tx_pause = 1;
233
234 spin_unlock(&priv->lock);
235 return;
236}
237
238static int
239stmmac_set_pauseparam(struct net_device *netdev,
240 struct ethtool_pauseparam *pause)
241{
242 struct stmmac_priv *priv = netdev_priv(netdev);
243 struct phy_device *phy = priv->phydev;
244 int new_pause = FLOW_OFF;
245 int ret = 0;
246
247 spin_lock(&priv->lock);
248
249 if (pause->rx_pause)
250 new_pause |= FLOW_RX;
251 if (pause->tx_pause)
252 new_pause |= FLOW_TX;
253
254 priv->flow_ctrl = new_pause;
255
256 if (phy->autoneg) {
257 if (netif_running(netdev)) {
258 struct ethtool_cmd cmd;
259 /* auto-negotiation automatically restarted */
260 cmd.cmd = ETHTOOL_NWAY_RST;
261 cmd.supported = phy->supported;
262 cmd.advertising = phy->advertising;
263 cmd.autoneg = phy->autoneg;
264 cmd.speed = phy->speed;
265 cmd.duplex = phy->duplex;
266 cmd.phy_address = phy->addr;
267 ret = phy_ethtool_sset(phy, &cmd);
268 }
269 } else {
270 unsigned long ioaddr = netdev->base_addr;
271 priv->mac_type->ops->flow_ctrl(ioaddr, phy->duplex,
272 priv->flow_ctrl, priv->pause);
273 }
274 spin_unlock(&priv->lock);
275 return ret;
276}
277
278static void stmmac_get_ethtool_stats(struct net_device *dev,
279 struct ethtool_stats *dummy, u64 *data)
280{
281 struct stmmac_priv *priv = netdev_priv(dev);
282 unsigned long ioaddr = dev->base_addr;
283 int i;
284
285 /* Update HW stats if supported */
286 priv->mac_type->ops->dma_diagnostic_fr(&dev->stats, &priv->xstats,
287 ioaddr);
288
289 for (i = 0; i < STMMAC_STATS_LEN; i++) {
290 char *p = (char *)priv + stmmac_gstrings_stats[i].stat_offset;
291 data[i] = (stmmac_gstrings_stats[i].sizeof_stat ==
292 sizeof(u64)) ? (*(u64 *)p) : (*(u32 *)p);
293 }
294
295 return;
296}
297
298static int stmmac_get_sset_count(struct net_device *netdev, int sset)
299{
300 switch (sset) {
301 case ETH_SS_STATS:
302 return STMMAC_STATS_LEN;
303 default:
304 return -EOPNOTSUPP;
305 }
306}
307
308static void stmmac_get_strings(struct net_device *dev, u32 stringset, u8 *data)
309{
310 int i;
311 u8 *p = data;
312
313 switch (stringset) {
314 case ETH_SS_STATS:
315 for (i = 0; i < STMMAC_STATS_LEN; i++) {
316 memcpy(p, stmmac_gstrings_stats[i].stat_string,
317 ETH_GSTRING_LEN);
318 p += ETH_GSTRING_LEN;
319 }
320 break;
321 default:
322 WARN_ON(1);
323 break;
324 }
325 return;
326}
327
328/* Currently only support WOL through Magic packet. */
329static void stmmac_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
330{
331 struct stmmac_priv *priv = netdev_priv(dev);
332
333 spin_lock_irq(&priv->lock);
334 if (priv->wolenabled == PMT_SUPPORTED) {
335 wol->supported = WAKE_MAGIC;
336 wol->wolopts = priv->wolopts;
337 }
338 spin_unlock_irq(&priv->lock);
339}
340
341static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
342{
343 struct stmmac_priv *priv = netdev_priv(dev);
344 u32 support = WAKE_MAGIC;
345
346 if (priv->wolenabled == PMT_NOT_SUPPORTED)
347 return -EINVAL;
348
349 if (wol->wolopts & ~support)
350 return -EINVAL;
351
352 if (wol->wolopts == 0)
353 device_set_wakeup_enable(priv->device, 0);
354 else
355 device_set_wakeup_enable(priv->device, 1);
356
357 spin_lock_irq(&priv->lock);
358 priv->wolopts = wol->wolopts;
359 spin_unlock_irq(&priv->lock);
360
361 return 0;
362}
363
364static struct ethtool_ops stmmac_ethtool_ops = {
365 .begin = stmmac_check_if_running,
366 .get_drvinfo = stmmac_ethtool_getdrvinfo,
367 .get_settings = stmmac_ethtool_getsettings,
368 .set_settings = stmmac_ethtool_setsettings,
369 .get_msglevel = stmmac_ethtool_getmsglevel,
370 .set_msglevel = stmmac_ethtool_setmsglevel,
371 .get_regs = stmmac_ethtool_gregs,
372 .get_regs_len = stmmac_ethtool_get_regs_len,
373 .get_link = ethtool_op_get_link,
374 .get_rx_csum = stmmac_ethtool_get_rx_csum,
375 .get_tx_csum = ethtool_op_get_tx_csum,
376 .set_tx_csum = stmmac_ethtool_set_tx_csum,
377 .get_sg = ethtool_op_get_sg,
378 .set_sg = ethtool_op_set_sg,
379 .get_pauseparam = stmmac_get_pauseparam,
380 .set_pauseparam = stmmac_set_pauseparam,
381 .get_ethtool_stats = stmmac_get_ethtool_stats,
382 .get_strings = stmmac_get_strings,
383 .get_wol = stmmac_get_wol,
384 .set_wol = stmmac_set_wol,
385 .get_sset_count = stmmac_get_sset_count,
386#ifdef NETIF_F_TSO
387 .get_tso = ethtool_op_get_tso,
388 .set_tso = ethtool_op_set_tso,
389#endif
390};
391
392void stmmac_set_ethtool_ops(struct net_device *netdev)
393{
394 SET_ETHTOOL_OPS(netdev, &stmmac_ethtool_ops);
395}
diff --git a/drivers/net/stmmac/stmmac_main.c b/drivers/net/stmmac/stmmac_main.c
new file mode 100644
index 000000000000..9542995ba667
--- /dev/null
+++ b/drivers/net/stmmac/stmmac_main.c
@@ -0,0 +1,2210 @@
1/*******************************************************************************
2 This is the driver for the ST MAC 10/100/1000 on-chip Ethernet controllers.
3 ST Ethernet IPs are built around a Synopsys IP Core.
4
5 Copyright (C) 2007-2009 STMicroelectronics Ltd
6
7 This program is free software; you can redistribute it and/or modify it
8 under the terms and conditions of the GNU General Public License,
9 version 2, as published by the Free Software Foundation.
10
11 This program is distributed in the hope it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19
20 The full GNU General Public License is included in this distribution in
21 the file called "COPYING".
22
23 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
24
25 Documentation available at:
26 http://www.stlinux.com
27 Support available at:
28 https://bugzilla.stlinux.com/
29*******************************************************************************/
30
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/kernel.h>
34#include <linux/interrupt.h>
35#include <linux/netdevice.h>
36#include <linux/etherdevice.h>
37#include <linux/platform_device.h>
38#include <linux/ip.h>
39#include <linux/tcp.h>
40#include <linux/skbuff.h>
41#include <linux/ethtool.h>
42#include <linux/if_ether.h>
43#include <linux/crc32.h>
44#include <linux/mii.h>
45#include <linux/phy.h>
46#include <linux/if_vlan.h>
47#include <linux/dma-mapping.h>
48#include <linux/stm/soc.h>
49#include "stmmac.h"
50
51#define STMMAC_RESOURCE_NAME "stmmaceth"
52#define PHY_RESOURCE_NAME "stmmacphy"
53
54#undef STMMAC_DEBUG
55/*#define STMMAC_DEBUG*/
56#ifdef STMMAC_DEBUG
57#define DBG(nlevel, klevel, fmt, args...) \
58 ((void)(netif_msg_##nlevel(priv) && \
59 printk(KERN_##klevel fmt, ## args)))
60#else
61#define DBG(nlevel, klevel, fmt, args...) do { } while (0)
62#endif
63
64#undef STMMAC_RX_DEBUG
65/*#define STMMAC_RX_DEBUG*/
66#ifdef STMMAC_RX_DEBUG
67#define RX_DBG(fmt, args...) printk(fmt, ## args)
68#else
69#define RX_DBG(fmt, args...) do { } while (0)
70#endif
71
72#undef STMMAC_XMIT_DEBUG
73/*#define STMMAC_XMIT_DEBUG*/
74#ifdef STMMAC_TX_DEBUG
75#define TX_DBG(fmt, args...) printk(fmt, ## args)
76#else
77#define TX_DBG(fmt, args...) do { } while (0)
78#endif
79
80#define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x)
81#define JUMBO_LEN 9000
82
83/* Module parameters */
84#define TX_TIMEO 5000 /* default 5 seconds */
85static int watchdog = TX_TIMEO;
86module_param(watchdog, int, S_IRUGO | S_IWUSR);
87MODULE_PARM_DESC(watchdog, "Transmit timeout in milliseconds");
88
89static int debug = -1; /* -1: default, 0: no output, 16: all */
90module_param(debug, int, S_IRUGO | S_IWUSR);
91MODULE_PARM_DESC(debug, "Message Level (0: no output, 16: all)");
92
93static int phyaddr = -1;
94module_param(phyaddr, int, S_IRUGO);
95MODULE_PARM_DESC(phyaddr, "Physical device address");
96
97#define DMA_TX_SIZE 256
98static int dma_txsize = DMA_TX_SIZE;
99module_param(dma_txsize, int, S_IRUGO | S_IWUSR);
100MODULE_PARM_DESC(dma_txsize, "Number of descriptors in the TX list");
101
102#define DMA_RX_SIZE 256
103static int dma_rxsize = DMA_RX_SIZE;
104module_param(dma_rxsize, int, S_IRUGO | S_IWUSR);
105MODULE_PARM_DESC(dma_rxsize, "Number of descriptors in the RX list");
106
107static int flow_ctrl = FLOW_OFF;
108module_param(flow_ctrl, int, S_IRUGO | S_IWUSR);
109MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]");
110
111static int pause = PAUSE_TIME;
112module_param(pause, int, S_IRUGO | S_IWUSR);
113MODULE_PARM_DESC(pause, "Flow Control Pause Time");
114
115#define TC_DEFAULT 64
116static int tc = TC_DEFAULT;
117module_param(tc, int, S_IRUGO | S_IWUSR);
118MODULE_PARM_DESC(tc, "DMA threshold control value");
119
120#define RX_NO_COALESCE 1 /* Always interrupt on completion */
121#define TX_NO_COALESCE -1 /* No moderation by default */
122
123/* Pay attention to tune this parameter; take care of both
124 * hardware capability and network stabitily/performance impact.
125 * Many tests showed that ~4ms latency seems to be good enough. */
126#ifdef CONFIG_STMMAC_TIMER
127#define DEFAULT_PERIODIC_RATE 256
128static int tmrate = DEFAULT_PERIODIC_RATE;
129module_param(tmrate, int, S_IRUGO | S_IWUSR);
130MODULE_PARM_DESC(tmrate, "External timer freq. (default: 256Hz)");
131#endif
132
133#define DMA_BUFFER_SIZE BUF_SIZE_2KiB
134static int buf_sz = DMA_BUFFER_SIZE;
135module_param(buf_sz, int, S_IRUGO | S_IWUSR);
136MODULE_PARM_DESC(buf_sz, "DMA buffer size");
137
138/* In case of Giga ETH, we can enable/disable the COE for the
139 * transmit HW checksum computation.
140 * Note that, if tx csum is off in HW, SG will be still supported. */
141static int tx_coe = HW_CSUM;
142module_param(tx_coe, int, S_IRUGO | S_IWUSR);
143MODULE_PARM_DESC(tx_coe, "GMAC COE type 2 [on/off]");
144
145static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
146 NETIF_MSG_LINK | NETIF_MSG_IFUP |
147 NETIF_MSG_IFDOWN | NETIF_MSG_TIMER);
148
149static irqreturn_t stmmac_interrupt(int irq, void *dev_id);
150static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev);
151
152/**
153 * stmmac_verify_args - verify the driver parameters.
154 * Description: it verifies if some wrong parameter is passed to the driver.
155 * Note that wrong parameters are replaced with the default values.
156 */
157static void stmmac_verify_args(void)
158{
159 if (unlikely(watchdog < 0))
160 watchdog = TX_TIMEO;
161 if (unlikely(dma_rxsize < 0))
162 dma_rxsize = DMA_RX_SIZE;
163 if (unlikely(dma_txsize < 0))
164 dma_txsize = DMA_TX_SIZE;
165 if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB)))
166 buf_sz = DMA_BUFFER_SIZE;
167 if (unlikely(flow_ctrl > 1))
168 flow_ctrl = FLOW_AUTO;
169 else if (likely(flow_ctrl < 0))
170 flow_ctrl = FLOW_OFF;
171 if (unlikely((pause < 0) || (pause > 0xffff)))
172 pause = PAUSE_TIME;
173
174 return;
175}
176
177#if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
178static void print_pkt(unsigned char *buf, int len)
179{
180 int j;
181 pr_info("len = %d byte, buf addr: 0x%p", len, buf);
182 for (j = 0; j < len; j++) {
183 if ((j % 16) == 0)
184 pr_info("\n %03x:", j);
185 pr_info(" %02x", buf[j]);
186 }
187 pr_info("\n");
188 return;
189}
190#endif
191
192/* minimum number of free TX descriptors required to wake up TX process */
193#define STMMAC_TX_THRESH(x) (x->dma_tx_size/4)
194
195static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
196{
197 return priv->dirty_tx + priv->dma_tx_size - priv->cur_tx - 1;
198}
199
200/**
201 * stmmac_adjust_link
202 * @dev: net device structure
203 * Description: it adjusts the link parameters.
204 */
205static void stmmac_adjust_link(struct net_device *dev)
206{
207 struct stmmac_priv *priv = netdev_priv(dev);
208 struct phy_device *phydev = priv->phydev;
209 unsigned long ioaddr = dev->base_addr;
210 unsigned long flags;
211 int new_state = 0;
212 unsigned int fc = priv->flow_ctrl, pause_time = priv->pause;
213
214 if (phydev == NULL)
215 return;
216
217 DBG(probe, DEBUG, "stmmac_adjust_link: called. address %d link %d\n",
218 phydev->addr, phydev->link);
219
220 spin_lock_irqsave(&priv->lock, flags);
221 if (phydev->link) {
222 u32 ctrl = readl(ioaddr + MAC_CTRL_REG);
223
224 /* Now we make sure that we can be in full duplex mode.
225 * If not, we operate in half-duplex mode. */
226 if (phydev->duplex != priv->oldduplex) {
227 new_state = 1;
228 if (!(phydev->duplex))
229 ctrl &= ~priv->mac_type->hw.link.duplex;
230 else
231 ctrl |= priv->mac_type->hw.link.duplex;
232 priv->oldduplex = phydev->duplex;
233 }
234 /* Flow Control operation */
235 if (phydev->pause)
236 priv->mac_type->ops->flow_ctrl(ioaddr, phydev->duplex,
237 fc, pause_time);
238
239 if (phydev->speed != priv->speed) {
240 new_state = 1;
241 switch (phydev->speed) {
242 case 1000:
243 if (likely(priv->is_gmac))
244 ctrl &= ~priv->mac_type->hw.link.port;
245 break;
246 case 100:
247 case 10:
248 if (priv->is_gmac) {
249 ctrl |= priv->mac_type->hw.link.port;
250 if (phydev->speed == SPEED_100) {
251 ctrl |=
252 priv->mac_type->hw.link.
253 speed;
254 } else {
255 ctrl &=
256 ~(priv->mac_type->hw.
257 link.speed);
258 }
259 } else {
260 ctrl &= ~priv->mac_type->hw.link.port;
261 }
262 priv->fix_mac_speed(priv->bsp_priv,
263 phydev->speed);
264 break;
265 default:
266 if (netif_msg_link(priv))
267 pr_warning("%s: Speed (%d) is not 10"
268 " or 100!\n", dev->name, phydev->speed);
269 break;
270 }
271
272 priv->speed = phydev->speed;
273 }
274
275 writel(ctrl, ioaddr + MAC_CTRL_REG);
276
277 if (!priv->oldlink) {
278 new_state = 1;
279 priv->oldlink = 1;
280 }
281 } else if (priv->oldlink) {
282 new_state = 1;
283 priv->oldlink = 0;
284 priv->speed = 0;
285 priv->oldduplex = -1;
286 }
287
288 if (new_state && netif_msg_link(priv))
289 phy_print_status(phydev);
290
291 spin_unlock_irqrestore(&priv->lock, flags);
292
293 DBG(probe, DEBUG, "stmmac_adjust_link: exiting\n");
294}
295
296/**
297 * stmmac_init_phy - PHY initialization
298 * @dev: net device structure
299 * Description: it initializes the driver's PHY state, and attaches the PHY
300 * to the mac driver.
301 * Return value:
302 * 0 on success
303 */
304static int stmmac_init_phy(struct net_device *dev)
305{
306 struct stmmac_priv *priv = netdev_priv(dev);
307 struct phy_device *phydev;
308 char phy_id[BUS_ID_SIZE]; /* PHY to connect */
309 char bus_id[BUS_ID_SIZE];
310
311 priv->oldlink = 0;
312 priv->speed = 0;
313 priv->oldduplex = -1;
314
315 if (priv->phy_addr == -1) {
316 /* We don't have a PHY, so do nothing */
317 return 0;
318 }
319
320 snprintf(bus_id, MII_BUS_ID_SIZE, "%x", priv->bus_id);
321 snprintf(phy_id, BUS_ID_SIZE, PHY_ID_FMT, bus_id, priv->phy_addr);
322 pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id);
323
324 phydev = phy_connect(dev, phy_id, &stmmac_adjust_link, 0,
325 priv->phy_interface);
326
327 if (IS_ERR(phydev)) {
328 pr_err("%s: Could not attach to PHY\n", dev->name);
329 return PTR_ERR(phydev);
330 }
331
332 /*
333 * Broken HW is sometimes missing the pull-up resistor on the
334 * MDIO line, which results in reads to non-existent devices returning
335 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
336 * device as well.
337 * Note: phydev->phy_id is the result of reading the UID PHY registers.
338 */
339 if (phydev->phy_id == 0) {
340 phy_disconnect(phydev);
341 return -ENODEV;
342 }
343 pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)"
344 " Link = %d\n", dev->name, phydev->phy_id, phydev->link);
345
346 priv->phydev = phydev;
347
348 return 0;
349}
350
351static inline void stmmac_mac_enable_rx(unsigned long ioaddr)
352{
353 u32 value = readl(ioaddr + MAC_CTRL_REG);
354 value |= MAC_RNABLE_RX;
355 /* Set the RE (receive enable bit into the MAC CTRL register). */
356 writel(value, ioaddr + MAC_CTRL_REG);
357}
358
359static inline void stmmac_mac_enable_tx(unsigned long ioaddr)
360{
361 u32 value = readl(ioaddr + MAC_CTRL_REG);
362 value |= MAC_ENABLE_TX;
363 /* Set the TE (transmit enable bit into the MAC CTRL register). */
364 writel(value, ioaddr + MAC_CTRL_REG);
365}
366
367static inline void stmmac_mac_disable_rx(unsigned long ioaddr)
368{
369 u32 value = readl(ioaddr + MAC_CTRL_REG);
370 value &= ~MAC_RNABLE_RX;
371 writel(value, ioaddr + MAC_CTRL_REG);
372}
373
374static inline void stmmac_mac_disable_tx(unsigned long ioaddr)
375{
376 u32 value = readl(ioaddr + MAC_CTRL_REG);
377 value &= ~MAC_ENABLE_TX;
378 writel(value, ioaddr + MAC_CTRL_REG);
379}
380
381/**
382 * display_ring
383 * @p: pointer to the ring.
384 * @size: size of the ring.
385 * Description: display all the descriptors within the ring.
386 */
387static void display_ring(struct dma_desc *p, int size)
388{
389 struct tmp_s {
390 u64 a;
391 unsigned int b;
392 unsigned int c;
393 };
394 int i;
395 for (i = 0; i < size; i++) {
396 struct tmp_s *x = (struct tmp_s *)(p + i);
397 pr_info("\t%d [0x%x]: DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
398 i, (unsigned int)virt_to_phys(&p[i]),
399 (unsigned int)(x->a), (unsigned int)((x->a) >> 32),
400 x->b, x->c);
401 pr_info("\n");
402 }
403}
404
405/**
406 * init_dma_desc_rings - init the RX/TX descriptor rings
407 * @dev: net device structure
408 * Description: this function initializes the DMA RX/TX descriptors
409 * and allocates the socket buffers.
410 */
411static void init_dma_desc_rings(struct net_device *dev)
412{
413 int i;
414 struct stmmac_priv *priv = netdev_priv(dev);
415 struct sk_buff *skb;
416 unsigned int txsize = priv->dma_tx_size;
417 unsigned int rxsize = priv->dma_rx_size;
418 unsigned int bfsize = priv->dma_buf_sz;
419 int buff2_needed = 0, dis_ic = 0;
420
421 /* Set the Buffer size according to the MTU;
422 * indeed, in case of jumbo we need to bump-up the buffer sizes.
423 */
424 if (unlikely(dev->mtu >= BUF_SIZE_8KiB))
425 bfsize = BUF_SIZE_16KiB;
426 else if (unlikely(dev->mtu >= BUF_SIZE_4KiB))
427 bfsize = BUF_SIZE_8KiB;
428 else if (unlikely(dev->mtu >= BUF_SIZE_2KiB))
429 bfsize = BUF_SIZE_4KiB;
430 else if (unlikely(dev->mtu >= DMA_BUFFER_SIZE))
431 bfsize = BUF_SIZE_2KiB;
432 else
433 bfsize = DMA_BUFFER_SIZE;
434
435#ifdef CONFIG_STMMAC_TIMER
436 /* Disable interrupts on completion for the reception if timer is on */
437 if (likely(priv->tm->enable))
438 dis_ic = 1;
439#endif
440 /* If the MTU exceeds 8k so use the second buffer in the chain */
441 if (bfsize >= BUF_SIZE_8KiB)
442 buff2_needed = 1;
443
444 DBG(probe, INFO, "stmmac: txsize %d, rxsize %d, bfsize %d\n",
445 txsize, rxsize, bfsize);
446
447 priv->rx_skbuff_dma = kmalloc(rxsize * sizeof(dma_addr_t), GFP_KERNEL);
448 priv->rx_skbuff =
449 kmalloc(sizeof(struct sk_buff *) * rxsize, GFP_KERNEL);
450 priv->dma_rx =
451 (struct dma_desc *)dma_alloc_coherent(priv->device,
452 rxsize *
453 sizeof(struct dma_desc),
454 &priv->dma_rx_phy,
455 GFP_KERNEL);
456 priv->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * txsize,
457 GFP_KERNEL);
458 priv->dma_tx =
459 (struct dma_desc *)dma_alloc_coherent(priv->device,
460 txsize *
461 sizeof(struct dma_desc),
462 &priv->dma_tx_phy,
463 GFP_KERNEL);
464
465 if ((priv->dma_rx == NULL) || (priv->dma_tx == NULL)) {
466 pr_err("%s:ERROR allocating the DMA Tx/Rx desc\n", __func__);
467 return;
468 }
469
470 DBG(probe, INFO, "stmmac (%s) DMA desc rings: virt addr (Rx %p, "
471 "Tx %p)\n\tDMA phy addr (Rx 0x%08x, Tx 0x%08x)\n",
472 dev->name, priv->dma_rx, priv->dma_tx,
473 (unsigned int)priv->dma_rx_phy, (unsigned int)priv->dma_tx_phy);
474
475 /* RX INITIALIZATION */
476 DBG(probe, INFO, "stmmac: SKB addresses:\n"
477 "skb\t\tskb data\tdma data\n");
478
479 for (i = 0; i < rxsize; i++) {
480 struct dma_desc *p = priv->dma_rx + i;
481
482 skb = netdev_alloc_skb_ip_align(dev, bfsize);
483 if (unlikely(skb == NULL)) {
484 pr_err("%s: Rx init fails; skb is NULL\n", __func__);
485 break;
486 }
487 priv->rx_skbuff[i] = skb;
488 priv->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data,
489 bfsize, DMA_FROM_DEVICE);
490
491 p->des2 = priv->rx_skbuff_dma[i];
492 if (unlikely(buff2_needed))
493 p->des3 = p->des2 + BUF_SIZE_8KiB;
494 DBG(probe, INFO, "[%p]\t[%p]\t[%x]\n", priv->rx_skbuff[i],
495 priv->rx_skbuff[i]->data, priv->rx_skbuff_dma[i]);
496 }
497 priv->cur_rx = 0;
498 priv->dirty_rx = (unsigned int)(i - rxsize);
499 priv->dma_buf_sz = bfsize;
500 buf_sz = bfsize;
501
502 /* TX INITIALIZATION */
503 for (i = 0; i < txsize; i++) {
504 priv->tx_skbuff[i] = NULL;
505 priv->dma_tx[i].des2 = 0;
506 }
507 priv->dirty_tx = 0;
508 priv->cur_tx = 0;
509
510 /* Clear the Rx/Tx descriptors */
511 priv->mac_type->ops->init_rx_desc(priv->dma_rx, rxsize, dis_ic);
512 priv->mac_type->ops->init_tx_desc(priv->dma_tx, txsize);
513
514 if (netif_msg_hw(priv)) {
515 pr_info("RX descriptor ring:\n");
516 display_ring(priv->dma_rx, rxsize);
517 pr_info("TX descriptor ring:\n");
518 display_ring(priv->dma_tx, txsize);
519 }
520 return;
521}
522
523static void dma_free_rx_skbufs(struct stmmac_priv *priv)
524{
525 int i;
526
527 for (i = 0; i < priv->dma_rx_size; i++) {
528 if (priv->rx_skbuff[i]) {
529 dma_unmap_single(priv->device, priv->rx_skbuff_dma[i],
530 priv->dma_buf_sz, DMA_FROM_DEVICE);
531 dev_kfree_skb_any(priv->rx_skbuff[i]);
532 }
533 priv->rx_skbuff[i] = NULL;
534 }
535 return;
536}
537
538static void dma_free_tx_skbufs(struct stmmac_priv *priv)
539{
540 int i;
541
542 for (i = 0; i < priv->dma_tx_size; i++) {
543 if (priv->tx_skbuff[i] != NULL) {
544 struct dma_desc *p = priv->dma_tx + i;
545 if (p->des2)
546 dma_unmap_single(priv->device, p->des2,
547 priv->mac_type->ops->get_tx_len(p),
548 DMA_TO_DEVICE);
549 dev_kfree_skb_any(priv->tx_skbuff[i]);
550 priv->tx_skbuff[i] = NULL;
551 }
552 }
553 return;
554}
555
556static void free_dma_desc_resources(struct stmmac_priv *priv)
557{
558 /* Release the DMA TX/RX socket buffers */
559 dma_free_rx_skbufs(priv);
560 dma_free_tx_skbufs(priv);
561
562 /* Free the region of consistent memory previously allocated for
563 * the DMA */
564 dma_free_coherent(priv->device,
565 priv->dma_tx_size * sizeof(struct dma_desc),
566 priv->dma_tx, priv->dma_tx_phy);
567 dma_free_coherent(priv->device,
568 priv->dma_rx_size * sizeof(struct dma_desc),
569 priv->dma_rx, priv->dma_rx_phy);
570 kfree(priv->rx_skbuff_dma);
571 kfree(priv->rx_skbuff);
572 kfree(priv->tx_skbuff);
573
574 return;
575}
576
577/**
578 * stmmac_dma_start_tx
579 * @ioaddr: device I/O address
580 * Description: this function starts the DMA tx process.
581 */
582static void stmmac_dma_start_tx(unsigned long ioaddr)
583{
584 u32 value = readl(ioaddr + DMA_CONTROL);
585 value |= DMA_CONTROL_ST;
586 writel(value, ioaddr + DMA_CONTROL);
587 return;
588}
589
590static void stmmac_dma_stop_tx(unsigned long ioaddr)
591{
592 u32 value = readl(ioaddr + DMA_CONTROL);
593 value &= ~DMA_CONTROL_ST;
594 writel(value, ioaddr + DMA_CONTROL);
595 return;
596}
597
598/**
599 * stmmac_dma_start_rx
600 * @ioaddr: device I/O address
601 * Description: this function starts the DMA rx process.
602 */
603static void stmmac_dma_start_rx(unsigned long ioaddr)
604{
605 u32 value = readl(ioaddr + DMA_CONTROL);
606 value |= DMA_CONTROL_SR;
607 writel(value, ioaddr + DMA_CONTROL);
608
609 return;
610}
611
612static void stmmac_dma_stop_rx(unsigned long ioaddr)
613{
614 u32 value = readl(ioaddr + DMA_CONTROL);
615 value &= ~DMA_CONTROL_SR;
616 writel(value, ioaddr + DMA_CONTROL);
617
618 return;
619}
620
621/**
622 * stmmac_dma_operation_mode - HW DMA operation mode
623 * @priv : pointer to the private device structure.
624 * Description: it sets the DMA operation mode: tx/rx DMA thresholds
625 * or Store-And-Forward capability. It also verifies the COE for the
626 * transmission in case of Giga ETH.
627 */
628static void stmmac_dma_operation_mode(struct stmmac_priv *priv)
629{
630 if (!priv->is_gmac) {
631 /* MAC 10/100 */
632 priv->mac_type->ops->dma_mode(priv->dev->base_addr, tc, 0);
633 priv->tx_coe = NO_HW_CSUM;
634 } else {
635 if ((priv->dev->mtu <= ETH_DATA_LEN) && (tx_coe)) {
636 priv->mac_type->ops->dma_mode(priv->dev->base_addr,
637 SF_DMA_MODE, SF_DMA_MODE);
638 tc = SF_DMA_MODE;
639 priv->tx_coe = HW_CSUM;
640 } else {
641 /* Checksum computation is performed in software. */
642 priv->mac_type->ops->dma_mode(priv->dev->base_addr, tc,
643 SF_DMA_MODE);
644 priv->tx_coe = NO_HW_CSUM;
645 }
646 }
647 tx_coe = priv->tx_coe;
648
649 return;
650}
651
652#ifdef STMMAC_DEBUG
653/**
654 * show_tx_process_state
655 * @status: tx descriptor status field
656 * Description: it shows the Transmit Process State for CSR5[22:20]
657 */
658static void show_tx_process_state(unsigned int status)
659{
660 unsigned int state;
661 state = (status & DMA_STATUS_TS_MASK) >> DMA_STATUS_TS_SHIFT;
662
663 switch (state) {
664 case 0:
665 pr_info("- TX (Stopped): Reset or Stop command\n");
666 break;
667 case 1:
668 pr_info("- TX (Running):Fetching the Tx desc\n");
669 break;
670 case 2:
671 pr_info("- TX (Running): Waiting for end of tx\n");
672 break;
673 case 3:
674 pr_info("- TX (Running): Reading the data "
675 "and queuing the data into the Tx buf\n");
676 break;
677 case 6:
678 pr_info("- TX (Suspended): Tx Buff Underflow "
679 "or an unavailable Transmit descriptor\n");
680 break;
681 case 7:
682 pr_info("- TX (Running): Closing Tx descriptor\n");
683 break;
684 default:
685 break;
686 }
687 return;
688}
689
690/**
691 * show_rx_process_state
692 * @status: rx descriptor status field
693 * Description: it shows the Receive Process State for CSR5[19:17]
694 */
695static void show_rx_process_state(unsigned int status)
696{
697 unsigned int state;
698 state = (status & DMA_STATUS_RS_MASK) >> DMA_STATUS_RS_SHIFT;
699
700 switch (state) {
701 case 0:
702 pr_info("- RX (Stopped): Reset or Stop command\n");
703 break;
704 case 1:
705 pr_info("- RX (Running): Fetching the Rx desc\n");
706 break;
707 case 2:
708 pr_info("- RX (Running):Checking for end of pkt\n");
709 break;
710 case 3:
711 pr_info("- RX (Running): Waiting for Rx pkt\n");
712 break;
713 case 4:
714 pr_info("- RX (Suspended): Unavailable Rx buf\n");
715 break;
716 case 5:
717 pr_info("- RX (Running): Closing Rx descriptor\n");
718 break;
719 case 6:
720 pr_info("- RX(Running): Flushing the current frame"
721 " from the Rx buf\n");
722 break;
723 case 7:
724 pr_info("- RX (Running): Queuing the Rx frame"
725 " from the Rx buf into memory\n");
726 break;
727 default:
728 break;
729 }
730 return;
731}
732#endif
733
734/**
735 * stmmac_tx:
736 * @priv: private driver structure
737 * Description: it reclaims resources after transmission completes.
738 */
739static void stmmac_tx(struct stmmac_priv *priv)
740{
741 unsigned int txsize = priv->dma_tx_size;
742 unsigned long ioaddr = priv->dev->base_addr;
743
744 while (priv->dirty_tx != priv->cur_tx) {
745 int last;
746 unsigned int entry = priv->dirty_tx % txsize;
747 struct sk_buff *skb = priv->tx_skbuff[entry];
748 struct dma_desc *p = priv->dma_tx + entry;
749
750 /* Check if the descriptor is owned by the DMA. */
751 if (priv->mac_type->ops->get_tx_owner(p))
752 break;
753
754 /* Verify tx error by looking at the last segment */
755 last = priv->mac_type->ops->get_tx_ls(p);
756 if (likely(last)) {
757 int tx_error =
758 priv->mac_type->ops->tx_status(&priv->dev->stats,
759 &priv->xstats,
760 p, ioaddr);
761 if (likely(tx_error == 0)) {
762 priv->dev->stats.tx_packets++;
763 priv->xstats.tx_pkt_n++;
764 } else
765 priv->dev->stats.tx_errors++;
766 }
767 TX_DBG("%s: curr %d, dirty %d\n", __func__,
768 priv->cur_tx, priv->dirty_tx);
769
770 if (likely(p->des2))
771 dma_unmap_single(priv->device, p->des2,
772 priv->mac_type->ops->get_tx_len(p),
773 DMA_TO_DEVICE);
774 if (unlikely(p->des3))
775 p->des3 = 0;
776
777 if (likely(skb != NULL)) {
778 /*
779 * If there's room in the queue (limit it to size)
780 * we add this skb back into the pool,
781 * if it's the right size.
782 */
783 if ((skb_queue_len(&priv->rx_recycle) <
784 priv->dma_rx_size) &&
785 skb_recycle_check(skb, priv->dma_buf_sz))
786 __skb_queue_head(&priv->rx_recycle, skb);
787 else
788 dev_kfree_skb(skb);
789
790 priv->tx_skbuff[entry] = NULL;
791 }
792
793 priv->mac_type->ops->release_tx_desc(p);
794
795 entry = (++priv->dirty_tx) % txsize;
796 }
797 if (unlikely(netif_queue_stopped(priv->dev) &&
798 stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv))) {
799 netif_tx_lock(priv->dev);
800 if (netif_queue_stopped(priv->dev) &&
801 stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv)) {
802 TX_DBG("%s: restart transmit\n", __func__);
803 netif_wake_queue(priv->dev);
804 }
805 netif_tx_unlock(priv->dev);
806 }
807 return;
808}
809
810static inline void stmmac_enable_irq(struct stmmac_priv *priv)
811{
812#ifdef CONFIG_STMMAC_TIMER
813 if (likely(priv->tm->enable))
814 priv->tm->timer_start(tmrate);
815 else
816#endif
817 writel(DMA_INTR_DEFAULT_MASK, priv->dev->base_addr + DMA_INTR_ENA);
818}
819
820static inline void stmmac_disable_irq(struct stmmac_priv *priv)
821{
822#ifdef CONFIG_STMMAC_TIMER
823 if (likely(priv->tm->enable))
824 priv->tm->timer_stop();
825 else
826#endif
827 writel(0, priv->dev->base_addr + DMA_INTR_ENA);
828}
829
830static int stmmac_has_work(struct stmmac_priv *priv)
831{
832 unsigned int has_work = 0;
833 int rxret, tx_work = 0;
834
835 rxret = priv->mac_type->ops->get_rx_owner(priv->dma_rx +
836 (priv->cur_rx % priv->dma_rx_size));
837
838 if (priv->dirty_tx != priv->cur_tx)
839 tx_work = 1;
840
841 if (likely(!rxret || tx_work))
842 has_work = 1;
843
844 return has_work;
845}
846
847static inline void _stmmac_schedule(struct stmmac_priv *priv)
848{
849 if (likely(stmmac_has_work(priv))) {
850 stmmac_disable_irq(priv);
851 napi_schedule(&priv->napi);
852 }
853}
854
855#ifdef CONFIG_STMMAC_TIMER
856void stmmac_schedule(struct net_device *dev)
857{
858 struct stmmac_priv *priv = netdev_priv(dev);
859
860 priv->xstats.sched_timer_n++;
861
862 _stmmac_schedule(priv);
863
864 return;
865}
866
867static void stmmac_no_timer_started(unsigned int x)
868{;
869};
870
871static void stmmac_no_timer_stopped(void)
872{;
873};
874#endif
875
876/**
877 * stmmac_tx_err:
878 * @priv: pointer to the private device structure
879 * Description: it cleans the descriptors and restarts the transmission
880 * in case of errors.
881 */
882static void stmmac_tx_err(struct stmmac_priv *priv)
883{
884 netif_stop_queue(priv->dev);
885
886 stmmac_dma_stop_tx(priv->dev->base_addr);
887 dma_free_tx_skbufs(priv);
888 priv->mac_type->ops->init_tx_desc(priv->dma_tx, priv->dma_tx_size);
889 priv->dirty_tx = 0;
890 priv->cur_tx = 0;
891 stmmac_dma_start_tx(priv->dev->base_addr);
892
893 priv->dev->stats.tx_errors++;
894 netif_wake_queue(priv->dev);
895
896 return;
897}
898
899/**
900 * stmmac_dma_interrupt - Interrupt handler for the driver
901 * @dev: net device structure
902 * Description: Interrupt handler for the driver (DMA).
903 */
904static void stmmac_dma_interrupt(struct net_device *dev)
905{
906 unsigned long ioaddr = dev->base_addr;
907 struct stmmac_priv *priv = netdev_priv(dev);
908 /* read the status register (CSR5) */
909 u32 intr_status = readl(ioaddr + DMA_STATUS);
910
911 DBG(intr, INFO, "%s: [CSR5: 0x%08x]\n", __func__, intr_status);
912
913#ifdef STMMAC_DEBUG
914 /* It displays the DMA transmit process state (CSR5 register) */
915 if (netif_msg_tx_done(priv))
916 show_tx_process_state(intr_status);
917 if (netif_msg_rx_status(priv))
918 show_rx_process_state(intr_status);
919#endif
920 /* ABNORMAL interrupts */
921 if (unlikely(intr_status & DMA_STATUS_AIS)) {
922 DBG(intr, INFO, "CSR5[15] DMA ABNORMAL IRQ: ");
923 if (unlikely(intr_status & DMA_STATUS_UNF)) {
924 DBG(intr, INFO, "transmit underflow\n");
925 if (unlikely(tc != SF_DMA_MODE)
926 && (tc <= 256)) {
927 /* Try to bump up the threshold */
928 tc += 64;
929 priv->mac_type->ops->dma_mode(ioaddr, tc,
930 SF_DMA_MODE);
931 priv->xstats.threshold = tc;
932 }
933 stmmac_tx_err(priv);
934 priv->xstats.tx_undeflow_irq++;
935 }
936 if (unlikely(intr_status & DMA_STATUS_TJT)) {
937 DBG(intr, INFO, "transmit jabber\n");
938 priv->xstats.tx_jabber_irq++;
939 }
940 if (unlikely(intr_status & DMA_STATUS_OVF)) {
941 DBG(intr, INFO, "recv overflow\n");
942 priv->xstats.rx_overflow_irq++;
943 }
944 if (unlikely(intr_status & DMA_STATUS_RU)) {
945 DBG(intr, INFO, "receive buffer unavailable\n");
946 priv->xstats.rx_buf_unav_irq++;
947 }
948 if (unlikely(intr_status & DMA_STATUS_RPS)) {
949 DBG(intr, INFO, "receive process stopped\n");
950 priv->xstats.rx_process_stopped_irq++;
951 }
952 if (unlikely(intr_status & DMA_STATUS_RWT)) {
953 DBG(intr, INFO, "receive watchdog\n");
954 priv->xstats.rx_watchdog_irq++;
955 }
956 if (unlikely(intr_status & DMA_STATUS_ETI)) {
957 DBG(intr, INFO, "transmit early interrupt\n");
958 priv->xstats.tx_early_irq++;
959 }
960 if (unlikely(intr_status & DMA_STATUS_TPS)) {
961 DBG(intr, INFO, "transmit process stopped\n");
962 priv->xstats.tx_process_stopped_irq++;
963 stmmac_tx_err(priv);
964 }
965 if (unlikely(intr_status & DMA_STATUS_FBI)) {
966 DBG(intr, INFO, "fatal bus error\n");
967 priv->xstats.fatal_bus_error_irq++;
968 stmmac_tx_err(priv);
969 }
970 }
971
972 /* TX/RX NORMAL interrupts */
973 if (intr_status & DMA_STATUS_NIS) {
974 priv->xstats.normal_irq_n++;
975 if (likely((intr_status & DMA_STATUS_RI) ||
976 (intr_status & (DMA_STATUS_TI))))
977 _stmmac_schedule(priv);
978 }
979
980 /* Optional hardware blocks, interrupts should be disabled */
981 if (unlikely(intr_status &
982 (DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
983 pr_info("%s: unexpected status %08x\n", __func__, intr_status);
984
985 /* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
986 writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
987
988 DBG(intr, INFO, "\n\n");
989
990 return;
991}
992
993/**
994 * stmmac_open - open entry point of the driver
995 * @dev : pointer to the device structure.
996 * Description:
997 * This function is the open entry point of the driver.
998 * Return value:
999 * 0 on success and an appropriate (-)ve integer as defined in errno.h
1000 * file on failure.
1001 */
1002static int stmmac_open(struct net_device *dev)
1003{
1004 struct stmmac_priv *priv = netdev_priv(dev);
1005 unsigned long ioaddr = dev->base_addr;
1006 int ret;
1007
1008 /* Check that the MAC address is valid. If its not, refuse
1009 * to bring the device up. The user must specify an
1010 * address using the following linux command:
1011 * ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx */
1012 if (!is_valid_ether_addr(dev->dev_addr)) {
1013 random_ether_addr(dev->dev_addr);
1014 pr_warning("%s: generated random MAC address %pM\n", dev->name,
1015 dev->dev_addr);
1016 }
1017
1018 stmmac_verify_args();
1019
1020 ret = stmmac_init_phy(dev);
1021 if (unlikely(ret)) {
1022 pr_err("%s: Cannot attach to PHY (error: %d)\n", __func__, ret);
1023 return ret;
1024 }
1025
1026 /* Request the IRQ lines */
1027 ret = request_irq(dev->irq, &stmmac_interrupt,
1028 IRQF_SHARED, dev->name, dev);
1029 if (unlikely(ret < 0)) {
1030 pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n",
1031 __func__, dev->irq, ret);
1032 return ret;
1033 }
1034
1035#ifdef CONFIG_STMMAC_TIMER
1036 priv->tm = kzalloc(sizeof(struct stmmac_timer *), GFP_KERNEL);
1037 if (unlikely(priv->tm == NULL)) {
1038 pr_err("%s: ERROR: timer memory alloc failed \n", __func__);
1039 return -ENOMEM;
1040 }
1041 priv->tm->freq = tmrate;
1042
1043 /* Test if the external timer can be actually used.
1044 * In case of failure continue without timer. */
1045 if (unlikely((stmmac_open_ext_timer(dev, priv->tm)) < 0)) {
1046 pr_warning("stmmaceth: cannot attach the external timer.\n");
1047 tmrate = 0;
1048 priv->tm->freq = 0;
1049 priv->tm->timer_start = stmmac_no_timer_started;
1050 priv->tm->timer_stop = stmmac_no_timer_stopped;
1051 } else
1052 priv->tm->enable = 1;
1053#endif
1054
1055 /* Create and initialize the TX/RX descriptors chains. */
1056 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
1057 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
1058 priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
1059 init_dma_desc_rings(dev);
1060
1061 /* DMA initialization and SW reset */
1062 if (unlikely(priv->mac_type->ops->dma_init(ioaddr,
1063 priv->pbl, priv->dma_tx_phy, priv->dma_rx_phy) < 0)) {
1064
1065 pr_err("%s: DMA initialization failed\n", __func__);
1066 return -1;
1067 }
1068
1069 /* Copy the MAC addr into the HW */
1070 priv->mac_type->ops->set_umac_addr(ioaddr, dev->dev_addr, 0);
1071 /* Initialize the MAC Core */
1072 priv->mac_type->ops->core_init(ioaddr);
1073
1074 priv->shutdown = 0;
1075
1076 /* Initialise the MMC (if present) to disable all interrupts. */
1077 writel(0xffffffff, ioaddr + MMC_HIGH_INTR_MASK);
1078 writel(0xffffffff, ioaddr + MMC_LOW_INTR_MASK);
1079
1080 /* Enable the MAC Rx/Tx */
1081 stmmac_mac_enable_rx(ioaddr);
1082 stmmac_mac_enable_tx(ioaddr);
1083
1084 /* Set the HW DMA mode and the COE */
1085 stmmac_dma_operation_mode(priv);
1086
1087 /* Extra statistics */
1088 memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
1089 priv->xstats.threshold = tc;
1090
1091 /* Start the ball rolling... */
1092 DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name);
1093 stmmac_dma_start_tx(ioaddr);
1094 stmmac_dma_start_rx(ioaddr);
1095
1096#ifdef CONFIG_STMMAC_TIMER
1097 priv->tm->timer_start(tmrate);
1098#endif
1099 /* Dump DMA/MAC registers */
1100 if (netif_msg_hw(priv)) {
1101 priv->mac_type->ops->dump_mac_regs(ioaddr);
1102 priv->mac_type->ops->dump_dma_regs(ioaddr);
1103 }
1104
1105 if (priv->phydev)
1106 phy_start(priv->phydev);
1107
1108 napi_enable(&priv->napi);
1109 skb_queue_head_init(&priv->rx_recycle);
1110 netif_start_queue(dev);
1111 return 0;
1112}
1113
1114/**
1115 * stmmac_release - close entry point of the driver
1116 * @dev : device pointer.
1117 * Description:
1118 * This is the stop entry point of the driver.
1119 */
1120static int stmmac_release(struct net_device *dev)
1121{
1122 struct stmmac_priv *priv = netdev_priv(dev);
1123
1124 /* Stop and disconnect the PHY */
1125 if (priv->phydev) {
1126 phy_stop(priv->phydev);
1127 phy_disconnect(priv->phydev);
1128 priv->phydev = NULL;
1129 }
1130
1131 netif_stop_queue(dev);
1132
1133#ifdef CONFIG_STMMAC_TIMER
1134 /* Stop and release the timer */
1135 stmmac_close_ext_timer();
1136 if (priv->tm != NULL)
1137 kfree(priv->tm);
1138#endif
1139 napi_disable(&priv->napi);
1140 skb_queue_purge(&priv->rx_recycle);
1141
1142 /* Free the IRQ lines */
1143 free_irq(dev->irq, dev);
1144
1145 /* Stop TX/RX DMA and clear the descriptors */
1146 stmmac_dma_stop_tx(dev->base_addr);
1147 stmmac_dma_stop_rx(dev->base_addr);
1148
1149 /* Release and free the Rx/Tx resources */
1150 free_dma_desc_resources(priv);
1151
1152 /* Disable the MAC core */
1153 stmmac_mac_disable_tx(dev->base_addr);
1154 stmmac_mac_disable_rx(dev->base_addr);
1155
1156 netif_carrier_off(dev);
1157
1158 return 0;
1159}
1160
1161/*
1162 * To perform emulated hardware segmentation on skb.
1163 */
1164static int stmmac_sw_tso(struct stmmac_priv *priv, struct sk_buff *skb)
1165{
1166 struct sk_buff *segs, *curr_skb;
1167 int gso_segs = skb_shinfo(skb)->gso_segs;
1168
1169 /* Estimate the number of fragments in the worst case */
1170 if (unlikely(stmmac_tx_avail(priv) < gso_segs)) {
1171 netif_stop_queue(priv->dev);
1172 TX_DBG(KERN_ERR "%s: TSO BUG! Tx Ring full when queue awake\n",
1173 __func__);
1174 if (stmmac_tx_avail(priv) < gso_segs)
1175 return NETDEV_TX_BUSY;
1176
1177 netif_wake_queue(priv->dev);
1178 }
1179 TX_DBG("\tstmmac_sw_tso: segmenting: skb %p (len %d)\n",
1180 skb, skb->len);
1181
1182 segs = skb_gso_segment(skb, priv->dev->features & ~NETIF_F_TSO);
1183 if (unlikely(IS_ERR(segs)))
1184 goto sw_tso_end;
1185
1186 do {
1187 curr_skb = segs;
1188 segs = segs->next;
1189 TX_DBG("\t\tcurrent skb->len: %d, *curr %p,"
1190 "*next %p\n", curr_skb->len, curr_skb, segs);
1191 curr_skb->next = NULL;
1192 stmmac_xmit(curr_skb, priv->dev);
1193 } while (segs);
1194
1195sw_tso_end:
1196 dev_kfree_skb(skb);
1197
1198 return NETDEV_TX_OK;
1199}
1200
1201static unsigned int stmmac_handle_jumbo_frames(struct sk_buff *skb,
1202 struct net_device *dev,
1203 int csum_insertion)
1204{
1205 struct stmmac_priv *priv = netdev_priv(dev);
1206 unsigned int nopaged_len = skb_headlen(skb);
1207 unsigned int txsize = priv->dma_tx_size;
1208 unsigned int entry = priv->cur_tx % txsize;
1209 struct dma_desc *desc = priv->dma_tx + entry;
1210
1211 if (nopaged_len > BUF_SIZE_8KiB) {
1212
1213 int buf2_size = nopaged_len - BUF_SIZE_8KiB;
1214
1215 desc->des2 = dma_map_single(priv->device, skb->data,
1216 BUF_SIZE_8KiB, DMA_TO_DEVICE);
1217 desc->des3 = desc->des2 + BUF_SIZE_4KiB;
1218 priv->mac_type->ops->prepare_tx_desc(desc, 1, BUF_SIZE_8KiB,
1219 csum_insertion);
1220
1221 entry = (++priv->cur_tx) % txsize;
1222 desc = priv->dma_tx + entry;
1223
1224 desc->des2 = dma_map_single(priv->device,
1225 skb->data + BUF_SIZE_8KiB,
1226 buf2_size, DMA_TO_DEVICE);
1227 desc->des3 = desc->des2 + BUF_SIZE_4KiB;
1228 priv->mac_type->ops->prepare_tx_desc(desc, 0,
1229 buf2_size, csum_insertion);
1230 priv->mac_type->ops->set_tx_owner(desc);
1231 priv->tx_skbuff[entry] = NULL;
1232 } else {
1233 desc->des2 = dma_map_single(priv->device, skb->data,
1234 nopaged_len, DMA_TO_DEVICE);
1235 desc->des3 = desc->des2 + BUF_SIZE_4KiB;
1236 priv->mac_type->ops->prepare_tx_desc(desc, 1, nopaged_len,
1237 csum_insertion);
1238 }
1239 return entry;
1240}
1241
1242/**
1243 * stmmac_xmit:
1244 * @skb : the socket buffer
1245 * @dev : device pointer
1246 * Description : Tx entry point of the driver.
1247 */
1248static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1249{
1250 struct stmmac_priv *priv = netdev_priv(dev);
1251 unsigned int txsize = priv->dma_tx_size;
1252 unsigned int entry;
1253 int i, csum_insertion = 0;
1254 int nfrags = skb_shinfo(skb)->nr_frags;
1255 struct dma_desc *desc, *first;
1256
1257 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1258 if (!netif_queue_stopped(dev)) {
1259 netif_stop_queue(dev);
1260 /* This is a hard error, log it. */
1261 pr_err("%s: BUG! Tx Ring full when queue awake\n",
1262 __func__);
1263 }
1264 return NETDEV_TX_BUSY;
1265 }
1266
1267 entry = priv->cur_tx % txsize;
1268
1269#ifdef STMMAC_XMIT_DEBUG
1270 if ((skb->len > ETH_FRAME_LEN) || nfrags)
1271 pr_info("stmmac xmit:\n"
1272 "\tskb addr %p - len: %d - nopaged_len: %d\n"
1273 "\tn_frags: %d - ip_summed: %d - %s gso\n",
1274 skb, skb->len, skb_headlen(skb), nfrags, skb->ip_summed,
1275 !skb_is_gso(skb) ? "isn't" : "is");
1276#endif
1277
1278 if (unlikely(skb_is_gso(skb)))
1279 return stmmac_sw_tso(priv, skb);
1280
1281 if (likely((skb->ip_summed == CHECKSUM_PARTIAL))) {
1282 if (likely(priv->tx_coe == NO_HW_CSUM))
1283 skb_checksum_help(skb);
1284 else
1285 csum_insertion = 1;
1286 }
1287
1288 desc = priv->dma_tx + entry;
1289 first = desc;
1290
1291#ifdef STMMAC_XMIT_DEBUG
1292 if ((nfrags > 0) || (skb->len > ETH_FRAME_LEN))
1293 pr_debug("stmmac xmit: skb len: %d, nopaged_len: %d,\n"
1294 "\t\tn_frags: %d, ip_summed: %d\n",
1295 skb->len, skb_headlen(skb), nfrags, skb->ip_summed);
1296#endif
1297 priv->tx_skbuff[entry] = skb;
1298 if (unlikely(skb->len >= BUF_SIZE_4KiB)) {
1299 entry = stmmac_handle_jumbo_frames(skb, dev, csum_insertion);
1300 desc = priv->dma_tx + entry;
1301 } else {
1302 unsigned int nopaged_len = skb_headlen(skb);
1303 desc->des2 = dma_map_single(priv->device, skb->data,
1304 nopaged_len, DMA_TO_DEVICE);
1305 priv->mac_type->ops->prepare_tx_desc(desc, 1, nopaged_len,
1306 csum_insertion);
1307 }
1308
1309 for (i = 0; i < nfrags; i++) {
1310 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1311 int len = frag->size;
1312
1313 entry = (++priv->cur_tx) % txsize;
1314 desc = priv->dma_tx + entry;
1315
1316 TX_DBG("\t[entry %d] segment len: %d\n", entry, len);
1317 desc->des2 = dma_map_page(priv->device, frag->page,
1318 frag->page_offset,
1319 len, DMA_TO_DEVICE);
1320 priv->tx_skbuff[entry] = NULL;
1321 priv->mac_type->ops->prepare_tx_desc(desc, 0, len,
1322 csum_insertion);
1323 priv->mac_type->ops->set_tx_owner(desc);
1324 }
1325
1326 /* Interrupt on completition only for the latest segment */
1327 priv->mac_type->ops->close_tx_desc(desc);
1328
1329#ifdef CONFIG_STMMAC_TIMER
1330 /* Clean IC while using timer */
1331 if (likely(priv->tm->enable))
1332 priv->mac_type->ops->clear_tx_ic(desc);
1333#endif
1334 /* To avoid raise condition */
1335 priv->mac_type->ops->set_tx_owner(first);
1336
1337 priv->cur_tx++;
1338
1339#ifdef STMMAC_XMIT_DEBUG
1340 if (netif_msg_pktdata(priv)) {
1341 pr_info("stmmac xmit: current=%d, dirty=%d, entry=%d, "
1342 "first=%p, nfrags=%d\n",
1343 (priv->cur_tx % txsize), (priv->dirty_tx % txsize),
1344 entry, first, nfrags);
1345 display_ring(priv->dma_tx, txsize);
1346 pr_info(">>> frame to be transmitted: ");
1347 print_pkt(skb->data, skb->len);
1348 }
1349#endif
1350 if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) {
1351 TX_DBG("%s: stop transmitted packets\n", __func__);
1352 netif_stop_queue(dev);
1353 }
1354
1355 dev->stats.tx_bytes += skb->len;
1356
1357 /* CSR1 enables the transmit DMA to check for new descriptor */
1358 writel(1, dev->base_addr + DMA_XMT_POLL_DEMAND);
1359
1360 return NETDEV_TX_OK;
1361}
1362
1363static inline void stmmac_rx_refill(struct stmmac_priv *priv)
1364{
1365 unsigned int rxsize = priv->dma_rx_size;
1366 int bfsize = priv->dma_buf_sz;
1367 struct dma_desc *p = priv->dma_rx;
1368
1369 for (; priv->cur_rx - priv->dirty_rx > 0; priv->dirty_rx++) {
1370 unsigned int entry = priv->dirty_rx % rxsize;
1371 if (likely(priv->rx_skbuff[entry] == NULL)) {
1372 struct sk_buff *skb;
1373
1374 skb = __skb_dequeue(&priv->rx_recycle);
1375 if (skb == NULL)
1376 skb = netdev_alloc_skb_ip_align(priv->dev,
1377 bfsize);
1378
1379 if (unlikely(skb == NULL))
1380 break;
1381
1382 priv->rx_skbuff[entry] = skb;
1383 priv->rx_skbuff_dma[entry] =
1384 dma_map_single(priv->device, skb->data, bfsize,
1385 DMA_FROM_DEVICE);
1386
1387 (p + entry)->des2 = priv->rx_skbuff_dma[entry];
1388 if (unlikely(priv->is_gmac)) {
1389 if (bfsize >= BUF_SIZE_8KiB)
1390 (p + entry)->des3 =
1391 (p + entry)->des2 + BUF_SIZE_8KiB;
1392 }
1393 RX_DBG(KERN_INFO "\trefill entry #%d\n", entry);
1394 }
1395 priv->mac_type->ops->set_rx_owner(p + entry);
1396 }
1397 return;
1398}
1399
1400static int stmmac_rx(struct stmmac_priv *priv, int limit)
1401{
1402 unsigned int rxsize = priv->dma_rx_size;
1403 unsigned int entry = priv->cur_rx % rxsize;
1404 unsigned int next_entry;
1405 unsigned int count = 0;
1406 struct dma_desc *p = priv->dma_rx + entry;
1407 struct dma_desc *p_next;
1408
1409#ifdef STMMAC_RX_DEBUG
1410 if (netif_msg_hw(priv)) {
1411 pr_debug(">>> stmmac_rx: descriptor ring:\n");
1412 display_ring(priv->dma_rx, rxsize);
1413 }
1414#endif
1415 count = 0;
1416 while (!priv->mac_type->ops->get_rx_owner(p)) {
1417 int status;
1418
1419 if (count >= limit)
1420 break;
1421
1422 count++;
1423
1424 next_entry = (++priv->cur_rx) % rxsize;
1425 p_next = priv->dma_rx + next_entry;
1426 prefetch(p_next);
1427
1428 /* read the status of the incoming frame */
1429 status = (priv->mac_type->ops->rx_status(&priv->dev->stats,
1430 &priv->xstats, p));
1431 if (unlikely(status == discard_frame))
1432 priv->dev->stats.rx_errors++;
1433 else {
1434 struct sk_buff *skb;
1435 /* Length should omit the CRC */
1436 int frame_len =
1437 priv->mac_type->ops->get_rx_frame_len(p) - 4;
1438
1439#ifdef STMMAC_RX_DEBUG
1440 if (frame_len > ETH_FRAME_LEN)
1441 pr_debug("\tRX frame size %d, COE status: %d\n",
1442 frame_len, status);
1443
1444 if (netif_msg_hw(priv))
1445 pr_debug("\tdesc: %p [entry %d] buff=0x%x\n",
1446 p, entry, p->des2);
1447#endif
1448 skb = priv->rx_skbuff[entry];
1449 if (unlikely(!skb)) {
1450 pr_err("%s: Inconsistent Rx descriptor chain\n",
1451 priv->dev->name);
1452 priv->dev->stats.rx_dropped++;
1453 break;
1454 }
1455 prefetch(skb->data - NET_IP_ALIGN);
1456 priv->rx_skbuff[entry] = NULL;
1457
1458 skb_put(skb, frame_len);
1459 dma_unmap_single(priv->device,
1460 priv->rx_skbuff_dma[entry],
1461 priv->dma_buf_sz, DMA_FROM_DEVICE);
1462#ifdef STMMAC_RX_DEBUG
1463 if (netif_msg_pktdata(priv)) {
1464 pr_info(" frame received (%dbytes)", frame_len);
1465 print_pkt(skb->data, frame_len);
1466 }
1467#endif
1468 skb->protocol = eth_type_trans(skb, priv->dev);
1469
1470 if (unlikely(status == csum_none)) {
1471 /* always for the old mac 10/100 */
1472 skb->ip_summed = CHECKSUM_NONE;
1473 netif_receive_skb(skb);
1474 } else {
1475 skb->ip_summed = CHECKSUM_UNNECESSARY;
1476 napi_gro_receive(&priv->napi, skb);
1477 }
1478
1479 priv->dev->stats.rx_packets++;
1480 priv->dev->stats.rx_bytes += frame_len;
1481 priv->dev->last_rx = jiffies;
1482 }
1483 entry = next_entry;
1484 p = p_next; /* use prefetched values */
1485 }
1486
1487 stmmac_rx_refill(priv);
1488
1489 priv->xstats.rx_pkt_n += count;
1490
1491 return count;
1492}
1493
1494/**
1495 * stmmac_poll - stmmac poll method (NAPI)
1496 * @napi : pointer to the napi structure.
1497 * @budget : maximum number of packets that the current CPU can receive from
1498 * all interfaces.
1499 * Description :
1500 * This function implements the the reception process.
1501 * Also it runs the TX completion thread
1502 */
1503static int stmmac_poll(struct napi_struct *napi, int budget)
1504{
1505 struct stmmac_priv *priv = container_of(napi, struct stmmac_priv, napi);
1506 int work_done = 0;
1507
1508 priv->xstats.poll_n++;
1509 stmmac_tx(priv);
1510 work_done = stmmac_rx(priv, budget);
1511
1512 if (work_done < budget) {
1513 napi_complete(napi);
1514 stmmac_enable_irq(priv);
1515 }
1516 return work_done;
1517}
1518
1519/**
1520 * stmmac_tx_timeout
1521 * @dev : Pointer to net device structure
1522 * Description: this function is called when a packet transmission fails to
1523 * complete within a reasonable tmrate. The driver will mark the error in the
1524 * netdev structure and arrange for the device to be reset to a sane state
1525 * in order to transmit a new packet.
1526 */
1527static void stmmac_tx_timeout(struct net_device *dev)
1528{
1529 struct stmmac_priv *priv = netdev_priv(dev);
1530
1531 /* Clear Tx resources and restart transmitting again */
1532 stmmac_tx_err(priv);
1533 return;
1534}
1535
1536/* Configuration changes (passed on by ifconfig) */
1537static int stmmac_config(struct net_device *dev, struct ifmap *map)
1538{
1539 if (dev->flags & IFF_UP) /* can't act on a running interface */
1540 return -EBUSY;
1541
1542 /* Don't allow changing the I/O address */
1543 if (map->base_addr != dev->base_addr) {
1544 pr_warning("%s: can't change I/O address\n", dev->name);
1545 return -EOPNOTSUPP;
1546 }
1547
1548 /* Don't allow changing the IRQ */
1549 if (map->irq != dev->irq) {
1550 pr_warning("%s: can't change IRQ number %d\n",
1551 dev->name, dev->irq);
1552 return -EOPNOTSUPP;
1553 }
1554
1555 /* ignore other fields */
1556 return 0;
1557}
1558
1559/**
1560 * stmmac_multicast_list - entry point for multicast addressing
1561 * @dev : pointer to the device structure
1562 * Description:
1563 * This function is a driver entry point which gets called by the kernel
1564 * whenever multicast addresses must be enabled/disabled.
1565 * Return value:
1566 * void.
1567 */
1568static void stmmac_multicast_list(struct net_device *dev)
1569{
1570 struct stmmac_priv *priv = netdev_priv(dev);
1571
1572 spin_lock(&priv->lock);
1573 priv->mac_type->ops->set_filter(dev);
1574 spin_unlock(&priv->lock);
1575 return;
1576}
1577
1578/**
1579 * stmmac_change_mtu - entry point to change MTU size for the device.
1580 * @dev : device pointer.
1581 * @new_mtu : the new MTU size for the device.
1582 * Description: the Maximum Transfer Unit (MTU) is used by the network layer
1583 * to drive packet transmission. Ethernet has an MTU of 1500 octets
1584 * (ETH_DATA_LEN). This value can be changed with ifconfig.
1585 * Return value:
1586 * 0 on success and an appropriate (-)ve integer as defined in errno.h
1587 * file on failure.
1588 */
1589static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
1590{
1591 struct stmmac_priv *priv = netdev_priv(dev);
1592 int max_mtu;
1593
1594 if (netif_running(dev)) {
1595 pr_err("%s: must be stopped to change its MTU\n", dev->name);
1596 return -EBUSY;
1597 }
1598
1599 if (priv->is_gmac)
1600 max_mtu = JUMBO_LEN;
1601 else
1602 max_mtu = ETH_DATA_LEN;
1603
1604 if ((new_mtu < 46) || (new_mtu > max_mtu)) {
1605 pr_err("%s: invalid MTU, max MTU is: %d\n", dev->name, max_mtu);
1606 return -EINVAL;
1607 }
1608
1609 dev->mtu = new_mtu;
1610
1611 return 0;
1612}
1613
1614static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
1615{
1616 struct net_device *dev = (struct net_device *)dev_id;
1617 struct stmmac_priv *priv = netdev_priv(dev);
1618
1619 if (unlikely(!dev)) {
1620 pr_err("%s: invalid dev pointer\n", __func__);
1621 return IRQ_NONE;
1622 }
1623
1624 if (priv->is_gmac) {
1625 unsigned long ioaddr = dev->base_addr;
1626 /* To handle GMAC own interrupts */
1627 priv->mac_type->ops->host_irq_status(ioaddr);
1628 }
1629 stmmac_dma_interrupt(dev);
1630
1631 return IRQ_HANDLED;
1632}
1633
1634#ifdef CONFIG_NET_POLL_CONTROLLER
1635/* Polling receive - used by NETCONSOLE and other diagnostic tools
1636 * to allow network I/O with interrupts disabled. */
1637static void stmmac_poll_controller(struct net_device *dev)
1638{
1639 disable_irq(dev->irq);
1640 stmmac_interrupt(dev->irq, dev);
1641 enable_irq(dev->irq);
1642}
1643#endif
1644
1645/**
1646 * stmmac_ioctl - Entry point for the Ioctl
1647 * @dev: Device pointer.
1648 * @rq: An IOCTL specefic structure, that can contain a pointer to
1649 * a proprietary structure used to pass information to the driver.
1650 * @cmd: IOCTL command
1651 * Description:
1652 * Currently there are no special functionality supported in IOCTL, just the
1653 * phy_mii_ioctl(...) can be invoked.
1654 */
1655static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1656{
1657 struct stmmac_priv *priv = netdev_priv(dev);
1658 int ret = -EOPNOTSUPP;
1659
1660 if (!netif_running(dev))
1661 return -EINVAL;
1662
1663 switch (cmd) {
1664 case SIOCGMIIPHY:
1665 case SIOCGMIIREG:
1666 case SIOCSMIIREG:
1667 if (!priv->phydev)
1668 return -EINVAL;
1669
1670 spin_lock(&priv->lock);
1671 ret = phy_mii_ioctl(priv->phydev, if_mii(rq), cmd);
1672 spin_unlock(&priv->lock);
1673 default:
1674 break;
1675 }
1676 return ret;
1677}
1678
1679#ifdef STMMAC_VLAN_TAG_USED
1680static void stmmac_vlan_rx_register(struct net_device *dev,
1681 struct vlan_group *grp)
1682{
1683 struct stmmac_priv *priv = netdev_priv(dev);
1684
1685 DBG(probe, INFO, "%s: Setting vlgrp to %p\n", dev->name, grp);
1686
1687 spin_lock(&priv->lock);
1688 priv->vlgrp = grp;
1689 spin_unlock(&priv->lock);
1690
1691 return;
1692}
1693#endif
1694
1695static const struct net_device_ops stmmac_netdev_ops = {
1696 .ndo_open = stmmac_open,
1697 .ndo_start_xmit = stmmac_xmit,
1698 .ndo_stop = stmmac_release,
1699 .ndo_change_mtu = stmmac_change_mtu,
1700 .ndo_set_multicast_list = stmmac_multicast_list,
1701 .ndo_tx_timeout = stmmac_tx_timeout,
1702 .ndo_do_ioctl = stmmac_ioctl,
1703 .ndo_set_config = stmmac_config,
1704#ifdef STMMAC_VLAN_TAG_USED
1705 .ndo_vlan_rx_register = stmmac_vlan_rx_register,
1706#endif
1707#ifdef CONFIG_NET_POLL_CONTROLLER
1708 .ndo_poll_controller = stmmac_poll_controller,
1709#endif
1710 .ndo_set_mac_address = eth_mac_addr,
1711};
1712
1713/**
1714 * stmmac_probe - Initialization of the adapter .
1715 * @dev : device pointer
1716 * Description: The function initializes the network device structure for
1717 * the STMMAC driver. It also calls the low level routines
1718 * in order to init the HW (i.e. the DMA engine)
1719 */
1720static int stmmac_probe(struct net_device *dev)
1721{
1722 int ret = 0;
1723 struct stmmac_priv *priv = netdev_priv(dev);
1724
1725 ether_setup(dev);
1726
1727 dev->netdev_ops = &stmmac_netdev_ops;
1728 stmmac_set_ethtool_ops(dev);
1729
1730 dev->features |= (NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HIGHDMA);
1731 dev->watchdog_timeo = msecs_to_jiffies(watchdog);
1732#ifdef STMMAC_VLAN_TAG_USED
1733 /* Both mac100 and gmac support receive VLAN tag detection */
1734 dev->features |= NETIF_F_HW_VLAN_RX;
1735#endif
1736 priv->msg_enable = netif_msg_init(debug, default_msg_level);
1737
1738 if (priv->is_gmac)
1739 priv->rx_csum = 1;
1740
1741 if (flow_ctrl)
1742 priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */
1743
1744 priv->pause = pause;
1745 netif_napi_add(dev, &priv->napi, stmmac_poll, 64);
1746
1747 /* Get the MAC address */
1748 priv->mac_type->ops->get_umac_addr(dev->base_addr, dev->dev_addr, 0);
1749
1750 if (!is_valid_ether_addr(dev->dev_addr))
1751 pr_warning("\tno valid MAC address;"
1752 "please, use ifconfig or nwhwconfig!\n");
1753
1754 ret = register_netdev(dev);
1755 if (ret) {
1756 pr_err("%s: ERROR %i registering the device\n",
1757 __func__, ret);
1758 return -ENODEV;
1759 }
1760
1761 DBG(probe, DEBUG, "%s: Scatter/Gather: %s - HW checksums: %s\n",
1762 dev->name, (dev->features & NETIF_F_SG) ? "on" : "off",
1763 (dev->features & NETIF_F_HW_CSUM) ? "on" : "off");
1764
1765 spin_lock_init(&priv->lock);
1766
1767 return ret;
1768}
1769
1770/**
1771 * stmmac_mac_device_setup
1772 * @dev : device pointer
1773 * Description: select and initialise the mac device (mac100 or Gmac).
1774 */
1775static int stmmac_mac_device_setup(struct net_device *dev)
1776{
1777 struct stmmac_priv *priv = netdev_priv(dev);
1778 unsigned long ioaddr = dev->base_addr;
1779
1780 struct mac_device_info *device;
1781
1782 if (priv->is_gmac)
1783 device = gmac_setup(ioaddr);
1784 else
1785 device = mac100_setup(ioaddr);
1786
1787 if (!device)
1788 return -ENOMEM;
1789
1790 priv->mac_type = device;
1791
1792 priv->wolenabled = priv->mac_type->hw.pmt; /* PMT supported */
1793 if (priv->wolenabled == PMT_SUPPORTED)
1794 priv->wolopts = WAKE_MAGIC; /* Magic Frame */
1795
1796 return 0;
1797}
1798
1799static int stmmacphy_dvr_probe(struct platform_device *pdev)
1800{
1801 struct plat_stmmacphy_data *plat_dat;
1802 plat_dat = (struct plat_stmmacphy_data *)((pdev->dev).platform_data);
1803
1804 pr_debug("stmmacphy_dvr_probe: added phy for bus %d\n",
1805 plat_dat->bus_id);
1806
1807 return 0;
1808}
1809
1810static int stmmacphy_dvr_remove(struct platform_device *pdev)
1811{
1812 return 0;
1813}
1814
1815static struct platform_driver stmmacphy_driver = {
1816 .driver = {
1817 .name = PHY_RESOURCE_NAME,
1818 },
1819 .probe = stmmacphy_dvr_probe,
1820 .remove = stmmacphy_dvr_remove,
1821};
1822
1823/**
1824 * stmmac_associate_phy
1825 * @dev: pointer to device structure
1826 * @data: points to the private structure.
1827 * Description: Scans through all the PHYs we have registered and checks if
1828 * any are associated with our MAC. If so, then just fill in
1829 * the blanks in our local context structure
1830 */
1831static int stmmac_associate_phy(struct device *dev, void *data)
1832{
1833 struct stmmac_priv *priv = (struct stmmac_priv *)data;
1834 struct plat_stmmacphy_data *plat_dat;
1835
1836 plat_dat = (struct plat_stmmacphy_data *)(dev->platform_data);
1837
1838 DBG(probe, DEBUG, "%s: checking phy for bus %d\n", __func__,
1839 plat_dat->bus_id);
1840
1841 /* Check that this phy is for the MAC being initialised */
1842 if (priv->bus_id != plat_dat->bus_id)
1843 return 0;
1844
1845 /* OK, this PHY is connected to the MAC.
1846 Go ahead and get the parameters */
1847 DBG(probe, DEBUG, "%s: OK. Found PHY config\n", __func__);
1848 priv->phy_irq =
1849 platform_get_irq_byname(to_platform_device(dev), "phyirq");
1850 DBG(probe, DEBUG, "%s: PHY irq on bus %d is %d\n", __func__,
1851 plat_dat->bus_id, priv->phy_irq);
1852
1853 /* Override with kernel parameters if supplied XXX CRS XXX
1854 * this needs to have multiple instances */
1855 if ((phyaddr >= 0) && (phyaddr <= 31))
1856 plat_dat->phy_addr = phyaddr;
1857
1858 priv->phy_addr = plat_dat->phy_addr;
1859 priv->phy_mask = plat_dat->phy_mask;
1860 priv->phy_interface = plat_dat->interface;
1861 priv->phy_reset = plat_dat->phy_reset;
1862
1863 DBG(probe, DEBUG, "%s: exiting\n", __func__);
1864 return 1; /* forces exit of driver_for_each_device() */
1865}
1866
1867/**
1868 * stmmac_dvr_probe
1869 * @pdev: platform device pointer
1870 * Description: the driver is initialized through platform_device.
1871 */
1872static int stmmac_dvr_probe(struct platform_device *pdev)
1873{
1874 int ret = 0;
1875 struct resource *res;
1876 unsigned int *addr = NULL;
1877 struct net_device *ndev = NULL;
1878 struct stmmac_priv *priv;
1879 struct plat_stmmacenet_data *plat_dat;
1880
1881 pr_info("STMMAC driver:\n\tplatform registration... ");
1882 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1883 if (!res) {
1884 ret = -ENODEV;
1885 goto out;
1886 }
1887 pr_info("done!\n");
1888
1889 if (!request_mem_region(res->start, (res->end - res->start),
1890 pdev->name)) {
1891 pr_err("%s: ERROR: memory allocation failed"
1892 "cannot get the I/O addr 0x%x\n",
1893 __func__, (unsigned int)res->start);
1894 ret = -EBUSY;
1895 goto out;
1896 }
1897
1898 addr = ioremap(res->start, (res->end - res->start));
1899 if (!addr) {
1900 pr_err("%s: ERROR: memory mapping failed \n", __func__);
1901 ret = -ENOMEM;
1902 goto out;
1903 }
1904
1905 ndev = alloc_etherdev(sizeof(struct stmmac_priv));
1906 if (!ndev) {
1907 pr_err("%s: ERROR: allocating the device\n", __func__);
1908 ret = -ENOMEM;
1909 goto out;
1910 }
1911
1912 SET_NETDEV_DEV(ndev, &pdev->dev);
1913
1914 /* Get the MAC information */
1915 ndev->irq = platform_get_irq_byname(pdev, "macirq");
1916 if (ndev->irq == -ENXIO) {
1917 pr_err("%s: ERROR: MAC IRQ configuration "
1918 "information not found\n", __func__);
1919 ret = -ENODEV;
1920 goto out;
1921 }
1922
1923 priv = netdev_priv(ndev);
1924 priv->device = &(pdev->dev);
1925 priv->dev = ndev;
1926 plat_dat = (struct plat_stmmacenet_data *)((pdev->dev).platform_data);
1927 priv->bus_id = plat_dat->bus_id;
1928 priv->pbl = plat_dat->pbl; /* TLI */
1929 priv->is_gmac = plat_dat->has_gmac; /* GMAC is on board */
1930
1931 platform_set_drvdata(pdev, ndev);
1932
1933 /* Set the I/O base addr */
1934 ndev->base_addr = (unsigned long)addr;
1935
1936 /* MAC HW revice detection */
1937 ret = stmmac_mac_device_setup(ndev);
1938 if (ret < 0)
1939 goto out;
1940
1941 /* Network Device Registration */
1942 ret = stmmac_probe(ndev);
1943 if (ret < 0)
1944 goto out;
1945
1946 /* associate a PHY - it is provided by another platform bus */
1947 if (!driver_for_each_device
1948 (&(stmmacphy_driver.driver), NULL, (void *)priv,
1949 stmmac_associate_phy)) {
1950 pr_err("No PHY device is associated with this MAC!\n");
1951 ret = -ENODEV;
1952 goto out;
1953 }
1954
1955 priv->fix_mac_speed = plat_dat->fix_mac_speed;
1956 priv->bsp_priv = plat_dat->bsp_priv;
1957
1958 pr_info("\t%s - (dev. name: %s - id: %d, IRQ #%d\n"
1959 "\tIO base addr: 0x%08x)\n", ndev->name, pdev->name,
1960 pdev->id, ndev->irq, (unsigned int)addr);
1961
1962 /* MDIO bus Registration */
1963 pr_debug("\tMDIO bus (id: %d)...", priv->bus_id);
1964 ret = stmmac_mdio_register(ndev);
1965 if (ret < 0)
1966 goto out;
1967 pr_debug("registered!\n");
1968
1969out:
1970 if (ret < 0) {
1971 platform_set_drvdata(pdev, NULL);
1972 release_mem_region(res->start, (res->end - res->start));
1973 if (addr != NULL)
1974 iounmap(addr);
1975 }
1976
1977 return ret;
1978}
1979
1980/**
1981 * stmmac_dvr_remove
1982 * @pdev: platform device pointer
1983 * Description: this function resets the TX/RX processes, disables the MAC RX/TX
1984 * changes the link status, releases the DMA descriptor rings,
1985 * unregisters the MDIO bus and unmaps the allocated memory.
1986 */
1987static int stmmac_dvr_remove(struct platform_device *pdev)
1988{
1989 struct net_device *ndev = platform_get_drvdata(pdev);
1990 struct resource *res;
1991
1992 pr_info("%s:\n\tremoving driver", __func__);
1993
1994 stmmac_dma_stop_rx(ndev->base_addr);
1995 stmmac_dma_stop_tx(ndev->base_addr);
1996
1997 stmmac_mac_disable_rx(ndev->base_addr);
1998 stmmac_mac_disable_tx(ndev->base_addr);
1999
2000 netif_carrier_off(ndev);
2001
2002 stmmac_mdio_unregister(ndev);
2003
2004 platform_set_drvdata(pdev, NULL);
2005 unregister_netdev(ndev);
2006
2007 iounmap((void *)ndev->base_addr);
2008 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2009 release_mem_region(res->start, (res->end - res->start));
2010
2011 free_netdev(ndev);
2012
2013 return 0;
2014}
2015
2016#ifdef CONFIG_PM
2017static int stmmac_suspend(struct platform_device *pdev, pm_message_t state)
2018{
2019 struct net_device *dev = platform_get_drvdata(pdev);
2020 struct stmmac_priv *priv = netdev_priv(dev);
2021 int dis_ic = 0;
2022
2023 if (!dev || !netif_running(dev))
2024 return 0;
2025
2026 spin_lock(&priv->lock);
2027
2028 if (state.event == PM_EVENT_SUSPEND) {
2029 netif_device_detach(dev);
2030 netif_stop_queue(dev);
2031 if (priv->phydev)
2032 phy_stop(priv->phydev);
2033
2034#ifdef CONFIG_STMMAC_TIMER
2035 priv->tm->timer_stop();
2036 if (likely(priv->tm->enable))
2037 dis_ic = 1;
2038#endif
2039 napi_disable(&priv->napi);
2040
2041 /* Stop TX/RX DMA */
2042 stmmac_dma_stop_tx(dev->base_addr);
2043 stmmac_dma_stop_rx(dev->base_addr);
2044 /* Clear the Rx/Tx descriptors */
2045 priv->mac_type->ops->init_rx_desc(priv->dma_rx,
2046 priv->dma_rx_size, dis_ic);
2047 priv->mac_type->ops->init_tx_desc(priv->dma_tx,
2048 priv->dma_tx_size);
2049
2050 stmmac_mac_disable_tx(dev->base_addr);
2051
2052 if (device_may_wakeup(&(pdev->dev))) {
2053 /* Enable Power down mode by programming the PMT regs */
2054 if (priv->wolenabled == PMT_SUPPORTED)
2055 priv->mac_type->ops->pmt(dev->base_addr,
2056 priv->wolopts);
2057 } else {
2058 stmmac_mac_disable_rx(dev->base_addr);
2059 }
2060 } else {
2061 priv->shutdown = 1;
2062 /* Although this can appear slightly redundant it actually
2063 * makes fast the standby operation and guarantees the driver
2064 * working if hibernation is on media. */
2065 stmmac_release(dev);
2066 }
2067
2068 spin_unlock(&priv->lock);
2069 return 0;
2070}
2071
2072static int stmmac_resume(struct platform_device *pdev)
2073{
2074 struct net_device *dev = platform_get_drvdata(pdev);
2075 struct stmmac_priv *priv = netdev_priv(dev);
2076 unsigned long ioaddr = dev->base_addr;
2077
2078 if (!netif_running(dev))
2079 return 0;
2080
2081 spin_lock(&priv->lock);
2082
2083 if (priv->shutdown) {
2084 /* Re-open the interface and re-init the MAC/DMA
2085 and the rings. */
2086 stmmac_open(dev);
2087 goto out_resume;
2088 }
2089
2090 /* Power Down bit, into the PM register, is cleared
2091 * automatically as soon as a magic packet or a Wake-up frame
2092 * is received. Anyway, it's better to manually clear
2093 * this bit because it can generate problems while resuming
2094 * from another devices (e.g. serial console). */
2095 if (device_may_wakeup(&(pdev->dev)))
2096 if (priv->wolenabled == PMT_SUPPORTED)
2097 priv->mac_type->ops->pmt(dev->base_addr, 0);
2098
2099 netif_device_attach(dev);
2100
2101 /* Enable the MAC and DMA */
2102 stmmac_mac_enable_rx(ioaddr);
2103 stmmac_mac_enable_tx(ioaddr);
2104 stmmac_dma_start_tx(ioaddr);
2105 stmmac_dma_start_rx(ioaddr);
2106
2107#ifdef CONFIG_STMMAC_TIMER
2108 priv->tm->timer_start(tmrate);
2109#endif
2110 napi_enable(&priv->napi);
2111
2112 if (priv->phydev)
2113 phy_start(priv->phydev);
2114
2115 netif_start_queue(dev);
2116
2117out_resume:
2118 spin_unlock(&priv->lock);
2119 return 0;
2120}
2121#endif
2122
2123static struct platform_driver stmmac_driver = {
2124 .driver = {
2125 .name = STMMAC_RESOURCE_NAME,
2126 },
2127 .probe = stmmac_dvr_probe,
2128 .remove = stmmac_dvr_remove,
2129#ifdef CONFIG_PM
2130 .suspend = stmmac_suspend,
2131 .resume = stmmac_resume,
2132#endif
2133
2134};
2135
2136/**
2137 * stmmac_init_module - Entry point for the driver
2138 * Description: This function is the entry point for the driver.
2139 */
2140static int __init stmmac_init_module(void)
2141{
2142 int ret;
2143
2144 if (platform_driver_register(&stmmacphy_driver)) {
2145 pr_err("No PHY devices registered!\n");
2146 return -ENODEV;
2147 }
2148
2149 ret = platform_driver_register(&stmmac_driver);
2150 return ret;
2151}
2152
2153/**
2154 * stmmac_cleanup_module - Cleanup routine for the driver
2155 * Description: This function is the cleanup routine for the driver.
2156 */
2157static void __exit stmmac_cleanup_module(void)
2158{
2159 platform_driver_unregister(&stmmacphy_driver);
2160 platform_driver_unregister(&stmmac_driver);
2161}
2162
2163#ifndef MODULE
2164static int __init stmmac_cmdline_opt(char *str)
2165{
2166 char *opt;
2167
2168 if (!str || !*str)
2169 return -EINVAL;
2170 while ((opt = strsep(&str, ",")) != NULL) {
2171 if (!strncmp(opt, "debug:", 6))
2172 strict_strtoul(opt + 6, 0, (unsigned long *)&debug);
2173 else if (!strncmp(opt, "phyaddr:", 8))
2174 strict_strtoul(opt + 8, 0, (unsigned long *)&phyaddr);
2175 else if (!strncmp(opt, "dma_txsize:", 11))
2176 strict_strtoul(opt + 11, 0,
2177 (unsigned long *)&dma_txsize);
2178 else if (!strncmp(opt, "dma_rxsize:", 11))
2179 strict_strtoul(opt + 11, 0,
2180 (unsigned long *)&dma_rxsize);
2181 else if (!strncmp(opt, "buf_sz:", 7))
2182 strict_strtoul(opt + 7, 0, (unsigned long *)&buf_sz);
2183 else if (!strncmp(opt, "tc:", 3))
2184 strict_strtoul(opt + 3, 0, (unsigned long *)&tc);
2185 else if (!strncmp(opt, "tx_coe:", 7))
2186 strict_strtoul(opt + 7, 0, (unsigned long *)&tx_coe);
2187 else if (!strncmp(opt, "watchdog:", 9))
2188 strict_strtoul(opt + 9, 0, (unsigned long *)&watchdog);
2189 else if (!strncmp(opt, "flow_ctrl:", 10))
2190 strict_strtoul(opt + 10, 0,
2191 (unsigned long *)&flow_ctrl);
2192 else if (!strncmp(opt, "pause:", 6))
2193 strict_strtoul(opt + 6, 0, (unsigned long *)&pause);
2194#ifdef CONFIG_STMMAC_TIMER
2195 else if (!strncmp(opt, "tmrate:", 7))
2196 strict_strtoul(opt + 7, 0, (unsigned long *)&tmrate);
2197#endif
2198 }
2199 return 0;
2200}
2201
2202__setup("stmmaceth=", stmmac_cmdline_opt);
2203#endif
2204
2205module_init(stmmac_init_module);
2206module_exit(stmmac_cleanup_module);
2207
2208MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet driver");
2209MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
2210MODULE_LICENSE("GPL");
diff --git a/drivers/net/stmmac/stmmac_mdio.c b/drivers/net/stmmac/stmmac_mdio.c
new file mode 100644
index 000000000000..8498552a22fc
--- /dev/null
+++ b/drivers/net/stmmac/stmmac_mdio.c
@@ -0,0 +1,217 @@
1/*******************************************************************************
2 STMMAC Ethernet Driver -- MDIO bus implementation
3 Provides Bus interface for MII registers
4
5 Copyright (C) 2007-2009 STMicroelectronics Ltd
6
7 This program is free software; you can redistribute it and/or modify it
8 under the terms and conditions of the GNU General Public License,
9 version 2, as published by the Free Software Foundation.
10
11 This program is distributed in the hope it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19
20 The full GNU General Public License is included in this distribution in
21 the file called "COPYING".
22
23 Author: Carl Shaw <carl.shaw@st.com>
24 Maintainer: Giuseppe Cavallaro <peppe.cavallaro@st.com>
25*******************************************************************************/
26
27#include <linux/netdevice.h>
28#include <linux/mii.h>
29#include <linux/phy.h>
30
31#include "stmmac.h"
32
33#define MII_BUSY 0x00000001
34#define MII_WRITE 0x00000002
35
36/**
37 * stmmac_mdio_read
38 * @bus: points to the mii_bus structure
39 * @phyaddr: MII addr reg bits 15-11
40 * @phyreg: MII addr reg bits 10-6
41 * Description: it reads data from the MII register from within the phy device.
42 * For the 7111 GMAC, we must set the bit 0 in the MII address register while
43 * accessing the PHY registers.
44 * Fortunately, it seems this has no drawback for the 7109 MAC.
45 */
46static int stmmac_mdio_read(struct mii_bus *bus, int phyaddr, int phyreg)
47{
48 struct net_device *ndev = bus->priv;
49 struct stmmac_priv *priv = netdev_priv(ndev);
50 unsigned long ioaddr = ndev->base_addr;
51 unsigned int mii_address = priv->mac_type->hw.mii.addr;
52 unsigned int mii_data = priv->mac_type->hw.mii.data;
53
54 int data;
55 u16 regValue = (((phyaddr << 11) & (0x0000F800)) |
56 ((phyreg << 6) & (0x000007C0)));
57 regValue |= MII_BUSY; /* in case of GMAC */
58
59 do {} while (((readl(ioaddr + mii_address)) & MII_BUSY) == 1);
60 writel(regValue, ioaddr + mii_address);
61 do {} while (((readl(ioaddr + mii_address)) & MII_BUSY) == 1);
62
63 /* Read the data from the MII data register */
64 data = (int)readl(ioaddr + mii_data);
65
66 return data;
67}
68
69/**
70 * stmmac_mdio_write
71 * @bus: points to the mii_bus structure
72 * @phyaddr: MII addr reg bits 15-11
73 * @phyreg: MII addr reg bits 10-6
74 * @phydata: phy data
75 * Description: it writes the data into the MII register from within the device.
76 */
77static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg,
78 u16 phydata)
79{
80 struct net_device *ndev = bus->priv;
81 struct stmmac_priv *priv = netdev_priv(ndev);
82 unsigned long ioaddr = ndev->base_addr;
83 unsigned int mii_address = priv->mac_type->hw.mii.addr;
84 unsigned int mii_data = priv->mac_type->hw.mii.data;
85
86 u16 value =
87 (((phyaddr << 11) & (0x0000F800)) | ((phyreg << 6) & (0x000007C0)))
88 | MII_WRITE;
89
90 value |= MII_BUSY;
91
92 /* Wait until any existing MII operation is complete */
93 do {} while (((readl(ioaddr + mii_address)) & MII_BUSY) == 1);
94
95 /* Set the MII address register to write */
96 writel(phydata, ioaddr + mii_data);
97 writel(value, ioaddr + mii_address);
98
99 /* Wait until any existing MII operation is complete */
100 do {} while (((readl(ioaddr + mii_address)) & MII_BUSY) == 1);
101
102 return 0;
103}
104
105/**
106 * stmmac_mdio_reset
107 * @bus: points to the mii_bus structure
108 * Description: reset the MII bus
109 */
110static int stmmac_mdio_reset(struct mii_bus *bus)
111{
112 struct net_device *ndev = bus->priv;
113 struct stmmac_priv *priv = netdev_priv(ndev);
114 unsigned long ioaddr = ndev->base_addr;
115 unsigned int mii_address = priv->mac_type->hw.mii.addr;
116
117 if (priv->phy_reset) {
118 pr_debug("stmmac_mdio_reset: calling phy_reset\n");
119 priv->phy_reset(priv->bsp_priv);
120 }
121
122 /* This is a workaround for problems with the STE101P PHY.
123 * It doesn't complete its reset until at least one clock cycle
124 * on MDC, so perform a dummy mdio read.
125 */
126 writel(0, ioaddr + mii_address);
127
128 return 0;
129}
130
131/**
132 * stmmac_mdio_register
133 * @ndev: net device structure
134 * Description: it registers the MII bus
135 */
136int stmmac_mdio_register(struct net_device *ndev)
137{
138 int err = 0;
139 struct mii_bus *new_bus;
140 int *irqlist;
141 struct stmmac_priv *priv = netdev_priv(ndev);
142 int addr, found;
143
144 new_bus = mdiobus_alloc();
145 if (new_bus == NULL)
146 return -ENOMEM;
147
148 irqlist = kzalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
149 if (irqlist == NULL) {
150 err = -ENOMEM;
151 goto irqlist_alloc_fail;
152 }
153
154 /* Assign IRQ to phy at address phy_addr */
155 if (priv->phy_addr != -1)
156 irqlist[priv->phy_addr] = priv->phy_irq;
157
158 new_bus->name = "STMMAC MII Bus";
159 new_bus->read = &stmmac_mdio_read;
160 new_bus->write = &stmmac_mdio_write;
161 new_bus->reset = &stmmac_mdio_reset;
162 snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", priv->bus_id);
163 new_bus->priv = ndev;
164 new_bus->irq = irqlist;
165 new_bus->phy_mask = priv->phy_mask;
166 new_bus->parent = priv->device;
167 err = mdiobus_register(new_bus);
168 if (err != 0) {
169 pr_err("%s: Cannot register as MDIO bus\n", new_bus->name);
170 goto bus_register_fail;
171 }
172
173 priv->mii = new_bus;
174
175 found = 0;
176 for (addr = 0; addr < 32; addr++) {
177 struct phy_device *phydev = new_bus->phy_map[addr];
178 if (phydev) {
179 if (priv->phy_addr == -1) {
180 priv->phy_addr = addr;
181 phydev->irq = priv->phy_irq;
182 irqlist[addr] = priv->phy_irq;
183 }
184 pr_info("%s: PHY ID %08x at %d IRQ %d (%s)%s\n",
185 ndev->name, phydev->phy_id, addr,
186 phydev->irq, dev_name(&phydev->dev),
187 (addr == priv->phy_addr) ? " active" : "");
188 found = 1;
189 }
190 }
191
192 if (!found)
193 pr_warning("%s: No PHY found\n", ndev->name);
194
195 return 0;
196bus_register_fail:
197 kfree(irqlist);
198irqlist_alloc_fail:
199 kfree(new_bus);
200 return err;
201}
202
203/**
204 * stmmac_mdio_unregister
205 * @ndev: net device structure
206 * Description: it unregisters the MII bus
207 */
208int stmmac_mdio_unregister(struct net_device *ndev)
209{
210 struct stmmac_priv *priv = netdev_priv(ndev);
211
212 mdiobus_unregister(priv->mii);
213 priv->mii->priv = NULL;
214 kfree(priv->mii);
215
216 return 0;
217}
diff --git a/drivers/net/stmmac/stmmac_timer.c b/drivers/net/stmmac/stmmac_timer.c
new file mode 100644
index 000000000000..679f61ffb1f8
--- /dev/null
+++ b/drivers/net/stmmac/stmmac_timer.c
@@ -0,0 +1,140 @@
1/*******************************************************************************
2 STMMAC external timer support.
3
4 Copyright (C) 2007-2009 STMicroelectronics Ltd
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23*******************************************************************************/
24
25#include <linux/kernel.h>
26#include <linux/etherdevice.h>
27#include "stmmac_timer.h"
28
29static void stmmac_timer_handler(void *data)
30{
31 struct net_device *dev = (struct net_device *)data;
32
33 stmmac_schedule(dev);
34
35 return;
36}
37
38#define STMMAC_TIMER_MSG(timer, freq) \
39printk(KERN_INFO "stmmac_timer: %s Timer ON (freq %dHz)\n", timer, freq);
40
41#if defined(CONFIG_STMMAC_RTC_TIMER)
42#include <linux/rtc.h>
43static struct rtc_device *stmmac_rtc;
44static rtc_task_t stmmac_task;
45
46static void stmmac_rtc_start(unsigned int new_freq)
47{
48 rtc_irq_set_freq(stmmac_rtc, &stmmac_task, new_freq);
49 rtc_irq_set_state(stmmac_rtc, &stmmac_task, 1);
50 return;
51}
52
53static void stmmac_rtc_stop(void)
54{
55 rtc_irq_set_state(stmmac_rtc, &stmmac_task, 0);
56 return;
57}
58
59int stmmac_open_ext_timer(struct net_device *dev, struct stmmac_timer *tm)
60{
61 stmmac_task.private_data = dev;
62 stmmac_task.func = stmmac_timer_handler;
63
64 stmmac_rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
65 if (stmmac_rtc == NULL) {
66 pr_err("open rtc device failed\n");
67 return -ENODEV;
68 }
69
70 rtc_irq_register(stmmac_rtc, &stmmac_task);
71
72 /* Periodic mode is not supported */
73 if ((rtc_irq_set_freq(stmmac_rtc, &stmmac_task, tm->freq) < 0)) {
74 pr_err("set periodic failed\n");
75 rtc_irq_unregister(stmmac_rtc, &stmmac_task);
76 rtc_class_close(stmmac_rtc);
77 return -1;
78 }
79
80 STMMAC_TIMER_MSG(CONFIG_RTC_HCTOSYS_DEVICE, tm->freq);
81
82 tm->timer_start = stmmac_rtc_start;
83 tm->timer_stop = stmmac_rtc_stop;
84
85 return 0;
86}
87
88int stmmac_close_ext_timer(void)
89{
90 rtc_irq_set_state(stmmac_rtc, &stmmac_task, 0);
91 rtc_irq_unregister(stmmac_rtc, &stmmac_task);
92 rtc_class_close(stmmac_rtc);
93 return 0;
94}
95
96#elif defined(CONFIG_STMMAC_TMU_TIMER)
97#include <linux/clk.h>
98#define TMU_CHANNEL "tmu2_clk"
99static struct clk *timer_clock;
100
101static void stmmac_tmu_start(unsigned int new_freq)
102{
103 clk_set_rate(timer_clock, new_freq);
104 clk_enable(timer_clock);
105 return;
106}
107
108static void stmmac_tmu_stop(void)
109{
110 clk_disable(timer_clock);
111 return;
112}
113
114int stmmac_open_ext_timer(struct net_device *dev, struct stmmac_timer *tm)
115{
116 timer_clock = clk_get(NULL, TMU_CHANNEL);
117
118 if (timer_clock == NULL)
119 return -1;
120
121 if (tmu2_register_user(stmmac_timer_handler, (void *)dev) < 0) {
122 timer_clock = NULL;
123 return -1;
124 }
125
126 STMMAC_TIMER_MSG("TMU2", tm->freq);
127 tm->timer_start = stmmac_tmu_start;
128 tm->timer_stop = stmmac_tmu_stop;
129
130 return 0;
131}
132
133int stmmac_close_ext_timer(void)
134{
135 clk_disable(timer_clock);
136 tmu2_unregister_user();
137 clk_put(timer_clock);
138 return 0;
139}
140#endif
diff --git a/drivers/net/stmmac/stmmac_timer.h b/drivers/net/stmmac/stmmac_timer.h
new file mode 100644
index 000000000000..6863590d184b
--- /dev/null
+++ b/drivers/net/stmmac/stmmac_timer.h
@@ -0,0 +1,42 @@
1/*******************************************************************************
2 STMMAC external timer Header File.
3
4 Copyright (C) 2007-2009 STMicroelectronics Ltd
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23*******************************************************************************/
24
25struct stmmac_timer {
26 void (*timer_start) (unsigned int new_freq);
27 void (*timer_stop) (void);
28 unsigned int freq;
29 unsigned int enable;
30};
31
32/* Open the HW timer device and return 0 in case of success */
33int stmmac_open_ext_timer(struct net_device *dev, struct stmmac_timer *tm);
34/* Stop the timer and release it */
35int stmmac_close_ext_timer(void);
36/* Function used for scheduling task within the stmmac */
37void stmmac_schedule(struct net_device *dev);
38
39#if defined(CONFIG_STMMAC_TMU_TIMER)
40extern int tmu2_register_user(void *fnt, void *data);
41extern void tmu2_unregister_user(void);
42#endif
diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c
index 7019a0d1a82b..61640b99b705 100644
--- a/drivers/net/sungem.c
+++ b/drivers/net/sungem.c
@@ -2063,7 +2063,15 @@ static int gem_check_invariants(struct gem *gp)
2063 mif_cfg &= ~MIF_CFG_PSELECT; 2063 mif_cfg &= ~MIF_CFG_PSELECT;
2064 writel(mif_cfg, gp->regs + MIF_CFG); 2064 writel(mif_cfg, gp->regs + MIF_CFG);
2065 } else { 2065 } else {
2066 gp->phy_type = phy_serialink; 2066#ifdef CONFIG_SPARC
2067 const char *p;
2068
2069 p = of_get_property(gp->of_node, "shared-pins", NULL);
2070 if (p && !strcmp(p, "serdes"))
2071 gp->phy_type = phy_serdes;
2072 else
2073#endif
2074 gp->phy_type = phy_serialink;
2067 } 2075 }
2068 if (gp->phy_type == phy_mii_mdio1 || 2076 if (gp->phy_type == phy_mii_mdio1 ||
2069 gp->phy_type == phy_mii_mdio0) { 2077 gp->phy_type == phy_mii_mdio0) {
diff --git a/drivers/net/tokenring/ibmtr.c b/drivers/net/tokenring/ibmtr.c
index 36cb2423bcf1..75fa32e34fd0 100644
--- a/drivers/net/tokenring/ibmtr.c
+++ b/drivers/net/tokenring/ibmtr.c
@@ -1144,9 +1144,16 @@ static void dir_open_adapter (struct net_device *dev)
1144 } else { 1144 } else {
1145 char **prphase = printphase; 1145 char **prphase = printphase;
1146 char **prerror = printerror; 1146 char **prerror = printerror;
1147 int pnr = err / 16 - 1;
1148 int enr = err % 16 - 1;
1147 DPRINTK("TR Adapter misc open failure, error code = "); 1149 DPRINTK("TR Adapter misc open failure, error code = ");
1148 printk("0x%x, Phase: %s, Error: %s\n", 1150 if (pnr < 0 || pnr >= ARRAY_SIZE(printphase) ||
1149 err, prphase[err/16 -1], prerror[err%16 -1]); 1151 enr < 0 ||
1152 enr >= ARRAY_SIZE(printerror))
1153 printk("0x%x, invalid Phase/Error.", err);
1154 else
1155 printk("0x%x, Phase: %s, Error: %s\n", err,
1156 prphase[pnr], prerror[enr]);
1150 printk(" retrying after %ds delay...\n", 1157 printk(" retrying after %ds delay...\n",
1151 TR_RETRY_INTERVAL/HZ); 1158 TR_RETRY_INTERVAL/HZ);
1152 } 1159 }
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index c47237c2d638..32d93564a74d 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -174,7 +174,7 @@ config USB_NET_CDCETHER
174 * Ericsson Mobile Broadband Module (all variants) 174 * Ericsson Mobile Broadband Module (all variants)
175 * Motorola (DM100 and SB4100) 175 * Motorola (DM100 and SB4100)
176 * Broadcom Cable Modem (reference design) 176 * Broadcom Cable Modem (reference design)
177 * Toshiba (PCX1100U and F3507g) 177 * Toshiba (PCX1100U and F3507g/F3607gw)
178 * ... 178 * ...
179 179
180 This driver creates an interface named "ethX", where X depends on 180 This driver creates an interface named "ethX", where X depends on
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index 4a6aff579403..21e1ba160008 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -544,20 +544,60 @@ static const struct usb_device_id products [] = {
544 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE), 544 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
545 .driver_info = (unsigned long) &cdc_info, 545 .driver_info = (unsigned long) &cdc_info,
546}, { 546}, {
547 /* Ericsson F3307 */ 547 /* Ericsson F3607gw ver 2 */
548 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1905, USB_CLASS_COMM,
549 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
550 .driver_info = (unsigned long) &cdc_info,
551}, {
552 /* Ericsson F3607gw ver 3 */
548 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1906, USB_CLASS_COMM, 553 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1906, USB_CLASS_COMM,
549 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE), 554 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
550 .driver_info = (unsigned long) &cdc_info, 555 .driver_info = (unsigned long) &cdc_info,
551}, { 556}, {
557 /* Ericsson F3307 */
558 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x190a, USB_CLASS_COMM,
559 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
560 .driver_info = (unsigned long) &cdc_info,
561}, {
562 /* Ericsson F3307 ver 2 */
563 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1909, USB_CLASS_COMM,
564 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
565 .driver_info = (unsigned long) &cdc_info,
566}, {
567 /* Ericsson C3607w */
568 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1049, USB_CLASS_COMM,
569 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
570 .driver_info = (unsigned long) &cdc_info,
571}, {
552 /* Toshiba F3507g */ 572 /* Toshiba F3507g */
553 USB_DEVICE_AND_INTERFACE_INFO(0x0930, 0x130b, USB_CLASS_COMM, 573 USB_DEVICE_AND_INTERFACE_INFO(0x0930, 0x130b, USB_CLASS_COMM,
554 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE), 574 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
555 .driver_info = (unsigned long) &cdc_info, 575 .driver_info = (unsigned long) &cdc_info,
556}, { 576}, {
577 /* Toshiba F3607gw */
578 USB_DEVICE_AND_INTERFACE_INFO(0x0930, 0x130c, USB_CLASS_COMM,
579 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
580 .driver_info = (unsigned long) &cdc_info,
581}, {
582 /* Toshiba F3607gw ver 2 */
583 USB_DEVICE_AND_INTERFACE_INFO(0x0930, 0x1311, USB_CLASS_COMM,
584 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
585 .driver_info = (unsigned long) &cdc_info,
586}, {
557 /* Dell F3507g */ 587 /* Dell F3507g */
558 USB_DEVICE_AND_INTERFACE_INFO(0x413c, 0x8147, USB_CLASS_COMM, 588 USB_DEVICE_AND_INTERFACE_INFO(0x413c, 0x8147, USB_CLASS_COMM,
559 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE), 589 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
560 .driver_info = (unsigned long) &cdc_info, 590 .driver_info = (unsigned long) &cdc_info,
591}, {
592 /* Dell F3607gw */
593 USB_DEVICE_AND_INTERFACE_INFO(0x413c, 0x8183, USB_CLASS_COMM,
594 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
595 .driver_info = (unsigned long) &cdc_info,
596}, {
597 /* Dell F3607gw ver 2 */
598 USB_DEVICE_AND_INTERFACE_INFO(0x413c, 0x8184, USB_CLASS_COMM,
599 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
600 .driver_info = (unsigned long) &cdc_info,
561}, 601},
562 { }, // END 602 { }, // END
563}; 603};
diff --git a/drivers/net/usb/dm9601.c b/drivers/net/usb/dm9601.c
index 72470f77f556..a2b30a10064f 100644
--- a/drivers/net/usb/dm9601.c
+++ b/drivers/net/usb/dm9601.c
@@ -649,6 +649,10 @@ static const struct usb_device_id products[] = {
649 USB_DEVICE(0x0fe6, 0x8101), /* DM9601 USB to Fast Ethernet Adapter */ 649 USB_DEVICE(0x0fe6, 0x8101), /* DM9601 USB to Fast Ethernet Adapter */
650 .driver_info = (unsigned long)&dm9601_info, 650 .driver_info = (unsigned long)&dm9601_info,
651 }, 651 },
652 {
653 USB_DEVICE(0x0a46, 0x9000), /* DM9000E */
654 .driver_info = (unsigned long)&dm9601_info,
655 },
652 {}, // END 656 {}, // END
653}; 657};
654 658
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index fa4e58196c21..43bc3fcc0d85 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -378,7 +378,7 @@ static void dbg_dump(int line_count, const char *func_name, unsigned char *buf,
378} 378}
379 379
380#define DUMP(buf_, len_) \ 380#define DUMP(buf_, len_) \
381 dbg_dump(__LINE__, __func__, buf_, len_) 381 dbg_dump(__LINE__, __func__, (unsigned char *)buf_, len_)
382 382
383#define DUMP1(buf_, len_) \ 383#define DUMP1(buf_, len_) \
384 do { \ 384 do { \
@@ -1363,7 +1363,7 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
1363 /* reset the rts and dtr */ 1363 /* reset the rts and dtr */
1364 /* do the actual close */ 1364 /* do the actual close */
1365 serial->open_count--; 1365 serial->open_count--;
1366 kref_put(&serial->parent->ref, hso_serial_ref_free); 1366
1367 if (serial->open_count <= 0) { 1367 if (serial->open_count <= 0) {
1368 serial->open_count = 0; 1368 serial->open_count = 0;
1369 spin_lock_irq(&serial->serial_lock); 1369 spin_lock_irq(&serial->serial_lock);
@@ -1383,6 +1383,8 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
1383 usb_autopm_put_interface(serial->parent->interface); 1383 usb_autopm_put_interface(serial->parent->interface);
1384 1384
1385 mutex_unlock(&serial->parent->mutex); 1385 mutex_unlock(&serial->parent->mutex);
1386
1387 kref_put(&serial->parent->ref, hso_serial_ref_free);
1386} 1388}
1387 1389
1388/* close the requested serial port */ 1390/* close the requested serial port */
@@ -1527,7 +1529,7 @@ static void tiocmget_intr_callback(struct urb *urb)
1527 dev_warn(&usb->dev, 1529 dev_warn(&usb->dev,
1528 "hso received invalid serial state notification\n"); 1530 "hso received invalid serial state notification\n");
1529 DUMP(serial_state_notification, 1531 DUMP(serial_state_notification,
1530 sizeof(hso_serial_state_notifation)) 1532 sizeof(struct hso_serial_state_notification));
1531 } else { 1533 } else {
1532 1534
1533 UART_state_bitmap = le16_to_cpu(serial_state_notification-> 1535 UART_state_bitmap = le16_to_cpu(serial_state_notification->
diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c
index 6fdaba8674b9..ed4a508ef262 100644
--- a/drivers/net/usb/pegasus.c
+++ b/drivers/net/usb/pegasus.c
@@ -62,8 +62,11 @@ static char *devid=NULL;
62static struct usb_eth_dev usb_dev_id[] = { 62static struct usb_eth_dev usb_dev_id[] = {
63#define PEGASUS_DEV(pn, vid, pid, flags) \ 63#define PEGASUS_DEV(pn, vid, pid, flags) \
64 {.name = pn, .vendor = vid, .device = pid, .private = flags}, 64 {.name = pn, .vendor = vid, .device = pid, .private = flags},
65#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
66 PEGASUS_DEV(pn, vid, pid, flags)
65#include "pegasus.h" 67#include "pegasus.h"
66#undef PEGASUS_DEV 68#undef PEGASUS_DEV
69#undef PEGASUS_DEV_CLASS
67 {NULL, 0, 0, 0}, 70 {NULL, 0, 0, 0},
68 {NULL, 0, 0, 0} 71 {NULL, 0, 0, 0}
69}; 72};
@@ -71,8 +74,18 @@ static struct usb_eth_dev usb_dev_id[] = {
71static struct usb_device_id pegasus_ids[] = { 74static struct usb_device_id pegasus_ids[] = {
72#define PEGASUS_DEV(pn, vid, pid, flags) \ 75#define PEGASUS_DEV(pn, vid, pid, flags) \
73 {.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid}, 76 {.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid},
77/*
78 * The Belkin F8T012xx1 bluetooth adaptor has the same vendor and product
79 * IDs as the Belkin F5D5050, so we need to teach the pegasus driver to
80 * ignore adaptors belonging to the "Wireless" class 0xE0. For this one
81 * case anyway, seeing as the pegasus is for "Wired" adaptors.
82 */
83#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
84 {.match_flags = (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS), \
85 .idVendor = vid, .idProduct = pid, .bDeviceClass = dclass},
74#include "pegasus.h" 86#include "pegasus.h"
75#undef PEGASUS_DEV 87#undef PEGASUS_DEV
88#undef PEGASUS_DEV_CLASS
76 {}, 89 {},
77 {} 90 {}
78}; 91};
diff --git a/drivers/net/usb/pegasus.h b/drivers/net/usb/pegasus.h
index f968c834ff63..5d02f0200737 100644
--- a/drivers/net/usb/pegasus.h
+++ b/drivers/net/usb/pegasus.h
@@ -202,7 +202,11 @@ PEGASUS_DEV( "AEI USB Fast Ethernet Adapter", VENDOR_AEILAB, 0x1701,
202 DEFAULT_GPIO_RESET | PEGASUS_II ) 202 DEFAULT_GPIO_RESET | PEGASUS_II )
203PEGASUS_DEV( "Allied Telesyn Int. AT-USB100", VENDOR_ALLIEDTEL, 0xb100, 203PEGASUS_DEV( "Allied Telesyn Int. AT-USB100", VENDOR_ALLIEDTEL, 0xb100,
204 DEFAULT_GPIO_RESET | PEGASUS_II ) 204 DEFAULT_GPIO_RESET | PEGASUS_II )
205PEGASUS_DEV( "Belkin F5D5050 USB Ethernet", VENDOR_BELKIN, 0x0121, 205/*
206 * Distinguish between this Belkin adaptor and the Belkin bluetooth adaptors
207 * with the same product IDs by checking the device class too.
208 */
209PEGASUS_DEV_CLASS( "Belkin F5D5050 USB Ethernet", VENDOR_BELKIN, 0x0121, 0x00,
206 DEFAULT_GPIO_RESET | PEGASUS_II ) 210 DEFAULT_GPIO_RESET | PEGASUS_II )
207PEGASUS_DEV( "Billionton USB-100", VENDOR_BILLIONTON, 0x0986, 211PEGASUS_DEV( "Billionton USB-100", VENDOR_BILLIONTON, 0x0986,
208 DEFAULT_GPIO_RESET ) 212 DEFAULT_GPIO_RESET )
diff --git a/drivers/net/usb/rndis_host.c b/drivers/net/usb/rndis_host.c
index 0caa8008c51c..f56dec6119c3 100644
--- a/drivers/net/usb/rndis_host.c
+++ b/drivers/net/usb/rndis_host.c
@@ -362,12 +362,12 @@ generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf, int flags)
362 retval = -EINVAL; 362 retval = -EINVAL;
363 goto halt_fail_and_release; 363 goto halt_fail_and_release;
364 } 364 }
365 dev->hard_mtu = tmp;
366 net->mtu = dev->hard_mtu - net->hard_header_len;
367 dev_warn(&intf->dev, 365 dev_warn(&intf->dev,
368 "dev can't take %u byte packets (max %u), " 366 "dev can't take %u byte packets (max %u), "
369 "adjusting MTU to %u\n", 367 "adjusting MTU to %u\n",
370 dev->hard_mtu, tmp, net->mtu); 368 dev->hard_mtu, tmp, tmp - net->hard_header_len);
369 dev->hard_mtu = tmp;
370 net->mtu = dev->hard_mtu - net->hard_header_len;
371 } 371 }
372 372
373 /* REVISIT: peripheral "alignment" request is ignored ... */ 373 /* REVISIT: peripheral "alignment" request is ignored ... */
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index ade5b344f75d..52af5017c46b 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -210,32 +210,29 @@ rx_drop:
210static struct net_device_stats *veth_get_stats(struct net_device *dev) 210static struct net_device_stats *veth_get_stats(struct net_device *dev)
211{ 211{
212 struct veth_priv *priv; 212 struct veth_priv *priv;
213 struct net_device_stats *dev_stats;
214 int cpu; 213 int cpu;
215 struct veth_net_stats *stats; 214 struct veth_net_stats *stats, total = {0};
216 215
217 priv = netdev_priv(dev); 216 priv = netdev_priv(dev);
218 dev_stats = &dev->stats;
219
220 dev_stats->rx_packets = 0;
221 dev_stats->tx_packets = 0;
222 dev_stats->rx_bytes = 0;
223 dev_stats->tx_bytes = 0;
224 dev_stats->tx_dropped = 0;
225 dev_stats->rx_dropped = 0;
226 217
227 for_each_online_cpu(cpu) { 218 for_each_possible_cpu(cpu) {
228 stats = per_cpu_ptr(priv->stats, cpu); 219 stats = per_cpu_ptr(priv->stats, cpu);
229 220
230 dev_stats->rx_packets += stats->rx_packets; 221 total.rx_packets += stats->rx_packets;
231 dev_stats->tx_packets += stats->tx_packets; 222 total.tx_packets += stats->tx_packets;
232 dev_stats->rx_bytes += stats->rx_bytes; 223 total.rx_bytes += stats->rx_bytes;
233 dev_stats->tx_bytes += stats->tx_bytes; 224 total.tx_bytes += stats->tx_bytes;
234 dev_stats->tx_dropped += stats->tx_dropped; 225 total.tx_dropped += stats->tx_dropped;
235 dev_stats->rx_dropped += stats->rx_dropped; 226 total.rx_dropped += stats->rx_dropped;
236 } 227 }
237 228 dev->stats.rx_packets = total.rx_packets;
238 return dev_stats; 229 dev->stats.tx_packets = total.tx_packets;
230 dev->stats.rx_bytes = total.rx_bytes;
231 dev->stats.tx_bytes = total.tx_bytes;
232 dev->stats.tx_dropped = total.tx_dropped;
233 dev->stats.rx_dropped = total.rx_dropped;
234
235 return &dev->stats;
239} 236}
240 237
241static int veth_open(struct net_device *dev) 238static int veth_open(struct net_device *dev)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 8d009760277c..b9e002fccbca 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -22,7 +22,6 @@
22#include <linux/ethtool.h> 22#include <linux/ethtool.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/virtio.h> 24#include <linux/virtio.h>
25#include <linux/virtio_ids.h>
26#include <linux/virtio_net.h> 25#include <linux/virtio_net.h>
27#include <linux/scatterlist.h> 26#include <linux/scatterlist.h>
28#include <linux/if_vlan.h> 27#include <linux/if_vlan.h>
@@ -454,7 +453,7 @@ static unsigned int free_old_xmit_skbs(struct virtnet_info *vi)
454 vi->dev->stats.tx_bytes += skb->len; 453 vi->dev->stats.tx_bytes += skb->len;
455 vi->dev->stats.tx_packets++; 454 vi->dev->stats.tx_packets++;
456 tot_sgs += skb_vnet_hdr(skb)->num_sg; 455 tot_sgs += skb_vnet_hdr(skb)->num_sg;
457 kfree_skb(skb); 456 dev_kfree_skb_any(skb);
458 } 457 }
459 return tot_sgs; 458 return tot_sgs;
460} 459}
@@ -517,8 +516,7 @@ again:
517 /* Free up any pending old buffers before queueing new ones. */ 516 /* Free up any pending old buffers before queueing new ones. */
518 free_old_xmit_skbs(vi); 517 free_old_xmit_skbs(vi);
519 518
520 /* Put new one in send queue and do transmit */ 519 /* Try to transmit */
521 __skb_queue_head(&vi->send, skb);
522 capacity = xmit_skb(vi, skb); 520 capacity = xmit_skb(vi, skb);
523 521
524 /* This can happen with OOM and indirect buffers. */ 522 /* This can happen with OOM and indirect buffers. */
@@ -532,8 +530,17 @@ again:
532 } 530 }
533 return NETDEV_TX_BUSY; 531 return NETDEV_TX_BUSY;
534 } 532 }
535
536 vi->svq->vq_ops->kick(vi->svq); 533 vi->svq->vq_ops->kick(vi->svq);
534
535 /*
536 * Put new one in send queue. You'd expect we'd need this before
537 * xmit_skb calls add_buf(), since the callback can be triggered
538 * immediately after that. But since the callback just triggers
539 * another call back here, normal network xmit locking prevents the
540 * race.
541 */
542 __skb_queue_head(&vi->send, skb);
543
537 /* Don't wait up for transmitted skbs to be freed. */ 544 /* Don't wait up for transmitted skbs to be freed. */
538 skb_orphan(skb); 545 skb_orphan(skb);
539 nf_reset(skb); 546 nf_reset(skb);
@@ -991,7 +998,7 @@ static unsigned int features[] = {
991 VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN, 998 VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN,
992}; 999};
993 1000
994static struct virtio_driver virtio_net = { 1001static struct virtio_driver virtio_net_driver = {
995 .feature_table = features, 1002 .feature_table = features,
996 .feature_table_size = ARRAY_SIZE(features), 1003 .feature_table_size = ARRAY_SIZE(features),
997 .driver.name = KBUILD_MODNAME, 1004 .driver.name = KBUILD_MODNAME,
@@ -1004,12 +1011,12 @@ static struct virtio_driver virtio_net = {
1004 1011
1005static int __init init(void) 1012static int __init init(void)
1006{ 1013{
1007 return register_virtio_driver(&virtio_net); 1014 return register_virtio_driver(&virtio_net_driver);
1008} 1015}
1009 1016
1010static void __exit fini(void) 1017static void __exit fini(void)
1011{ 1018{
1012 unregister_virtio_driver(&virtio_net); 1019 unregister_virtio_driver(&virtio_net_driver);
1013} 1020}
1014module_init(init); 1021module_init(init);
1015module_exit(fini); 1022module_exit(fini);
diff --git a/drivers/net/vmxnet3/Makefile b/drivers/net/vmxnet3/Makefile
new file mode 100644
index 000000000000..880f5098eac9
--- /dev/null
+++ b/drivers/net/vmxnet3/Makefile
@@ -0,0 +1,35 @@
1################################################################################
2#
3# Linux driver for VMware's vmxnet3 ethernet NIC.
4#
5# Copyright (C) 2007-2009, VMware, Inc. All Rights Reserved.
6#
7# This program is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by the
9# Free Software Foundation; version 2 of the License and no later version.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14# NON INFRINGEMENT. See the GNU General Public License for more
15# details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# The full GNU General Public License is included in this distribution in
22# the file called "COPYING".
23#
24# Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
25#
26#
27################################################################################
28
29#
30# Makefile for the VMware vmxnet3 ethernet NIC driver
31#
32
33obj-$(CONFIG_VMXNET3) += vmxnet3.o
34
35vmxnet3-objs := vmxnet3_drv.o vmxnet3_ethtool.o
diff --git a/drivers/net/vmxnet3/upt1_defs.h b/drivers/net/vmxnet3/upt1_defs.h
new file mode 100644
index 000000000000..37108fb226d3
--- /dev/null
+++ b/drivers/net/vmxnet3/upt1_defs.h
@@ -0,0 +1,96 @@
1/*
2 * Linux driver for VMware's vmxnet3 ethernet NIC.
3 *
4 * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License and no later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * The full GNU General Public License is included in this distribution in
21 * the file called "COPYING".
22 *
23 * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
24 *
25 */
26
27#ifndef _UPT1_DEFS_H
28#define _UPT1_DEFS_H
29
30struct UPT1_TxStats {
31 u64 TSOPktsTxOK; /* TSO pkts post-segmentation */
32 u64 TSOBytesTxOK;
33 u64 ucastPktsTxOK;
34 u64 ucastBytesTxOK;
35 u64 mcastPktsTxOK;
36 u64 mcastBytesTxOK;
37 u64 bcastPktsTxOK;
38 u64 bcastBytesTxOK;
39 u64 pktsTxError;
40 u64 pktsTxDiscard;
41};
42
43struct UPT1_RxStats {
44 u64 LROPktsRxOK; /* LRO pkts */
45 u64 LROBytesRxOK; /* bytes from LRO pkts */
46 /* the following counters are for pkts from the wire, i.e., pre-LRO */
47 u64 ucastPktsRxOK;
48 u64 ucastBytesRxOK;
49 u64 mcastPktsRxOK;
50 u64 mcastBytesRxOK;
51 u64 bcastPktsRxOK;
52 u64 bcastBytesRxOK;
53 u64 pktsRxOutOfBuf;
54 u64 pktsRxError;
55};
56
57/* interrupt moderation level */
58enum {
59 UPT1_IML_NONE = 0, /* no interrupt moderation */
60 UPT1_IML_HIGHEST = 7, /* least intr generated */
61 UPT1_IML_ADAPTIVE = 8, /* adpative intr moderation */
62};
63/* values for UPT1_RSSConf.hashFunc */
64enum {
65 UPT1_RSS_HASH_TYPE_NONE = 0x0,
66 UPT1_RSS_HASH_TYPE_IPV4 = 0x01,
67 UPT1_RSS_HASH_TYPE_TCP_IPV4 = 0x02,
68 UPT1_RSS_HASH_TYPE_IPV6 = 0x04,
69 UPT1_RSS_HASH_TYPE_TCP_IPV6 = 0x08,
70};
71
72enum {
73 UPT1_RSS_HASH_FUNC_NONE = 0x0,
74 UPT1_RSS_HASH_FUNC_TOEPLITZ = 0x01,
75};
76
77#define UPT1_RSS_MAX_KEY_SIZE 40
78#define UPT1_RSS_MAX_IND_TABLE_SIZE 128
79
80struct UPT1_RSSConf {
81 u16 hashType;
82 u16 hashFunc;
83 u16 hashKeySize;
84 u16 indTableSize;
85 u8 hashKey[UPT1_RSS_MAX_KEY_SIZE];
86 u8 indTable[UPT1_RSS_MAX_IND_TABLE_SIZE];
87};
88
89/* features */
90enum {
91 UPT1_F_RXCSUM = 0x0001, /* rx csum verification */
92 UPT1_F_RSS = 0x0002,
93 UPT1_F_RXVLAN = 0x0004, /* VLAN tag stripping */
94 UPT1_F_LRO = 0x0008,
95};
96#endif
diff --git a/drivers/net/vmxnet3/vmxnet3_defs.h b/drivers/net/vmxnet3/vmxnet3_defs.h
new file mode 100644
index 000000000000..dc8ee4438a4f
--- /dev/null
+++ b/drivers/net/vmxnet3/vmxnet3_defs.h
@@ -0,0 +1,535 @@
1/*
2 * Linux driver for VMware's vmxnet3 ethernet NIC.
3 *
4 * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License and no later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * The full GNU General Public License is included in this distribution in
21 * the file called "COPYING".
22 *
23 * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
24 *
25 */
26
27#ifndef _VMXNET3_DEFS_H_
28#define _VMXNET3_DEFS_H_
29
30#include "upt1_defs.h"
31
32/* all registers are 32 bit wide */
33/* BAR 1 */
34enum {
35 VMXNET3_REG_VRRS = 0x0, /* Vmxnet3 Revision Report Selection */
36 VMXNET3_REG_UVRS = 0x8, /* UPT Version Report Selection */
37 VMXNET3_REG_DSAL = 0x10, /* Driver Shared Address Low */
38 VMXNET3_REG_DSAH = 0x18, /* Driver Shared Address High */
39 VMXNET3_REG_CMD = 0x20, /* Command */
40 VMXNET3_REG_MACL = 0x28, /* MAC Address Low */
41 VMXNET3_REG_MACH = 0x30, /* MAC Address High */
42 VMXNET3_REG_ICR = 0x38, /* Interrupt Cause Register */
43 VMXNET3_REG_ECR = 0x40 /* Event Cause Register */
44};
45
46/* BAR 0 */
47enum {
48 VMXNET3_REG_IMR = 0x0, /* Interrupt Mask Register */
49 VMXNET3_REG_TXPROD = 0x600, /* Tx Producer Index */
50 VMXNET3_REG_RXPROD = 0x800, /* Rx Producer Index for ring 1 */
51 VMXNET3_REG_RXPROD2 = 0xA00 /* Rx Producer Index for ring 2 */
52};
53
54#define VMXNET3_PT_REG_SIZE 4096 /* BAR 0 */
55#define VMXNET3_VD_REG_SIZE 4096 /* BAR 1 */
56
57#define VMXNET3_REG_ALIGN 8 /* All registers are 8-byte aligned. */
58#define VMXNET3_REG_ALIGN_MASK 0x7
59
60/* I/O Mapped access to registers */
61#define VMXNET3_IO_TYPE_PT 0
62#define VMXNET3_IO_TYPE_VD 1
63#define VMXNET3_IO_ADDR(type, reg) (((type) << 24) | ((reg) & 0xFFFFFF))
64#define VMXNET3_IO_TYPE(addr) ((addr) >> 24)
65#define VMXNET3_IO_REG(addr) ((addr) & 0xFFFFFF)
66
67enum {
68 VMXNET3_CMD_FIRST_SET = 0xCAFE0000,
69 VMXNET3_CMD_ACTIVATE_DEV = VMXNET3_CMD_FIRST_SET,
70 VMXNET3_CMD_QUIESCE_DEV,
71 VMXNET3_CMD_RESET_DEV,
72 VMXNET3_CMD_UPDATE_RX_MODE,
73 VMXNET3_CMD_UPDATE_MAC_FILTERS,
74 VMXNET3_CMD_UPDATE_VLAN_FILTERS,
75 VMXNET3_CMD_UPDATE_RSSIDT,
76 VMXNET3_CMD_UPDATE_IML,
77 VMXNET3_CMD_UPDATE_PMCFG,
78 VMXNET3_CMD_UPDATE_FEATURE,
79 VMXNET3_CMD_LOAD_PLUGIN,
80
81 VMXNET3_CMD_FIRST_GET = 0xF00D0000,
82 VMXNET3_CMD_GET_QUEUE_STATUS = VMXNET3_CMD_FIRST_GET,
83 VMXNET3_CMD_GET_STATS,
84 VMXNET3_CMD_GET_LINK,
85 VMXNET3_CMD_GET_PERM_MAC_LO,
86 VMXNET3_CMD_GET_PERM_MAC_HI,
87 VMXNET3_CMD_GET_DID_LO,
88 VMXNET3_CMD_GET_DID_HI,
89 VMXNET3_CMD_GET_DEV_EXTRA_INFO,
90 VMXNET3_CMD_GET_CONF_INTR
91};
92
93struct Vmxnet3_TxDesc {
94 u64 addr;
95
96 u32 len:14;
97 u32 gen:1; /* generation bit */
98 u32 rsvd:1;
99 u32 dtype:1; /* descriptor type */
100 u32 ext1:1;
101 u32 msscof:14; /* MSS, checksum offset, flags */
102
103 u32 hlen:10; /* header len */
104 u32 om:2; /* offload mode */
105 u32 eop:1; /* End Of Packet */
106 u32 cq:1; /* completion request */
107 u32 ext2:1;
108 u32 ti:1; /* VLAN Tag Insertion */
109 u32 tci:16; /* Tag to Insert */
110};
111
112/* TxDesc.OM values */
113#define VMXNET3_OM_NONE 0
114#define VMXNET3_OM_CSUM 2
115#define VMXNET3_OM_TSO 3
116
117/* fields in TxDesc we access w/o using bit fields */
118#define VMXNET3_TXD_EOP_SHIFT 12
119#define VMXNET3_TXD_CQ_SHIFT 13
120#define VMXNET3_TXD_GEN_SHIFT 14
121
122#define VMXNET3_TXD_CQ (1 << VMXNET3_TXD_CQ_SHIFT)
123#define VMXNET3_TXD_EOP (1 << VMXNET3_TXD_EOP_SHIFT)
124#define VMXNET3_TXD_GEN (1 << VMXNET3_TXD_GEN_SHIFT)
125
126#define VMXNET3_HDR_COPY_SIZE 128
127
128
129struct Vmxnet3_TxDataDesc {
130 u8 data[VMXNET3_HDR_COPY_SIZE];
131};
132
133
134struct Vmxnet3_TxCompDesc {
135 u32 txdIdx:12; /* Index of the EOP TxDesc */
136 u32 ext1:20;
137
138 u32 ext2;
139 u32 ext3;
140
141 u32 rsvd:24;
142 u32 type:7; /* completion type */
143 u32 gen:1; /* generation bit */
144};
145
146
147struct Vmxnet3_RxDesc {
148 u64 addr;
149
150 u32 len:14;
151 u32 btype:1; /* Buffer Type */
152 u32 dtype:1; /* Descriptor type */
153 u32 rsvd:15;
154 u32 gen:1; /* Generation bit */
155
156 u32 ext1;
157};
158
159/* values of RXD.BTYPE */
160#define VMXNET3_RXD_BTYPE_HEAD 0 /* head only */
161#define VMXNET3_RXD_BTYPE_BODY 1 /* body only */
162
163/* fields in RxDesc we access w/o using bit fields */
164#define VMXNET3_RXD_BTYPE_SHIFT 14
165#define VMXNET3_RXD_GEN_SHIFT 31
166
167
168struct Vmxnet3_RxCompDesc {
169 u32 rxdIdx:12; /* Index of the RxDesc */
170 u32 ext1:2;
171 u32 eop:1; /* End of Packet */
172 u32 sop:1; /* Start of Packet */
173 u32 rqID:10; /* rx queue/ring ID */
174 u32 rssType:4; /* RSS hash type used */
175 u32 cnc:1; /* Checksum Not Calculated */
176 u32 ext2:1;
177
178 u32 rssHash; /* RSS hash value */
179
180 u32 len:14; /* data length */
181 u32 err:1; /* Error */
182 u32 ts:1; /* Tag is stripped */
183 u32 tci:16; /* Tag stripped */
184
185 u32 csum:16;
186 u32 tuc:1; /* TCP/UDP Checksum Correct */
187 u32 udp:1; /* UDP packet */
188 u32 tcp:1; /* TCP packet */
189 u32 ipc:1; /* IP Checksum Correct */
190 u32 v6:1; /* IPv6 */
191 u32 v4:1; /* IPv4 */
192 u32 frg:1; /* IP Fragment */
193 u32 fcs:1; /* Frame CRC correct */
194 u32 type:7; /* completion type */
195 u32 gen:1; /* generation bit */
196};
197
198/* fields in RxCompDesc we access via Vmxnet3_GenericDesc.dword[3] */
199#define VMXNET3_RCD_TUC_SHIFT 16
200#define VMXNET3_RCD_IPC_SHIFT 19
201
202/* fields in RxCompDesc we access via Vmxnet3_GenericDesc.qword[1] */
203#define VMXNET3_RCD_TYPE_SHIFT 56
204#define VMXNET3_RCD_GEN_SHIFT 63
205
206/* csum OK for TCP/UDP pkts over IP */
207#define VMXNET3_RCD_CSUM_OK (1 << VMXNET3_RCD_TUC_SHIFT | \
208 1 << VMXNET3_RCD_IPC_SHIFT)
209
210/* value of RxCompDesc.rssType */
211enum {
212 VMXNET3_RCD_RSS_TYPE_NONE = 0,
213 VMXNET3_RCD_RSS_TYPE_IPV4 = 1,
214 VMXNET3_RCD_RSS_TYPE_TCPIPV4 = 2,
215 VMXNET3_RCD_RSS_TYPE_IPV6 = 3,
216 VMXNET3_RCD_RSS_TYPE_TCPIPV6 = 4,
217};
218
219
220/* a union for accessing all cmd/completion descriptors */
221union Vmxnet3_GenericDesc {
222 u64 qword[2];
223 u32 dword[4];
224 u16 word[8];
225 struct Vmxnet3_TxDesc txd;
226 struct Vmxnet3_RxDesc rxd;
227 struct Vmxnet3_TxCompDesc tcd;
228 struct Vmxnet3_RxCompDesc rcd;
229};
230
231#define VMXNET3_INIT_GEN 1
232
233/* Max size of a single tx buffer */
234#define VMXNET3_MAX_TX_BUF_SIZE (1 << 14)
235
236/* # of tx desc needed for a tx buffer size */
237#define VMXNET3_TXD_NEEDED(size) (((size) + VMXNET3_MAX_TX_BUF_SIZE - 1) / \
238 VMXNET3_MAX_TX_BUF_SIZE)
239
240/* max # of tx descs for a non-tso pkt */
241#define VMXNET3_MAX_TXD_PER_PKT 16
242
243/* Max size of a single rx buffer */
244#define VMXNET3_MAX_RX_BUF_SIZE ((1 << 14) - 1)
245/* Minimum size of a type 0 buffer */
246#define VMXNET3_MIN_T0_BUF_SIZE 128
247#define VMXNET3_MAX_CSUM_OFFSET 1024
248
249/* Ring base address alignment */
250#define VMXNET3_RING_BA_ALIGN 512
251#define VMXNET3_RING_BA_MASK (VMXNET3_RING_BA_ALIGN - 1)
252
253/* Ring size must be a multiple of 32 */
254#define VMXNET3_RING_SIZE_ALIGN 32
255#define VMXNET3_RING_SIZE_MASK (VMXNET3_RING_SIZE_ALIGN - 1)
256
257/* Max ring size */
258#define VMXNET3_TX_RING_MAX_SIZE 4096
259#define VMXNET3_TC_RING_MAX_SIZE 4096
260#define VMXNET3_RX_RING_MAX_SIZE 4096
261#define VMXNET3_RC_RING_MAX_SIZE 8192
262
263/* a list of reasons for queue stop */
264
265enum {
266 VMXNET3_ERR_NOEOP = 0x80000000, /* cannot find the EOP desc of a pkt */
267 VMXNET3_ERR_TXD_REUSE = 0x80000001, /* reuse TxDesc before tx completion */
268 VMXNET3_ERR_BIG_PKT = 0x80000002, /* too many TxDesc for a pkt */
269 VMXNET3_ERR_DESC_NOT_SPT = 0x80000003, /* descriptor type not supported */
270 VMXNET3_ERR_SMALL_BUF = 0x80000004, /* type 0 buffer too small */
271 VMXNET3_ERR_STRESS = 0x80000005, /* stress option firing in vmkernel */
272 VMXNET3_ERR_SWITCH = 0x80000006, /* mode switch failure */
273 VMXNET3_ERR_TXD_INVALID = 0x80000007, /* invalid TxDesc */
274};
275
276/* completion descriptor types */
277#define VMXNET3_CDTYPE_TXCOMP 0 /* Tx Completion Descriptor */
278#define VMXNET3_CDTYPE_RXCOMP 3 /* Rx Completion Descriptor */
279
280enum {
281 VMXNET3_GOS_BITS_UNK = 0, /* unknown */
282 VMXNET3_GOS_BITS_32 = 1,
283 VMXNET3_GOS_BITS_64 = 2,
284};
285
286#define VMXNET3_GOS_TYPE_LINUX 1
287
288
289struct Vmxnet3_GOSInfo {
290 u32 gosBits:2; /* 32-bit or 64-bit? */
291 u32 gosType:4; /* which guest */
292 u32 gosVer:16; /* gos version */
293 u32 gosMisc:10; /* other info about gos */
294};
295
296
297struct Vmxnet3_DriverInfo {
298 u32 version;
299 struct Vmxnet3_GOSInfo gos;
300 u32 vmxnet3RevSpt;
301 u32 uptVerSpt;
302};
303
304
305#define VMXNET3_REV1_MAGIC 0xbabefee1
306
307/*
308 * QueueDescPA must be 128 bytes aligned. It points to an array of
309 * Vmxnet3_TxQueueDesc followed by an array of Vmxnet3_RxQueueDesc.
310 * The number of Vmxnet3_TxQueueDesc/Vmxnet3_RxQueueDesc are specified by
311 * Vmxnet3_MiscConf.numTxQueues/numRxQueues, respectively.
312 */
313#define VMXNET3_QUEUE_DESC_ALIGN 128
314
315
316struct Vmxnet3_MiscConf {
317 struct Vmxnet3_DriverInfo driverInfo;
318 u64 uptFeatures;
319 u64 ddPA; /* driver data PA */
320 u64 queueDescPA; /* queue descriptor table PA */
321 u32 ddLen; /* driver data len */
322 u32 queueDescLen; /* queue desc. table len in bytes */
323 u32 mtu;
324 u16 maxNumRxSG;
325 u8 numTxQueues;
326 u8 numRxQueues;
327 u32 reserved[4];
328};
329
330
331struct Vmxnet3_TxQueueConf {
332 u64 txRingBasePA;
333 u64 dataRingBasePA;
334 u64 compRingBasePA;
335 u64 ddPA; /* driver data */
336 u64 reserved;
337 u32 txRingSize; /* # of tx desc */
338 u32 dataRingSize; /* # of data desc */
339 u32 compRingSize; /* # of comp desc */
340 u32 ddLen; /* size of driver data */
341 u8 intrIdx;
342 u8 _pad[7];
343};
344
345
346struct Vmxnet3_RxQueueConf {
347 u64 rxRingBasePA[2];
348 u64 compRingBasePA;
349 u64 ddPA; /* driver data */
350 u64 reserved;
351 u32 rxRingSize[2]; /* # of rx desc */
352 u32 compRingSize; /* # of rx comp desc */
353 u32 ddLen; /* size of driver data */
354 u8 intrIdx;
355 u8 _pad[7];
356};
357
358
359enum vmxnet3_intr_mask_mode {
360 VMXNET3_IMM_AUTO = 0,
361 VMXNET3_IMM_ACTIVE = 1,
362 VMXNET3_IMM_LAZY = 2
363};
364
365enum vmxnet3_intr_type {
366 VMXNET3_IT_AUTO = 0,
367 VMXNET3_IT_INTX = 1,
368 VMXNET3_IT_MSI = 2,
369 VMXNET3_IT_MSIX = 3
370};
371
372#define VMXNET3_MAX_TX_QUEUES 8
373#define VMXNET3_MAX_RX_QUEUES 16
374/* addition 1 for events */
375#define VMXNET3_MAX_INTRS 25
376
377
378struct Vmxnet3_IntrConf {
379 bool autoMask;
380 u8 numIntrs; /* # of interrupts */
381 u8 eventIntrIdx;
382 u8 modLevels[VMXNET3_MAX_INTRS]; /* moderation level for
383 * each intr */
384 u32 reserved[3];
385};
386
387/* one bit per VLAN ID, the size is in the units of u32 */
388#define VMXNET3_VFT_SIZE (4096 / (sizeof(u32) * 8))
389
390
391struct Vmxnet3_QueueStatus {
392 bool stopped;
393 u8 _pad[3];
394 u32 error;
395};
396
397
398struct Vmxnet3_TxQueueCtrl {
399 u32 txNumDeferred;
400 u32 txThreshold;
401 u64 reserved;
402};
403
404
405struct Vmxnet3_RxQueueCtrl {
406 bool updateRxProd;
407 u8 _pad[7];
408 u64 reserved;
409};
410
411enum {
412 VMXNET3_RXM_UCAST = 0x01, /* unicast only */
413 VMXNET3_RXM_MCAST = 0x02, /* multicast passing the filters */
414 VMXNET3_RXM_BCAST = 0x04, /* broadcast only */
415 VMXNET3_RXM_ALL_MULTI = 0x08, /* all multicast */
416 VMXNET3_RXM_PROMISC = 0x10 /* promiscuous */
417};
418
419struct Vmxnet3_RxFilterConf {
420 u32 rxMode; /* VMXNET3_RXM_xxx */
421 u16 mfTableLen; /* size of the multicast filter table */
422 u16 _pad1;
423 u64 mfTablePA; /* PA of the multicast filters table */
424 u32 vfTable[VMXNET3_VFT_SIZE]; /* vlan filter */
425};
426
427
428#define VMXNET3_PM_MAX_FILTERS 6
429#define VMXNET3_PM_MAX_PATTERN_SIZE 128
430#define VMXNET3_PM_MAX_MASK_SIZE (VMXNET3_PM_MAX_PATTERN_SIZE / 8)
431
432#define VMXNET3_PM_WAKEUP_MAGIC 0x01 /* wake up on magic pkts */
433#define VMXNET3_PM_WAKEUP_FILTER 0x02 /* wake up on pkts matching
434 * filters */
435
436
437struct Vmxnet3_PM_PktFilter {
438 u8 maskSize;
439 u8 patternSize;
440 u8 mask[VMXNET3_PM_MAX_MASK_SIZE];
441 u8 pattern[VMXNET3_PM_MAX_PATTERN_SIZE];
442 u8 pad[6];
443};
444
445
446struct Vmxnet3_PMConf {
447 u16 wakeUpEvents; /* VMXNET3_PM_WAKEUP_xxx */
448 u8 numFilters;
449 u8 pad[5];
450 struct Vmxnet3_PM_PktFilter filters[VMXNET3_PM_MAX_FILTERS];
451};
452
453
454struct Vmxnet3_VariableLenConfDesc {
455 u32 confVer;
456 u32 confLen;
457 u64 confPA;
458};
459
460
461struct Vmxnet3_TxQueueDesc {
462 struct Vmxnet3_TxQueueCtrl ctrl;
463 struct Vmxnet3_TxQueueConf conf;
464
465 /* Driver read after a GET command */
466 struct Vmxnet3_QueueStatus status;
467 struct UPT1_TxStats stats;
468 u8 _pad[88]; /* 128 aligned */
469};
470
471
472struct Vmxnet3_RxQueueDesc {
473 struct Vmxnet3_RxQueueCtrl ctrl;
474 struct Vmxnet3_RxQueueConf conf;
475 /* Driver read after a GET commad */
476 struct Vmxnet3_QueueStatus status;
477 struct UPT1_RxStats stats;
478 u8 __pad[88]; /* 128 aligned */
479};
480
481
482struct Vmxnet3_DSDevRead {
483 /* read-only region for device, read by dev in response to a SET cmd */
484 struct Vmxnet3_MiscConf misc;
485 struct Vmxnet3_IntrConf intrConf;
486 struct Vmxnet3_RxFilterConf rxFilterConf;
487 struct Vmxnet3_VariableLenConfDesc rssConfDesc;
488 struct Vmxnet3_VariableLenConfDesc pmConfDesc;
489 struct Vmxnet3_VariableLenConfDesc pluginConfDesc;
490};
491
492/* All structures in DriverShared are padded to multiples of 8 bytes */
493struct Vmxnet3_DriverShared {
494 u32 magic;
495 /* make devRead start at 64bit boundaries */
496 u32 pad;
497 struct Vmxnet3_DSDevRead devRead;
498 u32 ecr;
499 u32 reserved[5];
500};
501
502
503#define VMXNET3_ECR_RQERR (1 << 0)
504#define VMXNET3_ECR_TQERR (1 << 1)
505#define VMXNET3_ECR_LINK (1 << 2)
506#define VMXNET3_ECR_DIC (1 << 3)
507#define VMXNET3_ECR_DEBUG (1 << 4)
508
509/* flip the gen bit of a ring */
510#define VMXNET3_FLIP_RING_GEN(gen) ((gen) = (gen) ^ 0x1)
511
512/* only use this if moving the idx won't affect the gen bit */
513#define VMXNET3_INC_RING_IDX_ONLY(idx, ring_size) \
514 do {\
515 (idx)++;\
516 if (unlikely((idx) == (ring_size))) {\
517 (idx) = 0;\
518 } \
519 } while (0)
520
521#define VMXNET3_SET_VFTABLE_ENTRY(vfTable, vid) \
522 (vfTable[vid >> 5] |= (1 << (vid & 31)))
523#define VMXNET3_CLEAR_VFTABLE_ENTRY(vfTable, vid) \
524 (vfTable[vid >> 5] &= ~(1 << (vid & 31)))
525
526#define VMXNET3_VFTABLE_ENTRY_IS_SET(vfTable, vid) \
527 ((vfTable[vid >> 5] & (1 << (vid & 31))) != 0)
528
529#define VMXNET3_MAX_MTU 9000
530#define VMXNET3_MIN_MTU 60
531
532#define VMXNET3_LINK_UP (10000 << 16 | 1) /* 10 Gbps, up */
533#define VMXNET3_LINK_DOWN 0
534
535#endif /* _VMXNET3_DEFS_H_ */
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
new file mode 100644
index 000000000000..004353a46af0
--- /dev/null
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -0,0 +1,2574 @@
1/*
2 * Linux driver for VMware's vmxnet3 ethernet NIC.
3 *
4 * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License and no later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * The full GNU General Public License is included in this distribution in
21 * the file called "COPYING".
22 *
23 * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
24 *
25 */
26
27#include "vmxnet3_int.h"
28
29char vmxnet3_driver_name[] = "vmxnet3";
30#define VMXNET3_DRIVER_DESC "VMware vmxnet3 virtual NIC driver"
31
32
33/*
34 * PCI Device ID Table
35 * Last entry must be all 0s
36 */
37static const struct pci_device_id vmxnet3_pciid_table[] = {
38 {PCI_VDEVICE(VMWARE, PCI_DEVICE_ID_VMWARE_VMXNET3)},
39 {0}
40};
41
42MODULE_DEVICE_TABLE(pci, vmxnet3_pciid_table);
43
44static atomic_t devices_found;
45
46
47/*
48 * Enable/Disable the given intr
49 */
50static void
51vmxnet3_enable_intr(struct vmxnet3_adapter *adapter, unsigned intr_idx)
52{
53 VMXNET3_WRITE_BAR0_REG(adapter, VMXNET3_REG_IMR + intr_idx * 8, 0);
54}
55
56
57static void
58vmxnet3_disable_intr(struct vmxnet3_adapter *adapter, unsigned intr_idx)
59{
60 VMXNET3_WRITE_BAR0_REG(adapter, VMXNET3_REG_IMR + intr_idx * 8, 1);
61}
62
63
64/*
65 * Enable/Disable all intrs used by the device
66 */
67static void
68vmxnet3_enable_all_intrs(struct vmxnet3_adapter *adapter)
69{
70 int i;
71
72 for (i = 0; i < adapter->intr.num_intrs; i++)
73 vmxnet3_enable_intr(adapter, i);
74}
75
76
77static void
78vmxnet3_disable_all_intrs(struct vmxnet3_adapter *adapter)
79{
80 int i;
81
82 for (i = 0; i < adapter->intr.num_intrs; i++)
83 vmxnet3_disable_intr(adapter, i);
84}
85
86
87static void
88vmxnet3_ack_events(struct vmxnet3_adapter *adapter, u32 events)
89{
90 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_ECR, events);
91}
92
93
94static bool
95vmxnet3_tq_stopped(struct vmxnet3_tx_queue *tq, struct vmxnet3_adapter *adapter)
96{
97 return netif_queue_stopped(adapter->netdev);
98}
99
100
101static void
102vmxnet3_tq_start(struct vmxnet3_tx_queue *tq, struct vmxnet3_adapter *adapter)
103{
104 tq->stopped = false;
105 netif_start_queue(adapter->netdev);
106}
107
108
109static void
110vmxnet3_tq_wake(struct vmxnet3_tx_queue *tq, struct vmxnet3_adapter *adapter)
111{
112 tq->stopped = false;
113 netif_wake_queue(adapter->netdev);
114}
115
116
117static void
118vmxnet3_tq_stop(struct vmxnet3_tx_queue *tq, struct vmxnet3_adapter *adapter)
119{
120 tq->stopped = true;
121 tq->num_stop++;
122 netif_stop_queue(adapter->netdev);
123}
124
125
126/*
127 * Check the link state. This may start or stop the tx queue.
128 */
129static void
130vmxnet3_check_link(struct vmxnet3_adapter *adapter)
131{
132 u32 ret;
133
134 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
135 ret = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
136 adapter->link_speed = ret >> 16;
137 if (ret & 1) { /* Link is up. */
138 printk(KERN_INFO "%s: NIC Link is Up %d Mbps\n",
139 adapter->netdev->name, adapter->link_speed);
140 if (!netif_carrier_ok(adapter->netdev))
141 netif_carrier_on(adapter->netdev);
142
143 vmxnet3_tq_start(&adapter->tx_queue, adapter);
144 } else {
145 printk(KERN_INFO "%s: NIC Link is Down\n",
146 adapter->netdev->name);
147 if (netif_carrier_ok(adapter->netdev))
148 netif_carrier_off(adapter->netdev);
149
150 vmxnet3_tq_stop(&adapter->tx_queue, adapter);
151 }
152}
153
154
155static void
156vmxnet3_process_events(struct vmxnet3_adapter *adapter)
157{
158 u32 events = adapter->shared->ecr;
159 if (!events)
160 return;
161
162 vmxnet3_ack_events(adapter, events);
163
164 /* Check if link state has changed */
165 if (events & VMXNET3_ECR_LINK)
166 vmxnet3_check_link(adapter);
167
168 /* Check if there is an error on xmit/recv queues */
169 if (events & (VMXNET3_ECR_TQERR | VMXNET3_ECR_RQERR)) {
170 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
171 VMXNET3_CMD_GET_QUEUE_STATUS);
172
173 if (adapter->tqd_start->status.stopped) {
174 printk(KERN_ERR "%s: tq error 0x%x\n",
175 adapter->netdev->name,
176 adapter->tqd_start->status.error);
177 }
178 if (adapter->rqd_start->status.stopped) {
179 printk(KERN_ERR "%s: rq error 0x%x\n",
180 adapter->netdev->name,
181 adapter->rqd_start->status.error);
182 }
183
184 schedule_work(&adapter->work);
185 }
186}
187
188
189static void
190vmxnet3_unmap_tx_buf(struct vmxnet3_tx_buf_info *tbi,
191 struct pci_dev *pdev)
192{
193 if (tbi->map_type == VMXNET3_MAP_SINGLE)
194 pci_unmap_single(pdev, tbi->dma_addr, tbi->len,
195 PCI_DMA_TODEVICE);
196 else if (tbi->map_type == VMXNET3_MAP_PAGE)
197 pci_unmap_page(pdev, tbi->dma_addr, tbi->len,
198 PCI_DMA_TODEVICE);
199 else
200 BUG_ON(tbi->map_type != VMXNET3_MAP_NONE);
201
202 tbi->map_type = VMXNET3_MAP_NONE; /* to help debugging */
203}
204
205
206static int
207vmxnet3_unmap_pkt(u32 eop_idx, struct vmxnet3_tx_queue *tq,
208 struct pci_dev *pdev, struct vmxnet3_adapter *adapter)
209{
210 struct sk_buff *skb;
211 int entries = 0;
212
213 /* no out of order completion */
214 BUG_ON(tq->buf_info[eop_idx].sop_idx != tq->tx_ring.next2comp);
215 BUG_ON(tq->tx_ring.base[eop_idx].txd.eop != 1);
216
217 skb = tq->buf_info[eop_idx].skb;
218 BUG_ON(skb == NULL);
219 tq->buf_info[eop_idx].skb = NULL;
220
221 VMXNET3_INC_RING_IDX_ONLY(eop_idx, tq->tx_ring.size);
222
223 while (tq->tx_ring.next2comp != eop_idx) {
224 vmxnet3_unmap_tx_buf(tq->buf_info + tq->tx_ring.next2comp,
225 pdev);
226
227 /* update next2comp w/o tx_lock. Since we are marking more,
228 * instead of less, tx ring entries avail, the worst case is
229 * that the tx routine incorrectly re-queues a pkt due to
230 * insufficient tx ring entries.
231 */
232 vmxnet3_cmd_ring_adv_next2comp(&tq->tx_ring);
233 entries++;
234 }
235
236 dev_kfree_skb_any(skb);
237 return entries;
238}
239
240
241static int
242vmxnet3_tq_tx_complete(struct vmxnet3_tx_queue *tq,
243 struct vmxnet3_adapter *adapter)
244{
245 int completed = 0;
246 union Vmxnet3_GenericDesc *gdesc;
247
248 gdesc = tq->comp_ring.base + tq->comp_ring.next2proc;
249 while (gdesc->tcd.gen == tq->comp_ring.gen) {
250 completed += vmxnet3_unmap_pkt(gdesc->tcd.txdIdx, tq,
251 adapter->pdev, adapter);
252
253 vmxnet3_comp_ring_adv_next2proc(&tq->comp_ring);
254 gdesc = tq->comp_ring.base + tq->comp_ring.next2proc;
255 }
256
257 if (completed) {
258 spin_lock(&tq->tx_lock);
259 if (unlikely(vmxnet3_tq_stopped(tq, adapter) &&
260 vmxnet3_cmd_ring_desc_avail(&tq->tx_ring) >
261 VMXNET3_WAKE_QUEUE_THRESHOLD(tq) &&
262 netif_carrier_ok(adapter->netdev))) {
263 vmxnet3_tq_wake(tq, adapter);
264 }
265 spin_unlock(&tq->tx_lock);
266 }
267 return completed;
268}
269
270
271static void
272vmxnet3_tq_cleanup(struct vmxnet3_tx_queue *tq,
273 struct vmxnet3_adapter *adapter)
274{
275 int i;
276
277 while (tq->tx_ring.next2comp != tq->tx_ring.next2fill) {
278 struct vmxnet3_tx_buf_info *tbi;
279 union Vmxnet3_GenericDesc *gdesc;
280
281 tbi = tq->buf_info + tq->tx_ring.next2comp;
282 gdesc = tq->tx_ring.base + tq->tx_ring.next2comp;
283
284 vmxnet3_unmap_tx_buf(tbi, adapter->pdev);
285 if (tbi->skb) {
286 dev_kfree_skb_any(tbi->skb);
287 tbi->skb = NULL;
288 }
289 vmxnet3_cmd_ring_adv_next2comp(&tq->tx_ring);
290 }
291
292 /* sanity check, verify all buffers are indeed unmapped and freed */
293 for (i = 0; i < tq->tx_ring.size; i++) {
294 BUG_ON(tq->buf_info[i].skb != NULL ||
295 tq->buf_info[i].map_type != VMXNET3_MAP_NONE);
296 }
297
298 tq->tx_ring.gen = VMXNET3_INIT_GEN;
299 tq->tx_ring.next2fill = tq->tx_ring.next2comp = 0;
300
301 tq->comp_ring.gen = VMXNET3_INIT_GEN;
302 tq->comp_ring.next2proc = 0;
303}
304
305
306void
307vmxnet3_tq_destroy(struct vmxnet3_tx_queue *tq,
308 struct vmxnet3_adapter *adapter)
309{
310 if (tq->tx_ring.base) {
311 pci_free_consistent(adapter->pdev, tq->tx_ring.size *
312 sizeof(struct Vmxnet3_TxDesc),
313 tq->tx_ring.base, tq->tx_ring.basePA);
314 tq->tx_ring.base = NULL;
315 }
316 if (tq->data_ring.base) {
317 pci_free_consistent(adapter->pdev, tq->data_ring.size *
318 sizeof(struct Vmxnet3_TxDataDesc),
319 tq->data_ring.base, tq->data_ring.basePA);
320 tq->data_ring.base = NULL;
321 }
322 if (tq->comp_ring.base) {
323 pci_free_consistent(adapter->pdev, tq->comp_ring.size *
324 sizeof(struct Vmxnet3_TxCompDesc),
325 tq->comp_ring.base, tq->comp_ring.basePA);
326 tq->comp_ring.base = NULL;
327 }
328 kfree(tq->buf_info);
329 tq->buf_info = NULL;
330}
331
332
333static void
334vmxnet3_tq_init(struct vmxnet3_tx_queue *tq,
335 struct vmxnet3_adapter *adapter)
336{
337 int i;
338
339 /* reset the tx ring contents to 0 and reset the tx ring states */
340 memset(tq->tx_ring.base, 0, tq->tx_ring.size *
341 sizeof(struct Vmxnet3_TxDesc));
342 tq->tx_ring.next2fill = tq->tx_ring.next2comp = 0;
343 tq->tx_ring.gen = VMXNET3_INIT_GEN;
344
345 memset(tq->data_ring.base, 0, tq->data_ring.size *
346 sizeof(struct Vmxnet3_TxDataDesc));
347
348 /* reset the tx comp ring contents to 0 and reset comp ring states */
349 memset(tq->comp_ring.base, 0, tq->comp_ring.size *
350 sizeof(struct Vmxnet3_TxCompDesc));
351 tq->comp_ring.next2proc = 0;
352 tq->comp_ring.gen = VMXNET3_INIT_GEN;
353
354 /* reset the bookkeeping data */
355 memset(tq->buf_info, 0, sizeof(tq->buf_info[0]) * tq->tx_ring.size);
356 for (i = 0; i < tq->tx_ring.size; i++)
357 tq->buf_info[i].map_type = VMXNET3_MAP_NONE;
358
359 /* stats are not reset */
360}
361
362
363static int
364vmxnet3_tq_create(struct vmxnet3_tx_queue *tq,
365 struct vmxnet3_adapter *adapter)
366{
367 BUG_ON(tq->tx_ring.base || tq->data_ring.base ||
368 tq->comp_ring.base || tq->buf_info);
369
370 tq->tx_ring.base = pci_alloc_consistent(adapter->pdev, tq->tx_ring.size
371 * sizeof(struct Vmxnet3_TxDesc),
372 &tq->tx_ring.basePA);
373 if (!tq->tx_ring.base) {
374 printk(KERN_ERR "%s: failed to allocate tx ring\n",
375 adapter->netdev->name);
376 goto err;
377 }
378
379 tq->data_ring.base = pci_alloc_consistent(adapter->pdev,
380 tq->data_ring.size *
381 sizeof(struct Vmxnet3_TxDataDesc),
382 &tq->data_ring.basePA);
383 if (!tq->data_ring.base) {
384 printk(KERN_ERR "%s: failed to allocate data ring\n",
385 adapter->netdev->name);
386 goto err;
387 }
388
389 tq->comp_ring.base = pci_alloc_consistent(adapter->pdev,
390 tq->comp_ring.size *
391 sizeof(struct Vmxnet3_TxCompDesc),
392 &tq->comp_ring.basePA);
393 if (!tq->comp_ring.base) {
394 printk(KERN_ERR "%s: failed to allocate tx comp ring\n",
395 adapter->netdev->name);
396 goto err;
397 }
398
399 tq->buf_info = kcalloc(tq->tx_ring.size, sizeof(tq->buf_info[0]),
400 GFP_KERNEL);
401 if (!tq->buf_info) {
402 printk(KERN_ERR "%s: failed to allocate tx bufinfo\n",
403 adapter->netdev->name);
404 goto err;
405 }
406
407 return 0;
408
409err:
410 vmxnet3_tq_destroy(tq, adapter);
411 return -ENOMEM;
412}
413
414
415/*
416 * starting from ring->next2fill, allocate rx buffers for the given ring
417 * of the rx queue and update the rx desc. stop after @num_to_alloc buffers
418 * are allocated or allocation fails
419 */
420
421static int
422vmxnet3_rq_alloc_rx_buf(struct vmxnet3_rx_queue *rq, u32 ring_idx,
423 int num_to_alloc, struct vmxnet3_adapter *adapter)
424{
425 int num_allocated = 0;
426 struct vmxnet3_rx_buf_info *rbi_base = rq->buf_info[ring_idx];
427 struct vmxnet3_cmd_ring *ring = &rq->rx_ring[ring_idx];
428 u32 val;
429
430 while (num_allocated < num_to_alloc) {
431 struct vmxnet3_rx_buf_info *rbi;
432 union Vmxnet3_GenericDesc *gd;
433
434 rbi = rbi_base + ring->next2fill;
435 gd = ring->base + ring->next2fill;
436
437 if (rbi->buf_type == VMXNET3_RX_BUF_SKB) {
438 if (rbi->skb == NULL) {
439 rbi->skb = dev_alloc_skb(rbi->len +
440 NET_IP_ALIGN);
441 if (unlikely(rbi->skb == NULL)) {
442 rq->stats.rx_buf_alloc_failure++;
443 break;
444 }
445 rbi->skb->dev = adapter->netdev;
446
447 skb_reserve(rbi->skb, NET_IP_ALIGN);
448 rbi->dma_addr = pci_map_single(adapter->pdev,
449 rbi->skb->data, rbi->len,
450 PCI_DMA_FROMDEVICE);
451 } else {
452 /* rx buffer skipped by the device */
453 }
454 val = VMXNET3_RXD_BTYPE_HEAD << VMXNET3_RXD_BTYPE_SHIFT;
455 } else {
456 BUG_ON(rbi->buf_type != VMXNET3_RX_BUF_PAGE ||
457 rbi->len != PAGE_SIZE);
458
459 if (rbi->page == NULL) {
460 rbi->page = alloc_page(GFP_ATOMIC);
461 if (unlikely(rbi->page == NULL)) {
462 rq->stats.rx_buf_alloc_failure++;
463 break;
464 }
465 rbi->dma_addr = pci_map_page(adapter->pdev,
466 rbi->page, 0, PAGE_SIZE,
467 PCI_DMA_FROMDEVICE);
468 } else {
469 /* rx buffers skipped by the device */
470 }
471 val = VMXNET3_RXD_BTYPE_BODY << VMXNET3_RXD_BTYPE_SHIFT;
472 }
473
474 BUG_ON(rbi->dma_addr == 0);
475 gd->rxd.addr = rbi->dma_addr;
476 gd->dword[2] = (ring->gen << VMXNET3_RXD_GEN_SHIFT) | val |
477 rbi->len;
478
479 num_allocated++;
480 vmxnet3_cmd_ring_adv_next2fill(ring);
481 }
482 rq->uncommitted[ring_idx] += num_allocated;
483
484 dev_dbg(&adapter->netdev->dev,
485 "alloc_rx_buf: %d allocated, next2fill %u, next2comp "
486 "%u, uncommited %u\n", num_allocated, ring->next2fill,
487 ring->next2comp, rq->uncommitted[ring_idx]);
488
489 /* so that the device can distinguish a full ring and an empty ring */
490 BUG_ON(num_allocated != 0 && ring->next2fill == ring->next2comp);
491
492 return num_allocated;
493}
494
495
496static void
497vmxnet3_append_frag(struct sk_buff *skb, struct Vmxnet3_RxCompDesc *rcd,
498 struct vmxnet3_rx_buf_info *rbi)
499{
500 struct skb_frag_struct *frag = skb_shinfo(skb)->frags +
501 skb_shinfo(skb)->nr_frags;
502
503 BUG_ON(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS);
504
505 frag->page = rbi->page;
506 frag->page_offset = 0;
507 frag->size = rcd->len;
508 skb->data_len += frag->size;
509 skb_shinfo(skb)->nr_frags++;
510}
511
512
513static void
514vmxnet3_map_pkt(struct sk_buff *skb, struct vmxnet3_tx_ctx *ctx,
515 struct vmxnet3_tx_queue *tq, struct pci_dev *pdev,
516 struct vmxnet3_adapter *adapter)
517{
518 u32 dw2, len;
519 unsigned long buf_offset;
520 int i;
521 union Vmxnet3_GenericDesc *gdesc;
522 struct vmxnet3_tx_buf_info *tbi = NULL;
523
524 BUG_ON(ctx->copy_size > skb_headlen(skb));
525
526 /* use the previous gen bit for the SOP desc */
527 dw2 = (tq->tx_ring.gen ^ 0x1) << VMXNET3_TXD_GEN_SHIFT;
528
529 ctx->sop_txd = tq->tx_ring.base + tq->tx_ring.next2fill;
530 gdesc = ctx->sop_txd; /* both loops below can be skipped */
531
532 /* no need to map the buffer if headers are copied */
533 if (ctx->copy_size) {
534 ctx->sop_txd->txd.addr = tq->data_ring.basePA +
535 tq->tx_ring.next2fill *
536 sizeof(struct Vmxnet3_TxDataDesc);
537 ctx->sop_txd->dword[2] = dw2 | ctx->copy_size;
538 ctx->sop_txd->dword[3] = 0;
539
540 tbi = tq->buf_info + tq->tx_ring.next2fill;
541 tbi->map_type = VMXNET3_MAP_NONE;
542
543 dev_dbg(&adapter->netdev->dev,
544 "txd[%u]: 0x%Lx 0x%x 0x%x\n",
545 tq->tx_ring.next2fill, ctx->sop_txd->txd.addr,
546 ctx->sop_txd->dword[2], ctx->sop_txd->dword[3]);
547 vmxnet3_cmd_ring_adv_next2fill(&tq->tx_ring);
548
549 /* use the right gen for non-SOP desc */
550 dw2 = tq->tx_ring.gen << VMXNET3_TXD_GEN_SHIFT;
551 }
552
553 /* linear part can use multiple tx desc if it's big */
554 len = skb_headlen(skb) - ctx->copy_size;
555 buf_offset = ctx->copy_size;
556 while (len) {
557 u32 buf_size;
558
559 buf_size = len > VMXNET3_MAX_TX_BUF_SIZE ?
560 VMXNET3_MAX_TX_BUF_SIZE : len;
561
562 tbi = tq->buf_info + tq->tx_ring.next2fill;
563 tbi->map_type = VMXNET3_MAP_SINGLE;
564 tbi->dma_addr = pci_map_single(adapter->pdev,
565 skb->data + buf_offset, buf_size,
566 PCI_DMA_TODEVICE);
567
568 tbi->len = buf_size; /* this automatically convert 2^14 to 0 */
569
570 gdesc = tq->tx_ring.base + tq->tx_ring.next2fill;
571 BUG_ON(gdesc->txd.gen == tq->tx_ring.gen);
572
573 gdesc->txd.addr = tbi->dma_addr;
574 gdesc->dword[2] = dw2 | buf_size;
575 gdesc->dword[3] = 0;
576
577 dev_dbg(&adapter->netdev->dev,
578 "txd[%u]: 0x%Lx 0x%x 0x%x\n",
579 tq->tx_ring.next2fill, gdesc->txd.addr,
580 gdesc->dword[2], gdesc->dword[3]);
581 vmxnet3_cmd_ring_adv_next2fill(&tq->tx_ring);
582 dw2 = tq->tx_ring.gen << VMXNET3_TXD_GEN_SHIFT;
583
584 len -= buf_size;
585 buf_offset += buf_size;
586 }
587
588 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
589 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i];
590
591 tbi = tq->buf_info + tq->tx_ring.next2fill;
592 tbi->map_type = VMXNET3_MAP_PAGE;
593 tbi->dma_addr = pci_map_page(adapter->pdev, frag->page,
594 frag->page_offset, frag->size,
595 PCI_DMA_TODEVICE);
596
597 tbi->len = frag->size;
598
599 gdesc = tq->tx_ring.base + tq->tx_ring.next2fill;
600 BUG_ON(gdesc->txd.gen == tq->tx_ring.gen);
601
602 gdesc->txd.addr = tbi->dma_addr;
603 gdesc->dword[2] = dw2 | frag->size;
604 gdesc->dword[3] = 0;
605
606 dev_dbg(&adapter->netdev->dev,
607 "txd[%u]: 0x%llu %u %u\n",
608 tq->tx_ring.next2fill, gdesc->txd.addr,
609 gdesc->dword[2], gdesc->dword[3]);
610 vmxnet3_cmd_ring_adv_next2fill(&tq->tx_ring);
611 dw2 = tq->tx_ring.gen << VMXNET3_TXD_GEN_SHIFT;
612 }
613
614 ctx->eop_txd = gdesc;
615
616 /* set the last buf_info for the pkt */
617 tbi->skb = skb;
618 tbi->sop_idx = ctx->sop_txd - tq->tx_ring.base;
619}
620
621
622/*
623 * parse and copy relevant protocol headers:
624 * For a tso pkt, relevant headers are L2/3/4 including options
625 * For a pkt requesting csum offloading, they are L2/3 and may include L4
626 * if it's a TCP/UDP pkt
627 *
628 * Returns:
629 * -1: error happens during parsing
630 * 0: protocol headers parsed, but too big to be copied
631 * 1: protocol headers parsed and copied
632 *
633 * Other effects:
634 * 1. related *ctx fields are updated.
635 * 2. ctx->copy_size is # of bytes copied
636 * 3. the portion copied is guaranteed to be in the linear part
637 *
638 */
639static int
640vmxnet3_parse_and_copy_hdr(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,
641 struct vmxnet3_tx_ctx *ctx,
642 struct vmxnet3_adapter *adapter)
643{
644 struct Vmxnet3_TxDataDesc *tdd;
645
646 if (ctx->mss) {
647 ctx->eth_ip_hdr_size = skb_transport_offset(skb);
648 ctx->l4_hdr_size = ((struct tcphdr *)
649 skb_transport_header(skb))->doff * 4;
650 ctx->copy_size = ctx->eth_ip_hdr_size + ctx->l4_hdr_size;
651 } else {
652 unsigned int pull_size;
653
654 if (skb->ip_summed == CHECKSUM_PARTIAL) {
655 ctx->eth_ip_hdr_size = skb_transport_offset(skb);
656
657 if (ctx->ipv4) {
658 struct iphdr *iph = (struct iphdr *)
659 skb_network_header(skb);
660 if (iph->protocol == IPPROTO_TCP) {
661 pull_size = ctx->eth_ip_hdr_size +
662 sizeof(struct tcphdr);
663
664 if (unlikely(!pskb_may_pull(skb,
665 pull_size))) {
666 goto err;
667 }
668 ctx->l4_hdr_size = ((struct tcphdr *)
669 skb_transport_header(skb))->doff * 4;
670 } else if (iph->protocol == IPPROTO_UDP) {
671 ctx->l4_hdr_size =
672 sizeof(struct udphdr);
673 } else {
674 ctx->l4_hdr_size = 0;
675 }
676 } else {
677 /* for simplicity, don't copy L4 headers */
678 ctx->l4_hdr_size = 0;
679 }
680 ctx->copy_size = ctx->eth_ip_hdr_size +
681 ctx->l4_hdr_size;
682 } else {
683 ctx->eth_ip_hdr_size = 0;
684 ctx->l4_hdr_size = 0;
685 /* copy as much as allowed */
686 ctx->copy_size = min((unsigned int)VMXNET3_HDR_COPY_SIZE
687 , skb_headlen(skb));
688 }
689
690 /* make sure headers are accessible directly */
691 if (unlikely(!pskb_may_pull(skb, ctx->copy_size)))
692 goto err;
693 }
694
695 if (unlikely(ctx->copy_size > VMXNET3_HDR_COPY_SIZE)) {
696 tq->stats.oversized_hdr++;
697 ctx->copy_size = 0;
698 return 0;
699 }
700
701 tdd = tq->data_ring.base + tq->tx_ring.next2fill;
702
703 memcpy(tdd->data, skb->data, ctx->copy_size);
704 dev_dbg(&adapter->netdev->dev,
705 "copy %u bytes to dataRing[%u]\n",
706 ctx->copy_size, tq->tx_ring.next2fill);
707 return 1;
708
709err:
710 return -1;
711}
712
713
714static void
715vmxnet3_prepare_tso(struct sk_buff *skb,
716 struct vmxnet3_tx_ctx *ctx)
717{
718 struct tcphdr *tcph = (struct tcphdr *)skb_transport_header(skb);
719 if (ctx->ipv4) {
720 struct iphdr *iph = (struct iphdr *)skb_network_header(skb);
721 iph->check = 0;
722 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, 0,
723 IPPROTO_TCP, 0);
724 } else {
725 struct ipv6hdr *iph = (struct ipv6hdr *)skb_network_header(skb);
726 tcph->check = ~csum_ipv6_magic(&iph->saddr, &iph->daddr, 0,
727 IPPROTO_TCP, 0);
728 }
729}
730
731
732/*
733 * Transmits a pkt thru a given tq
734 * Returns:
735 * NETDEV_TX_OK: descriptors are setup successfully
736 * NETDEV_TX_OK: error occured, the pkt is dropped
737 * NETDEV_TX_BUSY: tx ring is full, queue is stopped
738 *
739 * Side-effects:
740 * 1. tx ring may be changed
741 * 2. tq stats may be updated accordingly
742 * 3. shared->txNumDeferred may be updated
743 */
744
745static int
746vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,
747 struct vmxnet3_adapter *adapter, struct net_device *netdev)
748{
749 int ret;
750 u32 count;
751 unsigned long flags;
752 struct vmxnet3_tx_ctx ctx;
753 union Vmxnet3_GenericDesc *gdesc;
754
755 /* conservatively estimate # of descriptors to use */
756 count = VMXNET3_TXD_NEEDED(skb_headlen(skb)) +
757 skb_shinfo(skb)->nr_frags + 1;
758
759 ctx.ipv4 = (skb->protocol == __constant_ntohs(ETH_P_IP));
760
761 ctx.mss = skb_shinfo(skb)->gso_size;
762 if (ctx.mss) {
763 if (skb_header_cloned(skb)) {
764 if (unlikely(pskb_expand_head(skb, 0, 0,
765 GFP_ATOMIC) != 0)) {
766 tq->stats.drop_tso++;
767 goto drop_pkt;
768 }
769 tq->stats.copy_skb_header++;
770 }
771 vmxnet3_prepare_tso(skb, &ctx);
772 } else {
773 if (unlikely(count > VMXNET3_MAX_TXD_PER_PKT)) {
774
775 /* non-tso pkts must not use more than
776 * VMXNET3_MAX_TXD_PER_PKT entries
777 */
778 if (skb_linearize(skb) != 0) {
779 tq->stats.drop_too_many_frags++;
780 goto drop_pkt;
781 }
782 tq->stats.linearized++;
783
784 /* recalculate the # of descriptors to use */
785 count = VMXNET3_TXD_NEEDED(skb_headlen(skb)) + 1;
786 }
787 }
788
789 ret = vmxnet3_parse_and_copy_hdr(skb, tq, &ctx, adapter);
790 if (ret >= 0) {
791 BUG_ON(ret <= 0 && ctx.copy_size != 0);
792 /* hdrs parsed, check against other limits */
793 if (ctx.mss) {
794 if (unlikely(ctx.eth_ip_hdr_size + ctx.l4_hdr_size >
795 VMXNET3_MAX_TX_BUF_SIZE)) {
796 goto hdr_too_big;
797 }
798 } else {
799 if (skb->ip_summed == CHECKSUM_PARTIAL) {
800 if (unlikely(ctx.eth_ip_hdr_size +
801 skb->csum_offset >
802 VMXNET3_MAX_CSUM_OFFSET)) {
803 goto hdr_too_big;
804 }
805 }
806 }
807 } else {
808 tq->stats.drop_hdr_inspect_err++;
809 goto drop_pkt;
810 }
811
812 spin_lock_irqsave(&tq->tx_lock, flags);
813
814 if (count > vmxnet3_cmd_ring_desc_avail(&tq->tx_ring)) {
815 tq->stats.tx_ring_full++;
816 dev_dbg(&adapter->netdev->dev,
817 "tx queue stopped on %s, next2comp %u"
818 " next2fill %u\n", adapter->netdev->name,
819 tq->tx_ring.next2comp, tq->tx_ring.next2fill);
820
821 vmxnet3_tq_stop(tq, adapter);
822 spin_unlock_irqrestore(&tq->tx_lock, flags);
823 return NETDEV_TX_BUSY;
824 }
825
826 /* fill tx descs related to addr & len */
827 vmxnet3_map_pkt(skb, &ctx, tq, adapter->pdev, adapter);
828
829 /* setup the EOP desc */
830 ctx.eop_txd->dword[3] = VMXNET3_TXD_CQ | VMXNET3_TXD_EOP;
831
832 /* setup the SOP desc */
833 gdesc = ctx.sop_txd;
834 if (ctx.mss) {
835 gdesc->txd.hlen = ctx.eth_ip_hdr_size + ctx.l4_hdr_size;
836 gdesc->txd.om = VMXNET3_OM_TSO;
837 gdesc->txd.msscof = ctx.mss;
838 tq->shared->txNumDeferred += (skb->len - gdesc->txd.hlen +
839 ctx.mss - 1) / ctx.mss;
840 } else {
841 if (skb->ip_summed == CHECKSUM_PARTIAL) {
842 gdesc->txd.hlen = ctx.eth_ip_hdr_size;
843 gdesc->txd.om = VMXNET3_OM_CSUM;
844 gdesc->txd.msscof = ctx.eth_ip_hdr_size +
845 skb->csum_offset;
846 } else {
847 gdesc->txd.om = 0;
848 gdesc->txd.msscof = 0;
849 }
850 tq->shared->txNumDeferred++;
851 }
852
853 if (vlan_tx_tag_present(skb)) {
854 gdesc->txd.ti = 1;
855 gdesc->txd.tci = vlan_tx_tag_get(skb);
856 }
857
858 wmb();
859
860 /* finally flips the GEN bit of the SOP desc */
861 gdesc->dword[2] ^= VMXNET3_TXD_GEN;
862 dev_dbg(&adapter->netdev->dev,
863 "txd[%u]: SOP 0x%Lx 0x%x 0x%x\n",
864 (u32)((union Vmxnet3_GenericDesc *)ctx.sop_txd -
865 tq->tx_ring.base), gdesc->txd.addr, gdesc->dword[2],
866 gdesc->dword[3]);
867
868 spin_unlock_irqrestore(&tq->tx_lock, flags);
869
870 if (tq->shared->txNumDeferred >= tq->shared->txThreshold) {
871 tq->shared->txNumDeferred = 0;
872 VMXNET3_WRITE_BAR0_REG(adapter, VMXNET3_REG_TXPROD,
873 tq->tx_ring.next2fill);
874 }
875 netdev->trans_start = jiffies;
876
877 return NETDEV_TX_OK;
878
879hdr_too_big:
880 tq->stats.drop_oversized_hdr++;
881drop_pkt:
882 tq->stats.drop_total++;
883 dev_kfree_skb(skb);
884 return NETDEV_TX_OK;
885}
886
887
888static netdev_tx_t
889vmxnet3_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
890{
891 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
892 struct vmxnet3_tx_queue *tq = &adapter->tx_queue;
893
894 return vmxnet3_tq_xmit(skb, tq, adapter, netdev);
895}
896
897
898static void
899vmxnet3_rx_csum(struct vmxnet3_adapter *adapter,
900 struct sk_buff *skb,
901 union Vmxnet3_GenericDesc *gdesc)
902{
903 if (!gdesc->rcd.cnc && adapter->rxcsum) {
904 /* typical case: TCP/UDP over IP and both csums are correct */
905 if ((gdesc->dword[3] & VMXNET3_RCD_CSUM_OK) ==
906 VMXNET3_RCD_CSUM_OK) {
907 skb->ip_summed = CHECKSUM_UNNECESSARY;
908 BUG_ON(!(gdesc->rcd.tcp || gdesc->rcd.udp));
909 BUG_ON(!(gdesc->rcd.v4 || gdesc->rcd.v6));
910 BUG_ON(gdesc->rcd.frg);
911 } else {
912 if (gdesc->rcd.csum) {
913 skb->csum = htons(gdesc->rcd.csum);
914 skb->ip_summed = CHECKSUM_PARTIAL;
915 } else {
916 skb->ip_summed = CHECKSUM_NONE;
917 }
918 }
919 } else {
920 skb->ip_summed = CHECKSUM_NONE;
921 }
922}
923
924
925static void
926vmxnet3_rx_error(struct vmxnet3_rx_queue *rq, struct Vmxnet3_RxCompDesc *rcd,
927 struct vmxnet3_rx_ctx *ctx, struct vmxnet3_adapter *adapter)
928{
929 rq->stats.drop_err++;
930 if (!rcd->fcs)
931 rq->stats.drop_fcs++;
932
933 rq->stats.drop_total++;
934
935 /*
936 * We do not unmap and chain the rx buffer to the skb.
937 * We basically pretend this buffer is not used and will be recycled
938 * by vmxnet3_rq_alloc_rx_buf()
939 */
940
941 /*
942 * ctx->skb may be NULL if this is the first and the only one
943 * desc for the pkt
944 */
945 if (ctx->skb)
946 dev_kfree_skb_irq(ctx->skb);
947
948 ctx->skb = NULL;
949}
950
951
952static int
953vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq,
954 struct vmxnet3_adapter *adapter, int quota)
955{
956 static u32 rxprod_reg[2] = {VMXNET3_REG_RXPROD, VMXNET3_REG_RXPROD2};
957 u32 num_rxd = 0;
958 struct Vmxnet3_RxCompDesc *rcd;
959 struct vmxnet3_rx_ctx *ctx = &rq->rx_ctx;
960
961 rcd = &rq->comp_ring.base[rq->comp_ring.next2proc].rcd;
962 while (rcd->gen == rq->comp_ring.gen) {
963 struct vmxnet3_rx_buf_info *rbi;
964 struct sk_buff *skb;
965 int num_to_alloc;
966 struct Vmxnet3_RxDesc *rxd;
967 u32 idx, ring_idx;
968
969 if (num_rxd >= quota) {
970 /* we may stop even before we see the EOP desc of
971 * the current pkt
972 */
973 break;
974 }
975 num_rxd++;
976
977 idx = rcd->rxdIdx;
978 ring_idx = rcd->rqID == rq->qid ? 0 : 1;
979
980 rxd = &rq->rx_ring[ring_idx].base[idx].rxd;
981 rbi = rq->buf_info[ring_idx] + idx;
982
983 BUG_ON(rxd->addr != rbi->dma_addr || rxd->len != rbi->len);
984
985 if (unlikely(rcd->eop && rcd->err)) {
986 vmxnet3_rx_error(rq, rcd, ctx, adapter);
987 goto rcd_done;
988 }
989
990 if (rcd->sop) { /* first buf of the pkt */
991 BUG_ON(rxd->btype != VMXNET3_RXD_BTYPE_HEAD ||
992 rcd->rqID != rq->qid);
993
994 BUG_ON(rbi->buf_type != VMXNET3_RX_BUF_SKB);
995 BUG_ON(ctx->skb != NULL || rbi->skb == NULL);
996
997 if (unlikely(rcd->len == 0)) {
998 /* Pretend the rx buffer is skipped. */
999 BUG_ON(!(rcd->sop && rcd->eop));
1000 dev_dbg(&adapter->netdev->dev,
1001 "rxRing[%u][%u] 0 length\n",
1002 ring_idx, idx);
1003 goto rcd_done;
1004 }
1005
1006 ctx->skb = rbi->skb;
1007 rbi->skb = NULL;
1008
1009 pci_unmap_single(adapter->pdev, rbi->dma_addr, rbi->len,
1010 PCI_DMA_FROMDEVICE);
1011
1012 skb_put(ctx->skb, rcd->len);
1013 } else {
1014 BUG_ON(ctx->skb == NULL);
1015 /* non SOP buffer must be type 1 in most cases */
1016 if (rbi->buf_type == VMXNET3_RX_BUF_PAGE) {
1017 BUG_ON(rxd->btype != VMXNET3_RXD_BTYPE_BODY);
1018
1019 if (rcd->len) {
1020 pci_unmap_page(adapter->pdev,
1021 rbi->dma_addr, rbi->len,
1022 PCI_DMA_FROMDEVICE);
1023
1024 vmxnet3_append_frag(ctx->skb, rcd, rbi);
1025 rbi->page = NULL;
1026 }
1027 } else {
1028 /*
1029 * The only time a non-SOP buffer is type 0 is
1030 * when it's EOP and error flag is raised, which
1031 * has already been handled.
1032 */
1033 BUG_ON(true);
1034 }
1035 }
1036
1037 skb = ctx->skb;
1038 if (rcd->eop) {
1039 skb->len += skb->data_len;
1040 skb->truesize += skb->data_len;
1041
1042 vmxnet3_rx_csum(adapter, skb,
1043 (union Vmxnet3_GenericDesc *)rcd);
1044 skb->protocol = eth_type_trans(skb, adapter->netdev);
1045
1046 if (unlikely(adapter->vlan_grp && rcd->ts)) {
1047 vlan_hwaccel_receive_skb(skb,
1048 adapter->vlan_grp, rcd->tci);
1049 } else {
1050 netif_receive_skb(skb);
1051 }
1052
1053 adapter->netdev->last_rx = jiffies;
1054 ctx->skb = NULL;
1055 }
1056
1057rcd_done:
1058 /* device may skip some rx descs */
1059 rq->rx_ring[ring_idx].next2comp = idx;
1060 VMXNET3_INC_RING_IDX_ONLY(rq->rx_ring[ring_idx].next2comp,
1061 rq->rx_ring[ring_idx].size);
1062
1063 /* refill rx buffers frequently to avoid starving the h/w */
1064 num_to_alloc = vmxnet3_cmd_ring_desc_avail(rq->rx_ring +
1065 ring_idx);
1066 if (unlikely(num_to_alloc > VMXNET3_RX_ALLOC_THRESHOLD(rq,
1067 ring_idx, adapter))) {
1068 vmxnet3_rq_alloc_rx_buf(rq, ring_idx, num_to_alloc,
1069 adapter);
1070
1071 /* if needed, update the register */
1072 if (unlikely(rq->shared->updateRxProd)) {
1073 VMXNET3_WRITE_BAR0_REG(adapter,
1074 rxprod_reg[ring_idx] + rq->qid * 8,
1075 rq->rx_ring[ring_idx].next2fill);
1076 rq->uncommitted[ring_idx] = 0;
1077 }
1078 }
1079
1080 vmxnet3_comp_ring_adv_next2proc(&rq->comp_ring);
1081 rcd = &rq->comp_ring.base[rq->comp_ring.next2proc].rcd;
1082 }
1083
1084 return num_rxd;
1085}
1086
1087
1088static void
1089vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq,
1090 struct vmxnet3_adapter *adapter)
1091{
1092 u32 i, ring_idx;
1093 struct Vmxnet3_RxDesc *rxd;
1094
1095 for (ring_idx = 0; ring_idx < 2; ring_idx++) {
1096 for (i = 0; i < rq->rx_ring[ring_idx].size; i++) {
1097 rxd = &rq->rx_ring[ring_idx].base[i].rxd;
1098
1099 if (rxd->btype == VMXNET3_RXD_BTYPE_HEAD &&
1100 rq->buf_info[ring_idx][i].skb) {
1101 pci_unmap_single(adapter->pdev, rxd->addr,
1102 rxd->len, PCI_DMA_FROMDEVICE);
1103 dev_kfree_skb(rq->buf_info[ring_idx][i].skb);
1104 rq->buf_info[ring_idx][i].skb = NULL;
1105 } else if (rxd->btype == VMXNET3_RXD_BTYPE_BODY &&
1106 rq->buf_info[ring_idx][i].page) {
1107 pci_unmap_page(adapter->pdev, rxd->addr,
1108 rxd->len, PCI_DMA_FROMDEVICE);
1109 put_page(rq->buf_info[ring_idx][i].page);
1110 rq->buf_info[ring_idx][i].page = NULL;
1111 }
1112 }
1113
1114 rq->rx_ring[ring_idx].gen = VMXNET3_INIT_GEN;
1115 rq->rx_ring[ring_idx].next2fill =
1116 rq->rx_ring[ring_idx].next2comp = 0;
1117 rq->uncommitted[ring_idx] = 0;
1118 }
1119
1120 rq->comp_ring.gen = VMXNET3_INIT_GEN;
1121 rq->comp_ring.next2proc = 0;
1122}
1123
1124
1125void vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq,
1126 struct vmxnet3_adapter *adapter)
1127{
1128 int i;
1129 int j;
1130
1131 /* all rx buffers must have already been freed */
1132 for (i = 0; i < 2; i++) {
1133 if (rq->buf_info[i]) {
1134 for (j = 0; j < rq->rx_ring[i].size; j++)
1135 BUG_ON(rq->buf_info[i][j].page != NULL);
1136 }
1137 }
1138
1139
1140 kfree(rq->buf_info[0]);
1141
1142 for (i = 0; i < 2; i++) {
1143 if (rq->rx_ring[i].base) {
1144 pci_free_consistent(adapter->pdev, rq->rx_ring[i].size
1145 * sizeof(struct Vmxnet3_RxDesc),
1146 rq->rx_ring[i].base,
1147 rq->rx_ring[i].basePA);
1148 rq->rx_ring[i].base = NULL;
1149 }
1150 rq->buf_info[i] = NULL;
1151 }
1152
1153 if (rq->comp_ring.base) {
1154 pci_free_consistent(adapter->pdev, rq->comp_ring.size *
1155 sizeof(struct Vmxnet3_RxCompDesc),
1156 rq->comp_ring.base, rq->comp_ring.basePA);
1157 rq->comp_ring.base = NULL;
1158 }
1159}
1160
1161
1162static int
1163vmxnet3_rq_init(struct vmxnet3_rx_queue *rq,
1164 struct vmxnet3_adapter *adapter)
1165{
1166 int i;
1167
1168 /* initialize buf_info */
1169 for (i = 0; i < rq->rx_ring[0].size; i++) {
1170
1171 /* 1st buf for a pkt is skbuff */
1172 if (i % adapter->rx_buf_per_pkt == 0) {
1173 rq->buf_info[0][i].buf_type = VMXNET3_RX_BUF_SKB;
1174 rq->buf_info[0][i].len = adapter->skb_buf_size;
1175 } else { /* subsequent bufs for a pkt is frag */
1176 rq->buf_info[0][i].buf_type = VMXNET3_RX_BUF_PAGE;
1177 rq->buf_info[0][i].len = PAGE_SIZE;
1178 }
1179 }
1180 for (i = 0; i < rq->rx_ring[1].size; i++) {
1181 rq->buf_info[1][i].buf_type = VMXNET3_RX_BUF_PAGE;
1182 rq->buf_info[1][i].len = PAGE_SIZE;
1183 }
1184
1185 /* reset internal state and allocate buffers for both rings */
1186 for (i = 0; i < 2; i++) {
1187 rq->rx_ring[i].next2fill = rq->rx_ring[i].next2comp = 0;
1188 rq->uncommitted[i] = 0;
1189
1190 memset(rq->rx_ring[i].base, 0, rq->rx_ring[i].size *
1191 sizeof(struct Vmxnet3_RxDesc));
1192 rq->rx_ring[i].gen = VMXNET3_INIT_GEN;
1193 }
1194 if (vmxnet3_rq_alloc_rx_buf(rq, 0, rq->rx_ring[0].size - 1,
1195 adapter) == 0) {
1196 /* at least has 1 rx buffer for the 1st ring */
1197 return -ENOMEM;
1198 }
1199 vmxnet3_rq_alloc_rx_buf(rq, 1, rq->rx_ring[1].size - 1, adapter);
1200
1201 /* reset the comp ring */
1202 rq->comp_ring.next2proc = 0;
1203 memset(rq->comp_ring.base, 0, rq->comp_ring.size *
1204 sizeof(struct Vmxnet3_RxCompDesc));
1205 rq->comp_ring.gen = VMXNET3_INIT_GEN;
1206
1207 /* reset rxctx */
1208 rq->rx_ctx.skb = NULL;
1209
1210 /* stats are not reset */
1211 return 0;
1212}
1213
1214
1215static int
1216vmxnet3_rq_create(struct vmxnet3_rx_queue *rq, struct vmxnet3_adapter *adapter)
1217{
1218 int i;
1219 size_t sz;
1220 struct vmxnet3_rx_buf_info *bi;
1221
1222 for (i = 0; i < 2; i++) {
1223
1224 sz = rq->rx_ring[i].size * sizeof(struct Vmxnet3_RxDesc);
1225 rq->rx_ring[i].base = pci_alloc_consistent(adapter->pdev, sz,
1226 &rq->rx_ring[i].basePA);
1227 if (!rq->rx_ring[i].base) {
1228 printk(KERN_ERR "%s: failed to allocate rx ring %d\n",
1229 adapter->netdev->name, i);
1230 goto err;
1231 }
1232 }
1233
1234 sz = rq->comp_ring.size * sizeof(struct Vmxnet3_RxCompDesc);
1235 rq->comp_ring.base = pci_alloc_consistent(adapter->pdev, sz,
1236 &rq->comp_ring.basePA);
1237 if (!rq->comp_ring.base) {
1238 printk(KERN_ERR "%s: failed to allocate rx comp ring\n",
1239 adapter->netdev->name);
1240 goto err;
1241 }
1242
1243 sz = sizeof(struct vmxnet3_rx_buf_info) * (rq->rx_ring[0].size +
1244 rq->rx_ring[1].size);
1245 bi = kmalloc(sz, GFP_KERNEL);
1246 if (!bi) {
1247 printk(KERN_ERR "%s: failed to allocate rx bufinfo\n",
1248 adapter->netdev->name);
1249 goto err;
1250 }
1251 memset(bi, 0, sz);
1252 rq->buf_info[0] = bi;
1253 rq->buf_info[1] = bi + rq->rx_ring[0].size;
1254
1255 return 0;
1256
1257err:
1258 vmxnet3_rq_destroy(rq, adapter);
1259 return -ENOMEM;
1260}
1261
1262
1263static int
1264vmxnet3_do_poll(struct vmxnet3_adapter *adapter, int budget)
1265{
1266 if (unlikely(adapter->shared->ecr))
1267 vmxnet3_process_events(adapter);
1268
1269 vmxnet3_tq_tx_complete(&adapter->tx_queue, adapter);
1270 return vmxnet3_rq_rx_complete(&adapter->rx_queue, adapter, budget);
1271}
1272
1273
1274static int
1275vmxnet3_poll(struct napi_struct *napi, int budget)
1276{
1277 struct vmxnet3_adapter *adapter = container_of(napi,
1278 struct vmxnet3_adapter, napi);
1279 int rxd_done;
1280
1281 rxd_done = vmxnet3_do_poll(adapter, budget);
1282
1283 if (rxd_done < budget) {
1284 napi_complete(napi);
1285 vmxnet3_enable_intr(adapter, 0);
1286 }
1287 return rxd_done;
1288}
1289
1290
1291/* Interrupt handler for vmxnet3 */
1292static irqreturn_t
1293vmxnet3_intr(int irq, void *dev_id)
1294{
1295 struct net_device *dev = dev_id;
1296 struct vmxnet3_adapter *adapter = netdev_priv(dev);
1297
1298 if (unlikely(adapter->intr.type == VMXNET3_IT_INTX)) {
1299 u32 icr = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ICR);
1300 if (unlikely(icr == 0))
1301 /* not ours */
1302 return IRQ_NONE;
1303 }
1304
1305
1306 /* disable intr if needed */
1307 if (adapter->intr.mask_mode == VMXNET3_IMM_ACTIVE)
1308 vmxnet3_disable_intr(adapter, 0);
1309
1310 napi_schedule(&adapter->napi);
1311
1312 return IRQ_HANDLED;
1313}
1314
1315#ifdef CONFIG_NET_POLL_CONTROLLER
1316
1317
1318/* netpoll callback. */
1319static void
1320vmxnet3_netpoll(struct net_device *netdev)
1321{
1322 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1323 int irq;
1324
1325#ifdef CONFIG_PCI_MSI
1326 if (adapter->intr.type == VMXNET3_IT_MSIX)
1327 irq = adapter->intr.msix_entries[0].vector;
1328 else
1329#endif
1330 irq = adapter->pdev->irq;
1331
1332 disable_irq(irq);
1333 vmxnet3_intr(irq, netdev);
1334 enable_irq(irq);
1335}
1336#endif
1337
1338static int
1339vmxnet3_request_irqs(struct vmxnet3_adapter *adapter)
1340{
1341 int err;
1342
1343#ifdef CONFIG_PCI_MSI
1344 if (adapter->intr.type == VMXNET3_IT_MSIX) {
1345 /* we only use 1 MSI-X vector */
1346 err = request_irq(adapter->intr.msix_entries[0].vector,
1347 vmxnet3_intr, 0, adapter->netdev->name,
1348 adapter->netdev);
1349 } else
1350#endif
1351 if (adapter->intr.type == VMXNET3_IT_MSI) {
1352 err = request_irq(adapter->pdev->irq, vmxnet3_intr, 0,
1353 adapter->netdev->name, adapter->netdev);
1354 } else {
1355 err = request_irq(adapter->pdev->irq, vmxnet3_intr,
1356 IRQF_SHARED, adapter->netdev->name,
1357 adapter->netdev);
1358 }
1359
1360 if (err)
1361 printk(KERN_ERR "Failed to request irq %s (intr type:%d), error"
1362 ":%d\n", adapter->netdev->name, adapter->intr.type, err);
1363
1364
1365 if (!err) {
1366 int i;
1367 /* init our intr settings */
1368 for (i = 0; i < adapter->intr.num_intrs; i++)
1369 adapter->intr.mod_levels[i] = UPT1_IML_ADAPTIVE;
1370
1371 /* next setup intr index for all intr sources */
1372 adapter->tx_queue.comp_ring.intr_idx = 0;
1373 adapter->rx_queue.comp_ring.intr_idx = 0;
1374 adapter->intr.event_intr_idx = 0;
1375
1376 printk(KERN_INFO "%s: intr type %u, mode %u, %u vectors "
1377 "allocated\n", adapter->netdev->name, adapter->intr.type,
1378 adapter->intr.mask_mode, adapter->intr.num_intrs);
1379 }
1380
1381 return err;
1382}
1383
1384
1385static void
1386vmxnet3_free_irqs(struct vmxnet3_adapter *adapter)
1387{
1388 BUG_ON(adapter->intr.type == VMXNET3_IT_AUTO ||
1389 adapter->intr.num_intrs <= 0);
1390
1391 switch (adapter->intr.type) {
1392#ifdef CONFIG_PCI_MSI
1393 case VMXNET3_IT_MSIX:
1394 {
1395 int i;
1396
1397 for (i = 0; i < adapter->intr.num_intrs; i++)
1398 free_irq(adapter->intr.msix_entries[i].vector,
1399 adapter->netdev);
1400 break;
1401 }
1402#endif
1403 case VMXNET3_IT_MSI:
1404 free_irq(adapter->pdev->irq, adapter->netdev);
1405 break;
1406 case VMXNET3_IT_INTX:
1407 free_irq(adapter->pdev->irq, adapter->netdev);
1408 break;
1409 default:
1410 BUG_ON(true);
1411 }
1412}
1413
1414
1415static void
1416vmxnet3_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
1417{
1418 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1419 struct Vmxnet3_DriverShared *shared = adapter->shared;
1420 u32 *vfTable = adapter->shared->devRead.rxFilterConf.vfTable;
1421
1422 if (grp) {
1423 /* add vlan rx stripping. */
1424 if (adapter->netdev->features & NETIF_F_HW_VLAN_RX) {
1425 int i;
1426 struct Vmxnet3_DSDevRead *devRead = &shared->devRead;
1427 adapter->vlan_grp = grp;
1428
1429 /* update FEATURES to device */
1430 devRead->misc.uptFeatures |= UPT1_F_RXVLAN;
1431 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1432 VMXNET3_CMD_UPDATE_FEATURE);
1433 /*
1434 * Clear entire vfTable; then enable untagged pkts.
1435 * Note: setting one entry in vfTable to non-zero turns
1436 * on VLAN rx filtering.
1437 */
1438 for (i = 0; i < VMXNET3_VFT_SIZE; i++)
1439 vfTable[i] = 0;
1440
1441 VMXNET3_SET_VFTABLE_ENTRY(vfTable, 0);
1442 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1443 VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1444 } else {
1445 printk(KERN_ERR "%s: vlan_rx_register when device has "
1446 "no NETIF_F_HW_VLAN_RX\n", netdev->name);
1447 }
1448 } else {
1449 /* remove vlan rx stripping. */
1450 struct Vmxnet3_DSDevRead *devRead = &shared->devRead;
1451 adapter->vlan_grp = NULL;
1452
1453 if (devRead->misc.uptFeatures & UPT1_F_RXVLAN) {
1454 int i;
1455
1456 for (i = 0; i < VMXNET3_VFT_SIZE; i++) {
1457 /* clear entire vfTable; this also disables
1458 * VLAN rx filtering
1459 */
1460 vfTable[i] = 0;
1461 }
1462 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1463 VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1464
1465 /* update FEATURES to device */
1466 devRead->misc.uptFeatures &= ~UPT1_F_RXVLAN;
1467 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1468 VMXNET3_CMD_UPDATE_FEATURE);
1469 }
1470 }
1471}
1472
1473
1474static void
1475vmxnet3_restore_vlan(struct vmxnet3_adapter *adapter)
1476{
1477 if (adapter->vlan_grp) {
1478 u16 vid;
1479 u32 *vfTable = adapter->shared->devRead.rxFilterConf.vfTable;
1480 bool activeVlan = false;
1481
1482 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1483 if (vlan_group_get_device(adapter->vlan_grp, vid)) {
1484 VMXNET3_SET_VFTABLE_ENTRY(vfTable, vid);
1485 activeVlan = true;
1486 }
1487 }
1488 if (activeVlan) {
1489 /* continue to allow untagged pkts */
1490 VMXNET3_SET_VFTABLE_ENTRY(vfTable, 0);
1491 }
1492 }
1493}
1494
1495
1496static void
1497vmxnet3_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1498{
1499 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1500 u32 *vfTable = adapter->shared->devRead.rxFilterConf.vfTable;
1501
1502 VMXNET3_SET_VFTABLE_ENTRY(vfTable, vid);
1503 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1504 VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1505}
1506
1507
1508static void
1509vmxnet3_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1510{
1511 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1512 u32 *vfTable = adapter->shared->devRead.rxFilterConf.vfTable;
1513
1514 VMXNET3_CLEAR_VFTABLE_ENTRY(vfTable, vid);
1515 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1516 VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1517}
1518
1519
1520static u8 *
1521vmxnet3_copy_mc(struct net_device *netdev)
1522{
1523 u8 *buf = NULL;
1524 u32 sz = netdev->mc_count * ETH_ALEN;
1525
1526 /* struct Vmxnet3_RxFilterConf.mfTableLen is u16. */
1527 if (sz <= 0xffff) {
1528 /* We may be called with BH disabled */
1529 buf = kmalloc(sz, GFP_ATOMIC);
1530 if (buf) {
1531 int i;
1532 struct dev_mc_list *mc = netdev->mc_list;
1533
1534 for (i = 0; i < netdev->mc_count; i++) {
1535 BUG_ON(!mc);
1536 memcpy(buf + i * ETH_ALEN, mc->dmi_addr,
1537 ETH_ALEN);
1538 mc = mc->next;
1539 }
1540 }
1541 }
1542 return buf;
1543}
1544
1545
1546static void
1547vmxnet3_set_mc(struct net_device *netdev)
1548{
1549 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1550 struct Vmxnet3_RxFilterConf *rxConf =
1551 &adapter->shared->devRead.rxFilterConf;
1552 u8 *new_table = NULL;
1553 u32 new_mode = VMXNET3_RXM_UCAST;
1554
1555 if (netdev->flags & IFF_PROMISC)
1556 new_mode |= VMXNET3_RXM_PROMISC;
1557
1558 if (netdev->flags & IFF_BROADCAST)
1559 new_mode |= VMXNET3_RXM_BCAST;
1560
1561 if (netdev->flags & IFF_ALLMULTI)
1562 new_mode |= VMXNET3_RXM_ALL_MULTI;
1563 else
1564 if (netdev->mc_count > 0) {
1565 new_table = vmxnet3_copy_mc(netdev);
1566 if (new_table) {
1567 new_mode |= VMXNET3_RXM_MCAST;
1568 rxConf->mfTableLen = netdev->mc_count *
1569 ETH_ALEN;
1570 rxConf->mfTablePA = virt_to_phys(new_table);
1571 } else {
1572 printk(KERN_INFO "%s: failed to copy mcast list"
1573 ", setting ALL_MULTI\n", netdev->name);
1574 new_mode |= VMXNET3_RXM_ALL_MULTI;
1575 }
1576 }
1577
1578
1579 if (!(new_mode & VMXNET3_RXM_MCAST)) {
1580 rxConf->mfTableLen = 0;
1581 rxConf->mfTablePA = 0;
1582 }
1583
1584 if (new_mode != rxConf->rxMode) {
1585 rxConf->rxMode = new_mode;
1586 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1587 VMXNET3_CMD_UPDATE_RX_MODE);
1588 }
1589
1590 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1591 VMXNET3_CMD_UPDATE_MAC_FILTERS);
1592
1593 kfree(new_table);
1594}
1595
1596
1597/*
1598 * Set up driver_shared based on settings in adapter.
1599 */
1600
1601static void
1602vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter)
1603{
1604 struct Vmxnet3_DriverShared *shared = adapter->shared;
1605 struct Vmxnet3_DSDevRead *devRead = &shared->devRead;
1606 struct Vmxnet3_TxQueueConf *tqc;
1607 struct Vmxnet3_RxQueueConf *rqc;
1608 int i;
1609
1610 memset(shared, 0, sizeof(*shared));
1611
1612 /* driver settings */
1613 shared->magic = VMXNET3_REV1_MAGIC;
1614 devRead->misc.driverInfo.version = VMXNET3_DRIVER_VERSION_NUM;
1615 devRead->misc.driverInfo.gos.gosBits = (sizeof(void *) == 4 ?
1616 VMXNET3_GOS_BITS_32 : VMXNET3_GOS_BITS_64);
1617 devRead->misc.driverInfo.gos.gosType = VMXNET3_GOS_TYPE_LINUX;
1618 devRead->misc.driverInfo.vmxnet3RevSpt = 1;
1619 devRead->misc.driverInfo.uptVerSpt = 1;
1620
1621 devRead->misc.ddPA = virt_to_phys(adapter);
1622 devRead->misc.ddLen = sizeof(struct vmxnet3_adapter);
1623
1624 /* set up feature flags */
1625 if (adapter->rxcsum)
1626 devRead->misc.uptFeatures |= UPT1_F_RXCSUM;
1627
1628 if (adapter->lro) {
1629 devRead->misc.uptFeatures |= UPT1_F_LRO;
1630 devRead->misc.maxNumRxSG = 1 + MAX_SKB_FRAGS;
1631 }
1632 if ((adapter->netdev->features & NETIF_F_HW_VLAN_RX)
1633 && adapter->vlan_grp) {
1634 devRead->misc.uptFeatures |= UPT1_F_RXVLAN;
1635 }
1636
1637 devRead->misc.mtu = adapter->netdev->mtu;
1638 devRead->misc.queueDescPA = adapter->queue_desc_pa;
1639 devRead->misc.queueDescLen = sizeof(struct Vmxnet3_TxQueueDesc) +
1640 sizeof(struct Vmxnet3_RxQueueDesc);
1641
1642 /* tx queue settings */
1643 BUG_ON(adapter->tx_queue.tx_ring.base == NULL);
1644
1645 devRead->misc.numTxQueues = 1;
1646 tqc = &adapter->tqd_start->conf;
1647 tqc->txRingBasePA = adapter->tx_queue.tx_ring.basePA;
1648 tqc->dataRingBasePA = adapter->tx_queue.data_ring.basePA;
1649 tqc->compRingBasePA = adapter->tx_queue.comp_ring.basePA;
1650 tqc->ddPA = virt_to_phys(adapter->tx_queue.buf_info);
1651 tqc->txRingSize = adapter->tx_queue.tx_ring.size;
1652 tqc->dataRingSize = adapter->tx_queue.data_ring.size;
1653 tqc->compRingSize = adapter->tx_queue.comp_ring.size;
1654 tqc->ddLen = sizeof(struct vmxnet3_tx_buf_info) *
1655 tqc->txRingSize;
1656 tqc->intrIdx = adapter->tx_queue.comp_ring.intr_idx;
1657
1658 /* rx queue settings */
1659 devRead->misc.numRxQueues = 1;
1660 rqc = &adapter->rqd_start->conf;
1661 rqc->rxRingBasePA[0] = adapter->rx_queue.rx_ring[0].basePA;
1662 rqc->rxRingBasePA[1] = adapter->rx_queue.rx_ring[1].basePA;
1663 rqc->compRingBasePA = adapter->rx_queue.comp_ring.basePA;
1664 rqc->ddPA = virt_to_phys(adapter->rx_queue.buf_info);
1665 rqc->rxRingSize[0] = adapter->rx_queue.rx_ring[0].size;
1666 rqc->rxRingSize[1] = adapter->rx_queue.rx_ring[1].size;
1667 rqc->compRingSize = adapter->rx_queue.comp_ring.size;
1668 rqc->ddLen = sizeof(struct vmxnet3_rx_buf_info) *
1669 (rqc->rxRingSize[0] + rqc->rxRingSize[1]);
1670 rqc->intrIdx = adapter->rx_queue.comp_ring.intr_idx;
1671
1672 /* intr settings */
1673 devRead->intrConf.autoMask = adapter->intr.mask_mode ==
1674 VMXNET3_IMM_AUTO;
1675 devRead->intrConf.numIntrs = adapter->intr.num_intrs;
1676 for (i = 0; i < adapter->intr.num_intrs; i++)
1677 devRead->intrConf.modLevels[i] = adapter->intr.mod_levels[i];
1678
1679 devRead->intrConf.eventIntrIdx = adapter->intr.event_intr_idx;
1680
1681 /* rx filter settings */
1682 devRead->rxFilterConf.rxMode = 0;
1683 vmxnet3_restore_vlan(adapter);
1684 /* the rest are already zeroed */
1685}
1686
1687
1688int
1689vmxnet3_activate_dev(struct vmxnet3_adapter *adapter)
1690{
1691 int err;
1692 u32 ret;
1693
1694 dev_dbg(&adapter->netdev->dev,
1695 "%s: skb_buf_size %d, rx_buf_per_pkt %d, ring sizes"
1696 " %u %u %u\n", adapter->netdev->name, adapter->skb_buf_size,
1697 adapter->rx_buf_per_pkt, adapter->tx_queue.tx_ring.size,
1698 adapter->rx_queue.rx_ring[0].size,
1699 adapter->rx_queue.rx_ring[1].size);
1700
1701 vmxnet3_tq_init(&adapter->tx_queue, adapter);
1702 err = vmxnet3_rq_init(&adapter->rx_queue, adapter);
1703 if (err) {
1704 printk(KERN_ERR "Failed to init rx queue for %s: error %d\n",
1705 adapter->netdev->name, err);
1706 goto rq_err;
1707 }
1708
1709 err = vmxnet3_request_irqs(adapter);
1710 if (err) {
1711 printk(KERN_ERR "Failed to setup irq for %s: error %d\n",
1712 adapter->netdev->name, err);
1713 goto irq_err;
1714 }
1715
1716 vmxnet3_setup_driver_shared(adapter);
1717
1718 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_DSAL,
1719 VMXNET3_GET_ADDR_LO(adapter->shared_pa));
1720 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_DSAH,
1721 VMXNET3_GET_ADDR_HI(adapter->shared_pa));
1722
1723 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1724 VMXNET3_CMD_ACTIVATE_DEV);
1725 ret = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
1726
1727 if (ret != 0) {
1728 printk(KERN_ERR "Failed to activate dev %s: error %u\n",
1729 adapter->netdev->name, ret);
1730 err = -EINVAL;
1731 goto activate_err;
1732 }
1733 VMXNET3_WRITE_BAR0_REG(adapter, VMXNET3_REG_RXPROD,
1734 adapter->rx_queue.rx_ring[0].next2fill);
1735 VMXNET3_WRITE_BAR0_REG(adapter, VMXNET3_REG_RXPROD2,
1736 adapter->rx_queue.rx_ring[1].next2fill);
1737
1738 /* Apply the rx filter settins last. */
1739 vmxnet3_set_mc(adapter->netdev);
1740
1741 /*
1742 * Check link state when first activating device. It will start the
1743 * tx queue if the link is up.
1744 */
1745 vmxnet3_check_link(adapter);
1746
1747 napi_enable(&adapter->napi);
1748 vmxnet3_enable_all_intrs(adapter);
1749 clear_bit(VMXNET3_STATE_BIT_QUIESCED, &adapter->state);
1750 return 0;
1751
1752activate_err:
1753 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_DSAL, 0);
1754 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_DSAH, 0);
1755 vmxnet3_free_irqs(adapter);
1756irq_err:
1757rq_err:
1758 /* free up buffers we allocated */
1759 vmxnet3_rq_cleanup(&adapter->rx_queue, adapter);
1760 return err;
1761}
1762
1763
1764void
1765vmxnet3_reset_dev(struct vmxnet3_adapter *adapter)
1766{
1767 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_RESET_DEV);
1768}
1769
1770
1771int
1772vmxnet3_quiesce_dev(struct vmxnet3_adapter *adapter)
1773{
1774 if (test_and_set_bit(VMXNET3_STATE_BIT_QUIESCED, &adapter->state))
1775 return 0;
1776
1777
1778 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1779 VMXNET3_CMD_QUIESCE_DEV);
1780 vmxnet3_disable_all_intrs(adapter);
1781
1782 napi_disable(&adapter->napi);
1783 netif_tx_disable(adapter->netdev);
1784 adapter->link_speed = 0;
1785 netif_carrier_off(adapter->netdev);
1786
1787 vmxnet3_tq_cleanup(&adapter->tx_queue, adapter);
1788 vmxnet3_rq_cleanup(&adapter->rx_queue, adapter);
1789 vmxnet3_free_irqs(adapter);
1790 return 0;
1791}
1792
1793
1794static void
1795vmxnet3_write_mac_addr(struct vmxnet3_adapter *adapter, u8 *mac)
1796{
1797 u32 tmp;
1798
1799 tmp = *(u32 *)mac;
1800 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_MACL, tmp);
1801
1802 tmp = (mac[5] << 8) | mac[4];
1803 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_MACH, tmp);
1804}
1805
1806
1807static int
1808vmxnet3_set_mac_addr(struct net_device *netdev, void *p)
1809{
1810 struct sockaddr *addr = p;
1811 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1812
1813 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1814 vmxnet3_write_mac_addr(adapter, addr->sa_data);
1815
1816 return 0;
1817}
1818
1819
1820/* ==================== initialization and cleanup routines ============ */
1821
1822static int
1823vmxnet3_alloc_pci_resources(struct vmxnet3_adapter *adapter, bool *dma64)
1824{
1825 int err;
1826 unsigned long mmio_start, mmio_len;
1827 struct pci_dev *pdev = adapter->pdev;
1828
1829 err = pci_enable_device(pdev);
1830 if (err) {
1831 printk(KERN_ERR "Failed to enable adapter %s: error %d\n",
1832 pci_name(pdev), err);
1833 return err;
1834 }
1835
1836 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) {
1837 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {
1838 printk(KERN_ERR "pci_set_consistent_dma_mask failed "
1839 "for adapter %s\n", pci_name(pdev));
1840 err = -EIO;
1841 goto err_set_mask;
1842 }
1843 *dma64 = true;
1844 } else {
1845 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
1846 printk(KERN_ERR "pci_set_dma_mask failed for adapter "
1847 "%s\n", pci_name(pdev));
1848 err = -EIO;
1849 goto err_set_mask;
1850 }
1851 *dma64 = false;
1852 }
1853
1854 err = pci_request_selected_regions(pdev, (1 << 2) - 1,
1855 vmxnet3_driver_name);
1856 if (err) {
1857 printk(KERN_ERR "Failed to request region for adapter %s: "
1858 "error %d\n", pci_name(pdev), err);
1859 goto err_set_mask;
1860 }
1861
1862 pci_set_master(pdev);
1863
1864 mmio_start = pci_resource_start(pdev, 0);
1865 mmio_len = pci_resource_len(pdev, 0);
1866 adapter->hw_addr0 = ioremap(mmio_start, mmio_len);
1867 if (!adapter->hw_addr0) {
1868 printk(KERN_ERR "Failed to map bar0 for adapter %s\n",
1869 pci_name(pdev));
1870 err = -EIO;
1871 goto err_ioremap;
1872 }
1873
1874 mmio_start = pci_resource_start(pdev, 1);
1875 mmio_len = pci_resource_len(pdev, 1);
1876 adapter->hw_addr1 = ioremap(mmio_start, mmio_len);
1877 if (!adapter->hw_addr1) {
1878 printk(KERN_ERR "Failed to map bar1 for adapter %s\n",
1879 pci_name(pdev));
1880 err = -EIO;
1881 goto err_bar1;
1882 }
1883 return 0;
1884
1885err_bar1:
1886 iounmap(adapter->hw_addr0);
1887err_ioremap:
1888 pci_release_selected_regions(pdev, (1 << 2) - 1);
1889err_set_mask:
1890 pci_disable_device(pdev);
1891 return err;
1892}
1893
1894
1895static void
1896vmxnet3_free_pci_resources(struct vmxnet3_adapter *adapter)
1897{
1898 BUG_ON(!adapter->pdev);
1899
1900 iounmap(adapter->hw_addr0);
1901 iounmap(adapter->hw_addr1);
1902 pci_release_selected_regions(adapter->pdev, (1 << 2) - 1);
1903 pci_disable_device(adapter->pdev);
1904}
1905
1906
1907static void
1908vmxnet3_adjust_rx_ring_size(struct vmxnet3_adapter *adapter)
1909{
1910 size_t sz;
1911
1912 if (adapter->netdev->mtu <= VMXNET3_MAX_SKB_BUF_SIZE -
1913 VMXNET3_MAX_ETH_HDR_SIZE) {
1914 adapter->skb_buf_size = adapter->netdev->mtu +
1915 VMXNET3_MAX_ETH_HDR_SIZE;
1916 if (adapter->skb_buf_size < VMXNET3_MIN_T0_BUF_SIZE)
1917 adapter->skb_buf_size = VMXNET3_MIN_T0_BUF_SIZE;
1918
1919 adapter->rx_buf_per_pkt = 1;
1920 } else {
1921 adapter->skb_buf_size = VMXNET3_MAX_SKB_BUF_SIZE;
1922 sz = adapter->netdev->mtu - VMXNET3_MAX_SKB_BUF_SIZE +
1923 VMXNET3_MAX_ETH_HDR_SIZE;
1924 adapter->rx_buf_per_pkt = 1 + (sz + PAGE_SIZE - 1) / PAGE_SIZE;
1925 }
1926
1927 /*
1928 * for simplicity, force the ring0 size to be a multiple of
1929 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
1930 */
1931 sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
1932 adapter->rx_queue.rx_ring[0].size = (adapter->rx_queue.rx_ring[0].size +
1933 sz - 1) / sz * sz;
1934 adapter->rx_queue.rx_ring[0].size = min_t(u32,
1935 adapter->rx_queue.rx_ring[0].size,
1936 VMXNET3_RX_RING_MAX_SIZE / sz * sz);
1937}
1938
1939
1940int
1941vmxnet3_create_queues(struct vmxnet3_adapter *adapter, u32 tx_ring_size,
1942 u32 rx_ring_size, u32 rx_ring2_size)
1943{
1944 int err;
1945
1946 adapter->tx_queue.tx_ring.size = tx_ring_size;
1947 adapter->tx_queue.data_ring.size = tx_ring_size;
1948 adapter->tx_queue.comp_ring.size = tx_ring_size;
1949 adapter->tx_queue.shared = &adapter->tqd_start->ctrl;
1950 adapter->tx_queue.stopped = true;
1951 err = vmxnet3_tq_create(&adapter->tx_queue, adapter);
1952 if (err)
1953 return err;
1954
1955 adapter->rx_queue.rx_ring[0].size = rx_ring_size;
1956 adapter->rx_queue.rx_ring[1].size = rx_ring2_size;
1957 vmxnet3_adjust_rx_ring_size(adapter);
1958 adapter->rx_queue.comp_ring.size = adapter->rx_queue.rx_ring[0].size +
1959 adapter->rx_queue.rx_ring[1].size;
1960 adapter->rx_queue.qid = 0;
1961 adapter->rx_queue.qid2 = 1;
1962 adapter->rx_queue.shared = &adapter->rqd_start->ctrl;
1963 err = vmxnet3_rq_create(&adapter->rx_queue, adapter);
1964 if (err)
1965 vmxnet3_tq_destroy(&adapter->tx_queue, adapter);
1966
1967 return err;
1968}
1969
1970static int
1971vmxnet3_open(struct net_device *netdev)
1972{
1973 struct vmxnet3_adapter *adapter;
1974 int err;
1975
1976 adapter = netdev_priv(netdev);
1977
1978 spin_lock_init(&adapter->tx_queue.tx_lock);
1979
1980 err = vmxnet3_create_queues(adapter, VMXNET3_DEF_TX_RING_SIZE,
1981 VMXNET3_DEF_RX_RING_SIZE,
1982 VMXNET3_DEF_RX_RING_SIZE);
1983 if (err)
1984 goto queue_err;
1985
1986 err = vmxnet3_activate_dev(adapter);
1987 if (err)
1988 goto activate_err;
1989
1990 return 0;
1991
1992activate_err:
1993 vmxnet3_rq_destroy(&adapter->rx_queue, adapter);
1994 vmxnet3_tq_destroy(&adapter->tx_queue, adapter);
1995queue_err:
1996 return err;
1997}
1998
1999
2000static int
2001vmxnet3_close(struct net_device *netdev)
2002{
2003 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
2004
2005 /*
2006 * Reset_work may be in the middle of resetting the device, wait for its
2007 * completion.
2008 */
2009 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
2010 msleep(1);
2011
2012 vmxnet3_quiesce_dev(adapter);
2013
2014 vmxnet3_rq_destroy(&adapter->rx_queue, adapter);
2015 vmxnet3_tq_destroy(&adapter->tx_queue, adapter);
2016
2017 clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
2018
2019
2020 return 0;
2021}
2022
2023
2024void
2025vmxnet3_force_close(struct vmxnet3_adapter *adapter)
2026{
2027 /*
2028 * we must clear VMXNET3_STATE_BIT_RESETTING, otherwise
2029 * vmxnet3_close() will deadlock.
2030 */
2031 BUG_ON(test_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state));
2032
2033 /* we need to enable NAPI, otherwise dev_close will deadlock */
2034 napi_enable(&adapter->napi);
2035 dev_close(adapter->netdev);
2036}
2037
2038
2039static int
2040vmxnet3_change_mtu(struct net_device *netdev, int new_mtu)
2041{
2042 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
2043 int err = 0;
2044
2045 if (new_mtu < VMXNET3_MIN_MTU || new_mtu > VMXNET3_MAX_MTU)
2046 return -EINVAL;
2047
2048 if (new_mtu > 1500 && !adapter->jumbo_frame)
2049 return -EINVAL;
2050
2051 netdev->mtu = new_mtu;
2052
2053 /*
2054 * Reset_work may be in the middle of resetting the device, wait for its
2055 * completion.
2056 */
2057 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
2058 msleep(1);
2059
2060 if (netif_running(netdev)) {
2061 vmxnet3_quiesce_dev(adapter);
2062 vmxnet3_reset_dev(adapter);
2063
2064 /* we need to re-create the rx queue based on the new mtu */
2065 vmxnet3_rq_destroy(&adapter->rx_queue, adapter);
2066 vmxnet3_adjust_rx_ring_size(adapter);
2067 adapter->rx_queue.comp_ring.size =
2068 adapter->rx_queue.rx_ring[0].size +
2069 adapter->rx_queue.rx_ring[1].size;
2070 err = vmxnet3_rq_create(&adapter->rx_queue, adapter);
2071 if (err) {
2072 printk(KERN_ERR "%s: failed to re-create rx queue,"
2073 " error %d. Closing it.\n", netdev->name, err);
2074 goto out;
2075 }
2076
2077 err = vmxnet3_activate_dev(adapter);
2078 if (err) {
2079 printk(KERN_ERR "%s: failed to re-activate, error %d. "
2080 "Closing it\n", netdev->name, err);
2081 goto out;
2082 }
2083 }
2084
2085out:
2086 clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
2087 if (err)
2088 vmxnet3_force_close(adapter);
2089
2090 return err;
2091}
2092
2093
2094static void
2095vmxnet3_declare_features(struct vmxnet3_adapter *adapter, bool dma64)
2096{
2097 struct net_device *netdev = adapter->netdev;
2098
2099 netdev->features = NETIF_F_SG |
2100 NETIF_F_HW_CSUM |
2101 NETIF_F_HW_VLAN_TX |
2102 NETIF_F_HW_VLAN_RX |
2103 NETIF_F_HW_VLAN_FILTER |
2104 NETIF_F_TSO |
2105 NETIF_F_TSO6 |
2106 NETIF_F_LRO;
2107
2108 printk(KERN_INFO "features: sg csum vlan jf tso tsoIPv6 lro");
2109
2110 adapter->rxcsum = true;
2111 adapter->jumbo_frame = true;
2112 adapter->lro = true;
2113
2114 if (dma64) {
2115 netdev->features |= NETIF_F_HIGHDMA;
2116 printk(" highDMA");
2117 }
2118
2119 netdev->vlan_features = netdev->features;
2120 printk("\n");
2121}
2122
2123
2124static void
2125vmxnet3_read_mac_addr(struct vmxnet3_adapter *adapter, u8 *mac)
2126{
2127 u32 tmp;
2128
2129 tmp = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACL);
2130 *(u32 *)mac = tmp;
2131
2132 tmp = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACH);
2133 mac[4] = tmp & 0xff;
2134 mac[5] = (tmp >> 8) & 0xff;
2135}
2136
2137
2138static void
2139vmxnet3_alloc_intr_resources(struct vmxnet3_adapter *adapter)
2140{
2141 u32 cfg;
2142
2143 /* intr settings */
2144 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
2145 VMXNET3_CMD_GET_CONF_INTR);
2146 cfg = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
2147 adapter->intr.type = cfg & 0x3;
2148 adapter->intr.mask_mode = (cfg >> 2) & 0x3;
2149
2150 if (adapter->intr.type == VMXNET3_IT_AUTO) {
2151 int err;
2152
2153#ifdef CONFIG_PCI_MSI
2154 adapter->intr.msix_entries[0].entry = 0;
2155 err = pci_enable_msix(adapter->pdev, adapter->intr.msix_entries,
2156 VMXNET3_LINUX_MAX_MSIX_VECT);
2157 if (!err) {
2158 adapter->intr.num_intrs = 1;
2159 adapter->intr.type = VMXNET3_IT_MSIX;
2160 return;
2161 }
2162#endif
2163
2164 err = pci_enable_msi(adapter->pdev);
2165 if (!err) {
2166 adapter->intr.num_intrs = 1;
2167 adapter->intr.type = VMXNET3_IT_MSI;
2168 return;
2169 }
2170 }
2171
2172 adapter->intr.type = VMXNET3_IT_INTX;
2173
2174 /* INT-X related setting */
2175 adapter->intr.num_intrs = 1;
2176}
2177
2178
2179static void
2180vmxnet3_free_intr_resources(struct vmxnet3_adapter *adapter)
2181{
2182 if (adapter->intr.type == VMXNET3_IT_MSIX)
2183 pci_disable_msix(adapter->pdev);
2184 else if (adapter->intr.type == VMXNET3_IT_MSI)
2185 pci_disable_msi(adapter->pdev);
2186 else
2187 BUG_ON(adapter->intr.type != VMXNET3_IT_INTX);
2188}
2189
2190
2191static void
2192vmxnet3_tx_timeout(struct net_device *netdev)
2193{
2194 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
2195 adapter->tx_timeout_count++;
2196
2197 printk(KERN_ERR "%s: tx hang\n", adapter->netdev->name);
2198 schedule_work(&adapter->work);
2199}
2200
2201
2202static void
2203vmxnet3_reset_work(struct work_struct *data)
2204{
2205 struct vmxnet3_adapter *adapter;
2206
2207 adapter = container_of(data, struct vmxnet3_adapter, work);
2208
2209 /* if another thread is resetting the device, no need to proceed */
2210 if (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
2211 return;
2212
2213 /* if the device is closed, we must leave it alone */
2214 if (netif_running(adapter->netdev)) {
2215 printk(KERN_INFO "%s: resetting\n", adapter->netdev->name);
2216 vmxnet3_quiesce_dev(adapter);
2217 vmxnet3_reset_dev(adapter);
2218 vmxnet3_activate_dev(adapter);
2219 } else {
2220 printk(KERN_INFO "%s: already closed\n", adapter->netdev->name);
2221 }
2222
2223 clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
2224}
2225
2226
2227static int __devinit
2228vmxnet3_probe_device(struct pci_dev *pdev,
2229 const struct pci_device_id *id)
2230{
2231 static const struct net_device_ops vmxnet3_netdev_ops = {
2232 .ndo_open = vmxnet3_open,
2233 .ndo_stop = vmxnet3_close,
2234 .ndo_start_xmit = vmxnet3_xmit_frame,
2235 .ndo_set_mac_address = vmxnet3_set_mac_addr,
2236 .ndo_change_mtu = vmxnet3_change_mtu,
2237 .ndo_get_stats = vmxnet3_get_stats,
2238 .ndo_tx_timeout = vmxnet3_tx_timeout,
2239 .ndo_set_multicast_list = vmxnet3_set_mc,
2240 .ndo_vlan_rx_register = vmxnet3_vlan_rx_register,
2241 .ndo_vlan_rx_add_vid = vmxnet3_vlan_rx_add_vid,
2242 .ndo_vlan_rx_kill_vid = vmxnet3_vlan_rx_kill_vid,
2243#ifdef CONFIG_NET_POLL_CONTROLLER
2244 .ndo_poll_controller = vmxnet3_netpoll,
2245#endif
2246 };
2247 int err;
2248 bool dma64 = false; /* stupid gcc */
2249 u32 ver;
2250 struct net_device *netdev;
2251 struct vmxnet3_adapter *adapter;
2252 u8 mac[ETH_ALEN];
2253
2254 netdev = alloc_etherdev(sizeof(struct vmxnet3_adapter));
2255 if (!netdev) {
2256 printk(KERN_ERR "Failed to alloc ethernet device for adapter "
2257 "%s\n", pci_name(pdev));
2258 return -ENOMEM;
2259 }
2260
2261 pci_set_drvdata(pdev, netdev);
2262 adapter = netdev_priv(netdev);
2263 adapter->netdev = netdev;
2264 adapter->pdev = pdev;
2265
2266 adapter->shared = pci_alloc_consistent(adapter->pdev,
2267 sizeof(struct Vmxnet3_DriverShared),
2268 &adapter->shared_pa);
2269 if (!adapter->shared) {
2270 printk(KERN_ERR "Failed to allocate memory for %s\n",
2271 pci_name(pdev));
2272 err = -ENOMEM;
2273 goto err_alloc_shared;
2274 }
2275
2276 adapter->tqd_start = pci_alloc_consistent(adapter->pdev,
2277 sizeof(struct Vmxnet3_TxQueueDesc) +
2278 sizeof(struct Vmxnet3_RxQueueDesc),
2279 &adapter->queue_desc_pa);
2280
2281 if (!adapter->tqd_start) {
2282 printk(KERN_ERR "Failed to allocate memory for %s\n",
2283 pci_name(pdev));
2284 err = -ENOMEM;
2285 goto err_alloc_queue_desc;
2286 }
2287 adapter->rqd_start = (struct Vmxnet3_RxQueueDesc *)(adapter->tqd_start
2288 + 1);
2289
2290 adapter->pm_conf = kmalloc(sizeof(struct Vmxnet3_PMConf), GFP_KERNEL);
2291 if (adapter->pm_conf == NULL) {
2292 printk(KERN_ERR "Failed to allocate memory for %s\n",
2293 pci_name(pdev));
2294 err = -ENOMEM;
2295 goto err_alloc_pm;
2296 }
2297
2298 err = vmxnet3_alloc_pci_resources(adapter, &dma64);
2299 if (err < 0)
2300 goto err_alloc_pci;
2301
2302 ver = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_VRRS);
2303 if (ver & 1) {
2304 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_VRRS, 1);
2305 } else {
2306 printk(KERN_ERR "Incompatible h/w version (0x%x) for adapter"
2307 " %s\n", ver, pci_name(pdev));
2308 err = -EBUSY;
2309 goto err_ver;
2310 }
2311
2312 ver = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_UVRS);
2313 if (ver & 1) {
2314 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_UVRS, 1);
2315 } else {
2316 printk(KERN_ERR "Incompatible upt version (0x%x) for "
2317 "adapter %s\n", ver, pci_name(pdev));
2318 err = -EBUSY;
2319 goto err_ver;
2320 }
2321
2322 vmxnet3_declare_features(adapter, dma64);
2323
2324 adapter->dev_number = atomic_read(&devices_found);
2325 vmxnet3_alloc_intr_resources(adapter);
2326
2327 vmxnet3_read_mac_addr(adapter, mac);
2328 memcpy(netdev->dev_addr, mac, netdev->addr_len);
2329
2330 netdev->netdev_ops = &vmxnet3_netdev_ops;
2331 netdev->watchdog_timeo = 5 * HZ;
2332 vmxnet3_set_ethtool_ops(netdev);
2333
2334 INIT_WORK(&adapter->work, vmxnet3_reset_work);
2335
2336 netif_napi_add(netdev, &adapter->napi, vmxnet3_poll, 64);
2337 SET_NETDEV_DEV(netdev, &pdev->dev);
2338 err = register_netdev(netdev);
2339
2340 if (err) {
2341 printk(KERN_ERR "Failed to register adapter %s\n",
2342 pci_name(pdev));
2343 goto err_register;
2344 }
2345
2346 set_bit(VMXNET3_STATE_BIT_QUIESCED, &adapter->state);
2347 atomic_inc(&devices_found);
2348 return 0;
2349
2350err_register:
2351 vmxnet3_free_intr_resources(adapter);
2352err_ver:
2353 vmxnet3_free_pci_resources(adapter);
2354err_alloc_pci:
2355 kfree(adapter->pm_conf);
2356err_alloc_pm:
2357 pci_free_consistent(adapter->pdev, sizeof(struct Vmxnet3_TxQueueDesc) +
2358 sizeof(struct Vmxnet3_RxQueueDesc),
2359 adapter->tqd_start, adapter->queue_desc_pa);
2360err_alloc_queue_desc:
2361 pci_free_consistent(adapter->pdev, sizeof(struct Vmxnet3_DriverShared),
2362 adapter->shared, adapter->shared_pa);
2363err_alloc_shared:
2364 pci_set_drvdata(pdev, NULL);
2365 free_netdev(netdev);
2366 return err;
2367}
2368
2369
2370static void __devexit
2371vmxnet3_remove_device(struct pci_dev *pdev)
2372{
2373 struct net_device *netdev = pci_get_drvdata(pdev);
2374 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
2375
2376 flush_scheduled_work();
2377
2378 unregister_netdev(netdev);
2379
2380 vmxnet3_free_intr_resources(adapter);
2381 vmxnet3_free_pci_resources(adapter);
2382 kfree(adapter->pm_conf);
2383 pci_free_consistent(adapter->pdev, sizeof(struct Vmxnet3_TxQueueDesc) +
2384 sizeof(struct Vmxnet3_RxQueueDesc),
2385 adapter->tqd_start, adapter->queue_desc_pa);
2386 pci_free_consistent(adapter->pdev, sizeof(struct Vmxnet3_DriverShared),
2387 adapter->shared, adapter->shared_pa);
2388 free_netdev(netdev);
2389}
2390
2391
2392#ifdef CONFIG_PM
2393
2394static int
2395vmxnet3_suspend(struct device *device)
2396{
2397 struct pci_dev *pdev = to_pci_dev(device);
2398 struct net_device *netdev = pci_get_drvdata(pdev);
2399 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
2400 struct Vmxnet3_PMConf *pmConf;
2401 struct ethhdr *ehdr;
2402 struct arphdr *ahdr;
2403 u8 *arpreq;
2404 struct in_device *in_dev;
2405 struct in_ifaddr *ifa;
2406 int i = 0;
2407
2408 if (!netif_running(netdev))
2409 return 0;
2410
2411 vmxnet3_disable_all_intrs(adapter);
2412 vmxnet3_free_irqs(adapter);
2413 vmxnet3_free_intr_resources(adapter);
2414
2415 netif_device_detach(netdev);
2416 netif_stop_queue(netdev);
2417
2418 /* Create wake-up filters. */
2419 pmConf = adapter->pm_conf;
2420 memset(pmConf, 0, sizeof(*pmConf));
2421
2422 if (adapter->wol & WAKE_UCAST) {
2423 pmConf->filters[i].patternSize = ETH_ALEN;
2424 pmConf->filters[i].maskSize = 1;
2425 memcpy(pmConf->filters[i].pattern, netdev->dev_addr, ETH_ALEN);
2426 pmConf->filters[i].mask[0] = 0x3F; /* LSB ETH_ALEN bits */
2427
2428 pmConf->wakeUpEvents |= VMXNET3_PM_WAKEUP_FILTER;
2429 i++;
2430 }
2431
2432 if (adapter->wol & WAKE_ARP) {
2433 in_dev = in_dev_get(netdev);
2434 if (!in_dev)
2435 goto skip_arp;
2436
2437 ifa = (struct in_ifaddr *)in_dev->ifa_list;
2438 if (!ifa)
2439 goto skip_arp;
2440
2441 pmConf->filters[i].patternSize = ETH_HLEN + /* Ethernet header*/
2442 sizeof(struct arphdr) + /* ARP header */
2443 2 * ETH_ALEN + /* 2 Ethernet addresses*/
2444 2 * sizeof(u32); /*2 IPv4 addresses */
2445 pmConf->filters[i].maskSize =
2446 (pmConf->filters[i].patternSize - 1) / 8 + 1;
2447
2448 /* ETH_P_ARP in Ethernet header. */
2449 ehdr = (struct ethhdr *)pmConf->filters[i].pattern;
2450 ehdr->h_proto = htons(ETH_P_ARP);
2451
2452 /* ARPOP_REQUEST in ARP header. */
2453 ahdr = (struct arphdr *)&pmConf->filters[i].pattern[ETH_HLEN];
2454 ahdr->ar_op = htons(ARPOP_REQUEST);
2455 arpreq = (u8 *)(ahdr + 1);
2456
2457 /* The Unicast IPv4 address in 'tip' field. */
2458 arpreq += 2 * ETH_ALEN + sizeof(u32);
2459 *(u32 *)arpreq = ifa->ifa_address;
2460
2461 /* The mask for the relevant bits. */
2462 pmConf->filters[i].mask[0] = 0x00;
2463 pmConf->filters[i].mask[1] = 0x30; /* ETH_P_ARP */
2464 pmConf->filters[i].mask[2] = 0x30; /* ARPOP_REQUEST */
2465 pmConf->filters[i].mask[3] = 0x00;
2466 pmConf->filters[i].mask[4] = 0xC0; /* IPv4 TIP */
2467 pmConf->filters[i].mask[5] = 0x03; /* IPv4 TIP */
2468 in_dev_put(in_dev);
2469
2470 pmConf->wakeUpEvents |= VMXNET3_PM_WAKEUP_FILTER;
2471 i++;
2472 }
2473
2474skip_arp:
2475 if (adapter->wol & WAKE_MAGIC)
2476 pmConf->wakeUpEvents |= VMXNET3_PM_WAKEUP_MAGIC;
2477
2478 pmConf->numFilters = i;
2479
2480 adapter->shared->devRead.pmConfDesc.confVer = 1;
2481 adapter->shared->devRead.pmConfDesc.confLen = sizeof(*pmConf);
2482 adapter->shared->devRead.pmConfDesc.confPA = virt_to_phys(pmConf);
2483
2484 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
2485 VMXNET3_CMD_UPDATE_PMCFG);
2486
2487 pci_save_state(pdev);
2488 pci_enable_wake(pdev, pci_choose_state(pdev, PMSG_SUSPEND),
2489 adapter->wol);
2490 pci_disable_device(pdev);
2491 pci_set_power_state(pdev, pci_choose_state(pdev, PMSG_SUSPEND));
2492
2493 return 0;
2494}
2495
2496
2497static int
2498vmxnet3_resume(struct device *device)
2499{
2500 int err;
2501 struct pci_dev *pdev = to_pci_dev(device);
2502 struct net_device *netdev = pci_get_drvdata(pdev);
2503 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
2504 struct Vmxnet3_PMConf *pmConf;
2505
2506 if (!netif_running(netdev))
2507 return 0;
2508
2509 /* Destroy wake-up filters. */
2510 pmConf = adapter->pm_conf;
2511 memset(pmConf, 0, sizeof(*pmConf));
2512
2513 adapter->shared->devRead.pmConfDesc.confVer = 1;
2514 adapter->shared->devRead.pmConfDesc.confLen = sizeof(*pmConf);
2515 adapter->shared->devRead.pmConfDesc.confPA = virt_to_phys(pmConf);
2516
2517 netif_device_attach(netdev);
2518 pci_set_power_state(pdev, PCI_D0);
2519 pci_restore_state(pdev);
2520 err = pci_enable_device_mem(pdev);
2521 if (err != 0)
2522 return err;
2523
2524 pci_enable_wake(pdev, PCI_D0, 0);
2525
2526 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
2527 VMXNET3_CMD_UPDATE_PMCFG);
2528 vmxnet3_alloc_intr_resources(adapter);
2529 vmxnet3_request_irqs(adapter);
2530 vmxnet3_enable_all_intrs(adapter);
2531
2532 return 0;
2533}
2534
2535static struct dev_pm_ops vmxnet3_pm_ops = {
2536 .suspend = vmxnet3_suspend,
2537 .resume = vmxnet3_resume,
2538};
2539#endif
2540
2541static struct pci_driver vmxnet3_driver = {
2542 .name = vmxnet3_driver_name,
2543 .id_table = vmxnet3_pciid_table,
2544 .probe = vmxnet3_probe_device,
2545 .remove = __devexit_p(vmxnet3_remove_device),
2546#ifdef CONFIG_PM
2547 .driver.pm = &vmxnet3_pm_ops,
2548#endif
2549};
2550
2551
2552static int __init
2553vmxnet3_init_module(void)
2554{
2555 printk(KERN_INFO "%s - version %s\n", VMXNET3_DRIVER_DESC,
2556 VMXNET3_DRIVER_VERSION_REPORT);
2557 return pci_register_driver(&vmxnet3_driver);
2558}
2559
2560module_init(vmxnet3_init_module);
2561
2562
2563static void
2564vmxnet3_exit_module(void)
2565{
2566 pci_unregister_driver(&vmxnet3_driver);
2567}
2568
2569module_exit(vmxnet3_exit_module);
2570
2571MODULE_AUTHOR("VMware, Inc.");
2572MODULE_DESCRIPTION(VMXNET3_DRIVER_DESC);
2573MODULE_LICENSE("GPL v2");
2574MODULE_VERSION(VMXNET3_DRIVER_VERSION_STRING);
diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
new file mode 100644
index 000000000000..c2c15e4cafc7
--- /dev/null
+++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
@@ -0,0 +1,566 @@
1/*
2 * Linux driver for VMware's vmxnet3 ethernet NIC.
3 *
4 * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License and no later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * The full GNU General Public License is included in this distribution in
21 * the file called "COPYING".
22 *
23 * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
24 *
25 */
26
27
28#include "vmxnet3_int.h"
29
30struct vmxnet3_stat_desc {
31 char desc[ETH_GSTRING_LEN];
32 int offset;
33};
34
35
36static u32
37vmxnet3_get_rx_csum(struct net_device *netdev)
38{
39 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
40 return adapter->rxcsum;
41}
42
43
44static int
45vmxnet3_set_rx_csum(struct net_device *netdev, u32 val)
46{
47 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
48
49 if (adapter->rxcsum != val) {
50 adapter->rxcsum = val;
51 if (netif_running(netdev)) {
52 if (val)
53 adapter->shared->devRead.misc.uptFeatures |=
54 UPT1_F_RXCSUM;
55 else
56 adapter->shared->devRead.misc.uptFeatures &=
57 ~UPT1_F_RXCSUM;
58
59 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
60 VMXNET3_CMD_UPDATE_FEATURE);
61 }
62 }
63 return 0;
64}
65
66
67/* per tq stats maintained by the device */
68static const struct vmxnet3_stat_desc
69vmxnet3_tq_dev_stats[] = {
70 /* description, offset */
71 { "TSO pkts tx", offsetof(struct UPT1_TxStats, TSOPktsTxOK) },
72 { "TSO bytes tx", offsetof(struct UPT1_TxStats, TSOBytesTxOK) },
73 { "ucast pkts tx", offsetof(struct UPT1_TxStats, ucastPktsTxOK) },
74 { "ucast bytes tx", offsetof(struct UPT1_TxStats, ucastBytesTxOK) },
75 { "mcast pkts tx", offsetof(struct UPT1_TxStats, mcastPktsTxOK) },
76 { "mcast bytes tx", offsetof(struct UPT1_TxStats, mcastBytesTxOK) },
77 { "bcast pkts tx", offsetof(struct UPT1_TxStats, bcastPktsTxOK) },
78 { "bcast bytes tx", offsetof(struct UPT1_TxStats, bcastBytesTxOK) },
79 { "pkts tx err", offsetof(struct UPT1_TxStats, pktsTxError) },
80 { "pkts tx discard", offsetof(struct UPT1_TxStats, pktsTxDiscard) },
81};
82
83/* per tq stats maintained by the driver */
84static const struct vmxnet3_stat_desc
85vmxnet3_tq_driver_stats[] = {
86 /* description, offset */
87 {"drv dropped tx total", offsetof(struct vmxnet3_tq_driver_stats,
88 drop_total) },
89 { " too many frags", offsetof(struct vmxnet3_tq_driver_stats,
90 drop_too_many_frags) },
91 { " giant hdr", offsetof(struct vmxnet3_tq_driver_stats,
92 drop_oversized_hdr) },
93 { " hdr err", offsetof(struct vmxnet3_tq_driver_stats,
94 drop_hdr_inspect_err) },
95 { " tso", offsetof(struct vmxnet3_tq_driver_stats,
96 drop_tso) },
97 { "ring full", offsetof(struct vmxnet3_tq_driver_stats,
98 tx_ring_full) },
99 { "pkts linearized", offsetof(struct vmxnet3_tq_driver_stats,
100 linearized) },
101 { "hdr cloned", offsetof(struct vmxnet3_tq_driver_stats,
102 copy_skb_header) },
103 { "giant hdr", offsetof(struct vmxnet3_tq_driver_stats,
104 oversized_hdr) },
105};
106
107/* per rq stats maintained by the device */
108static const struct vmxnet3_stat_desc
109vmxnet3_rq_dev_stats[] = {
110 { "LRO pkts rx", offsetof(struct UPT1_RxStats, LROPktsRxOK) },
111 { "LRO byte rx", offsetof(struct UPT1_RxStats, LROBytesRxOK) },
112 { "ucast pkts rx", offsetof(struct UPT1_RxStats, ucastPktsRxOK) },
113 { "ucast bytes rx", offsetof(struct UPT1_RxStats, ucastBytesRxOK) },
114 { "mcast pkts rx", offsetof(struct UPT1_RxStats, mcastPktsRxOK) },
115 { "mcast bytes rx", offsetof(struct UPT1_RxStats, mcastBytesRxOK) },
116 { "bcast pkts rx", offsetof(struct UPT1_RxStats, bcastPktsRxOK) },
117 { "bcast bytes rx", offsetof(struct UPT1_RxStats, bcastBytesRxOK) },
118 { "pkts rx out of buf", offsetof(struct UPT1_RxStats, pktsRxOutOfBuf) },
119 { "pkts rx err", offsetof(struct UPT1_RxStats, pktsRxError) },
120};
121
122/* per rq stats maintained by the driver */
123static const struct vmxnet3_stat_desc
124vmxnet3_rq_driver_stats[] = {
125 /* description, offset */
126 { "drv dropped rx total", offsetof(struct vmxnet3_rq_driver_stats,
127 drop_total) },
128 { " err", offsetof(struct vmxnet3_rq_driver_stats,
129 drop_err) },
130 { " fcs", offsetof(struct vmxnet3_rq_driver_stats,
131 drop_fcs) },
132 { "rx buf alloc fail", offsetof(struct vmxnet3_rq_driver_stats,
133 rx_buf_alloc_failure) },
134};
135
136/* gloabl stats maintained by the driver */
137static const struct vmxnet3_stat_desc
138vmxnet3_global_stats[] = {
139 /* description, offset */
140 { "tx timeout count", offsetof(struct vmxnet3_adapter,
141 tx_timeout_count) }
142};
143
144
145struct net_device_stats *
146vmxnet3_get_stats(struct net_device *netdev)
147{
148 struct vmxnet3_adapter *adapter;
149 struct vmxnet3_tq_driver_stats *drvTxStats;
150 struct vmxnet3_rq_driver_stats *drvRxStats;
151 struct UPT1_TxStats *devTxStats;
152 struct UPT1_RxStats *devRxStats;
153 struct net_device_stats *net_stats = &netdev->stats;
154
155 adapter = netdev_priv(netdev);
156
157 /* Collect the dev stats into the shared area */
158 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
159
160 /* Assuming that we have a single queue device */
161 devTxStats = &adapter->tqd_start->stats;
162 devRxStats = &adapter->rqd_start->stats;
163
164 /* Get access to the driver stats per queue */
165 drvTxStats = &adapter->tx_queue.stats;
166 drvRxStats = &adapter->rx_queue.stats;
167
168 memset(net_stats, 0, sizeof(*net_stats));
169
170 net_stats->rx_packets = devRxStats->ucastPktsRxOK +
171 devRxStats->mcastPktsRxOK +
172 devRxStats->bcastPktsRxOK;
173
174 net_stats->tx_packets = devTxStats->ucastPktsTxOK +
175 devTxStats->mcastPktsTxOK +
176 devTxStats->bcastPktsTxOK;
177
178 net_stats->rx_bytes = devRxStats->ucastBytesRxOK +
179 devRxStats->mcastBytesRxOK +
180 devRxStats->bcastBytesRxOK;
181
182 net_stats->tx_bytes = devTxStats->ucastBytesTxOK +
183 devTxStats->mcastBytesTxOK +
184 devTxStats->bcastBytesTxOK;
185
186 net_stats->rx_errors = devRxStats->pktsRxError;
187 net_stats->tx_errors = devTxStats->pktsTxError;
188 net_stats->rx_dropped = drvRxStats->drop_total;
189 net_stats->tx_dropped = drvTxStats->drop_total;
190 net_stats->multicast = devRxStats->mcastPktsRxOK;
191
192 return net_stats;
193}
194
195static int
196vmxnet3_get_sset_count(struct net_device *netdev, int sset)
197{
198 switch (sset) {
199 case ETH_SS_STATS:
200 return ARRAY_SIZE(vmxnet3_tq_dev_stats) +
201 ARRAY_SIZE(vmxnet3_tq_driver_stats) +
202 ARRAY_SIZE(vmxnet3_rq_dev_stats) +
203 ARRAY_SIZE(vmxnet3_rq_driver_stats) +
204 ARRAY_SIZE(vmxnet3_global_stats);
205 default:
206 return -EOPNOTSUPP;
207 }
208}
209
210
211static int
212vmxnet3_get_regs_len(struct net_device *netdev)
213{
214 return 20 * sizeof(u32);
215}
216
217
218static void
219vmxnet3_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
220{
221 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
222
223 strlcpy(drvinfo->driver, vmxnet3_driver_name, sizeof(drvinfo->driver));
224 drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
225
226 strlcpy(drvinfo->version, VMXNET3_DRIVER_VERSION_REPORT,
227 sizeof(drvinfo->version));
228 drvinfo->driver[sizeof(drvinfo->version) - 1] = '\0';
229
230 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
231 drvinfo->fw_version[sizeof(drvinfo->fw_version) - 1] = '\0';
232
233 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
234 ETHTOOL_BUSINFO_LEN);
235 drvinfo->n_stats = vmxnet3_get_sset_count(netdev, ETH_SS_STATS);
236 drvinfo->testinfo_len = 0;
237 drvinfo->eedump_len = 0;
238 drvinfo->regdump_len = vmxnet3_get_regs_len(netdev);
239}
240
241
242static void
243vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
244{
245 if (stringset == ETH_SS_STATS) {
246 int i;
247
248 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) {
249 memcpy(buf, vmxnet3_tq_dev_stats[i].desc,
250 ETH_GSTRING_LEN);
251 buf += ETH_GSTRING_LEN;
252 }
253 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++) {
254 memcpy(buf, vmxnet3_tq_driver_stats[i].desc,
255 ETH_GSTRING_LEN);
256 buf += ETH_GSTRING_LEN;
257 }
258 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) {
259 memcpy(buf, vmxnet3_rq_dev_stats[i].desc,
260 ETH_GSTRING_LEN);
261 buf += ETH_GSTRING_LEN;
262 }
263 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++) {
264 memcpy(buf, vmxnet3_rq_driver_stats[i].desc,
265 ETH_GSTRING_LEN);
266 buf += ETH_GSTRING_LEN;
267 }
268 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) {
269 memcpy(buf, vmxnet3_global_stats[i].desc,
270 ETH_GSTRING_LEN);
271 buf += ETH_GSTRING_LEN;
272 }
273 }
274}
275
276static u32
277vmxnet3_get_flags(struct net_device *netdev) {
278 return netdev->features;
279}
280
281static int
282vmxnet3_set_flags(struct net_device *netdev, u32 data) {
283 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
284 u8 lro_requested = (data & ETH_FLAG_LRO) == 0 ? 0 : 1;
285 u8 lro_present = (netdev->features & NETIF_F_LRO) == 0 ? 0 : 1;
286
287 if (lro_requested ^ lro_present) {
288 /* toggle the LRO feature*/
289 netdev->features ^= NETIF_F_LRO;
290
291 /* update harware LRO capability accordingly */
292 if (lro_requested)
293 adapter->shared->devRead.misc.uptFeatures &= UPT1_F_LRO;
294 else
295 adapter->shared->devRead.misc.uptFeatures &=
296 ~UPT1_F_LRO;
297 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
298 VMXNET3_CMD_UPDATE_FEATURE);
299 }
300 return 0;
301}
302
303static void
304vmxnet3_get_ethtool_stats(struct net_device *netdev,
305 struct ethtool_stats *stats, u64 *buf)
306{
307 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
308 u8 *base;
309 int i;
310
311 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
312
313 /* this does assume each counter is 64-bit wide */
314
315 base = (u8 *)&adapter->tqd_start->stats;
316 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
317 *buf++ = *(u64 *)(base + vmxnet3_tq_dev_stats[i].offset);
318
319 base = (u8 *)&adapter->tx_queue.stats;
320 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
321 *buf++ = *(u64 *)(base + vmxnet3_tq_driver_stats[i].offset);
322
323 base = (u8 *)&adapter->rqd_start->stats;
324 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
325 *buf++ = *(u64 *)(base + vmxnet3_rq_dev_stats[i].offset);
326
327 base = (u8 *)&adapter->rx_queue.stats;
328 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
329 *buf++ = *(u64 *)(base + vmxnet3_rq_driver_stats[i].offset);
330
331 base = (u8 *)adapter;
332 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
333 *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset);
334}
335
336
337static void
338vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
339{
340 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
341 u32 *buf = p;
342
343 memset(p, 0, vmxnet3_get_regs_len(netdev));
344
345 regs->version = 1;
346
347 /* Update vmxnet3_get_regs_len if we want to dump more registers */
348
349 /* make each ring use multiple of 16 bytes */
350 buf[0] = adapter->tx_queue.tx_ring.next2fill;
351 buf[1] = adapter->tx_queue.tx_ring.next2comp;
352 buf[2] = adapter->tx_queue.tx_ring.gen;
353 buf[3] = 0;
354
355 buf[4] = adapter->tx_queue.comp_ring.next2proc;
356 buf[5] = adapter->tx_queue.comp_ring.gen;
357 buf[6] = adapter->tx_queue.stopped;
358 buf[7] = 0;
359
360 buf[8] = adapter->rx_queue.rx_ring[0].next2fill;
361 buf[9] = adapter->rx_queue.rx_ring[0].next2comp;
362 buf[10] = adapter->rx_queue.rx_ring[0].gen;
363 buf[11] = 0;
364
365 buf[12] = adapter->rx_queue.rx_ring[1].next2fill;
366 buf[13] = adapter->rx_queue.rx_ring[1].next2comp;
367 buf[14] = adapter->rx_queue.rx_ring[1].gen;
368 buf[15] = 0;
369
370 buf[16] = adapter->rx_queue.comp_ring.next2proc;
371 buf[17] = adapter->rx_queue.comp_ring.gen;
372 buf[18] = 0;
373 buf[19] = 0;
374}
375
376
377static void
378vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
379{
380 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
381
382 wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC;
383 wol->wolopts = adapter->wol;
384}
385
386
387static int
388vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
389{
390 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
391
392 if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST |
393 WAKE_MAGICSECURE)) {
394 return -EOPNOTSUPP;
395 }
396
397 adapter->wol = wol->wolopts;
398
399 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
400
401 return 0;
402}
403
404
405static int
406vmxnet3_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
407{
408 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
409
410 ecmd->supported = SUPPORTED_10000baseT_Full | SUPPORTED_1000baseT_Full |
411 SUPPORTED_TP;
412 ecmd->advertising = ADVERTISED_TP;
413 ecmd->port = PORT_TP;
414 ecmd->transceiver = XCVR_INTERNAL;
415
416 if (adapter->link_speed) {
417 ecmd->speed = adapter->link_speed;
418 ecmd->duplex = DUPLEX_FULL;
419 } else {
420 ecmd->speed = -1;
421 ecmd->duplex = -1;
422 }
423 return 0;
424}
425
426
427static void
428vmxnet3_get_ringparam(struct net_device *netdev,
429 struct ethtool_ringparam *param)
430{
431 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
432
433 param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE;
434 param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE;
435 param->rx_mini_max_pending = 0;
436 param->rx_jumbo_max_pending = 0;
437
438 param->rx_pending = adapter->rx_queue.rx_ring[0].size;
439 param->tx_pending = adapter->tx_queue.tx_ring.size;
440 param->rx_mini_pending = 0;
441 param->rx_jumbo_pending = 0;
442}
443
444
445static int
446vmxnet3_set_ringparam(struct net_device *netdev,
447 struct ethtool_ringparam *param)
448{
449 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
450 u32 new_tx_ring_size, new_rx_ring_size;
451 u32 sz;
452 int err = 0;
453
454 if (param->tx_pending == 0 || param->tx_pending >
455 VMXNET3_TX_RING_MAX_SIZE)
456 return -EINVAL;
457
458 if (param->rx_pending == 0 || param->rx_pending >
459 VMXNET3_RX_RING_MAX_SIZE)
460 return -EINVAL;
461
462
463 /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
464 new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
465 ~VMXNET3_RING_SIZE_MASK;
466 new_tx_ring_size = min_t(u32, new_tx_ring_size,
467 VMXNET3_TX_RING_MAX_SIZE);
468 if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
469 VMXNET3_RING_SIZE_ALIGN) != 0)
470 return -EINVAL;
471
472 /* ring0 has to be a multiple of
473 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
474 */
475 sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
476 new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
477 new_rx_ring_size = min_t(u32, new_rx_ring_size,
478 VMXNET3_RX_RING_MAX_SIZE / sz * sz);
479 if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
480 sz) != 0)
481 return -EINVAL;
482
483 if (new_tx_ring_size == adapter->tx_queue.tx_ring.size &&
484 new_rx_ring_size == adapter->rx_queue.rx_ring[0].size) {
485 return 0;
486 }
487
488 /*
489 * Reset_work may be in the middle of resetting the device, wait for its
490 * completion.
491 */
492 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
493 msleep(1);
494
495 if (netif_running(netdev)) {
496 vmxnet3_quiesce_dev(adapter);
497 vmxnet3_reset_dev(adapter);
498
499 /* recreate the rx queue and the tx queue based on the
500 * new sizes */
501 vmxnet3_tq_destroy(&adapter->tx_queue, adapter);
502 vmxnet3_rq_destroy(&adapter->rx_queue, adapter);
503
504 err = vmxnet3_create_queues(adapter, new_tx_ring_size,
505 new_rx_ring_size, VMXNET3_DEF_RX_RING_SIZE);
506 if (err) {
507 /* failed, most likely because of OOM, try default
508 * size */
509 printk(KERN_ERR "%s: failed to apply new sizes, try the"
510 " default ones\n", netdev->name);
511 err = vmxnet3_create_queues(adapter,
512 VMXNET3_DEF_TX_RING_SIZE,
513 VMXNET3_DEF_RX_RING_SIZE,
514 VMXNET3_DEF_RX_RING_SIZE);
515 if (err) {
516 printk(KERN_ERR "%s: failed to create queues "
517 "with default sizes. Closing it\n",
518 netdev->name);
519 goto out;
520 }
521 }
522
523 err = vmxnet3_activate_dev(adapter);
524 if (err)
525 printk(KERN_ERR "%s: failed to re-activate, error %d."
526 " Closing it\n", netdev->name, err);
527 }
528
529out:
530 clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
531 if (err)
532 vmxnet3_force_close(adapter);
533
534 return err;
535}
536
537
538static struct ethtool_ops vmxnet3_ethtool_ops = {
539 .get_settings = vmxnet3_get_settings,
540 .get_drvinfo = vmxnet3_get_drvinfo,
541 .get_regs_len = vmxnet3_get_regs_len,
542 .get_regs = vmxnet3_get_regs,
543 .get_wol = vmxnet3_get_wol,
544 .set_wol = vmxnet3_set_wol,
545 .get_link = ethtool_op_get_link,
546 .get_rx_csum = vmxnet3_get_rx_csum,
547 .set_rx_csum = vmxnet3_set_rx_csum,
548 .get_tx_csum = ethtool_op_get_tx_csum,
549 .set_tx_csum = ethtool_op_set_tx_hw_csum,
550 .get_sg = ethtool_op_get_sg,
551 .set_sg = ethtool_op_set_sg,
552 .get_tso = ethtool_op_get_tso,
553 .set_tso = ethtool_op_set_tso,
554 .get_strings = vmxnet3_get_strings,
555 .get_flags = vmxnet3_get_flags,
556 .set_flags = vmxnet3_set_flags,
557 .get_sset_count = vmxnet3_get_sset_count,
558 .get_ethtool_stats = vmxnet3_get_ethtool_stats,
559 .get_ringparam = vmxnet3_get_ringparam,
560 .set_ringparam = vmxnet3_set_ringparam,
561};
562
563void vmxnet3_set_ethtool_ops(struct net_device *netdev)
564{
565 SET_ETHTOOL_OPS(netdev, &vmxnet3_ethtool_ops);
566}
diff --git a/drivers/net/vmxnet3/vmxnet3_int.h b/drivers/net/vmxnet3/vmxnet3_int.h
new file mode 100644
index 000000000000..3c0d70d58111
--- /dev/null
+++ b/drivers/net/vmxnet3/vmxnet3_int.h
@@ -0,0 +1,389 @@
1/*
2 * Linux driver for VMware's vmxnet3 ethernet NIC.
3 *
4 * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License and no later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * The full GNU General Public License is included in this distribution in
21 * the file called "COPYING".
22 *
23 * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
24 *
25 */
26
27#ifndef _VMXNET3_INT_H
28#define _VMXNET3_INT_H
29
30#include <linux/types.h>
31#include <linux/ethtool.h>
32#include <linux/delay.h>
33#include <linux/device.h>
34#include <linux/netdevice.h>
35#include <linux/pci.h>
36#include <linux/ethtool.h>
37#include <linux/compiler.h>
38#include <linux/module.h>
39#include <linux/moduleparam.h>
40#include <linux/slab.h>
41#include <linux/spinlock.h>
42#include <linux/ioport.h>
43#include <linux/highmem.h>
44#include <linux/init.h>
45#include <linux/timer.h>
46#include <linux/skbuff.h>
47#include <linux/interrupt.h>
48#include <linux/workqueue.h>
49#include <linux/uaccess.h>
50#include <asm/dma.h>
51#include <asm/page.h>
52
53#include <linux/tcp.h>
54#include <linux/udp.h>
55#include <linux/ip.h>
56#include <linux/ipv6.h>
57#include <linux/in.h>
58#include <linux/etherdevice.h>
59#include <asm/checksum.h>
60#include <linux/if_vlan.h>
61#include <linux/if_arp.h>
62#include <linux/inetdevice.h>
63
64#include "vmxnet3_defs.h"
65
66#ifdef DEBUG
67# define VMXNET3_DRIVER_VERSION_REPORT VMXNET3_DRIVER_VERSION_STRING"-NAPI(debug)"
68#else
69# define VMXNET3_DRIVER_VERSION_REPORT VMXNET3_DRIVER_VERSION_STRING"-NAPI"
70#endif
71
72
73/*
74 * Version numbers
75 */
76#define VMXNET3_DRIVER_VERSION_STRING "1.0.5.0-k"
77
78/* a 32-bit int, each byte encode a verion number in VMXNET3_DRIVER_VERSION */
79#define VMXNET3_DRIVER_VERSION_NUM 0x01000500
80
81
82/*
83 * Capabilities
84 */
85
86enum {
87 VMNET_CAP_SG = 0x0001, /* Can do scatter-gather transmits. */
88 VMNET_CAP_IP4_CSUM = 0x0002, /* Can checksum only TCP/UDP over
89 * IPv4 */
90 VMNET_CAP_HW_CSUM = 0x0004, /* Can checksum all packets. */
91 VMNET_CAP_HIGH_DMA = 0x0008, /* Can DMA to high memory. */
92 VMNET_CAP_TOE = 0x0010, /* Supports TCP/IP offload. */
93 VMNET_CAP_TSO = 0x0020, /* Supports TCP Segmentation
94 * offload */
95 VMNET_CAP_SW_TSO = 0x0040, /* Supports SW TCP Segmentation */
96 VMNET_CAP_VMXNET_APROM = 0x0080, /* Vmxnet APROM support */
97 VMNET_CAP_HW_TX_VLAN = 0x0100, /* Can we do VLAN tagging in HW */
98 VMNET_CAP_HW_RX_VLAN = 0x0200, /* Can we do VLAN untagging in HW */
99 VMNET_CAP_SW_VLAN = 0x0400, /* VLAN tagging/untagging in SW */
100 VMNET_CAP_WAKE_PCKT_RCV = 0x0800, /* Can wake on network packet recv? */
101 VMNET_CAP_ENABLE_INT_INLINE = 0x1000, /* Enable Interrupt Inline */
102 VMNET_CAP_ENABLE_HEADER_COPY = 0x2000, /* copy header for vmkernel */
103 VMNET_CAP_TX_CHAIN = 0x4000, /* Guest can use multiple tx entries
104 * for a pkt */
105 VMNET_CAP_RX_CHAIN = 0x8000, /* pkt can span multiple rx entries */
106 VMNET_CAP_LPD = 0x10000, /* large pkt delivery */
107 VMNET_CAP_BPF = 0x20000, /* BPF Support in VMXNET Virtual HW*/
108 VMNET_CAP_SG_SPAN_PAGES = 0x40000, /* Scatter-gather can span multiple*/
109 /* pages transmits */
110 VMNET_CAP_IP6_CSUM = 0x80000, /* Can do IPv6 csum offload. */
111 VMNET_CAP_TSO6 = 0x100000, /* TSO seg. offload for IPv6 pkts. */
112 VMNET_CAP_TSO256k = 0x200000, /* Can do TSO seg offload for */
113 /* pkts up to 256kB. */
114 VMNET_CAP_UPT = 0x400000 /* Support UPT */
115};
116
117/*
118 * PCI vendor and device IDs.
119 */
120#define PCI_VENDOR_ID_VMWARE 0x15AD
121#define PCI_DEVICE_ID_VMWARE_VMXNET3 0x07B0
122#define MAX_ETHERNET_CARDS 10
123#define MAX_PCI_PASSTHRU_DEVICE 6
124
125struct vmxnet3_cmd_ring {
126 union Vmxnet3_GenericDesc *base;
127 u32 size;
128 u32 next2fill;
129 u32 next2comp;
130 u8 gen;
131 dma_addr_t basePA;
132};
133
134static inline void
135vmxnet3_cmd_ring_adv_next2fill(struct vmxnet3_cmd_ring *ring)
136{
137 ring->next2fill++;
138 if (unlikely(ring->next2fill == ring->size)) {
139 ring->next2fill = 0;
140 VMXNET3_FLIP_RING_GEN(ring->gen);
141 }
142}
143
144static inline void
145vmxnet3_cmd_ring_adv_next2comp(struct vmxnet3_cmd_ring *ring)
146{
147 VMXNET3_INC_RING_IDX_ONLY(ring->next2comp, ring->size);
148}
149
150static inline int
151vmxnet3_cmd_ring_desc_avail(struct vmxnet3_cmd_ring *ring)
152{
153 return (ring->next2comp > ring->next2fill ? 0 : ring->size) +
154 ring->next2comp - ring->next2fill - 1;
155}
156
157struct vmxnet3_comp_ring {
158 union Vmxnet3_GenericDesc *base;
159 u32 size;
160 u32 next2proc;
161 u8 gen;
162 u8 intr_idx;
163 dma_addr_t basePA;
164};
165
166static inline void
167vmxnet3_comp_ring_adv_next2proc(struct vmxnet3_comp_ring *ring)
168{
169 ring->next2proc++;
170 if (unlikely(ring->next2proc == ring->size)) {
171 ring->next2proc = 0;
172 VMXNET3_FLIP_RING_GEN(ring->gen);
173 }
174}
175
176struct vmxnet3_tx_data_ring {
177 struct Vmxnet3_TxDataDesc *base;
178 u32 size;
179 dma_addr_t basePA;
180};
181
182enum vmxnet3_buf_map_type {
183 VMXNET3_MAP_INVALID = 0,
184 VMXNET3_MAP_NONE,
185 VMXNET3_MAP_SINGLE,
186 VMXNET3_MAP_PAGE,
187};
188
189struct vmxnet3_tx_buf_info {
190 u32 map_type;
191 u16 len;
192 u16 sop_idx;
193 dma_addr_t dma_addr;
194 struct sk_buff *skb;
195};
196
197struct vmxnet3_tq_driver_stats {
198 u64 drop_total; /* # of pkts dropped by the driver, the
199 * counters below track droppings due to
200 * different reasons
201 */
202 u64 drop_too_many_frags;
203 u64 drop_oversized_hdr;
204 u64 drop_hdr_inspect_err;
205 u64 drop_tso;
206
207 u64 tx_ring_full;
208 u64 linearized; /* # of pkts linearized */
209 u64 copy_skb_header; /* # of times we have to copy skb header */
210 u64 oversized_hdr;
211};
212
213struct vmxnet3_tx_ctx {
214 bool ipv4;
215 u16 mss;
216 u32 eth_ip_hdr_size; /* only valid for pkts requesting tso or csum
217 * offloading
218 */
219 u32 l4_hdr_size; /* only valid if mss != 0 */
220 u32 copy_size; /* # of bytes copied into the data ring */
221 union Vmxnet3_GenericDesc *sop_txd;
222 union Vmxnet3_GenericDesc *eop_txd;
223};
224
225struct vmxnet3_tx_queue {
226 spinlock_t tx_lock;
227 struct vmxnet3_cmd_ring tx_ring;
228 struct vmxnet3_tx_buf_info *buf_info;
229 struct vmxnet3_tx_data_ring data_ring;
230 struct vmxnet3_comp_ring comp_ring;
231 struct Vmxnet3_TxQueueCtrl *shared;
232 struct vmxnet3_tq_driver_stats stats;
233 bool stopped;
234 int num_stop; /* # of times the queue is
235 * stopped */
236} __attribute__((__aligned__(SMP_CACHE_BYTES)));
237
238enum vmxnet3_rx_buf_type {
239 VMXNET3_RX_BUF_NONE = 0,
240 VMXNET3_RX_BUF_SKB = 1,
241 VMXNET3_RX_BUF_PAGE = 2
242};
243
244struct vmxnet3_rx_buf_info {
245 enum vmxnet3_rx_buf_type buf_type;
246 u16 len;
247 union {
248 struct sk_buff *skb;
249 struct page *page;
250 };
251 dma_addr_t dma_addr;
252};
253
254struct vmxnet3_rx_ctx {
255 struct sk_buff *skb;
256 u32 sop_idx;
257};
258
259struct vmxnet3_rq_driver_stats {
260 u64 drop_total;
261 u64 drop_err;
262 u64 drop_fcs;
263 u64 rx_buf_alloc_failure;
264};
265
266struct vmxnet3_rx_queue {
267 struct vmxnet3_cmd_ring rx_ring[2];
268 struct vmxnet3_comp_ring comp_ring;
269 struct vmxnet3_rx_ctx rx_ctx;
270 u32 qid; /* rqID in RCD for buffer from 1st ring */
271 u32 qid2; /* rqID in RCD for buffer from 2nd ring */
272 u32 uncommitted[2]; /* # of buffers allocated since last RXPROD
273 * update */
274 struct vmxnet3_rx_buf_info *buf_info[2];
275 struct Vmxnet3_RxQueueCtrl *shared;
276 struct vmxnet3_rq_driver_stats stats;
277} __attribute__((__aligned__(SMP_CACHE_BYTES)));
278
279#define VMXNET3_LINUX_MAX_MSIX_VECT 1
280
281struct vmxnet3_intr {
282 enum vmxnet3_intr_mask_mode mask_mode;
283 enum vmxnet3_intr_type type; /* MSI-X, MSI, or INTx? */
284 u8 num_intrs; /* # of intr vectors */
285 u8 event_intr_idx; /* idx of the intr vector for event */
286 u8 mod_levels[VMXNET3_LINUX_MAX_MSIX_VECT]; /* moderation level */
287#ifdef CONFIG_PCI_MSI
288 struct msix_entry msix_entries[VMXNET3_LINUX_MAX_MSIX_VECT];
289#endif
290};
291
292#define VMXNET3_STATE_BIT_RESETTING 0
293#define VMXNET3_STATE_BIT_QUIESCED 1
294struct vmxnet3_adapter {
295 struct vmxnet3_tx_queue tx_queue;
296 struct vmxnet3_rx_queue rx_queue;
297 struct napi_struct napi;
298 struct vlan_group *vlan_grp;
299
300 struct vmxnet3_intr intr;
301
302 struct Vmxnet3_DriverShared *shared;
303 struct Vmxnet3_PMConf *pm_conf;
304 struct Vmxnet3_TxQueueDesc *tqd_start; /* first tx queue desc */
305 struct Vmxnet3_RxQueueDesc *rqd_start; /* first rx queue desc */
306 struct net_device *netdev;
307 struct pci_dev *pdev;
308
309 u8 *hw_addr0; /* for BAR 0 */
310 u8 *hw_addr1; /* for BAR 1 */
311
312 /* feature control */
313 bool rxcsum;
314 bool lro;
315 bool jumbo_frame;
316
317 /* rx buffer related */
318 unsigned skb_buf_size;
319 int rx_buf_per_pkt; /* only apply to the 1st ring */
320 dma_addr_t shared_pa;
321 dma_addr_t queue_desc_pa;
322
323 /* Wake-on-LAN */
324 u32 wol;
325
326 /* Link speed */
327 u32 link_speed; /* in mbps */
328
329 u64 tx_timeout_count;
330 struct work_struct work;
331
332 unsigned long state; /* VMXNET3_STATE_BIT_xxx */
333
334 int dev_number;
335};
336
337#define VMXNET3_WRITE_BAR0_REG(adapter, reg, val) \
338 writel((val), (adapter)->hw_addr0 + (reg))
339#define VMXNET3_READ_BAR0_REG(adapter, reg) \
340 readl((adapter)->hw_addr0 + (reg))
341
342#define VMXNET3_WRITE_BAR1_REG(adapter, reg, val) \
343 writel((val), (adapter)->hw_addr1 + (reg))
344#define VMXNET3_READ_BAR1_REG(adapter, reg) \
345 readl((adapter)->hw_addr1 + (reg))
346
347#define VMXNET3_WAKE_QUEUE_THRESHOLD(tq) (5)
348#define VMXNET3_RX_ALLOC_THRESHOLD(rq, ring_idx, adapter) \
349 ((rq)->rx_ring[ring_idx].size >> 3)
350
351#define VMXNET3_GET_ADDR_LO(dma) ((u32)(dma))
352#define VMXNET3_GET_ADDR_HI(dma) ((u32)(((u64)(dma)) >> 32))
353
354/* must be a multiple of VMXNET3_RING_SIZE_ALIGN */
355#define VMXNET3_DEF_TX_RING_SIZE 512
356#define VMXNET3_DEF_RX_RING_SIZE 256
357
358#define VMXNET3_MAX_ETH_HDR_SIZE 22
359#define VMXNET3_MAX_SKB_BUF_SIZE (3*1024)
360
361int
362vmxnet3_quiesce_dev(struct vmxnet3_adapter *adapter);
363
364int
365vmxnet3_activate_dev(struct vmxnet3_adapter *adapter);
366
367void
368vmxnet3_force_close(struct vmxnet3_adapter *adapter);
369
370void
371vmxnet3_reset_dev(struct vmxnet3_adapter *adapter);
372
373void
374vmxnet3_tq_destroy(struct vmxnet3_tx_queue *tq,
375 struct vmxnet3_adapter *adapter);
376
377void
378vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq,
379 struct vmxnet3_adapter *adapter);
380
381int
382vmxnet3_create_queues(struct vmxnet3_adapter *adapter,
383 u32 tx_ring_size, u32 rx_ring_size, u32 rx_ring2_size);
384
385extern void vmxnet3_set_ethtool_ops(struct net_device *netdev);
386extern struct net_device_stats *vmxnet3_get_stats(struct net_device *netdev);
387
388extern char vmxnet3_driver_name[];
389#endif
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index e2c33c06190b..8e25ca7080c7 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -907,6 +907,7 @@ static ssize_t cosa_write(struct file *file,
907 current->state = TASK_RUNNING; 907 current->state = TASK_RUNNING;
908 chan->tx_status = 1; 908 chan->tx_status = 1;
909 spin_unlock_irqrestore(&cosa->lock, flags); 909 spin_unlock_irqrestore(&cosa->lock, flags);
910 up(&chan->wsem);
910 return -ERESTARTSYS; 911 return -ERESTARTSYS;
911 } 912 }
912 } 913 }
diff --git a/drivers/net/wan/hdlc_cisco.c b/drivers/net/wan/hdlc_cisco.c
index cf5fd17ad707..f1bff98acd1f 100644
--- a/drivers/net/wan/hdlc_cisco.c
+++ b/drivers/net/wan/hdlc_cisco.c
@@ -58,8 +58,7 @@ struct cisco_state {
58 spinlock_t lock; 58 spinlock_t lock;
59 unsigned long last_poll; 59 unsigned long last_poll;
60 int up; 60 int up;
61 int request_sent; 61 u32 txseq; /* TX sequence number, 0 = none */
62 u32 txseq; /* TX sequence number */
63 u32 rxseq; /* RX sequence number */ 62 u32 rxseq; /* RX sequence number */
64}; 63};
65 64
@@ -163,6 +162,7 @@ static int cisco_rx(struct sk_buff *skb)
163 struct cisco_packet *cisco_data; 162 struct cisco_packet *cisco_data;
164 struct in_device *in_dev; 163 struct in_device *in_dev;
165 __be32 addr, mask; 164 __be32 addr, mask;
165 u32 ack;
166 166
167 if (skb->len < sizeof(struct hdlc_header)) 167 if (skb->len < sizeof(struct hdlc_header))
168 goto rx_error; 168 goto rx_error;
@@ -223,8 +223,10 @@ static int cisco_rx(struct sk_buff *skb)
223 case CISCO_KEEPALIVE_REQ: 223 case CISCO_KEEPALIVE_REQ:
224 spin_lock(&st->lock); 224 spin_lock(&st->lock);
225 st->rxseq = ntohl(cisco_data->par1); 225 st->rxseq = ntohl(cisco_data->par1);
226 if (st->request_sent && 226 ack = ntohl(cisco_data->par2);
227 ntohl(cisco_data->par2) == st->txseq) { 227 if (ack && (ack == st->txseq ||
228 /* our current REQ may be in transit */
229 ack == st->txseq - 1)) {
228 st->last_poll = jiffies; 230 st->last_poll = jiffies;
229 if (!st->up) { 231 if (!st->up) {
230 u32 sec, min, hrs, days; 232 u32 sec, min, hrs, days;
@@ -275,7 +277,6 @@ static void cisco_timer(unsigned long arg)
275 277
276 cisco_keepalive_send(dev, CISCO_KEEPALIVE_REQ, htonl(++st->txseq), 278 cisco_keepalive_send(dev, CISCO_KEEPALIVE_REQ, htonl(++st->txseq),
277 htonl(st->rxseq)); 279 htonl(st->rxseq));
278 st->request_sent = 1;
279 spin_unlock(&st->lock); 280 spin_unlock(&st->lock);
280 281
281 st->timer.expires = jiffies + st->settings.interval * HZ; 282 st->timer.expires = jiffies + st->settings.interval * HZ;
@@ -293,9 +294,7 @@ static void cisco_start(struct net_device *dev)
293 unsigned long flags; 294 unsigned long flags;
294 295
295 spin_lock_irqsave(&st->lock, flags); 296 spin_lock_irqsave(&st->lock, flags);
296 st->up = 0; 297 st->up = st->txseq = st->rxseq = 0;
297 st->request_sent = 0;
298 st->txseq = st->rxseq = 0;
299 spin_unlock_irqrestore(&st->lock, flags); 298 spin_unlock_irqrestore(&st->lock, flags);
300 299
301 init_timer(&st->timer); 300 init_timer(&st->timer);
@@ -317,8 +316,7 @@ static void cisco_stop(struct net_device *dev)
317 316
318 spin_lock_irqsave(&st->lock, flags); 317 spin_lock_irqsave(&st->lock, flags);
319 netif_dormant_on(dev); 318 netif_dormant_on(dev);
320 st->up = 0; 319 st->up = st->txseq = 0;
321 st->request_sent = 0;
322 spin_unlock_irqrestore(&st->lock, flags); 320 spin_unlock_irqrestore(&st->lock, flags);
323} 321}
324 322
diff --git a/drivers/net/wireless/adm8211.h b/drivers/net/wireless/adm8211.h
index 4f6ab1322189..b07e4d3a6b4d 100644
--- a/drivers/net/wireless/adm8211.h
+++ b/drivers/net/wireless/adm8211.h
@@ -266,7 +266,7 @@ do { \
266#define ADM8211_SYNCTL_CS1 (1 << 28) 266#define ADM8211_SYNCTL_CS1 (1 << 28)
267#define ADM8211_SYNCTL_CAL (1 << 27) 267#define ADM8211_SYNCTL_CAL (1 << 27)
268#define ADM8211_SYNCTL_SELCAL (1 << 26) 268#define ADM8211_SYNCTL_SELCAL (1 << 26)
269#define ADM8211_SYNCTL_RFtype ((1 << 24) || (1 << 23) || (1 << 22)) 269#define ADM8211_SYNCTL_RFtype ((1 << 24) | (1 << 23) | (1 << 22))
270#define ADM8211_SYNCTL_RFMD (1 << 22) 270#define ADM8211_SYNCTL_RFMD (1 << 22)
271#define ADM8211_SYNCTL_GENERAL (0x7 << 22) 271#define ADM8211_SYNCTL_GENERAL (0x7 << 22)
272/* SYNCTL 21:0 Data (Si4126: 18-bit data, 4-bit address) */ 272/* SYNCTL 21:0 Data (Si4126: 18-bit data, 4-bit address) */
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 7116a1aa20ce..abf896a7390e 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -4790,9 +4790,8 @@ static int proc_stats_rid_open( struct inode *inode,
4790static int get_dec_u16( char *buffer, int *start, int limit ) { 4790static int get_dec_u16( char *buffer, int *start, int limit ) {
4791 u16 value; 4791 u16 value;
4792 int valid = 0; 4792 int valid = 0;
4793 for( value = 0; buffer[*start] >= '0' && 4793 for (value = 0; *start < limit && buffer[*start] >= '0' &&
4794 buffer[*start] <= '9' && 4794 buffer[*start] <= '9'; (*start)++) {
4795 *start < limit; (*start)++ ) {
4796 valid = 1; 4795 valid = 1;
4797 value *= 10; 4796 value *= 10;
4798 value += buffer[*start] - '0'; 4797 value += buffer[*start] - '0';
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
index d0593ed9170e..f6036fb42319 100644
--- a/drivers/net/wireless/airo_cs.c
+++ b/drivers/net/wireless/airo_cs.c
@@ -43,21 +43,6 @@
43 43
44#include "airo.h" 44#include "airo.h"
45 45
46/*
47 All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
48 you do not define PCMCIA_DEBUG at all, all the debug code will be
49 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
50 be present but disabled -- but it can then be enabled for specific
51 modules at load time with a 'pc_debug=#' option to insmod.
52*/
53#ifdef PCMCIA_DEBUG
54static int pc_debug = PCMCIA_DEBUG;
55module_param(pc_debug, int, 0);
56static char *version = "$Revision: 1.2 $";
57#define DEBUG(n, args...) if (pc_debug > (n)) printk(KERN_DEBUG args);
58#else
59#define DEBUG(n, args...)
60#endif
61 46
62/*====================================================================*/ 47/*====================================================================*/
63 48
@@ -145,11 +130,10 @@ static int airo_probe(struct pcmcia_device *p_dev)
145{ 130{
146 local_info_t *local; 131 local_info_t *local;
147 132
148 DEBUG(0, "airo_attach()\n"); 133 dev_dbg(&p_dev->dev, "airo_attach()\n");
149 134
150 /* Interrupt setup */ 135 /* Interrupt setup */
151 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING; 136 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
152 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
153 p_dev->irq.Handler = NULL; 137 p_dev->irq.Handler = NULL;
154 138
155 /* 139 /*
@@ -184,7 +168,7 @@ static int airo_probe(struct pcmcia_device *p_dev)
184 168
185static void airo_detach(struct pcmcia_device *link) 169static void airo_detach(struct pcmcia_device *link)
186{ 170{
187 DEBUG(0, "airo_detach(0x%p)\n", link); 171 dev_dbg(&link->dev, "airo_detach\n");
188 172
189 airo_release(link); 173 airo_release(link);
190 174
@@ -204,9 +188,6 @@ static void airo_detach(struct pcmcia_device *link)
204 188
205 ======================================================================*/ 189 ======================================================================*/
206 190
207#define CS_CHECK(fn, ret) \
208do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
209
210static int airo_cs_config_check(struct pcmcia_device *p_dev, 191static int airo_cs_config_check(struct pcmcia_device *p_dev,
211 cistpl_cftable_entry_t *cfg, 192 cistpl_cftable_entry_t *cfg,
212 cistpl_cftable_entry_t *dflt, 193 cistpl_cftable_entry_t *dflt,
@@ -275,11 +256,11 @@ static int airo_cs_config_check(struct pcmcia_device *p_dev,
275 req->Base = mem->win[0].host_addr; 256 req->Base = mem->win[0].host_addr;
276 req->Size = mem->win[0].len; 257 req->Size = mem->win[0].len;
277 req->AccessSpeed = 0; 258 req->AccessSpeed = 0;
278 if (pcmcia_request_window(&p_dev, req, &p_dev->win) != 0) 259 if (pcmcia_request_window(p_dev, req, &p_dev->win) != 0)
279 return -ENODEV; 260 return -ENODEV;
280 map.Page = 0; 261 map.Page = 0;
281 map.CardOffset = mem->win[0].card_addr; 262 map.CardOffset = mem->win[0].card_addr;
282 if (pcmcia_map_mem_page(p_dev->win, &map) != 0) 263 if (pcmcia_map_mem_page(p_dev, p_dev->win, &map) != 0)
283 return -ENODEV; 264 return -ENODEV;
284 } 265 }
285 /* If we got this far, we're cool! */ 266 /* If we got this far, we're cool! */
@@ -291,11 +272,11 @@ static int airo_config(struct pcmcia_device *link)
291{ 272{
292 local_info_t *dev; 273 local_info_t *dev;
293 win_req_t *req; 274 win_req_t *req;
294 int last_fn, last_ret; 275 int ret;
295 276
296 dev = link->priv; 277 dev = link->priv;
297 278
298 DEBUG(0, "airo_config(0x%p)\n", link); 279 dev_dbg(&link->dev, "airo_config\n");
299 280
300 req = kzalloc(sizeof(win_req_t), GFP_KERNEL); 281 req = kzalloc(sizeof(win_req_t), GFP_KERNEL);
301 if (!req) 282 if (!req)
@@ -315,8 +296,8 @@ static int airo_config(struct pcmcia_device *link)
315 * and most client drivers will only use the CIS to fill in 296 * and most client drivers will only use the CIS to fill in
316 * implementation-defined details. 297 * implementation-defined details.
317 */ 298 */
318 last_ret = pcmcia_loop_config(link, airo_cs_config_check, req); 299 ret = pcmcia_loop_config(link, airo_cs_config_check, req);
319 if (last_ret) 300 if (ret)
320 goto failed; 301 goto failed;
321 302
322 /* 303 /*
@@ -324,21 +305,25 @@ static int airo_config(struct pcmcia_device *link)
324 handler to the interrupt, unless the 'Handler' member of the 305 handler to the interrupt, unless the 'Handler' member of the
325 irq structure is initialized. 306 irq structure is initialized.
326 */ 307 */
327 if (link->conf.Attributes & CONF_ENABLE_IRQ) 308 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
328 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 309 ret = pcmcia_request_irq(link, &link->irq);
310 if (ret)
311 goto failed;
312 }
329 313
330 /* 314 /*
331 This actually configures the PCMCIA socket -- setting up 315 This actually configures the PCMCIA socket -- setting up
332 the I/O windows and the interrupt mapping, and putting the 316 the I/O windows and the interrupt mapping, and putting the
333 card and host interface into "Memory and IO" mode. 317 card and host interface into "Memory and IO" mode.
334 */ 318 */
335 CS_CHECK(RequestConfiguration, 319 ret = pcmcia_request_configuration(link, &link->conf);
336 pcmcia_request_configuration(link, &link->conf)); 320 if (ret)
321 goto failed;
337 ((local_info_t *)link->priv)->eth_dev = 322 ((local_info_t *)link->priv)->eth_dev =
338 init_airo_card(link->irq.AssignedIRQ, 323 init_airo_card(link->irq.AssignedIRQ,
339 link->io.BasePort1, 1, &handle_to_dev(link)); 324 link->io.BasePort1, 1, &link->dev);
340 if (!((local_info_t *)link->priv)->eth_dev) 325 if (!((local_info_t *)link->priv)->eth_dev)
341 goto cs_failed; 326 goto failed;
342 327
343 /* 328 /*
344 At this point, the dev_node_t structure(s) need to be 329 At this point, the dev_node_t structure(s) need to be
@@ -368,8 +353,6 @@ static int airo_config(struct pcmcia_device *link)
368 kfree(req); 353 kfree(req);
369 return 0; 354 return 0;
370 355
371 cs_failed:
372 cs_error(link, last_fn, last_ret);
373 failed: 356 failed:
374 airo_release(link); 357 airo_release(link);
375 kfree(req); 358 kfree(req);
@@ -386,7 +369,7 @@ static int airo_config(struct pcmcia_device *link)
386 369
387static void airo_release(struct pcmcia_device *link) 370static void airo_release(struct pcmcia_device *link)
388{ 371{
389 DEBUG(0, "airo_release(0x%p)\n", link); 372 dev_dbg(&link->dev, "airo_release\n");
390 pcmcia_disable_device(link); 373 pcmcia_disable_device(link);
391} 374}
392 375
diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
index 9c6ab5378f6e..95a8e232b58f 100644
--- a/drivers/net/wireless/ath/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -1125,7 +1125,6 @@ ath5k_mode_setup(struct ath5k_softc *sc)
1125 /* configure operational mode */ 1125 /* configure operational mode */
1126 ath5k_hw_set_opmode(ah); 1126 ath5k_hw_set_opmode(ah);
1127 1127
1128 ath5k_hw_set_mcast_filter(ah, 0, 0);
1129 ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "RX filter 0x%x\n", rfilt); 1128 ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "RX filter 0x%x\n", rfilt);
1130} 1129}
1131 1130
diff --git a/drivers/net/wireless/ath/ath5k/led.c b/drivers/net/wireless/ath/ath5k/led.c
index b767c3b67b24..b548c8eaaae1 100644
--- a/drivers/net/wireless/ath/ath5k/led.c
+++ b/drivers/net/wireless/ath/ath5k/led.c
@@ -63,12 +63,16 @@ static const struct pci_device_id ath5k_led_devices[] = {
63 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) }, 63 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) },
64 /* E-machines E510 (tuliom@gmail.com) */ 64 /* E-machines E510 (tuliom@gmail.com) */
65 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) }, 65 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) },
66 /* BenQ Joybook R55v (nowymarluk@wp.pl) */
67 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0100), ATH_LED(1, 0) },
66 /* Acer Extensa 5620z (nekoreeve@gmail.com) */ 68 /* Acer Extensa 5620z (nekoreeve@gmail.com) */
67 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) }, 69 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) },
68 /* Fukato Datacask Jupiter 1014a (mrb74@gmx.at) */ 70 /* Fukato Datacask Jupiter 1014a (mrb74@gmx.at) */
69 { ATH_SDEVICE(PCI_VENDOR_ID_AZWAVE, 0x1026), ATH_LED(3, 0) }, 71 { ATH_SDEVICE(PCI_VENDOR_ID_AZWAVE, 0x1026), ATH_LED(3, 0) },
70 /* IBM ThinkPad AR5BXB6 (legovini@spiro.fisica.unipd.it) */ 72 /* IBM ThinkPad AR5BXB6 (legovini@spiro.fisica.unipd.it) */
71 { ATH_SDEVICE(PCI_VENDOR_ID_IBM, 0x058a), ATH_LED(1, 0) }, 73 { ATH_SDEVICE(PCI_VENDOR_ID_IBM, 0x058a), ATH_LED(1, 0) },
74 /* HP Compaq CQ60-206US (ddreggors@jumptv.com) */
75 { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137a), ATH_LED(3, 1) },
72 /* HP Compaq C700 (nitrousnrg@gmail.com) */ 76 /* HP Compaq C700 (nitrousnrg@gmail.com) */
73 { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137b), ATH_LED(3, 1) }, 77 { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137b), ATH_LED(3, 1) },
74 /* IBM-specific AR5212 (all others) */ 78 /* IBM-specific AR5212 (all others) */
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 52bed89063d4..43d2be9867fc 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -1555,6 +1555,8 @@ void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
1555 BIT(NL80211_IFTYPE_ADHOC) | 1555 BIT(NL80211_IFTYPE_ADHOC) |
1556 BIT(NL80211_IFTYPE_MESH_POINT); 1556 BIT(NL80211_IFTYPE_MESH_POINT);
1557 1557
1558 hw->wiphy->ps_default = false;
1559
1558 hw->queues = 4; 1560 hw->queues = 4;
1559 hw->max_rates = 4; 1561 hw->max_rates = 4;
1560 hw->channel_change_time = 5000; 1562 hw->channel_change_time = 5000;
diff --git a/drivers/net/wireless/ath/ath9k/rc.c b/drivers/net/wireless/ath/ath9k/rc.c
index 16a271787b85..1895d63aad0a 100644
--- a/drivers/net/wireless/ath/ath9k/rc.c
+++ b/drivers/net/wireless/ath/ath9k/rc.c
@@ -679,7 +679,7 @@ static u8 ath_rc_get_highest_rix(struct ath_softc *sc,
679 return rate; 679 return rate;
680 680
681 if (rate_table->info[rate].valid_single_stream && 681 if (rate_table->info[rate].valid_single_stream &&
682 !(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG)); 682 !(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG))
683 return rate; 683 return rate;
684 684
685 /* This should not happen */ 685 /* This should not happen */
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index ddaa859c3491..32407911842f 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -55,22 +55,6 @@
55 55
56#include "atmel.h" 56#include "atmel.h"
57 57
58/*
59 All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
60 you do not define PCMCIA_DEBUG at all, all the debug code will be
61 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
62 be present but disabled -- but it can then be enabled for specific
63 modules at load time with a 'pc_debug=#' option to insmod.
64*/
65
66#ifdef PCMCIA_DEBUG
67static int pc_debug = PCMCIA_DEBUG;
68module_param(pc_debug, int, 0);
69static char *version = "$Revision: 1.2 $";
70#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args);
71#else
72#define DEBUG(n, args...)
73#endif
74 58
75/*====================================================================*/ 59/*====================================================================*/
76 60
@@ -155,11 +139,10 @@ static int atmel_probe(struct pcmcia_device *p_dev)
155{ 139{
156 local_info_t *local; 140 local_info_t *local;
157 141
158 DEBUG(0, "atmel_attach()\n"); 142 dev_dbg(&p_dev->dev, "atmel_attach()\n");
159 143
160 /* Interrupt setup */ 144 /* Interrupt setup */
161 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING; 145 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
162 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
163 p_dev->irq.Handler = NULL; 146 p_dev->irq.Handler = NULL;
164 147
165 /* 148 /*
@@ -194,7 +177,7 @@ static int atmel_probe(struct pcmcia_device *p_dev)
194 177
195static void atmel_detach(struct pcmcia_device *link) 178static void atmel_detach(struct pcmcia_device *link)
196{ 179{
197 DEBUG(0, "atmel_detach(0x%p)\n", link); 180 dev_dbg(&link->dev, "atmel_detach\n");
198 181
199 atmel_release(link); 182 atmel_release(link);
200 183
@@ -209,9 +192,6 @@ static void atmel_detach(struct pcmcia_device *link)
209 192
210 ======================================================================*/ 193 ======================================================================*/
211 194
212#define CS_CHECK(fn, ret) \
213do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
214
215/* Call-back function to interrogate PCMCIA-specific information 195/* Call-back function to interrogate PCMCIA-specific information
216 about the current existance of the card */ 196 about the current existance of the card */
217static int card_present(void *arg) 197static int card_present(void *arg)
@@ -275,13 +255,13 @@ static int atmel_config_check(struct pcmcia_device *p_dev,
275static int atmel_config(struct pcmcia_device *link) 255static int atmel_config(struct pcmcia_device *link)
276{ 256{
277 local_info_t *dev; 257 local_info_t *dev;
278 int last_fn, last_ret; 258 int ret;
279 struct pcmcia_device_id *did; 259 struct pcmcia_device_id *did;
280 260
281 dev = link->priv; 261 dev = link->priv;
282 did = dev_get_drvdata(&handle_to_dev(link)); 262 did = dev_get_drvdata(&link->dev);
283 263
284 DEBUG(0, "atmel_config(0x%p)\n", link); 264 dev_dbg(&link->dev, "atmel_config\n");
285 265
286 /* 266 /*
287 In this loop, we scan the CIS for configuration table entries, 267 In this loop, we scan the CIS for configuration table entries,
@@ -303,31 +283,36 @@ static int atmel_config(struct pcmcia_device *link)
303 handler to the interrupt, unless the 'Handler' member of the 283 handler to the interrupt, unless the 'Handler' member of the
304 irq structure is initialized. 284 irq structure is initialized.
305 */ 285 */
306 if (link->conf.Attributes & CONF_ENABLE_IRQ) 286 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
307 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 287 ret = pcmcia_request_irq(link, &link->irq);
288 if (ret)
289 goto failed;
290 }
308 291
309 /* 292 /*
310 This actually configures the PCMCIA socket -- setting up 293 This actually configures the PCMCIA socket -- setting up
311 the I/O windows and the interrupt mapping, and putting the 294 the I/O windows and the interrupt mapping, and putting the
312 card and host interface into "Memory and IO" mode. 295 card and host interface into "Memory and IO" mode.
313 */ 296 */
314 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 297 ret = pcmcia_request_configuration(link, &link->conf);
298 if (ret)
299 goto failed;
315 300
316 if (link->irq.AssignedIRQ == 0) { 301 if (link->irq.AssignedIRQ == 0) {
317 printk(KERN_ALERT 302 printk(KERN_ALERT
318 "atmel: cannot assign IRQ: check that CONFIG_ISA is set in kernel config."); 303 "atmel: cannot assign IRQ: check that CONFIG_ISA is set in kernel config.");
319 goto cs_failed; 304 goto failed;
320 } 305 }
321 306
322 ((local_info_t*)link->priv)->eth_dev = 307 ((local_info_t*)link->priv)->eth_dev =
323 init_atmel_card(link->irq.AssignedIRQ, 308 init_atmel_card(link->irq.AssignedIRQ,
324 link->io.BasePort1, 309 link->io.BasePort1,
325 did ? did->driver_info : ATMEL_FW_TYPE_NONE, 310 did ? did->driver_info : ATMEL_FW_TYPE_NONE,
326 &handle_to_dev(link), 311 &link->dev,
327 card_present, 312 card_present,
328 link); 313 link);
329 if (!((local_info_t*)link->priv)->eth_dev) 314 if (!((local_info_t*)link->priv)->eth_dev)
330 goto cs_failed; 315 goto failed;
331 316
332 317
333 /* 318 /*
@@ -340,8 +325,6 @@ static int atmel_config(struct pcmcia_device *link)
340 325
341 return 0; 326 return 0;
342 327
343 cs_failed:
344 cs_error(link, last_fn, last_ret);
345 failed: 328 failed:
346 atmel_release(link); 329 atmel_release(link);
347 return -ENODEV; 330 return -ENODEV;
@@ -359,7 +342,7 @@ static void atmel_release(struct pcmcia_device *link)
359{ 342{
360 struct net_device *dev = ((local_info_t*)link->priv)->eth_dev; 343 struct net_device *dev = ((local_info_t*)link->priv)->eth_dev;
361 344
362 DEBUG(0, "atmel_release(0x%p)\n", link); 345 dev_dbg(&link->dev, "atmel_release\n");
363 346
364 if (dev) 347 if (dev)
365 stop_atmel_card(dev); 348 stop_atmel_card(dev);
diff --git a/drivers/net/wireless/b43/b43.h b/drivers/net/wireless/b43/b43.h
index fa1549a03c71..660716214d49 100644
--- a/drivers/net/wireless/b43/b43.h
+++ b/drivers/net/wireless/b43/b43.h
@@ -607,82 +607,7 @@ struct b43_qos_params {
607 struct ieee80211_tx_queue_params p; 607 struct ieee80211_tx_queue_params p;
608}; 608};
609 609
610struct b43_wldev; 610struct b43_wl;
611
612/* Data structure for the WLAN parts (802.11 cores) of the b43 chip. */
613struct b43_wl {
614 /* Pointer to the active wireless device on this chip */
615 struct b43_wldev *current_dev;
616 /* Pointer to the ieee80211 hardware data structure */
617 struct ieee80211_hw *hw;
618
619 /* Global driver mutex. Every operation must run with this mutex locked. */
620 struct mutex mutex;
621 /* Hard-IRQ spinlock. This lock protects things used in the hard-IRQ
622 * handler, only. This basically is just the IRQ mask register. */
623 spinlock_t hardirq_lock;
624
625 /* The number of queues that were registered with the mac80211 subsystem
626 * initially. This is a backup copy of hw->queues in case hw->queues has
627 * to be dynamically lowered at runtime (Firmware does not support QoS).
628 * hw->queues has to be restored to the original value before unregistering
629 * from the mac80211 subsystem. */
630 u16 mac80211_initially_registered_queues;
631
632 /* We can only have one operating interface (802.11 core)
633 * at a time. General information about this interface follows.
634 */
635
636 struct ieee80211_vif *vif;
637 /* The MAC address of the operating interface. */
638 u8 mac_addr[ETH_ALEN];
639 /* Current BSSID */
640 u8 bssid[ETH_ALEN];
641 /* Interface type. (NL80211_IFTYPE_XXX) */
642 int if_type;
643 /* Is the card operating in AP, STA or IBSS mode? */
644 bool operating;
645 /* filter flags */
646 unsigned int filter_flags;
647 /* Stats about the wireless interface */
648 struct ieee80211_low_level_stats ieee_stats;
649
650#ifdef CONFIG_B43_HWRNG
651 struct hwrng rng;
652 bool rng_initialized;
653 char rng_name[30 + 1];
654#endif /* CONFIG_B43_HWRNG */
655
656 /* List of all wireless devices on this chip */
657 struct list_head devlist;
658 u8 nr_devs;
659
660 bool radiotap_enabled;
661 bool radio_enabled;
662
663 /* The beacon we are currently using (AP or IBSS mode). */
664 struct sk_buff *current_beacon;
665 bool beacon0_uploaded;
666 bool beacon1_uploaded;
667 bool beacon_templates_virgin; /* Never wrote the templates? */
668 struct work_struct beacon_update_trigger;
669
670 /* The current QOS parameters for the 4 queues. */
671 struct b43_qos_params qos_params[4];
672
673 /* Work for adjustment of the transmission power.
674 * This is scheduled when we determine that the actual TX output
675 * power doesn't match what we want. */
676 struct work_struct txpower_adjust_work;
677
678 /* Packet transmit work */
679 struct work_struct tx_work;
680 /* Queue of packets to be transmitted. */
681 struct sk_buff_head tx_queue;
682
683 /* The device LEDs. */
684 struct b43_leds leds;
685};
686 611
687/* The type of the firmware file. */ 612/* The type of the firmware file. */
688enum b43_firmware_file_type { 613enum b43_firmware_file_type {
@@ -824,6 +749,97 @@ struct b43_wldev {
824#endif 749#endif
825}; 750};
826 751
752/*
753 * Include goes here to avoid a dependency problem.
754 * A better fix would be to integrate xmit.h into b43.h.
755 */
756#include "xmit.h"
757
758/* Data structure for the WLAN parts (802.11 cores) of the b43 chip. */
759struct b43_wl {
760 /* Pointer to the active wireless device on this chip */
761 struct b43_wldev *current_dev;
762 /* Pointer to the ieee80211 hardware data structure */
763 struct ieee80211_hw *hw;
764
765 /* Global driver mutex. Every operation must run with this mutex locked. */
766 struct mutex mutex;
767 /* Hard-IRQ spinlock. This lock protects things used in the hard-IRQ
768 * handler, only. This basically is just the IRQ mask register. */
769 spinlock_t hardirq_lock;
770
771 /* The number of queues that were registered with the mac80211 subsystem
772 * initially. This is a backup copy of hw->queues in case hw->queues has
773 * to be dynamically lowered at runtime (Firmware does not support QoS).
774 * hw->queues has to be restored to the original value before unregistering
775 * from the mac80211 subsystem. */
776 u16 mac80211_initially_registered_queues;
777
778 /* We can only have one operating interface (802.11 core)
779 * at a time. General information about this interface follows.
780 */
781
782 struct ieee80211_vif *vif;
783 /* The MAC address of the operating interface. */
784 u8 mac_addr[ETH_ALEN];
785 /* Current BSSID */
786 u8 bssid[ETH_ALEN];
787 /* Interface type. (NL80211_IFTYPE_XXX) */
788 int if_type;
789 /* Is the card operating in AP, STA or IBSS mode? */
790 bool operating;
791 /* filter flags */
792 unsigned int filter_flags;
793 /* Stats about the wireless interface */
794 struct ieee80211_low_level_stats ieee_stats;
795
796#ifdef CONFIG_B43_HWRNG
797 struct hwrng rng;
798 bool rng_initialized;
799 char rng_name[30 + 1];
800#endif /* CONFIG_B43_HWRNG */
801
802 /* List of all wireless devices on this chip */
803 struct list_head devlist;
804 u8 nr_devs;
805
806 bool radiotap_enabled;
807 bool radio_enabled;
808
809 /* The beacon we are currently using (AP or IBSS mode). */
810 struct sk_buff *current_beacon;
811 bool beacon0_uploaded;
812 bool beacon1_uploaded;
813 bool beacon_templates_virgin; /* Never wrote the templates? */
814 struct work_struct beacon_update_trigger;
815
816 /* The current QOS parameters for the 4 queues. */
817 struct b43_qos_params qos_params[4];
818
819 /* Work for adjustment of the transmission power.
820 * This is scheduled when we determine that the actual TX output
821 * power doesn't match what we want. */
822 struct work_struct txpower_adjust_work;
823
824 /* Packet transmit work */
825 struct work_struct tx_work;
826 /* Queue of packets to be transmitted. */
827 struct sk_buff_head tx_queue;
828
829 /* The device LEDs. */
830 struct b43_leds leds;
831
832#ifdef CONFIG_B43_PIO
833 /*
834 * RX/TX header/tail buffers used by the frame transmit functions.
835 */
836 struct b43_rxhdr_fw4 rxhdr;
837 struct b43_txhdr txhdr;
838 u8 rx_tail[4];
839 u8 tx_tail[4];
840#endif /* CONFIG_B43_PIO */
841};
842
827static inline struct b43_wl *hw_to_b43_wl(struct ieee80211_hw *hw) 843static inline struct b43_wl *hw_to_b43_wl(struct ieee80211_hw *hw)
828{ 844{
829 return hw->priv; 845 return hw->priv;
diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c
index 8701034569fa..de4e804bedf0 100644
--- a/drivers/net/wireless/b43/dma.c
+++ b/drivers/net/wireless/b43/dma.c
@@ -1157,8 +1157,9 @@ struct b43_dmaring *parse_cookie(struct b43_wldev *dev, u16 cookie, int *slot)
1157} 1157}
1158 1158
1159static int dma_tx_fragment(struct b43_dmaring *ring, 1159static int dma_tx_fragment(struct b43_dmaring *ring,
1160 struct sk_buff *skb) 1160 struct sk_buff **in_skb)
1161{ 1161{
1162 struct sk_buff *skb = *in_skb;
1162 const struct b43_dma_ops *ops = ring->ops; 1163 const struct b43_dma_ops *ops = ring->ops;
1163 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1164 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1164 u8 *header; 1165 u8 *header;
@@ -1224,8 +1225,14 @@ static int dma_tx_fragment(struct b43_dmaring *ring,
1224 } 1225 }
1225 1226
1226 memcpy(skb_put(bounce_skb, skb->len), skb->data, skb->len); 1227 memcpy(skb_put(bounce_skb, skb->len), skb->data, skb->len);
1228 memcpy(bounce_skb->cb, skb->cb, sizeof(skb->cb));
1229 bounce_skb->dev = skb->dev;
1230 skb_set_queue_mapping(bounce_skb, skb_get_queue_mapping(skb));
1231 info = IEEE80211_SKB_CB(bounce_skb);
1232
1227 dev_kfree_skb_any(skb); 1233 dev_kfree_skb_any(skb);
1228 skb = bounce_skb; 1234 skb = bounce_skb;
1235 *in_skb = bounce_skb;
1229 meta->skb = skb; 1236 meta->skb = skb;
1230 meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1); 1237 meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
1231 if (b43_dma_mapping_error(ring, meta->dmaaddr, skb->len, 1)) { 1238 if (b43_dma_mapping_error(ring, meta->dmaaddr, skb->len, 1)) {
@@ -1355,7 +1362,11 @@ int b43_dma_tx(struct b43_wldev *dev, struct sk_buff *skb)
1355 * static, so we don't need to store it per frame. */ 1362 * static, so we don't need to store it per frame. */
1356 ring->queue_prio = skb_get_queue_mapping(skb); 1363 ring->queue_prio = skb_get_queue_mapping(skb);
1357 1364
1358 err = dma_tx_fragment(ring, skb); 1365 /* dma_tx_fragment might reallocate the skb, so invalidate pointers pointing
1366 * into the skb data or cb now. */
1367 hdr = NULL;
1368 info = NULL;
1369 err = dma_tx_fragment(ring, &skb);
1359 if (unlikely(err == -ENOKEY)) { 1370 if (unlikely(err == -ENOKEY)) {
1360 /* Drop this packet, as we don't have the encryption key 1371 /* Drop this packet, as we don't have the encryption key
1361 * anymore and must not transmit it unencrypted. */ 1372 * anymore and must not transmit it unencrypted. */
diff --git a/drivers/net/wireless/b43/leds.c b/drivers/net/wireless/b43/leds.c
index fbe3d4f62ce2..1e8dba488004 100644
--- a/drivers/net/wireless/b43/leds.c
+++ b/drivers/net/wireless/b43/leds.c
@@ -348,9 +348,9 @@ void b43_leds_register(struct b43_wldev *dev)
348 } 348 }
349} 349}
350 350
351void b43_leds_unregister(struct b43_wldev *dev) 351void b43_leds_unregister(struct b43_wl *wl)
352{ 352{
353 struct b43_leds *leds = &dev->wl->leds; 353 struct b43_leds *leds = &wl->leds;
354 354
355 b43_unregister_led(&leds->led_tx); 355 b43_unregister_led(&leds->led_tx);
356 b43_unregister_led(&leds->led_rx); 356 b43_unregister_led(&leds->led_rx);
diff --git a/drivers/net/wireless/b43/leds.h b/drivers/net/wireless/b43/leds.h
index 9592e4c5a5f5..32b66d53cdac 100644
--- a/drivers/net/wireless/b43/leds.h
+++ b/drivers/net/wireless/b43/leds.h
@@ -1,6 +1,7 @@
1#ifndef B43_LEDS_H_ 1#ifndef B43_LEDS_H_
2#define B43_LEDS_H_ 2#define B43_LEDS_H_
3 3
4struct b43_wl;
4struct b43_wldev; 5struct b43_wldev;
5 6
6#ifdef CONFIG_B43_LEDS 7#ifdef CONFIG_B43_LEDS
@@ -60,7 +61,7 @@ enum b43_led_behaviour {
60}; 61};
61 62
62void b43_leds_register(struct b43_wldev *dev); 63void b43_leds_register(struct b43_wldev *dev);
63void b43_leds_unregister(struct b43_wldev *dev); 64void b43_leds_unregister(struct b43_wl *wl);
64void b43_leds_init(struct b43_wldev *dev); 65void b43_leds_init(struct b43_wldev *dev);
65void b43_leds_exit(struct b43_wldev *dev); 66void b43_leds_exit(struct b43_wldev *dev);
66void b43_leds_stop(struct b43_wldev *dev); 67void b43_leds_stop(struct b43_wldev *dev);
@@ -76,7 +77,7 @@ struct b43_leds {
76static inline void b43_leds_register(struct b43_wldev *dev) 77static inline void b43_leds_register(struct b43_wldev *dev)
77{ 78{
78} 79}
79static inline void b43_leds_unregister(struct b43_wldev *dev) 80static inline void b43_leds_unregister(struct b43_wl *wl)
80{ 81{
81} 82}
82static inline void b43_leds_init(struct b43_wldev *dev) 83static inline void b43_leds_init(struct b43_wldev *dev)
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 9b907a36bb8c..098dda1a67c1 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -3874,6 +3874,7 @@ static struct b43_wldev * b43_wireless_core_stop(struct b43_wldev *dev)
3874{ 3874{
3875 struct b43_wl *wl = dev->wl; 3875 struct b43_wl *wl = dev->wl;
3876 struct b43_wldev *orig_dev; 3876 struct b43_wldev *orig_dev;
3877 u32 mask;
3877 3878
3878redo: 3879redo:
3879 if (!dev || b43_status(dev) < B43_STAT_STARTED) 3880 if (!dev || b43_status(dev) < B43_STAT_STARTED)
@@ -3920,7 +3921,8 @@ redo:
3920 goto redo; 3921 goto redo;
3921 return dev; 3922 return dev;
3922 } 3923 }
3923 B43_WARN_ON(b43_read32(dev, B43_MMIO_GEN_IRQ_MASK)); 3924 mask = b43_read32(dev, B43_MMIO_GEN_IRQ_MASK);
3925 B43_WARN_ON(mask != 0xFFFFFFFF && mask);
3924 3926
3925 /* Drain the TX queue */ 3927 /* Drain the TX queue */
3926 while (skb_queue_len(&wl->tx_queue)) 3928 while (skb_queue_len(&wl->tx_queue))
@@ -4519,9 +4521,8 @@ static int b43_op_beacon_set_tim(struct ieee80211_hw *hw,
4519{ 4521{
4520 struct b43_wl *wl = hw_to_b43_wl(hw); 4522 struct b43_wl *wl = hw_to_b43_wl(hw);
4521 4523
4522 mutex_lock(&wl->mutex); 4524 /* FIXME: add locking */
4523 b43_update_templates(wl); 4525 b43_update_templates(wl);
4524 mutex_unlock(&wl->mutex);
4525 4526
4526 return 0; 4527 return 0;
4527} 4528}
@@ -4997,7 +4998,7 @@ static void b43_remove(struct ssb_device *dev)
4997 4998
4998 if (list_empty(&wl->devlist)) { 4999 if (list_empty(&wl->devlist)) {
4999 b43_rng_exit(wl); 5000 b43_rng_exit(wl);
5000 b43_leds_unregister(wldev); 5001 b43_leds_unregister(wl);
5001 /* Last core on the chip unregistered. 5002 /* Last core on the chip unregistered.
5002 * We can destroy common struct b43_wl. 5003 * We can destroy common struct b43_wl.
5003 */ 5004 */
diff --git a/drivers/net/wireless/b43/pcmcia.c b/drivers/net/wireless/b43/pcmcia.c
index 6c3a74964ab8..984174bc7b0f 100644
--- a/drivers/net/wireless/b43/pcmcia.c
+++ b/drivers/net/wireless/b43/pcmcia.c
@@ -65,35 +65,15 @@ static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
65 struct ssb_bus *ssb; 65 struct ssb_bus *ssb;
66 win_req_t win; 66 win_req_t win;
67 memreq_t mem; 67 memreq_t mem;
68 tuple_t tuple;
69 cisparse_t parse;
70 int err = -ENOMEM; 68 int err = -ENOMEM;
71 int res = 0; 69 int res = 0;
72 unsigned char buf[64];
73 70
74 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL); 71 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
75 if (!ssb) 72 if (!ssb)
76 goto out_error; 73 goto out_error;
77 74
78 err = -ENODEV; 75 err = -ENODEV;
79 tuple.DesiredTuple = CISTPL_CONFIG;
80 tuple.Attributes = 0;
81 tuple.TupleData = buf;
82 tuple.TupleDataMax = sizeof(buf);
83 tuple.TupleOffset = 0;
84 76
85 res = pcmcia_get_first_tuple(dev, &tuple);
86 if (res != 0)
87 goto err_kfree_ssb;
88 res = pcmcia_get_tuple_data(dev, &tuple);
89 if (res != 0)
90 goto err_kfree_ssb;
91 res = pcmcia_parse_tuple(&tuple, &parse);
92 if (res != 0)
93 goto err_kfree_ssb;
94
95 dev->conf.ConfigBase = parse.config.base;
96 dev->conf.Present = parse.config.rmask[0];
97 dev->conf.Attributes = CONF_ENABLE_IRQ; 77 dev->conf.Attributes = CONF_ENABLE_IRQ;
98 dev->conf.IntType = INT_MEMORY_AND_IO; 78 dev->conf.IntType = INT_MEMORY_AND_IO;
99 79
@@ -107,20 +87,18 @@ static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
107 win.Base = 0; 87 win.Base = 0;
108 win.Size = SSB_CORE_SIZE; 88 win.Size = SSB_CORE_SIZE;
109 win.AccessSpeed = 250; 89 win.AccessSpeed = 250;
110 res = pcmcia_request_window(&dev, &win, &dev->win); 90 res = pcmcia_request_window(dev, &win, &dev->win);
111 if (res != 0) 91 if (res != 0)
112 goto err_kfree_ssb; 92 goto err_kfree_ssb;
113 93
114 mem.CardOffset = 0; 94 mem.CardOffset = 0;
115 mem.Page = 0; 95 mem.Page = 0;
116 res = pcmcia_map_mem_page(dev->win, &mem); 96 res = pcmcia_map_mem_page(dev, dev->win, &mem);
117 if (res != 0) 97 if (res != 0)
118 goto err_disable; 98 goto err_disable;
119 99
120 dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING; 100 dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
121 dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
122 dev->irq.Handler = NULL; /* The handler is registered later. */ 101 dev->irq.Handler = NULL; /* The handler is registered later. */
123 dev->irq.Instance = NULL;
124 res = pcmcia_request_irq(dev, &dev->irq); 102 res = pcmcia_request_irq(dev, &dev->irq);
125 if (res != 0) 103 if (res != 0)
126 goto err_disable; 104 goto err_disable;
diff --git a/drivers/net/wireless/b43/pio.c b/drivers/net/wireless/b43/pio.c
index 5e87650b07fb..9b9044400218 100644
--- a/drivers/net/wireless/b43/pio.c
+++ b/drivers/net/wireless/b43/pio.c
@@ -332,6 +332,7 @@ static u16 tx_write_2byte_queue(struct b43_pio_txqueue *q,
332 unsigned int data_len) 332 unsigned int data_len)
333{ 333{
334 struct b43_wldev *dev = q->dev; 334 struct b43_wldev *dev = q->dev;
335 struct b43_wl *wl = dev->wl;
335 const u8 *data = _data; 336 const u8 *data = _data;
336 337
337 ctl |= B43_PIO_TXCTL_WRITELO | B43_PIO_TXCTL_WRITEHI; 338 ctl |= B43_PIO_TXCTL_WRITELO | B43_PIO_TXCTL_WRITEHI;
@@ -341,13 +342,12 @@ static u16 tx_write_2byte_queue(struct b43_pio_txqueue *q,
341 q->mmio_base + B43_PIO_TXDATA, 342 q->mmio_base + B43_PIO_TXDATA,
342 sizeof(u16)); 343 sizeof(u16));
343 if (data_len & 1) { 344 if (data_len & 1) {
344 u8 tail[2] = { 0, };
345
346 /* Write the last byte. */ 345 /* Write the last byte. */
347 ctl &= ~B43_PIO_TXCTL_WRITEHI; 346 ctl &= ~B43_PIO_TXCTL_WRITEHI;
348 b43_piotx_write16(q, B43_PIO_TXCTL, ctl); 347 b43_piotx_write16(q, B43_PIO_TXCTL, ctl);
349 tail[0] = data[data_len - 1]; 348 wl->tx_tail[0] = data[data_len - 1];
350 ssb_block_write(dev->dev, tail, 2, 349 wl->tx_tail[1] = 0;
350 ssb_block_write(dev->dev, wl->tx_tail, 2,
351 q->mmio_base + B43_PIO_TXDATA, 351 q->mmio_base + B43_PIO_TXDATA,
352 sizeof(u16)); 352 sizeof(u16));
353 } 353 }
@@ -382,6 +382,7 @@ static u32 tx_write_4byte_queue(struct b43_pio_txqueue *q,
382 unsigned int data_len) 382 unsigned int data_len)
383{ 383{
384 struct b43_wldev *dev = q->dev; 384 struct b43_wldev *dev = q->dev;
385 struct b43_wl *wl = dev->wl;
385 const u8 *data = _data; 386 const u8 *data = _data;
386 387
387 ctl |= B43_PIO8_TXCTL_0_7 | B43_PIO8_TXCTL_8_15 | 388 ctl |= B43_PIO8_TXCTL_0_7 | B43_PIO8_TXCTL_8_15 |
@@ -392,29 +393,31 @@ static u32 tx_write_4byte_queue(struct b43_pio_txqueue *q,
392 q->mmio_base + B43_PIO8_TXDATA, 393 q->mmio_base + B43_PIO8_TXDATA,
393 sizeof(u32)); 394 sizeof(u32));
394 if (data_len & 3) { 395 if (data_len & 3) {
395 u8 tail[4] = { 0, }; 396 wl->tx_tail[3] = 0;
396
397 /* Write the last few bytes. */ 397 /* Write the last few bytes. */
398 ctl &= ~(B43_PIO8_TXCTL_8_15 | B43_PIO8_TXCTL_16_23 | 398 ctl &= ~(B43_PIO8_TXCTL_8_15 | B43_PIO8_TXCTL_16_23 |
399 B43_PIO8_TXCTL_24_31); 399 B43_PIO8_TXCTL_24_31);
400 switch (data_len & 3) { 400 switch (data_len & 3) {
401 case 3: 401 case 3:
402 ctl |= B43_PIO8_TXCTL_16_23 | B43_PIO8_TXCTL_8_15; 402 ctl |= B43_PIO8_TXCTL_16_23 | B43_PIO8_TXCTL_8_15;
403 tail[0] = data[data_len - 3]; 403 wl->tx_tail[0] = data[data_len - 3];
404 tail[1] = data[data_len - 2]; 404 wl->tx_tail[1] = data[data_len - 2];
405 tail[2] = data[data_len - 1]; 405 wl->tx_tail[2] = data[data_len - 1];
406 break; 406 break;
407 case 2: 407 case 2:
408 ctl |= B43_PIO8_TXCTL_8_15; 408 ctl |= B43_PIO8_TXCTL_8_15;
409 tail[0] = data[data_len - 2]; 409 wl->tx_tail[0] = data[data_len - 2];
410 tail[1] = data[data_len - 1]; 410 wl->tx_tail[1] = data[data_len - 1];
411 wl->tx_tail[2] = 0;
411 break; 412 break;
412 case 1: 413 case 1:
413 tail[0] = data[data_len - 1]; 414 wl->tx_tail[0] = data[data_len - 1];
415 wl->tx_tail[1] = 0;
416 wl->tx_tail[2] = 0;
414 break; 417 break;
415 } 418 }
416 b43_piotx_write32(q, B43_PIO8_TXCTL, ctl); 419 b43_piotx_write32(q, B43_PIO8_TXCTL, ctl);
417 ssb_block_write(dev->dev, tail, 4, 420 ssb_block_write(dev->dev, wl->tx_tail, 4,
418 q->mmio_base + B43_PIO8_TXDATA, 421 q->mmio_base + B43_PIO8_TXDATA,
419 sizeof(u32)); 422 sizeof(u32));
420 } 423 }
@@ -446,8 +449,9 @@ static void pio_tx_frame_4byte_queue(struct b43_pio_txpacket *pack,
446static int pio_tx_frame(struct b43_pio_txqueue *q, 449static int pio_tx_frame(struct b43_pio_txqueue *q,
447 struct sk_buff *skb) 450 struct sk_buff *skb)
448{ 451{
452 struct b43_wldev *dev = q->dev;
453 struct b43_wl *wl = dev->wl;
449 struct b43_pio_txpacket *pack; 454 struct b43_pio_txpacket *pack;
450 struct b43_txhdr txhdr;
451 u16 cookie; 455 u16 cookie;
452 int err; 456 int err;
453 unsigned int hdrlen; 457 unsigned int hdrlen;
@@ -458,8 +462,8 @@ static int pio_tx_frame(struct b43_pio_txqueue *q,
458 struct b43_pio_txpacket, list); 462 struct b43_pio_txpacket, list);
459 463
460 cookie = generate_cookie(q, pack); 464 cookie = generate_cookie(q, pack);
461 hdrlen = b43_txhdr_size(q->dev); 465 hdrlen = b43_txhdr_size(dev);
462 err = b43_generate_txhdr(q->dev, (u8 *)&txhdr, skb, 466 err = b43_generate_txhdr(dev, (u8 *)&wl->txhdr, skb,
463 info, cookie); 467 info, cookie);
464 if (err) 468 if (err)
465 return err; 469 return err;
@@ -467,15 +471,15 @@ static int pio_tx_frame(struct b43_pio_txqueue *q,
467 if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) { 471 if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
468 /* Tell the firmware about the cookie of the last 472 /* Tell the firmware about the cookie of the last
469 * mcast frame, so it can clear the more-data bit in it. */ 473 * mcast frame, so it can clear the more-data bit in it. */
470 b43_shm_write16(q->dev, B43_SHM_SHARED, 474 b43_shm_write16(dev, B43_SHM_SHARED,
471 B43_SHM_SH_MCASTCOOKIE, cookie); 475 B43_SHM_SH_MCASTCOOKIE, cookie);
472 } 476 }
473 477
474 pack->skb = skb; 478 pack->skb = skb;
475 if (q->rev >= 8) 479 if (q->rev >= 8)
476 pio_tx_frame_4byte_queue(pack, (const u8 *)&txhdr, hdrlen); 480 pio_tx_frame_4byte_queue(pack, (const u8 *)&wl->txhdr, hdrlen);
477 else 481 else
478 pio_tx_frame_2byte_queue(pack, (const u8 *)&txhdr, hdrlen); 482 pio_tx_frame_2byte_queue(pack, (const u8 *)&wl->txhdr, hdrlen);
479 483
480 /* Remove it from the list of available packet slots. 484 /* Remove it from the list of available packet slots.
481 * It will be put back when we receive the status report. */ 485 * It will be put back when we receive the status report. */
@@ -615,14 +619,14 @@ void b43_pio_get_tx_stats(struct b43_wldev *dev,
615static bool pio_rx_frame(struct b43_pio_rxqueue *q) 619static bool pio_rx_frame(struct b43_pio_rxqueue *q)
616{ 620{
617 struct b43_wldev *dev = q->dev; 621 struct b43_wldev *dev = q->dev;
618 struct b43_rxhdr_fw4 rxhdr; 622 struct b43_wl *wl = dev->wl;
619 u16 len; 623 u16 len;
620 u32 macstat; 624 u32 macstat;
621 unsigned int i, padding; 625 unsigned int i, padding;
622 struct sk_buff *skb; 626 struct sk_buff *skb;
623 const char *err_msg = NULL; 627 const char *err_msg = NULL;
624 628
625 memset(&rxhdr, 0, sizeof(rxhdr)); 629 memset(&wl->rxhdr, 0, sizeof(wl->rxhdr));
626 630
627 /* Check if we have data and wait for it to get ready. */ 631 /* Check if we have data and wait for it to get ready. */
628 if (q->rev >= 8) { 632 if (q->rev >= 8) {
@@ -660,16 +664,16 @@ data_ready:
660 664
661 /* Get the preamble (RX header) */ 665 /* Get the preamble (RX header) */
662 if (q->rev >= 8) { 666 if (q->rev >= 8) {
663 ssb_block_read(dev->dev, &rxhdr, sizeof(rxhdr), 667 ssb_block_read(dev->dev, &wl->rxhdr, sizeof(wl->rxhdr),
664 q->mmio_base + B43_PIO8_RXDATA, 668 q->mmio_base + B43_PIO8_RXDATA,
665 sizeof(u32)); 669 sizeof(u32));
666 } else { 670 } else {
667 ssb_block_read(dev->dev, &rxhdr, sizeof(rxhdr), 671 ssb_block_read(dev->dev, &wl->rxhdr, sizeof(wl->rxhdr),
668 q->mmio_base + B43_PIO_RXDATA, 672 q->mmio_base + B43_PIO_RXDATA,
669 sizeof(u16)); 673 sizeof(u16));
670 } 674 }
671 /* Sanity checks. */ 675 /* Sanity checks. */
672 len = le16_to_cpu(rxhdr.frame_len); 676 len = le16_to_cpu(wl->rxhdr.frame_len);
673 if (unlikely(len > 0x700)) { 677 if (unlikely(len > 0x700)) {
674 err_msg = "len > 0x700"; 678 err_msg = "len > 0x700";
675 goto rx_error; 679 goto rx_error;
@@ -679,7 +683,7 @@ data_ready:
679 goto rx_error; 683 goto rx_error;
680 } 684 }
681 685
682 macstat = le32_to_cpu(rxhdr.mac_status); 686 macstat = le32_to_cpu(wl->rxhdr.mac_status);
683 if (macstat & B43_RX_MAC_FCSERR) { 687 if (macstat & B43_RX_MAC_FCSERR) {
684 if (!(q->dev->wl->filter_flags & FIF_FCSFAIL)) { 688 if (!(q->dev->wl->filter_flags & FIF_FCSFAIL)) {
685 /* Drop frames with failed FCS. */ 689 /* Drop frames with failed FCS. */
@@ -704,24 +708,22 @@ data_ready:
704 q->mmio_base + B43_PIO8_RXDATA, 708 q->mmio_base + B43_PIO8_RXDATA,
705 sizeof(u32)); 709 sizeof(u32));
706 if (len & 3) { 710 if (len & 3) {
707 u8 tail[4] = { 0, };
708
709 /* Read the last few bytes. */ 711 /* Read the last few bytes. */
710 ssb_block_read(dev->dev, tail, 4, 712 ssb_block_read(dev->dev, wl->rx_tail, 4,
711 q->mmio_base + B43_PIO8_RXDATA, 713 q->mmio_base + B43_PIO8_RXDATA,
712 sizeof(u32)); 714 sizeof(u32));
713 switch (len & 3) { 715 switch (len & 3) {
714 case 3: 716 case 3:
715 skb->data[len + padding - 3] = tail[0]; 717 skb->data[len + padding - 3] = wl->rx_tail[0];
716 skb->data[len + padding - 2] = tail[1]; 718 skb->data[len + padding - 2] = wl->rx_tail[1];
717 skb->data[len + padding - 1] = tail[2]; 719 skb->data[len + padding - 1] = wl->rx_tail[2];
718 break; 720 break;
719 case 2: 721 case 2:
720 skb->data[len + padding - 2] = tail[0]; 722 skb->data[len + padding - 2] = wl->rx_tail[0];
721 skb->data[len + padding - 1] = tail[1]; 723 skb->data[len + padding - 1] = wl->rx_tail[1];
722 break; 724 break;
723 case 1: 725 case 1:
724 skb->data[len + padding - 1] = tail[0]; 726 skb->data[len + padding - 1] = wl->rx_tail[0];
725 break; 727 break;
726 } 728 }
727 } 729 }
@@ -730,17 +732,15 @@ data_ready:
730 q->mmio_base + B43_PIO_RXDATA, 732 q->mmio_base + B43_PIO_RXDATA,
731 sizeof(u16)); 733 sizeof(u16));
732 if (len & 1) { 734 if (len & 1) {
733 u8 tail[2] = { 0, };
734
735 /* Read the last byte. */ 735 /* Read the last byte. */
736 ssb_block_read(dev->dev, tail, 2, 736 ssb_block_read(dev->dev, wl->rx_tail, 2,
737 q->mmio_base + B43_PIO_RXDATA, 737 q->mmio_base + B43_PIO_RXDATA,
738 sizeof(u16)); 738 sizeof(u16));
739 skb->data[len + padding - 1] = tail[0]; 739 skb->data[len + padding - 1] = wl->rx_tail[0];
740 } 740 }
741 } 741 }
742 742
743 b43_rx(q->dev, skb, &rxhdr); 743 b43_rx(q->dev, skb, &wl->rxhdr);
744 744
745 return 1; 745 return 1;
746 746
diff --git a/drivers/net/wireless/b43/rfkill.c b/drivers/net/wireless/b43/rfkill.c
index 7a3218c5ba7d..ffdce6f3c909 100644
--- a/drivers/net/wireless/b43/rfkill.c
+++ b/drivers/net/wireless/b43/rfkill.c
@@ -33,7 +33,8 @@ bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
33 & B43_MMIO_RADIO_HWENABLED_HI_MASK)) 33 & B43_MMIO_RADIO_HWENABLED_HI_MASK))
34 return 1; 34 return 1;
35 } else { 35 } else {
36 if (b43_read16(dev, B43_MMIO_RADIO_HWENABLED_LO) 36 if (b43_status(dev) >= B43_STAT_STARTED &&
37 b43_read16(dev, B43_MMIO_RADIO_HWENABLED_LO)
37 & B43_MMIO_RADIO_HWENABLED_LO_MASK) 38 & B43_MMIO_RADIO_HWENABLED_LO_MASK)
38 return 1; 39 return 1;
39 } 40 }
diff --git a/drivers/net/wireless/b43/xmit.c b/drivers/net/wireless/b43/xmit.c
index ac9f600995e4..f4e9695ec186 100644
--- a/drivers/net/wireless/b43/xmit.c
+++ b/drivers/net/wireless/b43/xmit.c
@@ -27,7 +27,7 @@
27 27
28*/ 28*/
29 29
30#include "xmit.h" 30#include "b43.h"
31#include "phy_common.h" 31#include "phy_common.h"
32#include "dma.h" 32#include "dma.h"
33#include "pio.h" 33#include "pio.h"
@@ -690,7 +690,10 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
690 } 690 }
691 691
692 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); 692 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
693
694 local_bh_disable();
693 ieee80211_rx(dev->wl->hw, skb); 695 ieee80211_rx(dev->wl->hw, skb);
696 local_bh_enable();
694 697
695#if B43_DEBUG 698#if B43_DEBUG
696 dev->rx_count++; 699 dev->rx_count++;
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
index ad8eab4a639b..c9640a3e02c9 100644
--- a/drivers/net/wireless/hostap/hostap_cs.c
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -274,9 +274,6 @@ static int sandisk_enable_wireless(struct net_device *dev)
274 conf_reg_t reg; 274 conf_reg_t reg;
275 struct hostap_interface *iface = netdev_priv(dev); 275 struct hostap_interface *iface = netdev_priv(dev);
276 local_info_t *local = iface->local; 276 local_info_t *local = iface->local;
277 tuple_t tuple;
278 cisparse_t *parse = NULL;
279 u_char buf[64];
280 struct hostap_cs_priv *hw_priv = local->hw_priv; 277 struct hostap_cs_priv *hw_priv = local->hw_priv;
281 278
282 if (hw_priv->link->io.NumPorts1 < 0x42) { 279 if (hw_priv->link->io.NumPorts1 < 0x42) {
@@ -285,28 +282,13 @@ static int sandisk_enable_wireless(struct net_device *dev)
285 goto done; 282 goto done;
286 } 283 }
287 284
288 parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
289 if (parse == NULL) {
290 ret = -ENOMEM;
291 goto done;
292 }
293
294 tuple.Attributes = TUPLE_RETURN_COMMON;
295 tuple.TupleData = buf;
296 tuple.TupleDataMax = sizeof(buf);
297 tuple.TupleOffset = 0;
298
299 if (hw_priv->link->manf_id != 0xd601 || hw_priv->link->card_id != 0x0101) { 285 if (hw_priv->link->manf_id != 0xd601 || hw_priv->link->card_id != 0x0101) {
300 /* No SanDisk manfid found */ 286 /* No SanDisk manfid found */
301 ret = -ENODEV; 287 ret = -ENODEV;
302 goto done; 288 goto done;
303 } 289 }
304 290
305 tuple.DesiredTuple = CISTPL_LONGLINK_MFC; 291 if (hw_priv->link->socket->functions < 2) {
306 if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
307 pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
308 pcmcia_parse_tuple(&tuple, parse) ||
309 parse->longlink_mfc.nfn < 2) {
310 /* No multi-function links found */ 292 /* No multi-function links found */
311 ret = -ENODEV; 293 ret = -ENODEV;
312 goto done; 294 goto done;
@@ -354,7 +336,6 @@ static int sandisk_enable_wireless(struct net_device *dev)
354 udelay(10); 336 udelay(10);
355 337
356done: 338done:
357 kfree(parse);
358 return ret; 339 return ret;
359} 340}
360 341
@@ -529,10 +510,6 @@ static void prism2_detach(struct pcmcia_device *link)
529} 510}
530 511
531 512
532#define CS_CHECK(fn, ret) \
533do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
534
535
536/* run after a CARD_INSERTION event is received to configure the PCMCIA 513/* run after a CARD_INSERTION event is received to configure the PCMCIA
537 * socket and make the device available to the system */ 514 * socket and make the device available to the system */
538 515
@@ -624,7 +601,6 @@ static int prism2_config(struct pcmcia_device *link)
624 struct hostap_interface *iface; 601 struct hostap_interface *iface;
625 local_info_t *local; 602 local_info_t *local;
626 int ret = 1; 603 int ret = 1;
627 int last_fn, last_ret;
628 struct hostap_cs_priv *hw_priv; 604 struct hostap_cs_priv *hw_priv;
629 605
630 PDEBUG(DEBUG_FLOW, "prism2_config()\n"); 606 PDEBUG(DEBUG_FLOW, "prism2_config()\n");
@@ -636,19 +612,18 @@ static int prism2_config(struct pcmcia_device *link)
636 } 612 }
637 613
638 /* Look for an appropriate configuration table entry in the CIS */ 614 /* Look for an appropriate configuration table entry in the CIS */
639 last_ret = pcmcia_loop_config(link, prism2_config_check, NULL); 615 ret = pcmcia_loop_config(link, prism2_config_check, NULL);
640 if (last_ret) { 616 if (ret) {
641 if (!ignore_cis_vcc) 617 if (!ignore_cis_vcc)
642 printk(KERN_ERR "GetNextTuple(): No matching " 618 printk(KERN_ERR "GetNextTuple(): No matching "
643 "CIS configuration. Maybe you need the " 619 "CIS configuration. Maybe you need the "
644 "ignore_cis_vcc=1 parameter.\n"); 620 "ignore_cis_vcc=1 parameter.\n");
645 cs_error(link, RequestIO, last_ret);
646 goto failed; 621 goto failed;
647 } 622 }
648 623
649 /* Need to allocate net_device before requesting IRQ handler */ 624 /* Need to allocate net_device before requesting IRQ handler */
650 dev = prism2_init_local_data(&prism2_pccard_funcs, 0, 625 dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
651 &handle_to_dev(link)); 626 &link->dev);
652 if (dev == NULL) 627 if (dev == NULL)
653 goto failed; 628 goto failed;
654 link->priv = dev; 629 link->priv = dev;
@@ -666,13 +641,11 @@ static int prism2_config(struct pcmcia_device *link)
666 * irq structure is initialized. 641 * irq structure is initialized.
667 */ 642 */
668 if (link->conf.Attributes & CONF_ENABLE_IRQ) { 643 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
669 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | 644 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
670 IRQ_HANDLE_PRESENT;
671 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
672 link->irq.Handler = prism2_interrupt; 645 link->irq.Handler = prism2_interrupt;
673 link->irq.Instance = dev; 646 ret = pcmcia_request_irq(link, &link->irq);
674 CS_CHECK(RequestIRQ, 647 if (ret)
675 pcmcia_request_irq(link, &link->irq)); 648 goto failed;
676 } 649 }
677 650
678 /* 651 /*
@@ -680,8 +653,9 @@ static int prism2_config(struct pcmcia_device *link)
680 * the I/O windows and the interrupt mapping, and putting the 653 * the I/O windows and the interrupt mapping, and putting the
681 * card and host interface into "Memory and IO" mode. 654 * card and host interface into "Memory and IO" mode.
682 */ 655 */
683 CS_CHECK(RequestConfiguration, 656 ret = pcmcia_request_configuration(link, &link->conf);
684 pcmcia_request_configuration(link, &link->conf)); 657 if (ret)
658 goto failed;
685 659
686 dev->irq = link->irq.AssignedIRQ; 660 dev->irq = link->irq.AssignedIRQ;
687 dev->base_addr = link->io.BasePort1; 661 dev->base_addr = link->io.BasePort1;
@@ -714,9 +688,6 @@ static int prism2_config(struct pcmcia_device *link)
714 } 688 }
715 return ret; 689 return ret;
716 690
717 cs_failed:
718 cs_error(link, last_fn, last_ret);
719
720 failed: 691 failed:
721 kfree(hw_priv); 692 kfree(hw_priv);
722 prism2_release((u_long)link); 693 prism2_release((u_long)link);
diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
index 240cff1e6979..6e2fc0cb6f8a 100644
--- a/drivers/net/wireless/ipw2x00/ipw2100.c
+++ b/drivers/net/wireless/ipw2x00/ipw2100.c
@@ -6029,7 +6029,7 @@ static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev,
6029 struct ipw2100_priv *priv; 6029 struct ipw2100_priv *priv;
6030 struct net_device *dev; 6030 struct net_device *dev;
6031 6031
6032 dev = alloc_ieee80211(sizeof(struct ipw2100_priv), 0); 6032 dev = alloc_ieee80211(sizeof(struct ipw2100_priv));
6033 if (!dev) 6033 if (!dev)
6034 return NULL; 6034 return NULL;
6035 priv = libipw_priv(dev); 6035 priv = libipw_priv(dev);
@@ -6342,7 +6342,7 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6342 sysfs_remove_group(&pci_dev->dev.kobj, 6342 sysfs_remove_group(&pci_dev->dev.kobj,
6343 &ipw2100_attribute_group); 6343 &ipw2100_attribute_group);
6344 6344
6345 free_ieee80211(dev, 0); 6345 free_ieee80211(dev);
6346 pci_set_drvdata(pci_dev, NULL); 6346 pci_set_drvdata(pci_dev, NULL);
6347 } 6347 }
6348 6348
@@ -6400,7 +6400,7 @@ static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6400 if (dev->base_addr) 6400 if (dev->base_addr)
6401 iounmap((void __iomem *)dev->base_addr); 6401 iounmap((void __iomem *)dev->base_addr);
6402 6402
6403 free_ieee80211(dev, 0); 6403 free_ieee80211(dev);
6404 } 6404 }
6405 6405
6406 pci_release_regions(pci_dev); 6406 pci_release_regions(pci_dev);
diff --git a/drivers/net/wireless/ipw2x00/ipw2200.c b/drivers/net/wireless/ipw2x00/ipw2200.c
index 827824d45de9..a6ca536e44f8 100644
--- a/drivers/net/wireless/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/ipw2x00/ipw2200.c
@@ -104,25 +104,6 @@ static int antenna = CFG_SYS_ANTENNA_BOTH;
104static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */ 104static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
105#endif 105#endif
106 106
107static struct ieee80211_rate ipw2200_rates[] = {
108 { .bitrate = 10 },
109 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
110 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
111 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
112 { .bitrate = 60 },
113 { .bitrate = 90 },
114 { .bitrate = 120 },
115 { .bitrate = 180 },
116 { .bitrate = 240 },
117 { .bitrate = 360 },
118 { .bitrate = 480 },
119 { .bitrate = 540 }
120};
121
122#define ipw2200_a_rates (ipw2200_rates + 4)
123#define ipw2200_num_a_rates 8
124#define ipw2200_bg_rates (ipw2200_rates + 0)
125#define ipw2200_num_bg_rates 12
126 107
127#ifdef CONFIG_IPW2200_QOS 108#ifdef CONFIG_IPW2200_QOS
128static int qos_enable = 0; 109static int qos_enable = 0;
@@ -8674,6 +8655,24 @@ static int ipw_sw_reset(struct ipw_priv *priv, int option)
8674 * 8655 *
8675 */ 8656 */
8676 8657
8658static int ipw_wx_get_name(struct net_device *dev,
8659 struct iw_request_info *info,
8660 union iwreq_data *wrqu, char *extra)
8661{
8662 struct ipw_priv *priv = libipw_priv(dev);
8663 mutex_lock(&priv->mutex);
8664 if (priv->status & STATUS_RF_KILL_MASK)
8665 strcpy(wrqu->name, "radio off");
8666 else if (!(priv->status & STATUS_ASSOCIATED))
8667 strcpy(wrqu->name, "unassociated");
8668 else
8669 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8670 ipw_modes[priv->assoc_request.ieee_mode]);
8671 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
8672 mutex_unlock(&priv->mutex);
8673 return 0;
8674}
8675
8677static int ipw_set_channel(struct ipw_priv *priv, u8 channel) 8676static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8678{ 8677{
8679 if (channel == 0) { 8678 if (channel == 0) {
@@ -9973,7 +9972,7 @@ static int ipw_wx_sw_reset(struct net_device *dev,
9973/* Rebase the WE IOCTLs to zero for the handler array */ 9972/* Rebase the WE IOCTLs to zero for the handler array */
9974#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] 9973#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
9975static iw_handler ipw_wx_handlers[] = { 9974static iw_handler ipw_wx_handlers[] = {
9976 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname, 9975 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9977 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, 9976 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9978 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, 9977 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9979 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, 9978 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
@@ -11417,100 +11416,16 @@ static void ipw_bg_down(struct work_struct *work)
11417/* Called by register_netdev() */ 11416/* Called by register_netdev() */
11418static int ipw_net_init(struct net_device *dev) 11417static int ipw_net_init(struct net_device *dev)
11419{ 11418{
11420 int i, rc = 0;
11421 struct ipw_priv *priv = libipw_priv(dev); 11419 struct ipw_priv *priv = libipw_priv(dev);
11422 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11423 struct wireless_dev *wdev = &priv->ieee->wdev;
11424 mutex_lock(&priv->mutex); 11420 mutex_lock(&priv->mutex);
11425 11421
11426 if (ipw_up(priv)) { 11422 if (ipw_up(priv)) {
11427 rc = -EIO; 11423 mutex_unlock(&priv->mutex);
11428 goto out; 11424 return -EIO;
11429 }
11430
11431 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11432
11433 /* fill-out priv->ieee->bg_band */
11434 if (geo->bg_channels) {
11435 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11436
11437 bg_band->band = IEEE80211_BAND_2GHZ;
11438 bg_band->n_channels = geo->bg_channels;
11439 bg_band->channels =
11440 kzalloc(geo->bg_channels *
11441 sizeof(struct ieee80211_channel), GFP_KERNEL);
11442 /* translate geo->bg to bg_band.channels */
11443 for (i = 0; i < geo->bg_channels; i++) {
11444 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
11445 bg_band->channels[i].center_freq = geo->bg[i].freq;
11446 bg_band->channels[i].hw_value = geo->bg[i].channel;
11447 bg_band->channels[i].max_power = geo->bg[i].max_power;
11448 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11449 bg_band->channels[i].flags |=
11450 IEEE80211_CHAN_PASSIVE_SCAN;
11451 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11452 bg_band->channels[i].flags |=
11453 IEEE80211_CHAN_NO_IBSS;
11454 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11455 bg_band->channels[i].flags |=
11456 IEEE80211_CHAN_RADAR;
11457 /* No equivalent for LIBIPW_CH_80211H_RULES,
11458 LIBIPW_CH_UNIFORM_SPREADING, or
11459 LIBIPW_CH_B_ONLY... */
11460 }
11461 /* point at bitrate info */
11462 bg_band->bitrates = ipw2200_bg_rates;
11463 bg_band->n_bitrates = ipw2200_num_bg_rates;
11464
11465 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
11466 }
11467
11468 /* fill-out priv->ieee->a_band */
11469 if (geo->a_channels) {
11470 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11471
11472 a_band->band = IEEE80211_BAND_5GHZ;
11473 a_band->n_channels = geo->a_channels;
11474 a_band->channels =
11475 kzalloc(geo->a_channels *
11476 sizeof(struct ieee80211_channel), GFP_KERNEL);
11477 /* translate geo->bg to a_band.channels */
11478 for (i = 0; i < geo->a_channels; i++) {
11479 a_band->channels[i].band = IEEE80211_BAND_2GHZ;
11480 a_band->channels[i].center_freq = geo->a[i].freq;
11481 a_band->channels[i].hw_value = geo->a[i].channel;
11482 a_band->channels[i].max_power = geo->a[i].max_power;
11483 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11484 a_band->channels[i].flags |=
11485 IEEE80211_CHAN_PASSIVE_SCAN;
11486 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11487 a_band->channels[i].flags |=
11488 IEEE80211_CHAN_NO_IBSS;
11489 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11490 a_band->channels[i].flags |=
11491 IEEE80211_CHAN_RADAR;
11492 /* No equivalent for LIBIPW_CH_80211H_RULES,
11493 LIBIPW_CH_UNIFORM_SPREADING, or
11494 LIBIPW_CH_B_ONLY... */
11495 }
11496 /* point at bitrate info */
11497 a_band->bitrates = ipw2200_a_rates;
11498 a_band->n_bitrates = ipw2200_num_a_rates;
11499
11500 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
11501 }
11502
11503 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11504
11505 /* With that information in place, we can now register the wiphy... */
11506 if (wiphy_register(wdev->wiphy)) {
11507 rc = -EIO;
11508 goto out;
11509 } 11425 }
11510 11426
11511out:
11512 mutex_unlock(&priv->mutex); 11427 mutex_unlock(&priv->mutex);
11513 return rc; 11428 return 0;
11514} 11429}
11515 11430
11516/* PCI driver stuff */ 11431/* PCI driver stuff */
@@ -11641,7 +11556,7 @@ static int ipw_prom_alloc(struct ipw_priv *priv)
11641 if (priv->prom_net_dev) 11556 if (priv->prom_net_dev)
11642 return -EPERM; 11557 return -EPERM;
11643 11558
11644 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv), 1); 11559 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
11645 if (priv->prom_net_dev == NULL) 11560 if (priv->prom_net_dev == NULL)
11646 return -ENOMEM; 11561 return -ENOMEM;
11647 11562
@@ -11660,7 +11575,7 @@ static int ipw_prom_alloc(struct ipw_priv *priv)
11660 11575
11661 rc = register_netdev(priv->prom_net_dev); 11576 rc = register_netdev(priv->prom_net_dev);
11662 if (rc) { 11577 if (rc) {
11663 free_ieee80211(priv->prom_net_dev, 1); 11578 free_ieee80211(priv->prom_net_dev);
11664 priv->prom_net_dev = NULL; 11579 priv->prom_net_dev = NULL;
11665 return rc; 11580 return rc;
11666 } 11581 }
@@ -11674,7 +11589,7 @@ static void ipw_prom_free(struct ipw_priv *priv)
11674 return; 11589 return;
11675 11590
11676 unregister_netdev(priv->prom_net_dev); 11591 unregister_netdev(priv->prom_net_dev);
11677 free_ieee80211(priv->prom_net_dev, 1); 11592 free_ieee80211(priv->prom_net_dev);
11678 11593
11679 priv->prom_net_dev = NULL; 11594 priv->prom_net_dev = NULL;
11680} 11595}
@@ -11702,7 +11617,7 @@ static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11702 struct ipw_priv *priv; 11617 struct ipw_priv *priv;
11703 int i; 11618 int i;
11704 11619
11705 net_dev = alloc_ieee80211(sizeof(struct ipw_priv), 0); 11620 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11706 if (net_dev == NULL) { 11621 if (net_dev == NULL) {
11707 err = -ENOMEM; 11622 err = -ENOMEM;
11708 goto out; 11623 goto out;
@@ -11850,7 +11765,7 @@ static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11850 pci_disable_device(pdev); 11765 pci_disable_device(pdev);
11851 pci_set_drvdata(pdev, NULL); 11766 pci_set_drvdata(pdev, NULL);
11852 out_free_ieee80211: 11767 out_free_ieee80211:
11853 free_ieee80211(priv->net_dev, 0); 11768 free_ieee80211(priv->net_dev);
11854 out: 11769 out:
11855 return err; 11770 return err;
11856} 11771}
@@ -11917,7 +11832,7 @@ static void __devexit ipw_pci_remove(struct pci_dev *pdev)
11917 pci_release_regions(pdev); 11832 pci_release_regions(pdev);
11918 pci_disable_device(pdev); 11833 pci_disable_device(pdev);
11919 pci_set_drvdata(pdev, NULL); 11834 pci_set_drvdata(pdev, NULL);
11920 free_ieee80211(priv->net_dev, 0); 11835 free_ieee80211(priv->net_dev);
11921 free_firmware(); 11836 free_firmware();
11922} 11837}
11923 11838
diff --git a/drivers/net/wireless/ipw2x00/libipw.h b/drivers/net/wireless/ipw2x00/libipw.h
index bf45391172f3..1e334ff6bd52 100644
--- a/drivers/net/wireless/ipw2x00/libipw.h
+++ b/drivers/net/wireless/ipw2x00/libipw.h
@@ -31,7 +31,6 @@
31#include <linux/ieee80211.h> 31#include <linux/ieee80211.h>
32 32
33#include <net/lib80211.h> 33#include <net/lib80211.h>
34#include <net/cfg80211.h>
35 34
36#define LIBIPW_VERSION "git-1.1.13" 35#define LIBIPW_VERSION "git-1.1.13"
37 36
@@ -784,15 +783,12 @@ struct libipw_geo {
784 783
785struct libipw_device { 784struct libipw_device {
786 struct net_device *dev; 785 struct net_device *dev;
787 struct wireless_dev wdev;
788 struct libipw_security sec; 786 struct libipw_security sec;
789 787
790 /* Bookkeeping structures */ 788 /* Bookkeeping structures */
791 struct libipw_stats ieee_stats; 789 struct libipw_stats ieee_stats;
792 790
793 struct libipw_geo geo; 791 struct libipw_geo geo;
794 struct ieee80211_supported_band bg_band;
795 struct ieee80211_supported_band a_band;
796 792
797 /* Probe / Beacon management */ 793 /* Probe / Beacon management */
798 struct list_head network_free_list; 794 struct list_head network_free_list;
@@ -1018,8 +1014,8 @@ static inline int libipw_is_cck_rate(u8 rate)
1018} 1014}
1019 1015
1020/* ieee80211.c */ 1016/* ieee80211.c */
1021extern void free_ieee80211(struct net_device *dev, int monitor); 1017extern void free_ieee80211(struct net_device *dev);
1022extern struct net_device *alloc_ieee80211(int sizeof_priv, int monitor); 1018extern struct net_device *alloc_ieee80211(int sizeof_priv);
1023extern int libipw_change_mtu(struct net_device *dev, int new_mtu); 1019extern int libipw_change_mtu(struct net_device *dev, int new_mtu);
1024 1020
1025extern void libipw_networks_age(struct libipw_device *ieee, 1021extern void libipw_networks_age(struct libipw_device *ieee,
diff --git a/drivers/net/wireless/ipw2x00/libipw_module.c b/drivers/net/wireless/ipw2x00/libipw_module.c
index a0e9f6aed7da..eb2b60834c17 100644
--- a/drivers/net/wireless/ipw2x00/libipw_module.c
+++ b/drivers/net/wireless/ipw2x00/libipw_module.c
@@ -62,9 +62,6 @@ MODULE_DESCRIPTION(DRV_DESCRIPTION);
62MODULE_AUTHOR(DRV_COPYRIGHT); 62MODULE_AUTHOR(DRV_COPYRIGHT);
63MODULE_LICENSE("GPL"); 63MODULE_LICENSE("GPL");
64 64
65struct cfg80211_ops libipw_config_ops = { };
66void *libipw_wiphy_privid = &libipw_wiphy_privid;
67
68static int libipw_networks_allocate(struct libipw_device *ieee) 65static int libipw_networks_allocate(struct libipw_device *ieee)
69{ 66{
70 if (ieee->networks) 67 if (ieee->networks)
@@ -143,7 +140,7 @@ int libipw_change_mtu(struct net_device *dev, int new_mtu)
143} 140}
144EXPORT_SYMBOL(libipw_change_mtu); 141EXPORT_SYMBOL(libipw_change_mtu);
145 142
146struct net_device *alloc_ieee80211(int sizeof_priv, int monitor) 143struct net_device *alloc_ieee80211(int sizeof_priv)
147{ 144{
148 struct libipw_device *ieee; 145 struct libipw_device *ieee;
149 struct net_device *dev; 146 struct net_device *dev;
@@ -160,31 +157,10 @@ struct net_device *alloc_ieee80211(int sizeof_priv, int monitor)
160 157
161 ieee->dev = dev; 158 ieee->dev = dev;
162 159
163 if (!monitor) {
164 ieee->wdev.wiphy = wiphy_new(&libipw_config_ops, 0);
165 if (!ieee->wdev.wiphy) {
166 LIBIPW_ERROR("Unable to allocate wiphy.\n");
167 goto failed_free_netdev;
168 }
169
170 ieee->dev->ieee80211_ptr = &ieee->wdev;
171 ieee->wdev.iftype = NL80211_IFTYPE_STATION;
172
173 /* Fill-out wiphy structure bits we know... Not enough info
174 here to call set_wiphy_dev or set MAC address or channel info
175 -- have to do that in ->ndo_init... */
176 ieee->wdev.wiphy->privid = libipw_wiphy_privid;
177
178 ieee->wdev.wiphy->max_scan_ssids = 1;
179 ieee->wdev.wiphy->max_scan_ie_len = 0;
180 ieee->wdev.wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
181 | BIT(NL80211_IFTYPE_ADHOC);
182 }
183
184 err = libipw_networks_allocate(ieee); 160 err = libipw_networks_allocate(ieee);
185 if (err) { 161 if (err) {
186 LIBIPW_ERROR("Unable to allocate beacon storage: %d\n", err); 162 LIBIPW_ERROR("Unable to allocate beacon storage: %d\n", err);
187 goto failed_free_wiphy; 163 goto failed_free_netdev;
188 } 164 }
189 libipw_networks_initialize(ieee); 165 libipw_networks_initialize(ieee);
190 166
@@ -217,31 +193,19 @@ struct net_device *alloc_ieee80211(int sizeof_priv, int monitor)
217 193
218 return dev; 194 return dev;
219 195
220failed_free_wiphy:
221 if (!monitor)
222 wiphy_free(ieee->wdev.wiphy);
223failed_free_netdev: 196failed_free_netdev:
224 free_netdev(dev); 197 free_netdev(dev);
225failed: 198failed:
226 return NULL; 199 return NULL;
227} 200}
228 201
229void free_ieee80211(struct net_device *dev, int monitor) 202void free_ieee80211(struct net_device *dev)
230{ 203{
231 struct libipw_device *ieee = netdev_priv(dev); 204 struct libipw_device *ieee = netdev_priv(dev);
232 205
233 lib80211_crypt_info_free(&ieee->crypt_info); 206 lib80211_crypt_info_free(&ieee->crypt_info);
234 207
235 libipw_networks_free(ieee); 208 libipw_networks_free(ieee);
236
237 /* free cfg80211 resources */
238 if (!monitor) {
239 wiphy_unregister(ieee->wdev.wiphy);
240 kfree(ieee->a_band.channels);
241 kfree(ieee->bg_band.channels);
242 wiphy_free(ieee->wdev.wiphy);
243 }
244
245 free_netdev(dev); 209 free_netdev(dev);
246} 210}
247 211
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
index 2716b91ba9fa..950267ab556a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
@@ -161,5 +161,6 @@ struct iwl_cfg iwl1000_bgn_cfg = {
161 .max_ll_items = OTP_MAX_LL_ITEMS_1000, 161 .max_ll_items = OTP_MAX_LL_ITEMS_1000,
162 .shadow_ram_support = false, 162 .shadow_ram_support = false,
163 .ht_greenfield_support = true, 163 .ht_greenfield_support = true,
164 .use_rts_for_ht = true, /* use rts/cts protection */
164}; 165};
165 166
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index a16bd4147eac..cbb0585083a9 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -702,7 +702,7 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
702 u8 sta_id = iwl_find_station(priv, hdr->addr1); 702 u8 sta_id = iwl_find_station(priv, hdr->addr1);
703 703
704 if (sta_id == IWL_INVALID_STATION) { 704 if (sta_id == IWL_INVALID_STATION) {
705 IWL_DEBUG_RATE(priv, "LQ: ADD station %pm\n", 705 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n",
706 hdr->addr1); 706 hdr->addr1);
707 sta_id = iwl_add_station(priv, hdr->addr1, false, 707 sta_id = iwl_add_station(priv, hdr->addr1, false,
708 CMD_ASYNC, NULL); 708 CMD_ASYNC, NULL);
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index 68136172b823..f059b49dc691 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -611,7 +611,7 @@ static void iwl3945_rx_reply_rx(struct iwl_priv *priv,
611 if (rx_status.band == IEEE80211_BAND_5GHZ) 611 if (rx_status.band == IEEE80211_BAND_5GHZ)
612 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE; 612 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
613 613
614 rx_status.antenna = le16_to_cpu(rx_hdr->phy_flags & 614 rx_status.antenna = (le16_to_cpu(rx_hdr->phy_flags) &
615 RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4; 615 RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
616 616
617 /* set the preamble flag if appropriate */ 617 /* set the preamble flag if appropriate */
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index d6bc0e051043..6e6f516ba404 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -318,7 +318,7 @@ static void iwl5000_gain_computation(struct iwl_priv *priv,
318 (s32)average_noise[i])) / 1500; 318 (s32)average_noise[i])) / 1500;
319 /* bound gain by 2 bits value max, 3rd bit is sign */ 319 /* bound gain by 2 bits value max, 3rd bit is sign */
320 data->delta_gain_code[i] = 320 data->delta_gain_code[i] =
321 min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE); 321 min(abs(delta_g), (long) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
322 322
323 if (delta_g < 0) 323 if (delta_g < 0)
324 /* set negative sign */ 324 /* set negative sign */
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index c295b8ee9228..1473452ba22f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -175,6 +175,7 @@ struct iwl_cfg iwl6000h_2agn_cfg = {
175 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 175 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
176 .shadow_ram_support = true, 176 .shadow_ram_support = true,
177 .ht_greenfield_support = true, 177 .ht_greenfield_support = true,
178 .use_rts_for_ht = true, /* use rts/cts protection */
178}; 179};
179 180
180/* 181/*
@@ -198,6 +199,7 @@ struct iwl_cfg iwl6000i_2agn_cfg = {
198 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 199 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
199 .shadow_ram_support = true, 200 .shadow_ram_support = true,
200 .ht_greenfield_support = true, 201 .ht_greenfield_support = true,
202 .use_rts_for_ht = true, /* use rts/cts protection */
201}; 203};
202 204
203struct iwl_cfg iwl6050_2agn_cfg = { 205struct iwl_cfg iwl6050_2agn_cfg = {
@@ -218,6 +220,7 @@ struct iwl_cfg iwl6050_2agn_cfg = {
218 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 220 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
219 .shadow_ram_support = true, 221 .shadow_ram_support = true,
220 .ht_greenfield_support = true, 222 .ht_greenfield_support = true,
223 .use_rts_for_ht = true, /* use rts/cts protection */
221}; 224};
222 225
223struct iwl_cfg iwl6000_3agn_cfg = { 226struct iwl_cfg iwl6000_3agn_cfg = {
@@ -238,6 +241,7 @@ struct iwl_cfg iwl6000_3agn_cfg = {
238 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 241 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
239 .shadow_ram_support = true, 242 .shadow_ram_support = true,
240 .ht_greenfield_support = true, 243 .ht_greenfield_support = true,
244 .use_rts_for_ht = true, /* use rts/cts protection */
241}; 245};
242 246
243struct iwl_cfg iwl6050_3agn_cfg = { 247struct iwl_cfg iwl6050_3agn_cfg = {
@@ -258,6 +262,7 @@ struct iwl_cfg iwl6050_3agn_cfg = {
258 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 262 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
259 .shadow_ram_support = true, 263 .shadow_ram_support = true,
260 .ht_greenfield_support = true, 264 .ht_greenfield_support = true,
265 .use_rts_for_ht = true, /* use rts/cts protection */
261}; 266};
262 267
263MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_MAX)); 268MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_MAX));
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index 346dc06fa7b7..81726ee32858 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -418,6 +418,15 @@ static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid,
418 else if (tid == IWL_AGG_ALL_TID) 418 else if (tid == IWL_AGG_ALL_TID)
419 for (tid = 0; tid < TID_MAX_LOAD_COUNT; tid++) 419 for (tid = 0; tid < TID_MAX_LOAD_COUNT; tid++)
420 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta); 420 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta);
421 if (priv->cfg->use_rts_for_ht) {
422 /*
423 * switch to RTS/CTS if it is the prefer protection method
424 * for HT traffic
425 */
426 IWL_DEBUG_HT(priv, "use RTS/CTS protection for HT\n");
427 priv->staging_rxon.flags &= ~RXON_FLG_SELF_CTS_EN;
428 iwlcore_commit_rxon(priv);
429 }
421} 430}
422 431
423static inline int get_num_of_ant_from_rate(u32 rate_n_flags) 432static inline int get_num_of_ant_from_rate(u32 rate_n_flags)
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 313d3e5ee84b..921dc4a26fe2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -116,9 +116,6 @@ int iwl_commit_rxon(struct iwl_priv *priv)
116 116
117 /* always get timestamp with Rx frame */ 117 /* always get timestamp with Rx frame */
118 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; 118 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
119 /* allow CTS-to-self if possible. this is relevant only for
120 * 5000, but will not damage 4965 */
121 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
122 119
123 ret = iwl_check_rxon_cmd(priv); 120 ret = iwl_check_rxon_cmd(priv);
124 if (ret) { 121 if (ret) {
@@ -218,6 +215,13 @@ int iwl_commit_rxon(struct iwl_priv *priv)
218 "Could not send WEP static key.\n"); 215 "Could not send WEP static key.\n");
219 } 216 }
220 217
218 /*
219 * allow CTS-to-self if possible for new association.
220 * this is relevant only for 5000 series and up,
221 * but will not damage 4965
222 */
223 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
224
221 /* Apply the new configuration 225 /* Apply the new configuration
222 * RXON assoc doesn't clear the station table in uCode, 226 * RXON assoc doesn't clear the station table in uCode,
223 */ 227 */
@@ -3106,8 +3110,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3106 out_pci_disable_device: 3110 out_pci_disable_device:
3107 pci_disable_device(pdev); 3111 pci_disable_device(pdev);
3108 out_ieee80211_free_hw: 3112 out_ieee80211_free_hw:
3109 ieee80211_free_hw(priv->hw);
3110 iwl_free_traffic_mem(priv); 3113 iwl_free_traffic_mem(priv);
3114 ieee80211_free_hw(priv->hw);
3111 out: 3115 out:
3112 return err; 3116 return err;
3113} 3117}
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index 2c5c88fc38f5..4afaf773aeac 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -1154,7 +1154,7 @@ struct iwl_wep_cmd {
1154#define RX_RES_PHY_FLAGS_MOD_CCK_MSK cpu_to_le16(1 << 1) 1154#define RX_RES_PHY_FLAGS_MOD_CCK_MSK cpu_to_le16(1 << 1)
1155#define RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK cpu_to_le16(1 << 2) 1155#define RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK cpu_to_le16(1 << 2)
1156#define RX_RES_PHY_FLAGS_NARROW_BAND_MSK cpu_to_le16(1 << 3) 1156#define RX_RES_PHY_FLAGS_NARROW_BAND_MSK cpu_to_le16(1 << 3)
1157#define RX_RES_PHY_FLAGS_ANTENNA_MSK cpu_to_le16(0xf0) 1157#define RX_RES_PHY_FLAGS_ANTENNA_MSK 0xf0
1158#define RX_RES_PHY_FLAGS_ANTENNA_POS 4 1158#define RX_RES_PHY_FLAGS_ANTENNA_POS 4
1159 1159
1160#define RX_RES_STATUS_SEC_TYPE_MSK (0x7 << 8) 1160#define RX_RES_STATUS_SEC_TYPE_MSK (0x7 << 8)
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index e50103a956b1..7754538c2194 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -213,6 +213,7 @@ struct iwl_mod_params {
213 * @pa_type: used by 6000 series only to identify the type of Power Amplifier 213 * @pa_type: used by 6000 series only to identify the type of Power Amplifier
214 * @max_ll_items: max number of OTP blocks 214 * @max_ll_items: max number of OTP blocks
215 * @shadow_ram_support: shadow support for OTP memory 215 * @shadow_ram_support: shadow support for OTP memory
216 * @use_rts_for_ht: use rts/cts protection for HT traffic
216 * 217 *
217 * We enable the driver to be backward compatible wrt API version. The 218 * We enable the driver to be backward compatible wrt API version. The
218 * driver specifies which APIs it supports (with @ucode_api_max being the 219 * driver specifies which APIs it supports (with @ucode_api_max being the
@@ -255,6 +256,7 @@ struct iwl_cfg {
255 const bool shadow_ram_support; 256 const bool shadow_ram_support;
256 const bool ht_greenfield_support; 257 const bool ht_greenfield_support;
257 const bool broken_powersave; 258 const bool broken_powersave;
259 bool use_rts_for_ht;
258}; 260};
259 261
260/*************************** 262/***************************
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.c b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
index 3d2b93a61e62..e14c9952a935 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.c
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
@@ -410,7 +410,6 @@ static int iwl_find_otp_image(struct iwl_priv *priv,
410 u16 *validblockaddr) 410 u16 *validblockaddr)
411{ 411{
412 u16 next_link_addr = 0, link_value = 0, valid_addr; 412 u16 next_link_addr = 0, link_value = 0, valid_addr;
413 int ret = 0;
414 int usedblocks = 0; 413 int usedblocks = 0;
415 414
416 /* set addressing mode to absolute to traverse the link list */ 415 /* set addressing mode to absolute to traverse the link list */
@@ -430,29 +429,29 @@ static int iwl_find_otp_image(struct iwl_priv *priv,
430 * check for more block on the link list 429 * check for more block on the link list
431 */ 430 */
432 valid_addr = next_link_addr; 431 valid_addr = next_link_addr;
433 next_link_addr = link_value; 432 next_link_addr = link_value * sizeof(u16);
434 IWL_DEBUG_INFO(priv, "OTP blocks %d addr 0x%x\n", 433 IWL_DEBUG_INFO(priv, "OTP blocks %d addr 0x%x\n",
435 usedblocks, next_link_addr); 434 usedblocks, next_link_addr);
436 if (iwl_read_otp_word(priv, next_link_addr, &link_value)) 435 if (iwl_read_otp_word(priv, next_link_addr, &link_value))
437 return -EINVAL; 436 return -EINVAL;
438 if (!link_value) { 437 if (!link_value) {
439 /* 438 /*
440 * reach the end of link list, 439 * reach the end of link list, return success and
441 * set address point to the starting address 440 * set address point to the starting address
442 * of the image 441 * of the image
443 */ 442 */
444 goto done; 443 *validblockaddr = valid_addr;
444 /* skip first 2 bytes (link list pointer) */
445 *validblockaddr += 2;
446 return 0;
445 } 447 }
446 /* more in the link list, continue */ 448 /* more in the link list, continue */
447 usedblocks++; 449 usedblocks++;
448 } while (usedblocks < priv->cfg->max_ll_items); 450 } while (usedblocks <= priv->cfg->max_ll_items);
449 /* OTP full, use last block */ 451
450 IWL_DEBUG_INFO(priv, "OTP is full, use last block\n"); 452 /* OTP has no valid blocks */
451done: 453 IWL_DEBUG_INFO(priv, "OTP has no valid blocks\n");
452 *validblockaddr = valid_addr; 454 return -EINVAL;
453 /* skip first 2 bytes (link list pointer) */
454 *validblockaddr += 2;
455 return ret;
456} 455}
457 456
458/** 457/**
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.h b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
index 6b68db7b1b81..80b9e45d9b9c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.h
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
@@ -220,35 +220,35 @@ struct iwl_eeprom_enhanced_txpwr {
220 * Section 10: 2.4 GHz 40MHz channels: 132, 44 (_above_) 220 * Section 10: 2.4 GHz 40MHz channels: 132, 44 (_above_)
221 */ 221 */
222/* 2.4 GHz band: CCK */ 222/* 2.4 GHz band: CCK */
223#define EEPROM_LB_CCK_20_COMMON ((0xAA)\ 223#define EEPROM_LB_CCK_20_COMMON ((0xA8)\
224 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 8 bytes */ 224 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 8 bytes */
225/* 2.4 GHz band: 20MHz-Legacy, 20MHz-HT, 40MHz-HT */ 225/* 2.4 GHz band: 20MHz-Legacy, 20MHz-HT, 40MHz-HT */
226#define EEPROM_LB_OFDM_COMMON ((0xB2)\ 226#define EEPROM_LB_OFDM_COMMON ((0xB0)\
227 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 24 bytes */ 227 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 24 bytes */
228/* 5.2 GHz band: 20MHz-Legacy, 20MHz-HT, 40MHz-HT */ 228/* 5.2 GHz band: 20MHz-Legacy, 20MHz-HT, 40MHz-HT */
229#define EEPROM_HB_OFDM_COMMON ((0xCA)\ 229#define EEPROM_HB_OFDM_COMMON ((0xC8)\
230 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 24 bytes */ 230 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 24 bytes */
231/* 2.4GHz band channels: 231/* 2.4GHz band channels:
232 * 1Legacy, 1HT, 2Legacy, 2HT, 10Legacy, 10HT, 11Legacy, 11HT */ 232 * 1Legacy, 1HT, 2Legacy, 2HT, 10Legacy, 10HT, 11Legacy, 11HT */
233#define EEPROM_LB_OFDM_20_BAND ((0xE2)\ 233#define EEPROM_LB_OFDM_20_BAND ((0xE0)\
234 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 64 bytes */ 234 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 64 bytes */
235/* 2.4 GHz band HT40 channels: (1,+1) (2,+1) (6,+1) (7,+1) (9,+1) */ 235/* 2.4 GHz band HT40 channels: (1,+1) (2,+1) (6,+1) (7,+1) (9,+1) */
236#define EEPROM_LB_OFDM_HT40_BAND ((0x122)\ 236#define EEPROM_LB_OFDM_HT40_BAND ((0x120)\
237 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 40 bytes */ 237 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 40 bytes */
238/* 5.2GHz band channels: 36Legacy, 36HT, 64Legacy, 64HT, 100Legacy, 100HT */ 238/* 5.2GHz band channels: 36Legacy, 36HT, 64Legacy, 64HT, 100Legacy, 100HT */
239#define EEPROM_HB_OFDM_20_BAND ((0x14A)\ 239#define EEPROM_HB_OFDM_20_BAND ((0x148)\
240 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 48 bytes */ 240 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 48 bytes */
241/* 5.2 GHz band HT40 channels: (36,+1) (60,+1) (100,+1) */ 241/* 5.2 GHz band HT40 channels: (36,+1) (60,+1) (100,+1) */
242#define EEPROM_HB_OFDM_HT40_BAND ((0x17A)\ 242#define EEPROM_HB_OFDM_HT40_BAND ((0x178)\
243 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 24 bytes */ 243 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 24 bytes */
244/* 2.4 GHz band, channnel 13: Legacy, HT */ 244/* 2.4 GHz band, channnel 13: Legacy, HT */
245#define EEPROM_LB_OFDM_20_CHANNEL_13 ((0x192)\ 245#define EEPROM_LB_OFDM_20_CHANNEL_13 ((0x190)\
246 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 16 bytes */ 246 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 16 bytes */
247/* 5.2 GHz band, channnel 140: Legacy, HT */ 247/* 5.2 GHz band, channnel 140: Legacy, HT */
248#define EEPROM_HB_OFDM_20_CHANNEL_140 ((0x1A2)\ 248#define EEPROM_HB_OFDM_20_CHANNEL_140 ((0x1A0)\
249 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 16 bytes */ 249 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 16 bytes */
250/* 5.2 GHz band, HT40 channnels (132,+1) (44,+1) */ 250/* 5.2 GHz band, HT40 channnels (132,+1) (44,+1) */
251#define EEPROM_HB_OFDM_HT40_BAND_1 ((0x1B2)\ 251#define EEPROM_HB_OFDM_HT40_BAND_1 ((0x1B0)\
252 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 16 bytes */ 252 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 16 bytes */
253 253
254 254
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c
index 8e1bb53c0aa3..493626bcd3ec 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rx.c
@@ -1044,7 +1044,7 @@ void iwl_rx_reply_rx(struct iwl_priv *priv,
1044 * as a bitmask. 1044 * as a bitmask.
1045 */ 1045 */
1046 rx_status.antenna = 1046 rx_status.antenna =
1047 le16_to_cpu(phy_res->phy_flags & RX_RES_PHY_FLAGS_ANTENNA_MSK) 1047 (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
1048 >> RX_RES_PHY_FLAGS_ANTENNA_POS; 1048 >> RX_RES_PHY_FLAGS_ANTENNA_POS;
1049 1049
1050 /* set the preamble flag if appropriate */ 1050 /* set the preamble flag if appropriate */
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index fb9bcfa6d947..b7e196e3c8d3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -1277,8 +1277,16 @@ int iwl_tx_agg_stop(struct iwl_priv *priv , const u8 *ra, u16 tid)
1277 return -ENXIO; 1277 return -ENXIO;
1278 } 1278 }
1279 1279
1280 if (priv->stations[sta_id].tid[tid].agg.state ==
1281 IWL_EMPTYING_HW_QUEUE_ADDBA) {
1282 IWL_DEBUG_HT(priv, "AGG stop before setup done\n");
1283 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, ra, tid);
1284 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
1285 return 0;
1286 }
1287
1280 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON) 1288 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
1281 IWL_WARN(priv, "Stopping AGG while state not IWL_AGG_ON\n"); 1289 IWL_WARN(priv, "Stopping AGG while state not ON or starting\n");
1282 1290
1283 tid_data = &priv->stations[sta_id].tid[tid]; 1291 tid_data = &priv->stations[sta_id].tid[tid];
1284 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4; 1292 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index aa49230422f3..d00a80334095 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -4097,8 +4097,8 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4097 pci_set_drvdata(pdev, NULL); 4097 pci_set_drvdata(pdev, NULL);
4098 pci_disable_device(pdev); 4098 pci_disable_device(pdev);
4099 out_ieee80211_free_hw: 4099 out_ieee80211_free_hw:
4100 ieee80211_free_hw(priv->hw);
4101 iwl_free_traffic_mem(priv); 4100 iwl_free_traffic_mem(priv);
4101 ieee80211_free_hw(priv->hw);
4102 out: 4102 out:
4103 return err; 4103 return err;
4104} 4104}
diff --git a/drivers/net/wireless/libertas/cmdresp.c b/drivers/net/wireless/libertas/cmdresp.c
index c42d3faa2660..23f684337fdd 100644
--- a/drivers/net/wireless/libertas/cmdresp.c
+++ b/drivers/net/wireless/libertas/cmdresp.c
@@ -3,6 +3,7 @@
3 * responses as well as events generated by firmware. 3 * responses as well as events generated by firmware.
4 */ 4 */
5#include <linux/delay.h> 5#include <linux/delay.h>
6#include <linux/sched.h>
6#include <linux/if_arp.h> 7#include <linux/if_arp.h>
7#include <linux/netdevice.h> 8#include <linux/netdevice.h>
8#include <asm/unaligned.h> 9#include <asm/unaligned.h>
diff --git a/drivers/net/wireless/libertas/ethtool.c b/drivers/net/wireless/libertas/ethtool.c
index 039b555e4d76..53d56ab83c03 100644
--- a/drivers/net/wireless/libertas/ethtool.c
+++ b/drivers/net/wireless/libertas/ethtool.c
@@ -169,16 +169,19 @@ static int lbs_ethtool_set_wol(struct net_device *dev,
169 struct lbs_private *priv = dev->ml_priv; 169 struct lbs_private *priv = dev->ml_priv;
170 uint32_t criteria = 0; 170 uint32_t criteria = 0;
171 171
172 if (priv->wol_criteria == 0xffffffff && wol->wolopts)
173 return -EOPNOTSUPP;
174
175 if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY)) 172 if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
176 return -EOPNOTSUPP; 173 return -EOPNOTSUPP;
177 174
178 if (wol->wolopts & WAKE_UCAST) criteria |= EHS_WAKE_ON_UNICAST_DATA; 175 if (wol->wolopts & WAKE_UCAST)
179 if (wol->wolopts & WAKE_MCAST) criteria |= EHS_WAKE_ON_MULTICAST_DATA; 176 criteria |= EHS_WAKE_ON_UNICAST_DATA;
180 if (wol->wolopts & WAKE_BCAST) criteria |= EHS_WAKE_ON_BROADCAST_DATA; 177 if (wol->wolopts & WAKE_MCAST)
181 if (wol->wolopts & WAKE_PHY) criteria |= EHS_WAKE_ON_MAC_EVENT; 178 criteria |= EHS_WAKE_ON_MULTICAST_DATA;
179 if (wol->wolopts & WAKE_BCAST)
180 criteria |= EHS_WAKE_ON_BROADCAST_DATA;
181 if (wol->wolopts & WAKE_PHY)
182 criteria |= EHS_WAKE_ON_MAC_EVENT;
183 if (wol->wolopts == 0)
184 criteria |= EHS_REMOVE_WAKEUP;
182 185
183 return lbs_host_sleep_cfg(priv, criteria, (struct wol_config *)NULL); 186 return lbs_host_sleep_cfg(priv, criteria, (struct wol_config *)NULL);
184} 187}
diff --git a/drivers/net/wireless/libertas/if_cs.c b/drivers/net/wireless/libertas/if_cs.c
index 62381768f2d5..b1d84592b959 100644
--- a/drivers/net/wireless/libertas/if_cs.c
+++ b/drivers/net/wireless/libertas/if_cs.c
@@ -590,7 +590,7 @@ static int if_cs_prog_helper(struct if_cs_card *card)
590 590
591 /* TODO: make firmware file configurable */ 591 /* TODO: make firmware file configurable */
592 ret = request_firmware(&fw, "libertas_cs_helper.fw", 592 ret = request_firmware(&fw, "libertas_cs_helper.fw",
593 &handle_to_dev(card->p_dev)); 593 &card->p_dev->dev);
594 if (ret) { 594 if (ret) {
595 lbs_pr_err("can't load helper firmware\n"); 595 lbs_pr_err("can't load helper firmware\n");
596 ret = -ENODEV; 596 ret = -ENODEV;
@@ -663,7 +663,7 @@ static int if_cs_prog_real(struct if_cs_card *card)
663 663
664 /* TODO: make firmware file configurable */ 664 /* TODO: make firmware file configurable */
665 ret = request_firmware(&fw, "libertas_cs.fw", 665 ret = request_firmware(&fw, "libertas_cs.fw",
666 &handle_to_dev(card->p_dev)); 666 &card->p_dev->dev);
667 if (ret) { 667 if (ret) {
668 lbs_pr_err("can't load firmware\n"); 668 lbs_pr_err("can't load firmware\n");
669 ret = -ENODEV; 669 ret = -ENODEV;
@@ -793,18 +793,37 @@ static void if_cs_release(struct pcmcia_device *p_dev)
793 * configure the card at this point -- we wait until we receive a card 793 * configure the card at this point -- we wait until we receive a card
794 * insertion event. 794 * insertion event.
795 */ 795 */
796
797static int if_cs_ioprobe(struct pcmcia_device *p_dev,
798 cistpl_cftable_entry_t *cfg,
799 cistpl_cftable_entry_t *dflt,
800 unsigned int vcc,
801 void *priv_data)
802{
803 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
804 p_dev->io.BasePort1 = cfg->io.win[0].base;
805 p_dev->io.NumPorts1 = cfg->io.win[0].len;
806
807 /* Do we need to allocate an interrupt? */
808 if (cfg->irq.IRQInfo1)
809 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
810
811 /* IO window settings */
812 if (cfg->io.nwin != 1) {
813 lbs_pr_err("wrong CIS (check number of IO windows)\n");
814 return -ENODEV;
815 }
816
817 /* This reserves IO space but doesn't actually enable it */
818 return pcmcia_request_io(p_dev, &p_dev->io);
819}
820
796static int if_cs_probe(struct pcmcia_device *p_dev) 821static int if_cs_probe(struct pcmcia_device *p_dev)
797{ 822{
798 int ret = -ENOMEM; 823 int ret = -ENOMEM;
799 unsigned int prod_id; 824 unsigned int prod_id;
800 struct lbs_private *priv; 825 struct lbs_private *priv;
801 struct if_cs_card *card; 826 struct if_cs_card *card;
802 /* CIS parsing */
803 tuple_t tuple;
804 cisparse_t parse;
805 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
806 cistpl_io_t *io = &cfg->io;
807 u_char buf[64];
808 827
809 lbs_deb_enter(LBS_DEB_CS); 828 lbs_deb_enter(LBS_DEB_CS);
810 829
@@ -818,48 +837,15 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
818 837
819 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING; 838 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
820 p_dev->irq.Handler = NULL; 839 p_dev->irq.Handler = NULL;
821 p_dev->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
822 840
823 p_dev->conf.Attributes = 0; 841 p_dev->conf.Attributes = 0;
824 p_dev->conf.IntType = INT_MEMORY_AND_IO; 842 p_dev->conf.IntType = INT_MEMORY_AND_IO;
825 843
826 tuple.Attributes = 0; 844 if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) {
827 tuple.TupleData = buf; 845 lbs_pr_err("error in pcmcia_loop_config\n");
828 tuple.TupleDataMax = sizeof(buf);
829 tuple.TupleOffset = 0;
830
831 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
832 if ((ret = pcmcia_get_first_tuple(p_dev, &tuple)) != 0 ||
833 (ret = pcmcia_get_tuple_data(p_dev, &tuple)) != 0 ||
834 (ret = pcmcia_parse_tuple(&tuple, &parse)) != 0)
835 {
836 lbs_pr_err("error in pcmcia_get_first_tuple etc\n");
837 goto out1;
838 }
839
840 p_dev->conf.ConfigIndex = cfg->index;
841
842 /* Do we need to allocate an interrupt? */
843 if (cfg->irq.IRQInfo1) {
844 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
845 }
846
847 /* IO window settings */
848 if (cfg->io.nwin != 1) {
849 lbs_pr_err("wrong CIS (check number of IO windows)\n");
850 ret = -ENODEV;
851 goto out1; 846 goto out1;
852 } 847 }
853 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
854 p_dev->io.BasePort1 = io->win[0].base;
855 p_dev->io.NumPorts1 = io->win[0].len;
856 848
857 /* This reserves IO space but doesn't actually enable it */
858 ret = pcmcia_request_io(p_dev, &p_dev->io);
859 if (ret) {
860 lbs_pr_err("error in pcmcia_request_io\n");
861 goto out1;
862 }
863 849
864 /* 850 /*
865 * Allocate an interrupt line. Note that this does not assign 851 * Allocate an interrupt line. Note that this does not assign
diff --git a/drivers/net/wireless/libertas/if_spi.c b/drivers/net/wireless/libertas/if_spi.c
index cb8be8d7abc1..5b3672c4d0cc 100644
--- a/drivers/net/wireless/libertas/if_spi.c
+++ b/drivers/net/wireless/libertas/if_spi.c
@@ -134,7 +134,7 @@ static void spu_transaction_finish(struct if_spi_card *card)
134static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len) 134static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len)
135{ 135{
136 int err = 0; 136 int err = 0;
137 u16 reg_out = cpu_to_le16(reg | IF_SPI_WRITE_OPERATION_MASK); 137 __le16 reg_out = cpu_to_le16(reg | IF_SPI_WRITE_OPERATION_MASK);
138 struct spi_message m; 138 struct spi_message m;
139 struct spi_transfer reg_trans; 139 struct spi_transfer reg_trans;
140 struct spi_transfer data_trans; 140 struct spi_transfer data_trans;
@@ -166,7 +166,7 @@ static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len)
166 166
167static inline int spu_write_u16(struct if_spi_card *card, u16 reg, u16 val) 167static inline int spu_write_u16(struct if_spi_card *card, u16 reg, u16 val)
168{ 168{
169 u16 buff; 169 __le16 buff;
170 170
171 buff = cpu_to_le16(val); 171 buff = cpu_to_le16(val);
172 return spu_write(card, reg, (u8 *)&buff, sizeof(u16)); 172 return spu_write(card, reg, (u8 *)&buff, sizeof(u16));
@@ -188,7 +188,7 @@ static int spu_read(struct if_spi_card *card, u16 reg, u8 *buf, int len)
188{ 188{
189 unsigned int delay; 189 unsigned int delay;
190 int err = 0; 190 int err = 0;
191 u16 reg_out = cpu_to_le16(reg | IF_SPI_READ_OPERATION_MASK); 191 __le16 reg_out = cpu_to_le16(reg | IF_SPI_READ_OPERATION_MASK);
192 struct spi_message m; 192 struct spi_message m;
193 struct spi_transfer reg_trans; 193 struct spi_transfer reg_trans;
194 struct spi_transfer dummy_trans; 194 struct spi_transfer dummy_trans;
@@ -235,7 +235,7 @@ static int spu_read(struct if_spi_card *card, u16 reg, u8 *buf, int len)
235/* Read 16 bits from an SPI register */ 235/* Read 16 bits from an SPI register */
236static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val) 236static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val)
237{ 237{
238 u16 buf; 238 __le16 buf;
239 int ret; 239 int ret;
240 240
241 ret = spu_read(card, reg, (u8 *)&buf, sizeof(buf)); 241 ret = spu_read(card, reg, (u8 *)&buf, sizeof(buf));
@@ -248,7 +248,7 @@ static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val)
248 * The low 16 bits are read first. */ 248 * The low 16 bits are read first. */
249static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val) 249static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val)
250{ 250{
251 u32 buf; 251 __le32 buf;
252 int err; 252 int err;
253 253
254 err = spu_read(card, reg, (u8 *)&buf, sizeof(buf)); 254 err = spu_read(card, reg, (u8 *)&buf, sizeof(buf));
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 92bc8c5f1ca2..3fac4efa5ac8 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -508,7 +508,7 @@ static int __if_usb_submit_rx_urb(struct if_usb_card *cardp,
508 /* Fill the receive configuration URB and initialise the Rx call back */ 508 /* Fill the receive configuration URB and initialise the Rx call back */
509 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev, 509 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev,
510 usb_rcvbulkpipe(cardp->udev, cardp->ep_in), 510 usb_rcvbulkpipe(cardp->udev, cardp->ep_in),
511 (void *) (skb->tail + (size_t) IPFIELD_ALIGN_OFFSET), 511 skb->data + IPFIELD_ALIGN_OFFSET,
512 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn, 512 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn,
513 cardp); 513 cardp);
514 514
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index 9498b46c99a4..e61e6b9440ab 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -145,23 +145,6 @@ static const unsigned int txConfEUD = 0x10; /* Enable Uni-Data packets */
145static const unsigned int txConfKey = 0x02; /* Scramble data packets */ 145static const unsigned int txConfKey = 0x02; /* Scramble data packets */
146static const unsigned int txConfLoop = 0x01; /* Loopback mode */ 146static const unsigned int txConfLoop = 0x01; /* Loopback mode */
147 147
148/*
149 All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
150 you do not define PCMCIA_DEBUG at all, all the debug code will be
151 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
152 be present but disabled -- but it can then be enabled for specific
153 modules at load time with a 'pc_debug=#' option to insmod.
154*/
155
156#ifdef PCMCIA_DEBUG
157static int pc_debug = PCMCIA_DEBUG;
158module_param(pc_debug, int, 0);
159#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
160static char *version =
161"netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
162#else
163#define DEBUG(n, args...)
164#endif
165 148
166/*====================================================================*/ 149/*====================================================================*/
167 150
@@ -383,7 +366,7 @@ static int netwave_probe(struct pcmcia_device *link)
383 struct net_device *dev; 366 struct net_device *dev;
384 netwave_private *priv; 367 netwave_private *priv;
385 368
386 DEBUG(0, "netwave_attach()\n"); 369 dev_dbg(&link->dev, "netwave_attach()\n");
387 370
388 /* Initialize the struct pcmcia_device structure */ 371 /* Initialize the struct pcmcia_device structure */
389 dev = alloc_etherdev(sizeof(netwave_private)); 372 dev = alloc_etherdev(sizeof(netwave_private));
@@ -401,8 +384,7 @@ static int netwave_probe(struct pcmcia_device *link)
401 link->io.IOAddrLines = 5; 384 link->io.IOAddrLines = 5;
402 385
403 /* Interrupt setup */ 386 /* Interrupt setup */
404 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT; 387 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
405 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
406 link->irq.Handler = &netwave_interrupt; 388 link->irq.Handler = &netwave_interrupt;
407 389
408 /* General socket configuration */ 390 /* General socket configuration */
@@ -421,8 +403,6 @@ static int netwave_probe(struct pcmcia_device *link)
421 403
422 dev->watchdog_timeo = TX_TIMEOUT; 404 dev->watchdog_timeo = TX_TIMEOUT;
423 405
424 link->irq.Instance = dev;
425
426 return netwave_pcmcia_config( link); 406 return netwave_pcmcia_config( link);
427} /* netwave_attach */ 407} /* netwave_attach */
428 408
@@ -438,7 +418,7 @@ static void netwave_detach(struct pcmcia_device *link)
438{ 418{
439 struct net_device *dev = link->priv; 419 struct net_device *dev = link->priv;
440 420
441 DEBUG(0, "netwave_detach(0x%p)\n", link); 421 dev_dbg(&link->dev, "netwave_detach\n");
442 422
443 netwave_release(link); 423 netwave_release(link);
444 424
@@ -725,18 +705,15 @@ static const struct iw_handler_def netwave_handler_def =
725 * 705 *
726 */ 706 */
727 707
728#define CS_CHECK(fn, ret) \
729do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
730
731static int netwave_pcmcia_config(struct pcmcia_device *link) { 708static int netwave_pcmcia_config(struct pcmcia_device *link) {
732 struct net_device *dev = link->priv; 709 struct net_device *dev = link->priv;
733 netwave_private *priv = netdev_priv(dev); 710 netwave_private *priv = netdev_priv(dev);
734 int i, j, last_ret, last_fn; 711 int i, j, ret;
735 win_req_t req; 712 win_req_t req;
736 memreq_t mem; 713 memreq_t mem;
737 u_char __iomem *ramBase = NULL; 714 u_char __iomem *ramBase = NULL;
738 715
739 DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link); 716 dev_dbg(&link->dev, "netwave_pcmcia_config\n");
740 717
741 /* 718 /*
742 * Try allocating IO ports. This tries a few fixed addresses. 719 * Try allocating IO ports. This tries a few fixed addresses.
@@ -749,22 +726,24 @@ static int netwave_pcmcia_config(struct pcmcia_device *link) {
749 if (i == 0) 726 if (i == 0)
750 break; 727 break;
751 } 728 }
752 if (i != 0) { 729 if (i != 0)
753 cs_error(link, RequestIO, i);
754 goto failed; 730 goto failed;
755 }
756 731
757 /* 732 /*
758 * Now allocate an interrupt line. Note that this does not 733 * Now allocate an interrupt line. Note that this does not
759 * actually assign a handler to the interrupt. 734 * actually assign a handler to the interrupt.
760 */ 735 */
761 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 736 ret = pcmcia_request_irq(link, &link->irq);
737 if (ret)
738 goto failed;
762 739
763 /* 740 /*
764 * This actually configures the PCMCIA socket -- setting up 741 * This actually configures the PCMCIA socket -- setting up
765 * the I/O windows and the interrupt mapping. 742 * the I/O windows and the interrupt mapping.
766 */ 743 */
767 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 744 ret = pcmcia_request_configuration(link, &link->conf);
745 if (ret)
746 goto failed;
768 747
769 /* 748 /*
770 * Allocate a 32K memory window. Note that the struct pcmcia_device 749 * Allocate a 32K memory window. Note that the struct pcmcia_device
@@ -772,14 +751,18 @@ static int netwave_pcmcia_config(struct pcmcia_device *link) {
772 * device needs several windows, you'll need to keep track of 751 * device needs several windows, you'll need to keep track of
773 * the handles in your private data structure, dev->priv. 752 * the handles in your private data structure, dev->priv.
774 */ 753 */
775 DEBUG(1, "Setting mem speed of %d\n", mem_speed); 754 dev_dbg(&link->dev, "Setting mem speed of %d\n", mem_speed);
776 755
777 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE; 756 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
778 req.Base = 0; req.Size = 0x8000; 757 req.Base = 0; req.Size = 0x8000;
779 req.AccessSpeed = mem_speed; 758 req.AccessSpeed = mem_speed;
780 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win)); 759 ret = pcmcia_request_window(link, &req, &link->win);
760 if (ret)
761 goto failed;
781 mem.CardOffset = 0x20000; mem.Page = 0; 762 mem.CardOffset = 0x20000; mem.Page = 0;
782 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem)); 763 ret = pcmcia_map_mem_page(link, link->win, &mem);
764 if (ret)
765 goto failed;
783 766
784 /* Store base address of the common window frame */ 767 /* Store base address of the common window frame */
785 ramBase = ioremap(req.Base, 0x8000); 768 ramBase = ioremap(req.Base, 0x8000);
@@ -787,7 +770,7 @@ static int netwave_pcmcia_config(struct pcmcia_device *link) {
787 770
788 dev->irq = link->irq.AssignedIRQ; 771 dev->irq = link->irq.AssignedIRQ;
789 dev->base_addr = link->io.BasePort1; 772 dev->base_addr = link->io.BasePort1;
790 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 773 SET_NETDEV_DEV(dev, &link->dev);
791 774
792 if (register_netdev(dev) != 0) { 775 if (register_netdev(dev) != 0) {
793 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n"); 776 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
@@ -818,8 +801,6 @@ static int netwave_pcmcia_config(struct pcmcia_device *link) {
818 get_uint16(ramBase + NETWAVE_EREG_ARW+2)); 801 get_uint16(ramBase + NETWAVE_EREG_ARW+2));
819 return 0; 802 return 0;
820 803
821cs_failed:
822 cs_error(link, last_fn, last_ret);
823failed: 804failed:
824 netwave_release(link); 805 netwave_release(link);
825 return -ENODEV; 806 return -ENODEV;
@@ -837,7 +818,7 @@ static void netwave_release(struct pcmcia_device *link)
837 struct net_device *dev = link->priv; 818 struct net_device *dev = link->priv;
838 netwave_private *priv = netdev_priv(dev); 819 netwave_private *priv = netdev_priv(dev);
839 820
840 DEBUG(0, "netwave_release(0x%p)\n", link); 821 dev_dbg(&link->dev, "netwave_release\n");
841 822
842 pcmcia_disable_device(link); 823 pcmcia_disable_device(link);
843 if (link->win) 824 if (link->win)
@@ -892,7 +873,7 @@ static void netwave_reset(struct net_device *dev) {
892 u_char __iomem *ramBase = priv->ramBase; 873 u_char __iomem *ramBase = priv->ramBase;
893 unsigned int iobase = dev->base_addr; 874 unsigned int iobase = dev->base_addr;
894 875
895 DEBUG(0, "netwave_reset: Done with hardware reset\n"); 876 pr_debug("netwave_reset: Done with hardware reset\n");
896 877
897 priv->timeoutCounter = 0; 878 priv->timeoutCounter = 0;
898 879
@@ -988,7 +969,7 @@ static int netwave_hw_xmit(unsigned char* data, int len,
988 969
989 dev->stats.tx_bytes += len; 970 dev->stats.tx_bytes += len;
990 971
991 DEBUG(3, "Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n", 972 pr_debug("Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
992 readb(ramBase + NETWAVE_EREG_SPCQ), 973 readb(ramBase + NETWAVE_EREG_SPCQ),
993 readb(ramBase + NETWAVE_EREG_SPU), 974 readb(ramBase + NETWAVE_EREG_SPU),
994 readb(ramBase + NETWAVE_EREG_LIF), 975 readb(ramBase + NETWAVE_EREG_LIF),
@@ -1000,7 +981,7 @@ static int netwave_hw_xmit(unsigned char* data, int len,
1000 MaxData = get_uint16(ramBase + NETWAVE_EREG_TDP+2); 981 MaxData = get_uint16(ramBase + NETWAVE_EREG_TDP+2);
1001 DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4); 982 DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4);
1002 983
1003 DEBUG(3, "TxFreeList %x, MaxData %x, DataOffset %x\n", 984 pr_debug("TxFreeList %x, MaxData %x, DataOffset %x\n",
1004 TxFreeList, MaxData, DataOffset); 985 TxFreeList, MaxData, DataOffset);
1005 986
1006 /* Copy packet to the adapter fragment buffers */ 987 /* Copy packet to the adapter fragment buffers */
@@ -1088,7 +1069,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id)
1088 status = inb(iobase + NETWAVE_REG_ASR); 1069 status = inb(iobase + NETWAVE_REG_ASR);
1089 1070
1090 if (!pcmcia_dev_present(link)) { 1071 if (!pcmcia_dev_present(link)) {
1091 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x " 1072 pr_debug("netwave_interrupt: Interrupt with status 0x%x "
1092 "from removed or suspended card!\n", status); 1073 "from removed or suspended card!\n", status);
1093 break; 1074 break;
1094 } 1075 }
@@ -1132,7 +1113,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id)
1132 int txStatus; 1113 int txStatus;
1133 1114
1134 txStatus = readb(ramBase + NETWAVE_EREG_TSER); 1115 txStatus = readb(ramBase + NETWAVE_EREG_TSER);
1135 DEBUG(3, "Transmit done. TSER = %x id %x\n", 1116 pr_debug("Transmit done. TSER = %x id %x\n",
1136 txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1)); 1117 txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1));
1137 1118
1138 if (txStatus & 0x20) { 1119 if (txStatus & 0x20) {
@@ -1156,7 +1137,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id)
1156 * TxGU and TxNOAP is set. (Those are the only ones 1137 * TxGU and TxNOAP is set. (Those are the only ones
1157 * to set TxErr). 1138 * to set TxErr).
1158 */ 1139 */
1159 DEBUG(3, "netwave_interrupt: TxDN with error status %x\n", 1140 pr_debug("netwave_interrupt: TxDN with error status %x\n",
1160 txStatus); 1141 txStatus);
1161 1142
1162 /* Clear out TxGU, TxNOAP, TxErr and TxTrys */ 1143 /* Clear out TxGU, TxNOAP, TxErr and TxTrys */
@@ -1164,7 +1145,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id)
1164 writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4); 1145 writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4);
1165 ++dev->stats.tx_errors; 1146 ++dev->stats.tx_errors;
1166 } 1147 }
1167 DEBUG(3, "New status is TSER %x ASR %x\n", 1148 pr_debug("New status is TSER %x ASR %x\n",
1168 readb(ramBase + NETWAVE_EREG_TSER), 1149 readb(ramBase + NETWAVE_EREG_TSER),
1169 inb(iobase + NETWAVE_REG_ASR)); 1150 inb(iobase + NETWAVE_REG_ASR));
1170 1151
@@ -1172,7 +1153,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id)
1172 } 1153 }
1173 /* TxBA, this would trigger on all error packets received */ 1154 /* TxBA, this would trigger on all error packets received */
1174 /* if (status & 0x01) { 1155 /* if (status & 0x01) {
1175 DEBUG(4, "Transmit buffers available, %x\n", status); 1156 pr_debug("Transmit buffers available, %x\n", status);
1176 } 1157 }
1177 */ 1158 */
1178 } 1159 }
@@ -1190,7 +1171,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id)
1190 */ 1171 */
1191static void netwave_watchdog(struct net_device *dev) { 1172static void netwave_watchdog(struct net_device *dev) {
1192 1173
1193 DEBUG(1, "%s: netwave_watchdog: watchdog timer expired\n", dev->name); 1174 pr_debug("%s: netwave_watchdog: watchdog timer expired\n", dev->name);
1194 netwave_reset(dev); 1175 netwave_reset(dev);
1195 dev->trans_start = jiffies; 1176 dev->trans_start = jiffies;
1196 netif_wake_queue(dev); 1177 netif_wake_queue(dev);
@@ -1211,7 +1192,7 @@ static int netwave_rx(struct net_device *dev)
1211 int i; 1192 int i;
1212 u_char *ptr; 1193 u_char *ptr;
1213 1194
1214 DEBUG(3, "xinw_rx: Receiving ... \n"); 1195 pr_debug("xinw_rx: Receiving ... \n");
1215 1196
1216 /* Receive max 10 packets for now. */ 1197 /* Receive max 10 packets for now. */
1217 for (i = 0; i < 10; i++) { 1198 for (i = 0; i < 10; i++) {
@@ -1237,7 +1218,7 @@ static int netwave_rx(struct net_device *dev)
1237 1218
1238 skb = dev_alloc_skb(rcvLen+5); 1219 skb = dev_alloc_skb(rcvLen+5);
1239 if (skb == NULL) { 1220 if (skb == NULL) {
1240 DEBUG(1, "netwave_rx: Could not allocate an sk_buff of " 1221 pr_debug("netwave_rx: Could not allocate an sk_buff of "
1241 "length %d\n", rcvLen); 1222 "length %d\n", rcvLen);
1242 ++dev->stats.rx_dropped; 1223 ++dev->stats.rx_dropped;
1243 /* Tell the adapter to skip the packet */ 1224 /* Tell the adapter to skip the packet */
@@ -1279,7 +1260,7 @@ static int netwave_rx(struct net_device *dev)
1279 wait_WOC(iobase); 1260 wait_WOC(iobase);
1280 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0); 1261 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1281 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1); 1262 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1282 DEBUG(3, "Packet reception ok\n"); 1263 pr_debug("Packet reception ok\n");
1283 } 1264 }
1284 return 0; 1265 return 0;
1285} 1266}
@@ -1288,7 +1269,7 @@ static int netwave_open(struct net_device *dev) {
1288 netwave_private *priv = netdev_priv(dev); 1269 netwave_private *priv = netdev_priv(dev);
1289 struct pcmcia_device *link = priv->p_dev; 1270 struct pcmcia_device *link = priv->p_dev;
1290 1271
1291 DEBUG(1, "netwave_open: starting.\n"); 1272 dev_dbg(&link->dev, "netwave_open: starting.\n");
1292 1273
1293 if (!pcmcia_dev_present(link)) 1274 if (!pcmcia_dev_present(link))
1294 return -ENODEV; 1275 return -ENODEV;
@@ -1305,7 +1286,7 @@ static int netwave_close(struct net_device *dev) {
1305 netwave_private *priv = netdev_priv(dev); 1286 netwave_private *priv = netdev_priv(dev);
1306 struct pcmcia_device *link = priv->p_dev; 1287 struct pcmcia_device *link = priv->p_dev;
1307 1288
1308 DEBUG(1, "netwave_close: finishing.\n"); 1289 dev_dbg(&link->dev, "netwave_close: finishing.\n");
1309 1290
1310 link->open--; 1291 link->open--;
1311 netif_stop_queue(dev); 1292 netif_stop_queue(dev);
@@ -1358,11 +1339,11 @@ static void set_multicast_list(struct net_device *dev)
1358 u_char rcvMode = 0; 1339 u_char rcvMode = 0;
1359 1340
1360#ifdef PCMCIA_DEBUG 1341#ifdef PCMCIA_DEBUG
1361 if (pc_debug > 2) { 1342 {
1362 static int old; 1343 xstatic int old;
1363 if (old != dev->mc_count) { 1344 if (old != dev->mc_count) {
1364 old = dev->mc_count; 1345 old = dev->mc_count;
1365 DEBUG(0, "%s: setting Rx mode to %d addresses.\n", 1346 pr_debug("%s: setting Rx mode to %d addresses.\n",
1366 dev->name, dev->mc_count); 1347 dev->name, dev->mc_count);
1367 } 1348 }
1368 } 1349 }
diff --git a/drivers/net/wireless/orinoco/orinoco_cs.c b/drivers/net/wireless/orinoco/orinoco_cs.c
index 38c1c9d2abb8..f27bb8367c98 100644
--- a/drivers/net/wireless/orinoco/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco/orinoco_cs.c
@@ -109,7 +109,7 @@ orinoco_cs_probe(struct pcmcia_device *link)
109 struct orinoco_private *priv; 109 struct orinoco_private *priv;
110 struct orinoco_pccard *card; 110 struct orinoco_pccard *card;
111 111
112 priv = alloc_orinocodev(sizeof(*card), &handle_to_dev(link), 112 priv = alloc_orinocodev(sizeof(*card), &link->dev,
113 orinoco_cs_hard_reset, NULL); 113 orinoco_cs_hard_reset, NULL);
114 if (!priv) 114 if (!priv)
115 return -ENOMEM; 115 return -ENOMEM;
@@ -120,10 +120,8 @@ orinoco_cs_probe(struct pcmcia_device *link)
120 link->priv = priv; 120 link->priv = priv;
121 121
122 /* Interrupt setup */ 122 /* Interrupt setup */
123 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT; 123 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
124 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
125 link->irq.Handler = orinoco_interrupt; 124 link->irq.Handler = orinoco_interrupt;
126 link->irq.Instance = priv;
127 125
128 /* General socket configuration defaults can go here. In this 126 /* General socket configuration defaults can go here. In this
129 * client, we assume very little, and rely on the CIS for 127 * client, we assume very little, and rely on the CIS for
@@ -160,12 +158,6 @@ static void orinoco_cs_detach(struct pcmcia_device *link)
160 * device available to the system. 158 * device available to the system.
161 */ 159 */
162 160
163#define CS_CHECK(fn, ret) do { \
164 last_fn = (fn); \
165 if ((last_ret = (ret)) != 0) \
166 goto cs_failed; \
167} while (0)
168
169static int orinoco_cs_config_check(struct pcmcia_device *p_dev, 161static int orinoco_cs_config_check(struct pcmcia_device *p_dev,
170 cistpl_cftable_entry_t *cfg, 162 cistpl_cftable_entry_t *cfg,
171 cistpl_cftable_entry_t *dflt, 163 cistpl_cftable_entry_t *dflt,
@@ -240,7 +232,7 @@ orinoco_cs_config(struct pcmcia_device *link)
240 struct orinoco_private *priv = link->priv; 232 struct orinoco_private *priv = link->priv;
241 struct orinoco_pccard *card = priv->card; 233 struct orinoco_pccard *card = priv->card;
242 hermes_t *hw = &priv->hw; 234 hermes_t *hw = &priv->hw;
243 int last_fn, last_ret; 235 int ret;
244 void __iomem *mem; 236 void __iomem *mem;
245 237
246 /* 238 /*
@@ -257,13 +249,12 @@ orinoco_cs_config(struct pcmcia_device *link)
257 * and most client drivers will only use the CIS to fill in 249 * and most client drivers will only use the CIS to fill in
258 * implementation-defined details. 250 * implementation-defined details.
259 */ 251 */
260 last_ret = pcmcia_loop_config(link, orinoco_cs_config_check, NULL); 252 ret = pcmcia_loop_config(link, orinoco_cs_config_check, NULL);
261 if (last_ret) { 253 if (ret) {
262 if (!ignore_cis_vcc) 254 if (!ignore_cis_vcc)
263 printk(KERN_ERR PFX "GetNextTuple(): No matching " 255 printk(KERN_ERR PFX "GetNextTuple(): No matching "
264 "CIS configuration. Maybe you need the " 256 "CIS configuration. Maybe you need the "
265 "ignore_cis_vcc=1 parameter.\n"); 257 "ignore_cis_vcc=1 parameter.\n");
266 cs_error(link, RequestIO, last_ret);
267 goto failed; 258 goto failed;
268 } 259 }
269 260
@@ -272,14 +263,16 @@ orinoco_cs_config(struct pcmcia_device *link)
272 * a handler to the interrupt, unless the 'Handler' member of 263 * a handler to the interrupt, unless the 'Handler' member of
273 * the irq structure is initialized. 264 * the irq structure is initialized.
274 */ 265 */
275 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 266 ret = pcmcia_request_irq(link, &link->irq);
267 if (ret)
268 goto failed;
276 269
277 /* We initialize the hermes structure before completing PCMCIA 270 /* We initialize the hermes structure before completing PCMCIA
278 * configuration just in case the interrupt handler gets 271 * configuration just in case the interrupt handler gets
279 * called. */ 272 * called. */
280 mem = ioport_map(link->io.BasePort1, link->io.NumPorts1); 273 mem = ioport_map(link->io.BasePort1, link->io.NumPorts1);
281 if (!mem) 274 if (!mem)
282 goto cs_failed; 275 goto failed;
283 276
284 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); 277 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
285 278
@@ -288,8 +281,9 @@ orinoco_cs_config(struct pcmcia_device *link)
288 * the I/O windows and the interrupt mapping, and putting the 281 * the I/O windows and the interrupt mapping, and putting the
289 * card and host interface into "Memory and IO" mode. 282 * card and host interface into "Memory and IO" mode.
290 */ 283 */
291 CS_CHECK(RequestConfiguration, 284 ret = pcmcia_request_configuration(link, &link->conf);
292 pcmcia_request_configuration(link, &link->conf)); 285 if (ret)
286 goto failed;
293 287
294 /* Ok, we have the configuration, prepare to register the netdev */ 288 /* Ok, we have the configuration, prepare to register the netdev */
295 card->node.major = card->node.minor = 0; 289 card->node.major = card->node.minor = 0;
@@ -315,9 +309,6 @@ orinoco_cs_config(struct pcmcia_device *link)
315 * net_device has been registered */ 309 * net_device has been registered */
316 return 0; 310 return 0;
317 311
318 cs_failed:
319 cs_error(link, last_fn, last_ret);
320
321 failed: 312 failed:
322 orinoco_cs_release(link); 313 orinoco_cs_release(link);
323 return -ENODEV; 314 return -ENODEV;
diff --git a/drivers/net/wireless/orinoco/spectrum_cs.c b/drivers/net/wireless/orinoco/spectrum_cs.c
index c361310b885d..59bda240fdc2 100644
--- a/drivers/net/wireless/orinoco/spectrum_cs.c
+++ b/drivers/net/wireless/orinoco/spectrum_cs.c
@@ -73,9 +73,6 @@ static void spectrum_cs_release(struct pcmcia_device *link);
73#define HCR_MEM16 0x10 /* memory width bit, should be preserved */ 73#define HCR_MEM16 0x10 /* memory width bit, should be preserved */
74 74
75 75
76#define CS_CHECK(fn, ret) \
77 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
78
79/* 76/*
80 * Reset the card using configuration registers COR and CCSR. 77 * Reset the card using configuration registers COR and CCSR.
81 * If IDLE is 1, stop the firmware, so that it can be safely rewritten. 78 * If IDLE is 1, stop the firmware, so that it can be safely rewritten.
@@ -83,7 +80,7 @@ static void spectrum_cs_release(struct pcmcia_device *link);
83static int 80static int
84spectrum_reset(struct pcmcia_device *link, int idle) 81spectrum_reset(struct pcmcia_device *link, int idle)
85{ 82{
86 int last_ret, last_fn; 83 int ret;
87 conf_reg_t reg; 84 conf_reg_t reg;
88 u_int save_cor; 85 u_int save_cor;
89 86
@@ -95,23 +92,26 @@ spectrum_reset(struct pcmcia_device *link, int idle)
95 reg.Function = 0; 92 reg.Function = 0;
96 reg.Action = CS_READ; 93 reg.Action = CS_READ;
97 reg.Offset = CISREG_COR; 94 reg.Offset = CISREG_COR;
98 CS_CHECK(AccessConfigurationRegister, 95 ret = pcmcia_access_configuration_register(link, &reg);
99 pcmcia_access_configuration_register(link, &reg)); 96 if (ret)
97 goto failed;
100 save_cor = reg.Value; 98 save_cor = reg.Value;
101 99
102 /* Soft-Reset card */ 100 /* Soft-Reset card */
103 reg.Action = CS_WRITE; 101 reg.Action = CS_WRITE;
104 reg.Offset = CISREG_COR; 102 reg.Offset = CISREG_COR;
105 reg.Value = (save_cor | COR_SOFT_RESET); 103 reg.Value = (save_cor | COR_SOFT_RESET);
106 CS_CHECK(AccessConfigurationRegister, 104 ret = pcmcia_access_configuration_register(link, &reg);
107 pcmcia_access_configuration_register(link, &reg)); 105 if (ret)
106 goto failed;
108 udelay(1000); 107 udelay(1000);
109 108
110 /* Read CCSR */ 109 /* Read CCSR */
111 reg.Action = CS_READ; 110 reg.Action = CS_READ;
112 reg.Offset = CISREG_CCSR; 111 reg.Offset = CISREG_CCSR;
113 CS_CHECK(AccessConfigurationRegister, 112 ret = pcmcia_access_configuration_register(link, &reg);
114 pcmcia_access_configuration_register(link, &reg)); 113 if (ret)
114 goto failed;
115 115
116 /* 116 /*
117 * Start or stop the firmware. Memory width bit should be 117 * Start or stop the firmware. Memory width bit should be
@@ -120,21 +120,22 @@ spectrum_reset(struct pcmcia_device *link, int idle)
120 reg.Action = CS_WRITE; 120 reg.Action = CS_WRITE;
121 reg.Offset = CISREG_CCSR; 121 reg.Offset = CISREG_CCSR;
122 reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16); 122 reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16);
123 CS_CHECK(AccessConfigurationRegister, 123 ret = pcmcia_access_configuration_register(link, &reg);
124 pcmcia_access_configuration_register(link, &reg)); 124 if (ret)
125 goto failed;
125 udelay(1000); 126 udelay(1000);
126 127
127 /* Restore original COR configuration index */ 128 /* Restore original COR configuration index */
128 reg.Action = CS_WRITE; 129 reg.Action = CS_WRITE;
129 reg.Offset = CISREG_COR; 130 reg.Offset = CISREG_COR;
130 reg.Value = (save_cor & ~COR_SOFT_RESET); 131 reg.Value = (save_cor & ~COR_SOFT_RESET);
131 CS_CHECK(AccessConfigurationRegister, 132 ret = pcmcia_access_configuration_register(link, &reg);
132 pcmcia_access_configuration_register(link, &reg)); 133 if (ret)
134 goto failed;
133 udelay(1000); 135 udelay(1000);
134 return 0; 136 return 0;
135 137
136cs_failed: 138failed:
137 cs_error(link, last_fn, last_ret);
138 return -ENODEV; 139 return -ENODEV;
139} 140}
140 141
@@ -181,7 +182,7 @@ spectrum_cs_probe(struct pcmcia_device *link)
181 struct orinoco_private *priv; 182 struct orinoco_private *priv;
182 struct orinoco_pccard *card; 183 struct orinoco_pccard *card;
183 184
184 priv = alloc_orinocodev(sizeof(*card), &handle_to_dev(link), 185 priv = alloc_orinocodev(sizeof(*card), &link->dev,
185 spectrum_cs_hard_reset, 186 spectrum_cs_hard_reset,
186 spectrum_cs_stop_firmware); 187 spectrum_cs_stop_firmware);
187 if (!priv) 188 if (!priv)
@@ -193,10 +194,8 @@ spectrum_cs_probe(struct pcmcia_device *link)
193 link->priv = priv; 194 link->priv = priv;
194 195
195 /* Interrupt setup */ 196 /* Interrupt setup */
196 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT; 197 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
197 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
198 link->irq.Handler = orinoco_interrupt; 198 link->irq.Handler = orinoco_interrupt;
199 link->irq.Instance = priv;
200 199
201 /* General socket configuration defaults can go here. In this 200 /* General socket configuration defaults can go here. In this
202 * client, we assume very little, and rely on the CIS for 201 * client, we assume very little, and rely on the CIS for
@@ -307,7 +306,7 @@ spectrum_cs_config(struct pcmcia_device *link)
307 struct orinoco_private *priv = link->priv; 306 struct orinoco_private *priv = link->priv;
308 struct orinoco_pccard *card = priv->card; 307 struct orinoco_pccard *card = priv->card;
309 hermes_t *hw = &priv->hw; 308 hermes_t *hw = &priv->hw;
310 int last_fn, last_ret; 309 int ret;
311 void __iomem *mem; 310 void __iomem *mem;
312 311
313 /* 312 /*
@@ -324,13 +323,12 @@ spectrum_cs_config(struct pcmcia_device *link)
324 * and most client drivers will only use the CIS to fill in 323 * and most client drivers will only use the CIS to fill in
325 * implementation-defined details. 324 * implementation-defined details.
326 */ 325 */
327 last_ret = pcmcia_loop_config(link, spectrum_cs_config_check, NULL); 326 ret = pcmcia_loop_config(link, spectrum_cs_config_check, NULL);
328 if (last_ret) { 327 if (ret) {
329 if (!ignore_cis_vcc) 328 if (!ignore_cis_vcc)
330 printk(KERN_ERR PFX "GetNextTuple(): No matching " 329 printk(KERN_ERR PFX "GetNextTuple(): No matching "
331 "CIS configuration. Maybe you need the " 330 "CIS configuration. Maybe you need the "
332 "ignore_cis_vcc=1 parameter.\n"); 331 "ignore_cis_vcc=1 parameter.\n");
333 cs_error(link, RequestIO, last_ret);
334 goto failed; 332 goto failed;
335 } 333 }
336 334
@@ -339,14 +337,16 @@ spectrum_cs_config(struct pcmcia_device *link)
339 * a handler to the interrupt, unless the 'Handler' member of 337 * a handler to the interrupt, unless the 'Handler' member of
340 * the irq structure is initialized. 338 * the irq structure is initialized.
341 */ 339 */
342 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 340 ret = pcmcia_request_irq(link, &link->irq);
341 if (ret)
342 goto failed;
343 343
344 /* We initialize the hermes structure before completing PCMCIA 344 /* We initialize the hermes structure before completing PCMCIA
345 * configuration just in case the interrupt handler gets 345 * configuration just in case the interrupt handler gets
346 * called. */ 346 * called. */
347 mem = ioport_map(link->io.BasePort1, link->io.NumPorts1); 347 mem = ioport_map(link->io.BasePort1, link->io.NumPorts1);
348 if (!mem) 348 if (!mem)
349 goto cs_failed; 349 goto failed;
350 350
351 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); 351 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
352 352
@@ -355,8 +355,9 @@ spectrum_cs_config(struct pcmcia_device *link)
355 * the I/O windows and the interrupt mapping, and putting the 355 * the I/O windows and the interrupt mapping, and putting the
356 * card and host interface into "Memory and IO" mode. 356 * card and host interface into "Memory and IO" mode.
357 */ 357 */
358 CS_CHECK(RequestConfiguration, 358 ret = pcmcia_request_configuration(link, &link->conf);
359 pcmcia_request_configuration(link, &link->conf)); 359 if (ret)
360 goto failed;
360 361
361 /* Ok, we have the configuration, prepare to register the netdev */ 362 /* Ok, we have the configuration, prepare to register the netdev */
362 card->node.major = card->node.minor = 0; 363 card->node.major = card->node.minor = 0;
@@ -386,9 +387,6 @@ spectrum_cs_config(struct pcmcia_device *link)
386 * net_device has been registered */ 387 * net_device has been registered */
387 return 0; 388 return 0;
388 389
389 cs_failed:
390 cs_error(link, last_fn, last_ret);
391
392 failed: 390 failed:
393 spectrum_cs_release(link); 391 spectrum_cs_release(link);
394 return -ENODEV; 392 return -ENODEV;
diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
index 17e199546eeb..92af9b96bb7a 100644
--- a/drivers/net/wireless/p54/p54usb.c
+++ b/drivers/net/wireless/p54/p54usb.c
@@ -426,12 +426,16 @@ static const char p54u_romboot_3887[] = "~~~~";
426static int p54u_firmware_reset_3887(struct ieee80211_hw *dev) 426static int p54u_firmware_reset_3887(struct ieee80211_hw *dev)
427{ 427{
428 struct p54u_priv *priv = dev->priv; 428 struct p54u_priv *priv = dev->priv;
429 u8 buf[4]; 429 u8 *buf;
430 int ret; 430 int ret;
431 431
432 memcpy(&buf, p54u_romboot_3887, sizeof(buf)); 432 buf = kmalloc(4, GFP_KERNEL);
433 if (!buf)
434 return -ENOMEM;
435 memcpy(buf, p54u_romboot_3887, 4);
433 ret = p54u_bulk_msg(priv, P54U_PIPE_DATA, 436 ret = p54u_bulk_msg(priv, P54U_PIPE_DATA,
434 buf, sizeof(buf)); 437 buf, 4);
438 kfree(buf);
435 if (ret) 439 if (ret)
436 dev_err(&priv->udev->dev, "(p54usb) unable to jump to " 440 dev_err(&priv->udev->dev, "(p54usb) unable to jump to "
437 "boot ROM (%d)!\n", ret); 441 "boot ROM (%d)!\n", ret);
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 88cd58eb3b9f..5b8e3e4cdd9f 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -71,25 +71,7 @@ typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
71#include "rayctl.h" 71#include "rayctl.h"
72#include "ray_cs.h" 72#include "ray_cs.h"
73 73
74/* All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
75 you do not define PCMCIA_DEBUG at all, all the debug code will be
76 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
77 be present but disabled -- but it can then be enabled for specific
78 modules at load time with a 'pc_debug=#' option to insmod.
79*/
80 74
81#ifdef RAYLINK_DEBUG
82#define PCMCIA_DEBUG RAYLINK_DEBUG
83#endif
84#ifdef PCMCIA_DEBUG
85static int ray_debug;
86static int pc_debug = PCMCIA_DEBUG;
87module_param(pc_debug, int, 0);
88/* #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args); */
89#define DEBUG(n, args...) if (pc_debug > (n)) printk(args);
90#else
91#define DEBUG(n, args...)
92#endif
93/** Prototypes based on PCMCIA skeleton driver *******************************/ 75/** Prototypes based on PCMCIA skeleton driver *******************************/
94static int ray_config(struct pcmcia_device *link); 76static int ray_config(struct pcmcia_device *link);
95static void ray_release(struct pcmcia_device *link); 77static void ray_release(struct pcmcia_device *link);
@@ -325,7 +307,7 @@ static int ray_probe(struct pcmcia_device *p_dev)
325 ray_dev_t *local; 307 ray_dev_t *local;
326 struct net_device *dev; 308 struct net_device *dev;
327 309
328 DEBUG(1, "ray_attach()\n"); 310 dev_dbg(&p_dev->dev, "ray_attach()\n");
329 311
330 /* Allocate space for private device-specific data */ 312 /* Allocate space for private device-specific data */
331 dev = alloc_etherdev(sizeof(ray_dev_t)); 313 dev = alloc_etherdev(sizeof(ray_dev_t));
@@ -341,8 +323,7 @@ static int ray_probe(struct pcmcia_device *p_dev)
341 p_dev->io.IOAddrLines = 5; 323 p_dev->io.IOAddrLines = 5;
342 324
343 /* Interrupt setup. For PCMCIA, driver takes what's given */ 325 /* Interrupt setup. For PCMCIA, driver takes what's given */
344 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT; 326 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
345 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
346 p_dev->irq.Handler = &ray_interrupt; 327 p_dev->irq.Handler = &ray_interrupt;
347 328
348 /* General socket configuration */ 329 /* General socket configuration */
@@ -351,13 +332,12 @@ static int ray_probe(struct pcmcia_device *p_dev)
351 p_dev->conf.ConfigIndex = 1; 332 p_dev->conf.ConfigIndex = 1;
352 333
353 p_dev->priv = dev; 334 p_dev->priv = dev;
354 p_dev->irq.Instance = dev;
355 335
356 local->finder = p_dev; 336 local->finder = p_dev;
357 local->card_status = CARD_INSERTED; 337 local->card_status = CARD_INSERTED;
358 local->authentication_state = UNAUTHENTICATED; 338 local->authentication_state = UNAUTHENTICATED;
359 local->num_multi = 0; 339 local->num_multi = 0;
360 DEBUG(2, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n", 340 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
361 p_dev, dev, local, &ray_interrupt); 341 p_dev, dev, local, &ray_interrupt);
362 342
363 /* Raylink entries in the device structure */ 343 /* Raylink entries in the device structure */
@@ -370,7 +350,7 @@ static int ray_probe(struct pcmcia_device *p_dev)
370#endif /* WIRELESS_SPY */ 350#endif /* WIRELESS_SPY */
371 351
372 352
373 DEBUG(2, "ray_cs ray_attach calling ether_setup.)\n"); 353 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
374 netif_stop_queue(dev); 354 netif_stop_queue(dev);
375 355
376 init_timer(&local->timer); 356 init_timer(&local->timer);
@@ -393,7 +373,7 @@ static void ray_detach(struct pcmcia_device *link)
393 struct net_device *dev; 373 struct net_device *dev;
394 ray_dev_t *local; 374 ray_dev_t *local;
395 375
396 DEBUG(1, "ray_detach(0x%p)\n", link); 376 dev_dbg(&link->dev, "ray_detach\n");
397 377
398 this_device = NULL; 378 this_device = NULL;
399 dev = link->priv; 379 dev = link->priv;
@@ -408,7 +388,7 @@ static void ray_detach(struct pcmcia_device *link)
408 unregister_netdev(dev); 388 unregister_netdev(dev);
409 free_netdev(dev); 389 free_netdev(dev);
410 } 390 }
411 DEBUG(2, "ray_cs ray_detach ending\n"); 391 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
412} /* ray_detach */ 392} /* ray_detach */
413 393
414/*============================================================================= 394/*=============================================================================
@@ -416,19 +396,17 @@ static void ray_detach(struct pcmcia_device *link)
416 is received, to configure the PCMCIA socket, and to make the 396 is received, to configure the PCMCIA socket, and to make the
417 ethernet device available to the system. 397 ethernet device available to the system.
418=============================================================================*/ 398=============================================================================*/
419#define CS_CHECK(fn, ret) \
420do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
421#define MAX_TUPLE_SIZE 128 399#define MAX_TUPLE_SIZE 128
422static int ray_config(struct pcmcia_device *link) 400static int ray_config(struct pcmcia_device *link)
423{ 401{
424 int last_fn = 0, last_ret = 0; 402 int ret = 0;
425 int i; 403 int i;
426 win_req_t req; 404 win_req_t req;
427 memreq_t mem; 405 memreq_t mem;
428 struct net_device *dev = (struct net_device *)link->priv; 406 struct net_device *dev = (struct net_device *)link->priv;
429 ray_dev_t *local = netdev_priv(dev); 407 ray_dev_t *local = netdev_priv(dev);
430 408
431 DEBUG(1, "ray_config(0x%p)\n", link); 409 dev_dbg(&link->dev, "ray_config\n");
432 410
433 /* Determine card type and firmware version */ 411 /* Determine card type and firmware version */
434 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n", 412 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
@@ -440,14 +418,17 @@ static int ray_config(struct pcmcia_device *link)
440 /* Now allocate an interrupt line. Note that this does not 418 /* Now allocate an interrupt line. Note that this does not
441 actually assign a handler to the interrupt. 419 actually assign a handler to the interrupt.
442 */ 420 */
443 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 421 ret = pcmcia_request_irq(link, &link->irq);
422 if (ret)
423 goto failed;
444 dev->irq = link->irq.AssignedIRQ; 424 dev->irq = link->irq.AssignedIRQ;
445 425
446 /* This actually configures the PCMCIA socket -- setting up 426 /* This actually configures the PCMCIA socket -- setting up
447 the I/O windows and the interrupt mapping. 427 the I/O windows and the interrupt mapping.
448 */ 428 */
449 CS_CHECK(RequestConfiguration, 429 ret = pcmcia_request_configuration(link, &link->conf);
450 pcmcia_request_configuration(link, &link->conf)); 430 if (ret)
431 goto failed;
451 432
452/*** Set up 32k window for shared memory (transmit and control) ************/ 433/*** Set up 32k window for shared memory (transmit and control) ************/
453 req.Attributes = 434 req.Attributes =
@@ -455,10 +436,14 @@ static int ray_config(struct pcmcia_device *link)
455 req.Base = 0; 436 req.Base = 0;
456 req.Size = 0x8000; 437 req.Size = 0x8000;
457 req.AccessSpeed = ray_mem_speed; 438 req.AccessSpeed = ray_mem_speed;
458 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win)); 439 ret = pcmcia_request_window(link, &req, &link->win);
440 if (ret)
441 goto failed;
459 mem.CardOffset = 0x0000; 442 mem.CardOffset = 0x0000;
460 mem.Page = 0; 443 mem.Page = 0;
461 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem)); 444 ret = pcmcia_map_mem_page(link, link->win, &mem);
445 if (ret)
446 goto failed;
462 local->sram = ioremap(req.Base, req.Size); 447 local->sram = ioremap(req.Base, req.Size);
463 448
464/*** Set up 16k window for shared memory (receive buffer) ***************/ 449/*** Set up 16k window for shared memory (receive buffer) ***************/
@@ -467,11 +452,14 @@ static int ray_config(struct pcmcia_device *link)
467 req.Base = 0; 452 req.Base = 0;
468 req.Size = 0x4000; 453 req.Size = 0x4000;
469 req.AccessSpeed = ray_mem_speed; 454 req.AccessSpeed = ray_mem_speed;
470 CS_CHECK(RequestWindow, 455 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
471 pcmcia_request_window(&link, &req, &local->rmem_handle)); 456 if (ret)
457 goto failed;
472 mem.CardOffset = 0x8000; 458 mem.CardOffset = 0x8000;
473 mem.Page = 0; 459 mem.Page = 0;
474 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->rmem_handle, &mem)); 460 ret = pcmcia_map_mem_page(link, local->rmem_handle, &mem);
461 if (ret)
462 goto failed;
475 local->rmem = ioremap(req.Base, req.Size); 463 local->rmem = ioremap(req.Base, req.Size);
476 464
477/*** Set up window for attribute memory ***********************************/ 465/*** Set up window for attribute memory ***********************************/
@@ -480,22 +468,25 @@ static int ray_config(struct pcmcia_device *link)
480 req.Base = 0; 468 req.Base = 0;
481 req.Size = 0x1000; 469 req.Size = 0x1000;
482 req.AccessSpeed = ray_mem_speed; 470 req.AccessSpeed = ray_mem_speed;
483 CS_CHECK(RequestWindow, 471 ret = pcmcia_request_window(link, &req, &local->amem_handle);
484 pcmcia_request_window(&link, &req, &local->amem_handle)); 472 if (ret)
473 goto failed;
485 mem.CardOffset = 0x0000; 474 mem.CardOffset = 0x0000;
486 mem.Page = 0; 475 mem.Page = 0;
487 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->amem_handle, &mem)); 476 ret = pcmcia_map_mem_page(link, local->amem_handle, &mem);
477 if (ret)
478 goto failed;
488 local->amem = ioremap(req.Base, req.Size); 479 local->amem = ioremap(req.Base, req.Size);
489 480
490 DEBUG(3, "ray_config sram=%p\n", local->sram); 481 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
491 DEBUG(3, "ray_config rmem=%p\n", local->rmem); 482 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
492 DEBUG(3, "ray_config amem=%p\n", local->amem); 483 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
493 if (ray_init(dev) < 0) { 484 if (ray_init(dev) < 0) {
494 ray_release(link); 485 ray_release(link);
495 return -ENODEV; 486 return -ENODEV;
496 } 487 }
497 488
498 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 489 SET_NETDEV_DEV(dev, &link->dev);
499 i = register_netdev(dev); 490 i = register_netdev(dev);
500 if (i != 0) { 491 if (i != 0) {
501 printk("ray_config register_netdev() failed\n"); 492 printk("ray_config register_netdev() failed\n");
@@ -511,9 +502,7 @@ static int ray_config(struct pcmcia_device *link)
511 502
512 return 0; 503 return 0;
513 504
514cs_failed: 505failed:
515 cs_error(link, last_fn, last_ret);
516
517 ray_release(link); 506 ray_release(link);
518 return -ENODEV; 507 return -ENODEV;
519} /* ray_config */ 508} /* ray_config */
@@ -543,9 +532,9 @@ static int ray_init(struct net_device *dev)
543 struct ccs __iomem *pccs; 532 struct ccs __iomem *pccs;
544 ray_dev_t *local = netdev_priv(dev); 533 ray_dev_t *local = netdev_priv(dev);
545 struct pcmcia_device *link = local->finder; 534 struct pcmcia_device *link = local->finder;
546 DEBUG(1, "ray_init(0x%p)\n", dev); 535 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
547 if (!(pcmcia_dev_present(link))) { 536 if (!(pcmcia_dev_present(link))) {
548 DEBUG(0, "ray_init - device not present\n"); 537 dev_dbg(&link->dev, "ray_init - device not present\n");
549 return -1; 538 return -1;
550 } 539 }
551 540
@@ -567,13 +556,13 @@ static int ray_init(struct net_device *dev)
567 local->fw_ver = local->startup_res.firmware_version[0]; 556 local->fw_ver = local->startup_res.firmware_version[0];
568 local->fw_bld = local->startup_res.firmware_version[1]; 557 local->fw_bld = local->startup_res.firmware_version[1];
569 local->fw_var = local->startup_res.firmware_version[2]; 558 local->fw_var = local->startup_res.firmware_version[2];
570 DEBUG(1, "ray_init firmware version %d.%d \n", local->fw_ver, 559 dev_dbg(&link->dev, "ray_init firmware version %d.%d \n", local->fw_ver,
571 local->fw_bld); 560 local->fw_bld);
572 561
573 local->tib_length = 0x20; 562 local->tib_length = 0x20;
574 if ((local->fw_ver == 5) && (local->fw_bld >= 30)) 563 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
575 local->tib_length = local->startup_res.tib_length; 564 local->tib_length = local->startup_res.tib_length;
576 DEBUG(2, "ray_init tib_length = 0x%02x\n", local->tib_length); 565 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
577 /* Initialize CCS's to buffer free state */ 566 /* Initialize CCS's to buffer free state */
578 pccs = ccs_base(local); 567 pccs = ccs_base(local);
579 for (i = 0; i < NUMBER_OF_CCS; i++) { 568 for (i = 0; i < NUMBER_OF_CCS; i++) {
@@ -592,7 +581,7 @@ static int ray_init(struct net_device *dev)
592 581
593 clear_interrupt(local); /* Clear any interrupt from the card */ 582 clear_interrupt(local); /* Clear any interrupt from the card */
594 local->card_status = CARD_AWAITING_PARAM; 583 local->card_status = CARD_AWAITING_PARAM;
595 DEBUG(2, "ray_init ending\n"); 584 dev_dbg(&link->dev, "ray_init ending\n");
596 return 0; 585 return 0;
597} /* ray_init */ 586} /* ray_init */
598 587
@@ -605,9 +594,9 @@ static int dl_startup_params(struct net_device *dev)
605 struct ccs __iomem *pccs; 594 struct ccs __iomem *pccs;
606 struct pcmcia_device *link = local->finder; 595 struct pcmcia_device *link = local->finder;
607 596
608 DEBUG(1, "dl_startup_params entered\n"); 597 dev_dbg(&link->dev, "dl_startup_params entered\n");
609 if (!(pcmcia_dev_present(link))) { 598 if (!(pcmcia_dev_present(link))) {
610 DEBUG(2, "ray_cs dl_startup_params - device not present\n"); 599 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
611 return -1; 600 return -1;
612 } 601 }
613 602
@@ -625,7 +614,7 @@ static int dl_startup_params(struct net_device *dev)
625 local->dl_param_ccs = ccsindex; 614 local->dl_param_ccs = ccsindex;
626 pccs = ccs_base(local) + ccsindex; 615 pccs = ccs_base(local) + ccsindex;
627 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd); 616 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
628 DEBUG(2, "dl_startup_params start ccsindex = %d\n", 617 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
629 local->dl_param_ccs); 618 local->dl_param_ccs);
630 /* Interrupt the firmware to process the command */ 619 /* Interrupt the firmware to process the command */
631 if (interrupt_ecf(local, ccsindex)) { 620 if (interrupt_ecf(local, ccsindex)) {
@@ -641,7 +630,7 @@ static int dl_startup_params(struct net_device *dev)
641 local->timer.data = (long)local; 630 local->timer.data = (long)local;
642 local->timer.function = &verify_dl_startup; 631 local->timer.function = &verify_dl_startup;
643 add_timer(&local->timer); 632 add_timer(&local->timer);
644 DEBUG(2, 633 dev_dbg(&link->dev,
645 "ray_cs dl_startup_params started timer for verify_dl_startup\n"); 634 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
646 return 0; 635 return 0;
647} /* dl_startup_params */ 636} /* dl_startup_params */
@@ -717,11 +706,11 @@ static void verify_dl_startup(u_long data)
717 struct pcmcia_device *link = local->finder; 706 struct pcmcia_device *link = local->finder;
718 707
719 if (!(pcmcia_dev_present(link))) { 708 if (!(pcmcia_dev_present(link))) {
720 DEBUG(2, "ray_cs verify_dl_startup - device not present\n"); 709 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
721 return; 710 return;
722 } 711 }
723#ifdef PCMCIA_DEBUG 712#if 0
724 if (pc_debug > 2) { 713 {
725 int i; 714 int i;
726 printk(KERN_DEBUG 715 printk(KERN_DEBUG
727 "verify_dl_startup parameters sent via ccs %d:\n", 716 "verify_dl_startup parameters sent via ccs %d:\n",
@@ -760,7 +749,7 @@ static void start_net(u_long data)
760 int ccsindex; 749 int ccsindex;
761 struct pcmcia_device *link = local->finder; 750 struct pcmcia_device *link = local->finder;
762 if (!(pcmcia_dev_present(link))) { 751 if (!(pcmcia_dev_present(link))) {
763 DEBUG(2, "ray_cs start_net - device not present\n"); 752 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
764 return; 753 return;
765 } 754 }
766 /* Fill in the CCS fields for the ECF */ 755 /* Fill in the CCS fields for the ECF */
@@ -771,7 +760,7 @@ static void start_net(u_long data)
771 writeb(0, &pccs->var.start_network.update_param); 760 writeb(0, &pccs->var.start_network.update_param);
772 /* Interrupt the firmware to process the command */ 761 /* Interrupt the firmware to process the command */
773 if (interrupt_ecf(local, ccsindex)) { 762 if (interrupt_ecf(local, ccsindex)) {
774 DEBUG(1, "ray start net failed - card not ready for intr\n"); 763 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
775 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 764 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
776 return; 765 return;
777 } 766 }
@@ -790,7 +779,7 @@ static void join_net(u_long data)
790 struct pcmcia_device *link = local->finder; 779 struct pcmcia_device *link = local->finder;
791 780
792 if (!(pcmcia_dev_present(link))) { 781 if (!(pcmcia_dev_present(link))) {
793 DEBUG(2, "ray_cs join_net - device not present\n"); 782 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
794 return; 783 return;
795 } 784 }
796 /* Fill in the CCS fields for the ECF */ 785 /* Fill in the CCS fields for the ECF */
@@ -802,7 +791,7 @@ static void join_net(u_long data)
802 writeb(0, &pccs->var.join_network.net_initiated); 791 writeb(0, &pccs->var.join_network.net_initiated);
803 /* Interrupt the firmware to process the command */ 792 /* Interrupt the firmware to process the command */
804 if (interrupt_ecf(local, ccsindex)) { 793 if (interrupt_ecf(local, ccsindex)) {
805 DEBUG(1, "ray join net failed - card not ready for intr\n"); 794 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
806 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 795 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
807 return; 796 return;
808 } 797 }
@@ -821,7 +810,7 @@ static void ray_release(struct pcmcia_device *link)
821 ray_dev_t *local = netdev_priv(dev); 810 ray_dev_t *local = netdev_priv(dev);
822 int i; 811 int i;
823 812
824 DEBUG(1, "ray_release(0x%p)\n", link); 813 dev_dbg(&link->dev, "ray_release\n");
825 814
826 del_timer(&local->timer); 815 del_timer(&local->timer);
827 816
@@ -829,15 +818,15 @@ static void ray_release(struct pcmcia_device *link)
829 iounmap(local->rmem); 818 iounmap(local->rmem);
830 iounmap(local->amem); 819 iounmap(local->amem);
831 /* Do bother checking to see if these succeed or not */ 820 /* Do bother checking to see if these succeed or not */
832 i = pcmcia_release_window(local->amem_handle); 821 i = pcmcia_release_window(link, local->amem_handle);
833 if (i != 0) 822 if (i != 0)
834 DEBUG(0, "ReleaseWindow(local->amem) ret = %x\n", i); 823 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i);
835 i = pcmcia_release_window(local->rmem_handle); 824 i = pcmcia_release_window(link, local->rmem_handle);
836 if (i != 0) 825 if (i != 0)
837 DEBUG(0, "ReleaseWindow(local->rmem) ret = %x\n", i); 826 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i);
838 pcmcia_disable_device(link); 827 pcmcia_disable_device(link);
839 828
840 DEBUG(2, "ray_release ending\n"); 829 dev_dbg(&link->dev, "ray_release ending\n");
841} 830}
842 831
843static int ray_suspend(struct pcmcia_device *link) 832static int ray_suspend(struct pcmcia_device *link)
@@ -871,9 +860,9 @@ static int ray_dev_init(struct net_device *dev)
871 ray_dev_t *local = netdev_priv(dev); 860 ray_dev_t *local = netdev_priv(dev);
872 struct pcmcia_device *link = local->finder; 861 struct pcmcia_device *link = local->finder;
873 862
874 DEBUG(1, "ray_dev_init(dev=%p)\n", dev); 863 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
875 if (!(pcmcia_dev_present(link))) { 864 if (!(pcmcia_dev_present(link))) {
876 DEBUG(2, "ray_dev_init - device not present\n"); 865 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
877 return -1; 866 return -1;
878 } 867 }
879#ifdef RAY_IMMEDIATE_INIT 868#ifdef RAY_IMMEDIATE_INIT
@@ -887,7 +876,7 @@ static int ray_dev_init(struct net_device *dev)
887 /* Postpone the card init so that we can still configure the card, 876 /* Postpone the card init so that we can still configure the card,
888 * for example using the Wireless Extensions. The init will happen 877 * for example using the Wireless Extensions. The init will happen
889 * in ray_open() - Jean II */ 878 * in ray_open() - Jean II */
890 DEBUG(1, 879 dev_dbg(&link->dev,
891 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n", 880 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
892 local->card_status); 881 local->card_status);
893#endif /* RAY_IMMEDIATE_INIT */ 882#endif /* RAY_IMMEDIATE_INIT */
@@ -896,7 +885,7 @@ static int ray_dev_init(struct net_device *dev)
896 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN); 885 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
897 memset(dev->broadcast, 0xff, ETH_ALEN); 886 memset(dev->broadcast, 0xff, ETH_ALEN);
898 887
899 DEBUG(2, "ray_dev_init ending\n"); 888 dev_dbg(&link->dev, "ray_dev_init ending\n");
900 return 0; 889 return 0;
901} 890}
902 891
@@ -906,9 +895,9 @@ static int ray_dev_config(struct net_device *dev, struct ifmap *map)
906 ray_dev_t *local = netdev_priv(dev); 895 ray_dev_t *local = netdev_priv(dev);
907 struct pcmcia_device *link = local->finder; 896 struct pcmcia_device *link = local->finder;
908 /* Dummy routine to satisfy device structure */ 897 /* Dummy routine to satisfy device structure */
909 DEBUG(1, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map); 898 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
910 if (!(pcmcia_dev_present(link))) { 899 if (!(pcmcia_dev_present(link))) {
911 DEBUG(2, "ray_dev_config - device not present\n"); 900 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
912 return -1; 901 return -1;
913 } 902 }
914 903
@@ -924,14 +913,14 @@ static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
924 short length = skb->len; 913 short length = skb->len;
925 914
926 if (!pcmcia_dev_present(link)) { 915 if (!pcmcia_dev_present(link)) {
927 DEBUG(2, "ray_dev_start_xmit - device not present\n"); 916 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
928 dev_kfree_skb(skb); 917 dev_kfree_skb(skb);
929 return NETDEV_TX_OK; 918 return NETDEV_TX_OK;
930 } 919 }
931 920
932 DEBUG(3, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev); 921 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
933 if (local->authentication_state == NEED_TO_AUTH) { 922 if (local->authentication_state == NEED_TO_AUTH) {
934 DEBUG(0, "ray_cs Sending authentication request.\n"); 923 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
935 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) { 924 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
936 local->authentication_state = AUTHENTICATED; 925 local->authentication_state = AUTHENTICATED;
937 netif_stop_queue(dev); 926 netif_stop_queue(dev);
@@ -971,7 +960,7 @@ static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
971 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */ 960 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
972 short int addr; /* Address of xmit buffer in card space */ 961 short int addr; /* Address of xmit buffer in card space */
973 962
974 DEBUG(3, "ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev); 963 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
975 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) { 964 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
976 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n", 965 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
977 len); 966 len);
@@ -979,9 +968,9 @@ static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
979 } 968 }
980 switch (ccsindex = get_free_tx_ccs(local)) { 969 switch (ccsindex = get_free_tx_ccs(local)) {
981 case ECCSBUSY: 970 case ECCSBUSY:
982 DEBUG(2, "ray_hw_xmit tx_ccs table busy\n"); 971 pr_debug("ray_hw_xmit tx_ccs table busy\n");
983 case ECCSFULL: 972 case ECCSFULL:
984 DEBUG(2, "ray_hw_xmit No free tx ccs\n"); 973 pr_debug("ray_hw_xmit No free tx ccs\n");
985 case ECARDGONE: 974 case ECARDGONE:
986 netif_stop_queue(dev); 975 netif_stop_queue(dev);
987 return XMIT_NO_CCS; 976 return XMIT_NO_CCS;
@@ -1018,12 +1007,12 @@ static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
1018 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode); 1007 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
1019 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate); 1008 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
1020 writeb(0, &pccs->var.tx_request.antenna); 1009 writeb(0, &pccs->var.tx_request.antenna);
1021 DEBUG(3, "ray_hw_xmit default_tx_rate = 0x%x\n", 1010 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
1022 local->net_default_tx_rate); 1011 local->net_default_tx_rate);
1023 1012
1024 /* Interrupt the firmware to process the command */ 1013 /* Interrupt the firmware to process the command */
1025 if (interrupt_ecf(local, ccsindex)) { 1014 if (interrupt_ecf(local, ccsindex)) {
1026 DEBUG(2, "ray_hw_xmit failed - ECF not ready for intr\n"); 1015 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
1027/* TBD very inefficient to copy packet to buffer, and then not 1016/* TBD very inefficient to copy packet to buffer, and then not
1028 send it, but the alternative is to queue the messages and that 1017 send it, but the alternative is to queue the messages and that
1029 won't be done for a while. Maybe set tbusy until a CCS is free? 1018 won't be done for a while. Maybe set tbusy until a CCS is free?
@@ -1040,7 +1029,7 @@ static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1040{ 1029{
1041 __be16 proto = ((struct ethhdr *)data)->h_proto; 1030 __be16 proto = ((struct ethhdr *)data)->h_proto;
1042 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */ 1031 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
1043 DEBUG(3, "ray_cs translate_frame DIX II\n"); 1032 pr_debug("ray_cs translate_frame DIX II\n");
1044 /* Copy LLC header to card buffer */ 1033 /* Copy LLC header to card buffer */
1045 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc)); 1034 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1046 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc), 1035 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
@@ -1056,9 +1045,9 @@ static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1056 len - ETH_HLEN); 1045 len - ETH_HLEN);
1057 return (int)sizeof(struct snaphdr_t) - ETH_HLEN; 1046 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1058 } else { /* already 802 type, and proto is length */ 1047 } else { /* already 802 type, and proto is length */
1059 DEBUG(3, "ray_cs translate_frame 802\n"); 1048 pr_debug("ray_cs translate_frame 802\n");
1060 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */ 1049 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
1061 DEBUG(3, "ray_cs translate_frame evil IPX\n"); 1050 pr_debug("ray_cs translate_frame evil IPX\n");
1062 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN); 1051 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1063 return 0 - ETH_HLEN; 1052 return 0 - ETH_HLEN;
1064 } 1053 }
@@ -1603,7 +1592,7 @@ static int ray_open(struct net_device *dev)
1603 struct pcmcia_device *link; 1592 struct pcmcia_device *link;
1604 link = local->finder; 1593 link = local->finder;
1605 1594
1606 DEBUG(1, "ray_open('%s')\n", dev->name); 1595 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
1607 1596
1608 if (link->open == 0) 1597 if (link->open == 0)
1609 local->num_multi = 0; 1598 local->num_multi = 0;
@@ -1613,7 +1602,7 @@ static int ray_open(struct net_device *dev)
1613 if (local->card_status == CARD_AWAITING_PARAM) { 1602 if (local->card_status == CARD_AWAITING_PARAM) {
1614 int i; 1603 int i;
1615 1604
1616 DEBUG(1, "ray_open: doing init now !\n"); 1605 dev_dbg(&link->dev, "ray_open: doing init now !\n");
1617 1606
1618 /* Download startup parameters */ 1607 /* Download startup parameters */
1619 if ((i = dl_startup_params(dev)) < 0) { 1608 if ((i = dl_startup_params(dev)) < 0) {
@@ -1629,7 +1618,7 @@ static int ray_open(struct net_device *dev)
1629 else 1618 else
1630 netif_start_queue(dev); 1619 netif_start_queue(dev);
1631 1620
1632 DEBUG(2, "ray_open ending\n"); 1621 dev_dbg(&link->dev, "ray_open ending\n");
1633 return 0; 1622 return 0;
1634} /* end ray_open */ 1623} /* end ray_open */
1635 1624
@@ -1640,7 +1629,7 @@ static int ray_dev_close(struct net_device *dev)
1640 struct pcmcia_device *link; 1629 struct pcmcia_device *link;
1641 link = local->finder; 1630 link = local->finder;
1642 1631
1643 DEBUG(1, "ray_dev_close('%s')\n", dev->name); 1632 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
1644 1633
1645 link->open--; 1634 link->open--;
1646 netif_stop_queue(dev); 1635 netif_stop_queue(dev);
@@ -1656,7 +1645,7 @@ static int ray_dev_close(struct net_device *dev)
1656/*===========================================================================*/ 1645/*===========================================================================*/
1657static void ray_reset(struct net_device *dev) 1646static void ray_reset(struct net_device *dev)
1658{ 1647{
1659 DEBUG(1, "ray_reset entered\n"); 1648 pr_debug("ray_reset entered\n");
1660 return; 1649 return;
1661} 1650}
1662 1651
@@ -1669,17 +1658,17 @@ static int interrupt_ecf(ray_dev_t *local, int ccs)
1669 struct pcmcia_device *link = local->finder; 1658 struct pcmcia_device *link = local->finder;
1670 1659
1671 if (!(pcmcia_dev_present(link))) { 1660 if (!(pcmcia_dev_present(link))) {
1672 DEBUG(2, "ray_cs interrupt_ecf - device not present\n"); 1661 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
1673 return -1; 1662 return -1;
1674 } 1663 }
1675 DEBUG(2, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs); 1664 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
1676 1665
1677 while (i && 1666 while (i &&
1678 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) & 1667 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1679 ECF_INTR_SET)) 1668 ECF_INTR_SET))
1680 i--; 1669 i--;
1681 if (i == 0) { 1670 if (i == 0) {
1682 DEBUG(2, "ray_cs interrupt_ecf card not ready for interrupt\n"); 1671 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
1683 return -1; 1672 return -1;
1684 } 1673 }
1685 /* Fill the mailbox, then kick the card */ 1674 /* Fill the mailbox, then kick the card */
@@ -1698,12 +1687,12 @@ static int get_free_tx_ccs(ray_dev_t *local)
1698 struct pcmcia_device *link = local->finder; 1687 struct pcmcia_device *link = local->finder;
1699 1688
1700 if (!(pcmcia_dev_present(link))) { 1689 if (!(pcmcia_dev_present(link))) {
1701 DEBUG(2, "ray_cs get_free_tx_ccs - device not present\n"); 1690 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
1702 return ECARDGONE; 1691 return ECARDGONE;
1703 } 1692 }
1704 1693
1705 if (test_and_set_bit(0, &local->tx_ccs_lock)) { 1694 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
1706 DEBUG(1, "ray_cs tx_ccs_lock busy\n"); 1695 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
1707 return ECCSBUSY; 1696 return ECCSBUSY;
1708 } 1697 }
1709 1698
@@ -1716,7 +1705,7 @@ static int get_free_tx_ccs(ray_dev_t *local)
1716 } 1705 }
1717 } 1706 }
1718 local->tx_ccs_lock = 0; 1707 local->tx_ccs_lock = 0;
1719 DEBUG(2, "ray_cs ERROR no free tx CCS for raylink card\n"); 1708 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
1720 return ECCSFULL; 1709 return ECCSFULL;
1721} /* get_free_tx_ccs */ 1710} /* get_free_tx_ccs */
1722 1711
@@ -1730,11 +1719,11 @@ static int get_free_ccs(ray_dev_t *local)
1730 struct pcmcia_device *link = local->finder; 1719 struct pcmcia_device *link = local->finder;
1731 1720
1732 if (!(pcmcia_dev_present(link))) { 1721 if (!(pcmcia_dev_present(link))) {
1733 DEBUG(2, "ray_cs get_free_ccs - device not present\n"); 1722 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
1734 return ECARDGONE; 1723 return ECARDGONE;
1735 } 1724 }
1736 if (test_and_set_bit(0, &local->ccs_lock)) { 1725 if (test_and_set_bit(0, &local->ccs_lock)) {
1737 DEBUG(1, "ray_cs ccs_lock busy\n"); 1726 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
1738 return ECCSBUSY; 1727 return ECCSBUSY;
1739 } 1728 }
1740 1729
@@ -1747,7 +1736,7 @@ static int get_free_ccs(ray_dev_t *local)
1747 } 1736 }
1748 } 1737 }
1749 local->ccs_lock = 0; 1738 local->ccs_lock = 0;
1750 DEBUG(1, "ray_cs ERROR no free CCS for raylink card\n"); 1739 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
1751 return ECCSFULL; 1740 return ECCSFULL;
1752} /* get_free_ccs */ 1741} /* get_free_ccs */
1753 1742
@@ -1823,7 +1812,7 @@ static struct net_device_stats *ray_get_stats(struct net_device *dev)
1823 struct pcmcia_device *link = local->finder; 1812 struct pcmcia_device *link = local->finder;
1824 struct status __iomem *p = local->sram + STATUS_BASE; 1813 struct status __iomem *p = local->sram + STATUS_BASE;
1825 if (!(pcmcia_dev_present(link))) { 1814 if (!(pcmcia_dev_present(link))) {
1826 DEBUG(2, "ray_cs net_device_stats - device not present\n"); 1815 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
1827 return &local->stats; 1816 return &local->stats;
1828 } 1817 }
1829 if (readb(&p->mrx_overflow_for_host)) { 1818 if (readb(&p->mrx_overflow_for_host)) {
@@ -1856,12 +1845,12 @@ static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1856 struct ccs __iomem *pccs; 1845 struct ccs __iomem *pccs;
1857 1846
1858 if (!(pcmcia_dev_present(link))) { 1847 if (!(pcmcia_dev_present(link))) {
1859 DEBUG(2, "ray_update_parm - device not present\n"); 1848 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
1860 return; 1849 return;
1861 } 1850 }
1862 1851
1863 if ((ccsindex = get_free_ccs(local)) < 0) { 1852 if ((ccsindex = get_free_ccs(local)) < 0) {
1864 DEBUG(0, "ray_update_parm - No free ccs\n"); 1853 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
1865 return; 1854 return;
1866 } 1855 }
1867 pccs = ccs_base(local) + ccsindex; 1856 pccs = ccs_base(local) + ccsindex;
@@ -1874,7 +1863,7 @@ static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1874 } 1863 }
1875 /* Interrupt the firmware to process the command */ 1864 /* Interrupt the firmware to process the command */
1876 if (interrupt_ecf(local, ccsindex)) { 1865 if (interrupt_ecf(local, ccsindex)) {
1877 DEBUG(0, "ray_cs associate failed - ECF not ready for intr\n"); 1866 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
1878 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 1867 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1879 } 1868 }
1880} 1869}
@@ -1891,12 +1880,12 @@ static void ray_update_multi_list(struct net_device *dev, int all)
1891 void __iomem *p = local->sram + HOST_TO_ECF_BASE; 1880 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
1892 1881
1893 if (!(pcmcia_dev_present(link))) { 1882 if (!(pcmcia_dev_present(link))) {
1894 DEBUG(2, "ray_update_multi_list - device not present\n"); 1883 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
1895 return; 1884 return;
1896 } else 1885 } else
1897 DEBUG(2, "ray_update_multi_list(%p)\n", dev); 1886 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
1898 if ((ccsindex = get_free_ccs(local)) < 0) { 1887 if ((ccsindex = get_free_ccs(local)) < 0) {
1899 DEBUG(1, "ray_update_multi - No free ccs\n"); 1888 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
1900 return; 1889 return;
1901 } 1890 }
1902 pccs = ccs_base(local) + ccsindex; 1891 pccs = ccs_base(local) + ccsindex;
@@ -1910,7 +1899,7 @@ static void ray_update_multi_list(struct net_device *dev, int all)
1910 for (dmip = &dev->mc_list; (dmi = *dmip) != NULL; 1899 for (dmip = &dev->mc_list; (dmi = *dmip) != NULL;
1911 dmip = &dmi->next) { 1900 dmip = &dmi->next) {
1912 memcpy_toio(p, dmi->dmi_addr, ETH_ALEN); 1901 memcpy_toio(p, dmi->dmi_addr, ETH_ALEN);
1913 DEBUG(1, 1902 dev_dbg(&link->dev,
1914 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n", 1903 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
1915 dmi->dmi_addr[0], dmi->dmi_addr[1], 1904 dmi->dmi_addr[0], dmi->dmi_addr[1],
1916 dmi->dmi_addr[2], dmi->dmi_addr[3], 1905 dmi->dmi_addr[2], dmi->dmi_addr[3],
@@ -1921,12 +1910,12 @@ static void ray_update_multi_list(struct net_device *dev, int all)
1921 if (i > 256 / ADDRLEN) 1910 if (i > 256 / ADDRLEN)
1922 i = 256 / ADDRLEN; 1911 i = 256 / ADDRLEN;
1923 writeb((UCHAR) i, &pccs->var); 1912 writeb((UCHAR) i, &pccs->var);
1924 DEBUG(1, "ray_cs update_multi %d addresses in list\n", i); 1913 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
1925 /* Interrupt the firmware to process the command */ 1914 /* Interrupt the firmware to process the command */
1926 local->num_multi = i; 1915 local->num_multi = i;
1927 } 1916 }
1928 if (interrupt_ecf(local, ccsindex)) { 1917 if (interrupt_ecf(local, ccsindex)) {
1929 DEBUG(1, 1918 dev_dbg(&link->dev,
1930 "ray_cs update_multi failed - ECF not ready for intr\n"); 1919 "ray_cs update_multi failed - ECF not ready for intr\n");
1931 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 1920 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1932 } 1921 }
@@ -1938,11 +1927,11 @@ static void set_multicast_list(struct net_device *dev)
1938 ray_dev_t *local = netdev_priv(dev); 1927 ray_dev_t *local = netdev_priv(dev);
1939 UCHAR promisc; 1928 UCHAR promisc;
1940 1929
1941 DEBUG(2, "ray_cs set_multicast_list(%p)\n", dev); 1930 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
1942 1931
1943 if (dev->flags & IFF_PROMISC) { 1932 if (dev->flags & IFF_PROMISC) {
1944 if (local->sparm.b5.a_promiscuous_mode == 0) { 1933 if (local->sparm.b5.a_promiscuous_mode == 0) {
1945 DEBUG(1, "ray_cs set_multicast_list promisc on\n"); 1934 pr_debug("ray_cs set_multicast_list promisc on\n");
1946 local->sparm.b5.a_promiscuous_mode = 1; 1935 local->sparm.b5.a_promiscuous_mode = 1;
1947 promisc = 1; 1936 promisc = 1;
1948 ray_update_parm(dev, OBJID_promiscuous_mode, 1937 ray_update_parm(dev, OBJID_promiscuous_mode,
@@ -1950,7 +1939,7 @@ static void set_multicast_list(struct net_device *dev)
1950 } 1939 }
1951 } else { 1940 } else {
1952 if (local->sparm.b5.a_promiscuous_mode == 1) { 1941 if (local->sparm.b5.a_promiscuous_mode == 1) {
1953 DEBUG(1, "ray_cs set_multicast_list promisc off\n"); 1942 pr_debug("ray_cs set_multicast_list promisc off\n");
1954 local->sparm.b5.a_promiscuous_mode = 0; 1943 local->sparm.b5.a_promiscuous_mode = 0;
1955 promisc = 0; 1944 promisc = 0;
1956 ray_update_parm(dev, OBJID_promiscuous_mode, 1945 ray_update_parm(dev, OBJID_promiscuous_mode,
@@ -1984,19 +1973,19 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id)
1984 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */ 1973 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1985 return IRQ_NONE; 1974 return IRQ_NONE;
1986 1975
1987 DEBUG(4, "ray_cs: interrupt for *dev=%p\n", dev); 1976 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
1988 1977
1989 local = netdev_priv(dev); 1978 local = netdev_priv(dev);
1990 link = (struct pcmcia_device *)local->finder; 1979 link = (struct pcmcia_device *)local->finder;
1991 if (!pcmcia_dev_present(link)) { 1980 if (!pcmcia_dev_present(link)) {
1992 DEBUG(2, 1981 pr_debug(
1993 "ray_cs interrupt from device not present or suspended.\n"); 1982 "ray_cs interrupt from device not present or suspended.\n");
1994 return IRQ_NONE; 1983 return IRQ_NONE;
1995 } 1984 }
1996 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index); 1985 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
1997 1986
1998 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) { 1987 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
1999 DEBUG(1, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex); 1988 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
2000 clear_interrupt(local); 1989 clear_interrupt(local);
2001 return IRQ_HANDLED; 1990 return IRQ_HANDLED;
2002 } 1991 }
@@ -2008,33 +1997,33 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id)
2008 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */ 1997 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
2009 del_timer(&local->timer); 1998 del_timer(&local->timer);
2010 if (status == CCS_COMMAND_COMPLETE) { 1999 if (status == CCS_COMMAND_COMPLETE) {
2011 DEBUG(1, 2000 dev_dbg(&link->dev,
2012 "ray_cs interrupt download_startup_parameters OK\n"); 2001 "ray_cs interrupt download_startup_parameters OK\n");
2013 } else { 2002 } else {
2014 DEBUG(1, 2003 dev_dbg(&link->dev,
2015 "ray_cs interrupt download_startup_parameters fail\n"); 2004 "ray_cs interrupt download_startup_parameters fail\n");
2016 } 2005 }
2017 break; 2006 break;
2018 case CCS_UPDATE_PARAMS: 2007 case CCS_UPDATE_PARAMS:
2019 DEBUG(1, "ray_cs interrupt update params done\n"); 2008 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
2020 if (status != CCS_COMMAND_COMPLETE) { 2009 if (status != CCS_COMMAND_COMPLETE) {
2021 tmp = 2010 tmp =
2022 readb(&pccs->var.update_param. 2011 readb(&pccs->var.update_param.
2023 failure_cause); 2012 failure_cause);
2024 DEBUG(0, 2013 dev_dbg(&link->dev,
2025 "ray_cs interrupt update params failed - reason %d\n", 2014 "ray_cs interrupt update params failed - reason %d\n",
2026 tmp); 2015 tmp);
2027 } 2016 }
2028 break; 2017 break;
2029 case CCS_REPORT_PARAMS: 2018 case CCS_REPORT_PARAMS:
2030 DEBUG(1, "ray_cs interrupt report params done\n"); 2019 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
2031 break; 2020 break;
2032 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */ 2021 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
2033 DEBUG(1, 2022 dev_dbg(&link->dev,
2034 "ray_cs interrupt CCS Update Multicast List done\n"); 2023 "ray_cs interrupt CCS Update Multicast List done\n");
2035 break; 2024 break;
2036 case CCS_UPDATE_POWER_SAVINGS_MODE: 2025 case CCS_UPDATE_POWER_SAVINGS_MODE:
2037 DEBUG(1, 2026 dev_dbg(&link->dev,
2038 "ray_cs interrupt update power save mode done\n"); 2027 "ray_cs interrupt update power save mode done\n");
2039 break; 2028 break;
2040 case CCS_START_NETWORK: 2029 case CCS_START_NETWORK:
@@ -2043,11 +2032,11 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id)
2043 if (readb 2032 if (readb
2044 (&pccs->var.start_network.net_initiated) == 2033 (&pccs->var.start_network.net_initiated) ==
2045 1) { 2034 1) {
2046 DEBUG(0, 2035 dev_dbg(&link->dev,
2047 "ray_cs interrupt network \"%s\" started\n", 2036 "ray_cs interrupt network \"%s\" started\n",
2048 local->sparm.b4.a_current_ess_id); 2037 local->sparm.b4.a_current_ess_id);
2049 } else { 2038 } else {
2050 DEBUG(0, 2039 dev_dbg(&link->dev,
2051 "ray_cs interrupt network \"%s\" joined\n", 2040 "ray_cs interrupt network \"%s\" joined\n",
2052 local->sparm.b4.a_current_ess_id); 2041 local->sparm.b4.a_current_ess_id);
2053 } 2042 }
@@ -2075,12 +2064,12 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id)
2075 local->timer.expires = jiffies + HZ * 5; 2064 local->timer.expires = jiffies + HZ * 5;
2076 local->timer.data = (long)local; 2065 local->timer.data = (long)local;
2077 if (status == CCS_START_NETWORK) { 2066 if (status == CCS_START_NETWORK) {
2078 DEBUG(0, 2067 dev_dbg(&link->dev,
2079 "ray_cs interrupt network \"%s\" start failed\n", 2068 "ray_cs interrupt network \"%s\" start failed\n",
2080 local->sparm.b4.a_current_ess_id); 2069 local->sparm.b4.a_current_ess_id);
2081 local->timer.function = &start_net; 2070 local->timer.function = &start_net;
2082 } else { 2071 } else {
2083 DEBUG(0, 2072 dev_dbg(&link->dev,
2084 "ray_cs interrupt network \"%s\" join failed\n", 2073 "ray_cs interrupt network \"%s\" join failed\n",
2085 local->sparm.b4.a_current_ess_id); 2074 local->sparm.b4.a_current_ess_id);
2086 local->timer.function = &join_net; 2075 local->timer.function = &join_net;
@@ -2091,19 +2080,19 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id)
2091 case CCS_START_ASSOCIATION: 2080 case CCS_START_ASSOCIATION:
2092 if (status == CCS_COMMAND_COMPLETE) { 2081 if (status == CCS_COMMAND_COMPLETE) {
2093 local->card_status = CARD_ASSOC_COMPLETE; 2082 local->card_status = CARD_ASSOC_COMPLETE;
2094 DEBUG(0, "ray_cs association successful\n"); 2083 dev_dbg(&link->dev, "ray_cs association successful\n");
2095 } else { 2084 } else {
2096 DEBUG(0, "ray_cs association failed,\n"); 2085 dev_dbg(&link->dev, "ray_cs association failed,\n");
2097 local->card_status = CARD_ASSOC_FAILED; 2086 local->card_status = CARD_ASSOC_FAILED;
2098 join_net((u_long) local); 2087 join_net((u_long) local);
2099 } 2088 }
2100 break; 2089 break;
2101 case CCS_TX_REQUEST: 2090 case CCS_TX_REQUEST:
2102 if (status == CCS_COMMAND_COMPLETE) { 2091 if (status == CCS_COMMAND_COMPLETE) {
2103 DEBUG(3, 2092 dev_dbg(&link->dev,
2104 "ray_cs interrupt tx request complete\n"); 2093 "ray_cs interrupt tx request complete\n");
2105 } else { 2094 } else {
2106 DEBUG(1, 2095 dev_dbg(&link->dev,
2107 "ray_cs interrupt tx request failed\n"); 2096 "ray_cs interrupt tx request failed\n");
2108 } 2097 }
2109 if (!sniffer) 2098 if (!sniffer)
@@ -2111,21 +2100,21 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id)
2111 netif_wake_queue(dev); 2100 netif_wake_queue(dev);
2112 break; 2101 break;
2113 case CCS_TEST_MEMORY: 2102 case CCS_TEST_MEMORY:
2114 DEBUG(1, "ray_cs interrupt mem test done\n"); 2103 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
2115 break; 2104 break;
2116 case CCS_SHUTDOWN: 2105 case CCS_SHUTDOWN:
2117 DEBUG(1, 2106 dev_dbg(&link->dev,
2118 "ray_cs interrupt Unexpected CCS returned - Shutdown\n"); 2107 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2119 break; 2108 break;
2120 case CCS_DUMP_MEMORY: 2109 case CCS_DUMP_MEMORY:
2121 DEBUG(1, "ray_cs interrupt dump memory done\n"); 2110 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
2122 break; 2111 break;
2123 case CCS_START_TIMER: 2112 case CCS_START_TIMER:
2124 DEBUG(2, 2113 dev_dbg(&link->dev,
2125 "ray_cs interrupt DING - raylink timer expired\n"); 2114 "ray_cs interrupt DING - raylink timer expired\n");
2126 break; 2115 break;
2127 default: 2116 default:
2128 DEBUG(1, 2117 dev_dbg(&link->dev,
2129 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n", 2118 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2130 rcsindex, cmd); 2119 rcsindex, cmd);
2131 } 2120 }
@@ -2139,7 +2128,7 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id)
2139 ray_rx(dev, local, prcs); 2128 ray_rx(dev, local, prcs);
2140 break; 2129 break;
2141 case REJOIN_NET_COMPLETE: 2130 case REJOIN_NET_COMPLETE:
2142 DEBUG(1, "ray_cs interrupt rejoin net complete\n"); 2131 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
2143 local->card_status = CARD_ACQ_COMPLETE; 2132 local->card_status = CARD_ACQ_COMPLETE;
2144 /* do we need to clear tx buffers CCS's? */ 2133 /* do we need to clear tx buffers CCS's? */
2145 if (local->sparm.b4.a_network_type == ADHOC) { 2134 if (local->sparm.b4.a_network_type == ADHOC) {
@@ -2149,7 +2138,7 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id)
2149 memcpy_fromio(&local->bss_id, 2138 memcpy_fromio(&local->bss_id,
2150 prcs->var.rejoin_net_complete. 2139 prcs->var.rejoin_net_complete.
2151 bssid, ADDRLEN); 2140 bssid, ADDRLEN);
2152 DEBUG(1, 2141 dev_dbg(&link->dev,
2153 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n", 2142 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2154 local->bss_id[0], local->bss_id[1], 2143 local->bss_id[0], local->bss_id[1],
2155 local->bss_id[2], local->bss_id[3], 2144 local->bss_id[2], local->bss_id[3],
@@ -2159,15 +2148,15 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id)
2159 } 2148 }
2160 break; 2149 break;
2161 case ROAMING_INITIATED: 2150 case ROAMING_INITIATED:
2162 DEBUG(1, "ray_cs interrupt roaming initiated\n"); 2151 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
2163 netif_stop_queue(dev); 2152 netif_stop_queue(dev);
2164 local->card_status = CARD_DOING_ACQ; 2153 local->card_status = CARD_DOING_ACQ;
2165 break; 2154 break;
2166 case JAPAN_CALL_SIGN_RXD: 2155 case JAPAN_CALL_SIGN_RXD:
2167 DEBUG(1, "ray_cs interrupt japan call sign rx\n"); 2156 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
2168 break; 2157 break;
2169 default: 2158 default:
2170 DEBUG(1, 2159 dev_dbg(&link->dev,
2171 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n", 2160 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2172 rcsindex, 2161 rcsindex,
2173 (unsigned int)readb(&prcs->interrupt_id)); 2162 (unsigned int)readb(&prcs->interrupt_id));
@@ -2186,7 +2175,7 @@ static void ray_rx(struct net_device *dev, ray_dev_t *local,
2186 int rx_len; 2175 int rx_len;
2187 unsigned int pkt_addr; 2176 unsigned int pkt_addr;
2188 void __iomem *pmsg; 2177 void __iomem *pmsg;
2189 DEBUG(4, "ray_rx process rx packet\n"); 2178 pr_debug("ray_rx process rx packet\n");
2190 2179
2191 /* Calculate address of packet within Rx buffer */ 2180 /* Calculate address of packet within Rx buffer */
2192 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8) 2181 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
@@ -2199,28 +2188,28 @@ static void ray_rx(struct net_device *dev, ray_dev_t *local,
2199 pmsg = local->rmem + pkt_addr; 2188 pmsg = local->rmem + pkt_addr;
2200 switch (readb(pmsg)) { 2189 switch (readb(pmsg)) {
2201 case DATA_TYPE: 2190 case DATA_TYPE:
2202 DEBUG(4, "ray_rx data type\n"); 2191 pr_debug("ray_rx data type\n");
2203 rx_data(dev, prcs, pkt_addr, rx_len); 2192 rx_data(dev, prcs, pkt_addr, rx_len);
2204 break; 2193 break;
2205 case AUTHENTIC_TYPE: 2194 case AUTHENTIC_TYPE:
2206 DEBUG(4, "ray_rx authentic type\n"); 2195 pr_debug("ray_rx authentic type\n");
2207 if (sniffer) 2196 if (sniffer)
2208 rx_data(dev, prcs, pkt_addr, rx_len); 2197 rx_data(dev, prcs, pkt_addr, rx_len);
2209 else 2198 else
2210 rx_authenticate(local, prcs, pkt_addr, rx_len); 2199 rx_authenticate(local, prcs, pkt_addr, rx_len);
2211 break; 2200 break;
2212 case DEAUTHENTIC_TYPE: 2201 case DEAUTHENTIC_TYPE:
2213 DEBUG(4, "ray_rx deauth type\n"); 2202 pr_debug("ray_rx deauth type\n");
2214 if (sniffer) 2203 if (sniffer)
2215 rx_data(dev, prcs, pkt_addr, rx_len); 2204 rx_data(dev, prcs, pkt_addr, rx_len);
2216 else 2205 else
2217 rx_deauthenticate(local, prcs, pkt_addr, rx_len); 2206 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2218 break; 2207 break;
2219 case NULL_MSG_TYPE: 2208 case NULL_MSG_TYPE:
2220 DEBUG(3, "ray_cs rx NULL msg\n"); 2209 pr_debug("ray_cs rx NULL msg\n");
2221 break; 2210 break;
2222 case BEACON_TYPE: 2211 case BEACON_TYPE:
2223 DEBUG(4, "ray_rx beacon type\n"); 2212 pr_debug("ray_rx beacon type\n");
2224 if (sniffer) 2213 if (sniffer)
2225 rx_data(dev, prcs, pkt_addr, rx_len); 2214 rx_data(dev, prcs, pkt_addr, rx_len);
2226 2215
@@ -2233,7 +2222,7 @@ static void ray_rx(struct net_device *dev, ray_dev_t *local,
2233 ray_get_stats(dev); 2222 ray_get_stats(dev);
2234 break; 2223 break;
2235 default: 2224 default:
2236 DEBUG(0, "ray_cs unknown pkt type %2x\n", 2225 pr_debug("ray_cs unknown pkt type %2x\n",
2237 (unsigned int)readb(pmsg)); 2226 (unsigned int)readb(pmsg));
2238 break; 2227 break;
2239 } 2228 }
@@ -2262,7 +2251,7 @@ static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2262 rx_len > 2251 rx_len >
2263 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + 2252 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2264 FCS_LEN)) { 2253 FCS_LEN)) {
2265 DEBUG(0, 2254 pr_debug(
2266 "ray_cs invalid packet length %d received \n", 2255 "ray_cs invalid packet length %d received \n",
2267 rx_len); 2256 rx_len);
2268 return; 2257 return;
@@ -2273,17 +2262,17 @@ static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2273 rx_len > 2262 rx_len >
2274 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + 2263 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2275 FCS_LEN)) { 2264 FCS_LEN)) {
2276 DEBUG(0, 2265 pr_debug(
2277 "ray_cs invalid packet length %d received \n", 2266 "ray_cs invalid packet length %d received \n",
2278 rx_len); 2267 rx_len);
2279 return; 2268 return;
2280 } 2269 }
2281 } 2270 }
2282 } 2271 }
2283 DEBUG(4, "ray_cs rx_data packet\n"); 2272 pr_debug("ray_cs rx_data packet\n");
2284 /* If fragmented packet, verify sizes of fragments add up */ 2273 /* If fragmented packet, verify sizes of fragments add up */
2285 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) { 2274 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2286 DEBUG(1, "ray_cs rx'ed fragment\n"); 2275 pr_debug("ray_cs rx'ed fragment\n");
2287 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8) 2276 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2288 + readb(&prcs->var.rx_packet.totalpacketlength[1]); 2277 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2289 total_len = tmp; 2278 total_len = tmp;
@@ -2301,7 +2290,7 @@ static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2301 } while (1); 2290 } while (1);
2302 2291
2303 if (tmp < 0) { 2292 if (tmp < 0) {
2304 DEBUG(0, 2293 pr_debug(
2305 "ray_cs rx_data fragment lengths don't add up\n"); 2294 "ray_cs rx_data fragment lengths don't add up\n");
2306 local->stats.rx_dropped++; 2295 local->stats.rx_dropped++;
2307 release_frag_chain(local, prcs); 2296 release_frag_chain(local, prcs);
@@ -2313,7 +2302,7 @@ static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2313 2302
2314 skb = dev_alloc_skb(total_len + 5); 2303 skb = dev_alloc_skb(total_len + 5);
2315 if (skb == NULL) { 2304 if (skb == NULL) {
2316 DEBUG(0, "ray_cs rx_data could not allocate skb\n"); 2305 pr_debug("ray_cs rx_data could not allocate skb\n");
2317 local->stats.rx_dropped++; 2306 local->stats.rx_dropped++;
2318 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) 2307 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2319 release_frag_chain(local, prcs); 2308 release_frag_chain(local, prcs);
@@ -2321,7 +2310,7 @@ static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2321 } 2310 }
2322 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */ 2311 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2323 2312
2324 DEBUG(4, "ray_cs rx_data total_len = %x, rx_len = %x\n", total_len, 2313 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
2325 rx_len); 2314 rx_len);
2326 2315
2327/************************/ 2316/************************/
@@ -2354,7 +2343,7 @@ static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2354 tmp = 17; 2343 tmp = 17;
2355 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) { 2344 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2356 prcslink = prcs; 2345 prcslink = prcs;
2357 DEBUG(1, "ray_cs rx_data in fragment loop\n"); 2346 pr_debug("ray_cs rx_data in fragment loop\n");
2358 do { 2347 do {
2359 prcslink = rcs_base(local) 2348 prcslink = rcs_base(local)
2360 + 2349 +
@@ -2426,8 +2415,8 @@ static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2426 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN); 2415 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2427 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN); 2416 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
2428 2417
2429#ifdef PCMCIA_DEBUG 2418#if 0
2430 if (pc_debug > 3) { 2419 if {
2431 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ", 2420 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2432 DUMP_PREFIX_NONE, 16, 1, 2421 DUMP_PREFIX_NONE, 16, 1,
2433 skb->data, 64, true); 2422 skb->data, 64, true);
@@ -2441,7 +2430,7 @@ static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2441 2430
2442 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) { 2431 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2443 /* not a snap type so leave it alone */ 2432 /* not a snap type so leave it alone */
2444 DEBUG(3, "ray_cs untranslate NOT SNAP %02x %02x %02x\n", 2433 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
2445 psnap->dsap, psnap->ssap, psnap->ctrl); 2434 psnap->dsap, psnap->ssap, psnap->ctrl);
2446 2435
2447 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; 2436 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
@@ -2450,7 +2439,7 @@ static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2450 } else { /* Its a SNAP */ 2439 } else { /* Its a SNAP */
2451 if (memcmp(psnap->org, org_bridge, 3) == 0) { 2440 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2452 /* EtherII and nuke the LLC */ 2441 /* EtherII and nuke the LLC */
2453 DEBUG(3, "ray_cs untranslate Bridge encap\n"); 2442 pr_debug("ray_cs untranslate Bridge encap\n");
2454 delta = RX_MAC_HEADER_LENGTH 2443 delta = RX_MAC_HEADER_LENGTH
2455 + sizeof(struct snaphdr_t) - ETH_HLEN; 2444 + sizeof(struct snaphdr_t) - ETH_HLEN;
2456 peth = (struct ethhdr *)(skb->data + delta); 2445 peth = (struct ethhdr *)(skb->data + delta);
@@ -2459,14 +2448,14 @@ static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2459 switch (ntohs(type)) { 2448 switch (ntohs(type)) {
2460 case ETH_P_IPX: 2449 case ETH_P_IPX:
2461 case ETH_P_AARP: 2450 case ETH_P_AARP:
2462 DEBUG(3, "ray_cs untranslate RFC IPX/AARP\n"); 2451 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
2463 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; 2452 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2464 peth = (struct ethhdr *)(skb->data + delta); 2453 peth = (struct ethhdr *)(skb->data + delta);
2465 peth->h_proto = 2454 peth->h_proto =
2466 htons(len - RX_MAC_HEADER_LENGTH); 2455 htons(len - RX_MAC_HEADER_LENGTH);
2467 break; 2456 break;
2468 default: 2457 default:
2469 DEBUG(3, "ray_cs untranslate RFC default\n"); 2458 pr_debug("ray_cs untranslate RFC default\n");
2470 delta = RX_MAC_HEADER_LENGTH + 2459 delta = RX_MAC_HEADER_LENGTH +
2471 sizeof(struct snaphdr_t) - ETH_HLEN; 2460 sizeof(struct snaphdr_t) - ETH_HLEN;
2472 peth = (struct ethhdr *)(skb->data + delta); 2461 peth = (struct ethhdr *)(skb->data + delta);
@@ -2482,12 +2471,12 @@ static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2482 } 2471 }
2483/* TBD reserve skb_reserve(skb, delta); */ 2472/* TBD reserve skb_reserve(skb, delta); */
2484 skb_pull(skb, delta); 2473 skb_pull(skb, delta);
2485 DEBUG(3, "untranslate after skb_pull(%d), skb->data = %p\n", delta, 2474 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
2486 skb->data); 2475 skb->data);
2487 memcpy(peth->h_dest, destaddr, ADDRLEN); 2476 memcpy(peth->h_dest, destaddr, ADDRLEN);
2488 memcpy(peth->h_source, srcaddr, ADDRLEN); 2477 memcpy(peth->h_source, srcaddr, ADDRLEN);
2489#ifdef PCMCIA_DEBUG 2478#if 0
2490 if (pc_debug > 3) { 2479 {
2491 int i; 2480 int i;
2492 printk(KERN_DEBUG "skb->data after untranslate:"); 2481 printk(KERN_DEBUG "skb->data after untranslate:");
2493 for (i = 0; i < 64; i++) 2482 for (i = 0; i < 64; i++)
@@ -2529,7 +2518,7 @@ static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2529 while (tmp--) { 2518 while (tmp--) {
2530 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status); 2519 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2531 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) { 2520 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
2532 DEBUG(1, "ray_cs interrupt bad rcsindex = 0x%x\n", 2521 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
2533 rcsindex); 2522 rcsindex);
2534 break; 2523 break;
2535 } 2524 }
@@ -2543,9 +2532,9 @@ static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2543static void authenticate(ray_dev_t *local) 2532static void authenticate(ray_dev_t *local)
2544{ 2533{
2545 struct pcmcia_device *link = local->finder; 2534 struct pcmcia_device *link = local->finder;
2546 DEBUG(0, "ray_cs Starting authentication.\n"); 2535 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
2547 if (!(pcmcia_dev_present(link))) { 2536 if (!(pcmcia_dev_present(link))) {
2548 DEBUG(2, "ray_cs authenticate - device not present\n"); 2537 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
2549 return; 2538 return;
2550 } 2539 }
2551 2540
@@ -2573,11 +2562,11 @@ static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2573 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff); 2562 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2574 /* if we are trying to get authenticated */ 2563 /* if we are trying to get authenticated */
2575 if (local->sparm.b4.a_network_type == ADHOC) { 2564 if (local->sparm.b4.a_network_type == ADHOC) {
2576 DEBUG(1, "ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n", 2565 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
2577 msg->var[0], msg->var[1], msg->var[2], msg->var[3], 2566 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2578 msg->var[4], msg->var[5]); 2567 msg->var[4], msg->var[5]);
2579 if (msg->var[2] == 1) { 2568 if (msg->var[2] == 1) {
2580 DEBUG(0, "ray_cs Sending authentication response.\n"); 2569 pr_debug("ray_cs Sending authentication response.\n");
2581 if (!build_auth_frame 2570 if (!build_auth_frame
2582 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) { 2571 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2583 local->authentication_state = NEED_TO_AUTH; 2572 local->authentication_state = NEED_TO_AUTH;
@@ -2591,13 +2580,13 @@ static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2591 /* Verify authentication sequence #2 and success */ 2580 /* Verify authentication sequence #2 and success */
2592 if (msg->var[2] == 2) { 2581 if (msg->var[2] == 2) {
2593 if ((msg->var[3] | msg->var[4]) == 0) { 2582 if ((msg->var[3] | msg->var[4]) == 0) {
2594 DEBUG(1, "Authentication successful\n"); 2583 pr_debug("Authentication successful\n");
2595 local->card_status = CARD_AUTH_COMPLETE; 2584 local->card_status = CARD_AUTH_COMPLETE;
2596 associate(local); 2585 associate(local);
2597 local->authentication_state = 2586 local->authentication_state =
2598 AUTHENTICATED; 2587 AUTHENTICATED;
2599 } else { 2588 } else {
2600 DEBUG(0, "Authentication refused\n"); 2589 pr_debug("Authentication refused\n");
2601 local->card_status = CARD_AUTH_REFUSED; 2590 local->card_status = CARD_AUTH_REFUSED;
2602 join_net((u_long) local); 2591 join_net((u_long) local);
2603 local->authentication_state = 2592 local->authentication_state =
@@ -2617,22 +2606,22 @@ static void associate(ray_dev_t *local)
2617 struct net_device *dev = link->priv; 2606 struct net_device *dev = link->priv;
2618 int ccsindex; 2607 int ccsindex;
2619 if (!(pcmcia_dev_present(link))) { 2608 if (!(pcmcia_dev_present(link))) {
2620 DEBUG(2, "ray_cs associate - device not present\n"); 2609 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
2621 return; 2610 return;
2622 } 2611 }
2623 /* If no tx buffers available, return */ 2612 /* If no tx buffers available, return */
2624 if ((ccsindex = get_free_ccs(local)) < 0) { 2613 if ((ccsindex = get_free_ccs(local)) < 0) {
2625/* TBD should never be here but... what if we are? */ 2614/* TBD should never be here but... what if we are? */
2626 DEBUG(1, "ray_cs associate - No free ccs\n"); 2615 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
2627 return; 2616 return;
2628 } 2617 }
2629 DEBUG(1, "ray_cs Starting association with access point\n"); 2618 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
2630 pccs = ccs_base(local) + ccsindex; 2619 pccs = ccs_base(local) + ccsindex;
2631 /* fill in the CCS */ 2620 /* fill in the CCS */
2632 writeb(CCS_START_ASSOCIATION, &pccs->cmd); 2621 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2633 /* Interrupt the firmware to process the command */ 2622 /* Interrupt the firmware to process the command */
2634 if (interrupt_ecf(local, ccsindex)) { 2623 if (interrupt_ecf(local, ccsindex)) {
2635 DEBUG(1, "ray_cs associate failed - ECF not ready for intr\n"); 2624 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
2636 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 2625 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2637 2626
2638 del_timer(&local->timer); 2627 del_timer(&local->timer);
@@ -2655,7 +2644,7 @@ static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2655/* UCHAR buff[256]; 2644/* UCHAR buff[256];
2656 struct rx_msg *msg = (struct rx_msg *)buff; 2645 struct rx_msg *msg = (struct rx_msg *)buff;
2657*/ 2646*/
2658 DEBUG(0, "Deauthentication frame received\n"); 2647 pr_debug("Deauthentication frame received\n");
2659 local->authentication_state = UNAUTHENTICATED; 2648 local->authentication_state = UNAUTHENTICATED;
2660 /* Need to reauthenticate or rejoin depending on reason code */ 2649 /* Need to reauthenticate or rejoin depending on reason code */
2661/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff); 2650/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
@@ -2823,7 +2812,7 @@ static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2823 2812
2824 /* If no tx buffers available, return */ 2813 /* If no tx buffers available, return */
2825 if ((ccsindex = get_free_tx_ccs(local)) < 0) { 2814 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
2826 DEBUG(1, "ray_cs send authenticate - No free tx ccs\n"); 2815 pr_debug("ray_cs send authenticate - No free tx ccs\n");
2827 return -1; 2816 return -1;
2828 } 2817 }
2829 2818
@@ -2855,7 +2844,7 @@ static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2855 2844
2856 /* Interrupt the firmware to process the command */ 2845 /* Interrupt the firmware to process the command */
2857 if (interrupt_ecf(local, ccsindex)) { 2846 if (interrupt_ecf(local, ccsindex)) {
2858 DEBUG(1, 2847 pr_debug(
2859 "ray_cs send authentication request failed - ECF not ready for intr\n"); 2848 "ray_cs send authentication request failed - ECF not ready for intr\n");
2860 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 2849 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2861 return -1; 2850 return -1;
@@ -2879,7 +2868,7 @@ static int write_essid(struct file *file, const char __user *buffer,
2879 unsigned long count, void *data) 2868 unsigned long count, void *data)
2880{ 2869{
2881 static char proc_essid[33]; 2870 static char proc_essid[33];
2882 int len = count; 2871 unsigned int len = count;
2883 2872
2884 if (len > 32) 2873 if (len > 32)
2885 len = 32; 2874 len = 32;
@@ -2942,9 +2931,9 @@ static int __init init_ray_cs(void)
2942{ 2931{
2943 int rc; 2932 int rc;
2944 2933
2945 DEBUG(1, "%s\n", rcsid); 2934 pr_debug("%s\n", rcsid);
2946 rc = pcmcia_register_driver(&ray_driver); 2935 rc = pcmcia_register_driver(&ray_driver);
2947 DEBUG(1, "raylink init_module register_pcmcia_driver returns 0x%x\n", 2936 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
2948 rc); 2937 rc);
2949 2938
2950#ifdef CONFIG_PROC_FS 2939#ifdef CONFIG_PROC_FS
@@ -2964,7 +2953,7 @@ static int __init init_ray_cs(void)
2964 2953
2965static void __exit exit_ray_cs(void) 2954static void __exit exit_ray_cs(void)
2966{ 2955{
2967 DEBUG(0, "ray_cs: cleanup_module\n"); 2956 pr_debug("ray_cs: cleanup_module\n");
2968 2957
2969#ifdef CONFIG_PROC_FS 2958#ifdef CONFIG_PROC_FS
2970 remove_proc_entry("driver/ray_cs/ray_cs", NULL); 2959 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index a084077a1c61..9fe770f7d7bb 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -1994,7 +1994,7 @@ static void rt2800usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1994 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size); 1994 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
1995 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID, 1995 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
1996 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ? 1996 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
1997 (skbdesc->entry->entry_idx + 1) : 0xff); 1997 txdesc->key_idx : 0xff);
1998 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT, 1998 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
1999 skb->len - txdesc->l2pad); 1999 skb->len - txdesc->l2pad);
2000 rt2x00_set_field32(&word, TXWI_W1_PACKETID, 2000 rt2x00_set_field32(&word, TXWI_W1_PACKETID,
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index 71761b343839..73bbec58341e 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -815,6 +815,8 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
815 815
816 mutex_init(&rt2x00dev->csr_mutex); 816 mutex_init(&rt2x00dev->csr_mutex);
817 817
818 set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
819
818 /* 820 /*
819 * Make room for rt2x00_intf inside the per-interface 821 * Make room for rt2x00_intf inside the per-interface
820 * structure ieee80211_vif. 822 * structure ieee80211_vif.
@@ -871,8 +873,6 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
871 rt2x00leds_register(rt2x00dev); 873 rt2x00leds_register(rt2x00dev);
872 rt2x00debug_register(rt2x00dev); 874 rt2x00debug_register(rt2x00dev);
873 875
874 set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
875
876 return 0; 876 return 0;
877 877
878exit: 878exit:
diff --git a/drivers/net/wireless/rt2x00/rt2x00link.c b/drivers/net/wireless/rt2x00/rt2x00link.c
index c64db0ba7f40..c708d0be9155 100644
--- a/drivers/net/wireless/rt2x00/rt2x00link.c
+++ b/drivers/net/wireless/rt2x00/rt2x00link.c
@@ -362,8 +362,9 @@ void rt2x00link_start_tuner(struct rt2x00_dev *rt2x00dev)
362 362
363 rt2x00link_reset_tuner(rt2x00dev, false); 363 rt2x00link_reset_tuner(rt2x00dev, false);
364 364
365 ieee80211_queue_delayed_work(rt2x00dev->hw, 365 if (test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
366 &link->work, LINK_TUNE_INTERVAL); 366 ieee80211_queue_delayed_work(rt2x00dev->hw,
367 &link->work, LINK_TUNE_INTERVAL);
367} 368}
368 369
369void rt2x00link_stop_tuner(struct rt2x00_dev *rt2x00dev) 370void rt2x00link_stop_tuner(struct rt2x00_dev *rt2x00dev)
@@ -469,8 +470,10 @@ static void rt2x00link_tuner(struct work_struct *work)
469 * Increase tuner counter, and reschedule the next link tuner run. 470 * Increase tuner counter, and reschedule the next link tuner run.
470 */ 471 */
471 link->count++; 472 link->count++;
472 ieee80211_queue_delayed_work(rt2x00dev->hw, 473
473 &link->work, LINK_TUNE_INTERVAL); 474 if (test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
475 ieee80211_queue_delayed_work(rt2x00dev->hw,
476 &link->work, LINK_TUNE_INTERVAL);
474} 477}
475 478
476void rt2x00link_register(struct rt2x00_dev *rt2x00dev) 479void rt2x00link_register(struct rt2x00_dev *rt2x00dev)
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.c b/drivers/net/wireless/rt2x00/rt2x00usb.c
index 501544882c2c..f02b48a90593 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.c
@@ -47,6 +47,8 @@ int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
47 (requesttype == USB_VENDOR_REQUEST_IN) ? 47 (requesttype == USB_VENDOR_REQUEST_IN) ?
48 usb_rcvctrlpipe(usb_dev, 0) : usb_sndctrlpipe(usb_dev, 0); 48 usb_rcvctrlpipe(usb_dev, 0) : usb_sndctrlpipe(usb_dev, 0);
49 49
50 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
51 return -ENODEV;
50 52
51 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 53 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
52 status = usb_control_msg(usb_dev, pipe, request, requesttype, 54 status = usb_control_msg(usb_dev, pipe, request, requesttype,
@@ -60,8 +62,10 @@ int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
60 * -ENODEV: Device has disappeared, no point continuing. 62 * -ENODEV: Device has disappeared, no point continuing.
61 * All other errors: Try again. 63 * All other errors: Try again.
62 */ 64 */
63 else if (status == -ENODEV) 65 else if (status == -ENODEV) {
66 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
64 break; 67 break;
68 }
65 } 69 }
66 70
67 ERROR(rt2x00dev, 71 ERROR(rt2x00dev,
@@ -161,6 +165,9 @@ int rt2x00usb_regbusy_read(struct rt2x00_dev *rt2x00dev,
161{ 165{
162 unsigned int i; 166 unsigned int i;
163 167
168 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
169 return -ENODEV;
170
164 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 171 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
165 rt2x00usb_register_read_lock(rt2x00dev, offset, reg); 172 rt2x00usb_register_read_lock(rt2x00dev, offset, reg);
166 if (!rt2x00_get_field32(*reg, field)) 173 if (!rt2x00_get_field32(*reg, field))
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index b8f5ee33445e..14e7bb210075 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -2389,10 +2389,13 @@ static struct usb_device_id rt73usb_device_table[] = {
2389 { USB_DEVICE(0x13b1, 0x0023), USB_DEVICE_DATA(&rt73usb_ops) }, 2389 { USB_DEVICE(0x13b1, 0x0023), USB_DEVICE_DATA(&rt73usb_ops) },
2390 { USB_DEVICE(0x13b1, 0x0028), USB_DEVICE_DATA(&rt73usb_ops) }, 2390 { USB_DEVICE(0x13b1, 0x0028), USB_DEVICE_DATA(&rt73usb_ops) },
2391 /* MSI */ 2391 /* MSI */
2392 { USB_DEVICE(0x0db0, 0x4600), USB_DEVICE_DATA(&rt73usb_ops) },
2392 { USB_DEVICE(0x0db0, 0x6877), USB_DEVICE_DATA(&rt73usb_ops) }, 2393 { USB_DEVICE(0x0db0, 0x6877), USB_DEVICE_DATA(&rt73usb_ops) },
2393 { USB_DEVICE(0x0db0, 0x6874), USB_DEVICE_DATA(&rt73usb_ops) }, 2394 { USB_DEVICE(0x0db0, 0x6874), USB_DEVICE_DATA(&rt73usb_ops) },
2394 { USB_DEVICE(0x0db0, 0xa861), USB_DEVICE_DATA(&rt73usb_ops) }, 2395 { USB_DEVICE(0x0db0, 0xa861), USB_DEVICE_DATA(&rt73usb_ops) },
2395 { USB_DEVICE(0x0db0, 0xa874), USB_DEVICE_DATA(&rt73usb_ops) }, 2396 { USB_DEVICE(0x0db0, 0xa874), USB_DEVICE_DATA(&rt73usb_ops) },
2397 /* Ovislink */
2398 { USB_DEVICE(0x1b75, 0x7318), USB_DEVICE_DATA(&rt73usb_ops) },
2396 /* Ralink */ 2399 /* Ralink */
2397 { USB_DEVICE(0x04bb, 0x093d), USB_DEVICE_DATA(&rt73usb_ops) }, 2400 { USB_DEVICE(0x04bb, 0x093d), USB_DEVICE_DATA(&rt73usb_ops) },
2398 { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt73usb_ops) }, 2401 { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt73usb_ops) },
@@ -2420,6 +2423,8 @@ static struct usb_device_id rt73usb_device_table[] = {
2420 /* Planex */ 2423 /* Planex */
2421 { USB_DEVICE(0x2019, 0xab01), USB_DEVICE_DATA(&rt73usb_ops) }, 2424 { USB_DEVICE(0x2019, 0xab01), USB_DEVICE_DATA(&rt73usb_ops) },
2422 { USB_DEVICE(0x2019, 0xab50), USB_DEVICE_DATA(&rt73usb_ops) }, 2425 { USB_DEVICE(0x2019, 0xab50), USB_DEVICE_DATA(&rt73usb_ops) },
2426 /* WideTell */
2427 { USB_DEVICE(0x7167, 0x3840), USB_DEVICE_DATA(&rt73usb_ops) },
2423 /* Zcom */ 2428 /* Zcom */
2424 { USB_DEVICE(0x0cde, 0x001c), USB_DEVICE_DATA(&rt73usb_ops) }, 2429 { USB_DEVICE(0x0cde, 0x001c), USB_DEVICE_DATA(&rt73usb_ops) },
2425 /* ZyXEL */ 2430 /* ZyXEL */
diff --git a/drivers/net/wireless/rtl818x/rtl8187_leds.c b/drivers/net/wireless/rtl818x/rtl8187_leds.c
index a1c670fc1552..cf8a4a40fdf6 100644
--- a/drivers/net/wireless/rtl818x/rtl8187_leds.c
+++ b/drivers/net/wireless/rtl818x/rtl8187_leds.c
@@ -210,10 +210,10 @@ void rtl8187_leds_exit(struct ieee80211_hw *dev)
210 210
211 /* turn the LED off before exiting */ 211 /* turn the LED off before exiting */
212 ieee80211_queue_delayed_work(dev, &priv->led_off, 0); 212 ieee80211_queue_delayed_work(dev, &priv->led_off, 0);
213 cancel_delayed_work_sync(&priv->led_off);
214 cancel_delayed_work_sync(&priv->led_on);
215 rtl8187_unregister_led(&priv->led_rx); 213 rtl8187_unregister_led(&priv->led_rx);
216 rtl8187_unregister_led(&priv->led_tx); 214 rtl8187_unregister_led(&priv->led_tx);
215 cancel_delayed_work_sync(&priv->led_off);
216 cancel_delayed_work_sync(&priv->led_on);
217} 217}
218#endif /* def CONFIG_RTL8187_LED */ 218#endif /* def CONFIG_RTL8187_LED */
219 219
diff --git a/drivers/net/wireless/rtl818x/rtl8187_rfkill.c b/drivers/net/wireless/rtl818x/rtl8187_rfkill.c
index 9fab13e4004e..cad8037ab2af 100644
--- a/drivers/net/wireless/rtl818x/rtl8187_rfkill.c
+++ b/drivers/net/wireless/rtl818x/rtl8187_rfkill.c
@@ -18,6 +18,7 @@
18#include <net/mac80211.h> 18#include <net/mac80211.h>
19 19
20#include "rtl8187.h" 20#include "rtl8187.h"
21#include "rtl8187_rfkill.h"
21 22
22static bool rtl8187_is_radio_enabled(struct rtl8187_priv *priv) 23static bool rtl8187_is_radio_enabled(struct rtl8187_priv *priv)
23{ 24{
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index 431a20ec6db6..33918fd5b231 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -3656,10 +3656,7 @@ wv_pcmcia_reset(struct net_device * dev)
3656 3656
3657 i = pcmcia_access_configuration_register(link, &reg); 3657 i = pcmcia_access_configuration_register(link, &reg);
3658 if (i != 0) 3658 if (i != 0)
3659 {
3660 cs_error(link, AccessConfigurationRegister, i);
3661 return FALSE; 3659 return FALSE;
3662 }
3663 3660
3664#ifdef DEBUG_CONFIG_INFO 3661#ifdef DEBUG_CONFIG_INFO
3665 printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n", 3662 printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n",
@@ -3670,19 +3667,13 @@ wv_pcmcia_reset(struct net_device * dev)
3670 reg.Value = reg.Value | COR_SW_RESET; 3667 reg.Value = reg.Value | COR_SW_RESET;
3671 i = pcmcia_access_configuration_register(link, &reg); 3668 i = pcmcia_access_configuration_register(link, &reg);
3672 if (i != 0) 3669 if (i != 0)
3673 {
3674 cs_error(link, AccessConfigurationRegister, i);
3675 return FALSE; 3670 return FALSE;
3676 }
3677 3671
3678 reg.Action = CS_WRITE; 3672 reg.Action = CS_WRITE;
3679 reg.Value = COR_LEVEL_IRQ | COR_CONFIG; 3673 reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
3680 i = pcmcia_access_configuration_register(link, &reg); 3674 i = pcmcia_access_configuration_register(link, &reg);
3681 if (i != 0) 3675 if (i != 0)
3682 {
3683 cs_error(link, AccessConfigurationRegister, i);
3684 return FALSE; 3676 return FALSE;
3685 }
3686 3677
3687#ifdef DEBUG_CONFIG_TRACE 3678#ifdef DEBUG_CONFIG_TRACE
3688 printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name); 3679 printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name);
@@ -3857,10 +3848,7 @@ wv_pcmcia_config(struct pcmcia_device * link)
3857 { 3848 {
3858 i = pcmcia_request_io(link, &link->io); 3849 i = pcmcia_request_io(link, &link->io);
3859 if (i != 0) 3850 if (i != 0)
3860 {
3861 cs_error(link, RequestIO, i);
3862 break; 3851 break;
3863 }
3864 3852
3865 /* 3853 /*
3866 * Now allocate an interrupt line. Note that this does not 3854 * Now allocate an interrupt line. Note that this does not
@@ -3868,10 +3856,7 @@ wv_pcmcia_config(struct pcmcia_device * link)
3868 */ 3856 */
3869 i = pcmcia_request_irq(link, &link->irq); 3857 i = pcmcia_request_irq(link, &link->irq);
3870 if (i != 0) 3858 if (i != 0)
3871 {
3872 cs_error(link, RequestIRQ, i);
3873 break; 3859 break;
3874 }
3875 3860
3876 /* 3861 /*
3877 * This actually configures the PCMCIA socket -- setting up 3862 * This actually configures the PCMCIA socket -- setting up
@@ -3880,10 +3865,7 @@ wv_pcmcia_config(struct pcmcia_device * link)
3880 link->conf.ConfigIndex = 1; 3865 link->conf.ConfigIndex = 1;
3881 i = pcmcia_request_configuration(link, &link->conf); 3866 i = pcmcia_request_configuration(link, &link->conf);
3882 if (i != 0) 3867 if (i != 0)
3883 {
3884 cs_error(link, RequestConfiguration, i);
3885 break; 3868 break;
3886 }
3887 3869
3888 /* 3870 /*
3889 * Allocate a small memory window. Note that the struct pcmcia_device 3871 * Allocate a small memory window. Note that the struct pcmcia_device
@@ -3894,24 +3876,18 @@ wv_pcmcia_config(struct pcmcia_device * link)
3894 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 3876 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
3895 req.Base = req.Size = 0; 3877 req.Base = req.Size = 0;
3896 req.AccessSpeed = mem_speed; 3878 req.AccessSpeed = mem_speed;
3897 i = pcmcia_request_window(&link, &req, &link->win); 3879 i = pcmcia_request_window(link, &req, &link->win);
3898 if (i != 0) 3880 if (i != 0)
3899 {
3900 cs_error(link, RequestWindow, i);
3901 break; 3881 break;
3902 }
3903 3882
3904 lp->mem = ioremap(req.Base, req.Size); 3883 lp->mem = ioremap(req.Base, req.Size);
3905 dev->mem_start = (u_long)lp->mem; 3884 dev->mem_start = (u_long)lp->mem;
3906 dev->mem_end = dev->mem_start + req.Size; 3885 dev->mem_end = dev->mem_start + req.Size;
3907 3886
3908 mem.CardOffset = 0; mem.Page = 0; 3887 mem.CardOffset = 0; mem.Page = 0;
3909 i = pcmcia_map_mem_page(link->win, &mem); 3888 i = pcmcia_map_mem_page(link, link->win, &mem);
3910 if (i != 0) 3889 if (i != 0)
3911 {
3912 cs_error(link, MapMemPage, i);
3913 break; 3890 break;
3914 }
3915 3891
3916 /* Feed device with this info... */ 3892 /* Feed device with this info... */
3917 dev->irq = link->irq.AssignedIRQ; 3893 dev->irq = link->irq.AssignedIRQ;
@@ -3923,7 +3899,7 @@ wv_pcmcia_config(struct pcmcia_device * link)
3923 lp->mem, dev->irq, (u_int) dev->base_addr); 3899 lp->mem, dev->irq, (u_int) dev->base_addr);
3924#endif 3900#endif
3925 3901
3926 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 3902 SET_NETDEV_DEV(dev, &link->dev);
3927 i = register_netdev(dev); 3903 i = register_netdev(dev);
3928 if(i != 0) 3904 if(i != 0)
3929 { 3905 {
@@ -4462,8 +4438,7 @@ wavelan_probe(struct pcmcia_device *p_dev)
4462 p_dev->io.IOAddrLines = 3; 4438 p_dev->io.IOAddrLines = 3;
4463 4439
4464 /* Interrupt setup */ 4440 /* Interrupt setup */
4465 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT; 4441 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
4466 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
4467 p_dev->irq.Handler = wavelan_interrupt; 4442 p_dev->irq.Handler = wavelan_interrupt;
4468 4443
4469 /* General socket configuration */ 4444 /* General socket configuration */
@@ -4475,7 +4450,7 @@ wavelan_probe(struct pcmcia_device *p_dev)
4475 if (!dev) 4450 if (!dev)
4476 return -ENOMEM; 4451 return -ENOMEM;
4477 4452
4478 p_dev->priv = p_dev->irq.Instance = dev; 4453 p_dev->priv = dev;
4479 4454
4480 lp = netdev_priv(dev); 4455 lp = netdev_priv(dev);
4481 4456
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 4f1e0cfe609b..5f0401a52cff 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -67,23 +67,7 @@
67/* For rough constant delay */ 67/* For rough constant delay */
68#define WL3501_NOPLOOP(n) { int x = 0; while (x++ < n) slow_down_io(); } 68#define WL3501_NOPLOOP(n) { int x = 0; while (x++ < n) slow_down_io(); }
69 69
70/* 70
71 * All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If you do not
72 * define PCMCIA_DEBUG at all, all the debug code will be left out. If you
73 * compile with PCMCIA_DEBUG=0, the debug code will be present but disabled --
74 * but it can then be enabled for specific modules at load time with a
75 * 'pc_debug=#' option to insmod.
76 */
77#define PCMCIA_DEBUG 0
78#ifdef PCMCIA_DEBUG
79static int pc_debug = PCMCIA_DEBUG;
80module_param(pc_debug, int, 0);
81#define dprintk(n, format, args...) \
82 { if (pc_debug > (n)) \
83 printk(KERN_INFO "%s: " format "\n", __func__ , ##args); }
84#else
85#define dprintk(n, format, args...)
86#endif
87 71
88#define wl3501_outb(a, b) { outb(a, b); slow_down_io(); } 72#define wl3501_outb(a, b) { outb(a, b); slow_down_io(); }
89#define wl3501_outb_p(a, b) { outb_p(a, b); slow_down_io(); } 73#define wl3501_outb_p(a, b) { outb_p(a, b); slow_down_io(); }
@@ -684,10 +668,10 @@ static void wl3501_mgmt_scan_confirm(struct wl3501_card *this, u16 addr)
684 int matchflag = 0; 668 int matchflag = 0;
685 struct wl3501_scan_confirm sig; 669 struct wl3501_scan_confirm sig;
686 670
687 dprintk(3, "entry"); 671 pr_debug("entry");
688 wl3501_get_from_wla(this, addr, &sig, sizeof(sig)); 672 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
689 if (sig.status == WL3501_STATUS_SUCCESS) { 673 if (sig.status == WL3501_STATUS_SUCCESS) {
690 dprintk(3, "success"); 674 pr_debug("success");
691 if ((this->net_type == IW_MODE_INFRA && 675 if ((this->net_type == IW_MODE_INFRA &&
692 (sig.cap_info & WL3501_MGMT_CAPABILITY_ESS)) || 676 (sig.cap_info & WL3501_MGMT_CAPABILITY_ESS)) ||
693 (this->net_type == IW_MODE_ADHOC && 677 (this->net_type == IW_MODE_ADHOC &&
@@ -722,7 +706,7 @@ static void wl3501_mgmt_scan_confirm(struct wl3501_card *this, u16 addr)
722 } 706 }
723 } 707 }
724 } else if (sig.status == WL3501_STATUS_TIMEOUT) { 708 } else if (sig.status == WL3501_STATUS_TIMEOUT) {
725 dprintk(3, "timeout"); 709 pr_debug("timeout");
726 this->join_sta_bss = 0; 710 this->join_sta_bss = 0;
727 for (i = this->join_sta_bss; i < this->bss_cnt; i++) 711 for (i = this->join_sta_bss; i < this->bss_cnt; i++)
728 if (!wl3501_mgmt_join(this, i)) 712 if (!wl3501_mgmt_join(this, i))
@@ -879,7 +863,7 @@ static int wl3501_mgmt_auth(struct wl3501_card *this)
879 .timeout = 1000, 863 .timeout = 1000,
880 }; 864 };
881 865
882 dprintk(3, "entry"); 866 pr_debug("entry");
883 memcpy(sig.mac_addr, this->bssid, ETH_ALEN); 867 memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
884 return wl3501_esbq_exec(this, &sig, sizeof(sig)); 868 return wl3501_esbq_exec(this, &sig, sizeof(sig));
885} 869}
@@ -893,7 +877,7 @@ static int wl3501_mgmt_association(struct wl3501_card *this)
893 .cap_info = this->cap_info, 877 .cap_info = this->cap_info,
894 }; 878 };
895 879
896 dprintk(3, "entry"); 880 pr_debug("entry");
897 memcpy(sig.mac_addr, this->bssid, ETH_ALEN); 881 memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
898 return wl3501_esbq_exec(this, &sig, sizeof(sig)); 882 return wl3501_esbq_exec(this, &sig, sizeof(sig));
899} 883}
@@ -903,7 +887,7 @@ static void wl3501_mgmt_join_confirm(struct net_device *dev, u16 addr)
903 struct wl3501_card *this = netdev_priv(dev); 887 struct wl3501_card *this = netdev_priv(dev);
904 struct wl3501_join_confirm sig; 888 struct wl3501_join_confirm sig;
905 889
906 dprintk(3, "entry"); 890 pr_debug("entry");
907 wl3501_get_from_wla(this, addr, &sig, sizeof(sig)); 891 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
908 if (sig.status == WL3501_STATUS_SUCCESS) { 892 if (sig.status == WL3501_STATUS_SUCCESS) {
909 if (this->net_type == IW_MODE_INFRA) { 893 if (this->net_type == IW_MODE_INFRA) {
@@ -962,7 +946,7 @@ static inline void wl3501_md_confirm_interrupt(struct net_device *dev,
962{ 946{
963 struct wl3501_md_confirm sig; 947 struct wl3501_md_confirm sig;
964 948
965 dprintk(3, "entry"); 949 pr_debug("entry");
966 wl3501_get_from_wla(this, addr, &sig, sizeof(sig)); 950 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
967 wl3501_free_tx_buffer(this, sig.data); 951 wl3501_free_tx_buffer(this, sig.data);
968 if (netif_queue_stopped(dev)) 952 if (netif_queue_stopped(dev))
@@ -1017,7 +1001,7 @@ static inline void wl3501_md_ind_interrupt(struct net_device *dev,
1017static inline void wl3501_get_confirm_interrupt(struct wl3501_card *this, 1001static inline void wl3501_get_confirm_interrupt(struct wl3501_card *this,
1018 u16 addr, void *sig, int size) 1002 u16 addr, void *sig, int size)
1019{ 1003{
1020 dprintk(3, "entry"); 1004 pr_debug("entry");
1021 wl3501_get_from_wla(this, addr, &this->sig_get_confirm, 1005 wl3501_get_from_wla(this, addr, &this->sig_get_confirm,
1022 sizeof(this->sig_get_confirm)); 1006 sizeof(this->sig_get_confirm));
1023 wake_up(&this->wait); 1007 wake_up(&this->wait);
@@ -1029,7 +1013,7 @@ static inline void wl3501_start_confirm_interrupt(struct net_device *dev,
1029{ 1013{
1030 struct wl3501_start_confirm sig; 1014 struct wl3501_start_confirm sig;
1031 1015
1032 dprintk(3, "entry"); 1016 pr_debug("entry");
1033 wl3501_get_from_wla(this, addr, &sig, sizeof(sig)); 1017 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1034 if (sig.status == WL3501_STATUS_SUCCESS) 1018 if (sig.status == WL3501_STATUS_SUCCESS)
1035 netif_wake_queue(dev); 1019 netif_wake_queue(dev);
@@ -1041,7 +1025,7 @@ static inline void wl3501_assoc_confirm_interrupt(struct net_device *dev,
1041 struct wl3501_card *this = netdev_priv(dev); 1025 struct wl3501_card *this = netdev_priv(dev);
1042 struct wl3501_assoc_confirm sig; 1026 struct wl3501_assoc_confirm sig;
1043 1027
1044 dprintk(3, "entry"); 1028 pr_debug("entry");
1045 wl3501_get_from_wla(this, addr, &sig, sizeof(sig)); 1029 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1046 1030
1047 if (sig.status == WL3501_STATUS_SUCCESS) 1031 if (sig.status == WL3501_STATUS_SUCCESS)
@@ -1053,7 +1037,7 @@ static inline void wl3501_auth_confirm_interrupt(struct wl3501_card *this,
1053{ 1037{
1054 struct wl3501_auth_confirm sig; 1038 struct wl3501_auth_confirm sig;
1055 1039
1056 dprintk(3, "entry"); 1040 pr_debug("entry");
1057 wl3501_get_from_wla(this, addr, &sig, sizeof(sig)); 1041 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1058 1042
1059 if (sig.status == WL3501_STATUS_SUCCESS) 1043 if (sig.status == WL3501_STATUS_SUCCESS)
@@ -1069,7 +1053,7 @@ static inline void wl3501_rx_interrupt(struct net_device *dev)
1069 u8 sig_id; 1053 u8 sig_id;
1070 struct wl3501_card *this = netdev_priv(dev); 1054 struct wl3501_card *this = netdev_priv(dev);
1071 1055
1072 dprintk(3, "entry"); 1056 pr_debug("entry");
1073loop: 1057loop:
1074 morepkts = 0; 1058 morepkts = 0;
1075 if (!wl3501_esbq_confirm(this)) 1059 if (!wl3501_esbq_confirm(this))
@@ -1302,7 +1286,7 @@ static int wl3501_reset(struct net_device *dev)
1302 wl3501_ack_interrupt(this); 1286 wl3501_ack_interrupt(this);
1303 wl3501_unblock_interrupt(this); 1287 wl3501_unblock_interrupt(this);
1304 wl3501_mgmt_scan(this, 100); 1288 wl3501_mgmt_scan(this, 100);
1305 dprintk(1, "%s: device reset", dev->name); 1289 pr_debug("%s: device reset", dev->name);
1306 rc = 0; 1290 rc = 0;
1307out: 1291out:
1308 return rc; 1292 return rc;
@@ -1376,7 +1360,7 @@ static int wl3501_open(struct net_device *dev)
1376 link->open++; 1360 link->open++;
1377 1361
1378 /* Initial WL3501 firmware */ 1362 /* Initial WL3501 firmware */
1379 dprintk(1, "%s: Initialize WL3501 firmware...", dev->name); 1363 pr_debug("%s: Initialize WL3501 firmware...", dev->name);
1380 if (wl3501_init_firmware(this)) 1364 if (wl3501_init_firmware(this))
1381 goto fail; 1365 goto fail;
1382 /* Initial device variables */ 1366 /* Initial device variables */
@@ -1388,7 +1372,7 @@ static int wl3501_open(struct net_device *dev)
1388 wl3501_unblock_interrupt(this); 1372 wl3501_unblock_interrupt(this);
1389 wl3501_mgmt_scan(this, 100); 1373 wl3501_mgmt_scan(this, 100);
1390 rc = 0; 1374 rc = 0;
1391 dprintk(1, "%s: WL3501 opened", dev->name); 1375 pr_debug("%s: WL3501 opened", dev->name);
1392 printk(KERN_INFO "%s: Card Name: %s\n" 1376 printk(KERN_INFO "%s: Card Name: %s\n"
1393 "%s: Firmware Date: %s\n", 1377 "%s: Firmware Date: %s\n",
1394 dev->name, this->card_name, 1378 dev->name, this->card_name,
@@ -1914,8 +1898,7 @@ static int wl3501_probe(struct pcmcia_device *p_dev)
1914 p_dev->io.IOAddrLines = 5; 1898 p_dev->io.IOAddrLines = 5;
1915 1899
1916 /* Interrupt setup */ 1900 /* Interrupt setup */
1917 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT; 1901 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
1918 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
1919 p_dev->irq.Handler = wl3501_interrupt; 1902 p_dev->irq.Handler = wl3501_interrupt;
1920 1903
1921 /* General socket configuration */ 1904 /* General socket configuration */
@@ -1938,16 +1921,13 @@ static int wl3501_probe(struct pcmcia_device *p_dev)
1938 dev->wireless_handlers = &wl3501_handler_def; 1921 dev->wireless_handlers = &wl3501_handler_def;
1939 SET_ETHTOOL_OPS(dev, &ops); 1922 SET_ETHTOOL_OPS(dev, &ops);
1940 netif_stop_queue(dev); 1923 netif_stop_queue(dev);
1941 p_dev->priv = p_dev->irq.Instance = dev; 1924 p_dev->priv = dev;
1942 1925
1943 return wl3501_config(p_dev); 1926 return wl3501_config(p_dev);
1944out_link: 1927out_link:
1945 return -ENOMEM; 1928 return -ENOMEM;
1946} 1929}
1947 1930
1948#define CS_CHECK(fn, ret) \
1949do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
1950
1951/** 1931/**
1952 * wl3501_config - configure the PCMCIA socket and make eth device available 1932 * wl3501_config - configure the PCMCIA socket and make eth device available
1953 * @link - FILL_IN 1933 * @link - FILL_IN
@@ -1959,7 +1939,7 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
1959static int wl3501_config(struct pcmcia_device *link) 1939static int wl3501_config(struct pcmcia_device *link)
1960{ 1940{
1961 struct net_device *dev = link->priv; 1941 struct net_device *dev = link->priv;
1962 int i = 0, j, last_fn, last_ret; 1942 int i = 0, j, ret;
1963 struct wl3501_card *this; 1943 struct wl3501_card *this;
1964 1944
1965 /* Try allocating IO ports. This tries a few fixed addresses. If you 1945 /* Try allocating IO ports. This tries a few fixed addresses. If you
@@ -1975,24 +1955,26 @@ static int wl3501_config(struct pcmcia_device *link)
1975 if (i == 0) 1955 if (i == 0)
1976 break; 1956 break;
1977 } 1957 }
1978 if (i != 0) { 1958 if (i != 0)
1979 cs_error(link, RequestIO, i);
1980 goto failed; 1959 goto failed;
1981 }
1982 1960
1983 /* Now allocate an interrupt line. Note that this does not actually 1961 /* Now allocate an interrupt line. Note that this does not actually
1984 * assign a handler to the interrupt. */ 1962 * assign a handler to the interrupt. */
1985 1963
1986 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 1964 ret = pcmcia_request_irq(link, &link->irq);
1965 if (ret)
1966 goto failed;
1987 1967
1988 /* This actually configures the PCMCIA socket -- setting up the I/O 1968 /* This actually configures the PCMCIA socket -- setting up the I/O
1989 * windows and the interrupt mapping. */ 1969 * windows and the interrupt mapping. */
1990 1970
1991 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 1971 ret = pcmcia_request_configuration(link, &link->conf);
1972 if (ret)
1973 goto failed;
1992 1974
1993 dev->irq = link->irq.AssignedIRQ; 1975 dev->irq = link->irq.AssignedIRQ;
1994 dev->base_addr = link->io.BasePort1; 1976 dev->base_addr = link->io.BasePort1;
1995 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 1977 SET_NETDEV_DEV(dev, &link->dev);
1996 if (register_netdev(dev)) { 1978 if (register_netdev(dev)) {
1997 printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n"); 1979 printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n");
1998 goto failed; 1980 goto failed;
@@ -2041,8 +2023,6 @@ static int wl3501_config(struct pcmcia_device *link)
2041 netif_start_queue(dev); 2023 netif_start_queue(dev);
2042 return 0; 2024 return 0;
2043 2025
2044cs_failed:
2045 cs_error(link, last_fn, last_ret);
2046failed: 2026failed:
2047 wl3501_release(link); 2027 wl3501_release(link);
2048 return -ENODEV; 2028 return -ENODEV;
diff --git a/drivers/net/znet.c b/drivers/net/znet.c
index a0384b6f09b6..b42347333750 100644
--- a/drivers/net/znet.c
+++ b/drivers/net/znet.c
@@ -169,7 +169,6 @@ static void znet_tx_timeout (struct net_device *dev);
169static int znet_request_resources (struct net_device *dev) 169static int znet_request_resources (struct net_device *dev)
170{ 170{
171 struct znet_private *znet = netdev_priv(dev); 171 struct znet_private *znet = netdev_priv(dev);
172 unsigned long flags;
173 172
174 if (request_irq (dev->irq, &znet_interrupt, 0, "ZNet", dev)) 173 if (request_irq (dev->irq, &znet_interrupt, 0, "ZNet", dev))
175 goto failed; 174 goto failed;
@@ -187,13 +186,9 @@ static int znet_request_resources (struct net_device *dev)
187 free_sia: 186 free_sia:
188 release_region (znet->sia_base, znet->sia_size); 187 release_region (znet->sia_base, znet->sia_size);
189 free_tx_dma: 188 free_tx_dma:
190 flags = claim_dma_lock();
191 free_dma (znet->tx_dma); 189 free_dma (znet->tx_dma);
192 release_dma_lock (flags);
193 free_rx_dma: 190 free_rx_dma:
194 flags = claim_dma_lock();
195 free_dma (znet->rx_dma); 191 free_dma (znet->rx_dma);
196 release_dma_lock (flags);
197 free_irq: 192 free_irq:
198 free_irq (dev->irq, dev); 193 free_irq (dev->irq, dev);
199 failed: 194 failed:
@@ -203,14 +198,11 @@ static int znet_request_resources (struct net_device *dev)
203static void znet_release_resources (struct net_device *dev) 198static void znet_release_resources (struct net_device *dev)
204{ 199{
205 struct znet_private *znet = netdev_priv(dev); 200 struct znet_private *znet = netdev_priv(dev);
206 unsigned long flags;
207 201
208 release_region (znet->sia_base, znet->sia_size); 202 release_region (znet->sia_base, znet->sia_size);
209 release_region (dev->base_addr, znet->io_size); 203 release_region (dev->base_addr, znet->io_size);
210 flags = claim_dma_lock();
211 free_dma (znet->tx_dma); 204 free_dma (znet->tx_dma);
212 free_dma (znet->rx_dma); 205 free_dma (znet->rx_dma);
213 release_dma_lock (flags);
214 free_irq (dev->irq, dev); 206 free_irq (dev->irq, dev);
215} 207}
216 208