net/qede/base: fix to prevent VF promisc config
[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         OSAL_MEMSET(p_iov, 0, sizeof(*p_iov));
391
392         /* Allocate vf2pf msg */
393         p_iov->vf2pf_request = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
394                                                          &p_iov->
395                                                          vf2pf_request_phys,
396                                                          sizeof(union
397                                                                 vfpf_tlvs));
398         if (!p_iov->vf2pf_request) {
399                 DP_NOTICE(p_hwfn, true,
400                          "Failed to allocate `vf2pf_request' DMA memory\n");
401                 goto free_p_iov;
402         }
403
404         p_iov->pf2vf_reply = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
405                                                        &p_iov->
406                                                        pf2vf_reply_phys,
407                                                        sizeof(union pfvf_tlvs));
408         if (!p_iov->pf2vf_reply) {
409                 DP_NOTICE(p_hwfn, true,
410                           "Failed to allocate `pf2vf_reply' DMA memory\n");
411                 goto free_vf2pf_request;
412         }
413
414         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
415                    "VF's Request mailbox [%p virt 0x%lx phys], "
416                    "Response mailbox [%p virt 0x%lx phys]\n",
417                    p_iov->vf2pf_request,
418                    (unsigned long)p_iov->vf2pf_request_phys,
419                    p_iov->pf2vf_reply,
420                    (unsigned long)p_iov->pf2vf_reply_phys);
421
422         /* Allocate Bulletin board */
423         p_iov->bulletin.size = sizeof(struct ecore_bulletin_content);
424         p_iov->bulletin.p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
425                                                            &p_iov->bulletin.
426                                                            phys,
427                                                            p_iov->bulletin.
428                                                            size);
429         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
430                    "VF's bulletin Board [%p virt 0x%lx phys 0x%08x bytes]\n",
431                    p_iov->bulletin.p_virt, (unsigned long)p_iov->bulletin.phys,
432                    p_iov->bulletin.size);
433
434         OSAL_MUTEX_ALLOC(p_hwfn, &p_iov->mutex);
435         OSAL_MUTEX_INIT(&p_iov->mutex);
436
437         p_hwfn->vf_iov_info = p_iov;
438
439         p_hwfn->hw_info.personality = ECORE_PCI_ETH;
440
441         return ecore_vf_pf_acquire(p_hwfn);
442
443 free_vf2pf_request:
444         OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev, p_iov->vf2pf_request,
445                                p_iov->vf2pf_request_phys,
446                                sizeof(union vfpf_tlvs));
447 free_p_iov:
448         OSAL_FREE(p_hwfn->p_dev, p_iov);
449
450         return ECORE_NOMEM;
451 }
452
453 #define TSTORM_QZONE_START   PXP_VF_BAR0_START_SDM_ZONE_A
454 #define MSTORM_QZONE_START(dev)   (TSTORM_QZONE_START + \
455                                    (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
456
457 enum _ecore_status_t ecore_vf_pf_rxq_start(struct ecore_hwfn *p_hwfn,
458                                            u8 rx_qid,
459                                            u16 sb,
460                                            u8 sb_index,
461                                            u16 bd_max_bytes,
462                                            dma_addr_t bd_chain_phys_addr,
463                                            dma_addr_t cqe_pbl_addr,
464                                            u16 cqe_pbl_size,
465                                            void OSAL_IOMEM **pp_prod)
466 {
467         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
468         struct pfvf_start_queue_resp_tlv *resp;
469         struct vfpf_start_rxq_tlv *req;
470         enum _ecore_status_t rc;
471
472         /* clear mailbox and prep first tlv */
473         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
474
475         req->rx_qid = rx_qid;
476         req->cqe_pbl_addr = cqe_pbl_addr;
477         req->cqe_pbl_size = cqe_pbl_size;
478         req->rxq_addr = bd_chain_phys_addr;
479         req->hw_sb = sb;
480         req->sb_index = sb_index;
481         req->bd_max_bytes = bd_max_bytes;
482         req->stat_id = -1; /* Keep initialized, for future compatibility */
483
484         /* If PF is legacy, we'll need to calculate producers ourselves
485          * as well as clean them.
486          */
487         if (pp_prod && p_iov->b_pre_fp_hsi) {
488                 u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
489                 u32 init_prod_val = 0;
490
491                 *pp_prod = (u8 OSAL_IOMEM *)p_hwfn->regview +
492                            MSTORM_QZONE_START(p_hwfn->p_dev) +
493                            (hw_qid) * MSTORM_QZONE_SIZE;
494
495                 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
496                 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
497                                   (u32 *)(&init_prod_val));
498         }
499
500         /* add list termination tlv */
501         ecore_add_tlv(p_hwfn, &p_iov->offset,
502                       CHANNEL_TLV_LIST_END,
503                       sizeof(struct channel_list_end_tlv));
504
505         resp = &p_iov->pf2vf_reply->queue_start;
506         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
507         if (rc)
508                 goto exit;
509
510         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
511                 rc = ECORE_INVAL;
512                 goto exit;
513         }
514
515         /* Learn the address of the producer from the response */
516         if (pp_prod && !p_iov->b_pre_fp_hsi) {
517                 u32 init_prod_val = 0;
518
519                 *pp_prod = (u8 OSAL_IOMEM *)p_hwfn->regview + resp->offset;
520                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
521                            "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
522                            rx_qid, *pp_prod, resp->offset);
523
524                 /* Init the rcq, rx bd and rx sge (if valid) producers to 0.
525                  * It was actually the PF's responsibility, but since some
526                  * old PFs might fail to do so, we do this as well.
527                  */
528                 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
529                 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
530                                   (u32 *)&init_prod_val);
531         }
532
533 exit:
534         ecore_vf_pf_req_end(p_hwfn, rc);
535
536         return rc;
537 }
538
539 enum _ecore_status_t ecore_vf_pf_rxq_stop(struct ecore_hwfn *p_hwfn,
540                                           u16 rx_qid, bool cqe_completion)
541 {
542         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
543         struct vfpf_stop_rxqs_tlv *req;
544         struct pfvf_def_resp_tlv *resp;
545         enum _ecore_status_t rc;
546
547         /* clear mailbox and prep first tlv */
548         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
549
550         req->rx_qid = rx_qid;
551         req->num_rxqs = 1;
552         req->cqe_completion = cqe_completion;
553
554         /* add list termination tlv */
555         ecore_add_tlv(p_hwfn, &p_iov->offset,
556                       CHANNEL_TLV_LIST_END,
557                       sizeof(struct channel_list_end_tlv));
558
559         resp = &p_iov->pf2vf_reply->default_resp;
560         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
561         if (rc)
562                 goto exit;
563
564         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
565                 rc = ECORE_INVAL;
566                 goto exit;
567         }
568
569 exit:
570         ecore_vf_pf_req_end(p_hwfn, rc);
571
572         return rc;
573 }
574
575 enum _ecore_status_t ecore_vf_pf_txq_start(struct ecore_hwfn *p_hwfn,
576                                            u16 tx_queue_id,
577                                            u16 sb,
578                                            u8 sb_index,
579                                            dma_addr_t pbl_addr,
580                                            u16 pbl_size,
581                                            void OSAL_IOMEM **pp_doorbell)
582 {
583         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
584         struct pfvf_start_queue_resp_tlv *resp;
585         struct vfpf_start_txq_tlv *req;
586         enum _ecore_status_t rc;
587
588         /* clear mailbox and prep first tlv */
589         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
590
591         req->tx_qid = tx_queue_id;
592
593         /* Tx */
594         req->pbl_addr = pbl_addr;
595         req->pbl_size = pbl_size;
596         req->hw_sb = sb;
597         req->sb_index = sb_index;
598
599         /* add list termination tlv */
600         ecore_add_tlv(p_hwfn, &p_iov->offset,
601                       CHANNEL_TLV_LIST_END,
602                       sizeof(struct channel_list_end_tlv));
603
604         resp  = &p_iov->pf2vf_reply->queue_start;
605         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
606         if (rc)
607                 goto exit;
608
609         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
610                 rc = ECORE_INVAL;
611                 goto exit;
612         }
613
614         if (pp_doorbell) {
615                 /* Modern PFs provide the actual offsets, while legacy
616                  * provided only the queue id.
617                  */
618                 if (!p_iov->b_pre_fp_hsi) {
619                         *pp_doorbell = (u8 OSAL_IOMEM *)p_hwfn->doorbells +
620                                                        resp->offset;
621                 } else {
622                         u8 cid = p_iov->acquire_resp.resc.cid[tx_queue_id];
623
624                 *pp_doorbell = (u8 OSAL_IOMEM *)p_hwfn->doorbells +
625                                 DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
626                 }
627
628                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
629                            "Txq[0x%02x]: doorbell at %p [offset 0x%08x]\n",
630                            tx_queue_id, *pp_doorbell, resp->offset);
631         }
632
633 exit:
634         ecore_vf_pf_req_end(p_hwfn, rc);
635
636         return rc;
637 }
638
639 enum _ecore_status_t ecore_vf_pf_txq_stop(struct ecore_hwfn *p_hwfn, u16 tx_qid)
640 {
641         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
642         struct vfpf_stop_txqs_tlv *req;
643         struct pfvf_def_resp_tlv *resp;
644         enum _ecore_status_t rc;
645
646         /* clear mailbox and prep first tlv */
647         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
648
649         req->tx_qid = tx_qid;
650         req->num_txqs = 1;
651
652         /* add list termination tlv */
653         ecore_add_tlv(p_hwfn, &p_iov->offset,
654                       CHANNEL_TLV_LIST_END,
655                       sizeof(struct channel_list_end_tlv));
656
657         resp = &p_iov->pf2vf_reply->default_resp;
658         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
659         if (rc)
660                 goto exit;
661
662         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
663                 rc = ECORE_INVAL;
664                 goto exit;
665         }
666
667 exit:
668         ecore_vf_pf_req_end(p_hwfn, rc);
669
670         return rc;
671 }
672
673 enum _ecore_status_t ecore_vf_pf_rxqs_update(struct ecore_hwfn *p_hwfn,
674                                              u16 rx_queue_id,
675                                              u8 num_rxqs,
676                                              u8 comp_cqe_flg, u8 comp_event_flg)
677 {
678         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
679         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
680         struct vfpf_update_rxq_tlv *req;
681         enum _ecore_status_t rc;
682
683         /* clear mailbox and prep first tlv */
684         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_RXQ, sizeof(*req));
685
686         req->rx_qid = rx_queue_id;
687         req->num_rxqs = num_rxqs;
688
689         if (comp_cqe_flg)
690                 req->flags |= VFPF_RXQ_UPD_COMPLETE_CQE_FLAG;
691         if (comp_event_flg)
692                 req->flags |= VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG;
693
694         /* add list termination tlv */
695         ecore_add_tlv(p_hwfn, &p_iov->offset,
696                       CHANNEL_TLV_LIST_END,
697                       sizeof(struct channel_list_end_tlv));
698
699         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
700         if (rc)
701                 goto exit;
702
703         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
704                 rc = ECORE_INVAL;
705                 goto exit;
706         }
707
708 exit:
709         ecore_vf_pf_req_end(p_hwfn, rc);
710
711         return rc;
712 }
713
714 enum _ecore_status_t
715 ecore_vf_pf_vport_start(struct ecore_hwfn *p_hwfn, u8 vport_id,
716                         u16 mtu, u8 inner_vlan_removal,
717                         enum ecore_tpa_mode tpa_mode, u8 max_buffers_per_cqe,
718                         u8 only_untagged)
719 {
720         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
721         struct vfpf_vport_start_tlv *req;
722         struct pfvf_def_resp_tlv *resp;
723         enum _ecore_status_t rc;
724         int i;
725
726         /* clear mailbox and prep first tlv */
727         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
728
729         req->mtu = mtu;
730         req->vport_id = vport_id;
731         req->inner_vlan_removal = inner_vlan_removal;
732         req->tpa_mode = tpa_mode;
733         req->max_buffers_per_cqe = max_buffers_per_cqe;
734         req->only_untagged = only_untagged;
735
736         /* status blocks */
737         for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++)
738                 if (p_hwfn->sbs_info[i])
739                         req->sb_addr[i] = p_hwfn->sbs_info[i]->sb_phys;
740
741         /* add list termination tlv */
742         ecore_add_tlv(p_hwfn, &p_iov->offset,
743                       CHANNEL_TLV_LIST_END,
744                       sizeof(struct channel_list_end_tlv));
745
746         resp  = &p_iov->pf2vf_reply->default_resp;
747         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
748         if (rc)
749                 goto exit;
750
751         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
752                 rc = ECORE_INVAL;
753                 goto exit;
754         }
755
756 exit:
757         ecore_vf_pf_req_end(p_hwfn, rc);
758
759         return rc;
760 }
761
762 enum _ecore_status_t ecore_vf_pf_vport_stop(struct ecore_hwfn *p_hwfn)
763 {
764         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
765         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
766         enum _ecore_status_t rc;
767
768         /* clear mailbox and prep first tlv */
769         ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
770                          sizeof(struct vfpf_first_tlv));
771
772         /* add list termination tlv */
773         ecore_add_tlv(p_hwfn, &p_iov->offset,
774                       CHANNEL_TLV_LIST_END,
775                       sizeof(struct channel_list_end_tlv));
776
777         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
778         if (rc)
779                 goto exit;
780
781         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
782                 rc = ECORE_INVAL;
783                 goto exit;
784         }
785
786 exit:
787         ecore_vf_pf_req_end(p_hwfn, rc);
788
789         return rc;
790 }
791
792 static bool
793 ecore_vf_handle_vp_update_is_needed(struct ecore_hwfn *p_hwfn,
794                                     struct ecore_sp_vport_update_params *p_data,
795                                     u16 tlv)
796 {
797         switch (tlv) {
798         case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
799                 return !!(p_data->update_vport_active_rx_flg ||
800                           p_data->update_vport_active_tx_flg);
801         case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
802 #ifndef ASIC_ONLY
803                 /* FPGA doesn't have PVFC and so can't support tx-switching */
804                 return !!(p_data->update_tx_switching_flg &&
805                           !CHIP_REV_IS_FPGA(p_hwfn->p_dev));
806 #else
807                 return !!p_data->update_tx_switching_flg;
808 #endif
809         case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
810                 return !!p_data->update_inner_vlan_removal_flg;
811         case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
812                 return !!p_data->update_accept_any_vlan_flg;
813         case CHANNEL_TLV_VPORT_UPDATE_MCAST:
814                 return !!p_data->update_approx_mcast_flg;
815         case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
816                 return !!(p_data->accept_flags.update_rx_mode_config ||
817                           p_data->accept_flags.update_tx_mode_config);
818         case CHANNEL_TLV_VPORT_UPDATE_RSS:
819                 return !!p_data->rss_params;
820         case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
821                 return !!p_data->sge_tpa_params;
822         default:
823                 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d] %s\n",
824                         tlv, ecore_channel_tlvs_string[tlv]);
825                 return false;
826         }
827 }
828
829 static void
830 ecore_vf_handle_vp_update_tlvs_resp(struct ecore_hwfn *p_hwfn,
831                                     struct ecore_sp_vport_update_params *p_data)
832 {
833         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
834         struct pfvf_def_resp_tlv *p_resp;
835         u16 tlv;
836
837         for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
838              tlv < CHANNEL_TLV_VPORT_UPDATE_MAX;
839              tlv++) {
840                 if (!ecore_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
841                         continue;
842
843                 p_resp = (struct pfvf_def_resp_tlv *)
844                     ecore_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply, tlv);
845                 if (p_resp && p_resp->hdr.status)
846                         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
847                                    "TLV[%d] type %s Configuration %s\n",
848                                    tlv, ecore_channel_tlvs_string[tlv],
849                                    (p_resp && p_resp->hdr.status) ? "succeeded"
850                                                                   : "failed");
851         }
852 }
853
854 enum _ecore_status_t
855 ecore_vf_pf_vport_update(struct ecore_hwfn *p_hwfn,
856                          struct ecore_sp_vport_update_params *p_params)
857 {
858         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
859         struct vfpf_vport_update_tlv *req;
860         struct pfvf_def_resp_tlv *resp;
861         u8 update_rx, update_tx;
862         u32 resp_size = 0;
863         u16 size, tlv;
864         enum _ecore_status_t rc;
865
866         resp = &p_iov->pf2vf_reply->default_resp;
867         resp_size = sizeof(*resp);
868
869         update_rx = p_params->update_vport_active_rx_flg;
870         update_tx = p_params->update_vport_active_tx_flg;
871
872         /* clear mailbox and prep header tlv */
873         ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
874
875         /* Prepare extended tlvs */
876         if (update_rx || update_tx) {
877                 struct vfpf_vport_update_activate_tlv *p_act_tlv;
878
879                 size = sizeof(struct vfpf_vport_update_activate_tlv);
880                 p_act_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
881                                           CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
882                                           size);
883                 resp_size += sizeof(struct pfvf_def_resp_tlv);
884
885                 if (update_rx) {
886                         p_act_tlv->update_rx = update_rx;
887                         p_act_tlv->active_rx = p_params->vport_active_rx_flg;
888                 }
889
890                 if (update_tx) {
891                         p_act_tlv->update_tx = update_tx;
892                         p_act_tlv->active_tx = p_params->vport_active_tx_flg;
893                 }
894         }
895
896         if (p_params->update_inner_vlan_removal_flg) {
897                 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
898
899                 size = sizeof(struct vfpf_vport_update_vlan_strip_tlv);
900                 p_vlan_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
901                                            CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP,
902                                            size);
903                 resp_size += sizeof(struct pfvf_def_resp_tlv);
904
905                 p_vlan_tlv->remove_vlan = p_params->inner_vlan_removal_flg;
906         }
907
908         if (p_params->update_tx_switching_flg) {
909                 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
910
911                 size = sizeof(struct vfpf_vport_update_tx_switch_tlv);
912                 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
913                 p_tx_switch_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
914                                                 tlv, size);
915                 resp_size += sizeof(struct pfvf_def_resp_tlv);
916
917                 p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg;
918         }
919
920         if (p_params->update_approx_mcast_flg) {
921                 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
922
923                 size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
924                 p_mcast_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
925                                             CHANNEL_TLV_VPORT_UPDATE_MCAST,
926                                             size);
927                 resp_size += sizeof(struct pfvf_def_resp_tlv);
928
929                 OSAL_MEMCPY(p_mcast_tlv->bins, p_params->bins,
930                             sizeof(unsigned long) *
931                             ETH_MULTICAST_MAC_BINS_IN_REGS);
932         }
933
934         update_rx = p_params->accept_flags.update_rx_mode_config;
935         update_tx = p_params->accept_flags.update_tx_mode_config;
936
937         if (update_rx || update_tx) {
938                 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
939
940                 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
941                 size = sizeof(struct vfpf_vport_update_accept_param_tlv);
942                 p_accept_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
943                 resp_size += sizeof(struct pfvf_def_resp_tlv);
944
945                 if (update_rx) {
946                         p_accept_tlv->update_rx_mode = update_rx;
947                         p_accept_tlv->rx_accept_filter =
948                             p_params->accept_flags.rx_accept_filter;
949                 }
950
951                 if (update_tx) {
952                         p_accept_tlv->update_tx_mode = update_tx;
953                         p_accept_tlv->tx_accept_filter =
954                             p_params->accept_flags.tx_accept_filter;
955                 }
956         }
957
958         if (p_params->rss_params) {
959                 struct ecore_rss_params *rss_params = p_params->rss_params;
960                 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
961
962                 size = sizeof(struct vfpf_vport_update_rss_tlv);
963                 p_rss_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
964                                           CHANNEL_TLV_VPORT_UPDATE_RSS, size);
965                 resp_size += sizeof(struct pfvf_def_resp_tlv);
966
967                 if (rss_params->update_rss_config)
968                         p_rss_tlv->update_rss_flags |=
969                             VFPF_UPDATE_RSS_CONFIG_FLAG;
970                 if (rss_params->update_rss_capabilities)
971                         p_rss_tlv->update_rss_flags |=
972                             VFPF_UPDATE_RSS_CAPS_FLAG;
973                 if (rss_params->update_rss_ind_table)
974                         p_rss_tlv->update_rss_flags |=
975                             VFPF_UPDATE_RSS_IND_TABLE_FLAG;
976                 if (rss_params->update_rss_key)
977                         p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
978
979                 p_rss_tlv->rss_enable = rss_params->rss_enable;
980                 p_rss_tlv->rss_caps = rss_params->rss_caps;
981                 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
982                 OSAL_MEMCPY(p_rss_tlv->rss_ind_table, rss_params->rss_ind_table,
983                             sizeof(rss_params->rss_ind_table));
984                 OSAL_MEMCPY(p_rss_tlv->rss_key, rss_params->rss_key,
985                             sizeof(rss_params->rss_key));
986         }
987
988         if (p_params->update_accept_any_vlan_flg) {
989                 struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
990
991                 size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
992                 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
993                 p_any_vlan_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
994                                                tlv, size);
995
996                 resp_size += sizeof(struct pfvf_def_resp_tlv);
997                 p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
998                 p_any_vlan_tlv->update_accept_any_vlan_flg =
999                     p_params->update_accept_any_vlan_flg;
1000         }
1001
1002         if (p_params->sge_tpa_params) {
1003                 struct ecore_sge_tpa_params *sge_tpa_params;
1004                 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
1005
1006                 sge_tpa_params = p_params->sge_tpa_params;
1007                 size = sizeof(struct vfpf_vport_update_sge_tpa_tlv);
1008                 p_sge_tpa_tlv = ecore_add_tlv(p_hwfn, &p_iov->offset,
1009                                               CHANNEL_TLV_VPORT_UPDATE_SGE_TPA,
1010                                               size);
1011                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1012
1013                 if (sge_tpa_params->update_tpa_en_flg)
1014                         p_sge_tpa_tlv->update_sge_tpa_flags |=
1015                             VFPF_UPDATE_TPA_EN_FLAG;
1016                 if (sge_tpa_params->update_tpa_param_flg)
1017                         p_sge_tpa_tlv->update_sge_tpa_flags |=
1018                             VFPF_UPDATE_TPA_PARAM_FLAG;
1019
1020                 if (sge_tpa_params->tpa_ipv4_en_flg)
1021                         p_sge_tpa_tlv->sge_tpa_flags |= VFPF_TPA_IPV4_EN_FLAG;
1022                 if (sge_tpa_params->tpa_ipv6_en_flg)
1023                         p_sge_tpa_tlv->sge_tpa_flags |= VFPF_TPA_IPV6_EN_FLAG;
1024                 if (sge_tpa_params->tpa_pkt_split_flg)
1025                         p_sge_tpa_tlv->sge_tpa_flags |= VFPF_TPA_PKT_SPLIT_FLAG;
1026                 if (sge_tpa_params->tpa_hdr_data_split_flg)
1027                         p_sge_tpa_tlv->sge_tpa_flags |=
1028                             VFPF_TPA_HDR_DATA_SPLIT_FLAG;
1029                 if (sge_tpa_params->tpa_gro_consistent_flg)
1030                         p_sge_tpa_tlv->sge_tpa_flags |=
1031                             VFPF_TPA_GRO_CONSIST_FLAG;
1032
1033                 p_sge_tpa_tlv->tpa_max_aggs_num =
1034                     sge_tpa_params->tpa_max_aggs_num;
1035                 p_sge_tpa_tlv->tpa_max_size = sge_tpa_params->tpa_max_size;
1036                 p_sge_tpa_tlv->tpa_min_size_to_start =
1037                     sge_tpa_params->tpa_min_size_to_start;
1038                 p_sge_tpa_tlv->tpa_min_size_to_cont =
1039                     sge_tpa_params->tpa_min_size_to_cont;
1040
1041                 p_sge_tpa_tlv->max_buffers_per_cqe =
1042                     sge_tpa_params->max_buffers_per_cqe;
1043         }
1044
1045         /* add list termination tlv */
1046         ecore_add_tlv(p_hwfn, &p_iov->offset,
1047                       CHANNEL_TLV_LIST_END,
1048                       sizeof(struct channel_list_end_tlv));
1049
1050         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
1051         if (rc)
1052                 goto exit;
1053
1054         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1055                 rc = ECORE_INVAL;
1056                 goto exit;
1057         }
1058
1059         ecore_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
1060
1061 exit:
1062         ecore_vf_pf_req_end(p_hwfn, rc);
1063
1064         return rc;
1065 }
1066
1067 enum _ecore_status_t ecore_vf_pf_reset(struct ecore_hwfn *p_hwfn)
1068 {
1069         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1070         struct pfvf_def_resp_tlv *resp;
1071         struct vfpf_first_tlv *req;
1072         enum _ecore_status_t rc;
1073
1074         /* clear mailbox and prep first tlv */
1075         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
1076
1077         /* add list termination tlv */
1078         ecore_add_tlv(p_hwfn, &p_iov->offset,
1079                       CHANNEL_TLV_LIST_END,
1080                       sizeof(struct channel_list_end_tlv));
1081
1082         resp = &p_iov->pf2vf_reply->default_resp;
1083         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1084         if (rc)
1085                 goto exit;
1086
1087         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1088                 rc = ECORE_AGAIN;
1089                 goto exit;
1090         }
1091
1092         p_hwfn->b_int_enabled = 0;
1093
1094 exit:
1095         ecore_vf_pf_req_end(p_hwfn, rc);
1096
1097         return rc;
1098 }
1099
1100 enum _ecore_status_t ecore_vf_pf_release(struct ecore_hwfn *p_hwfn)
1101 {
1102         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1103         struct pfvf_def_resp_tlv *resp;
1104         struct vfpf_first_tlv *req;
1105         enum _ecore_status_t rc;
1106         u32 size;
1107
1108         /* clear mailbox and prep first tlv */
1109         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
1110
1111         /* add list termination tlv */
1112         ecore_add_tlv(p_hwfn, &p_iov->offset,
1113                       CHANNEL_TLV_LIST_END,
1114                       sizeof(struct channel_list_end_tlv));
1115
1116         resp = &p_iov->pf2vf_reply->default_resp;
1117         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1118
1119         if (rc == ECORE_SUCCESS && resp->hdr.status != PFVF_STATUS_SUCCESS)
1120                 rc = ECORE_AGAIN;
1121
1122         ecore_vf_pf_req_end(p_hwfn, rc);
1123
1124         p_hwfn->b_int_enabled = 0;
1125
1126         if (p_iov->vf2pf_request)
1127                 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
1128                                        p_iov->vf2pf_request,
1129                                        p_iov->vf2pf_request_phys,
1130                                        sizeof(union vfpf_tlvs));
1131         if (p_iov->pf2vf_reply)
1132                 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
1133                                        p_iov->pf2vf_reply,
1134                                        p_iov->pf2vf_reply_phys,
1135                                        sizeof(union pfvf_tlvs));
1136
1137         if (p_iov->bulletin.p_virt) {
1138                 size = sizeof(struct ecore_bulletin_content);
1139                 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
1140                                        p_iov->bulletin.p_virt,
1141                                        p_iov->bulletin.phys, size);
1142         }
1143
1144         OSAL_FREE(p_hwfn->p_dev, p_hwfn->vf_iov_info);
1145
1146         return rc;
1147 }
1148
1149 void ecore_vf_pf_filter_mcast(struct ecore_hwfn *p_hwfn,
1150                               struct ecore_filter_mcast *p_filter_cmd)
1151 {
1152         struct ecore_sp_vport_update_params sp_params;
1153         int i;
1154
1155         OSAL_MEMSET(&sp_params, 0, sizeof(sp_params));
1156         sp_params.update_approx_mcast_flg = 1;
1157
1158         if (p_filter_cmd->opcode == ECORE_FILTER_ADD) {
1159                 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1160                         u32 bit;
1161
1162                         bit = ecore_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1163                         OSAL_SET_BIT(bit, sp_params.bins);
1164                 }
1165         }
1166
1167         ecore_vf_pf_vport_update(p_hwfn, &sp_params);
1168 }
1169
1170 enum _ecore_status_t ecore_vf_pf_filter_ucast(struct ecore_hwfn *p_hwfn,
1171                                               struct ecore_filter_ucast
1172                                               *p_ucast)
1173 {
1174         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1175         struct vfpf_ucast_filter_tlv *req;
1176         struct pfvf_def_resp_tlv *resp;
1177         enum _ecore_status_t rc;
1178
1179         /* Sanitize */
1180         if (p_ucast->opcode == ECORE_FILTER_MOVE) {
1181                 DP_NOTICE(p_hwfn, true,
1182                           "VFs don't support Moving of filters\n");
1183                 return ECORE_INVAL;
1184         }
1185
1186         /* clear mailbox and prep first tlv */
1187         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
1188         req->opcode = (u8)p_ucast->opcode;
1189         req->type = (u8)p_ucast->type;
1190         OSAL_MEMCPY(req->mac, p_ucast->mac, ETH_ALEN);
1191         req->vlan = p_ucast->vlan;
1192
1193         /* add list termination tlv */
1194         ecore_add_tlv(p_hwfn, &p_iov->offset,
1195                       CHANNEL_TLV_LIST_END,
1196                       sizeof(struct channel_list_end_tlv));
1197
1198         resp = &p_iov->pf2vf_reply->default_resp;
1199         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1200         if (rc)
1201                 goto exit;
1202
1203         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1204                 rc = ECORE_AGAIN;
1205                 goto exit;
1206         }
1207
1208 exit:
1209         ecore_vf_pf_req_end(p_hwfn, rc);
1210
1211         return rc;
1212 }
1213
1214 enum _ecore_status_t ecore_vf_pf_int_cleanup(struct ecore_hwfn *p_hwfn)
1215 {
1216         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1217         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
1218         enum _ecore_status_t rc;
1219
1220         /* clear mailbox and prep first tlv */
1221         ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
1222                          sizeof(struct vfpf_first_tlv));
1223
1224         /* add list termination tlv */
1225         ecore_add_tlv(p_hwfn, &p_iov->offset,
1226                       CHANNEL_TLV_LIST_END,
1227                       sizeof(struct channel_list_end_tlv));
1228
1229         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1230         if (rc)
1231                 goto exit;
1232
1233         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1234                 rc = ECORE_INVAL;
1235                 goto exit;
1236         }
1237
1238 exit:
1239         ecore_vf_pf_req_end(p_hwfn, rc);
1240
1241         return rc;
1242 }
1243
1244 u16 ecore_vf_get_igu_sb_id(struct ecore_hwfn *p_hwfn,
1245                            u16               sb_id)
1246 {
1247         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1248
1249         if (!p_iov) {
1250                 DP_NOTICE(p_hwfn, true, "vf_sriov_info isn't initialized\n");
1251                 return 0;
1252         }
1253
1254         return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
1255 }
1256
1257 enum _ecore_status_t ecore_vf_read_bulletin(struct ecore_hwfn *p_hwfn,
1258                                             u8 *p_change)
1259 {
1260         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1261         struct ecore_bulletin_content shadow;
1262         u32 crc, crc_size;
1263
1264         crc_size = sizeof(p_iov->bulletin.p_virt->crc);
1265         *p_change = 0;
1266
1267         /* Need to guarantee PF is not in the middle of writing it */
1268         OSAL_MEMCPY(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
1269
1270         /* If version did not update, no need to do anything */
1271         if (shadow.version == p_iov->bulletin_shadow.version)
1272                 return ECORE_SUCCESS;
1273
1274         /* Verify the bulletin we see is valid */
1275         crc = ecore_crc32(0, (u8 *)&shadow + crc_size,
1276                           p_iov->bulletin.size - crc_size);
1277         if (crc != shadow.crc)
1278                 return ECORE_AGAIN;
1279
1280         /* Set the shadow bulletin and process it */
1281         OSAL_MEMCPY(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
1282
1283         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1284                    "Read a bulletin update %08x\n", shadow.version);
1285
1286         *p_change = 1;
1287
1288         return ECORE_SUCCESS;
1289 }
1290
1291 void __ecore_vf_get_link_params(struct ecore_hwfn *p_hwfn,
1292                                 struct ecore_mcp_link_params *p_params,
1293                                 struct ecore_bulletin_content *p_bulletin)
1294 {
1295         OSAL_MEMSET(p_params, 0, sizeof(*p_params));
1296
1297         p_params->speed.autoneg = p_bulletin->req_autoneg;
1298         p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
1299         p_params->speed.forced_speed = p_bulletin->req_forced_speed;
1300         p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
1301         p_params->pause.forced_rx = p_bulletin->req_forced_rx;
1302         p_params->pause.forced_tx = p_bulletin->req_forced_tx;
1303         p_params->loopback_mode = p_bulletin->req_loopback;
1304 }
1305
1306 void ecore_vf_get_link_params(struct ecore_hwfn *p_hwfn,
1307                               struct ecore_mcp_link_params *params)
1308 {
1309         __ecore_vf_get_link_params(p_hwfn, params,
1310                                    &p_hwfn->vf_iov_info->bulletin_shadow);
1311 }
1312
1313 void __ecore_vf_get_link_state(struct ecore_hwfn *p_hwfn,
1314                                struct ecore_mcp_link_state *p_link,
1315                                struct ecore_bulletin_content *p_bulletin)
1316 {
1317         OSAL_MEMSET(p_link, 0, sizeof(*p_link));
1318
1319         p_link->link_up = p_bulletin->link_up;
1320         p_link->speed = p_bulletin->speed;
1321         p_link->full_duplex = p_bulletin->full_duplex;
1322         p_link->an = p_bulletin->autoneg;
1323         p_link->an_complete = p_bulletin->autoneg_complete;
1324         p_link->parallel_detection = p_bulletin->parallel_detection;
1325         p_link->pfc_enabled = p_bulletin->pfc_enabled;
1326         p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
1327         p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
1328         p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
1329         p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
1330         p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
1331 }
1332
1333 void ecore_vf_get_link_state(struct ecore_hwfn *p_hwfn,
1334                              struct ecore_mcp_link_state *link)
1335 {
1336         __ecore_vf_get_link_state(p_hwfn, link,
1337                                   &p_hwfn->vf_iov_info->bulletin_shadow);
1338 }
1339
1340 void __ecore_vf_get_link_caps(struct ecore_hwfn *p_hwfn,
1341                               struct ecore_mcp_link_capabilities *p_link_caps,
1342                               struct ecore_bulletin_content *p_bulletin)
1343 {
1344         OSAL_MEMSET(p_link_caps, 0, sizeof(*p_link_caps));
1345         p_link_caps->speed_capabilities = p_bulletin->capability_speed;
1346 }
1347
1348 void ecore_vf_get_link_caps(struct ecore_hwfn *p_hwfn,
1349                             struct ecore_mcp_link_capabilities *p_link_caps)
1350 {
1351         __ecore_vf_get_link_caps(p_hwfn, p_link_caps,
1352                                  &p_hwfn->vf_iov_info->bulletin_shadow);
1353 }
1354
1355 void ecore_vf_get_num_rxqs(struct ecore_hwfn *p_hwfn, u8 *num_rxqs)
1356 {
1357         *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
1358 }
1359
1360 void ecore_vf_get_port_mac(struct ecore_hwfn *p_hwfn, u8 *port_mac)
1361 {
1362         OSAL_MEMCPY(port_mac,
1363                     p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac,
1364                     ETH_ALEN);
1365 }
1366
1367 void ecore_vf_get_num_vlan_filters(struct ecore_hwfn *p_hwfn,
1368                                    u8 *num_vlan_filters)
1369 {
1370         struct ecore_vf_iov *p_vf;
1371
1372         p_vf = p_hwfn->vf_iov_info;
1373         *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
1374 }
1375
1376 void ecore_vf_get_num_sbs(struct ecore_hwfn *p_hwfn,
1377                           u32 *num_sbs)
1378 {
1379         struct ecore_vf_iov *p_vf;
1380
1381         p_vf = p_hwfn->vf_iov_info;
1382         *num_sbs = (u32)p_vf->acquire_resp.resc.num_sbs;
1383 }
1384
1385 void ecore_vf_get_num_mac_filters(struct ecore_hwfn *p_hwfn,
1386                                   u32 *num_mac_filters)
1387 {
1388         struct ecore_vf_iov *p_vf = p_hwfn->vf_iov_info;
1389
1390         *num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters;
1391 }
1392
1393 bool ecore_vf_check_mac(struct ecore_hwfn *p_hwfn, u8 *mac)
1394 {
1395         struct ecore_bulletin_content *bulletin;
1396
1397         bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1398         if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
1399                 return true;
1400
1401         /* Forbid VF from changing a MAC enforced by PF */
1402         if (OSAL_MEMCMP(bulletin->mac, mac, ETH_ALEN))
1403                 return false;
1404
1405         return false;
1406 }
1407
1408 bool ecore_vf_bulletin_get_forced_mac(struct ecore_hwfn *hwfn, u8 *dst_mac,
1409                                       u8 *p_is_forced)
1410 {
1411         struct ecore_bulletin_content *bulletin;
1412
1413         bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1414
1415         if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
1416                 if (p_is_forced)
1417                         *p_is_forced = 1;
1418         } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
1419                 if (p_is_forced)
1420                         *p_is_forced = 0;
1421         } else {
1422                 return false;
1423         }
1424
1425         OSAL_MEMCPY(dst_mac, bulletin->mac, ETH_ALEN);
1426
1427         return true;
1428 }
1429
1430 bool ecore_vf_bulletin_get_forced_vlan(struct ecore_hwfn *hwfn, u16 *dst_pvid)
1431 {
1432         struct ecore_bulletin_content *bulletin;
1433
1434         bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1435
1436         if (!(bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
1437                 return false;
1438
1439         if (dst_pvid)
1440                 *dst_pvid = bulletin->pvid;
1441
1442         return true;
1443 }
1444
1445 bool ecore_vf_get_pre_fp_hsi(struct ecore_hwfn *p_hwfn)
1446 {
1447         return p_hwfn->vf_iov_info->b_pre_fp_hsi;
1448 }
1449
1450 void ecore_vf_get_fw_version(struct ecore_hwfn *p_hwfn,
1451                              u16 *fw_major, u16 *fw_minor, u16 *fw_rev,
1452                              u16 *fw_eng)
1453 {
1454         struct pf_vf_pfdev_info *info;
1455
1456         info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
1457
1458         *fw_major = info->fw_major;
1459         *fw_minor = info->fw_minor;
1460         *fw_rev = info->fw_rev;
1461         *fw_eng = info->fw_eng;
1462 }