12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412 |
- /**
- * Copyright (c) 2014 Redpine Signals Inc.
- *
- * 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.
- */
- #include <linux/etherdevice.h>
- #include "rsi_mgmt.h"
- #include "rsi_common.h"
- static struct bootup_params boot_params_20 = {
- .magic_number = cpu_to_le16(0x5aa5),
- .crystal_good_time = 0x0,
- .valid = cpu_to_le32(VALID_20),
- .reserved_for_valids = 0x0,
- .bootup_mode_info = 0x0,
- .digital_loop_back_params = 0x0,
- .rtls_timestamp_en = 0x0,
- .host_spi_intr_cfg = 0x0,
- .device_clk_info = {{
- .pll_config_g = {
- .tapll_info_g = {
- .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
- (TA_PLL_M_VAL_20)),
- .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
- },
- .pll960_info_g = {
- .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
- (PLL960_N_VAL_20)),
- .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
- .pll_reg_3 = 0x0,
- },
- .afepll_info_g = {
- .pll_reg = cpu_to_le16(0x9f0),
- }
- },
- .switch_clk_g = {
- .switch_clk_info = cpu_to_le16(BIT(3)),
- .bbp_lmac_clk_reg_val = cpu_to_le16(0x121),
- .umac_clock_reg_config = 0x0,
- .qspi_uart_clock_reg_config = 0x0
- }
- },
- {
- .pll_config_g = {
- .tapll_info_g = {
- .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
- (TA_PLL_M_VAL_20)),
- .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
- },
- .pll960_info_g = {
- .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
- (PLL960_N_VAL_20)),
- .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
- .pll_reg_3 = 0x0,
- },
- .afepll_info_g = {
- .pll_reg = cpu_to_le16(0x9f0),
- }
- },
- .switch_clk_g = {
- .switch_clk_info = 0x0,
- .bbp_lmac_clk_reg_val = 0x0,
- .umac_clock_reg_config = 0x0,
- .qspi_uart_clock_reg_config = 0x0
- }
- },
- {
- .pll_config_g = {
- .tapll_info_g = {
- .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
- (TA_PLL_M_VAL_20)),
- .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
- },
- .pll960_info_g = {
- .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
- (PLL960_N_VAL_20)),
- .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
- .pll_reg_3 = 0x0,
- },
- .afepll_info_g = {
- .pll_reg = cpu_to_le16(0x9f0),
- }
- },
- .switch_clk_g = {
- .switch_clk_info = 0x0,
- .bbp_lmac_clk_reg_val = 0x0,
- .umac_clock_reg_config = 0x0,
- .qspi_uart_clock_reg_config = 0x0
- }
- } },
- .buckboost_wakeup_cnt = 0x0,
- .pmu_wakeup_wait = 0x0,
- .shutdown_wait_time = 0x0,
- .pmu_slp_clkout_sel = 0x0,
- .wdt_prog_value = 0x0,
- .wdt_soc_rst_delay = 0x0,
- .dcdc_operation_mode = 0x0,
- .soc_reset_wait_cnt = 0x0
- };
- static struct bootup_params boot_params_40 = {
- .magic_number = cpu_to_le16(0x5aa5),
- .crystal_good_time = 0x0,
- .valid = cpu_to_le32(VALID_40),
- .reserved_for_valids = 0x0,
- .bootup_mode_info = 0x0,
- .digital_loop_back_params = 0x0,
- .rtls_timestamp_en = 0x0,
- .host_spi_intr_cfg = 0x0,
- .device_clk_info = {{
- .pll_config_g = {
- .tapll_info_g = {
- .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
- (TA_PLL_M_VAL_40)),
- .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
- },
- .pll960_info_g = {
- .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
- (PLL960_N_VAL_40)),
- .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
- .pll_reg_3 = 0x0,
- },
- .afepll_info_g = {
- .pll_reg = cpu_to_le16(0x9f0),
- }
- },
- .switch_clk_g = {
- .switch_clk_info = cpu_to_le16(0x09),
- .bbp_lmac_clk_reg_val = cpu_to_le16(0x1121),
- .umac_clock_reg_config = cpu_to_le16(0x48),
- .qspi_uart_clock_reg_config = 0x0
- }
- },
- {
- .pll_config_g = {
- .tapll_info_g = {
- .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
- (TA_PLL_M_VAL_40)),
- .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
- },
- .pll960_info_g = {
- .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
- (PLL960_N_VAL_40)),
- .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
- .pll_reg_3 = 0x0,
- },
- .afepll_info_g = {
- .pll_reg = cpu_to_le16(0x9f0),
- }
- },
- .switch_clk_g = {
- .switch_clk_info = 0x0,
- .bbp_lmac_clk_reg_val = 0x0,
- .umac_clock_reg_config = 0x0,
- .qspi_uart_clock_reg_config = 0x0
- }
- },
- {
- .pll_config_g = {
- .tapll_info_g = {
- .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
- (TA_PLL_M_VAL_40)),
- .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
- },
- .pll960_info_g = {
- .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
- (PLL960_N_VAL_40)),
- .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
- .pll_reg_3 = 0x0,
- },
- .afepll_info_g = {
- .pll_reg = cpu_to_le16(0x9f0),
- }
- },
- .switch_clk_g = {
- .switch_clk_info = 0x0,
- .bbp_lmac_clk_reg_val = 0x0,
- .umac_clock_reg_config = 0x0,
- .qspi_uart_clock_reg_config = 0x0
- }
- } },
- .buckboost_wakeup_cnt = 0x0,
- .pmu_wakeup_wait = 0x0,
- .shutdown_wait_time = 0x0,
- .pmu_slp_clkout_sel = 0x0,
- .wdt_prog_value = 0x0,
- .wdt_soc_rst_delay = 0x0,
- .dcdc_operation_mode = 0x0,
- .soc_reset_wait_cnt = 0x0
- };
- static u16 mcs[] = {13, 26, 39, 52, 78, 104, 117, 130};
- /**
- * rsi_set_default_parameters() - This function sets default parameters.
- * @common: Pointer to the driver private structure.
- *
- * Return: none
- */
- static void rsi_set_default_parameters(struct rsi_common *common)
- {
- common->band = NL80211_BAND_2GHZ;
- common->channel_width = BW_20MHZ;
- common->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
- common->channel = 1;
- common->min_rate = 0xffff;
- common->fsm_state = FSM_CARD_NOT_READY;
- common->iface_down = true;
- common->endpoint = EP_2GHZ_20MHZ;
- }
- /**
- * rsi_set_contention_vals() - This function sets the contention values for the
- * backoff procedure.
- * @common: Pointer to the driver private structure.
- *
- * Return: None.
- */
- static void rsi_set_contention_vals(struct rsi_common *common)
- {
- u8 ii = 0;
- for (; ii < NUM_EDCA_QUEUES; ii++) {
- common->tx_qinfo[ii].wme_params =
- (((common->edca_params[ii].cw_min / 2) +
- (common->edca_params[ii].aifs)) *
- WMM_SHORT_SLOT_TIME + SIFS_DURATION);
- common->tx_qinfo[ii].weight = common->tx_qinfo[ii].wme_params;
- common->tx_qinfo[ii].pkt_contended = 0;
- }
- }
- /**
- * rsi_send_internal_mgmt_frame() - This function sends management frames to
- * firmware.Also schedules packet to queue
- * for transmission.
- * @common: Pointer to the driver private structure.
- * @skb: Pointer to the socket buffer structure.
- *
- * Return: 0 on success, -1 on failure.
- */
- static int rsi_send_internal_mgmt_frame(struct rsi_common *common,
- struct sk_buff *skb)
- {
- struct skb_info *tx_params;
- if (skb == NULL) {
- rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__);
- return -ENOMEM;
- }
- tx_params = (struct skb_info *)&IEEE80211_SKB_CB(skb)->driver_data;
- tx_params->flags |= INTERNAL_MGMT_PKT;
- skb_queue_tail(&common->tx_queue[MGMT_SOFT_Q], skb);
- rsi_set_event(&common->tx_thread.event);
- return 0;
- }
- /**
- * rsi_load_radio_caps() - This function is used to send radio capabilities
- * values to firmware.
- * @common: Pointer to the driver private structure.
- *
- * Return: 0 on success, corresponding negative error code on failure.
- */
- static int rsi_load_radio_caps(struct rsi_common *common)
- {
- struct rsi_radio_caps *radio_caps;
- struct rsi_hw *adapter = common->priv;
- u16 inx = 0;
- u8 ii;
- u8 radio_id = 0;
- u16 gc[20] = {0xf0, 0xf0, 0xf0, 0xf0,
- 0xf0, 0xf0, 0xf0, 0xf0,
- 0xf0, 0xf0, 0xf0, 0xf0,
- 0xf0, 0xf0, 0xf0, 0xf0,
- 0xf0, 0xf0, 0xf0, 0xf0};
- struct sk_buff *skb;
- rsi_dbg(INFO_ZONE, "%s: Sending rate symbol req frame\n", __func__);
- skb = dev_alloc_skb(sizeof(struct rsi_radio_caps));
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, sizeof(struct rsi_radio_caps));
- radio_caps = (struct rsi_radio_caps *)skb->data;
- radio_caps->desc_word[1] = cpu_to_le16(RADIO_CAPABILITIES);
- radio_caps->desc_word[4] = cpu_to_le16(RSI_RF_TYPE << 8);
- if (common->channel_width == BW_40MHZ) {
- radio_caps->desc_word[7] |= cpu_to_le16(RSI_LMAC_CLOCK_80MHZ);
- radio_caps->desc_word[7] |= cpu_to_le16(RSI_ENABLE_40MHZ);
- if (common->fsm_state == FSM_MAC_INIT_DONE) {
- struct ieee80211_hw *hw = adapter->hw;
- struct ieee80211_conf *conf = &hw->conf;
- if (conf_is_ht40_plus(conf)) {
- radio_caps->desc_word[5] =
- cpu_to_le16(LOWER_20_ENABLE);
- radio_caps->desc_word[5] |=
- cpu_to_le16(LOWER_20_ENABLE >> 12);
- } else if (conf_is_ht40_minus(conf)) {
- radio_caps->desc_word[5] =
- cpu_to_le16(UPPER_20_ENABLE);
- radio_caps->desc_word[5] |=
- cpu_to_le16(UPPER_20_ENABLE >> 12);
- } else {
- radio_caps->desc_word[5] =
- cpu_to_le16(BW_40MHZ << 12);
- radio_caps->desc_word[5] |=
- cpu_to_le16(FULL40M_ENABLE);
- }
- }
- }
- radio_caps->sifs_tx_11n = cpu_to_le16(SIFS_TX_11N_VALUE);
- radio_caps->sifs_tx_11b = cpu_to_le16(SIFS_TX_11B_VALUE);
- radio_caps->slot_rx_11n = cpu_to_le16(SHORT_SLOT_VALUE);
- radio_caps->ofdm_ack_tout = cpu_to_le16(OFDM_ACK_TOUT_VALUE);
- radio_caps->cck_ack_tout = cpu_to_le16(CCK_ACK_TOUT_VALUE);
- radio_caps->preamble_type = cpu_to_le16(LONG_PREAMBLE);
- radio_caps->desc_word[7] |= cpu_to_le16(radio_id << 8);
- for (ii = 0; ii < MAX_HW_QUEUES; ii++) {
- radio_caps->qos_params[ii].cont_win_min_q = cpu_to_le16(3);
- radio_caps->qos_params[ii].cont_win_max_q = cpu_to_le16(0x3f);
- radio_caps->qos_params[ii].aifsn_val_q = cpu_to_le16(2);
- radio_caps->qos_params[ii].txop_q = 0;
- }
- for (ii = 0; ii < MAX_HW_QUEUES - 4; ii++) {
- radio_caps->qos_params[ii].cont_win_min_q =
- cpu_to_le16(common->edca_params[ii].cw_min);
- radio_caps->qos_params[ii].cont_win_max_q =
- cpu_to_le16(common->edca_params[ii].cw_max);
- radio_caps->qos_params[ii].aifsn_val_q =
- cpu_to_le16((common->edca_params[ii].aifs) << 8);
- radio_caps->qos_params[ii].txop_q =
- cpu_to_le16(common->edca_params[ii].txop);
- }
- memcpy(&common->rate_pwr[0], &gc[0], 40);
- for (ii = 0; ii < 20; ii++)
- radio_caps->gcpd_per_rate[inx++] =
- cpu_to_le16(common->rate_pwr[ii] & 0x00FF);
- radio_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_radio_caps) -
- FRAME_DESC_SZ) |
- (RSI_WIFI_MGMT_Q << 12));
- skb_put(skb, (sizeof(struct rsi_radio_caps)));
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /**
- * rsi_mgmt_pkt_to_core() - This function is the entry point for Mgmt module.
- * @common: Pointer to the driver private structure.
- * @msg: Pointer to received packet.
- * @msg_len: Length of the recieved packet.
- * @type: Type of recieved packet.
- *
- * Return: 0 on success, -1 on failure.
- */
- static int rsi_mgmt_pkt_to_core(struct rsi_common *common,
- u8 *msg,
- s32 msg_len,
- u8 type)
- {
- struct rsi_hw *adapter = common->priv;
- struct ieee80211_tx_info *info;
- struct skb_info *rx_params;
- u8 pad_bytes = msg[4];
- u8 pkt_recv;
- struct sk_buff *skb;
- char *buffer;
- if (type == RX_DOT11_MGMT) {
- if (!adapter->sc_nvifs)
- return -ENOLINK;
- msg_len -= pad_bytes;
- if (msg_len <= 0) {
- rsi_dbg(MGMT_RX_ZONE,
- "%s: Invalid rx msg of len = %d\n",
- __func__, msg_len);
- return -EINVAL;
- }
- skb = dev_alloc_skb(msg_len);
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed to allocate skb\n",
- __func__);
- return -ENOMEM;
- }
- buffer = skb_put(skb, msg_len);
- memcpy(buffer,
- (u8 *)(msg + FRAME_DESC_SZ + pad_bytes),
- msg_len);
- pkt_recv = buffer[0];
- info = IEEE80211_SKB_CB(skb);
- rx_params = (struct skb_info *)info->driver_data;
- rx_params->rssi = rsi_get_rssi(msg);
- rx_params->channel = rsi_get_channel(msg);
- rsi_indicate_pkt_to_os(common, skb);
- } else {
- rsi_dbg(MGMT_TX_ZONE, "%s: Internal Packet\n", __func__);
- }
- return 0;
- }
- /**
- * rsi_hal_send_sta_notify_frame() - This function sends the station notify
- * frame to firmware.
- * @common: Pointer to the driver private structure.
- * @opmode: Operating mode of device.
- * @notify_event: Notification about station connection.
- * @bssid: bssid.
- * @qos_enable: Qos is enabled.
- * @aid: Aid (unique for all STA).
- *
- * Return: status: 0 on success, corresponding negative error code on failure.
- */
- static int rsi_hal_send_sta_notify_frame(struct rsi_common *common,
- u8 opmode,
- u8 notify_event,
- const unsigned char *bssid,
- u8 qos_enable,
- u16 aid)
- {
- struct sk_buff *skb = NULL;
- struct rsi_peer_notify *peer_notify;
- u16 vap_id = 0;
- int status;
- rsi_dbg(MGMT_TX_ZONE, "%s: Sending sta notify frame\n", __func__);
- skb = dev_alloc_skb(sizeof(struct rsi_peer_notify));
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, sizeof(struct rsi_peer_notify));
- peer_notify = (struct rsi_peer_notify *)skb->data;
- peer_notify->command = cpu_to_le16(opmode << 1);
- switch (notify_event) {
- case STA_CONNECTED:
- peer_notify->command |= cpu_to_le16(RSI_ADD_PEER);
- break;
- case STA_DISCONNECTED:
- peer_notify->command |= cpu_to_le16(RSI_DELETE_PEER);
- break;
- default:
- break;
- }
- peer_notify->command |= cpu_to_le16((aid & 0xfff) << 4);
- ether_addr_copy(peer_notify->mac_addr, bssid);
- peer_notify->sta_flags = cpu_to_le32((qos_enable) ? 1 : 0);
- peer_notify->desc_word[0] =
- cpu_to_le16((sizeof(struct rsi_peer_notify) - FRAME_DESC_SZ) |
- (RSI_WIFI_MGMT_Q << 12));
- peer_notify->desc_word[1] = cpu_to_le16(PEER_NOTIFY);
- peer_notify->desc_word[7] |= cpu_to_le16(vap_id << 8);
- skb_put(skb, sizeof(struct rsi_peer_notify));
- status = rsi_send_internal_mgmt_frame(common, skb);
- if (!status && qos_enable) {
- rsi_set_contention_vals(common);
- status = rsi_load_radio_caps(common);
- }
- return status;
- }
- /**
- * rsi_send_aggregation_params_frame() - This function sends the ampdu
- * indication frame to firmware.
- * @common: Pointer to the driver private structure.
- * @tid: traffic identifier.
- * @ssn: ssn.
- * @buf_size: buffer size.
- * @event: notification about station connection.
- *
- * Return: 0 on success, corresponding negative error code on failure.
- */
- int rsi_send_aggregation_params_frame(struct rsi_common *common,
- u16 tid,
- u16 ssn,
- u8 buf_size,
- u8 event)
- {
- struct sk_buff *skb = NULL;
- struct rsi_mac_frame *mgmt_frame;
- u8 peer_id = 0;
- skb = dev_alloc_skb(FRAME_DESC_SZ);
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, FRAME_DESC_SZ);
- mgmt_frame = (struct rsi_mac_frame *)skb->data;
- rsi_dbg(MGMT_TX_ZONE, "%s: Sending AMPDU indication frame\n", __func__);
- mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
- mgmt_frame->desc_word[1] = cpu_to_le16(AMPDU_IND);
- if (event == STA_TX_ADDBA_DONE) {
- mgmt_frame->desc_word[4] = cpu_to_le16(ssn);
- mgmt_frame->desc_word[5] = cpu_to_le16(buf_size);
- mgmt_frame->desc_word[7] =
- cpu_to_le16((tid | (START_AMPDU_AGGR << 4) | (peer_id << 8)));
- } else if (event == STA_RX_ADDBA_DONE) {
- mgmt_frame->desc_word[4] = cpu_to_le16(ssn);
- mgmt_frame->desc_word[7] = cpu_to_le16(tid |
- (START_AMPDU_AGGR << 4) |
- (RX_BA_INDICATION << 5) |
- (peer_id << 8));
- } else if (event == STA_TX_DELBA) {
- mgmt_frame->desc_word[7] = cpu_to_le16(tid |
- (STOP_AMPDU_AGGR << 4) |
- (peer_id << 8));
- } else if (event == STA_RX_DELBA) {
- mgmt_frame->desc_word[7] = cpu_to_le16(tid |
- (STOP_AMPDU_AGGR << 4) |
- (RX_BA_INDICATION << 5) |
- (peer_id << 8));
- }
- skb_put(skb, FRAME_DESC_SZ);
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /**
- * rsi_program_bb_rf() - This function starts base band and RF programming.
- * This is called after initial configurations are done.
- * @common: Pointer to the driver private structure.
- *
- * Return: 0 on success, corresponding negative error code on failure.
- */
- static int rsi_program_bb_rf(struct rsi_common *common)
- {
- struct sk_buff *skb;
- struct rsi_mac_frame *mgmt_frame;
- rsi_dbg(MGMT_TX_ZONE, "%s: Sending program BB/RF frame\n", __func__);
- skb = dev_alloc_skb(FRAME_DESC_SZ);
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, FRAME_DESC_SZ);
- mgmt_frame = (struct rsi_mac_frame *)skb->data;
- mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
- mgmt_frame->desc_word[1] = cpu_to_le16(BBP_PROG_IN_TA);
- mgmt_frame->desc_word[4] = cpu_to_le16(common->endpoint);
- if (common->rf_reset) {
- mgmt_frame->desc_word[7] = cpu_to_le16(RF_RESET_ENABLE);
- rsi_dbg(MGMT_TX_ZONE, "%s: ===> RF RESET REQUEST SENT <===\n",
- __func__);
- common->rf_reset = 0;
- }
- common->bb_rf_prog_count = 1;
- mgmt_frame->desc_word[7] |= cpu_to_le16(PUT_BBP_RESET |
- BBP_REG_WRITE | (RSI_RF_TYPE << 4));
- skb_put(skb, FRAME_DESC_SZ);
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /**
- * rsi_set_vap_capabilities() - This function send vap capability to firmware.
- * @common: Pointer to the driver private structure.
- * @opmode: Operating mode of device.
- *
- * Return: 0 on success, corresponding negative error code on failure.
- */
- int rsi_set_vap_capabilities(struct rsi_common *common, enum opmode mode)
- {
- struct sk_buff *skb = NULL;
- struct rsi_vap_caps *vap_caps;
- struct rsi_hw *adapter = common->priv;
- struct ieee80211_hw *hw = adapter->hw;
- struct ieee80211_conf *conf = &hw->conf;
- u16 vap_id = 0;
- rsi_dbg(MGMT_TX_ZONE, "%s: Sending VAP capabilities frame\n", __func__);
- skb = dev_alloc_skb(sizeof(struct rsi_vap_caps));
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, sizeof(struct rsi_vap_caps));
- vap_caps = (struct rsi_vap_caps *)skb->data;
- vap_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_vap_caps) -
- FRAME_DESC_SZ) |
- (RSI_WIFI_MGMT_Q << 12));
- vap_caps->desc_word[1] = cpu_to_le16(VAP_CAPABILITIES);
- vap_caps->desc_word[4] = cpu_to_le16(mode |
- (common->channel_width << 8));
- vap_caps->desc_word[7] = cpu_to_le16((vap_id << 8) |
- (common->mac_id << 4) |
- common->radio_id);
- memcpy(vap_caps->mac_addr, common->mac_addr, IEEE80211_ADDR_LEN);
- vap_caps->keep_alive_period = cpu_to_le16(90);
- vap_caps->frag_threshold = cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD);
- vap_caps->rts_threshold = cpu_to_le16(common->rts_threshold);
- vap_caps->default_mgmt_rate = cpu_to_le32(RSI_RATE_6);
- if (common->band == NL80211_BAND_5GHZ) {
- vap_caps->default_ctrl_rate = cpu_to_le32(RSI_RATE_6);
- if (conf_is_ht40(&common->priv->hw->conf)) {
- vap_caps->default_ctrl_rate |=
- cpu_to_le32(FULL40M_ENABLE << 16);
- }
- } else {
- vap_caps->default_ctrl_rate = cpu_to_le32(RSI_RATE_1);
- if (conf_is_ht40_minus(conf))
- vap_caps->default_ctrl_rate |=
- cpu_to_le32(UPPER_20_ENABLE << 16);
- else if (conf_is_ht40_plus(conf))
- vap_caps->default_ctrl_rate |=
- cpu_to_le32(LOWER_20_ENABLE << 16);
- }
- vap_caps->default_data_rate = 0;
- vap_caps->beacon_interval = cpu_to_le16(200);
- vap_caps->dtim_period = cpu_to_le16(4);
- skb_put(skb, sizeof(*vap_caps));
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /**
- * rsi_hal_load_key() - This function is used to load keys within the firmware.
- * @common: Pointer to the driver private structure.
- * @data: Pointer to the key data.
- * @key_len: Key length to be loaded.
- * @key_type: Type of key: GROUP/PAIRWISE.
- * @key_id: Key index.
- * @cipher: Type of cipher used.
- *
- * Return: 0 on success, -1 on failure.
- */
- int rsi_hal_load_key(struct rsi_common *common,
- u8 *data,
- u16 key_len,
- u8 key_type,
- u8 key_id,
- u32 cipher)
- {
- struct sk_buff *skb = NULL;
- struct rsi_set_key *set_key;
- u16 key_descriptor = 0;
- rsi_dbg(MGMT_TX_ZONE, "%s: Sending load key frame\n", __func__);
- skb = dev_alloc_skb(sizeof(struct rsi_set_key));
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, sizeof(struct rsi_set_key));
- set_key = (struct rsi_set_key *)skb->data;
- if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
- (cipher == WLAN_CIPHER_SUITE_WEP104)) {
- key_len += 1;
- key_descriptor |= BIT(2);
- if (key_len >= 13)
- key_descriptor |= BIT(3);
- } else if (cipher != KEY_TYPE_CLEAR) {
- key_descriptor |= BIT(4);
- if (key_type == RSI_PAIRWISE_KEY)
- key_id = 0;
- if (cipher == WLAN_CIPHER_SUITE_TKIP)
- key_descriptor |= BIT(5);
- }
- key_descriptor |= (key_type | BIT(13) | (key_id << 14));
- set_key->desc_word[0] = cpu_to_le16((sizeof(struct rsi_set_key) -
- FRAME_DESC_SZ) |
- (RSI_WIFI_MGMT_Q << 12));
- set_key->desc_word[1] = cpu_to_le16(SET_KEY_REQ);
- set_key->desc_word[4] = cpu_to_le16(key_descriptor);
- if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
- (cipher == WLAN_CIPHER_SUITE_WEP104)) {
- memcpy(&set_key->key[key_id][1],
- data,
- key_len * 2);
- } else {
- memcpy(&set_key->key[0][0], data, key_len);
- }
- memcpy(set_key->tx_mic_key, &data[16], 8);
- memcpy(set_key->rx_mic_key, &data[24], 8);
- skb_put(skb, sizeof(struct rsi_set_key));
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /*
- * rsi_load_bootup_params() - This function send bootup params to the firmware.
- * @common: Pointer to the driver private structure.
- *
- * Return: 0 on success, corresponding error code on failure.
- */
- static int rsi_load_bootup_params(struct rsi_common *common)
- {
- struct sk_buff *skb;
- struct rsi_boot_params *boot_params;
- rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__);
- skb = dev_alloc_skb(sizeof(struct rsi_boot_params));
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, sizeof(struct rsi_boot_params));
- boot_params = (struct rsi_boot_params *)skb->data;
- rsi_dbg(MGMT_TX_ZONE, "%s:\n", __func__);
- if (common->channel_width == BW_40MHZ) {
- memcpy(&boot_params->bootup_params,
- &boot_params_40,
- sizeof(struct bootup_params));
- rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__,
- UMAC_CLK_40BW);
- boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40BW);
- } else {
- memcpy(&boot_params->bootup_params,
- &boot_params_20,
- sizeof(struct bootup_params));
- if (boot_params_20.valid != cpu_to_le32(VALID_20)) {
- boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_20BW);
- rsi_dbg(MGMT_TX_ZONE,
- "%s: Packet 20MHZ <=== %d\n", __func__,
- UMAC_CLK_20BW);
- } else {
- boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40MHZ);
- rsi_dbg(MGMT_TX_ZONE,
- "%s: Packet 20MHZ <=== %d\n", __func__,
- UMAC_CLK_40MHZ);
- }
- }
- /**
- * Bit{0:11} indicates length of the Packet
- * Bit{12:15} indicates host queue number
- */
- boot_params->desc_word[0] = cpu_to_le16(sizeof(struct bootup_params) |
- (RSI_WIFI_MGMT_Q << 12));
- boot_params->desc_word[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST);
- skb_put(skb, sizeof(struct rsi_boot_params));
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /**
- * rsi_send_reset_mac() - This function prepares reset MAC request and sends an
- * internal management frame to indicate it to firmware.
- * @common: Pointer to the driver private structure.
- *
- * Return: 0 on success, corresponding error code on failure.
- */
- static int rsi_send_reset_mac(struct rsi_common *common)
- {
- struct sk_buff *skb;
- struct rsi_mac_frame *mgmt_frame;
- rsi_dbg(MGMT_TX_ZONE, "%s: Sending reset MAC frame\n", __func__);
- skb = dev_alloc_skb(FRAME_DESC_SZ);
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, FRAME_DESC_SZ);
- mgmt_frame = (struct rsi_mac_frame *)skb->data;
- mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
- mgmt_frame->desc_word[1] = cpu_to_le16(RESET_MAC_REQ);
- mgmt_frame->desc_word[4] = cpu_to_le16(RETRY_COUNT << 8);
- skb_put(skb, FRAME_DESC_SZ);
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /**
- * rsi_band_check() - This function programs the band
- * @common: Pointer to the driver private structure.
- *
- * Return: 0 on success, corresponding error code on failure.
- */
- int rsi_band_check(struct rsi_common *common)
- {
- struct rsi_hw *adapter = common->priv;
- struct ieee80211_hw *hw = adapter->hw;
- u8 prev_bw = common->channel_width;
- u8 prev_ep = common->endpoint;
- struct ieee80211_channel *curchan = hw->conf.chandef.chan;
- int status = 0;
- if (common->band != curchan->band) {
- common->rf_reset = 1;
- common->band = curchan->band;
- }
- if ((hw->conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) ||
- (hw->conf.chandef.width == NL80211_CHAN_WIDTH_20))
- common->channel_width = BW_20MHZ;
- else
- common->channel_width = BW_40MHZ;
- if (common->band == NL80211_BAND_2GHZ) {
- if (common->channel_width)
- common->endpoint = EP_2GHZ_40MHZ;
- else
- common->endpoint = EP_2GHZ_20MHZ;
- } else {
- if (common->channel_width)
- common->endpoint = EP_5GHZ_40MHZ;
- else
- common->endpoint = EP_5GHZ_20MHZ;
- }
- if (common->endpoint != prev_ep) {
- status = rsi_program_bb_rf(common);
- if (status)
- return status;
- }
- if (common->channel_width != prev_bw) {
- status = rsi_load_bootup_params(common);
- if (status)
- return status;
- status = rsi_load_radio_caps(common);
- if (status)
- return status;
- }
- return status;
- }
- /**
- * rsi_set_channel() - This function programs the channel.
- * @common: Pointer to the driver private structure.
- * @channel: Channel value to be set.
- *
- * Return: 0 on success, corresponding error code on failure.
- */
- int rsi_set_channel(struct rsi_common *common, u16 channel)
- {
- struct sk_buff *skb = NULL;
- struct rsi_mac_frame *mgmt_frame;
- rsi_dbg(MGMT_TX_ZONE,
- "%s: Sending scan req frame\n", __func__);
- skb = dev_alloc_skb(FRAME_DESC_SZ);
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, FRAME_DESC_SZ);
- mgmt_frame = (struct rsi_mac_frame *)skb->data;
- mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
- mgmt_frame->desc_word[1] = cpu_to_le16(SCAN_REQUEST);
- mgmt_frame->desc_word[4] = cpu_to_le16(channel);
- mgmt_frame->desc_word[7] = cpu_to_le16(PUT_BBP_RESET |
- BBP_REG_WRITE |
- (RSI_RF_TYPE << 4));
- mgmt_frame->desc_word[5] = cpu_to_le16(0x01);
- mgmt_frame->desc_word[6] = cpu_to_le16(0x12);
- if (common->channel_width == BW_40MHZ)
- mgmt_frame->desc_word[5] |= cpu_to_le16(0x1 << 8);
- common->channel = channel;
- skb_put(skb, FRAME_DESC_SZ);
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /**
- * rsi_compare() - This function is used to compare two integers
- * @a: pointer to the first integer
- * @b: pointer to the second integer
- *
- * Return: 0 if both are equal, -1 if the first is smaller, else 1
- */
- static int rsi_compare(const void *a, const void *b)
- {
- u16 _a = *(const u16 *)(a);
- u16 _b = *(const u16 *)(b);
- if (_a > _b)
- return -1;
- if (_a < _b)
- return 1;
- return 0;
- }
- /**
- * rsi_map_rates() - This function is used to map selected rates to hw rates.
- * @rate: The standard rate to be mapped.
- * @offset: Offset that will be returned.
- *
- * Return: 0 if it is a mcs rate, else 1
- */
- static bool rsi_map_rates(u16 rate, int *offset)
- {
- int kk;
- for (kk = 0; kk < ARRAY_SIZE(rsi_mcsrates); kk++) {
- if (rate == mcs[kk]) {
- *offset = kk;
- return false;
- }
- }
- for (kk = 0; kk < ARRAY_SIZE(rsi_rates); kk++) {
- if (rate == rsi_rates[kk].bitrate / 5) {
- *offset = kk;
- break;
- }
- }
- return true;
- }
- /**
- * rsi_send_auto_rate_request() - This function is to set rates for connection
- * and send autorate request to firmware.
- * @common: Pointer to the driver private structure.
- *
- * Return: 0 on success, corresponding error code on failure.
- */
- static int rsi_send_auto_rate_request(struct rsi_common *common)
- {
- struct sk_buff *skb;
- struct rsi_auto_rate *auto_rate;
- int ii = 0, jj = 0, kk = 0;
- struct ieee80211_hw *hw = common->priv->hw;
- u8 band = hw->conf.chandef.chan->band;
- u8 num_supported_rates = 0;
- u8 rate_table_offset, rate_offset = 0;
- u32 rate_bitmap = common->bitrate_mask[band];
- u16 *selected_rates, min_rate;
- skb = dev_alloc_skb(sizeof(struct rsi_auto_rate));
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- selected_rates = kzalloc(2 * RSI_TBL_SZ, GFP_KERNEL);
- if (!selected_rates) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of mem\n",
- __func__);
- dev_kfree_skb(skb);
- return -ENOMEM;
- }
- memset(skb->data, 0, sizeof(struct rsi_auto_rate));
- auto_rate = (struct rsi_auto_rate *)skb->data;
- auto_rate->aarf_rssi = cpu_to_le16(((u16)3 << 6) | (u16)(18 & 0x3f));
- auto_rate->collision_tolerance = cpu_to_le16(3);
- auto_rate->failure_limit = cpu_to_le16(3);
- auto_rate->initial_boundary = cpu_to_le16(3);
- auto_rate->max_threshold_limt = cpu_to_le16(27);
- auto_rate->desc_word[1] = cpu_to_le16(AUTO_RATE_IND);
- if (common->channel_width == BW_40MHZ)
- auto_rate->desc_word[7] |= cpu_to_le16(1);
- if (band == NL80211_BAND_2GHZ) {
- min_rate = RSI_RATE_1;
- rate_table_offset = 0;
- } else {
- min_rate = RSI_RATE_6;
- rate_table_offset = 4;
- }
- for (ii = 0, jj = 0;
- ii < (ARRAY_SIZE(rsi_rates) - rate_table_offset); ii++) {
- if (rate_bitmap & BIT(ii)) {
- selected_rates[jj++] =
- (rsi_rates[ii + rate_table_offset].bitrate / 5);
- rate_offset++;
- }
- }
- num_supported_rates = jj;
- if (common->vif_info[0].is_ht) {
- for (ii = 0; ii < ARRAY_SIZE(mcs); ii++)
- selected_rates[jj++] = mcs[ii];
- num_supported_rates += ARRAY_SIZE(mcs);
- rate_offset += ARRAY_SIZE(mcs);
- }
- sort(selected_rates, jj, sizeof(u16), &rsi_compare, NULL);
- /* mapping the rates to RSI rates */
- for (ii = 0; ii < jj; ii++) {
- if (rsi_map_rates(selected_rates[ii], &kk)) {
- auto_rate->supported_rates[ii] =
- cpu_to_le16(rsi_rates[kk].hw_value);
- } else {
- auto_rate->supported_rates[ii] =
- cpu_to_le16(rsi_mcsrates[kk]);
- }
- }
- /* loading HT rates in the bottom half of the auto rate table */
- if (common->vif_info[0].is_ht) {
- for (ii = rate_offset, kk = ARRAY_SIZE(rsi_mcsrates) - 1;
- ii < rate_offset + 2 * ARRAY_SIZE(rsi_mcsrates); ii++) {
- if (common->vif_info[0].sgi ||
- conf_is_ht40(&common->priv->hw->conf))
- auto_rate->supported_rates[ii++] =
- cpu_to_le16(rsi_mcsrates[kk] | BIT(9));
- auto_rate->supported_rates[ii] =
- cpu_to_le16(rsi_mcsrates[kk--]);
- }
- for (; ii < (RSI_TBL_SZ - 1); ii++) {
- auto_rate->supported_rates[ii] =
- cpu_to_le16(rsi_mcsrates[0]);
- }
- }
- for (; ii < RSI_TBL_SZ; ii++)
- auto_rate->supported_rates[ii] = cpu_to_le16(min_rate);
- auto_rate->num_supported_rates = cpu_to_le16(num_supported_rates * 2);
- auto_rate->moderate_rate_inx = cpu_to_le16(num_supported_rates / 2);
- auto_rate->desc_word[7] |= cpu_to_le16(0 << 8);
- num_supported_rates *= 2;
- auto_rate->desc_word[0] = cpu_to_le16((sizeof(*auto_rate) -
- FRAME_DESC_SZ) |
- (RSI_WIFI_MGMT_Q << 12));
- skb_put(skb,
- sizeof(struct rsi_auto_rate));
- kfree(selected_rates);
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /**
- * rsi_inform_bss_status() - This function informs about bss status with the
- * help of sta notify params by sending an internal
- * management frame to firmware.
- * @common: Pointer to the driver private structure.
- * @status: Bss status type.
- * @bssid: Bssid.
- * @qos_enable: Qos is enabled.
- * @aid: Aid (unique for all STAs).
- *
- * Return: None.
- */
- void rsi_inform_bss_status(struct rsi_common *common,
- u8 status,
- const unsigned char *bssid,
- u8 qos_enable,
- u16 aid)
- {
- if (status) {
- rsi_hal_send_sta_notify_frame(common,
- RSI_IFTYPE_STATION,
- STA_CONNECTED,
- bssid,
- qos_enable,
- aid);
- if (common->min_rate == 0xffff)
- rsi_send_auto_rate_request(common);
- } else {
- rsi_hal_send_sta_notify_frame(common,
- RSI_IFTYPE_STATION,
- STA_DISCONNECTED,
- bssid,
- qos_enable,
- aid);
- }
- }
- /**
- * rsi_eeprom_read() - This function sends a frame to read the mac address
- * from the eeprom.
- * @common: Pointer to the driver private structure.
- *
- * Return: 0 on success, -1 on failure.
- */
- static int rsi_eeprom_read(struct rsi_common *common)
- {
- struct rsi_mac_frame *mgmt_frame;
- struct sk_buff *skb;
- rsi_dbg(MGMT_TX_ZONE, "%s: Sending EEPROM read req frame\n", __func__);
- skb = dev_alloc_skb(FRAME_DESC_SZ);
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, FRAME_DESC_SZ);
- mgmt_frame = (struct rsi_mac_frame *)skb->data;
- /* FrameType */
- mgmt_frame->desc_word[1] = cpu_to_le16(EEPROM_READ_TYPE);
- mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
- /* Number of bytes to read */
- mgmt_frame->desc_word[3] = cpu_to_le16(ETH_ALEN +
- WLAN_MAC_MAGIC_WORD_LEN +
- WLAN_HOST_MODE_LEN +
- WLAN_FW_VERSION_LEN);
- /* Address to read */
- mgmt_frame->desc_word[4] = cpu_to_le16(WLAN_MAC_EEPROM_ADDR);
- skb_put(skb, FRAME_DESC_SZ);
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /**
- * This function sends a frame to block/unblock
- * data queues in the firmware
- *
- * @param common Pointer to the driver private structure.
- * @param block event - block if true, unblock if false
- * @return 0 on success, -1 on failure.
- */
- int rsi_send_block_unblock_frame(struct rsi_common *common, bool block_event)
- {
- struct rsi_mac_frame *mgmt_frame;
- struct sk_buff *skb;
- rsi_dbg(MGMT_TX_ZONE, "%s: Sending block/unblock frame\n", __func__);
- skb = dev_alloc_skb(FRAME_DESC_SZ);
- if (!skb) {
- rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
- __func__);
- return -ENOMEM;
- }
- memset(skb->data, 0, FRAME_DESC_SZ);
- mgmt_frame = (struct rsi_mac_frame *)skb->data;
- mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
- mgmt_frame->desc_word[1] = cpu_to_le16(BLOCK_HW_QUEUE);
- if (block_event) {
- rsi_dbg(INFO_ZONE, "blocking the data qs\n");
- mgmt_frame->desc_word[4] = cpu_to_le16(0xf);
- } else {
- rsi_dbg(INFO_ZONE, "unblocking the data qs\n");
- mgmt_frame->desc_word[5] = cpu_to_le16(0xf);
- }
- skb_put(skb, FRAME_DESC_SZ);
- return rsi_send_internal_mgmt_frame(common, skb);
- }
- /**
- * rsi_handle_ta_confirm_type() - This function handles the confirm frames.
- * @common: Pointer to the driver private structure.
- * @msg: Pointer to received packet.
- *
- * Return: 0 on success, -1 on failure.
- */
- static int rsi_handle_ta_confirm_type(struct rsi_common *common,
- u8 *msg)
- {
- u8 sub_type = (msg[15] & 0xff);
- switch (sub_type) {
- case BOOTUP_PARAMS_REQUEST:
- rsi_dbg(FSM_ZONE, "%s: Boot up params confirm received\n",
- __func__);
- if (common->fsm_state == FSM_BOOT_PARAMS_SENT) {
- if (rsi_eeprom_read(common)) {
- common->fsm_state = FSM_CARD_NOT_READY;
- goto out;
- } else {
- common->fsm_state = FSM_EEPROM_READ_MAC_ADDR;
- }
- } else {
- rsi_dbg(INFO_ZONE,
- "%s: Received bootup params cfm in %d state\n",
- __func__, common->fsm_state);
- return 0;
- }
- break;
- case EEPROM_READ_TYPE:
- if (common->fsm_state == FSM_EEPROM_READ_MAC_ADDR) {
- if (msg[16] == MAGIC_WORD) {
- u8 offset = (FRAME_DESC_SZ + WLAN_HOST_MODE_LEN
- + WLAN_MAC_MAGIC_WORD_LEN);
- memcpy(common->mac_addr,
- &msg[offset],
- ETH_ALEN);
- memcpy(&common->fw_ver,
- &msg[offset + ETH_ALEN],
- sizeof(struct version_info));
- } else {
- common->fsm_state = FSM_CARD_NOT_READY;
- break;
- }
- if (rsi_send_reset_mac(common))
- goto out;
- else
- common->fsm_state = FSM_RESET_MAC_SENT;
- } else {
- rsi_dbg(ERR_ZONE,
- "%s: Received eeprom mac addr in %d state\n",
- __func__, common->fsm_state);
- return 0;
- }
- break;
- case RESET_MAC_REQ:
- if (common->fsm_state == FSM_RESET_MAC_SENT) {
- rsi_dbg(FSM_ZONE, "%s: Reset MAC cfm received\n",
- __func__);
- if (rsi_load_radio_caps(common))
- goto out;
- else
- common->fsm_state = FSM_RADIO_CAPS_SENT;
- } else {
- rsi_dbg(ERR_ZONE,
- "%s: Received reset mac cfm in %d state\n",
- __func__, common->fsm_state);
- return 0;
- }
- break;
- case RADIO_CAPABILITIES:
- if (common->fsm_state == FSM_RADIO_CAPS_SENT) {
- common->rf_reset = 1;
- if (rsi_program_bb_rf(common)) {
- goto out;
- } else {
- common->fsm_state = FSM_BB_RF_PROG_SENT;
- rsi_dbg(FSM_ZONE, "%s: Radio cap cfm received\n",
- __func__);
- }
- } else {
- rsi_dbg(INFO_ZONE,
- "%s: Received radio caps cfm in %d state\n",
- __func__, common->fsm_state);
- return 0;
- }
- break;
- case BB_PROG_VALUES_REQUEST:
- case RF_PROG_VALUES_REQUEST:
- case BBP_PROG_IN_TA:
- rsi_dbg(FSM_ZONE, "%s: BB/RF cfm received\n", __func__);
- if (common->fsm_state == FSM_BB_RF_PROG_SENT) {
- common->bb_rf_prog_count--;
- if (!common->bb_rf_prog_count) {
- common->fsm_state = FSM_MAC_INIT_DONE;
- return rsi_mac80211_attach(common);
- }
- } else {
- rsi_dbg(INFO_ZONE,
- "%s: Received bbb_rf cfm in %d state\n",
- __func__, common->fsm_state);
- return 0;
- }
- break;
- default:
- rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n",
- __func__);
- break;
- }
- return 0;
- out:
- rsi_dbg(ERR_ZONE, "%s: Unable to send pkt/Invalid frame received\n",
- __func__);
- return -EINVAL;
- }
- /**
- * rsi_mgmt_pkt_recv() - This function processes the management packets
- * recieved from the hardware.
- * @common: Pointer to the driver private structure.
- * @msg: Pointer to the received packet.
- *
- * Return: 0 on success, -1 on failure.
- */
- int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg)
- {
- s32 msg_len = (le16_to_cpu(*(__le16 *)&msg[0]) & 0x0fff);
- u16 msg_type = (msg[2]);
- int ret;
- rsi_dbg(FSM_ZONE, "%s: Msg Len: %d, Msg Type: %4x\n",
- __func__, msg_len, msg_type);
- if (msg_type == TA_CONFIRM_TYPE) {
- return rsi_handle_ta_confirm_type(common, msg);
- } else if (msg_type == CARD_READY_IND) {
- rsi_dbg(FSM_ZONE, "%s: Card ready indication received\n",
- __func__);
- if (common->fsm_state == FSM_CARD_NOT_READY) {
- rsi_set_default_parameters(common);
- ret = rsi_load_bootup_params(common);
- if (ret)
- return ret;
- else
- common->fsm_state = FSM_BOOT_PARAMS_SENT;
- } else {
- return -EINVAL;
- }
- } else if (msg_type == TX_STATUS_IND) {
- if (msg[15] == PROBEREQ_CONFIRM) {
- common->mgmt_q_block = false;
- rsi_dbg(FSM_ZONE, "%s: Probe confirm received\n",
- __func__);
- }
- } else {
- return rsi_mgmt_pkt_to_core(common, msg, msg_len, msg_type);
- }
- return 0;
- }
|