Lines Matching +full:tx +full:- +full:ping +full:- +full:pong

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2021-2024 Intel Corporation
23 #include "iwl-mei.h"
25 #include "trace-data.h"
95 * +-----------------------------------+
97 * +-----------------------------------+
98 * |Host -> ME data queue |
99 * +-----------------------------------+
100 * |Host -> ME notif queue |
101 * +-----------------------------------+
102 * |ME -> Host data queue |
103 * +-----------------------------------+
104 * |ME -> host notif queue |
105 * +-----------------------------------+
107 * +-----------------------------------+
138 * struct iwl_mei - holds the private date for iwl_mei
166 * @ownership_dwork: used to re-ask for NIC ownership after ownership was taken
200 * struct iwl_mei_cache - cache for the parameters from iwlwifi
239 dev_err(&cldev->dev, "Couldn't unmap the shared mem properly\n"); in iwl_mei_free_shared_mem()
240 memset(&mei->shared_mem, 0, sizeof(mei->shared_mem)); in iwl_mei_free_shared_mem()
249 struct iwl_mei_shared_mem_ptrs *mem = &mei->shared_mem; in iwl_mei_alloc_mem_for_version()
255 mem->ctrl = mei_cldev_dma_map(cldev, HBM_DMA_BUF_ID_WLAN, mem_size); in iwl_mei_alloc_mem_for_version()
256 if (IS_ERR(mem->ctrl)) { in iwl_mei_alloc_mem_for_version()
257 int ret = PTR_ERR(mem->ctrl); in iwl_mei_alloc_mem_for_version()
259 mem->ctrl = NULL; in iwl_mei_alloc_mem_for_version()
264 memset(mem->ctrl, 0, mem_size); in iwl_mei_alloc_mem_for_version()
290 struct iwl_mei_shared_mem_ptrs *mem = &mei->shared_mem; in iwl_mei_init_shared_mem()
296 mem->ctrl->sap_id = cpu_to_le32(SAP_CONTROL_BLOCK_ID); in iwl_mei_init_shared_mem()
298 mem->ctrl->size = cpu_to_le32(sizeof(*mem->ctrl)); in iwl_mei_init_shared_mem()
300 h2m = &mem->ctrl->dir[SAP_DIRECTION_HOST_TO_ME]; in iwl_mei_init_shared_mem()
301 m2h = &mem->ctrl->dir[SAP_DIRECTION_ME_TO_HOST]; in iwl_mei_init_shared_mem()
303 h2m->q_ctrl_blk[SAP_QUEUE_IDX_DATA].size = in iwl_mei_init_shared_mem()
305 h2m->q_ctrl_blk[SAP_QUEUE_IDX_NOTIF].size = in iwl_mei_init_shared_mem()
309 m2h->q_ctrl_blk[SAP_QUEUE_IDX_DATA].size = in iwl_mei_init_shared_mem()
311 m2h->q_ctrl_blk[SAP_QUEUE_IDX_NOTIF].size = in iwl_mei_init_shared_mem()
315 q_head = (void *)(mem->ctrl + 1); in iwl_mei_init_shared_mem()
320 mem->q_head[dir][queue] = q_head; in iwl_mei_init_shared_mem()
322 le32_to_cpu(mem->ctrl->dir[dir].q_ctrl_blk[queue].size); in iwl_mei_init_shared_mem()
323 mem->q_size[dir][queue] = in iwl_mei_init_shared_mem()
324 le32_to_cpu(mem->ctrl->dir[dir].q_ctrl_blk[queue].size); in iwl_mei_init_shared_mem()
337 u32 rd = le32_to_cpu(READ_ONCE(notif_q->rd_ptr)); in iwl_mei_write_cyclic_buf()
338 u32 wr = le32_to_cpu(READ_ONCE(notif_q->wr_ptr)); in iwl_mei_write_cyclic_buf()
340 size_t tx_sz = sizeof(*hdr) + le16_to_cpu(hdr->len); in iwl_mei_write_cyclic_buf()
343 dev_err(&cldev->dev, in iwl_mei_write_cyclic_buf()
345 return -EINVAL; in iwl_mei_write_cyclic_buf()
348 room_in_buf = wr >= rd ? q_sz - wr + rd : rd - wr; in iwl_mei_write_cyclic_buf()
352 dev_err(&cldev->dev, in iwl_mei_write_cyclic_buf()
354 return -ENOSPC; in iwl_mei_write_cyclic_buf()
360 memcpy(q_head + wr, hdr, q_sz - wr); in iwl_mei_write_cyclic_buf()
361 memcpy(q_head, (const u8 *)hdr + q_sz - wr, tx_sz - (q_sz - wr)); in iwl_mei_write_cyclic_buf()
364 WRITE_ONCE(notif_q->wr_ptr, cpu_to_le32((wr + tx_sz) % q_sz)); in iwl_mei_write_cyclic_buf()
373 dir = &mei->shared_mem.ctrl->dir[SAP_DIRECTION_HOST_TO_ME]; in iwl_mei_host_to_me_data_pending()
374 notif_q = &dir->q_ctrl_blk[SAP_QUEUE_IDX_DATA]; in iwl_mei_host_to_me_data_pending()
376 if (READ_ONCE(notif_q->wr_ptr) != READ_ONCE(notif_q->rd_ptr)) in iwl_mei_host_to_me_data_pending()
379 notif_q = &dir->q_ctrl_blk[SAP_QUEUE_IDX_NOTIF]; in iwl_mei_host_to_me_data_pending()
380 return READ_ONCE(notif_q->wr_ptr) != READ_ONCE(notif_q->rd_ptr); in iwl_mei_host_to_me_data_pending()
388 .hdr.seq_num = cpu_to_le32(atomic_inc_return(&mei->seq_no)), in iwl_mei_send_check_shared_area()
394 if (mei->csa_throttled) in iwl_mei_send_check_shared_area()
400 dev_err(&cldev->dev, in iwl_mei_send_check_shared_area()
406 mei->csa_throttled = true; in iwl_mei_send_check_shared_area()
408 schedule_delayed_work(&mei->csa_throttle_end_wk, in iwl_mei_send_check_shared_area()
421 mei->csa_throttled = false; in iwl_mei_csa_throttle_end_wk()
424 iwl_mei_send_check_shared_area(mei->cldev); in iwl_mei_csa_throttle_end_wk()
441 if (!mei->shared_mem.ctrl) { in iwl_mei_send_sap_msg_payload()
442 dev_err(&cldev->dev, in iwl_mei_send_sap_msg_payload()
444 return -EINVAL; in iwl_mei_send_sap_msg_payload()
448 dev_err(&cldev->dev, in iwl_mei_send_sap_msg_payload()
450 return -ENODEV; in iwl_mei_send_sap_msg_payload()
453 hdr->seq_num = cpu_to_le32(atomic_inc_return(&mei->sap_seq_no)); in iwl_mei_send_sap_msg_payload()
454 dev_dbg(&cldev->dev, "Sending %d\n", hdr->type); in iwl_mei_send_sap_msg_payload()
456 dir = &mei->shared_mem.ctrl->dir[SAP_DIRECTION_HOST_TO_ME]; in iwl_mei_send_sap_msg_payload()
457 notif_q = &dir->q_ctrl_blk[SAP_QUEUE_IDX_NOTIF]; in iwl_mei_send_sap_msg_payload()
458 q_head = mei->shared_mem.q_head[SAP_DIRECTION_HOST_TO_ME][SAP_QUEUE_IDX_NOTIF]; in iwl_mei_send_sap_msg_payload()
459 q_sz = mei->shared_mem.q_size[SAP_DIRECTION_HOST_TO_ME][SAP_QUEUE_IDX_NOTIF]; in iwl_mei_send_sap_msg_payload()
490 * and from Tx path when we send DHCP packets, the latter is in iwl_mei_add_data_to_ring()
495 spin_lock_bh(&mei->data_q_lock); in iwl_mei_add_data_to_ring()
498 spin_unlock_bh(&mei->data_q_lock); in iwl_mei_add_data_to_ring()
507 dir = &mei->shared_mem.ctrl->dir[SAP_DIRECTION_HOST_TO_ME]; in iwl_mei_add_data_to_ring()
508 notif_q = &dir->q_ctrl_blk[SAP_QUEUE_IDX_DATA]; in iwl_mei_add_data_to_ring()
509 q_head = mei->shared_mem.q_head[SAP_DIRECTION_HOST_TO_ME][SAP_QUEUE_IDX_DATA]; in iwl_mei_add_data_to_ring()
510 q_sz = mei->shared_mem.q_size[SAP_DIRECTION_HOST_TO_ME][SAP_QUEUE_IDX_DATA]; in iwl_mei_add_data_to_ring()
512 rd = le32_to_cpu(READ_ONCE(notif_q->rd_ptr)); in iwl_mei_add_data_to_ring()
513 wr = le32_to_cpu(READ_ONCE(notif_q->wr_ptr)); in iwl_mei_add_data_to_ring()
516 tx_sz = skb->len + hdr_sz; in iwl_mei_add_data_to_ring()
519 dev_err(&mei->cldev->dev, in iwl_mei_add_data_to_ring()
524 room_in_buf = wr >= rd ? q_sz - wr + rd : rd - wr; in iwl_mei_add_data_to_ring()
528 dev_err(&mei->cldev->dev, in iwl_mei_add_data_to_ring()
534 dev_err(&mei->cldev->dev, in iwl_mei_add_data_to_ring()
543 cb_hdr->hdr.type = cpu_to_le16(SAP_MSG_CB_DATA_PACKET); in iwl_mei_add_data_to_ring()
544 cb_hdr->hdr.len = cpu_to_le16(skb->len - sizeof(cb_hdr->hdr)); in iwl_mei_add_data_to_ring()
545 cb_hdr->hdr.seq_num = cpu_to_le32(atomic_inc_return(&mei->sap_seq_no)); in iwl_mei_add_data_to_ring()
546 cb_hdr->to_me_filt_status = cpu_to_le32(BIT(CB_TX_DHCP_FILT_IDX)); in iwl_mei_add_data_to_ring()
547 cb_hdr->data_len = cpu_to_le32(skb->len - sizeof(*cb_hdr)); in iwl_mei_add_data_to_ring()
552 hdr->type = cpu_to_le16(SAP_MSG_DATA_PACKET); in iwl_mei_add_data_to_ring()
553 hdr->len = cpu_to_le16(skb->len - sizeof(*hdr)); in iwl_mei_add_data_to_ring()
554 hdr->seq_num = cpu_to_le32(atomic_inc_return(&mei->sap_seq_no)); in iwl_mei_add_data_to_ring()
561 skb_copy_bits(skb, 0, q_head + wr, q_sz - wr); in iwl_mei_add_data_to_ring()
562 skb_copy_bits(skb, q_sz - wr, q_head, tx_sz - (q_sz - wr)); in iwl_mei_add_data_to_ring()
565 WRITE_ONCE(notif_q->wr_ptr, cpu_to_le32((wr + tx_sz) % q_sz)); in iwl_mei_add_data_to_ring()
568 spin_unlock_bh(&mei->data_q_lock); in iwl_mei_add_data_to_ring()
591 iwl_mei_send_check_shared_area(mei->cldev); in iwl_mei_send_csa_msg_wk()
601 rcu_dereference(skb->dev->rx_handler_data); in iwl_mei_rx_handler()
602 struct iwl_mei_filters *filters = rcu_dereference(mei->filters); in iwl_mei_rx_handler()
611 dev_err(&mei->cldev->dev, in iwl_mei_rx_handler()
617 res = iwl_mei_rx_filter(skb, &filters->filters, &rx_for_csme); in iwl_mei_rx_handler()
627 schedule_work(&mei->send_csa_msg_wk); in iwl_mei_rx_handler()
653 if (mei->amt_enabled) in iwl_mei_netdev_work()
670 dev_err(&cldev->dev, in iwl_mei_handle_rx_start_ok()
672 dev_err(&cldev->dev, in iwl_mei_handle_rx_start_ok()
678 if (rsp->supported_version != iwl_mei_cache.sap_version) { in iwl_mei_handle_rx_start_ok()
679 dev_err(&cldev->dev, in iwl_mei_handle_rx_start_ok()
681 rsp->supported_version); in iwl_mei_handle_rx_start_ok()
702 rcu_dereference_protected(mei->filters, in iwl_mei_handle_csme_filters()
710 new_filters->filters = filters->filters; in iwl_mei_handle_csme_filters()
712 rcu_assign_pointer(mei->filters, new_filters); in iwl_mei_handle_csme_filters()
724 .lp_state = le32_to_cpu(status->link_prot_state), in iwl_mei_handle_conn_status()
725 .ssid_len = le32_to_cpu(status->conn_info.ssid_len), in iwl_mei_handle_conn_status()
726 .channel = status->conn_info.channel, in iwl_mei_handle_conn_status()
727 .band = status->conn_info.band, in iwl_mei_handle_conn_status()
728 .auth_mode = le32_to_cpu(status->conn_info.auth_mode), in iwl_mei_handle_conn_status()
729 .pairwise_cipher = le32_to_cpu(status->conn_info.pairwise_cipher), in iwl_mei_handle_conn_status()
736 memcpy(conn_info.ssid, status->conn_info.ssid, conn_info.ssid_len); in iwl_mei_handle_conn_status()
737 ether_addr_copy(conn_info.bssid, status->conn_info.bssid); in iwl_mei_handle_conn_status()
739 iwl_mei_cache.ops->me_conn_status(iwl_mei_cache.priv, &conn_info); in iwl_mei_handle_conn_status()
741 mei->link_prot_state = status->link_prot_state; in iwl_mei_handle_conn_status()
750 if (mei->got_ownership) in iwl_mei_handle_conn_status()
751 iwl_mei_cache.ops->roaming_forbidden(iwl_mei_cache.priv, in iwl_mei_handle_conn_status()
752 status->link_prot_state); in iwl_mei_handle_conn_status()
754 iwl_mei_cache.ops->rfkill(iwl_mei_cache.priv, in iwl_mei_handle_conn_status()
755 status->link_prot_state, false); in iwl_mei_handle_conn_status()
762 .hdr.len = cpu_to_le16(sizeof(link_msg) - sizeof(link_msg.hdr)), in iwl_mei_set_init_conf()
766 .hdr.len = cpu_to_le16(sizeof(mcc_msg) - sizeof(mcc_msg.hdr)), in iwl_mei_set_init_conf()
771 .hdr.len = cpu_to_le16(sizeof(sar_msg) - sizeof(sar_msg.hdr)), in iwl_mei_set_init_conf()
775 .hdr.len = cpu_to_le16(sizeof(nic_info_msg) - sizeof(nic_info_msg.hdr)), in iwl_mei_set_init_conf()
779 .hdr.len = cpu_to_le16(sizeof(rfkill_msg) - sizeof(rfkill_msg.hdr)), in iwl_mei_set_init_conf()
785 iwl_mei_send_sap_msg(mei->cldev, in iwl_mei_set_init_conf()
787 iwl_mei_cache.ops->sap_connected(iwl_mei_cache.priv); in iwl_mei_set_init_conf()
790 iwl_mei_send_sap_msg(mei->cldev, SAP_MSG_NOTIF_WHO_OWNS_NIC); in iwl_mei_set_init_conf()
794 iwl_mei_send_sap_msg_payload(mei->cldev, &link_msg.hdr); in iwl_mei_set_init_conf()
797 iwl_mei_send_sap_msg_payload(mei->cldev, &mcc_msg.hdr); in iwl_mei_set_init_conf()
802 iwl_mei_send_sap_msg_payload(mei->cldev, &sar_msg.hdr); in iwl_mei_set_init_conf()
810 iwl_mei_send_sap_msg_payload(mei->cldev, &nic_info_msg.hdr); in iwl_mei_set_init_conf()
813 iwl_mei_send_sap_msg_payload(mei->cldev, &rfkill_msg.hdr); in iwl_mei_set_init_conf()
823 if (mei->amt_enabled == !!le32_to_cpu(dw->val)) in iwl_mei_handle_amt_state()
826 mei->amt_enabled = dw->val; in iwl_mei_handle_amt_state()
828 if (mei->amt_enabled) in iwl_mei_handle_amt_state()
831 iwl_mei_cache.ops->rfkill(iwl_mei_cache.priv, false, false); in iwl_mei_handle_amt_state()
833 schedule_work(&mei->netdev_work); in iwl_mei_handle_amt_state()
844 mei->got_ownership = dw->val != cpu_to_le32(SAP_NIC_OWNER_ME); in iwl_mei_handle_nic_owner()
861 dev_info(&cldev->dev, "CSME takes ownership\n"); in iwl_mei_handle_csme_taking_ownership()
863 mei->got_ownership = false; in iwl_mei_handle_csme_taking_ownership()
865 if (iwl_mei_cache.ops && !mei->device_down) { in iwl_mei_handle_csme_taking_ownership()
870 mei->csme_taking_ownership = true; in iwl_mei_handle_csme_taking_ownership()
872 iwl_mei_cache.ops->rfkill(iwl_mei_cache.priv, true, true); in iwl_mei_handle_csme_taking_ownership()
876 schedule_delayed_work(&mei->ownership_dwork, in iwl_mei_handle_csme_taking_ownership()
888 kfree(mei->nvm); in iwl_mei_handle_nvm()
889 mei->nvm = kzalloc(sizeof(*mei_nvm), GFP_KERNEL); in iwl_mei_handle_nvm()
890 if (!mei->nvm) in iwl_mei_handle_nvm()
893 ether_addr_copy(mei->nvm->hw_addr, sap_nvm->hw_addr); in iwl_mei_handle_nvm()
894 mei->nvm->n_hw_addrs = sap_nvm->n_hw_addrs; in iwl_mei_handle_nvm()
895 mei->nvm->radio_cfg = le32_to_cpu(sap_nvm->radio_cfg); in iwl_mei_handle_nvm()
896 mei->nvm->caps = le32_to_cpu(sap_nvm->caps); in iwl_mei_handle_nvm()
897 mei->nvm->nvm_version = le32_to_cpu(sap_nvm->nvm_version); in iwl_mei_handle_nvm()
899 for (i = 0; i < ARRAY_SIZE(mei->nvm->channels); i++) in iwl_mei_handle_nvm()
900 mei->nvm->channels[i] = le32_to_cpu(sap_nvm->channels[i]); in iwl_mei_handle_nvm()
902 wake_up_all(&mei->get_nvm_wq); in iwl_mei_handle_nvm()
914 if (!dw->val) { in iwl_mei_handle_rx_host_own_req()
915 dev_info(&cldev->dev, "Ownership req denied\n"); in iwl_mei_handle_rx_host_own_req()
919 mei->got_ownership = true; in iwl_mei_handle_rx_host_own_req()
920 wake_up_all(&mei->get_ownership_wq); in iwl_mei_handle_rx_host_own_req()
927 iwl_mei_cache.ops->rfkill(iwl_mei_cache.priv, false, false); in iwl_mei_handle_rx_host_own_req()
935 mei->pldr_active = le32_to_cpu(ack->status) == SAP_PLDR_STATUS_SUCCESS; in iwl_mei_handle_pldr_ack()
936 wake_up_all(&mei->pldr_wq); in iwl_mei_handle_pldr_ack()
948 u16 len = le16_to_cpu(hdr->len) + sizeof(*hdr); in iwl_mei_handle_sap_msg()
949 u16 type = le16_to_cpu(hdr->type); in iwl_mei_handle_sap_msg()
951 dev_dbg(&cldev->dev, in iwl_mei_handle_sap_msg()
953 le16_to_cpu(hdr->type), len, in iwl_mei_handle_sap_msg()
954 le32_to_cpu(hdr->seq_num)); in iwl_mei_handle_sap_msg()
959 dev_err(&cldev->dev, \ in iwl_mei_handle_sap_msg()
961 le16_to_cpu(hdr->type), \ in iwl_mei_handle_sap_msg()
974 dev_err(&cldev->dev, \ in iwl_mei_handle_sap_msg()
976 le16_to_cpu(hdr->type), \ in iwl_mei_handle_sap_msg()
987 dev_err(&cldev->dev, \ in iwl_mei_handle_sap_msg()
989 le16_to_cpu(hdr->type), \ in iwl_mei_handle_sap_msg()
997 SAP_MSG_HANDLER(PING, iwl_mei_handle_ping, 0); in iwl_mei_handle_sap_msg()
1007 SAP_MSG_HANDLER_NO_HANDLER(PONG, 0); in iwl_mei_handle_sap_msg()
1027 dev_dbg(&cldev->dev, "Unsupported message: type %d, len %d\n", in iwl_mei_handle_sap_msg()
1028 le16_to_cpu(hdr->type), len); in iwl_mei_handle_sap_msg()
1046 memcpy(buf, q_head + rd, q_sz - rd); in iwl_mei_read_from_q()
1047 memcpy(buf + q_sz - rd, q_head, len - (q_sz - rd)); in iwl_mei_read_from_q()
1048 rd = len - (q_sz - rd); in iwl_mei_read_from_q()
1078 valid_rx_sz -= sizeof(hdr); in iwl_mei_handle_sap_data()
1082 dev_err(&cldev->dev, in iwl_mei_handle_sap_data()
1089 dev_err(&cldev->dev, in iwl_mei_handle_sap_data()
1094 valid_rx_sz -= len; in iwl_mei_handle_sap_data()
1097 dev_err(&cldev->dev, "Unsupported Rx data: type %d, len %d\n", in iwl_mei_handle_sap_data()
1112 len -= sizeof(*ethhdr); in iwl_mei_handle_sap_data()
1116 skb->protocol = ethhdr->h_proto; in iwl_mei_handle_sap_data()
1123 * do not hold the mutex. TX'ing a packet with a mutex held is in iwl_mei_handle_sap_data()
1124 * possible, but it wouldn't be nice to forbid the TX path to in iwl_mei_handle_sap_data()
1148 valid_rx_sz -= sizeof(*hdr); in iwl_mei_handle_sap_rx_cmd()
1149 len = le16_to_cpu(hdr->len); in iwl_mei_handle_sap_rx_cmd()
1158 valid_rx_sz -= len; in iwl_mei_handle_sap_rx_cmd()
1163 dev_err(&cldev->dev, in iwl_mei_handle_sap_rx_cmd()
1175 u32 rd = le32_to_cpu(READ_ONCE(notif_q->rd_ptr)); in iwl_mei_handle_sap_rx()
1176 u32 wr = le32_to_cpu(READ_ONCE(notif_q->wr_ptr)); in iwl_mei_handle_sap_rx()
1180 dev_err(&cldev->dev, in iwl_mei_handle_sap_rx()
1188 valid_rx_sz = wr > rd ? wr - rd : q_sz - rd + wr; in iwl_mei_handle_sap_rx()
1198 WRITE_ONCE(notif_q->rd_ptr, cpu_to_le32(wr)); in iwl_mei_handle_sap_rx()
1210 if (!mei->shared_mem.ctrl) in iwl_mei_handle_check_shared_area()
1213 dir = &mei->shared_mem.ctrl->dir[SAP_DIRECTION_ME_TO_HOST]; in iwl_mei_handle_check_shared_area()
1214 notif_q = &dir->q_ctrl_blk[SAP_QUEUE_IDX_NOTIF]; in iwl_mei_handle_check_shared_area()
1215 q_head = mei->shared_mem.q_head[SAP_DIRECTION_ME_TO_HOST][SAP_QUEUE_IDX_NOTIF]; in iwl_mei_handle_check_shared_area()
1216 q_sz = mei->shared_mem.q_size[SAP_DIRECTION_ME_TO_HOST][SAP_QUEUE_IDX_NOTIF]; in iwl_mei_handle_check_shared_area()
1226 dir = &mei->shared_mem.ctrl->dir[SAP_DIRECTION_ME_TO_HOST]; in iwl_mei_handle_check_shared_area()
1227 notif_q = &dir->q_ctrl_blk[SAP_QUEUE_IDX_DATA]; in iwl_mei_handle_check_shared_area()
1228 q_head = mei->shared_mem.q_head[SAP_DIRECTION_ME_TO_HOST][SAP_QUEUE_IDX_DATA]; in iwl_mei_handle_check_shared_area()
1229 q_sz = mei->shared_mem.q_size[SAP_DIRECTION_ME_TO_HOST][SAP_QUEUE_IDX_DATA]; in iwl_mei_handle_check_shared_area()
1242 * even if the netdev is replaced by another non-NULL netdev right after in iwl_mei_handle_check_shared_area()
1252 dev_err(&cldev->dev, "Can't Tx without a netdev\n"); in iwl_mei_handle_check_shared_area()
1276 dev_err(&cldev->dev, "failed to receive data: %zd\n", ret); in iwl_mei_rx()
1281 dev_err(&cldev->dev, "got an empty response\n"); in iwl_mei_rx()
1288 switch (le32_to_cpu(hdr->type)) { in iwl_mei_rx()
1299 dev_err(&cldev->dev, "got a RX notification: %d\n", in iwl_mei_rx()
1300 le32_to_cpu(hdr->type)); in iwl_mei_rx()
1310 .hdr.seq_num = cpu_to_le32(atomic_inc_return(&mei->seq_no)), in iwl_mei_send_start()
1321 dev_err(&cldev->dev, in iwl_mei_send_start()
1336 dev_err(&cldev->dev, "failed to enable the device: %d\n", ret); in iwl_mei_enable()
1342 dev_err(&cldev->dev, in iwl_mei_enable()
1374 ret = wait_event_timeout(mei->get_nvm_wq, mei->nvm, 2 * HZ); in iwl_mei_get_nvm()
1388 if (mei->nvm) in iwl_mei_get_nvm()
1389 nvm = kmemdup(mei->nvm, sizeof(*mei->nvm), GFP_KERNEL); in iwl_mei_get_nvm()
1405 .hdr.len = cpu_to_le16(sizeof(msg) - sizeof(msg.hdr)), in iwl_mei_pldr_req()
1420 ret = -ENODEV; in iwl_mei_pldr_req()
1424 if (!mei->amt_enabled) { in iwl_mei_pldr_req()
1430 ret = iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr); in iwl_mei_pldr_req()
1435 ret = wait_event_timeout(mei->pldr_wq, mei->pldr_active, HZ / 2); in iwl_mei_pldr_req()
1446 ret = -ETIMEDOUT; in iwl_mei_pldr_req()
1469 ret = -ENODEV; in iwl_mei_get_ownership()
1473 if (!mei->amt_enabled) { in iwl_mei_get_ownership()
1478 if (mei->got_ownership) { in iwl_mei_get_ownership()
1483 ret = iwl_mei_send_sap_msg(mei->cldev, in iwl_mei_get_ownership()
1490 ret = wait_event_timeout(mei->get_ownership_wq, in iwl_mei_get_ownership()
1491 mei->got_ownership, HZ / 2); in iwl_mei_get_ownership()
1493 schedule_delayed_work(&mei->ownership_dwork, in iwl_mei_get_ownership()
1495 return -ETIMEDOUT; in iwl_mei_get_ownership()
1510 .hdr.len = cpu_to_le16(sizeof(msg) - sizeof(msg.hdr)), in iwl_mei_alive_notif()
1521 if (!mei || !mei->pldr_active) in iwl_mei_alive_notif()
1524 mei->pldr_active = false; in iwl_mei_alive_notif()
1526 iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr); in iwl_mei_alive_notif()
1537 .hdr.len = cpu_to_le16(sizeof(msg) - sizeof(msg.hdr)), in iwl_mei_host_associated()
1539 .ssid_len = cpu_to_le32(conn_info->ssid_len), in iwl_mei_host_associated()
1540 .channel = conn_info->channel, in iwl_mei_host_associated()
1541 .band = conn_info->band, in iwl_mei_host_associated()
1542 .pairwise_cipher = cpu_to_le32(conn_info->pairwise_cipher), in iwl_mei_host_associated()
1543 .auth_mode = cpu_to_le32(conn_info->auth_mode), in iwl_mei_host_associated()
1548 if (conn_info->ssid_len > ARRAY_SIZE(msg.conn_info.ssid)) in iwl_mei_host_associated()
1551 memcpy(msg.conn_info.ssid, conn_info->ssid, conn_info->ssid_len); in iwl_mei_host_associated()
1552 memcpy(msg.conn_info.bssid, conn_info->bssid, ETH_ALEN); in iwl_mei_host_associated()
1555 msg.colloc_channel = colloc_info->channel; in iwl_mei_host_associated()
1556 msg.colloc_band = colloc_info->channel <= 14 ? 0 : 1; in iwl_mei_host_associated()
1557 memcpy(msg.colloc_bssid, colloc_info->bssid, ETH_ALEN); in iwl_mei_host_associated()
1567 if (!mei || !mei->amt_enabled) in iwl_mei_host_associated()
1570 iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr); in iwl_mei_host_associated()
1585 .hdr.len = cpu_to_le16(sizeof(msg) - sizeof(msg.hdr)), in iwl_mei_host_disassociated()
1596 if (!mei || !mei->amt_enabled) in iwl_mei_host_disassociated()
1599 iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr); in iwl_mei_host_disassociated()
1614 .hdr.len = cpu_to_le16(sizeof(msg) - sizeof(msg.hdr)), in iwl_mei_set_rfkill_state()
1632 if (!mei || !mei->amt_enabled) in iwl_mei_set_rfkill_state()
1635 iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr); in iwl_mei_set_rfkill_state()
1648 .hdr.len = cpu_to_le16(sizeof(msg) - sizeof(msg.hdr)), in iwl_mei_set_nic_info()
1661 if (!mei || !mei->amt_enabled) in iwl_mei_set_nic_info()
1664 iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr); in iwl_mei_set_nic_info()
1678 .hdr.len = cpu_to_le16(sizeof(msg) - sizeof(msg.hdr)), in iwl_mei_set_country_code()
1689 if (!mei || !mei->amt_enabled) in iwl_mei_set_country_code()
1692 iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr); in iwl_mei_set_country_code()
1705 .hdr.len = cpu_to_le16(sizeof(msg) - sizeof(msg.hdr)), in iwl_mei_set_power_limit()
1715 if (!mei || !mei->amt_enabled) in iwl_mei_set_power_limit()
1720 iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr); in iwl_mei_set_power_limit()
1759 if (netdev && mei->amt_enabled) in iwl_mei_set_netdev()
1781 mei->device_down = !up; in iwl_mei_device_state()
1783 if (up || !mei->csme_taking_ownership) in iwl_mei_device_state()
1786 iwl_mei_send_sap_msg(mei->cldev, in iwl_mei_device_state()
1788 mei->csme_taking_ownership = false; in iwl_mei_device_state()
1789 schedule_delayed_work(&mei->ownership_dwork, in iwl_mei_device_state()
1801 * We must have a non-NULL priv pointer to not crash when there are in iwl_mei_register()
1805 return -EINVAL; in iwl_mei_register()
1811 ret = -EBUSY; in iwl_mei_register()
1824 if (mei->amt_enabled) in iwl_mei_register()
1825 iwl_mei_send_sap_msg(mei->cldev, in iwl_mei_register()
1827 ops->rfkill(priv, mei->link_prot_state, false); in iwl_mei_register()
1851 /* leave iwl_mei_cache.priv non-NULL to prevent any new registration */ in iwl_mei_start_unregister()
1867 if (mei->amt_enabled) in iwl_mei_unregister_complete()
1868 iwl_mei_send_sap_msg(mei->cldev, in iwl_mei_unregister_complete()
1870 mei->got_ownership = false; in iwl_mei_unregister_complete()
1889 ret = -ENODEV; in iwl_mei_dbgfs_send_start_message_write()
1923 mei->dbgfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL); in iwl_mei_dbgfs_register()
1925 if (!mei->dbgfs_dir) in iwl_mei_dbgfs_register()
1929 mei->dbgfs_dir, &iwl_mei_status); in iwl_mei_dbgfs_register()
1930 debugfs_create_file("send_start_message", S_IWUSR, mei->dbgfs_dir, in iwl_mei_dbgfs_register()
1932 debugfs_create_file("req_ownership", S_IWUSR, mei->dbgfs_dir, in iwl_mei_dbgfs_register()
1938 debugfs_remove_recursive(mei->dbgfs_dir); in iwl_mei_dbgfs_unregister()
1939 mei->dbgfs_dir = NULL; in iwl_mei_dbgfs_unregister()
1957 * iwl_mei_probe - the probe function called by the mei bus enumeration
1971 mei = devm_kzalloc(&cldev->dev, sizeof(*mei), GFP_KERNEL); in iwl_mei_probe()
1973 return -ENOMEM; in iwl_mei_probe()
1975 init_waitqueue_head(&mei->get_nvm_wq); in iwl_mei_probe()
1976 INIT_WORK(&mei->send_csa_msg_wk, iwl_mei_send_csa_msg_wk); in iwl_mei_probe()
1977 INIT_DELAYED_WORK(&mei->csa_throttle_end_wk, in iwl_mei_probe()
1979 init_waitqueue_head(&mei->get_ownership_wq); in iwl_mei_probe()
1980 init_waitqueue_head(&mei->pldr_wq); in iwl_mei_probe()
1981 spin_lock_init(&mei->data_q_lock); in iwl_mei_probe()
1982 INIT_WORK(&mei->netdev_work, iwl_mei_netdev_work); in iwl_mei_probe()
1983 INIT_DELAYED_WORK(&mei->ownership_dwork, iwl_mei_ownership_dwork); in iwl_mei_probe()
1986 mei->cldev = cldev; in iwl_mei_probe()
1987 mei->device_down = true; in iwl_mei_probe()
2002 dev_dbg(&cldev->dev, in iwl_mei_probe()
2006 alloc_retry--; in iwl_mei_probe()
2010 dev_err(&cldev->dev, "Couldn't allocate the shared memory: %d\n", in iwl_mei_probe()
2045 devm_kfree(&cldev->dev, mei); in iwl_mei_probe()
2071 while (!down && iter--) { in iwl_mei_remove()
2075 down = mei->device_down; in iwl_mei_remove()
2080 iwl_mei_cache.ops->nic_stolen(iwl_mei_cache.priv); in iwl_mei_remove()
2110 mei->csa_throttled = false; in iwl_mei_remove()
2111 iwl_mei_send_sap_msg(mei->cldev, in iwl_mei_remove()
2127 dev_err(&mei->cldev->dev, in iwl_mei_remove()
2134 * iwl_mei_add_data_to_ring called from the Tx path sees that we in iwl_mei_remove()
2139 spin_lock_bh(&mei->data_q_lock); in iwl_mei_remove()
2141 spin_unlock_bh(&mei->data_q_lock); in iwl_mei_remove()
2144 iwl_mei_cache.ops->rfkill(iwl_mei_cache.priv, false, false); in iwl_mei_remove()
2159 cancel_work_sync(&mei->send_csa_msg_wk); in iwl_mei_remove()
2160 cancel_delayed_work_sync(&mei->csa_throttle_end_wk); in iwl_mei_remove()
2161 cancel_work_sync(&mei->netdev_work); in iwl_mei_remove()
2162 cancel_delayed_work_sync(&mei->ownership_dwork); in iwl_mei_remove()
2169 wake_up_all(&mei->get_ownership_wq); in iwl_mei_remove()
2170 wake_up_all(&mei->pldr_wq); in iwl_mei_remove()
2176 wake_up_all(&mei->get_nvm_wq); in iwl_mei_remove()
2184 kfree(mei->nvm); in iwl_mei_remove()
2186 kfree(rcu_access_pointer(mei->filters)); in iwl_mei_remove()
2188 devm_kfree(&cldev->dev, mei); in iwl_mei_remove()