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},
29 {"flash_content", 0x00010000},
30 {"rsi/rs9113_ap_bt_dual_mode.rps", 0x00010000},
34 static struct ta_metadata metadata
[] = {{"pmemdata_dummy", 0x00000000},
35 {"rsi/rs9116_wlan.rps", 0x00000000},
36 {"rsi/rs9116_wlan_bt_classic.rps", 0x00000000},
37 {"rsi/pmemdata_dummy", 0x00000000},
38 {"rsi/rs9116_wlan_bt_classic.rps", 0x00000000}
41 int rsi_send_pkt_to_bus(struct rsi_common
*common
, struct sk_buff
*skb
)
43 struct rsi_hw
*adapter
= common
->priv
;
46 if (common
->coex_mode
> 1)
47 mutex_lock(&common
->tx_bus_mutex
);
49 status
= adapter
->host_intf_ops
->write_pkt(common
->priv
,
52 if (common
->coex_mode
> 1)
53 mutex_unlock(&common
->tx_bus_mutex
);
58 int rsi_prepare_mgmt_desc(struct rsi_common
*common
, struct sk_buff
*skb
)
60 struct rsi_hw
*adapter
= common
->priv
;
61 struct ieee80211_hdr
*wh
= NULL
;
62 struct ieee80211_tx_info
*info
;
63 struct ieee80211_conf
*conf
= &adapter
->hw
->conf
;
64 struct ieee80211_vif
*vif
;
65 struct rsi_mgmt_desc
*mgmt_desc
;
66 struct skb_info
*tx_params
;
67 struct rsi_xtended_desc
*xtend_desc
= NULL
;
69 u32 dword_align_bytes
= 0;
71 if (skb
->len
> MAX_MGMT_PKT_SIZE
) {
72 rsi_dbg(INFO_ZONE
, "%s: Dropping mgmt pkt > 512\n", __func__
);
76 info
= IEEE80211_SKB_CB(skb
);
77 tx_params
= (struct skb_info
*)info
->driver_data
;
80 /* Update header size */
81 header_size
= FRAME_DESC_SZ
+ sizeof(struct rsi_xtended_desc
);
82 if (header_size
> skb_headroom(skb
)) {
84 "%s: Failed to add extended descriptor\n",
88 skb_push(skb
, header_size
);
89 dword_align_bytes
= ((unsigned long)skb
->data
& 0x3f);
90 if (dword_align_bytes
> skb_headroom(skb
)) {
92 "%s: Failed to add dword align\n", __func__
);
95 skb_push(skb
, dword_align_bytes
);
96 header_size
+= dword_align_bytes
;
98 tx_params
->internal_hdr_size
= header_size
;
99 memset(&skb
->data
[0], 0, header_size
);
100 wh
= (struct ieee80211_hdr
*)&skb
->data
[header_size
];
102 mgmt_desc
= (struct rsi_mgmt_desc
*)skb
->data
;
103 xtend_desc
= (struct rsi_xtended_desc
*)&skb
->data
[FRAME_DESC_SZ
];
105 rsi_set_len_qno(&mgmt_desc
->len_qno
, (skb
->len
- FRAME_DESC_SZ
),
107 mgmt_desc
->frame_type
= TX_DOT11_MGMT
;
108 mgmt_desc
->header_len
= MIN_802_11_HDR_LEN
;
109 mgmt_desc
->xtend_desc_size
= header_size
- FRAME_DESC_SZ
;
111 if (ieee80211_is_probe_req(wh
->frame_control
))
112 mgmt_desc
->frame_info
= cpu_to_le16(RSI_INSERT_SEQ_IN_FW
);
113 mgmt_desc
->frame_info
|= cpu_to_le16(RATE_INFO_ENABLE
);
114 if (is_broadcast_ether_addr(wh
->addr1
))
115 mgmt_desc
->frame_info
|= cpu_to_le16(RSI_BROADCAST_PKT
);
117 mgmt_desc
->seq_ctrl
=
118 cpu_to_le16(IEEE80211_SEQ_TO_SN(le16_to_cpu(wh
->seq_ctrl
)));
119 if ((common
->band
== NL80211_BAND_2GHZ
) && !common
->p2p_enabled
)
120 mgmt_desc
->rate_info
= cpu_to_le16(RSI_RATE_1
);
122 mgmt_desc
->rate_info
= cpu_to_le16(RSI_RATE_6
);
124 if (conf_is_ht40(conf
))
125 mgmt_desc
->bbp_info
= cpu_to_le16(FULL40M_ENABLE
);
127 if (ieee80211_is_probe_resp(wh
->frame_control
)) {
128 mgmt_desc
->misc_flags
|= (RSI_ADD_DELTA_TSF_VAP_ID
|
129 RSI_FETCH_RETRY_CNT_FRM_HST
);
130 #define PROBE_RESP_RETRY_CNT 3
131 xtend_desc
->retry_cnt
= PROBE_RESP_RETRY_CNT
;
134 if (((vif
->type
== NL80211_IFTYPE_AP
) ||
135 (vif
->type
== NL80211_IFTYPE_P2P_GO
)) &&
136 (ieee80211_is_action(wh
->frame_control
))) {
137 struct rsi_sta
*rsta
= rsi_find_sta(common
, wh
->addr1
);
140 mgmt_desc
->sta_id
= tx_params
->sta_id
;
144 mgmt_desc
->rate_info
|=
145 cpu_to_le16((tx_params
->vap_id
<< RSI_DESC_VAP_ID_OFST
) &
146 RSI_DESC_VAP_ID_MASK
);
151 /* This function prepares descriptor for given data packet */
152 int rsi_prepare_data_desc(struct rsi_common
*common
, struct sk_buff
*skb
)
154 struct rsi_hw
*adapter
= common
->priv
;
155 struct ieee80211_vif
*vif
;
156 struct ieee80211_hdr
*wh
= NULL
;
157 struct ieee80211_tx_info
*info
;
158 struct skb_info
*tx_params
;
159 struct rsi_data_desc
*data_desc
;
160 struct rsi_xtended_desc
*xtend_desc
;
161 u8 ieee80211_size
= MIN_802_11_HDR_LEN
;
164 u8 dword_align_bytes
;
168 info
= IEEE80211_SKB_CB(skb
);
169 vif
= info
->control
.vif
;
170 tx_params
= (struct skb_info
*)info
->driver_data
;
172 tx_eapol
= IEEE80211_SKB_CB(skb
)->control
.flags
&
173 IEEE80211_TX_CTRL_PORT_CTRL_PROTO
;
175 header_size
= FRAME_DESC_SZ
+ sizeof(struct rsi_xtended_desc
);
176 if (header_size
> skb_headroom(skb
)) {
177 rsi_dbg(ERR_ZONE
, "%s: Unable to send pkt\n", __func__
);
180 skb_push(skb
, header_size
);
181 dword_align_bytes
= ((unsigned long)skb
->data
& 0x3f);
182 if (header_size
> skb_headroom(skb
)) {
183 rsi_dbg(ERR_ZONE
, "%s: Not enough headroom\n", __func__
);
186 skb_push(skb
, dword_align_bytes
);
187 header_size
+= dword_align_bytes
;
189 tx_params
->internal_hdr_size
= header_size
;
190 data_desc
= (struct rsi_data_desc
*)skb
->data
;
191 memset(data_desc
, 0, header_size
);
193 xtend_desc
= (struct rsi_xtended_desc
*)&skb
->data
[FRAME_DESC_SZ
];
194 wh
= (struct ieee80211_hdr
*)&skb
->data
[header_size
];
195 seq_num
= IEEE80211_SEQ_TO_SN(le16_to_cpu(wh
->seq_ctrl
));
197 data_desc
->xtend_desc_size
= header_size
- FRAME_DESC_SZ
;
199 if (ieee80211_is_data_qos(wh
->frame_control
)) {
201 data_desc
->mac_flags
|= cpu_to_le16(RSI_QOS_ENABLE
);
204 if (((vif
->type
== NL80211_IFTYPE_STATION
) ||
205 (vif
->type
== NL80211_IFTYPE_P2P_CLIENT
)) &&
206 (adapter
->ps_state
== PS_ENABLED
))
207 wh
->frame_control
|= cpu_to_le16(RSI_SET_PS_ENABLE
);
209 if ((!(info
->flags
& IEEE80211_TX_INTFL_DONT_ENCRYPT
)) &&
210 tx_params
->have_key
) {
211 if (rsi_is_cipher_wep(common
))
215 data_desc
->mac_flags
|= cpu_to_le16(RSI_ENCRYPT_PKT
);
217 rsi_set_len_qno(&data_desc
->len_qno
, (skb
->len
- FRAME_DESC_SZ
),
219 data_desc
->header_len
= ieee80211_size
;
221 if (common
->rate_config
[common
->band
].fixed_enabled
) {
222 /* Send fixed rate */
223 u16 fixed_rate
= common
->rate_config
[common
->band
].fixed_hw_rate
;
225 data_desc
->frame_info
= cpu_to_le16(RATE_INFO_ENABLE
);
226 data_desc
->rate_info
= cpu_to_le16(fixed_rate
);
228 if (conf_is_ht40(&common
->priv
->hw
->conf
))
229 data_desc
->bbp_info
= cpu_to_le16(FULL40M_ENABLE
);
231 if (common
->vif_info
[0].sgi
&& (fixed_rate
& 0x100)) {
233 data_desc
->rate_info
|=
234 cpu_to_le16(ENABLE_SHORTGI_RATE
);
239 rsi_dbg(INFO_ZONE
, "*** Tx EAPOL ***\n");
241 data_desc
->frame_info
= cpu_to_le16(RATE_INFO_ENABLE
);
242 if (common
->band
== NL80211_BAND_5GHZ
)
243 data_desc
->rate_info
= cpu_to_le16(RSI_RATE_6
);
245 data_desc
->rate_info
= cpu_to_le16(RSI_RATE_1
);
246 data_desc
->mac_flags
|= cpu_to_le16(RSI_REKEY_PURPOSE
);
247 data_desc
->misc_flags
|= RSI_FETCH_RETRY_CNT_FRM_HST
;
248 #define EAPOL_RETRY_CNT 15
249 xtend_desc
->retry_cnt
= EAPOL_RETRY_CNT
;
251 if (common
->eapol4_confirm
)
252 skb
->priority
= VO_Q
;
254 rsi_set_len_qno(&data_desc
->len_qno
,
255 (skb
->len
- FRAME_DESC_SZ
),
257 if (((skb
->len
- header_size
) == EAPOL4_PACKET_LEN
) ||
258 ((skb
->len
- header_size
) == EAPOL4_PACKET_LEN
- 2)) {
259 data_desc
->misc_flags
|=
260 RSI_DESC_REQUIRE_CFM_TO_HOST
;
261 xtend_desc
->confirm_frame_type
= EAPOL4_CONFIRM
;
265 data_desc
->mac_flags
|= cpu_to_le16(seq_num
& 0xfff);
266 data_desc
->qid_tid
= ((skb
->priority
& 0xf) |
267 ((tx_params
->tid
& 0xf) << 4));
268 data_desc
->sta_id
= tx_params
->sta_id
;
270 if ((is_broadcast_ether_addr(wh
->addr1
)) ||
271 (is_multicast_ether_addr(wh
->addr1
))) {
272 data_desc
->frame_info
= cpu_to_le16(RATE_INFO_ENABLE
);
273 data_desc
->frame_info
|= cpu_to_le16(RSI_BROADCAST_PKT
);
274 data_desc
->sta_id
= vap_id
;
276 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
277 (vif
->type
== NL80211_IFTYPE_P2P_GO
)) {
278 if (common
->band
== NL80211_BAND_5GHZ
)
279 data_desc
->rate_info
= cpu_to_le16(RSI_RATE_6
);
281 data_desc
->rate_info
= cpu_to_le16(RSI_RATE_1
);
284 if (((vif
->type
== NL80211_IFTYPE_AP
) ||
285 (vif
->type
== NL80211_IFTYPE_P2P_GO
)) &&
286 (ieee80211_has_moredata(wh
->frame_control
)))
287 data_desc
->frame_info
|= cpu_to_le16(MORE_DATA_PRESENT
);
289 data_desc
->rate_info
|=
290 cpu_to_le16((tx_params
->vap_id
<< RSI_DESC_VAP_ID_OFST
) &
291 RSI_DESC_VAP_ID_MASK
);
296 /* This function sends received data packet from driver to device */
297 int rsi_send_data_pkt(struct rsi_common
*common
, struct sk_buff
*skb
)
299 struct rsi_hw
*adapter
= common
->priv
;
300 struct ieee80211_vif
*vif
;
301 struct ieee80211_tx_info
*info
;
302 int status
= -EINVAL
;
306 if (common
->iface_down
)
309 info
= IEEE80211_SKB_CB(skb
);
310 if (!info
->control
.vif
)
312 vif
= info
->control
.vif
;
314 if (((vif
->type
== NL80211_IFTYPE_STATION
) ||
315 (vif
->type
== NL80211_IFTYPE_P2P_CLIENT
)) &&
319 status
= rsi_send_pkt_to_bus(common
, skb
);
321 rsi_dbg(ERR_ZONE
, "%s: Failed to write pkt\n", __func__
);
324 ++common
->tx_stats
.total_tx_pkt_freed
[skb
->priority
];
325 rsi_indicate_tx_status(adapter
, skb
, status
);
330 * rsi_send_mgmt_pkt() - This functions sends the received management packet
331 * from driver to device.
332 * @common: Pointer to the driver private structure.
333 * @skb: Pointer to the socket buffer structure.
335 * Return: status: 0 on success, -1 on failure.
337 int rsi_send_mgmt_pkt(struct rsi_common
*common
,
340 struct rsi_hw
*adapter
= common
->priv
;
341 struct ieee80211_hdr
*wh
;
342 struct ieee80211_tx_info
*info
;
343 struct skb_info
*tx_params
;
344 struct rsi_mgmt_desc
*mgmt_desc
;
345 struct rsi_xtended_desc
*xtend_desc
;
349 info
= IEEE80211_SKB_CB(skb
);
350 tx_params
= (struct skb_info
*)info
->driver_data
;
351 header_size
= tx_params
->internal_hdr_size
;
353 if (tx_params
->flags
& INTERNAL_MGMT_PKT
) {
354 status
= adapter
->host_intf_ops
->write_pkt(common
->priv
,
359 "%s: Failed to write the packet\n", __func__
);
365 wh
= (struct ieee80211_hdr
*)&skb
->data
[header_size
];
366 mgmt_desc
= (struct rsi_mgmt_desc
*)skb
->data
;
367 xtend_desc
= (struct rsi_xtended_desc
*)&skb
->data
[FRAME_DESC_SZ
];
369 /* Indicate to firmware to give cfm for probe */
370 if (ieee80211_is_probe_req(wh
->frame_control
) &&
371 !info
->control
.vif
->cfg
.assoc
) {
373 "%s: blocking mgmt queue\n", __func__
);
374 mgmt_desc
->misc_flags
= RSI_DESC_REQUIRE_CFM_TO_HOST
;
375 xtend_desc
->confirm_frame_type
= PROBEREQ_CONFIRM
;
376 common
->mgmt_q_block
= true;
377 rsi_dbg(INFO_ZONE
, "Mgmt queue blocked\n");
380 status
= rsi_send_pkt_to_bus(common
, skb
);
382 rsi_dbg(ERR_ZONE
, "%s: Failed to write the packet\n", __func__
);
384 rsi_indicate_tx_status(common
->priv
, skb
, status
);
388 int rsi_send_bt_pkt(struct rsi_common
*common
, struct sk_buff
*skb
)
390 int status
= -EINVAL
;
392 struct rsi_bt_desc
*bt_desc
;
393 u8 queueno
= ((skb
->data
[1] >> 4) & 0xf);
395 if (queueno
== RSI_BT_MGMT_Q
) {
396 status
= rsi_send_pkt_to_bus(common
, skb
);
398 rsi_dbg(ERR_ZONE
, "%s: Failed to write bt mgmt pkt\n",
402 header_size
= FRAME_DESC_SZ
;
403 if (header_size
> skb_headroom(skb
)) {
404 rsi_dbg(ERR_ZONE
, "%s: Not enough headroom\n", __func__
);
408 skb_push(skb
, header_size
);
409 memset(skb
->data
, 0, header_size
);
410 bt_desc
= (struct rsi_bt_desc
*)skb
->data
;
412 rsi_set_len_qno(&bt_desc
->len_qno
, (skb
->len
- FRAME_DESC_SZ
),
414 bt_desc
->bt_pkt_type
= cpu_to_le16(bt_cb(skb
)->pkt_type
);
416 status
= rsi_send_pkt_to_bus(common
, skb
);
418 rsi_dbg(ERR_ZONE
, "%s: Failed to write bt pkt\n", __func__
);
425 int rsi_prepare_beacon(struct rsi_common
*common
, struct sk_buff
*skb
)
427 struct rsi_hw
*adapter
= common
->priv
;
428 struct rsi_data_desc
*bcn_frm
;
429 struct ieee80211_hw
*hw
= common
->priv
->hw
;
430 struct ieee80211_conf
*conf
= &hw
->conf
;
431 struct ieee80211_vif
*vif
;
432 struct sk_buff
*mac_bcn
;
436 for (i
= 0; i
< RSI_MAX_VIFS
; i
++) {
437 vif
= adapter
->vifs
[i
];
440 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
441 (vif
->type
== NL80211_IFTYPE_P2P_GO
))
446 mac_bcn
= ieee80211_beacon_get_tim(adapter
->hw
,
448 &tim_offset
, NULL
, 0);
450 rsi_dbg(ERR_ZONE
, "Failed to get beacon from mac80211\n");
454 common
->beacon_cnt
++;
455 bcn_frm
= (struct rsi_data_desc
*)skb
->data
;
456 rsi_set_len_qno(&bcn_frm
->len_qno
, mac_bcn
->len
, RSI_WIFI_DATA_Q
);
457 bcn_frm
->header_len
= MIN_802_11_HDR_LEN
;
458 bcn_frm
->frame_info
= cpu_to_le16(RSI_DATA_DESC_MAC_BBP_INFO
|
459 RSI_DATA_DESC_NO_ACK_IND
|
460 RSI_DATA_DESC_BEACON_FRAME
|
461 RSI_DATA_DESC_INSERT_TSF
|
462 RSI_DATA_DESC_INSERT_SEQ_NO
|
464 bcn_frm
->rate_info
= cpu_to_le16(vap_id
<< 14);
465 bcn_frm
->qid_tid
= BEACON_HW_Q
;
467 if (conf_is_ht40_plus(conf
)) {
468 bcn_frm
->bbp_info
= cpu_to_le16(LOWER_20_ENABLE
);
469 bcn_frm
->bbp_info
|= cpu_to_le16(LOWER_20_ENABLE
>> 12);
470 } else if (conf_is_ht40_minus(conf
)) {
471 bcn_frm
->bbp_info
= cpu_to_le16(UPPER_20_ENABLE
);
472 bcn_frm
->bbp_info
|= cpu_to_le16(UPPER_20_ENABLE
>> 12);
475 if (common
->band
== NL80211_BAND_2GHZ
)
476 bcn_frm
->rate_info
|= cpu_to_le16(RSI_RATE_1
);
478 bcn_frm
->rate_info
|= cpu_to_le16(RSI_RATE_6
);
480 if (mac_bcn
->data
[tim_offset
+ 2] == 0)
481 bcn_frm
->frame_info
|= cpu_to_le16(RSI_DATA_DESC_DTIM_BEACON
);
483 memcpy(&skb
->data
[FRAME_DESC_SZ
], mac_bcn
->data
, mac_bcn
->len
);
484 skb_put(skb
, mac_bcn
->len
+ FRAME_DESC_SZ
);
486 dev_kfree_skb(mac_bcn
);
491 static void bl_cmd_timeout(struct timer_list
*t
)
493 struct rsi_hw
*adapter
= from_timer(adapter
, t
, bl_cmd_timer
);
495 adapter
->blcmd_timer_expired
= true;
496 del_timer(&adapter
->bl_cmd_timer
);
499 static int bl_start_cmd_timer(struct rsi_hw
*adapter
, u32 timeout
)
501 timer_setup(&adapter
->bl_cmd_timer
, bl_cmd_timeout
, 0);
502 adapter
->bl_cmd_timer
.expires
= (msecs_to_jiffies(timeout
) + jiffies
);
504 adapter
->blcmd_timer_expired
= false;
505 add_timer(&adapter
->bl_cmd_timer
);
510 static int bl_stop_cmd_timer(struct rsi_hw
*adapter
)
512 adapter
->blcmd_timer_expired
= false;
513 if (timer_pending(&adapter
->bl_cmd_timer
))
514 del_timer(&adapter
->bl_cmd_timer
);
519 static int bl_write_cmd(struct rsi_hw
*adapter
, u8 cmd
, u8 exp_resp
,
522 struct rsi_host_intf_ops
*hif_ops
= adapter
->host_intf_ops
;
523 u32 regin_val
= 0, regout_val
= 0;
528 regin_input
= (REGIN_INPUT
| adapter
->priv
->coex_mode
);
530 while (!adapter
->blcmd_timer_expired
) {
532 status
= hif_ops
->master_reg_read(adapter
, SWBL_REGIN
,
536 "%s: Command %0x REGIN reading failed..\n",
541 if ((regin_val
>> 12) != REGIN_VALID
)
544 if (adapter
->blcmd_timer_expired
) {
546 "%s: Command %0x REGIN reading timed out..\n",
552 "Issuing write to Regin val:%0x sending cmd:%0x\n",
553 regin_val
, (cmd
| regin_input
<< 8));
554 status
= hif_ops
->master_reg_write(adapter
, SWBL_REGIN
,
555 (cmd
| regin_input
<< 8), 2);
560 if (cmd
== LOAD_HOSTED_FW
|| cmd
== JUMP_TO_ZERO_PC
) {
561 /* JUMP_TO_ZERO_PC doesn't expect
562 * any response. So return from here
567 while (!adapter
->blcmd_timer_expired
) {
569 status
= hif_ops
->master_reg_read(adapter
, SWBL_REGOUT
,
573 "%s: Command %0x REGOUT reading failed..\n",
578 if ((regout_val
>> 8) == REGOUT_VALID
)
581 if (adapter
->blcmd_timer_expired
) {
583 "%s: Command %0x REGOUT reading timed out..\n",
588 *cmd_resp
= ((u16
*)®out_val
)[0] & 0xffff;
590 output
= ((u8
*)®out_val
)[0] & 0xff;
592 status
= hif_ops
->master_reg_write(adapter
, SWBL_REGOUT
,
593 (cmd
| REGOUT_INVALID
<< 8), 2);
596 "%s: Command %0x REGOUT writing failed..\n",
602 if (output
!= exp_resp
) {
604 "%s: Recvd resp %x for cmd %0x\n",
605 __func__
, output
, cmd
);
609 "%s: Recvd Expected resp %x for cmd %0x\n",
610 __func__
, output
, cmd
);
615 static int bl_cmd(struct rsi_hw
*adapter
, u8 cmd
, u8 exp_resp
, char *str
)
621 if ((cmd
== EOF_REACHED
) || (cmd
== PING_VALID
) || (cmd
== PONG_VALID
))
622 timeout
= BL_BURN_TIMEOUT
;
624 timeout
= BL_CMD_TIMEOUT
;
626 bl_start_cmd_timer(adapter
, timeout
);
627 status
= bl_write_cmd(adapter
, cmd
, exp_resp
, ®out_val
);
629 bl_stop_cmd_timer(adapter
);
631 "%s: Command %s (%0x) writing failed..\n",
635 bl_stop_cmd_timer(adapter
);
639 #define CHECK_SUM_OFFSET 20
641 #define ADDR_OFFSET 16
642 static int bl_write_header(struct rsi_hw
*adapter
, u8
*flash_content
,
645 struct rsi_host_intf_ops
*hif_ops
= adapter
->host_intf_ops
;
646 struct bl_header
*bl_hdr
;
647 u32 write_addr
, write_len
;
650 bl_hdr
= kzalloc(sizeof(*bl_hdr
), GFP_KERNEL
);
655 bl_hdr
->image_no
= cpu_to_le32(adapter
->priv
->coex_mode
);
657 cpu_to_le32(*(u32
*)&flash_content
[CHECK_SUM_OFFSET
]);
658 bl_hdr
->flash_start_address
=
659 cpu_to_le32(*(u32
*)&flash_content
[ADDR_OFFSET
]);
660 bl_hdr
->flash_len
= cpu_to_le32(*(u32
*)&flash_content
[LEN_OFFSET
]);
661 write_len
= sizeof(struct bl_header
);
663 if (adapter
->rsi_host_intf
== RSI_HOST_INTF_USB
) {
664 write_addr
= PING_BUFFER_ADDRESS
;
665 status
= hif_ops
->write_reg_multiple(adapter
, write_addr
,
666 (u8
*)bl_hdr
, write_len
);
669 "%s: Failed to load Version/CRC structure\n",
674 write_addr
= PING_BUFFER_ADDRESS
>> 16;
675 status
= hif_ops
->master_access_msword(adapter
, write_addr
);
678 "%s: Unable to set ms word to common reg\n",
682 write_addr
= RSI_SD_REQUEST_MASTER
|
683 (PING_BUFFER_ADDRESS
& 0xFFFF);
684 status
= hif_ops
->write_reg_multiple(adapter
, write_addr
,
685 (u8
*)bl_hdr
, write_len
);
688 "%s: Failed to load Version/CRC structure\n",
699 static u32
read_flash_capacity(struct rsi_hw
*adapter
)
703 if ((adapter
->host_intf_ops
->master_reg_read(adapter
, FLASH_SIZE_ADDR
,
704 &flash_sz
, 2)) < 0) {
706 "%s: Flash size reading failed..\n",
710 rsi_dbg(INIT_ZONE
, "Flash capacity: %d KiloBytes\n", flash_sz
);
712 return (flash_sz
* 1024); /* Return size in kbytes */
715 static int ping_pong_write(struct rsi_hw
*adapter
, u8 cmd
, u8
*addr
, u32 size
)
717 struct rsi_host_intf_ops
*hif_ops
= adapter
->host_intf_ops
;
718 u32 block_size
= adapter
->block_size
;
720 u16 cmd_resp
, cmd_req
;
724 if (cmd
== PING_WRITE
) {
725 cmd_addr
= PING_BUFFER_ADDRESS
;
726 cmd_resp
= PONG_AVAIL
;
727 cmd_req
= PING_VALID
;
730 cmd_addr
= PONG_BUFFER_ADDRESS
;
731 cmd_resp
= PING_AVAIL
;
732 cmd_req
= PONG_VALID
;
736 status
= hif_ops
->load_data_master_write(adapter
, cmd_addr
, size
,
739 rsi_dbg(ERR_ZONE
, "%s: Unable to write blk at addr %0x\n",
744 status
= bl_cmd(adapter
, cmd_req
, cmd_resp
, str
);
751 static int auto_fw_upgrade(struct rsi_hw
*adapter
, u8
*flash_content
,
755 u32 temp_content_size
, num_flash
, index
;
756 u32 flash_start_address
;
759 if (content_size
> MAX_FLASH_FILE_SIZE
) {
761 "%s: Flash Content size is more than 400K %u\n",
762 __func__
, MAX_FLASH_FILE_SIZE
);
766 flash_start_address
= *(u32
*)&flash_content
[FLASH_START_ADDRESS
];
767 rsi_dbg(INFO_ZONE
, "flash start address: %08x\n", flash_start_address
);
769 if (flash_start_address
< FW_IMAGE_MIN_ADDRESS
) {
771 "%s: Fw image Flash Start Address is less than 64K\n",
776 if (flash_start_address
% FLASH_SECTOR_SIZE
) {
778 "%s: Flash Start Address is not multiple of 4K\n",
783 if ((flash_start_address
+ content_size
) > adapter
->flash_capacity
) {
785 "%s: Flash Content will cross max flash size\n",
790 temp_content_size
= content_size
;
791 num_flash
= content_size
/ FLASH_WRITE_CHUNK_SIZE
;
793 rsi_dbg(INFO_ZONE
, "content_size: %d, num_flash: %d\n",
794 content_size
, num_flash
);
796 for (index
= 0; index
<= num_flash
; index
++) {
797 rsi_dbg(INFO_ZONE
, "flash index: %d\n", index
);
798 if (index
!= num_flash
) {
799 content_size
= FLASH_WRITE_CHUNK_SIZE
;
800 rsi_dbg(INFO_ZONE
, "QSPI content_size:%d\n",
804 temp_content_size
% FLASH_WRITE_CHUNK_SIZE
;
806 "Writing last sector content_size:%d\n",
809 rsi_dbg(INFO_ZONE
, "instruction size zero\n");
819 status
= ping_pong_write(adapter
, cmd
, flash_content
,
822 rsi_dbg(ERR_ZONE
, "%s: Unable to load %d block\n",
828 "%s: Successfully loaded %d instructions\n",
830 flash_content
+= content_size
;
833 status
= bl_cmd(adapter
, EOF_REACHED
, FW_LOADING_SUCCESSFUL
,
838 rsi_dbg(INFO_ZONE
, "FW loading is done and FW is running..\n");
842 static int rsi_hal_prepare_fwload(struct rsi_hw
*adapter
)
844 struct rsi_host_intf_ops
*hif_ops
= adapter
->host_intf_ops
;
848 bl_start_cmd_timer(adapter
, BL_CMD_TIMEOUT
);
850 while (!adapter
->blcmd_timer_expired
) {
851 status
= hif_ops
->master_reg_read(adapter
, SWBL_REGOUT
,
853 RSI_COMMON_REG_SIZE
);
855 bl_stop_cmd_timer(adapter
);
857 "%s: REGOUT read failed\n", __func__
);
861 if ((regout_val
>> 8) == REGOUT_VALID
)
864 if (adapter
->blcmd_timer_expired
) {
865 rsi_dbg(ERR_ZONE
, "%s: REGOUT read timedout\n", __func__
);
867 "%s: Soft boot loader not present\n", __func__
);
870 bl_stop_cmd_timer(adapter
);
872 rsi_dbg(INFO_ZONE
, "Received Board Version Number: %x\n",
873 (regout_val
& 0xff));
875 status
= hif_ops
->master_reg_write(adapter
, SWBL_REGOUT
,
877 REGOUT_INVALID
<< 8),
878 RSI_COMMON_REG_SIZE
);
880 rsi_dbg(ERR_ZONE
, "%s: REGOUT writing failed..\n", __func__
);
883 "===> Device is ready to load firmware <===\n");
888 static int rsi_load_9113_firmware(struct rsi_hw
*adapter
)
890 struct rsi_common
*common
= adapter
->priv
;
891 const struct firmware
*fw_entry
= NULL
;
893 u16 tmp_regout_val
= 0;
894 struct ta_metadata
*metadata_p
;
897 status
= bl_cmd(adapter
, AUTO_READ_MODE
, CMD_PASS
,
902 adapter
->flash_capacity
= read_flash_capacity(adapter
);
903 if (adapter
->flash_capacity
<= 0) {
905 "%s: Unable to read flash size from EEPROM\n",
910 metadata_p
= &metadata_flash_content
[adapter
->priv
->coex_mode
];
912 rsi_dbg(INIT_ZONE
, "%s: Loading file %s\n", __func__
, metadata_p
->name
);
913 adapter
->fw_file_name
= metadata_p
->name
;
915 status
= request_firmware(&fw_entry
, metadata_p
->name
, adapter
->device
);
917 rsi_dbg(ERR_ZONE
, "%s: Failed to open file %s\n",
918 __func__
, metadata_p
->name
);
921 content_size
= fw_entry
->size
;
922 rsi_dbg(INFO_ZONE
, "FW Length = %d bytes\n", content_size
);
924 /* Get the firmware version */
925 common
->lmac_ver
.ver
.info
.fw_ver
[0] =
926 fw_entry
->data
[LMAC_VER_OFFSET_9113
] & 0xFF;
927 common
->lmac_ver
.ver
.info
.fw_ver
[1] =
928 fw_entry
->data
[LMAC_VER_OFFSET_9113
+ 1] & 0xFF;
929 common
->lmac_ver
.major
=
930 fw_entry
->data
[LMAC_VER_OFFSET_9113
+ 2] & 0xFF;
931 common
->lmac_ver
.release_num
=
932 fw_entry
->data
[LMAC_VER_OFFSET_9113
+ 3] & 0xFF;
933 common
->lmac_ver
.minor
=
934 fw_entry
->data
[LMAC_VER_OFFSET_9113
+ 4] & 0xFF;
935 common
->lmac_ver
.patch_num
= 0;
936 rsi_print_version(common
);
938 status
= bl_write_header(adapter
, (u8
*)fw_entry
->data
, content_size
);
941 "%s: RPS Image header loading failed\n",
946 bl_start_cmd_timer(adapter
, BL_CMD_TIMEOUT
);
947 status
= bl_write_cmd(adapter
, CHECK_CRC
, CMD_PASS
, &tmp_regout_val
);
949 bl_stop_cmd_timer(adapter
);
951 "%s: CHECK_CRC Command writing failed..\n",
953 if ((tmp_regout_val
& 0xff) == CMD_FAIL
) {
955 "CRC Fail.. Proceeding to Upgrade mode\n");
959 bl_stop_cmd_timer(adapter
);
961 status
= bl_cmd(adapter
, POLLING_MODE
, CMD_PASS
, "POLLING_MODE");
966 status
= bl_cmd(adapter
, LOAD_HOSTED_FW
, LOADING_INITIATED
,
970 rsi_dbg(INFO_ZONE
, "Load Image command passed..\n");
974 status
= bl_cmd(adapter
, BURN_HOSTED_FW
, SEND_RPS_FILE
, "FW_UPGRADE");
978 rsi_dbg(INFO_ZONE
, "Burn Command Pass.. Upgrading the firmware\n");
980 status
= auto_fw_upgrade(adapter
, (u8
*)fw_entry
->data
, content_size
);
982 rsi_dbg(ERR_ZONE
, "Firmware upgradation Done\n");
985 rsi_dbg(ERR_ZONE
, "Firmware upgrade failed\n");
987 status
= bl_cmd(adapter
, AUTO_READ_MODE
, CMD_PASS
,
993 rsi_dbg(ERR_ZONE
, "***** Firmware Loading successful *****\n");
994 release_firmware(fw_entry
);
998 rsi_dbg(ERR_ZONE
, "##### Firmware loading failed #####\n");
999 release_firmware(fw_entry
);
1003 static int rsi_load_9116_firmware(struct rsi_hw
*adapter
)
1005 struct rsi_common
*common
= adapter
->priv
;
1006 struct rsi_host_intf_ops
*hif_ops
= adapter
->host_intf_ops
;
1007 const struct firmware
*fw_entry
;
1008 struct ta_metadata
*metadata_p
;
1009 u8
*ta_firmware
, *fw_p
;
1010 struct bootload_ds bootload_ds
;
1011 u32 instructions_sz
, base_address
;
1012 u16 block_size
= adapter
->block_size
;
1016 rsi_dbg(INIT_ZONE
, "***** Load 9116 TA Instructions *****\n");
1018 if (adapter
->rsi_host_intf
== RSI_HOST_INTF_USB
) {
1019 status
= bl_cmd(adapter
, POLLING_MODE
, CMD_PASS
,
1025 status
= hif_ops
->master_reg_write(adapter
, MEM_ACCESS_CTRL_FROM_HOST
,
1026 RAM_384K_ACCESS_FROM_TA
,
1029 rsi_dbg(ERR_ZONE
, "%s: Unable to access full RAM memory\n",
1034 metadata_p
= &metadata
[adapter
->priv
->coex_mode
];
1035 rsi_dbg(INIT_ZONE
, "%s: loading file %s\n", __func__
, metadata_p
->name
);
1036 status
= request_firmware(&fw_entry
, metadata_p
->name
, adapter
->device
);
1038 rsi_dbg(ERR_ZONE
, "%s: Failed to open file %s\n",
1039 __func__
, metadata_p
->name
);
1043 ta_firmware
= kmemdup(fw_entry
->data
, fw_entry
->size
, GFP_KERNEL
);
1046 goto fail_release_fw
;
1049 instructions_sz
= fw_entry
->size
;
1050 rsi_dbg(INFO_ZONE
, "FW Length = %d bytes\n", instructions_sz
);
1052 common
->lmac_ver
.major
= ta_firmware
[LMAC_VER_OFFSET_9116
];
1053 common
->lmac_ver
.minor
= ta_firmware
[LMAC_VER_OFFSET_9116
+ 1];
1054 common
->lmac_ver
.release_num
= ta_firmware
[LMAC_VER_OFFSET_9116
+ 2];
1055 common
->lmac_ver
.patch_num
= ta_firmware
[LMAC_VER_OFFSET_9116
+ 3];
1056 common
->lmac_ver
.ver
.info
.fw_ver
[0] =
1057 ta_firmware
[LMAC_VER_OFFSET_9116
+ 4];
1059 if (instructions_sz
% FW_ALIGN_SIZE
)
1061 (FW_ALIGN_SIZE
- (instructions_sz
% FW_ALIGN_SIZE
));
1062 rsi_dbg(INFO_ZONE
, "instructions_sz : %d\n", instructions_sz
);
1064 if (*(u16
*)fw_p
== RSI_9116_FW_MAGIC_WORD
) {
1065 memcpy(&bootload_ds
, fw_p
, sizeof(struct bootload_ds
));
1066 fw_p
+= le16_to_cpu(bootload_ds
.offset
);
1067 rsi_dbg(INFO_ZONE
, "FW start = %x\n", *(u32
*)fw_p
);
1071 rsi_dbg(ERR_ZONE
, "%s: Loading chunk %d\n",
1074 dest
= le32_to_cpu(bootload_ds
.bl_entry
[cnt
].dst_addr
);
1075 len
= le32_to_cpu(bootload_ds
.bl_entry
[cnt
].control
) &
1076 RSI_BL_CTRL_LEN_MASK
;
1077 rsi_dbg(INFO_ZONE
, "length %d destination %x\n",
1080 status
= hif_ops
->load_data_master_write(adapter
, dest
,
1086 "Failed to load chunk %d\n", cnt
);
1090 if (le32_to_cpu(bootload_ds
.bl_entry
[cnt
].control
) &
1091 RSI_BL_CTRL_LAST_ENTRY
)
1096 base_address
= metadata_p
->address
;
1097 status
= hif_ops
->load_data_master_write(adapter
,
1105 "%s: Unable to load %s blk\n",
1106 __func__
, metadata_p
->name
);
1110 rsi_dbg(INIT_ZONE
, "%s: Successfully loaded %s instructions\n",
1111 __func__
, metadata_p
->name
);
1113 if (adapter
->rsi_host_intf
== RSI_HOST_INTF_SDIO
) {
1114 if (hif_ops
->ta_reset(adapter
))
1115 rsi_dbg(ERR_ZONE
, "Unable to put ta in reset\n");
1117 if (bl_cmd(adapter
, JUMP_TO_ZERO_PC
,
1118 CMD_PASS
, "JUMP_TO_ZERO") < 0)
1119 rsi_dbg(INFO_ZONE
, "Jump to zero command failed\n");
1121 rsi_dbg(INFO_ZONE
, "Jump to zero command successful\n");
1127 release_firmware(fw_entry
);
1132 int rsi_hal_device_init(struct rsi_hw
*adapter
)
1134 struct rsi_common
*common
= adapter
->priv
;
1137 switch (adapter
->device_model
) {
1139 status
= rsi_hal_prepare_fwload(adapter
);
1142 if (rsi_load_9113_firmware(adapter
)) {
1144 "%s: Failed to load TA instructions\n",
1150 status
= rsi_hal_prepare_fwload(adapter
);
1153 if (rsi_load_9116_firmware(adapter
)) {
1155 "%s: Failed to load firmware to 9116 device\n",
1163 common
->fsm_state
= FSM_CARD_NOT_READY
;
1167 EXPORT_SYMBOL_GPL(rsi_hal_device_init
);