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