MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / net / wireless / rtlink.org / rtmp_main.c
blob8cb0de89c83eebf628fc2b75039b0e64db399842
1 /*
2 ***************************************************************************
3 * Ralink Tech Inc.
4 * 4F, No. 2 Technology 5th Rd.
5 * Science-based Industrial Park
6 * Hsin-chu, Taiwan, R.O.C.
8 * (c) Copyright 2002, Ralink Technology, Inc.
10 * All rights reserved. Ralink's source code is an unpublished work and the
11 * use of a copyright notice does not imply otherwise. This source code
12 * contains confidential trade secret material of Ralink Tech. Any attemp
13 * or participation in deciphering, decoding, reverse engineering or in any
14 * way altering the source code is stricitly prohibited, unless the prior
15 * written consent of Ralink Technology, Inc. is obtained.
16 ***************************************************************************
18 Module Name:
19 rtmp_main.c
21 Abstract:
23 Revision History:
24 Who When What
25 -------- ---------- ----------------------------------------------
26 Name Date Modification logs
27 Paul Lin 2002-11-25 Initial version
30 #include "rt_config.h"
32 //unsigned long IrqFlags;
34 // Global static variable, Debug level flag
35 #ifdef RT2500_DBG
36 ULONG RTDebugLevel = 6;
37 #endif
39 // Following information will be show when you run 'modinfo'
40 MODULE_AUTHOR("Paul Lin <paul_lin@ralinktech.com>");
41 MODULE_DESCRIPTION("Ralink RT2500 802.11b/g WLAN driver ");
42 // YL
43 #if LINUX_VERSION_CODE >= 0x20412 // Red Hat 7.3
44 MODULE_LICENSE("GPL");
45 #endif
46 extern const struct iw_handler_def rt2500_iw_handler_def;
48 #if 1 // add by Victor Yu. 01-12-2006
49 #include <linux/kmod.h>
50 static void itfact(char *action)
52 char *argv[2], **envp, *buf, *scratch;
53 int i=0;
55 if ( in_interrupt() )
56 return;
57 if ( !current->fs->root )
58 return;
59 if ( !(envp=(char **)kmalloc(10*sizeof(char *), GFP_KERNEL)) )
60 return;
61 if ( !(buf=kmalloc(256, GFP_KERNEL)) )
62 return;
63 argv[0] = "/bin/wirelesspnp";
64 argv[1] = 0;
65 envp[i++] = "HOME=/";
66 envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
67 scratch = buf;
68 envp[i++] = scratch;
69 scratch += sprintf(scratch, "ACTION=%s", action) + 1;
70 envp[i++] = 0;
71 call_usermodehelper(argv[0], argv, envp, 0);
72 kfree(envp);
73 kfree(buf);
75 #endif // 01-12-2005
77 static INT __devinit RT2500_init_one (
78 IN struct pci_dev *pPci_Dev,
79 IN const struct pci_device_id *ent)
81 INT rc;
83 // wake up and enable device
84 if (pci_enable_device (pPci_Dev)) {
85 rc = -EIO;
86 } else {
87 rc = RT2500_probe(pPci_Dev, ent);
88 #if 1 // add by Victor Yu. 01-12-2006
89 if ( rc == 0 )
90 itfact("add");
91 #endif
93 return rc;
96 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
97 static struct net_device *alloc_netdev(int sizeof_priv, const char *mask, void (*setup)(struct net_device *))
99 struct net_device *dev;
100 int alloc_size;
102 /* ensure 32-byte alignment of the private area */
103 alloc_size = sizeof (*dev) + sizeof_priv + 31;
105 dev = (struct net_device *) kmalloc (alloc_size, GFP_KERNEL);
106 if (dev == NULL)
108 DBGPRINT(RT_DEBUG_ERROR, "alloc_netdev: Unable to allocate device memory.\n");
109 return NULL;
112 memset(dev, 0, alloc_size);
114 if (sizeof_priv)
115 dev->priv = (void *) (((long)(dev + 1) + 31) & ~31);
117 setup(dev);
118 strcpy(dev->name,mask);
120 return dev;
122 #endif
125 // PCI device probe & initialization function
127 INT __devinit RT2500_probe(
128 IN struct pci_dev *pPci_Dev,
129 IN const struct pci_device_id *ent)
131 struct net_device *net_dev;
132 RTMP_ADAPTER *pAd;
133 CHAR *print_name;
134 INT chip_id = (int) ent->driver_data;
135 ULONG csr_addr;
136 CSR3_STRUC StaMacReg0;
137 CSR4_STRUC StaMacReg1;
138 INT Status;
140 print_name = pPci_Dev ? pPci_Dev->slot_name : "rt2500";
142 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
143 net_dev = alloc_netdev(sizeof(RTMP_ADAPTER), "eth%d", ether_setup);
144 #else
145 net_dev = alloc_etherdev(sizeof(RTMP_ADAPTER));
146 #endif
147 if (net_dev == NULL)
149 DBGPRINT(RT_DEBUG_TRACE, "init_ethernet failed\n");
150 goto err_out;
153 SET_MODULE_OWNER(net_dev);
155 if (pci_request_regions(pPci_Dev, print_name))
156 goto err_out_free_netdev;
158 // Interrupt IRQ number
159 net_dev->irq = pPci_Dev->irq;
161 // map physical address to virtual address for accessing register
162 csr_addr = (ULONG) ioremap(pci_resource_start(pPci_Dev, 0), pci_resource_len(pPci_Dev, 0));
163 if (!csr_addr)
165 DBGPRINT(RT_DEBUG_TRACE, "ioremap failed for device %s, region 0x%X @ 0x%lX\n",
166 pPci_Dev->slot_name, (ULONG)pci_resource_len(pPci_Dev, 0), pci_resource_start(pPci_Dev, 0));
167 goto err_out_free_res;
170 // Save CSR virtual address and irq to device structure
171 net_dev->base_addr = csr_addr;
172 pAd = net_dev->priv;
173 pAd->CSRBaseAddress = csr_addr;
174 pAd->net_dev = net_dev;
176 // Set DMA master
177 pci_set_master(pPci_Dev);
179 // Read MAC address
180 // 3. Read MAC address
182 USHORT value0, value1, value2;
184 value0 = RTMP_EEPROM_READ16(pAd, 4);
185 value1 = RTMP_EEPROM_READ16(pAd, 6);
186 value2 = RTMP_EEPROM_READ16(pAd, 8);
188 pAd->PermanentAddress[0] = value0;
189 pAd->PermanentAddress[1] = (value0 & 0xFF00) >> 8;
190 pAd->PermanentAddress[2] = value1;
191 pAd->PermanentAddress[3] = (value1 & 0xFF00) >> 8;
192 pAd->PermanentAddress[4] = value2;
193 pAd->PermanentAddress[5] = (value2 & 0xFF00) >> 8;
196 RTMP_IO_READ32(pAd, CSR3, &StaMacReg0.word);
197 RTMP_IO_READ32(pAd, CSR4, &StaMacReg1.word);
198 net_dev->dev_addr[0] = StaMacReg0.field.Byte0;
199 net_dev->dev_addr[1] = StaMacReg0.field.Byte1;
200 net_dev->dev_addr[2] = StaMacReg0.field.Byte2;
201 net_dev->dev_addr[3] = StaMacReg0.field.Byte3;
202 net_dev->dev_addr[4] = StaMacReg1.field.Byte4;
203 net_dev->dev_addr[5] = StaMacReg1.field.Byte5;
205 pAd->chip_id = chip_id;
206 pAd->pPci_Dev = pPci_Dev;
208 // The chip-specific entries in the device structure.
209 net_dev->open = RT2500_open;
210 net_dev->hard_start_xmit = RTMPSendPackets;
211 net_dev->stop = RT2500_close;
212 net_dev->get_stats = RT2500_get_ether_stats;
214 #if WIRELESS_EXT >= 12
215 net_dev->get_wireless_stats = RT2500_get_wireless_stats;
216 net_dev->wireless_handlers = (struct iw_handler_def *) &rt2500_iw_handler_def;
217 #endif
219 net_dev->set_multicast_list = RT2500_set_rx_mode;
220 net_dev->do_ioctl = RT2500_ioctl;
222 #ifdef CONFIG_ARCH_MOXACPU // add by Victor Yu. 01-11-2006
223 sprintf(net_dev->name, "eth2");
224 #else
225 {// find available
226 int i=0;
227 char slot_name[IFNAMSIZ];
228 struct net_device *device;
230 for (i = 0; i < 8; i++)
232 sprintf(slot_name, "eth%d", i); // Scott
234 for (device = dev_base; device != NULL; device = device->next)
236 if (strncmp(device->name, slot_name, 4) == 0)
238 break;
241 if(device == NULL) break;
243 if(i == 8)
245 DBGPRINT(RT_DEBUG_ERROR, "No available slot name\n");
246 goto err_out_unmap;
249 sprintf(net_dev->name, "eth%d", i); // Scott
251 #endif
253 // Register this device
254 Status = register_netdev(net_dev);
255 if (Status)
256 goto err_out_unmap;
258 DBGPRINT(RT_DEBUG_TRACE, "%s: at 0x%lx, VA 0x%1x, IRQ %d. \n",
259 net_dev->name, pci_resource_start(pPci_Dev, 0), (ULONG)csr_addr, pPci_Dev->irq);
261 // Set driver data
262 pci_set_drvdata(pPci_Dev, net_dev);
264 return 0;
266 err_out_unmap:
267 iounmap((void *)csr_addr);
268 release_mem_region(pci_resource_start(pPci_Dev, 0), pci_resource_len(pPci_Dev, 0));
269 err_out_free_res:
270 pci_release_regions(pPci_Dev);
271 err_out_free_netdev:
272 kfree (net_dev);
273 err_out:
274 return -ENODEV;
277 INT RT2500_open(
278 IN struct net_device *net_dev)
280 PRTMP_ADAPTER pAd = net_dev->priv;
281 INT status = NDIS_STATUS_SUCCESS;
283 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
284 if (!try_module_get(THIS_MODULE))
286 DBGPRINT(RT_DEBUG_ERROR, "%s: cannot reserve module\n", __FUNCTION__);
287 return -1;
289 #else
290 MOD_INC_USE_COUNT;
291 #endif
293 // 1. Allocate DMA descriptors & buffers
294 status = RTMPAllocDMAMemory(pAd);
295 if (status != NDIS_STATUS_SUCCESS)
296 goto out_module_put;
298 // 2. request interrupt\x14
299 // Disable interrupts here which is as soon as possible
300 // This statement should never be true. We might consider to remove it later
301 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
303 NICDisableInterrupt(pAd);
306 status = request_irq(pAd->pPci_Dev->irq, &RTMPIsr, SA_SHIRQ, net_dev->name, net_dev);
307 if (status)
309 RTMPFreeDMAMemory(pAd);
310 goto out_module_put;
312 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
314 // 3. Read MAC address
315 NICReadAdapterInfo(pAd);
317 DBGPRINT(RT_DEBUG_TRACE, "%s: RT2500_open() irq %d. MAC = %02x:%02x:%02x:%02x:%02x:%02x \n",
318 net_dev->name, pAd->pPci_Dev->irq, pAd->CurrentAddress[0], pAd->CurrentAddress[1], pAd->CurrentAddress[2],
319 pAd->CurrentAddress[3], pAd->CurrentAddress[4], pAd->CurrentAddress[5]);
321 NICInitTransmit(pAd);
323 // manufacture default
324 PortCfgInit(pAd);
326 // Read RaConfig profile parameters
327 RTMPReadParametersFromFile(pAd);
329 // initialize MLME
330 status = MlmeInit(pAd);
332 // Initialize Mlme Memory Handler
333 // Allocate 20 nonpaged memory pool which size are MAX_LEN_OF_MLME_BUFFER for use
334 status = MlmeInitMemoryHandler(pAd, 20, MAX_LEN_OF_MLME_BUFFER);
336 if(status != NDIS_STATUS_SUCCESS)
338 free_irq(net_dev->irq, net_dev);
339 RTMPFreeDMAMemory(pAd);
340 goto out_module_put;
343 // Initialize Asics
344 NICInitializeAdapter(pAd);
346 NICReadEEPROMParameters(pAd);
348 NICInitAsicFromEEPROM(pAd);
350 // 2nd stage hardware initialization after all parameters are acquired from
351 // Registry or E2PROM
352 RTMPSetPhyMode(pAd, PHY_11BG_MIXED);
354 // Set the timer to check for link beat.
355 /* RTMPInitTimer(pAd, &pAd->timer, RT2500_timer);
356 RTMPSetTimer(pAd, &pAd->timer, DEBUG_TASK_DELAY);*/
358 // Enable interrupt
359 NICEnableInterrupt(pAd);
361 // Start net interface tx /rx
362 netif_start_queue(net_dev);
364 netif_carrier_on(net_dev);
365 netif_wake_queue(net_dev);
367 return 0;
369 out_module_put:
370 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
371 module_put(THIS_MODULE);
372 #else
373 MOD_DEC_USE_COUNT;
374 #endif
376 return status;
379 VOID RT2500_timer(
380 IN unsigned long data)
382 RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)data;
384 // NICCheckForHang(pAd);
386 RTMPSetTimer(pAd, &pAd->timer, DEBUG_TASK_DELAY);
390 ========================================================================
392 Routine Description:
393 hard_start_xmit handler
395 Arguments:
396 skb point to sk_buf which upper layer transmit
397 net_dev point to net_dev
398 Return Value:
399 None
401 Note:
403 ========================================================================
405 INT RTMPSendPackets(
406 IN struct sk_buff *skb,
407 IN struct net_device *net_dev)
409 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
410 PRTMP_ADAPTER pAdapter = net_dev->priv;
412 DBGPRINT(RT_DEBUG_INFO, "<==== RTMPSendPackets\n");
414 // Drop packets if no associations
415 if (!INFRA_ON(pAdapter) && !ADHOC_ON(pAdapter))
417 // Drop send request since there are no physical connection yet
418 // Check the association status for infrastructure mode
419 // And Mibss for Ad-hoc mode setup
420 RTMPFreeSkbBuffer(skb);
422 else
424 // This function has to manage NdisSendComplete return call within its routine
425 // NdisSendComplete will acknowledge upper layer in two steps.
426 // 1. Within Packet Enqueue, set the NDIS_STATUS_PENDING
427 // 2. Within TxRingTxDone / PrioRingTxDone call NdisSendComplete with final status
428 // initial skb->data_len=0, we will use this variable to store data size when fragment(in TKIP)
429 // and skb->len is actual data len
430 skb->data_len = skb->len;
431 Status = RTMPSendPacket(pAdapter,skb);
433 if (Status != NDIS_STATUS_SUCCESS)
435 // Errors before enqueue stage
436 RTMPFreeSkbBuffer(skb);
440 // Dequeue one frame from SendTxWait queue and process it
441 // There are two place calling dequeue for TX ring.
442 // 1. Here, right after queueing the frame.
443 // 2. At the end of TxRingTxDone service routine.
444 if ((!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) &&
445 (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF)) &&
446 (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RESET_IN_PROGRESS)))
448 //RTMPDeQueuePacket(pAdapter, &pAdapter->TxSwQueue0);
449 // Call dequeue without selected queue, let the subroutine select the right priority
450 // Tx software queue
451 RTMPDeQueuePacket(pAdapter);
454 return 0;
458 ========================================================================
460 Routine Description:
461 Interrupt handler
463 Arguments:
464 irq interrupt line
465 dev_instance Pointer to net_device
466 rgs store process's context before entering ISR,
467 this parameter is just for debug purpose.
469 Return Value:
470 VOID
472 Note:
474 ========================================================================
476 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
477 irqreturn_t
478 #else
479 VOID
480 #endif
481 RTMPIsr(
482 IN INT irq,
483 IN VOID *dev_instance,
484 IN struct pt_regs *rgs)
486 struct net_device *net_dev = dev_instance;
487 PRTMP_ADAPTER pAdapter = net_dev->priv;
488 INTSRC_STRUC IntSource;
490 // Scott DBGPRINT(RT_DEBUG_INFO, "====> RTMPHandleInterrupt\n");
492 // 1. Disable interrupt
493 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE) && RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
495 NICDisableInterrupt(pAdapter);
499 // Get the interrupt sources & saved to local variable
501 // RTMP_IO_READ32(pAdapter, CSR7, &IntSource);
502 RTMP_IO_READ32(pAdapter, CSR7, &IntSource.word);
503 RTMP_IO_WRITE32(pAdapter, CSR7, IntSource.word);
506 // Handle interrupt, walk through all bits
507 // Should start from highest priority interrupt
508 // The priority can be adjust by altering processing if statement
510 // If required spinlock, each interrupt service routine has to acquire
511 // and release itself.
513 if (IntSource.field.TbcnExpire)
515 DBGPRINT(RT_DEBUG_INFO, "====> RTMPHandleTbcnInterrupt\n");
516 RTMPHandleTbcnInterrupt(pAdapter);
519 if (IntSource.field.TwakeExpire)
521 DBGPRINT(RT_DEBUG_INFO, "====> RTMPHandleTwakeupInterrupt\n");
522 RTMPHandleTwakeupInterrupt(pAdapter);
525 if (IntSource.field.TatimwExpire)
527 DBGPRINT(RT_DEBUG_INFO, "====> RTMPHandleTatimInterrupt\n");
528 // RTMPHandleTatimInterrupt(pAdapter);
531 if (IntSource.field.EncryptionDone)
533 DBGPRINT(RT_DEBUG_INFO, "====> RTMPHandleEncryptionDoneInterrupt\n");
534 RTMPHandleEncryptionDoneInterrupt(pAdapter);
537 if (IntSource.field.TxRingTxDone)
539 DBGPRINT(RT_DEBUG_INFO, "====> RTMPHandleTxRingTxDoneInterrupt\n");
540 RTMPHandleTxRingTxDoneInterrupt(pAdapter);
543 if (IntSource.field.AtimRingTxDone)
545 DBGPRINT(RT_DEBUG_INFO, "====> RTMPHandleAtimRingTxDoneInterrupt\n");
546 RTMPHandleAtimRingTxDoneInterrupt(pAdapter);
549 if (IntSource.field.PrioRingTxDone)
551 DBGPRINT(RT_DEBUG_INFO, "====> RTMPHandlePrioRingTxDoneInterrupt\n");
552 RTMPHandlePrioRingTxDoneInterrupt(pAdapter);
555 if (IntSource.field.DecryptionDone)
557 // Scott DBGPRINT(RT_DEBUG_INFO, "====> RTMPHandleDecryptionDoneInterrupt\n");
558 RTMPHandleDecryptionDoneInterrupt(pAdapter);
561 if (IntSource.field.RxDone)
563 // Scott DBGPRINT(RT_DEBUG_INFO, "====> RTMPHandleRxDoneInterrupt\n");
564 RTMPHandleRxDoneInterrupt(pAdapter);
565 RTMPHandleEncryptionDoneInterrupt(pAdapter);
568 // Do nothing if Reset in progress
569 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RESET_IN_PROGRESS))
571 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
572 return IRQ_HANDLED;
573 #else
574 return;
575 #endif
579 // Re-enable the interrupt (disabled in RTMPIsr)
581 NICEnableInterrupt(pAdapter);
583 // Scott DBGPRINT(RT_DEBUG_INFO, "<==== RTMPHandleInterrupt\n");
584 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
585 return IRQ_HANDLED;
586 #endif
589 #if WIRELESS_EXT >= 12
591 ========================================================================
593 Routine Description:
594 get wireless statistics
596 Arguments:
597 net_dev Pointer to net_device
599 Return Value:
600 struct iw_statistics
602 Note:
603 This function will be called when query /proc
605 ========================================================================
607 struct iw_statistics *RT2500_get_wireless_stats(
608 IN struct net_device *net_dev)
610 RTMP_ADAPTER *pAd = net_dev->priv;
612 DBGPRINT(RT_DEBUG_TRACE, "RT2500_get_wireless_stats --->\n");
614 DBGPRINT(RT_DEBUG_TRACE, "pAd->PortCfg.BbpTuningEnable=%d\n", pAd->PortCfg.BbpTuningEnable);
615 DBGPRINT(RT_DEBUG_TRACE, "pAd->PortCfg.VgcLowerBound=%d\n", pAd->PortCfg.VgcLowerBound);
616 DBGPRINT(RT_DEBUG_TRACE, "pAd->PortCfg.BbpTuning.FalseCcaLowerThreshold=%d\n", pAd->PortCfg.BbpTuning.FalseCcaLowerThreshold);
617 DBGPRINT(RT_DEBUG_TRACE, "pAd->PortCfg.BbpTuning.FalseCcaUpperThreshold=%d\n", pAd->PortCfg.BbpTuning.FalseCcaUpperThreshold);
618 DBGPRINT(RT_DEBUG_TRACE, "pAd->PortCfg.BbpTuning.VgcDelta=%d\n", pAd->PortCfg.BbpTuning.VgcDelta);
619 DBGPRINT(RT_DEBUG_TRACE, "pAd->PortCfg.BbpTuning.VgcUpperBound=%d\n", pAd->PortCfg.BbpTuning.VgcUpperBound);
621 // TODO: All elements are zero before be implemented
623 pAd->iw_stats.status = 0; // Status - device dependent for now
625 pAd->iw_stats.qual.qual = 0;//pAd->Mlme.RoamCqi; // link quality (%retries, SNR, %missed beacons or better...)
626 pAd->iw_stats.qual.level = pAd->PortCfg.LastRssi; // signal level (dBm)
628 pAd->iw_stats.qual.noise = 0; // noise level (dBm)
629 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
631 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
632 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
634 // pAd->iw_stats.discard.code, discard.fragment, discard.retries, discard.misc has counted in other place
636 return &pAd->iw_stats;
638 #endif
641 ========================================================================
643 Routine Description:
644 return ethernet statistics counter
646 Arguments:
647 net_dev Pointer to net_device
649 Return Value:
650 net_device_stats*
652 Note:
654 ========================================================================
656 struct net_device_stats *RT2500_get_ether_stats(
657 IN struct net_device *net_dev)
659 RTMP_ADAPTER *pAd = net_dev->priv;
661 DBGPRINT(RT_DEBUG_INFO, "RT2500_get_ether_stats --->\n");
663 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.u.LowPart; // total packets received
664 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.u.LowPart; // total packets transmitted
666 pAd->stats.rx_bytes= pAd->RalinkCounters.ReceivedByteCount; // total bytes received
667 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount; // total bytes transmitted
669 pAd->stats.rx_errors = pAd->Counters.RxErrors; // bad packets received
670 pAd->stats.tx_errors = pAd->Counters.TxErrors; // packet transmit problems
672 pAd->stats.rx_dropped = pAd->Counters.RxNoBuffer; // no space in linux buffers
673 pAd->stats.tx_dropped = pAd->WlanCounters.FailedCount.u.LowPart; // no space available in linux
675 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.u.LowPart; // multicast packets received
676 pAd->stats.collisions = pAd->Counters.OneCollision + pAd->Counters.MoreCollisions; // Collision packets
678 pAd->stats.rx_length_errors = 0;
679 pAd->stats.rx_over_errors = pAd->Counters.RxNoBuffer; // receiver ring buff overflow
680 pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
681 pAd->stats.rx_frame_errors = pAd->Counters.RcvAlignmentErrors; // recv'd frame alignment error
682 pAd->stats.rx_fifo_errors = pAd->Counters.RxNoBuffer; // recv'r fifo overrun
683 pAd->stats.rx_missed_errors = 0; // receiver missed packet
685 // detailed tx_errors
686 pAd->stats.tx_aborted_errors = 0;
687 pAd->stats.tx_carrier_errors = 0;
688 pAd->stats.tx_fifo_errors = 0;
689 pAd->stats.tx_heartbeat_errors = 0;
690 pAd->stats.tx_window_errors = 0;
692 // for cslip etc
693 pAd->stats.rx_compressed = 0;
694 pAd->stats.tx_compressed = 0;
696 return &pAd->stats;
700 ========================================================================
702 Routine Description:
703 Set to filter multicast list
705 Arguments:
706 net_dev Pointer to net_device
708 Return Value:
709 VOID
711 Note:
713 ========================================================================
715 VOID RT2500_set_rx_mode(
716 IN struct net_device *net_dev)
718 // RTMP_ADAPTER *pAd = net_dev->priv;
719 // TODO: set_multicast_list
723 // Close driver function
725 INT RT2500_close(
726 IN struct net_device *net_dev)
728 RTMP_ADAPTER *pAd = net_dev->priv;
729 // LONG ioaddr = net_dev->base_addr;
731 DBGPRINT(RT_DEBUG_TRACE, "%s: ===> RT2500_close\n", net_dev->name);
733 // Stop Mlme state machine
734 RTMPCancelTimer(&pAd->PortCfg.RfTuningTimer);
735 MlmeHalt(pAd);
737 netif_stop_queue(net_dev);
738 netif_carrier_off(net_dev);
740 // Shut down monitor timer task
741 #if 0 // mask by Victor Yu. 01-11-2006
742 RTMPCancelTimer(&pAd->timer);
743 #endif
745 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
747 NICDisableInterrupt(pAd);
750 // Disable Rx, register value supposed will remain after reset
751 NICIssueReset(pAd);
753 // Free IRQ
754 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
756 // Deregister interrupt function
757 free_irq(net_dev->irq, net_dev);
758 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
761 // Free Ring buffers
762 RTMPFreeDMAMemory(pAd);
764 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
765 module_put(THIS_MODULE);
766 #else
767 MOD_DEC_USE_COUNT;
768 #endif
770 return 0;
774 // Remove driver function
776 static VOID __devexit RT2500_remove_one(
777 IN struct pci_dev *pPci_Dev)
779 struct net_device *net_dev = pci_get_drvdata(pPci_Dev);
780 // RTMP_ADAPTER *pAd = net_dev->priv;
782 #if 1 // add by Victor Yu. 01-12-2006
783 itfact("remove");
784 #endif
785 // Unregister network device
786 unregister_netdev(net_dev);
788 // Unmap CSR base address
789 iounmap((char *)(net_dev->base_addr));
791 // release memory region
792 release_mem_region(pci_resource_start(pPci_Dev, 0), pci_resource_len(pPci_Dev, 0));
794 // Free pre-allocated net_device memory
795 kfree(net_dev);
799 // Ralink PCI device table, include all supported chipsets
801 static struct pci_device_id rt2500_pci_tbl[] __devinitdata =
803 {0x1814, 0x0201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RT2560A},
804 {0,} /* terminate list */
806 MODULE_DEVICE_TABLE(pci, rt2500_pci_tbl);
809 // Our PCI driver structure
811 static struct pci_driver rt2500_driver =
813 name: "rt2500",
814 id_table: rt2500_pci_tbl,
815 probe: RT2500_init_one,
816 #if LINUX_VERSION_CODE >= 0x20412 || BIG_ENDIAN == TRUE || RTMP_EMBEDDED == TRUE
817 remove: __devexit_p(RT2500_remove_one),
818 #else
819 remove: __devexit(RT2500_remove_one),
820 #endif
823 // =======================================================================
824 // LOAD / UNLOAD sections
825 // =======================================================================
827 // Driver module load function
829 static INT __init rt2500_init_module(VOID)
831 return pci_module_init(&rt2500_driver);
835 // Driver module unload function
837 static VOID __exit rt2500_cleanup_module(VOID)
839 pci_unregister_driver(&rt2500_driver);
842 module_init(rt2500_init_module);
843 module_exit(rt2500_cleanup_module);