2 * sktr.c: A network driver for the SysKonnect Token Ring ISA/PCI Adapters.
4 * Written 1997 by Christoph Goos
6 * A fine result of the Linux Systems Network Architecture Project.
7 * http://samba.anu.edu.au/linux-sna/
9 * This software may be used and distributed according to the terms
10 * of the GNU Public License, incorporated herein by reference.
12 * This device driver works with the following SysKonnect adapters:
13 * - SysKonnect TR4/16(+) ISA (SK-4190)
14 * - SysKonnect TR4/16(+) PCI (SK-4590)
15 * - SysKonnect TR4/16 PCI (SK-4591)
18 * - The hardware related parts of this driver are take from
19 * the SysKonnect Token Ring driver for Windows NT.
20 * - I used the IBM Token Ring driver 'ibmtr.c' as a base for this
21 * driver, as well as the 'skeleton.c' driver by Donald Becker.
22 * - Also various other drivers in the linux source tree were taken
23 * as samples for some tasks.
26 * JS Jay Schulist jschlst@samba.anu.edu.au
27 * CG Christoph Goos cgoos@syskonnect.de
28 * AF Adam Fritzler mid@auk.cx
30 * Modification History:
31 * 29-Aug-97 CG Created
32 * 04-Apr-98 CG Fixed problems caused by tok_timer_check
33 * 10-Apr-98 CG Fixed lockups at cable disconnection
34 * 27-May-98 JS Formated to Linux Kernel Format
35 * 31-May-98 JS Hacked in PCI support
36 * 16-Jun-98 JS Modulized for multiple cards with one driver
37 * 21-Sep-99 CG Fixed source routing issues for 2.2 kernels
38 * 21-Sep-99 AF Added multicast changes recommended by
39 * Jochen Friedrich <jochen@nwe.de> (untested)
40 * Added detection of compatible Compaq PCI card
43 * 1. Selectable 16 Mbps or 4Mbps
44 * 2. Multi/Broadcast packet handling (might be done)
48 static const char *version
= "sktr.c: v1.01 08/29/97 by Christoph Goos\n";
51 #include <linux/module.h>
52 #include <linux/version.h>
55 #include <linux/kernel.h>
56 #include <linux/sched.h>
57 #include <linux/types.h>
58 #include <linux/fcntl.h>
59 #include <linux/interrupt.h>
60 #include <linux/ptrace.h>
61 #include <linux/ioport.h>
63 #include <linux/malloc.h>
64 #include <linux/string.h>
65 #include <linux/time.h>
66 #include <asm/system.h>
67 #include <asm/bitops.h>
71 #include <linux/errno.h>
72 #include <linux/init.h>
73 #include <linux/pci.h>
75 #include <linux/netdevice.h>
76 #include <linux/etherdevice.h>
77 #include <linux/skbuff.h>
78 #include <linux/trdevice.h>
80 #include "sktr.h" /* Our Stuff */
81 #include "sktr_firmware.h" /* SysKonnect adapter firmware */
83 /* A zero-terminated list of I/O addresses to be probed. */
84 static unsigned int sktr_portlist
[] __initdata
= {
85 0x0A20, 0x1A20, 0x0B20, 0x1B20, 0x0980, 0x1980, 0x0900, 0x1900,
89 /* A zero-terminated list of IRQs to be probed.
90 * Used again after initial probe for sktr_chipset_init, called from sktr_open.
92 static unsigned short sktr_irqlist
[] = {
93 3, 5, 9, 10, 11, 12, 15,
97 /* A zero-terminated list of DMAs to be probed. */
98 static int sktr_dmalist
[] __initdata
= {
104 static char *pci_cardname
= "SK NET TR 4/16 PCI\0";
105 static char *isa_cardname
= "SK NET TR 4/16 ISA\0";
106 static char *AdapterName
;
108 /* Use 0 for production, 1 for verification, 2 for debug, and
109 * 3 for very verbose debug.
114 static unsigned int sktr_debug
= SKTR_DEBUG
;
116 /* The number of low I/O ports used by the tokencard. */
117 #define SKTR_IO_EXTENT 32
119 /* Index to functions, as function prototypes.
120 * Alphabetical by function name.
124 static int sktr_bringup_diags(struct net_device
*dev
);
126 static void sktr_cancel_tx_queue(struct net_local
* tp
);
127 static int sktr_chipset_init(struct net_device
*dev
);
128 static void sktr_chk_irq(struct net_device
*dev
);
129 static unsigned char sktr_chk_frame(struct net_device
*dev
, unsigned char *Addr
);
130 static void sktr_chk_outstanding_cmds(struct net_device
*dev
);
131 static void sktr_chk_src_addr(unsigned char *frame
, unsigned char *hw_addr
);
132 static unsigned char sktr_chk_ssb(struct net_local
*tp
, unsigned short IrqType
);
133 static int sktr_close(struct net_device
*dev
);
134 static void sktr_cmd_status_irq(struct net_device
*dev
);
136 static void sktr_disable_interrupts(struct net_device
*dev
);
137 static void sktr_dump(unsigned char *Data
, int length
);
139 static void sktr_enable_interrupts(struct net_device
*dev
);
140 static void sktr_exec_cmd(struct net_device
*dev
, unsigned short Command
);
141 static void sktr_exec_sifcmd(struct net_device
*dev
, unsigned int WriteValue
);
144 static struct enet_statistics
*sktr_get_stats(struct net_device
*dev
);
146 static void sktr_hardware_send_packet(struct net_device
*dev
,
147 struct net_local
* tp
);
149 static int sktr_init_adapter(struct net_device
*dev
);
150 static int sktr_init_card(struct net_device
*dev
);
151 static void sktr_init_ipb(struct net_local
*tp
);
152 static void sktr_init_net_local(struct net_device
*dev
);
153 static void sktr_init_opb(struct net_local
*tp
);
154 static void sktr_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
155 static int sktr_isa_chk_card(struct net_device
*dev
, int ioaddr
);
156 static int sktr_isa_chk_ioaddr(int ioaddr
);
158 static int sktr_open(struct net_device
*dev
);
159 static void sktr_open_adapter(struct net_device
*dev
);
161 static int sktr_pci_chk_card(struct net_device
*dev
);
162 int sktr_probe(struct net_device
*dev
);
163 static int sktr_probe1(struct net_device
*dev
, int ioaddr
);
165 static void sktr_rcv_status_irq(struct net_device
*dev
);
166 static void sktr_read_addr(struct net_device
*dev
, unsigned char *Address
);
167 static void sktr_read_ptr(struct net_device
*dev
);
168 static void sktr_read_ram(struct net_device
*dev
, unsigned char *Data
,
169 unsigned short Address
, int Length
);
170 static int sktr_reset_adapter(struct net_device
*dev
);
171 static void sktr_reset_interrupt(struct net_device
*dev
);
172 static void sktr_ring_status_irq(struct net_device
*dev
);
174 static int sktr_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
175 static void sktr_set_multicast_list(struct net_device
*dev
);
177 static void sktr_timer_chk(unsigned long data
);
178 static void sktr_timer_end_wait(unsigned long data
);
179 static void sktr_tx_status_irq(struct net_device
*dev
);
181 static void sktr_update_rcv_stats(struct net_local
*tp
,
182 unsigned char DataPtr
[], unsigned int Length
);
184 static void sktr_wait(unsigned long time
);
185 static void sktr_write_rpl_status(RPL
*rpl
, unsigned int Status
);
186 static void sktr_write_tpl_status(TPL
*tpl
, unsigned int Status
);
189 * Check for a network adapter of this type, and return '0' if one exists.
190 * If dev->base_addr == 0, probe all likely locations.
191 * If dev->base_addr == 1, always return failure.
193 int __init
sktr_probe(struct net_device
*dev
)
196 int base_addr
= dev
? dev
->base_addr
: 0;
198 if(base_addr
> 0x1ff) /* Check a single specified location. */
199 return (sktr_probe1(dev
, base_addr
));
200 else if(base_addr
!= 0) /* Don't probe at all. */
203 for(i
= 0; sktr_portlist
[i
]; i
++)
205 int ioaddr
= sktr_portlist
[i
];
206 if(check_region(ioaddr
, SKTR_IO_EXTENT
))
208 if(sktr_probe1(dev
, ioaddr
))
222 * Detect and setup the PCI SysKonnect TR cards in slot order.
224 static int __init
sktr_pci_chk_card(struct net_device
*dev
)
226 static int pci_index
= 0;
227 unsigned char pci_bus
, pci_device_fn
;
230 return (-1); /* No PCI present. */
232 for(; pci_index
< 0xff; pci_index
++)
234 unsigned int pci_irq_line
;
235 struct pci_dev
*pdev
;
236 unsigned short pci_command
, new_command
, vendor
, device
;
237 unsigned int pci_ioaddr
;
239 if(pcibios_find_class(PCI_CLASS_NETWORK_TOKEN_RING
<< 8,
240 pci_index
, &pci_bus
, &pci_device_fn
)
241 != PCIBIOS_SUCCESSFUL
)
246 pcibios_read_config_word(pci_bus
, pci_device_fn
,
247 PCI_VENDOR_ID
, &vendor
);
248 pcibios_read_config_word(pci_bus
, pci_device_fn
,
249 PCI_DEVICE_ID
, &device
);
251 pdev
= pci_find_slot(pci_bus
, pci_device_fn
);
252 pci_irq_line
= pdev
->irq
;
253 pci_ioaddr
= pdev
->resource
[0].start
;
255 pcibios_read_config_word(pci_bus
, pci_device_fn
,
256 PCI_COMMAND
, &pci_command
);
258 /* Remove I/O space marker in bit 0. */
261 if((vendor
!= PCI_VENDOR_ID_SK
) &&
262 (vendor
!= PCI_VENDOR_ID_COMPAQ
))
265 if((vendor
== PCI_VENDOR_ID_SK
) &&
266 (device
!= PCI_DEVICE_ID_SK_TR
))
268 else if((vendor
== PCI_VENDOR_ID_COMPAQ
) &&
269 (device
!= PCI_DEVICE_ID_COMPAQ_TOKENRING
))
272 if(check_region(pci_ioaddr
, SKTR_IO_EXTENT
))
274 request_region(pci_ioaddr
, SKTR_IO_EXTENT
, pci_cardname
);
275 if(request_irq(pdev
->irq
, sktr_interrupt
, SA_SHIRQ
,
277 return (-ENODEV
); /* continue; ?? */
279 AdapterName
= pci_cardname
;
281 new_command
= (pci_command
|PCI_COMMAND_MASTER
|PCI_COMMAND_IO
);
283 if(pci_command
!= new_command
)
285 printk("The PCI BIOS has not enabled this"
286 "device! Updating PCI command %4.4x->%4.4x.\n",
287 pci_command
, new_command
);
288 pcibios_write_config_word(pci_bus
, pci_device_fn
,
289 PCI_COMMAND
, new_command
);
292 /* At this point we have found a valid PCI TR card. */
293 dev
->base_addr
= pci_ioaddr
;
294 dev
->irq
= pci_irq_line
;
297 printk("%s: %s found at %#4x, using IRQ %d.\n",
298 dev
->name
, AdapterName
, pci_ioaddr
, dev
->irq
);
307 * Detect and setup the ISA SysKonnect TR cards.
309 static int __init
sktr_isa_chk_card(struct net_device
*dev
, int ioaddr
)
314 err
= sktr_isa_chk_ioaddr(ioaddr
);
318 if(virt_to_bus((void*)((unsigned long)dev
->priv
+sizeof(struct net_local
)))
321 printk("%s: Memory not accessible for DMA\n", dev
->name
);
326 AdapterName
= isa_cardname
;
328 /* Grab the region so that no one else tries to probe our ioports. */
329 request_region(ioaddr
, SKTR_IO_EXTENT
, AdapterName
);
330 dev
->base_addr
= ioaddr
;
332 /* Autoselect IRQ and DMA if dev->irq == 0 */
335 for(i
= 0; sktr_irqlist
[i
] != 0; i
++)
337 dev
->irq
= sktr_irqlist
[i
];
338 err
= request_irq(dev
->irq
, &sktr_interrupt
, 0, AdapterName
, dev
);
343 if(sktr_irqlist
[i
] == 0)
345 printk("%s: AutoSelect no IRQ available\n", dev
->name
);
351 err
= request_irq(dev
->irq
, &sktr_interrupt
, 0, AdapterName
, dev
);
354 printk("%s: Selected IRQ not available\n", dev
->name
);
359 /* Always allocate the DMA channel after IRQ and clean up on failure */
362 for(i
= 0; sktr_dmalist
[i
] != 0; i
++)
364 dev
->dma
= sktr_dmalist
[i
];
365 err
= request_dma(dev
->dma
, AdapterName
);
372 printk("%s: AutoSelect no DMA available\n", dev
->name
);
373 free_irq(dev
->irq
, NULL
);
379 err
= request_dma(dev
->dma
, AdapterName
);
382 printk("%s: Selected DMA not available\n", dev
->name
);
383 free_irq(dev
->irq
, NULL
);
388 flags
=claim_dma_lock();
389 disable_dma(dev
->dma
);
390 set_dma_mode(dev
->dma
, DMA_MODE_CASCADE
);
391 enable_dma(dev
->dma
);
392 release_dma_lock(flags
);
394 printk("%s: %s found at %#4x, using IRQ %d and DMA %d.\n",
395 dev
->name
, AdapterName
, ioaddr
, dev
->irq
, dev
->dma
);
400 static int __init
sktr_probe1(struct net_device
*dev
, int ioaddr
)
402 static unsigned version_printed
= 0;
403 struct net_local
*tp
;
404 int DeviceType
= SK_PCI
;
407 if(sktr_debug
&& version_printed
++ == 0)
408 printk("%s", version
);
411 dev
= init_trdev(dev
, 0);
416 err
= sktr_pci_chk_card(dev
);
419 err
= sktr_isa_chk_card(dev
, ioaddr
);
425 /* Setup this devices private information structure */
426 tp
= (struct net_local
*)kmalloc(sizeof(struct net_local
), GFP_KERNEL
| GFP_DMA
);
429 memset(tp
, 0, sizeof(struct net_local
));
430 tp
->DeviceType
= DeviceType
;
431 init_waitqueue_head(&tp
->wait_for_tok_int
);
434 dev
->init
= sktr_init_card
;
435 dev
->open
= sktr_open
;
436 dev
->stop
= sktr_close
;
437 dev
->hard_start_xmit
= sktr_send_packet
;
438 dev
->get_stats
= sktr_get_stats
;
439 dev
->set_multicast_list
= &sktr_set_multicast_list
;
445 static int __init
sktr_init_card(struct net_device
*dev
)
448 printk("%s: sktr_init_card\n", dev
->name
);
454 * This function tests if an adapter is really installed at the
455 * given I/O address. Return negative if no adapter at IO addr.
457 static int __init
sktr_isa_chk_ioaddr(int ioaddr
)
459 unsigned char old
, chk1
, chk2
;
461 old
= inb(ioaddr
+ SIFADR
); /* Get the old SIFADR value */
463 chk1
= 0; /* Begin with check value 0 */
465 /* Write new SIFADR value */
466 outb(chk1
, ioaddr
+ SIFADR
);
468 /* Read, invert and write */
469 chk2
= inb(ioaddr
+ SIFADD
);
471 outb(chk2
, ioaddr
+ SIFADR
);
473 /* Read, invert and compare */
474 chk2
= inb(ioaddr
+ SIFADD
);
478 return (-1); /* No adapter */
481 } while(chk1
!= 0); /* Repeat 128 times (all byte values) */
483 /* Restore the SIFADR value */
484 outb(old
, ioaddr
+ SIFADR
);
490 * Open/initialize the board. This is called sometime after
491 * booting when the 'ifconfig' program is run.
493 * This routine should set everything up anew at each open, even
494 * registers that "should" only need to be set once at boot, so that
495 * there is non-reboot way to recover if something goes wrong.
497 static int sktr_open(struct net_device
*dev
)
499 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
502 /* Reset the hardware here. Don't forget to set the station address. */
503 err
= sktr_chipset_init(dev
);
506 printk(KERN_INFO
"%s: Chipset initialization error\n",
512 sktr_read_addr(dev
, (unsigned char*)dev
->dev_addr
);
514 init_timer(&tp
->timer
);
515 tp
->timer
.expires
= jiffies
+ 30*HZ
;
516 tp
->timer
.function
= sktr_timer_end_wait
;
517 tp
->timer
.data
= (unsigned long)dev
;
518 tp
->timer
.next
= NULL
;
519 tp
->timer
.prev
= NULL
;
520 add_timer(&tp
->timer
);
523 sktr_enable_interrupts(dev
);
524 sktr_open_adapter(dev
);
530 /* Wait for interrupt from hardware. If interrupt does not come,
531 * there will be a timeout from the timer.
534 interruptible_sleep_on(&tp
->wait_for_tok_int
);
535 del_timer(&tp
->timer
);
537 /* If AdapterVirtOpenFlag is 1, the adapter is now open for use */
538 if(tp
->AdapterVirtOpenFlag
== 0)
540 sktr_disable_interrupts(dev
);
546 tp
->StartTime
= jiffies
;
548 /* Start function control timer */
549 tp
->timer
.expires
= jiffies
+ 2*HZ
;
550 tp
->timer
.function
= sktr_timer_chk
;
551 tp
->timer
.data
= (unsigned long)dev
;
552 add_timer(&tp
->timer
);
562 * Timeout function while waiting for event
564 static void sktr_timer_end_wait(unsigned long data
)
566 struct net_device
*dev
= (struct net_device
*)data
;
567 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
572 wake_up_interruptible(&tp
->wait_for_tok_int
);
579 * Initialize the chipset
581 static int sktr_chipset_init(struct net_device
*dev
)
583 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
584 unsigned char PosReg
, Tmp
;
589 sktr_init_net_local(dev
);
591 /* Set pos register: selects irq and dma channel.
592 * Only for ISA bus adapters.
597 for(i
= 0; sktr_irqlist
[i
] != 0; i
++)
599 if(sktr_irqlist
[i
] == dev
->irq
)
603 /* Choose default cycle time, 500 nsec */
604 PosReg
|= CYCLE_TIME
<< 2;
609 if(tp
->DataRate
== SPEED_4
)
610 PosReg
|= LINE_SPEED_BIT
;
612 PosReg
&= ~LINE_SPEED_BIT
;
614 outb(PosReg
, dev
->base_addr
+ POSREG
);
615 Tmp
= inb(dev
->base_addr
+ POSREG
);
616 if((Tmp
& ~CYCLE_TIME
) != (PosReg
& ~CYCLE_TIME
))
617 printk(KERN_INFO
"%s: POSREG error\n", dev
->name
);
620 err
= sktr_reset_adapter(dev
);
624 err
= sktr_bringup_diags(dev
);
628 err
= sktr_init_adapter(dev
);
636 * Initializes the net_local structure.
638 static void sktr_init_net_local(struct net_device
*dev
)
640 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
654 tp
->AdapterOpenFlag
= 0;
655 tp
->AdapterVirtOpenFlag
= 0;
657 tp
->OpenCommandIssued
= 0;
658 tp
->ReOpenInProgress
= 0;
659 tp
->HaltInProgress
= 0;
660 tp
->TransmitHaltScheduled
= 0;
661 tp
->LobeWireFaultLogged
= 0;
662 tp
->LastOpenStatus
= 0;
663 tp
->MaxPacketSize
= DEFAULT_PACKET_SIZE
;
665 skb_queue_head_init(&tp
->SendSkbQueue
);
666 tp
->QueueSkb
= MAX_TX_QUEUE
;
668 /* Create circular chain of transmit lists */
669 for (i
= 0; i
< TPL_NUM
; i
++)
671 tp
->Tpl
[i
].NextTPLAddr
= htonl((unsigned long) virt_to_bus(&tp
->Tpl
[(i
+1) % TPL_NUM
]));
672 tp
->Tpl
[i
].Status
= 0;
673 tp
->Tpl
[i
].FrameSize
= 0;
674 tp
->Tpl
[i
].FragList
[0].DataCount
= 0;
675 tp
->Tpl
[i
].FragList
[0].DataAddr
= 0;
676 tp
->Tpl
[i
].NextTPLPtr
= &tp
->Tpl
[(i
+1) % TPL_NUM
];
677 tp
->Tpl
[i
].MData
= NULL
;
678 tp
->Tpl
[i
].TPLIndex
= i
;
679 tp
->Tpl
[i
].BusyFlag
= 0;
682 tp
->TplFree
= tp
->TplBusy
= &tp
->Tpl
[0];
684 /* Create circular chain of receive lists */
685 for (i
= 0; i
< RPL_NUM
; i
++)
687 tp
->Rpl
[i
].NextRPLAddr
= htonl((unsigned long) virt_to_bus(&tp
->Rpl
[(i
+1) % RPL_NUM
]));
688 tp
->Rpl
[i
].Status
= (RX_VALID
| RX_START_FRAME
| RX_END_FRAME
| RX_FRAME_IRQ
);
689 tp
->Rpl
[i
].FrameSize
= 0;
690 tp
->Rpl
[i
].FragList
[0].DataCount
= SWAPB(tp
->MaxPacketSize
);
692 /* Alloc skb and point adapter to data area */
693 tp
->Rpl
[i
].Skb
= dev_alloc_skb(tp
->MaxPacketSize
);
695 /* skb == NULL ? then use local buffer */
696 if(tp
->Rpl
[i
].Skb
== NULL
)
698 tp
->Rpl
[i
].SkbStat
= SKB_UNAVAILABLE
;
699 tp
->Rpl
[i
].FragList
[0].DataAddr
= htonl(virt_to_bus(tp
->LocalRxBuffers
[i
]));
700 tp
->Rpl
[i
].MData
= tp
->LocalRxBuffers
[i
];
702 else /* SKB != NULL */
704 tp
->Rpl
[i
].Skb
->dev
= dev
;
705 skb_put(tp
->Rpl
[i
].Skb
, tp
->MaxPacketSize
);
707 /* data unreachable for DMA ? then use local buffer */
708 if(tp
->DeviceType
== SK_ISA
&&
709 virt_to_bus(tp
->Rpl
[i
].Skb
->data
) +
710 tp
->MaxPacketSize
> ISA_MAX_ADDRESS
)
712 tp
->Rpl
[i
].SkbStat
= SKB_DATA_COPY
;
713 tp
->Rpl
[i
].FragList
[0].DataAddr
= htonl(virt_to_bus(tp
->LocalRxBuffers
[i
]));
714 tp
->Rpl
[i
].MData
= tp
->LocalRxBuffers
[i
];
716 else /* DMA directly in skb->data */
718 tp
->Rpl
[i
].SkbStat
= SKB_DMA_DIRECT
;
719 tp
->Rpl
[i
].FragList
[0].DataAddr
= htonl(virt_to_bus(tp
->Rpl
[i
].Skb
->data
));
720 tp
->Rpl
[i
].MData
= tp
->Rpl
[i
].Skb
->data
;
724 tp
->Rpl
[i
].NextRPLPtr
= &tp
->Rpl
[(i
+1) % RPL_NUM
];
725 tp
->Rpl
[i
].RPLIndex
= i
;
728 tp
->RplHead
= &tp
->Rpl
[0];
729 tp
->RplTail
= &tp
->Rpl
[RPL_NUM
-1];
730 tp
->RplTail
->Status
= (RX_START_FRAME
| RX_END_FRAME
| RX_FRAME_IRQ
);
736 * Initializes the initialisation parameter block.
738 static void sktr_init_ipb(struct net_local
*tp
)
740 tp
->ipb
.Init_Options
= BURST_MODE
;
741 tp
->ipb
.CMD_Status_IV
= 0;
744 tp
->ipb
.Ring_Status_IV
= 0;
745 tp
->ipb
.SCB_Clear_IV
= 0;
746 tp
->ipb
.Adapter_CHK_IV
= 0;
747 tp
->ipb
.RX_Burst_Size
= BURST_SIZE
;
748 tp
->ipb
.TX_Burst_Size
= BURST_SIZE
;
749 tp
->ipb
.DMA_Abort_Thrhld
= DMA_RETRIES
;
750 tp
->ipb
.SCB_Addr
= 0;
751 tp
->ipb
.SSB_Addr
= 0;
757 * Initializes the open parameter block.
759 static void sktr_init_opb(struct net_local
*tp
)
762 unsigned short RplSize
= RPL_SIZE
;
763 unsigned short TplSize
= TPL_SIZE
;
764 unsigned short BufferSize
= BUFFER_SIZE
;
766 tp
->ocpl
.OPENOptions
= 0;
767 tp
->ocpl
.OPENOptions
|= ENABLE_FULL_DUPLEX_SELECTION
;
768 /* tp->ocpl.OPENOptions |= PAD_ROUTING_FIELD; no more needed */
769 tp
->ocpl
.FullDuplex
= 0;
770 tp
->ocpl
.FullDuplex
|= OPEN_FULL_DUPLEX_OFF
;
772 /* Fixme: If mac address setable:
773 * for (i=0; i<LENGTH_OF_ADDRESS; i++)
774 * mac->Vam->ocpl.NodeAddr[i] = mac->CurrentAddress[i];
777 tp
->ocpl
.GroupAddr
= 0;
778 tp
->ocpl
.FunctAddr
= 0;
779 tp
->ocpl
.RxListSize
= SWAPB(RplSize
);
780 tp
->ocpl
.TxListSize
= SWAPB(TplSize
);
781 tp
->ocpl
.BufSize
= SWAPB(BufferSize
);
782 tp
->ocpl
.Reserved
= 0;
783 tp
->ocpl
.TXBufMin
= TX_BUF_MIN
;
784 tp
->ocpl
.TXBufMax
= TX_BUF_MAX
;
786 Addr
= htonl(virt_to_bus(tp
->ProductID
));
788 tp
->ocpl
.ProdIDAddr
[0] = LOWORD(Addr
);
789 tp
->ocpl
.ProdIDAddr
[1] = HIWORD(Addr
);
795 * Send OPEN command to adapter
797 static void sktr_open_adapter(struct net_device
*dev
)
799 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
801 if(tp
->OpenCommandIssued
)
804 tp
->OpenCommandIssued
= 1;
805 sktr_exec_cmd(dev
, OC_OPEN
);
811 * Clear the adapter's interrupt flag. Clear system interrupt enable
812 * (SINTEN): disable adapter to system interrupts.
814 static void sktr_disable_interrupts(struct net_device
*dev
)
816 outb(0, dev
->base_addr
+ SIFACL
);
822 * Set the adapter's interrupt flag. Set system interrupt enable
823 * (SINTEN): enable adapter to system interrupts.
825 static void sktr_enable_interrupts(struct net_device
*dev
)
827 outb(ACL_SINTEN
, dev
->base_addr
+ SIFACL
);
833 * Put command in command queue, try to execute it.
835 static void sktr_exec_cmd(struct net_device
*dev
, unsigned short Command
)
837 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
839 tp
->CMDqueue
|= Command
;
840 sktr_chk_outstanding_cmds(dev
);
846 * Gets skb from system, queues it and checks if it can be sent
848 static int sktr_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
850 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
855 * If we get here, some higher level has decided we are broken.
856 * There should really be a "kick me" function call instead.
858 * Resetting the token ring adapter takes a long time so just
859 * fake transmission time and go on trying. Our own timeout
860 * routine is in sktr_timer_chk()
863 dev
->trans_start
= jiffies
;
868 * If some higher layer thinks we've missed an tx-done interrupt we
875 * Block a timer-based transmit from overlapping. This could better be
876 * done with atomic_swap(1, dev->tbusy), but set_bit() works as well.
878 if(test_and_set_bit(0, (void*)&dev
->tbusy
) != 0)
880 printk("%s: Transmitter access conflict.\n", dev
->name
);
884 if(tp
->QueueSkb
== 0)
885 return (1); /* Return with tbusy set: queue full */
888 skb_queue_tail(&tp
->SendSkbQueue
, skb
);
889 sktr_hardware_send_packet(dev
, tp
);
897 * Move frames from internal skb queue into adapter tx queue
899 static void sktr_hardware_send_packet(struct net_device
*dev
, struct net_local
* tp
)
903 unsigned char *buf
, *newbuf
;
909 /* Try to get a free TPL from the chain.
911 * NOTE: We *must* always leave one unused TPL in the chain,
912 * because otherwise the adapter might send frames twice.
914 if(tp
->TplFree
->NextTPLPtr
->BusyFlag
) /* No free TPL */
916 printk(KERN_INFO
"%s: No free TPL\n", dev
->name
);
920 /* Send first buffer from queue */
921 skb
= skb_dequeue(&tp
->SendSkbQueue
);
926 /* Is buffer reachable for Busmaster-DMA? */
927 if(tp
->DeviceType
== SK_ISA
&&
928 virt_to_bus((void*)(((long) skb
->data
) + skb
->len
))
931 /* Copy frame to local buffer */
932 i
= tp
->TplFree
->TPLIndex
;
934 buf
= tp
->LocalTxBuffers
[i
];
935 memcpy(buf
, skb
->data
, length
);
940 /* Send direct from skb->data */
945 /* Source address in packet? */
946 sktr_chk_src_addr(newbuf
, dev
->dev_addr
);
948 tp
->LastSendTime
= jiffies
;
949 tpl
= tp
->TplFree
; /* Get the "free" TPL */
950 tpl
->BusyFlag
= 1; /* Mark TPL as busy */
951 tp
->TplFree
= tpl
->NextTPLPtr
;
953 /* Save the skb for delayed return of skb to system */
955 tpl
->FragList
[0].DataCount
= (unsigned short) SWAPB(length
);
956 tpl
->FragList
[0].DataAddr
= htonl(virt_to_bus(newbuf
));
958 /* Write the data length in the transmit list. */
959 tpl
->FrameSize
= (unsigned short) SWAPB(length
);
962 /* Transmit the frame and set the status values. */
963 sktr_write_tpl_status(tpl
, TX_VALID
| TX_START_FRAME
964 | TX_END_FRAME
| TX_PASS_SRC_ADDR
967 /* Let adapter send the frame. */
968 sktr_exec_sifcmd(dev
, CMD_TX_VALID
);
975 * Write the given value to the 'Status' field of the specified TPL.
976 * NOTE: This function should be used whenever the status of any TPL must be
977 * modified by the driver, because the compiler may otherwise change the
978 * order of instructions such that writing the TPL status may be executed at
979 * an undesireable time. When this function is used, the status is always
980 * written when the function is called.
982 static void sktr_write_tpl_status(TPL
*tpl
, unsigned int Status
)
984 tpl
->Status
= Status
;
987 static void sktr_chk_src_addr(unsigned char *frame
, unsigned char *hw_addr
)
991 if((((unsigned long)frame
[8]) & ~0x80) != 0) /* Compare 4 bytes */
993 if((unsigned short)frame
[12] != 0) /* Compare 2 bytes */
996 SRBit
= frame
[8] & 0x80;
997 memcpy(&frame
[8], hw_addr
, 6);
1004 * The timer routine: Check if adapter still open and working, reopen if not.
1006 static void sktr_timer_chk(unsigned long data
)
1008 struct net_device
*dev
= (struct net_device
*)data
;
1009 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1011 if(tp
->HaltInProgress
)
1014 sktr_chk_outstanding_cmds(dev
);
1015 if(time_before(tp
->LastSendTime
+ SEND_TIMEOUT
, jiffies
)
1016 && (tp
->QueueSkb
< MAX_TX_QUEUE
|| tp
->TplFree
!= tp
->TplBusy
))
1018 /* Anything to send, but stalled to long */
1019 tp
->LastSendTime
= jiffies
;
1020 sktr_exec_cmd(dev
, OC_CLOSE
); /* Does reopen automatically */
1023 tp
->timer
.expires
= jiffies
+ 2*HZ
;
1024 add_timer(&tp
->timer
);
1026 if(tp
->AdapterOpenFlag
|| tp
->ReOpenInProgress
)
1028 tp
->ReOpenInProgress
= 1;
1029 sktr_open_adapter(dev
);
1035 * The typical workload of the driver: Handle the network interface interrupts.
1037 static void sktr_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1039 struct net_device
*dev
= dev_id
;
1040 struct net_local
*tp
;
1042 unsigned short irq_type
;
1046 printk("%s: irq %d for unknown device.\n", dev
->name
, irq
);
1052 ioaddr
= dev
->base_addr
;
1053 tp
= (struct net_local
*)dev
->priv
;
1055 irq_type
= inw(ioaddr
+ SIFSTS
);
1057 while(irq_type
& STS_SYSTEM_IRQ
)
1059 irq_type
&= STS_IRQ_MASK
;
1061 if(!sktr_chk_ssb(tp
, irq_type
))
1063 printk(KERN_INFO
"%s: DATA LATE occurred\n", dev
->name
);
1069 case STS_IRQ_RECEIVE_STATUS
:
1070 sktr_reset_interrupt(dev
);
1071 sktr_rcv_status_irq(dev
);
1074 case STS_IRQ_TRANSMIT_STATUS
:
1075 /* Check if TRANSMIT.HALT command is complete */
1076 if(tp
->ssb
.Parm
[0] & COMMAND_COMPLETE
)
1078 tp
->TransmitCommandActive
= 0;
1079 tp
->TransmitHaltScheduled
= 0;
1081 /* Issue a new transmit command. */
1082 sktr_exec_cmd(dev
, OC_TRANSMIT
);
1085 sktr_reset_interrupt(dev
);
1086 sktr_tx_status_irq(dev
);
1089 case STS_IRQ_COMMAND_STATUS
:
1090 /* The SSB contains status of last command
1091 * other than receive/transmit.
1093 sktr_cmd_status_irq(dev
);
1096 case STS_IRQ_SCB_CLEAR
:
1097 /* The SCB is free for another command. */
1099 sktr_chk_outstanding_cmds(dev
);
1102 case STS_IRQ_RING_STATUS
:
1103 sktr_ring_status_irq(dev
);
1106 case STS_IRQ_ADAPTER_CHECK
:
1111 printk(KERN_INFO
"Unknown Token Ring IRQ\n");
1115 /* Reset system interrupt if not already done. */
1116 if(irq_type
!= STS_IRQ_TRANSMIT_STATUS
1117 && irq_type
!= STS_IRQ_RECEIVE_STATUS
)
1119 sktr_reset_interrupt(dev
);
1122 irq_type
= inw(ioaddr
+ SIFSTS
);
1131 * Reset the INTERRUPT SYSTEM bit and issue SSB CLEAR command.
1133 static void sktr_reset_interrupt(struct net_device
*dev
)
1135 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1136 SSB
*ssb
= &tp
->ssb
;
1139 * [Workaround for "Data Late"]
1140 * Set all fields of the SSB to well-defined values so we can
1141 * check if the adapter has written the SSB.
1144 ssb
->STS
= (unsigned short) -1;
1145 ssb
->Parm
[0] = (unsigned short) -1;
1146 ssb
->Parm
[1] = (unsigned short) -1;
1147 ssb
->Parm
[2] = (unsigned short) -1;
1149 /* Free SSB by issuing SSB_CLEAR command after reading IRQ code
1150 * and clear STS_SYSTEM_IRQ bit: enable adapter for further interrupts.
1152 sktr_exec_sifcmd(dev
, CMD_SSB_CLEAR
| CMD_CLEAR_SYSTEM_IRQ
);
1158 * Check if the SSB has actually been written by the adapter.
1160 static unsigned char sktr_chk_ssb(struct net_local
*tp
, unsigned short IrqType
)
1162 SSB
*ssb
= &tp
->ssb
; /* The address of the SSB. */
1164 /* C 0 1 2 INTERRUPT CODE
1165 * - - - - --------------
1166 * 1 1 1 1 TRANSMIT STATUS
1167 * 1 1 1 1 RECEIVE STATUS
1168 * 1 ? ? 0 COMMAND STATUS
1170 * 1 1 0 0 RING STATUS
1171 * 0 0 0 0 ADAPTER CHECK
1173 * 0 = SSB field not affected by interrupt
1174 * 1 = SSB field is affected by interrupt
1176 * C = SSB ADDRESS +0: COMMAND
1177 * 0 = SSB ADDRESS +2: STATUS 0
1178 * 1 = SSB ADDRESS +4: STATUS 1
1179 * 2 = SSB ADDRESS +6: STATUS 2
1182 /* Check if this interrupt does use the SSB. */
1184 if(IrqType
!= STS_IRQ_TRANSMIT_STATUS
1185 && IrqType
!= STS_IRQ_RECEIVE_STATUS
1186 && IrqType
!= STS_IRQ_COMMAND_STATUS
1187 && IrqType
!= STS_IRQ_RING_STATUS
)
1189 return (1); /* SSB not involved. */
1192 /* Note: All fields of the SSB have been set to all ones (-1) after it
1193 * has last been used by the software (see DriverIsr()).
1195 * Check if the affected SSB fields are still unchanged.
1198 if(ssb
->STS
== (unsigned short) -1)
1199 return (0); /* Command field not yet available. */
1200 if(IrqType
== STS_IRQ_COMMAND_STATUS
)
1201 return (1); /* Status fields not always affected. */
1202 if(ssb
->Parm
[0] == (unsigned short) -1)
1203 return (0); /* Status 1 field not yet available. */
1204 if(IrqType
== STS_IRQ_RING_STATUS
)
1205 return (1); /* Status 2 & 3 fields not affected. */
1207 /* Note: At this point, the interrupt is either TRANSMIT or RECEIVE. */
1208 if(ssb
->Parm
[1] == (unsigned short) -1)
1209 return (0); /* Status 2 field not yet available. */
1210 if(ssb
->Parm
[2] == (unsigned short) -1)
1211 return (0); /* Status 3 field not yet available. */
1213 return (1); /* All SSB fields have been written by the adapter. */
1217 * Evaluates the command results status in the SSB status field.
1219 static void sktr_cmd_status_irq(struct net_device
*dev
)
1221 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1222 unsigned short ssb_cmd
, ssb_parm_0
;
1223 unsigned short ssb_parm_1
;
1224 char *open_err
= "Open error -";
1225 char *code_err
= "Open code -";
1227 /* Copy the ssb values to local variables */
1228 ssb_cmd
= tp
->ssb
.STS
;
1229 ssb_parm_0
= tp
->ssb
.Parm
[0];
1230 ssb_parm_1
= tp
->ssb
.Parm
[1];
1235 if(!tp
->ReOpenInProgress
)
1236 wake_up_interruptible(&tp
->wait_for_tok_int
);
1238 tp
->OpenCommandIssued
= 0;
1241 if((ssb_parm_0
& 0x00FF) == GOOD_COMPLETION
)
1243 /* Success, the adapter is open. */
1244 tp
->LobeWireFaultLogged
= 0;
1245 tp
->AdapterOpenFlag
= 1;
1246 tp
->AdapterVirtOpenFlag
= 1;
1247 tp
->TransmitCommandActive
= 0;
1248 sktr_exec_cmd(dev
, OC_TRANSMIT
);
1249 sktr_exec_cmd(dev
, OC_RECEIVE
);
1251 if(tp
->ReOpenInProgress
)
1252 tp
->ReOpenInProgress
= 0;
1256 else /* The adapter did not open. */
1258 if(ssb_parm_0
& NODE_ADDR_ERROR
)
1259 printk(KERN_INFO
"%s: Node address error\n",
1261 if(ssb_parm_0
& LIST_SIZE_ERROR
)
1262 printk(KERN_INFO
"%s: List size error\n",
1264 if(ssb_parm_0
& BUF_SIZE_ERROR
)
1265 printk(KERN_INFO
"%s: Buffer size error\n",
1267 if(ssb_parm_0
& TX_BUF_COUNT_ERROR
)
1268 printk(KERN_INFO
"%s: Tx buffer count error\n",
1270 if(ssb_parm_0
& INVALID_OPEN_OPTION
)
1271 printk(KERN_INFO
"%s: Invalid open option\n",
1273 if(ssb_parm_0
& OPEN_ERROR
)
1275 /* Show the open phase. */
1276 switch(ssb_parm_0
& OPEN_PHASES_MASK
)
1278 case LOBE_MEDIA_TEST
:
1279 if(!tp
->LobeWireFaultLogged
)
1281 tp
->LobeWireFaultLogged
= 1;
1282 printk(KERN_INFO
"%s: %s Lobe wire fault (check cable !).\n", dev
->name
, open_err
);
1284 tp
->ReOpenInProgress
= 1;
1285 tp
->AdapterOpenFlag
= 0;
1286 tp
->AdapterVirtOpenFlag
= 1;
1287 sktr_open_adapter(dev
);
1290 case PHYSICAL_INSERTION
:
1291 printk(KERN_INFO
"%s: %s Physical insertion.\n", dev
->name
, open_err
);
1294 case ADDRESS_VERIFICATION
:
1295 printk(KERN_INFO
"%s: %s Address verification.\n", dev
->name
, open_err
);
1298 case PARTICIPATION_IN_RING_POLL
:
1299 printk(KERN_INFO
"%s: %s Participation in ring poll.\n", dev
->name
, open_err
);
1302 case REQUEST_INITIALISATION
:
1303 printk(KERN_INFO
"%s: %s Request initialisation.\n", dev
->name
, open_err
);
1306 case FULLDUPLEX_CHECK
:
1307 printk(KERN_INFO
"%s: %s Full duplex check.\n", dev
->name
, open_err
);
1311 printk(KERN_INFO
"%s: %s Unknown open phase\n", dev
->name
, open_err
);
1315 /* Show the open errors. */
1316 switch(ssb_parm_0
& OPEN_ERROR_CODES_MASK
)
1318 case OPEN_FUNCTION_FAILURE
:
1319 printk(KERN_INFO
"%s: %s OPEN_FUNCTION_FAILURE", dev
->name
, code_err
);
1320 tp
->LastOpenStatus
=
1321 OPEN_FUNCTION_FAILURE
;
1324 case OPEN_SIGNAL_LOSS
:
1325 printk(KERN_INFO
"%s: %s OPEN_SIGNAL_LOSS\n", dev
->name
, code_err
);
1326 tp
->LastOpenStatus
=
1331 printk(KERN_INFO
"%s: %s OPEN_TIMEOUT\n", dev
->name
, code_err
);
1332 tp
->LastOpenStatus
=
1336 case OPEN_RING_FAILURE
:
1337 printk(KERN_INFO
"%s: %s OPEN_RING_FAILURE\n", dev
->name
, code_err
);
1338 tp
->LastOpenStatus
=
1342 case OPEN_RING_BEACONING
:
1343 printk(KERN_INFO
"%s: %s OPEN_RING_BEACONING\n", dev
->name
, code_err
);
1344 tp
->LastOpenStatus
=
1345 OPEN_RING_BEACONING
;
1348 case OPEN_DUPLICATE_NODEADDR
:
1349 printk(KERN_INFO
"%s: %s OPEN_DUPLICATE_NODEADDR\n", dev
->name
, code_err
);
1350 tp
->LastOpenStatus
=
1351 OPEN_DUPLICATE_NODEADDR
;
1354 case OPEN_REQUEST_INIT
:
1355 printk(KERN_INFO
"%s: %s OPEN_REQUEST_INIT\n", dev
->name
, code_err
);
1356 tp
->LastOpenStatus
=
1360 case OPEN_REMOVE_RECEIVED
:
1361 printk(KERN_INFO
"%s: %s OPEN_REMOVE_RECEIVED", dev
->name
, code_err
);
1362 tp
->LastOpenStatus
=
1363 OPEN_REMOVE_RECEIVED
;
1366 case OPEN_FULLDUPLEX_SET
:
1367 printk(KERN_INFO
"%s: %s OPEN_FULLDUPLEX_SET\n", dev
->name
, code_err
);
1368 tp
->LastOpenStatus
=
1369 OPEN_FULLDUPLEX_SET
;
1373 printk(KERN_INFO
"%s: %s Unknown open err code", dev
->name
, code_err
);
1374 tp
->LastOpenStatus
=
1375 OPEN_FUNCTION_FAILURE
;
1380 tp
->AdapterOpenFlag
= 0;
1381 tp
->AdapterVirtOpenFlag
= 0;
1388 if(ssb_cmd
!= READ_ERROR_LOG
)
1391 /* Add values from the error log table to the MAC
1392 * statistics counters and update the errorlogtable
1395 tp
->MacStat
.line_errors
+= tp
->errorlogtable
.Line_Error
;
1396 tp
->MacStat
.burst_errors
+= tp
->errorlogtable
.Burst_Error
;
1397 tp
->MacStat
.A_C_errors
+= tp
->errorlogtable
.ARI_FCI_Error
;
1398 tp
->MacStat
.lost_frames
+= tp
->errorlogtable
.Lost_Frame_Error
;
1399 tp
->MacStat
.recv_congest_count
+= tp
->errorlogtable
.Rx_Congest_Error
;
1400 tp
->MacStat
.rx_errors
+= tp
->errorlogtable
.Rx_Congest_Error
;
1401 tp
->MacStat
.frame_copied_errors
+= tp
->errorlogtable
.Frame_Copied_Error
;
1402 tp
->MacStat
.token_errors
+= tp
->errorlogtable
.Token_Error
;
1403 tp
->MacStat
.dummy1
+= tp
->errorlogtable
.DMA_Bus_Error
;
1404 tp
->MacStat
.dummy1
+= tp
->errorlogtable
.DMA_Parity_Error
;
1405 tp
->MacStat
.abort_delimiters
+= tp
->errorlogtable
.AbortDelimeters
;
1406 tp
->MacStat
.frequency_errors
+= tp
->errorlogtable
.Frequency_Error
;
1407 tp
->MacStat
.internal_errors
+= tp
->errorlogtable
.Internal_Error
;
1414 * The inverse routine to sktr_open().
1416 static int sktr_close(struct net_device
*dev
)
1418 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1423 del_timer(&tp
->timer
);
1425 /* Flush the Tx and disable Rx here. */
1427 tp
->HaltInProgress
= 1;
1428 sktr_exec_cmd(dev
, OC_CLOSE
);
1429 tp
->timer
.expires
= jiffies
+ 1*HZ
;
1430 tp
->timer
.function
= sktr_timer_end_wait
;
1431 tp
->timer
.data
= (unsigned long)dev
;
1432 add_timer(&tp
->timer
);
1434 sktr_enable_interrupts(dev
);
1437 interruptible_sleep_on(&tp
->wait_for_tok_int
);
1438 tp
->TransmitCommandActive
= 0;
1440 del_timer(&tp
->timer
);
1441 sktr_disable_interrupts(dev
);
1445 unsigned long flags
=claim_dma_lock();
1446 disable_dma(dev
->dma
);
1447 release_dma_lock(flags
);
1450 outw(0xFF00, dev
->base_addr
+ SIFCMD
);
1452 outb(0xff, dev
->base_addr
+ POSREG
);
1458 sktr_cancel_tx_queue(tp
);
1464 * Get the current statistics. This may be called with the card open
1467 static struct enet_statistics
*sktr_get_stats(struct net_device
*dev
)
1469 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1471 return ((struct enet_statistics
*)&tp
->MacStat
);
1475 * Set or clear the multicast filter for this adapter.
1477 static void sktr_set_multicast_list(struct net_device
*dev
)
1479 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1480 unsigned int OpenOptions
;
1482 OpenOptions
= tp
->ocpl
.OPENOptions
&
1483 ~(PASS_ADAPTER_MAC_FRAMES
1484 | PASS_ATTENTION_FRAMES
1485 | PASS_BEACON_MAC_FRAMES
1486 | COPY_ALL_MAC_FRAMES
1487 | COPY_ALL_NON_MAC_FRAMES
);
1489 tp
->ocpl
.FunctAddr
= 0;
1491 if(dev
->flags
& IFF_PROMISC
)
1492 /* Enable promiscuous mode */
1493 OpenOptions
|= COPY_ALL_NON_MAC_FRAMES
|
1494 COPY_ALL_MAC_FRAMES
;
1497 if(dev
->flags
& IFF_ALLMULTI
)
1499 /* Disable promiscuous mode, use normal mode. */
1500 tp
->ocpl
.FunctAddr
= 0xFFFFFFFF;
1506 struct dev_mc_list
*mclist
= dev
->mc_list
;
1507 for (i
=0; i
< dev
->mc_count
; i
++)
1509 ((char *)(&tp
->ocpl
.FunctAddr
))[0] |=
1510 mclist
->dmi_addr
[2];
1511 ((char *)(&tp
->ocpl
.FunctAddr
))[1] |=
1512 mclist
->dmi_addr
[3];
1513 ((char *)(&tp
->ocpl
.FunctAddr
))[2] |=
1514 mclist
->dmi_addr
[4];
1515 ((char *)(&tp
->ocpl
.FunctAddr
))[3] |=
1516 mclist
->dmi_addr
[5];
1517 mclist
= mclist
->next
;
1520 sktr_exec_cmd(dev
, OC_SET_FUNCT_ADDR
);
1523 tp
->ocpl
.OPENOptions
= OpenOptions
;
1524 sktr_exec_cmd(dev
, OC_MODIFY_OPEN_PARMS
);
1529 * Wait for some time (microseconds)
1531 * udelay() is a bit harsh, but using a looser timer causes
1532 * the bring-up-diags to stall indefinitly.
1536 static void sktr_wait(unsigned long time
)
1543 * Write a command value to the SIFCMD register
1545 static void sktr_exec_sifcmd(struct net_device
*dev
, unsigned int WriteValue
)
1547 int ioaddr
= dev
->base_addr
;
1549 unsigned short SifStsValue
;
1550 unsigned long loop_counter
;
1552 WriteValue
= ((WriteValue
^ CMD_SYSTEM_IRQ
) | CMD_INTERRUPT_ADAPTER
);
1553 cmd
= (unsigned short)WriteValue
;
1554 loop_counter
= 0,5 * 800000;
1556 SifStsValue
= inw(ioaddr
+ SIFSTS
);
1557 } while((SifStsValue
& CMD_INTERRUPT_ADAPTER
) && loop_counter
--);
1558 outw(cmd
, ioaddr
+ SIFCMD
);
1564 * Processes adapter hardware reset, halts adapter and downloads firmware,
1565 * clears the halt bit.
1567 static int sktr_reset_adapter(struct net_device
*dev
)
1569 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1570 unsigned short *fw_ptr
= (unsigned short *)&sktr_code
;
1571 unsigned short count
, c
;
1572 int ioaddr
= dev
->base_addr
;
1574 /* Hardware adapter reset */
1575 outw(ACL_ARESET
, ioaddr
+ SIFACL
);
1578 c
= inw(ioaddr
+ SIFACL
);
1581 if(dev
->dma
== 0) /* For PCI adapters */
1583 c
&= ~(ACL_SPEED4
| ACL_SPEED16
); /* Clear bits */
1584 if(tp
->DataRate
== SPEED_4
)
1585 c
|= ACL_SPEED4
; /* Set 4Mbps */
1587 c
|= ACL_SPEED16
; /* Set 16Mbps */
1590 /* In case a command is pending - forget it */
1593 c
&= ~ACL_ARESET
; /* Clear adapter reset bit */
1594 c
|= ACL_CPHALT
; /* Halt adapter CPU, allow download */
1595 c
&= ~ACL_PSDMAEN
; /* Clear pseudo dma bit */
1596 outw(c
, ioaddr
+ SIFACL
);
1599 /* Download firmware via DIO interface: */
1601 /* Download first address part */
1602 outw(*fw_ptr
, ioaddr
+ SIFADX
);
1605 /* Download second address part */
1606 outw(*fw_ptr
, ioaddr
+ SIFADD
);
1609 if((count
= *fw_ptr
) != 0) /* Load loop counter */
1611 fw_ptr
++; /* Download block data */
1612 for(; count
> 0; count
--)
1614 outw(*fw_ptr
, ioaddr
+ SIFINC
);
1618 else /* Stop, if last block downloaded */
1620 c
= inw(ioaddr
+ SIFACL
);
1621 c
&= (~ACL_CPHALT
| ACL_SINTEN
);
1623 /* Clear CPHALT and start BUD */
1624 outw(c
, ioaddr
+ SIFACL
);
1627 } while(count
== 0);
1633 * Starts bring up diagnostics of token ring adapter and evaluates
1634 * diagnostic results.
1636 static int sktr_bringup_diags(struct net_device
*dev
)
1638 int loop_cnt
, retry_cnt
;
1639 unsigned short Status
;
1640 int ioaddr
= dev
->base_addr
;
1642 sktr_wait(HALF_SECOND
);
1643 sktr_exec_sifcmd(dev
, EXEC_SOFT_RESET
);
1644 sktr_wait(HALF_SECOND
);
1646 retry_cnt
= BUD_MAX_RETRIES
; /* maximal number of retrys */
1651 printk(KERN_INFO
"BUD-Status: \n");
1652 loop_cnt
= BUD_MAX_LOOPCNT
; /* maximum: three seconds*/
1653 do { /* Inspect BUD results */
1655 sktr_wait(HALF_SECOND
);
1656 Status
= inw(ioaddr
+ SIFSTS
);
1660 printk(KERN_INFO
" %04X \n", Status
);
1661 /* BUD successfully completed */
1662 if(Status
== STS_INITIALIZE
)
1664 /* Unrecoverable hardware error, BUD not completed? */
1665 } while((loop_cnt
> 0) && ((Status
& (STS_ERROR
| STS_TEST
))
1666 != (STS_ERROR
| STS_TEST
)));
1668 /* Error preventing completion of BUD */
1671 printk(KERN_INFO
"%s: Adapter Software Reset.\n",
1673 sktr_exec_sifcmd(dev
, EXEC_SOFT_RESET
);
1674 sktr_wait(HALF_SECOND
);
1676 } while(retry_cnt
> 0);
1678 Status
= inw(ioaddr
+ SIFSTS
);
1679 Status
&= STS_ERROR_MASK
; /* Hardware error occurred! */
1681 printk(KERN_INFO
"%s: Bring Up Diagnostics Error (%04X) occurred\n",
1688 * Copy initialisation data to adapter memory, beginning at address
1689 * 1:0A00; Starting DMA test and evaluating result bits.
1691 static int sktr_init_adapter(struct net_device
*dev
)
1693 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1695 const unsigned char SCB_Test
[6] = {0x00, 0x00, 0xC1, 0xE2, 0xD4, 0x8B};
1696 const unsigned char SSB_Test
[8] = {0xFF, 0xFF, 0xD1, 0xD7,
1697 0xC5, 0xD9, 0xC3, 0xD4};
1698 void *ptr
= (void *)&tp
->ipb
;
1699 unsigned short *ipb_ptr
= (unsigned short *)ptr
;
1700 unsigned char *cb_ptr
= (unsigned char *) &tp
->scb
;
1701 unsigned char *sb_ptr
= (unsigned char *) &tp
->ssb
;
1702 unsigned short Status
;
1703 int i
, loop_cnt
, retry_cnt
;
1704 int ioaddr
= dev
->base_addr
;
1706 /* Normalize: byte order low/high, word order high/low! (only IPB!) */
1707 tp
->ipb
.SCB_Addr
= SWAPW(virt_to_bus(&tp
->scb
));
1708 tp
->ipb
.SSB_Addr
= SWAPW(virt_to_bus(&tp
->ssb
));
1710 /* Maximum: three initialization retries */
1711 retry_cnt
= INIT_MAX_RETRIES
;
1716 /* Transfer initialization block */
1717 outw(0x0001, ioaddr
+ SIFADX
);
1719 /* To address 0001:0A00 of adapter RAM */
1720 outw(0x0A00, ioaddr
+ SIFADD
);
1722 /* Write 11 words to adapter RAM */
1723 for(i
= 0; i
< 11; i
++)
1724 outw(ipb_ptr
[i
], ioaddr
+ SIFINC
);
1726 /* Execute SCB adapter command */
1727 sktr_exec_sifcmd(dev
, CMD_EXECUTE
);
1729 loop_cnt
= INIT_MAX_LOOPCNT
; /* Maximum: 11 seconds */
1731 /* While remaining retries, no error and not completed */
1735 sktr_wait(HALF_SECOND
);
1737 /* Mask interesting status bits */
1738 Status
= inw(ioaddr
+ SIFSTS
);
1740 } while(((Status
&(STS_INITIALIZE
| STS_ERROR
| STS_TEST
)) != 0)
1741 && ((Status
& STS_ERROR
) == 0) && (loop_cnt
!= 0));
1743 if((Status
& (STS_INITIALIZE
| STS_ERROR
| STS_TEST
)) == 0)
1745 /* Initialization completed without error */
1747 do { /* Test if contents of SCB is valid */
1748 if(SCB_Test
[i
] != *(cb_ptr
+ i
))
1749 /* DMA data error: wrong data in SCB */
1755 do { /* Test if contents of SSB is valid */
1756 if(SSB_Test
[i
] != *(sb_ptr
+ i
))
1757 /* DMA data error: wrong data in SSB */
1762 return (1); /* Adapter successfully initialized */
1766 if((Status
& STS_ERROR
) != 0)
1768 /* Initialization error occurred */
1769 Status
= inw(ioaddr
+ SIFSTS
);
1770 Status
&= STS_ERROR_MASK
;
1771 /* ShowInitialisationErrorCode(Status); */
1772 return (-1); /* Unrecoverable error */
1778 /* Reset adapter and try init again */
1779 sktr_exec_sifcmd(dev
, EXEC_SOFT_RESET
);
1780 sktr_wait(HALF_SECOND
);
1784 } while(retry_cnt
> 0);
1790 * Check for outstanding commands in command queue and tries to execute
1791 * command immediately. Corresponding command flag in command queue is cleared.
1793 static void sktr_chk_outstanding_cmds(struct net_device
*dev
)
1795 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1796 unsigned long Addr
= 0;
1797 unsigned char i
= 0;
1799 if(tp
->CMDqueue
== 0)
1800 return; /* No command execution */
1802 /* If SCB in use: no command */
1803 if(tp
->ScbInUse
== 1)
1806 /* Check if adapter is opened, avoiding COMMAND_REJECT
1807 * interrupt by the adapter!
1809 if(tp
->AdapterOpenFlag
== 0)
1811 if(tp
->CMDqueue
& OC_OPEN
)
1813 /* Execute OPEN command */
1814 tp
->CMDqueue
^= OC_OPEN
;
1816 /* Copy the 18 bytes of the product ID */
1817 while((AdapterName
[i
] != '\0') && (i
< PROD_ID_SIZE
))
1819 tp
->ProductID
[i
] = AdapterName
[i
];
1823 Addr
= htonl(virt_to_bus(&tp
->ocpl
));
1824 tp
->scb
.Parm
[0] = LOWORD(Addr
);
1825 tp
->scb
.Parm
[1] = HIWORD(Addr
);
1829 /* No OPEN command queued, but adapter closed. Note:
1830 * We'll try to re-open the adapter in DriverPoll()
1832 return; /* No adapter command issued */
1836 /* Adapter is open; evaluate command queue: try to execute
1837 * outstanding commands (depending on priority!) CLOSE
1840 if(tp
->CMDqueue
& OC_CLOSE
)
1842 tp
->CMDqueue
^= OC_CLOSE
;
1843 tp
->AdapterOpenFlag
= 0;
1844 tp
->scb
.Parm
[0] = 0; /* Parm[0], Parm[1] are ignored */
1845 tp
->scb
.Parm
[1] = 0; /* but should be set to zero! */
1846 tp
->scb
.CMD
= CLOSE
;
1847 if(!tp
->HaltInProgress
)
1848 tp
->CMDqueue
|= OC_OPEN
; /* re-open adapter */
1850 tp
->CMDqueue
= 0; /* no more commands */
1854 if(tp
->CMDqueue
& OC_RECEIVE
)
1856 tp
->CMDqueue
^= OC_RECEIVE
;
1857 Addr
= htonl(virt_to_bus(tp
->RplHead
));
1858 tp
->scb
.Parm
[0] = LOWORD(Addr
);
1859 tp
->scb
.Parm
[1] = HIWORD(Addr
);
1860 tp
->scb
.CMD
= RECEIVE
;
1864 if(tp
->CMDqueue
& OC_TRANSMIT_HALT
)
1866 /* NOTE: TRANSMIT.HALT must be checked
1869 tp
->CMDqueue
^= OC_TRANSMIT_HALT
;
1870 tp
->scb
.CMD
= TRANSMIT_HALT
;
1872 /* Parm[0] and Parm[1] are ignored
1873 * but should be set to zero!
1875 tp
->scb
.Parm
[0] = 0;
1876 tp
->scb
.Parm
[1] = 0;
1880 if(tp
->CMDqueue
& OC_TRANSMIT
)
1882 /* NOTE: TRANSMIT must be
1883 * checked after TRANSMIT.HALT
1885 if(tp
->TransmitCommandActive
)
1887 if(!tp
->TransmitHaltScheduled
)
1889 tp
->TransmitHaltScheduled
= 1;
1890 sktr_exec_cmd(dev
, OC_TRANSMIT_HALT
) ;
1892 tp
->TransmitCommandActive
= 0;
1896 tp
->CMDqueue
^= OC_TRANSMIT
;
1897 sktr_cancel_tx_queue(tp
);
1898 Addr
= htonl(virt_to_bus(tp
->TplBusy
));
1899 tp
->scb
.Parm
[0] = LOWORD(Addr
);
1900 tp
->scb
.Parm
[1] = HIWORD(Addr
);
1901 tp
->scb
.CMD
= TRANSMIT
;
1902 tp
->TransmitCommandActive
= 1;
1906 if(tp
->CMDqueue
& OC_MODIFY_OPEN_PARMS
)
1908 tp
->CMDqueue
^= OC_MODIFY_OPEN_PARMS
;
1909 tp
->scb
.Parm
[0] = tp
->ocpl
.OPENOptions
; /* new OPEN options*/
1910 tp
->scb
.Parm
[0] |= ENABLE_FULL_DUPLEX_SELECTION
;
1911 tp
->scb
.Parm
[1] = 0; /* is ignored but should be zero */
1912 tp
->scb
.CMD
= MODIFY_OPEN_PARMS
;
1916 if(tp
->CMDqueue
& OC_SET_FUNCT_ADDR
)
1918 tp
->CMDqueue
^= OC_SET_FUNCT_ADDR
;
1919 tp
->scb
.Parm
[0] = LOWORD(tp
->ocpl
.FunctAddr
);
1920 tp
->scb
.Parm
[1] = HIWORD(tp
->ocpl
.FunctAddr
);
1921 tp
->scb
.CMD
= SET_FUNCT_ADDR
;
1925 if(tp
->CMDqueue
& OC_SET_GROUP_ADDR
)
1927 tp
->CMDqueue
^= OC_SET_GROUP_ADDR
;
1928 tp
->scb
.Parm
[0] = LOWORD(tp
->ocpl
.GroupAddr
);
1929 tp
->scb
.Parm
[1] = HIWORD(tp
->ocpl
.GroupAddr
);
1930 tp
->scb
.CMD
= SET_GROUP_ADDR
;
1934 if(tp
->CMDqueue
& OC_READ_ERROR_LOG
)
1936 tp
->CMDqueue
^= OC_READ_ERROR_LOG
;
1937 Addr
= htonl(virt_to_bus(&tp
->errorlogtable
));
1938 tp
->scb
.Parm
[0] = LOWORD(Addr
);
1939 tp
->scb
.Parm
[1] = HIWORD(Addr
);
1940 tp
->scb
.CMD
= READ_ERROR_LOG
;
1944 printk(KERN_WARNING
"CheckForOutstandingCommand: unknown Command\n");
1957 tp
->ScbInUse
= 1; /* Set semaphore: SCB in use. */
1959 /* Execute SCB and generate IRQ when done. */
1960 sktr_exec_sifcmd(dev
, CMD_EXECUTE
| CMD_SCB_REQUEST
);
1966 * IRQ conditions: signal loss on the ring, transmit or receive of beacon
1967 * frames (disabled if bit 1 of OPEN option is set); report error MAC
1968 * frame transmit (disabled if bit 2 of OPEN option is set); open or short
1969 * cirquit fault on the lobe is detected; remove MAC frame received;
1970 * error counter overflow (255); opened adapter is the only station in ring.
1971 * After some of the IRQs the adapter is closed!
1973 static void sktr_ring_status_irq(struct net_device
*dev
)
1975 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1977 tp
->CurrentRingStatus
= SWAPB(tp
->ssb
.Parm
[0]);
1979 /* First: fill up statistics */
1980 if(tp
->ssb
.Parm
[0] & SIGNAL_LOSS
)
1982 printk(KERN_INFO
"%s: Signal Loss\n", dev
->name
);
1983 tp
->MacStat
.line_errors
++;
1986 /* Adapter is closed, but initialized */
1987 if(tp
->ssb
.Parm
[0] & LOBE_WIRE_FAULT
)
1989 printk(KERN_INFO
"%s: Lobe Wire Fault, Reopen Adapter\n",
1991 tp
->MacStat
.line_errors
++;
1994 if(tp
->ssb
.Parm
[0] & RING_RECOVERY
)
1995 printk(KERN_INFO
"%s: Ring Recovery\n", dev
->name
);
1997 /* Counter overflow: read error log */
1998 if(tp
->ssb
.Parm
[0] & COUNTER_OVERFLOW
)
2000 printk(KERN_INFO
"%s: Counter Overflow\n", dev
->name
);
2001 sktr_exec_cmd(dev
, OC_READ_ERROR_LOG
);
2004 /* Adapter is closed, but initialized */
2005 if(tp
->ssb
.Parm
[0] & REMOVE_RECEIVED
)
2006 printk(KERN_INFO
"%s: Remove Received, Reopen Adapter\n",
2009 /* Adapter is closed, but initialized */
2010 if(tp
->ssb
.Parm
[0] & AUTO_REMOVAL_ERROR
)
2011 printk(KERN_INFO
"%s: Auto Removal Error, Reopen Adapter\n",
2014 if(tp
->ssb
.Parm
[0] & HARD_ERROR
)
2015 printk(KERN_INFO
"%s: Hard Error\n", dev
->name
);
2017 if(tp
->ssb
.Parm
[0] & SOFT_ERROR
)
2018 printk(KERN_INFO
"%s: Soft Error\n", dev
->name
);
2020 if(tp
->ssb
.Parm
[0] & TRANSMIT_BEACON
)
2021 printk(KERN_INFO
"%s: Transmit Beacon\n", dev
->name
);
2023 if(tp
->ssb
.Parm
[0] & SINGLE_STATION
)
2024 printk(KERN_INFO
"%s: Single Station\n", dev
->name
);
2026 /* Check if adapter has been closed */
2027 if(tp
->ssb
.Parm
[0] & ADAPTER_CLOSED
)
2029 printk(KERN_INFO
"%s: Adapter closed (Reopening),"
2030 "QueueSkb %d, CurrentRingStat %x\n",
2031 dev
->name
, tp
->QueueSkb
, tp
->CurrentRingStatus
);
2032 tp
->AdapterOpenFlag
= 0;
2033 sktr_open_adapter(dev
);
2040 * Issued if adapter has encountered an unrecoverable hardware
2041 * or software error.
2043 static void sktr_chk_irq(struct net_device
*dev
)
2046 unsigned short AdapterCheckBlock
[4];
2047 unsigned short ioaddr
= dev
->base_addr
;
2048 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
2050 tp
->AdapterOpenFlag
= 0; /* Adapter closed now */
2052 /* Page number of adapter memory */
2053 outw(0x0001, ioaddr
+ SIFADX
);
2054 /* Address offset */
2055 outw(CHECKADDR
, ioaddr
+ SIFADR
);
2057 /* Reading 8 byte adapter check block. */
2058 for(i
= 0; i
< 4; i
++)
2059 AdapterCheckBlock
[i
] = inw(ioaddr
+ SIFINC
);
2063 printk("%s: AdapterCheckBlock: ", dev
->name
);
2064 for (i
= 0; i
< 4; i
++)
2065 printk("%04X", AdapterCheckBlock
[i
]);
2069 switch(AdapterCheckBlock
[0])
2072 printk(KERN_INFO
"%s: DIO parity error\n", dev
->name
);
2075 case DMA_READ_ABORT
:
2076 printk(KERN_INFO
"%s DMA read operation aborted:\n",
2078 switch (AdapterCheckBlock
[1])
2081 printk(KERN_INFO
"Timeout\n");
2082 printk(KERN_INFO
"Address: %04X %04X\n",
2083 AdapterCheckBlock
[2],
2084 AdapterCheckBlock
[3]);
2088 printk(KERN_INFO
"Parity error\n");
2089 printk(KERN_INFO
"Address: %04X %04X\n",
2090 AdapterCheckBlock
[2],
2091 AdapterCheckBlock
[3]);
2095 printk(KERN_INFO
"Bus error\n");
2096 printk(KERN_INFO
"Address: %04X %04X\n",
2097 AdapterCheckBlock
[2],
2098 AdapterCheckBlock
[3]);
2102 printk(KERN_INFO
"Unknown error.\n");
2107 case DMA_WRITE_ABORT
:
2108 printk(KERN_INFO
"%s: DMA write operation aborted: \n",
2110 switch (AdapterCheckBlock
[1])
2113 printk(KERN_INFO
"Timeout\n");
2114 printk(KERN_INFO
"Address: %04X %04X\n",
2115 AdapterCheckBlock
[2],
2116 AdapterCheckBlock
[3]);
2120 printk(KERN_INFO
"Parity error\n");
2121 printk(KERN_INFO
"Address: %04X %04X\n",
2122 AdapterCheckBlock
[2],
2123 AdapterCheckBlock
[3]);
2127 printk(KERN_INFO
"Bus error\n");
2128 printk(KERN_INFO
"Address: %04X %04X\n",
2129 AdapterCheckBlock
[2],
2130 AdapterCheckBlock
[3]);
2134 printk(KERN_INFO
"Unknown error.\n");
2139 case ILLEGAL_OP_CODE
:
2140 printk("%s: Illegal operation code in firmware\n",
2142 /* Parm[0-3]: adapter internal register R13-R15 */
2146 printk("%s: Adapter internal bus parity error\n",
2148 /* Parm[0-3]: adapter internal register R13-R15 */
2151 case RAM_DATA_ERROR
:
2152 printk("%s: RAM data error\n", dev
->name
);
2153 /* Parm[0-1]: MSW/LSW address of RAM location. */
2156 case RAM_PARITY_ERROR
:
2157 printk("%s: RAM parity error\n", dev
->name
);
2158 /* Parm[0-1]: MSW/LSW address of RAM location. */
2162 printk("%s: Internal DMA underrun detected\n",
2167 printk("%s: Unrecognized interrupt detected\n",
2169 /* Parm[0-3]: adapter internal register R13-R15 */
2172 case INVALID_ERROR_IRQ
:
2173 printk("%s: Unrecognized error interrupt detected\n",
2175 /* Parm[0-3]: adapter internal register R13-R15 */
2179 printk("%s: Unrecognized XOP request detected\n",
2181 /* Parm[0-3]: adapter internal register R13-R15 */
2185 printk("%s: Unknown status", dev
->name
);
2189 if(sktr_chipset_init(dev
) == 1)
2191 /* Restart of firmware successful */
2192 tp
->AdapterOpenFlag
= 1;
2199 * Internal adapter pointer to RAM data are copied from adapter into
2202 static void sktr_read_ptr(struct net_device
*dev
)
2204 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
2205 unsigned short adapterram
;
2207 sktr_read_ram(dev
, (unsigned char *)&tp
->intptrs
.BurnedInAddrPtr
,
2208 ADAPTER_INT_PTRS
, 16);
2209 sktr_read_ram(dev
, (unsigned char *)&adapterram
,
2210 (unsigned short)SWAPB(tp
->intptrs
.AdapterRAMPtr
), 2);
2212 printk(KERN_INFO
"%s: Adapter RAM size: %d K\n",
2213 dev
->name
, SWAPB(adapterram
));
2219 * Reads a number of bytes from adapter to system memory.
2221 static void sktr_read_ram(struct net_device
*dev
, unsigned char *Data
,
2222 unsigned short Address
, int Length
)
2225 unsigned short old_sifadx
, old_sifadr
, InWord
;
2226 unsigned short ioaddr
= dev
->base_addr
;
2228 /* Save the current values */
2229 old_sifadx
= inw(ioaddr
+ SIFADX
);
2230 old_sifadr
= inw(ioaddr
+ SIFADR
);
2232 /* Page number of adapter memory */
2233 outw(0x0001, ioaddr
+ SIFADX
);
2234 /* Address offset in adapter RAM */
2235 outw(Address
, ioaddr
+ SIFADR
);
2237 /* Copy len byte from adapter memory to system data area. */
2241 InWord
= inw(ioaddr
+ SIFINC
);
2243 *(Data
+ i
) = HIBYTE(InWord
); /* Write first byte */
2244 if(++i
== Length
) /* All is done break */
2247 *(Data
+ i
) = LOBYTE(InWord
); /* Write second byte */
2248 if (++i
== Length
) /* All is done break */
2252 /* Restore original values */
2253 outw(old_sifadx
, ioaddr
+ SIFADX
);
2254 outw(old_sifadr
, ioaddr
+ SIFADR
);
2260 * Reads MAC address from adapter ROM.
2262 static void sktr_read_addr(struct net_device
*dev
, unsigned char *Address
)
2265 unsigned short ioaddr
= dev
->base_addr
;
2267 /* Address: 0000:0000 */
2268 outw(0, ioaddr
+ SIFADX
);
2269 outw(0, ioaddr
+ SIFADR
);
2271 /* Read six byte MAC address data */
2272 for(i
= 0; i
< 6; i
++)
2274 In
= inw(ioaddr
+ SIFINC
);
2275 *(Address
+ i
) = (unsigned char)(In
>> 8);
2282 * Cancel all queued packets in the transmission queue.
2284 static void sktr_cancel_tx_queue(struct net_local
* tp
)
2287 struct sk_buff
*skb
;
2290 * NOTE: There must not be an active TRANSMIT command pending, when
2291 * this function is called.
2293 if(tp
->TransmitCommandActive
)
2301 /* "Remove" TPL from busy list. */
2302 tp
->TplBusy
= tpl
->NextTPLPtr
;
2303 sktr_write_tpl_status(tpl
, 0); /* Clear VALID bit */
2304 tpl
->BusyFlag
= 0; /* "free" TPL */
2306 printk(KERN_INFO
"Cancel tx (%08lXh).\n", (unsigned long)tpl
);
2308 dev_kfree_skb(tpl
->Skb
);
2313 skb
= skb_dequeue(&tp
->SendSkbQueue
);
2324 * This function is called whenever a transmit interrupt is generated by the
2325 * adapter. For a command complete interrupt, it is checked if we have to
2326 * issue a new transmit command or not.
2328 static void sktr_tx_status_irq(struct net_device
*dev
)
2330 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
2331 unsigned char HighByte
, HighAc
, LowAc
;
2334 /* NOTE: At this point the SSB from TRANSMIT STATUS is no longer
2335 * available, because the CLEAR SSB command has already been issued.
2337 * Process all complete transmissions.
2343 if(!tpl
->BusyFlag
|| (tpl
->Status
2344 & (TX_VALID
| TX_FRAME_COMPLETE
))
2345 != TX_FRAME_COMPLETE
)
2350 /* "Remove" TPL from busy list. */
2351 tp
->TplBusy
= tpl
->NextTPLPtr
;
2354 sktr_dump(tpl
->MData
, SWAPB(tpl
->FrameSize
));
2356 /* Check the transmit status field only for directed frames*/
2357 if(DIRECTED_FRAME(tpl
) && (tpl
->Status
& TX_ERROR
) == 0)
2359 HighByte
= GET_TRANSMIT_STATUS_HIGH_BYTE(tpl
->Status
);
2360 HighAc
= GET_FRAME_STATUS_HIGH_AC(HighByte
);
2361 LowAc
= GET_FRAME_STATUS_LOW_AC(HighByte
);
2363 if((HighAc
!= LowAc
) || (HighAc
== AC_NOT_RECOGNIZED
))
2365 printk(KERN_INFO
"%s: (DA=%08lX not recognized)",
2367 *(unsigned long *)&tpl
->MData
[2+2]);
2372 printk("%s: Directed frame tx'd\n",
2378 if(!DIRECTED_FRAME(tpl
))
2381 printk("%s: Broadcast frame tx'd\n",
2386 tp
->MacStat
.tx_packets
++;
2387 dev_kfree_skb(tpl
->Skb
);
2388 tpl
->BusyFlag
= 0; /* "free" TPL */
2392 if(tp
->QueueSkb
< MAX_TX_QUEUE
)
2393 sktr_hardware_send_packet(dev
, tp
);
2399 * Called if a frame receive interrupt is generated by the adapter.
2400 * Check if the frame is valid and indicate it to system.
2402 static void sktr_rcv_status_irq(struct net_device
*dev
)
2404 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
2405 unsigned char *ReceiveDataPtr
;
2406 struct sk_buff
*skb
;
2407 unsigned int Length
, Length2
;
2411 /* NOTE: At this point the SSB from RECEIVE STATUS is no longer
2412 * available, because the CLEAR SSB command has already been issued.
2414 * Process all complete receives.
2420 if(rpl
->Status
& RX_VALID
)
2421 break; /* RPL still in use by adapter */
2423 /* Forward RPLHead pointer to next list. */
2424 SaveHead
= tp
->RplHead
;
2425 tp
->RplHead
= rpl
->NextRPLPtr
;
2427 /* Get the frame size (Byte swap for Intel).
2428 * Do this early (see workaround comment below)
2430 Length
= (unsigned short)SWAPB(rpl
->FrameSize
);
2432 /* Check if the Frame_Start, Frame_End and
2433 * Frame_Complete bits are set.
2435 if((rpl
->Status
& VALID_SINGLE_BUFFER_FRAME
)
2436 == VALID_SINGLE_BUFFER_FRAME
)
2438 ReceiveDataPtr
= rpl
->MData
;
2440 /* Workaround for delayed write of FrameSize on ISA
2441 * (FrameSize is false but valid-bit is reset)
2442 * Frame size is set to zero when the RPL is freed.
2443 * Length2 is there because there have also been
2444 * cases where the FrameSize was partially written
2446 Length2
= (unsigned short)SWAPB(rpl
->FrameSize
);
2448 if(Length
== 0 || Length
!= Length2
)
2450 tp
->RplHead
= SaveHead
;
2451 break; /* Return to sktr_interrupt */
2454 /* Drop frames sent by myself */
2455 if(sktr_chk_frame(dev
, rpl
->MData
))
2457 if(rpl
->Skb
!= NULL
)
2458 dev_kfree_skb(rpl
->Skb
);
2462 sktr_update_rcv_stats(tp
,ReceiveDataPtr
,Length
);
2465 printk("%s: Packet Length %04X (%d)\n",
2466 dev
->name
, Length
, Length
);
2468 /* Indicate the received frame to system.
2469 * The source routing padding is no more
2470 * necessary with 2.2.x kernel.
2471 * See: OpenOptions in sktr_init_opb()
2474 if(rpl
->SkbStat
== SKB_UNAVAILABLE
)
2476 /* Try again to allocate skb */
2477 skb
= dev_alloc_skb(tp
->MaxPacketSize
);
2480 /* Update Stats ?? */
2485 skb_put(skb
, tp
->MaxPacketSize
);
2486 rpl
->SkbStat
= SKB_DATA_COPY
;
2487 ReceiveDataPtr
= rpl
->MData
;
2491 if(rpl
->SkbStat
== SKB_DATA_COPY
2492 || rpl
->SkbStat
== SKB_DMA_DIRECT
)
2494 if(rpl
->SkbStat
== SKB_DATA_COPY
)
2496 memmove(skb
->data
, ReceiveDataPtr
, Length
);
2499 /* Deliver frame to system */
2501 skb_trim(skb
,Length
);
2503 skb
->protocol
= tr_type_trans(skb
,dev
);
2508 else /* Invalid frame */
2510 if(rpl
->Skb
!= NULL
)
2511 dev_kfree_skb(rpl
->Skb
);
2514 if(rpl
->Status
& RX_START_FRAME
)
2515 /* Frame start bit is set -> overflow. */
2516 tp
->MacStat
.rx_errors
++;
2519 /* Allocate new skb for rpl */
2520 rpl
->Skb
= dev_alloc_skb(tp
->MaxPacketSize
);
2522 /* skb == NULL ? then use local buffer */
2523 if(rpl
->Skb
== NULL
)
2525 rpl
->SkbStat
= SKB_UNAVAILABLE
;
2526 rpl
->FragList
[0].DataAddr
= htonl(virt_to_bus(tp
->LocalRxBuffers
[rpl
->RPLIndex
]));
2527 rpl
->MData
= tp
->LocalRxBuffers
[rpl
->RPLIndex
];
2529 else /* skb != NULL */
2531 rpl
->Skb
->dev
= dev
;
2532 skb_put(rpl
->Skb
, tp
->MaxPacketSize
);
2534 /* Data unreachable for DMA ? then use local buffer */
2535 if(tp
->DeviceType
== SK_ISA
&&
2536 virt_to_bus(rpl
->Skb
->data
) + tp
->MaxPacketSize
2539 rpl
->SkbStat
= SKB_DATA_COPY
;
2540 rpl
->FragList
[0].DataAddr
= htonl(virt_to_bus(tp
->LocalRxBuffers
[rpl
->RPLIndex
]));
2541 rpl
->MData
= tp
->LocalRxBuffers
[rpl
->RPLIndex
];
2545 /* DMA directly in skb->data */
2546 rpl
->SkbStat
= SKB_DMA_DIRECT
;
2547 rpl
->FragList
[0].DataAddr
= htonl(virt_to_bus(rpl
->Skb
->data
));
2548 rpl
->MData
= rpl
->Skb
->data
;
2552 rpl
->FragList
[0].DataCount
= SWAPB(tp
->MaxPacketSize
);
2555 /* Pass the last RPL back to the adapter */
2556 tp
->RplTail
->FrameSize
= 0;
2558 /* Reset the CSTAT field in the list. */
2559 sktr_write_rpl_status(tp
->RplTail
, RX_VALID
| RX_FRAME_IRQ
);
2561 /* Current RPL becomes last one in list. */
2562 tp
->RplTail
= tp
->RplTail
->NextRPLPtr
;
2564 /* Inform adapter about RPL valid. */
2565 sktr_exec_sifcmd(dev
, CMD_RX_VALID
);
2572 * This function should be used whenever the status of any RPL must be
2573 * modified by the driver, because the compiler may otherwise change the
2574 * order of instructions such that writing the RPL status may be executed
2575 * at an undesireable time. When this function is used, the status is
2576 * always written when the function is called.
2578 static void sktr_write_rpl_status(RPL
*rpl
, unsigned int Status
)
2580 rpl
->Status
= Status
;
2586 * The function updates the statistic counters in mac->MacStat.
2587 * It differtiates between directed and broadcast/multicast ( ==functional)
2590 static void sktr_update_rcv_stats(struct net_local
*tp
, unsigned char DataPtr
[],
2591 unsigned int Length
)
2593 tp
->MacStat
.rx_packets
++;
2595 /* Test functional bit */
2596 if(DataPtr
[2] & GROUP_BIT
)
2597 tp
->MacStat
.multicast
++;
2603 * Check if it is a frame of myself. Compare source address with my current
2604 * address in reverse direction, and mask out the TR_RII.
2606 static unsigned char sktr_chk_frame(struct net_device
*dev
, unsigned char *Addr
)
2610 for(i
= 5; i
> 0; i
--)
2612 if(Addr
[8 + i
] != dev
->dev_addr
[i
])
2616 /* Mask out RIF bit. */
2617 if((Addr
[8] & ~TR_RII
) != (unsigned char)(dev
->dev_addr
[0]))
2620 return (1); /* It is my frame. */
2624 * Dump Packet (data)
2626 static void sktr_dump(unsigned char *Data
, int length
)
2630 for (i
= 0, j
= 0; i
< length
/ 8; i
++, j
+= 8)
2632 printk(KERN_DEBUG
"%02x %02x %02x %02x %02x %02x %02x %02x\n",
2633 Data
[j
+0],Data
[j
+1],Data
[j
+2],Data
[j
+3],
2634 Data
[j
+4],Data
[j
+5],Data
[j
+6],Data
[j
+7]);
2642 static struct net_device
* dev_sktr
[SKTR_MAX_ADAPTERS
];
2643 static int io
[SKTR_MAX_ADAPTERS
] = { 0, 0 };
2644 static int irq
[SKTR_MAX_ADAPTERS
] = { 0, 0 };
2645 static int mem
[SKTR_MAX_ADAPTERS
] = { 0, 0 };
2647 MODULE_PARM(io
, "1-" __MODULE_STRING(SKTR_MAX_ADAPTERS
) "i");
2648 MODULE_PARM(irq
, "1-" __MODULE_STRING(SKTR_MAX_ADAPTERS
) "i");
2649 MODULE_PARM(mem
, "1-" __MODULE_STRING(SKTR_MAX_ADAPTERS
) "i");
2651 int init_module(void)
2655 for(i
= 0; i
< SKTR_MAX_ADAPTERS
; i
++)
2660 dev_sktr
[i
] = init_trdev(dev_sktr
[i
], 0);
2661 if(dev_sktr
[i
] == NULL
)
2664 dev_sktr
[i
]->base_addr
= io
[i
];
2665 dev_sktr
[i
]->irq
= irq
[i
];
2666 dev_sktr
[i
]->mem_start
= mem
[i
];
2667 dev_sktr
[i
]->init
= &sktr_probe
;
2669 if(register_trdev(dev_sktr
[i
]) != 0)
2671 kfree_s(dev_sktr
[i
], sizeof(struct net_device
));
2675 printk("sktr: register_trdev() returned non-zero.\n");
2686 void cleanup_module(void)
2690 for(i
= 0; i
< SKTR_MAX_ADAPTERS
; i
++)
2694 unregister_trdev(dev_sktr
[i
]);
2695 release_region(dev_sktr
[i
]->base_addr
, SKTR_IO_EXTENT
);
2696 if(dev_sktr
[i
]->irq
)
2697 free_irq(dev_sktr
[i
]->irq
, dev_sktr
[i
]);
2698 if(dev_sktr
[i
]->dma
> 0)
2699 free_dma(dev_sktr
[i
]->dma
);
2700 if(dev_sktr
[i
]->priv
)
2701 kfree_s(dev_sktr
[i
]->priv
, sizeof(struct net_local
));
2702 kfree_s(dev_sktr
[i
], sizeof(struct net_device
));