Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net-3-driver for the NI5210 card (i82586 Ethernet chip) |
| 3 | * |
| 4 | * This is an extension to the Linux operating system, and is covered by the |
| 5 | * same GNU General Public License that covers that work. |
| 6 | * |
| 7 | * Alphacode 0.82 (96/09/29) for Linux 2.0.0 (or later) |
| 8 | * Copyrights (c) 1994,1995,1996 by M.Hipp (hippm@informatik.uni-tuebingen.de) |
| 9 | * [feel free to mail ....] |
| 10 | * |
| 11 | * when using as module: (no autoprobing!) |
| 12 | * compile with: |
| 13 | * gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ -DMODULE -c ni52.c |
| 14 | * run with e.g: |
| 15 | * insmod ni52.o io=0x360 irq=9 memstart=0xd0000 memend=0xd4000 |
| 16 | * |
| 17 | * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!. |
| 18 | * |
| 19 | * If you find a bug, please report me: |
| 20 | * The kernel panic output and any kmsg from the ni52 driver |
| 21 | * the ni5210-driver-version and the linux-kernel version |
| 22 | * how many shared memory (memsize) on the netcard, |
| 23 | * bootprom: yes/no, base_addr, mem_start |
| 24 | * maybe the ni5210-card revision and the i82586 version |
| 25 | * |
| 26 | * autoprobe for: base_addr: 0x300,0x280,0x360,0x320,0x340 |
| 27 | * mem_start: 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000, |
| 28 | * 0xd8000,0xcc000,0xce000,0xda000,0xdc000 |
| 29 | * |
| 30 | * sources: |
| 31 | * skeleton.c from Donald Becker |
| 32 | * |
| 33 | * I have also done a look in the following sources: (mail me if you need them) |
| 34 | * crynwr-packet-driver by Russ Nelson |
| 35 | * Garret A. Wollman's (fourth) i82586-driver for BSD |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 36 | * (before getting an i82596 (yes 596 not 586) manual, the existing drivers |
| 37 | * helped me a lot to understand this tricky chip.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | * |
| 39 | * Known Problems: |
| 40 | * The internal sysbus seems to be slow. So we often lose packets because of |
| 41 | * overruns while receiving from a fast remote host. |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 42 | * This can slow down TCP connections. Maybe the newer ni5210 cards are |
| 43 | * better. My experience is, that if a machine sends with more than about |
| 44 | * 500-600K/s the fifo/sysbus overflows. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | * |
| 46 | * IMPORTANT NOTE: |
| 47 | * On fast networks, it's a (very) good idea to have 16K shared memory. With |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 48 | * 8K, we can store only 4 receive frames, so it can (easily) happen that a |
| 49 | * remote machine 'overruns' our system. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | * |
| 51 | * Known i82586/card problems (I'm sure, there are many more!): |
| 52 | * Running the NOP-mode, the i82586 sometimes seems to forget to report |
| 53 | * every xmit-interrupt until we restart the CU. |
| 54 | * Another MAJOR bug is, that the RU sometimes seems to ignore the EL-Bit |
| 55 | * in the RBD-Struct which indicates an end of the RBD queue. |
| 56 | * Instead, the RU fetches another (randomly selected and |
| 57 | * usually used) RBD and begins to fill it. (Maybe, this happens only if |
| 58 | * the last buffer from the previous RFD fits exact into the queue and |
| 59 | * the next RFD can't fetch an initial RBD. Anyone knows more? ) |
| 60 | * |
| 61 | * results from ftp performance tests with Linux 1.2.5 |
| 62 | * send and receive about 350-400 KByte/s (peak up to 460 kbytes/s) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 63 | * sending in NOP-mode: peak performance up to 530K/s (but better don't |
| 64 | * run this mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | */ |
| 66 | |
| 67 | /* |
| 68 | * 29.Sept.96: virt_to_bus changes for new memory scheme |
| 69 | * 19.Feb.96: more Mcast changes, module support (MH) |
| 70 | * |
| 71 | * 18.Nov.95: Mcast changes (AC). |
| 72 | * |
| 73 | * 23.April.95: fixed(?) receiving problems by configuring a RFD more |
| 74 | * than the number of RBD's. Can maybe cause other problems. |
| 75 | * 18.April.95: Added MODULE support (MH) |
| 76 | * 17.April.95: MC related changes in init586() and set_multicast_list(). |
| 77 | * removed use of 'jiffies' in init586() (MH) |
| 78 | * |
| 79 | * 19.Sep.94: Added Multicast support (not tested yet) (MH) |
| 80 | * |
| 81 | * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling. |
| 82 | * Now, every RFD has exact one RBD. (MH) |
| 83 | * |
| 84 | * 14.Sep.94: added promiscuous mode, a few cleanups (MH) |
| 85 | * |
| 86 | * 19.Aug.94: changed request_irq() parameter (MH) |
| 87 | * |
| 88 | * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH) |
| 89 | * |
| 90 | * 19.July.94: lotsa cleanups .. (MH) |
| 91 | * |
| 92 | * 17.July.94: some patches ... verified to run with 1.1.29 (MH) |
| 93 | * |
| 94 | * 4.July.94: patches for Linux 1.1.24 (MH) |
| 95 | * |
| 96 | * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH) |
| 97 | * |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 98 | * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff, |
| 99 | * too (MH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | * |
| 101 | * < 30.Sep.93: first versions |
| 102 | */ |
| 103 | |
| 104 | static int debuglevel; /* debug-printk 0: off 1: a few 2: more */ |
| 105 | static int automatic_resume; /* experimental .. better should be zero */ |
| 106 | static int rfdadd; /* rfdadd=1 may be better for 8K MEM cards */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 107 | static int fifo = 0x8; /* don't change */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | #include <linux/module.h> |
| 110 | #include <linux/kernel.h> |
| 111 | #include <linux/string.h> |
| 112 | #include <linux/errno.h> |
| 113 | #include <linux/ioport.h> |
| 114 | #include <linux/slab.h> |
| 115 | #include <linux/interrupt.h> |
| 116 | #include <linux/delay.h> |
| 117 | #include <linux/init.h> |
| 118 | #include <linux/bitops.h> |
| 119 | #include <asm/io.h> |
| 120 | |
| 121 | #include <linux/netdevice.h> |
| 122 | #include <linux/etherdevice.h> |
| 123 | #include <linux/skbuff.h> |
| 124 | |
| 125 | #include "ni52.h" |
| 126 | |
| 127 | #define DRV_NAME "ni52" |
| 128 | |
| 129 | #define DEBUG /* debug on */ |
| 130 | #define SYSBUSVAL 1 /* 8 Bit */ |
| 131 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 132 | #define ni_attn586() { outb(0, dev->base_addr + NI52_ATTENTION); } |
| 133 | #define ni_reset586() { outb(0, dev->base_addr + NI52_RESET); } |
| 134 | #define ni_disint() { outb(0, dev->base_addr + NI52_INTDIS); } |
| 135 | #define ni_enaint() { outb(0, dev->base_addr + NI52_INTENA); } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 137 | #define make32(ptr16) (p->memtop + (short) (ptr16)) |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 138 | #define make24(ptr32) ((char __iomem *)(ptr32)) - p->base |
| 139 | #define make16(ptr32) ((unsigned short) ((char __iomem *)(ptr32)\ |
| 140 | - p->memtop)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | /******************* how to calculate the buffers ***************************** |
| 143 | |
| 144 | * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works |
| 145 | * --------------- in a different (more stable?) mode. Only in this mode it's |
| 146 | * possible to configure the driver with 'NO_NOPCOMMANDS' |
| 147 | |
| 148 | sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8; |
| 149 | sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT |
| 150 | sizeof(rfd) = 24; sizeof(rbd) = 12; |
| 151 | sizeof(tbd) = 8; sizeof(transmit_cmd) = 16; |
| 152 | sizeof(nop_cmd) = 8; |
| 153 | |
| 154 | * if you don't know the driver, better do not change these values: */ |
| 155 | |
| 156 | #define RECV_BUFF_SIZE 1524 /* slightly oversized */ |
| 157 | #define XMIT_BUFF_SIZE 1524 /* slightly oversized */ |
| 158 | #define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */ |
| 159 | #define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */ |
| 160 | #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */ |
| 161 | #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */ |
| 162 | |
| 163 | /**************************************************************************/ |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | #define NI52_TOTAL_SIZE 16 |
| 167 | #define NI52_ADDR0 0x02 |
| 168 | #define NI52_ADDR1 0x07 |
| 169 | #define NI52_ADDR2 0x01 |
| 170 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 171 | static int ni52_probe1(struct net_device *dev, int ioaddr); |
| 172 | static irqreturn_t ni52_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | static int ni52_open(struct net_device *dev); |
| 174 | static int ni52_close(struct net_device *dev); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 175 | static int ni52_send_packet(struct sk_buff *, struct net_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | static struct net_device_stats *ni52_get_stats(struct net_device *dev); |
| 177 | static void set_multicast_list(struct net_device *dev); |
| 178 | static void ni52_timeout(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | /* helper-functions */ |
| 181 | static int init586(struct net_device *dev); |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 182 | static int check586(struct net_device *dev, unsigned size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | static void alloc586(struct net_device *dev); |
| 184 | static void startrecv586(struct net_device *dev); |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 185 | static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | static void ni52_rcv_int(struct net_device *dev); |
| 187 | static void ni52_xmt_int(struct net_device *dev); |
| 188 | static void ni52_rnr_int(struct net_device *dev); |
| 189 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 190 | struct priv { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | struct net_device_stats stats; |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 192 | char __iomem *base; |
| 193 | char __iomem *mapped; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 194 | char __iomem *memtop; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 195 | spinlock_t spinlock; |
| 196 | int reset; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 197 | struct rfd_struct __iomem *rfd_last, *rfd_top, *rfd_first; |
| 198 | struct scp_struct __iomem *scp; |
| 199 | struct iscp_struct __iomem *iscp; |
| 200 | struct scb_struct __iomem *scb; |
| 201 | struct tbd_struct __iomem *xmit_buffs[NUM_XMIT_BUFFS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | #if (NUM_XMIT_BUFFS == 1) |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 203 | struct transmit_cmd_struct __iomem *xmit_cmds[2]; |
| 204 | struct nop_cmd_struct __iomem *nop_cmds[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | #else |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 206 | struct transmit_cmd_struct __iomem *xmit_cmds[NUM_XMIT_BUFFS]; |
| 207 | struct nop_cmd_struct __iomem *nop_cmds[NUM_XMIT_BUFFS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | #endif |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 209 | int nop_point, num_recv_buffs; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 210 | char __iomem *xmit_cbuffs[NUM_XMIT_BUFFS]; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 211 | int xmit_count, xmit_last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 214 | /* wait for command with timeout: */ |
| 215 | static void wait_for_scb_cmd(struct net_device *dev) |
| 216 | { |
| 217 | struct priv *p = dev->priv; |
| 218 | int i; |
| 219 | for (i = 0; i < 16384; i++) { |
| 220 | if (readb(&p->scb->cmd_cuc) == 0) |
| 221 | break; |
| 222 | udelay(4); |
| 223 | if (i == 16383) { |
| 224 | printk(KERN_ERR "%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n", |
| 225 | dev->name, readb(&p->scb->cmd_cuc), readb(&p->scb->cus)); |
| 226 | if (!p->reset) { |
| 227 | p->reset = 1; |
| 228 | ni_reset586(); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | static void wait_for_scb_cmd_ruc(struct net_device *dev) |
| 235 | { |
| 236 | struct priv *p = dev->priv; |
| 237 | int i; |
| 238 | for (i = 0; i < 16384; i++) { |
| 239 | if (readb(&p->scb->cmd_ruc) == 0) |
| 240 | break; |
| 241 | udelay(4); |
| 242 | if (i == 16383) { |
| 243 | printk(KERN_ERR "%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n", |
| 244 | dev->name, p->scb->cmd_ruc, p->scb->rus); |
| 245 | if (!p->reset) { |
| 246 | p->reset = 1; |
| 247 | ni_reset586(); |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 253 | static void wait_for_stat_compl(void __iomem *p) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 254 | { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 255 | struct nop_cmd_struct __iomem *addr = p; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 256 | int i; |
| 257 | for (i = 0; i < 32767; i++) { |
| 258 | if (readw(&((addr)->cmd_status)) & STAT_COMPL) |
| 259 | break; |
| 260 | udelay(32); |
| 261 | } |
| 262 | } |
| 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | /********************************************** |
| 265 | * close device |
| 266 | */ |
| 267 | static int ni52_close(struct net_device *dev) |
| 268 | { |
| 269 | free_irq(dev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | ni_reset586(); /* the hard way to stop the receiver */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | /********************************************** |
| 276 | * open device |
| 277 | */ |
| 278 | static int ni52_open(struct net_device *dev) |
| 279 | { |
| 280 | int ret; |
| 281 | |
| 282 | ni_disint(); |
| 283 | alloc586(dev); |
| 284 | init586(dev); |
| 285 | startrecv586(dev); |
| 286 | ni_enaint(); |
| 287 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 288 | ret = request_irq(dev->irq, &ni52_interrupt, 0, dev->name, dev); |
| 289 | if (ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | ni_reset586(); |
| 291 | return ret; |
| 292 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | netif_start_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | return 0; /* most done by init */ |
| 295 | } |
| 296 | |
Al Viro | 76af569 | 2008-03-19 09:44:19 +0000 | [diff] [blame] | 297 | static int check_iscp(struct net_device *dev, void __iomem *addr) |
| 298 | { |
| 299 | struct iscp_struct __iomem *iscp = addr; |
| 300 | struct priv *p = dev->priv; |
| 301 | memset_io(iscp, 0, sizeof(struct iscp_struct)); |
| 302 | |
| 303 | writel(make24(iscp), &p->scp->iscp); |
| 304 | writeb(1, &iscp->busy); |
| 305 | |
| 306 | ni_reset586(); |
| 307 | ni_attn586(); |
| 308 | mdelay(32); /* wait a while... */ |
| 309 | /* i82586 clears 'busy' after successful init */ |
| 310 | if (readb(&iscp->busy)) |
| 311 | return 0; |
| 312 | return 1; |
| 313 | } |
| 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | /********************************************** |
| 316 | * Check to see if there's an 82586 out there. |
| 317 | */ |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 318 | static int check586(struct net_device *dev, unsigned size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
Al Viro | 7f8cfd5 | 2008-03-19 09:44:09 +0000 | [diff] [blame] | 320 | struct priv *p = dev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | int i; |
| 322 | |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 323 | p->mapped = ioremap(dev->mem_start, size); |
| 324 | if (!p->mapped) |
| 325 | return 0; |
| 326 | |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 327 | p->base = p->mapped + size - 0x01000000; |
| 328 | p->memtop = p->mapped + size; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 329 | p->scp = (struct scp_struct __iomem *)(p->base + SCP_DEFAULT_ADDRESS); |
Al Viro | 7f8cfd5 | 2008-03-19 09:44:09 +0000 | [diff] [blame] | 330 | p->scb = (struct scb_struct __iomem *) p->mapped; |
Al Viro | 76af569 | 2008-03-19 09:44:19 +0000 | [diff] [blame] | 331 | p->iscp = (struct iscp_struct __iomem *)p->scp - 1; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 332 | memset_io(p->scp, 0, sizeof(struct scp_struct)); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 333 | for (i = 0; i < sizeof(struct scp_struct); i++) |
| 334 | /* memory was writeable? */ |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 335 | if (readb((char __iomem *)p->scp + i)) |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 336 | goto Enodev; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 337 | writeb(SYSBUSVAL, &p->scp->sysbus); /* 1 = 8Bit-Bus, 0 = 16 Bit */ |
| 338 | if (readb(&p->scp->sysbus) != SYSBUSVAL) |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 339 | goto Enodev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Al Viro | 76af569 | 2008-03-19 09:44:19 +0000 | [diff] [blame] | 341 | if (!check_iscp(dev, p->mapped)) |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 342 | goto Enodev; |
Al Viro | 76af569 | 2008-03-19 09:44:19 +0000 | [diff] [blame] | 343 | if (!check_iscp(dev, p->iscp)) |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 344 | goto Enodev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | return 1; |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 346 | Enodev: |
| 347 | iounmap(p->mapped); |
| 348 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /****************************************************************** |
| 352 | * set iscp at the right place, called by ni52_probe1 and open586. |
| 353 | */ |
| 354 | static void alloc586(struct net_device *dev) |
| 355 | { |
| 356 | struct priv *p = (struct priv *) dev->priv; |
| 357 | |
| 358 | ni_reset586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 359 | mdelay(32); |
| 360 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 361 | memset_io(p->iscp, 0, sizeof(struct iscp_struct)); |
| 362 | memset_io(p->scp , 0, sizeof(struct scp_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 364 | writel(make24(p->iscp), &p->scp->iscp); |
| 365 | writeb(SYSBUSVAL, &p->scp->sysbus); |
| 366 | writew(make16(p->scb), &p->iscp->scb_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 368 | writeb(1, &p->iscp->busy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | ni_reset586(); |
| 370 | ni_attn586(); |
| 371 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 372 | mdelay(32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 374 | if (readb(&p->iscp->busy)) |
| 375 | printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 377 | p->reset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 379 | memset_io(p->scb, 0, sizeof(struct scb_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /* set: io,irq,memstart,memend or set it when calling insmod */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 383 | static int irq = 9; |
| 384 | static int io = 0x300; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | static long memstart; /* e.g 0xd0000 */ |
| 386 | static long memend; /* e.g 0xd4000 */ |
| 387 | |
| 388 | /********************************************** |
| 389 | * probe the ni5210-card |
| 390 | */ |
| 391 | struct net_device * __init ni52_probe(int unit) |
| 392 | { |
| 393 | struct net_device *dev = alloc_etherdev(sizeof(struct priv)); |
| 394 | static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0}; |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 395 | struct priv *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | int *port; |
| 397 | int err = 0; |
| 398 | |
| 399 | if (!dev) |
| 400 | return ERR_PTR(-ENOMEM); |
| 401 | |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 402 | p = dev->priv; |
| 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | if (unit >= 0) { |
| 405 | sprintf(dev->name, "eth%d", unit); |
| 406 | netdev_boot_setup_check(dev); |
| 407 | io = dev->base_addr; |
| 408 | irq = dev->irq; |
| 409 | memstart = dev->mem_start; |
| 410 | memend = dev->mem_end; |
| 411 | } |
| 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | if (io > 0x1ff) { /* Check a single specified location. */ |
| 414 | err = ni52_probe1(dev, io); |
| 415 | } else if (io > 0) { /* Don't probe at all. */ |
| 416 | err = -ENXIO; |
| 417 | } else { |
| 418 | for (port = ports; *port && ni52_probe1(dev, *port) ; port++) |
| 419 | ; |
| 420 | if (*port) |
| 421 | goto got_it; |
| 422 | #ifdef FULL_IO_PROBE |
| 423 | for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8) |
| 424 | ; |
| 425 | if (io < 0x400) |
| 426 | goto got_it; |
| 427 | #endif |
| 428 | err = -ENODEV; |
| 429 | } |
| 430 | if (err) |
| 431 | goto out; |
| 432 | got_it: |
| 433 | err = register_netdev(dev); |
| 434 | if (err) |
| 435 | goto out1; |
| 436 | return dev; |
| 437 | out1: |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 438 | iounmap(p->mapped); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | release_region(dev->base_addr, NI52_TOTAL_SIZE); |
| 440 | out: |
| 441 | free_netdev(dev); |
| 442 | return ERR_PTR(err); |
| 443 | } |
| 444 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 445 | static int __init ni52_probe1(struct net_device *dev, int ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
| 447 | int i, size, retval; |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 448 | struct priv *priv = dev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | dev->base_addr = ioaddr; |
| 451 | dev->irq = irq; |
| 452 | dev->mem_start = memstart; |
| 453 | dev->mem_end = memend; |
| 454 | |
Al Viro | 7f8cfd5 | 2008-03-19 09:44:09 +0000 | [diff] [blame] | 455 | spin_lock_init(&priv->spinlock); |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME)) |
| 458 | return -EBUSY; |
| 459 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 460 | if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) { |
| 462 | retval = -ENODEV; |
| 463 | goto out; |
| 464 | } |
| 465 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 466 | for (i = 0; i < ETH_ALEN; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | dev->dev_addr[i] = inb(dev->base_addr+i); |
| 468 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 469 | if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | || dev->dev_addr[2] != NI52_ADDR2) { |
| 471 | retval = -ENODEV; |
| 472 | goto out; |
| 473 | } |
| 474 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 475 | printk(KERN_INFO "%s: NI5210 found at %#3lx, ", |
| 476 | dev->name, dev->base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
| 478 | /* |
| 479 | * check (or search) IO-Memory, 8K and 16K |
| 480 | */ |
| 481 | #ifdef MODULE |
| 482 | size = dev->mem_end - dev->mem_start; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 483 | if (size != 0x2000 && size != 0x4000) { |
| 484 | printk("\n"); |
| 485 | printk(KERN_ERR "%s: Invalid memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n", dev->name, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | retval = -ENODEV; |
| 487 | goto out; |
| 488 | } |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 489 | if (!check586(dev, size)) { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 490 | printk(KERN_ERR "?memcheck, Can't find memory at 0x%lx with size %d!\n", dev->mem_start, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | retval = -ENODEV; |
| 492 | goto out; |
| 493 | } |
| 494 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 495 | if (dev->mem_start != 0) { |
| 496 | /* no auto-mem-probe */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | size = 0x4000; /* check for 16K mem */ |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 498 | if (!check586(dev, size)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | size = 0x2000; /* check for 8K mem */ |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 500 | if (!check586(dev, size)) { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 501 | printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | retval = -ENODEV; |
| 503 | goto out; |
| 504 | } |
| 505 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 506 | } else { |
| 507 | static const unsigned long memaddrs[] = { |
| 508 | 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000, |
| 509 | 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0 |
| 510 | }; |
| 511 | for (i = 0;; i++) { |
| 512 | if (!memaddrs[i]) { |
| 513 | printk(KERN_ERR "?memprobe, Can't find io-memory!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | retval = -ENODEV; |
| 515 | goto out; |
| 516 | } |
| 517 | dev->mem_start = memaddrs[i]; |
| 518 | size = 0x2000; /* check for 8K mem */ |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 519 | if (check586(dev, size)) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 520 | /* 8K-check */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | break; |
| 522 | size = 0x4000; /* check for 16K mem */ |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 523 | if (check586(dev, size)) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 524 | /* 16K-check */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | break; |
| 526 | } |
| 527 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 528 | /* set mem_end showed by 'ifconfig' */ |
| 529 | dev->mem_end = dev->mem_start + size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | #endif |
| 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | alloc586(dev); |
| 533 | |
| 534 | /* set number of receive-buffs according to memsize */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 535 | if (size == 0x2000) |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 536 | priv->num_recv_buffs = NUM_RECV_BUFFS_8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | else |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 538 | priv->num_recv_buffs = NUM_RECV_BUFFS_16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 540 | printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ", |
| 541 | dev->mem_start, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 543 | if (dev->irq < 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | unsigned long irq_mask; |
| 545 | |
| 546 | irq_mask = probe_irq_on(); |
| 547 | ni_reset586(); |
| 548 | ni_attn586(); |
| 549 | |
| 550 | mdelay(20); |
| 551 | dev->irq = probe_irq_off(irq_mask); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 552 | if (!dev->irq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | printk("?autoirq, Failed to detect IRQ line!\n"); |
| 554 | retval = -EAGAIN; |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 555 | iounmap(priv->mapped); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | goto out; |
| 557 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 558 | printk("IRQ %d (autodetected).\n", dev->irq); |
| 559 | } else { |
| 560 | if (dev->irq == 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | dev->irq = 9; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 562 | printk("IRQ %d (assigned and not checked!).\n", dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | dev->open = ni52_open; |
| 566 | dev->stop = ni52_close; |
| 567 | dev->get_stats = ni52_get_stats; |
| 568 | dev->tx_timeout = ni52_timeout; |
| 569 | dev->watchdog_timeo = HZ/20; |
| 570 | dev->hard_start_xmit = ni52_send_packet; |
| 571 | dev->set_multicast_list = set_multicast_list; |
| 572 | |
| 573 | dev->if_port = 0; |
| 574 | |
| 575 | return 0; |
| 576 | out: |
| 577 | release_region(ioaddr, NI52_TOTAL_SIZE); |
| 578 | return retval; |
| 579 | } |
| 580 | |
| 581 | /********************************************** |
| 582 | * init the chip (ni52-interrupt should be disabled?!) |
| 583 | * needs a correct 'allocated' memory |
| 584 | */ |
| 585 | |
| 586 | static int init586(struct net_device *dev) |
| 587 | { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 588 | void __iomem *ptr; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 589 | int i, result = 0; |
| 590 | struct priv *p = (struct priv *)dev->priv; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 591 | struct configure_cmd_struct __iomem *cfg_cmd; |
| 592 | struct iasetup_cmd_struct __iomem *ias_cmd; |
| 593 | struct tdr_cmd_struct __iomem *tdr_cmd; |
| 594 | struct mcsetup_cmd_struct __iomem *mc_cmd; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 595 | struct dev_mc_list *dmi = dev->mc_list; |
| 596 | int num_addrs = dev->mc_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 598 | ptr = p->scb + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 600 | cfg_cmd = ptr; /* configure-command */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 601 | writew(0, &cfg_cmd->cmd_status); |
| 602 | writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd); |
| 603 | writew(0xFFFF, &cfg_cmd->cmd_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 605 | /* number of cfg bytes */ |
| 606 | writeb(0x0a, &cfg_cmd->byte_cnt); |
| 607 | /* fifo-limit (8=tx:32/rx:64) */ |
| 608 | writeb(fifo, &cfg_cmd->fifo); |
| 609 | /* hold or discard bad recv frames (bit 7) */ |
| 610 | writeb(0x40, &cfg_cmd->sav_bf); |
| 611 | /* addr_len |!src_insert |pre-len |loopback */ |
| 612 | writeb(0x2e, &cfg_cmd->adr_len); |
| 613 | writeb(0x00, &cfg_cmd->priority); |
| 614 | writeb(0x60, &cfg_cmd->ifs);; |
| 615 | writeb(0x00, &cfg_cmd->time_low); |
| 616 | writeb(0xf2, &cfg_cmd->time_high); |
| 617 | writeb(0x00, &cfg_cmd->promisc);; |
| 618 | if (dev->flags & IFF_ALLMULTI) { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 619 | int len = ((char __iomem *)p->iscp - (char __iomem *)ptr - 8) / 6; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 620 | if (num_addrs > len) { |
| 621 | printk(KERN_ERR "%s: switching to promisc. mode\n", |
| 622 | dev->name); |
| 623 | dev->flags |= IFF_PROMISC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
| 625 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 626 | if (dev->flags & IFF_PROMISC) |
| 627 | writeb(0x01, &cfg_cmd->promisc); |
| 628 | writeb(0x00, &cfg_cmd->carr_coll); |
| 629 | writew(make16(cfg_cmd), &p->scb->cbl_offset); |
| 630 | writew(0, &p->scb->cmd_ruc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 632 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | ni_attn586(); |
| 634 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 635 | wait_for_stat_compl(cfg_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 637 | if ((readw(&cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != |
| 638 | (STAT_COMPL|STAT_OK)) { |
| 639 | printk(KERN_ERR "%s: configure command failed: %x\n", |
| 640 | dev->name, readw(&cfg_cmd->cmd_status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | return 1; |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | * individual address setup |
| 646 | */ |
| 647 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 648 | ias_cmd = ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 650 | writew(0, &ias_cmd->cmd_status); |
| 651 | writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd); |
| 652 | writew(0xffff, &ias_cmd->cmd_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 654 | memcpy_toio(&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 656 | writew(make16(ias_cmd), &p->scb->cbl_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 658 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | ni_attn586(); |
| 660 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 661 | wait_for_stat_compl(ias_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 663 | if ((readw(&ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != |
| 664 | (STAT_OK|STAT_COMPL)) { |
| 665 | printk(KERN_ERR "%s (ni52): individual address setup command failed: %04x\n", dev->name, readw(&ias_cmd->cmd_status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | return 1; |
| 667 | } |
| 668 | |
| 669 | /* |
| 670 | * TDR, wire check .. e.g. no resistor e.t.c |
| 671 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 672 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 673 | tdr_cmd = ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 675 | writew(0, &tdr_cmd->cmd_status); |
| 676 | writew(CMD_TDR | CMD_LAST, &tdr_cmd->cmd_cmd); |
| 677 | writew(0xffff, &tdr_cmd->cmd_link); |
| 678 | writew(0, &tdr_cmd->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 680 | writew(make16(tdr_cmd), &p->scb->cbl_offset); |
| 681 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | ni_attn586(); |
| 683 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 684 | wait_for_stat_compl(tdr_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 686 | if (!(readw(&tdr_cmd->cmd_status) & STAT_COMPL)) |
| 687 | printk(KERN_ERR "%s: Problems while running the TDR.\n", |
| 688 | dev->name); |
| 689 | else { |
| 690 | udelay(16); |
| 691 | result = readw(&tdr_cmd->status); |
| 692 | writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | ni_attn586(); /* ack the interrupts */ |
| 694 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 695 | if (result & TDR_LNK_OK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | ; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 697 | else if (result & TDR_XCVR_PRB) |
| 698 | printk(KERN_ERR "%s: TDR: Transceiver problem. Check the cable(s)!\n", |
| 699 | dev->name); |
| 700 | else if (result & TDR_ET_OPN) |
| 701 | printk(KERN_ERR "%s: TDR: No correct termination %d clocks away.\n", |
| 702 | dev->name, result & TDR_TIMEMASK); |
| 703 | else if (result & TDR_ET_SRT) { |
| 704 | /* time == 0 -> strange :-) */ |
| 705 | if (result & TDR_TIMEMASK) |
| 706 | printk(KERN_ERR "%s: TDR: Detected a short circuit %d clocks away.\n", |
| 707 | dev->name, result & TDR_TIMEMASK); |
| 708 | } else |
| 709 | printk(KERN_ERR "%s: TDR: Unknown status %04x\n", |
| 710 | dev->name, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /* |
| 714 | * Multicast setup |
| 715 | */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 716 | if (num_addrs && !(dev->flags & IFF_PROMISC)) { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 717 | mc_cmd = ptr; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 718 | writew(0, &mc_cmd->cmd_status); |
| 719 | writew(CMD_MCSETUP | CMD_LAST, &mc_cmd->cmd_cmd); |
| 720 | writew(0xffff, &mc_cmd->cmd_link); |
| 721 | writew(num_addrs * 6, &mc_cmd->mc_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 723 | for (i = 0; i < num_addrs; i++, dmi = dmi->next) |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 724 | memcpy_toio(mc_cmd->mc_list[i], |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 725 | dmi->dmi_addr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 727 | writew(make16(mc_cmd), &p->scb->cbl_offset); |
| 728 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | ni_attn586(); |
| 730 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 731 | wait_for_stat_compl(mc_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 733 | if ((readw(&mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK)) |
| 734 | != (STAT_COMPL|STAT_OK)) |
| 735 | printk(KERN_ERR "%s: Can't apply multicast-address-list.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /* |
| 739 | * alloc nop/xmit-cmds |
| 740 | */ |
| 741 | #if (NUM_XMIT_BUFFS == 1) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 742 | for (i = 0; i < 2; i++) { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 743 | p->nop_cmds[i] = ptr; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 744 | writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd); |
| 745 | writew(0, &p->nop_cmds[i]->cmd_status); |
| 746 | writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link); |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 747 | ptr = ptr + sizeof(struct nop_cmd_struct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
| 749 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 750 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 751 | p->nop_cmds[i] = ptr; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 752 | writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd); |
| 753 | writew(0, &p->nop_cmds[i]->cmd_status); |
| 754 | writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link); |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 755 | ptr = ptr + sizeof(struct nop_cmd_struct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | #endif |
| 758 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 759 | ptr = alloc_rfa(dev, ptr); /* init receive-frame-area */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
| 761 | /* |
| 762 | * alloc xmit-buffs / init xmit_cmds |
| 763 | */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 764 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { |
| 765 | /* Transmit cmd/buff 0 */ |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 766 | p->xmit_cmds[i] = ptr; |
| 767 | ptr = ptr + sizeof(struct transmit_cmd_struct); |
| 768 | p->xmit_cbuffs[i] = ptr; /* char-buffs */ |
| 769 | ptr = ptr + XMIT_BUFF_SIZE; |
| 770 | p->xmit_buffs[i] = ptr; /* TBD */ |
| 771 | ptr = ptr + sizeof(struct tbd_struct); |
| 772 | if ((void __iomem *)ptr > (void __iomem *)p->iscp) { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 773 | printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n", |
| 774 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | return 1; |
| 776 | } |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 777 | memset_io(p->xmit_cmds[i], 0, |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 778 | sizeof(struct transmit_cmd_struct)); |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 779 | memset_io(p->xmit_buffs[i], 0, |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 780 | sizeof(struct tbd_struct)); |
| 781 | writew(make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]), |
| 782 | &p->xmit_cmds[i]->cmd_link); |
| 783 | writew(STAT_COMPL, &p->xmit_cmds[i]->cmd_status); |
| 784 | writew(CMD_XMIT|CMD_INT, &p->xmit_cmds[i]->cmd_cmd); |
| 785 | writew(make16(p->xmit_buffs[i]), &p->xmit_cmds[i]->tbd_offset); |
| 786 | writew(0xffff, &p->xmit_buffs[i]->next); |
| 787 | writel(make24(p->xmit_cbuffs[i]), &p->xmit_buffs[i]->buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | p->xmit_count = 0; |
| 791 | p->xmit_last = 0; |
| 792 | #ifndef NO_NOPCOMMANDS |
| 793 | p->nop_point = 0; |
| 794 | #endif |
| 795 | |
| 796 | /* |
| 797 | * 'start transmitter' |
| 798 | */ |
| 799 | #ifndef NO_NOPCOMMANDS |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 800 | writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset); |
| 801 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 803 | wait_for_scb_cmd(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 805 | writew(make16(p->xmit_cmds[0]), &p->xmit_cmds[0]->cmd_link); |
| 806 | writew(CMD_XMIT | CMD_SUSPEND | CMD_INT, &p->xmit_cmds[0]->cmd_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | #endif |
| 808 | |
| 809 | /* |
| 810 | * ack. interrupts |
| 811 | */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 812 | writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 814 | udelay(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
| 816 | ni_enaint(); |
| 817 | |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | /****************************************************** |
| 822 | * This is a helper routine for ni52_rnr_int() and init586(). |
| 823 | * It sets up the Receive Frame Area (RFA). |
| 824 | */ |
| 825 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 826 | static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 828 | struct rfd_struct __iomem *rfd = ptr; |
| 829 | struct rbd_struct __iomem *rbd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | int i; |
| 831 | struct priv *p = (struct priv *) dev->priv; |
| 832 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 833 | memset_io(rfd, 0, |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 834 | sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | p->rfd_first = rfd; |
| 836 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 837 | for (i = 0; i < (p->num_recv_buffs + rfdadd); i++) { |
| 838 | writew(make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd)), |
| 839 | &rfd[i].next); |
| 840 | writew(0xffff, &rfd[i].rbd_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 842 | /* RU suspend */ |
| 843 | writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 845 | ptr = rfd + (p->num_recv_buffs + rfdadd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 847 | rbd = ptr; |
| 848 | ptr = rbd + p->num_recv_buffs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | /* clr descriptors */ |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 851 | memset_io(rbd, 0, sizeof(struct rbd_struct) * (p->num_recv_buffs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 853 | for (i = 0; i < p->num_recv_buffs; i++) { |
| 854 | writew(make16(rbd + (i+1) % p->num_recv_buffs), &rbd[i].next); |
| 855 | writew(RECV_BUFF_SIZE, &rbd[i].size); |
| 856 | writel(make24(ptr), &rbd[i].buffer); |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 857 | ptr = ptr + RECV_BUFF_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | p->rfd_top = p->rfd_first; |
| 860 | p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd); |
| 861 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 862 | writew(make16(p->rfd_first), &p->scb->rfa_offset); |
| 863 | writew(make16(rbd), &p->rfd_first->rbd_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | |
| 865 | return ptr; |
| 866 | } |
| 867 | |
| 868 | |
| 869 | /************************************************** |
| 870 | * Interrupt Handler ... |
| 871 | */ |
| 872 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 873 | static irqreturn_t ni52_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | { |
| 875 | struct net_device *dev = dev_id; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 876 | unsigned int stat; |
| 877 | int cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | struct priv *p; |
| 879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | p = (struct priv *) dev->priv; |
| 881 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 882 | if (debuglevel > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | printk("I"); |
| 884 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 885 | spin_lock(&p->spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 887 | wait_for_scb_cmd(dev); /* wait for last command */ |
| 888 | |
| 889 | while ((stat = readb(&p->scb->cus) & STAT_MASK)) { |
| 890 | writeb(stat, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | ni_attn586(); |
| 892 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 893 | if (stat & STAT_FR) /* received a frame */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | ni52_rcv_int(dev); |
| 895 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 896 | if (stat & STAT_RNR) { /* RU went 'not ready' */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | printk("(R)"); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 898 | if (readb(&p->scb->rus) & RU_SUSPEND) { |
| 899 | /* special case: RU_SUSPEND */ |
| 900 | wait_for_scb_cmd(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | p->scb->cmd_ruc = RUC_RESUME; |
| 902 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 903 | wait_for_scb_cmd_ruc(dev); |
| 904 | } else { |
| 905 | printk(KERN_ERR "%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n", |
| 906 | dev->name, stat, readb(&p->scb->rus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | ni52_rnr_int(dev); |
| 908 | } |
| 909 | } |
| 910 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 911 | /* Command with I-bit set complete */ |
| 912 | if (stat & STAT_CX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | ni52_xmt_int(dev); |
| 914 | |
| 915 | #ifndef NO_NOPCOMMANDS |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 916 | if (stat & STAT_CNA) { /* CU went 'not ready' */ |
| 917 | if (netif_running(dev)) |
| 918 | printk(KERN_ERR "%s: oops! CU has left active state. stat: %04x/%02x.\n", |
| 919 | dev->name, stat, readb(&p->scb->cus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | #endif |
| 922 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 923 | if (debuglevel > 1) |
| 924 | printk("%d", cnt++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 926 | /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */ |
| 927 | wait_for_scb_cmd(dev); |
| 928 | if (p->scb->cmd_cuc) { /* timed out? */ |
| 929 | printk(KERN_ERR "%s: Acknowledge timed out.\n", |
| 930 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | ni_disint(); |
| 932 | break; |
| 933 | } |
| 934 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 935 | spin_unlock(&p->spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 937 | if (debuglevel > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | printk("i"); |
| 939 | return IRQ_HANDLED; |
| 940 | } |
| 941 | |
| 942 | /******************************************************* |
| 943 | * receive-interrupt |
| 944 | */ |
| 945 | |
| 946 | static void ni52_rcv_int(struct net_device *dev) |
| 947 | { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 948 | int status, cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | unsigned short totlen; |
| 950 | struct sk_buff *skb; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 951 | struct rbd_struct __iomem *rbd; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 952 | struct priv *p = (struct priv *)dev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 954 | if (debuglevel > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | printk("R"); |
| 956 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 957 | for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 958 | rbd = (struct rbd_struct __iomem *) make32(p->rfd_top->rbd_offset); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 959 | if (status & RFD_OK) { /* frame received without error? */ |
| 960 | totlen = readw(&rbd->status); |
| 961 | if (totlen & RBD_LAST) { |
| 962 | /* the first and the last buffer? */ |
| 963 | totlen &= RBD_MASK; /* length of this frame */ |
| 964 | writew(0x00, &rbd->status); |
| 965 | skb = (struct sk_buff *)dev_alloc_skb(totlen+2); |
| 966 | if (skb != NULL) { |
| 967 | skb_reserve(skb, 2); |
| 968 | skb_put(skb, totlen); |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 969 | skb_copy_to_linear_data(skb, p->base + (unsigned long) rbd->buffer, totlen); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 970 | skb->protocol = eth_type_trans(skb, dev); |
| 971 | netif_rx(skb); |
| 972 | dev->last_rx = jiffies; |
| 973 | p->stats.rx_packets++; |
| 974 | p->stats.rx_bytes += totlen; |
| 975 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | p->stats.rx_dropped++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 977 | } else { |
| 978 | int rstat; |
| 979 | /* free all RBD's until RBD_LAST is set */ |
| 980 | totlen = 0; |
| 981 | while (!((rstat = readw(&rbd->status)) & RBD_LAST)) { |
| 982 | totlen += rstat & RBD_MASK; |
| 983 | if (!rstat) { |
| 984 | printk(KERN_ERR "%s: Whoops .. no end mark in RBD list\n", dev->name); |
| 985 | break; |
| 986 | } |
| 987 | writew(0, &rbd->status); |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 988 | rbd = (struct rbd_struct __iomem *) make32(readl(&rbd->next)); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 989 | } |
| 990 | totlen += rstat & RBD_MASK; |
| 991 | writew(0, &rbd->status); |
| 992 | printk(KERN_ERR "%s: received oversized frame! length: %d\n", |
| 993 | dev->name, totlen); |
| 994 | p->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 996 | } else {/* frame !(ok), only with 'save-bad-frames' */ |
| 997 | printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n", |
| 998 | dev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | p->stats.rx_errors++; |
| 1000 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1001 | writeb(0, &p->rfd_top->stat_high); |
| 1002 | writeb(RFD_SUSP, &p->rfd_top->last); /* maybe exchange by RFD_LAST */ |
| 1003 | writew(0xffff, &p->rfd_top->rbd_offset); |
| 1004 | writeb(0, &p->rfd_last->last); /* delete RFD_SUSP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | p->rfd_last = p->rfd_top; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 1006 | p->rfd_top = (struct rfd_struct __iomem *) make32(p->rfd_top->next); /* step to next RFD */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1007 | writew(make16(p->rfd_top), &p->scb->rfa_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1009 | if (debuglevel > 0) |
| 1010 | printk("%d", cnt++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1013 | if (automatic_resume) { |
| 1014 | wait_for_scb_cmd(dev); |
| 1015 | writeb(RUC_RESUME, &p->scb->cmd_ruc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1017 | wait_for_scb_cmd_ruc(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | #ifdef WAIT_4_BUSY |
| 1021 | { |
| 1022 | int i; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1023 | for (i = 0; i < 1024; i++) { |
| 1024 | if (p->rfd_top->status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | break; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1026 | udelay(16); |
| 1027 | if (i == 1023) |
| 1028 | printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | #endif |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1032 | if (debuglevel > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | printk("r"); |
| 1034 | } |
| 1035 | |
| 1036 | /********************************************************** |
| 1037 | * handle 'Receiver went not ready'. |
| 1038 | */ |
| 1039 | |
| 1040 | static void ni52_rnr_int(struct net_device *dev) |
| 1041 | { |
| 1042 | struct priv *p = (struct priv *) dev->priv; |
| 1043 | |
| 1044 | p->stats.rx_errors++; |
| 1045 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1046 | wait_for_scb_cmd(dev); /* wait for the last cmd, WAIT_4_FULLSTAT?? */ |
| 1047 | writeb(RUC_ABORT, &p->scb->cmd_ruc); /* usually the RU is in the 'no resource'-state .. abort it now. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1049 | wait_for_scb_cmd_ruc(dev); /* wait for accept cmd. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 1051 | alloc_rfa(dev, p->rfd_first); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1052 | /* maybe add a check here, before restarting the RU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | startrecv586(dev); /* restart RU */ |
| 1054 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1055 | printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->rus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | |
| 1057 | } |
| 1058 | |
| 1059 | /********************************************************** |
| 1060 | * handle xmit - interrupt |
| 1061 | */ |
| 1062 | |
| 1063 | static void ni52_xmt_int(struct net_device *dev) |
| 1064 | { |
| 1065 | int status; |
| 1066 | struct priv *p = (struct priv *) dev->priv; |
| 1067 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1068 | if (debuglevel > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | printk("X"); |
| 1070 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1071 | status = readw(&p->xmit_cmds[p->xmit_last]->cmd_status); |
| 1072 | if (!(status & STAT_COMPL)) |
| 1073 | printk(KERN_ERR "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1075 | if (status & STAT_OK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | p->stats.tx_packets++; |
| 1077 | p->stats.collisions += (status & TCMD_MAXCOLLMASK); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1078 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | p->stats.tx_errors++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1080 | if (status & TCMD_LATECOLL) { |
| 1081 | printk(KERN_ERR "%s: late collision detected.\n", |
| 1082 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | p->stats.collisions++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1084 | } else if (status & TCMD_NOCARRIER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | p->stats.tx_carrier_errors++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1086 | printk(KERN_ERR "%s: no carrier detected.\n", |
| 1087 | dev->name); |
| 1088 | } else if (status & TCMD_LOSTCTS) |
| 1089 | printk(KERN_ERR "%s: loss of CTS detected.\n", |
| 1090 | dev->name); |
| 1091 | else if (status & TCMD_UNDERRUN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | p->stats.tx_fifo_errors++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1093 | printk(KERN_ERR "%s: DMA underrun detected.\n", |
| 1094 | dev->name); |
| 1095 | } else if (status & TCMD_MAXCOLL) { |
| 1096 | printk(KERN_ERR "%s: Max. collisions exceeded.\n", |
| 1097 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | p->stats.collisions += 16; |
| 1099 | } |
| 1100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | #if (NUM_XMIT_BUFFS > 1) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1102 | if ((++p->xmit_last) == NUM_XMIT_BUFFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | p->xmit_last = 0; |
| 1104 | #endif |
| 1105 | netif_wake_queue(dev); |
| 1106 | } |
| 1107 | |
| 1108 | /*********************************************************** |
| 1109 | * (re)start the receiver |
| 1110 | */ |
| 1111 | |
| 1112 | static void startrecv586(struct net_device *dev) |
| 1113 | { |
| 1114 | struct priv *p = (struct priv *) dev->priv; |
| 1115 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1116 | wait_for_scb_cmd(dev); |
| 1117 | wait_for_scb_cmd_ruc(dev); |
| 1118 | writew(make16(p->rfd_first), &p->scb->rfa_offset); |
| 1119 | writeb(RUC_START, &p->scb->cmd_ruc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | ni_attn586(); /* start cmd. */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1121 | wait_for_scb_cmd_ruc(dev); |
| 1122 | /* wait for accept cmd. (no timeout!!) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | static void ni52_timeout(struct net_device *dev) |
| 1126 | { |
| 1127 | struct priv *p = (struct priv *) dev->priv; |
| 1128 | #ifndef NO_NOPCOMMANDS |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1129 | if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | netif_wake_queue(dev); |
| 1131 | #ifdef DEBUG |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1132 | printk(KERN_ERR "%s: strange ... timeout with CU active?!?\n", |
| 1133 | dev->name); |
| 1134 | printk(KERN_ERR "%s: X0: %04x N0: %04x N1: %04x %d\n", |
| 1135 | dev->name, (int)p->xmit_cmds[0]->cmd_status, |
| 1136 | readw(&p->nop_cmds[0]->cmd_status), |
| 1137 | readw(&p->nop_cmds[1]->cmd_status), |
| 1138 | p->nop_point); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | #endif |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1140 | writeb(CUC_ABORT, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1142 | wait_for_scb_cmd(dev); |
| 1143 | writew(make16(p->nop_cmds[p->nop_point]), &p->scb->cbl_offset); |
| 1144 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1146 | wait_for_scb_cmd(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | dev->trans_start = jiffies; |
| 1148 | return 0; |
| 1149 | } |
| 1150 | #endif |
| 1151 | { |
| 1152 | #ifdef DEBUG |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1153 | printk(KERN_ERR "%s: xmitter timed out, try to restart! stat: %02x\n", |
| 1154 | dev->name, readb(&p->scb->cus)); |
| 1155 | printk(KERN_ERR "%s: command-stats: %04x %04x\n", |
| 1156 | dev->name, |
| 1157 | readw(&p->xmit_cmds[0]->cmd_status), |
| 1158 | readw(&p->xmit_cmds[1]->cmd_status)); |
| 1159 | printk(KERN_ERR "%s: check, whether you set the right interrupt number!\n", |
| 1160 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | #endif |
| 1162 | ni52_close(dev); |
| 1163 | ni52_open(dev); |
| 1164 | } |
| 1165 | dev->trans_start = jiffies; |
| 1166 | } |
| 1167 | |
| 1168 | /****************************************************** |
| 1169 | * send frame |
| 1170 | */ |
| 1171 | |
| 1172 | static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev) |
| 1173 | { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1174 | int len, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | #ifndef NO_NOPCOMMANDS |
| 1176 | int next_nop; |
| 1177 | #endif |
| 1178 | struct priv *p = (struct priv *) dev->priv; |
| 1179 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1180 | if (skb->len > XMIT_BUFF_SIZE) { |
| 1181 | printk(KERN_ERR "%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n", dev->name, XMIT_BUFF_SIZE, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | netif_stop_queue(dev); |
| 1186 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1187 | skb_copy_from_linear_data(skb, (char *)p->xmit_cbuffs[p->xmit_count], |
| 1188 | skb->len); |
| 1189 | len = skb->len; |
| 1190 | if (len < ETH_ZLEN) { |
| 1191 | len = ETH_ZLEN; |
| 1192 | memset((char *)p->xmit_cbuffs[p->xmit_count]+skb->len, 0, |
| 1193 | len - skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
| 1196 | #if (NUM_XMIT_BUFFS == 1) |
| 1197 | # ifdef NO_NOPCOMMANDS |
| 1198 | |
| 1199 | #ifdef DEBUG |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1200 | if (p->scb->cus & CU_ACTIVE) { |
| 1201 | printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name); |
| 1202 | printk(KERN_ERR "%s: stat: %04x %04x\n", |
| 1203 | dev->name, readb(&p->scb->cus), |
| 1204 | readw(&p->xmit_cmds[0]->cmd_status)); |
| 1205 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | #endif |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1207 | writew(TBD_LAST | len, &p->xmit_buffs[0]->size);; |
| 1208 | for (i = 0; i < 16; i++) { |
| 1209 | writew(0, &p->xmit_cmds[0]->cmd_status); |
| 1210 | wait_for_scb_cmd(dev); |
| 1211 | if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND) |
| 1212 | writeb(CUC_RESUME, &p->scb->cmd_cuc); |
| 1213 | else { |
| 1214 | writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset); |
| 1215 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1217 | ni_attn586(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | dev->trans_start = jiffies; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1219 | if (!i) |
| 1220 | dev_kfree_skb(skb); |
| 1221 | wait_for_scb_cmd(dev); |
| 1222 | /* test it, because CU sometimes doesn't start immediately */ |
| 1223 | if (readb(&p->scb->cus) & CU_ACTIVE) |
| 1224 | break; |
| 1225 | if (readw(&p->xmit_cmds[0]->cmd_status)) |
| 1226 | break; |
| 1227 | if (i == 15) |
| 1228 | printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name); |
| 1229 | } |
| 1230 | # else |
| 1231 | next_nop = (p->nop_point + 1) & 0x1; |
| 1232 | writew(TBD_LAST | len, &p->xmit_buffs[0]->size); |
| 1233 | writew(make16(p->nop_cmds[next_nop]), &p->xmit_cmds[0]->cmd_link); |
| 1234 | writew(make16(p->nop_cmds[next_nop]), |
| 1235 | &p->nop_cmds[next_nop]->cmd_link); |
| 1236 | writew(0, &p->xmit_cmds[0]->cmd_status); |
| 1237 | writew(0, &p->nop_cmds[next_nop]->cmd_status); |
| 1238 | |
| 1239 | writew(make16(p->xmit_cmds[0]), &p->nop_cmds[p->nop_point]->cmd_link); |
| 1240 | dev->trans_start = jiffies; |
| 1241 | p->nop_point = next_nop; |
| 1242 | dev_kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | # endif |
| 1244 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1245 | writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size); |
| 1246 | next_nop = p->xmit_count + 1 |
| 1247 | if (next_nop == NUM_XMIT_BUFFS) |
| 1248 | next_nop = 0; |
| 1249 | writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status); |
| 1250 | /* linkpointer of xmit-command already points to next nop cmd */ |
| 1251 | writew(make16(p->nop_cmds[next_nop]), |
| 1252 | &p->nop_cmds[next_nop]->cmd_link); |
| 1253 | writew(0, &p->nop_cmds[next_nop]->cmd_status); |
| 1254 | writew(make16(p->xmit_cmds[p->xmit_count]), |
| 1255 | &p->nop_cmds[p->xmit_count]->cmd_link); |
| 1256 | dev->trans_start = jiffies; |
| 1257 | p->xmit_count = next_nop; |
| 1258 | { |
| 1259 | unsigned long flags; |
| 1260 | spin_lock_irqsave(&p->spinlock); |
| 1261 | if (p->xmit_count != p->xmit_last) |
| 1262 | netif_wake_queue(dev); |
| 1263 | spin_unlock_irqrestore(&p->spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1265 | dev_kfree_skb(skb); |
| 1266 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | return 0; |
| 1268 | } |
| 1269 | |
| 1270 | /******************************************* |
| 1271 | * Someone wanna have the statistics |
| 1272 | */ |
| 1273 | |
| 1274 | static struct net_device_stats *ni52_get_stats(struct net_device *dev) |
| 1275 | { |
| 1276 | struct priv *p = (struct priv *) dev->priv; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1277 | unsigned short crc, aln, rsc, ovrn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1279 | /* Get error-statistics from the ni82586 */ |
| 1280 | crc = readw(&p->scb->crc_errs); |
| 1281 | writew(0, &p->scb->crc_errs); |
| 1282 | aln = readw(&p->scb->aln_errs); |
| 1283 | writew(0, &p->scb->aln_errs); |
| 1284 | rsc = readw(&p->scb->rsc_errs); |
| 1285 | writew(0, &p->scb->rsc_errs); |
| 1286 | ovrn = readw(&p->scb->ovrn_errs); |
| 1287 | writew(0, &p->scb->ovrn_errs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | |
| 1289 | p->stats.rx_crc_errors += crc; |
| 1290 | p->stats.rx_fifo_errors += ovrn; |
| 1291 | p->stats.rx_frame_errors += aln; |
| 1292 | p->stats.rx_dropped += rsc; |
| 1293 | |
| 1294 | return &p->stats; |
| 1295 | } |
| 1296 | |
| 1297 | /******************************************************** |
| 1298 | * Set MC list .. |
| 1299 | */ |
| 1300 | |
| 1301 | static void set_multicast_list(struct net_device *dev) |
| 1302 | { |
| 1303 | netif_stop_queue(dev); |
| 1304 | ni_disint(); |
| 1305 | alloc586(dev); |
| 1306 | init586(dev); |
| 1307 | startrecv586(dev); |
| 1308 | ni_enaint(); |
| 1309 | netif_wake_queue(dev); |
| 1310 | } |
| 1311 | |
| 1312 | #ifdef MODULE |
| 1313 | static struct net_device *dev_ni52; |
| 1314 | |
| 1315 | module_param(io, int, 0); |
| 1316 | module_param(irq, int, 0); |
| 1317 | module_param(memstart, long, 0); |
| 1318 | module_param(memend, long, 0); |
| 1319 | MODULE_PARM_DESC(io, "NI5210 I/O base address,required"); |
| 1320 | MODULE_PARM_DESC(irq, "NI5210 IRQ number,required"); |
| 1321 | MODULE_PARM_DESC(memstart, "NI5210 memory base address,required"); |
| 1322 | MODULE_PARM_DESC(memend, "NI5210 memory end address,required"); |
| 1323 | |
Andrew Morton | 19a8664 | 2006-08-14 23:00:05 -0700 | [diff] [blame] | 1324 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1326 | if (io <= 0x0 || !memend || !memstart || irq < 2) { |
| 1327 | printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n"); |
| 1328 | printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | return -ENODEV; |
| 1330 | } |
| 1331 | dev_ni52 = ni52_probe(-1); |
| 1332 | if (IS_ERR(dev_ni52)) |
| 1333 | return PTR_ERR(dev_ni52); |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 1337 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | { |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 1339 | struct priv *p = dev_ni52->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | unregister_netdev(dev_ni52); |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame^] | 1341 | iounmap(p->mapped); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE); |
| 1343 | free_netdev(dev_ni52); |
| 1344 | } |
| 1345 | #endif /* MODULE */ |
| 1346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | MODULE_LICENSE("GPL"); |
| 1348 | |
| 1349 | /* |
| 1350 | * END: linux/drivers/net/ni52.c |
| 1351 | */ |