iscsi_ibft.c fix compilation warning
[linux-2.6/btrfs-unstable.git] / drivers / net / skfp / skfddi.c
blob9a00e5566af74db199d2625db4903ecd58e3b9e8
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
171 static const struct net_device_ops skfp_netdev_ops = {
172 .ndo_open = skfp_open,
173 .ndo_stop = skfp_close,
174 .ndo_start_xmit = skfp_send_pkt,
175 .ndo_get_stats = skfp_ctl_get_stats,
176 .ndo_change_mtu = fddi_change_mtu,
177 .ndo_set_multicast_list = skfp_ctl_set_multicast_list,
178 .ndo_set_mac_address = skfp_ctl_set_mac_address,
179 .ndo_do_ioctl = skfp_ioctl,
183 * =================
184 * = skfp_init_one =
185 * =================
187 * Overview:
188 * Probes for supported FDDI PCI controllers
190 * Returns:
191 * Condition code
193 * Arguments:
194 * pdev - pointer to PCI device information
196 * Functional Description:
197 * This is now called by PCI driver registration process
198 * for each board found.
200 * Return Codes:
201 * 0 - This device (fddi0, fddi1, etc) configured successfully
202 * -ENODEV - No devices present, or no SysKonnect FDDI PCI device
203 * present for this device name
206 * Side Effects:
207 * Device structures for FDDI adapters (fddi0, fddi1, etc) are
208 * initialized and the board resources are read and stored in
209 * the device structure.
211 static int skfp_init_one(struct pci_dev *pdev,
212 const struct pci_device_id *ent)
214 struct net_device *dev;
215 struct s_smc *smc; /* board pointer */
216 void __iomem *mem;
217 int err;
219 PRINTK(KERN_INFO "entering skfp_init_one\n");
221 if (num_boards == 0)
222 printk("%s\n", boot_msg);
224 err = pci_enable_device(pdev);
225 if (err)
226 return err;
228 err = pci_request_regions(pdev, "skfddi");
229 if (err)
230 goto err_out1;
232 pci_set_master(pdev);
234 #ifdef MEM_MAPPED_IO
235 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
236 printk(KERN_ERR "skfp: region is not an MMIO resource\n");
237 err = -EIO;
238 goto err_out2;
241 mem = ioremap(pci_resource_start(pdev, 0), 0x4000);
242 #else
243 if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) {
244 printk(KERN_ERR "skfp: region is not PIO resource\n");
245 err = -EIO;
246 goto err_out2;
249 mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN);
250 #endif
251 if (!mem) {
252 printk(KERN_ERR "skfp: Unable to map register, "
253 "FDDI adapter will be disabled.\n");
254 err = -EIO;
255 goto err_out2;
258 dev = alloc_fddidev(sizeof(struct s_smc));
259 if (!dev) {
260 printk(KERN_ERR "skfp: Unable to allocate fddi device, "
261 "FDDI adapter will be disabled.\n");
262 err = -ENOMEM;
263 goto err_out3;
266 dev->irq = pdev->irq;
267 dev->netdev_ops = &skfp_netdev_ops;
269 SET_NETDEV_DEV(dev, &pdev->dev);
271 /* Initialize board structure with bus-specific info */
272 smc = netdev_priv(dev);
273 smc->os.dev = dev;
274 smc->os.bus_type = SK_BUS_TYPE_PCI;
275 smc->os.pdev = *pdev;
276 smc->os.QueueSkb = MAX_TX_QUEUE_LEN;
277 smc->os.MaxFrameSize = MAX_FRAME_SIZE;
278 smc->os.dev = dev;
279 smc->hw.slot = -1;
280 smc->hw.iop = mem;
281 smc->os.ResetRequested = FALSE;
282 skb_queue_head_init(&smc->os.SendSkbQueue);
284 dev->base_addr = (unsigned long)mem;
286 err = skfp_driver_init(dev);
287 if (err)
288 goto err_out4;
290 err = register_netdev(dev);
291 if (err)
292 goto err_out5;
294 ++num_boards;
295 pci_set_drvdata(pdev, dev);
297 if ((pdev->subsystem_device & 0xff00) == 0x5500 ||
298 (pdev->subsystem_device & 0xff00) == 0x5800)
299 printk("%s: SysKonnect FDDI PCI adapter"
300 " found (SK-%04X)\n", dev->name,
301 pdev->subsystem_device);
302 else
303 printk("%s: FDDI PCI adapter found\n", dev->name);
305 return 0;
306 err_out5:
307 if (smc->os.SharedMemAddr)
308 pci_free_consistent(pdev, smc->os.SharedMemSize,
309 smc->os.SharedMemAddr,
310 smc->os.SharedMemDMA);
311 pci_free_consistent(pdev, MAX_FRAME_SIZE,
312 smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA);
313 err_out4:
314 free_netdev(dev);
315 err_out3:
316 #ifdef MEM_MAPPED_IO
317 iounmap(mem);
318 #else
319 ioport_unmap(mem);
320 #endif
321 err_out2:
322 pci_release_regions(pdev);
323 err_out1:
324 pci_disable_device(pdev);
325 return err;
329 * Called for each adapter board from pci_unregister_driver
331 static void __devexit skfp_remove_one(struct pci_dev *pdev)
333 struct net_device *p = pci_get_drvdata(pdev);
334 struct s_smc *lp = netdev_priv(p);
336 unregister_netdev(p);
338 if (lp->os.SharedMemAddr) {
339 pci_free_consistent(&lp->os.pdev,
340 lp->os.SharedMemSize,
341 lp->os.SharedMemAddr,
342 lp->os.SharedMemDMA);
343 lp->os.SharedMemAddr = NULL;
345 if (lp->os.LocalRxBuffer) {
346 pci_free_consistent(&lp->os.pdev,
347 MAX_FRAME_SIZE,
348 lp->os.LocalRxBuffer,
349 lp->os.LocalRxBufferDMA);
350 lp->os.LocalRxBuffer = NULL;
352 #ifdef MEM_MAPPED_IO
353 iounmap(lp->hw.iop);
354 #else
355 ioport_unmap(lp->hw.iop);
356 #endif
357 pci_release_regions(pdev);
358 free_netdev(p);
360 pci_disable_device(pdev);
361 pci_set_drvdata(pdev, NULL);
365 * ====================
366 * = skfp_driver_init =
367 * ====================
369 * Overview:
370 * Initializes remaining adapter board structure information
371 * and makes sure adapter is in a safe state prior to skfp_open().
373 * Returns:
374 * Condition code
376 * Arguments:
377 * dev - pointer to device information
379 * Functional Description:
380 * This function allocates additional resources such as the host memory
381 * blocks needed by the adapter.
382 * The adapter is also reset. The OS must call skfp_open() to open
383 * the adapter and bring it on-line.
385 * Return Codes:
386 * 0 - initialization succeeded
387 * -1 - initialization failed
389 static int skfp_driver_init(struct net_device *dev)
391 struct s_smc *smc = netdev_priv(dev);
392 skfddi_priv *bp = &smc->os;
393 int err = -EIO;
395 PRINTK(KERN_INFO "entering skfp_driver_init\n");
397 // set the io address in private structures
398 bp->base_addr = dev->base_addr;
400 // Get the interrupt level from the PCI Configuration Table
401 smc->hw.irq = dev->irq;
403 spin_lock_init(&bp->DriverLock);
405 // Allocate invalid frame
406 bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA);
407 if (!bp->LocalRxBuffer) {
408 printk("could not allocate mem for ");
409 printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
410 goto fail;
413 // Determine the required size of the 'shared' memory area.
414 bp->SharedMemSize = mac_drv_check_space();
415 PRINTK(KERN_INFO "Memory for HWM: %ld\n", bp->SharedMemSize);
416 if (bp->SharedMemSize > 0) {
417 bp->SharedMemSize += 16; // for descriptor alignment
419 bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev,
420 bp->SharedMemSize,
421 &bp->SharedMemDMA);
422 if (!bp->SharedMemSize) {
423 printk("could not allocate mem for ");
424 printk("hardware module: %ld byte\n",
425 bp->SharedMemSize);
426 goto fail;
428 bp->SharedMemHeap = 0; // Nothing used yet.
430 } else {
431 bp->SharedMemAddr = NULL;
432 bp->SharedMemHeap = 0;
433 } // SharedMemSize > 0
435 memset(bp->SharedMemAddr, 0, bp->SharedMemSize);
437 card_stop(smc); // Reset adapter.
439 PRINTK(KERN_INFO "mac_drv_init()..\n");
440 if (mac_drv_init(smc) != 0) {
441 PRINTK(KERN_INFO "mac_drv_init() failed.\n");
442 goto fail;
444 read_address(smc, NULL);
445 PRINTK(KERN_INFO "HW-Addr: %02x %02x %02x %02x %02x %02x\n",
446 smc->hw.fddi_canon_addr.a[0],
447 smc->hw.fddi_canon_addr.a[1],
448 smc->hw.fddi_canon_addr.a[2],
449 smc->hw.fddi_canon_addr.a[3],
450 smc->hw.fddi_canon_addr.a[4],
451 smc->hw.fddi_canon_addr.a[5]);
452 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
454 smt_reset_defaults(smc, 0);
456 return (0);
458 fail:
459 if (bp->SharedMemAddr) {
460 pci_free_consistent(&bp->pdev,
461 bp->SharedMemSize,
462 bp->SharedMemAddr,
463 bp->SharedMemDMA);
464 bp->SharedMemAddr = NULL;
466 if (bp->LocalRxBuffer) {
467 pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE,
468 bp->LocalRxBuffer, bp->LocalRxBufferDMA);
469 bp->LocalRxBuffer = NULL;
471 return err;
472 } // skfp_driver_init
476 * =============
477 * = skfp_open =
478 * =============
480 * Overview:
481 * Opens the adapter
483 * Returns:
484 * Condition code
486 * Arguments:
487 * dev - pointer to device information
489 * Functional Description:
490 * This function brings the adapter to an operational state.
492 * Return Codes:
493 * 0 - Adapter was successfully opened
494 * -EAGAIN - Could not register IRQ
496 static int skfp_open(struct net_device *dev)
498 struct s_smc *smc = netdev_priv(dev);
499 int err;
501 PRINTK(KERN_INFO "entering skfp_open\n");
502 /* Register IRQ - support shared interrupts by passing device ptr */
503 err = request_irq(dev->irq, skfp_interrupt, IRQF_SHARED,
504 dev->name, dev);
505 if (err)
506 return err;
509 * Set current address to factory MAC address
511 * Note: We've already done this step in skfp_driver_init.
512 * However, it's possible that a user has set a node
513 * address override, then closed and reopened the
514 * adapter. Unless we reset the device address field
515 * now, we'll continue to use the existing modified
516 * address.
518 read_address(smc, NULL);
519 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
521 init_smt(smc, NULL);
522 smt_online(smc, 1);
523 STI_FBI();
525 /* Clear local multicast address tables */
526 mac_clear_multicast(smc);
528 /* Disable promiscuous filter settings */
529 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
531 netif_start_queue(dev);
532 return (0);
533 } // skfp_open
537 * ==============
538 * = skfp_close =
539 * ==============
541 * Overview:
542 * Closes the device/module.
544 * Returns:
545 * Condition code
547 * Arguments:
548 * dev - pointer to device information
550 * Functional Description:
551 * This routine closes the adapter and brings it to a safe state.
552 * The interrupt service routine is deregistered with the OS.
553 * The adapter can be opened again with another call to skfp_open().
555 * Return Codes:
556 * Always return 0.
558 * Assumptions:
559 * No further requests for this adapter are made after this routine is
560 * called. skfp_open() can be called to reset and reinitialize the
561 * adapter.
563 static int skfp_close(struct net_device *dev)
565 struct s_smc *smc = netdev_priv(dev);
566 skfddi_priv *bp = &smc->os;
568 CLI_FBI();
569 smt_reset_defaults(smc, 1);
570 card_stop(smc);
571 mac_drv_clear_tx_queue(smc);
572 mac_drv_clear_rx_queue(smc);
574 netif_stop_queue(dev);
575 /* Deregister (free) IRQ */
576 free_irq(dev->irq, dev);
578 skb_queue_purge(&bp->SendSkbQueue);
579 bp->QueueSkb = MAX_TX_QUEUE_LEN;
581 return (0);
582 } // skfp_close
586 * ==================
587 * = skfp_interrupt =
588 * ==================
590 * Overview:
591 * Interrupt processing routine
593 * Returns:
594 * None
596 * Arguments:
597 * irq - interrupt vector
598 * dev_id - pointer to device information
600 * Functional Description:
601 * This routine calls the interrupt processing routine for this adapter. It
602 * disables and reenables adapter interrupts, as appropriate. We can support
603 * shared interrupts since the incoming dev_id pointer provides our device
604 * structure context. All the real work is done in the hardware module.
606 * Return Codes:
607 * None
609 * Assumptions:
610 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
611 * on Intel-based systems) is done by the operating system outside this
612 * routine.
614 * System interrupts are enabled through this call.
616 * Side Effects:
617 * Interrupts are disabled, then reenabled at the adapter.
620 static irqreturn_t skfp_interrupt(int irq, void *dev_id)
622 struct net_device *dev = dev_id;
623 struct s_smc *smc; /* private board structure pointer */
624 skfddi_priv *bp;
626 smc = netdev_priv(dev);
627 bp = &smc->os;
629 // IRQs enabled or disabled ?
630 if (inpd(ADDR(B0_IMSK)) == 0) {
631 // IRQs are disabled: must be shared interrupt
632 return IRQ_NONE;
634 // Note: At this point, IRQs are enabled.
635 if ((inpd(ISR_A) & smc->hw.is_imask) == 0) { // IRQ?
636 // Adapter did not issue an IRQ: must be shared interrupt
637 return IRQ_NONE;
639 CLI_FBI(); // Disable IRQs from our adapter.
640 spin_lock(&bp->DriverLock);
642 // Call interrupt handler in hardware module (HWM).
643 fddi_isr(smc);
645 if (smc->os.ResetRequested) {
646 ResetAdapter(smc);
647 smc->os.ResetRequested = FALSE;
649 spin_unlock(&bp->DriverLock);
650 STI_FBI(); // Enable IRQs from our adapter.
652 return IRQ_HANDLED;
653 } // skfp_interrupt
657 * ======================
658 * = skfp_ctl_get_stats =
659 * ======================
661 * Overview:
662 * Get statistics for FDDI adapter
664 * Returns:
665 * Pointer to FDDI statistics structure
667 * Arguments:
668 * dev - pointer to device information
670 * Functional Description:
671 * Gets current MIB objects from adapter, then
672 * returns FDDI statistics structure as defined
673 * in if_fddi.h.
675 * Note: Since the FDDI statistics structure is
676 * still new and the device structure doesn't
677 * have an FDDI-specific get statistics handler,
678 * we'll return the FDDI statistics structure as
679 * a pointer to an Ethernet statistics structure.
680 * That way, at least the first part of the statistics
681 * structure can be decoded properly.
682 * We'll have to pay attention to this routine as the
683 * device structure becomes more mature and LAN media
684 * independent.
687 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
689 struct s_smc *bp = netdev_priv(dev);
691 /* Fill the bp->stats structure with driver-maintained counters */
693 bp->os.MacStat.port_bs_flag[0] = 0x1234;
694 bp->os.MacStat.port_bs_flag[1] = 0x5678;
695 // goos: need to fill out fddi statistic
696 #if 0
697 /* Get FDDI SMT MIB objects */
699 /* Fill the bp->stats structure with the SMT MIB object values */
701 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));
702 bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
703 bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
704 bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
705 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));
706 bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
707 bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
708 bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
709 bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
710 bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
711 bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
712 bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
713 bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
714 bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
715 bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
716 bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
717 bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
718 bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
719 bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
720 bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
721 bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
722 bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
723 bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
724 bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
725 bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
726 bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
727 bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
728 bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
729 bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
730 memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
731 memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
732 memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
733 memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
734 bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
735 bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
736 bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
737 memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
738 bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
739 bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
740 bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
741 bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
742 bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
743 bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
744 bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
745 bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
746 bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
747 bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
748 bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
749 bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
750 bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
751 bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
752 bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
753 bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
754 memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
755 bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
756 bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
757 bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
758 bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
759 bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
760 bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
761 bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
762 bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
763 bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
764 bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
765 memcpy(&bp->stats.port_requested_paths[0 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
766 memcpy(&bp->stats.port_requested_paths[1 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
767 bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
768 bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
769 bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
770 bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
771 bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
772 bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
773 bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
774 bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
775 bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
776 bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
777 bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
778 bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
779 bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
780 bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
781 bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
782 bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
783 bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
784 bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
785 bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
786 bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
787 bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
788 bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
789 bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
790 bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
791 bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
792 bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
795 /* Fill the bp->stats structure with the FDDI counter values */
797 bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
798 bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
799 bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
800 bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
801 bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
802 bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
803 bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
804 bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
805 bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
806 bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
807 bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
809 #endif
810 return ((struct net_device_stats *) &bp->os.MacStat);
811 } // ctl_get_stat
815 * ==============================
816 * = skfp_ctl_set_multicast_list =
817 * ==============================
819 * Overview:
820 * Enable/Disable LLC frame promiscuous mode reception
821 * on the adapter and/or update multicast address table.
823 * Returns:
824 * None
826 * Arguments:
827 * dev - pointer to device information
829 * Functional Description:
830 * This function acquires the driver lock and only calls
831 * skfp_ctl_set_multicast_list_wo_lock then.
832 * This routine follows a fairly simple algorithm for setting the
833 * adapter filters and CAM:
835 * if IFF_PROMISC flag is set
836 * enable promiscuous mode
837 * else
838 * disable promiscuous mode
839 * if number of multicast addresses <= max. multicast number
840 * add mc addresses to adapter table
841 * else
842 * enable promiscuous mode
843 * update adapter filters
845 * Assumptions:
846 * Multicast addresses are presented in canonical (LSB) format.
848 * Side Effects:
849 * On-board adapter filters are updated.
851 static void skfp_ctl_set_multicast_list(struct net_device *dev)
853 struct s_smc *smc = netdev_priv(dev);
854 skfddi_priv *bp = &smc->os;
855 unsigned long Flags;
857 spin_lock_irqsave(&bp->DriverLock, Flags);
858 skfp_ctl_set_multicast_list_wo_lock(dev);
859 spin_unlock_irqrestore(&bp->DriverLock, Flags);
860 return;
861 } // skfp_ctl_set_multicast_list
865 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
867 struct s_smc *smc = netdev_priv(dev);
868 struct dev_mc_list *dmi; /* ptr to multicast addr entry */
869 int i;
871 /* Enable promiscuous mode, if necessary */
872 if (dev->flags & IFF_PROMISC) {
873 mac_drv_rx_mode(smc, RX_ENABLE_PROMISC);
874 PRINTK(KERN_INFO "PROMISCUOUS MODE ENABLED\n");
876 /* Else, update multicast address table */
877 else {
878 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
879 PRINTK(KERN_INFO "PROMISCUOUS MODE DISABLED\n");
881 // Reset all MC addresses
882 mac_clear_multicast(smc);
883 mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI);
885 if (dev->flags & IFF_ALLMULTI) {
886 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
887 PRINTK(KERN_INFO "ENABLE ALL MC ADDRESSES\n");
888 } else if (dev->mc_count > 0) {
889 if (dev->mc_count <= FPMAX_MULTICAST) {
890 /* use exact filtering */
892 // point to first multicast addr
893 dmi = dev->mc_list;
895 for (i = 0; i < dev->mc_count; i++) {
896 mac_add_multicast(smc,
897 (struct fddi_addr *)dmi->dmi_addr,
900 PRINTK(KERN_INFO "ENABLE MC ADDRESS:");
901 PRINTK(" %02x %02x %02x ",
902 dmi->dmi_addr[0],
903 dmi->dmi_addr[1],
904 dmi->dmi_addr[2]);
905 PRINTK("%02x %02x %02x\n",
906 dmi->dmi_addr[3],
907 dmi->dmi_addr[4],
908 dmi->dmi_addr[5]);
909 dmi = dmi->next;
910 } // for
912 } else { // more MC addresses than HW supports
914 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
915 PRINTK(KERN_INFO "ENABLE ALL MC ADDRESSES\n");
917 } else { // no MC addresses
919 PRINTK(KERN_INFO "DISABLE ALL MC ADDRESSES\n");
922 /* Update adapter filters */
923 mac_update_multicast(smc);
925 return;
926 } // skfp_ctl_set_multicast_list_wo_lock
930 * ===========================
931 * = skfp_ctl_set_mac_address =
932 * ===========================
934 * Overview:
935 * set new mac address on adapter and update dev_addr field in device table.
937 * Returns:
938 * None
940 * Arguments:
941 * dev - pointer to device information
942 * addr - pointer to sockaddr structure containing unicast address to set
944 * Assumptions:
945 * The address pointed to by addr->sa_data is a valid unicast
946 * address and is presented in canonical (LSB) format.
948 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
950 struct s_smc *smc = netdev_priv(dev);
951 struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
952 skfddi_priv *bp = &smc->os;
953 unsigned long Flags;
956 memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);
957 spin_lock_irqsave(&bp->DriverLock, Flags);
958 ResetAdapter(smc);
959 spin_unlock_irqrestore(&bp->DriverLock, Flags);
961 return (0); /* always return zero */
962 } // skfp_ctl_set_mac_address
966 * ==============
967 * = skfp_ioctl =
968 * ==============
970 * Overview:
972 * Perform IOCTL call functions here. Some are privileged operations and the
973 * effective uid is checked in those cases.
975 * Returns:
976 * status value
977 * 0 - success
978 * other - failure
980 * Arguments:
981 * dev - pointer to device information
982 * rq - pointer to ioctl request structure
983 * cmd - ?
988 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
990 struct s_smc *smc = netdev_priv(dev);
991 skfddi_priv *lp = &smc->os;
992 struct s_skfp_ioctl ioc;
993 int status = 0;
995 if (copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl)))
996 return -EFAULT;
998 switch (ioc.cmd) {
999 case SKFP_GET_STATS: /* Get the driver statistics */
1000 ioc.len = sizeof(lp->MacStat);
1001 status = copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len)
1002 ? -EFAULT : 0;
1003 break;
1004 case SKFP_CLR_STATS: /* Zero out the driver statistics */
1005 if (!capable(CAP_NET_ADMIN)) {
1006 status = -EPERM;
1007 } else {
1008 memset(&lp->MacStat, 0, sizeof(lp->MacStat));
1010 break;
1011 default:
1012 printk("ioctl for %s: unknow cmd: %04x\n", dev->name, ioc.cmd);
1013 status = -EOPNOTSUPP;
1015 } // switch
1017 return status;
1018 } // skfp_ioctl
1022 * =====================
1023 * = skfp_send_pkt =
1024 * =====================
1026 * Overview:
1027 * Queues a packet for transmission and try to transmit it.
1029 * Returns:
1030 * Condition code
1032 * Arguments:
1033 * skb - pointer to sk_buff to queue for transmission
1034 * dev - pointer to device information
1036 * Functional Description:
1037 * Here we assume that an incoming skb transmit request
1038 * is contained in a single physically contiguous buffer
1039 * in which the virtual address of the start of packet
1040 * (skb->data) can be converted to a physical address
1041 * by using pci_map_single().
1043 * We have an internal queue for packets we can not send
1044 * immediately. Packets in this queue can be given to the
1045 * adapter if transmit buffers are freed.
1047 * We can't free the skb until after it's been DMA'd
1048 * out by the adapter, so we'll keep it in the driver and
1049 * return it in mac_drv_tx_complete.
1051 * Return Codes:
1052 * 0 - driver has queued and/or sent packet
1053 * 1 - caller should requeue the sk_buff for later transmission
1055 * Assumptions:
1056 * The entire packet is stored in one physically
1057 * contiguous buffer which is not cached and whose
1058 * 32-bit physical address can be determined.
1060 * It's vital that this routine is NOT reentered for the
1061 * same board and that the OS is not in another section of
1062 * code (eg. skfp_interrupt) for the same board on a
1063 * different thread.
1065 * Side Effects:
1066 * None
1068 static int skfp_send_pkt(struct sk_buff *skb, struct net_device *dev)
1070 struct s_smc *smc = netdev_priv(dev);
1071 skfddi_priv *bp = &smc->os;
1073 PRINTK(KERN_INFO "skfp_send_pkt\n");
1076 * Verify that incoming transmit request is OK
1078 * Note: The packet size check is consistent with other
1079 * Linux device drivers, although the correct packet
1080 * size should be verified before calling the
1081 * transmit routine.
1084 if (!(skb->len >= FDDI_K_LLC_ZLEN && skb->len <= FDDI_K_LLC_LEN)) {
1085 bp->MacStat.gen.tx_errors++; /* bump error counter */
1086 // dequeue packets from xmt queue and send them
1087 netif_start_queue(dev);
1088 dev_kfree_skb(skb);
1089 return (0); /* return "success" */
1091 if (bp->QueueSkb == 0) { // return with tbusy set: queue full
1093 netif_stop_queue(dev);
1094 return 1;
1096 bp->QueueSkb--;
1097 skb_queue_tail(&bp->SendSkbQueue, skb);
1098 send_queued_packets(netdev_priv(dev));
1099 if (bp->QueueSkb == 0) {
1100 netif_stop_queue(dev);
1102 dev->trans_start = jiffies;
1103 return 0;
1105 } // skfp_send_pkt
1109 * =======================
1110 * = send_queued_packets =
1111 * =======================
1113 * Overview:
1114 * Send packets from the driver queue as long as there are some and
1115 * transmit resources are available.
1117 * Returns:
1118 * None
1120 * Arguments:
1121 * smc - pointer to smc (adapter) structure
1123 * Functional Description:
1124 * Take a packet from queue if there is any. If not, then we are done.
1125 * Check if there are resources to send the packet. If not, requeue it
1126 * and exit.
1127 * Set packet descriptor flags and give packet to adapter.
1128 * Check if any send resources can be freed (we do not use the
1129 * transmit complete interrupt).
1131 static void send_queued_packets(struct s_smc *smc)
1133 skfddi_priv *bp = &smc->os;
1134 struct sk_buff *skb;
1135 unsigned char fc;
1136 int queue;
1137 struct s_smt_fp_txd *txd; // Current TxD.
1138 dma_addr_t dma_address;
1139 unsigned long Flags;
1141 int frame_status; // HWM tx frame status.
1143 PRINTK(KERN_INFO "send queued packets\n");
1144 for (;;) {
1145 // send first buffer from queue
1146 skb = skb_dequeue(&bp->SendSkbQueue);
1148 if (!skb) {
1149 PRINTK(KERN_INFO "queue empty\n");
1150 return;
1151 } // queue empty !
1153 spin_lock_irqsave(&bp->DriverLock, Flags);
1154 fc = skb->data[0];
1155 queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0;
1156 #ifdef ESS
1157 // Check if the frame may/must be sent as a synchronous frame.
1159 if ((fc & ~(FC_SYNC_BIT | FC_LLC_PRIOR)) == FC_ASYNC_LLC) {
1160 // It's an LLC frame.
1161 if (!smc->ess.sync_bw_available)
1162 fc &= ~FC_SYNC_BIT; // No bandwidth available.
1164 else { // Bandwidth is available.
1166 if (smc->mib.fddiESSSynchTxMode) {
1167 // Send as sync. frame.
1168 fc |= FC_SYNC_BIT;
1172 #endif // ESS
1173 frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue);
1175 if ((frame_status & (LOC_TX | LAN_TX)) == 0) {
1176 // Unable to send the frame.
1178 if ((frame_status & RING_DOWN) != 0) {
1179 // Ring is down.
1180 PRINTK("Tx attempt while ring down.\n");
1181 } else if ((frame_status & OUT_OF_TXD) != 0) {
1182 PRINTK("%s: out of TXDs.\n", bp->dev->name);
1183 } else {
1184 PRINTK("%s: out of transmit resources",
1185 bp->dev->name);
1188 // Note: We will retry the operation as soon as
1189 // transmit resources become available.
1190 skb_queue_head(&bp->SendSkbQueue, skb);
1191 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1192 return; // Packet has been queued.
1194 } // if (unable to send frame)
1196 bp->QueueSkb++; // one packet less in local queue
1198 // source address in packet ?
1199 CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a);
1201 txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue);
1203 dma_address = pci_map_single(&bp->pdev, skb->data,
1204 skb->len, PCI_DMA_TODEVICE);
1205 if (frame_status & LAN_TX) {
1206 txd->txd_os.skb = skb; // save skb
1207 txd->txd_os.dma_addr = dma_address; // save dma mapping
1209 hwm_tx_frag(smc, skb->data, dma_address, skb->len,
1210 frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF);
1212 if (!(frame_status & LAN_TX)) { // local only frame
1213 pci_unmap_single(&bp->pdev, dma_address,
1214 skb->len, PCI_DMA_TODEVICE);
1215 dev_kfree_skb_irq(skb);
1217 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1218 } // for
1220 return; // never reached
1222 } // send_queued_packets
1225 /************************
1227 * CheckSourceAddress
1229 * Verify if the source address is set. Insert it if necessary.
1231 ************************/
1232 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr)
1234 unsigned char SRBit;
1236 if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0) // source routing bit
1238 return;
1239 if ((unsigned short) frame[1 + 10] != 0)
1240 return;
1241 SRBit = frame[1 + 6] & 0x01;
1242 memcpy(&frame[1 + 6], hw_addr, 6);
1243 frame[8] |= SRBit;
1244 } // CheckSourceAddress
1247 /************************
1249 * ResetAdapter
1251 * Reset the adapter and bring it back to operational mode.
1252 * Args
1253 * smc - A pointer to the SMT context struct.
1254 * Out
1255 * Nothing.
1257 ************************/
1258 static void ResetAdapter(struct s_smc *smc)
1261 PRINTK(KERN_INFO "[fddi: ResetAdapter]\n");
1263 // Stop the adapter.
1265 card_stop(smc); // Stop all activity.
1267 // Clear the transmit and receive descriptor queues.
1268 mac_drv_clear_tx_queue(smc);
1269 mac_drv_clear_rx_queue(smc);
1271 // Restart the adapter.
1273 smt_reset_defaults(smc, 1); // Initialize the SMT module.
1275 init_smt(smc, (smc->os.dev)->dev_addr); // Initialize the hardware.
1277 smt_online(smc, 1); // Insert into the ring again.
1278 STI_FBI();
1280 // Restore original receive mode (multicasts, promiscuous, etc.).
1281 skfp_ctl_set_multicast_list_wo_lock(smc->os.dev);
1282 } // ResetAdapter
1285 //--------------- functions called by hardware module ----------------
1287 /************************
1289 * llc_restart_tx
1291 * The hardware driver calls this routine when the transmit complete
1292 * interrupt bits (end of frame) for the synchronous or asynchronous
1293 * queue is set.
1295 * NOTE The hardware driver calls this function also if no packets are queued.
1296 * The routine must be able to handle this case.
1297 * Args
1298 * smc - A pointer to the SMT context struct.
1299 * Out
1300 * Nothing.
1302 ************************/
1303 void llc_restart_tx(struct s_smc *smc)
1305 skfddi_priv *bp = &smc->os;
1307 PRINTK(KERN_INFO "[llc_restart_tx]\n");
1309 // Try to send queued packets
1310 spin_unlock(&bp->DriverLock);
1311 send_queued_packets(smc);
1312 spin_lock(&bp->DriverLock);
1313 netif_start_queue(bp->dev);// system may send again if it was blocked
1315 } // llc_restart_tx
1318 /************************
1320 * mac_drv_get_space
1322 * The hardware module calls this function to allocate the memory
1323 * for the SMT MBufs if the define MB_OUTSIDE_SMC is specified.
1324 * Args
1325 * smc - A pointer to the SMT context struct.
1327 * size - Size of memory in bytes to allocate.
1328 * Out
1329 * != 0 A pointer to the virtual address of the allocated memory.
1330 * == 0 Allocation error.
1332 ************************/
1333 void *mac_drv_get_space(struct s_smc *smc, unsigned int size)
1335 void *virt;
1337 PRINTK(KERN_INFO "mac_drv_get_space (%d bytes), ", size);
1338 virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap);
1340 if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) {
1341 printk("Unexpected SMT memory size requested: %d\n", size);
1342 return (NULL);
1344 smc->os.SharedMemHeap += size; // Move heap pointer.
1346 PRINTK(KERN_INFO "mac_drv_get_space end\n");
1347 PRINTK(KERN_INFO "virt addr: %lx\n", (ulong) virt);
1348 PRINTK(KERN_INFO "bus addr: %lx\n", (ulong)
1349 (smc->os.SharedMemDMA +
1350 ((char *) virt - (char *)smc->os.SharedMemAddr)));
1351 return (virt);
1352 } // mac_drv_get_space
1355 /************************
1357 * mac_drv_get_desc_mem
1359 * This function is called by the hardware dependent module.
1360 * It allocates the memory for the RxD and TxD descriptors.
1362 * This memory must be non-cached, non-movable and non-swappable.
1363 * This memory should start at a physical page boundary.
1364 * Args
1365 * smc - A pointer to the SMT context struct.
1367 * size - Size of memory in bytes to allocate.
1368 * Out
1369 * != 0 A pointer to the virtual address of the allocated memory.
1370 * == 0 Allocation error.
1372 ************************/
1373 void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size)
1376 char *virt;
1378 PRINTK(KERN_INFO "mac_drv_get_desc_mem\n");
1380 // Descriptor memory must be aligned on 16-byte boundary.
1382 virt = mac_drv_get_space(smc, size);
1384 size = (u_int) (16 - (((unsigned long) virt) & 15UL));
1385 size = size % 16;
1387 PRINTK("Allocate %u bytes alignment gap ", size);
1388 PRINTK("for descriptor memory.\n");
1390 if (!mac_drv_get_space(smc, size)) {
1391 printk("fddi: Unable to align descriptor memory.\n");
1392 return (NULL);
1394 return (virt + size);
1395 } // mac_drv_get_desc_mem
1398 /************************
1400 * mac_drv_virt2phys
1402 * Get the physical address of a given virtual address.
1403 * Args
1404 * smc - A pointer to the SMT context struct.
1406 * virt - A (virtual) pointer into our 'shared' memory area.
1407 * Out
1408 * Physical address of the given virtual address.
1410 ************************/
1411 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt)
1413 return (smc->os.SharedMemDMA +
1414 ((char *) virt - (char *)smc->os.SharedMemAddr));
1415 } // mac_drv_virt2phys
1418 /************************
1420 * dma_master
1422 * The HWM calls this function, when the driver leads through a DMA
1423 * transfer. If the OS-specific module must prepare the system hardware
1424 * for the DMA transfer, it should do it in this function.
1426 * The hardware module calls this dma_master if it wants to send an SMT
1427 * frame. This means that the virt address passed in here is part of
1428 * the 'shared' memory area.
1429 * Args
1430 * smc - A pointer to the SMT context struct.
1432 * virt - The virtual address of the data.
1434 * len - The length in bytes of the data.
1436 * flag - Indicates the transmit direction and the buffer type:
1437 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1438 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1439 * SMT_BUF (0x80) SMT buffer
1441 * >> NOTE: SMT_BUF and DMA_RD are always set for PCI. <<
1442 * Out
1443 * Returns the pyhsical address for the DMA transfer.
1445 ************************/
1446 u_long dma_master(struct s_smc * smc, void *virt, int len, int flag)
1448 return (smc->os.SharedMemDMA +
1449 ((char *) virt - (char *)smc->os.SharedMemAddr));
1450 } // dma_master
1453 /************************
1455 * dma_complete
1457 * The hardware module calls this routine when it has completed a DMA
1458 * transfer. If the operating system dependent module has set up the DMA
1459 * channel via dma_master() (e.g. Windows NT or AIX) it should clean up
1460 * the DMA channel.
1461 * Args
1462 * smc - A pointer to the SMT context struct.
1464 * descr - A pointer to a TxD or RxD, respectively.
1466 * flag - Indicates the DMA transfer direction / SMT buffer:
1467 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1468 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1469 * SMT_BUF (0x80) SMT buffer (managed by HWM)
1470 * Out
1471 * Nothing.
1473 ************************/
1474 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag)
1476 /* For TX buffers, there are two cases. If it is an SMT transmit
1477 * buffer, there is nothing to do since we use consistent memory
1478 * for the 'shared' memory area. The other case is for normal
1479 * transmit packets given to us by the networking stack, and in
1480 * that case we cleanup the PCI DMA mapping in mac_drv_tx_complete
1481 * below.
1483 * For RX buffers, we have to unmap dynamic PCI DMA mappings here
1484 * because the hardware module is about to potentially look at
1485 * the contents of the buffer. If we did not call the PCI DMA
1486 * unmap first, the hardware module could read inconsistent data.
1488 if (flag & DMA_WR) {
1489 skfddi_priv *bp = &smc->os;
1490 volatile struct s_smt_fp_rxd *r = &descr->r;
1492 /* If SKB is NULL, we used the local buffer. */
1493 if (r->rxd_os.skb && r->rxd_os.dma_addr) {
1494 int MaxFrameSize = bp->MaxFrameSize;
1496 pci_unmap_single(&bp->pdev, r->rxd_os.dma_addr,
1497 MaxFrameSize, PCI_DMA_FROMDEVICE);
1498 r->rxd_os.dma_addr = 0;
1501 } // dma_complete
1504 /************************
1506 * mac_drv_tx_complete
1508 * Transmit of a packet is complete. Release the tx staging buffer.
1510 * Args
1511 * smc - A pointer to the SMT context struct.
1513 * txd - A pointer to the last TxD which is used by the frame.
1514 * Out
1515 * Returns nothing.
1517 ************************/
1518 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
1520 struct sk_buff *skb;
1522 PRINTK(KERN_INFO "entering mac_drv_tx_complete\n");
1523 // Check if this TxD points to a skb
1525 if (!(skb = txd->txd_os.skb)) {
1526 PRINTK("TXD with no skb assigned.\n");
1527 return;
1529 txd->txd_os.skb = NULL;
1531 // release the DMA mapping
1532 pci_unmap_single(&smc->os.pdev, txd->txd_os.dma_addr,
1533 skb->len, PCI_DMA_TODEVICE);
1534 txd->txd_os.dma_addr = 0;
1536 smc->os.MacStat.gen.tx_packets++; // Count transmitted packets.
1537 smc->os.MacStat.gen.tx_bytes+=skb->len; // Count bytes
1539 // free the skb
1540 dev_kfree_skb_irq(skb);
1542 PRINTK(KERN_INFO "leaving mac_drv_tx_complete\n");
1543 } // mac_drv_tx_complete
1546 /************************
1548 * dump packets to logfile
1550 ************************/
1551 #ifdef DUMPPACKETS
1552 void dump_data(unsigned char *Data, int length)
1554 int i, j;
1555 unsigned char s[255], sh[10];
1556 if (length > 64) {
1557 length = 64;
1559 printk(KERN_INFO "---Packet start---\n");
1560 for (i = 0, j = 0; i < length / 8; i++, j += 8)
1561 printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\n",
1562 Data[j + 0], Data[j + 1], Data[j + 2], Data[j + 3],
1563 Data[j + 4], Data[j + 5], Data[j + 6], Data[j + 7]);
1564 strcpy(s, "");
1565 for (i = 0; i < length % 8; i++) {
1566 sprintf(sh, "%02x ", Data[j + i]);
1567 strcat(s, sh);
1569 printk(KERN_INFO "%s\n", s);
1570 printk(KERN_INFO "------------------\n");
1571 } // dump_data
1572 #else
1573 #define dump_data(data,len)
1574 #endif // DUMPPACKETS
1576 /************************
1578 * mac_drv_rx_complete
1580 * The hardware module calls this function if an LLC frame is received
1581 * in a receive buffer. Also the SMT, NSA, and directed beacon frames
1582 * from the network will be passed to the LLC layer by this function
1583 * if passing is enabled.
1585 * mac_drv_rx_complete forwards the frame to the LLC layer if it should
1586 * be received. It also fills the RxD ring with new receive buffers if
1587 * some can be queued.
1588 * Args
1589 * smc - A pointer to the SMT context struct.
1591 * rxd - A pointer to the first RxD which is used by the receive frame.
1593 * frag_count - Count of RxDs used by the received frame.
1595 * len - Frame length.
1596 * Out
1597 * Nothing.
1599 ************************/
1600 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1601 int frag_count, int len)
1603 skfddi_priv *bp = &smc->os;
1604 struct sk_buff *skb;
1605 unsigned char *virt, *cp;
1606 unsigned short ri;
1607 u_int RifLength;
1609 PRINTK(KERN_INFO "entering mac_drv_rx_complete (len=%d)\n", len);
1610 if (frag_count != 1) { // This is not allowed to happen.
1612 printk("fddi: Multi-fragment receive!\n");
1613 goto RequeueRxd; // Re-use the given RXD(s).
1616 skb = rxd->rxd_os.skb;
1617 if (!skb) {
1618 PRINTK(KERN_INFO "No skb in rxd\n");
1619 smc->os.MacStat.gen.rx_errors++;
1620 goto RequeueRxd;
1622 virt = skb->data;
1624 // The DMA mapping was released in dma_complete above.
1626 dump_data(skb->data, len);
1629 * FDDI Frame format:
1630 * +-------+-------+-------+------------+--------+------------+
1631 * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] |
1632 * +-------+-------+-------+------------+--------+------------+
1634 * FC = Frame Control
1635 * DA = Destination Address
1636 * SA = Source Address
1637 * RIF = Routing Information Field
1638 * LLC = Logical Link Control
1641 // Remove Routing Information Field (RIF), if present.
1643 if ((virt[1 + 6] & FDDI_RII) == 0)
1644 RifLength = 0;
1645 else {
1646 int n;
1647 // goos: RIF removal has still to be tested
1648 PRINTK(KERN_INFO "RIF found\n");
1649 // Get RIF length from Routing Control (RC) field.
1650 cp = virt + FDDI_MAC_HDR_LEN; // Point behind MAC header.
1652 ri = ntohs(*((__be16 *) cp));
1653 RifLength = ri & FDDI_RCF_LEN_MASK;
1654 if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) {
1655 printk("fddi: Invalid RIF.\n");
1656 goto RequeueRxd; // Discard the frame.
1659 virt[1 + 6] &= ~FDDI_RII; // Clear RII bit.
1660 // regions overlap
1662 virt = cp + RifLength;
1663 for (n = FDDI_MAC_HDR_LEN; n; n--)
1664 *--virt = *--cp;
1665 // adjust sbd->data pointer
1666 skb_pull(skb, RifLength);
1667 len -= RifLength;
1668 RifLength = 0;
1671 // Count statistics.
1672 smc->os.MacStat.gen.rx_packets++; // Count indicated receive
1673 // packets.
1674 smc->os.MacStat.gen.rx_bytes+=len; // Count bytes.
1676 // virt points to header again
1677 if (virt[1] & 0x01) { // Check group (multicast) bit.
1679 smc->os.MacStat.gen.multicast++;
1682 // deliver frame to system
1683 rxd->rxd_os.skb = NULL;
1684 skb_trim(skb, len);
1685 skb->protocol = fddi_type_trans(skb, bp->dev);
1687 netif_rx(skb);
1689 HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
1690 return;
1692 RequeueRxd:
1693 PRINTK(KERN_INFO "Rx: re-queue RXD.\n");
1694 mac_drv_requeue_rxd(smc, rxd, frag_count);
1695 smc->os.MacStat.gen.rx_errors++; // Count receive packets
1696 // not indicated.
1698 } // mac_drv_rx_complete
1701 /************************
1703 * mac_drv_requeue_rxd
1705 * The hardware module calls this function to request the OS-specific
1706 * module to queue the receive buffer(s) represented by the pointer
1707 * to the RxD and the frag_count into the receive queue again. This
1708 * buffer was filled with an invalid frame or an SMT frame.
1709 * Args
1710 * smc - A pointer to the SMT context struct.
1712 * rxd - A pointer to the first RxD which is used by the receive frame.
1714 * frag_count - Count of RxDs used by the received frame.
1715 * Out
1716 * Nothing.
1718 ************************/
1719 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1720 int frag_count)
1722 volatile struct s_smt_fp_rxd *next_rxd;
1723 volatile struct s_smt_fp_rxd *src_rxd;
1724 struct sk_buff *skb;
1725 int MaxFrameSize;
1726 unsigned char *v_addr;
1727 dma_addr_t b_addr;
1729 if (frag_count != 1) // This is not allowed to happen.
1731 printk("fddi: Multi-fragment requeue!\n");
1733 MaxFrameSize = smc->os.MaxFrameSize;
1734 src_rxd = rxd;
1735 for (; frag_count > 0; frag_count--) {
1736 next_rxd = src_rxd->rxd_next;
1737 rxd = HWM_GET_CURR_RXD(smc);
1739 skb = src_rxd->rxd_os.skb;
1740 if (skb == NULL) { // this should not happen
1742 PRINTK("Requeue with no skb in rxd!\n");
1743 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1744 if (skb) {
1745 // we got a skb
1746 rxd->rxd_os.skb = skb;
1747 skb_reserve(skb, 3);
1748 skb_put(skb, MaxFrameSize);
1749 v_addr = skb->data;
1750 b_addr = pci_map_single(&smc->os.pdev,
1751 v_addr,
1752 MaxFrameSize,
1753 PCI_DMA_FROMDEVICE);
1754 rxd->rxd_os.dma_addr = b_addr;
1755 } else {
1756 // no skb available, use local buffer
1757 PRINTK("Queueing invalid buffer!\n");
1758 rxd->rxd_os.skb = NULL;
1759 v_addr = smc->os.LocalRxBuffer;
1760 b_addr = smc->os.LocalRxBufferDMA;
1762 } else {
1763 // we use skb from old rxd
1764 rxd->rxd_os.skb = skb;
1765 v_addr = skb->data;
1766 b_addr = pci_map_single(&smc->os.pdev,
1767 v_addr,
1768 MaxFrameSize,
1769 PCI_DMA_FROMDEVICE);
1770 rxd->rxd_os.dma_addr = b_addr;
1772 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1773 FIRST_FRAG | LAST_FRAG);
1775 src_rxd = next_rxd;
1777 } // mac_drv_requeue_rxd
1780 /************************
1782 * mac_drv_fill_rxd
1784 * The hardware module calls this function at initialization time
1785 * to fill the RxD ring with receive buffers. It is also called by
1786 * mac_drv_rx_complete if rx_free is large enough to queue some new
1787 * receive buffers into the RxD ring. mac_drv_fill_rxd queues new
1788 * receive buffers as long as enough RxDs and receive buffers are
1789 * available.
1790 * Args
1791 * smc - A pointer to the SMT context struct.
1792 * Out
1793 * Nothing.
1795 ************************/
1796 void mac_drv_fill_rxd(struct s_smc *smc)
1798 int MaxFrameSize;
1799 unsigned char *v_addr;
1800 unsigned long b_addr;
1801 struct sk_buff *skb;
1802 volatile struct s_smt_fp_rxd *rxd;
1804 PRINTK(KERN_INFO "entering mac_drv_fill_rxd\n");
1806 // Walk through the list of free receive buffers, passing receive
1807 // buffers to the HWM as long as RXDs are available.
1809 MaxFrameSize = smc->os.MaxFrameSize;
1810 // Check if there is any RXD left.
1811 while (HWM_GET_RX_FREE(smc) > 0) {
1812 PRINTK(KERN_INFO ".\n");
1814 rxd = HWM_GET_CURR_RXD(smc);
1815 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1816 if (skb) {
1817 // we got a skb
1818 skb_reserve(skb, 3);
1819 skb_put(skb, MaxFrameSize);
1820 v_addr = skb->data;
1821 b_addr = pci_map_single(&smc->os.pdev,
1822 v_addr,
1823 MaxFrameSize,
1824 PCI_DMA_FROMDEVICE);
1825 rxd->rxd_os.dma_addr = b_addr;
1826 } else {
1827 // no skb available, use local buffer
1828 // System has run out of buffer memory, but we want to
1829 // keep the receiver running in hope of better times.
1830 // Multiple descriptors may point to this local buffer,
1831 // so data in it must be considered invalid.
1832 PRINTK("Queueing invalid buffer!\n");
1833 v_addr = smc->os.LocalRxBuffer;
1834 b_addr = smc->os.LocalRxBufferDMA;
1837 rxd->rxd_os.skb = skb;
1839 // Pass receive buffer to HWM.
1840 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1841 FIRST_FRAG | LAST_FRAG);
1843 PRINTK(KERN_INFO "leaving mac_drv_fill_rxd\n");
1844 } // mac_drv_fill_rxd
1847 /************************
1849 * mac_drv_clear_rxd
1851 * The hardware module calls this function to release unused
1852 * receive buffers.
1853 * Args
1854 * smc - A pointer to the SMT context struct.
1856 * rxd - A pointer to the first RxD which is used by the receive buffer.
1858 * frag_count - Count of RxDs used by the receive buffer.
1859 * Out
1860 * Nothing.
1862 ************************/
1863 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1864 int frag_count)
1867 struct sk_buff *skb;
1869 PRINTK("entering mac_drv_clear_rxd\n");
1871 if (frag_count != 1) // This is not allowed to happen.
1873 printk("fddi: Multi-fragment clear!\n");
1875 for (; frag_count > 0; frag_count--) {
1876 skb = rxd->rxd_os.skb;
1877 if (skb != NULL) {
1878 skfddi_priv *bp = &smc->os;
1879 int MaxFrameSize = bp->MaxFrameSize;
1881 pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr,
1882 MaxFrameSize, PCI_DMA_FROMDEVICE);
1884 dev_kfree_skb(skb);
1885 rxd->rxd_os.skb = NULL;
1887 rxd = rxd->rxd_next; // Next RXD.
1890 } // mac_drv_clear_rxd
1893 /************************
1895 * mac_drv_rx_init
1897 * The hardware module calls this routine when an SMT or NSA frame of the
1898 * local SMT should be delivered to the LLC layer.
1900 * It is necessary to have this function, because there is no other way to
1901 * copy the contents of SMT MBufs into receive buffers.
1903 * mac_drv_rx_init allocates the required target memory for this frame,
1904 * and receives the frame fragment by fragment by calling mac_drv_rx_frag.
1905 * Args
1906 * smc - A pointer to the SMT context struct.
1908 * len - The length (in bytes) of the received frame (FC, DA, SA, Data).
1910 * fc - The Frame Control field of the received frame.
1912 * look_ahead - A pointer to the lookahead data buffer (may be NULL).
1914 * la_len - The length of the lookahead data stored in the lookahead
1915 * buffer (may be zero).
1916 * Out
1917 * Always returns zero (0).
1919 ************************/
1920 int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
1921 char *look_ahead, int la_len)
1923 struct sk_buff *skb;
1925 PRINTK("entering mac_drv_rx_init(len=%d)\n", len);
1927 // "Received" a SMT or NSA frame of the local SMT.
1929 if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) {
1930 PRINTK("fddi: Discard invalid local SMT frame\n");
1931 PRINTK(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n",
1932 len, la_len, (unsigned long) look_ahead);
1933 return (0);
1935 skb = alloc_skb(len + 3, GFP_ATOMIC);
1936 if (!skb) {
1937 PRINTK("fddi: Local SMT: skb memory exhausted.\n");
1938 return (0);
1940 skb_reserve(skb, 3);
1941 skb_put(skb, len);
1942 skb_copy_to_linear_data(skb, look_ahead, len);
1944 // deliver frame to system
1945 skb->protocol = fddi_type_trans(skb, smc->os.dev);
1946 netif_rx(skb);
1948 return (0);
1949 } // mac_drv_rx_init
1952 /************************
1954 * smt_timer_poll
1956 * This routine is called periodically by the SMT module to clean up the
1957 * driver.
1959 * Return any queued frames back to the upper protocol layers if the ring
1960 * is down.
1961 * Args
1962 * smc - A pointer to the SMT context struct.
1963 * Out
1964 * Nothing.
1966 ************************/
1967 void smt_timer_poll(struct s_smc *smc)
1969 } // smt_timer_poll
1972 /************************
1974 * ring_status_indication
1976 * This function indicates a change of the ring state.
1977 * Args
1978 * smc - A pointer to the SMT context struct.
1980 * status - The current ring status.
1981 * Out
1982 * Nothing.
1984 ************************/
1985 void ring_status_indication(struct s_smc *smc, u_long status)
1987 PRINTK("ring_status_indication( ");
1988 if (status & RS_RES15)
1989 PRINTK("RS_RES15 ");
1990 if (status & RS_HARDERROR)
1991 PRINTK("RS_HARDERROR ");
1992 if (status & RS_SOFTERROR)
1993 PRINTK("RS_SOFTERROR ");
1994 if (status & RS_BEACON)
1995 PRINTK("RS_BEACON ");
1996 if (status & RS_PATHTEST)
1997 PRINTK("RS_PATHTEST ");
1998 if (status & RS_SELFTEST)
1999 PRINTK("RS_SELFTEST ");
2000 if (status & RS_RES9)
2001 PRINTK("RS_RES9 ");
2002 if (status & RS_DISCONNECT)
2003 PRINTK("RS_DISCONNECT ");
2004 if (status & RS_RES7)
2005 PRINTK("RS_RES7 ");
2006 if (status & RS_DUPADDR)
2007 PRINTK("RS_DUPADDR ");
2008 if (status & RS_NORINGOP)
2009 PRINTK("RS_NORINGOP ");
2010 if (status & RS_VERSION)
2011 PRINTK("RS_VERSION ");
2012 if (status & RS_STUCKBYPASSS)
2013 PRINTK("RS_STUCKBYPASSS ");
2014 if (status & RS_EVENT)
2015 PRINTK("RS_EVENT ");
2016 if (status & RS_RINGOPCHANGE)
2017 PRINTK("RS_RINGOPCHANGE ");
2018 if (status & RS_RES0)
2019 PRINTK("RS_RES0 ");
2020 PRINTK("]\n");
2021 } // ring_status_indication
2024 /************************
2026 * smt_get_time
2028 * Gets the current time from the system.
2029 * Args
2030 * None.
2031 * Out
2032 * The current time in TICKS_PER_SECOND.
2034 * TICKS_PER_SECOND has the unit 'count of timer ticks per second'. It is
2035 * defined in "targetos.h". The definition of TICKS_PER_SECOND must comply
2036 * to the time returned by smt_get_time().
2038 ************************/
2039 unsigned long smt_get_time(void)
2041 return jiffies;
2042 } // smt_get_time
2045 /************************
2047 * smt_stat_counter
2049 * Status counter update (ring_op, fifo full).
2050 * Args
2051 * smc - A pointer to the SMT context struct.
2053 * stat - = 0: A ring operational change occurred.
2054 * = 1: The FORMAC FIFO buffer is full / FIFO overflow.
2055 * Out
2056 * Nothing.
2058 ************************/
2059 void smt_stat_counter(struct s_smc *smc, int stat)
2061 // BOOLEAN RingIsUp ;
2063 PRINTK(KERN_INFO "smt_stat_counter\n");
2064 switch (stat) {
2065 case 0:
2066 PRINTK(KERN_INFO "Ring operational change.\n");
2067 break;
2068 case 1:
2069 PRINTK(KERN_INFO "Receive fifo overflow.\n");
2070 smc->os.MacStat.gen.rx_errors++;
2071 break;
2072 default:
2073 PRINTK(KERN_INFO "Unknown status (%d).\n", stat);
2074 break;
2076 } // smt_stat_counter
2079 /************************
2081 * cfm_state_change
2083 * Sets CFM state in custom statistics.
2084 * Args
2085 * smc - A pointer to the SMT context struct.
2087 * c_state - Possible values are:
2089 * EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST,
2090 * EC5_INSERT, EC6_CHECK, EC7_DEINSERT
2091 * Out
2092 * Nothing.
2094 ************************/
2095 void cfm_state_change(struct s_smc *smc, int c_state)
2097 #ifdef DRIVERDEBUG
2098 char *s;
2100 switch (c_state) {
2101 case SC0_ISOLATED:
2102 s = "SC0_ISOLATED";
2103 break;
2104 case SC1_WRAP_A:
2105 s = "SC1_WRAP_A";
2106 break;
2107 case SC2_WRAP_B:
2108 s = "SC2_WRAP_B";
2109 break;
2110 case SC4_THRU_A:
2111 s = "SC4_THRU_A";
2112 break;
2113 case SC5_THRU_B:
2114 s = "SC5_THRU_B";
2115 break;
2116 case SC7_WRAP_S:
2117 s = "SC7_WRAP_S";
2118 break;
2119 case SC9_C_WRAP_A:
2120 s = "SC9_C_WRAP_A";
2121 break;
2122 case SC10_C_WRAP_B:
2123 s = "SC10_C_WRAP_B";
2124 break;
2125 case SC11_C_WRAP_S:
2126 s = "SC11_C_WRAP_S";
2127 break;
2128 default:
2129 PRINTK(KERN_INFO "cfm_state_change: unknown %d\n", c_state);
2130 return;
2132 PRINTK(KERN_INFO "cfm_state_change: %s\n", s);
2133 #endif // DRIVERDEBUG
2134 } // cfm_state_change
2137 /************************
2139 * ecm_state_change
2141 * Sets ECM state in custom statistics.
2142 * Args
2143 * smc - A pointer to the SMT context struct.
2145 * e_state - Possible values are:
2147 * SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12),
2148 * SC5_THRU_B (7), SC7_WRAP_S (8)
2149 * Out
2150 * Nothing.
2152 ************************/
2153 void ecm_state_change(struct s_smc *smc, int e_state)
2155 #ifdef DRIVERDEBUG
2156 char *s;
2158 switch (e_state) {
2159 case EC0_OUT:
2160 s = "EC0_OUT";
2161 break;
2162 case EC1_IN:
2163 s = "EC1_IN";
2164 break;
2165 case EC2_TRACE:
2166 s = "EC2_TRACE";
2167 break;
2168 case EC3_LEAVE:
2169 s = "EC3_LEAVE";
2170 break;
2171 case EC4_PATH_TEST:
2172 s = "EC4_PATH_TEST";
2173 break;
2174 case EC5_INSERT:
2175 s = "EC5_INSERT";
2176 break;
2177 case EC6_CHECK:
2178 s = "EC6_CHECK";
2179 break;
2180 case EC7_DEINSERT:
2181 s = "EC7_DEINSERT";
2182 break;
2183 default:
2184 s = "unknown";
2185 break;
2187 PRINTK(KERN_INFO "ecm_state_change: %s\n", s);
2188 #endif //DRIVERDEBUG
2189 } // ecm_state_change
2192 /************************
2194 * rmt_state_change
2196 * Sets RMT state in custom statistics.
2197 * Args
2198 * smc - A pointer to the SMT context struct.
2200 * r_state - Possible values are:
2202 * RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT,
2203 * RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE
2204 * Out
2205 * Nothing.
2207 ************************/
2208 void rmt_state_change(struct s_smc *smc, int r_state)
2210 #ifdef DRIVERDEBUG
2211 char *s;
2213 switch (r_state) {
2214 case RM0_ISOLATED:
2215 s = "RM0_ISOLATED";
2216 break;
2217 case RM1_NON_OP:
2218 s = "RM1_NON_OP - not operational";
2219 break;
2220 case RM2_RING_OP:
2221 s = "RM2_RING_OP - ring operational";
2222 break;
2223 case RM3_DETECT:
2224 s = "RM3_DETECT - detect dupl addresses";
2225 break;
2226 case RM4_NON_OP_DUP:
2227 s = "RM4_NON_OP_DUP - dupl. addr detected";
2228 break;
2229 case RM5_RING_OP_DUP:
2230 s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
2231 break;
2232 case RM6_DIRECTED:
2233 s = "RM6_DIRECTED - sending directed beacons";
2234 break;
2235 case RM7_TRACE:
2236 s = "RM7_TRACE - trace initiated";
2237 break;
2238 default:
2239 s = "unknown";
2240 break;
2242 PRINTK(KERN_INFO "[rmt_state_change: %s]\n", s);
2243 #endif // DRIVERDEBUG
2244 } // rmt_state_change
2247 /************************
2249 * drv_reset_indication
2251 * This function is called by the SMT when it has detected a severe
2252 * hardware problem. The driver should perform a reset on the adapter
2253 * as soon as possible, but not from within this function.
2254 * Args
2255 * smc - A pointer to the SMT context struct.
2256 * Out
2257 * Nothing.
2259 ************************/
2260 void drv_reset_indication(struct s_smc *smc)
2262 PRINTK(KERN_INFO "entering drv_reset_indication\n");
2264 smc->os.ResetRequested = TRUE; // Set flag.
2266 } // drv_reset_indication
2268 static struct pci_driver skfddi_pci_driver = {
2269 .name = "skfddi",
2270 .id_table = skfddi_pci_tbl,
2271 .probe = skfp_init_one,
2272 .remove = __devexit_p(skfp_remove_one),
2275 static int __init skfd_init(void)
2277 return pci_register_driver(&skfddi_pci_driver);
2280 static void __exit skfd_exit(void)
2282 pci_unregister_driver(&skfddi_pci_driver);
2285 module_init(skfd_init);
2286 module_exit(skfd_exit);