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