2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
31 Create and register network interface for PCI based chipsets in Linux platform.
35 -------- ---------- ----------------------------------------------
38 #include "rt_config.h"
39 #include <linux/pci.h>
42 // Function declarations
44 extern int rt28xx_close(IN struct net_device *net_dev);
45 extern int rt28xx_open(struct net_device *net_dev);
47 static VOID __devexit rt2860_remove_one(struct pci_dev *pci_dev);
48 static INT __devinit rt2860_probe(struct pci_dev *pci_dev, const struct pci_device_id *ent);
49 static void __exit rt2860_cleanup_module(void);
50 static int __init rt2860_init_module(void);
52 static VOID RTMPInitPCIeDevice(
53 IN struct pci_dev *pci_dev,
54 IN PRTMP_ADAPTER pAd);
57 static int rt2860_suspend(struct pci_dev *pci_dev, pm_message_t state);
58 static int rt2860_resume(struct pci_dev *pci_dev);
59 #endif // CONFIG_PM //
62 // Ralink PCI device table, include all supported chipsets
64 static struct pci_device_id rt2860_pci_tbl[] __devinitdata =
66 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2860_PCI_DEVICE_ID)}, //RT28602.4G
67 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2860_PCIe_DEVICE_ID)},
68 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2760_PCI_DEVICE_ID)},
69 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2790_PCIe_DEVICE_ID)},
70 {PCI_DEVICE(VEN_AWT_PCI_VENDOR_ID, VEN_AWT_PCIe_DEVICE_ID)},
71 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7708)},
72 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7728)},
73 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7758)},
74 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7727)},
75 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7738)},
76 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7748)},
77 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7768)},
78 {0,} // terminate list
81 MODULE_DEVICE_TABLE(pci, rt2860_pci_tbl);
82 MODULE_LICENSE("GPL");
84 MODULE_VERSION(STA_DRIVER_VERSION);
89 // Our PCI driver structure
91 static struct pci_driver rt2860_driver =
94 id_table: rt2860_pci_tbl,
96 remove: __devexit_p(rt2860_remove_one),
98 suspend: rt2860_suspend,
99 resume: rt2860_resume,
104 /***************************************************************************
106 * PCI device initialization related procedures.
108 ***************************************************************************/
111 VOID RT2860RejectPendingPackets(
112 IN PRTMP_ADAPTER pAd)
115 // clear TxSw packets
118 static int rt2860_suspend(
119 struct pci_dev *pci_dev,
122 struct net_device *net_dev = pci_get_drvdata(pci_dev);
123 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL;
127 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_suspend()\n"));
131 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
135 GET_PAD_FROM_NET_DEV(pAd, net_dev);
137 /* we can not use IFF_UP because ra0 down but ra1 up */
138 /* and 1 suspend/resume function for 1 module, not for each interface */
139 /* so Linux will call suspend/resume function once */
140 if (VIRTUAL_IF_NUM(pAd) > 0)
142 // avoid users do suspend after interface is down
145 netif_carrier_off(net_dev);
146 netif_stop_queue(net_dev);
148 // mark device as removed from system and therefore no longer available
149 netif_device_detach(net_dev);
152 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
153 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
155 // take down the device
156 rt28xx_close((PNET_DEV)net_dev);
158 RT_MOD_DEC_USE_COUNT();
162 // reference to http://vovo2000.com/type-lab/linux/kernel-api/linux-kernel-api.html
163 // enable device to generate PME# when suspended
164 // pci_choose_state(): Choose the power state of a PCI device to be suspended
165 retval = pci_enable_wake(pci_dev, pci_choose_state(pci_dev, state), 1);
166 // save the PCI configuration space of a device before suspending
167 pci_save_state(pci_dev);
168 // disable PCI device after use
169 pci_disable_device(pci_dev);
171 retval = pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
173 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_suspend()\n"));
177 static int rt2860_resume(
178 struct pci_dev *pci_dev)
180 struct net_device *net_dev = pci_get_drvdata(pci_dev);
181 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL;
185 // set the power state of a PCI device
186 // PCI has 4 power states, DO (normal) ~ D3(less power)
187 // in include/linux/pci.h, you can find that
188 // #define PCI_D0 ((pci_power_t __force) 0)
189 // #define PCI_D1 ((pci_power_t __force) 1)
190 // #define PCI_D2 ((pci_power_t __force) 2)
191 // #define PCI_D3hot ((pci_power_t __force) 3)
192 // #define PCI_D3cold ((pci_power_t __force) 4)
193 // #define PCI_UNKNOWN ((pci_power_t __force) 5)
194 // #define PCI_POWER_ERROR ((pci_power_t __force) -1)
195 retval = pci_set_power_state(pci_dev, PCI_D0);
197 // restore the saved state of a PCI device
198 pci_restore_state(pci_dev);
200 // initialize device before it's used by a driver
201 if (pci_enable_device(pci_dev))
203 printk("pci enable fail!\n");
207 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_resume()\n"));
211 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
214 GET_PAD_FROM_NET_DEV(pAd, net_dev);
218 /* we can not use IFF_UP because ra0 down but ra1 up */
219 /* and 1 suspend/resume function for 1 module, not for each interface */
220 /* so Linux will call suspend/resume function once */
221 if (VIRTUAL_IF_NUM(pAd) > 0)
223 // mark device as attached from system and restart if needed
224 netif_device_attach(net_dev);
226 if (rt28xx_open((PNET_DEV)net_dev) != 0)
229 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_resume()\n"));
233 // increase MODULE use count
234 RT_MOD_INC_USE_COUNT();
236 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
237 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
239 netif_start_queue(net_dev);
240 netif_carrier_on(net_dev);
241 netif_wake_queue(net_dev);
245 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_resume()\n"));
248 #endif // CONFIG_PM //
251 static INT __init rt2860_init_module(VOID)
253 return pci_register_driver(&rt2860_driver);
258 // Driver module unload function
260 static VOID __exit rt2860_cleanup_module(VOID)
262 pci_unregister_driver(&rt2860_driver);
265 module_init(rt2860_init_module);
266 module_exit(rt2860_cleanup_module);
270 // PCI device probe & initialization function
272 static INT __devinit rt2860_probe(
273 IN struct pci_dev *pci_dev,
274 IN const struct pci_device_id *pci_id)
276 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL;
277 struct net_device *net_dev;
282 RTMP_OS_NETDEV_OP_HOOK netDevHook;
284 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_probe\n"));
286 //PCIDevInit==============================================
287 // wake up and enable device
288 if ((rv = pci_enable_device(pci_dev))!= 0)
290 DBGPRINT(RT_DEBUG_ERROR, ("Enable PCI device failed, errno=%d!\n", rv));
294 print_name = pci_name(pci_dev);
296 if ((rv = pci_request_regions(pci_dev, print_name)) != 0)
298 DBGPRINT(RT_DEBUG_ERROR, ("Request PCI resource failed, errno=%d!\n", rv));
302 // map physical address to virtual address for accessing register
303 csr_addr = (unsigned long) ioremap(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0));
306 DBGPRINT(RT_DEBUG_ERROR, ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n",
307 print_name, (ULONG)pci_resource_len(pci_dev, 0), (ULONG)pci_resource_start(pci_dev, 0)));
308 goto err_out_free_res;
312 DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n", print_name,
313 (ULONG)pci_resource_start(pci_dev, 0), (ULONG)csr_addr, pci_dev->irq));
317 pci_set_master(pci_dev);
320 //RtmpDevInit==============================================
321 // Allocate RTMP_ADAPTER adapter structure
322 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
325 DBGPRINT(RT_DEBUG_ERROR, ("%s(): Allocate memory for os handle failed!\n", __func__));
326 goto err_out_iounmap;
329 ((POS_COOKIE)handle)->pci_dev = pci_dev;
331 rv = RTMPAllocAdapterBlock(handle, &pAd); //shiang: we may need the pci_dev for allocate structure of "RTMP_ADAPTER"
332 if (rv != NDIS_STATUS_SUCCESS)
333 goto err_out_iounmap;
334 // Here are the RTMP_ADAPTER structure with pci-bus specific parameters.
335 pAd->CSRBaseAddress = (PUCHAR)csr_addr;
336 DBGPRINT(RT_DEBUG_ERROR, ("pAd->CSRBaseAddress =0x%lx, csr_addr=0x%lx!\n", (ULONG)pAd->CSRBaseAddress, csr_addr));
337 RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_PCI);
340 //NetDevInit==============================================
341 net_dev = RtmpPhyNetDevInit(pAd, &netDevHook);
343 goto err_out_free_radev;
345 // Here are the net_device structure with pci-bus specific parameters.
346 net_dev->irq = pci_dev->irq; // Interrupt IRQ number
347 net_dev->base_addr = csr_addr; // Save CSR virtual address and irq to device structure
348 pci_set_drvdata(pci_dev, net_dev); // Set driver data
350 /* for supporting Network Manager */
351 /* Set the sysfs physical device reference for the network logical device
352 * if set prior to registration will cause a symlink during initialization.
354 SET_NETDEV_DEV(net_dev, &(pci_dev->dev));
357 //All done, it's time to register the net device to linux kernel.
358 // Register this device
359 rv = RtmpOSNetDevAttach(net_dev, &netDevHook);
361 goto err_out_free_netdev;
363 pAd->StaCfg.OriDevType = net_dev->type;
364 RTMPInitPCIeDevice(pci_dev, pAd);
366 #ifdef KTHREAD_SUPPORT
367 #endif // KTHREAD_SUPPORT //
369 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_probe\n"));
371 return 0; // probe ok
374 /* --------------------------- ERROR HANDLE --------------------------- */
376 RtmpOSNetDevFree(net_dev);
379 /* free RTMP_ADAPTER strcuture and os_cookie*/
380 RTMPFreeAdapter(pAd);
383 iounmap((void *)(csr_addr));
384 release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0));
387 pci_release_regions(pci_dev);
390 pci_disable_device(pci_dev);
392 DBGPRINT(RT_DEBUG_ERROR, ("<=== rt2860_probe failed with rv = %d!\n", rv));
394 return -ENODEV; /* probe fail */
398 static VOID __devexit rt2860_remove_one(
399 IN struct pci_dev *pci_dev)
401 PNET_DEV net_dev = pci_get_drvdata(pci_dev);
402 RTMP_ADAPTER *pAd = NULL;
403 ULONG csr_addr = net_dev->base_addr; // pAd->CSRBaseAddress;
405 GET_PAD_FROM_NET_DEV(pAd, net_dev);
407 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_remove_one\n"));
411 // Unregister/Free all allocated net_device.
412 RtmpPhyNetDevExit(pAd, net_dev);
414 // Unmap CSR base address
415 iounmap((char *)(csr_addr));
417 // release memory region
418 release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0));
420 // Free RTMP_ADAPTER related structures.
421 RtmpRaDevCtrlExit(pAd);
426 // Unregister network device
427 RtmpOSNetDevDetach(net_dev);
429 // Unmap CSR base address
430 iounmap((char *)(net_dev->base_addr));
432 // release memory region
433 release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0));
436 // Free the root net_device
437 RtmpOSNetDevFree(net_dev);
443 ========================================================================
445 Check the chipset vendor/product ID.
448 _dev_p Point to the PCI or USB device
455 ========================================================================
457 BOOLEAN RT28XXChipsetCheck(
465 /***************************************************************************
467 * PCIe device initialization related procedures.
469 ***************************************************************************/
470 static VOID RTMPInitPCIeDevice(
471 IN struct pci_dev *pci_dev,
472 IN PRTMP_ADAPTER pAd)
477 pObj = (POS_COOKIE) pAd->OS_Cookie;
478 pci_read_config_word(pci_dev, PCI_DEVICE_ID, &device_id);
479 device_id = le2cpu16(device_id);
480 pObj->DeviceID = device_id;
481 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE);
483 (device_id == NIC2860_PCIe_DEVICE_ID) ||
484 (device_id == NIC2790_PCIe_DEVICE_ID) ||
485 (device_id == VEN_AWT_PCIe_DEVICE_ID) ||
488 UINT32 MacCsr0 = 0, Index= 0;
491 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
493 if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF))
497 } while (Index++ < 100);
499 // Support advanced power save after 2892/2790.
500 // MAC version at offset 0x1000 is 0x2872XXXX/0x2870XXXX(PCIe, USB, SDIO).
501 if ((MacCsr0&0xffff0000) != 0x28600000)
503 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE);
509 VOID RTMPInitPCIeLinkCtrlValue(
510 IN PRTMP_ADAPTER pAd)
513 USHORT reg16, data2, PCIePowerSaveLevel, Configuration;
514 BOOLEAN bFindIntel = FALSE;
517 pObj = (POS_COOKIE) pAd->OS_Cookie;
519 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE))
522 DBGPRINT(RT_DEBUG_TRACE, ("%s.===>\n", __func__));
523 // Init EEPROM, and save settings
526 RT28xx_EEPROM_READ16(pAd, 0x22, PCIePowerSaveLevel);
527 pAd->PCIePowerSaveLevel = PCIePowerSaveLevel & 0xff;
529 if ((PCIePowerSaveLevel&0xff) == 0xff)
531 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE);
532 DBGPRINT(RT_DEBUG_TRACE, ("====> PCIePowerSaveLevel = 0x%x.\n", PCIePowerSaveLevel));
537 PCIePowerSaveLevel &= 0x3;
538 RT28xx_EEPROM_READ16(pAd, 0x24, data2);
540 if( !(((data2&0xff00) == 0x9200) && ((data2&0x80) !=0)) )
542 if (PCIePowerSaveLevel > 1 )
543 PCIePowerSaveLevel = 1;
546 DBGPRINT(RT_DEBUG_TRACE, ("====> Write 0x83 = 0x%x.\n", PCIePowerSaveLevel));
547 AsicSendCommandToMcu(pAd, 0x83, 0xff, (UCHAR)PCIePowerSaveLevel, 0x00);
548 RT28xx_EEPROM_READ16(pAd, 0x22, PCIePowerSaveLevel);
549 PCIePowerSaveLevel &= 0xff;
550 PCIePowerSaveLevel = PCIePowerSaveLevel >> 6;
551 switch(PCIePowerSaveLevel)
553 case 0: // Only support L0
554 pAd->LnkCtrlBitMask = 0;
556 case 1: // Only enable L0s
557 pAd->LnkCtrlBitMask = 1;
559 case 2: // enable L1, L0s
560 pAd->LnkCtrlBitMask = 3;
562 case 3: // sync with host clk and enable L1, L0s
563 pAd->LnkCtrlBitMask = 0x103;
566 DBGPRINT(RT_DEBUG_TRACE, ("====> LnkCtrlBitMask = 0x%x.\n", pAd->LnkCtrlBitMask));
569 else if (IS_RT3090(pAd))
571 // 1. read setting from inf file.
573 USHORT PCIePowerSetting = 0;
574 /* code from windows, default value of rt30xxPowerMode = 0
575 PCIePowerSetting = pAd->StaCfg.PSControl.field.rt30xxPowerMode;
577 DBGPRINT(RT_DEBUG_TRACE, ("====> rt30xx Read PowerLevelMode = 0x%x.\n", PCIePowerSetting));
578 // 2. Check EnableNewPS
580 if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE)
581 PCIePowerSetting = 1;
584 if ((pAd->MACVersion&0xffff) <= 0x0211)
586 // Chip Version E only allow 1
587 PCIePowerSetting = 1;
588 DBGPRINT(RT_DEBUG_TRACE, ("====> rt30xx Write 0x83 Command = 0x%x.\n", PCIePowerSetting));
589 AsicSendCommandToMcu(pAd, 0x83, 0xff, (UCHAR)PCIePowerSetting, 0x00);
593 // Chip Version F only allow 1 or 2
594 if ((PCIePowerSetting > 2) || (PCIePowerSetting == 0))
595 PCIePowerSetting = 1;
596 DBGPRINT(RT_DEBUG_TRACE, ("====> rt30xx Write 0x83 Command = 0x%x.\n", PCIePowerSetting));
597 AsicSendCommandToMcu(pAd, 0x83, 0xff, (UCHAR)PCIePowerSetting, 0x00);
602 // Find Ralink PCIe Device's Express Capability Offset
603 pos = pci_find_capability(pObj->pci_dev, PCI_CAP_ID_EXP);
607 // Ralink PCIe Device's Link Control Register Offset
608 pAd->RLnkCtrlOffset = pos + PCI_EXP_LNKCTL;
609 pci_read_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset, ®16);
610 Configuration = le2cpu16(reg16);
611 DBGPRINT(RT_DEBUG_TRACE, ("Read (Ralink PCIe Link Control Register) offset 0x%x = 0x%x\n",
612 pAd->RLnkCtrlOffset, Configuration));
613 pAd->RLnkCtrlConfiguration = (Configuration & 0x103);
614 Configuration &= 0xfefc;
615 Configuration |= (0x0);
616 if ((pObj->DeviceID == NIC2860_PCIe_DEVICE_ID)
617 ||(pObj->DeviceID == NIC2790_PCIe_DEVICE_ID))
619 reg16 = cpu2le16(Configuration);
620 pci_write_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset, reg16);
621 DBGPRINT(RT_DEBUG_TRACE, ("Write (Ralink PCIe Link Control Register) offset 0x%x = 0x%x\n",
622 pos + PCI_EXP_LNKCTL, Configuration));
625 RTMPFindHostPCIDev(pAd);
626 if (pObj->parent_pci_dev)
630 pci_read_config_word(pObj->parent_pci_dev, PCI_VENDOR_ID, &vendor_id);
631 vendor_id = le2cpu16(vendor_id);
632 if (vendor_id == PCIBUS_INTEL_VENDOR)
635 // Find PCI-to-PCI Bridge Express Capability Offset
636 pos = pci_find_capability(pObj->parent_pci_dev, PCI_CAP_ID_EXP);
640 BOOLEAN bChange = FALSE;
641 // PCI-to-PCI Bridge Link Control Register Offset
642 pAd->HostLnkCtrlOffset = pos + PCI_EXP_LNKCTL;
643 pci_read_config_word(pObj->parent_pci_dev, pAd->HostLnkCtrlOffset, ®16);
644 Configuration = le2cpu16(reg16);
645 DBGPRINT(RT_DEBUG_TRACE, ("Read (Host PCI-to-PCI Bridge Link Control Register) offset 0x%x = 0x%x\n",
646 pAd->HostLnkCtrlOffset, Configuration));
647 pAd->HostLnkCtrlConfiguration = (Configuration & 0x103);
648 Configuration &= 0xfefc;
649 Configuration |= (0x0);
651 switch (pObj->DeviceID)
653 case NIC2860_PCIe_DEVICE_ID:
654 case NIC2790_PCIe_DEVICE_ID:
663 reg16 = cpu2le16(Configuration);
664 pci_write_config_word(pObj->parent_pci_dev, pAd->HostLnkCtrlOffset, reg16);
665 DBGPRINT(RT_DEBUG_TRACE, ("Write (Host PCI-to-PCI Bridge Link Control Register) offset 0x%x = 0x%x\n",
666 pAd->HostLnkCtrlOffset, Configuration));
671 pAd->HostLnkCtrlOffset = 0;
672 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot find PCI-to-PCI Bridge PCI Express Capability!\n", __func__));
678 pAd->RLnkCtrlOffset = 0;
679 pAd->HostLnkCtrlOffset = 0;
680 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot find Ralink PCIe Device's PCI Express Capability!\n", __func__));
683 if (bFindIntel == FALSE)
685 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't find Intel PCI host controller. \n"));
686 // Doesn't switch L0, L1, So set PCIePowerSaveLevel to 0xff
687 pAd->PCIePowerSaveLevel = 0xff;
688 if ((pAd->RLnkCtrlOffset != 0)
691 pci_read_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset, ®16);
692 Configuration = le2cpu16(reg16);
693 DBGPRINT(RT_DEBUG_TRACE, ("Read (Ralink 30xx PCIe Link Control Register) offset 0x%x = 0x%x\n",
694 pAd->RLnkCtrlOffset, Configuration));
695 pAd->RLnkCtrlConfiguration = (Configuration & 0x103);
696 Configuration &= 0xfefc;
697 Configuration |= (0x0);
698 reg16 = cpu2le16(Configuration);
699 pci_write_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset, reg16);
700 DBGPRINT(RT_DEBUG_TRACE, ("Write (Ralink PCIe Link Control Register) offset 0x%x = 0x%x\n",
701 pos + PCI_EXP_LNKCTL, Configuration));
706 VOID RTMPFindHostPCIDev(
707 IN PRTMP_ADAPTER pAd)
715 pObj = (POS_COOKIE) pAd->OS_Cookie;
717 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE))
720 DBGPRINT(RT_DEBUG_TRACE, ("%s.===>\n", __func__));
722 pObj->parent_pci_dev = NULL;
723 if (pObj->pci_dev->bus->parent)
725 for (DevFn = 0; DevFn < 255; DevFn++)
727 pPci_dev = pci_get_slot(pObj->pci_dev->bus->parent, DevFn);
730 pci_read_config_word(pPci_dev, PCI_CLASS_DEVICE, ®16);
731 reg16 = le2cpu16(reg16);
732 pci_read_config_byte(pPci_dev, PCI_CB_CARD_BUS, ®8);
733 if ((reg16 == PCI_CLASS_BRIDGE_PCI) &&
734 (reg8 == pObj->pci_dev->bus->number))
736 pObj->parent_pci_dev = pPci_dev;
744 ========================================================================
749 Level = RESTORE_HALT : Restore PCI host and Ralink PCIe Link Control field to its default value.
750 Level = Other Value : Restore from dot11 power save or radio off status. And force PCI host Link Control fields to 0x1
752 ========================================================================
754 VOID RTMPPCIeLinkCtrlValueRestore(
755 IN PRTMP_ADAPTER pAd,
758 USHORT PCIePowerSaveLevel, reg16;
759 USHORT Configuration;
762 pObj = (POS_COOKIE) pAd->OS_Cookie;
764 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE))
767 if (!((pObj->DeviceID == NIC2860_PCIe_DEVICE_ID)
768 ||(pObj->DeviceID == NIC2790_PCIe_DEVICE_ID)))
771 DBGPRINT(RT_DEBUG_TRACE, ("%s.===>\n", __func__));
772 PCIePowerSaveLevel = pAd->PCIePowerSaveLevel;
773 if ((PCIePowerSaveLevel&0xff) == 0xff)
775 DBGPRINT(RT_DEBUG_TRACE,("return \n"));
779 if (pObj->parent_pci_dev && (pAd->HostLnkCtrlOffset != 0))
781 PCI_REG_READ_WORD(pObj->parent_pci_dev, pAd->HostLnkCtrlOffset, Configuration);
782 if ((Configuration != 0) &&
783 (Configuration != 0xFFFF))
785 Configuration &= 0xfefc;
786 // If call from interface down, restore to orginial setting.
787 if (Level == RESTORE_CLOSE)
789 Configuration |= pAd->HostLnkCtrlConfiguration;
792 Configuration |= 0x0;
793 PCI_REG_WIRTE_WORD(pObj->parent_pci_dev, pAd->HostLnkCtrlOffset, Configuration);
794 DBGPRINT(RT_DEBUG_TRACE, ("Restore PCI host : offset 0x%x = 0x%x\n", pAd->HostLnkCtrlOffset, Configuration));
797 DBGPRINT(RT_DEBUG_ERROR, ("Restore PCI host : PCI_REG_READ_WORD failed (Configuration = 0x%x)\n", Configuration));
800 if (pObj->pci_dev && (pAd->RLnkCtrlOffset != 0))
802 PCI_REG_READ_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset, Configuration);
803 if ((Configuration != 0) &&
804 (Configuration != 0xFFFF))
806 Configuration &= 0xfefc;
807 // If call from interface down, restore to orginial setting.
808 if (Level == RESTORE_CLOSE)
809 Configuration |= pAd->RLnkCtrlConfiguration;
811 Configuration |= 0x0;
812 PCI_REG_WIRTE_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset, Configuration);
813 DBGPRINT(RT_DEBUG_TRACE, ("Restore Ralink : offset 0x%x = 0x%x\n", pAd->RLnkCtrlOffset, Configuration));
816 DBGPRINT(RT_DEBUG_ERROR, ("Restore Ralink : PCI_REG_READ_WORD failed (Configuration = 0x%x)\n", Configuration));
819 DBGPRINT(RT_DEBUG_TRACE,("%s <===\n", __func__));
823 ========================================================================
828 Max : limit Host PCI and Ralink PCIe device's LINK CONTROL field's value.
829 Because now frequently set our device to mode 1 or mode 3 will cause problem.
831 ========================================================================
833 VOID RTMPPCIeLinkCtrlSetting(
834 IN PRTMP_ADAPTER pAd,
837 USHORT PCIePowerSaveLevel, reg16;
838 USHORT Configuration;
841 pObj = (POS_COOKIE) pAd->OS_Cookie;
843 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE))
846 if (!((pObj->DeviceID == NIC2860_PCIe_DEVICE_ID)
847 ||(pObj->DeviceID == NIC2790_PCIe_DEVICE_ID)))
850 DBGPRINT(RT_DEBUG_TRACE,("%s===>\n", __func__));
851 PCIePowerSaveLevel = pAd->PCIePowerSaveLevel;
852 if ((PCIePowerSaveLevel&0xff) == 0xff)
854 DBGPRINT(RT_DEBUG_TRACE,("return \n"));
857 PCIePowerSaveLevel = PCIePowerSaveLevel>>6;
860 if (pObj->pci_dev && (pAd->RLnkCtrlOffset != 0))
862 // first 2892 chip not allow to frequently set mode 3. will cause hang problem.
863 if (PCIePowerSaveLevel > Max)
864 PCIePowerSaveLevel = Max;
866 PCI_REG_READ_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset, Configuration);
867 Configuration |= 0x100;
868 PCI_REG_WIRTE_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset, Configuration);
869 DBGPRINT(RT_DEBUG_TRACE, ("Write Ralink device : offset 0x%x = 0x%x\n", pAd->RLnkCtrlOffset, Configuration));
872 DBGPRINT(RT_DEBUG_TRACE,("RTMPPCIePowerLinkCtrl <==============\n"));