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