blob: b5e0855e4b39836cf6bc2bb52a8e9d1e373dbdc9 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#include <asm/io.h>
102#include <asm/dma.h>
103#include <asm/irq.h>
104#include <asm/uaccess.h>
105
106#include "tms380tr.h" /* Our Stuff */
107
108/* Use 0 for production, 1 for verification, 2 for debug, and
109 * 3 for very verbose debug.
110 */
111#ifndef TMS380TR_DEBUG
112#define TMS380TR_DEBUG 0
113#endif
114static unsigned int tms380tr_debug = TMS380TR_DEBUG;
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/* Index to functions, as function prototypes.
117 * Alphabetical by function name.
118 */
119
120/* "A" */
121/* "B" */
122static int tms380tr_bringup_diags(struct net_device *dev);
123/* "C" */
124static void tms380tr_cancel_tx_queue(struct net_local* tp);
125static int tms380tr_chipset_init(struct net_device *dev);
126static void tms380tr_chk_irq(struct net_device *dev);
127static void tms380tr_chk_outstanding_cmds(struct net_device *dev);
128static void tms380tr_chk_src_addr(unsigned char *frame, unsigned char *hw_addr);
129static unsigned char tms380tr_chk_ssb(struct net_local *tp, unsigned short IrqType);
130int tms380tr_close(struct net_device *dev);
131static void tms380tr_cmd_status_irq(struct net_device *dev);
132/* "D" */
133static void tms380tr_disable_interrupts(struct net_device *dev);
134#if TMS380TR_DEBUG > 0
135static void tms380tr_dump(unsigned char *Data, int length);
136#endif
137/* "E" */
138static void tms380tr_enable_interrupts(struct net_device *dev);
139static void tms380tr_exec_cmd(struct net_device *dev, unsigned short Command);
140static void tms380tr_exec_sifcmd(struct net_device *dev, unsigned int WriteValue);
141/* "F" */
142/* "G" */
143static struct net_device_stats *tms380tr_get_stats(struct net_device *dev);
144/* "H" */
Stephen Hemminger61a84102009-08-31 19:50:46 +0000145static netdev_tx_t tms380tr_hardware_send_packet(struct sk_buff *skb,
146 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147/* "I" */
148static int tms380tr_init_adapter(struct net_device *dev);
149static void tms380tr_init_ipb(struct net_local *tp);
150static void tms380tr_init_net_local(struct net_device *dev);
151static void tms380tr_init_opb(struct net_device *dev);
152/* "M" */
153/* "O" */
154int tms380tr_open(struct net_device *dev);
155static void tms380tr_open_adapter(struct net_device *dev);
156/* "P" */
157/* "R" */
158static void tms380tr_rcv_status_irq(struct net_device *dev);
159static int tms380tr_read_ptr(struct net_device *dev);
160static void tms380tr_read_ram(struct net_device *dev, unsigned char *Data,
161 unsigned short Address, int Length);
162static int tms380tr_reset_adapter(struct net_device *dev);
163static void tms380tr_reset_interrupt(struct net_device *dev);
164static void tms380tr_ring_status_irq(struct net_device *dev);
165/* "S" */
Stephen Hemminger61a84102009-08-31 19:50:46 +0000166static netdev_tx_t tms380tr_send_packet(struct sk_buff *skb,
167 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168static void tms380tr_set_multicast_list(struct net_device *dev);
169static int tms380tr_set_mac_address(struct net_device *dev, void *addr);
170/* "T" */
171static void tms380tr_timer_chk(unsigned long data);
172static void tms380tr_timer_end_wait(unsigned long data);
173static void tms380tr_tx_status_irq(struct net_device *dev);
174/* "U" */
175static void tms380tr_update_rcv_stats(struct net_local *tp,
176 unsigned char DataPtr[], unsigned int Length);
177/* "W" */
178void tms380tr_wait(unsigned long time);
179static void tms380tr_write_rpl_status(RPL *rpl, unsigned int Status);
180static void tms380tr_write_tpl_status(TPL *tpl, unsigned int Status);
181
Wang Chen8f15ea42008-11-12 23:38:36 -0800182#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))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191
192
193#if 0 /* TMS380TR_DEBUG > 0 */
194static int madgemc_sifprobe(struct net_device *dev)
195{
196 unsigned char old, chk1, chk2;
197
198 old = SIFREADB(SIFADR); /* Get the old SIFADR value */
199
200 chk1 = 0; /* Begin with check value 0 */
201 do {
202 madgemc_setregpage(dev, 0);
203 /* Write new SIFADR value */
204 SIFWRITEB(chk1, SIFADR);
205 chk2 = SIFREADB(SIFADR);
206 if (chk2 != chk1)
207 return -1;
208
209 madgemc_setregpage(dev, 1);
210 /* Read, invert and write */
211 chk2 = SIFREADB(SIFADD);
212 if (chk2 != chk1)
213 return -1;
214
215 madgemc_setregpage(dev, 0);
216 chk2 ^= 0x0FE;
217 SIFWRITEB(chk2, SIFADR);
218
219 /* Read, invert and compare */
220 madgemc_setregpage(dev, 1);
221 chk2 = SIFREADB(SIFADD);
222 madgemc_setregpage(dev, 0);
223 chk2 ^= 0x0FE;
224
225 if(chk1 != chk2)
Eric Dumazet807540b2010-09-23 05:40:09 +0000226 return -1; /* No adapter */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 chk1 -= 2;
228 } while(chk1 != 0); /* Repeat 128 times (all byte values) */
229
230 madgemc_setregpage(dev, 0); /* sanity */
231 /* Restore the SIFADR value */
232 SIFWRITEB(old, SIFADR);
233
Eric Dumazet807540b2010-09-23 05:40:09 +0000234 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236#endif
237
238/*
239 * Open/initialize the board. This is called sometime after
240 * booting when the 'ifconfig' program is run.
241 *
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.
245 */
246int tms380tr_open(struct net_device *dev)
247{
248 struct net_local *tp = netdev_priv(dev);
249 int err;
250
251 /* init the spinlock */
252 spin_lock_init(&tp->lock);
253 init_timer(&tp->timer);
254
255 /* Reset the hardware here. Don't forget to set the station address. */
256
Arnd Bergmann59c55bd2012-04-20 10:56:16 +0000257#if defined(CONFIG_ISA) && defined(CONFIG_ISA_DMA_API)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if(dev->dma > 0)
259 {
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);
265 }
266#endif
267
268 err = tms380tr_chipset_init(dev);
269 if(err)
270 {
271 printk(KERN_INFO "%s: Chipset initialization error\n",
272 dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +0000273 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
275
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);
280
281 printk(KERN_DEBUG "%s: Adapter RAM size: %dK\n",
282 dev->name, tms380tr_read_ptr(dev));
283
284 tms380tr_enable_interrupts(dev);
285 tms380tr_open_adapter(dev);
286
287 netif_start_queue(dev);
288
289 /* Wait for interrupt from hardware. If interrupt does not come,
290 * there will be a timeout from the timer.
291 */
292 tp->Sleeping = 1;
293 interruptible_sleep_on(&tp->wait_for_tok_int);
294 del_timer(&tp->timer);
295
296 /* If AdapterVirtOpenFlag is 1, the adapter is now open for use */
297 if(tp->AdapterVirtOpenFlag == 0)
298 {
299 tms380tr_disable_interrupts(dev);
Eric Dumazet807540b2010-09-23 05:40:09 +0000300 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 }
302
303 tp->StartTime = jiffies;
304
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);
310
Eric Dumazet807540b2010-09-23 05:40:09 +0000311 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312}
313
314/*
315 * Timeout function while waiting for event
316 */
317static void tms380tr_timer_end_wait(unsigned long data)
318{
319 struct net_device *dev = (struct net_device*)data;
320 struct net_local *tp = netdev_priv(dev);
321
322 if(tp->Sleeping)
323 {
324 tp->Sleeping = 0;
325 wake_up_interruptible(&tp->wait_for_tok_int);
326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327}
328
329/*
330 * Initialize the chipset
331 */
332static int tms380tr_chipset_init(struct net_device *dev)
333{
334 struct net_local *tp = netdev_priv(dev);
335 int err;
336
337 tms380tr_init_ipb(tp);
338 tms380tr_init_opb(dev);
339 tms380tr_init_net_local(dev);
340
341 if(tms380tr_debug > 3)
342 printk(KERN_DEBUG "%s: Resetting adapter...\n", dev->name);
343 err = tms380tr_reset_adapter(dev);
344 if(err < 0)
Eric Dumazet807540b2010-09-23 05:40:09 +0000345 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 if(tms380tr_debug > 3)
348 printk(KERN_DEBUG "%s: Bringup diags...\n", dev->name);
349 err = tms380tr_bringup_diags(dev);
350 if(err < 0)
Eric Dumazet807540b2010-09-23 05:40:09 +0000351 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 if(tms380tr_debug > 3)
354 printk(KERN_DEBUG "%s: Init adapter...\n", dev->name);
355 err = tms380tr_init_adapter(dev);
356 if(err < 0)
Eric Dumazet807540b2010-09-23 05:40:09 +0000357 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 if(tms380tr_debug > 3)
360 printk(KERN_DEBUG "%s: Done!\n", dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +0000361 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
364/*
365 * Initializes the net_local structure.
366 */
367static void tms380tr_init_net_local(struct net_device *dev)
368{
369 struct net_local *tp = netdev_priv(dev);
370 int i;
371 dma_addr_t dmabuf;
372
373 tp->scb.CMD = 0;
374 tp->scb.Parm[0] = 0;
375 tp->scb.Parm[1] = 0;
376
377 tp->ssb.STS = 0;
378 tp->ssb.Parm[0] = 0;
379 tp->ssb.Parm[1] = 0;
380 tp->ssb.Parm[2] = 0;
381
382 tp->CMDqueue = 0;
383
384 tp->AdapterOpenFlag = 0;
385 tp->AdapterVirtOpenFlag = 0;
386 tp->ScbInUse = 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;
394
395 /* Create circular chain of transmit lists */
396 for (i = 0; i < TPL_NUM; i++)
397 {
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;
408 }
409
410 tp->TplFree = tp->TplBusy = &tp->Tpl[0];
411
412 /* Create circular chain of receive lists */
413 for (i = 0; i < RPL_NUM; i++)
414 {
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);
419
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;
423
424 /* skb == NULL ? then use local buffer */
425 if(tp->Rpl[i].Skb == NULL)
426 {
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];
430 }
431 else /* SKB != NULL */
432 {
433 tp->Rpl[i].Skb->dev = dev;
434 skb_put(tp->Rpl[i].Skb, tp->MaxPacketSize);
435
436 /* data unreachable for DMA ? then use local buffer */
Jochen Friedrich504ff162005-07-27 01:14:50 -0700437 dmabuf = dma_map_single(tp->pdev, tp->Rpl[i].Skb->data, tp->MaxPacketSize, DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit))
439 {
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];
443 }
444 else /* DMA directly in skb->data */
445 {
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;
450 }
451 }
452
453 tp->Rpl[i].NextRPLPtr = &tp->Rpl[(i+1) % RPL_NUM];
454 tp->Rpl[i].RPLIndex = i;
455 }
456
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460}
461
462/*
463 * Initializes the initialisation parameter block.
464 */
465static void tms380tr_init_ipb(struct net_local *tp)
466{
467 tp->ipb.Init_Options = BURST_MODE;
468 tp->ipb.CMD_Status_IV = 0;
469 tp->ipb.TX_IV = 0;
470 tp->ipb.RX_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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
481/*
482 * Initializes the open parameter block.
483 */
484static void tms380tr_init_opb(struct net_device *dev)
485{
486 struct net_local *tp;
487 unsigned long Addr;
488 unsigned short RplSize = RPL_SIZE;
489 unsigned short TplSize = TPL_SIZE;
490 unsigned short BufferSize = BUFFER_SIZE;
491 int i;
492
493 tp = netdev_priv(dev);
494
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;
499
500 /*
501 * Set node address
502 *
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
506 */
507 for (i=0;i<6;i++)
508 tp->ocpl.NodeAddr[i] = ((unsigned char *)dev->dev_addr)[i];
509
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;
518
519 Addr = htonl(((char *)tp->ProductID - (char *)tp) + tp->dmabuffer);
520
521 tp->ocpl.ProdIDAddr[0] = LOWORD(Addr);
522 tp->ocpl.ProdIDAddr[1] = HIWORD(Addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523}
524
525/*
526 * Send OPEN command to adapter
527 */
528static void tms380tr_open_adapter(struct net_device *dev)
529{
530 struct net_local *tp = netdev_priv(dev);
531
532 if(tp->OpenCommandIssued)
533 return;
534
535 tp->OpenCommandIssued = 1;
536 tms380tr_exec_cmd(dev, OC_OPEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
539/*
540 * Clear the adapter's interrupt flag. Clear system interrupt enable
541 * (SINTEN): disable adapter to system interrupts.
542 */
543static void tms380tr_disable_interrupts(struct net_device *dev)
544{
545 SIFWRITEB(0, SIFACL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
547
548/*
549 * Set the adapter's interrupt flag. Set system interrupt enable
550 * (SINTEN): enable adapter to system interrupts.
551 */
552static void tms380tr_enable_interrupts(struct net_device *dev)
553{
554 SIFWRITEB(ACL_SINTEN, SIFACL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555}
556
557/*
558 * Put command in command queue, try to execute it.
559 */
560static void tms380tr_exec_cmd(struct net_device *dev, unsigned short Command)
561{
562 struct net_local *tp = netdev_priv(dev);
563
564 tp->CMDqueue |= Command;
565 tms380tr_chk_outstanding_cmds(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
567
568static void tms380tr_timeout(struct net_device *dev)
569{
570 /*
571 * If we get here, some higher level has decided we are broken.
572 * There should really be a "kick me" function call instead.
573 *
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()
577 */
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700578 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 netif_wake_queue(dev);
580}
581
582/*
583 * Gets skb from system, queues it and checks if it can be sent
584 */
Stephen Hemminger61a84102009-08-31 19:50:46 +0000585static netdev_tx_t tms380tr_send_packet(struct sk_buff *skb,
586 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
588 struct net_local *tp = netdev_priv(dev);
Stephen Hemminger61a84102009-08-31 19:50:46 +0000589 netdev_tx_t rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Stephen Hemminger61a84102009-08-31 19:50:46 +0000591 rc = tms380tr_hardware_send_packet(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 if(tp->TplFree->NextTPLPtr->BusyFlag)
593 netif_stop_queue(dev);
Stephen Hemminger61a84102009-08-31 19:50:46 +0000594 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
597/*
598 * Move frames into adapter tx queue
599 */
Stephen Hemminger61a84102009-08-31 19:50:46 +0000600static netdev_tx_t tms380tr_hardware_send_packet(struct sk_buff *skb,
601 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 TPL *tpl;
604 short length;
605 unsigned char *buf;
606 unsigned long flags;
607 int i;
608 dma_addr_t dmabuf, newbuf;
609 struct net_local *tp = netdev_priv(dev);
610
611 /* Try to get a free TPL from the chain.
612 *
613 * NOTE: We *must* always leave one unused TPL in the chain,
614 * because otherwise the adapter might send frames twice.
615 */
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);
Patrick McHardy5b548142009-06-12 06:22:29 +0000621 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 }
623
624 dmabuf = 0;
625
626 /* Is buffer reachable for Busmaster-DMA? */
627
628 length = skb->len;
Jochen Friedrich504ff162005-07-27 01:14:50 -0700629 dmabuf = dma_map_single(tp->pdev, skb->data, length, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 if(tp->dmalimit && (dmabuf + length > tp->dmalimit)) {
631 /* Copy frame to local buffer */
Jochen Friedrich504ff162005-07-27 01:14:50 -0700632 dma_unmap_single(tp->pdev, dmabuf, length, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 dmabuf = 0;
634 i = tp->TplFree->TPLIndex;
635 buf = tp->LocalTxBuffers[i];
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300636 skb_copy_from_linear_data(skb, buf, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 newbuf = ((char *)buf - (char *)tp) + tp->dmabuffer;
638 }
639 else {
640 /* Send direct from skb->data */
641 newbuf = dmabuf;
642 buf = skb->data;
643 }
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;
650
651 /* Save the skb for delayed return of skb to system */
652 tpl->Skb = skb;
653 tpl->DMABuff = dmabuf;
654 tpl->FragList[0].DataCount = cpu_to_be16((unsigned short)length);
655 tpl->FragList[0].DataAddr = htonl(newbuf);
656
657 /* Write the data length in the transmit list. */
658 tpl->FrameSize = cpu_to_be16((unsigned short)length);
659 tpl->MData = buf;
660
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
664 | TX_FRAME_IRQ);
665
666 /* Let adapter send the frame. */
667 tms380tr_exec_sifcmd(dev, CMD_TX_VALID);
668 spin_unlock_irqrestore(&tp->lock, flags);
669
Patrick McHardyec634fe2009-07-05 19:23:38 -0700670 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671}
672
673/*
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
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800678 * an undesirable time. When this function is used, the status is always
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 * written when the function is called.
680 */
681static void tms380tr_write_tpl_status(TPL *tpl, unsigned int Status)
682{
683 tpl->Status = Status;
684}
685
686static void tms380tr_chk_src_addr(unsigned char *frame, unsigned char *hw_addr)
687{
688 unsigned char SRBit;
689
690 if((((unsigned long)frame[8]) & ~0x80) != 0) /* Compare 4 bytes */
691 return;
692 if((unsigned short)frame[12] != 0) /* Compare 2 bytes */
693 return;
694
695 SRBit = frame[8] & 0x80;
696 memcpy(&frame[8], hw_addr, 6);
697 frame[8] |= SRBit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
700/*
701 * The timer routine: Check if adapter still open and working, reopen if not.
702 */
703static void tms380tr_timer_chk(unsigned long data)
704{
705 struct net_device *dev = (struct net_device*)data;
706 struct net_local *tp = netdev_priv(dev);
707
708 if(tp->HaltInProgress)
709 return;
710
711 tms380tr_chk_outstanding_cmds(dev);
Joe Perches8e95a202009-12-03 07:58:21 +0000712 if(time_before(tp->LastSendTime + SEND_TIMEOUT, jiffies) &&
713 (tp->TplFree != tp->TplBusy))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 {
715 /* Anything to send, but stalled too long */
716 tp->LastSendTime = jiffies;
717 tms380tr_exec_cmd(dev, OC_CLOSE); /* Does reopen automatically */
718 }
719
720 tp->timer.expires = jiffies + 2*HZ;
721 add_timer(&tp->timer);
722
723 if(tp->AdapterOpenFlag || tp->ReOpenInProgress)
724 return;
725 tp->ReOpenInProgress = 1;
726 tms380tr_open_adapter(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
729/*
730 * The typical workload of the driver: Handle the network interface interrupts.
731 */
David Howells7d12e782006-10-05 14:55:46 +0100732irqreturn_t tms380tr_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
734 struct net_device *dev = dev_id;
735 struct net_local *tp;
736 unsigned short irq_type;
737 int handled = 0;
738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 tp = netdev_priv(dev);
740
741 irq_type = SIFREADW(SIFSTS);
742
743 while(irq_type & STS_SYSTEM_IRQ) {
744 handled = 1;
745 irq_type &= STS_IRQ_MASK;
746
747 if(!tms380tr_chk_ssb(tp, irq_type)) {
748 printk(KERN_DEBUG "%s: DATA LATE occurred\n", dev->name);
749 break;
750 }
751
752 switch(irq_type) {
753 case STS_IRQ_RECEIVE_STATUS:
754 tms380tr_reset_interrupt(dev);
755 tms380tr_rcv_status_irq(dev);
756 break;
757
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;
763
764 /* Issue a new transmit command. */
765 tms380tr_exec_cmd(dev, OC_TRANSMIT);
766 }
767
768 tms380tr_reset_interrupt(dev);
769 tms380tr_tx_status_irq(dev);
770 break;
771
772 case STS_IRQ_COMMAND_STATUS:
773 /* The SSB contains status of last command
774 * other than receive/transmit.
775 */
776 tms380tr_cmd_status_irq(dev);
777 break;
778
779 case STS_IRQ_SCB_CLEAR:
780 /* The SCB is free for another command. */
781 tp->ScbInUse = 0;
782 tms380tr_chk_outstanding_cmds(dev);
783 break;
784
785 case STS_IRQ_RING_STATUS:
786 tms380tr_ring_status_irq(dev);
787 break;
788
789 case STS_IRQ_ADAPTER_CHECK:
790 tms380tr_chk_irq(dev);
791 break;
792
793 case STS_IRQ_LLC_STATUS:
794 printk(KERN_DEBUG "tms380tr: unexpected LLC status IRQ\n");
795 break;
796
797 case STS_IRQ_TIMER:
798 printk(KERN_DEBUG "tms380tr: unexpected Timer IRQ\n");
799 break;
800
801 case STS_IRQ_RECEIVE_PENDING:
802 printk(KERN_DEBUG "tms380tr: unexpected Receive Pending IRQ\n");
803 break;
804
805 default:
806 printk(KERN_DEBUG "Unknown Token Ring IRQ (0x%04x)\n", irq_type);
807 break;
808 }
809
810 /* Reset system interrupt if not already done. */
Joe Perches8e95a202009-12-03 07:58:21 +0000811 if(irq_type != STS_IRQ_TRANSMIT_STATUS &&
812 irq_type != STS_IRQ_RECEIVE_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 tms380tr_reset_interrupt(dev);
814 }
815
816 irq_type = SIFREADW(SIFSTS);
817 }
818
819 return IRQ_RETVAL(handled);
820}
821
822/*
823 * Reset the INTERRUPT SYSTEM bit and issue SSB CLEAR command.
824 */
825static void tms380tr_reset_interrupt(struct net_device *dev)
826{
827 struct net_local *tp = netdev_priv(dev);
828 SSB *ssb = &tp->ssb;
829
830 /*
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.
834 */
835
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;
840
841 /* Free SSB by issuing SSB_CLEAR command after reading IRQ code
842 * and clear STS_SYSTEM_IRQ bit: enable adapter for further interrupts.
843 */
844 tms380tr_exec_sifcmd(dev, CMD_SSB_CLEAR | CMD_CLEAR_SYSTEM_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845}
846
847/*
848 * Check if the SSB has actually been written by the adapter.
849 */
850static unsigned char tms380tr_chk_ssb(struct net_local *tp, unsigned short IrqType)
851{
852 SSB *ssb = &tp->ssb; /* The address of the SSB. */
853
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
859 * 0 0 0 0 SCB CLEAR
860 * 1 1 0 0 RING STATUS
861 * 0 0 0 0 ADAPTER CHECK
862 *
863 * 0 = SSB field not affected by interrupt
864 * 1 = SSB field is affected by interrupt
865 *
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
870 */
871
872 /* Check if this interrupt does use the SSB. */
873
Joe Perches8e95a202009-12-03 07:58:21 +0000874 if(IrqType != STS_IRQ_TRANSMIT_STATUS &&
875 IrqType != STS_IRQ_RECEIVE_STATUS &&
876 IrqType != STS_IRQ_COMMAND_STATUS &&
877 IrqType != STS_IRQ_RING_STATUS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 {
Eric Dumazet807540b2010-09-23 05:40:09 +0000879 return 1; /* SSB not involved. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
881
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()).
884 *
885 * Check if the affected SSB fields are still unchanged.
886 */
887
888 if(ssb->STS == (unsigned short) -1)
Eric Dumazet807540b2010-09-23 05:40:09 +0000889 return 0; /* Command field not yet available. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 if(IrqType == STS_IRQ_COMMAND_STATUS)
Eric Dumazet807540b2010-09-23 05:40:09 +0000891 return 1; /* Status fields not always affected. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 if(ssb->Parm[0] == (unsigned short) -1)
Eric Dumazet807540b2010-09-23 05:40:09 +0000893 return 0; /* Status 1 field not yet available. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 if(IrqType == STS_IRQ_RING_STATUS)
Eric Dumazet807540b2010-09-23 05:40:09 +0000895 return 1; /* Status 2 & 3 fields not affected. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897 /* Note: At this point, the interrupt is either TRANSMIT or RECEIVE. */
898 if(ssb->Parm[1] == (unsigned short) -1)
Eric Dumazet807540b2010-09-23 05:40:09 +0000899 return 0; /* Status 2 field not yet available. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 if(ssb->Parm[2] == (unsigned short) -1)
Eric Dumazet807540b2010-09-23 05:40:09 +0000901 return 0; /* Status 3 field not yet available. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Eric Dumazet807540b2010-09-23 05:40:09 +0000903 return 1; /* All SSB fields have been written by the adapter. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904}
905
906/*
907 * Evaluates the command results status in the SSB status field.
908 */
909static void tms380tr_cmd_status_irq(struct net_device *dev)
910{
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 -";
916
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];
921
922 if(ssb_cmd == OPEN)
923 {
924 tp->Sleeping = 0;
925 if(!tp->ReOpenInProgress)
926 wake_up_interruptible(&tp->wait_for_tok_int);
927
928 tp->OpenCommandIssued = 0;
929 tp->ScbInUse = 0;
930
931 if((ssb_parm_0 & 0x00FF) == GOOD_COMPLETION)
932 {
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);
940
941 if(tp->ReOpenInProgress)
942 tp->ReOpenInProgress = 0;
943
944 return;
945 }
946 else /* The adapter did not open. */
947 {
948 if(ssb_parm_0 & NODE_ADDR_ERROR)
949 printk(KERN_INFO "%s: Node address error\n",
950 dev->name);
951 if(ssb_parm_0 & LIST_SIZE_ERROR)
952 printk(KERN_INFO "%s: List size error\n",
953 dev->name);
954 if(ssb_parm_0 & BUF_SIZE_ERROR)
955 printk(KERN_INFO "%s: Buffer size error\n",
956 dev->name);
957 if(ssb_parm_0 & TX_BUF_COUNT_ERROR)
958 printk(KERN_INFO "%s: Tx buffer count error\n",
959 dev->name);
960 if(ssb_parm_0 & INVALID_OPEN_OPTION)
961 printk(KERN_INFO "%s: Invalid open option\n",
962 dev->name);
963 if(ssb_parm_0 & OPEN_ERROR)
964 {
965 /* Show the open phase. */
966 switch(ssb_parm_0 & OPEN_PHASES_MASK)
967 {
968 case LOBE_MEDIA_TEST:
969 if(!tp->LobeWireFaultLogged)
970 {
971 tp->LobeWireFaultLogged = 1;
972 printk(KERN_INFO "%s: %s Lobe wire fault (check cable !).\n", dev->name, open_err);
973 }
974 tp->ReOpenInProgress = 1;
975 tp->AdapterOpenFlag = 0;
976 tp->AdapterVirtOpenFlag = 1;
977 tms380tr_open_adapter(dev);
978 return;
979
980 case PHYSICAL_INSERTION:
981 printk(KERN_INFO "%s: %s Physical insertion.\n", dev->name, open_err);
982 break;
983
984 case ADDRESS_VERIFICATION:
985 printk(KERN_INFO "%s: %s Address verification.\n", dev->name, open_err);
986 break;
987
988 case PARTICIPATION_IN_RING_POLL:
989 printk(KERN_INFO "%s: %s Participation in ring poll.\n", dev->name, open_err);
990 break;
991
992 case REQUEST_INITIALISATION:
993 printk(KERN_INFO "%s: %s Request initialisation.\n", dev->name, open_err);
994 break;
995
996 case FULLDUPLEX_CHECK:
997 printk(KERN_INFO "%s: %s Full duplex check.\n", dev->name, open_err);
998 break;
999
1000 default:
1001 printk(KERN_INFO "%s: %s Unknown open phase\n", dev->name, open_err);
1002 break;
1003 }
1004
1005 /* Show the open errors. */
1006 switch(ssb_parm_0 & OPEN_ERROR_CODES_MASK)
1007 {
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;
1012 break;
1013
1014 case OPEN_SIGNAL_LOSS:
1015 printk(KERN_INFO "%s: %s OPEN_SIGNAL_LOSS\n", dev->name, code_err);
1016 tp->LastOpenStatus =
1017 OPEN_SIGNAL_LOSS;
1018 break;
1019
1020 case OPEN_TIMEOUT:
1021 printk(KERN_INFO "%s: %s OPEN_TIMEOUT\n", dev->name, code_err);
1022 tp->LastOpenStatus =
1023 OPEN_TIMEOUT;
1024 break;
1025
1026 case OPEN_RING_FAILURE:
1027 printk(KERN_INFO "%s: %s OPEN_RING_FAILURE\n", dev->name, code_err);
1028 tp->LastOpenStatus =
1029 OPEN_RING_FAILURE;
1030 break;
1031
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;
1036 break;
1037
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;
1042 break;
1043
1044 case OPEN_REQUEST_INIT:
1045 printk(KERN_INFO "%s: %s OPEN_REQUEST_INIT\n", dev->name, code_err);
1046 tp->LastOpenStatus =
1047 OPEN_REQUEST_INIT;
1048 break;
1049
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;
1054 break;
1055
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;
1060 break;
1061
1062 default:
1063 printk(KERN_INFO "%s: %s Unknown open err code", dev->name, code_err);
1064 tp->LastOpenStatus =
1065 OPEN_FUNCTION_FAILURE;
1066 break;
1067 }
1068 }
1069
1070 tp->AdapterOpenFlag = 0;
1071 tp->AdapterVirtOpenFlag = 0;
1072
1073 return;
1074 }
1075 }
1076 else
1077 {
1078 if(ssb_cmd != READ_ERROR_LOG)
1079 return;
1080
1081 /* Add values from the error log table to the MAC
1082 * statistics counters and update the errorlogtable
1083 * memory.
1084 */
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;
1098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
1101/*
1102 * The inverse routine to tms380tr_open().
1103 */
1104int tms380tr_close(struct net_device *dev)
1105{
1106 struct net_local *tp = netdev_priv(dev);
1107 netif_stop_queue(dev);
1108
1109 del_timer(&tp->timer);
1110
1111 /* Flush the Tx and disable Rx here. */
1112
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);
1119
1120 tms380tr_enable_interrupts(dev);
1121
1122 tp->Sleeping = 1;
1123 interruptible_sleep_on(&tp->wait_for_tok_int);
1124 tp->TransmitCommandActive = 0;
1125
1126 del_timer(&tp->timer);
1127 tms380tr_disable_interrupts(dev);
Arnd Bergmann59c55bd2012-04-20 10:56:16 +00001128
1129#if defined(CONFIG_ISA) && defined(CONFIG_ISA_DMA_API)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 if(dev->dma > 0)
1131 {
1132 unsigned long flags=claim_dma_lock();
1133 disable_dma(dev->dma);
1134 release_dma_lock(flags);
1135 }
1136#endif
1137
1138 SIFWRITEW(0xFF00, SIFCMD);
1139#if 0
1140 if(dev->dma > 0) /* what the? */
1141 SIFWRITEB(0xff, POSREG);
1142#endif
1143 tms380tr_cancel_tx_queue(tp);
1144
Eric Dumazet807540b2010-09-23 05:40:09 +00001145 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
1148/*
1149 * Get the current statistics. This may be called with the card open
1150 * or closed.
1151 */
1152static struct net_device_stats *tms380tr_get_stats(struct net_device *dev)
1153{
1154 struct net_local *tp = netdev_priv(dev);
1155
Eric Dumazet807540b2010-09-23 05:40:09 +00001156 return (struct net_device_stats *)&tp->MacStat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157}
1158
1159/*
1160 * Set or clear the multicast filter for this adapter.
1161 */
1162static void tms380tr_set_multicast_list(struct net_device *dev)
1163{
1164 struct net_local *tp = netdev_priv(dev);
1165 unsigned int OpenOptions;
1166
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);
1173
1174 tp->ocpl.FunctAddr = 0;
1175
1176 if(dev->flags & IFF_PROMISC)
1177 /* Enable promiscuous mode */
1178 OpenOptions |= COPY_ALL_NON_MAC_FRAMES |
1179 COPY_ALL_MAC_FRAMES;
1180 else
1181 {
1182 if(dev->flags & IFF_ALLMULTI)
1183 {
1184 /* Disable promiscuous mode, use normal mode. */
1185 tp->ocpl.FunctAddr = 0xFFFFFFFF;
1186 }
1187 else
1188 {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001189 struct netdev_hw_addr *ha;
Jiri Pirko16cad982010-02-18 02:47:07 +00001190
Jiri Pirko22bedad32010-04-01 21:22:57 +00001191 netdev_for_each_mc_addr(ha, dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 ((char *)(&tp->ocpl.FunctAddr))[0] |=
Jiri Pirko22bedad32010-04-01 21:22:57 +00001193 ha->addr[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 ((char *)(&tp->ocpl.FunctAddr))[1] |=
Jiri Pirko22bedad32010-04-01 21:22:57 +00001195 ha->addr[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 ((char *)(&tp->ocpl.FunctAddr))[2] |=
Jiri Pirko22bedad32010-04-01 21:22:57 +00001197 ha->addr[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 ((char *)(&tp->ocpl.FunctAddr))[3] |=
Jiri Pirko22bedad32010-04-01 21:22:57 +00001199 ha->addr[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 }
1201 }
1202 tms380tr_exec_cmd(dev, OC_SET_FUNCT_ADDR);
1203 }
1204
1205 tp->ocpl.OPENOptions = OpenOptions;
1206 tms380tr_exec_cmd(dev, OC_MODIFY_OPEN_PARMS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207}
1208
1209/*
1210 * Wait for some time (microseconds)
1211 */
1212void tms380tr_wait(unsigned long time)
1213{
1214#if 0
1215 long tmp;
1216
1217 tmp = jiffies + time/(1000000/HZ);
1218 do {
Nishanth Aravamudan3173c892005-09-11 02:09:55 -07001219 tmp = schedule_timeout_interruptible(tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 } while(time_after(tmp, jiffies));
1221#else
David S. Miller5202e172010-10-25 13:04:48 -07001222 mdelay(time / 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224}
1225
1226/*
1227 * Write a command value to the SIFCMD register
1228 */
1229static void tms380tr_exec_sifcmd(struct net_device *dev, unsigned int WriteValue)
1230{
1231 unsigned short cmd;
1232 unsigned short SifStsValue;
1233 unsigned long loop_counter;
1234
1235 WriteValue = ((WriteValue ^ CMD_SYSTEM_IRQ) | CMD_INTERRUPT_ADAPTER);
1236 cmd = (unsigned short)WriteValue;
1237 loop_counter = 0,5 * 800000;
1238 do {
1239 SifStsValue = SIFREADW(SIFSTS);
1240 } while((SifStsValue & CMD_INTERRUPT_ADAPTER) && loop_counter--);
1241 SIFWRITEW(cmd, SIFCMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242}
1243
1244/*
1245 * Processes adapter hardware reset, halts adapter and downloads firmware,
1246 * clears the halt bit.
1247 */
1248static int tms380tr_reset_adapter(struct net_device *dev)
1249{
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;
1254
Jochen Friedrich504ff162005-07-27 01:14:50 -07001255 if (request_firmware(&fw_entry, "tms380tr.bin", tp->pdev) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 printk(KERN_ALERT "%s: firmware %s is missing, cannot start.\n",
1257 dev->name, "tms380tr.bin");
Eric Dumazet807540b2010-09-23 05:40:09 +00001258 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 }
1260
1261 fw_ptr = (unsigned short *)fw_entry->data;
1262 count2 = fw_entry->size / 2;
1263
1264 /* Hardware adapter reset */
1265 SIFWRITEW(ACL_ARESET, SIFACL);
1266 tms380tr_wait(40);
1267
1268 c = SIFREADW(SIFACL);
1269 tms380tr_wait(20);
1270
1271 if(dev->dma == 0) /* For PCI adapters */
1272 {
1273 c &= ~(ACL_NSELOUT0 | ACL_NSELOUT1); /* Clear bits */
1274 if(tp->setnselout)
1275 c |= (*tp->setnselout)(dev);
1276 }
1277
1278 /* In case a command is pending - forget it */
1279 tp->ScbInUse = 0;
1280
1281 c &= ~ACL_ARESET; /* Clear adapter reset bit */
1282 c |= ACL_CPHALT; /* Halt adapter CPU, allow download */
1283 c |= ACL_BOOT;
1284 c |= ACL_SINTEN;
1285 c &= ~ACL_PSDMAEN; /* Clear pseudo dma bit */
1286 SIFWRITEW(c, SIFACL);
1287 tms380tr_wait(40);
1288
1289 count = 0;
1290 /* Download firmware via DIO interface: */
1291 do {
1292 if (count2 < 3) continue;
1293
1294 /* Download first address part */
1295 SIFWRITEW(*fw_ptr, SIFADX);
1296 fw_ptr++;
1297 count2--;
1298 /* Download second address part */
1299 SIFWRITEW(*fw_ptr, SIFADD);
1300 fw_ptr++;
1301 count2--;
1302
1303 if((count = *fw_ptr) != 0) /* Load loop counter */
1304 {
1305 fw_ptr++; /* Download block data */
1306 count2--;
1307 if (count > count2) continue;
1308
1309 for(; count > 0; count--)
1310 {
1311 SIFWRITEW(*fw_ptr, SIFINC);
1312 fw_ptr++;
1313 count2--;
1314 }
1315 }
1316 else /* Stop, if last block downloaded */
1317 {
1318 c = SIFREADW(SIFACL);
1319 c &= (~ACL_CPHALT | ACL_SINTEN);
1320
1321 /* Clear CPHALT and start BUD */
1322 SIFWRITEW(c, SIFACL);
Dan Carpenter773bc972010-08-22 00:54:30 -07001323 release_firmware(fw_entry);
Eric Dumazet807540b2010-09-23 05:40:09 +00001324 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 }
1326 } while(count == 0);
1327
Dan Carpenter773bc972010-08-22 00:54:30 -07001328 release_firmware(fw_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 printk(KERN_INFO "%s: Adapter Download Failed\n", dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +00001330 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
Ben Hutchingsb3ccbb22009-11-07 11:55:20 +00001333MODULE_FIRMWARE("tms380tr.bin");
1334
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335/*
1336 * Starts bring up diagnostics of token ring adapter and evaluates
1337 * diagnostic results.
1338 */
1339static int tms380tr_bringup_diags(struct net_device *dev)
1340{
1341 int loop_cnt, retry_cnt;
1342 unsigned short Status;
1343
1344 tms380tr_wait(HALF_SECOND);
1345 tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
1346 tms380tr_wait(HALF_SECOND);
1347
1348 retry_cnt = BUD_MAX_RETRIES; /* maximal number of retrys */
1349
1350 do {
1351 retry_cnt--;
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 */
1356 loop_cnt--;
1357 tms380tr_wait(HALF_SECOND);
1358 Status = SIFREADW(SIFSTS);
1359 Status &= STS_MASK;
1360
1361 if(tms380tr_debug > 3)
Frans Pop014e4662010-03-24 07:57:33 +00001362 printk(KERN_DEBUG " %04X\n", Status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 /* BUD successfully completed */
1364 if(Status == STS_INITIALIZE)
Eric Dumazet807540b2010-09-23 05:40:09 +00001365 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 /* Unrecoverable hardware error, BUD not completed? */
1367 } while((loop_cnt > 0) && ((Status & (STS_ERROR | STS_TEST))
1368 != (STS_ERROR | STS_TEST)));
1369
1370 /* Error preventing completion of BUD */
1371 if(retry_cnt > 0)
1372 {
1373 printk(KERN_INFO "%s: Adapter Software Reset.\n",
1374 dev->name);
1375 tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
1376 tms380tr_wait(HALF_SECOND);
1377 }
1378 } while(retry_cnt > 0);
1379
1380 Status = SIFREADW(SIFSTS);
1381
1382 printk(KERN_INFO "%s: Hardware error\n", dev->name);
1383 /* Hardware error occurred! */
1384 Status &= 0x001f;
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);
1389 else
1390 printk(KERN_INFO "%s: Bring Up Diagnostics Error (%04X) occurred\n", dev->name, Status & 0x000f);
1391
Eric Dumazet807540b2010-09-23 05:40:09 +00001392 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393}
1394
1395/*
1396 * Copy initialisation data to adapter memory, beginning at address
1397 * 1:0A00; Starting DMA test and evaluating result bits.
1398 */
1399static int tms380tr_init_adapter(struct net_device *dev)
1400{
1401 struct net_local *tp = netdev_priv(dev);
1402
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;
1412
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);
1416
1417 if(tms380tr_debug > 3)
1418 {
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);
1423 }
1424 /* Maximum: three initialization retries */
1425 retry_cnt = INIT_MAX_RETRIES;
1426
1427 do {
1428 retry_cnt--;
1429
1430 /* Transfer initialization block */
1431 SIFWRITEW(0x0001, SIFADX);
1432
1433 /* To address 0001:0A00 of adapter RAM */
1434 SIFWRITEW(0x0A00, SIFADD);
1435
1436 /* Write 11 words to adapter RAM */
1437 for(i = 0; i < 11; i++)
1438 SIFWRITEW(ipb_ptr[i], SIFINC);
1439
1440 /* Execute SCB adapter command */
1441 tms380tr_exec_sifcmd(dev, CMD_EXECUTE);
1442
1443 loop_cnt = INIT_MAX_LOOPCNT; /* Maximum: 11 seconds */
1444
1445 /* While remaining retries, no error and not completed */
1446 do {
1447 Status = 0;
1448 loop_cnt--;
1449 tms380tr_wait(HALF_SECOND);
1450
1451 /* Mask interesting status bits */
1452 Status = SIFREADW(SIFSTS);
1453 Status &= STS_MASK;
Joe Perches8e95a202009-12-03 07:58:21 +00001454 } while(((Status &(STS_INITIALIZE | STS_ERROR | STS_TEST)) != 0) &&
1455 ((Status & STS_ERROR) == 0) && (loop_cnt != 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
1457 if((Status & (STS_INITIALIZE | STS_ERROR | STS_TEST)) == 0)
1458 {
1459 /* Initialization completed without error */
1460 i = 0;
1461 do { /* Test if contents of SCB is valid */
1462 if(SCB_Test[i] != *(cb_ptr + i))
1463 {
1464 printk(KERN_INFO "%s: DMA failed\n", dev->name);
1465 /* DMA data error: wrong data in SCB */
Eric Dumazet807540b2010-09-23 05:40:09 +00001466 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 }
1468 i++;
1469 } while(i < 6);
1470
1471 i = 0;
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 */
Eric Dumazet807540b2010-09-23 05:40:09 +00001475 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 i++;
1477 } while (i < 8);
1478
Eric Dumazet807540b2010-09-23 05:40:09 +00001479 return 1; /* Adapter successfully initialized */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 }
1481 else
1482 {
1483 if((Status & STS_ERROR) != 0)
1484 {
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);
Eric Dumazet807540b2010-09-23 05:40:09 +00001490 return -1; /* Unrecoverable error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 }
1492 else
1493 {
1494 if(retry_cnt > 0)
1495 {
1496 /* Reset adapter and try init again */
1497 tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
1498 tms380tr_wait(HALF_SECOND);
1499 }
1500 }
1501 }
1502 } while(retry_cnt > 0);
1503
1504 printk(KERN_INFO "%s: Retry exceeded\n", dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +00001505 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506}
1507
1508/*
1509 * Check for outstanding commands in command queue and tries to execute
1510 * command immediately. Corresponding command flag in command queue is cleared.
1511 */
1512static void tms380tr_chk_outstanding_cmds(struct net_device *dev)
1513{
1514 struct net_local *tp = netdev_priv(dev);
1515 unsigned long Addr = 0;
1516
1517 if(tp->CMDqueue == 0)
1518 return; /* No command execution */
1519
1520 /* If SCB in use: no command */
1521 if(tp->ScbInUse == 1)
1522 return;
1523
1524 /* Check if adapter is opened, avoiding COMMAND_REJECT
1525 * interrupt by the adapter!
1526 */
Joe Perches76a82ab2012-02-04 10:52:56 +00001527 if (tp->AdapterOpenFlag == 0) {
1528 if (tp->CMDqueue & OC_OPEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 /* Execute OPEN command */
1530 tp->CMDqueue ^= OC_OPEN;
1531
1532 Addr = htonl(((char *)&tp->ocpl - (char *)tp) + tp->dmabuffer);
1533 tp->scb.Parm[0] = LOWORD(Addr);
1534 tp->scb.Parm[1] = HIWORD(Addr);
1535 tp->scb.CMD = OPEN;
Joe Perches76a82ab2012-02-04 10:52:56 +00001536 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 /* No OPEN command queued, but adapter closed. Note:
1538 * We'll try to re-open the adapter in DriverPoll()
1539 */
1540 return; /* No adapter command issued */
Joe Perches76a82ab2012-02-04 10:52:56 +00001541 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 /* Adapter is open; evaluate command queue: try to execute
1543 * outstanding commands (depending on priority!) CLOSE
1544 * command queued
1545 */
Joe Perches76a82ab2012-02-04 10:52:56 +00001546 if (tp->CMDqueue & OC_CLOSE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 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 */
1554 else
1555 tp->CMDqueue = 0; /* no more commands */
Joe Perches76a82ab2012-02-04 10:52:56 +00001556 } 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
1564 * before TRANSMIT.
1565 */
1566 tp->CMDqueue ^= OC_TRANSMIT_HALT;
1567 tp->scb.CMD = TRANSMIT_HALT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Joe Perches76a82ab2012-02-04 10:52:56 +00001569 /* Parm[0] and Parm[1] are ignored
1570 * but should be set to zero!
1571 */
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
1577 */
1578 if (tp->TransmitCommandActive) {
1579 if (!tp->TransmitHaltScheduled) {
1580 tp->TransmitHaltScheduled = 1;
1581 tms380tr_exec_cmd(dev, OC_TRANSMIT_HALT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 }
Joe Perches76a82ab2012-02-04 10:52:56 +00001583 tp->TransmitCommandActive = 0;
1584 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 }
Joe Perches76a82ab2012-02-04 10:52:56 +00001586
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;
1616 } else {
1617 printk(KERN_WARNING "CheckForOutstandingCommand: unknown Command\n");
1618 tp->CMDqueue = 0;
1619 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 }
1621 }
1622
1623 tp->ScbInUse = 1; /* Set semaphore: SCB in use. */
1624
1625 /* Execute SCB and generate IRQ when done. */
1626 tms380tr_exec_sifcmd(dev, CMD_EXECUTE | CMD_SCB_REQUEST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
1629/*
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!
1636 */
1637static void tms380tr_ring_status_irq(struct net_device *dev)
1638{
1639 struct net_local *tp = netdev_priv(dev);
1640
1641 tp->CurrentRingStatus = be16_to_cpu((unsigned short)tp->ssb.Parm[0]);
1642
1643 /* First: fill up statistics */
1644 if(tp->ssb.Parm[0] & SIGNAL_LOSS)
1645 {
1646 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
1647 tp->MacStat.line_errors++;
1648 }
1649
1650 /* Adapter is closed, but initialized */
1651 if(tp->ssb.Parm[0] & LOBE_WIRE_FAULT)
1652 {
1653 printk(KERN_INFO "%s: Lobe Wire Fault, Reopen Adapter\n",
1654 dev->name);
1655 tp->MacStat.line_errors++;
1656 }
1657
1658 if(tp->ssb.Parm[0] & RING_RECOVERY)
1659 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
1660
1661 /* Counter overflow: read error log */
1662 if(tp->ssb.Parm[0] & COUNTER_OVERFLOW)
1663 {
1664 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
1665 tms380tr_exec_cmd(dev, OC_READ_ERROR_LOG);
1666 }
1667
1668 /* Adapter is closed, but initialized */
1669 if(tp->ssb.Parm[0] & REMOVE_RECEIVED)
1670 printk(KERN_INFO "%s: Remove Received, Reopen Adapter\n",
1671 dev->name);
1672
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",
1676 dev->name);
1677
1678 if(tp->ssb.Parm[0] & HARD_ERROR)
1679 printk(KERN_INFO "%s: Hard Error\n", dev->name);
1680
1681 if(tp->ssb.Parm[0] & SOFT_ERROR)
1682 printk(KERN_INFO "%s: Soft Error\n", dev->name);
1683
1684 if(tp->ssb.Parm[0] & TRANSMIT_BEACON)
1685 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
1686
1687 if(tp->ssb.Parm[0] & SINGLE_STATION)
1688 printk(KERN_INFO "%s: Single Station\n", dev->name);
1689
1690 /* Check if adapter has been closed */
1691 if(tp->ssb.Parm[0] & ADAPTER_CLOSED)
1692 {
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);
1698 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
1700
1701/*
1702 * Issued if adapter has encountered an unrecoverable hardware
1703 * or software error.
1704 */
1705static void tms380tr_chk_irq(struct net_device *dev)
1706{
1707 int i;
1708 unsigned short AdapterCheckBlock[4];
1709 struct net_local *tp = netdev_priv(dev);
1710
1711 tp->AdapterOpenFlag = 0; /* Adapter closed now */
1712
1713 /* Page number of adapter memory */
1714 SIFWRITEW(0x0001, SIFADX);
1715 /* Address offset */
1716 SIFWRITEW(CHECKADDR, SIFADR);
1717
1718 /* Reading 8 byte adapter check block. */
1719 for(i = 0; i < 4; i++)
1720 AdapterCheckBlock[i] = SIFREADW(SIFINC);
1721
1722 if(tms380tr_debug > 3)
1723 {
1724 printk(KERN_DEBUG "%s: AdapterCheckBlock: ", dev->name);
1725 for (i = 0; i < 4; i++)
1726 printk("%04X", AdapterCheckBlock[i]);
1727 printk("\n");
1728 }
1729
1730 switch(AdapterCheckBlock[0])
1731 {
1732 case DIO_PARITY:
1733 printk(KERN_INFO "%s: DIO parity error\n", dev->name);
1734 break;
1735
1736 case DMA_READ_ABORT:
1737 printk(KERN_INFO "%s DMA read operation aborted:\n",
1738 dev->name);
1739 switch (AdapterCheckBlock[1])
1740 {
1741 case 0:
1742 printk(KERN_INFO "Timeout\n");
1743 printk(KERN_INFO "Address: %04X %04X\n",
1744 AdapterCheckBlock[2],
1745 AdapterCheckBlock[3]);
1746 break;
1747
1748 case 1:
1749 printk(KERN_INFO "Parity error\n");
1750 printk(KERN_INFO "Address: %04X %04X\n",
1751 AdapterCheckBlock[2],
1752 AdapterCheckBlock[3]);
1753 break;
1754
1755 case 2:
1756 printk(KERN_INFO "Bus error\n");
1757 printk(KERN_INFO "Address: %04X %04X\n",
1758 AdapterCheckBlock[2],
1759 AdapterCheckBlock[3]);
1760 break;
1761
1762 default:
1763 printk(KERN_INFO "Unknown error.\n");
1764 break;
1765 }
1766 break;
1767
1768 case DMA_WRITE_ABORT:
Frans Pop014e4662010-03-24 07:57:33 +00001769 printk(KERN_INFO "%s: DMA write operation aborted:\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 dev->name);
1771 switch (AdapterCheckBlock[1])
1772 {
1773 case 0:
1774 printk(KERN_INFO "Timeout\n");
1775 printk(KERN_INFO "Address: %04X %04X\n",
1776 AdapterCheckBlock[2],
1777 AdapterCheckBlock[3]);
1778 break;
1779
1780 case 1:
1781 printk(KERN_INFO "Parity error\n");
1782 printk(KERN_INFO "Address: %04X %04X\n",
1783 AdapterCheckBlock[2],
1784 AdapterCheckBlock[3]);
1785 break;
1786
1787 case 2:
1788 printk(KERN_INFO "Bus error\n");
1789 printk(KERN_INFO "Address: %04X %04X\n",
1790 AdapterCheckBlock[2],
1791 AdapterCheckBlock[3]);
1792 break;
1793
1794 default:
1795 printk(KERN_INFO "Unknown error.\n");
1796 break;
1797 }
1798 break;
1799
1800 case ILLEGAL_OP_CODE:
1801 printk(KERN_INFO "%s: Illegal operation code in firmware\n",
1802 dev->name);
1803 /* Parm[0-3]: adapter internal register R13-R15 */
1804 break;
1805
1806 case PARITY_ERRORS:
1807 printk(KERN_INFO "%s: Adapter internal bus parity error\n",
1808 dev->name);
1809 /* Parm[0-3]: adapter internal register R13-R15 */
1810 break;
1811
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. */
1815 break;
1816
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. */
1820 break;
1821
1822 case RING_UNDERRUN:
1823 printk(KERN_INFO "%s: Internal DMA underrun detected\n",
1824 dev->name);
1825 break;
1826
1827 case INVALID_IRQ:
1828 printk(KERN_INFO "%s: Unrecognized interrupt detected\n",
1829 dev->name);
1830 /* Parm[0-3]: adapter internal register R13-R15 */
1831 break;
1832
1833 case INVALID_ERROR_IRQ:
1834 printk(KERN_INFO "%s: Unrecognized error interrupt detected\n",
1835 dev->name);
1836 /* Parm[0-3]: adapter internal register R13-R15 */
1837 break;
1838
1839 case INVALID_XOP:
1840 printk(KERN_INFO "%s: Unrecognized XOP request detected\n",
1841 dev->name);
1842 /* Parm[0-3]: adapter internal register R13-R15 */
1843 break;
1844
1845 default:
1846 printk(KERN_INFO "%s: Unknown status", dev->name);
1847 break;
1848 }
1849
1850 if(tms380tr_chipset_init(dev) == 1)
1851 {
1852 /* Restart of firmware successful */
1853 tp->AdapterOpenFlag = 1;
1854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855}
1856
1857/*
1858 * Internal adapter pointer to RAM data are copied from adapter into
1859 * host system.
1860 */
1861static int tms380tr_read_ptr(struct net_device *dev)
1862{
1863 struct net_local *tp = netdev_priv(dev);
1864 unsigned short adapterram;
1865
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);
1871}
1872
1873/*
1874 * Reads a number of bytes from adapter to system memory.
1875 */
1876static void tms380tr_read_ram(struct net_device *dev, unsigned char *Data,
1877 unsigned short Address, int Length)
1878{
1879 int i;
1880 unsigned short old_sifadx, old_sifadr, InWord;
1881
1882 /* Save the current values */
1883 old_sifadx = SIFREADW(SIFADX);
1884 old_sifadr = SIFREADW(SIFADR);
1885
1886 /* Page number of adapter memory */
1887 SIFWRITEW(0x0001, SIFADX);
1888 /* Address offset in adapter RAM */
1889 SIFWRITEW(Address, SIFADR);
1890
1891 /* Copy len byte from adapter memory to system data area. */
1892 i = 0;
1893 for(;;)
1894 {
1895 InWord = SIFREADW(SIFINC);
1896
1897 *(Data + i) = HIBYTE(InWord); /* Write first byte */
1898 if(++i == Length) /* All is done break */
1899 break;
1900
1901 *(Data + i) = LOBYTE(InWord); /* Write second byte */
1902 if (++i == Length) /* All is done break */
1903 break;
1904 }
1905
1906 /* Restore original values */
1907 SIFWRITEW(old_sifadx, SIFADX);
1908 SIFWRITEW(old_sifadr, SIFADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909}
1910
1911/*
1912 * Cancel all queued packets in the transmission queue.
1913 */
1914static void tms380tr_cancel_tx_queue(struct net_local* tp)
1915{
1916 TPL *tpl;
1917
1918 /*
1919 * NOTE: There must not be an active TRANSMIT command pending, when
1920 * this function is called.
1921 */
1922 if(tp->TransmitCommandActive)
1923 return;
1924
1925 for(;;)
1926 {
1927 tpl = tp->TplBusy;
1928 if(!tpl->BusyFlag)
1929 break;
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 */
1934
1935 printk(KERN_INFO "Cancel tx (%08lXh).\n", (unsigned long)tpl);
1936 if (tpl->DMABuff)
Jochen Friedrich504ff162005-07-27 01:14:50 -07001937 dma_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 dev_kfree_skb_any(tpl->Skb);
1939 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940}
1941
1942/*
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.
1946 */
1947static void tms380tr_tx_status_irq(struct net_device *dev)
1948{
1949 struct net_local *tp = netdev_priv(dev);
1950 unsigned char HighByte, HighAc, LowAc;
1951 TPL *tpl;
1952
1953 /* NOTE: At this point the SSB from TRANSMIT STATUS is no longer
1954 * available, because the CLEAR SSB command has already been issued.
1955 *
1956 * Process all complete transmissions.
1957 */
1958
1959 for(;;)
1960 {
1961 tpl = tp->TplBusy;
1962 if(!tpl->BusyFlag || (tpl->Status
1963 & (TX_VALID | TX_FRAME_COMPLETE))
1964 != TX_FRAME_COMPLETE)
1965 {
1966 break;
1967 }
1968
1969 /* "Remove" TPL from busy list. */
1970 tp->TplBusy = tpl->NextTPLPtr ;
1971
1972 /* Check the transmit status field only for directed frames*/
1973 if(DIRECTED_FRAME(tpl) && (tpl->Status & TX_ERROR) == 0)
1974 {
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);
1978
1979 if((HighAc != LowAc) || (HighAc == AC_NOT_RECOGNIZED))
1980 {
1981 printk(KERN_DEBUG "%s: (DA=%08lX not recognized)\n",
1982 dev->name,
1983 *(unsigned long *)&tpl->MData[2+2]);
1984 }
1985 else
1986 {
1987 if(tms380tr_debug > 3)
1988 printk(KERN_DEBUG "%s: Directed frame tx'd\n",
1989 dev->name);
1990 }
1991 }
1992 else
1993 {
1994 if(!DIRECTED_FRAME(tpl))
1995 {
1996 if(tms380tr_debug > 3)
1997 printk(KERN_DEBUG "%s: Broadcast frame tx'd\n",
1998 dev->name);
1999 }
2000 }
2001
2002 tp->MacStat.tx_packets++;
2003 if (tpl->DMABuff)
Jochen Friedrich504ff162005-07-27 01:14:50 -07002004 dma_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 dev_kfree_skb_irq(tpl->Skb);
2006 tpl->BusyFlag = 0; /* "free" TPL */
2007 }
2008
2009 if(!tp->TplFree->NextTPLPtr->BusyFlag)
2010 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011}
2012
2013/*
2014 * Called if a frame receive interrupt is generated by the adapter.
2015 * Check if the frame is valid and indicate it to system.
2016 */
2017static void tms380tr_rcv_status_irq(struct net_device *dev)
2018{
2019 struct net_local *tp = netdev_priv(dev);
2020 unsigned char *ReceiveDataPtr;
2021 struct sk_buff *skb;
2022 unsigned int Length, Length2;
2023 RPL *rpl;
2024 RPL *SaveHead;
2025 dma_addr_t dmabuf;
2026
2027 /* NOTE: At this point the SSB from RECEIVE STATUS is no longer
2028 * available, because the CLEAR SSB command has already been issued.
2029 *
2030 * Process all complete receives.
2031 */
2032
2033 for(;;)
2034 {
2035 rpl = tp->RplHead;
2036 if(rpl->Status & RX_VALID)
2037 break; /* RPL still in use by adapter */
2038
2039 /* Forward RPLHead pointer to next list. */
2040 SaveHead = tp->RplHead;
2041 tp->RplHead = rpl->NextRPLPtr;
2042
2043 /* Get the frame size (Byte swap for Intel).
2044 * Do this early (see workaround comment below)
2045 */
Al Viro2929e772007-08-23 02:57:00 -04002046 Length = be16_to_cpu(rpl->FrameSize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
2048 /* Check if the Frame_Start, Frame_End and
2049 * Frame_Complete bits are set.
2050 */
2051 if((rpl->Status & VALID_SINGLE_BUFFER_FRAME)
2052 == VALID_SINGLE_BUFFER_FRAME)
2053 {
2054 ReceiveDataPtr = rpl->MData;
2055
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
2061 */
Al Viro2929e772007-08-23 02:57:00 -04002062 Length2 = be16_to_cpu(rpl->FrameSize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
2064 if(Length == 0 || Length != Length2)
2065 {
2066 tp->RplHead = SaveHead;
2067 break; /* Return to tms380tr_interrupt */
2068 }
2069 tms380tr_update_rcv_stats(tp,ReceiveDataPtr,Length);
2070
2071 if(tms380tr_debug > 3)
2072 printk(KERN_DEBUG "%s: Packet Length %04X (%d)\n",
2073 dev->name, Length, Length);
2074
2075 /* Indicate the received frame to system the
2076 * adapter does the Source-Routing padding for
2077 * us. See: OpenOptions in tms380tr_init_opb()
2078 */
2079 skb = rpl->Skb;
2080 if(rpl->SkbStat == SKB_UNAVAILABLE)
2081 {
2082 /* Try again to allocate skb */
2083 skb = dev_alloc_skb(tp->MaxPacketSize);
2084 if(skb == NULL)
2085 {
2086 /* Update Stats ?? */
2087 }
2088 else
2089 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 skb_put(skb, tp->MaxPacketSize);
2091 rpl->SkbStat = SKB_DATA_COPY;
2092 ReceiveDataPtr = rpl->MData;
2093 }
2094 }
2095
Joe Perches8e95a202009-12-03 07:58:21 +00002096 if(skb && (rpl->SkbStat == SKB_DATA_COPY ||
2097 rpl->SkbStat == SKB_DMA_DIRECT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 {
2099 if(rpl->SkbStat == SKB_DATA_COPY)
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002100 skb_copy_to_linear_data(skb, ReceiveDataPtr,
2101 Length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
2103 /* Deliver frame to system */
2104 rpl->Skb = NULL;
2105 skb_trim(skb,Length);
2106 skb->protocol = tr_type_trans(skb,dev);
2107 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 }
2109 }
2110 else /* Invalid frame */
2111 {
2112 if(rpl->Skb != NULL)
2113 dev_kfree_skb_irq(rpl->Skb);
2114
2115 /* Skip list. */
2116 if(rpl->Status & RX_START_FRAME)
2117 /* Frame start bit is set -> overflow. */
2118 tp->MacStat.rx_errors++;
2119 }
2120 if (rpl->DMABuff)
Jochen Friedrich504ff162005-07-27 01:14:50 -07002121 dma_unmap_single(tp->pdev, rpl->DMABuff, tp->MaxPacketSize, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 rpl->DMABuff = 0;
2123
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)
2128 {
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];
2132 }
2133 else /* skb != NULL */
2134 {
2135 rpl->Skb->dev = dev;
2136 skb_put(rpl->Skb, tp->MaxPacketSize);
2137
2138 /* Data unreachable for DMA ? then use local buffer */
Jochen Friedrich504ff162005-07-27 01:14:50 -07002139 dmabuf = dma_map_single(tp->pdev, rpl->Skb->data, tp->MaxPacketSize, DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit))
2141 {
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];
2145 }
2146 else
2147 {
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;
2153 }
2154 }
2155
2156 rpl->FragList[0].DataCount = cpu_to_be16((unsigned short)tp->MaxPacketSize);
2157 rpl->FrameSize = 0;
2158
2159 /* Pass the last RPL back to the adapter */
2160 tp->RplTail->FrameSize = 0;
2161
2162 /* Reset the CSTAT field in the list. */
2163 tms380tr_write_rpl_status(tp->RplTail, RX_VALID | RX_FRAME_IRQ);
2164
2165 /* Current RPL becomes last one in list. */
2166 tp->RplTail = tp->RplTail->NextRPLPtr;
2167
2168 /* Inform adapter about RPL valid. */
2169 tms380tr_exec_sifcmd(dev, CMD_RX_VALID);
2170 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171}
2172
2173/*
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
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08002177 * at an undesirable time. When this function is used, the status is
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 * always written when the function is called.
2179 */
2180static void tms380tr_write_rpl_status(RPL *rpl, unsigned int Status)
2181{
2182 rpl->Status = Status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * The function updates the statistic counters in mac->MacStat.
2187 * It differtiates between directed and broadcast/multicast ( ==functional)
2188 * frames.
2189 */
2190static void tms380tr_update_rcv_stats(struct net_local *tp, unsigned char DataPtr[],
2191 unsigned int Length)
2192{
2193 tp->MacStat.rx_packets++;
2194 tp->MacStat.rx_bytes += Length;
2195
2196 /* Test functional bit */
2197 if(DataPtr[2] & GROUP_BIT)
2198 tp->MacStat.multicast++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199}
2200
2201static int tms380tr_set_mac_address(struct net_device *dev, void *addr)
2202{
2203 struct net_local *tp = netdev_priv(dev);
2204 struct sockaddr *saddr = addr;
2205
2206 if (tp->AdapterOpenFlag || tp->AdapterVirtOpenFlag) {
2207 printk(KERN_WARNING "%s: Cannot set MAC/LAA address while card is open\n", dev->name);
2208 return -EIO;
2209 }
2210 memcpy(dev->dev_addr, saddr->sa_data, dev->addr_len);
2211 return 0;
2212}
2213
2214#if TMS380TR_DEBUG > 0
2215/*
2216 * Dump Packet (data)
2217 */
2218static void tms380tr_dump(unsigned char *Data, int length)
2219{
2220 int i, j;
2221
2222 for (i = 0, j = 0; i < length / 8; i++, j += 8)
2223 {
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]);
2227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228}
2229#endif
2230
2231void tmsdev_term(struct net_device *dev)
2232{
2233 struct net_local *tp;
2234
2235 tp = netdev_priv(dev);
Jochen Friedrich504ff162005-07-27 01:14:50 -07002236 dma_unmap_single(tp->pdev, tp->dmabuffer, sizeof(struct net_local),
2237 DMA_BIDIRECTIONAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238}
2239
Stephen Hemmingerf1608f82009-01-09 13:01:25 +00002240const 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,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002246 .ndo_set_rx_mode = tms380tr_set_multicast_list,
Stephen Hemmingerf1608f82009-01-09 13:01:25 +00002247 .ndo_set_mac_address = tms380tr_set_mac_address,
2248};
2249EXPORT_SYMBOL(tms380tr_netdev_ops);
2250
Jochen Friedrich84c3ea02005-08-19 21:05:56 -04002251int tmsdev_init(struct net_device *dev, struct device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252{
2253 struct net_local *tms_local;
2254
Wang Chen8f15ea42008-11-12 23:38:36 -08002255 memset(netdev_priv(dev), 0, sizeof(struct net_local));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 tms_local = netdev_priv(dev);
2257 init_waitqueue_head(&tms_local->wait_for_tok_int);
Jochen Friedrich84c3ea02005-08-19 21:05:56 -04002258 if (pdev->dma_mask)
2259 tms_local->dmalimit = *pdev->dma_mask;
2260 else
2261 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 tms_local->pdev = pdev;
Jochen Friedrich504ff162005-07-27 01:14:50 -07002263 tms_local->dmabuffer = dma_map_single(pdev, (void *)tms_local,
2264 sizeof(struct net_local), DMA_BIDIRECTIONAL);
Jochen Friedrich84c3ea02005-08-19 21:05:56 -04002265 if (tms_local->dmabuffer + sizeof(struct net_local) >
2266 tms_local->dmalimit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 {
2268 printk(KERN_INFO "%s: Memory not accessible for DMA\n",
2269 dev->name);
2270 tmsdev_term(dev);
2271 return -ENOMEM;
2272 }
2273
Stephen Hemmingerf1608f82009-01-09 13:01:25 +00002274 dev->netdev_ops = &tms380tr_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 dev->watchdog_timeo = HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
2277 return 0;
2278}
2279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280EXPORT_SYMBOL(tms380tr_open);
2281EXPORT_SYMBOL(tms380tr_close);
2282EXPORT_SYMBOL(tms380tr_interrupt);
2283EXPORT_SYMBOL(tmsdev_init);
2284EXPORT_SYMBOL(tmsdev_term);
2285EXPORT_SYMBOL(tms380tr_wait);
2286
Jochen Friedrich504ff162005-07-27 01:14:50 -07002287#ifdef MODULE
2288
Adrian Bunkde70b4c2005-05-02 03:46:43 +02002289static struct module *TMS380_module = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
2291int init_module(void)
2292{
2293 printk(KERN_DEBUG "%s", version);
2294
2295 TMS380_module = &__this_module;
2296 return 0;
2297}
2298
2299void cleanup_module(void)
2300{
2301 TMS380_module = NULL;
2302}
2303#endif
2304
2305MODULE_LICENSE("GPL");
2306