0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/skbuff.h>
0009 #include <linux/etherdevice.h>
0010
0011 #include "hif_rx.h"
0012 #include "wfx.h"
0013 #include "scan.h"
0014 #include "bh.h"
0015 #include "sta.h"
0016 #include "data_rx.h"
0017 #include "hif_api_cmd.h"
0018
0019 static int wfx_hif_generic_confirm(struct wfx_dev *wdev,
0020 const struct wfx_hif_msg *hif, const void *buf)
0021 {
0022
0023 int status = le32_to_cpup((__le32 *)buf);
0024 int cmd = hif->id;
0025 int len = le16_to_cpu(hif->len) - 4;
0026
0027 WARN(!mutex_is_locked(&wdev->hif_cmd.lock), "data locking error");
0028
0029 if (!wdev->hif_cmd.buf_send) {
0030 dev_warn(wdev->dev, "unexpected confirmation: 0x%.2x\n", cmd);
0031 return -EINVAL;
0032 }
0033
0034 if (cmd != wdev->hif_cmd.buf_send->id) {
0035 dev_warn(wdev->dev, "chip response mismatch request: 0x%.2x vs 0x%.2x\n",
0036 cmd, wdev->hif_cmd.buf_send->id);
0037 return -EINVAL;
0038 }
0039
0040 if (wdev->hif_cmd.buf_recv) {
0041 if (wdev->hif_cmd.len_recv >= len && len > 0)
0042 memcpy(wdev->hif_cmd.buf_recv, buf, len);
0043 else
0044 status = -EIO;
0045 }
0046 wdev->hif_cmd.ret = status;
0047
0048 complete(&wdev->hif_cmd.done);
0049 return status;
0050 }
0051
0052 static int wfx_hif_tx_confirm(struct wfx_dev *wdev,
0053 const struct wfx_hif_msg *hif, const void *buf)
0054 {
0055 const struct wfx_hif_cnf_tx *body = buf;
0056
0057 wfx_tx_confirm_cb(wdev, body);
0058 return 0;
0059 }
0060
0061 static int wfx_hif_multi_tx_confirm(struct wfx_dev *wdev,
0062 const struct wfx_hif_msg *hif, const void *buf)
0063 {
0064 const struct wfx_hif_cnf_multi_transmit *body = buf;
0065 int i;
0066
0067 WARN(body->num_tx_confs <= 0, "corrupted message");
0068 for (i = 0; i < body->num_tx_confs; i++)
0069 wfx_tx_confirm_cb(wdev, &body->tx_conf_payload[i]);
0070 return 0;
0071 }
0072
0073 static int wfx_hif_startup_indication(struct wfx_dev *wdev,
0074 const struct wfx_hif_msg *hif, const void *buf)
0075 {
0076 const struct wfx_hif_ind_startup *body = buf;
0077
0078 if (body->status || body->firmware_type > 4) {
0079 dev_err(wdev->dev, "received invalid startup indication");
0080 return -EINVAL;
0081 }
0082 memcpy(&wdev->hw_caps, body, sizeof(struct wfx_hif_ind_startup));
0083 complete(&wdev->firmware_ready);
0084 return 0;
0085 }
0086
0087 static int wfx_hif_wakeup_indication(struct wfx_dev *wdev,
0088 const struct wfx_hif_msg *hif, const void *buf)
0089 {
0090 if (!wdev->pdata.gpio_wakeup || gpiod_get_value(wdev->pdata.gpio_wakeup) == 0) {
0091 dev_warn(wdev->dev, "unexpected wake-up indication\n");
0092 return -EIO;
0093 }
0094 return 0;
0095 }
0096
0097 static int wfx_hif_receive_indication(struct wfx_dev *wdev, const struct wfx_hif_msg *hif,
0098 const void *buf, struct sk_buff *skb)
0099 {
0100 struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface);
0101 const struct wfx_hif_ind_rx *body = buf;
0102
0103 if (!wvif) {
0104 dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
0105 return -EIO;
0106 }
0107 skb_pull(skb, sizeof(struct wfx_hif_msg) + sizeof(struct wfx_hif_ind_rx));
0108 wfx_rx_cb(wvif, body, skb);
0109
0110 return 0;
0111 }
0112
0113 static int wfx_hif_event_indication(struct wfx_dev *wdev,
0114 const struct wfx_hif_msg *hif, const void *buf)
0115 {
0116 struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface);
0117 const struct wfx_hif_ind_event *body = buf;
0118 int type = le32_to_cpu(body->event_id);
0119
0120 if (!wvif) {
0121 dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
0122 return -EIO;
0123 }
0124
0125 switch (type) {
0126 case HIF_EVENT_IND_RCPI_RSSI:
0127 wfx_event_report_rssi(wvif, body->event_data.rcpi_rssi);
0128 break;
0129 case HIF_EVENT_IND_BSSLOST:
0130 schedule_delayed_work(&wvif->beacon_loss_work, 0);
0131 break;
0132 case HIF_EVENT_IND_BSSREGAINED:
0133 cancel_delayed_work(&wvif->beacon_loss_work);
0134 dev_dbg(wdev->dev, "ignore BSSREGAINED indication\n");
0135 break;
0136 case HIF_EVENT_IND_PS_MODE_ERROR:
0137 dev_warn(wdev->dev, "error while processing power save request: %d\n",
0138 le32_to_cpu(body->event_data.ps_mode_error));
0139 break;
0140 default:
0141 dev_warn(wdev->dev, "unhandled event indication: %.2x\n", type);
0142 break;
0143 }
0144 return 0;
0145 }
0146
0147 static int wfx_hif_pm_mode_complete_indication(struct wfx_dev *wdev,
0148 const struct wfx_hif_msg *hif, const void *buf)
0149 {
0150 struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface);
0151
0152 if (!wvif) {
0153 dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
0154 return -EIO;
0155 }
0156 complete(&wvif->set_pm_mode_complete);
0157
0158 return 0;
0159 }
0160
0161 static int wfx_hif_scan_complete_indication(struct wfx_dev *wdev,
0162 const struct wfx_hif_msg *hif, const void *buf)
0163 {
0164 struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface);
0165 const struct wfx_hif_ind_scan_cmpl *body = buf;
0166
0167 if (!wvif) {
0168 dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
0169 return -EIO;
0170 }
0171
0172 wfx_scan_complete(wvif, body->num_channels_completed);
0173
0174 return 0;
0175 }
0176
0177 static int wfx_hif_join_complete_indication(struct wfx_dev *wdev,
0178 const struct wfx_hif_msg *hif, const void *buf)
0179 {
0180 struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface);
0181
0182 if (!wvif) {
0183 dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
0184 return -EIO;
0185 }
0186 dev_warn(wdev->dev, "unattended JoinCompleteInd\n");
0187
0188 return 0;
0189 }
0190
0191 static int wfx_hif_suspend_resume_indication(struct wfx_dev *wdev,
0192 const struct wfx_hif_msg *hif, const void *buf)
0193 {
0194 const struct wfx_hif_ind_suspend_resume_tx *body = buf;
0195 struct wfx_vif *wvif;
0196
0197 if (body->bc_mc_only) {
0198 wvif = wdev_to_wvif(wdev, hif->interface);
0199 if (!wvif) {
0200 dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
0201 return -EIO;
0202 }
0203 if (body->resume)
0204 wfx_suspend_resume_mc(wvif, STA_NOTIFY_AWAKE);
0205 else
0206 wfx_suspend_resume_mc(wvif, STA_NOTIFY_SLEEP);
0207 } else {
0208 WARN(body->peer_sta_set, "misunderstood indication");
0209 WARN(hif->interface != 2, "misunderstood indication");
0210 if (body->resume)
0211 wfx_suspend_hot_dev(wdev, STA_NOTIFY_AWAKE);
0212 else
0213 wfx_suspend_hot_dev(wdev, STA_NOTIFY_SLEEP);
0214 }
0215
0216 return 0;
0217 }
0218
0219 static int wfx_hif_generic_indication(struct wfx_dev *wdev,
0220 const struct wfx_hif_msg *hif, const void *buf)
0221 {
0222 const struct wfx_hif_ind_generic *body = buf;
0223 int type = le32_to_cpu(body->type);
0224
0225 switch (type) {
0226 case HIF_GENERIC_INDICATION_TYPE_RAW:
0227 return 0;
0228 case HIF_GENERIC_INDICATION_TYPE_STRING:
0229 dev_info(wdev->dev, "firmware says: %s\n", (char *)&body->data);
0230 return 0;
0231 case HIF_GENERIC_INDICATION_TYPE_RX_STATS:
0232 mutex_lock(&wdev->rx_stats_lock);
0233
0234 if (!wfx_api_older_than(wdev, 1, 4))
0235 dev_info(wdev->dev, "Rx test ongoing. Temperature: %d degrees C\n",
0236 body->data.rx_stats.current_temp);
0237 memcpy(&wdev->rx_stats, &body->data.rx_stats, sizeof(wdev->rx_stats));
0238 mutex_unlock(&wdev->rx_stats_lock);
0239 return 0;
0240 case HIF_GENERIC_INDICATION_TYPE_TX_POWER_LOOP_INFO:
0241 mutex_lock(&wdev->tx_power_loop_info_lock);
0242 memcpy(&wdev->tx_power_loop_info, &body->data.tx_power_loop_info,
0243 sizeof(wdev->tx_power_loop_info));
0244 mutex_unlock(&wdev->tx_power_loop_info_lock);
0245 return 0;
0246 default:
0247 dev_err(wdev->dev, "generic_indication: unknown indication type: %#.8x\n", type);
0248 return -EIO;
0249 }
0250 }
0251
0252 static const struct {
0253 int val;
0254 const char *str;
0255 bool has_param;
0256 } hif_errors[] = {
0257 { HIF_ERROR_FIRMWARE_ROLLBACK,
0258 "rollback status" },
0259 { HIF_ERROR_FIRMWARE_DEBUG_ENABLED,
0260 "debug feature enabled" },
0261 { HIF_ERROR_PDS_PAYLOAD,
0262 "PDS version is not supported" },
0263 { HIF_ERROR_PDS_TESTFEATURE,
0264 "PDS ask for an unknown test mode" },
0265 { HIF_ERROR_OOR_VOLTAGE,
0266 "out-of-range power supply voltage", true },
0267 { HIF_ERROR_OOR_TEMPERATURE,
0268 "out-of-range temperature", true },
0269 { HIF_ERROR_SLK_REQ_DURING_KEY_EXCHANGE,
0270 "secure link does not expect request during key exchange" },
0271 { HIF_ERROR_SLK_SESSION_KEY,
0272 "secure link session key is invalid" },
0273 { HIF_ERROR_SLK_OVERFLOW,
0274 "secure link overflow" },
0275 { HIF_ERROR_SLK_WRONG_ENCRYPTION_STATE,
0276 "secure link messages list does not match message encryption" },
0277 { HIF_ERROR_SLK_UNCONFIGURED,
0278 "secure link not yet configured" },
0279 { HIF_ERROR_HIF_BUS_FREQUENCY_TOO_LOW,
0280 "bus clock is too slow (<1kHz)" },
0281 { HIF_ERROR_HIF_RX_DATA_TOO_LARGE,
0282 "HIF message too large" },
0283
0284 { HIF_ERROR_HIF_TX_QUEUE_FULL,
0285 "HIF messages queue is full" },
0286 { HIF_ERROR_HIF_BUS,
0287 "HIF bus" },
0288 { HIF_ERROR_SLK_MULTI_TX_UNSUPPORTED,
0289 "secure link does not support multi-tx confirmations" },
0290 { HIF_ERROR_SLK_OUTDATED_SESSION_KEY,
0291 "secure link session key is outdated" },
0292 { HIF_ERROR_SLK_DECRYPTION,
0293 "secure link params (nonce or tag) mismatch" },
0294 };
0295
0296 static int wfx_hif_error_indication(struct wfx_dev *wdev,
0297 const struct wfx_hif_msg *hif, const void *buf)
0298 {
0299 const struct wfx_hif_ind_error *body = buf;
0300 int type = le32_to_cpu(body->type);
0301 int param = (s8)body->data[0];
0302 int i;
0303
0304 for (i = 0; i < ARRAY_SIZE(hif_errors); i++)
0305 if (type == hif_errors[i].val)
0306 break;
0307 if (i < ARRAY_SIZE(hif_errors))
0308 if (hif_errors[i].has_param)
0309 dev_err(wdev->dev, "asynchronous error: %s: %d\n",
0310 hif_errors[i].str, param);
0311 else
0312 dev_err(wdev->dev, "asynchronous error: %s\n", hif_errors[i].str);
0313 else
0314 dev_err(wdev->dev, "asynchronous error: unknown: %08x\n", type);
0315 print_hex_dump(KERN_INFO, "hif: ", DUMP_PREFIX_OFFSET,
0316 16, 1, hif, le16_to_cpu(hif->len), false);
0317 wdev->chip_frozen = true;
0318
0319 return 0;
0320 };
0321
0322 static int wfx_hif_exception_indication(struct wfx_dev *wdev,
0323 const struct wfx_hif_msg *hif, const void *buf)
0324 {
0325 const struct wfx_hif_ind_exception *body = buf;
0326 int type = le32_to_cpu(body->type);
0327
0328 if (type == 4)
0329 dev_err(wdev->dev, "firmware assert %d\n", le32_to_cpup((__le32 *)body->data));
0330 else
0331 dev_err(wdev->dev, "firmware exception\n");
0332 print_hex_dump(KERN_INFO, "hif: ", DUMP_PREFIX_OFFSET,
0333 16, 1, hif, le16_to_cpu(hif->len), false);
0334 wdev->chip_frozen = true;
0335
0336 return -1;
0337 }
0338
0339 static const struct {
0340 int msg_id;
0341 int (*handler)(struct wfx_dev *wdev, const struct wfx_hif_msg *hif, const void *buf);
0342 } hif_handlers[] = {
0343
0344 { HIF_CNF_ID_TX, wfx_hif_tx_confirm },
0345 { HIF_CNF_ID_MULTI_TRANSMIT, wfx_hif_multi_tx_confirm },
0346
0347 { HIF_IND_ID_STARTUP, wfx_hif_startup_indication },
0348 { HIF_IND_ID_WAKEUP, wfx_hif_wakeup_indication },
0349 { HIF_IND_ID_JOIN_COMPLETE, wfx_hif_join_complete_indication },
0350 { HIF_IND_ID_SET_PM_MODE_CMPL, wfx_hif_pm_mode_complete_indication },
0351 { HIF_IND_ID_SCAN_CMPL, wfx_hif_scan_complete_indication },
0352 { HIF_IND_ID_SUSPEND_RESUME_TX, wfx_hif_suspend_resume_indication },
0353 { HIF_IND_ID_EVENT, wfx_hif_event_indication },
0354 { HIF_IND_ID_GENERIC, wfx_hif_generic_indication },
0355 { HIF_IND_ID_ERROR, wfx_hif_error_indication },
0356 { HIF_IND_ID_EXCEPTION, wfx_hif_exception_indication },
0357
0358
0359 };
0360
0361 void wfx_handle_rx(struct wfx_dev *wdev, struct sk_buff *skb)
0362 {
0363 int i;
0364 const struct wfx_hif_msg *hif = (const struct wfx_hif_msg *)skb->data;
0365 int hif_id = hif->id;
0366
0367 if (hif_id == HIF_IND_ID_RX) {
0368
0369 wfx_hif_receive_indication(wdev, hif, hif->body, skb);
0370 return;
0371 }
0372
0373 if (mutex_is_locked(&wdev->hif_cmd.lock) &&
0374 wdev->hif_cmd.buf_send && wdev->hif_cmd.buf_send->id == hif_id) {
0375 wfx_hif_generic_confirm(wdev, hif, hif->body);
0376 goto free;
0377 }
0378 for (i = 0; i < ARRAY_SIZE(hif_handlers); i++) {
0379 if (hif_handlers[i].msg_id == hif_id) {
0380 if (hif_handlers[i].handler)
0381 hif_handlers[i].handler(wdev, hif, hif->body);
0382 goto free;
0383 }
0384 }
0385 if (hif_id & HIF_ID_IS_INDICATION)
0386 dev_err(wdev->dev, "unsupported HIF indication: ID %02x\n", hif_id);
0387 else
0388 dev_err(wdev->dev, "unexpected HIF confirmation: ID %02x\n", hif_id);
0389 free:
0390 dev_kfree_skb(skb);
0391 }