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
143 POWER_SAVING_CTRL_WK_CID,/* IPS, AUTOSuspend */
148 CHECK_HIQ_WK_CID,/* for softap mode, check hi queue if empty */
151 RTP_TIMER_CFG_WK_CID,
152 RESET_SECURITYPRIV, /* add for CONFIG_IEEE80211W, none 11w also can use */
153 FREE_ASSOC_RESOURCES, /* add for CONFIG_IEEE80211W, none 11w also can use */
155 DM_RA_MSK_WK_CID, /* add for STA update RAMask when bandwith change. */
165 LPS_CTRL_JOINBSS = 1,
167 LPS_CTRL_DISCONNECT =3,
168 LPS_CTRL_SPECIAL_PACKET =4,
170 LPS_CTRL_TRAFFIC_BUSY = 6,
180 Caller Mode: Infra, Ad-HoC(C)
182 Notes: To enter USB suspend mode
187 struct usb_suspend_parm {
188 u32 action;/* 1: sleep, 0:resume */
192 Caller Mode: Infra, Ad-HoC
194 Notes: To join a known BSS.
201 Caller Mode: Infra, Ad-Hoc
203 Notes: To join the specified bss
208 struct joinbss_parm {
209 struct wlan_bssid_ex network;
213 Caller Mode: Infra, Ad-HoC(C)
215 Notes: To disconnect the current associated BSS
220 struct disconnect_parm {
221 u32 deauth_timeout_ms;
225 Caller Mode: AP, Ad-HoC(M)
227 Notes: To create a BSS
231 struct createbss_parm {
232 struct wlan_bssid_ex network;
236 Caller Mode: AP, Ad-HoC, Infra
238 Notes: To set the NIC mode of RTL8711
242 The definition of mode:
244 #define IW_MODE_AUTO 0 Let the driver decides which AP to join
245 #define IW_MODE_ADHOC 1 Single cell network (Ad-Hoc Clients)
246 #define IW_MODE_INFRA 2 Multi cell network, roaming, ..
247 #define IW_MODE_MASTER 3 Synchronisation master or Access Point
248 #define IW_MODE_REPEAT 4 Wireless Repeater (forwarder)
249 #define IW_MODE_SECOND 5 Secondary master/repeater (backup)
250 #define IW_MODE_MONITOR 6 Passive monitor (listen only)
253 struct setopmode_parm {
259 Caller Mode: AP, Ad-HoC, Infra
261 Notes: To ask RTL8711 performing site-survey
267 #define RTW_SSID_SCAN_AMOUNT 9 /* for WEXT_CSCAN_AMOUNT 9 */
268 #define RTW_CHANNEL_SCAN_AMOUNT (14+37)
269 struct sitesurvey_parm {
270 sint scan_mode; /* active: 1, passive: 0 */
273 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT];
274 struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
280 Notes: To set the auth type of RTL8711. open/shared/802.1x
285 struct setauth_parm {
286 u8 mode; /* 0: legacy open, 1: legacy shared 2: 802.1x */
287 u8 _1x; /* 0: PSK, 1: TLS */
294 a. algorithm: wep40, wep104, tkip & aes
295 b. keytype: grp key/unicast key
298 when shared key ==> keyid is the camid
299 when 802.1x ==> keyid [0:1] ==> grp key
300 when 802.1x ==> keyid > 2 ==> unicast key
304 u8 algorithm; /* encryption algorithm, could be none, wep40, TKIP, CCMP, wep104 */
306 u8 grpkey; /* 1: this is the grpkey for 802.1x. 0: this is the unicast key for 802.1x */
307 u8 set_tx; /* 1: main tx key for wep. 0: other key. */
308 u8 key[16]; /* this could be 40 or 104 */
312 When in AP or Ad-Hoc mode, this is used to
313 allocate an sw/hw entry for a newly associated sta.
317 when shared key ==> algorithm/keyid
320 struct set_stakey_parm {
327 struct set_stakey_rsp {
336 Command -Rsp(AID == CAMID) mode
338 This is to force fw to add an sta_data entry per driver's request.
340 FW will write an cam entry associated with it.
343 struct set_assocsta_parm {
347 struct set_assocsta_rsp {
357 This is to force fw to del an sta_data entry per driver's request
359 FW will invalidate the cam entry associated with it.
362 struct del_assocsta_parm {
367 Caller Mode: AP/Ad-HoC(M)
369 Notes: To notify fw that given staid has changed its power state
374 struct setstapwrstate_parm {
383 Notes: To setup the basic rate of RTL8711
388 struct setbasicrate_parm {
389 u8 basicrates[NumRates];
395 Notes: To read the current basic rate
400 struct getbasicrate_parm {
404 struct getbasicrate_rsp {
405 u8 basicrates[NumRates];
411 Notes: To setup the data rate of RTL8711
416 struct setdatarate_parm {
418 u8 datarates[NumRates];
424 Notes: To read the current data rate
429 struct getdatarate_parm {
433 struct getdatarate_rsp {
434 u8 datarates[NumRates];
440 AP: AP can use the info for the contents of beacon frame
441 Infra: STA can use the info when sitesurveying
446 Notes: To set the phy capability of the NIC
452 struct setphyinfo_parm {
453 struct regulatory_class class_sets[NUM_REGULATORYS];
457 struct getphyinfo_parm {
461 struct getphyinfo_rsp {
462 struct regulatory_class class_sets[NUM_REGULATORYS];
469 Notes: To set the channel/modem/band
470 This command will be used when channel/modem/band is changed.
483 Notes: To get the current setting of channel/modem/band
504 struct readTSSI_parm {
507 struct readTSSI_rsp {
511 struct writeBB_parm {
523 struct writeRF_parm {
528 struct getrfintfs_parm {
533 struct Tx_Beacon_param
535 struct wlan_bssid_ex network;
539 Notes: This command is used for H2C/C2H loopback testing
542 ==> CMD mode, return H2C_SUCCESS.
543 The following condition must be true under CMD mode
544 mac[1] == mac[4], mac[2] == mac[3], mac[0]=mac[5]= 0;
545 s0 == 0x1234, s1 == 0xabcd, w0 == 0x78563412, w1 == 0x5aa5def7;
546 s2 == (b1 << 8 | b0);
549 ==> CMD_RSP mode, return H2C_SUCCESS_RSP
551 The rsp layout shall be:
568 ==> CMD_EVENT mode, return H2C_SUCCESS
569 The event layout shall be:
573 mac[2] = event's sequence number, starting from 1 to parm's marc[3]
577 s0 = swap16(s0) - event.mac[2];
578 s1 = s1 + event.mac[2];
581 s2 = s0 + event.mac[2]
583 w1 = swap32(w1) - event.mac[2];
585 parm->mac[3] is the total event counts that host requested.
588 event will be the same with the cmd's param.
592 /* CMD param Formart for driver extra cmd handler */
593 struct drvextra_cmd_parm {
594 int ec_id; /* extra cmd id */
595 int type; /* Can use this field as the type id or command size */
596 int size; /* buffer size */
600 /*------------------- Below are used for RF/BB tunning ---------------------*/
602 struct setantenna_parm {
609 struct enrateadaptive_parm {
613 struct settxagctbl_parm {
614 u32 txagc[MAX_RATES_LENGTH];
617 struct gettxagctbl_parm {
620 struct gettxagctbl_rsp {
621 u32 txagc[MAX_RATES_LENGTH];
624 struct setagcctrl_parm {
625 u32 agcctrl; /* 0: pure hw, 1: fw */
629 struct setssup_parm {
630 u32 ss_ForceUp[MAX_RATES_LENGTH];
633 struct getssup_parm {
637 u8 ss_ForceUp[MAX_RATES_LENGTH];
641 struct setssdlevel_parm {
642 u8 ss_DLevel[MAX_RATES_LENGTH];
645 struct getssdlevel_parm {
648 struct getssdlevel_rsp {
649 u8 ss_DLevel[MAX_RATES_LENGTH];
652 struct setssulevel_parm {
653 u8 ss_ULevel[MAX_RATES_LENGTH];
656 struct getssulevel_parm {
659 struct getssulevel_rsp {
660 u8 ss_ULevel[MAX_RATES_LENGTH];
664 struct setcountjudge_parm {
665 u8 count_judge[MAX_RATES_LENGTH];
668 struct getcountjudge_parm {
671 struct getcountjudge_rsp {
672 u8 count_judge[MAX_RATES_LENGTH];
676 struct setratable_parm {
677 u8 ss_ForceUp[NumRates];
678 u8 ss_ULevel[NumRates];
679 u8 ss_DLevel[NumRates];
680 u8 count_judge[NumRates];
683 struct getratable_parm {
686 struct getratable_rsp {
687 u8 ss_ForceUp[NumRates];
688 u8 ss_ULevel[NumRates];
689 u8 ss_DLevel[NumRates];
690 u8 count_judge[NumRates];
694 /* to get TX, RX retry count */
695 struct gettxretrycnt_parm{
698 struct gettxretrycnt_rsp{
699 unsigned long tx_retrycnt;
702 struct getrxretrycnt_parm{
705 struct getrxretrycnt_rsp{
706 unsigned long rx_retrycnt;
709 /* to get BCNOK, BCNERR count */
710 struct getbcnokcnt_parm{
713 struct getbcnokcnt_rsp{
714 unsigned long bcnokcnt;
717 struct getbcnerrcnt_parm{
720 struct getbcnerrcnt_rsp{
721 unsigned long bcnerrcnt;
724 /* to get current TX power level */
725 struct getcurtxpwrlevel_parm{
728 struct getcurtxpwrlevel_rsp{
729 unsigned short tx_power;
732 struct setprobereqextraie_parm {
734 unsigned char ie_len;
738 struct setassocreqextraie_parm {
740 unsigned char ie_len;
744 struct setproberspextraie_parm {
746 unsigned char ie_len;
750 struct setassocrspextraie_parm {
752 unsigned char ie_len;
763 /*H2C Handler index: 46 */
770 /*H2C Handler index: 59 */
771 struct SetChannelPlan_param
776 /*H2C Handler index: 60 */
777 struct LedBlink_param
782 /*H2C Handler index: 61 */
783 struct SetChannelSwitch_param
788 /*H2C Handler index: 62 */
789 struct TDLSoption_param
795 /*H2C Handler index: 64 */
796 struct RunInThread_param
803 #define GEN_CMD_CODE(cmd) cmd ## _CMD_
810 0x01: sucess, and check Response.
811 0x02: cmd ignored due to duplicated sequcne number
812 0x03: cmd dropped due to invalid cmd code
817 #define H2C_RSP_OFFSET 512
819 #define H2C_SUCCESS 0x00
820 #define H2C_SUCCESS_RSP 0x01
821 #define H2C_DUPLICATED 0x02
822 #define H2C_DROPPED 0x03
823 #define H2C_PARAMETERS_ERROR 0x04
824 #define H2C_REJECTED 0x05
825 #define H2C_CMD_OVERFLOW 0x06
826 #define H2C_RESERVED 0x07
828 u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid, int ssid_num, struct rtw_ieee80211_channel *ch, int ch_num);
829 extern u8 rtw_createbss_cmd(struct adapter *padapter);
830 int rtw_startbss_cmd(struct adapter *padapter, int flags);
833 extern u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_key, bool enqueue);
834 extern u8 rtw_clearstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 enqueue);
836 extern u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network* pnetwork);
837 u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueue);
838 extern u8 rtw_setopmode_cmd(struct adapter *padapter, enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype, bool enqueue);
839 extern u8 rtw_setdatarate_cmd(struct adapter *padapter, u8 *rateset);
840 extern u8 rtw_setrfintfs_cmd(struct adapter *padapter, u8 mode);
842 extern u8 rtw_gettssi_cmd(struct adapter *padapter, u8 offset, u8 *pval);
843 extern u8 rtw_setfwdig_cmd(struct adapter *padapter, u8 type);
844 extern u8 rtw_setfwra_cmd(struct adapter *padapter, u8 type);
846 extern u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr);
847 /* add for CONFIG_IEEE80211W, none 11w also can use */
848 extern u8 rtw_reset_securitypriv_cmd(struct adapter *padapter);
849 extern u8 rtw_free_assoc_resources_cmd(struct adapter *padapter);
850 extern u8 rtw_dynamic_chk_wk_cmd(struct adapter *adapter);
852 u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue);
853 u8 rtw_dm_in_lps_wk_cmd(struct adapter *padapter);
855 u8 rtw_dm_ra_mask_wk_cmd(struct adapter *padapter, u8 *psta);
857 extern u8 rtw_ps_cmd(struct adapter *padapter);
859 u8 rtw_chk_hi_queue_cmd(struct adapter *padapter);
861 extern u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue, u8 swconfig);
863 extern u8 rtw_c2h_packet_wk_cmd(struct adapter *padapter, u8 *pbuf, u16 length);
864 extern u8 rtw_c2h_wk_cmd(struct adapter *padapter, u8 *c2h_evt);
866 u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf);
868 extern void rtw_survey_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
869 extern void rtw_disassoc_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
870 extern void rtw_joinbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
871 extern void rtw_createbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
872 extern void rtw_getbbrfreg_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
874 extern void rtw_setstaKey_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
875 extern void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
876 extern void rtw_getrttbl_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
879 struct _cmd_callback {
881 void (*callback)(struct adapter *padapter, struct cmd_obj *cmd);
886 GEN_CMD_CODE(_Read_MACREG) , /*0*/
887 GEN_CMD_CODE(_Write_MACREG) ,
888 GEN_CMD_CODE(_Read_BBREG) ,
889 GEN_CMD_CODE(_Write_BBREG) ,
890 GEN_CMD_CODE(_Read_RFREG) ,
891 GEN_CMD_CODE(_Write_RFREG) , /*5*/
892 GEN_CMD_CODE(_Read_EEPROM) ,
893 GEN_CMD_CODE(_Write_EEPROM) ,
894 GEN_CMD_CODE(_Read_EFUSE) ,
895 GEN_CMD_CODE(_Write_EFUSE) ,
897 GEN_CMD_CODE(_Read_CAM) , /*10*/
898 GEN_CMD_CODE(_Write_CAM) ,
899 GEN_CMD_CODE(_setBCNITV),
900 GEN_CMD_CODE(_setMBIDCFG),
901 GEN_CMD_CODE(_JoinBss), /*14*/
902 GEN_CMD_CODE(_DisConnect) , /*15*/
903 GEN_CMD_CODE(_CreateBss) ,
904 GEN_CMD_CODE(_SetOpMode) ,
905 GEN_CMD_CODE(_SiteSurvey), /*18*/
906 GEN_CMD_CODE(_SetAuth) ,
908 GEN_CMD_CODE(_SetKey) , /*20*/
909 GEN_CMD_CODE(_SetStaKey) ,
910 GEN_CMD_CODE(_SetAssocSta) ,
911 GEN_CMD_CODE(_DelAssocSta) ,
912 GEN_CMD_CODE(_SetStaPwrState) ,
913 GEN_CMD_CODE(_SetBasicRate) , /*25*/
914 GEN_CMD_CODE(_GetBasicRate) ,
915 GEN_CMD_CODE(_SetDataRate) ,
916 GEN_CMD_CODE(_GetDataRate) ,
917 GEN_CMD_CODE(_SetPhyInfo) ,
919 GEN_CMD_CODE(_GetPhyInfo) , /*30*/
920 GEN_CMD_CODE(_SetPhy) ,
921 GEN_CMD_CODE(_GetPhy) ,
922 GEN_CMD_CODE(_readRssi) ,
923 GEN_CMD_CODE(_readGain) ,
924 GEN_CMD_CODE(_SetAtim) , /*35*/
925 GEN_CMD_CODE(_SetPwrMode) ,
926 GEN_CMD_CODE(_JoinbssRpt),
927 GEN_CMD_CODE(_SetRaTable) ,
928 GEN_CMD_CODE(_GetRaTable) ,
930 GEN_CMD_CODE(_GetCCXReport), /*40*/
931 GEN_CMD_CODE(_GetDTMReport),
932 GEN_CMD_CODE(_GetTXRateStatistics),
933 GEN_CMD_CODE(_SetUsbSuspend),
934 GEN_CMD_CODE(_SetH2cLbk),
935 GEN_CMD_CODE(_AddBAReq) , /*45*/
936 GEN_CMD_CODE(_SetChannel), /*46*/
937 GEN_CMD_CODE(_SetTxPower),
938 GEN_CMD_CODE(_SwitchAntenna),
939 GEN_CMD_CODE(_SetCrystalCap),
940 GEN_CMD_CODE(_SetSingleCarrierTx), /*50*/
942 GEN_CMD_CODE(_SetSingleToneTx),/*51*/
943 GEN_CMD_CODE(_SetCarrierSuppressionTx),
944 GEN_CMD_CODE(_SetContinuousTx),
945 GEN_CMD_CODE(_SwitchBandwidth), /*54*/
946 GEN_CMD_CODE(_TX_Beacon), /*55*/
948 GEN_CMD_CODE(_Set_MLME_EVT), /*56*/
949 GEN_CMD_CODE(_Set_Drv_Extra), /*57*/
950 GEN_CMD_CODE(_Set_H2C_MSG), /*58*/
952 GEN_CMD_CODE(_SetChannelPlan), /*59*/
953 GEN_CMD_CODE(_LedBlink), /*60*/
955 GEN_CMD_CODE(_SetChannelSwitch), /*61*/
956 GEN_CMD_CODE(_TDLS), /*62*/
957 GEN_CMD_CODE(_ChkBMCSleepq), /*63*/
959 GEN_CMD_CODE(_RunInThreadCMD), /*64*/
964 #define _GetBBReg_CMD_ _Read_BBREG_CMD_
965 #define _SetBBReg_CMD_ _Write_BBREG_CMD_
966 #define _GetRFReg_CMD_ _Read_RFREG_CMD_
967 #define _SetRFReg_CMD_ _Write_RFREG_CMD_