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 | |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 137 | #define make32(ptr16) ((void __iomem *)(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", |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 244 | dev->name, readb(&p->scb->cmd_ruc), |
| 245 | readb(&p->scb->rus)); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 246 | if (!p->reset) { |
| 247 | p->reset = 1; |
| 248 | ni_reset586(); |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 254 | static void wait_for_stat_compl(void __iomem *p) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 255 | { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 256 | struct nop_cmd_struct __iomem *addr = p; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 257 | int i; |
| 258 | for (i = 0; i < 32767; i++) { |
| 259 | if (readw(&((addr)->cmd_status)) & STAT_COMPL) |
| 260 | break; |
| 261 | udelay(32); |
| 262 | } |
| 263 | } |
| 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | /********************************************** |
| 266 | * close device |
| 267 | */ |
| 268 | static int ni52_close(struct net_device *dev) |
| 269 | { |
| 270 | free_irq(dev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | ni_reset586(); /* the hard way to stop the receiver */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | /********************************************** |
| 277 | * open device |
| 278 | */ |
| 279 | static int ni52_open(struct net_device *dev) |
| 280 | { |
| 281 | int ret; |
| 282 | |
| 283 | ni_disint(); |
| 284 | alloc586(dev); |
| 285 | init586(dev); |
| 286 | startrecv586(dev); |
| 287 | ni_enaint(); |
| 288 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 289 | ret = request_irq(dev->irq, &ni52_interrupt, 0, dev->name, dev); |
| 290 | if (ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | ni_reset586(); |
| 292 | return ret; |
| 293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | netif_start_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | return 0; /* most done by init */ |
| 296 | } |
| 297 | |
Al Viro | 76af569 | 2008-03-19 09:44:19 +0000 | [diff] [blame] | 298 | static int check_iscp(struct net_device *dev, void __iomem *addr) |
| 299 | { |
| 300 | struct iscp_struct __iomem *iscp = addr; |
| 301 | struct priv *p = dev->priv; |
| 302 | memset_io(iscp, 0, sizeof(struct iscp_struct)); |
| 303 | |
| 304 | writel(make24(iscp), &p->scp->iscp); |
| 305 | writeb(1, &iscp->busy); |
| 306 | |
| 307 | ni_reset586(); |
| 308 | ni_attn586(); |
| 309 | mdelay(32); /* wait a while... */ |
| 310 | /* i82586 clears 'busy' after successful init */ |
| 311 | if (readb(&iscp->busy)) |
| 312 | return 0; |
| 313 | return 1; |
| 314 | } |
| 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | /********************************************** |
| 317 | * Check to see if there's an 82586 out there. |
| 318 | */ |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 319 | static int check586(struct net_device *dev, unsigned size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { |
Al Viro | 7f8cfd5 | 2008-03-19 09:44:09 +0000 | [diff] [blame] | 321 | struct priv *p = dev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | int i; |
| 323 | |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 324 | p->mapped = ioremap(dev->mem_start, size); |
| 325 | if (!p->mapped) |
| 326 | return 0; |
| 327 | |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 328 | p->base = p->mapped + size - 0x01000000; |
| 329 | p->memtop = p->mapped + size; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 330 | p->scp = (struct scp_struct __iomem *)(p->base + SCP_DEFAULT_ADDRESS); |
Al Viro | 7f8cfd5 | 2008-03-19 09:44:09 +0000 | [diff] [blame] | 331 | p->scb = (struct scb_struct __iomem *) p->mapped; |
Al Viro | 76af569 | 2008-03-19 09:44:19 +0000 | [diff] [blame] | 332 | p->iscp = (struct iscp_struct __iomem *)p->scp - 1; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 333 | memset_io(p->scp, 0, sizeof(struct scp_struct)); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 334 | for (i = 0; i < sizeof(struct scp_struct); i++) |
| 335 | /* memory was writeable? */ |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 336 | if (readb((char __iomem *)p->scp + i)) |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 337 | goto Enodev; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 338 | writeb(SYSBUSVAL, &p->scp->sysbus); /* 1 = 8Bit-Bus, 0 = 16 Bit */ |
| 339 | if (readb(&p->scp->sysbus) != SYSBUSVAL) |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 340 | goto Enodev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Al Viro | 76af569 | 2008-03-19 09:44:19 +0000 | [diff] [blame] | 342 | if (!check_iscp(dev, p->mapped)) |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 343 | goto Enodev; |
Al Viro | 76af569 | 2008-03-19 09:44:19 +0000 | [diff] [blame] | 344 | if (!check_iscp(dev, p->iscp)) |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 345 | goto Enodev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | return 1; |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 347 | Enodev: |
| 348 | iounmap(p->mapped); |
| 349 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /****************************************************************** |
| 353 | * set iscp at the right place, called by ni52_probe1 and open586. |
| 354 | */ |
| 355 | static void alloc586(struct net_device *dev) |
| 356 | { |
| 357 | struct priv *p = (struct priv *) dev->priv; |
| 358 | |
| 359 | ni_reset586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 360 | mdelay(32); |
| 361 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 362 | memset_io(p->iscp, 0, sizeof(struct iscp_struct)); |
| 363 | memset_io(p->scp , 0, sizeof(struct scp_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 365 | writel(make24(p->iscp), &p->scp->iscp); |
| 366 | writeb(SYSBUSVAL, &p->scp->sysbus); |
| 367 | writew(make16(p->scb), &p->iscp->scb_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 369 | writeb(1, &p->iscp->busy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | ni_reset586(); |
| 371 | ni_attn586(); |
| 372 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 373 | mdelay(32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 375 | if (readb(&p->iscp->busy)) |
| 376 | printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 378 | p->reset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 380 | memset_io(p->scb, 0, sizeof(struct scb_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* set: io,irq,memstart,memend or set it when calling insmod */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 384 | static int irq = 9; |
| 385 | static int io = 0x300; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | static long memstart; /* e.g 0xd0000 */ |
| 387 | static long memend; /* e.g 0xd4000 */ |
| 388 | |
| 389 | /********************************************** |
| 390 | * probe the ni5210-card |
| 391 | */ |
| 392 | struct net_device * __init ni52_probe(int unit) |
| 393 | { |
| 394 | struct net_device *dev = alloc_etherdev(sizeof(struct priv)); |
| 395 | static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0}; |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 396 | struct priv *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | int *port; |
| 398 | int err = 0; |
| 399 | |
| 400 | if (!dev) |
| 401 | return ERR_PTR(-ENOMEM); |
| 402 | |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 403 | p = dev->priv; |
| 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | if (unit >= 0) { |
| 406 | sprintf(dev->name, "eth%d", unit); |
| 407 | netdev_boot_setup_check(dev); |
| 408 | io = dev->base_addr; |
| 409 | irq = dev->irq; |
| 410 | memstart = dev->mem_start; |
| 411 | memend = dev->mem_end; |
| 412 | } |
| 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | if (io > 0x1ff) { /* Check a single specified location. */ |
| 415 | err = ni52_probe1(dev, io); |
| 416 | } else if (io > 0) { /* Don't probe at all. */ |
| 417 | err = -ENXIO; |
| 418 | } else { |
| 419 | for (port = ports; *port && ni52_probe1(dev, *port) ; port++) |
| 420 | ; |
| 421 | if (*port) |
| 422 | goto got_it; |
| 423 | #ifdef FULL_IO_PROBE |
| 424 | for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8) |
| 425 | ; |
| 426 | if (io < 0x400) |
| 427 | goto got_it; |
| 428 | #endif |
| 429 | err = -ENODEV; |
| 430 | } |
| 431 | if (err) |
| 432 | goto out; |
| 433 | got_it: |
| 434 | err = register_netdev(dev); |
| 435 | if (err) |
| 436 | goto out1; |
| 437 | return dev; |
| 438 | out1: |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 439 | iounmap(p->mapped); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | release_region(dev->base_addr, NI52_TOTAL_SIZE); |
| 441 | out: |
| 442 | free_netdev(dev); |
| 443 | return ERR_PTR(err); |
| 444 | } |
| 445 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 446 | static int __init ni52_probe1(struct net_device *dev, int ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | { |
| 448 | int i, size, retval; |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 449 | struct priv *priv = dev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | dev->base_addr = ioaddr; |
| 452 | dev->irq = irq; |
| 453 | dev->mem_start = memstart; |
| 454 | dev->mem_end = memend; |
| 455 | |
Al Viro | 7f8cfd5 | 2008-03-19 09:44:09 +0000 | [diff] [blame] | 456 | spin_lock_init(&priv->spinlock); |
| 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME)) |
| 459 | return -EBUSY; |
| 460 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 461 | if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) { |
| 463 | retval = -ENODEV; |
| 464 | goto out; |
| 465 | } |
| 466 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 467 | for (i = 0; i < ETH_ALEN; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | dev->dev_addr[i] = inb(dev->base_addr+i); |
| 469 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 470 | 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] | 471 | || dev->dev_addr[2] != NI52_ADDR2) { |
| 472 | retval = -ENODEV; |
| 473 | goto out; |
| 474 | } |
| 475 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 476 | printk(KERN_INFO "%s: NI5210 found at %#3lx, ", |
| 477 | dev->name, dev->base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | /* |
| 480 | * check (or search) IO-Memory, 8K and 16K |
| 481 | */ |
| 482 | #ifdef MODULE |
| 483 | size = dev->mem_end - dev->mem_start; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 484 | if (size != 0x2000 && size != 0x4000) { |
| 485 | printk("\n"); |
| 486 | 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] | 487 | retval = -ENODEV; |
| 488 | goto out; |
| 489 | } |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 490 | if (!check586(dev, size)) { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 491 | 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] | 492 | retval = -ENODEV; |
| 493 | goto out; |
| 494 | } |
| 495 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 496 | if (dev->mem_start != 0) { |
| 497 | /* no auto-mem-probe */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | size = 0x4000; /* check for 16K mem */ |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 499 | if (!check586(dev, size)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | size = 0x2000; /* check for 8K mem */ |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 501 | if (!check586(dev, size)) { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 502 | 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] | 503 | retval = -ENODEV; |
| 504 | goto out; |
| 505 | } |
| 506 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 507 | } else { |
| 508 | static const unsigned long memaddrs[] = { |
| 509 | 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000, |
| 510 | 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0 |
| 511 | }; |
| 512 | for (i = 0;; i++) { |
| 513 | if (!memaddrs[i]) { |
| 514 | printk(KERN_ERR "?memprobe, Can't find io-memory!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | retval = -ENODEV; |
| 516 | goto out; |
| 517 | } |
| 518 | dev->mem_start = memaddrs[i]; |
| 519 | size = 0x2000; /* check for 8K mem */ |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 520 | if (check586(dev, size)) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 521 | /* 8K-check */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | break; |
| 523 | size = 0x4000; /* check for 16K mem */ |
Al Viro | de59714 | 2008-03-19 09:43:49 +0000 | [diff] [blame] | 524 | if (check586(dev, size)) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 525 | /* 16K-check */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | break; |
| 527 | } |
| 528 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 529 | /* set mem_end showed by 'ifconfig' */ |
| 530 | dev->mem_end = dev->mem_start + size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | #endif |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | alloc586(dev); |
| 534 | |
| 535 | /* set number of receive-buffs according to memsize */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 536 | if (size == 0x2000) |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 537 | priv->num_recv_buffs = NUM_RECV_BUFFS_8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | else |
Al Viro | e06ee2b | 2008-03-19 09:43:59 +0000 | [diff] [blame] | 539 | priv->num_recv_buffs = NUM_RECV_BUFFS_16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 541 | printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ", |
| 542 | dev->mem_start, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 544 | if (dev->irq < 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | unsigned long irq_mask; |
| 546 | |
| 547 | irq_mask = probe_irq_on(); |
| 548 | ni_reset586(); |
| 549 | ni_attn586(); |
| 550 | |
| 551 | mdelay(20); |
| 552 | dev->irq = probe_irq_off(irq_mask); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 553 | if (!dev->irq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | printk("?autoirq, Failed to detect IRQ line!\n"); |
| 555 | retval = -EAGAIN; |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 556 | iounmap(priv->mapped); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | goto out; |
| 558 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 559 | printk("IRQ %d (autodetected).\n", dev->irq); |
| 560 | } else { |
| 561 | if (dev->irq == 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | dev->irq = 9; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 563 | printk("IRQ %d (assigned and not checked!).\n", dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | dev->open = ni52_open; |
| 567 | dev->stop = ni52_close; |
| 568 | dev->get_stats = ni52_get_stats; |
| 569 | dev->tx_timeout = ni52_timeout; |
| 570 | dev->watchdog_timeo = HZ/20; |
| 571 | dev->hard_start_xmit = ni52_send_packet; |
| 572 | dev->set_multicast_list = set_multicast_list; |
| 573 | |
| 574 | dev->if_port = 0; |
| 575 | |
| 576 | return 0; |
| 577 | out: |
| 578 | release_region(ioaddr, NI52_TOTAL_SIZE); |
| 579 | return retval; |
| 580 | } |
| 581 | |
| 582 | /********************************************** |
| 583 | * init the chip (ni52-interrupt should be disabled?!) |
| 584 | * needs a correct 'allocated' memory |
| 585 | */ |
| 586 | |
| 587 | static int init586(struct net_device *dev) |
| 588 | { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 589 | void __iomem *ptr; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 590 | int i, result = 0; |
| 591 | struct priv *p = (struct priv *)dev->priv; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 592 | struct configure_cmd_struct __iomem *cfg_cmd; |
| 593 | struct iasetup_cmd_struct __iomem *ias_cmd; |
| 594 | struct tdr_cmd_struct __iomem *tdr_cmd; |
| 595 | struct mcsetup_cmd_struct __iomem *mc_cmd; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 596 | struct dev_mc_list *dmi = dev->mc_list; |
| 597 | int num_addrs = dev->mc_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 599 | ptr = p->scb + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 601 | cfg_cmd = ptr; /* configure-command */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 602 | writew(0, &cfg_cmd->cmd_status); |
| 603 | writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd); |
| 604 | writew(0xFFFF, &cfg_cmd->cmd_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 606 | /* number of cfg bytes */ |
| 607 | writeb(0x0a, &cfg_cmd->byte_cnt); |
| 608 | /* fifo-limit (8=tx:32/rx:64) */ |
| 609 | writeb(fifo, &cfg_cmd->fifo); |
| 610 | /* hold or discard bad recv frames (bit 7) */ |
| 611 | writeb(0x40, &cfg_cmd->sav_bf); |
| 612 | /* addr_len |!src_insert |pre-len |loopback */ |
| 613 | writeb(0x2e, &cfg_cmd->adr_len); |
| 614 | writeb(0x00, &cfg_cmd->priority); |
| 615 | writeb(0x60, &cfg_cmd->ifs);; |
| 616 | writeb(0x00, &cfg_cmd->time_low); |
| 617 | writeb(0xf2, &cfg_cmd->time_high); |
| 618 | writeb(0x00, &cfg_cmd->promisc);; |
| 619 | if (dev->flags & IFF_ALLMULTI) { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 620 | int len = ((char __iomem *)p->iscp - (char __iomem *)ptr - 8) / 6; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 621 | if (num_addrs > len) { |
| 622 | printk(KERN_ERR "%s: switching to promisc. mode\n", |
| 623 | dev->name); |
| 624 | dev->flags |= IFF_PROMISC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |
| 626 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 627 | if (dev->flags & IFF_PROMISC) |
| 628 | writeb(0x01, &cfg_cmd->promisc); |
| 629 | writeb(0x00, &cfg_cmd->carr_coll); |
| 630 | writew(make16(cfg_cmd), &p->scb->cbl_offset); |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 631 | writeb(0, &p->scb->cmd_ruc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 633 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | ni_attn586(); |
| 635 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 636 | wait_for_stat_compl(cfg_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 638 | if ((readw(&cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != |
| 639 | (STAT_COMPL|STAT_OK)) { |
| 640 | printk(KERN_ERR "%s: configure command failed: %x\n", |
| 641 | dev->name, readw(&cfg_cmd->cmd_status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | return 1; |
| 643 | } |
| 644 | |
| 645 | /* |
| 646 | * individual address setup |
| 647 | */ |
| 648 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 649 | ias_cmd = ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 651 | writew(0, &ias_cmd->cmd_status); |
| 652 | writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd); |
| 653 | writew(0xffff, &ias_cmd->cmd_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 655 | memcpy_toio(&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 657 | writew(make16(ias_cmd), &p->scb->cbl_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 659 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | ni_attn586(); |
| 661 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 662 | wait_for_stat_compl(ias_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 664 | if ((readw(&ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != |
| 665 | (STAT_OK|STAT_COMPL)) { |
| 666 | 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] | 667 | return 1; |
| 668 | } |
| 669 | |
| 670 | /* |
| 671 | * TDR, wire check .. e.g. no resistor e.t.c |
| 672 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 673 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 674 | tdr_cmd = ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 676 | writew(0, &tdr_cmd->cmd_status); |
| 677 | writew(CMD_TDR | CMD_LAST, &tdr_cmd->cmd_cmd); |
| 678 | writew(0xffff, &tdr_cmd->cmd_link); |
| 679 | writew(0, &tdr_cmd->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 681 | writew(make16(tdr_cmd), &p->scb->cbl_offset); |
| 682 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | ni_attn586(); |
| 684 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 685 | wait_for_stat_compl(tdr_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 687 | if (!(readw(&tdr_cmd->cmd_status) & STAT_COMPL)) |
| 688 | printk(KERN_ERR "%s: Problems while running the TDR.\n", |
| 689 | dev->name); |
| 690 | else { |
| 691 | udelay(16); |
| 692 | result = readw(&tdr_cmd->status); |
| 693 | writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | ni_attn586(); /* ack the interrupts */ |
| 695 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 696 | if (result & TDR_LNK_OK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | ; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 698 | else if (result & TDR_XCVR_PRB) |
| 699 | printk(KERN_ERR "%s: TDR: Transceiver problem. Check the cable(s)!\n", |
| 700 | dev->name); |
| 701 | else if (result & TDR_ET_OPN) |
| 702 | printk(KERN_ERR "%s: TDR: No correct termination %d clocks away.\n", |
| 703 | dev->name, result & TDR_TIMEMASK); |
| 704 | else if (result & TDR_ET_SRT) { |
| 705 | /* time == 0 -> strange :-) */ |
| 706 | if (result & TDR_TIMEMASK) |
| 707 | printk(KERN_ERR "%s: TDR: Detected a short circuit %d clocks away.\n", |
| 708 | dev->name, result & TDR_TIMEMASK); |
| 709 | } else |
| 710 | printk(KERN_ERR "%s: TDR: Unknown status %04x\n", |
| 711 | dev->name, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /* |
| 715 | * Multicast setup |
| 716 | */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 717 | if (num_addrs && !(dev->flags & IFF_PROMISC)) { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 718 | mc_cmd = ptr; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 719 | writew(0, &mc_cmd->cmd_status); |
| 720 | writew(CMD_MCSETUP | CMD_LAST, &mc_cmd->cmd_cmd); |
| 721 | writew(0xffff, &mc_cmd->cmd_link); |
| 722 | writew(num_addrs * 6, &mc_cmd->mc_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 724 | for (i = 0; i < num_addrs; i++, dmi = dmi->next) |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 725 | memcpy_toio(mc_cmd->mc_list[i], |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 726 | dmi->dmi_addr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 728 | writew(make16(mc_cmd), &p->scb->cbl_offset); |
| 729 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | ni_attn586(); |
| 731 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 732 | wait_for_stat_compl(mc_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 734 | if ((readw(&mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK)) |
| 735 | != (STAT_COMPL|STAT_OK)) |
| 736 | 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] | 737 | } |
| 738 | |
| 739 | /* |
| 740 | * alloc nop/xmit-cmds |
| 741 | */ |
| 742 | #if (NUM_XMIT_BUFFS == 1) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 743 | for (i = 0; i < 2; i++) { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 744 | p->nop_cmds[i] = ptr; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 745 | writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd); |
| 746 | writew(0, &p->nop_cmds[i]->cmd_status); |
| 747 | writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link); |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 748 | ptr = ptr + sizeof(struct nop_cmd_struct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 751 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 752 | p->nop_cmds[i] = ptr; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 753 | writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd); |
| 754 | writew(0, &p->nop_cmds[i]->cmd_status); |
| 755 | writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link); |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 756 | ptr = ptr + sizeof(struct nop_cmd_struct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | } |
| 758 | #endif |
| 759 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 760 | ptr = alloc_rfa(dev, ptr); /* init receive-frame-area */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
| 762 | /* |
| 763 | * alloc xmit-buffs / init xmit_cmds |
| 764 | */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 765 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { |
| 766 | /* Transmit cmd/buff 0 */ |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 767 | p->xmit_cmds[i] = ptr; |
| 768 | ptr = ptr + sizeof(struct transmit_cmd_struct); |
| 769 | p->xmit_cbuffs[i] = ptr; /* char-buffs */ |
| 770 | ptr = ptr + XMIT_BUFF_SIZE; |
| 771 | p->xmit_buffs[i] = ptr; /* TBD */ |
| 772 | ptr = ptr + sizeof(struct tbd_struct); |
| 773 | if ((void __iomem *)ptr > (void __iomem *)p->iscp) { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 774 | printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n", |
| 775 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | return 1; |
| 777 | } |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 778 | memset_io(p->xmit_cmds[i], 0, |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 779 | sizeof(struct transmit_cmd_struct)); |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 780 | memset_io(p->xmit_buffs[i], 0, |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 781 | sizeof(struct tbd_struct)); |
| 782 | writew(make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]), |
| 783 | &p->xmit_cmds[i]->cmd_link); |
| 784 | writew(STAT_COMPL, &p->xmit_cmds[i]->cmd_status); |
| 785 | writew(CMD_XMIT|CMD_INT, &p->xmit_cmds[i]->cmd_cmd); |
| 786 | writew(make16(p->xmit_buffs[i]), &p->xmit_cmds[i]->tbd_offset); |
| 787 | writew(0xffff, &p->xmit_buffs[i]->next); |
| 788 | writel(make24(p->xmit_cbuffs[i]), &p->xmit_buffs[i]->buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | p->xmit_count = 0; |
| 792 | p->xmit_last = 0; |
| 793 | #ifndef NO_NOPCOMMANDS |
| 794 | p->nop_point = 0; |
| 795 | #endif |
| 796 | |
| 797 | /* |
| 798 | * 'start transmitter' |
| 799 | */ |
| 800 | #ifndef NO_NOPCOMMANDS |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 801 | writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset); |
| 802 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 804 | wait_for_scb_cmd(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 806 | writew(make16(p->xmit_cmds[0]), &p->xmit_cmds[0]->cmd_link); |
| 807 | 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] | 808 | #endif |
| 809 | |
| 810 | /* |
| 811 | * ack. interrupts |
| 812 | */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 813 | writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 815 | udelay(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
| 817 | ni_enaint(); |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | /****************************************************** |
| 823 | * This is a helper routine for ni52_rnr_int() and init586(). |
| 824 | * It sets up the Receive Frame Area (RFA). |
| 825 | */ |
| 826 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 827 | static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 829 | struct rfd_struct __iomem *rfd = ptr; |
| 830 | struct rbd_struct __iomem *rbd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | int i; |
| 832 | struct priv *p = (struct priv *) dev->priv; |
| 833 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 834 | memset_io(rfd, 0, |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 835 | sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | p->rfd_first = rfd; |
| 837 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 838 | for (i = 0; i < (p->num_recv_buffs + rfdadd); i++) { |
| 839 | writew(make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd)), |
| 840 | &rfd[i].next); |
| 841 | writew(0xffff, &rfd[i].rbd_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 843 | /* RU suspend */ |
| 844 | writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 846 | ptr = rfd + (p->num_recv_buffs + rfdadd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 848 | rbd = ptr; |
| 849 | ptr = rbd + p->num_recv_buffs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
| 851 | /* clr descriptors */ |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 852 | memset_io(rbd, 0, sizeof(struct rbd_struct) * (p->num_recv_buffs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 854 | for (i = 0; i < p->num_recv_buffs; i++) { |
| 855 | writew(make16(rbd + (i+1) % p->num_recv_buffs), &rbd[i].next); |
| 856 | writew(RECV_BUFF_SIZE, &rbd[i].size); |
| 857 | writel(make24(ptr), &rbd[i].buffer); |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 858 | ptr = ptr + RECV_BUFF_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | p->rfd_top = p->rfd_first; |
| 861 | p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd); |
| 862 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 863 | writew(make16(p->rfd_first), &p->scb->rfa_offset); |
| 864 | writew(make16(rbd), &p->rfd_first->rbd_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | return ptr; |
| 867 | } |
| 868 | |
| 869 | |
| 870 | /************************************************** |
| 871 | * Interrupt Handler ... |
| 872 | */ |
| 873 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 874 | static irqreturn_t ni52_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | { |
| 876 | struct net_device *dev = dev_id; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 877 | unsigned int stat; |
| 878 | int cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | struct priv *p; |
| 880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | p = (struct priv *) dev->priv; |
| 882 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 883 | if (debuglevel > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | printk("I"); |
| 885 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 886 | spin_lock(&p->spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 888 | wait_for_scb_cmd(dev); /* wait for last command */ |
| 889 | |
| 890 | while ((stat = readb(&p->scb->cus) & STAT_MASK)) { |
| 891 | writeb(stat, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | ni_attn586(); |
| 893 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 894 | if (stat & STAT_FR) /* received a frame */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | ni52_rcv_int(dev); |
| 896 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 897 | if (stat & STAT_RNR) { /* RU went 'not ready' */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | printk("(R)"); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 899 | if (readb(&p->scb->rus) & RU_SUSPEND) { |
| 900 | /* special case: RU_SUSPEND */ |
| 901 | wait_for_scb_cmd(dev); |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 902 | writeb(RUC_RESUME, &p->scb->cmd_ruc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 904 | wait_for_scb_cmd_ruc(dev); |
| 905 | } else { |
| 906 | printk(KERN_ERR "%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n", |
| 907 | dev->name, stat, readb(&p->scb->rus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | ni52_rnr_int(dev); |
| 909 | } |
| 910 | } |
| 911 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 912 | /* Command with I-bit set complete */ |
| 913 | if (stat & STAT_CX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | ni52_xmt_int(dev); |
| 915 | |
| 916 | #ifndef NO_NOPCOMMANDS |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 917 | if (stat & STAT_CNA) { /* CU went 'not ready' */ |
| 918 | if (netif_running(dev)) |
| 919 | printk(KERN_ERR "%s: oops! CU has left active state. stat: %04x/%02x.\n", |
| 920 | dev->name, stat, readb(&p->scb->cus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } |
| 922 | #endif |
| 923 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 924 | if (debuglevel > 1) |
| 925 | printk("%d", cnt++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 927 | /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */ |
| 928 | wait_for_scb_cmd(dev); |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 929 | if (readb(&p->scb->cmd_cuc)) { /* timed out? */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 930 | printk(KERN_ERR "%s: Acknowledge timed out.\n", |
| 931 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | ni_disint(); |
| 933 | break; |
| 934 | } |
| 935 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 936 | spin_unlock(&p->spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 938 | if (debuglevel > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | printk("i"); |
| 940 | return IRQ_HANDLED; |
| 941 | } |
| 942 | |
| 943 | /******************************************************* |
| 944 | * receive-interrupt |
| 945 | */ |
| 946 | |
| 947 | static void ni52_rcv_int(struct net_device *dev) |
| 948 | { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 949 | int status, cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | unsigned short totlen; |
| 951 | struct sk_buff *skb; |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 952 | struct rbd_struct __iomem *rbd; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 953 | struct priv *p = (struct priv *)dev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 955 | if (debuglevel > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | printk("R"); |
| 957 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 958 | for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) { |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 959 | rbd = make32(readw(&p->rfd_top->rbd_offset)); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 960 | if (status & RFD_OK) { /* frame received without error? */ |
| 961 | totlen = readw(&rbd->status); |
| 962 | if (totlen & RBD_LAST) { |
| 963 | /* the first and the last buffer? */ |
| 964 | totlen &= RBD_MASK; /* length of this frame */ |
| 965 | writew(0x00, &rbd->status); |
| 966 | skb = (struct sk_buff *)dev_alloc_skb(totlen+2); |
| 967 | if (skb != NULL) { |
| 968 | skb_reserve(skb, 2); |
| 969 | skb_put(skb, totlen); |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 970 | memcpy_fromio(skb->data, p->base + readl(&rbd->buffer), totlen); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 971 | skb->protocol = eth_type_trans(skb, dev); |
| 972 | netif_rx(skb); |
| 973 | dev->last_rx = jiffies; |
| 974 | p->stats.rx_packets++; |
| 975 | p->stats.rx_bytes += totlen; |
| 976 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | p->stats.rx_dropped++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 978 | } else { |
| 979 | int rstat; |
| 980 | /* free all RBD's until RBD_LAST is set */ |
| 981 | totlen = 0; |
| 982 | while (!((rstat = readw(&rbd->status)) & RBD_LAST)) { |
| 983 | totlen += rstat & RBD_MASK; |
| 984 | if (!rstat) { |
| 985 | printk(KERN_ERR "%s: Whoops .. no end mark in RBD list\n", dev->name); |
| 986 | break; |
| 987 | } |
| 988 | writew(0, &rbd->status); |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 989 | rbd = make32(readw(&rbd->next)); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 990 | } |
| 991 | totlen += rstat & RBD_MASK; |
| 992 | writew(0, &rbd->status); |
| 993 | printk(KERN_ERR "%s: received oversized frame! length: %d\n", |
| 994 | dev->name, totlen); |
| 995 | p->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 997 | } else {/* frame !(ok), only with 'save-bad-frames' */ |
| 998 | printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n", |
| 999 | dev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | p->stats.rx_errors++; |
| 1001 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1002 | writeb(0, &p->rfd_top->stat_high); |
| 1003 | writeb(RFD_SUSP, &p->rfd_top->last); /* maybe exchange by RFD_LAST */ |
| 1004 | writew(0xffff, &p->rfd_top->rbd_offset); |
| 1005 | writeb(0, &p->rfd_last->last); /* delete RFD_SUSP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | p->rfd_last = p->rfd_top; |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 1007 | p->rfd_top = make32(readw(&p->rfd_top->next)); /* step to next RFD */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1008 | writew(make16(p->rfd_top), &p->scb->rfa_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1010 | if (debuglevel > 0) |
| 1011 | printk("%d", cnt++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1014 | if (automatic_resume) { |
| 1015 | wait_for_scb_cmd(dev); |
| 1016 | writeb(RUC_RESUME, &p->scb->cmd_ruc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1018 | wait_for_scb_cmd_ruc(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | #ifdef WAIT_4_BUSY |
| 1022 | { |
| 1023 | int i; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1024 | for (i = 0; i < 1024; i++) { |
| 1025 | if (p->rfd_top->status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | break; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1027 | udelay(16); |
| 1028 | if (i == 1023) |
| 1029 | 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] | 1030 | } |
| 1031 | } |
| 1032 | #endif |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1033 | if (debuglevel > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | printk("r"); |
| 1035 | } |
| 1036 | |
| 1037 | /********************************************************** |
| 1038 | * handle 'Receiver went not ready'. |
| 1039 | */ |
| 1040 | |
| 1041 | static void ni52_rnr_int(struct net_device *dev) |
| 1042 | { |
| 1043 | struct priv *p = (struct priv *) dev->priv; |
| 1044 | |
| 1045 | p->stats.rx_errors++; |
| 1046 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1047 | wait_for_scb_cmd(dev); /* wait for the last cmd, WAIT_4_FULLSTAT?? */ |
| 1048 | 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] | 1049 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1050 | wait_for_scb_cmd_ruc(dev); /* wait for accept cmd. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | |
Al Viro | 2d76c26 | 2008-03-19 09:43:29 +0000 | [diff] [blame] | 1052 | alloc_rfa(dev, p->rfd_first); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1053 | /* maybe add a check here, before restarting the RU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | startrecv586(dev); /* restart RU */ |
| 1055 | |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 1056 | printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n", |
| 1057 | dev->name, readb(&p->scb->rus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | |
| 1059 | } |
| 1060 | |
| 1061 | /********************************************************** |
| 1062 | * handle xmit - interrupt |
| 1063 | */ |
| 1064 | |
| 1065 | static void ni52_xmt_int(struct net_device *dev) |
| 1066 | { |
| 1067 | int status; |
| 1068 | struct priv *p = (struct priv *) dev->priv; |
| 1069 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1070 | if (debuglevel > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | printk("X"); |
| 1072 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1073 | status = readw(&p->xmit_cmds[p->xmit_last]->cmd_status); |
| 1074 | if (!(status & STAT_COMPL)) |
| 1075 | 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] | 1076 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1077 | if (status & STAT_OK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | p->stats.tx_packets++; |
| 1079 | p->stats.collisions += (status & TCMD_MAXCOLLMASK); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1080 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | p->stats.tx_errors++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1082 | if (status & TCMD_LATECOLL) { |
| 1083 | printk(KERN_ERR "%s: late collision detected.\n", |
| 1084 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | p->stats.collisions++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1086 | } else if (status & TCMD_NOCARRIER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | p->stats.tx_carrier_errors++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1088 | printk(KERN_ERR "%s: no carrier detected.\n", |
| 1089 | dev->name); |
| 1090 | } else if (status & TCMD_LOSTCTS) |
| 1091 | printk(KERN_ERR "%s: loss of CTS detected.\n", |
| 1092 | dev->name); |
| 1093 | else if (status & TCMD_UNDERRUN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | p->stats.tx_fifo_errors++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1095 | printk(KERN_ERR "%s: DMA underrun detected.\n", |
| 1096 | dev->name); |
| 1097 | } else if (status & TCMD_MAXCOLL) { |
| 1098 | printk(KERN_ERR "%s: Max. collisions exceeded.\n", |
| 1099 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | p->stats.collisions += 16; |
| 1101 | } |
| 1102 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | #if (NUM_XMIT_BUFFS > 1) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1104 | if ((++p->xmit_last) == NUM_XMIT_BUFFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | p->xmit_last = 0; |
| 1106 | #endif |
| 1107 | netif_wake_queue(dev); |
| 1108 | } |
| 1109 | |
| 1110 | /*********************************************************** |
| 1111 | * (re)start the receiver |
| 1112 | */ |
| 1113 | |
| 1114 | static void startrecv586(struct net_device *dev) |
| 1115 | { |
| 1116 | struct priv *p = (struct priv *) dev->priv; |
| 1117 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1118 | wait_for_scb_cmd(dev); |
| 1119 | wait_for_scb_cmd_ruc(dev); |
| 1120 | writew(make16(p->rfd_first), &p->scb->rfa_offset); |
| 1121 | writeb(RUC_START, &p->scb->cmd_ruc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | ni_attn586(); /* start cmd. */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1123 | wait_for_scb_cmd_ruc(dev); |
| 1124 | /* wait for accept cmd. (no timeout!!) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | static void ni52_timeout(struct net_device *dev) |
| 1128 | { |
| 1129 | struct priv *p = (struct priv *) dev->priv; |
| 1130 | #ifndef NO_NOPCOMMANDS |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1131 | if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | netif_wake_queue(dev); |
| 1133 | #ifdef DEBUG |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1134 | printk(KERN_ERR "%s: strange ... timeout with CU active?!?\n", |
| 1135 | dev->name); |
| 1136 | printk(KERN_ERR "%s: X0: %04x N0: %04x N1: %04x %d\n", |
| 1137 | dev->name, (int)p->xmit_cmds[0]->cmd_status, |
| 1138 | readw(&p->nop_cmds[0]->cmd_status), |
| 1139 | readw(&p->nop_cmds[1]->cmd_status), |
| 1140 | p->nop_point); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | #endif |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1142 | writeb(CUC_ABORT, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1144 | wait_for_scb_cmd(dev); |
| 1145 | writew(make16(p->nop_cmds[p->nop_point]), &p->scb->cbl_offset); |
| 1146 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1148 | wait_for_scb_cmd(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | dev->trans_start = jiffies; |
| 1150 | return 0; |
| 1151 | } |
| 1152 | #endif |
| 1153 | { |
| 1154 | #ifdef DEBUG |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1155 | printk(KERN_ERR "%s: xmitter timed out, try to restart! stat: %02x\n", |
| 1156 | dev->name, readb(&p->scb->cus)); |
| 1157 | printk(KERN_ERR "%s: command-stats: %04x %04x\n", |
| 1158 | dev->name, |
| 1159 | readw(&p->xmit_cmds[0]->cmd_status), |
| 1160 | readw(&p->xmit_cmds[1]->cmd_status)); |
| 1161 | printk(KERN_ERR "%s: check, whether you set the right interrupt number!\n", |
| 1162 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | #endif |
| 1164 | ni52_close(dev); |
| 1165 | ni52_open(dev); |
| 1166 | } |
| 1167 | dev->trans_start = jiffies; |
| 1168 | } |
| 1169 | |
| 1170 | /****************************************************** |
| 1171 | * send frame |
| 1172 | */ |
| 1173 | |
| 1174 | static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev) |
| 1175 | { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1176 | int len, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | #ifndef NO_NOPCOMMANDS |
| 1178 | int next_nop; |
| 1179 | #endif |
| 1180 | struct priv *p = (struct priv *) dev->priv; |
| 1181 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1182 | if (skb->len > XMIT_BUFF_SIZE) { |
| 1183 | 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] | 1184 | return 0; |
| 1185 | } |
| 1186 | |
| 1187 | netif_stop_queue(dev); |
| 1188 | |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 1189 | memcpy_toio(p->xmit_cbuffs[p->xmit_count], skb->data, skb->len); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1190 | len = skb->len; |
| 1191 | if (len < ETH_ZLEN) { |
| 1192 | len = ETH_ZLEN; |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 1193 | memset_io(p->xmit_cbuffs[p->xmit_count]+skb->len, 0, |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1194 | len - skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | |
| 1197 | #if (NUM_XMIT_BUFFS == 1) |
| 1198 | # ifdef NO_NOPCOMMANDS |
| 1199 | |
| 1200 | #ifdef DEBUG |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 1201 | if (readb(&p->scb->cus) & CU_ACTIVE) { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1202 | printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name); |
| 1203 | printk(KERN_ERR "%s: stat: %04x %04x\n", |
| 1204 | dev->name, readb(&p->scb->cus), |
| 1205 | readw(&p->xmit_cmds[0]->cmd_status)); |
| 1206 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | #endif |
Al Viro | 05bd831 | 2008-03-19 09:44:39 +0000 | [diff] [blame] | 1208 | writew(TBD_LAST | len, &p->xmit_buffs[0]->size); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1209 | for (i = 0; i < 16; i++) { |
| 1210 | writew(0, &p->xmit_cmds[0]->cmd_status); |
| 1211 | wait_for_scb_cmd(dev); |
| 1212 | if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND) |
| 1213 | writeb(CUC_RESUME, &p->scb->cmd_cuc); |
| 1214 | else { |
| 1215 | writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset); |
| 1216 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1218 | ni_attn586(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | dev->trans_start = jiffies; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1220 | if (!i) |
| 1221 | dev_kfree_skb(skb); |
| 1222 | wait_for_scb_cmd(dev); |
| 1223 | /* test it, because CU sometimes doesn't start immediately */ |
| 1224 | if (readb(&p->scb->cus) & CU_ACTIVE) |
| 1225 | break; |
| 1226 | if (readw(&p->xmit_cmds[0]->cmd_status)) |
| 1227 | break; |
| 1228 | if (i == 15) |
| 1229 | printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name); |
| 1230 | } |
| 1231 | # else |
| 1232 | next_nop = (p->nop_point + 1) & 0x1; |
| 1233 | writew(TBD_LAST | len, &p->xmit_buffs[0]->size); |
| 1234 | writew(make16(p->nop_cmds[next_nop]), &p->xmit_cmds[0]->cmd_link); |
| 1235 | writew(make16(p->nop_cmds[next_nop]), |
| 1236 | &p->nop_cmds[next_nop]->cmd_link); |
| 1237 | writew(0, &p->xmit_cmds[0]->cmd_status); |
| 1238 | writew(0, &p->nop_cmds[next_nop]->cmd_status); |
| 1239 | |
| 1240 | writew(make16(p->xmit_cmds[0]), &p->nop_cmds[p->nop_point]->cmd_link); |
| 1241 | dev->trans_start = jiffies; |
| 1242 | p->nop_point = next_nop; |
| 1243 | dev_kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | # endif |
| 1245 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1246 | writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size); |
| 1247 | next_nop = p->xmit_count + 1 |
| 1248 | if (next_nop == NUM_XMIT_BUFFS) |
| 1249 | next_nop = 0; |
| 1250 | writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status); |
| 1251 | /* linkpointer of xmit-command already points to next nop cmd */ |
| 1252 | writew(make16(p->nop_cmds[next_nop]), |
| 1253 | &p->nop_cmds[next_nop]->cmd_link); |
| 1254 | writew(0, &p->nop_cmds[next_nop]->cmd_status); |
| 1255 | writew(make16(p->xmit_cmds[p->xmit_count]), |
| 1256 | &p->nop_cmds[p->xmit_count]->cmd_link); |
| 1257 | dev->trans_start = jiffies; |
| 1258 | p->xmit_count = next_nop; |
| 1259 | { |
| 1260 | unsigned long flags; |
| 1261 | spin_lock_irqsave(&p->spinlock); |
| 1262 | if (p->xmit_count != p->xmit_last) |
| 1263 | netif_wake_queue(dev); |
| 1264 | spin_unlock_irqrestore(&p->spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1266 | dev_kfree_skb(skb); |
| 1267 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | return 0; |
| 1269 | } |
| 1270 | |
| 1271 | /******************************************* |
| 1272 | * Someone wanna have the statistics |
| 1273 | */ |
| 1274 | |
| 1275 | static struct net_device_stats *ni52_get_stats(struct net_device *dev) |
| 1276 | { |
| 1277 | struct priv *p = (struct priv *) dev->priv; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1278 | unsigned short crc, aln, rsc, ovrn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1280 | /* Get error-statistics from the ni82586 */ |
| 1281 | crc = readw(&p->scb->crc_errs); |
| 1282 | writew(0, &p->scb->crc_errs); |
| 1283 | aln = readw(&p->scb->aln_errs); |
| 1284 | writew(0, &p->scb->aln_errs); |
| 1285 | rsc = readw(&p->scb->rsc_errs); |
| 1286 | writew(0, &p->scb->rsc_errs); |
| 1287 | ovrn = readw(&p->scb->ovrn_errs); |
| 1288 | writew(0, &p->scb->ovrn_errs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | |
| 1290 | p->stats.rx_crc_errors += crc; |
| 1291 | p->stats.rx_fifo_errors += ovrn; |
| 1292 | p->stats.rx_frame_errors += aln; |
| 1293 | p->stats.rx_dropped += rsc; |
| 1294 | |
| 1295 | return &p->stats; |
| 1296 | } |
| 1297 | |
| 1298 | /******************************************************** |
| 1299 | * Set MC list .. |
| 1300 | */ |
| 1301 | |
| 1302 | static void set_multicast_list(struct net_device *dev) |
| 1303 | { |
| 1304 | netif_stop_queue(dev); |
| 1305 | ni_disint(); |
| 1306 | alloc586(dev); |
| 1307 | init586(dev); |
| 1308 | startrecv586(dev); |
| 1309 | ni_enaint(); |
| 1310 | netif_wake_queue(dev); |
| 1311 | } |
| 1312 | |
| 1313 | #ifdef MODULE |
| 1314 | static struct net_device *dev_ni52; |
| 1315 | |
| 1316 | module_param(io, int, 0); |
| 1317 | module_param(irq, int, 0); |
| 1318 | module_param(memstart, long, 0); |
| 1319 | module_param(memend, long, 0); |
| 1320 | MODULE_PARM_DESC(io, "NI5210 I/O base address,required"); |
| 1321 | MODULE_PARM_DESC(irq, "NI5210 IRQ number,required"); |
| 1322 | MODULE_PARM_DESC(memstart, "NI5210 memory base address,required"); |
| 1323 | MODULE_PARM_DESC(memend, "NI5210 memory end address,required"); |
| 1324 | |
Andrew Morton | 19a8664 | 2006-08-14 23:00:05 -0700 | [diff] [blame] | 1325 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1327 | if (io <= 0x0 || !memend || !memstart || irq < 2) { |
| 1328 | printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n"); |
| 1329 | printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | return -ENODEV; |
| 1331 | } |
| 1332 | dev_ni52 = ni52_probe(-1); |
| 1333 | if (IS_ERR(dev_ni52)) |
| 1334 | return PTR_ERR(dev_ni52); |
| 1335 | return 0; |
| 1336 | } |
| 1337 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 1338 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | { |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 1340 | struct priv *p = dev_ni52->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | unregister_netdev(dev_ni52); |
Al Viro | 176f65f | 2008-03-19 09:44:29 +0000 | [diff] [blame] | 1342 | iounmap(p->mapped); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE); |
| 1344 | free_netdev(dev_ni52); |
| 1345 | } |
| 1346 | #endif /* MODULE */ |
| 1347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | MODULE_LICENSE("GPL"); |
| 1349 | |
| 1350 | /* |
| 1351 | * END: linux/drivers/net/ni52.c |
| 1352 | */ |