qede: Add VF support
[deliverable/linux.git] / drivers / net / ethernet / qlogic / qed / qed_vf.c
CommitLineData
1408cc1f
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
36558c3d 9#include <linux/crc32.h>
1408cc1f
YM
10#include "qed.h"
11#include "qed_sriov.h"
12#include "qed_vf.h"
13
14static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length)
15{
16 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
17 void *p_tlv;
18
19 /* This lock is released when we receive PF's response
20 * in qed_send_msg2pf().
21 * So, qed_vf_pf_prep() and qed_send_msg2pf()
22 * must come in sequence.
23 */
24 mutex_lock(&(p_iov->mutex));
25
26 DP_VERBOSE(p_hwfn,
27 QED_MSG_IOV,
28 "preparing to send 0x%04x tlv over vf pf channel\n",
29 type);
30
31 /* Reset Requst offset */
32 p_iov->offset = (u8 *)p_iov->vf2pf_request;
33
34 /* Clear mailbox - both request and reply */
35 memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
36 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
37
38 /* Init type and length */
39 p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length);
40
41 /* Init first tlv header */
42 ((struct vfpf_first_tlv *)p_tlv)->reply_address =
43 (u64)p_iov->pf2vf_reply_phys;
44
45 return p_tlv;
46}
47
48static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size)
49{
50 union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
51 struct ustorm_trigger_vf_zone trigger;
52 struct ustorm_vf_zone *zone_data;
53 int rc = 0, time = 100;
54
55 zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
56
57 /* output tlvs list */
58 qed_dp_tlv_list(p_hwfn, p_req);
59
60 /* need to add the END TLV to the message size */
61 resp_size += sizeof(struct channel_list_end_tlv);
62
63 /* Send TLVs over HW channel */
64 memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
65 trigger.vf_pf_msg_valid = 1;
66
67 DP_VERBOSE(p_hwfn,
68 QED_MSG_IOV,
69 "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n",
70 GET_FIELD(p_hwfn->hw_info.concrete_fid,
71 PXP_CONCRETE_FID_PFID),
72 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
73 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
74 &zone_data->non_trigger.vf_pf_msg_addr,
75 *((u32 *)&trigger), &zone_data->trigger);
76
77 REG_WR(p_hwfn,
78 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
79 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
80
81 REG_WR(p_hwfn,
82 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
83 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
84
85 /* The message data must be written first, to prevent trigger before
86 * data is written.
87 */
88 wmb();
89
90 REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger));
91
92 /* When PF would be done with the response, it would write back to the
93 * `done' address. Poll until then.
94 */
95 while ((!*done) && time) {
96 msleep(25);
97 time--;
98 }
99
100 if (!*done) {
101 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
102 "VF <-- PF Timeout [Type %d]\n",
103 p_req->first_tlv.tl.type);
104 rc = -EBUSY;
105 goto exit;
106 } else {
107 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
108 "PF response: %d [Type %d]\n",
109 *done, p_req->first_tlv.tl.type);
110 }
111
112exit:
113 mutex_unlock(&(p_hwfn->vf_iov_info->mutex));
114
115 return rc;
116}
117
118#define VF_ACQUIRE_THRESH 3
119#define VF_ACQUIRE_MAC_FILTERS 1
120
121static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
122{
123 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
124 struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
125 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
126 u8 rx_count = 1, tx_count = 1, num_sbs = 1;
127 u8 num_mac = VF_ACQUIRE_MAC_FILTERS;
128 bool resources_acquired = false;
129 struct vfpf_acquire_tlv *req;
130 int rc = 0, attempts = 0;
131
132 /* clear mailbox and prep first tlv */
133 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
134
135 /* starting filling the request */
136 req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
137
138 req->resc_request.num_rxqs = rx_count;
139 req->resc_request.num_txqs = tx_count;
140 req->resc_request.num_sbs = num_sbs;
141 req->resc_request.num_mac_filters = num_mac;
142 req->resc_request.num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
143
144 req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
145 req->vfdev_info.fw_major = FW_MAJOR_VERSION;
146 req->vfdev_info.fw_minor = FW_MINOR_VERSION;
147 req->vfdev_info.fw_revision = FW_REVISION_VERSION;
148 req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
149
150 /* Fill capability field with any non-deprecated config we support */
151 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
152
153 /* pf 2 vf bulletin board address */
154 req->bulletin_addr = p_iov->bulletin.phys;
155 req->bulletin_size = p_iov->bulletin.size;
156
157 /* add list termination tlv */
158 qed_add_tlv(p_hwfn, &p_iov->offset,
159 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
160
161 while (!resources_acquired) {
162 DP_VERBOSE(p_hwfn,
163 QED_MSG_IOV, "attempting to acquire resources\n");
164
165 /* send acquire request */
166 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
167 if (rc)
168 return rc;
169
170 /* copy acquire response from buffer to p_hwfn */
171 memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
172
173 attempts++;
174
175 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
176 /* PF agrees to allocate our resources */
177 if (!(resp->pfdev_info.capabilities &
178 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
179 DP_INFO(p_hwfn,
180 "PF is using old incompatible driver; Either downgrade driver or request provider to update hypervisor version\n");
181 return -EINVAL;
182 }
183 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
184 resources_acquired = true;
185 } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
186 attempts < VF_ACQUIRE_THRESH) {
187 DP_VERBOSE(p_hwfn,
188 QED_MSG_IOV,
189 "PF unwilling to fullfill resource request. Try PF recommended amount\n");
190
191 /* humble our request */
192 req->resc_request.num_txqs = resp->resc.num_txqs;
193 req->resc_request.num_rxqs = resp->resc.num_rxqs;
194 req->resc_request.num_sbs = resp->resc.num_sbs;
195 req->resc_request.num_mac_filters =
196 resp->resc.num_mac_filters;
197 req->resc_request.num_vlan_filters =
198 resp->resc.num_vlan_filters;
199
200 /* Clear response buffer */
201 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
202 } else {
203 DP_ERR(p_hwfn,
204 "PF returned error %d to VF acquisition request\n",
205 resp->hdr.status);
206 return -EAGAIN;
207 }
208 }
209
210 /* Update bulletin board size with response from PF */
211 p_iov->bulletin.size = resp->bulletin_size;
212
213 /* get HW info */
214 p_hwfn->cdev->type = resp->pfdev_info.dev_type;
215 p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
216
217 p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
218
219 /* Learn of the possibility of CMT */
220 if (IS_LEAD_HWFN(p_hwfn)) {
221 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
222 DP_NOTICE(p_hwfn, "100g VF\n");
223 p_hwfn->cdev->num_hwfns = 2;
224 }
225 }
226
227 return 0;
228}
229
230int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
231{
232 struct qed_vf_iov *p_iov;
233 u32 reg;
234
235 /* Set number of hwfns - might be overriden once leading hwfn learns
236 * actual configuration from PF.
237 */
238 if (IS_LEAD_HWFN(p_hwfn))
239 p_hwfn->cdev->num_hwfns = 1;
240
241 /* Set the doorbell bar. Assumption: regview is set */
242 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
243 PXP_VF_BAR0_START_DQ;
244
245 reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
246 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
247
248 reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
249 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
250
251 /* Allocate vf sriov info */
252 p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
253 if (!p_iov) {
254 DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_sriov'\n");
255 return -ENOMEM;
256 }
257
258 /* Allocate vf2pf msg */
259 p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
260 sizeof(union vfpf_tlvs),
261 &p_iov->vf2pf_request_phys,
262 GFP_KERNEL);
263 if (!p_iov->vf2pf_request) {
264 DP_NOTICE(p_hwfn,
265 "Failed to allocate `vf2pf_request' DMA memory\n");
266 goto free_p_iov;
267 }
268
269 p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
270 sizeof(union pfvf_tlvs),
271 &p_iov->pf2vf_reply_phys,
272 GFP_KERNEL);
273 if (!p_iov->pf2vf_reply) {
274 DP_NOTICE(p_hwfn,
275 "Failed to allocate `pf2vf_reply' DMA memory\n");
276 goto free_vf2pf_request;
277 }
278
279 DP_VERBOSE(p_hwfn,
280 QED_MSG_IOV,
281 "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
282 p_iov->vf2pf_request,
283 (u64) p_iov->vf2pf_request_phys,
284 p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
285
286 /* Allocate Bulletin board */
287 p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
288 p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
289 p_iov->bulletin.size,
290 &p_iov->bulletin.phys,
291 GFP_KERNEL);
292 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
293 "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
294 p_iov->bulletin.p_virt,
295 (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
296
297 mutex_init(&p_iov->mutex);
298
299 p_hwfn->vf_iov_info = p_iov;
300
301 p_hwfn->hw_info.personality = QED_PCI_ETH;
302
303 return qed_vf_pf_acquire(p_hwfn);
304
305free_vf2pf_request:
306 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
307 sizeof(union vfpf_tlvs),
308 p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
309free_p_iov:
310 kfree(p_iov);
311
312 return -ENOMEM;
313}
314
dacd88d6
YM
315int qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn,
316 u8 rx_qid,
317 u16 sb,
318 u8 sb_index,
319 u16 bd_max_bytes,
320 dma_addr_t bd_chain_phys_addr,
321 dma_addr_t cqe_pbl_addr,
322 u16 cqe_pbl_size, void __iomem **pp_prod)
323{
324 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
325 struct pfvf_start_queue_resp_tlv *resp;
326 struct vfpf_start_rxq_tlv *req;
327 int rc;
328
329 /* clear mailbox and prep first tlv */
330 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
331
332 req->rx_qid = rx_qid;
333 req->cqe_pbl_addr = cqe_pbl_addr;
334 req->cqe_pbl_size = cqe_pbl_size;
335 req->rxq_addr = bd_chain_phys_addr;
336 req->hw_sb = sb;
337 req->sb_index = sb_index;
338 req->bd_max_bytes = bd_max_bytes;
339 req->stat_id = -1;
340
341 /* add list termination tlv */
342 qed_add_tlv(p_hwfn, &p_iov->offset,
343 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
344
345 resp = &p_iov->pf2vf_reply->queue_start;
346 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
347 if (rc)
348 return rc;
349
350 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
351 return -EINVAL;
352
353 /* Learn the address of the producer from the response */
354 if (pp_prod) {
355 u64 init_prod_val = 0;
356
357 *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset;
358 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
359 "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
360 rx_qid, *pp_prod, resp->offset);
361
362 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
363 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u64),
364 (u32 *)&init_prod_val);
365 }
366
367 return rc;
368}
369
370int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn, u16 rx_qid, bool cqe_completion)
371{
372 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
373 struct vfpf_stop_rxqs_tlv *req;
374 struct pfvf_def_resp_tlv *resp;
375 int rc;
376
377 /* clear mailbox and prep first tlv */
378 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
379
380 req->rx_qid = rx_qid;
381 req->num_rxqs = 1;
382 req->cqe_completion = cqe_completion;
383
384 /* add list termination tlv */
385 qed_add_tlv(p_hwfn, &p_iov->offset,
386 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
387
388 resp = &p_iov->pf2vf_reply->default_resp;
389 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
390 if (rc)
391 return rc;
392
393 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
394 return -EINVAL;
395
396 return rc;
397}
398
399int qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn,
400 u16 tx_queue_id,
401 u16 sb,
402 u8 sb_index,
403 dma_addr_t pbl_addr,
404 u16 pbl_size, void __iomem **pp_doorbell)
405{
406 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
407 struct vfpf_start_txq_tlv *req;
408 struct pfvf_def_resp_tlv *resp;
409 int rc;
410
411 /* clear mailbox and prep first tlv */
412 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
413
414 req->tx_qid = tx_queue_id;
415
416 /* Tx */
417 req->pbl_addr = pbl_addr;
418 req->pbl_size = pbl_size;
419 req->hw_sb = sb;
420 req->sb_index = sb_index;
421
422 /* add list termination tlv */
423 qed_add_tlv(p_hwfn, &p_iov->offset,
424 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
425
426 resp = &p_iov->pf2vf_reply->default_resp;
427 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
428 if (rc)
429 return rc;
430
431 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
432 return -EINVAL;
433
434 if (pp_doorbell) {
435 u8 cid = p_iov->acquire_resp.resc.cid[tx_queue_id];
436
437 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
438 qed_db_addr(cid, DQ_DEMS_LEGACY);
439 }
440
441 return rc;
442}
443
444int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, u16 tx_qid)
445{
446 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
447 struct vfpf_stop_txqs_tlv *req;
448 struct pfvf_def_resp_tlv *resp;
449 int rc;
450
451 /* clear mailbox and prep first tlv */
452 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
453
454 req->tx_qid = tx_qid;
455 req->num_txqs = 1;
456
457 /* add list termination tlv */
458 qed_add_tlv(p_hwfn, &p_iov->offset,
459 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
460
461 resp = &p_iov->pf2vf_reply->default_resp;
462 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
463 if (rc)
464 return rc;
465
466 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
467 return -EINVAL;
468
469 return rc;
470}
471
472int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn,
473 u8 vport_id,
474 u16 mtu,
475 u8 inner_vlan_removal,
476 enum qed_tpa_mode tpa_mode,
477 u8 max_buffers_per_cqe)
478{
479 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
480 struct vfpf_vport_start_tlv *req;
481 struct pfvf_def_resp_tlv *resp;
482 int rc, i;
483
484 /* clear mailbox and prep first tlv */
485 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
486
487 req->mtu = mtu;
488 req->vport_id = vport_id;
489 req->inner_vlan_removal = inner_vlan_removal;
490 req->tpa_mode = tpa_mode;
491 req->max_buffers_per_cqe = max_buffers_per_cqe;
492
493 /* status blocks */
494 for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++)
495 if (p_hwfn->sbs_info[i])
496 req->sb_addr[i] = p_hwfn->sbs_info[i]->sb_phys;
497
498 /* add list termination tlv */
499 qed_add_tlv(p_hwfn, &p_iov->offset,
500 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
501
502 resp = &p_iov->pf2vf_reply->default_resp;
503 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
504 if (rc)
505 return rc;
506
507 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
508 return -EINVAL;
509
510 return rc;
511}
512
513int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn)
514{
515 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
516 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
517 int rc;
518
519 /* clear mailbox and prep first tlv */
520 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
521 sizeof(struct vfpf_first_tlv));
522
523 /* add list termination tlv */
524 qed_add_tlv(p_hwfn, &p_iov->offset,
525 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
526
527 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
528 if (rc)
529 return rc;
530
531 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
532 return -EINVAL;
533
534 return rc;
535}
536
537static bool
538qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn,
539 struct qed_sp_vport_update_params *p_data,
540 u16 tlv)
541{
542 switch (tlv) {
543 case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
544 return !!(p_data->update_vport_active_rx_flg ||
545 p_data->update_vport_active_tx_flg);
17b235c1
YM
546 case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
547 return !!p_data->update_tx_switching_flg;
548 case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
549 return !!p_data->update_inner_vlan_removal_flg;
dacd88d6
YM
550 case CHANNEL_TLV_VPORT_UPDATE_MCAST:
551 return !!p_data->update_approx_mcast_flg;
552 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
553 return !!(p_data->accept_flags.update_rx_mode_config ||
554 p_data->accept_flags.update_tx_mode_config);
555 case CHANNEL_TLV_VPORT_UPDATE_RSS:
556 return !!p_data->rss_params;
17b235c1
YM
557 case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
558 return !!p_data->sge_tpa_params;
dacd88d6
YM
559 default:
560 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n",
561 tlv);
562 return false;
563 }
564}
565
566static void
567qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn,
568 struct qed_sp_vport_update_params *p_data)
569{
570 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
571 struct pfvf_def_resp_tlv *p_resp;
572 u16 tlv;
573
574 for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
575 tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) {
576 if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
577 continue;
578
579 p_resp = (struct pfvf_def_resp_tlv *)
580 qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply,
581 tlv);
582 if (p_resp && p_resp->hdr.status)
583 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
584 "TLV[%d] Configuration %s\n",
585 tlv,
586 (p_resp && p_resp->hdr.status) ? "succeeded"
587 : "failed");
588 }
589}
590
591int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn,
592 struct qed_sp_vport_update_params *p_params)
593{
594 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
595 struct vfpf_vport_update_tlv *req;
596 struct pfvf_def_resp_tlv *resp;
597 u8 update_rx, update_tx;
598 u32 resp_size = 0;
599 u16 size, tlv;
600 int rc;
601
602 resp = &p_iov->pf2vf_reply->default_resp;
603 resp_size = sizeof(*resp);
604
605 update_rx = p_params->update_vport_active_rx_flg;
606 update_tx = p_params->update_vport_active_tx_flg;
607
608 /* clear mailbox and prep header tlv */
609 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
610
611 /* Prepare extended tlvs */
612 if (update_rx || update_tx) {
613 struct vfpf_vport_update_activate_tlv *p_act_tlv;
614
615 size = sizeof(struct vfpf_vport_update_activate_tlv);
616 p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
617 CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
618 size);
619 resp_size += sizeof(struct pfvf_def_resp_tlv);
620
621 if (update_rx) {
622 p_act_tlv->update_rx = update_rx;
623 p_act_tlv->active_rx = p_params->vport_active_rx_flg;
624 }
625
626 if (update_tx) {
627 p_act_tlv->update_tx = update_tx;
628 p_act_tlv->active_tx = p_params->vport_active_tx_flg;
629 }
630 }
631
632 if (p_params->update_approx_mcast_flg) {
633 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
634
635 size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
636 p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
637 CHANNEL_TLV_VPORT_UPDATE_MCAST, size);
638 resp_size += sizeof(struct pfvf_def_resp_tlv);
639
640 memcpy(p_mcast_tlv->bins, p_params->bins,
641 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
642 }
643
644 update_rx = p_params->accept_flags.update_rx_mode_config;
645 update_tx = p_params->accept_flags.update_tx_mode_config;
646
647 if (update_rx || update_tx) {
648 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
649
650 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
651 size = sizeof(struct vfpf_vport_update_accept_param_tlv);
652 p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
653 resp_size += sizeof(struct pfvf_def_resp_tlv);
654
655 if (update_rx) {
656 p_accept_tlv->update_rx_mode = update_rx;
657 p_accept_tlv->rx_accept_filter =
658 p_params->accept_flags.rx_accept_filter;
659 }
660
661 if (update_tx) {
662 p_accept_tlv->update_tx_mode = update_tx;
663 p_accept_tlv->tx_accept_filter =
664 p_params->accept_flags.tx_accept_filter;
665 }
666 }
667
668 if (p_params->rss_params) {
669 struct qed_rss_params *rss_params = p_params->rss_params;
670 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
671
672 size = sizeof(struct vfpf_vport_update_rss_tlv);
673 p_rss_tlv = qed_add_tlv(p_hwfn,
674 &p_iov->offset,
675 CHANNEL_TLV_VPORT_UPDATE_RSS, size);
676 resp_size += sizeof(struct pfvf_def_resp_tlv);
677
678 if (rss_params->update_rss_config)
679 p_rss_tlv->update_rss_flags |=
680 VFPF_UPDATE_RSS_CONFIG_FLAG;
681 if (rss_params->update_rss_capabilities)
682 p_rss_tlv->update_rss_flags |=
683 VFPF_UPDATE_RSS_CAPS_FLAG;
684 if (rss_params->update_rss_ind_table)
685 p_rss_tlv->update_rss_flags |=
686 VFPF_UPDATE_RSS_IND_TABLE_FLAG;
687 if (rss_params->update_rss_key)
688 p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
689
690 p_rss_tlv->rss_enable = rss_params->rss_enable;
691 p_rss_tlv->rss_caps = rss_params->rss_caps;
692 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
693 memcpy(p_rss_tlv->rss_ind_table, rss_params->rss_ind_table,
694 sizeof(rss_params->rss_ind_table));
695 memcpy(p_rss_tlv->rss_key, rss_params->rss_key,
696 sizeof(rss_params->rss_key));
697 }
698
699 /* add list termination tlv */
700 qed_add_tlv(p_hwfn, &p_iov->offset,
701 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
702
703 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
704 if (rc)
705 return rc;
706
707 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
708 return -EINVAL;
709
710 qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
711
712 return rc;
713}
714
0b55e27d
YM
715int qed_vf_pf_reset(struct qed_hwfn *p_hwfn)
716{
717 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
718 struct pfvf_def_resp_tlv *resp;
719 struct vfpf_first_tlv *req;
720 int rc;
721
722 /* clear mailbox and prep first tlv */
723 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
724
725 /* add list termination tlv */
726 qed_add_tlv(p_hwfn, &p_iov->offset,
727 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
728
729 resp = &p_iov->pf2vf_reply->default_resp;
730 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
731 if (rc)
732 return rc;
733
734 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
735 return -EAGAIN;
736
737 p_hwfn->b_int_enabled = 0;
738
739 return 0;
740}
741
742int qed_vf_pf_release(struct qed_hwfn *p_hwfn)
743{
744 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
745 struct pfvf_def_resp_tlv *resp;
746 struct vfpf_first_tlv *req;
747 u32 size;
748 int rc;
749
750 /* clear mailbox and prep first tlv */
751 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
752
753 /* add list termination tlv */
754 qed_add_tlv(p_hwfn, &p_iov->offset,
755 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
756
757 resp = &p_iov->pf2vf_reply->default_resp;
758 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
759
760 if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS)
761 rc = -EAGAIN;
762
763 p_hwfn->b_int_enabled = 0;
764
765 if (p_iov->vf2pf_request)
766 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
767 sizeof(union vfpf_tlvs),
768 p_iov->vf2pf_request,
769 p_iov->vf2pf_request_phys);
770 if (p_iov->pf2vf_reply)
771 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
772 sizeof(union pfvf_tlvs),
773 p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
774
775 if (p_iov->bulletin.p_virt) {
776 size = sizeof(struct qed_bulletin_content);
777 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
778 size,
779 p_iov->bulletin.p_virt, p_iov->bulletin.phys);
780 }
781
782 kfree(p_hwfn->vf_iov_info);
783 p_hwfn->vf_iov_info = NULL;
784
785 return rc;
786}
787
dacd88d6
YM
788void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn,
789 struct qed_filter_mcast *p_filter_cmd)
790{
791 struct qed_sp_vport_update_params sp_params;
792 int i;
793
794 memset(&sp_params, 0, sizeof(sp_params));
795 sp_params.update_approx_mcast_flg = 1;
796
797 if (p_filter_cmd->opcode == QED_FILTER_ADD) {
798 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
799 u32 bit;
800
801 bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
802 __set_bit(bit, sp_params.bins);
803 }
804 }
805
806 qed_vf_pf_vport_update(p_hwfn, &sp_params);
807}
808
809int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn,
810 struct qed_filter_ucast *p_ucast)
811{
812 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
813 struct vfpf_ucast_filter_tlv *req;
814 struct pfvf_def_resp_tlv *resp;
815 int rc;
816
817 /* clear mailbox and prep first tlv */
818 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
819 req->opcode = (u8) p_ucast->opcode;
820 req->type = (u8) p_ucast->type;
821 memcpy(req->mac, p_ucast->mac, ETH_ALEN);
822 req->vlan = p_ucast->vlan;
823
824 /* add list termination tlv */
825 qed_add_tlv(p_hwfn, &p_iov->offset,
826 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
827
828 resp = &p_iov->pf2vf_reply->default_resp;
829 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
830 if (rc)
831 return rc;
832
833 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
834 return -EAGAIN;
835
836 return 0;
837}
838
0b55e27d
YM
839int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn)
840{
841 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
842 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
843 int rc;
844
845 /* clear mailbox and prep first tlv */
846 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
847 sizeof(struct vfpf_first_tlv));
848
849 /* add list termination tlv */
850 qed_add_tlv(p_hwfn, &p_iov->offset,
851 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
852
853 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
854 if (rc)
855 return rc;
856
857 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
858 return -EINVAL;
859
860 return 0;
861}
862
1408cc1f
YM
863u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
864{
865 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
866
867 if (!p_iov) {
868 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
869 return 0;
870 }
871
872 return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
873}
874
36558c3d
YM
875int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change)
876{
877 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
878 struct qed_bulletin_content shadow;
879 u32 crc, crc_size;
880
881 crc_size = sizeof(p_iov->bulletin.p_virt->crc);
882 *p_change = 0;
883
884 /* Need to guarantee PF is not in the middle of writing it */
885 memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
886
887 /* If version did not update, no need to do anything */
888 if (shadow.version == p_iov->bulletin_shadow.version)
889 return 0;
890
891 /* Verify the bulletin we see is valid */
892 crc = crc32(0, (u8 *)&shadow + crc_size,
893 p_iov->bulletin.size - crc_size);
894 if (crc != shadow.crc)
895 return -EAGAIN;
896
897 /* Set the shadow bulletin and process it */
898 memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
899
900 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
901 "Read a bulletin update %08x\n", shadow.version);
902
903 *p_change = 1;
904
905 return 0;
906}
907
908void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
909 struct qed_mcp_link_params *p_params,
910 struct qed_bulletin_content *p_bulletin)
911{
912 memset(p_params, 0, sizeof(*p_params));
913
914 p_params->speed.autoneg = p_bulletin->req_autoneg;
915 p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
916 p_params->speed.forced_speed = p_bulletin->req_forced_speed;
917 p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
918 p_params->pause.forced_rx = p_bulletin->req_forced_rx;
919 p_params->pause.forced_tx = p_bulletin->req_forced_tx;
920 p_params->loopback_mode = p_bulletin->req_loopback;
921}
922
923void qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
924 struct qed_mcp_link_params *params)
925{
926 __qed_vf_get_link_params(p_hwfn, params,
927 &(p_hwfn->vf_iov_info->bulletin_shadow));
928}
929
930void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
931 struct qed_mcp_link_state *p_link,
932 struct qed_bulletin_content *p_bulletin)
933{
934 memset(p_link, 0, sizeof(*p_link));
935
936 p_link->link_up = p_bulletin->link_up;
937 p_link->speed = p_bulletin->speed;
938 p_link->full_duplex = p_bulletin->full_duplex;
939 p_link->an = p_bulletin->autoneg;
940 p_link->an_complete = p_bulletin->autoneg_complete;
941 p_link->parallel_detection = p_bulletin->parallel_detection;
942 p_link->pfc_enabled = p_bulletin->pfc_enabled;
943 p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
944 p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
945 p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
946 p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
947 p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
948}
949
950void qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
951 struct qed_mcp_link_state *link)
952{
953 __qed_vf_get_link_state(p_hwfn, link,
954 &(p_hwfn->vf_iov_info->bulletin_shadow));
955}
956
957void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
958 struct qed_mcp_link_capabilities *p_link_caps,
959 struct qed_bulletin_content *p_bulletin)
960{
961 memset(p_link_caps, 0, sizeof(*p_link_caps));
962 p_link_caps->speed_capabilities = p_bulletin->capability_speed;
963}
964
965void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
966 struct qed_mcp_link_capabilities *p_link_caps)
967{
968 __qed_vf_get_link_caps(p_hwfn, p_link_caps,
969 &(p_hwfn->vf_iov_info->bulletin_shadow));
970}
971
1408cc1f
YM
972void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
973{
974 *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
975}
976
977void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
978{
979 memcpy(port_mac,
980 p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
981}
982
983void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
984{
985 struct qed_vf_iov *p_vf;
986
987 p_vf = p_hwfn->vf_iov_info;
988 *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
989}
990
991void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
992 u16 *fw_major, u16 *fw_minor,
993 u16 *fw_rev, u16 *fw_eng)
994{
995 struct pf_vf_pfdev_info *info;
996
997 info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
998
999 *fw_major = info->fw_major;
1000 *fw_minor = info->fw_minor;
1001 *fw_rev = info->fw_rev;
1002 *fw_eng = info->fw_eng;
1003}
36558c3d
YM
1004
1005static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
1006{
1007 /* Always update link configuration according to bulletin */
1008 qed_link_update(hwfn);
1009}
1010
1011void qed_iov_vf_task(struct work_struct *work)
1012{
1013 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
1014 iov_task.work);
1015 u8 change = 0;
1016
1017 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
1018 return;
1019
1020 /* Handle bulletin board changes */
1021 qed_vf_read_bulletin(hwfn, &change);
1022 if (change)
1023 qed_handle_bulletin_change(hwfn);
1024
1025 /* As VF is polling bulletin board, need to constantly re-schedule */
1026 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ);
1027}
This page took 0.068189 seconds and 5 git commands to generate.