05ceefd37da14a736ccc2e522bda3e6385dc5b47
[dpdk.git] / drivers / net / qede / base / ecore_vf.c
1 /*
2  * Copyright (c) 2016 QLogic Corporation.
3  * All rights reserved.
4  * www.qlogic.com
5  *
6  * See LICENSE.qede_pmd for copyright and licensing details.
7  */
8
9 #include "bcm_osal.h"
10 #include "ecore.h"
11 #include "ecore_hsi_eth.h"
12 #include "ecore_sriov.h"
13 #include "ecore_l2_api.h"
14 #include "ecore_vf.h"
15 #include "ecore_vfpf_if.h"
16 #include "ecore_status.h"
17 #include "reg_addr.h"
18 #include "ecore_int.h"
19 #include "ecore_l2.h"
20 #include "ecore_mcp_api.h"
21 #include "ecore_vf_api.h"
22
23 static void *ecore_vf_pf_prep(struct ecore_hwfn *p_hwfn, u16 type, u16 length)
24 {
25         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
26         void *p_tlv;
27
28         /* This lock is released when we receive PF's response
29          * in ecore_send_msg2pf().
30          * So, ecore_vf_pf_prep() and ecore_send_msg2pf()
31          * must come in sequence.
32          */
33         OSAL_MUTEX_ACQUIRE(&p_iov->mutex);
34
35         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
36                    "preparing to send %s tlv over vf pf channel\n",
37                    ecore_channel_tlvs_string[type]);
38
39         /* Reset Request offset */
40         p_iov->offset = (u8 *)(p_iov->vf2pf_request);
41
42         /* Clear mailbox - both request and reply */
43         OSAL_MEMSET(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
44         OSAL_MEMSET(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
45
46         /* Init type and length */
47         p_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset, type, length);
48
49         /* Init first tlv header */
50         ((struct vfpf_first_tlv *)p_tlv)->reply_address =
51             (u64)p_iov->pf2vf_reply_phys;
52
53         return p_tlv;
54 }
55
56 static void ecore_vf_pf_req_end(struct ecore_hwfn *p_hwfn,
57                                  enum _ecore_status_t req_status)
58 {
59         union pfvf_tlvs *resp = p_hwfn->vf_iov_info->pf2vf_reply;
60
61         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
62                    "VF request status = 0x%x, PF reply status = 0x%x\n",
63                    req_status, resp->default_resp.hdr.status);
64
65         OSAL_MUTEX_RELEASE(&p_hwfn->vf_iov_info->mutex);
66 }
67
68 static enum _ecore_status_t
69 ecore_send_msg2pf(struct ecore_hwfn *p_hwfn,
70                   u8 *done, u32 resp_size)
71 {
72         union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
73         struct ustorm_trigger_vf_zone trigger;
74         struct ustorm_vf_zone *zone_data;
75         enum _ecore_status_t rc = ECORE_SUCCESS;
76         int time = 100;
77
78         zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
79
80         /* output tlvs list */
81         ecore_dp_tlv_list(p_hwfn, p_req);
82
83         /* need to add the END TLV to the message size */
84         resp_size += sizeof(struct channel_list_end_tlv);
85
86         /* Send TLVs over HW channel */
87         OSAL_MEMSET(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
88         trigger.vf_pf_msg_valid = 1;
89
90         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
91                    "VF -> PF [%02x] message: [%08x, %08x] --> %p,"
92                    " %08x --> %p\n",
93                    GET_FIELD(p_hwfn->hw_info.concrete_fid,
94                              PXP_CONCRETE_FID_PFID),
95                    U64_HI(p_hwfn->vf_iov_info->vf2pf_request_phys),
96                    U64_LO(p_hwfn->vf_iov_info->vf2pf_request_phys),
97                    &zone_data->non_trigger.vf_pf_msg_addr,
98                    *((u32 *)&trigger), &zone_data->trigger);
99
100         REG_WR(p_hwfn,
101                (osal_uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
102                U64_LO(p_hwfn->vf_iov_info->vf2pf_request_phys));
103
104         REG_WR(p_hwfn,
105                (osal_uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
106                U64_HI(p_hwfn->vf_iov_info->vf2pf_request_phys));
107
108         /* The message data must be written first, to prevent trigger before
109          * data is written.
110          */
111         OSAL_WMB(p_hwfn->p_dev);
112
113         REG_WR(p_hwfn, (osal_uintptr_t)&zone_data->trigger,
114                *((u32 *)&trigger));
115
116         /* When PF would be done with the response, it would write back to the
117          * `done' address. Poll until then.
118          */
119         while ((!*done) && time) {
120                 OSAL_MSLEEP(25);
121                 time--;
122         }
123
124         if (!*done) {
125                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
126                            "VF <-- PF Timeout [Type %d]\n",
127                            p_req->first_tlv.tl.type);
128                 rc = ECORE_TIMEOUT;
129         } else {
130                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
131                            "PF response: %d [Type %d]\n",
132                            *done, p_req->first_tlv.tl.type);
133         }
134
135         return rc;
136 }
137
138 #define VF_ACQUIRE_THRESH 3
139 static void ecore_vf_pf_acquire_reduce_resc(struct ecore_hwfn *p_hwfn,
140                                             struct vf_pf_resc_request *p_req,
141                                             struct pf_vf_resc *p_resp)
142 {
143         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
144                    "PF unwilling to fullill resource request: rxq [%02x/%02x]"
145                    " txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x]"
146                    " vlan [%02x/%02x] mc [%02x/%02x]."
147                    " Try PF recommended amount\n",
148                    p_req->num_rxqs, p_resp->num_rxqs,
149                    p_req->num_rxqs, p_resp->num_txqs,
150                    p_req->num_sbs, p_resp->num_sbs,
151                    p_req->num_mac_filters, p_resp->num_mac_filters,
152                    p_req->num_vlan_filters, p_resp->num_vlan_filters,
153                    p_req->num_mc_filters, p_resp->num_mc_filters);
154
155         /* humble our request */
156         p_req->num_txqs = p_resp->num_txqs;
157         p_req->num_rxqs = p_resp->num_rxqs;
158         p_req->num_sbs = p_resp->num_sbs;
159         p_req->num_mac_filters = p_resp->num_mac_filters;
160         p_req->num_vlan_filters = p_resp->num_vlan_filters;
161         p_req->num_mc_filters = p_resp->num_mc_filters;
162 }
163
164 static enum _ecore_status_t ecore_vf_pf_acquire(struct ecore_hwfn *p_hwfn)
165 {
166         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
167         struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
168         struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
169         struct ecore_vf_acquire_sw_info vf_sw_info;
170         struct vf_pf_resc_request *p_resc;
171         bool resources_acquired = false;
172         struct vfpf_acquire_tlv *req;
173         int attempts = 0;
174         enum _ecore_status_t rc = ECORE_SUCCESS;
175
176         /* clear mailbox and prep first tlv */
177         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
178         p_resc = &req->resc_request;
179
180         /* @@@ TBD: PF may not be ready bnx2x_get_vf_id... */
181         req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
182
183         p_resc->num_rxqs = ECORE_MAX_VF_CHAINS_PER_PF;
184         p_resc->num_txqs = ECORE_MAX_VF_CHAINS_PER_PF;
185         p_resc->num_sbs = ECORE_MAX_VF_CHAINS_PER_PF;
186         p_resc->num_mac_filters = ECORE_ETH_VF_NUM_MAC_FILTERS;
187         p_resc->num_vlan_filters = ECORE_ETH_VF_NUM_VLAN_FILTERS;
188
189         OSAL_MEMSET(&vf_sw_info, 0, sizeof(vf_sw_info));
190         OSAL_VF_FILL_ACQUIRE_RESC_REQ(p_hwfn, &req->resc_request, &vf_sw_info);
191
192         req->vfdev_info.os_type = vf_sw_info.os_type;
193         req->vfdev_info.driver_version = vf_sw_info.driver_version;
194         req->vfdev_info.fw_major = FW_MAJOR_VERSION;
195         req->vfdev_info.fw_minor = FW_MINOR_VERSION;
196         req->vfdev_info.fw_revision = FW_REVISION_VERSION;
197         req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
198         req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
199         req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR;
200
201         /* Fill capability field with any non-deprecated config we support */
202         req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
203
204         /* pf 2 vf bulletin board address */
205         req->bulletin_addr = p_iov->bulletin.phys;
206         req->bulletin_size = p_iov->bulletin.size;
207
208         /* add list termination tlv */
209         ecore_add_tlv(p_hwfn, &p_iov->offset,
210                       CHANNEL_TLV_LIST_END,
211                       sizeof(struct channel_list_end_tlv));
212
213         while (!resources_acquired) {
214                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
215                            "attempting to acquire resources\n");
216
217                 /* Clear response buffer, as this might be a re-send */
218                 OSAL_MEMSET(p_iov->pf2vf_reply, 0,
219                             sizeof(union pfvf_tlvs));
220
221                 /* send acquire request */
222                 rc = ecore_send_msg2pf(p_hwfn,
223                                        &resp->hdr.status, sizeof(*resp));
224
225                 /* PF timeout */
226                 if (rc)
227                         return rc;
228
229                 /* copy acquire response from buffer to p_hwfn */
230                 OSAL_MEMCPY(&p_iov->acquire_resp,
231                             resp, sizeof(p_iov->acquire_resp));
232
233                 attempts++;
234
235                 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
236                         /* PF agrees to allocate our resources */
237                         if (!(resp->pfdev_info.capabilities &
238                               PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
239                                 /* It's possible legacy PF mistakenly accepted;
240                                  * but we don't care - simply mark it as
241                                  * legacy and continue.
242                                  */
243                                 req->vfdev_info.capabilities |=
244                                         VFPF_ACQUIRE_CAP_PRE_FP_HSI;
245                         }
246                         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
247                                    "resources acquired\n");
248                         resources_acquired = true;
249                 } /* PF refuses to allocate our resources */
250                 else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
251                          attempts < VF_ACQUIRE_THRESH) {
252                         ecore_vf_pf_acquire_reduce_resc(p_hwfn, p_resc,
253                                                         &resp->resc);
254
255                 } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) {
256                         if (pfdev_info->major_fp_hsi &&
257                             (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) {
258                                 DP_NOTICE(p_hwfn, false,
259                                           "PF uses an incompatible fastpath HSI"
260                                           " %02x.%02x [VF requires %02x.%02x]."
261                                           " Please change to a VF driver using"
262                                           " %02x.xx.\n",
263                                           pfdev_info->major_fp_hsi,
264                                           pfdev_info->minor_fp_hsi,
265                                           ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR,
266                                           pfdev_info->major_fp_hsi);
267                                 rc = ECORE_INVAL;
268                                 goto exit;
269                         }
270
271                         if (!pfdev_info->major_fp_hsi) {
272                                 if (req->vfdev_info.capabilities &
273                                     VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
274                                         DP_NOTICE(p_hwfn, false,
275                                                   "PF uses very old drivers."
276                                                   " Please change to a VF"
277                                                   " driver using no later than"
278                                                   " 8.8.x.x.\n");
279                                         rc = ECORE_INVAL;
280                                         goto exit;
281                                 } else {
282                                         DP_INFO(p_hwfn,
283                                                 "PF is old - try re-acquire to"
284                                                 " see if it supports FW-version"
285                                                 " override\n");
286                                         req->vfdev_info.capabilities |=
287                                                 VFPF_ACQUIRE_CAP_PRE_FP_HSI;
288                                         continue;
289                                 }
290                         }
291
292                         /* If PF/VF are using same Major, PF must have had
293                          * it's reasons. Simply fail.
294                          */
295                         DP_NOTICE(p_hwfn, false,
296                                   "PF rejected acquisition by VF\n");
297                         rc = ECORE_INVAL;
298                         goto exit;
299                 } else {
300                         DP_ERR(p_hwfn,
301                                "PF returned err %d to VF acquisition request\n",
302                                resp->hdr.status);
303                         rc = ECORE_AGAIN;
304                         goto exit;
305                 }
306         }
307
308         /* Mark the PF as legacy, if needed */
309         if (req->vfdev_info.capabilities &
310             VFPF_ACQUIRE_CAP_PRE_FP_HSI)
311                 p_iov->b_pre_fp_hsi = true;
312
313         rc = OSAL_VF_UPDATE_ACQUIRE_RESC_RESP(p_hwfn, &resp->resc);
314         if (rc) {
315                 DP_NOTICE(p_hwfn, true,
316                           "VF_UPDATE_ACQUIRE_RESC_RESP Failed:"
317                           " status = 0x%x.\n",
318                           rc);
319                 rc = ECORE_AGAIN;
320                 goto exit;
321         }
322
323         /* Update bulletin board size with response from PF */
324         p_iov->bulletin.size = resp->bulletin_size;
325
326         /* get HW info */
327         p_hwfn->p_dev->type = resp->pfdev_info.dev_type;
328         p_hwfn->p_dev->chip_rev = resp->pfdev_info.chip_rev;
329
330         DP_INFO(p_hwfn, "Chip details - %s%d\n",
331                 ECORE_IS_BB(p_hwfn->p_dev) ? "BB" : "AH",
332                 CHIP_REV_IS_A0(p_hwfn->p_dev) ? 0 : 1);
333
334         p_hwfn->p_dev->chip_num = pfdev_info->chip_num & 0xffff;
335
336         /* Learn of the possibility of CMT */
337         if (IS_LEAD_HWFN(p_hwfn)) {
338                 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
339                         DP_INFO(p_hwfn, "100g VF\n");
340                         p_hwfn->p_dev->num_hwfns = 2;
341                 }
342         }
343
344         /* @DPDK */
345         if ((~p_iov->b_pre_fp_hsi &
346             ETH_HSI_VER_MINOR) &&
347             (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR))
348                 DP_INFO(p_hwfn,
349                         "PF is using older fastpath HSI;"
350                         " %02x.%02x is configured\n",
351                         ETH_HSI_VER_MAJOR,
352                         resp->pfdev_info.minor_fp_hsi);
353
354 exit:
355         ecore_vf_pf_req_end(p_hwfn, rc);
356
357         return rc;
358 }
359
360 enum _ecore_status_t ecore_vf_hw_prepare(struct ecore_hwfn *p_hwfn)
361 {
362         struct ecore_vf_iov *p_iov;
363         u32 reg;
364
365         /* Set number of hwfns - might be overridden once leading hwfn learns
366          * actual configuration from PF.
367          */
368         if (IS_LEAD_HWFN(p_hwfn))
369                 p_hwfn->p_dev->num_hwfns = 1;
370
371         /* Set the doorbell bar. Assumption: regview is set */
372         p_hwfn->doorbells = (u8 OSAL_IOMEM *)p_hwfn->regview +
373             PXP_VF_BAR0_START_DQ;
374
375         reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
376         p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
377
378         reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
379         p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
380
381         /* Allocate vf sriov info */
382         p_iov = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_iov));
383         if (!p_iov) {
384                 DP_NOTICE(p_hwfn, true,
385                           "Failed to allocate `struct ecore_sriov'\n");
386                 return ECORE_NOMEM;
387         }
388
389         /* Allocate vf2pf msg */
390         p_iov->vf2pf_request = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
391                                                          &p_iov->
392                                                          vf2pf_request_phys,
393                                                          sizeof(union
394                                                                 vfpf_tlvs));
395         if (!p_iov->vf2pf_request) {
396                 DP_NOTICE(p_hwfn, true,
397                          "Failed to allocate `vf2pf_request' DMA memory\n");
398                 goto free_p_iov;
399         }
400
401         p_iov->pf2vf_reply = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
402                                                        &p_iov->
403                                                        pf2vf_reply_phys,
404                                                        sizeof(union pfvf_tlvs));
405         if (!p_iov->pf2vf_reply) {
406                 DP_NOTICE(p_hwfn, true,
407                           "Failed to allocate `pf2vf_reply' DMA memory\n");
408                 goto free_vf2pf_request;
409         }
410
411         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
412                    "VF's Request mailbox [%p virt 0x%lx phys], "
413                    "Response mailbox [%p virt 0x%lx phys]\n",
414                    p_iov->vf2pf_request,
415                    (unsigned long)p_iov->vf2pf_request_phys,
416                    p_iov->pf2vf_reply,
417                    (unsigned long)p_iov->pf2vf_reply_phys);
418
419         /* Allocate Bulletin board */
420         p_iov->bulletin.size = sizeof(struct ecore_bulletin_content);
421         p_iov->bulletin.p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
422                                                            &p_iov->bulletin.
423                                                            phys,
424                                                            p_iov->bulletin.
425                                                            size);
426         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
427                    "VF's bulletin Board [%p virt 0x%lx phys 0x%08x bytes]\n",
428                    p_iov->bulletin.p_virt, (unsigned long)p_iov->bulletin.phys,
429                    p_iov->bulletin.size);
430
431         OSAL_MUTEX_ALLOC(p_hwfn, &p_iov->mutex);
432         OSAL_MUTEX_INIT(&p_iov->mutex);
433
434         p_hwfn->vf_iov_info = p_iov;
435
436         p_hwfn->hw_info.personality = ECORE_PCI_ETH;
437
438         return ecore_vf_pf_acquire(p_hwfn);
439
440 free_vf2pf_request:
441         OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev, p_iov->vf2pf_request,
442                                p_iov->vf2pf_request_phys,
443                                sizeof(union vfpf_tlvs));
444 free_p_iov:
445         OSAL_FREE(p_hwfn->p_dev, p_iov);
446
447         return ECORE_NOMEM;
448 }
449
450 #define TSTORM_QZONE_START   PXP_VF_BAR0_START_SDM_ZONE_A
451 #define MSTORM_QZONE_START(dev)   (TSTORM_QZONE_START + \
452                                    (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
453
454 enum _ecore_status_t ecore_vf_pf_rxq_start(struct ecore_hwfn *p_hwfn,
455                                            u8 rx_qid,
456                                            u16 sb,
457                                            u8 sb_index,
458                                            u16 bd_max_bytes,
459                                            dma_addr_t bd_chain_phys_addr,
460                                            dma_addr_t cqe_pbl_addr,
461                                            u16 cqe_pbl_size,
462                                            void OSAL_IOMEM **pp_prod)
463 {
464         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
465         struct pfvf_start_queue_resp_tlv *resp;
466         struct vfpf_start_rxq_tlv *req;
467         enum _ecore_status_t rc;
468
469         /* clear mailbox and prep first tlv */
470         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
471
472         req->rx_qid = rx_qid;
473         req->cqe_pbl_addr = cqe_pbl_addr;
474         req->cqe_pbl_size = cqe_pbl_size;
475         req->rxq_addr = bd_chain_phys_addr;
476         req->hw_sb = sb;
477         req->sb_index = sb_index;
478         req->bd_max_bytes = bd_max_bytes;
479         req->stat_id = -1; /* Keep initialized, for future compatibility */
480
481         /* If PF is legacy, we'll need to calculate producers ourselves
482          * as well as clean them.
483          */
484         if (pp_prod && p_iov->b_pre_fp_hsi) {
485                 u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
486                 u32 init_prod_val = 0;
487
488                 *pp_prod = (u8 OSAL_IOMEM *)p_hwfn->regview +
489                            MSTORM_QZONE_START(p_hwfn->p_dev) +
490                            (hw_qid) * MSTORM_QZONE_SIZE;
491
492                 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
493                 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
494                                   (u32 *)(&init_prod_val));
495         }
496
497         /* add list termination tlv */
498         ecore_add_tlv(p_hwfn, &p_iov->offset,
499                       CHANNEL_TLV_LIST_END,
500                       sizeof(struct channel_list_end_tlv));
501
502         resp = &p_iov->pf2vf_reply->queue_start;
503         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
504         if (rc)
505                 goto exit;
506
507         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
508                 rc = ECORE_INVAL;
509                 goto exit;
510         }
511
512         /* Learn the address of the producer from the response */
513         if (pp_prod && !p_iov->b_pre_fp_hsi) {
514                 u32 init_prod_val = 0;
515
516                 *pp_prod = (u8 OSAL_IOMEM *)p_hwfn->regview + resp->offset;
517                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
518                            "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
519                            rx_qid, *pp_prod, resp->offset);
520
521                 /* Init the rcq, rx bd and rx sge (if valid) producers to 0.
522                  * It was actually the PF's responsibility, but since some
523                  * old PFs might fail to do so, we do this as well.
524                  */
525                 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
526                 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
527                                   (u32 *)&init_prod_val);
528         }
529
530 exit:
531         ecore_vf_pf_req_end(p_hwfn, rc);
532
533         return rc;
534 }
535
536 enum _ecore_status_t ecore_vf_pf_rxq_stop(struct ecore_hwfn *p_hwfn,
537                                           u16 rx_qid, bool cqe_completion)
538 {
539         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
540         struct vfpf_stop_rxqs_tlv *req;
541         struct pfvf_def_resp_tlv *resp;
542         enum _ecore_status_t rc;
543
544         /* clear mailbox and prep first tlv */
545         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
546
547         req->rx_qid = rx_qid;
548         req->num_rxqs = 1;
549         req->cqe_completion = cqe_completion;
550
551         /* add list termination tlv */
552         ecore_add_tlv(p_hwfn, &p_iov->offset,
553                       CHANNEL_TLV_LIST_END,
554                       sizeof(struct channel_list_end_tlv));
555
556         resp = &p_iov->pf2vf_reply->default_resp;
557         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
558         if (rc)
559                 goto exit;
560
561         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
562                 rc = ECORE_INVAL;
563                 goto exit;
564         }
565
566 exit:
567         ecore_vf_pf_req_end(p_hwfn, rc);
568
569         return rc;
570 }
571
572 enum _ecore_status_t ecore_vf_pf_txq_start(struct ecore_hwfn *p_hwfn,
573                                            u16 tx_queue_id,
574                                            u16 sb,
575                                            u8 sb_index,
576                                            dma_addr_t pbl_addr,
577                                            u16 pbl_size,
578                                            void OSAL_IOMEM **pp_doorbell)
579 {
580         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
581         struct pfvf_start_queue_resp_tlv *resp;
582         struct vfpf_start_txq_tlv *req;
583         enum _ecore_status_t rc;
584
585         /* clear mailbox and prep first tlv */
586         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
587
588         req->tx_qid = tx_queue_id;
589
590         /* Tx */
591         req->pbl_addr = pbl_addr;
592         req->pbl_size = pbl_size;
593         req->hw_sb = sb;
594         req->sb_index = sb_index;
595
596         /* add list termination tlv */
597         ecore_add_tlv(p_hwfn, &p_iov->offset,
598                       CHANNEL_TLV_LIST_END,
599                       sizeof(struct channel_list_end_tlv));
600
601         resp  = &p_iov->pf2vf_reply->queue_start;
602         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
603         if (rc)
604                 goto exit;
605
606         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
607                 rc = ECORE_INVAL;
608                 goto exit;
609         }
610
611         if (pp_doorbell) {
612                 /* Modern PFs provide the actual offsets, while legacy
613                  * provided only the queue id.
614                  */
615                 if (!p_iov->b_pre_fp_hsi) {
616                         *pp_doorbell = (u8 OSAL_IOMEM *)p_hwfn->doorbells +
617                                                        resp->offset;
618                 } else {
619                         u8 cid = p_iov->acquire_resp.resc.cid[tx_queue_id];
620
621                 *pp_doorbell = (u8 OSAL_IOMEM *)p_hwfn->doorbells +
622                                 DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
623                 }
624
625                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
626                            "Txq[0x%02x]: doorbell at %p [offset 0x%08x]\n",
627                            tx_queue_id, *pp_doorbell, resp->offset);
628         }
629
630 exit:
631         ecore_vf_pf_req_end(p_hwfn, rc);
632
633         return rc;
634 }
635
636 enum _ecore_status_t ecore_vf_pf_txq_stop(struct ecore_hwfn *p_hwfn, u16 tx_qid)
637 {
638         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
639         struct vfpf_stop_txqs_tlv *req;
640         struct pfvf_def_resp_tlv *resp;
641         enum _ecore_status_t rc;
642
643         /* clear mailbox and prep first tlv */
644         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
645
646         req->tx_qid = tx_qid;
647         req->num_txqs = 1;
648
649         /* add list termination tlv */
650         ecore_add_tlv(p_hwfn, &p_iov->offset,
651                       CHANNEL_TLV_LIST_END,
652                       sizeof(struct channel_list_end_tlv));
653
654         resp = &p_iov->pf2vf_reply->default_resp;
655         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
656         if (rc)
657                 goto exit;
658
659         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
660                 rc = ECORE_INVAL;
661                 goto exit;
662         }
663
664 exit:
665         ecore_vf_pf_req_end(p_hwfn, rc);
666
667         return rc;
668 }
669
670 enum _ecore_status_t ecore_vf_pf_rxqs_update(struct ecore_hwfn *p_hwfn,
671                                              u16 rx_queue_id,
672                                              u8 num_rxqs,
673                                              u8 comp_cqe_flg, u8 comp_event_flg)
674 {
675         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
676         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
677         struct vfpf_update_rxq_tlv *req;
678         enum _ecore_status_t rc;
679
680         /* clear mailbox and prep first tlv */
681         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_RXQ, sizeof(*req));
682
683         req->rx_qid = rx_queue_id;
684         req->num_rxqs = num_rxqs;
685
686         if (comp_cqe_flg)
687                 req->flags |= VFPF_RXQ_UPD_COMPLETE_CQE_FLAG;
688         if (comp_event_flg)
689                 req->flags |= VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG;
690
691         /* add list termination tlv */
692         ecore_add_tlv(p_hwfn, &p_iov->offset,
693                       CHANNEL_TLV_LIST_END,
694                       sizeof(struct channel_list_end_tlv));
695
696         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
697         if (rc)
698                 goto exit;
699
700         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
701                 rc = ECORE_INVAL;
702                 goto exit;
703         }
704
705 exit:
706         ecore_vf_pf_req_end(p_hwfn, rc);
707
708         return rc;
709 }
710
711 enum _ecore_status_t
712 ecore_vf_pf_vport_start(struct ecore_hwfn *p_hwfn, u8 vport_id,
713                         u16 mtu, u8 inner_vlan_removal,
714                         enum ecore_tpa_mode tpa_mode, u8 max_buffers_per_cqe,
715                         u8 only_untagged)
716 {
717         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
718         struct vfpf_vport_start_tlv *req;
719         struct pfvf_def_resp_tlv *resp;
720         enum _ecore_status_t rc;
721         int i;
722
723         /* clear mailbox and prep first tlv */
724         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
725
726         req->mtu = mtu;
727         req->vport_id = vport_id;
728         req->inner_vlan_removal = inner_vlan_removal;
729         req->tpa_mode = tpa_mode;
730         req->max_buffers_per_cqe = max_buffers_per_cqe;
731         req->only_untagged = only_untagged;
732
733         /* status blocks */
734         for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++)
735                 if (p_hwfn->sbs_info[i])
736                         req->sb_addr[i] = p_hwfn->sbs_info[i]->sb_phys;
737
738         /* add list termination tlv */
739         ecore_add_tlv(p_hwfn, &p_iov->offset,
740                       CHANNEL_TLV_LIST_END,
741                       sizeof(struct channel_list_end_tlv));
742
743         resp  = &p_iov->pf2vf_reply->default_resp;
744         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
745         if (rc)
746                 goto exit;
747
748         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
749                 rc = ECORE_INVAL;
750                 goto exit;
751         }
752
753 exit:
754         ecore_vf_pf_req_end(p_hwfn, rc);
755
756         return rc;
757 }
758
759 enum _ecore_status_t ecore_vf_pf_vport_stop(struct ecore_hwfn *p_hwfn)
760 {
761         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
762         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
763         enum _ecore_status_t rc;
764
765         /* clear mailbox and prep first tlv */
766         ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
767                          sizeof(struct vfpf_first_tlv));
768
769         /* add list termination tlv */
770         ecore_add_tlv(p_hwfn, &p_iov->offset,
771                       CHANNEL_TLV_LIST_END,
772                       sizeof(struct channel_list_end_tlv));
773
774         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
775         if (rc)
776                 goto exit;
777
778         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
779                 rc = ECORE_INVAL;
780                 goto exit;
781         }
782
783 exit:
784         ecore_vf_pf_req_end(p_hwfn, rc);
785
786         return rc;
787 }
788
789 static bool
790 ecore_vf_handle_vp_update_is_needed(struct ecore_hwfn *p_hwfn,
791                                     struct ecore_sp_vport_update_params *p_data,
792                                     u16 tlv)
793 {
794         switch (tlv) {
795         case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
796                 return !!(p_data->update_vport_active_rx_flg ||
797                           p_data->update_vport_active_tx_flg);
798         case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
799 #ifndef ASIC_ONLY
800                 /* FPGA doesn't have PVFC and so can't support tx-switching */
801                 return !!(p_data->update_tx_switching_flg &&
802                           !CHIP_REV_IS_FPGA(p_hwfn->p_dev));
803 #else
804                 return !!p_data->update_tx_switching_flg;
805 #endif
806         case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
807                 return !!p_data->update_inner_vlan_removal_flg;
808         case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
809                 return !!p_data->update_accept_any_vlan_flg;
810         case CHANNEL_TLV_VPORT_UPDATE_MCAST:
811                 return !!p_data->update_approx_mcast_flg;
812         case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
813                 return !!(p_data->accept_flags.update_rx_mode_config ||
814                           p_data->accept_flags.update_tx_mode_config);
815         case CHANNEL_TLV_VPORT_UPDATE_RSS:
816                 return !!p_data->rss_params;
817         case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
818                 return !!p_data->sge_tpa_params;
819         default:
820                 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d] %s\n",
821                         tlv, ecore_channel_tlvs_string[tlv]);
822                 return false;
823         }
824 }
825
826 static void
827 ecore_vf_handle_vp_update_tlvs_resp(struct ecore_hwfn *p_hwfn,
828                                     struct ecore_sp_vport_update_params *p_data)
829 {
830         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
831         struct pfvf_def_resp_tlv *p_resp;
832         u16 tlv;
833
834         for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
835              tlv < CHANNEL_TLV_VPORT_UPDATE_MAX;
836              tlv++) {
837                 if (!ecore_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
838                         continue;
839
840                 p_resp = (struct pfvf_def_resp_tlv *)
841                     ecore_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply, tlv);
842                 if (p_resp && p_resp->hdr.status)
843                         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
844                                    "TLV[%d] type %s Configuration %s\n",
845                                    tlv, ecore_channel_tlvs_string[tlv],
846                                    (p_resp && p_resp->hdr.status) ? "succeeded"
847                                                                   : "failed");
848         }
849 }
850
851 enum _ecore_status_t
852 ecore_vf_pf_vport_update(struct ecore_hwfn *p_hwfn,
853                          struct ecore_sp_vport_update_params *p_params)
854 {
855         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
856         struct vfpf_vport_update_tlv *req;
857         struct pfvf_def_resp_tlv *resp;
858         u8 update_rx, update_tx;
859         u32 resp_size = 0;
860         u16 size, tlv;
861         enum _ecore_status_t rc;
862
863         resp = &p_iov->pf2vf_reply->default_resp;
864         resp_size = sizeof(*resp);
865
866         update_rx = p_params->update_vport_active_rx_flg;
867         update_tx = p_params->update_vport_active_tx_flg;
868
869         /* clear mailbox and prep header tlv */
870         ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
871
872         /* Prepare extended tlvs */
873         if (update_rx || update_tx) {
874                 struct vfpf_vport_update_activate_tlv *p_act_tlv;
875
876                 size = sizeof(struct vfpf_vport_update_activate_tlv);
877                 p_act_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
878                                           CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
879                                           size);
880                 resp_size += sizeof(struct pfvf_def_resp_tlv);
881
882                 if (update_rx) {
883                         p_act_tlv->update_rx = update_rx;
884                         p_act_tlv->active_rx = p_params->vport_active_rx_flg;
885                 }
886
887                 if (update_tx) {
888                         p_act_tlv->update_tx = update_tx;
889                         p_act_tlv->active_tx = p_params->vport_active_tx_flg;
890                 }
891         }
892
893         if (p_params->update_inner_vlan_removal_flg) {
894                 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
895
896                 size = sizeof(struct vfpf_vport_update_vlan_strip_tlv);
897                 p_vlan_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
898                                            CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP,
899                                            size);
900                 resp_size += sizeof(struct pfvf_def_resp_tlv);
901
902                 p_vlan_tlv->remove_vlan = p_params->inner_vlan_removal_flg;
903         }
904
905         if (p_params->update_tx_switching_flg) {
906                 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
907
908                 size = sizeof(struct vfpf_vport_update_tx_switch_tlv);
909                 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
910                 p_tx_switch_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
911                                                 tlv, size);
912                 resp_size += sizeof(struct pfvf_def_resp_tlv);
913
914                 p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg;
915         }
916
917         if (p_params->update_approx_mcast_flg) {
918                 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
919
920                 size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
921                 p_mcast_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
922                                             CHANNEL_TLV_VPORT_UPDATE_MCAST,
923                                             size);
924                 resp_size += sizeof(struct pfvf_def_resp_tlv);
925
926                 OSAL_MEMCPY(p_mcast_tlv->bins, p_params->bins,
927                             sizeof(unsigned long) *
928                             ETH_MULTICAST_MAC_BINS_IN_REGS);
929         }
930
931         update_rx = p_params->accept_flags.update_rx_mode_config;
932         update_tx = p_params->accept_flags.update_tx_mode_config;
933
934         if (update_rx || update_tx) {
935                 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
936
937                 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
938                 size = sizeof(struct vfpf_vport_update_accept_param_tlv);
939                 p_accept_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
940                 resp_size += sizeof(struct pfvf_def_resp_tlv);
941
942                 if (update_rx) {
943                         p_accept_tlv->update_rx_mode = update_rx;
944                         p_accept_tlv->rx_accept_filter =
945                             p_params->accept_flags.rx_accept_filter;
946                 }
947
948                 if (update_tx) {
949                         p_accept_tlv->update_tx_mode = update_tx;
950                         p_accept_tlv->tx_accept_filter =
951                             p_params->accept_flags.tx_accept_filter;
952                 }
953         }
954
955         if (p_params->rss_params) {
956                 struct ecore_rss_params *rss_params = p_params->rss_params;
957                 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
958
959                 size = sizeof(struct vfpf_vport_update_rss_tlv);
960                 p_rss_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
961                                           CHANNEL_TLV_VPORT_UPDATE_RSS, size);
962                 resp_size += sizeof(struct pfvf_def_resp_tlv);
963
964                 if (rss_params->update_rss_config)
965                         p_rss_tlv->update_rss_flags |=
966                             VFPF_UPDATE_RSS_CONFIG_FLAG;
967                 if (rss_params->update_rss_capabilities)
968                         p_rss_tlv->update_rss_flags |=
969                             VFPF_UPDATE_RSS_CAPS_FLAG;
970                 if (rss_params->update_rss_ind_table)
971                         p_rss_tlv->update_rss_flags |=
972                             VFPF_UPDATE_RSS_IND_TABLE_FLAG;
973                 if (rss_params->update_rss_key)
974                         p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
975
976                 p_rss_tlv->rss_enable = rss_params->rss_enable;
977                 p_rss_tlv->rss_caps = rss_params->rss_caps;
978                 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
979                 OSAL_MEMCPY(p_rss_tlv->rss_ind_table, rss_params->rss_ind_table,
980                             sizeof(rss_params->rss_ind_table));
981                 OSAL_MEMCPY(p_rss_tlv->rss_key, rss_params->rss_key,
982                             sizeof(rss_params->rss_key));
983         }
984
985         if (p_params->update_accept_any_vlan_flg) {
986                 struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
987
988                 size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
989                 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
990                 p_any_vlan_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
991                                                tlv, size);
992
993                 resp_size += sizeof(struct pfvf_def_resp_tlv);
994                 p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
995                 p_any_vlan_tlv->update_accept_any_vlan_flg =
996                     p_params->update_accept_any_vlan_flg;
997         }
998
999         if (p_params->sge_tpa_params) {
1000                 struct ecore_sge_tpa_params *sge_tpa_params;
1001                 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
1002
1003                 sge_tpa_params = p_params->sge_tpa_params;
1004                 size = sizeof(struct vfpf_vport_update_sge_tpa_tlv);
1005                 p_sge_tpa_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
1006                                               CHANNEL_TLV_VPORT_UPDATE_SGE_TPA,
1007                                               size);
1008                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1009
1010                 if (sge_tpa_params->update_tpa_en_flg)
1011                         p_sge_tpa_tlv->update_sge_tpa_flags |=
1012                             VFPF_UPDATE_TPA_EN_FLAG;
1013                 if (sge_tpa_params->update_tpa_param_flg)
1014                         p_sge_tpa_tlv->update_sge_tpa_flags |=
1015                             VFPF_UPDATE_TPA_PARAM_FLAG;
1016
1017                 if (sge_tpa_params->tpa_ipv4_en_flg)
1018                         p_sge_tpa_tlv->sge_tpa_flags |= VFPF_TPA_IPV4_EN_FLAG;
1019                 if (sge_tpa_params->tpa_ipv6_en_flg)
1020                         p_sge_tpa_tlv->sge_tpa_flags |= VFPF_TPA_IPV6_EN_FLAG;
1021                 if (sge_tpa_params->tpa_pkt_split_flg)
1022                         p_sge_tpa_tlv->sge_tpa_flags |= VFPF_TPA_PKT_SPLIT_FLAG;
1023                 if (sge_tpa_params->tpa_hdr_data_split_flg)
1024                         p_sge_tpa_tlv->sge_tpa_flags |=
1025                             VFPF_TPA_HDR_DATA_SPLIT_FLAG;
1026                 if (sge_tpa_params->tpa_gro_consistent_flg)
1027                         p_sge_tpa_tlv->sge_tpa_flags |=
1028                             VFPF_TPA_GRO_CONSIST_FLAG;
1029
1030                 p_sge_tpa_tlv->tpa_max_aggs_num =
1031                     sge_tpa_params->tpa_max_aggs_num;
1032                 p_sge_tpa_tlv->tpa_max_size = sge_tpa_params->tpa_max_size;
1033                 p_sge_tpa_tlv->tpa_min_size_to_start =
1034                     sge_tpa_params->tpa_min_size_to_start;
1035                 p_sge_tpa_tlv->tpa_min_size_to_cont =
1036                     sge_tpa_params->tpa_min_size_to_cont;
1037
1038                 p_sge_tpa_tlv->max_buffers_per_cqe =
1039                     sge_tpa_params->max_buffers_per_cqe;
1040         }
1041
1042         /* add list termination tlv */
1043         ecore_add_tlv(p_hwfn, &p_iov->offset,
1044                       CHANNEL_TLV_LIST_END,
1045                       sizeof(struct channel_list_end_tlv));
1046
1047         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
1048         if (rc)
1049                 goto exit;
1050
1051         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1052                 rc = ECORE_INVAL;
1053                 goto exit;
1054         }
1055
1056         ecore_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
1057
1058 exit:
1059         ecore_vf_pf_req_end(p_hwfn, rc);
1060
1061         return rc;
1062 }
1063
1064 enum _ecore_status_t ecore_vf_pf_reset(struct ecore_hwfn *p_hwfn)
1065 {
1066         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1067         struct pfvf_def_resp_tlv *resp;
1068         struct vfpf_first_tlv *req;
1069         enum _ecore_status_t rc;
1070
1071         /* clear mailbox and prep first tlv */
1072         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
1073
1074         /* add list termination tlv */
1075         ecore_add_tlv(p_hwfn, &p_iov->offset,
1076                       CHANNEL_TLV_LIST_END,
1077                       sizeof(struct channel_list_end_tlv));
1078
1079         resp = &p_iov->pf2vf_reply->default_resp;
1080         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1081         if (rc)
1082                 goto exit;
1083
1084         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1085                 rc = ECORE_AGAIN;
1086                 goto exit;
1087         }
1088
1089         p_hwfn->b_int_enabled = 0;
1090
1091 exit:
1092         ecore_vf_pf_req_end(p_hwfn, rc);
1093
1094         return rc;
1095 }
1096
1097 enum _ecore_status_t ecore_vf_pf_release(struct ecore_hwfn *p_hwfn)
1098 {
1099         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1100         struct pfvf_def_resp_tlv *resp;
1101         struct vfpf_first_tlv *req;
1102         enum _ecore_status_t rc;
1103         u32 size;
1104
1105         /* clear mailbox and prep first tlv */
1106         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
1107
1108         /* add list termination tlv */
1109         ecore_add_tlv(p_hwfn, &p_iov->offset,
1110                       CHANNEL_TLV_LIST_END,
1111                       sizeof(struct channel_list_end_tlv));
1112
1113         resp = &p_iov->pf2vf_reply->default_resp;
1114         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1115
1116         if (rc == ECORE_SUCCESS && resp->hdr.status != PFVF_STATUS_SUCCESS)
1117                 rc = ECORE_AGAIN;
1118
1119         ecore_vf_pf_req_end(p_hwfn, rc);
1120
1121         p_hwfn->b_int_enabled = 0;
1122
1123         if (p_iov->vf2pf_request)
1124                 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
1125                                        p_iov->vf2pf_request,
1126                                        p_iov->vf2pf_request_phys,
1127                                        sizeof(union vfpf_tlvs));
1128         if (p_iov->pf2vf_reply)
1129                 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
1130                                        p_iov->pf2vf_reply,
1131                                        p_iov->pf2vf_reply_phys,
1132                                        sizeof(union pfvf_tlvs));
1133
1134         if (p_iov->bulletin.p_virt) {
1135                 size = sizeof(struct ecore_bulletin_content);
1136                 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
1137                                        p_iov->bulletin.p_virt,
1138                                        p_iov->bulletin.phys, size);
1139         }
1140
1141         OSAL_FREE(p_hwfn->p_dev, p_hwfn->vf_iov_info);
1142
1143         return rc;
1144 }
1145
1146 void ecore_vf_pf_filter_mcast(struct ecore_hwfn *p_hwfn,
1147                               struct ecore_filter_mcast *p_filter_cmd)
1148 {
1149         struct ecore_sp_vport_update_params sp_params;
1150         int i;
1151
1152         OSAL_MEMSET(&sp_params, 0, sizeof(sp_params));
1153         sp_params.update_approx_mcast_flg = 1;
1154
1155         if (p_filter_cmd->opcode == ECORE_FILTER_ADD) {
1156                 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1157                         u32 bit;
1158
1159                         bit = ecore_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1160                         OSAL_SET_BIT(bit, sp_params.bins);
1161                 }
1162         }
1163
1164         ecore_vf_pf_vport_update(p_hwfn, &sp_params);
1165 }
1166
1167 enum _ecore_status_t ecore_vf_pf_filter_ucast(struct ecore_hwfn *p_hwfn,
1168                                               struct ecore_filter_ucast
1169                                               *p_ucast)
1170 {
1171         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1172         struct vfpf_ucast_filter_tlv *req;
1173         struct pfvf_def_resp_tlv *resp;
1174         enum _ecore_status_t rc;
1175
1176         /* Sanitize */
1177         if (p_ucast->opcode == ECORE_FILTER_MOVE) {
1178                 DP_NOTICE(p_hwfn, true,
1179                           "VFs don't support Moving of filters\n");
1180                 return ECORE_INVAL;
1181         }
1182
1183         /* clear mailbox and prep first tlv */
1184         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
1185         req->opcode = (u8)p_ucast->opcode;
1186         req->type = (u8)p_ucast->type;
1187         OSAL_MEMCPY(req->mac, p_ucast->mac, ETH_ALEN);
1188         req->vlan = p_ucast->vlan;
1189
1190         /* add list termination tlv */
1191         ecore_add_tlv(p_hwfn, &p_iov->offset,
1192                       CHANNEL_TLV_LIST_END,
1193                       sizeof(struct channel_list_end_tlv));
1194
1195         resp = &p_iov->pf2vf_reply->default_resp;
1196         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1197         if (rc)
1198                 goto exit;
1199
1200         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1201                 rc = ECORE_AGAIN;
1202                 goto exit;
1203         }
1204
1205 exit:
1206         ecore_vf_pf_req_end(p_hwfn, rc);
1207
1208         return rc;
1209 }
1210
1211 enum _ecore_status_t ecore_vf_pf_int_cleanup(struct ecore_hwfn *p_hwfn)
1212 {
1213         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1214         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
1215         enum _ecore_status_t rc;
1216
1217         /* clear mailbox and prep first tlv */
1218         ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
1219                          sizeof(struct vfpf_first_tlv));
1220
1221         /* add list termination tlv */
1222         ecore_add_tlv(p_hwfn, &p_iov->offset,
1223                       CHANNEL_TLV_LIST_END,
1224                       sizeof(struct channel_list_end_tlv));
1225
1226         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1227         if (rc)
1228                 goto exit;
1229
1230         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1231                 rc = ECORE_INVAL;
1232                 goto exit;
1233         }
1234
1235 exit:
1236         ecore_vf_pf_req_end(p_hwfn, rc);
1237
1238         return rc;
1239 }
1240
1241 u16 ecore_vf_get_igu_sb_id(struct ecore_hwfn *p_hwfn,
1242                            u16               sb_id)
1243 {
1244         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1245
1246         if (!p_iov) {
1247                 DP_NOTICE(p_hwfn, true, "vf_sriov_info isn't initialized\n");
1248                 return 0;
1249         }
1250
1251         return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
1252 }
1253
1254 enum _ecore_status_t ecore_vf_read_bulletin(struct ecore_hwfn *p_hwfn,
1255                                             u8 *p_change)
1256 {
1257         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1258         struct ecore_bulletin_content shadow;
1259         u32 crc, crc_size;
1260
1261         crc_size = sizeof(p_iov->bulletin.p_virt->crc);
1262         *p_change = 0;
1263
1264         /* Need to guarantee PF is not in the middle of writing it */
1265         OSAL_MEMCPY(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
1266
1267         /* If version did not update, no need to do anything */
1268         if (shadow.version == p_iov->bulletin_shadow.version)
1269                 return ECORE_SUCCESS;
1270
1271         /* Verify the bulletin we see is valid */
1272         crc = ecore_crc32(0, (u8 *)&shadow + crc_size,
1273                           p_iov->bulletin.size - crc_size);
1274         if (crc != shadow.crc)
1275                 return ECORE_AGAIN;
1276
1277         /* Set the shadow bulletin and process it */
1278         OSAL_MEMCPY(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
1279
1280         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1281                    "Read a bulletin update %08x\n", shadow.version);
1282
1283         *p_change = 1;
1284
1285         return ECORE_SUCCESS;
1286 }
1287
1288 void __ecore_vf_get_link_params(struct ecore_hwfn *p_hwfn,
1289                                 struct ecore_mcp_link_params *p_params,
1290                                 struct ecore_bulletin_content *p_bulletin)
1291 {
1292         OSAL_MEMSET(p_params, 0, sizeof(*p_params));
1293
1294         p_params->speed.autoneg = p_bulletin->req_autoneg;
1295         p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
1296         p_params->speed.forced_speed = p_bulletin->req_forced_speed;
1297         p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
1298         p_params->pause.forced_rx = p_bulletin->req_forced_rx;
1299         p_params->pause.forced_tx = p_bulletin->req_forced_tx;
1300         p_params->loopback_mode = p_bulletin->req_loopback;
1301 }
1302
1303 void ecore_vf_get_link_params(struct ecore_hwfn *p_hwfn,
1304                               struct ecore_mcp_link_params *params)
1305 {
1306         __ecore_vf_get_link_params(p_hwfn, params,
1307                                    &p_hwfn->vf_iov_info->bulletin_shadow);
1308 }
1309
1310 void __ecore_vf_get_link_state(struct ecore_hwfn *p_hwfn,
1311                                struct ecore_mcp_link_state *p_link,
1312                                struct ecore_bulletin_content *p_bulletin)
1313 {
1314         OSAL_MEMSET(p_link, 0, sizeof(*p_link));
1315
1316         p_link->link_up = p_bulletin->link_up;
1317         p_link->speed = p_bulletin->speed;
1318         p_link->full_duplex = p_bulletin->full_duplex;
1319         p_link->an = p_bulletin->autoneg;
1320         p_link->an_complete = p_bulletin->autoneg_complete;
1321         p_link->parallel_detection = p_bulletin->parallel_detection;
1322         p_link->pfc_enabled = p_bulletin->pfc_enabled;
1323         p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
1324         p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
1325         p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
1326         p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
1327         p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
1328 }
1329
1330 void ecore_vf_get_link_state(struct ecore_hwfn *p_hwfn,
1331                              struct ecore_mcp_link_state *link)
1332 {
1333         __ecore_vf_get_link_state(p_hwfn, link,
1334                                   &p_hwfn->vf_iov_info->bulletin_shadow);
1335 }
1336
1337 void __ecore_vf_get_link_caps(struct ecore_hwfn *p_hwfn,
1338                               struct ecore_mcp_link_capabilities *p_link_caps,
1339                               struct ecore_bulletin_content *p_bulletin)
1340 {
1341         OSAL_MEMSET(p_link_caps, 0, sizeof(*p_link_caps));
1342         p_link_caps->speed_capabilities = p_bulletin->capability_speed;
1343 }
1344
1345 void ecore_vf_get_link_caps(struct ecore_hwfn *p_hwfn,
1346                             struct ecore_mcp_link_capabilities *p_link_caps)
1347 {
1348         __ecore_vf_get_link_caps(p_hwfn, p_link_caps,
1349                                  &p_hwfn->vf_iov_info->bulletin_shadow);
1350 }
1351
1352 void ecore_vf_get_num_rxqs(struct ecore_hwfn *p_hwfn, u8 *num_rxqs)
1353 {
1354         *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
1355 }
1356
1357 void ecore_vf_get_port_mac(struct ecore_hwfn *p_hwfn, u8 *port_mac)
1358 {
1359         OSAL_MEMCPY(port_mac,
1360                     p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac,
1361                     ETH_ALEN);
1362 }
1363
1364 void ecore_vf_get_num_vlan_filters(struct ecore_hwfn *p_hwfn,
1365                                    u8 *num_vlan_filters)
1366 {
1367         struct ecore_vf_iov *p_vf;
1368
1369         p_vf = p_hwfn->vf_iov_info;
1370         *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
1371 }
1372
1373 void ecore_vf_get_num_sbs(struct ecore_hwfn *p_hwfn,
1374                           u32 *num_sbs)
1375 {
1376         struct ecore_vf_iov *p_vf;
1377
1378         p_vf = p_hwfn->vf_iov_info;
1379         *num_sbs = (u32)p_vf->acquire_resp.resc.num_sbs;
1380 }
1381
1382 void ecore_vf_get_num_mac_filters(struct ecore_hwfn *p_hwfn,
1383                                   u32 *num_mac_filters)
1384 {
1385         struct ecore_vf_iov *p_vf = p_hwfn->vf_iov_info;
1386
1387         *num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters;
1388 }
1389
1390 bool ecore_vf_check_mac(struct ecore_hwfn *p_hwfn, u8 *mac)
1391 {
1392         struct ecore_bulletin_content *bulletin;
1393
1394         bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1395         if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
1396                 return true;
1397
1398         /* Forbid VF from changing a MAC enforced by PF */
1399         if (OSAL_MEMCMP(bulletin->mac, mac, ETH_ALEN))
1400                 return false;
1401
1402         return false;
1403 }
1404
1405 bool ecore_vf_bulletin_get_forced_mac(struct ecore_hwfn *hwfn, u8 *dst_mac,
1406                                       u8 *p_is_forced)
1407 {
1408         struct ecore_bulletin_content *bulletin;
1409
1410         bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1411
1412         if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
1413                 if (p_is_forced)
1414                         *p_is_forced = 1;
1415         } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
1416                 if (p_is_forced)
1417                         *p_is_forced = 0;
1418         } else {
1419                 return false;
1420         }
1421
1422         OSAL_MEMCPY(dst_mac, bulletin->mac, ETH_ALEN);
1423
1424         return true;
1425 }
1426
1427 bool ecore_vf_bulletin_get_forced_vlan(struct ecore_hwfn *hwfn, u16 *dst_pvid)
1428 {
1429         struct ecore_bulletin_content *bulletin;
1430
1431         bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1432
1433         if (!(bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
1434                 return false;
1435
1436         if (dst_pvid)
1437                 *dst_pvid = bulletin->pvid;
1438
1439         return true;
1440 }
1441
1442 bool ecore_vf_get_pre_fp_hsi(struct ecore_hwfn *p_hwfn)
1443 {
1444         return p_hwfn->vf_iov_info->b_pre_fp_hsi;
1445 }
1446
1447 void ecore_vf_get_fw_version(struct ecore_hwfn *p_hwfn,
1448                              u16 *fw_major, u16 *fw_minor, u16 *fw_rev,
1449                              u16 *fw_eng)
1450 {
1451         struct pf_vf_pfdev_info *info;
1452
1453         info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
1454
1455         *fw_major = info->fw_major;
1456         *fw_minor = info->fw_minor;
1457         *fw_rev = info->fw_rev;
1458         *fw_eng = info->fw_eng;
1459 }