e84f97ac54284b61bd1b73467494ab5141b255f6
[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_iov->offset, type, length);
48
49         /* Init first tlv header */
50         ((struct vfpf_first_tlv *)p_tlv)->reply_address =
51             (u64)p_iov->pf2vf_reply_phys;
52
53         return p_tlv;
54 }
55
56 static void ecore_vf_pf_req_end(struct ecore_hwfn *p_hwfn,
57                                  enum _ecore_status_t req_status)
58 {
59         union pfvf_tlvs *resp = p_hwfn->vf_iov_info->pf2vf_reply;
60
61         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
62                    "VF request status = 0x%x, PF reply status = 0x%x\n",
63                    req_status, resp->default_resp.hdr.status);
64
65         OSAL_MUTEX_RELEASE(&p_hwfn->vf_iov_info->mutex);
66 }
67
68 static enum _ecore_status_t
69 ecore_send_msg2pf(struct ecore_hwfn *p_hwfn,
70                   u8 *done, u32 resp_size)
71 {
72         union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
73         struct ustorm_trigger_vf_zone trigger;
74         struct ustorm_vf_zone *zone_data;
75         enum _ecore_status_t rc = ECORE_SUCCESS;
76         int time = 100;
77
78         zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
79
80         /* output tlvs list */
81         ecore_dp_tlv_list(p_hwfn, p_req);
82
83         /* need to add the END TLV to the message size */
84         resp_size += sizeof(struct channel_list_end_tlv);
85
86         /* Send TLVs over HW channel */
87         OSAL_MEMSET(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
88         trigger.vf_pf_msg_valid = 1;
89
90         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
91                    "VF -> PF [%02x] message: [%08x, %08x] --> %p,"
92                    " %08x --> %p\n",
93                    GET_FIELD(p_hwfn->hw_info.concrete_fid,
94                              PXP_CONCRETE_FID_PFID),
95                    U64_HI(p_hwfn->vf_iov_info->vf2pf_request_phys),
96                    U64_LO(p_hwfn->vf_iov_info->vf2pf_request_phys),
97                    &zone_data->non_trigger.vf_pf_msg_addr,
98                    *((u32 *)&trigger), &zone_data->trigger);
99
100         REG_WR(p_hwfn,
101                (osal_uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
102                U64_LO(p_hwfn->vf_iov_info->vf2pf_request_phys));
103
104         REG_WR(p_hwfn,
105                (osal_uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
106                U64_HI(p_hwfn->vf_iov_info->vf2pf_request_phys));
107
108         /* The message data must be written first, to prevent trigger before
109          * data is written.
110          */
111         OSAL_WMB(p_hwfn->p_dev);
112
113         REG_WR(p_hwfn, (osal_uintptr_t)&zone_data->trigger,
114                *((u32 *)&trigger));
115
116         /* When PF would be done with the response, it would write back to the
117          * `done' address. Poll until then.
118          */
119         while ((!*done) && time) {
120                 OSAL_MSLEEP(25);
121                 time--;
122         }
123
124         if (!*done) {
125                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
126                            "VF <-- PF Timeout [Type %d]\n",
127                            p_req->first_tlv.tl.type);
128                 rc = ECORE_TIMEOUT;
129         } else {
130                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
131                            "PF response: %d [Type %d]\n",
132                            *done, p_req->first_tlv.tl.type);
133         }
134
135         return rc;
136 }
137
138 static void ecore_vf_pf_add_qid(struct ecore_hwfn *p_hwfn,
139                                 struct ecore_queue_cid *p_cid)
140 {
141         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
142         struct vfpf_qid_tlv *p_qid_tlv;
143
144         /* Only add QIDs for the queue if it was negotiated with PF */
145         if (!(p_iov->acquire_resp.pfdev_info.capabilities &
146               PFVF_ACQUIRE_CAP_QUEUE_QIDS))
147                 return;
148
149         p_qid_tlv = ecore_add_tlv(&p_iov->offset,
150                                   CHANNEL_TLV_QID, sizeof(*p_qid_tlv));
151         p_qid_tlv->qid = p_cid->qid_usage_idx;
152 }
153
154 #define VF_ACQUIRE_THRESH 3
155 static void ecore_vf_pf_acquire_reduce_resc(struct ecore_hwfn *p_hwfn,
156                                             struct vf_pf_resc_request *p_req,
157                                             struct pf_vf_resc *p_resp)
158 {
159         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
160                    "PF unwilling to fullill resource request: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x] cids [%02x/%02x]. Try PF recommended amount\n",
161                    p_req->num_rxqs, p_resp->num_rxqs,
162                    p_req->num_rxqs, p_resp->num_txqs,
163                    p_req->num_sbs, p_resp->num_sbs,
164                    p_req->num_mac_filters, p_resp->num_mac_filters,
165                    p_req->num_vlan_filters, p_resp->num_vlan_filters,
166                    p_req->num_mc_filters, p_resp->num_mc_filters,
167                    p_req->num_cids, p_resp->num_cids);
168
169         /* humble our request */
170         p_req->num_txqs = p_resp->num_txqs;
171         p_req->num_rxqs = p_resp->num_rxqs;
172         p_req->num_sbs = p_resp->num_sbs;
173         p_req->num_mac_filters = p_resp->num_mac_filters;
174         p_req->num_vlan_filters = p_resp->num_vlan_filters;
175         p_req->num_mc_filters = p_resp->num_mc_filters;
176         p_req->num_cids = p_resp->num_cids;
177 }
178
179 static enum _ecore_status_t ecore_vf_pf_acquire(struct ecore_hwfn *p_hwfn)
180 {
181         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
182         struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
183         struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
184         struct ecore_vf_acquire_sw_info vf_sw_info;
185         struct vf_pf_resc_request *p_resc;
186         bool resources_acquired = false;
187         struct vfpf_acquire_tlv *req;
188         int attempts = 0;
189         enum _ecore_status_t rc = ECORE_SUCCESS;
190
191         /* clear mailbox and prep first tlv */
192         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
193         p_resc = &req->resc_request;
194
195         /* @@@ TBD: PF may not be ready bnx2x_get_vf_id... */
196         req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
197
198         p_resc->num_rxqs = ECORE_MAX_VF_CHAINS_PER_PF;
199         p_resc->num_txqs = ECORE_MAX_VF_CHAINS_PER_PF;
200         p_resc->num_sbs = ECORE_MAX_VF_CHAINS_PER_PF;
201         p_resc->num_mac_filters = ECORE_ETH_VF_NUM_MAC_FILTERS;
202         p_resc->num_vlan_filters = ECORE_ETH_VF_NUM_VLAN_FILTERS;
203         p_resc->num_cids = ECORE_ETH_VF_DEFAULT_NUM_CIDS;
204
205         OSAL_MEMSET(&vf_sw_info, 0, sizeof(vf_sw_info));
206         OSAL_VF_FILL_ACQUIRE_RESC_REQ(p_hwfn, &req->resc_request, &vf_sw_info);
207
208         req->vfdev_info.os_type = vf_sw_info.os_type;
209         req->vfdev_info.driver_version = vf_sw_info.driver_version;
210         req->vfdev_info.fw_major = FW_MAJOR_VERSION;
211         req->vfdev_info.fw_minor = FW_MINOR_VERSION;
212         req->vfdev_info.fw_revision = FW_REVISION_VERSION;
213         req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
214         req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
215         req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR;
216
217         /* Fill capability field with any non-deprecated config we support */
218         req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
219
220         /* pf 2 vf bulletin board address */
221         req->bulletin_addr = p_iov->bulletin.phys;
222         req->bulletin_size = p_iov->bulletin.size;
223
224         /* add list termination tlv */
225         ecore_add_tlv(&p_iov->offset,
226                       CHANNEL_TLV_LIST_END,
227                       sizeof(struct channel_list_end_tlv));
228
229         while (!resources_acquired) {
230                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
231                            "attempting to acquire resources\n");
232
233                 /* Clear response buffer, as this might be a re-send */
234                 OSAL_MEMSET(p_iov->pf2vf_reply, 0,
235                             sizeof(union pfvf_tlvs));
236
237                 /* send acquire request */
238                 rc = ecore_send_msg2pf(p_hwfn,
239                                        &resp->hdr.status, sizeof(*resp));
240                 if (rc != ECORE_SUCCESS)
241                         goto exit;
242
243                 /* copy acquire response from buffer to p_hwfn */
244                 OSAL_MEMCPY(&p_iov->acquire_resp,
245                             resp, sizeof(p_iov->acquire_resp));
246
247                 attempts++;
248
249                 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
250                         /* PF agrees to allocate our resources */
251                         if (!(resp->pfdev_info.capabilities &
252                               PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
253                                 /* It's possible legacy PF mistakenly accepted;
254                                  * but we don't care - simply mark it as
255                                  * legacy and continue.
256                                  */
257                                 req->vfdev_info.capabilities |=
258                                         VFPF_ACQUIRE_CAP_PRE_FP_HSI;
259                         }
260                         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
261                                    "resources acquired\n");
262                         resources_acquired = true;
263                 } /* PF refuses to allocate our resources */
264                 else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
265                          attempts < VF_ACQUIRE_THRESH) {
266                         ecore_vf_pf_acquire_reduce_resc(p_hwfn, p_resc,
267                                                         &resp->resc);
268
269                 } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) {
270                         if (pfdev_info->major_fp_hsi &&
271                             (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) {
272                                 DP_NOTICE(p_hwfn, false,
273                                           "PF uses an incompatible fastpath HSI"
274                                           " %02x.%02x [VF requires %02x.%02x]."
275                                           " Please change to a VF driver using"
276                                           " %02x.xx.\n",
277                                           pfdev_info->major_fp_hsi,
278                                           pfdev_info->minor_fp_hsi,
279                                           ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR,
280                                           pfdev_info->major_fp_hsi);
281                                 rc = ECORE_INVAL;
282                                 goto exit;
283                         }
284
285                         if (!pfdev_info->major_fp_hsi) {
286                                 if (req->vfdev_info.capabilities &
287                                     VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
288                                         DP_NOTICE(p_hwfn, false,
289                                                   "PF uses very old drivers."
290                                                   " Please change to a VF"
291                                                   " driver using no later than"
292                                                   " 8.8.x.x.\n");
293                                         rc = ECORE_INVAL;
294                                         goto exit;
295                                 } else {
296                                         DP_INFO(p_hwfn,
297                                                 "PF is old - try re-acquire to"
298                                                 " see if it supports FW-version"
299                                                 " override\n");
300                                         req->vfdev_info.capabilities |=
301                                                 VFPF_ACQUIRE_CAP_PRE_FP_HSI;
302                                         continue;
303                                 }
304                         }
305
306                         /* If PF/VF are using same Major, PF must have had
307                          * it's reasons. Simply fail.
308                          */
309                         DP_NOTICE(p_hwfn, false,
310                                   "PF rejected acquisition by VF\n");
311                         rc = ECORE_INVAL;
312                         goto exit;
313                 } else {
314                         DP_ERR(p_hwfn,
315                                "PF returned err %d to VF acquisition request\n",
316                                resp->hdr.status);
317                         rc = ECORE_AGAIN;
318                         goto exit;
319                 }
320         }
321
322         /* Mark the PF as legacy, if needed */
323         if (req->vfdev_info.capabilities &
324             VFPF_ACQUIRE_CAP_PRE_FP_HSI)
325                 p_iov->b_pre_fp_hsi = true;
326
327         /* In case PF doesn't support multi-queue Tx, update the number of
328          * CIDs to reflect the number of queues [older PFs didn't fill that
329          * field].
330          */
331         if (!(resp->pfdev_info.capabilities &
332               PFVF_ACQUIRE_CAP_QUEUE_QIDS))
333                 resp->resc.num_cids = resp->resc.num_rxqs +
334                                       resp->resc.num_txqs;
335
336         rc = OSAL_VF_UPDATE_ACQUIRE_RESC_RESP(p_hwfn, &resp->resc);
337         if (rc) {
338                 DP_NOTICE(p_hwfn, true,
339                           "VF_UPDATE_ACQUIRE_RESC_RESP Failed:"
340                           " status = 0x%x.\n",
341                           rc);
342                 rc = ECORE_AGAIN;
343                 goto exit;
344         }
345
346         /* Update bulletin board size with response from PF */
347         p_iov->bulletin.size = resp->bulletin_size;
348
349         /* get HW info */
350         p_hwfn->p_dev->type = resp->pfdev_info.dev_type;
351         p_hwfn->p_dev->chip_rev = (u8)resp->pfdev_info.chip_rev;
352
353         DP_INFO(p_hwfn, "Chip details - %s%d\n",
354                 ECORE_IS_BB(p_hwfn->p_dev) ? "BB" : "AH",
355                 CHIP_REV_IS_A0(p_hwfn->p_dev) ? 0 : 1);
356
357         p_hwfn->p_dev->chip_num = pfdev_info->chip_num & 0xffff;
358
359         /* Learn of the possibility of CMT */
360         if (IS_LEAD_HWFN(p_hwfn)) {
361                 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
362                         DP_INFO(p_hwfn, "100g VF\n");
363                         p_hwfn->p_dev->num_hwfns = 2;
364                 }
365         }
366
367         /* @DPDK */
368         if ((~p_iov->b_pre_fp_hsi &
369             ETH_HSI_VER_MINOR) &&
370             (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR))
371                 DP_INFO(p_hwfn,
372                         "PF is using older fastpath HSI;"
373                         " %02x.%02x is configured\n",
374                         ETH_HSI_VER_MAJOR,
375                         resp->pfdev_info.minor_fp_hsi);
376
377 exit:
378         ecore_vf_pf_req_end(p_hwfn, rc);
379
380         return rc;
381 }
382
383 enum _ecore_status_t ecore_vf_hw_prepare(struct ecore_hwfn *p_hwfn)
384 {
385         struct ecore_vf_iov *p_iov;
386         u32 reg;
387
388         /* Set number of hwfns - might be overridden once leading hwfn learns
389          * actual configuration from PF.
390          */
391         if (IS_LEAD_HWFN(p_hwfn))
392                 p_hwfn->p_dev->num_hwfns = 1;
393
394         /* Set the doorbell bar. Assumption: regview is set */
395         p_hwfn->doorbells = (u8 OSAL_IOMEM *)p_hwfn->regview +
396             PXP_VF_BAR0_START_DQ;
397
398         reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
399         p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
400
401         reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
402         p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
403
404         /* Allocate vf sriov info */
405         p_iov = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_iov));
406         if (!p_iov) {
407                 DP_NOTICE(p_hwfn, true,
408                           "Failed to allocate `struct ecore_sriov'\n");
409                 return ECORE_NOMEM;
410         }
411
412         /* Allocate vf2pf msg */
413         p_iov->vf2pf_request = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
414                                                          &p_iov->
415                                                          vf2pf_request_phys,
416                                                          sizeof(union
417                                                                 vfpf_tlvs));
418         if (!p_iov->vf2pf_request) {
419                 DP_NOTICE(p_hwfn, true,
420                          "Failed to allocate `vf2pf_request' DMA memory\n");
421                 goto free_p_iov;
422         }
423
424         p_iov->pf2vf_reply = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
425                                                        &p_iov->
426                                                        pf2vf_reply_phys,
427                                                        sizeof(union pfvf_tlvs));
428         if (!p_iov->pf2vf_reply) {
429                 DP_NOTICE(p_hwfn, true,
430                           "Failed to allocate `pf2vf_reply' DMA memory\n");
431                 goto free_vf2pf_request;
432         }
433
434         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
435                    "VF's Request mailbox [%p virt 0x%lx phys], "
436                    "Response mailbox [%p virt 0x%lx phys]\n",
437                    p_iov->vf2pf_request,
438                    (unsigned long)p_iov->vf2pf_request_phys,
439                    p_iov->pf2vf_reply,
440                    (unsigned long)p_iov->pf2vf_reply_phys);
441
442         /* Allocate Bulletin board */
443         p_iov->bulletin.size = sizeof(struct ecore_bulletin_content);
444         p_iov->bulletin.p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
445                                                            &p_iov->bulletin.
446                                                            phys,
447                                                            p_iov->bulletin.
448                                                            size);
449         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
450                    "VF's bulletin Board [%p virt 0x%lx phys 0x%08x bytes]\n",
451                    p_iov->bulletin.p_virt, (unsigned long)p_iov->bulletin.phys,
452                    p_iov->bulletin.size);
453
454 #ifdef CONFIG_ECORE_LOCK_ALLOC
455         OSAL_MUTEX_ALLOC(p_hwfn, &p_iov->mutex);
456 #endif
457         OSAL_MUTEX_INIT(&p_iov->mutex);
458
459         p_hwfn->vf_iov_info = p_iov;
460
461         p_hwfn->hw_info.personality = ECORE_PCI_ETH;
462
463         return ecore_vf_pf_acquire(p_hwfn);
464
465 free_vf2pf_request:
466         OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev, p_iov->vf2pf_request,
467                                p_iov->vf2pf_request_phys,
468                                sizeof(union vfpf_tlvs));
469 free_p_iov:
470         OSAL_FREE(p_hwfn->p_dev, p_iov);
471
472         return ECORE_NOMEM;
473 }
474
475 #define TSTORM_QZONE_START   PXP_VF_BAR0_START_SDM_ZONE_A
476 #define MSTORM_QZONE_START(dev)   (TSTORM_QZONE_START + \
477                                    (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
478
479 /* @DPDK - changed enum ecore_tunn_clss to enum ecore_tunn_mode */
480 static void
481 __ecore_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
482                              struct ecore_tunn_update_type *p_src,
483                              enum ecore_tunn_mode mask, u8 *p_cls)
484 {
485         if (p_src->b_update_mode) {
486                 p_req->tun_mode_update_mask |= (1 << mask);
487
488                 if (p_src->b_mode_enabled)
489                         p_req->tunn_mode |= (1 << mask);
490         }
491
492         *p_cls = p_src->tun_cls;
493 }
494
495 /* @DPDK - changed enum ecore_tunn_clss to enum ecore_tunn_mode */
496 static void
497 ecore_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
498                            struct ecore_tunn_update_type *p_src,
499                            enum ecore_tunn_mode mask, u8 *p_cls,
500                            struct ecore_tunn_update_udp_port *p_port,
501                            u8 *p_update_port, u16 *p_udp_port)
502 {
503         if (p_port->b_update_port) {
504                 *p_update_port = 1;
505                 *p_udp_port = p_port->port;
506         }
507
508         __ecore_vf_prep_tunn_req_tlv(p_req, p_src, mask, p_cls);
509 }
510
511 void ecore_vf_set_vf_start_tunn_update_param(struct ecore_tunnel_info *p_tun)
512 {
513         if (p_tun->vxlan.b_mode_enabled)
514                 p_tun->vxlan.b_update_mode = true;
515         if (p_tun->l2_geneve.b_mode_enabled)
516                 p_tun->l2_geneve.b_update_mode = true;
517         if (p_tun->ip_geneve.b_mode_enabled)
518                 p_tun->ip_geneve.b_update_mode = true;
519         if (p_tun->l2_gre.b_mode_enabled)
520                 p_tun->l2_gre.b_update_mode = true;
521         if (p_tun->ip_gre.b_mode_enabled)
522                 p_tun->ip_gre.b_update_mode = true;
523
524         p_tun->b_update_rx_cls = true;
525         p_tun->b_update_tx_cls = true;
526 }
527
528 static void
529 __ecore_vf_update_tunn_param(struct ecore_tunn_update_type *p_tun,
530                              u16 feature_mask, u8 tunn_mode, u8 tunn_cls,
531                              enum ecore_tunn_mode val)
532 {
533         if (feature_mask & (1 << val)) {
534                 p_tun->b_mode_enabled = tunn_mode;
535                 p_tun->tun_cls = tunn_cls;
536         } else {
537                 p_tun->b_mode_enabled = false;
538         }
539 }
540
541 static void
542 ecore_vf_update_tunn_param(struct ecore_hwfn *p_hwfn,
543                            struct ecore_tunnel_info *p_tun,
544                            struct pfvf_update_tunn_param_tlv *p_resp)
545 {
546         /* Update mode and classes provided by PF */
547         u16 feat_mask = p_resp->tunn_feature_mask;
548
549         __ecore_vf_update_tunn_param(&p_tun->vxlan, feat_mask,
550                                      p_resp->vxlan_mode, p_resp->vxlan_clss,
551                                      ECORE_MODE_VXLAN_TUNN);
552         __ecore_vf_update_tunn_param(&p_tun->l2_geneve, feat_mask,
553                                      p_resp->l2geneve_mode,
554                                      p_resp->l2geneve_clss,
555                                      ECORE_MODE_L2GENEVE_TUNN);
556         __ecore_vf_update_tunn_param(&p_tun->ip_geneve, feat_mask,
557                                      p_resp->ipgeneve_mode,
558                                      p_resp->ipgeneve_clss,
559                                      ECORE_MODE_IPGENEVE_TUNN);
560         __ecore_vf_update_tunn_param(&p_tun->l2_gre, feat_mask,
561                                      p_resp->l2gre_mode, p_resp->l2gre_clss,
562                                      ECORE_MODE_L2GRE_TUNN);
563         __ecore_vf_update_tunn_param(&p_tun->ip_gre, feat_mask,
564                                      p_resp->ipgre_mode, p_resp->ipgre_clss,
565                                      ECORE_MODE_IPGRE_TUNN);
566         p_tun->geneve_port.port = p_resp->geneve_udp_port;
567         p_tun->vxlan_port.port = p_resp->vxlan_udp_port;
568
569         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
570                    "tunn mode: vxlan=0x%x, l2geneve=0x%x, ipgeneve=0x%x, l2gre=0x%x, ipgre=0x%x",
571                    p_tun->vxlan.b_mode_enabled, p_tun->l2_geneve.b_mode_enabled,
572                    p_tun->ip_geneve.b_mode_enabled,
573                    p_tun->l2_gre.b_mode_enabled,
574                    p_tun->ip_gre.b_mode_enabled);
575 }
576
577 enum _ecore_status_t
578 ecore_vf_pf_tunnel_param_update(struct ecore_hwfn *p_hwfn,
579                                 struct ecore_tunnel_info *p_src)
580 {
581         struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
582         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
583         struct pfvf_update_tunn_param_tlv *p_resp;
584         struct vfpf_update_tunn_param_tlv *p_req;
585         enum _ecore_status_t rc;
586
587         p_req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_TUNN_PARAM,
588                                  sizeof(*p_req));
589
590         if (p_src->b_update_rx_cls && p_src->b_update_tx_cls)
591                 p_req->update_tun_cls = 1;
592
593         ecore_vf_prep_tunn_req_tlv(p_req, &p_src->vxlan, ECORE_MODE_VXLAN_TUNN,
594                                    &p_req->vxlan_clss, &p_src->vxlan_port,
595                                    &p_req->update_vxlan_port,
596                                    &p_req->vxlan_port);
597         ecore_vf_prep_tunn_req_tlv(p_req, &p_src->l2_geneve,
598                                    ECORE_MODE_L2GENEVE_TUNN,
599                                    &p_req->l2geneve_clss, &p_src->geneve_port,
600                                    &p_req->update_geneve_port,
601                                    &p_req->geneve_port);
602         __ecore_vf_prep_tunn_req_tlv(p_req, &p_src->ip_geneve,
603                                      ECORE_MODE_IPGENEVE_TUNN,
604                                      &p_req->ipgeneve_clss);
605         __ecore_vf_prep_tunn_req_tlv(p_req, &p_src->l2_gre,
606                                      ECORE_MODE_L2GRE_TUNN, &p_req->l2gre_clss);
607         __ecore_vf_prep_tunn_req_tlv(p_req, &p_src->ip_gre,
608                                      ECORE_MODE_IPGRE_TUNN, &p_req->ipgre_clss);
609
610         /* add list termination tlv */
611         ecore_add_tlv(&p_iov->offset,
612                       CHANNEL_TLV_LIST_END,
613                       sizeof(struct channel_list_end_tlv));
614
615         p_resp = &p_iov->pf2vf_reply->tunn_param_resp;
616         rc = ecore_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
617
618         if (rc)
619                 goto exit;
620
621         if (p_resp->hdr.status != PFVF_STATUS_SUCCESS) {
622                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
623                            "Failed to update tunnel parameters\n");
624                 rc = ECORE_INVAL;
625         }
626
627         ecore_vf_update_tunn_param(p_hwfn, p_tun, p_resp);
628 exit:
629         ecore_vf_pf_req_end(p_hwfn, rc);
630         return rc;
631 }
632
633 enum _ecore_status_t
634 ecore_vf_pf_rxq_start(struct ecore_hwfn *p_hwfn,
635                       struct ecore_queue_cid *p_cid,
636                       u16 bd_max_bytes,
637                       dma_addr_t bd_chain_phys_addr,
638                       dma_addr_t cqe_pbl_addr,
639                       u16 cqe_pbl_size,
640                       void OSAL_IOMEM **pp_prod)
641 {
642         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
643         struct pfvf_start_queue_resp_tlv *resp;
644         struct vfpf_start_rxq_tlv *req;
645         u16 rx_qid = p_cid->rel.queue_id;
646         enum _ecore_status_t rc;
647
648         /* clear mailbox and prep first tlv */
649         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
650
651         req->rx_qid = rx_qid;
652         req->cqe_pbl_addr = cqe_pbl_addr;
653         req->cqe_pbl_size = cqe_pbl_size;
654         req->rxq_addr = bd_chain_phys_addr;
655         req->hw_sb = p_cid->sb_igu_id;
656         req->sb_index = p_cid->sb_idx;
657         req->bd_max_bytes = bd_max_bytes;
658         req->stat_id = -1; /* Keep initialized, for future compatibility */
659
660         /* If PF is legacy, we'll need to calculate producers ourselves
661          * as well as clean them.
662          */
663         if (p_iov->b_pre_fp_hsi) {
664                 u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
665                 u32 init_prod_val = 0;
666
667                 *pp_prod = (u8 OSAL_IOMEM *)
668                            p_hwfn->regview +
669                            MSTORM_QZONE_START(p_hwfn->p_dev) +
670                            (hw_qid) * MSTORM_QZONE_SIZE;
671
672                 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
673                 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
674                                   (u32 *)(&init_prod_val));
675         }
676
677         ecore_vf_pf_add_qid(p_hwfn, p_cid);
678
679         /* add list termination tlv */
680         ecore_add_tlv(&p_iov->offset,
681                       CHANNEL_TLV_LIST_END,
682                       sizeof(struct channel_list_end_tlv));
683
684         resp = &p_iov->pf2vf_reply->queue_start;
685         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
686         if (rc)
687                 goto exit;
688
689         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
690                 rc = ECORE_INVAL;
691                 goto exit;
692         }
693
694         /* Learn the address of the producer from the response */
695         if (!p_iov->b_pre_fp_hsi) {
696                 u32 init_prod_val = 0;
697
698                 *pp_prod = (u8 OSAL_IOMEM *)p_hwfn->regview + resp->offset;
699                 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
700                            "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
701                            rx_qid, *pp_prod, resp->offset);
702
703                 /* Init the rcq, rx bd and rx sge (if valid) producers to 0.
704                  * It was actually the PF's responsibility, but since some
705                  * old PFs might fail to do so, we do this as well.
706                  */
707                 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
708                 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
709                                   (u32 *)&init_prod_val);
710         }
711
712 exit:
713         ecore_vf_pf_req_end(p_hwfn, rc);
714
715         return rc;
716 }
717
718 enum _ecore_status_t ecore_vf_pf_rxq_stop(struct ecore_hwfn *p_hwfn,
719                                           struct ecore_queue_cid *p_cid,
720                                           bool cqe_completion)
721 {
722         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
723         struct vfpf_stop_rxqs_tlv *req;
724         struct pfvf_def_resp_tlv *resp;
725         enum _ecore_status_t rc;
726
727         /* clear mailbox and prep first tlv */
728         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
729
730         req->rx_qid = p_cid->rel.queue_id;
731         req->num_rxqs = 1;
732         req->cqe_completion = cqe_completion;
733
734         ecore_vf_pf_add_qid(p_hwfn, p_cid);
735
736         /* add list termination tlv */
737         ecore_add_tlv(&p_iov->offset,
738                       CHANNEL_TLV_LIST_END,
739                       sizeof(struct channel_list_end_tlv));
740
741         resp = &p_iov->pf2vf_reply->default_resp;
742         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
743         if (rc)
744                 goto exit;
745
746         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
747                 rc = ECORE_INVAL;
748                 goto exit;
749         }
750
751 exit:
752         ecore_vf_pf_req_end(p_hwfn, rc);
753
754         return rc;
755 }
756
757 enum _ecore_status_t
758 ecore_vf_pf_txq_start(struct ecore_hwfn *p_hwfn,
759                       struct ecore_queue_cid *p_cid,
760                       dma_addr_t pbl_addr, u16 pbl_size,
761                       void OSAL_IOMEM **pp_doorbell)
762 {
763         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
764         struct pfvf_start_queue_resp_tlv *resp;
765         struct vfpf_start_txq_tlv *req;
766         u16 qid = p_cid->rel.queue_id;
767         enum _ecore_status_t rc;
768
769         /* clear mailbox and prep first tlv */
770         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
771
772         req->tx_qid = qid;
773
774         /* Tx */
775         req->pbl_addr = pbl_addr;
776         req->pbl_size = pbl_size;
777         req->hw_sb = p_cid->sb_igu_id;
778         req->sb_index = p_cid->sb_idx;
779
780         ecore_vf_pf_add_qid(p_hwfn, p_cid);
781
782         /* add list termination tlv */
783         ecore_add_tlv(&p_iov->offset,
784                       CHANNEL_TLV_LIST_END,
785                       sizeof(struct channel_list_end_tlv));
786
787         resp  = &p_iov->pf2vf_reply->queue_start;
788         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
789         if (rc)
790                 goto exit;
791
792         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
793                 rc = ECORE_INVAL;
794                 goto exit;
795         }
796
797         /* Modern PFs provide the actual offsets, while legacy
798          * provided only the queue id.
799          */
800         if (!p_iov->b_pre_fp_hsi) {
801                 *pp_doorbell = (u8 OSAL_IOMEM *)p_hwfn->doorbells +
802                                                 resp->offset;
803         } else {
804                 u8 cid = p_iov->acquire_resp.resc.cid[qid];
805
806                 *pp_doorbell = (u8 OSAL_IOMEM *)p_hwfn->doorbells +
807                                                 DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
808         }
809
810         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
811                    "Txq[0x%02x]: doorbell at %p [offset 0x%08x]\n",
812                    qid, *pp_doorbell, resp->offset);
813 exit:
814         ecore_vf_pf_req_end(p_hwfn, rc);
815
816         return rc;
817 }
818
819 enum _ecore_status_t ecore_vf_pf_txq_stop(struct ecore_hwfn *p_hwfn,
820                                           struct ecore_queue_cid *p_cid)
821 {
822         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
823         struct vfpf_stop_txqs_tlv *req;
824         struct pfvf_def_resp_tlv *resp;
825         enum _ecore_status_t rc;
826
827         /* clear mailbox and prep first tlv */
828         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
829
830         req->tx_qid = p_cid->rel.queue_id;
831         req->num_txqs = 1;
832
833         ecore_vf_pf_add_qid(p_hwfn, p_cid);
834
835         /* add list termination tlv */
836         ecore_add_tlv(&p_iov->offset,
837                       CHANNEL_TLV_LIST_END,
838                       sizeof(struct channel_list_end_tlv));
839
840         resp = &p_iov->pf2vf_reply->default_resp;
841         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
842         if (rc)
843                 goto exit;
844
845         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
846                 rc = ECORE_INVAL;
847                 goto exit;
848         }
849
850 exit:
851         ecore_vf_pf_req_end(p_hwfn, rc);
852
853         return rc;
854 }
855
856 enum _ecore_status_t ecore_vf_pf_rxqs_update(struct ecore_hwfn *p_hwfn,
857                                              struct ecore_queue_cid **pp_cid,
858                                              u8 num_rxqs,
859                                              u8 comp_cqe_flg,
860                                              u8 comp_event_flg)
861 {
862         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
863         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
864         struct vfpf_update_rxq_tlv *req;
865         enum _ecore_status_t rc;
866
867         /* Starting with CHANNEL_TLV_QID and the need for additional queue
868          * information, this API stopped supporting multiple rxqs.
869          * TODO - remove this and change the API to accept a single queue-cid
870          * in a follow-up patch.
871          */
872         if (num_rxqs != 1) {
873                 DP_NOTICE(p_hwfn, true,
874                           "VFs can no longer update more than a single queue\n");
875                 return ECORE_INVAL;
876         }
877
878         /* clear mailbox and prep first tlv */
879         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_RXQ, sizeof(*req));
880
881         req->rx_qid = (*pp_cid)->rel.queue_id;
882         req->num_rxqs = 1;
883
884         if (comp_cqe_flg)
885                 req->flags |= VFPF_RXQ_UPD_COMPLETE_CQE_FLAG;
886         if (comp_event_flg)
887                 req->flags |= VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG;
888
889         ecore_vf_pf_add_qid(p_hwfn, *pp_cid);
890
891         /* add list termination tlv */
892         ecore_add_tlv(&p_iov->offset,
893                       CHANNEL_TLV_LIST_END,
894                       sizeof(struct channel_list_end_tlv));
895
896         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
897         if (rc)
898                 goto exit;
899
900         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
901                 rc = ECORE_INVAL;
902                 goto exit;
903         }
904
905 exit:
906         ecore_vf_pf_req_end(p_hwfn, rc);
907         return rc;
908 }
909
910 enum _ecore_status_t
911 ecore_vf_pf_vport_start(struct ecore_hwfn *p_hwfn, u8 vport_id,
912                         u16 mtu, u8 inner_vlan_removal,
913                         enum ecore_tpa_mode tpa_mode, u8 max_buffers_per_cqe,
914                         u8 only_untagged)
915 {
916         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
917         struct vfpf_vport_start_tlv *req;
918         struct pfvf_def_resp_tlv *resp;
919         enum _ecore_status_t rc;
920         int i;
921
922         /* clear mailbox and prep first tlv */
923         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
924
925         req->mtu = mtu;
926         req->vport_id = vport_id;
927         req->inner_vlan_removal = inner_vlan_removal;
928         req->tpa_mode = tpa_mode;
929         req->max_buffers_per_cqe = max_buffers_per_cqe;
930         req->only_untagged = only_untagged;
931
932         /* status blocks */
933         for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++) {
934                 struct ecore_sb_info *p_sb = p_hwfn->vf_iov_info->sbs_info[i];
935
936                 if (p_sb)
937                         req->sb_addr[i] = p_sb->sb_phys;
938         }
939
940         /* add list termination tlv */
941         ecore_add_tlv(&p_iov->offset,
942                       CHANNEL_TLV_LIST_END,
943                       sizeof(struct channel_list_end_tlv));
944
945         resp  = &p_iov->pf2vf_reply->default_resp;
946         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
947         if (rc)
948                 goto exit;
949
950         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
951                 rc = ECORE_INVAL;
952                 goto exit;
953         }
954
955 exit:
956         ecore_vf_pf_req_end(p_hwfn, rc);
957
958         return rc;
959 }
960
961 enum _ecore_status_t ecore_vf_pf_vport_stop(struct ecore_hwfn *p_hwfn)
962 {
963         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
964         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
965         enum _ecore_status_t rc;
966
967         /* clear mailbox and prep first tlv */
968         ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
969                          sizeof(struct vfpf_first_tlv));
970
971         /* add list termination tlv */
972         ecore_add_tlv(&p_iov->offset,
973                       CHANNEL_TLV_LIST_END,
974                       sizeof(struct channel_list_end_tlv));
975
976         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
977         if (rc)
978                 goto exit;
979
980         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
981                 rc = ECORE_INVAL;
982                 goto exit;
983         }
984
985 exit:
986         ecore_vf_pf_req_end(p_hwfn, rc);
987
988         return rc;
989 }
990
991 static bool
992 ecore_vf_handle_vp_update_is_needed(struct ecore_hwfn *p_hwfn,
993                                     struct ecore_sp_vport_update_params *p_data,
994                                     u16 tlv)
995 {
996         switch (tlv) {
997         case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
998                 return !!(p_data->update_vport_active_rx_flg ||
999                           p_data->update_vport_active_tx_flg);
1000         case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
1001 #ifndef ASIC_ONLY
1002                 /* FPGA doesn't have PVFC and so can't support tx-switching */
1003                 return !!(p_data->update_tx_switching_flg &&
1004                           !CHIP_REV_IS_FPGA(p_hwfn->p_dev));
1005 #else
1006                 return !!p_data->update_tx_switching_flg;
1007 #endif
1008         case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
1009                 return !!p_data->update_inner_vlan_removal_flg;
1010         case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
1011                 return !!p_data->update_accept_any_vlan_flg;
1012         case CHANNEL_TLV_VPORT_UPDATE_MCAST:
1013                 return !!p_data->update_approx_mcast_flg;
1014         case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
1015                 return !!(p_data->accept_flags.update_rx_mode_config ||
1016                           p_data->accept_flags.update_tx_mode_config);
1017         case CHANNEL_TLV_VPORT_UPDATE_RSS:
1018                 return !!p_data->rss_params;
1019         case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
1020                 return !!p_data->sge_tpa_params;
1021         default:
1022                 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d] %s\n",
1023                         tlv, ecore_channel_tlvs_string[tlv]);
1024                 return false;
1025         }
1026 }
1027
1028 static void
1029 ecore_vf_handle_vp_update_tlvs_resp(struct ecore_hwfn *p_hwfn,
1030                                     struct ecore_sp_vport_update_params *p_data)
1031 {
1032         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1033         struct pfvf_def_resp_tlv *p_resp;
1034         u16 tlv;
1035
1036         for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1037              tlv < CHANNEL_TLV_VPORT_UPDATE_MAX;
1038              tlv++) {
1039                 if (!ecore_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
1040                         continue;
1041
1042                 p_resp = (struct pfvf_def_resp_tlv *)
1043                     ecore_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply, tlv);
1044                 if (p_resp && p_resp->hdr.status)
1045                         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1046                                    "TLV[%d] type %s Configuration %s\n",
1047                                    tlv, ecore_channel_tlvs_string[tlv],
1048                                    (p_resp && p_resp->hdr.status) ? "succeeded"
1049                                                                   : "failed");
1050         }
1051 }
1052
1053 enum _ecore_status_t
1054 ecore_vf_pf_vport_update(struct ecore_hwfn *p_hwfn,
1055                          struct ecore_sp_vport_update_params *p_params)
1056 {
1057         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1058         struct vfpf_vport_update_tlv *req;
1059         struct pfvf_def_resp_tlv *resp;
1060         u8 update_rx, update_tx;
1061         u32 resp_size = 0;
1062         u16 size, tlv;
1063         enum _ecore_status_t rc;
1064
1065         resp = &p_iov->pf2vf_reply->default_resp;
1066         resp_size = sizeof(*resp);
1067
1068         update_rx = p_params->update_vport_active_rx_flg;
1069         update_tx = p_params->update_vport_active_tx_flg;
1070
1071         /* clear mailbox and prep header tlv */
1072         ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
1073
1074         /* Prepare extended tlvs */
1075         if (update_rx || update_tx) {
1076                 struct vfpf_vport_update_activate_tlv *p_act_tlv;
1077
1078                 size = sizeof(struct vfpf_vport_update_activate_tlv);
1079                 p_act_tlv = ecore_add_tlv(&p_iov->offset,
1080                                           CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
1081                                           size);
1082                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1083
1084                 if (update_rx) {
1085                         p_act_tlv->update_rx = update_rx;
1086                         p_act_tlv->active_rx = p_params->vport_active_rx_flg;
1087                 }
1088
1089                 if (update_tx) {
1090                         p_act_tlv->update_tx = update_tx;
1091                         p_act_tlv->active_tx = p_params->vport_active_tx_flg;
1092                 }
1093         }
1094
1095         if (p_params->update_inner_vlan_removal_flg) {
1096                 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
1097
1098                 size = sizeof(struct vfpf_vport_update_vlan_strip_tlv);
1099                 p_vlan_tlv = ecore_add_tlv(&p_iov->offset,
1100                                            CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP,
1101                                            size);
1102                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1103
1104                 p_vlan_tlv->remove_vlan = p_params->inner_vlan_removal_flg;
1105         }
1106
1107         if (p_params->update_tx_switching_flg) {
1108                 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
1109
1110                 size = sizeof(struct vfpf_vport_update_tx_switch_tlv);
1111                 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1112                 p_tx_switch_tlv = ecore_add_tlv(&p_iov->offset,
1113                                                 tlv, size);
1114                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1115
1116                 p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg;
1117         }
1118
1119         if (p_params->update_approx_mcast_flg) {
1120                 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
1121
1122                 size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
1123                 p_mcast_tlv = ecore_add_tlv(&p_iov->offset,
1124                                             CHANNEL_TLV_VPORT_UPDATE_MCAST,
1125                                             size);
1126                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1127
1128                 OSAL_MEMCPY(p_mcast_tlv->bins, p_params->bins,
1129                             sizeof(unsigned long) *
1130                             ETH_MULTICAST_MAC_BINS_IN_REGS);
1131         }
1132
1133         update_rx = p_params->accept_flags.update_rx_mode_config;
1134         update_tx = p_params->accept_flags.update_tx_mode_config;
1135
1136         if (update_rx || update_tx) {
1137                 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
1138
1139                 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1140                 size = sizeof(struct vfpf_vport_update_accept_param_tlv);
1141                 p_accept_tlv = ecore_add_tlv(&p_iov->offset, tlv, size);
1142                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1143
1144                 if (update_rx) {
1145                         p_accept_tlv->update_rx_mode = update_rx;
1146                         p_accept_tlv->rx_accept_filter =
1147                             p_params->accept_flags.rx_accept_filter;
1148                 }
1149
1150                 if (update_tx) {
1151                         p_accept_tlv->update_tx_mode = update_tx;
1152                         p_accept_tlv->tx_accept_filter =
1153                             p_params->accept_flags.tx_accept_filter;
1154                 }
1155         }
1156
1157         if (p_params->rss_params) {
1158                 struct ecore_rss_params *rss_params = p_params->rss_params;
1159                 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
1160                 int i, table_size;
1161
1162                 size = sizeof(struct vfpf_vport_update_rss_tlv);
1163                 p_rss_tlv = ecore_add_tlv(&p_iov->offset,
1164                                           CHANNEL_TLV_VPORT_UPDATE_RSS, size);
1165                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1166
1167                 if (rss_params->update_rss_config)
1168                         p_rss_tlv->update_rss_flags |=
1169                             VFPF_UPDATE_RSS_CONFIG_FLAG;
1170                 if (rss_params->update_rss_capabilities)
1171                         p_rss_tlv->update_rss_flags |=
1172                             VFPF_UPDATE_RSS_CAPS_FLAG;
1173                 if (rss_params->update_rss_ind_table)
1174                         p_rss_tlv->update_rss_flags |=
1175                             VFPF_UPDATE_RSS_IND_TABLE_FLAG;
1176                 if (rss_params->update_rss_key)
1177                         p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
1178
1179                 p_rss_tlv->rss_enable = rss_params->rss_enable;
1180                 p_rss_tlv->rss_caps = rss_params->rss_caps;
1181                 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
1182
1183                 table_size = OSAL_MIN_T(int, T_ETH_INDIRECTION_TABLE_SIZE,
1184                                         1 << p_rss_tlv->rss_table_size_log);
1185                 for (i = 0; i < table_size; i++) {
1186                         struct ecore_queue_cid *p_queue;
1187
1188                         p_queue = rss_params->rss_ind_table[i];
1189                         p_rss_tlv->rss_ind_table[i] = p_queue->rel.queue_id;
1190                 }
1191
1192                 OSAL_MEMCPY(p_rss_tlv->rss_key, rss_params->rss_key,
1193                             sizeof(rss_params->rss_key));
1194         }
1195
1196         if (p_params->update_accept_any_vlan_flg) {
1197                 struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
1198
1199                 size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
1200                 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1201                 p_any_vlan_tlv = ecore_add_tlv(&p_iov->offset, tlv, size);
1202
1203                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1204                 p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
1205                 p_any_vlan_tlv->update_accept_any_vlan_flg =
1206                     p_params->update_accept_any_vlan_flg;
1207         }
1208
1209         if (p_params->sge_tpa_params) {
1210                 struct ecore_sge_tpa_params *sge_tpa_params;
1211                 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
1212
1213                 sge_tpa_params = p_params->sge_tpa_params;
1214                 size = sizeof(struct vfpf_vport_update_sge_tpa_tlv);
1215                 p_sge_tpa_tlv = ecore_add_tlv(&p_iov->offset,
1216                                               CHANNEL_TLV_VPORT_UPDATE_SGE_TPA,
1217                                               size);
1218                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1219
1220                 if (sge_tpa_params->update_tpa_en_flg)
1221                         p_sge_tpa_tlv->update_sge_tpa_flags |=
1222                             VFPF_UPDATE_TPA_EN_FLAG;
1223                 if (sge_tpa_params->update_tpa_param_flg)
1224                         p_sge_tpa_tlv->update_sge_tpa_flags |=
1225                             VFPF_UPDATE_TPA_PARAM_FLAG;
1226
1227                 if (sge_tpa_params->tpa_ipv4_en_flg)
1228                         p_sge_tpa_tlv->sge_tpa_flags |= VFPF_TPA_IPV4_EN_FLAG;
1229                 if (sge_tpa_params->tpa_ipv6_en_flg)
1230                         p_sge_tpa_tlv->sge_tpa_flags |= VFPF_TPA_IPV6_EN_FLAG;
1231                 if (sge_tpa_params->tpa_pkt_split_flg)
1232                         p_sge_tpa_tlv->sge_tpa_flags |= VFPF_TPA_PKT_SPLIT_FLAG;
1233                 if (sge_tpa_params->tpa_hdr_data_split_flg)
1234                         p_sge_tpa_tlv->sge_tpa_flags |=
1235                             VFPF_TPA_HDR_DATA_SPLIT_FLAG;
1236                 if (sge_tpa_params->tpa_gro_consistent_flg)
1237                         p_sge_tpa_tlv->sge_tpa_flags |=
1238                             VFPF_TPA_GRO_CONSIST_FLAG;
1239
1240                 p_sge_tpa_tlv->tpa_max_aggs_num =
1241                     sge_tpa_params->tpa_max_aggs_num;
1242                 p_sge_tpa_tlv->tpa_max_size = sge_tpa_params->tpa_max_size;
1243                 p_sge_tpa_tlv->tpa_min_size_to_start =
1244                     sge_tpa_params->tpa_min_size_to_start;
1245                 p_sge_tpa_tlv->tpa_min_size_to_cont =
1246                     sge_tpa_params->tpa_min_size_to_cont;
1247
1248                 p_sge_tpa_tlv->max_buffers_per_cqe =
1249                     sge_tpa_params->max_buffers_per_cqe;
1250         }
1251
1252         /* add list termination tlv */
1253         ecore_add_tlv(&p_iov->offset,
1254                       CHANNEL_TLV_LIST_END,
1255                       sizeof(struct channel_list_end_tlv));
1256
1257         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
1258         if (rc)
1259                 goto exit;
1260
1261         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1262                 rc = ECORE_INVAL;
1263                 goto exit;
1264         }
1265
1266         ecore_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
1267
1268 exit:
1269         ecore_vf_pf_req_end(p_hwfn, rc);
1270
1271         return rc;
1272 }
1273
1274 enum _ecore_status_t ecore_vf_pf_reset(struct ecore_hwfn *p_hwfn)
1275 {
1276         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1277         struct pfvf_def_resp_tlv *resp;
1278         struct vfpf_first_tlv *req;
1279         enum _ecore_status_t rc;
1280
1281         /* clear mailbox and prep first tlv */
1282         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
1283
1284         /* add list termination tlv */
1285         ecore_add_tlv(&p_iov->offset,
1286                       CHANNEL_TLV_LIST_END,
1287                       sizeof(struct channel_list_end_tlv));
1288
1289         resp = &p_iov->pf2vf_reply->default_resp;
1290         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1291         if (rc)
1292                 goto exit;
1293
1294         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1295                 rc = ECORE_AGAIN;
1296                 goto exit;
1297         }
1298
1299         p_hwfn->b_int_enabled = 0;
1300
1301 exit:
1302         ecore_vf_pf_req_end(p_hwfn, rc);
1303
1304         return rc;
1305 }
1306
1307 enum _ecore_status_t ecore_vf_pf_release(struct ecore_hwfn *p_hwfn)
1308 {
1309         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1310         struct pfvf_def_resp_tlv *resp;
1311         struct vfpf_first_tlv *req;
1312         u32 size;
1313         enum _ecore_status_t rc;
1314
1315         /* clear mailbox and prep first tlv */
1316         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
1317
1318         /* add list termination tlv */
1319         ecore_add_tlv(&p_iov->offset,
1320                       CHANNEL_TLV_LIST_END,
1321                       sizeof(struct channel_list_end_tlv));
1322
1323         resp = &p_iov->pf2vf_reply->default_resp;
1324         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1325
1326         if (rc == ECORE_SUCCESS && resp->hdr.status != PFVF_STATUS_SUCCESS)
1327                 rc = ECORE_AGAIN;
1328
1329         ecore_vf_pf_req_end(p_hwfn, rc);
1330
1331         p_hwfn->b_int_enabled = 0;
1332
1333         if (p_iov->vf2pf_request)
1334                 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
1335                                        p_iov->vf2pf_request,
1336                                        p_iov->vf2pf_request_phys,
1337                                        sizeof(union vfpf_tlvs));
1338         if (p_iov->pf2vf_reply)
1339                 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
1340                                        p_iov->pf2vf_reply,
1341                                        p_iov->pf2vf_reply_phys,
1342                                        sizeof(union pfvf_tlvs));
1343
1344         if (p_iov->bulletin.p_virt) {
1345                 size = sizeof(struct ecore_bulletin_content);
1346                 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
1347                                        p_iov->bulletin.p_virt,
1348                                        p_iov->bulletin.phys, size);
1349         }
1350
1351 #ifdef CONFIG_ECORE_LOCK_ALLOC
1352         OSAL_MUTEX_DEALLOC(&p_iov->mutex);
1353 #endif
1354
1355         OSAL_FREE(p_hwfn->p_dev, p_hwfn->vf_iov_info);
1356
1357         return rc;
1358 }
1359
1360 void ecore_vf_pf_filter_mcast(struct ecore_hwfn *p_hwfn,
1361                               struct ecore_filter_mcast *p_filter_cmd)
1362 {
1363         struct ecore_sp_vport_update_params sp_params;
1364         int i;
1365
1366         OSAL_MEMSET(&sp_params, 0, sizeof(sp_params));
1367         sp_params.update_approx_mcast_flg = 1;
1368
1369         if (p_filter_cmd->opcode == ECORE_FILTER_ADD) {
1370                 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1371                         u32 bit;
1372
1373                         bit = ecore_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1374                         OSAL_SET_BIT(bit, sp_params.bins);
1375                 }
1376         }
1377
1378         ecore_vf_pf_vport_update(p_hwfn, &sp_params);
1379 }
1380
1381 enum _ecore_status_t ecore_vf_pf_filter_ucast(struct ecore_hwfn *p_hwfn,
1382                                               struct ecore_filter_ucast
1383                                               *p_ucast)
1384 {
1385         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1386         struct vfpf_ucast_filter_tlv *req;
1387         struct pfvf_def_resp_tlv *resp;
1388         enum _ecore_status_t rc;
1389
1390         /* Sanitize */
1391         if (p_ucast->opcode == ECORE_FILTER_MOVE) {
1392                 DP_NOTICE(p_hwfn, true,
1393                           "VFs don't support Moving of filters\n");
1394                 return ECORE_INVAL;
1395         }
1396
1397         /* clear mailbox and prep first tlv */
1398         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
1399         req->opcode = (u8)p_ucast->opcode;
1400         req->type = (u8)p_ucast->type;
1401         OSAL_MEMCPY(req->mac, p_ucast->mac, ETH_ALEN);
1402         req->vlan = p_ucast->vlan;
1403
1404         /* add list termination tlv */
1405         ecore_add_tlv(&p_iov->offset,
1406                       CHANNEL_TLV_LIST_END,
1407                       sizeof(struct channel_list_end_tlv));
1408
1409         resp = &p_iov->pf2vf_reply->default_resp;
1410         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1411         if (rc)
1412                 goto exit;
1413
1414         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1415                 rc = ECORE_AGAIN;
1416                 goto exit;
1417         }
1418
1419 exit:
1420         ecore_vf_pf_req_end(p_hwfn, rc);
1421
1422         return rc;
1423 }
1424
1425 enum _ecore_status_t ecore_vf_pf_int_cleanup(struct ecore_hwfn *p_hwfn)
1426 {
1427         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1428         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
1429         enum _ecore_status_t rc;
1430
1431         /* clear mailbox and prep first tlv */
1432         ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
1433                          sizeof(struct vfpf_first_tlv));
1434
1435         /* add list termination tlv */
1436         ecore_add_tlv(&p_iov->offset,
1437                       CHANNEL_TLV_LIST_END,
1438                       sizeof(struct channel_list_end_tlv));
1439
1440         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1441         if (rc)
1442                 goto exit;
1443
1444         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1445                 rc = ECORE_INVAL;
1446                 goto exit;
1447         }
1448
1449 exit:
1450         ecore_vf_pf_req_end(p_hwfn, rc);
1451
1452         return rc;
1453 }
1454
1455 enum _ecore_status_t ecore_vf_pf_get_coalesce(struct ecore_hwfn *p_hwfn,
1456                                               u16 *p_coal,
1457                                               struct ecore_queue_cid *p_cid)
1458 {
1459         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1460         struct pfvf_read_coal_resp_tlv *resp;
1461         struct vfpf_read_coal_req_tlv *req;
1462         enum _ecore_status_t rc;
1463
1464         /* clear mailbox and prep header tlv */
1465         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_READ,
1466                                sizeof(*req));
1467         req->qid = p_cid->rel.queue_id;
1468         req->is_rx = p_cid->b_is_rx ? 1 : 0;
1469
1470         ecore_add_tlv(&p_iov->offset, CHANNEL_TLV_LIST_END,
1471                       sizeof(struct channel_list_end_tlv));
1472         resp = &p_iov->pf2vf_reply->read_coal_resp;
1473
1474         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1475         if (rc != ECORE_SUCCESS)
1476                 goto exit;
1477
1478         if (resp->hdr.status != PFVF_STATUS_SUCCESS)
1479                 goto exit;
1480
1481         *p_coal = resp->coal;
1482 exit:
1483         ecore_vf_pf_req_end(p_hwfn, rc);
1484
1485         return rc;
1486 }
1487
1488 enum _ecore_status_t
1489 ecore_vf_pf_set_coalesce(struct ecore_hwfn *p_hwfn, u16 rx_coal, u16 tx_coal,
1490                          struct ecore_queue_cid     *p_cid)
1491 {
1492         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1493         struct vfpf_update_coalesce *req;
1494         struct pfvf_def_resp_tlv *resp;
1495         enum _ecore_status_t rc;
1496
1497         /* clear mailbox and prep header tlv */
1498         req = ecore_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_UPDATE,
1499                                sizeof(*req));
1500
1501         req->rx_coal = rx_coal;
1502         req->tx_coal = tx_coal;
1503         req->qid = p_cid->rel.queue_id;
1504
1505         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1506                    "Setting coalesce rx_coal = %d, tx_coal = %d at queue = %d\n",
1507                    rx_coal, tx_coal, req->qid);
1508
1509         /* add list termination tlv */
1510         ecore_add_tlv(&p_iov->offset, CHANNEL_TLV_LIST_END,
1511                       sizeof(struct channel_list_end_tlv));
1512
1513         resp = &p_iov->pf2vf_reply->default_resp;
1514         rc = ecore_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1515
1516         if (rc != ECORE_SUCCESS)
1517                 goto exit;
1518
1519         if (resp->hdr.status != PFVF_STATUS_SUCCESS)
1520                 goto exit;
1521
1522         p_hwfn->p_dev->rx_coalesce_usecs = rx_coal;
1523         p_hwfn->p_dev->tx_coalesce_usecs = tx_coal;
1524
1525 exit:
1526         ecore_vf_pf_req_end(p_hwfn, rc);
1527         return rc;
1528 }
1529
1530 u16 ecore_vf_get_igu_sb_id(struct ecore_hwfn *p_hwfn,
1531                            u16               sb_id)
1532 {
1533         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1534
1535         if (!p_iov) {
1536                 DP_NOTICE(p_hwfn, true, "vf_sriov_info isn't initialized\n");
1537                 return 0;
1538         }
1539
1540         return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
1541 }
1542
1543 void ecore_vf_set_sb_info(struct ecore_hwfn *p_hwfn,
1544                           u16 sb_id, struct ecore_sb_info *p_sb)
1545 {
1546         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1547
1548         if (!p_iov) {
1549                 DP_NOTICE(p_hwfn, true, "vf_sriov_info isn't initialized\n");
1550                 return;
1551         }
1552
1553         if (sb_id >= PFVF_MAX_SBS_PER_VF) {
1554                 DP_NOTICE(p_hwfn, true, "Can't configure SB %04x\n", sb_id);
1555                 return;
1556         }
1557
1558         p_iov->sbs_info[sb_id] = p_sb;
1559 }
1560
1561 enum _ecore_status_t ecore_vf_read_bulletin(struct ecore_hwfn *p_hwfn,
1562                                             u8 *p_change)
1563 {
1564         struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1565         struct ecore_bulletin_content shadow;
1566         u32 crc, crc_size;
1567
1568         crc_size = sizeof(p_iov->bulletin.p_virt->crc);
1569         *p_change = 0;
1570
1571         /* Need to guarantee PF is not in the middle of writing it */
1572         OSAL_MEMCPY(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
1573
1574         /* If version did not update, no need to do anything */
1575         if (shadow.version == p_iov->bulletin_shadow.version)
1576                 return ECORE_SUCCESS;
1577
1578         /* Verify the bulletin we see is valid */
1579         crc = OSAL_CRC32(0, (u8 *)&shadow + crc_size,
1580                          p_iov->bulletin.size - crc_size);
1581         if (crc != shadow.crc)
1582                 return ECORE_AGAIN;
1583
1584         /* Set the shadow bulletin and process it */
1585         OSAL_MEMCPY(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
1586
1587         DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1588                    "Read a bulletin update %08x\n", shadow.version);
1589
1590         *p_change = 1;
1591
1592         return ECORE_SUCCESS;
1593 }
1594
1595 void __ecore_vf_get_link_params(struct ecore_mcp_link_params *p_params,
1596                                 struct ecore_bulletin_content *p_bulletin)
1597 {
1598         OSAL_MEMSET(p_params, 0, sizeof(*p_params));
1599
1600         p_params->speed.autoneg = p_bulletin->req_autoneg;
1601         p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
1602         p_params->speed.forced_speed = p_bulletin->req_forced_speed;
1603         p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
1604         p_params->pause.forced_rx = p_bulletin->req_forced_rx;
1605         p_params->pause.forced_tx = p_bulletin->req_forced_tx;
1606         p_params->loopback_mode = p_bulletin->req_loopback;
1607 }
1608
1609 void ecore_vf_get_link_params(struct ecore_hwfn *p_hwfn,
1610                               struct ecore_mcp_link_params *params)
1611 {
1612         __ecore_vf_get_link_params(params,
1613                                    &p_hwfn->vf_iov_info->bulletin_shadow);
1614 }
1615
1616 void __ecore_vf_get_link_state(struct ecore_mcp_link_state *p_link,
1617                                struct ecore_bulletin_content *p_bulletin)
1618 {
1619         OSAL_MEMSET(p_link, 0, sizeof(*p_link));
1620
1621         p_link->link_up = p_bulletin->link_up;
1622         p_link->speed = p_bulletin->speed;
1623         p_link->full_duplex = p_bulletin->full_duplex;
1624         p_link->an = p_bulletin->autoneg;
1625         p_link->an_complete = p_bulletin->autoneg_complete;
1626         p_link->parallel_detection = p_bulletin->parallel_detection;
1627         p_link->pfc_enabled = p_bulletin->pfc_enabled;
1628         p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
1629         p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
1630         p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
1631         p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
1632         p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
1633 }
1634
1635 void ecore_vf_get_link_state(struct ecore_hwfn *p_hwfn,
1636                              struct ecore_mcp_link_state *link)
1637 {
1638         __ecore_vf_get_link_state(link,
1639                                   &p_hwfn->vf_iov_info->bulletin_shadow);
1640 }
1641
1642 void __ecore_vf_get_link_caps(struct ecore_mcp_link_capabilities *p_link_caps,
1643                               struct ecore_bulletin_content *p_bulletin)
1644 {
1645         OSAL_MEMSET(p_link_caps, 0, sizeof(*p_link_caps));
1646         p_link_caps->speed_capabilities = p_bulletin->capability_speed;
1647 }
1648
1649 void ecore_vf_get_link_caps(struct ecore_hwfn *p_hwfn,
1650                             struct ecore_mcp_link_capabilities *p_link_caps)
1651 {
1652         __ecore_vf_get_link_caps(p_link_caps,
1653                                  &p_hwfn->vf_iov_info->bulletin_shadow);
1654 }
1655
1656 void ecore_vf_get_num_rxqs(struct ecore_hwfn *p_hwfn, u8 *num_rxqs)
1657 {
1658         *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
1659 }
1660
1661 void ecore_vf_get_num_txqs(struct ecore_hwfn *p_hwfn,
1662                            u8 *num_txqs)
1663 {
1664         *num_txqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_txqs;
1665 }
1666
1667 void ecore_vf_get_port_mac(struct ecore_hwfn *p_hwfn, u8 *port_mac)
1668 {
1669         OSAL_MEMCPY(port_mac,
1670                     p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac,
1671                     ETH_ALEN);
1672 }
1673
1674 void ecore_vf_get_num_vlan_filters(struct ecore_hwfn *p_hwfn,
1675                                    u8 *num_vlan_filters)
1676 {
1677         struct ecore_vf_iov *p_vf;
1678
1679         p_vf = p_hwfn->vf_iov_info;
1680         *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
1681 }
1682
1683 void ecore_vf_get_num_sbs(struct ecore_hwfn *p_hwfn,
1684                           u32 *num_sbs)
1685 {
1686         struct ecore_vf_iov *p_vf;
1687
1688         p_vf = p_hwfn->vf_iov_info;
1689         *num_sbs = (u32)p_vf->acquire_resp.resc.num_sbs;
1690 }
1691
1692 void ecore_vf_get_num_mac_filters(struct ecore_hwfn *p_hwfn,
1693                                   u32 *num_mac_filters)
1694 {
1695         struct ecore_vf_iov *p_vf = p_hwfn->vf_iov_info;
1696
1697         *num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters;
1698 }
1699
1700 bool ecore_vf_check_mac(struct ecore_hwfn *p_hwfn, u8 *mac)
1701 {
1702         struct ecore_bulletin_content *bulletin;
1703
1704         bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1705         if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
1706                 return true;
1707
1708         /* Forbid VF from changing a MAC enforced by PF */
1709         if (OSAL_MEMCMP(bulletin->mac, mac, ETH_ALEN))
1710                 return false;
1711
1712         return false;
1713 }
1714
1715 bool ecore_vf_bulletin_get_forced_mac(struct ecore_hwfn *hwfn, u8 *dst_mac,
1716                                       u8 *p_is_forced)
1717 {
1718         struct ecore_bulletin_content *bulletin;
1719
1720         bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1721
1722         if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
1723                 if (p_is_forced)
1724                         *p_is_forced = 1;
1725         } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
1726                 if (p_is_forced)
1727                         *p_is_forced = 0;
1728         } else {
1729                 return false;
1730         }
1731
1732         OSAL_MEMCPY(dst_mac, bulletin->mac, ETH_ALEN);
1733
1734         return true;
1735 }
1736
1737 void ecore_vf_bulletin_get_udp_ports(struct ecore_hwfn *p_hwfn,
1738                                      u16 *p_vxlan_port,
1739                                      u16 *p_geneve_port)
1740 {
1741         struct ecore_bulletin_content *p_bulletin;
1742
1743         p_bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1744
1745         *p_vxlan_port = p_bulletin->vxlan_udp_port;
1746         *p_geneve_port = p_bulletin->geneve_udp_port;
1747 }
1748
1749 bool ecore_vf_bulletin_get_forced_vlan(struct ecore_hwfn *hwfn, u16 *dst_pvid)
1750 {
1751         struct ecore_bulletin_content *bulletin;
1752
1753         bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1754
1755         if (!(bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
1756                 return false;
1757
1758         if (dst_pvid)
1759                 *dst_pvid = bulletin->pvid;
1760
1761         return true;
1762 }
1763
1764 bool ecore_vf_get_pre_fp_hsi(struct ecore_hwfn *p_hwfn)
1765 {
1766         return p_hwfn->vf_iov_info->b_pre_fp_hsi;
1767 }
1768
1769 void ecore_vf_get_fw_version(struct ecore_hwfn *p_hwfn,
1770                              u16 *fw_major, u16 *fw_minor, u16 *fw_rev,
1771                              u16 *fw_eng)
1772 {
1773         struct pf_vf_pfdev_info *info;
1774
1775         info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
1776
1777         *fw_major = info->fw_major;
1778         *fw_minor = info->fw_minor;
1779         *fw_rev = info->fw_rev;
1780         *fw_eng = info->fw_eng;
1781 }