RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / net / skfp / skfddi.c
blobe98a30895f91cf1689277e3399067adfd057469d
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/capability.h>
77 #include <linux/module.h>
78 #include <linux/kernel.h>
79 #include <linux/errno.h>
80 #include <linux/ioport.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>
87 #include <linux/gfp.h>
89 #include <asm/byteorder.h>
90 #include <asm/io.h>
91 #include <asm/uaccess.h>
93 #include "h/types.h"
94 #undef ADDR // undo Linux definition
95 #include "h/skfbi.h"
96 #include "h/fddi.h"
97 #include "h/smc.h"
98 #include "h/smtstate.h"
101 // Define module-wide (static) routines
102 static int skfp_driver_init(struct net_device *dev);
103 static int skfp_open(struct net_device *dev);
104 static int skfp_close(struct net_device *dev);
105 static irqreturn_t skfp_interrupt(int irq, void *dev_id);
106 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev);
107 static void skfp_ctl_set_multicast_list(struct net_device *dev);
108 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev);
109 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr);
110 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
111 static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
112 struct net_device *dev);
113 static void send_queued_packets(struct s_smc *smc);
114 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr);
115 static void ResetAdapter(struct s_smc *smc);
118 // Functions needed by the hardware module
119 void *mac_drv_get_space(struct s_smc *smc, u_int size);
120 void *mac_drv_get_desc_mem(struct s_smc *smc, u_int size);
121 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt);
122 unsigned long dma_master(struct s_smc *smc, void *virt, int len, int flag);
123 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr,
124 int flag);
125 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd);
126 void llc_restart_tx(struct s_smc *smc);
127 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
128 int frag_count, int len);
129 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
130 int frag_count);
131 void mac_drv_fill_rxd(struct s_smc *smc);
132 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
133 int frag_count);
134 int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
135 int la_len);
136 void dump_data(unsigned char *Data, int length);
138 // External functions from the hardware module
139 extern u_int mac_drv_check_space(void);
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 void fddi_isr(struct s_smc *smc);
146 extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
147 int len, int frame_status);
148 extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
149 extern void mac_drv_clear_rx_queue(struct s_smc *smc);
150 extern void enable_tx_irq(struct s_smc *smc, u_short queue);
152 static DEFINE_PCI_DEVICE_TABLE(skfddi_pci_tbl) = {
153 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
154 { } /* Terminating entry */
156 MODULE_DEVICE_TABLE(pci, skfddi_pci_tbl);
157 MODULE_LICENSE("GPL");
158 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
160 // Define module-wide (static) variables
162 static int num_boards; /* total number of adapters configured */
164 static const struct net_device_ops skfp_netdev_ops = {
165 .ndo_open = skfp_open,
166 .ndo_stop = skfp_close,
167 .ndo_start_xmit = skfp_send_pkt,
168 .ndo_get_stats = skfp_ctl_get_stats,
169 .ndo_change_mtu = fddi_change_mtu,
170 .ndo_set_multicast_list = skfp_ctl_set_multicast_list,
171 .ndo_set_mac_address = skfp_ctl_set_mac_address,
172 .ndo_do_ioctl = skfp_ioctl,
176 * =================
177 * = skfp_init_one =
178 * =================
180 * Overview:
181 * Probes for supported FDDI PCI controllers
183 * Returns:
184 * Condition code
186 * Arguments:
187 * pdev - pointer to PCI device information
189 * Functional Description:
190 * This is now called by PCI driver registration process
191 * for each board found.
193 * Return Codes:
194 * 0 - This device (fddi0, fddi1, etc) configured successfully
195 * -ENODEV - No devices present, or no SysKonnect FDDI PCI device
196 * present for this device name
199 * Side Effects:
200 * Device structures for FDDI adapters (fddi0, fddi1, etc) are
201 * initialized and the board resources are read and stored in
202 * the device structure.
204 static int skfp_init_one(struct pci_dev *pdev,
205 const struct pci_device_id *ent)
207 struct net_device *dev;
208 struct s_smc *smc; /* board pointer */
209 void __iomem *mem;
210 int err;
212 pr_debug(KERN_INFO "entering skfp_init_one\n");
214 if (num_boards == 0)
215 printk("%s\n", boot_msg);
217 err = pci_enable_device(pdev);
218 if (err)
219 return err;
221 err = pci_request_regions(pdev, "skfddi");
222 if (err)
223 goto err_out1;
225 pci_set_master(pdev);
227 #ifdef MEM_MAPPED_IO
228 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
229 printk(KERN_ERR "skfp: region is not an MMIO resource\n");
230 err = -EIO;
231 goto err_out2;
234 mem = ioremap(pci_resource_start(pdev, 0), 0x4000);
235 #else
236 if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) {
237 printk(KERN_ERR "skfp: region is not PIO resource\n");
238 err = -EIO;
239 goto err_out2;
242 mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN);
243 #endif
244 if (!mem) {
245 printk(KERN_ERR "skfp: Unable to map register, "
246 "FDDI adapter will be disabled.\n");
247 err = -EIO;
248 goto err_out2;
251 dev = alloc_fddidev(sizeof(struct s_smc));
252 if (!dev) {
253 printk(KERN_ERR "skfp: Unable to allocate fddi device, "
254 "FDDI adapter will be disabled.\n");
255 err = -ENOMEM;
256 goto err_out3;
259 dev->irq = pdev->irq;
260 dev->netdev_ops = &skfp_netdev_ops;
262 SET_NETDEV_DEV(dev, &pdev->dev);
264 /* Initialize board structure with bus-specific info */
265 smc = netdev_priv(dev);
266 smc->os.dev = dev;
267 smc->os.bus_type = SK_BUS_TYPE_PCI;
268 smc->os.pdev = *pdev;
269 smc->os.QueueSkb = MAX_TX_QUEUE_LEN;
270 smc->os.MaxFrameSize = MAX_FRAME_SIZE;
271 smc->os.dev = dev;
272 smc->hw.slot = -1;
273 smc->hw.iop = mem;
274 smc->os.ResetRequested = FALSE;
275 skb_queue_head_init(&smc->os.SendSkbQueue);
277 dev->base_addr = (unsigned long)mem;
279 err = skfp_driver_init(dev);
280 if (err)
281 goto err_out4;
283 err = register_netdev(dev);
284 if (err)
285 goto err_out5;
287 ++num_boards;
288 pci_set_drvdata(pdev, dev);
290 if ((pdev->subsystem_device & 0xff00) == 0x5500 ||
291 (pdev->subsystem_device & 0xff00) == 0x5800)
292 printk("%s: SysKonnect FDDI PCI adapter"
293 " found (SK-%04X)\n", dev->name,
294 pdev->subsystem_device);
295 else
296 printk("%s: FDDI PCI adapter found\n", dev->name);
298 return 0;
299 err_out5:
300 if (smc->os.SharedMemAddr)
301 pci_free_consistent(pdev, smc->os.SharedMemSize,
302 smc->os.SharedMemAddr,
303 smc->os.SharedMemDMA);
304 pci_free_consistent(pdev, MAX_FRAME_SIZE,
305 smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA);
306 err_out4:
307 free_netdev(dev);
308 err_out3:
309 #ifdef MEM_MAPPED_IO
310 iounmap(mem);
311 #else
312 ioport_unmap(mem);
313 #endif
314 err_out2:
315 pci_release_regions(pdev);
316 err_out1:
317 pci_disable_device(pdev);
318 return err;
322 * Called for each adapter board from pci_unregister_driver
324 static void __devexit skfp_remove_one(struct pci_dev *pdev)
326 struct net_device *p = pci_get_drvdata(pdev);
327 struct s_smc *lp = netdev_priv(p);
329 unregister_netdev(p);
331 if (lp->os.SharedMemAddr) {
332 pci_free_consistent(&lp->os.pdev,
333 lp->os.SharedMemSize,
334 lp->os.SharedMemAddr,
335 lp->os.SharedMemDMA);
336 lp->os.SharedMemAddr = NULL;
338 if (lp->os.LocalRxBuffer) {
339 pci_free_consistent(&lp->os.pdev,
340 MAX_FRAME_SIZE,
341 lp->os.LocalRxBuffer,
342 lp->os.LocalRxBufferDMA);
343 lp->os.LocalRxBuffer = NULL;
345 #ifdef MEM_MAPPED_IO
346 iounmap(lp->hw.iop);
347 #else
348 ioport_unmap(lp->hw.iop);
349 #endif
350 pci_release_regions(pdev);
351 free_netdev(p);
353 pci_disable_device(pdev);
354 pci_set_drvdata(pdev, NULL);
358 * ====================
359 * = skfp_driver_init =
360 * ====================
362 * Overview:
363 * Initializes remaining adapter board structure information
364 * and makes sure adapter is in a safe state prior to skfp_open().
366 * Returns:
367 * Condition code
369 * Arguments:
370 * dev - pointer to device information
372 * Functional Description:
373 * This function allocates additional resources such as the host memory
374 * blocks needed by the adapter.
375 * The adapter is also reset. The OS must call skfp_open() to open
376 * the adapter and bring it on-line.
378 * Return Codes:
379 * 0 - initialization succeeded
380 * -1 - initialization failed
382 static int skfp_driver_init(struct net_device *dev)
384 struct s_smc *smc = netdev_priv(dev);
385 skfddi_priv *bp = &smc->os;
386 int err = -EIO;
388 pr_debug(KERN_INFO "entering skfp_driver_init\n");
390 // set the io address in private structures
391 bp->base_addr = dev->base_addr;
393 // Get the interrupt level from the PCI Configuration Table
394 smc->hw.irq = dev->irq;
396 spin_lock_init(&bp->DriverLock);
398 // Allocate invalid frame
399 bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA);
400 if (!bp->LocalRxBuffer) {
401 printk("could not allocate mem for ");
402 printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
403 goto fail;
406 // Determine the required size of the 'shared' memory area.
407 bp->SharedMemSize = mac_drv_check_space();
408 pr_debug(KERN_INFO "Memory for HWM: %ld\n", bp->SharedMemSize);
409 if (bp->SharedMemSize > 0) {
410 bp->SharedMemSize += 16; // for descriptor alignment
412 bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev,
413 bp->SharedMemSize,
414 &bp->SharedMemDMA);
415 if (!bp->SharedMemSize) {
416 printk("could not allocate mem for ");
417 printk("hardware module: %ld byte\n",
418 bp->SharedMemSize);
419 goto fail;
421 bp->SharedMemHeap = 0; // Nothing used yet.
423 } else {
424 bp->SharedMemAddr = NULL;
425 bp->SharedMemHeap = 0;
426 } // SharedMemSize > 0
428 memset(bp->SharedMemAddr, 0, bp->SharedMemSize);
430 card_stop(smc); // Reset adapter.
432 pr_debug(KERN_INFO "mac_drv_init()..\n");
433 if (mac_drv_init(smc) != 0) {
434 pr_debug(KERN_INFO "mac_drv_init() failed.\n");
435 goto fail;
437 read_address(smc, NULL);
438 pr_debug(KERN_INFO "HW-Addr: %pMF\n", smc->hw.fddi_canon_addr.a);
439 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
441 smt_reset_defaults(smc, 0);
443 return (0);
445 fail:
446 if (bp->SharedMemAddr) {
447 pci_free_consistent(&bp->pdev,
448 bp->SharedMemSize,
449 bp->SharedMemAddr,
450 bp->SharedMemDMA);
451 bp->SharedMemAddr = NULL;
453 if (bp->LocalRxBuffer) {
454 pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE,
455 bp->LocalRxBuffer, bp->LocalRxBufferDMA);
456 bp->LocalRxBuffer = NULL;
458 return err;
459 } // skfp_driver_init
463 * =============
464 * = skfp_open =
465 * =============
467 * Overview:
468 * Opens the adapter
470 * Returns:
471 * Condition code
473 * Arguments:
474 * dev - pointer to device information
476 * Functional Description:
477 * This function brings the adapter to an operational state.
479 * Return Codes:
480 * 0 - Adapter was successfully opened
481 * -EAGAIN - Could not register IRQ
483 static int skfp_open(struct net_device *dev)
485 struct s_smc *smc = netdev_priv(dev);
486 int err;
488 pr_debug(KERN_INFO "entering skfp_open\n");
489 /* Register IRQ - support shared interrupts by passing device ptr */
490 err = request_irq(dev->irq, skfp_interrupt, IRQF_SHARED,
491 dev->name, dev);
492 if (err)
493 return err;
496 * Set current address to factory MAC address
498 * Note: We've already done this step in skfp_driver_init.
499 * However, it's possible that a user has set a node
500 * address override, then closed and reopened the
501 * adapter. Unless we reset the device address field
502 * now, we'll continue to use the existing modified
503 * address.
505 read_address(smc, NULL);
506 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
508 init_smt(smc, NULL);
509 smt_online(smc, 1);
510 STI_FBI();
512 /* Clear local multicast address tables */
513 mac_clear_multicast(smc);
515 /* Disable promiscuous filter settings */
516 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
518 netif_start_queue(dev);
519 return (0);
520 } // skfp_open
524 * ==============
525 * = skfp_close =
526 * ==============
528 * Overview:
529 * Closes the device/module.
531 * Returns:
532 * Condition code
534 * Arguments:
535 * dev - pointer to device information
537 * Functional Description:
538 * This routine closes the adapter and brings it to a safe state.
539 * The interrupt service routine is deregistered with the OS.
540 * The adapter can be opened again with another call to skfp_open().
542 * Return Codes:
543 * Always return 0.
545 * Assumptions:
546 * No further requests for this adapter are made after this routine is
547 * called. skfp_open() can be called to reset and reinitialize the
548 * adapter.
550 static int skfp_close(struct net_device *dev)
552 struct s_smc *smc = netdev_priv(dev);
553 skfddi_priv *bp = &smc->os;
555 CLI_FBI();
556 smt_reset_defaults(smc, 1);
557 card_stop(smc);
558 mac_drv_clear_tx_queue(smc);
559 mac_drv_clear_rx_queue(smc);
561 netif_stop_queue(dev);
562 /* Deregister (free) IRQ */
563 free_irq(dev->irq, dev);
565 skb_queue_purge(&bp->SendSkbQueue);
566 bp->QueueSkb = MAX_TX_QUEUE_LEN;
568 return (0);
569 } // skfp_close
573 * ==================
574 * = skfp_interrupt =
575 * ==================
577 * Overview:
578 * Interrupt processing routine
580 * Returns:
581 * None
583 * Arguments:
584 * irq - interrupt vector
585 * dev_id - pointer to device information
587 * Functional Description:
588 * This routine calls the interrupt processing routine for this adapter. It
589 * disables and reenables adapter interrupts, as appropriate. We can support
590 * shared interrupts since the incoming dev_id pointer provides our device
591 * structure context. All the real work is done in the hardware module.
593 * Return Codes:
594 * None
596 * Assumptions:
597 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
598 * on Intel-based systems) is done by the operating system outside this
599 * routine.
601 * System interrupts are enabled through this call.
603 * Side Effects:
604 * Interrupts are disabled, then reenabled at the adapter.
607 static irqreturn_t skfp_interrupt(int irq, void *dev_id)
609 struct net_device *dev = dev_id;
610 struct s_smc *smc; /* private board structure pointer */
611 skfddi_priv *bp;
613 smc = netdev_priv(dev);
614 bp = &smc->os;
616 // IRQs enabled or disabled ?
617 if (inpd(ADDR(B0_IMSK)) == 0) {
618 // IRQs are disabled: must be shared interrupt
619 return IRQ_NONE;
621 // Note: At this point, IRQs are enabled.
622 if ((inpd(ISR_A) & smc->hw.is_imask) == 0) { // IRQ?
623 // Adapter did not issue an IRQ: must be shared interrupt
624 return IRQ_NONE;
626 CLI_FBI(); // Disable IRQs from our adapter.
627 spin_lock(&bp->DriverLock);
629 // Call interrupt handler in hardware module (HWM).
630 fddi_isr(smc);
632 if (smc->os.ResetRequested) {
633 ResetAdapter(smc);
634 smc->os.ResetRequested = FALSE;
636 spin_unlock(&bp->DriverLock);
637 STI_FBI(); // Enable IRQs from our adapter.
639 return IRQ_HANDLED;
640 } // skfp_interrupt
644 * ======================
645 * = skfp_ctl_get_stats =
646 * ======================
648 * Overview:
649 * Get statistics for FDDI adapter
651 * Returns:
652 * Pointer to FDDI statistics structure
654 * Arguments:
655 * dev - pointer to device information
657 * Functional Description:
658 * Gets current MIB objects from adapter, then
659 * returns FDDI statistics structure as defined
660 * in if_fddi.h.
662 * Note: Since the FDDI statistics structure is
663 * still new and the device structure doesn't
664 * have an FDDI-specific get statistics handler,
665 * we'll return the FDDI statistics structure as
666 * a pointer to an Ethernet statistics structure.
667 * That way, at least the first part of the statistics
668 * structure can be decoded properly.
669 * We'll have to pay attention to this routine as the
670 * device structure becomes more mature and LAN media
671 * independent.
674 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
676 struct s_smc *bp = netdev_priv(dev);
678 /* Fill the bp->stats structure with driver-maintained counters */
680 bp->os.MacStat.port_bs_flag[0] = 0x1234;
681 bp->os.MacStat.port_bs_flag[1] = 0x5678;
682 // goos: need to fill out fddi statistic
683 return ((struct net_device_stats *) &bp->os.MacStat);
684 } // ctl_get_stat
688 * ==============================
689 * = skfp_ctl_set_multicast_list =
690 * ==============================
692 * Overview:
693 * Enable/Disable LLC frame promiscuous mode reception
694 * on the adapter and/or update multicast address table.
696 * Returns:
697 * None
699 * Arguments:
700 * dev - pointer to device information
702 * Functional Description:
703 * This function acquires the driver lock and only calls
704 * skfp_ctl_set_multicast_list_wo_lock then.
705 * This routine follows a fairly simple algorithm for setting the
706 * adapter filters and CAM:
708 * if IFF_PROMISC flag is set
709 * enable promiscuous mode
710 * else
711 * disable promiscuous mode
712 * if number of multicast addresses <= max. multicast number
713 * add mc addresses to adapter table
714 * else
715 * enable promiscuous mode
716 * update adapter filters
718 * Assumptions:
719 * Multicast addresses are presented in canonical (LSB) format.
721 * Side Effects:
722 * On-board adapter filters are updated.
724 static void skfp_ctl_set_multicast_list(struct net_device *dev)
726 struct s_smc *smc = netdev_priv(dev);
727 skfddi_priv *bp = &smc->os;
728 unsigned long Flags;
730 spin_lock_irqsave(&bp->DriverLock, Flags);
731 skfp_ctl_set_multicast_list_wo_lock(dev);
732 spin_unlock_irqrestore(&bp->DriverLock, Flags);
733 } // skfp_ctl_set_multicast_list
737 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
739 struct s_smc *smc = netdev_priv(dev);
740 struct netdev_hw_addr *ha;
742 /* Enable promiscuous mode, if necessary */
743 if (dev->flags & IFF_PROMISC) {
744 mac_drv_rx_mode(smc, RX_ENABLE_PROMISC);
745 pr_debug(KERN_INFO "PROMISCUOUS MODE ENABLED\n");
747 /* Else, update multicast address table */
748 else {
749 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
750 pr_debug(KERN_INFO "PROMISCUOUS MODE DISABLED\n");
752 // Reset all MC addresses
753 mac_clear_multicast(smc);
754 mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI);
756 if (dev->flags & IFF_ALLMULTI) {
757 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
758 pr_debug(KERN_INFO "ENABLE ALL MC ADDRESSES\n");
759 } else if (!netdev_mc_empty(dev)) {
760 if (netdev_mc_count(dev) <= FPMAX_MULTICAST) {
761 /* use exact filtering */
763 // point to first multicast addr
764 netdev_for_each_mc_addr(ha, dev) {
765 mac_add_multicast(smc,
766 (struct fddi_addr *)ha->addr,
769 pr_debug(KERN_INFO "ENABLE MC ADDRESS: %pMF\n",
770 ha->addr);
773 } else { // more MC addresses than HW supports
775 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
776 pr_debug(KERN_INFO "ENABLE ALL MC ADDRESSES\n");
778 } else { // no MC addresses
780 pr_debug(KERN_INFO "DISABLE ALL MC ADDRESSES\n");
783 /* Update adapter filters */
784 mac_update_multicast(smc);
786 } // skfp_ctl_set_multicast_list_wo_lock
790 * ===========================
791 * = skfp_ctl_set_mac_address =
792 * ===========================
794 * Overview:
795 * set new mac address on adapter and update dev_addr field in device table.
797 * Returns:
798 * None
800 * Arguments:
801 * dev - pointer to device information
802 * addr - pointer to sockaddr structure containing unicast address to set
804 * Assumptions:
805 * The address pointed to by addr->sa_data is a valid unicast
806 * address and is presented in canonical (LSB) format.
808 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
810 struct s_smc *smc = netdev_priv(dev);
811 struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
812 skfddi_priv *bp = &smc->os;
813 unsigned long Flags;
816 memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);
817 spin_lock_irqsave(&bp->DriverLock, Flags);
818 ResetAdapter(smc);
819 spin_unlock_irqrestore(&bp->DriverLock, Flags);
821 return (0); /* always return zero */
822 } // skfp_ctl_set_mac_address
826 * ==============
827 * = skfp_ioctl =
828 * ==============
830 * Overview:
832 * Perform IOCTL call functions here. Some are privileged operations and the
833 * effective uid is checked in those cases.
835 * Returns:
836 * status value
837 * 0 - success
838 * other - failure
840 * Arguments:
841 * dev - pointer to device information
842 * rq - pointer to ioctl request structure
843 * cmd - ?
848 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
850 struct s_smc *smc = netdev_priv(dev);
851 skfddi_priv *lp = &smc->os;
852 struct s_skfp_ioctl ioc;
853 int status = 0;
855 if (copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl)))
856 return -EFAULT;
858 switch (ioc.cmd) {
859 case SKFP_GET_STATS: /* Get the driver statistics */
860 ioc.len = sizeof(lp->MacStat);
861 status = copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len)
862 ? -EFAULT : 0;
863 break;
864 case SKFP_CLR_STATS: /* Zero out the driver statistics */
865 if (!capable(CAP_NET_ADMIN)) {
866 status = -EPERM;
867 } else {
868 memset(&lp->MacStat, 0, sizeof(lp->MacStat));
870 break;
871 default:
872 printk("ioctl for %s: unknown cmd: %04x\n", dev->name, ioc.cmd);
873 status = -EOPNOTSUPP;
875 } // switch
877 return status;
878 } // skfp_ioctl
882 * =====================
883 * = skfp_send_pkt =
884 * =====================
886 * Overview:
887 * Queues a packet for transmission and try to transmit it.
889 * Returns:
890 * Condition code
892 * Arguments:
893 * skb - pointer to sk_buff to queue for transmission
894 * dev - pointer to device information
896 * Functional Description:
897 * Here we assume that an incoming skb transmit request
898 * is contained in a single physically contiguous buffer
899 * in which the virtual address of the start of packet
900 * (skb->data) can be converted to a physical address
901 * by using pci_map_single().
903 * We have an internal queue for packets we can not send
904 * immediately. Packets in this queue can be given to the
905 * adapter if transmit buffers are freed.
907 * We can't free the skb until after it's been DMA'd
908 * out by the adapter, so we'll keep it in the driver and
909 * return it in mac_drv_tx_complete.
911 * Return Codes:
912 * 0 - driver has queued and/or sent packet
913 * 1 - caller should requeue the sk_buff for later transmission
915 * Assumptions:
916 * The entire packet is stored in one physically
917 * contiguous buffer which is not cached and whose
918 * 32-bit physical address can be determined.
920 * It's vital that this routine is NOT reentered for the
921 * same board and that the OS is not in another section of
922 * code (eg. skfp_interrupt) for the same board on a
923 * different thread.
925 * Side Effects:
926 * None
928 static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
929 struct net_device *dev)
931 struct s_smc *smc = netdev_priv(dev);
932 skfddi_priv *bp = &smc->os;
934 pr_debug(KERN_INFO "skfp_send_pkt\n");
937 * Verify that incoming transmit request is OK
939 * Note: The packet size check is consistent with other
940 * Linux device drivers, although the correct packet
941 * size should be verified before calling the
942 * transmit routine.
945 if (!(skb->len >= FDDI_K_LLC_ZLEN && skb->len <= FDDI_K_LLC_LEN)) {
946 bp->MacStat.gen.tx_errors++; /* bump error counter */
947 // dequeue packets from xmt queue and send them
948 netif_start_queue(dev);
949 dev_kfree_skb(skb);
950 return NETDEV_TX_OK; /* return "success" */
952 if (bp->QueueSkb == 0) { // return with tbusy set: queue full
954 netif_stop_queue(dev);
955 return NETDEV_TX_BUSY;
957 bp->QueueSkb--;
958 skb_queue_tail(&bp->SendSkbQueue, skb);
959 send_queued_packets(netdev_priv(dev));
960 if (bp->QueueSkb == 0) {
961 netif_stop_queue(dev);
963 return NETDEV_TX_OK;
965 } // skfp_send_pkt
969 * =======================
970 * = send_queued_packets =
971 * =======================
973 * Overview:
974 * Send packets from the driver queue as long as there are some and
975 * transmit resources are available.
977 * Returns:
978 * None
980 * Arguments:
981 * smc - pointer to smc (adapter) structure
983 * Functional Description:
984 * Take a packet from queue if there is any. If not, then we are done.
985 * Check if there are resources to send the packet. If not, requeue it
986 * and exit.
987 * Set packet descriptor flags and give packet to adapter.
988 * Check if any send resources can be freed (we do not use the
989 * transmit complete interrupt).
991 static void send_queued_packets(struct s_smc *smc)
993 skfddi_priv *bp = &smc->os;
994 struct sk_buff *skb;
995 unsigned char fc;
996 int queue;
997 struct s_smt_fp_txd *txd; // Current TxD.
998 dma_addr_t dma_address;
999 unsigned long Flags;
1001 int frame_status; // HWM tx frame status.
1003 pr_debug(KERN_INFO "send queued packets\n");
1004 for (;;) {
1005 // send first buffer from queue
1006 skb = skb_dequeue(&bp->SendSkbQueue);
1008 if (!skb) {
1009 pr_debug(KERN_INFO "queue empty\n");
1010 return;
1011 } // queue empty !
1013 spin_lock_irqsave(&bp->DriverLock, Flags);
1014 fc = skb->data[0];
1015 queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0;
1016 #ifdef ESS
1017 // Check if the frame may/must be sent as a synchronous frame.
1019 if ((fc & ~(FC_SYNC_BIT | FC_LLC_PRIOR)) == FC_ASYNC_LLC) {
1020 // It's an LLC frame.
1021 if (!smc->ess.sync_bw_available)
1022 fc &= ~FC_SYNC_BIT; // No bandwidth available.
1024 else { // Bandwidth is available.
1026 if (smc->mib.fddiESSSynchTxMode) {
1027 // Send as sync. frame.
1028 fc |= FC_SYNC_BIT;
1032 #endif // ESS
1033 frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue);
1035 if ((frame_status & (LOC_TX | LAN_TX)) == 0) {
1036 // Unable to send the frame.
1038 if ((frame_status & RING_DOWN) != 0) {
1039 // Ring is down.
1040 pr_debug("Tx attempt while ring down.\n");
1041 } else if ((frame_status & OUT_OF_TXD) != 0) {
1042 pr_debug("%s: out of TXDs.\n", bp->dev->name);
1043 } else {
1044 pr_debug("%s: out of transmit resources",
1045 bp->dev->name);
1048 // Note: We will retry the operation as soon as
1049 // transmit resources become available.
1050 skb_queue_head(&bp->SendSkbQueue, skb);
1051 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1052 return; // Packet has been queued.
1054 } // if (unable to send frame)
1056 bp->QueueSkb++; // one packet less in local queue
1058 // source address in packet ?
1059 CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a);
1061 txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue);
1063 dma_address = pci_map_single(&bp->pdev, skb->data,
1064 skb->len, PCI_DMA_TODEVICE);
1065 if (frame_status & LAN_TX) {
1066 txd->txd_os.skb = skb; // save skb
1067 txd->txd_os.dma_addr = dma_address; // save dma mapping
1069 hwm_tx_frag(smc, skb->data, dma_address, skb->len,
1070 frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF);
1072 if (!(frame_status & LAN_TX)) { // local only frame
1073 pci_unmap_single(&bp->pdev, dma_address,
1074 skb->len, PCI_DMA_TODEVICE);
1075 dev_kfree_skb_irq(skb);
1077 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1078 } // for
1080 return; // never reached
1082 } // send_queued_packets
1085 /************************
1087 * CheckSourceAddress
1089 * Verify if the source address is set. Insert it if necessary.
1091 ************************/
1092 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr)
1094 unsigned char SRBit;
1096 if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0) // source routing bit
1098 return;
1099 if ((unsigned short) frame[1 + 10] != 0)
1100 return;
1101 SRBit = frame[1 + 6] & 0x01;
1102 memcpy(&frame[1 + 6], hw_addr, 6);
1103 frame[8] |= SRBit;
1104 } // CheckSourceAddress
1107 /************************
1109 * ResetAdapter
1111 * Reset the adapter and bring it back to operational mode.
1112 * Args
1113 * smc - A pointer to the SMT context struct.
1114 * Out
1115 * Nothing.
1117 ************************/
1118 static void ResetAdapter(struct s_smc *smc)
1121 pr_debug(KERN_INFO "[fddi: ResetAdapter]\n");
1123 // Stop the adapter.
1125 card_stop(smc); // Stop all activity.
1127 // Clear the transmit and receive descriptor queues.
1128 mac_drv_clear_tx_queue(smc);
1129 mac_drv_clear_rx_queue(smc);
1131 // Restart the adapter.
1133 smt_reset_defaults(smc, 1); // Initialize the SMT module.
1135 init_smt(smc, (smc->os.dev)->dev_addr); // Initialize the hardware.
1137 smt_online(smc, 1); // Insert into the ring again.
1138 STI_FBI();
1140 // Restore original receive mode (multicasts, promiscuous, etc.).
1141 skfp_ctl_set_multicast_list_wo_lock(smc->os.dev);
1142 } // ResetAdapter
1145 //--------------- functions called by hardware module ----------------
1147 /************************
1149 * llc_restart_tx
1151 * The hardware driver calls this routine when the transmit complete
1152 * interrupt bits (end of frame) for the synchronous or asynchronous
1153 * queue is set.
1155 * NOTE The hardware driver calls this function also if no packets are queued.
1156 * The routine must be able to handle this case.
1157 * Args
1158 * smc - A pointer to the SMT context struct.
1159 * Out
1160 * Nothing.
1162 ************************/
1163 void llc_restart_tx(struct s_smc *smc)
1165 skfddi_priv *bp = &smc->os;
1167 pr_debug(KERN_INFO "[llc_restart_tx]\n");
1169 // Try to send queued packets
1170 spin_unlock(&bp->DriverLock);
1171 send_queued_packets(smc);
1172 spin_lock(&bp->DriverLock);
1173 netif_start_queue(bp->dev);// system may send again if it was blocked
1175 } // llc_restart_tx
1178 /************************
1180 * mac_drv_get_space
1182 * The hardware module calls this function to allocate the memory
1183 * for the SMT MBufs if the define MB_OUTSIDE_SMC is specified.
1184 * Args
1185 * smc - A pointer to the SMT context struct.
1187 * size - Size of memory in bytes to allocate.
1188 * Out
1189 * != 0 A pointer to the virtual address of the allocated memory.
1190 * == 0 Allocation error.
1192 ************************/
1193 void *mac_drv_get_space(struct s_smc *smc, unsigned int size)
1195 void *virt;
1197 pr_debug(KERN_INFO "mac_drv_get_space (%d bytes), ", size);
1198 virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap);
1200 if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) {
1201 printk("Unexpected SMT memory size requested: %d\n", size);
1202 return (NULL);
1204 smc->os.SharedMemHeap += size; // Move heap pointer.
1206 pr_debug(KERN_INFO "mac_drv_get_space end\n");
1207 pr_debug(KERN_INFO "virt addr: %lx\n", (ulong) virt);
1208 pr_debug(KERN_INFO "bus addr: %lx\n", (ulong)
1209 (smc->os.SharedMemDMA +
1210 ((char *) virt - (char *)smc->os.SharedMemAddr)));
1211 return (virt);
1212 } // mac_drv_get_space
1215 /************************
1217 * mac_drv_get_desc_mem
1219 * This function is called by the hardware dependent module.
1220 * It allocates the memory for the RxD and TxD descriptors.
1222 * This memory must be non-cached, non-movable and non-swappable.
1223 * This memory should start at a physical page boundary.
1224 * Args
1225 * smc - A pointer to the SMT context struct.
1227 * size - Size of memory in bytes to allocate.
1228 * Out
1229 * != 0 A pointer to the virtual address of the allocated memory.
1230 * == 0 Allocation error.
1232 ************************/
1233 void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size)
1236 char *virt;
1238 pr_debug(KERN_INFO "mac_drv_get_desc_mem\n");
1240 // Descriptor memory must be aligned on 16-byte boundary.
1242 virt = mac_drv_get_space(smc, size);
1244 size = (u_int) (16 - (((unsigned long) virt) & 15UL));
1245 size = size % 16;
1247 pr_debug("Allocate %u bytes alignment gap ", size);
1248 pr_debug("for descriptor memory.\n");
1250 if (!mac_drv_get_space(smc, size)) {
1251 printk("fddi: Unable to align descriptor memory.\n");
1252 return (NULL);
1254 return (virt + size);
1255 } // mac_drv_get_desc_mem
1258 /************************
1260 * mac_drv_virt2phys
1262 * Get the physical address of a given virtual address.
1263 * Args
1264 * smc - A pointer to the SMT context struct.
1266 * virt - A (virtual) pointer into our 'shared' memory area.
1267 * Out
1268 * Physical address of the given virtual address.
1270 ************************/
1271 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt)
1273 return (smc->os.SharedMemDMA +
1274 ((char *) virt - (char *)smc->os.SharedMemAddr));
1275 } // mac_drv_virt2phys
1278 /************************
1280 * dma_master
1282 * The HWM calls this function, when the driver leads through a DMA
1283 * transfer. If the OS-specific module must prepare the system hardware
1284 * for the DMA transfer, it should do it in this function.
1286 * The hardware module calls this dma_master if it wants to send an SMT
1287 * frame. This means that the virt address passed in here is part of
1288 * the 'shared' memory area.
1289 * Args
1290 * smc - A pointer to the SMT context struct.
1292 * virt - The virtual address of the data.
1294 * len - The length in bytes of the data.
1296 * flag - Indicates the transmit direction and the buffer type:
1297 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1298 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1299 * SMT_BUF (0x80) SMT buffer
1301 * >> NOTE: SMT_BUF and DMA_RD are always set for PCI. <<
1302 * Out
1303 * Returns the pyhsical address for the DMA transfer.
1305 ************************/
1306 u_long dma_master(struct s_smc * smc, void *virt, int len, int flag)
1308 return (smc->os.SharedMemDMA +
1309 ((char *) virt - (char *)smc->os.SharedMemAddr));
1310 } // dma_master
1313 /************************
1315 * dma_complete
1317 * The hardware module calls this routine when it has completed a DMA
1318 * transfer. If the operating system dependent module has set up the DMA
1319 * channel via dma_master() (e.g. Windows NT or AIX) it should clean up
1320 * the DMA channel.
1321 * Args
1322 * smc - A pointer to the SMT context struct.
1324 * descr - A pointer to a TxD or RxD, respectively.
1326 * flag - Indicates the DMA transfer direction / SMT buffer:
1327 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1328 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1329 * SMT_BUF (0x80) SMT buffer (managed by HWM)
1330 * Out
1331 * Nothing.
1333 ************************/
1334 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag)
1336 /* For TX buffers, there are two cases. If it is an SMT transmit
1337 * buffer, there is nothing to do since we use consistent memory
1338 * for the 'shared' memory area. The other case is for normal
1339 * transmit packets given to us by the networking stack, and in
1340 * that case we cleanup the PCI DMA mapping in mac_drv_tx_complete
1341 * below.
1343 * For RX buffers, we have to unmap dynamic PCI DMA mappings here
1344 * because the hardware module is about to potentially look at
1345 * the contents of the buffer. If we did not call the PCI DMA
1346 * unmap first, the hardware module could read inconsistent data.
1348 if (flag & DMA_WR) {
1349 skfddi_priv *bp = &smc->os;
1350 volatile struct s_smt_fp_rxd *r = &descr->r;
1352 /* If SKB is NULL, we used the local buffer. */
1353 if (r->rxd_os.skb && r->rxd_os.dma_addr) {
1354 int MaxFrameSize = bp->MaxFrameSize;
1356 pci_unmap_single(&bp->pdev, r->rxd_os.dma_addr,
1357 MaxFrameSize, PCI_DMA_FROMDEVICE);
1358 r->rxd_os.dma_addr = 0;
1361 } // dma_complete
1364 /************************
1366 * mac_drv_tx_complete
1368 * Transmit of a packet is complete. Release the tx staging buffer.
1370 * Args
1371 * smc - A pointer to the SMT context struct.
1373 * txd - A pointer to the last TxD which is used by the frame.
1374 * Out
1375 * Returns nothing.
1377 ************************/
1378 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
1380 struct sk_buff *skb;
1382 pr_debug(KERN_INFO "entering mac_drv_tx_complete\n");
1383 // Check if this TxD points to a skb
1385 if (!(skb = txd->txd_os.skb)) {
1386 pr_debug("TXD with no skb assigned.\n");
1387 return;
1389 txd->txd_os.skb = NULL;
1391 // release the DMA mapping
1392 pci_unmap_single(&smc->os.pdev, txd->txd_os.dma_addr,
1393 skb->len, PCI_DMA_TODEVICE);
1394 txd->txd_os.dma_addr = 0;
1396 smc->os.MacStat.gen.tx_packets++; // Count transmitted packets.
1397 smc->os.MacStat.gen.tx_bytes+=skb->len; // Count bytes
1399 // free the skb
1400 dev_kfree_skb_irq(skb);
1402 pr_debug(KERN_INFO "leaving mac_drv_tx_complete\n");
1403 } // mac_drv_tx_complete
1406 /************************
1408 * dump packets to logfile
1410 ************************/
1411 #ifdef DUMPPACKETS
1412 void dump_data(unsigned char *Data, int length)
1414 int i, j;
1415 unsigned char s[255], sh[10];
1416 if (length > 64) {
1417 length = 64;
1419 printk(KERN_INFO "---Packet start---\n");
1420 for (i = 0, j = 0; i < length / 8; i++, j += 8)
1421 printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\n",
1422 Data[j + 0], Data[j + 1], Data[j + 2], Data[j + 3],
1423 Data[j + 4], Data[j + 5], Data[j + 6], Data[j + 7]);
1424 strcpy(s, "");
1425 for (i = 0; i < length % 8; i++) {
1426 sprintf(sh, "%02x ", Data[j + i]);
1427 strcat(s, sh);
1429 printk(KERN_INFO "%s\n", s);
1430 printk(KERN_INFO "------------------\n");
1431 } // dump_data
1432 #else
1433 #define dump_data(data,len)
1434 #endif // DUMPPACKETS
1436 /************************
1438 * mac_drv_rx_complete
1440 * The hardware module calls this function if an LLC frame is received
1441 * in a receive buffer. Also the SMT, NSA, and directed beacon frames
1442 * from the network will be passed to the LLC layer by this function
1443 * if passing is enabled.
1445 * mac_drv_rx_complete forwards the frame to the LLC layer if it should
1446 * be received. It also fills the RxD ring with new receive buffers if
1447 * some can be queued.
1448 * Args
1449 * smc - A pointer to the SMT context struct.
1451 * rxd - A pointer to the first RxD which is used by the receive frame.
1453 * frag_count - Count of RxDs used by the received frame.
1455 * len - Frame length.
1456 * Out
1457 * Nothing.
1459 ************************/
1460 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1461 int frag_count, int len)
1463 skfddi_priv *bp = &smc->os;
1464 struct sk_buff *skb;
1465 unsigned char *virt, *cp;
1466 unsigned short ri;
1467 u_int RifLength;
1469 pr_debug(KERN_INFO "entering mac_drv_rx_complete (len=%d)\n", len);
1470 if (frag_count != 1) { // This is not allowed to happen.
1472 printk("fddi: Multi-fragment receive!\n");
1473 goto RequeueRxd; // Re-use the given RXD(s).
1476 skb = rxd->rxd_os.skb;
1477 if (!skb) {
1478 pr_debug(KERN_INFO "No skb in rxd\n");
1479 smc->os.MacStat.gen.rx_errors++;
1480 goto RequeueRxd;
1482 virt = skb->data;
1484 // The DMA mapping was released in dma_complete above.
1486 dump_data(skb->data, len);
1489 * FDDI Frame format:
1490 * +-------+-------+-------+------------+--------+------------+
1491 * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] |
1492 * +-------+-------+-------+------------+--------+------------+
1494 * FC = Frame Control
1495 * DA = Destination Address
1496 * SA = Source Address
1497 * RIF = Routing Information Field
1498 * LLC = Logical Link Control
1501 // Remove Routing Information Field (RIF), if present.
1503 if ((virt[1 + 6] & FDDI_RII) == 0)
1504 RifLength = 0;
1505 else {
1506 int n;
1507 // goos: RIF removal has still to be tested
1508 pr_debug(KERN_INFO "RIF found\n");
1509 // Get RIF length from Routing Control (RC) field.
1510 cp = virt + FDDI_MAC_HDR_LEN; // Point behind MAC header.
1512 ri = ntohs(*((__be16 *) cp));
1513 RifLength = ri & FDDI_RCF_LEN_MASK;
1514 if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) {
1515 printk("fddi: Invalid RIF.\n");
1516 goto RequeueRxd; // Discard the frame.
1519 virt[1 + 6] &= ~FDDI_RII; // Clear RII bit.
1520 // regions overlap
1522 virt = cp + RifLength;
1523 for (n = FDDI_MAC_HDR_LEN; n; n--)
1524 *--virt = *--cp;
1525 // adjust sbd->data pointer
1526 skb_pull(skb, RifLength);
1527 len -= RifLength;
1528 RifLength = 0;
1531 // Count statistics.
1532 smc->os.MacStat.gen.rx_packets++; // Count indicated receive
1533 // packets.
1534 smc->os.MacStat.gen.rx_bytes+=len; // Count bytes.
1536 // virt points to header again
1537 if (virt[1] & 0x01) { // Check group (multicast) bit.
1539 smc->os.MacStat.gen.multicast++;
1542 // deliver frame to system
1543 rxd->rxd_os.skb = NULL;
1544 skb_trim(skb, len);
1545 skb->protocol = fddi_type_trans(skb, bp->dev);
1547 netif_rx(skb);
1549 HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
1550 return;
1552 RequeueRxd:
1553 pr_debug(KERN_INFO "Rx: re-queue RXD.\n");
1554 mac_drv_requeue_rxd(smc, rxd, frag_count);
1555 smc->os.MacStat.gen.rx_errors++; // Count receive packets
1556 // not indicated.
1558 } // mac_drv_rx_complete
1561 /************************
1563 * mac_drv_requeue_rxd
1565 * The hardware module calls this function to request the OS-specific
1566 * module to queue the receive buffer(s) represented by the pointer
1567 * to the RxD and the frag_count into the receive queue again. This
1568 * buffer was filled with an invalid frame or an SMT frame.
1569 * Args
1570 * smc - A pointer to the SMT context struct.
1572 * rxd - A pointer to the first RxD which is used by the receive frame.
1574 * frag_count - Count of RxDs used by the received frame.
1575 * Out
1576 * Nothing.
1578 ************************/
1579 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1580 int frag_count)
1582 volatile struct s_smt_fp_rxd *next_rxd;
1583 volatile struct s_smt_fp_rxd *src_rxd;
1584 struct sk_buff *skb;
1585 int MaxFrameSize;
1586 unsigned char *v_addr;
1587 dma_addr_t b_addr;
1589 if (frag_count != 1) // This is not allowed to happen.
1591 printk("fddi: Multi-fragment requeue!\n");
1593 MaxFrameSize = smc->os.MaxFrameSize;
1594 src_rxd = rxd;
1595 for (; frag_count > 0; frag_count--) {
1596 next_rxd = src_rxd->rxd_next;
1597 rxd = HWM_GET_CURR_RXD(smc);
1599 skb = src_rxd->rxd_os.skb;
1600 if (skb == NULL) { // this should not happen
1602 pr_debug("Requeue with no skb in rxd!\n");
1603 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1604 if (skb) {
1605 // we got a skb
1606 rxd->rxd_os.skb = skb;
1607 skb_reserve(skb, 3);
1608 skb_put(skb, MaxFrameSize);
1609 v_addr = skb->data;
1610 b_addr = pci_map_single(&smc->os.pdev,
1611 v_addr,
1612 MaxFrameSize,
1613 PCI_DMA_FROMDEVICE);
1614 rxd->rxd_os.dma_addr = b_addr;
1615 } else {
1616 // no skb available, use local buffer
1617 pr_debug("Queueing invalid buffer!\n");
1618 rxd->rxd_os.skb = NULL;
1619 v_addr = smc->os.LocalRxBuffer;
1620 b_addr = smc->os.LocalRxBufferDMA;
1622 } else {
1623 // we use skb from old rxd
1624 rxd->rxd_os.skb = skb;
1625 v_addr = skb->data;
1626 b_addr = pci_map_single(&smc->os.pdev,
1627 v_addr,
1628 MaxFrameSize,
1629 PCI_DMA_FROMDEVICE);
1630 rxd->rxd_os.dma_addr = b_addr;
1632 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1633 FIRST_FRAG | LAST_FRAG);
1635 src_rxd = next_rxd;
1637 } // mac_drv_requeue_rxd
1640 /************************
1642 * mac_drv_fill_rxd
1644 * The hardware module calls this function at initialization time
1645 * to fill the RxD ring with receive buffers. It is also called by
1646 * mac_drv_rx_complete if rx_free is large enough to queue some new
1647 * receive buffers into the RxD ring. mac_drv_fill_rxd queues new
1648 * receive buffers as long as enough RxDs and receive buffers are
1649 * available.
1650 * Args
1651 * smc - A pointer to the SMT context struct.
1652 * Out
1653 * Nothing.
1655 ************************/
1656 void mac_drv_fill_rxd(struct s_smc *smc)
1658 int MaxFrameSize;
1659 unsigned char *v_addr;
1660 unsigned long b_addr;
1661 struct sk_buff *skb;
1662 volatile struct s_smt_fp_rxd *rxd;
1664 pr_debug(KERN_INFO "entering mac_drv_fill_rxd\n");
1666 // Walk through the list of free receive buffers, passing receive
1667 // buffers to the HWM as long as RXDs are available.
1669 MaxFrameSize = smc->os.MaxFrameSize;
1670 // Check if there is any RXD left.
1671 while (HWM_GET_RX_FREE(smc) > 0) {
1672 pr_debug(KERN_INFO ".\n");
1674 rxd = HWM_GET_CURR_RXD(smc);
1675 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1676 if (skb) {
1677 // we got a skb
1678 skb_reserve(skb, 3);
1679 skb_put(skb, MaxFrameSize);
1680 v_addr = skb->data;
1681 b_addr = pci_map_single(&smc->os.pdev,
1682 v_addr,
1683 MaxFrameSize,
1684 PCI_DMA_FROMDEVICE);
1685 rxd->rxd_os.dma_addr = b_addr;
1686 } else {
1687 // no skb available, use local buffer
1688 // System has run out of buffer memory, but we want to
1689 // keep the receiver running in hope of better times.
1690 // Multiple descriptors may point to this local buffer,
1691 // so data in it must be considered invalid.
1692 pr_debug("Queueing invalid buffer!\n");
1693 v_addr = smc->os.LocalRxBuffer;
1694 b_addr = smc->os.LocalRxBufferDMA;
1697 rxd->rxd_os.skb = skb;
1699 // Pass receive buffer to HWM.
1700 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1701 FIRST_FRAG | LAST_FRAG);
1703 pr_debug(KERN_INFO "leaving mac_drv_fill_rxd\n");
1704 } // mac_drv_fill_rxd
1707 /************************
1709 * mac_drv_clear_rxd
1711 * The hardware module calls this function to release unused
1712 * receive buffers.
1713 * Args
1714 * smc - A pointer to the SMT context struct.
1716 * rxd - A pointer to the first RxD which is used by the receive buffer.
1718 * frag_count - Count of RxDs used by the receive buffer.
1719 * Out
1720 * Nothing.
1722 ************************/
1723 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1724 int frag_count)
1727 struct sk_buff *skb;
1729 pr_debug("entering mac_drv_clear_rxd\n");
1731 if (frag_count != 1) // This is not allowed to happen.
1733 printk("fddi: Multi-fragment clear!\n");
1735 for (; frag_count > 0; frag_count--) {
1736 skb = rxd->rxd_os.skb;
1737 if (skb != NULL) {
1738 skfddi_priv *bp = &smc->os;
1739 int MaxFrameSize = bp->MaxFrameSize;
1741 pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr,
1742 MaxFrameSize, PCI_DMA_FROMDEVICE);
1744 dev_kfree_skb(skb);
1745 rxd->rxd_os.skb = NULL;
1747 rxd = rxd->rxd_next; // Next RXD.
1750 } // mac_drv_clear_rxd
1753 /************************
1755 * mac_drv_rx_init
1757 * The hardware module calls this routine when an SMT or NSA frame of the
1758 * local SMT should be delivered to the LLC layer.
1760 * It is necessary to have this function, because there is no other way to
1761 * copy the contents of SMT MBufs into receive buffers.
1763 * mac_drv_rx_init allocates the required target memory for this frame,
1764 * and receives the frame fragment by fragment by calling mac_drv_rx_frag.
1765 * Args
1766 * smc - A pointer to the SMT context struct.
1768 * len - The length (in bytes) of the received frame (FC, DA, SA, Data).
1770 * fc - The Frame Control field of the received frame.
1772 * look_ahead - A pointer to the lookahead data buffer (may be NULL).
1774 * la_len - The length of the lookahead data stored in the lookahead
1775 * buffer (may be zero).
1776 * Out
1777 * Always returns zero (0).
1779 ************************/
1780 int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
1781 char *look_ahead, int la_len)
1783 struct sk_buff *skb;
1785 pr_debug("entering mac_drv_rx_init(len=%d)\n", len);
1787 // "Received" a SMT or NSA frame of the local SMT.
1789 if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) {
1790 pr_debug("fddi: Discard invalid local SMT frame\n");
1791 pr_debug(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n",
1792 len, la_len, (unsigned long) look_ahead);
1793 return (0);
1795 skb = alloc_skb(len + 3, GFP_ATOMIC);
1796 if (!skb) {
1797 pr_debug("fddi: Local SMT: skb memory exhausted.\n");
1798 return (0);
1800 skb_reserve(skb, 3);
1801 skb_put(skb, len);
1802 skb_copy_to_linear_data(skb, look_ahead, len);
1804 // deliver frame to system
1805 skb->protocol = fddi_type_trans(skb, smc->os.dev);
1806 netif_rx(skb);
1808 return (0);
1809 } // mac_drv_rx_init
1812 /************************
1814 * smt_timer_poll
1816 * This routine is called periodically by the SMT module to clean up the
1817 * driver.
1819 * Return any queued frames back to the upper protocol layers if the ring
1820 * is down.
1821 * Args
1822 * smc - A pointer to the SMT context struct.
1823 * Out
1824 * Nothing.
1826 ************************/
1827 void smt_timer_poll(struct s_smc *smc)
1829 } // smt_timer_poll
1832 /************************
1834 * ring_status_indication
1836 * This function indicates a change of the ring state.
1837 * Args
1838 * smc - A pointer to the SMT context struct.
1840 * status - The current ring status.
1841 * Out
1842 * Nothing.
1844 ************************/
1845 void ring_status_indication(struct s_smc *smc, u_long status)
1847 pr_debug("ring_status_indication( ");
1848 if (status & RS_RES15)
1849 pr_debug("RS_RES15 ");
1850 if (status & RS_HARDERROR)
1851 pr_debug("RS_HARDERROR ");
1852 if (status & RS_SOFTERROR)
1853 pr_debug("RS_SOFTERROR ");
1854 if (status & RS_BEACON)
1855 pr_debug("RS_BEACON ");
1856 if (status & RS_PATHTEST)
1857 pr_debug("RS_PATHTEST ");
1858 if (status & RS_SELFTEST)
1859 pr_debug("RS_SELFTEST ");
1860 if (status & RS_RES9)
1861 pr_debug("RS_RES9 ");
1862 if (status & RS_DISCONNECT)
1863 pr_debug("RS_DISCONNECT ");
1864 if (status & RS_RES7)
1865 pr_debug("RS_RES7 ");
1866 if (status & RS_DUPADDR)
1867 pr_debug("RS_DUPADDR ");
1868 if (status & RS_NORINGOP)
1869 pr_debug("RS_NORINGOP ");
1870 if (status & RS_VERSION)
1871 pr_debug("RS_VERSION ");
1872 if (status & RS_STUCKBYPASSS)
1873 pr_debug("RS_STUCKBYPASSS ");
1874 if (status & RS_EVENT)
1875 pr_debug("RS_EVENT ");
1876 if (status & RS_RINGOPCHANGE)
1877 pr_debug("RS_RINGOPCHANGE ");
1878 if (status & RS_RES0)
1879 pr_debug("RS_RES0 ");
1880 pr_debug("]\n");
1881 } // ring_status_indication
1884 /************************
1886 * smt_get_time
1888 * Gets the current time from the system.
1889 * Args
1890 * None.
1891 * Out
1892 * The current time in TICKS_PER_SECOND.
1894 * TICKS_PER_SECOND has the unit 'count of timer ticks per second'. It is
1895 * defined in "targetos.h". The definition of TICKS_PER_SECOND must comply
1896 * to the time returned by smt_get_time().
1898 ************************/
1899 unsigned long smt_get_time(void)
1901 return jiffies;
1902 } // smt_get_time
1905 /************************
1907 * smt_stat_counter
1909 * Status counter update (ring_op, fifo full).
1910 * Args
1911 * smc - A pointer to the SMT context struct.
1913 * stat - = 0: A ring operational change occurred.
1914 * = 1: The FORMAC FIFO buffer is full / FIFO overflow.
1915 * Out
1916 * Nothing.
1918 ************************/
1919 void smt_stat_counter(struct s_smc *smc, int stat)
1921 // BOOLEAN RingIsUp ;
1923 pr_debug(KERN_INFO "smt_stat_counter\n");
1924 switch (stat) {
1925 case 0:
1926 pr_debug(KERN_INFO "Ring operational change.\n");
1927 break;
1928 case 1:
1929 pr_debug(KERN_INFO "Receive fifo overflow.\n");
1930 smc->os.MacStat.gen.rx_errors++;
1931 break;
1932 default:
1933 pr_debug(KERN_INFO "Unknown status (%d).\n", stat);
1934 break;
1936 } // smt_stat_counter
1939 /************************
1941 * cfm_state_change
1943 * Sets CFM state in custom statistics.
1944 * Args
1945 * smc - A pointer to the SMT context struct.
1947 * c_state - Possible values are:
1949 * EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST,
1950 * EC5_INSERT, EC6_CHECK, EC7_DEINSERT
1951 * Out
1952 * Nothing.
1954 ************************/
1955 void cfm_state_change(struct s_smc *smc, int c_state)
1957 #ifdef DRIVERDEBUG
1958 char *s;
1960 switch (c_state) {
1961 case SC0_ISOLATED:
1962 s = "SC0_ISOLATED";
1963 break;
1964 case SC1_WRAP_A:
1965 s = "SC1_WRAP_A";
1966 break;
1967 case SC2_WRAP_B:
1968 s = "SC2_WRAP_B";
1969 break;
1970 case SC4_THRU_A:
1971 s = "SC4_THRU_A";
1972 break;
1973 case SC5_THRU_B:
1974 s = "SC5_THRU_B";
1975 break;
1976 case SC7_WRAP_S:
1977 s = "SC7_WRAP_S";
1978 break;
1979 case SC9_C_WRAP_A:
1980 s = "SC9_C_WRAP_A";
1981 break;
1982 case SC10_C_WRAP_B:
1983 s = "SC10_C_WRAP_B";
1984 break;
1985 case SC11_C_WRAP_S:
1986 s = "SC11_C_WRAP_S";
1987 break;
1988 default:
1989 pr_debug(KERN_INFO "cfm_state_change: unknown %d\n", c_state);
1990 return;
1992 pr_debug(KERN_INFO "cfm_state_change: %s\n", s);
1993 #endif // DRIVERDEBUG
1994 } // cfm_state_change
1997 /************************
1999 * ecm_state_change
2001 * Sets ECM state in custom statistics.
2002 * Args
2003 * smc - A pointer to the SMT context struct.
2005 * e_state - Possible values are:
2007 * SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12),
2008 * SC5_THRU_B (7), SC7_WRAP_S (8)
2009 * Out
2010 * Nothing.
2012 ************************/
2013 void ecm_state_change(struct s_smc *smc, int e_state)
2015 #ifdef DRIVERDEBUG
2016 char *s;
2018 switch (e_state) {
2019 case EC0_OUT:
2020 s = "EC0_OUT";
2021 break;
2022 case EC1_IN:
2023 s = "EC1_IN";
2024 break;
2025 case EC2_TRACE:
2026 s = "EC2_TRACE";
2027 break;
2028 case EC3_LEAVE:
2029 s = "EC3_LEAVE";
2030 break;
2031 case EC4_PATH_TEST:
2032 s = "EC4_PATH_TEST";
2033 break;
2034 case EC5_INSERT:
2035 s = "EC5_INSERT";
2036 break;
2037 case EC6_CHECK:
2038 s = "EC6_CHECK";
2039 break;
2040 case EC7_DEINSERT:
2041 s = "EC7_DEINSERT";
2042 break;
2043 default:
2044 s = "unknown";
2045 break;
2047 pr_debug(KERN_INFO "ecm_state_change: %s\n", s);
2048 #endif //DRIVERDEBUG
2049 } // ecm_state_change
2052 /************************
2054 * rmt_state_change
2056 * Sets RMT state in custom statistics.
2057 * Args
2058 * smc - A pointer to the SMT context struct.
2060 * r_state - Possible values are:
2062 * RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT,
2063 * RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE
2064 * Out
2065 * Nothing.
2067 ************************/
2068 void rmt_state_change(struct s_smc *smc, int r_state)
2070 #ifdef DRIVERDEBUG
2071 char *s;
2073 switch (r_state) {
2074 case RM0_ISOLATED:
2075 s = "RM0_ISOLATED";
2076 break;
2077 case RM1_NON_OP:
2078 s = "RM1_NON_OP - not operational";
2079 break;
2080 case RM2_RING_OP:
2081 s = "RM2_RING_OP - ring operational";
2082 break;
2083 case RM3_DETECT:
2084 s = "RM3_DETECT - detect dupl addresses";
2085 break;
2086 case RM4_NON_OP_DUP:
2087 s = "RM4_NON_OP_DUP - dupl. addr detected";
2088 break;
2089 case RM5_RING_OP_DUP:
2090 s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
2091 break;
2092 case RM6_DIRECTED:
2093 s = "RM6_DIRECTED - sending directed beacons";
2094 break;
2095 case RM7_TRACE:
2096 s = "RM7_TRACE - trace initiated";
2097 break;
2098 default:
2099 s = "unknown";
2100 break;
2102 pr_debug(KERN_INFO "[rmt_state_change: %s]\n", s);
2103 #endif // DRIVERDEBUG
2104 } // rmt_state_change
2107 /************************
2109 * drv_reset_indication
2111 * This function is called by the SMT when it has detected a severe
2112 * hardware problem. The driver should perform a reset on the adapter
2113 * as soon as possible, but not from within this function.
2114 * Args
2115 * smc - A pointer to the SMT context struct.
2116 * Out
2117 * Nothing.
2119 ************************/
2120 void drv_reset_indication(struct s_smc *smc)
2122 pr_debug(KERN_INFO "entering drv_reset_indication\n");
2124 smc->os.ResetRequested = TRUE; // Set flag.
2126 } // drv_reset_indication
2128 static struct pci_driver skfddi_pci_driver = {
2129 .name = "skfddi",
2130 .id_table = skfddi_pci_tbl,
2131 .probe = skfp_init_one,
2132 .remove = __devexit_p(skfp_remove_one),
2135 static int __init skfd_init(void)
2137 return pci_register_driver(&skfddi_pci_driver);
2140 static void __exit skfd_exit(void)
2142 pci_unregister_driver(&skfddi_pci_driver);
2145 module_init(skfd_init);
2146 module_exit(skfd_exit);