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
29 * Modification History:
30 * 29-Aug-97 CG Created
31 * 04-Apr-98 CG Fixed problems caused by tok_timer_check
32 * 10-Apr-98 CG Fixed lockups at cable disconnection
33 * 27-May-98 JS Formated to Linux Kernel Format
34 * 31-May-98 JS Hacked in PCI support
35 * 16-Jun-98 JS Modulized for multiple cards with one driver
38 * 1. Selectable 16 Mbps or 4Mbps
39 * 2. Multi/Broadcast packet handling
43 static const char *version
= "sktr.c: v1.01 08/29/97 by Christoph Goos\n";
46 #include <linux/module.h>
47 #include <linux/version.h>
50 #include <linux/kernel.h>
51 #include <linux/sched.h>
52 #include <linux/types.h>
53 #include <linux/fcntl.h>
54 #include <linux/interrupt.h>
55 #include <linux/ptrace.h>
56 #include <linux/ioport.h>
58 #include <linux/malloc.h>
59 #include <linux/string.h>
60 #include <linux/time.h>
61 #include <asm/system.h>
62 #include <asm/bitops.h>
66 #include <linux/errno.h>
67 #include <linux/init.h>
68 #include <linux/pci.h>
70 #include <linux/netdevice.h>
71 #include <linux/etherdevice.h>
72 #include <linux/skbuff.h>
73 #include <linux/trdevice.h>
75 #include "sktr.h" /* Our Stuff */
76 #include "sktr_firmware.h" /* SysKonnect adapter firmware */
78 /* A zero-terminated list of I/O addresses to be probed. */
79 static unsigned int sktr_portlist
[] __initdata
= {
80 0x0A20, 0x1A20, 0x0B20, 0x1B20, 0x0980, 0x1980, 0x0900, 0x1900,
84 /* A zero-terminated list of IRQs to be probed.
85 * Used again after initial probe for sktr_chipset_init, called from sktr_open.
87 static unsigned short sktr_irqlist
[] = {
88 3, 5, 9, 10, 11, 12, 15,
92 /* A zero-terminated list of DMAs to be probed. */
93 static int sktr_dmalist
[] __initdata
= {
99 static char *pci_cardname
= "SK NET TR 4/16 PCI\0";
100 static char *isa_cardname
= "SK NET TR 4/16 ISA\0";
101 static char *AdapterName
;
103 /* Use 0 for production, 1 for verification, 2 for debug, and
104 * 3 for very verbose debug.
109 static unsigned int sktr_debug
= SKTR_DEBUG
;
111 /* The number of low I/O ports used by the tokencard. */
112 #define SKTR_IO_EXTENT 32
114 /* Index to functions, as function prototypes.
115 * Alphabetical by function name.
119 static int sktr_bringup_diags(struct device
*dev
);
121 static void sktr_cancel_tx_queue(struct net_local
* tp
);
122 static int sktr_chipset_init(struct device
*dev
);
123 static void sktr_chk_irq(struct device
*dev
);
124 static unsigned char sktr_chk_frame(struct device
*dev
, unsigned char *Addr
);
125 static void sktr_chk_outstanding_cmds(struct device
*dev
);
126 static void sktr_chk_src_addr(unsigned char *frame
, unsigned char *hw_addr
);
127 static unsigned char sktr_chk_ssb(struct net_local
*tp
, unsigned short IrqType
);
128 static int sktr_close(struct device
*dev
);
129 static void sktr_cmd_status_irq(struct device
*dev
);
131 static void sktr_disable_interrupts(struct device
*dev
);
132 static void sktr_dump(unsigned char *Data
, int length
);
134 static void sktr_enable_interrupts(struct device
*dev
);
135 static void sktr_exec_cmd(struct device
*dev
, unsigned short Command
);
136 static void sktr_exec_sifcmd(struct device
*dev
, unsigned int WriteValue
);
138 static unsigned char *sktr_fix_srouting(unsigned char *buf
, short *FrameLen
);
140 static struct enet_statistics
*sktr_get_stats(struct device
*dev
);
142 static void sktr_hardware_send_packet(struct device
*dev
,
143 struct net_local
* tp
);
145 static int sktr_init_adapter(struct device
*dev
);
146 static int sktr_init_card(struct device
*dev
);
147 static void sktr_init_ipb(struct net_local
*tp
);
148 static void sktr_init_net_local(struct device
*dev
);
149 static void sktr_init_opb(struct net_local
*tp
);
150 static void sktr_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
151 static int sktr_isa_chk_card(struct device
*dev
, int ioaddr
);
152 static int sktr_isa_chk_ioaddr(int ioaddr
);
154 static int sktr_open(struct device
*dev
);
155 static void sktr_open_adapter(struct device
*dev
);
157 static int sktr_pci_chk_card(struct device
*dev
);
158 int sktr_probe(struct device
*dev
);
159 static int sktr_probe1(struct device
*dev
, int ioaddr
);
161 static void sktr_rcv_status_irq(struct device
*dev
);
162 static void sktr_read_addr(struct device
*dev
, unsigned char *Address
);
163 static void sktr_read_ptr(struct device
*dev
);
164 static void sktr_read_ram(struct device
*dev
, unsigned char *Data
,
165 unsigned short Address
, int Length
);
166 static int sktr_reset_adapter(struct device
*dev
);
167 static void sktr_reset_interrupt(struct device
*dev
);
168 static void sktr_ring_status_irq(struct device
*dev
);
170 static int sktr_send_packet(struct sk_buff
*skb
, struct device
*dev
);
171 static void sktr_set_multicast_list(struct device
*dev
);
173 static void sktr_timer_chk(unsigned long data
);
174 static void sktr_timer_end_wait(unsigned long data
);
175 static void sktr_tx_status_irq(struct device
*dev
);
177 static void sktr_update_rcv_stats(struct net_local
*tp
,
178 unsigned char DataPtr
[], unsigned int Length
);
180 static void sktr_wait(unsigned long time
);
181 static void sktr_write_rpl_status(RPL
*rpl
, unsigned int Status
);
182 static void sktr_write_tpl_status(TPL
*tpl
, unsigned int Status
);
185 * Check for a network adapter of this type, and return '0' if one exists.
186 * If dev->base_addr == 0, probe all likely locations.
187 * If dev->base_addr == 1, always return failure.
189 __initfunc(int sktr_probe(struct device
*dev
))
192 int base_addr
= dev
? dev
->base_addr
: 0;
194 if(base_addr
> 0x1ff) /* Check a single specified location. */
195 return (sktr_probe1(dev
, base_addr
));
196 else if(base_addr
!= 0) /* Don't probe at all. */
199 for(i
= 0; sktr_portlist
[i
]; i
++)
201 int ioaddr
= sktr_portlist
[i
];
202 if(check_region(ioaddr
, SKTR_IO_EXTENT
))
204 if(sktr_probe1(dev
, ioaddr
))
218 * Detect and setup the PCI SysKonnect TR cards in slot order.
220 __initfunc(static int sktr_pci_chk_card(struct device
*dev
))
222 static int pci_index
= 0;
223 unsigned char pci_bus
, pci_device_fn
;
226 return (-1); /* No PCI present. */
228 for(; pci_index
< 0xff; pci_index
++)
230 unsigned int pci_irq_line
;
231 struct pci_dev
*pdev
;
232 unsigned short pci_command
, new_command
, vendor
, device
;
233 unsigned int pci_ioaddr
;
235 if(pcibios_find_class(PCI_CLASS_NETWORK_TOKEN_RING
<< 8,
236 pci_index
, &pci_bus
, &pci_device_fn
)
237 != PCIBIOS_SUCCESSFUL
)
242 pcibios_read_config_word(pci_bus
, pci_device_fn
,
243 PCI_VENDOR_ID
, &vendor
);
244 pcibios_read_config_word(pci_bus
, pci_device_fn
,
245 PCI_DEVICE_ID
, &device
);
247 pdev
= pci_find_slot(pci_bus
, pci_device_fn
);
248 pci_irq_line
= pdev
->irq
;
249 pci_ioaddr
= pdev
->base_address
[0];
251 pcibios_read_config_word(pci_bus
, pci_device_fn
,
252 PCI_COMMAND
, &pci_command
);
254 /* Remove I/O space marker in bit 0. */
257 if(vendor
!= PCI_VENDOR_ID_SK
)
259 if(device
!= PCI_DEVICE_ID_SK_TR
)
261 if(check_region(pci_ioaddr
, SKTR_IO_EXTENT
))
263 request_region(pci_ioaddr
, SKTR_IO_EXTENT
, pci_cardname
);
264 if(request_irq(pdev
->irq
, sktr_interrupt
, SA_SHIRQ
,
266 return (-ENODEV
); /* continue; ?? */
268 AdapterName
= pci_cardname
;
270 new_command
= (pci_command
|PCI_COMMAND_MASTER
|PCI_COMMAND_IO
);
272 if(pci_command
!= new_command
)
274 printk("The PCI BIOS has not enabled this"
275 "device! Updating PCI command %4.4x->%4.4x.\n",
276 pci_command
, new_command
);
277 pcibios_write_config_word(pci_bus
, pci_device_fn
,
278 PCI_COMMAND
, new_command
);
281 /* At this point we have found a valid PCI TR card. */
282 dev
->base_addr
= pci_ioaddr
;
283 dev
->irq
= pci_irq_line
;
286 printk("%s: %s found at %#4x, using IRQ %d.\n",
287 dev
->name
, AdapterName
, pci_ioaddr
, dev
->irq
);
296 * Detect and setup the ISA SysKonnect TR cards.
298 __initfunc(static int sktr_isa_chk_card(struct device
*dev
, int ioaddr
))
303 err
= sktr_isa_chk_ioaddr(ioaddr
);
307 if(virt_to_bus((void*)((unsigned long)dev
->priv
+sizeof(struct net_local
)))
310 printk("%s: Memory not accessible for DMA\n", dev
->name
);
315 AdapterName
= isa_cardname
;
317 /* Grab the region so that no one else tries to probe our ioports. */
318 request_region(ioaddr
, SKTR_IO_EXTENT
, AdapterName
);
319 dev
->base_addr
= ioaddr
;
321 /* Autoselect IRQ and DMA if dev->irq == 0 */
324 for(i
= 0; sktr_irqlist
[i
] != 0; i
++)
326 dev
->irq
= sktr_irqlist
[i
];
327 err
= request_irq(dev
->irq
, &sktr_interrupt
, 0, AdapterName
, dev
);
332 if(sktr_irqlist
[i
] == 0)
334 printk("%s: AutoSelect no IRQ available\n", dev
->name
);
340 err
= request_irq(dev
->irq
, &sktr_interrupt
, 0, AdapterName
, dev
);
343 printk("%s: Selected IRQ not available\n", dev
->name
);
348 /* Always allocate the DMA channel after IRQ and clean up on failure */
351 for(i
= 0; sktr_dmalist
[i
] != 0; i
++)
353 dev
->dma
= sktr_dmalist
[i
];
354 err
= request_dma(dev
->dma
, AdapterName
);
361 printk("%s: AutoSelect no DMA available\n", dev
->name
);
362 free_irq(dev
->irq
, NULL
);
368 err
= request_dma(dev
->dma
, AdapterName
);
371 printk("%s: Selected DMA not available\n", dev
->name
);
372 free_irq(dev
->irq
, NULL
);
377 flags
=claim_dma_lock();
378 disable_dma(dev
->dma
);
379 set_dma_mode(dev
->dma
, DMA_MODE_CASCADE
);
380 enable_dma(dev
->dma
);
381 release_dma_lock(flags
);
383 printk("%s: %s found at %#4x, using IRQ %d and DMA %d.\n",
384 dev
->name
, AdapterName
, ioaddr
, dev
->irq
, dev
->dma
);
389 __initfunc(static int sktr_probe1(struct device
*dev
, int ioaddr
))
391 static unsigned version_printed
= 0;
392 struct net_local
*tp
;
395 if(sktr_debug
&& version_printed
++ == 0)
396 printk("%s", version
);
399 dev
= init_trdev(dev
, 0);
404 err
= sktr_pci_chk_card(dev
);
407 err
= sktr_isa_chk_card(dev
, ioaddr
);
412 /* Setup this devices private information structure */
413 tp
= (struct net_local
*)kmalloc(sizeof(struct net_local
), GFP_KERNEL
| GFP_DMA
);
416 memset(tp
, 0, sizeof(struct net_local
));
417 init_waitqueue_head(&tp
->wait_for_tok_int
);
420 dev
->init
= sktr_init_card
;
421 dev
->open
= sktr_open
;
422 dev
->stop
= sktr_close
;
423 dev
->hard_start_xmit
= sktr_send_packet
;
424 dev
->get_stats
= sktr_get_stats
;
425 dev
->set_multicast_list
= &sktr_set_multicast_list
;
431 __initfunc(static int sktr_init_card(struct device
*dev
))
434 printk("%s: sktr_init_card\n", dev
->name
);
440 * This function tests if an adapter is really installed at the
441 * given I/O address. Return negative if no adapter at IO addr.
443 __initfunc(static int sktr_isa_chk_ioaddr(int ioaddr
))
445 unsigned char old
, chk1
, chk2
;
447 old
= inb(ioaddr
+ SIFADR
); /* Get the old SIFADR value */
449 chk1
= 0; /* Begin with check value 0 */
451 /* Write new SIFADR value */
452 outb(chk1
, ioaddr
+ SIFADR
);
454 /* Read, invert and write */
455 chk2
= inb(ioaddr
+ SIFADD
);
457 outb(chk2
, ioaddr
+ SIFADR
);
459 /* Read, invert and compare */
460 chk2
= inb(ioaddr
+ SIFADD
);
464 return (-1); /* No adapter */
467 } while(chk1
!= 0); /* Repeat 128 times (all byte values) */
469 /* Restore the SIFADR value */
470 outb(old
, ioaddr
+ SIFADR
);
476 * Open/initialize the board. This is called sometime after
477 * booting when the 'ifconfig' program is run.
479 * This routine should set everything up anew at each open, even
480 * registers that "should" only need to be set once at boot, so that
481 * there is non-reboot way to recover if something goes wrong.
483 static int sktr_open(struct device
*dev
)
485 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
488 /* Reset the hardware here. Don't forget to set the station address. */
489 err
= sktr_chipset_init(dev
);
492 printk(KERN_INFO
"%s: Chipset initialization error\n",
498 sktr_read_addr(dev
, (unsigned char*)dev
->dev_addr
);
500 init_timer(&tp
->timer
);
501 tp
->timer
.expires
= jiffies
+ 30*HZ
;
502 tp
->timer
.function
= sktr_timer_end_wait
;
503 tp
->timer
.data
= (unsigned long)dev
;
504 tp
->timer
.next
= NULL
;
505 tp
->timer
.prev
= NULL
;
506 add_timer(&tp
->timer
);
509 sktr_enable_interrupts(dev
);
510 sktr_open_adapter(dev
);
516 /* Wait for interrupt from hardware. If interrupt does not come,
517 * there will be a timeout from the timer.
520 interruptible_sleep_on(&tp
->wait_for_tok_int
);
521 del_timer(&tp
->timer
);
523 /* If AdapterVirtOpenFlag is 1, the adapter is now open for use */
524 if(tp
->AdapterVirtOpenFlag
== 0)
526 sktr_disable_interrupts(dev
);
532 tp
->StartTime
= jiffies
;
534 /* Start function control timer */
535 tp
->timer
.expires
= jiffies
+ 2*HZ
;
536 tp
->timer
.function
= sktr_timer_chk
;
537 tp
->timer
.data
= (unsigned long)dev
;
538 add_timer(&tp
->timer
);
548 * Timeout function while waiting for event
550 static void sktr_timer_end_wait(unsigned long data
)
552 struct device
*dev
= (struct device
*)data
;
553 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
558 wake_up_interruptible(&tp
->wait_for_tok_int
);
565 * Initialize the chipset
567 static int sktr_chipset_init(struct device
*dev
)
569 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
570 unsigned char PosReg
, Tmp
;
575 sktr_init_net_local(dev
);
577 /* Set pos register: selects irq and dma channel.
578 * Only for ISA bus adapters.
583 for(i
= 0; sktr_irqlist
[i
] != 0; i
++)
585 if(sktr_irqlist
[i
] == dev
->irq
)
589 /* Choose default cycle time, 500 nsec */
590 PosReg
|= CYCLE_TIME
<< 2;
595 if(tp
->DataRate
== SPEED_4
)
596 PosReg
|= LINE_SPEED_BIT
;
598 PosReg
&= ~LINE_SPEED_BIT
;
600 outb(PosReg
, dev
->base_addr
+ POSREG
);
601 Tmp
= inb(dev
->base_addr
+ POSREG
);
602 if((Tmp
& ~CYCLE_TIME
) != (PosReg
& ~CYCLE_TIME
))
603 printk(KERN_INFO
"%s: POSREG error\n", dev
->name
);
606 err
= sktr_reset_adapter(dev
);
610 err
= sktr_bringup_diags(dev
);
614 err
= sktr_init_adapter(dev
);
622 * Initializes the net_local structure.
624 static void sktr_init_net_local(struct device
*dev
)
626 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
640 tp
->AdapterOpenFlag
= 0;
641 tp
->AdapterVirtOpenFlag
= 0;
643 tp
->OpenCommandIssued
= 0;
644 tp
->ReOpenInProgress
= 0;
645 tp
->HaltInProgress
= 0;
646 tp
->TransmitHaltScheduled
= 0;
647 tp
->LobeWireFaultLogged
= 0;
648 tp
->LastOpenStatus
= 0;
649 tp
->MaxPacketSize
= DEFAULT_PACKET_SIZE
;
651 skb_queue_head_init(&tp
->SendSkbQueue
);
652 tp
->QueueSkb
= MAX_TX_QUEUE
;
654 /* Create circular chain of transmit lists */
655 for (i
= 0; i
< TPL_NUM
; i
++)
657 tp
->Tpl
[i
].NextTPLAddr
= htonl((unsigned long) virt_to_bus(&tp
->Tpl
[(i
+1) % TPL_NUM
]));
658 tp
->Tpl
[i
].Status
= 0;
659 tp
->Tpl
[i
].FrameSize
= 0;
660 tp
->Tpl
[i
].FragList
[0].DataCount
= 0;
661 tp
->Tpl
[i
].FragList
[0].DataAddr
= 0;
662 tp
->Tpl
[i
].NextTPLPtr
= &tp
->Tpl
[(i
+1) % TPL_NUM
];
663 tp
->Tpl
[i
].MData
= NULL
;
664 tp
->Tpl
[i
].TPLIndex
= i
;
665 tp
->Tpl
[i
].BusyFlag
= 0;
668 tp
->TplFree
= tp
->TplBusy
= &tp
->Tpl
[0];
670 /* Create circular chain of receive lists */
671 for (i
= 0; i
< RPL_NUM
; i
++)
673 tp
->Rpl
[i
].NextRPLAddr
= htonl((unsigned long) virt_to_bus(&tp
->Rpl
[(i
+1) % RPL_NUM
]));
674 tp
->Rpl
[i
].Status
= (RX_VALID
| RX_START_FRAME
| RX_END_FRAME
| RX_FRAME_IRQ
);
675 tp
->Rpl
[i
].FrameSize
= 0;
676 tp
->Rpl
[i
].FragList
[0].DataCount
= SWAPB(tp
->MaxPacketSize
);
678 /* Alloc skb and point adapter to data area */
679 tp
->Rpl
[i
].Skb
= dev_alloc_skb(tp
->MaxPacketSize
);
681 /* skb == NULL ? then use local buffer */
682 if(tp
->Rpl
[i
].Skb
== NULL
)
684 tp
->Rpl
[i
].SkbStat
= SKB_UNAVAILABLE
;
685 tp
->Rpl
[i
].FragList
[0].DataAddr
= htonl(virt_to_bus(tp
->LocalRxBuffers
[i
]));
686 tp
->Rpl
[i
].MData
= tp
->LocalRxBuffers
[i
];
688 else /* SKB != NULL */
690 tp
->Rpl
[i
].Skb
->dev
= dev
;
691 skb_put(tp
->Rpl
[i
].Skb
, tp
->MaxPacketSize
);
693 /* data unreachable for DMA ? then use local buffer */
694 if(virt_to_bus(tp
->Rpl
[i
].Skb
->data
) + tp
->MaxPacketSize
> ISA_MAX_ADDRESS
)
696 tp
->Rpl
[i
].SkbStat
= SKB_DATA_COPY
;
697 tp
->Rpl
[i
].FragList
[0].DataAddr
= htonl(virt_to_bus(tp
->LocalRxBuffers
[i
]));
698 tp
->Rpl
[i
].MData
= tp
->LocalRxBuffers
[i
];
700 else /* DMA directly in skb->data */
702 tp
->Rpl
[i
].SkbStat
= SKB_DMA_DIRECT
;
703 tp
->Rpl
[i
].FragList
[0].DataAddr
= htonl(virt_to_bus(tp
->Rpl
[i
].Skb
->data
));
704 tp
->Rpl
[i
].MData
= tp
->Rpl
[i
].Skb
->data
;
708 tp
->Rpl
[i
].NextRPLPtr
= &tp
->Rpl
[(i
+1) % RPL_NUM
];
709 tp
->Rpl
[i
].RPLIndex
= i
;
712 tp
->RplHead
= &tp
->Rpl
[0];
713 tp
->RplTail
= &tp
->Rpl
[RPL_NUM
-1];
714 tp
->RplTail
->Status
= (RX_START_FRAME
| RX_END_FRAME
| RX_FRAME_IRQ
);
720 * Initializes the initialisation parameter block.
722 static void sktr_init_ipb(struct net_local
*tp
)
724 tp
->ipb
.Init_Options
= BURST_MODE
;
725 tp
->ipb
.CMD_Status_IV
= 0;
728 tp
->ipb
.Ring_Status_IV
= 0;
729 tp
->ipb
.SCB_Clear_IV
= 0;
730 tp
->ipb
.Adapter_CHK_IV
= 0;
731 tp
->ipb
.RX_Burst_Size
= BURST_SIZE
;
732 tp
->ipb
.TX_Burst_Size
= BURST_SIZE
;
733 tp
->ipb
.DMA_Abort_Thrhld
= DMA_RETRIES
;
734 tp
->ipb
.SCB_Addr
= 0;
735 tp
->ipb
.SSB_Addr
= 0;
741 * Initializes the open parameter block.
743 static void sktr_init_opb(struct net_local
*tp
)
746 unsigned short RplSize
= RPL_SIZE
;
747 unsigned short TplSize
= TPL_SIZE
;
748 unsigned short BufferSize
= BUFFER_SIZE
;
750 tp
->ocpl
.OPENOptions
= 0;
751 tp
->ocpl
.OPENOptions
|= ENABLE_FULL_DUPLEX_SELECTION
;
752 tp
->ocpl
.OPENOptions
|= PAD_ROUTING_FIELD
;
753 tp
->ocpl
.FullDuplex
= 0;
754 tp
->ocpl
.FullDuplex
|= OPEN_FULL_DUPLEX_OFF
;
756 /* Fixme: If mac address setable:
757 * for (i=0; i<LENGTH_OF_ADDRESS; i++)
758 * mac->Vam->ocpl.NodeAddr[i] = mac->CurrentAddress[i];
761 tp
->ocpl
.GroupAddr
= 0;
762 tp
->ocpl
.FunctAddr
= 0;
763 tp
->ocpl
.RxListSize
= SWAPB(RplSize
);
764 tp
->ocpl
.TxListSize
= SWAPB(TplSize
);
765 tp
->ocpl
.BufSize
= SWAPB(BufferSize
);
766 tp
->ocpl
.Reserved
= 0;
767 tp
->ocpl
.TXBufMin
= TX_BUF_MIN
;
768 tp
->ocpl
.TXBufMax
= TX_BUF_MAX
;
770 Addr
= htonl(virt_to_bus(tp
->ProductID
));
772 tp
->ocpl
.ProdIDAddr
[0] = LOWORD(Addr
);
773 tp
->ocpl
.ProdIDAddr
[1] = HIWORD(Addr
);
779 * Send OPEN command to adapter
781 static void sktr_open_adapter(struct device
*dev
)
783 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
785 if(tp
->OpenCommandIssued
)
788 tp
->OpenCommandIssued
= 1;
789 sktr_exec_cmd(dev
, OC_OPEN
);
795 * Clear the adapter's interrupt flag. Clear system interrupt enable
796 * (SINTEN): disable adapter to system interrupts.
798 static void sktr_disable_interrupts(struct device
*dev
)
800 outb(0, dev
->base_addr
+ SIFACL
);
806 * Set the adapter's interrupt flag. Set system interrupt enable
807 * (SINTEN): enable adapter to system interrupts.
809 static void sktr_enable_interrupts(struct device
*dev
)
811 outb(ACL_SINTEN
, dev
->base_addr
+ SIFACL
);
817 * Put command in command queue, try to execute it.
819 static void sktr_exec_cmd(struct device
*dev
, unsigned short Command
)
821 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
823 tp
->CMDqueue
|= Command
;
824 sktr_chk_outstanding_cmds(dev
);
830 * Linux always gives 18 byte of source routing information in the frame header.
831 * But the length field can indicate shorter length. Then cut header
834 static unsigned char *sktr_fix_srouting(unsigned char *buf
, short *FrameLen
)
836 struct trh_hdr
*trh
= (struct trh_hdr
*)buf
;
841 trh
->rcf
&= ~SWAPB((unsigned short) TR_RCF_LONGEST_FRAME_MASK
);
842 trh
->rcf
|= SWAPB((unsigned short) TR_RCF_FRAME4K
);
843 len
= (SWAPB(trh
->rcf
) & TR_RCF_LEN_MASK
) >> 8;
846 memcpy(&buf
[18-len
],buf
,sizeof(struct trh_hdr
)-18+len
);
847 *FrameLen
-= (18 - len
);
849 return (&buf
[18-len
]);
856 * Gets skb from system, queues it and checks if it can be sent
858 static int sktr_send_packet(struct sk_buff
*skb
, struct device
*dev
)
860 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
865 * If we get here, some higher level has decided we are broken.
866 * There should really be a "kick me" function call instead.
868 * Resetting the token ring adapter takes a long time so just
869 * fake transmission time and go on trying. Our own timeout
870 * routine is in sktr_timer_chk()
873 dev
->trans_start
= jiffies
;
878 * If some higher layer thinks we've missed an tx-done interrupt we
885 * Block a timer-based transmit from overlapping. This could better be
886 * done with atomic_swap(1, dev->tbusy), but set_bit() works as well.
888 if(test_and_set_bit(0, (void*)&dev
->tbusy
) != 0)
890 printk("%s: Transmitter access conflict.\n", dev
->name
);
894 if(tp
->QueueSkb
== 0)
895 return (1); /* Return with tbusy set: queue full */
898 skb_queue_tail(&tp
->SendSkbQueue
, skb
);
899 sktr_hardware_send_packet(dev
, tp
);
907 * Move frames from internal skb queue into adapter tx queue
909 static void sktr_hardware_send_packet(struct device
*dev
, struct net_local
* tp
)
913 unsigned char *buf
, *newbuf
;
919 /* Try to get a free TPL from the chain.
921 * NOTE: We *must* always leave one unused TPL in the chain,
922 * because otherwise the adapter might send frames twice.
924 if(tp
->TplFree
->NextTPLPtr
->BusyFlag
) /* No free TPL */
926 printk(KERN_INFO
"%s: No free TPL\n", dev
->name
);
930 /* Send first buffer from queue */
931 skb
= skb_dequeue(&tp
->SendSkbQueue
);
936 /* Is buffer reachable for Busmaster-DMA? */
937 if(virt_to_bus((void*)(((long) skb
->data
) + skb
->len
))
940 /* Copy frame to local buffer */
941 i
= tp
->TplFree
->TPLIndex
;
943 buf
= tp
->LocalTxBuffers
[i
];
944 memcpy(buf
, skb
->data
, length
);
945 newbuf
= sktr_fix_srouting(buf
, &length
);
949 /* Send direct from skb->data */
951 newbuf
= sktr_fix_srouting(skb
->data
, &length
);
954 /* Source address in packet? */
955 sktr_chk_src_addr(newbuf
, dev
->dev_addr
);
957 tp
->LastSendTime
= jiffies
;
958 tpl
= tp
->TplFree
; /* Get the "free" TPL */
959 tpl
->BusyFlag
= 1; /* Mark TPL as busy */
960 tp
->TplFree
= tpl
->NextTPLPtr
;
962 /* Save the skb for delayed return of skb to system */
964 tpl
->FragList
[0].DataCount
= (unsigned short) SWAPB(length
);
965 tpl
->FragList
[0].DataAddr
= htonl(virt_to_bus(newbuf
));
967 /* Write the data length in the transmit list. */
968 tpl
->FrameSize
= (unsigned short) SWAPB(length
);
971 /* Transmit the frame and set the status values. */
972 sktr_write_tpl_status(tpl
, TX_VALID
| TX_START_FRAME
973 | TX_END_FRAME
| TX_PASS_SRC_ADDR
976 /* Let adapter send the frame. */
977 sktr_exec_sifcmd(dev
, CMD_TX_VALID
);
984 * Write the given value to the 'Status' field of the specified TPL.
985 * NOTE: This function should be used whenever the status of any TPL must be
986 * modified by the driver, because the compiler may otherwise change the
987 * order of instructions such that writing the TPL status may be executed at
988 * an undesireable time. When this function is used, the status is always
989 * written when the function is called.
991 static void sktr_write_tpl_status(TPL
*tpl
, unsigned int Status
)
993 tpl
->Status
= Status
;
996 static void sktr_chk_src_addr(unsigned char *frame
, unsigned char *hw_addr
)
1000 if((((unsigned long)frame
[8]) & ~0x80) != 0) /* Compare 4 bytes */
1002 if((unsigned short)frame
[12] != 0) /* Compare 2 bytes */
1005 SRBit
= frame
[8] & 0x80;
1006 memcpy(&frame
[8], hw_addr
, 6);
1013 * The timer routine: Check if adapter still open and working, reopen if not.
1015 static void sktr_timer_chk(unsigned long data
)
1017 struct device
*dev
= (struct device
*)data
;
1018 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1020 if(tp
->HaltInProgress
)
1023 sktr_chk_outstanding_cmds(dev
);
1024 if(time_before(tp
->LastSendTime
+ SEND_TIMEOUT
, jiffies
)
1025 && (tp
->QueueSkb
< MAX_TX_QUEUE
|| tp
->TplFree
!= tp
->TplBusy
))
1027 /* Anything to send, but stalled to long */
1028 tp
->LastSendTime
= jiffies
;
1029 sktr_exec_cmd(dev
, OC_CLOSE
); /* Does reopen automatically */
1032 tp
->timer
.expires
= jiffies
+ 2*HZ
;
1033 add_timer(&tp
->timer
);
1035 if(tp
->AdapterOpenFlag
|| tp
->ReOpenInProgress
)
1037 tp
->ReOpenInProgress
= 1;
1038 sktr_open_adapter(dev
);
1044 * The typical workload of the driver: Handle the network interface interrupts.
1046 static void sktr_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1048 struct device
*dev
= dev_id
;
1049 struct net_local
*tp
;
1051 unsigned short irq_type
;
1055 printk("%s: irq %d for unknown device.\n", dev
->name
, irq
);
1061 ioaddr
= dev
->base_addr
;
1062 tp
= (struct net_local
*)dev
->priv
;
1064 irq_type
= inw(ioaddr
+ SIFSTS
);
1066 while(irq_type
& STS_SYSTEM_IRQ
)
1068 irq_type
&= STS_IRQ_MASK
;
1070 if(!sktr_chk_ssb(tp
, irq_type
))
1072 printk(KERN_INFO
"%s: DATA LATE occurred\n", dev
->name
);
1078 case STS_IRQ_RECEIVE_STATUS
:
1079 sktr_reset_interrupt(dev
);
1080 sktr_rcv_status_irq(dev
);
1083 case STS_IRQ_TRANSMIT_STATUS
:
1084 /* Check if TRANSMIT.HALT command is complete */
1085 if(tp
->ssb
.Parm
[0] & COMMAND_COMPLETE
)
1087 tp
->TransmitCommandActive
= 0;
1088 tp
->TransmitHaltScheduled
= 0;
1090 /* Issue a new transmit command. */
1091 sktr_exec_cmd(dev
, OC_TRANSMIT
);
1094 sktr_reset_interrupt(dev
);
1095 sktr_tx_status_irq(dev
);
1098 case STS_IRQ_COMMAND_STATUS
:
1099 /* The SSB contains status of last command
1100 * other than receive/transmit.
1102 sktr_cmd_status_irq(dev
);
1105 case STS_IRQ_SCB_CLEAR
:
1106 /* The SCB is free for another command. */
1108 sktr_chk_outstanding_cmds(dev
);
1111 case STS_IRQ_RING_STATUS
:
1112 sktr_ring_status_irq(dev
);
1115 case STS_IRQ_ADAPTER_CHECK
:
1120 printk(KERN_INFO
"Unknown Token Ring IRQ\n");
1124 /* Reset system interrupt if not already done. */
1125 if(irq_type
!= STS_IRQ_TRANSMIT_STATUS
1126 && irq_type
!= STS_IRQ_RECEIVE_STATUS
)
1128 sktr_reset_interrupt(dev
);
1131 irq_type
= inw(ioaddr
+ SIFSTS
);
1140 * Reset the INTERRUPT SYSTEM bit and issue SSB CLEAR command.
1142 static void sktr_reset_interrupt(struct device
*dev
)
1144 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1145 SSB
*ssb
= &tp
->ssb
;
1148 * [Workaround for "Data Late"]
1149 * Set all fields of the SSB to well-defined values so we can
1150 * check if the adapter has written the SSB.
1153 ssb
->STS
= (unsigned short) -1;
1154 ssb
->Parm
[0] = (unsigned short) -1;
1155 ssb
->Parm
[1] = (unsigned short) -1;
1156 ssb
->Parm
[2] = (unsigned short) -1;
1158 /* Free SSB by issuing SSB_CLEAR command after reading IRQ code
1159 * and clear STS_SYSTEM_IRQ bit: enable adapter for further interrupts.
1161 sktr_exec_sifcmd(dev
, CMD_SSB_CLEAR
| CMD_CLEAR_SYSTEM_IRQ
);
1167 * Check if the SSB has actually been written by the adapter.
1169 static unsigned char sktr_chk_ssb(struct net_local
*tp
, unsigned short IrqType
)
1171 SSB
*ssb
= &tp
->ssb
; /* The address of the SSB. */
1173 /* C 0 1 2 INTERRUPT CODE
1174 * - - - - --------------
1175 * 1 1 1 1 TRANSMIT STATUS
1176 * 1 1 1 1 RECEIVE STATUS
1177 * 1 ? ? 0 COMMAND STATUS
1179 * 1 1 0 0 RING STATUS
1180 * 0 0 0 0 ADAPTER CHECK
1182 * 0 = SSB field not affected by interrupt
1183 * 1 = SSB field is affected by interrupt
1185 * C = SSB ADDRESS +0: COMMAND
1186 * 0 = SSB ADDRESS +2: STATUS 0
1187 * 1 = SSB ADDRESS +4: STATUS 1
1188 * 2 = SSB ADDRESS +6: STATUS 2
1191 /* Check if this interrupt does use the SSB. */
1193 if(IrqType
!= STS_IRQ_TRANSMIT_STATUS
1194 && IrqType
!= STS_IRQ_RECEIVE_STATUS
1195 && IrqType
!= STS_IRQ_COMMAND_STATUS
1196 && IrqType
!= STS_IRQ_RING_STATUS
)
1198 return (1); /* SSB not involved. */
1201 /* Note: All fields of the SSB have been set to all ones (-1) after it
1202 * has last been used by the software (see DriverIsr()).
1204 * Check if the affected SSB fields are still unchanged.
1207 if(ssb
->STS
== (unsigned short) -1)
1208 return (0); /* Command field not yet available. */
1209 if(IrqType
== STS_IRQ_COMMAND_STATUS
)
1210 return (1); /* Status fields not always affected. */
1211 if(ssb
->Parm
[0] == (unsigned short) -1)
1212 return (0); /* Status 1 field not yet available. */
1213 if(IrqType
== STS_IRQ_RING_STATUS
)
1214 return (1); /* Status 2 & 3 fields not affected. */
1216 /* Note: At this point, the interrupt is either TRANSMIT or RECEIVE. */
1217 if(ssb
->Parm
[1] == (unsigned short) -1)
1218 return (0); /* Status 2 field not yet available. */
1219 if(ssb
->Parm
[2] == (unsigned short) -1)
1220 return (0); /* Status 3 field not yet available. */
1222 return (1); /* All SSB fields have been written by the adapter. */
1226 * Evaluates the command results status in the SSB status field.
1228 static void sktr_cmd_status_irq(struct device
*dev
)
1230 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1231 unsigned short ssb_cmd
, ssb_parm_0
;
1232 unsigned short ssb_parm_1
;
1233 char *open_err
= "Open error -";
1234 char *code_err
= "Open code -";
1236 /* Copy the ssb values to local variables */
1237 ssb_cmd
= tp
->ssb
.STS
;
1238 ssb_parm_0
= tp
->ssb
.Parm
[0];
1239 ssb_parm_1
= tp
->ssb
.Parm
[1];
1244 if(!tp
->ReOpenInProgress
)
1245 wake_up_interruptible(&tp
->wait_for_tok_int
);
1247 tp
->OpenCommandIssued
= 0;
1250 if((ssb_parm_0
& 0x00FF) == GOOD_COMPLETION
)
1252 /* Success, the adapter is open. */
1253 tp
->LobeWireFaultLogged
= 0;
1254 tp
->AdapterOpenFlag
= 1;
1255 tp
->AdapterVirtOpenFlag
= 1;
1256 tp
->TransmitCommandActive
= 0;
1257 sktr_exec_cmd(dev
, OC_TRANSMIT
);
1258 sktr_exec_cmd(dev
, OC_RECEIVE
);
1260 if(tp
->ReOpenInProgress
)
1261 tp
->ReOpenInProgress
= 0;
1265 else /* The adapter did not open. */
1267 if(ssb_parm_0
& NODE_ADDR_ERROR
)
1268 printk(KERN_INFO
"%s: Node address error\n",
1270 if(ssb_parm_0
& LIST_SIZE_ERROR
)
1271 printk(KERN_INFO
"%s: List size error\n",
1273 if(ssb_parm_0
& BUF_SIZE_ERROR
)
1274 printk(KERN_INFO
"%s: Buffer size error\n",
1276 if(ssb_parm_0
& TX_BUF_COUNT_ERROR
)
1277 printk(KERN_INFO
"%s: Tx buffer count error\n",
1279 if(ssb_parm_0
& INVALID_OPEN_OPTION
)
1280 printk(KERN_INFO
"%s: Invalid open option\n",
1282 if(ssb_parm_0
& OPEN_ERROR
)
1284 /* Show the open phase. */
1285 switch(ssb_parm_0
& OPEN_PHASES_MASK
)
1287 case LOBE_MEDIA_TEST
:
1288 if(!tp
->LobeWireFaultLogged
)
1290 tp
->LobeWireFaultLogged
= 1;
1291 printk(KERN_INFO
"%s: %s Lobe wire fault (check cable !).\n", dev
->name
, open_err
);
1293 tp
->ReOpenInProgress
= 1;
1294 tp
->AdapterOpenFlag
= 0;
1295 tp
->AdapterVirtOpenFlag
= 1;
1296 sktr_open_adapter(dev
);
1299 case PHYSICAL_INSERTION
:
1300 printk(KERN_INFO
"%s: %s Physical insertion.\n", dev
->name
, open_err
);
1303 case ADDRESS_VERIFICATION
:
1304 printk(KERN_INFO
"%s: %s Address verification.\n", dev
->name
, open_err
);
1307 case PARTICIPATION_IN_RING_POLL
:
1308 printk(KERN_INFO
"%s: %s Participation in ring poll.\n", dev
->name
, open_err
);
1311 case REQUEST_INITIALISATION
:
1312 printk(KERN_INFO
"%s: %s Request initialisation.\n", dev
->name
, open_err
);
1315 case FULLDUPLEX_CHECK
:
1316 printk(KERN_INFO
"%s: %s Full duplex check.\n", dev
->name
, open_err
);
1320 printk(KERN_INFO
"%s: %s Unknown open phase\n", dev
->name
, open_err
);
1324 /* Show the open errors. */
1325 switch(ssb_parm_0
& OPEN_ERROR_CODES_MASK
)
1327 case OPEN_FUNCTION_FAILURE
:
1328 printk(KERN_INFO
"%s: %s OPEN_FUNCTION_FAILURE", dev
->name
, code_err
);
1329 tp
->LastOpenStatus
=
1330 OPEN_FUNCTION_FAILURE
;
1333 case OPEN_SIGNAL_LOSS
:
1334 printk(KERN_INFO
"%s: %s OPEN_SIGNAL_LOSS\n", dev
->name
, code_err
);
1335 tp
->LastOpenStatus
=
1340 printk(KERN_INFO
"%s: %s OPEN_TIMEOUT\n", dev
->name
, code_err
);
1341 tp
->LastOpenStatus
=
1345 case OPEN_RING_FAILURE
:
1346 printk(KERN_INFO
"%s: %s OPEN_RING_FAILURE\n", dev
->name
, code_err
);
1347 tp
->LastOpenStatus
=
1351 case OPEN_RING_BEACONING
:
1352 printk(KERN_INFO
"%s: %s OPEN_RING_BEACONING\n", dev
->name
, code_err
);
1353 tp
->LastOpenStatus
=
1354 OPEN_RING_BEACONING
;
1357 case OPEN_DUPLICATE_NODEADDR
:
1358 printk(KERN_INFO
"%s: %s OPEN_DUPLICATE_NODEADDR\n", dev
->name
, code_err
);
1359 tp
->LastOpenStatus
=
1360 OPEN_DUPLICATE_NODEADDR
;
1363 case OPEN_REQUEST_INIT
:
1364 printk(KERN_INFO
"%s: %s OPEN_REQUEST_INIT\n", dev
->name
, code_err
);
1365 tp
->LastOpenStatus
=
1369 case OPEN_REMOVE_RECEIVED
:
1370 printk(KERN_INFO
"%s: %s OPEN_REMOVE_RECEIVED", dev
->name
, code_err
);
1371 tp
->LastOpenStatus
=
1372 OPEN_REMOVE_RECEIVED
;
1375 case OPEN_FULLDUPLEX_SET
:
1376 printk(KERN_INFO
"%s: %s OPEN_FULLDUPLEX_SET\n", dev
->name
, code_err
);
1377 tp
->LastOpenStatus
=
1378 OPEN_FULLDUPLEX_SET
;
1382 printk(KERN_INFO
"%s: %s Unknown open err code", dev
->name
, code_err
);
1383 tp
->LastOpenStatus
=
1384 OPEN_FUNCTION_FAILURE
;
1389 tp
->AdapterOpenFlag
= 0;
1390 tp
->AdapterVirtOpenFlag
= 0;
1397 if(ssb_cmd
!= READ_ERROR_LOG
)
1400 /* Add values from the error log table to the MAC
1401 * statistics counters and update the errorlogtable
1404 tp
->MacStat
.line_errors
+= tp
->errorlogtable
.Line_Error
;
1405 tp
->MacStat
.burst_errors
+= tp
->errorlogtable
.Burst_Error
;
1406 tp
->MacStat
.A_C_errors
+= tp
->errorlogtable
.ARI_FCI_Error
;
1407 tp
->MacStat
.lost_frames
+= tp
->errorlogtable
.Lost_Frame_Error
;
1408 tp
->MacStat
.recv_congest_count
+= tp
->errorlogtable
.Rx_Congest_Error
;
1409 tp
->MacStat
.rx_errors
+= tp
->errorlogtable
.Rx_Congest_Error
;
1410 tp
->MacStat
.frame_copied_errors
+= tp
->errorlogtable
.Frame_Copied_Error
;
1411 tp
->MacStat
.token_errors
+= tp
->errorlogtable
.Token_Error
;
1412 tp
->MacStat
.dummy1
+= tp
->errorlogtable
.DMA_Bus_Error
;
1413 tp
->MacStat
.dummy1
+= tp
->errorlogtable
.DMA_Parity_Error
;
1414 tp
->MacStat
.abort_delimiters
+= tp
->errorlogtable
.AbortDelimeters
;
1415 tp
->MacStat
.frequency_errors
+= tp
->errorlogtable
.Frequency_Error
;
1416 tp
->MacStat
.internal_errors
+= tp
->errorlogtable
.Internal_Error
;
1423 * The inverse routine to sktr_open().
1425 static int sktr_close(struct device
*dev
)
1427 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1432 del_timer(&tp
->timer
);
1434 /* Flush the Tx and disable Rx here. */
1436 tp
->HaltInProgress
= 1;
1437 sktr_exec_cmd(dev
, OC_CLOSE
);
1438 tp
->timer
.expires
= jiffies
+ 1*HZ
;
1439 tp
->timer
.function
= sktr_timer_end_wait
;
1440 tp
->timer
.data
= (unsigned long)dev
;
1441 add_timer(&tp
->timer
);
1443 sktr_enable_interrupts(dev
);
1446 interruptible_sleep_on(&tp
->wait_for_tok_int
);
1447 tp
->TransmitCommandActive
= 0;
1449 del_timer(&tp
->timer
);
1450 sktr_disable_interrupts(dev
);
1454 unsigned long flags
=claim_dma_lock();
1455 disable_dma(dev
->dma
);
1456 release_dma_lock(flags
);
1459 outw(0xFF00, dev
->base_addr
+ SIFCMD
);
1461 outb(0xff, dev
->base_addr
+ POSREG
);
1467 sktr_cancel_tx_queue(tp
);
1473 * Get the current statistics. This may be called with the card open
1476 static struct enet_statistics
*sktr_get_stats(struct device
*dev
)
1478 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1480 return ((struct enet_statistics
*)&tp
->MacStat
);
1484 * Set or clear the multicast filter for this adapter.
1486 static void sktr_set_multicast_list(struct device
*dev
)
1488 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1489 unsigned int OpenOptions
;
1491 OpenOptions
= tp
->ocpl
.OPENOptions
&
1492 ~(PASS_ADAPTER_MAC_FRAMES
1493 | PASS_ATTENTION_FRAMES
1494 | PASS_BEACON_MAC_FRAMES
1495 | COPY_ALL_MAC_FRAMES
1496 | COPY_ALL_NON_MAC_FRAMES
);
1498 if(dev
->flags
& IFF_PROMISC
)
1499 /* Enable promiscuous mode */
1500 OpenOptions
|= COPY_ALL_NON_MAC_FRAMES
| COPY_ALL_MAC_FRAMES
;
1503 if(dev
->flags
& IFF_ALLMULTI
)
1504 /* || dev->mc_count > HW_MAX_ADDRS) */
1506 /* Disable promiscuous mode, use normal mode. */
1512 /* Walk the address list, and load the filter */
1517 tp
->ocpl
.OPENOptions
= OpenOptions
;
1518 sktr_exec_cmd(dev
, OC_MODIFY_OPEN_PARMS
);
1524 * Wait for some time (microseconds)
1526 static void sktr_wait(unsigned long time
)
1530 tmp
= jiffies
+ time
/(1000000/HZ
);
1532 current
->state
= TASK_INTERRUPTIBLE
;
1533 tmp
= schedule_timeout(tmp
);
1534 } while(time_after(tmp
, jiffies
));
1540 * Write a command value to the SIFCMD register
1542 static void sktr_exec_sifcmd(struct device
*dev
, unsigned int WriteValue
)
1544 int ioaddr
= dev
->base_addr
;
1546 unsigned short SifStsValue
;
1547 unsigned long loop_counter
;
1549 WriteValue
= ((WriteValue
^ CMD_SYSTEM_IRQ
) | CMD_INTERRUPT_ADAPTER
);
1550 cmd
= (unsigned short)WriteValue
;
1551 loop_counter
= 0,5 * 800000;
1553 SifStsValue
= inw(ioaddr
+ SIFSTS
);
1554 } while((SifStsValue
& CMD_INTERRUPT_ADAPTER
) && loop_counter
--);
1555 outw(cmd
, ioaddr
+ SIFCMD
);
1561 * Processes adapter hardware reset, halts adapter and downloads firmware,
1562 * clears the halt bit.
1564 static int sktr_reset_adapter(struct device
*dev
)
1566 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1567 unsigned short *fw_ptr
= (unsigned short *)&sktr_code
;
1568 unsigned short count
, c
;
1569 int ioaddr
= dev
->base_addr
;
1571 /* Hardware adapter reset */
1572 outw(ACL_ARESET
, ioaddr
+ SIFACL
);
1575 c
= inw(ioaddr
+ SIFACL
);
1578 if(dev
->dma
== 0) /* For PCI adapters */
1580 c
&= ~(ACL_SPEED4
| ACL_SPEED16
); /* Clear bits */
1581 if(tp
->DataRate
== SPEED_4
)
1582 c
|= ACL_SPEED4
; /* Set 4Mbps */
1584 c
|= ACL_SPEED16
; /* Set 16Mbps */
1587 /* In case a command is pending - forget it */
1590 c
&= ~ACL_ARESET
; /* Clear adapter reset bit */
1591 c
|= ACL_CPHALT
; /* Halt adapter CPU, allow download */
1592 c
&= ~ACL_PSDMAEN
; /* Clear pseudo dma bit */
1593 outw(c
, ioaddr
+ SIFACL
);
1596 /* Download firmware via DIO interface: */
1598 /* Download first address part */
1599 outw(*fw_ptr
, ioaddr
+ SIFADX
);
1602 /* Download second address part */
1603 outw(*fw_ptr
, ioaddr
+ SIFADD
);
1606 if((count
= *fw_ptr
) != 0) /* Load loop counter */
1608 fw_ptr
++; /* Download block data */
1609 for(; count
> 0; count
--)
1611 outw(*fw_ptr
, ioaddr
+ SIFINC
);
1615 else /* Stop, if last block downloaded */
1617 c
= inw(ioaddr
+ SIFACL
);
1618 c
&= (~ACL_CPHALT
| ACL_SINTEN
);
1620 /* Clear CPHALT and start BUD */
1621 outw(c
, ioaddr
+ SIFACL
);
1624 } while(count
== 0);
1630 * Starts bring up diagnostics of token ring adapter and evaluates
1631 * diagnostic results.
1633 static int sktr_bringup_diags(struct device
*dev
)
1635 int loop_cnt
, retry_cnt
;
1636 unsigned short Status
;
1637 int ioaddr
= dev
->base_addr
;
1639 sktr_wait(HALF_SECOND
);
1640 sktr_exec_sifcmd(dev
, EXEC_SOFT_RESET
);
1641 sktr_wait(HALF_SECOND
);
1643 retry_cnt
= BUD_MAX_RETRIES
; /* maximal number of retrys */
1648 printk(KERN_INFO
"BUD-Status: \n");
1649 loop_cnt
= BUD_MAX_LOOPCNT
; /* maximum: three seconds*/
1650 do { /* Inspect BUD results */
1652 sktr_wait(HALF_SECOND
);
1653 Status
= inw(ioaddr
+ SIFSTS
);
1657 printk(KERN_INFO
" %04X \n", Status
);
1658 /* BUD successfully completed */
1659 if(Status
== STS_INITIALIZE
)
1661 /* Unrecoverable hardware error, BUD not completed? */
1662 } while((loop_cnt
> 0) && ((Status
& (STS_ERROR
| STS_TEST
))
1663 != (STS_ERROR
| STS_TEST
)));
1665 /* Error preventing completion of BUD */
1668 printk(KERN_INFO
"%s: Adapter Software Reset.\n",
1670 sktr_exec_sifcmd(dev
, EXEC_SOFT_RESET
);
1671 sktr_wait(HALF_SECOND
);
1673 } while(retry_cnt
> 0);
1675 Status
= inw(ioaddr
+ SIFSTS
);
1676 Status
&= STS_ERROR_MASK
; /* Hardware error occurred! */
1678 printk(KERN_INFO
"%s: Bring Up Diagnostics Error (%04X) occurred\n",
1685 * Copy initialisation data to adapter memory, beginning at address
1686 * 1:0A00; Starting DMA test and evaluating result bits.
1688 static int sktr_init_adapter(struct device
*dev
)
1690 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1692 const unsigned char SCB_Test
[6] = {0x00, 0x00, 0xC1, 0xE2, 0xD4, 0x8B};
1693 const unsigned char SSB_Test
[8] = {0xFF, 0xFF, 0xD1, 0xD7,
1694 0xC5, 0xD9, 0xC3, 0xD4};
1695 void *ptr
= (void *)&tp
->ipb
;
1696 unsigned short *ipb_ptr
= (unsigned short *)ptr
;
1697 unsigned char *cb_ptr
= (unsigned char *) &tp
->scb
;
1698 unsigned char *sb_ptr
= (unsigned char *) &tp
->ssb
;
1699 unsigned short Status
;
1700 int i
, loop_cnt
, retry_cnt
;
1701 int ioaddr
= dev
->base_addr
;
1703 /* Normalize: byte order low/high, word order high/low! (only IPB!) */
1704 tp
->ipb
.SCB_Addr
= SWAPW(virt_to_bus(&tp
->scb
));
1705 tp
->ipb
.SSB_Addr
= SWAPW(virt_to_bus(&tp
->ssb
));
1707 /* Maximum: three initialization retries */
1708 retry_cnt
= INIT_MAX_RETRIES
;
1713 /* Transfer initialization block */
1714 outw(0x0001, ioaddr
+ SIFADX
);
1716 /* To address 0001:0A00 of adapter RAM */
1717 outw(0x0A00, ioaddr
+ SIFADD
);
1719 /* Write 11 words to adapter RAM */
1720 for(i
= 0; i
< 11; i
++)
1721 outw(ipb_ptr
[i
], ioaddr
+ SIFINC
);
1723 /* Execute SCB adapter command */
1724 sktr_exec_sifcmd(dev
, CMD_EXECUTE
);
1726 loop_cnt
= INIT_MAX_LOOPCNT
; /* Maximum: 11 seconds */
1728 /* While remaining retries, no error and not completed */
1732 sktr_wait(HALF_SECOND
);
1734 /* Mask interesting status bits */
1735 Status
= inw(ioaddr
+ SIFSTS
);
1737 } while(((Status
&(STS_INITIALIZE
| STS_ERROR
| STS_TEST
)) != 0)
1738 && ((Status
& STS_ERROR
) == 0) && (loop_cnt
!= 0));
1740 if((Status
& (STS_INITIALIZE
| STS_ERROR
| STS_TEST
)) == 0)
1742 /* Initialization completed without error */
1744 do { /* Test if contents of SCB is valid */
1745 if(SCB_Test
[i
] != *(cb_ptr
+ i
))
1746 /* DMA data error: wrong data in SCB */
1752 do { /* Test if contents of SSB is valid */
1753 if(SSB_Test
[i
] != *(sb_ptr
+ i
))
1754 /* DMA data error: wrong data in SSB */
1759 return (1); /* Adapter successfully initialized */
1763 if((Status
& STS_ERROR
) != 0)
1765 /* Initialization error occurred */
1766 Status
= inw(ioaddr
+ SIFSTS
);
1767 Status
&= STS_ERROR_MASK
;
1768 /* ShowInitialisationErrorCode(Status); */
1769 return (-1); /* Unrecoverable error */
1775 /* Reset adapter and try init again */
1776 sktr_exec_sifcmd(dev
, EXEC_SOFT_RESET
);
1777 sktr_wait(HALF_SECOND
);
1781 } while(retry_cnt
> 0);
1787 * Check for outstanding commands in command queue and tries to execute
1788 * command immediately. Corresponding command flag in command queue is cleared.
1790 static void sktr_chk_outstanding_cmds(struct device
*dev
)
1792 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1793 unsigned long Addr
= 0;
1794 unsigned char i
= 0;
1796 if(tp
->CMDqueue
== 0)
1797 return; /* No command execution */
1799 /* If SCB in use: no command */
1800 if(tp
->ScbInUse
== 1)
1803 /* Check if adapter is opened, avoiding COMMAND_REJECT
1804 * interrupt by the adapter!
1806 if(tp
->AdapterOpenFlag
== 0)
1808 if(tp
->CMDqueue
& OC_OPEN
)
1810 /* Execute OPEN command */
1811 tp
->CMDqueue
^= OC_OPEN
;
1813 /* Copy the 18 bytes of the product ID */
1814 while((AdapterName
[i
] != '\0') && (i
< PROD_ID_SIZE
))
1816 tp
->ProductID
[i
] = AdapterName
[i
];
1820 Addr
= htonl(virt_to_bus(&tp
->ocpl
));
1821 tp
->scb
.Parm
[0] = LOWORD(Addr
);
1822 tp
->scb
.Parm
[1] = HIWORD(Addr
);
1826 /* No OPEN command queued, but adapter closed. Note:
1827 * We'll try to re-open the adapter in DriverPoll()
1829 return; /* No adapter command issued */
1833 /* Adapter is open; evaluate command queue: try to execute
1834 * outstanding commands (depending on priority!) CLOSE
1837 if(tp
->CMDqueue
& OC_CLOSE
)
1839 tp
->CMDqueue
^= OC_CLOSE
;
1840 tp
->AdapterOpenFlag
= 0;
1841 tp
->scb
.Parm
[0] = 0; /* Parm[0], Parm[1] are ignored */
1842 tp
->scb
.Parm
[1] = 0; /* but should be set to zero! */
1843 tp
->scb
.CMD
= CLOSE
;
1844 if(!tp
->HaltInProgress
)
1845 tp
->CMDqueue
|= OC_OPEN
; /* re-open adapter */
1847 tp
->CMDqueue
= 0; /* no more commands */
1851 if(tp
->CMDqueue
& OC_RECEIVE
)
1853 tp
->CMDqueue
^= OC_RECEIVE
;
1854 Addr
= htonl(virt_to_bus(tp
->RplHead
));
1855 tp
->scb
.Parm
[0] = LOWORD(Addr
);
1856 tp
->scb
.Parm
[1] = HIWORD(Addr
);
1857 tp
->scb
.CMD
= RECEIVE
;
1861 if(tp
->CMDqueue
& OC_TRANSMIT_HALT
)
1863 /* NOTE: TRANSMIT.HALT must be checked
1866 tp
->CMDqueue
^= OC_TRANSMIT_HALT
;
1867 tp
->scb
.CMD
= TRANSMIT_HALT
;
1869 /* Parm[0] and Parm[1] are ignored
1870 * but should be set to zero!
1872 tp
->scb
.Parm
[0] = 0;
1873 tp
->scb
.Parm
[1] = 0;
1877 if(tp
->CMDqueue
& OC_TRANSMIT
)
1879 /* NOTE: TRANSMIT must be
1880 * checked after TRANSMIT.HALT
1882 if(tp
->TransmitCommandActive
)
1884 if(!tp
->TransmitHaltScheduled
)
1886 tp
->TransmitHaltScheduled
= 1;
1887 sktr_exec_cmd(dev
, OC_TRANSMIT_HALT
) ;
1889 tp
->TransmitCommandActive
= 0;
1893 tp
->CMDqueue
^= OC_TRANSMIT
;
1894 sktr_cancel_tx_queue(tp
);
1895 Addr
= htonl(virt_to_bus(tp
->TplBusy
));
1896 tp
->scb
.Parm
[0] = LOWORD(Addr
);
1897 tp
->scb
.Parm
[1] = HIWORD(Addr
);
1898 tp
->scb
.CMD
= TRANSMIT
;
1899 tp
->TransmitCommandActive
= 1;
1903 if(tp
->CMDqueue
& OC_MODIFY_OPEN_PARMS
)
1905 tp
->CMDqueue
^= OC_MODIFY_OPEN_PARMS
;
1906 tp
->scb
.Parm
[0] = tp
->ocpl
.OPENOptions
; /* new OPEN options*/
1907 tp
->scb
.Parm
[0] |= ENABLE_FULL_DUPLEX_SELECTION
;
1908 tp
->scb
.Parm
[1] = 0; /* is ignored but should be zero */
1909 tp
->scb
.CMD
= MODIFY_OPEN_PARMS
;
1913 if(tp
->CMDqueue
& OC_SET_FUNCT_ADDR
)
1915 tp
->CMDqueue
^= OC_SET_FUNCT_ADDR
;
1916 tp
->scb
.Parm
[0] = LOWORD(tp
->ocpl
.FunctAddr
);
1917 tp
->scb
.Parm
[1] = HIWORD(tp
->ocpl
.FunctAddr
);
1918 tp
->scb
.CMD
= SET_FUNCT_ADDR
;
1922 if(tp
->CMDqueue
& OC_SET_GROUP_ADDR
)
1924 tp
->CMDqueue
^= OC_SET_GROUP_ADDR
;
1925 tp
->scb
.Parm
[0] = LOWORD(tp
->ocpl
.GroupAddr
);
1926 tp
->scb
.Parm
[1] = HIWORD(tp
->ocpl
.GroupAddr
);
1927 tp
->scb
.CMD
= SET_GROUP_ADDR
;
1931 if(tp
->CMDqueue
& OC_READ_ERROR_LOG
)
1933 tp
->CMDqueue
^= OC_READ_ERROR_LOG
;
1934 Addr
= htonl(virt_to_bus(&tp
->errorlogtable
));
1935 tp
->scb
.Parm
[0] = LOWORD(Addr
);
1936 tp
->scb
.Parm
[1] = HIWORD(Addr
);
1937 tp
->scb
.CMD
= READ_ERROR_LOG
;
1941 printk(KERN_WARNING
"CheckForOutstandingCommand: unknown Command\n");
1954 tp
->ScbInUse
= 1; /* Set semaphore: SCB in use. */
1956 /* Execute SCB and generate IRQ when done. */
1957 sktr_exec_sifcmd(dev
, CMD_EXECUTE
| CMD_SCB_REQUEST
);
1963 * IRQ conditions: signal loss on the ring, transmit or receive of beacon
1964 * frames (disabled if bit 1 of OPEN option is set); report error MAC
1965 * frame transmit (disabled if bit 2 of OPEN option is set); open or short
1966 * cirquit fault on the lobe is detected; remove MAC frame received;
1967 * error counter overflow (255); opened adapter is the only station in ring.
1968 * After some of the IRQs the adapter is closed!
1970 static void sktr_ring_status_irq(struct device
*dev
)
1972 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
1974 tp
->CurrentRingStatus
= SWAPB(tp
->ssb
.Parm
[0]);
1976 /* First: fill up statistics */
1977 if(tp
->ssb
.Parm
[0] & SIGNAL_LOSS
)
1979 printk(KERN_INFO
"%s: Signal Loss\n", dev
->name
);
1980 tp
->MacStat
.line_errors
++;
1983 /* Adapter is closed, but initialized */
1984 if(tp
->ssb
.Parm
[0] & LOBE_WIRE_FAULT
)
1986 printk(KERN_INFO
"%s: Lobe Wire Fault, Reopen Adapter\n",
1988 tp
->MacStat
.line_errors
++;
1991 if(tp
->ssb
.Parm
[0] & RING_RECOVERY
)
1992 printk(KERN_INFO
"%s: Ring Recovery\n", dev
->name
);
1994 /* Counter overflow: read error log */
1995 if(tp
->ssb
.Parm
[0] & COUNTER_OVERFLOW
)
1997 printk(KERN_INFO
"%s: Counter Overflow\n", dev
->name
);
1998 sktr_exec_cmd(dev
, OC_READ_ERROR_LOG
);
2001 /* Adapter is closed, but initialized */
2002 if(tp
->ssb
.Parm
[0] & REMOVE_RECEIVED
)
2003 printk(KERN_INFO
"%s: Remove Received, Reopen Adapter\n",
2006 /* Adapter is closed, but initialized */
2007 if(tp
->ssb
.Parm
[0] & AUTO_REMOVAL_ERROR
)
2008 printk(KERN_INFO
"%s: Auto Removal Error, Reopen Adapter\n",
2011 if(tp
->ssb
.Parm
[0] & HARD_ERROR
)
2012 printk(KERN_INFO
"%s: Hard Error\n", dev
->name
);
2014 if(tp
->ssb
.Parm
[0] & SOFT_ERROR
)
2015 printk(KERN_INFO
"%s: Soft Error\n", dev
->name
);
2017 if(tp
->ssb
.Parm
[0] & TRANSMIT_BEACON
)
2018 printk(KERN_INFO
"%s: Transmit Beacon\n", dev
->name
);
2020 if(tp
->ssb
.Parm
[0] & SINGLE_STATION
)
2021 printk(KERN_INFO
"%s: Single Station\n", dev
->name
);
2023 /* Check if adapter has been closed */
2024 if(tp
->ssb
.Parm
[0] & ADAPTER_CLOSED
)
2026 printk(KERN_INFO
"%s: Adapter closed (Reopening),"
2027 "QueueSkb %d, CurrentRingStat %x\n",
2028 dev
->name
, tp
->QueueSkb
, tp
->CurrentRingStatus
);
2029 tp
->AdapterOpenFlag
= 0;
2030 sktr_open_adapter(dev
);
2037 * Issued if adapter has encountered an unrecoverable hardware
2038 * or software error.
2040 static void sktr_chk_irq(struct device
*dev
)
2043 unsigned short AdapterCheckBlock
[4];
2044 unsigned short ioaddr
= dev
->base_addr
;
2045 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
2047 tp
->AdapterOpenFlag
= 0; /* Adapter closed now */
2049 /* Page number of adapter memory */
2050 outw(0x0001, ioaddr
+ SIFADX
);
2051 /* Address offset */
2052 outw(CHECKADDR
, ioaddr
+ SIFADR
);
2054 /* Reading 8 byte adapter check block. */
2055 for(i
= 0; i
< 4; i
++)
2056 AdapterCheckBlock
[i
] = inw(ioaddr
+ SIFINC
);
2060 printk("%s: AdapterCheckBlock: ", dev
->name
);
2061 for (i
= 0; i
< 4; i
++)
2062 printk("%04X", AdapterCheckBlock
[i
]);
2066 switch(AdapterCheckBlock
[0])
2069 printk(KERN_INFO
"%s: DIO parity error\n", dev
->name
);
2072 case DMA_READ_ABORT
:
2073 printk(KERN_INFO
"%s DMA read operation aborted:\n",
2075 switch (AdapterCheckBlock
[1])
2078 printk(KERN_INFO
"Timeout\n");
2079 printk(KERN_INFO
"Address: %04X %04X\n",
2080 AdapterCheckBlock
[2],
2081 AdapterCheckBlock
[3]);
2085 printk(KERN_INFO
"Parity error\n");
2086 printk(KERN_INFO
"Address: %04X %04X\n",
2087 AdapterCheckBlock
[2],
2088 AdapterCheckBlock
[3]);
2092 printk(KERN_INFO
"Bus error\n");
2093 printk(KERN_INFO
"Address: %04X %04X\n",
2094 AdapterCheckBlock
[2],
2095 AdapterCheckBlock
[3]);
2099 printk(KERN_INFO
"Unknown error.\n");
2104 case DMA_WRITE_ABORT
:
2105 printk(KERN_INFO
"%s: DMA write operation aborted: \n",
2107 switch (AdapterCheckBlock
[1])
2110 printk(KERN_INFO
"Timeout\n");
2111 printk(KERN_INFO
"Address: %04X %04X\n",
2112 AdapterCheckBlock
[2],
2113 AdapterCheckBlock
[3]);
2117 printk(KERN_INFO
"Parity error\n");
2118 printk(KERN_INFO
"Address: %04X %04X\n",
2119 AdapterCheckBlock
[2],
2120 AdapterCheckBlock
[3]);
2124 printk(KERN_INFO
"Bus error\n");
2125 printk(KERN_INFO
"Address: %04X %04X\n",
2126 AdapterCheckBlock
[2],
2127 AdapterCheckBlock
[3]);
2131 printk(KERN_INFO
"Unknown error.\n");
2136 case ILLEGAL_OP_CODE
:
2137 printk("%s: Illegal operation code in firmware\n",
2139 /* Parm[0-3]: adapter internal register R13-R15 */
2143 printk("%s: Adapter internal bus parity error\n",
2145 /* Parm[0-3]: adapter internal register R13-R15 */
2148 case RAM_DATA_ERROR
:
2149 printk("%s: RAM data error\n", dev
->name
);
2150 /* Parm[0-1]: MSW/LSW address of RAM location. */
2153 case RAM_PARITY_ERROR
:
2154 printk("%s: RAM parity error\n", dev
->name
);
2155 /* Parm[0-1]: MSW/LSW address of RAM location. */
2159 printk("%s: Internal DMA underrun detected\n",
2164 printk("%s: Unrecognized interrupt detected\n",
2166 /* Parm[0-3]: adapter internal register R13-R15 */
2169 case INVALID_ERROR_IRQ
:
2170 printk("%s: Unrecognized error interrupt detected\n",
2172 /* Parm[0-3]: adapter internal register R13-R15 */
2176 printk("%s: Unrecognized XOP request detected\n",
2178 /* Parm[0-3]: adapter internal register R13-R15 */
2182 printk("%s: Unknown status", dev
->name
);
2186 if(sktr_chipset_init(dev
) == 1)
2188 /* Restart of firmware successful */
2189 tp
->AdapterOpenFlag
= 1;
2196 * Internal adapter pointer to RAM data are copied from adapter into
2199 static void sktr_read_ptr(struct device
*dev
)
2201 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
2202 unsigned short adapterram
;
2204 sktr_read_ram(dev
, (unsigned char *)&tp
->intptrs
.BurnedInAddrPtr
,
2205 ADAPTER_INT_PTRS
, 16);
2206 sktr_read_ram(dev
, (unsigned char *)&adapterram
,
2207 (unsigned short)SWAPB(tp
->intptrs
.AdapterRAMPtr
), 2);
2209 printk(KERN_INFO
"%s: Adapter RAM size: %d K\n",
2210 dev
->name
, SWAPB(adapterram
));
2216 * Reads a number of bytes from adapter to system memory.
2218 static void sktr_read_ram(struct device
*dev
, unsigned char *Data
,
2219 unsigned short Address
, int Length
)
2222 unsigned short old_sifadx
, old_sifadr
, InWord
;
2223 unsigned short ioaddr
= dev
->base_addr
;
2225 /* Save the current values */
2226 old_sifadx
= inw(ioaddr
+ SIFADX
);
2227 old_sifadr
= inw(ioaddr
+ SIFADR
);
2229 /* Page number of adapter memory */
2230 outw(0x0001, ioaddr
+ SIFADX
);
2231 /* Address offset in adapter RAM */
2232 outw(Address
, ioaddr
+ SIFADR
);
2234 /* Copy len byte from adapter memory to system data area. */
2238 InWord
= inw(ioaddr
+ SIFINC
);
2240 *(Data
+ i
) = HIBYTE(InWord
); /* Write first byte */
2241 if(++i
== Length
) /* All is done break */
2244 *(Data
+ i
) = LOBYTE(InWord
); /* Write second byte */
2245 if (++i
== Length
) /* All is done break */
2249 /* Restore original values */
2250 outw(old_sifadx
, ioaddr
+ SIFADX
);
2251 outw(old_sifadr
, ioaddr
+ SIFADR
);
2257 * Reads MAC address from adapter ROM.
2259 static void sktr_read_addr(struct device
*dev
, unsigned char *Address
)
2262 unsigned short ioaddr
= dev
->base_addr
;
2264 /* Address: 0000:0000 */
2265 outw(0, ioaddr
+ SIFADX
);
2266 outw(0, ioaddr
+ SIFADR
);
2268 /* Read six byte MAC address data */
2269 for(i
= 0; i
< 6; i
++)
2271 In
= inw(ioaddr
+ SIFINC
);
2272 *(Address
+ i
) = (unsigned char)(In
>> 8);
2279 * Cancel all queued packets in the transmission queue.
2281 static void sktr_cancel_tx_queue(struct net_local
* tp
)
2284 struct sk_buff
*skb
;
2287 * NOTE: There must not be an active TRANSMIT command pending, when
2288 * this function is called.
2290 if(tp
->TransmitCommandActive
)
2298 /* "Remove" TPL from busy list. */
2299 tp
->TplBusy
= tpl
->NextTPLPtr
;
2300 sktr_write_tpl_status(tpl
, 0); /* Clear VALID bit */
2301 tpl
->BusyFlag
= 0; /* "free" TPL */
2303 printk(KERN_INFO
"Cancel tx (%08lXh).\n", (unsigned long)tpl
);
2305 dev_kfree_skb(tpl
->Skb
);
2310 skb
= skb_dequeue(&tp
->SendSkbQueue
);
2321 * This function is called whenever a transmit interrupt is generated by the
2322 * adapter. For a command complete interrupt, it is checked if we have to
2323 * issue a new transmit command or not.
2325 static void sktr_tx_status_irq(struct device
*dev
)
2327 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
2328 unsigned char HighByte
, HighAc
, LowAc
;
2331 /* NOTE: At this point the SSB from TRANSMIT STATUS is no longer
2332 * available, because the CLEAR SSB command has already been issued.
2334 * Process all complete transmissions.
2340 if(!tpl
->BusyFlag
|| (tpl
->Status
2341 & (TX_VALID
| TX_FRAME_COMPLETE
))
2342 != TX_FRAME_COMPLETE
)
2347 /* "Remove" TPL from busy list. */
2348 tp
->TplBusy
= tpl
->NextTPLPtr
;
2351 sktr_dump(tpl
->MData
, SWAPB(tpl
->FrameSize
));
2353 /* Check the transmit status field only for directed frames*/
2354 if(DIRECTED_FRAME(tpl
) && (tpl
->Status
& TX_ERROR
) == 0)
2356 HighByte
= GET_TRANSMIT_STATUS_HIGH_BYTE(tpl
->Status
);
2357 HighAc
= GET_FRAME_STATUS_HIGH_AC(HighByte
);
2358 LowAc
= GET_FRAME_STATUS_LOW_AC(HighByte
);
2360 if((HighAc
!= LowAc
) || (HighAc
== AC_NOT_RECOGNIZED
))
2362 printk(KERN_INFO
"%s: (DA=%08lX not recognized)",
2364 *(unsigned long *)&tpl
->MData
[2+2]);
2369 printk("%s: Directed frame tx'd\n",
2375 if(!DIRECTED_FRAME(tpl
))
2378 printk("%s: Broadcast frame tx'd\n",
2383 tp
->MacStat
.tx_packets
++;
2384 dev_kfree_skb(tpl
->Skb
);
2385 tpl
->BusyFlag
= 0; /* "free" TPL */
2389 if(tp
->QueueSkb
< MAX_TX_QUEUE
)
2390 sktr_hardware_send_packet(dev
, tp
);
2396 * Called if a frame receive interrupt is generated by the adapter.
2397 * Check if the frame is valid and indicate it to system.
2399 static void sktr_rcv_status_irq(struct device
*dev
)
2401 struct net_local
*tp
= (struct net_local
*)dev
->priv
;
2402 unsigned char *ReceiveDataPtr
;
2403 struct sk_buff
*skb
;
2404 unsigned int Length
, Length2
;
2408 /* NOTE: At this point the SSB from RECEIVE STATUS is no longer
2409 * available, because the CLEAR SSB command has already been issued.
2411 * Process all complete receives.
2417 if(rpl
->Status
& RX_VALID
)
2418 break; /* RPL still in use by adapter */
2420 /* Forward RPLHead pointer to next list. */
2421 SaveHead
= tp
->RplHead
;
2422 tp
->RplHead
= rpl
->NextRPLPtr
;
2424 /* Get the frame size (Byte swap for Intel).
2425 * Do this early (see workaround comment below)
2427 Length
= (unsigned short)SWAPB(rpl
->FrameSize
);
2429 /* Check if the Frame_Start, Frame_End and
2430 * Frame_Complete bits are set.
2432 if((rpl
->Status
& VALID_SINGLE_BUFFER_FRAME
)
2433 == VALID_SINGLE_BUFFER_FRAME
)
2435 ReceiveDataPtr
= rpl
->MData
;
2437 /* Workaround for delayed write of FrameSize on ISA
2438 * (FrameSize is false but valid-bit is reset)
2439 * Frame size is set to zero when the RPL is freed.
2440 * Length2 is there because there have also been
2441 * cases where the FrameSize was partially written
2443 Length2
= (unsigned short)SWAPB(rpl
->FrameSize
);
2445 if(Length
== 0 || Length
!= Length2
)
2447 tp
->RplHead
= SaveHead
;
2448 break; /* Return to sktr_interrupt */
2451 /* Drop frames sent by myself */
2452 if(sktr_chk_frame(dev
, rpl
->MData
))
2454 printk(KERN_INFO
"%s: Received my own frame\n",
2456 if(rpl
->Skb
!= NULL
)
2457 dev_kfree_skb(rpl
->Skb
);
2461 sktr_update_rcv_stats(tp
,ReceiveDataPtr
,Length
);
2464 printk("%s: Packet Length %04X (%d)\n",
2465 dev
->name
, Length
, Length
);
2467 /* Indicate the received frame to system the
2468 * adapter does the Source-Routing padding for
2469 * us. See: OpenOptions in sktr_init_opb()
2472 if(rpl
->SkbStat
== SKB_UNAVAILABLE
)
2474 /* Try again to allocate skb */
2475 skb
= dev_alloc_skb(tp
->MaxPacketSize
);
2478 /* Update Stats ?? */
2483 skb_put(skb
, tp
->MaxPacketSize
);
2484 rpl
->SkbStat
= SKB_DATA_COPY
;
2485 ReceiveDataPtr
= rpl
->MData
;
2489 if(rpl
->SkbStat
== SKB_DATA_COPY
2490 || rpl
->SkbStat
== SKB_DMA_DIRECT
)
2492 if(rpl
->SkbStat
== SKB_DATA_COPY
)
2494 memmove(skb
->data
, ReceiveDataPtr
, Length
);
2497 /* Deliver frame to system */
2499 skb_trim(skb
,Length
);
2500 skb
->protocol
= tr_type_trans(skb
,dev
);
2505 else /* Invalid frame */
2507 if(rpl
->Skb
!= NULL
)
2508 dev_kfree_skb(rpl
->Skb
);
2511 if(rpl
->Status
& RX_START_FRAME
)
2512 /* Frame start bit is set -> overflow. */
2513 tp
->MacStat
.rx_errors
++;
2516 /* Allocate new skb for rpl */
2517 rpl
->Skb
= dev_alloc_skb(tp
->MaxPacketSize
);
2519 /* skb == NULL ? then use local buffer */
2520 if(rpl
->Skb
== NULL
)
2522 rpl
->SkbStat
= SKB_UNAVAILABLE
;
2523 rpl
->FragList
[0].DataAddr
= htonl(virt_to_bus(tp
->LocalRxBuffers
[rpl
->RPLIndex
]));
2524 rpl
->MData
= tp
->LocalRxBuffers
[rpl
->RPLIndex
];
2526 else /* skb != NULL */
2528 rpl
->Skb
->dev
= dev
;
2529 skb_put(rpl
->Skb
, tp
->MaxPacketSize
);
2531 /* Data unreachable for DMA ? then use local buffer */
2532 if(virt_to_bus(rpl
->Skb
->data
) + tp
->MaxPacketSize
2535 rpl
->SkbStat
= SKB_DATA_COPY
;
2536 rpl
->FragList
[0].DataAddr
= htonl(virt_to_bus(tp
->LocalRxBuffers
[rpl
->RPLIndex
]));
2537 rpl
->MData
= tp
->LocalRxBuffers
[rpl
->RPLIndex
];
2541 /* DMA directly in skb->data */
2542 rpl
->SkbStat
= SKB_DMA_DIRECT
;
2543 rpl
->FragList
[0].DataAddr
= htonl(virt_to_bus(rpl
->Skb
->data
));
2544 rpl
->MData
= rpl
->Skb
->data
;
2548 rpl
->FragList
[0].DataCount
= SWAPB(tp
->MaxPacketSize
);
2551 /* Pass the last RPL back to the adapter */
2552 tp
->RplTail
->FrameSize
= 0;
2554 /* Reset the CSTAT field in the list. */
2555 sktr_write_rpl_status(tp
->RplTail
, RX_VALID
| RX_FRAME_IRQ
);
2557 /* Current RPL becomes last one in list. */
2558 tp
->RplTail
= tp
->RplTail
->NextRPLPtr
;
2560 /* Inform adapter about RPL valid. */
2561 sktr_exec_sifcmd(dev
, CMD_RX_VALID
);
2568 * This function should be used whenever the status of any RPL must be
2569 * modified by the driver, because the compiler may otherwise change the
2570 * order of instructions such that writing the RPL status may be executed
2571 * at an undesireable time. When this function is used, the status is
2572 * always written when the function is called.
2574 static void sktr_write_rpl_status(RPL
*rpl
, unsigned int Status
)
2576 rpl
->Status
= Status
;
2582 * The function updates the statistic counters in mac->MacStat.
2583 * It differtiates between directed and broadcast/multicast ( ==functional)
2586 static void sktr_update_rcv_stats(struct net_local
*tp
, unsigned char DataPtr
[],
2587 unsigned int Length
)
2589 tp
->MacStat
.rx_packets
++;
2591 /* Test functional bit */
2592 if(DataPtr
[2] & GROUP_BIT
)
2593 tp
->MacStat
.multicast
++;
2599 * Check if it is a frame of myself. Compare source address with my current
2600 * address in reverse direction, and mask out the TR_RII.
2602 static unsigned char sktr_chk_frame(struct device
*dev
, unsigned char *Addr
)
2606 for(i
= 5; i
> 0; i
--)
2608 if(Addr
[8 + i
] != dev
->dev_addr
[i
])
2612 /* Mask out RIF bit. */
2613 if((Addr
[8] & ~TR_RII
) != (unsigned char)(dev
->dev_addr
[0]))
2616 return (1); /* It is my frame. */
2620 * Dump Packet (data)
2622 static void sktr_dump(unsigned char *Data
, int length
)
2626 for (i
= 0, j
= 0; i
< length
/ 8; i
++, j
+= 8)
2628 printk(KERN_DEBUG
"%02x %02x %02x %02x %02x %02x %02x %02x\n",
2629 Data
[j
+0],Data
[j
+1],Data
[j
+2],Data
[j
+3],
2630 Data
[j
+4],Data
[j
+5],Data
[j
+6],Data
[j
+7]);
2638 static struct device
* dev_sktr
[SKTR_MAX_ADAPTERS
];
2639 static int io
[SKTR_MAX_ADAPTERS
] = { 0, 0 };
2640 static int irq
[SKTR_MAX_ADAPTERS
] = { 0, 0 };
2641 static int mem
[SKTR_MAX_ADAPTERS
] = { 0, 0 };
2643 MODULE_PARM(io
, "1-" __MODULE_STRING(SKTR_MAX_ADAPTERS
) "i");
2644 MODULE_PARM(irq
, "1-" __MODULE_STRING(SKTR_MAX_ADAPTERS
) "i");
2645 MODULE_PARM(mem
, "1-" __MODULE_STRING(SKTR_MAX_ADAPTERS
) "i");
2647 int init_module(void)
2651 for(i
= 0; i
< SKTR_MAX_ADAPTERS
; i
++)
2656 dev_sktr
[i
] = init_trdev(dev_sktr
[i
], 0);
2657 if(dev_sktr
[i
] == NULL
)
2660 dev_sktr
[i
]->base_addr
= io
[i
];
2661 dev_sktr
[i
]->irq
= irq
[i
];
2662 dev_sktr
[i
]->mem_start
= mem
[i
];
2663 dev_sktr
[i
]->init
= &sktr_probe
;
2665 if(register_trdev(dev_sktr
[i
]) != 0)
2667 kfree_s(dev_sktr
[i
], sizeof(struct device
));
2671 printk("sktr: register_trdev() returned non-zero.\n");
2682 void cleanup_module(void)
2686 for(i
= 0; i
< SKTR_MAX_ADAPTERS
; i
++)
2690 unregister_trdev(dev_sktr
[i
]);
2691 release_region(dev_sktr
[i
]->base_addr
, SKTR_IO_EXTENT
);
2692 if(dev_sktr
[i
]->irq
)
2693 free_irq(dev_sktr
[i
]->irq
, dev_sktr
[i
]);
2694 if(dev_sktr
[i
]->dma
> 0)
2695 free_dma(dev_sktr
[i
]->dma
);
2696 if(dev_sktr
[i
]->priv
)
2697 kfree_s(dev_sktr
[i
]->priv
, sizeof(struct net_local
));
2698 kfree_s(dev_sktr
[i
], sizeof(struct device
));