1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64#include "iwl-drv.h"
65#include "runtime.h"
66#include "fw/api/commands.h"
67
68static void iwl_parse_shared_mem_22000(struct iwl_fw_runtime *fwrt,
69 struct iwl_rx_packet *pkt)
70{
71 struct iwl_shared_mem_cfg *mem_cfg = (void *)pkt->data;
72 int i, lmac;
73 int lmac_num = le32_to_cpu(mem_cfg->lmac_num);
74
75 if (WARN_ON(lmac_num > ARRAY_SIZE(mem_cfg->lmac_smem)))
76 return;
77
78 fwrt->smem_cfg.num_lmacs = lmac_num;
79 fwrt->smem_cfg.num_txfifo_entries =
80 ARRAY_SIZE(mem_cfg->lmac_smem[0].txfifo_size);
81 fwrt->smem_cfg.rxfifo2_size = le32_to_cpu(mem_cfg->rxfifo2_size);
82
83 for (lmac = 0; lmac < lmac_num; lmac++) {
84 struct iwl_shared_mem_lmac_cfg *lmac_cfg =
85 &mem_cfg->lmac_smem[lmac];
86
87 for (i = 0; i < ARRAY_SIZE(lmac_cfg->txfifo_size); i++)
88 fwrt->smem_cfg.lmac[lmac].txfifo_size[i] =
89 le32_to_cpu(lmac_cfg->txfifo_size[i]);
90 fwrt->smem_cfg.lmac[lmac].rxfifo1_size =
91 le32_to_cpu(lmac_cfg->rxfifo1_size);
92 }
93}
94
95static void iwl_parse_shared_mem(struct iwl_fw_runtime *fwrt,
96 struct iwl_rx_packet *pkt)
97{
98 struct iwl_shared_mem_cfg_v2 *mem_cfg = (void *)pkt->data;
99 int i;
100
101 fwrt->smem_cfg.num_lmacs = 1;
102
103 fwrt->smem_cfg.num_txfifo_entries = ARRAY_SIZE(mem_cfg->txfifo_size);
104 for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++)
105 fwrt->smem_cfg.lmac[0].txfifo_size[i] =
106 le32_to_cpu(mem_cfg->txfifo_size[i]);
107
108 fwrt->smem_cfg.lmac[0].rxfifo1_size =
109 le32_to_cpu(mem_cfg->rxfifo_size[0]);
110 fwrt->smem_cfg.rxfifo2_size = le32_to_cpu(mem_cfg->rxfifo_size[1]);
111
112
113 if (fw_has_capa(&fwrt->fw->ucode_capa,
114 IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
115 BUILD_BUG_ON(sizeof(fwrt->smem_cfg.internal_txfifo_size) !=
116 sizeof(mem_cfg->internal_txfifo_size));
117
118 fwrt->smem_cfg.internal_txfifo_addr =
119 le32_to_cpu(mem_cfg->internal_txfifo_addr);
120
121 for (i = 0;
122 i < ARRAY_SIZE(fwrt->smem_cfg.internal_txfifo_size);
123 i++)
124 fwrt->smem_cfg.internal_txfifo_size[i] =
125 le32_to_cpu(mem_cfg->internal_txfifo_size[i]);
126 }
127}
128
129void iwl_get_shared_mem_conf(struct iwl_fw_runtime *fwrt)
130{
131 struct iwl_host_cmd cmd = {
132 .flags = CMD_WANT_SKB,
133 .data = { NULL, },
134 .len = { 0, },
135 };
136 struct iwl_rx_packet *pkt;
137 int ret;
138
139 if (fw_has_capa(&fwrt->fw->ucode_capa,
140 IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG))
141 cmd.id = iwl_cmd_id(SHARED_MEM_CFG_CMD, SYSTEM_GROUP, 0);
142 else
143 cmd.id = SHARED_MEM_CFG;
144
145 ret = iwl_trans_send_cmd(fwrt->trans, &cmd);
146
147 if (ret) {
148 WARN(ret != -ERFKILL,
149 "Could not send the SMEM command: %d\n", ret);
150 return;
151 }
152
153 pkt = cmd.resp_pkt;
154 if (fwrt->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000)
155 iwl_parse_shared_mem_22000(fwrt, pkt);
156 else
157 iwl_parse_shared_mem(fwrt, pkt);
158
159 IWL_DEBUG_INFO(fwrt, "SHARED MEM CFG: got memory offsets/sizes\n");
160
161 iwl_free_resp(&cmd);
162}
163IWL_EXPORT_SYMBOL(iwl_get_shared_mem_conf);
164