blob: 102f896bbc58e849ef7cea66f6e4941675298e96 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * tms380tr.c: A network driver library for Texas Instruments TMS380-based
3 * Token Ring Adapters.
4 *
5 * Originally sktr.c: Written 1997 by Christoph Goos
6 *
7 * A fine result of the Linux Systems Network Architecture Project.
Justin P. Mattock631dd1a2010-10-18 11:03:14 +02008 * http://www.vanheusden.com/sna/
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * This software may be used and distributed according to the terms
11 * of the GNU General Public License, incorporated herein by reference.
12 *
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)
17 *
18 * Sources:
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
29 *
30 * Maintainer(s):
31 * JS Jay Schulist jschlst@samba.org
32 * CG Christoph Goos cgoos@syskonnect.de
Joe Perches726a6452008-02-03 16:36:24 +020033 * AF Adam Fritzler
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 * MLP Mike Phillips phillim@amtrak.com
35 * JF Jochen Friedrich jochen@scram.de
36 *
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
57 * as well.
58 * 14-Jan-01 JF Fix DMA on ifdown/ifup sequences. Some
59 * cleanup.
60 * 13-Jan-02 JF Add spinlock to fix race condition.
61 * 09-Nov-02 JF Fixed printks to not SPAM the console during
62 * normal operation.
63 * 30-Dec-02 JF Removed incorrect __init from
64 * tms380tr_init_card.
Jochen Friedrich504ff162005-07-27 01:14:50 -070065 * 22-Jul-05 JF Converted to dma-mapping.
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 *
67 * To do:
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
72 * quite unacceptable.
73 * 5. Still a few remaining stalls when the cable is unplugged.
74 */
75
76#ifdef MODULE
77static const char version[] = "tms380tr.c: v1.10 30/12/2002 by Christoph Goos, Adam Fritzler\n";
78#endif
79
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>
87#include <linux/in.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#include <linux/string.h>
89#include <linux/time.h>
90#include <linux/errno.h>
91#include <linux/init.h>
Jochen Friedrich504ff162005-07-27 01:14:50 -070092#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#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>
100
101#include <asm/system.h>
102#include <asm/io.h>
103#include <asm/dma.h>
104#include <asm/irq.h>
105#include <asm/uaccess.h>
106
107#include "tms380tr.h" /* Our Stuff */
108
109/* Use 0 for production, 1 for verification, 2 for debug, and
110 * 3 for very verbose debug.
111 */
112#ifndef TMS380TR_DEBUG
113#define TMS380TR_DEBUG 0
114#endif
115static unsigned int tms380tr_debug = TMS380TR_DEBUG;
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/* Index to functions, as function prototypes.
118 * Alphabetical by function name.
119 */
120
121/* "A" */
122/* "B" */
123static int tms380tr_bringup_diags(struct net_device *dev);
124/* "C" */
125static void tms380tr_cancel_tx_queue(struct net_local* tp);
126static int tms380tr_chipset_init(struct net_device *dev);
127static void tms380tr_chk_irq(struct net_device *dev);
128static void tms380tr_chk_outstanding_cmds(struct net_device *dev);
129static void tms380tr_chk_src_addr(unsigned char *frame, unsigned char *hw_addr);
130static unsigned char tms380tr_chk_ssb(struct net_local *tp, unsigned short IrqType);
131int tms380tr_close(struct net_device *dev);
132static void tms380tr_cmd_status_irq(struct net_device *dev);
133/* "D" */
134static void tms380tr_disable_interrupts(struct net_device *dev);
135#if TMS380TR_DEBUG > 0
136static void tms380tr_dump(unsigned char *Data, int length);
137#endif
138/* "E" */
139static void tms380tr_enable_interrupts(struct net_device *dev);
140static void tms380tr_exec_cmd(struct net_device *dev, unsigned short Command);
141static void tms380tr_exec_sifcmd(struct net_device *dev, unsigned int WriteValue);
142/* "F" */
143/* "G" */
144static struct net_device_stats *tms380tr_get_stats(struct net_device *dev);
145/* "H" */
Stephen Hemminger61a84102009-08-31 19:50:46 +0000146static netdev_tx_t tms380tr_hardware_send_packet(struct sk_buff *skb,
147 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/* "I" */
149static int tms380tr_init_adapter(struct net_device *dev);
150static void tms380tr_init_ipb(struct net_local *tp);
151static void tms380tr_init_net_local(struct net_device *dev);
152static void tms380tr_init_opb(struct net_device *dev);
153/* "M" */
154/* "O" */
155int tms380tr_open(struct net_device *dev);
156static void tms380tr_open_adapter(struct net_device *dev);
157/* "P" */
158/* "R" */
159static void tms380tr_rcv_status_irq(struct net_device *dev);
160static int tms380tr_read_ptr(struct net_device *dev);
161static void tms380tr_read_ram(struct net_device *dev, unsigned char *Data,
162 unsigned short Address, int Length);
163static int tms380tr_reset_adapter(struct net_device *dev);
164static void tms380tr_reset_interrupt(struct net_device *dev);
165static void tms380tr_ring_status_irq(struct net_device *dev);
166/* "S" */
Stephen Hemminger61a84102009-08-31 19:50:46 +0000167static netdev_tx_t tms380tr_send_packet(struct sk_buff *skb,
168 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169static void tms380tr_set_multicast_list(struct net_device *dev);
170static int tms380tr_set_mac_address(struct net_device *dev, void *addr);
171/* "T" */
172static void tms380tr_timer_chk(unsigned long data);
173static void tms380tr_timer_end_wait(unsigned long data);
174static void tms380tr_tx_status_irq(struct net_device *dev);
175/* "U" */
176static void tms380tr_update_rcv_stats(struct net_local *tp,
177 unsigned char DataPtr[], unsigned int Length);
178/* "W" */
179void tms380tr_wait(unsigned long time);
180static void tms380tr_write_rpl_status(RPL *rpl, unsigned int Status);
181static void tms380tr_write_tpl_status(TPL *tpl, unsigned int Status);
182
Wang Chen8f15ea42008-11-12 23:38:36 -0800183#define SIFREADB(reg) \
184 (((struct net_local *)netdev_priv(dev))->sifreadb(dev, reg))
185#define SIFWRITEB(val, reg) \
186 (((struct net_local *)netdev_priv(dev))->sifwriteb(dev, val, reg))
187#define SIFREADW(reg) \
188 (((struct net_local *)netdev_priv(dev))->sifreadw(dev, reg))
189#define SIFWRITEW(val, reg) \
190 (((struct net_local *)netdev_priv(dev))->sifwritew(dev, val, reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192
193
194#if 0 /* TMS380TR_DEBUG > 0 */
195static int madgemc_sifprobe(struct net_device *dev)
196{
197 unsigned char old, chk1, chk2;
198
199 old = SIFREADB(SIFADR); /* Get the old SIFADR value */
200
201 chk1 = 0; /* Begin with check value 0 */
202 do {
203 madgemc_setregpage(dev, 0);
204 /* Write new SIFADR value */
205 SIFWRITEB(chk1, SIFADR);
206 chk2 = SIFREADB(SIFADR);
207 if (chk2 != chk1)
208 return -1;
209
210 madgemc_setregpage(dev, 1);
211 /* Read, invert and write */
212 chk2 = SIFREADB(SIFADD);
213 if (chk2 != chk1)
214 return -1;
215
216 madgemc_setregpage(dev, 0);
217 chk2 ^= 0x0FE;
218 SIFWRITEB(chk2, SIFADR);
219
220 /* Read, invert and compare */
221 madgemc_setregpage(dev, 1);
222 chk2 = SIFREADB(SIFADD);
223 madgemc_setregpage(dev, 0);
224 chk2 ^= 0x0FE;
225
226 if(chk1 != chk2)
Eric Dumazet807540b2010-09-23 05:40:09 +0000227 return -1; /* No adapter */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 chk1 -= 2;
229 } while(chk1 != 0); /* Repeat 128 times (all byte values) */
230
231 madgemc_setregpage(dev, 0); /* sanity */
232 /* Restore the SIFADR value */
233 SIFWRITEB(old, SIFADR);
234
Eric Dumazet807540b2010-09-23 05:40:09 +0000235 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237#endif
238
239/*
240 * Open/initialize the board. This is called sometime after
241 * booting when the 'ifconfig' program is run.
242 *
243 * This routine should set everything up anew at each open, even
244 * registers that "should" only need to be set once at boot, so that
245 * there is non-reboot way to recover if something goes wrong.
246 */
247int tms380tr_open(struct net_device *dev)
248{
249 struct net_local *tp = netdev_priv(dev);
250 int err;
251
252 /* init the spinlock */
253 spin_lock_init(&tp->lock);
254 init_timer(&tp->timer);
255
256 /* Reset the hardware here. Don't forget to set the station address. */
257
258#ifdef CONFIG_ISA
259 if(dev->dma > 0)
260 {
261 unsigned long flags=claim_dma_lock();
262 disable_dma(dev->dma);
263 set_dma_mode(dev->dma, DMA_MODE_CASCADE);
264 enable_dma(dev->dma);
265 release_dma_lock(flags);
266 }
267#endif
268
269 err = tms380tr_chipset_init(dev);
270 if(err)
271 {
272 printk(KERN_INFO "%s: Chipset initialization error\n",
273 dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +0000274 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276
277 tp->timer.expires = jiffies + 30*HZ;
278 tp->timer.function = tms380tr_timer_end_wait;
279 tp->timer.data = (unsigned long)dev;
280 add_timer(&tp->timer);
281
282 printk(KERN_DEBUG "%s: Adapter RAM size: %dK\n",
283 dev->name, tms380tr_read_ptr(dev));
284
285 tms380tr_enable_interrupts(dev);
286 tms380tr_open_adapter(dev);
287
288 netif_start_queue(dev);
289
290 /* Wait for interrupt from hardware. If interrupt does not come,
291 * there will be a timeout from the timer.
292 */
293 tp->Sleeping = 1;
294 interruptible_sleep_on(&tp->wait_for_tok_int);
295 del_timer(&tp->timer);
296
297 /* If AdapterVirtOpenFlag is 1, the adapter is now open for use */
298 if(tp->AdapterVirtOpenFlag == 0)
299 {
300 tms380tr_disable_interrupts(dev);
Eric Dumazet807540b2010-09-23 05:40:09 +0000301 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303
304 tp->StartTime = jiffies;
305
306 /* Start function control timer */
307 tp->timer.expires = jiffies + 2*HZ;
308 tp->timer.function = tms380tr_timer_chk;
309 tp->timer.data = (unsigned long)dev;
310 add_timer(&tp->timer);
311
Eric Dumazet807540b2010-09-23 05:40:09 +0000312 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313}
314
315/*
316 * Timeout function while waiting for event
317 */
318static void tms380tr_timer_end_wait(unsigned long data)
319{
320 struct net_device *dev = (struct net_device*)data;
321 struct net_local *tp = netdev_priv(dev);
322
323 if(tp->Sleeping)
324 {
325 tp->Sleeping = 0;
326 wake_up_interruptible(&tp->wait_for_tok_int);
327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328}
329
330/*
331 * Initialize the chipset
332 */
333static int tms380tr_chipset_init(struct net_device *dev)
334{
335 struct net_local *tp = netdev_priv(dev);
336 int err;
337
338 tms380tr_init_ipb(tp);
339 tms380tr_init_opb(dev);
340 tms380tr_init_net_local(dev);
341
342 if(tms380tr_debug > 3)
343 printk(KERN_DEBUG "%s: Resetting adapter...\n", dev->name);
344 err = tms380tr_reset_adapter(dev);
345 if(err < 0)
Eric Dumazet807540b2010-09-23 05:40:09 +0000346 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 if(tms380tr_debug > 3)
349 printk(KERN_DEBUG "%s: Bringup diags...\n", dev->name);
350 err = tms380tr_bringup_diags(dev);
351 if(err < 0)
Eric Dumazet807540b2010-09-23 05:40:09 +0000352 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 if(tms380tr_debug > 3)
355 printk(KERN_DEBUG "%s: Init adapter...\n", dev->name);
356 err = tms380tr_init_adapter(dev);
357 if(err < 0)
Eric Dumazet807540b2010-09-23 05:40:09 +0000358 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 if(tms380tr_debug > 3)
361 printk(KERN_DEBUG "%s: Done!\n", dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +0000362 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
365/*
366 * Initializes the net_local structure.
367 */
368static void tms380tr_init_net_local(struct net_device *dev)
369{
370 struct net_local *tp = netdev_priv(dev);
371 int i;
372 dma_addr_t dmabuf;
373
374 tp->scb.CMD = 0;
375 tp->scb.Parm[0] = 0;
376 tp->scb.Parm[1] = 0;
377
378 tp->ssb.STS = 0;
379 tp->ssb.Parm[0] = 0;
380 tp->ssb.Parm[1] = 0;
381 tp->ssb.Parm[2] = 0;
382
383 tp->CMDqueue = 0;
384
385 tp->AdapterOpenFlag = 0;
386 tp->AdapterVirtOpenFlag = 0;
387 tp->ScbInUse = 0;
388 tp->OpenCommandIssued = 0;
389 tp->ReOpenInProgress = 0;
390 tp->HaltInProgress = 0;
391 tp->TransmitHaltScheduled = 0;
392 tp->LobeWireFaultLogged = 0;
393 tp->LastOpenStatus = 0;
394 tp->MaxPacketSize = DEFAULT_PACKET_SIZE;
395
396 /* Create circular chain of transmit lists */
397 for (i = 0; i < TPL_NUM; i++)
398 {
399 tp->Tpl[i].NextTPLAddr = htonl(((char *)(&tp->Tpl[(i+1) % TPL_NUM]) - (char *)tp) + tp->dmabuffer); /* DMA buffer may be MMU driven */
400 tp->Tpl[i].Status = 0;
401 tp->Tpl[i].FrameSize = 0;
402 tp->Tpl[i].FragList[0].DataCount = 0;
403 tp->Tpl[i].FragList[0].DataAddr = 0;
404 tp->Tpl[i].NextTPLPtr = &tp->Tpl[(i+1) % TPL_NUM];
405 tp->Tpl[i].MData = NULL;
406 tp->Tpl[i].TPLIndex = i;
407 tp->Tpl[i].DMABuff = 0;
408 tp->Tpl[i].BusyFlag = 0;
409 }
410
411 tp->TplFree = tp->TplBusy = &tp->Tpl[0];
412
413 /* Create circular chain of receive lists */
414 for (i = 0; i < RPL_NUM; i++)
415 {
416 tp->Rpl[i].NextRPLAddr = htonl(((char *)(&tp->Rpl[(i+1) % RPL_NUM]) - (char *)tp) + tp->dmabuffer); /* DMA buffer may be MMU driven */
417 tp->Rpl[i].Status = (RX_VALID | RX_START_FRAME | RX_END_FRAME | RX_FRAME_IRQ);
418 tp->Rpl[i].FrameSize = 0;
419 tp->Rpl[i].FragList[0].DataCount = cpu_to_be16((unsigned short)tp->MaxPacketSize);
420
421 /* Alloc skb and point adapter to data area */
422 tp->Rpl[i].Skb = dev_alloc_skb(tp->MaxPacketSize);
423 tp->Rpl[i].DMABuff = 0;
424
425 /* skb == NULL ? then use local buffer */
426 if(tp->Rpl[i].Skb == NULL)
427 {
428 tp->Rpl[i].SkbStat = SKB_UNAVAILABLE;
429 tp->Rpl[i].FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[i] - (char *)tp) + tp->dmabuffer);
430 tp->Rpl[i].MData = tp->LocalRxBuffers[i];
431 }
432 else /* SKB != NULL */
433 {
434 tp->Rpl[i].Skb->dev = dev;
435 skb_put(tp->Rpl[i].Skb, tp->MaxPacketSize);
436
437 /* data unreachable for DMA ? then use local buffer */
Jochen Friedrich504ff162005-07-27 01:14:50 -0700438 dmabuf = dma_map_single(tp->pdev, tp->Rpl[i].Skb->data, tp->MaxPacketSize, DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit))
440 {
441 tp->Rpl[i].SkbStat = SKB_DATA_COPY;
442 tp->Rpl[i].FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[i] - (char *)tp) + tp->dmabuffer);
443 tp->Rpl[i].MData = tp->LocalRxBuffers[i];
444 }
445 else /* DMA directly in skb->data */
446 {
447 tp->Rpl[i].SkbStat = SKB_DMA_DIRECT;
448 tp->Rpl[i].FragList[0].DataAddr = htonl(dmabuf);
449 tp->Rpl[i].MData = tp->Rpl[i].Skb->data;
450 tp->Rpl[i].DMABuff = dmabuf;
451 }
452 }
453
454 tp->Rpl[i].NextRPLPtr = &tp->Rpl[(i+1) % RPL_NUM];
455 tp->Rpl[i].RPLIndex = i;
456 }
457
458 tp->RplHead = &tp->Rpl[0];
459 tp->RplTail = &tp->Rpl[RPL_NUM-1];
460 tp->RplTail->Status = (RX_START_FRAME | RX_END_FRAME | RX_FRAME_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
463/*
464 * Initializes the initialisation parameter block.
465 */
466static void tms380tr_init_ipb(struct net_local *tp)
467{
468 tp->ipb.Init_Options = BURST_MODE;
469 tp->ipb.CMD_Status_IV = 0;
470 tp->ipb.TX_IV = 0;
471 tp->ipb.RX_IV = 0;
472 tp->ipb.Ring_Status_IV = 0;
473 tp->ipb.SCB_Clear_IV = 0;
474 tp->ipb.Adapter_CHK_IV = 0;
475 tp->ipb.RX_Burst_Size = BURST_SIZE;
476 tp->ipb.TX_Burst_Size = BURST_SIZE;
477 tp->ipb.DMA_Abort_Thrhld = DMA_RETRIES;
478 tp->ipb.SCB_Addr = 0;
479 tp->ipb.SSB_Addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
482/*
483 * Initializes the open parameter block.
484 */
485static void tms380tr_init_opb(struct net_device *dev)
486{
487 struct net_local *tp;
488 unsigned long Addr;
489 unsigned short RplSize = RPL_SIZE;
490 unsigned short TplSize = TPL_SIZE;
491 unsigned short BufferSize = BUFFER_SIZE;
492 int i;
493
494 tp = netdev_priv(dev);
495
496 tp->ocpl.OPENOptions = 0;
497 tp->ocpl.OPENOptions |= ENABLE_FULL_DUPLEX_SELECTION;
498 tp->ocpl.FullDuplex = 0;
499 tp->ocpl.FullDuplex |= OPEN_FULL_DUPLEX_OFF;
500
501 /*
502 * Set node address
503 *
504 * We go ahead and put it in the OPB even though on
505 * most of the generic adapters this isn't required.
506 * Its simpler this way. -- ASF
507 */
508 for (i=0;i<6;i++)
509 tp->ocpl.NodeAddr[i] = ((unsigned char *)dev->dev_addr)[i];
510
511 tp->ocpl.GroupAddr = 0;
512 tp->ocpl.FunctAddr = 0;
513 tp->ocpl.RxListSize = cpu_to_be16((unsigned short)RplSize);
514 tp->ocpl.TxListSize = cpu_to_be16((unsigned short)TplSize);
515 tp->ocpl.BufSize = cpu_to_be16((unsigned short)BufferSize);
516 tp->ocpl.Reserved = 0;
517 tp->ocpl.TXBufMin = TX_BUF_MIN;
518 tp->ocpl.TXBufMax = TX_BUF_MAX;
519
520 Addr = htonl(((char *)tp->ProductID - (char *)tp) + tp->dmabuffer);
521
522 tp->ocpl.ProdIDAddr[0] = LOWORD(Addr);
523 tp->ocpl.ProdIDAddr[1] = HIWORD(Addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524}
525
526/*
527 * Send OPEN command to adapter
528 */
529static void tms380tr_open_adapter(struct net_device *dev)
530{
531 struct net_local *tp = netdev_priv(dev);
532
533 if(tp->OpenCommandIssued)
534 return;
535
536 tp->OpenCommandIssued = 1;
537 tms380tr_exec_cmd(dev, OC_OPEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538}
539
540/*
541 * Clear the adapter's interrupt flag. Clear system interrupt enable
542 * (SINTEN): disable adapter to system interrupts.
543 */
544static void tms380tr_disable_interrupts(struct net_device *dev)
545{
546 SIFWRITEB(0, SIFACL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547}
548
549/*
550 * Set the adapter's interrupt flag. Set system interrupt enable
551 * (SINTEN): enable adapter to system interrupts.
552 */
553static void tms380tr_enable_interrupts(struct net_device *dev)
554{
555 SIFWRITEB(ACL_SINTEN, SIFACL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
558/*
559 * Put command in command queue, try to execute it.
560 */
561static void tms380tr_exec_cmd(struct net_device *dev, unsigned short Command)
562{
563 struct net_local *tp = netdev_priv(dev);
564
565 tp->CMDqueue |= Command;
566 tms380tr_chk_outstanding_cmds(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
569static void tms380tr_timeout(struct net_device *dev)
570{
571 /*
572 * If we get here, some higher level has decided we are broken.
573 * There should really be a "kick me" function call instead.
574 *
575 * Resetting the token ring adapter takes a long time so just
576 * fake transmission time and go on trying. Our own timeout
577 * routine is in tms380tr_timer_chk()
578 */
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700579 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 netif_wake_queue(dev);
581}
582
583/*
584 * Gets skb from system, queues it and checks if it can be sent
585 */
Stephen Hemminger61a84102009-08-31 19:50:46 +0000586static netdev_tx_t tms380tr_send_packet(struct sk_buff *skb,
587 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588{
589 struct net_local *tp = netdev_priv(dev);
Stephen Hemminger61a84102009-08-31 19:50:46 +0000590 netdev_tx_t rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Stephen Hemminger61a84102009-08-31 19:50:46 +0000592 rc = tms380tr_hardware_send_packet(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if(tp->TplFree->NextTPLPtr->BusyFlag)
594 netif_stop_queue(dev);
Stephen Hemminger61a84102009-08-31 19:50:46 +0000595 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
598/*
599 * Move frames into adapter tx queue
600 */
Stephen Hemminger61a84102009-08-31 19:50:46 +0000601static netdev_tx_t tms380tr_hardware_send_packet(struct sk_buff *skb,
602 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
604 TPL *tpl;
605 short length;
606 unsigned char *buf;
607 unsigned long flags;
608 int i;
609 dma_addr_t dmabuf, newbuf;
610 struct net_local *tp = netdev_priv(dev);
611
612 /* Try to get a free TPL from the chain.
613 *
614 * NOTE: We *must* always leave one unused TPL in the chain,
615 * because otherwise the adapter might send frames twice.
616 */
617 spin_lock_irqsave(&tp->lock, flags);
618 if(tp->TplFree->NextTPLPtr->BusyFlag) { /* No free TPL */
619 if (tms380tr_debug > 0)
620 printk(KERN_DEBUG "%s: No free TPL\n", dev->name);
621 spin_unlock_irqrestore(&tp->lock, flags);
Patrick McHardy5b548142009-06-12 06:22:29 +0000622 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 }
624
625 dmabuf = 0;
626
627 /* Is buffer reachable for Busmaster-DMA? */
628
629 length = skb->len;
Jochen Friedrich504ff162005-07-27 01:14:50 -0700630 dmabuf = dma_map_single(tp->pdev, skb->data, length, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 if(tp->dmalimit && (dmabuf + length > tp->dmalimit)) {
632 /* Copy frame to local buffer */
Jochen Friedrich504ff162005-07-27 01:14:50 -0700633 dma_unmap_single(tp->pdev, dmabuf, length, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 dmabuf = 0;
635 i = tp->TplFree->TPLIndex;
636 buf = tp->LocalTxBuffers[i];
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300637 skb_copy_from_linear_data(skb, buf, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 newbuf = ((char *)buf - (char *)tp) + tp->dmabuffer;
639 }
640 else {
641 /* Send direct from skb->data */
642 newbuf = dmabuf;
643 buf = skb->data;
644 }
645 /* Source address in packet? */
646 tms380tr_chk_src_addr(buf, dev->dev_addr);
647 tp->LastSendTime = jiffies;
648 tpl = tp->TplFree; /* Get the "free" TPL */
649 tpl->BusyFlag = 1; /* Mark TPL as busy */
650 tp->TplFree = tpl->NextTPLPtr;
651
652 /* Save the skb for delayed return of skb to system */
653 tpl->Skb = skb;
654 tpl->DMABuff = dmabuf;
655 tpl->FragList[0].DataCount = cpu_to_be16((unsigned short)length);
656 tpl->FragList[0].DataAddr = htonl(newbuf);
657
658 /* Write the data length in the transmit list. */
659 tpl->FrameSize = cpu_to_be16((unsigned short)length);
660 tpl->MData = buf;
661
662 /* Transmit the frame and set the status values. */
663 tms380tr_write_tpl_status(tpl, TX_VALID | TX_START_FRAME
664 | TX_END_FRAME | TX_PASS_SRC_ADDR
665 | TX_FRAME_IRQ);
666
667 /* Let adapter send the frame. */
668 tms380tr_exec_sifcmd(dev, CMD_TX_VALID);
669 spin_unlock_irqrestore(&tp->lock, flags);
670
Patrick McHardyec634fe2009-07-05 19:23:38 -0700671 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672}
673
674/*
675 * Write the given value to the 'Status' field of the specified TPL.
676 * NOTE: This function should be used whenever the status of any TPL must be
677 * modified by the driver, because the compiler may otherwise change the
678 * order of instructions such that writing the TPL status may be executed at
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800679 * an undesirable time. When this function is used, the status is always
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 * written when the function is called.
681 */
682static void tms380tr_write_tpl_status(TPL *tpl, unsigned int Status)
683{
684 tpl->Status = Status;
685}
686
687static void tms380tr_chk_src_addr(unsigned char *frame, unsigned char *hw_addr)
688{
689 unsigned char SRBit;
690
691 if((((unsigned long)frame[8]) & ~0x80) != 0) /* Compare 4 bytes */
692 return;
693 if((unsigned short)frame[12] != 0) /* Compare 2 bytes */
694 return;
695
696 SRBit = frame[8] & 0x80;
697 memcpy(&frame[8], hw_addr, 6);
698 frame[8] |= SRBit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
701/*
702 * The timer routine: Check if adapter still open and working, reopen if not.
703 */
704static void tms380tr_timer_chk(unsigned long data)
705{
706 struct net_device *dev = (struct net_device*)data;
707 struct net_local *tp = netdev_priv(dev);
708
709 if(tp->HaltInProgress)
710 return;
711
712 tms380tr_chk_outstanding_cmds(dev);
Joe Perches8e95a202009-12-03 07:58:21 +0000713 if(time_before(tp->LastSendTime + SEND_TIMEOUT, jiffies) &&
714 (tp->TplFree != tp->TplBusy))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 {
716 /* Anything to send, but stalled too long */
717 tp->LastSendTime = jiffies;
718 tms380tr_exec_cmd(dev, OC_CLOSE); /* Does reopen automatically */
719 }
720
721 tp->timer.expires = jiffies + 2*HZ;
722 add_timer(&tp->timer);
723
724 if(tp->AdapterOpenFlag || tp->ReOpenInProgress)
725 return;
726 tp->ReOpenInProgress = 1;
727 tms380tr_open_adapter(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728}
729
730/*
731 * The typical workload of the driver: Handle the network interface interrupts.
732 */
David Howells7d12e782006-10-05 14:55:46 +0100733irqreturn_t tms380tr_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734{
735 struct net_device *dev = dev_id;
736 struct net_local *tp;
737 unsigned short irq_type;
738 int handled = 0;
739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 tp = netdev_priv(dev);
741
742 irq_type = SIFREADW(SIFSTS);
743
744 while(irq_type & STS_SYSTEM_IRQ) {
745 handled = 1;
746 irq_type &= STS_IRQ_MASK;
747
748 if(!tms380tr_chk_ssb(tp, irq_type)) {
749 printk(KERN_DEBUG "%s: DATA LATE occurred\n", dev->name);
750 break;
751 }
752
753 switch(irq_type) {
754 case STS_IRQ_RECEIVE_STATUS:
755 tms380tr_reset_interrupt(dev);
756 tms380tr_rcv_status_irq(dev);
757 break;
758
759 case STS_IRQ_TRANSMIT_STATUS:
760 /* Check if TRANSMIT.HALT command is complete */
761 if(tp->ssb.Parm[0] & COMMAND_COMPLETE) {
762 tp->TransmitCommandActive = 0;
763 tp->TransmitHaltScheduled = 0;
764
765 /* Issue a new transmit command. */
766 tms380tr_exec_cmd(dev, OC_TRANSMIT);
767 }
768
769 tms380tr_reset_interrupt(dev);
770 tms380tr_tx_status_irq(dev);
771 break;
772
773 case STS_IRQ_COMMAND_STATUS:
774 /* The SSB contains status of last command
775 * other than receive/transmit.
776 */
777 tms380tr_cmd_status_irq(dev);
778 break;
779
780 case STS_IRQ_SCB_CLEAR:
781 /* The SCB is free for another command. */
782 tp->ScbInUse = 0;
783 tms380tr_chk_outstanding_cmds(dev);
784 break;
785
786 case STS_IRQ_RING_STATUS:
787 tms380tr_ring_status_irq(dev);
788 break;
789
790 case STS_IRQ_ADAPTER_CHECK:
791 tms380tr_chk_irq(dev);
792 break;
793
794 case STS_IRQ_LLC_STATUS:
795 printk(KERN_DEBUG "tms380tr: unexpected LLC status IRQ\n");
796 break;
797
798 case STS_IRQ_TIMER:
799 printk(KERN_DEBUG "tms380tr: unexpected Timer IRQ\n");
800 break;
801
802 case STS_IRQ_RECEIVE_PENDING:
803 printk(KERN_DEBUG "tms380tr: unexpected Receive Pending IRQ\n");
804 break;
805
806 default:
807 printk(KERN_DEBUG "Unknown Token Ring IRQ (0x%04x)\n", irq_type);
808 break;
809 }
810
811 /* Reset system interrupt if not already done. */
Joe Perches8e95a202009-12-03 07:58:21 +0000812 if(irq_type != STS_IRQ_TRANSMIT_STATUS &&
813 irq_type != STS_IRQ_RECEIVE_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 tms380tr_reset_interrupt(dev);
815 }
816
817 irq_type = SIFREADW(SIFSTS);
818 }
819
820 return IRQ_RETVAL(handled);
821}
822
823/*
824 * Reset the INTERRUPT SYSTEM bit and issue SSB CLEAR command.
825 */
826static void tms380tr_reset_interrupt(struct net_device *dev)
827{
828 struct net_local *tp = netdev_priv(dev);
829 SSB *ssb = &tp->ssb;
830
831 /*
832 * [Workaround for "Data Late"]
833 * Set all fields of the SSB to well-defined values so we can
834 * check if the adapter has written the SSB.
835 */
836
837 ssb->STS = (unsigned short) -1;
838 ssb->Parm[0] = (unsigned short) -1;
839 ssb->Parm[1] = (unsigned short) -1;
840 ssb->Parm[2] = (unsigned short) -1;
841
842 /* Free SSB by issuing SSB_CLEAR command after reading IRQ code
843 * and clear STS_SYSTEM_IRQ bit: enable adapter for further interrupts.
844 */
845 tms380tr_exec_sifcmd(dev, CMD_SSB_CLEAR | CMD_CLEAR_SYSTEM_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
848/*
849 * Check if the SSB has actually been written by the adapter.
850 */
851static unsigned char tms380tr_chk_ssb(struct net_local *tp, unsigned short IrqType)
852{
853 SSB *ssb = &tp->ssb; /* The address of the SSB. */
854
855 /* C 0 1 2 INTERRUPT CODE
856 * - - - - --------------
857 * 1 1 1 1 TRANSMIT STATUS
858 * 1 1 1 1 RECEIVE STATUS
859 * 1 ? ? 0 COMMAND STATUS
860 * 0 0 0 0 SCB CLEAR
861 * 1 1 0 0 RING STATUS
862 * 0 0 0 0 ADAPTER CHECK
863 *
864 * 0 = SSB field not affected by interrupt
865 * 1 = SSB field is affected by interrupt
866 *
867 * C = SSB ADDRESS +0: COMMAND
868 * 0 = SSB ADDRESS +2: STATUS 0
869 * 1 = SSB ADDRESS +4: STATUS 1
870 * 2 = SSB ADDRESS +6: STATUS 2
871 */
872
873 /* Check if this interrupt does use the SSB. */
874
Joe Perches8e95a202009-12-03 07:58:21 +0000875 if(IrqType != STS_IRQ_TRANSMIT_STATUS &&
876 IrqType != STS_IRQ_RECEIVE_STATUS &&
877 IrqType != STS_IRQ_COMMAND_STATUS &&
878 IrqType != STS_IRQ_RING_STATUS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 {
Eric Dumazet807540b2010-09-23 05:40:09 +0000880 return 1; /* SSB not involved. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
882
883 /* Note: All fields of the SSB have been set to all ones (-1) after it
884 * has last been used by the software (see DriverIsr()).
885 *
886 * Check if the affected SSB fields are still unchanged.
887 */
888
889 if(ssb->STS == (unsigned short) -1)
Eric Dumazet807540b2010-09-23 05:40:09 +0000890 return 0; /* Command field not yet available. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 if(IrqType == STS_IRQ_COMMAND_STATUS)
Eric Dumazet807540b2010-09-23 05:40:09 +0000892 return 1; /* Status fields not always affected. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if(ssb->Parm[0] == (unsigned short) -1)
Eric Dumazet807540b2010-09-23 05:40:09 +0000894 return 0; /* Status 1 field not yet available. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 if(IrqType == STS_IRQ_RING_STATUS)
Eric Dumazet807540b2010-09-23 05:40:09 +0000896 return 1; /* Status 2 & 3 fields not affected. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
898 /* Note: At this point, the interrupt is either TRANSMIT or RECEIVE. */
899 if(ssb->Parm[1] == (unsigned short) -1)
Eric Dumazet807540b2010-09-23 05:40:09 +0000900 return 0; /* Status 2 field not yet available. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 if(ssb->Parm[2] == (unsigned short) -1)
Eric Dumazet807540b2010-09-23 05:40:09 +0000902 return 0; /* Status 3 field not yet available. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Eric Dumazet807540b2010-09-23 05:40:09 +0000904 return 1; /* All SSB fields have been written by the adapter. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905}
906
907/*
908 * Evaluates the command results status in the SSB status field.
909 */
910static void tms380tr_cmd_status_irq(struct net_device *dev)
911{
912 struct net_local *tp = netdev_priv(dev);
913 unsigned short ssb_cmd, ssb_parm_0;
914 unsigned short ssb_parm_1;
915 char *open_err = "Open error -";
916 char *code_err = "Open code -";
917
918 /* Copy the ssb values to local variables */
919 ssb_cmd = tp->ssb.STS;
920 ssb_parm_0 = tp->ssb.Parm[0];
921 ssb_parm_1 = tp->ssb.Parm[1];
922
923 if(ssb_cmd == OPEN)
924 {
925 tp->Sleeping = 0;
926 if(!tp->ReOpenInProgress)
927 wake_up_interruptible(&tp->wait_for_tok_int);
928
929 tp->OpenCommandIssued = 0;
930 tp->ScbInUse = 0;
931
932 if((ssb_parm_0 & 0x00FF) == GOOD_COMPLETION)
933 {
934 /* Success, the adapter is open. */
935 tp->LobeWireFaultLogged = 0;
936 tp->AdapterOpenFlag = 1;
937 tp->AdapterVirtOpenFlag = 1;
938 tp->TransmitCommandActive = 0;
939 tms380tr_exec_cmd(dev, OC_TRANSMIT);
940 tms380tr_exec_cmd(dev, OC_RECEIVE);
941
942 if(tp->ReOpenInProgress)
943 tp->ReOpenInProgress = 0;
944
945 return;
946 }
947 else /* The adapter did not open. */
948 {
949 if(ssb_parm_0 & NODE_ADDR_ERROR)
950 printk(KERN_INFO "%s: Node address error\n",
951 dev->name);
952 if(ssb_parm_0 & LIST_SIZE_ERROR)
953 printk(KERN_INFO "%s: List size error\n",
954 dev->name);
955 if(ssb_parm_0 & BUF_SIZE_ERROR)
956 printk(KERN_INFO "%s: Buffer size error\n",
957 dev->name);
958 if(ssb_parm_0 & TX_BUF_COUNT_ERROR)
959 printk(KERN_INFO "%s: Tx buffer count error\n",
960 dev->name);
961 if(ssb_parm_0 & INVALID_OPEN_OPTION)
962 printk(KERN_INFO "%s: Invalid open option\n",
963 dev->name);
964 if(ssb_parm_0 & OPEN_ERROR)
965 {
966 /* Show the open phase. */
967 switch(ssb_parm_0 & OPEN_PHASES_MASK)
968 {
969 case LOBE_MEDIA_TEST:
970 if(!tp->LobeWireFaultLogged)
971 {
972 tp->LobeWireFaultLogged = 1;
973 printk(KERN_INFO "%s: %s Lobe wire fault (check cable !).\n", dev->name, open_err);
974 }
975 tp->ReOpenInProgress = 1;
976 tp->AdapterOpenFlag = 0;
977 tp->AdapterVirtOpenFlag = 1;
978 tms380tr_open_adapter(dev);
979 return;
980
981 case PHYSICAL_INSERTION:
982 printk(KERN_INFO "%s: %s Physical insertion.\n", dev->name, open_err);
983 break;
984
985 case ADDRESS_VERIFICATION:
986 printk(KERN_INFO "%s: %s Address verification.\n", dev->name, open_err);
987 break;
988
989 case PARTICIPATION_IN_RING_POLL:
990 printk(KERN_INFO "%s: %s Participation in ring poll.\n", dev->name, open_err);
991 break;
992
993 case REQUEST_INITIALISATION:
994 printk(KERN_INFO "%s: %s Request initialisation.\n", dev->name, open_err);
995 break;
996
997 case FULLDUPLEX_CHECK:
998 printk(KERN_INFO "%s: %s Full duplex check.\n", dev->name, open_err);
999 break;
1000
1001 default:
1002 printk(KERN_INFO "%s: %s Unknown open phase\n", dev->name, open_err);
1003 break;
1004 }
1005
1006 /* Show the open errors. */
1007 switch(ssb_parm_0 & OPEN_ERROR_CODES_MASK)
1008 {
1009 case OPEN_FUNCTION_FAILURE:
1010 printk(KERN_INFO "%s: %s OPEN_FUNCTION_FAILURE", dev->name, code_err);
1011 tp->LastOpenStatus =
1012 OPEN_FUNCTION_FAILURE;
1013 break;
1014
1015 case OPEN_SIGNAL_LOSS:
1016 printk(KERN_INFO "%s: %s OPEN_SIGNAL_LOSS\n", dev->name, code_err);
1017 tp->LastOpenStatus =
1018 OPEN_SIGNAL_LOSS;
1019 break;
1020
1021 case OPEN_TIMEOUT:
1022 printk(KERN_INFO "%s: %s OPEN_TIMEOUT\n", dev->name, code_err);
1023 tp->LastOpenStatus =
1024 OPEN_TIMEOUT;
1025 break;
1026
1027 case OPEN_RING_FAILURE:
1028 printk(KERN_INFO "%s: %s OPEN_RING_FAILURE\n", dev->name, code_err);
1029 tp->LastOpenStatus =
1030 OPEN_RING_FAILURE;
1031 break;
1032
1033 case OPEN_RING_BEACONING:
1034 printk(KERN_INFO "%s: %s OPEN_RING_BEACONING\n", dev->name, code_err);
1035 tp->LastOpenStatus =
1036 OPEN_RING_BEACONING;
1037 break;
1038
1039 case OPEN_DUPLICATE_NODEADDR:
1040 printk(KERN_INFO "%s: %s OPEN_DUPLICATE_NODEADDR\n", dev->name, code_err);
1041 tp->LastOpenStatus =
1042 OPEN_DUPLICATE_NODEADDR;
1043 break;
1044
1045 case OPEN_REQUEST_INIT:
1046 printk(KERN_INFO "%s: %s OPEN_REQUEST_INIT\n", dev->name, code_err);
1047 tp->LastOpenStatus =
1048 OPEN_REQUEST_INIT;
1049 break;
1050
1051 case OPEN_REMOVE_RECEIVED:
1052 printk(KERN_INFO "%s: %s OPEN_REMOVE_RECEIVED", dev->name, code_err);
1053 tp->LastOpenStatus =
1054 OPEN_REMOVE_RECEIVED;
1055 break;
1056
1057 case OPEN_FULLDUPLEX_SET:
1058 printk(KERN_INFO "%s: %s OPEN_FULLDUPLEX_SET\n", dev->name, code_err);
1059 tp->LastOpenStatus =
1060 OPEN_FULLDUPLEX_SET;
1061 break;
1062
1063 default:
1064 printk(KERN_INFO "%s: %s Unknown open err code", dev->name, code_err);
1065 tp->LastOpenStatus =
1066 OPEN_FUNCTION_FAILURE;
1067 break;
1068 }
1069 }
1070
1071 tp->AdapterOpenFlag = 0;
1072 tp->AdapterVirtOpenFlag = 0;
1073
1074 return;
1075 }
1076 }
1077 else
1078 {
1079 if(ssb_cmd != READ_ERROR_LOG)
1080 return;
1081
1082 /* Add values from the error log table to the MAC
1083 * statistics counters and update the errorlogtable
1084 * memory.
1085 */
1086 tp->MacStat.line_errors += tp->errorlogtable.Line_Error;
1087 tp->MacStat.burst_errors += tp->errorlogtable.Burst_Error;
1088 tp->MacStat.A_C_errors += tp->errorlogtable.ARI_FCI_Error;
1089 tp->MacStat.lost_frames += tp->errorlogtable.Lost_Frame_Error;
1090 tp->MacStat.recv_congest_count += tp->errorlogtable.Rx_Congest_Error;
1091 tp->MacStat.rx_errors += tp->errorlogtable.Rx_Congest_Error;
1092 tp->MacStat.frame_copied_errors += tp->errorlogtable.Frame_Copied_Error;
1093 tp->MacStat.token_errors += tp->errorlogtable.Token_Error;
1094 tp->MacStat.dummy1 += tp->errorlogtable.DMA_Bus_Error;
1095 tp->MacStat.dummy1 += tp->errorlogtable.DMA_Parity_Error;
1096 tp->MacStat.abort_delimiters += tp->errorlogtable.AbortDelimeters;
1097 tp->MacStat.frequency_errors += tp->errorlogtable.Frequency_Error;
1098 tp->MacStat.internal_errors += tp->errorlogtable.Internal_Error;
1099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100}
1101
1102/*
1103 * The inverse routine to tms380tr_open().
1104 */
1105int tms380tr_close(struct net_device *dev)
1106{
1107 struct net_local *tp = netdev_priv(dev);
1108 netif_stop_queue(dev);
1109
1110 del_timer(&tp->timer);
1111
1112 /* Flush the Tx and disable Rx here. */
1113
1114 tp->HaltInProgress = 1;
1115 tms380tr_exec_cmd(dev, OC_CLOSE);
1116 tp->timer.expires = jiffies + 1*HZ;
1117 tp->timer.function = tms380tr_timer_end_wait;
1118 tp->timer.data = (unsigned long)dev;
1119 add_timer(&tp->timer);
1120
1121 tms380tr_enable_interrupts(dev);
1122
1123 tp->Sleeping = 1;
1124 interruptible_sleep_on(&tp->wait_for_tok_int);
1125 tp->TransmitCommandActive = 0;
1126
1127 del_timer(&tp->timer);
1128 tms380tr_disable_interrupts(dev);
1129
1130#ifdef CONFIG_ISA
1131 if(dev->dma > 0)
1132 {
1133 unsigned long flags=claim_dma_lock();
1134 disable_dma(dev->dma);
1135 release_dma_lock(flags);
1136 }
1137#endif
1138
1139 SIFWRITEW(0xFF00, SIFCMD);
1140#if 0
1141 if(dev->dma > 0) /* what the? */
1142 SIFWRITEB(0xff, POSREG);
1143#endif
1144 tms380tr_cancel_tx_queue(tp);
1145
Eric Dumazet807540b2010-09-23 05:40:09 +00001146 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147}
1148
1149/*
1150 * Get the current statistics. This may be called with the card open
1151 * or closed.
1152 */
1153static struct net_device_stats *tms380tr_get_stats(struct net_device *dev)
1154{
1155 struct net_local *tp = netdev_priv(dev);
1156
Eric Dumazet807540b2010-09-23 05:40:09 +00001157 return (struct net_device_stats *)&tp->MacStat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158}
1159
1160/*
1161 * Set or clear the multicast filter for this adapter.
1162 */
1163static void tms380tr_set_multicast_list(struct net_device *dev)
1164{
1165 struct net_local *tp = netdev_priv(dev);
1166 unsigned int OpenOptions;
1167
1168 OpenOptions = tp->ocpl.OPENOptions &
1169 ~(PASS_ADAPTER_MAC_FRAMES
1170 | PASS_ATTENTION_FRAMES
1171 | PASS_BEACON_MAC_FRAMES
1172 | COPY_ALL_MAC_FRAMES
1173 | COPY_ALL_NON_MAC_FRAMES);
1174
1175 tp->ocpl.FunctAddr = 0;
1176
1177 if(dev->flags & IFF_PROMISC)
1178 /* Enable promiscuous mode */
1179 OpenOptions |= COPY_ALL_NON_MAC_FRAMES |
1180 COPY_ALL_MAC_FRAMES;
1181 else
1182 {
1183 if(dev->flags & IFF_ALLMULTI)
1184 {
1185 /* Disable promiscuous mode, use normal mode. */
1186 tp->ocpl.FunctAddr = 0xFFFFFFFF;
1187 }
1188 else
1189 {
Jiri Pirko22bedad2010-04-01 21:22:57 +00001190 struct netdev_hw_addr *ha;
Jiri Pirko16cad982010-02-18 02:47:07 +00001191
Jiri Pirko22bedad2010-04-01 21:22:57 +00001192 netdev_for_each_mc_addr(ha, dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 ((char *)(&tp->ocpl.FunctAddr))[0] |=
Jiri Pirko22bedad2010-04-01 21:22:57 +00001194 ha->addr[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 ((char *)(&tp->ocpl.FunctAddr))[1] |=
Jiri Pirko22bedad2010-04-01 21:22:57 +00001196 ha->addr[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 ((char *)(&tp->ocpl.FunctAddr))[2] |=
Jiri Pirko22bedad2010-04-01 21:22:57 +00001198 ha->addr[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 ((char *)(&tp->ocpl.FunctAddr))[3] |=
Jiri Pirko22bedad2010-04-01 21:22:57 +00001200 ha->addr[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 }
1202 }
1203 tms380tr_exec_cmd(dev, OC_SET_FUNCT_ADDR);
1204 }
1205
1206 tp->ocpl.OPENOptions = OpenOptions;
1207 tms380tr_exec_cmd(dev, OC_MODIFY_OPEN_PARMS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208}
1209
1210/*
1211 * Wait for some time (microseconds)
1212 */
1213void tms380tr_wait(unsigned long time)
1214{
1215#if 0
1216 long tmp;
1217
1218 tmp = jiffies + time/(1000000/HZ);
1219 do {
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001220 tmp = schedule_timeout_interruptible(tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 } while(time_after(tmp, jiffies));
1222#else
David S. Miller5202e172010-10-25 13:04:48 -07001223 mdelay(time / 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225}
1226
1227/*
1228 * Write a command value to the SIFCMD register
1229 */
1230static void tms380tr_exec_sifcmd(struct net_device *dev, unsigned int WriteValue)
1231{
1232 unsigned short cmd;
1233 unsigned short SifStsValue;
1234 unsigned long loop_counter;
1235
1236 WriteValue = ((WriteValue ^ CMD_SYSTEM_IRQ) | CMD_INTERRUPT_ADAPTER);
1237 cmd = (unsigned short)WriteValue;
1238 loop_counter = 0,5 * 800000;
1239 do {
1240 SifStsValue = SIFREADW(SIFSTS);
1241 } while((SifStsValue & CMD_INTERRUPT_ADAPTER) && loop_counter--);
1242 SIFWRITEW(cmd, SIFCMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243}
1244
1245/*
1246 * Processes adapter hardware reset, halts adapter and downloads firmware,
1247 * clears the halt bit.
1248 */
1249static int tms380tr_reset_adapter(struct net_device *dev)
1250{
1251 struct net_local *tp = netdev_priv(dev);
1252 unsigned short *fw_ptr;
1253 unsigned short count, c, count2;
1254 const struct firmware *fw_entry = NULL;
1255
Jochen Friedrich504ff162005-07-27 01:14:50 -07001256 if (request_firmware(&fw_entry, "tms380tr.bin", tp->pdev) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 printk(KERN_ALERT "%s: firmware %s is missing, cannot start.\n",
1258 dev->name, "tms380tr.bin");
Eric Dumazet807540b2010-09-23 05:40:09 +00001259 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 }
1261
1262 fw_ptr = (unsigned short *)fw_entry->data;
1263 count2 = fw_entry->size / 2;
1264
1265 /* Hardware adapter reset */
1266 SIFWRITEW(ACL_ARESET, SIFACL);
1267 tms380tr_wait(40);
1268
1269 c = SIFREADW(SIFACL);
1270 tms380tr_wait(20);
1271
1272 if(dev->dma == 0) /* For PCI adapters */
1273 {
1274 c &= ~(ACL_NSELOUT0 | ACL_NSELOUT1); /* Clear bits */
1275 if(tp->setnselout)
1276 c |= (*tp->setnselout)(dev);
1277 }
1278
1279 /* In case a command is pending - forget it */
1280 tp->ScbInUse = 0;
1281
1282 c &= ~ACL_ARESET; /* Clear adapter reset bit */
1283 c |= ACL_CPHALT; /* Halt adapter CPU, allow download */
1284 c |= ACL_BOOT;
1285 c |= ACL_SINTEN;
1286 c &= ~ACL_PSDMAEN; /* Clear pseudo dma bit */
1287 SIFWRITEW(c, SIFACL);
1288 tms380tr_wait(40);
1289
1290 count = 0;
1291 /* Download firmware via DIO interface: */
1292 do {
1293 if (count2 < 3) continue;
1294
1295 /* Download first address part */
1296 SIFWRITEW(*fw_ptr, SIFADX);
1297 fw_ptr++;
1298 count2--;
1299 /* Download second address part */
1300 SIFWRITEW(*fw_ptr, SIFADD);
1301 fw_ptr++;
1302 count2--;
1303
1304 if((count = *fw_ptr) != 0) /* Load loop counter */
1305 {
1306 fw_ptr++; /* Download block data */
1307 count2--;
1308 if (count > count2) continue;
1309
1310 for(; count > 0; count--)
1311 {
1312 SIFWRITEW(*fw_ptr, SIFINC);
1313 fw_ptr++;
1314 count2--;
1315 }
1316 }
1317 else /* Stop, if last block downloaded */
1318 {
1319 c = SIFREADW(SIFACL);
1320 c &= (~ACL_CPHALT | ACL_SINTEN);
1321
1322 /* Clear CPHALT and start BUD */
1323 SIFWRITEW(c, SIFACL);
Dan Carpenter773bc972010-08-22 00:54:30 -07001324 release_firmware(fw_entry);
Eric Dumazet807540b2010-09-23 05:40:09 +00001325 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 }
1327 } while(count == 0);
1328
Dan Carpenter773bc972010-08-22 00:54:30 -07001329 release_firmware(fw_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 printk(KERN_INFO "%s: Adapter Download Failed\n", dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +00001331 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332}
1333
Ben Hutchingsb3ccbb22009-11-07 11:55:20 +00001334MODULE_FIRMWARE("tms380tr.bin");
1335
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336/*
1337 * Starts bring up diagnostics of token ring adapter and evaluates
1338 * diagnostic results.
1339 */
1340static int tms380tr_bringup_diags(struct net_device *dev)
1341{
1342 int loop_cnt, retry_cnt;
1343 unsigned short Status;
1344
1345 tms380tr_wait(HALF_SECOND);
1346 tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
1347 tms380tr_wait(HALF_SECOND);
1348
1349 retry_cnt = BUD_MAX_RETRIES; /* maximal number of retrys */
1350
1351 do {
1352 retry_cnt--;
1353 if(tms380tr_debug > 3)
1354 printk(KERN_DEBUG "BUD-Status: ");
1355 loop_cnt = BUD_MAX_LOOPCNT; /* maximum: three seconds*/
1356 do { /* Inspect BUD results */
1357 loop_cnt--;
1358 tms380tr_wait(HALF_SECOND);
1359 Status = SIFREADW(SIFSTS);
1360 Status &= STS_MASK;
1361
1362 if(tms380tr_debug > 3)
Frans Pop014e4662010-03-24 07:57:33 +00001363 printk(KERN_DEBUG " %04X\n", Status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 /* BUD successfully completed */
1365 if(Status == STS_INITIALIZE)
Eric Dumazet807540b2010-09-23 05:40:09 +00001366 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 /* Unrecoverable hardware error, BUD not completed? */
1368 } while((loop_cnt > 0) && ((Status & (STS_ERROR | STS_TEST))
1369 != (STS_ERROR | STS_TEST)));
1370
1371 /* Error preventing completion of BUD */
1372 if(retry_cnt > 0)
1373 {
1374 printk(KERN_INFO "%s: Adapter Software Reset.\n",
1375 dev->name);
1376 tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
1377 tms380tr_wait(HALF_SECOND);
1378 }
1379 } while(retry_cnt > 0);
1380
1381 Status = SIFREADW(SIFSTS);
1382
1383 printk(KERN_INFO "%s: Hardware error\n", dev->name);
1384 /* Hardware error occurred! */
1385 Status &= 0x001f;
1386 if (Status & 0x0010)
1387 printk(KERN_INFO "%s: BUD Error: Timeout\n", dev->name);
1388 else if ((Status & 0x000f) > 6)
1389 printk(KERN_INFO "%s: BUD Error: Illegal Failure\n", dev->name);
1390 else
1391 printk(KERN_INFO "%s: Bring Up Diagnostics Error (%04X) occurred\n", dev->name, Status & 0x000f);
1392
Eric Dumazet807540b2010-09-23 05:40:09 +00001393 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394}
1395
1396/*
1397 * Copy initialisation data to adapter memory, beginning at address
1398 * 1:0A00; Starting DMA test and evaluating result bits.
1399 */
1400static int tms380tr_init_adapter(struct net_device *dev)
1401{
1402 struct net_local *tp = netdev_priv(dev);
1403
1404 const unsigned char SCB_Test[6] = {0x00, 0x00, 0xC1, 0xE2, 0xD4, 0x8B};
1405 const unsigned char SSB_Test[8] = {0xFF, 0xFF, 0xD1, 0xD7,
1406 0xC5, 0xD9, 0xC3, 0xD4};
1407 void *ptr = (void *)&tp->ipb;
1408 unsigned short *ipb_ptr = (unsigned short *)ptr;
1409 unsigned char *cb_ptr = (unsigned char *) &tp->scb;
1410 unsigned char *sb_ptr = (unsigned char *) &tp->ssb;
1411 unsigned short Status;
1412 int i, loop_cnt, retry_cnt;
1413
1414 /* Normalize: byte order low/high, word order high/low! (only IPB!) */
1415 tp->ipb.SCB_Addr = SWAPW(((char *)&tp->scb - (char *)tp) + tp->dmabuffer);
1416 tp->ipb.SSB_Addr = SWAPW(((char *)&tp->ssb - (char *)tp) + tp->dmabuffer);
1417
1418 if(tms380tr_debug > 3)
1419 {
1420 printk(KERN_DEBUG "%s: buffer (real): %lx\n", dev->name, (long) &tp->scb);
1421 printk(KERN_DEBUG "%s: buffer (virt): %lx\n", dev->name, (long) ((char *)&tp->scb - (char *)tp) + (long) tp->dmabuffer);
1422 printk(KERN_DEBUG "%s: buffer (DMA) : %lx\n", dev->name, (long) tp->dmabuffer);
1423 printk(KERN_DEBUG "%s: buffer (tp) : %lx\n", dev->name, (long) tp);
1424 }
1425 /* Maximum: three initialization retries */
1426 retry_cnt = INIT_MAX_RETRIES;
1427
1428 do {
1429 retry_cnt--;
1430
1431 /* Transfer initialization block */
1432 SIFWRITEW(0x0001, SIFADX);
1433
1434 /* To address 0001:0A00 of adapter RAM */
1435 SIFWRITEW(0x0A00, SIFADD);
1436
1437 /* Write 11 words to adapter RAM */
1438 for(i = 0; i < 11; i++)
1439 SIFWRITEW(ipb_ptr[i], SIFINC);
1440
1441 /* Execute SCB adapter command */
1442 tms380tr_exec_sifcmd(dev, CMD_EXECUTE);
1443
1444 loop_cnt = INIT_MAX_LOOPCNT; /* Maximum: 11 seconds */
1445
1446 /* While remaining retries, no error and not completed */
1447 do {
1448 Status = 0;
1449 loop_cnt--;
1450 tms380tr_wait(HALF_SECOND);
1451
1452 /* Mask interesting status bits */
1453 Status = SIFREADW(SIFSTS);
1454 Status &= STS_MASK;
Joe Perches8e95a202009-12-03 07:58:21 +00001455 } while(((Status &(STS_INITIALIZE | STS_ERROR | STS_TEST)) != 0) &&
1456 ((Status & STS_ERROR) == 0) && (loop_cnt != 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
1458 if((Status & (STS_INITIALIZE | STS_ERROR | STS_TEST)) == 0)
1459 {
1460 /* Initialization completed without error */
1461 i = 0;
1462 do { /* Test if contents of SCB is valid */
1463 if(SCB_Test[i] != *(cb_ptr + i))
1464 {
1465 printk(KERN_INFO "%s: DMA failed\n", dev->name);
1466 /* DMA data error: wrong data in SCB */
Eric Dumazet807540b2010-09-23 05:40:09 +00001467 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 }
1469 i++;
1470 } while(i < 6);
1471
1472 i = 0;
1473 do { /* Test if contents of SSB is valid */
1474 if(SSB_Test[i] != *(sb_ptr + i))
1475 /* DMA data error: wrong data in SSB */
Eric Dumazet807540b2010-09-23 05:40:09 +00001476 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 i++;
1478 } while (i < 8);
1479
Eric Dumazet807540b2010-09-23 05:40:09 +00001480 return 1; /* Adapter successfully initialized */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 }
1482 else
1483 {
1484 if((Status & STS_ERROR) != 0)
1485 {
1486 /* Initialization error occurred */
1487 Status = SIFREADW(SIFSTS);
1488 Status &= STS_ERROR_MASK;
1489 /* ShowInitialisationErrorCode(Status); */
1490 printk(KERN_INFO "%s: Status error: %d\n", dev->name, Status);
Eric Dumazet807540b2010-09-23 05:40:09 +00001491 return -1; /* Unrecoverable error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 }
1493 else
1494 {
1495 if(retry_cnt > 0)
1496 {
1497 /* Reset adapter and try init again */
1498 tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
1499 tms380tr_wait(HALF_SECOND);
1500 }
1501 }
1502 }
1503 } while(retry_cnt > 0);
1504
1505 printk(KERN_INFO "%s: Retry exceeded\n", dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +00001506 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507}
1508
1509/*
1510 * Check for outstanding commands in command queue and tries to execute
1511 * command immediately. Corresponding command flag in command queue is cleared.
1512 */
1513static void tms380tr_chk_outstanding_cmds(struct net_device *dev)
1514{
1515 struct net_local *tp = netdev_priv(dev);
1516 unsigned long Addr = 0;
1517
1518 if(tp->CMDqueue == 0)
1519 return; /* No command execution */
1520
1521 /* If SCB in use: no command */
1522 if(tp->ScbInUse == 1)
1523 return;
1524
1525 /* Check if adapter is opened, avoiding COMMAND_REJECT
1526 * interrupt by the adapter!
1527 */
Joe Perches76a82ab2012-02-04 10:52:56 +00001528 if (tp->AdapterOpenFlag == 0) {
1529 if (tp->CMDqueue & OC_OPEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 /* Execute OPEN command */
1531 tp->CMDqueue ^= OC_OPEN;
1532
1533 Addr = htonl(((char *)&tp->ocpl - (char *)tp) + tp->dmabuffer);
1534 tp->scb.Parm[0] = LOWORD(Addr);
1535 tp->scb.Parm[1] = HIWORD(Addr);
1536 tp->scb.CMD = OPEN;
Joe Perches76a82ab2012-02-04 10:52:56 +00001537 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 /* No OPEN command queued, but adapter closed. Note:
1539 * We'll try to re-open the adapter in DriverPoll()
1540 */
1541 return; /* No adapter command issued */
Joe Perches76a82ab2012-02-04 10:52:56 +00001542 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 /* Adapter is open; evaluate command queue: try to execute
1544 * outstanding commands (depending on priority!) CLOSE
1545 * command queued
1546 */
Joe Perches76a82ab2012-02-04 10:52:56 +00001547 if (tp->CMDqueue & OC_CLOSE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 tp->CMDqueue ^= OC_CLOSE;
1549 tp->AdapterOpenFlag = 0;
1550 tp->scb.Parm[0] = 0; /* Parm[0], Parm[1] are ignored */
1551 tp->scb.Parm[1] = 0; /* but should be set to zero! */
1552 tp->scb.CMD = CLOSE;
1553 if(!tp->HaltInProgress)
1554 tp->CMDqueue |= OC_OPEN; /* re-open adapter */
1555 else
1556 tp->CMDqueue = 0; /* no more commands */
Joe Perches76a82ab2012-02-04 10:52:56 +00001557 } else if (tp->CMDqueue & OC_RECEIVE) {
1558 tp->CMDqueue ^= OC_RECEIVE;
1559 Addr = htonl(((char *)tp->RplHead - (char *)tp) + tp->dmabuffer);
1560 tp->scb.Parm[0] = LOWORD(Addr);
1561 tp->scb.Parm[1] = HIWORD(Addr);
1562 tp->scb.CMD = RECEIVE;
1563 } else if (tp->CMDqueue & OC_TRANSMIT_HALT) {
1564 /* NOTE: TRANSMIT.HALT must be checked
1565 * before TRANSMIT.
1566 */
1567 tp->CMDqueue ^= OC_TRANSMIT_HALT;
1568 tp->scb.CMD = TRANSMIT_HALT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Joe Perches76a82ab2012-02-04 10:52:56 +00001570 /* Parm[0] and Parm[1] are ignored
1571 * but should be set to zero!
1572 */
1573 tp->scb.Parm[0] = 0;
1574 tp->scb.Parm[1] = 0;
1575 } else if (tp->CMDqueue & OC_TRANSMIT) {
1576 /* NOTE: TRANSMIT must be
1577 * checked after TRANSMIT.HALT
1578 */
1579 if (tp->TransmitCommandActive) {
1580 if (!tp->TransmitHaltScheduled) {
1581 tp->TransmitHaltScheduled = 1;
1582 tms380tr_exec_cmd(dev, OC_TRANSMIT_HALT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 }
Joe Perches76a82ab2012-02-04 10:52:56 +00001584 tp->TransmitCommandActive = 0;
1585 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 }
Joe Perches76a82ab2012-02-04 10:52:56 +00001587
1588 tp->CMDqueue ^= OC_TRANSMIT;
1589 tms380tr_cancel_tx_queue(tp);
1590 Addr = htonl(((char *)tp->TplBusy - (char *)tp) + tp->dmabuffer);
1591 tp->scb.Parm[0] = LOWORD(Addr);
1592 tp->scb.Parm[1] = HIWORD(Addr);
1593 tp->scb.CMD = TRANSMIT;
1594 tp->TransmitCommandActive = 1;
1595 } else if (tp->CMDqueue & OC_MODIFY_OPEN_PARMS) {
1596 tp->CMDqueue ^= OC_MODIFY_OPEN_PARMS;
1597 tp->scb.Parm[0] = tp->ocpl.OPENOptions; /* new OPEN options*/
1598 tp->scb.Parm[0] |= ENABLE_FULL_DUPLEX_SELECTION;
1599 tp->scb.Parm[1] = 0; /* is ignored but should be zero */
1600 tp->scb.CMD = MODIFY_OPEN_PARMS;
1601 } else if (tp->CMDqueue & OC_SET_FUNCT_ADDR) {
1602 tp->CMDqueue ^= OC_SET_FUNCT_ADDR;
1603 tp->scb.Parm[0] = LOWORD(tp->ocpl.FunctAddr);
1604 tp->scb.Parm[1] = HIWORD(tp->ocpl.FunctAddr);
1605 tp->scb.CMD = SET_FUNCT_ADDR;
1606 } else if (tp->CMDqueue & OC_SET_GROUP_ADDR) {
1607 tp->CMDqueue ^= OC_SET_GROUP_ADDR;
1608 tp->scb.Parm[0] = LOWORD(tp->ocpl.GroupAddr);
1609 tp->scb.Parm[1] = HIWORD(tp->ocpl.GroupAddr);
1610 tp->scb.CMD = SET_GROUP_ADDR;
1611 } else if (tp->CMDqueue & OC_READ_ERROR_LOG) {
1612 tp->CMDqueue ^= OC_READ_ERROR_LOG;
1613 Addr = htonl(((char *)&tp->errorlogtable - (char *)tp) + tp->dmabuffer);
1614 tp->scb.Parm[0] = LOWORD(Addr);
1615 tp->scb.Parm[1] = HIWORD(Addr);
1616 tp->scb.CMD = READ_ERROR_LOG;
1617 } else {
1618 printk(KERN_WARNING "CheckForOutstandingCommand: unknown Command\n");
1619 tp->CMDqueue = 0;
1620 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 }
1622 }
1623
1624 tp->ScbInUse = 1; /* Set semaphore: SCB in use. */
1625
1626 /* Execute SCB and generate IRQ when done. */
1627 tms380tr_exec_sifcmd(dev, CMD_EXECUTE | CMD_SCB_REQUEST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628}
1629
1630/*
1631 * IRQ conditions: signal loss on the ring, transmit or receive of beacon
1632 * frames (disabled if bit 1 of OPEN option is set); report error MAC
1633 * frame transmit (disabled if bit 2 of OPEN option is set); open or short
1634 * circuit fault on the lobe is detected; remove MAC frame received;
1635 * error counter overflow (255); opened adapter is the only station in ring.
1636 * After some of the IRQs the adapter is closed!
1637 */
1638static void tms380tr_ring_status_irq(struct net_device *dev)
1639{
1640 struct net_local *tp = netdev_priv(dev);
1641
1642 tp->CurrentRingStatus = be16_to_cpu((unsigned short)tp->ssb.Parm[0]);
1643
1644 /* First: fill up statistics */
1645 if(tp->ssb.Parm[0] & SIGNAL_LOSS)
1646 {
1647 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
1648 tp->MacStat.line_errors++;
1649 }
1650
1651 /* Adapter is closed, but initialized */
1652 if(tp->ssb.Parm[0] & LOBE_WIRE_FAULT)
1653 {
1654 printk(KERN_INFO "%s: Lobe Wire Fault, Reopen Adapter\n",
1655 dev->name);
1656 tp->MacStat.line_errors++;
1657 }
1658
1659 if(tp->ssb.Parm[0] & RING_RECOVERY)
1660 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
1661
1662 /* Counter overflow: read error log */
1663 if(tp->ssb.Parm[0] & COUNTER_OVERFLOW)
1664 {
1665 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
1666 tms380tr_exec_cmd(dev, OC_READ_ERROR_LOG);
1667 }
1668
1669 /* Adapter is closed, but initialized */
1670 if(tp->ssb.Parm[0] & REMOVE_RECEIVED)
1671 printk(KERN_INFO "%s: Remove Received, Reopen Adapter\n",
1672 dev->name);
1673
1674 /* Adapter is closed, but initialized */
1675 if(tp->ssb.Parm[0] & AUTO_REMOVAL_ERROR)
1676 printk(KERN_INFO "%s: Auto Removal Error, Reopen Adapter\n",
1677 dev->name);
1678
1679 if(tp->ssb.Parm[0] & HARD_ERROR)
1680 printk(KERN_INFO "%s: Hard Error\n", dev->name);
1681
1682 if(tp->ssb.Parm[0] & SOFT_ERROR)
1683 printk(KERN_INFO "%s: Soft Error\n", dev->name);
1684
1685 if(tp->ssb.Parm[0] & TRANSMIT_BEACON)
1686 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
1687
1688 if(tp->ssb.Parm[0] & SINGLE_STATION)
1689 printk(KERN_INFO "%s: Single Station\n", dev->name);
1690
1691 /* Check if adapter has been closed */
1692 if(tp->ssb.Parm[0] & ADAPTER_CLOSED)
1693 {
1694 printk(KERN_INFO "%s: Adapter closed (Reopening),"
1695 "CurrentRingStat %x\n",
1696 dev->name, tp->CurrentRingStatus);
1697 tp->AdapterOpenFlag = 0;
1698 tms380tr_open_adapter(dev);
1699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
1702/*
1703 * Issued if adapter has encountered an unrecoverable hardware
1704 * or software error.
1705 */
1706static void tms380tr_chk_irq(struct net_device *dev)
1707{
1708 int i;
1709 unsigned short AdapterCheckBlock[4];
1710 struct net_local *tp = netdev_priv(dev);
1711
1712 tp->AdapterOpenFlag = 0; /* Adapter closed now */
1713
1714 /* Page number of adapter memory */
1715 SIFWRITEW(0x0001, SIFADX);
1716 /* Address offset */
1717 SIFWRITEW(CHECKADDR, SIFADR);
1718
1719 /* Reading 8 byte adapter check block. */
1720 for(i = 0; i < 4; i++)
1721 AdapterCheckBlock[i] = SIFREADW(SIFINC);
1722
1723 if(tms380tr_debug > 3)
1724 {
1725 printk(KERN_DEBUG "%s: AdapterCheckBlock: ", dev->name);
1726 for (i = 0; i < 4; i++)
1727 printk("%04X", AdapterCheckBlock[i]);
1728 printk("\n");
1729 }
1730
1731 switch(AdapterCheckBlock[0])
1732 {
1733 case DIO_PARITY:
1734 printk(KERN_INFO "%s: DIO parity error\n", dev->name);
1735 break;
1736
1737 case DMA_READ_ABORT:
1738 printk(KERN_INFO "%s DMA read operation aborted:\n",
1739 dev->name);
1740 switch (AdapterCheckBlock[1])
1741 {
1742 case 0:
1743 printk(KERN_INFO "Timeout\n");
1744 printk(KERN_INFO "Address: %04X %04X\n",
1745 AdapterCheckBlock[2],
1746 AdapterCheckBlock[3]);
1747 break;
1748
1749 case 1:
1750 printk(KERN_INFO "Parity error\n");
1751 printk(KERN_INFO "Address: %04X %04X\n",
1752 AdapterCheckBlock[2],
1753 AdapterCheckBlock[3]);
1754 break;
1755
1756 case 2:
1757 printk(KERN_INFO "Bus error\n");
1758 printk(KERN_INFO "Address: %04X %04X\n",
1759 AdapterCheckBlock[2],
1760 AdapterCheckBlock[3]);
1761 break;
1762
1763 default:
1764 printk(KERN_INFO "Unknown error.\n");
1765 break;
1766 }
1767 break;
1768
1769 case DMA_WRITE_ABORT:
Frans Pop014e4662010-03-24 07:57:33 +00001770 printk(KERN_INFO "%s: DMA write operation aborted:\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 dev->name);
1772 switch (AdapterCheckBlock[1])
1773 {
1774 case 0:
1775 printk(KERN_INFO "Timeout\n");
1776 printk(KERN_INFO "Address: %04X %04X\n",
1777 AdapterCheckBlock[2],
1778 AdapterCheckBlock[3]);
1779 break;
1780
1781 case 1:
1782 printk(KERN_INFO "Parity error\n");
1783 printk(KERN_INFO "Address: %04X %04X\n",
1784 AdapterCheckBlock[2],
1785 AdapterCheckBlock[3]);
1786 break;
1787
1788 case 2:
1789 printk(KERN_INFO "Bus error\n");
1790 printk(KERN_INFO "Address: %04X %04X\n",
1791 AdapterCheckBlock[2],
1792 AdapterCheckBlock[3]);
1793 break;
1794
1795 default:
1796 printk(KERN_INFO "Unknown error.\n");
1797 break;
1798 }
1799 break;
1800
1801 case ILLEGAL_OP_CODE:
1802 printk(KERN_INFO "%s: Illegal operation code in firmware\n",
1803 dev->name);
1804 /* Parm[0-3]: adapter internal register R13-R15 */
1805 break;
1806
1807 case PARITY_ERRORS:
1808 printk(KERN_INFO "%s: Adapter internal bus parity error\n",
1809 dev->name);
1810 /* Parm[0-3]: adapter internal register R13-R15 */
1811 break;
1812
1813 case RAM_DATA_ERROR:
1814 printk(KERN_INFO "%s: RAM data error\n", dev->name);
1815 /* Parm[0-1]: MSW/LSW address of RAM location. */
1816 break;
1817
1818 case RAM_PARITY_ERROR:
1819 printk(KERN_INFO "%s: RAM parity error\n", dev->name);
1820 /* Parm[0-1]: MSW/LSW address of RAM location. */
1821 break;
1822
1823 case RING_UNDERRUN:
1824 printk(KERN_INFO "%s: Internal DMA underrun detected\n",
1825 dev->name);
1826 break;
1827
1828 case INVALID_IRQ:
1829 printk(KERN_INFO "%s: Unrecognized interrupt detected\n",
1830 dev->name);
1831 /* Parm[0-3]: adapter internal register R13-R15 */
1832 break;
1833
1834 case INVALID_ERROR_IRQ:
1835 printk(KERN_INFO "%s: Unrecognized error interrupt detected\n",
1836 dev->name);
1837 /* Parm[0-3]: adapter internal register R13-R15 */
1838 break;
1839
1840 case INVALID_XOP:
1841 printk(KERN_INFO "%s: Unrecognized XOP request detected\n",
1842 dev->name);
1843 /* Parm[0-3]: adapter internal register R13-R15 */
1844 break;
1845
1846 default:
1847 printk(KERN_INFO "%s: Unknown status", dev->name);
1848 break;
1849 }
1850
1851 if(tms380tr_chipset_init(dev) == 1)
1852 {
1853 /* Restart of firmware successful */
1854 tp->AdapterOpenFlag = 1;
1855 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856}
1857
1858/*
1859 * Internal adapter pointer to RAM data are copied from adapter into
1860 * host system.
1861 */
1862static int tms380tr_read_ptr(struct net_device *dev)
1863{
1864 struct net_local *tp = netdev_priv(dev);
1865 unsigned short adapterram;
1866
1867 tms380tr_read_ram(dev, (unsigned char *)&tp->intptrs.BurnedInAddrPtr,
1868 ADAPTER_INT_PTRS, 16);
1869 tms380tr_read_ram(dev, (unsigned char *)&adapterram,
1870 cpu_to_be16((unsigned short)tp->intptrs.AdapterRAMPtr), 2);
1871 return be16_to_cpu(adapterram);
1872}
1873
1874/*
1875 * Reads a number of bytes from adapter to system memory.
1876 */
1877static void tms380tr_read_ram(struct net_device *dev, unsigned char *Data,
1878 unsigned short Address, int Length)
1879{
1880 int i;
1881 unsigned short old_sifadx, old_sifadr, InWord;
1882
1883 /* Save the current values */
1884 old_sifadx = SIFREADW(SIFADX);
1885 old_sifadr = SIFREADW(SIFADR);
1886
1887 /* Page number of adapter memory */
1888 SIFWRITEW(0x0001, SIFADX);
1889 /* Address offset in adapter RAM */
1890 SIFWRITEW(Address, SIFADR);
1891
1892 /* Copy len byte from adapter memory to system data area. */
1893 i = 0;
1894 for(;;)
1895 {
1896 InWord = SIFREADW(SIFINC);
1897
1898 *(Data + i) = HIBYTE(InWord); /* Write first byte */
1899 if(++i == Length) /* All is done break */
1900 break;
1901
1902 *(Data + i) = LOBYTE(InWord); /* Write second byte */
1903 if (++i == Length) /* All is done break */
1904 break;
1905 }
1906
1907 /* Restore original values */
1908 SIFWRITEW(old_sifadx, SIFADX);
1909 SIFWRITEW(old_sifadr, SIFADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910}
1911
1912/*
1913 * Cancel all queued packets in the transmission queue.
1914 */
1915static void tms380tr_cancel_tx_queue(struct net_local* tp)
1916{
1917 TPL *tpl;
1918
1919 /*
1920 * NOTE: There must not be an active TRANSMIT command pending, when
1921 * this function is called.
1922 */
1923 if(tp->TransmitCommandActive)
1924 return;
1925
1926 for(;;)
1927 {
1928 tpl = tp->TplBusy;
1929 if(!tpl->BusyFlag)
1930 break;
1931 /* "Remove" TPL from busy list. */
1932 tp->TplBusy = tpl->NextTPLPtr;
1933 tms380tr_write_tpl_status(tpl, 0); /* Clear VALID bit */
1934 tpl->BusyFlag = 0; /* "free" TPL */
1935
1936 printk(KERN_INFO "Cancel tx (%08lXh).\n", (unsigned long)tpl);
1937 if (tpl->DMABuff)
Jochen Friedrich504ff162005-07-27 01:14:50 -07001938 dma_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 dev_kfree_skb_any(tpl->Skb);
1940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941}
1942
1943/*
1944 * This function is called whenever a transmit interrupt is generated by the
1945 * adapter. For a command complete interrupt, it is checked if we have to
1946 * issue a new transmit command or not.
1947 */
1948static void tms380tr_tx_status_irq(struct net_device *dev)
1949{
1950 struct net_local *tp = netdev_priv(dev);
1951 unsigned char HighByte, HighAc, LowAc;
1952 TPL *tpl;
1953
1954 /* NOTE: At this point the SSB from TRANSMIT STATUS is no longer
1955 * available, because the CLEAR SSB command has already been issued.
1956 *
1957 * Process all complete transmissions.
1958 */
1959
1960 for(;;)
1961 {
1962 tpl = tp->TplBusy;
1963 if(!tpl->BusyFlag || (tpl->Status
1964 & (TX_VALID | TX_FRAME_COMPLETE))
1965 != TX_FRAME_COMPLETE)
1966 {
1967 break;
1968 }
1969
1970 /* "Remove" TPL from busy list. */
1971 tp->TplBusy = tpl->NextTPLPtr ;
1972
1973 /* Check the transmit status field only for directed frames*/
1974 if(DIRECTED_FRAME(tpl) && (tpl->Status & TX_ERROR) == 0)
1975 {
1976 HighByte = GET_TRANSMIT_STATUS_HIGH_BYTE(tpl->Status);
1977 HighAc = GET_FRAME_STATUS_HIGH_AC(HighByte);
1978 LowAc = GET_FRAME_STATUS_LOW_AC(HighByte);
1979
1980 if((HighAc != LowAc) || (HighAc == AC_NOT_RECOGNIZED))
1981 {
1982 printk(KERN_DEBUG "%s: (DA=%08lX not recognized)\n",
1983 dev->name,
1984 *(unsigned long *)&tpl->MData[2+2]);
1985 }
1986 else
1987 {
1988 if(tms380tr_debug > 3)
1989 printk(KERN_DEBUG "%s: Directed frame tx'd\n",
1990 dev->name);
1991 }
1992 }
1993 else
1994 {
1995 if(!DIRECTED_FRAME(tpl))
1996 {
1997 if(tms380tr_debug > 3)
1998 printk(KERN_DEBUG "%s: Broadcast frame tx'd\n",
1999 dev->name);
2000 }
2001 }
2002
2003 tp->MacStat.tx_packets++;
2004 if (tpl->DMABuff)
Jochen Friedrich504ff162005-07-27 01:14:50 -07002005 dma_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 dev_kfree_skb_irq(tpl->Skb);
2007 tpl->BusyFlag = 0; /* "free" TPL */
2008 }
2009
2010 if(!tp->TplFree->NextTPLPtr->BusyFlag)
2011 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012}
2013
2014/*
2015 * Called if a frame receive interrupt is generated by the adapter.
2016 * Check if the frame is valid and indicate it to system.
2017 */
2018static void tms380tr_rcv_status_irq(struct net_device *dev)
2019{
2020 struct net_local *tp = netdev_priv(dev);
2021 unsigned char *ReceiveDataPtr;
2022 struct sk_buff *skb;
2023 unsigned int Length, Length2;
2024 RPL *rpl;
2025 RPL *SaveHead;
2026 dma_addr_t dmabuf;
2027
2028 /* NOTE: At this point the SSB from RECEIVE STATUS is no longer
2029 * available, because the CLEAR SSB command has already been issued.
2030 *
2031 * Process all complete receives.
2032 */
2033
2034 for(;;)
2035 {
2036 rpl = tp->RplHead;
2037 if(rpl->Status & RX_VALID)
2038 break; /* RPL still in use by adapter */
2039
2040 /* Forward RPLHead pointer to next list. */
2041 SaveHead = tp->RplHead;
2042 tp->RplHead = rpl->NextRPLPtr;
2043
2044 /* Get the frame size (Byte swap for Intel).
2045 * Do this early (see workaround comment below)
2046 */
Al Viro2929e772007-08-23 02:57:00 -04002047 Length = be16_to_cpu(rpl->FrameSize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
2049 /* Check if the Frame_Start, Frame_End and
2050 * Frame_Complete bits are set.
2051 */
2052 if((rpl->Status & VALID_SINGLE_BUFFER_FRAME)
2053 == VALID_SINGLE_BUFFER_FRAME)
2054 {
2055 ReceiveDataPtr = rpl->MData;
2056
2057 /* Workaround for delayed write of FrameSize on ISA
2058 * (FrameSize is false but valid-bit is reset)
2059 * Frame size is set to zero when the RPL is freed.
2060 * Length2 is there because there have also been
2061 * cases where the FrameSize was partially written
2062 */
Al Viro2929e772007-08-23 02:57:00 -04002063 Length2 = be16_to_cpu(rpl->FrameSize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
2065 if(Length == 0 || Length != Length2)
2066 {
2067 tp->RplHead = SaveHead;
2068 break; /* Return to tms380tr_interrupt */
2069 }
2070 tms380tr_update_rcv_stats(tp,ReceiveDataPtr,Length);
2071
2072 if(tms380tr_debug > 3)
2073 printk(KERN_DEBUG "%s: Packet Length %04X (%d)\n",
2074 dev->name, Length, Length);
2075
2076 /* Indicate the received frame to system the
2077 * adapter does the Source-Routing padding for
2078 * us. See: OpenOptions in tms380tr_init_opb()
2079 */
2080 skb = rpl->Skb;
2081 if(rpl->SkbStat == SKB_UNAVAILABLE)
2082 {
2083 /* Try again to allocate skb */
2084 skb = dev_alloc_skb(tp->MaxPacketSize);
2085 if(skb == NULL)
2086 {
2087 /* Update Stats ?? */
2088 }
2089 else
2090 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 skb_put(skb, tp->MaxPacketSize);
2092 rpl->SkbStat = SKB_DATA_COPY;
2093 ReceiveDataPtr = rpl->MData;
2094 }
2095 }
2096
Joe Perches8e95a202009-12-03 07:58:21 +00002097 if(skb && (rpl->SkbStat == SKB_DATA_COPY ||
2098 rpl->SkbStat == SKB_DMA_DIRECT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 {
2100 if(rpl->SkbStat == SKB_DATA_COPY)
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002101 skb_copy_to_linear_data(skb, ReceiveDataPtr,
2102 Length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
2104 /* Deliver frame to system */
2105 rpl->Skb = NULL;
2106 skb_trim(skb,Length);
2107 skb->protocol = tr_type_trans(skb,dev);
2108 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 }
2110 }
2111 else /* Invalid frame */
2112 {
2113 if(rpl->Skb != NULL)
2114 dev_kfree_skb_irq(rpl->Skb);
2115
2116 /* Skip list. */
2117 if(rpl->Status & RX_START_FRAME)
2118 /* Frame start bit is set -> overflow. */
2119 tp->MacStat.rx_errors++;
2120 }
2121 if (rpl->DMABuff)
Jochen Friedrich504ff162005-07-27 01:14:50 -07002122 dma_unmap_single(tp->pdev, rpl->DMABuff, tp->MaxPacketSize, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 rpl->DMABuff = 0;
2124
2125 /* Allocate new skb for rpl */
2126 rpl->Skb = dev_alloc_skb(tp->MaxPacketSize);
2127 /* skb == NULL ? then use local buffer */
2128 if(rpl->Skb == NULL)
2129 {
2130 rpl->SkbStat = SKB_UNAVAILABLE;
2131 rpl->FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[rpl->RPLIndex] - (char *)tp) + tp->dmabuffer);
2132 rpl->MData = tp->LocalRxBuffers[rpl->RPLIndex];
2133 }
2134 else /* skb != NULL */
2135 {
2136 rpl->Skb->dev = dev;
2137 skb_put(rpl->Skb, tp->MaxPacketSize);
2138
2139 /* Data unreachable for DMA ? then use local buffer */
Jochen Friedrich504ff162005-07-27 01:14:50 -07002140 dmabuf = dma_map_single(tp->pdev, rpl->Skb->data, tp->MaxPacketSize, DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit))
2142 {
2143 rpl->SkbStat = SKB_DATA_COPY;
2144 rpl->FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[rpl->RPLIndex] - (char *)tp) + tp->dmabuffer);
2145 rpl->MData = tp->LocalRxBuffers[rpl->RPLIndex];
2146 }
2147 else
2148 {
2149 /* DMA directly in skb->data */
2150 rpl->SkbStat = SKB_DMA_DIRECT;
2151 rpl->FragList[0].DataAddr = htonl(dmabuf);
2152 rpl->MData = rpl->Skb->data;
2153 rpl->DMABuff = dmabuf;
2154 }
2155 }
2156
2157 rpl->FragList[0].DataCount = cpu_to_be16((unsigned short)tp->MaxPacketSize);
2158 rpl->FrameSize = 0;
2159
2160 /* Pass the last RPL back to the adapter */
2161 tp->RplTail->FrameSize = 0;
2162
2163 /* Reset the CSTAT field in the list. */
2164 tms380tr_write_rpl_status(tp->RplTail, RX_VALID | RX_FRAME_IRQ);
2165
2166 /* Current RPL becomes last one in list. */
2167 tp->RplTail = tp->RplTail->NextRPLPtr;
2168
2169 /* Inform adapter about RPL valid. */
2170 tms380tr_exec_sifcmd(dev, CMD_RX_VALID);
2171 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172}
2173
2174/*
2175 * This function should be used whenever the status of any RPL must be
2176 * modified by the driver, because the compiler may otherwise change the
2177 * order of instructions such that writing the RPL status may be executed
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08002178 * at an undesirable time. When this function is used, the status is
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 * always written when the function is called.
2180 */
2181static void tms380tr_write_rpl_status(RPL *rpl, unsigned int Status)
2182{
2183 rpl->Status = Status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184}
2185
2186/*
2187 * The function updates the statistic counters in mac->MacStat.
2188 * It differtiates between directed and broadcast/multicast ( ==functional)
2189 * frames.
2190 */
2191static void tms380tr_update_rcv_stats(struct net_local *tp, unsigned char DataPtr[],
2192 unsigned int Length)
2193{
2194 tp->MacStat.rx_packets++;
2195 tp->MacStat.rx_bytes += Length;
2196
2197 /* Test functional bit */
2198 if(DataPtr[2] & GROUP_BIT)
2199 tp->MacStat.multicast++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200}
2201
2202static int tms380tr_set_mac_address(struct net_device *dev, void *addr)
2203{
2204 struct net_local *tp = netdev_priv(dev);
2205 struct sockaddr *saddr = addr;
2206
2207 if (tp->AdapterOpenFlag || tp->AdapterVirtOpenFlag) {
2208 printk(KERN_WARNING "%s: Cannot set MAC/LAA address while card is open\n", dev->name);
2209 return -EIO;
2210 }
2211 memcpy(dev->dev_addr, saddr->sa_data, dev->addr_len);
2212 return 0;
2213}
2214
2215#if TMS380TR_DEBUG > 0
2216/*
2217 * Dump Packet (data)
2218 */
2219static void tms380tr_dump(unsigned char *Data, int length)
2220{
2221 int i, j;
2222
2223 for (i = 0, j = 0; i < length / 8; i++, j += 8)
2224 {
2225 printk(KERN_DEBUG "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2226 Data[j+0],Data[j+1],Data[j+2],Data[j+3],
2227 Data[j+4],Data[j+5],Data[j+6],Data[j+7]);
2228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230#endif
2231
2232void tmsdev_term(struct net_device *dev)
2233{
2234 struct net_local *tp;
2235
2236 tp = netdev_priv(dev);
Jochen Friedrich504ff162005-07-27 01:14:50 -07002237 dma_unmap_single(tp->pdev, tp->dmabuffer, sizeof(struct net_local),
2238 DMA_BIDIRECTIONAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239}
2240
Stephen Hemmingerf1608f82009-01-09 13:01:25 +00002241const struct net_device_ops tms380tr_netdev_ops = {
2242 .ndo_open = tms380tr_open,
2243 .ndo_stop = tms380tr_close,
2244 .ndo_start_xmit = tms380tr_send_packet,
2245 .ndo_tx_timeout = tms380tr_timeout,
2246 .ndo_get_stats = tms380tr_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002247 .ndo_set_rx_mode = tms380tr_set_multicast_list,
Stephen Hemmingerf1608f82009-01-09 13:01:25 +00002248 .ndo_set_mac_address = tms380tr_set_mac_address,
2249};
2250EXPORT_SYMBOL(tms380tr_netdev_ops);
2251
Jochen Friedrich84c3ea02005-08-19 21:05:56 -04002252int tmsdev_init(struct net_device *dev, struct device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
2254 struct net_local *tms_local;
2255
Wang Chen8f15ea42008-11-12 23:38:36 -08002256 memset(netdev_priv(dev), 0, sizeof(struct net_local));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 tms_local = netdev_priv(dev);
2258 init_waitqueue_head(&tms_local->wait_for_tok_int);
Jochen Friedrich84c3ea02005-08-19 21:05:56 -04002259 if (pdev->dma_mask)
2260 tms_local->dmalimit = *pdev->dma_mask;
2261 else
2262 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 tms_local->pdev = pdev;
Jochen Friedrich504ff162005-07-27 01:14:50 -07002264 tms_local->dmabuffer = dma_map_single(pdev, (void *)tms_local,
2265 sizeof(struct net_local), DMA_BIDIRECTIONAL);
Jochen Friedrich84c3ea02005-08-19 21:05:56 -04002266 if (tms_local->dmabuffer + sizeof(struct net_local) >
2267 tms_local->dmalimit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 {
2269 printk(KERN_INFO "%s: Memory not accessible for DMA\n",
2270 dev->name);
2271 tmsdev_term(dev);
2272 return -ENOMEM;
2273 }
2274
Stephen Hemmingerf1608f82009-01-09 13:01:25 +00002275 dev->netdev_ops = &tms380tr_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 dev->watchdog_timeo = HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
2278 return 0;
2279}
2280
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281EXPORT_SYMBOL(tms380tr_open);
2282EXPORT_SYMBOL(tms380tr_close);
2283EXPORT_SYMBOL(tms380tr_interrupt);
2284EXPORT_SYMBOL(tmsdev_init);
2285EXPORT_SYMBOL(tmsdev_term);
2286EXPORT_SYMBOL(tms380tr_wait);
2287
Jochen Friedrich504ff162005-07-27 01:14:50 -07002288#ifdef MODULE
2289
Adrian Bunkde70b4c2005-05-02 03:46:43 +02002290static struct module *TMS380_module = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292int init_module(void)
2293{
2294 printk(KERN_DEBUG "%s", version);
2295
2296 TMS380_module = &__this_module;
2297 return 0;
2298}
2299
2300void cleanup_module(void)
2301{
2302 TMS380_module = NULL;
2303}
2304#endif
2305
2306MODULE_LICENSE("GPL");
2307