123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136 |
- /*
- * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
- #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
- #include <linux/etherdevice.h>
- #include <linux/firmware.h>
- #include <linux/bitops.h>
- #include "smd.h"
- static int put_cfg_tlv_u32(struct wcn36xx *wcn, size_t *len, u32 id, u32 value)
- {
- struct wcn36xx_hal_cfg *entry;
- u32 *val;
- if (*len + sizeof(*entry) + sizeof(u32) >= WCN36XX_HAL_BUF_SIZE) {
- wcn36xx_err("Not enough room for TLV entry\n");
- return -ENOMEM;
- }
- entry = (struct wcn36xx_hal_cfg *) (wcn->hal_buf + *len);
- entry->id = id;
- entry->len = sizeof(u32);
- entry->pad_bytes = 0;
- entry->reserve = 0;
- val = (u32 *) (entry + 1);
- *val = value;
- *len += sizeof(*entry) + sizeof(u32);
- return 0;
- }
- static void wcn36xx_smd_set_bss_nw_type(struct wcn36xx *wcn,
- struct ieee80211_sta *sta,
- struct wcn36xx_hal_config_bss_params *bss_params)
- {
- if (IEEE80211_BAND_5GHZ == WCN36XX_BAND(wcn))
- bss_params->nw_type = WCN36XX_HAL_11A_NW_TYPE;
- else if (sta && sta->ht_cap.ht_supported)
- bss_params->nw_type = WCN36XX_HAL_11N_NW_TYPE;
- else if (sta && (sta->supp_rates[IEEE80211_BAND_2GHZ] & 0x7f))
- bss_params->nw_type = WCN36XX_HAL_11G_NW_TYPE;
- else
- bss_params->nw_type = WCN36XX_HAL_11B_NW_TYPE;
- }
- static inline u8 is_cap_supported(unsigned long caps, unsigned long flag)
- {
- return caps & flag ? 1 : 0;
- }
- static void wcn36xx_smd_set_bss_ht_params(struct ieee80211_vif *vif,
- struct ieee80211_sta *sta,
- struct wcn36xx_hal_config_bss_params *bss_params)
- {
- if (sta && sta->ht_cap.ht_supported) {
- unsigned long caps = sta->ht_cap.cap;
- bss_params->ht = sta->ht_cap.ht_supported;
- bss_params->tx_channel_width_set = is_cap_supported(caps,
- IEEE80211_HT_CAP_SUP_WIDTH_20_40);
- bss_params->lsig_tx_op_protection_full_support =
- is_cap_supported(caps,
- IEEE80211_HT_CAP_LSIG_TXOP_PROT);
- bss_params->ht_oper_mode = vif->bss_conf.ht_operation_mode;
- bss_params->lln_non_gf_coexist =
- !!(vif->bss_conf.ht_operation_mode &
- IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
- /* IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT */
- bss_params->dual_cts_protection = 0;
- /* IEEE80211_HT_OP_MODE_PROTECTION_20MHZ */
- bss_params->ht20_coexist = 0;
- }
- }
- static void wcn36xx_smd_set_sta_ht_params(struct ieee80211_sta *sta,
- struct wcn36xx_hal_config_sta_params *sta_params)
- {
- if (sta->ht_cap.ht_supported) {
- unsigned long caps = sta->ht_cap.cap;
- sta_params->ht_capable = sta->ht_cap.ht_supported;
- sta_params->tx_channel_width_set = is_cap_supported(caps,
- IEEE80211_HT_CAP_SUP_WIDTH_20_40);
- sta_params->lsig_txop_protection = is_cap_supported(caps,
- IEEE80211_HT_CAP_LSIG_TXOP_PROT);
- sta_params->max_ampdu_size = sta->ht_cap.ampdu_factor;
- sta_params->max_ampdu_density = sta->ht_cap.ampdu_density;
- sta_params->max_amsdu_size = is_cap_supported(caps,
- IEEE80211_HT_CAP_MAX_AMSDU);
- sta_params->sgi_20Mhz = is_cap_supported(caps,
- IEEE80211_HT_CAP_SGI_20);
- sta_params->sgi_40mhz = is_cap_supported(caps,
- IEEE80211_HT_CAP_SGI_40);
- sta_params->green_field_capable = is_cap_supported(caps,
- IEEE80211_HT_CAP_GRN_FLD);
- sta_params->delayed_ba_support = is_cap_supported(caps,
- IEEE80211_HT_CAP_DELAY_BA);
- sta_params->dsss_cck_mode_40mhz = is_cap_supported(caps,
- IEEE80211_HT_CAP_DSSSCCK40);
- }
- }
- static void wcn36xx_smd_set_sta_params(struct wcn36xx *wcn,
- struct ieee80211_vif *vif,
- struct ieee80211_sta *sta,
- struct wcn36xx_hal_config_sta_params *sta_params)
- {
- struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
- struct wcn36xx_sta *priv_sta = NULL;
- if (vif->type == NL80211_IFTYPE_ADHOC ||
- vif->type == NL80211_IFTYPE_AP ||
- vif->type == NL80211_IFTYPE_MESH_POINT) {
- sta_params->type = 1;
- sta_params->sta_index = 0xFF;
- } else {
- sta_params->type = 0;
- sta_params->sta_index = 1;
- }
- sta_params->listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
- /*
- * In STA mode ieee80211_sta contains bssid and ieee80211_vif
- * contains our mac address. In AP mode we are bssid so vif
- * contains bssid and ieee80211_sta contains mac.
- */
- if (NL80211_IFTYPE_STATION == vif->type)
- memcpy(&sta_params->mac, vif->addr, ETH_ALEN);
- else
- memcpy(&sta_params->bssid, vif->addr, ETH_ALEN);
- sta_params->encrypt_type = priv_vif->encrypt_type;
- sta_params->short_preamble_supported =
- !(WCN36XX_FLAGS(wcn) &
- IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE);
- sta_params->rifs_mode = 0;
- sta_params->rmf = 0;
- sta_params->action = 0;
- sta_params->uapsd = 0;
- sta_params->mimo_ps = WCN36XX_HAL_HT_MIMO_PS_STATIC;
- sta_params->max_ampdu_duration = 0;
- sta_params->bssid_index = priv_vif->bss_index;
- sta_params->p2p = 0;
- if (sta) {
- priv_sta = (struct wcn36xx_sta *)sta->drv_priv;
- if (NL80211_IFTYPE_STATION == vif->type)
- memcpy(&sta_params->bssid, sta->addr, ETH_ALEN);
- else
- memcpy(&sta_params->mac, sta->addr, ETH_ALEN);
- sta_params->wmm_enabled = sta->wme;
- sta_params->max_sp_len = sta->max_sp;
- sta_params->aid = priv_sta->aid;
- wcn36xx_smd_set_sta_ht_params(sta, sta_params);
- memcpy(&sta_params->supported_rates, &priv_sta->supported_rates,
- sizeof(priv_sta->supported_rates));
- } else {
- wcn36xx_set_default_rates(&sta_params->supported_rates);
- }
- }
- static int wcn36xx_smd_send_and_wait(struct wcn36xx *wcn, size_t len)
- {
- int ret = 0;
- wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "HAL >>> ", wcn->hal_buf, len);
- init_completion(&wcn->hal_rsp_compl);
- ret = wcn->ctrl_ops->tx(wcn->hal_buf, len);
- if (ret) {
- wcn36xx_err("HAL TX failed\n");
- goto out;
- }
- if (wait_for_completion_timeout(&wcn->hal_rsp_compl,
- msecs_to_jiffies(HAL_MSG_TIMEOUT)) <= 0) {
- wcn36xx_err("Timeout while waiting SMD response\n");
- ret = -ETIME;
- goto out;
- }
- out:
- return ret;
- }
- #define INIT_HAL_MSG(msg_body, type) \
- do { \
- memset(&msg_body, 0, sizeof(msg_body)); \
- msg_body.header.msg_type = type; \
- msg_body.header.msg_version = WCN36XX_HAL_MSG_VERSION0; \
- msg_body.header.len = sizeof(msg_body); \
- } while (0) \
- #define PREPARE_HAL_BUF(send_buf, msg_body) \
- do { \
- memset(send_buf, 0, msg_body.header.len); \
- memcpy(send_buf, &msg_body, sizeof(msg_body)); \
- } while (0) \
- static int wcn36xx_smd_rsp_status_check(void *buf, size_t len)
- {
- struct wcn36xx_fw_msg_status_rsp *rsp;
- if (len < sizeof(struct wcn36xx_hal_msg_header) +
- sizeof(struct wcn36xx_fw_msg_status_rsp))
- return -EIO;
- rsp = (struct wcn36xx_fw_msg_status_rsp *)
- (buf + sizeof(struct wcn36xx_hal_msg_header));
- if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status)
- return rsp->status;
- return 0;
- }
- int wcn36xx_smd_load_nv(struct wcn36xx *wcn)
- {
- const struct firmware *nv;
- struct nv_data *nv_d;
- struct wcn36xx_hal_nv_img_download_req_msg msg_body;
- int fw_bytes_left;
- int ret;
- u16 fm_offset = 0;
- ret = request_firmware(&nv, WLAN_NV_FILE, wcn->dev);
- if (ret) {
- wcn36xx_err("Failed to load nv file %s: %d\n",
- WLAN_NV_FILE, ret);
- goto out_free_nv;
- }
- nv_d = (struct nv_data *)nv->data;
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_DOWNLOAD_NV_REQ);
- msg_body.header.len += WCN36XX_NV_FRAGMENT_SIZE;
- msg_body.frag_number = 0;
- /* hal_buf must be protected with mutex */
- mutex_lock(&wcn->hal_mutex);
- do {
- fw_bytes_left = nv->size - fm_offset - 4;
- if (fw_bytes_left > WCN36XX_NV_FRAGMENT_SIZE) {
- msg_body.last_fragment = 0;
- msg_body.nv_img_buffer_size = WCN36XX_NV_FRAGMENT_SIZE;
- } else {
- msg_body.last_fragment = 1;
- msg_body.nv_img_buffer_size = fw_bytes_left;
- /* Do not forget update general message len */
- msg_body.header.len = sizeof(msg_body) + fw_bytes_left;
- }
- /* Add load NV request message header */
- memcpy(wcn->hal_buf, &msg_body, sizeof(msg_body));
- /* Add NV body itself */
- memcpy(wcn->hal_buf + sizeof(msg_body),
- &nv_d->table + fm_offset,
- msg_body.nv_img_buffer_size);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret)
- goto out_unlock;
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf,
- wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_load_nv response failed err=%d\n",
- ret);
- goto out_unlock;
- }
- msg_body.frag_number++;
- fm_offset += WCN36XX_NV_FRAGMENT_SIZE;
- } while (msg_body.last_fragment != 1);
- out_unlock:
- mutex_unlock(&wcn->hal_mutex);
- out_free_nv:
- release_firmware(nv);
- return ret;
- }
- static int wcn36xx_smd_start_rsp(struct wcn36xx *wcn, void *buf, size_t len)
- {
- struct wcn36xx_hal_mac_start_rsp_msg *rsp;
- if (len < sizeof(*rsp))
- return -EIO;
- rsp = (struct wcn36xx_hal_mac_start_rsp_msg *)buf;
- if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->start_rsp_params.status)
- return -EIO;
- memcpy(wcn->crm_version, rsp->start_rsp_params.crm_version,
- WCN36XX_HAL_VERSION_LENGTH);
- memcpy(wcn->wlan_version, rsp->start_rsp_params.wlan_version,
- WCN36XX_HAL_VERSION_LENGTH);
- /* null terminate the strings, just in case */
- wcn->crm_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
- wcn->wlan_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
- wcn->fw_revision = rsp->start_rsp_params.version.revision;
- wcn->fw_version = rsp->start_rsp_params.version.version;
- wcn->fw_minor = rsp->start_rsp_params.version.minor;
- wcn->fw_major = rsp->start_rsp_params.version.major;
- wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n",
- wcn->wlan_version, wcn->crm_version);
- wcn36xx_info("firmware API %u.%u.%u.%u, %u stations, %u bssids\n",
- wcn->fw_major, wcn->fw_minor,
- wcn->fw_version, wcn->fw_revision,
- rsp->start_rsp_params.stations,
- rsp->start_rsp_params.bssids);
- return 0;
- }
- int wcn36xx_smd_start(struct wcn36xx *wcn)
- {
- struct wcn36xx_hal_mac_start_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_REQ);
- msg_body.params.type = DRIVER_TYPE_PRODUCTION;
- msg_body.params.len = 0;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start type %d\n",
- msg_body.params.type);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_start failed\n");
- goto out;
- }
- ret = wcn36xx_smd_start_rsp(wcn, wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_start response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_stop(struct wcn36xx *wcn)
- {
- struct wcn36xx_hal_mac_stop_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_STOP_REQ);
- msg_body.stop_req_params.reason = HAL_STOP_TYPE_RF_KILL;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_stop failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_stop response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_init_scan(struct wcn36xx *wcn, enum wcn36xx_hal_sys_mode mode)
- {
- struct wcn36xx_hal_init_scan_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_INIT_SCAN_REQ);
- msg_body.mode = mode;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL, "hal init scan mode %d\n", msg_body.mode);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_init_scan failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_init_scan response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_start_scan(struct wcn36xx *wcn)
- {
- struct wcn36xx_hal_start_scan_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_SCAN_REQ);
- msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start scan channel %d\n",
- msg_body.scan_channel);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_start_scan failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_start_scan response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_end_scan(struct wcn36xx *wcn)
- {
- struct wcn36xx_hal_end_scan_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_END_SCAN_REQ);
- msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL, "hal end scan channel %d\n",
- msg_body.scan_channel);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_end_scan failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_end_scan response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_finish_scan(struct wcn36xx *wcn,
- enum wcn36xx_hal_sys_mode mode)
- {
- struct wcn36xx_hal_finish_scan_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_FINISH_SCAN_REQ);
- msg_body.mode = mode;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL, "hal finish scan mode %d\n",
- msg_body.mode);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_finish_scan failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_finish_scan response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- static int wcn36xx_smd_switch_channel_rsp(void *buf, size_t len)
- {
- struct wcn36xx_hal_switch_channel_rsp_msg *rsp;
- int ret = 0;
- ret = wcn36xx_smd_rsp_status_check(buf, len);
- if (ret)
- return ret;
- rsp = (struct wcn36xx_hal_switch_channel_rsp_msg *)buf;
- wcn36xx_dbg(WCN36XX_DBG_HAL, "channel switched to: %d, status: %d\n",
- rsp->channel_number, rsp->status);
- return ret;
- }
- int wcn36xx_smd_switch_channel(struct wcn36xx *wcn,
- struct ieee80211_vif *vif, int ch)
- {
- struct wcn36xx_hal_switch_channel_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_CH_SWITCH_REQ);
- msg_body.channel_number = (u8)ch;
- msg_body.tx_mgmt_power = 0xbf;
- msg_body.max_tx_power = 0xbf;
- memcpy(msg_body.self_sta_mac_addr, vif->addr, ETH_ALEN);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_switch_channel failed\n");
- goto out;
- }
- ret = wcn36xx_smd_switch_channel_rsp(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_switch_channel response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- static int wcn36xx_smd_update_scan_params_rsp(void *buf, size_t len)
- {
- struct wcn36xx_hal_update_scan_params_resp *rsp;
- rsp = (struct wcn36xx_hal_update_scan_params_resp *)buf;
- /* Remove the PNO version bit */
- rsp->status &= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK));
- if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status) {
- wcn36xx_warn("error response from update scan\n");
- return rsp->status;
- }
- return 0;
- }
- int wcn36xx_smd_update_scan_params(struct wcn36xx *wcn)
- {
- struct wcn36xx_hal_update_scan_params_req msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ);
- msg_body.dot11d_enabled = 0;
- msg_body.dot11d_resolved = 0;
- msg_body.channel_count = 26;
- msg_body.active_min_ch_time = 60;
- msg_body.active_max_ch_time = 120;
- msg_body.passive_min_ch_time = 60;
- msg_body.passive_max_ch_time = 110;
- msg_body.state = 0;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal update scan params channel_count %d\n",
- msg_body.channel_count);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_update_scan_params failed\n");
- goto out;
- }
- ret = wcn36xx_smd_update_scan_params_rsp(wcn->hal_buf,
- wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_update_scan_params response failed err=%d\n",
- ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx *wcn,
- struct ieee80211_vif *vif,
- void *buf,
- size_t len)
- {
- struct wcn36xx_hal_add_sta_self_rsp_msg *rsp;
- struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
- if (len < sizeof(*rsp))
- return -EINVAL;
- rsp = (struct wcn36xx_hal_add_sta_self_rsp_msg *)buf;
- if (rsp->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
- wcn36xx_warn("hal add sta self failure: %d\n",
- rsp->status);
- return rsp->status;
- }
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal add sta self status %d self_sta_index %d dpu_index %d\n",
- rsp->status, rsp->self_sta_index, rsp->dpu_index);
- priv_vif->self_sta_index = rsp->self_sta_index;
- priv_vif->self_dpu_desc_index = rsp->dpu_index;
- return 0;
- }
- int wcn36xx_smd_add_sta_self(struct wcn36xx *wcn, struct ieee80211_vif *vif)
- {
- struct wcn36xx_hal_add_sta_self_req msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_STA_SELF_REQ);
- memcpy(&msg_body.self_addr, vif->addr, ETH_ALEN);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal add sta self self_addr %pM status %d\n",
- msg_body.self_addr, msg_body.status);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_add_sta_self failed\n");
- goto out;
- }
- ret = wcn36xx_smd_add_sta_self_rsp(wcn,
- vif,
- wcn->hal_buf,
- wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_delete_sta_self(struct wcn36xx *wcn, u8 *addr)
- {
- struct wcn36xx_hal_del_sta_self_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_STA_SELF_REQ);
- memcpy(&msg_body.self_addr, addr, ETH_ALEN);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_delete_sta_self failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_delete_sta_self response failed err=%d\n",
- ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_delete_sta(struct wcn36xx *wcn, u8 sta_index)
- {
- struct wcn36xx_hal_delete_sta_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_STA_REQ);
- msg_body.sta_index = sta_index;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal delete sta sta_index %d\n",
- msg_body.sta_index);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_delete_sta failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_delete_sta response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- static int wcn36xx_smd_join_rsp(void *buf, size_t len)
- {
- struct wcn36xx_hal_join_rsp_msg *rsp;
- if (wcn36xx_smd_rsp_status_check(buf, len))
- return -EIO;
- rsp = (struct wcn36xx_hal_join_rsp_msg *)buf;
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal rsp join status %d tx_mgmt_power %d\n",
- rsp->status, rsp->tx_mgmt_power);
- return 0;
- }
- int wcn36xx_smd_join(struct wcn36xx *wcn, const u8 *bssid, u8 *vif, u8 ch)
- {
- struct wcn36xx_hal_join_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_JOIN_REQ);
- memcpy(&msg_body.bssid, bssid, ETH_ALEN);
- memcpy(&msg_body.self_sta_mac_addr, vif, ETH_ALEN);
- msg_body.channel = ch;
- if (conf_is_ht40_minus(&wcn->hw->conf))
- msg_body.secondary_channel_offset =
- PHY_DOUBLE_CHANNEL_HIGH_PRIMARY;
- else if (conf_is_ht40_plus(&wcn->hw->conf))
- msg_body.secondary_channel_offset =
- PHY_DOUBLE_CHANNEL_LOW_PRIMARY;
- else
- msg_body.secondary_channel_offset =
- PHY_SINGLE_CHANNEL_CENTERED;
- msg_body.link_state = WCN36XX_HAL_LINK_PREASSOC_STATE;
- msg_body.max_tx_power = 0xbf;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal join req bssid %pM self_sta_mac_addr %pM channel %d link_state %d\n",
- msg_body.bssid, msg_body.self_sta_mac_addr,
- msg_body.channel, msg_body.link_state);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_join failed\n");
- goto out;
- }
- ret = wcn36xx_smd_join_rsp(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_join response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_set_link_st(struct wcn36xx *wcn, const u8 *bssid,
- const u8 *sta_mac,
- enum wcn36xx_hal_link_state state)
- {
- struct wcn36xx_hal_set_link_state_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_LINK_ST_REQ);
- memcpy(&msg_body.bssid, bssid, ETH_ALEN);
- memcpy(&msg_body.self_mac_addr, sta_mac, ETH_ALEN);
- msg_body.state = state;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal set link state bssid %pM self_mac_addr %pM state %d\n",
- msg_body.bssid, msg_body.self_mac_addr, msg_body.state);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_set_link_st failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_set_link_st response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- static void wcn36xx_smd_convert_sta_to_v1(struct wcn36xx *wcn,
- const struct wcn36xx_hal_config_sta_params *orig,
- struct wcn36xx_hal_config_sta_params_v1 *v1)
- {
- /* convert orig to v1 format */
- memcpy(&v1->bssid, orig->bssid, ETH_ALEN);
- memcpy(&v1->mac, orig->mac, ETH_ALEN);
- v1->aid = orig->aid;
- v1->type = orig->type;
- v1->listen_interval = orig->listen_interval;
- v1->ht_capable = orig->ht_capable;
- v1->max_ampdu_size = orig->max_ampdu_size;
- v1->max_ampdu_density = orig->max_ampdu_density;
- v1->sgi_40mhz = orig->sgi_40mhz;
- v1->sgi_20Mhz = orig->sgi_20Mhz;
- memcpy(&v1->supported_rates, &orig->supported_rates,
- sizeof(orig->supported_rates));
- v1->sta_index = orig->sta_index;
- }
- static int wcn36xx_smd_config_sta_rsp(struct wcn36xx *wcn,
- struct ieee80211_sta *sta,
- void *buf,
- size_t len)
- {
- struct wcn36xx_hal_config_sta_rsp_msg *rsp;
- struct config_sta_rsp_params *params;
- struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
- if (len < sizeof(*rsp))
- return -EINVAL;
- rsp = (struct wcn36xx_hal_config_sta_rsp_msg *)buf;
- params = &rsp->params;
- if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
- wcn36xx_warn("hal config sta response failure: %d\n",
- params->status);
- return -EIO;
- }
- sta_priv->sta_index = params->sta_index;
- sta_priv->dpu_desc_index = params->dpu_index;
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal config sta rsp status %d sta_index %d bssid_index %d p2p %d\n",
- params->status, params->sta_index, params->bssid_index,
- params->p2p);
- return 0;
- }
- static int wcn36xx_smd_config_sta_v1(struct wcn36xx *wcn,
- const struct wcn36xx_hal_config_sta_req_msg *orig)
- {
- struct wcn36xx_hal_config_sta_req_msg_v1 msg_body;
- struct wcn36xx_hal_config_sta_params_v1 *sta = &msg_body.sta_params;
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_STA_REQ);
- wcn36xx_smd_convert_sta_to_v1(wcn, &orig->sta_params,
- &msg_body.sta_params);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal config sta v1 action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
- sta->action, sta->sta_index, sta->bssid_index,
- sta->bssid, sta->type, sta->mac, sta->aid);
- return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- }
- int wcn36xx_smd_config_sta(struct wcn36xx *wcn, struct ieee80211_vif *vif,
- struct ieee80211_sta *sta)
- {
- struct wcn36xx_hal_config_sta_req_msg msg;
- struct wcn36xx_hal_config_sta_params *sta_params;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_STA_REQ);
- sta_params = &msg.sta_params;
- wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
- if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
- ret = wcn36xx_smd_config_sta_v1(wcn, &msg);
- } else {
- PREPARE_HAL_BUF(wcn->hal_buf, msg);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal config sta action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
- sta_params->action, sta_params->sta_index,
- sta_params->bssid_index, sta_params->bssid,
- sta_params->type, sta_params->mac, sta_params->aid);
- ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
- }
- if (ret) {
- wcn36xx_err("Sending hal_config_sta failed\n");
- goto out;
- }
- ret = wcn36xx_smd_config_sta_rsp(wcn,
- sta,
- wcn->hal_buf,
- wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_config_sta response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- static int wcn36xx_smd_config_bss_v1(struct wcn36xx *wcn,
- const struct wcn36xx_hal_config_bss_req_msg *orig)
- {
- struct wcn36xx_hal_config_bss_req_msg_v1 msg_body;
- struct wcn36xx_hal_config_bss_params_v1 *bss = &msg_body.bss_params;
- struct wcn36xx_hal_config_sta_params_v1 *sta = &bss->sta;
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_BSS_REQ);
- /* convert orig to v1 */
- memcpy(&msg_body.bss_params.bssid,
- &orig->bss_params.bssid, ETH_ALEN);
- memcpy(&msg_body.bss_params.self_mac_addr,
- &orig->bss_params.self_mac_addr, ETH_ALEN);
- msg_body.bss_params.bss_type = orig->bss_params.bss_type;
- msg_body.bss_params.oper_mode = orig->bss_params.oper_mode;
- msg_body.bss_params.nw_type = orig->bss_params.nw_type;
- msg_body.bss_params.short_slot_time_supported =
- orig->bss_params.short_slot_time_supported;
- msg_body.bss_params.lla_coexist = orig->bss_params.lla_coexist;
- msg_body.bss_params.llb_coexist = orig->bss_params.llb_coexist;
- msg_body.bss_params.llg_coexist = orig->bss_params.llg_coexist;
- msg_body.bss_params.ht20_coexist = orig->bss_params.ht20_coexist;
- msg_body.bss_params.lln_non_gf_coexist =
- orig->bss_params.lln_non_gf_coexist;
- msg_body.bss_params.lsig_tx_op_protection_full_support =
- orig->bss_params.lsig_tx_op_protection_full_support;
- msg_body.bss_params.rifs_mode = orig->bss_params.rifs_mode;
- msg_body.bss_params.beacon_interval = orig->bss_params.beacon_interval;
- msg_body.bss_params.dtim_period = orig->bss_params.dtim_period;
- msg_body.bss_params.tx_channel_width_set =
- orig->bss_params.tx_channel_width_set;
- msg_body.bss_params.oper_channel = orig->bss_params.oper_channel;
- msg_body.bss_params.ext_channel = orig->bss_params.ext_channel;
- msg_body.bss_params.reserved = orig->bss_params.reserved;
- memcpy(&msg_body.bss_params.ssid,
- &orig->bss_params.ssid,
- sizeof(orig->bss_params.ssid));
- msg_body.bss_params.action = orig->bss_params.action;
- msg_body.bss_params.rateset = orig->bss_params.rateset;
- msg_body.bss_params.ht = orig->bss_params.ht;
- msg_body.bss_params.obss_prot_enabled =
- orig->bss_params.obss_prot_enabled;
- msg_body.bss_params.rmf = orig->bss_params.rmf;
- msg_body.bss_params.ht_oper_mode = orig->bss_params.ht_oper_mode;
- msg_body.bss_params.dual_cts_protection =
- orig->bss_params.dual_cts_protection;
- msg_body.bss_params.max_probe_resp_retry_limit =
- orig->bss_params.max_probe_resp_retry_limit;
- msg_body.bss_params.hidden_ssid = orig->bss_params.hidden_ssid;
- msg_body.bss_params.proxy_probe_resp =
- orig->bss_params.proxy_probe_resp;
- msg_body.bss_params.edca_params_valid =
- orig->bss_params.edca_params_valid;
- memcpy(&msg_body.bss_params.acbe,
- &orig->bss_params.acbe,
- sizeof(orig->bss_params.acbe));
- memcpy(&msg_body.bss_params.acbk,
- &orig->bss_params.acbk,
- sizeof(orig->bss_params.acbk));
- memcpy(&msg_body.bss_params.acvi,
- &orig->bss_params.acvi,
- sizeof(orig->bss_params.acvi));
- memcpy(&msg_body.bss_params.acvo,
- &orig->bss_params.acvo,
- sizeof(orig->bss_params.acvo));
- msg_body.bss_params.ext_set_sta_key_param_valid =
- orig->bss_params.ext_set_sta_key_param_valid;
- memcpy(&msg_body.bss_params.ext_set_sta_key_param,
- &orig->bss_params.ext_set_sta_key_param,
- sizeof(orig->bss_params.acvo));
- msg_body.bss_params.wcn36xx_hal_persona =
- orig->bss_params.wcn36xx_hal_persona;
- msg_body.bss_params.spectrum_mgt_enable =
- orig->bss_params.spectrum_mgt_enable;
- msg_body.bss_params.tx_mgmt_power = orig->bss_params.tx_mgmt_power;
- msg_body.bss_params.max_tx_power = orig->bss_params.max_tx_power;
- wcn36xx_smd_convert_sta_to_v1(wcn, &orig->bss_params.sta,
- &msg_body.bss_params.sta);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal config bss v1 bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
- bss->bssid, bss->self_mac_addr, bss->bss_type,
- bss->oper_mode, bss->nw_type);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
- sta->bssid, sta->action, sta->sta_index,
- sta->bssid_index, sta->aid, sta->type, sta->mac);
- return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- }
- static int wcn36xx_smd_config_bss_rsp(struct wcn36xx *wcn,
- struct ieee80211_vif *vif,
- void *buf,
- size_t len)
- {
- struct wcn36xx_hal_config_bss_rsp_msg *rsp;
- struct wcn36xx_hal_config_bss_rsp_params *params;
- struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
- if (len < sizeof(*rsp))
- return -EINVAL;
- rsp = (struct wcn36xx_hal_config_bss_rsp_msg *)buf;
- params = &rsp->bss_rsp_params;
- if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
- wcn36xx_warn("hal config bss response failure: %d\n",
- params->status);
- return -EIO;
- }
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal config bss rsp status %d bss_idx %d dpu_desc_index %d"
- " sta_idx %d self_idx %d bcast_idx %d mac %pM"
- " power %d ucast_dpu_signature %d\n",
- params->status, params->bss_index, params->dpu_desc_index,
- params->bss_sta_index, params->bss_self_sta_index,
- params->bss_bcast_sta_idx, params->mac,
- params->tx_mgmt_power, params->ucast_dpu_signature);
- priv_vif->bss_index = params->bss_index;
- if (priv_vif->sta) {
- priv_vif->sta->bss_sta_index = params->bss_sta_index;
- priv_vif->sta->bss_dpu_desc_index = params->dpu_desc_index;
- }
- priv_vif->ucast_dpu_signature = params->ucast_dpu_signature;
- return 0;
- }
- int wcn36xx_smd_config_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif,
- struct ieee80211_sta *sta, const u8 *bssid,
- bool update)
- {
- struct wcn36xx_hal_config_bss_req_msg msg;
- struct wcn36xx_hal_config_bss_params *bss;
- struct wcn36xx_hal_config_sta_params *sta_params;
- struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_BSS_REQ);
- bss = &msg.bss_params;
- sta_params = &bss->sta;
- WARN_ON(is_zero_ether_addr(bssid));
- memcpy(&bss->bssid, bssid, ETH_ALEN);
- memcpy(bss->self_mac_addr, vif->addr, ETH_ALEN);
- if (vif->type == NL80211_IFTYPE_STATION) {
- bss->bss_type = WCN36XX_HAL_INFRASTRUCTURE_MODE;
- /* STA */
- bss->oper_mode = 1;
- bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_MODE;
- } else if (vif->type == NL80211_IFTYPE_AP) {
- bss->bss_type = WCN36XX_HAL_INFRA_AP_MODE;
- /* AP */
- bss->oper_mode = 0;
- bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_SAP_MODE;
- } else if (vif->type == NL80211_IFTYPE_ADHOC ||
- vif->type == NL80211_IFTYPE_MESH_POINT) {
- bss->bss_type = WCN36XX_HAL_IBSS_MODE;
- /* STA */
- bss->oper_mode = 1;
- } else {
- wcn36xx_warn("Unknown type for bss config: %d\n", vif->type);
- }
- if (vif->type == NL80211_IFTYPE_STATION)
- wcn36xx_smd_set_bss_nw_type(wcn, sta, bss);
- else
- bss->nw_type = WCN36XX_HAL_11N_NW_TYPE;
- bss->short_slot_time_supported = vif->bss_conf.use_short_slot;
- bss->lla_coexist = 0;
- bss->llb_coexist = 0;
- bss->llg_coexist = 0;
- bss->rifs_mode = 0;
- bss->beacon_interval = vif->bss_conf.beacon_int;
- bss->dtim_period = vif_priv->dtim_period;
- wcn36xx_smd_set_bss_ht_params(vif, sta, bss);
- bss->oper_channel = WCN36XX_HW_CHANNEL(wcn);
- if (conf_is_ht40_minus(&wcn->hw->conf))
- bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
- else if (conf_is_ht40_plus(&wcn->hw->conf))
- bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
- else
- bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_NONE;
- bss->reserved = 0;
- wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
- /* wcn->ssid is only valid in AP and IBSS mode */
- bss->ssid.length = vif_priv->ssid.length;
- memcpy(bss->ssid.ssid, vif_priv->ssid.ssid, vif_priv->ssid.length);
- bss->obss_prot_enabled = 0;
- bss->rmf = 0;
- bss->max_probe_resp_retry_limit = 0;
- bss->hidden_ssid = vif->bss_conf.hidden_ssid;
- bss->proxy_probe_resp = 0;
- bss->edca_params_valid = 0;
- /* FIXME: set acbe, acbk, acvi and acvo */
- bss->ext_set_sta_key_param_valid = 0;
- /* FIXME: set ext_set_sta_key_param */
- bss->spectrum_mgt_enable = 0;
- bss->tx_mgmt_power = 0;
- bss->max_tx_power = WCN36XX_MAX_POWER(wcn);
- bss->action = update;
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal config bss bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
- bss->bssid, bss->self_mac_addr, bss->bss_type,
- bss->oper_mode, bss->nw_type);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
- sta_params->bssid, sta_params->action,
- sta_params->sta_index, sta_params->bssid_index,
- sta_params->aid, sta_params->type,
- sta_params->mac);
- if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
- ret = wcn36xx_smd_config_bss_v1(wcn, &msg);
- } else {
- PREPARE_HAL_BUF(wcn->hal_buf, msg);
- ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
- }
- if (ret) {
- wcn36xx_err("Sending hal_config_bss failed\n");
- goto out;
- }
- ret = wcn36xx_smd_config_bss_rsp(wcn,
- vif,
- wcn->hal_buf,
- wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_config_bss response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_delete_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif)
- {
- struct wcn36xx_hal_delete_bss_req_msg msg_body;
- struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_BSS_REQ);
- msg_body.bss_index = priv_vif->bss_index;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL, "hal delete bss %d\n", msg_body.bss_index);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_delete_bss failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_delete_bss response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_send_beacon(struct wcn36xx *wcn, struct ieee80211_vif *vif,
- struct sk_buff *skb_beacon, u16 tim_off,
- u16 p2p_off)
- {
- struct wcn36xx_hal_send_beacon_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_SEND_BEACON_REQ);
- /* TODO need to find out why this is needed? */
- msg_body.beacon_length = skb_beacon->len + 6;
- if (BEACON_TEMPLATE_SIZE > msg_body.beacon_length) {
- memcpy(&msg_body.beacon, &skb_beacon->len, sizeof(u32));
- memcpy(&(msg_body.beacon[4]), skb_beacon->data,
- skb_beacon->len);
- } else {
- wcn36xx_err("Beacon is to big: beacon size=%d\n",
- msg_body.beacon_length);
- ret = -ENOMEM;
- goto out;
- }
- memcpy(msg_body.bssid, vif->addr, ETH_ALEN);
- /* TODO need to find out why this is needed? */
- msg_body.tim_ie_offset = tim_off+4;
- msg_body.p2p_ie_offset = p2p_off;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal send beacon beacon_length %d\n",
- msg_body.beacon_length);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_send_beacon failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_send_beacon response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx *wcn,
- struct ieee80211_vif *vif,
- struct sk_buff *skb)
- {
- struct wcn36xx_hal_send_probe_resp_req_msg msg;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ);
- if (skb->len > BEACON_TEMPLATE_SIZE) {
- wcn36xx_warn("probe response template is too big: %d\n",
- skb->len);
- ret = -E2BIG;
- goto out;
- }
- msg.probe_resp_template_len = skb->len;
- memcpy(&msg.probe_resp_template, skb->data, skb->len);
- memcpy(msg.bssid, vif->addr, ETH_ALEN);
- PREPARE_HAL_BUF(wcn->hal_buf, msg);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "hal update probe rsp len %d bssid %pM\n",
- msg.probe_resp_template_len, msg.bssid);
- ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
- ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_set_stakey(struct wcn36xx *wcn,
- enum ani_ed_type enc_type,
- u8 keyidx,
- u8 keylen,
- u8 *key,
- u8 sta_index)
- {
- struct wcn36xx_hal_set_sta_key_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_STAKEY_REQ);
- msg_body.set_sta_key_params.sta_index = sta_index;
- msg_body.set_sta_key_params.enc_type = enc_type;
- msg_body.set_sta_key_params.key[0].id = keyidx;
- msg_body.set_sta_key_params.key[0].unicast = 1;
- msg_body.set_sta_key_params.key[0].direction = WCN36XX_HAL_TX_RX;
- msg_body.set_sta_key_params.key[0].pae_role = 0;
- msg_body.set_sta_key_params.key[0].length = keylen;
- memcpy(msg_body.set_sta_key_params.key[0].key, key, keylen);
- msg_body.set_sta_key_params.single_tid_rc = 1;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_set_stakey failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_set_stakey response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_set_bsskey(struct wcn36xx *wcn,
- enum ani_ed_type enc_type,
- u8 keyidx,
- u8 keylen,
- u8 *key)
- {
- struct wcn36xx_hal_set_bss_key_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_BSSKEY_REQ);
- msg_body.bss_idx = 0;
- msg_body.enc_type = enc_type;
- msg_body.num_keys = 1;
- msg_body.keys[0].id = keyidx;
- msg_body.keys[0].unicast = 0;
- msg_body.keys[0].direction = WCN36XX_HAL_RX_ONLY;
- msg_body.keys[0].pae_role = 0;
- msg_body.keys[0].length = keylen;
- memcpy(msg_body.keys[0].key, key, keylen);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_set_bsskey failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_remove_stakey(struct wcn36xx *wcn,
- enum ani_ed_type enc_type,
- u8 keyidx,
- u8 sta_index)
- {
- struct wcn36xx_hal_remove_sta_key_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_STAKEY_REQ);
- msg_body.sta_idx = sta_index;
- msg_body.enc_type = enc_type;
- msg_body.key_id = keyidx;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_remove_stakey failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_remove_bsskey(struct wcn36xx *wcn,
- enum ani_ed_type enc_type,
- u8 keyidx)
- {
- struct wcn36xx_hal_remove_bss_key_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_BSSKEY_REQ);
- msg_body.bss_idx = 0;
- msg_body.enc_type = enc_type;
- msg_body.key_id = keyidx;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_remove_bsskey failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_enter_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
- {
- struct wcn36xx_hal_enter_bmps_req_msg msg_body;
- struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_ENTER_BMPS_REQ);
- msg_body.bss_index = vif_priv->bss_index;
- msg_body.tbtt = vif->bss_conf.sync_tsf;
- msg_body.dtim_period = vif_priv->dtim_period;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_enter_bmps failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_exit_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
- {
- struct wcn36xx_hal_enter_bmps_req_msg msg_body;
- struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_EXIT_BMPS_REQ);
- msg_body.bss_index = vif_priv->bss_index;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_exit_bmps failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_set_power_params(struct wcn36xx *wcn, bool ignore_dtim)
- {
- struct wcn36xx_hal_set_power_params_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_POWER_PARAMS_REQ);
- /*
- * When host is down ignore every second dtim
- */
- if (ignore_dtim) {
- msg_body.ignore_dtim = 1;
- msg_body.dtim_period = 2;
- }
- msg_body.listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_set_power_params failed\n");
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- /* Notice: This function should be called after associated, or else it
- * will be invalid
- */
- int wcn36xx_smd_keep_alive_req(struct wcn36xx *wcn,
- struct ieee80211_vif *vif,
- int packet_type)
- {
- struct wcn36xx_hal_keep_alive_req_msg msg_body;
- struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_KEEP_ALIVE_REQ);
- if (packet_type == WCN36XX_HAL_KEEP_ALIVE_NULL_PKT) {
- msg_body.bss_index = vif_priv->bss_index;
- msg_body.packet_type = WCN36XX_HAL_KEEP_ALIVE_NULL_PKT;
- msg_body.time_period = WCN36XX_KEEP_ALIVE_TIME_PERIOD;
- } else if (packet_type == WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP) {
- /* TODO: it also support ARP response type */
- } else {
- wcn36xx_warn("unknow keep alive packet type %d\n", packet_type);
- ret = -EINVAL;
- goto out;
- }
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_exit_bmps failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_dump_cmd_req(struct wcn36xx *wcn, u32 arg1, u32 arg2,
- u32 arg3, u32 arg4, u32 arg5)
- {
- struct wcn36xx_hal_dump_cmd_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_DUMP_COMMAND_REQ);
- msg_body.arg1 = arg1;
- msg_body.arg2 = arg2;
- msg_body.arg3 = arg3;
- msg_body.arg4 = arg4;
- msg_body.arg5 = arg5;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_dump_cmd failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- static inline void set_feat_caps(u32 *bitmap,
- enum place_holder_in_cap_bitmap cap)
- {
- int arr_idx, bit_idx;
- if (cap < 0 || cap > 127) {
- wcn36xx_warn("error cap idx %d\n", cap);
- return;
- }
- arr_idx = cap / 32;
- bit_idx = cap % 32;
- bitmap[arr_idx] |= (1 << bit_idx);
- }
- static inline int get_feat_caps(u32 *bitmap,
- enum place_holder_in_cap_bitmap cap)
- {
- int arr_idx, bit_idx;
- int ret = 0;
- if (cap < 0 || cap > 127) {
- wcn36xx_warn("error cap idx %d\n", cap);
- return -EINVAL;
- }
- arr_idx = cap / 32;
- bit_idx = cap % 32;
- ret = (bitmap[arr_idx] & (1 << bit_idx)) ? 1 : 0;
- return ret;
- }
- static inline void clear_feat_caps(u32 *bitmap,
- enum place_holder_in_cap_bitmap cap)
- {
- int arr_idx, bit_idx;
- if (cap < 0 || cap > 127) {
- wcn36xx_warn("error cap idx %d\n", cap);
- return;
- }
- arr_idx = cap / 32;
- bit_idx = cap % 32;
- bitmap[arr_idx] &= ~(1 << bit_idx);
- }
- int wcn36xx_smd_feature_caps_exchange(struct wcn36xx *wcn)
- {
- struct wcn36xx_hal_feat_caps_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ);
- set_feat_caps(msg_body.feat_caps, STA_POWERSAVE);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_feature_caps_exchange response failed err=%d\n",
- ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_add_ba_session(struct wcn36xx *wcn,
- struct ieee80211_sta *sta,
- u16 tid,
- u16 *ssn,
- u8 direction,
- u8 sta_index)
- {
- struct wcn36xx_hal_add_ba_session_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_SESSION_REQ);
- msg_body.sta_index = sta_index;
- memcpy(&msg_body.mac_addr, sta->addr, ETH_ALEN);
- msg_body.dialog_token = 0x10;
- msg_body.tid = tid;
- /* Immediate BA because Delayed BA is not supported */
- msg_body.policy = 1;
- msg_body.buffer_size = WCN36XX_AGGR_BUFFER_SIZE;
- msg_body.timeout = 0;
- if (ssn)
- msg_body.ssn = *ssn;
- msg_body.direction = direction;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_add_ba_session failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_add_ba(struct wcn36xx *wcn)
- {
- struct wcn36xx_hal_add_ba_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_REQ);
- msg_body.session_id = 0;
- msg_body.win_size = WCN36XX_AGGR_BUFFER_SIZE;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_add_ba failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_add_ba response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_del_ba(struct wcn36xx *wcn, u16 tid, u8 sta_index)
- {
- struct wcn36xx_hal_del_ba_req_msg msg_body;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_BA_REQ);
- msg_body.sta_index = sta_index;
- msg_body.tid = tid;
- msg_body.direction = 0;
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_del_ba failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_del_ba response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- int wcn36xx_smd_trigger_ba(struct wcn36xx *wcn, u8 sta_index)
- {
- struct wcn36xx_hal_trigger_ba_req_msg msg_body;
- struct wcn36xx_hal_trigget_ba_req_candidate *candidate;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_TRIGGER_BA_REQ);
- msg_body.session_id = 0;
- msg_body.candidate_cnt = 1;
- msg_body.header.len += sizeof(*candidate);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- candidate = (struct wcn36xx_hal_trigget_ba_req_candidate *)
- (wcn->hal_buf + sizeof(msg_body));
- candidate->sta_index = sta_index;
- candidate->tid_bitmap = 1;
- ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
- if (ret) {
- wcn36xx_err("Sending hal_trigger_ba failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len)
- {
- struct wcn36xx_hal_tx_compl_ind_msg *rsp = buf;
- if (len != sizeof(*rsp)) {
- wcn36xx_warn("Bad TX complete indication\n");
- return -EIO;
- }
- wcn36xx_dxe_tx_ack_ind(wcn, rsp->status);
- return 0;
- }
- static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx *wcn,
- void *buf,
- size_t len)
- {
- struct wcn36xx_hal_missed_beacon_ind_msg *rsp = buf;
- struct ieee80211_vif *vif = NULL;
- struct wcn36xx_vif *tmp;
- /* Old FW does not have bss index */
- if (wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
- list_for_each_entry(tmp, &wcn->vif_list, list) {
- wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
- tmp->bss_index);
- vif = container_of((void *)tmp,
- struct ieee80211_vif,
- drv_priv);
- ieee80211_connection_loss(vif);
- }
- return 0;
- }
- if (len != sizeof(*rsp)) {
- wcn36xx_warn("Corrupted missed beacon indication\n");
- return -EIO;
- }
- list_for_each_entry(tmp, &wcn->vif_list, list) {
- if (tmp->bss_index == rsp->bss_index) {
- wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
- rsp->bss_index);
- vif = container_of((void *)tmp,
- struct ieee80211_vif,
- drv_priv);
- ieee80211_connection_loss(vif);
- return 0;
- }
- }
- wcn36xx_warn("BSS index %d not found\n", rsp->bss_index);
- return -ENOENT;
- }
- static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx *wcn,
- void *buf,
- size_t len)
- {
- struct wcn36xx_hal_delete_sta_context_ind_msg *rsp = buf;
- struct wcn36xx_vif *tmp;
- struct ieee80211_sta *sta = NULL;
- if (len != sizeof(*rsp)) {
- wcn36xx_warn("Corrupted delete sta indication\n");
- return -EIO;
- }
- list_for_each_entry(tmp, &wcn->vif_list, list) {
- if (sta && (tmp->sta->sta_index == rsp->sta_id)) {
- sta = container_of((void *)tmp->sta,
- struct ieee80211_sta,
- drv_priv);
- wcn36xx_dbg(WCN36XX_DBG_HAL,
- "delete station indication %pM index %d\n",
- rsp->addr2,
- rsp->sta_id);
- ieee80211_report_low_ack(sta, 0);
- return 0;
- }
- }
- wcn36xx_warn("STA with addr %pM and index %d not found\n",
- rsp->addr2,
- rsp->sta_id);
- return -ENOENT;
- }
- int wcn36xx_smd_update_cfg(struct wcn36xx *wcn, u32 cfg_id, u32 value)
- {
- struct wcn36xx_hal_update_cfg_req_msg msg_body, *body;
- size_t len;
- int ret = 0;
- mutex_lock(&wcn->hal_mutex);
- INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_CFG_REQ);
- PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
- body = (struct wcn36xx_hal_update_cfg_req_msg *) wcn->hal_buf;
- len = msg_body.header.len;
- put_cfg_tlv_u32(wcn, &len, cfg_id, value);
- body->header.len = len;
- body->len = len - sizeof(*body);
- ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
- if (ret) {
- wcn36xx_err("Sending hal_update_cfg failed\n");
- goto out;
- }
- ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
- if (ret) {
- wcn36xx_err("hal_update_cfg response failed err=%d\n", ret);
- goto out;
- }
- out:
- mutex_unlock(&wcn->hal_mutex);
- return ret;
- }
- static void wcn36xx_smd_rsp_process(struct wcn36xx *wcn, void *buf, size_t len)
- {
- struct wcn36xx_hal_msg_header *msg_header = buf;
- struct wcn36xx_hal_ind_msg *msg_ind;
- wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "SMD <<< ", buf, len);
- switch (msg_header->msg_type) {
- case WCN36XX_HAL_START_RSP:
- case WCN36XX_HAL_CONFIG_STA_RSP:
- case WCN36XX_HAL_CONFIG_BSS_RSP:
- case WCN36XX_HAL_ADD_STA_SELF_RSP:
- case WCN36XX_HAL_STOP_RSP:
- case WCN36XX_HAL_DEL_STA_SELF_RSP:
- case WCN36XX_HAL_DELETE_STA_RSP:
- case WCN36XX_HAL_INIT_SCAN_RSP:
- case WCN36XX_HAL_START_SCAN_RSP:
- case WCN36XX_HAL_END_SCAN_RSP:
- case WCN36XX_HAL_FINISH_SCAN_RSP:
- case WCN36XX_HAL_DOWNLOAD_NV_RSP:
- case WCN36XX_HAL_DELETE_BSS_RSP:
- case WCN36XX_HAL_SEND_BEACON_RSP:
- case WCN36XX_HAL_SET_LINK_ST_RSP:
- case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP:
- case WCN36XX_HAL_SET_BSSKEY_RSP:
- case WCN36XX_HAL_SET_STAKEY_RSP:
- case WCN36XX_HAL_RMV_STAKEY_RSP:
- case WCN36XX_HAL_RMV_BSSKEY_RSP:
- case WCN36XX_HAL_ENTER_BMPS_RSP:
- case WCN36XX_HAL_SET_POWER_PARAMS_RSP:
- case WCN36XX_HAL_EXIT_BMPS_RSP:
- case WCN36XX_HAL_KEEP_ALIVE_RSP:
- case WCN36XX_HAL_DUMP_COMMAND_RSP:
- case WCN36XX_HAL_ADD_BA_SESSION_RSP:
- case WCN36XX_HAL_ADD_BA_RSP:
- case WCN36XX_HAL_DEL_BA_RSP:
- case WCN36XX_HAL_TRIGGER_BA_RSP:
- case WCN36XX_HAL_UPDATE_CFG_RSP:
- case WCN36XX_HAL_JOIN_RSP:
- case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP:
- case WCN36XX_HAL_CH_SWITCH_RSP:
- case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP:
- memcpy(wcn->hal_buf, buf, len);
- wcn->hal_rsp_len = len;
- complete(&wcn->hal_rsp_compl);
- break;
- case WCN36XX_HAL_OTA_TX_COMPL_IND:
- case WCN36XX_HAL_MISSED_BEACON_IND:
- case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
- mutex_lock(&wcn->hal_ind_mutex);
- msg_ind = kmalloc(sizeof(*msg_ind), GFP_KERNEL);
- if (msg_ind) {
- msg_ind->msg_len = len;
- msg_ind->msg = kmalloc(len, GFP_KERNEL);
- memcpy(msg_ind->msg, buf, len);
- list_add_tail(&msg_ind->list, &wcn->hal_ind_queue);
- queue_work(wcn->hal_ind_wq, &wcn->hal_ind_work);
- wcn36xx_dbg(WCN36XX_DBG_HAL, "indication arrived\n");
- }
- mutex_unlock(&wcn->hal_ind_mutex);
- if (msg_ind)
- break;
- /* FIXME: Do something smarter then just printing an error. */
- wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
- msg_header->msg_type);
- break;
- default:
- wcn36xx_err("SMD_EVENT (%d) not supported\n",
- msg_header->msg_type);
- }
- }
- static void wcn36xx_ind_smd_work(struct work_struct *work)
- {
- struct wcn36xx *wcn =
- container_of(work, struct wcn36xx, hal_ind_work);
- struct wcn36xx_hal_msg_header *msg_header;
- struct wcn36xx_hal_ind_msg *hal_ind_msg;
- mutex_lock(&wcn->hal_ind_mutex);
- hal_ind_msg = list_first_entry(&wcn->hal_ind_queue,
- struct wcn36xx_hal_ind_msg,
- list);
- msg_header = (struct wcn36xx_hal_msg_header *)hal_ind_msg->msg;
- switch (msg_header->msg_type) {
- case WCN36XX_HAL_OTA_TX_COMPL_IND:
- wcn36xx_smd_tx_compl_ind(wcn,
- hal_ind_msg->msg,
- hal_ind_msg->msg_len);
- break;
- case WCN36XX_HAL_MISSED_BEACON_IND:
- wcn36xx_smd_missed_beacon_ind(wcn,
- hal_ind_msg->msg,
- hal_ind_msg->msg_len);
- break;
- case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
- wcn36xx_smd_delete_sta_context_ind(wcn,
- hal_ind_msg->msg,
- hal_ind_msg->msg_len);
- break;
- default:
- wcn36xx_err("SMD_EVENT (%d) not supported\n",
- msg_header->msg_type);
- }
- list_del(wcn->hal_ind_queue.next);
- kfree(hal_ind_msg->msg);
- kfree(hal_ind_msg);
- mutex_unlock(&wcn->hal_ind_mutex);
- }
- int wcn36xx_smd_open(struct wcn36xx *wcn)
- {
- int ret = 0;
- wcn->hal_ind_wq = create_freezable_workqueue("wcn36xx_smd_ind");
- if (!wcn->hal_ind_wq) {
- wcn36xx_err("failed to allocate wq\n");
- ret = -ENOMEM;
- goto out;
- }
- INIT_WORK(&wcn->hal_ind_work, wcn36xx_ind_smd_work);
- INIT_LIST_HEAD(&wcn->hal_ind_queue);
- mutex_init(&wcn->hal_ind_mutex);
- ret = wcn->ctrl_ops->open(wcn, wcn36xx_smd_rsp_process);
- if (ret) {
- wcn36xx_err("failed to open control channel\n");
- goto free_wq;
- }
- return ret;
- free_wq:
- destroy_workqueue(wcn->hal_ind_wq);
- out:
- return ret;
- }
- void wcn36xx_smd_close(struct wcn36xx *wcn)
- {
- wcn->ctrl_ops->close();
- destroy_workqueue(wcn->hal_ind_wq);
- mutex_destroy(&wcn->hal_ind_mutex);
- }
|