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;
56 struct mutex sctx_mutex;
60 struct work_struct c2h_wk;
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 int rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj);
111 extern struct cmd_obj *rtw_dequeue_cmd(struct cmd_priv *pcmdpriv);
112 extern void rtw_free_cmd_obj(struct cmd_obj *pcmd);
114 void rtw_stop_cmd_thread(struct adapter *adapter);
115 int rtw_cmd_thread(void *context);
117 extern void rtw_free_cmd_priv(struct cmd_priv *pcmdpriv);
119 extern void rtw_free_evt_priv(struct evt_priv *pevtpriv);
120 extern void rtw_evt_notify_isr(struct evt_priv *pevtpriv);
127 POWER_SAVING_CTRL_WK_CID,/* IPS, AUTOSuspend */
132 CHECK_HIQ_WK_CID,/* for softap mode, check hi queue if empty */
135 RTP_TIMER_CFG_WK_CID,
136 RESET_SECURITYPRIV, /* add for CONFIG_IEEE80211W, none 11w also can use */
137 FREE_ASSOC_RESOURCES, /* add for CONFIG_IEEE80211W, none 11w also can use */
139 DM_RA_MSK_WK_CID, /* add for STA update RAMask when bandwidth change. */
148 LPS_CTRL_JOINBSS = 1,
149 LPS_CTRL_CONNECT = 2,
150 LPS_CTRL_DISCONNECT = 3,
151 LPS_CTRL_SPECIAL_PACKET = 4,
153 LPS_CTRL_TRAFFIC_BUSY = 6,
163 Caller Mode: Infra, Ad-HoC
165 Notes: To join a known BSS.
172 Caller Mode: Infra, Ad-Hoc
174 Notes: To join the specified bss
179 struct joinbss_parm {
180 struct wlan_bssid_ex network;
184 Caller Mode: Infra, Ad-HoC(C)
186 Notes: To disconnect the current associated BSS
191 struct disconnect_parm {
192 u32 deauth_timeout_ms;
196 Caller Mode: AP, Ad-HoC(M)
198 Notes: To create a BSS
202 struct createbss_parm {
203 struct wlan_bssid_ex network;
207 Caller Mode: AP, Ad-HoC, Infra
209 Notes: To set the NIC mode of RTL8711
213 The definition of mode:
215 #define IW_MODE_AUTO 0 Let the driver decides which AP to join
216 #define IW_MODE_ADHOC 1 Single cell network (Ad-Hoc Clients)
217 #define IW_MODE_INFRA 2 Multi cell network, roaming, ..
218 #define IW_MODE_MASTER 3 Synchronisation master or Access Point
219 #define IW_MODE_REPEAT 4 Wireless Repeater (forwarder)
220 #define IW_MODE_SECOND 5 Secondary master/repeater (backup)
221 #define IW_MODE_MONITOR 6 Passive monitor (listen only)
224 struct setopmode_parm {
230 Caller Mode: AP, Ad-HoC, Infra
232 Notes: To ask RTL8711 performing site-survey
238 #define RTW_SSID_SCAN_AMOUNT 9 /* for WEXT_CSCAN_AMOUNT 9 */
239 #define RTW_CHANNEL_SCAN_AMOUNT (14+37)
240 struct sitesurvey_parm {
241 signed int scan_mode; /* active: 1, passive: 0 */
244 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT];
245 struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
251 Notes: To set the auth type of RTL8711. open/shared/802.1x
256 struct setauth_parm {
257 u8 mode; /* 0: legacy open, 1: legacy shared 2: 802.1x */
258 u8 _1x; /* 0: PSK, 1: TLS */
265 a. algorithm: wep40, wep104, tkip & aes
266 b. keytype: grp key/unicast key
269 when shared key ==> keyid is the camid
270 when 802.1x ==> keyid [0:1] ==> grp key
271 when 802.1x ==> keyid > 2 ==> unicast key
275 u8 algorithm; /* encryption algorithm, could be none, wep40, TKIP, CCMP, wep104 */
277 u8 grpkey; /* 1: this is the grpkey for 802.1x. 0: this is the unicast key for 802.1x */
278 u8 set_tx; /* 1: main tx key for wep. 0: other key. */
279 u8 key[16]; /* this could be 40 or 104 */
283 When in AP or Ad-Hoc mode, this is used to
284 allocate an sw/hw entry for a newly associated sta.
288 when shared key ==> algorithm/keyid
291 struct set_stakey_parm {
298 struct set_stakey_rsp {
307 Command -Rsp(AID == CAMID) mode
309 This is to force fw to add an sta_data entry per driver's request.
311 FW will write an cam entry associated with it.
314 struct set_assocsta_parm {
318 struct set_assocsta_rsp {
328 This is to force fw to del an sta_data entry per driver's request
330 FW will invalidate the cam entry associated with it.
333 struct del_assocsta_parm {
338 Caller Mode: AP/Ad-HoC(M)
340 Notes: To notify fw that given staid has changed its power state
345 struct setstapwrstate_parm {
354 Notes: To setup the basic rate of RTL8711
359 struct setbasicrate_parm {
360 u8 basicrates[NumRates];
366 Notes: To read the current basic rate
371 struct getbasicrate_parm {
378 Notes: To setup the data rate of RTL8711
383 struct setdatarate_parm {
385 u8 datarates[NumRates];
391 Notes: To read the current data rate
396 struct getdatarate_parm {
403 AP: AP can use the info for the contents of beacon frame
404 Infra: STA can use the info when sitesurveying
409 Notes: To set the phy capability of the NIC
415 struct setphyinfo_parm {
416 struct regulatory_class class_sets[NUM_REGULATORYS];
420 struct getphyinfo_parm {
427 Notes: To set the channel/modem/band
428 This command will be used when channel/modem/band is changed.
441 Notes: To get the current setting of channel/modem/band
451 struct Tx_Beacon_param {
452 struct wlan_bssid_ex network;
456 Notes: This command is used for H2C/C2H loopback testing
459 ==> CMD mode, return H2C_SUCCESS.
460 The following condition must be true under CMD mode
461 mac[1] == mac[4], mac[2] == mac[3], mac[0]=mac[5]= 0;
462 s0 == 0x1234, s1 == 0xabcd, w0 == 0x78563412, w1 == 0x5aa5def7;
463 s2 == (b1 << 8 | b0);
466 ==> CMD_RSP mode, return H2C_SUCCESS_RSP
468 The rsp layout shall be:
485 ==> CMD_EVENT mode, return H2C_SUCCESS
486 The event layout shall be:
490 mac[2] = event's sequence number, starting from 1 to parm's marc[3]
494 s0 = swap16(s0) - event.mac[2];
495 s1 = s1 + event.mac[2];
498 s2 = s0 + event.mac[2]
500 w1 = swap32(w1) - event.mac[2];
502 parm->mac[3] is the total event counts that host requested.
505 event will be the same with the cmd's param.
509 /* CMD param Formart for driver extra cmd handler */
510 struct drvextra_cmd_parm {
511 int ec_id; /* extra cmd id */
512 int type; /* Can use this field as the type id or command size */
513 int size; /* buffer size */
517 /*------------------- Below are used for RF/BB tuning ---------------------*/
519 struct getcountjudge_rsp {
520 u8 count_judge[MAX_RATES_LENGTH];
523 struct addBaReq_parm {
528 /*H2C Handler index: 46 */
535 /*H2C Handler index: 59 */
536 struct SetChannelPlan_param {
540 /*H2C Handler index: 61 */
541 struct SetChannelSwitch_param {
545 /*H2C Handler index: 62 */
546 struct TDLSoption_param {
551 /*H2C Handler index: 64 */
552 struct RunInThread_param {
553 void (*func)(void *);
558 #define GEN_CMD_CODE(cmd) cmd ## _CMD_
565 0x01: success, and check Response.
566 0x02: cmd ignored due to duplicated sequcne number
567 0x03: cmd dropped due to invalid cmd code
572 #define H2C_RSP_OFFSET 512
574 #define H2C_SUCCESS 0x00
575 #define H2C_SUCCESS_RSP 0x01
576 #define H2C_DUPLICATED 0x02
577 #define H2C_DROPPED 0x03
578 #define H2C_PARAMETERS_ERROR 0x04
579 #define H2C_REJECTED 0x05
580 #define H2C_CMD_OVERFLOW 0x06
581 #define H2C_RESERVED 0x07
583 u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid, int ssid_num, struct rtw_ieee80211_channel *ch, int ch_num);
584 extern u8 rtw_createbss_cmd(struct adapter *padapter);
585 int rtw_startbss_cmd(struct adapter *padapter, int flags);
588 extern u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_key, bool enqueue);
589 extern u8 rtw_clearstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 enqueue);
591 extern u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork);
592 u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueue);
593 extern u8 rtw_setopmode_cmd(struct adapter *padapter, enum ndis_802_11_network_infrastructure networktype, bool enqueue);
594 extern u8 rtw_setdatarate_cmd(struct adapter *padapter, u8 *rateset);
595 extern u8 rtw_setrfintfs_cmd(struct adapter *padapter, u8 mode);
597 extern u8 rtw_gettssi_cmd(struct adapter *padapter, u8 offset, u8 *pval);
598 extern u8 rtw_setfwdig_cmd(struct adapter *padapter, u8 type);
599 extern u8 rtw_setfwra_cmd(struct adapter *padapter, u8 type);
601 extern u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr);
602 /* add for CONFIG_IEEE80211W, none 11w also can use */
603 extern u8 rtw_reset_securitypriv_cmd(struct adapter *padapter);
604 extern u8 rtw_free_assoc_resources_cmd(struct adapter *padapter);
605 extern u8 rtw_dynamic_chk_wk_cmd(struct adapter *adapter);
607 u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue);
608 u8 rtw_dm_in_lps_wk_cmd(struct adapter *padapter);
610 u8 rtw_dm_ra_mask_wk_cmd(struct adapter *padapter, u8 *psta);
612 extern u8 rtw_ps_cmd(struct adapter *padapter);
614 u8 rtw_chk_hi_queue_cmd(struct adapter *padapter);
616 extern u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue, u8 swconfig);
618 extern u8 rtw_c2h_packet_wk_cmd(struct adapter *padapter, u8 *pbuf, u16 length);
619 extern u8 rtw_c2h_wk_cmd(struct adapter *padapter, u8 *c2h_evt);
621 u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf);
623 extern void rtw_survey_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
624 extern void rtw_disassoc_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
625 extern void rtw_joinbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
626 extern void rtw_createbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd);
627 extern void rtw_getbbrfreg_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
629 extern void rtw_setstaKey_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
630 extern void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
631 extern void rtw_getrttbl_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd);
634 struct _cmd_callback {
636 void (*callback)(struct adapter *padapter, struct cmd_obj *cmd);
640 GEN_CMD_CODE(_Read_MACREG), /*0*/
641 GEN_CMD_CODE(_Write_MACREG),
642 GEN_CMD_CODE(_Read_BBREG),
643 GEN_CMD_CODE(_Write_BBREG),
644 GEN_CMD_CODE(_Read_RFREG),
645 GEN_CMD_CODE(_Write_RFREG), /*5*/
646 GEN_CMD_CODE(_Read_EEPROM),
647 GEN_CMD_CODE(_Write_EEPROM),
648 GEN_CMD_CODE(_Read_EFUSE),
649 GEN_CMD_CODE(_Write_EFUSE),
651 GEN_CMD_CODE(_Read_CAM), /*10*/
652 GEN_CMD_CODE(_Write_CAM),
653 GEN_CMD_CODE(_setBCNITV),
654 GEN_CMD_CODE(_setMBIDCFG),
655 GEN_CMD_CODE(_JoinBss), /*14*/
656 GEN_CMD_CODE(_DisConnect), /*15*/
657 GEN_CMD_CODE(_CreateBss),
658 GEN_CMD_CODE(_SetOpMode),
659 GEN_CMD_CODE(_SiteSurvey), /*18*/
660 GEN_CMD_CODE(_SetAuth),
662 GEN_CMD_CODE(_SetKey), /*20*/
663 GEN_CMD_CODE(_SetStaKey),
664 GEN_CMD_CODE(_SetAssocSta),
665 GEN_CMD_CODE(_DelAssocSta),
666 GEN_CMD_CODE(_SetStaPwrState),
667 GEN_CMD_CODE(_SetBasicRate), /*25*/
668 GEN_CMD_CODE(_GetBasicRate),
669 GEN_CMD_CODE(_SetDataRate),
670 GEN_CMD_CODE(_GetDataRate),
671 GEN_CMD_CODE(_SetPhyInfo),
673 GEN_CMD_CODE(_GetPhyInfo), /*30*/
674 GEN_CMD_CODE(_SetPhy),
675 GEN_CMD_CODE(_GetPhy),
676 GEN_CMD_CODE(_readRssi),
677 GEN_CMD_CODE(_readGain),
678 GEN_CMD_CODE(_SetAtim), /*35*/
679 GEN_CMD_CODE(_SetPwrMode),
680 GEN_CMD_CODE(_JoinbssRpt),
681 GEN_CMD_CODE(_SetRaTable),
682 GEN_CMD_CODE(_GetRaTable),
684 GEN_CMD_CODE(_GetCCXReport), /*40*/
685 GEN_CMD_CODE(_GetDTMReport),
686 GEN_CMD_CODE(_GetTXRateStatistics),
687 GEN_CMD_CODE(_SetUsbSuspend),
688 GEN_CMD_CODE(_SetH2cLbk),
689 GEN_CMD_CODE(_AddBAReq), /*45*/
690 GEN_CMD_CODE(_SetChannel), /*46*/
691 GEN_CMD_CODE(_SetTxPower),
692 GEN_CMD_CODE(_SwitchAntenna),
693 GEN_CMD_CODE(_SetCrystalCap),
694 GEN_CMD_CODE(_SetSingleCarrierTx), /*50*/
696 GEN_CMD_CODE(_SetSingleToneTx),/*51*/
697 GEN_CMD_CODE(_SetCarrierSuppressionTx),
698 GEN_CMD_CODE(_SetContinuousTx),
699 GEN_CMD_CODE(_SwitchBandwidth), /*54*/
700 GEN_CMD_CODE(_TX_Beacon), /*55*/
702 GEN_CMD_CODE(_Set_MLME_EVT), /*56*/
703 GEN_CMD_CODE(_Set_Drv_Extra), /*57*/
704 GEN_CMD_CODE(_Set_H2C_MSG), /*58*/
706 GEN_CMD_CODE(_SetChannelPlan), /*59*/
708 GEN_CMD_CODE(_SetChannelSwitch), /*60*/
709 GEN_CMD_CODE(_TDLS), /*61*/
710 GEN_CMD_CODE(_ChkBMCSleepq), /*62*/
712 GEN_CMD_CODE(_RunInThreadCMD), /*63*/
717 #define _GetBBReg_CMD_ _Read_BBREG_CMD_
718 #define _SetBBReg_CMD_ _Write_BBREG_CMD_
719 #define _GetRFReg_CMD_ _Read_RFREG_CMD_
720 #define _SetRFReg_CMD_ _Write_RFREG_CMD_