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