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