1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <linux/crc32.h>
34#include <linux/etherdevice.h>
35#include "qed.h"
36#include "qed_sriov.h"
37#include "qed_vf.h"
38
39static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length)
40{
41 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
42 void *p_tlv;
43
44
45
46
47
48
49 mutex_lock(&(p_iov->mutex));
50
51 DP_VERBOSE(p_hwfn,
52 QED_MSG_IOV,
53 "preparing to send 0x%04x tlv over vf pf channel\n",
54 type);
55
56
57 p_iov->offset = (u8 *)p_iov->vf2pf_request;
58
59
60 memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
61 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
62
63
64 p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length);
65
66
67 ((struct vfpf_first_tlv *)p_tlv)->reply_address =
68 (u64)p_iov->pf2vf_reply_phys;
69
70 return p_tlv;
71}
72
73static void qed_vf_pf_req_end(struct qed_hwfn *p_hwfn, int req_status)
74{
75 union pfvf_tlvs *resp = p_hwfn->vf_iov_info->pf2vf_reply;
76
77 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
78 "VF request status = 0x%x, PF reply status = 0x%x\n",
79 req_status, resp->default_resp.hdr.status);
80
81 mutex_unlock(&(p_hwfn->vf_iov_info->mutex));
82}
83
84static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size)
85{
86 union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
87 struct ustorm_trigger_vf_zone trigger;
88 struct ustorm_vf_zone *zone_data;
89 int rc = 0, time = 100;
90
91 zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
92
93
94 qed_dp_tlv_list(p_hwfn, p_req);
95
96
97 resp_size += sizeof(struct channel_list_end_tlv);
98
99
100 memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
101 trigger.vf_pf_msg_valid = 1;
102
103 DP_VERBOSE(p_hwfn,
104 QED_MSG_IOV,
105 "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n",
106 GET_FIELD(p_hwfn->hw_info.concrete_fid,
107 PXP_CONCRETE_FID_PFID),
108 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
109 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
110 &zone_data->non_trigger.vf_pf_msg_addr,
111 *((u32 *)&trigger), &zone_data->trigger);
112
113 REG_WR(p_hwfn,
114 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
115 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
116
117 REG_WR(p_hwfn,
118 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
119 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
120
121
122
123
124 wmb();
125
126 REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger));
127
128
129
130
131 while ((!*done) && time) {
132 msleep(25);
133 time--;
134 }
135
136 if (!*done) {
137 DP_NOTICE(p_hwfn,
138 "VF <-- PF Timeout [Type %d]\n",
139 p_req->first_tlv.tl.type);
140 rc = -EBUSY;
141 } else {
142 if ((*done != PFVF_STATUS_SUCCESS) &&
143 (*done != PFVF_STATUS_NO_RESOURCE))
144 DP_NOTICE(p_hwfn,
145 "PF response: %d [Type %d]\n",
146 *done, p_req->first_tlv.tl.type);
147 else
148 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
149 "PF response: %d [Type %d]\n",
150 *done, p_req->first_tlv.tl.type);
151 }
152
153 return rc;
154}
155
156static void qed_vf_pf_add_qid(struct qed_hwfn *p_hwfn,
157 struct qed_queue_cid *p_cid)
158{
159 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
160 struct vfpf_qid_tlv *p_qid_tlv;
161
162
163 if (!(p_iov->acquire_resp.pfdev_info.capabilities &
164 PFVF_ACQUIRE_CAP_QUEUE_QIDS))
165 return;
166
167 p_qid_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
168 CHANNEL_TLV_QID, sizeof(*p_qid_tlv));
169 p_qid_tlv->qid = p_cid->qid_usage_idx;
170}
171
172int _qed_vf_pf_release(struct qed_hwfn *p_hwfn, bool b_final)
173{
174 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
175 struct pfvf_def_resp_tlv *resp;
176 struct vfpf_first_tlv *req;
177 u32 size;
178 int rc;
179
180
181 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
182
183
184 qed_add_tlv(p_hwfn, &p_iov->offset,
185 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
186
187 resp = &p_iov->pf2vf_reply->default_resp;
188 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
189
190 if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS)
191 rc = -EAGAIN;
192
193 qed_vf_pf_req_end(p_hwfn, rc);
194 if (!b_final)
195 return rc;
196
197 p_hwfn->b_int_enabled = 0;
198
199 if (p_iov->vf2pf_request)
200 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
201 sizeof(union vfpf_tlvs),
202 p_iov->vf2pf_request,
203 p_iov->vf2pf_request_phys);
204 if (p_iov->pf2vf_reply)
205 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
206 sizeof(union pfvf_tlvs),
207 p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
208
209 if (p_iov->bulletin.p_virt) {
210 size = sizeof(struct qed_bulletin_content);
211 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
212 size,
213 p_iov->bulletin.p_virt, p_iov->bulletin.phys);
214 }
215
216 kfree(p_hwfn->vf_iov_info);
217 p_hwfn->vf_iov_info = NULL;
218
219 return rc;
220}
221
222int qed_vf_pf_release(struct qed_hwfn *p_hwfn)
223{
224 return _qed_vf_pf_release(p_hwfn, true);
225}
226
227#define VF_ACQUIRE_THRESH 3
228static void qed_vf_pf_acquire_reduce_resc(struct qed_hwfn *p_hwfn,
229 struct vf_pf_resc_request *p_req,
230 struct pf_vf_resc *p_resp)
231{
232 DP_VERBOSE(p_hwfn,
233 QED_MSG_IOV,
234 "PF unwilling to fullill resource request: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x] cids [%02x/%02x]. Try PF recommended amount\n",
235 p_req->num_rxqs,
236 p_resp->num_rxqs,
237 p_req->num_rxqs,
238 p_resp->num_txqs,
239 p_req->num_sbs,
240 p_resp->num_sbs,
241 p_req->num_mac_filters,
242 p_resp->num_mac_filters,
243 p_req->num_vlan_filters,
244 p_resp->num_vlan_filters,
245 p_req->num_mc_filters,
246 p_resp->num_mc_filters, p_req->num_cids, p_resp->num_cids);
247
248
249 p_req->num_txqs = p_resp->num_txqs;
250 p_req->num_rxqs = p_resp->num_rxqs;
251 p_req->num_sbs = p_resp->num_sbs;
252 p_req->num_mac_filters = p_resp->num_mac_filters;
253 p_req->num_vlan_filters = p_resp->num_vlan_filters;
254 p_req->num_mc_filters = p_resp->num_mc_filters;
255 p_req->num_cids = p_resp->num_cids;
256}
257
258static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
259{
260 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
261 struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
262 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
263 struct vf_pf_resc_request *p_resc;
264 bool resources_acquired = false;
265 struct vfpf_acquire_tlv *req;
266 int rc = 0, attempts = 0;
267
268
269 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
270 p_resc = &req->resc_request;
271
272
273 req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
274
275 p_resc->num_rxqs = QED_MAX_VF_CHAINS_PER_PF;
276 p_resc->num_txqs = QED_MAX_VF_CHAINS_PER_PF;
277 p_resc->num_sbs = QED_MAX_VF_CHAINS_PER_PF;
278 p_resc->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
279 p_resc->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
280 p_resc->num_cids = QED_ETH_VF_DEFAULT_NUM_CIDS;
281
282 req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
283 req->vfdev_info.fw_major = FW_MAJOR_VERSION;
284 req->vfdev_info.fw_minor = FW_MINOR_VERSION;
285 req->vfdev_info.fw_revision = FW_REVISION_VERSION;
286 req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
287 req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
288 req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR;
289
290
291 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
292
293
294 if (p_iov->b_doorbell_bar) {
295 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_PHYSICAL_BAR |
296 VFPF_ACQUIRE_CAP_QUEUE_QIDS;
297 p_resc->num_cids = QED_ETH_VF_MAX_NUM_CIDS;
298 }
299
300
301 req->bulletin_addr = p_iov->bulletin.phys;
302 req->bulletin_size = p_iov->bulletin.size;
303
304
305 qed_add_tlv(p_hwfn, &p_iov->offset,
306 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
307
308 while (!resources_acquired) {
309 DP_VERBOSE(p_hwfn,
310 QED_MSG_IOV, "attempting to acquire resources\n");
311
312
313 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
314
315
316 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
317 if (rc)
318 goto exit;
319
320
321 memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
322
323 attempts++;
324
325 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
326
327 if (!(resp->pfdev_info.capabilities &
328 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
329
330
331
332
333 req->vfdev_info.capabilities |=
334 VFPF_ACQUIRE_CAP_PRE_FP_HSI;
335 }
336 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
337 resources_acquired = true;
338 } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
339 attempts < VF_ACQUIRE_THRESH) {
340 qed_vf_pf_acquire_reduce_resc(p_hwfn, p_resc,
341 &resp->resc);
342 } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) {
343 if (pfdev_info->major_fp_hsi &&
344 (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) {
345 DP_NOTICE(p_hwfn,
346 "PF uses an incompatible fastpath HSI %02x.%02x [VF requires %02x.%02x]. Please change to a VF driver using %02x.xx.\n",
347 pfdev_info->major_fp_hsi,
348 pfdev_info->minor_fp_hsi,
349 ETH_HSI_VER_MAJOR,
350 ETH_HSI_VER_MINOR,
351 pfdev_info->major_fp_hsi);
352 rc = -EINVAL;
353 goto exit;
354 }
355
356 if (!pfdev_info->major_fp_hsi) {
357 if (req->vfdev_info.capabilities &
358 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
359 DP_NOTICE(p_hwfn,
360 "PF uses very old drivers. Please change to a VF driver using no later than 8.8.x.x.\n");
361 rc = -EINVAL;
362 goto exit;
363 } else {
364 DP_INFO(p_hwfn,
365 "PF is old - try re-acquire to see if it supports FW-version override\n");
366 req->vfdev_info.capabilities |=
367 VFPF_ACQUIRE_CAP_PRE_FP_HSI;
368 continue;
369 }
370 }
371
372
373
374
375 DP_NOTICE(p_hwfn, "PF rejected acquisition by VF\n");
376 rc = -EINVAL;
377 goto exit;
378 } else {
379 DP_ERR(p_hwfn,
380 "PF returned error %d to VF acquisition request\n",
381 resp->hdr.status);
382 rc = -EAGAIN;
383 goto exit;
384 }
385 }
386
387
388 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_PRE_FP_HSI)
389 p_iov->b_pre_fp_hsi = true;
390
391
392
393
394
395 if (!(resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_QUEUE_QIDS))
396 resp->resc.num_cids = resp->resc.num_rxqs + resp->resc.num_txqs;
397
398
399 p_iov->bulletin.size = resp->bulletin_size;
400
401
402 p_hwfn->cdev->type = resp->pfdev_info.dev_type;
403 p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
404
405 p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
406
407
408 if (IS_LEAD_HWFN(p_hwfn)) {
409 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
410 DP_NOTICE(p_hwfn, "100g VF\n");
411 p_hwfn->cdev->num_hwfns = 2;
412 }
413 }
414
415 if (!p_iov->b_pre_fp_hsi &&
416 ETH_HSI_VER_MINOR &&
417 (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR)) {
418 DP_INFO(p_hwfn,
419 "PF is using older fastpath HSI; %02x.%02x is configured\n",
420 ETH_HSI_VER_MAJOR, resp->pfdev_info.minor_fp_hsi);
421 }
422
423exit:
424 qed_vf_pf_req_end(p_hwfn, rc);
425
426 return rc;
427}
428
429u32 qed_vf_hw_bar_size(struct qed_hwfn *p_hwfn, enum BAR_ID bar_id)
430{
431 u32 bar_size;
432
433
434 if (bar_id == BAR_ID_0)
435 return 1 << 17;
436
437
438 bar_size = p_hwfn->vf_iov_info->acquire_resp.pfdev_info.bar_size;
439 if (bar_size)
440 return 1 << bar_size;
441 return 0;
442}
443
444int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
445{
446 struct qed_hwfn *p_lead = QED_LEADING_HWFN(p_hwfn->cdev);
447 struct qed_vf_iov *p_iov;
448 u32 reg;
449 int rc;
450
451
452
453
454 if (IS_LEAD_HWFN(p_hwfn))
455 p_hwfn->cdev->num_hwfns = 1;
456
457 reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
458 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
459
460 reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
461 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
462
463
464 p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
465 if (!p_iov)
466 return -ENOMEM;
467
468
469
470
471
472 if (!p_hwfn->doorbells) {
473 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
474 PXP_VF_BAR0_START_DQ;
475 } else if (p_hwfn == p_lead) {
476
477
478
479
480 p_iov->b_doorbell_bar = true;
481 } else {
482
483
484
485 if (p_lead->vf_iov_info->b_doorbell_bar)
486 p_iov->b_doorbell_bar = true;
487 else
488 p_hwfn->doorbells = (u8 __iomem *)
489 p_hwfn->regview + PXP_VF_BAR0_START_DQ;
490 }
491
492
493 p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
494 sizeof(union vfpf_tlvs),
495 &p_iov->vf2pf_request_phys,
496 GFP_KERNEL);
497 if (!p_iov->vf2pf_request)
498 goto free_p_iov;
499
500 p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
501 sizeof(union pfvf_tlvs),
502 &p_iov->pf2vf_reply_phys,
503 GFP_KERNEL);
504 if (!p_iov->pf2vf_reply)
505 goto free_vf2pf_request;
506
507 DP_VERBOSE(p_hwfn,
508 QED_MSG_IOV,
509 "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
510 p_iov->vf2pf_request,
511 (u64) p_iov->vf2pf_request_phys,
512 p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
513
514
515 p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
516 p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
517 p_iov->bulletin.size,
518 &p_iov->bulletin.phys,
519 GFP_KERNEL);
520 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
521 "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
522 p_iov->bulletin.p_virt,
523 (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
524
525 mutex_init(&p_iov->mutex);
526
527 p_hwfn->vf_iov_info = p_iov;
528
529 p_hwfn->hw_info.personality = QED_PCI_ETH;
530
531 rc = qed_vf_pf_acquire(p_hwfn);
532
533
534
535
536
537
538
539
540 if (!rc && p_iov->b_doorbell_bar &&
541 !qed_vf_hw_bar_size(p_hwfn, BAR_ID_1) &&
542 (p_hwfn->cdev->num_hwfns > 1)) {
543 rc = _qed_vf_pf_release(p_hwfn, false);
544 if (rc)
545 return rc;
546
547 p_iov->b_doorbell_bar = false;
548 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
549 PXP_VF_BAR0_START_DQ;
550 rc = qed_vf_pf_acquire(p_hwfn);
551 }
552
553 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
554 "Regview [%p], Doorbell [%p], Device-doorbell [%p]\n",
555 p_hwfn->regview, p_hwfn->doorbells, p_hwfn->cdev->doorbells);
556
557 return rc;
558
559free_vf2pf_request:
560 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
561 sizeof(union vfpf_tlvs),
562 p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
563free_p_iov:
564 kfree(p_iov);
565
566 return -ENOMEM;
567}
568#define TSTORM_QZONE_START PXP_VF_BAR0_START_SDM_ZONE_A
569#define MSTORM_QZONE_START(dev) (TSTORM_QZONE_START + \
570 (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
571
572static void
573__qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
574 struct qed_tunn_update_type *p_src,
575 enum qed_tunn_clss mask, u8 *p_cls)
576{
577 if (p_src->b_update_mode) {
578 p_req->tun_mode_update_mask |= BIT(mask);
579
580 if (p_src->b_mode_enabled)
581 p_req->tunn_mode |= BIT(mask);
582 }
583
584 *p_cls = p_src->tun_cls;
585}
586
587static void
588qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
589 struct qed_tunn_update_type *p_src,
590 enum qed_tunn_clss mask,
591 u8 *p_cls, struct qed_tunn_update_udp_port *p_port,
592 u8 *p_update_port, u16 *p_udp_port)
593{
594 if (p_port->b_update_port) {
595 *p_update_port = 1;
596 *p_udp_port = p_port->port;
597 }
598
599 __qed_vf_prep_tunn_req_tlv(p_req, p_src, mask, p_cls);
600}
601
602void qed_vf_set_vf_start_tunn_update_param(struct qed_tunnel_info *p_tun)
603{
604 if (p_tun->vxlan.b_mode_enabled)
605 p_tun->vxlan.b_update_mode = true;
606 if (p_tun->l2_geneve.b_mode_enabled)
607 p_tun->l2_geneve.b_update_mode = true;
608 if (p_tun->ip_geneve.b_mode_enabled)
609 p_tun->ip_geneve.b_update_mode = true;
610 if (p_tun->l2_gre.b_mode_enabled)
611 p_tun->l2_gre.b_update_mode = true;
612 if (p_tun->ip_gre.b_mode_enabled)
613 p_tun->ip_gre.b_update_mode = true;
614
615 p_tun->b_update_rx_cls = true;
616 p_tun->b_update_tx_cls = true;
617}
618
619static void
620__qed_vf_update_tunn_param(struct qed_tunn_update_type *p_tun,
621 u16 feature_mask, u8 tunn_mode,
622 u8 tunn_cls, enum qed_tunn_mode val)
623{
624 if (feature_mask & BIT(val)) {
625 p_tun->b_mode_enabled = tunn_mode;
626 p_tun->tun_cls = tunn_cls;
627 } else {
628 p_tun->b_mode_enabled = false;
629 }
630}
631
632static void qed_vf_update_tunn_param(struct qed_hwfn *p_hwfn,
633 struct qed_tunnel_info *p_tun,
634 struct pfvf_update_tunn_param_tlv *p_resp)
635{
636
637 u16 feat_mask = p_resp->tunn_feature_mask;
638
639 __qed_vf_update_tunn_param(&p_tun->vxlan, feat_mask,
640 p_resp->vxlan_mode, p_resp->vxlan_clss,
641 QED_MODE_VXLAN_TUNN);
642 __qed_vf_update_tunn_param(&p_tun->l2_geneve, feat_mask,
643 p_resp->l2geneve_mode,
644 p_resp->l2geneve_clss,
645 QED_MODE_L2GENEVE_TUNN);
646 __qed_vf_update_tunn_param(&p_tun->ip_geneve, feat_mask,
647 p_resp->ipgeneve_mode,
648 p_resp->ipgeneve_clss,
649 QED_MODE_IPGENEVE_TUNN);
650 __qed_vf_update_tunn_param(&p_tun->l2_gre, feat_mask,
651 p_resp->l2gre_mode, p_resp->l2gre_clss,
652 QED_MODE_L2GRE_TUNN);
653 __qed_vf_update_tunn_param(&p_tun->ip_gre, feat_mask,
654 p_resp->ipgre_mode, p_resp->ipgre_clss,
655 QED_MODE_IPGRE_TUNN);
656 p_tun->geneve_port.port = p_resp->geneve_udp_port;
657 p_tun->vxlan_port.port = p_resp->vxlan_udp_port;
658
659 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
660 "tunn mode: vxlan=0x%x, l2geneve=0x%x, ipgeneve=0x%x, l2gre=0x%x, ipgre=0x%x",
661 p_tun->vxlan.b_mode_enabled, p_tun->l2_geneve.b_mode_enabled,
662 p_tun->ip_geneve.b_mode_enabled,
663 p_tun->l2_gre.b_mode_enabled, p_tun->ip_gre.b_mode_enabled);
664}
665
666int qed_vf_pf_tunnel_param_update(struct qed_hwfn *p_hwfn,
667 struct qed_tunnel_info *p_src)
668{
669 struct qed_tunnel_info *p_tun = &p_hwfn->cdev->tunnel;
670 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
671 struct pfvf_update_tunn_param_tlv *p_resp;
672 struct vfpf_update_tunn_param_tlv *p_req;
673 int rc;
674
675 p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_TUNN_PARAM,
676 sizeof(*p_req));
677
678 if (p_src->b_update_rx_cls && p_src->b_update_tx_cls)
679 p_req->update_tun_cls = 1;
680
681 qed_vf_prep_tunn_req_tlv(p_req, &p_src->vxlan, QED_MODE_VXLAN_TUNN,
682 &p_req->vxlan_clss, &p_src->vxlan_port,
683 &p_req->update_vxlan_port,
684 &p_req->vxlan_port);
685 qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_geneve,
686 QED_MODE_L2GENEVE_TUNN,
687 &p_req->l2geneve_clss, &p_src->geneve_port,
688 &p_req->update_geneve_port,
689 &p_req->geneve_port);
690 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_geneve,
691 QED_MODE_IPGENEVE_TUNN,
692 &p_req->ipgeneve_clss);
693 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_gre,
694 QED_MODE_L2GRE_TUNN, &p_req->l2gre_clss);
695 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_gre,
696 QED_MODE_IPGRE_TUNN, &p_req->ipgre_clss);
697
698
699 qed_add_tlv(p_hwfn, &p_iov->offset,
700 CHANNEL_TLV_LIST_END,
701 sizeof(struct channel_list_end_tlv));
702
703 p_resp = &p_iov->pf2vf_reply->tunn_param_resp;
704 rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
705
706 if (rc)
707 goto exit;
708
709 if (p_resp->hdr.status != PFVF_STATUS_SUCCESS) {
710 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
711 "Failed to update tunnel parameters\n");
712 rc = -EINVAL;
713 }
714
715 qed_vf_update_tunn_param(p_hwfn, p_tun, p_resp);
716exit:
717 qed_vf_pf_req_end(p_hwfn, rc);
718 return rc;
719}
720
721int
722qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn,
723 struct qed_queue_cid *p_cid,
724 u16 bd_max_bytes,
725 dma_addr_t bd_chain_phys_addr,
726 dma_addr_t cqe_pbl_addr,
727 u16 cqe_pbl_size, void __iomem **pp_prod)
728{
729 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
730 struct pfvf_start_queue_resp_tlv *resp;
731 struct vfpf_start_rxq_tlv *req;
732 u8 rx_qid = p_cid->rel.queue_id;
733 int rc;
734
735
736 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
737
738 req->rx_qid = rx_qid;
739 req->cqe_pbl_addr = cqe_pbl_addr;
740 req->cqe_pbl_size = cqe_pbl_size;
741 req->rxq_addr = bd_chain_phys_addr;
742 req->hw_sb = p_cid->sb_igu_id;
743 req->sb_index = p_cid->sb_idx;
744 req->bd_max_bytes = bd_max_bytes;
745 req->stat_id = -1;
746
747
748
749
750 if (p_iov->b_pre_fp_hsi) {
751 u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
752 u32 init_prod_val = 0;
753
754 *pp_prod = (u8 __iomem *)
755 p_hwfn->regview +
756 MSTORM_QZONE_START(p_hwfn->cdev) +
757 hw_qid * MSTORM_QZONE_SIZE;
758
759
760 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
761 (u32 *)(&init_prod_val));
762 }
763
764 qed_vf_pf_add_qid(p_hwfn, p_cid);
765
766
767 qed_add_tlv(p_hwfn, &p_iov->offset,
768 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
769
770 resp = &p_iov->pf2vf_reply->queue_start;
771 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
772 if (rc)
773 goto exit;
774
775 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
776 rc = -EINVAL;
777 goto exit;
778 }
779
780
781 if (!p_iov->b_pre_fp_hsi) {
782 u32 init_prod_val = 0;
783
784 *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset;
785 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
786 "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
787 rx_qid, *pp_prod, resp->offset);
788
789
790 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
791 (u32 *)&init_prod_val);
792 }
793exit:
794 qed_vf_pf_req_end(p_hwfn, rc);
795
796 return rc;
797}
798
799int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn,
800 struct qed_queue_cid *p_cid, bool cqe_completion)
801{
802 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
803 struct vfpf_stop_rxqs_tlv *req;
804 struct pfvf_def_resp_tlv *resp;
805 int rc;
806
807
808 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
809
810 req->rx_qid = p_cid->rel.queue_id;
811 req->num_rxqs = 1;
812 req->cqe_completion = cqe_completion;
813
814 qed_vf_pf_add_qid(p_hwfn, p_cid);
815
816
817 qed_add_tlv(p_hwfn, &p_iov->offset,
818 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
819
820 resp = &p_iov->pf2vf_reply->default_resp;
821 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
822 if (rc)
823 goto exit;
824
825 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
826 rc = -EINVAL;
827 goto exit;
828 }
829
830exit:
831 qed_vf_pf_req_end(p_hwfn, rc);
832
833 return rc;
834}
835
836int
837qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn,
838 struct qed_queue_cid *p_cid,
839 dma_addr_t pbl_addr,
840 u16 pbl_size, void __iomem **pp_doorbell)
841{
842 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
843 struct pfvf_start_queue_resp_tlv *resp;
844 struct vfpf_start_txq_tlv *req;
845 u16 qid = p_cid->rel.queue_id;
846 int rc;
847
848
849 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
850
851 req->tx_qid = qid;
852
853
854 req->pbl_addr = pbl_addr;
855 req->pbl_size = pbl_size;
856 req->hw_sb = p_cid->sb_igu_id;
857 req->sb_index = p_cid->sb_idx;
858
859 qed_vf_pf_add_qid(p_hwfn, p_cid);
860
861
862 qed_add_tlv(p_hwfn, &p_iov->offset,
863 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
864
865 resp = &p_iov->pf2vf_reply->queue_start;
866 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
867 if (rc)
868 goto exit;
869
870 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
871 rc = -EINVAL;
872 goto exit;
873 }
874
875
876
877
878 if (!p_iov->b_pre_fp_hsi) {
879 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + resp->offset;
880 } else {
881 u8 cid = p_iov->acquire_resp.resc.cid[qid];
882
883 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
884 qed_db_addr_vf(cid,
885 DQ_DEMS_LEGACY);
886 }
887
888 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
889 "Txq[0x%02x.%02x]: doorbell at %p [offset 0x%08x]\n",
890 qid, p_cid->qid_usage_idx, *pp_doorbell, resp->offset);
891exit:
892 qed_vf_pf_req_end(p_hwfn, rc);
893
894 return rc;
895}
896
897int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
898{
899 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
900 struct vfpf_stop_txqs_tlv *req;
901 struct pfvf_def_resp_tlv *resp;
902 int rc;
903
904
905 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
906
907 req->tx_qid = p_cid->rel.queue_id;
908 req->num_txqs = 1;
909
910 qed_vf_pf_add_qid(p_hwfn, p_cid);
911
912
913 qed_add_tlv(p_hwfn, &p_iov->offset,
914 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
915
916 resp = &p_iov->pf2vf_reply->default_resp;
917 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
918 if (rc)
919 goto exit;
920
921 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
922 rc = -EINVAL;
923 goto exit;
924 }
925
926exit:
927 qed_vf_pf_req_end(p_hwfn, rc);
928
929 return rc;
930}
931
932int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn,
933 u8 vport_id,
934 u16 mtu,
935 u8 inner_vlan_removal,
936 enum qed_tpa_mode tpa_mode,
937 u8 max_buffers_per_cqe, u8 only_untagged)
938{
939 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
940 struct vfpf_vport_start_tlv *req;
941 struct pfvf_def_resp_tlv *resp;
942 int rc, i;
943
944
945 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
946
947 req->mtu = mtu;
948 req->vport_id = vport_id;
949 req->inner_vlan_removal = inner_vlan_removal;
950 req->tpa_mode = tpa_mode;
951 req->max_buffers_per_cqe = max_buffers_per_cqe;
952 req->only_untagged = only_untagged;
953
954
955 for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++) {
956 struct qed_sb_info *p_sb = p_hwfn->vf_iov_info->sbs_info[i];
957
958 if (p_sb)
959 req->sb_addr[i] = p_sb->sb_phys;
960 }
961
962
963 qed_add_tlv(p_hwfn, &p_iov->offset,
964 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
965
966 resp = &p_iov->pf2vf_reply->default_resp;
967 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
968 if (rc)
969 goto exit;
970
971 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
972 rc = -EINVAL;
973 goto exit;
974 }
975
976exit:
977 qed_vf_pf_req_end(p_hwfn, rc);
978
979 return rc;
980}
981
982int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn)
983{
984 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
985 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
986 int rc;
987
988
989 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
990 sizeof(struct vfpf_first_tlv));
991
992
993 qed_add_tlv(p_hwfn, &p_iov->offset,
994 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
995
996 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
997 if (rc)
998 goto exit;
999
1000 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1001 rc = -EINVAL;
1002 goto exit;
1003 }
1004
1005exit:
1006 qed_vf_pf_req_end(p_hwfn, rc);
1007
1008 return rc;
1009}
1010
1011static bool
1012qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn,
1013 struct qed_sp_vport_update_params *p_data,
1014 u16 tlv)
1015{
1016 switch (tlv) {
1017 case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
1018 return !!(p_data->update_vport_active_rx_flg ||
1019 p_data->update_vport_active_tx_flg);
1020 case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
1021 return !!p_data->update_tx_switching_flg;
1022 case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
1023 return !!p_data->update_inner_vlan_removal_flg;
1024 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
1025 return !!p_data->update_accept_any_vlan_flg;
1026 case CHANNEL_TLV_VPORT_UPDATE_MCAST:
1027 return !!p_data->update_approx_mcast_flg;
1028 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
1029 return !!(p_data->accept_flags.update_rx_mode_config ||
1030 p_data->accept_flags.update_tx_mode_config);
1031 case CHANNEL_TLV_VPORT_UPDATE_RSS:
1032 return !!p_data->rss_params;
1033 case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
1034 return !!p_data->sge_tpa_params;
1035 default:
1036 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n",
1037 tlv);
1038 return false;
1039 }
1040}
1041
1042static void
1043qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn,
1044 struct qed_sp_vport_update_params *p_data)
1045{
1046 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1047 struct pfvf_def_resp_tlv *p_resp;
1048 u16 tlv;
1049
1050 for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1051 tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) {
1052 if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
1053 continue;
1054
1055 p_resp = (struct pfvf_def_resp_tlv *)
1056 qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply,
1057 tlv);
1058 if (p_resp && p_resp->hdr.status)
1059 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1060 "TLV[%d] Configuration %s\n",
1061 tlv,
1062 (p_resp && p_resp->hdr.status) ? "succeeded"
1063 : "failed");
1064 }
1065}
1066
1067int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn,
1068 struct qed_sp_vport_update_params *p_params)
1069{
1070 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1071 struct vfpf_vport_update_tlv *req;
1072 struct pfvf_def_resp_tlv *resp;
1073 u8 update_rx, update_tx;
1074 u32 resp_size = 0;
1075 u16 size, tlv;
1076 int rc;
1077
1078 resp = &p_iov->pf2vf_reply->default_resp;
1079 resp_size = sizeof(*resp);
1080
1081 update_rx = p_params->update_vport_active_rx_flg;
1082 update_tx = p_params->update_vport_active_tx_flg;
1083
1084
1085 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
1086
1087
1088 if (update_rx || update_tx) {
1089 struct vfpf_vport_update_activate_tlv *p_act_tlv;
1090
1091 size = sizeof(struct vfpf_vport_update_activate_tlv);
1092 p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
1093 CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
1094 size);
1095 resp_size += sizeof(struct pfvf_def_resp_tlv);
1096
1097 if (update_rx) {
1098 p_act_tlv->update_rx = update_rx;
1099 p_act_tlv->active_rx = p_params->vport_active_rx_flg;
1100 }
1101
1102 if (update_tx) {
1103 p_act_tlv->update_tx = update_tx;
1104 p_act_tlv->active_tx = p_params->vport_active_tx_flg;
1105 }
1106 }
1107
1108 if (p_params->update_tx_switching_flg) {
1109 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
1110
1111 size = sizeof(struct vfpf_vport_update_tx_switch_tlv);
1112 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1113 p_tx_switch_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
1114 tlv, size);
1115 resp_size += sizeof(struct pfvf_def_resp_tlv);
1116
1117 p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg;
1118 }
1119
1120 if (p_params->update_approx_mcast_flg) {
1121 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
1122
1123 size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
1124 p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
1125 CHANNEL_TLV_VPORT_UPDATE_MCAST, size);
1126 resp_size += sizeof(struct pfvf_def_resp_tlv);
1127
1128 memcpy(p_mcast_tlv->bins, p_params->bins,
1129 sizeof(u32) * ETH_MULTICAST_MAC_BINS_IN_REGS);
1130 }
1131
1132 update_rx = p_params->accept_flags.update_rx_mode_config;
1133 update_tx = p_params->accept_flags.update_tx_mode_config;
1134
1135 if (update_rx || update_tx) {
1136 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
1137
1138 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1139 size = sizeof(struct vfpf_vport_update_accept_param_tlv);
1140 p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
1141 resp_size += sizeof(struct pfvf_def_resp_tlv);
1142
1143 if (update_rx) {
1144 p_accept_tlv->update_rx_mode = update_rx;
1145 p_accept_tlv->rx_accept_filter =
1146 p_params->accept_flags.rx_accept_filter;
1147 }
1148
1149 if (update_tx) {
1150 p_accept_tlv->update_tx_mode = update_tx;
1151 p_accept_tlv->tx_accept_filter =
1152 p_params->accept_flags.tx_accept_filter;
1153 }
1154 }
1155
1156 if (p_params->rss_params) {
1157 struct qed_rss_params *rss_params = p_params->rss_params;
1158 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
1159 int i, table_size;
1160
1161 size = sizeof(struct vfpf_vport_update_rss_tlv);
1162 p_rss_tlv = qed_add_tlv(p_hwfn,
1163 &p_iov->offset,
1164 CHANNEL_TLV_VPORT_UPDATE_RSS, size);
1165 resp_size += sizeof(struct pfvf_def_resp_tlv);
1166
1167 if (rss_params->update_rss_config)
1168 p_rss_tlv->update_rss_flags |=
1169 VFPF_UPDATE_RSS_CONFIG_FLAG;
1170 if (rss_params->update_rss_capabilities)
1171 p_rss_tlv->update_rss_flags |=
1172 VFPF_UPDATE_RSS_CAPS_FLAG;
1173 if (rss_params->update_rss_ind_table)
1174 p_rss_tlv->update_rss_flags |=
1175 VFPF_UPDATE_RSS_IND_TABLE_FLAG;
1176 if (rss_params->update_rss_key)
1177 p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
1178
1179 p_rss_tlv->rss_enable = rss_params->rss_enable;
1180 p_rss_tlv->rss_caps = rss_params->rss_caps;
1181 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
1182
1183 table_size = min_t(int, T_ETH_INDIRECTION_TABLE_SIZE,
1184 1 << p_rss_tlv->rss_table_size_log);
1185 for (i = 0; i < table_size; i++) {
1186 struct qed_queue_cid *p_queue;
1187
1188 p_queue = rss_params->rss_ind_table[i];
1189 p_rss_tlv->rss_ind_table[i] = p_queue->rel.queue_id;
1190 }
1191 memcpy(p_rss_tlv->rss_key, rss_params->rss_key,
1192 sizeof(rss_params->rss_key));
1193 }
1194
1195 if (p_params->update_accept_any_vlan_flg) {
1196 struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
1197
1198 size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
1199 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1200 p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
1201
1202 resp_size += sizeof(struct pfvf_def_resp_tlv);
1203 p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
1204 p_any_vlan_tlv->update_accept_any_vlan_flg =
1205 p_params->update_accept_any_vlan_flg;
1206 }
1207
1208
1209 qed_add_tlv(p_hwfn, &p_iov->offset,
1210 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1211
1212 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
1213 if (rc)
1214 goto exit;
1215
1216 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1217 rc = -EINVAL;
1218 goto exit;
1219 }
1220
1221 qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
1222
1223exit:
1224 qed_vf_pf_req_end(p_hwfn, rc);
1225
1226 return rc;
1227}
1228
1229int qed_vf_pf_reset(struct qed_hwfn *p_hwfn)
1230{
1231 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1232 struct pfvf_def_resp_tlv *resp;
1233 struct vfpf_first_tlv *req;
1234 int rc;
1235
1236
1237 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
1238
1239
1240 qed_add_tlv(p_hwfn, &p_iov->offset,
1241 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1242
1243 resp = &p_iov->pf2vf_reply->default_resp;
1244 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1245 if (rc)
1246 goto exit;
1247
1248 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1249 rc = -EAGAIN;
1250 goto exit;
1251 }
1252
1253 p_hwfn->b_int_enabled = 0;
1254
1255exit:
1256 qed_vf_pf_req_end(p_hwfn, rc);
1257
1258 return rc;
1259}
1260
1261void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn,
1262 struct qed_filter_mcast *p_filter_cmd)
1263{
1264 struct qed_sp_vport_update_params sp_params;
1265 int i;
1266
1267 memset(&sp_params, 0, sizeof(sp_params));
1268 sp_params.update_approx_mcast_flg = 1;
1269
1270 if (p_filter_cmd->opcode == QED_FILTER_ADD) {
1271 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1272 u32 bit;
1273
1274 bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1275 sp_params.bins[bit / 32] |= 1 << (bit % 32);
1276 }
1277 }
1278
1279 qed_vf_pf_vport_update(p_hwfn, &sp_params);
1280}
1281
1282int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn,
1283 struct qed_filter_ucast *p_ucast)
1284{
1285 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1286 struct vfpf_ucast_filter_tlv *req;
1287 struct pfvf_def_resp_tlv *resp;
1288 int rc;
1289
1290
1291 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
1292 req->opcode = (u8) p_ucast->opcode;
1293 req->type = (u8) p_ucast->type;
1294 memcpy(req->mac, p_ucast->mac, ETH_ALEN);
1295 req->vlan = p_ucast->vlan;
1296
1297
1298 qed_add_tlv(p_hwfn, &p_iov->offset,
1299 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1300
1301 resp = &p_iov->pf2vf_reply->default_resp;
1302 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1303 if (rc)
1304 goto exit;
1305
1306 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1307 rc = -EAGAIN;
1308 goto exit;
1309 }
1310
1311exit:
1312 qed_vf_pf_req_end(p_hwfn, rc);
1313
1314 return rc;
1315}
1316
1317int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn)
1318{
1319 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1320 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
1321 int rc;
1322
1323
1324 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
1325 sizeof(struct vfpf_first_tlv));
1326
1327
1328 qed_add_tlv(p_hwfn, &p_iov->offset,
1329 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1330
1331 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1332 if (rc)
1333 goto exit;
1334
1335 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1336 rc = -EINVAL;
1337 goto exit;
1338 }
1339
1340exit:
1341 qed_vf_pf_req_end(p_hwfn, rc);
1342
1343 return rc;
1344}
1345
1346int qed_vf_pf_get_coalesce(struct qed_hwfn *p_hwfn,
1347 u16 *p_coal, struct qed_queue_cid *p_cid)
1348{
1349 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1350 struct pfvf_read_coal_resp_tlv *resp;
1351 struct vfpf_read_coal_req_tlv *req;
1352 int rc;
1353
1354
1355 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_READ, sizeof(*req));
1356 req->qid = p_cid->rel.queue_id;
1357 req->is_rx = p_cid->b_is_rx ? 1 : 0;
1358
1359 qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1360 sizeof(struct channel_list_end_tlv));
1361 resp = &p_iov->pf2vf_reply->read_coal_resp;
1362
1363 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1364 if (rc)
1365 goto exit;
1366
1367 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
1368 goto exit;
1369
1370 *p_coal = resp->coal;
1371exit:
1372 qed_vf_pf_req_end(p_hwfn, rc);
1373
1374 return rc;
1375}
1376
1377int
1378qed_vf_pf_bulletin_update_mac(struct qed_hwfn *p_hwfn,
1379 u8 *p_mac)
1380{
1381 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1382 struct vfpf_bulletin_update_mac_tlv *p_req;
1383 struct pfvf_def_resp_tlv *p_resp;
1384 int rc;
1385
1386 if (!p_mac)
1387 return -EINVAL;
1388
1389
1390 p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_BULLETIN_UPDATE_MAC,
1391 sizeof(*p_req));
1392 ether_addr_copy(p_req->mac, p_mac);
1393 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1394 "Requesting bulletin update for MAC[%pM]\n", p_mac);
1395
1396
1397 qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1398 sizeof(struct channel_list_end_tlv));
1399
1400 p_resp = &p_iov->pf2vf_reply->default_resp;
1401 rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
1402 qed_vf_pf_req_end(p_hwfn, rc);
1403 return rc;
1404}
1405
1406int
1407qed_vf_pf_set_coalesce(struct qed_hwfn *p_hwfn,
1408 u16 rx_coal, u16 tx_coal, struct qed_queue_cid *p_cid)
1409{
1410 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1411 struct vfpf_update_coalesce *req;
1412 struct pfvf_def_resp_tlv *resp;
1413 int rc;
1414
1415
1416 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_UPDATE, sizeof(*req));
1417
1418 req->rx_coal = rx_coal;
1419 req->tx_coal = tx_coal;
1420 req->qid = p_cid->rel.queue_id;
1421
1422 DP_VERBOSE(p_hwfn,
1423 QED_MSG_IOV,
1424 "Setting coalesce rx_coal = %d, tx_coal = %d at queue = %d\n",
1425 rx_coal, tx_coal, req->qid);
1426
1427
1428 qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1429 sizeof(struct channel_list_end_tlv));
1430
1431 resp = &p_iov->pf2vf_reply->default_resp;
1432 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1433 if (rc)
1434 goto exit;
1435
1436 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
1437 goto exit;
1438
1439 if (rx_coal)
1440 p_hwfn->cdev->rx_coalesce_usecs = rx_coal;
1441
1442 if (tx_coal)
1443 p_hwfn->cdev->tx_coalesce_usecs = tx_coal;
1444
1445exit:
1446 qed_vf_pf_req_end(p_hwfn, rc);
1447 return rc;
1448}
1449
1450u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
1451{
1452 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1453
1454 if (!p_iov) {
1455 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1456 return 0;
1457 }
1458
1459 return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
1460}
1461
1462void qed_vf_set_sb_info(struct qed_hwfn *p_hwfn,
1463 u16 sb_id, struct qed_sb_info *p_sb)
1464{
1465 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1466
1467 if (!p_iov) {
1468 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1469 return;
1470 }
1471
1472 if (sb_id >= PFVF_MAX_SBS_PER_VF) {
1473 DP_NOTICE(p_hwfn, "Can't configure SB %04x\n", sb_id);
1474 return;
1475 }
1476
1477 p_iov->sbs_info[sb_id] = p_sb;
1478}
1479
1480int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change)
1481{
1482 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1483 struct qed_bulletin_content shadow;
1484 u32 crc, crc_size;
1485
1486 crc_size = sizeof(p_iov->bulletin.p_virt->crc);
1487 *p_change = 0;
1488
1489
1490 memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
1491
1492
1493 if (shadow.version == p_iov->bulletin_shadow.version)
1494 return 0;
1495
1496
1497 crc = crc32(0, (u8 *)&shadow + crc_size,
1498 p_iov->bulletin.size - crc_size);
1499 if (crc != shadow.crc)
1500 return -EAGAIN;
1501
1502
1503 memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
1504
1505 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1506 "Read a bulletin update %08x\n", shadow.version);
1507
1508 *p_change = 1;
1509
1510 return 0;
1511}
1512
1513void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1514 struct qed_mcp_link_params *p_params,
1515 struct qed_bulletin_content *p_bulletin)
1516{
1517 memset(p_params, 0, sizeof(*p_params));
1518
1519 p_params->speed.autoneg = p_bulletin->req_autoneg;
1520 p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
1521 p_params->speed.forced_speed = p_bulletin->req_forced_speed;
1522 p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
1523 p_params->pause.forced_rx = p_bulletin->req_forced_rx;
1524 p_params->pause.forced_tx = p_bulletin->req_forced_tx;
1525 p_params->loopback_mode = p_bulletin->req_loopback;
1526}
1527
1528void qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1529 struct qed_mcp_link_params *params)
1530{
1531 __qed_vf_get_link_params(p_hwfn, params,
1532 &(p_hwfn->vf_iov_info->bulletin_shadow));
1533}
1534
1535void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1536 struct qed_mcp_link_state *p_link,
1537 struct qed_bulletin_content *p_bulletin)
1538{
1539 memset(p_link, 0, sizeof(*p_link));
1540
1541 p_link->link_up = p_bulletin->link_up;
1542 p_link->speed = p_bulletin->speed;
1543 p_link->full_duplex = p_bulletin->full_duplex;
1544 p_link->an = p_bulletin->autoneg;
1545 p_link->an_complete = p_bulletin->autoneg_complete;
1546 p_link->parallel_detection = p_bulletin->parallel_detection;
1547 p_link->pfc_enabled = p_bulletin->pfc_enabled;
1548 p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
1549 p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
1550 p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
1551 p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
1552 p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
1553}
1554
1555void qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1556 struct qed_mcp_link_state *link)
1557{
1558 __qed_vf_get_link_state(p_hwfn, link,
1559 &(p_hwfn->vf_iov_info->bulletin_shadow));
1560}
1561
1562void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1563 struct qed_mcp_link_capabilities *p_link_caps,
1564 struct qed_bulletin_content *p_bulletin)
1565{
1566 memset(p_link_caps, 0, sizeof(*p_link_caps));
1567 p_link_caps->speed_capabilities = p_bulletin->capability_speed;
1568}
1569
1570void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1571 struct qed_mcp_link_capabilities *p_link_caps)
1572{
1573 __qed_vf_get_link_caps(p_hwfn, p_link_caps,
1574 &(p_hwfn->vf_iov_info->bulletin_shadow));
1575}
1576
1577void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
1578{
1579 *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
1580}
1581
1582void qed_vf_get_num_txqs(struct qed_hwfn *p_hwfn, u8 *num_txqs)
1583{
1584 *num_txqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_txqs;
1585}
1586
1587void qed_vf_get_num_cids(struct qed_hwfn *p_hwfn, u8 *num_cids)
1588{
1589 *num_cids = p_hwfn->vf_iov_info->acquire_resp.resc.num_cids;
1590}
1591
1592void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
1593{
1594 memcpy(port_mac,
1595 p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
1596}
1597
1598void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
1599{
1600 struct qed_vf_iov *p_vf;
1601
1602 p_vf = p_hwfn->vf_iov_info;
1603 *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
1604}
1605
1606void qed_vf_get_num_mac_filters(struct qed_hwfn *p_hwfn, u8 *num_mac_filters)
1607{
1608 struct qed_vf_iov *p_vf = p_hwfn->vf_iov_info;
1609
1610 *num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters;
1611}
1612
1613bool qed_vf_check_mac(struct qed_hwfn *p_hwfn, u8 *mac)
1614{
1615 struct qed_bulletin_content *bulletin;
1616
1617 bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1618 if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
1619 return true;
1620
1621
1622 if (ether_addr_equal(bulletin->mac, mac))
1623 return false;
1624
1625 return false;
1626}
1627
1628static bool qed_vf_bulletin_get_forced_mac(struct qed_hwfn *hwfn,
1629 u8 *dst_mac, u8 *p_is_forced)
1630{
1631 struct qed_bulletin_content *bulletin;
1632
1633 bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1634
1635 if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
1636 if (p_is_forced)
1637 *p_is_forced = 1;
1638 } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
1639 if (p_is_forced)
1640 *p_is_forced = 0;
1641 } else {
1642 return false;
1643 }
1644
1645 ether_addr_copy(dst_mac, bulletin->mac);
1646
1647 return true;
1648}
1649
1650static void
1651qed_vf_bulletin_get_udp_ports(struct qed_hwfn *p_hwfn,
1652 u16 *p_vxlan_port, u16 *p_geneve_port)
1653{
1654 struct qed_bulletin_content *p_bulletin;
1655
1656 p_bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1657
1658 *p_vxlan_port = p_bulletin->vxlan_udp_port;
1659 *p_geneve_port = p_bulletin->geneve_udp_port;
1660}
1661
1662void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
1663 u16 *fw_major, u16 *fw_minor,
1664 u16 *fw_rev, u16 *fw_eng)
1665{
1666 struct pf_vf_pfdev_info *info;
1667
1668 info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
1669
1670 *fw_major = info->fw_major;
1671 *fw_minor = info->fw_minor;
1672 *fw_rev = info->fw_rev;
1673 *fw_eng = info->fw_eng;
1674}
1675
1676static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
1677{
1678 struct qed_eth_cb_ops *ops = hwfn->cdev->protocol_ops.eth;
1679 u8 mac[ETH_ALEN], is_mac_exist, is_mac_forced;
1680 void *cookie = hwfn->cdev->ops_cookie;
1681 u16 vxlan_port, geneve_port;
1682
1683 qed_vf_bulletin_get_udp_ports(hwfn, &vxlan_port, &geneve_port);
1684 is_mac_exist = qed_vf_bulletin_get_forced_mac(hwfn, mac,
1685 &is_mac_forced);
1686 if (is_mac_exist && cookie)
1687 ops->force_mac(cookie, mac, !!is_mac_forced);
1688
1689 ops->ports_update(cookie, vxlan_port, geneve_port);
1690
1691
1692 qed_link_update(hwfn);
1693}
1694
1695void qed_iov_vf_task(struct work_struct *work)
1696{
1697 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
1698 iov_task.work);
1699 u8 change = 0;
1700
1701 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
1702 return;
1703
1704
1705 qed_vf_read_bulletin(hwfn, &change);
1706 if (test_and_clear_bit(QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG,
1707 &hwfn->iov_task_flags))
1708 change = 1;
1709 if (change)
1710 qed_handle_bulletin_change(hwfn);
1711
1712
1713 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ);
1714}
1715