Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* hplance.c : the Linux/hp300/lance ethernet driver |
| 2 | * |
| 3 | * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk> |
| 4 | * Based on the Sun Lance driver and the NetBSD HP Lance driver |
| 5 | * Uses the generic 7990.c LANCE code. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/string.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/errno.h> |
| 17 | /* Used for the temporal inet entries and routing */ |
| 18 | #include <linux/socket.h> |
| 19 | #include <linux/route.h> |
| 20 | #include <linux/dio.h> |
| 21 | #include <linux/netdevice.h> |
| 22 | #include <linux/etherdevice.h> |
| 23 | #include <linux/skbuff.h> |
| 24 | |
| 25 | #include <asm/system.h> |
| 26 | #include <asm/io.h> |
| 27 | #include <asm/pgtable.h> |
| 28 | |
| 29 | #include "hplance.h" |
| 30 | |
| 31 | /* We have 16834 bytes of RAM for the init block and buffers. This places |
| 32 | * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx |
| 33 | * buffers and 2 Tx buffers. |
| 34 | */ |
| 35 | #define LANCE_LOG_TX_BUFFERS 1 |
| 36 | #define LANCE_LOG_RX_BUFFERS 3 |
| 37 | |
| 38 | #include "7990.h" /* use generic LANCE code */ |
| 39 | |
| 40 | /* Our private data structure */ |
| 41 | struct hplance_private { |
| 42 | struct lance_private lance; |
| 43 | }; |
| 44 | |
| 45 | /* function prototypes... This is easy because all the grot is in the |
| 46 | * generic LANCE support. All we have to support is probing for boards, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 47 | * plus board-specific init, open and close actions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | * Oh, and we need to tell the generic code how to read and write LANCE registers... |
| 49 | */ |
| 50 | static int __devinit hplance_init_one(struct dio_dev *d, |
| 51 | const struct dio_device_id *ent); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 52 | static void __devinit hplance_init(struct net_device *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct dio_dev *d); |
| 54 | static void __devexit hplance_remove_one(struct dio_dev *d); |
| 55 | static void hplance_writerap(void *priv, unsigned short value); |
| 56 | static void hplance_writerdp(void *priv, unsigned short value); |
| 57 | static unsigned short hplance_readrdp(void *priv); |
| 58 | static int hplance_open(struct net_device *dev); |
| 59 | static int hplance_close(struct net_device *dev); |
| 60 | |
| 61 | static struct dio_device_id hplance_dio_tbl[] = { |
| 62 | { DIO_ID_LAN }, |
| 63 | { 0 } |
| 64 | }; |
| 65 | |
| 66 | static struct dio_driver hplance_driver = { |
| 67 | .name = "hplance", |
| 68 | .id_table = hplance_dio_tbl, |
| 69 | .probe = hplance_init_one, |
| 70 | .remove = __devexit_p(hplance_remove_one), |
| 71 | }; |
| 72 | |
Alexander Beregalov | 2e303a9 | 2009-04-15 12:52:38 +0000 | [diff] [blame] | 73 | static const struct net_device_ops hplance_netdev_ops = { |
| 74 | .ndo_open = hplance_open, |
| 75 | .ndo_stop = hplance_close, |
| 76 | .ndo_start_xmit = lance_start_xmit, |
| 77 | .ndo_set_multicast_list = lance_set_multicast, |
| 78 | .ndo_change_mtu = eth_change_mtu, |
| 79 | .ndo_validate_addr = eth_validate_addr, |
| 80 | .ndo_set_mac_address = eth_mac_addr, |
| 81 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 82 | .ndo_poll_controller = lance_poll, |
| 83 | #endif |
| 84 | }; |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* Find all the HP Lance boards and initialise them... */ |
| 87 | static int __devinit hplance_init_one(struct dio_dev *d, |
| 88 | const struct dio_device_id *ent) |
| 89 | { |
| 90 | struct net_device *dev; |
| 91 | int err = -ENOMEM; |
Kars de Jong | 8e8858e | 2006-12-09 10:29:58 +0100 | [diff] [blame] | 92 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | dev = alloc_etherdev(sizeof(struct hplance_private)); |
| 95 | if (!dev) |
| 96 | goto out; |
| 97 | |
| 98 | err = -EBUSY; |
| 99 | if (!request_mem_region(dio_resource_start(d), |
| 100 | dio_resource_len(d), d->name)) |
| 101 | goto out_free_netdev; |
| 102 | |
| 103 | hplance_init(dev, d); |
| 104 | err = register_netdev(dev); |
| 105 | if (err) |
| 106 | goto out_release_mem_region; |
| 107 | |
| 108 | dio_set_drvdata(d, dev); |
Kars de Jong | 8e8858e | 2006-12-09 10:29:58 +0100 | [diff] [blame] | 109 | |
| 110 | printk(KERN_INFO "%s: %s; select code %d, addr %2.2x", dev->name, d->name, d->scode, dev->dev_addr[0]); |
| 111 | |
| 112 | for (i=1; i<6; i++) { |
| 113 | printk(":%2.2x", dev->dev_addr[i]); |
| 114 | } |
| 115 | |
| 116 | printk(", irq %d\n", d->ipl); |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | return 0; |
| 119 | |
| 120 | out_release_mem_region: |
| 121 | release_mem_region(dio_resource_start(d), dio_resource_len(d)); |
| 122 | out_free_netdev: |
| 123 | free_netdev(dev); |
| 124 | out: |
| 125 | return err; |
| 126 | } |
| 127 | |
| 128 | static void __devexit hplance_remove_one(struct dio_dev *d) |
| 129 | { |
| 130 | struct net_device *dev = dio_get_drvdata(d); |
| 131 | |
| 132 | unregister_netdev(dev); |
| 133 | release_mem_region(dio_resource_start(d), dio_resource_len(d)); |
| 134 | free_netdev(dev); |
| 135 | } |
| 136 | |
| 137 | /* Initialise a single lance board at the given DIO device */ |
| 138 | static void __init hplance_init(struct net_device *dev, struct dio_dev *d) |
| 139 | { |
| 140 | unsigned long va = (d->resource.start + DIO_VIRADDRBASE); |
| 141 | struct hplance_private *lp; |
| 142 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* reset the board */ |
| 145 | out_8(va+DIO_IDOFF, 0xff); |
| 146 | udelay(100); /* ariba! ariba! udelay! udelay! */ |
| 147 | |
| 148 | /* Fill the dev fields */ |
| 149 | dev->base_addr = va; |
Alexander Beregalov | 2e303a9 | 2009-04-15 12:52:38 +0000 | [diff] [blame] | 150 | dev->netdev_ops = &hplance_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | dev->dma = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | for (i=0; i<6; i++) { |
| 154 | /* The NVRAM holds our ethernet address, one nibble per byte, |
| 155 | * at bytes NVRAMOFF+1,3,5,7,9... |
| 156 | */ |
| 157 | dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4) |
| 158 | | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | lp = netdev_priv(dev); |
| 162 | lp->lance.name = (char*)d->name; /* discards const, shut up gcc */ |
| 163 | lp->lance.base = va; |
| 164 | lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */ |
Al Viro | a5d361f | 2006-01-12 01:06:34 -0800 | [diff] [blame] | 165 | lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */ |
| 167 | lp->lance.irq = d->ipl; |
| 168 | lp->lance.writerap = hplance_writerap; |
| 169 | lp->lance.writerdp = hplance_writerdp; |
| 170 | lp->lance.readrdp = hplance_readrdp; |
| 171 | lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS; |
| 172 | lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS; |
| 173 | lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK; |
| 174 | lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /* This is disgusting. We have to check the DIO status register for ack every |
| 178 | * time we read or write the LANCE registers. |
| 179 | */ |
| 180 | static void hplance_writerap(void *priv, unsigned short value) |
| 181 | { |
| 182 | struct lance_private *lp = (struct lance_private *)priv; |
| 183 | do { |
| 184 | out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value); |
| 185 | } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0); |
| 186 | } |
| 187 | |
| 188 | static void hplance_writerdp(void *priv, unsigned short value) |
| 189 | { |
| 190 | struct lance_private *lp = (struct lance_private *)priv; |
| 191 | do { |
| 192 | out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value); |
| 193 | } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0); |
| 194 | } |
| 195 | |
| 196 | static unsigned short hplance_readrdp(void *priv) |
| 197 | { |
| 198 | struct lance_private *lp = (struct lance_private *)priv; |
| 199 | __u16 value; |
| 200 | do { |
| 201 | value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP); |
| 202 | } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0); |
| 203 | return value; |
| 204 | } |
| 205 | |
| 206 | static int hplance_open(struct net_device *dev) |
| 207 | { |
| 208 | int status; |
| 209 | struct lance_private *lp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | status = lance_open(dev); /* call generic lance open code */ |
| 212 | if (status) |
| 213 | return status; |
| 214 | /* enable interrupts at board level. */ |
| 215 | out_8(lp->base + HPLANCE_STATUS, LE_IE); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static int hplance_close(struct net_device *dev) |
| 221 | { |
| 222 | struct lance_private *lp = netdev_priv(dev); |
| 223 | |
| 224 | out_8(lp->base + HPLANCE_STATUS, 0); /* disable interrupts at boardlevel */ |
| 225 | lance_close(dev); |
| 226 | return 0; |
| 227 | } |
| 228 | |
Adrian Bunk | 0b11407 | 2008-06-10 01:23:32 +0300 | [diff] [blame] | 229 | static int __init hplance_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
Bjorn Helgaas | e51c01b | 2006-03-25 03:07:17 -0800 | [diff] [blame] | 231 | return dio_register_driver(&hplance_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Adrian Bunk | 0b11407 | 2008-06-10 01:23:32 +0300 | [diff] [blame] | 234 | static void __exit hplance_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
| 236 | dio_unregister_driver(&hplance_driver); |
| 237 | } |
| 238 | |
| 239 | module_init(hplance_init_module); |
| 240 | module_exit(hplance_cleanup_module); |
| 241 | |
| 242 | MODULE_LICENSE("GPL"); |