]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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. | |
8 | * http://www.linux-sna.org | |
9 | * | |
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 | |
726a6459 | 33 | * AF Adam Fritzler |
1da177e4 LT |
34 | * 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. | |
504ff16c | 65 | * 22-Jul-05 JF Converted to dma-mapping. |
1da177e4 LT |
66 | * |
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 | |
77 | static 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> | |
1da177e4 LT |
88 | #include <linux/string.h> |
89 | #include <linux/time.h> | |
90 | #include <linux/errno.h> | |
91 | #include <linux/init.h> | |
504ff16c | 92 | #include <linux/dma-mapping.h> |
1da177e4 LT |
93 | #include <linux/delay.h> |
94 | #include <linux/netdevice.h> | |
95 | #include <linux/etherdevice.h> | |
96 | #include <linux/skbuff.h> | |
97 | #include <linux/trdevice.h> | |
98 | #include <linux/firmware.h> | |
99 | #include <linux/bitops.h> | |
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 | |
115 | static unsigned int tms380tr_debug = TMS380TR_DEBUG; | |
116 | ||
1da177e4 LT |
117 | /* Index to functions, as function prototypes. |
118 | * Alphabetical by function name. | |
119 | */ | |
120 | ||
121 | /* "A" */ | |
122 | /* "B" */ | |
123 | static int tms380tr_bringup_diags(struct net_device *dev); | |
124 | /* "C" */ | |
125 | static void tms380tr_cancel_tx_queue(struct net_local* tp); | |
126 | static int tms380tr_chipset_init(struct net_device *dev); | |
127 | static void tms380tr_chk_irq(struct net_device *dev); | |
128 | static void tms380tr_chk_outstanding_cmds(struct net_device *dev); | |
129 | static void tms380tr_chk_src_addr(unsigned char *frame, unsigned char *hw_addr); | |
130 | static unsigned char tms380tr_chk_ssb(struct net_local *tp, unsigned short IrqType); | |
131 | int tms380tr_close(struct net_device *dev); | |
132 | static void tms380tr_cmd_status_irq(struct net_device *dev); | |
133 | /* "D" */ | |
134 | static void tms380tr_disable_interrupts(struct net_device *dev); | |
135 | #if TMS380TR_DEBUG > 0 | |
136 | static void tms380tr_dump(unsigned char *Data, int length); | |
137 | #endif | |
138 | /* "E" */ | |
139 | static void tms380tr_enable_interrupts(struct net_device *dev); | |
140 | static void tms380tr_exec_cmd(struct net_device *dev, unsigned short Command); | |
141 | static void tms380tr_exec_sifcmd(struct net_device *dev, unsigned int WriteValue); | |
142 | /* "F" */ | |
143 | /* "G" */ | |
144 | static struct net_device_stats *tms380tr_get_stats(struct net_device *dev); | |
145 | /* "H" */ | |
61a84108 SH |
146 | static netdev_tx_t tms380tr_hardware_send_packet(struct sk_buff *skb, |
147 | struct net_device *dev); | |
1da177e4 LT |
148 | /* "I" */ |
149 | static int tms380tr_init_adapter(struct net_device *dev); | |
150 | static void tms380tr_init_ipb(struct net_local *tp); | |
151 | static void tms380tr_init_net_local(struct net_device *dev); | |
152 | static void tms380tr_init_opb(struct net_device *dev); | |
153 | /* "M" */ | |
154 | /* "O" */ | |
155 | int tms380tr_open(struct net_device *dev); | |
156 | static void tms380tr_open_adapter(struct net_device *dev); | |
157 | /* "P" */ | |
158 | /* "R" */ | |
159 | static void tms380tr_rcv_status_irq(struct net_device *dev); | |
160 | static int tms380tr_read_ptr(struct net_device *dev); | |
161 | static void tms380tr_read_ram(struct net_device *dev, unsigned char *Data, | |
162 | unsigned short Address, int Length); | |
163 | static int tms380tr_reset_adapter(struct net_device *dev); | |
164 | static void tms380tr_reset_interrupt(struct net_device *dev); | |
165 | static void tms380tr_ring_status_irq(struct net_device *dev); | |
166 | /* "S" */ | |
61a84108 SH |
167 | static netdev_tx_t tms380tr_send_packet(struct sk_buff *skb, |
168 | struct net_device *dev); | |
1da177e4 LT |
169 | static void tms380tr_set_multicast_list(struct net_device *dev); |
170 | static int tms380tr_set_mac_address(struct net_device *dev, void *addr); | |
171 | /* "T" */ | |
172 | static void tms380tr_timer_chk(unsigned long data); | |
173 | static void tms380tr_timer_end_wait(unsigned long data); | |
174 | static void tms380tr_tx_status_irq(struct net_device *dev); | |
175 | /* "U" */ | |
176 | static void tms380tr_update_rcv_stats(struct net_local *tp, | |
177 | unsigned char DataPtr[], unsigned int Length); | |
178 | /* "W" */ | |
179 | void tms380tr_wait(unsigned long time); | |
180 | static void tms380tr_write_rpl_status(RPL *rpl, unsigned int Status); | |
181 | static void tms380tr_write_tpl_status(TPL *tpl, unsigned int Status); | |
182 | ||
8f15ea42 WC |
183 | #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)) | |
1da177e4 LT |
191 | |
192 | ||
193 | ||
194 | #if 0 /* TMS380TR_DEBUG > 0 */ | |
195 | static 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) | |
227 | return (-1); /* No adapter */ | |
228 | 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 | ||
235 | return (0); | |
236 | } | |
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 | */ | |
247 | int 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); | |
274 | return (-1); | |
275 | } | |
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); | |
301 | return (-1); | |
302 | } | |
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 | ||
312 | return (0); | |
313 | } | |
314 | ||
315 | /* | |
316 | * Timeout function while waiting for event | |
317 | */ | |
318 | static 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 | } | |
328 | ||
329 | return; | |
330 | } | |
331 | ||
332 | /* | |
333 | * Initialize the chipset | |
334 | */ | |
335 | static int tms380tr_chipset_init(struct net_device *dev) | |
336 | { | |
337 | struct net_local *tp = netdev_priv(dev); | |
338 | int err; | |
339 | ||
340 | tms380tr_init_ipb(tp); | |
341 | tms380tr_init_opb(dev); | |
342 | tms380tr_init_net_local(dev); | |
343 | ||
344 | if(tms380tr_debug > 3) | |
345 | printk(KERN_DEBUG "%s: Resetting adapter...\n", dev->name); | |
346 | err = tms380tr_reset_adapter(dev); | |
347 | if(err < 0) | |
348 | return (-1); | |
349 | ||
350 | if(tms380tr_debug > 3) | |
351 | printk(KERN_DEBUG "%s: Bringup diags...\n", dev->name); | |
352 | err = tms380tr_bringup_diags(dev); | |
353 | if(err < 0) | |
354 | return (-1); | |
355 | ||
356 | if(tms380tr_debug > 3) | |
357 | printk(KERN_DEBUG "%s: Init adapter...\n", dev->name); | |
358 | err = tms380tr_init_adapter(dev); | |
359 | if(err < 0) | |
360 | return (-1); | |
361 | ||
362 | if(tms380tr_debug > 3) | |
363 | printk(KERN_DEBUG "%s: Done!\n", dev->name); | |
364 | return (0); | |
365 | } | |
366 | ||
367 | /* | |
368 | * Initializes the net_local structure. | |
369 | */ | |
370 | static void tms380tr_init_net_local(struct net_device *dev) | |
371 | { | |
372 | struct net_local *tp = netdev_priv(dev); | |
373 | int i; | |
374 | dma_addr_t dmabuf; | |
375 | ||
376 | tp->scb.CMD = 0; | |
377 | tp->scb.Parm[0] = 0; | |
378 | tp->scb.Parm[1] = 0; | |
379 | ||
380 | tp->ssb.STS = 0; | |
381 | tp->ssb.Parm[0] = 0; | |
382 | tp->ssb.Parm[1] = 0; | |
383 | tp->ssb.Parm[2] = 0; | |
384 | ||
385 | tp->CMDqueue = 0; | |
386 | ||
387 | tp->AdapterOpenFlag = 0; | |
388 | tp->AdapterVirtOpenFlag = 0; | |
389 | tp->ScbInUse = 0; | |
390 | tp->OpenCommandIssued = 0; | |
391 | tp->ReOpenInProgress = 0; | |
392 | tp->HaltInProgress = 0; | |
393 | tp->TransmitHaltScheduled = 0; | |
394 | tp->LobeWireFaultLogged = 0; | |
395 | tp->LastOpenStatus = 0; | |
396 | tp->MaxPacketSize = DEFAULT_PACKET_SIZE; | |
397 | ||
398 | /* Create circular chain of transmit lists */ | |
399 | for (i = 0; i < TPL_NUM; i++) | |
400 | { | |
401 | tp->Tpl[i].NextTPLAddr = htonl(((char *)(&tp->Tpl[(i+1) % TPL_NUM]) - (char *)tp) + tp->dmabuffer); /* DMA buffer may be MMU driven */ | |
402 | tp->Tpl[i].Status = 0; | |
403 | tp->Tpl[i].FrameSize = 0; | |
404 | tp->Tpl[i].FragList[0].DataCount = 0; | |
405 | tp->Tpl[i].FragList[0].DataAddr = 0; | |
406 | tp->Tpl[i].NextTPLPtr = &tp->Tpl[(i+1) % TPL_NUM]; | |
407 | tp->Tpl[i].MData = NULL; | |
408 | tp->Tpl[i].TPLIndex = i; | |
409 | tp->Tpl[i].DMABuff = 0; | |
410 | tp->Tpl[i].BusyFlag = 0; | |
411 | } | |
412 | ||
413 | tp->TplFree = tp->TplBusy = &tp->Tpl[0]; | |
414 | ||
415 | /* Create circular chain of receive lists */ | |
416 | for (i = 0; i < RPL_NUM; i++) | |
417 | { | |
418 | tp->Rpl[i].NextRPLAddr = htonl(((char *)(&tp->Rpl[(i+1) % RPL_NUM]) - (char *)tp) + tp->dmabuffer); /* DMA buffer may be MMU driven */ | |
419 | tp->Rpl[i].Status = (RX_VALID | RX_START_FRAME | RX_END_FRAME | RX_FRAME_IRQ); | |
420 | tp->Rpl[i].FrameSize = 0; | |
421 | tp->Rpl[i].FragList[0].DataCount = cpu_to_be16((unsigned short)tp->MaxPacketSize); | |
422 | ||
423 | /* Alloc skb and point adapter to data area */ | |
424 | tp->Rpl[i].Skb = dev_alloc_skb(tp->MaxPacketSize); | |
425 | tp->Rpl[i].DMABuff = 0; | |
426 | ||
427 | /* skb == NULL ? then use local buffer */ | |
428 | if(tp->Rpl[i].Skb == NULL) | |
429 | { | |
430 | tp->Rpl[i].SkbStat = SKB_UNAVAILABLE; | |
431 | tp->Rpl[i].FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[i] - (char *)tp) + tp->dmabuffer); | |
432 | tp->Rpl[i].MData = tp->LocalRxBuffers[i]; | |
433 | } | |
434 | else /* SKB != NULL */ | |
435 | { | |
436 | tp->Rpl[i].Skb->dev = dev; | |
437 | skb_put(tp->Rpl[i].Skb, tp->MaxPacketSize); | |
438 | ||
439 | /* data unreachable for DMA ? then use local buffer */ | |
504ff16c | 440 | dmabuf = dma_map_single(tp->pdev, tp->Rpl[i].Skb->data, tp->MaxPacketSize, DMA_FROM_DEVICE); |
1da177e4 LT |
441 | if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit)) |
442 | { | |
443 | tp->Rpl[i].SkbStat = SKB_DATA_COPY; | |
444 | tp->Rpl[i].FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[i] - (char *)tp) + tp->dmabuffer); | |
445 | tp->Rpl[i].MData = tp->LocalRxBuffers[i]; | |
446 | } | |
447 | else /* DMA directly in skb->data */ | |
448 | { | |
449 | tp->Rpl[i].SkbStat = SKB_DMA_DIRECT; | |
450 | tp->Rpl[i].FragList[0].DataAddr = htonl(dmabuf); | |
451 | tp->Rpl[i].MData = tp->Rpl[i].Skb->data; | |
452 | tp->Rpl[i].DMABuff = dmabuf; | |
453 | } | |
454 | } | |
455 | ||
456 | tp->Rpl[i].NextRPLPtr = &tp->Rpl[(i+1) % RPL_NUM]; | |
457 | tp->Rpl[i].RPLIndex = i; | |
458 | } | |
459 | ||
460 | tp->RplHead = &tp->Rpl[0]; | |
461 | tp->RplTail = &tp->Rpl[RPL_NUM-1]; | |
462 | tp->RplTail->Status = (RX_START_FRAME | RX_END_FRAME | RX_FRAME_IRQ); | |
463 | ||
464 | return; | |
465 | } | |
466 | ||
467 | /* | |
468 | * Initializes the initialisation parameter block. | |
469 | */ | |
470 | static void tms380tr_init_ipb(struct net_local *tp) | |
471 | { | |
472 | tp->ipb.Init_Options = BURST_MODE; | |
473 | tp->ipb.CMD_Status_IV = 0; | |
474 | tp->ipb.TX_IV = 0; | |
475 | tp->ipb.RX_IV = 0; | |
476 | tp->ipb.Ring_Status_IV = 0; | |
477 | tp->ipb.SCB_Clear_IV = 0; | |
478 | tp->ipb.Adapter_CHK_IV = 0; | |
479 | tp->ipb.RX_Burst_Size = BURST_SIZE; | |
480 | tp->ipb.TX_Burst_Size = BURST_SIZE; | |
481 | tp->ipb.DMA_Abort_Thrhld = DMA_RETRIES; | |
482 | tp->ipb.SCB_Addr = 0; | |
483 | tp->ipb.SSB_Addr = 0; | |
484 | ||
485 | return; | |
486 | } | |
487 | ||
488 | /* | |
489 | * Initializes the open parameter block. | |
490 | */ | |
491 | static void tms380tr_init_opb(struct net_device *dev) | |
492 | { | |
493 | struct net_local *tp; | |
494 | unsigned long Addr; | |
495 | unsigned short RplSize = RPL_SIZE; | |
496 | unsigned short TplSize = TPL_SIZE; | |
497 | unsigned short BufferSize = BUFFER_SIZE; | |
498 | int i; | |
499 | ||
500 | tp = netdev_priv(dev); | |
501 | ||
502 | tp->ocpl.OPENOptions = 0; | |
503 | tp->ocpl.OPENOptions |= ENABLE_FULL_DUPLEX_SELECTION; | |
504 | tp->ocpl.FullDuplex = 0; | |
505 | tp->ocpl.FullDuplex |= OPEN_FULL_DUPLEX_OFF; | |
506 | ||
507 | /* | |
508 | * Set node address | |
509 | * | |
510 | * We go ahead and put it in the OPB even though on | |
511 | * most of the generic adapters this isn't required. | |
512 | * Its simpler this way. -- ASF | |
513 | */ | |
514 | for (i=0;i<6;i++) | |
515 | tp->ocpl.NodeAddr[i] = ((unsigned char *)dev->dev_addr)[i]; | |
516 | ||
517 | tp->ocpl.GroupAddr = 0; | |
518 | tp->ocpl.FunctAddr = 0; | |
519 | tp->ocpl.RxListSize = cpu_to_be16((unsigned short)RplSize); | |
520 | tp->ocpl.TxListSize = cpu_to_be16((unsigned short)TplSize); | |
521 | tp->ocpl.BufSize = cpu_to_be16((unsigned short)BufferSize); | |
522 | tp->ocpl.Reserved = 0; | |
523 | tp->ocpl.TXBufMin = TX_BUF_MIN; | |
524 | tp->ocpl.TXBufMax = TX_BUF_MAX; | |
525 | ||
526 | Addr = htonl(((char *)tp->ProductID - (char *)tp) + tp->dmabuffer); | |
527 | ||
528 | tp->ocpl.ProdIDAddr[0] = LOWORD(Addr); | |
529 | tp->ocpl.ProdIDAddr[1] = HIWORD(Addr); | |
530 | ||
531 | return; | |
532 | } | |
533 | ||
534 | /* | |
535 | * Send OPEN command to adapter | |
536 | */ | |
537 | static void tms380tr_open_adapter(struct net_device *dev) | |
538 | { | |
539 | struct net_local *tp = netdev_priv(dev); | |
540 | ||
541 | if(tp->OpenCommandIssued) | |
542 | return; | |
543 | ||
544 | tp->OpenCommandIssued = 1; | |
545 | tms380tr_exec_cmd(dev, OC_OPEN); | |
546 | ||
547 | return; | |
548 | } | |
549 | ||
550 | /* | |
551 | * Clear the adapter's interrupt flag. Clear system interrupt enable | |
552 | * (SINTEN): disable adapter to system interrupts. | |
553 | */ | |
554 | static void tms380tr_disable_interrupts(struct net_device *dev) | |
555 | { | |
556 | SIFWRITEB(0, SIFACL); | |
557 | ||
558 | return; | |
559 | } | |
560 | ||
561 | /* | |
562 | * Set the adapter's interrupt flag. Set system interrupt enable | |
563 | * (SINTEN): enable adapter to system interrupts. | |
564 | */ | |
565 | static void tms380tr_enable_interrupts(struct net_device *dev) | |
566 | { | |
567 | SIFWRITEB(ACL_SINTEN, SIFACL); | |
568 | ||
569 | return; | |
570 | } | |
571 | ||
572 | /* | |
573 | * Put command in command queue, try to execute it. | |
574 | */ | |
575 | static void tms380tr_exec_cmd(struct net_device *dev, unsigned short Command) | |
576 | { | |
577 | struct net_local *tp = netdev_priv(dev); | |
578 | ||
579 | tp->CMDqueue |= Command; | |
580 | tms380tr_chk_outstanding_cmds(dev); | |
581 | ||
582 | return; | |
583 | } | |
584 | ||
585 | static void tms380tr_timeout(struct net_device *dev) | |
586 | { | |
587 | /* | |
588 | * If we get here, some higher level has decided we are broken. | |
589 | * There should really be a "kick me" function call instead. | |
590 | * | |
591 | * Resetting the token ring adapter takes a long time so just | |
592 | * fake transmission time and go on trying. Our own timeout | |
593 | * routine is in tms380tr_timer_chk() | |
594 | */ | |
595 | dev->trans_start = jiffies; | |
596 | netif_wake_queue(dev); | |
597 | } | |
598 | ||
599 | /* | |
600 | * Gets skb from system, queues it and checks if it can be sent | |
601 | */ | |
61a84108 SH |
602 | static netdev_tx_t tms380tr_send_packet(struct sk_buff *skb, |
603 | struct net_device *dev) | |
1da177e4 LT |
604 | { |
605 | struct net_local *tp = netdev_priv(dev); | |
61a84108 | 606 | netdev_tx_t rc; |
1da177e4 | 607 | |
61a84108 | 608 | rc = tms380tr_hardware_send_packet(skb, dev); |
1da177e4 LT |
609 | if(tp->TplFree->NextTPLPtr->BusyFlag) |
610 | netif_stop_queue(dev); | |
61a84108 | 611 | return rc; |
1da177e4 LT |
612 | } |
613 | ||
614 | /* | |
615 | * Move frames into adapter tx queue | |
616 | */ | |
61a84108 SH |
617 | static netdev_tx_t tms380tr_hardware_send_packet(struct sk_buff *skb, |
618 | struct net_device *dev) | |
1da177e4 LT |
619 | { |
620 | TPL *tpl; | |
621 | short length; | |
622 | unsigned char *buf; | |
623 | unsigned long flags; | |
624 | int i; | |
625 | dma_addr_t dmabuf, newbuf; | |
626 | struct net_local *tp = netdev_priv(dev); | |
627 | ||
628 | /* Try to get a free TPL from the chain. | |
629 | * | |
630 | * NOTE: We *must* always leave one unused TPL in the chain, | |
631 | * because otherwise the adapter might send frames twice. | |
632 | */ | |
633 | spin_lock_irqsave(&tp->lock, flags); | |
634 | if(tp->TplFree->NextTPLPtr->BusyFlag) { /* No free TPL */ | |
635 | if (tms380tr_debug > 0) | |
636 | printk(KERN_DEBUG "%s: No free TPL\n", dev->name); | |
637 | spin_unlock_irqrestore(&tp->lock, flags); | |
5b548140 | 638 | return NETDEV_TX_BUSY; |
1da177e4 LT |
639 | } |
640 | ||
641 | dmabuf = 0; | |
642 | ||
643 | /* Is buffer reachable for Busmaster-DMA? */ | |
644 | ||
645 | length = skb->len; | |
504ff16c | 646 | dmabuf = dma_map_single(tp->pdev, skb->data, length, DMA_TO_DEVICE); |
1da177e4 LT |
647 | if(tp->dmalimit && (dmabuf + length > tp->dmalimit)) { |
648 | /* Copy frame to local buffer */ | |
504ff16c | 649 | dma_unmap_single(tp->pdev, dmabuf, length, DMA_TO_DEVICE); |
1da177e4 LT |
650 | dmabuf = 0; |
651 | i = tp->TplFree->TPLIndex; | |
652 | buf = tp->LocalTxBuffers[i]; | |
d626f62b | 653 | skb_copy_from_linear_data(skb, buf, length); |
1da177e4 LT |
654 | newbuf = ((char *)buf - (char *)tp) + tp->dmabuffer; |
655 | } | |
656 | else { | |
657 | /* Send direct from skb->data */ | |
658 | newbuf = dmabuf; | |
659 | buf = skb->data; | |
660 | } | |
661 | /* Source address in packet? */ | |
662 | tms380tr_chk_src_addr(buf, dev->dev_addr); | |
663 | tp->LastSendTime = jiffies; | |
664 | tpl = tp->TplFree; /* Get the "free" TPL */ | |
665 | tpl->BusyFlag = 1; /* Mark TPL as busy */ | |
666 | tp->TplFree = tpl->NextTPLPtr; | |
667 | ||
668 | /* Save the skb for delayed return of skb to system */ | |
669 | tpl->Skb = skb; | |
670 | tpl->DMABuff = dmabuf; | |
671 | tpl->FragList[0].DataCount = cpu_to_be16((unsigned short)length); | |
672 | tpl->FragList[0].DataAddr = htonl(newbuf); | |
673 | ||
674 | /* Write the data length in the transmit list. */ | |
675 | tpl->FrameSize = cpu_to_be16((unsigned short)length); | |
676 | tpl->MData = buf; | |
677 | ||
678 | /* Transmit the frame and set the status values. */ | |
679 | tms380tr_write_tpl_status(tpl, TX_VALID | TX_START_FRAME | |
680 | | TX_END_FRAME | TX_PASS_SRC_ADDR | |
681 | | TX_FRAME_IRQ); | |
682 | ||
683 | /* Let adapter send the frame. */ | |
684 | tms380tr_exec_sifcmd(dev, CMD_TX_VALID); | |
685 | spin_unlock_irqrestore(&tp->lock, flags); | |
686 | ||
ec634fe3 | 687 | return NETDEV_TX_OK; |
1da177e4 LT |
688 | } |
689 | ||
690 | /* | |
691 | * Write the given value to the 'Status' field of the specified TPL. | |
692 | * NOTE: This function should be used whenever the status of any TPL must be | |
693 | * modified by the driver, because the compiler may otherwise change the | |
694 | * order of instructions such that writing the TPL status may be executed at | |
3ad2f3fb | 695 | * an undesirable time. When this function is used, the status is always |
1da177e4 LT |
696 | * written when the function is called. |
697 | */ | |
698 | static void tms380tr_write_tpl_status(TPL *tpl, unsigned int Status) | |
699 | { | |
700 | tpl->Status = Status; | |
701 | } | |
702 | ||
703 | static void tms380tr_chk_src_addr(unsigned char *frame, unsigned char *hw_addr) | |
704 | { | |
705 | unsigned char SRBit; | |
706 | ||
707 | if((((unsigned long)frame[8]) & ~0x80) != 0) /* Compare 4 bytes */ | |
708 | return; | |
709 | if((unsigned short)frame[12] != 0) /* Compare 2 bytes */ | |
710 | return; | |
711 | ||
712 | SRBit = frame[8] & 0x80; | |
713 | memcpy(&frame[8], hw_addr, 6); | |
714 | frame[8] |= SRBit; | |
715 | ||
716 | return; | |
717 | } | |
718 | ||
719 | /* | |
720 | * The timer routine: Check if adapter still open and working, reopen if not. | |
721 | */ | |
722 | static void tms380tr_timer_chk(unsigned long data) | |
723 | { | |
724 | struct net_device *dev = (struct net_device*)data; | |
725 | struct net_local *tp = netdev_priv(dev); | |
726 | ||
727 | if(tp->HaltInProgress) | |
728 | return; | |
729 | ||
730 | tms380tr_chk_outstanding_cmds(dev); | |
8e95a202 JP |
731 | if(time_before(tp->LastSendTime + SEND_TIMEOUT, jiffies) && |
732 | (tp->TplFree != tp->TplBusy)) | |
1da177e4 LT |
733 | { |
734 | /* Anything to send, but stalled too long */ | |
735 | tp->LastSendTime = jiffies; | |
736 | tms380tr_exec_cmd(dev, OC_CLOSE); /* Does reopen automatically */ | |
737 | } | |
738 | ||
739 | tp->timer.expires = jiffies + 2*HZ; | |
740 | add_timer(&tp->timer); | |
741 | ||
742 | if(tp->AdapterOpenFlag || tp->ReOpenInProgress) | |
743 | return; | |
744 | tp->ReOpenInProgress = 1; | |
745 | tms380tr_open_adapter(dev); | |
746 | ||
747 | return; | |
748 | } | |
749 | ||
750 | /* | |
751 | * The typical workload of the driver: Handle the network interface interrupts. | |
752 | */ | |
7d12e780 | 753 | irqreturn_t tms380tr_interrupt(int irq, void *dev_id) |
1da177e4 LT |
754 | { |
755 | struct net_device *dev = dev_id; | |
756 | struct net_local *tp; | |
757 | unsigned short irq_type; | |
758 | int handled = 0; | |
759 | ||
1da177e4 LT |
760 | tp = netdev_priv(dev); |
761 | ||
762 | irq_type = SIFREADW(SIFSTS); | |
763 | ||
764 | while(irq_type & STS_SYSTEM_IRQ) { | |
765 | handled = 1; | |
766 | irq_type &= STS_IRQ_MASK; | |
767 | ||
768 | if(!tms380tr_chk_ssb(tp, irq_type)) { | |
769 | printk(KERN_DEBUG "%s: DATA LATE occurred\n", dev->name); | |
770 | break; | |
771 | } | |
772 | ||
773 | switch(irq_type) { | |
774 | case STS_IRQ_RECEIVE_STATUS: | |
775 | tms380tr_reset_interrupt(dev); | |
776 | tms380tr_rcv_status_irq(dev); | |
777 | break; | |
778 | ||
779 | case STS_IRQ_TRANSMIT_STATUS: | |
780 | /* Check if TRANSMIT.HALT command is complete */ | |
781 | if(tp->ssb.Parm[0] & COMMAND_COMPLETE) { | |
782 | tp->TransmitCommandActive = 0; | |
783 | tp->TransmitHaltScheduled = 0; | |
784 | ||
785 | /* Issue a new transmit command. */ | |
786 | tms380tr_exec_cmd(dev, OC_TRANSMIT); | |
787 | } | |
788 | ||
789 | tms380tr_reset_interrupt(dev); | |
790 | tms380tr_tx_status_irq(dev); | |
791 | break; | |
792 | ||
793 | case STS_IRQ_COMMAND_STATUS: | |
794 | /* The SSB contains status of last command | |
795 | * other than receive/transmit. | |
796 | */ | |
797 | tms380tr_cmd_status_irq(dev); | |
798 | break; | |
799 | ||
800 | case STS_IRQ_SCB_CLEAR: | |
801 | /* The SCB is free for another command. */ | |
802 | tp->ScbInUse = 0; | |
803 | tms380tr_chk_outstanding_cmds(dev); | |
804 | break; | |
805 | ||
806 | case STS_IRQ_RING_STATUS: | |
807 | tms380tr_ring_status_irq(dev); | |
808 | break; | |
809 | ||
810 | case STS_IRQ_ADAPTER_CHECK: | |
811 | tms380tr_chk_irq(dev); | |
812 | break; | |
813 | ||
814 | case STS_IRQ_LLC_STATUS: | |
815 | printk(KERN_DEBUG "tms380tr: unexpected LLC status IRQ\n"); | |
816 | break; | |
817 | ||
818 | case STS_IRQ_TIMER: | |
819 | printk(KERN_DEBUG "tms380tr: unexpected Timer IRQ\n"); | |
820 | break; | |
821 | ||
822 | case STS_IRQ_RECEIVE_PENDING: | |
823 | printk(KERN_DEBUG "tms380tr: unexpected Receive Pending IRQ\n"); | |
824 | break; | |
825 | ||
826 | default: | |
827 | printk(KERN_DEBUG "Unknown Token Ring IRQ (0x%04x)\n", irq_type); | |
828 | break; | |
829 | } | |
830 | ||
831 | /* Reset system interrupt if not already done. */ | |
8e95a202 JP |
832 | if(irq_type != STS_IRQ_TRANSMIT_STATUS && |
833 | irq_type != STS_IRQ_RECEIVE_STATUS) { | |
1da177e4 LT |
834 | tms380tr_reset_interrupt(dev); |
835 | } | |
836 | ||
837 | irq_type = SIFREADW(SIFSTS); | |
838 | } | |
839 | ||
840 | return IRQ_RETVAL(handled); | |
841 | } | |
842 | ||
843 | /* | |
844 | * Reset the INTERRUPT SYSTEM bit and issue SSB CLEAR command. | |
845 | */ | |
846 | static void tms380tr_reset_interrupt(struct net_device *dev) | |
847 | { | |
848 | struct net_local *tp = netdev_priv(dev); | |
849 | SSB *ssb = &tp->ssb; | |
850 | ||
851 | /* | |
852 | * [Workaround for "Data Late"] | |
853 | * Set all fields of the SSB to well-defined values so we can | |
854 | * check if the adapter has written the SSB. | |
855 | */ | |
856 | ||
857 | ssb->STS = (unsigned short) -1; | |
858 | ssb->Parm[0] = (unsigned short) -1; | |
859 | ssb->Parm[1] = (unsigned short) -1; | |
860 | ssb->Parm[2] = (unsigned short) -1; | |
861 | ||
862 | /* Free SSB by issuing SSB_CLEAR command after reading IRQ code | |
863 | * and clear STS_SYSTEM_IRQ bit: enable adapter for further interrupts. | |
864 | */ | |
865 | tms380tr_exec_sifcmd(dev, CMD_SSB_CLEAR | CMD_CLEAR_SYSTEM_IRQ); | |
866 | ||
867 | return; | |
868 | } | |
869 | ||
870 | /* | |
871 | * Check if the SSB has actually been written by the adapter. | |
872 | */ | |
873 | static unsigned char tms380tr_chk_ssb(struct net_local *tp, unsigned short IrqType) | |
874 | { | |
875 | SSB *ssb = &tp->ssb; /* The address of the SSB. */ | |
876 | ||
877 | /* C 0 1 2 INTERRUPT CODE | |
878 | * - - - - -------------- | |
879 | * 1 1 1 1 TRANSMIT STATUS | |
880 | * 1 1 1 1 RECEIVE STATUS | |
881 | * 1 ? ? 0 COMMAND STATUS | |
882 | * 0 0 0 0 SCB CLEAR | |
883 | * 1 1 0 0 RING STATUS | |
884 | * 0 0 0 0 ADAPTER CHECK | |
885 | * | |
886 | * 0 = SSB field not affected by interrupt | |
887 | * 1 = SSB field is affected by interrupt | |
888 | * | |
889 | * C = SSB ADDRESS +0: COMMAND | |
890 | * 0 = SSB ADDRESS +2: STATUS 0 | |
891 | * 1 = SSB ADDRESS +4: STATUS 1 | |
892 | * 2 = SSB ADDRESS +6: STATUS 2 | |
893 | */ | |
894 | ||
895 | /* Check if this interrupt does use the SSB. */ | |
896 | ||
8e95a202 JP |
897 | if(IrqType != STS_IRQ_TRANSMIT_STATUS && |
898 | IrqType != STS_IRQ_RECEIVE_STATUS && | |
899 | IrqType != STS_IRQ_COMMAND_STATUS && | |
900 | IrqType != STS_IRQ_RING_STATUS) | |
1da177e4 LT |
901 | { |
902 | return (1); /* SSB not involved. */ | |
903 | } | |
904 | ||
905 | /* Note: All fields of the SSB have been set to all ones (-1) after it | |
906 | * has last been used by the software (see DriverIsr()). | |
907 | * | |
908 | * Check if the affected SSB fields are still unchanged. | |
909 | */ | |
910 | ||
911 | if(ssb->STS == (unsigned short) -1) | |
912 | return (0); /* Command field not yet available. */ | |
913 | if(IrqType == STS_IRQ_COMMAND_STATUS) | |
914 | return (1); /* Status fields not always affected. */ | |
915 | if(ssb->Parm[0] == (unsigned short) -1) | |
916 | return (0); /* Status 1 field not yet available. */ | |
917 | if(IrqType == STS_IRQ_RING_STATUS) | |
918 | return (1); /* Status 2 & 3 fields not affected. */ | |
919 | ||
920 | /* Note: At this point, the interrupt is either TRANSMIT or RECEIVE. */ | |
921 | if(ssb->Parm[1] == (unsigned short) -1) | |
922 | return (0); /* Status 2 field not yet available. */ | |
923 | if(ssb->Parm[2] == (unsigned short) -1) | |
924 | return (0); /* Status 3 field not yet available. */ | |
925 | ||
926 | return (1); /* All SSB fields have been written by the adapter. */ | |
927 | } | |
928 | ||
929 | /* | |
930 | * Evaluates the command results status in the SSB status field. | |
931 | */ | |
932 | static void tms380tr_cmd_status_irq(struct net_device *dev) | |
933 | { | |
934 | struct net_local *tp = netdev_priv(dev); | |
935 | unsigned short ssb_cmd, ssb_parm_0; | |
936 | unsigned short ssb_parm_1; | |
937 | char *open_err = "Open error -"; | |
938 | char *code_err = "Open code -"; | |
939 | ||
940 | /* Copy the ssb values to local variables */ | |
941 | ssb_cmd = tp->ssb.STS; | |
942 | ssb_parm_0 = tp->ssb.Parm[0]; | |
943 | ssb_parm_1 = tp->ssb.Parm[1]; | |
944 | ||
945 | if(ssb_cmd == OPEN) | |
946 | { | |
947 | tp->Sleeping = 0; | |
948 | if(!tp->ReOpenInProgress) | |
949 | wake_up_interruptible(&tp->wait_for_tok_int); | |
950 | ||
951 | tp->OpenCommandIssued = 0; | |
952 | tp->ScbInUse = 0; | |
953 | ||
954 | if((ssb_parm_0 & 0x00FF) == GOOD_COMPLETION) | |
955 | { | |
956 | /* Success, the adapter is open. */ | |
957 | tp->LobeWireFaultLogged = 0; | |
958 | tp->AdapterOpenFlag = 1; | |
959 | tp->AdapterVirtOpenFlag = 1; | |
960 | tp->TransmitCommandActive = 0; | |
961 | tms380tr_exec_cmd(dev, OC_TRANSMIT); | |
962 | tms380tr_exec_cmd(dev, OC_RECEIVE); | |
963 | ||
964 | if(tp->ReOpenInProgress) | |
965 | tp->ReOpenInProgress = 0; | |
966 | ||
967 | return; | |
968 | } | |
969 | else /* The adapter did not open. */ | |
970 | { | |
971 | if(ssb_parm_0 & NODE_ADDR_ERROR) | |
972 | printk(KERN_INFO "%s: Node address error\n", | |
973 | dev->name); | |
974 | if(ssb_parm_0 & LIST_SIZE_ERROR) | |
975 | printk(KERN_INFO "%s: List size error\n", | |
976 | dev->name); | |
977 | if(ssb_parm_0 & BUF_SIZE_ERROR) | |
978 | printk(KERN_INFO "%s: Buffer size error\n", | |
979 | dev->name); | |
980 | if(ssb_parm_0 & TX_BUF_COUNT_ERROR) | |
981 | printk(KERN_INFO "%s: Tx buffer count error\n", | |
982 | dev->name); | |
983 | if(ssb_parm_0 & INVALID_OPEN_OPTION) | |
984 | printk(KERN_INFO "%s: Invalid open option\n", | |
985 | dev->name); | |
986 | if(ssb_parm_0 & OPEN_ERROR) | |
987 | { | |
988 | /* Show the open phase. */ | |
989 | switch(ssb_parm_0 & OPEN_PHASES_MASK) | |
990 | { | |
991 | case LOBE_MEDIA_TEST: | |
992 | if(!tp->LobeWireFaultLogged) | |
993 | { | |
994 | tp->LobeWireFaultLogged = 1; | |
995 | printk(KERN_INFO "%s: %s Lobe wire fault (check cable !).\n", dev->name, open_err); | |
996 | } | |
997 | tp->ReOpenInProgress = 1; | |
998 | tp->AdapterOpenFlag = 0; | |
999 | tp->AdapterVirtOpenFlag = 1; | |
1000 | tms380tr_open_adapter(dev); | |
1001 | return; | |
1002 | ||
1003 | case PHYSICAL_INSERTION: | |
1004 | printk(KERN_INFO "%s: %s Physical insertion.\n", dev->name, open_err); | |
1005 | break; | |
1006 | ||
1007 | case ADDRESS_VERIFICATION: | |
1008 | printk(KERN_INFO "%s: %s Address verification.\n", dev->name, open_err); | |
1009 | break; | |
1010 | ||
1011 | case PARTICIPATION_IN_RING_POLL: | |
1012 | printk(KERN_INFO "%s: %s Participation in ring poll.\n", dev->name, open_err); | |
1013 | break; | |
1014 | ||
1015 | case REQUEST_INITIALISATION: | |
1016 | printk(KERN_INFO "%s: %s Request initialisation.\n", dev->name, open_err); | |
1017 | break; | |
1018 | ||
1019 | case FULLDUPLEX_CHECK: | |
1020 | printk(KERN_INFO "%s: %s Full duplex check.\n", dev->name, open_err); | |
1021 | break; | |
1022 | ||
1023 | default: | |
1024 | printk(KERN_INFO "%s: %s Unknown open phase\n", dev->name, open_err); | |
1025 | break; | |
1026 | } | |
1027 | ||
1028 | /* Show the open errors. */ | |
1029 | switch(ssb_parm_0 & OPEN_ERROR_CODES_MASK) | |
1030 | { | |
1031 | case OPEN_FUNCTION_FAILURE: | |
1032 | printk(KERN_INFO "%s: %s OPEN_FUNCTION_FAILURE", dev->name, code_err); | |
1033 | tp->LastOpenStatus = | |
1034 | OPEN_FUNCTION_FAILURE; | |
1035 | break; | |
1036 | ||
1037 | case OPEN_SIGNAL_LOSS: | |
1038 | printk(KERN_INFO "%s: %s OPEN_SIGNAL_LOSS\n", dev->name, code_err); | |
1039 | tp->LastOpenStatus = | |
1040 | OPEN_SIGNAL_LOSS; | |
1041 | break; | |
1042 | ||
1043 | case OPEN_TIMEOUT: | |
1044 | printk(KERN_INFO "%s: %s OPEN_TIMEOUT\n", dev->name, code_err); | |
1045 | tp->LastOpenStatus = | |
1046 | OPEN_TIMEOUT; | |
1047 | break; | |
1048 | ||
1049 | case OPEN_RING_FAILURE: | |
1050 | printk(KERN_INFO "%s: %s OPEN_RING_FAILURE\n", dev->name, code_err); | |
1051 | tp->LastOpenStatus = | |
1052 | OPEN_RING_FAILURE; | |
1053 | break; | |
1054 | ||
1055 | case OPEN_RING_BEACONING: | |
1056 | printk(KERN_INFO "%s: %s OPEN_RING_BEACONING\n", dev->name, code_err); | |
1057 | tp->LastOpenStatus = | |
1058 | OPEN_RING_BEACONING; | |
1059 | break; | |
1060 | ||
1061 | case OPEN_DUPLICATE_NODEADDR: | |
1062 | printk(KERN_INFO "%s: %s OPEN_DUPLICATE_NODEADDR\n", dev->name, code_err); | |
1063 | tp->LastOpenStatus = | |
1064 | OPEN_DUPLICATE_NODEADDR; | |
1065 | break; | |
1066 | ||
1067 | case OPEN_REQUEST_INIT: | |
1068 | printk(KERN_INFO "%s: %s OPEN_REQUEST_INIT\n", dev->name, code_err); | |
1069 | tp->LastOpenStatus = | |
1070 | OPEN_REQUEST_INIT; | |
1071 | break; | |
1072 | ||
1073 | case OPEN_REMOVE_RECEIVED: | |
1074 | printk(KERN_INFO "%s: %s OPEN_REMOVE_RECEIVED", dev->name, code_err); | |
1075 | tp->LastOpenStatus = | |
1076 | OPEN_REMOVE_RECEIVED; | |
1077 | break; | |
1078 | ||
1079 | case OPEN_FULLDUPLEX_SET: | |
1080 | printk(KERN_INFO "%s: %s OPEN_FULLDUPLEX_SET\n", dev->name, code_err); | |
1081 | tp->LastOpenStatus = | |
1082 | OPEN_FULLDUPLEX_SET; | |
1083 | break; | |
1084 | ||
1085 | default: | |
1086 | printk(KERN_INFO "%s: %s Unknown open err code", dev->name, code_err); | |
1087 | tp->LastOpenStatus = | |
1088 | OPEN_FUNCTION_FAILURE; | |
1089 | break; | |
1090 | } | |
1091 | } | |
1092 | ||
1093 | tp->AdapterOpenFlag = 0; | |
1094 | tp->AdapterVirtOpenFlag = 0; | |
1095 | ||
1096 | return; | |
1097 | } | |
1098 | } | |
1099 | else | |
1100 | { | |
1101 | if(ssb_cmd != READ_ERROR_LOG) | |
1102 | return; | |
1103 | ||
1104 | /* Add values from the error log table to the MAC | |
1105 | * statistics counters and update the errorlogtable | |
1106 | * memory. | |
1107 | */ | |
1108 | tp->MacStat.line_errors += tp->errorlogtable.Line_Error; | |
1109 | tp->MacStat.burst_errors += tp->errorlogtable.Burst_Error; | |
1110 | tp->MacStat.A_C_errors += tp->errorlogtable.ARI_FCI_Error; | |
1111 | tp->MacStat.lost_frames += tp->errorlogtable.Lost_Frame_Error; | |
1112 | tp->MacStat.recv_congest_count += tp->errorlogtable.Rx_Congest_Error; | |
1113 | tp->MacStat.rx_errors += tp->errorlogtable.Rx_Congest_Error; | |
1114 | tp->MacStat.frame_copied_errors += tp->errorlogtable.Frame_Copied_Error; | |
1115 | tp->MacStat.token_errors += tp->errorlogtable.Token_Error; | |
1116 | tp->MacStat.dummy1 += tp->errorlogtable.DMA_Bus_Error; | |
1117 | tp->MacStat.dummy1 += tp->errorlogtable.DMA_Parity_Error; | |
1118 | tp->MacStat.abort_delimiters += tp->errorlogtable.AbortDelimeters; | |
1119 | tp->MacStat.frequency_errors += tp->errorlogtable.Frequency_Error; | |
1120 | tp->MacStat.internal_errors += tp->errorlogtable.Internal_Error; | |
1121 | } | |
1122 | ||
1123 | return; | |
1124 | } | |
1125 | ||
1126 | /* | |
1127 | * The inverse routine to tms380tr_open(). | |
1128 | */ | |
1129 | int tms380tr_close(struct net_device *dev) | |
1130 | { | |
1131 | struct net_local *tp = netdev_priv(dev); | |
1132 | netif_stop_queue(dev); | |
1133 | ||
1134 | del_timer(&tp->timer); | |
1135 | ||
1136 | /* Flush the Tx and disable Rx here. */ | |
1137 | ||
1138 | tp->HaltInProgress = 1; | |
1139 | tms380tr_exec_cmd(dev, OC_CLOSE); | |
1140 | tp->timer.expires = jiffies + 1*HZ; | |
1141 | tp->timer.function = tms380tr_timer_end_wait; | |
1142 | tp->timer.data = (unsigned long)dev; | |
1143 | add_timer(&tp->timer); | |
1144 | ||
1145 | tms380tr_enable_interrupts(dev); | |
1146 | ||
1147 | tp->Sleeping = 1; | |
1148 | interruptible_sleep_on(&tp->wait_for_tok_int); | |
1149 | tp->TransmitCommandActive = 0; | |
1150 | ||
1151 | del_timer(&tp->timer); | |
1152 | tms380tr_disable_interrupts(dev); | |
1153 | ||
1154 | #ifdef CONFIG_ISA | |
1155 | if(dev->dma > 0) | |
1156 | { | |
1157 | unsigned long flags=claim_dma_lock(); | |
1158 | disable_dma(dev->dma); | |
1159 | release_dma_lock(flags); | |
1160 | } | |
1161 | #endif | |
1162 | ||
1163 | SIFWRITEW(0xFF00, SIFCMD); | |
1164 | #if 0 | |
1165 | if(dev->dma > 0) /* what the? */ | |
1166 | SIFWRITEB(0xff, POSREG); | |
1167 | #endif | |
1168 | tms380tr_cancel_tx_queue(tp); | |
1169 | ||
1170 | return (0); | |
1171 | } | |
1172 | ||
1173 | /* | |
1174 | * Get the current statistics. This may be called with the card open | |
1175 | * or closed. | |
1176 | */ | |
1177 | static struct net_device_stats *tms380tr_get_stats(struct net_device *dev) | |
1178 | { | |
1179 | struct net_local *tp = netdev_priv(dev); | |
1180 | ||
1181 | return ((struct net_device_stats *)&tp->MacStat); | |
1182 | } | |
1183 | ||
1184 | /* | |
1185 | * Set or clear the multicast filter for this adapter. | |
1186 | */ | |
1187 | static void tms380tr_set_multicast_list(struct net_device *dev) | |
1188 | { | |
1189 | struct net_local *tp = netdev_priv(dev); | |
1190 | unsigned int OpenOptions; | |
1191 | ||
1192 | OpenOptions = tp->ocpl.OPENOptions & | |
1193 | ~(PASS_ADAPTER_MAC_FRAMES | |
1194 | | PASS_ATTENTION_FRAMES | |
1195 | | PASS_BEACON_MAC_FRAMES | |
1196 | | COPY_ALL_MAC_FRAMES | |
1197 | | COPY_ALL_NON_MAC_FRAMES); | |
1198 | ||
1199 | tp->ocpl.FunctAddr = 0; | |
1200 | ||
1201 | if(dev->flags & IFF_PROMISC) | |
1202 | /* Enable promiscuous mode */ | |
1203 | OpenOptions |= COPY_ALL_NON_MAC_FRAMES | | |
1204 | COPY_ALL_MAC_FRAMES; | |
1205 | else | |
1206 | { | |
1207 | if(dev->flags & IFF_ALLMULTI) | |
1208 | { | |
1209 | /* Disable promiscuous mode, use normal mode. */ | |
1210 | tp->ocpl.FunctAddr = 0xFFFFFFFF; | |
1211 | } | |
1212 | else | |
1213 | { | |
16cad981 JP |
1214 | struct dev_mc_list *mclist; |
1215 | ||
1216 | netdev_for_each_mc_addr(mclist, dev) { | |
1da177e4 LT |
1217 | ((char *)(&tp->ocpl.FunctAddr))[0] |= |
1218 | mclist->dmi_addr[2]; | |
1219 | ((char *)(&tp->ocpl.FunctAddr))[1] |= | |
1220 | mclist->dmi_addr[3]; | |
1221 | ((char *)(&tp->ocpl.FunctAddr))[2] |= | |
1222 | mclist->dmi_addr[4]; | |
1223 | ((char *)(&tp->ocpl.FunctAddr))[3] |= | |
1224 | mclist->dmi_addr[5]; | |
1da177e4 LT |
1225 | } |
1226 | } | |
1227 | tms380tr_exec_cmd(dev, OC_SET_FUNCT_ADDR); | |
1228 | } | |
1229 | ||
1230 | tp->ocpl.OPENOptions = OpenOptions; | |
1231 | tms380tr_exec_cmd(dev, OC_MODIFY_OPEN_PARMS); | |
1232 | return; | |
1233 | } | |
1234 | ||
1235 | /* | |
1236 | * Wait for some time (microseconds) | |
1237 | */ | |
1238 | void tms380tr_wait(unsigned long time) | |
1239 | { | |
1240 | #if 0 | |
1241 | long tmp; | |
1242 | ||
1243 | tmp = jiffies + time/(1000000/HZ); | |
1244 | do { | |
3173c890 | 1245 | tmp = schedule_timeout_interruptible(tmp); |
1da177e4 LT |
1246 | } while(time_after(tmp, jiffies)); |
1247 | #else | |
1248 | udelay(time); | |
1249 | #endif | |
1250 | return; | |
1251 | } | |
1252 | ||
1253 | /* | |
1254 | * Write a command value to the SIFCMD register | |
1255 | */ | |
1256 | static void tms380tr_exec_sifcmd(struct net_device *dev, unsigned int WriteValue) | |
1257 | { | |
1258 | unsigned short cmd; | |
1259 | unsigned short SifStsValue; | |
1260 | unsigned long loop_counter; | |
1261 | ||
1262 | WriteValue = ((WriteValue ^ CMD_SYSTEM_IRQ) | CMD_INTERRUPT_ADAPTER); | |
1263 | cmd = (unsigned short)WriteValue; | |
1264 | loop_counter = 0,5 * 800000; | |
1265 | do { | |
1266 | SifStsValue = SIFREADW(SIFSTS); | |
1267 | } while((SifStsValue & CMD_INTERRUPT_ADAPTER) && loop_counter--); | |
1268 | SIFWRITEW(cmd, SIFCMD); | |
1269 | ||
1270 | return; | |
1271 | } | |
1272 | ||
1273 | /* | |
1274 | * Processes adapter hardware reset, halts adapter and downloads firmware, | |
1275 | * clears the halt bit. | |
1276 | */ | |
1277 | static int tms380tr_reset_adapter(struct net_device *dev) | |
1278 | { | |
1279 | struct net_local *tp = netdev_priv(dev); | |
1280 | unsigned short *fw_ptr; | |
1281 | unsigned short count, c, count2; | |
1282 | const struct firmware *fw_entry = NULL; | |
1283 | ||
504ff16c | 1284 | if (request_firmware(&fw_entry, "tms380tr.bin", tp->pdev) != 0) { |
1da177e4 LT |
1285 | printk(KERN_ALERT "%s: firmware %s is missing, cannot start.\n", |
1286 | dev->name, "tms380tr.bin"); | |
1287 | return (-1); | |
1288 | } | |
1289 | ||
1290 | fw_ptr = (unsigned short *)fw_entry->data; | |
1291 | count2 = fw_entry->size / 2; | |
1292 | ||
1293 | /* Hardware adapter reset */ | |
1294 | SIFWRITEW(ACL_ARESET, SIFACL); | |
1295 | tms380tr_wait(40); | |
1296 | ||
1297 | c = SIFREADW(SIFACL); | |
1298 | tms380tr_wait(20); | |
1299 | ||
1300 | if(dev->dma == 0) /* For PCI adapters */ | |
1301 | { | |
1302 | c &= ~(ACL_NSELOUT0 | ACL_NSELOUT1); /* Clear bits */ | |
1303 | if(tp->setnselout) | |
1304 | c |= (*tp->setnselout)(dev); | |
1305 | } | |
1306 | ||
1307 | /* In case a command is pending - forget it */ | |
1308 | tp->ScbInUse = 0; | |
1309 | ||
1310 | c &= ~ACL_ARESET; /* Clear adapter reset bit */ | |
1311 | c |= ACL_CPHALT; /* Halt adapter CPU, allow download */ | |
1312 | c |= ACL_BOOT; | |
1313 | c |= ACL_SINTEN; | |
1314 | c &= ~ACL_PSDMAEN; /* Clear pseudo dma bit */ | |
1315 | SIFWRITEW(c, SIFACL); | |
1316 | tms380tr_wait(40); | |
1317 | ||
1318 | count = 0; | |
1319 | /* Download firmware via DIO interface: */ | |
1320 | do { | |
1321 | if (count2 < 3) continue; | |
1322 | ||
1323 | /* Download first address part */ | |
1324 | SIFWRITEW(*fw_ptr, SIFADX); | |
1325 | fw_ptr++; | |
1326 | count2--; | |
1327 | /* Download second address part */ | |
1328 | SIFWRITEW(*fw_ptr, SIFADD); | |
1329 | fw_ptr++; | |
1330 | count2--; | |
1331 | ||
1332 | if((count = *fw_ptr) != 0) /* Load loop counter */ | |
1333 | { | |
1334 | fw_ptr++; /* Download block data */ | |
1335 | count2--; | |
1336 | if (count > count2) continue; | |
1337 | ||
1338 | for(; count > 0; count--) | |
1339 | { | |
1340 | SIFWRITEW(*fw_ptr, SIFINC); | |
1341 | fw_ptr++; | |
1342 | count2--; | |
1343 | } | |
1344 | } | |
1345 | else /* Stop, if last block downloaded */ | |
1346 | { | |
1347 | c = SIFREADW(SIFACL); | |
1348 | c &= (~ACL_CPHALT | ACL_SINTEN); | |
1349 | ||
1350 | /* Clear CPHALT and start BUD */ | |
1351 | SIFWRITEW(c, SIFACL); | |
1352 | if (fw_entry) | |
1353 | release_firmware(fw_entry); | |
1354 | return (1); | |
1355 | } | |
1356 | } while(count == 0); | |
1357 | ||
1358 | if (fw_entry) | |
1359 | release_firmware(fw_entry); | |
1360 | printk(KERN_INFO "%s: Adapter Download Failed\n", dev->name); | |
1361 | return (-1); | |
1362 | } | |
1363 | ||
b3ccbb24 BH |
1364 | MODULE_FIRMWARE("tms380tr.bin"); |
1365 | ||
1da177e4 LT |
1366 | /* |
1367 | * Starts bring up diagnostics of token ring adapter and evaluates | |
1368 | * diagnostic results. | |
1369 | */ | |
1370 | static int tms380tr_bringup_diags(struct net_device *dev) | |
1371 | { | |
1372 | int loop_cnt, retry_cnt; | |
1373 | unsigned short Status; | |
1374 | ||
1375 | tms380tr_wait(HALF_SECOND); | |
1376 | tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET); | |
1377 | tms380tr_wait(HALF_SECOND); | |
1378 | ||
1379 | retry_cnt = BUD_MAX_RETRIES; /* maximal number of retrys */ | |
1380 | ||
1381 | do { | |
1382 | retry_cnt--; | |
1383 | if(tms380tr_debug > 3) | |
1384 | printk(KERN_DEBUG "BUD-Status: "); | |
1385 | loop_cnt = BUD_MAX_LOOPCNT; /* maximum: three seconds*/ | |
1386 | do { /* Inspect BUD results */ | |
1387 | loop_cnt--; | |
1388 | tms380tr_wait(HALF_SECOND); | |
1389 | Status = SIFREADW(SIFSTS); | |
1390 | Status &= STS_MASK; | |
1391 | ||
1392 | if(tms380tr_debug > 3) | |
1393 | printk(KERN_DEBUG " %04X \n", Status); | |
1394 | /* BUD successfully completed */ | |
1395 | if(Status == STS_INITIALIZE) | |
1396 | return (1); | |
1397 | /* Unrecoverable hardware error, BUD not completed? */ | |
1398 | } while((loop_cnt > 0) && ((Status & (STS_ERROR | STS_TEST)) | |
1399 | != (STS_ERROR | STS_TEST))); | |
1400 | ||
1401 | /* Error preventing completion of BUD */ | |
1402 | if(retry_cnt > 0) | |
1403 | { | |
1404 | printk(KERN_INFO "%s: Adapter Software Reset.\n", | |
1405 | dev->name); | |
1406 | tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET); | |
1407 | tms380tr_wait(HALF_SECOND); | |
1408 | } | |
1409 | } while(retry_cnt > 0); | |
1410 | ||
1411 | Status = SIFREADW(SIFSTS); | |
1412 | ||
1413 | printk(KERN_INFO "%s: Hardware error\n", dev->name); | |
1414 | /* Hardware error occurred! */ | |
1415 | Status &= 0x001f; | |
1416 | if (Status & 0x0010) | |
1417 | printk(KERN_INFO "%s: BUD Error: Timeout\n", dev->name); | |
1418 | else if ((Status & 0x000f) > 6) | |
1419 | printk(KERN_INFO "%s: BUD Error: Illegal Failure\n", dev->name); | |
1420 | else | |
1421 | printk(KERN_INFO "%s: Bring Up Diagnostics Error (%04X) occurred\n", dev->name, Status & 0x000f); | |
1422 | ||
1423 | return (-1); | |
1424 | } | |
1425 | ||
1426 | /* | |
1427 | * Copy initialisation data to adapter memory, beginning at address | |
1428 | * 1:0A00; Starting DMA test and evaluating result bits. | |
1429 | */ | |
1430 | static int tms380tr_init_adapter(struct net_device *dev) | |
1431 | { | |
1432 | struct net_local *tp = netdev_priv(dev); | |
1433 | ||
1434 | const unsigned char SCB_Test[6] = {0x00, 0x00, 0xC1, 0xE2, 0xD4, 0x8B}; | |
1435 | const unsigned char SSB_Test[8] = {0xFF, 0xFF, 0xD1, 0xD7, | |
1436 | 0xC5, 0xD9, 0xC3, 0xD4}; | |
1437 | void *ptr = (void *)&tp->ipb; | |
1438 | unsigned short *ipb_ptr = (unsigned short *)ptr; | |
1439 | unsigned char *cb_ptr = (unsigned char *) &tp->scb; | |
1440 | unsigned char *sb_ptr = (unsigned char *) &tp->ssb; | |
1441 | unsigned short Status; | |
1442 | int i, loop_cnt, retry_cnt; | |
1443 | ||
1444 | /* Normalize: byte order low/high, word order high/low! (only IPB!) */ | |
1445 | tp->ipb.SCB_Addr = SWAPW(((char *)&tp->scb - (char *)tp) + tp->dmabuffer); | |
1446 | tp->ipb.SSB_Addr = SWAPW(((char *)&tp->ssb - (char *)tp) + tp->dmabuffer); | |
1447 | ||
1448 | if(tms380tr_debug > 3) | |
1449 | { | |
1450 | printk(KERN_DEBUG "%s: buffer (real): %lx\n", dev->name, (long) &tp->scb); | |
1451 | printk(KERN_DEBUG "%s: buffer (virt): %lx\n", dev->name, (long) ((char *)&tp->scb - (char *)tp) + (long) tp->dmabuffer); | |
1452 | printk(KERN_DEBUG "%s: buffer (DMA) : %lx\n", dev->name, (long) tp->dmabuffer); | |
1453 | printk(KERN_DEBUG "%s: buffer (tp) : %lx\n", dev->name, (long) tp); | |
1454 | } | |
1455 | /* Maximum: three initialization retries */ | |
1456 | retry_cnt = INIT_MAX_RETRIES; | |
1457 | ||
1458 | do { | |
1459 | retry_cnt--; | |
1460 | ||
1461 | /* Transfer initialization block */ | |
1462 | SIFWRITEW(0x0001, SIFADX); | |
1463 | ||
1464 | /* To address 0001:0A00 of adapter RAM */ | |
1465 | SIFWRITEW(0x0A00, SIFADD); | |
1466 | ||
1467 | /* Write 11 words to adapter RAM */ | |
1468 | for(i = 0; i < 11; i++) | |
1469 | SIFWRITEW(ipb_ptr[i], SIFINC); | |
1470 | ||
1471 | /* Execute SCB adapter command */ | |
1472 | tms380tr_exec_sifcmd(dev, CMD_EXECUTE); | |
1473 | ||
1474 | loop_cnt = INIT_MAX_LOOPCNT; /* Maximum: 11 seconds */ | |
1475 | ||
1476 | /* While remaining retries, no error and not completed */ | |
1477 | do { | |
1478 | Status = 0; | |
1479 | loop_cnt--; | |
1480 | tms380tr_wait(HALF_SECOND); | |
1481 | ||
1482 | /* Mask interesting status bits */ | |
1483 | Status = SIFREADW(SIFSTS); | |
1484 | Status &= STS_MASK; | |
8e95a202 JP |
1485 | } while(((Status &(STS_INITIALIZE | STS_ERROR | STS_TEST)) != 0) && |
1486 | ((Status & STS_ERROR) == 0) && (loop_cnt != 0)); | |
1da177e4 LT |
1487 | |
1488 | if((Status & (STS_INITIALIZE | STS_ERROR | STS_TEST)) == 0) | |
1489 | { | |
1490 | /* Initialization completed without error */ | |
1491 | i = 0; | |
1492 | do { /* Test if contents of SCB is valid */ | |
1493 | if(SCB_Test[i] != *(cb_ptr + i)) | |
1494 | { | |
1495 | printk(KERN_INFO "%s: DMA failed\n", dev->name); | |
1496 | /* DMA data error: wrong data in SCB */ | |
1497 | return (-1); | |
1498 | } | |
1499 | i++; | |
1500 | } while(i < 6); | |
1501 | ||
1502 | i = 0; | |
1503 | do { /* Test if contents of SSB is valid */ | |
1504 | if(SSB_Test[i] != *(sb_ptr + i)) | |
1505 | /* DMA data error: wrong data in SSB */ | |
1506 | return (-1); | |
1507 | i++; | |
1508 | } while (i < 8); | |
1509 | ||
1510 | return (1); /* Adapter successfully initialized */ | |
1511 | } | |
1512 | else | |
1513 | { | |
1514 | if((Status & STS_ERROR) != 0) | |
1515 | { | |
1516 | /* Initialization error occurred */ | |
1517 | Status = SIFREADW(SIFSTS); | |
1518 | Status &= STS_ERROR_MASK; | |
1519 | /* ShowInitialisationErrorCode(Status); */ | |
1520 | printk(KERN_INFO "%s: Status error: %d\n", dev->name, Status); | |
1521 | return (-1); /* Unrecoverable error */ | |
1522 | } | |
1523 | else | |
1524 | { | |
1525 | if(retry_cnt > 0) | |
1526 | { | |
1527 | /* Reset adapter and try init again */ | |
1528 | tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET); | |
1529 | tms380tr_wait(HALF_SECOND); | |
1530 | } | |
1531 | } | |
1532 | } | |
1533 | } while(retry_cnt > 0); | |
1534 | ||
1535 | printk(KERN_INFO "%s: Retry exceeded\n", dev->name); | |
1536 | return (-1); | |
1537 | } | |
1538 | ||
1539 | /* | |
1540 | * Check for outstanding commands in command queue and tries to execute | |
1541 | * command immediately. Corresponding command flag in command queue is cleared. | |
1542 | */ | |
1543 | static void tms380tr_chk_outstanding_cmds(struct net_device *dev) | |
1544 | { | |
1545 | struct net_local *tp = netdev_priv(dev); | |
1546 | unsigned long Addr = 0; | |
1547 | ||
1548 | if(tp->CMDqueue == 0) | |
1549 | return; /* No command execution */ | |
1550 | ||
1551 | /* If SCB in use: no command */ | |
1552 | if(tp->ScbInUse == 1) | |
1553 | return; | |
1554 | ||
1555 | /* Check if adapter is opened, avoiding COMMAND_REJECT | |
1556 | * interrupt by the adapter! | |
1557 | */ | |
1558 | if(tp->AdapterOpenFlag == 0) | |
1559 | { | |
1560 | if(tp->CMDqueue & OC_OPEN) | |
1561 | { | |
1562 | /* Execute OPEN command */ | |
1563 | tp->CMDqueue ^= OC_OPEN; | |
1564 | ||
1565 | Addr = htonl(((char *)&tp->ocpl - (char *)tp) + tp->dmabuffer); | |
1566 | tp->scb.Parm[0] = LOWORD(Addr); | |
1567 | tp->scb.Parm[1] = HIWORD(Addr); | |
1568 | tp->scb.CMD = OPEN; | |
1569 | } | |
1570 | else | |
1571 | /* No OPEN command queued, but adapter closed. Note: | |
1572 | * We'll try to re-open the adapter in DriverPoll() | |
1573 | */ | |
1574 | return; /* No adapter command issued */ | |
1575 | } | |
1576 | else | |
1577 | { | |
1578 | /* Adapter is open; evaluate command queue: try to execute | |
1579 | * outstanding commands (depending on priority!) CLOSE | |
1580 | * command queued | |
1581 | */ | |
1582 | if(tp->CMDqueue & OC_CLOSE) | |
1583 | { | |
1584 | tp->CMDqueue ^= OC_CLOSE; | |
1585 | tp->AdapterOpenFlag = 0; | |
1586 | tp->scb.Parm[0] = 0; /* Parm[0], Parm[1] are ignored */ | |
1587 | tp->scb.Parm[1] = 0; /* but should be set to zero! */ | |
1588 | tp->scb.CMD = CLOSE; | |
1589 | if(!tp->HaltInProgress) | |
1590 | tp->CMDqueue |= OC_OPEN; /* re-open adapter */ | |
1591 | else | |
1592 | tp->CMDqueue = 0; /* no more commands */ | |
1593 | } | |
1594 | else | |
1595 | { | |
1596 | if(tp->CMDqueue & OC_RECEIVE) | |
1597 | { | |
1598 | tp->CMDqueue ^= OC_RECEIVE; | |
1599 | Addr = htonl(((char *)tp->RplHead - (char *)tp) + tp->dmabuffer); | |
1600 | tp->scb.Parm[0] = LOWORD(Addr); | |
1601 | tp->scb.Parm[1] = HIWORD(Addr); | |
1602 | tp->scb.CMD = RECEIVE; | |
1603 | } | |
1604 | else | |
1605 | { | |
1606 | if(tp->CMDqueue & OC_TRANSMIT_HALT) | |
1607 | { | |
1608 | /* NOTE: TRANSMIT.HALT must be checked | |
1609 | * before TRANSMIT. | |
1610 | */ | |
1611 | tp->CMDqueue ^= OC_TRANSMIT_HALT; | |
1612 | tp->scb.CMD = TRANSMIT_HALT; | |
1613 | ||
1614 | /* Parm[0] and Parm[1] are ignored | |
1615 | * but should be set to zero! | |
1616 | */ | |
1617 | tp->scb.Parm[0] = 0; | |
1618 | tp->scb.Parm[1] = 0; | |
1619 | } | |
1620 | else | |
1621 | { | |
1622 | if(tp->CMDqueue & OC_TRANSMIT) | |
1623 | { | |
1624 | /* NOTE: TRANSMIT must be | |
1625 | * checked after TRANSMIT.HALT | |
1626 | */ | |
1627 | if(tp->TransmitCommandActive) | |
1628 | { | |
1629 | if(!tp->TransmitHaltScheduled) | |
1630 | { | |
1631 | tp->TransmitHaltScheduled = 1; | |
1632 | tms380tr_exec_cmd(dev, OC_TRANSMIT_HALT) ; | |
1633 | } | |
1634 | tp->TransmitCommandActive = 0; | |
1635 | return; | |
1636 | } | |
1637 | ||
1638 | tp->CMDqueue ^= OC_TRANSMIT; | |
1639 | tms380tr_cancel_tx_queue(tp); | |
1640 | Addr = htonl(((char *)tp->TplBusy - (char *)tp) + tp->dmabuffer); | |
1641 | tp->scb.Parm[0] = LOWORD(Addr); | |
1642 | tp->scb.Parm[1] = HIWORD(Addr); | |
1643 | tp->scb.CMD = TRANSMIT; | |
1644 | tp->TransmitCommandActive = 1; | |
1645 | } | |
1646 | else | |
1647 | { | |
1648 | if(tp->CMDqueue & OC_MODIFY_OPEN_PARMS) | |
1649 | { | |
1650 | tp->CMDqueue ^= OC_MODIFY_OPEN_PARMS; | |
1651 | tp->scb.Parm[0] = tp->ocpl.OPENOptions; /* new OPEN options*/ | |
1652 | tp->scb.Parm[0] |= ENABLE_FULL_DUPLEX_SELECTION; | |
1653 | tp->scb.Parm[1] = 0; /* is ignored but should be zero */ | |
1654 | tp->scb.CMD = MODIFY_OPEN_PARMS; | |
1655 | } | |
1656 | else | |
1657 | { | |
1658 | if(tp->CMDqueue & OC_SET_FUNCT_ADDR) | |
1659 | { | |
1660 | tp->CMDqueue ^= OC_SET_FUNCT_ADDR; | |
1661 | tp->scb.Parm[0] = LOWORD(tp->ocpl.FunctAddr); | |
1662 | tp->scb.Parm[1] = HIWORD(tp->ocpl.FunctAddr); | |
1663 | tp->scb.CMD = SET_FUNCT_ADDR; | |
1664 | } | |
1665 | else | |
1666 | { | |
1667 | if(tp->CMDqueue & OC_SET_GROUP_ADDR) | |
1668 | { | |
1669 | tp->CMDqueue ^= OC_SET_GROUP_ADDR; | |
1670 | tp->scb.Parm[0] = LOWORD(tp->ocpl.GroupAddr); | |
1671 | tp->scb.Parm[1] = HIWORD(tp->ocpl.GroupAddr); | |
1672 | tp->scb.CMD = SET_GROUP_ADDR; | |
1673 | } | |
1674 | else | |
1675 | { | |
1676 | if(tp->CMDqueue & OC_READ_ERROR_LOG) | |
1677 | { | |
1678 | tp->CMDqueue ^= OC_READ_ERROR_LOG; | |
1679 | Addr = htonl(((char *)&tp->errorlogtable - (char *)tp) + tp->dmabuffer); | |
1680 | tp->scb.Parm[0] = LOWORD(Addr); | |
1681 | tp->scb.Parm[1] = HIWORD(Addr); | |
1682 | tp->scb.CMD = READ_ERROR_LOG; | |
1683 | } | |
1684 | else | |
1685 | { | |
1686 | printk(KERN_WARNING "CheckForOutstandingCommand: unknown Command\n"); | |
1687 | tp->CMDqueue = 0; | |
1688 | return; | |
1689 | } | |
1690 | } | |
1691 | } | |
1692 | } | |
1693 | } | |
1694 | } | |
1695 | } | |
1696 | } | |
1697 | } | |
1698 | ||
1699 | tp->ScbInUse = 1; /* Set semaphore: SCB in use. */ | |
1700 | ||
1701 | /* Execute SCB and generate IRQ when done. */ | |
1702 | tms380tr_exec_sifcmd(dev, CMD_EXECUTE | CMD_SCB_REQUEST); | |
1703 | ||
1704 | return; | |
1705 | } | |
1706 | ||
1707 | /* | |
1708 | * IRQ conditions: signal loss on the ring, transmit or receive of beacon | |
1709 | * frames (disabled if bit 1 of OPEN option is set); report error MAC | |
1710 | * frame transmit (disabled if bit 2 of OPEN option is set); open or short | |
1711 | * circuit fault on the lobe is detected; remove MAC frame received; | |
1712 | * error counter overflow (255); opened adapter is the only station in ring. | |
1713 | * After some of the IRQs the adapter is closed! | |
1714 | */ | |
1715 | static void tms380tr_ring_status_irq(struct net_device *dev) | |
1716 | { | |
1717 | struct net_local *tp = netdev_priv(dev); | |
1718 | ||
1719 | tp->CurrentRingStatus = be16_to_cpu((unsigned short)tp->ssb.Parm[0]); | |
1720 | ||
1721 | /* First: fill up statistics */ | |
1722 | if(tp->ssb.Parm[0] & SIGNAL_LOSS) | |
1723 | { | |
1724 | printk(KERN_INFO "%s: Signal Loss\n", dev->name); | |
1725 | tp->MacStat.line_errors++; | |
1726 | } | |
1727 | ||
1728 | /* Adapter is closed, but initialized */ | |
1729 | if(tp->ssb.Parm[0] & LOBE_WIRE_FAULT) | |
1730 | { | |
1731 | printk(KERN_INFO "%s: Lobe Wire Fault, Reopen Adapter\n", | |
1732 | dev->name); | |
1733 | tp->MacStat.line_errors++; | |
1734 | } | |
1735 | ||
1736 | if(tp->ssb.Parm[0] & RING_RECOVERY) | |
1737 | printk(KERN_INFO "%s: Ring Recovery\n", dev->name); | |
1738 | ||
1739 | /* Counter overflow: read error log */ | |
1740 | if(tp->ssb.Parm[0] & COUNTER_OVERFLOW) | |
1741 | { | |
1742 | printk(KERN_INFO "%s: Counter Overflow\n", dev->name); | |
1743 | tms380tr_exec_cmd(dev, OC_READ_ERROR_LOG); | |
1744 | } | |
1745 | ||
1746 | /* Adapter is closed, but initialized */ | |
1747 | if(tp->ssb.Parm[0] & REMOVE_RECEIVED) | |
1748 | printk(KERN_INFO "%s: Remove Received, Reopen Adapter\n", | |
1749 | dev->name); | |
1750 | ||
1751 | /* Adapter is closed, but initialized */ | |
1752 | if(tp->ssb.Parm[0] & AUTO_REMOVAL_ERROR) | |
1753 | printk(KERN_INFO "%s: Auto Removal Error, Reopen Adapter\n", | |
1754 | dev->name); | |
1755 | ||
1756 | if(tp->ssb.Parm[0] & HARD_ERROR) | |
1757 | printk(KERN_INFO "%s: Hard Error\n", dev->name); | |
1758 | ||
1759 | if(tp->ssb.Parm[0] & SOFT_ERROR) | |
1760 | printk(KERN_INFO "%s: Soft Error\n", dev->name); | |
1761 | ||
1762 | if(tp->ssb.Parm[0] & TRANSMIT_BEACON) | |
1763 | printk(KERN_INFO "%s: Transmit Beacon\n", dev->name); | |
1764 | ||
1765 | if(tp->ssb.Parm[0] & SINGLE_STATION) | |
1766 | printk(KERN_INFO "%s: Single Station\n", dev->name); | |
1767 | ||
1768 | /* Check if adapter has been closed */ | |
1769 | if(tp->ssb.Parm[0] & ADAPTER_CLOSED) | |
1770 | { | |
1771 | printk(KERN_INFO "%s: Adapter closed (Reopening)," | |
1772 | "CurrentRingStat %x\n", | |
1773 | dev->name, tp->CurrentRingStatus); | |
1774 | tp->AdapterOpenFlag = 0; | |
1775 | tms380tr_open_adapter(dev); | |
1776 | } | |
1777 | ||
1778 | return; | |
1779 | } | |
1780 | ||
1781 | /* | |
1782 | * Issued if adapter has encountered an unrecoverable hardware | |
1783 | * or software error. | |
1784 | */ | |
1785 | static void tms380tr_chk_irq(struct net_device *dev) | |
1786 | { | |
1787 | int i; | |
1788 | unsigned short AdapterCheckBlock[4]; | |
1789 | struct net_local *tp = netdev_priv(dev); | |
1790 | ||
1791 | tp->AdapterOpenFlag = 0; /* Adapter closed now */ | |
1792 | ||
1793 | /* Page number of adapter memory */ | |
1794 | SIFWRITEW(0x0001, SIFADX); | |
1795 | /* Address offset */ | |
1796 | SIFWRITEW(CHECKADDR, SIFADR); | |
1797 | ||
1798 | /* Reading 8 byte adapter check block. */ | |
1799 | for(i = 0; i < 4; i++) | |
1800 | AdapterCheckBlock[i] = SIFREADW(SIFINC); | |
1801 | ||
1802 | if(tms380tr_debug > 3) | |
1803 | { | |
1804 | printk(KERN_DEBUG "%s: AdapterCheckBlock: ", dev->name); | |
1805 | for (i = 0; i < 4; i++) | |
1806 | printk("%04X", AdapterCheckBlock[i]); | |
1807 | printk("\n"); | |
1808 | } | |
1809 | ||
1810 | switch(AdapterCheckBlock[0]) | |
1811 | { | |
1812 | case DIO_PARITY: | |
1813 | printk(KERN_INFO "%s: DIO parity error\n", dev->name); | |
1814 | break; | |
1815 | ||
1816 | case DMA_READ_ABORT: | |
1817 | printk(KERN_INFO "%s DMA read operation aborted:\n", | |
1818 | dev->name); | |
1819 | switch (AdapterCheckBlock[1]) | |
1820 | { | |
1821 | case 0: | |
1822 | printk(KERN_INFO "Timeout\n"); | |
1823 | printk(KERN_INFO "Address: %04X %04X\n", | |
1824 | AdapterCheckBlock[2], | |
1825 | AdapterCheckBlock[3]); | |
1826 | break; | |
1827 | ||
1828 | case 1: | |
1829 | printk(KERN_INFO "Parity error\n"); | |
1830 | printk(KERN_INFO "Address: %04X %04X\n", | |
1831 | AdapterCheckBlock[2], | |
1832 | AdapterCheckBlock[3]); | |
1833 | break; | |
1834 | ||
1835 | case 2: | |
1836 | printk(KERN_INFO "Bus error\n"); | |
1837 | printk(KERN_INFO "Address: %04X %04X\n", | |
1838 | AdapterCheckBlock[2], | |
1839 | AdapterCheckBlock[3]); | |
1840 | break; | |
1841 | ||
1842 | default: | |
1843 | printk(KERN_INFO "Unknown error.\n"); | |
1844 | break; | |
1845 | } | |
1846 | break; | |
1847 | ||
1848 | case DMA_WRITE_ABORT: | |
1849 | printk(KERN_INFO "%s: DMA write operation aborted: \n", | |
1850 | dev->name); | |
1851 | switch (AdapterCheckBlock[1]) | |
1852 | { | |
1853 | case 0: | |
1854 | printk(KERN_INFO "Timeout\n"); | |
1855 | printk(KERN_INFO "Address: %04X %04X\n", | |
1856 | AdapterCheckBlock[2], | |
1857 | AdapterCheckBlock[3]); | |
1858 | break; | |
1859 | ||
1860 | case 1: | |
1861 | printk(KERN_INFO "Parity error\n"); | |
1862 | printk(KERN_INFO "Address: %04X %04X\n", | |
1863 | AdapterCheckBlock[2], | |
1864 | AdapterCheckBlock[3]); | |
1865 | break; | |
1866 | ||
1867 | case 2: | |
1868 | printk(KERN_INFO "Bus error\n"); | |
1869 | printk(KERN_INFO "Address: %04X %04X\n", | |
1870 | AdapterCheckBlock[2], | |
1871 | AdapterCheckBlock[3]); | |
1872 | break; | |
1873 | ||
1874 | default: | |
1875 | printk(KERN_INFO "Unknown error.\n"); | |
1876 | break; | |
1877 | } | |
1878 | break; | |
1879 | ||
1880 | case ILLEGAL_OP_CODE: | |
1881 | printk(KERN_INFO "%s: Illegal operation code in firmware\n", | |
1882 | dev->name); | |
1883 | /* Parm[0-3]: adapter internal register R13-R15 */ | |
1884 | break; | |
1885 | ||
1886 | case PARITY_ERRORS: | |
1887 | printk(KERN_INFO "%s: Adapter internal bus parity error\n", | |
1888 | dev->name); | |
1889 | /* Parm[0-3]: adapter internal register R13-R15 */ | |
1890 | break; | |
1891 | ||
1892 | case RAM_DATA_ERROR: | |
1893 | printk(KERN_INFO "%s: RAM data error\n", dev->name); | |
1894 | /* Parm[0-1]: MSW/LSW address of RAM location. */ | |
1895 | break; | |
1896 | ||
1897 | case RAM_PARITY_ERROR: | |
1898 | printk(KERN_INFO "%s: RAM parity error\n", dev->name); | |
1899 | /* Parm[0-1]: MSW/LSW address of RAM location. */ | |
1900 | break; | |
1901 | ||
1902 | case RING_UNDERRUN: | |
1903 | printk(KERN_INFO "%s: Internal DMA underrun detected\n", | |
1904 | dev->name); | |
1905 | break; | |
1906 | ||
1907 | case INVALID_IRQ: | |
1908 | printk(KERN_INFO "%s: Unrecognized interrupt detected\n", | |
1909 | dev->name); | |
1910 | /* Parm[0-3]: adapter internal register R13-R15 */ | |
1911 | break; | |
1912 | ||
1913 | case INVALID_ERROR_IRQ: | |
1914 | printk(KERN_INFO "%s: Unrecognized error interrupt detected\n", | |
1915 | dev->name); | |
1916 | /* Parm[0-3]: adapter internal register R13-R15 */ | |
1917 | break; | |
1918 | ||
1919 | case INVALID_XOP: | |
1920 | printk(KERN_INFO "%s: Unrecognized XOP request detected\n", | |
1921 | dev->name); | |
1922 | /* Parm[0-3]: adapter internal register R13-R15 */ | |
1923 | break; | |
1924 | ||
1925 | default: | |
1926 | printk(KERN_INFO "%s: Unknown status", dev->name); | |
1927 | break; | |
1928 | } | |
1929 | ||
1930 | if(tms380tr_chipset_init(dev) == 1) | |
1931 | { | |
1932 | /* Restart of firmware successful */ | |
1933 | tp->AdapterOpenFlag = 1; | |
1934 | } | |
1935 | ||
1936 | return; | |
1937 | } | |
1938 | ||
1939 | /* | |
1940 | * Internal adapter pointer to RAM data are copied from adapter into | |
1941 | * host system. | |
1942 | */ | |
1943 | static int tms380tr_read_ptr(struct net_device *dev) | |
1944 | { | |
1945 | struct net_local *tp = netdev_priv(dev); | |
1946 | unsigned short adapterram; | |
1947 | ||
1948 | tms380tr_read_ram(dev, (unsigned char *)&tp->intptrs.BurnedInAddrPtr, | |
1949 | ADAPTER_INT_PTRS, 16); | |
1950 | tms380tr_read_ram(dev, (unsigned char *)&adapterram, | |
1951 | cpu_to_be16((unsigned short)tp->intptrs.AdapterRAMPtr), 2); | |
1952 | return be16_to_cpu(adapterram); | |
1953 | } | |
1954 | ||
1955 | /* | |
1956 | * Reads a number of bytes from adapter to system memory. | |
1957 | */ | |
1958 | static void tms380tr_read_ram(struct net_device *dev, unsigned char *Data, | |
1959 | unsigned short Address, int Length) | |
1960 | { | |
1961 | int i; | |
1962 | unsigned short old_sifadx, old_sifadr, InWord; | |
1963 | ||
1964 | /* Save the current values */ | |
1965 | old_sifadx = SIFREADW(SIFADX); | |
1966 | old_sifadr = SIFREADW(SIFADR); | |
1967 | ||
1968 | /* Page number of adapter memory */ | |
1969 | SIFWRITEW(0x0001, SIFADX); | |
1970 | /* Address offset in adapter RAM */ | |
1971 | SIFWRITEW(Address, SIFADR); | |
1972 | ||
1973 | /* Copy len byte from adapter memory to system data area. */ | |
1974 | i = 0; | |
1975 | for(;;) | |
1976 | { | |
1977 | InWord = SIFREADW(SIFINC); | |
1978 | ||
1979 | *(Data + i) = HIBYTE(InWord); /* Write first byte */ | |
1980 | if(++i == Length) /* All is done break */ | |
1981 | break; | |
1982 | ||
1983 | *(Data + i) = LOBYTE(InWord); /* Write second byte */ | |
1984 | if (++i == Length) /* All is done break */ | |
1985 | break; | |
1986 | } | |
1987 | ||
1988 | /* Restore original values */ | |
1989 | SIFWRITEW(old_sifadx, SIFADX); | |
1990 | SIFWRITEW(old_sifadr, SIFADR); | |
1991 | ||
1992 | return; | |
1993 | } | |
1994 | ||
1995 | /* | |
1996 | * Cancel all queued packets in the transmission queue. | |
1997 | */ | |
1998 | static void tms380tr_cancel_tx_queue(struct net_local* tp) | |
1999 | { | |
2000 | TPL *tpl; | |
2001 | ||
2002 | /* | |
2003 | * NOTE: There must not be an active TRANSMIT command pending, when | |
2004 | * this function is called. | |
2005 | */ | |
2006 | if(tp->TransmitCommandActive) | |
2007 | return; | |
2008 | ||
2009 | for(;;) | |
2010 | { | |
2011 | tpl = tp->TplBusy; | |
2012 | if(!tpl->BusyFlag) | |
2013 | break; | |
2014 | /* "Remove" TPL from busy list. */ | |
2015 | tp->TplBusy = tpl->NextTPLPtr; | |
2016 | tms380tr_write_tpl_status(tpl, 0); /* Clear VALID bit */ | |
2017 | tpl->BusyFlag = 0; /* "free" TPL */ | |
2018 | ||
2019 | printk(KERN_INFO "Cancel tx (%08lXh).\n", (unsigned long)tpl); | |
2020 | if (tpl->DMABuff) | |
504ff16c | 2021 | dma_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, DMA_TO_DEVICE); |
1da177e4 LT |
2022 | dev_kfree_skb_any(tpl->Skb); |
2023 | } | |
2024 | ||
2025 | return; | |
2026 | } | |
2027 | ||
2028 | /* | |
2029 | * This function is called whenever a transmit interrupt is generated by the | |
2030 | * adapter. For a command complete interrupt, it is checked if we have to | |
2031 | * issue a new transmit command or not. | |
2032 | */ | |
2033 | static void tms380tr_tx_status_irq(struct net_device *dev) | |
2034 | { | |
2035 | struct net_local *tp = netdev_priv(dev); | |
2036 | unsigned char HighByte, HighAc, LowAc; | |
2037 | TPL *tpl; | |
2038 | ||
2039 | /* NOTE: At this point the SSB from TRANSMIT STATUS is no longer | |
2040 | * available, because the CLEAR SSB command has already been issued. | |
2041 | * | |
2042 | * Process all complete transmissions. | |
2043 | */ | |
2044 | ||
2045 | for(;;) | |
2046 | { | |
2047 | tpl = tp->TplBusy; | |
2048 | if(!tpl->BusyFlag || (tpl->Status | |
2049 | & (TX_VALID | TX_FRAME_COMPLETE)) | |
2050 | != TX_FRAME_COMPLETE) | |
2051 | { | |
2052 | break; | |
2053 | } | |
2054 | ||
2055 | /* "Remove" TPL from busy list. */ | |
2056 | tp->TplBusy = tpl->NextTPLPtr ; | |
2057 | ||
2058 | /* Check the transmit status field only for directed frames*/ | |
2059 | if(DIRECTED_FRAME(tpl) && (tpl->Status & TX_ERROR) == 0) | |
2060 | { | |
2061 | HighByte = GET_TRANSMIT_STATUS_HIGH_BYTE(tpl->Status); | |
2062 | HighAc = GET_FRAME_STATUS_HIGH_AC(HighByte); | |
2063 | LowAc = GET_FRAME_STATUS_LOW_AC(HighByte); | |
2064 | ||
2065 | if((HighAc != LowAc) || (HighAc == AC_NOT_RECOGNIZED)) | |
2066 | { | |
2067 | printk(KERN_DEBUG "%s: (DA=%08lX not recognized)\n", | |
2068 | dev->name, | |
2069 | *(unsigned long *)&tpl->MData[2+2]); | |
2070 | } | |
2071 | else | |
2072 | { | |
2073 | if(tms380tr_debug > 3) | |
2074 | printk(KERN_DEBUG "%s: Directed frame tx'd\n", | |
2075 | dev->name); | |
2076 | } | |
2077 | } | |
2078 | else | |
2079 | { | |
2080 | if(!DIRECTED_FRAME(tpl)) | |
2081 | { | |
2082 | if(tms380tr_debug > 3) | |
2083 | printk(KERN_DEBUG "%s: Broadcast frame tx'd\n", | |
2084 | dev->name); | |
2085 | } | |
2086 | } | |
2087 | ||
2088 | tp->MacStat.tx_packets++; | |
2089 | if (tpl->DMABuff) | |
504ff16c | 2090 | dma_unmap_single(tp->pdev, tpl->DMABuff, tpl->Skb->len, DMA_TO_DEVICE); |
1da177e4 LT |
2091 | dev_kfree_skb_irq(tpl->Skb); |
2092 | tpl->BusyFlag = 0; /* "free" TPL */ | |
2093 | } | |
2094 | ||
2095 | if(!tp->TplFree->NextTPLPtr->BusyFlag) | |
2096 | netif_wake_queue(dev); | |
2097 | return; | |
2098 | } | |
2099 | ||
2100 | /* | |
2101 | * Called if a frame receive interrupt is generated by the adapter. | |
2102 | * Check if the frame is valid and indicate it to system. | |
2103 | */ | |
2104 | static void tms380tr_rcv_status_irq(struct net_device *dev) | |
2105 | { | |
2106 | struct net_local *tp = netdev_priv(dev); | |
2107 | unsigned char *ReceiveDataPtr; | |
2108 | struct sk_buff *skb; | |
2109 | unsigned int Length, Length2; | |
2110 | RPL *rpl; | |
2111 | RPL *SaveHead; | |
2112 | dma_addr_t dmabuf; | |
2113 | ||
2114 | /* NOTE: At this point the SSB from RECEIVE STATUS is no longer | |
2115 | * available, because the CLEAR SSB command has already been issued. | |
2116 | * | |
2117 | * Process all complete receives. | |
2118 | */ | |
2119 | ||
2120 | for(;;) | |
2121 | { | |
2122 | rpl = tp->RplHead; | |
2123 | if(rpl->Status & RX_VALID) | |
2124 | break; /* RPL still in use by adapter */ | |
2125 | ||
2126 | /* Forward RPLHead pointer to next list. */ | |
2127 | SaveHead = tp->RplHead; | |
2128 | tp->RplHead = rpl->NextRPLPtr; | |
2129 | ||
2130 | /* Get the frame size (Byte swap for Intel). | |
2131 | * Do this early (see workaround comment below) | |
2132 | */ | |
2929e770 | 2133 | Length = be16_to_cpu(rpl->FrameSize); |
1da177e4 LT |
2134 | |
2135 | /* Check if the Frame_Start, Frame_End and | |
2136 | * Frame_Complete bits are set. | |
2137 | */ | |
2138 | if((rpl->Status & VALID_SINGLE_BUFFER_FRAME) | |
2139 | == VALID_SINGLE_BUFFER_FRAME) | |
2140 | { | |
2141 | ReceiveDataPtr = rpl->MData; | |
2142 | ||
2143 | /* Workaround for delayed write of FrameSize on ISA | |
2144 | * (FrameSize is false but valid-bit is reset) | |
2145 | * Frame size is set to zero when the RPL is freed. | |
2146 | * Length2 is there because there have also been | |
2147 | * cases where the FrameSize was partially written | |
2148 | */ | |
2929e770 | 2149 | Length2 = be16_to_cpu(rpl->FrameSize); |
1da177e4 LT |
2150 | |
2151 | if(Length == 0 || Length != Length2) | |
2152 | { | |
2153 | tp->RplHead = SaveHead; | |
2154 | break; /* Return to tms380tr_interrupt */ | |
2155 | } | |
2156 | tms380tr_update_rcv_stats(tp,ReceiveDataPtr,Length); | |
2157 | ||
2158 | if(tms380tr_debug > 3) | |
2159 | printk(KERN_DEBUG "%s: Packet Length %04X (%d)\n", | |
2160 | dev->name, Length, Length); | |
2161 | ||
2162 | /* Indicate the received frame to system the | |
2163 | * adapter does the Source-Routing padding for | |
2164 | * us. See: OpenOptions in tms380tr_init_opb() | |
2165 | */ | |
2166 | skb = rpl->Skb; | |
2167 | if(rpl->SkbStat == SKB_UNAVAILABLE) | |
2168 | { | |
2169 | /* Try again to allocate skb */ | |
2170 | skb = dev_alloc_skb(tp->MaxPacketSize); | |
2171 | if(skb == NULL) | |
2172 | { | |
2173 | /* Update Stats ?? */ | |
2174 | } | |
2175 | else | |
2176 | { | |
1da177e4 LT |
2177 | skb_put(skb, tp->MaxPacketSize); |
2178 | rpl->SkbStat = SKB_DATA_COPY; | |
2179 | ReceiveDataPtr = rpl->MData; | |
2180 | } | |
2181 | } | |
2182 | ||
8e95a202 JP |
2183 | if(skb && (rpl->SkbStat == SKB_DATA_COPY || |
2184 | rpl->SkbStat == SKB_DMA_DIRECT)) | |
1da177e4 LT |
2185 | { |
2186 | if(rpl->SkbStat == SKB_DATA_COPY) | |
27d7ff46 ACM |
2187 | skb_copy_to_linear_data(skb, ReceiveDataPtr, |
2188 | Length); | |
1da177e4 LT |
2189 | |
2190 | /* Deliver frame to system */ | |
2191 | rpl->Skb = NULL; | |
2192 | skb_trim(skb,Length); | |
2193 | skb->protocol = tr_type_trans(skb,dev); | |
2194 | netif_rx(skb); | |
1da177e4 LT |
2195 | } |
2196 | } | |
2197 | else /* Invalid frame */ | |
2198 | { | |
2199 | if(rpl->Skb != NULL) | |
2200 | dev_kfree_skb_irq(rpl->Skb); | |
2201 | ||
2202 | /* Skip list. */ | |
2203 | if(rpl->Status & RX_START_FRAME) | |
2204 | /* Frame start bit is set -> overflow. */ | |
2205 | tp->MacStat.rx_errors++; | |
2206 | } | |
2207 | if (rpl->DMABuff) | |
504ff16c | 2208 | dma_unmap_single(tp->pdev, rpl->DMABuff, tp->MaxPacketSize, DMA_TO_DEVICE); |
1da177e4 LT |
2209 | rpl->DMABuff = 0; |
2210 | ||
2211 | /* Allocate new skb for rpl */ | |
2212 | rpl->Skb = dev_alloc_skb(tp->MaxPacketSize); | |
2213 | /* skb == NULL ? then use local buffer */ | |
2214 | if(rpl->Skb == NULL) | |
2215 | { | |
2216 | rpl->SkbStat = SKB_UNAVAILABLE; | |
2217 | rpl->FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[rpl->RPLIndex] - (char *)tp) + tp->dmabuffer); | |
2218 | rpl->MData = tp->LocalRxBuffers[rpl->RPLIndex]; | |
2219 | } | |
2220 | else /* skb != NULL */ | |
2221 | { | |
2222 | rpl->Skb->dev = dev; | |
2223 | skb_put(rpl->Skb, tp->MaxPacketSize); | |
2224 | ||
2225 | /* Data unreachable for DMA ? then use local buffer */ | |
504ff16c | 2226 | dmabuf = dma_map_single(tp->pdev, rpl->Skb->data, tp->MaxPacketSize, DMA_FROM_DEVICE); |
1da177e4 LT |
2227 | if(tp->dmalimit && (dmabuf + tp->MaxPacketSize > tp->dmalimit)) |
2228 | { | |
2229 | rpl->SkbStat = SKB_DATA_COPY; | |
2230 | rpl->FragList[0].DataAddr = htonl(((char *)tp->LocalRxBuffers[rpl->RPLIndex] - (char *)tp) + tp->dmabuffer); | |
2231 | rpl->MData = tp->LocalRxBuffers[rpl->RPLIndex]; | |
2232 | } | |
2233 | else | |
2234 | { | |
2235 | /* DMA directly in skb->data */ | |
2236 | rpl->SkbStat = SKB_DMA_DIRECT; | |
2237 | rpl->FragList[0].DataAddr = htonl(dmabuf); | |
2238 | rpl->MData = rpl->Skb->data; | |
2239 | rpl->DMABuff = dmabuf; | |
2240 | } | |
2241 | } | |
2242 | ||
2243 | rpl->FragList[0].DataCount = cpu_to_be16((unsigned short)tp->MaxPacketSize); | |
2244 | rpl->FrameSize = 0; | |
2245 | ||
2246 | /* Pass the last RPL back to the adapter */ | |
2247 | tp->RplTail->FrameSize = 0; | |
2248 | ||
2249 | /* Reset the CSTAT field in the list. */ | |
2250 | tms380tr_write_rpl_status(tp->RplTail, RX_VALID | RX_FRAME_IRQ); | |
2251 | ||
2252 | /* Current RPL becomes last one in list. */ | |
2253 | tp->RplTail = tp->RplTail->NextRPLPtr; | |
2254 | ||
2255 | /* Inform adapter about RPL valid. */ | |
2256 | tms380tr_exec_sifcmd(dev, CMD_RX_VALID); | |
2257 | } | |
2258 | ||
2259 | return; | |
2260 | } | |
2261 | ||
2262 | /* | |
2263 | * This function should be used whenever the status of any RPL must be | |
2264 | * modified by the driver, because the compiler may otherwise change the | |
2265 | * order of instructions such that writing the RPL status may be executed | |
3ad2f3fb | 2266 | * at an undesirable time. When this function is used, the status is |
1da177e4 LT |
2267 | * always written when the function is called. |
2268 | */ | |
2269 | static void tms380tr_write_rpl_status(RPL *rpl, unsigned int Status) | |
2270 | { | |
2271 | rpl->Status = Status; | |
2272 | ||
2273 | return; | |
2274 | } | |
2275 | ||
2276 | /* | |
2277 | * The function updates the statistic counters in mac->MacStat. | |
2278 | * It differtiates between directed and broadcast/multicast ( ==functional) | |
2279 | * frames. | |
2280 | */ | |
2281 | static void tms380tr_update_rcv_stats(struct net_local *tp, unsigned char DataPtr[], | |
2282 | unsigned int Length) | |
2283 | { | |
2284 | tp->MacStat.rx_packets++; | |
2285 | tp->MacStat.rx_bytes += Length; | |
2286 | ||
2287 | /* Test functional bit */ | |
2288 | if(DataPtr[2] & GROUP_BIT) | |
2289 | tp->MacStat.multicast++; | |
2290 | ||
2291 | return; | |
2292 | } | |
2293 | ||
2294 | static int tms380tr_set_mac_address(struct net_device *dev, void *addr) | |
2295 | { | |
2296 | struct net_local *tp = netdev_priv(dev); | |
2297 | struct sockaddr *saddr = addr; | |
2298 | ||
2299 | if (tp->AdapterOpenFlag || tp->AdapterVirtOpenFlag) { | |
2300 | printk(KERN_WARNING "%s: Cannot set MAC/LAA address while card is open\n", dev->name); | |
2301 | return -EIO; | |
2302 | } | |
2303 | memcpy(dev->dev_addr, saddr->sa_data, dev->addr_len); | |
2304 | return 0; | |
2305 | } | |
2306 | ||
2307 | #if TMS380TR_DEBUG > 0 | |
2308 | /* | |
2309 | * Dump Packet (data) | |
2310 | */ | |
2311 | static void tms380tr_dump(unsigned char *Data, int length) | |
2312 | { | |
2313 | int i, j; | |
2314 | ||
2315 | for (i = 0, j = 0; i < length / 8; i++, j += 8) | |
2316 | { | |
2317 | printk(KERN_DEBUG "%02x %02x %02x %02x %02x %02x %02x %02x\n", | |
2318 | Data[j+0],Data[j+1],Data[j+2],Data[j+3], | |
2319 | Data[j+4],Data[j+5],Data[j+6],Data[j+7]); | |
2320 | } | |
2321 | ||
2322 | return; | |
2323 | } | |
2324 | #endif | |
2325 | ||
2326 | void tmsdev_term(struct net_device *dev) | |
2327 | { | |
2328 | struct net_local *tp; | |
2329 | ||
2330 | tp = netdev_priv(dev); | |
504ff16c JF |
2331 | dma_unmap_single(tp->pdev, tp->dmabuffer, sizeof(struct net_local), |
2332 | DMA_BIDIRECTIONAL); | |
1da177e4 LT |
2333 | } |
2334 | ||
f1608f85 SH |
2335 | const struct net_device_ops tms380tr_netdev_ops = { |
2336 | .ndo_open = tms380tr_open, | |
2337 | .ndo_stop = tms380tr_close, | |
2338 | .ndo_start_xmit = tms380tr_send_packet, | |
2339 | .ndo_tx_timeout = tms380tr_timeout, | |
2340 | .ndo_get_stats = tms380tr_get_stats, | |
2341 | .ndo_set_multicast_list = tms380tr_set_multicast_list, | |
2342 | .ndo_set_mac_address = tms380tr_set_mac_address, | |
2343 | }; | |
2344 | EXPORT_SYMBOL(tms380tr_netdev_ops); | |
2345 | ||
84c3ea01 | 2346 | int tmsdev_init(struct net_device *dev, struct device *pdev) |
1da177e4 LT |
2347 | { |
2348 | struct net_local *tms_local; | |
2349 | ||
8f15ea42 | 2350 | memset(netdev_priv(dev), 0, sizeof(struct net_local)); |
1da177e4 LT |
2351 | tms_local = netdev_priv(dev); |
2352 | init_waitqueue_head(&tms_local->wait_for_tok_int); | |
84c3ea01 JF |
2353 | if (pdev->dma_mask) |
2354 | tms_local->dmalimit = *pdev->dma_mask; | |
2355 | else | |
2356 | return -ENOMEM; | |
1da177e4 | 2357 | tms_local->pdev = pdev; |
504ff16c JF |
2358 | tms_local->dmabuffer = dma_map_single(pdev, (void *)tms_local, |
2359 | sizeof(struct net_local), DMA_BIDIRECTIONAL); | |
84c3ea01 JF |
2360 | if (tms_local->dmabuffer + sizeof(struct net_local) > |
2361 | tms_local->dmalimit) | |
1da177e4 LT |
2362 | { |
2363 | printk(KERN_INFO "%s: Memory not accessible for DMA\n", | |
2364 | dev->name); | |
2365 | tmsdev_term(dev); | |
2366 | return -ENOMEM; | |
2367 | } | |
2368 | ||
f1608f85 | 2369 | dev->netdev_ops = &tms380tr_netdev_ops; |
1da177e4 | 2370 | dev->watchdog_timeo = HZ; |
1da177e4 LT |
2371 | |
2372 | return 0; | |
2373 | } | |
2374 | ||
1da177e4 LT |
2375 | EXPORT_SYMBOL(tms380tr_open); |
2376 | EXPORT_SYMBOL(tms380tr_close); | |
2377 | EXPORT_SYMBOL(tms380tr_interrupt); | |
2378 | EXPORT_SYMBOL(tmsdev_init); | |
2379 | EXPORT_SYMBOL(tmsdev_term); | |
2380 | EXPORT_SYMBOL(tms380tr_wait); | |
2381 | ||
504ff16c JF |
2382 | #ifdef MODULE |
2383 | ||
de70b4c8 | 2384 | static struct module *TMS380_module = NULL; |
1da177e4 LT |
2385 | |
2386 | int init_module(void) | |
2387 | { | |
2388 | printk(KERN_DEBUG "%s", version); | |
2389 | ||
2390 | TMS380_module = &__this_module; | |
2391 | return 0; | |
2392 | } | |
2393 | ||
2394 | void cleanup_module(void) | |
2395 | { | |
2396 | TMS380_module = NULL; | |
2397 | } | |
2398 | #endif | |
2399 | ||
2400 | MODULE_LICENSE("GPL"); | |
2401 |