aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-06-12 19:14:22 -0400
committerDavid S. Miller <davem@davemloft.net>2008-06-12 19:14:22 -0400
commit030352a9c7715780b2c01033ae9afe56249bb7cc (patch)
treecc23683773d0d63712f4e6ea6824383f1d696e05
parente6e30add6bd8115af108de2a13ec82d997a55777 (diff)
parent0c1aa20fb87b796d904f4d89ad12e5a0c483127b (diff)
Merge branch 'davem-next' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik/netdev-2.6
-rw-r--r--drivers/net/Kconfig14
-rw-r--r--drivers/net/Makefile2
-rw-r--r--drivers/net/a2065.c4
-rw-r--r--drivers/net/atarilance.c2
-rw-r--r--drivers/net/declance.c4
-rw-r--r--drivers/net/e1000e/netdev.c5
-rw-r--r--drivers/net/hplance.c4
-rw-r--r--drivers/net/igb/igb_main.c7
-rw-r--r--drivers/net/ixgbe/ixgbe_main.c7
-rw-r--r--drivers/net/lib8390.c4
-rw-r--r--drivers/net/mac8390.c8
-rw-r--r--drivers/net/macb.c6
-rw-r--r--drivers/net/macsonic.c19
-rw-r--r--drivers/net/sh_eth.c1174
-rw-r--r--drivers/net/sh_eth.h464
-rw-r--r--drivers/net/smc911x.c423
-rw-r--r--drivers/net/smc911x.h495
-rw-r--r--drivers/net/sunlance.c4
-rw-r--r--drivers/net/usb/Kconfig10
-rw-r--r--drivers/net/usb/Makefile1
-rw-r--r--drivers/net/usb/hso.c2836
-rw-r--r--include/linux/smc911x.h12
22 files changed, 5017 insertions, 488 deletions
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index c537f53ffcb9..40eb24d6d755 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -524,6 +524,18 @@ config STNIC
524 524
525 If unsure, say N. 525 If unsure, say N.
526 526
527config SH_ETH
528 tristate "Renesas SuperH Ethernet support"
529 depends on SUPERH && \
530 (CPU_SUBTYPE_SH7710 || CPU_SUBTYPE_SH7712)
531 select CRC32
532 select MII
533 select MDIO_BITBANG
534 select PHYLIB
535 help
536 Renesas SuperH Ethernet device driver.
537 This driver support SH7710 and SH7712.
538
527config SUNLANCE 539config SUNLANCE
528 tristate "Sun LANCE support" 540 tristate "Sun LANCE support"
529 depends on SBUS 541 depends on SBUS
@@ -955,7 +967,7 @@ config SMC911X
955 tristate "SMSC LAN911[5678] support" 967 tristate "SMSC LAN911[5678] support"
956 select CRC32 968 select CRC32
957 select MII 969 select MII
958 depends on ARCH_PXA || SH_MAGIC_PANEL_R2 970 depends on ARCH_PXA || SUPERH
959 help 971 help
960 This is a driver for SMSC's LAN911x series of Ethernet chipsets 972 This is a driver for SMSC's LAN911x series of Ethernet chipsets
961 including the new LAN9115, LAN9116, LAN9117, and LAN9118. 973 including the new LAN9115, LAN9116, LAN9117, and LAN9118.
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index dcbfe8421154..c96fe2036800 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -80,6 +80,7 @@ obj-$(CONFIG_VIA_RHINE) += via-rhine.o
80obj-$(CONFIG_VIA_VELOCITY) += via-velocity.o 80obj-$(CONFIG_VIA_VELOCITY) += via-velocity.o
81obj-$(CONFIG_ADAPTEC_STARFIRE) += starfire.o 81obj-$(CONFIG_ADAPTEC_STARFIRE) += starfire.o
82obj-$(CONFIG_RIONET) += rionet.o 82obj-$(CONFIG_RIONET) += rionet.o
83obj-$(CONFIG_SH_ETH) += sh_eth.o
83 84
84# 85#
85# end link order section 86# end link order section
@@ -236,6 +237,7 @@ obj-$(CONFIG_USB_CATC) += usb/
236obj-$(CONFIG_USB_KAWETH) += usb/ 237obj-$(CONFIG_USB_KAWETH) += usb/
237obj-$(CONFIG_USB_PEGASUS) += usb/ 238obj-$(CONFIG_USB_PEGASUS) += usb/
238obj-$(CONFIG_USB_RTL8150) += usb/ 239obj-$(CONFIG_USB_RTL8150) += usb/
240obj-$(CONFIG_USB_HSO) += usb/
239obj-$(CONFIG_USB_USBNET) += usb/ 241obj-$(CONFIG_USB_USBNET) += usb/
240obj-$(CONFIG_USB_ZD1201) += usb/ 242obj-$(CONFIG_USB_ZD1201) += usb/
241 243
diff --git a/drivers/net/a2065.c b/drivers/net/a2065.c
index 6c5719ae8cca..9c0837435b68 100644
--- a/drivers/net/a2065.c
+++ b/drivers/net/a2065.c
@@ -475,16 +475,12 @@ static irqreturn_t lance_interrupt (int irq, void *dev_id)
475 return IRQ_HANDLED; 475 return IRQ_HANDLED;
476} 476}
477 477
478struct net_device *last_dev;
479
480static int lance_open (struct net_device *dev) 478static int lance_open (struct net_device *dev)
481{ 479{
482 struct lance_private *lp = netdev_priv(dev); 480 struct lance_private *lp = netdev_priv(dev);
483 volatile struct lance_regs *ll = lp->ll; 481 volatile struct lance_regs *ll = lp->ll;
484 int ret; 482 int ret;
485 483
486 last_dev = dev;
487
488 /* Stop the Lance */ 484 /* Stop the Lance */
489 ll->rap = LE_CSR0; 485 ll->rap = LE_CSR0;
490 ll->rdp = LE_C0_STOP; 486 ll->rdp = LE_C0_STOP;
diff --git a/drivers/net/atarilance.c b/drivers/net/atarilance.c
index 4cceaac8863a..0860cc280b01 100644
--- a/drivers/net/atarilance.c
+++ b/drivers/net/atarilance.c
@@ -243,7 +243,7 @@ struct lance_private {
243 243
244/* Possible memory/IO addresses for probing */ 244/* Possible memory/IO addresses for probing */
245 245
246struct lance_addr { 246static struct lance_addr {
247 unsigned long memaddr; 247 unsigned long memaddr;
248 unsigned long ioaddr; 248 unsigned long ioaddr;
249 int slow_flag; 249 int slow_flag;
diff --git a/drivers/net/declance.c b/drivers/net/declance.c
index 6b1e77cc069e..3e3506411ac0 100644
--- a/drivers/net/declance.c
+++ b/drivers/net/declance.c
@@ -773,8 +773,6 @@ static irqreturn_t lance_interrupt(int irq, void *dev_id)
773 return IRQ_HANDLED; 773 return IRQ_HANDLED;
774} 774}
775 775
776struct net_device *last_dev = 0;
777
778static int lance_open(struct net_device *dev) 776static int lance_open(struct net_device *dev)
779{ 777{
780 volatile u16 *ib = (volatile u16 *)dev->mem_start; 778 volatile u16 *ib = (volatile u16 *)dev->mem_start;
@@ -782,8 +780,6 @@ static int lance_open(struct net_device *dev)
782 volatile struct lance_regs *ll = lp->ll; 780 volatile struct lance_regs *ll = lp->ll;
783 int status = 0; 781 int status = 0;
784 782
785 last_dev = dev;
786
787 /* Stop the Lance */ 783 /* Stop the Lance */
788 writereg(&ll->rap, LE_CSR0); 784 writereg(&ll->rap, LE_CSR0);
789 writereg(&ll->rdp, LE_C0_STOP); 785 writereg(&ll->rdp, LE_C0_STOP);
diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c
index cab1835173cd..ccb8ca2cbb2b 100644
--- a/drivers/net/e1000e/netdev.c
+++ b/drivers/net/e1000e/netdev.c
@@ -4343,6 +4343,11 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
4343 netdev->features |= NETIF_F_TSO; 4343 netdev->features |= NETIF_F_TSO;
4344 netdev->features |= NETIF_F_TSO6; 4344 netdev->features |= NETIF_F_TSO6;
4345 4345
4346 netdev->vlan_features |= NETIF_F_TSO;
4347 netdev->vlan_features |= NETIF_F_TSO6;
4348 netdev->vlan_features |= NETIF_F_HW_CSUM;
4349 netdev->vlan_features |= NETIF_F_SG;
4350
4346 if (pci_using_dac) 4351 if (pci_using_dac)
4347 netdev->features |= NETIF_F_HIGHDMA; 4352 netdev->features |= NETIF_F_HIGHDMA;
4348 4353
diff --git a/drivers/net/hplance.c b/drivers/net/hplance.c
index be6e5bc7c881..2e802634d366 100644
--- a/drivers/net/hplance.c
+++ b/drivers/net/hplance.c
@@ -220,12 +220,12 @@ static int hplance_close(struct net_device *dev)
220 return 0; 220 return 0;
221} 221}
222 222
223int __init hplance_init_module(void) 223static int __init hplance_init_module(void)
224{ 224{
225 return dio_register_driver(&hplance_driver); 225 return dio_register_driver(&hplance_driver);
226} 226}
227 227
228void __exit hplance_cleanup_module(void) 228static void __exit hplance_cleanup_module(void)
229{ 229{
230 dio_unregister_driver(&hplance_driver); 230 dio_unregister_driver(&hplance_driver);
231} 231}
diff --git a/drivers/net/igb/igb_main.c b/drivers/net/igb/igb_main.c
index ae398f04c7b4..7b6b780dc8a6 100644
--- a/drivers/net/igb/igb_main.c
+++ b/drivers/net/igb/igb_main.c
@@ -967,8 +967,13 @@ static int __devinit igb_probe(struct pci_dev *pdev,
967 NETIF_F_HW_VLAN_FILTER; 967 NETIF_F_HW_VLAN_FILTER;
968 968
969 netdev->features |= NETIF_F_TSO; 969 netdev->features |= NETIF_F_TSO;
970
971 netdev->features |= NETIF_F_TSO6; 970 netdev->features |= NETIF_F_TSO6;
971
972 netdev->vlan_features |= NETIF_F_TSO;
973 netdev->vlan_features |= NETIF_F_TSO6;
974 netdev->vlan_features |= NETIF_F_HW_CSUM;
975 netdev->vlan_features |= NETIF_F_SG;
976
972 if (pci_using_dac) 977 if (pci_using_dac)
973 netdev->features |= NETIF_F_HIGHDMA; 978 netdev->features |= NETIF_F_HIGHDMA;
974 979
diff --git a/drivers/net/ixgbe/ixgbe_main.c b/drivers/net/ixgbe/ixgbe_main.c
index 7b859220c255..0d37c9025be4 100644
--- a/drivers/net/ixgbe/ixgbe_main.c
+++ b/drivers/net/ixgbe/ixgbe_main.c
@@ -3518,8 +3518,13 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
3518 NETIF_F_HW_VLAN_FILTER; 3518 NETIF_F_HW_VLAN_FILTER;
3519 3519
3520 netdev->features |= NETIF_F_TSO; 3520 netdev->features |= NETIF_F_TSO;
3521
3522 netdev->features |= NETIF_F_TSO6; 3521 netdev->features |= NETIF_F_TSO6;
3522
3523 netdev->vlan_features |= NETIF_F_TSO;
3524 netdev->vlan_features |= NETIF_F_TSO6;
3525 netdev->vlan_features |= NETIF_F_HW_CSUM;
3526 netdev->vlan_features |= NETIF_F_SG;
3527
3523 if (pci_using_dac) 3528 if (pci_using_dac)
3524 netdev->features |= NETIF_F_HIGHDMA; 3529 netdev->features |= NETIF_F_HIGHDMA;
3525 3530
diff --git a/drivers/net/lib8390.c b/drivers/net/lib8390.c
index ed495275b577..00d59ab2f8ac 100644
--- a/drivers/net/lib8390.c
+++ b/drivers/net/lib8390.c
@@ -553,6 +553,8 @@ static void __ei_poll(struct net_device *dev)
553static void ei_tx_err(struct net_device *dev) 553static void ei_tx_err(struct net_device *dev)
554{ 554{
555 unsigned long e8390_base = dev->base_addr; 555 unsigned long e8390_base = dev->base_addr;
556 /* ei_local is used on some platforms via the EI_SHIFT macro */
557 struct ei_device *ei_local __maybe_unused = netdev_priv(dev);
556 unsigned char txsr = ei_inb_p(e8390_base+EN0_TSR); 558 unsigned char txsr = ei_inb_p(e8390_base+EN0_TSR);
557 unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU); 559 unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU);
558 560
@@ -815,6 +817,8 @@ static void ei_rx_overrun(struct net_device *dev)
815{ 817{
816 unsigned long e8390_base = dev->base_addr; 818 unsigned long e8390_base = dev->base_addr;
817 unsigned char was_txing, must_resend = 0; 819 unsigned char was_txing, must_resend = 0;
820 /* ei_local is used on some platforms via the EI_SHIFT macro */
821 struct ei_device *ei_local __maybe_unused = netdev_priv(dev);
818 822
819 /* 823 /*
820 * Record whether a Tx was in progress and then issue the 824 * Record whether a Tx was in progress and then issue the
diff --git a/drivers/net/mac8390.c b/drivers/net/mac8390.c
index 9e700749bb31..98e3eb2697c9 100644
--- a/drivers/net/mac8390.c
+++ b/drivers/net/mac8390.c
@@ -117,8 +117,6 @@ enum mac8390_access {
117 ACCESS_16, 117 ACCESS_16,
118}; 118};
119 119
120extern enum mac8390_type mac8390_ident(struct nubus_dev * dev);
121extern int mac8390_memsize(unsigned long membase);
122extern int mac8390_memtest(struct net_device * dev); 120extern int mac8390_memtest(struct net_device * dev);
123static int mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev, 121static int mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
124 enum mac8390_type type); 122 enum mac8390_type type);
@@ -163,7 +161,7 @@ static void slow_sane_block_output(struct net_device *dev, int count,
163static void word_memcpy_tocard(void *tp, const void *fp, int count); 161static void word_memcpy_tocard(void *tp, const void *fp, int count);
164static void word_memcpy_fromcard(void *tp, const void *fp, int count); 162static void word_memcpy_fromcard(void *tp, const void *fp, int count);
165 163
166enum mac8390_type __init mac8390_ident(struct nubus_dev * dev) 164static enum mac8390_type __init mac8390_ident(struct nubus_dev *dev)
167{ 165{
168 switch (dev->dr_sw) { 166 switch (dev->dr_sw) {
169 case NUBUS_DRSW_3COM: 167 case NUBUS_DRSW_3COM:
@@ -234,7 +232,7 @@ enum mac8390_type __init mac8390_ident(struct nubus_dev * dev)
234 return MAC8390_NONE; 232 return MAC8390_NONE;
235} 233}
236 234
237enum mac8390_access __init mac8390_testio(volatile unsigned long membase) 235static enum mac8390_access __init mac8390_testio(volatile unsigned long membase)
238{ 236{
239 unsigned long outdata = 0xA5A0B5B0; 237 unsigned long outdata = 0xA5A0B5B0;
240 unsigned long indata = 0x00000000; 238 unsigned long indata = 0x00000000;
@@ -252,7 +250,7 @@ enum mac8390_access __init mac8390_testio(volatile unsigned long membase)
252 return ACCESS_UNKNOWN; 250 return ACCESS_UNKNOWN;
253} 251}
254 252
255int __init mac8390_memsize(unsigned long membase) 253static int __init mac8390_memsize(unsigned long membase)
256{ 254{
257 unsigned long flags; 255 unsigned long flags;
258 int i, j; 256 int i, j;
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 92dccd43bdca..e34630252cef 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -80,8 +80,12 @@ static void __init macb_get_hwaddr(struct macb *bp)
80 addr[4] = top & 0xff; 80 addr[4] = top & 0xff;
81 addr[5] = (top >> 8) & 0xff; 81 addr[5] = (top >> 8) & 0xff;
82 82
83 if (is_valid_ether_addr(addr)) 83 if (is_valid_ether_addr(addr)) {
84 memcpy(bp->dev->dev_addr, addr, sizeof(addr)); 84 memcpy(bp->dev->dev_addr, addr, sizeof(addr));
85 } else {
86 dev_info(&bp->pdev->dev, "invalid hw address, using random\n");
87 random_ether_addr(bp->dev->dev_addr);
88 }
85} 89}
86 90
87static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum) 91static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
diff --git a/drivers/net/macsonic.c b/drivers/net/macsonic.c
index b267161418ea..e64c2086d33c 100644
--- a/drivers/net/macsonic.c
+++ b/drivers/net/macsonic.c
@@ -83,9 +83,6 @@ static unsigned int sonic_debug = 1;
83 83
84static int sonic_version_printed; 84static int sonic_version_printed;
85 85
86extern int mac_onboard_sonic_probe(struct net_device* dev);
87extern int mac_nubus_sonic_probe(struct net_device* dev);
88
89/* For onboard SONIC */ 86/* For onboard SONIC */
90#define ONBOARD_SONIC_REGISTERS 0x50F0A000 87#define ONBOARD_SONIC_REGISTERS 0x50F0A000
91#define ONBOARD_SONIC_PROM_BASE 0x50f08000 88#define ONBOARD_SONIC_PROM_BASE 0x50f08000
@@ -170,7 +167,7 @@ static int macsonic_close(struct net_device* dev)
170 return err; 167 return err;
171} 168}
172 169
173int __init macsonic_init(struct net_device* dev) 170static int __init macsonic_init(struct net_device *dev)
174{ 171{
175 struct sonic_local* lp = netdev_priv(dev); 172 struct sonic_local* lp = netdev_priv(dev);
176 173
@@ -218,7 +215,7 @@ int __init macsonic_init(struct net_device* dev)
218 return 0; 215 return 0;
219} 216}
220 217
221int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev) 218static int __init mac_onboard_sonic_ethernet_addr(struct net_device *dev)
222{ 219{
223 struct sonic_local *lp = netdev_priv(dev); 220 struct sonic_local *lp = netdev_priv(dev);
224 const int prom_addr = ONBOARD_SONIC_PROM_BASE; 221 const int prom_addr = ONBOARD_SONIC_PROM_BASE;
@@ -284,7 +281,7 @@ int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev)
284 } else return 0; 281 } else return 0;
285} 282}
286 283
287int __init mac_onboard_sonic_probe(struct net_device* dev) 284static int __init mac_onboard_sonic_probe(struct net_device *dev)
288{ 285{
289 /* Bwahahaha */ 286 /* Bwahahaha */
290 static int once_is_more_than_enough; 287 static int once_is_more_than_enough;
@@ -405,9 +402,9 @@ int __init mac_onboard_sonic_probe(struct net_device* dev)
405 return macsonic_init(dev); 402 return macsonic_init(dev);
406} 403}
407 404
408int __init mac_nubus_sonic_ethernet_addr(struct net_device* dev, 405static int __init mac_nubus_sonic_ethernet_addr(struct net_device *dev,
409 unsigned long prom_addr, 406 unsigned long prom_addr,
410 int id) 407 int id)
411{ 408{
412 int i; 409 int i;
413 for(i = 0; i < 6; i++) 410 for(i = 0; i < 6; i++)
@@ -420,7 +417,7 @@ int __init mac_nubus_sonic_ethernet_addr(struct net_device* dev,
420 return 0; 417 return 0;
421} 418}
422 419
423int __init macsonic_ident(struct nubus_dev* ndev) 420static int __init macsonic_ident(struct nubus_dev *ndev)
424{ 421{
425 if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC && 422 if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC &&
426 ndev->dr_sw == NUBUS_DRSW_SONIC_LC) 423 ndev->dr_sw == NUBUS_DRSW_SONIC_LC)
@@ -445,7 +442,7 @@ int __init macsonic_ident(struct nubus_dev* ndev)
445 return -1; 442 return -1;
446} 443}
447 444
448int __init mac_nubus_sonic_probe(struct net_device* dev) 445static int __init mac_nubus_sonic_probe(struct net_device *dev)
449{ 446{
450 static int slots; 447 static int slots;
451 struct nubus_dev* ndev = NULL; 448 struct nubus_dev* ndev = NULL;
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
new file mode 100644
index 000000000000..f64d987140a9
--- /dev/null
+++ b/drivers/net/sh_eth.c
@@ -0,0 +1,1174 @@
1/*
2 * SuperH Ethernet device driver
3 *
4 * Copyright (C) 2006,2007 Nobuhiro Iwamatsu
5 * Copyright (C) 2008 Renesas Solutions Corp.
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 * 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
23#include <linux/version.h>
24#include <linux/init.h>
25#include <linux/dma-mapping.h>
26#include <linux/etherdevice.h>
27#include <linux/delay.h>
28#include <linux/platform_device.h>
29#include <linux/mdio-bitbang.h>
30#include <linux/netdevice.h>
31#include <linux/phy.h>
32#include <linux/cache.h>
33#include <linux/io.h>
34
35#include "sh_eth.h"
36
37/*
38 * Program the hardware MAC address from dev->dev_addr.
39 */
40static void update_mac_address(struct net_device *ndev)
41{
42 u32 ioaddr = ndev->base_addr;
43
44 ctrl_outl((ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) |
45 (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]),
46 ioaddr + MAHR);
47 ctrl_outl((ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]),
48 ioaddr + MALR);
49}
50
51/*
52 * Get MAC address from SuperH MAC address register
53 *
54 * SuperH's Ethernet device doesn't have 'ROM' to MAC address.
55 * This driver get MAC address that use by bootloader(U-boot or sh-ipl+g).
56 * When you want use this device, you must set MAC address in bootloader.
57 *
58 */
59static void read_mac_address(struct net_device *ndev)
60{
61 u32 ioaddr = ndev->base_addr;
62
63 ndev->dev_addr[0] = (ctrl_inl(ioaddr + MAHR) >> 24);
64 ndev->dev_addr[1] = (ctrl_inl(ioaddr + MAHR) >> 16) & 0xFF;
65 ndev->dev_addr[2] = (ctrl_inl(ioaddr + MAHR) >> 8) & 0xFF;
66 ndev->dev_addr[3] = (ctrl_inl(ioaddr + MAHR) & 0xFF);
67 ndev->dev_addr[4] = (ctrl_inl(ioaddr + MALR) >> 8) & 0xFF;
68 ndev->dev_addr[5] = (ctrl_inl(ioaddr + MALR) & 0xFF);
69}
70
71struct bb_info {
72 struct mdiobb_ctrl ctrl;
73 u32 addr;
74 u32 mmd_msk;/* MMD */
75 u32 mdo_msk;
76 u32 mdi_msk;
77 u32 mdc_msk;
78};
79
80/* PHY bit set */
81static void bb_set(u32 addr, u32 msk)
82{
83 ctrl_outl(ctrl_inl(addr) | msk, addr);
84}
85
86/* PHY bit clear */
87static void bb_clr(u32 addr, u32 msk)
88{
89 ctrl_outl((ctrl_inl(addr) & ~msk), addr);
90}
91
92/* PHY bit read */
93static int bb_read(u32 addr, u32 msk)
94{
95 return (ctrl_inl(addr) & msk) != 0;
96}
97
98/* Data I/O pin control */
99static void sh_mmd_ctrl(struct mdiobb_ctrl *ctrl, int bit)
100{
101 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
102 if (bit)
103 bb_set(bitbang->addr, bitbang->mmd_msk);
104 else
105 bb_clr(bitbang->addr, bitbang->mmd_msk);
106}
107
108/* Set bit data*/
109static void sh_set_mdio(struct mdiobb_ctrl *ctrl, int bit)
110{
111 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
112
113 if (bit)
114 bb_set(bitbang->addr, bitbang->mdo_msk);
115 else
116 bb_clr(bitbang->addr, bitbang->mdo_msk);
117}
118
119/* Get bit data*/
120static int sh_get_mdio(struct mdiobb_ctrl *ctrl)
121{
122 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
123 return bb_read(bitbang->addr, bitbang->mdi_msk);
124}
125
126/* MDC pin control */
127static void sh_mdc_ctrl(struct mdiobb_ctrl *ctrl, int bit)
128{
129 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
130
131 if (bit)
132 bb_set(bitbang->addr, bitbang->mdc_msk);
133 else
134 bb_clr(bitbang->addr, bitbang->mdc_msk);
135}
136
137/* mdio bus control struct */
138static struct mdiobb_ops bb_ops = {
139 .owner = THIS_MODULE,
140 .set_mdc = sh_mdc_ctrl,
141 .set_mdio_dir = sh_mmd_ctrl,
142 .set_mdio_data = sh_set_mdio,
143 .get_mdio_data = sh_get_mdio,
144};
145
146static void sh_eth_reset(struct net_device *ndev)
147{
148 u32 ioaddr = ndev->base_addr;
149
150 ctrl_outl(ctrl_inl(ioaddr + EDMR) | EDMR_SRST, ioaddr + EDMR);
151 mdelay(3);
152 ctrl_outl(ctrl_inl(ioaddr + EDMR) & ~EDMR_SRST, ioaddr + EDMR);
153}
154
155/* free skb and descriptor buffer */
156static void sh_eth_ring_free(struct net_device *ndev)
157{
158 struct sh_eth_private *mdp = netdev_priv(ndev);
159 int i;
160
161 /* Free Rx skb ringbuffer */
162 if (mdp->rx_skbuff) {
163 for (i = 0; i < RX_RING_SIZE; i++) {
164 if (mdp->rx_skbuff[i])
165 dev_kfree_skb(mdp->rx_skbuff[i]);
166 }
167 }
168 kfree(mdp->rx_skbuff);
169
170 /* Free Tx skb ringbuffer */
171 if (mdp->tx_skbuff) {
172 for (i = 0; i < TX_RING_SIZE; i++) {
173 if (mdp->tx_skbuff[i])
174 dev_kfree_skb(mdp->tx_skbuff[i]);
175 }
176 }
177 kfree(mdp->tx_skbuff);
178}
179
180/* format skb and descriptor buffer */
181static void sh_eth_ring_format(struct net_device *ndev)
182{
183 struct sh_eth_private *mdp = netdev_priv(ndev);
184 int i;
185 struct sk_buff *skb;
186 struct sh_eth_rxdesc *rxdesc = NULL;
187 struct sh_eth_txdesc *txdesc = NULL;
188 int rx_ringsize = sizeof(*rxdesc) * RX_RING_SIZE;
189 int tx_ringsize = sizeof(*txdesc) * TX_RING_SIZE;
190
191 mdp->cur_rx = mdp->cur_tx = 0;
192 mdp->dirty_rx = mdp->dirty_tx = 0;
193
194 memset(mdp->rx_ring, 0, rx_ringsize);
195
196 /* build Rx ring buffer */
197 for (i = 0; i < RX_RING_SIZE; i++) {
198 /* skb */
199 mdp->rx_skbuff[i] = NULL;
200 skb = dev_alloc_skb(mdp->rx_buf_sz);
201 mdp->rx_skbuff[i] = skb;
202 if (skb == NULL)
203 break;
204 skb->dev = ndev; /* Mark as being used by this device. */
205 skb_reserve(skb, RX_OFFSET);
206
207 /* RX descriptor */
208 rxdesc = &mdp->rx_ring[i];
209 rxdesc->addr = (u32)skb->data & ~0x3UL;
210 rxdesc->status = cpu_to_le32(RD_RACT | RD_RFP);
211
212 /* The size of the buffer is 16 byte boundary. */
213 rxdesc->buffer_length = (mdp->rx_buf_sz + 16) & ~0x0F;
214 }
215
216 mdp->dirty_rx = (u32) (i - RX_RING_SIZE);
217
218 /* Mark the last entry as wrapping the ring. */
219 rxdesc->status |= cpu_to_le32(RC_RDEL);
220
221 memset(mdp->tx_ring, 0, tx_ringsize);
222
223 /* build Tx ring buffer */
224 for (i = 0; i < TX_RING_SIZE; i++) {
225 mdp->tx_skbuff[i] = NULL;
226 txdesc = &mdp->tx_ring[i];
227 txdesc->status = cpu_to_le32(TD_TFP);
228 txdesc->buffer_length = 0;
229 }
230
231 txdesc->status |= cpu_to_le32(TD_TDLE);
232}
233
234/* Get skb and descriptor buffer */
235static int sh_eth_ring_init(struct net_device *ndev)
236{
237 struct sh_eth_private *mdp = netdev_priv(ndev);
238 int rx_ringsize, tx_ringsize, ret = 0;
239
240 /*
241 * +26 gets the maximum ethernet encapsulation, +7 & ~7 because the
242 * card needs room to do 8 byte alignment, +2 so we can reserve
243 * the first 2 bytes, and +16 gets room for the status word from the
244 * card.
245 */
246 mdp->rx_buf_sz = (ndev->mtu <= 1492 ? PKT_BUF_SZ :
247 (((ndev->mtu + 26 + 7) & ~7) + 2 + 16));
248
249 /* Allocate RX and TX skb rings */
250 mdp->rx_skbuff = kmalloc(sizeof(*mdp->rx_skbuff) * RX_RING_SIZE,
251 GFP_KERNEL);
252 if (!mdp->rx_skbuff) {
253 printk(KERN_ERR "%s: Cannot allocate Rx skb\n", ndev->name);
254 ret = -ENOMEM;
255 return ret;
256 }
257
258 mdp->tx_skbuff = kmalloc(sizeof(*mdp->tx_skbuff) * TX_RING_SIZE,
259 GFP_KERNEL);
260 if (!mdp->tx_skbuff) {
261 printk(KERN_ERR "%s: Cannot allocate Tx skb\n", ndev->name);
262 ret = -ENOMEM;
263 goto skb_ring_free;
264 }
265
266 /* Allocate all Rx descriptors. */
267 rx_ringsize = sizeof(struct sh_eth_rxdesc) * RX_RING_SIZE;
268 mdp->rx_ring = dma_alloc_coherent(NULL, rx_ringsize, &mdp->rx_desc_dma,
269 GFP_KERNEL);
270
271 if (!mdp->rx_ring) {
272 printk(KERN_ERR "%s: Cannot allocate Rx Ring (size %d bytes)\n",
273 ndev->name, rx_ringsize);
274 ret = -ENOMEM;
275 goto desc_ring_free;
276 }
277
278 mdp->dirty_rx = 0;
279
280 /* Allocate all Tx descriptors. */
281 tx_ringsize = sizeof(struct sh_eth_txdesc) * TX_RING_SIZE;
282 mdp->tx_ring = dma_alloc_coherent(NULL, tx_ringsize, &mdp->tx_desc_dma,
283 GFP_KERNEL);
284 if (!mdp->tx_ring) {
285 printk(KERN_ERR "%s: Cannot allocate Tx Ring (size %d bytes)\n",
286 ndev->name, tx_ringsize);
287 ret = -ENOMEM;
288 goto desc_ring_free;
289 }
290 return ret;
291
292desc_ring_free:
293 /* free DMA buffer */
294 dma_free_coherent(NULL, rx_ringsize, mdp->rx_ring, mdp->rx_desc_dma);
295
296skb_ring_free:
297 /* Free Rx and Tx skb ring buffer */
298 sh_eth_ring_free(ndev);
299
300 return ret;
301}
302
303static int sh_eth_dev_init(struct net_device *ndev)
304{
305 int ret = 0;
306 struct sh_eth_private *mdp = netdev_priv(ndev);
307 u32 ioaddr = ndev->base_addr;
308 u_int32_t rx_int_var, tx_int_var;
309 u32 val;
310
311 /* Soft Reset */
312 sh_eth_reset(ndev);
313
314 ctrl_outl(RPADIR_PADS1, ioaddr + RPADIR); /* SH7712-DMA-RX-PAD2 */
315
316 /* all sh_eth int mask */
317 ctrl_outl(0, ioaddr + EESIPR);
318
319 /* FIFO size set */
320 ctrl_outl(0, ioaddr + EDMR); /* Endian change */
321
322 ctrl_outl((FIFO_SIZE_T | FIFO_SIZE_R), ioaddr + FDR);
323 ctrl_outl(0, ioaddr + TFTR);
324
325 ctrl_outl(RMCR_RST, ioaddr + RMCR);
326
327 rx_int_var = mdp->rx_int_var = DESC_I_RINT8 | DESC_I_RINT5;
328 tx_int_var = mdp->tx_int_var = DESC_I_TINT2;
329 ctrl_outl(rx_int_var | tx_int_var, ioaddr + TRSCER);
330
331 ctrl_outl((FIFO_F_D_RFF | FIFO_F_D_RFD), ioaddr + FCFTR);
332 ctrl_outl(0, ioaddr + TRIMD);
333
334 /* Descriptor format */
335 sh_eth_ring_format(ndev);
336
337 ctrl_outl((u32)mdp->rx_ring, ioaddr + RDLAR);
338 ctrl_outl((u32)mdp->tx_ring, ioaddr + TDLAR);
339
340 ctrl_outl(ctrl_inl(ioaddr + EESR), ioaddr + EESR);
341 ctrl_outl((DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff), ioaddr + EESIPR);
342
343 /* PAUSE Prohibition */
344 val = (ctrl_inl(ioaddr + ECMR) & ECMR_DM) |
345 ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) | ECMR_TE | ECMR_RE;
346
347 ctrl_outl(val, ioaddr + ECMR);
348 ctrl_outl(ECSR_BRCRX | ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD |
349 ECSIPR_MPDIP, ioaddr + ECSR);
350 ctrl_outl(ECSIPR_BRCRXIP | ECSIPR_PSRTOIP | ECSIPR_LCHNGIP |
351 ECSIPR_ICDIP | ECSIPR_MPDIP, ioaddr + ECSIPR);
352
353 /* Set MAC address */
354 update_mac_address(ndev);
355
356 /* mask reset */
357#if defined(CONFIG_CPU_SUBTYPE_SH7710)
358 ctrl_outl(APR_AP, ioaddr + APR);
359 ctrl_outl(MPR_MP, ioaddr + MPR);
360 ctrl_outl(TPAUSER_UNLIMITED, ioaddr + TPAUSER);
361 ctrl_outl(BCFR_UNLIMITED, ioaddr + BCFR);
362#endif
363 /* Setting the Rx mode will start the Rx process. */
364 ctrl_outl(EDRRR_R, ioaddr + EDRRR);
365
366 netif_start_queue(ndev);
367
368 return ret;
369}
370
371/* free Tx skb function */
372static int sh_eth_txfree(struct net_device *ndev)
373{
374 struct sh_eth_private *mdp = netdev_priv(ndev);
375 struct sh_eth_txdesc *txdesc;
376 int freeNum = 0;
377 int entry = 0;
378
379 for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) {
380 entry = mdp->dirty_tx % TX_RING_SIZE;
381 txdesc = &mdp->tx_ring[entry];
382 if (txdesc->status & cpu_to_le32(TD_TACT))
383 break;
384 /* Free the original skb. */
385 if (mdp->tx_skbuff[entry]) {
386 dev_kfree_skb_irq(mdp->tx_skbuff[entry]);
387 mdp->tx_skbuff[entry] = NULL;
388 freeNum++;
389 }
390 txdesc->status = cpu_to_le32(TD_TFP);
391 if (entry >= TX_RING_SIZE - 1)
392 txdesc->status |= cpu_to_le32(TD_TDLE);
393
394 mdp->stats.tx_packets++;
395 mdp->stats.tx_bytes += txdesc->buffer_length;
396 }
397 return freeNum;
398}
399
400/* Packet receive function */
401static int sh_eth_rx(struct net_device *ndev)
402{
403 struct sh_eth_private *mdp = netdev_priv(ndev);
404 struct sh_eth_rxdesc *rxdesc;
405
406 int entry = mdp->cur_rx % RX_RING_SIZE;
407 int boguscnt = (mdp->dirty_rx + RX_RING_SIZE) - mdp->cur_rx;
408 struct sk_buff *skb;
409 u16 pkt_len = 0;
410 u32 desc_status;
411
412 rxdesc = &mdp->rx_ring[entry];
413 while (!(rxdesc->status & cpu_to_le32(RD_RACT))) {
414 desc_status = le32_to_cpu(rxdesc->status);
415 pkt_len = rxdesc->frame_length;
416
417 if (--boguscnt < 0)
418 break;
419
420 if (!(desc_status & RDFEND))
421 mdp->stats.rx_length_errors++;
422
423 if (desc_status & (RD_RFS1 | RD_RFS2 | RD_RFS3 | RD_RFS4 |
424 RD_RFS5 | RD_RFS6 | RD_RFS10)) {
425 mdp->stats.rx_errors++;
426 if (desc_status & RD_RFS1)
427 mdp->stats.rx_crc_errors++;
428 if (desc_status & RD_RFS2)
429 mdp->stats.rx_frame_errors++;
430 if (desc_status & RD_RFS3)
431 mdp->stats.rx_length_errors++;
432 if (desc_status & RD_RFS4)
433 mdp->stats.rx_length_errors++;
434 if (desc_status & RD_RFS6)
435 mdp->stats.rx_missed_errors++;
436 if (desc_status & RD_RFS10)
437 mdp->stats.rx_over_errors++;
438 } else {
439 swaps((char *)(rxdesc->addr & ~0x3), pkt_len + 2);
440 skb = mdp->rx_skbuff[entry];
441 mdp->rx_skbuff[entry] = NULL;
442 skb_put(skb, pkt_len);
443 skb->protocol = eth_type_trans(skb, ndev);
444 netif_rx(skb);
445 ndev->last_rx = jiffies;
446 mdp->stats.rx_packets++;
447 mdp->stats.rx_bytes += pkt_len;
448 }
449 rxdesc->status |= cpu_to_le32(RD_RACT);
450 entry = (++mdp->cur_rx) % RX_RING_SIZE;
451 }
452
453 /* Refill the Rx ring buffers. */
454 for (; mdp->cur_rx - mdp->dirty_rx > 0; mdp->dirty_rx++) {
455 entry = mdp->dirty_rx % RX_RING_SIZE;
456 rxdesc = &mdp->rx_ring[entry];
457 if (mdp->rx_skbuff[entry] == NULL) {
458 skb = dev_alloc_skb(mdp->rx_buf_sz);
459 mdp->rx_skbuff[entry] = skb;
460 if (skb == NULL)
461 break; /* Better luck next round. */
462 skb->dev = ndev;
463 skb_reserve(skb, RX_OFFSET);
464 rxdesc->addr = (u32)skb->data & ~0x3UL;
465 }
466 /* The size of the buffer is 16 byte boundary. */
467 rxdesc->buffer_length = (mdp->rx_buf_sz + 16) & ~0x0F;
468 if (entry >= RX_RING_SIZE - 1)
469 rxdesc->status |=
470 cpu_to_le32(RD_RACT | RD_RFP | RC_RDEL);
471 else
472 rxdesc->status |=
473 cpu_to_le32(RD_RACT | RD_RFP);
474 }
475
476 /* Restart Rx engine if stopped. */
477 /* If we don't need to check status, don't. -KDU */
478 ctrl_outl(EDRRR_R, ndev->base_addr + EDRRR);
479
480 return 0;
481}
482
483/* error control function */
484static void sh_eth_error(struct net_device *ndev, int intr_status)
485{
486 struct sh_eth_private *mdp = netdev_priv(ndev);
487 u32 ioaddr = ndev->base_addr;
488 u32 felic_stat;
489
490 if (intr_status & EESR_ECI) {
491 felic_stat = ctrl_inl(ioaddr + ECSR);
492 ctrl_outl(felic_stat, ioaddr + ECSR); /* clear int */
493 if (felic_stat & ECSR_ICD)
494 mdp->stats.tx_carrier_errors++;
495 if (felic_stat & ECSR_LCHNG) {
496 /* Link Changed */
497 u32 link_stat = (ctrl_inl(ioaddr + PSR));
498 if (!(link_stat & PHY_ST_LINK)) {
499 /* Link Down : disable tx and rx */
500 ctrl_outl(ctrl_inl(ioaddr + ECMR) &
501 ~(ECMR_RE | ECMR_TE), ioaddr + ECMR);
502 } else {
503 /* Link Up */
504 ctrl_outl(ctrl_inl(ioaddr + EESIPR) &
505 ~DMAC_M_ECI, ioaddr + EESIPR);
506 /*clear int */
507 ctrl_outl(ctrl_inl(ioaddr + ECSR),
508 ioaddr + ECSR);
509 ctrl_outl(ctrl_inl(ioaddr + EESIPR) |
510 DMAC_M_ECI, ioaddr + EESIPR);
511 /* enable tx and rx */
512 ctrl_outl(ctrl_inl(ioaddr + ECMR) |
513 (ECMR_RE | ECMR_TE), ioaddr + ECMR);
514 }
515 }
516 }
517
518 if (intr_status & EESR_TWB) {
519 /* Write buck end. unused write back interrupt */
520 if (intr_status & EESR_TABT) /* Transmit Abort int */
521 mdp->stats.tx_aborted_errors++;
522 }
523
524 if (intr_status & EESR_RABT) {
525 /* Receive Abort int */
526 if (intr_status & EESR_RFRMER) {
527 /* Receive Frame Overflow int */
528 mdp->stats.rx_frame_errors++;
529 printk(KERN_ERR "Receive Frame Overflow\n");
530 }
531 }
532
533 if (intr_status & EESR_ADE) {
534 if (intr_status & EESR_TDE) {
535 if (intr_status & EESR_TFE)
536 mdp->stats.tx_fifo_errors++;
537 }
538 }
539
540 if (intr_status & EESR_RDE) {
541 /* Receive Descriptor Empty int */
542 mdp->stats.rx_over_errors++;
543
544 if (ctrl_inl(ioaddr + EDRRR) ^ EDRRR_R)
545 ctrl_outl(EDRRR_R, ioaddr + EDRRR);
546 printk(KERN_ERR "Receive Descriptor Empty\n");
547 }
548 if (intr_status & EESR_RFE) {
549 /* Receive FIFO Overflow int */
550 mdp->stats.rx_fifo_errors++;
551 printk(KERN_ERR "Receive FIFO Overflow\n");
552 }
553 if (intr_status &
554 (EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE)) {
555 /* Tx error */
556 u32 edtrr = ctrl_inl(ndev->base_addr + EDTRR);
557 /* dmesg */
558 printk(KERN_ERR "%s:TX error. status=%8.8x cur_tx=%8.8x ",
559 ndev->name, intr_status, mdp->cur_tx);
560 printk(KERN_ERR "dirty_tx=%8.8x state=%8.8x EDTRR=%8.8x.\n",
561 mdp->dirty_tx, (u32) ndev->state, edtrr);
562 /* dirty buffer free */
563 sh_eth_txfree(ndev);
564
565 /* SH7712 BUG */
566 if (edtrr ^ EDTRR_TRNS) {
567 /* tx dma start */
568 ctrl_outl(EDTRR_TRNS, ndev->base_addr + EDTRR);
569 }
570 /* wakeup */
571 netif_wake_queue(ndev);
572 }
573}
574
575static irqreturn_t sh_eth_interrupt(int irq, void *netdev)
576{
577 struct net_device *ndev = netdev;
578 struct sh_eth_private *mdp = netdev_priv(ndev);
579 u32 ioaddr, boguscnt = RX_RING_SIZE;
580 u32 intr_status = 0;
581
582 ioaddr = ndev->base_addr;
583 spin_lock(&mdp->lock);
584
585 intr_status = ctrl_inl(ioaddr + EESR);
586 /* Clear interrupt */
587 ctrl_outl(intr_status, ioaddr + EESR);
588
589 if (intr_status & (EESR_FRC | EESR_RINT8 |
590 EESR_RINT5 | EESR_RINT4 | EESR_RINT3 | EESR_RINT2 |
591 EESR_RINT1))
592 sh_eth_rx(ndev);
593 if (intr_status & (EESR_FTC |
594 EESR_TINT4 | EESR_TINT3 | EESR_TINT2 | EESR_TINT1)) {
595
596 sh_eth_txfree(ndev);
597 netif_wake_queue(ndev);
598 }
599
600 if (intr_status & EESR_ERR_CHECK)
601 sh_eth_error(ndev, intr_status);
602
603 if (--boguscnt < 0) {
604 printk(KERN_WARNING
605 "%s: Too much work at interrupt, status=0x%4.4x.\n",
606 ndev->name, intr_status);
607 }
608
609 spin_unlock(&mdp->lock);
610
611 return IRQ_HANDLED;
612}
613
614static void sh_eth_timer(unsigned long data)
615{
616 struct net_device *ndev = (struct net_device *)data;
617 struct sh_eth_private *mdp = netdev_priv(ndev);
618
619 mod_timer(&mdp->timer, jiffies + (10 * HZ));
620}
621
622/* PHY state control function */
623static void sh_eth_adjust_link(struct net_device *ndev)
624{
625 struct sh_eth_private *mdp = netdev_priv(ndev);
626 struct phy_device *phydev = mdp->phydev;
627 u32 ioaddr = ndev->base_addr;
628 int new_state = 0;
629
630 if (phydev->link != PHY_DOWN) {
631 if (phydev->duplex != mdp->duplex) {
632 new_state = 1;
633 mdp->duplex = phydev->duplex;
634 }
635
636 if (phydev->speed != mdp->speed) {
637 new_state = 1;
638 mdp->speed = phydev->speed;
639 }
640 if (mdp->link == PHY_DOWN) {
641 ctrl_outl((ctrl_inl(ioaddr + ECMR) & ~ECMR_TXF)
642 | ECMR_DM, ioaddr + ECMR);
643 new_state = 1;
644 mdp->link = phydev->link;
645 netif_schedule(ndev);
646 netif_carrier_on(ndev);
647 netif_start_queue(ndev);
648 }
649 } else if (mdp->link) {
650 new_state = 1;
651 mdp->link = PHY_DOWN;
652 mdp->speed = 0;
653 mdp->duplex = -1;
654 netif_stop_queue(ndev);
655 netif_carrier_off(ndev);
656 }
657
658 if (new_state)
659 phy_print_status(phydev);
660}
661
662/* PHY init function */
663static int sh_eth_phy_init(struct net_device *ndev)
664{
665 struct sh_eth_private *mdp = netdev_priv(ndev);
666 char phy_id[BUS_ID_SIZE];
667 struct phy_device *phydev = NULL;
668
669 snprintf(phy_id, BUS_ID_SIZE, PHY_ID_FMT,
670 mdp->mii_bus->id , mdp->phy_id);
671
672 mdp->link = PHY_DOWN;
673 mdp->speed = 0;
674 mdp->duplex = -1;
675
676 /* Try connect to PHY */
677 phydev = phy_connect(ndev, phy_id, &sh_eth_adjust_link,
678 0, PHY_INTERFACE_MODE_MII);
679 if (IS_ERR(phydev)) {
680 dev_err(&ndev->dev, "phy_connect failed\n");
681 return PTR_ERR(phydev);
682 }
683 dev_info(&ndev->dev, "attached phy %i to driver %s\n",
684 phydev->addr, phydev->drv->name);
685
686 mdp->phydev = phydev;
687
688 return 0;
689}
690
691/* PHY control start function */
692static int sh_eth_phy_start(struct net_device *ndev)
693{
694 struct sh_eth_private *mdp = netdev_priv(ndev);
695 int ret;
696
697 ret = sh_eth_phy_init(ndev);
698 if (ret)
699 return ret;
700
701 /* reset phy - this also wakes it from PDOWN */
702 phy_write(mdp->phydev, MII_BMCR, BMCR_RESET);
703 phy_start(mdp->phydev);
704
705 return 0;
706}
707
708/* network device open function */
709static int sh_eth_open(struct net_device *ndev)
710{
711 int ret = 0;
712 struct sh_eth_private *mdp = netdev_priv(ndev);
713
714 ret = request_irq(ndev->irq, &sh_eth_interrupt, 0, ndev->name, ndev);
715 if (ret) {
716 printk(KERN_ERR "Can not assign IRQ number to %s\n", CARDNAME);
717 return ret;
718 }
719
720 /* Descriptor set */
721 ret = sh_eth_ring_init(ndev);
722 if (ret)
723 goto out_free_irq;
724
725 /* device init */
726 ret = sh_eth_dev_init(ndev);
727 if (ret)
728 goto out_free_irq;
729
730 /* PHY control start*/
731 ret = sh_eth_phy_start(ndev);
732 if (ret)
733 goto out_free_irq;
734
735 /* Set the timer to check for link beat. */
736 init_timer(&mdp->timer);
737 mdp->timer.expires = (jiffies + (24 * HZ)) / 10;/* 2.4 sec. */
738 setup_timer(&mdp->timer, sh_eth_timer, ndev);
739
740 return ret;
741
742out_free_irq:
743 free_irq(ndev->irq, ndev);
744 return ret;
745}
746
747/* Timeout function */
748static void sh_eth_tx_timeout(struct net_device *ndev)
749{
750 struct sh_eth_private *mdp = netdev_priv(ndev);
751 u32 ioaddr = ndev->base_addr;
752 struct sh_eth_rxdesc *rxdesc;
753 int i;
754
755 netif_stop_queue(ndev);
756
757 /* worning message out. */
758 printk(KERN_WARNING "%s: transmit timed out, status %8.8x,"
759 " resetting...\n", ndev->name, (int)ctrl_inl(ioaddr + EESR));
760
761 /* tx_errors count up */
762 mdp->stats.tx_errors++;
763
764 /* timer off */
765 del_timer_sync(&mdp->timer);
766
767 /* Free all the skbuffs in the Rx queue. */
768 for (i = 0; i < RX_RING_SIZE; i++) {
769 rxdesc = &mdp->rx_ring[i];
770 rxdesc->status = 0;
771 rxdesc->addr = 0xBADF00D0;
772 if (mdp->rx_skbuff[i])
773 dev_kfree_skb(mdp->rx_skbuff[i]);
774 mdp->rx_skbuff[i] = NULL;
775 }
776 for (i = 0; i < TX_RING_SIZE; i++) {
777 if (mdp->tx_skbuff[i])
778 dev_kfree_skb(mdp->tx_skbuff[i]);
779 mdp->tx_skbuff[i] = NULL;
780 }
781
782 /* device init */
783 sh_eth_dev_init(ndev);
784
785 /* timer on */
786 mdp->timer.expires = (jiffies + (24 * HZ)) / 10;/* 2.4 sec. */
787 add_timer(&mdp->timer);
788}
789
790/* Packet transmit function */
791static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
792{
793 struct sh_eth_private *mdp = netdev_priv(ndev);
794 struct sh_eth_txdesc *txdesc;
795 u32 entry;
796 int flags;
797
798 spin_lock_irqsave(&mdp->lock, flags);
799 if ((mdp->cur_tx - mdp->dirty_tx) >= (TX_RING_SIZE - 4)) {
800 if (!sh_eth_txfree(ndev)) {
801 netif_stop_queue(ndev);
802 spin_unlock_irqrestore(&mdp->lock, flags);
803 return 1;
804 }
805 }
806 spin_unlock_irqrestore(&mdp->lock, flags);
807
808 entry = mdp->cur_tx % TX_RING_SIZE;
809 mdp->tx_skbuff[entry] = skb;
810 txdesc = &mdp->tx_ring[entry];
811 txdesc->addr = (u32)(skb->data);
812 /* soft swap. */
813 swaps((char *)(txdesc->addr & ~0x3), skb->len + 2);
814 /* write back */
815 __flush_purge_region(skb->data, skb->len);
816 if (skb->len < ETHERSMALL)
817 txdesc->buffer_length = ETHERSMALL;
818 else
819 txdesc->buffer_length = skb->len;
820
821 if (entry >= TX_RING_SIZE - 1)
822 txdesc->status |= cpu_to_le32(TD_TACT | TD_TDLE);
823 else
824 txdesc->status |= cpu_to_le32(TD_TACT);
825
826 mdp->cur_tx++;
827
828 ctrl_outl(EDTRR_TRNS, ndev->base_addr + EDTRR);
829 ndev->trans_start = jiffies;
830
831 return 0;
832}
833
834/* device close function */
835static int sh_eth_close(struct net_device *ndev)
836{
837 struct sh_eth_private *mdp = netdev_priv(ndev);
838 u32 ioaddr = ndev->base_addr;
839 int ringsize;
840
841 netif_stop_queue(ndev);
842
843 /* Disable interrupts by clearing the interrupt mask. */
844 ctrl_outl(0x0000, ioaddr + EESIPR);
845
846 /* Stop the chip's Tx and Rx processes. */
847 ctrl_outl(0, ioaddr + EDTRR);
848 ctrl_outl(0, ioaddr + EDRRR);
849
850 /* PHY Disconnect */
851 if (mdp->phydev) {
852 phy_stop(mdp->phydev);
853 phy_disconnect(mdp->phydev);
854 }
855
856 free_irq(ndev->irq, ndev);
857
858 del_timer_sync(&mdp->timer);
859
860 /* Free all the skbuffs in the Rx queue. */
861 sh_eth_ring_free(ndev);
862
863 /* free DMA buffer */
864 ringsize = sizeof(struct sh_eth_rxdesc) * RX_RING_SIZE;
865 dma_free_coherent(NULL, ringsize, mdp->rx_ring, mdp->rx_desc_dma);
866
867 /* free DMA buffer */
868 ringsize = sizeof(struct sh_eth_txdesc) * TX_RING_SIZE;
869 dma_free_coherent(NULL, ringsize, mdp->tx_ring, mdp->tx_desc_dma);
870
871 return 0;
872}
873
874static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
875{
876 struct sh_eth_private *mdp = netdev_priv(ndev);
877 u32 ioaddr = ndev->base_addr;
878
879 mdp->stats.tx_dropped += ctrl_inl(ioaddr + TROCR);
880 ctrl_outl(0, ioaddr + TROCR); /* (write clear) */
881 mdp->stats.collisions += ctrl_inl(ioaddr + CDCR);
882 ctrl_outl(0, ioaddr + CDCR); /* (write clear) */
883 mdp->stats.tx_carrier_errors += ctrl_inl(ioaddr + LCCR);
884 ctrl_outl(0, ioaddr + LCCR); /* (write clear) */
885 mdp->stats.tx_carrier_errors += ctrl_inl(ioaddr + CNDCR);
886 ctrl_outl(0, ioaddr + CNDCR); /* (write clear) */
887
888 return &mdp->stats;
889}
890
891/* ioctl to device funciotn*/
892static int sh_eth_do_ioctl(struct net_device *ndev, struct ifreq *rq,
893 int cmd)
894{
895 struct sh_eth_private *mdp = netdev_priv(ndev);
896 struct phy_device *phydev = mdp->phydev;
897
898 if (!netif_running(ndev))
899 return -EINVAL;
900
901 if (!phydev)
902 return -ENODEV;
903
904 return phy_mii_ioctl(phydev, if_mii(rq), cmd);
905}
906
907
908/* Multicast reception directions set */
909static void sh_eth_set_multicast_list(struct net_device *ndev)
910{
911 u32 ioaddr = ndev->base_addr;
912
913 if (ndev->flags & IFF_PROMISC) {
914 /* Set promiscuous. */
915 ctrl_outl((ctrl_inl(ioaddr + ECMR) & ~ECMR_MCT) | ECMR_PRM,
916 ioaddr + ECMR);
917 } else {
918 /* Normal, unicast/broadcast-only mode. */
919 ctrl_outl((ctrl_inl(ioaddr + ECMR) & ~ECMR_PRM) | ECMR_MCT,
920 ioaddr + ECMR);
921 }
922}
923
924/* SuperH's TSU register init function */
925static void sh_eth_tsu_init(u32 ioaddr)
926{
927 ctrl_outl(0, ioaddr + TSU_FWEN0); /* Disable forward(0->1) */
928 ctrl_outl(0, ioaddr + TSU_FWEN1); /* Disable forward(1->0) */
929 ctrl_outl(0, ioaddr + TSU_FCM); /* forward fifo 3k-3k */
930 ctrl_outl(0xc, ioaddr + TSU_BSYSL0);
931 ctrl_outl(0xc, ioaddr + TSU_BSYSL1);
932 ctrl_outl(0, ioaddr + TSU_PRISL0);
933 ctrl_outl(0, ioaddr + TSU_PRISL1);
934 ctrl_outl(0, ioaddr + TSU_FWSL0);
935 ctrl_outl(0, ioaddr + TSU_FWSL1);
936 ctrl_outl(TSU_FWSLC_POSTENU | TSU_FWSLC_POSTENL, ioaddr + TSU_FWSLC);
937 ctrl_outl(0, ioaddr + TSU_QTAGM0); /* Disable QTAG(0->1) */
938 ctrl_outl(0, ioaddr + TSU_QTAGM1); /* Disable QTAG(1->0) */
939 ctrl_outl(0, ioaddr + TSU_FWSR); /* all interrupt status clear */
940 ctrl_outl(0, ioaddr + TSU_FWINMK); /* Disable all interrupt */
941 ctrl_outl(0, ioaddr + TSU_TEN); /* Disable all CAM entry */
942 ctrl_outl(0, ioaddr + TSU_POST1); /* Disable CAM entry [ 0- 7] */
943 ctrl_outl(0, ioaddr + TSU_POST2); /* Disable CAM entry [ 8-15] */
944 ctrl_outl(0, ioaddr + TSU_POST3); /* Disable CAM entry [16-23] */
945 ctrl_outl(0, ioaddr + TSU_POST4); /* Disable CAM entry [24-31] */
946}
947
948/* MDIO bus release function */
949static int sh_mdio_release(struct net_device *ndev)
950{
951 struct mii_bus *bus = dev_get_drvdata(&ndev->dev);
952
953 /* unregister mdio bus */
954 mdiobus_unregister(bus);
955
956 /* remove mdio bus info from net_device */
957 dev_set_drvdata(&ndev->dev, NULL);
958
959 /* free bitbang info */
960 free_mdio_bitbang(bus);
961
962 return 0;
963}
964
965/* MDIO bus init function */
966static int sh_mdio_init(struct net_device *ndev, int id)
967{
968 int ret, i;
969 struct bb_info *bitbang;
970 struct sh_eth_private *mdp = netdev_priv(ndev);
971
972 /* create bit control struct for PHY */
973 bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
974 if (!bitbang) {
975 ret = -ENOMEM;
976 goto out;
977 }
978
979 /* bitbang init */
980 bitbang->addr = ndev->base_addr + PIR;
981 bitbang->mdi_msk = 0x08;
982 bitbang->mdo_msk = 0x04;
983 bitbang->mmd_msk = 0x02;/* MMD */
984 bitbang->mdc_msk = 0x01;
985 bitbang->ctrl.ops = &bb_ops;
986
987 /* MII contorller setting */
988 mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
989 if (!mdp->mii_bus) {
990 ret = -ENOMEM;
991 goto out_free_bitbang;
992 }
993
994 /* Hook up MII support for ethtool */
995 mdp->mii_bus->name = "sh_mii";
996 mdp->mii_bus->dev = &ndev->dev;
997 mdp->mii_bus->id = id;
998
999 /* PHY IRQ */
1000 mdp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
1001 if (!mdp->mii_bus->irq) {
1002 ret = -ENOMEM;
1003 goto out_free_bus;
1004 }
1005
1006 for (i = 0; i < PHY_MAX_ADDR; i++)
1007 mdp->mii_bus->irq[i] = PHY_POLL;
1008
1009 /* regist mdio bus */
1010 ret = mdiobus_register(mdp->mii_bus);
1011 if (ret)
1012 goto out_free_irq;
1013
1014 dev_set_drvdata(&ndev->dev, mdp->mii_bus);
1015
1016 return 0;
1017
1018out_free_irq:
1019 kfree(mdp->mii_bus->irq);
1020
1021out_free_bus:
1022 kfree(mdp->mii_bus);
1023
1024out_free_bitbang:
1025 kfree(bitbang);
1026
1027out:
1028 return ret;
1029}
1030
1031static int sh_eth_drv_probe(struct platform_device *pdev)
1032{
1033 int ret, i, devno = 0;
1034 struct resource *res;
1035 struct net_device *ndev = NULL;
1036 struct sh_eth_private *mdp;
1037
1038 /* get base addr */
1039 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1040 if (unlikely(res == NULL)) {
1041 dev_err(&pdev->dev, "invalid resource\n");
1042 ret = -EINVAL;
1043 goto out;
1044 }
1045
1046 ndev = alloc_etherdev(sizeof(struct sh_eth_private));
1047 if (!ndev) {
1048 printk(KERN_ERR "%s: could not allocate device.\n", CARDNAME);
1049 ret = -ENOMEM;
1050 goto out;
1051 }
1052
1053 /* The sh Ether-specific entries in the device structure. */
1054 ndev->base_addr = res->start;
1055 devno = pdev->id;
1056 if (devno < 0)
1057 devno = 0;
1058
1059 ndev->dma = -1;
1060 ndev->irq = platform_get_irq(pdev, 0);
1061 if (ndev->irq < 0) {
1062 ret = -ENODEV;
1063 goto out_release;
1064 }
1065
1066 SET_NETDEV_DEV(ndev, &pdev->dev);
1067
1068 /* Fill in the fields of the device structure with ethernet values. */
1069 ether_setup(ndev);
1070
1071 mdp = netdev_priv(ndev);
1072 spin_lock_init(&mdp->lock);
1073
1074 /* get PHY ID */
1075 mdp->phy_id = (int)pdev->dev.platform_data;
1076
1077 /* set function */
1078 ndev->open = sh_eth_open;
1079 ndev->hard_start_xmit = sh_eth_start_xmit;
1080 ndev->stop = sh_eth_close;
1081 ndev->get_stats = sh_eth_get_stats;
1082 ndev->set_multicast_list = sh_eth_set_multicast_list;
1083 ndev->do_ioctl = sh_eth_do_ioctl;
1084 ndev->tx_timeout = sh_eth_tx_timeout;
1085 ndev->watchdog_timeo = TX_TIMEOUT;
1086
1087 mdp->post_rx = POST_RX >> (devno << 1);
1088 mdp->post_fw = POST_FW >> (devno << 1);
1089
1090 /* read and set MAC address */
1091 read_mac_address(ndev);
1092
1093 /* First device only init */
1094 if (!devno) {
1095 /* reset device */
1096 ctrl_outl(ARSTR_ARSTR, ndev->base_addr + ARSTR);
1097 mdelay(1);
1098
1099 /* TSU init (Init only)*/
1100 sh_eth_tsu_init(SH_TSU_ADDR);
1101 }
1102
1103 /* network device register */
1104 ret = register_netdev(ndev);
1105 if (ret)
1106 goto out_release;
1107
1108 /* mdio bus init */
1109 ret = sh_mdio_init(ndev, pdev->id);
1110 if (ret)
1111 goto out_unregister;
1112
1113 /* pritnt device infomation */
1114 printk(KERN_INFO "%s: %s at 0x%x, ",
1115 ndev->name, CARDNAME, (u32) ndev->base_addr);
1116
1117 for (i = 0; i < 5; i++)
1118 printk(KERN_INFO "%2.2x:", ndev->dev_addr[i]);
1119 printk(KERN_INFO "%2.2x, IRQ %d.\n", ndev->dev_addr[i], ndev->irq);
1120
1121 platform_set_drvdata(pdev, ndev);
1122
1123 return ret;
1124
1125out_unregister:
1126 unregister_netdev(ndev);
1127
1128out_release:
1129 /* net_dev free */
1130 if (ndev)
1131 free_netdev(ndev);
1132
1133out:
1134 return ret;
1135}
1136
1137static int sh_eth_drv_remove(struct platform_device *pdev)
1138{
1139 struct net_device *ndev = platform_get_drvdata(pdev);
1140
1141 sh_mdio_release(ndev);
1142 unregister_netdev(ndev);
1143 flush_scheduled_work();
1144
1145 free_netdev(ndev);
1146 platform_set_drvdata(pdev, NULL);
1147
1148 return 0;
1149}
1150
1151static struct platform_driver sh_eth_driver = {
1152 .probe = sh_eth_drv_probe,
1153 .remove = sh_eth_drv_remove,
1154 .driver = {
1155 .name = CARDNAME,
1156 },
1157};
1158
1159static int __init sh_eth_init(void)
1160{
1161 return platform_driver_register(&sh_eth_driver);
1162}
1163
1164static void __exit sh_eth_cleanup(void)
1165{
1166 platform_driver_unregister(&sh_eth_driver);
1167}
1168
1169module_init(sh_eth_init);
1170module_exit(sh_eth_cleanup);
1171
1172MODULE_AUTHOR("Nobuhiro Iwamatsu, Yoshihiro Shimoda");
1173MODULE_DESCRIPTION("Renesas SuperH Ethernet driver");
1174MODULE_LICENSE("GPL v2");
diff --git a/drivers/net/sh_eth.h b/drivers/net/sh_eth.h
new file mode 100644
index 000000000000..ca2db6bb3c61
--- /dev/null
+++ b/drivers/net/sh_eth.h
@@ -0,0 +1,464 @@
1/*
2 * SuperH Ethernet device driver
3 *
4 * Copyright (C) 2006-2008 Nobuhiro Iwamatsu
5 * Copyright (C) 2008 Renesas Solutions Corp.
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 * 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
23#ifndef __SH_ETH_H__
24#define __SH_ETH_H__
25
26#include <linux/module.h>
27#include <linux/kernel.h>
28#include <linux/spinlock.h>
29#include <linux/workqueue.h>
30#include <linux/netdevice.h>
31#include <linux/phy.h>
32
33#define CARDNAME "sh-eth"
34#define TX_TIMEOUT (5*HZ)
35
36#define TX_RING_SIZE 128 /* Tx ring size */
37#define RX_RING_SIZE 128 /* Rx ring size */
38#define RX_OFFSET 2 /* skb offset */
39#define ETHERSMALL 60
40#define PKT_BUF_SZ 1538
41
42/* Chip Base Address */
43#define SH_ETH0_BASE 0xA7000000
44#define SH_ETH1_BASE 0xA7000400
45#define SH_TSU_ADDR 0xA7000804
46
47/* Chip Registers */
48/* E-DMAC */
49#define EDMR 0x0000
50#define EDTRR 0x0004
51#define EDRRR 0x0008
52#define TDLAR 0x000C
53#define RDLAR 0x0010
54#define EESR 0x0014
55#define EESIPR 0x0018
56#define TRSCER 0x001C
57#define RMFCR 0x0020
58#define TFTR 0x0024
59#define FDR 0x0028
60#define RMCR 0x002C
61#define EDOCR 0x0030
62#define FCFTR 0x0034
63#define RPADIR 0x0038
64#define TRIMD 0x003C
65#define RBWAR 0x0040
66#define RDFAR 0x0044
67#define TBRAR 0x004C
68#define TDFAR 0x0050
69/* Ether Register */
70#define ECMR 0x0160
71#define ECSR 0x0164
72#define ECSIPR 0x0168
73#define PIR 0x016C
74#define MAHR 0x0170
75#define MALR 0x0174
76#define RFLR 0x0178
77#define PSR 0x017C
78#define TROCR 0x0180
79#define CDCR 0x0184
80#define LCCR 0x0188
81#define CNDCR 0x018C
82#define CEFCR 0x0194
83#define FRECR 0x0198
84#define TSFRCR 0x019C
85#define TLFRCR 0x01A0
86#define RFCR 0x01A4
87#define MAFCR 0x01A8
88#define IPGR 0x01B4
89#if defined(CONFIG_CPU_SUBTYPE_SH7710)
90#define APR 0x01B8
91#define MPR 0x01BC
92#define TPAUSER 0x1C4
93#define BCFR 0x1CC
94#endif /* CONFIG_CPU_SH7710 */
95
96#define ARSTR 0x0800
97
98/* TSU */
99#define TSU_CTRST 0x004
100#define TSU_FWEN0 0x010
101#define TSU_FWEN1 0x014
102#define TSU_FCM 0x018
103#define TSU_BSYSL0 0x020
104#define TSU_BSYSL1 0x024
105#define TSU_PRISL0 0x028
106#define TSU_PRISL1 0x02C
107#define TSU_FWSL0 0x030
108#define TSU_FWSL1 0x034
109#define TSU_FWSLC 0x038
110#define TSU_QTAGM0 0x040
111#define TSU_QTAGM1 0x044
112#define TSU_ADQT0 0x048
113#define TSU_ADQT1 0x04C
114#define TSU_FWSR 0x050
115#define TSU_FWINMK 0x054
116#define TSU_ADSBSY 0x060
117#define TSU_TEN 0x064
118#define TSU_POST1 0x070
119#define TSU_POST2 0x074
120#define TSU_POST3 0x078
121#define TSU_POST4 0x07C
122#define TXNLCR0 0x080
123#define TXALCR0 0x084
124#define RXNLCR0 0x088
125#define RXALCR0 0x08C
126#define FWNLCR0 0x090
127#define FWALCR0 0x094
128#define TXNLCR1 0x0A0
129#define TXALCR1 0x0A4
130#define RXNLCR1 0x0A8
131#define RXALCR1 0x0AC
132#define FWNLCR1 0x0B0
133#define FWALCR1 0x0B4
134
135#define TSU_ADRH0 0x0100
136#define TSU_ADRL0 0x0104
137#define TSU_ADRL31 0x01FC
138
139/* Register's bits */
140
141/* EDMR */
142enum DMAC_M_BIT {
143 EDMR_DL1 = 0x20, EDMR_DL0 = 0x10, EDMR_SRST = 0x01,
144};
145
146/* EDTRR */
147enum DMAC_T_BIT {
148 EDTRR_TRNS = 0x01,
149};
150
151/* EDRRR*/
152enum EDRRR_R_BIT {
153 EDRRR_R = 0x01,
154};
155
156/* TPAUSER */
157enum TPAUSER_BIT {
158 TPAUSER_TPAUSE = 0x0000ffff,
159 TPAUSER_UNLIMITED = 0,
160};
161
162/* BCFR */
163enum BCFR_BIT {
164 BCFR_RPAUSE = 0x0000ffff,
165 BCFR_UNLIMITED = 0,
166};
167
168/* PIR */
169enum PIR_BIT {
170 PIR_MDI = 0x08, PIR_MDO = 0x04, PIR_MMD = 0x02, PIR_MDC = 0x01,
171};
172
173/* PSR */
174enum PHY_STATUS_BIT { PHY_ST_LINK = 0x01, };
175
176/* EESR */
177enum EESR_BIT {
178 EESR_TWB = 0x40000000, EESR_TABT = 0x04000000,
179 EESR_RABT = 0x02000000, EESR_RFRMER = 0x01000000,
180 EESR_ADE = 0x00800000, EESR_ECI = 0x00400000,
181 EESR_FTC = 0x00200000, EESR_TDE = 0x00100000,
182 EESR_TFE = 0x00080000, EESR_FRC = 0x00040000,
183 EESR_RDE = 0x00020000, EESR_RFE = 0x00010000,
184 EESR_TINT4 = 0x00000800, EESR_TINT3 = 0x00000400,
185 EESR_TINT2 = 0x00000200, EESR_TINT1 = 0x00000100,
186 EESR_RINT8 = 0x00000080, EESR_RINT5 = 0x00000010,
187 EESR_RINT4 = 0x00000008, EESR_RINT3 = 0x00000004,
188 EESR_RINT2 = 0x00000002, EESR_RINT1 = 0x00000001,
189};
190
191#define EESR_ERR_CHECK (EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE \
192 | EESR_RFRMER | EESR_ADE | EESR_TFE | EESR_TDE | EESR_ECI)
193
194/* EESIPR */
195enum DMAC_IM_BIT {
196 DMAC_M_TWB = 0x40000000, DMAC_M_TABT = 0x04000000,
197 DMAC_M_RABT = 0x02000000,
198 DMAC_M_RFRMER = 0x01000000, DMAC_M_ADF = 0x00800000,
199 DMAC_M_ECI = 0x00400000, DMAC_M_FTC = 0x00200000,
200 DMAC_M_TDE = 0x00100000, DMAC_M_TFE = 0x00080000,
201 DMAC_M_FRC = 0x00040000, DMAC_M_RDE = 0x00020000,
202 DMAC_M_RFE = 0x00010000, DMAC_M_TINT4 = 0x00000800,
203 DMAC_M_TINT3 = 0x00000400, DMAC_M_TINT2 = 0x00000200,
204 DMAC_M_TINT1 = 0x00000100, DMAC_M_RINT8 = 0x00000080,
205 DMAC_M_RINT5 = 0x00000010, DMAC_M_RINT4 = 0x00000008,
206 DMAC_M_RINT3 = 0x00000004, DMAC_M_RINT2 = 0x00000002,
207 DMAC_M_RINT1 = 0x00000001,
208};
209
210/* Receive descriptor bit */
211enum RD_STS_BIT {
212 RD_RACT = 0x80000000, RC_RDEL = 0x40000000,
213 RC_RFP1 = 0x20000000, RC_RFP0 = 0x10000000,
214 RD_RFE = 0x08000000, RD_RFS10 = 0x00000200,
215 RD_RFS9 = 0x00000100, RD_RFS8 = 0x00000080,
216 RD_RFS7 = 0x00000040, RD_RFS6 = 0x00000020,
217 RD_RFS5 = 0x00000010, RD_RFS4 = 0x00000008,
218 RD_RFS3 = 0x00000004, RD_RFS2 = 0x00000002,
219 RD_RFS1 = 0x00000001,
220};
221#define RDF1ST RC_RFP1
222#define RDFEND RC_RFP0
223#define RD_RFP (RC_RFP1|RC_RFP0)
224
225/* FCFTR */
226enum FCFTR_BIT {
227 FCFTR_RFF2 = 0x00040000, FCFTR_RFF1 = 0x00020000,
228 FCFTR_RFF0 = 0x00010000, FCFTR_RFD2 = 0x00000004,
229 FCFTR_RFD1 = 0x00000002, FCFTR_RFD0 = 0x00000001,
230};
231#define FIFO_F_D_RFF (FCFTR_RFF2|FCFTR_RFF1|FCFTR_RFF0)
232#define FIFO_F_D_RFD (FCFTR_RFD2|FCFTR_RFD1|FCFTR_RFD0)
233
234/* Transfer descriptor bit */
235enum TD_STS_BIT {
236 TD_TACT = 0x80000000, TD_TDLE = 0x40000000, TD_TFP1 = 0x20000000,
237 TD_TFP0 = 0x10000000,
238};
239#define TDF1ST TD_TFP1
240#define TDFEND TD_TFP0
241#define TD_TFP (TD_TFP1|TD_TFP0)
242
243/* RMCR */
244enum RECV_RST_BIT { RMCR_RST = 0x01, };
245/* ECMR */
246enum FELIC_MODE_BIT {
247 ECMR_ZPF = 0x00080000, ECMR_PFR = 0x00040000, ECMR_RXF = 0x00020000,
248 ECMR_TXF = 0x00010000, ECMR_MCT = 0x00002000, ECMR_PRCEF = 0x00001000,
249 ECMR_PMDE = 0x00000200, ECMR_RE = 0x00000040, ECMR_TE = 0x00000020,
250 ECMR_ILB = 0x00000008, ECMR_ELB = 0x00000004, ECMR_DM = 0x00000002,
251 ECMR_PRM = 0x00000001,
252};
253
254/* ECSR */
255enum ECSR_STATUS_BIT {
256 ECSR_BRCRX = 0x20, ECSR_PSRTO = 0x10, ECSR_LCHNG = 0x04,
257 ECSR_MPD = 0x02, ECSR_ICD = 0x01,
258};
259
260/* ECSIPR */
261enum ECSIPR_STATUS_MASK_BIT {
262 ECSIPR_BRCRXIP = 0x20, ECSIPR_PSRTOIP = 0x10, ECSIPR_LCHNGIP = 0x04,
263 ECSIPR_MPDIP = 0x02, ECSIPR_ICDIP = 0x01,
264};
265
266/* APR */
267enum APR_BIT {
268 APR_AP = 0x00000001,
269};
270
271/* MPR */
272enum MPR_BIT {
273 MPR_MP = 0x00000001,
274};
275
276/* TRSCER */
277enum DESC_I_BIT {
278 DESC_I_TINT4 = 0x0800, DESC_I_TINT3 = 0x0400, DESC_I_TINT2 = 0x0200,
279 DESC_I_TINT1 = 0x0100, DESC_I_RINT8 = 0x0080, DESC_I_RINT5 = 0x0010,
280 DESC_I_RINT4 = 0x0008, DESC_I_RINT3 = 0x0004, DESC_I_RINT2 = 0x0002,
281 DESC_I_RINT1 = 0x0001,
282};
283
284/* RPADIR */
285enum RPADIR_BIT {
286 RPADIR_PADS1 = 0x20000, RPADIR_PADS0 = 0x10000,
287 RPADIR_PADR = 0x0003f,
288};
289
290/* FDR */
291enum FIFO_SIZE_BIT {
292 FIFO_SIZE_T = 0x00000700, FIFO_SIZE_R = 0x00000007,
293};
294enum phy_offsets {
295 PHY_CTRL = 0, PHY_STAT = 1, PHY_IDT1 = 2, PHY_IDT2 = 3,
296 PHY_ANA = 4, PHY_ANL = 5, PHY_ANE = 6,
297 PHY_16 = 16,
298};
299
300/* PHY_CTRL */
301enum PHY_CTRL_BIT {
302 PHY_C_RESET = 0x8000, PHY_C_LOOPBK = 0x4000, PHY_C_SPEEDSL = 0x2000,
303 PHY_C_ANEGEN = 0x1000, PHY_C_PWRDN = 0x0800, PHY_C_ISO = 0x0400,
304 PHY_C_RANEG = 0x0200, PHY_C_DUPLEX = 0x0100, PHY_C_COLT = 0x0080,
305};
306#define DM9161_PHY_C_ANEGEN 0 /* auto nego special */
307
308/* PHY_STAT */
309enum PHY_STAT_BIT {
310 PHY_S_100T4 = 0x8000, PHY_S_100X_F = 0x4000, PHY_S_100X_H = 0x2000,
311 PHY_S_10T_F = 0x1000, PHY_S_10T_H = 0x0800, PHY_S_ANEGC = 0x0020,
312 PHY_S_RFAULT = 0x0010, PHY_S_ANEGA = 0x0008, PHY_S_LINK = 0x0004,
313 PHY_S_JAB = 0x0002, PHY_S_EXTD = 0x0001,
314};
315
316/* PHY_ANA */
317enum PHY_ANA_BIT {
318 PHY_A_NP = 0x8000, PHY_A_ACK = 0x4000, PHY_A_RF = 0x2000,
319 PHY_A_FCS = 0x0400, PHY_A_T4 = 0x0200, PHY_A_FDX = 0x0100,
320 PHY_A_HDX = 0x0080, PHY_A_10FDX = 0x0040, PHY_A_10HDX = 0x0020,
321 PHY_A_SEL = 0x001f,
322};
323/* PHY_ANL */
324enum PHY_ANL_BIT {
325 PHY_L_NP = 0x8000, PHY_L_ACK = 0x4000, PHY_L_RF = 0x2000,
326 PHY_L_FCS = 0x0400, PHY_L_T4 = 0x0200, PHY_L_FDX = 0x0100,
327 PHY_L_HDX = 0x0080, PHY_L_10FDX = 0x0040, PHY_L_10HDX = 0x0020,
328 PHY_L_SEL = 0x001f,
329};
330
331/* PHY_ANE */
332enum PHY_ANE_BIT {
333 PHY_E_PDF = 0x0010, PHY_E_LPNPA = 0x0008, PHY_E_NPA = 0x0004,
334 PHY_E_PRX = 0x0002, PHY_E_LPANEGA = 0x0001,
335};
336
337/* DM9161 */
338enum PHY_16_BIT {
339 PHY_16_BP4B45 = 0x8000, PHY_16_BPSCR = 0x4000, PHY_16_BPALIGN = 0x2000,
340 PHY_16_BP_ADPOK = 0x1000, PHY_16_Repeatmode = 0x0800,
341 PHY_16_TXselect = 0x0400,
342 PHY_16_Rsvd = 0x0200, PHY_16_RMIIEnable = 0x0100,
343 PHY_16_Force100LNK = 0x0080,
344 PHY_16_APDLED_CTL = 0x0040, PHY_16_COLLED_CTL = 0x0020,
345 PHY_16_RPDCTR_EN = 0x0010,
346 PHY_16_ResetStMch = 0x0008, PHY_16_PreamSupr = 0x0004,
347 PHY_16_Sleepmode = 0x0002,
348 PHY_16_RemoteLoopOut = 0x0001,
349};
350
351#define POST_RX 0x08
352#define POST_FW 0x04
353#define POST0_RX (POST_RX)
354#define POST0_FW (POST_FW)
355#define POST1_RX (POST_RX >> 2)
356#define POST1_FW (POST_FW >> 2)
357#define POST_ALL (POST0_RX | POST0_FW | POST1_RX | POST1_FW)
358
359/* ARSTR */
360enum ARSTR_BIT { ARSTR_ARSTR = 0x00000001, };
361
362/* TSU_FWEN0 */
363enum TSU_FWEN0_BIT {
364 TSU_FWEN0_0 = 0x00000001,
365};
366
367/* TSU_ADSBSY */
368enum TSU_ADSBSY_BIT {
369 TSU_ADSBSY_0 = 0x00000001,
370};
371
372/* TSU_TEN */
373enum TSU_TEN_BIT {
374 TSU_TEN_0 = 0x80000000,
375};
376
377/* TSU_FWSL0 */
378enum TSU_FWSL0_BIT {
379 TSU_FWSL0_FW50 = 0x1000, TSU_FWSL0_FW40 = 0x0800,
380 TSU_FWSL0_FW30 = 0x0400, TSU_FWSL0_FW20 = 0x0200,
381 TSU_FWSL0_FW10 = 0x0100, TSU_FWSL0_RMSA0 = 0x0010,
382};
383
384/* TSU_FWSLC */
385enum TSU_FWSLC_BIT {
386 TSU_FWSLC_POSTENU = 0x2000, TSU_FWSLC_POSTENL = 0x1000,
387 TSU_FWSLC_CAMSEL03 = 0x0080, TSU_FWSLC_CAMSEL02 = 0x0040,
388 TSU_FWSLC_CAMSEL01 = 0x0020, TSU_FWSLC_CAMSEL00 = 0x0010,
389 TSU_FWSLC_CAMSEL13 = 0x0008, TSU_FWSLC_CAMSEL12 = 0x0004,
390 TSU_FWSLC_CAMSEL11 = 0x0002, TSU_FWSLC_CAMSEL10 = 0x0001,
391};
392
393/*
394 * The sh ether Tx buffer descriptors.
395 * This structure should be 20 bytes.
396 */
397struct sh_eth_txdesc {
398 u32 status; /* TD0 */
399#if defined(CONFIG_CPU_LITTLE_ENDIAN)
400 u16 pad0; /* TD1 */
401 u16 buffer_length; /* TD1 */
402#else
403 u16 buffer_length; /* TD1 */
404 u16 pad0; /* TD1 */
405#endif
406 u32 addr; /* TD2 */
407 u32 pad1; /* padding data */
408};
409
410/*
411 * The sh ether Rx buffer descriptors.
412 * This structure should be 20 bytes.
413 */
414struct sh_eth_rxdesc {
415 u32 status; /* RD0 */
416#if defined(CONFIG_CPU_LITTLE_ENDIAN)
417 u16 frame_length; /* RD1 */
418 u16 buffer_length; /* RD1 */
419#else
420 u16 buffer_length; /* RD1 */
421 u16 frame_length; /* RD1 */
422#endif
423 u32 addr; /* RD2 */
424 u32 pad0; /* padding data */
425};
426
427struct sh_eth_private {
428 dma_addr_t rx_desc_dma;
429 dma_addr_t tx_desc_dma;
430 struct sh_eth_rxdesc *rx_ring;
431 struct sh_eth_txdesc *tx_ring;
432 struct sk_buff **rx_skbuff;
433 struct sk_buff **tx_skbuff;
434 struct net_device_stats stats;
435 struct timer_list timer;
436 spinlock_t lock;
437 u32 cur_rx, dirty_rx; /* Producer/consumer ring indices */
438 u32 cur_tx, dirty_tx;
439 u32 rx_buf_sz; /* Based on MTU+slack. */
440 /* MII transceiver section. */
441 u32 phy_id; /* PHY ID */
442 struct mii_bus *mii_bus; /* MDIO bus control */
443 struct phy_device *phydev; /* PHY device control */
444 enum phy_state link;
445 int msg_enable;
446 int speed;
447 int duplex;
448 u32 rx_int_var, tx_int_var; /* interrupt control variables */
449 char post_rx; /* POST receive */
450 char post_fw; /* POST forward */
451 struct net_device_stats tsu_stats; /* TSU forward status */
452};
453
454static void swaps(char *src, int len)
455{
456#ifdef __LITTLE_ENDIAN__
457 u32 *p = (u32 *)src;
458 u32 *maxp;
459 maxp = p + ((len + sizeof(u32) - 1) / sizeof(u32));
460
461 for (; p < maxp; p++)
462 *p = swab32(*p);
463#endif
464}
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 4e2800205189..fc605f276c00 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -106,56 +106,6 @@ MODULE_ALIAS("platform:smc911x");
106 */ 106 */
107#define POWER_DOWN 1 107#define POWER_DOWN 1
108 108
109
110/* store this information for the driver.. */
111struct smc911x_local {
112 /*
113 * If I have to wait until the DMA is finished and ready to reload a
114 * packet, I will store the skbuff here. Then, the DMA will send it
115 * out and free it.
116 */
117 struct sk_buff *pending_tx_skb;
118
119 /* version/revision of the SMC911x chip */
120 u16 version;
121 u16 revision;
122
123 /* FIFO sizes */
124 int tx_fifo_kb;
125 int tx_fifo_size;
126 int rx_fifo_size;
127 int afc_cfg;
128
129 /* Contains the current active receive/phy mode */
130 int ctl_rfduplx;
131 int ctl_rspeed;
132
133 u32 msg_enable;
134 u32 phy_type;
135 struct mii_if_info mii;
136
137 /* work queue */
138 struct work_struct phy_configure;
139 int work_pending;
140
141 int tx_throttle;
142 spinlock_t lock;
143
144 struct net_device *netdev;
145
146#ifdef SMC_USE_DMA
147 /* DMA needs the physical address of the chip */
148 u_long physaddr;
149 int rxdma;
150 int txdma;
151 int rxdma_active;
152 int txdma_active;
153 struct sk_buff *current_rx_skb;
154 struct sk_buff *current_tx_skb;
155 struct device *dev;
156#endif
157};
158
159#if SMC_DEBUG > 0 109#if SMC_DEBUG > 0
160#define DBG(n, args...) \ 110#define DBG(n, args...) \
161 do { \ 111 do { \
@@ -203,24 +153,24 @@ static void PRINT_PKT(u_char *buf, int length)
203 153
204 154
205/* this enables an interrupt in the interrupt mask register */ 155/* this enables an interrupt in the interrupt mask register */
206#define SMC_ENABLE_INT(x) do { \ 156#define SMC_ENABLE_INT(lp, x) do { \
207 unsigned int __mask; \ 157 unsigned int __mask; \
208 unsigned long __flags; \ 158 unsigned long __flags; \
209 spin_lock_irqsave(&lp->lock, __flags); \ 159 spin_lock_irqsave(&lp->lock, __flags); \
210 __mask = SMC_GET_INT_EN(); \ 160 __mask = SMC_GET_INT_EN((lp)); \
211 __mask |= (x); \ 161 __mask |= (x); \
212 SMC_SET_INT_EN(__mask); \ 162 SMC_SET_INT_EN((lp), __mask); \
213 spin_unlock_irqrestore(&lp->lock, __flags); \ 163 spin_unlock_irqrestore(&lp->lock, __flags); \
214} while (0) 164} while (0)
215 165
216/* this disables an interrupt from the interrupt mask register */ 166/* this disables an interrupt from the interrupt mask register */
217#define SMC_DISABLE_INT(x) do { \ 167#define SMC_DISABLE_INT(lp, x) do { \
218 unsigned int __mask; \ 168 unsigned int __mask; \
219 unsigned long __flags; \ 169 unsigned long __flags; \
220 spin_lock_irqsave(&lp->lock, __flags); \ 170 spin_lock_irqsave(&lp->lock, __flags); \
221 __mask = SMC_GET_INT_EN(); \ 171 __mask = SMC_GET_INT_EN((lp)); \
222 __mask &= ~(x); \ 172 __mask &= ~(x); \
223 SMC_SET_INT_EN(__mask); \ 173 SMC_SET_INT_EN((lp), __mask); \
224 spin_unlock_irqrestore(&lp->lock, __flags); \ 174 spin_unlock_irqrestore(&lp->lock, __flags); \
225} while (0) 175} while (0)
226 176
@@ -229,7 +179,6 @@ static void PRINT_PKT(u_char *buf, int length)
229 */ 179 */
230static void smc911x_reset(struct net_device *dev) 180static void smc911x_reset(struct net_device *dev)
231{ 181{
232 unsigned long ioaddr = dev->base_addr;
233 struct smc911x_local *lp = netdev_priv(dev); 182 struct smc911x_local *lp = netdev_priv(dev);
234 unsigned int reg, timeout=0, resets=1; 183 unsigned int reg, timeout=0, resets=1;
235 unsigned long flags; 184 unsigned long flags;
@@ -237,13 +186,13 @@ static void smc911x_reset(struct net_device *dev)
237 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__); 186 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
238 187
239 /* Take out of PM setting first */ 188 /* Take out of PM setting first */
240 if ((SMC_GET_PMT_CTRL() & PMT_CTRL_READY_) == 0) { 189 if ((SMC_GET_PMT_CTRL(lp) & PMT_CTRL_READY_) == 0) {
241 /* Write to the bytetest will take out of powerdown */ 190 /* Write to the bytetest will take out of powerdown */
242 SMC_SET_BYTE_TEST(0); 191 SMC_SET_BYTE_TEST(lp, 0);
243 timeout=10; 192 timeout=10;
244 do { 193 do {
245 udelay(10); 194 udelay(10);
246 reg = SMC_GET_PMT_CTRL() & PMT_CTRL_READY_; 195 reg = SMC_GET_PMT_CTRL(lp) & PMT_CTRL_READY_;
247 } while (--timeout && !reg); 196 } while (--timeout && !reg);
248 if (timeout == 0) { 197 if (timeout == 0) {
249 PRINTK("%s: smc911x_reset timeout waiting for PM restore\n", dev->name); 198 PRINTK("%s: smc911x_reset timeout waiting for PM restore\n", dev->name);
@@ -253,15 +202,15 @@ static void smc911x_reset(struct net_device *dev)
253 202
254 /* Disable all interrupts */ 203 /* Disable all interrupts */
255 spin_lock_irqsave(&lp->lock, flags); 204 spin_lock_irqsave(&lp->lock, flags);
256 SMC_SET_INT_EN(0); 205 SMC_SET_INT_EN(lp, 0);
257 spin_unlock_irqrestore(&lp->lock, flags); 206 spin_unlock_irqrestore(&lp->lock, flags);
258 207
259 while (resets--) { 208 while (resets--) {
260 SMC_SET_HW_CFG(HW_CFG_SRST_); 209 SMC_SET_HW_CFG(lp, HW_CFG_SRST_);
261 timeout=10; 210 timeout=10;
262 do { 211 do {
263 udelay(10); 212 udelay(10);
264 reg = SMC_GET_HW_CFG(); 213 reg = SMC_GET_HW_CFG(lp);
265 /* If chip indicates reset timeout then try again */ 214 /* If chip indicates reset timeout then try again */
266 if (reg & HW_CFG_SRST_TO_) { 215 if (reg & HW_CFG_SRST_TO_) {
267 PRINTK("%s: chip reset timeout, retrying...\n", dev->name); 216 PRINTK("%s: chip reset timeout, retrying...\n", dev->name);
@@ -277,7 +226,7 @@ static void smc911x_reset(struct net_device *dev)
277 226
278 /* make sure EEPROM has finished loading before setting GPIO_CFG */ 227 /* make sure EEPROM has finished loading before setting GPIO_CFG */
279 timeout=1000; 228 timeout=1000;
280 while ( timeout-- && (SMC_GET_E2P_CMD() & E2P_CMD_EPC_BUSY_)) { 229 while ( timeout-- && (SMC_GET_E2P_CMD(lp) & E2P_CMD_EPC_BUSY_)) {
281 udelay(10); 230 udelay(10);
282 } 231 }
283 if (timeout == 0){ 232 if (timeout == 0){
@@ -286,24 +235,24 @@ static void smc911x_reset(struct net_device *dev)
286 } 235 }
287 236
288 /* Initialize interrupts */ 237 /* Initialize interrupts */
289 SMC_SET_INT_EN(0); 238 SMC_SET_INT_EN(lp, 0);
290 SMC_ACK_INT(-1); 239 SMC_ACK_INT(lp, -1);
291 240
292 /* Reset the FIFO level and flow control settings */ 241 /* Reset the FIFO level and flow control settings */
293 SMC_SET_HW_CFG((lp->tx_fifo_kb & 0xF) << 16); 242 SMC_SET_HW_CFG(lp, (lp->tx_fifo_kb & 0xF) << 16);
294//TODO: Figure out what appropriate pause time is 243//TODO: Figure out what appropriate pause time is
295 SMC_SET_FLOW(FLOW_FCPT_ | FLOW_FCEN_); 244 SMC_SET_FLOW(lp, FLOW_FCPT_ | FLOW_FCEN_);
296 SMC_SET_AFC_CFG(lp->afc_cfg); 245 SMC_SET_AFC_CFG(lp, lp->afc_cfg);
297 246
298 247
299 /* Set to LED outputs */ 248 /* Set to LED outputs */
300 SMC_SET_GPIO_CFG(0x70070000); 249 SMC_SET_GPIO_CFG(lp, 0x70070000);
301 250
302 /* 251 /*
303 * Deassert IRQ for 1*10us for edge type interrupts 252 * Deassert IRQ for 1*10us for edge type interrupts
304 * and drive IRQ pin push-pull 253 * and drive IRQ pin push-pull
305 */ 254 */
306 SMC_SET_IRQ_CFG( (1 << 24) | INT_CFG_IRQ_EN_ | INT_CFG_IRQ_TYPE_ ); 255 SMC_SET_IRQ_CFG(lp, (1 << 24) | INT_CFG_IRQ_EN_ | INT_CFG_IRQ_TYPE_);
307 256
308 /* clear anything saved */ 257 /* clear anything saved */
309 if (lp->pending_tx_skb != NULL) { 258 if (lp->pending_tx_skb != NULL) {
@@ -319,46 +268,45 @@ static void smc911x_reset(struct net_device *dev)
319 */ 268 */
320static void smc911x_enable(struct net_device *dev) 269static void smc911x_enable(struct net_device *dev)
321{ 270{
322 unsigned long ioaddr = dev->base_addr;
323 struct smc911x_local *lp = netdev_priv(dev); 271 struct smc911x_local *lp = netdev_priv(dev);
324 unsigned mask, cfg, cr; 272 unsigned mask, cfg, cr;
325 unsigned long flags; 273 unsigned long flags;
326 274
327 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__); 275 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
328 276
329 SMC_SET_MAC_ADDR(dev->dev_addr); 277 SMC_SET_MAC_ADDR(lp, dev->dev_addr);
330 278
331 /* Enable TX */ 279 /* Enable TX */
332 cfg = SMC_GET_HW_CFG(); 280 cfg = SMC_GET_HW_CFG(lp);
333 cfg &= HW_CFG_TX_FIF_SZ_ | 0xFFF; 281 cfg &= HW_CFG_TX_FIF_SZ_ | 0xFFF;
334 cfg |= HW_CFG_SF_; 282 cfg |= HW_CFG_SF_;
335 SMC_SET_HW_CFG(cfg); 283 SMC_SET_HW_CFG(lp, cfg);
336 SMC_SET_FIFO_TDA(0xFF); 284 SMC_SET_FIFO_TDA(lp, 0xFF);
337 /* Update TX stats on every 64 packets received or every 1 sec */ 285 /* Update TX stats on every 64 packets received or every 1 sec */
338 SMC_SET_FIFO_TSL(64); 286 SMC_SET_FIFO_TSL(lp, 64);
339 SMC_SET_GPT_CFG(GPT_CFG_TIMER_EN_ | 10000); 287 SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000);
340 288
341 spin_lock_irqsave(&lp->lock, flags); 289 spin_lock_irqsave(&lp->lock, flags);
342 SMC_GET_MAC_CR(cr); 290 SMC_GET_MAC_CR(lp, cr);
343 cr |= MAC_CR_TXEN_ | MAC_CR_HBDIS_; 291 cr |= MAC_CR_TXEN_ | MAC_CR_HBDIS_;
344 SMC_SET_MAC_CR(cr); 292 SMC_SET_MAC_CR(lp, cr);
345 SMC_SET_TX_CFG(TX_CFG_TX_ON_); 293 SMC_SET_TX_CFG(lp, TX_CFG_TX_ON_);
346 spin_unlock_irqrestore(&lp->lock, flags); 294 spin_unlock_irqrestore(&lp->lock, flags);
347 295
348 /* Add 2 byte padding to start of packets */ 296 /* Add 2 byte padding to start of packets */
349 SMC_SET_RX_CFG((2<<8) & RX_CFG_RXDOFF_); 297 SMC_SET_RX_CFG(lp, (2<<8) & RX_CFG_RXDOFF_);
350 298
351 /* Turn on receiver and enable RX */ 299 /* Turn on receiver and enable RX */
352 if (cr & MAC_CR_RXEN_) 300 if (cr & MAC_CR_RXEN_)
353 DBG(SMC_DEBUG_RX, "%s: Receiver already enabled\n", dev->name); 301 DBG(SMC_DEBUG_RX, "%s: Receiver already enabled\n", dev->name);
354 302
355 spin_lock_irqsave(&lp->lock, flags); 303 spin_lock_irqsave(&lp->lock, flags);
356 SMC_SET_MAC_CR( cr | MAC_CR_RXEN_ ); 304 SMC_SET_MAC_CR(lp, cr | MAC_CR_RXEN_);
357 spin_unlock_irqrestore(&lp->lock, flags); 305 spin_unlock_irqrestore(&lp->lock, flags);
358 306
359 /* Interrupt on every received packet */ 307 /* Interrupt on every received packet */
360 SMC_SET_FIFO_RSA(0x01); 308 SMC_SET_FIFO_RSA(lp, 0x01);
361 SMC_SET_FIFO_RSL(0x00); 309 SMC_SET_FIFO_RSL(lp, 0x00);
362 310
363 /* now, enable interrupts */ 311 /* now, enable interrupts */
364 mask = INT_EN_TDFA_EN_ | INT_EN_TSFL_EN_ | INT_EN_RSFL_EN_ | 312 mask = INT_EN_TDFA_EN_ | INT_EN_TSFL_EN_ | INT_EN_RSFL_EN_ |
@@ -369,7 +317,7 @@ static void smc911x_enable(struct net_device *dev)
369 else { 317 else {
370 mask|=INT_EN_RDFO_EN_; 318 mask|=INT_EN_RDFO_EN_;
371 } 319 }
372 SMC_ENABLE_INT(mask); 320 SMC_ENABLE_INT(lp, mask);
373} 321}
374 322
375/* 323/*
@@ -377,7 +325,6 @@ static void smc911x_enable(struct net_device *dev)
377 */ 325 */
378static void smc911x_shutdown(struct net_device *dev) 326static void smc911x_shutdown(struct net_device *dev)
379{ 327{
380 unsigned long ioaddr = dev->base_addr;
381 struct smc911x_local *lp = netdev_priv(dev); 328 struct smc911x_local *lp = netdev_priv(dev);
382 unsigned cr; 329 unsigned cr;
383 unsigned long flags; 330 unsigned long flags;
@@ -385,35 +332,35 @@ static void smc911x_shutdown(struct net_device *dev)
385 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", CARDNAME, __FUNCTION__); 332 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", CARDNAME, __FUNCTION__);
386 333
387 /* Disable IRQ's */ 334 /* Disable IRQ's */
388 SMC_SET_INT_EN(0); 335 SMC_SET_INT_EN(lp, 0);
389 336
390 /* Turn of Rx and TX */ 337 /* Turn of Rx and TX */
391 spin_lock_irqsave(&lp->lock, flags); 338 spin_lock_irqsave(&lp->lock, flags);
392 SMC_GET_MAC_CR(cr); 339 SMC_GET_MAC_CR(lp, cr);
393 cr &= ~(MAC_CR_TXEN_ | MAC_CR_RXEN_ | MAC_CR_HBDIS_); 340 cr &= ~(MAC_CR_TXEN_ | MAC_CR_RXEN_ | MAC_CR_HBDIS_);
394 SMC_SET_MAC_CR(cr); 341 SMC_SET_MAC_CR(lp, cr);
395 SMC_SET_TX_CFG(TX_CFG_STOP_TX_); 342 SMC_SET_TX_CFG(lp, TX_CFG_STOP_TX_);
396 spin_unlock_irqrestore(&lp->lock, flags); 343 spin_unlock_irqrestore(&lp->lock, flags);
397} 344}
398 345
399static inline void smc911x_drop_pkt(struct net_device *dev) 346static inline void smc911x_drop_pkt(struct net_device *dev)
400{ 347{
401 unsigned long ioaddr = dev->base_addr; 348 struct smc911x_local *lp = netdev_priv(dev);
402 unsigned int fifo_count, timeout, reg; 349 unsigned int fifo_count, timeout, reg;
403 350
404 DBG(SMC_DEBUG_FUNC | SMC_DEBUG_RX, "%s: --> %s\n", CARDNAME, __FUNCTION__); 351 DBG(SMC_DEBUG_FUNC | SMC_DEBUG_RX, "%s: --> %s\n", CARDNAME, __FUNCTION__);
405 fifo_count = SMC_GET_RX_FIFO_INF() & 0xFFFF; 352 fifo_count = SMC_GET_RX_FIFO_INF(lp) & 0xFFFF;
406 if (fifo_count <= 4) { 353 if (fifo_count <= 4) {
407 /* Manually dump the packet data */ 354 /* Manually dump the packet data */
408 while (fifo_count--) 355 while (fifo_count--)
409 SMC_GET_RX_FIFO(); 356 SMC_GET_RX_FIFO(lp);
410 } else { 357 } else {
411 /* Fast forward through the bad packet */ 358 /* Fast forward through the bad packet */
412 SMC_SET_RX_DP_CTRL(RX_DP_CTRL_FFWD_BUSY_); 359 SMC_SET_RX_DP_CTRL(lp, RX_DP_CTRL_FFWD_BUSY_);
413 timeout=50; 360 timeout=50;
414 do { 361 do {
415 udelay(10); 362 udelay(10);
416 reg = SMC_GET_RX_DP_CTRL() & RX_DP_CTRL_FFWD_BUSY_; 363 reg = SMC_GET_RX_DP_CTRL(lp) & RX_DP_CTRL_FFWD_BUSY_;
417 } while (--timeout && reg); 364 } while (--timeout && reg);
418 if (timeout == 0) { 365 if (timeout == 0) {
419 PRINTK("%s: timeout waiting for RX fast forward\n", dev->name); 366 PRINTK("%s: timeout waiting for RX fast forward\n", dev->name);
@@ -429,14 +376,14 @@ static inline void smc911x_drop_pkt(struct net_device *dev)
429 */ 376 */
430static inline void smc911x_rcv(struct net_device *dev) 377static inline void smc911x_rcv(struct net_device *dev)
431{ 378{
432 unsigned long ioaddr = dev->base_addr; 379 struct smc911x_local *lp = netdev_priv(dev);
433 unsigned int pkt_len, status; 380 unsigned int pkt_len, status;
434 struct sk_buff *skb; 381 struct sk_buff *skb;
435 unsigned char *data; 382 unsigned char *data;
436 383
437 DBG(SMC_DEBUG_FUNC | SMC_DEBUG_RX, "%s: --> %s\n", 384 DBG(SMC_DEBUG_FUNC | SMC_DEBUG_RX, "%s: --> %s\n",
438 dev->name, __FUNCTION__); 385 dev->name, __FUNCTION__);
439 status = SMC_GET_RX_STS_FIFO(); 386 status = SMC_GET_RX_STS_FIFO(lp);
440 DBG(SMC_DEBUG_RX, "%s: Rx pkt len %d status 0x%08x \n", 387 DBG(SMC_DEBUG_RX, "%s: Rx pkt len %d status 0x%08x \n",
441 dev->name, (status & 0x3fff0000) >> 16, status & 0xc000ffff); 388 dev->name, (status & 0x3fff0000) >> 16, status & 0xc000ffff);
442 pkt_len = (status & RX_STS_PKT_LEN_) >> 16; 389 pkt_len = (status & RX_STS_PKT_LEN_) >> 16;
@@ -473,24 +420,23 @@ static inline void smc911x_rcv(struct net_device *dev)
473 skb_put(skb,pkt_len-4); 420 skb_put(skb,pkt_len-4);
474#ifdef SMC_USE_DMA 421#ifdef SMC_USE_DMA
475 { 422 {
476 struct smc911x_local *lp = netdev_priv(dev);
477 unsigned int fifo; 423 unsigned int fifo;
478 /* Lower the FIFO threshold if possible */ 424 /* Lower the FIFO threshold if possible */
479 fifo = SMC_GET_FIFO_INT(); 425 fifo = SMC_GET_FIFO_INT(lp);
480 if (fifo & 0xFF) fifo--; 426 if (fifo & 0xFF) fifo--;
481 DBG(SMC_DEBUG_RX, "%s: Setting RX stat FIFO threshold to %d\n", 427 DBG(SMC_DEBUG_RX, "%s: Setting RX stat FIFO threshold to %d\n",
482 dev->name, fifo & 0xff); 428 dev->name, fifo & 0xff);
483 SMC_SET_FIFO_INT(fifo); 429 SMC_SET_FIFO_INT(lp, fifo);
484 /* Setup RX DMA */ 430 /* Setup RX DMA */
485 SMC_SET_RX_CFG(RX_CFG_RX_END_ALGN16_ | ((2<<8) & RX_CFG_RXDOFF_)); 431 SMC_SET_RX_CFG(lp, RX_CFG_RX_END_ALGN16_ | ((2<<8) & RX_CFG_RXDOFF_));
486 lp->rxdma_active = 1; 432 lp->rxdma_active = 1;
487 lp->current_rx_skb = skb; 433 lp->current_rx_skb = skb;
488 SMC_PULL_DATA(data, (pkt_len+2+15) & ~15); 434 SMC_PULL_DATA(lp, data, (pkt_len+2+15) & ~15);
489 /* Packet processing deferred to DMA RX interrupt */ 435 /* Packet processing deferred to DMA RX interrupt */
490 } 436 }
491#else 437#else
492 SMC_SET_RX_CFG(RX_CFG_RX_END_ALGN4_ | ((2<<8) & RX_CFG_RXDOFF_)); 438 SMC_SET_RX_CFG(lp, RX_CFG_RX_END_ALGN4_ | ((2<<8) & RX_CFG_RXDOFF_));
493 SMC_PULL_DATA(data, pkt_len+2+3); 439 SMC_PULL_DATA(lp, data, pkt_len+2+3);
494 440
495 DBG(SMC_DEBUG_PKTS, "%s: Received packet\n", dev->name); 441 DBG(SMC_DEBUG_PKTS, "%s: Received packet\n", dev->name);
496 PRINT_PKT(data, ((pkt_len - 4) <= 64) ? pkt_len - 4 : 64); 442 PRINT_PKT(data, ((pkt_len - 4) <= 64) ? pkt_len - 4 : 64);
@@ -509,7 +455,6 @@ static inline void smc911x_rcv(struct net_device *dev)
509static void smc911x_hardware_send_pkt(struct net_device *dev) 455static void smc911x_hardware_send_pkt(struct net_device *dev)
510{ 456{
511 struct smc911x_local *lp = netdev_priv(dev); 457 struct smc911x_local *lp = netdev_priv(dev);
512 unsigned long ioaddr = dev->base_addr;
513 struct sk_buff *skb; 458 struct sk_buff *skb;
514 unsigned int cmdA, cmdB, len; 459 unsigned int cmdA, cmdB, len;
515 unsigned char *buf; 460 unsigned char *buf;
@@ -542,8 +487,8 @@ static void smc911x_hardware_send_pkt(struct net_device *dev)
542 487
543 DBG(SMC_DEBUG_TX, "%s: TX PKT LENGTH 0x%04x (%d) BUF 0x%p CMDA 0x%08x CMDB 0x%08x\n", 488 DBG(SMC_DEBUG_TX, "%s: TX PKT LENGTH 0x%04x (%d) BUF 0x%p CMDA 0x%08x CMDB 0x%08x\n",
544 dev->name, len, len, buf, cmdA, cmdB); 489 dev->name, len, len, buf, cmdA, cmdB);
545 SMC_SET_TX_FIFO(cmdA); 490 SMC_SET_TX_FIFO(lp, cmdA);
546 SMC_SET_TX_FIFO(cmdB); 491 SMC_SET_TX_FIFO(lp, cmdB);
547 492
548 DBG(SMC_DEBUG_PKTS, "%s: Transmitted packet\n", dev->name); 493 DBG(SMC_DEBUG_PKTS, "%s: Transmitted packet\n", dev->name);
549 PRINT_PKT(buf, len <= 64 ? len : 64); 494 PRINT_PKT(buf, len <= 64 ? len : 64);
@@ -551,10 +496,10 @@ static void smc911x_hardware_send_pkt(struct net_device *dev)
551 /* Send pkt via PIO or DMA */ 496 /* Send pkt via PIO or DMA */
552#ifdef SMC_USE_DMA 497#ifdef SMC_USE_DMA
553 lp->current_tx_skb = skb; 498 lp->current_tx_skb = skb;
554 SMC_PUSH_DATA(buf, len); 499 SMC_PUSH_DATA(lp, buf, len);
555 /* DMA complete IRQ will free buffer and set jiffies */ 500 /* DMA complete IRQ will free buffer and set jiffies */
556#else 501#else
557 SMC_PUSH_DATA(buf, len); 502 SMC_PUSH_DATA(lp, buf, len);
558 dev->trans_start = jiffies; 503 dev->trans_start = jiffies;
559 dev_kfree_skb(skb); 504 dev_kfree_skb(skb);
560#endif 505#endif
@@ -563,7 +508,7 @@ static void smc911x_hardware_send_pkt(struct net_device *dev)
563 netif_wake_queue(dev); 508 netif_wake_queue(dev);
564 } 509 }
565 spin_unlock_irqrestore(&lp->lock, flags); 510 spin_unlock_irqrestore(&lp->lock, flags);
566 SMC_ENABLE_INT(INT_EN_TDFA_EN_ | INT_EN_TSFL_EN_); 511 SMC_ENABLE_INT(lp, INT_EN_TDFA_EN_ | INT_EN_TSFL_EN_);
567} 512}
568 513
569/* 514/*
@@ -575,7 +520,6 @@ static void smc911x_hardware_send_pkt(struct net_device *dev)
575static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) 520static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
576{ 521{
577 struct smc911x_local *lp = netdev_priv(dev); 522 struct smc911x_local *lp = netdev_priv(dev);
578 unsigned long ioaddr = dev->base_addr;
579 unsigned int free; 523 unsigned int free;
580 unsigned long flags; 524 unsigned long flags;
581 525
@@ -584,7 +528,7 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
584 528
585 BUG_ON(lp->pending_tx_skb != NULL); 529 BUG_ON(lp->pending_tx_skb != NULL);
586 530
587 free = SMC_GET_TX_FIFO_INF() & TX_FIFO_INF_TDFREE_; 531 free = SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TDFREE_;
588 DBG(SMC_DEBUG_TX, "%s: TX free space %d\n", dev->name, free); 532 DBG(SMC_DEBUG_TX, "%s: TX free space %d\n", dev->name, free);
589 533
590 /* Turn off the flow when running out of space in FIFO */ 534 /* Turn off the flow when running out of space in FIFO */
@@ -593,7 +537,7 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
593 dev->name, free); 537 dev->name, free);
594 spin_lock_irqsave(&lp->lock, flags); 538 spin_lock_irqsave(&lp->lock, flags);
595 /* Reenable when at least 1 packet of size MTU present */ 539 /* Reenable when at least 1 packet of size MTU present */
596 SMC_SET_FIFO_TDA((SMC911X_TX_FIFO_LOW_THRESHOLD)/64); 540 SMC_SET_FIFO_TDA(lp, (SMC911X_TX_FIFO_LOW_THRESHOLD)/64);
597 lp->tx_throttle = 1; 541 lp->tx_throttle = 1;
598 netif_stop_queue(dev); 542 netif_stop_queue(dev);
599 spin_unlock_irqrestore(&lp->lock, flags); 543 spin_unlock_irqrestore(&lp->lock, flags);
@@ -648,7 +592,6 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
648 */ 592 */
649static void smc911x_tx(struct net_device *dev) 593static void smc911x_tx(struct net_device *dev)
650{ 594{
651 unsigned long ioaddr = dev->base_addr;
652 struct smc911x_local *lp = netdev_priv(dev); 595 struct smc911x_local *lp = netdev_priv(dev);
653 unsigned int tx_status; 596 unsigned int tx_status;
654 597
@@ -656,11 +599,11 @@ static void smc911x_tx(struct net_device *dev)
656 dev->name, __FUNCTION__); 599 dev->name, __FUNCTION__);
657 600
658 /* Collect the TX status */ 601 /* Collect the TX status */
659 while (((SMC_GET_TX_FIFO_INF() & TX_FIFO_INF_TSUSED_) >> 16) != 0) { 602 while (((SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TSUSED_) >> 16) != 0) {
660 DBG(SMC_DEBUG_TX, "%s: Tx stat FIFO used 0x%04x\n", 603 DBG(SMC_DEBUG_TX, "%s: Tx stat FIFO used 0x%04x\n",
661 dev->name, 604 dev->name,
662 (SMC_GET_TX_FIFO_INF() & TX_FIFO_INF_TSUSED_) >> 16); 605 (SMC_GET_TX_FIFO_INF(lp) & TX_FIFO_INF_TSUSED_) >> 16);
663 tx_status = SMC_GET_TX_STS_FIFO(); 606 tx_status = SMC_GET_TX_STS_FIFO(lp);
664 dev->stats.tx_packets++; 607 dev->stats.tx_packets++;
665 dev->stats.tx_bytes+=tx_status>>16; 608 dev->stats.tx_bytes+=tx_status>>16;
666 DBG(SMC_DEBUG_TX, "%s: Tx FIFO tag 0x%04x status 0x%04x\n", 609 DBG(SMC_DEBUG_TX, "%s: Tx FIFO tag 0x%04x status 0x%04x\n",
@@ -698,10 +641,10 @@ static void smc911x_tx(struct net_device *dev)
698 641
699static int smc911x_phy_read(struct net_device *dev, int phyaddr, int phyreg) 642static int smc911x_phy_read(struct net_device *dev, int phyaddr, int phyreg)
700{ 643{
701 unsigned long ioaddr = dev->base_addr; 644 struct smc911x_local *lp = netdev_priv(dev);
702 unsigned int phydata; 645 unsigned int phydata;
703 646
704 SMC_GET_MII(phyreg, phyaddr, phydata); 647 SMC_GET_MII(lp, phyreg, phyaddr, phydata);
705 648
706 DBG(SMC_DEBUG_MISC, "%s: phyaddr=0x%x, phyreg=0x%02x, phydata=0x%04x\n", 649 DBG(SMC_DEBUG_MISC, "%s: phyaddr=0x%x, phyreg=0x%02x, phydata=0x%04x\n",
707 __FUNCTION__, phyaddr, phyreg, phydata); 650 __FUNCTION__, phyaddr, phyreg, phydata);
@@ -715,12 +658,12 @@ static int smc911x_phy_read(struct net_device *dev, int phyaddr, int phyreg)
715static void smc911x_phy_write(struct net_device *dev, int phyaddr, int phyreg, 658static void smc911x_phy_write(struct net_device *dev, int phyaddr, int phyreg,
716 int phydata) 659 int phydata)
717{ 660{
718 unsigned long ioaddr = dev->base_addr; 661 struct smc911x_local *lp = netdev_priv(dev);
719 662
720 DBG(SMC_DEBUG_MISC, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n", 663 DBG(SMC_DEBUG_MISC, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
721 __FUNCTION__, phyaddr, phyreg, phydata); 664 __FUNCTION__, phyaddr, phyreg, phydata);
722 665
723 SMC_SET_MII(phyreg, phyaddr, phydata); 666 SMC_SET_MII(lp, phyreg, phyaddr, phydata);
724} 667}
725 668
726/* 669/*
@@ -729,7 +672,6 @@ static void smc911x_phy_write(struct net_device *dev, int phyaddr, int phyreg,
729 */ 672 */
730static void smc911x_phy_detect(struct net_device *dev) 673static void smc911x_phy_detect(struct net_device *dev)
731{ 674{
732 unsigned long ioaddr = dev->base_addr;
733 struct smc911x_local *lp = netdev_priv(dev); 675 struct smc911x_local *lp = netdev_priv(dev);
734 int phyaddr; 676 int phyaddr;
735 unsigned int cfg, id1, id2; 677 unsigned int cfg, id1, id2;
@@ -745,30 +687,30 @@ static void smc911x_phy_detect(struct net_device *dev)
745 switch(lp->version) { 687 switch(lp->version) {
746 case 0x115: 688 case 0x115:
747 case 0x117: 689 case 0x117:
748 cfg = SMC_GET_HW_CFG(); 690 cfg = SMC_GET_HW_CFG(lp);
749 if (cfg & HW_CFG_EXT_PHY_DET_) { 691 if (cfg & HW_CFG_EXT_PHY_DET_) {
750 cfg &= ~HW_CFG_PHY_CLK_SEL_; 692 cfg &= ~HW_CFG_PHY_CLK_SEL_;
751 cfg |= HW_CFG_PHY_CLK_SEL_CLK_DIS_; 693 cfg |= HW_CFG_PHY_CLK_SEL_CLK_DIS_;
752 SMC_SET_HW_CFG(cfg); 694 SMC_SET_HW_CFG(lp, cfg);
753 udelay(10); /* Wait for clocks to stop */ 695 udelay(10); /* Wait for clocks to stop */
754 696
755 cfg |= HW_CFG_EXT_PHY_EN_; 697 cfg |= HW_CFG_EXT_PHY_EN_;
756 SMC_SET_HW_CFG(cfg); 698 SMC_SET_HW_CFG(lp, cfg);
757 udelay(10); /* Wait for clocks to stop */ 699 udelay(10); /* Wait for clocks to stop */
758 700
759 cfg &= ~HW_CFG_PHY_CLK_SEL_; 701 cfg &= ~HW_CFG_PHY_CLK_SEL_;
760 cfg |= HW_CFG_PHY_CLK_SEL_EXT_PHY_; 702 cfg |= HW_CFG_PHY_CLK_SEL_EXT_PHY_;
761 SMC_SET_HW_CFG(cfg); 703 SMC_SET_HW_CFG(lp, cfg);
762 udelay(10); /* Wait for clocks to stop */ 704 udelay(10); /* Wait for clocks to stop */
763 705
764 cfg |= HW_CFG_SMI_SEL_; 706 cfg |= HW_CFG_SMI_SEL_;
765 SMC_SET_HW_CFG(cfg); 707 SMC_SET_HW_CFG(lp, cfg);
766 708
767 for (phyaddr = 1; phyaddr < 32; ++phyaddr) { 709 for (phyaddr = 1; phyaddr < 32; ++phyaddr) {
768 710
769 /* Read the PHY identifiers */ 711 /* Read the PHY identifiers */
770 SMC_GET_PHY_ID1(phyaddr & 31, id1); 712 SMC_GET_PHY_ID1(lp, phyaddr & 31, id1);
771 SMC_GET_PHY_ID2(phyaddr & 31, id2); 713 SMC_GET_PHY_ID2(lp, phyaddr & 31, id2);
772 714
773 /* Make sure it is a valid identifier */ 715 /* Make sure it is a valid identifier */
774 if (id1 != 0x0000 && id1 != 0xffff && 716 if (id1 != 0x0000 && id1 != 0xffff &&
@@ -783,8 +725,8 @@ static void smc911x_phy_detect(struct net_device *dev)
783 } 725 }
784 default: 726 default:
785 /* Internal media only */ 727 /* Internal media only */
786 SMC_GET_PHY_ID1(1, id1); 728 SMC_GET_PHY_ID1(lp, 1, id1);
787 SMC_GET_PHY_ID2(1, id2); 729 SMC_GET_PHY_ID2(lp, 1, id2);
788 /* Save the PHY's address */ 730 /* Save the PHY's address */
789 lp->mii.phy_id = 1; 731 lp->mii.phy_id = 1;
790 lp->phy_type = id1 << 16 | id2; 732 lp->phy_type = id1 << 16 | id2;
@@ -801,16 +743,15 @@ static void smc911x_phy_detect(struct net_device *dev)
801static int smc911x_phy_fixed(struct net_device *dev) 743static int smc911x_phy_fixed(struct net_device *dev)
802{ 744{
803 struct smc911x_local *lp = netdev_priv(dev); 745 struct smc911x_local *lp = netdev_priv(dev);
804 unsigned long ioaddr = dev->base_addr;
805 int phyaddr = lp->mii.phy_id; 746 int phyaddr = lp->mii.phy_id;
806 int bmcr; 747 int bmcr;
807 748
808 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__); 749 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
809 750
810 /* Enter Link Disable state */ 751 /* Enter Link Disable state */
811 SMC_GET_PHY_BMCR(phyaddr, bmcr); 752 SMC_GET_PHY_BMCR(lp, phyaddr, bmcr);
812 bmcr |= BMCR_PDOWN; 753 bmcr |= BMCR_PDOWN;
813 SMC_SET_PHY_BMCR(phyaddr, bmcr); 754 SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
814 755
815 /* 756 /*
816 * Set our fixed capabilities 757 * Set our fixed capabilities
@@ -824,11 +765,11 @@ static int smc911x_phy_fixed(struct net_device *dev)
824 bmcr |= BMCR_SPEED100; 765 bmcr |= BMCR_SPEED100;
825 766
826 /* Write our capabilities to the phy control register */ 767 /* Write our capabilities to the phy control register */
827 SMC_SET_PHY_BMCR(phyaddr, bmcr); 768 SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
828 769
829 /* Re-Configure the Receive/Phy Control register */ 770 /* Re-Configure the Receive/Phy Control register */
830 bmcr &= ~BMCR_PDOWN; 771 bmcr &= ~BMCR_PDOWN;
831 SMC_SET_PHY_BMCR(phyaddr, bmcr); 772 SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
832 773
833 return 1; 774 return 1;
834} 775}
@@ -848,7 +789,6 @@ static int smc911x_phy_fixed(struct net_device *dev)
848static int smc911x_phy_reset(struct net_device *dev, int phy) 789static int smc911x_phy_reset(struct net_device *dev, int phy)
849{ 790{
850 struct smc911x_local *lp = netdev_priv(dev); 791 struct smc911x_local *lp = netdev_priv(dev);
851 unsigned long ioaddr = dev->base_addr;
852 int timeout; 792 int timeout;
853 unsigned long flags; 793 unsigned long flags;
854 unsigned int reg; 794 unsigned int reg;
@@ -856,15 +796,15 @@ static int smc911x_phy_reset(struct net_device *dev, int phy)
856 DBG(SMC_DEBUG_FUNC, "%s: --> %s()\n", dev->name, __FUNCTION__); 796 DBG(SMC_DEBUG_FUNC, "%s: --> %s()\n", dev->name, __FUNCTION__);
857 797
858 spin_lock_irqsave(&lp->lock, flags); 798 spin_lock_irqsave(&lp->lock, flags);
859 reg = SMC_GET_PMT_CTRL(); 799 reg = SMC_GET_PMT_CTRL(lp);
860 reg &= ~0xfffff030; 800 reg &= ~0xfffff030;
861 reg |= PMT_CTRL_PHY_RST_; 801 reg |= PMT_CTRL_PHY_RST_;
862 SMC_SET_PMT_CTRL(reg); 802 SMC_SET_PMT_CTRL(lp, reg);
863 spin_unlock_irqrestore(&lp->lock, flags); 803 spin_unlock_irqrestore(&lp->lock, flags);
864 for (timeout = 2; timeout; timeout--) { 804 for (timeout = 2; timeout; timeout--) {
865 msleep(50); 805 msleep(50);
866 spin_lock_irqsave(&lp->lock, flags); 806 spin_lock_irqsave(&lp->lock, flags);
867 reg = SMC_GET_PMT_CTRL(); 807 reg = SMC_GET_PMT_CTRL(lp);
868 spin_unlock_irqrestore(&lp->lock, flags); 808 spin_unlock_irqrestore(&lp->lock, flags);
869 if (!(reg & PMT_CTRL_PHY_RST_)) { 809 if (!(reg & PMT_CTRL_PHY_RST_)) {
870 /* extra delay required because the phy may 810 /* extra delay required because the phy may
@@ -889,13 +829,13 @@ static int smc911x_phy_reset(struct net_device *dev, int phy)
889 */ 829 */
890static void smc911x_phy_powerdown(struct net_device *dev, int phy) 830static void smc911x_phy_powerdown(struct net_device *dev, int phy)
891{ 831{
892 unsigned long ioaddr = dev->base_addr; 832 struct smc911x_local *lp = netdev_priv(dev);
893 unsigned int bmcr; 833 unsigned int bmcr;
894 834
895 /* Enter Link Disable state */ 835 /* Enter Link Disable state */
896 SMC_GET_PHY_BMCR(phy, bmcr); 836 SMC_GET_PHY_BMCR(lp, phy, bmcr);
897 bmcr |= BMCR_PDOWN; 837 bmcr |= BMCR_PDOWN;
898 SMC_SET_PHY_BMCR(phy, bmcr); 838 SMC_SET_PHY_BMCR(lp, phy, bmcr);
899} 839}
900 840
901/* 841/*
@@ -909,7 +849,6 @@ static void smc911x_phy_powerdown(struct net_device *dev, int phy)
909static void smc911x_phy_check_media(struct net_device *dev, int init) 849static void smc911x_phy_check_media(struct net_device *dev, int init)
910{ 850{
911 struct smc911x_local *lp = netdev_priv(dev); 851 struct smc911x_local *lp = netdev_priv(dev);
912 unsigned long ioaddr = dev->base_addr;
913 int phyaddr = lp->mii.phy_id; 852 int phyaddr = lp->mii.phy_id;
914 unsigned int bmcr, cr; 853 unsigned int bmcr, cr;
915 854
@@ -917,8 +856,8 @@ static void smc911x_phy_check_media(struct net_device *dev, int init)
917 856
918 if (mii_check_media(&lp->mii, netif_msg_link(lp), init)) { 857 if (mii_check_media(&lp->mii, netif_msg_link(lp), init)) {
919 /* duplex state has changed */ 858 /* duplex state has changed */
920 SMC_GET_PHY_BMCR(phyaddr, bmcr); 859 SMC_GET_PHY_BMCR(lp, phyaddr, bmcr);
921 SMC_GET_MAC_CR(cr); 860 SMC_GET_MAC_CR(lp, cr);
922 if (lp->mii.full_duplex) { 861 if (lp->mii.full_duplex) {
923 DBG(SMC_DEBUG_MISC, "%s: Configuring for full-duplex mode\n", dev->name); 862 DBG(SMC_DEBUG_MISC, "%s: Configuring for full-duplex mode\n", dev->name);
924 bmcr |= BMCR_FULLDPLX; 863 bmcr |= BMCR_FULLDPLX;
@@ -928,8 +867,8 @@ static void smc911x_phy_check_media(struct net_device *dev, int init)
928 bmcr &= ~BMCR_FULLDPLX; 867 bmcr &= ~BMCR_FULLDPLX;
929 cr &= ~MAC_CR_RCVOWN_; 868 cr &= ~MAC_CR_RCVOWN_;
930 } 869 }
931 SMC_SET_PHY_BMCR(phyaddr, bmcr); 870 SMC_SET_PHY_BMCR(lp, phyaddr, bmcr);
932 SMC_SET_MAC_CR(cr); 871 SMC_SET_MAC_CR(lp, cr);
933 } 872 }
934} 873}
935 874
@@ -947,7 +886,6 @@ static void smc911x_phy_configure(struct work_struct *work)
947 struct smc911x_local *lp = container_of(work, struct smc911x_local, 886 struct smc911x_local *lp = container_of(work, struct smc911x_local,
948 phy_configure); 887 phy_configure);
949 struct net_device *dev = lp->netdev; 888 struct net_device *dev = lp->netdev;
950 unsigned long ioaddr = dev->base_addr;
951 int phyaddr = lp->mii.phy_id; 889 int phyaddr = lp->mii.phy_id;
952 int my_phy_caps; /* My PHY capabilities */ 890 int my_phy_caps; /* My PHY capabilities */
953 int my_ad_caps; /* My Advertised capabilities */ 891 int my_ad_caps; /* My Advertised capabilities */
@@ -972,7 +910,7 @@ static void smc911x_phy_configure(struct work_struct *work)
972 * Enable PHY Interrupts (for register 18) 910 * Enable PHY Interrupts (for register 18)
973 * Interrupts listed here are enabled 911 * Interrupts listed here are enabled
974 */ 912 */
975 SMC_SET_PHY_INT_MASK(phyaddr, PHY_INT_MASK_ENERGY_ON_ | 913 SMC_SET_PHY_INT_MASK(lp, phyaddr, PHY_INT_MASK_ENERGY_ON_ |
976 PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_REMOTE_FAULT_ | 914 PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_REMOTE_FAULT_ |
977 PHY_INT_MASK_LINK_DOWN_); 915 PHY_INT_MASK_LINK_DOWN_);
978 916
@@ -983,7 +921,7 @@ static void smc911x_phy_configure(struct work_struct *work)
983 } 921 }
984 922
985 /* Copy our capabilities from MII_BMSR to MII_ADVERTISE */ 923 /* Copy our capabilities from MII_BMSR to MII_ADVERTISE */
986 SMC_GET_PHY_BMSR(phyaddr, my_phy_caps); 924 SMC_GET_PHY_BMSR(lp, phyaddr, my_phy_caps);
987 if (!(my_phy_caps & BMSR_ANEGCAPABLE)) { 925 if (!(my_phy_caps & BMSR_ANEGCAPABLE)) {
988 printk(KERN_INFO "Auto negotiation NOT supported\n"); 926 printk(KERN_INFO "Auto negotiation NOT supported\n");
989 smc911x_phy_fixed(dev); 927 smc911x_phy_fixed(dev);
@@ -1012,7 +950,7 @@ static void smc911x_phy_configure(struct work_struct *work)
1012 my_ad_caps &= ~(ADVERTISE_100FULL|ADVERTISE_10FULL); 950 my_ad_caps &= ~(ADVERTISE_100FULL|ADVERTISE_10FULL);
1013 951
1014 /* Update our Auto-Neg Advertisement Register */ 952 /* Update our Auto-Neg Advertisement Register */
1015 SMC_SET_PHY_MII_ADV(phyaddr, my_ad_caps); 953 SMC_SET_PHY_MII_ADV(lp, phyaddr, my_ad_caps);
1016 lp->mii.advertising = my_ad_caps; 954 lp->mii.advertising = my_ad_caps;
1017 955
1018 /* 956 /*
@@ -1021,13 +959,13 @@ static void smc911x_phy_configure(struct work_struct *work)
1021 * the link does not come up. 959 * the link does not come up.
1022 */ 960 */
1023 udelay(10); 961 udelay(10);
1024 SMC_GET_PHY_MII_ADV(phyaddr, status); 962 SMC_GET_PHY_MII_ADV(lp, phyaddr, status);
1025 963
1026 DBG(SMC_DEBUG_MISC, "%s: phy caps=0x%04x\n", dev->name, my_phy_caps); 964 DBG(SMC_DEBUG_MISC, "%s: phy caps=0x%04x\n", dev->name, my_phy_caps);
1027 DBG(SMC_DEBUG_MISC, "%s: phy advertised caps=0x%04x\n", dev->name, my_ad_caps); 965 DBG(SMC_DEBUG_MISC, "%s: phy advertised caps=0x%04x\n", dev->name, my_ad_caps);
1028 966
1029 /* Restart auto-negotiation process in order to advertise my caps */ 967 /* Restart auto-negotiation process in order to advertise my caps */
1030 SMC_SET_PHY_BMCR(phyaddr, BMCR_ANENABLE | BMCR_ANRESTART); 968 SMC_SET_PHY_BMCR(lp, phyaddr, BMCR_ANENABLE | BMCR_ANRESTART);
1031 969
1032 smc911x_phy_check_media(dev, 1); 970 smc911x_phy_check_media(dev, 1);
1033 971
@@ -1046,7 +984,6 @@ smc911x_phy_configure_exit_nolock:
1046static void smc911x_phy_interrupt(struct net_device *dev) 984static void smc911x_phy_interrupt(struct net_device *dev)
1047{ 985{
1048 struct smc911x_local *lp = netdev_priv(dev); 986 struct smc911x_local *lp = netdev_priv(dev);
1049 unsigned long ioaddr = dev->base_addr;
1050 int phyaddr = lp->mii.phy_id; 987 int phyaddr = lp->mii.phy_id;
1051 int status; 988 int status;
1052 989
@@ -1057,11 +994,11 @@ static void smc911x_phy_interrupt(struct net_device *dev)
1057 994
1058 smc911x_phy_check_media(dev, 0); 995 smc911x_phy_check_media(dev, 0);
1059 /* read to clear status bits */ 996 /* read to clear status bits */
1060 SMC_GET_PHY_INT_SRC(phyaddr,status); 997 SMC_GET_PHY_INT_SRC(lp, phyaddr,status);
1061 DBG(SMC_DEBUG_MISC, "%s: PHY interrupt status 0x%04x\n", 998 DBG(SMC_DEBUG_MISC, "%s: PHY interrupt status 0x%04x\n",
1062 dev->name, status & 0xffff); 999 dev->name, status & 0xffff);
1063 DBG(SMC_DEBUG_MISC, "%s: AFC_CFG 0x%08x\n", 1000 DBG(SMC_DEBUG_MISC, "%s: AFC_CFG 0x%08x\n",
1064 dev->name, SMC_GET_AFC_CFG()); 1001 dev->name, SMC_GET_AFC_CFG(lp));
1065} 1002}
1066 1003
1067/*--- END PHY CONTROL AND CONFIGURATION-------------------------------------*/ 1004/*--- END PHY CONTROL AND CONFIGURATION-------------------------------------*/
@@ -1073,7 +1010,6 @@ static void smc911x_phy_interrupt(struct net_device *dev)
1073static irqreturn_t smc911x_interrupt(int irq, void *dev_id) 1010static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
1074{ 1011{
1075 struct net_device *dev = dev_id; 1012 struct net_device *dev = dev_id;
1076 unsigned long ioaddr = dev->base_addr;
1077 struct smc911x_local *lp = netdev_priv(dev); 1013 struct smc911x_local *lp = netdev_priv(dev);
1078 unsigned int status, mask, timeout; 1014 unsigned int status, mask, timeout;
1079 unsigned int rx_overrun=0, cr, pkts; 1015 unsigned int rx_overrun=0, cr, pkts;
@@ -1084,21 +1020,21 @@ static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
1084 spin_lock_irqsave(&lp->lock, flags); 1020 spin_lock_irqsave(&lp->lock, flags);
1085 1021
1086 /* Spurious interrupt check */ 1022 /* Spurious interrupt check */
1087 if ((SMC_GET_IRQ_CFG() & (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) != 1023 if ((SMC_GET_IRQ_CFG(lp) & (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) !=
1088 (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) { 1024 (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) {
1089 spin_unlock_irqrestore(&lp->lock, flags); 1025 spin_unlock_irqrestore(&lp->lock, flags);
1090 return IRQ_NONE; 1026 return IRQ_NONE;
1091 } 1027 }
1092 1028
1093 mask = SMC_GET_INT_EN(); 1029 mask = SMC_GET_INT_EN(lp);
1094 SMC_SET_INT_EN(0); 1030 SMC_SET_INT_EN(lp, 0);
1095 1031
1096 /* set a timeout value, so I don't stay here forever */ 1032 /* set a timeout value, so I don't stay here forever */
1097 timeout = 8; 1033 timeout = 8;
1098 1034
1099 1035
1100 do { 1036 do {
1101 status = SMC_GET_INT(); 1037 status = SMC_GET_INT(lp);
1102 1038
1103 DBG(SMC_DEBUG_MISC, "%s: INT 0x%08x MASK 0x%08x OUTSIDE MASK 0x%08x\n", 1039 DBG(SMC_DEBUG_MISC, "%s: INT 0x%08x MASK 0x%08x OUTSIDE MASK 0x%08x\n",
1104 dev->name, status, mask, status & ~mask); 1040 dev->name, status, mask, status & ~mask);
@@ -1109,53 +1045,53 @@ static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
1109 1045
1110 /* Handle SW interrupt condition */ 1046 /* Handle SW interrupt condition */
1111 if (status & INT_STS_SW_INT_) { 1047 if (status & INT_STS_SW_INT_) {
1112 SMC_ACK_INT(INT_STS_SW_INT_); 1048 SMC_ACK_INT(lp, INT_STS_SW_INT_);
1113 mask &= ~INT_EN_SW_INT_EN_; 1049 mask &= ~INT_EN_SW_INT_EN_;
1114 } 1050 }
1115 /* Handle various error conditions */ 1051 /* Handle various error conditions */
1116 if (status & INT_STS_RXE_) { 1052 if (status & INT_STS_RXE_) {
1117 SMC_ACK_INT(INT_STS_RXE_); 1053 SMC_ACK_INT(lp, INT_STS_RXE_);
1118 dev->stats.rx_errors++; 1054 dev->stats.rx_errors++;
1119 } 1055 }
1120 if (status & INT_STS_RXDFH_INT_) { 1056 if (status & INT_STS_RXDFH_INT_) {
1121 SMC_ACK_INT(INT_STS_RXDFH_INT_); 1057 SMC_ACK_INT(lp, INT_STS_RXDFH_INT_);
1122 dev->stats.rx_dropped+=SMC_GET_RX_DROP(); 1058 dev->stats.rx_dropped+=SMC_GET_RX_DROP(lp);
1123 } 1059 }
1124 /* Undocumented interrupt-what is the right thing to do here? */ 1060 /* Undocumented interrupt-what is the right thing to do here? */
1125 if (status & INT_STS_RXDF_INT_) { 1061 if (status & INT_STS_RXDF_INT_) {
1126 SMC_ACK_INT(INT_STS_RXDF_INT_); 1062 SMC_ACK_INT(lp, INT_STS_RXDF_INT_);
1127 } 1063 }
1128 1064
1129 /* Rx Data FIFO exceeds set level */ 1065 /* Rx Data FIFO exceeds set level */
1130 if (status & INT_STS_RDFL_) { 1066 if (status & INT_STS_RDFL_) {
1131 if (IS_REV_A(lp->revision)) { 1067 if (IS_REV_A(lp->revision)) {
1132 rx_overrun=1; 1068 rx_overrun=1;
1133 SMC_GET_MAC_CR(cr); 1069 SMC_GET_MAC_CR(lp, cr);
1134 cr &= ~MAC_CR_RXEN_; 1070 cr &= ~MAC_CR_RXEN_;
1135 SMC_SET_MAC_CR(cr); 1071 SMC_SET_MAC_CR(lp, cr);
1136 DBG(SMC_DEBUG_RX, "%s: RX overrun\n", dev->name); 1072 DBG(SMC_DEBUG_RX, "%s: RX overrun\n", dev->name);
1137 dev->stats.rx_errors++; 1073 dev->stats.rx_errors++;
1138 dev->stats.rx_fifo_errors++; 1074 dev->stats.rx_fifo_errors++;
1139 } 1075 }
1140 SMC_ACK_INT(INT_STS_RDFL_); 1076 SMC_ACK_INT(lp, INT_STS_RDFL_);
1141 } 1077 }
1142 if (status & INT_STS_RDFO_) { 1078 if (status & INT_STS_RDFO_) {
1143 if (!IS_REV_A(lp->revision)) { 1079 if (!IS_REV_A(lp->revision)) {
1144 SMC_GET_MAC_CR(cr); 1080 SMC_GET_MAC_CR(lp, cr);
1145 cr &= ~MAC_CR_RXEN_; 1081 cr &= ~MAC_CR_RXEN_;
1146 SMC_SET_MAC_CR(cr); 1082 SMC_SET_MAC_CR(lp, cr);
1147 rx_overrun=1; 1083 rx_overrun=1;
1148 DBG(SMC_DEBUG_RX, "%s: RX overrun\n", dev->name); 1084 DBG(SMC_DEBUG_RX, "%s: RX overrun\n", dev->name);
1149 dev->stats.rx_errors++; 1085 dev->stats.rx_errors++;
1150 dev->stats.rx_fifo_errors++; 1086 dev->stats.rx_fifo_errors++;
1151 } 1087 }
1152 SMC_ACK_INT(INT_STS_RDFO_); 1088 SMC_ACK_INT(lp, INT_STS_RDFO_);
1153 } 1089 }
1154 /* Handle receive condition */ 1090 /* Handle receive condition */
1155 if ((status & INT_STS_RSFL_) || rx_overrun) { 1091 if ((status & INT_STS_RSFL_) || rx_overrun) {
1156 unsigned int fifo; 1092 unsigned int fifo;
1157 DBG(SMC_DEBUG_RX, "%s: RX irq\n", dev->name); 1093 DBG(SMC_DEBUG_RX, "%s: RX irq\n", dev->name);
1158 fifo = SMC_GET_RX_FIFO_INF(); 1094 fifo = SMC_GET_RX_FIFO_INF(lp);
1159 pkts = (fifo & RX_FIFO_INF_RXSUSED_) >> 16; 1095 pkts = (fifo & RX_FIFO_INF_RXSUSED_) >> 16;
1160 DBG(SMC_DEBUG_RX, "%s: Rx FIFO pkts %d, bytes %d\n", 1096 DBG(SMC_DEBUG_RX, "%s: Rx FIFO pkts %d, bytes %d\n",
1161 dev->name, pkts, fifo & 0xFFFF ); 1097 dev->name, pkts, fifo & 0xFFFF );
@@ -1166,61 +1102,61 @@ static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
1166 DBG(SMC_DEBUG_RX | SMC_DEBUG_DMA, 1102 DBG(SMC_DEBUG_RX | SMC_DEBUG_DMA,
1167 "%s: RX DMA active\n", dev->name); 1103 "%s: RX DMA active\n", dev->name);
1168 /* The DMA is already running so up the IRQ threshold */ 1104 /* The DMA is already running so up the IRQ threshold */
1169 fifo = SMC_GET_FIFO_INT() & ~0xFF; 1105 fifo = SMC_GET_FIFO_INT(lp) & ~0xFF;
1170 fifo |= pkts & 0xFF; 1106 fifo |= pkts & 0xFF;
1171 DBG(SMC_DEBUG_RX, 1107 DBG(SMC_DEBUG_RX,
1172 "%s: Setting RX stat FIFO threshold to %d\n", 1108 "%s: Setting RX stat FIFO threshold to %d\n",
1173 dev->name, fifo & 0xff); 1109 dev->name, fifo & 0xff);
1174 SMC_SET_FIFO_INT(fifo); 1110 SMC_SET_FIFO_INT(lp, fifo);
1175 } else 1111 } else
1176#endif 1112#endif
1177 smc911x_rcv(dev); 1113 smc911x_rcv(dev);
1178 } 1114 }
1179 SMC_ACK_INT(INT_STS_RSFL_); 1115 SMC_ACK_INT(lp, INT_STS_RSFL_);
1180 } 1116 }
1181 /* Handle transmit FIFO available */ 1117 /* Handle transmit FIFO available */
1182 if (status & INT_STS_TDFA_) { 1118 if (status & INT_STS_TDFA_) {
1183 DBG(SMC_DEBUG_TX, "%s: TX data FIFO space available irq\n", dev->name); 1119 DBG(SMC_DEBUG_TX, "%s: TX data FIFO space available irq\n", dev->name);
1184 SMC_SET_FIFO_TDA(0xFF); 1120 SMC_SET_FIFO_TDA(lp, 0xFF);
1185 lp->tx_throttle = 0; 1121 lp->tx_throttle = 0;
1186#ifdef SMC_USE_DMA 1122#ifdef SMC_USE_DMA
1187 if (!lp->txdma_active) 1123 if (!lp->txdma_active)
1188#endif 1124#endif
1189 netif_wake_queue(dev); 1125 netif_wake_queue(dev);
1190 SMC_ACK_INT(INT_STS_TDFA_); 1126 SMC_ACK_INT(lp, INT_STS_TDFA_);
1191 } 1127 }
1192 /* Handle transmit done condition */ 1128 /* Handle transmit done condition */
1193#if 1 1129#if 1
1194 if (status & (INT_STS_TSFL_ | INT_STS_GPT_INT_)) { 1130 if (status & (INT_STS_TSFL_ | INT_STS_GPT_INT_)) {
1195 DBG(SMC_DEBUG_TX | SMC_DEBUG_MISC, 1131 DBG(SMC_DEBUG_TX | SMC_DEBUG_MISC,
1196 "%s: Tx stat FIFO limit (%d) /GPT irq\n", 1132 "%s: Tx stat FIFO limit (%d) /GPT irq\n",
1197 dev->name, (SMC_GET_FIFO_INT() & 0x00ff0000) >> 16); 1133 dev->name, (SMC_GET_FIFO_INT(lp) & 0x00ff0000) >> 16);
1198 smc911x_tx(dev); 1134 smc911x_tx(dev);
1199 SMC_SET_GPT_CFG(GPT_CFG_TIMER_EN_ | 10000); 1135 SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000);
1200 SMC_ACK_INT(INT_STS_TSFL_); 1136 SMC_ACK_INT(lp, INT_STS_TSFL_);
1201 SMC_ACK_INT(INT_STS_TSFL_ | INT_STS_GPT_INT_); 1137 SMC_ACK_INT(lp, INT_STS_TSFL_ | INT_STS_GPT_INT_);
1202 } 1138 }
1203#else 1139#else
1204 if (status & INT_STS_TSFL_) { 1140 if (status & INT_STS_TSFL_) {
1205 DBG(SMC_DEBUG_TX, "%s: TX status FIFO limit (%d) irq \n", dev->name, ); 1141 DBG(SMC_DEBUG_TX, "%s: TX status FIFO limit (%d) irq \n", dev->name, );
1206 smc911x_tx(dev); 1142 smc911x_tx(dev);
1207 SMC_ACK_INT(INT_STS_TSFL_); 1143 SMC_ACK_INT(lp, INT_STS_TSFL_);
1208 } 1144 }
1209 1145
1210 if (status & INT_STS_GPT_INT_) { 1146 if (status & INT_STS_GPT_INT_) {
1211 DBG(SMC_DEBUG_RX, "%s: IRQ_CFG 0x%08x FIFO_INT 0x%08x RX_CFG 0x%08x\n", 1147 DBG(SMC_DEBUG_RX, "%s: IRQ_CFG 0x%08x FIFO_INT 0x%08x RX_CFG 0x%08x\n",
1212 dev->name, 1148 dev->name,
1213 SMC_GET_IRQ_CFG(), 1149 SMC_GET_IRQ_CFG(lp),
1214 SMC_GET_FIFO_INT(), 1150 SMC_GET_FIFO_INT(lp),
1215 SMC_GET_RX_CFG()); 1151 SMC_GET_RX_CFG(lp));
1216 DBG(SMC_DEBUG_RX, "%s: Rx Stat FIFO Used 0x%02x " 1152 DBG(SMC_DEBUG_RX, "%s: Rx Stat FIFO Used 0x%02x "
1217 "Data FIFO Used 0x%04x Stat FIFO 0x%08x\n", 1153 "Data FIFO Used 0x%04x Stat FIFO 0x%08x\n",
1218 dev->name, 1154 dev->name,
1219 (SMC_GET_RX_FIFO_INF() & 0x00ff0000) >> 16, 1155 (SMC_GET_RX_FIFO_INF(lp) & 0x00ff0000) >> 16,
1220 SMC_GET_RX_FIFO_INF() & 0xffff, 1156 SMC_GET_RX_FIFO_INF(lp) & 0xffff,
1221 SMC_GET_RX_STS_FIFO_PEEK()); 1157 SMC_GET_RX_STS_FIFO_PEEK(lp));
1222 SMC_SET_GPT_CFG(GPT_CFG_TIMER_EN_ | 10000); 1158 SMC_SET_GPT_CFG(lp, GPT_CFG_TIMER_EN_ | 10000);
1223 SMC_ACK_INT(INT_STS_GPT_INT_); 1159 SMC_ACK_INT(lp, INT_STS_GPT_INT_);
1224 } 1160 }
1225#endif 1161#endif
1226 1162
@@ -1228,12 +1164,12 @@ static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
1228 if (status & INT_STS_PHY_INT_) { 1164 if (status & INT_STS_PHY_INT_) {
1229 DBG(SMC_DEBUG_MISC, "%s: PHY irq\n", dev->name); 1165 DBG(SMC_DEBUG_MISC, "%s: PHY irq\n", dev->name);
1230 smc911x_phy_interrupt(dev); 1166 smc911x_phy_interrupt(dev);
1231 SMC_ACK_INT(INT_STS_PHY_INT_); 1167 SMC_ACK_INT(lp, INT_STS_PHY_INT_);
1232 } 1168 }
1233 } while (--timeout); 1169 } while (--timeout);
1234 1170
1235 /* restore mask state */ 1171 /* restore mask state */
1236 SMC_SET_INT_EN(mask); 1172 SMC_SET_INT_EN(lp, mask);
1237 1173
1238 DBG(SMC_DEBUG_MISC, "%s: Interrupt done (%d loops)\n", 1174 DBG(SMC_DEBUG_MISC, "%s: Interrupt done (%d loops)\n",
1239 dev->name, 8-timeout); 1175 dev->name, 8-timeout);
@@ -1335,22 +1271,21 @@ static void smc911x_poll_controller(struct net_device *dev)
1335static void smc911x_timeout(struct net_device *dev) 1271static void smc911x_timeout(struct net_device *dev)
1336{ 1272{
1337 struct smc911x_local *lp = netdev_priv(dev); 1273 struct smc911x_local *lp = netdev_priv(dev);
1338 unsigned long ioaddr = dev->base_addr;
1339 int status, mask; 1274 int status, mask;
1340 unsigned long flags; 1275 unsigned long flags;
1341 1276
1342 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__); 1277 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
1343 1278
1344 spin_lock_irqsave(&lp->lock, flags); 1279 spin_lock_irqsave(&lp->lock, flags);
1345 status = SMC_GET_INT(); 1280 status = SMC_GET_INT(lp);
1346 mask = SMC_GET_INT_EN(); 1281 mask = SMC_GET_INT_EN(lp);
1347 spin_unlock_irqrestore(&lp->lock, flags); 1282 spin_unlock_irqrestore(&lp->lock, flags);
1348 DBG(SMC_DEBUG_MISC, "%s: INT 0x%02x MASK 0x%02x \n", 1283 DBG(SMC_DEBUG_MISC, "%s: INT 0x%02x MASK 0x%02x \n",
1349 dev->name, status, mask); 1284 dev->name, status, mask);
1350 1285
1351 /* Dump the current TX FIFO contents and restart */ 1286 /* Dump the current TX FIFO contents and restart */
1352 mask = SMC_GET_TX_CFG(); 1287 mask = SMC_GET_TX_CFG(lp);
1353 SMC_SET_TX_CFG(mask | TX_CFG_TXS_DUMP_ | TX_CFG_TXD_DUMP_); 1288 SMC_SET_TX_CFG(lp, mask | TX_CFG_TXS_DUMP_ | TX_CFG_TXD_DUMP_);
1354 /* 1289 /*
1355 * Reconfiguring the PHY doesn't seem like a bad idea here, but 1290 * Reconfiguring the PHY doesn't seem like a bad idea here, but
1356 * smc911x_phy_configure() calls msleep() which calls schedule_timeout() 1291 * smc911x_phy_configure() calls msleep() which calls schedule_timeout()
@@ -1376,7 +1311,6 @@ static void smc911x_timeout(struct net_device *dev)
1376static void smc911x_set_multicast_list(struct net_device *dev) 1311static void smc911x_set_multicast_list(struct net_device *dev)
1377{ 1312{
1378 struct smc911x_local *lp = netdev_priv(dev); 1313 struct smc911x_local *lp = netdev_priv(dev);
1379 unsigned long ioaddr = dev->base_addr;
1380 unsigned int multicast_table[2]; 1314 unsigned int multicast_table[2];
1381 unsigned int mcr, update_multicast = 0; 1315 unsigned int mcr, update_multicast = 0;
1382 unsigned long flags; 1316 unsigned long flags;
@@ -1384,7 +1318,7 @@ static void smc911x_set_multicast_list(struct net_device *dev)
1384 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__); 1318 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
1385 1319
1386 spin_lock_irqsave(&lp->lock, flags); 1320 spin_lock_irqsave(&lp->lock, flags);
1387 SMC_GET_MAC_CR(mcr); 1321 SMC_GET_MAC_CR(lp, mcr);
1388 spin_unlock_irqrestore(&lp->lock, flags); 1322 spin_unlock_irqrestore(&lp->lock, flags);
1389 1323
1390 if (dev->flags & IFF_PROMISC) { 1324 if (dev->flags & IFF_PROMISC) {
@@ -1461,13 +1395,13 @@ static void smc911x_set_multicast_list(struct net_device *dev)
1461 } 1395 }
1462 1396
1463 spin_lock_irqsave(&lp->lock, flags); 1397 spin_lock_irqsave(&lp->lock, flags);
1464 SMC_SET_MAC_CR(mcr); 1398 SMC_SET_MAC_CR(lp, mcr);
1465 if (update_multicast) { 1399 if (update_multicast) {
1466 DBG(SMC_DEBUG_MISC, 1400 DBG(SMC_DEBUG_MISC,
1467 "%s: update mcast hash table 0x%08x 0x%08x\n", 1401 "%s: update mcast hash table 0x%08x 0x%08x\n",
1468 dev->name, multicast_table[0], multicast_table[1]); 1402 dev->name, multicast_table[0], multicast_table[1]);
1469 SMC_SET_HASHL(multicast_table[0]); 1403 SMC_SET_HASHL(lp, multicast_table[0]);
1470 SMC_SET_HASHH(multicast_table[1]); 1404 SMC_SET_HASHH(lp, multicast_table[1]);
1471 } 1405 }
1472 spin_unlock_irqrestore(&lp->lock, flags); 1406 spin_unlock_irqrestore(&lp->lock, flags);
1473} 1407}
@@ -1559,7 +1493,6 @@ static int
1559smc911x_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd) 1493smc911x_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
1560{ 1494{
1561 struct smc911x_local *lp = netdev_priv(dev); 1495 struct smc911x_local *lp = netdev_priv(dev);
1562 unsigned long ioaddr = dev->base_addr;
1563 int ret, status; 1496 int ret, status;
1564 unsigned long flags; 1497 unsigned long flags;
1565 1498
@@ -1587,7 +1520,7 @@ smc911x_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
1587 else 1520 else
1588 cmd->transceiver = XCVR_EXTERNAL; 1521 cmd->transceiver = XCVR_EXTERNAL;
1589 cmd->port = 0; 1522 cmd->port = 0;
1590 SMC_GET_PHY_SPECIAL(lp->mii.phy_id, status); 1523 SMC_GET_PHY_SPECIAL(lp, lp->mii.phy_id, status);
1591 cmd->duplex = 1524 cmd->duplex =
1592 (status & (PHY_SPECIAL_SPD_10FULL_ | PHY_SPECIAL_SPD_100FULL_)) ? 1525 (status & (PHY_SPECIAL_SPD_10FULL_ | PHY_SPECIAL_SPD_100FULL_)) ?
1593 DUPLEX_FULL : DUPLEX_HALF; 1526 DUPLEX_FULL : DUPLEX_HALF;
@@ -1668,7 +1601,6 @@ static int smc911x_ethtool_getregslen(struct net_device *dev)
1668static void smc911x_ethtool_getregs(struct net_device *dev, 1601static void smc911x_ethtool_getregs(struct net_device *dev,
1669 struct ethtool_regs* regs, void *buf) 1602 struct ethtool_regs* regs, void *buf)
1670{ 1603{
1671 unsigned long ioaddr = dev->base_addr;
1672 struct smc911x_local *lp = netdev_priv(dev); 1604 struct smc911x_local *lp = netdev_priv(dev);
1673 unsigned long flags; 1605 unsigned long flags;
1674 u32 reg,i,j=0; 1606 u32 reg,i,j=0;
@@ -1676,17 +1608,17 @@ static void smc911x_ethtool_getregs(struct net_device *dev,
1676 1608
1677 regs->version = lp->version; 1609 regs->version = lp->version;
1678 for(i=ID_REV;i<=E2P_CMD;i+=4) { 1610 for(i=ID_REV;i<=E2P_CMD;i+=4) {
1679 data[j++] = SMC_inl(ioaddr,i); 1611 data[j++] = SMC_inl(lp, i);
1680 } 1612 }
1681 for(i=MAC_CR;i<=WUCSR;i++) { 1613 for(i=MAC_CR;i<=WUCSR;i++) {
1682 spin_lock_irqsave(&lp->lock, flags); 1614 spin_lock_irqsave(&lp->lock, flags);
1683 SMC_GET_MAC_CSR(i, reg); 1615 SMC_GET_MAC_CSR(lp, i, reg);
1684 spin_unlock_irqrestore(&lp->lock, flags); 1616 spin_unlock_irqrestore(&lp->lock, flags);
1685 data[j++] = reg; 1617 data[j++] = reg;
1686 } 1618 }
1687 for(i=0;i<=31;i++) { 1619 for(i=0;i<=31;i++) {
1688 spin_lock_irqsave(&lp->lock, flags); 1620 spin_lock_irqsave(&lp->lock, flags);
1689 SMC_GET_MII(i, lp->mii.phy_id, reg); 1621 SMC_GET_MII(lp, i, lp->mii.phy_id, reg);
1690 spin_unlock_irqrestore(&lp->lock, flags); 1622 spin_unlock_irqrestore(&lp->lock, flags);
1691 data[j++] = reg & 0xFFFF; 1623 data[j++] = reg & 0xFFFF;
1692 } 1624 }
@@ -1694,11 +1626,11 @@ static void smc911x_ethtool_getregs(struct net_device *dev,
1694 1626
1695static int smc911x_ethtool_wait_eeprom_ready(struct net_device *dev) 1627static int smc911x_ethtool_wait_eeprom_ready(struct net_device *dev)
1696{ 1628{
1697 unsigned long ioaddr = dev->base_addr; 1629 struct smc911x_local *lp = netdev_priv(dev);
1698 unsigned int timeout; 1630 unsigned int timeout;
1699 int e2p_cmd; 1631 int e2p_cmd;
1700 1632
1701 e2p_cmd = SMC_GET_E2P_CMD(); 1633 e2p_cmd = SMC_GET_E2P_CMD(lp);
1702 for(timeout=10;(e2p_cmd & E2P_CMD_EPC_BUSY_) && timeout; timeout--) { 1634 for(timeout=10;(e2p_cmd & E2P_CMD_EPC_BUSY_) && timeout; timeout--) {
1703 if (e2p_cmd & E2P_CMD_EPC_TIMEOUT_) { 1635 if (e2p_cmd & E2P_CMD_EPC_TIMEOUT_) {
1704 PRINTK("%s: %s timeout waiting for EEPROM to respond\n", 1636 PRINTK("%s: %s timeout waiting for EEPROM to respond\n",
@@ -1706,7 +1638,7 @@ static int smc911x_ethtool_wait_eeprom_ready(struct net_device *dev)
1706 return -EFAULT; 1638 return -EFAULT;
1707 } 1639 }
1708 mdelay(1); 1640 mdelay(1);
1709 e2p_cmd = SMC_GET_E2P_CMD(); 1641 e2p_cmd = SMC_GET_E2P_CMD(lp);
1710 } 1642 }
1711 if (timeout == 0) { 1643 if (timeout == 0) {
1712 PRINTK("%s: %s timeout waiting for EEPROM CMD not busy\n", 1644 PRINTK("%s: %s timeout waiting for EEPROM CMD not busy\n",
@@ -1719,12 +1651,12 @@ static int smc911x_ethtool_wait_eeprom_ready(struct net_device *dev)
1719static inline int smc911x_ethtool_write_eeprom_cmd(struct net_device *dev, 1651static inline int smc911x_ethtool_write_eeprom_cmd(struct net_device *dev,
1720 int cmd, int addr) 1652 int cmd, int addr)
1721{ 1653{
1722 unsigned long ioaddr = dev->base_addr; 1654 struct smc911x_local *lp = netdev_priv(dev);
1723 int ret; 1655 int ret;
1724 1656
1725 if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0) 1657 if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
1726 return ret; 1658 return ret;
1727 SMC_SET_E2P_CMD(E2P_CMD_EPC_BUSY_ | 1659 SMC_SET_E2P_CMD(lp, E2P_CMD_EPC_BUSY_ |
1728 ((cmd) & (0x7<<28)) | 1660 ((cmd) & (0x7<<28)) |
1729 ((addr) & 0xFF)); 1661 ((addr) & 0xFF));
1730 return 0; 1662 return 0;
@@ -1733,24 +1665,24 @@ static inline int smc911x_ethtool_write_eeprom_cmd(struct net_device *dev,
1733static inline int smc911x_ethtool_read_eeprom_byte(struct net_device *dev, 1665static inline int smc911x_ethtool_read_eeprom_byte(struct net_device *dev,
1734 u8 *data) 1666 u8 *data)
1735{ 1667{
1736 unsigned long ioaddr = dev->base_addr; 1668 struct smc911x_local *lp = netdev_priv(dev);
1737 int ret; 1669 int ret;
1738 1670
1739 if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0) 1671 if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
1740 return ret; 1672 return ret;
1741 *data = SMC_GET_E2P_DATA(); 1673 *data = SMC_GET_E2P_DATA(lp);
1742 return 0; 1674 return 0;
1743} 1675}
1744 1676
1745static inline int smc911x_ethtool_write_eeprom_byte(struct net_device *dev, 1677static inline int smc911x_ethtool_write_eeprom_byte(struct net_device *dev,
1746 u8 data) 1678 u8 data)
1747{ 1679{
1748 unsigned long ioaddr = dev->base_addr; 1680 struct smc911x_local *lp = netdev_priv(dev);
1749 int ret; 1681 int ret;
1750 1682
1751 if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0) 1683 if ((ret = smc911x_ethtool_wait_eeprom_ready(dev))!=0)
1752 return ret; 1684 return ret;
1753 SMC_SET_E2P_DATA(data); 1685 SMC_SET_E2P_DATA(lp, data);
1754 return 0; 1686 return 0;
1755} 1687}
1756 1688
@@ -1817,8 +1749,9 @@ static const struct ethtool_ops smc911x_ethtool_ops = {
1817 * This routine has a simple purpose -- make the SMC chip generate an 1749 * This routine has a simple purpose -- make the SMC chip generate an
1818 * interrupt, so an auto-detect routine can detect it, and find the IRQ, 1750 * interrupt, so an auto-detect routine can detect it, and find the IRQ,
1819 */ 1751 */
1820static int __init smc911x_findirq(unsigned long ioaddr) 1752static int __init smc911x_findirq(struct net_device *dev)
1821{ 1753{
1754 struct smc911x_local *lp = netdev_priv(dev);
1822 int timeout = 20; 1755 int timeout = 20;
1823 unsigned long cookie; 1756 unsigned long cookie;
1824 1757
@@ -1830,7 +1763,7 @@ static int __init smc911x_findirq(unsigned long ioaddr)
1830 * Force a SW interrupt 1763 * Force a SW interrupt
1831 */ 1764 */
1832 1765
1833 SMC_SET_INT_EN(INT_EN_SW_INT_EN_); 1766 SMC_SET_INT_EN(lp, INT_EN_SW_INT_EN_);
1834 1767
1835 /* 1768 /*
1836 * Wait until positive that the interrupt has been generated 1769 * Wait until positive that the interrupt has been generated
@@ -1838,7 +1771,7 @@ static int __init smc911x_findirq(unsigned long ioaddr)
1838 do { 1771 do {
1839 int int_status; 1772 int int_status;
1840 udelay(10); 1773 udelay(10);
1841 int_status = SMC_GET_INT_EN(); 1774 int_status = SMC_GET_INT_EN(lp);
1842 if (int_status & INT_EN_SW_INT_EN_) 1775 if (int_status & INT_EN_SW_INT_EN_)
1843 break; /* got the interrupt */ 1776 break; /* got the interrupt */
1844 } while (--timeout); 1777 } while (--timeout);
@@ -1851,7 +1784,7 @@ static int __init smc911x_findirq(unsigned long ioaddr)
1851 */ 1784 */
1852 1785
1853 /* and disable all interrupts again */ 1786 /* and disable all interrupts again */
1854 SMC_SET_INT_EN(0); 1787 SMC_SET_INT_EN(lp, 0);
1855 1788
1856 /* and return what I found */ 1789 /* and return what I found */
1857 return probe_irq_off(cookie); 1790 return probe_irq_off(cookie);
@@ -1880,17 +1813,18 @@ static int __init smc911x_findirq(unsigned long ioaddr)
1880 * o actually GRAB the irq. 1813 * o actually GRAB the irq.
1881 * o GRAB the region 1814 * o GRAB the region
1882 */ 1815 */
1883static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr) 1816static int __init smc911x_probe(struct net_device *dev)
1884{ 1817{
1885 struct smc911x_local *lp = netdev_priv(dev); 1818 struct smc911x_local *lp = netdev_priv(dev);
1886 int i, retval; 1819 int i, retval;
1887 unsigned int val, chip_id, revision; 1820 unsigned int val, chip_id, revision;
1888 const char *version_string; 1821 const char *version_string;
1822 unsigned long irq_flags;
1889 1823
1890 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__); 1824 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
1891 1825
1892 /* First, see if the endian word is recognized */ 1826 /* First, see if the endian word is recognized */
1893 val = SMC_GET_BYTE_TEST(); 1827 val = SMC_GET_BYTE_TEST(lp);
1894 DBG(SMC_DEBUG_MISC, "%s: endian probe returned 0x%04x\n", CARDNAME, val); 1828 DBG(SMC_DEBUG_MISC, "%s: endian probe returned 0x%04x\n", CARDNAME, val);
1895 if (val != 0x87654321) { 1829 if (val != 0x87654321) {
1896 printk(KERN_ERR "Invalid chip endian 0x08%x\n",val); 1830 printk(KERN_ERR "Invalid chip endian 0x08%x\n",val);
@@ -1903,7 +1837,7 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
1903 * recognize. These might need to be added to later, 1837 * recognize. These might need to be added to later,
1904 * as future revisions could be added. 1838 * as future revisions could be added.
1905 */ 1839 */
1906 chip_id = SMC_GET_PN(); 1840 chip_id = SMC_GET_PN(lp);
1907 DBG(SMC_DEBUG_MISC, "%s: id probe returned 0x%04x\n", CARDNAME, chip_id); 1841 DBG(SMC_DEBUG_MISC, "%s: id probe returned 0x%04x\n", CARDNAME, chip_id);
1908 for(i=0;chip_ids[i].id != 0; i++) { 1842 for(i=0;chip_ids[i].id != 0; i++) {
1909 if (chip_ids[i].id == chip_id) break; 1843 if (chip_ids[i].id == chip_id) break;
@@ -1915,7 +1849,7 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
1915 } 1849 }
1916 version_string = chip_ids[i].name; 1850 version_string = chip_ids[i].name;
1917 1851
1918 revision = SMC_GET_REV(); 1852 revision = SMC_GET_REV(lp);
1919 DBG(SMC_DEBUG_MISC, "%s: revision = 0x%04x\n", CARDNAME, revision); 1853 DBG(SMC_DEBUG_MISC, "%s: revision = 0x%04x\n", CARDNAME, revision);
1920 1854
1921 /* At this point I'll assume that the chip is an SMC911x. */ 1855 /* At this point I'll assume that the chip is an SMC911x. */
@@ -1929,7 +1863,6 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
1929 } 1863 }
1930 1864
1931 /* fill in some of the fields */ 1865 /* fill in some of the fields */
1932 dev->base_addr = ioaddr;
1933 lp->version = chip_ids[i].id; 1866 lp->version = chip_ids[i].id;
1934 lp->revision = revision; 1867 lp->revision = revision;
1935 lp->tx_fifo_kb = tx_fifo_kb; 1868 lp->tx_fifo_kb = tx_fifo_kb;
@@ -1988,7 +1921,7 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
1988 spin_lock_init(&lp->lock); 1921 spin_lock_init(&lp->lock);
1989 1922
1990 /* Get the MAC address */ 1923 /* Get the MAC address */
1991 SMC_GET_MAC_ADDR(dev->dev_addr); 1924 SMC_GET_MAC_ADDR(lp, dev->dev_addr);
1992 1925
1993 /* now, reset the chip, and put it into a known state */ 1926 /* now, reset the chip, and put it into a known state */
1994 smc911x_reset(dev); 1927 smc911x_reset(dev);
@@ -2005,7 +1938,7 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
2005 1938
2006 trials = 3; 1939 trials = 3;
2007 while (trials--) { 1940 while (trials--) {
2008 dev->irq = smc911x_findirq(ioaddr); 1941 dev->irq = smc911x_findirq(dev);
2009 if (dev->irq) 1942 if (dev->irq)
2010 break; 1943 break;
2011 /* kick the card and try again */ 1944 /* kick the card and try again */
@@ -2053,9 +1986,15 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
2053 lp->ctl_rfduplx = 1; 1986 lp->ctl_rfduplx = 1;
2054 lp->ctl_rspeed = 100; 1987 lp->ctl_rspeed = 100;
2055 1988
1989#ifdef SMC_DYNAMIC_BUS_CONFIG
1990 irq_flags = lp->cfg.irq_flags;
1991#else
1992 irq_flags = IRQF_SHARED | SMC_IRQ_SENSE;
1993#endif
1994
2056 /* Grab the IRQ */ 1995 /* Grab the IRQ */
2057 retval = request_irq(dev->irq, &smc911x_interrupt, 1996 retval = request_irq(dev->irq, &smc911x_interrupt,
2058 IRQF_SHARED | SMC_IRQ_SENSE, dev->name, dev); 1997 irq_flags, dev->name, dev);
2059 if (retval) 1998 if (retval)
2060 goto err_out; 1999 goto err_out;
2061 2000
@@ -2125,6 +2064,7 @@ err_out:
2125 */ 2064 */
2126static int smc911x_drv_probe(struct platform_device *pdev) 2065static int smc911x_drv_probe(struct platform_device *pdev)
2127{ 2066{
2067 struct smc91x_platdata *pd = pdev->dev.platform_data;
2128 struct net_device *ndev; 2068 struct net_device *ndev;
2129 struct resource *res; 2069 struct resource *res;
2130 struct smc911x_local *lp; 2070 struct smc911x_local *lp;
@@ -2158,6 +2098,13 @@ static int smc911x_drv_probe(struct platform_device *pdev)
2158 ndev->irq = platform_get_irq(pdev, 0); 2098 ndev->irq = platform_get_irq(pdev, 0);
2159 lp = netdev_priv(ndev); 2099 lp = netdev_priv(ndev);
2160 lp->netdev = ndev; 2100 lp->netdev = ndev;
2101#ifdef SMC_DYNAMIC_BUS_CONFIG
2102 if (!pd) {
2103 ret = -EINVAL;
2104 goto release_both;
2105 }
2106 memcpy(&lp->cfg, pd, sizeof(lp->cfg));
2107#endif
2161 2108
2162 addr = ioremap(res->start, SMC911X_IO_EXTENT); 2109 addr = ioremap(res->start, SMC911X_IO_EXTENT);
2163 if (!addr) { 2110 if (!addr) {
@@ -2166,7 +2113,9 @@ static int smc911x_drv_probe(struct platform_device *pdev)
2166 } 2113 }
2167 2114
2168 platform_set_drvdata(pdev, ndev); 2115 platform_set_drvdata(pdev, ndev);
2169 ret = smc911x_probe(ndev, (unsigned long)addr); 2116 lp->base = addr;
2117 ndev->base_addr = res->start;
2118 ret = smc911x_probe(ndev);
2170 if (ret != 0) { 2119 if (ret != 0) {
2171 platform_set_drvdata(pdev, NULL); 2120 platform_set_drvdata(pdev, NULL);
2172 iounmap(addr); 2121 iounmap(addr);
@@ -2190,6 +2139,7 @@ out:
2190static int smc911x_drv_remove(struct platform_device *pdev) 2139static int smc911x_drv_remove(struct platform_device *pdev)
2191{ 2140{
2192 struct net_device *ndev = platform_get_drvdata(pdev); 2141 struct net_device *ndev = platform_get_drvdata(pdev);
2142 struct smc911x_local *lp = netdev_priv(ndev);
2193 struct resource *res; 2143 struct resource *res;
2194 2144
2195 DBG(SMC_DEBUG_FUNC, "--> %s\n", __FUNCTION__); 2145 DBG(SMC_DEBUG_FUNC, "--> %s\n", __FUNCTION__);
@@ -2201,7 +2151,6 @@ static int smc911x_drv_remove(struct platform_device *pdev)
2201 2151
2202#ifdef SMC_USE_DMA 2152#ifdef SMC_USE_DMA
2203 { 2153 {
2204 struct smc911x_local *lp = netdev_priv(ndev);
2205 if (lp->rxdma != -1) { 2154 if (lp->rxdma != -1) {
2206 SMC_DMA_FREE(dev, lp->rxdma); 2155 SMC_DMA_FREE(dev, lp->rxdma);
2207 } 2156 }
@@ -2210,7 +2159,7 @@ static int smc911x_drv_remove(struct platform_device *pdev)
2210 } 2159 }
2211 } 2160 }
2212#endif 2161#endif
2213 iounmap((void *)ndev->base_addr); 2162 iounmap(lp->base);
2214 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2163 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2215 release_mem_region(res->start, SMC911X_IO_EXTENT); 2164 release_mem_region(res->start, SMC911X_IO_EXTENT);
2216 2165
@@ -2221,7 +2170,7 @@ static int smc911x_drv_remove(struct platform_device *pdev)
2221static int smc911x_drv_suspend(struct platform_device *dev, pm_message_t state) 2170static int smc911x_drv_suspend(struct platform_device *dev, pm_message_t state)
2222{ 2171{
2223 struct net_device *ndev = platform_get_drvdata(dev); 2172 struct net_device *ndev = platform_get_drvdata(dev);
2224 unsigned long ioaddr = ndev->base_addr; 2173 struct smc911x_local *lp = netdev_priv(ndev);
2225 2174
2226 DBG(SMC_DEBUG_FUNC, "--> %s\n", __FUNCTION__); 2175 DBG(SMC_DEBUG_FUNC, "--> %s\n", __FUNCTION__);
2227 if (ndev) { 2176 if (ndev) {
@@ -2230,7 +2179,7 @@ static int smc911x_drv_suspend(struct platform_device *dev, pm_message_t state)
2230 smc911x_shutdown(ndev); 2179 smc911x_shutdown(ndev);
2231#if POWER_DOWN 2180#if POWER_DOWN
2232 /* Set D2 - Energy detect only setting */ 2181 /* Set D2 - Energy detect only setting */
2233 SMC_SET_PMT_CTRL(2<<12); 2182 SMC_SET_PMT_CTRL(lp, 2<<12);
2234#endif 2183#endif
2235 } 2184 }
2236 } 2185 }
diff --git a/drivers/net/smc911x.h b/drivers/net/smc911x.h
index 7defa63b9c74..7cc7cd7e99cd 100644
--- a/drivers/net/smc911x.h
+++ b/drivers/net/smc911x.h
@@ -29,6 +29,7 @@
29#ifndef _SMC911X_H_ 29#ifndef _SMC911X_H_
30#define _SMC911X_H_ 30#define _SMC911X_H_
31 31
32#include <linux/smc911x.h>
32/* 33/*
33 * Use the DMA feature on PXA chips 34 * Use the DMA feature on PXA chips
34 */ 35 */
@@ -38,42 +39,161 @@
38 #define SMC_USE_32BIT 1 39 #define SMC_USE_32BIT 1
39 #define SMC_IRQ_SENSE IRQF_TRIGGER_FALLING 40 #define SMC_IRQ_SENSE IRQF_TRIGGER_FALLING
40#elif defined(CONFIG_SH_MAGIC_PANEL_R2) 41#elif defined(CONFIG_SH_MAGIC_PANEL_R2)
41 #define SMC_USE_SH_DMA 0
42 #define SMC_USE_16BIT 0 42 #define SMC_USE_16BIT 0
43 #define SMC_USE_32BIT 1 43 #define SMC_USE_32BIT 1
44 #define SMC_IRQ_SENSE IRQF_TRIGGER_LOW 44 #define SMC_IRQ_SENSE IRQF_TRIGGER_LOW
45#else
46/*
47 * Default configuration
48 */
49
50#define SMC_DYNAMIC_BUS_CONFIG
45#endif 51#endif
46 52
53/* store this information for the driver.. */
54struct smc911x_local {
55 /*
56 * If I have to wait until the DMA is finished and ready to reload a
57 * packet, I will store the skbuff here. Then, the DMA will send it
58 * out and free it.
59 */
60 struct sk_buff *pending_tx_skb;
61
62 /* version/revision of the SMC911x chip */
63 u16 version;
64 u16 revision;
65
66 /* FIFO sizes */
67 int tx_fifo_kb;
68 int tx_fifo_size;
69 int rx_fifo_size;
70 int afc_cfg;
71
72 /* Contains the current active receive/phy mode */
73 int ctl_rfduplx;
74 int ctl_rspeed;
75
76 u32 msg_enable;
77 u32 phy_type;
78 struct mii_if_info mii;
79
80 /* work queue */
81 struct work_struct phy_configure;
82 int work_pending;
83
84 int tx_throttle;
85 spinlock_t lock;
86
87 struct net_device *netdev;
88
89#ifdef SMC_USE_DMA
90 /* DMA needs the physical address of the chip */
91 u_long physaddr;
92 int rxdma;
93 int txdma;
94 int rxdma_active;
95 int txdma_active;
96 struct sk_buff *current_rx_skb;
97 struct sk_buff *current_tx_skb;
98 struct device *dev;
99#endif
100 void __iomem *base;
101#ifdef SMC_DYNAMIC_BUS_CONFIG
102 struct smc911x_platdata cfg;
103#endif
104};
47 105
48/* 106/*
49 * Define the bus width specific IO macros 107 * Define the bus width specific IO macros
50 */ 108 */
51 109
110#ifdef SMC_DYNAMIC_BUS_CONFIG
111static inline unsigned int SMC_inl(struct smc911x_local *lp, int reg)
112{
113 void __iomem *ioaddr = lp->base + reg;
114
115 if (lp->cfg.flags & SMC911X_USE_32BIT)
116 return readl(ioaddr);
117
118 if (lp->cfg.flags & SMC911X_USE_16BIT)
119 return readw(ioaddr) | (readw(ioaddr + 2) << 16);
120
121 BUG();
122}
123
124static inline void SMC_outl(unsigned int value, struct smc911x_local *lp,
125 int reg)
126{
127 void __iomem *ioaddr = lp->base + reg;
128
129 if (lp->cfg.flags & SMC911X_USE_32BIT) {
130 writel(value, ioaddr);
131 return;
132 }
133
134 if (lp->cfg.flags & SMC911X_USE_16BIT) {
135 writew(value & 0xffff, ioaddr);
136 writew(value >> 16, ioaddr + 2);
137 return;
138 }
139
140 BUG();
141}
142
143static inline void SMC_insl(struct smc911x_local *lp, int reg,
144 void *addr, unsigned int count)
145{
146 void __iomem *ioaddr = lp->base + reg;
147
148 if (lp->cfg.flags & SMC911X_USE_32BIT) {
149 readsl(ioaddr, addr, count);
150 return;
151 }
152
153 if (lp->cfg.flags & SMC911X_USE_16BIT) {
154 readsw(ioaddr, addr, count * 2);
155 return;
156 }
157
158 BUG();
159}
160
161static inline void SMC_outsl(struct smc911x_local *lp, int reg,
162 void *addr, unsigned int count)
163{
164 void __iomem *ioaddr = lp->base + reg;
165
166 if (lp->cfg.flags & SMC911X_USE_32BIT) {
167 writesl(ioaddr, addr, count);
168 return;
169 }
170
171 if (lp->cfg.flags & SMC911X_USE_16BIT) {
172 writesw(ioaddr, addr, count * 2);
173 return;
174 }
175
176 BUG();
177}
178#else
52#if SMC_USE_16BIT 179#if SMC_USE_16BIT
53#define SMC_inb(a, r) readb((a) + (r)) 180#define SMC_inl(lp, r) ((readw((lp)->base + (r)) & 0xFFFF) + (readw((lp)->base + (r) + 2) << 16))
54#define SMC_inw(a, r) readw((a) + (r)) 181#define SMC_outl(v, lp, r) \
55#define SMC_inl(a, r) ((SMC_inw(a, r) & 0xFFFF)+(SMC_inw(a+2, r)<<16))
56#define SMC_outb(v, a, r) writeb(v, (a) + (r))
57#define SMC_outw(v, a, r) writew(v, (a) + (r))
58#define SMC_outl(v, a, r) \
59 do{ \ 182 do{ \
60 writel(v & 0xFFFF, (a) + (r)); \ 183 writew(v & 0xFFFF, (lp)->base + (r)); \
61 writel(v >> 16, (a) + (r) + 2); \ 184 writew(v >> 16, (lp)->base + (r) + 2); \
62 } while (0) 185 } while (0)
63#define SMC_insl(a, r, p, l) readsw((short*)((a) + (r)), p, l*2) 186#define SMC_insl(lp, r, p, l) readsw((short*)((lp)->base + (r)), p, l*2)
64#define SMC_outsl(a, r, p, l) writesw((short*)((a) + (r)), p, l*2) 187#define SMC_outsl(lp, r, p, l) writesw((short*)((lp)->base + (r)), p, l*2)
65 188
66#elif SMC_USE_32BIT 189#elif SMC_USE_32BIT
67#define SMC_inb(a, r) readb((a) + (r)) 190#define SMC_inl(lp, r) readl((lp)->base + (r))
68#define SMC_inw(a, r) readw((a) + (r)) 191#define SMC_outl(v, lp, r) writel(v, (lp)->base + (r))
69#define SMC_inl(a, r) readl((a) + (r)) 192#define SMC_insl(lp, r, p, l) readsl((int*)((lp)->base + (r)), p, l)
70#define SMC_outb(v, a, r) writeb(v, (a) + (r)) 193#define SMC_outsl(lp, r, p, l) writesl((int*)((lp)->base + (r)), p, l)
71#define SMC_outl(v, a, r) writel(v, (a) + (r))
72#define SMC_insl(a, r, p, l) readsl((int*)((a) + (r)), p, l)
73#define SMC_outsl(a, r, p, l) writesl((int*)((a) + (r)), p, l)
74 194
75#endif /* SMC_USE_16BIT */ 195#endif /* SMC_USE_16BIT */
76 196#endif /* SMC_DYNAMIC_BUS_CONFIG */
77 197
78 198
79#ifdef SMC_USE_PXA_DMA 199#ifdef SMC_USE_PXA_DMA
@@ -110,22 +230,22 @@ static int rx_dmalen, tx_dmalen;
110 230
111#ifdef SMC_insl 231#ifdef SMC_insl
112#undef SMC_insl 232#undef SMC_insl
113#define SMC_insl(a, r, p, l) \ 233#define SMC_insl(lp, r, p, l) \
114 smc_pxa_dma_insl(lp->dev, a, lp->physaddr, r, lp->rxdma, p, l) 234 smc_pxa_dma_insl(lp, lp->physaddr, r, lp->rxdma, p, l)
115 235
116static inline void 236static inline void
117smc_pxa_dma_insl(struct device *dev, u_long ioaddr, u_long physaddr, 237smc_pxa_dma_insl(struct smc911x_local *lp, u_long physaddr,
118 int reg, int dma, u_char *buf, int len) 238 int reg, int dma, u_char *buf, int len)
119{ 239{
120 /* 64 bit alignment is required for memory to memory DMA */ 240 /* 64 bit alignment is required for memory to memory DMA */
121 if ((long)buf & 4) { 241 if ((long)buf & 4) {
122 *((u32 *)buf) = SMC_inl(ioaddr, reg); 242 *((u32 *)buf) = SMC_inl(lp, reg);
123 buf += 4; 243 buf += 4;
124 len--; 244 len--;
125 } 245 }
126 246
127 len *= 4; 247 len *= 4;
128 rx_dmabuf = dma_map_single(dev, buf, len, DMA_FROM_DEVICE); 248 rx_dmabuf = dma_map_single(lp->dev, buf, len, DMA_FROM_DEVICE);
129 rx_dmalen = len; 249 rx_dmalen = len;
130 DCSR(dma) = DCSR_NODESC; 250 DCSR(dma) = DCSR_NODESC;
131 DTADR(dma) = rx_dmabuf; 251 DTADR(dma) = rx_dmabuf;
@@ -136,52 +256,24 @@ smc_pxa_dma_insl(struct device *dev, u_long ioaddr, u_long physaddr,
136} 256}
137#endif 257#endif
138 258
139#ifdef SMC_insw
140#undef SMC_insw
141#define SMC_insw(a, r, p, l) \
142 smc_pxa_dma_insw(lp->dev, a, lp->physaddr, r, lp->rxdma, p, l)
143
144static inline void
145smc_pxa_dma_insw(struct device *dev, u_long ioaddr, u_long physaddr,
146 int reg, int dma, u_char *buf, int len)
147{
148 /* 64 bit alignment is required for memory to memory DMA */
149 while ((long)buf & 6) {
150 *((u16 *)buf) = SMC_inw(ioaddr, reg);
151 buf += 2;
152 len--;
153 }
154
155 len *= 2;
156 rx_dmabuf = dma_map_single(dev, buf, len, DMA_FROM_DEVICE);
157 rx_dmalen = len;
158 DCSR(dma) = DCSR_NODESC;
159 DTADR(dma) = rx_dmabuf;
160 DSADR(dma) = physaddr + reg;
161 DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
162 DCMD_WIDTH2 | DCMD_ENDIRQEN | (DCMD_LENGTH & rx_dmalen));
163 DCSR(dma) = DCSR_NODESC | DCSR_RUN;
164}
165#endif
166
167#ifdef SMC_outsl 259#ifdef SMC_outsl
168#undef SMC_outsl 260#undef SMC_outsl
169#define SMC_outsl(a, r, p, l) \ 261#define SMC_outsl(lp, r, p, l) \
170 smc_pxa_dma_outsl(lp->dev, a, lp->physaddr, r, lp->txdma, p, l) 262 smc_pxa_dma_outsl(lp, lp->physaddr, r, lp->txdma, p, l)
171 263
172static inline void 264static inline void
173smc_pxa_dma_outsl(struct device *dev, u_long ioaddr, u_long physaddr, 265smc_pxa_dma_outsl(struct smc911x_local *lp, u_long physaddr,
174 int reg, int dma, u_char *buf, int len) 266 int reg, int dma, u_char *buf, int len)
175{ 267{
176 /* 64 bit alignment is required for memory to memory DMA */ 268 /* 64 bit alignment is required for memory to memory DMA */
177 if ((long)buf & 4) { 269 if ((long)buf & 4) {
178 SMC_outl(*((u32 *)buf), ioaddr, reg); 270 SMC_outl(*((u32 *)buf), lp, reg);
179 buf += 4; 271 buf += 4;
180 len--; 272 len--;
181 } 273 }
182 274
183 len *= 4; 275 len *= 4;
184 tx_dmabuf = dma_map_single(dev, buf, len, DMA_TO_DEVICE); 276 tx_dmabuf = dma_map_single(lp->dev, buf, len, DMA_TO_DEVICE);
185 tx_dmalen = len; 277 tx_dmalen = len;
186 DCSR(dma) = DCSR_NODESC; 278 DCSR(dma) = DCSR_NODESC;
187 DSADR(dma) = tx_dmabuf; 279 DSADR(dma) = tx_dmabuf;
@@ -191,35 +283,6 @@ smc_pxa_dma_outsl(struct device *dev, u_long ioaddr, u_long physaddr,
191 DCSR(dma) = DCSR_NODESC | DCSR_RUN; 283 DCSR(dma) = DCSR_NODESC | DCSR_RUN;
192} 284}
193#endif 285#endif
194
195#ifdef SMC_outsw
196#undef SMC_outsw
197#define SMC_outsw(a, r, p, l) \
198 smc_pxa_dma_outsw(lp->dev, a, lp->physaddr, r, lp->txdma, p, l)
199
200static inline void
201smc_pxa_dma_outsw(struct device *dev, u_long ioaddr, u_long physaddr,
202 int reg, int dma, u_char *buf, int len)
203{
204 /* 64 bit alignment is required for memory to memory DMA */
205 while ((long)buf & 6) {
206 SMC_outw(*((u16 *)buf), ioaddr, reg);
207 buf += 2;
208 len--;
209 }
210
211 len *= 2;
212 tx_dmabuf = dma_map_single(dev, buf, len, DMA_TO_DEVICE);
213 tx_dmalen = len;
214 DCSR(dma) = DCSR_NODESC;
215 DSADR(dma) = tx_dmabuf;
216 DTADR(dma) = physaddr + reg;
217 DCMD(dma) = (DCMD_INCSRCADDR | DCMD_BURST32 |
218 DCMD_WIDTH2 | DCMD_ENDIRQEN | (DCMD_LENGTH & tx_dmalen));
219 DCSR(dma) = DCSR_NODESC | DCSR_RUN;
220}
221#endif
222
223#endif /* SMC_USE_PXA_DMA */ 286#endif /* SMC_USE_PXA_DMA */
224 287
225 288
@@ -629,213 +692,213 @@ static const struct chip_id chip_ids[] = {
629 * capabilities. Please use those and not the in/out primitives. 692 * capabilities. Please use those and not the in/out primitives.
630 */ 693 */
631/* FIFO read/write macros */ 694/* FIFO read/write macros */
632#define SMC_PUSH_DATA(p, l) SMC_outsl( ioaddr, TX_DATA_FIFO, p, (l) >> 2 ) 695#define SMC_PUSH_DATA(lp, p, l) SMC_outsl( lp, TX_DATA_FIFO, p, (l) >> 2 )
633#define SMC_PULL_DATA(p, l) SMC_insl ( ioaddr, RX_DATA_FIFO, p, (l) >> 2 ) 696#define SMC_PULL_DATA(lp, p, l) SMC_insl ( lp, RX_DATA_FIFO, p, (l) >> 2 )
634#define SMC_SET_TX_FIFO(x) SMC_outl( x, ioaddr, TX_DATA_FIFO ) 697#define SMC_SET_TX_FIFO(lp, x) SMC_outl( x, lp, TX_DATA_FIFO )
635#define SMC_GET_RX_FIFO() SMC_inl( ioaddr, RX_DATA_FIFO ) 698#define SMC_GET_RX_FIFO(lp) SMC_inl( lp, RX_DATA_FIFO )
636 699
637 700
638/* I/O mapped register read/write macros */ 701/* I/O mapped register read/write macros */
639#define SMC_GET_TX_STS_FIFO() SMC_inl( ioaddr, TX_STATUS_FIFO ) 702#define SMC_GET_TX_STS_FIFO(lp) SMC_inl( lp, TX_STATUS_FIFO )
640#define SMC_GET_RX_STS_FIFO() SMC_inl( ioaddr, RX_STATUS_FIFO ) 703#define SMC_GET_RX_STS_FIFO(lp) SMC_inl( lp, RX_STATUS_FIFO )
641#define SMC_GET_RX_STS_FIFO_PEEK() SMC_inl( ioaddr, RX_STATUS_FIFO_PEEK ) 704#define SMC_GET_RX_STS_FIFO_PEEK(lp) SMC_inl( lp, RX_STATUS_FIFO_PEEK )
642#define SMC_GET_PN() (SMC_inl( ioaddr, ID_REV ) >> 16) 705#define SMC_GET_PN(lp) (SMC_inl( lp, ID_REV ) >> 16)
643#define SMC_GET_REV() (SMC_inl( ioaddr, ID_REV ) & 0xFFFF) 706#define SMC_GET_REV(lp) (SMC_inl( lp, ID_REV ) & 0xFFFF)
644#define SMC_GET_IRQ_CFG() SMC_inl( ioaddr, INT_CFG ) 707#define SMC_GET_IRQ_CFG(lp) SMC_inl( lp, INT_CFG )
645#define SMC_SET_IRQ_CFG(x) SMC_outl( x, ioaddr, INT_CFG ) 708#define SMC_SET_IRQ_CFG(lp, x) SMC_outl( x, lp, INT_CFG )
646#define SMC_GET_INT() SMC_inl( ioaddr, INT_STS ) 709#define SMC_GET_INT(lp) SMC_inl( lp, INT_STS )
647#define SMC_ACK_INT(x) SMC_outl( x, ioaddr, INT_STS ) 710#define SMC_ACK_INT(lp, x) SMC_outl( x, lp, INT_STS )
648#define SMC_GET_INT_EN() SMC_inl( ioaddr, INT_EN ) 711#define SMC_GET_INT_EN(lp) SMC_inl( lp, INT_EN )
649#define SMC_SET_INT_EN(x) SMC_outl( x, ioaddr, INT_EN ) 712#define SMC_SET_INT_EN(lp, x) SMC_outl( x, lp, INT_EN )
650#define SMC_GET_BYTE_TEST() SMC_inl( ioaddr, BYTE_TEST ) 713#define SMC_GET_BYTE_TEST(lp) SMC_inl( lp, BYTE_TEST )
651#define SMC_SET_BYTE_TEST(x) SMC_outl( x, ioaddr, BYTE_TEST ) 714#define SMC_SET_BYTE_TEST(lp, x) SMC_outl( x, lp, BYTE_TEST )
652#define SMC_GET_FIFO_INT() SMC_inl( ioaddr, FIFO_INT ) 715#define SMC_GET_FIFO_INT(lp) SMC_inl( lp, FIFO_INT )
653#define SMC_SET_FIFO_INT(x) SMC_outl( x, ioaddr, FIFO_INT ) 716#define SMC_SET_FIFO_INT(lp, x) SMC_outl( x, lp, FIFO_INT )
654#define SMC_SET_FIFO_TDA(x) \ 717#define SMC_SET_FIFO_TDA(lp, x) \
655 do { \ 718 do { \
656 unsigned long __flags; \ 719 unsigned long __flags; \
657 int __mask; \ 720 int __mask; \
658 local_irq_save(__flags); \ 721 local_irq_save(__flags); \
659 __mask = SMC_GET_FIFO_INT() & ~(0xFF<<24); \ 722 __mask = SMC_GET_FIFO_INT((lp)) & ~(0xFF<<24); \
660 SMC_SET_FIFO_INT( __mask | (x)<<24 ); \ 723 SMC_SET_FIFO_INT( (lp), __mask | (x)<<24 ); \
661 local_irq_restore(__flags); \ 724 local_irq_restore(__flags); \
662 } while (0) 725 } while (0)
663#define SMC_SET_FIFO_TSL(x) \ 726#define SMC_SET_FIFO_TSL(lp, x) \
664 do { \ 727 do { \
665 unsigned long __flags; \ 728 unsigned long __flags; \
666 int __mask; \ 729 int __mask; \
667 local_irq_save(__flags); \ 730 local_irq_save(__flags); \
668 __mask = SMC_GET_FIFO_INT() & ~(0xFF<<16); \ 731 __mask = SMC_GET_FIFO_INT((lp)) & ~(0xFF<<16); \
669 SMC_SET_FIFO_INT( __mask | (((x) & 0xFF)<<16)); \ 732 SMC_SET_FIFO_INT( (lp), __mask | (((x) & 0xFF)<<16)); \
670 local_irq_restore(__flags); \ 733 local_irq_restore(__flags); \
671 } while (0) 734 } while (0)
672#define SMC_SET_FIFO_RSA(x) \ 735#define SMC_SET_FIFO_RSA(lp, x) \
673 do { \ 736 do { \
674 unsigned long __flags; \ 737 unsigned long __flags; \
675 int __mask; \ 738 int __mask; \
676 local_irq_save(__flags); \ 739 local_irq_save(__flags); \
677 __mask = SMC_GET_FIFO_INT() & ~(0xFF<<8); \ 740 __mask = SMC_GET_FIFO_INT((lp)) & ~(0xFF<<8); \
678 SMC_SET_FIFO_INT( __mask | (((x) & 0xFF)<<8)); \ 741 SMC_SET_FIFO_INT( (lp), __mask | (((x) & 0xFF)<<8)); \
679 local_irq_restore(__flags); \ 742 local_irq_restore(__flags); \
680 } while (0) 743 } while (0)
681#define SMC_SET_FIFO_RSL(x) \ 744#define SMC_SET_FIFO_RSL(lp, x) \
682 do { \ 745 do { \
683 unsigned long __flags; \ 746 unsigned long __flags; \
684 int __mask; \ 747 int __mask; \
685 local_irq_save(__flags); \ 748 local_irq_save(__flags); \
686 __mask = SMC_GET_FIFO_INT() & ~0xFF; \ 749 __mask = SMC_GET_FIFO_INT((lp)) & ~0xFF; \
687 SMC_SET_FIFO_INT( __mask | ((x) & 0xFF)); \ 750 SMC_SET_FIFO_INT( (lp),__mask | ((x) & 0xFF)); \
688 local_irq_restore(__flags); \ 751 local_irq_restore(__flags); \
689 } while (0) 752 } while (0)
690#define SMC_GET_RX_CFG() SMC_inl( ioaddr, RX_CFG ) 753#define SMC_GET_RX_CFG(lp) SMC_inl( lp, RX_CFG )
691#define SMC_SET_RX_CFG(x) SMC_outl( x, ioaddr, RX_CFG ) 754#define SMC_SET_RX_CFG(lp, x) SMC_outl( x, lp, RX_CFG )
692#define SMC_GET_TX_CFG() SMC_inl( ioaddr, TX_CFG ) 755#define SMC_GET_TX_CFG(lp) SMC_inl( lp, TX_CFG )
693#define SMC_SET_TX_CFG(x) SMC_outl( x, ioaddr, TX_CFG ) 756#define SMC_SET_TX_CFG(lp, x) SMC_outl( x, lp, TX_CFG )
694#define SMC_GET_HW_CFG() SMC_inl( ioaddr, HW_CFG ) 757#define SMC_GET_HW_CFG(lp) SMC_inl( lp, HW_CFG )
695#define SMC_SET_HW_CFG(x) SMC_outl( x, ioaddr, HW_CFG ) 758#define SMC_SET_HW_CFG(lp, x) SMC_outl( x, lp, HW_CFG )
696#define SMC_GET_RX_DP_CTRL() SMC_inl( ioaddr, RX_DP_CTRL ) 759#define SMC_GET_RX_DP_CTRL(lp) SMC_inl( lp, RX_DP_CTRL )
697#define SMC_SET_RX_DP_CTRL(x) SMC_outl( x, ioaddr, RX_DP_CTRL ) 760#define SMC_SET_RX_DP_CTRL(lp, x) SMC_outl( x, lp, RX_DP_CTRL )
698#define SMC_GET_PMT_CTRL() SMC_inl( ioaddr, PMT_CTRL ) 761#define SMC_GET_PMT_CTRL(lp) SMC_inl( lp, PMT_CTRL )
699#define SMC_SET_PMT_CTRL(x) SMC_outl( x, ioaddr, PMT_CTRL ) 762#define SMC_SET_PMT_CTRL(lp, x) SMC_outl( x, lp, PMT_CTRL )
700#define SMC_GET_GPIO_CFG() SMC_inl( ioaddr, GPIO_CFG ) 763#define SMC_GET_GPIO_CFG(lp) SMC_inl( lp, GPIO_CFG )
701#define SMC_SET_GPIO_CFG(x) SMC_outl( x, ioaddr, GPIO_CFG ) 764#define SMC_SET_GPIO_CFG(lp, x) SMC_outl( x, lp, GPIO_CFG )
702#define SMC_GET_RX_FIFO_INF() SMC_inl( ioaddr, RX_FIFO_INF ) 765#define SMC_GET_RX_FIFO_INF(lp) SMC_inl( lp, RX_FIFO_INF )
703#define SMC_SET_RX_FIFO_INF(x) SMC_outl( x, ioaddr, RX_FIFO_INF ) 766#define SMC_SET_RX_FIFO_INF(lp, x) SMC_outl( x, lp, RX_FIFO_INF )
704#define SMC_GET_TX_FIFO_INF() SMC_inl( ioaddr, TX_FIFO_INF ) 767#define SMC_GET_TX_FIFO_INF(lp) SMC_inl( lp, TX_FIFO_INF )
705#define SMC_SET_TX_FIFO_INF(x) SMC_outl( x, ioaddr, TX_FIFO_INF ) 768#define SMC_SET_TX_FIFO_INF(lp, x) SMC_outl( x, lp, TX_FIFO_INF )
706#define SMC_GET_GPT_CFG() SMC_inl( ioaddr, GPT_CFG ) 769#define SMC_GET_GPT_CFG(lp) SMC_inl( lp, GPT_CFG )
707#define SMC_SET_GPT_CFG(x) SMC_outl( x, ioaddr, GPT_CFG ) 770#define SMC_SET_GPT_CFG(lp, x) SMC_outl( x, lp, GPT_CFG )
708#define SMC_GET_RX_DROP() SMC_inl( ioaddr, RX_DROP ) 771#define SMC_GET_RX_DROP(lp) SMC_inl( lp, RX_DROP )
709#define SMC_SET_RX_DROP(x) SMC_outl( x, ioaddr, RX_DROP ) 772#define SMC_SET_RX_DROP(lp, x) SMC_outl( x, lp, RX_DROP )
710#define SMC_GET_MAC_CMD() SMC_inl( ioaddr, MAC_CSR_CMD ) 773#define SMC_GET_MAC_CMD(lp) SMC_inl( lp, MAC_CSR_CMD )
711#define SMC_SET_MAC_CMD(x) SMC_outl( x, ioaddr, MAC_CSR_CMD ) 774#define SMC_SET_MAC_CMD(lp, x) SMC_outl( x, lp, MAC_CSR_CMD )
712#define SMC_GET_MAC_DATA() SMC_inl( ioaddr, MAC_CSR_DATA ) 775#define SMC_GET_MAC_DATA(lp) SMC_inl( lp, MAC_CSR_DATA )
713#define SMC_SET_MAC_DATA(x) SMC_outl( x, ioaddr, MAC_CSR_DATA ) 776#define SMC_SET_MAC_DATA(lp, x) SMC_outl( x, lp, MAC_CSR_DATA )
714#define SMC_GET_AFC_CFG() SMC_inl( ioaddr, AFC_CFG ) 777#define SMC_GET_AFC_CFG(lp) SMC_inl( lp, AFC_CFG )
715#define SMC_SET_AFC_CFG(x) SMC_outl( x, ioaddr, AFC_CFG ) 778#define SMC_SET_AFC_CFG(lp, x) SMC_outl( x, lp, AFC_CFG )
716#define SMC_GET_E2P_CMD() SMC_inl( ioaddr, E2P_CMD ) 779#define SMC_GET_E2P_CMD(lp) SMC_inl( lp, E2P_CMD )
717#define SMC_SET_E2P_CMD(x) SMC_outl( x, ioaddr, E2P_CMD ) 780#define SMC_SET_E2P_CMD(lp, x) SMC_outl( x, lp, E2P_CMD )
718#define SMC_GET_E2P_DATA() SMC_inl( ioaddr, E2P_DATA ) 781#define SMC_GET_E2P_DATA(lp) SMC_inl( lp, E2P_DATA )
719#define SMC_SET_E2P_DATA(x) SMC_outl( x, ioaddr, E2P_DATA ) 782#define SMC_SET_E2P_DATA(lp, x) SMC_outl( x, lp, E2P_DATA )
720 783
721/* MAC register read/write macros */ 784/* MAC register read/write macros */
722#define SMC_GET_MAC_CSR(a,v) \ 785#define SMC_GET_MAC_CSR(lp,a,v) \
723 do { \ 786 do { \
724 while (SMC_GET_MAC_CMD() & MAC_CSR_CMD_CSR_BUSY_); \ 787 while (SMC_GET_MAC_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
725 SMC_SET_MAC_CMD(MAC_CSR_CMD_CSR_BUSY_ | \ 788 SMC_SET_MAC_CMD((lp),MAC_CSR_CMD_CSR_BUSY_ | \
726 MAC_CSR_CMD_R_NOT_W_ | (a) ); \ 789 MAC_CSR_CMD_R_NOT_W_ | (a) ); \
727 while (SMC_GET_MAC_CMD() & MAC_CSR_CMD_CSR_BUSY_); \ 790 while (SMC_GET_MAC_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
728 v = SMC_GET_MAC_DATA(); \ 791 v = SMC_GET_MAC_DATA((lp)); \
729 } while (0) 792 } while (0)
730#define SMC_SET_MAC_CSR(a,v) \ 793#define SMC_SET_MAC_CSR(lp,a,v) \
731 do { \ 794 do { \
732 while (SMC_GET_MAC_CMD() & MAC_CSR_CMD_CSR_BUSY_); \ 795 while (SMC_GET_MAC_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
733 SMC_SET_MAC_DATA(v); \ 796 SMC_SET_MAC_DATA((lp), v); \
734 SMC_SET_MAC_CMD(MAC_CSR_CMD_CSR_BUSY_ | (a) ); \ 797 SMC_SET_MAC_CMD((lp), MAC_CSR_CMD_CSR_BUSY_ | (a) ); \
735 while (SMC_GET_MAC_CMD() & MAC_CSR_CMD_CSR_BUSY_); \ 798 while (SMC_GET_MAC_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
736 } while (0) 799 } while (0)
737#define SMC_GET_MAC_CR(x) SMC_GET_MAC_CSR( MAC_CR, x ) 800#define SMC_GET_MAC_CR(lp, x) SMC_GET_MAC_CSR( (lp), MAC_CR, x )
738#define SMC_SET_MAC_CR(x) SMC_SET_MAC_CSR( MAC_CR, x ) 801#define SMC_SET_MAC_CR(lp, x) SMC_SET_MAC_CSR( (lp), MAC_CR, x )
739#define SMC_GET_ADDRH(x) SMC_GET_MAC_CSR( ADDRH, x ) 802#define SMC_GET_ADDRH(lp, x) SMC_GET_MAC_CSR( (lp), ADDRH, x )
740#define SMC_SET_ADDRH(x) SMC_SET_MAC_CSR( ADDRH, x ) 803#define SMC_SET_ADDRH(lp, x) SMC_SET_MAC_CSR( (lp), ADDRH, x )
741#define SMC_GET_ADDRL(x) SMC_GET_MAC_CSR( ADDRL, x ) 804#define SMC_GET_ADDRL(lp, x) SMC_GET_MAC_CSR( (lp), ADDRL, x )
742#define SMC_SET_ADDRL(x) SMC_SET_MAC_CSR( ADDRL, x ) 805#define SMC_SET_ADDRL(lp, x) SMC_SET_MAC_CSR( (lp), ADDRL, x )
743#define SMC_GET_HASHH(x) SMC_GET_MAC_CSR( HASHH, x ) 806#define SMC_GET_HASHH(lp, x) SMC_GET_MAC_CSR( (lp), HASHH, x )
744#define SMC_SET_HASHH(x) SMC_SET_MAC_CSR( HASHH, x ) 807#define SMC_SET_HASHH(lp, x) SMC_SET_MAC_CSR( (lp), HASHH, x )
745#define SMC_GET_HASHL(x) SMC_GET_MAC_CSR( HASHL, x ) 808#define SMC_GET_HASHL(lp, x) SMC_GET_MAC_CSR( (lp), HASHL, x )
746#define SMC_SET_HASHL(x) SMC_SET_MAC_CSR( HASHL, x ) 809#define SMC_SET_HASHL(lp, x) SMC_SET_MAC_CSR( (lp), HASHL, x )
747#define SMC_GET_MII_ACC(x) SMC_GET_MAC_CSR( MII_ACC, x ) 810#define SMC_GET_MII_ACC(lp, x) SMC_GET_MAC_CSR( (lp), MII_ACC, x )
748#define SMC_SET_MII_ACC(x) SMC_SET_MAC_CSR( MII_ACC, x ) 811#define SMC_SET_MII_ACC(lp, x) SMC_SET_MAC_CSR( (lp), MII_ACC, x )
749#define SMC_GET_MII_DATA(x) SMC_GET_MAC_CSR( MII_DATA, x ) 812#define SMC_GET_MII_DATA(lp, x) SMC_GET_MAC_CSR( (lp), MII_DATA, x )
750#define SMC_SET_MII_DATA(x) SMC_SET_MAC_CSR( MII_DATA, x ) 813#define SMC_SET_MII_DATA(lp, x) SMC_SET_MAC_CSR( (lp), MII_DATA, x )
751#define SMC_GET_FLOW(x) SMC_GET_MAC_CSR( FLOW, x ) 814#define SMC_GET_FLOW(lp, x) SMC_GET_MAC_CSR( (lp), FLOW, x )
752#define SMC_SET_FLOW(x) SMC_SET_MAC_CSR( FLOW, x ) 815#define SMC_SET_FLOW(lp, x) SMC_SET_MAC_CSR( (lp), FLOW, x )
753#define SMC_GET_VLAN1(x) SMC_GET_MAC_CSR( VLAN1, x ) 816#define SMC_GET_VLAN1(lp, x) SMC_GET_MAC_CSR( (lp), VLAN1, x )
754#define SMC_SET_VLAN1(x) SMC_SET_MAC_CSR( VLAN1, x ) 817#define SMC_SET_VLAN1(lp, x) SMC_SET_MAC_CSR( (lp), VLAN1, x )
755#define SMC_GET_VLAN2(x) SMC_GET_MAC_CSR( VLAN2, x ) 818#define SMC_GET_VLAN2(lp, x) SMC_GET_MAC_CSR( (lp), VLAN2, x )
756#define SMC_SET_VLAN2(x) SMC_SET_MAC_CSR( VLAN2, x ) 819#define SMC_SET_VLAN2(lp, x) SMC_SET_MAC_CSR( (lp), VLAN2, x )
757#define SMC_SET_WUFF(x) SMC_SET_MAC_CSR( WUFF, x ) 820#define SMC_SET_WUFF(lp, x) SMC_SET_MAC_CSR( (lp), WUFF, x )
758#define SMC_GET_WUCSR(x) SMC_GET_MAC_CSR( WUCSR, x ) 821#define SMC_GET_WUCSR(lp, x) SMC_GET_MAC_CSR( (lp), WUCSR, x )
759#define SMC_SET_WUCSR(x) SMC_SET_MAC_CSR( WUCSR, x ) 822#define SMC_SET_WUCSR(lp, x) SMC_SET_MAC_CSR( (lp), WUCSR, x )
760 823
761/* PHY register read/write macros */ 824/* PHY register read/write macros */
762#define SMC_GET_MII(a,phy,v) \ 825#define SMC_GET_MII(lp,a,phy,v) \
763 do { \ 826 do { \
764 u32 __v; \ 827 u32 __v; \
765 do { \ 828 do { \
766 SMC_GET_MII_ACC(__v); \ 829 SMC_GET_MII_ACC((lp), __v); \
767 } while ( __v & MII_ACC_MII_BUSY_ ); \ 830 } while ( __v & MII_ACC_MII_BUSY_ ); \
768 SMC_SET_MII_ACC( ((phy)<<11) | ((a)<<6) | \ 831 SMC_SET_MII_ACC( (lp), ((phy)<<11) | ((a)<<6) | \
769 MII_ACC_MII_BUSY_); \ 832 MII_ACC_MII_BUSY_); \
770 do { \ 833 do { \
771 SMC_GET_MII_ACC(__v); \ 834 SMC_GET_MII_ACC( (lp), __v); \
772 } while ( __v & MII_ACC_MII_BUSY_ ); \ 835 } while ( __v & MII_ACC_MII_BUSY_ ); \
773 SMC_GET_MII_DATA(v); \ 836 SMC_GET_MII_DATA((lp), v); \
774 } while (0) 837 } while (0)
775#define SMC_SET_MII(a,phy,v) \ 838#define SMC_SET_MII(lp,a,phy,v) \
776 do { \ 839 do { \
777 u32 __v; \ 840 u32 __v; \
778 do { \ 841 do { \
779 SMC_GET_MII_ACC(__v); \ 842 SMC_GET_MII_ACC((lp), __v); \
780 } while ( __v & MII_ACC_MII_BUSY_ ); \ 843 } while ( __v & MII_ACC_MII_BUSY_ ); \
781 SMC_SET_MII_DATA(v); \ 844 SMC_SET_MII_DATA((lp), v); \
782 SMC_SET_MII_ACC( ((phy)<<11) | ((a)<<6) | \ 845 SMC_SET_MII_ACC( (lp), ((phy)<<11) | ((a)<<6) | \
783 MII_ACC_MII_BUSY_ | \ 846 MII_ACC_MII_BUSY_ | \
784 MII_ACC_MII_WRITE_ ); \ 847 MII_ACC_MII_WRITE_ ); \
785 do { \ 848 do { \
786 SMC_GET_MII_ACC(__v); \ 849 SMC_GET_MII_ACC((lp), __v); \
787 } while ( __v & MII_ACC_MII_BUSY_ ); \ 850 } while ( __v & MII_ACC_MII_BUSY_ ); \
788 } while (0) 851 } while (0)
789#define SMC_GET_PHY_BMCR(phy,x) SMC_GET_MII( MII_BMCR, phy, x ) 852#define SMC_GET_PHY_BMCR(lp,phy,x) SMC_GET_MII( (lp), MII_BMCR, phy, x )
790#define SMC_SET_PHY_BMCR(phy,x) SMC_SET_MII( MII_BMCR, phy, x ) 853#define SMC_SET_PHY_BMCR(lp,phy,x) SMC_SET_MII( (lp), MII_BMCR, phy, x )
791#define SMC_GET_PHY_BMSR(phy,x) SMC_GET_MII( MII_BMSR, phy, x ) 854#define SMC_GET_PHY_BMSR(lp,phy,x) SMC_GET_MII( (lp), MII_BMSR, phy, x )
792#define SMC_GET_PHY_ID1(phy,x) SMC_GET_MII( MII_PHYSID1, phy, x ) 855#define SMC_GET_PHY_ID1(lp,phy,x) SMC_GET_MII( (lp), MII_PHYSID1, phy, x )
793#define SMC_GET_PHY_ID2(phy,x) SMC_GET_MII( MII_PHYSID2, phy, x ) 856#define SMC_GET_PHY_ID2(lp,phy,x) SMC_GET_MII( (lp), MII_PHYSID2, phy, x )
794#define SMC_GET_PHY_MII_ADV(phy,x) SMC_GET_MII( MII_ADVERTISE, phy, x ) 857#define SMC_GET_PHY_MII_ADV(lp,phy,x) SMC_GET_MII( (lp), MII_ADVERTISE, phy, x )
795#define SMC_SET_PHY_MII_ADV(phy,x) SMC_SET_MII( MII_ADVERTISE, phy, x ) 858#define SMC_SET_PHY_MII_ADV(lp,phy,x) SMC_SET_MII( (lp), MII_ADVERTISE, phy, x )
796#define SMC_GET_PHY_MII_LPA(phy,x) SMC_GET_MII( MII_LPA, phy, x ) 859#define SMC_GET_PHY_MII_LPA(lp,phy,x) SMC_GET_MII( (lp), MII_LPA, phy, x )
797#define SMC_SET_PHY_MII_LPA(phy,x) SMC_SET_MII( MII_LPA, phy, x ) 860#define SMC_SET_PHY_MII_LPA(lp,phy,x) SMC_SET_MII( (lp), MII_LPA, phy, x )
798#define SMC_GET_PHY_CTRL_STS(phy,x) SMC_GET_MII( PHY_MODE_CTRL_STS, phy, x ) 861#define SMC_GET_PHY_CTRL_STS(lp,phy,x) SMC_GET_MII( (lp), PHY_MODE_CTRL_STS, phy, x )
799#define SMC_SET_PHY_CTRL_STS(phy,x) SMC_SET_MII( PHY_MODE_CTRL_STS, phy, x ) 862#define SMC_SET_PHY_CTRL_STS(lp,phy,x) SMC_SET_MII( (lp), PHY_MODE_CTRL_STS, phy, x )
800#define SMC_GET_PHY_INT_SRC(phy,x) SMC_GET_MII( PHY_INT_SRC, phy, x ) 863#define SMC_GET_PHY_INT_SRC(lp,phy,x) SMC_GET_MII( (lp), PHY_INT_SRC, phy, x )
801#define SMC_SET_PHY_INT_SRC(phy,x) SMC_SET_MII( PHY_INT_SRC, phy, x ) 864#define SMC_SET_PHY_INT_SRC(lp,phy,x) SMC_SET_MII( (lp), PHY_INT_SRC, phy, x )
802#define SMC_GET_PHY_INT_MASK(phy,x) SMC_GET_MII( PHY_INT_MASK, phy, x ) 865#define SMC_GET_PHY_INT_MASK(lp,phy,x) SMC_GET_MII( (lp), PHY_INT_MASK, phy, x )
803#define SMC_SET_PHY_INT_MASK(phy,x) SMC_SET_MII( PHY_INT_MASK, phy, x ) 866#define SMC_SET_PHY_INT_MASK(lp,phy,x) SMC_SET_MII( (lp), PHY_INT_MASK, phy, x )
804#define SMC_GET_PHY_SPECIAL(phy,x) SMC_GET_MII( PHY_SPECIAL, phy, x ) 867#define SMC_GET_PHY_SPECIAL(lp,phy,x) SMC_GET_MII( (lp), PHY_SPECIAL, phy, x )
805 868
806 869
807 870
808/* Misc read/write macros */ 871/* Misc read/write macros */
809 872
810#ifndef SMC_GET_MAC_ADDR 873#ifndef SMC_GET_MAC_ADDR
811#define SMC_GET_MAC_ADDR(addr) \ 874#define SMC_GET_MAC_ADDR(lp, addr) \
812 do { \ 875 do { \
813 unsigned int __v; \ 876 unsigned int __v; \
814 \ 877 \
815 SMC_GET_MAC_CSR(ADDRL, __v); \ 878 SMC_GET_MAC_CSR((lp), ADDRL, __v); \
816 addr[0] = __v; addr[1] = __v >> 8; \ 879 addr[0] = __v; addr[1] = __v >> 8; \
817 addr[2] = __v >> 16; addr[3] = __v >> 24; \ 880 addr[2] = __v >> 16; addr[3] = __v >> 24; \
818 SMC_GET_MAC_CSR(ADDRH, __v); \ 881 SMC_GET_MAC_CSR((lp), ADDRH, __v); \
819 addr[4] = __v; addr[5] = __v >> 8; \ 882 addr[4] = __v; addr[5] = __v >> 8; \
820 } while (0) 883 } while (0)
821#endif 884#endif
822 885
823#define SMC_SET_MAC_ADDR(addr) \ 886#define SMC_SET_MAC_ADDR(lp, addr) \
824 do { \ 887 do { \
825 SMC_SET_MAC_CSR(ADDRL, \ 888 SMC_SET_MAC_CSR((lp), ADDRL, \
826 addr[0] | \ 889 addr[0] | \
827 (addr[1] << 8) | \ 890 (addr[1] << 8) | \
828 (addr[2] << 16) | \ 891 (addr[2] << 16) | \
829 (addr[3] << 24)); \ 892 (addr[3] << 24)); \
830 SMC_SET_MAC_CSR(ADDRH, addr[4]|(addr[5] << 8));\ 893 SMC_SET_MAC_CSR((lp), ADDRH, addr[4]|(addr[5] << 8));\
831 } while (0) 894 } while (0)
832 895
833 896
834#define SMC_WRITE_EEPROM_CMD(cmd, addr) \ 897#define SMC_WRITE_EEPROM_CMD(lp, cmd, addr) \
835 do { \ 898 do { \
836 while (SMC_GET_E2P_CMD() & MAC_CSR_CMD_CSR_BUSY_); \ 899 while (SMC_GET_E2P_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
837 SMC_SET_MAC_CMD(MAC_CSR_CMD_R_NOT_W_ | a ); \ 900 SMC_SET_MAC_CMD((lp), MAC_CSR_CMD_R_NOT_W_ | a ); \
838 while (SMC_GET_MAC_CMD() & MAC_CSR_CMD_CSR_BUSY_); \ 901 while (SMC_GET_MAC_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
839 } while (0) 902 } while (0)
840 903
841#endif /* _SMC911X_H_ */ 904#endif /* _SMC911X_H_ */
diff --git a/drivers/net/sunlance.c b/drivers/net/sunlance.c
index 26ade68aeabf..4e994f87469e 100644
--- a/drivers/net/sunlance.c
+++ b/drivers/net/sunlance.c
@@ -915,15 +915,11 @@ static void build_fake_packet(struct lance_private *lp)
915 lp->tx_new = TX_NEXT(entry); 915 lp->tx_new = TX_NEXT(entry);
916} 916}
917 917
918struct net_device *last_dev;
919
920static int lance_open(struct net_device *dev) 918static int lance_open(struct net_device *dev)
921{ 919{
922 struct lance_private *lp = netdev_priv(dev); 920 struct lance_private *lp = netdev_priv(dev);
923 int status = 0; 921 int status = 0;
924 922
925 last_dev = dev;
926
927 STOP_LANCE(lp); 923 STOP_LANCE(lp);
928 924
929 if (request_irq(dev->irq, &lance_interrupt, IRQF_SHARED, 925 if (request_irq(dev->irq, &lance_interrupt, IRQF_SHARED,
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index 0604f3faf043..68e198bd538b 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -154,6 +154,16 @@ config USB_NET_AX8817X
154 This driver creates an interface named "ethX", where X depends on 154 This driver creates an interface named "ethX", where X depends on
155 what other networking devices you have in use. 155 what other networking devices you have in use.
156 156
157config USB_HSO
158 tristate "Option USB High Speed Mobile Devices"
159 depends on USB && RFKILL
160 default n
161 help
162 Choose this option if you have an Option HSDPA/HSUPA card.
163 These cards support downlink speeds of 7.2Mbps or greater.
164
165 To compile this driver as a module, choose M here: the
166 module will be called hso.
157 167
158config USB_NET_CDCETHER 168config USB_NET_CDCETHER
159 tristate "CDC Ethernet support (smart devices such as cable modems)" 169 tristate "CDC Ethernet support (smart devices such as cable modems)"
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index 595a539f8384..24800c157f98 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_USB_CATC) += catc.o
6obj-$(CONFIG_USB_KAWETH) += kaweth.o 6obj-$(CONFIG_USB_KAWETH) += kaweth.o
7obj-$(CONFIG_USB_PEGASUS) += pegasus.o 7obj-$(CONFIG_USB_PEGASUS) += pegasus.o
8obj-$(CONFIG_USB_RTL8150) += rtl8150.o 8obj-$(CONFIG_USB_RTL8150) += rtl8150.o
9obj-$(CONFIG_USB_HSO) += hso.o
9obj-$(CONFIG_USB_NET_AX8817X) += asix.o 10obj-$(CONFIG_USB_NET_AX8817X) += asix.o
10obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o 11obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o
11obj-$(CONFIG_USB_NET_DM9601) += dm9601.o 12obj-$(CONFIG_USB_NET_DM9601) += dm9601.o
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
new file mode 100644
index 000000000000..031d07b105af
--- /dev/null
+++ b/drivers/net/usb/hso.c
@@ -0,0 +1,2836 @@
1/******************************************************************************
2 *
3 * Driver for Option High Speed Mobile Devices.
4 *
5 * Copyright (C) 2008 Option International
6 * Copyright (C) 2007 Andrew Bird (Sphere Systems Ltd)
7 * <ajb@spheresystems.co.uk>
8 * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de>
9 * Copyright (C) 2008 Novell, Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 * USA
24 *
25 *
26 *****************************************************************************/
27
28/******************************************************************************
29 *
30 * Description of the device:
31 *
32 * Interface 0: Contains the IP network interface on the bulk end points.
33 * The multiplexed serial ports are using the interrupt and
34 * control endpoints.
35 * Interrupt contains a bitmap telling which multiplexed
36 * serialport needs servicing.
37 *
38 * Interface 1: Diagnostics port, uses bulk only, do not submit urbs until the
39 * port is opened, as this have a huge impact on the network port
40 * throughput.
41 *
42 * Interface 2: Standard modem interface - circuit switched interface, should
43 * not be used.
44 *
45 *****************************************************************************/
46
47#include <linux/sched.h>
48#include <linux/slab.h>
49#include <linux/init.h>
50#include <linux/delay.h>
51#include <linux/netdevice.h>
52#include <linux/module.h>
53#include <linux/ethtool.h>
54#include <linux/usb.h>
55#include <linux/timer.h>
56#include <linux/tty.h>
57#include <linux/tty_driver.h>
58#include <linux/tty_flip.h>
59#include <linux/kmod.h>
60#include <linux/rfkill.h>
61#include <linux/ip.h>
62#include <linux/uaccess.h>
63#include <linux/usb/cdc.h>
64#include <net/arp.h>
65#include <asm/byteorder.h>
66
67
68#define DRIVER_VERSION "1.2"
69#define MOD_AUTHOR "Option Wireless"
70#define MOD_DESCRIPTION "USB High Speed Option driver"
71#define MOD_LICENSE "GPL"
72
73#define HSO_MAX_NET_DEVICES 10
74#define HSO__MAX_MTU 2048
75#define DEFAULT_MTU 1500
76#define DEFAULT_MRU 1500
77
78#define CTRL_URB_RX_SIZE 1024
79#define CTRL_URB_TX_SIZE 64
80
81#define BULK_URB_RX_SIZE 4096
82#define BULK_URB_TX_SIZE 8192
83
84#define MUX_BULK_RX_BUF_SIZE HSO__MAX_MTU
85#define MUX_BULK_TX_BUF_SIZE HSO__MAX_MTU
86#define MUX_BULK_RX_BUF_COUNT 4
87#define USB_TYPE_OPTION_VENDOR 0x20
88
89/* These definitions are used with the struct hso_net flags element */
90/* - use *_bit operations on it. (bit indices not values.) */
91#define HSO_NET_RUNNING 0
92
93#define HSO_NET_TX_TIMEOUT (HZ*10)
94
95/* Serial port defines and structs. */
96#define HSO_SERIAL_FLAG_RX_SENT 0
97
98#define HSO_SERIAL_MAGIC 0x48534f31
99
100/* Number of ttys to handle */
101#define HSO_SERIAL_TTY_MINORS 256
102
103#define MAX_RX_URBS 2
104
105#define get_serial_by_tty(x) \
106 (x ? (struct hso_serial *)x->driver_data : NULL)
107
108/*****************************************************************************/
109/* Debugging functions */
110/*****************************************************************************/
111#define D__(lvl_, fmt, arg...) \
112 do { \
113 printk(lvl_ "[%d:%s]: " fmt "\n", \
114 __LINE__, __func__, ## arg); \
115 } while (0)
116
117#define D_(lvl, args...) \
118 do { \
119 if (lvl & debug) \
120 D__(KERN_INFO, args); \
121 } while (0)
122
123#define D1(args...) D_(0x01, ##args)
124#define D2(args...) D_(0x02, ##args)
125#define D3(args...) D_(0x04, ##args)
126#define D4(args...) D_(0x08, ##args)
127#define D5(args...) D_(0x10, ##args)
128
129/*****************************************************************************/
130/* Enumerators */
131/*****************************************************************************/
132enum pkt_parse_state {
133 WAIT_IP,
134 WAIT_DATA,
135 WAIT_SYNC
136};
137
138/*****************************************************************************/
139/* Structs */
140/*****************************************************************************/
141
142struct hso_shared_int {
143 struct usb_endpoint_descriptor *intr_endp;
144 void *shared_intr_buf;
145 struct urb *shared_intr_urb;
146 struct usb_device *usb;
147 int use_count;
148 int ref_count;
149 struct mutex shared_int_lock;
150};
151
152struct hso_net {
153 struct hso_device *parent;
154 struct net_device *net;
155 struct rfkill *rfkill;
156
157 struct usb_endpoint_descriptor *in_endp;
158 struct usb_endpoint_descriptor *out_endp;
159
160 struct urb *mux_bulk_rx_urb_pool[MUX_BULK_RX_BUF_COUNT];
161 struct urb *mux_bulk_tx_urb;
162 void *mux_bulk_rx_buf_pool[MUX_BULK_RX_BUF_COUNT];
163 void *mux_bulk_tx_buf;
164
165 struct sk_buff *skb_rx_buf;
166 struct sk_buff *skb_tx_buf;
167
168 enum pkt_parse_state rx_parse_state;
169 spinlock_t net_lock;
170
171 unsigned short rx_buf_size;
172 unsigned short rx_buf_missing;
173 struct iphdr rx_ip_hdr;
174
175 unsigned long flags;
176};
177
178struct hso_serial {
179 struct hso_device *parent;
180 int magic;
181 u8 minor;
182
183 struct hso_shared_int *shared_int;
184
185 /* rx/tx urb could be either a bulk urb or a control urb depending
186 on which serial port it is used on. */
187 struct urb *rx_urb[MAX_RX_URBS];
188 u8 num_rx_urbs;
189 u8 *rx_data[MAX_RX_URBS];
190 u16 rx_data_length; /* should contain allocated length */
191
192 struct urb *tx_urb;
193 u8 *tx_data;
194 u8 *tx_buffer;
195 u16 tx_data_length; /* should contain allocated length */
196 u16 tx_data_count;
197 u16 tx_buffer_count;
198 struct usb_ctrlrequest ctrl_req_tx;
199 struct usb_ctrlrequest ctrl_req_rx;
200
201 struct usb_endpoint_descriptor *in_endp;
202 struct usb_endpoint_descriptor *out_endp;
203
204 unsigned long flags;
205 u8 rts_state;
206 u8 dtr_state;
207 unsigned tx_urb_used:1;
208
209 /* from usb_serial_port */
210 struct tty_struct *tty;
211 int open_count;
212 spinlock_t serial_lock;
213
214 int (*write_data) (struct hso_serial *serial);
215};
216
217struct hso_device {
218 union {
219 struct hso_serial *dev_serial;
220 struct hso_net *dev_net;
221 } port_data;
222
223 u32 port_spec;
224
225 u8 is_active;
226 u8 usb_gone;
227 struct work_struct async_get_intf;
228 struct work_struct async_put_intf;
229
230 struct usb_device *usb;
231 struct usb_interface *interface;
232
233 struct device *dev;
234 struct kref ref;
235 struct mutex mutex;
236};
237
238/* Type of interface */
239#define HSO_INTF_MASK 0xFF00
240#define HSO_INTF_MUX 0x0100
241#define HSO_INTF_BULK 0x0200
242
243/* Type of port */
244#define HSO_PORT_MASK 0xFF
245#define HSO_PORT_NO_PORT 0x0
246#define HSO_PORT_CONTROL 0x1
247#define HSO_PORT_APP 0x2
248#define HSO_PORT_GPS 0x3
249#define HSO_PORT_PCSC 0x4
250#define HSO_PORT_APP2 0x5
251#define HSO_PORT_GPS_CONTROL 0x6
252#define HSO_PORT_MSD 0x7
253#define HSO_PORT_VOICE 0x8
254#define HSO_PORT_DIAG2 0x9
255#define HSO_PORT_DIAG 0x10
256#define HSO_PORT_MODEM 0x11
257#define HSO_PORT_NETWORK 0x12
258
259/* Additional device info */
260#define HSO_INFO_MASK 0xFF000000
261#define HSO_INFO_CRC_BUG 0x01000000
262
263/*****************************************************************************/
264/* Prototypes */
265/*****************************************************************************/
266/* Serial driver functions */
267static int hso_serial_tiocmset(struct tty_struct *tty, struct file *file,
268 unsigned int set, unsigned int clear);
269static void ctrl_callback(struct urb *urb);
270static void put_rxbuf_data(struct urb *urb, struct hso_serial *serial);
271static void hso_kick_transmit(struct hso_serial *serial);
272/* Helper functions */
273static int hso_mux_submit_intr_urb(struct hso_shared_int *mux_int,
274 struct usb_device *usb, gfp_t gfp);
275static void log_usb_status(int status, const char *function);
276static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf,
277 int type, int dir);
278static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports);
279static void hso_free_interface(struct usb_interface *intf);
280static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags);
281static int hso_stop_serial_device(struct hso_device *hso_dev);
282static int hso_start_net_device(struct hso_device *hso_dev);
283static void hso_free_shared_int(struct hso_shared_int *shared_int);
284static int hso_stop_net_device(struct hso_device *hso_dev);
285static void hso_serial_ref_free(struct kref *ref);
286static void async_get_intf(struct work_struct *data);
287static void async_put_intf(struct work_struct *data);
288static int hso_put_activity(struct hso_device *hso_dev);
289static int hso_get_activity(struct hso_device *hso_dev);
290
291/*****************************************************************************/
292/* Helping functions */
293/*****************************************************************************/
294
295/* #define DEBUG */
296
297#define dev2net(x) (x->port_data.dev_net)
298#define dev2ser(x) (x->port_data.dev_serial)
299
300/* Debugging functions */
301#ifdef DEBUG
302static void dbg_dump(int line_count, const char *func_name, unsigned char *buf,
303 unsigned int len)
304{
305 u8 i = 0;
306
307 printk(KERN_DEBUG "[%d:%s]: len %d", line_count, func_name, len);
308
309 for (i = 0; i < len; i++) {
310 if (!(i % 16))
311 printk("\n 0x%03x: ", i);
312 printk("%02x ", (unsigned char)buf[i]);
313 }
314 printk("\n");
315}
316
317#define DUMP(buf_, len_) \
318 dbg_dump(__LINE__, __func__, buf_, len_)
319
320#define DUMP1(buf_, len_) \
321 do { \
322 if (0x01 & debug) \
323 DUMP(buf_, len_); \
324 } while (0)
325#else
326#define DUMP(buf_, len_)
327#define DUMP1(buf_, len_)
328#endif
329
330/* module parameters */
331static int debug;
332static int tty_major;
333static int disable_net;
334
335/* driver info */
336static const char driver_name[] = "hso";
337static const char tty_filename[] = "ttyHS";
338static const char *version = __FILE__ ": " DRIVER_VERSION " " MOD_AUTHOR;
339/* the usb driver itself (registered in hso_init) */
340static struct usb_driver hso_driver;
341/* serial structures */
342static struct tty_driver *tty_drv;
343static struct hso_device *serial_table[HSO_SERIAL_TTY_MINORS];
344static struct hso_device *network_table[HSO_MAX_NET_DEVICES];
345static spinlock_t serial_table_lock;
346static struct ktermios *hso_serial_termios[HSO_SERIAL_TTY_MINORS];
347static struct ktermios *hso_serial_termios_locked[HSO_SERIAL_TTY_MINORS];
348
349static const s32 default_port_spec[] = {
350 HSO_INTF_MUX | HSO_PORT_NETWORK,
351 HSO_INTF_BULK | HSO_PORT_DIAG,
352 HSO_INTF_BULK | HSO_PORT_MODEM,
353 0
354};
355
356static const s32 icon321_port_spec[] = {
357 HSO_INTF_MUX | HSO_PORT_NETWORK,
358 HSO_INTF_BULK | HSO_PORT_DIAG2,
359 HSO_INTF_BULK | HSO_PORT_MODEM,
360 HSO_INTF_BULK | HSO_PORT_DIAG,
361 0
362};
363
364#define default_port_device(vendor, product) \
365 USB_DEVICE(vendor, product), \
366 .driver_info = (kernel_ulong_t)default_port_spec
367
368#define icon321_port_device(vendor, product) \
369 USB_DEVICE(vendor, product), \
370 .driver_info = (kernel_ulong_t)icon321_port_spec
371
372/* list of devices we support */
373static const struct usb_device_id hso_ids[] = {
374 {default_port_device(0x0af0, 0x6711)},
375 {default_port_device(0x0af0, 0x6731)},
376 {default_port_device(0x0af0, 0x6751)},
377 {default_port_device(0x0af0, 0x6771)},
378 {default_port_device(0x0af0, 0x6791)},
379 {default_port_device(0x0af0, 0x6811)},
380 {default_port_device(0x0af0, 0x6911)},
381 {default_port_device(0x0af0, 0x6951)},
382 {default_port_device(0x0af0, 0x6971)},
383 {default_port_device(0x0af0, 0x7011)},
384 {default_port_device(0x0af0, 0x7031)},
385 {default_port_device(0x0af0, 0x7051)},
386 {default_port_device(0x0af0, 0x7071)},
387 {default_port_device(0x0af0, 0x7111)},
388 {default_port_device(0x0af0, 0x7211)},
389 {default_port_device(0x0af0, 0x7251)},
390 {default_port_device(0x0af0, 0x7271)},
391 {default_port_device(0x0af0, 0x7311)},
392 {default_port_device(0x0af0, 0xc031)}, /* Icon-Edge */
393 {icon321_port_device(0x0af0, 0xd013)}, /* Module HSxPA */
394 {icon321_port_device(0x0af0, 0xd031)}, /* Icon-321 */
395 {default_port_device(0x0af0, 0xd033)}, /* Icon-322 */
396 {USB_DEVICE(0x0af0, 0x7301)}, /* GE40x */
397 {USB_DEVICE(0x0af0, 0x7361)}, /* GE40x */
398 {USB_DEVICE(0x0af0, 0x7401)}, /* GI 0401 */
399 {USB_DEVICE(0x0af0, 0x7501)}, /* GTM 382 */
400 {USB_DEVICE(0x0af0, 0x7601)}, /* GE40x */
401 {}
402};
403MODULE_DEVICE_TABLE(usb, hso_ids);
404
405/* Sysfs attribute */
406static ssize_t hso_sysfs_show_porttype(struct device *dev,
407 struct device_attribute *attr,
408 char *buf)
409{
410 struct hso_device *hso_dev = dev->driver_data;
411 char *port_name;
412
413 if (!hso_dev)
414 return 0;
415
416 switch (hso_dev->port_spec & HSO_PORT_MASK) {
417 case HSO_PORT_CONTROL:
418 port_name = "Control";
419 break;
420 case HSO_PORT_APP:
421 port_name = "Application";
422 break;
423 case HSO_PORT_APP2:
424 port_name = "Application2";
425 break;
426 case HSO_PORT_GPS:
427 port_name = "GPS";
428 break;
429 case HSO_PORT_GPS_CONTROL:
430 port_name = "GPS Control";
431 break;
432 case HSO_PORT_PCSC:
433 port_name = "PCSC";
434 break;
435 case HSO_PORT_DIAG:
436 port_name = "Diagnostic";
437 break;
438 case HSO_PORT_DIAG2:
439 port_name = "Diagnostic2";
440 break;
441 case HSO_PORT_MODEM:
442 port_name = "Modem";
443 break;
444 case HSO_PORT_NETWORK:
445 port_name = "Network";
446 break;
447 default:
448 port_name = "Unknown";
449 break;
450 }
451
452 return sprintf(buf, "%s\n", port_name);
453}
454static DEVICE_ATTR(hsotype, S_IRUGO, hso_sysfs_show_porttype, NULL);
455
456/* converts mux value to a port spec value */
457static u32 hso_mux_to_port(int mux)
458{
459 u32 result;
460
461 switch (mux) {
462 case 0x1:
463 result = HSO_PORT_CONTROL;
464 break;
465 case 0x2:
466 result = HSO_PORT_APP;
467 break;
468 case 0x4:
469 result = HSO_PORT_PCSC;
470 break;
471 case 0x8:
472 result = HSO_PORT_GPS;
473 break;
474 case 0x10:
475 result = HSO_PORT_APP2;
476 break;
477 default:
478 result = HSO_PORT_NO_PORT;
479 }
480 return result;
481}
482
483/* converts port spec value to a mux value */
484static u32 hso_port_to_mux(int port)
485{
486 u32 result;
487
488 switch (port & HSO_PORT_MASK) {
489 case HSO_PORT_CONTROL:
490 result = 0x0;
491 break;
492 case HSO_PORT_APP:
493 result = 0x1;
494 break;
495 case HSO_PORT_PCSC:
496 result = 0x2;
497 break;
498 case HSO_PORT_GPS:
499 result = 0x3;
500 break;
501 case HSO_PORT_APP2:
502 result = 0x4;
503 break;
504 default:
505 result = 0x0;
506 }
507 return result;
508}
509
510static struct hso_serial *get_serial_by_shared_int_and_type(
511 struct hso_shared_int *shared_int,
512 int mux)
513{
514 int i, port;
515
516 port = hso_mux_to_port(mux);
517
518 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
519 if (serial_table[i]
520 && (dev2ser(serial_table[i])->shared_int == shared_int)
521 && ((serial_table[i]->port_spec & HSO_PORT_MASK) == port)) {
522 return dev2ser(serial_table[i]);
523 }
524 }
525
526 return NULL;
527}
528
529static struct hso_serial *get_serial_by_index(unsigned index)
530{
531 struct hso_serial *serial;
532 unsigned long flags;
533
534 if (!serial_table[index])
535 return NULL;
536 spin_lock_irqsave(&serial_table_lock, flags);
537 serial = dev2ser(serial_table[index]);
538 spin_unlock_irqrestore(&serial_table_lock, flags);
539
540 return serial;
541}
542
543static int get_free_serial_index(void)
544{
545 int index;
546 unsigned long flags;
547
548 spin_lock_irqsave(&serial_table_lock, flags);
549 for (index = 0; index < HSO_SERIAL_TTY_MINORS; index++) {
550 if (serial_table[index] == NULL) {
551 spin_unlock_irqrestore(&serial_table_lock, flags);
552 return index;
553 }
554 }
555 spin_unlock_irqrestore(&serial_table_lock, flags);
556
557 printk(KERN_ERR "%s: no free serial devices in table\n", __func__);
558 return -1;
559}
560
561static void set_serial_by_index(unsigned index, struct hso_serial *serial)
562{
563 unsigned long flags;
564 spin_lock_irqsave(&serial_table_lock, flags);
565 if (serial)
566 serial_table[index] = serial->parent;
567 else
568 serial_table[index] = NULL;
569 spin_unlock_irqrestore(&serial_table_lock, flags);
570}
571
572/* log a meaningfull explanation of an USB status */
573static void log_usb_status(int status, const char *function)
574{
575 char *explanation;
576
577 switch (status) {
578 case -ENODEV:
579 explanation = "no device";
580 break;
581 case -ENOENT:
582 explanation = "endpoint not enabled";
583 break;
584 case -EPIPE:
585 explanation = "endpoint stalled";
586 break;
587 case -ENOSPC:
588 explanation = "not enough bandwidth";
589 break;
590 case -ESHUTDOWN:
591 explanation = "device disabled";
592 break;
593 case -EHOSTUNREACH:
594 explanation = "device suspended";
595 break;
596 case -EINVAL:
597 case -EAGAIN:
598 case -EFBIG:
599 case -EMSGSIZE:
600 explanation = "internal error";
601 break;
602 default:
603 explanation = "unknown status";
604 break;
605 }
606 D1("%s: received USB status - %s (%d)", function, explanation, status);
607}
608
609/* Network interface functions */
610
611/* called when net interface is brought up by ifconfig */
612static int hso_net_open(struct net_device *net)
613{
614 struct hso_net *odev = netdev_priv(net);
615 unsigned long flags = 0;
616
617 if (!odev) {
618 dev_err(&net->dev, "No net device !\n");
619 return -ENODEV;
620 }
621
622 odev->skb_tx_buf = NULL;
623
624 /* setup environment */
625 spin_lock_irqsave(&odev->net_lock, flags);
626 odev->rx_parse_state = WAIT_IP;
627 odev->rx_buf_size = 0;
628 odev->rx_buf_missing = sizeof(struct iphdr);
629 spin_unlock_irqrestore(&odev->net_lock, flags);
630
631 hso_start_net_device(odev->parent);
632
633 /* We are up and running. */
634 set_bit(HSO_NET_RUNNING, &odev->flags);
635
636 /* Tell the kernel we are ready to start receiving from it */
637 netif_start_queue(net);
638
639 return 0;
640}
641
642/* called when interface is brought down by ifconfig */
643static int hso_net_close(struct net_device *net)
644{
645 struct hso_net *odev = netdev_priv(net);
646
647 /* we don't need the queue anymore */
648 netif_stop_queue(net);
649 /* no longer running */
650 clear_bit(HSO_NET_RUNNING, &odev->flags);
651
652 hso_stop_net_device(odev->parent);
653
654 /* done */
655 return 0;
656}
657
658/* USB tells is xmit done, we should start the netqueue again */
659static void write_bulk_callback(struct urb *urb)
660{
661 struct hso_net *odev = urb->context;
662 int status = urb->status;
663
664 /* Sanity check */
665 if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) {
666 dev_err(&urb->dev->dev, "%s: device not running\n", __func__);
667 return;
668 }
669
670 /* Do we still have a valid kernel network device? */
671 if (!netif_device_present(odev->net)) {
672 dev_err(&urb->dev->dev, "%s: net device not present\n",
673 __func__);
674 return;
675 }
676
677 /* log status, but don't act on it, we don't need to resubmit anything
678 * anyhow */
679 if (status)
680 log_usb_status(status, __func__);
681
682 hso_put_activity(odev->parent);
683
684 /* Tell the network interface we are ready for another frame */
685 netif_wake_queue(odev->net);
686}
687
688/* called by kernel when we need to transmit a packet */
689static int hso_net_start_xmit(struct sk_buff *skb, struct net_device *net)
690{
691 struct hso_net *odev = netdev_priv(net);
692 int result;
693
694 /* Tell the kernel, "No more frames 'til we are done with this one." */
695 netif_stop_queue(net);
696 if (hso_get_activity(odev->parent) == -EAGAIN) {
697 odev->skb_tx_buf = skb;
698 return 0;
699 }
700
701 /* log if asked */
702 DUMP1(skb->data, skb->len);
703 /* Copy it from kernel memory to OUR memory */
704 memcpy(odev->mux_bulk_tx_buf, skb->data, skb->len);
705 D1("len: %d/%d", skb->len, MUX_BULK_TX_BUF_SIZE);
706
707 /* Fill in the URB for shipping it out. */
708 usb_fill_bulk_urb(odev->mux_bulk_tx_urb,
709 odev->parent->usb,
710 usb_sndbulkpipe(odev->parent->usb,
711 odev->out_endp->
712 bEndpointAddress & 0x7F),
713 odev->mux_bulk_tx_buf, skb->len, write_bulk_callback,
714 odev);
715
716 /* Deal with the Zero Length packet problem, I hope */
717 odev->mux_bulk_tx_urb->transfer_flags |= URB_ZERO_PACKET;
718
719 /* Send the URB on its merry way. */
720 result = usb_submit_urb(odev->mux_bulk_tx_urb, GFP_ATOMIC);
721 if (result) {
722 dev_warn(&odev->parent->interface->dev,
723 "failed mux_bulk_tx_urb %d", result);
724 net->stats.tx_errors++;
725 netif_start_queue(net);
726 } else {
727 net->stats.tx_packets++;
728 net->stats.tx_bytes += skb->len;
729 /* And tell the kernel when the last transmit started. */
730 net->trans_start = jiffies;
731 }
732 dev_kfree_skb(skb);
733 /* we're done */
734 return result;
735}
736
737static void hso_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
738{
739 struct hso_net *odev = netdev_priv(net);
740
741 strncpy(info->driver, driver_name, ETHTOOL_BUSINFO_LEN);
742 strncpy(info->version, DRIVER_VERSION, ETHTOOL_BUSINFO_LEN);
743 usb_make_path(odev->parent->usb, info->bus_info, sizeof info->bus_info);
744}
745
746static struct ethtool_ops ops = {
747 .get_drvinfo = hso_get_drvinfo,
748 .get_link = ethtool_op_get_link
749};
750
751/* called when a packet did not ack after watchdogtimeout */
752static void hso_net_tx_timeout(struct net_device *net)
753{
754 struct hso_net *odev = netdev_priv(net);
755
756 if (!odev)
757 return;
758
759 /* Tell syslog we are hosed. */
760 dev_warn(&net->dev, "Tx timed out.\n");
761
762 /* Tear the waiting frame off the list */
763 if (odev->mux_bulk_tx_urb
764 && (odev->mux_bulk_tx_urb->status == -EINPROGRESS))
765 usb_unlink_urb(odev->mux_bulk_tx_urb);
766
767 /* Update statistics */
768 net->stats.tx_errors++;
769}
770
771/* make a real packet from the received USB buffer */
772static void packetizeRx(struct hso_net *odev, unsigned char *ip_pkt,
773 unsigned int count, unsigned char is_eop)
774{
775 unsigned short temp_bytes;
776 unsigned short buffer_offset = 0;
777 unsigned short frame_len;
778 unsigned char *tmp_rx_buf;
779
780 /* log if needed */
781 D1("Rx %d bytes", count);
782 DUMP(ip_pkt, min(128, (int)count));
783
784 while (count) {
785 switch (odev->rx_parse_state) {
786 case WAIT_IP:
787 /* waiting for IP header. */
788 /* wanted bytes - size of ip header */
789 temp_bytes =
790 (count <
791 odev->rx_buf_missing) ? count : odev->
792 rx_buf_missing;
793
794 memcpy(((unsigned char *)(&odev->rx_ip_hdr)) +
795 odev->rx_buf_size, ip_pkt + buffer_offset,
796 temp_bytes);
797
798 odev->rx_buf_size += temp_bytes;
799 buffer_offset += temp_bytes;
800 odev->rx_buf_missing -= temp_bytes;
801 count -= temp_bytes;
802
803 if (!odev->rx_buf_missing) {
804 /* header is complete allocate an sk_buffer and
805 * continue to WAIT_DATA */
806 frame_len = ntohs(odev->rx_ip_hdr.tot_len);
807
808 if ((frame_len > DEFAULT_MRU) ||
809 (frame_len < sizeof(struct iphdr))) {
810 dev_err(&odev->net->dev,
811 "Invalid frame (%d) length\n",
812 frame_len);
813 odev->rx_parse_state = WAIT_SYNC;
814 continue;
815 }
816 /* Allocate an sk_buff */
817 odev->skb_rx_buf = dev_alloc_skb(frame_len);
818 if (!odev->skb_rx_buf) {
819 /* We got no receive buffer. */
820 D1("could not allocate memory");
821 odev->rx_parse_state = WAIT_SYNC;
822 return;
823 }
824 /* Here's where it came from */
825 odev->skb_rx_buf->dev = odev->net;
826
827 /* Copy what we got so far. make room for iphdr
828 * after tail. */
829 tmp_rx_buf =
830 skb_put(odev->skb_rx_buf,
831 sizeof(struct iphdr));
832 memcpy(tmp_rx_buf, (char *)&(odev->rx_ip_hdr),
833 sizeof(struct iphdr));
834
835 /* ETH_HLEN */
836 odev->rx_buf_size = sizeof(struct iphdr);
837
838 /* Filip actually use .tot_len */
839 odev->rx_buf_missing =
840 frame_len - sizeof(struct iphdr);
841 odev->rx_parse_state = WAIT_DATA;
842 }
843 break;
844
845 case WAIT_DATA:
846 temp_bytes = (count < odev->rx_buf_missing)
847 ? count : odev->rx_buf_missing;
848
849 /* Copy the rest of the bytes that are left in the
850 * buffer into the waiting sk_buf. */
851 /* Make room for temp_bytes after tail. */
852 tmp_rx_buf = skb_put(odev->skb_rx_buf, temp_bytes);
853 memcpy(tmp_rx_buf, ip_pkt + buffer_offset, temp_bytes);
854
855 odev->rx_buf_missing -= temp_bytes;
856 count -= temp_bytes;
857 buffer_offset += temp_bytes;
858 odev->rx_buf_size += temp_bytes;
859 if (!odev->rx_buf_missing) {
860 /* Packet is complete. Inject into stack. */
861 /* We have IP packet here */
862 odev->skb_rx_buf->protocol =
863 __constant_htons(ETH_P_IP);
864 /* don't check it */
865 odev->skb_rx_buf->ip_summed =
866 CHECKSUM_UNNECESSARY;
867
868 skb_reset_mac_header(odev->skb_rx_buf);
869
870 /* Ship it off to the kernel */
871 netif_rx(odev->skb_rx_buf);
872 /* No longer our buffer. */
873 odev->skb_rx_buf = NULL;
874
875 /* update out statistics */
876 odev->net->stats.rx_packets++;
877
878 odev->net->stats.rx_bytes += odev->rx_buf_size;
879
880 odev->rx_buf_size = 0;
881 odev->rx_buf_missing = sizeof(struct iphdr);
882 odev->rx_parse_state = WAIT_IP;
883 }
884 break;
885
886 case WAIT_SYNC:
887 D1(" W_S");
888 count = 0;
889 break;
890 default:
891 D1(" ");
892 count--;
893 break;
894 }
895 }
896
897 /* Recovery mechanism for WAIT_SYNC state. */
898 if (is_eop) {
899 if (odev->rx_parse_state == WAIT_SYNC) {
900 odev->rx_parse_state = WAIT_IP;
901 odev->rx_buf_size = 0;
902 odev->rx_buf_missing = sizeof(struct iphdr);
903 }
904 }
905}
906
907/* Moving data from usb to kernel (in interrupt state) */
908static void read_bulk_callback(struct urb *urb)
909{
910 struct hso_net *odev = urb->context;
911 struct net_device *net;
912 int result;
913 int status = urb->status;
914
915 /* is al ok? (Filip: Who's Al ?) */
916 if (status) {
917 log_usb_status(status, __func__);
918 return;
919 }
920
921 /* Sanity check */
922 if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) {
923 D1("BULK IN callback but driver is not active!");
924 return;
925 }
926 usb_mark_last_busy(urb->dev);
927
928 net = odev->net;
929
930 if (!netif_device_present(net)) {
931 /* Somebody killed our network interface... */
932 return;
933 }
934
935 if (odev->parent->port_spec & HSO_INFO_CRC_BUG) {
936 u32 rest;
937 u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF };
938 rest = urb->actual_length % odev->in_endp->wMaxPacketSize;
939 if (((rest == 5) || (rest == 6))
940 && !memcmp(((u8 *) urb->transfer_buffer) +
941 urb->actual_length - 4, crc_check, 4)) {
942 urb->actual_length -= 4;
943 }
944 }
945
946 /* do we even have a packet? */
947 if (urb->actual_length) {
948 /* Handle the IP stream, add header and push it onto network
949 * stack if the packet is complete. */
950 spin_lock(&odev->net_lock);
951 packetizeRx(odev, urb->transfer_buffer, urb->actual_length,
952 (urb->transfer_buffer_length >
953 urb->actual_length) ? 1 : 0);
954 spin_unlock(&odev->net_lock);
955 }
956
957 /* We are done with this URB, resubmit it. Prep the USB to wait for
958 * another frame. Reuse same as received. */
959 usb_fill_bulk_urb(urb,
960 odev->parent->usb,
961 usb_rcvbulkpipe(odev->parent->usb,
962 odev->in_endp->
963 bEndpointAddress & 0x7F),
964 urb->transfer_buffer, MUX_BULK_RX_BUF_SIZE,
965 read_bulk_callback, odev);
966
967 /* Give this to the USB subsystem so it can tell us when more data
968 * arrives. */
969 result = usb_submit_urb(urb, GFP_ATOMIC);
970 if (result)
971 dev_warn(&odev->parent->interface->dev,
972 "%s failed submit mux_bulk_rx_urb %d", __func__,
973 result);
974}
975
976/* Serial driver functions */
977
978static void _hso_serial_set_termios(struct tty_struct *tty,
979 struct ktermios *old)
980{
981 struct hso_serial *serial = get_serial_by_tty(tty);
982 struct ktermios *termios;
983
984 if ((!tty) || (!tty->termios) || (!serial)) {
985 printk(KERN_ERR "%s: no tty structures", __func__);
986 return;
987 }
988
989 D4("port %d", serial->minor);
990
991 /*
992 * The default requirements for this device are:
993 */
994 termios = tty->termios;
995 termios->c_iflag &=
996 ~(IGNBRK /* disable ignore break */
997 | BRKINT /* disable break causes interrupt */
998 | PARMRK /* disable mark parity errors */
999 | ISTRIP /* disable clear high bit of input characters */
1000 | INLCR /* disable translate NL to CR */
1001 | IGNCR /* disable ignore CR */
1002 | ICRNL /* disable translate CR to NL */
1003 | IXON); /* disable enable XON/XOFF flow control */
1004
1005 /* disable postprocess output characters */
1006 termios->c_oflag &= ~OPOST;
1007
1008 termios->c_lflag &=
1009 ~(ECHO /* disable echo input characters */
1010 | ECHONL /* disable echo new line */
1011 | ICANON /* disable erase, kill, werase, and rprnt
1012 special characters */
1013 | ISIG /* disable interrupt, quit, and suspend special
1014 characters */
1015 | IEXTEN); /* disable non-POSIX special characters */
1016
1017 termios->c_cflag &=
1018 ~(CSIZE /* no size */
1019 | PARENB /* disable parity bit */
1020 | CBAUD /* clear current baud rate */
1021 | CBAUDEX); /* clear current buad rate */
1022
1023 termios->c_cflag |= CS8; /* character size 8 bits */
1024
1025 /* baud rate 115200 */
1026 tty_encode_baud_rate(serial->tty, 115200, 115200);
1027
1028 /*
1029 * Force low_latency on; otherwise the pushes are scheduled;
1030 * this is bad as it opens up the possibility of dropping bytes
1031 * on the floor. We don't want to drop bytes on the floor. :)
1032 */
1033 serial->tty->low_latency = 1;
1034 return;
1035}
1036
1037/* open the requested serial port */
1038static int hso_serial_open(struct tty_struct *tty, struct file *filp)
1039{
1040 struct hso_serial *serial = get_serial_by_index(tty->index);
1041 int result;
1042
1043 /* sanity check */
1044 if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) {
1045 tty->driver_data = NULL;
1046 D1("Failed to open port");
1047 return -ENODEV;
1048 }
1049
1050 mutex_lock(&serial->parent->mutex);
1051 result = usb_autopm_get_interface(serial->parent->interface);
1052 if (result < 0)
1053 goto err_out;
1054
1055 D1("Opening %d", serial->minor);
1056 kref_get(&serial->parent->ref);
1057
1058 /* setup */
1059 tty->driver_data = serial;
1060 serial->tty = tty;
1061
1062 /* check for port allready opened, if not set the termios */
1063 serial->open_count++;
1064 if (serial->open_count == 1) {
1065 tty->low_latency = 1;
1066 serial->flags = 0;
1067 /* Force default termio settings */
1068 _hso_serial_set_termios(tty, NULL);
1069 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
1070 if (result) {
1071 hso_stop_serial_device(serial->parent);
1072 serial->open_count--;
1073 kref_put(&serial->parent->ref, hso_serial_ref_free);
1074 }
1075 } else {
1076 D1("Port was already open");
1077 }
1078
1079 usb_autopm_put_interface(serial->parent->interface);
1080
1081 /* done */
1082 if (result)
1083 hso_serial_tiocmset(tty, NULL, TIOCM_RTS | TIOCM_DTR, 0);
1084err_out:
1085 mutex_unlock(&serial->parent->mutex);
1086 return result;
1087}
1088
1089/* close the requested serial port */
1090static void hso_serial_close(struct tty_struct *tty, struct file *filp)
1091{
1092 struct hso_serial *serial = tty->driver_data;
1093 u8 usb_gone;
1094
1095 D1("Closing serial port");
1096
1097 mutex_lock(&serial->parent->mutex);
1098 usb_gone = serial->parent->usb_gone;
1099
1100 if (!usb_gone)
1101 usb_autopm_get_interface(serial->parent->interface);
1102
1103 /* reset the rts and dtr */
1104 /* do the actual close */
1105 serial->open_count--;
1106 if (serial->open_count <= 0) {
1107 kref_put(&serial->parent->ref, hso_serial_ref_free);
1108 serial->open_count = 0;
1109 if (serial->tty) {
1110 serial->tty->driver_data = NULL;
1111 serial->tty = NULL;
1112 }
1113 if (!usb_gone)
1114 hso_stop_serial_device(serial->parent);
1115 }
1116 if (!usb_gone)
1117 usb_autopm_put_interface(serial->parent->interface);
1118 mutex_unlock(&serial->parent->mutex);
1119}
1120
1121/* close the requested serial port */
1122static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf,
1123 int count)
1124{
1125 struct hso_serial *serial = get_serial_by_tty(tty);
1126 int space, tx_bytes;
1127 unsigned long flags;
1128
1129 /* sanity check */
1130 if (serial == NULL) {
1131 printk(KERN_ERR "%s: serial is NULL\n", __func__);
1132 return -ENODEV;
1133 }
1134
1135 spin_lock_irqsave(&serial->serial_lock, flags);
1136
1137 space = serial->tx_data_length - serial->tx_buffer_count;
1138 tx_bytes = (count < space) ? count : space;
1139
1140 if (!tx_bytes)
1141 goto out;
1142
1143 memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, tx_bytes);
1144 serial->tx_buffer_count += tx_bytes;
1145
1146out:
1147 spin_unlock_irqrestore(&serial->serial_lock, flags);
1148
1149 hso_kick_transmit(serial);
1150 /* done */
1151 return tx_bytes;
1152}
1153
1154/* how much room is there for writing */
1155static int hso_serial_write_room(struct tty_struct *tty)
1156{
1157 struct hso_serial *serial = get_serial_by_tty(tty);
1158 int room;
1159 unsigned long flags;
1160
1161 spin_lock_irqsave(&serial->serial_lock, flags);
1162 room = serial->tx_data_length - serial->tx_buffer_count;
1163 spin_unlock_irqrestore(&serial->serial_lock, flags);
1164
1165 /* return free room */
1166 return room;
1167}
1168
1169/* setup the term */
1170static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
1171{
1172 struct hso_serial *serial = get_serial_by_tty(tty);
1173 unsigned long flags;
1174
1175 if (old)
1176 D5("Termios called with: cflags new[%d] - old[%d]",
1177 tty->termios->c_cflag, old->c_cflag);
1178
1179 /* the actual setup */
1180 spin_lock_irqsave(&serial->serial_lock, flags);
1181 if (serial->open_count)
1182 _hso_serial_set_termios(tty, old);
1183 else
1184 tty->termios = old;
1185 spin_unlock_irqrestore(&serial->serial_lock, flags);
1186
1187 /* done */
1188 return;
1189}
1190
1191/* how many characters in the buffer */
1192static int hso_serial_chars_in_buffer(struct tty_struct *tty)
1193{
1194 struct hso_serial *serial = get_serial_by_tty(tty);
1195 int chars;
1196 unsigned long flags;
1197
1198 /* sanity check */
1199 if (serial == NULL)
1200 return 0;
1201
1202 spin_lock_irqsave(&serial->serial_lock, flags);
1203 chars = serial->tx_buffer_count;
1204 spin_unlock_irqrestore(&serial->serial_lock, flags);
1205
1206 return chars;
1207}
1208
1209static int hso_serial_tiocmget(struct tty_struct *tty, struct file *file)
1210{
1211 unsigned int value;
1212 struct hso_serial *serial = get_serial_by_tty(tty);
1213 unsigned long flags;
1214
1215 /* sanity check */
1216 if (!serial) {
1217 D1("no tty structures");
1218 return -EINVAL;
1219 }
1220
1221 spin_lock_irqsave(&serial->serial_lock, flags);
1222 value = ((serial->rts_state) ? TIOCM_RTS : 0) |
1223 ((serial->dtr_state) ? TIOCM_DTR : 0);
1224 spin_unlock_irqrestore(&serial->serial_lock, flags);
1225
1226 return value;
1227}
1228
1229static int hso_serial_tiocmset(struct tty_struct *tty, struct file *file,
1230 unsigned int set, unsigned int clear)
1231{
1232 int val = 0;
1233 unsigned long flags;
1234 int if_num;
1235 struct hso_serial *serial = get_serial_by_tty(tty);
1236
1237 /* sanity check */
1238 if (!serial) {
1239 D1("no tty structures");
1240 return -EINVAL;
1241 }
1242 if_num = serial->parent->interface->altsetting->desc.bInterfaceNumber;
1243
1244 spin_lock_irqsave(&serial->serial_lock, flags);
1245 if (set & TIOCM_RTS)
1246 serial->rts_state = 1;
1247 if (set & TIOCM_DTR)
1248 serial->dtr_state = 1;
1249
1250 if (clear & TIOCM_RTS)
1251 serial->rts_state = 0;
1252 if (clear & TIOCM_DTR)
1253 serial->dtr_state = 0;
1254
1255 if (serial->dtr_state)
1256 val |= 0x01;
1257 if (serial->rts_state)
1258 val |= 0x02;
1259
1260 spin_unlock_irqrestore(&serial->serial_lock, flags);
1261
1262 return usb_control_msg(serial->parent->usb,
1263 usb_rcvctrlpipe(serial->parent->usb, 0), 0x22,
1264 0x21, val, if_num, NULL, 0,
1265 USB_CTRL_SET_TIMEOUT);
1266}
1267
1268/* starts a transmit */
1269static void hso_kick_transmit(struct hso_serial *serial)
1270{
1271 u8 *temp;
1272 unsigned long flags;
1273 int res;
1274
1275 spin_lock_irqsave(&serial->serial_lock, flags);
1276 if (!serial->tx_buffer_count)
1277 goto out;
1278
1279 if (serial->tx_urb_used)
1280 goto out;
1281
1282 /* Wakeup USB interface if necessary */
1283 if (hso_get_activity(serial->parent) == -EAGAIN)
1284 goto out;
1285
1286 /* Switch pointers around to avoid memcpy */
1287 temp = serial->tx_buffer;
1288 serial->tx_buffer = serial->tx_data;
1289 serial->tx_data = temp;
1290 serial->tx_data_count = serial->tx_buffer_count;
1291 serial->tx_buffer_count = 0;
1292
1293 /* If temp is set, it means we switched buffers */
1294 if (temp && serial->write_data) {
1295 res = serial->write_data(serial);
1296 if (res >= 0)
1297 serial->tx_urb_used = 1;
1298 }
1299out:
1300 spin_unlock_irqrestore(&serial->serial_lock, flags);
1301}
1302
1303/* make a request (for reading and writing data to muxed serial port) */
1304static int mux_device_request(struct hso_serial *serial, u8 type, u16 port,
1305 struct urb *ctrl_urb,
1306 struct usb_ctrlrequest *ctrl_req,
1307 u8 *ctrl_urb_data, u32 size)
1308{
1309 int result;
1310 int pipe;
1311
1312 /* Sanity check */
1313 if (!serial || !ctrl_urb || !ctrl_req) {
1314 printk(KERN_ERR "%s: Wrong arguments\n", __func__);
1315 return -EINVAL;
1316 }
1317
1318 /* initialize */
1319 ctrl_req->wValue = 0;
1320 ctrl_req->wIndex = hso_port_to_mux(port);
1321 ctrl_req->wLength = size;
1322
1323 if (type == USB_CDC_GET_ENCAPSULATED_RESPONSE) {
1324 /* Reading command */
1325 ctrl_req->bRequestType = USB_DIR_IN |
1326 USB_TYPE_OPTION_VENDOR |
1327 USB_RECIP_INTERFACE;
1328 ctrl_req->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE;
1329 pipe = usb_rcvctrlpipe(serial->parent->usb, 0);
1330 } else {
1331 /* Writing command */
1332 ctrl_req->bRequestType = USB_DIR_OUT |
1333 USB_TYPE_OPTION_VENDOR |
1334 USB_RECIP_INTERFACE;
1335 ctrl_req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND;
1336 pipe = usb_sndctrlpipe(serial->parent->usb, 0);
1337 }
1338 /* syslog */
1339 D2("%s command (%02x) len: %d, port: %d",
1340 type == USB_CDC_GET_ENCAPSULATED_RESPONSE ? "Read" : "Write",
1341 ctrl_req->bRequestType, ctrl_req->wLength, port);
1342
1343 /* Load ctrl urb */
1344 ctrl_urb->transfer_flags = 0;
1345 usb_fill_control_urb(ctrl_urb,
1346 serial->parent->usb,
1347 pipe,
1348 (u8 *) ctrl_req,
1349 ctrl_urb_data, size, ctrl_callback, serial);
1350 /* Send it on merry way */
1351 result = usb_submit_urb(ctrl_urb, GFP_ATOMIC);
1352 if (result) {
1353 dev_err(&ctrl_urb->dev->dev,
1354 "%s failed submit ctrl_urb %d type %d", __func__,
1355 result, type);
1356 return result;
1357 }
1358
1359 /* done */
1360 return size;
1361}
1362
1363/* called by intr_callback when read occurs */
1364static int hso_mux_serial_read(struct hso_serial *serial)
1365{
1366 if (!serial)
1367 return -EINVAL;
1368
1369 /* clean data */
1370 memset(serial->rx_data[0], 0, CTRL_URB_RX_SIZE);
1371 /* make the request */
1372
1373 if (serial->num_rx_urbs != 1) {
1374 dev_err(&serial->parent->interface->dev,
1375 "ERROR: mux'd reads with multiple buffers "
1376 "not possible\n");
1377 return 0;
1378 }
1379 return mux_device_request(serial,
1380 USB_CDC_GET_ENCAPSULATED_RESPONSE,
1381 serial->parent->port_spec & HSO_PORT_MASK,
1382 serial->rx_urb[0],
1383 &serial->ctrl_req_rx,
1384 serial->rx_data[0], serial->rx_data_length);
1385}
1386
1387/* used for muxed serial port callback (muxed serial read) */
1388static void intr_callback(struct urb *urb)
1389{
1390 struct hso_shared_int *shared_int = urb->context;
1391 struct hso_serial *serial;
1392 unsigned char *port_req;
1393 int status = urb->status;
1394 int i;
1395
1396 usb_mark_last_busy(urb->dev);
1397
1398 /* sanity check */
1399 if (!shared_int)
1400 return;
1401
1402 /* status check */
1403 if (status) {
1404 log_usb_status(status, __func__);
1405 return;
1406 }
1407 D4("\n--- Got intr callback 0x%02X ---", status);
1408
1409 /* what request? */
1410 port_req = urb->transfer_buffer;
1411 D4(" port_req = 0x%.2X\n", *port_req);
1412 /* loop over all muxed ports to find the one sending this */
1413 for (i = 0; i < 8; i++) {
1414 /* max 8 channels on MUX */
1415 if (*port_req & (1 << i)) {
1416 serial = get_serial_by_shared_int_and_type(shared_int,
1417 (1 << i));
1418 if (serial != NULL) {
1419 D1("Pending read interrupt on port %d\n", i);
1420 if (!test_and_set_bit(HSO_SERIAL_FLAG_RX_SENT,
1421 &serial->flags)) {
1422 /* Setup and send a ctrl req read on
1423 * port i */
1424 hso_mux_serial_read(serial);
1425 } else {
1426 D1("Already pending a read on "
1427 "port %d\n", i);
1428 }
1429 }
1430 }
1431 }
1432 /* Resubmit interrupt urb */
1433 hso_mux_submit_intr_urb(shared_int, urb->dev, GFP_ATOMIC);
1434}
1435
1436/* called for writing to muxed serial port */
1437static int hso_mux_serial_write_data(struct hso_serial *serial)
1438{
1439 if (NULL == serial)
1440 return -EINVAL;
1441
1442 return mux_device_request(serial,
1443 USB_CDC_SEND_ENCAPSULATED_COMMAND,
1444 serial->parent->port_spec & HSO_PORT_MASK,
1445 serial->tx_urb,
1446 &serial->ctrl_req_tx,
1447 serial->tx_data, serial->tx_data_count);
1448}
1449
1450/* write callback for Diag and CS port */
1451static void hso_std_serial_write_bulk_callback(struct urb *urb)
1452{
1453 struct hso_serial *serial = urb->context;
1454 int status = urb->status;
1455
1456 /* sanity check */
1457 if (!serial) {
1458 D1("serial == NULL");
1459 return;
1460 }
1461
1462 spin_lock(&serial->serial_lock);
1463 serial->tx_urb_used = 0;
1464 spin_unlock(&serial->serial_lock);
1465 if (status) {
1466 log_usb_status(status, __func__);
1467 return;
1468 }
1469 hso_put_activity(serial->parent);
1470 tty_wakeup(serial->tty);
1471 hso_kick_transmit(serial);
1472
1473 D1(" ");
1474 return;
1475}
1476
1477/* called for writing diag or CS serial port */
1478static int hso_std_serial_write_data(struct hso_serial *serial)
1479{
1480 int count = serial->tx_data_count;
1481 int result;
1482
1483 usb_fill_bulk_urb(serial->tx_urb,
1484 serial->parent->usb,
1485 usb_sndbulkpipe(serial->parent->usb,
1486 serial->out_endp->
1487 bEndpointAddress & 0x7F),
1488 serial->tx_data, serial->tx_data_count,
1489 hso_std_serial_write_bulk_callback, serial);
1490
1491 result = usb_submit_urb(serial->tx_urb, GFP_ATOMIC);
1492 if (result) {
1493 dev_warn(&serial->parent->usb->dev,
1494 "Failed to submit urb - res %d\n", result);
1495 return result;
1496 }
1497
1498 return count;
1499}
1500
1501/* callback after read or write on muxed serial port */
1502static void ctrl_callback(struct urb *urb)
1503{
1504 struct hso_serial *serial = urb->context;
1505 struct usb_ctrlrequest *req;
1506 int status = urb->status;
1507
1508 /* sanity check */
1509 if (!serial)
1510 return;
1511
1512 spin_lock(&serial->serial_lock);
1513 serial->tx_urb_used = 0;
1514 spin_unlock(&serial->serial_lock);
1515 if (status) {
1516 log_usb_status(status, __func__);
1517 return;
1518 }
1519
1520 /* what request? */
1521 req = (struct usb_ctrlrequest *)(urb->setup_packet);
1522 D4("\n--- Got muxed ctrl callback 0x%02X ---", status);
1523 D4("Actual length of urb = %d\n", urb->actual_length);
1524 DUMP1(urb->transfer_buffer, urb->actual_length);
1525
1526 if (req->bRequestType ==
1527 (USB_DIR_IN | USB_TYPE_OPTION_VENDOR | USB_RECIP_INTERFACE)) {
1528 /* response to a read command */
1529 if (serial->open_count > 0) {
1530 /* handle RX data the normal way */
1531 put_rxbuf_data(urb, serial);
1532 }
1533
1534 /* Re issue a read as long as we receive data. */
1535 if (urb->actual_length != 0)
1536 hso_mux_serial_read(serial);
1537 else
1538 clear_bit(HSO_SERIAL_FLAG_RX_SENT, &serial->flags);
1539 } else {
1540 hso_put_activity(serial->parent);
1541 tty_wakeup(serial->tty);
1542 /* response to a write command */
1543 hso_kick_transmit(serial);
1544 }
1545}
1546
1547/* handle RX data for serial port */
1548static void put_rxbuf_data(struct urb *urb, struct hso_serial *serial)
1549{
1550 struct tty_struct *tty = serial->tty;
1551
1552 /* Sanity check */
1553 if (urb == NULL || serial == NULL) {
1554 D1("serial = NULL");
1555 return;
1556 }
1557
1558 /* Push data to tty */
1559 if (tty && urb->actual_length) {
1560 D1("data to push to tty");
1561 tty_insert_flip_string(tty, urb->transfer_buffer,
1562 urb->actual_length);
1563 tty_flip_buffer_push(tty);
1564 }
1565}
1566
1567/* read callback for Diag and CS port */
1568static void hso_std_serial_read_bulk_callback(struct urb *urb)
1569{
1570 struct hso_serial *serial = urb->context;
1571 int result;
1572 int status = urb->status;
1573
1574 /* sanity check */
1575 if (!serial) {
1576 D1("serial == NULL");
1577 return;
1578 } else if (status) {
1579 log_usb_status(status, __func__);
1580 return;
1581 }
1582
1583 D4("\n--- Got serial_read_bulk callback %02x ---", status);
1584 D1("Actual length = %d\n", urb->actual_length);
1585 DUMP1(urb->transfer_buffer, urb->actual_length);
1586
1587 /* Anyone listening? */
1588 if (serial->open_count == 0)
1589 return;
1590
1591 if (status == 0) {
1592 if (serial->parent->port_spec & HSO_INFO_CRC_BUG) {
1593 u32 rest;
1594 u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF };
1595 rest =
1596 urb->actual_length %
1597 serial->in_endp->wMaxPacketSize;
1598 if (((rest == 5) || (rest == 6))
1599 && !memcmp(((u8 *) urb->transfer_buffer) +
1600 urb->actual_length - 4, crc_check, 4)) {
1601 urb->actual_length -= 4;
1602 }
1603 }
1604 /* Valid data, handle RX data */
1605 put_rxbuf_data(urb, serial);
1606 } else if (status == -ENOENT || status == -ECONNRESET) {
1607 /* Unlinked - check for throttled port. */
1608 D2("Port %d, successfully unlinked urb", serial->minor);
1609 } else {
1610 D2("Port %d, status = %d for read urb", serial->minor, status);
1611 return;
1612 }
1613
1614 usb_mark_last_busy(urb->dev);
1615
1616 /* We are done with this URB, resubmit it. Prep the USB to wait for
1617 * another frame */
1618 usb_fill_bulk_urb(urb, serial->parent->usb,
1619 usb_rcvbulkpipe(serial->parent->usb,
1620 serial->in_endp->
1621 bEndpointAddress & 0x7F),
1622 urb->transfer_buffer, serial->rx_data_length,
1623 hso_std_serial_read_bulk_callback, serial);
1624 /* Give this to the USB subsystem so it can tell us when more data
1625 * arrives. */
1626 result = usb_submit_urb(urb, GFP_ATOMIC);
1627 if (result) {
1628 dev_err(&urb->dev->dev, "%s failed submit serial rx_urb %d",
1629 __func__, result);
1630 }
1631}
1632
1633/* Base driver functions */
1634
1635static void hso_log_port(struct hso_device *hso_dev)
1636{
1637 char *port_type;
1638 char port_dev[20];
1639
1640 switch (hso_dev->port_spec & HSO_PORT_MASK) {
1641 case HSO_PORT_CONTROL:
1642 port_type = "Control";
1643 break;
1644 case HSO_PORT_APP:
1645 port_type = "Application";
1646 break;
1647 case HSO_PORT_GPS:
1648 port_type = "GPS";
1649 break;
1650 case HSO_PORT_GPS_CONTROL:
1651 port_type = "GPS control";
1652 break;
1653 case HSO_PORT_APP2:
1654 port_type = "Application2";
1655 break;
1656 case HSO_PORT_PCSC:
1657 port_type = "PCSC";
1658 break;
1659 case HSO_PORT_DIAG:
1660 port_type = "Diagnostic";
1661 break;
1662 case HSO_PORT_DIAG2:
1663 port_type = "Diagnostic2";
1664 break;
1665 case HSO_PORT_MODEM:
1666 port_type = "Modem";
1667 break;
1668 case HSO_PORT_NETWORK:
1669 port_type = "Network";
1670 break;
1671 default:
1672 port_type = "Unknown";
1673 break;
1674 }
1675 if ((hso_dev->port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) {
1676 sprintf(port_dev, "%s", dev2net(hso_dev)->net->name);
1677 } else
1678 sprintf(port_dev, "/dev/%s%d", tty_filename,
1679 dev2ser(hso_dev)->minor);
1680
1681 dev_dbg(&hso_dev->interface->dev, "HSO: Found %s port %s\n",
1682 port_type, port_dev);
1683}
1684
1685static int hso_start_net_device(struct hso_device *hso_dev)
1686{
1687 int i, result = 0;
1688 struct hso_net *hso_net = dev2net(hso_dev);
1689
1690 if (!hso_net)
1691 return -ENODEV;
1692
1693 /* send URBs for all read buffers */
1694 for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
1695
1696 /* Prep a receive URB */
1697 usb_fill_bulk_urb(hso_net->mux_bulk_rx_urb_pool[i],
1698 hso_dev->usb,
1699 usb_rcvbulkpipe(hso_dev->usb,
1700 hso_net->in_endp->
1701 bEndpointAddress & 0x7F),
1702 hso_net->mux_bulk_rx_buf_pool[i],
1703 MUX_BULK_RX_BUF_SIZE, read_bulk_callback,
1704 hso_net);
1705
1706 /* Put it out there so the device can send us stuff */
1707 result = usb_submit_urb(hso_net->mux_bulk_rx_urb_pool[i],
1708 GFP_NOIO);
1709 if (result)
1710 dev_warn(&hso_dev->usb->dev,
1711 "%s failed mux_bulk_rx_urb[%d] %d\n", __func__,
1712 i, result);
1713 }
1714
1715 return result;
1716}
1717
1718static int hso_stop_net_device(struct hso_device *hso_dev)
1719{
1720 int i;
1721 struct hso_net *hso_net = dev2net(hso_dev);
1722
1723 if (!hso_net)
1724 return -ENODEV;
1725
1726 for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
1727 if (hso_net->mux_bulk_rx_urb_pool[i])
1728 usb_kill_urb(hso_net->mux_bulk_rx_urb_pool[i]);
1729
1730 }
1731 if (hso_net->mux_bulk_tx_urb)
1732 usb_kill_urb(hso_net->mux_bulk_tx_urb);
1733
1734 return 0;
1735}
1736
1737static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags)
1738{
1739 int i, result = 0;
1740 struct hso_serial *serial = dev2ser(hso_dev);
1741
1742 if (!serial)
1743 return -ENODEV;
1744
1745 /* If it is not the MUX port fill in and submit a bulk urb (already
1746 * allocated in hso_serial_start) */
1747 if (!(serial->parent->port_spec & HSO_INTF_MUX)) {
1748 for (i = 0; i < serial->num_rx_urbs; i++) {
1749 usb_fill_bulk_urb(serial->rx_urb[i],
1750 serial->parent->usb,
1751 usb_rcvbulkpipe(serial->parent->usb,
1752 serial->in_endp->
1753 bEndpointAddress &
1754 0x7F),
1755 serial->rx_data[i],
1756 serial->rx_data_length,
1757 hso_std_serial_read_bulk_callback,
1758 serial);
1759 result = usb_submit_urb(serial->rx_urb[i], flags);
1760 if (result) {
1761 dev_warn(&serial->parent->usb->dev,
1762 "Failed to submit urb - res %d\n",
1763 result);
1764 break;
1765 }
1766 }
1767 } else {
1768 mutex_lock(&serial->shared_int->shared_int_lock);
1769 if (!serial->shared_int->use_count) {
1770 result =
1771 hso_mux_submit_intr_urb(serial->shared_int,
1772 hso_dev->usb, flags);
1773 }
1774 serial->shared_int->use_count++;
1775 mutex_unlock(&serial->shared_int->shared_int_lock);
1776 }
1777
1778 return result;
1779}
1780
1781static int hso_stop_serial_device(struct hso_device *hso_dev)
1782{
1783 int i;
1784 struct hso_serial *serial = dev2ser(hso_dev);
1785
1786 if (!serial)
1787 return -ENODEV;
1788
1789 for (i = 0; i < serial->num_rx_urbs; i++) {
1790 if (serial->rx_urb[i])
1791 usb_kill_urb(serial->rx_urb[i]);
1792 }
1793
1794 if (serial->tx_urb)
1795 usb_kill_urb(serial->tx_urb);
1796
1797 if (serial->shared_int) {
1798 mutex_lock(&serial->shared_int->shared_int_lock);
1799 if (serial->shared_int->use_count &&
1800 (--serial->shared_int->use_count == 0)) {
1801 struct urb *urb;
1802
1803 urb = serial->shared_int->shared_intr_urb;
1804 if (urb)
1805 usb_kill_urb(urb);
1806 }
1807 mutex_unlock(&serial->shared_int->shared_int_lock);
1808 }
1809
1810 return 0;
1811}
1812
1813static void hso_serial_common_free(struct hso_serial *serial)
1814{
1815 int i;
1816
1817 if (serial->parent->dev)
1818 device_remove_file(serial->parent->dev, &dev_attr_hsotype);
1819
1820 tty_unregister_device(tty_drv, serial->minor);
1821
1822 for (i = 0; i < serial->num_rx_urbs; i++) {
1823 /* unlink and free RX URB */
1824 usb_free_urb(serial->rx_urb[i]);
1825 /* free the RX buffer */
1826 kfree(serial->rx_data[i]);
1827 }
1828
1829 /* unlink and free TX URB */
1830 usb_free_urb(serial->tx_urb);
1831 kfree(serial->tx_data);
1832}
1833
1834static int hso_serial_common_create(struct hso_serial *serial, int num_urbs,
1835 int rx_size, int tx_size)
1836{
1837 struct device *dev;
1838 int minor;
1839 int i;
1840
1841 minor = get_free_serial_index();
1842 if (minor < 0)
1843 goto exit;
1844
1845 /* register our minor number */
1846 serial->parent->dev = tty_register_device(tty_drv, minor,
1847 &serial->parent->interface->dev);
1848 dev = serial->parent->dev;
1849 dev->driver_data = serial->parent;
1850 i = device_create_file(dev, &dev_attr_hsotype);
1851
1852 /* fill in specific data for later use */
1853 serial->minor = minor;
1854 serial->magic = HSO_SERIAL_MAGIC;
1855 spin_lock_init(&serial->serial_lock);
1856 serial->num_rx_urbs = num_urbs;
1857
1858 /* RX, allocate urb and initialize */
1859
1860 /* prepare our RX buffer */
1861 serial->rx_data_length = rx_size;
1862 for (i = 0; i < serial->num_rx_urbs; i++) {
1863 serial->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
1864 if (!serial->rx_urb[i]) {
1865 dev_err(dev, "Could not allocate urb?\n");
1866 goto exit;
1867 }
1868 serial->rx_urb[i]->transfer_buffer = NULL;
1869 serial->rx_urb[i]->transfer_buffer_length = 0;
1870 serial->rx_data[i] = kzalloc(serial->rx_data_length,
1871 GFP_KERNEL);
1872 if (!serial->rx_data[i]) {
1873 dev_err(dev, "%s - Out of memory\n", __func__);
1874 goto exit;
1875 }
1876 }
1877
1878 /* TX, allocate urb and initialize */
1879 serial->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
1880 if (!serial->tx_urb) {
1881 dev_err(dev, "Could not allocate urb?\n");
1882 goto exit;
1883 }
1884 serial->tx_urb->transfer_buffer = NULL;
1885 serial->tx_urb->transfer_buffer_length = 0;
1886 /* prepare our TX buffer */
1887 serial->tx_data_count = 0;
1888 serial->tx_buffer_count = 0;
1889 serial->tx_data_length = tx_size;
1890 serial->tx_data = kzalloc(serial->tx_data_length, GFP_KERNEL);
1891 if (!serial->tx_data) {
1892 dev_err(dev, "%s - Out of memory", __func__);
1893 goto exit;
1894 }
1895 serial->tx_buffer = kzalloc(serial->tx_data_length, GFP_KERNEL);
1896 if (!serial->tx_buffer) {
1897 dev_err(dev, "%s - Out of memory", __func__);
1898 goto exit;
1899 }
1900
1901 return 0;
1902exit:
1903 hso_serial_common_free(serial);
1904 return -1;
1905}
1906
1907/* Frees a general hso device */
1908static void hso_free_device(struct hso_device *hso_dev)
1909{
1910 kfree(hso_dev);
1911}
1912
1913/* Creates a general hso device */
1914static struct hso_device *hso_create_device(struct usb_interface *intf,
1915 int port_spec)
1916{
1917 struct hso_device *hso_dev;
1918
1919 hso_dev = kzalloc(sizeof(*hso_dev), GFP_ATOMIC);
1920 if (!hso_dev)
1921 return NULL;
1922
1923 hso_dev->port_spec = port_spec;
1924 hso_dev->usb = interface_to_usbdev(intf);
1925 hso_dev->interface = intf;
1926 kref_init(&hso_dev->ref);
1927 mutex_init(&hso_dev->mutex);
1928
1929 INIT_WORK(&hso_dev->async_get_intf, async_get_intf);
1930 INIT_WORK(&hso_dev->async_put_intf, async_put_intf);
1931
1932 return hso_dev;
1933}
1934
1935/* Removes a network device in the network device table */
1936static int remove_net_device(struct hso_device *hso_dev)
1937{
1938 int i;
1939
1940 for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
1941 if (network_table[i] == hso_dev) {
1942 network_table[i] = NULL;
1943 break;
1944 }
1945 }
1946 if (i == HSO_MAX_NET_DEVICES)
1947 return -1;
1948 return 0;
1949}
1950
1951/* Frees our network device */
1952static void hso_free_net_device(struct hso_device *hso_dev)
1953{
1954 int i;
1955 struct hso_net *hso_net = dev2net(hso_dev);
1956
1957 if (!hso_net)
1958 return;
1959
1960 /* start freeing */
1961 for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
1962 usb_free_urb(hso_net->mux_bulk_rx_urb_pool[i]);
1963 kfree(hso_net->mux_bulk_rx_buf_pool[i]);
1964 }
1965 usb_free_urb(hso_net->mux_bulk_tx_urb);
1966 kfree(hso_net->mux_bulk_tx_buf);
1967
1968 remove_net_device(hso_net->parent);
1969
1970 if (hso_net->net) {
1971 unregister_netdev(hso_net->net);
1972 free_netdev(hso_net->net);
1973 }
1974
1975 hso_free_device(hso_dev);
1976}
1977
1978/* initialize the network interface */
1979static void hso_net_init(struct net_device *net)
1980{
1981 struct hso_net *hso_net = netdev_priv(net);
1982
1983 D1("sizeof hso_net is %d", (int)sizeof(*hso_net));
1984
1985 /* fill in the other fields */
1986 net->open = hso_net_open;
1987 net->stop = hso_net_close;
1988 net->hard_start_xmit = hso_net_start_xmit;
1989 net->tx_timeout = hso_net_tx_timeout;
1990 net->watchdog_timeo = HSO_NET_TX_TIMEOUT;
1991 net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
1992 net->type = ARPHRD_NONE;
1993 net->mtu = DEFAULT_MTU - 14;
1994 net->tx_queue_len = 10;
1995 SET_ETHTOOL_OPS(net, &ops);
1996
1997 /* and initialize the semaphore */
1998 spin_lock_init(&hso_net->net_lock);
1999}
2000
2001/* Adds a network device in the network device table */
2002static int add_net_device(struct hso_device *hso_dev)
2003{
2004 int i;
2005
2006 for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
2007 if (network_table[i] == NULL) {
2008 network_table[i] = hso_dev;
2009 break;
2010 }
2011 }
2012 if (i == HSO_MAX_NET_DEVICES)
2013 return -1;
2014 return 0;
2015}
2016
2017static int hso_radio_toggle(void *data, enum rfkill_state state)
2018{
2019 struct hso_device *hso_dev = data;
2020 int enabled = (state == RFKILL_STATE_ON);
2021 int rv;
2022
2023 mutex_lock(&hso_dev->mutex);
2024 if (hso_dev->usb_gone)
2025 rv = 0;
2026 else
2027 rv = usb_control_msg(hso_dev->usb, usb_rcvctrlpipe(hso_dev->usb, 0),
2028 enabled ? 0x82 : 0x81, 0x40, 0, 0, NULL, 0,
2029 USB_CTRL_SET_TIMEOUT);
2030 mutex_unlock(&hso_dev->mutex);
2031 return rv;
2032}
2033
2034/* Creates and sets up everything for rfkill */
2035static void hso_create_rfkill(struct hso_device *hso_dev,
2036 struct usb_interface *interface)
2037{
2038 struct hso_net *hso_net = dev2net(hso_dev);
2039 struct device *dev = hso_dev->dev;
2040 char *rfkn;
2041
2042 hso_net->rfkill = rfkill_allocate(&interface_to_usbdev(interface)->dev,
2043 RFKILL_TYPE_WLAN);
2044 if (!hso_net->rfkill) {
2045 dev_err(dev, "%s - Out of memory", __func__);
2046 return;
2047 }
2048 rfkn = kzalloc(20, GFP_KERNEL);
2049 if (!rfkn) {
2050 rfkill_free(hso_net->rfkill);
2051 dev_err(dev, "%s - Out of memory", __func__);
2052 return;
2053 }
2054 snprintf(rfkn, 20, "hso-%d",
2055 interface->altsetting->desc.bInterfaceNumber);
2056 hso_net->rfkill->name = rfkn;
2057 hso_net->rfkill->state = RFKILL_STATE_ON;
2058 hso_net->rfkill->data = hso_dev;
2059 hso_net->rfkill->toggle_radio = hso_radio_toggle;
2060 if (rfkill_register(hso_net->rfkill) < 0) {
2061 kfree(rfkn);
2062 hso_net->rfkill->name = NULL;
2063 rfkill_free(hso_net->rfkill);
2064 dev_err(dev, "%s - Failed to register rfkill", __func__);
2065 return;
2066 }
2067}
2068
2069/* Creates our network device */
2070static struct hso_device *hso_create_net_device(struct usb_interface *interface)
2071{
2072 int result, i;
2073 struct net_device *net;
2074 struct hso_net *hso_net;
2075 struct hso_device *hso_dev;
2076
2077 hso_dev = hso_create_device(interface, HSO_INTF_MUX | HSO_PORT_NETWORK);
2078 if (!hso_dev)
2079 return NULL;
2080
2081 /* allocate our network device, then we can put in our private data */
2082 /* call hso_net_init to do the basic initialization */
2083 net = alloc_netdev(sizeof(struct hso_net), "hso%d", hso_net_init);
2084 if (!net) {
2085 dev_err(&interface->dev, "Unable to create ethernet device\n");
2086 goto exit;
2087 }
2088
2089 hso_net = netdev_priv(net);
2090
2091 hso_dev->port_data.dev_net = hso_net;
2092 hso_net->net = net;
2093 hso_net->parent = hso_dev;
2094
2095 hso_net->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK,
2096 USB_DIR_IN);
2097 if (!hso_net->in_endp) {
2098 dev_err(&interface->dev, "Can't find BULK IN endpoint\n");
2099 goto exit;
2100 }
2101 hso_net->out_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK,
2102 USB_DIR_OUT);
2103 if (!hso_net->out_endp) {
2104 dev_err(&interface->dev, "Can't find BULK OUT endpoint\n");
2105 goto exit;
2106 }
2107 SET_NETDEV_DEV(net, &interface->dev);
2108
2109 /* registering our net device */
2110 result = register_netdev(net);
2111 if (result) {
2112 dev_err(&interface->dev, "Failed to register device\n");
2113 goto exit;
2114 }
2115
2116 /* start allocating */
2117 for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
2118 hso_net->mux_bulk_rx_urb_pool[i] = usb_alloc_urb(0, GFP_KERNEL);
2119 if (!hso_net->mux_bulk_rx_urb_pool[i]) {
2120 dev_err(&interface->dev, "Could not allocate rx urb\n");
2121 goto exit;
2122 }
2123 hso_net->mux_bulk_rx_buf_pool[i] = kzalloc(MUX_BULK_RX_BUF_SIZE,
2124 GFP_KERNEL);
2125 if (!hso_net->mux_bulk_rx_buf_pool[i]) {
2126 dev_err(&interface->dev, "Could not allocate rx buf\n");
2127 goto exit;
2128 }
2129 }
2130 hso_net->mux_bulk_tx_urb = usb_alloc_urb(0, GFP_KERNEL);
2131 if (!hso_net->mux_bulk_tx_urb) {
2132 dev_err(&interface->dev, "Could not allocate tx urb\n");
2133 goto exit;
2134 }
2135 hso_net->mux_bulk_tx_buf = kzalloc(MUX_BULK_TX_BUF_SIZE, GFP_KERNEL);
2136 if (!hso_net->mux_bulk_tx_buf) {
2137 dev_err(&interface->dev, "Could not allocate tx buf\n");
2138 goto exit;
2139 }
2140
2141 add_net_device(hso_dev);
2142
2143 hso_log_port(hso_dev);
2144
2145 hso_create_rfkill(hso_dev, interface);
2146
2147 return hso_dev;
2148exit:
2149 hso_free_net_device(hso_dev);
2150 return NULL;
2151}
2152
2153/* Frees an AT channel ( goes for both mux and non-mux ) */
2154static void hso_free_serial_device(struct hso_device *hso_dev)
2155{
2156 struct hso_serial *serial = dev2ser(hso_dev);
2157
2158 if (!serial)
2159 return;
2160 set_serial_by_index(serial->minor, NULL);
2161
2162 hso_serial_common_free(serial);
2163
2164 if (serial->shared_int) {
2165 mutex_lock(&serial->shared_int->shared_int_lock);
2166 if (--serial->shared_int->ref_count == 0)
2167 hso_free_shared_int(serial->shared_int);
2168 else
2169 mutex_unlock(&serial->shared_int->shared_int_lock);
2170 }
2171 kfree(serial);
2172 hso_free_device(hso_dev);
2173}
2174
2175/* Creates a bulk AT channel */
2176static struct hso_device *hso_create_bulk_serial_device(
2177 struct usb_interface *interface, int port)
2178{
2179 struct hso_device *hso_dev;
2180 struct hso_serial *serial;
2181 int num_urbs;
2182
2183 hso_dev = hso_create_device(interface, port);
2184 if (!hso_dev)
2185 return NULL;
2186
2187 serial = kzalloc(sizeof(*serial), GFP_KERNEL);
2188 if (!serial)
2189 goto exit;
2190
2191 serial->parent = hso_dev;
2192 hso_dev->port_data.dev_serial = serial;
2193
2194 if (port & HSO_PORT_MODEM)
2195 num_urbs = 2;
2196 else
2197 num_urbs = 1;
2198
2199 if (hso_serial_common_create(serial, num_urbs, BULK_URB_RX_SIZE,
2200 BULK_URB_TX_SIZE))
2201 goto exit;
2202
2203 serial->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK,
2204 USB_DIR_IN);
2205 if (!serial->in_endp) {
2206 dev_err(&interface->dev, "Failed to find BULK IN ep\n");
2207 goto exit;
2208 }
2209
2210 if (!
2211 (serial->out_endp =
2212 hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT))) {
2213 dev_err(&interface->dev, "Failed to find BULK IN ep\n");
2214 goto exit;
2215 }
2216
2217 serial->write_data = hso_std_serial_write_data;
2218
2219 /* and record this serial */
2220 set_serial_by_index(serial->minor, serial);
2221
2222 /* setup the proc dirs and files if needed */
2223 hso_log_port(hso_dev);
2224
2225 /* done, return it */
2226 return hso_dev;
2227exit:
2228 if (hso_dev && serial)
2229 hso_serial_common_free(serial);
2230 kfree(serial);
2231 hso_free_device(hso_dev);
2232 return NULL;
2233}
2234
2235/* Creates a multiplexed AT channel */
2236static
2237struct hso_device *hso_create_mux_serial_device(struct usb_interface *interface,
2238 int port,
2239 struct hso_shared_int *mux)
2240{
2241 struct hso_device *hso_dev;
2242 struct hso_serial *serial;
2243 int port_spec;
2244
2245 port_spec = HSO_INTF_MUX;
2246 port_spec &= ~HSO_PORT_MASK;
2247
2248 port_spec |= hso_mux_to_port(port);
2249 if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NO_PORT)
2250 return NULL;
2251
2252 hso_dev = hso_create_device(interface, port_spec);
2253 if (!hso_dev)
2254 return NULL;
2255
2256 serial = kzalloc(sizeof(*serial), GFP_KERNEL);
2257 if (!serial)
2258 goto exit;
2259
2260 hso_dev->port_data.dev_serial = serial;
2261 serial->parent = hso_dev;
2262
2263 if (hso_serial_common_create
2264 (serial, 1, CTRL_URB_RX_SIZE, CTRL_URB_TX_SIZE))
2265 goto exit;
2266
2267 serial->tx_data_length--;
2268 serial->write_data = hso_mux_serial_write_data;
2269
2270 serial->shared_int = mux;
2271 mutex_lock(&serial->shared_int->shared_int_lock);
2272 serial->shared_int->ref_count++;
2273 mutex_unlock(&serial->shared_int->shared_int_lock);
2274
2275 /* and record this serial */
2276 set_serial_by_index(serial->minor, serial);
2277
2278 /* setup the proc dirs and files if needed */
2279 hso_log_port(hso_dev);
2280
2281 /* done, return it */
2282 return hso_dev;
2283
2284exit:
2285 if (serial) {
2286 tty_unregister_device(tty_drv, serial->minor);
2287 kfree(serial);
2288 }
2289 if (hso_dev)
2290 hso_free_device(hso_dev);
2291 return NULL;
2292
2293}
2294
2295static void hso_free_shared_int(struct hso_shared_int *mux)
2296{
2297 usb_free_urb(mux->shared_intr_urb);
2298 kfree(mux->shared_intr_buf);
2299 mutex_unlock(&mux->shared_int_lock);
2300 kfree(mux);
2301}
2302
2303static
2304struct hso_shared_int *hso_create_shared_int(struct usb_interface *interface)
2305{
2306 struct hso_shared_int *mux = kzalloc(sizeof(*mux), GFP_KERNEL);
2307
2308 if (!mux)
2309 return NULL;
2310
2311 mux->intr_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_INT,
2312 USB_DIR_IN);
2313 if (!mux->intr_endp) {
2314 dev_err(&interface->dev, "Can't find INT IN endpoint\n");
2315 goto exit;
2316 }
2317
2318 mux->shared_intr_urb = usb_alloc_urb(0, GFP_KERNEL);
2319 if (!mux->shared_intr_urb) {
2320 dev_err(&interface->dev, "Could not allocate intr urb?");
2321 goto exit;
2322 }
2323 mux->shared_intr_buf = kzalloc(mux->intr_endp->wMaxPacketSize,
2324 GFP_KERNEL);
2325 if (!mux->shared_intr_buf) {
2326 dev_err(&interface->dev, "Could not allocate intr buf?");
2327 goto exit;
2328 }
2329
2330 mutex_init(&mux->shared_int_lock);
2331
2332 return mux;
2333
2334exit:
2335 kfree(mux->shared_intr_buf);
2336 usb_free_urb(mux->shared_intr_urb);
2337 kfree(mux);
2338 return NULL;
2339}
2340
2341/* Gets the port spec for a certain interface */
2342static int hso_get_config_data(struct usb_interface *interface)
2343{
2344 struct usb_device *usbdev = interface_to_usbdev(interface);
2345 u8 config_data[17];
2346 u32 if_num = interface->altsetting->desc.bInterfaceNumber;
2347 s32 result;
2348
2349 if (usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
2350 0x86, 0xC0, 0, 0, config_data, 17,
2351 USB_CTRL_SET_TIMEOUT) != 0x11) {
2352 return -EIO;
2353 }
2354
2355 switch (config_data[if_num]) {
2356 case 0x0:
2357 result = 0;
2358 break;
2359 case 0x1:
2360 result = HSO_PORT_DIAG;
2361 break;
2362 case 0x2:
2363 result = HSO_PORT_GPS;
2364 break;
2365 case 0x3:
2366 result = HSO_PORT_GPS_CONTROL;
2367 break;
2368 case 0x4:
2369 result = HSO_PORT_APP;
2370 break;
2371 case 0x5:
2372 result = HSO_PORT_APP2;
2373 break;
2374 case 0x6:
2375 result = HSO_PORT_CONTROL;
2376 break;
2377 case 0x7:
2378 result = HSO_PORT_NETWORK;
2379 break;
2380 case 0x8:
2381 result = HSO_PORT_MODEM;
2382 break;
2383 case 0x9:
2384 result = HSO_PORT_MSD;
2385 break;
2386 case 0xa:
2387 result = HSO_PORT_PCSC;
2388 break;
2389 case 0xb:
2390 result = HSO_PORT_VOICE;
2391 break;
2392 default:
2393 result = 0;
2394 }
2395
2396 if (result)
2397 result |= HSO_INTF_BULK;
2398
2399 if (config_data[16] & 0x1)
2400 result |= HSO_INFO_CRC_BUG;
2401
2402 return result;
2403}
2404
2405/* called once for each interface upon device insertion */
2406static int hso_probe(struct usb_interface *interface,
2407 const struct usb_device_id *id)
2408{
2409 int mux, i, if_num, port_spec;
2410 unsigned char port_mask;
2411 struct hso_device *hso_dev = NULL;
2412 struct hso_shared_int *shared_int;
2413 struct hso_device *tmp_dev = NULL;
2414
2415 if_num = interface->altsetting->desc.bInterfaceNumber;
2416
2417 /* Get the interface/port specification from either driver_info or from
2418 * the device itself */
2419 if (id->driver_info)
2420 port_spec = ((u32 *)(id->driver_info))[if_num];
2421 else
2422 port_spec = hso_get_config_data(interface);
2423
2424 if (interface->cur_altsetting->desc.bInterfaceClass != 0xFF) {
2425 dev_err(&interface->dev, "Not our interface\n");
2426 return -ENODEV;
2427 }
2428 /* Check if we need to switch to alt interfaces prior to port
2429 * configuration */
2430 if (interface->num_altsetting > 1)
2431 usb_set_interface(interface_to_usbdev(interface), if_num, 1);
2432 interface->needs_remote_wakeup = 1;
2433
2434 /* Allocate new hso device(s) */
2435 switch (port_spec & HSO_INTF_MASK) {
2436 case HSO_INTF_MUX:
2437 if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) {
2438 /* Create the network device */
2439 if (!disable_net) {
2440 hso_dev = hso_create_net_device(interface);
2441 if (!hso_dev)
2442 goto exit;
2443 tmp_dev = hso_dev;
2444 }
2445 }
2446
2447 if (hso_get_mux_ports(interface, &port_mask))
2448 /* TODO: de-allocate everything */
2449 goto exit;
2450
2451 shared_int = hso_create_shared_int(interface);
2452 if (!shared_int)
2453 goto exit;
2454
2455 for (i = 1, mux = 0; i < 0x100; i = i << 1, mux++) {
2456 if (port_mask & i) {
2457 hso_dev = hso_create_mux_serial_device(
2458 interface, i, shared_int);
2459 if (!hso_dev)
2460 goto exit;
2461 }
2462 }
2463
2464 if (tmp_dev)
2465 hso_dev = tmp_dev;
2466 break;
2467
2468 case HSO_INTF_BULK:
2469 /* It's a regular bulk interface */
2470 if (((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK)
2471 && !disable_net)
2472 hso_dev = hso_create_net_device(interface);
2473 else
2474 hso_dev =
2475 hso_create_bulk_serial_device(interface, port_spec);
2476 if (!hso_dev)
2477 goto exit;
2478 break;
2479 default:
2480 goto exit;
2481 }
2482
2483 usb_driver_claim_interface(&hso_driver, interface, hso_dev);
2484
2485 /* save our data pointer in this device */
2486 usb_set_intfdata(interface, hso_dev);
2487
2488 /* done */
2489 return 0;
2490exit:
2491 hso_free_interface(interface);
2492 return -ENODEV;
2493}
2494
2495/* device removed, cleaning up */
2496static void hso_disconnect(struct usb_interface *interface)
2497{
2498 hso_free_interface(interface);
2499
2500 /* remove reference of our private data */
2501 usb_set_intfdata(interface, NULL);
2502
2503 usb_driver_release_interface(&hso_driver, interface);
2504}
2505
2506static void async_get_intf(struct work_struct *data)
2507{
2508 struct hso_device *hso_dev =
2509 container_of(data, struct hso_device, async_get_intf);
2510 usb_autopm_get_interface(hso_dev->interface);
2511}
2512
2513static void async_put_intf(struct work_struct *data)
2514{
2515 struct hso_device *hso_dev =
2516 container_of(data, struct hso_device, async_put_intf);
2517 usb_autopm_put_interface(hso_dev->interface);
2518}
2519
2520static int hso_get_activity(struct hso_device *hso_dev)
2521{
2522 if (hso_dev->usb->state == USB_STATE_SUSPENDED) {
2523 if (!hso_dev->is_active) {
2524 hso_dev->is_active = 1;
2525 schedule_work(&hso_dev->async_get_intf);
2526 }
2527 }
2528
2529 if (hso_dev->usb->state != USB_STATE_CONFIGURED)
2530 return -EAGAIN;
2531
2532 usb_mark_last_busy(hso_dev->usb);
2533
2534 return 0;
2535}
2536
2537static int hso_put_activity(struct hso_device *hso_dev)
2538{
2539 if (hso_dev->usb->state != USB_STATE_SUSPENDED) {
2540 if (hso_dev->is_active) {
2541 hso_dev->is_active = 0;
2542 schedule_work(&hso_dev->async_put_intf);
2543 return -EAGAIN;
2544 }
2545 }
2546 hso_dev->is_active = 0;
2547 return 0;
2548}
2549
2550/* called by kernel when we need to suspend device */
2551static int hso_suspend(struct usb_interface *iface, pm_message_t message)
2552{
2553 int i, result;
2554
2555 /* Stop all serial ports */
2556 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
2557 if (serial_table[i] && (serial_table[i]->interface == iface)) {
2558 result = hso_stop_serial_device(serial_table[i]);
2559 if (result)
2560 goto out;
2561 }
2562 }
2563
2564 /* Stop all network ports */
2565 for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
2566 if (network_table[i] &&
2567 (network_table[i]->interface == iface)) {
2568 result = hso_stop_net_device(network_table[i]);
2569 if (result)
2570 goto out;
2571 }
2572 }
2573
2574out:
2575 return 0;
2576}
2577
2578/* called by kernel when we need to resume device */
2579static int hso_resume(struct usb_interface *iface)
2580{
2581 int i, result = 0;
2582 struct hso_net *hso_net;
2583
2584 /* Start all serial ports */
2585 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
2586 if (serial_table[i] && (serial_table[i]->interface == iface)) {
2587 if (dev2ser(serial_table[i])->open_count) {
2588 result =
2589 hso_start_serial_device(serial_table[i], GFP_NOIO);
2590 hso_kick_transmit(dev2ser(serial_table[i]));
2591 if (result)
2592 goto out;
2593 }
2594 }
2595 }
2596
2597 /* Start all network ports */
2598 for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
2599 if (network_table[i] &&
2600 (network_table[i]->interface == iface)) {
2601 hso_net = dev2net(network_table[i]);
2602 /* First transmit any lingering data, then restart the
2603 * device. */
2604 if (hso_net->skb_tx_buf) {
2605 dev_dbg(&iface->dev,
2606 "Transmitting lingering data\n");
2607 hso_net_start_xmit(hso_net->skb_tx_buf,
2608 hso_net->net);
2609 }
2610 result = hso_start_net_device(network_table[i]);
2611 if (result)
2612 goto out;
2613 }
2614 }
2615
2616out:
2617 return result;
2618}
2619
2620static void hso_serial_ref_free(struct kref *ref)
2621{
2622 struct hso_device *hso_dev = container_of(ref, struct hso_device, ref);
2623
2624 hso_free_serial_device(hso_dev);
2625}
2626
2627static void hso_free_interface(struct usb_interface *interface)
2628{
2629 struct hso_serial *hso_dev;
2630 int i;
2631
2632 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
2633 if (serial_table[i]
2634 && (serial_table[i]->interface == interface)) {
2635 hso_dev = dev2ser(serial_table[i]);
2636 if (hso_dev->tty)
2637 tty_hangup(hso_dev->tty);
2638 mutex_lock(&hso_dev->parent->mutex);
2639 hso_dev->parent->usb_gone = 1;
2640 mutex_unlock(&hso_dev->parent->mutex);
2641 kref_put(&serial_table[i]->ref, hso_serial_ref_free);
2642 }
2643 }
2644
2645 for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
2646 if (network_table[i]
2647 && (network_table[i]->interface == interface)) {
2648 struct rfkill *rfk = dev2net(network_table[i])->rfkill;
2649 /* hso_stop_net_device doesn't stop the net queue since
2650 * traffic needs to start it again when suspended */
2651 netif_stop_queue(dev2net(network_table[i])->net);
2652 hso_stop_net_device(network_table[i]);
2653 cancel_work_sync(&network_table[i]->async_put_intf);
2654 cancel_work_sync(&network_table[i]->async_get_intf);
2655 if(rfk)
2656 rfkill_unregister(rfk);
2657 hso_free_net_device(network_table[i]);
2658 }
2659 }
2660}
2661
2662/* Helper functions */
2663
2664/* Get the endpoint ! */
2665static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf,
2666 int type, int dir)
2667{
2668 int i;
2669 struct usb_host_interface *iface = intf->cur_altsetting;
2670 struct usb_endpoint_descriptor *endp;
2671
2672 for (i = 0; i < iface->desc.bNumEndpoints; i++) {
2673 endp = &iface->endpoint[i].desc;
2674 if (((endp->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == dir) &&
2675 ((endp->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == type))
2676 return endp;
2677 }
2678
2679 return NULL;
2680}
2681
2682/* Get the byte that describes which ports are enabled */
2683static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports)
2684{
2685 int i;
2686 struct usb_host_interface *iface = intf->cur_altsetting;
2687
2688 if (iface->extralen == 3) {
2689 *ports = iface->extra[2];
2690 return 0;
2691 }
2692
2693 for (i = 0; i < iface->desc.bNumEndpoints; i++) {
2694 if (iface->endpoint[i].extralen == 3) {
2695 *ports = iface->endpoint[i].extra[2];
2696 return 0;
2697 }
2698 }
2699
2700 return -1;
2701}
2702
2703/* interrupt urb needs to be submitted, used for serial read of muxed port */
2704static int hso_mux_submit_intr_urb(struct hso_shared_int *shared_int,
2705 struct usb_device *usb, gfp_t gfp)
2706{
2707 int result;
2708
2709 usb_fill_int_urb(shared_int->shared_intr_urb, usb,
2710 usb_rcvintpipe(usb,
2711 shared_int->intr_endp->bEndpointAddress & 0x7F),
2712 shared_int->shared_intr_buf,
2713 shared_int->intr_endp->wMaxPacketSize,
2714 intr_callback, shared_int,
2715 shared_int->intr_endp->bInterval);
2716
2717 result = usb_submit_urb(shared_int->shared_intr_urb, gfp);
2718 if (result)
2719 dev_warn(&usb->dev, "%s failed mux_intr_urb %d", __func__,
2720 result);
2721
2722 return result;
2723}
2724
2725/* operations setup of the serial interface */
2726static struct tty_operations hso_serial_ops = {
2727 .open = hso_serial_open,
2728 .close = hso_serial_close,
2729 .write = hso_serial_write,
2730 .write_room = hso_serial_write_room,
2731 .set_termios = hso_serial_set_termios,
2732 .chars_in_buffer = hso_serial_chars_in_buffer,
2733 .tiocmget = hso_serial_tiocmget,
2734 .tiocmset = hso_serial_tiocmset,
2735};
2736
2737static struct usb_driver hso_driver = {
2738 .name = driver_name,
2739 .probe = hso_probe,
2740 .disconnect = hso_disconnect,
2741 .id_table = hso_ids,
2742 .suspend = hso_suspend,
2743 .resume = hso_resume,
2744 .supports_autosuspend = 1,
2745};
2746
2747static int __init hso_init(void)
2748{
2749 int i;
2750 int result;
2751
2752 /* put it in the log */
2753 printk(KERN_INFO "hso: %s\n", version);
2754
2755 /* Initialise the serial table semaphore and table */
2756 spin_lock_init(&serial_table_lock);
2757 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++)
2758 serial_table[i] = NULL;
2759
2760 /* allocate our driver using the proper amount of supported minors */
2761 tty_drv = alloc_tty_driver(HSO_SERIAL_TTY_MINORS);
2762 if (!tty_drv)
2763 return -ENOMEM;
2764
2765 /* fill in all needed values */
2766 tty_drv->magic = TTY_DRIVER_MAGIC;
2767 tty_drv->owner = THIS_MODULE;
2768 tty_drv->driver_name = driver_name;
2769 tty_drv->name = tty_filename;
2770
2771 /* if major number is provided as parameter, use that one */
2772 if (tty_major)
2773 tty_drv->major = tty_major;
2774
2775 tty_drv->minor_start = 0;
2776 tty_drv->num = HSO_SERIAL_TTY_MINORS;
2777 tty_drv->type = TTY_DRIVER_TYPE_SERIAL;
2778 tty_drv->subtype = SERIAL_TYPE_NORMAL;
2779 tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
2780 tty_drv->init_termios = tty_std_termios;
2781 tty_drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2782 tty_drv->termios = hso_serial_termios;
2783 tty_drv->termios_locked = hso_serial_termios_locked;
2784 tty_set_operations(tty_drv, &hso_serial_ops);
2785
2786 /* register the tty driver */
2787 result = tty_register_driver(tty_drv);
2788 if (result) {
2789 printk(KERN_ERR "%s - tty_register_driver failed(%d)\n",
2790 __func__, result);
2791 return result;
2792 }
2793
2794 /* register this module as an usb driver */
2795 result = usb_register(&hso_driver);
2796 if (result) {
2797 printk(KERN_ERR "Could not register hso driver? error: %d\n",
2798 result);
2799 /* cleanup serial interface */
2800 tty_unregister_driver(tty_drv);
2801 return result;
2802 }
2803
2804 /* done */
2805 return 0;
2806}
2807
2808static void __exit hso_exit(void)
2809{
2810 printk(KERN_INFO "hso: unloaded\n");
2811
2812 tty_unregister_driver(tty_drv);
2813 /* deregister the usb driver */
2814 usb_deregister(&hso_driver);
2815}
2816
2817/* Module definitions */
2818module_init(hso_init);
2819module_exit(hso_exit);
2820
2821MODULE_AUTHOR(MOD_AUTHOR);
2822MODULE_DESCRIPTION(MOD_DESCRIPTION);
2823MODULE_LICENSE(MOD_LICENSE);
2824MODULE_INFO(Version, DRIVER_VERSION);
2825
2826/* change the debug level (eg: insmod hso.ko debug=0x04) */
2827MODULE_PARM_DESC(debug, "Level of debug [0x01 | 0x02 | 0x04 | 0x08 | 0x10]");
2828module_param(debug, int, S_IRUGO | S_IWUSR);
2829
2830/* set the major tty number (eg: insmod hso.ko tty_major=245) */
2831MODULE_PARM_DESC(tty_major, "Set the major tty number");
2832module_param(tty_major, int, S_IRUGO | S_IWUSR);
2833
2834/* disable network interface (eg: insmod hso.ko disable_net=1) */
2835MODULE_PARM_DESC(disable_net, "Disable the network interface");
2836module_param(disable_net, int, S_IRUGO | S_IWUSR);
diff --git a/include/linux/smc911x.h b/include/linux/smc911x.h
new file mode 100644
index 000000000000..b58f54c24183
--- /dev/null
+++ b/include/linux/smc911x.h
@@ -0,0 +1,12 @@
1#ifndef __SMC911X_H__
2#define __SMC911X_H__
3
4#define SMC911X_USE_16BIT (1 << 0)
5#define SMC911X_USE_32BIT (1 << 1)
6
7struct smc911x_platdata {
8 unsigned long flags;
9 unsigned long irq_flags; /* IRQF_... */
10};
11
12#endif /* __SMC911X_H__ */