2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
12 #include "ecore_status.h"
13 #include "ecore_hsi_eth.h"
14 #include "ecore_chain.h"
15 #include "ecore_spq.h"
16 #include "ecore_init_fw_funcs.h"
17 #include "ecore_cxt.h"
19 #include "ecore_sp_commands.h"
20 #include "ecore_gtt_reg_addr.h"
21 #include "ecore_iro.h"
23 #include "ecore_int.h"
26 #include "ecore_sriov.h"
27 #include "ecore_mcp.h"
29 #define ECORE_MAX_SGES_NUM 16
30 #define CRC32_POLY 0x1edc6f41
32 void ecore_eth_queue_cid_release(struct ecore_hwfn *p_hwfn,
33 struct ecore_queue_cid *p_cid)
35 /* VFs' CIDs are 0-based in PF-view, and uninitialized on VF */
36 if (!p_cid->is_vf && IS_PF(p_hwfn->p_dev))
37 ecore_cxt_release_cid(p_hwfn, p_cid->cid);
38 OSAL_VFREE(p_hwfn->p_dev, p_cid);
41 /* The internal is only meant to be directly called by PFs initializeing CIDs
44 struct ecore_queue_cid *
45 _ecore_eth_queue_to_cid(struct ecore_hwfn *p_hwfn,
46 u16 opaque_fid, u32 cid, u8 vf_qid,
47 struct ecore_queue_start_common_params *p_params)
49 bool b_is_same = (p_hwfn->hw_info.opaque_fid == opaque_fid);
50 struct ecore_queue_cid *p_cid;
51 enum _ecore_status_t rc;
53 p_cid = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_cid));
54 if (p_cid == OSAL_NULL)
57 p_cid->opaque_fid = opaque_fid;
59 p_cid->vf_qid = vf_qid;
60 p_cid->rel = *p_params;
61 p_cid->p_owner = p_hwfn;
63 /* Don't try calculating the absolute indices for VFs */
64 if (IS_VF(p_hwfn->p_dev)) {
65 p_cid->abs = p_cid->rel;
69 /* Calculate the engine-absolute indices of the resources.
70 * The would guarantee they're valid later on.
71 * In some cases [SBs] we already have the right values.
73 rc = ecore_fw_vport(p_hwfn, p_cid->rel.vport_id, &p_cid->abs.vport_id);
74 if (rc != ECORE_SUCCESS)
77 rc = ecore_fw_l2_queue(p_hwfn, p_cid->rel.queue_id,
78 &p_cid->abs.queue_id);
79 if (rc != ECORE_SUCCESS)
82 /* In case of a PF configuring its VF's queues, the stats-id is already
83 * absolute [since there's a single index that's suitable per-VF].
86 rc = ecore_fw_vport(p_hwfn, p_cid->rel.stats_id,
87 &p_cid->abs.stats_id);
88 if (rc != ECORE_SUCCESS)
91 p_cid->abs.stats_id = p_cid->rel.stats_id;
94 /* SBs relevant information was already provided as absolute */
95 p_cid->abs.sb = p_cid->rel.sb;
96 p_cid->abs.sb_idx = p_cid->rel.sb_idx;
98 /* This is tricky - we're actually interested in whehter this is a PF
99 * entry meant for the VF.
104 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
105 "opaque_fid: %04x CID %08x vport %02x [%02x] qzone %04x [%04x] stats %02x [%02x] SB %04x PI %02x\n",
106 p_cid->opaque_fid, p_cid->cid,
107 p_cid->rel.vport_id, p_cid->abs.vport_id,
108 p_cid->rel.queue_id, p_cid->abs.queue_id,
109 p_cid->rel.stats_id, p_cid->abs.stats_id,
110 p_cid->abs.sb, p_cid->abs.sb_idx);
115 OSAL_VFREE(p_hwfn->p_dev, p_cid);
119 static struct ecore_queue_cid *
120 ecore_eth_queue_to_cid(struct ecore_hwfn *p_hwfn,
122 struct ecore_queue_start_common_params *p_params)
124 struct ecore_queue_cid *p_cid;
127 /* Get a unique firmware CID for this queue, in case it's a PF.
128 * VF's don't need a CID as the queue configuration will be done
131 if (IS_PF(p_hwfn->p_dev)) {
132 if (ecore_cxt_acquire_cid(p_hwfn, PROTOCOLID_ETH,
133 &cid) != ECORE_SUCCESS) {
134 DP_NOTICE(p_hwfn, true, "Failed to acquire cid\n");
139 p_cid = _ecore_eth_queue_to_cid(p_hwfn, opaque_fid, cid, 0, p_params);
140 if ((p_cid == OSAL_NULL) && IS_PF(p_hwfn->p_dev))
141 ecore_cxt_release_cid(p_hwfn, cid);
147 ecore_sp_eth_vport_start(struct ecore_hwfn *p_hwfn,
148 struct ecore_sp_vport_start_params *p_params)
150 struct vport_start_ramrod_data *p_ramrod = OSAL_NULL;
151 struct ecore_spq_entry *p_ent = OSAL_NULL;
152 struct ecore_sp_init_data init_data;
153 u16 rx_mode = 0, tx_err = 0;
155 enum _ecore_status_t rc = ECORE_NOTIMPL;
157 rc = ecore_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
158 if (rc != ECORE_SUCCESS)
162 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
163 init_data.cid = ecore_spq_get_cid(p_hwfn);
164 init_data.opaque_fid = p_params->opaque_fid;
165 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
167 rc = ecore_sp_init_request(p_hwfn, &p_ent,
168 ETH_RAMROD_VPORT_START,
169 PROTOCOLID_ETH, &init_data);
170 if (rc != ECORE_SUCCESS)
173 p_ramrod = &p_ent->ramrod.vport_start;
174 p_ramrod->vport_id = abs_vport_id;
176 p_ramrod->mtu = OSAL_CPU_TO_LE16(p_params->mtu);
177 p_ramrod->inner_vlan_removal_en = p_params->remove_inner_vlan;
178 p_ramrod->handle_ptp_pkts = p_params->handle_ptp_pkts;
179 p_ramrod->drop_ttl0_en = p_params->drop_ttl0;
180 p_ramrod->untagged = p_params->only_untagged;
181 p_ramrod->zero_placement_offset = p_params->zero_placement_offset;
183 SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_UCAST_DROP_ALL, 1);
184 SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_MCAST_DROP_ALL, 1);
186 p_ramrod->rx_mode.state = OSAL_CPU_TO_LE16(rx_mode);
188 /* Handle requests for strict behavior on transmission errors */
189 SET_FIELD(tx_err, ETH_TX_ERR_VALS_ILLEGAL_VLAN_MODE,
190 p_params->b_err_illegal_vlan_mode ?
191 ETH_TX_ERR_ASSERT_MALICIOUS : 0);
192 SET_FIELD(tx_err, ETH_TX_ERR_VALS_PACKET_TOO_SMALL,
193 p_params->b_err_small_pkt ?
194 ETH_TX_ERR_ASSERT_MALICIOUS : 0);
195 SET_FIELD(tx_err, ETH_TX_ERR_VALS_ANTI_SPOOFING_ERR,
196 p_params->b_err_anti_spoof ?
197 ETH_TX_ERR_ASSERT_MALICIOUS : 0);
198 SET_FIELD(tx_err, ETH_TX_ERR_VALS_ILLEGAL_INBAND_TAGS,
199 p_params->b_err_illegal_inband_mode ?
200 ETH_TX_ERR_ASSERT_MALICIOUS : 0);
201 SET_FIELD(tx_err, ETH_TX_ERR_VALS_VLAN_INSERTION_W_INBAND_TAG,
202 p_params->b_err_vlan_insert_with_inband ?
203 ETH_TX_ERR_ASSERT_MALICIOUS : 0);
204 SET_FIELD(tx_err, ETH_TX_ERR_VALS_MTU_VIOLATION,
205 p_params->b_err_big_pkt ?
206 ETH_TX_ERR_ASSERT_MALICIOUS : 0);
207 SET_FIELD(tx_err, ETH_TX_ERR_VALS_ILLEGAL_CONTROL_FRAME,
208 p_params->b_err_ctrl_frame ?
209 ETH_TX_ERR_ASSERT_MALICIOUS : 0);
210 p_ramrod->tx_err_behav.values = OSAL_CPU_TO_LE16(tx_err);
212 /* TPA related fields */
213 OSAL_MEMSET(&p_ramrod->tpa_param, 0,
214 sizeof(struct eth_vport_tpa_param));
215 p_ramrod->tpa_param.max_buff_num = p_params->max_buffers_per_cqe;
217 switch (p_params->tpa_mode) {
218 case ECORE_TPA_MODE_GRO:
219 p_ramrod->tpa_param.tpa_max_aggs_num = ETH_TPA_MAX_AGGS_NUM;
220 p_ramrod->tpa_param.tpa_max_size = (u16)-1;
221 p_ramrod->tpa_param.tpa_min_size_to_cont = p_params->mtu / 2;
222 p_ramrod->tpa_param.tpa_min_size_to_start = p_params->mtu / 2;
223 p_ramrod->tpa_param.tpa_ipv4_en_flg = 1;
224 p_ramrod->tpa_param.tpa_ipv6_en_flg = 1;
225 p_ramrod->tpa_param.tpa_ipv4_tunn_en_flg = 1;
226 p_ramrod->tpa_param.tpa_ipv6_tunn_en_flg = 1;
227 p_ramrod->tpa_param.tpa_pkt_split_flg = 1;
228 p_ramrod->tpa_param.tpa_gro_consistent_flg = 1;
234 p_ramrod->tx_switching_en = p_params->tx_switching;
236 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev))
237 p_ramrod->tx_switching_en = 0;
240 p_ramrod->ctl_frame_mac_check_en = !!p_params->check_mac;
241 p_ramrod->ctl_frame_ethtype_check_en = !!p_params->check_ethtype;
243 /* Software Function ID in hwfn (PFs are 0 - 15, VFs are 16 - 135) */
244 p_ramrod->sw_fid = ecore_concrete_to_sw_fid(p_hwfn->p_dev,
245 p_params->concrete_fid);
247 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
251 ecore_sp_vport_start(struct ecore_hwfn *p_hwfn,
252 struct ecore_sp_vport_start_params *p_params)
254 if (IS_VF(p_hwfn->p_dev))
255 return ecore_vf_pf_vport_start(p_hwfn, p_params->vport_id,
257 p_params->remove_inner_vlan,
259 p_params->max_buffers_per_cqe,
260 p_params->only_untagged);
262 return ecore_sp_eth_vport_start(p_hwfn, p_params);
265 static enum _ecore_status_t
266 ecore_sp_vport_update_rss(struct ecore_hwfn *p_hwfn,
267 struct vport_update_ramrod_data *p_ramrod,
268 struct ecore_rss_params *p_rss)
270 struct eth_vport_rss_config *p_config;
272 enum _ecore_status_t rc = ECORE_SUCCESS;
275 p_ramrod->common.update_rss_flg = 0;
278 p_config = &p_ramrod->rss_config;
280 OSAL_BUILD_BUG_ON(ECORE_RSS_IND_TABLE_SIZE !=
281 ETH_RSS_IND_TABLE_ENTRIES_NUM);
283 rc = ecore_fw_rss_eng(p_hwfn, p_rss->rss_eng_id, &p_config->rss_id);
284 if (rc != ECORE_SUCCESS)
287 p_ramrod->common.update_rss_flg = p_rss->update_rss_config;
288 p_config->update_rss_capabilities = p_rss->update_rss_capabilities;
289 p_config->update_rss_ind_table = p_rss->update_rss_ind_table;
290 p_config->update_rss_key = p_rss->update_rss_key;
292 p_config->rss_mode = p_rss->rss_enable ?
293 ETH_VPORT_RSS_MODE_REGULAR : ETH_VPORT_RSS_MODE_DISABLED;
295 p_config->capabilities = 0;
297 SET_FIELD(p_config->capabilities,
298 ETH_VPORT_RSS_CONFIG_IPV4_CAPABILITY,
299 !!(p_rss->rss_caps & ECORE_RSS_IPV4));
300 SET_FIELD(p_config->capabilities,
301 ETH_VPORT_RSS_CONFIG_IPV6_CAPABILITY,
302 !!(p_rss->rss_caps & ECORE_RSS_IPV6));
303 SET_FIELD(p_config->capabilities,
304 ETH_VPORT_RSS_CONFIG_IPV4_TCP_CAPABILITY,
305 !!(p_rss->rss_caps & ECORE_RSS_IPV4_TCP));
306 SET_FIELD(p_config->capabilities,
307 ETH_VPORT_RSS_CONFIG_IPV6_TCP_CAPABILITY,
308 !!(p_rss->rss_caps & ECORE_RSS_IPV6_TCP));
309 SET_FIELD(p_config->capabilities,
310 ETH_VPORT_RSS_CONFIG_IPV4_UDP_CAPABILITY,
311 !!(p_rss->rss_caps & ECORE_RSS_IPV4_UDP));
312 SET_FIELD(p_config->capabilities,
313 ETH_VPORT_RSS_CONFIG_IPV6_UDP_CAPABILITY,
314 !!(p_rss->rss_caps & ECORE_RSS_IPV6_UDP));
315 p_config->tbl_size = p_rss->rss_table_size_log;
316 p_config->capabilities = OSAL_CPU_TO_LE16(p_config->capabilities);
318 DP_VERBOSE(p_hwfn, ECORE_MSG_IFUP,
319 "update rss flag %d, rss_mode = %d, update_caps = %d, capabilities = %d, update_ind = %d, update_rss_key = %d\n",
320 p_ramrod->common.update_rss_flg,
322 p_config->update_rss_capabilities,
323 p_config->capabilities,
324 p_config->update_rss_ind_table, p_config->update_rss_key);
326 table_size = OSAL_MIN_T(int, ECORE_RSS_IND_TABLE_SIZE,
327 1 << p_config->tbl_size);
328 for (i = 0; i < table_size; i++) {
329 struct ecore_queue_cid *p_queue = p_rss->rss_ind_table[i];
334 p_config->indirection_table[i] =
335 OSAL_CPU_TO_LE16(p_queue->abs.queue_id);
338 DP_VERBOSE(p_hwfn, ECORE_MSG_IFUP,
339 "Configured RSS indirection table [%d entries]:\n",
341 for (i = 0; i < ECORE_RSS_IND_TABLE_SIZE; i += 0x10) {
342 DP_VERBOSE(p_hwfn, ECORE_MSG_IFUP,
343 "%04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x\n",
344 OSAL_LE16_TO_CPU(p_config->indirection_table[i]),
345 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 1]),
346 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 2]),
347 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 3]),
348 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 4]),
349 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 5]),
350 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 6]),
351 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 7]),
352 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 8]),
353 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 9]),
354 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 10]),
355 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 11]),
356 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 12]),
357 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 13]),
358 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 14]),
359 OSAL_LE16_TO_CPU(p_config->indirection_table[i + 15]));
362 for (i = 0; i < 10; i++)
363 p_config->rss_key[i] = OSAL_CPU_TO_LE32(p_rss->rss_key[i]);
369 ecore_sp_update_accept_mode(struct ecore_hwfn *p_hwfn,
370 struct vport_update_ramrod_data *p_ramrod,
371 struct ecore_filter_accept_flags accept_flags)
373 p_ramrod->common.update_rx_mode_flg =
374 accept_flags.update_rx_mode_config;
375 p_ramrod->common.update_tx_mode_flg =
376 accept_flags.update_tx_mode_config;
379 /* On B0 emulation we cannot enable Tx, since this would cause writes
380 * to PVFC HW block which isn't implemented in emulation.
382 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
383 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
384 "Non-Asic - prevent Tx mode in vport update\n");
385 p_ramrod->common.update_tx_mode_flg = 0;
389 /* Set Rx mode accept flags */
390 if (p_ramrod->common.update_rx_mode_flg) {
391 u8 accept_filter = accept_flags.rx_accept_filter;
394 SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_DROP_ALL,
395 !(!!(accept_filter & ECORE_ACCEPT_UCAST_MATCHED) ||
396 !!(accept_filter & ECORE_ACCEPT_UCAST_UNMATCHED)));
398 SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_ACCEPT_UNMATCHED,
399 !!(accept_filter & ECORE_ACCEPT_UCAST_UNMATCHED));
401 SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_DROP_ALL,
402 !(!!(accept_filter & ECORE_ACCEPT_MCAST_MATCHED) ||
403 !!(accept_filter & ECORE_ACCEPT_MCAST_UNMATCHED)));
405 SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_ACCEPT_ALL,
406 (!!(accept_filter & ECORE_ACCEPT_MCAST_MATCHED) &&
407 !!(accept_filter & ECORE_ACCEPT_MCAST_UNMATCHED)));
409 SET_FIELD(state, ETH_VPORT_RX_MODE_BCAST_ACCEPT_ALL,
410 !!(accept_filter & ECORE_ACCEPT_BCAST));
412 p_ramrod->rx_mode.state = OSAL_CPU_TO_LE16(state);
413 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
414 "vport[%02x] p_ramrod->rx_mode.state = 0x%x\n",
415 p_ramrod->common.vport_id, state);
418 /* Set Tx mode accept flags */
419 if (p_ramrod->common.update_tx_mode_flg) {
420 u8 accept_filter = accept_flags.tx_accept_filter;
423 SET_FIELD(state, ETH_VPORT_TX_MODE_UCAST_DROP_ALL,
424 !!(accept_filter & ECORE_ACCEPT_NONE));
426 SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_DROP_ALL,
427 !!(accept_filter & ECORE_ACCEPT_NONE));
429 SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_ACCEPT_ALL,
430 (!!(accept_filter & ECORE_ACCEPT_MCAST_MATCHED) &&
431 !!(accept_filter & ECORE_ACCEPT_MCAST_UNMATCHED)));
433 SET_FIELD(state, ETH_VPORT_TX_MODE_BCAST_ACCEPT_ALL,
434 !!(accept_filter & ECORE_ACCEPT_BCAST));
436 p_ramrod->tx_mode.state = OSAL_CPU_TO_LE16(state);
437 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
438 "vport[%02x] p_ramrod->tx_mode.state = 0x%x\n",
439 p_ramrod->common.vport_id, state);
444 ecore_sp_vport_update_sge_tpa(struct ecore_hwfn *p_hwfn,
445 struct vport_update_ramrod_data *p_ramrod,
446 struct ecore_sge_tpa_params *p_params)
448 struct eth_vport_tpa_param *p_tpa;
451 p_ramrod->common.update_tpa_param_flg = 0;
452 p_ramrod->common.update_tpa_en_flg = 0;
453 p_ramrod->common.update_tpa_param_flg = 0;
457 p_ramrod->common.update_tpa_en_flg = p_params->update_tpa_en_flg;
458 p_tpa = &p_ramrod->tpa_param;
459 p_tpa->tpa_ipv4_en_flg = p_params->tpa_ipv4_en_flg;
460 p_tpa->tpa_ipv6_en_flg = p_params->tpa_ipv6_en_flg;
461 p_tpa->tpa_ipv4_tunn_en_flg = p_params->tpa_ipv4_tunn_en_flg;
462 p_tpa->tpa_ipv6_tunn_en_flg = p_params->tpa_ipv6_tunn_en_flg;
464 p_ramrod->common.update_tpa_param_flg = p_params->update_tpa_param_flg;
465 p_tpa->max_buff_num = p_params->max_buffers_per_cqe;
466 p_tpa->tpa_pkt_split_flg = p_params->tpa_pkt_split_flg;
467 p_tpa->tpa_hdr_data_split_flg = p_params->tpa_hdr_data_split_flg;
468 p_tpa->tpa_gro_consistent_flg = p_params->tpa_gro_consistent_flg;
469 p_tpa->tpa_max_aggs_num = p_params->tpa_max_aggs_num;
470 p_tpa->tpa_max_size = p_params->tpa_max_size;
471 p_tpa->tpa_min_size_to_start = p_params->tpa_min_size_to_start;
472 p_tpa->tpa_min_size_to_cont = p_params->tpa_min_size_to_cont;
476 ecore_sp_update_mcast_bin(struct ecore_hwfn *p_hwfn,
477 struct vport_update_ramrod_data *p_ramrod,
478 struct ecore_sp_vport_update_params *p_params)
482 OSAL_MEMSET(&p_ramrod->approx_mcast.bins, 0,
483 sizeof(p_ramrod->approx_mcast.bins));
485 if (!p_params->update_approx_mcast_flg)
488 p_ramrod->common.update_approx_mcast_flg = 1;
489 for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
490 u32 *p_bins = (u32 *)p_params->bins;
492 p_ramrod->approx_mcast.bins[i] = OSAL_CPU_TO_LE32(p_bins[i]);
497 ecore_sp_vport_update(struct ecore_hwfn *p_hwfn,
498 struct ecore_sp_vport_update_params *p_params,
499 enum spq_mode comp_mode,
500 struct ecore_spq_comp_cb *p_comp_data)
502 struct ecore_rss_params *p_rss_params = p_params->rss_params;
503 struct vport_update_ramrod_data_cmn *p_cmn;
504 struct ecore_sp_init_data init_data;
505 struct vport_update_ramrod_data *p_ramrod = OSAL_NULL;
506 struct ecore_spq_entry *p_ent = OSAL_NULL;
507 u8 abs_vport_id = 0, val;
508 enum _ecore_status_t rc = ECORE_NOTIMPL;
510 if (IS_VF(p_hwfn->p_dev)) {
511 rc = ecore_vf_pf_vport_update(p_hwfn, p_params);
515 rc = ecore_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
516 if (rc != ECORE_SUCCESS)
520 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
521 init_data.cid = ecore_spq_get_cid(p_hwfn);
522 init_data.opaque_fid = p_params->opaque_fid;
523 init_data.comp_mode = comp_mode;
524 init_data.p_comp_data = p_comp_data;
526 rc = ecore_sp_init_request(p_hwfn, &p_ent,
527 ETH_RAMROD_VPORT_UPDATE,
528 PROTOCOLID_ETH, &init_data);
529 if (rc != ECORE_SUCCESS)
532 /* Copy input params to ramrod according to FW struct */
533 p_ramrod = &p_ent->ramrod.vport_update;
534 p_cmn = &p_ramrod->common;
536 p_cmn->vport_id = abs_vport_id;
538 p_cmn->rx_active_flg = p_params->vport_active_rx_flg;
539 p_cmn->update_rx_active_flg = p_params->update_vport_active_rx_flg;
540 p_cmn->tx_active_flg = p_params->vport_active_tx_flg;
541 p_cmn->update_tx_active_flg = p_params->update_vport_active_tx_flg;
543 p_cmn->accept_any_vlan = p_params->accept_any_vlan;
544 val = p_params->update_accept_any_vlan_flg;
545 p_cmn->update_accept_any_vlan_flg = val;
547 p_cmn->inner_vlan_removal_en = p_params->inner_vlan_removal_flg;
548 val = p_params->update_inner_vlan_removal_flg;
549 p_cmn->update_inner_vlan_removal_en_flg = val;
551 p_cmn->default_vlan_en = p_params->default_vlan_enable_flg;
552 val = p_params->update_default_vlan_enable_flg;
553 p_cmn->update_default_vlan_en_flg = val;
555 p_cmn->default_vlan = OSAL_CPU_TO_LE16(p_params->default_vlan);
556 p_cmn->update_default_vlan_flg = p_params->update_default_vlan_flg;
558 p_cmn->silent_vlan_removal_en = p_params->silent_vlan_removal_flg;
560 p_ramrod->common.tx_switching_en = p_params->tx_switching_flg;
563 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
564 if (p_ramrod->common.tx_switching_en ||
565 p_ramrod->common.update_tx_switching_en_flg) {
566 DP_NOTICE(p_hwfn, false,
567 "FPGA - why are we seeing tx-switching? Overriding it\n");
568 p_ramrod->common.tx_switching_en = 0;
569 p_ramrod->common.update_tx_switching_en_flg = 1;
572 p_cmn->update_tx_switching_en_flg = p_params->update_tx_switching_flg;
574 p_cmn->anti_spoofing_en = p_params->anti_spoofing_en;
575 val = p_params->update_anti_spoofing_en_flg;
576 p_ramrod->common.update_anti_spoofing_en_flg = val;
578 rc = ecore_sp_vport_update_rss(p_hwfn, p_ramrod, p_rss_params);
579 if (rc != ECORE_SUCCESS) {
580 /* Return spq entry which is taken in ecore_sp_init_request()*/
581 ecore_spq_return_entry(p_hwfn, p_ent);
585 /* Update mcast bins for VFs, PF doesn't use this functionality */
586 ecore_sp_update_mcast_bin(p_hwfn, p_ramrod, p_params);
588 ecore_sp_update_accept_mode(p_hwfn, p_ramrod, p_params->accept_flags);
589 ecore_sp_vport_update_sge_tpa(p_hwfn, p_ramrod,
590 p_params->sge_tpa_params);
592 p_ramrod->common.update_mtu_flg = 1;
593 p_ramrod->common.mtu = OSAL_CPU_TO_LE16(p_params->mtu);
596 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
599 enum _ecore_status_t ecore_sp_vport_stop(struct ecore_hwfn *p_hwfn,
600 u16 opaque_fid, u8 vport_id)
602 struct vport_stop_ramrod_data *p_ramrod;
603 struct ecore_sp_init_data init_data;
604 struct ecore_spq_entry *p_ent;
606 enum _ecore_status_t rc;
608 if (IS_VF(p_hwfn->p_dev))
609 return ecore_vf_pf_vport_stop(p_hwfn);
611 rc = ecore_fw_vport(p_hwfn, vport_id, &abs_vport_id);
612 if (rc != ECORE_SUCCESS)
616 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
617 init_data.cid = ecore_spq_get_cid(p_hwfn);
618 init_data.opaque_fid = opaque_fid;
619 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
621 rc = ecore_sp_init_request(p_hwfn, &p_ent,
622 ETH_RAMROD_VPORT_STOP,
623 PROTOCOLID_ETH, &init_data);
624 if (rc != ECORE_SUCCESS)
627 p_ramrod = &p_ent->ramrod.vport_stop;
628 p_ramrod->vport_id = abs_vport_id;
630 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
633 static enum _ecore_status_t
634 ecore_vf_pf_accept_flags(struct ecore_hwfn *p_hwfn,
635 struct ecore_filter_accept_flags *p_accept_flags)
637 struct ecore_sp_vport_update_params s_params;
639 OSAL_MEMSET(&s_params, 0, sizeof(s_params));
640 OSAL_MEMCPY(&s_params.accept_flags, p_accept_flags,
641 sizeof(struct ecore_filter_accept_flags));
643 return ecore_vf_pf_vport_update(p_hwfn, &s_params);
647 ecore_filter_accept_cmd(struct ecore_dev *p_dev,
649 struct ecore_filter_accept_flags accept_flags,
650 u8 update_accept_any_vlan,
652 enum spq_mode comp_mode,
653 struct ecore_spq_comp_cb *p_comp_data)
655 struct ecore_sp_vport_update_params vport_update_params;
658 /* Prepare and send the vport rx_mode change */
659 OSAL_MEMSET(&vport_update_params, 0, sizeof(vport_update_params));
660 vport_update_params.vport_id = vport;
661 vport_update_params.accept_flags = accept_flags;
662 vport_update_params.update_accept_any_vlan_flg = update_accept_any_vlan;
663 vport_update_params.accept_any_vlan = accept_any_vlan;
665 for_each_hwfn(p_dev, i) {
666 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
668 vport_update_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
671 rc = ecore_vf_pf_accept_flags(p_hwfn, &accept_flags);
672 if (rc != ECORE_SUCCESS)
677 rc = ecore_sp_vport_update(p_hwfn, &vport_update_params,
678 comp_mode, p_comp_data);
679 if (rc != ECORE_SUCCESS) {
680 DP_ERR(p_dev, "Update rx_mode failed %d\n", rc);
684 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
685 "Accept filter configured, flags = [Rx]%x [Tx]%x\n",
686 accept_flags.rx_accept_filter,
687 accept_flags.tx_accept_filter);
689 if (update_accept_any_vlan)
690 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
691 "accept_any_vlan=%d configured\n",
699 ecore_eth_rxq_start_ramrod(struct ecore_hwfn *p_hwfn,
700 struct ecore_queue_cid *p_cid,
702 dma_addr_t bd_chain_phys_addr,
703 dma_addr_t cqe_pbl_addr,
706 struct rx_queue_start_ramrod_data *p_ramrod = OSAL_NULL;
707 struct ecore_spq_entry *p_ent = OSAL_NULL;
708 struct ecore_sp_init_data init_data;
709 enum _ecore_status_t rc = ECORE_NOTIMPL;
711 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
712 "opaque_fid=0x%x, cid=0x%x, rx_qzone=0x%x, vport_id=0x%x, sb_id=0x%x\n",
713 p_cid->opaque_fid, p_cid->cid, p_cid->abs.queue_id,
714 p_cid->abs.vport_id, p_cid->abs.sb);
717 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
718 init_data.cid = p_cid->cid;
719 init_data.opaque_fid = p_cid->opaque_fid;
720 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
722 rc = ecore_sp_init_request(p_hwfn, &p_ent,
723 ETH_RAMROD_RX_QUEUE_START,
724 PROTOCOLID_ETH, &init_data);
725 if (rc != ECORE_SUCCESS)
728 p_ramrod = &p_ent->ramrod.rx_queue_start;
730 p_ramrod->sb_id = OSAL_CPU_TO_LE16(p_cid->abs.sb);
731 p_ramrod->sb_index = p_cid->abs.sb_idx;
732 p_ramrod->vport_id = p_cid->abs.vport_id;
733 p_ramrod->stats_counter_id = p_cid->abs.stats_id;
734 p_ramrod->rx_queue_id = OSAL_CPU_TO_LE16(p_cid->abs.queue_id);
735 p_ramrod->complete_cqe_flg = 0;
736 p_ramrod->complete_event_flg = 1;
738 p_ramrod->bd_max_bytes = OSAL_CPU_TO_LE16(bd_max_bytes);
739 DMA_REGPAIR_LE(p_ramrod->bd_base, bd_chain_phys_addr);
741 p_ramrod->num_of_pbl_pages = OSAL_CPU_TO_LE16(cqe_pbl_size);
742 DMA_REGPAIR_LE(p_ramrod->cqe_pbl_addr, cqe_pbl_addr);
745 p_ramrod->vf_rx_prod_index = p_cid->vf_qid;
746 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
747 "Queue%s is meant for VF rxq[%02x]\n",
748 !!p_cid->b_legacy_vf ? " [legacy]" : "",
750 p_ramrod->vf_rx_prod_use_zone_a = !!p_cid->b_legacy_vf;
753 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
756 static enum _ecore_status_t
757 ecore_eth_pf_rx_queue_start(struct ecore_hwfn *p_hwfn,
758 struct ecore_queue_cid *p_cid,
760 dma_addr_t bd_chain_phys_addr,
761 dma_addr_t cqe_pbl_addr,
763 void OSAL_IOMEM * *pp_producer)
765 u32 init_prod_val = 0;
767 *pp_producer = (u8 OSAL_IOMEM *)
769 GTT_BAR0_MAP_REG_MSDM_RAM +
770 MSTORM_ETH_PF_PRODS_OFFSET(p_cid->abs.queue_id);
772 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
773 __internal_ram_wr(p_hwfn, *pp_producer, sizeof(u32),
774 (u32 *)(&init_prod_val));
776 return ecore_eth_rxq_start_ramrod(p_hwfn, p_cid,
779 cqe_pbl_addr, cqe_pbl_size);
783 ecore_eth_rx_queue_start(struct ecore_hwfn *p_hwfn,
785 struct ecore_queue_start_common_params *p_params,
787 dma_addr_t bd_chain_phys_addr,
788 dma_addr_t cqe_pbl_addr,
790 struct ecore_rxq_start_ret_params *p_ret_params)
792 struct ecore_queue_cid *p_cid;
793 enum _ecore_status_t rc;
795 /* Allocate a CID for the queue */
796 p_cid = ecore_eth_queue_to_cid(p_hwfn, opaque_fid, p_params);
797 if (p_cid == OSAL_NULL)
800 if (IS_PF(p_hwfn->p_dev))
801 rc = ecore_eth_pf_rx_queue_start(p_hwfn, p_cid,
804 cqe_pbl_addr, cqe_pbl_size,
805 &p_ret_params->p_prod);
807 rc = ecore_vf_pf_rxq_start(p_hwfn, p_cid,
812 &p_ret_params->p_prod);
814 /* Provide the caller with a reference to as handler */
815 if (rc != ECORE_SUCCESS)
816 ecore_eth_queue_cid_release(p_hwfn, p_cid);
818 p_ret_params->p_handle = (void *)p_cid;
824 ecore_sp_eth_rx_queues_update(struct ecore_hwfn *p_hwfn,
825 void **pp_rxq_handles,
828 u8 complete_event_flg,
829 enum spq_mode comp_mode,
830 struct ecore_spq_comp_cb *p_comp_data)
832 struct rx_queue_update_ramrod_data *p_ramrod = OSAL_NULL;
833 struct ecore_spq_entry *p_ent = OSAL_NULL;
834 struct ecore_sp_init_data init_data;
835 struct ecore_queue_cid *p_cid;
836 enum _ecore_status_t rc = ECORE_NOTIMPL;
839 if (IS_VF(p_hwfn->p_dev))
840 return ecore_vf_pf_rxqs_update(p_hwfn,
841 (struct ecore_queue_cid **)
847 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
848 init_data.comp_mode = comp_mode;
849 init_data.p_comp_data = p_comp_data;
851 for (i = 0; i < num_rxqs; i++) {
852 p_cid = ((struct ecore_queue_cid **)pp_rxq_handles)[i];
855 init_data.cid = p_cid->cid;
856 init_data.opaque_fid = p_cid->opaque_fid;
858 rc = ecore_sp_init_request(p_hwfn, &p_ent,
859 ETH_RAMROD_RX_QUEUE_UPDATE,
860 PROTOCOLID_ETH, &init_data);
861 if (rc != ECORE_SUCCESS)
864 p_ramrod = &p_ent->ramrod.rx_queue_update;
865 p_ramrod->vport_id = p_cid->abs.vport_id;
867 p_ramrod->rx_queue_id = OSAL_CPU_TO_LE16(p_cid->abs.queue_id);
868 p_ramrod->complete_cqe_flg = complete_cqe_flg;
869 p_ramrod->complete_event_flg = complete_event_flg;
871 rc = ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
872 if (rc != ECORE_SUCCESS)
879 static enum _ecore_status_t
880 ecore_eth_pf_rx_queue_stop(struct ecore_hwfn *p_hwfn,
881 struct ecore_queue_cid *p_cid,
882 bool b_eq_completion_only,
883 bool b_cqe_completion)
885 struct rx_queue_stop_ramrod_data *p_ramrod = OSAL_NULL;
886 struct ecore_spq_entry *p_ent = OSAL_NULL;
887 struct ecore_sp_init_data init_data;
888 enum _ecore_status_t rc;
890 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
891 init_data.cid = p_cid->cid;
892 init_data.opaque_fid = p_cid->opaque_fid;
893 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
895 rc = ecore_sp_init_request(p_hwfn, &p_ent,
896 ETH_RAMROD_RX_QUEUE_STOP,
897 PROTOCOLID_ETH, &init_data);
898 if (rc != ECORE_SUCCESS)
901 p_ramrod = &p_ent->ramrod.rx_queue_stop;
902 p_ramrod->vport_id = p_cid->abs.vport_id;
903 p_ramrod->rx_queue_id = OSAL_CPU_TO_LE16(p_cid->abs.queue_id);
905 /* Cleaning the queue requires the completion to arrive there.
906 * In addition, VFs require the answer to come as eqe to PF.
908 p_ramrod->complete_cqe_flg = (!p_cid->is_vf && !b_eq_completion_only) ||
910 p_ramrod->complete_event_flg = p_cid->is_vf || b_eq_completion_only;
912 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
915 enum _ecore_status_t ecore_eth_rx_queue_stop(struct ecore_hwfn *p_hwfn,
917 bool eq_completion_only,
920 struct ecore_queue_cid *p_cid = (struct ecore_queue_cid *)p_rxq;
921 enum _ecore_status_t rc = ECORE_NOTIMPL;
923 if (IS_PF(p_hwfn->p_dev))
924 rc = ecore_eth_pf_rx_queue_stop(p_hwfn, p_cid,
928 rc = ecore_vf_pf_rxq_stop(p_hwfn, p_cid, cqe_completion);
930 if (rc == ECORE_SUCCESS)
931 ecore_eth_queue_cid_release(p_hwfn, p_cid);
936 ecore_eth_txq_start_ramrod(struct ecore_hwfn *p_hwfn,
937 struct ecore_queue_cid *p_cid,
938 dma_addr_t pbl_addr, u16 pbl_size,
941 struct tx_queue_start_ramrod_data *p_ramrod = OSAL_NULL;
942 struct ecore_spq_entry *p_ent = OSAL_NULL;
943 struct ecore_sp_init_data init_data;
944 enum _ecore_status_t rc = ECORE_NOTIMPL;
947 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
948 init_data.cid = p_cid->cid;
949 init_data.opaque_fid = p_cid->opaque_fid;
950 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
952 rc = ecore_sp_init_request(p_hwfn, &p_ent,
953 ETH_RAMROD_TX_QUEUE_START,
954 PROTOCOLID_ETH, &init_data);
955 if (rc != ECORE_SUCCESS)
958 p_ramrod = &p_ent->ramrod.tx_queue_start;
959 p_ramrod->vport_id = p_cid->abs.vport_id;
961 p_ramrod->sb_id = OSAL_CPU_TO_LE16(p_cid->abs.sb);
962 p_ramrod->sb_index = p_cid->abs.sb_idx;
963 p_ramrod->stats_counter_id = p_cid->abs.stats_id;
965 p_ramrod->queue_zone_id = OSAL_CPU_TO_LE16(p_cid->abs.queue_id);
966 p_ramrod->same_as_last_id = OSAL_CPU_TO_LE16(p_cid->abs.queue_id);
968 p_ramrod->pbl_size = OSAL_CPU_TO_LE16(pbl_size);
969 DMA_REGPAIR_LE(p_ramrod->pbl_base_addr, pbl_addr);
971 p_ramrod->qm_pq_id = OSAL_CPU_TO_LE16(pq_id);
973 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
976 static enum _ecore_status_t
977 ecore_eth_pf_tx_queue_start(struct ecore_hwfn *p_hwfn,
978 struct ecore_queue_cid *p_cid,
980 dma_addr_t pbl_addr, u16 pbl_size,
981 void OSAL_IOMEM * *pp_doorbell)
983 enum _ecore_status_t rc;
985 /* TODO - set tc in the pq_params for multi-cos */
986 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid,
988 ecore_get_cm_pq_idx_mcos(p_hwfn, tc));
989 if (rc != ECORE_SUCCESS)
992 /* Provide the caller with the necessary return values */
993 *pp_doorbell = (u8 OSAL_IOMEM *)
995 DB_ADDR(p_cid->cid, DQ_DEMS_LEGACY);
997 return ECORE_SUCCESS;
1000 enum _ecore_status_t
1001 ecore_eth_tx_queue_start(struct ecore_hwfn *p_hwfn, u16 opaque_fid,
1002 struct ecore_queue_start_common_params *p_params,
1004 dma_addr_t pbl_addr, u16 pbl_size,
1005 struct ecore_txq_start_ret_params *p_ret_params)
1007 struct ecore_queue_cid *p_cid;
1008 enum _ecore_status_t rc;
1010 p_cid = ecore_eth_queue_to_cid(p_hwfn, opaque_fid, p_params);
1011 if (p_cid == OSAL_NULL)
1014 if (IS_PF(p_hwfn->p_dev))
1015 rc = ecore_eth_pf_tx_queue_start(p_hwfn, p_cid, tc,
1017 &p_ret_params->p_doorbell);
1019 rc = ecore_vf_pf_txq_start(p_hwfn, p_cid,
1021 &p_ret_params->p_doorbell);
1023 if (rc != ECORE_SUCCESS)
1024 ecore_eth_queue_cid_release(p_hwfn, p_cid);
1026 p_ret_params->p_handle = (void *)p_cid;
1031 static enum _ecore_status_t
1032 ecore_eth_pf_tx_queue_stop(struct ecore_hwfn *p_hwfn,
1033 struct ecore_queue_cid *p_cid)
1035 struct ecore_spq_entry *p_ent = OSAL_NULL;
1036 struct ecore_sp_init_data init_data;
1037 enum _ecore_status_t rc;
1039 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
1040 init_data.cid = p_cid->cid;
1041 init_data.opaque_fid = p_cid->opaque_fid;
1042 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
1044 rc = ecore_sp_init_request(p_hwfn, &p_ent,
1045 ETH_RAMROD_TX_QUEUE_STOP,
1046 PROTOCOLID_ETH, &init_data);
1047 if (rc != ECORE_SUCCESS)
1050 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
1053 enum _ecore_status_t ecore_eth_tx_queue_stop(struct ecore_hwfn *p_hwfn,
1056 struct ecore_queue_cid *p_cid = (struct ecore_queue_cid *)p_handle;
1057 enum _ecore_status_t rc;
1059 if (IS_PF(p_hwfn->p_dev))
1060 rc = ecore_eth_pf_tx_queue_stop(p_hwfn, p_cid);
1062 rc = ecore_vf_pf_txq_stop(p_hwfn, p_cid);
1064 if (rc == ECORE_SUCCESS)
1065 ecore_eth_queue_cid_release(p_hwfn, p_cid);
1069 static enum eth_filter_action
1070 ecore_filter_action(enum ecore_filter_opcode opcode)
1072 enum eth_filter_action action = MAX_ETH_FILTER_ACTION;
1075 case ECORE_FILTER_ADD:
1076 action = ETH_FILTER_ACTION_ADD;
1078 case ECORE_FILTER_REMOVE:
1079 action = ETH_FILTER_ACTION_REMOVE;
1081 case ECORE_FILTER_FLUSH:
1082 action = ETH_FILTER_ACTION_REMOVE_ALL;
1085 action = MAX_ETH_FILTER_ACTION;
1091 static enum _ecore_status_t
1092 ecore_filter_ucast_common(struct ecore_hwfn *p_hwfn,
1094 struct ecore_filter_ucast *p_filter_cmd,
1095 struct vport_filter_update_ramrod_data **pp_ramrod,
1096 struct ecore_spq_entry **pp_ent,
1097 enum spq_mode comp_mode,
1098 struct ecore_spq_comp_cb *p_comp_data)
1100 u8 vport_to_add_to = 0, vport_to_remove_from = 0;
1101 struct vport_filter_update_ramrod_data *p_ramrod;
1102 struct eth_filter_cmd *p_first_filter;
1103 struct eth_filter_cmd *p_second_filter;
1104 struct ecore_sp_init_data init_data;
1105 enum eth_filter_action action;
1106 enum _ecore_status_t rc;
1108 rc = ecore_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
1109 &vport_to_remove_from);
1110 if (rc != ECORE_SUCCESS)
1113 rc = ecore_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
1115 if (rc != ECORE_SUCCESS)
1119 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
1120 init_data.cid = ecore_spq_get_cid(p_hwfn);
1121 init_data.opaque_fid = opaque_fid;
1122 init_data.comp_mode = comp_mode;
1123 init_data.p_comp_data = p_comp_data;
1125 rc = ecore_sp_init_request(p_hwfn, pp_ent,
1126 ETH_RAMROD_FILTERS_UPDATE,
1127 PROTOCOLID_ETH, &init_data);
1128 if (rc != ECORE_SUCCESS)
1131 *pp_ramrod = &(*pp_ent)->ramrod.vport_filter_update;
1132 p_ramrod = *pp_ramrod;
1133 p_ramrod->filter_cmd_hdr.rx = p_filter_cmd->is_rx_filter ? 1 : 0;
1134 p_ramrod->filter_cmd_hdr.tx = p_filter_cmd->is_tx_filter ? 1 : 0;
1137 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
1138 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1139 "Non-Asic - prevent Tx filters\n");
1140 p_ramrod->filter_cmd_hdr.tx = 0;
1144 switch (p_filter_cmd->opcode) {
1145 case ECORE_FILTER_REPLACE:
1146 case ECORE_FILTER_MOVE:
1147 p_ramrod->filter_cmd_hdr.cmd_cnt = 2;
1150 p_ramrod->filter_cmd_hdr.cmd_cnt = 1;
1154 p_first_filter = &p_ramrod->filter_cmds[0];
1155 p_second_filter = &p_ramrod->filter_cmds[1];
1157 switch (p_filter_cmd->type) {
1158 case ECORE_FILTER_MAC:
1159 p_first_filter->type = ETH_FILTER_TYPE_MAC;
1161 case ECORE_FILTER_VLAN:
1162 p_first_filter->type = ETH_FILTER_TYPE_VLAN;
1164 case ECORE_FILTER_MAC_VLAN:
1165 p_first_filter->type = ETH_FILTER_TYPE_PAIR;
1167 case ECORE_FILTER_INNER_MAC:
1168 p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC;
1170 case ECORE_FILTER_INNER_VLAN:
1171 p_first_filter->type = ETH_FILTER_TYPE_INNER_VLAN;
1173 case ECORE_FILTER_INNER_PAIR:
1174 p_first_filter->type = ETH_FILTER_TYPE_INNER_PAIR;
1176 case ECORE_FILTER_INNER_MAC_VNI_PAIR:
1177 p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR;
1179 case ECORE_FILTER_MAC_VNI_PAIR:
1180 p_first_filter->type = ETH_FILTER_TYPE_MAC_VNI_PAIR;
1182 case ECORE_FILTER_VNI:
1183 p_first_filter->type = ETH_FILTER_TYPE_VNI;
1185 case ECORE_FILTER_UNUSED: /* @DPDK */
1186 p_first_filter->type = MAX_ETH_FILTER_TYPE;
1190 if ((p_first_filter->type == ETH_FILTER_TYPE_MAC) ||
1191 (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
1192 (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC) ||
1193 (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR) ||
1194 (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
1195 (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR))
1196 ecore_set_fw_mac_addr(&p_first_filter->mac_msb,
1197 &p_first_filter->mac_mid,
1198 &p_first_filter->mac_lsb,
1199 (u8 *)p_filter_cmd->mac);
1201 if ((p_first_filter->type == ETH_FILTER_TYPE_VLAN) ||
1202 (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
1203 (p_first_filter->type == ETH_FILTER_TYPE_INNER_VLAN) ||
1204 (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR))
1205 p_first_filter->vlan_id = OSAL_CPU_TO_LE16(p_filter_cmd->vlan);
1207 if ((p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
1208 (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR) ||
1209 (p_first_filter->type == ETH_FILTER_TYPE_VNI))
1210 p_first_filter->vni = OSAL_CPU_TO_LE32(p_filter_cmd->vni);
1212 if (p_filter_cmd->opcode == ECORE_FILTER_MOVE) {
1213 p_second_filter->type = p_first_filter->type;
1214 p_second_filter->mac_msb = p_first_filter->mac_msb;
1215 p_second_filter->mac_mid = p_first_filter->mac_mid;
1216 p_second_filter->mac_lsb = p_first_filter->mac_lsb;
1217 p_second_filter->vlan_id = p_first_filter->vlan_id;
1218 p_second_filter->vni = p_first_filter->vni;
1220 p_first_filter->action = ETH_FILTER_ACTION_REMOVE;
1222 p_first_filter->vport_id = vport_to_remove_from;
1224 p_second_filter->action = ETH_FILTER_ACTION_ADD;
1225 p_second_filter->vport_id = vport_to_add_to;
1226 } else if (p_filter_cmd->opcode == ECORE_FILTER_REPLACE) {
1227 p_first_filter->vport_id = vport_to_add_to;
1228 OSAL_MEMCPY(p_second_filter, p_first_filter,
1229 sizeof(*p_second_filter));
1230 p_first_filter->action = ETH_FILTER_ACTION_REMOVE_ALL;
1231 p_second_filter->action = ETH_FILTER_ACTION_ADD;
1233 action = ecore_filter_action(p_filter_cmd->opcode);
1235 if (action == MAX_ETH_FILTER_ACTION) {
1236 DP_NOTICE(p_hwfn, true,
1237 "%d is not supported yet\n",
1238 p_filter_cmd->opcode);
1239 return ECORE_NOTIMPL;
1242 p_first_filter->action = action;
1243 p_first_filter->vport_id =
1244 (p_filter_cmd->opcode == ECORE_FILTER_REMOVE) ?
1245 vport_to_remove_from : vport_to_add_to;
1248 return ECORE_SUCCESS;
1251 enum _ecore_status_t
1252 ecore_sp_eth_filter_ucast(struct ecore_hwfn *p_hwfn,
1254 struct ecore_filter_ucast *p_filter_cmd,
1255 enum spq_mode comp_mode,
1256 struct ecore_spq_comp_cb *p_comp_data)
1258 struct vport_filter_update_ramrod_data *p_ramrod = OSAL_NULL;
1259 struct ecore_spq_entry *p_ent = OSAL_NULL;
1260 struct eth_filter_cmd_header *p_header;
1261 enum _ecore_status_t rc;
1263 rc = ecore_filter_ucast_common(p_hwfn, opaque_fid, p_filter_cmd,
1265 comp_mode, p_comp_data);
1266 if (rc != ECORE_SUCCESS) {
1267 DP_ERR(p_hwfn, "Uni. filter command failed %d\n", rc);
1270 p_header = &p_ramrod->filter_cmd_hdr;
1271 p_header->assert_on_error = p_filter_cmd->assert_on_error;
1273 rc = ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
1274 if (rc != ECORE_SUCCESS) {
1275 DP_ERR(p_hwfn, "Unicast filter ADD command failed %d\n", rc);
1279 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1280 "Unicast filter configured, opcode = %s, type = %s, cmd_cnt = %d, is_rx_filter = %d, is_tx_filter = %d\n",
1281 (p_filter_cmd->opcode == ECORE_FILTER_ADD) ? "ADD" :
1282 ((p_filter_cmd->opcode == ECORE_FILTER_REMOVE) ?
1284 ((p_filter_cmd->opcode == ECORE_FILTER_MOVE) ?
1285 "MOVE" : "REPLACE")),
1286 (p_filter_cmd->type == ECORE_FILTER_MAC) ? "MAC" :
1287 ((p_filter_cmd->type == ECORE_FILTER_VLAN) ?
1288 "VLAN" : "MAC & VLAN"),
1289 p_ramrod->filter_cmd_hdr.cmd_cnt,
1290 p_filter_cmd->is_rx_filter, p_filter_cmd->is_tx_filter);
1291 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1292 "vport_to_add_to = %d, vport_to_remove_from = %d, mac = %2x:%2x:%2x:%2x:%2x:%2x, vlan = %d\n",
1293 p_filter_cmd->vport_to_add_to,
1294 p_filter_cmd->vport_to_remove_from,
1295 p_filter_cmd->mac[0], p_filter_cmd->mac[1],
1296 p_filter_cmd->mac[2], p_filter_cmd->mac[3],
1297 p_filter_cmd->mac[4], p_filter_cmd->mac[5],
1298 p_filter_cmd->vlan);
1300 return ECORE_SUCCESS;
1303 /*******************************************************************************
1305 * Calculates crc 32 on a buffer
1306 * Note: crc32_length MUST be aligned to 8
1308 ******************************************************************************/
1309 static u32 ecore_calc_crc32c(u8 *crc32_packet,
1310 u32 crc32_length, u32 crc32_seed, u8 complement)
1312 u32 byte = 0, bit = 0, crc32_result = crc32_seed;
1313 u8 msb = 0, current_byte = 0;
1315 if ((crc32_packet == OSAL_NULL) ||
1316 (crc32_length == 0) || ((crc32_length % 8) != 0)) {
1317 return crc32_result;
1320 for (byte = 0; byte < crc32_length; byte++) {
1321 current_byte = crc32_packet[byte];
1322 for (bit = 0; bit < 8; bit++) {
1323 msb = (u8)(crc32_result >> 31);
1324 crc32_result = crc32_result << 1;
1325 if (msb != (0x1 & (current_byte >> bit))) {
1326 crc32_result = crc32_result ^ CRC32_POLY;
1332 return crc32_result;
1335 static u32 ecore_crc32c_le(u32 seed, u8 *mac, u32 len)
1337 u32 packet_buf[2] = { 0 };
1339 OSAL_MEMCPY((u8 *)(&packet_buf[0]), &mac[0], 6);
1340 return ecore_calc_crc32c((u8 *)packet_buf, 8, seed, 0);
1343 u8 ecore_mcast_bin_from_mac(u8 *mac)
1345 u32 crc = ecore_crc32c_le(ETH_MULTICAST_BIN_FROM_MAC_SEED,
1351 static enum _ecore_status_t
1352 ecore_sp_eth_filter_mcast(struct ecore_hwfn *p_hwfn,
1354 struct ecore_filter_mcast *p_filter_cmd,
1355 enum spq_mode comp_mode,
1356 struct ecore_spq_comp_cb *p_comp_data)
1358 unsigned long bins[ETH_MULTICAST_MAC_BINS_IN_REGS];
1359 struct vport_update_ramrod_data *p_ramrod = OSAL_NULL;
1360 struct ecore_spq_entry *p_ent = OSAL_NULL;
1361 struct ecore_sp_init_data init_data;
1362 u8 abs_vport_id = 0;
1363 enum _ecore_status_t rc;
1366 if (p_filter_cmd->opcode == ECORE_FILTER_ADD)
1367 rc = ecore_fw_vport(p_hwfn,
1368 p_filter_cmd->vport_to_add_to,
1371 rc = ecore_fw_vport(p_hwfn,
1372 p_filter_cmd->vport_to_remove_from,
1374 if (rc != ECORE_SUCCESS)
1378 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
1379 init_data.cid = ecore_spq_get_cid(p_hwfn);
1380 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1381 init_data.comp_mode = comp_mode;
1382 init_data.p_comp_data = p_comp_data;
1384 rc = ecore_sp_init_request(p_hwfn, &p_ent,
1385 ETH_RAMROD_VPORT_UPDATE,
1386 PROTOCOLID_ETH, &init_data);
1387 if (rc != ECORE_SUCCESS) {
1388 DP_ERR(p_hwfn, "Multi-cast command failed %d\n", rc);
1392 p_ramrod = &p_ent->ramrod.vport_update;
1393 p_ramrod->common.update_approx_mcast_flg = 1;
1395 /* explicitly clear out the entire vector */
1396 OSAL_MEMSET(&p_ramrod->approx_mcast.bins,
1397 0, sizeof(p_ramrod->approx_mcast.bins));
1398 OSAL_MEMSET(bins, 0, sizeof(unsigned long) *
1399 ETH_MULTICAST_MAC_BINS_IN_REGS);
1400 /* filter ADD op is explicit set op and it removes
1401 * any existing filters for the vport.
1403 if (p_filter_cmd->opcode == ECORE_FILTER_ADD) {
1404 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1407 bit = ecore_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1408 OSAL_SET_BIT(bit, bins);
1411 /* Convert to correct endianity */
1412 for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
1413 struct vport_update_ramrod_mcast *p_ramrod_bins;
1414 u32 *p_bins = (u32 *)bins;
1416 p_ramrod_bins = &p_ramrod->approx_mcast;
1417 p_ramrod_bins->bins[i] = OSAL_CPU_TO_LE32(p_bins[i]);
1421 p_ramrod->common.vport_id = abs_vport_id;
1423 rc = ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
1424 if (rc != ECORE_SUCCESS)
1425 DP_ERR(p_hwfn, "Multicast filter command failed %d\n", rc);
1430 enum _ecore_status_t
1431 ecore_filter_mcast_cmd(struct ecore_dev *p_dev,
1432 struct ecore_filter_mcast *p_filter_cmd,
1433 enum spq_mode comp_mode,
1434 struct ecore_spq_comp_cb *p_comp_data)
1436 enum _ecore_status_t rc = ECORE_SUCCESS;
1439 /* only ADD and REMOVE operations are supported for multi-cast */
1440 if ((p_filter_cmd->opcode != ECORE_FILTER_ADD &&
1441 (p_filter_cmd->opcode != ECORE_FILTER_REMOVE)) ||
1442 (p_filter_cmd->num_mc_addrs > ECORE_MAX_MC_ADDRS)) {
1446 for_each_hwfn(p_dev, i) {
1447 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1451 ecore_vf_pf_filter_mcast(p_hwfn, p_filter_cmd);
1455 opaque_fid = p_hwfn->hw_info.opaque_fid;
1456 rc = ecore_sp_eth_filter_mcast(p_hwfn,
1459 comp_mode, p_comp_data);
1460 if (rc != ECORE_SUCCESS)
1467 enum _ecore_status_t
1468 ecore_filter_ucast_cmd(struct ecore_dev *p_dev,
1469 struct ecore_filter_ucast *p_filter_cmd,
1470 enum spq_mode comp_mode,
1471 struct ecore_spq_comp_cb *p_comp_data)
1473 enum _ecore_status_t rc = ECORE_SUCCESS;
1476 for_each_hwfn(p_dev, i) {
1477 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1481 rc = ecore_vf_pf_filter_ucast(p_hwfn, p_filter_cmd);
1485 opaque_fid = p_hwfn->hw_info.opaque_fid;
1486 rc = ecore_sp_eth_filter_ucast(p_hwfn,
1489 comp_mode, p_comp_data);
1490 if (rc != ECORE_SUCCESS)
1497 /* Statistics related code */
1498 static void __ecore_get_vport_pstats_addrlen(struct ecore_hwfn *p_hwfn,
1499 u32 *p_addr, u32 *p_len,
1502 if (IS_PF(p_hwfn->p_dev)) {
1503 *p_addr = BAR0_MAP_REG_PSDM_RAM +
1504 PSTORM_QUEUE_STAT_OFFSET(statistics_bin);
1505 *p_len = sizeof(struct eth_pstorm_per_queue_stat);
1507 struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1508 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1510 *p_addr = p_resp->pfdev_info.stats_info.pstats.address;
1511 *p_len = p_resp->pfdev_info.stats_info.pstats.len;
1515 static void __ecore_get_vport_pstats(struct ecore_hwfn *p_hwfn,
1516 struct ecore_ptt *p_ptt,
1517 struct ecore_eth_stats *p_stats,
1520 struct eth_pstorm_per_queue_stat pstats;
1521 u32 pstats_addr = 0, pstats_len = 0;
1523 __ecore_get_vport_pstats_addrlen(p_hwfn, &pstats_addr, &pstats_len,
1526 OSAL_MEMSET(&pstats, 0, sizeof(pstats));
1527 ecore_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, pstats_len);
1529 p_stats->tx_ucast_bytes += HILO_64_REGPAIR(pstats.sent_ucast_bytes);
1530 p_stats->tx_mcast_bytes += HILO_64_REGPAIR(pstats.sent_mcast_bytes);
1531 p_stats->tx_bcast_bytes += HILO_64_REGPAIR(pstats.sent_bcast_bytes);
1532 p_stats->tx_ucast_pkts += HILO_64_REGPAIR(pstats.sent_ucast_pkts);
1533 p_stats->tx_mcast_pkts += HILO_64_REGPAIR(pstats.sent_mcast_pkts);
1534 p_stats->tx_bcast_pkts += HILO_64_REGPAIR(pstats.sent_bcast_pkts);
1535 p_stats->tx_err_drop_pkts += HILO_64_REGPAIR(pstats.error_drop_pkts);
1538 static void __ecore_get_vport_tstats(struct ecore_hwfn *p_hwfn,
1539 struct ecore_ptt *p_ptt,
1540 struct ecore_eth_stats *p_stats,
1543 struct tstorm_per_port_stat tstats;
1544 u32 tstats_addr, tstats_len;
1546 if (IS_PF(p_hwfn->p_dev)) {
1547 tstats_addr = BAR0_MAP_REG_TSDM_RAM +
1548 TSTORM_PORT_STAT_OFFSET(MFW_PORT(p_hwfn));
1549 tstats_len = sizeof(struct tstorm_per_port_stat);
1551 struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1552 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1554 tstats_addr = p_resp->pfdev_info.stats_info.tstats.address;
1555 tstats_len = p_resp->pfdev_info.stats_info.tstats.len;
1558 OSAL_MEMSET(&tstats, 0, sizeof(tstats));
1559 ecore_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, tstats_len);
1561 p_stats->mftag_filter_discards +=
1562 HILO_64_REGPAIR(tstats.mftag_filter_discard);
1563 p_stats->mac_filter_discards +=
1564 HILO_64_REGPAIR(tstats.eth_mac_filter_discard);
1567 static void __ecore_get_vport_ustats_addrlen(struct ecore_hwfn *p_hwfn,
1568 u32 *p_addr, u32 *p_len,
1571 if (IS_PF(p_hwfn->p_dev)) {
1572 *p_addr = BAR0_MAP_REG_USDM_RAM +
1573 USTORM_QUEUE_STAT_OFFSET(statistics_bin);
1574 *p_len = sizeof(struct eth_ustorm_per_queue_stat);
1576 struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1577 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1579 *p_addr = p_resp->pfdev_info.stats_info.ustats.address;
1580 *p_len = p_resp->pfdev_info.stats_info.ustats.len;
1584 static void __ecore_get_vport_ustats(struct ecore_hwfn *p_hwfn,
1585 struct ecore_ptt *p_ptt,
1586 struct ecore_eth_stats *p_stats,
1589 struct eth_ustorm_per_queue_stat ustats;
1590 u32 ustats_addr = 0, ustats_len = 0;
1592 __ecore_get_vport_ustats_addrlen(p_hwfn, &ustats_addr, &ustats_len,
1595 OSAL_MEMSET(&ustats, 0, sizeof(ustats));
1596 ecore_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, ustats_len);
1598 p_stats->rx_ucast_bytes += HILO_64_REGPAIR(ustats.rcv_ucast_bytes);
1599 p_stats->rx_mcast_bytes += HILO_64_REGPAIR(ustats.rcv_mcast_bytes);
1600 p_stats->rx_bcast_bytes += HILO_64_REGPAIR(ustats.rcv_bcast_bytes);
1601 p_stats->rx_ucast_pkts += HILO_64_REGPAIR(ustats.rcv_ucast_pkts);
1602 p_stats->rx_mcast_pkts += HILO_64_REGPAIR(ustats.rcv_mcast_pkts);
1603 p_stats->rx_bcast_pkts += HILO_64_REGPAIR(ustats.rcv_bcast_pkts);
1606 static void __ecore_get_vport_mstats_addrlen(struct ecore_hwfn *p_hwfn,
1607 u32 *p_addr, u32 *p_len,
1610 if (IS_PF(p_hwfn->p_dev)) {
1611 *p_addr = BAR0_MAP_REG_MSDM_RAM +
1612 MSTORM_QUEUE_STAT_OFFSET(statistics_bin);
1613 *p_len = sizeof(struct eth_mstorm_per_queue_stat);
1615 struct ecore_vf_iov *p_iov = p_hwfn->vf_iov_info;
1616 struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
1618 *p_addr = p_resp->pfdev_info.stats_info.mstats.address;
1619 *p_len = p_resp->pfdev_info.stats_info.mstats.len;
1623 static void __ecore_get_vport_mstats(struct ecore_hwfn *p_hwfn,
1624 struct ecore_ptt *p_ptt,
1625 struct ecore_eth_stats *p_stats,
1628 struct eth_mstorm_per_queue_stat mstats;
1629 u32 mstats_addr = 0, mstats_len = 0;
1631 __ecore_get_vport_mstats_addrlen(p_hwfn, &mstats_addr, &mstats_len,
1634 OSAL_MEMSET(&mstats, 0, sizeof(mstats));
1635 ecore_memcpy_from(p_hwfn, p_ptt, &mstats, mstats_addr, mstats_len);
1637 p_stats->no_buff_discards += HILO_64_REGPAIR(mstats.no_buff_discard);
1638 p_stats->packet_too_big_discard +=
1639 HILO_64_REGPAIR(mstats.packet_too_big_discard);
1640 p_stats->ttl0_discard += HILO_64_REGPAIR(mstats.ttl0_discard);
1641 p_stats->tpa_coalesced_pkts +=
1642 HILO_64_REGPAIR(mstats.tpa_coalesced_pkts);
1643 p_stats->tpa_coalesced_events +=
1644 HILO_64_REGPAIR(mstats.tpa_coalesced_events);
1645 p_stats->tpa_aborts_num += HILO_64_REGPAIR(mstats.tpa_aborts_num);
1646 p_stats->tpa_coalesced_bytes +=
1647 HILO_64_REGPAIR(mstats.tpa_coalesced_bytes);
1650 static void __ecore_get_vport_port_stats(struct ecore_hwfn *p_hwfn,
1651 struct ecore_ptt *p_ptt,
1652 struct ecore_eth_stats *p_stats)
1654 struct port_stats port_stats;
1657 OSAL_MEMSET(&port_stats, 0, sizeof(port_stats));
1659 ecore_memcpy_from(p_hwfn, p_ptt, &port_stats,
1660 p_hwfn->mcp_info->port_addr +
1661 OFFSETOF(struct public_port, stats),
1662 sizeof(port_stats));
1664 p_stats->rx_64_byte_packets += port_stats.eth.r64;
1665 p_stats->rx_65_to_127_byte_packets += port_stats.eth.r127;
1666 p_stats->rx_128_to_255_byte_packets += port_stats.eth.r255;
1667 p_stats->rx_256_to_511_byte_packets += port_stats.eth.r511;
1668 p_stats->rx_512_to_1023_byte_packets += port_stats.eth.r1023;
1669 p_stats->rx_1024_to_1518_byte_packets += port_stats.eth.r1518;
1670 p_stats->rx_1519_to_1522_byte_packets += port_stats.eth.r1522;
1671 p_stats->rx_1519_to_2047_byte_packets += port_stats.eth.r2047;
1672 p_stats->rx_2048_to_4095_byte_packets += port_stats.eth.r4095;
1673 p_stats->rx_4096_to_9216_byte_packets += port_stats.eth.r9216;
1674 p_stats->rx_9217_to_16383_byte_packets += port_stats.eth.r16383;
1675 p_stats->rx_crc_errors += port_stats.eth.rfcs;
1676 p_stats->rx_mac_crtl_frames += port_stats.eth.rxcf;
1677 p_stats->rx_pause_frames += port_stats.eth.rxpf;
1678 p_stats->rx_pfc_frames += port_stats.eth.rxpp;
1679 p_stats->rx_align_errors += port_stats.eth.raln;
1680 p_stats->rx_carrier_errors += port_stats.eth.rfcr;
1681 p_stats->rx_oversize_packets += port_stats.eth.rovr;
1682 p_stats->rx_jabbers += port_stats.eth.rjbr;
1683 p_stats->rx_undersize_packets += port_stats.eth.rund;
1684 p_stats->rx_fragments += port_stats.eth.rfrg;
1685 p_stats->tx_64_byte_packets += port_stats.eth.t64;
1686 p_stats->tx_65_to_127_byte_packets += port_stats.eth.t127;
1687 p_stats->tx_128_to_255_byte_packets += port_stats.eth.t255;
1688 p_stats->tx_256_to_511_byte_packets += port_stats.eth.t511;
1689 p_stats->tx_512_to_1023_byte_packets += port_stats.eth.t1023;
1690 p_stats->tx_1024_to_1518_byte_packets += port_stats.eth.t1518;
1691 p_stats->tx_1519_to_2047_byte_packets += port_stats.eth.t2047;
1692 p_stats->tx_2048_to_4095_byte_packets += port_stats.eth.t4095;
1693 p_stats->tx_4096_to_9216_byte_packets += port_stats.eth.t9216;
1694 p_stats->tx_9217_to_16383_byte_packets += port_stats.eth.t16383;
1695 p_stats->tx_pause_frames += port_stats.eth.txpf;
1696 p_stats->tx_pfc_frames += port_stats.eth.txpp;
1697 p_stats->tx_lpi_entry_count += port_stats.eth.tlpiec;
1698 p_stats->tx_total_collisions += port_stats.eth.tncl;
1699 p_stats->rx_mac_bytes += port_stats.eth.rbyte;
1700 p_stats->rx_mac_uc_packets += port_stats.eth.rxuca;
1701 p_stats->rx_mac_mc_packets += port_stats.eth.rxmca;
1702 p_stats->rx_mac_bc_packets += port_stats.eth.rxbca;
1703 p_stats->rx_mac_frames_ok += port_stats.eth.rxpok;
1704 p_stats->tx_mac_bytes += port_stats.eth.tbyte;
1705 p_stats->tx_mac_uc_packets += port_stats.eth.txuca;
1706 p_stats->tx_mac_mc_packets += port_stats.eth.txmca;
1707 p_stats->tx_mac_bc_packets += port_stats.eth.txbca;
1708 p_stats->tx_mac_ctrl_frames += port_stats.eth.txcf;
1709 for (j = 0; j < 8; j++) {
1710 p_stats->brb_truncates += port_stats.brb.brb_truncate[j];
1711 p_stats->brb_discards += port_stats.brb.brb_discard[j];
1715 void __ecore_get_vport_stats(struct ecore_hwfn *p_hwfn,
1716 struct ecore_ptt *p_ptt,
1717 struct ecore_eth_stats *stats,
1718 u16 statistics_bin, bool b_get_port_stats)
1720 __ecore_get_vport_mstats(p_hwfn, p_ptt, stats, statistics_bin);
1721 __ecore_get_vport_ustats(p_hwfn, p_ptt, stats, statistics_bin);
1722 __ecore_get_vport_tstats(p_hwfn, p_ptt, stats, statistics_bin);
1723 __ecore_get_vport_pstats(p_hwfn, p_ptt, stats, statistics_bin);
1726 /* Avoid getting PORT stats for emulation. */
1727 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev))
1731 if (b_get_port_stats && p_hwfn->mcp_info)
1732 __ecore_get_vport_port_stats(p_hwfn, p_ptt, stats);
1735 static void _ecore_get_vport_stats(struct ecore_dev *p_dev,
1736 struct ecore_eth_stats *stats)
1741 OSAL_MEMSET(stats, 0, sizeof(*stats));
1743 for_each_hwfn(p_dev, i) {
1744 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1745 struct ecore_ptt *p_ptt = IS_PF(p_dev) ?
1746 ecore_ptt_acquire(p_hwfn) : OSAL_NULL;
1749 /* The main vport index is relative first */
1750 if (ecore_fw_vport(p_hwfn, 0, &fw_vport)) {
1751 DP_ERR(p_hwfn, "No vport available!\n");
1756 if (IS_PF(p_dev) && !p_ptt) {
1757 DP_ERR(p_hwfn, "Failed to acquire ptt\n");
1761 __ecore_get_vport_stats(p_hwfn, p_ptt, stats, fw_vport,
1762 IS_PF(p_dev) ? true : false);
1765 if (IS_PF(p_dev) && p_ptt)
1766 ecore_ptt_release(p_hwfn, p_ptt);
1770 void ecore_get_vport_stats(struct ecore_dev *p_dev,
1771 struct ecore_eth_stats *stats)
1776 OSAL_MEMSET(stats, 0, sizeof(*stats));
1780 _ecore_get_vport_stats(p_dev, stats);
1782 if (!p_dev->reset_stats)
1785 /* Reduce the statistics baseline */
1786 for (i = 0; i < sizeof(struct ecore_eth_stats) / sizeof(u64); i++)
1787 ((u64 *)stats)[i] -= ((u64 *)p_dev->reset_stats)[i];
1790 /* zeroes V-PORT specific portion of stats (Port stats remains untouched) */
1791 void ecore_reset_vport_stats(struct ecore_dev *p_dev)
1795 for_each_hwfn(p_dev, i) {
1796 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1797 struct eth_mstorm_per_queue_stat mstats;
1798 struct eth_ustorm_per_queue_stat ustats;
1799 struct eth_pstorm_per_queue_stat pstats;
1800 struct ecore_ptt *p_ptt = IS_PF(p_dev) ?
1801 ecore_ptt_acquire(p_hwfn) : OSAL_NULL;
1802 u32 addr = 0, len = 0;
1804 if (IS_PF(p_dev) && !p_ptt) {
1805 DP_ERR(p_hwfn, "Failed to acquire ptt\n");
1809 OSAL_MEMSET(&mstats, 0, sizeof(mstats));
1810 __ecore_get_vport_mstats_addrlen(p_hwfn, &addr, &len, 0);
1811 ecore_memcpy_to(p_hwfn, p_ptt, addr, &mstats, len);
1813 OSAL_MEMSET(&ustats, 0, sizeof(ustats));
1814 __ecore_get_vport_ustats_addrlen(p_hwfn, &addr, &len, 0);
1815 ecore_memcpy_to(p_hwfn, p_ptt, addr, &ustats, len);
1817 OSAL_MEMSET(&pstats, 0, sizeof(pstats));
1818 __ecore_get_vport_pstats_addrlen(p_hwfn, &addr, &len, 0);
1819 ecore_memcpy_to(p_hwfn, p_ptt, addr, &pstats, len);
1822 ecore_ptt_release(p_hwfn, p_ptt);
1825 /* PORT statistics are not necessarily reset, so we need to
1826 * read and create a baseline for future statistics.
1828 if (!p_dev->reset_stats)
1829 DP_INFO(p_dev, "Reset stats not allocated\n");
1831 _ecore_get_vport_stats(p_dev, p_dev->reset_stats);