allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / net / skfp / skfddi.c
bloba7ef6c8b7721b00e40148388784e5b70279902f0
1 /*
2 * File Name:
3 * skfddi.c
5 * Copyright Information:
6 * Copyright SysKonnect 1998,1999.
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.
13 * The information in this file is provided "AS IS" without warranty.
15 * Abstract:
16 * A Linux device driver supporting the SysKonnect FDDI PCI controller
17 * familie.
19 * Maintainers:
20 * CG Christoph Goos (cgoos@syskonnect.de)
22 * Contributors:
23 * DM David S. Miller
25 * Address all question to:
26 * linux@syskonnect.de
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".
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 dependent 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.
43 * Modification History:
44 * Date Name Description
45 * 02-Mar-98 CG Created.
47 * 10-Mar-99 CG Support for 2.2.x added.
48 * 25-Mar-99 CG Corrected IRQ routing for SMP (APIC)
49 * 26-Oct-99 CG Fixed compilation error on 2.2.13
50 * 12-Nov-99 CG Source code release
51 * 22-Nov-99 CG Included in kernel source.
52 * 07-May-00 DM 64 bit fixes, new dma interface
53 * 31-Jul-03 DB Audit copy_*_user in skfp_ioctl
54 * Daniele Bellucci <bellucda@tiscali.it>
55 * 03-Dec-03 SH Convert to PCI device model
57 * Compilation options (-Dxxx):
58 * DRIVERDEBUG print lots of messages to log file
59 * DUMPPACKETS print received/transmitted packets to logfile
61 * Tested cpu architectures:
62 * - i386
63 * - sparc64
66 /* Version information string - should be updated prior to */
67 /* each new release!!! */
68 #define VERSION "2.07"
70 static const char * const boot_msg =
71 "SysKonnect FDDI PCI Adapter driver v" VERSION " for\n"
72 " SK-55xx/SK-58xx adapters (SK-NET FDDI-FP/UP/LP)";
74 /* Include files */
76 #include <linux/module.h>
77 #include <linux/kernel.h>
78 #include <linux/errno.h>
79 #include <linux/ioport.h>
80 #include <linux/slab.h>
81 #include <linux/interrupt.h>
82 #include <linux/pci.h>
83 #include <linux/netdevice.h>
84 #include <linux/fddidevice.h>
85 #include <linux/skbuff.h>
86 #include <linux/bitops.h>
88 #include <asm/byteorder.h>
89 #include <asm/io.h>
90 #include <asm/uaccess.h>
92 #include "h/types.h"
93 #undef ADDR // undo Linux definition
94 #include "h/skfbi.h"
95 #include "h/fddi.h"
96 #include "h/smc.h"
97 #include "h/smtstate.h"
100 // Define module-wide (static) routines
101 static int skfp_driver_init(struct net_device *dev);
102 static int skfp_open(struct net_device *dev);
103 static int skfp_close(struct net_device *dev);
104 static irqreturn_t skfp_interrupt(int irq, void *dev_id);
105 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev);
106 static void skfp_ctl_set_multicast_list(struct net_device *dev);
107 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev);
108 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr);
109 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
110 static int skfp_send_pkt(struct sk_buff *skb, struct net_device *dev);
111 static void send_queued_packets(struct s_smc *smc);
112 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr);
113 static void ResetAdapter(struct s_smc *smc);
116 // Functions needed by the hardware module
117 void *mac_drv_get_space(struct s_smc *smc, u_int size);
118 void *mac_drv_get_desc_mem(struct s_smc *smc, u_int size);
119 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt);
120 unsigned long dma_master(struct s_smc *smc, void *virt, int len, int flag);
121 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr,
122 int flag);
123 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd);
124 void llc_restart_tx(struct s_smc *smc);
125 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
126 int frag_count, int len);
127 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
128 int frag_count);
129 void mac_drv_fill_rxd(struct s_smc *smc);
130 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
131 int frag_count);
132 int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
133 int la_len);
134 void dump_data(unsigned char *Data, int length);
136 // External functions from the hardware module
137 extern u_int mac_drv_check_space(void);
138 extern void read_address(struct s_smc *smc, u_char * mac_addr);
139 extern void card_stop(struct s_smc *smc);
140 extern int mac_drv_init(struct s_smc *smc);
141 extern void hwm_tx_frag(struct s_smc *smc, char far * virt, u_long phys,
142 int len, int frame_status);
143 extern int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count,
144 int frame_len, int frame_status);
145 extern int init_smt(struct s_smc *smc, u_char * mac_addr);
146 extern void fddi_isr(struct s_smc *smc);
147 extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
148 int len, int frame_status);
149 extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
150 extern void mac_drv_clear_rx_queue(struct s_smc *smc);
151 extern void enable_tx_irq(struct s_smc *smc, u_short queue);
153 static struct pci_device_id skfddi_pci_tbl[] = {
154 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
155 { } /* Terminating entry */
157 MODULE_DEVICE_TABLE(pci, skfddi_pci_tbl);
158 MODULE_LICENSE("GPL");
159 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
161 // Define module-wide (static) variables
163 static int num_boards; /* total number of adapters configured */
165 #ifdef DRIVERDEBUG
166 #define PRINTK(s, args...) printk(s, ## args)
167 #else
168 #define PRINTK(s, args...)
169 #endif // DRIVERDEBUG
172 * =================
173 * = skfp_init_one =
174 * =================
176 * Overview:
177 * Probes for supported FDDI PCI controllers
179 * Returns:
180 * Condition code
182 * Arguments:
183 * pdev - pointer to PCI device information
185 * Functional Description:
186 * This is now called by PCI driver registration process
187 * for each board found.
189 * Return Codes:
190 * 0 - This device (fddi0, fddi1, etc) configured successfully
191 * -ENODEV - No devices present, or no SysKonnect FDDI PCI device
192 * present for this device name
195 * Side Effects:
196 * Device structures for FDDI adapters (fddi0, fddi1, etc) are
197 * initialized and the board resources are read and stored in
198 * the device structure.
200 static int skfp_init_one(struct pci_dev *pdev,
201 const struct pci_device_id *ent)
203 struct net_device *dev;
204 struct s_smc *smc; /* board pointer */
205 void __iomem *mem;
206 int err;
208 PRINTK(KERN_INFO "entering skfp_init_one\n");
210 if (num_boards == 0)
211 printk("%s\n", boot_msg);
213 err = pci_enable_device(pdev);
214 if (err)
215 return err;
217 err = pci_request_regions(pdev, "skfddi");
218 if (err)
219 goto err_out1;
221 pci_set_master(pdev);
223 #ifdef MEM_MAPPED_IO
224 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
225 printk(KERN_ERR "skfp: region is not an MMIO resource\n");
226 err = -EIO;
227 goto err_out2;
230 mem = ioremap(pci_resource_start(pdev, 0), 0x4000);
231 #else
232 if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) {
233 printk(KERN_ERR "skfp: region is not PIO resource\n");
234 err = -EIO;
235 goto err_out2;
238 mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN);
239 #endif
240 if (!mem) {
241 printk(KERN_ERR "skfp: Unable to map register, "
242 "FDDI adapter will be disabled.\n");
243 err = -EIO;
244 goto err_out2;
247 dev = alloc_fddidev(sizeof(struct s_smc));
248 if (!dev) {
249 printk(KERN_ERR "skfp: Unable to allocate fddi device, "
250 "FDDI adapter will be disabled.\n");
251 err = -ENOMEM;
252 goto err_out3;
255 dev->irq = pdev->irq;
256 dev->get_stats = &skfp_ctl_get_stats;
257 dev->open = &skfp_open;
258 dev->stop = &skfp_close;
259 dev->hard_start_xmit = &skfp_send_pkt;
260 dev->set_multicast_list = &skfp_ctl_set_multicast_list;
261 dev->set_mac_address = &skfp_ctl_set_mac_address;
262 dev->do_ioctl = &skfp_ioctl;
263 dev->header_cache_update = NULL; /* not supported */
265 SET_MODULE_OWNER(dev);
266 SET_NETDEV_DEV(dev, &pdev->dev);
268 /* Initialize board structure with bus-specific info */
269 smc = netdev_priv(dev);
270 smc->os.dev = dev;
271 smc->os.bus_type = SK_BUS_TYPE_PCI;
272 smc->os.pdev = *pdev;
273 smc->os.QueueSkb = MAX_TX_QUEUE_LEN;
274 smc->os.MaxFrameSize = MAX_FRAME_SIZE;
275 smc->os.dev = dev;
276 smc->hw.slot = -1;
277 smc->hw.iop = mem;
278 smc->os.ResetRequested = FALSE;
279 skb_queue_head_init(&smc->os.SendSkbQueue);
281 dev->base_addr = (unsigned long)mem;
283 err = skfp_driver_init(dev);
284 if (err)
285 goto err_out4;
287 err = register_netdev(dev);
288 if (err)
289 goto err_out5;
291 ++num_boards;
292 pci_set_drvdata(pdev, dev);
294 if ((pdev->subsystem_device & 0xff00) == 0x5500 ||
295 (pdev->subsystem_device & 0xff00) == 0x5800)
296 printk("%s: SysKonnect FDDI PCI adapter"
297 " found (SK-%04X)\n", dev->name,
298 pdev->subsystem_device);
299 else
300 printk("%s: FDDI PCI adapter found\n", dev->name);
302 return 0;
303 err_out5:
304 if (smc->os.SharedMemAddr)
305 pci_free_consistent(pdev, smc->os.SharedMemSize,
306 smc->os.SharedMemAddr,
307 smc->os.SharedMemDMA);
308 pci_free_consistent(pdev, MAX_FRAME_SIZE,
309 smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA);
310 err_out4:
311 free_netdev(dev);
312 err_out3:
313 #ifdef MEM_MAPPED_IO
314 iounmap(mem);
315 #else
316 ioport_unmap(mem);
317 #endif
318 err_out2:
319 pci_release_regions(pdev);
320 err_out1:
321 pci_disable_device(pdev);
322 return err;
326 * Called for each adapter board from pci_unregister_driver
328 static void __devexit skfp_remove_one(struct pci_dev *pdev)
330 struct net_device *p = pci_get_drvdata(pdev);
331 struct s_smc *lp = netdev_priv(p);
333 unregister_netdev(p);
335 if (lp->os.SharedMemAddr) {
336 pci_free_consistent(&lp->os.pdev,
337 lp->os.SharedMemSize,
338 lp->os.SharedMemAddr,
339 lp->os.SharedMemDMA);
340 lp->os.SharedMemAddr = NULL;
342 if (lp->os.LocalRxBuffer) {
343 pci_free_consistent(&lp->os.pdev,
344 MAX_FRAME_SIZE,
345 lp->os.LocalRxBuffer,
346 lp->os.LocalRxBufferDMA);
347 lp->os.LocalRxBuffer = NULL;
349 #ifdef MEM_MAPPED_IO
350 iounmap(lp->hw.iop);
351 #else
352 ioport_unmap(lp->hw.iop);
353 #endif
354 pci_release_regions(pdev);
355 free_netdev(p);
357 pci_disable_device(pdev);
358 pci_set_drvdata(pdev, NULL);
362 * ====================
363 * = skfp_driver_init =
364 * ====================
366 * Overview:
367 * Initializes remaining adapter board structure information
368 * and makes sure adapter is in a safe state prior to skfp_open().
370 * Returns:
371 * Condition code
373 * Arguments:
374 * dev - pointer to device information
376 * Functional Description:
377 * This function allocates additional resources such as the host memory
378 * blocks needed by the adapter.
379 * The adapter is also reset. The OS must call skfp_open() to open
380 * the adapter and bring it on-line.
382 * Return Codes:
383 * 0 - initialization succeeded
384 * -1 - initialization failed
386 static int skfp_driver_init(struct net_device *dev)
388 struct s_smc *smc = netdev_priv(dev);
389 skfddi_priv *bp = &smc->os;
390 int err = -EIO;
392 PRINTK(KERN_INFO "entering skfp_driver_init\n");
394 // set the io address in private structures
395 bp->base_addr = dev->base_addr;
397 // Get the interrupt level from the PCI Configuration Table
398 smc->hw.irq = dev->irq;
400 spin_lock_init(&bp->DriverLock);
402 // Allocate invalid frame
403 bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA);
404 if (!bp->LocalRxBuffer) {
405 printk("could not allocate mem for ");
406 printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
407 goto fail;
410 // Determine the required size of the 'shared' memory area.
411 bp->SharedMemSize = mac_drv_check_space();
412 PRINTK(KERN_INFO "Memory for HWM: %ld\n", bp->SharedMemSize);
413 if (bp->SharedMemSize > 0) {
414 bp->SharedMemSize += 16; // for descriptor alignment
416 bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev,
417 bp->SharedMemSize,
418 &bp->SharedMemDMA);
419 if (!bp->SharedMemSize) {
420 printk("could not allocate mem for ");
421 printk("hardware module: %ld byte\n",
422 bp->SharedMemSize);
423 goto fail;
425 bp->SharedMemHeap = 0; // Nothing used yet.
427 } else {
428 bp->SharedMemAddr = NULL;
429 bp->SharedMemHeap = 0;
430 } // SharedMemSize > 0
432 memset(bp->SharedMemAddr, 0, bp->SharedMemSize);
434 card_stop(smc); // Reset adapter.
436 PRINTK(KERN_INFO "mac_drv_init()..\n");
437 if (mac_drv_init(smc) != 0) {
438 PRINTK(KERN_INFO "mac_drv_init() failed.\n");
439 goto fail;
441 read_address(smc, NULL);
442 PRINTK(KERN_INFO "HW-Addr: %02x %02x %02x %02x %02x %02x\n",
443 smc->hw.fddi_canon_addr.a[0],
444 smc->hw.fddi_canon_addr.a[1],
445 smc->hw.fddi_canon_addr.a[2],
446 smc->hw.fddi_canon_addr.a[3],
447 smc->hw.fddi_canon_addr.a[4],
448 smc->hw.fddi_canon_addr.a[5]);
449 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
451 smt_reset_defaults(smc, 0);
453 return (0);
455 fail:
456 if (bp->SharedMemAddr) {
457 pci_free_consistent(&bp->pdev,
458 bp->SharedMemSize,
459 bp->SharedMemAddr,
460 bp->SharedMemDMA);
461 bp->SharedMemAddr = NULL;
463 if (bp->LocalRxBuffer) {
464 pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE,
465 bp->LocalRxBuffer, bp->LocalRxBufferDMA);
466 bp->LocalRxBuffer = NULL;
468 return err;
469 } // skfp_driver_init
473 * =============
474 * = skfp_open =
475 * =============
477 * Overview:
478 * Opens the adapter
480 * Returns:
481 * Condition code
483 * Arguments:
484 * dev - pointer to device information
486 * Functional Description:
487 * This function brings the adapter to an operational state.
489 * Return Codes:
490 * 0 - Adapter was successfully opened
491 * -EAGAIN - Could not register IRQ
493 static int skfp_open(struct net_device *dev)
495 struct s_smc *smc = netdev_priv(dev);
496 int err;
498 PRINTK(KERN_INFO "entering skfp_open\n");
499 /* Register IRQ - support shared interrupts by passing device ptr */
500 err = request_irq(dev->irq, (void *) skfp_interrupt, IRQF_SHARED,
501 dev->name, dev);
502 if (err)
503 return err;
506 * Set current address to factory MAC address
508 * Note: We've already done this step in skfp_driver_init.
509 * However, it's possible that a user has set a node
510 * address override, then closed and reopened the
511 * adapter. Unless we reset the device address field
512 * now, we'll continue to use the existing modified
513 * address.
515 read_address(smc, NULL);
516 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
518 init_smt(smc, NULL);
519 smt_online(smc, 1);
520 STI_FBI();
522 /* Clear local multicast address tables */
523 mac_clear_multicast(smc);
525 /* Disable promiscuous filter settings */
526 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
528 netif_start_queue(dev);
529 return (0);
530 } // skfp_open
534 * ==============
535 * = skfp_close =
536 * ==============
538 * Overview:
539 * Closes the device/module.
541 * Returns:
542 * Condition code
544 * Arguments:
545 * dev - pointer to device information
547 * Functional Description:
548 * This routine closes the adapter and brings it to a safe state.
549 * The interrupt service routine is deregistered with the OS.
550 * The adapter can be opened again with another call to skfp_open().
552 * Return Codes:
553 * Always return 0.
555 * Assumptions:
556 * No further requests for this adapter are made after this routine is
557 * called. skfp_open() can be called to reset and reinitialize the
558 * adapter.
560 static int skfp_close(struct net_device *dev)
562 struct s_smc *smc = netdev_priv(dev);
563 skfddi_priv *bp = &smc->os;
565 CLI_FBI();
566 smt_reset_defaults(smc, 1);
567 card_stop(smc);
568 mac_drv_clear_tx_queue(smc);
569 mac_drv_clear_rx_queue(smc);
571 netif_stop_queue(dev);
572 /* Deregister (free) IRQ */
573 free_irq(dev->irq, dev);
575 skb_queue_purge(&bp->SendSkbQueue);
576 bp->QueueSkb = MAX_TX_QUEUE_LEN;
578 return (0);
579 } // skfp_close
583 * ==================
584 * = skfp_interrupt =
585 * ==================
587 * Overview:
588 * Interrupt processing routine
590 * Returns:
591 * None
593 * Arguments:
594 * irq - interrupt vector
595 * dev_id - pointer to device information
597 * Functional Description:
598 * This routine calls the interrupt processing routine for this adapter. It
599 * disables and reenables adapter interrupts, as appropriate. We can support
600 * shared interrupts since the incoming dev_id pointer provides our device
601 * structure context. All the real work is done in the hardware module.
603 * Return Codes:
604 * None
606 * Assumptions:
607 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
608 * on Intel-based systems) is done by the operating system outside this
609 * routine.
611 * System interrupts are enabled through this call.
613 * Side Effects:
614 * Interrupts are disabled, then reenabled at the adapter.
617 irqreturn_t skfp_interrupt(int irq, void *dev_id)
619 struct net_device *dev = dev_id;
620 struct s_smc *smc; /* private board structure pointer */
621 skfddi_priv *bp;
623 smc = netdev_priv(dev);
624 bp = &smc->os;
626 // IRQs enabled or disabled ?
627 if (inpd(ADDR(B0_IMSK)) == 0) {
628 // IRQs are disabled: must be shared interrupt
629 return IRQ_NONE;
631 // Note: At this point, IRQs are enabled.
632 if ((inpd(ISR_A) & smc->hw.is_imask) == 0) { // IRQ?
633 // Adapter did not issue an IRQ: must be shared interrupt
634 return IRQ_NONE;
636 CLI_FBI(); // Disable IRQs from our adapter.
637 spin_lock(&bp->DriverLock);
639 // Call interrupt handler in hardware module (HWM).
640 fddi_isr(smc);
642 if (smc->os.ResetRequested) {
643 ResetAdapter(smc);
644 smc->os.ResetRequested = FALSE;
646 spin_unlock(&bp->DriverLock);
647 STI_FBI(); // Enable IRQs from our adapter.
649 return IRQ_HANDLED;
650 } // skfp_interrupt
654 * ======================
655 * = skfp_ctl_get_stats =
656 * ======================
658 * Overview:
659 * Get statistics for FDDI adapter
661 * Returns:
662 * Pointer to FDDI statistics structure
664 * Arguments:
665 * dev - pointer to device information
667 * Functional Description:
668 * Gets current MIB objects from adapter, then
669 * returns FDDI statistics structure as defined
670 * in if_fddi.h.
672 * Note: Since the FDDI statistics structure is
673 * still new and the device structure doesn't
674 * have an FDDI-specific get statistics handler,
675 * we'll return the FDDI statistics structure as
676 * a pointer to an Ethernet statistics structure.
677 * That way, at least the first part of the statistics
678 * structure can be decoded properly.
679 * We'll have to pay attention to this routine as the
680 * device structure becomes more mature and LAN media
681 * independent.
684 struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
686 struct s_smc *bp = netdev_priv(dev);
688 /* Fill the bp->stats structure with driver-maintained counters */
690 bp->os.MacStat.port_bs_flag[0] = 0x1234;
691 bp->os.MacStat.port_bs_flag[1] = 0x5678;
692 // goos: need to fill out fddi statistic
693 #if 0
694 /* Get FDDI SMT MIB objects */
696 /* Fill the bp->stats structure with the SMT MIB object values */
698 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));
699 bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
700 bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
701 bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
702 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));
703 bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
704 bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
705 bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
706 bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
707 bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
708 bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
709 bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
710 bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
711 bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
712 bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
713 bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
714 bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
715 bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
716 bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
717 bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
718 bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
719 bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
720 bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
721 bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
722 bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
723 bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
724 bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
725 bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
726 bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
727 memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
728 memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
729 memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
730 memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
731 bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
732 bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
733 bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
734 memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
735 bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
736 bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
737 bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
738 bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
739 bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
740 bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
741 bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
742 bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
743 bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
744 bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
745 bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
746 bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
747 bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
748 bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
749 bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
750 bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
751 memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
752 bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
753 bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
754 bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
755 bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
756 bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
757 bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
758 bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
759 bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
760 bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
761 bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
762 memcpy(&bp->stats.port_requested_paths[0 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
763 memcpy(&bp->stats.port_requested_paths[1 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
764 bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
765 bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
766 bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
767 bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
768 bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
769 bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
770 bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
771 bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
772 bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
773 bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
774 bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
775 bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
776 bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
777 bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
778 bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
779 bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
780 bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
781 bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
782 bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
783 bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
784 bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
785 bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
786 bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
787 bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
788 bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
789 bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
792 /* Fill the bp->stats structure with the FDDI counter values */
794 bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
795 bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
796 bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
797 bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
798 bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
799 bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
800 bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
801 bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
802 bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
803 bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
804 bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
806 #endif
807 return ((struct net_device_stats *) &bp->os.MacStat);
808 } // ctl_get_stat
812 * ==============================
813 * = skfp_ctl_set_multicast_list =
814 * ==============================
816 * Overview:
817 * Enable/Disable LLC frame promiscuous mode reception
818 * on the adapter and/or update multicast address table.
820 * Returns:
821 * None
823 * Arguments:
824 * dev - pointer to device information
826 * Functional Description:
827 * This function acquires the driver lock and only calls
828 * skfp_ctl_set_multicast_list_wo_lock then.
829 * This routine follows a fairly simple algorithm for setting the
830 * adapter filters and CAM:
832 * if IFF_PROMISC flag is set
833 * enable promiscuous mode
834 * else
835 * disable promiscuous mode
836 * if number of multicast addresses <= max. multicast number
837 * add mc addresses to adapter table
838 * else
839 * enable promiscuous mode
840 * update adapter filters
842 * Assumptions:
843 * Multicast addresses are presented in canonical (LSB) format.
845 * Side Effects:
846 * On-board adapter filters are updated.
848 static void skfp_ctl_set_multicast_list(struct net_device *dev)
850 struct s_smc *smc = netdev_priv(dev);
851 skfddi_priv *bp = &smc->os;
852 unsigned long Flags;
854 spin_lock_irqsave(&bp->DriverLock, Flags);
855 skfp_ctl_set_multicast_list_wo_lock(dev);
856 spin_unlock_irqrestore(&bp->DriverLock, Flags);
857 return;
858 } // skfp_ctl_set_multicast_list
862 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
864 struct s_smc *smc = netdev_priv(dev);
865 struct dev_mc_list *dmi; /* ptr to multicast addr entry */
866 int i;
868 /* Enable promiscuous mode, if necessary */
869 if (dev->flags & IFF_PROMISC) {
870 mac_drv_rx_mode(smc, RX_ENABLE_PROMISC);
871 PRINTK(KERN_INFO "PROMISCUOUS MODE ENABLED\n");
873 /* Else, update multicast address table */
874 else {
875 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
876 PRINTK(KERN_INFO "PROMISCUOUS MODE DISABLED\n");
878 // Reset all MC addresses
879 mac_clear_multicast(smc);
880 mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI);
882 if (dev->flags & IFF_ALLMULTI) {
883 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
884 PRINTK(KERN_INFO "ENABLE ALL MC ADDRESSES\n");
885 } else if (dev->mc_count > 0) {
886 if (dev->mc_count <= FPMAX_MULTICAST) {
887 /* use exact filtering */
889 // point to first multicast addr
890 dmi = dev->mc_list;
892 for (i = 0; i < dev->mc_count; i++) {
893 mac_add_multicast(smc,
894 (struct fddi_addr *)dmi->dmi_addr,
897 PRINTK(KERN_INFO "ENABLE MC ADDRESS:");
898 PRINTK(" %02x %02x %02x ",
899 dmi->dmi_addr[0],
900 dmi->dmi_addr[1],
901 dmi->dmi_addr[2]);
902 PRINTK("%02x %02x %02x\n",
903 dmi->dmi_addr[3],
904 dmi->dmi_addr[4],
905 dmi->dmi_addr[5]);
906 dmi = dmi->next;
907 } // for
909 } else { // more MC addresses than HW supports
911 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
912 PRINTK(KERN_INFO "ENABLE ALL MC ADDRESSES\n");
914 } else { // no MC addresses
916 PRINTK(KERN_INFO "DISABLE ALL MC ADDRESSES\n");
919 /* Update adapter filters */
920 mac_update_multicast(smc);
922 return;
923 } // skfp_ctl_set_multicast_list_wo_lock
927 * ===========================
928 * = skfp_ctl_set_mac_address =
929 * ===========================
931 * Overview:
932 * set new mac address on adapter and update dev_addr field in device table.
934 * Returns:
935 * None
937 * Arguments:
938 * dev - pointer to device information
939 * addr - pointer to sockaddr structure containing unicast address to set
941 * Assumptions:
942 * The address pointed to by addr->sa_data is a valid unicast
943 * address and is presented in canonical (LSB) format.
945 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
947 struct s_smc *smc = netdev_priv(dev);
948 struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
949 skfddi_priv *bp = &smc->os;
950 unsigned long Flags;
953 memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);
954 spin_lock_irqsave(&bp->DriverLock, Flags);
955 ResetAdapter(smc);
956 spin_unlock_irqrestore(&bp->DriverLock, Flags);
958 return (0); /* always return zero */
959 } // skfp_ctl_set_mac_address
963 * ==============
964 * = skfp_ioctl =
965 * ==============
967 * Overview:
969 * Perform IOCTL call functions here. Some are privileged operations and the
970 * effective uid is checked in those cases.
972 * Returns:
973 * status value
974 * 0 - success
975 * other - failure
977 * Arguments:
978 * dev - pointer to device information
979 * rq - pointer to ioctl request structure
980 * cmd - ?
985 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
987 struct s_smc *smc = netdev_priv(dev);
988 skfddi_priv *lp = &smc->os;
989 struct s_skfp_ioctl ioc;
990 int status = 0;
992 if (copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl)))
993 return -EFAULT;
995 switch (ioc.cmd) {
996 case SKFP_GET_STATS: /* Get the driver statistics */
997 ioc.len = sizeof(lp->MacStat);
998 status = copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len)
999 ? -EFAULT : 0;
1000 break;
1001 case SKFP_CLR_STATS: /* Zero out the driver statistics */
1002 if (!capable(CAP_NET_ADMIN)) {
1003 memset(&lp->MacStat, 0, sizeof(lp->MacStat));
1004 } else {
1005 status = -EPERM;
1007 break;
1008 default:
1009 printk("ioctl for %s: unknow cmd: %04x\n", dev->name, ioc.cmd);
1010 status = -EOPNOTSUPP;
1012 } // switch
1014 return status;
1015 } // skfp_ioctl
1019 * =====================
1020 * = skfp_send_pkt =
1021 * =====================
1023 * Overview:
1024 * Queues a packet for transmission and try to transmit it.
1026 * Returns:
1027 * Condition code
1029 * Arguments:
1030 * skb - pointer to sk_buff to queue for transmission
1031 * dev - pointer to device information
1033 * Functional Description:
1034 * Here we assume that an incoming skb transmit request
1035 * is contained in a single physically contiguous buffer
1036 * in which the virtual address of the start of packet
1037 * (skb->data) can be converted to a physical address
1038 * by using pci_map_single().
1040 * We have an internal queue for packets we can not send
1041 * immediately. Packets in this queue can be given to the
1042 * adapter if transmit buffers are freed.
1044 * We can't free the skb until after it's been DMA'd
1045 * out by the adapter, so we'll keep it in the driver and
1046 * return it in mac_drv_tx_complete.
1048 * Return Codes:
1049 * 0 - driver has queued and/or sent packet
1050 * 1 - caller should requeue the sk_buff for later transmission
1052 * Assumptions:
1053 * The entire packet is stored in one physically
1054 * contiguous buffer which is not cached and whose
1055 * 32-bit physical address can be determined.
1057 * It's vital that this routine is NOT reentered for the
1058 * same board and that the OS is not in another section of
1059 * code (eg. skfp_interrupt) for the same board on a
1060 * different thread.
1062 * Side Effects:
1063 * None
1065 static int skfp_send_pkt(struct sk_buff *skb, struct net_device *dev)
1067 struct s_smc *smc = netdev_priv(dev);
1068 skfddi_priv *bp = &smc->os;
1070 PRINTK(KERN_INFO "skfp_send_pkt\n");
1073 * Verify that incoming transmit request is OK
1075 * Note: The packet size check is consistent with other
1076 * Linux device drivers, although the correct packet
1077 * size should be verified before calling the
1078 * transmit routine.
1081 if (!(skb->len >= FDDI_K_LLC_ZLEN && skb->len <= FDDI_K_LLC_LEN)) {
1082 bp->MacStat.gen.tx_errors++; /* bump error counter */
1083 // dequeue packets from xmt queue and send them
1084 netif_start_queue(dev);
1085 dev_kfree_skb(skb);
1086 return (0); /* return "success" */
1088 if (bp->QueueSkb == 0) { // return with tbusy set: queue full
1090 netif_stop_queue(dev);
1091 return 1;
1093 bp->QueueSkb--;
1094 skb_queue_tail(&bp->SendSkbQueue, skb);
1095 send_queued_packets(netdev_priv(dev));
1096 if (bp->QueueSkb == 0) {
1097 netif_stop_queue(dev);
1099 dev->trans_start = jiffies;
1100 return 0;
1102 } // skfp_send_pkt
1106 * =======================
1107 * = send_queued_packets =
1108 * =======================
1110 * Overview:
1111 * Send packets from the driver queue as long as there are some and
1112 * transmit resources are available.
1114 * Returns:
1115 * None
1117 * Arguments:
1118 * smc - pointer to smc (adapter) structure
1120 * Functional Description:
1121 * Take a packet from queue if there is any. If not, then we are done.
1122 * Check if there are resources to send the packet. If not, requeue it
1123 * and exit.
1124 * Set packet descriptor flags and give packet to adapter.
1125 * Check if any send resources can be freed (we do not use the
1126 * transmit complete interrupt).
1128 static void send_queued_packets(struct s_smc *smc)
1130 skfddi_priv *bp = &smc->os;
1131 struct sk_buff *skb;
1132 unsigned char fc;
1133 int queue;
1134 struct s_smt_fp_txd *txd; // Current TxD.
1135 dma_addr_t dma_address;
1136 unsigned long Flags;
1138 int frame_status; // HWM tx frame status.
1140 PRINTK(KERN_INFO "send queued packets\n");
1141 for (;;) {
1142 // send first buffer from queue
1143 skb = skb_dequeue(&bp->SendSkbQueue);
1145 if (!skb) {
1146 PRINTK(KERN_INFO "queue empty\n");
1147 return;
1148 } // queue empty !
1150 spin_lock_irqsave(&bp->DriverLock, Flags);
1151 fc = skb->data[0];
1152 queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0;
1153 #ifdef ESS
1154 // Check if the frame may/must be sent as a synchronous frame.
1156 if ((fc & ~(FC_SYNC_BIT | FC_LLC_PRIOR)) == FC_ASYNC_LLC) {
1157 // It's an LLC frame.
1158 if (!smc->ess.sync_bw_available)
1159 fc &= ~FC_SYNC_BIT; // No bandwidth available.
1161 else { // Bandwidth is available.
1163 if (smc->mib.fddiESSSynchTxMode) {
1164 // Send as sync. frame.
1165 fc |= FC_SYNC_BIT;
1169 #endif // ESS
1170 frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue);
1172 if ((frame_status & (LOC_TX | LAN_TX)) == 0) {
1173 // Unable to send the frame.
1175 if ((frame_status & RING_DOWN) != 0) {
1176 // Ring is down.
1177 PRINTK("Tx attempt while ring down.\n");
1178 } else if ((frame_status & OUT_OF_TXD) != 0) {
1179 PRINTK("%s: out of TXDs.\n", bp->dev->name);
1180 } else {
1181 PRINTK("%s: out of transmit resources",
1182 bp->dev->name);
1185 // Note: We will retry the operation as soon as
1186 // transmit resources become available.
1187 skb_queue_head(&bp->SendSkbQueue, skb);
1188 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1189 return; // Packet has been queued.
1191 } // if (unable to send frame)
1193 bp->QueueSkb++; // one packet less in local queue
1195 // source address in packet ?
1196 CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a);
1198 txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue);
1200 dma_address = pci_map_single(&bp->pdev, skb->data,
1201 skb->len, PCI_DMA_TODEVICE);
1202 if (frame_status & LAN_TX) {
1203 txd->txd_os.skb = skb; // save skb
1204 txd->txd_os.dma_addr = dma_address; // save dma mapping
1206 hwm_tx_frag(smc, skb->data, dma_address, skb->len,
1207 frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF);
1209 if (!(frame_status & LAN_TX)) { // local only frame
1210 pci_unmap_single(&bp->pdev, dma_address,
1211 skb->len, PCI_DMA_TODEVICE);
1212 dev_kfree_skb_irq(skb);
1214 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1215 } // for
1217 return; // never reached
1219 } // send_queued_packets
1222 /************************
1224 * CheckSourceAddress
1226 * Verify if the source address is set. Insert it if necessary.
1228 ************************/
1229 void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr)
1231 unsigned char SRBit;
1233 if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0) // source routing bit
1235 return;
1236 if ((unsigned short) frame[1 + 10] != 0)
1237 return;
1238 SRBit = frame[1 + 6] & 0x01;
1239 memcpy(&frame[1 + 6], hw_addr, 6);
1240 frame[8] |= SRBit;
1241 } // CheckSourceAddress
1244 /************************
1246 * ResetAdapter
1248 * Reset the adapter and bring it back to operational mode.
1249 * Args
1250 * smc - A pointer to the SMT context struct.
1251 * Out
1252 * Nothing.
1254 ************************/
1255 static void ResetAdapter(struct s_smc *smc)
1258 PRINTK(KERN_INFO "[fddi: ResetAdapter]\n");
1260 // Stop the adapter.
1262 card_stop(smc); // Stop all activity.
1264 // Clear the transmit and receive descriptor queues.
1265 mac_drv_clear_tx_queue(smc);
1266 mac_drv_clear_rx_queue(smc);
1268 // Restart the adapter.
1270 smt_reset_defaults(smc, 1); // Initialize the SMT module.
1272 init_smt(smc, (smc->os.dev)->dev_addr); // Initialize the hardware.
1274 smt_online(smc, 1); // Insert into the ring again.
1275 STI_FBI();
1277 // Restore original receive mode (multicasts, promiscuous, etc.).
1278 skfp_ctl_set_multicast_list_wo_lock(smc->os.dev);
1279 } // ResetAdapter
1282 //--------------- functions called by hardware module ----------------
1284 /************************
1286 * llc_restart_tx
1288 * The hardware driver calls this routine when the transmit complete
1289 * interrupt bits (end of frame) for the synchronous or asynchronous
1290 * queue is set.
1292 * NOTE The hardware driver calls this function also if no packets are queued.
1293 * The routine must be able to handle this case.
1294 * Args
1295 * smc - A pointer to the SMT context struct.
1296 * Out
1297 * Nothing.
1299 ************************/
1300 void llc_restart_tx(struct s_smc *smc)
1302 skfddi_priv *bp = &smc->os;
1304 PRINTK(KERN_INFO "[llc_restart_tx]\n");
1306 // Try to send queued packets
1307 spin_unlock(&bp->DriverLock);
1308 send_queued_packets(smc);
1309 spin_lock(&bp->DriverLock);
1310 netif_start_queue(bp->dev);// system may send again if it was blocked
1312 } // llc_restart_tx
1315 /************************
1317 * mac_drv_get_space
1319 * The hardware module calls this function to allocate the memory
1320 * for the SMT MBufs if the define MB_OUTSIDE_SMC is specified.
1321 * Args
1322 * smc - A pointer to the SMT context struct.
1324 * size - Size of memory in bytes to allocate.
1325 * Out
1326 * != 0 A pointer to the virtual address of the allocated memory.
1327 * == 0 Allocation error.
1329 ************************/
1330 void *mac_drv_get_space(struct s_smc *smc, unsigned int size)
1332 void *virt;
1334 PRINTK(KERN_INFO "mac_drv_get_space (%d bytes), ", size);
1335 virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap);
1337 if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) {
1338 printk("Unexpected SMT memory size requested: %d\n", size);
1339 return (NULL);
1341 smc->os.SharedMemHeap += size; // Move heap pointer.
1343 PRINTK(KERN_INFO "mac_drv_get_space end\n");
1344 PRINTK(KERN_INFO "virt addr: %lx\n", (ulong) virt);
1345 PRINTK(KERN_INFO "bus addr: %lx\n", (ulong)
1346 (smc->os.SharedMemDMA +
1347 ((char *) virt - (char *)smc->os.SharedMemAddr)));
1348 return (virt);
1349 } // mac_drv_get_space
1352 /************************
1354 * mac_drv_get_desc_mem
1356 * This function is called by the hardware dependent module.
1357 * It allocates the memory for the RxD and TxD descriptors.
1359 * This memory must be non-cached, non-movable and non-swappable.
1360 * This memory should start at a physical page boundary.
1361 * Args
1362 * smc - A pointer to the SMT context struct.
1364 * size - Size of memory in bytes to allocate.
1365 * Out
1366 * != 0 A pointer to the virtual address of the allocated memory.
1367 * == 0 Allocation error.
1369 ************************/
1370 void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size)
1373 char *virt;
1375 PRINTK(KERN_INFO "mac_drv_get_desc_mem\n");
1377 // Descriptor memory must be aligned on 16-byte boundary.
1379 virt = mac_drv_get_space(smc, size);
1381 size = (u_int) (16 - (((unsigned long) virt) & 15UL));
1382 size = size % 16;
1384 PRINTK("Allocate %u bytes alignment gap ", size);
1385 PRINTK("for descriptor memory.\n");
1387 if (!mac_drv_get_space(smc, size)) {
1388 printk("fddi: Unable to align descriptor memory.\n");
1389 return (NULL);
1391 return (virt + size);
1392 } // mac_drv_get_desc_mem
1395 /************************
1397 * mac_drv_virt2phys
1399 * Get the physical address of a given virtual address.
1400 * Args
1401 * smc - A pointer to the SMT context struct.
1403 * virt - A (virtual) pointer into our 'shared' memory area.
1404 * Out
1405 * Physical address of the given virtual address.
1407 ************************/
1408 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt)
1410 return (smc->os.SharedMemDMA +
1411 ((char *) virt - (char *)smc->os.SharedMemAddr));
1412 } // mac_drv_virt2phys
1415 /************************
1417 * dma_master
1419 * The HWM calls this function, when the driver leads through a DMA
1420 * transfer. If the OS-specific module must prepare the system hardware
1421 * for the DMA transfer, it should do it in this function.
1423 * The hardware module calls this dma_master if it wants to send an SMT
1424 * frame. This means that the virt address passed in here is part of
1425 * the 'shared' memory area.
1426 * Args
1427 * smc - A pointer to the SMT context struct.
1429 * virt - The virtual address of the data.
1431 * len - The length in bytes of the data.
1433 * flag - Indicates the transmit direction and the buffer type:
1434 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1435 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1436 * SMT_BUF (0x80) SMT buffer
1438 * >> NOTE: SMT_BUF and DMA_RD are always set for PCI. <<
1439 * Out
1440 * Returns the pyhsical address for the DMA transfer.
1442 ************************/
1443 u_long dma_master(struct s_smc * smc, void *virt, int len, int flag)
1445 return (smc->os.SharedMemDMA +
1446 ((char *) virt - (char *)smc->os.SharedMemAddr));
1447 } // dma_master
1450 /************************
1452 * dma_complete
1454 * The hardware module calls this routine when it has completed a DMA
1455 * transfer. If the operating system dependent module has set up the DMA
1456 * channel via dma_master() (e.g. Windows NT or AIX) it should clean up
1457 * the DMA channel.
1458 * Args
1459 * smc - A pointer to the SMT context struct.
1461 * descr - A pointer to a TxD or RxD, respectively.
1463 * flag - Indicates the DMA transfer direction / SMT buffer:
1464 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1465 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1466 * SMT_BUF (0x80) SMT buffer (managed by HWM)
1467 * Out
1468 * Nothing.
1470 ************************/
1471 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag)
1473 /* For TX buffers, there are two cases. If it is an SMT transmit
1474 * buffer, there is nothing to do since we use consistent memory
1475 * for the 'shared' memory area. The other case is for normal
1476 * transmit packets given to us by the networking stack, and in
1477 * that case we cleanup the PCI DMA mapping in mac_drv_tx_complete
1478 * below.
1480 * For RX buffers, we have to unmap dynamic PCI DMA mappings here
1481 * because the hardware module is about to potentially look at
1482 * the contents of the buffer. If we did not call the PCI DMA
1483 * unmap first, the hardware module could read inconsistent data.
1485 if (flag & DMA_WR) {
1486 skfddi_priv *bp = &smc->os;
1487 volatile struct s_smt_fp_rxd *r = &descr->r;
1489 /* If SKB is NULL, we used the local buffer. */
1490 if (r->rxd_os.skb && r->rxd_os.dma_addr) {
1491 int MaxFrameSize = bp->MaxFrameSize;
1493 pci_unmap_single(&bp->pdev, r->rxd_os.dma_addr,
1494 MaxFrameSize, PCI_DMA_FROMDEVICE);
1495 r->rxd_os.dma_addr = 0;
1498 } // dma_complete
1501 /************************
1503 * mac_drv_tx_complete
1505 * Transmit of a packet is complete. Release the tx staging buffer.
1507 * Args
1508 * smc - A pointer to the SMT context struct.
1510 * txd - A pointer to the last TxD which is used by the frame.
1511 * Out
1512 * Returns nothing.
1514 ************************/
1515 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
1517 struct sk_buff *skb;
1519 PRINTK(KERN_INFO "entering mac_drv_tx_complete\n");
1520 // Check if this TxD points to a skb
1522 if (!(skb = txd->txd_os.skb)) {
1523 PRINTK("TXD with no skb assigned.\n");
1524 return;
1526 txd->txd_os.skb = NULL;
1528 // release the DMA mapping
1529 pci_unmap_single(&smc->os.pdev, txd->txd_os.dma_addr,
1530 skb->len, PCI_DMA_TODEVICE);
1531 txd->txd_os.dma_addr = 0;
1533 smc->os.MacStat.gen.tx_packets++; // Count transmitted packets.
1534 smc->os.MacStat.gen.tx_bytes+=skb->len; // Count bytes
1536 // free the skb
1537 dev_kfree_skb_irq(skb);
1539 PRINTK(KERN_INFO "leaving mac_drv_tx_complete\n");
1540 } // mac_drv_tx_complete
1543 /************************
1545 * dump packets to logfile
1547 ************************/
1548 #ifdef DUMPPACKETS
1549 void dump_data(unsigned char *Data, int length)
1551 int i, j;
1552 unsigned char s[255], sh[10];
1553 if (length > 64) {
1554 length = 64;
1556 printk(KERN_INFO "---Packet start---\n");
1557 for (i = 0, j = 0; i < length / 8; i++, j += 8)
1558 printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\n",
1559 Data[j + 0], Data[j + 1], Data[j + 2], Data[j + 3],
1560 Data[j + 4], Data[j + 5], Data[j + 6], Data[j + 7]);
1561 strcpy(s, "");
1562 for (i = 0; i < length % 8; i++) {
1563 sprintf(sh, "%02x ", Data[j + i]);
1564 strcat(s, sh);
1566 printk(KERN_INFO "%s\n", s);
1567 printk(KERN_INFO "------------------\n");
1568 } // dump_data
1569 #else
1570 #define dump_data(data,len)
1571 #endif // DUMPPACKETS
1573 /************************
1575 * mac_drv_rx_complete
1577 * The hardware module calls this function if an LLC frame is received
1578 * in a receive buffer. Also the SMT, NSA, and directed beacon frames
1579 * from the network will be passed to the LLC layer by this function
1580 * if passing is enabled.
1582 * mac_drv_rx_complete forwards the frame to the LLC layer if it should
1583 * be received. It also fills the RxD ring with new receive buffers if
1584 * some can be queued.
1585 * Args
1586 * smc - A pointer to the SMT context struct.
1588 * rxd - A pointer to the first RxD which is used by the receive frame.
1590 * frag_count - Count of RxDs used by the received frame.
1592 * len - Frame length.
1593 * Out
1594 * Nothing.
1596 ************************/
1597 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1598 int frag_count, int len)
1600 skfddi_priv *bp = &smc->os;
1601 struct sk_buff *skb;
1602 unsigned char *virt, *cp;
1603 unsigned short ri;
1604 u_int RifLength;
1606 PRINTK(KERN_INFO "entering mac_drv_rx_complete (len=%d)\n", len);
1607 if (frag_count != 1) { // This is not allowed to happen.
1609 printk("fddi: Multi-fragment receive!\n");
1610 goto RequeueRxd; // Re-use the given RXD(s).
1613 skb = rxd->rxd_os.skb;
1614 if (!skb) {
1615 PRINTK(KERN_INFO "No skb in rxd\n");
1616 smc->os.MacStat.gen.rx_errors++;
1617 goto RequeueRxd;
1619 virt = skb->data;
1621 // The DMA mapping was released in dma_complete above.
1623 dump_data(skb->data, len);
1626 * FDDI Frame format:
1627 * +-------+-------+-------+------------+--------+------------+
1628 * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] |
1629 * +-------+-------+-------+------------+--------+------------+
1631 * FC = Frame Control
1632 * DA = Destination Address
1633 * SA = Source Address
1634 * RIF = Routing Information Field
1635 * LLC = Logical Link Control
1638 // Remove Routing Information Field (RIF), if present.
1640 if ((virt[1 + 6] & FDDI_RII) == 0)
1641 RifLength = 0;
1642 else {
1643 int n;
1644 // goos: RIF removal has still to be tested
1645 PRINTK(KERN_INFO "RIF found\n");
1646 // Get RIF length from Routing Control (RC) field.
1647 cp = virt + FDDI_MAC_HDR_LEN; // Point behind MAC header.
1649 ri = ntohs(*((unsigned short *) cp));
1650 RifLength = ri & FDDI_RCF_LEN_MASK;
1651 if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) {
1652 printk("fddi: Invalid RIF.\n");
1653 goto RequeueRxd; // Discard the frame.
1656 virt[1 + 6] &= ~FDDI_RII; // Clear RII bit.
1657 // regions overlap
1659 virt = cp + RifLength;
1660 for (n = FDDI_MAC_HDR_LEN; n; n--)
1661 *--virt = *--cp;
1662 // adjust sbd->data pointer
1663 skb_pull(skb, RifLength);
1664 len -= RifLength;
1665 RifLength = 0;
1668 // Count statistics.
1669 smc->os.MacStat.gen.rx_packets++; // Count indicated receive
1670 // packets.
1671 smc->os.MacStat.gen.rx_bytes+=len; // Count bytes.
1673 // virt points to header again
1674 if (virt[1] & 0x01) { // Check group (multicast) bit.
1676 smc->os.MacStat.gen.multicast++;
1679 // deliver frame to system
1680 rxd->rxd_os.skb = NULL;
1681 skb_trim(skb, len);
1682 skb->protocol = fddi_type_trans(skb, bp->dev);
1684 netif_rx(skb);
1685 bp->dev->last_rx = jiffies;
1687 HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
1688 return;
1690 RequeueRxd:
1691 PRINTK(KERN_INFO "Rx: re-queue RXD.\n");
1692 mac_drv_requeue_rxd(smc, rxd, frag_count);
1693 smc->os.MacStat.gen.rx_errors++; // Count receive packets
1694 // not indicated.
1696 } // mac_drv_rx_complete
1699 /************************
1701 * mac_drv_requeue_rxd
1703 * The hardware module calls this function to request the OS-specific
1704 * module to queue the receive buffer(s) represented by the pointer
1705 * to the RxD and the frag_count into the receive queue again. This
1706 * buffer was filled with an invalid frame or an SMT frame.
1707 * Args
1708 * smc - A pointer to the SMT context struct.
1710 * rxd - A pointer to the first RxD which is used by the receive frame.
1712 * frag_count - Count of RxDs used by the received frame.
1713 * Out
1714 * Nothing.
1716 ************************/
1717 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1718 int frag_count)
1720 volatile struct s_smt_fp_rxd *next_rxd;
1721 volatile struct s_smt_fp_rxd *src_rxd;
1722 struct sk_buff *skb;
1723 int MaxFrameSize;
1724 unsigned char *v_addr;
1725 dma_addr_t b_addr;
1727 if (frag_count != 1) // This is not allowed to happen.
1729 printk("fddi: Multi-fragment requeue!\n");
1731 MaxFrameSize = smc->os.MaxFrameSize;
1732 src_rxd = rxd;
1733 for (; frag_count > 0; frag_count--) {
1734 next_rxd = src_rxd->rxd_next;
1735 rxd = HWM_GET_CURR_RXD(smc);
1737 skb = src_rxd->rxd_os.skb;
1738 if (skb == NULL) { // this should not happen
1740 PRINTK("Requeue with no skb in rxd!\n");
1741 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1742 if (skb) {
1743 // we got a skb
1744 rxd->rxd_os.skb = skb;
1745 skb_reserve(skb, 3);
1746 skb_put(skb, MaxFrameSize);
1747 v_addr = skb->data;
1748 b_addr = pci_map_single(&smc->os.pdev,
1749 v_addr,
1750 MaxFrameSize,
1751 PCI_DMA_FROMDEVICE);
1752 rxd->rxd_os.dma_addr = b_addr;
1753 } else {
1754 // no skb available, use local buffer
1755 PRINTK("Queueing invalid buffer!\n");
1756 rxd->rxd_os.skb = NULL;
1757 v_addr = smc->os.LocalRxBuffer;
1758 b_addr = smc->os.LocalRxBufferDMA;
1760 } else {
1761 // we use skb from old rxd
1762 rxd->rxd_os.skb = skb;
1763 v_addr = skb->data;
1764 b_addr = pci_map_single(&smc->os.pdev,
1765 v_addr,
1766 MaxFrameSize,
1767 PCI_DMA_FROMDEVICE);
1768 rxd->rxd_os.dma_addr = b_addr;
1770 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1771 FIRST_FRAG | LAST_FRAG);
1773 src_rxd = next_rxd;
1775 } // mac_drv_requeue_rxd
1778 /************************
1780 * mac_drv_fill_rxd
1782 * The hardware module calls this function at initialization time
1783 * to fill the RxD ring with receive buffers. It is also called by
1784 * mac_drv_rx_complete if rx_free is large enough to queue some new
1785 * receive buffers into the RxD ring. mac_drv_fill_rxd queues new
1786 * receive buffers as long as enough RxDs and receive buffers are
1787 * available.
1788 * Args
1789 * smc - A pointer to the SMT context struct.
1790 * Out
1791 * Nothing.
1793 ************************/
1794 void mac_drv_fill_rxd(struct s_smc *smc)
1796 int MaxFrameSize;
1797 unsigned char *v_addr;
1798 unsigned long b_addr;
1799 struct sk_buff *skb;
1800 volatile struct s_smt_fp_rxd *rxd;
1802 PRINTK(KERN_INFO "entering mac_drv_fill_rxd\n");
1804 // Walk through the list of free receive buffers, passing receive
1805 // buffers to the HWM as long as RXDs are available.
1807 MaxFrameSize = smc->os.MaxFrameSize;
1808 // Check if there is any RXD left.
1809 while (HWM_GET_RX_FREE(smc) > 0) {
1810 PRINTK(KERN_INFO ".\n");
1812 rxd = HWM_GET_CURR_RXD(smc);
1813 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1814 if (skb) {
1815 // we got a skb
1816 skb_reserve(skb, 3);
1817 skb_put(skb, MaxFrameSize);
1818 v_addr = skb->data;
1819 b_addr = pci_map_single(&smc->os.pdev,
1820 v_addr,
1821 MaxFrameSize,
1822 PCI_DMA_FROMDEVICE);
1823 rxd->rxd_os.dma_addr = b_addr;
1824 } else {
1825 // no skb available, use local buffer
1826 // System has run out of buffer memory, but we want to
1827 // keep the receiver running in hope of better times.
1828 // Multiple descriptors may point to this local buffer,
1829 // so data in it must be considered invalid.
1830 PRINTK("Queueing invalid buffer!\n");
1831 v_addr = smc->os.LocalRxBuffer;
1832 b_addr = smc->os.LocalRxBufferDMA;
1835 rxd->rxd_os.skb = skb;
1837 // Pass receive buffer to HWM.
1838 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1839 FIRST_FRAG | LAST_FRAG);
1841 PRINTK(KERN_INFO "leaving mac_drv_fill_rxd\n");
1842 } // mac_drv_fill_rxd
1845 /************************
1847 * mac_drv_clear_rxd
1849 * The hardware module calls this function to release unused
1850 * receive buffers.
1851 * Args
1852 * smc - A pointer to the SMT context struct.
1854 * rxd - A pointer to the first RxD which is used by the receive buffer.
1856 * frag_count - Count of RxDs used by the receive buffer.
1857 * Out
1858 * Nothing.
1860 ************************/
1861 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1862 int frag_count)
1865 struct sk_buff *skb;
1867 PRINTK("entering mac_drv_clear_rxd\n");
1869 if (frag_count != 1) // This is not allowed to happen.
1871 printk("fddi: Multi-fragment clear!\n");
1873 for (; frag_count > 0; frag_count--) {
1874 skb = rxd->rxd_os.skb;
1875 if (skb != NULL) {
1876 skfddi_priv *bp = &smc->os;
1877 int MaxFrameSize = bp->MaxFrameSize;
1879 pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr,
1880 MaxFrameSize, PCI_DMA_FROMDEVICE);
1882 dev_kfree_skb(skb);
1883 rxd->rxd_os.skb = NULL;
1885 rxd = rxd->rxd_next; // Next RXD.
1888 } // mac_drv_clear_rxd
1891 /************************
1893 * mac_drv_rx_init
1895 * The hardware module calls this routine when an SMT or NSA frame of the
1896 * local SMT should be delivered to the LLC layer.
1898 * It is necessary to have this function, because there is no other way to
1899 * copy the contents of SMT MBufs into receive buffers.
1901 * mac_drv_rx_init allocates the required target memory for this frame,
1902 * and receives the frame fragment by fragment by calling mac_drv_rx_frag.
1903 * Args
1904 * smc - A pointer to the SMT context struct.
1906 * len - The length (in bytes) of the received frame (FC, DA, SA, Data).
1908 * fc - The Frame Control field of the received frame.
1910 * look_ahead - A pointer to the lookahead data buffer (may be NULL).
1912 * la_len - The length of the lookahead data stored in the lookahead
1913 * buffer (may be zero).
1914 * Out
1915 * Always returns zero (0).
1917 ************************/
1918 int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
1919 char *look_ahead, int la_len)
1921 struct sk_buff *skb;
1923 PRINTK("entering mac_drv_rx_init(len=%d)\n", len);
1925 // "Received" a SMT or NSA frame of the local SMT.
1927 if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) {
1928 PRINTK("fddi: Discard invalid local SMT frame\n");
1929 PRINTK(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n",
1930 len, la_len, (unsigned long) look_ahead);
1931 return (0);
1933 skb = alloc_skb(len + 3, GFP_ATOMIC);
1934 if (!skb) {
1935 PRINTK("fddi: Local SMT: skb memory exhausted.\n");
1936 return (0);
1938 skb_reserve(skb, 3);
1939 skb_put(skb, len);
1940 skb_copy_to_linear_data(skb, look_ahead, len);
1942 // deliver frame to system
1943 skb->protocol = fddi_type_trans(skb, smc->os.dev);
1944 skb->dev->last_rx = jiffies;
1945 netif_rx(skb);
1947 return (0);
1948 } // mac_drv_rx_init
1951 /************************
1953 * smt_timer_poll
1955 * This routine is called periodically by the SMT module to clean up the
1956 * driver.
1958 * Return any queued frames back to the upper protocol layers if the ring
1959 * is down.
1960 * Args
1961 * smc - A pointer to the SMT context struct.
1962 * Out
1963 * Nothing.
1965 ************************/
1966 void smt_timer_poll(struct s_smc *smc)
1968 } // smt_timer_poll
1971 /************************
1973 * ring_status_indication
1975 * This function indicates a change of the ring state.
1976 * Args
1977 * smc - A pointer to the SMT context struct.
1979 * status - The current ring status.
1980 * Out
1981 * Nothing.
1983 ************************/
1984 void ring_status_indication(struct s_smc *smc, u_long status)
1986 PRINTK("ring_status_indication( ");
1987 if (status & RS_RES15)
1988 PRINTK("RS_RES15 ");
1989 if (status & RS_HARDERROR)
1990 PRINTK("RS_HARDERROR ");
1991 if (status & RS_SOFTERROR)
1992 PRINTK("RS_SOFTERROR ");
1993 if (status & RS_BEACON)
1994 PRINTK("RS_BEACON ");
1995 if (status & RS_PATHTEST)
1996 PRINTK("RS_PATHTEST ");
1997 if (status & RS_SELFTEST)
1998 PRINTK("RS_SELFTEST ");
1999 if (status & RS_RES9)
2000 PRINTK("RS_RES9 ");
2001 if (status & RS_DISCONNECT)
2002 PRINTK("RS_DISCONNECT ");
2003 if (status & RS_RES7)
2004 PRINTK("RS_RES7 ");
2005 if (status & RS_DUPADDR)
2006 PRINTK("RS_DUPADDR ");
2007 if (status & RS_NORINGOP)
2008 PRINTK("RS_NORINGOP ");
2009 if (status & RS_VERSION)
2010 PRINTK("RS_VERSION ");
2011 if (status & RS_STUCKBYPASSS)
2012 PRINTK("RS_STUCKBYPASSS ");
2013 if (status & RS_EVENT)
2014 PRINTK("RS_EVENT ");
2015 if (status & RS_RINGOPCHANGE)
2016 PRINTK("RS_RINGOPCHANGE ");
2017 if (status & RS_RES0)
2018 PRINTK("RS_RES0 ");
2019 PRINTK("]\n");
2020 } // ring_status_indication
2023 /************************
2025 * smt_get_time
2027 * Gets the current time from the system.
2028 * Args
2029 * None.
2030 * Out
2031 * The current time in TICKS_PER_SECOND.
2033 * TICKS_PER_SECOND has the unit 'count of timer ticks per second'. It is
2034 * defined in "targetos.h". The definition of TICKS_PER_SECOND must comply
2035 * to the time returned by smt_get_time().
2037 ************************/
2038 unsigned long smt_get_time(void)
2040 return jiffies;
2041 } // smt_get_time
2044 /************************
2046 * smt_stat_counter
2048 * Status counter update (ring_op, fifo full).
2049 * Args
2050 * smc - A pointer to the SMT context struct.
2052 * stat - = 0: A ring operational change occurred.
2053 * = 1: The FORMAC FIFO buffer is full / FIFO overflow.
2054 * Out
2055 * Nothing.
2057 ************************/
2058 void smt_stat_counter(struct s_smc *smc, int stat)
2060 // BOOLEAN RingIsUp ;
2062 PRINTK(KERN_INFO "smt_stat_counter\n");
2063 switch (stat) {
2064 case 0:
2065 PRINTK(KERN_INFO "Ring operational change.\n");
2066 break;
2067 case 1:
2068 PRINTK(KERN_INFO "Receive fifo overflow.\n");
2069 smc->os.MacStat.gen.rx_errors++;
2070 break;
2071 default:
2072 PRINTK(KERN_INFO "Unknown status (%d).\n", stat);
2073 break;
2075 } // smt_stat_counter
2078 /************************
2080 * cfm_state_change
2082 * Sets CFM state in custom statistics.
2083 * Args
2084 * smc - A pointer to the SMT context struct.
2086 * c_state - Possible values are:
2088 * EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST,
2089 * EC5_INSERT, EC6_CHECK, EC7_DEINSERT
2090 * Out
2091 * Nothing.
2093 ************************/
2094 void cfm_state_change(struct s_smc *smc, int c_state)
2096 #ifdef DRIVERDEBUG
2097 char *s;
2099 switch (c_state) {
2100 case SC0_ISOLATED:
2101 s = "SC0_ISOLATED";
2102 break;
2103 case SC1_WRAP_A:
2104 s = "SC1_WRAP_A";
2105 break;
2106 case SC2_WRAP_B:
2107 s = "SC2_WRAP_B";
2108 break;
2109 case SC4_THRU_A:
2110 s = "SC4_THRU_A";
2111 break;
2112 case SC5_THRU_B:
2113 s = "SC5_THRU_B";
2114 break;
2115 case SC7_WRAP_S:
2116 s = "SC7_WRAP_S";
2117 break;
2118 case SC9_C_WRAP_A:
2119 s = "SC9_C_WRAP_A";
2120 break;
2121 case SC10_C_WRAP_B:
2122 s = "SC10_C_WRAP_B";
2123 break;
2124 case SC11_C_WRAP_S:
2125 s = "SC11_C_WRAP_S";
2126 break;
2127 default:
2128 PRINTK(KERN_INFO "cfm_state_change: unknown %d\n", c_state);
2129 return;
2131 PRINTK(KERN_INFO "cfm_state_change: %s\n", s);
2132 #endif // DRIVERDEBUG
2133 } // cfm_state_change
2136 /************************
2138 * ecm_state_change
2140 * Sets ECM state in custom statistics.
2141 * Args
2142 * smc - A pointer to the SMT context struct.
2144 * e_state - Possible values are:
2146 * SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12),
2147 * SC5_THRU_B (7), SC7_WRAP_S (8)
2148 * Out
2149 * Nothing.
2151 ************************/
2152 void ecm_state_change(struct s_smc *smc, int e_state)
2154 #ifdef DRIVERDEBUG
2155 char *s;
2157 switch (e_state) {
2158 case EC0_OUT:
2159 s = "EC0_OUT";
2160 break;
2161 case EC1_IN:
2162 s = "EC1_IN";
2163 break;
2164 case EC2_TRACE:
2165 s = "EC2_TRACE";
2166 break;
2167 case EC3_LEAVE:
2168 s = "EC3_LEAVE";
2169 break;
2170 case EC4_PATH_TEST:
2171 s = "EC4_PATH_TEST";
2172 break;
2173 case EC5_INSERT:
2174 s = "EC5_INSERT";
2175 break;
2176 case EC6_CHECK:
2177 s = "EC6_CHECK";
2178 break;
2179 case EC7_DEINSERT:
2180 s = "EC7_DEINSERT";
2181 break;
2182 default:
2183 s = "unknown";
2184 break;
2186 PRINTK(KERN_INFO "ecm_state_change: %s\n", s);
2187 #endif //DRIVERDEBUG
2188 } // ecm_state_change
2191 /************************
2193 * rmt_state_change
2195 * Sets RMT state in custom statistics.
2196 * Args
2197 * smc - A pointer to the SMT context struct.
2199 * r_state - Possible values are:
2201 * RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT,
2202 * RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE
2203 * Out
2204 * Nothing.
2206 ************************/
2207 void rmt_state_change(struct s_smc *smc, int r_state)
2209 #ifdef DRIVERDEBUG
2210 char *s;
2212 switch (r_state) {
2213 case RM0_ISOLATED:
2214 s = "RM0_ISOLATED";
2215 break;
2216 case RM1_NON_OP:
2217 s = "RM1_NON_OP - not operational";
2218 break;
2219 case RM2_RING_OP:
2220 s = "RM2_RING_OP - ring operational";
2221 break;
2222 case RM3_DETECT:
2223 s = "RM3_DETECT - detect dupl addresses";
2224 break;
2225 case RM4_NON_OP_DUP:
2226 s = "RM4_NON_OP_DUP - dupl. addr detected";
2227 break;
2228 case RM5_RING_OP_DUP:
2229 s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
2230 break;
2231 case RM6_DIRECTED:
2232 s = "RM6_DIRECTED - sending directed beacons";
2233 break;
2234 case RM7_TRACE:
2235 s = "RM7_TRACE - trace initiated";
2236 break;
2237 default:
2238 s = "unknown";
2239 break;
2241 PRINTK(KERN_INFO "[rmt_state_change: %s]\n", s);
2242 #endif // DRIVERDEBUG
2243 } // rmt_state_change
2246 /************************
2248 * drv_reset_indication
2250 * This function is called by the SMT when it has detected a severe
2251 * hardware problem. The driver should perform a reset on the adapter
2252 * as soon as possible, but not from within this function.
2253 * Args
2254 * smc - A pointer to the SMT context struct.
2255 * Out
2256 * Nothing.
2258 ************************/
2259 void drv_reset_indication(struct s_smc *smc)
2261 PRINTK(KERN_INFO "entering drv_reset_indication\n");
2263 smc->os.ResetRequested = TRUE; // Set flag.
2265 } // drv_reset_indication
2267 static struct pci_driver skfddi_pci_driver = {
2268 .name = "skfddi",
2269 .id_table = skfddi_pci_tbl,
2270 .probe = skfp_init_one,
2271 .remove = __devexit_p(skfp_remove_one),
2274 static int __init skfd_init(void)
2276 return pci_register_driver(&skfddi_pci_driver);
2279 static void __exit skfd_exit(void)
2281 pci_unregister_driver(&skfddi_pci_driver);
2284 module_init(skfd_init);
2285 module_exit(skfd_exit);