1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
5 #include <rte_ethdev.h>
6 #include <rte_ethdev_pci.h>
7 #include <rte_cycles.h>
8 #include <rte_malloc.h>
10 #include <rte_ether.h>
13 #include "lio_23xx_vf.h"
14 #include "lio_ethdev.h"
17 /* Default RSS key in use */
18 static uint8_t lio_rss_key[40] = {
19 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
20 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
21 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
22 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
23 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
26 static const struct rte_eth_desc_lim lio_rx_desc_lim = {
27 .nb_max = CN23XX_MAX_OQ_DESCRIPTORS,
28 .nb_min = CN23XX_MIN_OQ_DESCRIPTORS,
32 static const struct rte_eth_desc_lim lio_tx_desc_lim = {
33 .nb_max = CN23XX_MAX_IQ_DESCRIPTORS,
34 .nb_min = CN23XX_MIN_IQ_DESCRIPTORS,
38 /* Wait for control command to reach nic. */
40 lio_wait_for_ctrl_cmd(struct lio_device *lio_dev,
41 struct lio_dev_ctrl_cmd *ctrl_cmd)
43 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
45 while ((ctrl_cmd->cond == 0) && --timeout) {
46 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
54 * \brief Send Rx control command
55 * @param eth_dev Pointer to the structure rte_eth_dev
56 * @param start_stop whether to start or stop
59 lio_send_rx_ctrl_cmd(struct rte_eth_dev *eth_dev, int start_stop)
61 struct lio_device *lio_dev = LIO_DEV(eth_dev);
62 struct lio_dev_ctrl_cmd ctrl_cmd;
63 struct lio_ctrl_pkt ctrl_pkt;
65 /* flush added to prevent cmd failure
66 * incase the queue is full
68 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
70 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
71 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
73 ctrl_cmd.eth_dev = eth_dev;
76 ctrl_pkt.ncmd.s.cmd = LIO_CMD_RX_CTL;
77 ctrl_pkt.ncmd.s.param1 = start_stop;
78 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
80 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
81 lio_dev_err(lio_dev, "Failed to send RX Control message\n");
85 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
86 lio_dev_err(lio_dev, "RX Control command timed out\n");
93 /* store statistics names and its offset in stats structure */
94 struct rte_lio_xstats_name_off {
95 char name[RTE_ETH_XSTATS_NAME_SIZE];
99 static const struct rte_lio_xstats_name_off rte_lio_stats_strings[] = {
100 {"rx_pkts", offsetof(struct octeon_rx_stats, total_rcvd)},
101 {"rx_bytes", offsetof(struct octeon_rx_stats, bytes_rcvd)},
102 {"rx_broadcast_pkts", offsetof(struct octeon_rx_stats, total_bcst)},
103 {"rx_multicast_pkts", offsetof(struct octeon_rx_stats, total_mcst)},
104 {"rx_flow_ctrl_pkts", offsetof(struct octeon_rx_stats, ctl_rcvd)},
105 {"rx_fifo_err", offsetof(struct octeon_rx_stats, fifo_err)},
106 {"rx_dmac_drop", offsetof(struct octeon_rx_stats, dmac_drop)},
107 {"rx_fcs_err", offsetof(struct octeon_rx_stats, fcs_err)},
108 {"rx_jabber_err", offsetof(struct octeon_rx_stats, jabber_err)},
109 {"rx_l2_err", offsetof(struct octeon_rx_stats, l2_err)},
110 {"rx_vxlan_pkts", offsetof(struct octeon_rx_stats, fw_rx_vxlan)},
111 {"rx_vxlan_err", offsetof(struct octeon_rx_stats, fw_rx_vxlan_err)},
112 {"rx_lro_pkts", offsetof(struct octeon_rx_stats, fw_lro_pkts)},
113 {"tx_pkts", (offsetof(struct octeon_tx_stats, total_pkts_sent)) +
114 sizeof(struct octeon_rx_stats)},
115 {"tx_bytes", (offsetof(struct octeon_tx_stats, total_bytes_sent)) +
116 sizeof(struct octeon_rx_stats)},
117 {"tx_broadcast_pkts",
118 (offsetof(struct octeon_tx_stats, bcast_pkts_sent)) +
119 sizeof(struct octeon_rx_stats)},
120 {"tx_multicast_pkts",
121 (offsetof(struct octeon_tx_stats, mcast_pkts_sent)) +
122 sizeof(struct octeon_rx_stats)},
123 {"tx_flow_ctrl_pkts", (offsetof(struct octeon_tx_stats, ctl_sent)) +
124 sizeof(struct octeon_rx_stats)},
125 {"tx_fifo_err", (offsetof(struct octeon_tx_stats, fifo_err)) +
126 sizeof(struct octeon_rx_stats)},
127 {"tx_total_collisions", (offsetof(struct octeon_tx_stats,
129 sizeof(struct octeon_rx_stats)},
130 {"tx_tso", (offsetof(struct octeon_tx_stats, fw_tso)) +
131 sizeof(struct octeon_rx_stats)},
132 {"tx_vxlan_pkts", (offsetof(struct octeon_tx_stats, fw_tx_vxlan)) +
133 sizeof(struct octeon_rx_stats)},
136 #define LIO_NB_XSTATS RTE_DIM(rte_lio_stats_strings)
138 /* Get hw stats of the port */
140 lio_dev_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *xstats,
143 struct lio_device *lio_dev = LIO_DEV(eth_dev);
144 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
145 struct octeon_link_stats *hw_stats;
146 struct lio_link_stats_resp *resp;
147 struct lio_soft_command *sc;
152 if (!lio_dev->intf_open) {
153 lio_dev_err(lio_dev, "Port %d down\n",
158 if (n < LIO_NB_XSTATS)
159 return LIO_NB_XSTATS;
161 resp_size = sizeof(struct lio_link_stats_resp);
162 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
166 resp = (struct lio_link_stats_resp *)sc->virtrptr;
167 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
168 LIO_OPCODE_PORT_STATS, 0, 0, 0);
170 /* Setting wait time in seconds */
171 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
173 retval = lio_send_soft_command(lio_dev, sc);
174 if (retval == LIO_IQ_SEND_FAILED) {
175 lio_dev_err(lio_dev, "failed to get port stats from firmware. status: %x\n",
180 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
181 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
182 lio_process_ordered_list(lio_dev);
186 retval = resp->status;
188 lio_dev_err(lio_dev, "failed to get port stats from firmware\n");
192 lio_swap_8B_data((uint64_t *)(&resp->link_stats),
193 sizeof(struct octeon_link_stats) >> 3);
195 hw_stats = &resp->link_stats;
197 for (i = 0; i < LIO_NB_XSTATS; i++) {
200 *(uint64_t *)(((char *)hw_stats) +
201 rte_lio_stats_strings[i].offset);
204 lio_free_soft_command(sc);
206 return LIO_NB_XSTATS;
209 lio_free_soft_command(sc);
215 lio_dev_xstats_get_names(struct rte_eth_dev *eth_dev,
216 struct rte_eth_xstat_name *xstats_names,
217 unsigned limit __rte_unused)
219 struct lio_device *lio_dev = LIO_DEV(eth_dev);
222 if (!lio_dev->intf_open) {
223 lio_dev_err(lio_dev, "Port %d down\n",
228 if (xstats_names == NULL)
229 return LIO_NB_XSTATS;
231 /* Note: limit checked in rte_eth_xstats_names() */
233 for (i = 0; i < LIO_NB_XSTATS; i++) {
234 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
235 "%s", rte_lio_stats_strings[i].name);
238 return LIO_NB_XSTATS;
241 /* Reset hw stats for the port */
243 lio_dev_xstats_reset(struct rte_eth_dev *eth_dev)
245 struct lio_device *lio_dev = LIO_DEV(eth_dev);
246 struct lio_dev_ctrl_cmd ctrl_cmd;
247 struct lio_ctrl_pkt ctrl_pkt;
249 if (!lio_dev->intf_open) {
250 lio_dev_err(lio_dev, "Port %d down\n",
255 /* flush added to prevent cmd failure
256 * incase the queue is full
258 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
260 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
261 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
263 ctrl_cmd.eth_dev = eth_dev;
266 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CLEAR_STATS;
267 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
269 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
270 lio_dev_err(lio_dev, "Failed to send clear stats command\n");
274 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
275 lio_dev_err(lio_dev, "Clear stats command timed out\n");
279 /* clear stored per queue stats */
280 RTE_FUNC_PTR_OR_RET(*eth_dev->dev_ops->stats_reset);
281 (*eth_dev->dev_ops->stats_reset)(eth_dev);
284 /* Retrieve the device statistics (# packets in/out, # bytes in/out, etc */
286 lio_dev_stats_get(struct rte_eth_dev *eth_dev,
287 struct rte_eth_stats *stats)
289 struct lio_device *lio_dev = LIO_DEV(eth_dev);
290 struct lio_droq_stats *oq_stats;
291 struct lio_iq_stats *iq_stats;
292 struct lio_instr_queue *txq;
293 struct lio_droq *droq;
299 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
300 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
301 txq = lio_dev->instr_queue[iq_no];
303 iq_stats = &txq->stats;
304 pkts += iq_stats->tx_done;
305 drop += iq_stats->tx_dropped;
306 bytes += iq_stats->tx_tot_bytes;
310 stats->opackets = pkts;
311 stats->obytes = bytes;
312 stats->oerrors = drop;
318 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
319 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
320 droq = lio_dev->droq[oq_no];
322 oq_stats = &droq->stats;
323 pkts += oq_stats->rx_pkts_received;
324 drop += (oq_stats->rx_dropped +
325 oq_stats->dropped_toomany +
326 oq_stats->dropped_nomem);
327 bytes += oq_stats->rx_bytes_received;
330 stats->ibytes = bytes;
331 stats->ipackets = pkts;
332 stats->ierrors = drop;
338 lio_dev_stats_reset(struct rte_eth_dev *eth_dev)
340 struct lio_device *lio_dev = LIO_DEV(eth_dev);
341 struct lio_droq_stats *oq_stats;
342 struct lio_iq_stats *iq_stats;
343 struct lio_instr_queue *txq;
344 struct lio_droq *droq;
347 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
348 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
349 txq = lio_dev->instr_queue[iq_no];
351 iq_stats = &txq->stats;
352 memset(iq_stats, 0, sizeof(struct lio_iq_stats));
356 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
357 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
358 droq = lio_dev->droq[oq_no];
360 oq_stats = &droq->stats;
361 memset(oq_stats, 0, sizeof(struct lio_droq_stats));
367 lio_dev_info_get(struct rte_eth_dev *eth_dev,
368 struct rte_eth_dev_info *devinfo)
370 struct lio_device *lio_dev = LIO_DEV(eth_dev);
371 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
373 devinfo->pci_dev = pci_dev;
375 switch (pci_dev->id.subsystem_device_id) {
376 /* CN23xx 10G cards */
377 case PCI_SUBSYS_DEV_ID_CN2350_210:
378 case PCI_SUBSYS_DEV_ID_CN2360_210:
379 case PCI_SUBSYS_DEV_ID_CN2350_210SVPN3:
380 case PCI_SUBSYS_DEV_ID_CN2360_210SVPN3:
381 case PCI_SUBSYS_DEV_ID_CN2350_210SVPT:
382 case PCI_SUBSYS_DEV_ID_CN2360_210SVPT:
383 devinfo->speed_capa = ETH_LINK_SPEED_10G;
385 /* CN23xx 25G cards */
386 case PCI_SUBSYS_DEV_ID_CN2350_225:
387 case PCI_SUBSYS_DEV_ID_CN2360_225:
388 devinfo->speed_capa = ETH_LINK_SPEED_25G;
391 devinfo->speed_capa = ETH_LINK_SPEED_10G;
393 "Unknown CN23XX subsystem device id. Setting 10G as default link speed.\n");
396 devinfo->max_rx_queues = lio_dev->max_rx_queues;
397 devinfo->max_tx_queues = lio_dev->max_tx_queues;
399 devinfo->min_rx_bufsize = LIO_MIN_RX_BUF_SIZE;
400 devinfo->max_rx_pktlen = LIO_MAX_RX_PKTLEN;
402 devinfo->max_mac_addrs = 1;
404 devinfo->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
405 DEV_RX_OFFLOAD_UDP_CKSUM |
406 DEV_RX_OFFLOAD_TCP_CKSUM |
407 DEV_RX_OFFLOAD_VLAN_STRIP);
408 devinfo->tx_offload_capa = (DEV_TX_OFFLOAD_IPV4_CKSUM |
409 DEV_TX_OFFLOAD_UDP_CKSUM |
410 DEV_TX_OFFLOAD_TCP_CKSUM |
411 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM);
413 devinfo->rx_desc_lim = lio_rx_desc_lim;
414 devinfo->tx_desc_lim = lio_tx_desc_lim;
416 devinfo->reta_size = LIO_RSS_MAX_TABLE_SZ;
417 devinfo->hash_key_size = LIO_RSS_MAX_KEY_SZ;
418 devinfo->flow_type_rss_offloads = (ETH_RSS_IPV4 |
419 ETH_RSS_NONFRAG_IPV4_TCP |
421 ETH_RSS_NONFRAG_IPV6_TCP |
423 ETH_RSS_IPV6_TCP_EX);
427 lio_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
429 struct lio_device *lio_dev = LIO_DEV(eth_dev);
430 uint16_t pf_mtu = lio_dev->linfo.link.s.mtu;
431 uint32_t frame_len = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
432 struct lio_dev_ctrl_cmd ctrl_cmd;
433 struct lio_ctrl_pkt ctrl_pkt;
435 PMD_INIT_FUNC_TRACE();
437 if (!lio_dev->intf_open) {
438 lio_dev_err(lio_dev, "Port %d down, can't set MTU\n",
443 /* check if VF MTU is within allowed range.
444 * New value should not exceed PF MTU.
446 if ((mtu < ETHER_MIN_MTU) || (mtu > pf_mtu)) {
447 lio_dev_err(lio_dev, "VF MTU should be >= %d and <= %d\n",
448 ETHER_MIN_MTU, pf_mtu);
452 /* flush added to prevent cmd failure
453 * incase the queue is full
455 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
457 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
458 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
460 ctrl_cmd.eth_dev = eth_dev;
463 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CHANGE_MTU;
464 ctrl_pkt.ncmd.s.param1 = mtu;
465 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
467 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
468 lio_dev_err(lio_dev, "Failed to send command to change MTU\n");
472 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
473 lio_dev_err(lio_dev, "Command to change MTU timed out\n");
477 if (frame_len > ETHER_MAX_LEN)
478 eth_dev->data->dev_conf.rxmode.jumbo_frame = 1;
480 eth_dev->data->dev_conf.rxmode.jumbo_frame = 0;
482 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_len;
483 eth_dev->data->mtu = mtu;
489 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
490 struct rte_eth_rss_reta_entry64 *reta_conf,
493 struct lio_device *lio_dev = LIO_DEV(eth_dev);
494 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
495 struct lio_rss_set *rss_param;
496 struct lio_dev_ctrl_cmd ctrl_cmd;
497 struct lio_ctrl_pkt ctrl_pkt;
500 if (!lio_dev->intf_open) {
501 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
506 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
508 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
509 reta_size, LIO_RSS_MAX_TABLE_SZ);
513 /* flush added to prevent cmd failure
514 * incase the queue is full
516 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
518 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
519 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
521 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
523 ctrl_cmd.eth_dev = eth_dev;
526 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
527 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
528 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
530 rss_param->param.flags = 0xF;
531 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
532 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
534 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
535 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
536 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
537 index = (i * RTE_RETA_GROUP_SIZE) + j;
538 rss_state->itable[index] = reta_conf[i].reta[j];
543 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
544 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
546 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
548 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
549 lio_dev_err(lio_dev, "Failed to set rss hash\n");
553 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
554 lio_dev_err(lio_dev, "Set rss hash timed out\n");
562 lio_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
563 struct rte_eth_rss_reta_entry64 *reta_conf,
566 struct lio_device *lio_dev = LIO_DEV(eth_dev);
567 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
570 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
572 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
573 reta_size, LIO_RSS_MAX_TABLE_SZ);
577 num = reta_size / RTE_RETA_GROUP_SIZE;
579 for (i = 0; i < num; i++) {
580 memcpy(reta_conf->reta,
581 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
582 RTE_RETA_GROUP_SIZE);
590 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
591 struct rte_eth_rss_conf *rss_conf)
593 struct lio_device *lio_dev = LIO_DEV(eth_dev);
594 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
595 uint8_t *hash_key = NULL;
598 if (rss_state->hash_disable) {
599 lio_dev_info(lio_dev, "RSS disabled in nic\n");
600 rss_conf->rss_hf = 0;
605 hash_key = rss_conf->rss_key;
606 if (hash_key != NULL)
607 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
610 rss_hf |= ETH_RSS_IPV4;
611 if (rss_state->tcp_hash)
612 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
614 rss_hf |= ETH_RSS_IPV6;
615 if (rss_state->ipv6_tcp_hash)
616 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
617 if (rss_state->ipv6_ex)
618 rss_hf |= ETH_RSS_IPV6_EX;
619 if (rss_state->ipv6_tcp_ex_hash)
620 rss_hf |= ETH_RSS_IPV6_TCP_EX;
622 rss_conf->rss_hf = rss_hf;
628 lio_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
629 struct rte_eth_rss_conf *rss_conf)
631 struct lio_device *lio_dev = LIO_DEV(eth_dev);
632 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
633 struct lio_rss_set *rss_param;
634 struct lio_dev_ctrl_cmd ctrl_cmd;
635 struct lio_ctrl_pkt ctrl_pkt;
637 if (!lio_dev->intf_open) {
638 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
643 /* flush added to prevent cmd failure
644 * incase the queue is full
646 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
648 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
649 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
651 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
653 ctrl_cmd.eth_dev = eth_dev;
656 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
657 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
658 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
660 rss_param->param.flags = 0xF;
662 if (rss_conf->rss_key) {
663 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
664 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
665 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
666 memcpy(rss_state->hash_key, rss_conf->rss_key,
667 rss_state->hash_key_size);
668 memcpy(rss_param->key, rss_state->hash_key,
669 rss_state->hash_key_size);
672 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
673 /* Can't disable rss through hash flags,
674 * if it is enabled by default during init
676 if (!rss_state->hash_disable)
679 /* This is for --disable-rss during testpmd launch */
680 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
682 uint32_t hashinfo = 0;
684 /* Can't enable rss if disabled by default during init */
685 if (rss_state->hash_disable)
688 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
689 hashinfo |= LIO_RSS_HASH_IPV4;
695 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
696 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
697 rss_state->tcp_hash = 1;
699 rss_state->tcp_hash = 0;
702 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
703 hashinfo |= LIO_RSS_HASH_IPV6;
709 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
710 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
711 rss_state->ipv6_tcp_hash = 1;
713 rss_state->ipv6_tcp_hash = 0;
716 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
717 hashinfo |= LIO_RSS_HASH_IPV6_EX;
718 rss_state->ipv6_ex = 1;
720 rss_state->ipv6_ex = 0;
723 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
724 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
725 rss_state->ipv6_tcp_ex_hash = 1;
727 rss_state->ipv6_tcp_ex_hash = 0;
730 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
731 rss_param->param.hashinfo = hashinfo;
734 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
736 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
737 lio_dev_err(lio_dev, "Failed to set rss hash\n");
741 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
742 lio_dev_err(lio_dev, "Set rss hash timed out\n");
750 * Add vxlan dest udp port for an interface.
753 * Pointer to the structure rte_eth_dev
758 * On success return 0
759 * On failure return -1
762 lio_dev_udp_tunnel_add(struct rte_eth_dev *eth_dev,
763 struct rte_eth_udp_tunnel *udp_tnl)
765 struct lio_device *lio_dev = LIO_DEV(eth_dev);
766 struct lio_dev_ctrl_cmd ctrl_cmd;
767 struct lio_ctrl_pkt ctrl_pkt;
772 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
773 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
777 /* flush added to prevent cmd failure
778 * incase the queue is full
780 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
782 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
783 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
785 ctrl_cmd.eth_dev = eth_dev;
788 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
789 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
790 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_ADD;
791 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
793 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
794 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_ADD command\n");
798 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
799 lio_dev_err(lio_dev, "VXLAN_PORT_ADD command timed out\n");
807 * Remove vxlan dest udp port for an interface.
810 * Pointer to the structure rte_eth_dev
815 * On success return 0
816 * On failure return -1
819 lio_dev_udp_tunnel_del(struct rte_eth_dev *eth_dev,
820 struct rte_eth_udp_tunnel *udp_tnl)
822 struct lio_device *lio_dev = LIO_DEV(eth_dev);
823 struct lio_dev_ctrl_cmd ctrl_cmd;
824 struct lio_ctrl_pkt ctrl_pkt;
829 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
830 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
834 /* flush added to prevent cmd failure
835 * incase the queue is full
837 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
839 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
840 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
842 ctrl_cmd.eth_dev = eth_dev;
845 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
846 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
847 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_DEL;
848 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
850 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
851 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_DEL command\n");
855 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
856 lio_dev_err(lio_dev, "VXLAN_PORT_DEL command timed out\n");
864 lio_dev_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id, int on)
866 struct lio_device *lio_dev = LIO_DEV(eth_dev);
867 struct lio_dev_ctrl_cmd ctrl_cmd;
868 struct lio_ctrl_pkt ctrl_pkt;
870 if (lio_dev->linfo.vlan_is_admin_assigned)
873 /* flush added to prevent cmd failure
874 * incase the queue is full
876 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
878 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
879 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
881 ctrl_cmd.eth_dev = eth_dev;
884 ctrl_pkt.ncmd.s.cmd = on ?
885 LIO_CMD_ADD_VLAN_FILTER : LIO_CMD_DEL_VLAN_FILTER;
886 ctrl_pkt.ncmd.s.param1 = vlan_id;
887 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
889 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
890 lio_dev_err(lio_dev, "Failed to %s VLAN port\n",
891 on ? "add" : "remove");
895 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
896 lio_dev_err(lio_dev, "Command to %s VLAN port timed out\n",
897 on ? "add" : "remove");
905 * Atomically writes the link status information into global
906 * structure rte_eth_dev.
909 * - Pointer to the structure rte_eth_dev to read from.
910 * - Pointer to the buffer to be saved with the link status.
913 * - On success, zero.
914 * - On failure, negative value.
917 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
918 struct rte_eth_link *link)
920 struct rte_eth_link *dst = ð_dev->data->dev_link;
921 struct rte_eth_link *src = link;
923 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
924 *(uint64_t *)src) == 0)
931 lio_hweight64(uint64_t w)
933 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
936 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
937 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
938 res = res + (res >> 8);
939 res = res + (res >> 16);
941 return (res + (res >> 32)) & 0x00000000000000FFul;
945 lio_dev_link_update(struct rte_eth_dev *eth_dev,
946 int wait_to_complete __rte_unused)
948 struct lio_device *lio_dev = LIO_DEV(eth_dev);
949 struct rte_eth_link link, old;
952 link.link_status = ETH_LINK_DOWN;
953 link.link_speed = ETH_SPEED_NUM_NONE;
954 link.link_duplex = ETH_LINK_HALF_DUPLEX;
955 link.link_autoneg = ETH_LINK_AUTONEG;
956 memset(&old, 0, sizeof(old));
958 /* Return what we found */
959 if (lio_dev->linfo.link.s.link_up == 0) {
960 /* Interface is down */
961 if (lio_dev_atomic_write_link_status(eth_dev, &link))
963 if (link.link_status == old.link_status)
968 link.link_status = ETH_LINK_UP; /* Interface is up */
969 link.link_duplex = ETH_LINK_FULL_DUPLEX;
970 switch (lio_dev->linfo.link.s.speed) {
971 case LIO_LINK_SPEED_10000:
972 link.link_speed = ETH_SPEED_NUM_10G;
974 case LIO_LINK_SPEED_25000:
975 link.link_speed = ETH_SPEED_NUM_25G;
978 link.link_speed = ETH_SPEED_NUM_NONE;
979 link.link_duplex = ETH_LINK_HALF_DUPLEX;
982 if (lio_dev_atomic_write_link_status(eth_dev, &link))
985 if (link.link_status == old.link_status)
992 * \brief Net device enable, disable allmulticast
993 * @param eth_dev Pointer to the structure rte_eth_dev
996 lio_change_dev_flag(struct rte_eth_dev *eth_dev)
998 struct lio_device *lio_dev = LIO_DEV(eth_dev);
999 struct lio_dev_ctrl_cmd ctrl_cmd;
1000 struct lio_ctrl_pkt ctrl_pkt;
1002 /* flush added to prevent cmd failure
1003 * incase the queue is full
1005 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1007 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1008 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1010 ctrl_cmd.eth_dev = eth_dev;
1013 /* Create a ctrl pkt command to be sent to core app. */
1014 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CHANGE_DEVFLAGS;
1015 ctrl_pkt.ncmd.s.param1 = lio_dev->ifflags;
1016 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1018 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1019 lio_dev_err(lio_dev, "Failed to send change flag message\n");
1023 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1024 lio_dev_err(lio_dev, "Change dev flag command timed out\n");
1028 lio_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
1030 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1032 if (strcmp(lio_dev->firmware_version, LIO_VF_TRUST_MIN_VERSION) < 0) {
1033 lio_dev_err(lio_dev, "Require firmware version >= %s\n",
1034 LIO_VF_TRUST_MIN_VERSION);
1038 if (!lio_dev->intf_open) {
1039 lio_dev_err(lio_dev, "Port %d down, can't enable promiscuous\n",
1044 lio_dev->ifflags |= LIO_IFFLAG_PROMISC;
1045 lio_change_dev_flag(eth_dev);
1049 lio_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
1051 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1053 if (strcmp(lio_dev->firmware_version, LIO_VF_TRUST_MIN_VERSION) < 0) {
1054 lio_dev_err(lio_dev, "Require firmware version >= %s\n",
1055 LIO_VF_TRUST_MIN_VERSION);
1059 if (!lio_dev->intf_open) {
1060 lio_dev_err(lio_dev, "Port %d down, can't disable promiscuous\n",
1065 lio_dev->ifflags &= ~LIO_IFFLAG_PROMISC;
1066 lio_change_dev_flag(eth_dev);
1070 lio_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
1072 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1074 if (!lio_dev->intf_open) {
1075 lio_dev_err(lio_dev, "Port %d down, can't enable multicast\n",
1080 lio_dev->ifflags |= LIO_IFFLAG_ALLMULTI;
1081 lio_change_dev_flag(eth_dev);
1085 lio_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
1087 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1089 if (!lio_dev->intf_open) {
1090 lio_dev_err(lio_dev, "Port %d down, can't disable multicast\n",
1095 lio_dev->ifflags &= ~LIO_IFFLAG_ALLMULTI;
1096 lio_change_dev_flag(eth_dev);
1100 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
1102 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1103 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1104 struct rte_eth_rss_reta_entry64 reta_conf[8];
1105 struct rte_eth_rss_conf rss_conf;
1108 /* Configure the RSS key and the RSS protocols used to compute
1109 * the RSS hash of input packets.
1111 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
1112 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
1113 rss_state->hash_disable = 1;
1114 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1118 if (rss_conf.rss_key == NULL)
1119 rss_conf.rss_key = lio_rss_key; /* Default hash key */
1121 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1123 memset(reta_conf, 0, sizeof(reta_conf));
1124 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
1125 uint8_t q_idx, conf_idx, reta_idx;
1127 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
1128 i % eth_dev->data->nb_rx_queues : 0);
1129 conf_idx = i / RTE_RETA_GROUP_SIZE;
1130 reta_idx = i % RTE_RETA_GROUP_SIZE;
1131 reta_conf[conf_idx].reta[reta_idx] = q_idx;
1132 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
1135 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
1139 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
1141 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1142 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1143 struct rte_eth_rss_conf rss_conf;
1145 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
1147 lio_dev_rss_configure(eth_dev);
1149 case ETH_MQ_RX_NONE:
1150 /* if mq_mode is none, disable rss mode. */
1152 memset(&rss_conf, 0, sizeof(rss_conf));
1153 rss_state->hash_disable = 1;
1154 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1159 * Setup our receive queue/ringbuffer. This is the
1160 * queue the Octeon uses to send us packets and
1161 * responses. We are given a memory pool for our
1162 * packet buffers that are used to populate the receive
1166 * Pointer to the structure rte_eth_dev
1169 * @param num_rx_descs
1170 * Number of entries in the queue
1172 * Where to allocate memory
1174 * Pointer to the struction rte_eth_rxconf
1176 * Pointer to the packet pool
1179 * - On success, return 0
1180 * - On failure, return -1
1183 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1184 uint16_t num_rx_descs, unsigned int socket_id,
1185 const struct rte_eth_rxconf *rx_conf __rte_unused,
1186 struct rte_mempool *mp)
1188 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1189 struct rte_pktmbuf_pool_private *mbp_priv;
1190 uint32_t fw_mapped_oq;
1193 if (q_no >= lio_dev->nb_rx_queues) {
1194 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
1198 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
1200 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
1202 /* Free previous allocation if any */
1203 if (eth_dev->data->rx_queues[q_no] != NULL) {
1204 lio_dev_rx_queue_release(eth_dev->data->rx_queues[q_no]);
1205 eth_dev->data->rx_queues[q_no] = NULL;
1208 mbp_priv = rte_mempool_get_priv(mp);
1209 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
1211 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
1213 lio_dev_err(lio_dev, "droq allocation failed\n");
1217 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
1223 * Release the receive queue/ringbuffer. Called by
1227 * Opaque pointer to the receive queue to release
1233 lio_dev_rx_queue_release(void *rxq)
1235 struct lio_droq *droq = rxq;
1240 lio_delete_droq_queue(droq->lio_dev, oq_no);
1245 * Allocate and initialize SW ring. Initialize associated HW registers.
1248 * Pointer to structure rte_eth_dev
1253 * @param num_tx_descs
1254 * Number of ringbuffer descriptors
1257 * NUMA socket id, used for memory allocations
1260 * Pointer to the structure rte_eth_txconf
1263 * - On success, return 0
1264 * - On failure, return -errno value
1267 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1268 uint16_t num_tx_descs, unsigned int socket_id,
1269 const struct rte_eth_txconf *tx_conf __rte_unused)
1271 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1272 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
1275 if (q_no >= lio_dev->nb_tx_queues) {
1276 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
1280 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
1282 /* Free previous allocation if any */
1283 if (eth_dev->data->tx_queues[q_no] != NULL) {
1284 lio_dev_tx_queue_release(eth_dev->data->tx_queues[q_no]);
1285 eth_dev->data->tx_queues[q_no] = NULL;
1288 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
1289 num_tx_descs, lio_dev, socket_id);
1292 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
1296 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
1297 lio_dev->instr_queue[fw_mapped_iq]->nb_desc,
1301 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
1305 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
1311 * Release the transmit queue/ringbuffer. Called by
1315 * Opaque pointer to the transmit queue to release
1321 lio_dev_tx_queue_release(void *txq)
1323 struct lio_instr_queue *tq = txq;
1324 uint32_t fw_mapped_iq_no;
1329 lio_delete_sglist(tq);
1331 fw_mapped_iq_no = tq->txpciq.s.q_no;
1332 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
1337 * Api to check link state.
1340 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
1342 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1343 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1344 struct lio_link_status_resp *resp;
1345 union octeon_link_status *ls;
1346 struct lio_soft_command *sc;
1349 if (!lio_dev->intf_open)
1352 resp_size = sizeof(struct lio_link_status_resp);
1353 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1357 resp = (struct lio_link_status_resp *)sc->virtrptr;
1358 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1359 LIO_OPCODE_INFO, 0, 0, 0);
1361 /* Setting wait time in seconds */
1362 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1364 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
1365 goto get_status_fail;
1367 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1368 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1373 goto get_status_fail;
1375 ls = &resp->link_info.link;
1377 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
1379 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
1380 if (ls->s.mtu < eth_dev->data->mtu) {
1381 lio_dev_info(lio_dev, "Lowered VF MTU to %d as PF MTU dropped\n",
1383 eth_dev->data->mtu = ls->s.mtu;
1385 lio_dev->linfo.link.link_status64 = ls->link_status64;
1386 lio_dev_link_update(eth_dev, 0);
1389 lio_free_soft_command(sc);
1394 lio_free_soft_command(sc);
1397 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
1398 * and will update link state if it changes.
1401 lio_sync_link_state_check(void *eth_dev)
1403 struct lio_device *lio_dev =
1404 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
1406 if (lio_dev->port_configured)
1407 lio_dev_get_link_status(eth_dev);
1409 /* Schedule periodic link status check.
1410 * Stop check if interface is close and start again while opening.
1412 if (lio_dev->intf_open)
1413 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
1418 lio_dev_start(struct rte_eth_dev *eth_dev)
1421 uint32_t frame_len = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
1422 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1423 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1426 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
1428 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1431 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
1434 /* Ready for link status updates */
1435 lio_dev->intf_open = 1;
1438 /* Configure RSS if device configured with multiple RX queues. */
1439 lio_dev_mq_rx_configure(eth_dev);
1441 /* start polling for lsc */
1442 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
1443 lio_sync_link_state_check,
1446 lio_dev_err(lio_dev,
1447 "link state check handler creation failed\n");
1448 goto dev_lsc_handle_error;
1451 while ((lio_dev->linfo.link.link_status64 == 0) && (--timeout))
1454 if (lio_dev->linfo.link.link_status64 == 0) {
1456 goto dev_mtu_set_error;
1459 mtu = (uint16_t)(frame_len - ETHER_HDR_LEN - ETHER_CRC_LEN);
1460 if (mtu < ETHER_MIN_MTU)
1461 mtu = ETHER_MIN_MTU;
1463 if (eth_dev->data->mtu != mtu) {
1464 ret = lio_dev_mtu_set(eth_dev, mtu);
1466 goto dev_mtu_set_error;
1472 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1474 dev_lsc_handle_error:
1475 lio_dev->intf_open = 0;
1476 lio_send_rx_ctrl_cmd(eth_dev, 0);
1481 /* Stop device and disable input/output functions */
1483 lio_dev_stop(struct rte_eth_dev *eth_dev)
1485 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1487 lio_dev_info(lio_dev, "Stopping port %d\n", eth_dev->data->port_id);
1488 lio_dev->intf_open = 0;
1491 /* Cancel callback if still running. */
1492 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1494 lio_send_rx_ctrl_cmd(eth_dev, 0);
1496 lio_wait_for_instr_fetch(lio_dev);
1498 /* Clear recorded link status */
1499 lio_dev->linfo.link.link_status64 = 0;
1503 lio_dev_set_link_up(struct rte_eth_dev *eth_dev)
1505 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1507 if (!lio_dev->intf_open) {
1508 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1512 if (lio_dev->linfo.link.s.link_up) {
1513 lio_dev_info(lio_dev, "Link is already UP\n");
1517 if (lio_send_rx_ctrl_cmd(eth_dev, 1)) {
1518 lio_dev_err(lio_dev, "Unable to set Link UP\n");
1522 lio_dev->linfo.link.s.link_up = 1;
1523 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1529 lio_dev_set_link_down(struct rte_eth_dev *eth_dev)
1531 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1533 if (!lio_dev->intf_open) {
1534 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1538 if (!lio_dev->linfo.link.s.link_up) {
1539 lio_dev_info(lio_dev, "Link is already DOWN\n");
1543 lio_dev->linfo.link.s.link_up = 0;
1544 eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
1546 if (lio_send_rx_ctrl_cmd(eth_dev, 0)) {
1547 lio_dev->linfo.link.s.link_up = 1;
1548 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1549 lio_dev_err(lio_dev, "Unable to set Link Down\n");
1557 * Reset and stop the device. This occurs on the first
1558 * call to this routine. Subsequent calls will simply
1559 * return. NB: This will require the NIC to be rebooted.
1562 * Pointer to the structure rte_eth_dev
1568 lio_dev_close(struct rte_eth_dev *eth_dev)
1570 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1572 lio_dev_info(lio_dev, "closing port %d\n", eth_dev->data->port_id);
1574 if (lio_dev->intf_open)
1575 lio_dev_stop(eth_dev);
1577 /* Reset ioq regs */
1578 lio_dev->fn_list.setup_device_regs(lio_dev);
1580 if (lio_dev->pci_dev->kdrv == RTE_KDRV_IGB_UIO) {
1581 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1582 rte_delay_ms(LIO_PCI_FLR_WAIT);
1586 lio_dev->fn_list.free_mbox(lio_dev);
1588 /* Free glist resources */
1589 rte_free(lio_dev->glist_head);
1590 rte_free(lio_dev->glist_lock);
1591 lio_dev->glist_head = NULL;
1592 lio_dev->glist_lock = NULL;
1594 lio_dev->port_configured = 0;
1596 /* Delete all queues */
1597 lio_dev_clear_queues(eth_dev);
1601 * Enable tunnel rx checksum verification from firmware.
1604 lio_enable_hw_tunnel_rx_checksum(struct rte_eth_dev *eth_dev)
1606 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1607 struct lio_dev_ctrl_cmd ctrl_cmd;
1608 struct lio_ctrl_pkt ctrl_pkt;
1610 /* flush added to prevent cmd failure
1611 * incase the queue is full
1613 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1615 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1616 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1618 ctrl_cmd.eth_dev = eth_dev;
1621 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_RX_CSUM_CTL;
1622 ctrl_pkt.ncmd.s.param1 = LIO_CMD_RXCSUM_ENABLE;
1623 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1625 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1626 lio_dev_err(lio_dev, "Failed to send TNL_RX_CSUM command\n");
1630 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1631 lio_dev_err(lio_dev, "TNL_RX_CSUM command timed out\n");
1635 * Enable checksum calculation for inner packet in a tunnel.
1638 lio_enable_hw_tunnel_tx_checksum(struct rte_eth_dev *eth_dev)
1640 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1641 struct lio_dev_ctrl_cmd ctrl_cmd;
1642 struct lio_ctrl_pkt ctrl_pkt;
1644 /* flush added to prevent cmd failure
1645 * incase the queue is full
1647 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1649 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1650 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1652 ctrl_cmd.eth_dev = eth_dev;
1655 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_TX_CSUM_CTL;
1656 ctrl_pkt.ncmd.s.param1 = LIO_CMD_TXCSUM_ENABLE;
1657 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1659 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1660 lio_dev_err(lio_dev, "Failed to send TNL_TX_CSUM command\n");
1664 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1665 lio_dev_err(lio_dev, "TNL_TX_CSUM command timed out\n");
1669 lio_send_queue_count_update(struct rte_eth_dev *eth_dev, int num_txq,
1672 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1673 struct lio_dev_ctrl_cmd ctrl_cmd;
1674 struct lio_ctrl_pkt ctrl_pkt;
1676 if (strcmp(lio_dev->firmware_version, LIO_Q_RECONF_MIN_VERSION) < 0) {
1677 lio_dev_err(lio_dev, "Require firmware version >= %s\n",
1678 LIO_Q_RECONF_MIN_VERSION);
1682 /* flush added to prevent cmd failure
1683 * incase the queue is full
1685 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1687 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1688 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1690 ctrl_cmd.eth_dev = eth_dev;
1693 ctrl_pkt.ncmd.s.cmd = LIO_CMD_QUEUE_COUNT_CTL;
1694 ctrl_pkt.ncmd.s.param1 = num_txq;
1695 ctrl_pkt.ncmd.s.param2 = num_rxq;
1696 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1698 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1699 lio_dev_err(lio_dev, "Failed to send queue count control command\n");
1703 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
1704 lio_dev_err(lio_dev, "Queue count control command timed out\n");
1712 lio_reconf_queues(struct rte_eth_dev *eth_dev, int num_txq, int num_rxq)
1714 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1716 if (lio_dev->nb_rx_queues != num_rxq ||
1717 lio_dev->nb_tx_queues != num_txq) {
1718 if (lio_send_queue_count_update(eth_dev, num_txq, num_rxq))
1720 lio_dev->nb_rx_queues = num_rxq;
1721 lio_dev->nb_tx_queues = num_txq;
1724 if (lio_dev->intf_open)
1725 lio_dev_stop(eth_dev);
1727 /* Reset ioq registers */
1728 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1729 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1737 lio_dev_configure(struct rte_eth_dev *eth_dev)
1739 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1740 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1741 int retval, num_iqueues, num_oqueues;
1742 uint8_t mac[ETHER_ADDR_LEN], i;
1743 struct lio_if_cfg_resp *resp;
1744 struct lio_soft_command *sc;
1745 union lio_if_cfg if_cfg;
1748 PMD_INIT_FUNC_TRACE();
1750 /* Inform firmware about change in number of queues to use.
1751 * Disable IO queues and reset registers for re-configuration.
1753 if (lio_dev->port_configured)
1754 return lio_reconf_queues(eth_dev,
1755 eth_dev->data->nb_tx_queues,
1756 eth_dev->data->nb_rx_queues);
1758 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
1759 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
1761 /* Set max number of queues which can be re-configured. */
1762 lio_dev->max_rx_queues = eth_dev->data->nb_rx_queues;
1763 lio_dev->max_tx_queues = eth_dev->data->nb_tx_queues;
1765 resp_size = sizeof(struct lio_if_cfg_resp);
1766 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1770 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
1772 /* Firmware doesn't have capability to reconfigure the queues,
1773 * Claim all queues, and use as many required
1775 if_cfg.if_cfg64 = 0;
1776 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
1777 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
1778 if_cfg.s.base_queue = 0;
1780 if_cfg.s.gmx_port_id = lio_dev->pf_num;
1782 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1783 LIO_OPCODE_IF_CFG, 0,
1784 if_cfg.if_cfg64, 0);
1786 /* Setting wait time in seconds */
1787 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1789 retval = lio_send_soft_command(lio_dev, sc);
1790 if (retval == LIO_IQ_SEND_FAILED) {
1791 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
1793 /* Soft instr is freed by driver in case of failure. */
1794 goto nic_config_fail;
1797 /* Sleep on a wait queue till the cond flag indicates that the
1798 * response arrived or timed-out.
1800 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1801 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1802 lio_process_ordered_list(lio_dev);
1806 retval = resp->status;
1808 lio_dev_err(lio_dev, "iq/oq config failed\n");
1809 goto nic_config_fail;
1812 snprintf(lio_dev->firmware_version, LIO_FW_VERSION_LENGTH, "%s",
1813 resp->cfg_info.lio_firmware_version);
1815 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
1816 sizeof(struct octeon_if_cfg_info) >> 3);
1818 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
1819 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
1821 if (!(num_iqueues) || !(num_oqueues)) {
1822 lio_dev_err(lio_dev,
1823 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
1824 (unsigned long)resp->cfg_info.iqmask,
1825 (unsigned long)resp->cfg_info.oqmask);
1826 goto nic_config_fail;
1829 lio_dev_dbg(lio_dev,
1830 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
1831 eth_dev->data->port_id,
1832 (unsigned long)resp->cfg_info.iqmask,
1833 (unsigned long)resp->cfg_info.oqmask,
1834 num_iqueues, num_oqueues);
1836 lio_dev->linfo.num_rxpciq = num_oqueues;
1837 lio_dev->linfo.num_txpciq = num_iqueues;
1839 for (i = 0; i < num_oqueues; i++) {
1840 lio_dev->linfo.rxpciq[i].rxpciq64 =
1841 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
1842 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
1843 i, lio_dev->linfo.rxpciq[i].s.q_no);
1846 for (i = 0; i < num_iqueues; i++) {
1847 lio_dev->linfo.txpciq[i].txpciq64 =
1848 resp->cfg_info.linfo.txpciq[i].txpciq64;
1849 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
1850 i, lio_dev->linfo.txpciq[i].s.q_no);
1853 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1854 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1855 lio_dev->linfo.link.link_status64 =
1856 resp->cfg_info.linfo.link.link_status64;
1858 /* 64-bit swap required on LE machines */
1859 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
1860 for (i = 0; i < ETHER_ADDR_LEN; i++)
1861 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
1864 /* Copy the permanent MAC address */
1865 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
1867 /* enable firmware checksum support for tunnel packets */
1868 lio_enable_hw_tunnel_rx_checksum(eth_dev);
1869 lio_enable_hw_tunnel_tx_checksum(eth_dev);
1871 lio_dev->glist_lock =
1872 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
1873 if (lio_dev->glist_lock == NULL)
1876 lio_dev->glist_head =
1877 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
1879 if (lio_dev->glist_head == NULL) {
1880 rte_free(lio_dev->glist_lock);
1881 lio_dev->glist_lock = NULL;
1885 lio_dev_link_update(eth_dev, 0);
1887 lio_dev->port_configured = 1;
1889 lio_free_soft_command(sc);
1891 /* Reset ioq regs */
1892 lio_dev->fn_list.setup_device_regs(lio_dev);
1894 /* Free iq_0 used during init */
1895 lio_free_instr_queue0(lio_dev);
1900 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
1901 lio_free_soft_command(sc);
1902 lio_free_instr_queue0(lio_dev);
1907 /* Define our ethernet definitions */
1908 static const struct eth_dev_ops liovf_eth_dev_ops = {
1909 .dev_configure = lio_dev_configure,
1910 .dev_start = lio_dev_start,
1911 .dev_stop = lio_dev_stop,
1912 .dev_set_link_up = lio_dev_set_link_up,
1913 .dev_set_link_down = lio_dev_set_link_down,
1914 .dev_close = lio_dev_close,
1915 .promiscuous_enable = lio_dev_promiscuous_enable,
1916 .promiscuous_disable = lio_dev_promiscuous_disable,
1917 .allmulticast_enable = lio_dev_allmulticast_enable,
1918 .allmulticast_disable = lio_dev_allmulticast_disable,
1919 .link_update = lio_dev_link_update,
1920 .stats_get = lio_dev_stats_get,
1921 .xstats_get = lio_dev_xstats_get,
1922 .xstats_get_names = lio_dev_xstats_get_names,
1923 .stats_reset = lio_dev_stats_reset,
1924 .xstats_reset = lio_dev_xstats_reset,
1925 .dev_infos_get = lio_dev_info_get,
1926 .vlan_filter_set = lio_dev_vlan_filter_set,
1927 .rx_queue_setup = lio_dev_rx_queue_setup,
1928 .rx_queue_release = lio_dev_rx_queue_release,
1929 .tx_queue_setup = lio_dev_tx_queue_setup,
1930 .tx_queue_release = lio_dev_tx_queue_release,
1931 .reta_update = lio_dev_rss_reta_update,
1932 .reta_query = lio_dev_rss_reta_query,
1933 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
1934 .rss_hash_update = lio_dev_rss_hash_update,
1935 .udp_tunnel_port_add = lio_dev_udp_tunnel_add,
1936 .udp_tunnel_port_del = lio_dev_udp_tunnel_del,
1937 .mtu_set = lio_dev_mtu_set,
1941 lio_check_pf_hs_response(void *lio_dev)
1943 struct lio_device *dev = lio_dev;
1945 /* check till response arrives */
1946 if (dev->pfvf_hsword.coproc_tics_per_us)
1949 cn23xx_vf_handle_mbox(dev);
1951 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1955 * \brief Identify the LIO device and to map the BAR address space
1956 * @param lio_dev lio device
1959 lio_chip_specific_setup(struct lio_device *lio_dev)
1961 struct rte_pci_device *pdev = lio_dev->pci_dev;
1962 uint32_t dev_id = pdev->id.device_id;
1967 case LIO_CN23XX_VF_VID:
1968 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1969 ret = cn23xx_vf_setup_device(lio_dev);
1974 lio_dev_err(lio_dev, "Unsupported Chip\n");
1978 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1984 lio_first_time_init(struct lio_device *lio_dev,
1985 struct rte_pci_device *pdev)
1989 PMD_INIT_FUNC_TRACE();
1991 /* set dpdk specific pci device pointer */
1992 lio_dev->pci_dev = pdev;
1994 /* Identify the LIO type and set device ops */
1995 if (lio_chip_specific_setup(lio_dev)) {
1996 lio_dev_err(lio_dev, "Chip specific setup failed\n");
2000 /* Initialize soft command buffer pool */
2001 if (lio_setup_sc_buffer_pool(lio_dev)) {
2002 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
2006 /* Initialize lists to manage the requests of different types that
2007 * arrive from applications for this lio device.
2009 lio_setup_response_list(lio_dev);
2011 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
2012 lio_dev_err(lio_dev, "Mailbox setup failed\n");
2016 /* Check PF response */
2017 lio_check_pf_hs_response((void *)lio_dev);
2019 /* Do handshake and exit if incompatible PF driver */
2020 if (cn23xx_pfvf_handshake(lio_dev))
2023 /* Request and wait for device reset. */
2024 if (pdev->kdrv == RTE_KDRV_IGB_UIO) {
2025 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
2026 /* FLR wait time doubled as a precaution. */
2027 rte_delay_ms(LIO_PCI_FLR_WAIT * 2);
2030 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
2031 lio_dev_err(lio_dev, "Failed to configure device registers\n");
2035 if (lio_setup_instr_queue0(lio_dev)) {
2036 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
2040 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
2042 lio_dev->max_tx_queues = dpdk_queues;
2043 lio_dev->max_rx_queues = dpdk_queues;
2045 /* Enable input and output queues for this device */
2046 if (lio_dev->fn_list.enable_io_queues(lio_dev))
2052 lio_free_sc_buffer_pool(lio_dev);
2053 if (lio_dev->mbox[0])
2054 lio_dev->fn_list.free_mbox(lio_dev);
2055 if (lio_dev->instr_queue[0])
2056 lio_free_instr_queue0(lio_dev);
2062 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
2064 struct lio_device *lio_dev = LIO_DEV(eth_dev);
2066 PMD_INIT_FUNC_TRACE();
2068 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2071 /* lio_free_sc_buffer_pool */
2072 lio_free_sc_buffer_pool(lio_dev);
2074 rte_free(eth_dev->data->mac_addrs);
2075 eth_dev->data->mac_addrs = NULL;
2077 eth_dev->dev_ops = NULL;
2078 eth_dev->rx_pkt_burst = NULL;
2079 eth_dev->tx_pkt_burst = NULL;
2085 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
2087 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(eth_dev);
2088 struct lio_device *lio_dev = LIO_DEV(eth_dev);
2090 PMD_INIT_FUNC_TRACE();
2092 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
2093 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
2095 /* Primary does the initialization. */
2096 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2099 rte_eth_copy_pci_info(eth_dev, pdev);
2101 if (pdev->mem_resource[0].addr) {
2102 lio_dev->hw_addr = pdev->mem_resource[0].addr;
2104 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
2108 lio_dev->eth_dev = eth_dev;
2109 /* set lio device print string */
2110 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
2111 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
2112 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
2114 lio_dev->port_id = eth_dev->data->port_id;
2116 if (lio_first_time_init(lio_dev, pdev)) {
2117 lio_dev_err(lio_dev, "Device init failed\n");
2121 eth_dev->dev_ops = &liovf_eth_dev_ops;
2122 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
2123 if (eth_dev->data->mac_addrs == NULL) {
2124 lio_dev_err(lio_dev,
2125 "MAC addresses memory allocation failed\n");
2126 eth_dev->dev_ops = NULL;
2127 eth_dev->rx_pkt_burst = NULL;
2128 eth_dev->tx_pkt_burst = NULL;
2132 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
2135 lio_dev->port_configured = 0;
2136 /* Always allow unicast packets */
2137 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
2143 lio_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2144 struct rte_pci_device *pci_dev)
2146 struct rte_eth_dev *eth_dev;
2149 eth_dev = rte_eth_dev_pci_allocate(pci_dev,
2150 sizeof(struct lio_device));
2151 if (eth_dev == NULL)
2154 ret = lio_eth_dev_init(eth_dev);
2156 rte_eth_dev_pci_release(eth_dev);
2162 lio_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
2164 return rte_eth_dev_pci_generic_remove(pci_dev,
2165 lio_eth_dev_uninit);
2168 /* Set of PCI devices this driver supports */
2169 static const struct rte_pci_id pci_id_liovf_map[] = {
2170 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
2171 { .vendor_id = 0, /* sentinel */ }
2174 static struct rte_pci_driver rte_liovf_pmd = {
2175 .id_table = pci_id_liovf_map,
2176 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
2177 .probe = lio_eth_dev_pci_probe,
2178 .remove = lio_eth_dev_pci_remove,
2181 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd);
2182 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
2183 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio-pci");