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