Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* ibmtr.c: A shared-memory IBM Token Ring 16/4 driver for linux |
| 2 | * |
| 3 | * Written 1993 by Mark Swanson and Peter De Schrijver. |
| 4 | * This software may be used and distributed according to the terms |
| 5 | * of the GNU General Public License, incorporated herein by reference. |
| 6 | * |
| 7 | * This device driver should work with Any IBM Token Ring Card that does |
| 8 | * not use DMA. |
| 9 | * |
| 10 | * I used Donald Becker's (becker@scyld.com) device driver work |
| 11 | * as a base for most of my initial work. |
| 12 | * |
| 13 | * Changes by Peter De Schrijver |
| 14 | * (Peter.Deschrijver@linux.cc.kuleuven.ac.be) : |
| 15 | * |
| 16 | * + changed name to ibmtr.c in anticipation of other tr boards. |
| 17 | * + changed reset code and adapter open code. |
| 18 | * + added SAP open code. |
| 19 | * + a first attempt to write interrupt, transmit and receive routines. |
| 20 | * |
| 21 | * Changes by David W. Morris (dwm@shell.portal.com) : |
| 22 | * 941003 dwm: - Restructure tok_probe for multiple adapters, devices. |
| 23 | * + Add comments, misc reorg for clarity. |
| 24 | * + Flatten interrupt handler levels. |
| 25 | * |
| 26 | * Changes by Farzad Farid (farzy@zen.via.ecp.fr) |
| 27 | * and Pascal Andre (andre@chimay.via.ecp.fr) (March 9 1995) : |
| 28 | * + multi ring support clean up. |
| 29 | * + RFC1042 compliance enhanced. |
| 30 | * |
| 31 | * Changes by Pascal Andre (andre@chimay.via.ecp.fr) (September 7 1995) : |
| 32 | * + bug correction in tr_tx |
| 33 | * + removed redundant information display |
| 34 | * + some code reworking |
| 35 | * |
| 36 | * Changes by Michel Lespinasse (walken@via.ecp.fr), |
| 37 | * Yann Doussot (doussot@via.ecp.fr) and Pascal Andre (andre@via.ecp.fr) |
| 38 | * (February 18, 1996) : |
| 39 | * + modified shared memory and mmio access port the driver to |
| 40 | * alpha platform (structure access -> readb/writeb) |
| 41 | * |
| 42 | * Changes by Steve Kipisz (bungy@ibm.net or kipisz@vnet.ibm.com) |
| 43 | * (January 18 1996): |
| 44 | * + swapped WWOR and WWCR in ibmtr.h |
| 45 | * + moved some init code from tok_probe into trdev_init. The |
| 46 | * PCMCIA code can call trdev_init to complete initializing |
| 47 | * the driver. |
| 48 | * + added -DPCMCIA to support PCMCIA |
| 49 | * + detecting PCMCIA Card Removal in interrupt handler. If |
| 50 | * ISRP is FF, then a PCMCIA card has been removed |
| 51 | * 10/2000 Burt needed a new method to avoid crashing the OS |
| 52 | * |
| 53 | * Changes by Paul Norton (pnorton@cts.com) : |
| 54 | * + restructured the READ.LOG logic to prevent the transmit SRB |
| 55 | * from being rudely overwritten before the transmit cycle is |
| 56 | * complete. (August 15 1996) |
| 57 | * + completed multiple adapter support. (November 20 1996) |
| 58 | * + implemented csum_partial_copy in tr_rx and increased receive |
| 59 | * buffer size and count. Minor fixes. (March 15, 1997) |
| 60 | * |
| 61 | * Changes by Christopher Turcksin <wabbit@rtfc.demon.co.uk> |
| 62 | * + Now compiles ok as a module again. |
| 63 | * |
| 64 | * Changes by Paul Norton (pnorton@ieee.org) : |
| 65 | * + moved the header manipulation code in tr_tx and tr_rx to |
| 66 | * net/802/tr.c. (July 12 1997) |
| 67 | * + add retry and timeout on open if cable disconnected. (May 5 1998) |
| 68 | * + lifted 2000 byte mtu limit. now depends on shared-RAM size. |
| 69 | * May 25 1998) |
| 70 | * + can't allocate 2k recv buff at 8k shared-RAM. (20 October 1998) |
| 71 | * |
| 72 | * Changes by Joel Sloan (jjs@c-me.com) : |
| 73 | * + disable verbose debug messages by default - to enable verbose |
| 74 | * debugging, edit the IBMTR_DEBUG_MESSAGES define below |
| 75 | * |
| 76 | * Changes by Mike Phillips <phillim@amtrak.com> : |
| 77 | * + Added extra #ifdef's to work with new PCMCIA Token Ring Code. |
| 78 | * The PCMCIA code now just sets up the card so it can be recognized |
| 79 | * by ibmtr_probe. Also checks allocated memory vs. on-board memory |
| 80 | * for correct figure to use. |
| 81 | * |
| 82 | * Changes by Tim Hockin (thockin@isunix.it.ilstu.edu) : |
| 83 | * + added spinlocks for SMP sanity (10 March 1999) |
| 84 | * |
| 85 | * Changes by Jochen Friedrich to enable RFC1469 Option 2 multicasting |
| 86 | * i.e. using functional address C0 00 00 04 00 00 to transmit and |
| 87 | * receive multicast packets. |
| 88 | * |
| 89 | * Changes by Mike Sullivan (based on original sram patch by Dave Grothe |
| 90 | * to support windowing into on adapter shared ram. |
| 91 | * i.e. Use LANAID to setup a PnP configuration with 16K RAM. Paging |
| 92 | * will shift this 16K window over the entire available shared RAM. |
| 93 | * |
| 94 | * Changes by Peter De Schrijver (p2@mind.be) : |
| 95 | * + fixed a problem with PCMCIA card removal |
| 96 | * |
| 97 | * Change by Mike Sullivan et al.: |
| 98 | * + added turbo card support. No need to use lanaid to configure |
| 99 | * the adapter into isa compatiblity mode. |
| 100 | * |
| 101 | * Changes by Burt Silverman to allow the computer to behave nicely when |
| 102 | * a cable is pulled or not in place, or a PCMCIA card is removed hot. |
| 103 | */ |
| 104 | |
| 105 | /* change the define of IBMTR_DEBUG_MESSAGES to a nonzero value |
| 106 | in the event that chatty debug messages are desired - jjs 12/30/98 */ |
| 107 | |
| 108 | #define IBMTR_DEBUG_MESSAGES 0 |
| 109 | |
| 110 | #include <linux/module.h> |
| 111 | |
| 112 | #ifdef PCMCIA /* required for ibmtr_cs.c to build */ |
| 113 | #undef MODULE /* yes, really */ |
| 114 | #undef ENABLE_PAGING |
| 115 | #else |
| 116 | #define ENABLE_PAGING 1 |
| 117 | #endif |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* changes the output format of driver initialization */ |
| 120 | #define TR_VERBOSE 0 |
| 121 | |
| 122 | /* some 95 OS send many non UI frame; this allow removing the warning */ |
| 123 | #define TR_FILTERNONUI 1 |
| 124 | |
| 125 | #include <linux/ioport.h> |
| 126 | #include <linux/netdevice.h> |
| 127 | #include <linux/ip.h> |
| 128 | #include <linux/trdevice.h> |
| 129 | #include <linux/ibmtr.h> |
| 130 | |
| 131 | #include <net/checksum.h> |
| 132 | |
| 133 | #include <asm/io.h> |
| 134 | |
| 135 | #define DPRINTK(format, args...) printk("%s: " format, dev->name , ## args) |
| 136 | #define DPRINTD(format, args...) DummyCall("%s: " format, dev->name , ## args) |
| 137 | |
| 138 | /* version and credits */ |
| 139 | #ifndef PCMCIA |
Andrew Morton | 6d2cdb4 | 2006-08-14 23:00:05 -0700 | [diff] [blame] | 140 | static char version[] __devinitdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | "\nibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n" |
| 142 | " v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n" |
| 143 | " v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n" |
| 144 | " v2.2.1 02/08/00 Mike Sullivan <sullivam@us.ibm.com>\n" |
| 145 | " v2.2.2 07/27/00 Burt Silverman <burts@us.ibm.com>\n" |
| 146 | " v2.4.0 03/01/01 Mike Sullivan <sullivan@us.ibm.com>\n"; |
| 147 | #endif |
| 148 | |
| 149 | /* this allows displaying full adapter information */ |
| 150 | |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 151 | static char *channel_def[] __devinitdata = { "ISA", "MCA", "ISA P&P" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | static char pcchannelid[] __devinitdata = { |
| 154 | 0x05, 0x00, 0x04, 0x09, |
| 155 | 0x04, 0x03, 0x04, 0x0f, |
| 156 | 0x03, 0x06, 0x03, 0x01, |
| 157 | 0x03, 0x01, 0x03, 0x00, |
| 158 | 0x03, 0x09, 0x03, 0x09, |
| 159 | 0x03, 0x00, 0x02, 0x00 |
| 160 | }; |
| 161 | |
| 162 | static char mcchannelid[] __devinitdata = { |
| 163 | 0x04, 0x0d, 0x04, 0x01, |
| 164 | 0x05, 0x02, 0x05, 0x03, |
| 165 | 0x03, 0x06, 0x03, 0x03, |
| 166 | 0x05, 0x08, 0x03, 0x04, |
| 167 | 0x03, 0x05, 0x03, 0x01, |
| 168 | 0x03, 0x08, 0x02, 0x00 |
| 169 | }; |
| 170 | |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 171 | static char __devinit *adapter_def(char type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
| 173 | switch (type) { |
| 174 | case 0xF: return "PC Adapter | PC Adapter II | Adapter/A"; |
| 175 | case 0xE: return "16/4 Adapter | 16/4 Adapter/A (long)"; |
| 176 | case 0xD: return "16/4 Adapter/A (short) | 16/4 ISA-16 Adapter"; |
| 177 | case 0xC: return "Auto 16/4 Adapter"; |
| 178 | default: return "adapter (unknown type)"; |
| 179 | }; |
| 180 | }; |
| 181 | |
| 182 | #define TRC_INIT 0x01 /* Trace initialization & PROBEs */ |
| 183 | #define TRC_INITV 0x02 /* verbose init trace points */ |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 184 | static unsigned char ibmtr_debug_trace = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | static int ibmtr_probe1(struct net_device *dev, int ioaddr); |
| 187 | static unsigned char get_sram_size(struct tok_info *adapt_info); |
| 188 | static int trdev_init(struct net_device *dev); |
| 189 | static int tok_open(struct net_device *dev); |
| 190 | static int tok_init_card(struct net_device *dev); |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 191 | static void tok_open_adapter(unsigned long dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | static void open_sap(unsigned char type, struct net_device *dev); |
| 193 | static void tok_set_multicast_list(struct net_device *dev); |
| 194 | static int tok_send_packet(struct sk_buff *skb, struct net_device *dev); |
| 195 | static int tok_close(struct net_device *dev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 196 | static irqreturn_t tok_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | static void initial_tok_int(struct net_device *dev); |
| 198 | static void tr_tx(struct net_device *dev); |
| 199 | static void tr_rx(struct net_device *dev); |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 200 | static void ibmtr_reset_timer(struct timer_list*tmr,struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static void tok_rerun(unsigned long dev_addr); |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 202 | static void ibmtr_readlog(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | static struct net_device_stats *tok_get_stats(struct net_device *dev); |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 204 | static int ibmtr_change_mtu(struct net_device *dev, int mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | static void find_turbo_adapters(int *iolist); |
| 206 | |
| 207 | static int ibmtr_portlist[IBMTR_MAX_ADAPTERS+1] __devinitdata = { |
| 208 | 0xa20, 0xa24, 0, 0, 0 |
| 209 | }; |
| 210 | static int __devinitdata turbo_io[IBMTR_MAX_ADAPTERS] = {0}; |
| 211 | static int __devinitdata turbo_irq[IBMTR_MAX_ADAPTERS] = {0}; |
| 212 | static int __devinitdata turbo_searched = 0; |
| 213 | |
| 214 | #ifndef PCMCIA |
Andrew Morton | 6d2cdb4 | 2006-08-14 23:00:05 -0700 | [diff] [blame] | 215 | static __u32 ibmtr_mem_base __devinitdata = 0xd0000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | #endif |
| 217 | |
| 218 | static void __devinit PrtChanID(char *pcid, short stride) |
| 219 | { |
| 220 | short i, j; |
| 221 | for (i = 0, j = 0; i < 24; i++, j += stride) |
| 222 | printk("%1x", ((int) pcid[j]) & 0x0f); |
| 223 | printk("\n"); |
| 224 | } |
| 225 | |
| 226 | static void __devinit HWPrtChanID(void __iomem *pcid, short stride) |
| 227 | { |
| 228 | short i, j; |
| 229 | for (i = 0, j = 0; i < 24; i++, j += stride) |
| 230 | printk("%1x", ((int) readb(pcid + j)) & 0x0f); |
| 231 | printk("\n"); |
| 232 | } |
| 233 | |
| 234 | /* We have to ioremap every checked address, because isa_readb is |
| 235 | * going away. |
| 236 | */ |
| 237 | |
| 238 | static void __devinit find_turbo_adapters(int *iolist) |
| 239 | { |
| 240 | int ram_addr; |
| 241 | int index=0; |
| 242 | void __iomem *chanid; |
| 243 | int found_turbo=0; |
| 244 | unsigned char *tchanid, ctemp; |
| 245 | int i, j; |
| 246 | unsigned long jif; |
| 247 | void __iomem *ram_mapped ; |
| 248 | |
| 249 | if (turbo_searched == 1) return; |
| 250 | turbo_searched=1; |
| 251 | for (ram_addr=0xC0000; ram_addr < 0xE0000; ram_addr+=0x2000) { |
| 252 | |
| 253 | __u32 intf_tbl=0; |
| 254 | |
| 255 | found_turbo=1; |
| 256 | ram_mapped = ioremap((u32)ram_addr,0x1fff) ; |
| 257 | if (ram_mapped==NULL) |
| 258 | continue ; |
| 259 | chanid=(CHANNEL_ID + ram_mapped); |
| 260 | tchanid=pcchannelid; |
| 261 | ctemp=readb(chanid) & 0x0f; |
| 262 | if (ctemp != *tchanid) continue; |
| 263 | for (i=2,j=1; i<=46; i=i+2,j++) { |
| 264 | if ((readb(chanid+i) & 0x0f) != tchanid[j]){ |
| 265 | found_turbo=0; |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | if (!found_turbo) continue; |
| 270 | |
| 271 | writeb(0x90, ram_mapped+0x1E01); |
| 272 | for(i=2; i<0x0f; i++) { |
| 273 | writeb(0x00, ram_mapped+0x1E01+i); |
| 274 | } |
| 275 | writeb(0x00, ram_mapped+0x1E01); |
| 276 | for(jif=jiffies+TR_BUSY_INTERVAL; time_before_eq(jiffies,jif);); |
| 277 | intf_tbl=ntohs(readw(ram_mapped+ACA_OFFSET+ACA_RW+WRBR_EVEN)); |
| 278 | if (intf_tbl) { |
| 279 | #if IBMTR_DEBUG_MESSAGES |
| 280 | printk("ibmtr::find_turbo_adapters, Turbo found at " |
| 281 | "ram_addr %x\n",ram_addr); |
| 282 | printk("ibmtr::find_turbo_adapters, interface_table "); |
| 283 | for(i=0; i<6; i++) { |
| 284 | printk("%x:",readb(ram_addr+intf_tbl+i)); |
| 285 | } |
| 286 | printk("\n"); |
| 287 | #endif |
| 288 | turbo_io[index]=ntohs(readw(ram_mapped+intf_tbl+4)); |
| 289 | turbo_irq[index]=readb(ram_mapped+intf_tbl+3); |
| 290 | outb(0, turbo_io[index] + ADAPTRESET); |
| 291 | for(jif=jiffies+TR_RST_TIME;time_before_eq(jiffies,jif);); |
| 292 | outb(0, turbo_io[index] + ADAPTRESETREL); |
| 293 | index++; |
| 294 | continue; |
| 295 | } |
| 296 | #if IBMTR_DEBUG_MESSAGES |
| 297 | printk("ibmtr::find_turbo_adapters, ibmtr card found at" |
| 298 | " %x but not a Turbo model\n",ram_addr); |
| 299 | #endif |
| 300 | iounmap(ram_mapped) ; |
| 301 | } /* for */ |
| 302 | for(i=0; i<IBMTR_MAX_ADAPTERS; i++) { |
| 303 | if(!turbo_io[i]) break; |
| 304 | for (j=0; j<IBMTR_MAX_ADAPTERS; j++) { |
| 305 | if ( iolist[j] && iolist[j] != turbo_io[i]) continue; |
| 306 | iolist[j]=turbo_io[i]; |
| 307 | break; |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | static void ibmtr_cleanup_card(struct net_device *dev) |
| 313 | { |
| 314 | if (dev->base_addr) { |
| 315 | outb(0,dev->base_addr+ADAPTRESET); |
| 316 | |
Nishanth Aravamudan | 3173c89 | 2005-09-11 02:09:55 -0700 | [diff] [blame] | 317 | schedule_timeout_uninterruptible(TR_RST_TIME); /* wait 50ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | outb(0,dev->base_addr+ADAPTRESETREL); |
| 320 | } |
| 321 | |
| 322 | #ifndef PCMCIA |
| 323 | free_irq(dev->irq, dev); |
| 324 | release_region(dev->base_addr, IBMTR_IO_EXTENT); |
| 325 | |
| 326 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 327 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | iounmap(ti->mmio); |
| 329 | iounmap(ti->sram_virt); |
| 330 | } |
| 331 | #endif |
| 332 | } |
| 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /**************************************************************************** |
| 335 | * ibmtr_probe(): Routine specified in the network device structure |
| 336 | * to probe for an IBM Token Ring Adapter. Routine outline: |
| 337 | * I. Interrogate hardware to determine if an adapter exists |
| 338 | * and what the speeds and feeds are |
| 339 | * II. Setup data structures to control execution based upon |
| 340 | * adapter characteristics. |
| 341 | * |
| 342 | * We expect ibmtr_probe to be called once for each device entry |
| 343 | * which references it. |
| 344 | ****************************************************************************/ |
| 345 | |
Al Viro | abf0437 | 2007-03-14 09:04:21 +0000 | [diff] [blame] | 346 | static int __devinit ibmtr_probe(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
| 348 | int i; |
| 349 | int base_addr = dev->base_addr; |
| 350 | |
| 351 | if (base_addr && base_addr <= 0x1ff) /* Don't probe at all. */ |
| 352 | return -ENXIO; |
| 353 | if (base_addr > 0x1ff) { /* Check a single specified location. */ |
| 354 | if (!ibmtr_probe1(dev, base_addr)) return 0; |
| 355 | return -ENODEV; |
| 356 | } |
| 357 | find_turbo_adapters(ibmtr_portlist); |
| 358 | for (i = 0; ibmtr_portlist[i]; i++) { |
| 359 | int ioaddr = ibmtr_portlist[i]; |
| 360 | |
| 361 | if (!ibmtr_probe1(dev, ioaddr)) return 0; |
| 362 | } |
| 363 | return -ENODEV; |
| 364 | } |
| 365 | |
Al Viro | abf0437 | 2007-03-14 09:04:21 +0000 | [diff] [blame] | 366 | int __devinit ibmtr_probe_card(struct net_device *dev) |
Ralf Baechle | 82c00b6 | 2007-03-08 12:53:07 +0000 | [diff] [blame] | 367 | { |
| 368 | int err = ibmtr_probe(dev); |
| 369 | if (!err) { |
| 370 | err = register_netdev(dev); |
| 371 | if (err) |
| 372 | ibmtr_cleanup_card(dev); |
| 373 | } |
| 374 | return err; |
| 375 | } |
| 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | /*****************************************************************************/ |
| 378 | |
| 379 | static int __devinit ibmtr_probe1(struct net_device *dev, int PIOaddr) |
| 380 | { |
| 381 | |
| 382 | unsigned char segment, intr=0, irq=0, i, j, cardpresent=NOTOK, temp=0; |
| 383 | void __iomem * t_mmio = NULL; |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 384 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | void __iomem *cd_chanid; |
| 386 | unsigned char *tchanid, ctemp; |
| 387 | #ifndef PCMCIA |
| 388 | unsigned char t_irq=0; |
| 389 | unsigned long timeout; |
| 390 | static int version_printed; |
| 391 | #endif |
| 392 | |
| 393 | /* Query the adapter PIO base port which will return |
| 394 | * indication of where MMIO was placed. We also have a |
| 395 | * coded interrupt number. |
| 396 | */ |
| 397 | segment = inb(PIOaddr); |
| 398 | if (segment < 0x40 || segment > 0xe0) { |
| 399 | /* Out of range values so we'll assume non-existent IO device |
| 400 | * but this is not necessarily a problem, esp if a turbo |
| 401 | * adapter is being used. */ |
| 402 | #if IBMTR_DEBUG_MESSAGES |
| 403 | DPRINTK("ibmtr_probe1(): unhappy that inb(0x%X) == 0x%X, " |
| 404 | "Hardware Problem?\n",PIOaddr,segment); |
| 405 | #endif |
| 406 | return -ENODEV; |
| 407 | } |
| 408 | /* |
| 409 | * Compute the linear base address of the MMIO area |
| 410 | * as LINUX doesn't care about segments |
| 411 | */ |
| 412 | t_mmio = ioremap(((__u32) (segment & 0xfc) << 11) + 0x80000,2048); |
| 413 | if (!t_mmio) { |
| 414 | DPRINTK("Cannot remap mmiobase memory area") ; |
| 415 | return -ENODEV ; |
| 416 | } |
| 417 | intr = segment & 0x03; /* low bits is coded interrupt # */ |
| 418 | if (ibmtr_debug_trace & TRC_INIT) |
| 419 | DPRINTK("PIOaddr: %4hx seg/intr: %2x mmio base: %p intr: %d\n" |
| 420 | , PIOaddr, (int) segment, t_mmio, (int) intr); |
| 421 | |
| 422 | /* |
| 423 | * Now we will compare expected 'channelid' strings with |
| 424 | * what we is there to learn of ISA/MCA or not TR card |
| 425 | */ |
| 426 | #ifdef PCMCIA |
| 427 | iounmap(t_mmio); |
| 428 | t_mmio = ti->mmio; /*BMS to get virtual address */ |
| 429 | irq = ti->irq; /*BMS to display the irq! */ |
| 430 | #endif |
| 431 | cd_chanid = (CHANNEL_ID + t_mmio); /* for efficiency */ |
| 432 | tchanid = pcchannelid; |
| 433 | cardpresent = TR_ISA; /* try ISA */ |
| 434 | |
| 435 | /* Suboptimize knowing first byte different */ |
| 436 | ctemp = readb(cd_chanid) & 0x0f; |
| 437 | if (ctemp != *tchanid) { /* NOT ISA card, try MCA */ |
| 438 | tchanid = mcchannelid; |
| 439 | cardpresent = TR_MCA; |
| 440 | if (ctemp != *tchanid) /* Neither ISA nor MCA */ |
| 441 | cardpresent = NOTOK; |
| 442 | } |
| 443 | if (cardpresent != NOTOK) { |
| 444 | /* Know presumed type, try rest of ID */ |
| 445 | for (i = 2, j = 1; i <= 46; i = i + 2, j++) { |
| 446 | if( (readb(cd_chanid+i)&0x0f) == tchanid[j]) continue; |
| 447 | /* match failed, not TR card */ |
| 448 | cardpresent = NOTOK; |
| 449 | break; |
| 450 | } |
| 451 | } |
| 452 | /* |
| 453 | * If we have an ISA board check for the ISA P&P version, |
| 454 | * as it has different IRQ settings |
| 455 | */ |
| 456 | if (cardpresent == TR_ISA && (readb(AIPFID + t_mmio) == 0x0e)) |
| 457 | cardpresent = TR_ISAPNP; |
| 458 | if (cardpresent == NOTOK) { /* "channel_id" did not match, report */ |
| 459 | if (!(ibmtr_debug_trace & TRC_INIT)) { |
| 460 | #ifndef PCMCIA |
| 461 | iounmap(t_mmio); |
| 462 | #endif |
| 463 | return -ENODEV; |
| 464 | } |
| 465 | DPRINTK( "Channel ID string not found for PIOaddr: %4hx\n", |
| 466 | PIOaddr); |
| 467 | DPRINTK("Expected for ISA: "); |
| 468 | PrtChanID(pcchannelid, 1); |
| 469 | DPRINTK(" found: "); |
| 470 | /* BMS Note that this can be misleading, when hardware is flaky, because you |
| 471 | are reading it a second time here. So with my flaky hardware, I'll see my- |
| 472 | self in this block, with the HW ID matching the ISA ID exactly! */ |
| 473 | HWPrtChanID(cd_chanid, 2); |
| 474 | DPRINTK("Expected for MCA: "); |
| 475 | PrtChanID(mcchannelid, 1); |
| 476 | } |
| 477 | /* Now, setup some of the pl0 buffers for this driver.. */ |
| 478 | /* If called from PCMCIA, it is already set up, so no need to |
| 479 | waste the memory, just use the existing structure */ |
| 480 | #ifndef PCMCIA |
| 481 | ti->mmio = t_mmio; |
| 482 | for (i = 0; i < IBMTR_MAX_ADAPTERS; i++) { |
| 483 | if (turbo_io[i] != PIOaddr) |
| 484 | continue; |
| 485 | #if IBMTR_DEBUG_MESSAGES |
| 486 | printk("ibmtr::tr_probe1, setting PIOaddr %x to Turbo\n", |
| 487 | PIOaddr); |
| 488 | #endif |
| 489 | ti->turbo = 1; |
| 490 | t_irq = turbo_irq[i]; |
| 491 | } |
| 492 | #endif /* !PCMCIA */ |
| 493 | ti->readlog_pending = 0; |
| 494 | init_waitqueue_head(&ti->wait_for_reset); |
| 495 | |
| 496 | /* if PCMCIA, the card can be recognized as either TR_ISA or TR_ISAPNP |
| 497 | * depending which card is inserted. */ |
| 498 | |
| 499 | #ifndef PCMCIA |
| 500 | switch (cardpresent) { |
| 501 | case TR_ISA: |
| 502 | if (intr == 0) irq = 9; /* irq2 really is irq9 */ |
| 503 | if (intr == 1) irq = 3; |
| 504 | if (intr == 2) irq = 6; |
| 505 | if (intr == 3) irq = 7; |
| 506 | ti->adapter_int_enable = PIOaddr + ADAPTINTREL; |
| 507 | break; |
| 508 | case TR_MCA: |
| 509 | if (intr == 0) irq = 9; |
| 510 | if (intr == 1) irq = 3; |
| 511 | if (intr == 2) irq = 10; |
| 512 | if (intr == 3) irq = 11; |
| 513 | ti->global_int_enable = 0; |
| 514 | ti->adapter_int_enable = 0; |
| 515 | ti->sram_phys=(__u32)(inb(PIOaddr+ADAPTRESETREL) & 0xfe) << 12; |
| 516 | break; |
| 517 | case TR_ISAPNP: |
| 518 | if (!t_irq) { |
| 519 | if (intr == 0) irq = 9; |
| 520 | if (intr == 1) irq = 3; |
| 521 | if (intr == 2) irq = 10; |
| 522 | if (intr == 3) irq = 11; |
| 523 | } else |
| 524 | irq=t_irq; |
| 525 | timeout = jiffies + TR_SPIN_INTERVAL; |
| 526 | while (!readb(ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN)){ |
| 527 | if (!time_after(jiffies, timeout)) continue; |
| 528 | DPRINTK( "Hardware timeout during initialization.\n"); |
| 529 | iounmap(t_mmio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | return -ENODEV; |
| 531 | } |
| 532 | ti->sram_phys = |
| 533 | ((__u32)readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_EVEN)<<12); |
| 534 | ti->adapter_int_enable = PIOaddr + ADAPTINTREL; |
| 535 | break; |
| 536 | } /*end switch (cardpresent) */ |
| 537 | #endif /*not PCMCIA */ |
| 538 | |
| 539 | if (ibmtr_debug_trace & TRC_INIT) { /* just report int */ |
| 540 | DPRINTK("irq=%d", irq); |
| 541 | printk(", sram_phys=0x%x", ti->sram_phys); |
| 542 | if(ibmtr_debug_trace&TRC_INITV){ /* full chat in verbose only */ |
| 543 | DPRINTK(", ti->mmio=%p", ti->mmio); |
| 544 | printk(", segment=%02X", segment); |
| 545 | } |
| 546 | printk(".\n"); |
| 547 | } |
| 548 | |
| 549 | /* Get hw address of token ring card */ |
| 550 | j = 0; |
| 551 | for (i = 0; i < 0x18; i = i + 2) { |
| 552 | /* technical reference states to do this */ |
| 553 | temp = readb(ti->mmio + AIP + i) & 0x0f; |
| 554 | ti->hw_address[j] = temp; |
| 555 | if (j & 1) |
| 556 | dev->dev_addr[(j / 2)] = |
| 557 | ti->hw_address[j]+ (ti->hw_address[j - 1] << 4); |
| 558 | ++j; |
| 559 | } |
| 560 | /* get Adapter type: 'F' = Adapter/A, 'E' = 16/4 Adapter II,... */ |
| 561 | ti->adapter_type = readb(ti->mmio + AIPADAPTYPE); |
| 562 | |
| 563 | /* get Data Rate: F=4Mb, E=16Mb, D=4Mb & 16Mb ?? */ |
| 564 | ti->data_rate = readb(ti->mmio + AIPDATARATE); |
| 565 | |
| 566 | /* Get Early Token Release support?: F=no, E=4Mb, D=16Mb, C=4&16Mb */ |
| 567 | ti->token_release = readb(ti->mmio + AIPEARLYTOKEN); |
| 568 | |
| 569 | /* How much shared RAM is on adapter ? */ |
| 570 | if (ti->turbo) { |
| 571 | ti->avail_shared_ram=127; |
| 572 | } else { |
| 573 | ti->avail_shared_ram = get_sram_size(ti);/*in 512 byte units */ |
| 574 | } |
| 575 | /* We need to set or do a bunch of work here based on previous results*/ |
| 576 | /* Support paging? What sizes?: F=no, E=16k, D=32k, C=16 & 32k */ |
| 577 | ti->shared_ram_paging = readb(ti->mmio + AIPSHRAMPAGE); |
| 578 | |
| 579 | /* Available DHB 4Mb size: F=2048, E=4096, D=4464 */ |
| 580 | switch (readb(ti->mmio + AIP4MBDHB)) { |
| 581 | case 0xe: ti->dhb_size4mb = 4096; break; |
| 582 | case 0xd: ti->dhb_size4mb = 4464; break; |
| 583 | default: ti->dhb_size4mb = 2048; break; |
| 584 | } |
| 585 | |
| 586 | /* Available DHB 16Mb size: F=2048, E=4096, D=8192, C=16384, B=17960 */ |
| 587 | switch (readb(ti->mmio + AIP16MBDHB)) { |
| 588 | case 0xe: ti->dhb_size16mb = 4096; break; |
| 589 | case 0xd: ti->dhb_size16mb = 8192; break; |
| 590 | case 0xc: ti->dhb_size16mb = 16384; break; |
| 591 | case 0xb: ti->dhb_size16mb = 17960; break; |
| 592 | default: ti->dhb_size16mb = 2048; break; |
| 593 | } |
| 594 | |
| 595 | /* We must figure out how much shared memory space this adapter |
| 596 | * will occupy so that if there are two adapters we can fit both |
| 597 | * in. Given a choice, we will limit this adapter to 32K. The |
| 598 | * maximum space will will use for two adapters is 64K so if the |
| 599 | * adapter we are working on demands 64K (it also doesn't support |
| 600 | * paging), then only one adapter can be supported. |
| 601 | */ |
| 602 | |
| 603 | /* |
| 604 | * determine how much of total RAM is mapped into PC space |
| 605 | */ |
| 606 | ti->mapped_ram_size= /*sixteen to onehundredtwentyeight 512byte blocks*/ |
| 607 | 1<< ((readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03) + 4); |
| 608 | ti->page_mask = 0; |
| 609 | if (ti->turbo) ti->page_mask=0xf0; |
| 610 | else if (ti->shared_ram_paging == 0xf); /* No paging in adapter */ |
| 611 | else { |
| 612 | #ifdef ENABLE_PAGING |
| 613 | unsigned char pg_size = 0; |
| 614 | /* BMS: page size: PCMCIA, use configuration register; |
| 615 | ISAPNP, use LANAIDC config tool from www.ibm.com */ |
| 616 | switch (ti->shared_ram_paging) { |
| 617 | case 0xf: |
| 618 | break; |
| 619 | case 0xe: |
| 620 | ti->page_mask = (ti->mapped_ram_size == 32) ? 0xc0 : 0; |
| 621 | pg_size = 32; /* 16KB page size */ |
| 622 | break; |
| 623 | case 0xd: |
| 624 | ti->page_mask = (ti->mapped_ram_size == 64) ? 0x80 : 0; |
| 625 | pg_size = 64; /* 32KB page size */ |
| 626 | break; |
| 627 | case 0xc: |
| 628 | switch (ti->mapped_ram_size) { |
| 629 | case 32: |
| 630 | ti->page_mask = 0xc0; |
| 631 | pg_size = 32; |
| 632 | break; |
| 633 | case 64: |
| 634 | ti->page_mask = 0x80; |
| 635 | pg_size = 64; |
| 636 | break; |
| 637 | } |
| 638 | break; |
| 639 | default: |
| 640 | DPRINTK("Unknown shared ram paging info %01X\n", |
| 641 | ti->shared_ram_paging); |
| 642 | iounmap(t_mmio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | return -ENODEV; |
| 644 | break; |
| 645 | } /*end switch shared_ram_paging */ |
| 646 | |
| 647 | if (ibmtr_debug_trace & TRC_INIT) |
| 648 | DPRINTK("Shared RAM paging code: %02X, " |
| 649 | "mapped RAM size: %dK, shared RAM size: %dK, " |
| 650 | "page mask: %02X\n:", |
| 651 | ti->shared_ram_paging, ti->mapped_ram_size / 2, |
| 652 | ti->avail_shared_ram / 2, ti->page_mask); |
| 653 | #endif /*ENABLE_PAGING */ |
| 654 | } |
| 655 | |
| 656 | #ifndef PCMCIA |
| 657 | /* finish figuring the shared RAM address */ |
| 658 | if (cardpresent == TR_ISA) { |
| 659 | static __u32 ram_bndry_mask[] = |
| 660 | { 0xffffe000, 0xffffc000, 0xffff8000, 0xffff0000 }; |
| 661 | __u32 new_base, rrr_32, chk_base, rbm; |
| 662 | |
| 663 | rrr_32=readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03; |
| 664 | rbm = ram_bndry_mask[rrr_32]; |
| 665 | new_base = (ibmtr_mem_base + (~rbm)) & rbm;/* up to boundary */ |
| 666 | chk_base = new_base + (ti->mapped_ram_size << 9); |
| 667 | if (chk_base > (ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE)) { |
| 668 | DPRINTK("Shared RAM for this adapter (%05x) exceeds " |
| 669 | "driver limit (%05x), adapter not started.\n", |
| 670 | chk_base, ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE); |
| 671 | iounmap(t_mmio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | return -ENODEV; |
| 673 | } else { /* seems cool, record what we have figured out */ |
| 674 | ti->sram_base = new_base >> 12; |
| 675 | ibmtr_mem_base = chk_base; |
| 676 | } |
| 677 | } |
| 678 | else ti->sram_base = ti->sram_phys >> 12; |
| 679 | |
| 680 | /* The PCMCIA has already got the interrupt line and the io port, |
| 681 | so no chance of anybody else getting it - MLP */ |
| 682 | if (request_irq(dev->irq = irq, &tok_interrupt, 0, "ibmtr", dev) != 0) { |
| 683 | DPRINTK("Could not grab irq %d. Halting Token Ring driver.\n", |
| 684 | irq); |
| 685 | iounmap(t_mmio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | return -ENODEV; |
| 687 | } |
| 688 | /*?? Now, allocate some of the PIO PORTs for this driver.. */ |
| 689 | /* record PIOaddr range as busy */ |
| 690 | if (!request_region(PIOaddr, IBMTR_IO_EXTENT, "ibmtr")) { |
| 691 | DPRINTK("Could not grab PIO range. Halting driver.\n"); |
| 692 | free_irq(dev->irq, dev); |
| 693 | iounmap(t_mmio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | return -EBUSY; |
| 695 | } |
| 696 | |
| 697 | if (!version_printed++) { |
| 698 | printk(version); |
| 699 | } |
| 700 | #endif /* !PCMCIA */ |
| 701 | DPRINTK("%s %s found\n", |
| 702 | channel_def[cardpresent - 1], adapter_def(ti->adapter_type)); |
| 703 | DPRINTK("using irq %d, PIOaddr %hx, %dK shared RAM.\n", |
| 704 | irq, PIOaddr, ti->mapped_ram_size / 2); |
| 705 | DPRINTK("Hardware address : %02X:%02X:%02X:%02X:%02X:%02X\n", |
| 706 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], |
| 707 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); |
| 708 | if (ti->page_mask) |
| 709 | DPRINTK("Shared RAM paging enabled. " |
| 710 | "Page size: %uK Shared Ram size %dK\n", |
| 711 | ((ti->page_mask^0xff)+1) >>2, ti->avail_shared_ram / 2); |
| 712 | else |
| 713 | DPRINTK("Shared RAM paging disabled. ti->page_mask %x\n", |
| 714 | ti->page_mask); |
| 715 | |
| 716 | /* Calculate the maximum DHB we can use */ |
| 717 | /* two cases where avail_shared_ram doesn't equal mapped_ram_size: |
| 718 | 1. avail_shared_ram is 127 but mapped_ram_size is 128 (typical) |
| 719 | 2. user has configured adapter for less than avail_shared_ram |
| 720 | but is not using paging (she should use paging, I believe) |
| 721 | */ |
| 722 | if (!ti->page_mask) { |
| 723 | ti->avail_shared_ram= |
| 724 | min(ti->mapped_ram_size,ti->avail_shared_ram); |
| 725 | } |
| 726 | |
| 727 | switch (ti->avail_shared_ram) { |
| 728 | case 16: /* 8KB shared RAM */ |
| 729 | ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)2048); |
| 730 | ti->rbuf_len4 = 1032; |
| 731 | ti->rbuf_cnt4=2; |
| 732 | ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)2048); |
| 733 | ti->rbuf_len16 = 1032; |
| 734 | ti->rbuf_cnt16=2; |
| 735 | break; |
| 736 | case 32: /* 16KB shared RAM */ |
| 737 | ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464); |
| 738 | ti->rbuf_len4 = 1032; |
| 739 | ti->rbuf_cnt4=4; |
| 740 | ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)4096); |
| 741 | ti->rbuf_len16 = 1032; /*1024 usable */ |
| 742 | ti->rbuf_cnt16=4; |
| 743 | break; |
| 744 | case 64: /* 32KB shared RAM */ |
| 745 | ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464); |
| 746 | ti->rbuf_len4 = 1032; |
| 747 | ti->rbuf_cnt4=6; |
| 748 | ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)10240); |
| 749 | ti->rbuf_len16 = 1032; |
| 750 | ti->rbuf_cnt16=6; |
| 751 | break; |
| 752 | case 127: /* 63.5KB shared RAM */ |
| 753 | ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464); |
| 754 | ti->rbuf_len4 = 1032; |
| 755 | ti->rbuf_cnt4=6; |
| 756 | ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)16384); |
| 757 | ti->rbuf_len16 = 1032; |
| 758 | ti->rbuf_cnt16=16; |
| 759 | break; |
| 760 | case 128: /* 64KB shared RAM */ |
| 761 | ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464); |
| 762 | ti->rbuf_len4 = 1032; |
| 763 | ti->rbuf_cnt4=6; |
| 764 | ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)17960); |
| 765 | ti->rbuf_len16 = 1032; |
| 766 | ti->rbuf_cnt16=16; |
| 767 | break; |
| 768 | default: |
| 769 | ti->dhb_size4mb = 2048; |
| 770 | ti->rbuf_len4 = 1032; |
| 771 | ti->rbuf_cnt4=2; |
| 772 | ti->dhb_size16mb = 2048; |
| 773 | ti->rbuf_len16 = 1032; |
| 774 | ti->rbuf_cnt16=2; |
| 775 | break; |
| 776 | } |
| 777 | /* this formula is not smart enough for the paging case |
| 778 | ti->rbuf_cnt<x> = (ti->avail_shared_ram * BLOCKSZ - ADAPT_PRIVATE - |
| 779 | ARBLENGTH - SSBLENGTH - DLC_MAX_SAP * SAPLENGTH - |
| 780 | DLC_MAX_STA * STALENGTH - ti->dhb_size<x>mb * NUM_DHB - |
| 781 | SRBLENGTH - ASBLENGTH) / ti->rbuf_len<x>; |
| 782 | */ |
| 783 | ti->maxmtu16 = (ti->rbuf_len16 - 8) * ti->rbuf_cnt16 - TR_HLEN; |
| 784 | ti->maxmtu4 = (ti->rbuf_len4 - 8) * ti->rbuf_cnt4 - TR_HLEN; |
| 785 | /*BMS assuming 18 bytes of Routing Information (usually works) */ |
| 786 | DPRINTK("Maximum Receive Internet Protocol MTU 16Mbps: %d, 4Mbps: %d\n", |
| 787 | ti->maxmtu16, ti->maxmtu4); |
| 788 | |
| 789 | dev->base_addr = PIOaddr; /* set the value for device */ |
| 790 | dev->mem_start = ti->sram_base << 12; |
| 791 | dev->mem_end = dev->mem_start + (ti->mapped_ram_size << 9) - 1; |
| 792 | trdev_init(dev); |
| 793 | return 0; /* Return 0 to indicate we have found a Token Ring card. */ |
| 794 | } /*ibmtr_probe1() */ |
| 795 | |
| 796 | /*****************************************************************************/ |
| 797 | |
| 798 | /* query the adapter for the size of shared RAM */ |
| 799 | /* the function returns the RAM size in units of 512 bytes */ |
| 800 | |
| 801 | static unsigned char __devinit get_sram_size(struct tok_info *adapt_info) |
| 802 | { |
| 803 | unsigned char avail_sram_code; |
| 804 | static unsigned char size_code[] = { 0, 16, 32, 64, 127, 128 }; |
| 805 | /* Adapter gives |
| 806 | 'F' -- use RRR bits 3,2 |
| 807 | 'E' -- 8kb 'D' -- 16kb |
| 808 | 'C' -- 32kb 'A' -- 64KB |
| 809 | 'B' - 64KB less 512 bytes at top |
| 810 | (WARNING ... must zero top bytes in INIT */ |
| 811 | |
| 812 | avail_sram_code = 0xf - readb(adapt_info->mmio + AIPAVAILSHRAM); |
| 813 | if (avail_sram_code) return size_code[avail_sram_code]; |
| 814 | else /* for code 'F', must compute size from RRR(3,2) bits */ |
| 815 | return 1 << |
| 816 | ((readb(adapt_info->mmio+ACA_OFFSET+ACA_RW+RRR_ODD)>>2&3)+4); |
| 817 | } |
| 818 | |
| 819 | /*****************************************************************************/ |
| 820 | |
| 821 | static int __devinit trdev_init(struct net_device *dev) |
| 822 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 823 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
| 825 | SET_PAGE(ti->srb_page); |
| 826 | ti->open_failure = NO ; |
| 827 | dev->open = tok_open; |
| 828 | dev->stop = tok_close; |
| 829 | dev->hard_start_xmit = tok_send_packet; |
| 830 | dev->get_stats = tok_get_stats; |
| 831 | dev->set_multicast_list = tok_set_multicast_list; |
| 832 | dev->change_mtu = ibmtr_change_mtu; |
| 833 | |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | /*****************************************************************************/ |
| 838 | |
| 839 | static int tok_init_card(struct net_device *dev) |
| 840 | { |
| 841 | struct tok_info *ti; |
| 842 | short PIOaddr; |
| 843 | unsigned long i; |
| 844 | |
| 845 | PIOaddr = dev->base_addr; |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 846 | ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | /* Special processing for first interrupt after reset */ |
| 848 | ti->do_tok_int = FIRST_INT; |
| 849 | /* Reset adapter */ |
| 850 | writeb(~INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN); |
| 851 | outb(0, PIOaddr + ADAPTRESET); |
| 852 | |
Nishanth Aravamudan | 3173c89 | 2005-09-11 02:09:55 -0700 | [diff] [blame] | 853 | schedule_timeout_uninterruptible(TR_RST_TIME); /* wait 50ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
| 855 | outb(0, PIOaddr + ADAPTRESETREL); |
| 856 | #ifdef ENABLE_PAGING |
| 857 | if (ti->page_mask) |
| 858 | writeb(SRPR_ENABLE_PAGING,ti->mmio+ACA_OFFSET+ACA_RW+SRPR_EVEN); |
| 859 | #endif |
| 860 | writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN); |
| 861 | i = sleep_on_timeout(&ti->wait_for_reset, 4 * HZ); |
| 862 | return i? 0 : -EAGAIN; |
| 863 | } |
| 864 | |
| 865 | /*****************************************************************************/ |
| 866 | static int tok_open(struct net_device *dev) |
| 867 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 868 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | int i; |
| 870 | |
| 871 | /*the case we were left in a failure state during a previous open */ |
| 872 | if (ti->open_failure == YES) { |
| 873 | DPRINTK("Last time you were disconnected, how about now?\n"); |
| 874 | printk("You can't insert with an ICS connector half-cocked.\n"); |
| 875 | } |
| 876 | |
| 877 | ti->open_status = CLOSED; /* CLOSED or OPEN */ |
| 878 | ti->sap_status = CLOSED; /* CLOSED or OPEN */ |
| 879 | ti->open_failure = NO; /* NO or YES */ |
| 880 | ti->open_mode = MANUAL; /* MANUAL or AUTOMATIC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | |
| 882 | ti->sram_phys &= ~1; /* to reverse what we do in tok_close */ |
| 883 | /* init the spinlock */ |
| 884 | spin_lock_init(&ti->lock); |
| 885 | init_timer(&ti->tr_timer); |
| 886 | |
| 887 | i = tok_init_card(dev); |
| 888 | if (i) return i; |
| 889 | |
| 890 | while (1){ |
| 891 | tok_open_adapter((unsigned long) dev); |
| 892 | i= interruptible_sleep_on_timeout(&ti->wait_for_reset, 25 * HZ); |
| 893 | /* sig catch: estimate opening adapter takes more than .5 sec*/ |
| 894 | if (i>(245*HZ)/10) break; /* fancier than if (i==25*HZ) */ |
| 895 | if (i==0) break; |
| 896 | if (ti->open_status == OPEN && ti->sap_status==OPEN) { |
| 897 | netif_start_queue(dev); |
| 898 | DPRINTK("Adapter is up and running\n"); |
| 899 | return 0; |
| 900 | } |
Nishanth Aravamudan | 3173c89 | 2005-09-11 02:09:55 -0700 | [diff] [blame] | 901 | i=schedule_timeout_interruptible(TR_RETRY_INTERVAL); |
| 902 | /* wait 30 seconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | if(i!=0) break; /*prob. a signal, like the i>24*HZ case above */ |
| 904 | } |
| 905 | outb(0, dev->base_addr + ADAPTRESET);/* kill pending interrupts*/ |
| 906 | DPRINTK("TERMINATED via signal\n"); /*BMS useful */ |
| 907 | return -EAGAIN; |
| 908 | } |
| 909 | |
| 910 | /*****************************************************************************/ |
| 911 | |
| 912 | #define COMMAND_OFST 0 |
| 913 | #define OPEN_OPTIONS_OFST 8 |
| 914 | #define NUM_RCV_BUF_OFST 24 |
| 915 | #define RCV_BUF_LEN_OFST 26 |
| 916 | #define DHB_LENGTH_OFST 28 |
| 917 | #define NUM_DHB_OFST 30 |
| 918 | #define DLC_MAX_SAP_OFST 32 |
| 919 | #define DLC_MAX_STA_OFST 33 |
| 920 | |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 921 | static void tok_open_adapter(unsigned long dev_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | { |
| 923 | struct net_device *dev = (struct net_device *) dev_addr; |
| 924 | struct tok_info *ti; |
| 925 | int i; |
| 926 | |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 927 | ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | SET_PAGE(ti->init_srb_page); |
| 929 | writeb(~SRB_RESP_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD); |
| 930 | for (i = 0; i < sizeof(struct dir_open_adapter); i++) |
| 931 | writeb(0, ti->init_srb + i); |
| 932 | writeb(DIR_OPEN_ADAPTER, ti->init_srb + COMMAND_OFST); |
| 933 | writew(htons(OPEN_PASS_BCON_MAC), ti->init_srb + OPEN_OPTIONS_OFST); |
| 934 | if (ti->ring_speed == 16) { |
| 935 | writew(htons(ti->dhb_size16mb), ti->init_srb + DHB_LENGTH_OFST); |
| 936 | writew(htons(ti->rbuf_cnt16), ti->init_srb + NUM_RCV_BUF_OFST); |
| 937 | writew(htons(ti->rbuf_len16), ti->init_srb + RCV_BUF_LEN_OFST); |
| 938 | } else { |
| 939 | writew(htons(ti->dhb_size4mb), ti->init_srb + DHB_LENGTH_OFST); |
| 940 | writew(htons(ti->rbuf_cnt4), ti->init_srb + NUM_RCV_BUF_OFST); |
| 941 | writew(htons(ti->rbuf_len4), ti->init_srb + RCV_BUF_LEN_OFST); |
| 942 | } |
| 943 | writeb(NUM_DHB, /* always 2 */ ti->init_srb + NUM_DHB_OFST); |
| 944 | writeb(DLC_MAX_SAP, ti->init_srb + DLC_MAX_SAP_OFST); |
| 945 | writeb(DLC_MAX_STA, ti->init_srb + DLC_MAX_STA_OFST); |
| 946 | ti->srb = ti->init_srb; /* We use this one in the interrupt handler */ |
| 947 | ti->srb_page = ti->init_srb_page; |
| 948 | DPRINTK("Opening adapter: Xmit bfrs: %d X %d, Rcv bfrs: %d X %d\n", |
| 949 | readb(ti->init_srb + NUM_DHB_OFST), |
| 950 | ntohs(readw(ti->init_srb + DHB_LENGTH_OFST)), |
| 951 | ntohs(readw(ti->init_srb + NUM_RCV_BUF_OFST)), |
| 952 | ntohs(readw(ti->init_srb + RCV_BUF_LEN_OFST))); |
| 953 | writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN); |
| 954 | writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 955 | } |
| 956 | |
| 957 | /*****************************************************************************/ |
| 958 | |
| 959 | static void open_sap(unsigned char type, struct net_device *dev) |
| 960 | { |
| 961 | int i; |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 962 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
| 964 | SET_PAGE(ti->srb_page); |
| 965 | for (i = 0; i < sizeof(struct dlc_open_sap); i++) |
| 966 | writeb(0, ti->srb + i); |
| 967 | |
| 968 | #define MAX_I_FIELD_OFST 14 |
| 969 | #define SAP_VALUE_OFST 16 |
| 970 | #define SAP_OPTIONS_OFST 17 |
| 971 | #define STATION_COUNT_OFST 18 |
| 972 | |
| 973 | writeb(DLC_OPEN_SAP, ti->srb + COMMAND_OFST); |
| 974 | writew(htons(MAX_I_FIELD), ti->srb + MAX_I_FIELD_OFST); |
| 975 | writeb(SAP_OPEN_IND_SAP | SAP_OPEN_PRIORITY, ti->srb+ SAP_OPTIONS_OFST); |
| 976 | writeb(SAP_OPEN_STATION_CNT, ti->srb + STATION_COUNT_OFST); |
| 977 | writeb(type, ti->srb + SAP_VALUE_OFST); |
| 978 | writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 979 | } |
| 980 | |
| 981 | |
| 982 | /*****************************************************************************/ |
| 983 | |
| 984 | static void tok_set_multicast_list(struct net_device *dev) |
| 985 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 986 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | struct dev_mc_list *mclist; |
| 988 | unsigned char address[4]; |
| 989 | |
| 990 | int i; |
| 991 | |
| 992 | /*BMS the next line is CRUCIAL or you may be sad when you */ |
| 993 | /*BMS ifconfig tr down or hot unplug a PCMCIA card ??hownowbrowncow*/ |
| 994 | if (/*BMSHELPdev->start == 0 ||*/ ti->open_status != OPEN) return; |
| 995 | address[0] = address[1] = address[2] = address[3] = 0; |
| 996 | mclist = dev->mc_list; |
| 997 | for (i = 0; i < dev->mc_count; i++) { |
| 998 | address[0] |= mclist->dmi_addr[2]; |
| 999 | address[1] |= mclist->dmi_addr[3]; |
| 1000 | address[2] |= mclist->dmi_addr[4]; |
| 1001 | address[3] |= mclist->dmi_addr[5]; |
| 1002 | mclist = mclist->next; |
| 1003 | } |
| 1004 | SET_PAGE(ti->srb_page); |
| 1005 | for (i = 0; i < sizeof(struct srb_set_funct_addr); i++) |
| 1006 | writeb(0, ti->srb + i); |
| 1007 | |
| 1008 | #define FUNCT_ADDRESS_OFST 6 |
| 1009 | |
| 1010 | writeb(DIR_SET_FUNC_ADDR, ti->srb + COMMAND_OFST); |
| 1011 | for (i = 0; i < 4; i++) |
| 1012 | writeb(address[i], ti->srb + FUNCT_ADDRESS_OFST + i); |
| 1013 | writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 1014 | #if TR_VERBOSE |
| 1015 | DPRINTK("Setting functional address: "); |
| 1016 | for (i=0;i<4;i++) printk("%02X ", address[i]); |
| 1017 | printk("\n"); |
| 1018 | #endif |
| 1019 | } |
| 1020 | |
| 1021 | /*****************************************************************************/ |
| 1022 | |
| 1023 | #define STATION_ID_OFST 4 |
| 1024 | |
| 1025 | static int tok_send_packet(struct sk_buff *skb, struct net_device *dev) |
| 1026 | { |
| 1027 | struct tok_info *ti; |
| 1028 | unsigned long flags; |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1029 | ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
| 1031 | netif_stop_queue(dev); |
| 1032 | |
| 1033 | /* lock against other CPUs */ |
| 1034 | spin_lock_irqsave(&(ti->lock), flags); |
| 1035 | |
| 1036 | /* Save skb; we'll need it when the adapter asks for the data */ |
| 1037 | ti->current_skb = skb; |
| 1038 | SET_PAGE(ti->srb_page); |
| 1039 | writeb(XMIT_UI_FRAME, ti->srb + COMMAND_OFST); |
| 1040 | writew(ti->exsap_station_id, ti->srb + STATION_ID_OFST); |
| 1041 | writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 1042 | spin_unlock_irqrestore(&(ti->lock), flags); |
| 1043 | dev->trans_start = jiffies; |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
| 1047 | /*****************************************************************************/ |
| 1048 | |
| 1049 | static int tok_close(struct net_device *dev) |
| 1050 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1051 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | |
| 1053 | /* Important for PCMCIA hot unplug, otherwise, we'll pull the card, */ |
| 1054 | /* unloading the module from memory, and then if a timer pops, ouch */ |
| 1055 | del_timer_sync(&ti->tr_timer); |
| 1056 | outb(0, dev->base_addr + ADAPTRESET); |
| 1057 | ti->sram_phys |= 1; |
| 1058 | ti->open_status = CLOSED; |
| 1059 | |
| 1060 | netif_stop_queue(dev); |
| 1061 | DPRINTK("Adapter is closed.\n"); |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
| 1065 | /*****************************************************************************/ |
| 1066 | |
| 1067 | #define RETCODE_OFST 2 |
| 1068 | #define OPEN_ERROR_CODE_OFST 6 |
| 1069 | #define ASB_ADDRESS_OFST 8 |
| 1070 | #define SRB_ADDRESS_OFST 10 |
| 1071 | #define ARB_ADDRESS_OFST 12 |
| 1072 | #define SSB_ADDRESS_OFST 14 |
| 1073 | |
| 1074 | static char *printphase[]= {"Lobe media test","Physical insertion", |
| 1075 | "Address verification","Roll call poll","Request Parameters"}; |
| 1076 | static char *printerror[]={"Function failure","Signal loss","Reserved", |
| 1077 | "Frequency error","Timeout","Ring failure","Ring beaconing", |
| 1078 | "Duplicate node address", |
| 1079 | "Parameter request-retry count exceeded","Remove received", |
| 1080 | "IMPL force received","Duplicate modifier", |
| 1081 | "No monitor detected","Monitor contention failed for RPL"}; |
| 1082 | |
| 1083 | static void __iomem *map_address(struct tok_info *ti, unsigned index, __u8 *page) |
| 1084 | { |
| 1085 | if (ti->page_mask) { |
| 1086 | *page = (index >> 8) & ti->page_mask; |
| 1087 | index &= ~(ti->page_mask << 8); |
| 1088 | } |
| 1089 | return ti->sram_virt + index; |
| 1090 | } |
| 1091 | |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 1092 | static void dir_open_adapter (struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1094 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | unsigned char ret_code; |
| 1096 | __u16 err; |
| 1097 | |
| 1098 | ti->srb = map_address(ti, |
| 1099 | ntohs(readw(ti->init_srb + SRB_ADDRESS_OFST)), |
| 1100 | &ti->srb_page); |
| 1101 | ti->ssb = map_address(ti, |
| 1102 | ntohs(readw(ti->init_srb + SSB_ADDRESS_OFST)), |
| 1103 | &ti->ssb_page); |
| 1104 | ti->arb = map_address(ti, |
| 1105 | ntohs(readw(ti->init_srb + ARB_ADDRESS_OFST)), |
| 1106 | &ti->arb_page); |
| 1107 | ti->asb = map_address(ti, |
| 1108 | ntohs(readw(ti->init_srb + ASB_ADDRESS_OFST)), |
| 1109 | &ti->asb_page); |
| 1110 | ti->current_skb = NULL; |
| 1111 | ret_code = readb(ti->init_srb + RETCODE_OFST); |
| 1112 | err = ntohs(readw(ti->init_srb + OPEN_ERROR_CODE_OFST)); |
| 1113 | if (!ret_code) { |
| 1114 | ti->open_status = OPEN; /* TR adapter is now available */ |
| 1115 | if (ti->open_mode == AUTOMATIC) { |
| 1116 | DPRINTK("Adapter reopened.\n"); |
| 1117 | } |
| 1118 | writeb(~SRB_RESP_INT, ti->mmio+ACA_OFFSET+ACA_RESET+ISRP_ODD); |
| 1119 | open_sap(EXTENDED_SAP, dev); |
| 1120 | return; |
| 1121 | } |
| 1122 | ti->open_failure = YES; |
| 1123 | if (ret_code == 7){ |
| 1124 | if (err == 0x24) { |
| 1125 | if (!ti->auto_speedsave) { |
| 1126 | DPRINTK("Open failed: Adapter speed must match " |
| 1127 | "ring speed if Automatic Ring Speed Save is " |
| 1128 | "disabled.\n"); |
| 1129 | ti->open_action = FAIL; |
| 1130 | }else |
| 1131 | DPRINTK("Retrying open to adjust to " |
| 1132 | "ring speed, "); |
| 1133 | } else if (err == 0x2d) { |
| 1134 | DPRINTK("Physical Insertion: No Monitor Detected, "); |
| 1135 | printk("retrying after %ds delay...\n", |
| 1136 | TR_RETRY_INTERVAL/HZ); |
| 1137 | } else if (err == 0x11) { |
| 1138 | DPRINTK("Lobe Media Function Failure (0x11), "); |
| 1139 | printk(" retrying after %ds delay...\n", |
| 1140 | TR_RETRY_INTERVAL/HZ); |
| 1141 | } else { |
| 1142 | char **prphase = printphase; |
| 1143 | char **prerror = printerror; |
| 1144 | DPRINTK("TR Adapter misc open failure, error code = "); |
| 1145 | printk("0x%x, Phase: %s, Error: %s\n", |
| 1146 | err, prphase[err/16 -1], prerror[err%16 -1]); |
| 1147 | printk(" retrying after %ds delay...\n", |
| 1148 | TR_RETRY_INTERVAL/HZ); |
| 1149 | } |
| 1150 | } else DPRINTK("open failed: ret_code = %02X..., ", ret_code); |
| 1151 | if (ti->open_action != FAIL) { |
| 1152 | if (ti->open_mode==AUTOMATIC){ |
| 1153 | ti->open_action = REOPEN; |
| 1154 | ibmtr_reset_timer(&(ti->tr_timer), dev); |
| 1155 | return; |
| 1156 | } |
| 1157 | wake_up(&ti->wait_for_reset); |
| 1158 | return; |
| 1159 | } |
| 1160 | DPRINTK("FAILURE, CAPUT\n"); |
| 1161 | } |
| 1162 | |
| 1163 | /******************************************************************************/ |
| 1164 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1165 | static irqreturn_t tok_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | { |
| 1167 | unsigned char status; |
| 1168 | /* unsigned char status_even ; */ |
| 1169 | struct tok_info *ti; |
| 1170 | struct net_device *dev; |
| 1171 | #ifdef ENABLE_PAGING |
| 1172 | unsigned char save_srpr; |
| 1173 | #endif |
| 1174 | |
| 1175 | dev = dev_id; |
| 1176 | #if TR_VERBOSE |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1177 | DPRINTK("Int from tok_driver, dev : %p irq%d\n", dev,irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | #endif |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1179 | ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | if (ti->sram_phys & 1) |
| 1181 | return IRQ_NONE; /* PCMCIA card extraction flag */ |
| 1182 | spin_lock(&(ti->lock)); |
| 1183 | #ifdef ENABLE_PAGING |
| 1184 | save_srpr = readb(ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN); |
| 1185 | #endif |
| 1186 | |
| 1187 | /* Disable interrupts till processing is finished */ |
| 1188 | writeb((~INT_ENABLE), ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN); |
| 1189 | |
| 1190 | /* Reset interrupt for ISA boards */ |
| 1191 | if (ti->adapter_int_enable) |
| 1192 | outb(0, ti->adapter_int_enable); |
| 1193 | else /* used for PCMCIA cards */ |
| 1194 | outb(0, ti->global_int_enable); |
| 1195 | if (ti->do_tok_int == FIRST_INT){ |
| 1196 | initial_tok_int(dev); |
| 1197 | #ifdef ENABLE_PAGING |
| 1198 | writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN); |
| 1199 | #endif |
| 1200 | spin_unlock(&(ti->lock)); |
| 1201 | return IRQ_HANDLED; |
| 1202 | } |
| 1203 | /* Begin interrupt handler HERE inline to avoid the extra |
| 1204 | levels of logic and call depth for the original solution. */ |
| 1205 | status = readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_ODD); |
| 1206 | /*BMSstatus_even = readb (ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN) */ |
| 1207 | /*BMSdebugprintk("tok_interrupt: ISRP_ODD = 0x%x ISRP_EVEN = 0x%x\n", */ |
| 1208 | /*BMS status,status_even); */ |
| 1209 | |
| 1210 | if (status & ADAP_CHK_INT) { |
| 1211 | int i; |
| 1212 | void __iomem *check_reason; |
| 1213 | __u8 check_reason_page = 0; |
| 1214 | check_reason = map_address(ti, |
| 1215 | ntohs(readw(ti->mmio+ ACA_OFFSET+ACA_RW + WWCR_EVEN)), |
| 1216 | &check_reason_page); |
| 1217 | SET_PAGE(check_reason_page); |
| 1218 | |
| 1219 | DPRINTK("Adapter check interrupt\n"); |
| 1220 | DPRINTK("8 reason bytes follow: "); |
| 1221 | for (i = 0; i < 8; i++, check_reason++) |
| 1222 | printk("%02X ", (int) readb(check_reason)); |
| 1223 | printk("\n"); |
| 1224 | writeb(~ADAP_CHK_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD); |
| 1225 | status = readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRA_EVEN); |
| 1226 | DPRINTK("ISRA_EVEN == 0x02%x\n",status); |
| 1227 | ti->open_status = CLOSED; |
| 1228 | ti->sap_status = CLOSED; |
| 1229 | ti->open_mode = AUTOMATIC; |
| 7d17c1d | 2005-05-12 19:45:25 -0400 | [diff] [blame] | 1230 | netif_carrier_off(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | netif_stop_queue(dev); |
| 1232 | ti->open_action = RESTART; |
| 1233 | outb(0, dev->base_addr + ADAPTRESET); |
| 1234 | ibmtr_reset_timer(&(ti->tr_timer), dev);/*BMS try to reopen*/ |
| 1235 | spin_unlock(&(ti->lock)); |
| 1236 | return IRQ_HANDLED; |
| 1237 | } |
| 1238 | if (readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN) |
| 1239 | & (TCR_INT | ERR_INT | ACCESS_INT)) { |
| 1240 | DPRINTK("adapter error: ISRP_EVEN : %02x\n", |
| 1241 | (int)readb(ti->mmio+ ACA_OFFSET + ACA_RW + ISRP_EVEN)); |
| 1242 | writeb(~(TCR_INT | ERR_INT | ACCESS_INT), |
| 1243 | ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN); |
| 1244 | status= readb(ti->mmio+ ACA_OFFSET + ACA_RW + ISRA_EVEN);/*BMS*/ |
| 1245 | DPRINTK("ISRA_EVEN == 0x02%x\n",status);/*BMS*/ |
| 1246 | writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN); |
| 1247 | #ifdef ENABLE_PAGING |
| 1248 | writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN); |
| 1249 | #endif |
| 1250 | spin_unlock(&(ti->lock)); |
| 1251 | return IRQ_HANDLED; |
| 1252 | } |
| 1253 | if (status & SRB_RESP_INT) { /* SRB response */ |
| 1254 | SET_PAGE(ti->srb_page); |
| 1255 | #if TR_VERBOSE |
| 1256 | DPRINTK("SRB resp: cmd=%02X rsp=%02X\n", |
| 1257 | readb(ti->srb), readb(ti->srb + RETCODE_OFST)); |
| 1258 | #endif |
| 1259 | switch (readb(ti->srb)) { /* SRB command check */ |
| 1260 | case XMIT_DIR_FRAME:{ |
| 1261 | unsigned char xmit_ret_code; |
| 1262 | xmit_ret_code = readb(ti->srb + RETCODE_OFST); |
| 1263 | if (xmit_ret_code == 0xff) break; |
| 1264 | DPRINTK("error on xmit_dir_frame request: %02X\n", |
| 1265 | xmit_ret_code); |
| 1266 | if (ti->current_skb) { |
| 1267 | dev_kfree_skb_irq(ti->current_skb); |
| 1268 | ti->current_skb = NULL; |
| 1269 | } |
| 1270 | /*dev->tbusy = 0;*/ |
| 1271 | netif_wake_queue(dev); |
| 1272 | if (ti->readlog_pending) |
| 1273 | ibmtr_readlog(dev); |
| 1274 | break; |
| 1275 | } |
| 1276 | case XMIT_UI_FRAME:{ |
| 1277 | unsigned char xmit_ret_code; |
| 1278 | |
| 1279 | xmit_ret_code = readb(ti->srb + RETCODE_OFST); |
| 1280 | if (xmit_ret_code == 0xff) break; |
| 1281 | DPRINTK("error on xmit_ui_frame request: %02X\n", |
| 1282 | xmit_ret_code); |
| 1283 | if (ti->current_skb) { |
| 1284 | dev_kfree_skb_irq(ti->current_skb); |
| 1285 | ti->current_skb = NULL; |
| 1286 | } |
| 1287 | netif_wake_queue(dev); |
| 1288 | if (ti->readlog_pending) |
| 1289 | ibmtr_readlog(dev); |
| 1290 | break; |
| 1291 | } |
| 1292 | case DIR_OPEN_ADAPTER: |
| 1293 | dir_open_adapter(dev); |
| 1294 | break; |
| 1295 | case DLC_OPEN_SAP: |
| 1296 | if (readb(ti->srb + RETCODE_OFST)) { |
| 1297 | DPRINTK("open_sap failed: ret_code = %02X, " |
| 1298 | "retrying\n", |
| 1299 | (int) readb(ti->srb + RETCODE_OFST)); |
| 1300 | ti->open_action = REOPEN; |
| 1301 | ibmtr_reset_timer(&(ti->tr_timer), dev); |
| 1302 | break; |
| 1303 | } |
| 1304 | ti->exsap_station_id = readw(ti->srb + STATION_ID_OFST); |
| 1305 | ti->sap_status = OPEN;/* TR adapter is now available */ |
| 1306 | if (ti->open_mode==MANUAL){ |
| 1307 | wake_up(&ti->wait_for_reset); |
| 1308 | break; |
| 1309 | } |
| 1310 | netif_wake_queue(dev); |
| 7d17c1d | 2005-05-12 19:45:25 -0400 | [diff] [blame] | 1311 | netif_carrier_on(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | break; |
| 1313 | case DIR_INTERRUPT: |
| 1314 | case DIR_MOD_OPEN_PARAMS: |
| 1315 | case DIR_SET_GRP_ADDR: |
| 1316 | case DIR_SET_FUNC_ADDR: |
| 1317 | case DLC_CLOSE_SAP: |
| 1318 | if (readb(ti->srb + RETCODE_OFST)) |
| 1319 | DPRINTK("error on %02X: %02X\n", |
| 1320 | (int) readb(ti->srb + COMMAND_OFST), |
| 1321 | (int) readb(ti->srb + RETCODE_OFST)); |
| 1322 | break; |
| 1323 | case DIR_READ_LOG: |
| 1324 | if (readb(ti->srb + RETCODE_OFST)){ |
| 1325 | DPRINTK("error on dir_read_log: %02X\n", |
| 1326 | (int) readb(ti->srb + RETCODE_OFST)); |
| 1327 | netif_wake_queue(dev); |
| 1328 | break; |
| 1329 | } |
| 1330 | #if IBMTR_DEBUG_MESSAGES |
| 1331 | |
| 1332 | #define LINE_ERRORS_OFST 0 |
| 1333 | #define INTERNAL_ERRORS_OFST 1 |
| 1334 | #define BURST_ERRORS_OFST 2 |
| 1335 | #define AC_ERRORS_OFST 3 |
| 1336 | #define ABORT_DELIMITERS_OFST 4 |
| 1337 | #define LOST_FRAMES_OFST 6 |
| 1338 | #define RECV_CONGEST_COUNT_OFST 7 |
| 1339 | #define FRAME_COPIED_ERRORS_OFST 8 |
| 1340 | #define FREQUENCY_ERRORS_OFST 9 |
| 1341 | #define TOKEN_ERRORS_OFST 10 |
| 1342 | |
| 1343 | DPRINTK("Line errors %02X, Internal errors %02X, " |
| 1344 | "Burst errors %02X\n" "A/C errors %02X, " |
| 1345 | "Abort delimiters %02X, Lost frames %02X\n" |
| 1346 | "Receive congestion count %02X, " |
| 1347 | "Frame copied errors %02X\nFrequency errors %02X, " |
| 1348 | "Token errors %02X\n", |
| 1349 | (int) readb(ti->srb + LINE_ERRORS_OFST), |
| 1350 | (int) readb(ti->srb + INTERNAL_ERRORS_OFST), |
| 1351 | (int) readb(ti->srb + BURST_ERRORS_OFST), |
| 1352 | (int) readb(ti->srb + AC_ERRORS_OFST), |
| 1353 | (int) readb(ti->srb + ABORT_DELIMITERS_OFST), |
| 1354 | (int) readb(ti->srb + LOST_FRAMES_OFST), |
| 1355 | (int) readb(ti->srb + RECV_CONGEST_COUNT_OFST), |
| 1356 | (int) readb(ti->srb + FRAME_COPIED_ERRORS_OFST), |
| 1357 | (int) readb(ti->srb + FREQUENCY_ERRORS_OFST), |
| 1358 | (int) readb(ti->srb + TOKEN_ERRORS_OFST)); |
| 1359 | #endif |
| 1360 | netif_wake_queue(dev); |
| 1361 | break; |
| 1362 | default: |
| 1363 | DPRINTK("Unknown command %02X encountered\n", |
| 1364 | (int) readb(ti->srb)); |
| 1365 | } /* end switch SRB command check */ |
| 1366 | writeb(~SRB_RESP_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD); |
| 1367 | } /* if SRB response */ |
| 1368 | if (status & ASB_FREE_INT) { /* ASB response */ |
| 1369 | SET_PAGE(ti->asb_page); |
| 1370 | #if TR_VERBOSE |
| 1371 | DPRINTK("ASB resp: cmd=%02X\n", readb(ti->asb)); |
| 1372 | #endif |
| 1373 | |
| 1374 | switch (readb(ti->asb)) { /* ASB command check */ |
| 1375 | case REC_DATA: |
| 1376 | case XMIT_UI_FRAME: |
| 1377 | case XMIT_DIR_FRAME: |
| 1378 | break; |
| 1379 | default: |
| 1380 | DPRINTK("unknown command in asb %02X\n", |
| 1381 | (int) readb(ti->asb)); |
| 1382 | } /* switch ASB command check */ |
| 1383 | if (readb(ti->asb + 2) != 0xff) /* checks ret_code */ |
| 1384 | DPRINTK("ASB error %02X in cmd %02X\n", |
| 1385 | (int) readb(ti->asb + 2), (int) readb(ti->asb)); |
| 1386 | writeb(~ASB_FREE_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD); |
| 1387 | } /* if ASB response */ |
| 1388 | |
| 1389 | #define STATUS_OFST 6 |
| 1390 | #define NETW_STATUS_OFST 6 |
| 1391 | |
| 1392 | if (status & ARB_CMD_INT) { /* ARB response */ |
| 1393 | SET_PAGE(ti->arb_page); |
| 1394 | #if TR_VERBOSE |
| 1395 | DPRINTK("ARB resp: cmd=%02X\n", readb(ti->arb)); |
| 1396 | #endif |
| 1397 | |
| 1398 | switch (readb(ti->arb)) { /* ARB command check */ |
| 1399 | case DLC_STATUS: |
| 1400 | DPRINTK("DLC_STATUS new status: %02X on station %02X\n", |
| 1401 | ntohs(readw(ti->arb + STATUS_OFST)), |
| 1402 | ntohs(readw(ti->arb+ STATION_ID_OFST))); |
| 1403 | break; |
| 1404 | case REC_DATA: |
| 1405 | tr_rx(dev); |
| 1406 | break; |
| 1407 | case RING_STAT_CHANGE:{ |
| 1408 | unsigned short ring_status; |
| 1409 | ring_status= ntohs(readw(ti->arb + NETW_STATUS_OFST)); |
| 1410 | if (ibmtr_debug_trace & TRC_INIT) |
| 1411 | DPRINTK("Ring Status Change...(0x%x)\n", |
| 1412 | ring_status); |
| 1413 | if(ring_status& (REMOVE_RECV|AUTO_REMOVAL|LOBE_FAULT)){ |
| 1414 | netif_stop_queue(dev); |
| 7d17c1d | 2005-05-12 19:45:25 -0400 | [diff] [blame] | 1415 | netif_carrier_off(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | DPRINTK("Remove received, or Auto-removal error" |
| 1417 | ", or Lobe fault\n"); |
| 1418 | DPRINTK("We'll try to reopen the closed adapter" |
| 1419 | " after a %d second delay.\n", |
| 1420 | TR_RETRY_INTERVAL/HZ); |
| 1421 | /*I was confused: I saw the TR reopening but */ |
| 1422 | /*forgot:with an RJ45 in an RJ45/ICS adapter */ |
| 1423 | /*but adapter not in the ring, the TR will */ |
| 1424 | /* open, and then soon close and come here. */ |
| 1425 | ti->open_mode = AUTOMATIC; |
| 1426 | ti->open_status = CLOSED; /*12/2000 BMS*/ |
| 1427 | ti->open_action = REOPEN; |
| 1428 | ibmtr_reset_timer(&(ti->tr_timer), dev); |
| 1429 | } else if (ring_status & LOG_OVERFLOW) { |
| 1430 | if(netif_queue_stopped(dev)) |
| 1431 | ti->readlog_pending = 1; |
| 1432 | else |
| 1433 | ibmtr_readlog(dev); |
| 1434 | } |
| 1435 | break; |
| 1436 | } |
| 1437 | case XMIT_DATA_REQ: |
| 1438 | tr_tx(dev); |
| 1439 | break; |
| 1440 | default: |
| 1441 | DPRINTK("Unknown command %02X in arb\n", |
| 1442 | (int) readb(ti->arb)); |
| 1443 | break; |
| 1444 | } /* switch ARB command check */ |
| 1445 | writeb(~ARB_CMD_INT, ti->mmio+ ACA_OFFSET+ACA_RESET + ISRP_ODD); |
| 1446 | writeb(ARB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 1447 | } /* if ARB response */ |
| 1448 | if (status & SSB_RESP_INT) { /* SSB response */ |
| 1449 | unsigned char retcode; |
| 1450 | SET_PAGE(ti->ssb_page); |
| 1451 | #if TR_VERBOSE |
| 1452 | DPRINTK("SSB resp: cmd=%02X rsp=%02X\n", |
| 1453 | readb(ti->ssb), readb(ti->ssb + 2)); |
| 1454 | #endif |
| 1455 | |
| 1456 | switch (readb(ti->ssb)) { /* SSB command check */ |
| 1457 | case XMIT_DIR_FRAME: |
| 1458 | case XMIT_UI_FRAME: |
| 1459 | retcode = readb(ti->ssb + 2); |
| 1460 | if (retcode && (retcode != 0x22))/* checks ret_code */ |
| 1461 | DPRINTK("xmit ret_code: %02X xmit error code: " |
| 1462 | "%02X\n", |
| 1463 | (int)retcode, (int)readb(ti->ssb + 6)); |
| 1464 | else |
| 1465 | ti->tr_stats.tx_packets++; |
| 1466 | break; |
| 1467 | case XMIT_XID_CMD: |
| 1468 | DPRINTK("xmit xid ret_code: %02X\n", |
| 1469 | (int) readb(ti->ssb + 2)); |
| 1470 | default: |
| 1471 | DPRINTK("Unknown command %02X in ssb\n", |
| 1472 | (int) readb(ti->ssb)); |
| 1473 | } /* SSB command check */ |
| 1474 | writeb(~SSB_RESP_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD); |
| 1475 | writeb(SSB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 1476 | } /* if SSB response */ |
| 1477 | #ifdef ENABLE_PAGING |
| 1478 | writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN); |
| 1479 | #endif |
| 1480 | writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN); |
| 1481 | spin_unlock(&(ti->lock)); |
| 1482 | return IRQ_HANDLED; |
| 1483 | } /*tok_interrupt */ |
| 1484 | |
| 1485 | /*****************************************************************************/ |
| 1486 | |
| 1487 | #define INIT_STATUS_OFST 1 |
| 1488 | #define INIT_STATUS_2_OFST 2 |
| 1489 | #define ENCODED_ADDRESS_OFST 8 |
| 1490 | |
| 1491 | static void initial_tok_int(struct net_device *dev) |
| 1492 | { |
| 1493 | |
| 1494 | __u32 encoded_addr, hw_encoded_addr; |
| 1495 | struct tok_info *ti; |
| 1496 | unsigned char init_status; /*BMS 12/2000*/ |
| 1497 | |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1498 | ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | |
| 1500 | ti->do_tok_int = NOT_FIRST; |
| 1501 | |
| 1502 | /* we assign the shared-ram address for ISA devices */ |
| 1503 | writeb(ti->sram_base, ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN); |
| 1504 | #ifndef PCMCIA |
| 1505 | ti->sram_virt = ioremap(((__u32)ti->sram_base << 12), ti->avail_shared_ram); |
| 1506 | #endif |
| 1507 | ti->init_srb = map_address(ti, |
| 1508 | ntohs(readw(ti->mmio + ACA_OFFSET + WRBR_EVEN)), |
| 1509 | &ti->init_srb_page); |
| 1510 | if (ti->page_mask && ti->avail_shared_ram == 127) { |
| 1511 | void __iomem *last_512; |
| 1512 | __u8 last_512_page=0; |
| 1513 | int i; |
| 1514 | last_512 = map_address(ti, 0xfe00, &last_512_page); |
| 1515 | /* initialize high section of ram (if necessary) */ |
| 1516 | SET_PAGE(last_512_page); |
| 1517 | for (i = 0; i < 512; i++) |
| 1518 | writeb(0, last_512 + i); |
| 1519 | } |
| 1520 | SET_PAGE(ti->init_srb_page); |
| 1521 | |
| 1522 | #if TR_VERBOSE |
| 1523 | { |
| 1524 | int i; |
| 1525 | |
| 1526 | DPRINTK("ti->init_srb_page=0x%x\n", ti->init_srb_page); |
| 1527 | DPRINTK("init_srb(%p):", ti->init_srb ); |
| 1528 | for (i = 0; i < 20; i++) |
| 1529 | printk("%02X ", (int) readb(ti->init_srb + i)); |
| 1530 | printk("\n"); |
| 1531 | } |
| 1532 | #endif |
| 1533 | |
| 1534 | hw_encoded_addr = readw(ti->init_srb + ENCODED_ADDRESS_OFST); |
| 1535 | encoded_addr = ntohs(hw_encoded_addr); |
| 1536 | init_status= /*BMS 12/2000 check for shallow mode possibility (Turbo)*/ |
| 1537 | readb(ti->init_srb+offsetof(struct srb_init_response,init_status)); |
| 1538 | /*printk("Initial interrupt: init_status= 0x%02x\n",init_status);*/ |
| 1539 | ti->ring_speed = init_status & 0x01 ? 16 : 4; |
| 1540 | DPRINTK("Initial interrupt : %d Mbps, shared RAM base %08x.\n", |
| 1541 | ti->ring_speed, (unsigned int)dev->mem_start); |
Richard Knutsson | 2d6d749 | 2007-08-14 02:07:09 +0200 | [diff] [blame^] | 1542 | ti->auto_speedsave = (readb(ti->init_srb+INIT_STATUS_2_OFST) & 4) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | |
| 1544 | if (ti->open_mode == MANUAL) wake_up(&ti->wait_for_reset); |
| 1545 | else tok_open_adapter((unsigned long)dev); |
| 1546 | |
| 1547 | } /*initial_tok_int() */ |
| 1548 | |
| 1549 | /*****************************************************************************/ |
| 1550 | |
| 1551 | #define CMD_CORRELATE_OFST 1 |
| 1552 | #define DHB_ADDRESS_OFST 6 |
| 1553 | |
| 1554 | #define FRAME_LENGTH_OFST 6 |
| 1555 | #define HEADER_LENGTH_OFST 8 |
| 1556 | #define RSAP_VALUE_OFST 9 |
| 1557 | |
| 1558 | static void tr_tx(struct net_device *dev) |
| 1559 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1560 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | struct trh_hdr *trhdr = (struct trh_hdr *) ti->current_skb->data; |
| 1562 | unsigned int hdr_len; |
| 1563 | __u32 dhb=0,dhb_base; |
| 1564 | void __iomem *dhbuf = NULL; |
| 1565 | unsigned char xmit_command; |
| 1566 | int i,dhb_len=0x4000,src_len,src_offset; |
| 1567 | struct trllc *llc; |
| 1568 | struct srb_xmit xsrb; |
| 1569 | __u8 dhb_page = 0; |
| 1570 | __u8 llc_ssap; |
| 1571 | |
| 1572 | SET_PAGE(ti->asb_page); |
| 1573 | |
| 1574 | if (readb(ti->asb+RETCODE_OFST) != 0xFF) DPRINTK("ASB not free !!!\n"); |
| 1575 | |
| 1576 | /* in providing the transmit interrupts, is telling us it is ready for |
| 1577 | data and providing a shared memory address for us to stuff with data. |
| 1578 | Here we compute the effective address where we will place data. |
| 1579 | */ |
| 1580 | SET_PAGE(ti->arb_page); |
| 1581 | dhb=dhb_base=ntohs(readw(ti->arb + DHB_ADDRESS_OFST)); |
| 1582 | if (ti->page_mask) { |
| 1583 | dhb_page = (dhb_base >> 8) & ti->page_mask; |
| 1584 | dhb=dhb_base & ~(ti->page_mask << 8); |
| 1585 | } |
| 1586 | dhbuf = ti->sram_virt + dhb; |
| 1587 | |
| 1588 | /* Figure out the size of the 802.5 header */ |
| 1589 | if (!(trhdr->saddr[0] & 0x80)) /* RIF present? */ |
| 1590 | hdr_len = sizeof(struct trh_hdr) - TR_MAXRIFLEN; |
| 1591 | else |
| 1592 | hdr_len = ((ntohs(trhdr->rcf) & TR_RCF_LEN_MASK) >> 8) |
| 1593 | + sizeof(struct trh_hdr) - TR_MAXRIFLEN; |
| 1594 | |
| 1595 | llc = (struct trllc *) (ti->current_skb->data + hdr_len); |
| 1596 | |
| 1597 | llc_ssap = llc->ssap; |
| 1598 | SET_PAGE(ti->srb_page); |
| 1599 | memcpy_fromio(&xsrb, ti->srb, sizeof(xsrb)); |
| 1600 | SET_PAGE(ti->asb_page); |
| 1601 | xmit_command = xsrb.command; |
| 1602 | |
| 1603 | writeb(xmit_command, ti->asb + COMMAND_OFST); |
| 1604 | writew(xsrb.station_id, ti->asb + STATION_ID_OFST); |
| 1605 | writeb(llc_ssap, ti->asb + RSAP_VALUE_OFST); |
| 1606 | writeb(xsrb.cmd_corr, ti->asb + CMD_CORRELATE_OFST); |
| 1607 | writeb(0, ti->asb + RETCODE_OFST); |
| 1608 | if ((xmit_command == XMIT_XID_CMD) || (xmit_command == XMIT_TEST_CMD)) { |
| 1609 | writew(htons(0x11), ti->asb + FRAME_LENGTH_OFST); |
| 1610 | writeb(0x0e, ti->asb + HEADER_LENGTH_OFST); |
| 1611 | SET_PAGE(dhb_page); |
| 1612 | writeb(AC, dhbuf); |
| 1613 | writeb(LLC_FRAME, dhbuf + 1); |
| 1614 | for (i = 0; i < TR_ALEN; i++) |
| 1615 | writeb((int) 0x0FF, dhbuf + i + 2); |
| 1616 | for (i = 0; i < TR_ALEN; i++) |
| 1617 | writeb(0, dhbuf + i + TR_ALEN + 2); |
| 1618 | writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 1619 | return; |
| 1620 | } |
| 1621 | /* |
| 1622 | * the token ring packet is copied from sk_buff to the adapter |
| 1623 | * buffer identified in the command data received with the interrupt. |
| 1624 | */ |
| 1625 | writeb(hdr_len, ti->asb + HEADER_LENGTH_OFST); |
| 1626 | writew(htons(ti->current_skb->len), ti->asb + FRAME_LENGTH_OFST); |
| 1627 | src_len=ti->current_skb->len; |
| 1628 | src_offset=0; |
| 1629 | dhb=dhb_base; |
| 1630 | while(1) { |
| 1631 | if (ti->page_mask) { |
| 1632 | dhb_page=(dhb >> 8) & ti->page_mask; |
| 1633 | dhb=dhb & ~(ti->page_mask << 8); |
| 1634 | dhb_len=0x4000-dhb; /* remaining size of this page */ |
| 1635 | } |
| 1636 | dhbuf = ti->sram_virt + dhb; |
| 1637 | SET_PAGE(dhb_page); |
| 1638 | if (src_len > dhb_len) { |
| 1639 | memcpy_toio(dhbuf,&ti->current_skb->data[src_offset], |
| 1640 | dhb_len); |
| 1641 | src_len -= dhb_len; |
| 1642 | src_offset += dhb_len; |
| 1643 | dhb_base+=dhb_len; |
| 1644 | dhb=dhb_base; |
| 1645 | continue; |
| 1646 | } |
| 1647 | memcpy_toio(dhbuf, &ti->current_skb->data[src_offset], src_len); |
| 1648 | break; |
| 1649 | } |
| 1650 | writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 1651 | ti->tr_stats.tx_bytes += ti->current_skb->len; |
| 1652 | dev_kfree_skb_irq(ti->current_skb); |
| 1653 | ti->current_skb = NULL; |
| 1654 | netif_wake_queue(dev); |
| 1655 | if (ti->readlog_pending) |
| 1656 | ibmtr_readlog(dev); |
| 1657 | } /*tr_tx */ |
| 1658 | |
| 1659 | /*****************************************************************************/ |
| 1660 | |
| 1661 | |
| 1662 | #define RECEIVE_BUFFER_OFST 6 |
| 1663 | #define LAN_HDR_LENGTH_OFST 8 |
| 1664 | #define DLC_HDR_LENGTH_OFST 9 |
| 1665 | |
| 1666 | #define DSAP_OFST 0 |
| 1667 | #define SSAP_OFST 1 |
| 1668 | #define LLC_OFST 2 |
| 1669 | #define PROTID_OFST 3 |
| 1670 | #define ETHERTYPE_OFST 6 |
| 1671 | |
| 1672 | static void tr_rx(struct net_device *dev) |
| 1673 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1674 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | __u32 rbuffer; |
| 1676 | void __iomem *rbuf, *rbufdata, *llc; |
| 1677 | __u8 rbuffer_page = 0; |
| 1678 | unsigned char *data; |
| 1679 | unsigned int rbuffer_len, lan_hdr_len, hdr_len, ip_len, length; |
| 1680 | unsigned char dlc_hdr_len; |
| 1681 | struct sk_buff *skb; |
| 1682 | unsigned int skb_size = 0; |
| 1683 | int IPv4_p = 0; |
| 1684 | unsigned int chksum = 0; |
| 1685 | struct iphdr *iph; |
| 1686 | struct arb_rec_req rarb; |
| 1687 | |
| 1688 | SET_PAGE(ti->arb_page); |
| 1689 | memcpy_fromio(&rarb, ti->arb, sizeof(rarb)); |
| 1690 | rbuffer = ntohs(rarb.rec_buf_addr) ; |
| 1691 | rbuf = map_address(ti, rbuffer, &rbuffer_page); |
| 1692 | |
| 1693 | SET_PAGE(ti->asb_page); |
| 1694 | |
| 1695 | if (readb(ti->asb + RETCODE_OFST) !=0xFF) DPRINTK("ASB not free !!!\n"); |
| 1696 | |
| 1697 | writeb(REC_DATA, ti->asb + COMMAND_OFST); |
| 1698 | writew(rarb.station_id, ti->asb + STATION_ID_OFST); |
| 1699 | writew(rarb.rec_buf_addr, ti->asb + RECEIVE_BUFFER_OFST); |
| 1700 | |
| 1701 | lan_hdr_len = rarb.lan_hdr_len; |
| 1702 | if (lan_hdr_len > sizeof(struct trh_hdr)) { |
| 1703 | DPRINTK("Linux cannot handle greater than 18 bytes RIF\n"); |
| 1704 | return; |
| 1705 | } /*BMS I added this above just to be very safe */ |
| 1706 | dlc_hdr_len = readb(ti->arb + DLC_HDR_LENGTH_OFST); |
| 1707 | hdr_len = lan_hdr_len + sizeof(struct trllc) + sizeof(struct iphdr); |
| 1708 | |
| 1709 | SET_PAGE(rbuffer_page); |
| 1710 | llc = rbuf + offsetof(struct rec_buf, data) + lan_hdr_len; |
| 1711 | |
| 1712 | #if TR_VERBOSE |
| 1713 | DPRINTK("offsetof data: %02X lan_hdr_len: %02X\n", |
| 1714 | (__u32) offsetof(struct rec_buf, data), (unsigned int) lan_hdr_len); |
| 1715 | DPRINTK("llc: %08X rec_buf_addr: %04X dev->mem_start: %lX\n", |
| 1716 | llc, ntohs(rarb.rec_buf_addr), dev->mem_start); |
| 1717 | DPRINTK("dsap: %02X, ssap: %02X, llc: %02X, protid: %02X%02X%02X, " |
| 1718 | "ethertype: %04X\n", |
| 1719 | (int) readb(llc + DSAP_OFST), (int) readb(llc + SSAP_OFST), |
| 1720 | (int) readb(llc + LLC_OFST), (int) readb(llc + PROTID_OFST), |
| 1721 | (int) readb(llc+PROTID_OFST+1),(int)readb(llc+PROTID_OFST + 2), |
| 1722 | (int) ntohs(readw(llc + ETHERTYPE_OFST))); |
| 1723 | #endif |
| 1724 | if (readb(llc + offsetof(struct trllc, llc)) != UI_CMD) { |
| 1725 | SET_PAGE(ti->asb_page); |
| 1726 | writeb(DATA_LOST, ti->asb + RETCODE_OFST); |
| 1727 | ti->tr_stats.rx_dropped++; |
| 1728 | writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 1729 | return; |
| 1730 | } |
| 1731 | length = ntohs(rarb.frame_len); |
| 1732 | if (readb(llc + DSAP_OFST) == EXTENDED_SAP && |
| 1733 | readb(llc + SSAP_OFST) == EXTENDED_SAP && |
| 1734 | length >= hdr_len) IPv4_p = 1; |
| 1735 | #if TR_VERBOSE |
| 1736 | #define SADDR_OFST 8 |
| 1737 | #define DADDR_OFST 2 |
| 1738 | |
| 1739 | if (!IPv4_p) { |
| 1740 | |
| 1741 | void __iomem *trhhdr = rbuf + offsetof(struct rec_buf, data); |
| 1742 | |
| 1743 | DPRINTK("Probably non-IP frame received.\n"); |
| 1744 | DPRINTK("ssap: %02X dsap: %02X " |
| 1745 | "saddr: %02X:%02X:%02X:%02X:%02X:%02X " |
| 1746 | "daddr: %02X:%02X:%02X:%02X:%02X:%02X\n", |
| 1747 | readb(llc + SSAP_OFST), readb(llc + DSAP_OFST), |
| 1748 | readb(trhhdr+SADDR_OFST), readb(trhhdr+ SADDR_OFST+1), |
| 1749 | readb(trhhdr+SADDR_OFST+2), readb(trhhdr+SADDR_OFST+3), |
| 1750 | readb(trhhdr+SADDR_OFST+4), readb(trhhdr+SADDR_OFST+5), |
| 1751 | readb(trhhdr+DADDR_OFST), readb(trhhdr+DADDR_OFST + 1), |
| 1752 | readb(trhhdr+DADDR_OFST+2), readb(trhhdr+DADDR_OFST+3), |
| 1753 | readb(trhhdr+DADDR_OFST+4), readb(trhhdr+DADDR_OFST+5)); |
| 1754 | } |
| 1755 | #endif |
| 1756 | |
| 1757 | /*BMS handle the case she comes in with few hops but leaves with many */ |
| 1758 | skb_size=length-lan_hdr_len+sizeof(struct trh_hdr)+sizeof(struct trllc); |
| 1759 | |
| 1760 | if (!(skb = dev_alloc_skb(skb_size))) { |
| 1761 | DPRINTK("out of memory. frame dropped.\n"); |
| 1762 | ti->tr_stats.rx_dropped++; |
| 1763 | SET_PAGE(ti->asb_page); |
| 1764 | writeb(DATA_LOST, ti->asb + offsetof(struct asb_rec, ret_code)); |
| 1765 | writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 1766 | return; |
| 1767 | } |
| 1768 | /*BMS again, if she comes in with few but leaves with many */ |
| 1769 | skb_reserve(skb, sizeof(struct trh_hdr) - lan_hdr_len); |
| 1770 | skb_put(skb, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | data = skb->data; |
| 1772 | rbuffer_len = ntohs(readw(rbuf + offsetof(struct rec_buf, buf_len))); |
| 1773 | rbufdata = rbuf + offsetof(struct rec_buf, data); |
| 1774 | |
| 1775 | if (IPv4_p) { |
| 1776 | /* Copy the headers without checksumming */ |
| 1777 | memcpy_fromio(data, rbufdata, hdr_len); |
| 1778 | |
| 1779 | /* Watch for padded packets and bogons */ |
| 1780 | iph= (struct iphdr *)(data+ lan_hdr_len + sizeof(struct trllc)); |
| 1781 | ip_len = ntohs(iph->tot_len) - sizeof(struct iphdr); |
| 1782 | length -= hdr_len; |
| 1783 | if ((ip_len <= length) && (ip_len > 7)) |
| 1784 | length = ip_len; |
| 1785 | data += hdr_len; |
| 1786 | rbuffer_len -= hdr_len; |
| 1787 | rbufdata += hdr_len; |
| 1788 | } |
| 1789 | /* Copy the payload... */ |
| 1790 | #define BUFFER_POINTER_OFST 2 |
| 1791 | #define BUFFER_LENGTH_OFST 6 |
| 1792 | for (;;) { |
| 1793 | if (ibmtr_debug_trace&TRC_INITV && length < rbuffer_len) |
| 1794 | DPRINTK("CURIOUS, length=%d < rbuffer_len=%d\n", |
| 1795 | length,rbuffer_len); |
| 1796 | if (IPv4_p) |
| 1797 | chksum=csum_partial_copy_nocheck((void*)rbufdata, |
| 1798 | data,length<rbuffer_len?length:rbuffer_len,chksum); |
| 1799 | else |
| 1800 | memcpy_fromio(data, rbufdata, rbuffer_len); |
| 1801 | rbuffer = ntohs(readw(rbuf+BUFFER_POINTER_OFST)) ; |
| 1802 | if (!rbuffer) |
| 1803 | break; |
| 1804 | rbuffer -= 2; |
| 1805 | length -= rbuffer_len; |
| 1806 | data += rbuffer_len; |
| 1807 | rbuf = map_address(ti, rbuffer, &rbuffer_page); |
| 1808 | SET_PAGE(rbuffer_page); |
| 1809 | rbuffer_len = ntohs(readw(rbuf + BUFFER_LENGTH_OFST)); |
| 1810 | rbufdata = rbuf + offsetof(struct rec_buf, data); |
| 1811 | } |
| 1812 | |
| 1813 | SET_PAGE(ti->asb_page); |
| 1814 | writeb(0, ti->asb + offsetof(struct asb_rec, ret_code)); |
| 1815 | |
| 1816 | writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 1817 | |
| 1818 | ti->tr_stats.rx_bytes += skb->len; |
| 1819 | ti->tr_stats.rx_packets++; |
| 1820 | |
| 1821 | skb->protocol = tr_type_trans(skb, dev); |
| 1822 | if (IPv4_p) { |
| 1823 | skb->csum = chksum; |
Al Viro | ee28b0d | 2006-12-04 22:05:09 +0000 | [diff] [blame] | 1824 | skb->ip_summed = CHECKSUM_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | } |
| 1826 | netif_rx(skb); |
| 1827 | dev->last_rx = jiffies; |
| 1828 | } /*tr_rx */ |
| 1829 | |
| 1830 | /*****************************************************************************/ |
| 1831 | |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 1832 | static void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | { |
| 1834 | tmr->expires = jiffies + TR_RETRY_INTERVAL; |
| 1835 | tmr->data = (unsigned long) dev; |
| 1836 | tmr->function = tok_rerun; |
| 1837 | init_timer(tmr); |
| 1838 | add_timer(tmr); |
| 1839 | } |
| 1840 | |
| 1841 | /*****************************************************************************/ |
| 1842 | |
| 1843 | void tok_rerun(unsigned long dev_addr){ |
| 1844 | |
| 1845 | struct net_device *dev = (struct net_device *)dev_addr; |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1846 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | |
| 1848 | if ( ti->open_action == RESTART){ |
| 1849 | ti->do_tok_int = FIRST_INT; |
| 1850 | outb(0, dev->base_addr + ADAPTRESETREL); |
| 1851 | #ifdef ENABLE_PAGING |
| 1852 | if (ti->page_mask) |
| 1853 | writeb(SRPR_ENABLE_PAGING, |
| 1854 | ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN); |
| 1855 | #endif |
| 1856 | |
| 1857 | writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN); |
| 1858 | } else |
| 1859 | tok_open_adapter(dev_addr); |
| 1860 | } |
| 1861 | |
| 1862 | /*****************************************************************************/ |
| 1863 | |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 1864 | static void ibmtr_readlog(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | { |
| 1866 | struct tok_info *ti; |
| 1867 | |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1868 | ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | |
| 1870 | ti->readlog_pending = 0; |
| 1871 | SET_PAGE(ti->srb_page); |
| 1872 | writeb(DIR_READ_LOG, ti->srb); |
| 1873 | writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN); |
| 1874 | writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); |
| 1875 | |
| 1876 | netif_stop_queue(dev); |
| 1877 | |
| 1878 | } |
| 1879 | |
| 1880 | /*****************************************************************************/ |
| 1881 | |
| 1882 | /* tok_get_stats(): Basically a scaffold routine which will return |
| 1883 | the address of the tr_statistics structure associated with |
| 1884 | this device -- the tr.... structure is an ethnet look-alike |
| 1885 | so at least for this iteration may suffice. */ |
| 1886 | |
| 1887 | static struct net_device_stats *tok_get_stats(struct net_device *dev) |
| 1888 | { |
| 1889 | |
| 1890 | struct tok_info *toki; |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1891 | toki = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | return (struct net_device_stats *) &toki->tr_stats; |
| 1893 | } |
| 1894 | |
| 1895 | /*****************************************************************************/ |
| 1896 | |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 1897 | static int ibmtr_change_mtu(struct net_device *dev, int mtu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1899 | struct tok_info *ti = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | |
| 1901 | if (ti->ring_speed == 16 && mtu > ti->maxmtu16) |
| 1902 | return -EINVAL; |
| 1903 | if (ti->ring_speed == 4 && mtu > ti->maxmtu4) |
| 1904 | return -EINVAL; |
| 1905 | dev->mtu = mtu; |
| 1906 | return 0; |
| 1907 | } |
| 1908 | |
| 1909 | /*****************************************************************************/ |
| 1910 | #ifdef MODULE |
| 1911 | |
| 1912 | /* 3COM 3C619C supports 8 interrupts, 32 I/O ports */ |
| 1913 | static struct net_device *dev_ibmtr[IBMTR_MAX_ADAPTERS]; |
| 1914 | static int io[IBMTR_MAX_ADAPTERS] = { 0xa20, 0xa24 }; |
| 1915 | static int irq[IBMTR_MAX_ADAPTERS]; |
| 1916 | static int mem[IBMTR_MAX_ADAPTERS]; |
| 1917 | |
| 1918 | MODULE_LICENSE("GPL"); |
| 1919 | |
| 1920 | module_param_array(io, int, NULL, 0); |
| 1921 | module_param_array(irq, int, NULL, 0); |
| 1922 | module_param_array(mem, int, NULL, 0); |
| 1923 | |
| 1924 | static int __init ibmtr_init(void) |
| 1925 | { |
| 1926 | int i; |
| 1927 | int count=0; |
| 1928 | |
| 1929 | find_turbo_adapters(io); |
| 1930 | |
| 1931 | for (i = 0; io[i] && (i < IBMTR_MAX_ADAPTERS); i++) { |
| 1932 | struct net_device *dev; |
| 1933 | irq[i] = 0; |
| 1934 | mem[i] = 0; |
| 1935 | dev = alloc_trdev(sizeof(struct tok_info)); |
| 1936 | if (dev == NULL) { |
| 1937 | if (i == 0) |
| 1938 | return -ENOMEM; |
| 1939 | break; |
| 1940 | } |
| 1941 | dev->base_addr = io[i]; |
| 1942 | dev->irq = irq[i]; |
| 1943 | dev->mem_start = mem[i]; |
| 1944 | |
| 1945 | if (ibmtr_probe_card(dev)) { |
| 1946 | free_netdev(dev); |
| 1947 | continue; |
| 1948 | } |
| 1949 | dev_ibmtr[i] = dev; |
| 1950 | count++; |
| 1951 | } |
| 1952 | if (count) return 0; |
| 1953 | printk("ibmtr: register_netdev() returned non-zero.\n"); |
| 1954 | return -EIO; |
| 1955 | } |
| 1956 | module_init(ibmtr_init); |
| 1957 | |
| 1958 | static void __exit ibmtr_cleanup(void) |
| 1959 | { |
| 1960 | int i; |
| 1961 | |
| 1962 | for (i = 0; i < IBMTR_MAX_ADAPTERS; i++){ |
| 1963 | if (!dev_ibmtr[i]) |
| 1964 | continue; |
| 1965 | unregister_netdev(dev_ibmtr[i]); |
| 1966 | ibmtr_cleanup_card(dev_ibmtr[i]); |
| 1967 | free_netdev(dev_ibmtr[i]); |
| 1968 | } |
| 1969 | } |
| 1970 | module_exit(ibmtr_cleanup); |
| 1971 | #endif |