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