]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/net/ethernet/qlogic/qed/qed_l2.c
qed: Fix bug in tx promiscuous mode settings
[linux.git] / drivers / net / ethernet / qlogic / qed / qed_l2.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/types.h>
34 #include <asm/byteorder.h>
35 #include <asm/param.h>
36 #include <linux/delay.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/etherdevice.h>
39 #include <linux/interrupt.h>
40 #include <linux/kernel.h>
41 #include <linux/module.h>
42 #include <linux/pci.h>
43 #include <linux/slab.h>
44 #include <linux/stddef.h>
45 #include <linux/string.h>
46 #include <linux/workqueue.h>
47 #include <linux/bitops.h>
48 #include <linux/bug.h>
49 #include <linux/vmalloc.h>
50 #include "qed.h"
51 #include <linux/qed/qed_chain.h>
52 #include "qed_cxt.h"
53 #include "qed_dev_api.h"
54 #include <linux/qed/qed_eth_if.h>
55 #include "qed_hsi.h"
56 #include "qed_hw.h"
57 #include "qed_int.h"
58 #include "qed_l2.h"
59 #include "qed_mcp.h"
60 #include "qed_reg_addr.h"
61 #include "qed_sp.h"
62 #include "qed_sriov.h"
63
64
65 #define QED_MAX_SGES_NUM 16
66 #define CRC32_POLY 0x1edc6f41
67
68 struct qed_l2_info {
69         u32 queues;
70         unsigned long **pp_qid_usage;
71
72         /* The lock is meant to synchronize access to the qid usage */
73         struct mutex lock;
74 };
75
76 int qed_l2_alloc(struct qed_hwfn *p_hwfn)
77 {
78         struct qed_l2_info *p_l2_info;
79         unsigned long **pp_qids;
80         u32 i;
81
82         if (!QED_IS_L2_PERSONALITY(p_hwfn))
83                 return 0;
84
85         p_l2_info = kzalloc(sizeof(*p_l2_info), GFP_KERNEL);
86         if (!p_l2_info)
87                 return -ENOMEM;
88         p_hwfn->p_l2_info = p_l2_info;
89
90         if (IS_PF(p_hwfn->cdev)) {
91                 p_l2_info->queues = RESC_NUM(p_hwfn, QED_L2_QUEUE);
92         } else {
93                 u8 rx = 0, tx = 0;
94
95                 qed_vf_get_num_rxqs(p_hwfn, &rx);
96                 qed_vf_get_num_txqs(p_hwfn, &tx);
97
98                 p_l2_info->queues = max_t(u8, rx, tx);
99         }
100
101         pp_qids = kcalloc(p_l2_info->queues, sizeof(unsigned long *),
102                           GFP_KERNEL);
103         if (!pp_qids)
104                 return -ENOMEM;
105         p_l2_info->pp_qid_usage = pp_qids;
106
107         for (i = 0; i < p_l2_info->queues; i++) {
108                 pp_qids[i] = kzalloc(MAX_QUEUES_PER_QZONE / 8, GFP_KERNEL);
109                 if (!pp_qids[i])
110                         return -ENOMEM;
111         }
112
113         return 0;
114 }
115
116 void qed_l2_setup(struct qed_hwfn *p_hwfn)
117 {
118         if (!QED_IS_L2_PERSONALITY(p_hwfn))
119                 return;
120
121         mutex_init(&p_hwfn->p_l2_info->lock);
122 }
123
124 void qed_l2_free(struct qed_hwfn *p_hwfn)
125 {
126         u32 i;
127
128         if (!QED_IS_L2_PERSONALITY(p_hwfn))
129                 return;
130
131         if (!p_hwfn->p_l2_info)
132                 return;
133
134         if (!p_hwfn->p_l2_info->pp_qid_usage)
135                 goto out_l2_info;
136
137         /* Free until hit first uninitialized entry */
138         for (i = 0; i < p_hwfn->p_l2_info->queues; i++) {
139                 if (!p_hwfn->p_l2_info->pp_qid_usage[i])
140                         break;
141                 kfree(p_hwfn->p_l2_info->pp_qid_usage[i]);
142         }
143
144         kfree(p_hwfn->p_l2_info->pp_qid_usage);
145
146 out_l2_info:
147         kfree(p_hwfn->p_l2_info);
148         p_hwfn->p_l2_info = NULL;
149 }
150
151 static bool qed_eth_queue_qid_usage_add(struct qed_hwfn *p_hwfn,
152                                         struct qed_queue_cid *p_cid)
153 {
154         struct qed_l2_info *p_l2_info = p_hwfn->p_l2_info;
155         u16 queue_id = p_cid->rel.queue_id;
156         bool b_rc = true;
157         u8 first;
158
159         mutex_lock(&p_l2_info->lock);
160
161         if (queue_id >= p_l2_info->queues) {
162                 DP_NOTICE(p_hwfn,
163                           "Requested to increase usage for qzone %04x out of %08x\n",
164                           queue_id, p_l2_info->queues);
165                 b_rc = false;
166                 goto out;
167         }
168
169         first = (u8)find_first_zero_bit(p_l2_info->pp_qid_usage[queue_id],
170                                         MAX_QUEUES_PER_QZONE);
171         if (first >= MAX_QUEUES_PER_QZONE) {
172                 b_rc = false;
173                 goto out;
174         }
175
176         __set_bit(first, p_l2_info->pp_qid_usage[queue_id]);
177         p_cid->qid_usage_idx = first;
178
179 out:
180         mutex_unlock(&p_l2_info->lock);
181         return b_rc;
182 }
183
184 static void qed_eth_queue_qid_usage_del(struct qed_hwfn *p_hwfn,
185                                         struct qed_queue_cid *p_cid)
186 {
187         mutex_lock(&p_hwfn->p_l2_info->lock);
188
189         clear_bit(p_cid->qid_usage_idx,
190                   p_hwfn->p_l2_info->pp_qid_usage[p_cid->rel.queue_id]);
191
192         mutex_unlock(&p_hwfn->p_l2_info->lock);
193 }
194
195 void qed_eth_queue_cid_release(struct qed_hwfn *p_hwfn,
196                                struct qed_queue_cid *p_cid)
197 {
198         bool b_legacy_vf = !!(p_cid->vf_legacy & QED_QCID_LEGACY_VF_CID);
199
200         if (IS_PF(p_hwfn->cdev) && !b_legacy_vf)
201                 _qed_cxt_release_cid(p_hwfn, p_cid->cid, p_cid->vfid);
202
203         /* For PF's VFs we maintain the index inside queue-zone in IOV */
204         if (p_cid->vfid == QED_QUEUE_CID_SELF)
205                 qed_eth_queue_qid_usage_del(p_hwfn, p_cid);
206
207         vfree(p_cid);
208 }
209
210 /* The internal is only meant to be directly called by PFs initializeing CIDs
211  * for their VFs.
212  */
213 static struct qed_queue_cid *
214 _qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
215                       u16 opaque_fid,
216                       u32 cid,
217                       struct qed_queue_start_common_params *p_params,
218                       bool b_is_rx,
219                       struct qed_queue_cid_vf_params *p_vf_params)
220 {
221         struct qed_queue_cid *p_cid;
222         int rc;
223
224         p_cid = vzalloc(sizeof(*p_cid));
225         if (!p_cid)
226                 return NULL;
227
228         p_cid->opaque_fid = opaque_fid;
229         p_cid->cid = cid;
230         p_cid->p_owner = p_hwfn;
231
232         /* Fill in parameters */
233         p_cid->rel.vport_id = p_params->vport_id;
234         p_cid->rel.queue_id = p_params->queue_id;
235         p_cid->rel.stats_id = p_params->stats_id;
236         p_cid->sb_igu_id = p_params->p_sb->igu_sb_id;
237         p_cid->b_is_rx = b_is_rx;
238         p_cid->sb_idx = p_params->sb_idx;
239
240         /* Fill-in bits related to VFs' queues if information was provided */
241         if (p_vf_params) {
242                 p_cid->vfid = p_vf_params->vfid;
243                 p_cid->vf_qid = p_vf_params->vf_qid;
244                 p_cid->vf_legacy = p_vf_params->vf_legacy;
245         } else {
246                 p_cid->vfid = QED_QUEUE_CID_SELF;
247         }
248
249         /* Don't try calculating the absolute indices for VFs */
250         if (IS_VF(p_hwfn->cdev)) {
251                 p_cid->abs = p_cid->rel;
252                 goto out;
253         }
254
255         /* Calculate the engine-absolute indices of the resources.
256          * This would guarantee they're valid later on.
257          * In some cases [SBs] we already have the right values.
258          */
259         rc = qed_fw_vport(p_hwfn, p_cid->rel.vport_id, &p_cid->abs.vport_id);
260         if (rc)
261                 goto fail;
262
263         rc = qed_fw_l2_queue(p_hwfn, p_cid->rel.queue_id, &p_cid->abs.queue_id);
264         if (rc)
265                 goto fail;
266
267         /* In case of a PF configuring its VF's queues, the stats-id is already
268          * absolute [since there's a single index that's suitable per-VF].
269          */
270         if (p_cid->vfid == QED_QUEUE_CID_SELF) {
271                 rc = qed_fw_vport(p_hwfn, p_cid->rel.stats_id,
272                                   &p_cid->abs.stats_id);
273                 if (rc)
274                         goto fail;
275         } else {
276                 p_cid->abs.stats_id = p_cid->rel.stats_id;
277         }
278
279 out:
280         /* VF-images have provided the qid_usage_idx on their own.
281          * Otherwise, we need to allocate a unique one.
282          */
283         if (!p_vf_params) {
284                 if (!qed_eth_queue_qid_usage_add(p_hwfn, p_cid))
285                         goto fail;
286         } else {
287                 p_cid->qid_usage_idx = p_vf_params->qid_usage_idx;
288         }
289
290         DP_VERBOSE(p_hwfn,
291                    QED_MSG_SP,
292                    "opaque_fid: %04x CID %08x vport %02x [%02x] qzone %04x.%02x [%04x] stats %02x [%02x] SB %04x PI %02x\n",
293                    p_cid->opaque_fid,
294                    p_cid->cid,
295                    p_cid->rel.vport_id,
296                    p_cid->abs.vport_id,
297                    p_cid->rel.queue_id,
298                    p_cid->qid_usage_idx,
299                    p_cid->abs.queue_id,
300                    p_cid->rel.stats_id,
301                    p_cid->abs.stats_id, p_cid->sb_igu_id, p_cid->sb_idx);
302
303         return p_cid;
304
305 fail:
306         vfree(p_cid);
307         return NULL;
308 }
309
310 struct qed_queue_cid *
311 qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
312                      u16 opaque_fid,
313                      struct qed_queue_start_common_params *p_params,
314                      bool b_is_rx,
315                      struct qed_queue_cid_vf_params *p_vf_params)
316 {
317         struct qed_queue_cid *p_cid;
318         u8 vfid = QED_CXT_PF_CID;
319         bool b_legacy_vf = false;
320         u32 cid = 0;
321
322         /* In case of legacy VFs, The CID can be derived from the additional
323          * VF parameters - the VF assumes queue X uses CID X, so we can simply
324          * use the vf_qid for this purpose as well.
325          */
326         if (p_vf_params) {
327                 vfid = p_vf_params->vfid;
328
329                 if (p_vf_params->vf_legacy & QED_QCID_LEGACY_VF_CID) {
330                         b_legacy_vf = true;
331                         cid = p_vf_params->vf_qid;
332                 }
333         }
334
335         /* Get a unique firmware CID for this queue, in case it's a PF.
336          * VF's don't need a CID as the queue configuration will be done
337          * by PF.
338          */
339         if (IS_PF(p_hwfn->cdev) && !b_legacy_vf) {
340                 if (_qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_ETH,
341                                          &cid, vfid)) {
342                         DP_NOTICE(p_hwfn, "Failed to acquire cid\n");
343                         return NULL;
344                 }
345         }
346
347         p_cid = _qed_eth_queue_to_cid(p_hwfn, opaque_fid, cid,
348                                       p_params, b_is_rx, p_vf_params);
349         if (!p_cid && IS_PF(p_hwfn->cdev) && !b_legacy_vf)
350                 _qed_cxt_release_cid(p_hwfn, cid, vfid);
351
352         return p_cid;
353 }
354
355 static struct qed_queue_cid *
356 qed_eth_queue_to_cid_pf(struct qed_hwfn *p_hwfn,
357                         u16 opaque_fid,
358                         bool b_is_rx,
359                         struct qed_queue_start_common_params *p_params)
360 {
361         return qed_eth_queue_to_cid(p_hwfn, opaque_fid, p_params, b_is_rx,
362                                     NULL);
363 }
364
365 int qed_sp_eth_vport_start(struct qed_hwfn *p_hwfn,
366                            struct qed_sp_vport_start_params *p_params)
367 {
368         struct vport_start_ramrod_data *p_ramrod = NULL;
369         struct qed_spq_entry *p_ent =  NULL;
370         struct qed_sp_init_data init_data;
371         u8 abs_vport_id = 0;
372         int rc = -EINVAL;
373         u16 rx_mode = 0;
374
375         rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
376         if (rc)
377                 return rc;
378
379         memset(&init_data, 0, sizeof(init_data));
380         init_data.cid = qed_spq_get_cid(p_hwfn);
381         init_data.opaque_fid = p_params->opaque_fid;
382         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
383
384         rc = qed_sp_init_request(p_hwfn, &p_ent,
385                                  ETH_RAMROD_VPORT_START,
386                                  PROTOCOLID_ETH, &init_data);
387         if (rc)
388                 return rc;
389
390         p_ramrod                = &p_ent->ramrod.vport_start;
391         p_ramrod->vport_id      = abs_vport_id;
392
393         p_ramrod->mtu                   = cpu_to_le16(p_params->mtu);
394         p_ramrod->handle_ptp_pkts       = p_params->handle_ptp_pkts;
395         p_ramrod->inner_vlan_removal_en = p_params->remove_inner_vlan;
396         p_ramrod->drop_ttl0_en          = p_params->drop_ttl0;
397         p_ramrod->untagged              = p_params->only_untagged;
398
399         SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_UCAST_DROP_ALL, 1);
400         SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_MCAST_DROP_ALL, 1);
401
402         p_ramrod->rx_mode.state = cpu_to_le16(rx_mode);
403
404         /* TPA related fields */
405         memset(&p_ramrod->tpa_param, 0, sizeof(struct eth_vport_tpa_param));
406
407         p_ramrod->tpa_param.max_buff_num = p_params->max_buffers_per_cqe;
408
409         switch (p_params->tpa_mode) {
410         case QED_TPA_MODE_GRO:
411                 p_ramrod->tpa_param.tpa_max_aggs_num = ETH_TPA_MAX_AGGS_NUM;
412                 p_ramrod->tpa_param.tpa_max_size = (u16)-1;
413                 p_ramrod->tpa_param.tpa_min_size_to_cont = p_params->mtu / 2;
414                 p_ramrod->tpa_param.tpa_min_size_to_start = p_params->mtu / 2;
415                 p_ramrod->tpa_param.tpa_ipv4_en_flg = 1;
416                 p_ramrod->tpa_param.tpa_ipv6_en_flg = 1;
417                 p_ramrod->tpa_param.tpa_pkt_split_flg = 1;
418                 p_ramrod->tpa_param.tpa_gro_consistent_flg = 1;
419                 break;
420         default:
421                 break;
422         }
423
424         p_ramrod->tx_switching_en = p_params->tx_switching;
425
426         p_ramrod->ctl_frame_mac_check_en = !!p_params->check_mac;
427         p_ramrod->ctl_frame_ethtype_check_en = !!p_params->check_ethtype;
428
429         /* Software Function ID in hwfn (PFs are 0 - 15, VFs are 16 - 135) */
430         p_ramrod->sw_fid = qed_concrete_to_sw_fid(p_hwfn->cdev,
431                                                   p_params->concrete_fid);
432
433         return qed_spq_post(p_hwfn, p_ent, NULL);
434 }
435
436 static int qed_sp_vport_start(struct qed_hwfn *p_hwfn,
437                               struct qed_sp_vport_start_params *p_params)
438 {
439         if (IS_VF(p_hwfn->cdev)) {
440                 return qed_vf_pf_vport_start(p_hwfn, p_params->vport_id,
441                                              p_params->mtu,
442                                              p_params->remove_inner_vlan,
443                                              p_params->tpa_mode,
444                                              p_params->max_buffers_per_cqe,
445                                              p_params->only_untagged);
446         }
447
448         return qed_sp_eth_vport_start(p_hwfn, p_params);
449 }
450
451 static int
452 qed_sp_vport_update_rss(struct qed_hwfn *p_hwfn,
453                         struct vport_update_ramrod_data *p_ramrod,
454                         struct qed_rss_params *p_rss)
455 {
456         struct eth_vport_rss_config *p_config;
457         u16 capabilities = 0;
458         int i, table_size;
459         int rc = 0;
460
461         if (!p_rss) {
462                 p_ramrod->common.update_rss_flg = 0;
463                 return rc;
464         }
465         p_config = &p_ramrod->rss_config;
466
467         BUILD_BUG_ON(QED_RSS_IND_TABLE_SIZE != ETH_RSS_IND_TABLE_ENTRIES_NUM);
468
469         rc = qed_fw_rss_eng(p_hwfn, p_rss->rss_eng_id, &p_config->rss_id);
470         if (rc)
471                 return rc;
472
473         p_ramrod->common.update_rss_flg = p_rss->update_rss_config;
474         p_config->update_rss_capabilities = p_rss->update_rss_capabilities;
475         p_config->update_rss_ind_table = p_rss->update_rss_ind_table;
476         p_config->update_rss_key = p_rss->update_rss_key;
477
478         p_config->rss_mode = p_rss->rss_enable ?
479                              ETH_VPORT_RSS_MODE_REGULAR :
480                              ETH_VPORT_RSS_MODE_DISABLED;
481
482         SET_FIELD(capabilities,
483                   ETH_VPORT_RSS_CONFIG_IPV4_CAPABILITY,
484                   !!(p_rss->rss_caps & QED_RSS_IPV4));
485         SET_FIELD(capabilities,
486                   ETH_VPORT_RSS_CONFIG_IPV6_CAPABILITY,
487                   !!(p_rss->rss_caps & QED_RSS_IPV6));
488         SET_FIELD(capabilities,
489                   ETH_VPORT_RSS_CONFIG_IPV4_TCP_CAPABILITY,
490                   !!(p_rss->rss_caps & QED_RSS_IPV4_TCP));
491         SET_FIELD(capabilities,
492                   ETH_VPORT_RSS_CONFIG_IPV6_TCP_CAPABILITY,
493                   !!(p_rss->rss_caps & QED_RSS_IPV6_TCP));
494         SET_FIELD(capabilities,
495                   ETH_VPORT_RSS_CONFIG_IPV4_UDP_CAPABILITY,
496                   !!(p_rss->rss_caps & QED_RSS_IPV4_UDP));
497         SET_FIELD(capabilities,
498                   ETH_VPORT_RSS_CONFIG_IPV6_UDP_CAPABILITY,
499                   !!(p_rss->rss_caps & QED_RSS_IPV6_UDP));
500         p_config->tbl_size = p_rss->rss_table_size_log;
501
502         p_config->capabilities = cpu_to_le16(capabilities);
503
504         DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
505                    "update rss flag %d, rss_mode = %d, update_caps = %d, capabilities = %d, update_ind = %d, update_rss_key = %d\n",
506                    p_ramrod->common.update_rss_flg,
507                    p_config->rss_mode,
508                    p_config->update_rss_capabilities,
509                    p_config->capabilities,
510                    p_config->update_rss_ind_table, p_config->update_rss_key);
511
512         table_size = min_t(int, QED_RSS_IND_TABLE_SIZE,
513                            1 << p_config->tbl_size);
514         for (i = 0; i < table_size; i++) {
515                 struct qed_queue_cid *p_queue = p_rss->rss_ind_table[i];
516
517                 if (!p_queue)
518                         return -EINVAL;
519
520                 p_config->indirection_table[i] =
521                     cpu_to_le16(p_queue->abs.queue_id);
522         }
523
524         DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
525                    "Configured RSS indirection table [%d entries]:\n",
526                    table_size);
527         for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i += 0x10) {
528                 DP_VERBOSE(p_hwfn,
529                            NETIF_MSG_IFUP,
530                            "%04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x\n",
531                            le16_to_cpu(p_config->indirection_table[i]),
532                            le16_to_cpu(p_config->indirection_table[i + 1]),
533                            le16_to_cpu(p_config->indirection_table[i + 2]),
534                            le16_to_cpu(p_config->indirection_table[i + 3]),
535                            le16_to_cpu(p_config->indirection_table[i + 4]),
536                            le16_to_cpu(p_config->indirection_table[i + 5]),
537                            le16_to_cpu(p_config->indirection_table[i + 6]),
538                            le16_to_cpu(p_config->indirection_table[i + 7]),
539                            le16_to_cpu(p_config->indirection_table[i + 8]),
540                            le16_to_cpu(p_config->indirection_table[i + 9]),
541                            le16_to_cpu(p_config->indirection_table[i + 10]),
542                            le16_to_cpu(p_config->indirection_table[i + 11]),
543                            le16_to_cpu(p_config->indirection_table[i + 12]),
544                            le16_to_cpu(p_config->indirection_table[i + 13]),
545                            le16_to_cpu(p_config->indirection_table[i + 14]),
546                            le16_to_cpu(p_config->indirection_table[i + 15]));
547         }
548
549         for (i = 0; i < 10; i++)
550                 p_config->rss_key[i] = cpu_to_le32(p_rss->rss_key[i]);
551
552         return rc;
553 }
554
555 static void
556 qed_sp_update_accept_mode(struct qed_hwfn *p_hwfn,
557                           struct vport_update_ramrod_data *p_ramrod,
558                           struct qed_filter_accept_flags accept_flags)
559 {
560         p_ramrod->common.update_rx_mode_flg =
561                 accept_flags.update_rx_mode_config;
562
563         p_ramrod->common.update_tx_mode_flg =
564                 accept_flags.update_tx_mode_config;
565
566         /* Set Rx mode accept flags */
567         if (p_ramrod->common.update_rx_mode_flg) {
568                 u8 accept_filter = accept_flags.rx_accept_filter;
569                 u16 state = 0;
570
571                 SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_DROP_ALL,
572                           !(!!(accept_filter & QED_ACCEPT_UCAST_MATCHED) ||
573                             !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED)));
574
575                 SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_ACCEPT_UNMATCHED,
576                           !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED));
577
578                 SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_DROP_ALL,
579                           !(!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) ||
580                             !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
581
582                 SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_ACCEPT_ALL,
583                           (!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) &&
584                            !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
585
586                 SET_FIELD(state, ETH_VPORT_RX_MODE_BCAST_ACCEPT_ALL,
587                           !!(accept_filter & QED_ACCEPT_BCAST));
588
589                 SET_FIELD(state, ETH_VPORT_RX_MODE_ACCEPT_ANY_VNI,
590                           !!(accept_filter & QED_ACCEPT_ANY_VNI));
591
592                 p_ramrod->rx_mode.state = cpu_to_le16(state);
593                 DP_VERBOSE(p_hwfn, QED_MSG_SP,
594                            "p_ramrod->rx_mode.state = 0x%x\n", state);
595         }
596
597         /* Set Tx mode accept flags */
598         if (p_ramrod->common.update_tx_mode_flg) {
599                 u8 accept_filter = accept_flags.tx_accept_filter;
600                 u16 state = 0;
601
602                 SET_FIELD(state, ETH_VPORT_TX_MODE_UCAST_DROP_ALL,
603                           !!(accept_filter & QED_ACCEPT_NONE));
604
605                 SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_DROP_ALL,
606                           !!(accept_filter & QED_ACCEPT_NONE));
607
608                 SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_ACCEPT_ALL,
609                           (!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) &&
610                            !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
611
612                 SET_FIELD(state, ETH_VPORT_TX_MODE_UCAST_ACCEPT_ALL,
613                           (!!(accept_filter & QED_ACCEPT_UCAST_MATCHED) &&
614                            !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED)));
615
616                 SET_FIELD(state, ETH_VPORT_TX_MODE_BCAST_ACCEPT_ALL,
617                           !!(accept_filter & QED_ACCEPT_BCAST));
618
619                 p_ramrod->tx_mode.state = cpu_to_le16(state);
620                 DP_VERBOSE(p_hwfn, QED_MSG_SP,
621                            "p_ramrod->tx_mode.state = 0x%x\n", state);
622         }
623 }
624
625 static void
626 qed_sp_vport_update_sge_tpa(struct qed_hwfn *p_hwfn,
627                             struct vport_update_ramrod_data *p_ramrod,
628                             struct qed_sge_tpa_params *p_params)
629 {
630         struct eth_vport_tpa_param *p_tpa;
631
632         if (!p_params) {
633                 p_ramrod->common.update_tpa_param_flg = 0;
634                 p_ramrod->common.update_tpa_en_flg = 0;
635                 p_ramrod->common.update_tpa_param_flg = 0;
636                 return;
637         }
638
639         p_ramrod->common.update_tpa_en_flg = p_params->update_tpa_en_flg;
640         p_tpa = &p_ramrod->tpa_param;
641         p_tpa->tpa_ipv4_en_flg = p_params->tpa_ipv4_en_flg;
642         p_tpa->tpa_ipv6_en_flg = p_params->tpa_ipv6_en_flg;
643         p_tpa->tpa_ipv4_tunn_en_flg = p_params->tpa_ipv4_tunn_en_flg;
644         p_tpa->tpa_ipv6_tunn_en_flg = p_params->tpa_ipv6_tunn_en_flg;
645
646         p_ramrod->common.update_tpa_param_flg = p_params->update_tpa_param_flg;
647         p_tpa->max_buff_num = p_params->max_buffers_per_cqe;
648         p_tpa->tpa_pkt_split_flg = p_params->tpa_pkt_split_flg;
649         p_tpa->tpa_hdr_data_split_flg = p_params->tpa_hdr_data_split_flg;
650         p_tpa->tpa_gro_consistent_flg = p_params->tpa_gro_consistent_flg;
651         p_tpa->tpa_max_aggs_num = p_params->tpa_max_aggs_num;
652         p_tpa->tpa_max_size = p_params->tpa_max_size;
653         p_tpa->tpa_min_size_to_start = p_params->tpa_min_size_to_start;
654         p_tpa->tpa_min_size_to_cont = p_params->tpa_min_size_to_cont;
655 }
656
657 static void
658 qed_sp_update_mcast_bin(struct qed_hwfn *p_hwfn,
659                         struct vport_update_ramrod_data *p_ramrod,
660                         struct qed_sp_vport_update_params *p_params)
661 {
662         int i;
663
664         memset(&p_ramrod->approx_mcast.bins, 0,
665                sizeof(p_ramrod->approx_mcast.bins));
666
667         if (!p_params->update_approx_mcast_flg)
668                 return;
669
670         p_ramrod->common.update_approx_mcast_flg = 1;
671         for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
672                 u32 *p_bins = p_params->bins;
673
674                 p_ramrod->approx_mcast.bins[i] = cpu_to_le32(p_bins[i]);
675         }
676 }
677
678 int qed_sp_vport_update(struct qed_hwfn *p_hwfn,
679                         struct qed_sp_vport_update_params *p_params,
680                         enum spq_mode comp_mode,
681                         struct qed_spq_comp_cb *p_comp_data)
682 {
683         struct qed_rss_params *p_rss_params = p_params->rss_params;
684         struct vport_update_ramrod_data_cmn *p_cmn;
685         struct qed_sp_init_data init_data;
686         struct vport_update_ramrod_data *p_ramrod = NULL;
687         struct qed_spq_entry *p_ent = NULL;
688         u8 abs_vport_id = 0, val;
689         int rc = -EINVAL;
690
691         if (IS_VF(p_hwfn->cdev)) {
692                 rc = qed_vf_pf_vport_update(p_hwfn, p_params);
693                 return rc;
694         }
695
696         rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
697         if (rc)
698                 return rc;
699
700         memset(&init_data, 0, sizeof(init_data));
701         init_data.cid = qed_spq_get_cid(p_hwfn);
702         init_data.opaque_fid = p_params->opaque_fid;
703         init_data.comp_mode = comp_mode;
704         init_data.p_comp_data = p_comp_data;
705
706         rc = qed_sp_init_request(p_hwfn, &p_ent,
707                                  ETH_RAMROD_VPORT_UPDATE,
708                                  PROTOCOLID_ETH, &init_data);
709         if (rc)
710                 return rc;
711
712         /* Copy input params to ramrod according to FW struct */
713         p_ramrod = &p_ent->ramrod.vport_update;
714         p_cmn = &p_ramrod->common;
715
716         p_cmn->vport_id = abs_vport_id;
717         p_cmn->rx_active_flg = p_params->vport_active_rx_flg;
718         p_cmn->update_rx_active_flg = p_params->update_vport_active_rx_flg;
719         p_cmn->tx_active_flg = p_params->vport_active_tx_flg;
720         p_cmn->update_tx_active_flg = p_params->update_vport_active_tx_flg;
721         p_cmn->accept_any_vlan = p_params->accept_any_vlan;
722         val = p_params->update_accept_any_vlan_flg;
723         p_cmn->update_accept_any_vlan_flg = val;
724
725         p_cmn->inner_vlan_removal_en = p_params->inner_vlan_removal_flg;
726         val = p_params->update_inner_vlan_removal_flg;
727         p_cmn->update_inner_vlan_removal_en_flg = val;
728
729         p_cmn->default_vlan_en = p_params->default_vlan_enable_flg;
730         val = p_params->update_default_vlan_enable_flg;
731         p_cmn->update_default_vlan_en_flg = val;
732
733         p_cmn->default_vlan = cpu_to_le16(p_params->default_vlan);
734         p_cmn->update_default_vlan_flg = p_params->update_default_vlan_flg;
735
736         p_cmn->silent_vlan_removal_en = p_params->silent_vlan_removal_flg;
737
738         p_ramrod->common.tx_switching_en = p_params->tx_switching_flg;
739         p_cmn->update_tx_switching_en_flg = p_params->update_tx_switching_flg;
740
741         p_cmn->anti_spoofing_en = p_params->anti_spoofing_en;
742         val = p_params->update_anti_spoofing_en_flg;
743         p_ramrod->common.update_anti_spoofing_en_flg = val;
744
745         rc = qed_sp_vport_update_rss(p_hwfn, p_ramrod, p_rss_params);
746         if (rc) {
747                 qed_sp_destroy_request(p_hwfn, p_ent);
748                 return rc;
749         }
750
751         /* Update mcast bins for VFs, PF doesn't use this functionality */
752         qed_sp_update_mcast_bin(p_hwfn, p_ramrod, p_params);
753
754         qed_sp_update_accept_mode(p_hwfn, p_ramrod, p_params->accept_flags);
755         qed_sp_vport_update_sge_tpa(p_hwfn, p_ramrod, p_params->sge_tpa_params);
756         return qed_spq_post(p_hwfn, p_ent, NULL);
757 }
758
759 int qed_sp_vport_stop(struct qed_hwfn *p_hwfn, u16 opaque_fid, u8 vport_id)
760 {
761         struct vport_stop_ramrod_data *p_ramrod;
762         struct qed_sp_init_data init_data;
763         struct qed_spq_entry *p_ent;
764         u8 abs_vport_id = 0;
765         int rc;
766
767         if (IS_VF(p_hwfn->cdev))
768                 return qed_vf_pf_vport_stop(p_hwfn);
769
770         rc = qed_fw_vport(p_hwfn, vport_id, &abs_vport_id);
771         if (rc)
772                 return rc;
773
774         memset(&init_data, 0, sizeof(init_data));
775         init_data.cid = qed_spq_get_cid(p_hwfn);
776         init_data.opaque_fid = opaque_fid;
777         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
778
779         rc = qed_sp_init_request(p_hwfn, &p_ent,
780                                  ETH_RAMROD_VPORT_STOP,
781                                  PROTOCOLID_ETH, &init_data);
782         if (rc)
783                 return rc;
784
785         p_ramrod = &p_ent->ramrod.vport_stop;
786         p_ramrod->vport_id = abs_vport_id;
787
788         return qed_spq_post(p_hwfn, p_ent, NULL);
789 }
790
791 static int
792 qed_vf_pf_accept_flags(struct qed_hwfn *p_hwfn,
793                        struct qed_filter_accept_flags *p_accept_flags)
794 {
795         struct qed_sp_vport_update_params s_params;
796
797         memset(&s_params, 0, sizeof(s_params));
798         memcpy(&s_params.accept_flags, p_accept_flags,
799                sizeof(struct qed_filter_accept_flags));
800
801         return qed_vf_pf_vport_update(p_hwfn, &s_params);
802 }
803
804 static int qed_filter_accept_cmd(struct qed_dev *cdev,
805                                  u8 vport,
806                                  struct qed_filter_accept_flags accept_flags,
807                                  u8 update_accept_any_vlan,
808                                  u8 accept_any_vlan,
809                                  enum spq_mode comp_mode,
810                                  struct qed_spq_comp_cb *p_comp_data)
811 {
812         struct qed_sp_vport_update_params vport_update_params;
813         int i, rc;
814
815         /* Prepare and send the vport rx_mode change */
816         memset(&vport_update_params, 0, sizeof(vport_update_params));
817         vport_update_params.vport_id = vport;
818         vport_update_params.accept_flags = accept_flags;
819         vport_update_params.update_accept_any_vlan_flg = update_accept_any_vlan;
820         vport_update_params.accept_any_vlan = accept_any_vlan;
821
822         for_each_hwfn(cdev, i) {
823                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
824
825                 vport_update_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
826
827                 if (IS_VF(cdev)) {
828                         rc = qed_vf_pf_accept_flags(p_hwfn, &accept_flags);
829                         if (rc)
830                                 return rc;
831                         continue;
832                 }
833
834                 rc = qed_sp_vport_update(p_hwfn, &vport_update_params,
835                                          comp_mode, p_comp_data);
836                 if (rc) {
837                         DP_ERR(cdev, "Update rx_mode failed %d\n", rc);
838                         return rc;
839                 }
840
841                 DP_VERBOSE(p_hwfn, QED_MSG_SP,
842                            "Accept filter configured, flags = [Rx]%x [Tx]%x\n",
843                            accept_flags.rx_accept_filter,
844                            accept_flags.tx_accept_filter);
845                 if (update_accept_any_vlan)
846                         DP_VERBOSE(p_hwfn, QED_MSG_SP,
847                                    "accept_any_vlan=%d configured\n",
848                                    accept_any_vlan);
849         }
850
851         return 0;
852 }
853
854 int qed_eth_rxq_start_ramrod(struct qed_hwfn *p_hwfn,
855                              struct qed_queue_cid *p_cid,
856                              u16 bd_max_bytes,
857                              dma_addr_t bd_chain_phys_addr,
858                              dma_addr_t cqe_pbl_addr, u16 cqe_pbl_size)
859 {
860         struct rx_queue_start_ramrod_data *p_ramrod = NULL;
861         struct qed_spq_entry *p_ent = NULL;
862         struct qed_sp_init_data init_data;
863         int rc = -EINVAL;
864
865         DP_VERBOSE(p_hwfn, QED_MSG_SP,
866                    "opaque_fid=0x%x, cid=0x%x, rx_qzone=0x%x, vport_id=0x%x, sb_id=0x%x\n",
867                    p_cid->opaque_fid, p_cid->cid,
868                    p_cid->abs.queue_id, p_cid->abs.vport_id, p_cid->sb_igu_id);
869
870         /* Get SPQ entry */
871         memset(&init_data, 0, sizeof(init_data));
872         init_data.cid = p_cid->cid;
873         init_data.opaque_fid = p_cid->opaque_fid;
874         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
875
876         rc = qed_sp_init_request(p_hwfn, &p_ent,
877                                  ETH_RAMROD_RX_QUEUE_START,
878                                  PROTOCOLID_ETH, &init_data);
879         if (rc)
880                 return rc;
881
882         p_ramrod = &p_ent->ramrod.rx_queue_start;
883
884         p_ramrod->sb_id = cpu_to_le16(p_cid->sb_igu_id);
885         p_ramrod->sb_index = p_cid->sb_idx;
886         p_ramrod->vport_id = p_cid->abs.vport_id;
887         p_ramrod->stats_counter_id = p_cid->abs.stats_id;
888         p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
889         p_ramrod->complete_cqe_flg = 0;
890         p_ramrod->complete_event_flg = 1;
891
892         p_ramrod->bd_max_bytes = cpu_to_le16(bd_max_bytes);
893         DMA_REGPAIR_LE(p_ramrod->bd_base, bd_chain_phys_addr);
894
895         p_ramrod->num_of_pbl_pages = cpu_to_le16(cqe_pbl_size);
896         DMA_REGPAIR_LE(p_ramrod->cqe_pbl_addr, cqe_pbl_addr);
897
898         if (p_cid->vfid != QED_QUEUE_CID_SELF) {
899                 bool b_legacy_vf = !!(p_cid->vf_legacy &
900                                       QED_QCID_LEGACY_VF_RX_PROD);
901
902                 p_ramrod->vf_rx_prod_index = p_cid->vf_qid;
903                 DP_VERBOSE(p_hwfn, QED_MSG_SP,
904                            "Queue%s is meant for VF rxq[%02x]\n",
905                            b_legacy_vf ? " [legacy]" : "", p_cid->vf_qid);
906                 p_ramrod->vf_rx_prod_use_zone_a = b_legacy_vf;
907         }
908
909         return qed_spq_post(p_hwfn, p_ent, NULL);
910 }
911
912 static int
913 qed_eth_pf_rx_queue_start(struct qed_hwfn *p_hwfn,
914                           struct qed_queue_cid *p_cid,
915                           u16 bd_max_bytes,
916                           dma_addr_t bd_chain_phys_addr,
917                           dma_addr_t cqe_pbl_addr,
918                           u16 cqe_pbl_size, void __iomem **pp_prod)
919 {
920         u32 init_prod_val = 0;
921
922         *pp_prod = p_hwfn->regview +
923                    GTT_BAR0_MAP_REG_MSDM_RAM +
924                     MSTORM_ETH_PF_PRODS_OFFSET(p_cid->abs.queue_id);
925
926         /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
927         __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
928                           (u32 *)(&init_prod_val));
929
930         return qed_eth_rxq_start_ramrod(p_hwfn, p_cid,
931                                         bd_max_bytes,
932                                         bd_chain_phys_addr,
933                                         cqe_pbl_addr, cqe_pbl_size);
934 }
935
936 static int
937 qed_eth_rx_queue_start(struct qed_hwfn *p_hwfn,
938                        u16 opaque_fid,
939                        struct qed_queue_start_common_params *p_params,
940                        u16 bd_max_bytes,
941                        dma_addr_t bd_chain_phys_addr,
942                        dma_addr_t cqe_pbl_addr,
943                        u16 cqe_pbl_size,
944                        struct qed_rxq_start_ret_params *p_ret_params)
945 {
946         struct qed_queue_cid *p_cid;
947         int rc;
948
949         /* Allocate a CID for the queue */
950         p_cid = qed_eth_queue_to_cid_pf(p_hwfn, opaque_fid, true, p_params);
951         if (!p_cid)
952                 return -ENOMEM;
953
954         if (IS_PF(p_hwfn->cdev)) {
955                 rc = qed_eth_pf_rx_queue_start(p_hwfn, p_cid,
956                                                bd_max_bytes,
957                                                bd_chain_phys_addr,
958                                                cqe_pbl_addr, cqe_pbl_size,
959                                                &p_ret_params->p_prod);
960         } else {
961                 rc = qed_vf_pf_rxq_start(p_hwfn, p_cid,
962                                          bd_max_bytes,
963                                          bd_chain_phys_addr,
964                                          cqe_pbl_addr,
965                                          cqe_pbl_size, &p_ret_params->p_prod);
966         }
967
968         /* Provide the caller with a reference to as handler */
969         if (rc)
970                 qed_eth_queue_cid_release(p_hwfn, p_cid);
971         else
972                 p_ret_params->p_handle = (void *)p_cid;
973
974         return rc;
975 }
976
977 int qed_sp_eth_rx_queues_update(struct qed_hwfn *p_hwfn,
978                                 void **pp_rxq_handles,
979                                 u8 num_rxqs,
980                                 u8 complete_cqe_flg,
981                                 u8 complete_event_flg,
982                                 enum spq_mode comp_mode,
983                                 struct qed_spq_comp_cb *p_comp_data)
984 {
985         struct rx_queue_update_ramrod_data *p_ramrod = NULL;
986         struct qed_spq_entry *p_ent = NULL;
987         struct qed_sp_init_data init_data;
988         struct qed_queue_cid *p_cid;
989         int rc = -EINVAL;
990         u8 i;
991
992         memset(&init_data, 0, sizeof(init_data));
993         init_data.comp_mode = comp_mode;
994         init_data.p_comp_data = p_comp_data;
995
996         for (i = 0; i < num_rxqs; i++) {
997                 p_cid = ((struct qed_queue_cid **)pp_rxq_handles)[i];
998
999                 /* Get SPQ entry */
1000                 init_data.cid = p_cid->cid;
1001                 init_data.opaque_fid = p_cid->opaque_fid;
1002
1003                 rc = qed_sp_init_request(p_hwfn, &p_ent,
1004                                          ETH_RAMROD_RX_QUEUE_UPDATE,
1005                                          PROTOCOLID_ETH, &init_data);
1006                 if (rc)
1007                         return rc;
1008
1009                 p_ramrod = &p_ent->ramrod.rx_queue_update;
1010                 p_ramrod->vport_id = p_cid->abs.vport_id;
1011
1012                 p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
1013                 p_ramrod->complete_cqe_flg = complete_cqe_flg;
1014                 p_ramrod->complete_event_flg = complete_event_flg;
1015
1016                 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1017                 if (rc)
1018                         return rc;
1019         }
1020
1021         return rc;
1022 }
1023
1024 static int
1025 qed_eth_pf_rx_queue_stop(struct qed_hwfn *p_hwfn,
1026                          struct qed_queue_cid *p_cid,
1027                          bool b_eq_completion_only, bool b_cqe_completion)
1028 {
1029         struct rx_queue_stop_ramrod_data *p_ramrod = NULL;
1030         struct qed_spq_entry *p_ent = NULL;
1031         struct qed_sp_init_data init_data;
1032         int rc;
1033
1034         memset(&init_data, 0, sizeof(init_data));
1035         init_data.cid = p_cid->cid;
1036         init_data.opaque_fid = p_cid->opaque_fid;
1037         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1038
1039         rc = qed_sp_init_request(p_hwfn, &p_ent,
1040                                  ETH_RAMROD_RX_QUEUE_STOP,
1041                                  PROTOCOLID_ETH, &init_data);
1042         if (rc)
1043                 return rc;
1044
1045         p_ramrod = &p_ent->ramrod.rx_queue_stop;
1046         p_ramrod->vport_id = p_cid->abs.vport_id;
1047         p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
1048
1049         /* Cleaning the queue requires the completion to arrive there.
1050          * In addition, VFs require the answer to come as eqe to PF.
1051          */
1052         p_ramrod->complete_cqe_flg = ((p_cid->vfid == QED_QUEUE_CID_SELF) &&
1053                                       !b_eq_completion_only) ||
1054                                      b_cqe_completion;
1055         p_ramrod->complete_event_flg = (p_cid->vfid != QED_QUEUE_CID_SELF) ||
1056                                        b_eq_completion_only;
1057
1058         return qed_spq_post(p_hwfn, p_ent, NULL);
1059 }
1060
1061 int qed_eth_rx_queue_stop(struct qed_hwfn *p_hwfn,
1062                           void *p_rxq,
1063                           bool eq_completion_only, bool cqe_completion)
1064 {
1065         struct qed_queue_cid *p_cid = (struct qed_queue_cid *)p_rxq;
1066         int rc = -EINVAL;
1067
1068         if (IS_PF(p_hwfn->cdev))
1069                 rc = qed_eth_pf_rx_queue_stop(p_hwfn, p_cid,
1070                                               eq_completion_only,
1071                                               cqe_completion);
1072         else
1073                 rc = qed_vf_pf_rxq_stop(p_hwfn, p_cid, cqe_completion);
1074
1075         if (!rc)
1076                 qed_eth_queue_cid_release(p_hwfn, p_cid);
1077         return rc;
1078 }
1079
1080 int
1081 qed_eth_txq_start_ramrod(struct qed_hwfn *p_hwfn,
1082                          struct qed_queue_cid *p_cid,
1083                          dma_addr_t pbl_addr, u16 pbl_size, u16 pq_id)
1084 {
1085         struct tx_queue_start_ramrod_data *p_ramrod = NULL;
1086         struct qed_spq_entry *p_ent = NULL;
1087         struct qed_sp_init_data init_data;
1088         int rc = -EINVAL;
1089
1090         /* Get SPQ entry */
1091         memset(&init_data, 0, sizeof(init_data));
1092         init_data.cid = p_cid->cid;
1093         init_data.opaque_fid = p_cid->opaque_fid;
1094         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1095
1096         rc = qed_sp_init_request(p_hwfn, &p_ent,
1097                                  ETH_RAMROD_TX_QUEUE_START,
1098                                  PROTOCOLID_ETH, &init_data);
1099         if (rc)
1100                 return rc;
1101
1102         p_ramrod = &p_ent->ramrod.tx_queue_start;
1103         p_ramrod->vport_id = p_cid->abs.vport_id;
1104
1105         p_ramrod->sb_id = cpu_to_le16(p_cid->sb_igu_id);
1106         p_ramrod->sb_index = p_cid->sb_idx;
1107         p_ramrod->stats_counter_id = p_cid->abs.stats_id;
1108
1109         p_ramrod->queue_zone_id = cpu_to_le16(p_cid->abs.queue_id);
1110         p_ramrod->same_as_last_id = cpu_to_le16(p_cid->abs.queue_id);
1111
1112         p_ramrod->pbl_size = cpu_to_le16(pbl_size);
1113         DMA_REGPAIR_LE(p_ramrod->pbl_base_addr, pbl_addr);
1114
1115         p_ramrod->qm_pq_id = cpu_to_le16(pq_id);
1116
1117         return qed_spq_post(p_hwfn, p_ent, NULL);
1118 }
1119
1120 static int
1121 qed_eth_pf_tx_queue_start(struct qed_hwfn *p_hwfn,
1122                           struct qed_queue_cid *p_cid,
1123                           u8 tc,
1124                           dma_addr_t pbl_addr,
1125                           u16 pbl_size, void __iomem **pp_doorbell)
1126 {
1127         int rc;
1128
1129
1130         rc = qed_eth_txq_start_ramrod(p_hwfn, p_cid,
1131                                       pbl_addr, pbl_size,
1132                                       qed_get_cm_pq_idx_mcos(p_hwfn, tc));
1133         if (rc)
1134                 return rc;
1135
1136         /* Provide the caller with the necessary return values */
1137         *pp_doorbell = p_hwfn->doorbells +
1138                        qed_db_addr(p_cid->cid, DQ_DEMS_LEGACY);
1139
1140         return 0;
1141 }
1142
1143 static int
1144 qed_eth_tx_queue_start(struct qed_hwfn *p_hwfn,
1145                        u16 opaque_fid,
1146                        struct qed_queue_start_common_params *p_params,
1147                        u8 tc,
1148                        dma_addr_t pbl_addr,
1149                        u16 pbl_size,
1150                        struct qed_txq_start_ret_params *p_ret_params)
1151 {
1152         struct qed_queue_cid *p_cid;
1153         int rc;
1154
1155         p_cid = qed_eth_queue_to_cid_pf(p_hwfn, opaque_fid, false, p_params);
1156         if (!p_cid)
1157                 return -EINVAL;
1158
1159         if (IS_PF(p_hwfn->cdev))
1160                 rc = qed_eth_pf_tx_queue_start(p_hwfn, p_cid, tc,
1161                                                pbl_addr, pbl_size,
1162                                                &p_ret_params->p_doorbell);
1163         else
1164                 rc = qed_vf_pf_txq_start(p_hwfn, p_cid,
1165                                          pbl_addr, pbl_size,
1166                                          &p_ret_params->p_doorbell);
1167
1168         if (rc)
1169                 qed_eth_queue_cid_release(p_hwfn, p_cid);
1170         else
1171                 p_ret_params->p_handle = (void *)p_cid;
1172
1173         return rc;
1174 }
1175
1176 static int
1177 qed_eth_pf_tx_queue_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
1178 {
1179         struct qed_spq_entry *p_ent = NULL;
1180         struct qed_sp_init_data init_data;
1181         int rc;
1182
1183         memset(&init_data, 0, sizeof(init_data));
1184         init_data.cid = p_cid->cid;
1185         init_data.opaque_fid = p_cid->opaque_fid;
1186         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1187
1188         rc = qed_sp_init_request(p_hwfn, &p_ent,
1189                                  ETH_RAMROD_TX_QUEUE_STOP,
1190                                  PROTOCOLID_ETH, &init_data);
1191         if (rc)
1192                 return rc;
1193
1194         return qed_spq_post(p_hwfn, p_ent, NULL);
1195 }
1196
1197 int qed_eth_tx_queue_stop(struct qed_hwfn *p_hwfn, void *p_handle)
1198 {
1199         struct qed_queue_cid *p_cid = (struct qed_queue_cid *)p_handle;
1200         int rc;
1201
1202         if (IS_PF(p_hwfn->cdev))
1203                 rc = qed_eth_pf_tx_queue_stop(p_hwfn, p_cid);
1204         else
1205                 rc = qed_vf_pf_txq_stop(p_hwfn, p_cid);
1206
1207         if (!rc)
1208                 qed_eth_queue_cid_release(p_hwfn, p_cid);
1209         return rc;
1210 }
1211
1212 static enum eth_filter_action qed_filter_action(enum qed_filter_opcode opcode)
1213 {
1214         enum eth_filter_action action = MAX_ETH_FILTER_ACTION;
1215
1216         switch (opcode) {
1217         case QED_FILTER_ADD:
1218                 action = ETH_FILTER_ACTION_ADD;
1219                 break;
1220         case QED_FILTER_REMOVE:
1221                 action = ETH_FILTER_ACTION_REMOVE;
1222                 break;
1223         case QED_FILTER_FLUSH:
1224                 action = ETH_FILTER_ACTION_REMOVE_ALL;
1225                 break;
1226         default:
1227                 action = MAX_ETH_FILTER_ACTION;
1228         }
1229
1230         return action;
1231 }
1232
1233 static int
1234 qed_filter_ucast_common(struct qed_hwfn *p_hwfn,
1235                         u16 opaque_fid,
1236                         struct qed_filter_ucast *p_filter_cmd,
1237                         struct vport_filter_update_ramrod_data **pp_ramrod,
1238                         struct qed_spq_entry **pp_ent,
1239                         enum spq_mode comp_mode,
1240                         struct qed_spq_comp_cb *p_comp_data)
1241 {
1242         u8 vport_to_add_to = 0, vport_to_remove_from = 0;
1243         struct vport_filter_update_ramrod_data *p_ramrod;
1244         struct eth_filter_cmd *p_first_filter;
1245         struct eth_filter_cmd *p_second_filter;
1246         struct qed_sp_init_data init_data;
1247         enum eth_filter_action action;
1248         int rc;
1249
1250         rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
1251                           &vport_to_remove_from);
1252         if (rc)
1253                 return rc;
1254
1255         rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
1256                           &vport_to_add_to);
1257         if (rc)
1258                 return rc;
1259
1260         /* Get SPQ entry */
1261         memset(&init_data, 0, sizeof(init_data));
1262         init_data.cid = qed_spq_get_cid(p_hwfn);
1263         init_data.opaque_fid = opaque_fid;
1264         init_data.comp_mode = comp_mode;
1265         init_data.p_comp_data = p_comp_data;
1266
1267         rc = qed_sp_init_request(p_hwfn, pp_ent,
1268                                  ETH_RAMROD_FILTERS_UPDATE,
1269                                  PROTOCOLID_ETH, &init_data);
1270         if (rc)
1271                 return rc;
1272
1273         *pp_ramrod = &(*pp_ent)->ramrod.vport_filter_update;
1274         p_ramrod = *pp_ramrod;
1275         p_ramrod->filter_cmd_hdr.rx = p_filter_cmd->is_rx_filter ? 1 : 0;
1276         p_ramrod->filter_cmd_hdr.tx = p_filter_cmd->is_tx_filter ? 1 : 0;
1277
1278         switch (p_filter_cmd->opcode) {
1279         case QED_FILTER_REPLACE:
1280         case QED_FILTER_MOVE:
1281                 p_ramrod->filter_cmd_hdr.cmd_cnt = 2; break;
1282         default:
1283                 p_ramrod->filter_cmd_hdr.cmd_cnt = 1; break;
1284         }
1285
1286         p_first_filter  = &p_ramrod->filter_cmds[0];
1287         p_second_filter = &p_ramrod->filter_cmds[1];
1288
1289         switch (p_filter_cmd->type) {
1290         case QED_FILTER_MAC:
1291                 p_first_filter->type = ETH_FILTER_TYPE_MAC; break;
1292         case QED_FILTER_VLAN:
1293                 p_first_filter->type = ETH_FILTER_TYPE_VLAN; break;
1294         case QED_FILTER_MAC_VLAN:
1295                 p_first_filter->type = ETH_FILTER_TYPE_PAIR; break;
1296         case QED_FILTER_INNER_MAC:
1297                 p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC; break;
1298         case QED_FILTER_INNER_VLAN:
1299                 p_first_filter->type = ETH_FILTER_TYPE_INNER_VLAN; break;
1300         case QED_FILTER_INNER_PAIR:
1301                 p_first_filter->type = ETH_FILTER_TYPE_INNER_PAIR; break;
1302         case QED_FILTER_INNER_MAC_VNI_PAIR:
1303                 p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR;
1304                 break;
1305         case QED_FILTER_MAC_VNI_PAIR:
1306                 p_first_filter->type = ETH_FILTER_TYPE_MAC_VNI_PAIR; break;
1307         case QED_FILTER_VNI:
1308                 p_first_filter->type = ETH_FILTER_TYPE_VNI; break;
1309         }
1310
1311         if ((p_first_filter->type == ETH_FILTER_TYPE_MAC) ||
1312             (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
1313             (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC) ||
1314             (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR) ||
1315             (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
1316             (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR)) {
1317                 qed_set_fw_mac_addr(&p_first_filter->mac_msb,
1318                                     &p_first_filter->mac_mid,
1319                                     &p_first_filter->mac_lsb,
1320                                     (u8 *)p_filter_cmd->mac);
1321         }
1322
1323         if ((p_first_filter->type == ETH_FILTER_TYPE_VLAN) ||
1324             (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
1325             (p_first_filter->type == ETH_FILTER_TYPE_INNER_VLAN) ||
1326             (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR))
1327                 p_first_filter->vlan_id = cpu_to_le16(p_filter_cmd->vlan);
1328
1329         if ((p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
1330             (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR) ||
1331             (p_first_filter->type == ETH_FILTER_TYPE_VNI))
1332                 p_first_filter->vni = cpu_to_le32(p_filter_cmd->vni);
1333
1334         if (p_filter_cmd->opcode == QED_FILTER_MOVE) {
1335                 p_second_filter->type = p_first_filter->type;
1336                 p_second_filter->mac_msb = p_first_filter->mac_msb;
1337                 p_second_filter->mac_mid = p_first_filter->mac_mid;
1338                 p_second_filter->mac_lsb = p_first_filter->mac_lsb;
1339                 p_second_filter->vlan_id = p_first_filter->vlan_id;
1340                 p_second_filter->vni = p_first_filter->vni;
1341
1342                 p_first_filter->action = ETH_FILTER_ACTION_REMOVE;
1343
1344                 p_first_filter->vport_id = vport_to_remove_from;
1345
1346                 p_second_filter->action = ETH_FILTER_ACTION_ADD;
1347                 p_second_filter->vport_id = vport_to_add_to;
1348         } else if (p_filter_cmd->opcode == QED_FILTER_REPLACE) {
1349                 p_first_filter->vport_id = vport_to_add_to;
1350                 memcpy(p_second_filter, p_first_filter,
1351                        sizeof(*p_second_filter));
1352                 p_first_filter->action  = ETH_FILTER_ACTION_REMOVE_ALL;
1353                 p_second_filter->action = ETH_FILTER_ACTION_ADD;
1354         } else {
1355                 action = qed_filter_action(p_filter_cmd->opcode);
1356
1357                 if (action == MAX_ETH_FILTER_ACTION) {
1358                         DP_NOTICE(p_hwfn,
1359                                   "%d is not supported yet\n",
1360                                   p_filter_cmd->opcode);
1361                         qed_sp_destroy_request(p_hwfn, *pp_ent);
1362                         return -EINVAL;
1363                 }
1364
1365                 p_first_filter->action = action;
1366                 p_first_filter->vport_id = (p_filter_cmd->opcode ==
1367                                             QED_FILTER_REMOVE) ?
1368                                            vport_to_remove_from :
1369                                            vport_to_add_to;
1370         }
1371
1372         return 0;
1373 }
1374
1375 int qed_sp_eth_filter_ucast(struct qed_hwfn *p_hwfn,
1376                             u16 opaque_fid,
1377                             struct qed_filter_ucast *p_filter_cmd,
1378                             enum spq_mode comp_mode,
1379                             struct qed_spq_comp_cb *p_comp_data)
1380 {
1381         struct vport_filter_update_ramrod_data  *p_ramrod       = NULL;
1382         struct qed_spq_entry                    *p_ent          = NULL;
1383         struct eth_filter_cmd_header            *p_header;
1384         int                                     rc;
1385
1386         rc = qed_filter_ucast_common(p_hwfn, opaque_fid, p_filter_cmd,
1387                                      &p_ramrod, &p_ent,
1388                                      comp_mode, p_comp_data);
1389         if (rc) {
1390                 DP_ERR(p_hwfn, "Uni. filter command failed %d\n", rc);
1391                 return rc;
1392         }
1393         p_header = &p_ramrod->filter_cmd_hdr;
1394         p_header->assert_on_error = p_filter_cmd->assert_on_error;
1395
1396         rc = qed_spq_post(p_hwfn, p_ent, NULL);
1397         if (rc) {
1398                 DP_ERR(p_hwfn, "Unicast filter ADD command failed %d\n", rc);
1399                 return rc;
1400         }
1401
1402         DP_VERBOSE(p_hwfn, QED_MSG_SP,
1403                    "Unicast filter configured, opcode = %s, type = %s, cmd_cnt = %d, is_rx_filter = %d, is_tx_filter = %d\n",
1404                    (p_filter_cmd->opcode == QED_FILTER_ADD) ? "ADD" :
1405                    ((p_filter_cmd->opcode == QED_FILTER_REMOVE) ?
1406                    "REMOVE" :
1407                    ((p_filter_cmd->opcode == QED_FILTER_MOVE) ?
1408                     "MOVE" : "REPLACE")),
1409                    (p_filter_cmd->type == QED_FILTER_MAC) ? "MAC" :
1410                    ((p_filter_cmd->type == QED_FILTER_VLAN) ?
1411                     "VLAN" : "MAC & VLAN"),
1412                    p_ramrod->filter_cmd_hdr.cmd_cnt,
1413                    p_filter_cmd->is_rx_filter,
1414                    p_filter_cmd->is_tx_filter);
1415         DP_VERBOSE(p_hwfn, QED_MSG_SP,
1416                    "vport_to_add_to = %d, vport_to_remove_from = %d, mac = %2x:%2x:%2x:%2x:%2x:%2x, vlan = %d\n",
1417                    p_filter_cmd->vport_to_add_to,
1418                    p_filter_cmd->vport_to_remove_from,
1419                    p_filter_cmd->mac[0],
1420                    p_filter_cmd->mac[1],
1421                    p_filter_cmd->mac[2],
1422                    p_filter_cmd->mac[3],
1423                    p_filter_cmd->mac[4],
1424                    p_filter_cmd->mac[5],
1425                    p_filter_cmd->vlan);
1426
1427         return 0;
1428 }
1429
1430 /*******************************************************************************
1431  * Description:
1432  *         Calculates crc 32 on a buffer
1433  *         Note: crc32_length MUST be aligned to 8
1434  * Return:
1435  ******************************************************************************/
1436 static u32 qed_calc_crc32c(u8 *crc32_packet,
1437                            u32 crc32_length, u32 crc32_seed, u8 complement)
1438 {
1439         u32 byte = 0, bit = 0, crc32_result = crc32_seed;
1440         u8 msb = 0, current_byte = 0;
1441
1442         if ((!crc32_packet) ||
1443             (crc32_length == 0) ||
1444             ((crc32_length % 8) != 0))
1445                 return crc32_result;
1446         for (byte = 0; byte < crc32_length; byte++) {
1447                 current_byte = crc32_packet[byte];
1448                 for (bit = 0; bit < 8; bit++) {
1449                         msb = (u8)(crc32_result >> 31);
1450                         crc32_result = crc32_result << 1;
1451                         if (msb != (0x1 & (current_byte >> bit))) {
1452                                 crc32_result = crc32_result ^ CRC32_POLY;
1453                                 crc32_result |= 1; /*crc32_result[0] = 1;*/
1454                         }
1455                 }
1456         }
1457         return crc32_result;
1458 }
1459
1460 static u32 qed_crc32c_le(u32 seed, u8 *mac, u32 len)
1461 {
1462         u32 packet_buf[2] = { 0 };
1463
1464         memcpy((u8 *)(&packet_buf[0]), &mac[0], 6);
1465         return qed_calc_crc32c((u8 *)packet_buf, 8, seed, 0);
1466 }
1467
1468 u8 qed_mcast_bin_from_mac(u8 *mac)
1469 {
1470         u32 crc = qed_crc32c_le(ETH_MULTICAST_BIN_FROM_MAC_SEED,
1471                                 mac, ETH_ALEN);
1472
1473         return crc & 0xff;
1474 }
1475
1476 static int
1477 qed_sp_eth_filter_mcast(struct qed_hwfn *p_hwfn,
1478                         u16 opaque_fid,
1479                         struct qed_filter_mcast *p_filter_cmd,
1480                         enum spq_mode comp_mode,
1481                         struct qed_spq_comp_cb *p_comp_data)
1482 {
1483         struct vport_update_ramrod_data *p_ramrod = NULL;
1484         u32 bins[ETH_MULTICAST_MAC_BINS_IN_REGS];
1485         struct qed_spq_entry *p_ent = NULL;
1486         struct qed_sp_init_data init_data;
1487         u8 abs_vport_id = 0;
1488         int rc, i;
1489
1490         if (p_filter_cmd->opcode == QED_FILTER_ADD)
1491                 rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
1492                                   &abs_vport_id);
1493         else
1494                 rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
1495                                   &abs_vport_id);
1496         if (rc)
1497                 return rc;
1498
1499         /* Get SPQ entry */
1500         memset(&init_data, 0, sizeof(init_data));
1501         init_data.cid = qed_spq_get_cid(p_hwfn);
1502         init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1503         init_data.comp_mode = comp_mode;
1504         init_data.p_comp_data = p_comp_data;
1505
1506         rc = qed_sp_init_request(p_hwfn, &p_ent,
1507                                  ETH_RAMROD_VPORT_UPDATE,
1508                                  PROTOCOLID_ETH, &init_data);
1509         if (rc) {
1510                 DP_ERR(p_hwfn, "Multi-cast command failed %d\n", rc);
1511                 return rc;
1512         }
1513
1514         p_ramrod = &p_ent->ramrod.vport_update;
1515         p_ramrod->common.update_approx_mcast_flg = 1;
1516
1517         /* explicitly clear out the entire vector */
1518         memset(&p_ramrod->approx_mcast.bins, 0,
1519                sizeof(p_ramrod->approx_mcast.bins));
1520         memset(bins, 0, sizeof(bins));
1521         /* filter ADD op is explicit set op and it removes
1522          *  any existing filters for the vport
1523          */
1524         if (p_filter_cmd->opcode == QED_FILTER_ADD) {
1525                 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1526                         u32 bit, nbits;
1527
1528                         bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1529                         nbits = sizeof(u32) * BITS_PER_BYTE;
1530                         bins[bit / nbits] |= 1 << (bit % nbits);
1531                 }
1532
1533                 /* Convert to correct endianity */
1534                 for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
1535                         struct vport_update_ramrod_mcast *p_ramrod_bins;
1536
1537                         p_ramrod_bins = &p_ramrod->approx_mcast;
1538                         p_ramrod_bins->bins[i] = cpu_to_le32(bins[i]);
1539                 }
1540         }
1541
1542         p_ramrod->common.vport_id = abs_vport_id;
1543
1544         return qed_spq_post(p_hwfn, p_ent, NULL);
1545 }
1546
1547 static int qed_filter_mcast_cmd(struct qed_dev *cdev,
1548                                 struct qed_filter_mcast *p_filter_cmd,
1549                                 enum spq_mode comp_mode,
1550                                 struct qed_spq_comp_cb *p_comp_data)
1551 {
1552         int rc = 0;
1553         int i;
1554
1555         /* only ADD and REMOVE operations are supported for multi-cast */
1556         if ((p_filter_cmd->opcode != QED_FILTER_ADD &&
1557              (p_filter_cmd->opcode != QED_FILTER_REMOVE)) ||
1558             (p_filter_cmd->num_mc_addrs > QED_MAX_MC_ADDRS))
1559                 return -EINVAL;
1560
1561         for_each_hwfn(cdev, i) {
1562                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1563
1564                 u16 opaque_fid;
1565
1566                 if (IS_VF(cdev)) {
1567                         qed_vf_pf_filter_mcast(p_hwfn, p_filter_cmd);
1568                         continue;
1569                 }
1570
1571                 opaque_fid = p_hwfn->hw_info.opaque_fid;
1572
1573                 rc = qed_sp_eth_filter_mcast(p_hwfn,
1574                                              opaque_fid,
1575                                              p_filter_cmd,
1576                                              comp_mode, p_comp_data);
1577         }
1578         return rc;
1579 }
1580
1581 static int qed_filter_ucast_cmd(struct qed_dev *cdev,
1582                                 struct qed_filter_ucast *p_filter_cmd,
1583                                 enum spq_mode comp_mode,
1584                                 struct qed_spq_comp_cb *p_comp_data)
1585 {
1586         int rc = 0;
1587         int i;
1588
1589         for_each_hwfn(cdev, i) {
1590                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1591                 u16 opaque_fid;
1592
1593                 if (IS_VF(cdev)) {
1594                         rc = qed_vf_pf_filter_ucast(p_hwfn, p_filter_cmd);
1595                         continue;
1596                 }
1597
1598                 opaque_fid = p_hwfn->hw_info.opaque_fid;
1599
1600                 rc = qed_sp_eth_filter_ucast(p_hwfn,
1601                                              opaque_fid,
1602                                              p_filter_cmd,
1603                                              comp_mode, p_comp_data);
1604                 if (rc)
1605                         break;
1606         }
1607
1608         return rc;
1609 }
1610
1611 /* Statistics related code */
1612 static void __qed_get_vport_pstats_addrlen(struct qed_hwfn *p_hwfn,
1613                                            u32 *p_addr,
1614                                            u32 *p_len, u16 statistics_bin)
1615 {
1616         if (IS_PF(p_hwfn->cdev)) {
1617                 *p_addr = BAR0_MAP_REG_PSDM_RAM +
1618                     PSTORM_QUEUE_STAT_OFFSET(statistics_bin);
1619                 *p_len = sizeof(struct eth_pstorm_per_queue_stat);
1620         } else {
1621                 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1622                 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1623
1624                 *p_addr = p_resp->pfdev_info.stats_info.pstats.address;
1625                 *p_len = p_resp->pfdev_info.stats_info.pstats.len;
1626         }
1627 }
1628
1629 static void __qed_get_vport_pstats(struct qed_hwfn *p_hwfn,
1630                                    struct qed_ptt *p_ptt,
1631                                    struct qed_eth_stats *p_stats,
1632                                    u16 statistics_bin)
1633 {
1634         struct eth_pstorm_per_queue_stat pstats;
1635         u32 pstats_addr = 0, pstats_len = 0;
1636
1637         __qed_get_vport_pstats_addrlen(p_hwfn, &pstats_addr, &pstats_len,
1638                                        statistics_bin);
1639
1640         memset(&pstats, 0, sizeof(pstats));
1641         qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, pstats_len);
1642
1643         p_stats->common.tx_ucast_bytes +=
1644             HILO_64_REGPAIR(pstats.sent_ucast_bytes);
1645         p_stats->common.tx_mcast_bytes +=
1646             HILO_64_REGPAIR(pstats.sent_mcast_bytes);
1647         p_stats->common.tx_bcast_bytes +=
1648             HILO_64_REGPAIR(pstats.sent_bcast_bytes);
1649         p_stats->common.tx_ucast_pkts +=
1650             HILO_64_REGPAIR(pstats.sent_ucast_pkts);
1651         p_stats->common.tx_mcast_pkts +=
1652             HILO_64_REGPAIR(pstats.sent_mcast_pkts);
1653         p_stats->common.tx_bcast_pkts +=
1654             HILO_64_REGPAIR(pstats.sent_bcast_pkts);
1655         p_stats->common.tx_err_drop_pkts +=
1656             HILO_64_REGPAIR(pstats.error_drop_pkts);
1657 }
1658
1659 static void __qed_get_vport_tstats(struct qed_hwfn *p_hwfn,
1660                                    struct qed_ptt *p_ptt,
1661                                    struct qed_eth_stats *p_stats,
1662                                    u16 statistics_bin)
1663 {
1664         struct tstorm_per_port_stat tstats;
1665         u32 tstats_addr, tstats_len;
1666
1667         if (IS_PF(p_hwfn->cdev)) {
1668                 tstats_addr = BAR0_MAP_REG_TSDM_RAM +
1669                     TSTORM_PORT_STAT_OFFSET(MFW_PORT(p_hwfn));
1670                 tstats_len = sizeof(struct tstorm_per_port_stat);
1671         } else {
1672                 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1673                 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1674
1675                 tstats_addr = p_resp->pfdev_info.stats_info.tstats.address;
1676                 tstats_len = p_resp->pfdev_info.stats_info.tstats.len;
1677         }
1678
1679         memset(&tstats, 0, sizeof(tstats));
1680         qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, tstats_len);
1681
1682         p_stats->common.mftag_filter_discards +=
1683             HILO_64_REGPAIR(tstats.mftag_filter_discard);
1684         p_stats->common.mac_filter_discards +=
1685             HILO_64_REGPAIR(tstats.eth_mac_filter_discard);
1686         p_stats->common.gft_filter_drop +=
1687                 HILO_64_REGPAIR(tstats.eth_gft_drop_pkt);
1688 }
1689
1690 static void __qed_get_vport_ustats_addrlen(struct qed_hwfn *p_hwfn,
1691                                            u32 *p_addr,
1692                                            u32 *p_len, u16 statistics_bin)
1693 {
1694         if (IS_PF(p_hwfn->cdev)) {
1695                 *p_addr = BAR0_MAP_REG_USDM_RAM +
1696                     USTORM_QUEUE_STAT_OFFSET(statistics_bin);
1697                 *p_len = sizeof(struct eth_ustorm_per_queue_stat);
1698         } else {
1699                 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1700                 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1701
1702                 *p_addr = p_resp->pfdev_info.stats_info.ustats.address;
1703                 *p_len = p_resp->pfdev_info.stats_info.ustats.len;
1704         }
1705 }
1706
1707 static void __qed_get_vport_ustats(struct qed_hwfn *p_hwfn,
1708                                    struct qed_ptt *p_ptt,
1709                                    struct qed_eth_stats *p_stats,
1710                                    u16 statistics_bin)
1711 {
1712         struct eth_ustorm_per_queue_stat ustats;
1713         u32 ustats_addr = 0, ustats_len = 0;
1714
1715         __qed_get_vport_ustats_addrlen(p_hwfn, &ustats_addr, &ustats_len,
1716                                        statistics_bin);
1717
1718         memset(&ustats, 0, sizeof(ustats));
1719         qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, ustats_len);
1720
1721         p_stats->common.rx_ucast_bytes +=
1722             HILO_64_REGPAIR(ustats.rcv_ucast_bytes);
1723         p_stats->common.rx_mcast_bytes +=
1724             HILO_64_REGPAIR(ustats.rcv_mcast_bytes);
1725         p_stats->common.rx_bcast_bytes +=
1726             HILO_64_REGPAIR(ustats.rcv_bcast_bytes);
1727         p_stats->common.rx_ucast_pkts += HILO_64_REGPAIR(ustats.rcv_ucast_pkts);
1728         p_stats->common.rx_mcast_pkts += HILO_64_REGPAIR(ustats.rcv_mcast_pkts);
1729         p_stats->common.rx_bcast_pkts += HILO_64_REGPAIR(ustats.rcv_bcast_pkts);
1730 }
1731
1732 static void __qed_get_vport_mstats_addrlen(struct qed_hwfn *p_hwfn,
1733                                            u32 *p_addr,
1734                                            u32 *p_len, u16 statistics_bin)
1735 {
1736         if (IS_PF(p_hwfn->cdev)) {
1737                 *p_addr = BAR0_MAP_REG_MSDM_RAM +
1738                     MSTORM_QUEUE_STAT_OFFSET(statistics_bin);
1739                 *p_len = sizeof(struct eth_mstorm_per_queue_stat);
1740         } else {
1741                 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1742                 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1743
1744                 *p_addr = p_resp->pfdev_info.stats_info.mstats.address;
1745                 *p_len = p_resp->pfdev_info.stats_info.mstats.len;
1746         }
1747 }
1748
1749 static void __qed_get_vport_mstats(struct qed_hwfn *p_hwfn,
1750                                    struct qed_ptt *p_ptt,
1751                                    struct qed_eth_stats *p_stats,
1752                                    u16 statistics_bin)
1753 {
1754         struct eth_mstorm_per_queue_stat mstats;
1755         u32 mstats_addr = 0, mstats_len = 0;
1756
1757         __qed_get_vport_mstats_addrlen(p_hwfn, &mstats_addr, &mstats_len,
1758                                        statistics_bin);
1759
1760         memset(&mstats, 0, sizeof(mstats));
1761         qed_memcpy_from(p_hwfn, p_ptt, &mstats, mstats_addr, mstats_len);
1762
1763         p_stats->common.no_buff_discards +=
1764             HILO_64_REGPAIR(mstats.no_buff_discard);
1765         p_stats->common.packet_too_big_discard +=
1766             HILO_64_REGPAIR(mstats.packet_too_big_discard);
1767         p_stats->common.ttl0_discard += HILO_64_REGPAIR(mstats.ttl0_discard);
1768         p_stats->common.tpa_coalesced_pkts +=
1769             HILO_64_REGPAIR(mstats.tpa_coalesced_pkts);
1770         p_stats->common.tpa_coalesced_events +=
1771             HILO_64_REGPAIR(mstats.tpa_coalesced_events);
1772         p_stats->common.tpa_aborts_num +=
1773             HILO_64_REGPAIR(mstats.tpa_aborts_num);
1774         p_stats->common.tpa_coalesced_bytes +=
1775             HILO_64_REGPAIR(mstats.tpa_coalesced_bytes);
1776 }
1777
1778 static void __qed_get_vport_port_stats(struct qed_hwfn *p_hwfn,
1779                                        struct qed_ptt *p_ptt,
1780                                        struct qed_eth_stats *p_stats)
1781 {
1782         struct qed_eth_stats_common *p_common = &p_stats->common;
1783         struct port_stats port_stats;
1784         int j;
1785
1786         memset(&port_stats, 0, sizeof(port_stats));
1787
1788         qed_memcpy_from(p_hwfn, p_ptt, &port_stats,
1789                         p_hwfn->mcp_info->port_addr +
1790                         offsetof(struct public_port, stats),
1791                         sizeof(port_stats));
1792
1793         p_common->rx_64_byte_packets += port_stats.eth.r64;
1794         p_common->rx_65_to_127_byte_packets += port_stats.eth.r127;
1795         p_common->rx_128_to_255_byte_packets += port_stats.eth.r255;
1796         p_common->rx_256_to_511_byte_packets += port_stats.eth.r511;
1797         p_common->rx_512_to_1023_byte_packets += port_stats.eth.r1023;
1798         p_common->rx_1024_to_1518_byte_packets += port_stats.eth.r1518;
1799         p_common->rx_crc_errors += port_stats.eth.rfcs;
1800         p_common->rx_mac_crtl_frames += port_stats.eth.rxcf;
1801         p_common->rx_pause_frames += port_stats.eth.rxpf;
1802         p_common->rx_pfc_frames += port_stats.eth.rxpp;
1803         p_common->rx_align_errors += port_stats.eth.raln;
1804         p_common->rx_carrier_errors += port_stats.eth.rfcr;
1805         p_common->rx_oversize_packets += port_stats.eth.rovr;
1806         p_common->rx_jabbers += port_stats.eth.rjbr;
1807         p_common->rx_undersize_packets += port_stats.eth.rund;
1808         p_common->rx_fragments += port_stats.eth.rfrg;
1809         p_common->tx_64_byte_packets += port_stats.eth.t64;
1810         p_common->tx_65_to_127_byte_packets += port_stats.eth.t127;
1811         p_common->tx_128_to_255_byte_packets += port_stats.eth.t255;
1812         p_common->tx_256_to_511_byte_packets += port_stats.eth.t511;
1813         p_common->tx_512_to_1023_byte_packets += port_stats.eth.t1023;
1814         p_common->tx_1024_to_1518_byte_packets += port_stats.eth.t1518;
1815         p_common->tx_pause_frames += port_stats.eth.txpf;
1816         p_common->tx_pfc_frames += port_stats.eth.txpp;
1817         p_common->rx_mac_bytes += port_stats.eth.rbyte;
1818         p_common->rx_mac_uc_packets += port_stats.eth.rxuca;
1819         p_common->rx_mac_mc_packets += port_stats.eth.rxmca;
1820         p_common->rx_mac_bc_packets += port_stats.eth.rxbca;
1821         p_common->rx_mac_frames_ok += port_stats.eth.rxpok;
1822         p_common->tx_mac_bytes += port_stats.eth.tbyte;
1823         p_common->tx_mac_uc_packets += port_stats.eth.txuca;
1824         p_common->tx_mac_mc_packets += port_stats.eth.txmca;
1825         p_common->tx_mac_bc_packets += port_stats.eth.txbca;
1826         p_common->tx_mac_ctrl_frames += port_stats.eth.txcf;
1827         for (j = 0; j < 8; j++) {
1828                 p_common->brb_truncates += port_stats.brb.brb_truncate[j];
1829                 p_common->brb_discards += port_stats.brb.brb_discard[j];
1830         }
1831
1832         if (QED_IS_BB(p_hwfn->cdev)) {
1833                 struct qed_eth_stats_bb *p_bb = &p_stats->bb;
1834
1835                 p_bb->rx_1519_to_1522_byte_packets +=
1836                     port_stats.eth.u0.bb0.r1522;
1837                 p_bb->rx_1519_to_2047_byte_packets +=
1838                     port_stats.eth.u0.bb0.r2047;
1839                 p_bb->rx_2048_to_4095_byte_packets +=
1840                     port_stats.eth.u0.bb0.r4095;
1841                 p_bb->rx_4096_to_9216_byte_packets +=
1842                     port_stats.eth.u0.bb0.r9216;
1843                 p_bb->rx_9217_to_16383_byte_packets +=
1844                     port_stats.eth.u0.bb0.r16383;
1845                 p_bb->tx_1519_to_2047_byte_packets +=
1846                     port_stats.eth.u1.bb1.t2047;
1847                 p_bb->tx_2048_to_4095_byte_packets +=
1848                     port_stats.eth.u1.bb1.t4095;
1849                 p_bb->tx_4096_to_9216_byte_packets +=
1850                     port_stats.eth.u1.bb1.t9216;
1851                 p_bb->tx_9217_to_16383_byte_packets +=
1852                     port_stats.eth.u1.bb1.t16383;
1853                 p_bb->tx_lpi_entry_count += port_stats.eth.u2.bb2.tlpiec;
1854                 p_bb->tx_total_collisions += port_stats.eth.u2.bb2.tncl;
1855         } else {
1856                 struct qed_eth_stats_ah *p_ah = &p_stats->ah;
1857
1858                 p_ah->rx_1519_to_max_byte_packets +=
1859                     port_stats.eth.u0.ah0.r1519_to_max;
1860                 p_ah->tx_1519_to_max_byte_packets =
1861                     port_stats.eth.u1.ah1.t1519_to_max;
1862         }
1863
1864         p_common->link_change_count = qed_rd(p_hwfn, p_ptt,
1865                                              p_hwfn->mcp_info->port_addr +
1866                                              offsetof(struct public_port,
1867                                                       link_change_count));
1868 }
1869
1870 static void __qed_get_vport_stats(struct qed_hwfn *p_hwfn,
1871                                   struct qed_ptt *p_ptt,
1872                                   struct qed_eth_stats *stats,
1873                                   u16 statistics_bin, bool b_get_port_stats)
1874 {
1875         __qed_get_vport_mstats(p_hwfn, p_ptt, stats, statistics_bin);
1876         __qed_get_vport_ustats(p_hwfn, p_ptt, stats, statistics_bin);
1877         __qed_get_vport_tstats(p_hwfn, p_ptt, stats, statistics_bin);
1878         __qed_get_vport_pstats(p_hwfn, p_ptt, stats, statistics_bin);
1879
1880         if (b_get_port_stats && p_hwfn->mcp_info)
1881                 __qed_get_vport_port_stats(p_hwfn, p_ptt, stats);
1882 }
1883
1884 static void _qed_get_vport_stats(struct qed_dev *cdev,
1885                                  struct qed_eth_stats *stats)
1886 {
1887         u8 fw_vport = 0;
1888         int i;
1889
1890         memset(stats, 0, sizeof(*stats));
1891
1892         for_each_hwfn(cdev, i) {
1893                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1894                 struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
1895                                                     :  NULL;
1896
1897                 if (IS_PF(cdev)) {
1898                         /* The main vport index is relative first */
1899                         if (qed_fw_vport(p_hwfn, 0, &fw_vport)) {
1900                                 DP_ERR(p_hwfn, "No vport available!\n");
1901                                 goto out;
1902                         }
1903                 }
1904
1905                 if (IS_PF(cdev) && !p_ptt) {
1906                         DP_ERR(p_hwfn, "Failed to acquire ptt\n");
1907                         continue;
1908                 }
1909
1910                 __qed_get_vport_stats(p_hwfn, p_ptt, stats, fw_vport,
1911                                       IS_PF(cdev) ? true : false);
1912
1913 out:
1914                 if (IS_PF(cdev) && p_ptt)
1915                         qed_ptt_release(p_hwfn, p_ptt);
1916         }
1917 }
1918
1919 void qed_get_vport_stats(struct qed_dev *cdev, struct qed_eth_stats *stats)
1920 {
1921         u32 i;
1922
1923         if (!cdev) {
1924                 memset(stats, 0, sizeof(*stats));
1925                 return;
1926         }
1927
1928         _qed_get_vport_stats(cdev, stats);
1929
1930         if (!cdev->reset_stats)
1931                 return;
1932
1933         /* Reduce the statistics baseline */
1934         for (i = 0; i < sizeof(struct qed_eth_stats) / sizeof(u64); i++)
1935                 ((u64 *)stats)[i] -= ((u64 *)cdev->reset_stats)[i];
1936 }
1937
1938 /* zeroes V-PORT specific portion of stats (Port stats remains untouched) */
1939 void qed_reset_vport_stats(struct qed_dev *cdev)
1940 {
1941         int i;
1942
1943         for_each_hwfn(cdev, i) {
1944                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1945                 struct eth_mstorm_per_queue_stat mstats;
1946                 struct eth_ustorm_per_queue_stat ustats;
1947                 struct eth_pstorm_per_queue_stat pstats;
1948                 struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
1949                                                     : NULL;
1950                 u32 addr = 0, len = 0;
1951
1952                 if (IS_PF(cdev) && !p_ptt) {
1953                         DP_ERR(p_hwfn, "Failed to acquire ptt\n");
1954                         continue;
1955                 }
1956
1957                 memset(&mstats, 0, sizeof(mstats));
1958                 __qed_get_vport_mstats_addrlen(p_hwfn, &addr, &len, 0);
1959                 qed_memcpy_to(p_hwfn, p_ptt, addr, &mstats, len);
1960
1961                 memset(&ustats, 0, sizeof(ustats));
1962                 __qed_get_vport_ustats_addrlen(p_hwfn, &addr, &len, 0);
1963                 qed_memcpy_to(p_hwfn, p_ptt, addr, &ustats, len);
1964
1965                 memset(&pstats, 0, sizeof(pstats));
1966                 __qed_get_vport_pstats_addrlen(p_hwfn, &addr, &len, 0);
1967                 qed_memcpy_to(p_hwfn, p_ptt, addr, &pstats, len);
1968
1969                 if (IS_PF(cdev))
1970                         qed_ptt_release(p_hwfn, p_ptt);
1971         }
1972
1973         /* PORT statistics are not necessarily reset, so we need to
1974          * read and create a baseline for future statistics.
1975          * Link change stat is maintained by MFW, return its value as is.
1976          */
1977         if (!cdev->reset_stats) {
1978                 DP_INFO(cdev, "Reset stats not allocated\n");
1979         } else {
1980                 _qed_get_vport_stats(cdev, cdev->reset_stats);
1981                 cdev->reset_stats->common.link_change_count = 0;
1982         }
1983 }
1984
1985 static enum gft_profile_type
1986 qed_arfs_mode_to_hsi(enum qed_filter_config_mode mode)
1987 {
1988         if (mode == QED_FILTER_CONFIG_MODE_5_TUPLE)
1989                 return GFT_PROFILE_TYPE_4_TUPLE;
1990         if (mode == QED_FILTER_CONFIG_MODE_IP_DEST)
1991                 return GFT_PROFILE_TYPE_IP_DST_ADDR;
1992         if (mode == QED_FILTER_CONFIG_MODE_IP_SRC)
1993                 return GFT_PROFILE_TYPE_IP_SRC_ADDR;
1994         return GFT_PROFILE_TYPE_L4_DST_PORT;
1995 }
1996
1997 void qed_arfs_mode_configure(struct qed_hwfn *p_hwfn,
1998                              struct qed_ptt *p_ptt,
1999                              struct qed_arfs_config_params *p_cfg_params)
2000 {
2001         if (p_cfg_params->mode != QED_FILTER_CONFIG_MODE_DISABLE) {
2002                 qed_gft_config(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
2003                                p_cfg_params->tcp,
2004                                p_cfg_params->udp,
2005                                p_cfg_params->ipv4,
2006                                p_cfg_params->ipv6,
2007                                qed_arfs_mode_to_hsi(p_cfg_params->mode));
2008                 DP_VERBOSE(p_hwfn,
2009                            QED_MSG_SP,
2010                            "Configured Filtering: tcp = %s, udp = %s, ipv4 = %s, ipv6 =%s mode=%08x\n",
2011                            p_cfg_params->tcp ? "Enable" : "Disable",
2012                            p_cfg_params->udp ? "Enable" : "Disable",
2013                            p_cfg_params->ipv4 ? "Enable" : "Disable",
2014                            p_cfg_params->ipv6 ? "Enable" : "Disable",
2015                            (u32)p_cfg_params->mode);
2016         } else {
2017                 DP_VERBOSE(p_hwfn, QED_MSG_SP, "Disabled Filtering\n");
2018                 qed_gft_disable(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
2019         }
2020 }
2021
2022 int
2023 qed_configure_rfs_ntuple_filter(struct qed_hwfn *p_hwfn,
2024                                 struct qed_spq_comp_cb *p_cb,
2025                                 struct qed_ntuple_filter_params *p_params)
2026 {
2027         struct rx_update_gft_filter_data *p_ramrod = NULL;
2028         struct qed_spq_entry *p_ent = NULL;
2029         struct qed_sp_init_data init_data;
2030         u16 abs_rx_q_id = 0;
2031         u8 abs_vport_id = 0;
2032         int rc = -EINVAL;
2033
2034         /* Get SPQ entry */
2035         memset(&init_data, 0, sizeof(init_data));
2036         init_data.cid = qed_spq_get_cid(p_hwfn);
2037
2038         init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
2039
2040         if (p_cb) {
2041                 init_data.comp_mode = QED_SPQ_MODE_CB;
2042                 init_data.p_comp_data = p_cb;
2043         } else {
2044                 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
2045         }
2046
2047         rc = qed_sp_init_request(p_hwfn, &p_ent,
2048                                  ETH_RAMROD_GFT_UPDATE_FILTER,
2049                                  PROTOCOLID_ETH, &init_data);
2050         if (rc)
2051                 return rc;
2052
2053         p_ramrod = &p_ent->ramrod.rx_update_gft;
2054
2055         DMA_REGPAIR_LE(p_ramrod->pkt_hdr_addr, p_params->addr);
2056         p_ramrod->pkt_hdr_length = cpu_to_le16(p_params->length);
2057
2058         if (p_params->b_is_drop) {
2059                 p_ramrod->vport_id = cpu_to_le16(ETH_GFT_TRASHCAN_VPORT);
2060         } else {
2061                 rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
2062                 if (rc)
2063                         goto err;
2064
2065                 if (p_params->qid != QED_RFS_NTUPLE_QID_RSS) {
2066                         rc = qed_fw_l2_queue(p_hwfn, p_params->qid,
2067                                              &abs_rx_q_id);
2068                         if (rc)
2069                                 goto err;
2070
2071                         p_ramrod->rx_qid_valid = 1;
2072                         p_ramrod->rx_qid = cpu_to_le16(abs_rx_q_id);
2073                 }
2074
2075                 p_ramrod->vport_id = cpu_to_le16((u16)abs_vport_id);
2076         }
2077
2078         p_ramrod->flow_id_valid = 0;
2079         p_ramrod->flow_id = 0;
2080         p_ramrod->filter_action = p_params->b_is_add ? GFT_ADD_FILTER
2081             : GFT_DELETE_FILTER;
2082
2083         DP_VERBOSE(p_hwfn, QED_MSG_SP,
2084                    "V[%0x], Q[%04x] - %s filter from 0x%llx [length %04xb]\n",
2085                    abs_vport_id, abs_rx_q_id,
2086                    p_params->b_is_add ? "Adding" : "Removing",
2087                    (u64)p_params->addr, p_params->length);
2088
2089         return qed_spq_post(p_hwfn, p_ent, NULL);
2090
2091 err:
2092         qed_sp_destroy_request(p_hwfn, p_ent);
2093         return rc;
2094 }
2095
2096 int qed_get_rxq_coalesce(struct qed_hwfn *p_hwfn,
2097                          struct qed_ptt *p_ptt,
2098                          struct qed_queue_cid *p_cid, u16 *p_rx_coal)
2099 {
2100         u32 coalesce, address, is_valid;
2101         struct cau_sb_entry sb_entry;
2102         u8 timer_res;
2103         int rc;
2104
2105         rc = qed_dmae_grc2host(p_hwfn, p_ptt, CAU_REG_SB_VAR_MEMORY +
2106                                p_cid->sb_igu_id * sizeof(u64),
2107                                (u64)(uintptr_t)&sb_entry, 2, 0);
2108         if (rc) {
2109                 DP_ERR(p_hwfn, "dmae_grc2host failed %d\n", rc);
2110                 return rc;
2111         }
2112
2113         timer_res = GET_FIELD(sb_entry.params, CAU_SB_ENTRY_TIMER_RES0);
2114
2115         address = BAR0_MAP_REG_USDM_RAM +
2116                   USTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
2117         coalesce = qed_rd(p_hwfn, p_ptt, address);
2118
2119         is_valid = GET_FIELD(coalesce, COALESCING_TIMESET_VALID);
2120         if (!is_valid)
2121                 return -EINVAL;
2122
2123         coalesce = GET_FIELD(coalesce, COALESCING_TIMESET_TIMESET);
2124         *p_rx_coal = (u16)(coalesce << timer_res);
2125
2126         return 0;
2127 }
2128
2129 int qed_get_txq_coalesce(struct qed_hwfn *p_hwfn,
2130                          struct qed_ptt *p_ptt,
2131                          struct qed_queue_cid *p_cid, u16 *p_tx_coal)
2132 {
2133         u32 coalesce, address, is_valid;
2134         struct cau_sb_entry sb_entry;
2135         u8 timer_res;
2136         int rc;
2137
2138         rc = qed_dmae_grc2host(p_hwfn, p_ptt, CAU_REG_SB_VAR_MEMORY +
2139                                p_cid->sb_igu_id * sizeof(u64),
2140                                (u64)(uintptr_t)&sb_entry, 2, 0);
2141         if (rc) {
2142                 DP_ERR(p_hwfn, "dmae_grc2host failed %d\n", rc);
2143                 return rc;
2144         }
2145
2146         timer_res = GET_FIELD(sb_entry.params, CAU_SB_ENTRY_TIMER_RES1);
2147
2148         address = BAR0_MAP_REG_XSDM_RAM +
2149                   XSTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
2150         coalesce = qed_rd(p_hwfn, p_ptt, address);
2151
2152         is_valid = GET_FIELD(coalesce, COALESCING_TIMESET_VALID);
2153         if (!is_valid)
2154                 return -EINVAL;
2155
2156         coalesce = GET_FIELD(coalesce, COALESCING_TIMESET_TIMESET);
2157         *p_tx_coal = (u16)(coalesce << timer_res);
2158
2159         return 0;
2160 }
2161
2162 int qed_get_queue_coalesce(struct qed_hwfn *p_hwfn, u16 *p_coal, void *handle)
2163 {
2164         struct qed_queue_cid *p_cid = handle;
2165         struct qed_ptt *p_ptt;
2166         int rc = 0;
2167
2168         if (IS_VF(p_hwfn->cdev)) {
2169                 rc = qed_vf_pf_get_coalesce(p_hwfn, p_coal, p_cid);
2170                 if (rc)
2171                         DP_NOTICE(p_hwfn, "Unable to read queue coalescing\n");
2172
2173                 return rc;
2174         }
2175
2176         p_ptt = qed_ptt_acquire(p_hwfn);
2177         if (!p_ptt)
2178                 return -EAGAIN;
2179
2180         if (p_cid->b_is_rx) {
2181                 rc = qed_get_rxq_coalesce(p_hwfn, p_ptt, p_cid, p_coal);
2182                 if (rc)
2183                         goto out;
2184         } else {
2185                 rc = qed_get_txq_coalesce(p_hwfn, p_ptt, p_cid, p_coal);
2186                 if (rc)
2187                         goto out;
2188         }
2189
2190 out:
2191         qed_ptt_release(p_hwfn, p_ptt);
2192
2193         return rc;
2194 }
2195
2196 static int qed_fill_eth_dev_info(struct qed_dev *cdev,
2197                                  struct qed_dev_eth_info *info)
2198 {
2199         struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
2200         int i;
2201
2202         memset(info, 0, sizeof(*info));
2203
2204         if (IS_PF(cdev)) {
2205                 int max_vf_vlan_filters = 0;
2206                 int max_vf_mac_filters = 0;
2207
2208                 info->num_tc = p_hwfn->hw_info.num_hw_tc;
2209
2210                 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
2211                         u16 num_queues = 0;
2212
2213                         /* Since the feature controls only queue-zones,
2214                          * make sure we have the contexts [rx, tx, xdp] to
2215                          * match.
2216                          */
2217                         for_each_hwfn(cdev, i) {
2218                                 struct qed_hwfn *hwfn = &cdev->hwfns[i];
2219                                 u16 l2_queues = (u16)FEAT_NUM(hwfn,
2220                                                               QED_PF_L2_QUE);
2221                                 u16 cids;
2222
2223                                 cids = hwfn->pf_params.eth_pf_params.num_cons;
2224                                 num_queues += min_t(u16, l2_queues, cids / 3);
2225                         }
2226
2227                         /* queues might theoretically be >256, but interrupts'
2228                          * upper-limit guarantes that it would fit in a u8.
2229                          */
2230                         if (cdev->int_params.fp_msix_cnt) {
2231                                 u8 irqs = cdev->int_params.fp_msix_cnt;
2232
2233                                 info->num_queues = (u8)min_t(u16,
2234                                                              num_queues, irqs);
2235                         }
2236                 } else {
2237                         info->num_queues = cdev->num_hwfns;
2238                 }
2239
2240                 if (IS_QED_SRIOV(cdev)) {
2241                         max_vf_vlan_filters = cdev->p_iov_info->total_vfs *
2242                                               QED_ETH_VF_NUM_VLAN_FILTERS;
2243                         max_vf_mac_filters = cdev->p_iov_info->total_vfs *
2244                                              QED_ETH_VF_NUM_MAC_FILTERS;
2245                 }
2246                 info->num_vlan_filters = RESC_NUM(QED_LEADING_HWFN(cdev),
2247                                                   QED_VLAN) -
2248                                          max_vf_vlan_filters;
2249                 info->num_mac_filters = RESC_NUM(QED_LEADING_HWFN(cdev),
2250                                                  QED_MAC) -
2251                                         max_vf_mac_filters;
2252
2253                 ether_addr_copy(info->port_mac,
2254                                 cdev->hwfns[0].hw_info.hw_mac_addr);
2255
2256                 info->xdp_supported = true;
2257         } else {
2258                 u16 total_cids = 0;
2259
2260                 info->num_tc = 1;
2261
2262                 /* Determine queues &  XDP support */
2263                 for_each_hwfn(cdev, i) {
2264                         struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2265                         u8 queues, cids;
2266
2267                         qed_vf_get_num_cids(p_hwfn, &cids);
2268                         qed_vf_get_num_rxqs(p_hwfn, &queues);
2269                         info->num_queues += queues;
2270                         total_cids += cids;
2271                 }
2272
2273                 /* Enable VF XDP in case PF guarntees sufficient connections */
2274                 if (total_cids >= info->num_queues * 3)
2275                         info->xdp_supported = true;
2276
2277                 qed_vf_get_num_vlan_filters(&cdev->hwfns[0],
2278                                             (u8 *)&info->num_vlan_filters);
2279                 qed_vf_get_num_mac_filters(&cdev->hwfns[0],
2280                                            (u8 *)&info->num_mac_filters);
2281                 qed_vf_get_port_mac(&cdev->hwfns[0], info->port_mac);
2282
2283                 info->is_legacy = !!cdev->hwfns[0].vf_iov_info->b_pre_fp_hsi;
2284         }
2285
2286         qed_fill_dev_info(cdev, &info->common);
2287
2288         if (IS_VF(cdev))
2289                 eth_zero_addr(info->common.hw_mac);
2290
2291         return 0;
2292 }
2293
2294 static void qed_register_eth_ops(struct qed_dev *cdev,
2295                                  struct qed_eth_cb_ops *ops, void *cookie)
2296 {
2297         cdev->protocol_ops.eth = ops;
2298         cdev->ops_cookie = cookie;
2299
2300         /* For VF, we start bulletin reading */
2301         if (IS_VF(cdev))
2302                 qed_vf_start_iov_wq(cdev);
2303 }
2304
2305 static bool qed_check_mac(struct qed_dev *cdev, u8 *mac)
2306 {
2307         if (IS_PF(cdev))
2308                 return true;
2309
2310         return qed_vf_check_mac(&cdev->hwfns[0], mac);
2311 }
2312
2313 static int qed_start_vport(struct qed_dev *cdev,
2314                            struct qed_start_vport_params *params)
2315 {
2316         int rc, i;
2317
2318         for_each_hwfn(cdev, i) {
2319                 struct qed_sp_vport_start_params start = { 0 };
2320                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2321
2322                 start.tpa_mode = params->gro_enable ? QED_TPA_MODE_GRO :
2323                                                         QED_TPA_MODE_NONE;
2324                 start.remove_inner_vlan = params->remove_inner_vlan;
2325                 start.only_untagged = true;     /* untagged only */
2326                 start.drop_ttl0 = params->drop_ttl0;
2327                 start.opaque_fid = p_hwfn->hw_info.opaque_fid;
2328                 start.concrete_fid = p_hwfn->hw_info.concrete_fid;
2329                 start.handle_ptp_pkts = params->handle_ptp_pkts;
2330                 start.vport_id = params->vport_id;
2331                 start.max_buffers_per_cqe = 16;
2332                 start.mtu = params->mtu;
2333
2334                 rc = qed_sp_vport_start(p_hwfn, &start);
2335                 if (rc) {
2336                         DP_ERR(cdev, "Failed to start VPORT\n");
2337                         return rc;
2338                 }
2339
2340                 rc = qed_hw_start_fastpath(p_hwfn);
2341                 if (rc) {
2342                         DP_ERR(cdev, "Failed to start VPORT fastpath\n");
2343                         return rc;
2344                 }
2345
2346                 DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
2347                            "Started V-PORT %d with MTU %d\n",
2348                            start.vport_id, start.mtu);
2349         }
2350
2351         if (params->clear_stats)
2352                 qed_reset_vport_stats(cdev);
2353
2354         return 0;
2355 }
2356
2357 static int qed_stop_vport(struct qed_dev *cdev, u8 vport_id)
2358 {
2359         int rc, i;
2360
2361         for_each_hwfn(cdev, i) {
2362                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2363
2364                 rc = qed_sp_vport_stop(p_hwfn,
2365                                        p_hwfn->hw_info.opaque_fid, vport_id);
2366
2367                 if (rc) {
2368                         DP_ERR(cdev, "Failed to stop VPORT\n");
2369                         return rc;
2370                 }
2371         }
2372         return 0;
2373 }
2374
2375 static int qed_update_vport_rss(struct qed_dev *cdev,
2376                                 struct qed_update_vport_rss_params *input,
2377                                 struct qed_rss_params *rss)
2378 {
2379         int i, fn;
2380
2381         /* Update configuration with what's correct regardless of CMT */
2382         rss->update_rss_config = 1;
2383         rss->rss_enable = 1;
2384         rss->update_rss_capabilities = 1;
2385         rss->update_rss_ind_table = 1;
2386         rss->update_rss_key = 1;
2387         rss->rss_caps = input->rss_caps;
2388         memcpy(rss->rss_key, input->rss_key, QED_RSS_KEY_SIZE * sizeof(u32));
2389
2390         /* In regular scenario, we'd simply need to take input handlers.
2391          * But in CMT, we'd have to split the handlers according to the
2392          * engine they were configured on. We'd then have to understand
2393          * whether RSS is really required, since 2-queues on CMT doesn't
2394          * require RSS.
2395          */
2396         if (cdev->num_hwfns == 1) {
2397                 memcpy(rss->rss_ind_table,
2398                        input->rss_ind_table,
2399                        QED_RSS_IND_TABLE_SIZE * sizeof(void *));
2400                 rss->rss_table_size_log = 7;
2401                 return 0;
2402         }
2403
2404         /* Start by copying the non-spcific information to the 2nd copy */
2405         memcpy(&rss[1], &rss[0], sizeof(struct qed_rss_params));
2406
2407         /* CMT should be round-robin */
2408         for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
2409                 struct qed_queue_cid *cid = input->rss_ind_table[i];
2410                 struct qed_rss_params *t_rss;
2411
2412                 if (cid->p_owner == QED_LEADING_HWFN(cdev))
2413                         t_rss = &rss[0];
2414                 else
2415                         t_rss = &rss[1];
2416
2417                 t_rss->rss_ind_table[i / cdev->num_hwfns] = cid;
2418         }
2419
2420         /* Make sure RSS is actually required */
2421         for_each_hwfn(cdev, fn) {
2422                 for (i = 1; i < QED_RSS_IND_TABLE_SIZE / cdev->num_hwfns; i++) {
2423                         if (rss[fn].rss_ind_table[i] !=
2424                             rss[fn].rss_ind_table[0])
2425                                 break;
2426                 }
2427                 if (i == QED_RSS_IND_TABLE_SIZE / cdev->num_hwfns) {
2428                         DP_VERBOSE(cdev, NETIF_MSG_IFUP,
2429                                    "CMT - 1 queue per-hwfn; Disabling RSS\n");
2430                         return -EINVAL;
2431                 }
2432                 rss[fn].rss_table_size_log = 6;
2433         }
2434
2435         return 0;
2436 }
2437
2438 static int qed_update_vport(struct qed_dev *cdev,
2439                             struct qed_update_vport_params *params)
2440 {
2441         struct qed_sp_vport_update_params sp_params;
2442         struct qed_rss_params *rss;
2443         int rc = 0, i;
2444
2445         if (!cdev)
2446                 return -ENODEV;
2447
2448         rss = vzalloc(array_size(sizeof(*rss), cdev->num_hwfns));
2449         if (!rss)
2450                 return -ENOMEM;
2451
2452         memset(&sp_params, 0, sizeof(sp_params));
2453
2454         /* Translate protocol params into sp params */
2455         sp_params.vport_id = params->vport_id;
2456         sp_params.update_vport_active_rx_flg = params->update_vport_active_flg;
2457         sp_params.update_vport_active_tx_flg = params->update_vport_active_flg;
2458         sp_params.vport_active_rx_flg = params->vport_active_flg;
2459         sp_params.vport_active_tx_flg = params->vport_active_flg;
2460         sp_params.update_tx_switching_flg = params->update_tx_switching_flg;
2461         sp_params.tx_switching_flg = params->tx_switching_flg;
2462         sp_params.accept_any_vlan = params->accept_any_vlan;
2463         sp_params.update_accept_any_vlan_flg =
2464                 params->update_accept_any_vlan_flg;
2465
2466         /* Prepare the RSS configuration */
2467         if (params->update_rss_flg)
2468                 if (qed_update_vport_rss(cdev, &params->rss_params, rss))
2469                         params->update_rss_flg = 0;
2470
2471         for_each_hwfn(cdev, i) {
2472                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2473
2474                 if (params->update_rss_flg)
2475                         sp_params.rss_params = &rss[i];
2476
2477                 sp_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
2478                 rc = qed_sp_vport_update(p_hwfn, &sp_params,
2479                                          QED_SPQ_MODE_EBLOCK,
2480                                          NULL);
2481                 if (rc) {
2482                         DP_ERR(cdev, "Failed to update VPORT\n");
2483                         goto out;
2484                 }
2485
2486                 DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
2487                            "Updated V-PORT %d: active_flag %d [update %d]\n",
2488                            params->vport_id, params->vport_active_flg,
2489                            params->update_vport_active_flg);
2490         }
2491
2492 out:
2493         vfree(rss);
2494         return rc;
2495 }
2496
2497 static int qed_start_rxq(struct qed_dev *cdev,
2498                          u8 rss_num,
2499                          struct qed_queue_start_common_params *p_params,
2500                          u16 bd_max_bytes,
2501                          dma_addr_t bd_chain_phys_addr,
2502                          dma_addr_t cqe_pbl_addr,
2503                          u16 cqe_pbl_size,
2504                          struct qed_rxq_start_ret_params *ret_params)
2505 {
2506         struct qed_hwfn *p_hwfn;
2507         int rc, hwfn_index;
2508
2509         hwfn_index = rss_num % cdev->num_hwfns;
2510         p_hwfn = &cdev->hwfns[hwfn_index];
2511
2512         p_params->queue_id = p_params->queue_id / cdev->num_hwfns;
2513         p_params->stats_id = p_params->vport_id;
2514
2515         rc = qed_eth_rx_queue_start(p_hwfn,
2516                                     p_hwfn->hw_info.opaque_fid,
2517                                     p_params,
2518                                     bd_max_bytes,
2519                                     bd_chain_phys_addr,
2520                                     cqe_pbl_addr, cqe_pbl_size, ret_params);
2521         if (rc) {
2522                 DP_ERR(cdev, "Failed to start RXQ#%d\n", p_params->queue_id);
2523                 return rc;
2524         }
2525
2526         DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
2527                    "Started RX-Q %d [rss_num %d] on V-PORT %d and SB igu %d\n",
2528                    p_params->queue_id, rss_num, p_params->vport_id,
2529                    p_params->p_sb->igu_sb_id);
2530
2531         return 0;
2532 }
2533
2534 static int qed_stop_rxq(struct qed_dev *cdev, u8 rss_id, void *handle)
2535 {
2536         int rc, hwfn_index;
2537         struct qed_hwfn *p_hwfn;
2538
2539         hwfn_index = rss_id % cdev->num_hwfns;
2540         p_hwfn = &cdev->hwfns[hwfn_index];
2541
2542         rc = qed_eth_rx_queue_stop(p_hwfn, handle, false, false);
2543         if (rc) {
2544                 DP_ERR(cdev, "Failed to stop RXQ#%02x\n", rss_id);
2545                 return rc;
2546         }
2547
2548         return 0;
2549 }
2550
2551 static int qed_start_txq(struct qed_dev *cdev,
2552                          u8 rss_num,
2553                          struct qed_queue_start_common_params *p_params,
2554                          dma_addr_t pbl_addr,
2555                          u16 pbl_size,
2556                          struct qed_txq_start_ret_params *ret_params)
2557 {
2558         struct qed_hwfn *p_hwfn;
2559         int rc, hwfn_index;
2560
2561         hwfn_index = rss_num % cdev->num_hwfns;
2562         p_hwfn = &cdev->hwfns[hwfn_index];
2563         p_params->queue_id = p_params->queue_id / cdev->num_hwfns;
2564         p_params->stats_id = p_params->vport_id;
2565
2566         rc = qed_eth_tx_queue_start(p_hwfn,
2567                                     p_hwfn->hw_info.opaque_fid,
2568                                     p_params, p_params->tc,
2569                                     pbl_addr, pbl_size, ret_params);
2570
2571         if (rc) {
2572                 DP_ERR(cdev, "Failed to start TXQ#%d\n", p_params->queue_id);
2573                 return rc;
2574         }
2575
2576         DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
2577                    "Started TX-Q %d [rss_num %d] on V-PORT %d and SB igu %d\n",
2578                    p_params->queue_id, rss_num, p_params->vport_id,
2579                    p_params->p_sb->igu_sb_id);
2580
2581         return 0;
2582 }
2583
2584 #define QED_HW_STOP_RETRY_LIMIT (10)
2585 static int qed_fastpath_stop(struct qed_dev *cdev)
2586 {
2587         int rc;
2588
2589         rc = qed_hw_stop_fastpath(cdev);
2590         if (rc) {
2591                 DP_ERR(cdev, "Failed to stop Fastpath\n");
2592                 return rc;
2593         }
2594
2595         return 0;
2596 }
2597
2598 static int qed_stop_txq(struct qed_dev *cdev, u8 rss_id, void *handle)
2599 {
2600         struct qed_hwfn *p_hwfn;
2601         int rc, hwfn_index;
2602
2603         hwfn_index = rss_id % cdev->num_hwfns;
2604         p_hwfn = &cdev->hwfns[hwfn_index];
2605
2606         rc = qed_eth_tx_queue_stop(p_hwfn, handle);
2607         if (rc) {
2608                 DP_ERR(cdev, "Failed to stop TXQ#%02x\n", rss_id);
2609                 return rc;
2610         }
2611
2612         return 0;
2613 }
2614
2615 static int qed_tunn_configure(struct qed_dev *cdev,
2616                               struct qed_tunn_params *tunn_params)
2617 {
2618         struct qed_tunnel_info tunn_info;
2619         int i, rc;
2620
2621         memset(&tunn_info, 0, sizeof(tunn_info));
2622         if (tunn_params->update_vxlan_port) {
2623                 tunn_info.vxlan_port.b_update_port = true;
2624                 tunn_info.vxlan_port.port = tunn_params->vxlan_port;
2625         }
2626
2627         if (tunn_params->update_geneve_port) {
2628                 tunn_info.geneve_port.b_update_port = true;
2629                 tunn_info.geneve_port.port = tunn_params->geneve_port;
2630         }
2631
2632         for_each_hwfn(cdev, i) {
2633                 struct qed_hwfn *hwfn = &cdev->hwfns[i];
2634                 struct qed_ptt *p_ptt;
2635                 struct qed_tunnel_info *tun;
2636
2637                 tun = &hwfn->cdev->tunnel;
2638                 if (IS_PF(cdev)) {
2639                         p_ptt = qed_ptt_acquire(hwfn);
2640                         if (!p_ptt)
2641                                 return -EAGAIN;
2642                 } else {
2643                         p_ptt = NULL;
2644                 }
2645
2646                 rc = qed_sp_pf_update_tunn_cfg(hwfn, p_ptt, &tunn_info,
2647                                                QED_SPQ_MODE_EBLOCK, NULL);
2648                 if (rc) {
2649                         if (IS_PF(cdev))
2650                                 qed_ptt_release(hwfn, p_ptt);
2651                         return rc;
2652                 }
2653
2654                 if (IS_PF_SRIOV(hwfn)) {
2655                         u16 vxlan_port, geneve_port;
2656                         int j;
2657
2658                         vxlan_port = tun->vxlan_port.port;
2659                         geneve_port = tun->geneve_port.port;
2660
2661                         qed_for_each_vf(hwfn, j) {
2662                                 qed_iov_bulletin_set_udp_ports(hwfn, j,
2663                                                                vxlan_port,
2664                                                                geneve_port);
2665                         }
2666
2667                         qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
2668                 }
2669                 if (IS_PF(cdev))
2670                         qed_ptt_release(hwfn, p_ptt);
2671         }
2672
2673         return 0;
2674 }
2675
2676 static int qed_configure_filter_rx_mode(struct qed_dev *cdev,
2677                                         enum qed_filter_rx_mode_type type)
2678 {
2679         struct qed_filter_accept_flags accept_flags;
2680
2681         memset(&accept_flags, 0, sizeof(accept_flags));
2682
2683         accept_flags.update_rx_mode_config = 1;
2684         accept_flags.update_tx_mode_config = 1;
2685         accept_flags.rx_accept_filter = QED_ACCEPT_UCAST_MATCHED |
2686                                         QED_ACCEPT_MCAST_MATCHED |
2687                                         QED_ACCEPT_BCAST;
2688         accept_flags.tx_accept_filter = QED_ACCEPT_UCAST_MATCHED |
2689                                         QED_ACCEPT_MCAST_MATCHED |
2690                                         QED_ACCEPT_BCAST;
2691
2692         if (type == QED_FILTER_RX_MODE_TYPE_PROMISC) {
2693                 accept_flags.rx_accept_filter |= QED_ACCEPT_UCAST_UNMATCHED |
2694                                                  QED_ACCEPT_MCAST_UNMATCHED;
2695                 accept_flags.tx_accept_filter |= QED_ACCEPT_UCAST_UNMATCHED |
2696                                                  QED_ACCEPT_MCAST_UNMATCHED;
2697         } else if (type == QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC) {
2698                 accept_flags.rx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
2699                 accept_flags.tx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
2700         }
2701
2702         return qed_filter_accept_cmd(cdev, 0, accept_flags, false, false,
2703                                      QED_SPQ_MODE_CB, NULL);
2704 }
2705
2706 static int qed_configure_filter_ucast(struct qed_dev *cdev,
2707                                       struct qed_filter_ucast_params *params)
2708 {
2709         struct qed_filter_ucast ucast;
2710
2711         if (!params->vlan_valid && !params->mac_valid) {
2712                 DP_NOTICE(cdev,
2713                           "Tried configuring a unicast filter, but both MAC and VLAN are not set\n");
2714                 return -EINVAL;
2715         }
2716
2717         memset(&ucast, 0, sizeof(ucast));
2718         switch (params->type) {
2719         case QED_FILTER_XCAST_TYPE_ADD:
2720                 ucast.opcode = QED_FILTER_ADD;
2721                 break;
2722         case QED_FILTER_XCAST_TYPE_DEL:
2723                 ucast.opcode = QED_FILTER_REMOVE;
2724                 break;
2725         case QED_FILTER_XCAST_TYPE_REPLACE:
2726                 ucast.opcode = QED_FILTER_REPLACE;
2727                 break;
2728         default:
2729                 DP_NOTICE(cdev, "Unknown unicast filter type %d\n",
2730                           params->type);
2731         }
2732
2733         if (params->vlan_valid && params->mac_valid) {
2734                 ucast.type = QED_FILTER_MAC_VLAN;
2735                 ether_addr_copy(ucast.mac, params->mac);
2736                 ucast.vlan = params->vlan;
2737         } else if (params->mac_valid) {
2738                 ucast.type = QED_FILTER_MAC;
2739                 ether_addr_copy(ucast.mac, params->mac);
2740         } else {
2741                 ucast.type = QED_FILTER_VLAN;
2742                 ucast.vlan = params->vlan;
2743         }
2744
2745         ucast.is_rx_filter = true;
2746         ucast.is_tx_filter = true;
2747
2748         return qed_filter_ucast_cmd(cdev, &ucast, QED_SPQ_MODE_CB, NULL);
2749 }
2750
2751 static int qed_configure_filter_mcast(struct qed_dev *cdev,
2752                                       struct qed_filter_mcast_params *params)
2753 {
2754         struct qed_filter_mcast mcast;
2755         int i;
2756
2757         memset(&mcast, 0, sizeof(mcast));
2758         switch (params->type) {
2759         case QED_FILTER_XCAST_TYPE_ADD:
2760                 mcast.opcode = QED_FILTER_ADD;
2761                 break;
2762         case QED_FILTER_XCAST_TYPE_DEL:
2763                 mcast.opcode = QED_FILTER_REMOVE;
2764                 break;
2765         default:
2766                 DP_NOTICE(cdev, "Unknown multicast filter type %d\n",
2767                           params->type);
2768         }
2769
2770         mcast.num_mc_addrs = params->num;
2771         for (i = 0; i < mcast.num_mc_addrs; i++)
2772                 ether_addr_copy(mcast.mac[i], params->mac[i]);
2773
2774         return qed_filter_mcast_cmd(cdev, &mcast, QED_SPQ_MODE_CB, NULL);
2775 }
2776
2777 static int qed_configure_filter(struct qed_dev *cdev,
2778                                 struct qed_filter_params *params)
2779 {
2780         enum qed_filter_rx_mode_type accept_flags;
2781
2782         switch (params->type) {
2783         case QED_FILTER_TYPE_UCAST:
2784                 return qed_configure_filter_ucast(cdev, &params->filter.ucast);
2785         case QED_FILTER_TYPE_MCAST:
2786                 return qed_configure_filter_mcast(cdev, &params->filter.mcast);
2787         case QED_FILTER_TYPE_RX_MODE:
2788                 accept_flags = params->filter.accept_flags;
2789                 return qed_configure_filter_rx_mode(cdev, accept_flags);
2790         default:
2791                 DP_NOTICE(cdev, "Unknown filter type %d\n", (int)params->type);
2792                 return -EINVAL;
2793         }
2794 }
2795
2796 static int qed_configure_arfs_searcher(struct qed_dev *cdev,
2797                                        enum qed_filter_config_mode mode)
2798 {
2799         struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
2800         struct qed_arfs_config_params arfs_config_params;
2801
2802         memset(&arfs_config_params, 0, sizeof(arfs_config_params));
2803         arfs_config_params.tcp = true;
2804         arfs_config_params.udp = true;
2805         arfs_config_params.ipv4 = true;
2806         arfs_config_params.ipv6 = true;
2807         arfs_config_params.mode = mode;
2808         qed_arfs_mode_configure(p_hwfn, p_hwfn->p_arfs_ptt,
2809                                 &arfs_config_params);
2810         return 0;
2811 }
2812
2813 static void
2814 qed_arfs_sp_response_handler(struct qed_hwfn *p_hwfn,
2815                              void *cookie,
2816                              union event_ring_data *data, u8 fw_return_code)
2817 {
2818         struct qed_common_cb_ops *op = p_hwfn->cdev->protocol_ops.common;
2819         void *dev = p_hwfn->cdev->ops_cookie;
2820
2821         op->arfs_filter_op(dev, cookie, fw_return_code);
2822 }
2823
2824 static int
2825 qed_ntuple_arfs_filter_config(struct qed_dev *cdev,
2826                               void *cookie,
2827                               struct qed_ntuple_filter_params *params)
2828 {
2829         struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
2830         struct qed_spq_comp_cb cb;
2831         int rc = -EINVAL;
2832
2833         cb.function = qed_arfs_sp_response_handler;
2834         cb.cookie = cookie;
2835
2836         if (params->b_is_vf) {
2837                 if (!qed_iov_is_valid_vfid(p_hwfn, params->vf_id, false,
2838                                            false)) {
2839                         DP_INFO(p_hwfn, "vfid 0x%02x is out of bounds\n",
2840                                 params->vf_id);
2841                         return rc;
2842                 }
2843
2844                 params->vport_id = params->vf_id + 1;
2845                 params->qid = QED_RFS_NTUPLE_QID_RSS;
2846         }
2847
2848         rc = qed_configure_rfs_ntuple_filter(p_hwfn, &cb, params);
2849         if (rc)
2850                 DP_NOTICE(p_hwfn,
2851                           "Failed to issue a-RFS filter configuration\n");
2852         else
2853                 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV,
2854                            "Successfully issued a-RFS filter configuration\n");
2855
2856         return rc;
2857 }
2858
2859 static int qed_get_coalesce(struct qed_dev *cdev, u16 *coal, void *handle)
2860 {
2861         struct qed_queue_cid *p_cid = handle;
2862         struct qed_hwfn *p_hwfn;
2863         int rc;
2864
2865         p_hwfn = p_cid->p_owner;
2866         rc = qed_get_queue_coalesce(p_hwfn, coal, handle);
2867         if (rc)
2868                 DP_NOTICE(p_hwfn, "Unable to read queue coalescing\n");
2869
2870         return rc;
2871 }
2872
2873 static int qed_fp_cqe_completion(struct qed_dev *dev,
2874                                  u8 rss_id, struct eth_slow_path_rx_cqe *cqe)
2875 {
2876         return qed_eth_cqe_completion(&dev->hwfns[rss_id % dev->num_hwfns],
2877                                       cqe);
2878 }
2879
2880 static int qed_req_bulletin_update_mac(struct qed_dev *cdev, u8 *mac)
2881 {
2882         int i, ret;
2883
2884         if (IS_PF(cdev))
2885                 return 0;
2886
2887         for_each_hwfn(cdev, i) {
2888                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2889
2890                 ret = qed_vf_pf_bulletin_update_mac(p_hwfn, mac);
2891                 if (ret)
2892                         return ret;
2893         }
2894
2895         return 0;
2896 }
2897
2898 #ifdef CONFIG_QED_SRIOV
2899 extern const struct qed_iov_hv_ops qed_iov_ops_pass;
2900 #endif
2901
2902 #ifdef CONFIG_DCB
2903 extern const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass;
2904 #endif
2905
2906 extern const struct qed_eth_ptp_ops qed_ptp_ops_pass;
2907
2908 static const struct qed_eth_ops qed_eth_ops_pass = {
2909         .common = &qed_common_ops_pass,
2910 #ifdef CONFIG_QED_SRIOV
2911         .iov = &qed_iov_ops_pass,
2912 #endif
2913 #ifdef CONFIG_DCB
2914         .dcb = &qed_dcbnl_ops_pass,
2915 #endif
2916         .ptp = &qed_ptp_ops_pass,
2917         .fill_dev_info = &qed_fill_eth_dev_info,
2918         .register_ops = &qed_register_eth_ops,
2919         .check_mac = &qed_check_mac,
2920         .vport_start = &qed_start_vport,
2921         .vport_stop = &qed_stop_vport,
2922         .vport_update = &qed_update_vport,
2923         .q_rx_start = &qed_start_rxq,
2924         .q_rx_stop = &qed_stop_rxq,
2925         .q_tx_start = &qed_start_txq,
2926         .q_tx_stop = &qed_stop_txq,
2927         .filter_config = &qed_configure_filter,
2928         .fastpath_stop = &qed_fastpath_stop,
2929         .eth_cqe_completion = &qed_fp_cqe_completion,
2930         .get_vport_stats = &qed_get_vport_stats,
2931         .tunn_config = &qed_tunn_configure,
2932         .ntuple_filter_config = &qed_ntuple_arfs_filter_config,
2933         .configure_arfs_searcher = &qed_configure_arfs_searcher,
2934         .get_coalesce = &qed_get_coalesce,
2935         .req_bulletin_update_mac = &qed_req_bulletin_update_mac,
2936 };
2937
2938 const struct qed_eth_ops *qed_get_eth_ops(void)
2939 {
2940         return &qed_eth_ops_pass;
2941 }
2942 EXPORT_SYMBOL(qed_get_eth_ops);
2943
2944 void qed_put_eth_ops(void)
2945 {
2946         /* TODO - reference count for module? */
2947 }
2948 EXPORT_SYMBOL(qed_put_eth_ops);