1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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 ******************************************************************************/
19 #define C2H_MEM_SZ (16*1024)
21 #define FREE_CMDOBJ_SZ 128
23 #define MAX_CMDSZ 1024
25 #define MAX_EVTSZ 1024
27 #define CMDBUFF_ALIGN_SZ 512
30 struct adapter *padapter;
37 struct submit_ctx *sctx;
39 struct list_head list;
44 RTW_CMDF_DIRECTLY = BIT0,
45 RTW_CMDF_WAIT_ACK = BIT1,
50 /* _sema cmd_done_sema; */
51 _sema terminate_cmdthread_sema;
52 struct __queue cmd_queue;
54 u8 *cmd_buf; /* shall be non-paged, and 4 bytes aligned */
55 u8 *cmd_allocated_buf;
56 u8 *rsp_buf; /* shall be non-paged, and 4 bytes aligned */
57 u8 *rsp_allocated_buf;
61 atomic_t cmdthd_running;
62 /* u8 cmdthd_running; */
64 struct adapter *padapter;
71 struct rtw_cbuf *c2h_queue;
72 #define C2H_QUEUE_MAX_LEN 10
75 u8 *evt_buf; /* shall be non-paged, and 4 bytes aligned */
76 u8 *evt_allocated_buf;
79 u8 *allocated_c2h_mem;
82 #define init_h2fwcmd_w_parm_no_rsp(pcmd, pparm, code) \
84 INIT_LIST_HEAD(&pcmd->list);\
85 pcmd->cmdcode = code;\
86 pcmd->parmbuf = (u8 *)(pparm);\
87 pcmd->cmdsz = sizeof (*pparm);\
92 #define init_h2fwcmd_w_parm_no_parm_rsp(pcmd, code) \
94 INIT_LIST_HEAD(&pcmd->list);\
95 pcmd->cmdcode = code;\
96 pcmd->parmbuf = NULL;\
109 struct c2h_evt_hdr_88xx {
117 #define c2h_evt_valid(c2h_evt) ((c2h_evt)->id || (c2h_evt)->plen)
119 struct P2P_PS_Offload_t {
121 u8 role:1; /* 1: Owner, 0: Client */
125 u8 AllStaSleep:1; /* Only valid in Owner */
130 struct P2P_PS_CTWPeriod_t {
131 u8 CTWPeriod; /* TU */
134 extern u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj);
135 extern struct cmd_obj *rtw_dequeue_cmd(struct cmd_priv *pcmdpriv);
136 extern void rtw_free_cmd_obj(struct cmd_obj *pcmd);
138 void rtw_stop_cmd_thread(struct adapter *adapter);
139 int rtw_cmd_thread(void *context);
141 extern u32 rtw_init_cmd_priv (struct cmd_priv *pcmdpriv);
142 extern void rtw_free_cmd_priv (struct cmd_priv *pcmdpriv);
144 extern u32 rtw_init_evt_priv (struct evt_priv *pevtpriv);
145 extern void rtw_free_evt_priv (struct evt_priv *pevtpriv);
146 extern void rtw_evt_notify_isr(struct evt_priv *pevtpriv);
148 enum rtw_drvextra_cmd_id
154 POWER_SAVING_CTRL_WK_CID,/* IPS, AUTOSuspend */
159 CHECK_HIQ_WK_CID,/* for softap mode, check hi queue if empty */
162 RTP_TIMER_CFG_WK_CID,
163 RESET_SECURITYPRIV, /* add for CONFIG_IEEE80211W, none 11w also can use */
164 FREE_ASSOC_RESOURCES, /* add for CONFIG_IEEE80211W, none 11w also can use */
166 DM_RA_MSK_WK_CID, /* add for STA update RAMask when bandwith change. */
176 LPS_CTRL_JOINBSS = 1,
178 LPS_CTRL_DISCONNECT =3,
179 LPS_CTRL_SPECIAL_PACKET =4,
181 LPS_CTRL_TRAFFIC_BUSY = 6,
191 Caller Mode: Infra, Ad-HoC(C)
193 Notes: To enter USB suspend mode
198 struct usb_suspend_parm {
199 u32 action;/* 1: sleep, 0:resume */
203 Caller Mode: Infra, Ad-HoC
205 Notes: To join a known BSS.
212 Caller Mode: Infra, Ad-Hoc
214 Notes: To join the specified bss
219 struct joinbss_parm {
220 struct wlan_bssid_ex network;
224 Caller Mode: Infra, Ad-HoC(C)
226 Notes: To disconnect the current associated BSS
231 struct disconnect_parm {
232 u32 deauth_timeout_ms;
236 Caller Mode: AP, Ad-HoC(M)
238 Notes: To create a BSS
242 struct createbss_parm {
243 struct wlan_bssid_ex network;
247 Caller Mode: AP, Ad-HoC, Infra
249 Notes: To set the NIC mode of RTL8711
253 The definition of mode:
255 #define IW_MODE_AUTO 0 Let the driver decides which AP to join
256 #define IW_MODE_ADHOC 1 Single cell network (Ad-Hoc Clients)
257 #define IW_MODE_INFRA 2 Multi cell network, roaming, ..
258 #define IW_MODE_MASTER 3 Synchronisation master or Access Point
259 #define IW_MODE_REPEAT 4 Wireless Repeater (forwarder)
260 #define IW_MODE_SECOND 5 Secondary master/repeater (backup)
261 #define IW_MODE_MONITOR 6 Passive monitor (listen only)
264 struct setopmode_parm {
270 Caller Mode: AP, Ad-HoC, Infra
272 Notes: To ask RTL8711 performing site-survey
278 #define RTW_SSID_SCAN_AMOUNT 9 /* for WEXT_CSCAN_AMOUNT 9 */
279 #define RTW_CHANNEL_SCAN_AMOUNT (14+37)
280 struct sitesurvey_parm {
281 sint scan_mode; /* active: 1, passive: 0 */
284 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT];
285 struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
291 Notes: To set the auth type of RTL8711. open/shared/802.1x
296 struct setauth_parm {
297 u8 mode; /* 0: legacy open, 1: legacy shared 2: 802.1x */
298 u8 _1x; /* 0: PSK, 1: TLS */
305 a. algorithm: wep40, wep104, tkip & aes
306 b. keytype: grp key/unicast key
309 when shared key ==> keyid is the camid
310 when 802.1x ==> keyid [0:1] ==> grp key
311 when 802.1x ==> keyid > 2 ==> unicast key
315 u8 algorithm; /* encryption algorithm, could be none, wep40, TKIP, CCMP, wep104 */
317 u8 grpkey; /* 1: this is the grpkey for 802.1x. 0: this is the unicast key for 802.1x */
318 u8 set_tx; /* 1: main tx key for wep. 0: other key. */
319 u8 key[16]; /* this could be 40 or 104 */
323 When in AP or Ad-Hoc mode, this is used to
324 allocate an sw/hw entry for a newly associated sta.
328 when shared key ==> algorithm/keyid
331 struct set_stakey_parm {
338 struct set_stakey_rsp {
347 Command -Rsp(AID == CAMID) mode
349 This is to force fw to add an sta_data entry per driver's request.
351 FW will write an cam entry associated with it.
354 struct set_assocsta_parm {
358 struct set_assocsta_rsp {
368 This is to force fw to del an sta_data entry per driver's request
370 FW will invalidate the cam entry associated with it.
373 struct del_assocsta_parm {
378 Caller Mode: AP/Ad-HoC(M)
380 Notes: To notify fw that given staid has changed its power state
385 struct setstapwrstate_parm {
394 Notes: To setup the basic rate of RTL8711
399 struct setbasicrate_parm {
400 u8 basicrates[NumRates];
406 Notes: To read the current basic rate
411 struct getbasicrate_parm {
415 struct getbasicrate_rsp {
416 u8 basicrates[NumRates];
422 Notes: To setup the data rate of RTL8711
427 struct setdatarate_parm {
429 u8 datarates[NumRates];
435 Notes: To read the current data rate
440 struct getdatarate_parm {
444 struct getdatarate_rsp {
445 u8 datarates[NumRates];
451 AP: AP can use the info for the contents of beacon frame
452 Infra: STA can use the info when sitesurveying
457 Notes: To set the phy capability of the NIC
463 struct setphyinfo_parm {
464 struct regulatory_class class_sets[NUM_REGULATORYS];
468 struct getphyinfo_parm {
472 struct getphyinfo_rsp {
473 struct regulatory_class class_sets[NUM_REGULATORYS];
480 Notes: To set the channel/modem/band
481 This command will be used when channel/modem/band is changed.
494 Notes: To get the current setting of channel/modem/band
515 struct readTSSI_parm {
518 struct readTSSI_rsp {
522 struct writeBB_parm {
534 struct writeRF_parm {
539 struct getrfintfs_parm {
544 struct Tx_Beacon_param
546 struct wlan_bssid_ex network;
550 Notes: This command is used for H2C/C2H loopback testing
553 ==> CMD mode, return H2C_SUCCESS.
554 The following condition must be ture under CMD mode
555 mac[1] == mac[4], mac[2] == mac[3], mac[0]=mac[5]= 0;
556 s0 == 0x1234, s1 == 0xabcd, w0 == 0x78563412, w1 == 0x5aa5def7;
557 s2 == (b1 << 8 | b0);
560 ==> CMD_RSP mode, return H2C_SUCCESS_RSP
562 The rsp layout shall be:
579 ==> CMD_EVENT mode, return H2C_SUCCESS
580 The event layout shall be:
584 mac[2] = event's sequence number, starting from 1 to parm's marc[3]
588 s0 = swap16(s0) - event.mac[2];
589 s1 = s1 + event.mac[2];
592 s2 = s0 + event.mac[2]
594 w1 = swap32(w1) - event.mac[2];
596 parm->mac[3] is the total event counts that host requested.
599 event will be the same with the cmd's param.
603 /* CMD param Formart for driver extra cmd handler */
604 struct drvextra_cmd_parm {
605 int ec_id; /* extra cmd id */
606 int type; /* Can use this field as the type id or command size */
607 int size; /* buffer size */
611 /*------------------- Below are used for RF/BB tunning ---------------------*/
613 struct setantenna_parm {
620 struct enrateadaptive_parm {
624 struct settxagctbl_parm {
625 u32 txagc[MAX_RATES_LENGTH];
628 struct gettxagctbl_parm {
631 struct gettxagctbl_rsp {
632 u32 txagc[MAX_RATES_LENGTH];
635 struct setagcctrl_parm {
636 u32 agcctrl; /* 0: pure hw, 1: fw */
640 struct setssup_parm {
641 u32 ss_ForceUp[MAX_RATES_LENGTH];
644 struct getssup_parm {
648 u8 ss_ForceUp[MAX_RATES_LENGTH];
652 struct setssdlevel_parm {
653 u8 ss_DLevel[MAX_RATES_LENGTH];
656 struct getssdlevel_parm {
659 struct getssdlevel_rsp {
660 u8 ss_DLevel[MAX_RATES_LENGTH];
663 struct setssulevel_parm {
664 u8 ss_ULevel[MAX_RATES_LENGTH];
667 struct getssulevel_parm {
670 struct getssulevel_rsp {
671 u8 ss_ULevel[MAX_RATES_LENGTH];
675 struct setcountjudge_parm {
676 u8 count_judge[MAX_RATES_LENGTH];
679 struct getcountjudge_parm {
682 struct getcountjudge_rsp {
683 u8 count_judge[MAX_RATES_LENGTH];
687 struct setratable_parm {
688 u8 ss_ForceUp[NumRates];
689 u8 ss_ULevel[NumRates];
690 u8 ss_DLevel[NumRates];
691 u8 count_judge[NumRates];
694 struct getratable_parm {
697 struct getratable_rsp {
698 u8 ss_ForceUp[NumRates];
699 u8 ss_ULevel[NumRates];
700 u8 ss_DLevel[NumRates];
701 u8 count_judge[NumRates];
705 /* to get TX, RX retry count */
706 struct gettxretrycnt_parm{
709 struct gettxretrycnt_rsp{
710 unsigned long tx_retrycnt;
713 struct getrxretrycnt_parm{
716 struct getrxretrycnt_rsp{
717 unsigned long rx_retrycnt;
720 /* to get BCNOK, BCNERR count */
721 struct getbcnokcnt_parm{
724 struct getbcnokcnt_rsp{
725 unsigned long bcnokcnt;
728 struct getbcnerrcnt_parm{
731 struct getbcnerrcnt_rsp{
732 unsigned long bcnerrcnt;
735 /* to get current TX power level */
736 struct getcurtxpwrlevel_parm{
739 struct getcurtxpwrlevel_rsp{
740 unsigned short tx_power;
743 struct setprobereqextraie_parm {
745 unsigned char ie_len;
749 struct setassocreqextraie_parm {
751 unsigned char ie_len;
755 struct setproberspextraie_parm {
757 unsigned char ie_len;
761 struct setassocrspextraie_parm {
763 unsigned char ie_len;
774 /*H2C Handler index: 46 */
781 /*H2C Handler index: 59 */
782 struct SetChannelPlan_param
787 /*H2C Handler index: 60 */
788 struct LedBlink_param
793 /*H2C Handler index: 61 */
794 struct SetChannelSwitch_param
799 /*H2C Handler index: 62 */
800 struct TDLSoption_param
806 /*H2C Handler index: 64 */
807 struct RunInThread_param
814 #define GEN_CMD_CODE(cmd) cmd ## _CMD_
821 0x01: sucess, and check Response.
822 0x02: cmd ignored due to duplicated sequcne number
823 0x03: cmd dropped due to invalid cmd code
828 #define H2C_RSP_OFFSET 512
830 #define H2C_SUCCESS 0x00
831 #define H2C_SUCCESS_RSP 0x01
832 #define H2C_DUPLICATED 0x02
833 #define H2C_DROPPED 0x03
834 #define H2C_PARAMETERS_ERROR 0x04
835 #define H2C_REJECTED 0x05
836 #define H2C_CMD_OVERFLOW 0x06
837 #define H2C_RESERVED 0x07
839 u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid, int ssid_num, struct rtw_ieee80211_channel *ch, int ch_num);
840 extern u8 rtw_createbss_cmd(struct adapter *padapter);
841 u8 rtw_startbss_cmd(struct adapter *padapter, int flags);
844 extern u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_key, bool enqueue);
845 extern u8 rtw_clearstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 enqueue);
847 extern u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network* pnetwork);
848 u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueue);
849 extern u8 rtw_setopmode_cmd(struct adapter *padapter, enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype, bool enqueue);
850 extern u8 rtw_setdatarate_cmd(struct adapter *padapter, u8 *rateset);
851 extern u8 rtw_setrfintfs_cmd(struct adapter *padapter, u8 mode);
853 extern u8 rtw_gettssi_cmd(struct adapter *padapter, u8 offset, u8 *pval);
854 extern u8 rtw_setfwdig_cmd(struct adapter *padapter, u8 type);
855 extern u8 rtw_setfwra_cmd(struct adapter *padapter, u8 type);
857 extern u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr);
858 /* add for CONFIG_IEEE80211W, none 11w also can use */
859 extern u8 rtw_reset_securitypriv_cmd(struct adapter *padapter);
860 extern u8 rtw_free_assoc_resources_cmd(struct adapter *padapter);
861 extern u8 rtw_dynamic_chk_wk_cmd(struct adapter *adapter);
863 u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue);
864 u8 rtw_dm_in_lps_wk_cmd(struct adapter *padapter);
866 u8 rtw_dm_ra_mask_wk_cmd(struct adapter *padapter, u8 *psta);
868 extern u8 rtw_ps_cmd(struct adapter *padapter);
870 u8 rtw_chk_hi_queue_cmd(struct adapter *padapter);
872 extern u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue, u8 swconfig);
874 extern u8 rtw_c2h_packet_wk_cmd(struct adapter *padapter, u8 *pbuf, u16 length);
875 extern u8 rtw_c2h_wk_cmd(struct adapter *padapter, u8 *c2h_evt);
877 u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf);
879 extern void rtw_survey_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
880 extern void rtw_disassoc_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
881 extern void rtw_joinbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
882 extern void rtw_createbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
883 extern void rtw_getbbrfreg_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
885 extern void rtw_setstaKey_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
886 extern void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
887 extern void rtw_getrttbl_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
890 struct _cmd_callback {
892 void (*callback)(struct adapter *padapter, struct cmd_obj *cmd);
897 GEN_CMD_CODE(_Read_MACREG) , /*0*/
898 GEN_CMD_CODE(_Write_MACREG) ,
899 GEN_CMD_CODE(_Read_BBREG) ,
900 GEN_CMD_CODE(_Write_BBREG) ,
901 GEN_CMD_CODE(_Read_RFREG) ,
902 GEN_CMD_CODE(_Write_RFREG) , /*5*/
903 GEN_CMD_CODE(_Read_EEPROM) ,
904 GEN_CMD_CODE(_Write_EEPROM) ,
905 GEN_CMD_CODE(_Read_EFUSE) ,
906 GEN_CMD_CODE(_Write_EFUSE) ,
908 GEN_CMD_CODE(_Read_CAM) , /*10*/
909 GEN_CMD_CODE(_Write_CAM) ,
910 GEN_CMD_CODE(_setBCNITV),
911 GEN_CMD_CODE(_setMBIDCFG),
912 GEN_CMD_CODE(_JoinBss), /*14*/
913 GEN_CMD_CODE(_DisConnect) , /*15*/
914 GEN_CMD_CODE(_CreateBss) ,
915 GEN_CMD_CODE(_SetOpMode) ,
916 GEN_CMD_CODE(_SiteSurvey), /*18*/
917 GEN_CMD_CODE(_SetAuth) ,
919 GEN_CMD_CODE(_SetKey) , /*20*/
920 GEN_CMD_CODE(_SetStaKey) ,
921 GEN_CMD_CODE(_SetAssocSta) ,
922 GEN_CMD_CODE(_DelAssocSta) ,
923 GEN_CMD_CODE(_SetStaPwrState) ,
924 GEN_CMD_CODE(_SetBasicRate) , /*25*/
925 GEN_CMD_CODE(_GetBasicRate) ,
926 GEN_CMD_CODE(_SetDataRate) ,
927 GEN_CMD_CODE(_GetDataRate) ,
928 GEN_CMD_CODE(_SetPhyInfo) ,
930 GEN_CMD_CODE(_GetPhyInfo) , /*30*/
931 GEN_CMD_CODE(_SetPhy) ,
932 GEN_CMD_CODE(_GetPhy) ,
933 GEN_CMD_CODE(_readRssi) ,
934 GEN_CMD_CODE(_readGain) ,
935 GEN_CMD_CODE(_SetAtim) , /*35*/
936 GEN_CMD_CODE(_SetPwrMode) ,
937 GEN_CMD_CODE(_JoinbssRpt),
938 GEN_CMD_CODE(_SetRaTable) ,
939 GEN_CMD_CODE(_GetRaTable) ,
941 GEN_CMD_CODE(_GetCCXReport), /*40*/
942 GEN_CMD_CODE(_GetDTMReport),
943 GEN_CMD_CODE(_GetTXRateStatistics),
944 GEN_CMD_CODE(_SetUsbSuspend),
945 GEN_CMD_CODE(_SetH2cLbk),
946 GEN_CMD_CODE(_AddBAReq) , /*45*/
947 GEN_CMD_CODE(_SetChannel), /*46*/
948 GEN_CMD_CODE(_SetTxPower),
949 GEN_CMD_CODE(_SwitchAntenna),
950 GEN_CMD_CODE(_SetCrystalCap),
951 GEN_CMD_CODE(_SetSingleCarrierTx), /*50*/
953 GEN_CMD_CODE(_SetSingleToneTx),/*51*/
954 GEN_CMD_CODE(_SetCarrierSuppressionTx),
955 GEN_CMD_CODE(_SetContinuousTx),
956 GEN_CMD_CODE(_SwitchBandwidth), /*54*/
957 GEN_CMD_CODE(_TX_Beacon), /*55*/
959 GEN_CMD_CODE(_Set_MLME_EVT), /*56*/
960 GEN_CMD_CODE(_Set_Drv_Extra), /*57*/
961 GEN_CMD_CODE(_Set_H2C_MSG), /*58*/
963 GEN_CMD_CODE(_SetChannelPlan), /*59*/
964 GEN_CMD_CODE(_LedBlink), /*60*/
966 GEN_CMD_CODE(_SetChannelSwitch), /*61*/
967 GEN_CMD_CODE(_TDLS), /*62*/
968 GEN_CMD_CODE(_ChkBMCSleepq), /*63*/
970 GEN_CMD_CODE(_RunInThreadCMD), /*64*/
975 #define _GetBBReg_CMD_ _Read_BBREG_CMD_
976 #define _SetBBReg_CMD_ _Write_BBREG_CMD_
977 #define _GetRFReg_CMD_ _Read_RFREG_CMD_
978 #define _SetRFReg_CMD_ _Write_RFREG_CMD_