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