Merge tag 'for-gkh' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
[linux-2.6-block.git] / drivers / net / ethernet / qlogic / qed / qed_vf.c
1 /* QLogic qed NIC Driver
2  * Copyright (c) 2015-2017  QLogic Corporation
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and /or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32
33 #include <linux/crc32.h>
34 #include <linux/etherdevice.h>
35 #include "qed.h"
36 #include "qed_sriov.h"
37 #include "qed_vf.h"
38
39 static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length)
40 {
41         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
42         void *p_tlv;
43
44         /* This lock is released when we receive PF's response
45          * in qed_send_msg2pf().
46          * So, qed_vf_pf_prep() and qed_send_msg2pf()
47          * must come in sequence.
48          */
49         mutex_lock(&(p_iov->mutex));
50
51         DP_VERBOSE(p_hwfn,
52                    QED_MSG_IOV,
53                    "preparing to send 0x%04x tlv over vf pf channel\n",
54                    type);
55
56         /* Reset Requst offset */
57         p_iov->offset = (u8 *)p_iov->vf2pf_request;
58
59         /* Clear mailbox - both request and reply */
60         memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
61         memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
62
63         /* Init type and length */
64         p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length);
65
66         /* Init first tlv header */
67         ((struct vfpf_first_tlv *)p_tlv)->reply_address =
68             (u64)p_iov->pf2vf_reply_phys;
69
70         return p_tlv;
71 }
72
73 static void qed_vf_pf_req_end(struct qed_hwfn *p_hwfn, int req_status)
74 {
75         union pfvf_tlvs *resp = p_hwfn->vf_iov_info->pf2vf_reply;
76
77         DP_VERBOSE(p_hwfn, QED_MSG_IOV,
78                    "VF request status = 0x%x, PF reply status = 0x%x\n",
79                    req_status, resp->default_resp.hdr.status);
80
81         mutex_unlock(&(p_hwfn->vf_iov_info->mutex));
82 }
83
84 static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size)
85 {
86         union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
87         struct ustorm_trigger_vf_zone trigger;
88         struct ustorm_vf_zone *zone_data;
89         int rc = 0, time = 100;
90
91         zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
92
93         /* output tlvs list */
94         qed_dp_tlv_list(p_hwfn, p_req);
95
96         /* need to add the END TLV to the message size */
97         resp_size += sizeof(struct channel_list_end_tlv);
98
99         /* Send TLVs over HW channel */
100         memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
101         trigger.vf_pf_msg_valid = 1;
102
103         DP_VERBOSE(p_hwfn,
104                    QED_MSG_IOV,
105                    "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n",
106                    GET_FIELD(p_hwfn->hw_info.concrete_fid,
107                              PXP_CONCRETE_FID_PFID),
108                    upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
109                    lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
110                    &zone_data->non_trigger.vf_pf_msg_addr,
111                    *((u32 *)&trigger), &zone_data->trigger);
112
113         REG_WR(p_hwfn,
114                (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
115                lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
116
117         REG_WR(p_hwfn,
118                (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
119                upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
120
121         /* The message data must be written first, to prevent trigger before
122          * data is written.
123          */
124         wmb();
125
126         REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger));
127
128         /* When PF would be done with the response, it would write back to the
129          * `done' address. Poll until then.
130          */
131         while ((!*done) && time) {
132                 msleep(25);
133                 time--;
134         }
135
136         if (!*done) {
137                 DP_NOTICE(p_hwfn,
138                           "VF <-- PF Timeout [Type %d]\n",
139                           p_req->first_tlv.tl.type);
140                 rc = -EBUSY;
141         } else {
142                 if ((*done != PFVF_STATUS_SUCCESS) &&
143                     (*done != PFVF_STATUS_NO_RESOURCE))
144                         DP_NOTICE(p_hwfn,
145                                   "PF response: %d [Type %d]\n",
146                                   *done, p_req->first_tlv.tl.type);
147                 else
148                         DP_VERBOSE(p_hwfn, QED_MSG_IOV,
149                                    "PF response: %d [Type %d]\n",
150                                    *done, p_req->first_tlv.tl.type);
151         }
152
153         return rc;
154 }
155
156 static void qed_vf_pf_add_qid(struct qed_hwfn *p_hwfn,
157                               struct qed_queue_cid *p_cid)
158 {
159         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
160         struct vfpf_qid_tlv *p_qid_tlv;
161
162         /* Only add QIDs for the queue if it was negotiated with PF */
163         if (!(p_iov->acquire_resp.pfdev_info.capabilities &
164               PFVF_ACQUIRE_CAP_QUEUE_QIDS))
165                 return;
166
167         p_qid_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
168                                 CHANNEL_TLV_QID, sizeof(*p_qid_tlv));
169         p_qid_tlv->qid = p_cid->qid_usage_idx;
170 }
171
172 static int _qed_vf_pf_release(struct qed_hwfn *p_hwfn, bool b_final)
173 {
174         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
175         struct pfvf_def_resp_tlv *resp;
176         struct vfpf_first_tlv *req;
177         u32 size;
178         int rc;
179
180         /* clear mailbox and prep first tlv */
181         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
182
183         /* add list termination tlv */
184         qed_add_tlv(p_hwfn, &p_iov->offset,
185                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
186
187         resp = &p_iov->pf2vf_reply->default_resp;
188         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
189
190         if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS)
191                 rc = -EAGAIN;
192
193         qed_vf_pf_req_end(p_hwfn, rc);
194         if (!b_final)
195                 return rc;
196
197         p_hwfn->b_int_enabled = 0;
198
199         if (p_iov->vf2pf_request)
200                 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
201                                   sizeof(union vfpf_tlvs),
202                                   p_iov->vf2pf_request,
203                                   p_iov->vf2pf_request_phys);
204         if (p_iov->pf2vf_reply)
205                 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
206                                   sizeof(union pfvf_tlvs),
207                                   p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
208
209         if (p_iov->bulletin.p_virt) {
210                 size = sizeof(struct qed_bulletin_content);
211                 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
212                                   size,
213                                   p_iov->bulletin.p_virt, p_iov->bulletin.phys);
214         }
215
216         kfree(p_hwfn->vf_iov_info);
217         p_hwfn->vf_iov_info = NULL;
218
219         return rc;
220 }
221
222 int qed_vf_pf_release(struct qed_hwfn *p_hwfn)
223 {
224         return _qed_vf_pf_release(p_hwfn, true);
225 }
226
227 #define VF_ACQUIRE_THRESH 3
228 static void qed_vf_pf_acquire_reduce_resc(struct qed_hwfn *p_hwfn,
229                                           struct vf_pf_resc_request *p_req,
230                                           struct pf_vf_resc *p_resp)
231 {
232         DP_VERBOSE(p_hwfn,
233                    QED_MSG_IOV,
234                    "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",
235                    p_req->num_rxqs,
236                    p_resp->num_rxqs,
237                    p_req->num_rxqs,
238                    p_resp->num_txqs,
239                    p_req->num_sbs,
240                    p_resp->num_sbs,
241                    p_req->num_mac_filters,
242                    p_resp->num_mac_filters,
243                    p_req->num_vlan_filters,
244                    p_resp->num_vlan_filters,
245                    p_req->num_mc_filters,
246                    p_resp->num_mc_filters, p_req->num_cids, p_resp->num_cids);
247
248         /* humble our request */
249         p_req->num_txqs = p_resp->num_txqs;
250         p_req->num_rxqs = p_resp->num_rxqs;
251         p_req->num_sbs = p_resp->num_sbs;
252         p_req->num_mac_filters = p_resp->num_mac_filters;
253         p_req->num_vlan_filters = p_resp->num_vlan_filters;
254         p_req->num_mc_filters = p_resp->num_mc_filters;
255         p_req->num_cids = p_resp->num_cids;
256 }
257
258 static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
259 {
260         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
261         struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
262         struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
263         struct vf_pf_resc_request *p_resc;
264         bool resources_acquired = false;
265         struct vfpf_acquire_tlv *req;
266         int rc = 0, attempts = 0;
267
268         /* clear mailbox and prep first tlv */
269         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
270         p_resc = &req->resc_request;
271
272         /* starting filling the request */
273         req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
274
275         p_resc->num_rxqs = QED_MAX_VF_CHAINS_PER_PF;
276         p_resc->num_txqs = QED_MAX_VF_CHAINS_PER_PF;
277         p_resc->num_sbs = QED_MAX_VF_CHAINS_PER_PF;
278         p_resc->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
279         p_resc->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
280         p_resc->num_cids = QED_ETH_VF_DEFAULT_NUM_CIDS;
281
282         req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
283         req->vfdev_info.fw_major = FW_MAJOR_VERSION;
284         req->vfdev_info.fw_minor = FW_MINOR_VERSION;
285         req->vfdev_info.fw_revision = FW_REVISION_VERSION;
286         req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
287         req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
288         req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR;
289
290         /* Fill capability field with any non-deprecated config we support */
291         req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
292
293         /* If we've mapped the doorbell bar, try using queue qids */
294         if (p_iov->b_doorbell_bar) {
295                 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_PHYSICAL_BAR |
296                                                 VFPF_ACQUIRE_CAP_QUEUE_QIDS;
297                 p_resc->num_cids = QED_ETH_VF_MAX_NUM_CIDS;
298         }
299
300         /* pf 2 vf bulletin board address */
301         req->bulletin_addr = p_iov->bulletin.phys;
302         req->bulletin_size = p_iov->bulletin.size;
303
304         /* add list termination tlv */
305         qed_add_tlv(p_hwfn, &p_iov->offset,
306                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
307
308         while (!resources_acquired) {
309                 DP_VERBOSE(p_hwfn,
310                            QED_MSG_IOV, "attempting to acquire resources\n");
311
312                 /* Clear response buffer, as this might be a re-send */
313                 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
314
315                 /* send acquire request */
316                 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
317                 if (rc)
318                         goto exit;
319
320                 /* copy acquire response from buffer to p_hwfn */
321                 memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
322
323                 attempts++;
324
325                 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
326                         /* PF agrees to allocate our resources */
327                         if (!(resp->pfdev_info.capabilities &
328                               PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
329                                 /* It's possible legacy PF mistakenly accepted;
330                                  * but we don't care - simply mark it as
331                                  * legacy and continue.
332                                  */
333                                 req->vfdev_info.capabilities |=
334                                     VFPF_ACQUIRE_CAP_PRE_FP_HSI;
335                         }
336                         DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
337                         resources_acquired = true;
338                 } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
339                            attempts < VF_ACQUIRE_THRESH) {
340                         qed_vf_pf_acquire_reduce_resc(p_hwfn, p_resc,
341                                                       &resp->resc);
342                 } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) {
343                         if (pfdev_info->major_fp_hsi &&
344                             (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) {
345                                 DP_NOTICE(p_hwfn,
346                                           "PF uses an incompatible fastpath HSI %02x.%02x [VF requires %02x.%02x]. Please change to a VF driver using %02x.xx.\n",
347                                           pfdev_info->major_fp_hsi,
348                                           pfdev_info->minor_fp_hsi,
349                                           ETH_HSI_VER_MAJOR,
350                                           ETH_HSI_VER_MINOR,
351                                           pfdev_info->major_fp_hsi);
352                                 rc = -EINVAL;
353                                 goto exit;
354                         }
355
356                         if (!pfdev_info->major_fp_hsi) {
357                                 if (req->vfdev_info.capabilities &
358                                     VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
359                                         DP_NOTICE(p_hwfn,
360                                                   "PF uses very old drivers. Please change to a VF driver using no later than 8.8.x.x.\n");
361                                         rc = -EINVAL;
362                                         goto exit;
363                                 } else {
364                                         DP_INFO(p_hwfn,
365                                                 "PF is old - try re-acquire to see if it supports FW-version override\n");
366                                         req->vfdev_info.capabilities |=
367                                             VFPF_ACQUIRE_CAP_PRE_FP_HSI;
368                                         continue;
369                                 }
370                         }
371
372                         /* If PF/VF are using same Major, PF must have had
373                          * it's reasons. Simply fail.
374                          */
375                         DP_NOTICE(p_hwfn, "PF rejected acquisition by VF\n");
376                         rc = -EINVAL;
377                         goto exit;
378                 } else {
379                         DP_ERR(p_hwfn,
380                                "PF returned error %d to VF acquisition request\n",
381                                resp->hdr.status);
382                         rc = -EAGAIN;
383                         goto exit;
384                 }
385         }
386
387         /* Mark the PF as legacy, if needed */
388         if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_PRE_FP_HSI)
389                 p_iov->b_pre_fp_hsi = true;
390
391         /* In case PF doesn't support multi-queue Tx, update the number of
392          * CIDs to reflect the number of queues [older PFs didn't fill that
393          * field].
394          */
395         if (!(resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_QUEUE_QIDS))
396                 resp->resc.num_cids = resp->resc.num_rxqs + resp->resc.num_txqs;
397
398         /* Update bulletin board size with response from PF */
399         p_iov->bulletin.size = resp->bulletin_size;
400
401         /* get HW info */
402         p_hwfn->cdev->type = resp->pfdev_info.dev_type;
403         p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
404
405         p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
406
407         /* Learn of the possibility of CMT */
408         if (IS_LEAD_HWFN(p_hwfn)) {
409                 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
410                         DP_NOTICE(p_hwfn, "100g VF\n");
411                         p_hwfn->cdev->num_hwfns = 2;
412                 }
413         }
414
415         if (!p_iov->b_pre_fp_hsi &&
416             (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR)) {
417                 DP_INFO(p_hwfn,
418                         "PF is using older fastpath HSI; %02x.%02x is configured\n",
419                         ETH_HSI_VER_MAJOR, resp->pfdev_info.minor_fp_hsi);
420         }
421
422 exit:
423         qed_vf_pf_req_end(p_hwfn, rc);
424
425         return rc;
426 }
427
428 u32 qed_vf_hw_bar_size(struct qed_hwfn *p_hwfn, enum BAR_ID bar_id)
429 {
430         u32 bar_size;
431
432         /* Regview size is fixed */
433         if (bar_id == BAR_ID_0)
434                 return 1 << 17;
435
436         /* Doorbell is received from PF */
437         bar_size = p_hwfn->vf_iov_info->acquire_resp.pfdev_info.bar_size;
438         if (bar_size)
439                 return 1 << bar_size;
440         return 0;
441 }
442
443 int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
444 {
445         struct qed_hwfn *p_lead = QED_LEADING_HWFN(p_hwfn->cdev);
446         struct qed_vf_iov *p_iov;
447         u32 reg;
448         int rc;
449
450         /* Set number of hwfns - might be overriden once leading hwfn learns
451          * actual configuration from PF.
452          */
453         if (IS_LEAD_HWFN(p_hwfn))
454                 p_hwfn->cdev->num_hwfns = 1;
455
456         reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
457         p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
458
459         reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
460         p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
461
462         /* Allocate vf sriov info */
463         p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
464         if (!p_iov)
465                 return -ENOMEM;
466
467         /* Doorbells are tricky; Upper-layer has alreday set the hwfn doorbell
468          * value, but there are several incompatibily scenarios where that
469          * would be incorrect and we'd need to override it.
470          */
471         if (!p_hwfn->doorbells) {
472                 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
473                                                   PXP_VF_BAR0_START_DQ;
474         } else if (p_hwfn == p_lead) {
475                 /* For leading hw-function, value is always correct, but need
476                  * to handle scenario where legacy PF would not support 100g
477                  * mapped bars later.
478                  */
479                 p_iov->b_doorbell_bar = true;
480         } else {
481                 /* here, value would be correct ONLY if the leading hwfn
482                  * received indication that mapped-bars are supported.
483                  */
484                 if (p_lead->vf_iov_info->b_doorbell_bar)
485                         p_iov->b_doorbell_bar = true;
486                 else
487                         p_hwfn->doorbells = (u8 __iomem *)
488                             p_hwfn->regview + PXP_VF_BAR0_START_DQ;
489         }
490
491         /* Allocate vf2pf msg */
492         p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
493                                                   sizeof(union vfpf_tlvs),
494                                                   &p_iov->vf2pf_request_phys,
495                                                   GFP_KERNEL);
496         if (!p_iov->vf2pf_request)
497                 goto free_p_iov;
498
499         p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
500                                                 sizeof(union pfvf_tlvs),
501                                                 &p_iov->pf2vf_reply_phys,
502                                                 GFP_KERNEL);
503         if (!p_iov->pf2vf_reply)
504                 goto free_vf2pf_request;
505
506         DP_VERBOSE(p_hwfn,
507                    QED_MSG_IOV,
508                    "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
509                    p_iov->vf2pf_request,
510                    (u64) p_iov->vf2pf_request_phys,
511                    p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
512
513         /* Allocate Bulletin board */
514         p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
515         p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
516                                                     p_iov->bulletin.size,
517                                                     &p_iov->bulletin.phys,
518                                                     GFP_KERNEL);
519         DP_VERBOSE(p_hwfn, QED_MSG_IOV,
520                    "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
521                    p_iov->bulletin.p_virt,
522                    (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
523
524         mutex_init(&p_iov->mutex);
525
526         p_hwfn->vf_iov_info = p_iov;
527
528         p_hwfn->hw_info.personality = QED_PCI_ETH;
529
530         rc = qed_vf_pf_acquire(p_hwfn);
531
532         /* If VF is 100g using a mapped bar and PF is too old to support that,
533          * acquisition would succeed - but the VF would have no way knowing
534          * the size of the doorbell bar configured in HW and thus will not
535          * know how to split it for 2nd hw-function.
536          * In this case we re-try without the indication of the mapped
537          * doorbell.
538          */
539         if (!rc && p_iov->b_doorbell_bar &&
540             !qed_vf_hw_bar_size(p_hwfn, BAR_ID_1) &&
541             (p_hwfn->cdev->num_hwfns > 1)) {
542                 rc = _qed_vf_pf_release(p_hwfn, false);
543                 if (rc)
544                         return rc;
545
546                 p_iov->b_doorbell_bar = false;
547                 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
548                                                   PXP_VF_BAR0_START_DQ;
549                 rc = qed_vf_pf_acquire(p_hwfn);
550         }
551
552         DP_VERBOSE(p_hwfn, QED_MSG_IOV,
553                    "Regview [%p], Doorbell [%p], Device-doorbell [%p]\n",
554                    p_hwfn->regview, p_hwfn->doorbells, p_hwfn->cdev->doorbells);
555
556         return rc;
557
558 free_vf2pf_request:
559         dma_free_coherent(&p_hwfn->cdev->pdev->dev,
560                           sizeof(union vfpf_tlvs),
561                           p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
562 free_p_iov:
563         kfree(p_iov);
564
565         return -ENOMEM;
566 }
567 #define TSTORM_QZONE_START   PXP_VF_BAR0_START_SDM_ZONE_A
568 #define MSTORM_QZONE_START(dev)   (TSTORM_QZONE_START + \
569                                    (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
570
571 static void
572 __qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
573                            struct qed_tunn_update_type *p_src,
574                            enum qed_tunn_mode mask, u8 *p_cls)
575 {
576         if (p_src->b_update_mode) {
577                 p_req->tun_mode_update_mask |= BIT(mask);
578
579                 if (p_src->b_mode_enabled)
580                         p_req->tunn_mode |= BIT(mask);
581         }
582
583         *p_cls = p_src->tun_cls;
584 }
585
586 static void
587 qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
588                          struct qed_tunn_update_type *p_src,
589                          enum qed_tunn_mode mask,
590                          u8 *p_cls, struct qed_tunn_update_udp_port *p_port,
591                          u8 *p_update_port, u16 *p_udp_port)
592 {
593         if (p_port->b_update_port) {
594                 *p_update_port = 1;
595                 *p_udp_port = p_port->port;
596         }
597
598         __qed_vf_prep_tunn_req_tlv(p_req, p_src, mask, p_cls);
599 }
600
601 void qed_vf_set_vf_start_tunn_update_param(struct qed_tunnel_info *p_tun)
602 {
603         if (p_tun->vxlan.b_mode_enabled)
604                 p_tun->vxlan.b_update_mode = true;
605         if (p_tun->l2_geneve.b_mode_enabled)
606                 p_tun->l2_geneve.b_update_mode = true;
607         if (p_tun->ip_geneve.b_mode_enabled)
608                 p_tun->ip_geneve.b_update_mode = true;
609         if (p_tun->l2_gre.b_mode_enabled)
610                 p_tun->l2_gre.b_update_mode = true;
611         if (p_tun->ip_gre.b_mode_enabled)
612                 p_tun->ip_gre.b_update_mode = true;
613
614         p_tun->b_update_rx_cls = true;
615         p_tun->b_update_tx_cls = true;
616 }
617
618 static void
619 __qed_vf_update_tunn_param(struct qed_tunn_update_type *p_tun,
620                            u16 feature_mask, u8 tunn_mode,
621                            u8 tunn_cls, enum qed_tunn_mode val)
622 {
623         if (feature_mask & BIT(val)) {
624                 p_tun->b_mode_enabled = tunn_mode;
625                 p_tun->tun_cls = tunn_cls;
626         } else {
627                 p_tun->b_mode_enabled = false;
628         }
629 }
630
631 static void qed_vf_update_tunn_param(struct qed_hwfn *p_hwfn,
632                                      struct qed_tunnel_info *p_tun,
633                                      struct pfvf_update_tunn_param_tlv *p_resp)
634 {
635         /* Update mode and classes provided by PF */
636         u16 feat_mask = p_resp->tunn_feature_mask;
637
638         __qed_vf_update_tunn_param(&p_tun->vxlan, feat_mask,
639                                    p_resp->vxlan_mode, p_resp->vxlan_clss,
640                                    QED_MODE_VXLAN_TUNN);
641         __qed_vf_update_tunn_param(&p_tun->l2_geneve, feat_mask,
642                                    p_resp->l2geneve_mode,
643                                    p_resp->l2geneve_clss,
644                                    QED_MODE_L2GENEVE_TUNN);
645         __qed_vf_update_tunn_param(&p_tun->ip_geneve, feat_mask,
646                                    p_resp->ipgeneve_mode,
647                                    p_resp->ipgeneve_clss,
648                                    QED_MODE_IPGENEVE_TUNN);
649         __qed_vf_update_tunn_param(&p_tun->l2_gre, feat_mask,
650                                    p_resp->l2gre_mode, p_resp->l2gre_clss,
651                                    QED_MODE_L2GRE_TUNN);
652         __qed_vf_update_tunn_param(&p_tun->ip_gre, feat_mask,
653                                    p_resp->ipgre_mode, p_resp->ipgre_clss,
654                                    QED_MODE_IPGRE_TUNN);
655         p_tun->geneve_port.port = p_resp->geneve_udp_port;
656         p_tun->vxlan_port.port = p_resp->vxlan_udp_port;
657
658         DP_VERBOSE(p_hwfn, QED_MSG_IOV,
659                    "tunn mode: vxlan=0x%x, l2geneve=0x%x, ipgeneve=0x%x, l2gre=0x%x, ipgre=0x%x",
660                    p_tun->vxlan.b_mode_enabled, p_tun->l2_geneve.b_mode_enabled,
661                    p_tun->ip_geneve.b_mode_enabled,
662                    p_tun->l2_gre.b_mode_enabled, p_tun->ip_gre.b_mode_enabled);
663 }
664
665 int qed_vf_pf_tunnel_param_update(struct qed_hwfn *p_hwfn,
666                                   struct qed_tunnel_info *p_src)
667 {
668         struct qed_tunnel_info *p_tun = &p_hwfn->cdev->tunnel;
669         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
670         struct pfvf_update_tunn_param_tlv *p_resp;
671         struct vfpf_update_tunn_param_tlv *p_req;
672         int rc;
673
674         p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_TUNN_PARAM,
675                                sizeof(*p_req));
676
677         if (p_src->b_update_rx_cls && p_src->b_update_tx_cls)
678                 p_req->update_tun_cls = 1;
679
680         qed_vf_prep_tunn_req_tlv(p_req, &p_src->vxlan, QED_MODE_VXLAN_TUNN,
681                                  &p_req->vxlan_clss, &p_src->vxlan_port,
682                                  &p_req->update_vxlan_port,
683                                  &p_req->vxlan_port);
684         qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_geneve,
685                                  QED_MODE_L2GENEVE_TUNN,
686                                  &p_req->l2geneve_clss, &p_src->geneve_port,
687                                  &p_req->update_geneve_port,
688                                  &p_req->geneve_port);
689         __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_geneve,
690                                    QED_MODE_IPGENEVE_TUNN,
691                                    &p_req->ipgeneve_clss);
692         __qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_gre,
693                                    QED_MODE_L2GRE_TUNN, &p_req->l2gre_clss);
694         __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_gre,
695                                    QED_MODE_IPGRE_TUNN, &p_req->ipgre_clss);
696
697         /* add list termination tlv */
698         qed_add_tlv(p_hwfn, &p_iov->offset,
699                     CHANNEL_TLV_LIST_END,
700                     sizeof(struct channel_list_end_tlv));
701
702         p_resp = &p_iov->pf2vf_reply->tunn_param_resp;
703         rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
704
705         if (rc)
706                 goto exit;
707
708         if (p_resp->hdr.status != PFVF_STATUS_SUCCESS) {
709                 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
710                            "Failed to update tunnel parameters\n");
711                 rc = -EINVAL;
712         }
713
714         qed_vf_update_tunn_param(p_hwfn, p_tun, p_resp);
715 exit:
716         qed_vf_pf_req_end(p_hwfn, rc);
717         return rc;
718 }
719
720 int
721 qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn,
722                     struct qed_queue_cid *p_cid,
723                     u16 bd_max_bytes,
724                     dma_addr_t bd_chain_phys_addr,
725                     dma_addr_t cqe_pbl_addr,
726                     u16 cqe_pbl_size, void __iomem **pp_prod)
727 {
728         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
729         struct pfvf_start_queue_resp_tlv *resp;
730         struct vfpf_start_rxq_tlv *req;
731         u8 rx_qid = p_cid->rel.queue_id;
732         int rc;
733
734         /* clear mailbox and prep first tlv */
735         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
736
737         req->rx_qid = rx_qid;
738         req->cqe_pbl_addr = cqe_pbl_addr;
739         req->cqe_pbl_size = cqe_pbl_size;
740         req->rxq_addr = bd_chain_phys_addr;
741         req->hw_sb = p_cid->sb_igu_id;
742         req->sb_index = p_cid->sb_idx;
743         req->bd_max_bytes = bd_max_bytes;
744         req->stat_id = -1;
745
746         /* If PF is legacy, we'll need to calculate producers ourselves
747          * as well as clean them.
748          */
749         if (p_iov->b_pre_fp_hsi) {
750                 u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
751                 u32 init_prod_val = 0;
752
753                 *pp_prod = (u8 __iomem *)
754                     p_hwfn->regview +
755                     MSTORM_QZONE_START(p_hwfn->cdev) +
756                     hw_qid * MSTORM_QZONE_SIZE;
757
758                 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
759                 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
760                                   (u32 *)(&init_prod_val));
761         }
762
763         qed_vf_pf_add_qid(p_hwfn, p_cid);
764
765         /* add list termination tlv */
766         qed_add_tlv(p_hwfn, &p_iov->offset,
767                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
768
769         resp = &p_iov->pf2vf_reply->queue_start;
770         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
771         if (rc)
772                 goto exit;
773
774         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
775                 rc = -EINVAL;
776                 goto exit;
777         }
778
779         /* Learn the address of the producer from the response */
780         if (!p_iov->b_pre_fp_hsi) {
781                 u32 init_prod_val = 0;
782
783                 *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset;
784                 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
785                            "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
786                            rx_qid, *pp_prod, resp->offset);
787
788                 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
789                 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
790                                   (u32 *)&init_prod_val);
791         }
792 exit:
793         qed_vf_pf_req_end(p_hwfn, rc);
794
795         return rc;
796 }
797
798 int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn,
799                        struct qed_queue_cid *p_cid, bool cqe_completion)
800 {
801         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
802         struct vfpf_stop_rxqs_tlv *req;
803         struct pfvf_def_resp_tlv *resp;
804         int rc;
805
806         /* clear mailbox and prep first tlv */
807         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
808
809         req->rx_qid = p_cid->rel.queue_id;
810         req->num_rxqs = 1;
811         req->cqe_completion = cqe_completion;
812
813         qed_vf_pf_add_qid(p_hwfn, p_cid);
814
815         /* add list termination tlv */
816         qed_add_tlv(p_hwfn, &p_iov->offset,
817                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
818
819         resp = &p_iov->pf2vf_reply->default_resp;
820         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
821         if (rc)
822                 goto exit;
823
824         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
825                 rc = -EINVAL;
826                 goto exit;
827         }
828
829 exit:
830         qed_vf_pf_req_end(p_hwfn, rc);
831
832         return rc;
833 }
834
835 int
836 qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn,
837                     struct qed_queue_cid *p_cid,
838                     dma_addr_t pbl_addr,
839                     u16 pbl_size, void __iomem **pp_doorbell)
840 {
841         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
842         struct pfvf_start_queue_resp_tlv *resp;
843         struct vfpf_start_txq_tlv *req;
844         u16 qid = p_cid->rel.queue_id;
845         int rc;
846
847         /* clear mailbox and prep first tlv */
848         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
849
850         req->tx_qid = qid;
851
852         /* Tx */
853         req->pbl_addr = pbl_addr;
854         req->pbl_size = pbl_size;
855         req->hw_sb = p_cid->sb_igu_id;
856         req->sb_index = p_cid->sb_idx;
857
858         qed_vf_pf_add_qid(p_hwfn, p_cid);
859
860         /* add list termination tlv */
861         qed_add_tlv(p_hwfn, &p_iov->offset,
862                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
863
864         resp = &p_iov->pf2vf_reply->queue_start;
865         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
866         if (rc)
867                 goto exit;
868
869         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
870                 rc = -EINVAL;
871                 goto exit;
872         }
873
874         /* Modern PFs provide the actual offsets, while legacy
875          * provided only the queue id.
876          */
877         if (!p_iov->b_pre_fp_hsi) {
878                 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + resp->offset;
879         } else {
880                 u8 cid = p_iov->acquire_resp.resc.cid[qid];
881
882                 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
883                                              qed_db_addr_vf(cid,
884                                                             DQ_DEMS_LEGACY);
885         }
886
887         DP_VERBOSE(p_hwfn, QED_MSG_IOV,
888                    "Txq[0x%02x.%02x]: doorbell at %p [offset 0x%08x]\n",
889                    qid, p_cid->qid_usage_idx, *pp_doorbell, resp->offset);
890 exit:
891         qed_vf_pf_req_end(p_hwfn, rc);
892
893         return rc;
894 }
895
896 int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
897 {
898         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
899         struct vfpf_stop_txqs_tlv *req;
900         struct pfvf_def_resp_tlv *resp;
901         int rc;
902
903         /* clear mailbox and prep first tlv */
904         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
905
906         req->tx_qid = p_cid->rel.queue_id;
907         req->num_txqs = 1;
908
909         qed_vf_pf_add_qid(p_hwfn, p_cid);
910
911         /* add list termination tlv */
912         qed_add_tlv(p_hwfn, &p_iov->offset,
913                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
914
915         resp = &p_iov->pf2vf_reply->default_resp;
916         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
917         if (rc)
918                 goto exit;
919
920         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
921                 rc = -EINVAL;
922                 goto exit;
923         }
924
925 exit:
926         qed_vf_pf_req_end(p_hwfn, rc);
927
928         return rc;
929 }
930
931 int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn,
932                           u8 vport_id,
933                           u16 mtu,
934                           u8 inner_vlan_removal,
935                           enum qed_tpa_mode tpa_mode,
936                           u8 max_buffers_per_cqe, u8 only_untagged)
937 {
938         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
939         struct vfpf_vport_start_tlv *req;
940         struct pfvf_def_resp_tlv *resp;
941         int rc, i;
942
943         /* clear mailbox and prep first tlv */
944         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
945
946         req->mtu = mtu;
947         req->vport_id = vport_id;
948         req->inner_vlan_removal = inner_vlan_removal;
949         req->tpa_mode = tpa_mode;
950         req->max_buffers_per_cqe = max_buffers_per_cqe;
951         req->only_untagged = only_untagged;
952
953         /* status blocks */
954         for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++) {
955                 struct qed_sb_info *p_sb = p_hwfn->vf_iov_info->sbs_info[i];
956
957                 if (p_sb)
958                         req->sb_addr[i] = p_sb->sb_phys;
959         }
960
961         /* add list termination tlv */
962         qed_add_tlv(p_hwfn, &p_iov->offset,
963                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
964
965         resp = &p_iov->pf2vf_reply->default_resp;
966         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
967         if (rc)
968                 goto exit;
969
970         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
971                 rc = -EINVAL;
972                 goto exit;
973         }
974
975 exit:
976         qed_vf_pf_req_end(p_hwfn, rc);
977
978         return rc;
979 }
980
981 int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn)
982 {
983         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
984         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
985         int rc;
986
987         /* clear mailbox and prep first tlv */
988         qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
989                        sizeof(struct vfpf_first_tlv));
990
991         /* add list termination tlv */
992         qed_add_tlv(p_hwfn, &p_iov->offset,
993                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
994
995         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
996         if (rc)
997                 goto exit;
998
999         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1000                 rc = -EINVAL;
1001                 goto exit;
1002         }
1003
1004 exit:
1005         qed_vf_pf_req_end(p_hwfn, rc);
1006
1007         return rc;
1008 }
1009
1010 static bool
1011 qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn,
1012                                   struct qed_sp_vport_update_params *p_data,
1013                                   u16 tlv)
1014 {
1015         switch (tlv) {
1016         case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
1017                 return !!(p_data->update_vport_active_rx_flg ||
1018                           p_data->update_vport_active_tx_flg);
1019         case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
1020                 return !!p_data->update_tx_switching_flg;
1021         case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
1022                 return !!p_data->update_inner_vlan_removal_flg;
1023         case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
1024                 return !!p_data->update_accept_any_vlan_flg;
1025         case CHANNEL_TLV_VPORT_UPDATE_MCAST:
1026                 return !!p_data->update_approx_mcast_flg;
1027         case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
1028                 return !!(p_data->accept_flags.update_rx_mode_config ||
1029                           p_data->accept_flags.update_tx_mode_config);
1030         case CHANNEL_TLV_VPORT_UPDATE_RSS:
1031                 return !!p_data->rss_params;
1032         case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
1033                 return !!p_data->sge_tpa_params;
1034         default:
1035                 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n",
1036                         tlv);
1037                 return false;
1038         }
1039 }
1040
1041 static void
1042 qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn,
1043                                   struct qed_sp_vport_update_params *p_data)
1044 {
1045         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1046         struct pfvf_def_resp_tlv *p_resp;
1047         u16 tlv;
1048
1049         for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1050              tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) {
1051                 if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
1052                         continue;
1053
1054                 p_resp = (struct pfvf_def_resp_tlv *)
1055                          qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply,
1056                                                   tlv);
1057                 if (p_resp && p_resp->hdr.status)
1058                         DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1059                                    "TLV[%d] Configuration %s\n",
1060                                    tlv,
1061                                    (p_resp && p_resp->hdr.status) ? "succeeded"
1062                                                                   : "failed");
1063         }
1064 }
1065
1066 int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn,
1067                            struct qed_sp_vport_update_params *p_params)
1068 {
1069         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1070         struct vfpf_vport_update_tlv *req;
1071         struct pfvf_def_resp_tlv *resp;
1072         u8 update_rx, update_tx;
1073         u32 resp_size = 0;
1074         u16 size, tlv;
1075         int rc;
1076
1077         resp = &p_iov->pf2vf_reply->default_resp;
1078         resp_size = sizeof(*resp);
1079
1080         update_rx = p_params->update_vport_active_rx_flg;
1081         update_tx = p_params->update_vport_active_tx_flg;
1082
1083         /* clear mailbox and prep header tlv */
1084         qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
1085
1086         /* Prepare extended tlvs */
1087         if (update_rx || update_tx) {
1088                 struct vfpf_vport_update_activate_tlv *p_act_tlv;
1089
1090                 size = sizeof(struct vfpf_vport_update_activate_tlv);
1091                 p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
1092                                         CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
1093                                         size);
1094                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1095
1096                 if (update_rx) {
1097                         p_act_tlv->update_rx = update_rx;
1098                         p_act_tlv->active_rx = p_params->vport_active_rx_flg;
1099                 }
1100
1101                 if (update_tx) {
1102                         p_act_tlv->update_tx = update_tx;
1103                         p_act_tlv->active_tx = p_params->vport_active_tx_flg;
1104                 }
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 = qed_add_tlv(p_hwfn, &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 = qed_add_tlv(p_hwfn, &p_iov->offset,
1124                                           CHANNEL_TLV_VPORT_UPDATE_MCAST, size);
1125                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1126
1127                 memcpy(p_mcast_tlv->bins, p_params->bins,
1128                        sizeof(u32) * ETH_MULTICAST_MAC_BINS_IN_REGS);
1129         }
1130
1131         update_rx = p_params->accept_flags.update_rx_mode_config;
1132         update_tx = p_params->accept_flags.update_tx_mode_config;
1133
1134         if (update_rx || update_tx) {
1135                 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
1136
1137                 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1138                 size = sizeof(struct vfpf_vport_update_accept_param_tlv);
1139                 p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
1140                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1141
1142                 if (update_rx) {
1143                         p_accept_tlv->update_rx_mode = update_rx;
1144                         p_accept_tlv->rx_accept_filter =
1145                             p_params->accept_flags.rx_accept_filter;
1146                 }
1147
1148                 if (update_tx) {
1149                         p_accept_tlv->update_tx_mode = update_tx;
1150                         p_accept_tlv->tx_accept_filter =
1151                             p_params->accept_flags.tx_accept_filter;
1152                 }
1153         }
1154
1155         if (p_params->rss_params) {
1156                 struct qed_rss_params *rss_params = p_params->rss_params;
1157                 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
1158                 int i, table_size;
1159
1160                 size = sizeof(struct vfpf_vport_update_rss_tlv);
1161                 p_rss_tlv = qed_add_tlv(p_hwfn,
1162                                         &p_iov->offset,
1163                                         CHANNEL_TLV_VPORT_UPDATE_RSS, size);
1164                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1165
1166                 if (rss_params->update_rss_config)
1167                         p_rss_tlv->update_rss_flags |=
1168                             VFPF_UPDATE_RSS_CONFIG_FLAG;
1169                 if (rss_params->update_rss_capabilities)
1170                         p_rss_tlv->update_rss_flags |=
1171                             VFPF_UPDATE_RSS_CAPS_FLAG;
1172                 if (rss_params->update_rss_ind_table)
1173                         p_rss_tlv->update_rss_flags |=
1174                             VFPF_UPDATE_RSS_IND_TABLE_FLAG;
1175                 if (rss_params->update_rss_key)
1176                         p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
1177
1178                 p_rss_tlv->rss_enable = rss_params->rss_enable;
1179                 p_rss_tlv->rss_caps = rss_params->rss_caps;
1180                 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
1181
1182                 table_size = min_t(int, T_ETH_INDIRECTION_TABLE_SIZE,
1183                                    1 << p_rss_tlv->rss_table_size_log);
1184                 for (i = 0; i < table_size; i++) {
1185                         struct qed_queue_cid *p_queue;
1186
1187                         p_queue = rss_params->rss_ind_table[i];
1188                         p_rss_tlv->rss_ind_table[i] = p_queue->rel.queue_id;
1189                 }
1190                 memcpy(p_rss_tlv->rss_key, rss_params->rss_key,
1191                        sizeof(rss_params->rss_key));
1192         }
1193
1194         if (p_params->update_accept_any_vlan_flg) {
1195                 struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
1196
1197                 size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
1198                 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1199                 p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
1200
1201                 resp_size += sizeof(struct pfvf_def_resp_tlv);
1202                 p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
1203                 p_any_vlan_tlv->update_accept_any_vlan_flg =
1204                     p_params->update_accept_any_vlan_flg;
1205         }
1206
1207         /* add list termination tlv */
1208         qed_add_tlv(p_hwfn, &p_iov->offset,
1209                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1210
1211         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
1212         if (rc)
1213                 goto exit;
1214
1215         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1216                 rc = -EINVAL;
1217                 goto exit;
1218         }
1219
1220         qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
1221
1222 exit:
1223         qed_vf_pf_req_end(p_hwfn, rc);
1224
1225         return rc;
1226 }
1227
1228 int qed_vf_pf_reset(struct qed_hwfn *p_hwfn)
1229 {
1230         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1231         struct pfvf_def_resp_tlv *resp;
1232         struct vfpf_first_tlv *req;
1233         int rc;
1234
1235         /* clear mailbox and prep first tlv */
1236         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
1237
1238         /* add list termination tlv */
1239         qed_add_tlv(p_hwfn, &p_iov->offset,
1240                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1241
1242         resp = &p_iov->pf2vf_reply->default_resp;
1243         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1244         if (rc)
1245                 goto exit;
1246
1247         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1248                 rc = -EAGAIN;
1249                 goto exit;
1250         }
1251
1252         p_hwfn->b_int_enabled = 0;
1253
1254 exit:
1255         qed_vf_pf_req_end(p_hwfn, rc);
1256
1257         return rc;
1258 }
1259
1260 void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn,
1261                             struct qed_filter_mcast *p_filter_cmd)
1262 {
1263         struct qed_sp_vport_update_params sp_params;
1264         int i;
1265
1266         memset(&sp_params, 0, sizeof(sp_params));
1267         sp_params.update_approx_mcast_flg = 1;
1268
1269         if (p_filter_cmd->opcode == QED_FILTER_ADD) {
1270                 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1271                         u32 bit;
1272
1273                         bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1274                         sp_params.bins[bit / 32] |= 1 << (bit % 32);
1275                 }
1276         }
1277
1278         qed_vf_pf_vport_update(p_hwfn, &sp_params);
1279 }
1280
1281 int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn,
1282                            struct qed_filter_ucast *p_ucast)
1283 {
1284         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1285         struct vfpf_ucast_filter_tlv *req;
1286         struct pfvf_def_resp_tlv *resp;
1287         int rc;
1288
1289         /* clear mailbox and prep first tlv */
1290         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
1291         req->opcode = (u8) p_ucast->opcode;
1292         req->type = (u8) p_ucast->type;
1293         memcpy(req->mac, p_ucast->mac, ETH_ALEN);
1294         req->vlan = p_ucast->vlan;
1295
1296         /* add list termination tlv */
1297         qed_add_tlv(p_hwfn, &p_iov->offset,
1298                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1299
1300         resp = &p_iov->pf2vf_reply->default_resp;
1301         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1302         if (rc)
1303                 goto exit;
1304
1305         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1306                 rc = -EAGAIN;
1307                 goto exit;
1308         }
1309
1310 exit:
1311         qed_vf_pf_req_end(p_hwfn, rc);
1312
1313         return rc;
1314 }
1315
1316 int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn)
1317 {
1318         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1319         struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
1320         int rc;
1321
1322         /* clear mailbox and prep first tlv */
1323         qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
1324                        sizeof(struct vfpf_first_tlv));
1325
1326         /* add list termination tlv */
1327         qed_add_tlv(p_hwfn, &p_iov->offset,
1328                     CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1329
1330         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1331         if (rc)
1332                 goto exit;
1333
1334         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1335                 rc = -EINVAL;
1336                 goto exit;
1337         }
1338
1339 exit:
1340         qed_vf_pf_req_end(p_hwfn, rc);
1341
1342         return rc;
1343 }
1344
1345 int qed_vf_pf_get_coalesce(struct qed_hwfn *p_hwfn,
1346                            u16 *p_coal, struct qed_queue_cid *p_cid)
1347 {
1348         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1349         struct pfvf_read_coal_resp_tlv *resp;
1350         struct vfpf_read_coal_req_tlv *req;
1351         int rc;
1352
1353         /* clear mailbox and prep header tlv */
1354         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_READ, sizeof(*req));
1355         req->qid = p_cid->rel.queue_id;
1356         req->is_rx = p_cid->b_is_rx ? 1 : 0;
1357
1358         qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1359                     sizeof(struct channel_list_end_tlv));
1360         resp = &p_iov->pf2vf_reply->read_coal_resp;
1361
1362         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1363         if (rc)
1364                 goto exit;
1365
1366         if (resp->hdr.status != PFVF_STATUS_SUCCESS)
1367                 goto exit;
1368
1369         *p_coal = resp->coal;
1370 exit:
1371         qed_vf_pf_req_end(p_hwfn, rc);
1372
1373         return rc;
1374 }
1375
1376 int
1377 qed_vf_pf_bulletin_update_mac(struct qed_hwfn *p_hwfn,
1378                               u8 *p_mac)
1379 {
1380         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1381         struct vfpf_bulletin_update_mac_tlv *p_req;
1382         struct pfvf_def_resp_tlv *p_resp;
1383         int rc;
1384
1385         if (!p_mac)
1386                 return -EINVAL;
1387
1388         /* clear mailbox and prep header tlv */
1389         p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_BULLETIN_UPDATE_MAC,
1390                                sizeof(*p_req));
1391         ether_addr_copy(p_req->mac, p_mac);
1392         DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1393                    "Requesting bulletin update for MAC[%pM]\n", p_mac);
1394
1395         /* add list termination tlv */
1396         qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1397                     sizeof(struct channel_list_end_tlv));
1398
1399         p_resp = &p_iov->pf2vf_reply->default_resp;
1400         rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
1401         qed_vf_pf_req_end(p_hwfn, rc);
1402         return rc;
1403 }
1404
1405 int
1406 qed_vf_pf_set_coalesce(struct qed_hwfn *p_hwfn,
1407                        u16 rx_coal, u16 tx_coal, struct qed_queue_cid *p_cid)
1408 {
1409         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1410         struct vfpf_update_coalesce *req;
1411         struct pfvf_def_resp_tlv *resp;
1412         int rc;
1413
1414         /* clear mailbox and prep header tlv */
1415         req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_UPDATE, sizeof(*req));
1416
1417         req->rx_coal = rx_coal;
1418         req->tx_coal = tx_coal;
1419         req->qid = p_cid->rel.queue_id;
1420
1421         DP_VERBOSE(p_hwfn,
1422                    QED_MSG_IOV,
1423                    "Setting coalesce rx_coal = %d, tx_coal = %d at queue = %d\n",
1424                    rx_coal, tx_coal, req->qid);
1425
1426         /* add list termination tlv */
1427         qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1428                     sizeof(struct channel_list_end_tlv));
1429
1430         resp = &p_iov->pf2vf_reply->default_resp;
1431         rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1432         if (rc)
1433                 goto exit;
1434
1435         if (resp->hdr.status != PFVF_STATUS_SUCCESS)
1436                 goto exit;
1437
1438         if (rx_coal)
1439                 p_hwfn->cdev->rx_coalesce_usecs = rx_coal;
1440
1441         if (tx_coal)
1442                 p_hwfn->cdev->tx_coalesce_usecs = tx_coal;
1443
1444 exit:
1445         qed_vf_pf_req_end(p_hwfn, rc);
1446         return rc;
1447 }
1448
1449 u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
1450 {
1451         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1452
1453         if (!p_iov) {
1454                 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1455                 return 0;
1456         }
1457
1458         return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
1459 }
1460
1461 void qed_vf_set_sb_info(struct qed_hwfn *p_hwfn,
1462                         u16 sb_id, struct qed_sb_info *p_sb)
1463 {
1464         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1465
1466         if (!p_iov) {
1467                 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1468                 return;
1469         }
1470
1471         if (sb_id >= PFVF_MAX_SBS_PER_VF) {
1472                 DP_NOTICE(p_hwfn, "Can't configure SB %04x\n", sb_id);
1473                 return;
1474         }
1475
1476         p_iov->sbs_info[sb_id] = p_sb;
1477 }
1478
1479 int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change)
1480 {
1481         struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1482         struct qed_bulletin_content shadow;
1483         u32 crc, crc_size;
1484
1485         crc_size = sizeof(p_iov->bulletin.p_virt->crc);
1486         *p_change = 0;
1487
1488         /* Need to guarantee PF is not in the middle of writing it */
1489         memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
1490
1491         /* If version did not update, no need to do anything */
1492         if (shadow.version == p_iov->bulletin_shadow.version)
1493                 return 0;
1494
1495         /* Verify the bulletin we see is valid */
1496         crc = crc32(0, (u8 *)&shadow + crc_size,
1497                     p_iov->bulletin.size - crc_size);
1498         if (crc != shadow.crc)
1499                 return -EAGAIN;
1500
1501         /* Set the shadow bulletin and process it */
1502         memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
1503
1504         DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1505                    "Read a bulletin update %08x\n", shadow.version);
1506
1507         *p_change = 1;
1508
1509         return 0;
1510 }
1511
1512 void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1513                               struct qed_mcp_link_params *p_params,
1514                               struct qed_bulletin_content *p_bulletin)
1515 {
1516         memset(p_params, 0, sizeof(*p_params));
1517
1518         p_params->speed.autoneg = p_bulletin->req_autoneg;
1519         p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
1520         p_params->speed.forced_speed = p_bulletin->req_forced_speed;
1521         p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
1522         p_params->pause.forced_rx = p_bulletin->req_forced_rx;
1523         p_params->pause.forced_tx = p_bulletin->req_forced_tx;
1524         p_params->loopback_mode = p_bulletin->req_loopback;
1525 }
1526
1527 void qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1528                             struct qed_mcp_link_params *params)
1529 {
1530         __qed_vf_get_link_params(p_hwfn, params,
1531                                  &(p_hwfn->vf_iov_info->bulletin_shadow));
1532 }
1533
1534 void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1535                              struct qed_mcp_link_state *p_link,
1536                              struct qed_bulletin_content *p_bulletin)
1537 {
1538         memset(p_link, 0, sizeof(*p_link));
1539
1540         p_link->link_up = p_bulletin->link_up;
1541         p_link->speed = p_bulletin->speed;
1542         p_link->full_duplex = p_bulletin->full_duplex;
1543         p_link->an = p_bulletin->autoneg;
1544         p_link->an_complete = p_bulletin->autoneg_complete;
1545         p_link->parallel_detection = p_bulletin->parallel_detection;
1546         p_link->pfc_enabled = p_bulletin->pfc_enabled;
1547         p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
1548         p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
1549         p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
1550         p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
1551         p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
1552 }
1553
1554 void qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1555                            struct qed_mcp_link_state *link)
1556 {
1557         __qed_vf_get_link_state(p_hwfn, link,
1558                                 &(p_hwfn->vf_iov_info->bulletin_shadow));
1559 }
1560
1561 void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1562                             struct qed_mcp_link_capabilities *p_link_caps,
1563                             struct qed_bulletin_content *p_bulletin)
1564 {
1565         memset(p_link_caps, 0, sizeof(*p_link_caps));
1566         p_link_caps->speed_capabilities = p_bulletin->capability_speed;
1567 }
1568
1569 void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1570                           struct qed_mcp_link_capabilities *p_link_caps)
1571 {
1572         __qed_vf_get_link_caps(p_hwfn, p_link_caps,
1573                                &(p_hwfn->vf_iov_info->bulletin_shadow));
1574 }
1575
1576 void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
1577 {
1578         *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
1579 }
1580
1581 void qed_vf_get_num_txqs(struct qed_hwfn *p_hwfn, u8 *num_txqs)
1582 {
1583         *num_txqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_txqs;
1584 }
1585
1586 void qed_vf_get_num_cids(struct qed_hwfn *p_hwfn, u8 *num_cids)
1587 {
1588         *num_cids = p_hwfn->vf_iov_info->acquire_resp.resc.num_cids;
1589 }
1590
1591 void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
1592 {
1593         memcpy(port_mac,
1594                p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
1595 }
1596
1597 void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
1598 {
1599         struct qed_vf_iov *p_vf;
1600
1601         p_vf = p_hwfn->vf_iov_info;
1602         *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
1603 }
1604
1605 void qed_vf_get_num_mac_filters(struct qed_hwfn *p_hwfn, u8 *num_mac_filters)
1606 {
1607         struct qed_vf_iov *p_vf = p_hwfn->vf_iov_info;
1608
1609         *num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters;
1610 }
1611
1612 bool qed_vf_check_mac(struct qed_hwfn *p_hwfn, u8 *mac)
1613 {
1614         struct qed_bulletin_content *bulletin;
1615
1616         bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1617         if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
1618                 return true;
1619
1620         /* Forbid VF from changing a MAC enforced by PF */
1621         if (ether_addr_equal(bulletin->mac, mac))
1622                 return false;
1623
1624         return false;
1625 }
1626
1627 static bool qed_vf_bulletin_get_forced_mac(struct qed_hwfn *hwfn,
1628                                            u8 *dst_mac, u8 *p_is_forced)
1629 {
1630         struct qed_bulletin_content *bulletin;
1631
1632         bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1633
1634         if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
1635                 if (p_is_forced)
1636                         *p_is_forced = 1;
1637         } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
1638                 if (p_is_forced)
1639                         *p_is_forced = 0;
1640         } else {
1641                 return false;
1642         }
1643
1644         ether_addr_copy(dst_mac, bulletin->mac);
1645
1646         return true;
1647 }
1648
1649 static void
1650 qed_vf_bulletin_get_udp_ports(struct qed_hwfn *p_hwfn,
1651                               u16 *p_vxlan_port, u16 *p_geneve_port)
1652 {
1653         struct qed_bulletin_content *p_bulletin;
1654
1655         p_bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1656
1657         *p_vxlan_port = p_bulletin->vxlan_udp_port;
1658         *p_geneve_port = p_bulletin->geneve_udp_port;
1659 }
1660
1661 void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
1662                            u16 *fw_major, u16 *fw_minor,
1663                            u16 *fw_rev, u16 *fw_eng)
1664 {
1665         struct pf_vf_pfdev_info *info;
1666
1667         info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
1668
1669         *fw_major = info->fw_major;
1670         *fw_minor = info->fw_minor;
1671         *fw_rev = info->fw_rev;
1672         *fw_eng = info->fw_eng;
1673 }
1674
1675 static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
1676 {
1677         struct qed_eth_cb_ops *ops = hwfn->cdev->protocol_ops.eth;
1678         u8 mac[ETH_ALEN], is_mac_exist, is_mac_forced;
1679         void *cookie = hwfn->cdev->ops_cookie;
1680         u16 vxlan_port, geneve_port;
1681
1682         qed_vf_bulletin_get_udp_ports(hwfn, &vxlan_port, &geneve_port);
1683         is_mac_exist = qed_vf_bulletin_get_forced_mac(hwfn, mac,
1684                                                       &is_mac_forced);
1685         if (is_mac_exist && cookie)
1686                 ops->force_mac(cookie, mac, !!is_mac_forced);
1687
1688         ops->ports_update(cookie, vxlan_port, geneve_port);
1689
1690         /* Always update link configuration according to bulletin */
1691         qed_link_update(hwfn);
1692 }
1693
1694 void qed_iov_vf_task(struct work_struct *work)
1695 {
1696         struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
1697                                              iov_task.work);
1698         u8 change = 0;
1699
1700         if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
1701                 return;
1702
1703         /* Handle bulletin board changes */
1704         qed_vf_read_bulletin(hwfn, &change);
1705         if (test_and_clear_bit(QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG,
1706                                &hwfn->iov_task_flags))
1707                 change = 1;
1708         if (change)
1709                 qed_handle_bulletin_change(hwfn);
1710
1711         /* As VF is polling bulletin board, need to constantly re-schedule */
1712         queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ);
1713 }