OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [net/] [tokenring/] [ibmtr.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.