2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
9 #include "qede_ethdev.h"
10 #include <rte_alarm.h>
11 #include <rte_version.h>
14 static const struct qed_eth_ops *qed_ops;
15 static int64_t timer_period = 1;
17 struct rte_qede_xstats_name_off {
18 char name[RTE_ETH_XSTATS_NAME_SIZE];
22 static const struct rte_qede_xstats_name_off qede_xstats_strings[] = {
23 {"rx_unicast_bytes", offsetof(struct ecore_eth_stats, rx_ucast_bytes)},
24 {"rx_multicast_bytes",
25 offsetof(struct ecore_eth_stats, rx_mcast_bytes)},
26 {"rx_broadcast_bytes",
27 offsetof(struct ecore_eth_stats, rx_bcast_bytes)},
28 {"rx_unicast_packets", offsetof(struct ecore_eth_stats, rx_ucast_pkts)},
29 {"rx_multicast_packets",
30 offsetof(struct ecore_eth_stats, rx_mcast_pkts)},
31 {"rx_broadcast_packets",
32 offsetof(struct ecore_eth_stats, rx_bcast_pkts)},
34 {"tx_unicast_bytes", offsetof(struct ecore_eth_stats, tx_ucast_bytes)},
35 {"tx_multicast_bytes",
36 offsetof(struct ecore_eth_stats, tx_mcast_bytes)},
37 {"tx_broadcast_bytes",
38 offsetof(struct ecore_eth_stats, tx_bcast_bytes)},
39 {"tx_unicast_packets", offsetof(struct ecore_eth_stats, tx_ucast_pkts)},
40 {"tx_multicast_packets",
41 offsetof(struct ecore_eth_stats, tx_mcast_pkts)},
42 {"tx_broadcast_packets",
43 offsetof(struct ecore_eth_stats, tx_bcast_pkts)},
45 {"rx_64_byte_packets",
46 offsetof(struct ecore_eth_stats, rx_64_byte_packets)},
47 {"rx_65_to_127_byte_packets",
48 offsetof(struct ecore_eth_stats, rx_65_to_127_byte_packets)},
49 {"rx_128_to_255_byte_packets",
50 offsetof(struct ecore_eth_stats, rx_128_to_255_byte_packets)},
51 {"rx_256_to_511_byte_packets",
52 offsetof(struct ecore_eth_stats, rx_256_to_511_byte_packets)},
53 {"rx_512_to_1023_byte_packets",
54 offsetof(struct ecore_eth_stats, rx_512_to_1023_byte_packets)},
55 {"rx_1024_to_1518_byte_packets",
56 offsetof(struct ecore_eth_stats, rx_1024_to_1518_byte_packets)},
57 {"rx_1519_to_1522_byte_packets",
58 offsetof(struct ecore_eth_stats, rx_1519_to_1522_byte_packets)},
59 {"rx_1519_to_2047_byte_packets",
60 offsetof(struct ecore_eth_stats, rx_1519_to_2047_byte_packets)},
61 {"rx_2048_to_4095_byte_packets",
62 offsetof(struct ecore_eth_stats, rx_2048_to_4095_byte_packets)},
63 {"rx_4096_to_9216_byte_packets",
64 offsetof(struct ecore_eth_stats, rx_4096_to_9216_byte_packets)},
65 {"rx_9217_to_16383_byte_packets",
66 offsetof(struct ecore_eth_stats,
67 rx_9217_to_16383_byte_packets)},
68 {"tx_64_byte_packets",
69 offsetof(struct ecore_eth_stats, tx_64_byte_packets)},
70 {"tx_65_to_127_byte_packets",
71 offsetof(struct ecore_eth_stats, tx_65_to_127_byte_packets)},
72 {"tx_128_to_255_byte_packets",
73 offsetof(struct ecore_eth_stats, tx_128_to_255_byte_packets)},
74 {"tx_256_to_511_byte_packets",
75 offsetof(struct ecore_eth_stats, tx_256_to_511_byte_packets)},
76 {"tx_512_to_1023_byte_packets",
77 offsetof(struct ecore_eth_stats, tx_512_to_1023_byte_packets)},
78 {"tx_1024_to_1518_byte_packets",
79 offsetof(struct ecore_eth_stats, tx_1024_to_1518_byte_packets)},
80 {"trx_1519_to_1522_byte_packets",
81 offsetof(struct ecore_eth_stats, tx_1519_to_2047_byte_packets)},
82 {"tx_2048_to_4095_byte_packets",
83 offsetof(struct ecore_eth_stats, tx_2048_to_4095_byte_packets)},
84 {"tx_4096_to_9216_byte_packets",
85 offsetof(struct ecore_eth_stats, tx_4096_to_9216_byte_packets)},
86 {"tx_9217_to_16383_byte_packets",
87 offsetof(struct ecore_eth_stats,
88 tx_9217_to_16383_byte_packets)},
90 {"rx_mac_crtl_frames",
91 offsetof(struct ecore_eth_stats, rx_mac_crtl_frames)},
92 {"tx_mac_control_frames",
93 offsetof(struct ecore_eth_stats, tx_mac_ctrl_frames)},
94 {"rx_pause_frames", offsetof(struct ecore_eth_stats, rx_pause_frames)},
95 {"tx_pause_frames", offsetof(struct ecore_eth_stats, tx_pause_frames)},
96 {"rx_priority_flow_control_frames",
97 offsetof(struct ecore_eth_stats, rx_pfc_frames)},
98 {"tx_priority_flow_control_frames",
99 offsetof(struct ecore_eth_stats, tx_pfc_frames)},
101 {"rx_crc_errors", offsetof(struct ecore_eth_stats, rx_crc_errors)},
102 {"rx_align_errors", offsetof(struct ecore_eth_stats, rx_align_errors)},
103 {"rx_carrier_errors",
104 offsetof(struct ecore_eth_stats, rx_carrier_errors)},
105 {"rx_oversize_packet_errors",
106 offsetof(struct ecore_eth_stats, rx_oversize_packets)},
107 {"rx_jabber_errors", offsetof(struct ecore_eth_stats, rx_jabbers)},
108 {"rx_undersize_packet_errors",
109 offsetof(struct ecore_eth_stats, rx_undersize_packets)},
110 {"rx_fragments", offsetof(struct ecore_eth_stats, rx_fragments)},
111 {"rx_host_buffer_not_available",
112 offsetof(struct ecore_eth_stats, no_buff_discards)},
113 /* Number of packets discarded because they are bigger than MTU */
114 {"rx_packet_too_big_discards",
115 offsetof(struct ecore_eth_stats, packet_too_big_discard)},
116 {"rx_ttl_zero_discards",
117 offsetof(struct ecore_eth_stats, ttl0_discard)},
118 {"rx_multi_function_tag_filter_discards",
119 offsetof(struct ecore_eth_stats, mftag_filter_discards)},
120 {"rx_mac_filter_discards",
121 offsetof(struct ecore_eth_stats, mac_filter_discards)},
122 {"rx_hw_buffer_truncates",
123 offsetof(struct ecore_eth_stats, brb_truncates)},
124 {"rx_hw_buffer_discards",
125 offsetof(struct ecore_eth_stats, brb_discards)},
126 {"tx_lpi_entry_count",
127 offsetof(struct ecore_eth_stats, tx_lpi_entry_count)},
128 {"tx_total_collisions",
129 offsetof(struct ecore_eth_stats, tx_total_collisions)},
130 {"tx_error_drop_packets",
131 offsetof(struct ecore_eth_stats, tx_err_drop_pkts)},
133 {"rx_mac_bytes", offsetof(struct ecore_eth_stats, rx_mac_bytes)},
134 {"rx_mac_unicast_packets",
135 offsetof(struct ecore_eth_stats, rx_mac_uc_packets)},
136 {"rx_mac_multicast_packets",
137 offsetof(struct ecore_eth_stats, rx_mac_mc_packets)},
138 {"rx_mac_broadcast_packets",
139 offsetof(struct ecore_eth_stats, rx_mac_bc_packets)},
141 offsetof(struct ecore_eth_stats, rx_mac_frames_ok)},
142 {"tx_mac_bytes", offsetof(struct ecore_eth_stats, tx_mac_bytes)},
143 {"tx_mac_unicast_packets",
144 offsetof(struct ecore_eth_stats, tx_mac_uc_packets)},
145 {"tx_mac_multicast_packets",
146 offsetof(struct ecore_eth_stats, tx_mac_mc_packets)},
147 {"tx_mac_broadcast_packets",
148 offsetof(struct ecore_eth_stats, tx_mac_bc_packets)},
150 {"lro_coalesced_packets",
151 offsetof(struct ecore_eth_stats, tpa_coalesced_pkts)},
152 {"lro_coalesced_events",
153 offsetof(struct ecore_eth_stats, tpa_coalesced_events)},
155 offsetof(struct ecore_eth_stats, tpa_aborts_num)},
156 {"lro_not_coalesced_packets",
157 offsetof(struct ecore_eth_stats, tpa_not_coalesced_pkts)},
158 {"lro_coalesced_bytes",
159 offsetof(struct ecore_eth_stats, tpa_coalesced_bytes)},
162 static const struct rte_qede_xstats_name_off qede_rxq_xstats_strings[] = {
164 offsetof(struct qede_rx_queue, rx_segs)},
166 offsetof(struct qede_rx_queue, rx_hw_errors)},
167 {"rx_q_allocation_errors",
168 offsetof(struct qede_rx_queue, rx_alloc_errors)}
171 static void qede_interrupt_action(struct ecore_hwfn *p_hwfn)
173 ecore_int_sp_dpc((osal_int_ptr_t)(p_hwfn));
177 qede_interrupt_handler(struct rte_intr_handle *handle, void *param)
179 struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
180 struct qede_dev *qdev = eth_dev->data->dev_private;
181 struct ecore_dev *edev = &qdev->edev;
183 qede_interrupt_action(ECORE_LEADING_HWFN(edev));
184 if (rte_intr_enable(handle))
185 DP_ERR(edev, "rte_intr_enable failed\n");
189 qede_alloc_etherdev(struct qede_dev *qdev, struct qed_dev_eth_info *info)
191 rte_memcpy(&qdev->dev_info, info, sizeof(*info));
192 qdev->num_tc = qdev->dev_info.num_tc;
196 static void qede_print_adapter_info(struct qede_dev *qdev)
198 struct ecore_dev *edev = &qdev->edev;
199 struct qed_dev_info *info = &qdev->dev_info.common;
200 static char drv_ver[QEDE_PMD_DRV_VER_STR_SIZE];
201 static char ver_str[QEDE_PMD_DRV_VER_STR_SIZE];
203 DP_INFO(edev, "*********************************\n");
204 DP_INFO(edev, " DPDK version:%s\n", rte_version());
205 DP_INFO(edev, " Chip details : %s%d\n",
206 ECORE_IS_BB(edev) ? "BB" : "AH",
207 CHIP_REV_IS_A0(edev) ? 0 : 1);
208 snprintf(ver_str, QEDE_PMD_DRV_VER_STR_SIZE, "%d.%d.%d.%d",
209 info->fw_major, info->fw_minor, info->fw_rev, info->fw_eng);
210 snprintf(drv_ver, QEDE_PMD_DRV_VER_STR_SIZE, "%s_%s",
211 ver_str, QEDE_PMD_VERSION);
212 DP_INFO(edev, " Driver version : %s\n", drv_ver);
213 DP_INFO(edev, " Firmware version : %s\n", ver_str);
215 snprintf(ver_str, MCP_DRV_VER_STR_SIZE,
217 (info->mfw_rev >> 24) & 0xff,
218 (info->mfw_rev >> 16) & 0xff,
219 (info->mfw_rev >> 8) & 0xff, (info->mfw_rev) & 0xff);
220 DP_INFO(edev, " Management Firmware version : %s\n", ver_str);
221 DP_INFO(edev, " Firmware file : %s\n", fw_file);
222 DP_INFO(edev, "*********************************\n");
225 static void qede_set_ucast_cmn_params(struct ecore_filter_ucast *ucast)
227 memset(ucast, 0, sizeof(struct ecore_filter_ucast));
228 ucast->is_rx_filter = true;
229 ucast->is_tx_filter = true;
230 /* ucast->assert_on_error = true; - For debug */
234 qede_ucast_filter(struct rte_eth_dev *eth_dev, struct ecore_filter_ucast *ucast,
237 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
238 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
239 struct qede_ucast_entry *tmp = NULL;
240 struct qede_ucast_entry *u;
241 struct ether_addr *mac_addr;
243 mac_addr = (struct ether_addr *)ucast->mac;
245 SLIST_FOREACH(tmp, &qdev->uc_list_head, list) {
246 if ((memcmp(mac_addr, &tmp->mac,
247 ETHER_ADDR_LEN) == 0) &&
248 ucast->vlan == tmp->vlan) {
249 DP_ERR(edev, "Unicast MAC is already added"
250 " with vlan = %u, vni = %u\n",
251 ucast->vlan, ucast->vni);
255 u = rte_malloc(NULL, sizeof(struct qede_ucast_entry),
256 RTE_CACHE_LINE_SIZE);
258 DP_ERR(edev, "Did not allocate memory for ucast\n");
261 ether_addr_copy(mac_addr, &u->mac);
262 u->vlan = ucast->vlan;
263 SLIST_INSERT_HEAD(&qdev->uc_list_head, u, list);
266 SLIST_FOREACH(tmp, &qdev->uc_list_head, list) {
267 if ((memcmp(mac_addr, &tmp->mac,
268 ETHER_ADDR_LEN) == 0) &&
269 ucast->vlan == tmp->vlan)
273 DP_INFO(edev, "Unicast MAC is not found\n");
276 SLIST_REMOVE(&qdev->uc_list_head, tmp, qede_ucast_entry, list);
284 qede_mcast_filter(struct rte_eth_dev *eth_dev, struct ecore_filter_ucast *mcast,
287 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
288 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
289 struct ether_addr *mac_addr;
290 struct qede_mcast_entry *tmp = NULL;
291 struct qede_mcast_entry *m;
293 mac_addr = (struct ether_addr *)mcast->mac;
295 SLIST_FOREACH(tmp, &qdev->mc_list_head, list) {
296 if (memcmp(mac_addr, &tmp->mac, ETHER_ADDR_LEN) == 0) {
298 "Multicast MAC is already added\n");
302 m = rte_malloc(NULL, sizeof(struct qede_mcast_entry),
303 RTE_CACHE_LINE_SIZE);
306 "Did not allocate memory for mcast\n");
309 ether_addr_copy(mac_addr, &m->mac);
310 SLIST_INSERT_HEAD(&qdev->mc_list_head, m, list);
313 SLIST_FOREACH(tmp, &qdev->mc_list_head, list) {
314 if (memcmp(mac_addr, &tmp->mac, ETHER_ADDR_LEN) == 0)
318 DP_INFO(edev, "Multicast mac is not found\n");
321 SLIST_REMOVE(&qdev->mc_list_head, tmp,
322 qede_mcast_entry, list);
329 static enum _ecore_status_t
330 qede_mac_int_ops(struct rte_eth_dev *eth_dev, struct ecore_filter_ucast *ucast,
333 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
334 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
335 enum _ecore_status_t rc;
336 struct ecore_filter_mcast mcast;
337 struct qede_mcast_entry *tmp;
341 if (is_multicast_ether_addr((struct ether_addr *)ucast->mac)) {
343 if (qdev->num_mc_addr >= ECORE_MAX_MC_ADDRS) {
345 "Mcast filter table limit exceeded, "
346 "Please enable mcast promisc mode\n");
350 rc = qede_mcast_filter(eth_dev, ucast, add);
352 DP_INFO(edev, "num_mc_addrs = %u\n", qdev->num_mc_addr);
353 memset(&mcast, 0, sizeof(mcast));
354 mcast.num_mc_addrs = qdev->num_mc_addr;
355 mcast.opcode = ECORE_FILTER_ADD;
356 SLIST_FOREACH(tmp, &qdev->mc_list_head, list) {
357 ether_addr_copy(&tmp->mac,
358 (struct ether_addr *)&mcast.mac[j]);
361 rc = ecore_filter_mcast_cmd(edev, &mcast,
362 ECORE_SPQ_MODE_CB, NULL);
364 if (rc != ECORE_SUCCESS) {
365 DP_ERR(edev, "Failed to add multicast filter"
366 " rc = %d, op = %d\n", rc, add);
368 } else { /* Unicast */
370 if (qdev->num_uc_addr >= qdev->dev_info.num_mac_addrs) {
372 "Ucast filter table limit exceeded,"
373 " Please enable promisc mode\n");
377 rc = qede_ucast_filter(eth_dev, ucast, add);
379 rc = ecore_filter_ucast_cmd(edev, ucast,
380 ECORE_SPQ_MODE_CB, NULL);
381 if (rc != ECORE_SUCCESS) {
382 DP_ERR(edev, "MAC filter failed, rc = %d, op = %d\n",
391 qede_mac_addr_add(struct rte_eth_dev *eth_dev, struct ether_addr *mac_addr,
392 uint32_t index, __rte_unused uint32_t pool)
394 struct ecore_filter_ucast ucast;
396 qede_set_ucast_cmn_params(&ucast);
397 ucast.type = ECORE_FILTER_MAC;
398 ether_addr_copy(mac_addr, (struct ether_addr *)&ucast.mac);
399 (void)qede_mac_int_ops(eth_dev, &ucast, 1);
403 qede_mac_addr_remove(struct rte_eth_dev *eth_dev, uint32_t index)
405 struct qede_dev *qdev = eth_dev->data->dev_private;
406 struct ecore_dev *edev = &qdev->edev;
407 struct ether_addr mac_addr;
408 struct ecore_filter_ucast ucast;
411 PMD_INIT_FUNC_TRACE(edev);
413 if (index >= qdev->dev_info.num_mac_addrs) {
414 DP_ERR(edev, "Index %u is above MAC filter limit %u\n",
415 index, qdev->dev_info.num_mac_addrs);
419 qede_set_ucast_cmn_params(&ucast);
420 ucast.opcode = ECORE_FILTER_REMOVE;
421 ucast.type = ECORE_FILTER_MAC;
423 /* Use the index maintained by rte */
424 ether_addr_copy(ð_dev->data->mac_addrs[index],
425 (struct ether_addr *)&ucast.mac);
427 ecore_filter_ucast_cmd(edev, &ucast, ECORE_SPQ_MODE_CB, NULL);
431 qede_mac_addr_set(struct rte_eth_dev *eth_dev, struct ether_addr *mac_addr)
433 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
434 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
435 struct ecore_filter_ucast ucast;
438 if (IS_VF(edev) && !ecore_vf_check_mac(ECORE_LEADING_HWFN(edev),
439 mac_addr->addr_bytes)) {
440 DP_ERR(edev, "Setting MAC address is not allowed\n");
441 ether_addr_copy(&qdev->primary_mac,
442 ð_dev->data->mac_addrs[0]);
446 /* First remove the primary mac */
447 qede_set_ucast_cmn_params(&ucast);
448 ucast.opcode = ECORE_FILTER_REMOVE;
449 ucast.type = ECORE_FILTER_MAC;
450 ether_addr_copy(&qdev->primary_mac,
451 (struct ether_addr *)&ucast.mac);
452 rc = ecore_filter_ucast_cmd(edev, &ucast, ECORE_SPQ_MODE_CB, NULL);
454 DP_ERR(edev, "Unable to remove current macaddr"
455 " Reverting to previous default mac\n");
456 ether_addr_copy(&qdev->primary_mac,
457 ð_dev->data->mac_addrs[0]);
462 ucast.opcode = ECORE_FILTER_ADD;
463 ether_addr_copy(mac_addr, (struct ether_addr *)&ucast.mac);
464 rc = ecore_filter_ucast_cmd(edev, &ucast, ECORE_SPQ_MODE_CB, NULL);
466 DP_ERR(edev, "Unable to add new default mac\n");
468 ether_addr_copy(mac_addr, &qdev->primary_mac);
471 static void qede_config_accept_any_vlan(struct qede_dev *qdev, bool action)
473 struct ecore_dev *edev = &qdev->edev;
474 struct qed_update_vport_params params = {
476 .accept_any_vlan = action,
477 .update_accept_any_vlan_flg = 1,
481 /* Proceed only if action actually needs to be performed */
482 if (qdev->accept_any_vlan == action)
485 rc = qdev->ops->vport_update(edev, ¶ms);
487 DP_ERR(edev, "Failed to %s accept-any-vlan\n",
488 action ? "enable" : "disable");
490 DP_INFO(edev, "%s accept-any-vlan\n",
491 action ? "enabled" : "disabled");
492 qdev->accept_any_vlan = action;
496 static int qede_vlan_stripping(struct rte_eth_dev *eth_dev, bool set_stripping)
498 struct qed_update_vport_params vport_update_params;
499 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
500 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
503 memset(&vport_update_params, 0, sizeof(vport_update_params));
504 vport_update_params.vport_id = 0;
505 vport_update_params.update_inner_vlan_removal_flg = 1;
506 vport_update_params.inner_vlan_removal_flg = set_stripping;
507 rc = qdev->ops->vport_update(edev, &vport_update_params);
509 DP_ERR(edev, "Update V-PORT failed %d\n", rc);
516 static void qede_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
518 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
519 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
520 struct rte_eth_rxmode *rxmode = ð_dev->data->dev_conf.rxmode;
522 if (mask & ETH_VLAN_STRIP_MASK) {
523 if (rxmode->hw_vlan_strip)
524 (void)qede_vlan_stripping(eth_dev, 1);
526 (void)qede_vlan_stripping(eth_dev, 0);
529 if (mask & ETH_VLAN_FILTER_MASK) {
530 /* VLAN filtering kicks in when a VLAN is added */
531 if (rxmode->hw_vlan_filter) {
532 qede_vlan_filter_set(eth_dev, 0, 1);
534 if (qdev->configured_vlans > 1) { /* Excluding VLAN0 */
535 DP_NOTICE(edev, false,
536 " Please remove existing VLAN filters"
537 " before disabling VLAN filtering\n");
538 /* Signal app that VLAN filtering is still
541 rxmode->hw_vlan_filter = true;
543 qede_vlan_filter_set(eth_dev, 0, 0);
548 if (mask & ETH_VLAN_EXTEND_MASK)
549 DP_INFO(edev, "No offloads are supported with VLAN Q-in-Q"
550 " and classification is based on outer tag only\n");
552 DP_INFO(edev, "vlan offload mask %d vlan-strip %d vlan-filter %d\n",
553 mask, rxmode->hw_vlan_strip, rxmode->hw_vlan_filter);
556 static int qede_vlan_filter_set(struct rte_eth_dev *eth_dev,
557 uint16_t vlan_id, int on)
559 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
560 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
561 struct qed_dev_eth_info *dev_info = &qdev->dev_info;
562 struct qede_vlan_entry *tmp = NULL;
563 struct qede_vlan_entry *vlan;
564 struct ecore_filter_ucast ucast;
568 if (qdev->configured_vlans == dev_info->num_vlan_filters) {
569 DP_INFO(edev, "Reached max VLAN filter limit"
570 " enabling accept_any_vlan\n");
571 qede_config_accept_any_vlan(qdev, true);
575 SLIST_FOREACH(tmp, &qdev->vlan_list_head, list) {
576 if (tmp->vid == vlan_id) {
577 DP_ERR(edev, "VLAN %u already configured\n",
583 vlan = rte_malloc(NULL, sizeof(struct qede_vlan_entry),
584 RTE_CACHE_LINE_SIZE);
587 DP_ERR(edev, "Did not allocate memory for VLAN\n");
591 qede_set_ucast_cmn_params(&ucast);
592 ucast.opcode = ECORE_FILTER_ADD;
593 ucast.type = ECORE_FILTER_VLAN;
594 ucast.vlan = vlan_id;
595 rc = ecore_filter_ucast_cmd(edev, &ucast, ECORE_SPQ_MODE_CB,
598 DP_ERR(edev, "Failed to add VLAN %u rc %d\n", vlan_id,
603 SLIST_INSERT_HEAD(&qdev->vlan_list_head, vlan, list);
604 qdev->configured_vlans++;
605 DP_INFO(edev, "VLAN %u added, configured_vlans %u\n",
606 vlan_id, qdev->configured_vlans);
609 SLIST_FOREACH(tmp, &qdev->vlan_list_head, list) {
610 if (tmp->vid == vlan_id)
615 if (qdev->configured_vlans == 0) {
617 "No VLAN filters configured yet\n");
621 DP_ERR(edev, "VLAN %u not configured\n", vlan_id);
625 SLIST_REMOVE(&qdev->vlan_list_head, tmp, qede_vlan_entry, list);
627 qede_set_ucast_cmn_params(&ucast);
628 ucast.opcode = ECORE_FILTER_REMOVE;
629 ucast.type = ECORE_FILTER_VLAN;
630 ucast.vlan = vlan_id;
631 rc = ecore_filter_ucast_cmd(edev, &ucast, ECORE_SPQ_MODE_CB,
634 DP_ERR(edev, "Failed to delete VLAN %u rc %d\n",
637 qdev->configured_vlans--;
638 DP_INFO(edev, "VLAN %u removed configured_vlans %u\n",
639 vlan_id, qdev->configured_vlans);
646 static int qede_init_vport(struct qede_dev *qdev)
648 struct ecore_dev *edev = &qdev->edev;
649 struct qed_start_vport_params start = {0};
652 start.remove_inner_vlan = 1;
653 start.gro_enable = 0;
654 start.mtu = ETHER_MTU + QEDE_ETH_OVERHEAD;
656 start.drop_ttl0 = false;
657 start.clear_stats = 1;
658 start.handle_ptp_pkts = 0;
660 rc = qdev->ops->vport_start(edev, &start);
662 DP_ERR(edev, "Start V-PORT failed %d\n", rc);
667 "Start vport ramrod passed, vport_id = %d, MTU = %u\n",
668 start.vport_id, ETHER_MTU);
673 static int qede_dev_configure(struct rte_eth_dev *eth_dev)
675 struct qede_dev *qdev = eth_dev->data->dev_private;
676 struct ecore_dev *edev = &qdev->edev;
677 struct rte_eth_rxmode *rxmode = ð_dev->data->dev_conf.rxmode;
680 PMD_INIT_FUNC_TRACE(edev);
682 /* Check requirements for 100G mode */
683 if (edev->num_hwfns > 1) {
684 if (eth_dev->data->nb_rx_queues < 2 ||
685 eth_dev->data->nb_tx_queues < 2) {
686 DP_NOTICE(edev, false,
687 "100G mode needs min. 2 RX/TX queues\n");
691 if ((eth_dev->data->nb_rx_queues % 2 != 0) ||
692 (eth_dev->data->nb_tx_queues % 2 != 0)) {
693 DP_NOTICE(edev, false,
694 "100G mode needs even no. of RX/TX queues\n");
699 /* Sanity checks and throw warnings */
700 if (rxmode->enable_scatter == 1)
701 eth_dev->data->scattered_rx = 1;
703 if (rxmode->enable_lro == 1) {
704 DP_INFO(edev, "LRO is not supported\n");
708 if (!rxmode->hw_strip_crc)
709 DP_INFO(edev, "L2 CRC stripping is always enabled in hw\n");
711 if (!rxmode->hw_ip_checksum)
712 DP_INFO(edev, "IP/UDP/TCP checksum offload is always enabled "
715 /* Check for the port restart case */
716 if (qdev->state != QEDE_DEV_INIT) {
717 rc = qdev->ops->vport_stop(edev, 0);
720 qede_dealloc_fp_resc(eth_dev);
723 qdev->fp_num_tx = eth_dev->data->nb_tx_queues;
724 qdev->fp_num_rx = eth_dev->data->nb_rx_queues;
725 qdev->num_queues = qdev->fp_num_tx + qdev->fp_num_rx;
727 /* Fastpath status block should be initialized before sending
728 * VPORT-START in the case of VF. Anyway, do it for both VF/PF.
730 rc = qede_alloc_fp_resc(qdev);
734 /* Issue VPORT-START with default config values to allow
735 * other port configurations early on.
737 rc = qede_init_vport(qdev);
741 SLIST_INIT(&qdev->vlan_list_head);
743 /* Add primary mac for PF */
745 qede_mac_addr_set(eth_dev, &qdev->primary_mac);
747 /* Enable VLAN offloads by default */
748 qede_vlan_offload_set(eth_dev, ETH_VLAN_STRIP_MASK |
749 ETH_VLAN_FILTER_MASK |
750 ETH_VLAN_EXTEND_MASK);
752 qdev->state = QEDE_DEV_CONFIG;
754 DP_INFO(edev, "Allocated RSS=%d TSS=%d (with CoS=%d)\n",
755 (int)QEDE_RSS_COUNT(qdev), (int)QEDE_TSS_COUNT(qdev),
761 /* Info about HW descriptor ring limitations */
762 static const struct rte_eth_desc_lim qede_rx_desc_lim = {
763 .nb_max = NUM_RX_BDS_MAX,
765 .nb_align = 128 /* lowest common multiple */
768 static const struct rte_eth_desc_lim qede_tx_desc_lim = {
769 .nb_max = NUM_TX_BDS_MAX,
775 qede_dev_info_get(struct rte_eth_dev *eth_dev,
776 struct rte_eth_dev_info *dev_info)
778 struct qede_dev *qdev = eth_dev->data->dev_private;
779 struct ecore_dev *edev = &qdev->edev;
780 struct qed_link_output link;
781 uint32_t speed_cap = 0;
783 PMD_INIT_FUNC_TRACE(edev);
785 dev_info->pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
786 dev_info->min_rx_bufsize = (uint32_t)(ETHER_MIN_MTU +
788 dev_info->max_rx_pktlen = (uint32_t)ETH_TX_MAX_NON_LSO_PKT_LEN;
789 dev_info->rx_desc_lim = qede_rx_desc_lim;
790 dev_info->tx_desc_lim = qede_tx_desc_lim;
791 dev_info->max_rx_queues = (uint16_t)QEDE_MAX_RSS_CNT(qdev);
792 dev_info->max_tx_queues = dev_info->max_rx_queues;
793 dev_info->max_mac_addrs = qdev->dev_info.num_mac_addrs;
795 dev_info->max_vfs = 0;
797 dev_info->max_vfs = (uint16_t)NUM_OF_VFS(&qdev->edev);
798 dev_info->reta_size = ECORE_RSS_IND_TABLE_SIZE;
799 dev_info->flow_type_rss_offloads = (uint64_t)QEDE_RSS_OFFLOAD_ALL;
801 dev_info->default_txconf = (struct rte_eth_txconf) {
802 .txq_flags = QEDE_TXQ_FLAGS,
805 dev_info->rx_offload_capa = (DEV_RX_OFFLOAD_VLAN_STRIP |
806 DEV_RX_OFFLOAD_IPV4_CKSUM |
807 DEV_RX_OFFLOAD_UDP_CKSUM |
808 DEV_RX_OFFLOAD_TCP_CKSUM);
809 dev_info->tx_offload_capa = (DEV_TX_OFFLOAD_VLAN_INSERT |
810 DEV_TX_OFFLOAD_IPV4_CKSUM |
811 DEV_TX_OFFLOAD_UDP_CKSUM |
812 DEV_TX_OFFLOAD_TCP_CKSUM);
814 memset(&link, 0, sizeof(struct qed_link_output));
815 qdev->ops->common->get_link(edev, &link);
816 if (link.adv_speed & NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
817 speed_cap |= ETH_LINK_SPEED_1G;
818 if (link.adv_speed & NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
819 speed_cap |= ETH_LINK_SPEED_10G;
820 if (link.adv_speed & NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
821 speed_cap |= ETH_LINK_SPEED_25G;
822 if (link.adv_speed & NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
823 speed_cap |= ETH_LINK_SPEED_40G;
824 if (link.adv_speed & NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
825 speed_cap |= ETH_LINK_SPEED_50G;
826 if (link.adv_speed & NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
827 speed_cap |= ETH_LINK_SPEED_100G;
828 dev_info->speed_capa = speed_cap;
831 /* return 0 means link status changed, -1 means not changed */
833 qede_link_update(struct rte_eth_dev *eth_dev, __rte_unused int wait_to_complete)
835 struct qede_dev *qdev = eth_dev->data->dev_private;
836 struct ecore_dev *edev = &qdev->edev;
837 uint16_t link_duplex;
838 struct qed_link_output link;
839 struct rte_eth_link *curr = ð_dev->data->dev_link;
841 memset(&link, 0, sizeof(struct qed_link_output));
842 qdev->ops->common->get_link(edev, &link);
845 curr->link_speed = link.speed;
848 switch (link.duplex) {
849 case QEDE_DUPLEX_HALF:
850 link_duplex = ETH_LINK_HALF_DUPLEX;
852 case QEDE_DUPLEX_FULL:
853 link_duplex = ETH_LINK_FULL_DUPLEX;
855 case QEDE_DUPLEX_UNKNOWN:
859 curr->link_duplex = link_duplex;
862 curr->link_status = (link.link_up) ? ETH_LINK_UP : ETH_LINK_DOWN;
865 curr->link_autoneg = (link.supported_caps & QEDE_SUPPORTED_AUTONEG) ?
866 ETH_LINK_AUTONEG : ETH_LINK_FIXED;
868 DP_INFO(edev, "Link - Speed %u Mode %u AN %u Status %u\n",
869 curr->link_speed, curr->link_duplex,
870 curr->link_autoneg, curr->link_status);
872 /* return 0 means link status changed, -1 means not changed */
873 return ((curr->link_status == link.link_up) ? -1 : 0);
876 static void qede_promiscuous_enable(struct rte_eth_dev *eth_dev)
878 struct qede_dev *qdev = eth_dev->data->dev_private;
879 struct ecore_dev *edev = &qdev->edev;
881 PMD_INIT_FUNC_TRACE(edev);
883 enum qed_filter_rx_mode_type type = QED_FILTER_RX_MODE_TYPE_PROMISC;
885 if (rte_eth_allmulticast_get(eth_dev->data->port_id) == 1)
886 type |= QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC;
888 qed_configure_filter_rx_mode(eth_dev, type);
891 static void qede_promiscuous_disable(struct rte_eth_dev *eth_dev)
893 struct qede_dev *qdev = eth_dev->data->dev_private;
894 struct ecore_dev *edev = &qdev->edev;
896 PMD_INIT_FUNC_TRACE(edev);
898 if (rte_eth_allmulticast_get(eth_dev->data->port_id) == 1)
899 qed_configure_filter_rx_mode(eth_dev,
900 QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC);
902 qed_configure_filter_rx_mode(eth_dev,
903 QED_FILTER_RX_MODE_TYPE_REGULAR);
906 static void qede_poll_sp_sb_cb(void *param)
908 struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
909 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
910 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
913 qede_interrupt_action(ECORE_LEADING_HWFN(edev));
914 qede_interrupt_action(&edev->hwfns[1]);
916 rc = rte_eal_alarm_set(timer_period * US_PER_S,
920 DP_ERR(edev, "Unable to start periodic"
921 " timer rc %d\n", rc);
922 assert(false && "Unable to start periodic timer");
926 static void qede_dev_close(struct rte_eth_dev *eth_dev)
928 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
929 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
930 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
933 PMD_INIT_FUNC_TRACE(edev);
935 /* dev_stop() shall cleanup fp resources in hw but without releasing
936 * dma memories and sw structures so that dev_start() can be called
937 * by the app without reconfiguration. However, in dev_close() we
938 * can release all the resources and device can be brought up newly
940 if (qdev->state != QEDE_DEV_STOP)
941 qede_dev_stop(eth_dev);
943 DP_INFO(edev, "Device is already stopped\n");
945 rc = qdev->ops->vport_stop(edev, 0);
947 DP_ERR(edev, "Failed to stop VPORT\n");
949 qede_dealloc_fp_resc(eth_dev);
951 qdev->ops->common->slowpath_stop(edev);
953 qdev->ops->common->remove(edev);
955 rte_intr_disable(&pci_dev->intr_handle);
957 rte_intr_callback_unregister(&pci_dev->intr_handle,
958 qede_interrupt_handler, (void *)eth_dev);
960 if (edev->num_hwfns > 1)
961 rte_eal_alarm_cancel(qede_poll_sp_sb_cb, (void *)eth_dev);
963 qdev->state = QEDE_DEV_INIT; /* Go back to init state */
967 qede_get_stats(struct rte_eth_dev *eth_dev, struct rte_eth_stats *eth_stats)
969 struct qede_dev *qdev = eth_dev->data->dev_private;
970 struct ecore_dev *edev = &qdev->edev;
971 struct ecore_eth_stats stats;
972 unsigned int i = 0, j = 0, qid;
973 struct qede_tx_queue *txq;
975 qdev->ops->get_vport_stats(edev, &stats);
978 eth_stats->ipackets = stats.rx_ucast_pkts +
979 stats.rx_mcast_pkts + stats.rx_bcast_pkts;
981 eth_stats->ibytes = stats.rx_ucast_bytes +
982 stats.rx_mcast_bytes + stats.rx_bcast_bytes;
984 eth_stats->ierrors = stats.rx_crc_errors +
985 stats.rx_align_errors +
986 stats.rx_carrier_errors +
987 stats.rx_oversize_packets +
988 stats.rx_jabbers + stats.rx_undersize_packets;
990 eth_stats->rx_nombuf = stats.no_buff_discards;
992 eth_stats->imissed = stats.mftag_filter_discards +
993 stats.mac_filter_discards +
994 stats.no_buff_discards + stats.brb_truncates + stats.brb_discards;
997 eth_stats->opackets = stats.tx_ucast_pkts +
998 stats.tx_mcast_pkts + stats.tx_bcast_pkts;
1000 eth_stats->obytes = stats.tx_ucast_bytes +
1001 stats.tx_mcast_bytes + stats.tx_bcast_bytes;
1003 eth_stats->oerrors = stats.tx_err_drop_pkts;
1006 for (qid = 0; qid < QEDE_QUEUE_CNT(qdev); qid++) {
1007 if (qdev->fp_array[qid].type & QEDE_FASTPATH_RX) {
1008 eth_stats->q_ipackets[i] =
1010 ((char *)(qdev->fp_array[(qid)].rxq)) +
1011 offsetof(struct qede_rx_queue,
1013 eth_stats->q_errors[i] =
1015 ((char *)(qdev->fp_array[(qid)].rxq)) +
1016 offsetof(struct qede_rx_queue,
1019 ((char *)(qdev->fp_array[(qid)].rxq)) +
1020 offsetof(struct qede_rx_queue,
1025 if (qdev->fp_array[qid].type & QEDE_FASTPATH_TX) {
1026 txq = qdev->fp_array[(qid)].txqs[0];
1027 eth_stats->q_opackets[j] =
1028 *((uint64_t *)(uintptr_t)
1029 (((uint64_t)(uintptr_t)(txq)) +
1030 offsetof(struct qede_tx_queue,
1038 qede_get_xstats_count(struct qede_dev *qdev) {
1039 return RTE_DIM(qede_xstats_strings) +
1040 (RTE_DIM(qede_rxq_xstats_strings) * QEDE_RSS_COUNT(qdev));
1044 qede_get_xstats_names(__rte_unused struct rte_eth_dev *dev,
1045 struct rte_eth_xstat_name *xstats_names, unsigned limit)
1047 struct qede_dev *qdev = dev->data->dev_private;
1048 const unsigned int stat_cnt = qede_get_xstats_count(qdev);
1049 unsigned int i, qid, stat_idx = 0;
1051 if (xstats_names != NULL) {
1052 for (i = 0; i < RTE_DIM(qede_xstats_strings); i++) {
1053 snprintf(xstats_names[stat_idx].name,
1054 sizeof(xstats_names[stat_idx].name),
1056 qede_xstats_strings[i].name);
1060 for (qid = 0; qid < QEDE_RSS_COUNT(qdev); qid++) {
1061 for (i = 0; i < RTE_DIM(qede_rxq_xstats_strings); i++) {
1062 snprintf(xstats_names[stat_idx].name,
1063 sizeof(xstats_names[stat_idx].name),
1065 qede_rxq_xstats_strings[i].name, qid,
1066 qede_rxq_xstats_strings[i].name + 4);
1076 qede_get_xstats(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1079 struct qede_dev *qdev = dev->data->dev_private;
1080 struct ecore_dev *edev = &qdev->edev;
1081 struct ecore_eth_stats stats;
1082 const unsigned int num = qede_get_xstats_count(qdev);
1083 unsigned int i, qid, stat_idx = 0;
1088 qdev->ops->get_vport_stats(edev, &stats);
1090 for (i = 0; i < RTE_DIM(qede_xstats_strings); i++) {
1091 xstats[stat_idx].value = *(uint64_t *)(((char *)&stats) +
1092 qede_xstats_strings[i].offset);
1093 xstats[stat_idx].id = stat_idx;
1097 for (qid = 0; qid < QEDE_QUEUE_CNT(qdev); qid++) {
1098 if (qdev->fp_array[qid].type & QEDE_FASTPATH_RX) {
1099 for (i = 0; i < RTE_DIM(qede_rxq_xstats_strings); i++) {
1100 xstats[stat_idx].value = *(uint64_t *)(
1101 ((char *)(qdev->fp_array[(qid)].rxq)) +
1102 qede_rxq_xstats_strings[i].offset);
1103 xstats[stat_idx].id = stat_idx;
1113 qede_reset_xstats(struct rte_eth_dev *dev)
1115 struct qede_dev *qdev = dev->data->dev_private;
1116 struct ecore_dev *edev = &qdev->edev;
1118 ecore_reset_vport_stats(edev);
1121 int qede_dev_set_link_state(struct rte_eth_dev *eth_dev, bool link_up)
1123 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
1124 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
1125 struct qed_link_params link_params;
1128 DP_INFO(edev, "setting link state %d\n", link_up);
1129 memset(&link_params, 0, sizeof(link_params));
1130 link_params.link_up = link_up;
1131 rc = qdev->ops->common->set_link(edev, &link_params);
1132 if (rc != ECORE_SUCCESS)
1133 DP_ERR(edev, "Unable to set link state %d\n", link_up);
1138 static int qede_dev_set_link_up(struct rte_eth_dev *eth_dev)
1140 return qede_dev_set_link_state(eth_dev, true);
1143 static int qede_dev_set_link_down(struct rte_eth_dev *eth_dev)
1145 return qede_dev_set_link_state(eth_dev, false);
1148 static void qede_reset_stats(struct rte_eth_dev *eth_dev)
1150 struct qede_dev *qdev = eth_dev->data->dev_private;
1151 struct ecore_dev *edev = &qdev->edev;
1153 ecore_reset_vport_stats(edev);
1156 static void qede_allmulticast_enable(struct rte_eth_dev *eth_dev)
1158 enum qed_filter_rx_mode_type type =
1159 QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC;
1161 if (rte_eth_promiscuous_get(eth_dev->data->port_id) == 1)
1162 type |= QED_FILTER_RX_MODE_TYPE_PROMISC;
1164 qed_configure_filter_rx_mode(eth_dev, type);
1167 static void qede_allmulticast_disable(struct rte_eth_dev *eth_dev)
1169 if (rte_eth_promiscuous_get(eth_dev->data->port_id) == 1)
1170 qed_configure_filter_rx_mode(eth_dev,
1171 QED_FILTER_RX_MODE_TYPE_PROMISC);
1173 qed_configure_filter_rx_mode(eth_dev,
1174 QED_FILTER_RX_MODE_TYPE_REGULAR);
1177 static int qede_flow_ctrl_set(struct rte_eth_dev *eth_dev,
1178 struct rte_eth_fc_conf *fc_conf)
1180 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
1181 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
1182 struct qed_link_output current_link;
1183 struct qed_link_params params;
1185 memset(¤t_link, 0, sizeof(current_link));
1186 qdev->ops->common->get_link(edev, ¤t_link);
1188 memset(¶ms, 0, sizeof(params));
1189 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
1190 if (fc_conf->autoneg) {
1191 if (!(current_link.supported_caps & QEDE_SUPPORTED_AUTONEG)) {
1192 DP_ERR(edev, "Autoneg not supported\n");
1195 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
1198 /* Pause is assumed to be supported (SUPPORTED_Pause) */
1199 if (fc_conf->mode == RTE_FC_FULL)
1200 params.pause_config |= (QED_LINK_PAUSE_TX_ENABLE |
1201 QED_LINK_PAUSE_RX_ENABLE);
1202 if (fc_conf->mode == RTE_FC_TX_PAUSE)
1203 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
1204 if (fc_conf->mode == RTE_FC_RX_PAUSE)
1205 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
1207 params.link_up = true;
1208 (void)qdev->ops->common->set_link(edev, ¶ms);
1213 static int qede_flow_ctrl_get(struct rte_eth_dev *eth_dev,
1214 struct rte_eth_fc_conf *fc_conf)
1216 struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
1217 struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
1218 struct qed_link_output current_link;
1220 memset(¤t_link, 0, sizeof(current_link));
1221 qdev->ops->common->get_link(edev, ¤t_link);
1223 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
1224 fc_conf->autoneg = true;
1226 if (current_link.pause_config & (QED_LINK_PAUSE_RX_ENABLE |
1227 QED_LINK_PAUSE_TX_ENABLE))
1228 fc_conf->mode = RTE_FC_FULL;
1229 else if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
1230 fc_conf->mode = RTE_FC_RX_PAUSE;
1231 else if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
1232 fc_conf->mode = RTE_FC_TX_PAUSE;
1234 fc_conf->mode = RTE_FC_NONE;
1239 static const uint32_t *
1240 qede_dev_supported_ptypes_get(struct rte_eth_dev *eth_dev)
1242 static const uint32_t ptypes[] = {
1248 if (eth_dev->rx_pkt_burst == qede_recv_pkts)
1254 void qede_init_rss_caps(uint8_t *rss_caps, uint64_t hf)
1257 *rss_caps |= (hf & ETH_RSS_IPV4) ? ECORE_RSS_IPV4 : 0;
1258 *rss_caps |= (hf & ETH_RSS_IPV6) ? ECORE_RSS_IPV6 : 0;
1259 *rss_caps |= (hf & ETH_RSS_IPV6_EX) ? ECORE_RSS_IPV6 : 0;
1260 *rss_caps |= (hf & ETH_RSS_NONFRAG_IPV4_TCP) ? ECORE_RSS_IPV4_TCP : 0;
1261 *rss_caps |= (hf & ETH_RSS_NONFRAG_IPV6_TCP) ? ECORE_RSS_IPV6_TCP : 0;
1262 *rss_caps |= (hf & ETH_RSS_IPV6_TCP_EX) ? ECORE_RSS_IPV6_TCP : 0;
1265 static int qede_rss_hash_update(struct rte_eth_dev *eth_dev,
1266 struct rte_eth_rss_conf *rss_conf)
1268 struct qed_update_vport_params vport_update_params;
1269 struct qede_dev *qdev = eth_dev->data->dev_private;
1270 struct ecore_dev *edev = &qdev->edev;
1271 uint32_t *key = (uint32_t *)rss_conf->rss_key;
1272 uint64_t hf = rss_conf->rss_hf;
1275 memset(&vport_update_params, 0, sizeof(vport_update_params));
1279 qede_init_rss_caps(&qdev->rss_params.rss_caps, hf);
1280 memcpy(&vport_update_params.rss_params, &qdev->rss_params,
1281 sizeof(vport_update_params.rss_params));
1283 memcpy(qdev->rss_params.rss_key, rss_conf->rss_key,
1284 rss_conf->rss_key_len);
1285 vport_update_params.update_rss_flg = 1;
1286 qdev->rss_enabled = 1;
1289 qdev->rss_enabled = 0;
1292 /* If the mapping doesn't fit any supported, return */
1293 if (qdev->rss_params.rss_caps == 0 && hf != 0)
1296 DP_INFO(edev, "%s\n", (vport_update_params.update_rss_flg) ?
1297 "Enabling RSS" : "Disabling RSS");
1299 vport_update_params.vport_id = 0;
1301 return qdev->ops->vport_update(edev, &vport_update_params);
1304 int qede_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
1305 struct rte_eth_rss_conf *rss_conf)
1307 struct qede_dev *qdev = eth_dev->data->dev_private;
1310 if (rss_conf->rss_key_len < sizeof(qdev->rss_params.rss_key))
1313 if (rss_conf->rss_key)
1314 memcpy(rss_conf->rss_key, qdev->rss_params.rss_key,
1315 sizeof(qdev->rss_params.rss_key));
1318 hf |= (qdev->rss_params.rss_caps & ECORE_RSS_IPV4) ?
1320 hf |= (qdev->rss_params.rss_caps & ECORE_RSS_IPV6) ?
1322 hf |= (qdev->rss_params.rss_caps & ECORE_RSS_IPV6) ?
1323 ETH_RSS_IPV6_EX : 0;
1324 hf |= (qdev->rss_params.rss_caps & ECORE_RSS_IPV4_TCP) ?
1325 ETH_RSS_NONFRAG_IPV4_TCP : 0;
1326 hf |= (qdev->rss_params.rss_caps & ECORE_RSS_IPV6_TCP) ?
1327 ETH_RSS_NONFRAG_IPV6_TCP : 0;
1328 hf |= (qdev->rss_params.rss_caps & ECORE_RSS_IPV6_TCP) ?
1329 ETH_RSS_IPV6_TCP_EX : 0;
1331 rss_conf->rss_hf = hf;
1336 static int qede_rss_reta_update(struct rte_eth_dev *eth_dev,
1337 struct rte_eth_rss_reta_entry64 *reta_conf,
1340 struct qed_update_vport_params vport_update_params;
1341 struct qede_dev *qdev = eth_dev->data->dev_private;
1342 struct ecore_dev *edev = &qdev->edev;
1343 uint16_t i, idx, shift;
1345 if (reta_size > ETH_RSS_RETA_SIZE_128) {
1346 DP_ERR(edev, "reta_size %d is not supported by hardware\n",
1351 memset(&vport_update_params, 0, sizeof(vport_update_params));
1352 memcpy(&vport_update_params.rss_params, &qdev->rss_params,
1353 sizeof(vport_update_params.rss_params));
1355 for (i = 0; i < reta_size; i++) {
1356 idx = i / RTE_RETA_GROUP_SIZE;
1357 shift = i % RTE_RETA_GROUP_SIZE;
1358 if (reta_conf[idx].mask & (1ULL << shift)) {
1359 uint8_t entry = reta_conf[idx].reta[shift];
1360 qdev->rss_params.rss_ind_table[i] = entry;
1364 vport_update_params.update_rss_flg = 1;
1365 vport_update_params.vport_id = 0;
1367 return qdev->ops->vport_update(edev, &vport_update_params);
1370 int qede_rss_reta_query(struct rte_eth_dev *eth_dev,
1371 struct rte_eth_rss_reta_entry64 *reta_conf,
1374 struct qede_dev *qdev = eth_dev->data->dev_private;
1375 uint16_t i, idx, shift;
1377 if (reta_size > ETH_RSS_RETA_SIZE_128) {
1378 struct ecore_dev *edev = &qdev->edev;
1379 DP_ERR(edev, "reta_size %d is not supported\n",
1383 for (i = 0; i < reta_size; i++) {
1384 idx = i / RTE_RETA_GROUP_SIZE;
1385 shift = i % RTE_RETA_GROUP_SIZE;
1386 if (reta_conf[idx].mask & (1ULL << shift)) {
1387 uint8_t entry = qdev->rss_params.rss_ind_table[i];
1388 reta_conf[idx].reta[shift] = entry;
1395 int qede_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
1397 uint32_t frame_size;
1398 struct qede_dev *qdev = dev->data->dev_private;
1399 struct rte_eth_dev_info dev_info = {0};
1401 qede_dev_info_get(dev, &dev_info);
1404 frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN + 4;
1406 if ((mtu < ETHER_MIN_MTU) || (frame_size > dev_info.max_rx_pktlen))
1409 if (!dev->data->scattered_rx &&
1410 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)
1413 if (frame_size > ETHER_MAX_LEN)
1414 dev->data->dev_conf.rxmode.jumbo_frame = 1;
1416 dev->data->dev_conf.rxmode.jumbo_frame = 0;
1418 /* update max frame size */
1419 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1422 qede_dev_start(dev);
1427 static const struct eth_dev_ops qede_eth_dev_ops = {
1428 .dev_configure = qede_dev_configure,
1429 .dev_infos_get = qede_dev_info_get,
1430 .rx_queue_setup = qede_rx_queue_setup,
1431 .rx_queue_release = qede_rx_queue_release,
1432 .tx_queue_setup = qede_tx_queue_setup,
1433 .tx_queue_release = qede_tx_queue_release,
1434 .dev_start = qede_dev_start,
1435 .dev_set_link_up = qede_dev_set_link_up,
1436 .dev_set_link_down = qede_dev_set_link_down,
1437 .link_update = qede_link_update,
1438 .promiscuous_enable = qede_promiscuous_enable,
1439 .promiscuous_disable = qede_promiscuous_disable,
1440 .allmulticast_enable = qede_allmulticast_enable,
1441 .allmulticast_disable = qede_allmulticast_disable,
1442 .dev_stop = qede_dev_stop,
1443 .dev_close = qede_dev_close,
1444 .stats_get = qede_get_stats,
1445 .stats_reset = qede_reset_stats,
1446 .xstats_get = qede_get_xstats,
1447 .xstats_reset = qede_reset_xstats,
1448 .xstats_get_names = qede_get_xstats_names,
1449 .mac_addr_add = qede_mac_addr_add,
1450 .mac_addr_remove = qede_mac_addr_remove,
1451 .mac_addr_set = qede_mac_addr_set,
1452 .vlan_offload_set = qede_vlan_offload_set,
1453 .vlan_filter_set = qede_vlan_filter_set,
1454 .flow_ctrl_set = qede_flow_ctrl_set,
1455 .flow_ctrl_get = qede_flow_ctrl_get,
1456 .dev_supported_ptypes_get = qede_dev_supported_ptypes_get,
1457 .rss_hash_update = qede_rss_hash_update,
1458 .rss_hash_conf_get = qede_rss_hash_conf_get,
1459 .reta_update = qede_rss_reta_update,
1460 .reta_query = qede_rss_reta_query,
1461 .mtu_set = qede_set_mtu,
1464 static const struct eth_dev_ops qede_eth_vf_dev_ops = {
1465 .dev_configure = qede_dev_configure,
1466 .dev_infos_get = qede_dev_info_get,
1467 .rx_queue_setup = qede_rx_queue_setup,
1468 .rx_queue_release = qede_rx_queue_release,
1469 .tx_queue_setup = qede_tx_queue_setup,
1470 .tx_queue_release = qede_tx_queue_release,
1471 .dev_start = qede_dev_start,
1472 .dev_set_link_up = qede_dev_set_link_up,
1473 .dev_set_link_down = qede_dev_set_link_down,
1474 .link_update = qede_link_update,
1475 .promiscuous_enable = qede_promiscuous_enable,
1476 .promiscuous_disable = qede_promiscuous_disable,
1477 .allmulticast_enable = qede_allmulticast_enable,
1478 .allmulticast_disable = qede_allmulticast_disable,
1479 .dev_stop = qede_dev_stop,
1480 .dev_close = qede_dev_close,
1481 .stats_get = qede_get_stats,
1482 .stats_reset = qede_reset_stats,
1483 .xstats_get = qede_get_xstats,
1484 .xstats_reset = qede_reset_xstats,
1485 .xstats_get_names = qede_get_xstats_names,
1486 .vlan_offload_set = qede_vlan_offload_set,
1487 .vlan_filter_set = qede_vlan_filter_set,
1488 .dev_supported_ptypes_get = qede_dev_supported_ptypes_get,
1489 .rss_hash_update = qede_rss_hash_update,
1490 .rss_hash_conf_get = qede_rss_hash_conf_get,
1491 .reta_update = qede_rss_reta_update,
1492 .reta_query = qede_rss_reta_query,
1493 .mtu_set = qede_set_mtu,
1496 static void qede_update_pf_params(struct ecore_dev *edev)
1498 struct ecore_pf_params pf_params;
1500 memset(&pf_params, 0, sizeof(struct ecore_pf_params));
1501 pf_params.eth_pf_params.num_cons = 64;
1502 qed_ops->common->update_pf_params(edev, &pf_params);
1505 static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
1507 struct rte_pci_device *pci_dev;
1508 struct rte_pci_addr pci_addr;
1509 struct qede_dev *adapter;
1510 struct ecore_dev *edev;
1511 struct qed_dev_eth_info dev_info;
1512 struct qed_slowpath_params params;
1513 static bool do_once = true;
1514 uint8_t bulletin_change;
1515 uint8_t vf_mac[ETHER_ADDR_LEN];
1516 uint8_t is_mac_forced;
1518 /* Fix up ecore debug level */
1519 uint32_t dp_module = ~0 & ~ECORE_MSG_HW;
1520 uint8_t dp_level = ECORE_LEVEL_VERBOSE;
1521 uint32_t max_mac_addrs;
1524 /* Extract key data structures */
1525 adapter = eth_dev->data->dev_private;
1526 edev = &adapter->edev;
1527 pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
1528 pci_addr = pci_dev->addr;
1530 PMD_INIT_FUNC_TRACE(edev);
1532 snprintf(edev->name, NAME_SIZE, PCI_SHORT_PRI_FMT ":dpdk-port-%u",
1533 pci_addr.bus, pci_addr.devid, pci_addr.function,
1534 eth_dev->data->port_id);
1536 eth_dev->rx_pkt_burst = qede_recv_pkts;
1537 eth_dev->tx_pkt_burst = qede_xmit_pkts;
1539 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1540 DP_NOTICE(edev, false,
1541 "Skipping device init from secondary process\n");
1545 rte_eth_copy_pci_info(eth_dev, pci_dev);
1547 qed_ops = qed_get_eth_ops();
1549 DP_ERR(edev, "Failed to get qed_eth_ops_pass\n");
1553 DP_INFO(edev, "Starting qede probe\n");
1555 rc = qed_ops->common->probe(edev, pci_dev, QED_PROTOCOL_ETH,
1556 dp_module, dp_level, is_vf);
1559 DP_ERR(edev, "qede probe failed rc %d\n", rc);
1563 qede_update_pf_params(edev);
1565 rte_intr_callback_register(&pci_dev->intr_handle,
1566 qede_interrupt_handler, (void *)eth_dev);
1568 if (rte_intr_enable(&pci_dev->intr_handle)) {
1569 DP_ERR(edev, "rte_intr_enable() failed\n");
1573 /* Start the Slowpath-process */
1574 memset(¶ms, 0, sizeof(struct qed_slowpath_params));
1575 params.int_mode = ECORE_INT_MODE_MSIX;
1576 params.drv_major = QEDE_PMD_VERSION_MAJOR;
1577 params.drv_minor = QEDE_PMD_VERSION_MINOR;
1578 params.drv_rev = QEDE_PMD_VERSION_REVISION;
1579 params.drv_eng = QEDE_PMD_VERSION_PATCH;
1580 strncpy((char *)params.name, QEDE_PMD_VER_PREFIX,
1581 QEDE_PMD_DRV_VER_STR_SIZE);
1583 /* For CMT mode device do periodic polling for slowpath events.
1584 * This is required since uio device uses only one MSI-x
1585 * interrupt vector but we need one for each engine.
1587 if (edev->num_hwfns > 1 && IS_PF(edev)) {
1588 rc = rte_eal_alarm_set(timer_period * US_PER_S,
1592 DP_ERR(edev, "Unable to start periodic"
1593 " timer rc %d\n", rc);
1598 rc = qed_ops->common->slowpath_start(edev, ¶ms);
1600 DP_ERR(edev, "Cannot start slowpath rc = %d\n", rc);
1601 rte_eal_alarm_cancel(qede_poll_sp_sb_cb,
1606 rc = qed_ops->fill_dev_info(edev, &dev_info);
1608 DP_ERR(edev, "Cannot get device_info rc %d\n", rc);
1609 qed_ops->common->slowpath_stop(edev);
1610 qed_ops->common->remove(edev);
1611 rte_eal_alarm_cancel(qede_poll_sp_sb_cb,
1616 qede_alloc_etherdev(adapter, &dev_info);
1618 adapter->ops->common->set_id(edev, edev->name, QEDE_PMD_VERSION);
1621 adapter->dev_info.num_mac_addrs =
1622 (uint32_t)RESC_NUM(ECORE_LEADING_HWFN(edev),
1625 ecore_vf_get_num_mac_filters(ECORE_LEADING_HWFN(edev),
1626 &adapter->dev_info.num_mac_addrs);
1628 /* Allocate memory for storing MAC addr */
1629 eth_dev->data->mac_addrs = rte_zmalloc(edev->name,
1631 adapter->dev_info.num_mac_addrs),
1632 RTE_CACHE_LINE_SIZE);
1634 if (eth_dev->data->mac_addrs == NULL) {
1635 DP_ERR(edev, "Failed to allocate MAC address\n");
1636 qed_ops->common->slowpath_stop(edev);
1637 qed_ops->common->remove(edev);
1638 rte_eal_alarm_cancel(qede_poll_sp_sb_cb,
1644 ether_addr_copy((struct ether_addr *)edev->hwfns[0].
1645 hw_info.hw_mac_addr,
1646 ð_dev->data->mac_addrs[0]);
1647 ether_addr_copy(ð_dev->data->mac_addrs[0],
1648 &adapter->primary_mac);
1650 ecore_vf_read_bulletin(ECORE_LEADING_HWFN(edev),
1652 if (bulletin_change) {
1654 ecore_vf_bulletin_get_forced_mac(
1655 ECORE_LEADING_HWFN(edev),
1658 if (is_mac_exist && is_mac_forced) {
1659 DP_INFO(edev, "VF macaddr received from PF\n");
1660 ether_addr_copy((struct ether_addr *)&vf_mac,
1661 ð_dev->data->mac_addrs[0]);
1662 ether_addr_copy(ð_dev->data->mac_addrs[0],
1663 &adapter->primary_mac);
1665 DP_NOTICE(edev, false,
1666 "No VF macaddr assigned\n");
1671 eth_dev->dev_ops = (is_vf) ? &qede_eth_vf_dev_ops : &qede_eth_dev_ops;
1674 qede_print_adapter_info(adapter);
1678 adapter->state = QEDE_DEV_INIT;
1680 DP_NOTICE(edev, false, "MAC address : %02x:%02x:%02x:%02x:%02x:%02x\n",
1681 adapter->primary_mac.addr_bytes[0],
1682 adapter->primary_mac.addr_bytes[1],
1683 adapter->primary_mac.addr_bytes[2],
1684 adapter->primary_mac.addr_bytes[3],
1685 adapter->primary_mac.addr_bytes[4],
1686 adapter->primary_mac.addr_bytes[5]);
1691 static int qedevf_eth_dev_init(struct rte_eth_dev *eth_dev)
1693 return qede_common_dev_init(eth_dev, 1);
1696 static int qede_eth_dev_init(struct rte_eth_dev *eth_dev)
1698 return qede_common_dev_init(eth_dev, 0);
1701 static int qede_dev_common_uninit(struct rte_eth_dev *eth_dev)
1703 /* only uninitialize in the primary process */
1704 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1707 /* safe to close dev here */
1708 qede_dev_close(eth_dev);
1710 eth_dev->dev_ops = NULL;
1711 eth_dev->rx_pkt_burst = NULL;
1712 eth_dev->tx_pkt_burst = NULL;
1714 if (eth_dev->data->mac_addrs)
1715 rte_free(eth_dev->data->mac_addrs);
1717 eth_dev->data->mac_addrs = NULL;
1722 static int qede_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1724 return qede_dev_common_uninit(eth_dev);
1727 static int qedevf_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1729 return qede_dev_common_uninit(eth_dev);
1732 static struct rte_pci_id pci_id_qedevf_map[] = {
1733 #define QEDEVF_RTE_PCI_DEVICE(dev) RTE_PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, dev)
1735 QEDEVF_RTE_PCI_DEVICE(PCI_DEVICE_ID_NX2_VF)
1738 QEDEVF_RTE_PCI_DEVICE(PCI_DEVICE_ID_57980S_IOV)
1743 static struct rte_pci_id pci_id_qede_map[] = {
1744 #define QEDE_RTE_PCI_DEVICE(dev) RTE_PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, dev)
1746 QEDE_RTE_PCI_DEVICE(PCI_DEVICE_ID_NX2_57980E)
1749 QEDE_RTE_PCI_DEVICE(PCI_DEVICE_ID_NX2_57980S)
1752 QEDE_RTE_PCI_DEVICE(PCI_DEVICE_ID_57980S_40)
1755 QEDE_RTE_PCI_DEVICE(PCI_DEVICE_ID_57980S_25)
1758 QEDE_RTE_PCI_DEVICE(PCI_DEVICE_ID_57980S_100)
1763 static struct eth_driver rte_qedevf_pmd = {
1765 .id_table = pci_id_qedevf_map,
1767 RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1768 .probe = rte_eth_dev_pci_probe,
1769 .remove = rte_eth_dev_pci_remove,
1771 .eth_dev_init = qedevf_eth_dev_init,
1772 .eth_dev_uninit = qedevf_eth_dev_uninit,
1773 .dev_private_size = sizeof(struct qede_dev),
1776 static struct eth_driver rte_qede_pmd = {
1778 .id_table = pci_id_qede_map,
1780 RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1781 .probe = rte_eth_dev_pci_probe,
1782 .remove = rte_eth_dev_pci_remove,
1784 .eth_dev_init = qede_eth_dev_init,
1785 .eth_dev_uninit = qede_eth_dev_uninit,
1786 .dev_private_size = sizeof(struct qede_dev),
1789 RTE_PMD_REGISTER_PCI(net_qede, rte_qede_pmd.pci_drv);
1790 RTE_PMD_REGISTER_PCI_TABLE(net_qede, pci_id_qede_map);
1791 RTE_PMD_REGISTER_KMOD_DEP(net_qede, "* igb_uio | uio_pci_generic | vfio");
1792 RTE_PMD_REGISTER_PCI(net_qede_vf, rte_qedevf_pmd.pci_drv);
1793 RTE_PMD_REGISTER_PCI_TABLE(net_qede_vf, pci_id_qedevf_map);
1794 RTE_PMD_REGISTER_KMOD_DEP(net_qede_vf, "* igb_uio | vfio");