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
75 /* change the define of IBMTR_DEBUG_MESSAGES to a nonzero value
76 in the event that chatty debug messages are desired - jjs 12/30/98 */
78 #define IBMTR_DEBUG_MESSAGES 0
84 #include <linux/module.h>
90 #define NO_AUTODETECT 1
97 /* changes the output format of driver initialisation */
98 #define TR_NEWFORMAT 1
101 /* some 95 OS send many non UI frame; this allow removing the warning */
102 #define TR_FILTERNONUI 1
104 /* version and credits */
105 static char *version
=
106 "ibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n"
107 " v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n"
108 " v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n";
110 static char pcchannelid
[] = {
111 0x05, 0x00, 0x04, 0x09,
112 0x04, 0x03, 0x04, 0x0f,
113 0x03, 0x06, 0x03, 0x01,
114 0x03, 0x01, 0x03, 0x00,
115 0x03, 0x09, 0x03, 0x09,
116 0x03, 0x00, 0x02, 0x00
119 static char mcchannelid
[] = {
120 0x04, 0x0d, 0x04, 0x01,
121 0x05, 0x02, 0x05, 0x03,
122 0x03, 0x06, 0x03, 0x03,
123 0x05, 0x08, 0x03, 0x04,
124 0x03, 0x05, 0x03, 0x01,
125 0x03, 0x08, 0x02, 0x00
128 #include <linux/kernel.h>
129 #include <linux/sched.h>
130 #include <linux/errno.h>
131 #include <linux/sched.h>
132 #include <linux/timer.h>
133 #include <linux/in.h>
134 #include <linux/ioport.h>
135 #include <linux/errno.h>
136 #include <linux/string.h>
137 #include <linux/skbuff.h>
138 #include <linux/interrupt.h>
139 #include <linux/delay.h>
140 #include <linux/netdevice.h>
141 #include <linux/trdevice.h>
142 #include <linux/stddef.h>
143 #include <linux/init.h>
144 #include <net/checksum.h>
147 #include <asm/system.h>
148 #include <asm/bitops.h>
153 #define DPRINTK(format, args...) printk("%s: " format, dev->name , ## args)
154 #define DPRINTD(format, args...) DummyCall("%s: " format, dev->name , ## args)
155 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
156 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
159 /* this allows displaying full adapter information */
161 const char *channel_def
[] __initdata
= {
162 "ISA", "MCA", "ISA P&P"
165 __initfunc(char *adapter_def(char type
))
169 case 0xF : return "PC Adapter | PC Adapter II | Adapter/A";
170 case 0xE : return "16/4 Adapter | 16/4 Adapter/A (long)";
171 case 0xD : return "16/4 Adapter/A (short) | 16/4 ISA-16 Adapter";
172 case 0xC : return "Auto 16/4 Adapter";
173 default : return "adapter (unknown type)";
179 unsigned char ibmtr_debug_trace
=1; /* Patch or otherwise alter to
180 control tokenring tracing. */
182 unsigned char ibmtr_debug_trace
=0;
184 #define TRC_INIT 0x01 /* Trace initialization & PROBEs */
185 #define TRC_INITV 0x02 /* verbose init trace points */
187 int ibmtr_probe(struct device
*dev
);
188 static int ibmtr_probe1(struct device
*dev
, int ioaddr
);
189 static unsigned char get_sram_size(struct tok_info
*adapt_info
);
190 static int tok_init_card(struct device
*dev
);
191 void tok_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
192 static int trdev_init(struct device
*dev
);
193 static void initial_tok_int(struct device
*dev
);
194 static void open_sap(unsigned char type
,struct device
*dev
);
195 void tok_open_adapter(unsigned long dev_addr
);
196 static void tr_rx(struct device
*dev
);
197 static void tr_tx(struct device
*dev
);
198 static int tok_open(struct device
*dev
);
199 static int tok_close(struct device
*dev
);
200 static int tok_send_packet(struct sk_buff
*skb
, struct device
*dev
);
201 static struct net_device_stats
* tok_get_stats(struct device
*dev
);
202 void ibmtr_readlog(struct device
*dev
);
203 void ibmtr_reset_timer(struct timer_list
*tmr
, struct device
*dev
);
204 int ibmtr_change_mtu(struct device
*dev
, int mtu
);
206 static unsigned int ibmtr_portlist
[] __initdata
= {
210 static __u32 ibmtr_mem_base
= 0xd0000;
212 __initfunc(static void PrtChanID(char *pcid
, short stride
) )
215 for (i
=0, j
=0; i
<24; i
++, j
+=stride
)
216 printk("%1x", ((int) pcid
[j
]) & 0x0f);
220 __initfunc(static void HWPrtChanID (__u32 pcid
, short stride
))
223 for (i
=0, j
=0; i
<24; i
++, j
+=stride
)
224 printk("%1x", ((int)readb(pcid
+ j
)) & 0x0f);
229 * ibmtr_probe(): Routine specified in the network device structure
230 * to probe for an IBM Token Ring Adapter. Routine outline:
231 * I. Interrogate hardware to determine if an adapter exists
232 * and what the speeds and feeds are
233 * II. Setup data structures to control execution based upon
234 * adapter characteristics.
235 * III. Initialize adapter operation
237 * We expect ibmtr_probe to be called once for each device entry
238 * which references it.
241 __initfunc(int ibmtr_probe(struct device
*dev
))
244 int base_addr
= dev
? dev
->base_addr
: 0;
246 if (base_addr
> 0x1ff)
249 * Check a single specified location.
252 if (ibmtr_probe1(dev
, base_addr
))
261 else if (base_addr
!= 0) /* Don't probe at all. */
264 for (i
= 0; ibmtr_portlist
[i
]; i
++)
266 int ioaddr
= ibmtr_portlist
[i
];
267 if (check_region(ioaddr
, IBMTR_IO_EXTENT
))
269 if (ibmtr_probe1(dev
, ioaddr
)) {
280 __initfunc(static int ibmtr_probe1(struct device
*dev
, int PIOaddr
))
282 unsigned char segment
=0, intr
=0, irq
=0, i
=0, j
=0, cardpresent
=NOTOK
,temp
=0;
284 struct tok_info
*ti
=0;
286 unsigned char *tchanid
, ctemp
;
287 unsigned long timeout
;
290 dev
= init_trdev(dev
,0);
293 /* Query the adapter PIO base port which will return
294 * indication of where MMIO was placed. We also have a
295 * coded interrupt number.
298 segment
= inb(PIOaddr
);
301 * Out of range values so we'll assume non-existent IO device
304 if (segment
< 0x40 || segment
> 0xe0)
308 * Compute the linear base address of the MMIO area
309 * as LINUX doesn't care about segments
312 t_mmio
=(((__u32
)(segment
& 0xfc) << 11) + 0x80000);
313 intr
= segment
& 0x03; /* low bits is coded interrupt # */
314 if (ibmtr_debug_trace
& TRC_INIT
)
315 DPRINTK("PIOaddr: %4hx seg/intr: %2x mmio base: %08X intr: %d\n",
316 PIOaddr
, (int)segment
, t_mmio
, (int)intr
);
319 * Now we will compare expected 'channelid' strings with
320 * what we is there to learn of ISA/MCA or not TR card
323 cd_chanid
= (CHANNEL_ID
+ t_mmio
); /* for efficiency */
325 cardpresent
=TR_ISA
; /* try ISA */
328 * Suboptimize knowing first byte different
331 ctemp
= readb(cd_chanid
) & 0x0f;
332 if (ctemp
!= *tchanid
) { /* NOT ISA card, try MCA */
335 if (ctemp
!= *tchanid
) /* Neither ISA nor MCA */
339 if (cardpresent
!= NOTOK
)
342 * Know presumed type, try rest of ID
344 for (i
=2,j
=1; i
<=46; i
=i
+2,j
++)
346 if ((readb(cd_chanid
+i
) & 0x0f) != tchanid
[j
]) {
347 cardpresent
=NOTOK
; /* match failed, not TR card */
354 * If we have an ISA board check for the ISA P&P version,
355 * as it has different IRQ settings
358 if (cardpresent
== TR_ISA
&& (readb(AIPFID
+ t_mmio
)==0x0e))
359 cardpresent
=TR_ISAPNP
;
361 if (cardpresent
== NOTOK
) { /* "channel_id" did not match, report */
362 if (ibmtr_debug_trace
& TRC_INIT
) {
363 DPRINTK("Channel ID string not found for PIOaddr: %4hx\n", PIOaddr
);
364 DPRINTK("Expected for ISA: "); PrtChanID(pcchannelid
,1);
365 DPRINTK(" found: "); HWPrtChanID(cd_chanid
,2);
366 DPRINTK("Expected for MCA: "); PrtChanID(mcchannelid
,1);
371 /* Now, allocate some of the pl0 buffers for this driver.. */
372 ti
= (struct tok_info
*)kmalloc(sizeof(struct tok_info
), GFP_KERNEL
);
376 memset(ti
, 0, sizeof(struct tok_info
));
379 ti
->readlog_pending
= 0;
381 dev
->priv
= ti
; /* this seems like the logical use of the
382 field ... let's try some empirical tests
383 using the token-info structure -- that
384 should fit with out future hope of multiple
385 adapter support as well /dwm */
391 irq
=9; /* irq2 really is irq9 */
398 ti
->global_int_enable
=GLOBAL_INT_ENABLE
+((irq
==9) ? 2 : irq
);
399 ti
->adapter_int_enable
=PIOaddr
+ADAPTINTREL
;
402 DPRINTK("ti->global_int_enable: %04X\n",ti
->global_int_enable
);
414 ti
->global_int_enable
=0;
415 ti
->adapter_int_enable
=0;
416 ti
->sram
=((__u32
)(inb(PIOaddr
+ADAPTRESETREL
) & 0xfe) << 12);
428 timeout
= jiffies
+ TR_SPIN_INTERVAL
;
429 while(!readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_EVEN
))
430 if (time_after(jiffies
, timeout
)) {
431 DPRINTK("Hardware timeout during initialization.\n");
432 kfree_s(ti
, sizeof(struct tok_info
));
435 ti
->sram
=((__u32
)readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_EVEN
)<<12);
436 ti
->global_int_enable
=PIOaddr
+ADAPTINTREL
;
437 ti
->adapter_int_enable
=PIOaddr
+ADAPTINTREL
;
441 if (ibmtr_debug_trace
& TRC_INIT
) { /* just report int */
442 DPRINTK("irq=%d",irq
);
443 if (ibmtr_debug_trace
& TRC_INITV
) { /* full chat in verbose only */
444 DPRINTK(", ti->mmio=%08X",ti
->mmio
);
445 printk(", segment=%02X",segment
);
450 /* Get hw address of token ring card */
452 DPRINTK("hw address: ");
455 for (i
=0; i
<0x18; i
=i
+2)
457 /* technical reference states to do this */
458 temp
= readb(ti
->mmio
+ AIP
+ i
) & 0x0f;
460 printk("%1X",ti
->hw_address
[j
]=temp
);
462 ti
->hw_address
[j
]=temp
;
465 dev
->dev_addr
[(j
/2)]=ti
->hw_address
[j
]+(ti
->hw_address
[j
-1]<<4);
472 /* get Adapter type: 'F' = Adapter/A, 'E' = 16/4 Adapter II,...*/
473 ti
->adapter_type
= readb(ti
->mmio
+ AIPADAPTYPE
);
475 /* get Data Rate: F=4Mb, E=16Mb, D=4Mb & 16Mb ?? */
476 ti
->data_rate
= readb(ti
->mmio
+ AIPDATARATE
);
478 /* Get Early Token Release support?: F=no, E=4Mb, D=16Mb, C=4&16Mb */
479 ti
->token_release
= readb(ti
->mmio
+ AIPEARLYTOKEN
);
481 /* How much shared RAM is on adapter ? */
482 ti
->avail_shared_ram
= get_sram_size(ti
);
484 /* We need to set or do a bunch of work here based on previous results.. */
485 /* Support paging? What sizes?: F=no, E=16k, D=32k, C=16 & 32k */
486 ti
->shared_ram_paging
= readb(ti
->mmio
+ AIPSHRAMPAGE
);
488 /* Available DHB 4Mb size: F=2048, E=4096, D=4464 */
489 switch (readb(ti
->mmio
+ AIP4MBDHB
)) {
491 ti
->dhb_size4mb
= 4096;
494 ti
->dhb_size4mb
= 4464;
497 ti
->dhb_size4mb
= 2048;
501 /* Available DHB 16Mb size: F=2048, E=4096, D=8192, C=16384, B=17960 */
502 switch (readb(ti
->mmio
+ AIP16MBDHB
)) {
504 ti
->dhb_size16mb
= 4096;
507 ti
->dhb_size16mb
= 8192;
510 ti
->dhb_size16mb
= 16384;
513 ti
->dhb_size16mb
= 17960;
516 ti
->dhb_size16mb
= 2048;
521 DPRINTK("atype=%x, drate=%x, trel=%x, asram=%dK, srp=%x, "
522 "dhb(4mb=%x, 16mb=%x)\n",ti
->adapter_type
,
523 ti
->data_rate
, ti
->token_release
, ti
->avail_shared_ram
/2,
524 ti
->shared_ram_paging
, ti
->dhb_size4mb
, ti
->dhb_size16mb
);
527 /* We must figure out how much shared memory space this adapter
528 * will occupy so that if there are two adapters we can fit both
529 * in. Given a choice, we will limit this adapter to 32K. The
530 * maximum space will will use for two adapters is 64K so if the
531 * adapter we are working on demands 64K (it also doesn't support
532 * paging), then only one adapter can be supported.
536 * determine how much of total RAM is mapped into PC space
538 ti
->mapped_ram_size
=1<<((((readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_ODD
)) >>2) & 0x03) + 4);
540 if (ti
->shared_ram_paging
== 0xf) { /* No paging in adapter */
541 ti
->mapped_ram_size
= ti
->avail_shared_ram
;
544 unsigned char pg_size
;
548 DPRINTK("shared ram page size: %dK\n",ti
->mapped_ram_size
/2);
551 switch(ti
->shared_ram_paging
)
556 ti
->page_mask
=(ti
->mapped_ram_size
==32) ? 0xc0 : 0;
557 pg_size
=32; /* 16KB page size */
560 ti
->page_mask
=(ti
->mapped_ram_size
==64) ? 0x80 : 0;
561 pg_size
=64; /* 32KB page size */
564 ti
->page_mask
=(ti
->mapped_ram_size
==32) ? 0xc0 : 0;
565 ti
->page_mask
=(ti
->mapped_ram_size
==64) ? 0x80 : 0;
566 DPRINTK("Dual size shared RAM page (code=0xC), don't support it!\n");
567 /* nb/dwm: I did this because RRR (3,2) bits are documented as
568 R/O and I can't find how to select which page size
569 Also, the above conditional statement sequence is invalid
570 as page_mask will always be set by the second stmt */
571 kfree_s(ti
, sizeof(struct tok_info
));
575 DPRINTK("Unknown shared ram paging info %01X\n",ti
->shared_ram_paging
);
576 kfree_s(ti
, sizeof(struct tok_info
));
581 if (pg_size
> ti
->mapped_ram_size
) {
582 DPRINTK("Page size (%d) > mapped ram window (%d), can't page.\n",
583 pg_size
, ti
->mapped_ram_size
);
584 ti
->page_mask
= 0; /* reset paging */
586 ti
->mapped_ram_size
=ti
->avail_shared_ram
;
587 DPRINTK("Shared RAM paging enabled. Page size : %uK\n",
588 ((ti
->page_mask
^ 0xff)+1)>>2);
593 /* finish figuring the shared RAM address */
594 if (cardpresent
==TR_ISA
) {
595 static __u32 ram_bndry_mask
[]={0xffffe000, 0xffffc000, 0xffff8000, 0xffff0000};
596 __u32 new_base
, rrr_32
, chk_base
, rbm
;
598 rrr_32
= ((readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_ODD
))>>2) & 0x00000003;
599 rbm
= ram_bndry_mask
[rrr_32
];
600 new_base
= (ibmtr_mem_base
+ (~rbm
)) & rbm
; /* up to boundary */
601 chk_base
= new_base
+ (ti
->mapped_ram_size
<<9);
602 if (chk_base
> (ibmtr_mem_base
+ IBMTR_SHARED_RAM_SIZE
)) {
603 DPRINTK("Shared RAM for this adapter (%05x) exceeds driver"
604 " limit (%05x), adapter not started.\n",
605 chk_base
, ibmtr_mem_base
+ IBMTR_SHARED_RAM_SIZE
);
606 kfree_s(ti
, sizeof(struct tok_info
));
608 } else { /* seems cool, record what we have figured out */
609 ti
->sram_base
= new_base
>> 12;
610 ibmtr_mem_base
= chk_base
;
615 DPRINTK("Using %dK shared RAM\n",ti
->mapped_ram_size
/2);
618 if (request_irq (dev
->irq
= irq
, &tok_interrupt
,0,"ibmtr", dev
) != 0) {
619 DPRINTK("Could not grab irq %d. Halting Token Ring driver.\n",irq
);
620 kfree_s(ti
, sizeof(struct tok_info
));
624 /*?? Now, allocate some of the PIO PORTs for this driver.. */
625 request_region(PIOaddr
,IBMTR_IO_EXTENT
,"ibmtr"); /* record PIOaddr range
628 DPRINTK("%s",version
); /* As we have passed card identification,
629 let the world know we're here! */
633 printk("%s",version
);
636 DPRINTK("%s %s found\n",
637 channel_def
[cardpresent
-1], adapter_def(ti
->adapter_type
));
638 DPRINTK("using irq %d, PIOaddr %hx, %dK shared RAM.\n",
639 irq
, PIOaddr
, ti
->mapped_ram_size
/2);
640 DPRINTK("Hardware address : %02X:%02X:%02X:%02X:%02X:%02X\n",
641 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
642 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
644 /* Calculate the maximum DHB we can use */
645 switch (ti
->mapped_ram_size
) {
646 case 16 : /* 8KB shared RAM */
647 ti
->dhb_size4mb
= MIN(ti
->dhb_size4mb
, 2048);
648 ti
->rbuf_len4
= 1032;
650 ti
->dhb_size16mb
= MIN(ti
->dhb_size16mb
, 2048);
651 ti
->rbuf_len16
= 1032;
654 case 32 : /* 16KB shared RAM */
655 ti
->dhb_size4mb
= MIN(ti
->dhb_size4mb
, 4464);
658 ti
->dhb_size16mb
= MIN(ti
->dhb_size16mb
, 4096);
659 ti
->rbuf_len16
= 1032; /* 1024 usable */
662 case 64 : /* 32KB shared RAM */
663 ti
->dhb_size4mb
= MIN(ti
->dhb_size4mb
, 4464);
664 ti
->rbuf_len4
= 1032;
666 ti
->dhb_size16mb
= MIN(ti
->dhb_size16mb
, 10240);
667 ti
->rbuf_len16
= 1032;
670 case 127 : /* 63KB shared RAM */
671 ti
->dhb_size4mb
= MIN(ti
->dhb_size4mb
, 4464);
672 ti
->rbuf_len4
= 1032;
674 ti
->dhb_size16mb
= MIN(ti
->dhb_size16mb
, 16384);
675 ti
->rbuf_len16
= 1032;
678 case 128 : /* 64KB shared RAM */
679 ti
->dhb_size4mb
= MIN(ti
->dhb_size4mb
, 4464);
680 ti
->rbuf_len4
= 1032;
682 ti
->dhb_size16mb
= MIN(ti
->dhb_size16mb
, 17960);
683 ti
->rbuf_len16
= 1032;
687 ti
->dhb_size4mb
= 2048;
688 ti
->rbuf_len4
= 1032;
690 ti
->dhb_size16mb
= 2048;
691 ti
->rbuf_len16
= 1032;
696 ti
->maxmtu16
= (ti
->rbuf_len16
*ti
->rbuf_cnt16
)-((ti
->rbuf_cnt16
)<<3)-TR_HLEN
;
697 ti
->maxmtu4
= (ti
->rbuf_len4
*ti
->rbuf_cnt4
)-((ti
->rbuf_cnt4
)<<3)-TR_HLEN
;
698 DPRINTK("Maximum MTU 16Mbps: %d, 4Mbps: %d\n",
699 ti
->maxmtu16
, ti
->maxmtu4
);
701 dev
->base_addr
=PIOaddr
; /* set the value for device */
706 return 0; /* Return 0 to indicate we have found a Token Ring card. */
709 /* query the adapter for the size of shared RAM */
711 __initfunc(static unsigned char get_sram_size(struct tok_info
*adapt_info
))
714 unsigned char avail_sram_code
;
715 static unsigned char size_code
[]={ 0,16,32,64,127,128 };
718 'F' -- use RRR bits 3,2
719 'E' -- 8kb 'D' -- 16kb
720 'C' -- 32kb 'A' -- 64KB
721 'B' - 64KB less 512 bytes at top
722 (WARNING ... must zero top bytes in INIT */
724 avail_sram_code
=0xf-readb(adapt_info
->mmio
+ AIPAVAILSHRAM
);
726 return size_code
[avail_sram_code
];
727 else /* for code 'F', must compute size from RRR(3,2) bits */
728 return 1<<((readb(adapt_info
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_ODD
)>>2)+4);
731 __initfunc(static int trdev_init(struct device
*dev
))
733 struct tok_info
*ti
=(struct tok_info
*)dev
->priv
;
735 ti
->open_status
= CLOSED
;
737 dev
->init
= tok_init_card
;
738 dev
->open
= tok_open
;
739 dev
->stop
= tok_close
;
740 dev
->hard_start_xmit
= tok_send_packet
;
741 dev
->get_stats
= tok_get_stats
;
742 dev
->set_multicast_list
= NULL
;
743 dev
->change_mtu
= ibmtr_change_mtu
;
753 static int tok_open(struct device
*dev
)
755 struct tok_info
*ti
=(struct tok_info
*)dev
->priv
;
757 if (ti
->open_status
==CLOSED
) tok_init_card(dev
);
759 if (ti
->open_status
==IN_PROGRESS
) sleep_on(&ti
->wait_for_reset
);
761 if (ti
->open_status
==SUCCESS
) {
765 /* NEED to see smem size *AND* reset high 512 bytes if needed */
770 } else return -EAGAIN
;
774 static int tok_close(struct device
*dev
)
777 struct tok_info
*ti
=(struct tok_info
*) dev
->priv
;
779 writeb(DIR_CLOSE_ADAPTER
,
780 ti
->srb
+ offsetof(struct srb_close_adapter
, command
));
781 writeb(CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
783 ti
->open_status
=CLOSED
;
785 sleep_on(&ti
->wait_for_tok_int
);
787 if (readb(ti
->srb
+ offsetof(struct srb_close_adapter
, ret_code
)))
788 DPRINTK("close adapter failed: %02X\n",
789 (int)readb(ti
->srb
+ offsetof(struct srb_close_adapter
, ret_code
)));
792 DPRINTK("Adapter closed.\n");
798 void tok_interrupt (int irq
, void *dev_id
, struct pt_regs
*regs
)
800 unsigned char status
;
806 DPRINTK("Int from tok_driver, dev : %p\n",dev
);
808 ti
= (struct tok_info
*) dev
->priv
;
810 /* Disable interrupts till processing is finished */
812 writeb((~INT_ENABLE
), ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_EVEN
);
814 /* Reset interrupt for ISA boards */
815 if (ti
->adapter_int_enable
)
816 outb(0,ti
->adapter_int_enable
);
818 outb(0,ti
->global_int_enable
);
821 switch (ti
->do_tok_int
) {
825 /* Begin the regular interrupt handler HERE inline to avoid
826 the extra levels of logic and call depth for the
827 original solution. */
829 status
=readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ ISRP_ODD
);
831 /* Check if the PCMCIA card was pulled. */
834 DPRINTK("PCMCIA card removed.\n");
839 /* Check ISRP EVEN too. */
840 if ( readb (ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ ISRP_EVEN
) == 0xFF)
842 DPRINTK("PCMCIA card removed.\n");
849 if (status
& ADAP_CHK_INT
) {
854 check_reason
=ti
->mmio
+ ntohs(readw(ti
->sram
+ ACA_OFFSET
+ ACA_RW
+WWCR_EVEN
));
856 DPRINTK("Adapter check interrupt\n");
857 DPRINTK("8 reason bytes follow: ");
858 for(i
=0; i
<8; i
++, check_reason
++)
859 printk("%02X ", (int)readb(check_reason
));
862 writeb((~ADAP_CHK_INT
), ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
863 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
866 } else if (readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ ISRP_EVEN
)
867 & (TCR_INT
| ERR_INT
| ACCESS_INT
)) {
869 DPRINTK("adapter error: ISRP_EVEN : %02x\n",
870 (int)readb(ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ ISRP_EVEN
));
871 writeb(~(TCR_INT
| ERR_INT
| ACCESS_INT
),
872 ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_EVEN
);
873 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
877 & (SRB_RESP_INT
| ASB_FREE_INT
| ARB_CMD_INT
| SSB_RESP_INT
)) {
878 /* SRB, ASB, ARB or SSB response */
880 if (status
& SRB_RESP_INT
) { /* SRB response */
882 switch(readb(ti
->srb
)) { /* SRB command check */
884 case XMIT_DIR_FRAME
: {
885 unsigned char xmit_ret_code
;
887 xmit_ret_code
=readb(ti
->srb
+ offsetof(struct srb_xmit
, ret_code
));
888 if (xmit_ret_code
!= 0xff) {
889 DPRINTK("error on xmit_dir_frame request: %02X\n",
891 if (ti
->current_skb
) {
892 dev_kfree_skb(ti
->current_skb
);
893 ti
->current_skb
=NULL
;
896 if (ti
->readlog_pending
) ibmtr_readlog(dev
);
901 case XMIT_UI_FRAME
: {
902 unsigned char xmit_ret_code
;
904 xmit_ret_code
=readb(ti
->srb
+ offsetof(struct srb_xmit
, ret_code
));
905 if (xmit_ret_code
!= 0xff) {
906 DPRINTK("error on xmit_ui_frame request: %02X\n",
908 if (ti
->current_skb
) {
909 dev_kfree_skb(ti
->current_skb
);
910 ti
->current_skb
=NULL
;
913 if (ti
->readlog_pending
) ibmtr_readlog(dev
);
918 case DIR_OPEN_ADAPTER
: {
919 unsigned char open_ret_code
;
920 __u16 open_error_code
;
922 ti
->srb
=ti
->sram
+ntohs(readw(ti
->init_srb
+offsetof(struct srb_open_response
, srb_addr
)));
923 ti
->ssb
=ti
->sram
+ntohs(readw(ti
->init_srb
+offsetof(struct srb_open_response
, ssb_addr
)));
924 ti
->arb
=ti
->sram
+ntohs(readw(ti
->init_srb
+offsetof(struct srb_open_response
, arb_addr
)));
925 ti
->asb
=ti
->sram
+ntohs(readw(ti
->init_srb
+offsetof(struct srb_open_response
, asb_addr
)));
926 ti
->current_skb
=NULL
;
928 open_ret_code
= readb(ti
->init_srb
+offsetof(struct srb_open_response
, ret_code
));
929 open_error_code
= ntohs(readw(ti
->init_srb
+offsetof(struct srb_open_response
, error_code
)));
931 if (open_ret_code
==7) {
933 if (!ti
->auto_ringspeedsave
&& (open_error_code
==0x24)) {
934 DPRINTK("Open failed: Adapter speed must match ring "
935 "speed if Automatic Ring Speed Save is disabled.\n");
936 ti
->open_status
=FAILURE
;
937 wake_up(&ti
->wait_for_reset
);
938 } else if (open_error_code
==0x24)
939 DPRINTK("Retrying open to adjust to ring speed.\n");
940 else if ((open_error_code
==0x2d) && ti
->auto_ringspeedsave
)
941 DPRINTK("No signal detected for Auto Speed Detection.\n");
942 else if (open_error_code
==0x11)
944 if (ti
->retry_count
--)
945 DPRINTK("Ring broken/disconnected, retrying...\n");
947 DPRINTK("Ring broken/disconnected, open failed.\n");
948 ti
->open_status
= FAILURE
;
951 else DPRINTK("Unrecoverable error: error code = %04x.\n",
954 } else if (!open_ret_code
) {
956 DPRINTK("board opened...\n");
958 DPRINTK("Adapter initialized and opened.\n");
960 writeb(~(SRB_RESP_INT
),
961 ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
962 writeb(~(CMD_IN_SRB
),
963 ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRA_ODD
);
964 open_sap(EXTENDED_SAP
,dev
);
966 /* YdW probably hates me */
969 DPRINTK("open failed: ret_code = %02X, retrying\n",
972 if (ti
->open_status
!= FAILURE
) {
973 ibmtr_reset_timer(&(ti
->tr_timer
), dev
);
979 case DIR_CLOSE_ADAPTER
:
980 wake_up(&ti
->wait_for_tok_int
);
984 if (readb(ti
->srb
+offsetof(struct dlc_open_sap
, ret_code
))) {
985 DPRINTK("open_sap failed: ret_code = %02X,retrying\n",
986 (int)readb(ti
->srb
+offsetof(struct dlc_open_sap
, ret_code
)));
987 ibmtr_reset_timer(&(ti
->tr_timer
), dev
);
989 ti
->exsap_station_id
=
990 readw(ti
->srb
+offsetof(struct dlc_open_sap
, station_id
));
991 ti
->open_status
=SUCCESS
; /* TR adapter is now available */
992 wake_up(&ti
->wait_for_reset
);
997 case DIR_MOD_OPEN_PARAMS
:
998 case DIR_SET_GRP_ADDR
:
999 case DIR_SET_FUNC_ADDR
:
1001 if (readb(ti
->srb
+offsetof(struct srb_interrupt
, ret_code
)))
1002 DPRINTK("error on %02X: %02X\n",
1003 (int)readb(ti
->srb
+offsetof(struct srb_interrupt
, command
)),
1004 (int)readb(ti
->srb
+offsetof(struct srb_interrupt
, ret_code
)));
1008 if (readb(ti
->srb
+offsetof(struct srb_read_log
, ret_code
)))
1009 DPRINTK("error on dir_read_log: %02X\n",
1010 (int)readb(ti
->srb
+offsetof(struct srb_read_log
, ret_code
)));
1012 if (IBMTR_DEBUG_MESSAGES
) {
1014 "Line errors %02X, Internal errors %02X, Burst errors %02X\n"
1015 "A/C errors %02X, Abort delimiters %02X, Lost frames %02X\n"
1016 "Receive congestion count %02X, Frame copied errors %02X\n"
1017 "Frequency errors %02X, Token errors %02X\n",
1018 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1020 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1022 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1024 (int)readb(ti
->srb
+offsetof(struct srb_read_log
, A_C_errors
)),
1025 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1027 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1029 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1030 recv_congest_count
)),
1031 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1032 frame_copied_errors
)),
1033 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1035 (int)readb(ti
->srb
+offsetof(struct srb_read_log
,
1042 DPRINTK("Unknown command %02X encountered\n",
1043 (int)readb(ti
->srb
));
1045 } /* SRB command check */
1047 writeb(~CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRA_ODD
);
1048 writeb(~SRB_RESP_INT
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1051 } /* SRB response */
1053 if (status
& ASB_FREE_INT
) { /* ASB response */
1055 switch(readb(ti
->asb
)) { /* ASB command check */
1059 case XMIT_DIR_FRAME
:
1063 DPRINTK("unknown command in asb %02X\n",
1064 (int)readb(ti
->asb
));
1066 } /* ASB command check */
1068 if (readb(ti
->asb
+2)!=0xff) /* checks ret_code */
1069 DPRINTK("ASB error %02X in cmd %02X\n",
1070 (int)readb(ti
->asb
+2),(int)readb(ti
->asb
));
1071 writeb(~ASB_FREE_INT
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1073 } /* ASB response */
1075 if (status
& ARB_CMD_INT
) { /* ARB response */
1077 switch (readb(ti
->arb
)) { /* ARB command check */
1080 DPRINTK("DLC_STATUS new status: %02X on station %02X\n",
1081 ntohs(readw(ti
->arb
+ offsetof(struct arb_dlc_status
, status
))),
1083 +offsetof(struct arb_dlc_status
, station_id
))));
1090 case RING_STAT_CHANGE
: {
1091 unsigned short ring_status
;
1093 ring_status
=ntohs(readw(ti
->arb
1094 +offsetof(struct arb_ring_stat_change
, ring_status
)));
1096 if (ring_status
& (SIGNAL_LOSS
| LOBE_FAULT
)) {
1098 DPRINTK("Signal loss/Lobe fault\n");
1099 DPRINTK("We try to reopen the adapter.\n");
1100 ibmtr_reset_timer(&(ti
->tr_timer
), dev
);
1101 } else if (ring_status
& (HARD_ERROR
| XMIT_BEACON
1102 | AUTO_REMOVAL
| REMOVE_RECV
| RING_RECOVER
))
1103 DPRINTK("New ring status: %02X\n", ring_status
);
1105 if (ring_status
& LOG_OVERFLOW
) {
1107 ti
->readlog_pending
= 1;
1119 DPRINTK("Unknown command %02X in arb\n",
1120 (int)readb(ti
->arb
));
1123 } /* ARB command check */
1125 writeb(~ARB_CMD_INT
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1126 writeb(ARB_FREE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1128 } /* ARB response */
1130 if (status
& SSB_RESP_INT
) { /* SSB response */
1131 unsigned char retcode
;
1132 switch (readb(ti
->ssb
)) { /* SSB command check */
1134 case XMIT_DIR_FRAME
:
1136 retcode
= readb(ti
->ssb
+2);
1137 if (retcode
&& (retcode
!= 0x22)) /* checks ret_code */
1138 DPRINTK("xmit ret_code: %02X xmit error code: %02X\n",
1139 (int)retcode
, (int)readb(ti
->ssb
+6));
1140 else ti
->tr_stats
.tx_packets
++;
1144 DPRINTK("xmit xid ret_code: %02X\n", (int)readb(ti
->ssb
+2));
1147 DPRINTK("Unknown command %02X in ssb\n", (int)readb(ti
->ssb
));
1149 } /* SSB command check */
1151 writeb(~SSB_RESP_INT
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1152 writeb(SSB_FREE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1154 } /* SSB response */
1156 } /* SRB, ARB, ASB or SSB response */
1159 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
1163 initial_tok_int(dev
);
1167 DPRINTK("Unexpected interrupt from tr adapter\n");
1172 static void initial_tok_int(struct device
*dev
)
1176 __u32 hw_encoded_addr
;
1177 struct tok_info
*ti
;
1179 ti
=(struct tok_info
*) dev
->priv
;
1181 ti
->do_tok_int
=NOT_FIRST
;
1183 #ifndef TR_NEWFORMAT
1184 DPRINTK("Initial tok int received\n");
1187 /* we assign the shared-ram address for ISA devices */
1189 writeb(ti
->sram_base
, ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ RRR_EVEN
);
1190 ti
->sram
=((__u32
)ti
->sram_base
<< 12);
1192 ti
->init_srb
=ti
->sram
1193 +ntohs((unsigned short)readw(ti
->mmio
+ ACA_OFFSET
+ WRBR_EVEN
));
1194 SET_PAGE(ntohs((unsigned short)readw(ti
->mmio
+ACA_OFFSET
+ WRBR_EVEN
)));
1196 dev
->mem_start
= ti
->sram
;
1197 dev
->mem_end
= ti
->sram
+ (ti
->mapped_ram_size
<<9) - 1;
1202 DPRINTK("init_srb(%p):", ti
->init_srb
);
1203 for (i
=0;i
<17;i
++) printk("%02X ", (int)readb(ti
->init_srb
+i
));
1208 hw_encoded_addr
= readw(ti
->init_srb
1209 + offsetof(struct srb_init_response
, encoded_address
));
1212 DPRINTK("srb_init_response->encoded_address: %04X\n", hw_encoded_addr
);
1213 DPRINTK("ntohs(srb_init_response->encoded_address): %04X\n",
1214 ntohs(hw_encoded_addr
));
1217 encoded_addr
=(ti
->sram
+ ntohs(hw_encoded_addr
));
1218 ti
->ring_speed
= readb(ti
->init_srb
+offsetof(struct srb_init_response
, init_status
)) & 0x01 ? 16 : 4;
1220 DPRINTK("encoded addr (%04X,%04X,%08X): ", hw_encoded_addr
,
1221 ntohs(hw_encoded_addr
), encoded_addr
);
1223 DPRINTK("Initial interrupt : %d Mbps, shared RAM base %08x.\n",
1224 ti
->ring_speed
, ti
->sram
);
1227 ti
->auto_ringspeedsave
=readb(ti
->init_srb
1228 +offsetof(struct srb_init_response
, init_status_2
)) & 0x4 ? TRUE
: FALSE
;
1231 for(i
=0;i
<TR_ALEN
;i
++) {
1232 dev
->dev_addr
[i
]=readb(encoded_addr
+ i
);
1233 printk("%02X%s", dev
->dev_addr
[i
], (i
==TR_ALEN
-1) ? "" : ":" );
1238 tok_open_adapter((unsigned long)dev
);
1241 static int tok_init_card(struct device
*dev
)
1243 struct tok_info
*ti
;
1246 PIOaddr
= dev
->base_addr
;
1247 ti
=(struct tok_info
*) dev
->priv
;
1249 /* Special processing for first interrupt after reset */
1250 ti
->do_tok_int
=FIRST_INT
;
1253 dev
->tbusy
=1; /* nothing can be done before reset and open completed */
1255 #ifdef ENABLE_PAGING
1257 writeb(SRPR_ENABLE_PAGING
, ti
->mmio
+ ACA_OFFSET
+ ACA_RW
+ SRPR_EVEN
);
1260 writeb(~INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_EVEN
);
1263 DPRINTK("resetting card\n");
1266 outb(0, PIOaddr
+ADAPTRESET
);
1267 for (i
=jiffies
+TR_RESET_INTERVAL
; time_before_eq(jiffies
, i
);); /* wait 50ms */
1268 outb(0,PIOaddr
+ADAPTRESETREL
);
1271 DPRINTK("card reset\n");
1274 ti
->open_status
=IN_PROGRESS
;
1275 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
1279 static void open_sap(unsigned char type
,struct device
*dev
)
1282 struct tok_info
*ti
=(struct tok_info
*) dev
->priv
;
1285 for (i
=0; i
<sizeof(struct dlc_open_sap
); i
++)
1286 writeb(0, ti
->srb
+i
);
1288 writeb(DLC_OPEN_SAP
, ti
->srb
+ offsetof(struct dlc_open_sap
, command
));
1289 writew(htons(MAX_I_FIELD
),
1290 ti
->srb
+ offsetof(struct dlc_open_sap
, max_i_field
));
1291 writeb(SAP_OPEN_IND_SAP
| SAP_OPEN_PRIORITY
,
1292 ti
->srb
+ offsetof(struct dlc_open_sap
, sap_options
));
1293 writeb(SAP_OPEN_STATION_CNT
,
1294 ti
->srb
+ offsetof(struct dlc_open_sap
, station_count
));
1295 writeb(type
, ti
->srb
+ offsetof(struct dlc_open_sap
, sap_value
));
1297 writeb(CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1301 void tok_open_adapter(unsigned long dev_addr
)
1304 struct device
*dev
=(struct device
*)dev_addr
;
1305 struct tok_info
*ti
;
1308 ti
=(struct tok_info
*) dev
->priv
;
1311 DPRINTK("now opening the board...\n");
1314 writeb(~SRB_RESP_INT
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRP_ODD
);
1315 writeb(~CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_RESET
+ ISRA_ODD
);
1317 for (i
=0; i
<sizeof(struct dir_open_adapter
); i
++)
1318 writeb(0, ti
->init_srb
+i
);
1320 writeb(DIR_OPEN_ADAPTER
,
1321 ti
->init_srb
+ offsetof(struct dir_open_adapter
, command
));
1322 writew(htons(OPEN_PASS_BCON_MAC
),
1323 ti
->init_srb
+ offsetof(struct dir_open_adapter
, open_options
));
1324 if (ti
->ring_speed
== 16) {
1325 writew(htons(ti
->dhb_size16mb
),
1326 ti
->init_srb
+ offsetof(struct dir_open_adapter
, dhb_length
));
1327 writew(htons(ti
->rbuf_cnt16
),
1328 ti
->init_srb
+ offsetof(struct dir_open_adapter
, num_rcv_buf
));
1329 writew(htons(ti
->rbuf_len16
),
1330 ti
->init_srb
+ offsetof(struct dir_open_adapter
, rcv_buf_len
));
1332 writew(htons(ti
->dhb_size4mb
),
1333 ti
->init_srb
+ offsetof(struct dir_open_adapter
, dhb_length
));
1334 writew(htons(ti
->rbuf_cnt4
),
1335 ti
->init_srb
+ offsetof(struct dir_open_adapter
, num_rcv_buf
));
1336 writew(htons(ti
->rbuf_len4
),
1337 ti
->init_srb
+ offsetof(struct dir_open_adapter
, rcv_buf_len
));
1339 writeb(NUM_DHB
, /* always 2 */
1340 ti
->init_srb
+ offsetof(struct dir_open_adapter
, num_dhb
));
1342 ti
->init_srb
+ offsetof(struct dir_open_adapter
, dlc_max_sap
));
1344 ti
->init_srb
+ offsetof(struct dir_open_adapter
, dlc_max_sta
));
1346 ti
->srb
=ti
->init_srb
; /* We use this one in the interrupt handler */
1348 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
1349 writeb(CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1353 static void tr_tx(struct device
*dev
)
1355 struct tok_info
*ti
=(struct tok_info
*) dev
->priv
;
1356 struct trh_hdr
*trhdr
=(struct trh_hdr
*)ti
->current_skb
->data
;
1357 unsigned int hdr_len
;
1359 unsigned char xmit_command
;
1363 if (readb(ti
->asb
+ offsetof(struct asb_xmit_resp
, ret_code
))!=0xFF)
1364 DPRINTK("ASB not free !!!\n");
1366 /* in providing the transmit interrupts,
1367 is telling us it is ready for data and
1368 providing a shared memory address for us
1369 to stuff with data. Here we compute the
1370 effective address where we will place data.*/
1372 +ntohs(readw(ti
->arb
+ offsetof(struct arb_xmit_req
, dhb_address
)));
1374 /* Figure out the size of the 802.5 header */
1375 if (!(trhdr
->saddr
[0] & 0x80)) /* RIF present? */
1376 hdr_len
=sizeof(struct trh_hdr
)-TR_MAXRIFLEN
;
1378 hdr_len
=((ntohs(trhdr
->rcf
) & TR_RCF_LEN_MASK
)>>8)
1379 +sizeof(struct trh_hdr
)-TR_MAXRIFLEN
;
1381 llc
= (struct trllc
*)(ti
->current_skb
->data
+ hdr_len
);
1383 xmit_command
= readb(ti
->srb
+ offsetof(struct srb_xmit
, command
));
1385 writeb(xmit_command
, ti
->asb
+ offsetof(struct asb_xmit_resp
, command
));
1386 writew(readb(ti
->srb
+ offsetof(struct srb_xmit
, station_id
)),
1387 ti
->asb
+ offsetof(struct asb_xmit_resp
, station_id
));
1388 writeb(llc
->ssap
, ti
->asb
+ offsetof(struct asb_xmit_resp
, rsap_value
));
1389 writeb(readb(ti
->srb
+ offsetof(struct srb_xmit
, cmd_corr
)),
1390 ti
->asb
+ offsetof(struct asb_xmit_resp
, cmd_corr
));
1391 writeb(0, ti
->asb
+ offsetof(struct asb_xmit_resp
, ret_code
));
1393 if ((xmit_command
==XMIT_XID_CMD
) || (xmit_command
==XMIT_TEST_CMD
)) {
1396 ti
->asb
+ offsetof(struct asb_xmit_resp
, frame_length
));
1397 writeb(0x0e, ti
->asb
+ offsetof(struct asb_xmit_resp
, hdr_length
));
1399 writeb(LLC_FRAME
, dhb
+1);
1401 for (i
=0; i
<TR_ALEN
; i
++) writeb((int)0x0FF, dhb
+i
+2);
1402 for (i
=0; i
<TR_ALEN
; i
++) writeb(0, dhb
+i
+TR_ALEN
+2);
1404 writeb(RESP_IN_ASB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1410 * the token ring packet is copied from sk_buff to the adapter
1411 * buffer identified in the command data received with the interrupt.
1413 writeb(hdr_len
, ti
->asb
+ offsetof(struct asb_xmit_resp
, hdr_length
));
1414 writew(htons(ti
->current_skb
->len
),
1415 ti
->asb
+ offsetof(struct asb_xmit_resp
, frame_length
));
1417 memcpy_toio(dhb
, ti
->current_skb
->data
, ti
->current_skb
->len
);
1419 writeb(RESP_IN_ASB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1420 ti
->tr_stats
.tx_bytes
+=ti
->current_skb
->len
;
1422 dev_kfree_skb(ti
->current_skb
);
1423 ti
->current_skb
=NULL
;
1425 if (ti
->readlog_pending
) ibmtr_readlog(dev
);
1428 static void tr_rx(struct device
*dev
)
1430 struct tok_info
*ti
=(struct tok_info
*) dev
->priv
;
1431 __u32 rbuffer
, rbufdata
;
1433 unsigned char *data
;
1434 unsigned int rbuffer_len
, lan_hdr_len
, hdr_len
, ip_len
, length
;
1435 struct sk_buff
*skb
;
1436 unsigned int skb_size
= 0;
1438 unsigned int chksum
= 0;
1442 +ntohs(readw(ti
->arb
+ offsetof(struct arb_rec_req
, rec_buf_addr
))))+2;
1444 if(readb(ti
->asb
+ offsetof(struct asb_rec
, ret_code
))!=0xFF)
1445 DPRINTK("ASB not free !!!\n");
1448 ti
->asb
+ offsetof(struct asb_rec
, command
));
1449 writew(readw(ti
->arb
+ offsetof(struct arb_rec_req
, station_id
)),
1450 ti
->asb
+ offsetof(struct asb_rec
, station_id
));
1451 writew(readw(ti
->arb
+ offsetof(struct arb_rec_req
, rec_buf_addr
)),
1452 ti
->asb
+ offsetof(struct asb_rec
, rec_buf_addr
));
1454 lan_hdr_len
=readb(ti
->arb
+ offsetof(struct arb_rec_req
, lan_hdr_len
));
1456 llc
=(rbuffer
+ offsetof(struct rec_buf
, data
) + lan_hdr_len
);
1459 DPRINTK("offsetof data: %02X lan_hdr_len: %02X\n",
1460 (unsigned int)offsetof(struct rec_buf
,data
), (unsigned int)lan_hdr_len
);
1461 DPRINTK("llc: %08X rec_buf_addr: %04X ti->sram: %p\n", llc
,
1462 ntohs(readw(ti
->arb
+ offsetof(struct arb_rec_req
, rec_buf_addr
))),
1464 DPRINTK("dsap: %02X, ssap: %02X, llc: %02X, protid: %02X%02X%02X, "
1465 "ethertype: %04X\n",
1466 (int)readb(llc
+ offsetof(struct trllc
, dsap
)),
1467 (int)readb(llc
+ offsetof(struct trllc
, ssap
)),
1468 (int)readb(llc
+ offsetof(struct trllc
, llc
)),
1469 (int)readb(llc
+ offsetof(struct trllc
, protid
)),
1470 (int)readb(llc
+ offsetof(struct trllc
, protid
)+1),
1471 (int)readb(llc
+ offsetof(struct trllc
, protid
)+2),
1472 (int)readw(llc
+ offsetof(struct trllc
, ethertype
)));
1474 if (readb(llc
+ offsetof(struct trllc
, llc
))!=UI_CMD
) {
1475 writeb(DATA_LOST
, ti
->asb
+ offsetof(struct asb_rec
, ret_code
));
1476 ti
->tr_stats
.rx_dropped
++;
1477 writeb(RESP_IN_ASB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1481 if ((readb(llc
+ offsetof(struct trllc
, dsap
))==EXTENDED_SAP
) &&
1482 (readb(llc
+ offsetof(struct trllc
, ssap
))==EXTENDED_SAP
)) {
1491 trhhdr
=(rbuffer
+offsetof(struct rec_buf
,data
));
1493 DPRINTK("Probably non-IP frame received.\n");
1494 DPRINTK("ssap: %02X dsap: %02X saddr: %02X:%02X:%02X:%02X:%02X:%02X "
1495 "daddr: %02X:%02X:%02X:%02X:%02X:%02X\n",
1496 (int)readb(llc
+ offsetof(struct trllc
, ssap
)),
1497 (int)readb(llc
+ offsetof(struct trllc
, dsap
)),
1498 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)),
1499 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)+1),
1500 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)+2),
1501 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)+3),
1502 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)+4),
1503 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, saddr
)+5),
1504 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)),
1505 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)+1),
1506 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)+2),
1507 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)+3),
1508 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)+4),
1509 (int)readb(trhhdr
+ offsetof(struct trh_hdr
, daddr
)+5));
1513 length
= ntohs(readw(ti
->arb
+offsetof(struct arb_rec_req
, frame_len
)));
1514 skb_size
= length
-lan_hdr_len
+sizeof(struct trh_hdr
)+sizeof(struct trllc
);
1516 if (!(skb
=dev_alloc_skb(skb_size
))) {
1517 DPRINTK("out of memory. frame dropped.\n");
1518 ti
->tr_stats
.rx_dropped
++;
1519 writeb(DATA_LOST
, ti
->asb
+ offsetof(struct asb_rec
, ret_code
));
1520 writeb(RESP_IN_ASB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1524 skb_put(skb
, length
);
1525 skb_reserve(skb
, sizeof(struct trh_hdr
)-lan_hdr_len
+sizeof(struct trllc
));
1528 rbuffer_len
=ntohs(readw(rbuffer
+ offsetof(struct rec_buf
, buf_len
)));
1529 rbufdata
= rbuffer
+ offsetof(struct rec_buf
,data
);
1532 /* Copy the headers without checksumming */
1533 hdr_len
= lan_hdr_len
+ sizeof(struct trllc
) + sizeof(struct iphdr
);
1534 memcpy_fromio(data
, rbufdata
, hdr_len
);
1536 /* Watch for padded packets and bogons */
1537 iph
=(struct iphdr
*)(data
+ lan_hdr_len
+ sizeof(struct trllc
));
1538 ip_len
= ntohs(iph
->tot_len
) - sizeof(struct iphdr
);
1540 if ((ip_len
<= length
) && (ip_len
> 7))
1543 rbuffer_len
-= hdr_len
;
1544 rbufdata
+= hdr_len
;
1547 /* Copy the payload... */
1550 chksum
= csum_partial_copy(bus_to_virt(rbufdata
), data
,
1551 length
< rbuffer_len
? length
: rbuffer_len
,
1554 memcpy_fromio(data
, rbufdata
, rbuffer_len
);
1555 rbuffer
= ntohs(readw(rbuffer
));
1558 length
-= rbuffer_len
;
1559 data
+= rbuffer_len
;
1560 rbuffer
+= ti
->sram
;
1561 rbuffer_len
= ntohs(readw(rbuffer
+ offsetof(struct rec_buf
, buf_len
)));
1562 rbufdata
= rbuffer
+ offsetof(struct rec_buf
, data
);
1565 writeb(0, ti
->asb
+ offsetof(struct asb_rec
, ret_code
));
1567 writeb(RESP_IN_ASB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1569 ti
->tr_stats
.rx_bytes
+= skb
->len
;
1570 ti
->tr_stats
.rx_packets
++;
1572 skb
->protocol
= tr_type_trans(skb
,dev
);
1582 static int tok_send_packet(struct sk_buff
*skb
, struct device
*dev
)
1584 struct tok_info
*ti
;
1585 ti
=(struct tok_info
*) dev
->priv
;
1590 ticks_waited
=jiffies
- dev
->trans_start
;
1591 if (ticks_waited
<TR_BUSY_INTERVAL
) return 1;
1593 DPRINTK("Arrg. Transmitter busy.\n");
1594 dev
->trans_start
+=5; /* we fake the transmission start time... */
1598 if (test_and_set_bit(0,(void *)&dev
->tbusy
)!=0)
1599 DPRINTK("Transmitter access conflict\n");
1601 /* Save skb; we'll need it when the adapter asks for the data */
1602 ti
->current_skb
=skb
;
1603 writeb(XMIT_UI_FRAME
, ti
->srb
+ offsetof(struct srb_xmit
, command
));
1604 writew(ti
->exsap_station_id
, ti
->srb
1605 +offsetof(struct srb_xmit
, station_id
));
1606 writeb(CMD_IN_SRB
, (ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
));
1607 dev
->trans_start
=jiffies
;
1613 void ibmtr_reset_timer(struct timer_list
*tmr
, struct device
*dev
) {
1614 tmr
->expires
= jiffies
+ TR_RETRY_INTERVAL
;
1615 tmr
->data
= (unsigned long) dev
;
1616 tmr
->function
= tok_open_adapter
;
1621 void ibmtr_readlog(struct device
*dev
) {
1622 struct tok_info
*ti
;
1623 ti
=(struct tok_info
*) dev
->priv
;
1625 ti
->readlog_pending
= 0;
1626 writeb(DIR_READ_LOG
, ti
->srb
);
1627 writeb(INT_ENABLE
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRP_EVEN
);
1628 writeb(CMD_IN_SRB
, ti
->mmio
+ ACA_OFFSET
+ ACA_SET
+ ISRA_ODD
);
1629 dev
->tbusy
=1; /* really srb busy... */
1632 /* tok_get_stats(): Basically a scaffold routine which will return
1633 the address of the tr_statistics structure associated with
1634 this device -- the tr.... structure is an ethnet look-alike
1635 so at least for this iteration may suffice. */
1637 static struct net_device_stats
* tok_get_stats(struct device
*dev
) {
1639 struct tok_info
*toki
;
1640 toki
=(struct tok_info
*) dev
->priv
;
1641 return (struct net_device_stats
*) &toki
->tr_stats
;
1644 int ibmtr_change_mtu(struct device
*dev
, int mtu
) {
1645 struct tok_info
*ti
= (struct tok_info
*) dev
->priv
;
1647 if (ti
->ring_speed
== 16 && mtu
> ti
->maxmtu16
)
1649 if (ti
->ring_speed
== 4 && mtu
> ti
->maxmtu4
)
1657 /* 3COM 3C619C supports 8 interrupts, 32 I/O ports */
1658 static struct device
* dev_ibmtr
[IBMTR_MAX_ADAPTERS
];
1659 static int io
[IBMTR_MAX_ADAPTERS
] = {0xa20,0xa24};
1660 static int irq
[IBMTR_MAX_ADAPTERS
] = {0,0};
1661 static int mem
[IBMTR_MAX_ADAPTERS
] = {0,0};
1663 MODULE_PARM(io
, "1-" __MODULE_STRING(IBMTR_MAX_ADAPTERS
) "i");
1664 MODULE_PARM(irq
, "1-" __MODULE_STRING(IBMTR_MAX_ADAPTERS
) "i");
1665 MODULE_PARM(mem
, "1-" __MODULE_STRING(IBMTR_MAX_ADAPTERS
) "i");
1667 int init_module(void)
1670 for (i
= 0; io
[i
] && (i
<IBMTR_MAX_ADAPTERS
); i
++) {
1673 dev_ibmtr
[i
] = NULL
;
1674 dev_ibmtr
[i
] = init_trdev(dev_ibmtr
[i
], 0);
1675 if (dev_ibmtr
[i
] == NULL
)
1678 dev_ibmtr
[i
]->base_addr
= io
[i
];
1679 dev_ibmtr
[i
]->irq
= irq
[i
];
1680 dev_ibmtr
[i
]->mem_start
= mem
[i
];
1681 dev_ibmtr
[i
]->init
= &ibmtr_probe
;
1683 if (register_trdev(dev_ibmtr
[i
]) != 0) {
1684 kfree_s(dev_ibmtr
[i
], sizeof(struct device
));
1685 dev_ibmtr
[i
] = NULL
;
1687 printk("ibmtr: register_trdev() returned non-zero.\n");
1697 void cleanup_module(void)
1701 for (i
= 0; i
< IBMTR_MAX_ADAPTERS
; i
++)
1703 unregister_trdev(dev_ibmtr
[i
]);
1704 free_irq(dev_ibmtr
[i
]->irq
, dev_ibmtr
[i
]);
1705 release_region(dev_ibmtr
[i
]->base_addr
, IBMTR_IO_EXTENT
);
1706 kfree_s(dev_ibmtr
[i
]->priv
, sizeof(struct tok_info
));
1707 kfree_s(dev_ibmtr
[i
], sizeof(struct device
));
1708 dev_ibmtr
[i
] = NULL
;