File: /usr/src/linux/drivers/net/skfp/skfddi.c
1 /*
2 * File Name:
3 * skfddi.c
4 *
5 * Copyright Information:
6 * Copyright SysKonnect 1998,1999.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * The information in this file is provided "AS IS" without warranty.
14 *
15 * Abstract:
16 * A Linux device driver supporting the SysKonnect FDDI PCI controller
17 * familie.
18 *
19 * Maintainers:
20 * CG Christoph Goos (cgoos@syskonnect.de)
21 *
22 * Contributors:
23 * DM David S. Miller
24 *
25 * Address all question to:
26 * linux@syskonnect.de
27 *
28 * The technical manual for the adapters is available from SysKonnect's
29 * web pages: www.syskonnect.com
30 * Goto "Support" and search Knowledge Base for "manual".
31 *
32 * Driver Architecture:
33 * The driver architecture is based on the DEC FDDI driver by
34 * Lawrence V. Stefani and several ethernet drivers.
35 * I also used an existing Windows NT miniport driver.
36 * All hardware dependant fuctions are handled by the SysKonnect
37 * Hardware Module.
38 * The only headerfiles that are directly related to this source
39 * are skfddi.c, h/types.h, h/osdef1st.h, h/targetos.h.
40 * The others belong to the SysKonnect FDDI Hardware Module and
41 * should better not be changed.
42 * NOTE:
43 * Compiling this driver produces some warnings, but I did not fix
44 * this, because the Hardware Module source is used for different
45 * drivers, and fixing it for Linux might bring problems on other
46 * projects. To keep the source common for all those drivers (and
47 * thus simplify fixes to it), please do not clean it up!
48 *
49 * Modification History:
50 * Date Name Description
51 * 02-Mar-98 CG Created.
52 *
53 * 10-Mar-99 CG Support for 2.2.x added.
54 * 25-Mar-99 CG Corrected IRQ routing for SMP (APIC)
55 * 26-Oct-99 CG Fixed compilation error on 2.2.13
56 * 12-Nov-99 CG Source code release
57 * 22-Nov-99 CG Included in kernel source.
58 * 07-May-00 DM 64 bit fixes, new dma interface
59 *
60 * Compilation options (-Dxxx):
61 * DRIVERDEBUG print lots of messages to log file
62 * DUMPPACKETS print received/transmitted packets to logfile
63 *
64 * Tested cpu architectures:
65 * - i386
66 * - sparc64
67 */
68
69 /* Version information string - should be updated prior to */
70 /* each new release!!! */
71 #define VERSION "2.06"
72
73 static const char *boot_msg =
74 "SysKonnect FDDI PCI Adapter driver v" VERSION " for\n"
75 " SK-55xx/SK-58xx adapters (SK-NET FDDI-FP/UP/LP)";
76
77 /* Include files */
78
79 #include <linux/module.h>
80
81 #include <linux/kernel.h>
82 #include <linux/sched.h>
83 #include <linux/string.h>
84 #include <linux/ptrace.h>
85 #include <linux/errno.h>
86 #include <linux/ioport.h>
87 #include <linux/slab.h>
88 #include <linux/interrupt.h>
89 #include <linux/pci.h>
90 #include <linux/delay.h>
91 #include <asm/byteorder.h>
92 #include <asm/bitops.h>
93 #include <asm/io.h>
94 #include <asm/uaccess.h>
95 #include <linux/ctype.h> // isdigit
96
97 #include <linux/netdevice.h>
98 #include <linux/fddidevice.h>
99 #include <linux/skbuff.h>
100
101 #include "h/types.h"
102 #undef ADDR // undo Linux definition
103 #include "h/skfbi.h"
104 #include "h/fddi.h"
105 #include "h/smc.h"
106 #include "h/smtstate.h"
107
108
109 // Define global routines
110 int skfp_probe(struct net_device *dev);
111
112
113 // Define module-wide (static) routines
114 static struct net_device *alloc_device(struct net_device *dev, u_long iobase);
115 static struct net_device *insert_device(struct net_device *dev,
116 int (*init) (struct net_device *));
117 static int fddi_dev_index(unsigned char *s);
118 static void init_dev(struct net_device *dev, u_long iobase);
119 static void link_modules(struct net_device *dev, struct net_device *tmp);
120 static int skfp_driver_init(struct net_device *dev);
121 static int skfp_open(struct net_device *dev);
122 static int skfp_close(struct net_device *dev);
123 static void skfp_interrupt(int irq, void *dev_id, struct pt_regs *regs);
124 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev);
125 static void skfp_ctl_set_multicast_list(struct net_device *dev);
126 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev);
127 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr);
128 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
129 static int skfp_send_pkt(struct sk_buff *skb, struct net_device *dev);
130 static void send_queued_packets(struct s_smc *smc);
131 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr);
132 static void ResetAdapter(struct s_smc *smc);
133
134
135 // Functions needed by the hardware module
136 void *mac_drv_get_space(struct s_smc *smc, u_int size);
137 void *mac_drv_get_desc_mem(struct s_smc *smc, u_int size);
138 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt);
139 unsigned long dma_master(struct s_smc *smc, void *virt, int len, int flag);
140 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr,
141 int flag);
142 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd);
143 void llc_restart_tx(struct s_smc *smc);
144 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
145 int frag_count, int len);
146 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
147 int frag_count);
148 void mac_drv_fill_rxd(struct s_smc *smc);
149 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
150 int frag_count);
151 int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
152 int la_len);
153 void smt_timer_poll(struct s_smc *smc);
154 void ring_status_indication(struct s_smc *smc, u_long status);
155 unsigned long smt_get_time(void);
156 void smt_stat_counter(struct s_smc *smc, int stat);
157 void cfm_state_change(struct s_smc *smc, int c_state);
158 void ecm_state_change(struct s_smc *smc, int e_state);
159 void pcm_state_change(struct s_smc *smc, int plc, int p_state);
160 void rmt_state_change(struct s_smc *smc, int r_state);
161 void drv_reset_indication(struct s_smc *smc);
162 void dump_data(unsigned char *Data, int length);
163
164
165 // External functions from the hardware module
166 extern u_int mac_drv_check_space();
167 extern void read_address(struct s_smc *smc, u_char * mac_addr);
168 extern void card_stop(struct s_smc *smc);
169 extern int mac_drv_init(struct s_smc *smc);
170 extern void hwm_tx_frag(struct s_smc *smc, char far * virt, u_long phys,
171 int len, int frame_status);
172 extern int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count,
173 int frame_len, int frame_status);
174 extern int init_smt(struct s_smc *smc, u_char * mac_addr);
175 extern void fddi_isr(struct s_smc *smc);
176 extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
177 int len, int frame_status);
178 extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
179 extern void mac_drv_clear_tx_queue(struct s_smc *smc);
180 extern void mac_drv_clear_rx_queue(struct s_smc *smc);
181 extern void mac_clear_multicast(struct s_smc *smc);
182 extern void enable_tx_irq(struct s_smc *smc, u_short queue);
183 extern void mac_drv_clear_txd(struct s_smc *smc);
184
185 static struct pci_device_id skfddi_pci_tbl[] __initdata = {
186 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
187 { } /* Terminating entry */
188 };
189 MODULE_DEVICE_TABLE(pci, skfddi_pci_tbl);
190
191 // Define module-wide (static) variables
192
193 static int num_boards; /* total number of adapters configured */
194 static int num_fddi;
195 static int autoprobed;
196
197 #ifdef MODULE
198 int init_module(void);
199 void cleanup_module(void);
200 static struct net_device *unlink_modules(struct net_device *p);
201 static int loading_module = 1;
202 #else
203 static int loading_module;
204 #endif // MODULE
205
206 #ifdef DRIVERDEBUG
207 #define PRINTK(s, args...) printk(s, ## args)
208 #else
209 #define PRINTK(s, args...)
210 #endif // DRIVERDEBUG
211
212 #define PRIV(dev) (&(((struct s_smc *)dev->priv)->os))
213
214 /*
215 * ==============
216 * = skfp_probe =
217 * ==============
218 *
219 * Overview:
220 * Probes for supported FDDI PCI controllers
221 *
222 * Returns:
223 * Condition code
224 *
225 * Arguments:
226 * dev - pointer to device information
227 *
228 * Functional Description:
229 * This routine is called by the OS for each FDDI device name (fddi0,
230 * fddi1,...,fddi6, fddi7) specified in drivers/net/Space.c.
231 * If loaded as a module, it will detect and initialize all
232 * adapters the first time it is called.
233 *
234 * Let's say that skfp_probe() is getting called to initialize fddi0.
235 * Furthermore, let's say there are three supported controllers in the
236 * system. Before skfp_probe() leaves, devices fddi0, fddi1, and fddi2
237 * will be initialized and a global flag will be set to indicate that
238 * skfp_probe() has already been called.
239 *
240 * However...the OS doesn't know that we've already initialized
241 * devices fddi1 and fddi2 so skfp_probe() gets called again and again
242 * until it reaches the end of the device list for FDDI (presently,
243 * fddi7). It's important that the driver "pretend" to probe for
244 * devices fddi1 and fddi2 and return success. Devices fddi3
245 * through fddi7 will return failure since they weren't initialized.
246 *
247 * This algorithm seems to work for the time being. As other FDDI
248 * drivers are written for Linux, a more generic approach (perhaps
249 * similar to the Ethernet card approach) may need to be implemented.
250 *
251 * Return Codes:
252 * 0 - This device (fddi0, fddi1, etc) configured successfully
253 * -ENODEV - No devices present, or no SysKonnect FDDI PCI device
254 * present for this device name
255 *
256 *
257 * Side Effects:
258 * Device structures for FDDI adapters (fddi0, fddi1, etc) are
259 * initialized and the board resources are read and stored in
260 * the device structure.
261 */
262 int skfp_probe(struct net_device *dev)
263 {
264 int i; /* used in for loops */
265 struct pci_dev *pdev = NULL; /* PCI device structure */
266 #ifndef MEM_MAPPED_IO
267 u16 port; /* temporary I/O (port) address */
268 int port_len; /* length of port address range (in bytes) */
269 #else
270 unsigned long port;
271 #endif
272 u16 command; /* PCI Configuration space Command register val */
273 struct s_smc *smc; /* board pointer */
274 struct net_device *tmp = dev;
275 u8 first_dev_used = 0;
276 u16 SubSysId;
277
278 PRINTK(KERN_INFO "entering skfp_probe\n");
279
280 /*
281 * Verify whether we're going through skfp_probe() again
282 *
283 * If so, see if we're going through for a subsequent fddi device that
284 * we've already initialized. If we are, return success (0). If not,
285 * return failure (-ENODEV).
286 */
287
288 if (autoprobed) {
289 PRINTK(KERN_INFO "Already entered skfp_probe\n");
290 if (dev != NULL) {
291 if ((strncmp(dev->name, "fddi", 4) == 0) &&
292 (dev->base_addr != 0)) {
293 return (0);
294 }
295 return (-ENODEV);
296 }
297 }
298 autoprobed = 1; /* set global flag */
299
300 printk("%s\n", boot_msg);
301
302 /* Scan for Syskonnect FDDI PCI controllers */
303 if (!pci_present()) { /* is PCI BIOS even present? */
304 printk("no PCI BIOS present\n");
305 return (-ENODEV);
306 }
307 for (i = 0; i < SKFP_MAX_NUM_BOARDS; i++) { // scan for PCI cards
308 PRINTK(KERN_INFO "Check device %d\n", i);
309 if ((pdev=pci_find_device(PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP,
310 pdev)) == 0) {
311 break;
312 }
313 if (pci_enable_device(pdev))
314 continue;
315
316 #ifndef MEM_MAPPED_IO
317 /* Verify that I/O enable bit is set (PCI slot is enabled) */
318 pci_read_config_word(pdev, PCI_COMMAND, &command);
319 if ((command & PCI_COMMAND_IO) == 0) {
320 PRINTK("I/O enable bit not set!");
321 PRINTK(" Verify that slot is enabled\n");
322 continue;
323 }
324
325 /* Turn off memory mapped space and enable mastering */
326
327 PRINTK(KERN_INFO "Command Reg: %04x\n", command);
328 command |= PCI_COMMAND_MASTER;
329 command &= ~PCI_COMMAND_MEMORY;
330 pci_write_config_word(pdev, PCI_COMMAND, command);
331
332 /* Read I/O base address from PCI Configuration Space */
333
334 pci_read_config_word(pdev, PCI_BASE_ADDRESS_1, &port);
335 port &= PCI_BASE_ADDRESS_IO_MASK; // clear I/O bit (bit 0)
336
337 /* Verify port address range is not already being used */
338
339 port_len = FP_IO_LEN;
340 if (check_region(port, port_len) != 0) {
341 printk("I/O range allocated to adapter");
342 printk(" (0x%X-0x%X) is already being used!\n", port,
343 (port + port_len - 1));
344 continue;
345 }
346 #else
347 /* Verify that MEM enable bit is set (PCI slot is enabled) */
348 pci_read_config_word(pdev, PCI_COMMAND, &command);
349 if ((command & PCI_COMMAND_MEMORY) == 0) {
350 PRINTK("MEMORY-I/O enable bit not set!");
351 PRINTK(" Verify that slot is enabled\n");
352 continue;
353 }
354
355 /* Turn off IO mapped space and enable mastering */
356
357 PRINTK(KERN_INFO "Command Reg: %04x\n", command);
358 command |= PCI_COMMAND_MASTER;
359 command &= ~PCI_COMMAND_IO;
360 pci_write_config_word(pdev, PCI_COMMAND, command);
361
362 port = pci_resource_start(pdev, 0);
363
364 port = (unsigned long)ioremap(port, 0x4000);
365 if (!port){
366 printk("skfp: Unable to map MEMORY register, "
367 "FDDI adapter will be disabled.\n");
368 break;
369 }
370 #endif
371
372 if ((!loading_module) || first_dev_used) {
373 /* Allocate a device structure for this adapter */
374 tmp = alloc_device(dev, port);
375 }
376 first_dev_used = 1; // only significant first time
377
378 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &SubSysId);
379
380 if (tmp != NULL) {
381 if (loading_module)
382 link_modules(dev, tmp);
383 dev = tmp;
384 init_dev(dev, port);
385 dev->irq = pdev->irq;
386
387 /* Initialize board structure with bus-specific info */
388
389 smc = (struct s_smc *) dev->priv;
390 smc->os.dev = dev;
391 smc->os.bus_type = SK_BUS_TYPE_PCI;
392 smc->os.pdev = *pdev;
393 smc->os.QueueSkb = MAX_TX_QUEUE_LEN;
394 smc->os.MaxFrameSize = MAX_FRAME_SIZE;
395 smc->os.dev = dev;
396 smc->hw.slot = -1;
397 smc->os.ResetRequested = FALSE;
398 skb_queue_head_init(&smc->os.SendSkbQueue);
399
400 if (skfp_driver_init(dev) == 0) {
401 // only increment global board
402 // count on success
403 num_boards++;
404 request_region(dev->base_addr,
405 FP_IO_LEN, dev->name);
406 if ((SubSysId & 0xff00) == 0x5500 ||
407 (SubSysId & 0xff00) == 0x5800) {
408 printk("%s: SysKonnect FDDI PCI adapter"
409 " found (SK-%04X)\n", dev->name,
410 SubSysId);
411 } else {
412 printk("%s: FDDI PCI adapter found\n",
413 dev->name);
414 }
415 } else {
416 kfree(dev);
417 i = SKFP_MAX_NUM_BOARDS; // stop search
418
419 }
420
421 } // if (dev != NULL)
422
423 } // for SKFP_MAX_NUM_BOARDS
424
425 /*
426 * If we're at this point we're going through skfp_probe() for the
427 * first time. Return success (0) if we've initialized 1 or more
428 * boards. Otherwise, return failure (-ENODEV).
429 */
430
431 if (num_boards > 0)
432 return (0);
433 else {
434 printk("no SysKonnect FDDI adapter found\n");
435 return (-ENODEV);
436 }
437 } // skfp_probe
438
439
440 /************************
441 *
442 * Search the entire 'fddi' device list for a fixed probe. If a match isn't
443 * found then check for an autoprobe or unused device location. If they
444 * are not available then insert a new device structure at the end of
445 * the current list.
446 *
447 ************************/
448 static struct net_device *alloc_device(struct net_device *dev, u_long iobase)
449 {
450 struct net_device *adev = NULL;
451 int fixed = 0, new_dev = 0;
452
453 PRINTK(KERN_INFO "entering alloc_device\n");
454 if (!dev)
455 return dev;
456
457 num_fddi = fddi_dev_index(dev->name);
458 if (loading_module) {
459 num_fddi++;
460 dev = insert_device(dev, skfp_probe);
461 return dev;
462 }
463 while (1) {
464 if (((dev->base_addr == NO_ADDRESS) ||
465 (dev->base_addr == 0)) && !adev) {
466 adev = dev;
467 } else if ((dev->priv == NULL) && (dev->base_addr == iobase)) {
468 fixed = 1;
469 } else {
470 if (dev->next == NULL) {
471 new_dev = 1;
472 } else if (strncmp(dev->next->name, "fddi", 4) != 0) {
473 new_dev = 1;
474 }
475 }
476 if ((dev->next == NULL) || new_dev || fixed)
477 break;
478 dev = dev->next;
479 num_fddi++;
480 } // while (1)
481
482 if (adev && !fixed) {
483 dev = adev;
484 num_fddi = fddi_dev_index(dev->name);
485 new_dev = 0;
486 }
487 if (((dev->next == NULL) && ((dev->base_addr != NO_ADDRESS) &&
488 (dev->base_addr != 0)) && !fixed) ||
489 new_dev) {
490 num_fddi++; /* New device */
491 dev = insert_device(dev, skfp_probe);
492 }
493 if (dev) {
494 if (!dev->priv) {
495 /* Allocate space for private board structure */
496 dev->priv = (void *) kmalloc(sizeof(struct s_smc),
497 GFP_KERNEL);
498 if (dev->priv == NULL) {
499 printk("%s: Could not allocate memory for",
500 dev->name);
501 printk(" private board structure!\n");
502 return (NULL);
503 }
504 /* clear structure */
505 memset(dev->priv, 0, sizeof(struct s_smc));
506 }
507 }
508 return dev;
509 } // alloc_device
510
511
512
513 /************************
514 *
515 * Initialize device structure
516 *
517 ************************/
518 static void init_dev(struct net_device *dev, u_long iobase)
519 {
520 /* Initialize new device structure */
521
522 dev->rmem_end = 0; /* shared memory isn't used */
523 dev->rmem_start = 0; /* shared memory isn't used */
524 dev->mem_end = 0; /* shared memory isn't used */
525 dev->mem_start = 0; /* shared memory isn't used */
526 dev->base_addr = iobase; /* save port (I/O) base address */
527 dev->if_port = 0; /* not applicable to FDDI adapters */
528 dev->dma = 0; /* Bus Master DMA doesn't require channel */
529 dev->irq = 0;
530
531 netif_start_queue(dev);
532
533 dev->get_stats = &skfp_ctl_get_stats;
534 dev->open = &skfp_open;
535 dev->stop = &skfp_close;
536 dev->hard_start_xmit = &skfp_send_pkt;
537 dev->hard_header = NULL; /* set in fddi_setup() */
538 dev->rebuild_header = NULL; /* set in fddi_setup() */
539 dev->set_multicast_list = &skfp_ctl_set_multicast_list;
540 dev->set_mac_address = &skfp_ctl_set_mac_address;
541 dev->do_ioctl = &skfp_ioctl;
542 dev->set_config = NULL; /* not supported for now &&& */
543 dev->header_cache_update = NULL; /* not supported */
544 dev->change_mtu = NULL; /* set in fddi_setup() */
545
546 /* Initialize remaining device structure information */
547 fddi_setup(dev);
548 } // init_device
549
550
551 /************************
552 *
553 * If at end of fddi device list and can't use current entry, malloc
554 * one up. If memory could not be allocated, print an error message.
555 *
556 ************************/
557 static struct net_device *insert_device(struct net_device *dev,
558 int (*init) (struct net_device *))
559 {
560 struct net_device *new;
561 int len;
562
563 PRINTK(KERN_INFO "entering insert_device\n");
564 len = sizeof(struct net_device) + sizeof(struct s_smc);
565 new = (struct net_device *) kmalloc(len, GFP_KERNEL);
566 if (new == NULL) {
567 printk("fddi%d: Device not initialised, insufficient memory\n",
568 num_fddi);
569 return NULL;
570 } else {
571 memset((char *) new, 0, len);
572 new->priv = (struct s_smc *) (new + 1);
573 new->init = init; /* initialisation routine */
574 if (!loading_module) {
575 new->next = dev->next;
576 dev->next = new;
577 }
578 /* create new device name */
579 if (num_fddi > 999) {
580 sprintf(new->name, "fddi????");
581 } else {
582 sprintf(new->name, "fddi%d", num_fddi);
583 }
584 }
585 return new;
586 } // insert_device
587
588
589 /************************
590 *
591 * Get the number of a "fddiX" string
592 *
593 ************************/
594 static int fddi_dev_index(unsigned char *s)
595 {
596 int i = 0, j = 0;
597
598 for (; *s; s++) {
599 if (isdigit(*s)) {
600 j = 1;
601 i = (i * 10) + (*s - '0');
602 } else if (j)
603 break;
604 }
605 return i;
606 } // fddi_dev_index
607
608
609 /************************
610 *
611 * Used if loaded as module only. Link the device structures
612 * together. Needed to release them all at unload.
613 *
614 ************************/
615 static void link_modules(struct net_device *dev, struct net_device *tmp)
616 {
617 struct net_device *p = dev;
618
619 if (p) {
620 while (((struct s_smc *) (p->priv))->os.next_module) {
621 p = ((struct s_smc *) (p->priv))->os.next_module;
622 }
623
624 if (dev != tmp) {
625 ((struct s_smc *) (p->priv))->os.next_module = tmp;
626 } else {
627 ((struct s_smc *) (p->priv))->os.next_module = NULL;
628 }
629 }
630 return;
631 } // link_modules
632
633
634
635 /*
636 * ====================
637 * = skfp_driver_init =
638 * ====================
639 *
640 * Overview:
641 * Initializes remaining adapter board structure information
642 * and makes sure adapter is in a safe state prior to skfp_open().
643 *
644 * Returns:
645 * Condition code
646 *
647 * Arguments:
648 * dev - pointer to device information
649 *
650 * Functional Description:
651 * This function allocates additional resources such as the host memory
652 * blocks needed by the adapter.
653 * The adapter is also reset. The OS must call skfp_open() to open
654 * the adapter and bring it on-line.
655 *
656 * Return Codes:
657 * 0 - initialization succeeded
658 * -1 - initialization failed
659 */
660 static int skfp_driver_init(struct net_device *dev)
661 {
662 struct s_smc *smc = (struct s_smc *) dev->priv;
663 skfddi_priv *bp = PRIV(dev);
664 u8 val; /* used for I/O read/writes */
665
666 PRINTK(KERN_INFO "entering skfp_driver_init\n");
667
668 // set the io address in private structures
669 bp->base_addr = dev->base_addr;
670 smc->hw.iop = dev->base_addr;
671
672 // Get the interrupt level from the PCI Configuration Table
673 val = dev->irq;
674
675 smc->hw.irq = val;
676
677 spin_lock_init(&bp->DriverLock);
678
679 // Allocate invalid frame
680 bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA);
681 if (!bp->LocalRxBuffer) {
682 printk("could not allocate mem for ");
683 printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
684 goto fail;
685 }
686
687 // Determine the required size of the 'shared' memory area.
688 bp->SharedMemSize = mac_drv_check_space();
689 PRINTK(KERN_INFO "Memory for HWM: %ld\n", bp->SharedMemSize);
690 if (bp->SharedMemSize > 0) {
691 bp->SharedMemSize += 16; // for descriptor alignment
692
693 bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev,
694 bp->SharedMemSize,
695 &bp->SharedMemDMA);
696 if (!bp->SharedMemSize) {
697 printk("could not allocate mem for ");
698 printk("hardware module: %ld byte\n",
699 bp->SharedMemSize);
700 goto fail;
701 }
702 bp->SharedMemHeap = 0; // Nothing used yet.
703
704 } else {
705 bp->SharedMemAddr = NULL;
706 bp->SharedMemHeap = 0;
707 } // SharedMemSize > 0
708
709 memset(bp->SharedMemAddr, 0, bp->SharedMemSize);
710
711 card_stop(smc); // Reset adapter.
712
713 PRINTK(KERN_INFO "mac_drv_init()..\n");
714 if (mac_drv_init(smc) != 0) {
715 PRINTK(KERN_INFO "mac_drv_init() failed.\n");
716 goto fail;
717 }
718 read_address(smc, NULL);
719 PRINTK(KERN_INFO "HW-Addr: %02x %02x %02x %02x %02x %02x\n",
720 smc->hw.fddi_canon_addr.a[0],
721 smc->hw.fddi_canon_addr.a[1],
722 smc->hw.fddi_canon_addr.a[2],
723 smc->hw.fddi_canon_addr.a[3],
724 smc->hw.fddi_canon_addr.a[4],
725 smc->hw.fddi_canon_addr.a[5]);
726 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
727
728 smt_reset_defaults(smc, 0);
729
730 return (0);
731
732 fail:
733 if (bp->SharedMemAddr) {
734 pci_free_consistent(&bp->pdev,
735 bp->SharedMemSize,
736 bp->SharedMemAddr,
737 bp->SharedMemDMA);
738 bp->SharedMemAddr = NULL;
739 }
740 if (bp->LocalRxBuffer) {
741 pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE,
742 bp->LocalRxBuffer, bp->LocalRxBufferDMA);
743 bp->LocalRxBuffer = NULL;
744 }
745 return (-1);
746 } // skfp_driver_init
747
748
749 /*
750 * =============
751 * = skfp_open =
752 * =============
753 *
754 * Overview:
755 * Opens the adapter
756 *
757 * Returns:
758 * Condition code
759 *
760 * Arguments:
761 * dev - pointer to device information
762 *
763 * Functional Description:
764 * This function brings the adapter to an operational state.
765 *
766 * Return Codes:
767 * 0 - Adapter was successfully opened
768 * -EAGAIN - Could not register IRQ
769 */
770 static int skfp_open(struct net_device *dev)
771 {
772 struct s_smc *smc = (struct s_smc *) dev->priv;
773
774 PRINTK(KERN_INFO "entering skfp_open\n");
775 /* Register IRQ - support shared interrupts by passing device ptr */
776 if (request_irq(dev->irq, (void *) skfp_interrupt, SA_SHIRQ,
777 dev->name, dev)) {
778 printk("%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
779 return (-EAGAIN);
780 }
781 /*
782 * Set current address to factory MAC address
783 *
784 * Note: We've already done this step in skfp_driver_init.
785 * However, it's possible that a user has set a node
786 * address override, then closed and reopened the
787 * adapter. Unless we reset the device address field
788 * now, we'll continue to use the existing modified
789 * address.
790 */
791 read_address(smc, NULL);
792 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
793
794 init_smt(smc, NULL);
795 smt_online(smc, 1);
796 STI_FBI();
797
798 MOD_INC_USE_COUNT;
799
800 /* Clear local multicast address tables */
801 mac_clear_multicast(smc);
802
803 /* Disable promiscuous filter settings */
804 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
805
806 return (0);
807 } // skfp_open
808
809
810 /*
811 * ==============
812 * = skfp_close =
813 * ==============
814 *
815 * Overview:
816 * Closes the device/module.
817 *
818 * Returns:
819 * Condition code
820 *
821 * Arguments:
822 * dev - pointer to device information
823 *
824 * Functional Description:
825 * This routine closes the adapter and brings it to a safe state.
826 * The interrupt service routine is deregistered with the OS.
827 * The adapter can be opened again with another call to skfp_open().
828 *
829 * Return Codes:
830 * Always return 0.
831 *
832 * Assumptions:
833 * No further requests for this adapter are made after this routine is
834 * called. skfp_open() can be called to reset and reinitialize the
835 * adapter.
836 */
837 static int skfp_close(struct net_device *dev)
838 {
839 struct s_smc *smc = (struct s_smc *) dev->priv;
840 struct sk_buff *skb;
841 skfddi_priv *bp = PRIV(dev);
842
843 CLI_FBI();
844 smt_reset_defaults(smc, 1);
845 card_stop(smc);
846 mac_drv_clear_tx_queue(smc);
847 mac_drv_clear_rx_queue(smc);
848
849 netif_stop_queue(dev);
850 /* Deregister (free) IRQ */
851 free_irq(dev->irq, dev);
852
853 for (;;) {
854 skb = skb_dequeue(&bp->SendSkbQueue);
855 if (skb == NULL)
856 break;
857 bp->QueueSkb++;
858 dev_kfree_skb(skb);
859 }
860
861 MOD_DEC_USE_COUNT;
862
863 return (0);
864 } // skfp_close
865
866
867 /*
868 * ==================
869 * = skfp_interrupt =
870 * ==================
871 *
872 * Overview:
873 * Interrupt processing routine
874 *
875 * Returns:
876 * None
877 *
878 * Arguments:
879 * irq - interrupt vector
880 * dev_id - pointer to device information
881 * regs - pointer to registers structure
882 *
883 * Functional Description:
884 * This routine calls the interrupt processing routine for this adapter. It
885 * disables and reenables adapter interrupts, as appropriate. We can support
886 * shared interrupts since the incoming dev_id pointer provides our device
887 * structure context. All the real work is done in the hardware module.
888 *
889 * Return Codes:
890 * None
891 *
892 * Assumptions:
893 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
894 * on Intel-based systems) is done by the operating system outside this
895 * routine.
896 *
897 * System interrupts are enabled through this call.
898 *
899 * Side Effects:
900 * Interrupts are disabled, then reenabled at the adapter.
901 */
902
903 void skfp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
904 {
905 struct net_device *dev = (struct net_device *) dev_id;
906 struct s_smc *smc; /* private board structure pointer */
907 skfddi_priv *bp = PRIV(dev);
908
909
910 if (dev == NULL) {
911 printk("%s: irq %d for unknown device\n", dev->name, irq);
912 return;
913 }
914
915 smc = (struct s_smc *) dev->priv;
916
917 // IRQs enabled or disabled ?
918 if (inpd(ADDR(B0_IMSK)) == 0) {
919 // IRQs are disabled: must be shared interrupt
920 return;
921 }
922 // Note: At this point, IRQs are enabled.
923 if ((inpd(ISR_A) & smc->hw.is_imask) == 0) { // IRQ?
924 // Adapter did not issue an IRQ: must be shared interrupt
925 return;
926 }
927 CLI_FBI(); // Disable IRQs from our adapter.
928 spin_lock(&bp->DriverLock);
929
930 // Call interrupt handler in hardware module (HWM).
931 fddi_isr(smc);
932
933 if (smc->os.ResetRequested) {
934 ResetAdapter(smc);
935 smc->os.ResetRequested = FALSE;
936 }
937 spin_unlock(&bp->DriverLock);
938 STI_FBI(); // Enable IRQs from our adapter.
939
940 return;
941 } // skfp_interrupt
942
943
944 /*
945 * ======================
946 * = skfp_ctl_get_stats =
947 * ======================
948 *
949 * Overview:
950 * Get statistics for FDDI adapter
951 *
952 * Returns:
953 * Pointer to FDDI statistics structure
954 *
955 * Arguments:
956 * dev - pointer to device information
957 *
958 * Functional Description:
959 * Gets current MIB objects from adapter, then
960 * returns FDDI statistics structure as defined
961 * in if_fddi.h.
962 *
963 * Note: Since the FDDI statistics structure is
964 * still new and the device structure doesn't
965 * have an FDDI-specific get statistics handler,
966 * we'll return the FDDI statistics structure as
967 * a pointer to an Ethernet statistics structure.
968 * That way, at least the first part of the statistics
969 * structure can be decoded properly.
970 * We'll have to pay attention to this routine as the
971 * device structure becomes more mature and LAN media
972 * independent.
973 *
974 */
975 struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
976 {
977 struct s_smc *bp = (struct s_smc *) dev->priv;
978
979 /* Fill the bp->stats structure with driver-maintained counters */
980
981 bp->os.MacStat.port_bs_flag[0] = 0x1234;
982 bp->os.MacStat.port_bs_flag[1] = 0x5678;
983 // goos: need to fill out fddi statistic
984 #if 0
985 /* Get FDDI SMT MIB objects */
986
987 /* Fill the bp->stats structure with the SMT MIB object values */
988
989 memcpy(bp->stats.smt_station_id, &bp->cmd_rsp_virt->smt_mib_get.smt_station_id, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_station_id));
990 bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
991 bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
992 bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
993 memcpy(bp->stats.smt_user_data, &bp->cmd_rsp_virt->smt_mib_get.smt_user_data, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_user_data));
994 bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
995 bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
996 bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
997 bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
998 bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
999 bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
1000 bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
1001 bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
1002 bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
1003 bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
1004 bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
1005 bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
1006 bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
1007 bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
1008 bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
1009 bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
1010 bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
1011 bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
1012 bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
1013 bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
1014 bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
1015 bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
1016 bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
1017 bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
1018 memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
1019 memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
1020 memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
1021 memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
1022 bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
1023 bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
1024 bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
1025 memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
1026 bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
1027 bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
1028 bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
1029 bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
1030 bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
1031 bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
1032 bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
1033 bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
1034 bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
1035 bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
1036 bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
1037 bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
1038 bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
1039 bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
1040 bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
1041 bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
1042 memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
1043 bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
1044 bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
1045 bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
1046 bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
1047 bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
1048 bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
1049 bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
1050 bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
1051 bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
1052 bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
1053 memcpy(&bp->stats.port_requested_paths[0 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
1054 memcpy(&bp->stats.port_requested_paths[1 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
1055 bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
1056 bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
1057 bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
1058 bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
1059 bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
1060 bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
1061 bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
1062 bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
1063 bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
1064 bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
1065 bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
1066 bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
1067 bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
1068 bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
1069 bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
1070 bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
1071 bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
1072 bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
1073 bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
1074 bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
1075 bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
1076 bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
1077 bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
1078 bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
1079 bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
1080 bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
1081
1082
1083 /* Fill the bp->stats structure with the FDDI counter values */
1084
1085 bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
1086 bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
1087 bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
1088 bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
1089 bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
1090 bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
1091 bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
1092 bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
1093 bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
1094 bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
1095 bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
1096
1097 #endif
1098 return ((struct net_device_stats *) &bp->os.MacStat);
1099 } // ctl_get_stat
1100
1101
1102 /*
1103 * ==============================
1104 * = skfp_ctl_set_multicast_list =
1105 * ==============================
1106 *
1107 * Overview:
1108 * Enable/Disable LLC frame promiscuous mode reception
1109 * on the adapter and/or update multicast address table.
1110 *
1111 * Returns:
1112 * None
1113 *
1114 * Arguments:
1115 * dev - pointer to device information
1116 *
1117 * Functional Description:
1118 * This function acquires the driver lock and only calls
1119 * skfp_ctl_set_multicast_list_wo_lock then.
1120 * This routine follows a fairly simple algorithm for setting the
1121 * adapter filters and CAM:
1122 *
1123 * if IFF_PROMISC flag is set
1124 * enable promiscuous mode
1125 * else
1126 * disable promiscuous mode
1127 * if number of multicast addresses <= max. multicast number
1128 * add mc addresses to adapter table
1129 * else
1130 * enable promiscuous mode
1131 * update adapter filters
1132 *
1133 * Assumptions:
1134 * Multicast addresses are presented in canonical (LSB) format.
1135 *
1136 * Side Effects:
1137 * On-board adapter filters are updated.
1138 */
1139 static void skfp_ctl_set_multicast_list(struct net_device *dev)
1140 {
1141 skfddi_priv *bp = PRIV(dev);
1142 unsigned long Flags;
1143
1144 spin_lock_irqsave(&bp->DriverLock, Flags);
1145 skfp_ctl_set_multicast_list_wo_lock(dev);
1146 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1147 return;
1148 } // skfp_ctl_set_multicast_list
1149
1150
1151
1152 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
1153 {
1154 struct s_smc *smc = (struct s_smc *) dev->priv;
1155 struct dev_mc_list *dmi; /* ptr to multicast addr entry */
1156 int i;
1157
1158 /* Enable promiscuous mode, if necessary */
1159 if (dev->flags & IFF_PROMISC) {
1160 mac_drv_rx_mode(smc, RX_ENABLE_PROMISC);
1161 PRINTK(KERN_INFO "PROMISCUOUS MODE ENABLED\n");
1162 }
1163 /* Else, update multicast address table */
1164 else {
1165 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
1166 PRINTK(KERN_INFO "PROMISCUOUS MODE DISABLED\n");
1167
1168 // Reset all MC addresses
1169 mac_clear_multicast(smc);
1170 mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI);
1171
1172 if (dev->flags & IFF_ALLMULTI) {
1173 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
1174 PRINTK(KERN_INFO "ENABLE ALL MC ADDRESSES\n");
1175 } else if (dev->mc_count > 0) {
1176 if (dev->mc_count <= FPMAX_MULTICAST) {
1177 /* use exact filtering */
1178
1179 // point to first multicast addr
1180 dmi = dev->mc_list;
1181
1182 for (i = 0; i < dev->mc_count; i++) {
1183 mac_add_multicast(smc,
1184 dmi->dmi_addr, 1);
1185 PRINTK(KERN_INFO "ENABLE MC ADDRESS:");
1186 PRINTK(" %02x %02x %02x ",
1187 dmi->dmi_addr[0],
1188 dmi->dmi_addr[1],
1189 dmi->dmi_addr[2]);
1190 PRINTK("%02x %02x %02x\n",
1191 dmi->dmi_addr[3],
1192 dmi->dmi_addr[4],
1193 dmi->dmi_addr[5]);
1194 dmi = dmi->next;
1195 } // for
1196
1197 } else { // more MC addresses than HW supports
1198
1199 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
1200 PRINTK(KERN_INFO "ENABLE ALL MC ADDRESSES\n");
1201 }
1202 } else { // no MC addresses
1203
1204 PRINTK(KERN_INFO "DISABLE ALL MC ADDRESSES\n");
1205 }
1206
1207 /* Update adapter filters */
1208 mac_update_multicast(smc);
1209 }
1210 return;
1211 } // skfp_ctl_set_multicast_list_wo_lock
1212
1213
1214 /*
1215 * ===========================
1216 * = skfp_ctl_set_mac_address =
1217 * ===========================
1218 *
1219 * Overview:
1220 * set new mac address on adapter and update dev_addr field in device table.
1221 *
1222 * Returns:
1223 * None
1224 *
1225 * Arguments:
1226 * dev - pointer to device information
1227 * addr - pointer to sockaddr structure containing unicast address to set
1228 *
1229 * Assumptions:
1230 * The address pointed to by addr->sa_data is a valid unicast
1231 * address and is presented in canonical (LSB) format.
1232 */
1233 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
1234 {
1235 struct s_smc *smc = (struct s_smc *) dev->priv;
1236 struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
1237 skfddi_priv *bp = (skfddi_priv *) & smc->os;
1238 unsigned long Flags;
1239
1240
1241 memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);
1242 spin_lock_irqsave(&bp->DriverLock, Flags);
1243 ResetAdapter(smc);
1244 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1245
1246 return (0); /* always return zero */
1247 } // skfp_ctl_set_mac_address
1248
1249
1250 /*
1251 * ==============
1252 * = skfp_ioctl =
1253 * ==============
1254 *
1255 * Overview:
1256 *
1257 * Perform IOCTL call functions here. Some are privileged operations and the
1258 * effective uid is checked in those cases.
1259 *
1260 * Returns:
1261 * status value
1262 * 0 - success
1263 * other - failure
1264 *
1265 * Arguments:
1266 * dev - pointer to device information
1267 * rq - pointer to ioctl request structure
1268 * cmd - ?
1269 *
1270 */
1271
1272
1273 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1274 {
1275 skfddi_priv *lp = PRIV(dev);
1276 struct s_skfp_ioctl ioc;
1277 int status = 0;
1278
1279 copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl));
1280 switch (ioc.cmd) {
1281 case SKFP_GET_STATS: /* Get the driver statistics */
1282 ioc.len = sizeof(lp->MacStat);
1283 copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len);
1284 break;
1285 case SKFP_CLR_STATS: /* Zero out the driver statistics */
1286 if (!capable(CAP_NET_ADMIN)) {
1287 memset(&lp->MacStat, 0, sizeof(lp->MacStat));
1288 } else {
1289 status = -EPERM;
1290 }
1291 break;
1292 default:
1293 printk("ioctl for %s: unknow cmd: %04x\n", dev->name, ioc.cmd);
1294 } // switch
1295
1296 return status;
1297 } // skfp_ioctl
1298
1299
1300 /*
1301 * =====================
1302 * = skfp_send_pkt =
1303 * =====================
1304 *
1305 * Overview:
1306 * Queues a packet for transmission and try to transmit it.
1307 *
1308 * Returns:
1309 * Condition code
1310 *
1311 * Arguments:
1312 * skb - pointer to sk_buff to queue for transmission
1313 * dev - pointer to device information
1314 *
1315 * Functional Description:
1316 * Here we assume that an incoming skb transmit request
1317 * is contained in a single physically contiguous buffer
1318 * in which the virtual address of the start of packet
1319 * (skb->data) can be converted to a physical address
1320 * by using pci_map_single().
1321 *
1322 * We have an internal queue for packets we can not send
1323 * immediately. Packets in this queue can be given to the
1324 * adapter if transmit buffers are freed.
1325 *
1326 * We can't free the skb until after it's been DMA'd
1327 * out by the adapter, so we'll keep it in the driver and
1328 * return it in mac_drv_tx_complete.
1329 *
1330 * Return Codes:
1331 * 0 - driver has queued and/or sent packet
1332 * 1 - caller should requeue the sk_buff for later transmission
1333 *
1334 * Assumptions:
1335 * The entire packet is stored in one physically
1336 * contiguous buffer which is not cached and whose
1337 * 32-bit physical address can be determined.
1338 *
1339 * It's vital that this routine is NOT reentered for the
1340 * same board and that the OS is not in another section of
1341 * code (eg. skfp_interrupt) for the same board on a
1342 * different thread.
1343 *
1344 * Side Effects:
1345 * None
1346 */
1347 static int skfp_send_pkt(struct sk_buff *skb, struct net_device *dev)
1348 {
1349 skfddi_priv *bp = PRIV(dev);
1350
1351 PRINTK(KERN_INFO "skfp_send_pkt\n");
1352
1353 /*
1354 * Verify that incoming transmit request is OK
1355 *
1356 * Note: The packet size check is consistent with other
1357 * Linux device drivers, although the correct packet
1358 * size should be verified before calling the
1359 * transmit routine.
1360 */
1361
1362 if (!(skb->len >= FDDI_K_LLC_ZLEN && skb->len <= FDDI_K_LLC_LEN)) {
1363 bp->MacStat.tx_errors++; /* bump error counter */
1364 // dequeue packets from xmt queue and send them
1365 netif_start_queue(dev);
1366 dev_kfree_skb(skb);
1367 return (0); /* return "success" */
1368 }
1369 if (bp->QueueSkb == 0) { // return with tbusy set: queue full
1370
1371 netif_stop_queue(dev);
1372 return 1;
1373 }
1374 bp->QueueSkb--;
1375 skb_queue_tail(&bp->SendSkbQueue, skb);
1376 send_queued_packets((struct s_smc *) dev->priv);
1377 if (bp->QueueSkb == 0) {
1378 netif_stop_queue(dev);
1379 }
1380 dev->trans_start = jiffies;
1381 return 0;
1382
1383 } // skfp_send_pkt
1384
1385
1386 /*
1387 * =======================
1388 * = send_queued_packets =
1389 * =======================
1390 *
1391 * Overview:
1392 * Send packets from the driver queue as long as there are some and
1393 * transmit resources are available.
1394 *
1395 * Returns:
1396 * None
1397 *
1398 * Arguments:
1399 * smc - pointer to smc (adapter) structure
1400 *
1401 * Functional Description:
1402 * Take a packet from queue if there is any. If not, then we are done.
1403 * Check if there are resources to send the packet. If not, requeue it
1404 * and exit.
1405 * Set packet descriptor flags and give packet to adapter.
1406 * Check if any send resources can be freed (we do not use the
1407 * transmit complete interrupt).
1408 */
1409 static void send_queued_packets(struct s_smc *smc)
1410 {
1411 skfddi_priv *bp = (skfddi_priv *) & smc->os;
1412 struct sk_buff *skb;
1413 unsigned char fc;
1414 int queue;
1415 struct s_smt_fp_txd *txd; // Current TxD.
1416 dma_addr_t dma_address;
1417 unsigned long Flags;
1418
1419 int frame_status; // HWM tx frame status.
1420
1421 PRINTK(KERN_INFO "send queued packets\n");
1422 for (;;) {
1423 // send first buffer from queue
1424 skb = skb_dequeue(&bp->SendSkbQueue);
1425
1426 if (!skb) {
1427 PRINTK(KERN_INFO "queue empty\n");
1428 return;
1429 } // queue empty !
1430
1431 spin_lock_irqsave(&bp->DriverLock, Flags);
1432 fc = skb->data[0];
1433 queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0;
1434 #ifdef ESS
1435 // Check if the frame may/must be sent as a synchronous frame.
1436
1437 if ((fc & ~(FC_SYNC_BIT | FC_LLC_PRIOR)) == FC_ASYNC_LLC) {
1438 // It's an LLC frame.
1439 if (!smc->ess.sync_bw_available)
1440 fc &= ~FC_SYNC_BIT; // No bandwidth available.
1441
1442 else { // Bandwidth is available.
1443
1444 if (smc->mib.fddiESSSynchTxMode) {
1445 // Send as sync. frame.
1446 fc |= FC_SYNC_BIT;
1447 }
1448 }
1449 }
1450 #endif // ESS
1451 frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue);
1452
1453 if ((frame_status & (LOC_TX | LAN_TX)) == 0) {
1454 // Unable to send the frame.
1455
1456 if ((frame_status & RING_DOWN) != 0) {
1457 // Ring is down.
1458 PRINTK("Tx attempt while ring down.\n");
1459 } else if ((frame_status & OUT_OF_TXD) != 0) {
1460 PRINTK("%s: out of TXDs.\n", bp->dev->name);
1461 } else {
1462 PRINTK("%s: out of transmit resources",
1463 bp->dev->name);
1464 }
1465
1466 // Note: We will retry the operation as soon as
1467 // transmit resources become available.
1468 skb_queue_head(&bp->SendSkbQueue, skb);
1469 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1470 return; // Packet has been queued.
1471
1472 } // if (unable to send frame)
1473
1474 bp->QueueSkb++; // one packet less in local queue
1475
1476 // source address in packet ?
1477 CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a);
1478
1479 txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue);
1480
1481 dma_address = pci_map_single(&bp->pdev, skb->data,
1482 skb->len, PCI_DMA_TODEVICE);
1483 if (frame_status & LAN_TX) {
1484 txd->txd_os.skb = skb; // save skb
1485 txd->txd_os.dma_addr = dma_address; // save dma mapping
1486 }
1487 hwm_tx_frag(smc, skb->data, dma_address, skb->len,
1488 frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF);
1489
1490 if (!(frame_status & LAN_TX)) { // local only frame
1491 pci_unmap_single(&bp->pdev, dma_address,
1492 skb->len, PCI_DMA_TODEVICE);
1493 dev_kfree_skb_irq(skb);
1494 }
1495 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1496 } // for
1497
1498 return; // never reached
1499
1500 } // send_queued_packets
1501
1502
1503 /************************
1504 *
1505 * CheckSourceAddress
1506 *
1507 * Verify if the source address is set. Insert it if necessary.
1508 *
1509 ************************/
1510 void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr)
1511 {
1512 unsigned char SRBit;
1513
1514 if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0) // source routing bit
1515
1516 return;
1517 if ((unsigned short) frame[1 + 10] != 0)
1518 return;
1519 SRBit = frame[1 + 6] & 0x01;
1520 memcpy(&frame[1 + 6], hw_addr, 6);
1521 frame[8] |= SRBit;
1522 } // CheckSourceAddress
1523
1524
1525 /************************
1526 *
1527 * ResetAdapter
1528 *
1529 * Reset the adapter and bring it back to operational mode.
1530 * Args
1531 * smc - A pointer to the SMT context struct.
1532 * Out
1533 * Nothing.
1534 *
1535 ************************/
1536 static void ResetAdapter(struct s_smc *smc)
1537 {
1538
1539 PRINTK(KERN_INFO "[fddi: ResetAdapter]\n");
1540
1541 // Stop the adapter.
1542
1543 card_stop(smc); // Stop all activity.
1544
1545 // Clear the transmit and receive descriptor queues.
1546 mac_drv_clear_tx_queue(smc);
1547 mac_drv_clear_rx_queue(smc);
1548
1549 // Restart the adapter.
1550
1551 smt_reset_defaults(smc, 1); // Initialize the SMT module.
1552
1553 init_smt(smc, (smc->os.dev)->dev_addr); // Initialize the hardware.
1554
1555 smt_online(smc, 1); // Insert into the ring again.
1556 STI_FBI();
1557
1558 // Restore original receive mode (multicasts, promiscuous, etc.).
1559 skfp_ctl_set_multicast_list_wo_lock(smc->os.dev);
1560 } // ResetAdapter
1561
1562
1563 //--------------- functions called by hardware module ----------------
1564
1565 /************************
1566 *
1567 * llc_restart_tx
1568 *
1569 * The hardware driver calls this routine when the transmit complete
1570 * interrupt bits (end of frame) for the synchronous or asynchronous
1571 * queue is set.
1572 *
1573 * NOTE The hardware driver calls this function also if no packets are queued.
1574 * The routine must be able to handle this case.
1575 * Args
1576 * smc - A pointer to the SMT context struct.
1577 * Out
1578 * Nothing.
1579 *
1580 ************************/
1581 void llc_restart_tx(struct s_smc *smc)
1582 {
1583 skfddi_priv *bp = (skfddi_priv *) & smc->os;
1584
1585 PRINTK(KERN_INFO "[llc_restart_tx]\n");
1586
1587 // Try to send queued packets
1588 spin_unlock(&bp->DriverLock);
1589 send_queued_packets(smc);
1590 spin_lock(&bp->DriverLock);
1591 netif_start_queue(bp->dev);// system may send again if it was blocked
1592
1593 } // llc_restart_tx
1594
1595
1596 /************************
1597 *
1598 * mac_drv_get_space
1599 *
1600 * The hardware module calls this function to allocate the memory
1601 * for the SMT MBufs if the define MB_OUTSIDE_SMC is specified.
1602 * Args
1603 * smc - A pointer to the SMT context struct.
1604 *
1605 * size - Size of memory in bytes to allocate.
1606 * Out
1607 * != 0 A pointer to the virtual address of the allocated memory.
1608 * == 0 Allocation error.
1609 *
1610 ************************/
1611 void *mac_drv_get_space(struct s_smc *smc, unsigned int size)
1612 {
1613 void *virt;
1614
1615 PRINTK(KERN_INFO "mac_drv_get_space (%d bytes), ", size);
1616 virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap);
1617
1618 if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) {
1619 printk("Unexpected SMT memory size requested: %d\n", size);
1620 return (NULL);
1621 }
1622 smc->os.SharedMemHeap += size; // Move heap pointer.
1623
1624 PRINTK(KERN_INFO "mac_drv_get_space end\n");
1625 PRINTK(KERN_INFO "virt addr: %lx\n", (ulong) virt);
1626 PRINTK(KERN_INFO "bus addr: %lx\n", (ulong)
1627 (smc->os.SharedMemDMA +
1628 ((char *) virt - (char *)smc->os.SharedMemAddr)));
1629 return (virt);
1630 } // mac_drv_get_space
1631
1632
1633 /************************
1634 *
1635 * mac_drv_get_desc_mem
1636 *
1637 * This function is called by the hardware dependent module.
1638 * It allocates the memory for the RxD and TxD descriptors.
1639 *
1640 * This memory must be non-cached, non-movable and non-swappable.
1641 * This memory should start at a physical page boundary.
1642 * Args
1643 * smc - A pointer to the SMT context struct.
1644 *
1645 * size - Size of memory in bytes to allocate.
1646 * Out
1647 * != 0 A pointer to the virtual address of the allocated memory.
1648 * == 0 Allocation error.
1649 *
1650 ************************/
1651 void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size)
1652 {
1653
1654 char *virt;
1655
1656 PRINTK(KERN_INFO "mac_drv_get_desc_mem\n");
1657
1658 // Descriptor memory must be aligned on 16-byte boundary.
1659
1660 virt = mac_drv_get_space(smc, size);
1661
1662 size = (u_int) (16 - (((unsigned long) virt) & 15UL));
1663 size = size % 16;
1664
1665 PRINTK("Allocate %u bytes alignment gap ", size);
1666 PRINTK("for descriptor memory.\n");
1667
1668 if (!mac_drv_get_space(smc, size)) {
1669 printk("fddi: Unable to align descriptor memory.\n");
1670 return (NULL);
1671 }
1672 return (virt + size);
1673 } // mac_drv_get_desc_mem
1674
1675
1676 /************************
1677 *
1678 * mac_drv_virt2phys
1679 *
1680 * Get the physical address of a given virtual address.
1681 * Args
1682 * smc - A pointer to the SMT context struct.
1683 *
1684 * virt - A (virtual) pointer into our 'shared' memory area.
1685 * Out
1686 * Physical address of the given virtual address.
1687 *
1688 ************************/
1689 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt)
1690 {
1691 return (smc->os.SharedMemDMA +
1692 ((char *) virt - (char *)smc->os.SharedMemAddr));
1693 } // mac_drv_virt2phys
1694
1695
1696 /************************
1697 *
1698 * dma_master
1699 *
1700 * The HWM calls this function, when the driver leads through a DMA
1701 * transfer. If the OS-specific module must prepare the system hardware
1702 * for the DMA transfer, it should do it in this function.
1703 *
1704 * The hardware module calls this dma_master if it wants to send an SMT
1705 * frame. This means that the virt address passed in here is part of
1706 * the 'shared' memory area.
1707 * Args
1708 * smc - A pointer to the SMT context struct.
1709 *
1710 * virt - The virtual address of the data.
1711 *
1712 * len - The length in bytes of the data.
1713 *
1714 * flag - Indicates the transmit direction and the buffer type:
1715 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1716 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1717 * SMT_BUF (0x80) SMT buffer
1718 *
1719 * >> NOTE: SMT_BUF and DMA_RD are always set for PCI. <<
1720 * Out
1721 * Returns the pyhsical address for the DMA transfer.
1722 *
1723 ************************/
1724 u_long dma_master(struct s_smc * smc, void *virt, int len, int flag)
1725 {
1726 return (smc->os.SharedMemDMA +
1727 ((char *) virt - (char *)smc->os.SharedMemAddr));
1728 } // dma_master
1729
1730
1731 /************************
1732 *
1733 * dma_complete
1734 *
1735 * The hardware module calls this routine when it has completed a DMA
1736 * transfer. If the operating system dependant module has set up the DMA
1737 * channel via dma_master() (e.g. Windows NT or AIX) it should clean up
1738 * the DMA channel.
1739 * Args
1740 * smc - A pointer to the SMT context struct.
1741 *
1742 * descr - A pointer to a TxD or RxD, respectively.
1743 *
1744 * flag - Indicates the DMA transfer direction / SMT buffer:
1745 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1746 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1747 * SMT_BUF (0x80) SMT buffer (managed by HWM)
1748 * Out
1749 * Nothing.
1750 *
1751 ************************/
1752 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag)
1753 {
1754 /* For TX buffers, there are two cases. If it is an SMT transmit
1755 * buffer, there is nothing to do since we use consistent memory
1756 * for the 'shared' memory area. The other case is for normal
1757 * transmit packets given to us by the networking stack, and in
1758 * that case we cleanup the PCI DMA mapping in mac_drv_tx_complete
1759 * below.
1760 *
1761 * For RX buffers, we have to unmap dynamic PCI DMA mappings here
1762 * because the hardware module is about to potentially look at
1763 * the contents of the buffer. If we did not call the PCI DMA
1764 * unmap first, the hardware module could read inconsistent data.
1765 */
1766 if (flag & DMA_WR) {
1767 skfddi_priv *bp = (skfddi_priv *) & smc->os;
1768 volatile struct s_smt_fp_rxd *r = &descr->r;
1769
1770 /* If SKB is NULL, we used the local buffer. */
1771 if (r->rxd_os.skb && r->rxd_os.dma_addr) {
1772 int MaxFrameSize = bp->MaxFrameSize;
1773
1774 pci_unmap_single(&bp->pdev, r->rxd_os.dma_addr,
1775 MaxFrameSize, PCI_DMA_FROMDEVICE);
1776 r->rxd_os.dma_addr = 0;
1777 }
1778 }
1779 } // dma_complete
1780
1781
1782 /************************
1783 *
1784 * mac_drv_tx_complete
1785 *
1786 * Transmit of a packet is complete. Release the tx staging buffer.
1787 *
1788 * Args
1789 * smc - A pointer to the SMT context struct.
1790 *
1791 * txd - A pointer to the last TxD which is used by the frame.
1792 * Out
1793 * Returns nothing.
1794 *
1795 ************************/
1796 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
1797 {
1798 struct sk_buff *skb;
1799
1800 PRINTK(KERN_INFO "entering mac_drv_tx_complete\n");
1801 // Check if this TxD points to a skb
1802
1803 if (!(skb = txd->txd_os.skb)) {
1804 PRINTK("TXD with no skb assigned.\n");
1805 return;
1806 }
1807 txd->txd_os.skb = NULL;
1808
1809 // release the DMA mapping
1810 pci_unmap_single(&smc->os.pdev, txd->txd_os.dma_addr,
1811 skb->len, PCI_DMA_TODEVICE);
1812 txd->txd_os.dma_addr = 0;
1813
1814 smc->os.MacStat.tx_packets++; // Count transmitted packets.
1815 smc->os.MacStat.tx_bytes+=skb->len; // Count bytes
1816
1817 // free the skb
1818 dev_kfree_skb_irq(skb);
1819
1820 PRINTK(KERN_INFO "leaving mac_drv_tx_complete\n");
1821 } // mac_drv_tx_complete
1822
1823
1824 /************************
1825 *
1826 * dump packets to logfile
1827 *
1828 ************************/
1829 #ifdef DUMPPACKETS
1830 void dump_data(unsigned char *Data, int length)
1831 {
1832 int i, j;
1833 unsigned char s[255], sh[10];
1834 if (length > 64) {
1835 length = 64;
1836 }
1837 printk(KERN_INFO "---Packet start---\n");
1838 for (i = 0, j = 0; i < length / 8; i++, j += 8)
1839 printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\n",
1840 Data[j + 0], Data[j + 1], Data[j + 2], Data[j + 3],
1841 Data[j + 4], Data[j + 5], Data[j + 6], Data[j + 7]);
1842 strcpy(s, "");
1843 for (i = 0; i < length % 8; i++) {
1844 sprintf(sh, "%02x ", Data[j + i]);
1845 strcat(s, sh);
1846 }
1847 printk(KERN_INFO "%s\n", s);
1848 printk(KERN_INFO "------------------\n");
1849 } // dump_data
1850 #else
1851 #define dump_data(data,len)
1852 #endif // DUMPPACKETS
1853
1854 /************************
1855 *
1856 * mac_drv_rx_complete
1857 *
1858 * The hardware module calls this function if an LLC frame is received
1859 * in a receive buffer. Also the SMT, NSA, and directed beacon frames
1860 * from the network will be passed to the LLC layer by this function
1861 * if passing is enabled.
1862 *
1863 * mac_drv_rx_complete forwards the frame to the LLC layer if it should
1864 * be received. It also fills the RxD ring with new receive buffers if
1865 * some can be queued.
1866 * Args
1867 * smc - A pointer to the SMT context struct.
1868 *
1869 * rxd - A pointer to the first RxD which is used by the receive frame.
1870 *
1871 * frag_count - Count of RxDs used by the received frame.
1872 *
1873 * len - Frame length.
1874 * Out
1875 * Nothing.
1876 *
1877 ************************/
1878 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1879 int frag_count, int len)
1880 {
1881 skfddi_priv *bp = (skfddi_priv *) & smc->os;
1882 struct sk_buff *skb;
1883 unsigned char *virt, *cp;
1884 unsigned short ri;
1885 u_int RifLength;
1886
1887 PRINTK(KERN_INFO "entering mac_drv_rx_complete (len=%d)\n", len);
1888 if (frag_count != 1) { // This is not allowed to happen.
1889
1890 printk("fddi: Multi-fragment receive!\n");
1891 goto RequeueRxd; // Re-use the given RXD(s).
1892
1893 }
1894 skb = rxd->rxd_os.skb;
1895 if (!skb) {
1896 PRINTK(KERN_INFO "No skb in rxd\n");
1897 smc->os.MacStat.rx_errors++;
1898 goto RequeueRxd;
1899 }
1900 virt = skb->data;
1901
1902 // The DMA mapping was released in dma_complete above.
1903
1904 dump_data(skb->data, len);
1905
1906 /*
1907 * FDDI Frame format:
1908 * +-------+-------+-------+------------+--------+------------+
1909 * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] |
1910 * +-------+-------+-------+------------+--------+------------+
1911 *
1912 * FC = Frame Control
1913 * DA = Destination Address
1914 * SA = Source Address
1915 * RIF = Routing Information Field
1916 * LLC = Logical Link Control
1917 */
1918
1919 // Remove Routing Information Field (RIF), if present.
1920
1921 if ((virt[1 + 6] & FDDI_RII) == 0)
1922 RifLength = 0;
1923 else {
1924 int n;
1925 // goos: RIF removal has still to be tested
1926 PRINTK(KERN_INFO "RIF found\n");
1927 // Get RIF length from Routing Control (RC) field.
1928 cp = virt + FDDI_MAC_HDR_LEN; // Point behind MAC header.
1929
1930 ri = ntohs(*((unsigned short *) cp));
1931 RifLength = ri & FDDI_RCF_LEN_MASK;
1932 if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) {
1933 printk("fddi: Invalid RIF.\n");
1934 goto RequeueRxd; // Discard the frame.
1935
1936 }
1937 virt[1 + 6] &= ~FDDI_RII; // Clear RII bit.
1938 // regions overlap
1939
1940 virt = cp + RifLength;
1941 for (n = FDDI_MAC_HDR_LEN; n; n--)
1942 *--virt = *--cp;
1943 // adjust sbd->data pointer
1944 skb_pull(skb, RifLength);
1945 len -= RifLength;
1946 RifLength = 0;
1947 }
1948
1949 // Count statistics.
1950 smc->os.MacStat.rx_packets++; // Count indicated receive packets.
1951 smc->os.MacStat.rx_bytes+=len; // Count bytes
1952
1953 // virt points to header again
1954 if (virt[1] & 0x01) { // Check group (multicast) bit.
1955
1956 smc->os.MacStat.multicast++;
1957 }
1958
1959 // deliver frame to system
1960 rxd->rxd_os.skb = NULL;
1961 skb_trim(skb, len);
1962 skb->protocol = fddi_type_trans(skb, bp->dev);
1963 skb->dev = bp->dev; /* pass up device pointer */
1964
1965 netif_rx(skb);
1966 bp->dev->last_rx = jiffies;
1967
1968 HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
1969 return;
1970
1971 RequeueRxd:
1972 PRINTK(KERN_INFO "Rx: re-queue RXD.\n");
1973 mac_drv_requeue_rxd(smc, rxd, frag_count);
1974 smc->os.MacStat.rx_errors++; // Count receive packets not indicated.
1975
1976 } // mac_drv_rx_complete
1977
1978
1979 /************************
1980 *
1981 * mac_drv_requeue_rxd
1982 *
1983 * The hardware module calls this function to request the OS-specific
1984 * module to queue the receive buffer(s) represented by the pointer
1985 * to the RxD and the frag_count into the receive queue again. This
1986 * buffer was filled with an invalid frame or an SMT frame.
1987 * Args
1988 * smc - A pointer to the SMT context struct.
1989 *
1990 * rxd - A pointer to the first RxD which is used by the receive frame.
1991 *
1992 * frag_count - Count of RxDs used by the received frame.
1993 * Out
1994 * Nothing.
1995 *
1996 ************************/
1997 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1998 int frag_count)
1999 {
2000 volatile struct s_smt_fp_rxd *next_rxd;
2001 volatile struct s_smt_fp_rxd *src_rxd;
2002 struct sk_buff *skb;
2003 int MaxFrameSize;
2004 unsigned char *v_addr;
2005 dma_addr_t b_addr;
2006
2007 if (frag_count != 1) // This is not allowed to happen.
2008
2009 printk("fddi: Multi-fragment requeue!\n");
2010
2011 MaxFrameSize = ((skfddi_priv *) & smc->os)->MaxFrameSize;
2012 src_rxd = rxd;
2013 for (; frag_count > 0; frag_count--) {
2014 next_rxd = src_rxd->rxd_next;
2015 rxd = HWM_GET_CURR_RXD(smc);
2016
2017 skb = src_rxd->rxd_os.skb;
2018 if (skb == NULL) { // this should not happen
2019
2020 PRINTK("Requeue with no skb in rxd!\n");
2021 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
2022 if (skb) {
2023 // we got a skb
2024 rxd->rxd_os.skb = skb;
2025 skb_reserve(skb, 3);
2026 skb_put(skb, MaxFrameSize);
2027 v_addr = skb->data;
2028 b_addr = pci_map_single(&smc->os.pdev,
2029 v_addr,
2030 MaxFrameSize,
2031 PCI_DMA_FROMDEVICE);
2032 rxd->rxd_os.dma_addr = b_addr;
2033 } else {
2034 // no skb available, use local buffer
2035 PRINTK("Queueing invalid buffer!\n");
2036 rxd->rxd_os.skb = NULL;
2037 v_addr = smc->os.LocalRxBuffer;
2038 b_addr = smc->os.LocalRxBufferDMA;
2039 }
2040 } else {
2041 // we use skb from old rxd
2042 rxd->rxd_os.skb = skb;
2043 v_addr = skb->data;
2044 b_addr = pci_map_single(&smc->os.pdev,
2045 v_addr,
2046 MaxFrameSize,
2047 PCI_DMA_FROMDEVICE);
2048 rxd->rxd_os.dma_addr = b_addr;
2049 }
2050 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
2051 FIRST_FRAG | LAST_FRAG);
2052
2053 src_rxd = next_rxd;
2054 }
2055 } // mac_drv_requeue_rxd
2056
2057
2058 /************************
2059 *
2060 * mac_drv_fill_rxd
2061 *
2062 * The hardware module calls this function at initialization time
2063 * to fill the RxD ring with receive buffers. It is also called by
2064 * mac_drv_rx_complete if rx_free is large enough to queue some new
2065 * receive buffers into the RxD ring. mac_drv_fill_rxd queues new
2066 * receive buffers as long as enough RxDs and receive buffers are
2067 * available.
2068 * Args
2069 * smc - A pointer to the SMT context struct.
2070 * Out
2071 * Nothing.
2072 *
2073 ************************/
2074 void mac_drv_fill_rxd(struct s_smc *smc)
2075 {
2076 int MaxFrameSize;
2077 unsigned char *v_addr;
2078 unsigned long b_addr;
2079 struct sk_buff *skb;
2080 volatile struct s_smt_fp_rxd *rxd;
2081
2082 PRINTK(KERN_INFO "entering mac_drv_fill_rxd\n");
2083
2084 // Walk through the list of free receive buffers, passing receive
2085 // buffers to the HWM as long as RXDs are available.
2086
2087 MaxFrameSize = ((skfddi_priv *) & smc->os)->MaxFrameSize;
2088 // Check if there is any RXD left.
2089 while (HWM_GET_RX_FREE(smc) > 0) {
2090 PRINTK(KERN_INFO ".\n");
2091
2092 rxd = HWM_GET_CURR_RXD(smc);
2093 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
2094 if (skb) {
2095 // we got a skb
2096 skb_reserve(skb, 3);
2097 skb_put(skb, MaxFrameSize);
2098 v_addr = skb->data;
2099 b_addr = pci_map_single(&smc->os.pdev,
2100 v_addr,
2101 MaxFrameSize,
2102 PCI_DMA_FROMDEVICE);
2103 rxd->rxd_os.dma_addr = b_addr;
2104 } else {
2105 // no skb available, use local buffer
2106 // System has run out of buffer memory, but we want to
2107 // keep the receiver running in hope of better times.
2108 // Multiple descriptors may point to this local buffer,
2109 // so data in it must be considered invalid.
2110 PRINTK("Queueing invalid buffer!\n");
2111 v_addr = smc->os.LocalRxBuffer;
2112 b_addr = smc->os.LocalRxBufferDMA;
2113 }
2114
2115 rxd->rxd_os.skb = skb;
2116
2117 // Pass receive buffer to HWM.
2118 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
2119 FIRST_FRAG | LAST_FRAG);
2120 }
2121 PRINTK(KERN_INFO "leaving mac_drv_fill_rxd\n");
2122 } // mac_drv_fill_rxd
2123
2124
2125 /************************
2126 *
2127 * mac_drv_clear_rxd
2128 *
2129 * The hardware module calls this function to release unused
2130 * receive buffers.
2131 * Args
2132 * smc - A pointer to the SMT context struct.
2133 *
2134 * rxd - A pointer to the first RxD which is used by the receive buffer.
2135 *
2136 * frag_count - Count of RxDs used by the receive buffer.
2137 * Out
2138 * Nothing.
2139 *
2140 ************************/
2141 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
2142 int frag_count)
2143 {
2144
2145 struct sk_buff *skb;
2146
2147 PRINTK("entering mac_drv_clear_rxd\n");
2148
2149 if (frag_count != 1) // This is not allowed to happen.
2150
2151 printk("fddi: Multi-fragment clear!\n");
2152
2153 for (; frag_count > 0; frag_count--) {
2154 skb = rxd->rxd_os.skb;
2155 if (skb != NULL) {
2156 skfddi_priv *bp = (skfddi_priv *) & smc->os;
2157 int MaxFrameSize = bp->MaxFrameSize;
2158
2159 pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr,
2160 MaxFrameSize, PCI_DMA_FROMDEVICE);
2161
2162 dev_kfree_skb(skb);
2163 rxd->rxd_os.skb = NULL;
2164 }
2165 rxd = rxd->rxd_next; // Next RXD.
2166
2167 }
2168 } // mac_drv_clear_rxd
2169
2170
2171 /************************
2172 *
2173 * mac_drv_rx_init
2174 *
2175 * The hardware module calls this routine when an SMT or NSA frame of the
2176 * local SMT should be delivered to the LLC layer.
2177 *
2178 * It is necessary to have this function, because there is no other way to
2179 * copy the contents of SMT MBufs into receive buffers.
2180 *
2181 * mac_drv_rx_init allocates the required target memory for this frame,
2182 * and receives the frame fragment by fragment by calling mac_drv_rx_frag.
2183 * Args
2184 * smc - A pointer to the SMT context struct.
2185 *
2186 * len - The length (in bytes) of the received frame (FC, DA, SA, Data).
2187 *
2188 * fc - The Frame Control field of the received frame.
2189 *
2190 * look_ahead - A pointer to the lookahead data buffer (may be NULL).
2191 *
2192 * la_len - The length of the lookahead data stored in the lookahead
2193 * buffer (may be zero).
2194 * Out
2195 * Always returns zero (0).
2196 *
2197 ************************/
2198 int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
2199 char *look_ahead, int la_len)
2200 {
2201 struct sk_buff *skb;
2202
2203 PRINTK("entering mac_drv_rx_init(len=%d)\n", len);
2204
2205 // "Received" a SMT or NSA frame of the local SMT.
2206
2207 if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) {
2208 PRINTK("fddi: Discard invalid local SMT frame\n");
2209 PRINTK(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n",
2210 len, la_len, (unsigned long) look_ahead);
2211 return (0);
2212 }
2213 skb = alloc_skb(len + 3, GFP_ATOMIC);
2214 if (!skb) {
2215 PRINTK("fddi: Local SMT: skb memory exhausted.\n");
2216 return (0);
2217 }
2218 skb_reserve(skb, 3);
2219 skb_put(skb, len);
2220 memcpy(skb->data, look_ahead, len);
2221
2222 // deliver frame to system
2223 skb->protocol = fddi_type_trans(skb, ((skfddi_priv *) & smc->os)->dev);
2224 skb->dev->last_rx = jiffies;
2225 netif_rx(skb);
2226
2227 return (0);
2228 } // mac_drv_rx_init
2229
2230
2231 /************************
2232 *
2233 * smt_timer_poll
2234 *
2235 * This routine is called periodically by the SMT module to clean up the
2236 * driver.
2237 *
2238 * Return any queued frames back to the upper protocol layers if the ring
2239 * is down.
2240 * Args
2241 * smc - A pointer to the SMT context struct.
2242 * Out
2243 * Nothing.
2244 *
2245 ************************/
2246 void smt_timer_poll(struct s_smc *smc)
2247 {
2248 } // smt_timer_poll
2249
2250
2251 /************************
2252 *
2253 * ring_status_indication
2254 *
2255 * This function indicates a change of the ring state.
2256 * Args
2257 * smc - A pointer to the SMT context struct.
2258 *
2259 * status - The current ring status.
2260 * Out
2261 * Nothing.
2262 *
2263 ************************/
2264 void ring_status_indication(struct s_smc *smc, u_long status)
2265 {
2266 PRINTK("ring_status_indication( ");
2267 if (status & RS_RES15)
2268 PRINTK("RS_RES15 ");
2269 if (status & RS_HARDERROR)
2270 PRINTK("RS_HARDERROR ");
2271 if (status & RS_SOFTERROR)
2272 PRINTK("RS_SOFTERROR ");
2273 if (status & RS_BEACON)
2274 PRINTK("RS_BEACON ");
2275 if (status & RS_PATHTEST)
2276 PRINTK("RS_PATHTEST ");
2277 if (status & RS_SELFTEST)
2278 PRINTK("RS_SELFTEST ");
2279 if (status & RS_RES9)
2280 PRINTK("RS_RES9 ");
2281 if (status & RS_DISCONNECT)
2282 PRINTK("RS_DISCONNECT ");
2283 if (status & RS_RES7)
2284 PRINTK("RS_RES7 ");
2285 if (status & RS_DUPADDR)
2286 PRINTK("RS_DUPADDR ");
2287 if (status & RS_NORINGOP)
2288 PRINTK("RS_NORINGOP ");
2289 if (status & RS_VERSION)
2290 PRINTK("RS_VERSION ");
2291 if (status & RS_STUCKBYPASSS)
2292 PRINTK("RS_STUCKBYPASSS ");
2293 if (status & RS_EVENT)
2294 PRINTK("RS_EVENT ");
2295 if (status & RS_RINGOPCHANGE)
2296 PRINTK("RS_RINGOPCHANGE ");
2297 if (status & RS_RES0)
2298 PRINTK("RS_RES0 ");
2299 PRINTK("]\n");
2300 } // ring_status_indication
2301
2302
2303 /************************
2304 *
2305 * smt_get_time
2306 *
2307 * Gets the current time from the system.
2308 * Args
2309 * None.
2310 * Out
2311 * The current time in TICKS_PER_SECOND.
2312 *
2313 * TICKS_PER_SECOND has the unit 'count of timer ticks per second'. It is
2314 * defined in "targetos.h". The definition of TICKS_PER_SECOND must comply
2315 * to the time returned by smt_get_time().
2316 *
2317 ************************/
2318 unsigned long smt_get_time(void)
2319 {
2320 return jiffies;
2321 } // smt_get_time
2322
2323
2324 /************************
2325 *
2326 * smt_stat_counter
2327 *
2328 * Status counter update (ring_op, fifo full).
2329 * Args
2330 * smc - A pointer to the SMT context struct.
2331 *
2332 * stat - = 0: A ring operational change occurred.
2333 * = 1: The FORMAC FIFO buffer is full / FIFO overflow.
2334 * Out
2335 * Nothing.
2336 *
2337 ************************/
2338 void smt_stat_counter(struct s_smc *smc, int stat)
2339 {
2340 // BOOLEAN RingIsUp ;
2341
2342 PRINTK(KERN_INFO "smt_stat_counter\n");
2343 switch (stat) {
2344 case 0:
2345 PRINTK(KERN_INFO "Ring operational change.\n");
2346 break;
2347 case 1:
2348 PRINTK(KERN_INFO "Receive fifo overflow.\n");
2349 smc->os.MacStat.rx_errors++;
2350 break;
2351 default:
2352 PRINTK(KERN_INFO "Unknown status (%d).\n", stat);
2353 break;
2354 }
2355 } // smt_stat_counter
2356
2357
2358 /************************
2359 *
2360 * cfm_state_change
2361 *
2362 * Sets CFM state in custom statistics.
2363 * Args
2364 * smc - A pointer to the SMT context struct.
2365 *
2366 * c_state - Possible values are:
2367 *
2368 * EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST,
2369 * EC5_INSERT, EC6_CHECK, EC7_DEINSERT
2370 * Out
2371 * Nothing.
2372 *
2373 ************************/
2374 void cfm_state_change(struct s_smc *smc, int c_state)
2375 {
2376 #ifdef DRIVERDEBUG
2377 char *s;
2378
2379 switch (c_state) {
2380 case SC0_ISOLATED:
2381 s = "SC0_ISOLATED";
2382 break;
2383 case SC1_WRAP_A:
2384 s = "SC1_WRAP_A";
2385 break;
2386 case SC2_WRAP_B:
2387 s = "SC2_WRAP_B";
2388 break;
2389 case SC4_THRU_A:
2390 s = "SC4_THRU_A";
2391 break;
2392 case SC5_THRU_B:
2393 s = "SC5_THRU_B";
2394 break;
2395 case SC7_WRAP_S:
2396 s = "SC7_WRAP_S";
2397 break;
2398 case SC9_C_WRAP_A:
2399 s = "SC9_C_WRAP_A";
2400 break;
2401 case SC10_C_WRAP_B:
2402 s = "SC10_C_WRAP_B";
2403 break;
2404 case SC11_C_WRAP_S:
2405 s = "SC11_C_WRAP_S";
2406 break;
2407 default:
2408 PRINTK(KERN_INFO "cfm_state_change: unknown %d\n", c_state);
2409 return;
2410 }
2411 PRINTK(KERN_INFO "cfm_state_change: %s\n", s);
2412 #endif // DRIVERDEBUG
2413 } // cfm_state_change
2414
2415
2416 /************************
2417 *
2418 * ecm_state_change
2419 *
2420 * Sets ECM state in custom statistics.
2421 * Args
2422 * smc - A pointer to the SMT context struct.
2423 *
2424 * e_state - Possible values are:
2425 *
2426 * SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12),
2427 * SC5_THRU_B (7), SC7_WRAP_S (8)
2428 * Out
2429 * Nothing.
2430 *
2431 ************************/
2432 void ecm_state_change(struct s_smc *smc, int e_state)
2433 {
2434 #ifdef DRIVERDEBUG
2435 char *s;
2436
2437 switch (e_state) {
2438 case EC0_OUT:
2439 s = "EC0_OUT";
2440 break;
2441 case EC1_IN:
2442 s = "EC1_IN";
2443 break;
2444 case EC2_TRACE:
2445 s = "EC2_TRACE";
2446 break;
2447 case EC3_LEAVE:
2448 s = "EC3_LEAVE";
2449 break;
2450 case EC4_PATH_TEST:
2451 s = "EC4_PATH_TEST";
2452 break;
2453 case EC5_INSERT:
2454 s = "EC5_INSERT";
2455 break;
2456 case EC6_CHECK:
2457 s = "EC6_CHECK";
2458 break;
2459 case EC7_DEINSERT:
2460 s = "EC7_DEINSERT";
2461 break;
2462 default:
2463 s = "unknown";
2464 break;
2465 }
2466 PRINTK(KERN_INFO "ecm_state_change: %s\n", s);
2467 #endif //DRIVERDEBUG
2468 } // ecm_state_change
2469
2470
2471 /************************
2472 *
2473 * rmt_state_change
2474 *
2475 * Sets RMT state in custom statistics.
2476 * Args
2477 * smc - A pointer to the SMT context struct.
2478 *
2479 * r_state - Possible values are:
2480 *
2481 * RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT,
2482 * RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE
2483 * Out
2484 * Nothing.
2485 *
2486 ************************/
2487 void rmt_state_change(struct s_smc *smc, int r_state)
2488 {
2489 #ifdef DRIVERDEBUG
2490 char *s;
2491
2492 switch (r_state) {
2493 case RM0_ISOLATED:
2494 s = "RM0_ISOLATED";
2495 break;
2496 case RM1_NON_OP:
2497 s = "RM1_NON_OP - not operational";
2498 break;
2499 case RM2_RING_OP:
2500 s = "RM2_RING_OP - ring operational";
2501 break;
2502 case RM3_DETECT:
2503 s = "RM3_DETECT - detect dupl addresses";
2504 break;
2505 case RM4_NON_OP_DUP:
2506 s = "RM4_NON_OP_DUP - dupl. addr detected";
2507 break;
2508 case RM5_RING_OP_DUP:
2509 s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
2510 break;
2511 case RM6_DIRECTED:
2512 s = "RM6_DIRECTED - sending directed beacons";
2513 break;
2514 case RM7_TRACE:
2515 s = "RM7_TRACE - trace initiated";
2516 break;
2517 default:
2518 s = "unknown";
2519 break;
2520 }
2521 PRINTK(KERN_INFO "[rmt_state_change: %s]\n", s);
2522 #endif // DRIVERDEBUG
2523 } // rmt_state_change
2524
2525
2526 /************************
2527 *
2528 * drv_reset_indication
2529 *
2530 * This function is called by the SMT when it has detected a severe
2531 * hardware problem. The driver should perform a reset on the adapter
2532 * as soon as possible, but not from within this function.
2533 * Args
2534 * smc - A pointer to the SMT context struct.
2535 * Out
2536 * Nothing.
2537 *
2538 ************************/
2539 void drv_reset_indication(struct s_smc *smc)
2540 {
2541 PRINTK(KERN_INFO "entering drv_reset_indication\n");
2542
2543 smc->os.ResetRequested = TRUE; // Set flag.
2544
2545 } // drv_reset_indication
2546
2547
2548
2549 //--------------- functions for use as a module ----------------
2550
2551 #ifdef MODULE
2552 /************************
2553 *
2554 * Note now that module autoprobing is allowed under PCI. The
2555 * IRQ lines will not be auto-detected; instead I'll rely on the BIOSes
2556 * to "do the right thing".
2557 *
2558 ************************/
2559 #define LP(a) ((struct s_smc*)(a))
2560 static struct net_device *mdev;
2561
2562 /************************
2563 *
2564 * init_module
2565 *
2566 * If compiled as a module, find
2567 * adapters and initialize them.
2568 *
2569 ************************/
2570 int init_module(void)
2571 {
2572 struct net_device *p;
2573
2574 PRINTK(KERN_INFO "FDDI init module\n");
2575 if ((mdev = insert_device(NULL, skfp_probe)) == NULL)
2576 return -ENOMEM;
2577
2578 for (p = mdev; p != NULL; p = LP(p->priv)->os.next_module) {
2579 PRINTK(KERN_INFO "device to register: %s\n", p->name);
2580 if (register_netdev(p) != 0) {
2581 printk("skfddi init_module failed\n");
2582 return -EIO;
2583 }
2584 }
2585
2586 PRINTK(KERN_INFO "+++++ exit with success +++++\n");
2587 return 0;
2588 } // init_module
2589
2590 /************************
2591 *
2592 * cleanup_module
2593 *
2594 * Release all resources claimed by this module.
2595 *
2596 ************************/
2597 void cleanup_module(void)
2598 {
2599 PRINTK(KERN_INFO "cleanup_module\n");
2600 while (mdev != NULL) {
2601 mdev = unlink_modules(mdev);
2602 }
2603 return;
2604 } // cleanup_module
2605
2606
2607 /************************
2608 *
2609 * unlink_modules
2610 *
2611 * Unregister devices and release their memory.
2612 *
2613 ************************/
2614 static struct net_device *unlink_modules(struct net_device *p)
2615 {
2616 struct net_device *next = NULL;
2617
2618 if (p->priv) { /* Private areas allocated? */
2619 struct s_smc *lp = (struct s_smc *) p->priv;
2620
2621 next = lp->os.next_module;
2622
2623 if (lp->os.SharedMemAddr) {
2624 pci_free_consistent(&lp->os.pdev,
2625 lp->os.SharedMemSize,
2626 lp->os.SharedMemAddr,
2627 lp->os.SharedMemDMA);
2628 lp->os.SharedMemAddr = NULL;
2629 }
2630 if (lp->os.LocalRxBuffer) {
2631 pci_free_consistent(&lp->os.pdev,
2632 MAX_FRAME_SIZE,
2633 lp->os.LocalRxBuffer,
2634 lp->os.LocalRxBufferDMA);
2635 lp->os.LocalRxBuffer = NULL;
2636 }
2637 release_region(p->base_addr,
2638 (lp->os.bus_type == SK_BUS_TYPE_PCI ? FP_IO_LEN : 0));
2639 }
2640 unregister_netdev(p);
2641 printk("%s: unloaded\n", p->name);
2642 kfree(p); /* Free the device structure */
2643
2644 return next;
2645 } // unlink_modules
2646
2647
2648 #endif /* MODULE */
2649