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