2
* tms380tr.c: A network driver library for Texas Instruments TMS380-based
5
* Originally sktr.c: Written 1997 by Christoph Goos
7
* A fine result of the Linux Systems Network Architecture Project.
8
* http://www.vanheusden.com/sna/
10
* This software may be used and distributed according to the terms
11
* of the GNU General Public License, incorporated herein by reference.
13
* The following modules are currently available for card support:
14
* - tmspci (Generic PCI card support)
15
* - abyss (Madge PCI support)
16
* - tmsisa (SysKonnect TR4/16 ISA)
19
* - The hardware related parts of this driver are take from
20
* the SysKonnect Token Ring driver for Windows NT.
21
* - I used the IBM Token Ring driver 'ibmtr.c' as a base for this
22
* driver, as well as the 'skeleton.c' driver by Donald Becker.
23
* - Also various other drivers in the linux source tree were taken
24
* as samples for some tasks.
25
* - TI TMS380 Second-Generation Token Ring User's Guide
26
* - TI datasheets for respective chips
27
* - David Hein at Texas Instruments
28
* - Various Madge employees
31
* JS Jay Schulist jschlst@samba.org
32
* CG Christoph Goos cgoos@syskonnect.de
34
* MLP Mike Phillips phillim@amtrak.com
35
* JF Jochen Friedrich jochen@scram.de
37
* Modification History:
38
* 29-Aug-97 CG Created
39
* 04-Apr-98 CG Fixed problems caused by tok_timer_check
40
* 10-Apr-98 CG Fixed lockups at cable disconnection
41
* 27-May-98 JS Formated to Linux Kernel Format
42
* 31-May-98 JS Hacked in PCI support
43
* 16-Jun-98 JS Modulized for multiple cards with one driver
44
* Sep-99 AF Renamed to tms380tr (supports more than SK's)
45
* 23-Sep-99 AF Added Compaq and Thomas-Conrad PCI support
46
* Fixed a bug causing double copies on PCI
47
* Fixed for new multicast stuff (2.2/2.3)
48
* 25-Sep-99 AF Uped TPL_NUM from 3 to 9
49
* Removed extraneous 'No free TPL'
50
* 22-Dec-99 AF Added Madge PCI Mk2 support and generalized
51
* parts of the initilization procedure.
52
* 30-Dec-99 AF Turned tms380tr into a library ala 8390.
53
* Madge support is provided in the abyss module
54
* Generic PCI support is in the tmspci module.
55
* 30-Nov-00 JF Updated PCI code to support IO MMU via
56
* pci_map_static(). Alpha uses this MMU for ISA
58
* 14-Jan-01 JF Fix DMA on ifdown/ifup sequences. Some
60
* 13-Jan-02 JF Add spinlock to fix race condition.
61
* 09-Nov-02 JF Fixed printks to not SPAM the console during
63
* 30-Dec-02 JF Removed incorrect __init from
65
* 22-Jul-05 JF Converted to dma-mapping.
68
* 1. Multi/Broadcast packet handling (this may have fixed itself)
69
* 2. Write a sktrisa module that includes the old ISA support (done)
70
* 3. Allow modules to load their own microcode
71
* 4. Speed up the BUD process -- freezing the kernel for 3+sec is
73
* 5. Still a few remaining stalls when the cable is unplugged.
77
static const char version[] = "tms380tr.c: v1.10 30/12/2002 by Christoph Goos, Adam Fritzler\n";
80
#include <linux/module.h>
81
#include <linux/kernel.h>
82
#include <linux/types.h>
83
#include <linux/fcntl.h>
84
#include <linux/interrupt.h>
85
#include <linux/ptrace.h>
86
#include <linux/ioport.h>
88
#include <linux/string.h>
89
#include <linux/time.h>
90
#include <linux/errno.h>
91
#include <linux/init.h>
92
#include <linux/dma-mapping.h>
93
#include <linux/delay.h>
94
#include <linux/netdevice.h>
95
#include <linux/etherdevice.h>
96
#include <linux/skbuff.h>
97
#include <linux/trdevice.h>
98
#include <linux/firmware.h>
99
#include <linux/bitops.h>
104
#include <asm/uaccess.h>
106
#include "tms380tr.h" /* Our Stuff */
108
/* Use 0 for production, 1 for verification, 2 for debug, and
109
* 3 for very verbose debug.
111
#ifndef TMS380TR_DEBUG
112
#define TMS380TR_DEBUG 0
114
static unsigned int tms380tr_debug = TMS380TR_DEBUG;
116
/* Index to functions, as function prototypes.
117
* Alphabetical by function name.
122
static int tms380tr_bringup_diags(struct net_device *dev);
124
static void tms380tr_cancel_tx_queue(struct net_local* tp);
125
static int tms380tr_chipset_init(struct net_device *dev);
126
static void tms380tr_chk_irq(struct net_device *dev);
127
static void tms380tr_chk_outstanding_cmds(struct net_device *dev);
128
static void tms380tr_chk_src_addr(unsigned char *frame, unsigned char *hw_addr);
129
static unsigned char tms380tr_chk_ssb(struct net_local *tp, unsigned short IrqType);
130
int tms380tr_close(struct net_device *dev);
131
static void tms380tr_cmd_status_irq(struct net_device *dev);
133
static void tms380tr_disable_interrupts(struct net_device *dev);
134
#if TMS380TR_DEBUG > 0
135
static void tms380tr_dump(unsigned char *Data, int length);
138
static void tms380tr_enable_interrupts(struct net_device *dev);
139
static void tms380tr_exec_cmd(struct net_device *dev, unsigned short Command);
140
static void tms380tr_exec_sifcmd(struct net_device *dev, unsigned int WriteValue);
143
static struct net_device_stats *tms380tr_get_stats(struct net_device *dev);
145
static netdev_tx_t tms380tr_hardware_send_packet(struct sk_buff *skb,
146
struct net_device *dev);
148
static int tms380tr_init_adapter(struct net_device *dev);
149
static void tms380tr_init_ipb(struct net_local *tp);
150
static void tms380tr_init_net_local(struct net_device *dev);
151
static void tms380tr_init_opb(struct net_device *dev);
154
int tms380tr_open(struct net_device *dev);
155
static void tms380tr_open_adapter(struct net_device *dev);
158
static void tms380tr_rcv_status_irq(struct net_device *dev);
159
static int tms380tr_read_ptr(struct net_device *dev);
160
static void tms380tr_read_ram(struct net_device *dev, unsigned char *Data,
161
unsigned short Address, int Length);
162
static int tms380tr_reset_adapter(struct net_device *dev);
163
static void tms380tr_reset_interrupt(struct net_device *dev);
164
static void tms380tr_ring_status_irq(struct net_device *dev);
166
static netdev_tx_t tms380tr_send_packet(struct sk_buff *skb,
167
struct net_device *dev);
168
static void tms380tr_set_multicast_list(struct net_device *dev);
169
static int tms380tr_set_mac_address(struct net_device *dev, void *addr);
171
static void tms380tr_timer_chk(unsigned long data);
172
static void tms380tr_timer_end_wait(unsigned long data);
173
static void tms380tr_tx_status_irq(struct net_device *dev);
175
static void tms380tr_update_rcv_stats(struct net_local *tp,
176
unsigned char DataPtr[], unsigned int Length);
178
void tms380tr_wait(unsigned long time);
179
static void tms380tr_write_rpl_status(RPL *rpl, unsigned int Status);
180
static void tms380tr_write_tpl_status(TPL *tpl, unsigned int Status);
182
#define SIFREADB(reg) \
183
(((struct net_local *)netdev_priv(dev))->sifreadb(dev, reg))
184
#define SIFWRITEB(val, reg) \
185
(((struct net_local *)netdev_priv(dev))->sifwriteb(dev, val, reg))
186
#define SIFREADW(reg) \
187
(((struct net_local *)netdev_priv(dev))->sifreadw(dev, reg))
188
#define SIFWRITEW(val, reg) \
189
(((struct net_local *)netdev_priv(dev))->sifwritew(dev, val, reg))
193
#if 0 /* TMS380TR_DEBUG > 0 */
194
static int madgemc_sifprobe(struct net_device *dev)
196
unsigned char old, chk1, chk2;
198
old = SIFREADB(SIFADR); /* Get the old SIFADR value */
200
chk1 = 0; /* Begin with check value 0 */
202
madgemc_setregpage(dev, 0);
203
/* Write new SIFADR value */
204
SIFWRITEB(chk1, SIFADR);
205
chk2 = SIFREADB(SIFADR);
209
madgemc_setregpage(dev, 1);
210
/* Read, invert and write */
211
chk2 = SIFREADB(SIFADD);
215
madgemc_setregpage(dev, 0);
217
SIFWRITEB(chk2, SIFADR);
219
/* Read, invert and compare */
220
madgemc_setregpage(dev, 1);
221
chk2 = SIFREADB(SIFADD);
222
madgemc_setregpage(dev, 0);
226
return -1; /* No adapter */
228
} while(chk1 != 0); /* Repeat 128 times (all byte values) */
230
madgemc_setregpage(dev, 0); /* sanity */
231
/* Restore the SIFADR value */
232
SIFWRITEB(old, SIFADR);
239
* Open/initialize the board. This is called sometime after
240
* booting when the 'ifconfig' program is run.
242
* This routine should set everything up anew at each open, even
243
* registers that "should" only need to be set once at boot, so that
244
* there is non-reboot way to recover if something goes wrong.
246
int tms380tr_open(struct net_device *dev)
248
struct net_local *tp = netdev_priv(dev);
251
/* init the spinlock */
252
spin_lock_init(&tp->lock);
253
init_timer(&tp->timer);
255
/* Reset the hardware here. Don't forget to set the station address. */
260
unsigned long flags=claim_dma_lock();
261
disable_dma(dev->dma);
262
set_dma_mode(dev->dma, DMA_MODE_CASCADE);
263
enable_dma(dev->dma);
264
release_dma_lock(flags);
268
err = tms380tr_chipset_init(dev);
271
printk(KERN_INFO "%s: Chipset initialization error\n",
276
tp->timer.expires = jiffies + 30*HZ;
277
tp->timer.function = tms380tr_timer_end_wait;
278
tp->timer.data = (unsigned long)dev;
279
add_timer(&tp->timer);
281
printk(KERN_DEBUG "%s: Adapter RAM size: %dK\n",
282
dev->name, tms380tr_read_ptr(dev));
284
tms380tr_enable_interrupts(dev);
285
tms380tr_open_adapter(dev);
287
netif_start_queue(dev);
289
/* Wait for interrupt from hardware. If interrupt does not come,
290
* there will be a timeout from the timer.
293
interruptible_sleep_on(&tp->wait_for_tok_int);
294
del_timer(&tp->timer);
296
/* If AdapterVirtOpenFlag is 1, the adapter is now open for use */
297
if(tp->AdapterVirtOpenFlag == 0)
299
tms380tr_disable_interrupts(dev);
303
tp->StartTime = jiffies;
305
/* Start function control timer */
306
tp->timer.expires = jiffies + 2*HZ;
307
tp->timer.function = tms380tr_timer_chk;
308
tp->timer.data = (unsigned long)dev;
309
add_timer(&tp->timer);
315
* Timeout function while waiting for event
317
static void tms380tr_timer_end_wait(unsigned long data)
319
struct net_device *dev = (struct net_device*)data;
320
struct net_local *tp = netdev_priv(dev);
325
wake_up_interruptible(&tp->wait_for_tok_int);
330
* Initialize the chipset
332
static int tms380tr_chipset_init(struct net_device *dev)
334
struct net_local *tp = netdev_priv(dev);
337
tms380tr_init_ipb(tp);
338
tms380tr_init_opb(dev);
339
tms380tr_init_net_local(dev);
341
if(tms380tr_debug > 3)
342
printk(KERN_DEBUG "%s: Resetting adapter...\n", dev->name);
343
err = tms380tr_reset_adapter(dev);
347
if(tms380tr_debug > 3)
348
printk(KERN_DEBUG "%s: Bringup diags...\n", dev->name);
349
err = tms380tr_bringup_diags(dev);
353
if(tms380tr_debug > 3)
354
printk(KERN_DEBUG "%s: Init adapter...\n", dev->name);
355
err = tms380tr_init_adapter(dev);
359
if(tms380tr_debug > 3)
360
printk(KERN_DEBUG "%s: Done!\n", dev->name);
365
* Initializes the net_local structure.
367
static void tms380tr_init_net_local(struct net_device *dev)
369
struct net_local *tp = netdev_priv(dev);
384
tp->AdapterOpenFlag = 0;
385
tp->AdapterVirtOpenFlag = 0;
387
tp->OpenCommandIssued = 0;
388
tp->ReOpenInProgress = 0;
389
tp->HaltInProgress = 0;
390
tp->TransmitHaltScheduled = 0;
391
tp->LobeWireFaultLogged = 0;
392
tp->LastOpenStatus = 0;
393
tp->MaxPacketSize = DEFAULT_PACKET_SIZE;
395
/* Create circular chain of transmit lists */
396
for (i = 0; i < TPL_NUM; i++)
398
tp->Tpl[i].NextTPLAddr = htonl(((char *)(&tp->Tpl[(i+1) % TPL_NUM]) - (char *)tp) + tp->dmabuffer); /* DMA buffer may be MMU driven */
399
tp->Tpl[i].Status = 0;
400
tp->Tpl[i].FrameSize = 0;
401
tp->Tpl[i].FragList[0].DataCount = 0;
402
tp->Tpl[i].FragList[0].DataAddr = 0;
403
tp->Tpl[i].NextTPLPtr = &tp->Tpl[(i+1) % TPL_NUM];
404
tp->Tpl[i].MData = NULL;
405
tp->Tpl[i].TPLIndex = i;
406
tp->Tpl[i].DMABuff = 0;
407
tp->Tpl[i].BusyFlag = 0;
410
tp->TplFree = tp->TplBusy = &tp->Tpl[0];
412
/* Create circular chain of receive lists */
413
for (i = 0; i < RPL_NUM; i++)
415
tp->Rpl[i].NextRPLAddr = htonl(((char *)(&tp->Rpl[(i+1) % RPL_NUM]) - (char *)tp) + tp->dmabuffer); /* DMA buffer may be MMU driven */
416
tp->Rpl[i].Status = (RX_VALID | RX_START_FRAME | RX_END_FRAME | RX_FRAME_IRQ);
417
tp->Rpl[i].FrameSize = 0;
418
tp->Rpl[i].FragList[0].DataCount = cpu_to_be16((unsigned short)tp->MaxPacketSize);
420
/* Alloc skb and point adapter to data area */
421
tp->Rpl[i].Skb = dev_alloc_skb(tp->MaxPacketSize);
422
tp->Rpl[i].DMABuff = 0;
424
/* skb == NULL ? then use local buffer */
425
if(tp->Rpl[i].Skb == NULL)
427
tp->Rpl[i].SkbStat = SKB_UNAVAILABLE;
428
tp->Rpl[i].FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[i] - (char *)tp) + tp->dmabuffer);
429
tp->Rpl[i].MData = tp->LocalRxBuffers[i];
431
else /* SKB != NULL */
433
tp->Rpl[i].Skb->dev = dev;
434
skb_put(tp->Rpl[i].Skb, tp->MaxPacketSize);
436
/* data unreachable for DMA ? then use local buffer */
437
dmabuf = dma_map_single(tp->pdev, tp->Rpl[i].Skb->data, tp->MaxPacketSize, DMA_FROM_DEVICE);
438
if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit))
440
tp->Rpl[i].SkbStat = SKB_DATA_COPY;
441
tp->Rpl[i].FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[i] - (char *)tp) + tp->dmabuffer);
442
tp->Rpl[i].MData = tp->LocalRxBuffers[i];
444
else /* DMA directly in skb->data */
446
tp->Rpl[i].SkbStat = SKB_DMA_DIRECT;
447
tp->Rpl[i].FragList[0].DataAddr = htonl(dmabuf);
448
tp->Rpl[i].MData = tp->Rpl[i].Skb->data;
449
tp->Rpl[i].DMABuff = dmabuf;
453
tp->Rpl[i].NextRPLPtr = &tp->Rpl[(i+1) % RPL_NUM];
454
tp->Rpl[i].RPLIndex = i;
457
tp->RplHead = &tp->Rpl[0];
458
tp->RplTail = &tp->Rpl[RPL_NUM-1];
459
tp->RplTail->Status = (RX_START_FRAME | RX_END_FRAME | RX_FRAME_IRQ);
463
* Initializes the initialisation parameter block.
465
static void tms380tr_init_ipb(struct net_local *tp)
467
tp->ipb.Init_Options = BURST_MODE;
468
tp->ipb.CMD_Status_IV = 0;
471
tp->ipb.Ring_Status_IV = 0;
472
tp->ipb.SCB_Clear_IV = 0;
473
tp->ipb.Adapter_CHK_IV = 0;
474
tp->ipb.RX_Burst_Size = BURST_SIZE;
475
tp->ipb.TX_Burst_Size = BURST_SIZE;
476
tp->ipb.DMA_Abort_Thrhld = DMA_RETRIES;
477
tp->ipb.SCB_Addr = 0;
478
tp->ipb.SSB_Addr = 0;
482
* Initializes the open parameter block.
484
static void tms380tr_init_opb(struct net_device *dev)
486
struct net_local *tp;
488
unsigned short RplSize = RPL_SIZE;
489
unsigned short TplSize = TPL_SIZE;
490
unsigned short BufferSize = BUFFER_SIZE;
493
tp = netdev_priv(dev);
495
tp->ocpl.OPENOptions = 0;
496
tp->ocpl.OPENOptions |= ENABLE_FULL_DUPLEX_SELECTION;
497
tp->ocpl.FullDuplex = 0;
498
tp->ocpl.FullDuplex |= OPEN_FULL_DUPLEX_OFF;
503
* We go ahead and put it in the OPB even though on
504
* most of the generic adapters this isn't required.
505
* Its simpler this way. -- ASF
508
tp->ocpl.NodeAddr[i] = ((unsigned char *)dev->dev_addr)[i];
510
tp->ocpl.GroupAddr = 0;
511
tp->ocpl.FunctAddr = 0;
512
tp->ocpl.RxListSize = cpu_to_be16((unsigned short)RplSize);
513
tp->ocpl.TxListSize = cpu_to_be16((unsigned short)TplSize);
514
tp->ocpl.BufSize = cpu_to_be16((unsigned short)BufferSize);
515
tp->ocpl.Reserved = 0;
516
tp->ocpl.TXBufMin = TX_BUF_MIN;
517
tp->ocpl.TXBufMax = TX_BUF_MAX;
519
Addr = htonl(((char *)tp->ProductID - (char *)tp) + tp->dmabuffer);
521
tp->ocpl.ProdIDAddr[0] = LOWORD(Addr);
522
tp->ocpl.ProdIDAddr[1] = HIWORD(Addr);
526
* Send OPEN command to adapter
528
static void tms380tr_open_adapter(struct net_device *dev)
530
struct net_local *tp = netdev_priv(dev);
532
if(tp->OpenCommandIssued)
535
tp->OpenCommandIssued = 1;
536
tms380tr_exec_cmd(dev, OC_OPEN);
540
* Clear the adapter's interrupt flag. Clear system interrupt enable
541
* (SINTEN): disable adapter to system interrupts.
543
static void tms380tr_disable_interrupts(struct net_device *dev)
545
SIFWRITEB(0, SIFACL);
549
* Set the adapter's interrupt flag. Set system interrupt enable
550
* (SINTEN): enable adapter to system interrupts.
552
static void tms380tr_enable_interrupts(struct net_device *dev)
554
SIFWRITEB(ACL_SINTEN, SIFACL);
558
* Put command in command queue, try to execute it.
560
static void tms380tr_exec_cmd(struct net_device *dev, unsigned short Command)
562
struct net_local *tp = netdev_priv(dev);
564
tp->CMDqueue |= Command;
565
tms380tr_chk_outstanding_cmds(dev);
568
static void tms380tr_timeout(struct net_device *dev)
571
* If we get here, some higher level has decided we are broken.
572
* There should really be a "kick me" function call instead.
574
* Resetting the token ring adapter takes a long time so just
575
* fake transmission time and go on trying. Our own timeout
576
* routine is in tms380tr_timer_chk()
578
dev->trans_start = jiffies; /* prevent tx timeout */
579
netif_wake_queue(dev);
583
* Gets skb from system, queues it and checks if it can be sent
585
static netdev_tx_t tms380tr_send_packet(struct sk_buff *skb,
586
struct net_device *dev)
588
struct net_local *tp = netdev_priv(dev);
591
rc = tms380tr_hardware_send_packet(skb, dev);
592
if(tp->TplFree->NextTPLPtr->BusyFlag)
593
netif_stop_queue(dev);
598
* Move frames into adapter tx queue
600
static netdev_tx_t tms380tr_hardware_send_packet(struct sk_buff *skb,
601
struct net_device *dev)
608
dma_addr_t dmabuf, newbuf;
609
struct net_local *tp = netdev_priv(dev);
611
/* Try to get a free TPL from the chain.
613
* NOTE: We *must* always leave one unused TPL in the chain,
614
* because otherwise the adapter might send frames twice.
616
spin_lock_irqsave(&tp->lock, flags);
617
if(tp->TplFree->NextTPLPtr->BusyFlag) { /* No free TPL */
618
if (tms380tr_debug > 0)
619
printk(KERN_DEBUG "%s: No free TPL\n", dev->name);
620
spin_unlock_irqrestore(&tp->lock, flags);
621
return NETDEV_TX_BUSY;
626
/* Is buffer reachable for Busmaster-DMA? */
629
dmabuf = dma_map_single(tp->pdev, skb->data, length, DMA_TO_DEVICE);
630
if(tp->dmalimit && (dmabuf + length > tp->dmalimit)) {
631
/* Copy frame to local buffer */
632
dma_unmap_single(tp->pdev, dmabuf, length, DMA_TO_DEVICE);
634
i = tp->TplFree->TPLIndex;
635
buf = tp->LocalTxBuffers[i];
636
skb_copy_from_linear_data(skb, buf, length);
637
newbuf = ((char *)buf - (char *)tp) + tp->dmabuffer;
640
/* Send direct from skb->data */
644
/* Source address in packet? */
645
tms380tr_chk_src_addr(buf, dev->dev_addr);
646
tp->LastSendTime = jiffies;
647
tpl = tp->TplFree; /* Get the "free" TPL */
648
tpl->BusyFlag = 1; /* Mark TPL as busy */
649
tp->TplFree = tpl->NextTPLPtr;
651
/* Save the skb for delayed return of skb to system */
653
tpl->DMABuff = dmabuf;
654
tpl->FragList[0].DataCount = cpu_to_be16((unsigned short)length);
655
tpl->FragList[0].DataAddr = htonl(newbuf);
657
/* Write the data length in the transmit list. */
658
tpl->FrameSize = cpu_to_be16((unsigned short)length);
661
/* Transmit the frame and set the status values. */
662
tms380tr_write_tpl_status(tpl, TX_VALID | TX_START_FRAME
663
| TX_END_FRAME | TX_PASS_SRC_ADDR
666
/* Let adapter send the frame. */
667
tms380tr_exec_sifcmd(dev, CMD_TX_VALID);
668
spin_unlock_irqrestore(&tp->lock, flags);
674
* Write the given value to the 'Status' field of the specified TPL.
675
* NOTE: This function should be used whenever the status of any TPL must be
676
* modified by the driver, because the compiler may otherwise change the
677
* order of instructions such that writing the TPL status may be executed at
678
* an undesirable time. When this function is used, the status is always
679
* written when the function is called.
681
static void tms380tr_write_tpl_status(TPL *tpl, unsigned int Status)
683
tpl->Status = Status;
686
static void tms380tr_chk_src_addr(unsigned char *frame, unsigned char *hw_addr)
690
if((((unsigned long)frame[8]) & ~0x80) != 0) /* Compare 4 bytes */
692
if((unsigned short)frame[12] != 0) /* Compare 2 bytes */
695
SRBit = frame[8] & 0x80;
696
memcpy(&frame[8], hw_addr, 6);
701
* The timer routine: Check if adapter still open and working, reopen if not.
703
static void tms380tr_timer_chk(unsigned long data)
705
struct net_device *dev = (struct net_device*)data;
706
struct net_local *tp = netdev_priv(dev);
708
if(tp->HaltInProgress)
711
tms380tr_chk_outstanding_cmds(dev);
712
if(time_before(tp->LastSendTime + SEND_TIMEOUT, jiffies) &&
713
(tp->TplFree != tp->TplBusy))
715
/* Anything to send, but stalled too long */
716
tp->LastSendTime = jiffies;
717
tms380tr_exec_cmd(dev, OC_CLOSE); /* Does reopen automatically */
720
tp->timer.expires = jiffies + 2*HZ;
721
add_timer(&tp->timer);
723
if(tp->AdapterOpenFlag || tp->ReOpenInProgress)
725
tp->ReOpenInProgress = 1;
726
tms380tr_open_adapter(dev);
730
* The typical workload of the driver: Handle the network interface interrupts.
732
irqreturn_t tms380tr_interrupt(int irq, void *dev_id)
734
struct net_device *dev = dev_id;
735
struct net_local *tp;
736
unsigned short irq_type;
739
tp = netdev_priv(dev);
741
irq_type = SIFREADW(SIFSTS);
743
while(irq_type & STS_SYSTEM_IRQ) {
745
irq_type &= STS_IRQ_MASK;
747
if(!tms380tr_chk_ssb(tp, irq_type)) {
748
printk(KERN_DEBUG "%s: DATA LATE occurred\n", dev->name);
753
case STS_IRQ_RECEIVE_STATUS:
754
tms380tr_reset_interrupt(dev);
755
tms380tr_rcv_status_irq(dev);
758
case STS_IRQ_TRANSMIT_STATUS:
759
/* Check if TRANSMIT.HALT command is complete */
760
if(tp->ssb.Parm[0] & COMMAND_COMPLETE) {
761
tp->TransmitCommandActive = 0;
762
tp->TransmitHaltScheduled = 0;
764
/* Issue a new transmit command. */
765
tms380tr_exec_cmd(dev, OC_TRANSMIT);
768
tms380tr_reset_interrupt(dev);
769
tms380tr_tx_status_irq(dev);
772
case STS_IRQ_COMMAND_STATUS:
773
/* The SSB contains status of last command
774
* other than receive/transmit.
776
tms380tr_cmd_status_irq(dev);
779
case STS_IRQ_SCB_CLEAR:
780
/* The SCB is free for another command. */
782
tms380tr_chk_outstanding_cmds(dev);
785
case STS_IRQ_RING_STATUS:
786
tms380tr_ring_status_irq(dev);
789
case STS_IRQ_ADAPTER_CHECK:
790
tms380tr_chk_irq(dev);
793
case STS_IRQ_LLC_STATUS:
794
printk(KERN_DEBUG "tms380tr: unexpected LLC status IRQ\n");
798
printk(KERN_DEBUG "tms380tr: unexpected Timer IRQ\n");
801
case STS_IRQ_RECEIVE_PENDING:
802
printk(KERN_DEBUG "tms380tr: unexpected Receive Pending IRQ\n");
806
printk(KERN_DEBUG "Unknown Token Ring IRQ (0x%04x)\n", irq_type);
810
/* Reset system interrupt if not already done. */
811
if(irq_type != STS_IRQ_TRANSMIT_STATUS &&
812
irq_type != STS_IRQ_RECEIVE_STATUS) {
813
tms380tr_reset_interrupt(dev);
816
irq_type = SIFREADW(SIFSTS);
819
return IRQ_RETVAL(handled);
823
* Reset the INTERRUPT SYSTEM bit and issue SSB CLEAR command.
825
static void tms380tr_reset_interrupt(struct net_device *dev)
827
struct net_local *tp = netdev_priv(dev);
831
* [Workaround for "Data Late"]
832
* Set all fields of the SSB to well-defined values so we can
833
* check if the adapter has written the SSB.
836
ssb->STS = (unsigned short) -1;
837
ssb->Parm[0] = (unsigned short) -1;
838
ssb->Parm[1] = (unsigned short) -1;
839
ssb->Parm[2] = (unsigned short) -1;
841
/* Free SSB by issuing SSB_CLEAR command after reading IRQ code
842
* and clear STS_SYSTEM_IRQ bit: enable adapter for further interrupts.
844
tms380tr_exec_sifcmd(dev, CMD_SSB_CLEAR | CMD_CLEAR_SYSTEM_IRQ);
848
* Check if the SSB has actually been written by the adapter.
850
static unsigned char tms380tr_chk_ssb(struct net_local *tp, unsigned short IrqType)
852
SSB *ssb = &tp->ssb; /* The address of the SSB. */
854
/* C 0 1 2 INTERRUPT CODE
855
* - - - - --------------
856
* 1 1 1 1 TRANSMIT STATUS
857
* 1 1 1 1 RECEIVE STATUS
858
* 1 ? ? 0 COMMAND STATUS
860
* 1 1 0 0 RING STATUS
861
* 0 0 0 0 ADAPTER CHECK
863
* 0 = SSB field not affected by interrupt
864
* 1 = SSB field is affected by interrupt
866
* C = SSB ADDRESS +0: COMMAND
867
* 0 = SSB ADDRESS +2: STATUS 0
868
* 1 = SSB ADDRESS +4: STATUS 1
869
* 2 = SSB ADDRESS +6: STATUS 2
872
/* Check if this interrupt does use the SSB. */
874
if(IrqType != STS_IRQ_TRANSMIT_STATUS &&
875
IrqType != STS_IRQ_RECEIVE_STATUS &&
876
IrqType != STS_IRQ_COMMAND_STATUS &&
877
IrqType != STS_IRQ_RING_STATUS)
879
return 1; /* SSB not involved. */
882
/* Note: All fields of the SSB have been set to all ones (-1) after it
883
* has last been used by the software (see DriverIsr()).
885
* Check if the affected SSB fields are still unchanged.
888
if(ssb->STS == (unsigned short) -1)
889
return 0; /* Command field not yet available. */
890
if(IrqType == STS_IRQ_COMMAND_STATUS)
891
return 1; /* Status fields not always affected. */
892
if(ssb->Parm[0] == (unsigned short) -1)
893
return 0; /* Status 1 field not yet available. */
894
if(IrqType == STS_IRQ_RING_STATUS)
895
return 1; /* Status 2 & 3 fields not affected. */
897
/* Note: At this point, the interrupt is either TRANSMIT or RECEIVE. */
898
if(ssb->Parm[1] == (unsigned short) -1)
899
return 0; /* Status 2 field not yet available. */
900
if(ssb->Parm[2] == (unsigned short) -1)
901
return 0; /* Status 3 field not yet available. */
903
return 1; /* All SSB fields have been written by the adapter. */
907
* Evaluates the command results status in the SSB status field.
909
static void tms380tr_cmd_status_irq(struct net_device *dev)
911
struct net_local *tp = netdev_priv(dev);
912
unsigned short ssb_cmd, ssb_parm_0;
913
unsigned short ssb_parm_1;
914
char *open_err = "Open error -";
915
char *code_err = "Open code -";
917
/* Copy the ssb values to local variables */
918
ssb_cmd = tp->ssb.STS;
919
ssb_parm_0 = tp->ssb.Parm[0];
920
ssb_parm_1 = tp->ssb.Parm[1];
925
if(!tp->ReOpenInProgress)
926
wake_up_interruptible(&tp->wait_for_tok_int);
928
tp->OpenCommandIssued = 0;
931
if((ssb_parm_0 & 0x00FF) == GOOD_COMPLETION)
933
/* Success, the adapter is open. */
934
tp->LobeWireFaultLogged = 0;
935
tp->AdapterOpenFlag = 1;
936
tp->AdapterVirtOpenFlag = 1;
937
tp->TransmitCommandActive = 0;
938
tms380tr_exec_cmd(dev, OC_TRANSMIT);
939
tms380tr_exec_cmd(dev, OC_RECEIVE);
941
if(tp->ReOpenInProgress)
942
tp->ReOpenInProgress = 0;
946
else /* The adapter did not open. */
948
if(ssb_parm_0 & NODE_ADDR_ERROR)
949
printk(KERN_INFO "%s: Node address error\n",
951
if(ssb_parm_0 & LIST_SIZE_ERROR)
952
printk(KERN_INFO "%s: List size error\n",
954
if(ssb_parm_0 & BUF_SIZE_ERROR)
955
printk(KERN_INFO "%s: Buffer size error\n",
957
if(ssb_parm_0 & TX_BUF_COUNT_ERROR)
958
printk(KERN_INFO "%s: Tx buffer count error\n",
960
if(ssb_parm_0 & INVALID_OPEN_OPTION)
961
printk(KERN_INFO "%s: Invalid open option\n",
963
if(ssb_parm_0 & OPEN_ERROR)
965
/* Show the open phase. */
966
switch(ssb_parm_0 & OPEN_PHASES_MASK)
968
case LOBE_MEDIA_TEST:
969
if(!tp->LobeWireFaultLogged)
971
tp->LobeWireFaultLogged = 1;
972
printk(KERN_INFO "%s: %s Lobe wire fault (check cable !).\n", dev->name, open_err);
974
tp->ReOpenInProgress = 1;
975
tp->AdapterOpenFlag = 0;
976
tp->AdapterVirtOpenFlag = 1;
977
tms380tr_open_adapter(dev);
980
case PHYSICAL_INSERTION:
981
printk(KERN_INFO "%s: %s Physical insertion.\n", dev->name, open_err);
984
case ADDRESS_VERIFICATION:
985
printk(KERN_INFO "%s: %s Address verification.\n", dev->name, open_err);
988
case PARTICIPATION_IN_RING_POLL:
989
printk(KERN_INFO "%s: %s Participation in ring poll.\n", dev->name, open_err);
992
case REQUEST_INITIALISATION:
993
printk(KERN_INFO "%s: %s Request initialisation.\n", dev->name, open_err);
996
case FULLDUPLEX_CHECK:
997
printk(KERN_INFO "%s: %s Full duplex check.\n", dev->name, open_err);
1001
printk(KERN_INFO "%s: %s Unknown open phase\n", dev->name, open_err);
1005
/* Show the open errors. */
1006
switch(ssb_parm_0 & OPEN_ERROR_CODES_MASK)
1008
case OPEN_FUNCTION_FAILURE:
1009
printk(KERN_INFO "%s: %s OPEN_FUNCTION_FAILURE", dev->name, code_err);
1010
tp->LastOpenStatus =
1011
OPEN_FUNCTION_FAILURE;
1014
case OPEN_SIGNAL_LOSS:
1015
printk(KERN_INFO "%s: %s OPEN_SIGNAL_LOSS\n", dev->name, code_err);
1016
tp->LastOpenStatus =
1021
printk(KERN_INFO "%s: %s OPEN_TIMEOUT\n", dev->name, code_err);
1022
tp->LastOpenStatus =
1026
case OPEN_RING_FAILURE:
1027
printk(KERN_INFO "%s: %s OPEN_RING_FAILURE\n", dev->name, code_err);
1028
tp->LastOpenStatus =
1032
case OPEN_RING_BEACONING:
1033
printk(KERN_INFO "%s: %s OPEN_RING_BEACONING\n", dev->name, code_err);
1034
tp->LastOpenStatus =
1035
OPEN_RING_BEACONING;
1038
case OPEN_DUPLICATE_NODEADDR:
1039
printk(KERN_INFO "%s: %s OPEN_DUPLICATE_NODEADDR\n", dev->name, code_err);
1040
tp->LastOpenStatus =
1041
OPEN_DUPLICATE_NODEADDR;
1044
case OPEN_REQUEST_INIT:
1045
printk(KERN_INFO "%s: %s OPEN_REQUEST_INIT\n", dev->name, code_err);
1046
tp->LastOpenStatus =
1050
case OPEN_REMOVE_RECEIVED:
1051
printk(KERN_INFO "%s: %s OPEN_REMOVE_RECEIVED", dev->name, code_err);
1052
tp->LastOpenStatus =
1053
OPEN_REMOVE_RECEIVED;
1056
case OPEN_FULLDUPLEX_SET:
1057
printk(KERN_INFO "%s: %s OPEN_FULLDUPLEX_SET\n", dev->name, code_err);
1058
tp->LastOpenStatus =
1059
OPEN_FULLDUPLEX_SET;
1063
printk(KERN_INFO "%s: %s Unknown open err code", dev->name, code_err);
1064
tp->LastOpenStatus =
1065
OPEN_FUNCTION_FAILURE;
1070
tp->AdapterOpenFlag = 0;
1071
tp->AdapterVirtOpenFlag = 0;
1078
if(ssb_cmd != READ_ERROR_LOG)
1081
/* Add values from the error log table to the MAC
1082
* statistics counters and update the errorlogtable
1085
tp->MacStat.line_errors += tp->errorlogtable.Line_Error;
1086
tp->MacStat.burst_errors += tp->errorlogtable.Burst_Error;
1087
tp->MacStat.A_C_errors += tp->errorlogtable.ARI_FCI_Error;
1088
tp->MacStat.lost_frames += tp->errorlogtable.Lost_Frame_Error;
1089
tp->MacStat.recv_congest_count += tp->errorlogtable.Rx_Congest_Error;
1090
tp->MacStat.rx_errors += tp->errorlogtable.Rx_Congest_Error;
1091
tp->MacStat.frame_copied_errors += tp->errorlogtable.Frame_Copied_Error;
1092
tp->MacStat.token_errors += tp->errorlogtable.Token_Error;
1093
tp->MacStat.dummy1 += tp->errorlogtable.DMA_Bus_Error;
1094
tp->MacStat.dummy1 += tp->errorlogtable.DMA_Parity_Error;
1095
tp->MacStat.abort_delimiters += tp->errorlogtable.AbortDelimeters;
1096
tp->MacStat.frequency_errors += tp->errorlogtable.Frequency_Error;
1097
tp->MacStat.internal_errors += tp->errorlogtable.Internal_Error;
1102
* The inverse routine to tms380tr_open().
1104
int tms380tr_close(struct net_device *dev)
1106
struct net_local *tp = netdev_priv(dev);
1107
netif_stop_queue(dev);
1109
del_timer(&tp->timer);
1111
/* Flush the Tx and disable Rx here. */
1113
tp->HaltInProgress = 1;
1114
tms380tr_exec_cmd(dev, OC_CLOSE);
1115
tp->timer.expires = jiffies + 1*HZ;
1116
tp->timer.function = tms380tr_timer_end_wait;
1117
tp->timer.data = (unsigned long)dev;
1118
add_timer(&tp->timer);
1120
tms380tr_enable_interrupts(dev);
1123
interruptible_sleep_on(&tp->wait_for_tok_int);
1124
tp->TransmitCommandActive = 0;
1126
del_timer(&tp->timer);
1127
tms380tr_disable_interrupts(dev);
1132
unsigned long flags=claim_dma_lock();
1133
disable_dma(dev->dma);
1134
release_dma_lock(flags);
1138
SIFWRITEW(0xFF00, SIFCMD);
1140
if(dev->dma > 0) /* what the? */
1141
SIFWRITEB(0xff, POSREG);
1143
tms380tr_cancel_tx_queue(tp);
1149
* Get the current statistics. This may be called with the card open
1152
static struct net_device_stats *tms380tr_get_stats(struct net_device *dev)
1154
struct net_local *tp = netdev_priv(dev);
1156
return (struct net_device_stats *)&tp->MacStat;
1160
* Set or clear the multicast filter for this adapter.
1162
static void tms380tr_set_multicast_list(struct net_device *dev)
1164
struct net_local *tp = netdev_priv(dev);
1165
unsigned int OpenOptions;
1167
OpenOptions = tp->ocpl.OPENOptions &
1168
~(PASS_ADAPTER_MAC_FRAMES
1169
| PASS_ATTENTION_FRAMES
1170
| PASS_BEACON_MAC_FRAMES
1171
| COPY_ALL_MAC_FRAMES
1172
| COPY_ALL_NON_MAC_FRAMES);
1174
tp->ocpl.FunctAddr = 0;
1176
if(dev->flags & IFF_PROMISC)
1177
/* Enable promiscuous mode */
1178
OpenOptions |= COPY_ALL_NON_MAC_FRAMES |
1179
COPY_ALL_MAC_FRAMES;
1182
if(dev->flags & IFF_ALLMULTI)
1184
/* Disable promiscuous mode, use normal mode. */
1185
tp->ocpl.FunctAddr = 0xFFFFFFFF;
1189
struct netdev_hw_addr *ha;
1191
netdev_for_each_mc_addr(ha, dev) {
1192
((char *)(&tp->ocpl.FunctAddr))[0] |=
1194
((char *)(&tp->ocpl.FunctAddr))[1] |=
1196
((char *)(&tp->ocpl.FunctAddr))[2] |=
1198
((char *)(&tp->ocpl.FunctAddr))[3] |=
1202
tms380tr_exec_cmd(dev, OC_SET_FUNCT_ADDR);
1205
tp->ocpl.OPENOptions = OpenOptions;
1206
tms380tr_exec_cmd(dev, OC_MODIFY_OPEN_PARMS);
1210
* Wait for some time (microseconds)
1212
void tms380tr_wait(unsigned long time)
1217
tmp = jiffies + time/(1000000/HZ);
1219
tmp = schedule_timeout_interruptible(tmp);
1220
} while(time_after(tmp, jiffies));
1222
mdelay(time / 1000);
1227
* Write a command value to the SIFCMD register
1229
static void tms380tr_exec_sifcmd(struct net_device *dev, unsigned int WriteValue)
1232
unsigned short SifStsValue;
1233
unsigned long loop_counter;
1235
WriteValue = ((WriteValue ^ CMD_SYSTEM_IRQ) | CMD_INTERRUPT_ADAPTER);
1236
cmd = (unsigned short)WriteValue;
1237
loop_counter = 0,5 * 800000;
1239
SifStsValue = SIFREADW(SIFSTS);
1240
} while((SifStsValue & CMD_INTERRUPT_ADAPTER) && loop_counter--);
1241
SIFWRITEW(cmd, SIFCMD);
1245
* Processes adapter hardware reset, halts adapter and downloads firmware,
1246
* clears the halt bit.
1248
static int tms380tr_reset_adapter(struct net_device *dev)
1250
struct net_local *tp = netdev_priv(dev);
1251
unsigned short *fw_ptr;
1252
unsigned short count, c, count2;
1253
const struct firmware *fw_entry = NULL;
1255
if (request_firmware(&fw_entry, "tms380tr.bin", tp->pdev) != 0) {
1256
printk(KERN_ALERT "%s: firmware %s is missing, cannot start.\n",
1257
dev->name, "tms380tr.bin");
1261
fw_ptr = (unsigned short *)fw_entry->data;
1262
count2 = fw_entry->size / 2;
1264
/* Hardware adapter reset */
1265
SIFWRITEW(ACL_ARESET, SIFACL);
1268
c = SIFREADW(SIFACL);
1271
if(dev->dma == 0) /* For PCI adapters */
1273
c &= ~(ACL_NSELOUT0 | ACL_NSELOUT1); /* Clear bits */
1275
c |= (*tp->setnselout)(dev);
1278
/* In case a command is pending - forget it */
1281
c &= ~ACL_ARESET; /* Clear adapter reset bit */
1282
c |= ACL_CPHALT; /* Halt adapter CPU, allow download */
1285
c &= ~ACL_PSDMAEN; /* Clear pseudo dma bit */
1286
SIFWRITEW(c, SIFACL);
1290
/* Download firmware via DIO interface: */
1292
if (count2 < 3) continue;
1294
/* Download first address part */
1295
SIFWRITEW(*fw_ptr, SIFADX);
1298
/* Download second address part */
1299
SIFWRITEW(*fw_ptr, SIFADD);
1303
if((count = *fw_ptr) != 0) /* Load loop counter */
1305
fw_ptr++; /* Download block data */
1307
if (count > count2) continue;
1309
for(; count > 0; count--)
1311
SIFWRITEW(*fw_ptr, SIFINC);
1316
else /* Stop, if last block downloaded */
1318
c = SIFREADW(SIFACL);
1319
c &= (~ACL_CPHALT | ACL_SINTEN);
1321
/* Clear CPHALT and start BUD */
1322
SIFWRITEW(c, SIFACL);
1323
release_firmware(fw_entry);
1326
} while(count == 0);
1328
release_firmware(fw_entry);
1329
printk(KERN_INFO "%s: Adapter Download Failed\n", dev->name);
1333
MODULE_FIRMWARE("tms380tr.bin");
1336
* Starts bring up diagnostics of token ring adapter and evaluates
1337
* diagnostic results.
1339
static int tms380tr_bringup_diags(struct net_device *dev)
1341
int loop_cnt, retry_cnt;
1342
unsigned short Status;
1344
tms380tr_wait(HALF_SECOND);
1345
tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
1346
tms380tr_wait(HALF_SECOND);
1348
retry_cnt = BUD_MAX_RETRIES; /* maximal number of retrys */
1352
if(tms380tr_debug > 3)
1353
printk(KERN_DEBUG "BUD-Status: ");
1354
loop_cnt = BUD_MAX_LOOPCNT; /* maximum: three seconds*/
1355
do { /* Inspect BUD results */
1357
tms380tr_wait(HALF_SECOND);
1358
Status = SIFREADW(SIFSTS);
1361
if(tms380tr_debug > 3)
1362
printk(KERN_DEBUG " %04X\n", Status);
1363
/* BUD successfully completed */
1364
if(Status == STS_INITIALIZE)
1366
/* Unrecoverable hardware error, BUD not completed? */
1367
} while((loop_cnt > 0) && ((Status & (STS_ERROR | STS_TEST))
1368
!= (STS_ERROR | STS_TEST)));
1370
/* Error preventing completion of BUD */
1373
printk(KERN_INFO "%s: Adapter Software Reset.\n",
1375
tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
1376
tms380tr_wait(HALF_SECOND);
1378
} while(retry_cnt > 0);
1380
Status = SIFREADW(SIFSTS);
1382
printk(KERN_INFO "%s: Hardware error\n", dev->name);
1383
/* Hardware error occurred! */
1385
if (Status & 0x0010)
1386
printk(KERN_INFO "%s: BUD Error: Timeout\n", dev->name);
1387
else if ((Status & 0x000f) > 6)
1388
printk(KERN_INFO "%s: BUD Error: Illegal Failure\n", dev->name);
1390
printk(KERN_INFO "%s: Bring Up Diagnostics Error (%04X) occurred\n", dev->name, Status & 0x000f);
1396
* Copy initialisation data to adapter memory, beginning at address
1397
* 1:0A00; Starting DMA test and evaluating result bits.
1399
static int tms380tr_init_adapter(struct net_device *dev)
1401
struct net_local *tp = netdev_priv(dev);
1403
const unsigned char SCB_Test[6] = {0x00, 0x00, 0xC1, 0xE2, 0xD4, 0x8B};
1404
const unsigned char SSB_Test[8] = {0xFF, 0xFF, 0xD1, 0xD7,
1405
0xC5, 0xD9, 0xC3, 0xD4};
1406
void *ptr = (void *)&tp->ipb;
1407
unsigned short *ipb_ptr = (unsigned short *)ptr;
1408
unsigned char *cb_ptr = (unsigned char *) &tp->scb;
1409
unsigned char *sb_ptr = (unsigned char *) &tp->ssb;
1410
unsigned short Status;
1411
int i, loop_cnt, retry_cnt;
1413
/* Normalize: byte order low/high, word order high/low! (only IPB!) */
1414
tp->ipb.SCB_Addr = SWAPW(((char *)&tp->scb - (char *)tp) + tp->dmabuffer);
1415
tp->ipb.SSB_Addr = SWAPW(((char *)&tp->ssb - (char *)tp) + tp->dmabuffer);
1417
if(tms380tr_debug > 3)
1419
printk(KERN_DEBUG "%s: buffer (real): %lx\n", dev->name, (long) &tp->scb);
1420
printk(KERN_DEBUG "%s: buffer (virt): %lx\n", dev->name, (long) ((char *)&tp->scb - (char *)tp) + (long) tp->dmabuffer);
1421
printk(KERN_DEBUG "%s: buffer (DMA) : %lx\n", dev->name, (long) tp->dmabuffer);
1422
printk(KERN_DEBUG "%s: buffer (tp) : %lx\n", dev->name, (long) tp);
1424
/* Maximum: three initialization retries */
1425
retry_cnt = INIT_MAX_RETRIES;
1430
/* Transfer initialization block */
1431
SIFWRITEW(0x0001, SIFADX);
1433
/* To address 0001:0A00 of adapter RAM */
1434
SIFWRITEW(0x0A00, SIFADD);
1436
/* Write 11 words to adapter RAM */
1437
for(i = 0; i < 11; i++)
1438
SIFWRITEW(ipb_ptr[i], SIFINC);
1440
/* Execute SCB adapter command */
1441
tms380tr_exec_sifcmd(dev, CMD_EXECUTE);
1443
loop_cnt = INIT_MAX_LOOPCNT; /* Maximum: 11 seconds */
1445
/* While remaining retries, no error and not completed */
1449
tms380tr_wait(HALF_SECOND);
1451
/* Mask interesting status bits */
1452
Status = SIFREADW(SIFSTS);
1454
} while(((Status &(STS_INITIALIZE | STS_ERROR | STS_TEST)) != 0) &&
1455
((Status & STS_ERROR) == 0) && (loop_cnt != 0));
1457
if((Status & (STS_INITIALIZE | STS_ERROR | STS_TEST)) == 0)
1459
/* Initialization completed without error */
1461
do { /* Test if contents of SCB is valid */
1462
if(SCB_Test[i] != *(cb_ptr + i))
1464
printk(KERN_INFO "%s: DMA failed\n", dev->name);
1465
/* DMA data error: wrong data in SCB */
1472
do { /* Test if contents of SSB is valid */
1473
if(SSB_Test[i] != *(sb_ptr + i))
1474
/* DMA data error: wrong data in SSB */
1479
return 1; /* Adapter successfully initialized */
1483
if((Status & STS_ERROR) != 0)
1485
/* Initialization error occurred */
1486
Status = SIFREADW(SIFSTS);
1487
Status &= STS_ERROR_MASK;
1488
/* ShowInitialisationErrorCode(Status); */
1489
printk(KERN_INFO "%s: Status error: %d\n", dev->name, Status);
1490
return -1; /* Unrecoverable error */
1496
/* Reset adapter and try init again */
1497
tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
1498
tms380tr_wait(HALF_SECOND);
1502
} while(retry_cnt > 0);
1504
printk(KERN_INFO "%s: Retry exceeded\n", dev->name);
1509
* Check for outstanding commands in command queue and tries to execute
1510
* command immediately. Corresponding command flag in command queue is cleared.
1512
static void tms380tr_chk_outstanding_cmds(struct net_device *dev)
1514
struct net_local *tp = netdev_priv(dev);
1515
unsigned long Addr = 0;
1517
if(tp->CMDqueue == 0)
1518
return; /* No command execution */
1520
/* If SCB in use: no command */
1521
if(tp->ScbInUse == 1)
1524
/* Check if adapter is opened, avoiding COMMAND_REJECT
1525
* interrupt by the adapter!
1527
if (tp->AdapterOpenFlag == 0) {
1528
if (tp->CMDqueue & OC_OPEN) {
1529
/* Execute OPEN command */
1530
tp->CMDqueue ^= OC_OPEN;
1532
Addr = htonl(((char *)&tp->ocpl - (char *)tp) + tp->dmabuffer);
1533
tp->scb.Parm[0] = LOWORD(Addr);
1534
tp->scb.Parm[1] = HIWORD(Addr);
1537
/* No OPEN command queued, but adapter closed. Note:
1538
* We'll try to re-open the adapter in DriverPoll()
1540
return; /* No adapter command issued */
1542
/* Adapter is open; evaluate command queue: try to execute
1543
* outstanding commands (depending on priority!) CLOSE
1546
if (tp->CMDqueue & OC_CLOSE) {
1547
tp->CMDqueue ^= OC_CLOSE;
1548
tp->AdapterOpenFlag = 0;
1549
tp->scb.Parm[0] = 0; /* Parm[0], Parm[1] are ignored */
1550
tp->scb.Parm[1] = 0; /* but should be set to zero! */
1551
tp->scb.CMD = CLOSE;
1552
if(!tp->HaltInProgress)
1553
tp->CMDqueue |= OC_OPEN; /* re-open adapter */
1555
tp->CMDqueue = 0; /* no more commands */
1556
} else if (tp->CMDqueue & OC_RECEIVE) {
1557
tp->CMDqueue ^= OC_RECEIVE;
1558
Addr = htonl(((char *)tp->RplHead - (char *)tp) + tp->dmabuffer);
1559
tp->scb.Parm[0] = LOWORD(Addr);
1560
tp->scb.Parm[1] = HIWORD(Addr);
1561
tp->scb.CMD = RECEIVE;
1562
} else if (tp->CMDqueue & OC_TRANSMIT_HALT) {
1563
/* NOTE: TRANSMIT.HALT must be checked
1566
tp->CMDqueue ^= OC_TRANSMIT_HALT;
1567
tp->scb.CMD = TRANSMIT_HALT;
1569
/* Parm[0] and Parm[1] are ignored
1570
* but should be set to zero!
1572
tp->scb.Parm[0] = 0;
1573
tp->scb.Parm[1] = 0;
1574
} else if (tp->CMDqueue & OC_TRANSMIT) {
1575
/* NOTE: TRANSMIT must be
1576
* checked after TRANSMIT.HALT
1578
if (tp->TransmitCommandActive) {
1579
if (!tp->TransmitHaltScheduled) {
1580
tp->TransmitHaltScheduled = 1;
1581
tms380tr_exec_cmd(dev, OC_TRANSMIT_HALT);
1583
tp->TransmitCommandActive = 0;
1587
tp->CMDqueue ^= OC_TRANSMIT;
1588
tms380tr_cancel_tx_queue(tp);
1589
Addr = htonl(((char *)tp->TplBusy - (char *)tp) + tp->dmabuffer);
1590
tp->scb.Parm[0] = LOWORD(Addr);
1591
tp->scb.Parm[1] = HIWORD(Addr);
1592
tp->scb.CMD = TRANSMIT;
1593
tp->TransmitCommandActive = 1;
1594
} else if (tp->CMDqueue & OC_MODIFY_OPEN_PARMS) {
1595
tp->CMDqueue ^= OC_MODIFY_OPEN_PARMS;
1596
tp->scb.Parm[0] = tp->ocpl.OPENOptions; /* new OPEN options*/
1597
tp->scb.Parm[0] |= ENABLE_FULL_DUPLEX_SELECTION;
1598
tp->scb.Parm[1] = 0; /* is ignored but should be zero */
1599
tp->scb.CMD = MODIFY_OPEN_PARMS;
1600
} else if (tp->CMDqueue & OC_SET_FUNCT_ADDR) {
1601
tp->CMDqueue ^= OC_SET_FUNCT_ADDR;
1602
tp->scb.Parm[0] = LOWORD(tp->ocpl.FunctAddr);
1603
tp->scb.Parm[1] = HIWORD(tp->ocpl.FunctAddr);
1604
tp->scb.CMD = SET_FUNCT_ADDR;
1605
} else if (tp->CMDqueue & OC_SET_GROUP_ADDR) {
1606
tp->CMDqueue ^= OC_SET_GROUP_ADDR;
1607
tp->scb.Parm[0] = LOWORD(tp->ocpl.GroupAddr);
1608
tp->scb.Parm[1] = HIWORD(tp->ocpl.GroupAddr);
1609
tp->scb.CMD = SET_GROUP_ADDR;
1610
} else if (tp->CMDqueue & OC_READ_ERROR_LOG) {
1611
tp->CMDqueue ^= OC_READ_ERROR_LOG;
1612
Addr = htonl(((char *)&tp->errorlogtable - (char *)tp) + tp->dmabuffer);
1613
tp->scb.Parm[0] = LOWORD(Addr);
1614
tp->scb.Parm[1] = HIWORD(Addr);
1615
tp->scb.CMD = READ_ERROR_LOG;
1617
printk(KERN_WARNING "CheckForOutstandingCommand: unknown Command\n");
1623
tp->ScbInUse = 1; /* Set semaphore: SCB in use. */
1625
/* Execute SCB and generate IRQ when done. */
1626
tms380tr_exec_sifcmd(dev, CMD_EXECUTE | CMD_SCB_REQUEST);
1630
* IRQ conditions: signal loss on the ring, transmit or receive of beacon
1631
* frames (disabled if bit 1 of OPEN option is set); report error MAC
1632
* frame transmit (disabled if bit 2 of OPEN option is set); open or short
1633
* circuit fault on the lobe is detected; remove MAC frame received;
1634
* error counter overflow (255); opened adapter is the only station in ring.
1635
* After some of the IRQs the adapter is closed!
1637
static void tms380tr_ring_status_irq(struct net_device *dev)
1639
struct net_local *tp = netdev_priv(dev);
1641
tp->CurrentRingStatus = be16_to_cpu((unsigned short)tp->ssb.Parm[0]);
1643
/* First: fill up statistics */
1644
if(tp->ssb.Parm[0] & SIGNAL_LOSS)
1646
printk(KERN_INFO "%s: Signal Loss\n", dev->name);
1647
tp->MacStat.line_errors++;
1650
/* Adapter is closed, but initialized */
1651
if(tp->ssb.Parm[0] & LOBE_WIRE_FAULT)
1653
printk(KERN_INFO "%s: Lobe Wire Fault, Reopen Adapter\n",
1655
tp->MacStat.line_errors++;
1658
if(tp->ssb.Parm[0] & RING_RECOVERY)
1659
printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
1661
/* Counter overflow: read error log */
1662
if(tp->ssb.Parm[0] & COUNTER_OVERFLOW)
1664
printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
1665
tms380tr_exec_cmd(dev, OC_READ_ERROR_LOG);
1668
/* Adapter is closed, but initialized */
1669
if(tp->ssb.Parm[0] & REMOVE_RECEIVED)
1670
printk(KERN_INFO "%s: Remove Received, Reopen Adapter\n",
1673
/* Adapter is closed, but initialized */
1674
if(tp->ssb.Parm[0] & AUTO_REMOVAL_ERROR)
1675
printk(KERN_INFO "%s: Auto Removal Error, Reopen Adapter\n",
1678
if(tp->ssb.Parm[0] & HARD_ERROR)
1679
printk(KERN_INFO "%s: Hard Error\n", dev->name);
1681
if(tp->ssb.Parm[0] & SOFT_ERROR)
1682
printk(KERN_INFO "%s: Soft Error\n", dev->name);
1684
if(tp->ssb.Parm[0] & TRANSMIT_BEACON)
1685
printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
1687
if(tp->ssb.Parm[0] & SINGLE_STATION)
1688
printk(KERN_INFO "%s: Single Station\n", dev->name);
1690
/* Check if adapter has been closed */
1691
if(tp->ssb.Parm[0] & ADAPTER_CLOSED)
1693
printk(KERN_INFO "%s: Adapter closed (Reopening),"
1694
"CurrentRingStat %x\n",
1695
dev->name, tp->CurrentRingStatus);
1696
tp->AdapterOpenFlag = 0;
1697
tms380tr_open_adapter(dev);
1702
* Issued if adapter has encountered an unrecoverable hardware
1703
* or software error.
1705
static void tms380tr_chk_irq(struct net_device *dev)
1708
unsigned short AdapterCheckBlock[4];
1709
struct net_local *tp = netdev_priv(dev);
1711
tp->AdapterOpenFlag = 0; /* Adapter closed now */
1713
/* Page number of adapter memory */
1714
SIFWRITEW(0x0001, SIFADX);
1715
/* Address offset */
1716
SIFWRITEW(CHECKADDR, SIFADR);
1718
/* Reading 8 byte adapter check block. */
1719
for(i = 0; i < 4; i++)
1720
AdapterCheckBlock[i] = SIFREADW(SIFINC);
1722
if(tms380tr_debug > 3)
1724
printk(KERN_DEBUG "%s: AdapterCheckBlock: ", dev->name);
1725
for (i = 0; i < 4; i++)
1726
printk("%04X", AdapterCheckBlock[i]);
1730
switch(AdapterCheckBlock[0])
1733
printk(KERN_INFO "%s: DIO parity error\n", dev->name);
1736
case DMA_READ_ABORT:
1737
printk(KERN_INFO "%s DMA read operation aborted:\n",
1739
switch (AdapterCheckBlock[1])
1742
printk(KERN_INFO "Timeout\n");
1743
printk(KERN_INFO "Address: %04X %04X\n",
1744
AdapterCheckBlock[2],
1745
AdapterCheckBlock[3]);
1749
printk(KERN_INFO "Parity error\n");
1750
printk(KERN_INFO "Address: %04X %04X\n",
1751
AdapterCheckBlock[2],
1752
AdapterCheckBlock[3]);
1756
printk(KERN_INFO "Bus error\n");
1757
printk(KERN_INFO "Address: %04X %04X\n",
1758
AdapterCheckBlock[2],
1759
AdapterCheckBlock[3]);
1763
printk(KERN_INFO "Unknown error.\n");
1768
case DMA_WRITE_ABORT:
1769
printk(KERN_INFO "%s: DMA write operation aborted:\n",
1771
switch (AdapterCheckBlock[1])
1774
printk(KERN_INFO "Timeout\n");
1775
printk(KERN_INFO "Address: %04X %04X\n",
1776
AdapterCheckBlock[2],
1777
AdapterCheckBlock[3]);
1781
printk(KERN_INFO "Parity error\n");
1782
printk(KERN_INFO "Address: %04X %04X\n",
1783
AdapterCheckBlock[2],
1784
AdapterCheckBlock[3]);
1788
printk(KERN_INFO "Bus error\n");
1789
printk(KERN_INFO "Address: %04X %04X\n",
1790
AdapterCheckBlock[2],
1791
AdapterCheckBlock[3]);
1795
printk(KERN_INFO "Unknown error.\n");
1800
case ILLEGAL_OP_CODE:
1801
printk(KERN_INFO "%s: Illegal operation code in firmware\n",
1803
/* Parm[0-3]: adapter internal register R13-R15 */
1807
printk(KERN_INFO "%s: Adapter internal bus parity error\n",
1809
/* Parm[0-3]: adapter internal register R13-R15 */
1812
case RAM_DATA_ERROR:
1813
printk(KERN_INFO "%s: RAM data error\n", dev->name);
1814
/* Parm[0-1]: MSW/LSW address of RAM location. */
1817
case RAM_PARITY_ERROR:
1818
printk(KERN_INFO "%s: RAM parity error\n", dev->name);
1819
/* Parm[0-1]: MSW/LSW address of RAM location. */
1823
printk(KERN_INFO "%s: Internal DMA underrun detected\n",
1828
printk(KERN_INFO "%s: Unrecognized interrupt detected\n",
1830
/* Parm[0-3]: adapter internal register R13-R15 */
1833
case INVALID_ERROR_IRQ:
1834
printk(KERN_INFO "%s: Unrecognized error interrupt detected\n",
1836
/* Parm[0-3]: adapter internal register R13-R15 */
1840
printk(KERN_INFO "%s: Unrecognized XOP request detected\n",
1842
/* Parm[0-3]: adapter internal register R13-R15 */
1846
printk(KERN_INFO "%s: Unknown status", dev->name);
1850
if(tms380tr_chipset_init(dev) == 1)
1852
/* Restart of firmware successful */
1853
tp->AdapterOpenFlag = 1;
1858
* Internal adapter pointer to RAM data are copied from adapter into
1861
static int tms380tr_read_ptr(struct net_device *dev)
1863
struct net_local *tp = netdev_priv(dev);
1864
unsigned short adapterram;
1866
tms380tr_read_ram(dev, (unsigned char *)&tp->intptrs.BurnedInAddrPtr,
1867
ADAPTER_INT_PTRS, 16);
1868
tms380tr_read_ram(dev, (unsigned char *)&adapterram,
1869
cpu_to_be16((unsigned short)tp->intptrs.AdapterRAMPtr), 2);
1870
return be16_to_cpu(adapterram);
1874
* Reads a number of bytes from adapter to system memory.
1876
static void tms380tr_read_ram(struct net_device *dev, unsigned char *Data,
1877
unsigned short Address, int Length)
1880
unsigned short old_sifadx, old_sifadr, InWord;
1882
/* Save the current values */
1883
old_sifadx = SIFREADW(SIFADX);
1884
old_sifadr = SIFREADW(SIFADR);
1886
/* Page number of adapter memory */
1887
SIFWRITEW(0x0001, SIFADX);
1888
/* Address offset in adapter RAM */
1889
SIFWRITEW(Address, SIFADR);
1891
/* Copy len byte from adapter memory to system data area. */
1895
InWord = SIFREADW(SIFINC);
1897
*(Data + i) = HIBYTE(InWord); /* Write first byte */
1898
if(++i == Length) /* All is done break */
1901
*(Data + i) = LOBYTE(InWord); /* Write second byte */
1902
if (++i == Length) /* All is done break */
1906
/* Restore original values */
1907
SIFWRITEW(old_sifadx, SIFADX);
1908
SIFWRITEW(old_sifadr, SIFADR);
1912
* Cancel all queued packets in the transmission queue.
1914
static void tms380tr_cancel_tx_queue(struct net_local* tp)
1919
* NOTE: There must not be an active TRANSMIT command pending, when
1920
* this function is called.
1922
if(tp->TransmitCommandActive)
1930
/* "Remove" TPL from busy list. */
1931
tp->TplBusy = tpl->NextTPLPtr;
1932
tms380tr_write_tpl_status(tpl, 0); /* Clear VALID bit */
1933
tpl->BusyFlag = 0; /* "free" TPL */
1935
printk(KERN_INFO "Cancel tx (%08lXh).\n", (unsigned long)tpl);
1937
dma_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, DMA_TO_DEVICE);
1938
dev_kfree_skb_any(tpl->Skb);
1943
* This function is called whenever a transmit interrupt is generated by the
1944
* adapter. For a command complete interrupt, it is checked if we have to
1945
* issue a new transmit command or not.
1947
static void tms380tr_tx_status_irq(struct net_device *dev)
1949
struct net_local *tp = netdev_priv(dev);
1950
unsigned char HighByte, HighAc, LowAc;
1953
/* NOTE: At this point the SSB from TRANSMIT STATUS is no longer
1954
* available, because the CLEAR SSB command has already been issued.
1956
* Process all complete transmissions.
1962
if(!tpl->BusyFlag || (tpl->Status
1963
& (TX_VALID | TX_FRAME_COMPLETE))
1964
!= TX_FRAME_COMPLETE)
1969
/* "Remove" TPL from busy list. */
1970
tp->TplBusy = tpl->NextTPLPtr ;
1972
/* Check the transmit status field only for directed frames*/
1973
if(DIRECTED_FRAME(tpl) && (tpl->Status & TX_ERROR) == 0)
1975
HighByte = GET_TRANSMIT_STATUS_HIGH_BYTE(tpl->Status);
1976
HighAc = GET_FRAME_STATUS_HIGH_AC(HighByte);
1977
LowAc = GET_FRAME_STATUS_LOW_AC(HighByte);
1979
if((HighAc != LowAc) || (HighAc == AC_NOT_RECOGNIZED))
1981
printk(KERN_DEBUG "%s: (DA=%08lX not recognized)\n",
1983
*(unsigned long *)&tpl->MData[2+2]);
1987
if(tms380tr_debug > 3)
1988
printk(KERN_DEBUG "%s: Directed frame tx'd\n",
1994
if(!DIRECTED_FRAME(tpl))
1996
if(tms380tr_debug > 3)
1997
printk(KERN_DEBUG "%s: Broadcast frame tx'd\n",
2002
tp->MacStat.tx_packets++;
2004
dma_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, DMA_TO_DEVICE);
2005
dev_kfree_skb_irq(tpl->Skb);
2006
tpl->BusyFlag = 0; /* "free" TPL */
2009
if(!tp->TplFree->NextTPLPtr->BusyFlag)
2010
netif_wake_queue(dev);
2014
* Called if a frame receive interrupt is generated by the adapter.
2015
* Check if the frame is valid and indicate it to system.
2017
static void tms380tr_rcv_status_irq(struct net_device *dev)
2019
struct net_local *tp = netdev_priv(dev);
2020
unsigned char *ReceiveDataPtr;
2021
struct sk_buff *skb;
2022
unsigned int Length, Length2;
2027
/* NOTE: At this point the SSB from RECEIVE STATUS is no longer
2028
* available, because the CLEAR SSB command has already been issued.
2030
* Process all complete receives.
2036
if(rpl->Status & RX_VALID)
2037
break; /* RPL still in use by adapter */
2039
/* Forward RPLHead pointer to next list. */
2040
SaveHead = tp->RplHead;
2041
tp->RplHead = rpl->NextRPLPtr;
2043
/* Get the frame size (Byte swap for Intel).
2044
* Do this early (see workaround comment below)
2046
Length = be16_to_cpu(rpl->FrameSize);
2048
/* Check if the Frame_Start, Frame_End and
2049
* Frame_Complete bits are set.
2051
if((rpl->Status & VALID_SINGLE_BUFFER_FRAME)
2052
== VALID_SINGLE_BUFFER_FRAME)
2054
ReceiveDataPtr = rpl->MData;
2056
/* Workaround for delayed write of FrameSize on ISA
2057
* (FrameSize is false but valid-bit is reset)
2058
* Frame size is set to zero when the RPL is freed.
2059
* Length2 is there because there have also been
2060
* cases where the FrameSize was partially written
2062
Length2 = be16_to_cpu(rpl->FrameSize);
2064
if(Length == 0 || Length != Length2)
2066
tp->RplHead = SaveHead;
2067
break; /* Return to tms380tr_interrupt */
2069
tms380tr_update_rcv_stats(tp,ReceiveDataPtr,Length);
2071
if(tms380tr_debug > 3)
2072
printk(KERN_DEBUG "%s: Packet Length %04X (%d)\n",
2073
dev->name, Length, Length);
2075
/* Indicate the received frame to system the
2076
* adapter does the Source-Routing padding for
2077
* us. See: OpenOptions in tms380tr_init_opb()
2080
if(rpl->SkbStat == SKB_UNAVAILABLE)
2082
/* Try again to allocate skb */
2083
skb = dev_alloc_skb(tp->MaxPacketSize);
2086
/* Update Stats ?? */
2090
skb_put(skb, tp->MaxPacketSize);
2091
rpl->SkbStat = SKB_DATA_COPY;
2092
ReceiveDataPtr = rpl->MData;
2096
if(skb && (rpl->SkbStat == SKB_DATA_COPY ||
2097
rpl->SkbStat == SKB_DMA_DIRECT))
2099
if(rpl->SkbStat == SKB_DATA_COPY)
2100
skb_copy_to_linear_data(skb, ReceiveDataPtr,
2103
/* Deliver frame to system */
2105
skb_trim(skb,Length);
2106
skb->protocol = tr_type_trans(skb,dev);
2110
else /* Invalid frame */
2112
if(rpl->Skb != NULL)
2113
dev_kfree_skb_irq(rpl->Skb);
2116
if(rpl->Status & RX_START_FRAME)
2117
/* Frame start bit is set -> overflow. */
2118
tp->MacStat.rx_errors++;
2121
dma_unmap_single(tp->pdev, rpl->DMABuff, tp->MaxPacketSize, DMA_TO_DEVICE);
2124
/* Allocate new skb for rpl */
2125
rpl->Skb = dev_alloc_skb(tp->MaxPacketSize);
2126
/* skb == NULL ? then use local buffer */
2127
if(rpl->Skb == NULL)
2129
rpl->SkbStat = SKB_UNAVAILABLE;
2130
rpl->FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[rpl->RPLIndex] - (char *)tp) + tp->dmabuffer);
2131
rpl->MData = tp->LocalRxBuffers[rpl->RPLIndex];
2133
else /* skb != NULL */
2135
rpl->Skb->dev = dev;
2136
skb_put(rpl->Skb, tp->MaxPacketSize);
2138
/* Data unreachable for DMA ? then use local buffer */
2139
dmabuf = dma_map_single(tp->pdev, rpl->Skb->data, tp->MaxPacketSize, DMA_FROM_DEVICE);
2140
if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit))
2142
rpl->SkbStat = SKB_DATA_COPY;
2143
rpl->FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[rpl->RPLIndex] - (char *)tp) + tp->dmabuffer);
2144
rpl->MData = tp->LocalRxBuffers[rpl->RPLIndex];
2148
/* DMA directly in skb->data */
2149
rpl->SkbStat = SKB_DMA_DIRECT;
2150
rpl->FragList[0].DataAddr = htonl(dmabuf);
2151
rpl->MData = rpl->Skb->data;
2152
rpl->DMABuff = dmabuf;
2156
rpl->FragList[0].DataCount = cpu_to_be16((unsigned short)tp->MaxPacketSize);
2159
/* Pass the last RPL back to the adapter */
2160
tp->RplTail->FrameSize = 0;
2162
/* Reset the CSTAT field in the list. */
2163
tms380tr_write_rpl_status(tp->RplTail, RX_VALID | RX_FRAME_IRQ);
2165
/* Current RPL becomes last one in list. */
2166
tp->RplTail = tp->RplTail->NextRPLPtr;
2168
/* Inform adapter about RPL valid. */
2169
tms380tr_exec_sifcmd(dev, CMD_RX_VALID);
2174
* This function should be used whenever the status of any RPL must be
2175
* modified by the driver, because the compiler may otherwise change the
2176
* order of instructions such that writing the RPL status may be executed
2177
* at an undesirable time. When this function is used, the status is
2178
* always written when the function is called.
2180
static void tms380tr_write_rpl_status(RPL *rpl, unsigned int Status)
2182
rpl->Status = Status;
2186
* The function updates the statistic counters in mac->MacStat.
2187
* It differtiates between directed and broadcast/multicast ( ==functional)
2190
static void tms380tr_update_rcv_stats(struct net_local *tp, unsigned char DataPtr[],
2191
unsigned int Length)
2193
tp->MacStat.rx_packets++;
2194
tp->MacStat.rx_bytes += Length;
2196
/* Test functional bit */
2197
if(DataPtr[2] & GROUP_BIT)
2198
tp->MacStat.multicast++;
2201
static int tms380tr_set_mac_address(struct net_device *dev, void *addr)
2203
struct net_local *tp = netdev_priv(dev);
2204
struct sockaddr *saddr = addr;
2206
if (tp->AdapterOpenFlag || tp->AdapterVirtOpenFlag) {
2207
printk(KERN_WARNING "%s: Cannot set MAC/LAA address while card is open\n", dev->name);
2210
memcpy(dev->dev_addr, saddr->sa_data, dev->addr_len);
2214
#if TMS380TR_DEBUG > 0
2216
* Dump Packet (data)
2218
static void tms380tr_dump(unsigned char *Data, int length)
2222
for (i = 0, j = 0; i < length / 8; i++, j += 8)
2224
printk(KERN_DEBUG "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2225
Data[j+0],Data[j+1],Data[j+2],Data[j+3],
2226
Data[j+4],Data[j+5],Data[j+6],Data[j+7]);
2231
void tmsdev_term(struct net_device *dev)
2233
struct net_local *tp;
2235
tp = netdev_priv(dev);
2236
dma_unmap_single(tp->pdev, tp->dmabuffer, sizeof(struct net_local),
2240
const struct net_device_ops tms380tr_netdev_ops = {
2241
.ndo_open = tms380tr_open,
2242
.ndo_stop = tms380tr_close,
2243
.ndo_start_xmit = tms380tr_send_packet,
2244
.ndo_tx_timeout = tms380tr_timeout,
2245
.ndo_get_stats = tms380tr_get_stats,
2246
.ndo_set_rx_mode = tms380tr_set_multicast_list,
2247
.ndo_set_mac_address = tms380tr_set_mac_address,
2249
EXPORT_SYMBOL(tms380tr_netdev_ops);
2251
int tmsdev_init(struct net_device *dev, struct device *pdev)
2253
struct net_local *tms_local;
2255
memset(netdev_priv(dev), 0, sizeof(struct net_local));
2256
tms_local = netdev_priv(dev);
2257
init_waitqueue_head(&tms_local->wait_for_tok_int);
2259
tms_local->dmalimit = *pdev->dma_mask;
2262
tms_local->pdev = pdev;
2263
tms_local->dmabuffer = dma_map_single(pdev, (void *)tms_local,
2264
sizeof(struct net_local), DMA_BIDIRECTIONAL);
2265
if (tms_local->dmabuffer + sizeof(struct net_local) >
2266
tms_local->dmalimit)
2268
printk(KERN_INFO "%s: Memory not accessible for DMA\n",
2274
dev->netdev_ops = &tms380tr_netdev_ops;
2275
dev->watchdog_timeo = HZ;
2280
EXPORT_SYMBOL(tms380tr_open);
2281
EXPORT_SYMBOL(tms380tr_close);
2282
EXPORT_SYMBOL(tms380tr_interrupt);
2283
EXPORT_SYMBOL(tmsdev_init);
2284
EXPORT_SYMBOL(tmsdev_term);
2285
EXPORT_SYMBOL(tms380tr_wait);
2289
static struct module *TMS380_module = NULL;
2291
int init_module(void)
2293
printk(KERN_DEBUG "%s", version);
2295
TMS380_module = &__this_module;
2299
void cleanup_module(void)
2301
TMS380_module = NULL;
2305
MODULE_LICENSE("GPL");