1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
37 static const u16 pcibridge_vendors
[PCI_BRIDGE_VENDOR_MAX
] = {
44 static const u8 ac_to_hwq
[] = {
51 static u8
_rtl_mac_to_hwqueue(struct ieee80211_hw
*hw
,
54 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
55 __le16 fc
= rtl_get_fc(skb
);
56 u8 queue_index
= skb_get_queue_mapping(skb
);
58 if (unlikely(ieee80211_is_beacon(fc
)))
60 if (ieee80211_is_mgmt(fc
))
62 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
)
63 if (ieee80211_is_nullfunc(fc
))
66 return ac_to_hwq
[queue_index
];
69 /* Update PCI dependent default settings*/
70 static void _rtl_pci_update_default_setting(struct ieee80211_hw
*hw
)
72 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
73 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
74 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
75 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
76 u8 pcibridge_vendor
= pcipriv
->ndis_adapter
.pcibridge_vendor
;
79 ppsc
->reg_rfps_level
= 0;
80 ppsc
->support_aspm
= 0;
82 /*Update PCI ASPM setting */
83 ppsc
->const_amdpci_aspm
= rtlpci
->const_amdpci_aspm
;
84 switch (rtlpci
->const_pci_aspm
) {
90 /*ASPM dynamically enabled/disable. */
91 ppsc
->reg_rfps_level
|= RT_RF_LPS_LEVEL_ASPM
;
95 /*ASPM with Clock Req dynamically enabled/disable. */
96 ppsc
->reg_rfps_level
|= (RT_RF_LPS_LEVEL_ASPM
|
97 RT_RF_OFF_LEVL_CLK_REQ
);
102 * Always enable ASPM and Clock Req
103 * from initialization to halt.
105 ppsc
->reg_rfps_level
&= ~(RT_RF_LPS_LEVEL_ASPM
);
106 ppsc
->reg_rfps_level
|= (RT_RF_PS_LEVEL_ALWAYS_ASPM
|
107 RT_RF_OFF_LEVL_CLK_REQ
);
112 * Always enable ASPM without Clock Req
113 * from initialization to halt.
115 ppsc
->reg_rfps_level
&= ~(RT_RF_LPS_LEVEL_ASPM
|
116 RT_RF_OFF_LEVL_CLK_REQ
);
117 ppsc
->reg_rfps_level
|= RT_RF_PS_LEVEL_ALWAYS_ASPM
;
121 ppsc
->reg_rfps_level
|= RT_RF_OFF_LEVL_HALT_NIC
;
123 /*Update Radio OFF setting */
124 switch (rtlpci
->const_hwsw_rfoff_d3
) {
126 if (ppsc
->reg_rfps_level
& RT_RF_LPS_LEVEL_ASPM
)
127 ppsc
->reg_rfps_level
|= RT_RF_OFF_LEVL_ASPM
;
131 if (ppsc
->reg_rfps_level
& RT_RF_LPS_LEVEL_ASPM
)
132 ppsc
->reg_rfps_level
|= RT_RF_OFF_LEVL_ASPM
;
133 ppsc
->reg_rfps_level
|= RT_RF_OFF_LEVL_HALT_NIC
;
137 ppsc
->reg_rfps_level
|= RT_RF_OFF_LEVL_PCI_D3
;
141 /*Set HW definition to determine if it supports ASPM. */
142 switch (rtlpci
->const_support_pciaspm
) {
144 /*Not support ASPM. */
145 bool support_aspm
= false;
146 ppsc
->support_aspm
= support_aspm
;
151 bool support_aspm
= true;
152 bool support_backdoor
= true;
153 ppsc
->support_aspm
= support_aspm
;
155 /*if (priv->oem_id == RT_CID_TOSHIBA &&
156 !priv->ndis_adapter.amd_l1_patch)
157 support_backdoor = false; */
159 ppsc
->support_backdoor
= support_backdoor
;
164 /*ASPM value set by chipset. */
165 if (pcibridge_vendor
== PCI_BRIDGE_VENDOR_INTEL
) {
166 bool support_aspm
= true;
167 ppsc
->support_aspm
= support_aspm
;
171 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
172 ("switch case not process\n"));
176 /* toshiba aspm issue, toshiba will set aspm selfly
177 * so we should not set aspm in driver */
178 pci_read_config_byte(rtlpci
->pdev
, 0x80, &init_aspm
);
179 if (rtlpriv
->rtlhal
.hw_type
== HARDWARE_TYPE_RTL8192SE
&&
181 ppsc
->support_aspm
= false;
184 static bool _rtl_pci_platform_switch_device_pci_aspm(
185 struct ieee80211_hw
*hw
,
188 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
189 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
191 if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192SE
)
194 pci_write_config_byte(rtlpci
->pdev
, 0x80, value
);
199 /*When we set 0x01 to enable clk request. Set 0x0 to disable clk req.*/
200 static bool _rtl_pci_switch_clk_req(struct ieee80211_hw
*hw
, u8 value
)
202 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
203 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
205 pci_write_config_byte(rtlpci
->pdev
, 0x81, value
);
207 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
)
213 /*Disable RTL8192SE ASPM & Disable Pci Bridge ASPM*/
214 static void rtl_pci_disable_aspm(struct ieee80211_hw
*hw
)
216 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
217 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
218 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
219 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
220 u8 pcibridge_vendor
= pcipriv
->ndis_adapter
.pcibridge_vendor
;
221 u8 num4bytes
= pcipriv
->ndis_adapter
.num4bytes
;
222 /*Retrieve original configuration settings. */
223 u8 linkctrl_reg
= pcipriv
->ndis_adapter
.linkctrl_reg
;
224 u16 pcibridge_linkctrlreg
= pcipriv
->ndis_adapter
.
225 pcibridge_linkctrlreg
;
229 if (!ppsc
->support_aspm
)
232 if (pcibridge_vendor
== PCI_BRIDGE_VENDOR_UNKNOWN
) {
233 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
234 ("PCI(Bridge) UNKNOWN.\n"));
239 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_CLK_REQ
) {
240 RT_CLEAR_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_CLK_REQ
);
241 _rtl_pci_switch_clk_req(hw
, 0x0);
244 /*for promising device will in L0 state after an I/O. */
245 pci_read_config_byte(rtlpci
->pdev
, 0x80, &tmp_u1b
);
247 /*Set corresponding value. */
248 aspmlevel
|= BIT(0) | BIT(1);
249 linkctrl_reg
&= ~aspmlevel
;
250 pcibridge_linkctrlreg
&= ~(BIT(0) | BIT(1));
252 _rtl_pci_platform_switch_device_pci_aspm(hw
, linkctrl_reg
);
255 /*4 Disable Pci Bridge ASPM */
256 pci_write_config_byte(rtlpci
->pdev
, (num4bytes
<< 2),
257 pcibridge_linkctrlreg
);
263 *Enable RTL8192SE ASPM & Enable Pci Bridge ASPM for
264 *power saving We should follow the sequence to enable
265 *RTL8192SE first then enable Pci Bridge ASPM
266 *or the system will show bluescreen.
268 static void rtl_pci_enable_aspm(struct ieee80211_hw
*hw
)
270 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
271 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
272 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
273 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
274 u8 pcibridge_busnum
= pcipriv
->ndis_adapter
.pcibridge_busnum
;
275 u8 pcibridge_devnum
= pcipriv
->ndis_adapter
.pcibridge_devnum
;
276 u8 pcibridge_funcnum
= pcipriv
->ndis_adapter
.pcibridge_funcnum
;
277 u8 pcibridge_vendor
= pcipriv
->ndis_adapter
.pcibridge_vendor
;
278 u8 num4bytes
= pcipriv
->ndis_adapter
.num4bytes
;
280 u8 u_pcibridge_aspmsetting
;
281 u8 u_device_aspmsetting
;
283 if (!ppsc
->support_aspm
)
286 if (pcibridge_vendor
== PCI_BRIDGE_VENDOR_UNKNOWN
) {
287 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
288 ("PCI(Bridge) UNKNOWN.\n"));
292 /*4 Enable Pci Bridge ASPM */
294 u_pcibridge_aspmsetting
=
295 pcipriv
->ndis_adapter
.pcibridge_linkctrlreg
|
296 rtlpci
->const_hostpci_aspm_setting
;
298 if (pcibridge_vendor
== PCI_BRIDGE_VENDOR_INTEL
)
299 u_pcibridge_aspmsetting
&= ~BIT(0);
301 pci_write_config_byte(rtlpci
->pdev
, (num4bytes
<< 2),
302 u_pcibridge_aspmsetting
);
304 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
305 ("PlatformEnableASPM():PciBridge busnumber[%x], "
306 "DevNumbe[%x], funcnumber[%x], Write reg[%x] = %x\n",
307 pcibridge_busnum
, pcibridge_devnum
, pcibridge_funcnum
,
308 (pcipriv
->ndis_adapter
.pcibridge_pciehdr_offset
+ 0x10),
309 u_pcibridge_aspmsetting
));
313 /*Get ASPM level (with/without Clock Req) */
314 aspmlevel
= rtlpci
->const_devicepci_aspm_setting
;
315 u_device_aspmsetting
= pcipriv
->ndis_adapter
.linkctrl_reg
;
317 /*_rtl_pci_platform_switch_device_pci_aspm(dev,*/
318 /*(priv->ndis_adapter.linkctrl_reg | ASPMLevel)); */
320 u_device_aspmsetting
|= aspmlevel
;
322 _rtl_pci_platform_switch_device_pci_aspm(hw
, u_device_aspmsetting
);
324 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_CLK_REQ
) {
325 _rtl_pci_switch_clk_req(hw
, (ppsc
->reg_rfps_level
&
326 RT_RF_OFF_LEVL_CLK_REQ
) ? 1 : 0);
327 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_CLK_REQ
);
332 static bool rtl_pci_get_amd_l1_patch(struct ieee80211_hw
*hw
)
334 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
340 pci_write_config_byte(rtlpci
->pdev
, 0xe0, 0xa0);
342 pci_read_config_byte(rtlpci
->pdev
, 0xe0, &offset_e0
);
344 if (offset_e0
== 0xA0) {
345 pci_read_config_dword(rtlpci
->pdev
, 0xe4, &offset_e4
);
346 if (offset_e4
& BIT(23))
353 static void rtl_pci_get_linkcontrol_field(struct ieee80211_hw
*hw
)
355 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
356 struct rtl_pci
*rtlpci
= rtl_pcidev(pcipriv
);
357 u8 capabilityoffset
= pcipriv
->ndis_adapter
.pcibridge_pciehdr_offset
;
361 num4bbytes
= (capabilityoffset
+ 0x10) / 4;
363 /*Read Link Control Register */
364 pci_read_config_byte(rtlpci
->pdev
, (num4bbytes
<< 2), &linkctrl_reg
);
366 pcipriv
->ndis_adapter
.pcibridge_linkctrlreg
= linkctrl_reg
;
369 static void rtl_pci_parse_configuration(struct pci_dev
*pdev
,
370 struct ieee80211_hw
*hw
)
372 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
373 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
379 /*Link Control Register */
380 pos
= pci_pcie_cap(pdev
);
381 pci_read_config_byte(pdev
, pos
+ PCI_EXP_LNKCTL
, &linkctrl_reg
);
382 pcipriv
->ndis_adapter
.linkctrl_reg
= linkctrl_reg
;
384 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
385 ("Link Control Register =%x\n",
386 pcipriv
->ndis_adapter
.linkctrl_reg
));
388 pci_read_config_byte(pdev
, 0x98, &tmp
);
390 pci_write_config_byte(pdev
, 0x98, tmp
);
393 pci_write_config_byte(pdev
, 0x70f, tmp
);
396 static void rtl_pci_init_aspm(struct ieee80211_hw
*hw
)
398 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
400 _rtl_pci_update_default_setting(hw
);
402 if (ppsc
->reg_rfps_level
& RT_RF_PS_LEVEL_ALWAYS_ASPM
) {
403 /*Always enable ASPM & Clock Req. */
404 rtl_pci_enable_aspm(hw
);
405 RT_SET_PS_LEVEL(ppsc
, RT_RF_PS_LEVEL_ALWAYS_ASPM
);
410 static void _rtl_pci_io_handler_init(struct device
*dev
,
411 struct ieee80211_hw
*hw
)
413 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
415 rtlpriv
->io
.dev
= dev
;
417 rtlpriv
->io
.write8_async
= pci_write8_async
;
418 rtlpriv
->io
.write16_async
= pci_write16_async
;
419 rtlpriv
->io
.write32_async
= pci_write32_async
;
421 rtlpriv
->io
.read8_sync
= pci_read8_sync
;
422 rtlpriv
->io
.read16_sync
= pci_read16_sync
;
423 rtlpriv
->io
.read32_sync
= pci_read32_sync
;
427 static void _rtl_pci_io_handler_release(struct ieee80211_hw
*hw
)
431 static bool _rtl_update_earlymode_info(struct ieee80211_hw
*hw
,
432 struct sk_buff
*skb
, struct rtl_tcb_desc
*tcb_desc
, u8 tid
)
434 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
435 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
436 u8 additionlen
= FCS_LEN
;
437 struct sk_buff
*next_skb
;
439 /* here open is 4, wep/tkip is 8, aes is 12*/
440 if (info
->control
.hw_key
)
441 additionlen
+= info
->control
.hw_key
->icv_len
;
443 /* The most skb num is 6 */
444 tcb_desc
->empkt_num
= 0;
445 spin_lock_bh(&rtlpriv
->locks
.waitq_lock
);
446 skb_queue_walk(&rtlpriv
->mac80211
.skb_waitq
[tid
], next_skb
) {
447 struct ieee80211_tx_info
*next_info
;
449 next_info
= IEEE80211_SKB_CB(next_skb
);
450 if (next_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
451 tcb_desc
->empkt_len
[tcb_desc
->empkt_num
] =
452 next_skb
->len
+ additionlen
;
453 tcb_desc
->empkt_num
++;
458 if (skb_queue_is_last(&rtlpriv
->mac80211
.skb_waitq
[tid
],
462 if (tcb_desc
->empkt_num
>= 5)
465 spin_unlock_bh(&rtlpriv
->locks
.waitq_lock
);
470 /* just for early mode now */
471 static void _rtl_pci_tx_chk_waitq(struct ieee80211_hw
*hw
)
473 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
474 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
475 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
476 struct sk_buff
*skb
= NULL
;
477 struct ieee80211_tx_info
*info
= NULL
;
478 int tid
; /* should be int */
480 if (!rtlpriv
->rtlhal
.earlymode_enable
)
483 /* we juse use em for BE/BK/VI/VO */
484 for (tid
= 7; tid
>= 0; tid
--) {
485 u8 hw_queue
= ac_to_hwq
[rtl_tid_to_ac(hw
, tid
)];
486 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[hw_queue
];
487 while (!mac
->act_scanning
&&
488 rtlpriv
->psc
.rfpwr_state
== ERFON
) {
489 struct rtl_tcb_desc tcb_desc
;
490 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
492 spin_lock_bh(&rtlpriv
->locks
.waitq_lock
);
493 if (!skb_queue_empty(&mac
->skb_waitq
[tid
]) &&
494 (ring
->entries
- skb_queue_len(&ring
->queue
) > 5)) {
495 skb
= skb_dequeue(&mac
->skb_waitq
[tid
]);
497 spin_unlock_bh(&rtlpriv
->locks
.waitq_lock
);
500 spin_unlock_bh(&rtlpriv
->locks
.waitq_lock
);
502 /* Some macaddr can't do early mode. like
503 * multicast/broadcast/no_qos data */
504 info
= IEEE80211_SKB_CB(skb
);
505 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
)
506 _rtl_update_earlymode_info(hw
, skb
,
509 rtlpriv
->intf_ops
->adapter_tx(hw
, skb
, &tcb_desc
);
515 static void _rtl_pci_tx_isr(struct ieee80211_hw
*hw
, int prio
)
517 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
518 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
520 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[prio
];
522 while (skb_queue_len(&ring
->queue
)) {
523 struct rtl_tx_desc
*entry
= &ring
->desc
[ring
->idx
];
525 struct ieee80211_tx_info
*info
;
529 u8 own
= (u8
) rtlpriv
->cfg
->ops
->get_desc((u8
*) entry
, true,
533 *beacon packet will only use the first
534 *descriptor defautly,and the own may not
535 *be cleared by the hardware
539 ring
->idx
= (ring
->idx
+ 1) % ring
->entries
;
541 skb
= __skb_dequeue(&ring
->queue
);
542 pci_unmap_single(rtlpci
->pdev
,
544 get_desc((u8
*) entry
, true,
545 HW_DESC_TXBUFF_ADDR
),
546 skb
->len
, PCI_DMA_TODEVICE
);
548 /* remove early mode header */
549 if (rtlpriv
->rtlhal
.earlymode_enable
)
550 skb_pull(skb
, EM_HDR_LEN
);
552 RT_TRACE(rtlpriv
, (COMP_INTR
| COMP_SEND
), DBG_TRACE
,
553 ("new ring->idx:%d, "
554 "free: skb_queue_len:%d, free: seq:%x\n",
556 skb_queue_len(&ring
->queue
),
557 *(u16
*) (skb
->data
+ 22)));
559 if (prio
== TXCMD_QUEUE
) {
565 /* for sw LPS, just after NULL skb send out, we can
566 * sure AP kown we are sleeped, our we should not let
568 fc
= rtl_get_fc(skb
);
569 if (ieee80211_is_nullfunc(fc
)) {
570 if (ieee80211_has_pm(fc
)) {
571 rtlpriv
->mac80211
.offchan_delay
= true;
572 rtlpriv
->psc
.state_inap
= 1;
574 rtlpriv
->psc
.state_inap
= 0;
578 /* update tid tx pkt num */
579 tid
= rtl_get_tid(skb
);
581 rtlpriv
->link_info
.tidtx_inperiod
[tid
]++;
583 info
= IEEE80211_SKB_CB(skb
);
584 ieee80211_tx_info_clear_status(info
);
586 info
->flags
|= IEEE80211_TX_STAT_ACK
;
587 /*info->status.rates[0].count = 1; */
589 ieee80211_tx_status_irqsafe(hw
, skb
);
591 if ((ring
->entries
- skb_queue_len(&ring
->queue
))
594 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
595 ("more desc left, wake"
596 "skb_queue@%d,ring->idx = %d,"
597 "skb_queue_len = 0x%d\n",
599 skb_queue_len(&ring
->queue
)));
601 ieee80211_wake_queue(hw
,
602 skb_get_queue_mapping
609 if (((rtlpriv
->link_info
.num_rx_inperiod
+
610 rtlpriv
->link_info
.num_tx_inperiod
) > 8) ||
611 (rtlpriv
->link_info
.num_rx_inperiod
> 2)) {
612 tasklet_schedule(&rtlpriv
->works
.ips_leave_tasklet
);
616 static void _rtl_receive_one(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
617 struct ieee80211_rx_status rx_status
)
619 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
620 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
621 __le16 fc
= rtl_get_fc(skb
);
622 bool unicast
= false;
623 struct sk_buff
*uskb
= NULL
;
627 memcpy(IEEE80211_SKB_RXCB(skb
), &rx_status
, sizeof(rx_status
));
629 if (is_broadcast_ether_addr(hdr
->addr1
)) {
631 } else if (is_multicast_ether_addr(hdr
->addr1
)) {
635 rtlpriv
->stats
.rxbytesunicast
+= skb
->len
;
638 rtl_is_special_data(hw
, skb
, false);
640 if (ieee80211_is_data(fc
)) {
641 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_RX
);
644 rtlpriv
->link_info
.num_rx_inperiod
++;
648 rtl_swlps_beacon(hw
, (void *)skb
->data
, skb
->len
);
649 rtl_recognize_peer(hw
, (void *)skb
->data
, skb
->len
);
650 if ((rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_AP
) &&
651 (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
) &&
652 (ieee80211_is_beacon(fc
) || ieee80211_is_probe_resp(fc
)))
655 if (unlikely(!rtl_action_proc(hw
, skb
, false)))
658 uskb
= dev_alloc_skb(skb
->len
+ 128);
659 memcpy(IEEE80211_SKB_RXCB(uskb
), &rx_status
, sizeof(rx_status
));
660 pdata
= (u8
*)skb_put(uskb
, skb
->len
);
661 memcpy(pdata
, skb
->data
, skb
->len
);
663 ieee80211_rx_irqsafe(hw
, uskb
);
666 static void _rtl_pci_rx_interrupt(struct ieee80211_hw
*hw
)
668 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
669 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
670 int rx_queue_idx
= RTL_PCI_RX_MPDU_QUEUE
;
672 struct ieee80211_rx_status rx_status
= { 0 };
673 unsigned int count
= rtlpci
->rxringcount
;
678 struct rtl_stats stats
= {
683 int index
= rtlpci
->rx_ring
[rx_queue_idx
].idx
;
688 struct rtl_rx_desc
*pdesc
= &rtlpci
->rx_ring
[rx_queue_idx
].desc
[
691 struct sk_buff
*skb
= rtlpci
->rx_ring
[rx_queue_idx
].rx_buf
[
693 struct sk_buff
*new_skb
= NULL
;
695 own
= (u8
) rtlpriv
->cfg
->ops
->get_desc((u8
*) pdesc
,
698 /*wait data to be filled by hardware */
702 rtlpriv
->cfg
->ops
->query_rx_desc(hw
, &stats
,
706 if (stats
.crc
|| stats
.hwerror
)
709 new_skb
= dev_alloc_skb(rtlpci
->rxbuffersize
);
710 if (unlikely(!new_skb
)) {
711 RT_TRACE(rtlpriv
, (COMP_INTR
| COMP_RECV
),
713 ("can't alloc skb for rx\n"));
717 pci_unmap_single(rtlpci
->pdev
,
718 *((dma_addr_t
*) skb
->cb
),
719 rtlpci
->rxbuffersize
,
722 skb_put(skb
, rtlpriv
->cfg
->ops
->get_desc((u8
*) pdesc
, false,
724 skb_reserve(skb
, stats
.rx_drvinfo_size
+ stats
.rx_bufshift
);
727 * NOTICE This can not be use for mac80211,
728 * this is done in mac80211 code,
729 * if you done here sec DHCP will fail
730 * skb_trim(skb, skb->len - 4);
733 _rtl_receive_one(hw
, skb
, rx_status
);
735 if (((rtlpriv
->link_info
.num_rx_inperiod
+
736 rtlpriv
->link_info
.num_tx_inperiod
) > 8) ||
737 (rtlpriv
->link_info
.num_rx_inperiod
> 2)) {
738 tasklet_schedule(&rtlpriv
->works
.ips_leave_tasklet
);
741 dev_kfree_skb_any(skb
);
744 rtlpci
->rx_ring
[rx_queue_idx
].rx_buf
[index
] = skb
;
745 *((dma_addr_t
*) skb
->cb
) =
746 pci_map_single(rtlpci
->pdev
, skb_tail_pointer(skb
),
747 rtlpci
->rxbuffersize
,
751 bufferaddress
= (*((dma_addr_t
*)skb
->cb
));
753 rtlpriv
->cfg
->ops
->set_desc((u8
*) pdesc
, false,
755 (u8
*)&bufferaddress
);
756 rtlpriv
->cfg
->ops
->set_desc((u8
*)pdesc
, false,
758 (u8
*)&rtlpci
->rxbuffersize
);
760 if (index
== rtlpci
->rxringcount
- 1)
761 rtlpriv
->cfg
->ops
->set_desc((u8
*)pdesc
, false,
765 rtlpriv
->cfg
->ops
->set_desc((u8
*)pdesc
, false, HW_DESC_RXOWN
,
768 index
= (index
+ 1) % rtlpci
->rxringcount
;
771 rtlpci
->rx_ring
[rx_queue_idx
].idx
= index
;
774 static irqreturn_t
_rtl_pci_interrupt(int irq
, void *dev_id
)
776 struct ieee80211_hw
*hw
= dev_id
;
777 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
778 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
783 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
785 /*read ISR: 4/8bytes */
786 rtlpriv
->cfg
->ops
->interrupt_recognized(hw
, &inta
, &intb
);
788 /*Shared IRQ or HW disappared */
789 if (!inta
|| inta
== 0xffff)
792 /*<1> beacon related */
793 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_TBDOK
]) {
794 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
795 ("beacon ok interrupt!\n"));
798 if (unlikely(inta
& rtlpriv
->cfg
->maps
[RTL_IMR_TBDER
])) {
799 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
800 ("beacon err interrupt!\n"));
803 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_BDOK
]) {
804 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
805 ("beacon interrupt!\n"));
808 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_BcnInt
]) {
809 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
810 ("prepare beacon for interrupt!\n"));
811 tasklet_schedule(&rtlpriv
->works
.irq_prepare_bcn_tasklet
);
815 if (unlikely(inta
& rtlpriv
->cfg
->maps
[RTL_IMR_TXFOVW
]))
816 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
, ("IMR_TXFOVW!\n"));
818 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_MGNTDOK
]) {
819 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
820 ("Manage ok interrupt!\n"));
821 _rtl_pci_tx_isr(hw
, MGNT_QUEUE
);
824 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_HIGHDOK
]) {
825 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
826 ("HIGH_QUEUE ok interrupt!\n"));
827 _rtl_pci_tx_isr(hw
, HIGH_QUEUE
);
830 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_BKDOK
]) {
831 rtlpriv
->link_info
.num_tx_inperiod
++;
833 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
834 ("BK Tx OK interrupt!\n"));
835 _rtl_pci_tx_isr(hw
, BK_QUEUE
);
838 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_BEDOK
]) {
839 rtlpriv
->link_info
.num_tx_inperiod
++;
841 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
842 ("BE TX OK interrupt!\n"));
843 _rtl_pci_tx_isr(hw
, BE_QUEUE
);
846 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_VIDOK
]) {
847 rtlpriv
->link_info
.num_tx_inperiod
++;
849 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
850 ("VI TX OK interrupt!\n"));
851 _rtl_pci_tx_isr(hw
, VI_QUEUE
);
854 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_VODOK
]) {
855 rtlpriv
->link_info
.num_tx_inperiod
++;
857 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
858 ("Vo TX OK interrupt!\n"));
859 _rtl_pci_tx_isr(hw
, VO_QUEUE
);
862 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
) {
863 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_COMDOK
]) {
864 rtlpriv
->link_info
.num_tx_inperiod
++;
866 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
,
867 ("CMD TX OK interrupt!\n"));
868 _rtl_pci_tx_isr(hw
, TXCMD_QUEUE
);
873 if (inta
& rtlpriv
->cfg
->maps
[RTL_IMR_ROK
]) {
874 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_TRACE
, ("Rx ok interrupt!\n"));
875 _rtl_pci_rx_interrupt(hw
);
878 if (unlikely(inta
& rtlpriv
->cfg
->maps
[RTL_IMR_RDU
])) {
879 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
880 ("rx descriptor unavailable!\n"));
881 _rtl_pci_rx_interrupt(hw
);
884 if (unlikely(inta
& rtlpriv
->cfg
->maps
[RTL_IMR_RXFOVW
])) {
885 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
, ("rx overflow !\n"));
886 _rtl_pci_rx_interrupt(hw
);
889 if (rtlpriv
->rtlhal
.earlymode_enable
)
890 tasklet_schedule(&rtlpriv
->works
.irq_tasklet
);
892 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
896 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
900 static void _rtl_pci_irq_tasklet(struct ieee80211_hw
*hw
)
902 _rtl_pci_tx_chk_waitq(hw
);
905 static void _rtl_pci_ips_leave_tasklet(struct ieee80211_hw
*hw
)
910 static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw
*hw
)
912 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
913 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
914 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
915 struct rtl8192_tx_ring
*ring
= NULL
;
916 struct ieee80211_hdr
*hdr
= NULL
;
917 struct ieee80211_tx_info
*info
= NULL
;
918 struct sk_buff
*pskb
= NULL
;
919 struct rtl_tx_desc
*pdesc
= NULL
;
920 struct rtl_tcb_desc tcb_desc
;
923 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
924 ring
= &rtlpci
->tx_ring
[BEACON_QUEUE
];
925 pskb
= __skb_dequeue(&ring
->queue
);
929 /*NB: the beacon data buffer must be 32-bit aligned. */
930 pskb
= ieee80211_beacon_get(hw
, mac
->vif
);
933 hdr
= rtl_get_hdr(pskb
);
934 info
= IEEE80211_SKB_CB(pskb
);
935 pdesc
= &ring
->desc
[0];
936 rtlpriv
->cfg
->ops
->fill_tx_desc(hw
, hdr
, (u8
*) pdesc
,
937 info
, pskb
, BEACON_QUEUE
, &tcb_desc
);
939 __skb_queue_tail(&ring
->queue
, pskb
);
941 rtlpriv
->cfg
->ops
->set_desc((u8
*) pdesc
, true, HW_DESC_OWN
,
947 static void _rtl_pci_init_trx_var(struct ieee80211_hw
*hw
)
949 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
952 for (i
= 0; i
< RTL_PCI_MAX_TX_QUEUE_COUNT
; i
++)
953 rtlpci
->txringcount
[i
] = RT_TXDESC_NUM
;
956 *we just alloc 2 desc for beacon queue,
957 *because we just need first desc in hw beacon.
959 rtlpci
->txringcount
[BEACON_QUEUE
] = 2;
962 *BE queue need more descriptor for performance
963 *consideration or, No more tx desc will happen,
964 *and may cause mac80211 mem leakage.
966 rtlpci
->txringcount
[BE_QUEUE
] = RT_TXDESC_NUM_BE_QUEUE
;
968 rtlpci
->rxbuffersize
= 9100; /*2048/1024; */
969 rtlpci
->rxringcount
= RTL_PCI_MAX_RX_COUNT
; /*64; */
972 static void _rtl_pci_init_struct(struct ieee80211_hw
*hw
,
973 struct pci_dev
*pdev
)
975 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
976 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
977 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
978 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
980 rtlpci
->up_first_time
= true;
981 rtlpci
->being_init_adapter
= false;
986 /*Tx/Rx related var */
987 _rtl_pci_init_trx_var(hw
);
989 /*IBSS*/ mac
->beacon_interval
= 100;
992 mac
->min_space_cfg
= 0;
993 mac
->max_mss_density
= 0;
994 /*set sane AMPDU defaults */
995 mac
->current_ampdu_density
= 7;
996 mac
->current_ampdu_factor
= 3;
999 rtlpci
->acm_method
= eAcmWay2_SW
;
1002 tasklet_init(&rtlpriv
->works
.irq_tasklet
,
1003 (void (*)(unsigned long))_rtl_pci_irq_tasklet
,
1005 tasklet_init(&rtlpriv
->works
.irq_prepare_bcn_tasklet
,
1006 (void (*)(unsigned long))_rtl_pci_prepare_bcn_tasklet
,
1008 tasklet_init(&rtlpriv
->works
.ips_leave_tasklet
,
1009 (void (*)(unsigned long))_rtl_pci_ips_leave_tasklet
,
1013 static int _rtl_pci_init_tx_ring(struct ieee80211_hw
*hw
,
1014 unsigned int prio
, unsigned int entries
)
1016 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1017 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1018 struct rtl_tx_desc
*ring
;
1020 u32 nextdescaddress
;
1023 ring
= pci_alloc_consistent(rtlpci
->pdev
,
1024 sizeof(*ring
) * entries
, &dma
);
1026 if (!ring
|| (unsigned long)ring
& 0xFF) {
1027 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1028 ("Cannot allocate TX ring (prio = %d)\n", prio
));
1032 memset(ring
, 0, sizeof(*ring
) * entries
);
1033 rtlpci
->tx_ring
[prio
].desc
= ring
;
1034 rtlpci
->tx_ring
[prio
].dma
= dma
;
1035 rtlpci
->tx_ring
[prio
].idx
= 0;
1036 rtlpci
->tx_ring
[prio
].entries
= entries
;
1037 skb_queue_head_init(&rtlpci
->tx_ring
[prio
].queue
);
1039 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1040 ("queue:%d, ring_addr:%p\n", prio
, ring
));
1042 for (i
= 0; i
< entries
; i
++) {
1043 nextdescaddress
= (u32
) dma
+
1044 ((i
+ 1) % entries
) *
1047 rtlpriv
->cfg
->ops
->set_desc((u8
*)&(ring
[i
]),
1048 true, HW_DESC_TX_NEXTDESC_ADDR
,
1049 (u8
*)&nextdescaddress
);
1055 static int _rtl_pci_init_rx_ring(struct ieee80211_hw
*hw
)
1057 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1058 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1059 struct rtl_rx_desc
*entry
= NULL
;
1060 int i
, rx_queue_idx
;
1064 *rx_queue_idx 0:RX_MPDU_QUEUE
1065 *rx_queue_idx 1:RX_CMD_QUEUE
1067 for (rx_queue_idx
= 0; rx_queue_idx
< RTL_PCI_MAX_RX_QUEUE
;
1069 rtlpci
->rx_ring
[rx_queue_idx
].desc
=
1070 pci_alloc_consistent(rtlpci
->pdev
,
1071 sizeof(*rtlpci
->rx_ring
[rx_queue_idx
].
1072 desc
) * rtlpci
->rxringcount
,
1073 &rtlpci
->rx_ring
[rx_queue_idx
].dma
);
1075 if (!rtlpci
->rx_ring
[rx_queue_idx
].desc
||
1076 (unsigned long)rtlpci
->rx_ring
[rx_queue_idx
].desc
& 0xFF) {
1077 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1078 ("Cannot allocate RX ring\n"));
1082 memset(rtlpci
->rx_ring
[rx_queue_idx
].desc
, 0,
1083 sizeof(*rtlpci
->rx_ring
[rx_queue_idx
].desc
) *
1084 rtlpci
->rxringcount
);
1086 rtlpci
->rx_ring
[rx_queue_idx
].idx
= 0;
1088 /* If amsdu_8k is disabled, set buffersize to 4096. This
1089 * change will reduce memory fragmentation.
1091 if (rtlpci
->rxbuffersize
> 4096 &&
1092 rtlpriv
->rtlhal
.disable_amsdu_8k
)
1093 rtlpci
->rxbuffersize
= 4096;
1095 for (i
= 0; i
< rtlpci
->rxringcount
; i
++) {
1096 struct sk_buff
*skb
=
1097 dev_alloc_skb(rtlpci
->rxbuffersize
);
1101 entry
= &rtlpci
->rx_ring
[rx_queue_idx
].desc
[i
];
1103 /*skb->dev = dev; */
1105 rtlpci
->rx_ring
[rx_queue_idx
].rx_buf
[i
] = skb
;
1108 *just set skb->cb to mapping addr
1109 *for pci_unmap_single use
1111 *((dma_addr_t
*) skb
->cb
) =
1112 pci_map_single(rtlpci
->pdev
, skb_tail_pointer(skb
),
1113 rtlpci
->rxbuffersize
,
1114 PCI_DMA_FROMDEVICE
);
1116 bufferaddress
= (*((dma_addr_t
*)skb
->cb
));
1117 rtlpriv
->cfg
->ops
->set_desc((u8
*)entry
, false,
1118 HW_DESC_RXBUFF_ADDR
,
1119 (u8
*)&bufferaddress
);
1120 rtlpriv
->cfg
->ops
->set_desc((u8
*)entry
, false,
1124 rtlpriv
->cfg
->ops
->set_desc((u8
*) entry
, false,
1129 rtlpriv
->cfg
->ops
->set_desc((u8
*) entry
, false,
1130 HW_DESC_RXERO
, (u8
*)&tmp_one
);
1135 static void _rtl_pci_free_tx_ring(struct ieee80211_hw
*hw
,
1138 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1139 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1140 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[prio
];
1142 while (skb_queue_len(&ring
->queue
)) {
1143 struct rtl_tx_desc
*entry
= &ring
->desc
[ring
->idx
];
1144 struct sk_buff
*skb
= __skb_dequeue(&ring
->queue
);
1146 pci_unmap_single(rtlpci
->pdev
,
1148 ops
->get_desc((u8
*) entry
, true,
1149 HW_DESC_TXBUFF_ADDR
),
1150 skb
->len
, PCI_DMA_TODEVICE
);
1152 ring
->idx
= (ring
->idx
+ 1) % ring
->entries
;
1155 pci_free_consistent(rtlpci
->pdev
,
1156 sizeof(*ring
->desc
) * ring
->entries
,
1157 ring
->desc
, ring
->dma
);
1161 static void _rtl_pci_free_rx_ring(struct rtl_pci
*rtlpci
)
1163 int i
, rx_queue_idx
;
1165 /*rx_queue_idx 0:RX_MPDU_QUEUE */
1166 /*rx_queue_idx 1:RX_CMD_QUEUE */
1167 for (rx_queue_idx
= 0; rx_queue_idx
< RTL_PCI_MAX_RX_QUEUE
;
1169 for (i
= 0; i
< rtlpci
->rxringcount
; i
++) {
1170 struct sk_buff
*skb
=
1171 rtlpci
->rx_ring
[rx_queue_idx
].rx_buf
[i
];
1175 pci_unmap_single(rtlpci
->pdev
,
1176 *((dma_addr_t
*) skb
->cb
),
1177 rtlpci
->rxbuffersize
,
1178 PCI_DMA_FROMDEVICE
);
1182 pci_free_consistent(rtlpci
->pdev
,
1183 sizeof(*rtlpci
->rx_ring
[rx_queue_idx
].
1184 desc
) * rtlpci
->rxringcount
,
1185 rtlpci
->rx_ring
[rx_queue_idx
].desc
,
1186 rtlpci
->rx_ring
[rx_queue_idx
].dma
);
1187 rtlpci
->rx_ring
[rx_queue_idx
].desc
= NULL
;
1191 static int _rtl_pci_init_trx_ring(struct ieee80211_hw
*hw
)
1193 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1197 ret
= _rtl_pci_init_rx_ring(hw
);
1201 for (i
= 0; i
< RTL_PCI_MAX_TX_QUEUE_COUNT
; i
++) {
1202 ret
= _rtl_pci_init_tx_ring(hw
, i
,
1203 rtlpci
->txringcount
[i
]);
1205 goto err_free_rings
;
1211 _rtl_pci_free_rx_ring(rtlpci
);
1213 for (i
= 0; i
< RTL_PCI_MAX_TX_QUEUE_COUNT
; i
++)
1214 if (rtlpci
->tx_ring
[i
].desc
)
1215 _rtl_pci_free_tx_ring(hw
, i
);
1220 static int _rtl_pci_deinit_trx_ring(struct ieee80211_hw
*hw
)
1222 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1226 _rtl_pci_free_rx_ring(rtlpci
);
1229 for (i
= 0; i
< RTL_PCI_MAX_TX_QUEUE_COUNT
; i
++)
1230 _rtl_pci_free_tx_ring(hw
, i
);
1235 int rtl_pci_reset_trx_ring(struct ieee80211_hw
*hw
)
1237 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1238 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1239 int i
, rx_queue_idx
;
1240 unsigned long flags
;
1243 /*rx_queue_idx 0:RX_MPDU_QUEUE */
1244 /*rx_queue_idx 1:RX_CMD_QUEUE */
1245 for (rx_queue_idx
= 0; rx_queue_idx
< RTL_PCI_MAX_RX_QUEUE
;
1248 *force the rx_ring[RX_MPDU_QUEUE/
1249 *RX_CMD_QUEUE].idx to the first one
1251 if (rtlpci
->rx_ring
[rx_queue_idx
].desc
) {
1252 struct rtl_rx_desc
*entry
= NULL
;
1254 for (i
= 0; i
< rtlpci
->rxringcount
; i
++) {
1255 entry
= &rtlpci
->rx_ring
[rx_queue_idx
].desc
[i
];
1256 rtlpriv
->cfg
->ops
->set_desc((u8
*) entry
,
1261 rtlpci
->rx_ring
[rx_queue_idx
].idx
= 0;
1266 *after reset, release previous pending packet,
1267 *and force the tx idx to the first one
1269 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
1270 for (i
= 0; i
< RTL_PCI_MAX_TX_QUEUE_COUNT
; i
++) {
1271 if (rtlpci
->tx_ring
[i
].desc
) {
1272 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[i
];
1274 while (skb_queue_len(&ring
->queue
)) {
1275 struct rtl_tx_desc
*entry
=
1276 &ring
->desc
[ring
->idx
];
1277 struct sk_buff
*skb
=
1278 __skb_dequeue(&ring
->queue
);
1280 pci_unmap_single(rtlpci
->pdev
,
1285 HW_DESC_TXBUFF_ADDR
),
1286 skb
->len
, PCI_DMA_TODEVICE
);
1288 ring
->idx
= (ring
->idx
+ 1) % ring
->entries
;
1294 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
1299 static bool rtl_pci_tx_chk_waitq_insert(struct ieee80211_hw
*hw
,
1300 struct sk_buff
*skb
)
1302 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1303 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1304 struct ieee80211_sta
*sta
= info
->control
.sta
;
1305 struct rtl_sta_info
*sta_entry
= NULL
;
1306 u8 tid
= rtl_get_tid(skb
);
1310 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1312 if (!rtlpriv
->rtlhal
.earlymode_enable
)
1314 if (sta_entry
->tids
[tid
].agg
.agg_state
!= RTL_AGG_OPERATIONAL
)
1316 if (_rtl_mac_to_hwqueue(hw
, skb
) > VO_QUEUE
)
1321 /* maybe every tid should be checked */
1322 if (!rtlpriv
->link_info
.higher_busytxtraffic
[tid
])
1325 spin_lock_bh(&rtlpriv
->locks
.waitq_lock
);
1326 skb_queue_tail(&rtlpriv
->mac80211
.skb_waitq
[tid
], skb
);
1327 spin_unlock_bh(&rtlpriv
->locks
.waitq_lock
);
1332 static int rtl_pci_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1333 struct rtl_tcb_desc
*ptcb_desc
)
1335 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1336 struct rtl_sta_info
*sta_entry
= NULL
;
1337 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1338 struct ieee80211_sta
*sta
= info
->control
.sta
;
1339 struct rtl8192_tx_ring
*ring
;
1340 struct rtl_tx_desc
*pdesc
;
1342 u8 hw_queue
= _rtl_mac_to_hwqueue(hw
, skb
);
1343 unsigned long flags
;
1344 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
1345 __le16 fc
= rtl_get_fc(skb
);
1346 u8
*pda_addr
= hdr
->addr1
;
1347 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1354 if (ieee80211_is_auth(fc
)) {
1355 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
, ("MAC80211_LINKING\n"));
1359 if (rtlpriv
->psc
.sw_ps_enabled
) {
1360 if (ieee80211_is_data(fc
) && !ieee80211_is_nullfunc(fc
) &&
1361 !ieee80211_has_pm(fc
))
1362 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
1365 rtl_action_proc(hw
, skb
, true);
1367 if (is_multicast_ether_addr(pda_addr
))
1368 rtlpriv
->stats
.txbytesmulticast
+= skb
->len
;
1369 else if (is_broadcast_ether_addr(pda_addr
))
1370 rtlpriv
->stats
.txbytesbroadcast
+= skb
->len
;
1372 rtlpriv
->stats
.txbytesunicast
+= skb
->len
;
1374 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
1375 ring
= &rtlpci
->tx_ring
[hw_queue
];
1376 if (hw_queue
!= BEACON_QUEUE
)
1377 idx
= (ring
->idx
+ skb_queue_len(&ring
->queue
)) %
1382 pdesc
= &ring
->desc
[idx
];
1383 own
= (u8
) rtlpriv
->cfg
->ops
->get_desc((u8
*) pdesc
,
1386 if ((own
== 1) && (hw_queue
!= BEACON_QUEUE
)) {
1387 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1388 ("No more TX desc@%d, ring->idx = %d,"
1389 "idx = %d, skb_queue_len = 0x%d\n",
1390 hw_queue
, ring
->idx
, idx
,
1391 skb_queue_len(&ring
->queue
)));
1393 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
1397 if (ieee80211_is_data_qos(fc
)) {
1398 tid
= rtl_get_tid(skb
);
1400 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1401 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) &
1402 IEEE80211_SCTL_SEQ
) >> 4;
1405 if (!ieee80211_has_morefrags(hdr
->frame_control
))
1406 sta_entry
->tids
[tid
].seq_number
= seq_number
;
1410 if (ieee80211_is_data(fc
))
1411 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_TX
);
1413 rtlpriv
->cfg
->ops
->fill_tx_desc(hw
, hdr
, (u8
*)pdesc
,
1414 info
, skb
, hw_queue
, ptcb_desc
);
1416 __skb_queue_tail(&ring
->queue
, skb
);
1418 rtlpriv
->cfg
->ops
->set_desc((u8
*)pdesc
, true,
1419 HW_DESC_OWN
, (u8
*)&temp_one
);
1422 if ((ring
->entries
- skb_queue_len(&ring
->queue
)) < 2 &&
1423 hw_queue
!= BEACON_QUEUE
) {
1425 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
1426 ("less desc left, stop skb_queue@%d, "
1428 "idx = %d, skb_queue_len = 0x%d\n",
1429 hw_queue
, ring
->idx
, idx
,
1430 skb_queue_len(&ring
->queue
)));
1432 ieee80211_stop_queue(hw
, skb_get_queue_mapping(skb
));
1435 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
1437 rtlpriv
->cfg
->ops
->tx_polling(hw
, hw_queue
);
1442 static void rtl_pci_flush(struct ieee80211_hw
*hw
, bool drop
)
1444 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1445 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
1446 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1449 struct rtl8192_tx_ring
*ring
;
1451 for (queue_id
= RTL_PCI_MAX_TX_QUEUE_COUNT
- 1; queue_id
>= 0;) {
1453 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
1454 queue_len
= skb_queue_len(&ring
->queue
);
1455 if (queue_len
== 0 || queue_id
== BEACON_QUEUE
||
1456 queue_id
== TXCMD_QUEUE
) {
1464 /* we just wait 1s for all queues */
1465 if (rtlpriv
->psc
.rfpwr_state
== ERFOFF
||
1466 is_hal_stop(rtlhal
) || i
>= 200)
1471 static void rtl_pci_deinit(struct ieee80211_hw
*hw
)
1473 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1474 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1476 _rtl_pci_deinit_trx_ring(hw
);
1478 synchronize_irq(rtlpci
->pdev
->irq
);
1479 tasklet_kill(&rtlpriv
->works
.irq_tasklet
);
1480 tasklet_kill(&rtlpriv
->works
.ips_leave_tasklet
);
1482 flush_workqueue(rtlpriv
->works
.rtl_wq
);
1483 destroy_workqueue(rtlpriv
->works
.rtl_wq
);
1487 static int rtl_pci_init(struct ieee80211_hw
*hw
, struct pci_dev
*pdev
)
1489 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1492 _rtl_pci_init_struct(hw
, pdev
);
1494 err
= _rtl_pci_init_trx_ring(hw
);
1496 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1497 ("tx ring initialization failed"));
1504 static int rtl_pci_start(struct ieee80211_hw
*hw
)
1506 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1507 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1508 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1509 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1513 rtl_pci_reset_trx_ring(hw
);
1515 rtlpci
->driver_is_goingto_unload
= false;
1516 err
= rtlpriv
->cfg
->ops
->hw_init(hw
);
1518 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1519 ("Failed to config hardware!\n"));
1523 rtlpriv
->cfg
->ops
->enable_interrupt(hw
);
1524 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, ("enable_interrupt OK\n"));
1526 rtl_init_rx_config(hw
);
1528 /*should after adapter start and interrupt enable. */
1529 set_hal_start(rtlhal
);
1531 RT_CLEAR_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1533 rtlpci
->up_first_time
= false;
1535 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, ("OK\n"));
1539 static void rtl_pci_stop(struct ieee80211_hw
*hw
)
1541 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1542 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1543 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1544 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1545 unsigned long flags
;
1546 u8 RFInProgressTimeOut
= 0;
1549 *should before disable interrrupt&adapter
1550 *and will do it immediately.
1552 set_hal_stop(rtlhal
);
1554 rtlpriv
->cfg
->ops
->disable_interrupt(hw
);
1555 tasklet_kill(&rtlpriv
->works
.ips_leave_tasklet
);
1557 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flags
);
1558 while (ppsc
->rfchange_inprogress
) {
1559 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flags
);
1560 if (RFInProgressTimeOut
> 100) {
1561 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flags
);
1565 RFInProgressTimeOut
++;
1566 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flags
);
1568 ppsc
->rfchange_inprogress
= true;
1569 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flags
);
1571 rtlpci
->driver_is_goingto_unload
= true;
1572 rtlpriv
->cfg
->ops
->hw_disable(hw
);
1573 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1575 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flags
);
1576 ppsc
->rfchange_inprogress
= false;
1577 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flags
);
1579 rtl_pci_enable_aspm(hw
);
1582 static bool _rtl_pci_find_adapter(struct pci_dev
*pdev
,
1583 struct ieee80211_hw
*hw
)
1585 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1586 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
1587 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1588 struct pci_dev
*bridge_pdev
= pdev
->bus
->self
;
1595 pcipriv
->ndis_adapter
.pcibridge_vendor
= PCI_BRIDGE_VENDOR_UNKNOWN
;
1596 venderid
= pdev
->vendor
;
1597 deviceid
= pdev
->device
;
1598 pci_read_config_byte(pdev
, 0x8, &revisionid
);
1599 pci_read_config_word(pdev
, 0x3C, &irqline
);
1601 /* PCI ID 0x10ec:0x8192 occurs for both RTL8192E, which uses
1602 * r8192e_pci, and RTL8192SE, which uses this driver. If the
1603 * revision ID is RTL_PCI_REVISION_ID_8192PCIE (0x01), then
1604 * the correct driver is r8192e_pci, thus this routine should
1607 if (deviceid
== RTL_PCI_8192SE_DID
&&
1608 revisionid
== RTL_PCI_REVISION_ID_8192PCIE
)
1611 if (deviceid
== RTL_PCI_8192_DID
||
1612 deviceid
== RTL_PCI_0044_DID
||
1613 deviceid
== RTL_PCI_0047_DID
||
1614 deviceid
== RTL_PCI_8192SE_DID
||
1615 deviceid
== RTL_PCI_8174_DID
||
1616 deviceid
== RTL_PCI_8173_DID
||
1617 deviceid
== RTL_PCI_8172_DID
||
1618 deviceid
== RTL_PCI_8171_DID
) {
1619 switch (revisionid
) {
1620 case RTL_PCI_REVISION_ID_8192PCIE
:
1621 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1622 ("8192 PCI-E is found - "
1623 "vid/did=%x/%x\n", venderid
, deviceid
));
1624 rtlhal
->hw_type
= HARDWARE_TYPE_RTL8192E
;
1626 case RTL_PCI_REVISION_ID_8192SE
:
1627 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1628 ("8192SE is found - "
1629 "vid/did=%x/%x\n", venderid
, deviceid
));
1630 rtlhal
->hw_type
= HARDWARE_TYPE_RTL8192SE
;
1633 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1634 ("Err: Unknown device - "
1635 "vid/did=%x/%x\n", venderid
, deviceid
));
1636 rtlhal
->hw_type
= HARDWARE_TYPE_RTL8192SE
;
1640 } else if (deviceid
== RTL_PCI_8192CET_DID
||
1641 deviceid
== RTL_PCI_8192CE_DID
||
1642 deviceid
== RTL_PCI_8191CE_DID
||
1643 deviceid
== RTL_PCI_8188CE_DID
) {
1644 rtlhal
->hw_type
= HARDWARE_TYPE_RTL8192CE
;
1645 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1646 ("8192C PCI-E is found - "
1647 "vid/did=%x/%x\n", venderid
, deviceid
));
1648 } else if (deviceid
== RTL_PCI_8192DE_DID
||
1649 deviceid
== RTL_PCI_8192DE_DID2
) {
1650 rtlhal
->hw_type
= HARDWARE_TYPE_RTL8192DE
;
1651 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1652 ("8192D PCI-E is found - "
1653 "vid/did=%x/%x\n", venderid
, deviceid
));
1655 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1656 ("Err: Unknown device -"
1657 " vid/did=%x/%x\n", venderid
, deviceid
));
1659 rtlhal
->hw_type
= RTL_DEFAULT_HARDWARE_TYPE
;
1662 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192DE
) {
1663 if (revisionid
== 0 || revisionid
== 1) {
1664 if (revisionid
== 0) {
1665 RT_TRACE(rtlpriv
, COMP_INIT
,
1666 DBG_LOUD
, ("Find 92DE MAC0.\n"));
1667 rtlhal
->interfaceindex
= 0;
1668 } else if (revisionid
== 1) {
1669 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1670 ("Find 92DE MAC1.\n"));
1671 rtlhal
->interfaceindex
= 1;
1674 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1675 ("Unknown device - "
1676 "VendorID/DeviceID=%x/%x, Revision=%x\n",
1677 venderid
, deviceid
, revisionid
));
1678 rtlhal
->interfaceindex
= 0;
1682 pcipriv
->ndis_adapter
.busnumber
= pdev
->bus
->number
;
1683 pcipriv
->ndis_adapter
.devnumber
= PCI_SLOT(pdev
->devfn
);
1684 pcipriv
->ndis_adapter
.funcnumber
= PCI_FUNC(pdev
->devfn
);
1687 /*find bridge info if available */
1688 pcipriv
->ndis_adapter
.pcibridge_vendorid
= bridge_pdev
->vendor
;
1689 for (tmp
= 0; tmp
< PCI_BRIDGE_VENDOR_MAX
; tmp
++) {
1690 if (bridge_pdev
->vendor
== pcibridge_vendors
[tmp
]) {
1691 pcipriv
->ndis_adapter
.pcibridge_vendor
= tmp
;
1692 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1693 ("Pci Bridge Vendor is found index:"
1700 if (pcipriv
->ndis_adapter
.pcibridge_vendor
!=
1701 PCI_BRIDGE_VENDOR_UNKNOWN
) {
1702 pcipriv
->ndis_adapter
.pcibridge_busnum
=
1703 bridge_pdev
->bus
->number
;
1704 pcipriv
->ndis_adapter
.pcibridge_devnum
=
1705 PCI_SLOT(bridge_pdev
->devfn
);
1706 pcipriv
->ndis_adapter
.pcibridge_funcnum
=
1707 PCI_FUNC(bridge_pdev
->devfn
);
1708 pcipriv
->ndis_adapter
.pcibridge_pciehdr_offset
=
1709 pci_pcie_cap(bridge_pdev
);
1710 pcipriv
->ndis_adapter
.num4bytes
=
1711 (pcipriv
->ndis_adapter
.pcibridge_pciehdr_offset
+ 0x10) / 4;
1713 rtl_pci_get_linkcontrol_field(hw
);
1715 if (pcipriv
->ndis_adapter
.pcibridge_vendor
==
1716 PCI_BRIDGE_VENDOR_AMD
) {
1717 pcipriv
->ndis_adapter
.amd_l1_patch
=
1718 rtl_pci_get_amd_l1_patch(hw
);
1722 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1723 ("pcidev busnumber:devnumber:funcnumber:"
1724 "vendor:link_ctl %d:%d:%d:%x:%x\n",
1725 pcipriv
->ndis_adapter
.busnumber
,
1726 pcipriv
->ndis_adapter
.devnumber
,
1727 pcipriv
->ndis_adapter
.funcnumber
,
1728 pdev
->vendor
, pcipriv
->ndis_adapter
.linkctrl_reg
));
1730 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1731 ("pci_bridge busnumber:devnumber:funcnumber:vendor:"
1732 "pcie_cap:link_ctl_reg:amd %d:%d:%d:%x:%x:%x:%x\n",
1733 pcipriv
->ndis_adapter
.pcibridge_busnum
,
1734 pcipriv
->ndis_adapter
.pcibridge_devnum
,
1735 pcipriv
->ndis_adapter
.pcibridge_funcnum
,
1736 pcibridge_vendors
[pcipriv
->ndis_adapter
.pcibridge_vendor
],
1737 pcipriv
->ndis_adapter
.pcibridge_pciehdr_offset
,
1738 pcipriv
->ndis_adapter
.pcibridge_linkctrlreg
,
1739 pcipriv
->ndis_adapter
.amd_l1_patch
));
1741 rtl_pci_parse_configuration(pdev
, hw
);
1746 int __devinit
rtl_pci_probe(struct pci_dev
*pdev
,
1747 const struct pci_device_id
*id
)
1749 struct ieee80211_hw
*hw
= NULL
;
1751 struct rtl_priv
*rtlpriv
= NULL
;
1752 struct rtl_pci_priv
*pcipriv
= NULL
;
1753 struct rtl_pci
*rtlpci
;
1754 unsigned long pmem_start
, pmem_len
, pmem_flags
;
1757 err
= pci_enable_device(pdev
);
1760 ("%s : Cannot enable new PCI device\n",
1765 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1766 if (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1767 RT_ASSERT(false, ("Unable to obtain 32bit DMA "
1768 "for consistent allocations\n"));
1769 pci_disable_device(pdev
);
1774 pci_set_master(pdev
);
1776 hw
= ieee80211_alloc_hw(sizeof(struct rtl_pci_priv
) +
1777 sizeof(struct rtl_priv
), &rtl_ops
);
1780 ("%s : ieee80211 alloc failed\n", pci_name(pdev
)));
1785 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
1786 pci_set_drvdata(pdev
, hw
);
1789 pcipriv
= (void *)rtlpriv
->priv
;
1790 pcipriv
->dev
.pdev
= pdev
;
1792 /* init cfg & intf_ops */
1793 rtlpriv
->rtlhal
.interface
= INTF_PCI
;
1794 rtlpriv
->cfg
= (struct rtl_hal_cfg
*)(id
->driver_data
);
1795 rtlpriv
->intf_ops
= &rtl_pci_ops
;
1798 *init dbgp flags before all
1799 *other functions, because we will
1800 *use it in other funtions like
1801 *RT_TRACE/RT_PRINT/RTL_PRINT_DATA
1802 *you can not use these macro
1805 rtl_dbgp_flag_init(hw
);
1808 err
= pci_request_regions(pdev
, KBUILD_MODNAME
);
1810 RT_ASSERT(false, ("Can't obtain PCI resources\n"));
1814 pmem_start
= pci_resource_start(pdev
, rtlpriv
->cfg
->bar_id
);
1815 pmem_len
= pci_resource_len(pdev
, rtlpriv
->cfg
->bar_id
);
1816 pmem_flags
= pci_resource_flags(pdev
, rtlpriv
->cfg
->bar_id
);
1818 /*shared mem start */
1819 rtlpriv
->io
.pci_mem_start
=
1820 (unsigned long)pci_iomap(pdev
,
1821 rtlpriv
->cfg
->bar_id
, pmem_len
);
1822 if (rtlpriv
->io
.pci_mem_start
== 0) {
1823 RT_ASSERT(false, ("Can't map PCI mem\n"));
1827 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1828 ("mem mapped space: start: 0x%08lx len:%08lx "
1829 "flags:%08lx, after map:0x%08lx\n",
1830 pmem_start
, pmem_len
, pmem_flags
,
1831 rtlpriv
->io
.pci_mem_start
));
1833 /* Disable Clk Request */
1834 pci_write_config_byte(pdev
, 0x81, 0);
1836 pci_write_config_byte(pdev
, 0x44, 0);
1837 pci_write_config_byte(pdev
, 0x04, 0x06);
1838 pci_write_config_byte(pdev
, 0x04, 0x07);
1841 if (!_rtl_pci_find_adapter(pdev
, hw
))
1844 /* Init IO handler */
1845 _rtl_pci_io_handler_init(&pdev
->dev
, hw
);
1847 /*like read eeprom and so on */
1848 rtlpriv
->cfg
->ops
->read_eeprom_info(hw
);
1850 if (rtlpriv
->cfg
->ops
->init_sw_vars(hw
)) {
1851 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1852 ("Can't init_sw_vars.\n"));
1856 rtlpriv
->cfg
->ops
->init_sw_leds(hw
);
1859 rtl_pci_init_aspm(hw
);
1861 /* Init mac80211 sw */
1862 err
= rtl_init_core(hw
);
1864 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1865 ("Can't allocate sw for mac80211.\n"));
1870 err
= !rtl_pci_init(hw
, pdev
);
1872 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1873 ("Failed to init PCI.\n"));
1877 err
= ieee80211_register_hw(hw
);
1879 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1880 ("Can't register mac80211 hw.\n"));
1883 rtlpriv
->mac80211
.mac80211_registered
= 1;
1886 err
= sysfs_create_group(&pdev
->dev
.kobj
, &rtl_attribute_group
);
1888 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1889 ("failed to create sysfs device attributes\n"));
1894 rtl_init_rfkill(hw
);
1896 rtlpci
= rtl_pcidev(pcipriv
);
1897 err
= request_irq(rtlpci
->pdev
->irq
, &_rtl_pci_interrupt
,
1898 IRQF_SHARED
, KBUILD_MODNAME
, hw
);
1900 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1901 ("%s: failed to register IRQ handler\n",
1902 wiphy_name(hw
->wiphy
)));
1905 rtlpci
->irq_alloc
= 1;
1908 set_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
);
1912 pci_set_drvdata(pdev
, NULL
);
1913 rtl_deinit_core(hw
);
1914 _rtl_pci_io_handler_release(hw
);
1915 ieee80211_free_hw(hw
);
1917 if (rtlpriv
->io
.pci_mem_start
!= 0)
1918 pci_iounmap(pdev
, (void __iomem
*)rtlpriv
->io
.pci_mem_start
);
1921 pci_release_regions(pdev
);
1925 pci_disable_device(pdev
);
1930 EXPORT_SYMBOL(rtl_pci_probe
);
1932 void rtl_pci_disconnect(struct pci_dev
*pdev
)
1934 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1935 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
1936 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1937 struct rtl_pci
*rtlpci
= rtl_pcidev(pcipriv
);
1938 struct rtl_mac
*rtlmac
= rtl_mac(rtlpriv
);
1940 clear_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
);
1942 sysfs_remove_group(&pdev
->dev
.kobj
, &rtl_attribute_group
);
1944 /*ieee80211_unregister_hw will call ops_stop */
1945 if (rtlmac
->mac80211_registered
== 1) {
1946 ieee80211_unregister_hw(hw
);
1947 rtlmac
->mac80211_registered
= 0;
1949 rtl_deinit_deferred_work(hw
);
1950 rtlpriv
->intf_ops
->adapter_stop(hw
);
1954 rtl_deinit_rfkill(hw
);
1957 rtl_deinit_core(hw
);
1958 _rtl_pci_io_handler_release(hw
);
1959 rtlpriv
->cfg
->ops
->deinit_sw_vars(hw
);
1961 if (rtlpci
->irq_alloc
) {
1962 free_irq(rtlpci
->pdev
->irq
, hw
);
1963 rtlpci
->irq_alloc
= 0;
1966 if (rtlpriv
->io
.pci_mem_start
!= 0) {
1967 pci_iounmap(pdev
, (void __iomem
*)rtlpriv
->io
.pci_mem_start
);
1968 pci_release_regions(pdev
);
1971 pci_disable_device(pdev
);
1973 rtl_pci_disable_aspm(hw
);
1975 pci_set_drvdata(pdev
, NULL
);
1977 ieee80211_free_hw(hw
);
1979 EXPORT_SYMBOL(rtl_pci_disconnect
);
1981 /***************************************
1982 kernel pci power state define:
1983 PCI_D0 ((pci_power_t __force) 0)
1984 PCI_D1 ((pci_power_t __force) 1)
1985 PCI_D2 ((pci_power_t __force) 2)
1986 PCI_D3hot ((pci_power_t __force) 3)
1987 PCI_D3cold ((pci_power_t __force) 4)
1988 PCI_UNKNOWN ((pci_power_t __force) 5)
1990 This function is called when system
1991 goes into suspend state mac80211 will
1992 call rtl_mac_stop() from the mac80211
1993 suspend function first, So there is
1994 no need to call hw_disable here.
1995 ****************************************/
1996 int rtl_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1998 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1999 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2001 rtlpriv
->cfg
->ops
->hw_suspend(hw
);
2002 rtl_deinit_rfkill(hw
);
2004 pci_save_state(pdev
);
2005 pci_disable_device(pdev
);
2006 pci_set_power_state(pdev
, PCI_D3hot
);
2009 EXPORT_SYMBOL(rtl_pci_suspend
);
2011 int rtl_pci_resume(struct pci_dev
*pdev
)
2014 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
2015 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2017 pci_set_power_state(pdev
, PCI_D0
);
2018 ret
= pci_enable_device(pdev
);
2020 RT_ASSERT(false, ("ERR: <======\n"));
2024 pci_restore_state(pdev
);
2026 rtlpriv
->cfg
->ops
->hw_resume(hw
);
2027 rtl_init_rfkill(hw
);
2030 EXPORT_SYMBOL(rtl_pci_resume
);
2032 struct rtl_intf_ops rtl_pci_ops
= {
2033 .read_efuse_byte
= read_efuse_byte
,
2034 .adapter_start
= rtl_pci_start
,
2035 .adapter_stop
= rtl_pci_stop
,
2036 .adapter_tx
= rtl_pci_tx
,
2037 .flush
= rtl_pci_flush
,
2038 .reset_trx_ring
= rtl_pci_reset_trx_ring
,
2039 .waitq_insert
= rtl_pci_tx_chk_waitq_insert
,
2041 .disable_aspm
= rtl_pci_disable_aspm
,
2042 .enable_aspm
= rtl_pci_enable_aspm
,