1 /* ibmtr.c: A shared-memory IBM Token Ring 16/4 driver for linux
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 Public License, incorporated herein by reference.
7 * This device driver should work with Any IBM Token Ring Card that does
10 * I used Donald Becker's (becker@cesdis.gsfc.nasa.gov) device driver work
11 * as a base for most of my initial work.
13 * Changes by Peter De Schrijver (Peter.Deschrijver@linux.cc.kuleuven.ac.be) :
15 * + changed name to ibmtr.c in anticipation of other tr boards.
16 * + changed reset code and adapter open code.
17 * + added SAP open code.
18 * + a first attempt to write interrupt, transmit and receive routines.
20 * Changes by David W. Morris (dwm@shell.portal.com) :
21 * 941003 dwm: - Restructure tok_probe for multiple adapters, devices.
22 * + Add comments, misc reorg for clarity.
23 * + Flatten interrupt handler levels.
25 * Changes by Farzad Farid (farzy@zen.via.ecp.fr)
26 * and Pascal Andre (andre@chimay.via.ecp.fr) (March 9 1995) :
27 * + multi ring support clean up.
28 * + RFC1042 compliance enhanced.
30 * Changes by Pascal Andre (andre@chimay.via.ecp.fr) (September 7 1995) :
31 * + bug correction in tr_tx
32 * + removed redundant information display
33 * + some code reworking
35 * Changes by Michel Lespinasse (walken@via.ecp.fr),
36 * Yann Doussot (doussot@via.ecp.fr) and Pascal Andre (andre@via.ecp.fr)
37 * (February 18, 1996) :
38 * + modified shared memory and mmio access port the driver to
39 * alpha platform (structure access -> readb/writeb)
41 * Changes by Steve Kipisz (bungy@ibm.net or kipisz@vnet.ibm.com)
43 * + swapped WWOR and WWCR in ibmtr.h
44 * + moved some init code from tok_probe into trdev_init. The
45 * PCMCIA code can call trdev_init to complete initializing
47 * + added -DPCMCIA to support PCMCIA
48 * + detecting PCMCIA Card Removal in interrupt handler. If
49 * ISRP is FF, then a PCMCIA card has been removed
51 * Changes by Paul Norton (pnorton@cts.com) :
52 * + restructured the READ.LOG logic to prevent the transmit SRB
53 * from being rudely overwritten before the transmit cycle is
54 * complete. (August 15 1996)
55 * + completed multiple adapter support. (November 20 1996)
56 * + implemented csum_partial_copy in tr_rx and increased receive
57 * buffer size and count. Minor fixes. (March 15, 1997)
59 * Changes by Christopher Turcksin <wabbit@rtfc.demon.co.uk>
60 * + Now compiles ok as a module again.
62 * Changes by Paul Norton (pnorton@ieee.org) :
63 * + moved the header manipulation code in tr_tx and tr_rx to
64 * net/802/tr.c. (July 12 1997)
65 * + add retry and timeout on open if cable disconnected. (May 5 1998)
66 * + lifted 2000 byte mtu limit. now depends on shared-RAM size.
68 * + can't allocate 2k recv buff at 8k shared-RAM. (20 October 1998)
70 * Changes by Joel Sloan (jjs@c-me.com) :
71 * + disable verbose debug messages by default - to enable verbose
72 * debugging, edit the IBMTR_DEBUG_MESSAGES define below
74 * Changes by Mike Phillips <phillim@amtrak.com> :
75 * + Added extra #ifdef's to work with new PCMCIA Token Ring Code.
76 * The PCMCIA code now just sets up the card so it can be recognized
77 * by ibmtr_probe. Also checks allocated memory vs. on-board memory
78 * for correct figure to use.
80 * Changes by Tim Hockin (thockin@isunix.it.ilstu.edu) :
81 * + added spinlocks for SMP sanity (10 March 1999)
84 /* change the define of IBMTR_DEBUG_MESSAGES to a nonzero value
85 in the event that chatty debug messages are desired - jjs 12/30/98 */
87 #define IBMTR_DEBUG_MESSAGES 0
93 #include <linux/module.h>
99 #define NO_AUTODETECT 1
105 #define TRUE (!FALSE)
107 /* changes the output format of driver initialisation */
108 #define TR_NEWFORMAT 1
111 /* some 95 OS send many non UI frame; this allow removing the warning */
112 #define TR_FILTERNONUI 1
114 /* version and credits */
115 static char *version
=
116 "ibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n"
117 " v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n"
118 " v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n";
120 static char pcchannelid
[] = {
121 0x05, 0x00, 0x04, 0x09,
122 0x04, 0x03, 0x04, 0x0f,
123 0x03, 0x06, 0x03, 0x01,
124 0x03, 0x01, 0x03, 0x00,
125 0x03, 0x09, 0x03, 0x09,
126 0x03, 0x00, 0x02, 0x00
129 static char mcchannelid
[] = {
130 0x04, 0x0d, 0x04, 0x01,
131 0x05, 0x02, 0x05, 0x03,
132 0x03, 0x06, 0x03, 0x03,
133 0x05, 0x08, 0x03, 0x04,
134 0x03, 0x05, 0x03, 0x01,
135 0x03, 0x08, 0x02, 0x00
138 #include <linux/kernel.h>
139 #include <linux/sched.h>
140 #include <linux/errno.h>
141 #include <linux/timer.h>
142 #include <linux/in.h>
143 #include <linux/ioport.h>
144 #include <linux/string.h>
145 #include <linux/skbuff.h>
146 #include <linux/interrupt.h>
147 #include <linux/delay.h>
148 #include <linux/netdevice.h>
149 #include <linux/trdevice.h>
150 #include <linux/stddef.h>
151 #include <linux/init.h>
152 #include <linux/spinlock.h>
153 #include <net/checksum.h>
156 #include <asm/system.h>
157 #include <asm/bitops.h>
162 #define DPRINTK(format, args...) printk("%s: " format, dev->name , ## args)
163 #define DPRINTD(format, args...) DummyCall("%s: " format, dev->name , ## args)
164 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
165 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
168 /* this allows displaying full adapter information */
170 const char *channel_def
[] __initdata
= {
171 "ISA", "MCA", "ISA P&P"
174 char __init
*adapter_def(char 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)";
188 unsigned char ibmtr_debug_trace
=1; /* Patch or otherwise alter to
189 control tokenring tracing. */
191 unsigned char ibmtr_debug_trace
=0;
193 #define TRC_INIT 0x01 /* Trace initialization & PROBEs */
194 #define TRC_INITV 0x02 /* verbose init trace points */
196 int ibmtr_probe(struct net_device
*dev
);
197 static int ibmtr_probe1(struct net_device
*dev
, int ioaddr
);
198 static unsigned char get_sram_size(struct tok_info
*adapt_info
);
200 extern unsigned char pcmcia_reality_check(unsigned char gss
);
202 static int tok_init_card(struct net_device
*dev
);
203 void tok_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
204 static int trdev_init(struct net_device
*dev
);
205 static void initial_tok_int(struct net_device
*dev
);
206 static void open_sap(unsigned char type
,struct net_device
*dev
);
207 void tok_open_adapter(unsigned long dev_addr
);
208 static void tr_rx(struct net_device
*dev
);
209 static void tr_tx(struct net_device
*dev
);
210 static int tok_open(struct net_device
*dev
);
211 static int tok_close(struct net_device
*dev
);
212 static int tok_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
213 static struct net_device_stats
* tok_get_stats(struct net_device
*dev
);
214 void ibmtr_readlog(struct net_device
*dev
);
215 void ibmtr_reset_timer(struct timer_list
*tmr
, struct net_device
*dev
);
216 int ibmtr_change_mtu(struct net_device
*dev
, int mtu
);
218 static unsigned int ibmtr_portlist
[] __initdata
= {
222 static __u32 ibmtr_mem_base
= 0xd0000;
224 static void __init
PrtChanID(char *pcid
, short stride
)
227 for (i
=0, j
=0; i
<24; i
++, j
+=stride
)
228 printk("%1x", ((int) pcid
[j
]) & 0x0f);
232 static void __init
HWPrtChanID (__u32 pcid
, short stride
)
235 for (i
=0, j
=0; i
<24; i
++, j
+=stride
)
236 printk("%1x", ((int)readb(pcid
+ j
)) & 0x0f);
241 * ibmtr_probe(): Routine specified in the network device structure
242 * to probe for an IBM Token Ring Adapter. Routine outline:
243 * I. Interrogate hardware to determine if an adapter exists
244 * and what the speeds and feeds are
245 * II. Setup data structures to control execution based upon
246 * adapter characteristics.
247 * III. Initialize adapter operation
249 * We expect ibmtr_probe to be called once for each device entry
250 * which references it.
253 int __init
ibmtr_probe(struct net_device
*dev
)
256 int base_addr
= dev
? dev
->base_addr
: 0;
258 if (base_addr
> 0x1ff)
261 * Check a single specified location.
264 if (ibmtr_probe1(dev
, base_addr
))
275 else if (base_addr
!= 0) /* Don't probe at all. */
278 for (i
= 0; ibmtr_portlist
[i
]; i
++)
280 int ioaddr
= ibmtr_portlist
[i
];
281 if (check_region(ioaddr
, IBMTR_IO_EXTENT
))
283 if (ibmtr_probe1(dev
, ioaddr
)) {
296 static int __init
ibmtr_probe1(struct net_device
*dev
, int PIOaddr
)
298 unsigned char segment
=0, intr
=0, irq
=0, i
=0, j
=0, cardpresent
=NOTOK
,temp
=0;
300 struct tok_info
*ti
=0;
302 unsigned char *tchanid
, ctemp
;
303 unsigned long timeout
;
307 dev
= init_trdev(dev
,0);
311 /* Query the adapter PIO base port which will return
312 * indication of where MMIO was placed. We also have a
313 * coded interrupt number.
316 segment
= inb(PIOaddr
);
319 * Out of range values so we'll assume non-existent IO device
322 if (segment
< 0x40 || segment
> 0xe0)
326 * Compute the linear base address of the MMIO area
327 * as LINUX doesn't care about segments
330 t_mmio
=(((__u32
)(segment
& 0xfc) << 11) + 0x80000);
331 intr
= segment
& 0x03; /* low bits is coded interrupt # */
332 if (ibmtr_debug_trace
& TRC_INIT
)
333 DPRINTK("PIOaddr: %4hx seg/intr: %2x mmio base: %08X intr: %d\n",
334 PIOaddr
, (int)segment
, t_mmio
, (int)intr
);
337 * Now we will compare expected 'channelid' strings with
338 * what we is there to learn of ISA/MCA or not TR card
341 cd_chanid
= (CHANNEL_ID
+ t_mmio
); /* for efficiency */
343 cardpresent
=TR_ISA
; /* try ISA */
346 * Suboptimize knowing first byte different
349 ctemp
= readb(cd_chanid
) & 0x0f;
350 if (ctemp
!= *tchanid
) { /* NOT ISA card, try MCA */
353 if (ctemp
!= *tchanid
) /* Neither ISA nor MCA */
357 if (cardpresent
!= NOTOK
)
360 * Know presumed type, try rest of ID
362 for (i
=2,j
=1; i
<=46; i
=i
+2,j
++)
364 if ((readb(cd_chanid
+i
) & 0x0f) != tchanid
[j
]) {
365 cardpresent
=NOTOK
; /* match failed, not TR card */
372 * If we have an ISA board check for the ISA P&P version,
373 * as it has different IRQ settings
376 if (cardpresent
== TR_ISA
&& (readb(AIPFID
+ t_mmio
)==0x0e))
377 cardpresent
=TR_ISAPNP
;
379 if (cardpresent
== NOTOK
) { /* "channel_id" did not match, report */
380 if (ibmtr_debug_trace
& TRC_INIT
) {
381 DPRINTK("Channel ID string not found for PIOaddr: %4hx\n", PIOaddr
);
382 DPRINTK("Expected for ISA: "); PrtChanID(pcchannelid
,1);
383 DPRINTK(" found: "); HWPrtChanID(cd_chanid
,2);
384 DPRINTK("Expected for MCA: "); PrtChanID(mcchannelid
,1);
389 /* Now, allocate some of the pl0 buffers for this driver.. */
391 /* If called from PCMCIA, ti is already set up, so no need to
392 waste the memory, just use the existing structure */
395 ti
= (struct tok_info
*)kmalloc(sizeof(struct tok_info
), GFP_KERNEL
);
399 memset(ti
, 0, sizeof(struct tok_info
));
404 ti
->readlog_pending
= 0;
405 init_waitqueue_head(&ti
->wait_for_tok_int
);
406 init_waitqueue_head(&ti
->wait_for_reset
);
408 dev
->priv
= ti
; /* this seems like the logical use of the
409 field ... let's try some empirical tests
410 using the token-info structure -- that
411 should fit with out future hope of multiple
412 adapter support as well /dwm */
414 /* if PCMCIA, then the card is recognized as TR_ISAPNP
415 * and there is no need to set up the interrupt, it is already done. */
422 irq
=9; /* irq2 really is irq9 */
429 ti
->global_int_enable
=GLOBAL_INT_ENABLE
+((irq
==9) ? 2 : irq
);
430 ti
->adapter_int_enable
=PIOaddr
+ADAPTINTREL
;
433 DPRINTK("ti->global_int_enable: %04X\n",ti
->global_int_enable
);
445 ti
->global_int_enable
=0;
446 ti
->adapter_int_enable
=0;
447 ti
->sram
=((__u32
)(inb(PIOaddr
+ADAPTRESETREL
) & 0xfe) << 12);
458 timeout
= jiffies
+ TR_SPIN_INTERVAL
;
459 while(!readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_EVEN
))
460 if (time_after(jiffies
, timeout
)) {
461 DPRINTK("Hardware timeout during initialization.\n");
462 kfree_s(ti
, sizeof(struct tok_info
));
466 ti
->sram
=((__u32
)readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_EVEN
)<<12);
467 ti
->global_int_enable
=PIOaddr
+ADAPTINTREL
;
468 ti
->adapter_int_enable
=PIOaddr
+ADAPTINTREL
;
473 if (ibmtr_debug_trace
& TRC_INIT
) { /* just report int */
474 DPRINTK("irq=%d",irq
);
475 if (ibmtr_debug_trace
& TRC_INITV
) { /* full chat in verbose only */
476 DPRINTK(", ti->mmio=%08X",ti
->mmio
);
477 printk(", segment=%02X",segment
);
482 /* Get hw address of token ring card */
484 DPRINTK("hw address: ");
487 for (i
=0; i
<0x18; i
=i
+2)
489 /* technical reference states to do this */
490 temp
= readb(ti
->mmio
+ AIP
+ i
) & 0x0f;
492 printk("%1X",ti
->hw_address
[j
]=temp
);
494 ti
->hw_address
[j
]=temp
;
497 dev
->dev_addr
[(j
/2)]=ti
->hw_address
[j
]+(ti
->hw_address
[j
-1]<<4);
504 /* get Adapter type: 'F' = Adapter/A, 'E' = 16/4 Adapter II,...*/
505 ti
->adapter_type
= readb(ti
->mmio
+ AIPADAPTYPE
);
507 /* get Data Rate: F=4Mb, E=16Mb, D=4Mb & 16Mb ?? */
508 ti
->data_rate
= readb(ti
->mmio
+ AIPDATARATE
);
510 /* Get Early Token Release support?: F=no, E=4Mb, D=16Mb, C=4&16Mb */
511 ti
->token_release
= readb(ti
->mmio
+ AIPEARLYTOKEN
);
513 /* How much shared RAM is on adapter ? */
515 ti
->avail_shared_ram
= pcmcia_reality_check(get_sram_size(ti
));
516 ibmtr_mem_base
= ti
->sram_base
<< 12 ;
518 ti
->avail_shared_ram
= get_sram_size(ti
);
520 /* We need to set or do a bunch of work here based on previous results.. */
521 /* Support paging? What sizes?: F=no, E=16k, D=32k, C=16 & 32k */
522 ti
->shared_ram_paging
= readb(ti
->mmio
+ AIPSHRAMPAGE
);
524 /* Available DHB 4Mb size: F=2048, E=4096, D=4464 */
525 switch (readb(ti
->mmio
+ AIP4MBDHB
)) {
527 ti
->dhb_size4mb
= 4096;
530 ti
->dhb_size4mb
= 4464;
533 ti
->dhb_size4mb
= 2048;
537 /* Available DHB 16Mb size: F=2048, E=4096, D=8192, C=16384, B=17960 */
538 switch (readb(ti
->mmio
+ AIP16MBDHB
)) {
540 ti
->dhb_size16mb
= 4096;
543 ti
->dhb_size16mb
= 8192;
546 ti
->dhb_size16mb
= 16384;
549 ti
->dhb_size16mb
= 17960;
552 ti
->dhb_size16mb
= 2048;
557 DPRINTK("atype=%x, drate=%x, trel=%x, asram=%dK, srp=%x, "
558 "dhb(4mb=%x, 16mb=%x)\n",ti
->adapter_type
,
559 ti
->data_rate
, ti
->token_release
, ti
->avail_shared_ram
/2,
560 ti
->shared_ram_paging
, ti
->dhb_size4mb
, ti
->dhb_size16mb
);
563 /* We must figure out how much shared memory space this adapter
564 * will occupy so that if there are two adapters we can fit both
565 * in. Given a choice, we will limit this adapter to 32K. The
566 * maximum space will will use for two adapters is 64K so if the
567 * adapter we are working on demands 64K (it also doesn't support
568 * paging), then only one adapter can be supported.
572 * determine how much of total RAM is mapped into PC space
574 ti
->mapped_ram_size
=1<<((((readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_ODD
)) >>2) & 0x03) + 4);
576 if (ti
->shared_ram_paging
== 0xf) { /* No paging in adapter */
577 ti
->mapped_ram_size
= ti
->avail_shared_ram
;
580 unsigned char pg_size
;
584 DPRINTK("shared ram page size: %dK\n",ti
->mapped_ram_size
/2);
587 switch(ti
->shared_ram_paging
)
592 ti
->page_mask
=(ti
->mapped_ram_size
==32) ? 0xc0 : 0;
593 pg_size
=32; /* 16KB page size */
596 ti
->page_mask
=(ti
->mapped_ram_size
==64) ? 0x80 : 0;
597 pg_size
=64; /* 32KB page size */
600 ti
->page_mask
=(ti
->mapped_ram_size
==32) ? 0xc0 : 0;
601 ti
->page_mask
=(ti
->mapped_ram_size
==64) ? 0x80 : 0;
602 DPRINTK("Dual size shared RAM page (code=0xC), don't support it!\n");
603 /* nb/dwm: I did this because RRR (3,2) bits are documented as
604 R/O and I can't find how to select which page size
605 Also, the above conditional statement sequence is invalid
606 as page_mask will always be set by the second stmt */
607 kfree_s(ti
, sizeof(struct tok_info
));
611 DPRINTK("Unknown shared ram paging info %01X\n",ti
->shared_ram_paging
);
612 kfree_s(ti
, sizeof(struct tok_info
));
617 if (pg_size
> ti
->mapped_ram_size
) {
618 DPRINTK("Page size (%d) > mapped ram window (%d), can't page.\n",
619 pg_size
, ti
->mapped_ram_size
);
620 ti
->page_mask
= 0; /* reset paging */
622 ti
->mapped_ram_size
=ti
->avail_shared_ram
;
623 DPRINTK("Shared RAM paging enabled. Page size : %uK\n",
624 ((ti
->page_mask
^ 0xff)+1)>>2);
628 /* finish figuring the shared RAM address */
629 if (cardpresent
==TR_ISA
) {
630 static __u32 ram_bndry_mask
[]={0xffffe000, 0xffffc000, 0xffff8000, 0xffff0000};
631 __u32 new_base
, rrr_32
, chk_base
, rbm
;
633 rrr_32
= ((readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_ODD
))>>2) & 0x00000003;
634 rbm
= ram_bndry_mask
[rrr_32
];
635 new_base
= (ibmtr_mem_base
+ (~rbm
)) & rbm
; /* up to boundary */
636 chk_base
= new_base
+ (ti
->mapped_ram_size
<<9);
637 if (chk_base
> (ibmtr_mem_base
+ IBMTR_SHARED_RAM_SIZE
)) {
638 DPRINTK("Shared RAM for this adapter (%05x) exceeds driver"
639 " limit (%05x), adapter not started.\n",
640 chk_base
, ibmtr_mem_base
+ IBMTR_SHARED_RAM_SIZE
);
641 kfree_s(ti
, sizeof(struct tok_info
));
643 } else { /* seems cool, record what we have figured out */
644 ti
->sram_base
= new_base
>> 12;
645 ibmtr_mem_base
= chk_base
;
650 DPRINTK("Using %dK shared RAM\n",ti
->mapped_ram_size
/2);
653 /* The PCMCIA has already got the interrupt line and the io port,
654 so no chance of anybody else getting it - MLP */
657 if (request_irq (dev
->irq
= irq
, &tok_interrupt
,0,"ibmtr", dev
) != 0) {
658 DPRINTK("Could not grab irq %d. Halting Token Ring driver.\n",irq
);
659 kfree_s(ti
, sizeof(struct tok_info
));
663 /*?? Now, allocate some of the PIO PORTs for this driver.. */
664 request_region(PIOaddr
,IBMTR_IO_EXTENT
,"ibmtr"); /* record PIOaddr range as busy */
668 DPRINTK("%s",version
); /* As we have passed card identification,
669 let the world know we're here! */
673 printk("%s",version
);
676 DPRINTK("%s %s found\n",
677 channel_def
[cardpresent
-1], adapter_def(ti
->adapter_type
));
678 DPRINTK("using irq %d, PIOaddr %hx, %dK shared RAM.\n",
679 irq
, PIOaddr
, ti
->mapped_ram_size
/2);
680 DPRINTK("Hardware address : %02X:%02X:%02X:%02X:%02X:%02X\n",
681 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
682 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
684 /* Calculate the maximum DHB we can use */
685 switch (ti
->mapped_ram_size
) {
686 case 16 : /* 8KB shared RAM */
687 ti
->dhb_size4mb
= MIN(ti
->dhb_size4mb
, 2048);
688 ti
->rbuf_len4
= 1032;
690 ti
->dhb_size16mb
= MIN(ti
->dhb_size16mb
, 2048);
691 ti
->rbuf_len16
= 1032;
694 case 32 : /* 16KB shared RAM */
695 ti
->dhb_size4mb
= MIN(ti
->dhb_size4mb
, 4464);
698 ti
->dhb_size16mb
= MIN(ti
->dhb_size16mb
, 4096);
699 ti
->rbuf_len16
= 1032; /* 1024 usable */
702 case 64 : /* 32KB shared RAM */
703 ti
->dhb_size4mb
= MIN(ti
->dhb_size4mb
, 4464);
704 ti
->rbuf_len4
= 1032;
706 ti
->dhb_size16mb
= MIN(ti
->dhb_size16mb
, 10240);
707 ti
->rbuf_len16
= 1032;
710 case 127 : /* 63KB shared RAM */
711 ti
->dhb_size4mb
= MIN(ti
->dhb_size4mb
, 4464);
712 ti
->rbuf_len4
= 1032;
714 ti
->dhb_size16mb
= MIN(ti
->dhb_size16mb
, 16384);
715 ti
->rbuf_len16
= 1032;
718 case 128 : /* 64KB shared RAM */
719 ti
->dhb_size4mb
= MIN(ti
->dhb_size4mb
, 4464);
720 ti
->rbuf_len4
= 1032;
722 ti
->dhb_size16mb
= MIN(ti
->dhb_size16mb
, 17960);
723 ti
->rbuf_len16
= 1032;
727 ti
->dhb_size4mb
= 2048;
728 ti
->rbuf_len4
= 1032;
730 ti
->dhb_size16mb
= 2048;
731 ti
->rbuf_len16
= 1032;
736 ti
->maxmtu16
= (ti
->rbuf_len16
*ti
->rbuf_cnt16
)-((ti
->rbuf_cnt16
)<<3)-TR_HLEN
;
737 ti
->maxmtu4
= (ti
->rbuf_len4
*ti
->rbuf_cnt4
)-((ti
->rbuf_cnt4
)<<3)-TR_HLEN
;
738 DPRINTK("Maximum MTU 16Mbps: %d, 4Mbps: %d\n",
739 ti
->maxmtu16
, ti
->maxmtu4
);
741 dev
->base_addr
=PIOaddr
; /* set the value for device */
746 return 0; /* Return 0 to indicate we have found a Token Ring card. */
749 /* query the adapter for the size of shared RAM */
751 static unsigned char __init
get_sram_size(struct tok_info
*adapt_info
)
754 unsigned char avail_sram_code
;
755 static unsigned char size_code
[]={ 0,16,32,64,127,128 };
757 'F' -- use RRR bits 3,2
758 'E' -- 8kb 'D' -- 16kb
759 'C' -- 32kb 'A' -- 64KB
760 'B' - 64KB less 512 bytes at top
761 (WARNING ... must zero top bytes in INIT */
763 avail_sram_code
=0xf-readb(adapt_info
->mmio
+ AIPAVAILSHRAM
);
765 return size_code
[avail_sram_code
];
766 else /* for code 'F', must compute size from RRR(3,2) bits */
767 return 1<<((readb(adapt_info
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_ODD
)>>2)+4);
770 static int __init
trdev_init(struct net_device
*dev
)
772 struct tok_info
*ti
=(struct tok_info
*)dev
->priv
;
774 ti
->open_status
= CLOSED
;
776 dev
->init
= tok_init_card
;
777 dev
->open
= tok_open
;
778 dev
->stop
= tok_close
;
779 dev
->hard_start_xmit
= tok_send_packet
;
780 dev
->get_stats
= tok_get_stats
;
781 dev
->set_multicast_list
= NULL
;
782 dev
->change_mtu
= ibmtr_change_mtu
;
794 static int tok_open(struct net_device
*dev
)
796 struct tok_info
*ti
=(struct tok_info
*)dev
->priv
;
798 /* init the spinlock */
799 ti
->lock
= (spinlock_t
) SPIN_LOCK_UNLOCKED
;
801 if (ti
->open_status
==CLOSED
) tok_init_card(dev
);
803 if (ti
->open_status
==IN_PROGRESS
) sleep_on(&ti
->wait_for_reset
);
805 if (ti
->open_status
==SUCCESS
) {
809 /* NEED to see smem size *AND* reset high 512 bytes if needed */
814 } else return -EAGAIN
;
818 static int tok_close(struct net_device
*dev
)
821 struct tok_info
*ti
=(struct tok_info
*) dev
->priv
;
823 writeb(DIR_CLOSE_ADAPTER
,
824 ti
->srb
+ offsetof(struct srb_close_adapter
, command
));
825 writeb(CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
827 ti
->open_status
=CLOSED
;
829 sleep_on(&ti
->wait_for_tok_int
);
831 if (readb(ti
->srb
+ offsetof(struct srb_close_adapter
, ret_code
)))
832 DPRINTK("close adapter failed: %02X\n",
833 (int)readb(ti
->srb
+ offsetof(struct srb_close_adapter
, ret_code
)));
839 DPRINTK("Adapter closed.\n");
845 void tok_interrupt (int irq
, void *dev_id
, struct pt_regs
*regs
)
847 unsigned char status
;
849 struct net_device
*dev
;
853 DPRINTK("Int from tok_driver, dev : %p\n",dev
);
855 ti
= (struct tok_info
*) dev
->priv
;
856 spin_lock(&(ti
->lock
));
858 /* Disable interrupts till processing is finished */
860 writeb((~INT_ENABLE
), ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_EVEN
);
862 /* Reset interrupt for ISA boards */
863 if (ti
->adapter_int_enable
)
864 outb(0,ti
->adapter_int_enable
);
866 outb(0,ti
->global_int_enable
);
869 switch (ti
->do_tok_int
) {
873 /* Begin the regular interrupt handler HERE inline to avoid
874 the extra levels of logic and call depth for the
875 original solution. */
877 status
=readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ ISRP_ODD
);
879 /* Check if the PCMCIA card was pulled. */
882 DPRINTK("PCMCIA card removed.\n");
883 spin_unlock(&(ti
->lock
));
888 /* Check ISRP EVEN too. */
889 if ( readb (ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ ISRP_EVEN
) == 0xFF)
891 DPRINTK("PCMCIA card removed.\n");
892 spin_unlock(&(ti
->lock
));
899 if (status
& ADAP_CHK_INT
) {
904 check_reason
=ti
->mmio
+ ntohs(readw(ti
->sram
+ ACA_OFFSET
+ ACA_RW
+WWCR_EVEN
));
906 DPRINTK("Adapter check interrupt\n");
907 DPRINTK("8 reason bytes follow: ");
908 for(i
=0; i
<8; i
++, check_reason
++)
909 printk("%02X ", (int)readb(check_reason
));
912 writeb((~ADAP_CHK_INT
), ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
913 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
916 } else if (readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ ISRP_EVEN
)
917 & (TCR_INT
| ERR_INT
| ACCESS_INT
)) {
919 DPRINTK("adapter error: ISRP_EVEN : %02x\n",
920 (int)readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ ISRP_EVEN
));
921 writeb(~(TCR_INT
| ERR_INT
| ACCESS_INT
),
922 ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_EVEN
);
923 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
927 & (SRB_RESP_INT
| ASB_FREE_INT
| ARB_CMD_INT
| SSB_RESP_INT
)) {
928 /* SRB, ASB, ARB or SSB response */
930 if (status
& SRB_RESP_INT
) { /* SRB response */
932 switch(readb(ti
->srb
)) { /* SRB command check */
934 case XMIT_DIR_FRAME
: {
935 unsigned char xmit_ret_code
;
937 xmit_ret_code
=readb(ti
->srb
+ offsetof(struct srb_xmit
, ret_code
));
938 if (xmit_ret_code
!= 0xff) {
939 DPRINTK("error on xmit_dir_frame request: %02X\n",
941 if (ti
->current_skb
) {
942 dev_kfree_skb(ti
->current_skb
);
943 ti
->current_skb
=NULL
;
946 if (ti
->readlog_pending
) ibmtr_readlog(dev
);
951 case XMIT_UI_FRAME
: {
952 unsigned char xmit_ret_code
;
954 xmit_ret_code
=readb(ti
->srb
+ offsetof(struct srb_xmit
, ret_code
));
955 if (xmit_ret_code
!= 0xff) {
956 DPRINTK("error on xmit_ui_frame request: %02X\n",
958 if (ti
->current_skb
) {
959 dev_kfree_skb(ti
->current_skb
);
960 ti
->current_skb
=NULL
;
963 if (ti
->readlog_pending
) ibmtr_readlog(dev
);
968 case DIR_OPEN_ADAPTER
: {
969 unsigned char open_ret_code
;
970 __u16 open_error_code
;
972 ti
->srb
=ti
->sram
+ntohs(readw(ti
->init_srb
+offsetof(struct srb_open_response
, srb_addr
)));
973 ti
->ssb
=ti
->sram
+ntohs(readw(ti
->init_srb
+offsetof(struct srb_open_response
, ssb_addr
)));
974 ti
->arb
=ti
->sram
+ntohs(readw(ti
->init_srb
+offsetof(struct srb_open_response
, arb_addr
)));
975 ti
->asb
=ti
->sram
+ntohs(readw(ti
->init_srb
+offsetof(struct srb_open_response
, asb_addr
)));
976 ti
->current_skb
=NULL
;
978 open_ret_code
= readb(ti
->init_srb
+offsetof(struct srb_open_response
, ret_code
));
979 open_error_code
= ntohs(readw(ti
->init_srb
+offsetof(struct srb_open_response
, error_code
)));
981 if (open_ret_code
==7) {
983 if (!ti
->auto_ringspeedsave
&& (open_error_code
==0x24)) {
984 DPRINTK("Open failed: Adapter speed must match ring "
985 "speed if Automatic Ring Speed Save is disabled.\n");
986 ti
->open_status
=FAILURE
;
987 wake_up(&ti
->wait_for_reset
);
988 } else if (open_error_code
==0x24)
989 DPRINTK("Retrying open to adjust to ring speed.\n");
990 else if ((open_error_code
==0x2d) && ti
->auto_ringspeedsave
)
991 DPRINTK("No signal detected for Auto Speed Detection.\n");
992 else if (open_error_code
==0x11)
994 if (ti
->retry_count
--)
995 DPRINTK("Ring broken/disconnected, retrying...\n");
997 DPRINTK("Ring broken/disconnected, open failed.\n");
998 ti
->open_status
= FAILURE
;
1001 else DPRINTK("Unrecoverable error: error code = %04x.\n",
1004 } else if (!open_ret_code
) {
1006 DPRINTK("board opened...\n");
1008 DPRINTK("Adapter initialized and opened.\n");
1010 writeb(~(SRB_RESP_INT
),
1011 ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1012 writeb(~(CMD_IN_SRB
),
1013 ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRA_ODD
);
1014 open_sap(EXTENDED_SAP
,dev
);
1016 /* YdW probably hates me */
1019 DPRINTK("open failed: ret_code = %02X, retrying\n",
1022 if (ti
->open_status
!= FAILURE
) {
1023 ibmtr_reset_timer(&(ti
->tr_timer
), dev
);
1029 case DIR_CLOSE_ADAPTER
:
1030 wake_up(&ti
->wait_for_tok_int
);
1034 if (readb(ti
->srb
+offsetof(struct dlc_open_sap
, ret_code
))) {
1035 DPRINTK("open_sap failed: ret_code = %02X,retrying\n",
1036 (int)readb(ti
->srb
+offsetof(struct dlc_open_sap
, ret_code
)));
1037 ibmtr_reset_timer(&(ti
->tr_timer
), dev
);
1039 ti
->exsap_station_id
=
1040 readw(ti
->srb
+offsetof(struct dlc_open_sap
, station_id
));
1041 ti
->open_status
=SUCCESS
; /* TR adapter is now available */
1042 wake_up(&ti
->wait_for_reset
);
1047 case DIR_MOD_OPEN_PARAMS
:
1048 case DIR_SET_GRP_ADDR
:
1049 case DIR_SET_FUNC_ADDR
:
1051 if (readb(ti
->srb
+offsetof(struct srb_interrupt
, ret_code
)))
1052 DPRINTK("error on %02X: %02X\n",
1053 (int)readb(ti
->srb
+offsetof(struct srb_interrupt
, command
)),
1054 (int)readb(ti
->srb
+offsetof(struct srb_interrupt
, ret_code
)));
1058 if (readb(ti
->srb
+offsetof(struct srb_read_log
, ret_code
)))
1059 DPRINTK("error on dir_read_log: %02X\n",
1060 (int)readb(ti
->srb
+offsetof(struct srb_read_log
, ret_code
)));
1062 if (IBMTR_DEBUG_MESSAGES
) {
1064 "Line errors %02X, Internal errors %02X, Burst errors %02X\n"
1065 "A/C errors %02X, Abort delimiters %02X, Lost frames %02X\n"
1066 "Receive congestion count %02X, Frame copied errors %02X\n"
1067 "Frequency errors %02X, Token errors %02X\n",
1068 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1070 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1072 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1074 (int)readb(ti
->srb
+offsetof(struct srb_read_log
, A_C_errors
)),
1075 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1077 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1079 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1080 recv_congest_count
)),
1081 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1082 frame_copied_errors
)),
1083 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1085 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1092 DPRINTK("Unknown command %02X encountered\n",
1093 (int)readb(ti
->srb
));
1095 } /* SRB command check */
1097 writeb(~CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRA_ODD
);
1098 writeb(~SRB_RESP_INT
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1101 } /* SRB response */
1103 if (status
& ASB_FREE_INT
) { /* ASB response */
1105 switch(readb(ti
->asb
)) { /* ASB command check */
1109 case XMIT_DIR_FRAME
:
1113 DPRINTK("unknown command in asb %02X\n",
1114 (int)readb(ti
->asb
));
1116 } /* ASB command check */
1118 if (readb(ti
->asb
+2)!=0xff) /* checks ret_code */
1119 DPRINTK("ASB error %02X in cmd %02X\n",
1120 (int)readb(ti
->asb
+2),(int)readb(ti
->asb
));
1121 writeb(~ASB_FREE_INT
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1123 } /* ASB response */
1125 if (status
& ARB_CMD_INT
) { /* ARB response */
1127 switch (readb(ti
->arb
)) { /* ARB command check */
1130 DPRINTK("DLC_STATUS new status: %02X on station %02X\n",
1131 ntohs(readw(ti
->arb
+ offsetof(struct arb_dlc_status
, status
))),
1133 +offsetof(struct arb_dlc_status
, station_id
))));
1140 case RING_STAT_CHANGE
: {
1141 unsigned short ring_status
;
1143 ring_status
=ntohs(readw(ti
->arb
1144 +offsetof(struct arb_ring_stat_change
, ring_status
)));
1146 if (ring_status
& (SIGNAL_LOSS
| LOBE_FAULT
)) {
1148 DPRINTK("Signal loss/Lobe fault\n");
1149 DPRINTK("We try to reopen the adapter.\n");
1150 ibmtr_reset_timer(&(ti
->tr_timer
), dev
);
1151 } else if (ring_status
& (HARD_ERROR
| XMIT_BEACON
1152 | AUTO_REMOVAL
| REMOVE_RECV
| RING_RECOVER
))
1153 DPRINTK("New ring status: %02X\n", ring_status
);
1155 if (ring_status
& LOG_OVERFLOW
) {
1157 ti
->readlog_pending
= 1;
1169 DPRINTK("Unknown command %02X in arb\n",
1170 (int)readb(ti
->arb
));
1173 } /* ARB command check */
1175 writeb(~ARB_CMD_INT
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1176 writeb(ARB_FREE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1178 } /* ARB response */
1180 if (status
& SSB_RESP_INT
) { /* SSB response */
1181 unsigned char retcode
;
1182 switch (readb(ti
->ssb
)) { /* SSB command check */
1184 case XMIT_DIR_FRAME
:
1186 retcode
= readb(ti
->ssb
+2);
1187 if (retcode
&& (retcode
!= 0x22)) /* checks ret_code */
1188 DPRINTK("xmit ret_code: %02X xmit error code: %02X\n",
1189 (int)retcode
, (int)readb(ti
->ssb
+6));
1190 else ti
->tr_stats
.tx_packets
++;
1194 DPRINTK("xmit xid ret_code: %02X\n", (int)readb(ti
->ssb
+2));
1197 DPRINTK("Unknown command %02X in ssb\n", (int)readb(ti
->ssb
));
1199 } /* SSB command check */
1201 writeb(~SSB_RESP_INT
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1202 writeb(SSB_FREE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1204 } /* SSB response */
1206 } /* SRB, ARB, ASB or SSB response */
1209 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
1213 initial_tok_int(dev
);
1217 DPRINTK("Unexpected interrupt from tr adapter\n");
1220 spin_unlock(&(ti
->lock
));
1223 static void initial_tok_int(struct net_device
*dev
)
1227 __u32 hw_encoded_addr
;
1228 struct tok_info
*ti
;
1229 ti
=(struct tok_info
*) dev
->priv
;
1231 ti
->do_tok_int
=NOT_FIRST
;
1233 #ifndef TR_NEWFORMAT
1234 DPRINTK("Initial tok int received\n");
1237 /* we assign the shared-ram address for ISA devices */
1239 writeb(ti
->sram_base
, ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_EVEN
);
1240 ti
->sram
=((__u32
)ti
->sram_base
<< 12);
1242 ti
->init_srb
=ti
->sram
1243 +ntohs((unsigned short)readw(ti
->mmio
+ ACA_OFFSET
+ WRBR_EVEN
));
1244 SET_PAGE(ntohs((unsigned short)readw(ti
->mmio
+ACA_OFFSET
+ WRBR_EVEN
)));
1246 dev
->mem_start
= ti
->sram
;
1247 dev
->mem_end
= ti
->sram
+ (ti
->mapped_ram_size
<<9) - 1;
1252 DPRINTK("init_srb(%p):", ti
->init_srb
);
1253 for (i
=0;i
<17;i
++) printk("%02X ", (int)readb(ti
->init_srb
+i
));
1258 hw_encoded_addr
= readw(ti
->init_srb
1259 + offsetof(struct srb_init_response
, encoded_address
));
1262 DPRINTK("srb_init_response->encoded_address: %04X\n", hw_encoded_addr
);
1263 DPRINTK("ntohs(srb_init_response->encoded_address): %04X\n",
1264 ntohs(hw_encoded_addr
));
1267 encoded_addr
=(ti
->sram
+ ntohs(hw_encoded_addr
));
1268 ti
->ring_speed
= readb(ti
->init_srb
+offsetof(struct srb_init_response
, init_status
)) & 0x01 ? 16 : 4;
1270 DPRINTK("encoded addr (%04X,%04X,%08X): ", hw_encoded_addr
,
1271 ntohs(hw_encoded_addr
), encoded_addr
);
1273 DPRINTK("Initial interrupt : %d Mbps, shared RAM base %08x.\n",
1274 ti
->ring_speed
, ti
->sram
);
1277 ti
->auto_ringspeedsave
=readb(ti
->init_srb
1278 +offsetof(struct srb_init_response
, init_status_2
)) & 0x4 ? TRUE
: FALSE
;
1281 for(i
=0;i
<TR_ALEN
;i
++) {
1282 dev
->dev_addr
[i
]=readb(encoded_addr
+ i
);
1283 printk("%02X%s", dev
->dev_addr
[i
], (i
==TR_ALEN
-1) ? "" : ":" );
1288 tok_open_adapter((unsigned long)dev
);
1291 static int tok_init_card(struct net_device
*dev
)
1293 struct tok_info
*ti
;
1296 PIOaddr
= dev
->base_addr
;
1297 ti
=(struct tok_info
*) dev
->priv
;
1299 /* Special processing for first interrupt after reset */
1300 ti
->do_tok_int
=FIRST_INT
;
1303 dev
->tbusy
=1; /* nothing can be done before reset and open completed */
1305 #ifdef ENABLE_PAGING
1307 writeb(SRPR_ENABLE_PAGING
, ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ SRPR_EVEN
);
1310 writeb(~INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_EVEN
);
1313 DPRINTK("resetting card\n");
1316 outb(0, PIOaddr
+ADAPTRESET
);
1317 for (i
=jiffies
+TR_RESET_INTERVAL
; time_before_eq(jiffies
, i
);); /* wait 50ms */
1318 outb(0,PIOaddr
+ADAPTRESETREL
);
1321 DPRINTK("card reset\n");
1324 ti
->open_status
=IN_PROGRESS
;
1325 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
1329 static void open_sap(unsigned char type
,struct net_device
*dev
)
1332 struct tok_info
*ti
=(struct tok_info
*) dev
->priv
;
1335 for (i
=0; i
<sizeof(struct dlc_open_sap
); i
++)
1336 writeb(0, ti
->srb
+i
);
1338 writeb(DLC_OPEN_SAP
, ti
->srb
+ offsetof(struct dlc_open_sap
, command
));
1339 writew(htons(MAX_I_FIELD
),
1340 ti
->srb
+ offsetof(struct dlc_open_sap
, max_i_field
));
1341 writeb(SAP_OPEN_IND_SAP
| SAP_OPEN_PRIORITY
,
1342 ti
->srb
+ offsetof(struct dlc_open_sap
, sap_options
));
1343 writeb(SAP_OPEN_STATION_CNT
,
1344 ti
->srb
+ offsetof(struct dlc_open_sap
, station_count
));
1345 writeb(type
, ti
->srb
+ offsetof(struct dlc_open_sap
, sap_value
));
1347 writeb(CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1351 void tok_open_adapter(unsigned long dev_addr
)
1354 struct net_device
*dev
=(struct net_device
*)dev_addr
;
1355 struct tok_info
*ti
;
1358 ti
=(struct tok_info
*) dev
->priv
;
1361 DPRINTK("now opening the board...\n");
1364 writeb(~SRB_RESP_INT
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1365 writeb(~CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRA_ODD
);
1367 for (i
=0; i
<sizeof(struct dir_open_adapter
); i
++)
1368 writeb(0, ti
->init_srb
+i
);
1370 writeb(DIR_OPEN_ADAPTER
,
1371 ti
->init_srb
+ offsetof(struct dir_open_adapter
, command
));
1372 writew(htons(OPEN_PASS_BCON_MAC
),
1373 ti
->init_srb
+ offsetof(struct dir_open_adapter
, open_options
));
1374 if (ti
->ring_speed
== 16) {
1375 writew(htons(ti
->dhb_size16mb
),
1376 ti
->init_srb
+ offsetof(struct dir_open_adapter
, dhb_length
));
1377 writew(htons(ti
->rbuf_cnt16
),
1378 ti
->init_srb
+ offsetof(struct dir_open_adapter
, num_rcv_buf
));
1379 writew(htons(ti
->rbuf_len16
),
1380 ti
->init_srb
+ offsetof(struct dir_open_adapter
, rcv_buf_len
));
1382 writew(htons(ti
->dhb_size4mb
),
1383 ti
->init_srb
+ offsetof(struct dir_open_adapter
, dhb_length
));
1384 writew(htons(ti
->rbuf_cnt4
),
1385 ti
->init_srb
+ offsetof(struct dir_open_adapter
, num_rcv_buf
));
1386 writew(htons(ti
->rbuf_len4
),
1387 ti
->init_srb
+ offsetof(struct dir_open_adapter
, rcv_buf_len
));
1389 writeb(NUM_DHB
, /* always 2 */
1390 ti
->init_srb
+ offsetof(struct dir_open_adapter
, num_dhb
));
1392 ti
->init_srb
+ offsetof(struct dir_open_adapter
, dlc_max_sap
));
1394 ti
->init_srb
+ offsetof(struct dir_open_adapter
, dlc_max_sta
));
1396 ti
->srb
=ti
->init_srb
; /* We use this one in the interrupt handler */
1398 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
1399 writeb(CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1403 static void tr_tx(struct net_device
*dev
)
1405 struct tok_info
*ti
=(struct tok_info
*) dev
->priv
;
1406 struct trh_hdr
*trhdr
=(struct trh_hdr
*)ti
->current_skb
->data
;
1407 unsigned int hdr_len
;
1409 unsigned char xmit_command
;
1413 if (readb(ti
->asb
+ offsetof(struct asb_xmit_resp
, ret_code
))!=0xFF)
1414 DPRINTK("ASB not free !!!\n");
1416 /* in providing the transmit interrupts,
1417 is telling us it is ready for data and
1418 providing a shared memory address for us
1419 to stuff with data. Here we compute the
1420 effective address where we will place data.*/
1422 +ntohs(readw(ti
->arb
+ offsetof(struct arb_xmit_req
, dhb_address
)));
1424 /* Figure out the size of the 802.5 header */
1425 if (!(trhdr
->saddr
[0] & 0x80)) /* RIF present? */
1426 hdr_len
=sizeof(struct trh_hdr
)-TR_MAXRIFLEN
;
1428 hdr_len
=((ntohs(trhdr
->rcf
) & TR_RCF_LEN_MASK
)>>8)
1429 +sizeof(struct trh_hdr
)-TR_MAXRIFLEN
;
1431 llc
= (struct trllc
*)(ti
->current_skb
->data
+ hdr_len
);
1433 xmit_command
= readb(ti
->srb
+ offsetof(struct srb_xmit
, command
));
1435 writeb(xmit_command
, ti
->asb
+ offsetof(struct asb_xmit_resp
, command
));
1436 writew(readb(ti
->srb
+ offsetof(struct srb_xmit
, station_id
)),
1437 ti
->asb
+ offsetof(struct asb_xmit_resp
, station_id
));
1438 writeb(llc
->ssap
, ti
->asb
+ offsetof(struct asb_xmit_resp
, rsap_value
));
1439 writeb(readb(ti
->srb
+ offsetof(struct srb_xmit
, cmd_corr
)),
1440 ti
->asb
+ offsetof(struct asb_xmit_resp
, cmd_corr
));
1441 writeb(0, ti
->asb
+ offsetof(struct asb_xmit_resp
, ret_code
));
1443 if ((xmit_command
==XMIT_XID_CMD
) || (xmit_command
==XMIT_TEST_CMD
)) {
1446 ti
->asb
+ offsetof(struct asb_xmit_resp
, frame_length
));
1447 writeb(0x0e, ti
->asb
+ offsetof(struct asb_xmit_resp
, hdr_length
));
1449 writeb(LLC_FRAME
, dhb
+1);
1451 for (i
=0; i
<TR_ALEN
; i
++) writeb((int)0x0FF, dhb
+i
+2);
1452 for (i
=0; i
<TR_ALEN
; i
++) writeb(0, dhb
+i
+TR_ALEN
+2);
1454 writeb(RESP_IN_ASB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1460 * the token ring packet is copied from sk_buff to the adapter
1461 * buffer identified in the command data received with the interrupt.
1463 writeb(hdr_len
, ti
->asb
+ offsetof(struct asb_xmit_resp
, hdr_length
));
1464 writew(htons(ti
->current_skb
->len
),
1465 ti
->asb
+ offsetof(struct asb_xmit_resp
, frame_length
));
1467 memcpy_toio(dhb
, ti
->current_skb
->data
, ti
->current_skb
->len
);
1469 writeb(RESP_IN_ASB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1470 ti
->tr_stats
.tx_bytes
+=ti
->current_skb
->len
;
1472 dev_kfree_skb(ti
->current_skb
);
1473 ti
->current_skb
=NULL
;
1475 if (ti
->readlog_pending
) ibmtr_readlog(dev
);
1478 static void tr_rx(struct net_device
*dev
)
1480 struct tok_info
*ti
=(struct tok_info
*) dev
->priv
;
1481 __u32 rbuffer
, rbufdata
;
1483 unsigned char *data
;
1484 unsigned int rbuffer_len
, lan_hdr_len
, hdr_len
, ip_len
, length
;
1485 struct sk_buff
*skb
;
1486 unsigned int skb_size
= 0;
1488 unsigned int chksum
= 0;
1492 +ntohs(readw(ti
->arb
+ offsetof(struct arb_rec_req
, rec_buf_addr
))))+2;
1494 if(readb(ti
->asb
+ offsetof(struct asb_rec
, ret_code
))!=0xFF)
1495 DPRINTK("ASB not free !!!\n");
1498 ti
->asb
+ offsetof(struct asb_rec
, command
));
1499 writew(readw(ti
->arb
+ offsetof(struct arb_rec_req
, station_id
)),
1500 ti
->asb
+ offsetof(struct asb_rec
, station_id
));
1501 writew(readw(ti
->arb
+ offsetof(struct arb_rec_req
, rec_buf_addr
)),
1502 ti
->asb
+ offsetof(struct asb_rec
, rec_buf_addr
));
1504 lan_hdr_len
=readb(ti
->arb
+ offsetof(struct arb_rec_req
, lan_hdr_len
));
1505 hdr_len
= lan_hdr_len
+ sizeof(struct trllc
) + sizeof(struct iphdr
);
1507 llc
=(rbuffer
+ offsetof(struct rec_buf
, data
) + lan_hdr_len
);
1510 DPRINTK("offsetof data: %02X lan_hdr_len: %02X\n",
1511 (unsigned int)offsetof(struct rec_buf
,data
), (unsigned int)lan_hdr_len
);
1512 DPRINTK("llc: %08X rec_buf_addr: %04X ti->sram: %p\n", llc
,
1513 ntohs(readw(ti
->arb
+ offsetof(struct arb_rec_req
, rec_buf_addr
))),
1515 DPRINTK("dsap: %02X, ssap: %02X, llc: %02X, protid: %02X%02X%02X, "
1516 "ethertype: %04X\n",
1517 (int)readb(llc
+ offsetof(struct trllc
, dsap
)),
1518 (int)readb(llc
+ offsetof(struct trllc
, ssap
)),
1519 (int)readb(llc
+ offsetof(struct trllc
, llc
)),
1520 (int)readb(llc
+ offsetof(struct trllc
, protid
)),
1521 (int)readb(llc
+ offsetof(struct trllc
, protid
)+1),
1522 (int)readb(llc
+ offsetof(struct trllc
, protid
)+2),
1523 (int)readw(llc
+ offsetof(struct trllc
, ethertype
)));
1525 if (readb(llc
+ offsetof(struct trllc
, llc
))!=UI_CMD
) {
1526 writeb(DATA_LOST
, ti
->asb
+ offsetof(struct asb_rec
, ret_code
));
1527 ti
->tr_stats
.rx_dropped
++;
1528 writeb(RESP_IN_ASB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1532 length
= ntohs(readw(ti
->arb
+offsetof(struct arb_rec_req
, frame_len
)));
1533 if ((readb(llc
+ offsetof(struct trllc
, dsap
))==EXTENDED_SAP
) &&
1534 (readb(llc
+ offsetof(struct trllc
, ssap
))==EXTENDED_SAP
) &&
1535 (length
>=hdr_len
)) {
1544 trhhdr
=(rbuffer
+offsetof(struct rec_buf
,data
));
1546 DPRINTK("Probably non-IP frame received.\n");
1547 DPRINTK("ssap: %02X dsap: %02X saddr: %02X:%02X:%02X:%02X:%02X:%02X "
1548 "daddr: %02X:%02X:%02X:%02X:%02X:%02X\n",
1549 (int)readb(llc
+ offsetof(struct trllc
, ssap
)),
1550 (int)readb(llc
+ offsetof(struct trllc
, dsap
)),
1551 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)),
1552 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)+1),
1553 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)+2),
1554 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)+3),
1555 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)+4),
1556 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)+5),
1557 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)),
1558 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)+1),
1559 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)+2),
1560 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)+3),
1561 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)+4),
1562 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)+5));
1566 skb_size
= length
-lan_hdr_len
+sizeof(struct trh_hdr
)+sizeof(struct trllc
);
1568 if (!(skb
=dev_alloc_skb(skb_size
))) {
1569 DPRINTK("out of memory. frame dropped.\n");
1570 ti
->tr_stats
.rx_dropped
++;
1571 writeb(DATA_LOST
, ti
->asb
+ offsetof(struct asb_rec
, ret_code
));
1572 writeb(RESP_IN_ASB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1576 skb_put(skb
, length
);
1577 skb_reserve(skb
, sizeof(struct trh_hdr
)-lan_hdr_len
+sizeof(struct trllc
));
1580 rbuffer_len
=ntohs(readw(rbuffer
+ offsetof(struct rec_buf
, buf_len
)));
1581 rbufdata
= rbuffer
+ offsetof(struct rec_buf
,data
);
1584 /* Copy the headers without checksumming */
1585 memcpy_fromio(data
, rbufdata
, hdr_len
);
1587 /* Watch for padded packets and bogons */
1588 iph
=(struct iphdr
*)(data
+ lan_hdr_len
+ sizeof(struct trllc
));
1589 ip_len
= ntohs(iph
->tot_len
) - sizeof(struct iphdr
);
1591 if ((ip_len
<= length
) && (ip_len
> 7))
1594 rbuffer_len
-= hdr_len
;
1595 rbufdata
+= hdr_len
;
1598 /* Copy the payload... */
1601 chksum
= csum_partial_copy(bus_to_virt(rbufdata
), data
,
1602 length
< rbuffer_len
? length
: rbuffer_len
,
1605 memcpy_fromio(data
, rbufdata
, rbuffer_len
);
1606 rbuffer
= ntohs(readw(rbuffer
));
1609 length
-= rbuffer_len
;
1610 data
+= rbuffer_len
;
1611 rbuffer
+= ti
->sram
;
1612 rbuffer_len
= ntohs(readw(rbuffer
+ offsetof(struct rec_buf
, buf_len
)));
1613 rbufdata
= rbuffer
+ offsetof(struct rec_buf
, data
);
1616 writeb(0, ti
->asb
+ offsetof(struct asb_rec
, ret_code
));
1618 writeb(RESP_IN_ASB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1620 ti
->tr_stats
.rx_bytes
+= skb
->len
;
1621 ti
->tr_stats
.rx_packets
++;
1623 skb
->protocol
= tr_type_trans(skb
,dev
);
1633 static int tok_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1635 struct tok_info
*ti
;
1636 ti
=(struct tok_info
*) dev
->priv
;
1641 ticks_waited
=jiffies
- dev
->trans_start
;
1642 if (ticks_waited
<TR_BUSY_INTERVAL
) return 1;
1644 DPRINTK("Arrg. Transmitter busy.\n");
1645 dev
->trans_start
+=5; /* we fake the transmission start time... */
1649 if (test_and_set_bit(0,(void *)&dev
->tbusy
)!=0)
1650 DPRINTK("Transmitter access conflict\n");
1654 /* lock against other CPUs */
1655 spin_lock_irqsave(&(ti
->lock
), flags
);
1657 /* Save skb; we'll need it when the adapter asks for the data */
1658 ti
->current_skb
=skb
;
1659 writeb(XMIT_UI_FRAME
, ti
->srb
+ offsetof(struct srb_xmit
, command
));
1660 writew(ti
->exsap_station_id
, ti
->srb
1661 +offsetof(struct srb_xmit
, station_id
));
1662 writeb(CMD_IN_SRB
, (ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
));
1663 spin_unlock_irqrestore(&(ti
->lock
), flags
);
1665 dev
->trans_start
=jiffies
;
1671 void ibmtr_reset_timer(struct timer_list
*tmr
, struct net_device
*dev
) {
1672 tmr
->expires
= jiffies
+ TR_RETRY_INTERVAL
;
1673 tmr
->data
= (unsigned long) dev
;
1674 tmr
->function
= tok_open_adapter
;
1679 void ibmtr_readlog(struct net_device
*dev
) {
1680 struct tok_info
*ti
;
1681 ti
=(struct tok_info
*) dev
->priv
;
1683 ti
->readlog_pending
= 0;
1684 writeb(DIR_READ_LOG
, ti
->srb
);
1685 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
1686 writeb(CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1687 dev
->tbusy
=1; /* really srb busy... */
1690 /* tok_get_stats(): Basically a scaffold routine which will return
1691 the address of the tr_statistics structure associated with
1692 this device -- the tr.... structure is an ethnet look-alike
1693 so at least for this iteration may suffice. */
1695 static struct net_device_stats
* tok_get_stats(struct net_device
*dev
) {
1697 struct tok_info
*toki
;
1698 toki
=(struct tok_info
*) dev
->priv
;
1699 return (struct net_device_stats
*) &toki
->tr_stats
;
1702 int ibmtr_change_mtu(struct net_device
*dev
, int mtu
) {
1703 struct tok_info
*ti
= (struct tok_info
*) dev
->priv
;
1705 if (ti
->ring_speed
== 16 && mtu
> ti
->maxmtu16
)
1707 if (ti
->ring_speed
== 4 && mtu
> ti
->maxmtu4
)
1715 /* 3COM 3C619C supports 8 interrupts, 32 I/O ports */
1716 static struct net_device
* dev_ibmtr
[IBMTR_MAX_ADAPTERS
];
1717 static int io
[IBMTR_MAX_ADAPTERS
] = {0xa20,0xa24};
1718 static int irq
[IBMTR_MAX_ADAPTERS
] = {0,0};
1719 static int mem
[IBMTR_MAX_ADAPTERS
] = {0,0};
1721 MODULE_PARM(io
, "1-" __MODULE_STRING(IBMTR_MAX_ADAPTERS
) "i");
1722 MODULE_PARM(irq
, "1-" __MODULE_STRING(IBMTR_MAX_ADAPTERS
) "i");
1723 MODULE_PARM(mem
, "1-" __MODULE_STRING(IBMTR_MAX_ADAPTERS
) "i");
1725 int init_module(void)
1728 for (i
= 0; io
[i
] && (i
<IBMTR_MAX_ADAPTERS
); i
++) {
1731 dev_ibmtr
[i
] = NULL
;
1732 dev_ibmtr
[i
] = init_trdev(dev_ibmtr
[i
], 0);
1733 if (dev_ibmtr
[i
] == NULL
)
1736 dev_ibmtr
[i
]->base_addr
= io
[i
];
1737 dev_ibmtr
[i
]->irq
= irq
[i
];
1738 dev_ibmtr
[i
]->mem_start
= mem
[i
];
1739 dev_ibmtr
[i
]->init
= &ibmtr_probe
;
1741 if (register_trdev(dev_ibmtr
[i
]) != 0) {
1742 kfree_s(dev_ibmtr
[i
], sizeof(struct net_device
));
1743 dev_ibmtr
[i
] = NULL
;
1745 printk("ibmtr: register_trdev() returned non-zero.\n");
1755 void cleanup_module(void)
1759 for (i
= 0; i
< IBMTR_MAX_ADAPTERS
; i
++)
1761 unregister_trdev(dev_ibmtr
[i
]);
1762 free_irq(dev_ibmtr
[i
]->irq
, dev_ibmtr
[i
]);
1763 release_region(dev_ibmtr
[i
]->base_addr
, IBMTR_IO_EXTENT
);
1764 kfree_s(dev_ibmtr
[i
]->priv
, sizeof(struct tok_info
));
1765 kfree_s(dev_ibmtr
[i
], sizeof(struct net_device
));
1766 dev_ibmtr
[i
] = NULL
;