1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
10 #include <linux/completion.h>
12 #define C2H_MEM_SZ (16*1024)
14 #define FREE_CMDOBJ_SZ 128
16 #define MAX_CMDSZ 1024
18 #define MAX_EVTSZ 1024
20 #define CMDBUFF_ALIGN_SZ 512
23 struct adapter *padapter;
30 struct submit_ctx *sctx;
31 struct list_head list;
36 RTW_CMDF_DIRECTLY = BIT0,
37 RTW_CMDF_WAIT_ACK = BIT1,
41 struct completion cmd_queue_comp;
42 struct completion terminate_cmdthread_comp;
43 struct __queue cmd_queue;
45 u8 *cmd_buf; /* shall be non-paged, and 4 bytes aligned */
46 u8 *cmd_allocated_buf;
47 u8 *rsp_buf; /* shall be non-paged, and 4 bytes aligned */
48 u8 *rsp_allocated_buf;
52 atomic_t cmdthd_running;
53 /* u8 cmdthd_running; */
55 struct adapter *padapter;
62 struct rtw_cbuf *c2h_queue;
63 #define C2H_QUEUE_MAX_LEN 10
66 u8 *evt_buf; /* shall be non-paged, and 4 bytes aligned */
67 u8 *evt_allocated_buf;
70 u8 *allocated_c2h_mem;
73 #define init_h2fwcmd_w_parm_no_rsp(pcmd, pparm, code) \
75 INIT_LIST_HEAD(&pcmd->list);\
76 pcmd->cmdcode = code;\
77 pcmd->parmbuf = (u8 *)(pparm);\
78 pcmd->cmdsz = sizeof(*pparm);\
83 #define init_h2fwcmd_w_parm_no_parm_rsp(pcmd, code) \
85 INIT_LIST_HEAD(&pcmd->list);\
86 pcmd->cmdcode = code;\
87 pcmd->parmbuf = NULL;\
100 struct c2h_evt_hdr_88xx {
108 #define c2h_evt_valid(c2h_evt) ((c2h_evt)->id || (c2h_evt)->plen)
110 struct P2P_PS_Offload_t {
112 u8 role:1; /* 1: Owner, 0: Client */
116 u8 AllStaSleep:1; /* Only valid in Owner */
121 struct P2P_PS_CTWPeriod_t {
122 u8 CTWPeriod; /* TU */
125 int rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj);
126 extern struct cmd_obj *rtw_dequeue_cmd(struct cmd_priv *pcmdpriv);
127 extern void rtw_free_cmd_obj(struct cmd_obj *pcmd);
129 void rtw_stop_cmd_thread(struct adapter *adapter);
130 int rtw_cmd_thread(void *context);
132 extern void rtw_free_cmd_priv(struct cmd_priv *pcmdpriv);
134 extern void rtw_free_evt_priv(struct evt_priv *pevtpriv);
135 extern void rtw_evt_notify_isr(struct evt_priv *pevtpriv);
137 enum rtw_drvextra_cmd_id {
142 POWER_SAVING_CTRL_WK_CID,/* IPS, AUTOSuspend */
147 CHECK_HIQ_WK_CID,/* for softap mode, check hi queue if empty */
150 RTP_TIMER_CFG_WK_CID,
151 RESET_SECURITYPRIV, /* add for CONFIG_IEEE80211W, none 11w also can use */
152 FREE_ASSOC_RESOURCES, /* add for CONFIG_IEEE80211W, none 11w also can use */
154 DM_RA_MSK_WK_CID, /* add for STA update RAMask when bandwith change. */
163 LPS_CTRL_JOINBSS = 1,
164 LPS_CTRL_CONNECT = 2,
165 LPS_CTRL_DISCONNECT = 3,
166 LPS_CTRL_SPECIAL_PACKET = 4,
168 LPS_CTRL_TRAFFIC_BUSY = 6,
178 Caller Mode: Infra, Ad-HoC(C)
180 Notes: To enter USB suspend mode
185 struct usb_suspend_parm {
186 u32 action;/* 1: sleep, 0:resume */
190 Caller Mode: Infra, Ad-HoC
192 Notes: To join a known BSS.
199 Caller Mode: Infra, Ad-Hoc
201 Notes: To join the specified bss
206 struct joinbss_parm {
207 struct wlan_bssid_ex network;
211 Caller Mode: Infra, Ad-HoC(C)
213 Notes: To disconnect the current associated BSS
218 struct disconnect_parm {
219 u32 deauth_timeout_ms;
223 Caller Mode: AP, Ad-HoC(M)
225 Notes: To create a BSS
229 struct createbss_parm {
230 struct wlan_bssid_ex network;
234 Caller Mode: AP, Ad-HoC, Infra
236 Notes: To set the NIC mode of RTL8711
240 The definition of mode:
242 #define IW_MODE_AUTO 0 Let the driver decides which AP to join
243 #define IW_MODE_ADHOC 1 Single cell network (Ad-Hoc Clients)
244 #define IW_MODE_INFRA 2 Multi cell network, roaming, ..
245 #define IW_MODE_MASTER 3 Synchronisation master or Access Point
246 #define IW_MODE_REPEAT 4 Wireless Repeater (forwarder)
247 #define IW_MODE_SECOND 5 Secondary master/repeater (backup)
248 #define IW_MODE_MONITOR 6 Passive monitor (listen only)
251 struct setopmode_parm {
257 Caller Mode: AP, Ad-HoC, Infra
259 Notes: To ask RTL8711 performing site-survey
265 #define RTW_SSID_SCAN_AMOUNT 9 /* for WEXT_CSCAN_AMOUNT 9 */
266 #define RTW_CHANNEL_SCAN_AMOUNT (14+37)
267 struct sitesurvey_parm {
268 sint scan_mode; /* active: 1, passive: 0 */
271 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT];
272 struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
278 Notes: To set the auth type of RTL8711. open/shared/802.1x
283 struct setauth_parm {
284 u8 mode; /* 0: legacy open, 1: legacy shared 2: 802.1x */
285 u8 _1x; /* 0: PSK, 1: TLS */
292 a. algorithm: wep40, wep104, tkip & aes
293 b. keytype: grp key/unicast key
296 when shared key ==> keyid is the camid
297 when 802.1x ==> keyid [0:1] ==> grp key
298 when 802.1x ==> keyid > 2 ==> unicast key
302 u8 algorithm; /* encryption algorithm, could be none, wep40, TKIP, CCMP, wep104 */
304 u8 grpkey; /* 1: this is the grpkey for 802.1x. 0: this is the unicast key for 802.1x */
305 u8 set_tx; /* 1: main tx key for wep. 0: other key. */
306 u8 key[16]; /* this could be 40 or 104 */
310 When in AP or Ad-Hoc mode, this is used to
311 allocate an sw/hw entry for a newly associated sta.
315 when shared key ==> algorithm/keyid
318 struct set_stakey_parm {
325 struct set_stakey_rsp {
334 Command -Rsp(AID == CAMID) mode
336 This is to force fw to add an sta_data entry per driver's request.
338 FW will write an cam entry associated with it.
341 struct set_assocsta_parm {
345 struct set_assocsta_rsp {
355 This is to force fw to del an sta_data entry per driver's request
357 FW will invalidate the cam entry associated with it.
360 struct del_assocsta_parm {
365 Caller Mode: AP/Ad-HoC(M)
367 Notes: To notify fw that given staid has changed its power state
372 struct setstapwrstate_parm {
381 Notes: To setup the basic rate of RTL8711
386 struct setbasicrate_parm {
387 u8 basicrates[NumRates];
393 Notes: To read the current basic rate
398 struct getbasicrate_parm {
402 struct getbasicrate_rsp {
403 u8 basicrates[NumRates];
409 Notes: To setup the data rate of RTL8711
414 struct setdatarate_parm {
416 u8 datarates[NumRates];
422 Notes: To read the current data rate
427 struct getdatarate_parm {
431 struct getdatarate_rsp {
432 u8 datarates[NumRates];
438 AP: AP can use the info for the contents of beacon frame
439 Infra: STA can use the info when sitesurveying
444 Notes: To set the phy capability of the NIC
450 struct setphyinfo_parm {
451 struct regulatory_class class_sets[NUM_REGULATORYS];
455 struct getphyinfo_parm {
459 struct getphyinfo_rsp {
460 struct regulatory_class class_sets[NUM_REGULATORYS];
467 Notes: To set the channel/modem/band
468 This command will be used when channel/modem/band is changed.
481 Notes: To get the current setting of channel/modem/band
502 struct readTSSI_parm {
505 struct readTSSI_rsp {
509 struct writeBB_parm {
521 struct writeRF_parm {
526 struct getrfintfs_parm {
531 struct Tx_Beacon_param {
532 struct wlan_bssid_ex network;
536 Notes: This command is used for H2C/C2H loopback testing
539 ==> CMD mode, return H2C_SUCCESS.
540 The following condition must be true under CMD mode
541 mac[1] == mac[4], mac[2] == mac[3], mac[0]=mac[5]= 0;
542 s0 == 0x1234, s1 == 0xabcd, w0 == 0x78563412, w1 == 0x5aa5def7;
543 s2 == (b1 << 8 | b0);
546 ==> CMD_RSP mode, return H2C_SUCCESS_RSP
548 The rsp layout shall be:
565 ==> CMD_EVENT mode, return H2C_SUCCESS
566 The event layout shall be:
570 mac[2] = event's sequence number, starting from 1 to parm's marc[3]
574 s0 = swap16(s0) - event.mac[2];
575 s1 = s1 + event.mac[2];
578 s2 = s0 + event.mac[2]
580 w1 = swap32(w1) - event.mac[2];
582 parm->mac[3] is the total event counts that host requested.
585 event will be the same with the cmd's param.
589 /* CMD param Formart for driver extra cmd handler */
590 struct drvextra_cmd_parm {
591 int ec_id; /* extra cmd id */
592 int type; /* Can use this field as the type id or command size */
593 int size; /* buffer size */
597 /*------------------- Below are used for RF/BB tunning ---------------------*/
599 struct setantenna_parm {
606 struct enrateadaptive_parm {
610 struct settxagctbl_parm {
611 u32 txagc[MAX_RATES_LENGTH];
614 struct gettxagctbl_parm {
617 struct gettxagctbl_rsp {
618 u32 txagc[MAX_RATES_LENGTH];
621 struct setagcctrl_parm {
622 u32 agcctrl; /* 0: pure hw, 1: fw */
626 struct setssup_parm {
627 u32 ss_ForceUp[MAX_RATES_LENGTH];
630 struct getssup_parm {
634 u8 ss_ForceUp[MAX_RATES_LENGTH];
638 struct setssdlevel_parm {
639 u8 ss_DLevel[MAX_RATES_LENGTH];
642 struct getssdlevel_parm {
645 struct getssdlevel_rsp {
646 u8 ss_DLevel[MAX_RATES_LENGTH];
649 struct setssulevel_parm {
650 u8 ss_ULevel[MAX_RATES_LENGTH];
653 struct getssulevel_parm {
656 struct getssulevel_rsp {
657 u8 ss_ULevel[MAX_RATES_LENGTH];
661 struct setcountjudge_parm {
662 u8 count_judge[MAX_RATES_LENGTH];
665 struct getcountjudge_parm {
668 struct getcountjudge_rsp {
669 u8 count_judge[MAX_RATES_LENGTH];
673 struct setratable_parm {
674 u8 ss_ForceUp[NumRates];
675 u8 ss_ULevel[NumRates];
676 u8 ss_DLevel[NumRates];
677 u8 count_judge[NumRates];
680 struct getratable_parm {
683 struct getratable_rsp {
684 u8 ss_ForceUp[NumRates];
685 u8 ss_ULevel[NumRates];
686 u8 ss_DLevel[NumRates];
687 u8 count_judge[NumRates];
691 /* to get TX, RX retry count */
692 struct gettxretrycnt_parm {
695 struct gettxretrycnt_rsp {
696 unsigned long tx_retrycnt;
699 struct getrxretrycnt_parm {
702 struct getrxretrycnt_rsp {
703 unsigned long rx_retrycnt;
706 /* to get BCNOK, BCNERR count */
707 struct getbcnokcnt_parm {
710 struct getbcnokcnt_rsp {
711 unsigned long bcnokcnt;
714 struct getbcnerrcnt_parm {
717 struct getbcnerrcnt_rsp {
718 unsigned long bcnerrcnt;
721 /* to get current TX power level */
722 struct getcurtxpwrlevel_parm {
725 struct getcurtxpwrlevel_rsp {
726 unsigned short tx_power;
729 struct setprobereqextraie_parm {
731 unsigned char ie_len;
735 struct setassocreqextraie_parm {
737 unsigned char ie_len;
741 struct setproberspextraie_parm {
743 unsigned char ie_len;
747 struct setassocrspextraie_parm {
749 unsigned char ie_len;
754 struct addBaReq_parm {
759 /*H2C Handler index: 46 */
766 /*H2C Handler index: 59 */
767 struct SetChannelPlan_param {
771 /*H2C Handler index: 60 */
772 struct LedBlink_param {
776 /*H2C Handler index: 61 */
777 struct SetChannelSwitch_param {
781 /*H2C Handler index: 62 */
782 struct TDLSoption_param {
787 /*H2C Handler index: 64 */
788 struct RunInThread_param {
794 #define GEN_CMD_CODE(cmd) cmd ## _CMD_
801 0x01: sucess, and check Response.
802 0x02: cmd ignored due to duplicated sequcne number
803 0x03: cmd dropped due to invalid cmd code
808 #define H2C_RSP_OFFSET 512
810 #define H2C_SUCCESS 0x00
811 #define H2C_SUCCESS_RSP 0x01
812 #define H2C_DUPLICATED 0x02
813 #define H2C_DROPPED 0x03
814 #define H2C_PARAMETERS_ERROR 0x04
815 #define H2C_REJECTED 0x05
816 #define H2C_CMD_OVERFLOW 0x06
817 #define H2C_RESERVED 0x07
819 u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid, int ssid_num, struct rtw_ieee80211_channel *ch, int ch_num);
820 extern u8 rtw_createbss_cmd(struct adapter *padapter);
821 int rtw_startbss_cmd(struct adapter *padapter, int flags);
824 extern u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_key, bool enqueue);
825 extern u8 rtw_clearstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 enqueue);
827 extern u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network* pnetwork);
828 u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueue);
829 extern u8 rtw_setopmode_cmd(struct adapter *padapter, enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype, bool enqueue);
830 extern u8 rtw_setdatarate_cmd(struct adapter *padapter, u8 *rateset);
831 extern u8 rtw_setrfintfs_cmd(struct adapter *padapter, u8 mode);
833 extern u8 rtw_gettssi_cmd(struct adapter *padapter, u8 offset, u8 *pval);
834 extern u8 rtw_setfwdig_cmd(struct adapter *padapter, u8 type);
835 extern u8 rtw_setfwra_cmd(struct adapter *padapter, u8 type);
837 extern u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr);
838 /* add for CONFIG_IEEE80211W, none 11w also can use */
839 extern u8 rtw_reset_securitypriv_cmd(struct adapter *padapter);
840 extern u8 rtw_free_assoc_resources_cmd(struct adapter *padapter);
841 extern u8 rtw_dynamic_chk_wk_cmd(struct adapter *adapter);
843 u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue);
844 u8 rtw_dm_in_lps_wk_cmd(struct adapter *padapter);
846 u8 rtw_dm_ra_mask_wk_cmd(struct adapter *padapter, u8 *psta);
848 extern u8 rtw_ps_cmd(struct adapter *padapter);
850 u8 rtw_chk_hi_queue_cmd(struct adapter *padapter);
852 extern u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue, u8 swconfig);
854 extern u8 rtw_c2h_packet_wk_cmd(struct adapter *padapter, u8 *pbuf, u16 length);
855 extern u8 rtw_c2h_wk_cmd(struct adapter *padapter, u8 *c2h_evt);
857 u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf);
859 extern void rtw_survey_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
860 extern void rtw_disassoc_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
861 extern void rtw_joinbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
862 extern void rtw_createbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
863 extern void rtw_getbbrfreg_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
865 extern void rtw_setstaKey_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
866 extern void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
867 extern void rtw_getrttbl_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
870 struct _cmd_callback {
872 void (*callback)(struct adapter *padapter, struct cmd_obj *cmd);
876 GEN_CMD_CODE(_Read_MACREG), /*0*/
877 GEN_CMD_CODE(_Write_MACREG),
878 GEN_CMD_CODE(_Read_BBREG),
879 GEN_CMD_CODE(_Write_BBREG),
880 GEN_CMD_CODE(_Read_RFREG),
881 GEN_CMD_CODE(_Write_RFREG), /*5*/
882 GEN_CMD_CODE(_Read_EEPROM),
883 GEN_CMD_CODE(_Write_EEPROM),
884 GEN_CMD_CODE(_Read_EFUSE),
885 GEN_CMD_CODE(_Write_EFUSE),
887 GEN_CMD_CODE(_Read_CAM), /*10*/
888 GEN_CMD_CODE(_Write_CAM),
889 GEN_CMD_CODE(_setBCNITV),
890 GEN_CMD_CODE(_setMBIDCFG),
891 GEN_CMD_CODE(_JoinBss), /*14*/
892 GEN_CMD_CODE(_DisConnect), /*15*/
893 GEN_CMD_CODE(_CreateBss),
894 GEN_CMD_CODE(_SetOpMode),
895 GEN_CMD_CODE(_SiteSurvey), /*18*/
896 GEN_CMD_CODE(_SetAuth),
898 GEN_CMD_CODE(_SetKey), /*20*/
899 GEN_CMD_CODE(_SetStaKey),
900 GEN_CMD_CODE(_SetAssocSta),
901 GEN_CMD_CODE(_DelAssocSta),
902 GEN_CMD_CODE(_SetStaPwrState),
903 GEN_CMD_CODE(_SetBasicRate), /*25*/
904 GEN_CMD_CODE(_GetBasicRate),
905 GEN_CMD_CODE(_SetDataRate),
906 GEN_CMD_CODE(_GetDataRate),
907 GEN_CMD_CODE(_SetPhyInfo),
909 GEN_CMD_CODE(_GetPhyInfo), /*30*/
910 GEN_CMD_CODE(_SetPhy),
911 GEN_CMD_CODE(_GetPhy),
912 GEN_CMD_CODE(_readRssi),
913 GEN_CMD_CODE(_readGain),
914 GEN_CMD_CODE(_SetAtim), /*35*/
915 GEN_CMD_CODE(_SetPwrMode),
916 GEN_CMD_CODE(_JoinbssRpt),
917 GEN_CMD_CODE(_SetRaTable),
918 GEN_CMD_CODE(_GetRaTable),
920 GEN_CMD_CODE(_GetCCXReport), /*40*/
921 GEN_CMD_CODE(_GetDTMReport),
922 GEN_CMD_CODE(_GetTXRateStatistics),
923 GEN_CMD_CODE(_SetUsbSuspend),
924 GEN_CMD_CODE(_SetH2cLbk),
925 GEN_CMD_CODE(_AddBAReq), /*45*/
926 GEN_CMD_CODE(_SetChannel), /*46*/
927 GEN_CMD_CODE(_SetTxPower),
928 GEN_CMD_CODE(_SwitchAntenna),
929 GEN_CMD_CODE(_SetCrystalCap),
930 GEN_CMD_CODE(_SetSingleCarrierTx), /*50*/
932 GEN_CMD_CODE(_SetSingleToneTx),/*51*/
933 GEN_CMD_CODE(_SetCarrierSuppressionTx),
934 GEN_CMD_CODE(_SetContinuousTx),
935 GEN_CMD_CODE(_SwitchBandwidth), /*54*/
936 GEN_CMD_CODE(_TX_Beacon), /*55*/
938 GEN_CMD_CODE(_Set_MLME_EVT), /*56*/
939 GEN_CMD_CODE(_Set_Drv_Extra), /*57*/
940 GEN_CMD_CODE(_Set_H2C_MSG), /*58*/
942 GEN_CMD_CODE(_SetChannelPlan), /*59*/
943 GEN_CMD_CODE(_LedBlink), /*60*/
945 GEN_CMD_CODE(_SetChannelSwitch), /*61*/
946 GEN_CMD_CODE(_TDLS), /*62*/
947 GEN_CMD_CODE(_ChkBMCSleepq), /*63*/
949 GEN_CMD_CODE(_RunInThreadCMD), /*64*/
954 #define _GetBBReg_CMD_ _Read_BBREG_CMD_
955 #define _SetBBReg_CMD_ _Write_BBREG_CMD_
956 #define _GetRFReg_CMD_ _Read_RFREG_CMD_
957 #define _SetRFReg_CMD_ _Write_RFREG_CMD_