]>
Commit | Line | Data |
---|---|---|
32a47e72 YM |
1 | /* QLogic qed NIC Driver |
2 | * Copyright (c) 2015 QLogic Corporation | |
3 | * | |
4 | * This software is available under the terms of the GNU General Public License | |
5 | * (GPL) Version 2, available from the file COPYING in the main directory of | |
6 | * this source tree. | |
7 | */ | |
8 | ||
dacd88d6 | 9 | #include <linux/etherdevice.h> |
36558c3d | 10 | #include <linux/crc32.h> |
0b55e27d | 11 | #include <linux/qed/qed_iov_if.h> |
1408cc1f YM |
12 | #include "qed_cxt.h" |
13 | #include "qed_hsi.h" | |
32a47e72 | 14 | #include "qed_hw.h" |
1408cc1f | 15 | #include "qed_init_ops.h" |
32a47e72 | 16 | #include "qed_int.h" |
1408cc1f | 17 | #include "qed_mcp.h" |
32a47e72 | 18 | #include "qed_reg_addr.h" |
1408cc1f | 19 | #include "qed_sp.h" |
32a47e72 YM |
20 | #include "qed_sriov.h" |
21 | #include "qed_vf.h" | |
22 | ||
1408cc1f YM |
23 | /* IOV ramrods */ |
24 | static int qed_sp_vf_start(struct qed_hwfn *p_hwfn, | |
25 | u32 concrete_vfid, u16 opaque_vfid) | |
26 | { | |
27 | struct vf_start_ramrod_data *p_ramrod = NULL; | |
28 | struct qed_spq_entry *p_ent = NULL; | |
29 | struct qed_sp_init_data init_data; | |
30 | int rc = -EINVAL; | |
31 | ||
32 | /* Get SPQ entry */ | |
33 | memset(&init_data, 0, sizeof(init_data)); | |
34 | init_data.cid = qed_spq_get_cid(p_hwfn); | |
35 | init_data.opaque_fid = opaque_vfid; | |
36 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; | |
37 | ||
38 | rc = qed_sp_init_request(p_hwfn, &p_ent, | |
39 | COMMON_RAMROD_VF_START, | |
40 | PROTOCOLID_COMMON, &init_data); | |
41 | if (rc) | |
42 | return rc; | |
43 | ||
44 | p_ramrod = &p_ent->ramrod.vf_start; | |
45 | ||
46 | p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID); | |
47 | p_ramrod->opaque_fid = cpu_to_le16(opaque_vfid); | |
48 | ||
49 | p_ramrod->personality = PERSONALITY_ETH; | |
351a4ded YM |
50 | p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR; |
51 | p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MINOR; | |
1408cc1f YM |
52 | |
53 | return qed_spq_post(p_hwfn, p_ent, NULL); | |
54 | } | |
55 | ||
0b55e27d YM |
56 | static int qed_sp_vf_stop(struct qed_hwfn *p_hwfn, |
57 | u32 concrete_vfid, u16 opaque_vfid) | |
58 | { | |
59 | struct vf_stop_ramrod_data *p_ramrod = NULL; | |
60 | struct qed_spq_entry *p_ent = NULL; | |
61 | struct qed_sp_init_data init_data; | |
62 | int rc = -EINVAL; | |
63 | ||
64 | /* Get SPQ entry */ | |
65 | memset(&init_data, 0, sizeof(init_data)); | |
66 | init_data.cid = qed_spq_get_cid(p_hwfn); | |
67 | init_data.opaque_fid = opaque_vfid; | |
68 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; | |
69 | ||
70 | rc = qed_sp_init_request(p_hwfn, &p_ent, | |
71 | COMMON_RAMROD_VF_STOP, | |
72 | PROTOCOLID_COMMON, &init_data); | |
73 | if (rc) | |
74 | return rc; | |
75 | ||
76 | p_ramrod = &p_ent->ramrod.vf_stop; | |
77 | ||
78 | p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID); | |
79 | ||
80 | return qed_spq_post(p_hwfn, p_ent, NULL); | |
81 | } | |
82 | ||
32a47e72 YM |
83 | bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn, |
84 | int rel_vf_id, bool b_enabled_only) | |
85 | { | |
86 | if (!p_hwfn->pf_iov_info) { | |
87 | DP_NOTICE(p_hwfn->cdev, "No iov info\n"); | |
88 | return false; | |
89 | } | |
90 | ||
91 | if ((rel_vf_id >= p_hwfn->cdev->p_iov_info->total_vfs) || | |
92 | (rel_vf_id < 0)) | |
93 | return false; | |
94 | ||
95 | if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) && | |
96 | b_enabled_only) | |
97 | return false; | |
98 | ||
99 | return true; | |
100 | } | |
101 | ||
37bff2b9 YM |
102 | static struct qed_vf_info *qed_iov_get_vf_info(struct qed_hwfn *p_hwfn, |
103 | u16 relative_vf_id, | |
104 | bool b_enabled_only) | |
105 | { | |
106 | struct qed_vf_info *vf = NULL; | |
107 | ||
108 | if (!p_hwfn->pf_iov_info) { | |
109 | DP_NOTICE(p_hwfn->cdev, "No iov info\n"); | |
110 | return NULL; | |
111 | } | |
112 | ||
113 | if (qed_iov_is_valid_vfid(p_hwfn, relative_vf_id, b_enabled_only)) | |
114 | vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id]; | |
115 | else | |
116 | DP_ERR(p_hwfn, "qed_iov_get_vf_info: VF[%d] is not enabled\n", | |
117 | relative_vf_id); | |
118 | ||
119 | return vf; | |
120 | } | |
121 | ||
36558c3d YM |
122 | int qed_iov_post_vf_bulletin(struct qed_hwfn *p_hwfn, |
123 | int vfid, struct qed_ptt *p_ptt) | |
124 | { | |
125 | struct qed_bulletin_content *p_bulletin; | |
126 | int crc_size = sizeof(p_bulletin->crc); | |
127 | struct qed_dmae_params params; | |
128 | struct qed_vf_info *p_vf; | |
129 | ||
130 | p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true); | |
131 | if (!p_vf) | |
132 | return -EINVAL; | |
133 | ||
134 | if (!p_vf->vf_bulletin) | |
135 | return -EINVAL; | |
136 | ||
137 | p_bulletin = p_vf->bulletin.p_virt; | |
138 | ||
139 | /* Increment bulletin board version and compute crc */ | |
140 | p_bulletin->version++; | |
141 | p_bulletin->crc = crc32(0, (u8 *)p_bulletin + crc_size, | |
142 | p_vf->bulletin.size - crc_size); | |
143 | ||
144 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
145 | "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n", | |
146 | p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc); | |
147 | ||
148 | /* propagate bulletin board via dmae to vm memory */ | |
149 | memset(¶ms, 0, sizeof(params)); | |
150 | params.flags = QED_DMAE_FLAG_VF_DST; | |
151 | params.dst_vfid = p_vf->abs_vf_id; | |
152 | return qed_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys, | |
153 | p_vf->vf_bulletin, p_vf->bulletin.size / 4, | |
154 | ¶ms); | |
155 | } | |
156 | ||
32a47e72 YM |
157 | static int qed_iov_pci_cfg_info(struct qed_dev *cdev) |
158 | { | |
159 | struct qed_hw_sriov_info *iov = cdev->p_iov_info; | |
160 | int pos = iov->pos; | |
161 | ||
162 | DP_VERBOSE(cdev, QED_MSG_IOV, "sriov ext pos %d\n", pos); | |
163 | pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_CTRL, &iov->ctrl); | |
164 | ||
165 | pci_read_config_word(cdev->pdev, | |
166 | pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs); | |
167 | pci_read_config_word(cdev->pdev, | |
168 | pos + PCI_SRIOV_INITIAL_VF, &iov->initial_vfs); | |
169 | ||
170 | pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs); | |
171 | if (iov->num_vfs) { | |
172 | DP_VERBOSE(cdev, | |
173 | QED_MSG_IOV, | |
174 | "Number of VFs are already set to non-zero value. Ignoring PCI configuration value\n"); | |
175 | iov->num_vfs = 0; | |
176 | } | |
177 | ||
178 | pci_read_config_word(cdev->pdev, | |
179 | pos + PCI_SRIOV_VF_OFFSET, &iov->offset); | |
180 | ||
181 | pci_read_config_word(cdev->pdev, | |
182 | pos + PCI_SRIOV_VF_STRIDE, &iov->stride); | |
183 | ||
184 | pci_read_config_word(cdev->pdev, | |
185 | pos + PCI_SRIOV_VF_DID, &iov->vf_device_id); | |
186 | ||
187 | pci_read_config_dword(cdev->pdev, | |
188 | pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz); | |
189 | ||
190 | pci_read_config_dword(cdev->pdev, pos + PCI_SRIOV_CAP, &iov->cap); | |
191 | ||
192 | pci_read_config_byte(cdev->pdev, pos + PCI_SRIOV_FUNC_LINK, &iov->link); | |
193 | ||
194 | DP_VERBOSE(cdev, | |
195 | QED_MSG_IOV, | |
196 | "IOV info: nres %d, cap 0x%x, ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d, stride %d, page size 0x%x\n", | |
197 | iov->nres, | |
198 | iov->cap, | |
199 | iov->ctrl, | |
200 | iov->total_vfs, | |
201 | iov->initial_vfs, | |
202 | iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz); | |
203 | ||
204 | /* Some sanity checks */ | |
205 | if (iov->num_vfs > NUM_OF_VFS(cdev) || | |
206 | iov->total_vfs > NUM_OF_VFS(cdev)) { | |
207 | /* This can happen only due to a bug. In this case we set | |
208 | * num_vfs to zero to avoid memory corruption in the code that | |
209 | * assumes max number of vfs | |
210 | */ | |
211 | DP_NOTICE(cdev, | |
212 | "IOV: Unexpected number of vfs set: %d setting num_vf to zero\n", | |
213 | iov->num_vfs); | |
214 | ||
215 | iov->num_vfs = 0; | |
216 | iov->total_vfs = 0; | |
217 | } | |
218 | ||
219 | return 0; | |
220 | } | |
221 | ||
222 | static void qed_iov_clear_vf_igu_blocks(struct qed_hwfn *p_hwfn, | |
223 | struct qed_ptt *p_ptt) | |
224 | { | |
225 | struct qed_igu_block *p_sb; | |
226 | u16 sb_id; | |
227 | u32 val; | |
228 | ||
229 | if (!p_hwfn->hw_info.p_igu_info) { | |
230 | DP_ERR(p_hwfn, | |
231 | "qed_iov_clear_vf_igu_blocks IGU Info not initialized\n"); | |
232 | return; | |
233 | } | |
234 | ||
235 | for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev); | |
236 | sb_id++) { | |
237 | p_sb = &p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks[sb_id]; | |
238 | if ((p_sb->status & QED_IGU_STATUS_FREE) && | |
239 | !(p_sb->status & QED_IGU_STATUS_PF)) { | |
240 | val = qed_rd(p_hwfn, p_ptt, | |
241 | IGU_REG_MAPPING_MEMORY + sb_id * 4); | |
242 | SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0); | |
243 | qed_wr(p_hwfn, p_ptt, | |
244 | IGU_REG_MAPPING_MEMORY + 4 * sb_id, val); | |
245 | } | |
246 | } | |
247 | } | |
248 | ||
249 | static void qed_iov_setup_vfdb(struct qed_hwfn *p_hwfn) | |
250 | { | |
251 | struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info; | |
252 | struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info; | |
253 | struct qed_bulletin_content *p_bulletin_virt; | |
254 | dma_addr_t req_p, rply_p, bulletin_p; | |
255 | union pfvf_tlvs *p_reply_virt_addr; | |
256 | union vfpf_tlvs *p_req_virt_addr; | |
257 | u8 idx = 0; | |
258 | ||
259 | memset(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array)); | |
260 | ||
261 | p_req_virt_addr = p_iov_info->mbx_msg_virt_addr; | |
262 | req_p = p_iov_info->mbx_msg_phys_addr; | |
263 | p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr; | |
264 | rply_p = p_iov_info->mbx_reply_phys_addr; | |
265 | p_bulletin_virt = p_iov_info->p_bulletins; | |
266 | bulletin_p = p_iov_info->bulletins_phys; | |
267 | if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) { | |
268 | DP_ERR(p_hwfn, | |
269 | "qed_iov_setup_vfdb called without allocating mem first\n"); | |
270 | return; | |
271 | } | |
272 | ||
273 | for (idx = 0; idx < p_iov->total_vfs; idx++) { | |
274 | struct qed_vf_info *vf = &p_iov_info->vfs_array[idx]; | |
275 | u32 concrete; | |
276 | ||
277 | vf->vf_mbx.req_virt = p_req_virt_addr + idx; | |
278 | vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs); | |
279 | vf->vf_mbx.reply_virt = p_reply_virt_addr + idx; | |
280 | vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs); | |
281 | ||
282 | vf->state = VF_STOPPED; | |
283 | vf->b_init = false; | |
284 | ||
285 | vf->bulletin.phys = idx * | |
286 | sizeof(struct qed_bulletin_content) + | |
287 | bulletin_p; | |
288 | vf->bulletin.p_virt = p_bulletin_virt + idx; | |
289 | vf->bulletin.size = sizeof(struct qed_bulletin_content); | |
290 | ||
291 | vf->relative_vf_id = idx; | |
292 | vf->abs_vf_id = idx + p_iov->first_vf_in_pf; | |
293 | concrete = qed_vfid_to_concrete(p_hwfn, vf->abs_vf_id); | |
294 | vf->concrete_fid = concrete; | |
295 | vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) | | |
296 | (vf->abs_vf_id << 8); | |
297 | vf->vport_id = idx + 1; | |
298 | } | |
299 | } | |
300 | ||
301 | static int qed_iov_allocate_vfdb(struct qed_hwfn *p_hwfn) | |
302 | { | |
303 | struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info; | |
304 | void **p_v_addr; | |
305 | u16 num_vfs = 0; | |
306 | ||
307 | num_vfs = p_hwfn->cdev->p_iov_info->total_vfs; | |
308 | ||
309 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
310 | "qed_iov_allocate_vfdb for %d VFs\n", num_vfs); | |
311 | ||
312 | /* Allocate PF Mailbox buffer (per-VF) */ | |
313 | p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs; | |
314 | p_v_addr = &p_iov_info->mbx_msg_virt_addr; | |
315 | *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, | |
316 | p_iov_info->mbx_msg_size, | |
317 | &p_iov_info->mbx_msg_phys_addr, | |
318 | GFP_KERNEL); | |
319 | if (!*p_v_addr) | |
320 | return -ENOMEM; | |
321 | ||
322 | /* Allocate PF Mailbox Reply buffer (per-VF) */ | |
323 | p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs; | |
324 | p_v_addr = &p_iov_info->mbx_reply_virt_addr; | |
325 | *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, | |
326 | p_iov_info->mbx_reply_size, | |
327 | &p_iov_info->mbx_reply_phys_addr, | |
328 | GFP_KERNEL); | |
329 | if (!*p_v_addr) | |
330 | return -ENOMEM; | |
331 | ||
332 | p_iov_info->bulletins_size = sizeof(struct qed_bulletin_content) * | |
333 | num_vfs; | |
334 | p_v_addr = &p_iov_info->p_bulletins; | |
335 | *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, | |
336 | p_iov_info->bulletins_size, | |
337 | &p_iov_info->bulletins_phys, | |
338 | GFP_KERNEL); | |
339 | if (!*p_v_addr) | |
340 | return -ENOMEM; | |
341 | ||
342 | DP_VERBOSE(p_hwfn, | |
343 | QED_MSG_IOV, | |
344 | "PF's Requests mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys] Bulletins [%p virt 0x%llx phys]\n", | |
345 | p_iov_info->mbx_msg_virt_addr, | |
346 | (u64) p_iov_info->mbx_msg_phys_addr, | |
347 | p_iov_info->mbx_reply_virt_addr, | |
348 | (u64) p_iov_info->mbx_reply_phys_addr, | |
349 | p_iov_info->p_bulletins, (u64) p_iov_info->bulletins_phys); | |
350 | ||
351 | return 0; | |
352 | } | |
353 | ||
354 | static void qed_iov_free_vfdb(struct qed_hwfn *p_hwfn) | |
355 | { | |
356 | struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info; | |
357 | ||
358 | if (p_hwfn->pf_iov_info->mbx_msg_virt_addr) | |
359 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, | |
360 | p_iov_info->mbx_msg_size, | |
361 | p_iov_info->mbx_msg_virt_addr, | |
362 | p_iov_info->mbx_msg_phys_addr); | |
363 | ||
364 | if (p_hwfn->pf_iov_info->mbx_reply_virt_addr) | |
365 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, | |
366 | p_iov_info->mbx_reply_size, | |
367 | p_iov_info->mbx_reply_virt_addr, | |
368 | p_iov_info->mbx_reply_phys_addr); | |
369 | ||
370 | if (p_iov_info->p_bulletins) | |
371 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, | |
372 | p_iov_info->bulletins_size, | |
373 | p_iov_info->p_bulletins, | |
374 | p_iov_info->bulletins_phys); | |
375 | } | |
376 | ||
377 | int qed_iov_alloc(struct qed_hwfn *p_hwfn) | |
378 | { | |
379 | struct qed_pf_iov *p_sriov; | |
380 | ||
381 | if (!IS_PF_SRIOV(p_hwfn)) { | |
382 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
383 | "No SR-IOV - no need for IOV db\n"); | |
384 | return 0; | |
385 | } | |
386 | ||
387 | p_sriov = kzalloc(sizeof(*p_sriov), GFP_KERNEL); | |
388 | if (!p_sriov) { | |
389 | DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_sriov'\n"); | |
390 | return -ENOMEM; | |
391 | } | |
392 | ||
393 | p_hwfn->pf_iov_info = p_sriov; | |
394 | ||
395 | return qed_iov_allocate_vfdb(p_hwfn); | |
396 | } | |
397 | ||
398 | void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) | |
399 | { | |
400 | if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn)) | |
401 | return; | |
402 | ||
403 | qed_iov_setup_vfdb(p_hwfn); | |
404 | qed_iov_clear_vf_igu_blocks(p_hwfn, p_ptt); | |
405 | } | |
406 | ||
407 | void qed_iov_free(struct qed_hwfn *p_hwfn) | |
408 | { | |
409 | if (IS_PF_SRIOV_ALLOC(p_hwfn)) { | |
410 | qed_iov_free_vfdb(p_hwfn); | |
411 | kfree(p_hwfn->pf_iov_info); | |
412 | } | |
413 | } | |
414 | ||
415 | void qed_iov_free_hw_info(struct qed_dev *cdev) | |
416 | { | |
417 | kfree(cdev->p_iov_info); | |
418 | cdev->p_iov_info = NULL; | |
419 | } | |
420 | ||
421 | int qed_iov_hw_info(struct qed_hwfn *p_hwfn) | |
422 | { | |
423 | struct qed_dev *cdev = p_hwfn->cdev; | |
424 | int pos; | |
425 | int rc; | |
426 | ||
1408cc1f YM |
427 | if (IS_VF(p_hwfn->cdev)) |
428 | return 0; | |
429 | ||
32a47e72 YM |
430 | /* Learn the PCI configuration */ |
431 | pos = pci_find_ext_capability(p_hwfn->cdev->pdev, | |
432 | PCI_EXT_CAP_ID_SRIOV); | |
433 | if (!pos) { | |
434 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No PCIe IOV support\n"); | |
435 | return 0; | |
436 | } | |
437 | ||
438 | /* Allocate a new struct for IOV information */ | |
439 | cdev->p_iov_info = kzalloc(sizeof(*cdev->p_iov_info), GFP_KERNEL); | |
440 | if (!cdev->p_iov_info) { | |
441 | DP_NOTICE(p_hwfn, "Can't support IOV due to lack of memory\n"); | |
442 | return -ENOMEM; | |
443 | } | |
444 | cdev->p_iov_info->pos = pos; | |
445 | ||
446 | rc = qed_iov_pci_cfg_info(cdev); | |
447 | if (rc) | |
448 | return rc; | |
449 | ||
450 | /* We want PF IOV to be synonemous with the existance of p_iov_info; | |
451 | * In case the capability is published but there are no VFs, simply | |
452 | * de-allocate the struct. | |
453 | */ | |
454 | if (!cdev->p_iov_info->total_vfs) { | |
455 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
456 | "IOV capabilities, but no VFs are published\n"); | |
457 | kfree(cdev->p_iov_info); | |
458 | cdev->p_iov_info = NULL; | |
459 | return 0; | |
460 | } | |
461 | ||
462 | /* Calculate the first VF index - this is a bit tricky; Basically, | |
463 | * VFs start at offset 16 relative to PF0, and 2nd engine VFs begin | |
464 | * after the first engine's VFs. | |
465 | */ | |
466 | cdev->p_iov_info->first_vf_in_pf = p_hwfn->cdev->p_iov_info->offset + | |
467 | p_hwfn->abs_pf_id - 16; | |
468 | if (QED_PATH_ID(p_hwfn)) | |
469 | cdev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB; | |
470 | ||
471 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
472 | "First VF in hwfn 0x%08x\n", | |
473 | cdev->p_iov_info->first_vf_in_pf); | |
474 | ||
475 | return 0; | |
476 | } | |
477 | ||
37bff2b9 YM |
478 | static bool qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn, int vfid) |
479 | { | |
480 | /* Check PF supports sriov */ | |
b0409fa0 YM |
481 | if (IS_VF(p_hwfn->cdev) || !IS_QED_SRIOV(p_hwfn->cdev) || |
482 | !IS_PF_SRIOV_ALLOC(p_hwfn)) | |
37bff2b9 YM |
483 | return false; |
484 | ||
485 | /* Check VF validity */ | |
b0409fa0 | 486 | if (!qed_iov_is_valid_vfid(p_hwfn, vfid, true)) |
37bff2b9 YM |
487 | return false; |
488 | ||
489 | return true; | |
490 | } | |
491 | ||
0b55e27d YM |
492 | static void qed_iov_set_vf_to_disable(struct qed_dev *cdev, |
493 | u16 rel_vf_id, u8 to_disable) | |
494 | { | |
495 | struct qed_vf_info *vf; | |
496 | int i; | |
497 | ||
498 | for_each_hwfn(cdev, i) { | |
499 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; | |
500 | ||
501 | vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false); | |
502 | if (!vf) | |
503 | continue; | |
504 | ||
505 | vf->to_disable = to_disable; | |
506 | } | |
507 | } | |
508 | ||
509 | void qed_iov_set_vfs_to_disable(struct qed_dev *cdev, u8 to_disable) | |
510 | { | |
511 | u16 i; | |
512 | ||
513 | if (!IS_QED_SRIOV(cdev)) | |
514 | return; | |
515 | ||
516 | for (i = 0; i < cdev->p_iov_info->total_vfs; i++) | |
517 | qed_iov_set_vf_to_disable(cdev, i, to_disable); | |
518 | } | |
519 | ||
1408cc1f YM |
520 | static void qed_iov_vf_pglue_clear_err(struct qed_hwfn *p_hwfn, |
521 | struct qed_ptt *p_ptt, u8 abs_vfid) | |
522 | { | |
523 | qed_wr(p_hwfn, p_ptt, | |
524 | PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4, | |
525 | 1 << (abs_vfid & 0x1f)); | |
526 | } | |
527 | ||
dacd88d6 YM |
528 | static void qed_iov_vf_igu_reset(struct qed_hwfn *p_hwfn, |
529 | struct qed_ptt *p_ptt, struct qed_vf_info *vf) | |
530 | { | |
dacd88d6 YM |
531 | int i; |
532 | ||
533 | /* Set VF masks and configuration - pretend */ | |
534 | qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid); | |
535 | ||
536 | qed_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0); | |
537 | ||
dacd88d6 YM |
538 | /* unpretend */ |
539 | qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid); | |
540 | ||
541 | /* iterate over all queues, clear sb consumer */ | |
b2b897eb YM |
542 | for (i = 0; i < vf->num_sbs; i++) |
543 | qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt, | |
544 | vf->igu_sbs[i], | |
545 | vf->opaque_fid, true); | |
dacd88d6 YM |
546 | } |
547 | ||
0b55e27d YM |
548 | static void qed_iov_vf_igu_set_int(struct qed_hwfn *p_hwfn, |
549 | struct qed_ptt *p_ptt, | |
550 | struct qed_vf_info *vf, bool enable) | |
551 | { | |
552 | u32 igu_vf_conf; | |
553 | ||
554 | qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid); | |
555 | ||
556 | igu_vf_conf = qed_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION); | |
557 | ||
558 | if (enable) | |
559 | igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN; | |
560 | else | |
561 | igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN; | |
562 | ||
563 | qed_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf); | |
564 | ||
565 | /* unpretend */ | |
566 | qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid); | |
567 | } | |
568 | ||
1408cc1f YM |
569 | static int qed_iov_enable_vf_access(struct qed_hwfn *p_hwfn, |
570 | struct qed_ptt *p_ptt, | |
571 | struct qed_vf_info *vf) | |
572 | { | |
573 | u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN; | |
574 | int rc; | |
575 | ||
0b55e27d YM |
576 | if (vf->to_disable) |
577 | return 0; | |
578 | ||
1408cc1f YM |
579 | DP_VERBOSE(p_hwfn, |
580 | QED_MSG_IOV, | |
581 | "Enable internal access for vf %x [abs %x]\n", | |
582 | vf->abs_vf_id, QED_VF_ABS_ID(p_hwfn, vf)); | |
583 | ||
584 | qed_iov_vf_pglue_clear_err(p_hwfn, p_ptt, QED_VF_ABS_ID(p_hwfn, vf)); | |
585 | ||
b2b897eb YM |
586 | qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf); |
587 | ||
1408cc1f YM |
588 | rc = qed_mcp_config_vf_msix(p_hwfn, p_ptt, vf->abs_vf_id, vf->num_sbs); |
589 | if (rc) | |
590 | return rc; | |
591 | ||
592 | qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid); | |
593 | ||
594 | SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id); | |
595 | STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf); | |
596 | ||
597 | qed_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id, | |
598 | p_hwfn->hw_info.hw_mode); | |
599 | ||
600 | /* unpretend */ | |
601 | qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid); | |
602 | ||
603 | if (vf->state != VF_STOPPED) { | |
604 | DP_NOTICE(p_hwfn, "VF[%02x] is already started\n", | |
605 | vf->abs_vf_id); | |
606 | return -EINVAL; | |
607 | } | |
608 | ||
609 | /* Start VF */ | |
610 | rc = qed_sp_vf_start(p_hwfn, vf->concrete_fid, vf->opaque_fid); | |
611 | if (rc) | |
612 | DP_NOTICE(p_hwfn, "Failed to start VF[%02x]\n", vf->abs_vf_id); | |
613 | ||
614 | vf->state = VF_FREE; | |
615 | ||
616 | return rc; | |
617 | } | |
618 | ||
0b55e27d YM |
619 | /** |
620 | * @brief qed_iov_config_perm_table - configure the permission | |
621 | * zone table. | |
622 | * In E4, queue zone permission table size is 320x9. There | |
623 | * are 320 VF queues for single engine device (256 for dual | |
624 | * engine device), and each entry has the following format: | |
625 | * {Valid, VF[7:0]} | |
626 | * @param p_hwfn | |
627 | * @param p_ptt | |
628 | * @param vf | |
629 | * @param enable | |
630 | */ | |
631 | static void qed_iov_config_perm_table(struct qed_hwfn *p_hwfn, | |
632 | struct qed_ptt *p_ptt, | |
633 | struct qed_vf_info *vf, u8 enable) | |
634 | { | |
635 | u32 reg_addr, val; | |
636 | u16 qzone_id = 0; | |
637 | int qid; | |
638 | ||
639 | for (qid = 0; qid < vf->num_rxqs; qid++) { | |
640 | qed_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid, | |
641 | &qzone_id); | |
642 | ||
643 | reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4; | |
644 | val = enable ? (vf->abs_vf_id | (1 << 8)) : 0; | |
645 | qed_wr(p_hwfn, p_ptt, reg_addr, val); | |
646 | } | |
647 | } | |
648 | ||
dacd88d6 YM |
649 | static void qed_iov_enable_vf_traffic(struct qed_hwfn *p_hwfn, |
650 | struct qed_ptt *p_ptt, | |
651 | struct qed_vf_info *vf) | |
652 | { | |
653 | /* Reset vf in IGU - interrupts are still disabled */ | |
654 | qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf); | |
655 | ||
656 | qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1); | |
657 | ||
658 | /* Permission Table */ | |
659 | qed_iov_config_perm_table(p_hwfn, p_ptt, vf, true); | |
660 | } | |
661 | ||
1408cc1f YM |
662 | static u8 qed_iov_alloc_vf_igu_sbs(struct qed_hwfn *p_hwfn, |
663 | struct qed_ptt *p_ptt, | |
664 | struct qed_vf_info *vf, u16 num_rx_queues) | |
665 | { | |
666 | struct qed_igu_block *igu_blocks; | |
667 | int qid = 0, igu_id = 0; | |
668 | u32 val = 0; | |
669 | ||
670 | igu_blocks = p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks; | |
671 | ||
672 | if (num_rx_queues > p_hwfn->hw_info.p_igu_info->free_blks) | |
673 | num_rx_queues = p_hwfn->hw_info.p_igu_info->free_blks; | |
674 | p_hwfn->hw_info.p_igu_info->free_blks -= num_rx_queues; | |
675 | ||
676 | SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id); | |
677 | SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1); | |
678 | SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0); | |
679 | ||
680 | while ((qid < num_rx_queues) && | |
681 | (igu_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev))) { | |
682 | if (igu_blocks[igu_id].status & QED_IGU_STATUS_FREE) { | |
683 | struct cau_sb_entry sb_entry; | |
684 | ||
685 | vf->igu_sbs[qid] = (u16)igu_id; | |
686 | igu_blocks[igu_id].status &= ~QED_IGU_STATUS_FREE; | |
687 | ||
688 | SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid); | |
689 | ||
690 | qed_wr(p_hwfn, p_ptt, | |
691 | IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id, | |
692 | val); | |
693 | ||
694 | /* Configure igu sb in CAU which were marked valid */ | |
695 | qed_init_cau_sb_entry(p_hwfn, &sb_entry, | |
696 | p_hwfn->rel_pf_id, | |
697 | vf->abs_vf_id, 1); | |
698 | qed_dmae_host2grc(p_hwfn, p_ptt, | |
699 | (u64)(uintptr_t)&sb_entry, | |
700 | CAU_REG_SB_VAR_MEMORY + | |
701 | igu_id * sizeof(u64), 2, 0); | |
702 | qid++; | |
703 | } | |
704 | igu_id++; | |
705 | } | |
706 | ||
707 | vf->num_sbs = (u8) num_rx_queues; | |
708 | ||
709 | return vf->num_sbs; | |
710 | } | |
711 | ||
0b55e27d YM |
712 | static void qed_iov_free_vf_igu_sbs(struct qed_hwfn *p_hwfn, |
713 | struct qed_ptt *p_ptt, | |
714 | struct qed_vf_info *vf) | |
715 | { | |
716 | struct qed_igu_info *p_info = p_hwfn->hw_info.p_igu_info; | |
717 | int idx, igu_id; | |
718 | u32 addr, val; | |
719 | ||
720 | /* Invalidate igu CAM lines and mark them as free */ | |
721 | for (idx = 0; idx < vf->num_sbs; idx++) { | |
722 | igu_id = vf->igu_sbs[idx]; | |
723 | addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id; | |
724 | ||
725 | val = qed_rd(p_hwfn, p_ptt, addr); | |
726 | SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0); | |
727 | qed_wr(p_hwfn, p_ptt, addr, val); | |
728 | ||
729 | p_info->igu_map.igu_blocks[igu_id].status |= | |
730 | QED_IGU_STATUS_FREE; | |
731 | ||
732 | p_hwfn->hw_info.p_igu_info->free_blks++; | |
733 | } | |
734 | ||
735 | vf->num_sbs = 0; | |
736 | } | |
737 | ||
1408cc1f YM |
738 | static int qed_iov_init_hw_for_vf(struct qed_hwfn *p_hwfn, |
739 | struct qed_ptt *p_ptt, | |
740 | u16 rel_vf_id, u16 num_rx_queues) | |
741 | { | |
742 | u8 num_of_vf_avaiable_chains = 0; | |
743 | struct qed_vf_info *vf = NULL; | |
744 | int rc = 0; | |
745 | u32 cids; | |
746 | u8 i; | |
747 | ||
748 | vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false); | |
749 | if (!vf) { | |
750 | DP_ERR(p_hwfn, "qed_iov_init_hw_for_vf : vf is NULL\n"); | |
751 | return -EINVAL; | |
752 | } | |
753 | ||
754 | if (vf->b_init) { | |
755 | DP_NOTICE(p_hwfn, "VF[%d] is already active.\n", rel_vf_id); | |
756 | return -EINVAL; | |
757 | } | |
758 | ||
759 | /* Limit number of queues according to number of CIDs */ | |
760 | qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids); | |
761 | DP_VERBOSE(p_hwfn, | |
762 | QED_MSG_IOV, | |
763 | "VF[%d] - requesting to initialize for 0x%04x queues [0x%04x CIDs available]\n", | |
764 | vf->relative_vf_id, num_rx_queues, (u16) cids); | |
765 | num_rx_queues = min_t(u16, num_rx_queues, ((u16) cids)); | |
766 | ||
767 | num_of_vf_avaiable_chains = qed_iov_alloc_vf_igu_sbs(p_hwfn, | |
768 | p_ptt, | |
769 | vf, | |
770 | num_rx_queues); | |
771 | if (!num_of_vf_avaiable_chains) { | |
772 | DP_ERR(p_hwfn, "no available igu sbs\n"); | |
773 | return -ENOMEM; | |
774 | } | |
775 | ||
776 | /* Choose queue number and index ranges */ | |
777 | vf->num_rxqs = num_of_vf_avaiable_chains; | |
778 | vf->num_txqs = num_of_vf_avaiable_chains; | |
779 | ||
780 | for (i = 0; i < vf->num_rxqs; i++) { | |
781 | u16 queue_id = qed_int_queue_id_from_sb_id(p_hwfn, | |
782 | vf->igu_sbs[i]); | |
783 | ||
784 | if (queue_id > RESC_NUM(p_hwfn, QED_L2_QUEUE)) { | |
785 | DP_NOTICE(p_hwfn, | |
786 | "VF[%d] will require utilizing of out-of-bounds queues - %04x\n", | |
787 | vf->relative_vf_id, queue_id); | |
788 | return -EINVAL; | |
789 | } | |
790 | ||
791 | /* CIDs are per-VF, so no problem having them 0-based. */ | |
792 | vf->vf_queues[i].fw_rx_qid = queue_id; | |
793 | vf->vf_queues[i].fw_tx_qid = queue_id; | |
794 | vf->vf_queues[i].fw_cid = i; | |
795 | ||
796 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
797 | "VF[%d] - [%d] SB %04x, Tx/Rx queue %04x CID %04x\n", | |
798 | vf->relative_vf_id, i, vf->igu_sbs[i], queue_id, i); | |
799 | } | |
800 | rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, vf); | |
801 | if (!rc) { | |
802 | vf->b_init = true; | |
803 | ||
804 | if (IS_LEAD_HWFN(p_hwfn)) | |
805 | p_hwfn->cdev->p_iov_info->num_vfs++; | |
806 | } | |
807 | ||
808 | return rc; | |
809 | } | |
810 | ||
079d20a6 MC |
811 | static void qed_iov_set_link(struct qed_hwfn *p_hwfn, |
812 | u16 vfid, | |
813 | struct qed_mcp_link_params *params, | |
814 | struct qed_mcp_link_state *link, | |
815 | struct qed_mcp_link_capabilities *p_caps) | |
816 | { | |
817 | struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn, | |
818 | vfid, | |
819 | false); | |
820 | struct qed_bulletin_content *p_bulletin; | |
821 | ||
822 | if (!p_vf) | |
823 | return; | |
824 | ||
825 | p_bulletin = p_vf->bulletin.p_virt; | |
826 | p_bulletin->req_autoneg = params->speed.autoneg; | |
827 | p_bulletin->req_adv_speed = params->speed.advertised_speeds; | |
828 | p_bulletin->req_forced_speed = params->speed.forced_speed; | |
829 | p_bulletin->req_autoneg_pause = params->pause.autoneg; | |
830 | p_bulletin->req_forced_rx = params->pause.forced_rx; | |
831 | p_bulletin->req_forced_tx = params->pause.forced_tx; | |
832 | p_bulletin->req_loopback = params->loopback_mode; | |
833 | ||
834 | p_bulletin->link_up = link->link_up; | |
835 | p_bulletin->speed = link->speed; | |
836 | p_bulletin->full_duplex = link->full_duplex; | |
837 | p_bulletin->autoneg = link->an; | |
838 | p_bulletin->autoneg_complete = link->an_complete; | |
839 | p_bulletin->parallel_detection = link->parallel_detection; | |
840 | p_bulletin->pfc_enabled = link->pfc_enabled; | |
841 | p_bulletin->partner_adv_speed = link->partner_adv_speed; | |
842 | p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en; | |
843 | p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en; | |
844 | p_bulletin->partner_adv_pause = link->partner_adv_pause; | |
845 | p_bulletin->sfp_tx_fault = link->sfp_tx_fault; | |
846 | ||
847 | p_bulletin->capability_speed = p_caps->speed_capabilities; | |
848 | } | |
849 | ||
0b55e27d YM |
850 | static int qed_iov_release_hw_for_vf(struct qed_hwfn *p_hwfn, |
851 | struct qed_ptt *p_ptt, u16 rel_vf_id) | |
852 | { | |
079d20a6 MC |
853 | struct qed_mcp_link_capabilities caps; |
854 | struct qed_mcp_link_params params; | |
855 | struct qed_mcp_link_state link; | |
0b55e27d YM |
856 | struct qed_vf_info *vf = NULL; |
857 | int rc = 0; | |
858 | ||
859 | vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true); | |
860 | if (!vf) { | |
861 | DP_ERR(p_hwfn, "qed_iov_release_hw_for_vf : vf is NULL\n"); | |
862 | return -EINVAL; | |
863 | } | |
864 | ||
36558c3d YM |
865 | if (vf->bulletin.p_virt) |
866 | memset(vf->bulletin.p_virt, 0, sizeof(*vf->bulletin.p_virt)); | |
867 | ||
868 | memset(&vf->p_vf_info, 0, sizeof(vf->p_vf_info)); | |
869 | ||
079d20a6 MC |
870 | /* Get the link configuration back in bulletin so |
871 | * that when VFs are re-enabled they get the actual | |
872 | * link configuration. | |
873 | */ | |
874 | memcpy(¶ms, qed_mcp_get_link_params(p_hwfn), sizeof(params)); | |
875 | memcpy(&link, qed_mcp_get_link_state(p_hwfn), sizeof(link)); | |
876 | memcpy(&caps, qed_mcp_get_link_capabilities(p_hwfn), sizeof(caps)); | |
877 | qed_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps); | |
878 | ||
0b55e27d YM |
879 | if (vf->state != VF_STOPPED) { |
880 | /* Stopping the VF */ | |
881 | rc = qed_sp_vf_stop(p_hwfn, vf->concrete_fid, vf->opaque_fid); | |
882 | ||
883 | if (rc != 0) { | |
884 | DP_ERR(p_hwfn, "qed_sp_vf_stop returned error %d\n", | |
885 | rc); | |
886 | return rc; | |
887 | } | |
888 | ||
889 | vf->state = VF_STOPPED; | |
890 | } | |
891 | ||
892 | /* disablng interrupts and resetting permission table was done during | |
893 | * vf-close, however, we could get here without going through vf_close | |
894 | */ | |
895 | /* Disable Interrupts for VF */ | |
896 | qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0); | |
897 | ||
898 | /* Reset Permission table */ | |
899 | qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0); | |
900 | ||
901 | vf->num_rxqs = 0; | |
902 | vf->num_txqs = 0; | |
903 | qed_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf); | |
904 | ||
905 | if (vf->b_init) { | |
906 | vf->b_init = false; | |
907 | ||
908 | if (IS_LEAD_HWFN(p_hwfn)) | |
909 | p_hwfn->cdev->p_iov_info->num_vfs--; | |
910 | } | |
911 | ||
912 | return 0; | |
913 | } | |
914 | ||
37bff2b9 YM |
915 | static bool qed_iov_tlv_supported(u16 tlvtype) |
916 | { | |
917 | return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX; | |
918 | } | |
919 | ||
920 | /* place a given tlv on the tlv buffer, continuing current tlv list */ | |
921 | void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length) | |
922 | { | |
923 | struct channel_tlv *tl = (struct channel_tlv *)*offset; | |
924 | ||
925 | tl->type = type; | |
926 | tl->length = length; | |
927 | ||
928 | /* Offset should keep pointing to next TLV (the end of the last) */ | |
929 | *offset += length; | |
930 | ||
931 | /* Return a pointer to the start of the added tlv */ | |
932 | return *offset - length; | |
933 | } | |
934 | ||
935 | /* list the types and lengths of the tlvs on the buffer */ | |
936 | void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list) | |
937 | { | |
938 | u16 i = 1, total_length = 0; | |
939 | struct channel_tlv *tlv; | |
940 | ||
941 | do { | |
942 | tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length); | |
943 | ||
944 | /* output tlv */ | |
945 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
946 | "TLV number %d: type %d, length %d\n", | |
947 | i, tlv->type, tlv->length); | |
948 | ||
949 | if (tlv->type == CHANNEL_TLV_LIST_END) | |
950 | return; | |
951 | ||
952 | /* Validate entry - protect against malicious VFs */ | |
953 | if (!tlv->length) { | |
954 | DP_NOTICE(p_hwfn, "TLV of length 0 found\n"); | |
955 | return; | |
956 | } | |
957 | ||
958 | total_length += tlv->length; | |
959 | ||
960 | if (total_length >= sizeof(struct tlv_buffer_size)) { | |
961 | DP_NOTICE(p_hwfn, "TLV ==> Buffer overflow\n"); | |
962 | return; | |
963 | } | |
964 | ||
965 | i++; | |
966 | } while (1); | |
967 | } | |
968 | ||
969 | static void qed_iov_send_response(struct qed_hwfn *p_hwfn, | |
970 | struct qed_ptt *p_ptt, | |
971 | struct qed_vf_info *p_vf, | |
972 | u16 length, u8 status) | |
973 | { | |
974 | struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx; | |
975 | struct qed_dmae_params params; | |
976 | u8 eng_vf_id; | |
977 | ||
978 | mbx->reply_virt->default_resp.hdr.status = status; | |
979 | ||
980 | qed_dp_tlv_list(p_hwfn, mbx->reply_virt); | |
981 | ||
982 | eng_vf_id = p_vf->abs_vf_id; | |
983 | ||
984 | memset(¶ms, 0, sizeof(struct qed_dmae_params)); | |
985 | params.flags = QED_DMAE_FLAG_VF_DST; | |
986 | params.dst_vfid = eng_vf_id; | |
987 | ||
988 | qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64), | |
989 | mbx->req_virt->first_tlv.reply_address + | |
990 | sizeof(u64), | |
991 | (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4, | |
992 | ¶ms); | |
993 | ||
994 | qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys, | |
995 | mbx->req_virt->first_tlv.reply_address, | |
996 | sizeof(u64) / 4, ¶ms); | |
997 | ||
998 | REG_WR(p_hwfn, | |
999 | GTT_BAR0_MAP_REG_USDM_RAM + | |
1000 | USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1); | |
1001 | } | |
1002 | ||
dacd88d6 YM |
1003 | static u16 qed_iov_vport_to_tlv(struct qed_hwfn *p_hwfn, |
1004 | enum qed_iov_vport_update_flag flag) | |
1005 | { | |
1006 | switch (flag) { | |
1007 | case QED_IOV_VP_UPDATE_ACTIVATE: | |
1008 | return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE; | |
17b235c1 YM |
1009 | case QED_IOV_VP_UPDATE_VLAN_STRIP: |
1010 | return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP; | |
1011 | case QED_IOV_VP_UPDATE_TX_SWITCH: | |
1012 | return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH; | |
dacd88d6 YM |
1013 | case QED_IOV_VP_UPDATE_MCAST: |
1014 | return CHANNEL_TLV_VPORT_UPDATE_MCAST; | |
1015 | case QED_IOV_VP_UPDATE_ACCEPT_PARAM: | |
1016 | return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM; | |
1017 | case QED_IOV_VP_UPDATE_RSS: | |
1018 | return CHANNEL_TLV_VPORT_UPDATE_RSS; | |
17b235c1 YM |
1019 | case QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN: |
1020 | return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN; | |
1021 | case QED_IOV_VP_UPDATE_SGE_TPA: | |
1022 | return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA; | |
dacd88d6 YM |
1023 | default: |
1024 | return 0; | |
1025 | } | |
1026 | } | |
1027 | ||
1028 | static u16 qed_iov_prep_vp_update_resp_tlvs(struct qed_hwfn *p_hwfn, | |
1029 | struct qed_vf_info *p_vf, | |
1030 | struct qed_iov_vf_mbx *p_mbx, | |
1031 | u8 status, | |
1032 | u16 tlvs_mask, u16 tlvs_accepted) | |
1033 | { | |
1034 | struct pfvf_def_resp_tlv *resp; | |
1035 | u16 size, total_len, i; | |
1036 | ||
1037 | memset(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs)); | |
1038 | p_mbx->offset = (u8 *)p_mbx->reply_virt; | |
1039 | size = sizeof(struct pfvf_def_resp_tlv); | |
1040 | total_len = size; | |
1041 | ||
1042 | qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size); | |
1043 | ||
1044 | /* Prepare response for all extended tlvs if they are found by PF */ | |
1045 | for (i = 0; i < QED_IOV_VP_UPDATE_MAX; i++) { | |
1046 | if (!(tlvs_mask & (1 << i))) | |
1047 | continue; | |
1048 | ||
1049 | resp = qed_add_tlv(p_hwfn, &p_mbx->offset, | |
1050 | qed_iov_vport_to_tlv(p_hwfn, i), size); | |
1051 | ||
1052 | if (tlvs_accepted & (1 << i)) | |
1053 | resp->hdr.status = status; | |
1054 | else | |
1055 | resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED; | |
1056 | ||
1057 | DP_VERBOSE(p_hwfn, | |
1058 | QED_MSG_IOV, | |
1059 | "VF[%d] - vport_update response: TLV %d, status %02x\n", | |
1060 | p_vf->relative_vf_id, | |
1061 | qed_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status); | |
1062 | ||
1063 | total_len += size; | |
1064 | } | |
1065 | ||
1066 | qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END, | |
1067 | sizeof(struct channel_list_end_tlv)); | |
1068 | ||
1069 | return total_len; | |
1070 | } | |
1071 | ||
37bff2b9 YM |
1072 | static void qed_iov_prepare_resp(struct qed_hwfn *p_hwfn, |
1073 | struct qed_ptt *p_ptt, | |
1074 | struct qed_vf_info *vf_info, | |
1075 | u16 type, u16 length, u8 status) | |
1076 | { | |
1077 | struct qed_iov_vf_mbx *mbx = &vf_info->vf_mbx; | |
1078 | ||
1079 | mbx->offset = (u8 *)mbx->reply_virt; | |
1080 | ||
1081 | qed_add_tlv(p_hwfn, &mbx->offset, type, length); | |
1082 | qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END, | |
1083 | sizeof(struct channel_list_end_tlv)); | |
1084 | ||
1085 | qed_iov_send_response(p_hwfn, p_ptt, vf_info, length, status); | |
1086 | } | |
1087 | ||
0b55e27d YM |
1088 | struct qed_public_vf_info *qed_iov_get_public_vf_info(struct qed_hwfn *p_hwfn, |
1089 | u16 relative_vf_id, | |
1090 | bool b_enabled_only) | |
1091 | { | |
1092 | struct qed_vf_info *vf = NULL; | |
1093 | ||
1094 | vf = qed_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only); | |
1095 | if (!vf) | |
1096 | return NULL; | |
1097 | ||
1098 | return &vf->p_vf_info; | |
1099 | } | |
1100 | ||
1101 | void qed_iov_clean_vf(struct qed_hwfn *p_hwfn, u8 vfid) | |
1102 | { | |
1103 | struct qed_public_vf_info *vf_info; | |
1104 | ||
1105 | vf_info = qed_iov_get_public_vf_info(p_hwfn, vfid, false); | |
1106 | ||
1107 | if (!vf_info) | |
1108 | return; | |
1109 | ||
1110 | /* Clear the VF mac */ | |
1111 | memset(vf_info->mac, 0, ETH_ALEN); | |
1112 | } | |
1113 | ||
1114 | static void qed_iov_vf_cleanup(struct qed_hwfn *p_hwfn, | |
1115 | struct qed_vf_info *p_vf) | |
1116 | { | |
1117 | u32 i; | |
1118 | ||
1119 | p_vf->vf_bulletin = 0; | |
dacd88d6 | 1120 | p_vf->vport_instance = 0; |
0b55e27d YM |
1121 | p_vf->num_mac_filters = 0; |
1122 | p_vf->num_vlan_filters = 0; | |
08feecd7 | 1123 | p_vf->configured_features = 0; |
0b55e27d YM |
1124 | |
1125 | /* If VF previously requested less resources, go back to default */ | |
1126 | p_vf->num_rxqs = p_vf->num_sbs; | |
1127 | p_vf->num_txqs = p_vf->num_sbs; | |
1128 | ||
dacd88d6 YM |
1129 | p_vf->num_active_rxqs = 0; |
1130 | ||
0b55e27d YM |
1131 | for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) |
1132 | p_vf->vf_queues[i].rxq_active = 0; | |
1133 | ||
08feecd7 | 1134 | memset(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config)); |
0b55e27d YM |
1135 | qed_iov_clean_vf(p_hwfn, p_vf->relative_vf_id); |
1136 | } | |
1137 | ||
1408cc1f YM |
1138 | static void qed_iov_vf_mbx_acquire(struct qed_hwfn *p_hwfn, |
1139 | struct qed_ptt *p_ptt, | |
1140 | struct qed_vf_info *vf) | |
37bff2b9 | 1141 | { |
1408cc1f YM |
1142 | struct qed_iov_vf_mbx *mbx = &vf->vf_mbx; |
1143 | struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp; | |
1144 | struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info; | |
1145 | struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire; | |
1146 | u8 i, vfpf_status = PFVF_STATUS_SUCCESS; | |
1147 | struct pf_vf_resc *resc = &resp->resc; | |
1148 | ||
1149 | /* Validate FW compatibility */ | |
1150 | if (req->vfdev_info.fw_major != FW_MAJOR_VERSION || | |
1151 | req->vfdev_info.fw_minor != FW_MINOR_VERSION || | |
1152 | req->vfdev_info.fw_revision != FW_REVISION_VERSION || | |
1153 | req->vfdev_info.fw_engineering != FW_ENGINEERING_VERSION) { | |
1154 | DP_INFO(p_hwfn, | |
1155 | "VF[%d] is running an incompatible driver [VF needs FW %02x:%02x:%02x:%02x but Hypervisor is using %02x:%02x:%02x:%02x]\n", | |
1156 | vf->abs_vf_id, | |
1157 | req->vfdev_info.fw_major, | |
1158 | req->vfdev_info.fw_minor, | |
1159 | req->vfdev_info.fw_revision, | |
1160 | req->vfdev_info.fw_engineering, | |
1161 | FW_MAJOR_VERSION, | |
1162 | FW_MINOR_VERSION, | |
1163 | FW_REVISION_VERSION, FW_ENGINEERING_VERSION); | |
1164 | vfpf_status = PFVF_STATUS_NOT_SUPPORTED; | |
1165 | goto out; | |
1166 | } | |
1167 | ||
1168 | /* On 100g PFs, prevent old VFs from loading */ | |
1169 | if ((p_hwfn->cdev->num_hwfns > 1) && | |
1170 | !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) { | |
1171 | DP_INFO(p_hwfn, | |
1172 | "VF[%d] is running an old driver that doesn't support 100g\n", | |
1173 | vf->abs_vf_id); | |
1174 | vfpf_status = PFVF_STATUS_NOT_SUPPORTED; | |
1175 | goto out; | |
1176 | } | |
1177 | ||
1178 | memset(resp, 0, sizeof(*resp)); | |
1179 | ||
1180 | /* Fill in vf info stuff */ | |
1181 | vf->opaque_fid = req->vfdev_info.opaque_fid; | |
1182 | vf->num_mac_filters = 1; | |
1183 | vf->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS; | |
1184 | ||
1185 | vf->vf_bulletin = req->bulletin_addr; | |
1186 | vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ? | |
1187 | vf->bulletin.size : req->bulletin_size; | |
1188 | ||
1189 | /* fill in pfdev info */ | |
1190 | pfdev_info->chip_num = p_hwfn->cdev->chip_num; | |
1191 | pfdev_info->db_size = 0; | |
1192 | pfdev_info->indices_per_sb = PIS_PER_SB; | |
1193 | ||
1194 | pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED | | |
1195 | PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE; | |
1196 | if (p_hwfn->cdev->num_hwfns > 1) | |
1197 | pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G; | |
1198 | ||
1199 | pfdev_info->stats_info.mstats.address = | |
1200 | PXP_VF_BAR0_START_MSDM_ZONE_B + | |
1201 | offsetof(struct mstorm_vf_zone, non_trigger.eth_queue_stat); | |
1202 | pfdev_info->stats_info.mstats.len = | |
1203 | sizeof(struct eth_mstorm_per_queue_stat); | |
1204 | ||
1205 | pfdev_info->stats_info.ustats.address = | |
1206 | PXP_VF_BAR0_START_USDM_ZONE_B + | |
1207 | offsetof(struct ustorm_vf_zone, non_trigger.eth_queue_stat); | |
1208 | pfdev_info->stats_info.ustats.len = | |
1209 | sizeof(struct eth_ustorm_per_queue_stat); | |
1210 | ||
1211 | pfdev_info->stats_info.pstats.address = | |
1212 | PXP_VF_BAR0_START_PSDM_ZONE_B + | |
1213 | offsetof(struct pstorm_vf_zone, non_trigger.eth_queue_stat); | |
1214 | pfdev_info->stats_info.pstats.len = | |
1215 | sizeof(struct eth_pstorm_per_queue_stat); | |
1216 | ||
1217 | pfdev_info->stats_info.tstats.address = 0; | |
1218 | pfdev_info->stats_info.tstats.len = 0; | |
1219 | ||
1220 | memcpy(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr, ETH_ALEN); | |
1221 | ||
1222 | pfdev_info->fw_major = FW_MAJOR_VERSION; | |
1223 | pfdev_info->fw_minor = FW_MINOR_VERSION; | |
1224 | pfdev_info->fw_rev = FW_REVISION_VERSION; | |
1225 | pfdev_info->fw_eng = FW_ENGINEERING_VERSION; | |
1226 | pfdev_info->os_type = VFPF_ACQUIRE_OS_LINUX; | |
1227 | qed_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver, NULL); | |
1228 | ||
1229 | pfdev_info->dev_type = p_hwfn->cdev->type; | |
1230 | pfdev_info->chip_rev = p_hwfn->cdev->chip_rev; | |
1231 | ||
1232 | resc->num_rxqs = vf->num_rxqs; | |
1233 | resc->num_txqs = vf->num_txqs; | |
1234 | resc->num_sbs = vf->num_sbs; | |
1235 | for (i = 0; i < resc->num_sbs; i++) { | |
1236 | resc->hw_sbs[i].hw_sb_id = vf->igu_sbs[i]; | |
1237 | resc->hw_sbs[i].sb_qid = 0; | |
1238 | } | |
1239 | ||
1240 | for (i = 0; i < resc->num_rxqs; i++) { | |
1241 | qed_fw_l2_queue(p_hwfn, vf->vf_queues[i].fw_rx_qid, | |
1242 | (u16 *)&resc->hw_qid[i]); | |
1243 | resc->cid[i] = vf->vf_queues[i].fw_cid; | |
1244 | } | |
1245 | ||
1246 | resc->num_mac_filters = min_t(u8, vf->num_mac_filters, | |
1247 | req->resc_request.num_mac_filters); | |
1248 | resc->num_vlan_filters = min_t(u8, vf->num_vlan_filters, | |
1249 | req->resc_request.num_vlan_filters); | |
1250 | ||
1251 | /* This isn't really required as VF isn't limited, but some VFs might | |
1252 | * actually test this value, so need to provide it. | |
1253 | */ | |
1254 | resc->num_mc_filters = req->resc_request.num_mc_filters; | |
1255 | ||
1256 | /* Fill agreed size of bulletin board in response */ | |
1257 | resp->bulletin_size = vf->bulletin.size; | |
36558c3d | 1258 | qed_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt); |
1408cc1f YM |
1259 | |
1260 | DP_VERBOSE(p_hwfn, | |
1261 | QED_MSG_IOV, | |
1262 | "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%llx\n" | |
1263 | "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d\n", | |
1264 | vf->abs_vf_id, | |
1265 | resp->pfdev_info.chip_num, | |
1266 | resp->pfdev_info.db_size, | |
1267 | resp->pfdev_info.indices_per_sb, | |
1268 | resp->pfdev_info.capabilities, | |
1269 | resc->num_rxqs, | |
1270 | resc->num_txqs, | |
1271 | resc->num_sbs, | |
1272 | resc->num_mac_filters, | |
1273 | resc->num_vlan_filters); | |
1274 | vf->state = VF_ACQUIRED; | |
1275 | ||
1276 | /* Prepare Response */ | |
1277 | out: | |
1278 | qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE, | |
1279 | sizeof(struct pfvf_acquire_resp_tlv), vfpf_status); | |
37bff2b9 YM |
1280 | } |
1281 | ||
6ddc7608 YM |
1282 | static int __qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn, |
1283 | struct qed_vf_info *p_vf, bool val) | |
1284 | { | |
1285 | struct qed_sp_vport_update_params params; | |
1286 | int rc; | |
1287 | ||
1288 | if (val == p_vf->spoof_chk) { | |
1289 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
1290 | "Spoofchk value[%d] is already configured\n", val); | |
1291 | return 0; | |
1292 | } | |
1293 | ||
1294 | memset(¶ms, 0, sizeof(struct qed_sp_vport_update_params)); | |
1295 | params.opaque_fid = p_vf->opaque_fid; | |
1296 | params.vport_id = p_vf->vport_id; | |
1297 | params.update_anti_spoofing_en_flg = 1; | |
1298 | params.anti_spoofing_en = val; | |
1299 | ||
1300 | rc = qed_sp_vport_update(p_hwfn, ¶ms, QED_SPQ_MODE_EBLOCK, NULL); | |
1301 | if (rc) { | |
1302 | p_vf->spoof_chk = val; | |
1303 | p_vf->req_spoofchk_val = p_vf->spoof_chk; | |
1304 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
1305 | "Spoofchk val[%d] configured\n", val); | |
1306 | } else { | |
1307 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
1308 | "Spoofchk configuration[val:%d] failed for VF[%d]\n", | |
1309 | val, p_vf->relative_vf_id); | |
1310 | } | |
1311 | ||
1312 | return rc; | |
1313 | } | |
1314 | ||
08feecd7 YM |
1315 | static int qed_iov_reconfigure_unicast_vlan(struct qed_hwfn *p_hwfn, |
1316 | struct qed_vf_info *p_vf) | |
1317 | { | |
1318 | struct qed_filter_ucast filter; | |
1319 | int rc = 0; | |
1320 | int i; | |
1321 | ||
1322 | memset(&filter, 0, sizeof(filter)); | |
1323 | filter.is_rx_filter = 1; | |
1324 | filter.is_tx_filter = 1; | |
1325 | filter.vport_to_add_to = p_vf->vport_id; | |
1326 | filter.opcode = QED_FILTER_ADD; | |
1327 | ||
1328 | /* Reconfigure vlans */ | |
1329 | for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) { | |
1330 | if (!p_vf->shadow_config.vlans[i].used) | |
1331 | continue; | |
1332 | ||
1333 | filter.type = QED_FILTER_VLAN; | |
1334 | filter.vlan = p_vf->shadow_config.vlans[i].vid; | |
1335 | DP_VERBOSE(p_hwfn, | |
1336 | QED_MSG_IOV, | |
1337 | "Reconfiguring VLAN [0x%04x] for VF [%04x]\n", | |
1338 | filter.vlan, p_vf->relative_vf_id); | |
1339 | rc = qed_sp_eth_filter_ucast(p_hwfn, | |
1340 | p_vf->opaque_fid, | |
1341 | &filter, | |
1342 | QED_SPQ_MODE_CB, NULL); | |
1343 | if (rc) { | |
1344 | DP_NOTICE(p_hwfn, | |
1345 | "Failed to configure VLAN [%04x] to VF [%04x]\n", | |
1346 | filter.vlan, p_vf->relative_vf_id); | |
1347 | break; | |
1348 | } | |
1349 | } | |
1350 | ||
1351 | return rc; | |
1352 | } | |
1353 | ||
1354 | static int | |
1355 | qed_iov_reconfigure_unicast_shadow(struct qed_hwfn *p_hwfn, | |
1356 | struct qed_vf_info *p_vf, u64 events) | |
1357 | { | |
1358 | int rc = 0; | |
1359 | ||
1360 | if ((events & (1 << VLAN_ADDR_FORCED)) && | |
1361 | !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) | |
1362 | rc = qed_iov_reconfigure_unicast_vlan(p_hwfn, p_vf); | |
1363 | ||
1364 | return rc; | |
1365 | } | |
1366 | ||
1367 | static int qed_iov_configure_vport_forced(struct qed_hwfn *p_hwfn, | |
1368 | struct qed_vf_info *p_vf, u64 events) | |
1369 | { | |
1370 | int rc = 0; | |
1371 | struct qed_filter_ucast filter; | |
1372 | ||
1373 | if (!p_vf->vport_instance) | |
1374 | return -EINVAL; | |
1375 | ||
eff16960 YM |
1376 | if (events & (1 << MAC_ADDR_FORCED)) { |
1377 | /* Since there's no way [currently] of removing the MAC, | |
1378 | * we can always assume this means we need to force it. | |
1379 | */ | |
1380 | memset(&filter, 0, sizeof(filter)); | |
1381 | filter.type = QED_FILTER_MAC; | |
1382 | filter.opcode = QED_FILTER_REPLACE; | |
1383 | filter.is_rx_filter = 1; | |
1384 | filter.is_tx_filter = 1; | |
1385 | filter.vport_to_add_to = p_vf->vport_id; | |
1386 | ether_addr_copy(filter.mac, p_vf->bulletin.p_virt->mac); | |
1387 | ||
1388 | rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid, | |
1389 | &filter, QED_SPQ_MODE_CB, NULL); | |
1390 | if (rc) { | |
1391 | DP_NOTICE(p_hwfn, | |
1392 | "PF failed to configure MAC for VF\n"); | |
1393 | return rc; | |
1394 | } | |
1395 | ||
1396 | p_vf->configured_features |= 1 << MAC_ADDR_FORCED; | |
1397 | } | |
1398 | ||
08feecd7 YM |
1399 | if (events & (1 << VLAN_ADDR_FORCED)) { |
1400 | struct qed_sp_vport_update_params vport_update; | |
1401 | u8 removal; | |
1402 | int i; | |
1403 | ||
1404 | memset(&filter, 0, sizeof(filter)); | |
1405 | filter.type = QED_FILTER_VLAN; | |
1406 | filter.is_rx_filter = 1; | |
1407 | filter.is_tx_filter = 1; | |
1408 | filter.vport_to_add_to = p_vf->vport_id; | |
1409 | filter.vlan = p_vf->bulletin.p_virt->pvid; | |
1410 | filter.opcode = filter.vlan ? QED_FILTER_REPLACE : | |
1411 | QED_FILTER_FLUSH; | |
1412 | ||
1413 | /* Send the ramrod */ | |
1414 | rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid, | |
1415 | &filter, QED_SPQ_MODE_CB, NULL); | |
1416 | if (rc) { | |
1417 | DP_NOTICE(p_hwfn, | |
1418 | "PF failed to configure VLAN for VF\n"); | |
1419 | return rc; | |
1420 | } | |
1421 | ||
1422 | /* Update the default-vlan & silent vlan stripping */ | |
1423 | memset(&vport_update, 0, sizeof(vport_update)); | |
1424 | vport_update.opaque_fid = p_vf->opaque_fid; | |
1425 | vport_update.vport_id = p_vf->vport_id; | |
1426 | vport_update.update_default_vlan_enable_flg = 1; | |
1427 | vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0; | |
1428 | vport_update.update_default_vlan_flg = 1; | |
1429 | vport_update.default_vlan = filter.vlan; | |
1430 | ||
1431 | vport_update.update_inner_vlan_removal_flg = 1; | |
1432 | removal = filter.vlan ? 1 | |
1433 | : p_vf->shadow_config.inner_vlan_removal; | |
1434 | vport_update.inner_vlan_removal_flg = removal; | |
1435 | vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0; | |
1436 | rc = qed_sp_vport_update(p_hwfn, | |
1437 | &vport_update, | |
1438 | QED_SPQ_MODE_EBLOCK, NULL); | |
1439 | if (rc) { | |
1440 | DP_NOTICE(p_hwfn, | |
1441 | "PF failed to configure VF vport for vlan\n"); | |
1442 | return rc; | |
1443 | } | |
1444 | ||
1445 | /* Update all the Rx queues */ | |
1446 | for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) { | |
1447 | u16 qid; | |
1448 | ||
1449 | if (!p_vf->vf_queues[i].rxq_active) | |
1450 | continue; | |
1451 | ||
1452 | qid = p_vf->vf_queues[i].fw_rx_qid; | |
1453 | ||
1454 | rc = qed_sp_eth_rx_queues_update(p_hwfn, qid, | |
1455 | 1, 0, 1, | |
1456 | QED_SPQ_MODE_EBLOCK, | |
1457 | NULL); | |
1458 | if (rc) { | |
1459 | DP_NOTICE(p_hwfn, | |
1460 | "Failed to send Rx update fo queue[0x%04x]\n", | |
1461 | qid); | |
1462 | return rc; | |
1463 | } | |
1464 | } | |
1465 | ||
1466 | if (filter.vlan) | |
1467 | p_vf->configured_features |= 1 << VLAN_ADDR_FORCED; | |
1468 | else | |
1469 | p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED); | |
1470 | } | |
1471 | ||
1472 | /* If forced features are terminated, we need to configure the shadow | |
1473 | * configuration back again. | |
1474 | */ | |
1475 | if (events) | |
1476 | qed_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events); | |
1477 | ||
1478 | return rc; | |
1479 | } | |
1480 | ||
dacd88d6 YM |
1481 | static void qed_iov_vf_mbx_start_vport(struct qed_hwfn *p_hwfn, |
1482 | struct qed_ptt *p_ptt, | |
1483 | struct qed_vf_info *vf) | |
1484 | { | |
1485 | struct qed_sp_vport_start_params params = { 0 }; | |
1486 | struct qed_iov_vf_mbx *mbx = &vf->vf_mbx; | |
1487 | struct vfpf_vport_start_tlv *start; | |
1488 | u8 status = PFVF_STATUS_SUCCESS; | |
1489 | struct qed_vf_info *vf_info; | |
08feecd7 | 1490 | u64 *p_bitmap; |
dacd88d6 YM |
1491 | int sb_id; |
1492 | int rc; | |
1493 | ||
1494 | vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vf->relative_vf_id, true); | |
1495 | if (!vf_info) { | |
1496 | DP_NOTICE(p_hwfn->cdev, | |
1497 | "Failed to get VF info, invalid vfid [%d]\n", | |
1498 | vf->relative_vf_id); | |
1499 | return; | |
1500 | } | |
1501 | ||
1502 | vf->state = VF_ENABLED; | |
1503 | start = &mbx->req_virt->start_vport; | |
1504 | ||
1505 | /* Initialize Status block in CAU */ | |
1506 | for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) { | |
1507 | if (!start->sb_addr[sb_id]) { | |
1508 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
1509 | "VF[%d] did not fill the address of SB %d\n", | |
1510 | vf->relative_vf_id, sb_id); | |
1511 | break; | |
1512 | } | |
1513 | ||
1514 | qed_int_cau_conf_sb(p_hwfn, p_ptt, | |
1515 | start->sb_addr[sb_id], | |
1516 | vf->igu_sbs[sb_id], | |
1517 | vf->abs_vf_id, 1); | |
1518 | } | |
1519 | qed_iov_enable_vf_traffic(p_hwfn, p_ptt, vf); | |
1520 | ||
1521 | vf->mtu = start->mtu; | |
08feecd7 YM |
1522 | vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal; |
1523 | ||
1524 | /* Take into consideration configuration forced by hypervisor; | |
1525 | * If none is configured, use the supplied VF values [for old | |
1526 | * vfs that would still be fine, since they passed '0' as padding]. | |
1527 | */ | |
1528 | p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap; | |
1529 | if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) { | |
1530 | u8 vf_req = start->only_untagged; | |
1531 | ||
1532 | vf_info->bulletin.p_virt->default_only_untagged = vf_req; | |
1533 | *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT; | |
1534 | } | |
dacd88d6 YM |
1535 | |
1536 | params.tpa_mode = start->tpa_mode; | |
1537 | params.remove_inner_vlan = start->inner_vlan_removal; | |
831bfb0e | 1538 | params.tx_switching = true; |
dacd88d6 | 1539 | |
08feecd7 | 1540 | params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged; |
dacd88d6 YM |
1541 | params.drop_ttl0 = false; |
1542 | params.concrete_fid = vf->concrete_fid; | |
1543 | params.opaque_fid = vf->opaque_fid; | |
1544 | params.vport_id = vf->vport_id; | |
1545 | params.max_buffers_per_cqe = start->max_buffers_per_cqe; | |
1546 | params.mtu = vf->mtu; | |
1547 | ||
1548 | rc = qed_sp_eth_vport_start(p_hwfn, ¶ms); | |
1549 | if (rc != 0) { | |
1550 | DP_ERR(p_hwfn, | |
1551 | "qed_iov_vf_mbx_start_vport returned error %d\n", rc); | |
1552 | status = PFVF_STATUS_FAILURE; | |
1553 | } else { | |
1554 | vf->vport_instance++; | |
08feecd7 YM |
1555 | |
1556 | /* Force configuration if needed on the newly opened vport */ | |
1557 | qed_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap); | |
6ddc7608 YM |
1558 | |
1559 | __qed_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val); | |
dacd88d6 YM |
1560 | } |
1561 | qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START, | |
1562 | sizeof(struct pfvf_def_resp_tlv), status); | |
1563 | } | |
1564 | ||
1565 | static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn *p_hwfn, | |
1566 | struct qed_ptt *p_ptt, | |
1567 | struct qed_vf_info *vf) | |
1568 | { | |
1569 | u8 status = PFVF_STATUS_SUCCESS; | |
1570 | int rc; | |
1571 | ||
1572 | vf->vport_instance--; | |
6ddc7608 | 1573 | vf->spoof_chk = false; |
dacd88d6 YM |
1574 | |
1575 | rc = qed_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id); | |
1576 | if (rc != 0) { | |
1577 | DP_ERR(p_hwfn, "qed_iov_vf_mbx_stop_vport returned error %d\n", | |
1578 | rc); | |
1579 | status = PFVF_STATUS_FAILURE; | |
1580 | } | |
1581 | ||
08feecd7 YM |
1582 | /* Forget the configuration on the vport */ |
1583 | vf->configured_features = 0; | |
1584 | memset(&vf->shadow_config, 0, sizeof(vf->shadow_config)); | |
1585 | ||
dacd88d6 YM |
1586 | qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN, |
1587 | sizeof(struct pfvf_def_resp_tlv), status); | |
1588 | } | |
1589 | ||
dacd88d6 YM |
1590 | static void qed_iov_vf_mbx_start_rxq_resp(struct qed_hwfn *p_hwfn, |
1591 | struct qed_ptt *p_ptt, | |
1592 | struct qed_vf_info *vf, u8 status) | |
1593 | { | |
1594 | struct qed_iov_vf_mbx *mbx = &vf->vf_mbx; | |
1595 | struct pfvf_start_queue_resp_tlv *p_tlv; | |
1596 | struct vfpf_start_rxq_tlv *req; | |
1597 | ||
1598 | mbx->offset = (u8 *)mbx->reply_virt; | |
1599 | ||
1600 | p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ, | |
1601 | sizeof(*p_tlv)); | |
1602 | qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END, | |
1603 | sizeof(struct channel_list_end_tlv)); | |
1604 | ||
1605 | /* Update the TLV with the response */ | |
1606 | if (status == PFVF_STATUS_SUCCESS) { | |
dacd88d6 | 1607 | req = &mbx->req_virt->start_rxq; |
351a4ded YM |
1608 | p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B + |
1609 | offsetof(struct mstorm_vf_zone, | |
1610 | non_trigger.eth_rx_queue_producers) + | |
1611 | sizeof(struct eth_rx_prod_data) * req->rx_qid; | |
dacd88d6 YM |
1612 | } |
1613 | ||
1614 | qed_iov_send_response(p_hwfn, p_ptt, vf, sizeof(*p_tlv), status); | |
1615 | } | |
1616 | ||
1617 | static void qed_iov_vf_mbx_start_rxq(struct qed_hwfn *p_hwfn, | |
1618 | struct qed_ptt *p_ptt, | |
1619 | struct qed_vf_info *vf) | |
1620 | { | |
1621 | struct qed_queue_start_common_params params; | |
1622 | struct qed_iov_vf_mbx *mbx = &vf->vf_mbx; | |
1623 | u8 status = PFVF_STATUS_SUCCESS; | |
1624 | struct vfpf_start_rxq_tlv *req; | |
1625 | int rc; | |
1626 | ||
1627 | memset(¶ms, 0, sizeof(params)); | |
1628 | req = &mbx->req_virt->start_rxq; | |
1629 | params.queue_id = vf->vf_queues[req->rx_qid].fw_rx_qid; | |
351a4ded | 1630 | params.vf_qid = req->rx_qid; |
dacd88d6 YM |
1631 | params.vport_id = vf->vport_id; |
1632 | params.sb = req->hw_sb; | |
1633 | params.sb_idx = req->sb_index; | |
1634 | ||
1635 | rc = qed_sp_eth_rxq_start_ramrod(p_hwfn, vf->opaque_fid, | |
1636 | vf->vf_queues[req->rx_qid].fw_cid, | |
1637 | ¶ms, | |
1638 | vf->abs_vf_id + 0x10, | |
1639 | req->bd_max_bytes, | |
1640 | req->rxq_addr, | |
1641 | req->cqe_pbl_addr, req->cqe_pbl_size); | |
1642 | ||
1643 | if (rc) { | |
1644 | status = PFVF_STATUS_FAILURE; | |
1645 | } else { | |
1646 | vf->vf_queues[req->rx_qid].rxq_active = true; | |
1647 | vf->num_active_rxqs++; | |
1648 | } | |
1649 | ||
1650 | qed_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status); | |
1651 | } | |
1652 | ||
1653 | static void qed_iov_vf_mbx_start_txq(struct qed_hwfn *p_hwfn, | |
1654 | struct qed_ptt *p_ptt, | |
1655 | struct qed_vf_info *vf) | |
1656 | { | |
1657 | u16 length = sizeof(struct pfvf_def_resp_tlv); | |
1658 | struct qed_queue_start_common_params params; | |
1659 | struct qed_iov_vf_mbx *mbx = &vf->vf_mbx; | |
1660 | union qed_qm_pq_params pq_params; | |
1661 | u8 status = PFVF_STATUS_SUCCESS; | |
1662 | struct vfpf_start_txq_tlv *req; | |
1663 | int rc; | |
1664 | ||
1665 | /* Prepare the parameters which would choose the right PQ */ | |
1666 | memset(&pq_params, 0, sizeof(pq_params)); | |
1667 | pq_params.eth.is_vf = 1; | |
1668 | pq_params.eth.vf_id = vf->relative_vf_id; | |
1669 | ||
1670 | memset(¶ms, 0, sizeof(params)); | |
1671 | req = &mbx->req_virt->start_txq; | |
1672 | params.queue_id = vf->vf_queues[req->tx_qid].fw_tx_qid; | |
1673 | params.vport_id = vf->vport_id; | |
1674 | params.sb = req->hw_sb; | |
1675 | params.sb_idx = req->sb_index; | |
1676 | ||
1677 | rc = qed_sp_eth_txq_start_ramrod(p_hwfn, | |
1678 | vf->opaque_fid, | |
1679 | vf->vf_queues[req->tx_qid].fw_cid, | |
1680 | ¶ms, | |
1681 | vf->abs_vf_id + 0x10, | |
1682 | req->pbl_addr, | |
1683 | req->pbl_size, &pq_params); | |
1684 | ||
1685 | if (rc) | |
1686 | status = PFVF_STATUS_FAILURE; | |
1687 | else | |
1688 | vf->vf_queues[req->tx_qid].txq_active = true; | |
1689 | ||
1690 | qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_START_TXQ, | |
1691 | length, status); | |
1692 | } | |
1693 | ||
1694 | static int qed_iov_vf_stop_rxqs(struct qed_hwfn *p_hwfn, | |
1695 | struct qed_vf_info *vf, | |
1696 | u16 rxq_id, u8 num_rxqs, bool cqe_completion) | |
1697 | { | |
1698 | int rc = 0; | |
1699 | int qid; | |
1700 | ||
1701 | if (rxq_id + num_rxqs > ARRAY_SIZE(vf->vf_queues)) | |
1702 | return -EINVAL; | |
1703 | ||
1704 | for (qid = rxq_id; qid < rxq_id + num_rxqs; qid++) { | |
1705 | if (vf->vf_queues[qid].rxq_active) { | |
1706 | rc = qed_sp_eth_rx_queue_stop(p_hwfn, | |
1707 | vf->vf_queues[qid]. | |
1708 | fw_rx_qid, false, | |
1709 | cqe_completion); | |
1710 | ||
1711 | if (rc) | |
1712 | return rc; | |
1713 | } | |
1714 | vf->vf_queues[qid].rxq_active = false; | |
1715 | vf->num_active_rxqs--; | |
1716 | } | |
1717 | ||
1718 | return rc; | |
1719 | } | |
1720 | ||
1721 | static int qed_iov_vf_stop_txqs(struct qed_hwfn *p_hwfn, | |
1722 | struct qed_vf_info *vf, u16 txq_id, u8 num_txqs) | |
1723 | { | |
1724 | int rc = 0; | |
1725 | int qid; | |
1726 | ||
1727 | if (txq_id + num_txqs > ARRAY_SIZE(vf->vf_queues)) | |
1728 | return -EINVAL; | |
1729 | ||
1730 | for (qid = txq_id; qid < txq_id + num_txqs; qid++) { | |
1731 | if (vf->vf_queues[qid].txq_active) { | |
1732 | rc = qed_sp_eth_tx_queue_stop(p_hwfn, | |
1733 | vf->vf_queues[qid]. | |
1734 | fw_tx_qid); | |
1735 | ||
1736 | if (rc) | |
1737 | return rc; | |
1738 | } | |
1739 | vf->vf_queues[qid].txq_active = false; | |
1740 | } | |
1741 | return rc; | |
1742 | } | |
1743 | ||
1744 | static void qed_iov_vf_mbx_stop_rxqs(struct qed_hwfn *p_hwfn, | |
1745 | struct qed_ptt *p_ptt, | |
1746 | struct qed_vf_info *vf) | |
1747 | { | |
1748 | u16 length = sizeof(struct pfvf_def_resp_tlv); | |
1749 | struct qed_iov_vf_mbx *mbx = &vf->vf_mbx; | |
1750 | u8 status = PFVF_STATUS_SUCCESS; | |
1751 | struct vfpf_stop_rxqs_tlv *req; | |
1752 | int rc; | |
1753 | ||
1754 | /* We give the option of starting from qid != 0, in this case we | |
1755 | * need to make sure that qid + num_qs doesn't exceed the actual | |
1756 | * amount of queues that exist. | |
1757 | */ | |
1758 | req = &mbx->req_virt->stop_rxqs; | |
1759 | rc = qed_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid, | |
1760 | req->num_rxqs, req->cqe_completion); | |
1761 | if (rc) | |
1762 | status = PFVF_STATUS_FAILURE; | |
1763 | ||
1764 | qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS, | |
1765 | length, status); | |
1766 | } | |
1767 | ||
1768 | static void qed_iov_vf_mbx_stop_txqs(struct qed_hwfn *p_hwfn, | |
1769 | struct qed_ptt *p_ptt, | |
1770 | struct qed_vf_info *vf) | |
1771 | { | |
1772 | u16 length = sizeof(struct pfvf_def_resp_tlv); | |
1773 | struct qed_iov_vf_mbx *mbx = &vf->vf_mbx; | |
1774 | u8 status = PFVF_STATUS_SUCCESS; | |
1775 | struct vfpf_stop_txqs_tlv *req; | |
1776 | int rc; | |
1777 | ||
1778 | /* We give the option of starting from qid != 0, in this case we | |
1779 | * need to make sure that qid + num_qs doesn't exceed the actual | |
1780 | * amount of queues that exist. | |
1781 | */ | |
1782 | req = &mbx->req_virt->stop_txqs; | |
1783 | rc = qed_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, req->num_txqs); | |
1784 | if (rc) | |
1785 | status = PFVF_STATUS_FAILURE; | |
1786 | ||
1787 | qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS, | |
1788 | length, status); | |
1789 | } | |
1790 | ||
17b235c1 YM |
1791 | static void qed_iov_vf_mbx_update_rxqs(struct qed_hwfn *p_hwfn, |
1792 | struct qed_ptt *p_ptt, | |
1793 | struct qed_vf_info *vf) | |
1794 | { | |
1795 | u16 length = sizeof(struct pfvf_def_resp_tlv); | |
1796 | struct qed_iov_vf_mbx *mbx = &vf->vf_mbx; | |
1797 | struct vfpf_update_rxq_tlv *req; | |
1798 | u8 status = PFVF_STATUS_SUCCESS; | |
1799 | u8 complete_event_flg; | |
1800 | u8 complete_cqe_flg; | |
1801 | u16 qid; | |
1802 | int rc; | |
1803 | u8 i; | |
1804 | ||
1805 | req = &mbx->req_virt->update_rxq; | |
1806 | complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG); | |
1807 | complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG); | |
1808 | ||
1809 | for (i = 0; i < req->num_rxqs; i++) { | |
1810 | qid = req->rx_qid + i; | |
1811 | ||
1812 | if (!vf->vf_queues[qid].rxq_active) { | |
1813 | DP_NOTICE(p_hwfn, "VF rx_qid = %d isn`t active!\n", | |
1814 | qid); | |
1815 | status = PFVF_STATUS_FAILURE; | |
1816 | break; | |
1817 | } | |
1818 | ||
1819 | rc = qed_sp_eth_rx_queues_update(p_hwfn, | |
1820 | vf->vf_queues[qid].fw_rx_qid, | |
1821 | 1, | |
1822 | complete_cqe_flg, | |
1823 | complete_event_flg, | |
1824 | QED_SPQ_MODE_EBLOCK, NULL); | |
1825 | ||
1826 | if (rc) { | |
1827 | status = PFVF_STATUS_FAILURE; | |
1828 | break; | |
1829 | } | |
1830 | } | |
1831 | ||
1832 | qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ, | |
1833 | length, status); | |
1834 | } | |
1835 | ||
dacd88d6 YM |
1836 | void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn, |
1837 | void *p_tlvs_list, u16 req_type) | |
1838 | { | |
1839 | struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list; | |
1840 | int len = 0; | |
1841 | ||
1842 | do { | |
1843 | if (!p_tlv->length) { | |
1844 | DP_NOTICE(p_hwfn, "Zero length TLV found\n"); | |
1845 | return NULL; | |
1846 | } | |
1847 | ||
1848 | if (p_tlv->type == req_type) { | |
1849 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
1850 | "Extended tlv type %d, length %d found\n", | |
1851 | p_tlv->type, p_tlv->length); | |
1852 | return p_tlv; | |
1853 | } | |
1854 | ||
1855 | len += p_tlv->length; | |
1856 | p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length); | |
1857 | ||
1858 | if ((len + p_tlv->length) > TLV_BUFFER_SIZE) { | |
1859 | DP_NOTICE(p_hwfn, "TLVs has overrun the buffer size\n"); | |
1860 | return NULL; | |
1861 | } | |
1862 | } while (p_tlv->type != CHANNEL_TLV_LIST_END); | |
1863 | ||
1864 | return NULL; | |
1865 | } | |
1866 | ||
1867 | static void | |
1868 | qed_iov_vp_update_act_param(struct qed_hwfn *p_hwfn, | |
1869 | struct qed_sp_vport_update_params *p_data, | |
1870 | struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask) | |
1871 | { | |
1872 | struct vfpf_vport_update_activate_tlv *p_act_tlv; | |
1873 | u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE; | |
1874 | ||
1875 | p_act_tlv = (struct vfpf_vport_update_activate_tlv *) | |
1876 | qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv); | |
1877 | if (!p_act_tlv) | |
1878 | return; | |
1879 | ||
1880 | p_data->update_vport_active_rx_flg = p_act_tlv->update_rx; | |
1881 | p_data->vport_active_rx_flg = p_act_tlv->active_rx; | |
1882 | p_data->update_vport_active_tx_flg = p_act_tlv->update_tx; | |
1883 | p_data->vport_active_tx_flg = p_act_tlv->active_tx; | |
1884 | *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACTIVATE; | |
1885 | } | |
1886 | ||
17b235c1 YM |
1887 | static void |
1888 | qed_iov_vp_update_vlan_param(struct qed_hwfn *p_hwfn, | |
1889 | struct qed_sp_vport_update_params *p_data, | |
1890 | struct qed_vf_info *p_vf, | |
1891 | struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask) | |
1892 | { | |
1893 | struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv; | |
1894 | u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP; | |
1895 | ||
1896 | p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *) | |
1897 | qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv); | |
1898 | if (!p_vlan_tlv) | |
1899 | return; | |
1900 | ||
08feecd7 YM |
1901 | p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan; |
1902 | ||
1903 | /* Ignore the VF request if we're forcing a vlan */ | |
1904 | if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) { | |
1905 | p_data->update_inner_vlan_removal_flg = 1; | |
1906 | p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan; | |
1907 | } | |
17b235c1 YM |
1908 | |
1909 | *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_VLAN_STRIP; | |
1910 | } | |
1911 | ||
1912 | static void | |
1913 | qed_iov_vp_update_tx_switch(struct qed_hwfn *p_hwfn, | |
1914 | struct qed_sp_vport_update_params *p_data, | |
1915 | struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask) | |
1916 | { | |
1917 | struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv; | |
1918 | u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH; | |
1919 | ||
1920 | p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *) | |
1921 | qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, | |
1922 | tlv); | |
1923 | if (!p_tx_switch_tlv) | |
1924 | return; | |
1925 | ||
1926 | p_data->update_tx_switching_flg = 1; | |
1927 | p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching; | |
1928 | *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_TX_SWITCH; | |
1929 | } | |
1930 | ||
dacd88d6 YM |
1931 | static void |
1932 | qed_iov_vp_update_mcast_bin_param(struct qed_hwfn *p_hwfn, | |
1933 | struct qed_sp_vport_update_params *p_data, | |
1934 | struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask) | |
1935 | { | |
1936 | struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv; | |
1937 | u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST; | |
1938 | ||
1939 | p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *) | |
1940 | qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv); | |
1941 | if (!p_mcast_tlv) | |
1942 | return; | |
1943 | ||
1944 | p_data->update_approx_mcast_flg = 1; | |
1945 | memcpy(p_data->bins, p_mcast_tlv->bins, | |
1946 | sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS); | |
1947 | *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_MCAST; | |
1948 | } | |
1949 | ||
1950 | static void | |
1951 | qed_iov_vp_update_accept_flag(struct qed_hwfn *p_hwfn, | |
1952 | struct qed_sp_vport_update_params *p_data, | |
1953 | struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask) | |
1954 | { | |
1955 | struct qed_filter_accept_flags *p_flags = &p_data->accept_flags; | |
1956 | struct vfpf_vport_update_accept_param_tlv *p_accept_tlv; | |
1957 | u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM; | |
1958 | ||
1959 | p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *) | |
1960 | qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv); | |
1961 | if (!p_accept_tlv) | |
1962 | return; | |
1963 | ||
1964 | p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode; | |
1965 | p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter; | |
1966 | p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode; | |
1967 | p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter; | |
1968 | *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_PARAM; | |
1969 | } | |
1970 | ||
17b235c1 YM |
1971 | static void |
1972 | qed_iov_vp_update_accept_any_vlan(struct qed_hwfn *p_hwfn, | |
1973 | struct qed_sp_vport_update_params *p_data, | |
1974 | struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask) | |
1975 | { | |
1976 | struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan; | |
1977 | u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN; | |
1978 | ||
1979 | p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *) | |
1980 | qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, | |
1981 | tlv); | |
1982 | if (!p_accept_any_vlan) | |
1983 | return; | |
1984 | ||
1985 | p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan; | |
1986 | p_data->update_accept_any_vlan_flg = | |
1987 | p_accept_any_vlan->update_accept_any_vlan_flg; | |
1988 | *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN; | |
1989 | } | |
1990 | ||
dacd88d6 YM |
1991 | static void |
1992 | qed_iov_vp_update_rss_param(struct qed_hwfn *p_hwfn, | |
1993 | struct qed_vf_info *vf, | |
1994 | struct qed_sp_vport_update_params *p_data, | |
1995 | struct qed_rss_params *p_rss, | |
1996 | struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask) | |
1997 | { | |
1998 | struct vfpf_vport_update_rss_tlv *p_rss_tlv; | |
1999 | u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS; | |
2000 | u16 i, q_idx, max_q_idx; | |
2001 | u16 table_size; | |
2002 | ||
2003 | p_rss_tlv = (struct vfpf_vport_update_rss_tlv *) | |
2004 | qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv); | |
2005 | if (!p_rss_tlv) { | |
2006 | p_data->rss_params = NULL; | |
2007 | return; | |
2008 | } | |
2009 | ||
2010 | memset(p_rss, 0, sizeof(struct qed_rss_params)); | |
2011 | ||
2012 | p_rss->update_rss_config = !!(p_rss_tlv->update_rss_flags & | |
2013 | VFPF_UPDATE_RSS_CONFIG_FLAG); | |
2014 | p_rss->update_rss_capabilities = !!(p_rss_tlv->update_rss_flags & | |
2015 | VFPF_UPDATE_RSS_CAPS_FLAG); | |
2016 | p_rss->update_rss_ind_table = !!(p_rss_tlv->update_rss_flags & | |
2017 | VFPF_UPDATE_RSS_IND_TABLE_FLAG); | |
2018 | p_rss->update_rss_key = !!(p_rss_tlv->update_rss_flags & | |
2019 | VFPF_UPDATE_RSS_KEY_FLAG); | |
2020 | ||
2021 | p_rss->rss_enable = p_rss_tlv->rss_enable; | |
2022 | p_rss->rss_eng_id = vf->relative_vf_id + 1; | |
2023 | p_rss->rss_caps = p_rss_tlv->rss_caps; | |
2024 | p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log; | |
2025 | memcpy(p_rss->rss_ind_table, p_rss_tlv->rss_ind_table, | |
2026 | sizeof(p_rss->rss_ind_table)); | |
2027 | memcpy(p_rss->rss_key, p_rss_tlv->rss_key, sizeof(p_rss->rss_key)); | |
2028 | ||
2029 | table_size = min_t(u16, ARRAY_SIZE(p_rss->rss_ind_table), | |
2030 | (1 << p_rss_tlv->rss_table_size_log)); | |
2031 | ||
2032 | max_q_idx = ARRAY_SIZE(vf->vf_queues); | |
2033 | ||
2034 | for (i = 0; i < table_size; i++) { | |
2035 | u16 index = vf->vf_queues[0].fw_rx_qid; | |
2036 | ||
2037 | q_idx = p_rss->rss_ind_table[i]; | |
2038 | if (q_idx >= max_q_idx) | |
2039 | DP_NOTICE(p_hwfn, | |
2040 | "rss_ind_table[%d] = %d, rxq is out of range\n", | |
2041 | i, q_idx); | |
2042 | else if (!vf->vf_queues[q_idx].rxq_active) | |
2043 | DP_NOTICE(p_hwfn, | |
2044 | "rss_ind_table[%d] = %d, rxq is not active\n", | |
2045 | i, q_idx); | |
2046 | else | |
2047 | index = vf->vf_queues[q_idx].fw_rx_qid; | |
2048 | p_rss->rss_ind_table[i] = index; | |
2049 | } | |
2050 | ||
2051 | p_data->rss_params = p_rss; | |
2052 | *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_RSS; | |
2053 | } | |
2054 | ||
17b235c1 YM |
2055 | static void |
2056 | qed_iov_vp_update_sge_tpa_param(struct qed_hwfn *p_hwfn, | |
2057 | struct qed_vf_info *vf, | |
2058 | struct qed_sp_vport_update_params *p_data, | |
2059 | struct qed_sge_tpa_params *p_sge_tpa, | |
2060 | struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask) | |
2061 | { | |
2062 | struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv; | |
2063 | u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA; | |
2064 | ||
2065 | p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *) | |
2066 | qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv); | |
2067 | ||
2068 | if (!p_sge_tpa_tlv) { | |
2069 | p_data->sge_tpa_params = NULL; | |
2070 | return; | |
2071 | } | |
2072 | ||
2073 | memset(p_sge_tpa, 0, sizeof(struct qed_sge_tpa_params)); | |
2074 | ||
2075 | p_sge_tpa->update_tpa_en_flg = | |
2076 | !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG); | |
2077 | p_sge_tpa->update_tpa_param_flg = | |
2078 | !!(p_sge_tpa_tlv->update_sge_tpa_flags & | |
2079 | VFPF_UPDATE_TPA_PARAM_FLAG); | |
2080 | ||
2081 | p_sge_tpa->tpa_ipv4_en_flg = | |
2082 | !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG); | |
2083 | p_sge_tpa->tpa_ipv6_en_flg = | |
2084 | !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG); | |
2085 | p_sge_tpa->tpa_pkt_split_flg = | |
2086 | !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG); | |
2087 | p_sge_tpa->tpa_hdr_data_split_flg = | |
2088 | !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG); | |
2089 | p_sge_tpa->tpa_gro_consistent_flg = | |
2090 | !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG); | |
2091 | ||
2092 | p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num; | |
2093 | p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size; | |
2094 | p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start; | |
2095 | p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont; | |
2096 | p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe; | |
2097 | ||
2098 | p_data->sge_tpa_params = p_sge_tpa; | |
2099 | ||
2100 | *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_SGE_TPA; | |
2101 | } | |
2102 | ||
dacd88d6 YM |
2103 | static void qed_iov_vf_mbx_vport_update(struct qed_hwfn *p_hwfn, |
2104 | struct qed_ptt *p_ptt, | |
2105 | struct qed_vf_info *vf) | |
2106 | { | |
2107 | struct qed_sp_vport_update_params params; | |
2108 | struct qed_iov_vf_mbx *mbx = &vf->vf_mbx; | |
17b235c1 | 2109 | struct qed_sge_tpa_params sge_tpa_params; |
dacd88d6 YM |
2110 | struct qed_rss_params rss_params; |
2111 | u8 status = PFVF_STATUS_SUCCESS; | |
2112 | u16 tlvs_mask = 0; | |
2113 | u16 length; | |
2114 | int rc; | |
2115 | ||
2116 | memset(¶ms, 0, sizeof(params)); | |
2117 | params.opaque_fid = vf->opaque_fid; | |
2118 | params.vport_id = vf->vport_id; | |
2119 | params.rss_params = NULL; | |
2120 | ||
2121 | /* Search for extended tlvs list and update values | |
2122 | * from VF in struct qed_sp_vport_update_params. | |
2123 | */ | |
2124 | qed_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask); | |
17b235c1 YM |
2125 | qed_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask); |
2126 | qed_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask); | |
dacd88d6 YM |
2127 | qed_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask); |
2128 | qed_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask); | |
2129 | qed_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, &rss_params, | |
2130 | mbx, &tlvs_mask); | |
17b235c1 YM |
2131 | qed_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask); |
2132 | qed_iov_vp_update_sge_tpa_param(p_hwfn, vf, ¶ms, | |
2133 | &sge_tpa_params, mbx, &tlvs_mask); | |
dacd88d6 YM |
2134 | |
2135 | /* Just log a message if there is no single extended tlv in buffer. | |
2136 | * When all features of vport update ramrod would be requested by VF | |
2137 | * as extended TLVs in buffer then an error can be returned in response | |
2138 | * if there is no extended TLV present in buffer. | |
2139 | */ | |
2140 | if (!tlvs_mask) { | |
2141 | DP_NOTICE(p_hwfn, | |
2142 | "No feature tlvs found for vport update\n"); | |
2143 | status = PFVF_STATUS_NOT_SUPPORTED; | |
2144 | goto out; | |
2145 | } | |
2146 | ||
2147 | rc = qed_sp_vport_update(p_hwfn, ¶ms, QED_SPQ_MODE_EBLOCK, NULL); | |
2148 | ||
2149 | if (rc) | |
2150 | status = PFVF_STATUS_FAILURE; | |
2151 | ||
2152 | out: | |
2153 | length = qed_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status, | |
2154 | tlvs_mask, tlvs_mask); | |
2155 | qed_iov_send_response(p_hwfn, p_ptt, vf, length, status); | |
2156 | } | |
2157 | ||
08feecd7 YM |
2158 | static int qed_iov_vf_update_unicast_shadow(struct qed_hwfn *p_hwfn, |
2159 | struct qed_vf_info *p_vf, | |
2160 | struct qed_filter_ucast *p_params) | |
2161 | { | |
2162 | int i; | |
2163 | ||
2164 | if (p_params->type == QED_FILTER_MAC) | |
2165 | return 0; | |
2166 | ||
2167 | /* First remove entries and then add new ones */ | |
2168 | if (p_params->opcode == QED_FILTER_REMOVE) { | |
2169 | for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) | |
2170 | if (p_vf->shadow_config.vlans[i].used && | |
2171 | p_vf->shadow_config.vlans[i].vid == | |
2172 | p_params->vlan) { | |
2173 | p_vf->shadow_config.vlans[i].used = false; | |
2174 | break; | |
2175 | } | |
2176 | if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) { | |
2177 | DP_VERBOSE(p_hwfn, | |
2178 | QED_MSG_IOV, | |
2179 | "VF [%d] - Tries to remove a non-existing vlan\n", | |
2180 | p_vf->relative_vf_id); | |
2181 | return -EINVAL; | |
2182 | } | |
2183 | } else if (p_params->opcode == QED_FILTER_REPLACE || | |
2184 | p_params->opcode == QED_FILTER_FLUSH) { | |
2185 | for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) | |
2186 | p_vf->shadow_config.vlans[i].used = false; | |
2187 | } | |
2188 | ||
2189 | /* In forced mode, we're willing to remove entries - but we don't add | |
2190 | * new ones. | |
2191 | */ | |
2192 | if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)) | |
2193 | return 0; | |
2194 | ||
2195 | if (p_params->opcode == QED_FILTER_ADD || | |
2196 | p_params->opcode == QED_FILTER_REPLACE) { | |
2197 | for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) { | |
2198 | if (p_vf->shadow_config.vlans[i].used) | |
2199 | continue; | |
2200 | ||
2201 | p_vf->shadow_config.vlans[i].used = true; | |
2202 | p_vf->shadow_config.vlans[i].vid = p_params->vlan; | |
2203 | break; | |
2204 | } | |
2205 | ||
2206 | if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) { | |
2207 | DP_VERBOSE(p_hwfn, | |
2208 | QED_MSG_IOV, | |
2209 | "VF [%d] - Tries to configure more than %d vlan filters\n", | |
2210 | p_vf->relative_vf_id, | |
2211 | QED_ETH_VF_NUM_VLAN_FILTERS + 1); | |
2212 | return -EINVAL; | |
2213 | } | |
2214 | } | |
2215 | ||
2216 | return 0; | |
2217 | } | |
2218 | ||
dacd88d6 YM |
2219 | int qed_iov_chk_ucast(struct qed_hwfn *hwfn, |
2220 | int vfid, struct qed_filter_ucast *params) | |
2221 | { | |
2222 | struct qed_public_vf_info *vf; | |
2223 | ||
2224 | vf = qed_iov_get_public_vf_info(hwfn, vfid, true); | |
2225 | if (!vf) | |
2226 | return -EINVAL; | |
2227 | ||
2228 | /* No real decision to make; Store the configured MAC */ | |
2229 | if (params->type == QED_FILTER_MAC || | |
2230 | params->type == QED_FILTER_MAC_VLAN) | |
2231 | ether_addr_copy(vf->mac, params->mac); | |
2232 | ||
2233 | return 0; | |
2234 | } | |
2235 | ||
2236 | static void qed_iov_vf_mbx_ucast_filter(struct qed_hwfn *p_hwfn, | |
2237 | struct qed_ptt *p_ptt, | |
2238 | struct qed_vf_info *vf) | |
2239 | { | |
08feecd7 | 2240 | struct qed_bulletin_content *p_bulletin = vf->bulletin.p_virt; |
dacd88d6 YM |
2241 | struct qed_iov_vf_mbx *mbx = &vf->vf_mbx; |
2242 | struct vfpf_ucast_filter_tlv *req; | |
2243 | u8 status = PFVF_STATUS_SUCCESS; | |
2244 | struct qed_filter_ucast params; | |
2245 | int rc; | |
2246 | ||
2247 | /* Prepare the unicast filter params */ | |
2248 | memset(¶ms, 0, sizeof(struct qed_filter_ucast)); | |
2249 | req = &mbx->req_virt->ucast_filter; | |
2250 | params.opcode = (enum qed_filter_opcode)req->opcode; | |
2251 | params.type = (enum qed_filter_ucast_type)req->type; | |
2252 | ||
2253 | params.is_rx_filter = 1; | |
2254 | params.is_tx_filter = 1; | |
2255 | params.vport_to_remove_from = vf->vport_id; | |
2256 | params.vport_to_add_to = vf->vport_id; | |
2257 | memcpy(params.mac, req->mac, ETH_ALEN); | |
2258 | params.vlan = req->vlan; | |
2259 | ||
2260 | DP_VERBOSE(p_hwfn, | |
2261 | QED_MSG_IOV, | |
2262 | "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n", | |
2263 | vf->abs_vf_id, params.opcode, params.type, | |
2264 | params.is_rx_filter ? "RX" : "", | |
2265 | params.is_tx_filter ? "TX" : "", | |
2266 | params.vport_to_add_to, | |
2267 | params.mac[0], params.mac[1], | |
2268 | params.mac[2], params.mac[3], | |
2269 | params.mac[4], params.mac[5], params.vlan); | |
2270 | ||
2271 | if (!vf->vport_instance) { | |
2272 | DP_VERBOSE(p_hwfn, | |
2273 | QED_MSG_IOV, | |
2274 | "No VPORT instance available for VF[%d], failing ucast MAC configuration\n", | |
2275 | vf->abs_vf_id); | |
2276 | status = PFVF_STATUS_FAILURE; | |
2277 | goto out; | |
2278 | } | |
2279 | ||
08feecd7 YM |
2280 | /* Update shadow copy of the VF configuration */ |
2281 | if (qed_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms)) { | |
2282 | status = PFVF_STATUS_FAILURE; | |
2283 | goto out; | |
2284 | } | |
2285 | ||
2286 | /* Determine if the unicast filtering is acceptible by PF */ | |
2287 | if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) && | |
2288 | (params.type == QED_FILTER_VLAN || | |
2289 | params.type == QED_FILTER_MAC_VLAN)) { | |
2290 | /* Once VLAN is forced or PVID is set, do not allow | |
2291 | * to add/replace any further VLANs. | |
2292 | */ | |
2293 | if (params.opcode == QED_FILTER_ADD || | |
2294 | params.opcode == QED_FILTER_REPLACE) | |
2295 | status = PFVF_STATUS_FORCED; | |
2296 | goto out; | |
2297 | } | |
2298 | ||
eff16960 YM |
2299 | if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) && |
2300 | (params.type == QED_FILTER_MAC || | |
2301 | params.type == QED_FILTER_MAC_VLAN)) { | |
2302 | if (!ether_addr_equal(p_bulletin->mac, params.mac) || | |
2303 | (params.opcode != QED_FILTER_ADD && | |
2304 | params.opcode != QED_FILTER_REPLACE)) | |
2305 | status = PFVF_STATUS_FORCED; | |
2306 | goto out; | |
2307 | } | |
2308 | ||
dacd88d6 YM |
2309 | rc = qed_iov_chk_ucast(p_hwfn, vf->relative_vf_id, ¶ms); |
2310 | if (rc) { | |
2311 | status = PFVF_STATUS_FAILURE; | |
2312 | goto out; | |
2313 | } | |
2314 | ||
2315 | rc = qed_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms, | |
2316 | QED_SPQ_MODE_CB, NULL); | |
2317 | if (rc) | |
2318 | status = PFVF_STATUS_FAILURE; | |
2319 | ||
2320 | out: | |
2321 | qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER, | |
2322 | sizeof(struct pfvf_def_resp_tlv), status); | |
2323 | } | |
2324 | ||
0b55e27d YM |
2325 | static void qed_iov_vf_mbx_int_cleanup(struct qed_hwfn *p_hwfn, |
2326 | struct qed_ptt *p_ptt, | |
2327 | struct qed_vf_info *vf) | |
2328 | { | |
2329 | int i; | |
2330 | ||
2331 | /* Reset the SBs */ | |
2332 | for (i = 0; i < vf->num_sbs; i++) | |
2333 | qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt, | |
2334 | vf->igu_sbs[i], | |
2335 | vf->opaque_fid, false); | |
2336 | ||
2337 | qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP, | |
2338 | sizeof(struct pfvf_def_resp_tlv), | |
2339 | PFVF_STATUS_SUCCESS); | |
2340 | } | |
2341 | ||
2342 | static void qed_iov_vf_mbx_close(struct qed_hwfn *p_hwfn, | |
2343 | struct qed_ptt *p_ptt, struct qed_vf_info *vf) | |
2344 | { | |
2345 | u16 length = sizeof(struct pfvf_def_resp_tlv); | |
2346 | u8 status = PFVF_STATUS_SUCCESS; | |
2347 | ||
2348 | /* Disable Interrupts for VF */ | |
2349 | qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0); | |
2350 | ||
2351 | /* Reset Permission table */ | |
2352 | qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0); | |
2353 | ||
2354 | qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE, | |
2355 | length, status); | |
2356 | } | |
2357 | ||
2358 | static void qed_iov_vf_mbx_release(struct qed_hwfn *p_hwfn, | |
2359 | struct qed_ptt *p_ptt, | |
2360 | struct qed_vf_info *p_vf) | |
2361 | { | |
2362 | u16 length = sizeof(struct pfvf_def_resp_tlv); | |
2363 | ||
2364 | qed_iov_vf_cleanup(p_hwfn, p_vf); | |
2365 | ||
2366 | qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE, | |
2367 | length, PFVF_STATUS_SUCCESS); | |
2368 | } | |
2369 | ||
2370 | static int | |
2371 | qed_iov_vf_flr_poll_dorq(struct qed_hwfn *p_hwfn, | |
2372 | struct qed_vf_info *p_vf, struct qed_ptt *p_ptt) | |
2373 | { | |
2374 | int cnt; | |
2375 | u32 val; | |
2376 | ||
2377 | qed_fid_pretend(p_hwfn, p_ptt, (u16) p_vf->concrete_fid); | |
2378 | ||
2379 | for (cnt = 0; cnt < 50; cnt++) { | |
2380 | val = qed_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT); | |
2381 | if (!val) | |
2382 | break; | |
2383 | msleep(20); | |
2384 | } | |
2385 | qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid); | |
2386 | ||
2387 | if (cnt == 50) { | |
2388 | DP_ERR(p_hwfn, | |
2389 | "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n", | |
2390 | p_vf->abs_vf_id, val); | |
2391 | return -EBUSY; | |
2392 | } | |
2393 | ||
2394 | return 0; | |
2395 | } | |
2396 | ||
2397 | static int | |
2398 | qed_iov_vf_flr_poll_pbf(struct qed_hwfn *p_hwfn, | |
2399 | struct qed_vf_info *p_vf, struct qed_ptt *p_ptt) | |
2400 | { | |
2401 | u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS]; | |
2402 | int i, cnt; | |
2403 | ||
2404 | /* Read initial consumers & producers */ | |
2405 | for (i = 0; i < MAX_NUM_VOQS; i++) { | |
2406 | u32 prod; | |
2407 | ||
2408 | cons[i] = qed_rd(p_hwfn, p_ptt, | |
2409 | PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 + | |
2410 | i * 0x40); | |
2411 | prod = qed_rd(p_hwfn, p_ptt, | |
2412 | PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 + | |
2413 | i * 0x40); | |
2414 | distance[i] = prod - cons[i]; | |
2415 | } | |
2416 | ||
2417 | /* Wait for consumers to pass the producers */ | |
2418 | i = 0; | |
2419 | for (cnt = 0; cnt < 50; cnt++) { | |
2420 | for (; i < MAX_NUM_VOQS; i++) { | |
2421 | u32 tmp; | |
2422 | ||
2423 | tmp = qed_rd(p_hwfn, p_ptt, | |
2424 | PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 + | |
2425 | i * 0x40); | |
2426 | if (distance[i] > tmp - cons[i]) | |
2427 | break; | |
2428 | } | |
2429 | ||
2430 | if (i == MAX_NUM_VOQS) | |
2431 | break; | |
2432 | ||
2433 | msleep(20); | |
2434 | } | |
2435 | ||
2436 | if (cnt == 50) { | |
2437 | DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n", | |
2438 | p_vf->abs_vf_id, i); | |
2439 | return -EBUSY; | |
2440 | } | |
2441 | ||
2442 | return 0; | |
2443 | } | |
2444 | ||
2445 | static int qed_iov_vf_flr_poll(struct qed_hwfn *p_hwfn, | |
2446 | struct qed_vf_info *p_vf, struct qed_ptt *p_ptt) | |
2447 | { | |
2448 | int rc; | |
2449 | ||
2450 | rc = qed_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt); | |
2451 | if (rc) | |
2452 | return rc; | |
2453 | ||
2454 | rc = qed_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt); | |
2455 | if (rc) | |
2456 | return rc; | |
2457 | ||
2458 | return 0; | |
2459 | } | |
2460 | ||
2461 | static int | |
2462 | qed_iov_execute_vf_flr_cleanup(struct qed_hwfn *p_hwfn, | |
2463 | struct qed_ptt *p_ptt, | |
2464 | u16 rel_vf_id, u32 *ack_vfs) | |
2465 | { | |
2466 | struct qed_vf_info *p_vf; | |
2467 | int rc = 0; | |
2468 | ||
2469 | p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false); | |
2470 | if (!p_vf) | |
2471 | return 0; | |
2472 | ||
2473 | if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] & | |
2474 | (1ULL << (rel_vf_id % 64))) { | |
2475 | u16 vfid = p_vf->abs_vf_id; | |
2476 | ||
2477 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
2478 | "VF[%d] - Handling FLR\n", vfid); | |
2479 | ||
2480 | qed_iov_vf_cleanup(p_hwfn, p_vf); | |
2481 | ||
2482 | /* If VF isn't active, no need for anything but SW */ | |
2483 | if (!p_vf->b_init) | |
2484 | goto cleanup; | |
2485 | ||
2486 | rc = qed_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt); | |
2487 | if (rc) | |
2488 | goto cleanup; | |
2489 | ||
2490 | rc = qed_final_cleanup(p_hwfn, p_ptt, vfid, true); | |
2491 | if (rc) { | |
2492 | DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid); | |
2493 | return rc; | |
2494 | } | |
2495 | ||
2496 | /* VF_STOPPED has to be set only after final cleanup | |
2497 | * but prior to re-enabling the VF. | |
2498 | */ | |
2499 | p_vf->state = VF_STOPPED; | |
2500 | ||
2501 | rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, p_vf); | |
2502 | if (rc) { | |
2503 | DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n", | |
2504 | vfid); | |
2505 | return rc; | |
2506 | } | |
2507 | cleanup: | |
2508 | /* Mark VF for ack and clean pending state */ | |
2509 | if (p_vf->state == VF_RESET) | |
2510 | p_vf->state = VF_STOPPED; | |
2511 | ack_vfs[vfid / 32] |= (1 << (vfid % 32)); | |
2512 | p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &= | |
2513 | ~(1ULL << (rel_vf_id % 64)); | |
2514 | p_hwfn->pf_iov_info->pending_events[rel_vf_id / 64] &= | |
2515 | ~(1ULL << (rel_vf_id % 64)); | |
2516 | } | |
2517 | ||
2518 | return rc; | |
2519 | } | |
2520 | ||
2521 | int qed_iov_vf_flr_cleanup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) | |
2522 | { | |
2523 | u32 ack_vfs[VF_MAX_STATIC / 32]; | |
2524 | int rc = 0; | |
2525 | u16 i; | |
2526 | ||
2527 | memset(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32)); | |
2528 | ||
2529 | /* Since BRB <-> PRS interface can't be tested as part of the flr | |
2530 | * polling due to HW limitations, simply sleep a bit. And since | |
2531 | * there's no need to wait per-vf, do it before looping. | |
2532 | */ | |
2533 | msleep(100); | |
2534 | ||
2535 | for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++) | |
2536 | qed_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs); | |
2537 | ||
2538 | rc = qed_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs); | |
2539 | return rc; | |
2540 | } | |
2541 | ||
2542 | int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *p_disabled_vfs) | |
2543 | { | |
2544 | u16 i, found = 0; | |
2545 | ||
2546 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, "Marking FLR-ed VFs\n"); | |
2547 | for (i = 0; i < (VF_MAX_STATIC / 32); i++) | |
2548 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
2549 | "[%08x,...,%08x]: %08x\n", | |
2550 | i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]); | |
2551 | ||
2552 | if (!p_hwfn->cdev->p_iov_info) { | |
2553 | DP_NOTICE(p_hwfn, "VF flr but no IOV\n"); | |
2554 | return 0; | |
2555 | } | |
2556 | ||
2557 | /* Mark VFs */ | |
2558 | for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++) { | |
2559 | struct qed_vf_info *p_vf; | |
2560 | u8 vfid; | |
2561 | ||
2562 | p_vf = qed_iov_get_vf_info(p_hwfn, i, false); | |
2563 | if (!p_vf) | |
2564 | continue; | |
2565 | ||
2566 | vfid = p_vf->abs_vf_id; | |
2567 | if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) { | |
2568 | u64 *p_flr = p_hwfn->pf_iov_info->pending_flr; | |
2569 | u16 rel_vf_id = p_vf->relative_vf_id; | |
2570 | ||
2571 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
2572 | "VF[%d] [rel %d] got FLR-ed\n", | |
2573 | vfid, rel_vf_id); | |
2574 | ||
2575 | p_vf->state = VF_RESET; | |
2576 | ||
2577 | /* No need to lock here, since pending_flr should | |
2578 | * only change here and before ACKing MFw. Since | |
2579 | * MFW will not trigger an additional attention for | |
2580 | * VF flr until ACKs, we're safe. | |
2581 | */ | |
2582 | p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64); | |
2583 | found = 1; | |
2584 | } | |
2585 | } | |
2586 | ||
2587 | return found; | |
2588 | } | |
2589 | ||
73390ac9 YM |
2590 | static void qed_iov_get_link(struct qed_hwfn *p_hwfn, |
2591 | u16 vfid, | |
2592 | struct qed_mcp_link_params *p_params, | |
2593 | struct qed_mcp_link_state *p_link, | |
2594 | struct qed_mcp_link_capabilities *p_caps) | |
2595 | { | |
2596 | struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn, | |
2597 | vfid, | |
2598 | false); | |
2599 | struct qed_bulletin_content *p_bulletin; | |
2600 | ||
2601 | if (!p_vf) | |
2602 | return; | |
2603 | ||
2604 | p_bulletin = p_vf->bulletin.p_virt; | |
2605 | ||
2606 | if (p_params) | |
2607 | __qed_vf_get_link_params(p_hwfn, p_params, p_bulletin); | |
2608 | if (p_link) | |
2609 | __qed_vf_get_link_state(p_hwfn, p_link, p_bulletin); | |
2610 | if (p_caps) | |
2611 | __qed_vf_get_link_caps(p_hwfn, p_caps, p_bulletin); | |
2612 | } | |
2613 | ||
37bff2b9 YM |
2614 | static void qed_iov_process_mbx_req(struct qed_hwfn *p_hwfn, |
2615 | struct qed_ptt *p_ptt, int vfid) | |
2616 | { | |
2617 | struct qed_iov_vf_mbx *mbx; | |
2618 | struct qed_vf_info *p_vf; | |
2619 | int i; | |
2620 | ||
2621 | p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true); | |
2622 | if (!p_vf) | |
2623 | return; | |
2624 | ||
2625 | mbx = &p_vf->vf_mbx; | |
2626 | ||
2627 | /* qed_iov_process_mbx_request */ | |
2628 | DP_VERBOSE(p_hwfn, | |
2629 | QED_MSG_IOV, | |
2630 | "qed_iov_process_mbx_req vfid %d\n", p_vf->abs_vf_id); | |
2631 | ||
2632 | mbx->first_tlv = mbx->req_virt->first_tlv; | |
2633 | ||
2634 | /* check if tlv type is known */ | |
2635 | if (qed_iov_tlv_supported(mbx->first_tlv.tl.type)) { | |
1408cc1f YM |
2636 | switch (mbx->first_tlv.tl.type) { |
2637 | case CHANNEL_TLV_ACQUIRE: | |
2638 | qed_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf); | |
2639 | break; | |
dacd88d6 YM |
2640 | case CHANNEL_TLV_VPORT_START: |
2641 | qed_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf); | |
2642 | break; | |
2643 | case CHANNEL_TLV_VPORT_TEARDOWN: | |
2644 | qed_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf); | |
2645 | break; | |
2646 | case CHANNEL_TLV_START_RXQ: | |
2647 | qed_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf); | |
2648 | break; | |
2649 | case CHANNEL_TLV_START_TXQ: | |
2650 | qed_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf); | |
2651 | break; | |
2652 | case CHANNEL_TLV_STOP_RXQS: | |
2653 | qed_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf); | |
2654 | break; | |
2655 | case CHANNEL_TLV_STOP_TXQS: | |
2656 | qed_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf); | |
2657 | break; | |
17b235c1 YM |
2658 | case CHANNEL_TLV_UPDATE_RXQ: |
2659 | qed_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf); | |
2660 | break; | |
dacd88d6 YM |
2661 | case CHANNEL_TLV_VPORT_UPDATE: |
2662 | qed_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf); | |
2663 | break; | |
2664 | case CHANNEL_TLV_UCAST_FILTER: | |
2665 | qed_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf); | |
2666 | break; | |
0b55e27d YM |
2667 | case CHANNEL_TLV_CLOSE: |
2668 | qed_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf); | |
2669 | break; | |
2670 | case CHANNEL_TLV_INT_CLEANUP: | |
2671 | qed_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf); | |
2672 | break; | |
2673 | case CHANNEL_TLV_RELEASE: | |
2674 | qed_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf); | |
2675 | break; | |
1408cc1f | 2676 | } |
37bff2b9 YM |
2677 | } else { |
2678 | /* unknown TLV - this may belong to a VF driver from the future | |
2679 | * - a version written after this PF driver was written, which | |
2680 | * supports features unknown as of yet. Too bad since we don't | |
2681 | * support them. Or this may be because someone wrote a crappy | |
2682 | * VF driver and is sending garbage over the channel. | |
2683 | */ | |
2684 | DP_ERR(p_hwfn, | |
2685 | "unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n", | |
2686 | mbx->first_tlv.tl.type, mbx->first_tlv.tl.length); | |
2687 | ||
2688 | for (i = 0; i < 20; i++) { | |
2689 | DP_VERBOSE(p_hwfn, | |
2690 | QED_MSG_IOV, | |
2691 | "%x ", | |
2692 | mbx->req_virt->tlv_buf_size.tlv_buffer[i]); | |
2693 | } | |
2694 | } | |
2695 | } | |
2696 | ||
2697 | void qed_iov_pf_add_pending_events(struct qed_hwfn *p_hwfn, u8 vfid) | |
2698 | { | |
2699 | u64 add_bit = 1ULL << (vfid % 64); | |
2700 | ||
2701 | p_hwfn->pf_iov_info->pending_events[vfid / 64] |= add_bit; | |
2702 | } | |
2703 | ||
2704 | static void qed_iov_pf_get_and_clear_pending_events(struct qed_hwfn *p_hwfn, | |
2705 | u64 *events) | |
2706 | { | |
2707 | u64 *p_pending_events = p_hwfn->pf_iov_info->pending_events; | |
2708 | ||
2709 | memcpy(events, p_pending_events, sizeof(u64) * QED_VF_ARRAY_LENGTH); | |
2710 | memset(p_pending_events, 0, sizeof(u64) * QED_VF_ARRAY_LENGTH); | |
2711 | } | |
2712 | ||
2713 | static int qed_sriov_vfpf_msg(struct qed_hwfn *p_hwfn, | |
2714 | u16 abs_vfid, struct regpair *vf_msg) | |
2715 | { | |
2716 | u8 min = (u8)p_hwfn->cdev->p_iov_info->first_vf_in_pf; | |
2717 | struct qed_vf_info *p_vf; | |
2718 | ||
2719 | if (!qed_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min)) { | |
2720 | DP_VERBOSE(p_hwfn, | |
2721 | QED_MSG_IOV, | |
2722 | "Got a message from VF [abs 0x%08x] that cannot be handled by PF\n", | |
2723 | abs_vfid); | |
2724 | return 0; | |
2725 | } | |
2726 | p_vf = &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min]; | |
2727 | ||
2728 | /* List the physical address of the request so that handler | |
2729 | * could later on copy the message from it. | |
2730 | */ | |
2731 | p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo; | |
2732 | ||
2733 | /* Mark the event and schedule the workqueue */ | |
2734 | qed_iov_pf_add_pending_events(p_hwfn, p_vf->relative_vf_id); | |
2735 | qed_schedule_iov(p_hwfn, QED_IOV_WQ_MSG_FLAG); | |
2736 | ||
2737 | return 0; | |
2738 | } | |
2739 | ||
2740 | int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn, | |
2741 | u8 opcode, __le16 echo, union event_ring_data *data) | |
2742 | { | |
2743 | switch (opcode) { | |
2744 | case COMMON_EVENT_VF_PF_CHANNEL: | |
2745 | return qed_sriov_vfpf_msg(p_hwfn, le16_to_cpu(echo), | |
2746 | &data->vf_pf_channel.msg_addr); | |
2747 | default: | |
2748 | DP_INFO(p_hwfn->cdev, "Unknown sriov eqe event 0x%02x\n", | |
2749 | opcode); | |
2750 | return -EINVAL; | |
2751 | } | |
2752 | } | |
2753 | ||
32a47e72 YM |
2754 | u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id) |
2755 | { | |
2756 | struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info; | |
2757 | u16 i; | |
2758 | ||
2759 | if (!p_iov) | |
2760 | goto out; | |
2761 | ||
2762 | for (i = rel_vf_id; i < p_iov->total_vfs; i++) | |
2763 | if (qed_iov_is_valid_vfid(p_hwfn, rel_vf_id, true)) | |
2764 | return i; | |
2765 | ||
2766 | out: | |
2767 | return MAX_NUM_VFS; | |
2768 | } | |
37bff2b9 YM |
2769 | |
2770 | static int qed_iov_copy_vf_msg(struct qed_hwfn *p_hwfn, struct qed_ptt *ptt, | |
2771 | int vfid) | |
2772 | { | |
2773 | struct qed_dmae_params params; | |
2774 | struct qed_vf_info *vf_info; | |
2775 | ||
2776 | vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true); | |
2777 | if (!vf_info) | |
2778 | return -EINVAL; | |
2779 | ||
2780 | memset(¶ms, 0, sizeof(struct qed_dmae_params)); | |
2781 | params.flags = QED_DMAE_FLAG_VF_SRC | QED_DMAE_FLAG_COMPLETION_DST; | |
2782 | params.src_vfid = vf_info->abs_vf_id; | |
2783 | ||
2784 | if (qed_dmae_host2host(p_hwfn, ptt, | |
2785 | vf_info->vf_mbx.pending_req, | |
2786 | vf_info->vf_mbx.req_phys, | |
2787 | sizeof(union vfpf_tlvs) / 4, ¶ms)) { | |
2788 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, | |
2789 | "Failed to copy message from VF 0x%02x\n", vfid); | |
2790 | ||
2791 | return -EIO; | |
2792 | } | |
2793 | ||
2794 | return 0; | |
2795 | } | |
2796 | ||
eff16960 YM |
2797 | static void qed_iov_bulletin_set_forced_mac(struct qed_hwfn *p_hwfn, |
2798 | u8 *mac, int vfid) | |
2799 | { | |
2800 | struct qed_vf_info *vf_info; | |
2801 | u64 feature; | |
2802 | ||
2803 | vf_info = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true); | |
2804 | if (!vf_info) { | |
2805 | DP_NOTICE(p_hwfn->cdev, | |
2806 | "Can not set forced MAC, invalid vfid [%d]\n", vfid); | |
2807 | return; | |
2808 | } | |
2809 | ||
2810 | feature = 1 << MAC_ADDR_FORCED; | |
2811 | memcpy(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN); | |
2812 | ||
2813 | vf_info->bulletin.p_virt->valid_bitmap |= feature; | |
2814 | /* Forced MAC will disable MAC_ADDR */ | |
2815 | vf_info->bulletin.p_virt->valid_bitmap &= | |
2816 | ~(1 << VFPF_BULLETIN_MAC_ADDR); | |
2817 | ||
2818 | qed_iov_configure_vport_forced(p_hwfn, vf_info, feature); | |
2819 | } | |
2820 | ||
08feecd7 YM |
2821 | void qed_iov_bulletin_set_forced_vlan(struct qed_hwfn *p_hwfn, |
2822 | u16 pvid, int vfid) | |
2823 | { | |
2824 | struct qed_vf_info *vf_info; | |
2825 | u64 feature; | |
2826 | ||
2827 | vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true); | |
2828 | if (!vf_info) { | |
2829 | DP_NOTICE(p_hwfn->cdev, | |
2830 | "Can not set forced MAC, invalid vfid [%d]\n", vfid); | |
2831 | return; | |
2832 | } | |
2833 | ||
2834 | feature = 1 << VLAN_ADDR_FORCED; | |
2835 | vf_info->bulletin.p_virt->pvid = pvid; | |
2836 | if (pvid) | |
2837 | vf_info->bulletin.p_virt->valid_bitmap |= feature; | |
2838 | else | |
2839 | vf_info->bulletin.p_virt->valid_bitmap &= ~feature; | |
2840 | ||
2841 | qed_iov_configure_vport_forced(p_hwfn, vf_info, feature); | |
2842 | } | |
2843 | ||
6ddc7608 YM |
2844 | static bool qed_iov_vf_has_vport_instance(struct qed_hwfn *p_hwfn, int vfid) |
2845 | { | |
2846 | struct qed_vf_info *p_vf_info; | |
2847 | ||
2848 | p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true); | |
2849 | if (!p_vf_info) | |
2850 | return false; | |
2851 | ||
2852 | return !!p_vf_info->vport_instance; | |
2853 | } | |
2854 | ||
0b55e27d YM |
2855 | bool qed_iov_is_vf_stopped(struct qed_hwfn *p_hwfn, int vfid) |
2856 | { | |
2857 | struct qed_vf_info *p_vf_info; | |
2858 | ||
2859 | p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true); | |
2860 | if (!p_vf_info) | |
2861 | return true; | |
2862 | ||
2863 | return p_vf_info->state == VF_STOPPED; | |
2864 | } | |
2865 | ||
73390ac9 YM |
2866 | static bool qed_iov_spoofchk_get(struct qed_hwfn *p_hwfn, int vfid) |
2867 | { | |
2868 | struct qed_vf_info *vf_info; | |
2869 | ||
2870 | vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true); | |
2871 | if (!vf_info) | |
2872 | return false; | |
2873 | ||
2874 | return vf_info->spoof_chk; | |
2875 | } | |
2876 | ||
6ddc7608 YM |
2877 | int qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn, int vfid, bool val) |
2878 | { | |
2879 | struct qed_vf_info *vf; | |
2880 | int rc = -EINVAL; | |
2881 | ||
2882 | if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) { | |
2883 | DP_NOTICE(p_hwfn, | |
2884 | "SR-IOV sanity check failed, can't set spoofchk\n"); | |
2885 | goto out; | |
2886 | } | |
2887 | ||
2888 | vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true); | |
2889 | if (!vf) | |
2890 | goto out; | |
2891 | ||
2892 | if (!qed_iov_vf_has_vport_instance(p_hwfn, vfid)) { | |
2893 | /* After VF VPORT start PF will configure spoof check */ | |
2894 | vf->req_spoofchk_val = val; | |
2895 | rc = 0; | |
2896 | goto out; | |
2897 | } | |
2898 | ||
2899 | rc = __qed_iov_spoofchk_set(p_hwfn, vf, val); | |
2900 | ||
2901 | out: | |
2902 | return rc; | |
2903 | } | |
2904 | ||
eff16960 YM |
2905 | static u8 *qed_iov_bulletin_get_forced_mac(struct qed_hwfn *p_hwfn, |
2906 | u16 rel_vf_id) | |
2907 | { | |
2908 | struct qed_vf_info *p_vf; | |
2909 | ||
2910 | p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true); | |
2911 | if (!p_vf || !p_vf->bulletin.p_virt) | |
2912 | return NULL; | |
2913 | ||
2914 | if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))) | |
2915 | return NULL; | |
2916 | ||
2917 | return p_vf->bulletin.p_virt->mac; | |
2918 | } | |
2919 | ||
08feecd7 YM |
2920 | u16 qed_iov_bulletin_get_forced_vlan(struct qed_hwfn *p_hwfn, u16 rel_vf_id) |
2921 | { | |
2922 | struct qed_vf_info *p_vf; | |
2923 | ||
2924 | p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true); | |
2925 | if (!p_vf || !p_vf->bulletin.p_virt) | |
2926 | return 0; | |
2927 | ||
2928 | if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))) | |
2929 | return 0; | |
2930 | ||
2931 | return p_vf->bulletin.p_virt->pvid; | |
2932 | } | |
2933 | ||
733def6a YM |
2934 | static int qed_iov_configure_tx_rate(struct qed_hwfn *p_hwfn, |
2935 | struct qed_ptt *p_ptt, int vfid, int val) | |
2936 | { | |
2937 | struct qed_vf_info *vf; | |
2938 | u8 abs_vp_id = 0; | |
2939 | int rc; | |
2940 | ||
2941 | vf = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true); | |
2942 | if (!vf) | |
2943 | return -EINVAL; | |
2944 | ||
2945 | rc = qed_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id); | |
2946 | if (rc) | |
2947 | return rc; | |
2948 | ||
2949 | return qed_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val); | |
2950 | } | |
2951 | ||
2952 | int qed_iov_configure_min_tx_rate(struct qed_dev *cdev, int vfid, u32 rate) | |
2953 | { | |
2954 | struct qed_vf_info *vf; | |
2955 | u8 vport_id; | |
2956 | int i; | |
2957 | ||
2958 | for_each_hwfn(cdev, i) { | |
2959 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; | |
2960 | ||
2961 | if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) { | |
2962 | DP_NOTICE(p_hwfn, | |
2963 | "SR-IOV sanity check failed, can't set min rate\n"); | |
2964 | return -EINVAL; | |
2965 | } | |
2966 | } | |
2967 | ||
2968 | vf = qed_iov_get_vf_info(QED_LEADING_HWFN(cdev), (u16)vfid, true); | |
2969 | vport_id = vf->vport_id; | |
2970 | ||
2971 | return qed_configure_vport_wfq(cdev, vport_id, rate); | |
2972 | } | |
2973 | ||
73390ac9 YM |
2974 | static int qed_iov_get_vf_min_rate(struct qed_hwfn *p_hwfn, int vfid) |
2975 | { | |
2976 | struct qed_wfq_data *vf_vp_wfq; | |
2977 | struct qed_vf_info *vf_info; | |
2978 | ||
2979 | vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true); | |
2980 | if (!vf_info) | |
2981 | return 0; | |
2982 | ||
2983 | vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id]; | |
2984 | ||
2985 | if (vf_vp_wfq->configured) | |
2986 | return vf_vp_wfq->min_speed; | |
2987 | else | |
2988 | return 0; | |
2989 | } | |
2990 | ||
37bff2b9 YM |
2991 | /** |
2992 | * qed_schedule_iov - schedules IOV task for VF and PF | |
2993 | * @hwfn: hardware function pointer | |
2994 | * @flag: IOV flag for VF/PF | |
2995 | */ | |
2996 | void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag) | |
2997 | { | |
2998 | smp_mb__before_atomic(); | |
2999 | set_bit(flag, &hwfn->iov_task_flags); | |
3000 | smp_mb__after_atomic(); | |
3001 | DP_VERBOSE(hwfn, QED_MSG_IOV, "Scheduling iov task [Flag: %d]\n", flag); | |
3002 | queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, 0); | |
3003 | } | |
3004 | ||
1408cc1f YM |
3005 | void qed_vf_start_iov_wq(struct qed_dev *cdev) |
3006 | { | |
3007 | int i; | |
3008 | ||
3009 | for_each_hwfn(cdev, i) | |
3010 | queue_delayed_work(cdev->hwfns[i].iov_wq, | |
3011 | &cdev->hwfns[i].iov_task, 0); | |
3012 | } | |
3013 | ||
0b55e27d YM |
3014 | int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled) |
3015 | { | |
3016 | int i, j; | |
3017 | ||
3018 | for_each_hwfn(cdev, i) | |
3019 | if (cdev->hwfns[i].iov_wq) | |
3020 | flush_workqueue(cdev->hwfns[i].iov_wq); | |
3021 | ||
3022 | /* Mark VFs for disablement */ | |
3023 | qed_iov_set_vfs_to_disable(cdev, true); | |
3024 | ||
3025 | if (cdev->p_iov_info && cdev->p_iov_info->num_vfs && pci_enabled) | |
3026 | pci_disable_sriov(cdev->pdev); | |
3027 | ||
3028 | for_each_hwfn(cdev, i) { | |
3029 | struct qed_hwfn *hwfn = &cdev->hwfns[i]; | |
3030 | struct qed_ptt *ptt = qed_ptt_acquire(hwfn); | |
3031 | ||
3032 | /* Failure to acquire the ptt in 100g creates an odd error | |
3033 | * where the first engine has already relased IOV. | |
3034 | */ | |
3035 | if (!ptt) { | |
3036 | DP_ERR(hwfn, "Failed to acquire ptt\n"); | |
3037 | return -EBUSY; | |
3038 | } | |
3039 | ||
733def6a YM |
3040 | /* Clean WFQ db and configure equal weight for all vports */ |
3041 | qed_clean_wfq_db(hwfn, ptt); | |
3042 | ||
0b55e27d YM |
3043 | qed_for_each_vf(hwfn, j) { |
3044 | int k; | |
3045 | ||
3046 | if (!qed_iov_is_valid_vfid(hwfn, j, true)) | |
3047 | continue; | |
3048 | ||
3049 | /* Wait until VF is disabled before releasing */ | |
3050 | for (k = 0; k < 100; k++) { | |
3051 | if (!qed_iov_is_vf_stopped(hwfn, j)) | |
3052 | msleep(20); | |
3053 | else | |
3054 | break; | |
3055 | } | |
3056 | ||
3057 | if (k < 100) | |
3058 | qed_iov_release_hw_for_vf(&cdev->hwfns[i], | |
3059 | ptt, j); | |
3060 | else | |
3061 | DP_ERR(hwfn, | |
3062 | "Timeout waiting for VF's FLR to end\n"); | |
3063 | } | |
3064 | ||
3065 | qed_ptt_release(hwfn, ptt); | |
3066 | } | |
3067 | ||
3068 | qed_iov_set_vfs_to_disable(cdev, false); | |
3069 | ||
3070 | return 0; | |
3071 | } | |
3072 | ||
3073 | static int qed_sriov_enable(struct qed_dev *cdev, int num) | |
3074 | { | |
3075 | struct qed_sb_cnt_info sb_cnt_info; | |
3076 | int i, j, rc; | |
3077 | ||
3078 | if (num >= RESC_NUM(&cdev->hwfns[0], QED_VPORT)) { | |
3079 | DP_NOTICE(cdev, "Can start at most %d VFs\n", | |
3080 | RESC_NUM(&cdev->hwfns[0], QED_VPORT) - 1); | |
3081 | return -EINVAL; | |
3082 | } | |
3083 | ||
3084 | /* Initialize HW for VF access */ | |
3085 | for_each_hwfn(cdev, j) { | |
3086 | struct qed_hwfn *hwfn = &cdev->hwfns[j]; | |
3087 | struct qed_ptt *ptt = qed_ptt_acquire(hwfn); | |
3088 | int num_sbs = 0, limit = 16; | |
3089 | ||
3090 | if (!ptt) { | |
3091 | DP_ERR(hwfn, "Failed to acquire ptt\n"); | |
3092 | rc = -EBUSY; | |
3093 | goto err; | |
3094 | } | |
3095 | ||
83f34bd4 YM |
3096 | if (IS_MF_DEFAULT(hwfn)) |
3097 | limit = MAX_NUM_VFS_BB / hwfn->num_funcs_on_engine; | |
3098 | ||
0b55e27d YM |
3099 | memset(&sb_cnt_info, 0, sizeof(sb_cnt_info)); |
3100 | qed_int_get_num_sbs(hwfn, &sb_cnt_info); | |
3101 | num_sbs = min_t(int, sb_cnt_info.sb_free_blk, limit); | |
3102 | ||
3103 | for (i = 0; i < num; i++) { | |
3104 | if (!qed_iov_is_valid_vfid(hwfn, i, false)) | |
3105 | continue; | |
3106 | ||
3107 | rc = qed_iov_init_hw_for_vf(hwfn, | |
3108 | ptt, i, num_sbs / num); | |
3109 | if (rc) { | |
3110 | DP_ERR(cdev, "Failed to enable VF[%d]\n", i); | |
3111 | qed_ptt_release(hwfn, ptt); | |
3112 | goto err; | |
3113 | } | |
3114 | } | |
3115 | ||
3116 | qed_ptt_release(hwfn, ptt); | |
3117 | } | |
3118 | ||
3119 | /* Enable SRIOV PCIe functions */ | |
3120 | rc = pci_enable_sriov(cdev->pdev, num); | |
3121 | if (rc) { | |
3122 | DP_ERR(cdev, "Failed to enable sriov [%d]\n", rc); | |
3123 | goto err; | |
3124 | } | |
3125 | ||
3126 | return num; | |
3127 | ||
3128 | err: | |
3129 | qed_sriov_disable(cdev, false); | |
3130 | return rc; | |
3131 | } | |
3132 | ||
3133 | static int qed_sriov_configure(struct qed_dev *cdev, int num_vfs_param) | |
3134 | { | |
3135 | if (!IS_QED_SRIOV(cdev)) { | |
3136 | DP_VERBOSE(cdev, QED_MSG_IOV, "SR-IOV is not supported\n"); | |
3137 | return -EOPNOTSUPP; | |
3138 | } | |
3139 | ||
3140 | if (num_vfs_param) | |
3141 | return qed_sriov_enable(cdev, num_vfs_param); | |
3142 | else | |
3143 | return qed_sriov_disable(cdev, true); | |
3144 | } | |
3145 | ||
eff16960 YM |
3146 | static int qed_sriov_pf_set_mac(struct qed_dev *cdev, u8 *mac, int vfid) |
3147 | { | |
3148 | int i; | |
3149 | ||
3150 | if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) { | |
3151 | DP_VERBOSE(cdev, QED_MSG_IOV, | |
3152 | "Cannot set a VF MAC; Sriov is not enabled\n"); | |
3153 | return -EINVAL; | |
3154 | } | |
3155 | ||
3156 | if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true)) { | |
3157 | DP_VERBOSE(cdev, QED_MSG_IOV, | |
3158 | "Cannot set VF[%d] MAC (VF is not active)\n", vfid); | |
3159 | return -EINVAL; | |
3160 | } | |
3161 | ||
3162 | for_each_hwfn(cdev, i) { | |
3163 | struct qed_hwfn *hwfn = &cdev->hwfns[i]; | |
3164 | struct qed_public_vf_info *vf_info; | |
3165 | ||
3166 | vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true); | |
3167 | if (!vf_info) | |
3168 | continue; | |
3169 | ||
3170 | /* Set the forced MAC, and schedule the IOV task */ | |
3171 | ether_addr_copy(vf_info->forced_mac, mac); | |
3172 | qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG); | |
3173 | } | |
3174 | ||
3175 | return 0; | |
3176 | } | |
3177 | ||
08feecd7 YM |
3178 | static int qed_sriov_pf_set_vlan(struct qed_dev *cdev, u16 vid, int vfid) |
3179 | { | |
3180 | int i; | |
3181 | ||
3182 | if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) { | |
3183 | DP_VERBOSE(cdev, QED_MSG_IOV, | |
3184 | "Cannot set a VF MAC; Sriov is not enabled\n"); | |
3185 | return -EINVAL; | |
3186 | } | |
3187 | ||
3188 | if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true)) { | |
3189 | DP_VERBOSE(cdev, QED_MSG_IOV, | |
3190 | "Cannot set VF[%d] MAC (VF is not active)\n", vfid); | |
3191 | return -EINVAL; | |
3192 | } | |
3193 | ||
3194 | for_each_hwfn(cdev, i) { | |
3195 | struct qed_hwfn *hwfn = &cdev->hwfns[i]; | |
3196 | struct qed_public_vf_info *vf_info; | |
3197 | ||
3198 | vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true); | |
3199 | if (!vf_info) | |
3200 | continue; | |
3201 | ||
3202 | /* Set the forced vlan, and schedule the IOV task */ | |
3203 | vf_info->forced_vlan = vid; | |
3204 | qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG); | |
3205 | } | |
3206 | ||
3207 | return 0; | |
3208 | } | |
3209 | ||
73390ac9 YM |
3210 | static int qed_get_vf_config(struct qed_dev *cdev, |
3211 | int vf_id, struct ifla_vf_info *ivi) | |
3212 | { | |
3213 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); | |
3214 | struct qed_public_vf_info *vf_info; | |
3215 | struct qed_mcp_link_state link; | |
3216 | u32 tx_rate; | |
3217 | ||
3218 | /* Sanitize request */ | |
3219 | if (IS_VF(cdev)) | |
3220 | return -EINVAL; | |
3221 | ||
3222 | if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true)) { | |
3223 | DP_VERBOSE(cdev, QED_MSG_IOV, | |
3224 | "VF index [%d] isn't active\n", vf_id); | |
3225 | return -EINVAL; | |
3226 | } | |
3227 | ||
3228 | vf_info = qed_iov_get_public_vf_info(hwfn, vf_id, true); | |
3229 | ||
3230 | qed_iov_get_link(hwfn, vf_id, NULL, &link, NULL); | |
3231 | ||
3232 | /* Fill information about VF */ | |
3233 | ivi->vf = vf_id; | |
3234 | ||
3235 | if (is_valid_ether_addr(vf_info->forced_mac)) | |
3236 | ether_addr_copy(ivi->mac, vf_info->forced_mac); | |
3237 | else | |
3238 | ether_addr_copy(ivi->mac, vf_info->mac); | |
3239 | ||
3240 | ivi->vlan = vf_info->forced_vlan; | |
3241 | ivi->spoofchk = qed_iov_spoofchk_get(hwfn, vf_id); | |
3242 | ivi->linkstate = vf_info->link_state; | |
3243 | tx_rate = vf_info->tx_rate; | |
3244 | ivi->max_tx_rate = tx_rate ? tx_rate : link.speed; | |
3245 | ivi->min_tx_rate = qed_iov_get_vf_min_rate(hwfn, vf_id); | |
3246 | ||
3247 | return 0; | |
3248 | } | |
3249 | ||
36558c3d YM |
3250 | void qed_inform_vf_link_state(struct qed_hwfn *hwfn) |
3251 | { | |
3252 | struct qed_mcp_link_capabilities caps; | |
3253 | struct qed_mcp_link_params params; | |
3254 | struct qed_mcp_link_state link; | |
3255 | int i; | |
3256 | ||
3257 | if (!hwfn->pf_iov_info) | |
3258 | return; | |
3259 | ||
3260 | /* Update bulletin of all future possible VFs with link configuration */ | |
3261 | for (i = 0; i < hwfn->cdev->p_iov_info->total_vfs; i++) { | |
733def6a YM |
3262 | struct qed_public_vf_info *vf_info; |
3263 | ||
3264 | vf_info = qed_iov_get_public_vf_info(hwfn, i, false); | |
3265 | if (!vf_info) | |
3266 | continue; | |
3267 | ||
36558c3d YM |
3268 | memcpy(¶ms, qed_mcp_get_link_params(hwfn), sizeof(params)); |
3269 | memcpy(&link, qed_mcp_get_link_state(hwfn), sizeof(link)); | |
3270 | memcpy(&caps, qed_mcp_get_link_capabilities(hwfn), | |
3271 | sizeof(caps)); | |
3272 | ||
733def6a YM |
3273 | /* Modify link according to the VF's configured link state */ |
3274 | switch (vf_info->link_state) { | |
3275 | case IFLA_VF_LINK_STATE_DISABLE: | |
3276 | link.link_up = false; | |
3277 | break; | |
3278 | case IFLA_VF_LINK_STATE_ENABLE: | |
3279 | link.link_up = true; | |
3280 | /* Set speed according to maximum supported by HW. | |
3281 | * that is 40G for regular devices and 100G for CMT | |
3282 | * mode devices. | |
3283 | */ | |
3284 | link.speed = (hwfn->cdev->num_hwfns > 1) ? | |
3285 | 100000 : 40000; | |
3286 | default: | |
3287 | /* In auto mode pass PF link image to VF */ | |
3288 | break; | |
3289 | } | |
3290 | ||
3291 | if (link.link_up && vf_info->tx_rate) { | |
3292 | struct qed_ptt *ptt; | |
3293 | int rate; | |
3294 | ||
3295 | rate = min_t(int, vf_info->tx_rate, link.speed); | |
3296 | ||
3297 | ptt = qed_ptt_acquire(hwfn); | |
3298 | if (!ptt) { | |
3299 | DP_NOTICE(hwfn, "Failed to acquire PTT\n"); | |
3300 | return; | |
3301 | } | |
3302 | ||
3303 | if (!qed_iov_configure_tx_rate(hwfn, ptt, i, rate)) { | |
3304 | vf_info->tx_rate = rate; | |
3305 | link.speed = rate; | |
3306 | } | |
3307 | ||
3308 | qed_ptt_release(hwfn, ptt); | |
3309 | } | |
3310 | ||
36558c3d YM |
3311 | qed_iov_set_link(hwfn, i, ¶ms, &link, &caps); |
3312 | } | |
3313 | ||
3314 | qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG); | |
3315 | } | |
3316 | ||
733def6a YM |
3317 | static int qed_set_vf_link_state(struct qed_dev *cdev, |
3318 | int vf_id, int link_state) | |
3319 | { | |
3320 | int i; | |
3321 | ||
3322 | /* Sanitize request */ | |
3323 | if (IS_VF(cdev)) | |
3324 | return -EINVAL; | |
3325 | ||
3326 | if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true)) { | |
3327 | DP_VERBOSE(cdev, QED_MSG_IOV, | |
3328 | "VF index [%d] isn't active\n", vf_id); | |
3329 | return -EINVAL; | |
3330 | } | |
3331 | ||
3332 | /* Handle configuration of link state */ | |
3333 | for_each_hwfn(cdev, i) { | |
3334 | struct qed_hwfn *hwfn = &cdev->hwfns[i]; | |
3335 | struct qed_public_vf_info *vf; | |
3336 | ||
3337 | vf = qed_iov_get_public_vf_info(hwfn, vf_id, true); | |
3338 | if (!vf) | |
3339 | continue; | |
3340 | ||
3341 | if (vf->link_state == link_state) | |
3342 | continue; | |
3343 | ||
3344 | vf->link_state = link_state; | |
3345 | qed_inform_vf_link_state(&cdev->hwfns[i]); | |
3346 | } | |
3347 | ||
3348 | return 0; | |
3349 | } | |
3350 | ||
6ddc7608 YM |
3351 | static int qed_spoof_configure(struct qed_dev *cdev, int vfid, bool val) |
3352 | { | |
3353 | int i, rc = -EINVAL; | |
3354 | ||
3355 | for_each_hwfn(cdev, i) { | |
3356 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; | |
3357 | ||
3358 | rc = qed_iov_spoofchk_set(p_hwfn, vfid, val); | |
3359 | if (rc) | |
3360 | break; | |
3361 | } | |
3362 | ||
3363 | return rc; | |
3364 | } | |
3365 | ||
733def6a YM |
3366 | static int qed_configure_max_vf_rate(struct qed_dev *cdev, int vfid, int rate) |
3367 | { | |
3368 | int i; | |
3369 | ||
3370 | for_each_hwfn(cdev, i) { | |
3371 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; | |
3372 | struct qed_public_vf_info *vf; | |
3373 | ||
3374 | if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) { | |
3375 | DP_NOTICE(p_hwfn, | |
3376 | "SR-IOV sanity check failed, can't set tx rate\n"); | |
3377 | return -EINVAL; | |
3378 | } | |
3379 | ||
3380 | vf = qed_iov_get_public_vf_info(p_hwfn, vfid, true); | |
3381 | ||
3382 | vf->tx_rate = rate; | |
3383 | ||
3384 | qed_inform_vf_link_state(p_hwfn); | |
3385 | } | |
3386 | ||
3387 | return 0; | |
3388 | } | |
3389 | ||
3390 | static int qed_set_vf_rate(struct qed_dev *cdev, | |
3391 | int vfid, u32 min_rate, u32 max_rate) | |
3392 | { | |
3393 | int rc_min = 0, rc_max = 0; | |
3394 | ||
3395 | if (max_rate) | |
3396 | rc_max = qed_configure_max_vf_rate(cdev, vfid, max_rate); | |
3397 | ||
3398 | if (min_rate) | |
3399 | rc_min = qed_iov_configure_min_tx_rate(cdev, vfid, min_rate); | |
3400 | ||
3401 | if (rc_max | rc_min) | |
3402 | return -EINVAL; | |
3403 | ||
3404 | return 0; | |
3405 | } | |
3406 | ||
37bff2b9 YM |
3407 | static void qed_handle_vf_msg(struct qed_hwfn *hwfn) |
3408 | { | |
3409 | u64 events[QED_VF_ARRAY_LENGTH]; | |
3410 | struct qed_ptt *ptt; | |
3411 | int i; | |
3412 | ||
3413 | ptt = qed_ptt_acquire(hwfn); | |
3414 | if (!ptt) { | |
3415 | DP_VERBOSE(hwfn, QED_MSG_IOV, | |
3416 | "Can't acquire PTT; re-scheduling\n"); | |
3417 | qed_schedule_iov(hwfn, QED_IOV_WQ_MSG_FLAG); | |
3418 | return; | |
3419 | } | |
3420 | ||
3421 | qed_iov_pf_get_and_clear_pending_events(hwfn, events); | |
3422 | ||
3423 | DP_VERBOSE(hwfn, QED_MSG_IOV, | |
3424 | "Event mask of VF events: 0x%llx 0x%llx 0x%llx\n", | |
3425 | events[0], events[1], events[2]); | |
3426 | ||
3427 | qed_for_each_vf(hwfn, i) { | |
3428 | /* Skip VFs with no pending messages */ | |
3429 | if (!(events[i / 64] & (1ULL << (i % 64)))) | |
3430 | continue; | |
3431 | ||
3432 | DP_VERBOSE(hwfn, QED_MSG_IOV, | |
3433 | "Handling VF message from VF 0x%02x [Abs 0x%02x]\n", | |
3434 | i, hwfn->cdev->p_iov_info->first_vf_in_pf + i); | |
3435 | ||
3436 | /* Copy VF's message to PF's request buffer for that VF */ | |
3437 | if (qed_iov_copy_vf_msg(hwfn, ptt, i)) | |
3438 | continue; | |
3439 | ||
3440 | qed_iov_process_mbx_req(hwfn, ptt, i); | |
3441 | } | |
3442 | ||
3443 | qed_ptt_release(hwfn, ptt); | |
3444 | } | |
3445 | ||
08feecd7 YM |
3446 | static void qed_handle_pf_set_vf_unicast(struct qed_hwfn *hwfn) |
3447 | { | |
3448 | int i; | |
3449 | ||
3450 | qed_for_each_vf(hwfn, i) { | |
3451 | struct qed_public_vf_info *info; | |
3452 | bool update = false; | |
eff16960 | 3453 | u8 *mac; |
08feecd7 YM |
3454 | |
3455 | info = qed_iov_get_public_vf_info(hwfn, i, true); | |
3456 | if (!info) | |
3457 | continue; | |
3458 | ||
3459 | /* Update data on bulletin board */ | |
eff16960 YM |
3460 | mac = qed_iov_bulletin_get_forced_mac(hwfn, i); |
3461 | if (is_valid_ether_addr(info->forced_mac) && | |
3462 | (!mac || !ether_addr_equal(mac, info->forced_mac))) { | |
3463 | DP_VERBOSE(hwfn, | |
3464 | QED_MSG_IOV, | |
3465 | "Handling PF setting of VF MAC to VF 0x%02x [Abs 0x%02x]\n", | |
3466 | i, | |
3467 | hwfn->cdev->p_iov_info->first_vf_in_pf + i); | |
3468 | ||
3469 | /* Update bulletin board with forced MAC */ | |
3470 | qed_iov_bulletin_set_forced_mac(hwfn, | |
3471 | info->forced_mac, i); | |
3472 | update = true; | |
3473 | } | |
08feecd7 YM |
3474 | |
3475 | if (qed_iov_bulletin_get_forced_vlan(hwfn, i) ^ | |
3476 | info->forced_vlan) { | |
3477 | DP_VERBOSE(hwfn, | |
3478 | QED_MSG_IOV, | |
3479 | "Handling PF setting of pvid [0x%04x] to VF 0x%02x [Abs 0x%02x]\n", | |
3480 | info->forced_vlan, | |
3481 | i, | |
3482 | hwfn->cdev->p_iov_info->first_vf_in_pf + i); | |
3483 | qed_iov_bulletin_set_forced_vlan(hwfn, | |
3484 | info->forced_vlan, i); | |
3485 | update = true; | |
3486 | } | |
3487 | ||
3488 | if (update) | |
3489 | qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG); | |
3490 | } | |
3491 | } | |
3492 | ||
36558c3d YM |
3493 | static void qed_handle_bulletin_post(struct qed_hwfn *hwfn) |
3494 | { | |
3495 | struct qed_ptt *ptt; | |
3496 | int i; | |
3497 | ||
3498 | ptt = qed_ptt_acquire(hwfn); | |
3499 | if (!ptt) { | |
3500 | DP_NOTICE(hwfn, "Failed allocating a ptt entry\n"); | |
3501 | qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG); | |
3502 | return; | |
3503 | } | |
3504 | ||
3505 | qed_for_each_vf(hwfn, i) | |
3506 | qed_iov_post_vf_bulletin(hwfn, i, ptt); | |
3507 | ||
3508 | qed_ptt_release(hwfn, ptt); | |
3509 | } | |
3510 | ||
37bff2b9 YM |
3511 | void qed_iov_pf_task(struct work_struct *work) |
3512 | { | |
3513 | struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn, | |
3514 | iov_task.work); | |
0b55e27d | 3515 | int rc; |
37bff2b9 YM |
3516 | |
3517 | if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags)) | |
3518 | return; | |
3519 | ||
0b55e27d YM |
3520 | if (test_and_clear_bit(QED_IOV_WQ_FLR_FLAG, &hwfn->iov_task_flags)) { |
3521 | struct qed_ptt *ptt = qed_ptt_acquire(hwfn); | |
3522 | ||
3523 | if (!ptt) { | |
3524 | qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG); | |
3525 | return; | |
3526 | } | |
3527 | ||
3528 | rc = qed_iov_vf_flr_cleanup(hwfn, ptt); | |
3529 | if (rc) | |
3530 | qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG); | |
3531 | ||
3532 | qed_ptt_release(hwfn, ptt); | |
3533 | } | |
3534 | ||
37bff2b9 YM |
3535 | if (test_and_clear_bit(QED_IOV_WQ_MSG_FLAG, &hwfn->iov_task_flags)) |
3536 | qed_handle_vf_msg(hwfn); | |
08feecd7 YM |
3537 | |
3538 | if (test_and_clear_bit(QED_IOV_WQ_SET_UNICAST_FILTER_FLAG, | |
3539 | &hwfn->iov_task_flags)) | |
3540 | qed_handle_pf_set_vf_unicast(hwfn); | |
3541 | ||
36558c3d YM |
3542 | if (test_and_clear_bit(QED_IOV_WQ_BULLETIN_UPDATE_FLAG, |
3543 | &hwfn->iov_task_flags)) | |
3544 | qed_handle_bulletin_post(hwfn); | |
37bff2b9 YM |
3545 | } |
3546 | ||
3547 | void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first) | |
3548 | { | |
3549 | int i; | |
3550 | ||
3551 | for_each_hwfn(cdev, i) { | |
3552 | if (!cdev->hwfns[i].iov_wq) | |
3553 | continue; | |
3554 | ||
3555 | if (schedule_first) { | |
3556 | qed_schedule_iov(&cdev->hwfns[i], | |
3557 | QED_IOV_WQ_STOP_WQ_FLAG); | |
3558 | cancel_delayed_work_sync(&cdev->hwfns[i].iov_task); | |
3559 | } | |
3560 | ||
3561 | flush_workqueue(cdev->hwfns[i].iov_wq); | |
3562 | destroy_workqueue(cdev->hwfns[i].iov_wq); | |
3563 | } | |
3564 | } | |
3565 | ||
3566 | int qed_iov_wq_start(struct qed_dev *cdev) | |
3567 | { | |
3568 | char name[NAME_SIZE]; | |
3569 | int i; | |
3570 | ||
3571 | for_each_hwfn(cdev, i) { | |
3572 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; | |
3573 | ||
36558c3d YM |
3574 | /* PFs needs a dedicated workqueue only if they support IOV. |
3575 | * VFs always require one. | |
3576 | */ | |
3577 | if (IS_PF(p_hwfn->cdev) && !IS_PF_SRIOV(p_hwfn)) | |
37bff2b9 YM |
3578 | continue; |
3579 | ||
3580 | snprintf(name, NAME_SIZE, "iov-%02x:%02x.%02x", | |
3581 | cdev->pdev->bus->number, | |
3582 | PCI_SLOT(cdev->pdev->devfn), p_hwfn->abs_pf_id); | |
3583 | ||
3584 | p_hwfn->iov_wq = create_singlethread_workqueue(name); | |
3585 | if (!p_hwfn->iov_wq) { | |
3586 | DP_NOTICE(p_hwfn, "Cannot create iov workqueue\n"); | |
3587 | return -ENOMEM; | |
3588 | } | |
3589 | ||
36558c3d YM |
3590 | if (IS_PF(cdev)) |
3591 | INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_pf_task); | |
3592 | else | |
3593 | INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_vf_task); | |
37bff2b9 YM |
3594 | } |
3595 | ||
3596 | return 0; | |
3597 | } | |
0b55e27d YM |
3598 | |
3599 | const struct qed_iov_hv_ops qed_iov_ops_pass = { | |
3600 | .configure = &qed_sriov_configure, | |
eff16960 | 3601 | .set_mac = &qed_sriov_pf_set_mac, |
08feecd7 | 3602 | .set_vlan = &qed_sriov_pf_set_vlan, |
73390ac9 | 3603 | .get_config = &qed_get_vf_config, |
733def6a | 3604 | .set_link_state = &qed_set_vf_link_state, |
6ddc7608 | 3605 | .set_spoof = &qed_spoof_configure, |
733def6a | 3606 | .set_rate = &qed_set_vf_rate, |
0b55e27d | 3607 | }; |