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