2 ***************************************************************************
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 ***************************************************************************
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
36 ULONG RTDebugLevel
= 6;
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 ");
43 #if LINUX_VERSION_CODE >= 0x20412 // Red Hat 7.3
44 MODULE_LICENSE("GPL");
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
;
57 if ( !current
->fs
->root
)
59 if ( !(envp
=(char **)kmalloc(10*sizeof(char *), GFP_KERNEL
)) )
61 if ( !(buf
=kmalloc(256, GFP_KERNEL
)) )
63 argv
[0] = "/bin/wirelesspnp";
66 envp
[i
++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
69 scratch
+= sprintf(scratch
, "ACTION=%s", action
) + 1;
71 call_usermodehelper(argv
[0], argv
, envp
, 0);
77 static INT __devinit
RT2500_init_one (
78 IN
struct pci_dev
*pPci_Dev
,
79 IN
const struct pci_device_id
*ent
)
83 // wake up and enable device
84 if (pci_enable_device (pPci_Dev
)) {
87 rc
= RT2500_probe(pPci_Dev
, ent
);
88 #if 1 // add by Victor Yu. 01-12-2006
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
;
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
);
108 DBGPRINT(RT_DEBUG_ERROR
, "alloc_netdev: Unable to allocate device memory.\n");
112 memset(dev
, 0, alloc_size
);
115 dev
->priv
= (void *) (((long)(dev
+ 1) + 31) & ~31);
118 strcpy(dev
->name
,mask
);
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
;
134 INT chip_id
= (int) ent
->driver_data
;
136 CSR3_STRUC StaMacReg0
;
137 CSR4_STRUC StaMacReg1
;
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
);
145 net_dev
= alloc_etherdev(sizeof(RTMP_ADAPTER
));
149 DBGPRINT(RT_DEBUG_TRACE
, "init_ethernet failed\n");
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));
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
;
173 pAd
->CSRBaseAddress
= csr_addr
;
174 pAd
->net_dev
= net_dev
;
177 pci_set_master(pPci_Dev
);
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
;
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");
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)
241 if(device
== NULL
) break;
245 DBGPRINT(RT_DEBUG_ERROR
, "No available slot name\n");
249 sprintf(net_dev
->name
, "eth%d", i
); // Scott
253 // Register this device
254 Status
= register_netdev(net_dev
);
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
);
262 pci_set_drvdata(pPci_Dev
, net_dev
);
267 iounmap((void *)csr_addr
);
268 release_mem_region(pci_resource_start(pPci_Dev
, 0), pci_resource_len(pPci_Dev
, 0));
270 pci_release_regions(pPci_Dev
);
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__
);
293 // 1. Allocate DMA descriptors & buffers
294 status
= RTMPAllocDMAMemory(pAd
);
295 if (status
!= NDIS_STATUS_SUCCESS
)
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
);
309 RTMPFreeDMAMemory(pAd
);
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
326 // Read RaConfig profile parameters
327 RTMPReadParametersFromFile(pAd
);
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
);
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);*/
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
);
370 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
371 module_put(THIS_MODULE
);
380 IN
unsigned long data
)
382 RTMP_ADAPTER
*pAd
= (RTMP_ADAPTER
*)data
;
384 // NICCheckForHang(pAd);
386 RTMPSetTimer(pAd
, &pAd
->timer
, DEBUG_TASK_DELAY
);
390 ========================================================================
393 hard_start_xmit handler
396 skb point to sk_buf which upper layer transmit
397 net_dev point to net_dev
403 ========================================================================
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
);
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
451 RTMPDeQueuePacket(pAdapter
);
458 ========================================================================
465 dev_instance Pointer to net_device
466 rgs store process's context before entering ISR,
467 this parameter is just for debug purpose.
474 ========================================================================
476 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
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)
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)
589 #if WIRELESS_EXT >= 12
591 ========================================================================
594 get wireless statistics
597 net_dev Pointer to net_device
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
;
641 ========================================================================
644 return ethernet statistics counter
647 net_dev Pointer to net_device
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;
693 pAd
->stats
.rx_compressed
= 0;
694 pAd
->stats
.tx_compressed
= 0;
700 ========================================================================
703 Set to filter multicast list
706 net_dev Pointer to net_device
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
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
);
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
);
745 if (RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_INTERRUPT_ACTIVE
))
747 NICDisableInterrupt(pAd
);
750 // Disable Rx, register value supposed will remain after reset
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
);
762 RTMPFreeDMAMemory(pAd
);
764 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
765 module_put(THIS_MODULE
);
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
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
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
=
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
),
819 remove
: __devexit(RT2500_remove_one
),
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
);