2 * Copyright (c) 2014 Redpine Signals Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/firmware.h>
18 #include <net/bluetooth/bluetooth.h>
22 #include "rsi_common.h"
25 static struct ta_metadata metadata_flash_content
[] = {
26 {"flash_content", 0x00010000},
27 {"rsi/rs9113_wlan_qspi.rps", 0x00010000},
28 {"rsi/rs9113_wlan_bt_dual_mode.rps", 0x00010000},
31 int rsi_send_pkt_to_bus(struct rsi_common
*common
, struct sk_buff
*skb
)
33 struct rsi_hw
*adapter
= common
->priv
;
36 if (common
->coex_mode
> 1)
37 mutex_lock(&common
->tx_bus_mutex
);
39 status
= adapter
->host_intf_ops
->write_pkt(common
->priv
,
42 if (common
->coex_mode
> 1)
43 mutex_unlock(&common
->tx_bus_mutex
);
48 int rsi_prepare_mgmt_desc(struct rsi_common
*common
, struct sk_buff
*skb
)
50 struct rsi_hw
*adapter
= common
->priv
;
51 struct ieee80211_hdr
*wh
= NULL
;
52 struct ieee80211_tx_info
*info
;
53 struct ieee80211_conf
*conf
= &adapter
->hw
->conf
;
54 struct ieee80211_vif
*vif
;
55 struct rsi_mgmt_desc
*mgmt_desc
;
56 struct skb_info
*tx_params
;
57 struct ieee80211_bss_conf
*bss
= NULL
;
58 struct rsi_xtended_desc
*xtend_desc
= NULL
;
60 u32 dword_align_bytes
= 0;
62 if (skb
->len
> MAX_MGMT_PKT_SIZE
) {
63 rsi_dbg(INFO_ZONE
, "%s: Dropping mgmt pkt > 512\n", __func__
);
67 info
= IEEE80211_SKB_CB(skb
);
68 tx_params
= (struct skb_info
*)info
->driver_data
;
71 /* Update header size */
72 header_size
= FRAME_DESC_SZ
+ sizeof(struct rsi_xtended_desc
);
73 if (header_size
> skb_headroom(skb
)) {
75 "%s: Failed to add extended descriptor\n",
79 skb_push(skb
, header_size
);
80 dword_align_bytes
= ((unsigned long)skb
->data
& 0x3f);
81 if (dword_align_bytes
> skb_headroom(skb
)) {
83 "%s: Failed to add dword align\n", __func__
);
86 skb_push(skb
, dword_align_bytes
);
87 header_size
+= dword_align_bytes
;
89 tx_params
->internal_hdr_size
= header_size
;
90 memset(&skb
->data
[0], 0, header_size
);
92 wh
= (struct ieee80211_hdr
*)&skb
->data
[header_size
];
94 mgmt_desc
= (struct rsi_mgmt_desc
*)skb
->data
;
95 xtend_desc
= (struct rsi_xtended_desc
*)&skb
->data
[FRAME_DESC_SZ
];
97 rsi_set_len_qno(&mgmt_desc
->len_qno
, (skb
->len
- FRAME_DESC_SZ
),
99 mgmt_desc
->frame_type
= TX_DOT11_MGMT
;
100 mgmt_desc
->header_len
= MIN_802_11_HDR_LEN
;
101 mgmt_desc
->xtend_desc_size
= header_size
- FRAME_DESC_SZ
;
102 mgmt_desc
->frame_info
|= cpu_to_le16(RATE_INFO_ENABLE
);
103 if (is_broadcast_ether_addr(wh
->addr1
))
104 mgmt_desc
->frame_info
|= cpu_to_le16(RSI_BROADCAST_PKT
);
106 mgmt_desc
->seq_ctrl
=
107 cpu_to_le16(IEEE80211_SEQ_TO_SN(le16_to_cpu(wh
->seq_ctrl
)));
108 if ((common
->band
== NL80211_BAND_2GHZ
) && !common
->p2p_enabled
)
109 mgmt_desc
->rate_info
= cpu_to_le16(RSI_RATE_1
);
111 mgmt_desc
->rate_info
= cpu_to_le16(RSI_RATE_6
);
113 if (conf_is_ht40(conf
))
114 mgmt_desc
->bbp_info
= cpu_to_le16(FULL40M_ENABLE
);
116 if (ieee80211_is_probe_resp(wh
->frame_control
)) {
117 mgmt_desc
->misc_flags
|= (RSI_ADD_DELTA_TSF_VAP_ID
|
118 RSI_FETCH_RETRY_CNT_FRM_HST
);
119 #define PROBE_RESP_RETRY_CNT 3
120 xtend_desc
->retry_cnt
= PROBE_RESP_RETRY_CNT
;
123 if (((vif
->type
== NL80211_IFTYPE_AP
) ||
124 (vif
->type
== NL80211_IFTYPE_P2P_GO
)) &&
125 (ieee80211_is_action(wh
->frame_control
))) {
126 struct rsi_sta
*rsta
= rsi_find_sta(common
, wh
->addr1
);
129 mgmt_desc
->sta_id
= tx_params
->sta_id
;
133 mgmt_desc
->rate_info
|=
134 cpu_to_le16((tx_params
->vap_id
<< RSI_DESC_VAP_ID_OFST
) &
135 RSI_DESC_VAP_ID_MASK
);
140 /* This function prepares descriptor for given data packet */
141 int rsi_prepare_data_desc(struct rsi_common
*common
, struct sk_buff
*skb
)
143 struct rsi_hw
*adapter
= common
->priv
;
144 struct ieee80211_vif
*vif
;
145 struct ieee80211_hdr
*wh
= NULL
;
146 struct ieee80211_tx_info
*info
;
147 struct skb_info
*tx_params
;
148 struct ieee80211_bss_conf
*bss
;
149 struct rsi_data_desc
*data_desc
;
150 struct rsi_xtended_desc
*xtend_desc
;
151 u8 ieee80211_size
= MIN_802_11_HDR_LEN
;
154 u8 dword_align_bytes
;
157 info
= IEEE80211_SKB_CB(skb
);
158 vif
= info
->control
.vif
;
159 bss
= &vif
->bss_conf
;
160 tx_params
= (struct skb_info
*)info
->driver_data
;
162 header_size
= FRAME_DESC_SZ
+ sizeof(struct rsi_xtended_desc
);
163 if (header_size
> skb_headroom(skb
)) {
164 rsi_dbg(ERR_ZONE
, "%s: Unable to send pkt\n", __func__
);
167 skb_push(skb
, header_size
);
168 dword_align_bytes
= ((unsigned long)skb
->data
& 0x3f);
169 if (header_size
> skb_headroom(skb
)) {
170 rsi_dbg(ERR_ZONE
, "%s: Not enough headroom\n", __func__
);
173 skb_push(skb
, dword_align_bytes
);
174 header_size
+= dword_align_bytes
;
176 tx_params
->internal_hdr_size
= header_size
;
177 data_desc
= (struct rsi_data_desc
*)skb
->data
;
178 memset(data_desc
, 0, header_size
);
180 xtend_desc
= (struct rsi_xtended_desc
*)&skb
->data
[FRAME_DESC_SZ
];
181 wh
= (struct ieee80211_hdr
*)&skb
->data
[header_size
];
182 seq_num
= IEEE80211_SEQ_TO_SN(le16_to_cpu(wh
->seq_ctrl
));
184 data_desc
->xtend_desc_size
= header_size
- FRAME_DESC_SZ
;
186 if (ieee80211_is_data_qos(wh
->frame_control
)) {
188 data_desc
->mac_flags
|= cpu_to_le16(RSI_QOS_ENABLE
);
191 if (((vif
->type
== NL80211_IFTYPE_STATION
) ||
192 (vif
->type
== NL80211_IFTYPE_P2P_CLIENT
)) &&
193 (adapter
->ps_state
== PS_ENABLED
))
194 wh
->frame_control
|= cpu_to_le16(RSI_SET_PS_ENABLE
);
196 if ((!(info
->flags
& IEEE80211_TX_INTFL_DONT_ENCRYPT
)) &&
197 (common
->secinfo
.security_enable
)) {
198 if (rsi_is_cipher_wep(common
))
202 data_desc
->mac_flags
|= cpu_to_le16(RSI_ENCRYPT_PKT
);
204 rsi_set_len_qno(&data_desc
->len_qno
, (skb
->len
- FRAME_DESC_SZ
),
206 data_desc
->header_len
= ieee80211_size
;
208 if (common
->min_rate
!= RSI_RATE_AUTO
) {
209 /* Send fixed rate */
210 data_desc
->frame_info
= cpu_to_le16(RATE_INFO_ENABLE
);
211 data_desc
->rate_info
= cpu_to_le16(common
->min_rate
);
213 if (conf_is_ht40(&common
->priv
->hw
->conf
))
214 data_desc
->bbp_info
= cpu_to_le16(FULL40M_ENABLE
);
216 if ((common
->vif_info
[0].sgi
) && (common
->min_rate
& 0x100)) {
218 data_desc
->rate_info
|=
219 cpu_to_le16(ENABLE_SHORTGI_RATE
);
223 if (skb
->protocol
== cpu_to_be16(ETH_P_PAE
)) {
224 rsi_dbg(INFO_ZONE
, "*** Tx EAPOL ***\n");
226 data_desc
->frame_info
= cpu_to_le16(RATE_INFO_ENABLE
);
227 if (common
->band
== NL80211_BAND_5GHZ
)
228 data_desc
->rate_info
= cpu_to_le16(RSI_RATE_6
);
230 data_desc
->rate_info
= cpu_to_le16(RSI_RATE_1
);
231 data_desc
->mac_flags
|= cpu_to_le16(RSI_REKEY_PURPOSE
);
232 data_desc
->misc_flags
|= RSI_FETCH_RETRY_CNT_FRM_HST
;
233 #define EAPOL_RETRY_CNT 15
234 xtend_desc
->retry_cnt
= EAPOL_RETRY_CNT
;
236 if (common
->eapol4_confirm
)
237 skb
->priority
= VO_Q
;
239 rsi_set_len_qno(&data_desc
->len_qno
,
240 (skb
->len
- FRAME_DESC_SZ
),
242 if ((skb
->len
- header_size
) == EAPOL4_PACKET_LEN
) {
243 data_desc
->misc_flags
|=
244 RSI_DESC_REQUIRE_CFM_TO_HOST
;
245 xtend_desc
->confirm_frame_type
= EAPOL4_CONFIRM
;
249 data_desc
->mac_flags
= cpu_to_le16(seq_num
& 0xfff);
250 data_desc
->qid_tid
= ((skb
->priority
& 0xf) |
251 ((tx_params
->tid
& 0xf) << 4));
252 data_desc
->sta_id
= tx_params
->sta_id
;
254 if ((is_broadcast_ether_addr(wh
->addr1
)) ||
255 (is_multicast_ether_addr(wh
->addr1
))) {
256 data_desc
->frame_info
= cpu_to_le16(RATE_INFO_ENABLE
);
257 data_desc
->frame_info
|= cpu_to_le16(RSI_BROADCAST_PKT
);
258 data_desc
->sta_id
= vap_id
;
260 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
261 (vif
->type
== NL80211_IFTYPE_P2P_GO
)) {
262 if (common
->band
== NL80211_BAND_5GHZ
)
263 data_desc
->rate_info
= cpu_to_le16(RSI_RATE_6
);
265 data_desc
->rate_info
= cpu_to_le16(RSI_RATE_1
);
268 if (((vif
->type
== NL80211_IFTYPE_AP
) ||
269 (vif
->type
== NL80211_IFTYPE_P2P_GO
)) &&
270 (ieee80211_has_moredata(wh
->frame_control
)))
271 data_desc
->frame_info
|= cpu_to_le16(MORE_DATA_PRESENT
);
273 data_desc
->rate_info
|=
274 cpu_to_le16((tx_params
->vap_id
<< RSI_DESC_VAP_ID_OFST
) &
275 RSI_DESC_VAP_ID_MASK
);
280 /* This function sends received data packet from driver to device */
281 int rsi_send_data_pkt(struct rsi_common
*common
, struct sk_buff
*skb
)
283 struct rsi_hw
*adapter
= common
->priv
;
284 struct ieee80211_vif
*vif
;
285 struct ieee80211_tx_info
*info
;
286 struct skb_info
*tx_params
;
287 struct ieee80211_bss_conf
*bss
;
288 struct ieee80211_hdr
*wh
;
289 int status
= -EINVAL
;
294 if (common
->iface_down
)
297 info
= IEEE80211_SKB_CB(skb
);
298 if (!info
->control
.vif
)
300 vif
= info
->control
.vif
;
301 bss
= &vif
->bss_conf
;
302 tx_params
= (struct skb_info
*)info
->driver_data
;
303 header_size
= tx_params
->internal_hdr_size
;
304 wh
= (struct ieee80211_hdr
*)&skb
->data
[header_size
];
306 if (((vif
->type
== NL80211_IFTYPE_STATION
) ||
307 (vif
->type
== NL80211_IFTYPE_P2P_CLIENT
)) &&
311 status
= rsi_send_pkt_to_bus(common
, skb
);
313 rsi_dbg(ERR_ZONE
, "%s: Failed to write pkt\n", __func__
);
316 ++common
->tx_stats
.total_tx_pkt_freed
[skb
->priority
];
317 rsi_indicate_tx_status(adapter
, skb
, status
);
322 * rsi_send_mgmt_pkt() - This functions sends the received management packet
323 * from driver to device.
324 * @common: Pointer to the driver private structure.
325 * @skb: Pointer to the socket buffer structure.
327 * Return: status: 0 on success, -1 on failure.
329 int rsi_send_mgmt_pkt(struct rsi_common
*common
,
332 struct rsi_hw
*adapter
= common
->priv
;
333 struct ieee80211_bss_conf
*bss
;
334 struct ieee80211_hdr
*wh
;
335 struct ieee80211_tx_info
*info
;
336 struct skb_info
*tx_params
;
337 struct rsi_mgmt_desc
*mgmt_desc
;
338 struct rsi_xtended_desc
*xtend_desc
;
342 info
= IEEE80211_SKB_CB(skb
);
343 tx_params
= (struct skb_info
*)info
->driver_data
;
344 header_size
= tx_params
->internal_hdr_size
;
346 if (tx_params
->flags
& INTERNAL_MGMT_PKT
) {
347 status
= adapter
->host_intf_ops
->write_pkt(common
->priv
,
352 "%s: Failed to write the packet\n", __func__
);
358 bss
= &info
->control
.vif
->bss_conf
;
359 wh
= (struct ieee80211_hdr
*)&skb
->data
[header_size
];
360 mgmt_desc
= (struct rsi_mgmt_desc
*)skb
->data
;
361 xtend_desc
= (struct rsi_xtended_desc
*)&skb
->data
[FRAME_DESC_SZ
];
363 /* Indicate to firmware to give cfm for probe */
364 if (ieee80211_is_probe_req(wh
->frame_control
) && !bss
->assoc
) {
366 "%s: blocking mgmt queue\n", __func__
);
367 mgmt_desc
->misc_flags
= RSI_DESC_REQUIRE_CFM_TO_HOST
;
368 xtend_desc
->confirm_frame_type
= PROBEREQ_CONFIRM
;
369 common
->mgmt_q_block
= true;
370 rsi_dbg(INFO_ZONE
, "Mgmt queue blocked\n");
373 status
= rsi_send_pkt_to_bus(common
, skb
);
375 rsi_dbg(ERR_ZONE
, "%s: Failed to write the packet\n", __func__
);
377 rsi_indicate_tx_status(common
->priv
, skb
, status
);
381 int rsi_send_bt_pkt(struct rsi_common
*common
, struct sk_buff
*skb
)
383 int status
= -EINVAL
;
385 struct rsi_bt_desc
*bt_desc
;
386 u8 queueno
= ((skb
->data
[1] >> 4) & 0xf);
388 if (queueno
== RSI_BT_MGMT_Q
) {
389 status
= rsi_send_pkt_to_bus(common
, skb
);
391 rsi_dbg(ERR_ZONE
, "%s: Failed to write bt mgmt pkt\n",
395 header_size
= FRAME_DESC_SZ
;
396 if (header_size
> skb_headroom(skb
)) {
397 rsi_dbg(ERR_ZONE
, "%s: Not enough headroom\n", __func__
);
401 skb_push(skb
, header_size
);
402 memset(skb
->data
, 0, header_size
);
403 bt_desc
= (struct rsi_bt_desc
*)skb
->data
;
405 rsi_set_len_qno(&bt_desc
->len_qno
, (skb
->len
- FRAME_DESC_SZ
),
407 bt_desc
->bt_pkt_type
= cpu_to_le16(bt_cb(skb
)->pkt_type
);
409 status
= rsi_send_pkt_to_bus(common
, skb
);
411 rsi_dbg(ERR_ZONE
, "%s: Failed to write bt pkt\n", __func__
);
418 int rsi_prepare_beacon(struct rsi_common
*common
, struct sk_buff
*skb
)
420 struct rsi_hw
*adapter
= (struct rsi_hw
*)common
->priv
;
421 struct rsi_data_desc
*bcn_frm
;
422 struct ieee80211_hw
*hw
= common
->priv
->hw
;
423 struct ieee80211_conf
*conf
= &hw
->conf
;
424 struct ieee80211_vif
*vif
;
425 struct sk_buff
*mac_bcn
;
429 for (i
= 0; i
< RSI_MAX_VIFS
; i
++) {
430 vif
= adapter
->vifs
[i
];
433 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
434 (vif
->type
== NL80211_IFTYPE_P2P_GO
))
439 mac_bcn
= ieee80211_beacon_get_tim(adapter
->hw
,
443 rsi_dbg(ERR_ZONE
, "Failed to get beacon from mac80211\n");
447 common
->beacon_cnt
++;
448 bcn_frm
= (struct rsi_data_desc
*)skb
->data
;
449 rsi_set_len_qno(&bcn_frm
->len_qno
, mac_bcn
->len
, RSI_WIFI_DATA_Q
);
450 bcn_frm
->header_len
= MIN_802_11_HDR_LEN
;
451 bcn_frm
->frame_info
= cpu_to_le16(RSI_DATA_DESC_MAC_BBP_INFO
|
452 RSI_DATA_DESC_NO_ACK_IND
|
453 RSI_DATA_DESC_BEACON_FRAME
|
454 RSI_DATA_DESC_INSERT_TSF
|
455 RSI_DATA_DESC_INSERT_SEQ_NO
|
457 bcn_frm
->rate_info
= cpu_to_le16(vap_id
<< 14);
458 bcn_frm
->qid_tid
= BEACON_HW_Q
;
460 if (conf_is_ht40_plus(conf
)) {
461 bcn_frm
->bbp_info
= cpu_to_le16(LOWER_20_ENABLE
);
462 bcn_frm
->bbp_info
|= cpu_to_le16(LOWER_20_ENABLE
>> 12);
463 } else if (conf_is_ht40_minus(conf
)) {
464 bcn_frm
->bbp_info
= cpu_to_le16(UPPER_20_ENABLE
);
465 bcn_frm
->bbp_info
|= cpu_to_le16(UPPER_20_ENABLE
>> 12);
468 if (common
->band
== NL80211_BAND_2GHZ
)
469 bcn_frm
->bbp_info
|= cpu_to_le16(RSI_RATE_1
);
471 bcn_frm
->bbp_info
|= cpu_to_le16(RSI_RATE_6
);
473 if (mac_bcn
->data
[tim_offset
+ 2] == 0)
474 bcn_frm
->frame_info
|= cpu_to_le16(RSI_DATA_DESC_DTIM_BEACON
);
476 memcpy(&skb
->data
[FRAME_DESC_SZ
], mac_bcn
->data
, mac_bcn
->len
);
477 skb_put(skb
, mac_bcn
->len
+ FRAME_DESC_SZ
);
479 dev_kfree_skb(mac_bcn
);
484 static void bl_cmd_timeout(struct timer_list
*t
)
486 struct rsi_hw
*adapter
= from_timer(adapter
, t
, bl_cmd_timer
);
488 adapter
->blcmd_timer_expired
= true;
489 del_timer(&adapter
->bl_cmd_timer
);
492 static int bl_start_cmd_timer(struct rsi_hw
*adapter
, u32 timeout
)
494 timer_setup(&adapter
->bl_cmd_timer
, bl_cmd_timeout
, 0);
495 adapter
->bl_cmd_timer
.expires
= (msecs_to_jiffies(timeout
) + jiffies
);
497 adapter
->blcmd_timer_expired
= false;
498 add_timer(&adapter
->bl_cmd_timer
);
503 static int bl_stop_cmd_timer(struct rsi_hw
*adapter
)
505 adapter
->blcmd_timer_expired
= false;
506 if (timer_pending(&adapter
->bl_cmd_timer
))
507 del_timer(&adapter
->bl_cmd_timer
);
512 static int bl_write_cmd(struct rsi_hw
*adapter
, u8 cmd
, u8 exp_resp
,
515 struct rsi_host_intf_ops
*hif_ops
= adapter
->host_intf_ops
;
516 u32 regin_val
= 0, regout_val
= 0;
521 regin_input
= (REGIN_INPUT
| adapter
->priv
->coex_mode
);
523 while (!adapter
->blcmd_timer_expired
) {
525 status
= hif_ops
->master_reg_read(adapter
, SWBL_REGIN
,
529 "%s: Command %0x REGIN reading failed..\n",
534 if ((regin_val
>> 12) != REGIN_VALID
)
537 if (adapter
->blcmd_timer_expired
) {
539 "%s: Command %0x REGIN reading timed out..\n",
545 "Issuing write to Regin val:%0x sending cmd:%0x\n",
546 regin_val
, (cmd
| regin_input
<< 8));
547 status
= hif_ops
->master_reg_write(adapter
, SWBL_REGIN
,
548 (cmd
| regin_input
<< 8), 2);
553 if (cmd
== LOAD_HOSTED_FW
|| cmd
== JUMP_TO_ZERO_PC
) {
554 /* JUMP_TO_ZERO_PC doesn't expect
555 * any response. So return from here
560 while (!adapter
->blcmd_timer_expired
) {
562 status
= hif_ops
->master_reg_read(adapter
, SWBL_REGOUT
,
566 "%s: Command %0x REGOUT reading failed..\n",
571 if ((regout_val
>> 8) == REGOUT_VALID
)
574 if (adapter
->blcmd_timer_expired
) {
576 "%s: Command %0x REGOUT reading timed out..\n",
581 *cmd_resp
= ((u16
*)®out_val
)[0] & 0xffff;
583 output
= ((u8
*)®out_val
)[0] & 0xff;
585 status
= hif_ops
->master_reg_write(adapter
, SWBL_REGOUT
,
586 (cmd
| REGOUT_INVALID
<< 8), 2);
589 "%s: Command %0x REGOUT writing failed..\n",
595 if (output
!= exp_resp
) {
597 "%s: Recvd resp %x for cmd %0x\n",
598 __func__
, output
, cmd
);
602 "%s: Recvd Expected resp %x for cmd %0x\n",
603 __func__
, output
, cmd
);
608 static int bl_cmd(struct rsi_hw
*adapter
, u8 cmd
, u8 exp_resp
, char *str
)
614 if ((cmd
== EOF_REACHED
) || (cmd
== PING_VALID
) || (cmd
== PONG_VALID
))
615 timeout
= BL_BURN_TIMEOUT
;
617 timeout
= BL_CMD_TIMEOUT
;
619 bl_start_cmd_timer(adapter
, timeout
);
620 status
= bl_write_cmd(adapter
, cmd
, exp_resp
, ®out_val
);
623 "%s: Command %s (%0x) writing failed..\n",
627 bl_stop_cmd_timer(adapter
);
631 #define CHECK_SUM_OFFSET 20
633 #define ADDR_OFFSET 16
634 static int bl_write_header(struct rsi_hw
*adapter
, u8
*flash_content
,
637 struct rsi_host_intf_ops
*hif_ops
= adapter
->host_intf_ops
;
638 struct bl_header
*bl_hdr
;
639 u32 write_addr
, write_len
;
642 bl_hdr
= kzalloc(sizeof(*bl_hdr
), GFP_KERNEL
);
647 bl_hdr
->image_no
= cpu_to_le32(adapter
->priv
->coex_mode
);
649 cpu_to_le32(*(u32
*)&flash_content
[CHECK_SUM_OFFSET
]);
650 bl_hdr
->flash_start_address
=
651 cpu_to_le32(*(u32
*)&flash_content
[ADDR_OFFSET
]);
652 bl_hdr
->flash_len
= cpu_to_le32(*(u32
*)&flash_content
[LEN_OFFSET
]);
653 write_len
= sizeof(struct bl_header
);
655 if (adapter
->rsi_host_intf
== RSI_HOST_INTF_USB
) {
656 write_addr
= PING_BUFFER_ADDRESS
;
657 status
= hif_ops
->write_reg_multiple(adapter
, write_addr
,
658 (u8
*)bl_hdr
, write_len
);
661 "%s: Failed to load Version/CRC structure\n",
666 write_addr
= PING_BUFFER_ADDRESS
>> 16;
667 status
= hif_ops
->master_access_msword(adapter
, write_addr
);
670 "%s: Unable to set ms word to common reg\n",
674 write_addr
= RSI_SD_REQUEST_MASTER
|
675 (PING_BUFFER_ADDRESS
& 0xFFFF);
676 status
= hif_ops
->write_reg_multiple(adapter
, write_addr
,
677 (u8
*)bl_hdr
, write_len
);
680 "%s: Failed to load Version/CRC structure\n",
691 static u32
read_flash_capacity(struct rsi_hw
*adapter
)
695 if ((adapter
->host_intf_ops
->master_reg_read(adapter
, FLASH_SIZE_ADDR
,
696 &flash_sz
, 2)) < 0) {
698 "%s: Flash size reading failed..\n",
702 rsi_dbg(INIT_ZONE
, "Flash capacity: %d KiloBytes\n", flash_sz
);
704 return (flash_sz
* 1024); /* Return size in kbytes */
707 static int ping_pong_write(struct rsi_hw
*adapter
, u8 cmd
, u8
*addr
, u32 size
)
709 struct rsi_host_intf_ops
*hif_ops
= adapter
->host_intf_ops
;
710 u32 block_size
= adapter
->block_size
;
712 u16 cmd_resp
, cmd_req
;
716 if (cmd
== PING_WRITE
) {
717 cmd_addr
= PING_BUFFER_ADDRESS
;
718 cmd_resp
= PONG_AVAIL
;
719 cmd_req
= PING_VALID
;
722 cmd_addr
= PONG_BUFFER_ADDRESS
;
723 cmd_resp
= PING_AVAIL
;
724 cmd_req
= PONG_VALID
;
728 status
= hif_ops
->load_data_master_write(adapter
, cmd_addr
, size
,
731 rsi_dbg(ERR_ZONE
, "%s: Unable to write blk at addr %0x\n",
736 status
= bl_cmd(adapter
, cmd_req
, cmd_resp
, str
);
738 bl_stop_cmd_timer(adapter
);
744 static int auto_fw_upgrade(struct rsi_hw
*adapter
, u8
*flash_content
,
747 u8 cmd
, *temp_flash_content
;
748 u32 temp_content_size
, num_flash
, index
;
749 u32 flash_start_address
;
752 temp_flash_content
= flash_content
;
754 if (content_size
> MAX_FLASH_FILE_SIZE
) {
756 "%s: Flash Content size is more than 400K %u\n",
757 __func__
, MAX_FLASH_FILE_SIZE
);
761 flash_start_address
= *(u32
*)&flash_content
[FLASH_START_ADDRESS
];
762 rsi_dbg(INFO_ZONE
, "flash start address: %08x\n", flash_start_address
);
764 if (flash_start_address
< FW_IMAGE_MIN_ADDRESS
) {
766 "%s: Fw image Flash Start Address is less than 64K\n",
771 if (flash_start_address
% FLASH_SECTOR_SIZE
) {
773 "%s: Flash Start Address is not multiple of 4K\n",
778 if ((flash_start_address
+ content_size
) > adapter
->flash_capacity
) {
780 "%s: Flash Content will cross max flash size\n",
785 temp_content_size
= content_size
;
786 num_flash
= content_size
/ FLASH_WRITE_CHUNK_SIZE
;
788 rsi_dbg(INFO_ZONE
, "content_size: %d, num_flash: %d\n",
789 content_size
, num_flash
);
791 for (index
= 0; index
<= num_flash
; index
++) {
792 rsi_dbg(INFO_ZONE
, "flash index: %d\n", index
);
793 if (index
!= num_flash
) {
794 content_size
= FLASH_WRITE_CHUNK_SIZE
;
795 rsi_dbg(INFO_ZONE
, "QSPI content_size:%d\n",
799 temp_content_size
% FLASH_WRITE_CHUNK_SIZE
;
801 "Writing last sector content_size:%d\n",
804 rsi_dbg(INFO_ZONE
, "instruction size zero\n");
814 status
= ping_pong_write(adapter
, cmd
, flash_content
,
817 rsi_dbg(ERR_ZONE
, "%s: Unable to load %d block\n",
823 "%s: Successfully loaded %d instructions\n",
825 flash_content
+= content_size
;
828 status
= bl_cmd(adapter
, EOF_REACHED
, FW_LOADING_SUCCESSFUL
,
831 bl_stop_cmd_timer(adapter
);
834 rsi_dbg(INFO_ZONE
, "FW loading is done and FW is running..\n");
838 static int rsi_load_firmware(struct rsi_hw
*adapter
)
840 struct rsi_common
*common
= adapter
->priv
;
841 struct rsi_host_intf_ops
*hif_ops
= adapter
->host_intf_ops
;
842 const struct firmware
*fw_entry
= NULL
;
843 u32 regout_val
= 0, content_size
;
844 u16 tmp_regout_val
= 0;
845 u8
*flash_content
= NULL
;
846 struct ta_metadata
*metadata_p
;
849 bl_start_cmd_timer(adapter
, BL_CMD_TIMEOUT
);
851 while (!adapter
->blcmd_timer_expired
) {
852 status
= hif_ops
->master_reg_read(adapter
, SWBL_REGOUT
,
856 "%s: REGOUT read failed\n", __func__
);
860 if ((regout_val
>> 8) == REGOUT_VALID
)
863 if (adapter
->blcmd_timer_expired
) {
864 rsi_dbg(ERR_ZONE
, "%s: REGOUT read timedout\n", __func__
);
866 "%s: Soft boot loader not present\n", __func__
);
869 bl_stop_cmd_timer(adapter
);
871 rsi_dbg(INFO_ZONE
, "Received Board Version Number: %x\n",
872 (regout_val
& 0xff));
874 status
= hif_ops
->master_reg_write(adapter
, SWBL_REGOUT
,
875 (REGOUT_INVALID
| REGOUT_INVALID
<< 8),
878 rsi_dbg(ERR_ZONE
, "%s: REGOUT writing failed..\n", __func__
);
883 status
= bl_cmd(adapter
, CONFIG_AUTO_READ_MODE
, CMD_PASS
,
888 adapter
->flash_capacity
= read_flash_capacity(adapter
);
889 if (adapter
->flash_capacity
<= 0) {
891 "%s: Unable to read flash size from EEPROM\n",
896 metadata_p
= &metadata_flash_content
[adapter
->priv
->coex_mode
];
898 rsi_dbg(INIT_ZONE
, "%s: Loading file %s\n", __func__
, metadata_p
->name
);
899 adapter
->fw_file_name
= metadata_p
->name
;
901 status
= request_firmware(&fw_entry
, metadata_p
->name
, adapter
->device
);
903 rsi_dbg(ERR_ZONE
, "%s: Failed to open file %s\n",
904 __func__
, metadata_p
->name
);
907 flash_content
= kmemdup(fw_entry
->data
, fw_entry
->size
, GFP_KERNEL
);
908 if (!flash_content
) {
909 rsi_dbg(ERR_ZONE
, "%s: Failed to copy firmware\n", __func__
);
913 content_size
= fw_entry
->size
;
914 rsi_dbg(INFO_ZONE
, "FW Length = %d bytes\n", content_size
);
916 /* Get the firmware version */
917 common
->lmac_ver
.ver
.info
.fw_ver
[0] =
918 flash_content
[LMAC_VER_OFFSET
] & 0xFF;
919 common
->lmac_ver
.ver
.info
.fw_ver
[1] =
920 flash_content
[LMAC_VER_OFFSET
+ 1] & 0xFF;
921 common
->lmac_ver
.major
= flash_content
[LMAC_VER_OFFSET
+ 2] & 0xFF;
922 common
->lmac_ver
.release_num
=
923 flash_content
[LMAC_VER_OFFSET
+ 3] & 0xFF;
924 common
->lmac_ver
.minor
= flash_content
[LMAC_VER_OFFSET
+ 4] & 0xFF;
925 common
->lmac_ver
.patch_num
= 0;
926 rsi_print_version(common
);
928 status
= bl_write_header(adapter
, flash_content
, content_size
);
931 "%s: RPS Image header loading failed\n",
936 bl_start_cmd_timer(adapter
, BL_CMD_TIMEOUT
);
937 status
= bl_write_cmd(adapter
, CHECK_CRC
, CMD_PASS
, &tmp_regout_val
);
939 bl_stop_cmd_timer(adapter
);
941 "%s: CHECK_CRC Command writing failed..\n",
943 if ((tmp_regout_val
& 0xff) == CMD_FAIL
) {
945 "CRC Fail.. Proceeding to Upgrade mode\n");
949 bl_stop_cmd_timer(adapter
);
951 status
= bl_cmd(adapter
, POLLING_MODE
, CMD_PASS
, "POLLING_MODE");
956 status
= bl_cmd(adapter
, LOAD_HOSTED_FW
, LOADING_INITIATED
,
960 rsi_dbg(INFO_ZONE
, "Load Image command passed..\n");
964 status
= bl_cmd(adapter
, BURN_HOSTED_FW
, SEND_RPS_FILE
, "FW_UPGRADE");
968 rsi_dbg(INFO_ZONE
, "Burn Command Pass.. Upgrading the firmware\n");
970 status
= auto_fw_upgrade(adapter
, flash_content
, content_size
);
972 rsi_dbg(ERR_ZONE
, "Firmware upgradation Done\n");
975 rsi_dbg(ERR_ZONE
, "Firmware upgrade failed\n");
977 status
= bl_cmd(adapter
, CONFIG_AUTO_READ_MODE
, CMD_PASS
,
983 rsi_dbg(ERR_ZONE
, "***** Firmware Loading successful *****\n");
984 kfree(flash_content
);
985 release_firmware(fw_entry
);
989 rsi_dbg(ERR_ZONE
, "##### Firmware loading failed #####\n");
990 kfree(flash_content
);
991 release_firmware(fw_entry
);
995 int rsi_hal_device_init(struct rsi_hw
*adapter
)
997 struct rsi_common
*common
= adapter
->priv
;
999 switch (adapter
->device_model
) {
1001 if (rsi_load_firmware(adapter
)) {
1003 "%s: Failed to load TA instructions\n",
1011 common
->fsm_state
= FSM_CARD_NOT_READY
;
1015 EXPORT_SYMBOL_GPL(rsi_hal_device_init
);