1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /****************************************************************************** 3 * 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * 6 * Modifications for inclusion into the Linux staging tree are 7 * Copyright(c) 2010 Larry Finger. All rights reserved. 8 * 9 * Contact information: 10 * WLAN FAE <wlanfae@realtek.com> 11 * Larry Finger <Larry.Finger@lwfinger.net> 12 * 13 ******************************************************************************/ 14 #ifndef __RTL871X_CMD_H_ 15 #define __RTL871X_CMD_H_ 16 17 #include "wlan_bssdef.h" 18 #include "rtl871x_rf.h" 19 #define C2H_MEM_SZ (16*1024) 20 21 #include "osdep_service.h" 22 #include "ieee80211.h" 23 24 #define FREE_CMDOBJ_SZ 128 25 #define MAX_CMDSZ 512 26 #define MAX_RSPSZ 512 27 #define MAX_EVTSZ 1024 28 #define CMDBUFF_ALIGN_SZ 512 29 30 struct cmd_obj { 31 u16 cmdcode; 32 u8 res; 33 u8 *parmbuf; 34 u32 cmdsz; 35 u8 *rsp; 36 u32 rspsz; 37 struct list_head list; 38 }; 39 40 struct cmd_priv { 41 struct completion cmd_queue_comp; 42 struct completion terminate_cmdthread_comp; 43 struct __queue cmd_queue; 44 u8 cmd_seq; 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; 49 u32 cmd_issued_cnt; 50 u32 cmd_done_cnt; 51 u32 rsp_cnt; 52 struct _adapter *padapter; 53 }; 54 55 struct evt_obj { 56 u16 evtcode; 57 u8 res; 58 u8 *parmbuf; 59 u32 evtsz; 60 struct list_head list; 61 }; 62 63 struct evt_priv { 64 struct __queue evt_queue; 65 u8 event_seq; 66 u8 *evt_buf; /*shall be non-paged, and 4 bytes aligned*/ 67 u8 *evt_allocated_buf; 68 u32 evt_done_cnt; 69 }; 70 71 #define init_h2fwcmd_w_parm_no_rsp(pcmd, pparm, code) \ 72 do {\ 73 INIT_LIST_HEAD(&pcmd->list);\ 74 pcmd->cmdcode = code;\ 75 pcmd->parmbuf = (u8 *)(pparm);\ 76 pcmd->cmdsz = sizeof(*pparm);\ 77 pcmd->rsp = NULL;\ 78 pcmd->rspsz = 0;\ 79 } while (0) 80 81 void r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj); 82 void r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct cmd_obj *obj); 83 struct cmd_obj *r8712_dequeue_cmd(struct __queue *queue); 84 void r8712_free_cmd_obj(struct cmd_obj *pcmd); 85 int r8712_cmd_thread(void *context); 86 int r8712_init_cmd_priv(struct cmd_priv *pcmdpriv); 87 void r8712_free_cmd_priv(struct cmd_priv *pcmdpriv); 88 int r8712_init_evt_priv(struct evt_priv *pevtpriv); 89 void r8712_free_evt_priv(struct evt_priv *pevtpriv); 90 91 enum rtl871x_drvint_cid { 92 NONE_WK_CID, 93 WDG_WK_CID, 94 MAX_WK_CID 95 }; 96 97 enum RFINTFS { 98 SWSI, 99 HWSI, 100 HWPI, 101 }; 102 103 /* 104 * Caller Mode: Infra, Ad-HoC(C) 105 * Notes: To enter USB suspend mode 106 * Command Mode 107 */ 108 struct usb_suspend_parm { 109 u32 action; /* 1: sleep, 0:resume */ 110 }; 111 112 /* 113 * Caller Mode: Infra, Ad-HoC(C) 114 * Notes: To disconnect the current associated BSS 115 * Command Mode 116 */ 117 struct disconnect_parm { 118 u32 rsvd; 119 }; 120 121 /* 122 * Caller Mode: AP, Ad-HoC, Infra 123 * Notes: To set the NIC mode of RTL8711 124 * Command Mode 125 * The definition of mode: 126 * 127 * #define IW_MODE_AUTO 0 // Let the driver decides which AP to join 128 * #define IW_MODE_ADHOC 1 // Single cell network (Ad-Hoc Clients) 129 * #define IW_MODE_INFRA 2 // Multi cell network, roaming, .. 130 * #define IW_MODE_MASTER 3 // Synchronisation master or AP 131 * #define IW_MODE_REPEAT 4 // Wireless Repeater (forwarder) 132 * #define IW_MODE_SECOND 5 // Secondary master/repeater (backup) 133 * #define IW_MODE_MONITOR 6 // Passive monitor (listen only) 134 */ 135 struct setopmode_parm { 136 u8 mode; 137 u8 rsvd[3]; 138 }; 139 140 /* 141 * Caller Mode: AP, Ad-HoC, Infra 142 * Notes: To ask RTL8711 performing site-survey 143 * Command-Event Mode 144 */ 145 struct sitesurvey_parm { 146 __le32 passive_mode; /*active: 1, passive: 0 */ 147 __le32 bsslimit; /* 1 ~ 48 */ 148 __le32 ss_ssidlen; 149 u8 ss_ssid[IW_ESSID_MAX_SIZE + 1]; 150 }; 151 152 /* 153 * Caller Mode: Any 154 * Notes: To set the auth type of RTL8711. open/shared/802.1x 155 * Command Mode 156 */ 157 struct setauth_parm { 158 u8 mode; /*0: legacy open, 1: legacy shared 2: 802.1x*/ 159 u8 _1x; /*0: PSK, 1: TLS*/ 160 u8 rsvd[2]; 161 }; 162 163 /* 164 * Caller Mode: Infra 165 * a. algorithm: wep40, wep104, tkip & aes 166 * b. keytype: grp key/unicast key 167 * c. key contents 168 * 169 * when shared key ==> keyid is the camid 170 * when 802.1x ==> keyid [0:1] ==> grp key 171 * when 802.1x ==> keyid > 2 ==> unicast key 172 */ 173 struct setkey_parm { 174 u8 algorithm; /* encryption algorithm, could be none, wep40, 175 * TKIP, CCMP, wep104 176 */ 177 u8 keyid; 178 u8 grpkey; /* 1: this is the grpkey for 802.1x. 179 * 0: this is the unicast key for 802.1x 180 */ 181 u8 key[16]; /* this could be 40 or 104 */ 182 }; 183 184 /* 185 * When in AP or Ad-Hoc mode, this is used to 186 * allocate an sw/hw entry for a newly associated sta. 187 * Command 188 * when shared key ==> algorithm/keyid 189 */ 190 struct set_stakey_parm { 191 u8 addr[ETH_ALEN]; 192 u8 algorithm; 193 u8 key[16]; 194 }; 195 196 struct set_stakey_rsp { 197 u8 addr[ETH_ALEN]; 198 u8 keyid; 199 u8 rsvd; 200 }; 201 202 struct SetMacAddr_param { 203 u8 MacAddr[ETH_ALEN]; 204 }; 205 206 /* 207 * Caller Ad-Hoc/AP 208 * 209 * Command -Rsp(AID == CAMID) mode 210 * 211 * This is to force fw to add an sta_data entry per driver's request. 212 * 213 * FW will write an cam entry associated with it. 214 * 215 */ 216 struct set_assocsta_parm { 217 u8 addr[ETH_ALEN]; 218 }; 219 220 struct set_assocsta_rsp { 221 u8 cam_id; 222 u8 rsvd[3]; 223 }; 224 225 /* 226 * Caller Ad-Hoc/AP 227 * 228 * Command mode 229 * 230 * This is to force fw to del an sta_data entry per driver's request 231 * 232 * FW will invalidate the cam entry associated with it. 233 * 234 */ 235 struct del_assocsta_parm { 236 u8 addr[ETH_ALEN]; 237 }; 238 239 /* 240 * Caller Mode: AP/Ad-HoC(M) 241 * 242 * Notes: To notify fw that given staid has changed its power state 243 * 244 * Command Mode 245 * 246 */ 247 struct setstapwrstate_parm { 248 u8 staid; 249 u8 status; 250 u8 hwaddr[6]; 251 }; 252 253 /* 254 * Caller Mode: Any 255 * 256 * Notes: To setup the basic rate of RTL8711 257 * 258 * Command Mode 259 * 260 */ 261 struct setbasicrate_parm { 262 u8 basicrates[NumRates]; 263 }; 264 265 /* 266 * Caller Mode: Any 267 * 268 * Notes: To read the current basic rate 269 * 270 * Command-Rsp Mode 271 * 272 */ 273 struct getbasicrate_parm { 274 u32 rsvd; 275 }; 276 277 struct getbasicrate_rsp { 278 u8 basicrates[NumRates]; 279 }; 280 281 /* 282 * Caller Mode: Any 283 * 284 * Notes: To setup the data rate of RTL8711 285 * 286 * Command Mode 287 * 288 */ 289 struct setdatarate_parm { 290 u8 mac_id; 291 u8 datarates[NumRates]; 292 }; 293 294 enum _RT_CHANNEL_DOMAIN { 295 RT_CHANNEL_DOMAIN_FCC = 0, 296 RT_CHANNEL_DOMAIN_IC = 1, 297 RT_CHANNEL_DOMAIN_ETSI = 2, 298 RT_CHANNEL_DOMAIN_SPAIN = 3, 299 RT_CHANNEL_DOMAIN_FRANCE = 4, 300 RT_CHANNEL_DOMAIN_MKK = 5, 301 RT_CHANNEL_DOMAIN_MKK1 = 6, 302 RT_CHANNEL_DOMAIN_ISRAEL = 7, 303 RT_CHANNEL_DOMAIN_TELEC = 8, 304 305 /* Be compatible with old channel plan. No good! */ 306 RT_CHANNEL_DOMAIN_MIC = 9, 307 RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN = 10, 308 RT_CHANNEL_DOMAIN_WORLD_WIDE_13 = 11, 309 RT_CHANNEL_DOMAIN_TELEC_NETGEAR = 12, 310 311 RT_CHANNEL_DOMAIN_NCC = 13, 312 RT_CHANNEL_DOMAIN_5G = 14, 313 RT_CHANNEL_DOMAIN_5G_40M = 15, 314 /*===== Add new channel plan above this line===============*/ 315 RT_CHANNEL_DOMAIN_MAX, 316 }; 317 318 struct SetChannelPlan_param { 319 enum _RT_CHANNEL_DOMAIN ChannelPlan; 320 }; 321 322 /* 323 * Caller Mode: Any 324 * 325 * Notes: To read the current data rate 326 * 327 * Command-Rsp Mode 328 * 329 */ 330 struct getdatarate_parm { 331 u32 rsvd; 332 333 }; 334 335 struct getdatarate_rsp { 336 u8 datarates[NumRates]; 337 }; 338 339 /* 340 * Caller Mode: Any 341 * AP: AP can use the info for the contents of beacon frame 342 * Infra: STA can use the info when sitesurveying 343 * Ad-HoC(M): Like AP 344 * Ad-HoC(C): Like STA 345 * 346 * 347 * Notes: To set the phy capability of the NIC 348 * 349 * Command Mode 350 * 351 */ 352 353 /* 354 * Caller Mode: Any 355 * 356 * Notes: To set the channel/modem/band 357 * This command will be used when channel/modem/band is changed. 358 * 359 * Command Mode 360 * 361 */ 362 /* 363 * Caller Mode: Any 364 * 365 * Notes: To get the current setting of channel/modem/band 366 * 367 * Command-Rsp Mode 368 * 369 */ 370 struct getphy_rsp { 371 u8 rfchannel; 372 u8 modem; 373 }; 374 375 struct readBB_parm { 376 u8 offset; 377 }; 378 379 struct readBB_rsp { 380 u8 value; 381 }; 382 383 struct readTSSI_parm { 384 u8 offset; 385 }; 386 387 struct readTSSI_rsp { 388 u8 value; 389 }; 390 391 struct writeBB_parm { 392 u8 offset; 393 u8 value; 394 }; 395 396 struct writePTM_parm { 397 u8 type; 398 }; 399 400 struct readRF_parm { 401 u8 offset; 402 }; 403 404 struct readRF_rsp { 405 u32 value; 406 }; 407 408 struct writeRF_parm { 409 u32 offset; 410 u32 value; 411 }; 412 413 struct setrfintfs_parm { 414 u8 rfintfs; 415 }; 416 417 struct getrfintfs_parm { 418 u8 rfintfs; 419 }; 420 421 /* 422 * Notes: This command is used for H2C/C2H loopback testing 423 * 424 * mac[0] == 0 425 * ==> CMD mode, return H2C_SUCCESS. 426 * The following condition must be true under CMD mode 427 * mac[1] == mac[4], mac[2] == mac[3], mac[0]=mac[5]= 0; 428 * s0 == 0x1234, s1 == 0xabcd, w0 == 0x78563412, w1 == 0x5aa5def7; 429 * s2 == (b1 << 8 | b0); 430 * 431 * mac[0] == 1 432 * ==> CMD_RSP mode, return H2C_SUCCESS_RSP 433 * 434 * The rsp layout shall be: 435 * rsp: parm: 436 * mac[0] = mac[5]; 437 * mac[1] = mac[4]; 438 * mac[2] = mac[3]; 439 * mac[3] = mac[2]; 440 * mac[4] = mac[1]; 441 * mac[5] = mac[0]; 442 * s0 = s1; 443 * s1 = swap16(s0); 444 * w0 = swap32(w1); 445 * b0 = b1 446 * s2 = s0 + s1 447 * b1 = b0 448 * w1 = w0 449 * 450 * mac[0] == 2 451 * ==> CMD_EVENT mode, return H2C_SUCCESS 452 * The event layout shall be: 453 * event: parm: 454 * mac[0] = mac[5]; 455 * mac[1] = mac[4]; 456 * mac[2] = event's sequence number, starting from 1 to parm's marc[3] 457 * mac[3] = mac[2]; 458 * mac[4] = mac[1]; 459 * mac[5] = mac[0]; 460 * s0 = swap16(s0) - event.mac[2]; 461 * s1 = s1 + event.mac[2]; 462 * w0 = swap32(w0); 463 * b0 = b1 464 * s2 = s0 + event.mac[2] 465 * b1 = b0 466 * w1 = swap32(w1) - event.mac[2]; 467 * 468 * parm->mac[3] is the total event counts that host requested. 469 * 470 * 471 * event will be the same with the cmd's param. 472 * 473 */ 474 475 /* CMD param Formart for DRV INTERNAL CMD HDL*/ 476 struct drvint_cmd_parm { 477 int i_cid; /*internal cmd id*/ 478 int sz; /* buf sz*/ 479 unsigned char *pbuf; 480 }; 481 482 /*------------------- Below are used for RF/BB tuning ---------------------*/ 483 484 struct setantenna_parm { 485 u8 tx_antset; 486 u8 rx_antset; 487 u8 tx_antenna; 488 u8 rx_antenna; 489 }; 490 491 struct enrateadaptive_parm { 492 u32 en; 493 }; 494 495 struct settxagctbl_parm { 496 u32 txagc[MAX_RATES_LENGTH]; 497 }; 498 499 struct gettxagctbl_parm { 500 u32 rsvd; 501 }; 502 503 struct gettxagctbl_rsp { 504 u32 txagc[MAX_RATES_LENGTH]; 505 }; 506 507 struct setagcctrl_parm { 508 u32 agcctrl; /* 0: pure hw, 1: fw */ 509 }; 510 511 struct setssup_parm { 512 u32 ss_ForceUp[MAX_RATES_LENGTH]; 513 }; 514 515 struct getssup_parm { 516 u32 rsvd; 517 }; 518 519 struct getssup_rsp { 520 u8 ss_ForceUp[MAX_RATES_LENGTH]; 521 }; 522 523 struct setssdlevel_parm { 524 u8 ss_DLevel[MAX_RATES_LENGTH]; 525 }; 526 527 struct getssdlevel_parm { 528 u32 rsvd; 529 }; 530 531 struct getssdlevel_rsp { 532 u8 ss_DLevel[MAX_RATES_LENGTH]; 533 }; 534 535 struct setssulevel_parm { 536 u8 ss_ULevel[MAX_RATES_LENGTH]; 537 }; 538 539 struct getssulevel_parm { 540 u32 rsvd; 541 }; 542 543 struct getssulevel_rsp { 544 u8 ss_ULevel[MAX_RATES_LENGTH]; 545 }; 546 547 struct setcountjudge_parm { 548 u8 count_judge[MAX_RATES_LENGTH]; 549 }; 550 551 struct getcountjudge_parm { 552 u32 rsvd; 553 }; 554 555 struct getcountjudge_rsp { 556 u8 count_judge[MAX_RATES_LENGTH]; 557 }; 558 559 struct setpwrmode_parm { 560 u8 mode; 561 u8 flag_low_traffic_en; 562 u8 flag_lpnav_en; 563 u8 flag_rf_low_snr_en; 564 u8 flag_dps_en; /* 1: dps, 0: 32k */ 565 u8 bcn_rx_en; 566 u8 bcn_pass_cnt; /* fw report one beacon information to 567 * driver when it receives bcn_pass_cnt 568 * beacons. 569 */ 570 u8 bcn_to; /* beacon TO (ms). ¡§=0¡¨ no limit.*/ 571 u16 bcn_itv; 572 u8 app_itv; /* only for VOIP mode. */ 573 u8 awake_bcn_itv; 574 u8 smart_ps; 575 u8 bcn_pass_time; /* unit: 100ms */ 576 }; 577 578 struct setatim_parm { 579 u8 op; /*0: add, 1:del*/ 580 u8 txid; /* id of dest station.*/ 581 }; 582 583 struct setratable_parm { 584 u8 ss_ForceUp[NumRates]; 585 u8 ss_ULevel[NumRates]; 586 u8 ss_DLevel[NumRates]; 587 u8 count_judge[NumRates]; 588 }; 589 590 struct getratable_parm { 591 uint rsvd; 592 }; 593 594 struct getratable_rsp { 595 u8 ss_ForceUp[NumRates]; 596 u8 ss_ULevel[NumRates]; 597 u8 ss_DLevel[NumRates]; 598 u8 count_judge[NumRates]; 599 }; 600 601 /*to get TX,RX retry count*/ 602 struct gettxretrycnt_parm { 603 unsigned int rsvd; 604 }; 605 606 struct gettxretrycnt_rsp { 607 unsigned long tx_retrycnt; 608 }; 609 610 struct getrxretrycnt_parm { 611 unsigned int rsvd; 612 }; 613 614 struct getrxretrycnt_rsp { 615 unsigned long rx_retrycnt; 616 }; 617 618 /*to get BCNOK,BCNERR count*/ 619 struct getbcnokcnt_parm { 620 unsigned int rsvd; 621 }; 622 623 struct getbcnokcnt_rsp { 624 unsigned long bcnokcnt; 625 }; 626 627 struct getbcnerrcnt_parm { 628 unsigned int rsvd; 629 }; 630 631 struct getbcnerrcnt_rsp { 632 unsigned long bcnerrcnt; 633 }; 634 635 /* to get current TX power level*/ 636 struct getcurtxpwrlevel_parm { 637 unsigned int rsvd; 638 }; 639 640 struct getcurtxpwrlevel_rsp { 641 unsigned short tx_power; 642 }; 643 644 /*dynamic on/off DIG*/ 645 struct setdig_parm { 646 unsigned char dig_on; /* 1:on , 0:off */ 647 }; 648 649 /*dynamic on/off RA*/ 650 struct setra_parm { 651 unsigned char ra_on; /* 1:on , 0:off */ 652 }; 653 654 struct setprobereqextraie_parm { 655 unsigned char e_id; 656 unsigned char ie_len; 657 unsigned char ie[]; 658 }; 659 660 struct setassocreqextraie_parm { 661 unsigned char e_id; 662 unsigned char ie_len; 663 unsigned char ie[]; 664 }; 665 666 struct setproberspextraie_parm { 667 unsigned char e_id; 668 unsigned char ie_len; 669 unsigned char ie[]; 670 }; 671 672 struct setassocrspextraie_parm { 673 unsigned char e_id; 674 unsigned char ie_len; 675 unsigned char ie[]; 676 }; 677 678 struct addBaReq_parm { 679 unsigned int tid; 680 }; 681 682 /*H2C Handler index: 46 */ 683 struct SetChannel_parm { 684 u32 curr_ch; 685 }; 686 687 /*H2C Handler index: 61 */ 688 struct DisconnectCtrlEx_param { 689 /* MAXTIME = (2 * FirstStageTO) + (TryPktCnt * TryPktInterval) */ 690 unsigned char EnableDrvCtrl; 691 unsigned char TryPktCnt; 692 unsigned char TryPktInterval; /* Unit: ms */ 693 unsigned char rsvd; 694 unsigned int FirstStageTO; /* Unit: ms */ 695 }; 696 697 #define GEN_CMD_CODE(cmd) cmd ## _CMD_ 698 699 /* 700 * Result: 701 * 0x00: success 702 * 0x01: success, and check Response. 703 * 0x02: cmd ignored due to duplicated sequence number 704 * 0x03: cmd dropped due to invalid cmd code 705 * 0x04: reserved. 706 */ 707 708 #define H2C_RSP_OFFSET 512 709 #define H2C_SUCCESS 0x00 710 #define H2C_SUCCESS_RSP 0x01 711 #define H2C_DUPLICATED 0x02 712 #define H2C_DROPPED 0x03 713 #define H2C_PARAMETERS_ERROR 0x04 714 #define H2C_REJECTED 0x05 715 #define H2C_CMD_OVERFLOW 0x06 716 #define H2C_RESERVED 0x07 717 718 void r8712_setMacAddr_cmd(struct _adapter *padapter, const u8 *mac_addr); 719 u8 r8712_sitesurvey_cmd(struct _adapter *padapter, struct ndis_802_11_ssid *pssid); 720 int r8712_createbss_cmd(struct _adapter *padapter); 721 void r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key); 722 int r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork); 723 void r8712_disassoc_cmd(struct _adapter *padapter); 724 void r8712_setopmode_cmd(struct _adapter *padapter, enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype); 725 int r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset); 726 void r8712_set_chplan_cmd(struct _adapter *padapter, int chplan); 727 int r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval); 728 int r8712_setrfreg_cmd(struct _adapter *padapter, u8 offset, u32 val); 729 void r8712_addbareq_cmd(struct _adapter *padapter, u8 tid); 730 void r8712_wdg_wk_cmd(struct _adapter *padapter); 731 void r8712_survey_cmd_callback(struct _adapter *padapter, struct cmd_obj *pcmd); 732 void r8712_disassoc_cmd_callback(struct _adapter *padapter, struct cmd_obj *pcmd); 733 void r8712_joinbss_cmd_callback(struct _adapter *padapter, struct cmd_obj *pcmd); 734 void r8712_createbss_cmd_callback(struct _adapter *padapter, struct cmd_obj *pcmd); 735 void r8712_getbbrfreg_cmdrsp_callback(struct _adapter *padapter, struct cmd_obj *pcmd); 736 void r8712_readtssi_cmdrsp_callback(struct _adapter *padapter, struct cmd_obj *pcmd); 737 void r8712_setstaKey_cmdrsp_callback(struct _adapter *padapter, struct cmd_obj *pcmd); 738 void r8712_setassocsta_cmdrsp_callback(struct _adapter *padapter, struct cmd_obj *pcmd); 739 void r8712_disconnectCtrlEx_cmd(struct _adapter *adapter, u32 enableDrvCtrl, u32 tryPktCnt, 740 u32 tryPktInterval, u32 firstStageTO); 741 742 struct _cmd_callback { 743 u32 cmd_code; 744 void (*callback)(struct _adapter *padapter, struct cmd_obj *cmd); 745 }; 746 747 #include "rtl8712_cmd.h" 748 749 #endif /* _CMD_H_ */ 750 751