GNU Linux-libre 4.9.284-gnu1
[releases.git] / drivers / net / ethernet / qlogic / qed / qed_l2.c
1 /* QLogic qed NIC Driver
2  * Copyright (c) 2015 QLogic Corporation
3  *
4  * This software is available under the terms of the GNU General Public License
5  * (GPL) Version 2, available from the file COPYING in the main directory of
6  * this source tree.
7  */
8
9 #include <linux/types.h>
10 #include <asm/byteorder.h>
11 #include <asm/param.h>
12 #include <linux/delay.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/etherdevice.h>
15 #include <linux/interrupt.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/pci.h>
19 #include <linux/slab.h>
20 #include <linux/stddef.h>
21 #include <linux/string.h>
22 #include <linux/version.h>
23 #include <linux/workqueue.h>
24 #include <linux/bitops.h>
25 #include <linux/bug.h>
26 #include "qed.h"
27 #include <linux/qed/qed_chain.h>
28 #include "qed_cxt.h"
29 #include "qed_dev_api.h"
30 #include <linux/qed/qed_eth_if.h>
31 #include "qed_hsi.h"
32 #include "qed_hw.h"
33 #include "qed_int.h"
34 #include "qed_l2.h"
35 #include "qed_mcp.h"
36 #include "qed_reg_addr.h"
37 #include "qed_sp.h"
38 #include "qed_sriov.h"
39
40
41 #define QED_MAX_SGES_NUM 16
42 #define CRC32_POLY 0x1edc6f41
43
44 int qed_sp_eth_vport_start(struct qed_hwfn *p_hwfn,
45                            struct qed_sp_vport_start_params *p_params)
46 {
47         struct vport_start_ramrod_data *p_ramrod = NULL;
48         struct qed_spq_entry *p_ent =  NULL;
49         struct qed_sp_init_data init_data;
50         u8 abs_vport_id = 0;
51         int rc = -EINVAL;
52         u16 rx_mode = 0;
53
54         rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
55         if (rc)
56                 return rc;
57
58         memset(&init_data, 0, sizeof(init_data));
59         init_data.cid = qed_spq_get_cid(p_hwfn);
60         init_data.opaque_fid = p_params->opaque_fid;
61         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
62
63         rc = qed_sp_init_request(p_hwfn, &p_ent,
64                                  ETH_RAMROD_VPORT_START,
65                                  PROTOCOLID_ETH, &init_data);
66         if (rc)
67                 return rc;
68
69         p_ramrod                = &p_ent->ramrod.vport_start;
70         p_ramrod->vport_id      = abs_vport_id;
71
72         p_ramrod->mtu                   = cpu_to_le16(p_params->mtu);
73         p_ramrod->inner_vlan_removal_en = p_params->remove_inner_vlan;
74         p_ramrod->drop_ttl0_en          = p_params->drop_ttl0;
75         p_ramrod->untagged              = p_params->only_untagged;
76
77         SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_UCAST_DROP_ALL, 1);
78         SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_MCAST_DROP_ALL, 1);
79
80         p_ramrod->rx_mode.state = cpu_to_le16(rx_mode);
81
82         /* TPA related fields */
83         memset(&p_ramrod->tpa_param, 0, sizeof(struct eth_vport_tpa_param));
84
85         p_ramrod->tpa_param.max_buff_num = p_params->max_buffers_per_cqe;
86
87         switch (p_params->tpa_mode) {
88         case QED_TPA_MODE_GRO:
89                 p_ramrod->tpa_param.tpa_max_aggs_num = ETH_TPA_MAX_AGGS_NUM;
90                 p_ramrod->tpa_param.tpa_max_size = (u16)-1;
91                 p_ramrod->tpa_param.tpa_min_size_to_cont = p_params->mtu / 2;
92                 p_ramrod->tpa_param.tpa_min_size_to_start = p_params->mtu / 2;
93                 p_ramrod->tpa_param.tpa_ipv4_en_flg = 1;
94                 p_ramrod->tpa_param.tpa_ipv6_en_flg = 1;
95                 p_ramrod->tpa_param.tpa_pkt_split_flg = 1;
96                 p_ramrod->tpa_param.tpa_gro_consistent_flg = 1;
97                 break;
98         default:
99                 break;
100         }
101
102         p_ramrod->tx_switching_en = p_params->tx_switching;
103
104         p_ramrod->ctl_frame_mac_check_en = !!p_params->check_mac;
105         p_ramrod->ctl_frame_ethtype_check_en = !!p_params->check_ethtype;
106
107         /* Software Function ID in hwfn (PFs are 0 - 15, VFs are 16 - 135) */
108         p_ramrod->sw_fid = qed_concrete_to_sw_fid(p_hwfn->cdev,
109                                                   p_params->concrete_fid);
110
111         return qed_spq_post(p_hwfn, p_ent, NULL);
112 }
113
114 static int qed_sp_vport_start(struct qed_hwfn *p_hwfn,
115                               struct qed_sp_vport_start_params *p_params)
116 {
117         if (IS_VF(p_hwfn->cdev)) {
118                 return qed_vf_pf_vport_start(p_hwfn, p_params->vport_id,
119                                              p_params->mtu,
120                                              p_params->remove_inner_vlan,
121                                              p_params->tpa_mode,
122                                              p_params->max_buffers_per_cqe,
123                                              p_params->only_untagged);
124         }
125
126         return qed_sp_eth_vport_start(p_hwfn, p_params);
127 }
128
129 static int
130 qed_sp_vport_update_rss(struct qed_hwfn *p_hwfn,
131                         struct vport_update_ramrod_data *p_ramrod,
132                         struct qed_rss_params *p_params)
133 {
134         struct eth_vport_rss_config *rss = &p_ramrod->rss_config;
135         u16 abs_l2_queue = 0, capabilities = 0;
136         int rc = 0, i;
137
138         if (!p_params) {
139                 p_ramrod->common.update_rss_flg = 0;
140                 return rc;
141         }
142
143         BUILD_BUG_ON(QED_RSS_IND_TABLE_SIZE !=
144                      ETH_RSS_IND_TABLE_ENTRIES_NUM);
145
146         rc = qed_fw_rss_eng(p_hwfn, p_params->rss_eng_id, &rss->rss_id);
147         if (rc)
148                 return rc;
149
150         p_ramrod->common.update_rss_flg = p_params->update_rss_config;
151         rss->update_rss_capabilities = p_params->update_rss_capabilities;
152         rss->update_rss_ind_table = p_params->update_rss_ind_table;
153         rss->update_rss_key = p_params->update_rss_key;
154
155         rss->rss_mode = p_params->rss_enable ?
156                         ETH_VPORT_RSS_MODE_REGULAR :
157                         ETH_VPORT_RSS_MODE_DISABLED;
158
159         SET_FIELD(capabilities,
160                   ETH_VPORT_RSS_CONFIG_IPV4_CAPABILITY,
161                   !!(p_params->rss_caps & QED_RSS_IPV4));
162         SET_FIELD(capabilities,
163                   ETH_VPORT_RSS_CONFIG_IPV6_CAPABILITY,
164                   !!(p_params->rss_caps & QED_RSS_IPV6));
165         SET_FIELD(capabilities,
166                   ETH_VPORT_RSS_CONFIG_IPV4_TCP_CAPABILITY,
167                   !!(p_params->rss_caps & QED_RSS_IPV4_TCP));
168         SET_FIELD(capabilities,
169                   ETH_VPORT_RSS_CONFIG_IPV6_TCP_CAPABILITY,
170                   !!(p_params->rss_caps & QED_RSS_IPV6_TCP));
171         SET_FIELD(capabilities,
172                   ETH_VPORT_RSS_CONFIG_IPV4_UDP_CAPABILITY,
173                   !!(p_params->rss_caps & QED_RSS_IPV4_UDP));
174         SET_FIELD(capabilities,
175                   ETH_VPORT_RSS_CONFIG_IPV6_UDP_CAPABILITY,
176                   !!(p_params->rss_caps & QED_RSS_IPV6_UDP));
177         rss->tbl_size = p_params->rss_table_size_log;
178
179         rss->capabilities = cpu_to_le16(capabilities);
180
181         DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
182                    "update rss flag %d, rss_mode = %d, update_caps = %d, capabilities = %d, update_ind = %d, update_rss_key = %d\n",
183                    p_ramrod->common.update_rss_flg,
184                    rss->rss_mode, rss->update_rss_capabilities,
185                    capabilities, rss->update_rss_ind_table,
186                    rss->update_rss_key);
187
188         for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
189                 rc = qed_fw_l2_queue(p_hwfn,
190                                      (u8)p_params->rss_ind_table[i],
191                                      &abs_l2_queue);
192                 if (rc)
193                         return rc;
194
195                 rss->indirection_table[i] = cpu_to_le16(abs_l2_queue);
196                 DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP, "i= %d, queue = %d\n",
197                            i, rss->indirection_table[i]);
198         }
199
200         for (i = 0; i < 10; i++)
201                 rss->rss_key[i] = cpu_to_le32(p_params->rss_key[i]);
202
203         return rc;
204 }
205
206 static void
207 qed_sp_update_accept_mode(struct qed_hwfn *p_hwfn,
208                           struct vport_update_ramrod_data *p_ramrod,
209                           struct qed_filter_accept_flags accept_flags)
210 {
211         p_ramrod->common.update_rx_mode_flg =
212                 accept_flags.update_rx_mode_config;
213
214         p_ramrod->common.update_tx_mode_flg =
215                 accept_flags.update_tx_mode_config;
216
217         /* Set Rx mode accept flags */
218         if (p_ramrod->common.update_rx_mode_flg) {
219                 u8 accept_filter = accept_flags.rx_accept_filter;
220                 u16 state = 0;
221
222                 SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_DROP_ALL,
223                           !(!!(accept_filter & QED_ACCEPT_UCAST_MATCHED) ||
224                             !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED)));
225
226                 SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_ACCEPT_UNMATCHED,
227                           !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED));
228
229                 SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_DROP_ALL,
230                           !(!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) ||
231                             !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
232
233                 SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_ACCEPT_ALL,
234                           (!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) &&
235                            !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
236
237                 SET_FIELD(state, ETH_VPORT_RX_MODE_BCAST_ACCEPT_ALL,
238                           !!(accept_filter & QED_ACCEPT_BCAST));
239
240                 p_ramrod->rx_mode.state = cpu_to_le16(state);
241                 DP_VERBOSE(p_hwfn, QED_MSG_SP,
242                            "p_ramrod->rx_mode.state = 0x%x\n", state);
243         }
244
245         /* Set Tx mode accept flags */
246         if (p_ramrod->common.update_tx_mode_flg) {
247                 u8 accept_filter = accept_flags.tx_accept_filter;
248                 u16 state = 0;
249
250                 SET_FIELD(state, ETH_VPORT_TX_MODE_UCAST_DROP_ALL,
251                           !!(accept_filter & QED_ACCEPT_NONE));
252
253                 SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_DROP_ALL,
254                           !!(accept_filter & QED_ACCEPT_NONE));
255
256                 SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_ACCEPT_ALL,
257                           (!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) &&
258                            !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
259
260                 SET_FIELD(state, ETH_VPORT_TX_MODE_BCAST_ACCEPT_ALL,
261                           !!(accept_filter & QED_ACCEPT_BCAST));
262
263                 p_ramrod->tx_mode.state = cpu_to_le16(state);
264                 DP_VERBOSE(p_hwfn, QED_MSG_SP,
265                            "p_ramrod->tx_mode.state = 0x%x\n", state);
266         }
267 }
268
269 static void
270 qed_sp_vport_update_sge_tpa(struct qed_hwfn *p_hwfn,
271                             struct vport_update_ramrod_data *p_ramrod,
272                             struct qed_sge_tpa_params *p_params)
273 {
274         struct eth_vport_tpa_param *p_tpa;
275
276         if (!p_params) {
277                 p_ramrod->common.update_tpa_param_flg = 0;
278                 p_ramrod->common.update_tpa_en_flg = 0;
279                 p_ramrod->common.update_tpa_param_flg = 0;
280                 return;
281         }
282
283         p_ramrod->common.update_tpa_en_flg = p_params->update_tpa_en_flg;
284         p_tpa = &p_ramrod->tpa_param;
285         p_tpa->tpa_ipv4_en_flg = p_params->tpa_ipv4_en_flg;
286         p_tpa->tpa_ipv6_en_flg = p_params->tpa_ipv6_en_flg;
287         p_tpa->tpa_ipv4_tunn_en_flg = p_params->tpa_ipv4_tunn_en_flg;
288         p_tpa->tpa_ipv6_tunn_en_flg = p_params->tpa_ipv6_tunn_en_flg;
289
290         p_ramrod->common.update_tpa_param_flg = p_params->update_tpa_param_flg;
291         p_tpa->max_buff_num = p_params->max_buffers_per_cqe;
292         p_tpa->tpa_pkt_split_flg = p_params->tpa_pkt_split_flg;
293         p_tpa->tpa_hdr_data_split_flg = p_params->tpa_hdr_data_split_flg;
294         p_tpa->tpa_gro_consistent_flg = p_params->tpa_gro_consistent_flg;
295         p_tpa->tpa_max_aggs_num = p_params->tpa_max_aggs_num;
296         p_tpa->tpa_max_size = p_params->tpa_max_size;
297         p_tpa->tpa_min_size_to_start = p_params->tpa_min_size_to_start;
298         p_tpa->tpa_min_size_to_cont = p_params->tpa_min_size_to_cont;
299 }
300
301 static void
302 qed_sp_update_mcast_bin(struct qed_hwfn *p_hwfn,
303                         struct vport_update_ramrod_data *p_ramrod,
304                         struct qed_sp_vport_update_params *p_params)
305 {
306         int i;
307
308         memset(&p_ramrod->approx_mcast.bins, 0,
309                sizeof(p_ramrod->approx_mcast.bins));
310
311         if (!p_params->update_approx_mcast_flg)
312                 return;
313
314         p_ramrod->common.update_approx_mcast_flg = 1;
315         for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
316                 u32 *p_bins = p_params->bins;
317
318                 p_ramrod->approx_mcast.bins[i] = cpu_to_le32(p_bins[i]);
319         }
320 }
321
322 int qed_sp_vport_update(struct qed_hwfn *p_hwfn,
323                         struct qed_sp_vport_update_params *p_params,
324                         enum spq_mode comp_mode,
325                         struct qed_spq_comp_cb *p_comp_data)
326 {
327         struct qed_rss_params *p_rss_params = p_params->rss_params;
328         struct vport_update_ramrod_data_cmn *p_cmn;
329         struct qed_sp_init_data init_data;
330         struct vport_update_ramrod_data *p_ramrod = NULL;
331         struct qed_spq_entry *p_ent = NULL;
332         u8 abs_vport_id = 0, val;
333         int rc = -EINVAL;
334
335         if (IS_VF(p_hwfn->cdev)) {
336                 rc = qed_vf_pf_vport_update(p_hwfn, p_params);
337                 return rc;
338         }
339
340         rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
341         if (rc)
342                 return rc;
343
344         memset(&init_data, 0, sizeof(init_data));
345         init_data.cid = qed_spq_get_cid(p_hwfn);
346         init_data.opaque_fid = p_params->opaque_fid;
347         init_data.comp_mode = comp_mode;
348         init_data.p_comp_data = p_comp_data;
349
350         rc = qed_sp_init_request(p_hwfn, &p_ent,
351                                  ETH_RAMROD_VPORT_UPDATE,
352                                  PROTOCOLID_ETH, &init_data);
353         if (rc)
354                 return rc;
355
356         /* Copy input params to ramrod according to FW struct */
357         p_ramrod = &p_ent->ramrod.vport_update;
358         p_cmn = &p_ramrod->common;
359
360         p_cmn->vport_id = abs_vport_id;
361         p_cmn->rx_active_flg = p_params->vport_active_rx_flg;
362         p_cmn->update_rx_active_flg = p_params->update_vport_active_rx_flg;
363         p_cmn->tx_active_flg = p_params->vport_active_tx_flg;
364         p_cmn->update_tx_active_flg = p_params->update_vport_active_tx_flg;
365         p_cmn->accept_any_vlan = p_params->accept_any_vlan;
366         val = p_params->update_accept_any_vlan_flg;
367         p_cmn->update_accept_any_vlan_flg = val;
368
369         p_cmn->inner_vlan_removal_en = p_params->inner_vlan_removal_flg;
370         val = p_params->update_inner_vlan_removal_flg;
371         p_cmn->update_inner_vlan_removal_en_flg = val;
372
373         p_cmn->default_vlan_en = p_params->default_vlan_enable_flg;
374         val = p_params->update_default_vlan_enable_flg;
375         p_cmn->update_default_vlan_en_flg = val;
376
377         p_cmn->default_vlan = cpu_to_le16(p_params->default_vlan);
378         p_cmn->update_default_vlan_flg = p_params->update_default_vlan_flg;
379
380         p_cmn->silent_vlan_removal_en = p_params->silent_vlan_removal_flg;
381
382         p_ramrod->common.tx_switching_en = p_params->tx_switching_flg;
383         p_cmn->update_tx_switching_en_flg = p_params->update_tx_switching_flg;
384
385         p_cmn->anti_spoofing_en = p_params->anti_spoofing_en;
386         val = p_params->update_anti_spoofing_en_flg;
387         p_ramrod->common.update_anti_spoofing_en_flg = val;
388
389         rc = qed_sp_vport_update_rss(p_hwfn, p_ramrod, p_rss_params);
390         if (rc) {
391                 /* Return spq entry which is taken in qed_sp_init_request()*/
392                 qed_spq_return_entry(p_hwfn, p_ent);
393                 return rc;
394         }
395
396         /* Update mcast bins for VFs, PF doesn't use this functionality */
397         qed_sp_update_mcast_bin(p_hwfn, p_ramrod, p_params);
398
399         qed_sp_update_accept_mode(p_hwfn, p_ramrod, p_params->accept_flags);
400         qed_sp_vport_update_sge_tpa(p_hwfn, p_ramrod, p_params->sge_tpa_params);
401         return qed_spq_post(p_hwfn, p_ent, NULL);
402 }
403
404 int qed_sp_vport_stop(struct qed_hwfn *p_hwfn, u16 opaque_fid, u8 vport_id)
405 {
406         struct vport_stop_ramrod_data *p_ramrod;
407         struct qed_sp_init_data init_data;
408         struct qed_spq_entry *p_ent;
409         u8 abs_vport_id = 0;
410         int rc;
411
412         if (IS_VF(p_hwfn->cdev))
413                 return qed_vf_pf_vport_stop(p_hwfn);
414
415         rc = qed_fw_vport(p_hwfn, vport_id, &abs_vport_id);
416         if (rc)
417                 return rc;
418
419         memset(&init_data, 0, sizeof(init_data));
420         init_data.cid = qed_spq_get_cid(p_hwfn);
421         init_data.opaque_fid = opaque_fid;
422         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
423
424         rc = qed_sp_init_request(p_hwfn, &p_ent,
425                                  ETH_RAMROD_VPORT_STOP,
426                                  PROTOCOLID_ETH, &init_data);
427         if (rc)
428                 return rc;
429
430         p_ramrod = &p_ent->ramrod.vport_stop;
431         p_ramrod->vport_id = abs_vport_id;
432
433         return qed_spq_post(p_hwfn, p_ent, NULL);
434 }
435
436 static int
437 qed_vf_pf_accept_flags(struct qed_hwfn *p_hwfn,
438                        struct qed_filter_accept_flags *p_accept_flags)
439 {
440         struct qed_sp_vport_update_params s_params;
441
442         memset(&s_params, 0, sizeof(s_params));
443         memcpy(&s_params.accept_flags, p_accept_flags,
444                sizeof(struct qed_filter_accept_flags));
445
446         return qed_vf_pf_vport_update(p_hwfn, &s_params);
447 }
448
449 static int qed_filter_accept_cmd(struct qed_dev *cdev,
450                                  u8 vport,
451                                  struct qed_filter_accept_flags accept_flags,
452                                  u8 update_accept_any_vlan,
453                                  u8 accept_any_vlan,
454                                  enum spq_mode comp_mode,
455                                  struct qed_spq_comp_cb *p_comp_data)
456 {
457         struct qed_sp_vport_update_params vport_update_params;
458         int i, rc;
459
460         /* Prepare and send the vport rx_mode change */
461         memset(&vport_update_params, 0, sizeof(vport_update_params));
462         vport_update_params.vport_id = vport;
463         vport_update_params.accept_flags = accept_flags;
464         vport_update_params.update_accept_any_vlan_flg = update_accept_any_vlan;
465         vport_update_params.accept_any_vlan = accept_any_vlan;
466
467         for_each_hwfn(cdev, i) {
468                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
469
470                 vport_update_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
471
472                 if (IS_VF(cdev)) {
473                         rc = qed_vf_pf_accept_flags(p_hwfn, &accept_flags);
474                         if (rc)
475                                 return rc;
476                         continue;
477                 }
478
479                 rc = qed_sp_vport_update(p_hwfn, &vport_update_params,
480                                          comp_mode, p_comp_data);
481                 if (rc) {
482                         DP_ERR(cdev, "Update rx_mode failed %d\n", rc);
483                         return rc;
484                 }
485
486                 DP_VERBOSE(p_hwfn, QED_MSG_SP,
487                            "Accept filter configured, flags = [Rx]%x [Tx]%x\n",
488                            accept_flags.rx_accept_filter,
489                            accept_flags.tx_accept_filter);
490                 if (update_accept_any_vlan)
491                         DP_VERBOSE(p_hwfn, QED_MSG_SP,
492                                    "accept_any_vlan=%d configured\n",
493                                    accept_any_vlan);
494         }
495
496         return 0;
497 }
498
499 static int qed_sp_release_queue_cid(
500         struct qed_hwfn *p_hwfn,
501         struct qed_hw_cid_data *p_cid_data)
502 {
503         if (!p_cid_data->b_cid_allocated)
504                 return 0;
505
506         qed_cxt_release_cid(p_hwfn, p_cid_data->cid);
507
508         p_cid_data->b_cid_allocated = false;
509
510         return 0;
511 }
512
513 int qed_sp_eth_rxq_start_ramrod(struct qed_hwfn *p_hwfn,
514                                 u16 opaque_fid,
515                                 u32 cid,
516                                 struct qed_queue_start_common_params *p_params,
517                                 u8 stats_id,
518                                 u16 bd_max_bytes,
519                                 dma_addr_t bd_chain_phys_addr,
520                                 dma_addr_t cqe_pbl_addr,
521                                 u16 cqe_pbl_size, bool b_use_zone_a_prod)
522 {
523         struct rx_queue_start_ramrod_data *p_ramrod = NULL;
524         struct qed_spq_entry *p_ent = NULL;
525         struct qed_sp_init_data init_data;
526         struct qed_hw_cid_data *p_rx_cid;
527         u16 abs_rx_q_id = 0;
528         u8 abs_vport_id = 0;
529         int rc = -EINVAL;
530
531         /* Store information for the stop */
532         p_rx_cid = &p_hwfn->p_rx_cids[p_params->queue_id];
533         p_rx_cid->cid = cid;
534         p_rx_cid->opaque_fid = opaque_fid;
535         p_rx_cid->vport_id = p_params->vport_id;
536
537         rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
538         if (rc)
539                 return rc;
540
541         rc = qed_fw_l2_queue(p_hwfn, p_params->queue_id, &abs_rx_q_id);
542         if (rc)
543                 return rc;
544
545         DP_VERBOSE(p_hwfn, QED_MSG_SP,
546                    "opaque_fid=0x%x, cid=0x%x, rx_qid=0x%x, vport_id=0x%x, sb_id=0x%x\n",
547                    opaque_fid,
548                    cid, p_params->queue_id, p_params->vport_id, p_params->sb);
549
550         /* Get SPQ entry */
551         memset(&init_data, 0, sizeof(init_data));
552         init_data.cid = cid;
553         init_data.opaque_fid = opaque_fid;
554         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
555
556         rc = qed_sp_init_request(p_hwfn, &p_ent,
557                                  ETH_RAMROD_RX_QUEUE_START,
558                                  PROTOCOLID_ETH, &init_data);
559         if (rc)
560                 return rc;
561
562         p_ramrod = &p_ent->ramrod.rx_queue_start;
563
564         p_ramrod->sb_id = cpu_to_le16(p_params->sb);
565         p_ramrod->sb_index = p_params->sb_idx;
566         p_ramrod->vport_id = abs_vport_id;
567         p_ramrod->stats_counter_id = stats_id;
568         p_ramrod->rx_queue_id = cpu_to_le16(abs_rx_q_id);
569         p_ramrod->complete_cqe_flg = 0;
570         p_ramrod->complete_event_flg = 1;
571
572         p_ramrod->bd_max_bytes = cpu_to_le16(bd_max_bytes);
573         DMA_REGPAIR_LE(p_ramrod->bd_base, bd_chain_phys_addr);
574
575         p_ramrod->num_of_pbl_pages = cpu_to_le16(cqe_pbl_size);
576         DMA_REGPAIR_LE(p_ramrod->cqe_pbl_addr, cqe_pbl_addr);
577
578         if (p_params->vf_qid || b_use_zone_a_prod) {
579                 p_ramrod->vf_rx_prod_index = p_params->vf_qid;
580                 DP_VERBOSE(p_hwfn, QED_MSG_SP,
581                            "Queue%s is meant for VF rxq[%02x]\n",
582                            b_use_zone_a_prod ? " [legacy]" : "",
583                            p_params->vf_qid);
584                 p_ramrod->vf_rx_prod_use_zone_a = b_use_zone_a_prod;
585         }
586
587         return qed_spq_post(p_hwfn, p_ent, NULL);
588 }
589
590 static int
591 qed_sp_eth_rx_queue_start(struct qed_hwfn *p_hwfn,
592                           u16 opaque_fid,
593                           struct qed_queue_start_common_params *p_params,
594                           u16 bd_max_bytes,
595                           dma_addr_t bd_chain_phys_addr,
596                           dma_addr_t cqe_pbl_addr,
597                           u16 cqe_pbl_size, void __iomem **pp_prod)
598 {
599         struct qed_hw_cid_data *p_rx_cid;
600         u32 init_prod_val = 0;
601         u16 abs_l2_queue = 0;
602         u8 abs_stats_id = 0;
603         int rc;
604
605         if (IS_VF(p_hwfn->cdev)) {
606                 return qed_vf_pf_rxq_start(p_hwfn,
607                                            p_params->queue_id,
608                                            p_params->sb,
609                                            (u8)p_params->sb_idx,
610                                            bd_max_bytes,
611                                            bd_chain_phys_addr,
612                                            cqe_pbl_addr, cqe_pbl_size, pp_prod);
613         }
614
615         rc = qed_fw_l2_queue(p_hwfn, p_params->queue_id, &abs_l2_queue);
616         if (rc)
617                 return rc;
618
619         rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_stats_id);
620         if (rc)
621                 return rc;
622
623         *pp_prod = (u8 __iomem *)p_hwfn->regview +
624                                  GTT_BAR0_MAP_REG_MSDM_RAM +
625                                  MSTORM_ETH_PF_PRODS_OFFSET(abs_l2_queue);
626
627         /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
628         __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
629                           (u32 *)(&init_prod_val));
630
631         /* Allocate a CID for the queue */
632         p_rx_cid = &p_hwfn->p_rx_cids[p_params->queue_id];
633         rc = qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_ETH, &p_rx_cid->cid);
634         if (rc) {
635                 DP_NOTICE(p_hwfn, "Failed to acquire cid\n");
636                 return rc;
637         }
638         p_rx_cid->b_cid_allocated = true;
639
640         rc = qed_sp_eth_rxq_start_ramrod(p_hwfn,
641                                          opaque_fid,
642                                          p_rx_cid->cid,
643                                          p_params,
644                                          abs_stats_id,
645                                          bd_max_bytes,
646                                          bd_chain_phys_addr,
647                                          cqe_pbl_addr, cqe_pbl_size, false);
648
649         if (rc)
650                 qed_sp_release_queue_cid(p_hwfn, p_rx_cid);
651
652         return rc;
653 }
654
655 int qed_sp_eth_rx_queues_update(struct qed_hwfn *p_hwfn,
656                                 u16 rx_queue_id,
657                                 u8 num_rxqs,
658                                 u8 complete_cqe_flg,
659                                 u8 complete_event_flg,
660                                 enum spq_mode comp_mode,
661                                 struct qed_spq_comp_cb *p_comp_data)
662 {
663         struct rx_queue_update_ramrod_data *p_ramrod = NULL;
664         struct qed_spq_entry *p_ent = NULL;
665         struct qed_sp_init_data init_data;
666         struct qed_hw_cid_data *p_rx_cid;
667         u16 qid, abs_rx_q_id = 0;
668         int rc = -EINVAL;
669         u8 i;
670
671         memset(&init_data, 0, sizeof(init_data));
672         init_data.comp_mode = comp_mode;
673         init_data.p_comp_data = p_comp_data;
674
675         for (i = 0; i < num_rxqs; i++) {
676                 qid = rx_queue_id + i;
677                 p_rx_cid = &p_hwfn->p_rx_cids[qid];
678
679                 /* Get SPQ entry */
680                 init_data.cid = p_rx_cid->cid;
681                 init_data.opaque_fid = p_rx_cid->opaque_fid;
682
683                 rc = qed_sp_init_request(p_hwfn, &p_ent,
684                                          ETH_RAMROD_RX_QUEUE_UPDATE,
685                                          PROTOCOLID_ETH, &init_data);
686                 if (rc)
687                         return rc;
688
689                 p_ramrod = &p_ent->ramrod.rx_queue_update;
690
691                 qed_fw_vport(p_hwfn, p_rx_cid->vport_id, &p_ramrod->vport_id);
692                 qed_fw_l2_queue(p_hwfn, qid, &abs_rx_q_id);
693                 p_ramrod->rx_queue_id = cpu_to_le16(abs_rx_q_id);
694                 p_ramrod->complete_cqe_flg = complete_cqe_flg;
695                 p_ramrod->complete_event_flg = complete_event_flg;
696
697                 rc = qed_spq_post(p_hwfn, p_ent, NULL);
698                 if (rc)
699                         return rc;
700         }
701
702         return rc;
703 }
704
705 int qed_sp_eth_rx_queue_stop(struct qed_hwfn *p_hwfn,
706                              u16 rx_queue_id,
707                              bool eq_completion_only, bool cqe_completion)
708 {
709         struct qed_hw_cid_data *p_rx_cid = &p_hwfn->p_rx_cids[rx_queue_id];
710         struct rx_queue_stop_ramrod_data *p_ramrod = NULL;
711         struct qed_spq_entry *p_ent = NULL;
712         struct qed_sp_init_data init_data;
713         u16 abs_rx_q_id = 0;
714         int rc = -EINVAL;
715
716         if (IS_VF(p_hwfn->cdev))
717                 return qed_vf_pf_rxq_stop(p_hwfn, rx_queue_id, cqe_completion);
718
719         /* Get SPQ entry */
720         memset(&init_data, 0, sizeof(init_data));
721         init_data.cid = p_rx_cid->cid;
722         init_data.opaque_fid = p_rx_cid->opaque_fid;
723         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
724
725         rc = qed_sp_init_request(p_hwfn, &p_ent,
726                                  ETH_RAMROD_RX_QUEUE_STOP,
727                                  PROTOCOLID_ETH, &init_data);
728         if (rc)
729                 return rc;
730
731         p_ramrod = &p_ent->ramrod.rx_queue_stop;
732
733         qed_fw_vport(p_hwfn, p_rx_cid->vport_id, &p_ramrod->vport_id);
734         qed_fw_l2_queue(p_hwfn, rx_queue_id, &abs_rx_q_id);
735         p_ramrod->rx_queue_id = cpu_to_le16(abs_rx_q_id);
736
737         /* Cleaning the queue requires the completion to arrive there.
738          * In addition, VFs require the answer to come as eqe to PF.
739          */
740         p_ramrod->complete_cqe_flg =
741                 (!!(p_rx_cid->opaque_fid == p_hwfn->hw_info.opaque_fid) &&
742                  !eq_completion_only) || cqe_completion;
743         p_ramrod->complete_event_flg =
744                 !(p_rx_cid->opaque_fid == p_hwfn->hw_info.opaque_fid) ||
745                 eq_completion_only;
746
747         rc = qed_spq_post(p_hwfn, p_ent, NULL);
748         if (rc)
749                 return rc;
750
751         return qed_sp_release_queue_cid(p_hwfn, p_rx_cid);
752 }
753
754 int qed_sp_eth_txq_start_ramrod(struct qed_hwfn  *p_hwfn,
755                                 u16  opaque_fid,
756                                 u32  cid,
757                                 struct qed_queue_start_common_params *p_params,
758                                 u8  stats_id,
759                                 dma_addr_t pbl_addr,
760                                 u16 pbl_size,
761                                 union qed_qm_pq_params *p_pq_params)
762 {
763         struct tx_queue_start_ramrod_data *p_ramrod = NULL;
764         struct qed_spq_entry *p_ent = NULL;
765         struct qed_sp_init_data init_data;
766         struct qed_hw_cid_data *p_tx_cid;
767         u16 pq_id, abs_tx_q_id = 0;
768         int rc = -EINVAL;
769         u8 abs_vport_id;
770
771         /* Store information for the stop */
772         p_tx_cid = &p_hwfn->p_tx_cids[p_params->queue_id];
773         p_tx_cid->cid           = cid;
774         p_tx_cid->opaque_fid    = opaque_fid;
775
776         rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
777         if (rc)
778                 return rc;
779
780         rc = qed_fw_l2_queue(p_hwfn, p_params->queue_id, &abs_tx_q_id);
781         if (rc)
782                 return rc;
783
784         /* Get SPQ entry */
785         memset(&init_data, 0, sizeof(init_data));
786         init_data.cid = cid;
787         init_data.opaque_fid = opaque_fid;
788         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
789
790         rc = qed_sp_init_request(p_hwfn, &p_ent,
791                                  ETH_RAMROD_TX_QUEUE_START,
792                                  PROTOCOLID_ETH, &init_data);
793         if (rc)
794                 return rc;
795
796         p_ramrod = &p_ent->ramrod.tx_queue_start;
797         p_ramrod->vport_id = abs_vport_id;
798
799         p_ramrod->sb_id = cpu_to_le16(p_params->sb);
800         p_ramrod->sb_index = p_params->sb_idx;
801         p_ramrod->stats_counter_id = stats_id;
802
803         p_ramrod->queue_zone_id = cpu_to_le16(abs_tx_q_id);
804
805         p_ramrod->pbl_size = cpu_to_le16(pbl_size);
806         DMA_REGPAIR_LE(p_ramrod->pbl_base_addr, pbl_addr);
807
808         pq_id = qed_get_qm_pq(p_hwfn, PROTOCOLID_ETH, p_pq_params);
809         p_ramrod->qm_pq_id = cpu_to_le16(pq_id);
810
811         return qed_spq_post(p_hwfn, p_ent, NULL);
812 }
813
814 static int
815 qed_sp_eth_tx_queue_start(struct qed_hwfn *p_hwfn,
816                           u16 opaque_fid,
817                           struct qed_queue_start_common_params *p_params,
818                           dma_addr_t pbl_addr,
819                           u16 pbl_size, void __iomem **pp_doorbell)
820 {
821         struct qed_hw_cid_data *p_tx_cid;
822         union qed_qm_pq_params pq_params;
823         u8 abs_stats_id = 0;
824         int rc;
825
826         if (IS_VF(p_hwfn->cdev)) {
827                 return qed_vf_pf_txq_start(p_hwfn,
828                                            p_params->queue_id,
829                                            p_params->sb,
830                                            p_params->sb_idx,
831                                            pbl_addr, pbl_size, pp_doorbell);
832         }
833
834         rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_stats_id);
835         if (rc)
836                 return rc;
837
838         p_tx_cid = &p_hwfn->p_tx_cids[p_params->queue_id];
839         memset(p_tx_cid, 0, sizeof(*p_tx_cid));
840         memset(&pq_params, 0, sizeof(pq_params));
841
842         /* Allocate a CID for the queue */
843         rc = qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_ETH, &p_tx_cid->cid);
844         if (rc) {
845                 DP_NOTICE(p_hwfn, "Failed to acquire cid\n");
846                 return rc;
847         }
848         p_tx_cid->b_cid_allocated = true;
849
850         DP_VERBOSE(p_hwfn, QED_MSG_SP,
851                    "opaque_fid=0x%x, cid=0x%x, tx_qid=0x%x, vport_id=0x%x, sb_id=0x%x\n",
852                    opaque_fid, p_tx_cid->cid,
853                    p_params->queue_id, p_params->vport_id, p_params->sb);
854
855         rc = qed_sp_eth_txq_start_ramrod(p_hwfn,
856                                          opaque_fid,
857                                          p_tx_cid->cid,
858                                          p_params,
859                                          abs_stats_id,
860                                          pbl_addr,
861                                          pbl_size,
862                                          &pq_params);
863
864         *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
865                                      qed_db_addr(p_tx_cid->cid, DQ_DEMS_LEGACY);
866
867         if (rc)
868                 qed_sp_release_queue_cid(p_hwfn, p_tx_cid);
869
870         return rc;
871 }
872
873 int qed_sp_eth_tx_queue_stop(struct qed_hwfn *p_hwfn, u16 tx_queue_id)
874 {
875         struct qed_hw_cid_data *p_tx_cid = &p_hwfn->p_tx_cids[tx_queue_id];
876         struct qed_spq_entry *p_ent = NULL;
877         struct qed_sp_init_data init_data;
878         int rc = -EINVAL;
879
880         if (IS_VF(p_hwfn->cdev))
881                 return qed_vf_pf_txq_stop(p_hwfn, tx_queue_id);
882
883         /* Get SPQ entry */
884         memset(&init_data, 0, sizeof(init_data));
885         init_data.cid = p_tx_cid->cid;
886         init_data.opaque_fid = p_tx_cid->opaque_fid;
887         init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
888
889         rc = qed_sp_init_request(p_hwfn, &p_ent,
890                                  ETH_RAMROD_TX_QUEUE_STOP,
891                                  PROTOCOLID_ETH, &init_data);
892         if (rc)
893                 return rc;
894
895         rc = qed_spq_post(p_hwfn, p_ent, NULL);
896         if (rc)
897                 return rc;
898
899         return qed_sp_release_queue_cid(p_hwfn, p_tx_cid);
900 }
901
902 static enum eth_filter_action qed_filter_action(enum qed_filter_opcode opcode)
903 {
904         enum eth_filter_action action = MAX_ETH_FILTER_ACTION;
905
906         switch (opcode) {
907         case QED_FILTER_ADD:
908                 action = ETH_FILTER_ACTION_ADD;
909                 break;
910         case QED_FILTER_REMOVE:
911                 action = ETH_FILTER_ACTION_REMOVE;
912                 break;
913         case QED_FILTER_FLUSH:
914                 action = ETH_FILTER_ACTION_REMOVE_ALL;
915                 break;
916         default:
917                 action = MAX_ETH_FILTER_ACTION;
918         }
919
920         return action;
921 }
922
923 static void qed_set_fw_mac_addr(__le16 *fw_msb,
924                                 __le16 *fw_mid,
925                                 __le16 *fw_lsb,
926                                 u8 *mac)
927 {
928         ((u8 *)fw_msb)[0] = mac[1];
929         ((u8 *)fw_msb)[1] = mac[0];
930         ((u8 *)fw_mid)[0] = mac[3];
931         ((u8 *)fw_mid)[1] = mac[2];
932         ((u8 *)fw_lsb)[0] = mac[5];
933         ((u8 *)fw_lsb)[1] = mac[4];
934 }
935
936 static int
937 qed_filter_ucast_common(struct qed_hwfn *p_hwfn,
938                         u16 opaque_fid,
939                         struct qed_filter_ucast *p_filter_cmd,
940                         struct vport_filter_update_ramrod_data **pp_ramrod,
941                         struct qed_spq_entry **pp_ent,
942                         enum spq_mode comp_mode,
943                         struct qed_spq_comp_cb *p_comp_data)
944 {
945         u8 vport_to_add_to = 0, vport_to_remove_from = 0;
946         struct vport_filter_update_ramrod_data *p_ramrod;
947         struct eth_filter_cmd *p_first_filter;
948         struct eth_filter_cmd *p_second_filter;
949         struct qed_sp_init_data init_data;
950         enum eth_filter_action action;
951         int rc;
952
953         rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
954                           &vport_to_remove_from);
955         if (rc)
956                 return rc;
957
958         rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
959                           &vport_to_add_to);
960         if (rc)
961                 return rc;
962
963         /* Get SPQ entry */
964         memset(&init_data, 0, sizeof(init_data));
965         init_data.cid = qed_spq_get_cid(p_hwfn);
966         init_data.opaque_fid = opaque_fid;
967         init_data.comp_mode = comp_mode;
968         init_data.p_comp_data = p_comp_data;
969
970         rc = qed_sp_init_request(p_hwfn, pp_ent,
971                                  ETH_RAMROD_FILTERS_UPDATE,
972                                  PROTOCOLID_ETH, &init_data);
973         if (rc)
974                 return rc;
975
976         *pp_ramrod = &(*pp_ent)->ramrod.vport_filter_update;
977         p_ramrod = *pp_ramrod;
978         p_ramrod->filter_cmd_hdr.rx = p_filter_cmd->is_rx_filter ? 1 : 0;
979         p_ramrod->filter_cmd_hdr.tx = p_filter_cmd->is_tx_filter ? 1 : 0;
980
981         switch (p_filter_cmd->opcode) {
982         case QED_FILTER_REPLACE:
983         case QED_FILTER_MOVE:
984                 p_ramrod->filter_cmd_hdr.cmd_cnt = 2; break;
985         default:
986                 p_ramrod->filter_cmd_hdr.cmd_cnt = 1; break;
987         }
988
989         p_first_filter  = &p_ramrod->filter_cmds[0];
990         p_second_filter = &p_ramrod->filter_cmds[1];
991
992         switch (p_filter_cmd->type) {
993         case QED_FILTER_MAC:
994                 p_first_filter->type = ETH_FILTER_TYPE_MAC; break;
995         case QED_FILTER_VLAN:
996                 p_first_filter->type = ETH_FILTER_TYPE_VLAN; break;
997         case QED_FILTER_MAC_VLAN:
998                 p_first_filter->type = ETH_FILTER_TYPE_PAIR; break;
999         case QED_FILTER_INNER_MAC:
1000                 p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC; break;
1001         case QED_FILTER_INNER_VLAN:
1002                 p_first_filter->type = ETH_FILTER_TYPE_INNER_VLAN; break;
1003         case QED_FILTER_INNER_PAIR:
1004                 p_first_filter->type = ETH_FILTER_TYPE_INNER_PAIR; break;
1005         case QED_FILTER_INNER_MAC_VNI_PAIR:
1006                 p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR;
1007                 break;
1008         case QED_FILTER_MAC_VNI_PAIR:
1009                 p_first_filter->type = ETH_FILTER_TYPE_MAC_VNI_PAIR; break;
1010         case QED_FILTER_VNI:
1011                 p_first_filter->type = ETH_FILTER_TYPE_VNI; break;
1012         }
1013
1014         if ((p_first_filter->type == ETH_FILTER_TYPE_MAC) ||
1015             (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
1016             (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC) ||
1017             (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR) ||
1018             (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
1019             (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR)) {
1020                 qed_set_fw_mac_addr(&p_first_filter->mac_msb,
1021                                     &p_first_filter->mac_mid,
1022                                     &p_first_filter->mac_lsb,
1023                                     (u8 *)p_filter_cmd->mac);
1024         }
1025
1026         if ((p_first_filter->type == ETH_FILTER_TYPE_VLAN) ||
1027             (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
1028             (p_first_filter->type == ETH_FILTER_TYPE_INNER_VLAN) ||
1029             (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR))
1030                 p_first_filter->vlan_id = cpu_to_le16(p_filter_cmd->vlan);
1031
1032         if ((p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
1033             (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR) ||
1034             (p_first_filter->type == ETH_FILTER_TYPE_VNI))
1035                 p_first_filter->vni = cpu_to_le32(p_filter_cmd->vni);
1036
1037         if (p_filter_cmd->opcode == QED_FILTER_MOVE) {
1038                 p_second_filter->type = p_first_filter->type;
1039                 p_second_filter->mac_msb = p_first_filter->mac_msb;
1040                 p_second_filter->mac_mid = p_first_filter->mac_mid;
1041                 p_second_filter->mac_lsb = p_first_filter->mac_lsb;
1042                 p_second_filter->vlan_id = p_first_filter->vlan_id;
1043                 p_second_filter->vni = p_first_filter->vni;
1044
1045                 p_first_filter->action = ETH_FILTER_ACTION_REMOVE;
1046
1047                 p_first_filter->vport_id = vport_to_remove_from;
1048
1049                 p_second_filter->action = ETH_FILTER_ACTION_ADD;
1050                 p_second_filter->vport_id = vport_to_add_to;
1051         } else if (p_filter_cmd->opcode == QED_FILTER_REPLACE) {
1052                 p_first_filter->vport_id = vport_to_add_to;
1053                 memcpy(p_second_filter, p_first_filter,
1054                        sizeof(*p_second_filter));
1055                 p_first_filter->action  = ETH_FILTER_ACTION_REMOVE_ALL;
1056                 p_second_filter->action = ETH_FILTER_ACTION_ADD;
1057         } else {
1058                 action = qed_filter_action(p_filter_cmd->opcode);
1059
1060                 if (action == MAX_ETH_FILTER_ACTION) {
1061                         DP_NOTICE(p_hwfn,
1062                                   "%d is not supported yet\n",
1063                                   p_filter_cmd->opcode);
1064                         return -EINVAL;
1065                 }
1066
1067                 p_first_filter->action = action;
1068                 p_first_filter->vport_id = (p_filter_cmd->opcode ==
1069                                             QED_FILTER_REMOVE) ?
1070                                            vport_to_remove_from :
1071                                            vport_to_add_to;
1072         }
1073
1074         return 0;
1075 }
1076
1077 int qed_sp_eth_filter_ucast(struct qed_hwfn *p_hwfn,
1078                             u16 opaque_fid,
1079                             struct qed_filter_ucast *p_filter_cmd,
1080                             enum spq_mode comp_mode,
1081                             struct qed_spq_comp_cb *p_comp_data)
1082 {
1083         struct vport_filter_update_ramrod_data  *p_ramrod       = NULL;
1084         struct qed_spq_entry                    *p_ent          = NULL;
1085         struct eth_filter_cmd_header            *p_header;
1086         int                                     rc;
1087
1088         rc = qed_filter_ucast_common(p_hwfn, opaque_fid, p_filter_cmd,
1089                                      &p_ramrod, &p_ent,
1090                                      comp_mode, p_comp_data);
1091         if (rc) {
1092                 DP_ERR(p_hwfn, "Uni. filter command failed %d\n", rc);
1093                 return rc;
1094         }
1095         p_header = &p_ramrod->filter_cmd_hdr;
1096         p_header->assert_on_error = p_filter_cmd->assert_on_error;
1097
1098         rc = qed_spq_post(p_hwfn, p_ent, NULL);
1099         if (rc) {
1100                 DP_ERR(p_hwfn, "Unicast filter ADD command failed %d\n", rc);
1101                 return rc;
1102         }
1103
1104         DP_VERBOSE(p_hwfn, QED_MSG_SP,
1105                    "Unicast filter configured, opcode = %s, type = %s, cmd_cnt = %d, is_rx_filter = %d, is_tx_filter = %d\n",
1106                    (p_filter_cmd->opcode == QED_FILTER_ADD) ? "ADD" :
1107                    ((p_filter_cmd->opcode == QED_FILTER_REMOVE) ?
1108                    "REMOVE" :
1109                    ((p_filter_cmd->opcode == QED_FILTER_MOVE) ?
1110                     "MOVE" : "REPLACE")),
1111                    (p_filter_cmd->type == QED_FILTER_MAC) ? "MAC" :
1112                    ((p_filter_cmd->type == QED_FILTER_VLAN) ?
1113                     "VLAN" : "MAC & VLAN"),
1114                    p_ramrod->filter_cmd_hdr.cmd_cnt,
1115                    p_filter_cmd->is_rx_filter,
1116                    p_filter_cmd->is_tx_filter);
1117         DP_VERBOSE(p_hwfn, QED_MSG_SP,
1118                    "vport_to_add_to = %d, vport_to_remove_from = %d, mac = %2x:%2x:%2x:%2x:%2x:%2x, vlan = %d\n",
1119                    p_filter_cmd->vport_to_add_to,
1120                    p_filter_cmd->vport_to_remove_from,
1121                    p_filter_cmd->mac[0],
1122                    p_filter_cmd->mac[1],
1123                    p_filter_cmd->mac[2],
1124                    p_filter_cmd->mac[3],
1125                    p_filter_cmd->mac[4],
1126                    p_filter_cmd->mac[5],
1127                    p_filter_cmd->vlan);
1128
1129         return 0;
1130 }
1131
1132 /*******************************************************************************
1133  * Description:
1134  *         Calculates crc 32 on a buffer
1135  *         Note: crc32_length MUST be aligned to 8
1136  * Return:
1137  ******************************************************************************/
1138 static u32 qed_calc_crc32c(u8 *crc32_packet,
1139                            u32 crc32_length, u32 crc32_seed, u8 complement)
1140 {
1141         u32 byte = 0, bit = 0, crc32_result = crc32_seed;
1142         u8 msb = 0, current_byte = 0;
1143
1144         if ((!crc32_packet) ||
1145             (crc32_length == 0) ||
1146             ((crc32_length % 8) != 0))
1147                 return crc32_result;
1148         for (byte = 0; byte < crc32_length; byte++) {
1149                 current_byte = crc32_packet[byte];
1150                 for (bit = 0; bit < 8; bit++) {
1151                         msb = (u8)(crc32_result >> 31);
1152                         crc32_result = crc32_result << 1;
1153                         if (msb != (0x1 & (current_byte >> bit))) {
1154                                 crc32_result = crc32_result ^ CRC32_POLY;
1155                                 crc32_result |= 1; /*crc32_result[0] = 1;*/
1156                         }
1157                 }
1158         }
1159         return crc32_result;
1160 }
1161
1162 static u32 qed_crc32c_le(u32 seed, u8 *mac, u32 len)
1163 {
1164         u32 packet_buf[2] = { 0 };
1165
1166         memcpy((u8 *)(&packet_buf[0]), &mac[0], 6);
1167         return qed_calc_crc32c((u8 *)packet_buf, 8, seed, 0);
1168 }
1169
1170 u8 qed_mcast_bin_from_mac(u8 *mac)
1171 {
1172         u32 crc = qed_crc32c_le(ETH_MULTICAST_BIN_FROM_MAC_SEED,
1173                                 mac, ETH_ALEN);
1174
1175         return crc & 0xff;
1176 }
1177
1178 static int
1179 qed_sp_eth_filter_mcast(struct qed_hwfn *p_hwfn,
1180                         u16 opaque_fid,
1181                         struct qed_filter_mcast *p_filter_cmd,
1182                         enum spq_mode comp_mode,
1183                         struct qed_spq_comp_cb *p_comp_data)
1184 {
1185         struct vport_update_ramrod_data *p_ramrod = NULL;
1186         u32 bins[ETH_MULTICAST_MAC_BINS_IN_REGS];
1187         struct qed_spq_entry *p_ent = NULL;
1188         struct qed_sp_init_data init_data;
1189         u8 abs_vport_id = 0;
1190         int rc, i;
1191
1192         if (p_filter_cmd->opcode == QED_FILTER_ADD)
1193                 rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
1194                                   &abs_vport_id);
1195         else
1196                 rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
1197                                   &abs_vport_id);
1198         if (rc)
1199                 return rc;
1200
1201         /* Get SPQ entry */
1202         memset(&init_data, 0, sizeof(init_data));
1203         init_data.cid = qed_spq_get_cid(p_hwfn);
1204         init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1205         init_data.comp_mode = comp_mode;
1206         init_data.p_comp_data = p_comp_data;
1207
1208         rc = qed_sp_init_request(p_hwfn, &p_ent,
1209                                  ETH_RAMROD_VPORT_UPDATE,
1210                                  PROTOCOLID_ETH, &init_data);
1211         if (rc) {
1212                 DP_ERR(p_hwfn, "Multi-cast command failed %d\n", rc);
1213                 return rc;
1214         }
1215
1216         p_ramrod = &p_ent->ramrod.vport_update;
1217         p_ramrod->common.update_approx_mcast_flg = 1;
1218
1219         /* explicitly clear out the entire vector */
1220         memset(&p_ramrod->approx_mcast.bins, 0,
1221                sizeof(p_ramrod->approx_mcast.bins));
1222         memset(bins, 0, sizeof(bins));
1223         /* filter ADD op is explicit set op and it removes
1224          *  any existing filters for the vport
1225          */
1226         if (p_filter_cmd->opcode == QED_FILTER_ADD) {
1227                 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1228                         u32 bit, nbits;
1229
1230                         bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1231                         nbits = sizeof(u32) * BITS_PER_BYTE;
1232                         bins[bit / nbits] |= 1 << (bit % nbits);
1233                 }
1234
1235                 /* Convert to correct endianity */
1236                 for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
1237                         struct vport_update_ramrod_mcast *p_ramrod_bins;
1238
1239                         p_ramrod_bins = &p_ramrod->approx_mcast;
1240                         p_ramrod_bins->bins[i] = cpu_to_le32(bins[i]);
1241                 }
1242         }
1243
1244         p_ramrod->common.vport_id = abs_vport_id;
1245
1246         return qed_spq_post(p_hwfn, p_ent, NULL);
1247 }
1248
1249 static int qed_filter_mcast_cmd(struct qed_dev *cdev,
1250                                 struct qed_filter_mcast *p_filter_cmd,
1251                                 enum spq_mode comp_mode,
1252                                 struct qed_spq_comp_cb *p_comp_data)
1253 {
1254         int rc = 0;
1255         int i;
1256
1257         /* only ADD and REMOVE operations are supported for multi-cast */
1258         if ((p_filter_cmd->opcode != QED_FILTER_ADD &&
1259              (p_filter_cmd->opcode != QED_FILTER_REMOVE)) ||
1260             (p_filter_cmd->num_mc_addrs > QED_MAX_MC_ADDRS))
1261                 return -EINVAL;
1262
1263         for_each_hwfn(cdev, i) {
1264                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1265
1266                 u16 opaque_fid;
1267
1268                 if (IS_VF(cdev)) {
1269                         qed_vf_pf_filter_mcast(p_hwfn, p_filter_cmd);
1270                         continue;
1271                 }
1272
1273                 opaque_fid = p_hwfn->hw_info.opaque_fid;
1274
1275                 rc = qed_sp_eth_filter_mcast(p_hwfn,
1276                                              opaque_fid,
1277                                              p_filter_cmd,
1278                                              comp_mode, p_comp_data);
1279         }
1280         return rc;
1281 }
1282
1283 static int qed_filter_ucast_cmd(struct qed_dev *cdev,
1284                                 struct qed_filter_ucast *p_filter_cmd,
1285                                 enum spq_mode comp_mode,
1286                                 struct qed_spq_comp_cb *p_comp_data)
1287 {
1288         int rc = 0;
1289         int i;
1290
1291         for_each_hwfn(cdev, i) {
1292                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1293                 u16 opaque_fid;
1294
1295                 if (IS_VF(cdev)) {
1296                         rc = qed_vf_pf_filter_ucast(p_hwfn, p_filter_cmd);
1297                         continue;
1298                 }
1299
1300                 opaque_fid = p_hwfn->hw_info.opaque_fid;
1301
1302                 rc = qed_sp_eth_filter_ucast(p_hwfn,
1303                                              opaque_fid,
1304                                              p_filter_cmd,
1305                                              comp_mode, p_comp_data);
1306                 if (rc)
1307                         break;
1308         }
1309
1310         return rc;
1311 }
1312
1313 /* Statistics related code */
1314 static void __qed_get_vport_pstats_addrlen(struct qed_hwfn *p_hwfn,
1315                                            u32 *p_addr,
1316                                            u32 *p_len, u16 statistics_bin)
1317 {
1318         if (IS_PF(p_hwfn->cdev)) {
1319                 *p_addr = BAR0_MAP_REG_PSDM_RAM +
1320                     PSTORM_QUEUE_STAT_OFFSET(statistics_bin);
1321                 *p_len = sizeof(struct eth_pstorm_per_queue_stat);
1322         } else {
1323                 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1324                 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1325
1326                 *p_addr = p_resp->pfdev_info.stats_info.pstats.address;
1327                 *p_len = p_resp->pfdev_info.stats_info.pstats.len;
1328         }
1329 }
1330
1331 static noinline_for_stack void
1332 __qed_get_vport_pstats(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1333                        struct qed_eth_stats *p_stats, u16 statistics_bin)
1334 {
1335         struct eth_pstorm_per_queue_stat pstats;
1336         u32 pstats_addr = 0, pstats_len = 0;
1337
1338         __qed_get_vport_pstats_addrlen(p_hwfn, &pstats_addr, &pstats_len,
1339                                        statistics_bin);
1340
1341         memset(&pstats, 0, sizeof(pstats));
1342         qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, pstats_len);
1343
1344         p_stats->tx_ucast_bytes += HILO_64_REGPAIR(pstats.sent_ucast_bytes);
1345         p_stats->tx_mcast_bytes += HILO_64_REGPAIR(pstats.sent_mcast_bytes);
1346         p_stats->tx_bcast_bytes += HILO_64_REGPAIR(pstats.sent_bcast_bytes);
1347         p_stats->tx_ucast_pkts += HILO_64_REGPAIR(pstats.sent_ucast_pkts);
1348         p_stats->tx_mcast_pkts += HILO_64_REGPAIR(pstats.sent_mcast_pkts);
1349         p_stats->tx_bcast_pkts += HILO_64_REGPAIR(pstats.sent_bcast_pkts);
1350         p_stats->tx_err_drop_pkts += HILO_64_REGPAIR(pstats.error_drop_pkts);
1351 }
1352
1353 static noinline_for_stack void
1354 __qed_get_vport_tstats(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1355                        struct qed_eth_stats *p_stats, u16 statistics_bin)
1356 {
1357         struct tstorm_per_port_stat tstats;
1358         u32 tstats_addr, tstats_len;
1359
1360         if (IS_PF(p_hwfn->cdev)) {
1361                 tstats_addr = BAR0_MAP_REG_TSDM_RAM +
1362                     TSTORM_PORT_STAT_OFFSET(MFW_PORT(p_hwfn));
1363                 tstats_len = sizeof(struct tstorm_per_port_stat);
1364         } else {
1365                 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1366                 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1367
1368                 tstats_addr = p_resp->pfdev_info.stats_info.tstats.address;
1369                 tstats_len = p_resp->pfdev_info.stats_info.tstats.len;
1370         }
1371
1372         memset(&tstats, 0, sizeof(tstats));
1373         qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, tstats_len);
1374
1375         p_stats->mftag_filter_discards +=
1376                 HILO_64_REGPAIR(tstats.mftag_filter_discard);
1377         p_stats->mac_filter_discards +=
1378                 HILO_64_REGPAIR(tstats.eth_mac_filter_discard);
1379 }
1380
1381 static void __qed_get_vport_ustats_addrlen(struct qed_hwfn *p_hwfn,
1382                                            u32 *p_addr,
1383                                            u32 *p_len, u16 statistics_bin)
1384 {
1385         if (IS_PF(p_hwfn->cdev)) {
1386                 *p_addr = BAR0_MAP_REG_USDM_RAM +
1387                     USTORM_QUEUE_STAT_OFFSET(statistics_bin);
1388                 *p_len = sizeof(struct eth_ustorm_per_queue_stat);
1389         } else {
1390                 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1391                 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1392
1393                 *p_addr = p_resp->pfdev_info.stats_info.ustats.address;
1394                 *p_len = p_resp->pfdev_info.stats_info.ustats.len;
1395         }
1396 }
1397
1398 static noinline_for_stack
1399 void __qed_get_vport_ustats(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1400                             struct qed_eth_stats *p_stats, u16 statistics_bin)
1401 {
1402         struct eth_ustorm_per_queue_stat ustats;
1403         u32 ustats_addr = 0, ustats_len = 0;
1404
1405         __qed_get_vport_ustats_addrlen(p_hwfn, &ustats_addr, &ustats_len,
1406                                        statistics_bin);
1407
1408         memset(&ustats, 0, sizeof(ustats));
1409         qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, ustats_len);
1410
1411         p_stats->rx_ucast_bytes += HILO_64_REGPAIR(ustats.rcv_ucast_bytes);
1412         p_stats->rx_mcast_bytes += HILO_64_REGPAIR(ustats.rcv_mcast_bytes);
1413         p_stats->rx_bcast_bytes += HILO_64_REGPAIR(ustats.rcv_bcast_bytes);
1414         p_stats->rx_ucast_pkts += HILO_64_REGPAIR(ustats.rcv_ucast_pkts);
1415         p_stats->rx_mcast_pkts += HILO_64_REGPAIR(ustats.rcv_mcast_pkts);
1416         p_stats->rx_bcast_pkts += HILO_64_REGPAIR(ustats.rcv_bcast_pkts);
1417 }
1418
1419 static void __qed_get_vport_mstats_addrlen(struct qed_hwfn *p_hwfn,
1420                                            u32 *p_addr,
1421                                            u32 *p_len, u16 statistics_bin)
1422 {
1423         if (IS_PF(p_hwfn->cdev)) {
1424                 *p_addr = BAR0_MAP_REG_MSDM_RAM +
1425                     MSTORM_QUEUE_STAT_OFFSET(statistics_bin);
1426                 *p_len = sizeof(struct eth_mstorm_per_queue_stat);
1427         } else {
1428                 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1429                 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1430
1431                 *p_addr = p_resp->pfdev_info.stats_info.mstats.address;
1432                 *p_len = p_resp->pfdev_info.stats_info.mstats.len;
1433         }
1434 }
1435
1436 static noinline_for_stack void
1437 __qed_get_vport_mstats(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1438                        struct qed_eth_stats *p_stats, u16 statistics_bin)
1439 {
1440         struct eth_mstorm_per_queue_stat mstats;
1441         u32 mstats_addr = 0, mstats_len = 0;
1442
1443         __qed_get_vport_mstats_addrlen(p_hwfn, &mstats_addr, &mstats_len,
1444                                        statistics_bin);
1445
1446         memset(&mstats, 0, sizeof(mstats));
1447         qed_memcpy_from(p_hwfn, p_ptt, &mstats, mstats_addr, mstats_len);
1448
1449         p_stats->no_buff_discards += HILO_64_REGPAIR(mstats.no_buff_discard);
1450         p_stats->packet_too_big_discard +=
1451                 HILO_64_REGPAIR(mstats.packet_too_big_discard);
1452         p_stats->ttl0_discard += HILO_64_REGPAIR(mstats.ttl0_discard);
1453         p_stats->tpa_coalesced_pkts +=
1454                 HILO_64_REGPAIR(mstats.tpa_coalesced_pkts);
1455         p_stats->tpa_coalesced_events +=
1456                 HILO_64_REGPAIR(mstats.tpa_coalesced_events);
1457         p_stats->tpa_aborts_num += HILO_64_REGPAIR(mstats.tpa_aborts_num);
1458         p_stats->tpa_coalesced_bytes +=
1459                 HILO_64_REGPAIR(mstats.tpa_coalesced_bytes);
1460 }
1461
1462 static noinline_for_stack void
1463 __qed_get_vport_port_stats(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1464                            struct qed_eth_stats *p_stats)
1465 {
1466         struct port_stats port_stats;
1467         int j;
1468
1469         memset(&port_stats, 0, sizeof(port_stats));
1470
1471         qed_memcpy_from(p_hwfn, p_ptt, &port_stats,
1472                         p_hwfn->mcp_info->port_addr +
1473                         offsetof(struct public_port, stats),
1474                         sizeof(port_stats));
1475
1476         p_stats->rx_64_byte_packets             += port_stats.eth.r64;
1477         p_stats->rx_65_to_127_byte_packets      += port_stats.eth.r127;
1478         p_stats->rx_128_to_255_byte_packets     += port_stats.eth.r255;
1479         p_stats->rx_256_to_511_byte_packets     += port_stats.eth.r511;
1480         p_stats->rx_512_to_1023_byte_packets    += port_stats.eth.r1023;
1481         p_stats->rx_1024_to_1518_byte_packets   += port_stats.eth.r1518;
1482         p_stats->rx_1519_to_1522_byte_packets   += port_stats.eth.r1522;
1483         p_stats->rx_1519_to_2047_byte_packets   += port_stats.eth.r2047;
1484         p_stats->rx_2048_to_4095_byte_packets   += port_stats.eth.r4095;
1485         p_stats->rx_4096_to_9216_byte_packets   += port_stats.eth.r9216;
1486         p_stats->rx_9217_to_16383_byte_packets  += port_stats.eth.r16383;
1487         p_stats->rx_crc_errors                  += port_stats.eth.rfcs;
1488         p_stats->rx_mac_crtl_frames             += port_stats.eth.rxcf;
1489         p_stats->rx_pause_frames                += port_stats.eth.rxpf;
1490         p_stats->rx_pfc_frames                  += port_stats.eth.rxpp;
1491         p_stats->rx_align_errors                += port_stats.eth.raln;
1492         p_stats->rx_carrier_errors              += port_stats.eth.rfcr;
1493         p_stats->rx_oversize_packets            += port_stats.eth.rovr;
1494         p_stats->rx_jabbers                     += port_stats.eth.rjbr;
1495         p_stats->rx_undersize_packets           += port_stats.eth.rund;
1496         p_stats->rx_fragments                   += port_stats.eth.rfrg;
1497         p_stats->tx_64_byte_packets             += port_stats.eth.t64;
1498         p_stats->tx_65_to_127_byte_packets      += port_stats.eth.t127;
1499         p_stats->tx_128_to_255_byte_packets     += port_stats.eth.t255;
1500         p_stats->tx_256_to_511_byte_packets     += port_stats.eth.t511;
1501         p_stats->tx_512_to_1023_byte_packets    += port_stats.eth.t1023;
1502         p_stats->tx_1024_to_1518_byte_packets   += port_stats.eth.t1518;
1503         p_stats->tx_1519_to_2047_byte_packets   += port_stats.eth.t2047;
1504         p_stats->tx_2048_to_4095_byte_packets   += port_stats.eth.t4095;
1505         p_stats->tx_4096_to_9216_byte_packets   += port_stats.eth.t9216;
1506         p_stats->tx_9217_to_16383_byte_packets  += port_stats.eth.t16383;
1507         p_stats->tx_pause_frames                += port_stats.eth.txpf;
1508         p_stats->tx_pfc_frames                  += port_stats.eth.txpp;
1509         p_stats->tx_lpi_entry_count             += port_stats.eth.tlpiec;
1510         p_stats->tx_total_collisions            += port_stats.eth.tncl;
1511         p_stats->rx_mac_bytes                   += port_stats.eth.rbyte;
1512         p_stats->rx_mac_uc_packets              += port_stats.eth.rxuca;
1513         p_stats->rx_mac_mc_packets              += port_stats.eth.rxmca;
1514         p_stats->rx_mac_bc_packets              += port_stats.eth.rxbca;
1515         p_stats->rx_mac_frames_ok               += port_stats.eth.rxpok;
1516         p_stats->tx_mac_bytes                   += port_stats.eth.tbyte;
1517         p_stats->tx_mac_uc_packets              += port_stats.eth.txuca;
1518         p_stats->tx_mac_mc_packets              += port_stats.eth.txmca;
1519         p_stats->tx_mac_bc_packets              += port_stats.eth.txbca;
1520         p_stats->tx_mac_ctrl_frames             += port_stats.eth.txcf;
1521         for (j = 0; j < 8; j++) {
1522                 p_stats->brb_truncates  += port_stats.brb.brb_truncate[j];
1523                 p_stats->brb_discards   += port_stats.brb.brb_discard[j];
1524         }
1525 }
1526
1527 static void __qed_get_vport_stats(struct qed_hwfn *p_hwfn,
1528                                   struct qed_ptt *p_ptt,
1529                                   struct qed_eth_stats *stats,
1530                                   u16 statistics_bin, bool b_get_port_stats)
1531 {
1532         __qed_get_vport_mstats(p_hwfn, p_ptt, stats, statistics_bin);
1533         __qed_get_vport_ustats(p_hwfn, p_ptt, stats, statistics_bin);
1534         __qed_get_vport_tstats(p_hwfn, p_ptt, stats, statistics_bin);
1535         __qed_get_vport_pstats(p_hwfn, p_ptt, stats, statistics_bin);
1536
1537         if (b_get_port_stats && p_hwfn->mcp_info)
1538                 __qed_get_vport_port_stats(p_hwfn, p_ptt, stats);
1539 }
1540
1541 static void _qed_get_vport_stats(struct qed_dev *cdev,
1542                                  struct qed_eth_stats *stats)
1543 {
1544         u8 fw_vport = 0;
1545         int i;
1546
1547         memset(stats, 0, sizeof(*stats));
1548
1549         for_each_hwfn(cdev, i) {
1550                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1551                 struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
1552                                                     :  NULL;
1553
1554                 if (IS_PF(cdev)) {
1555                         /* The main vport index is relative first */
1556                         if (qed_fw_vport(p_hwfn, 0, &fw_vport)) {
1557                                 DP_ERR(p_hwfn, "No vport available!\n");
1558                                 goto out;
1559                         }
1560                 }
1561
1562                 if (IS_PF(cdev) && !p_ptt) {
1563                         DP_ERR(p_hwfn, "Failed to acquire ptt\n");
1564                         continue;
1565                 }
1566
1567                 __qed_get_vport_stats(p_hwfn, p_ptt, stats, fw_vport,
1568                                       IS_PF(cdev) ? true : false);
1569
1570 out:
1571                 if (IS_PF(cdev) && p_ptt)
1572                         qed_ptt_release(p_hwfn, p_ptt);
1573         }
1574 }
1575
1576 void qed_get_vport_stats(struct qed_dev *cdev, struct qed_eth_stats *stats)
1577 {
1578         u32 i;
1579
1580         if (!cdev) {
1581                 memset(stats, 0, sizeof(*stats));
1582                 return;
1583         }
1584
1585         _qed_get_vport_stats(cdev, stats);
1586
1587         if (!cdev->reset_stats)
1588                 return;
1589
1590         /* Reduce the statistics baseline */
1591         for (i = 0; i < sizeof(struct qed_eth_stats) / sizeof(u64); i++)
1592                 ((u64 *)stats)[i] -= ((u64 *)cdev->reset_stats)[i];
1593 }
1594
1595 /* zeroes V-PORT specific portion of stats (Port stats remains untouched) */
1596 void qed_reset_vport_stats(struct qed_dev *cdev)
1597 {
1598         int i;
1599
1600         for_each_hwfn(cdev, i) {
1601                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1602                 struct eth_mstorm_per_queue_stat mstats;
1603                 struct eth_ustorm_per_queue_stat ustats;
1604                 struct eth_pstorm_per_queue_stat pstats;
1605                 struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
1606                                                     : NULL;
1607                 u32 addr = 0, len = 0;
1608
1609                 if (IS_PF(cdev) && !p_ptt) {
1610                         DP_ERR(p_hwfn, "Failed to acquire ptt\n");
1611                         continue;
1612                 }
1613
1614                 memset(&mstats, 0, sizeof(mstats));
1615                 __qed_get_vport_mstats_addrlen(p_hwfn, &addr, &len, 0);
1616                 qed_memcpy_to(p_hwfn, p_ptt, addr, &mstats, len);
1617
1618                 memset(&ustats, 0, sizeof(ustats));
1619                 __qed_get_vport_ustats_addrlen(p_hwfn, &addr, &len, 0);
1620                 qed_memcpy_to(p_hwfn, p_ptt, addr, &ustats, len);
1621
1622                 memset(&pstats, 0, sizeof(pstats));
1623                 __qed_get_vport_pstats_addrlen(p_hwfn, &addr, &len, 0);
1624                 qed_memcpy_to(p_hwfn, p_ptt, addr, &pstats, len);
1625
1626                 if (IS_PF(cdev))
1627                         qed_ptt_release(p_hwfn, p_ptt);
1628         }
1629
1630         /* PORT statistics are not necessarily reset, so we need to
1631          * read and create a baseline for future statistics.
1632          */
1633         if (!cdev->reset_stats)
1634                 DP_INFO(cdev, "Reset stats not allocated\n");
1635         else
1636                 _qed_get_vport_stats(cdev, cdev->reset_stats);
1637 }
1638
1639 static int qed_fill_eth_dev_info(struct qed_dev *cdev,
1640                                  struct qed_dev_eth_info *info)
1641 {
1642         int i;
1643
1644         memset(info, 0, sizeof(*info));
1645
1646         info->num_tc = 1;
1647
1648         if (IS_PF(cdev)) {
1649                 int max_vf_vlan_filters = 0;
1650
1651                 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
1652                         for_each_hwfn(cdev, i)
1653                             info->num_queues +=
1654                             FEAT_NUM(&cdev->hwfns[i], QED_PF_L2_QUE);
1655                         if (cdev->int_params.fp_msix_cnt)
1656                                 info->num_queues =
1657                                     min_t(u8, info->num_queues,
1658                                           cdev->int_params.fp_msix_cnt);
1659                 } else {
1660                         info->num_queues = cdev->num_hwfns;
1661                 }
1662
1663                 if (IS_QED_SRIOV(cdev))
1664                         max_vf_vlan_filters = cdev->p_iov_info->total_vfs *
1665                                               QED_ETH_VF_NUM_VLAN_FILTERS;
1666                 info->num_vlan_filters = RESC_NUM(&cdev->hwfns[0], QED_VLAN) -
1667                                          max_vf_vlan_filters;
1668
1669                 ether_addr_copy(info->port_mac,
1670                                 cdev->hwfns[0].hw_info.hw_mac_addr);
1671         } else {
1672                 qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev), &info->num_queues);
1673                 if (cdev->num_hwfns > 1) {
1674                         u8 queues = 0;
1675
1676                         qed_vf_get_num_rxqs(&cdev->hwfns[1], &queues);
1677                         info->num_queues += queues;
1678                 }
1679
1680                 qed_vf_get_num_vlan_filters(&cdev->hwfns[0],
1681                                             &info->num_vlan_filters);
1682                 qed_vf_get_port_mac(&cdev->hwfns[0], info->port_mac);
1683
1684                 info->is_legacy = !!cdev->hwfns[0].vf_iov_info->b_pre_fp_hsi;
1685         }
1686
1687         qed_fill_dev_info(cdev, &info->common);
1688
1689         if (IS_VF(cdev))
1690                 memset(info->common.hw_mac, 0, ETH_ALEN);
1691
1692         return 0;
1693 }
1694
1695 static void qed_register_eth_ops(struct qed_dev *cdev,
1696                                  struct qed_eth_cb_ops *ops, void *cookie)
1697 {
1698         cdev->protocol_ops.eth = ops;
1699         cdev->ops_cookie = cookie;
1700
1701         /* For VF, we start bulletin reading */
1702         if (IS_VF(cdev))
1703                 qed_vf_start_iov_wq(cdev);
1704 }
1705
1706 static bool qed_check_mac(struct qed_dev *cdev, u8 *mac)
1707 {
1708         if (IS_PF(cdev))
1709                 return true;
1710
1711         return qed_vf_check_mac(&cdev->hwfns[0], mac);
1712 }
1713
1714 static int qed_start_vport(struct qed_dev *cdev,
1715                            struct qed_start_vport_params *params)
1716 {
1717         int rc, i;
1718
1719         for_each_hwfn(cdev, i) {
1720                 struct qed_sp_vport_start_params start = { 0 };
1721                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1722
1723                 start.tpa_mode = params->gro_enable ? QED_TPA_MODE_GRO :
1724                                                         QED_TPA_MODE_NONE;
1725                 start.remove_inner_vlan = params->remove_inner_vlan;
1726                 start.only_untagged = true;     /* untagged only */
1727                 start.drop_ttl0 = params->drop_ttl0;
1728                 start.opaque_fid = p_hwfn->hw_info.opaque_fid;
1729                 start.concrete_fid = p_hwfn->hw_info.concrete_fid;
1730                 start.vport_id = params->vport_id;
1731                 start.max_buffers_per_cqe = 16;
1732                 start.mtu = params->mtu;
1733
1734                 rc = qed_sp_vport_start(p_hwfn, &start);
1735                 if (rc) {
1736                         DP_ERR(cdev, "Failed to start VPORT\n");
1737                         return rc;
1738                 }
1739
1740                 qed_hw_start_fastpath(p_hwfn);
1741
1742                 DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
1743                            "Started V-PORT %d with MTU %d\n",
1744                            start.vport_id, start.mtu);
1745         }
1746
1747         if (params->clear_stats)
1748                 qed_reset_vport_stats(cdev);
1749
1750         return 0;
1751 }
1752
1753 static int qed_stop_vport(struct qed_dev *cdev, u8 vport_id)
1754 {
1755         int rc, i;
1756
1757         for_each_hwfn(cdev, i) {
1758                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1759
1760                 rc = qed_sp_vport_stop(p_hwfn,
1761                                        p_hwfn->hw_info.opaque_fid, vport_id);
1762
1763                 if (rc) {
1764                         DP_ERR(cdev, "Failed to stop VPORT\n");
1765                         return rc;
1766                 }
1767         }
1768         return 0;
1769 }
1770
1771 static int qed_update_vport(struct qed_dev *cdev,
1772                             struct qed_update_vport_params *params)
1773 {
1774         struct qed_sp_vport_update_params sp_params;
1775         struct qed_rss_params sp_rss_params;
1776         int rc, i;
1777
1778         if (!cdev)
1779                 return -ENODEV;
1780
1781         memset(&sp_params, 0, sizeof(sp_params));
1782         memset(&sp_rss_params, 0, sizeof(sp_rss_params));
1783
1784         /* Translate protocol params into sp params */
1785         sp_params.vport_id = params->vport_id;
1786         sp_params.update_vport_active_rx_flg = params->update_vport_active_flg;
1787         sp_params.update_vport_active_tx_flg = params->update_vport_active_flg;
1788         sp_params.vport_active_rx_flg = params->vport_active_flg;
1789         sp_params.vport_active_tx_flg = params->vport_active_flg;
1790         sp_params.update_tx_switching_flg = params->update_tx_switching_flg;
1791         sp_params.tx_switching_flg = params->tx_switching_flg;
1792         sp_params.accept_any_vlan = params->accept_any_vlan;
1793         sp_params.update_accept_any_vlan_flg =
1794                 params->update_accept_any_vlan_flg;
1795
1796         /* RSS - is a bit tricky, since upper-layer isn't familiar with hwfns.
1797          * We need to re-fix the rss values per engine for CMT.
1798          */
1799         if (cdev->num_hwfns > 1 && params->update_rss_flg) {
1800                 struct qed_update_vport_rss_params *rss = &params->rss_params;
1801                 int k, max = 0;
1802
1803                 /* Find largest entry, since it's possible RSS needs to
1804                  * be disabled [in case only 1 queue per-hwfn]
1805                  */
1806                 for (k = 0; k < QED_RSS_IND_TABLE_SIZE; k++)
1807                         max = (max > rss->rss_ind_table[k]) ?
1808                                 max : rss->rss_ind_table[k];
1809
1810                 /* Either fix RSS values or disable RSS */
1811                 if (cdev->num_hwfns < max + 1) {
1812                         int divisor = (max + cdev->num_hwfns - 1) /
1813                                 cdev->num_hwfns;
1814
1815                         DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
1816                                    "CMT - fixing RSS values (modulo %02x)\n",
1817                                    divisor);
1818
1819                         for (k = 0; k < QED_RSS_IND_TABLE_SIZE; k++)
1820                                 rss->rss_ind_table[k] =
1821                                         rss->rss_ind_table[k] % divisor;
1822                 } else {
1823                         DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
1824                                    "CMT - 1 queue per-hwfn; Disabling RSS\n");
1825                         params->update_rss_flg = 0;
1826                 }
1827         }
1828
1829         /* Now, update the RSS configuration for actual configuration */
1830         if (params->update_rss_flg) {
1831                 sp_rss_params.update_rss_config = 1;
1832                 sp_rss_params.rss_enable = 1;
1833                 sp_rss_params.update_rss_capabilities = 1;
1834                 sp_rss_params.update_rss_ind_table = 1;
1835                 sp_rss_params.update_rss_key = 1;
1836                 sp_rss_params.rss_caps = params->rss_params.rss_caps;
1837                 sp_rss_params.rss_table_size_log = 7; /* 2^7 = 128 */
1838                 memcpy(sp_rss_params.rss_ind_table,
1839                        params->rss_params.rss_ind_table,
1840                        QED_RSS_IND_TABLE_SIZE * sizeof(u16));
1841                 memcpy(sp_rss_params.rss_key, params->rss_params.rss_key,
1842                        QED_RSS_KEY_SIZE * sizeof(u32));
1843                 sp_params.rss_params = &sp_rss_params;
1844         }
1845
1846         for_each_hwfn(cdev, i) {
1847                 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1848
1849                 sp_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
1850                 rc = qed_sp_vport_update(p_hwfn, &sp_params,
1851                                          QED_SPQ_MODE_EBLOCK,
1852                                          NULL);
1853                 if (rc) {
1854                         DP_ERR(cdev, "Failed to update VPORT\n");
1855                         return rc;
1856                 }
1857
1858                 DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
1859                            "Updated V-PORT %d: active_flag %d [update %d]\n",
1860                            params->vport_id, params->vport_active_flg,
1861                            params->update_vport_active_flg);
1862         }
1863
1864         return 0;
1865 }
1866
1867 static int qed_start_rxq(struct qed_dev *cdev,
1868                          struct qed_queue_start_common_params *params,
1869                          u16 bd_max_bytes,
1870                          dma_addr_t bd_chain_phys_addr,
1871                          dma_addr_t cqe_pbl_addr,
1872                          u16 cqe_pbl_size,
1873                          void __iomem **pp_prod)
1874 {
1875         struct qed_hwfn *p_hwfn;
1876         int rc, hwfn_index;
1877
1878         hwfn_index = params->rss_id % cdev->num_hwfns;
1879         p_hwfn = &cdev->hwfns[hwfn_index];
1880
1881         /* Fix queue ID in 100g mode */
1882         params->queue_id /= cdev->num_hwfns;
1883
1884         rc = qed_sp_eth_rx_queue_start(p_hwfn,
1885                                        p_hwfn->hw_info.opaque_fid,
1886                                        params,
1887                                        bd_max_bytes,
1888                                        bd_chain_phys_addr,
1889                                        cqe_pbl_addr,
1890                                        cqe_pbl_size,
1891                                        pp_prod);
1892
1893         if (rc) {
1894                 DP_ERR(cdev, "Failed to start RXQ#%d\n", params->queue_id);
1895                 return rc;
1896         }
1897
1898         DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
1899                    "Started RX-Q %d [rss %d] on V-PORT %d and SB %d\n",
1900                    params->queue_id, params->rss_id, params->vport_id,
1901                    params->sb);
1902
1903         return 0;
1904 }
1905
1906 static int qed_stop_rxq(struct qed_dev *cdev,
1907                         struct qed_stop_rxq_params *params)
1908 {
1909         int rc, hwfn_index;
1910         struct qed_hwfn *p_hwfn;
1911
1912         hwfn_index      = params->rss_id % cdev->num_hwfns;
1913         p_hwfn          = &cdev->hwfns[hwfn_index];
1914
1915         rc = qed_sp_eth_rx_queue_stop(p_hwfn,
1916                                       params->rx_queue_id / cdev->num_hwfns,
1917                                       params->eq_completion_only, false);
1918         if (rc) {
1919                 DP_ERR(cdev, "Failed to stop RXQ#%d\n", params->rx_queue_id);
1920                 return rc;
1921         }
1922
1923         return 0;
1924 }
1925
1926 static int qed_start_txq(struct qed_dev *cdev,
1927                          struct qed_queue_start_common_params *p_params,
1928                          dma_addr_t pbl_addr,
1929                          u16 pbl_size,
1930                          void __iomem **pp_doorbell)
1931 {
1932         struct qed_hwfn *p_hwfn;
1933         int rc, hwfn_index;
1934
1935         hwfn_index      = p_params->rss_id % cdev->num_hwfns;
1936         p_hwfn          = &cdev->hwfns[hwfn_index];
1937
1938         /* Fix queue ID in 100g mode */
1939         p_params->queue_id /= cdev->num_hwfns;
1940
1941         rc = qed_sp_eth_tx_queue_start(p_hwfn,
1942                                        p_hwfn->hw_info.opaque_fid,
1943                                        p_params,
1944                                        pbl_addr,
1945                                        pbl_size,
1946                                        pp_doorbell);
1947
1948         if (rc) {
1949                 DP_ERR(cdev, "Failed to start TXQ#%d\n", p_params->queue_id);
1950                 return rc;
1951         }
1952
1953         DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
1954                    "Started TX-Q %d [rss %d] on V-PORT %d and SB %d\n",
1955                    p_params->queue_id, p_params->rss_id, p_params->vport_id,
1956                    p_params->sb);
1957
1958         return 0;
1959 }
1960
1961 #define QED_HW_STOP_RETRY_LIMIT (10)
1962 static int qed_fastpath_stop(struct qed_dev *cdev)
1963 {
1964         qed_hw_stop_fastpath(cdev);
1965
1966         return 0;
1967 }
1968
1969 static int qed_stop_txq(struct qed_dev *cdev,
1970                         struct qed_stop_txq_params *params)
1971 {
1972         struct qed_hwfn *p_hwfn;
1973         int rc, hwfn_index;
1974
1975         hwfn_index      = params->rss_id % cdev->num_hwfns;
1976         p_hwfn          = &cdev->hwfns[hwfn_index];
1977
1978         rc = qed_sp_eth_tx_queue_stop(p_hwfn,
1979                                       params->tx_queue_id / cdev->num_hwfns);
1980         if (rc) {
1981                 DP_ERR(cdev, "Failed to stop TXQ#%d\n", params->tx_queue_id);
1982                 return rc;
1983         }
1984
1985         return 0;
1986 }
1987
1988 static int qed_tunn_configure(struct qed_dev *cdev,
1989                               struct qed_tunn_params *tunn_params)
1990 {
1991         struct qed_tunn_update_params tunn_info;
1992         int i, rc;
1993
1994         if (IS_VF(cdev))
1995                 return 0;
1996
1997         memset(&tunn_info, 0, sizeof(tunn_info));
1998         if (tunn_params->update_vxlan_port == 1) {
1999                 tunn_info.update_vxlan_udp_port = 1;
2000                 tunn_info.vxlan_udp_port = tunn_params->vxlan_port;
2001         }
2002
2003         if (tunn_params->update_geneve_port == 1) {
2004                 tunn_info.update_geneve_udp_port = 1;
2005                 tunn_info.geneve_udp_port = tunn_params->geneve_port;
2006         }
2007
2008         for_each_hwfn(cdev, i) {
2009                 struct qed_hwfn *hwfn = &cdev->hwfns[i];
2010
2011                 rc = qed_sp_pf_update_tunn_cfg(hwfn, &tunn_info,
2012                                                QED_SPQ_MODE_EBLOCK, NULL);
2013
2014                 if (rc)
2015                         return rc;
2016         }
2017
2018         return 0;
2019 }
2020
2021 static int qed_configure_filter_rx_mode(struct qed_dev *cdev,
2022                                         enum qed_filter_rx_mode_type type)
2023 {
2024         struct qed_filter_accept_flags accept_flags;
2025
2026         memset(&accept_flags, 0, sizeof(accept_flags));
2027
2028         accept_flags.update_rx_mode_config = 1;
2029         accept_flags.update_tx_mode_config = 1;
2030         accept_flags.rx_accept_filter = QED_ACCEPT_UCAST_MATCHED |
2031                                         QED_ACCEPT_MCAST_MATCHED |
2032                                         QED_ACCEPT_BCAST;
2033         accept_flags.tx_accept_filter = QED_ACCEPT_UCAST_MATCHED |
2034                                         QED_ACCEPT_MCAST_MATCHED |
2035                                         QED_ACCEPT_BCAST;
2036
2037         if (type == QED_FILTER_RX_MODE_TYPE_PROMISC)
2038                 accept_flags.rx_accept_filter |= QED_ACCEPT_UCAST_UNMATCHED |
2039                                                  QED_ACCEPT_MCAST_UNMATCHED;
2040         else if (type == QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC)
2041                 accept_flags.rx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
2042
2043         return qed_filter_accept_cmd(cdev, 0, accept_flags, false, false,
2044                                      QED_SPQ_MODE_CB, NULL);
2045 }
2046
2047 static int qed_configure_filter_ucast(struct qed_dev *cdev,
2048                                       struct qed_filter_ucast_params *params)
2049 {
2050         struct qed_filter_ucast ucast;
2051
2052         if (!params->vlan_valid && !params->mac_valid) {
2053                 DP_NOTICE(cdev,
2054                           "Tried configuring a unicast filter, but both MAC and VLAN are not set\n");
2055                 return -EINVAL;
2056         }
2057
2058         memset(&ucast, 0, sizeof(ucast));
2059         switch (params->type) {
2060         case QED_FILTER_XCAST_TYPE_ADD:
2061                 ucast.opcode = QED_FILTER_ADD;
2062                 break;
2063         case QED_FILTER_XCAST_TYPE_DEL:
2064                 ucast.opcode = QED_FILTER_REMOVE;
2065                 break;
2066         case QED_FILTER_XCAST_TYPE_REPLACE:
2067                 ucast.opcode = QED_FILTER_REPLACE;
2068                 break;
2069         default:
2070                 DP_NOTICE(cdev, "Unknown unicast filter type %d\n",
2071                           params->type);
2072         }
2073
2074         if (params->vlan_valid && params->mac_valid) {
2075                 ucast.type = QED_FILTER_MAC_VLAN;
2076                 ether_addr_copy(ucast.mac, params->mac);
2077                 ucast.vlan = params->vlan;
2078         } else if (params->mac_valid) {
2079                 ucast.type = QED_FILTER_MAC;
2080                 ether_addr_copy(ucast.mac, params->mac);
2081         } else {
2082                 ucast.type = QED_FILTER_VLAN;
2083                 ucast.vlan = params->vlan;
2084         }
2085
2086         ucast.is_rx_filter = true;
2087         ucast.is_tx_filter = true;
2088
2089         return qed_filter_ucast_cmd(cdev, &ucast, QED_SPQ_MODE_CB, NULL);
2090 }
2091
2092 static int qed_configure_filter_mcast(struct qed_dev *cdev,
2093                                       struct qed_filter_mcast_params *params)
2094 {
2095         struct qed_filter_mcast mcast;
2096         int i;
2097
2098         memset(&mcast, 0, sizeof(mcast));
2099         switch (params->type) {
2100         case QED_FILTER_XCAST_TYPE_ADD:
2101                 mcast.opcode = QED_FILTER_ADD;
2102                 break;
2103         case QED_FILTER_XCAST_TYPE_DEL:
2104                 mcast.opcode = QED_FILTER_REMOVE;
2105                 break;
2106         default:
2107                 DP_NOTICE(cdev, "Unknown multicast filter type %d\n",
2108                           params->type);
2109         }
2110
2111         mcast.num_mc_addrs = params->num;
2112         for (i = 0; i < mcast.num_mc_addrs; i++)
2113                 ether_addr_copy(mcast.mac[i], params->mac[i]);
2114
2115         return qed_filter_mcast_cmd(cdev, &mcast, QED_SPQ_MODE_CB, NULL);
2116 }
2117
2118 static int qed_configure_filter(struct qed_dev *cdev,
2119                                 struct qed_filter_params *params)
2120 {
2121         enum qed_filter_rx_mode_type accept_flags;
2122
2123         switch (params->type) {
2124         case QED_FILTER_TYPE_UCAST:
2125                 return qed_configure_filter_ucast(cdev, &params->filter.ucast);
2126         case QED_FILTER_TYPE_MCAST:
2127                 return qed_configure_filter_mcast(cdev, &params->filter.mcast);
2128         case QED_FILTER_TYPE_RX_MODE:
2129                 accept_flags = params->filter.accept_flags;
2130                 return qed_configure_filter_rx_mode(cdev, accept_flags);
2131         default:
2132                 DP_NOTICE(cdev, "Unknown filter type %d\n", (int)params->type);
2133                 return -EINVAL;
2134         }
2135 }
2136
2137 static int qed_fp_cqe_completion(struct qed_dev *dev,
2138                                  u8 rss_id, struct eth_slow_path_rx_cqe *cqe)
2139 {
2140         return qed_eth_cqe_completion(&dev->hwfns[rss_id % dev->num_hwfns],
2141                                       cqe);
2142 }
2143
2144 #ifdef CONFIG_QED_SRIOV
2145 extern const struct qed_iov_hv_ops qed_iov_ops_pass;
2146 #endif
2147
2148 #ifdef CONFIG_DCB
2149 extern const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass;
2150 #endif
2151
2152 static const struct qed_eth_ops qed_eth_ops_pass = {
2153         .common = &qed_common_ops_pass,
2154 #ifdef CONFIG_QED_SRIOV
2155         .iov = &qed_iov_ops_pass,
2156 #endif
2157 #ifdef CONFIG_DCB
2158         .dcb = &qed_dcbnl_ops_pass,
2159 #endif
2160         .fill_dev_info = &qed_fill_eth_dev_info,
2161         .register_ops = &qed_register_eth_ops,
2162         .check_mac = &qed_check_mac,
2163         .vport_start = &qed_start_vport,
2164         .vport_stop = &qed_stop_vport,
2165         .vport_update = &qed_update_vport,
2166         .q_rx_start = &qed_start_rxq,
2167         .q_rx_stop = &qed_stop_rxq,
2168         .q_tx_start = &qed_start_txq,
2169         .q_tx_stop = &qed_stop_txq,
2170         .filter_config = &qed_configure_filter,
2171         .fastpath_stop = &qed_fastpath_stop,
2172         .eth_cqe_completion = &qed_fp_cqe_completion,
2173         .get_vport_stats = &qed_get_vport_stats,
2174         .tunn_config = &qed_tunn_configure,
2175 };
2176
2177 const struct qed_eth_ops *qed_get_eth_ops(void)
2178 {
2179         return &qed_eth_ops_pass;
2180 }
2181 EXPORT_SYMBOL(qed_get_eth_ops);
2182
2183 void qed_put_eth_ops(void)
2184 {
2185         /* TODO - reference count for module? */
2186 }
2187 EXPORT_SYMBOL(qed_put_eth_ops);