1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
5 #include <rte_ethdev_driver.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"
18 int lio_logtype_driver;
20 /* Default RSS key in use */
21 static uint8_t lio_rss_key[40] = {
22 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
23 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
24 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
25 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
26 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
29 static const struct rte_eth_desc_lim lio_rx_desc_lim = {
30 .nb_max = CN23XX_MAX_OQ_DESCRIPTORS,
31 .nb_min = CN23XX_MIN_OQ_DESCRIPTORS,
35 static const struct rte_eth_desc_lim lio_tx_desc_lim = {
36 .nb_max = CN23XX_MAX_IQ_DESCRIPTORS,
37 .nb_min = CN23XX_MIN_IQ_DESCRIPTORS,
41 /* Wait for control command to reach nic. */
43 lio_wait_for_ctrl_cmd(struct lio_device *lio_dev,
44 struct lio_dev_ctrl_cmd *ctrl_cmd)
46 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
48 while ((ctrl_cmd->cond == 0) && --timeout) {
49 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
57 * \brief Send Rx control command
58 * @param eth_dev Pointer to the structure rte_eth_dev
59 * @param start_stop whether to start or stop
62 lio_send_rx_ctrl_cmd(struct rte_eth_dev *eth_dev, int start_stop)
64 struct lio_device *lio_dev = LIO_DEV(eth_dev);
65 struct lio_dev_ctrl_cmd ctrl_cmd;
66 struct lio_ctrl_pkt ctrl_pkt;
68 /* flush added to prevent cmd failure
69 * incase the queue is full
71 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
73 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
74 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
76 ctrl_cmd.eth_dev = eth_dev;
79 ctrl_pkt.ncmd.s.cmd = LIO_CMD_RX_CTL;
80 ctrl_pkt.ncmd.s.param1 = start_stop;
81 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
83 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
84 lio_dev_err(lio_dev, "Failed to send RX Control message\n");
88 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
89 lio_dev_err(lio_dev, "RX Control command timed out\n");
96 /* store statistics names and its offset in stats structure */
97 struct rte_lio_xstats_name_off {
98 char name[RTE_ETH_XSTATS_NAME_SIZE];
102 static const struct rte_lio_xstats_name_off rte_lio_stats_strings[] = {
103 {"rx_pkts", offsetof(struct octeon_rx_stats, total_rcvd)},
104 {"rx_bytes", offsetof(struct octeon_rx_stats, bytes_rcvd)},
105 {"rx_broadcast_pkts", offsetof(struct octeon_rx_stats, total_bcst)},
106 {"rx_multicast_pkts", offsetof(struct octeon_rx_stats, total_mcst)},
107 {"rx_flow_ctrl_pkts", offsetof(struct octeon_rx_stats, ctl_rcvd)},
108 {"rx_fifo_err", offsetof(struct octeon_rx_stats, fifo_err)},
109 {"rx_dmac_drop", offsetof(struct octeon_rx_stats, dmac_drop)},
110 {"rx_fcs_err", offsetof(struct octeon_rx_stats, fcs_err)},
111 {"rx_jabber_err", offsetof(struct octeon_rx_stats, jabber_err)},
112 {"rx_l2_err", offsetof(struct octeon_rx_stats, l2_err)},
113 {"rx_vxlan_pkts", offsetof(struct octeon_rx_stats, fw_rx_vxlan)},
114 {"rx_vxlan_err", offsetof(struct octeon_rx_stats, fw_rx_vxlan_err)},
115 {"rx_lro_pkts", offsetof(struct octeon_rx_stats, fw_lro_pkts)},
116 {"tx_pkts", (offsetof(struct octeon_tx_stats, total_pkts_sent)) +
117 sizeof(struct octeon_rx_stats)},
118 {"tx_bytes", (offsetof(struct octeon_tx_stats, total_bytes_sent)) +
119 sizeof(struct octeon_rx_stats)},
120 {"tx_broadcast_pkts",
121 (offsetof(struct octeon_tx_stats, bcast_pkts_sent)) +
122 sizeof(struct octeon_rx_stats)},
123 {"tx_multicast_pkts",
124 (offsetof(struct octeon_tx_stats, mcast_pkts_sent)) +
125 sizeof(struct octeon_rx_stats)},
126 {"tx_flow_ctrl_pkts", (offsetof(struct octeon_tx_stats, ctl_sent)) +
127 sizeof(struct octeon_rx_stats)},
128 {"tx_fifo_err", (offsetof(struct octeon_tx_stats, fifo_err)) +
129 sizeof(struct octeon_rx_stats)},
130 {"tx_total_collisions", (offsetof(struct octeon_tx_stats,
132 sizeof(struct octeon_rx_stats)},
133 {"tx_tso", (offsetof(struct octeon_tx_stats, fw_tso)) +
134 sizeof(struct octeon_rx_stats)},
135 {"tx_vxlan_pkts", (offsetof(struct octeon_tx_stats, fw_tx_vxlan)) +
136 sizeof(struct octeon_rx_stats)},
139 #define LIO_NB_XSTATS RTE_DIM(rte_lio_stats_strings)
141 /* Get hw stats of the port */
143 lio_dev_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *xstats,
146 struct lio_device *lio_dev = LIO_DEV(eth_dev);
147 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
148 struct octeon_link_stats *hw_stats;
149 struct lio_link_stats_resp *resp;
150 struct lio_soft_command *sc;
155 if (!lio_dev->intf_open) {
156 lio_dev_err(lio_dev, "Port %d down\n",
161 if (n < LIO_NB_XSTATS)
162 return LIO_NB_XSTATS;
164 resp_size = sizeof(struct lio_link_stats_resp);
165 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
169 resp = (struct lio_link_stats_resp *)sc->virtrptr;
170 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
171 LIO_OPCODE_PORT_STATS, 0, 0, 0);
173 /* Setting wait time in seconds */
174 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
176 retval = lio_send_soft_command(lio_dev, sc);
177 if (retval == LIO_IQ_SEND_FAILED) {
178 lio_dev_err(lio_dev, "failed to get port stats from firmware. status: %x\n",
183 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
184 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
185 lio_process_ordered_list(lio_dev);
189 retval = resp->status;
191 lio_dev_err(lio_dev, "failed to get port stats from firmware\n");
195 lio_swap_8B_data((uint64_t *)(&resp->link_stats),
196 sizeof(struct octeon_link_stats) >> 3);
198 hw_stats = &resp->link_stats;
200 for (i = 0; i < LIO_NB_XSTATS; i++) {
203 *(uint64_t *)(((char *)hw_stats) +
204 rte_lio_stats_strings[i].offset);
207 lio_free_soft_command(sc);
209 return LIO_NB_XSTATS;
212 lio_free_soft_command(sc);
218 lio_dev_xstats_get_names(struct rte_eth_dev *eth_dev,
219 struct rte_eth_xstat_name *xstats_names,
220 unsigned limit __rte_unused)
222 struct lio_device *lio_dev = LIO_DEV(eth_dev);
225 if (!lio_dev->intf_open) {
226 lio_dev_err(lio_dev, "Port %d down\n",
231 if (xstats_names == NULL)
232 return LIO_NB_XSTATS;
234 /* Note: limit checked in rte_eth_xstats_names() */
236 for (i = 0; i < LIO_NB_XSTATS; i++) {
237 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
238 "%s", rte_lio_stats_strings[i].name);
241 return LIO_NB_XSTATS;
244 /* Reset hw stats for the port */
246 lio_dev_xstats_reset(struct rte_eth_dev *eth_dev)
248 struct lio_device *lio_dev = LIO_DEV(eth_dev);
249 struct lio_dev_ctrl_cmd ctrl_cmd;
250 struct lio_ctrl_pkt ctrl_pkt;
252 if (!lio_dev->intf_open) {
253 lio_dev_err(lio_dev, "Port %d down\n",
258 /* flush added to prevent cmd failure
259 * incase the queue is full
261 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
263 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
264 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
266 ctrl_cmd.eth_dev = eth_dev;
269 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CLEAR_STATS;
270 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
272 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
273 lio_dev_err(lio_dev, "Failed to send clear stats command\n");
277 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
278 lio_dev_err(lio_dev, "Clear stats command timed out\n");
282 /* clear stored per queue stats */
283 RTE_FUNC_PTR_OR_RET(*eth_dev->dev_ops->stats_reset);
284 (*eth_dev->dev_ops->stats_reset)(eth_dev);
287 /* Retrieve the device statistics (# packets in/out, # bytes in/out, etc */
289 lio_dev_stats_get(struct rte_eth_dev *eth_dev,
290 struct rte_eth_stats *stats)
292 struct lio_device *lio_dev = LIO_DEV(eth_dev);
293 struct lio_droq_stats *oq_stats;
294 struct lio_iq_stats *iq_stats;
295 struct lio_instr_queue *txq;
296 struct lio_droq *droq;
302 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
303 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
304 txq = lio_dev->instr_queue[iq_no];
306 iq_stats = &txq->stats;
307 pkts += iq_stats->tx_done;
308 drop += iq_stats->tx_dropped;
309 bytes += iq_stats->tx_tot_bytes;
313 stats->opackets = pkts;
314 stats->obytes = bytes;
315 stats->oerrors = drop;
321 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
322 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
323 droq = lio_dev->droq[oq_no];
325 oq_stats = &droq->stats;
326 pkts += oq_stats->rx_pkts_received;
327 drop += (oq_stats->rx_dropped +
328 oq_stats->dropped_toomany +
329 oq_stats->dropped_nomem);
330 bytes += oq_stats->rx_bytes_received;
333 stats->ibytes = bytes;
334 stats->ipackets = pkts;
335 stats->ierrors = drop;
341 lio_dev_stats_reset(struct rte_eth_dev *eth_dev)
343 struct lio_device *lio_dev = LIO_DEV(eth_dev);
344 struct lio_droq_stats *oq_stats;
345 struct lio_iq_stats *iq_stats;
346 struct lio_instr_queue *txq;
347 struct lio_droq *droq;
350 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
351 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
352 txq = lio_dev->instr_queue[iq_no];
354 iq_stats = &txq->stats;
355 memset(iq_stats, 0, sizeof(struct lio_iq_stats));
359 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
360 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
361 droq = lio_dev->droq[oq_no];
363 oq_stats = &droq->stats;
364 memset(oq_stats, 0, sizeof(struct lio_droq_stats));
370 lio_dev_info_get(struct rte_eth_dev *eth_dev,
371 struct rte_eth_dev_info *devinfo)
373 struct lio_device *lio_dev = LIO_DEV(eth_dev);
374 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
376 devinfo->pci_dev = pci_dev;
378 switch (pci_dev->id.subsystem_device_id) {
379 /* CN23xx 10G cards */
380 case PCI_SUBSYS_DEV_ID_CN2350_210:
381 case PCI_SUBSYS_DEV_ID_CN2360_210:
382 case PCI_SUBSYS_DEV_ID_CN2350_210SVPN3:
383 case PCI_SUBSYS_DEV_ID_CN2360_210SVPN3:
384 case PCI_SUBSYS_DEV_ID_CN2350_210SVPT:
385 case PCI_SUBSYS_DEV_ID_CN2360_210SVPT:
386 devinfo->speed_capa = ETH_LINK_SPEED_10G;
388 /* CN23xx 25G cards */
389 case PCI_SUBSYS_DEV_ID_CN2350_225:
390 case PCI_SUBSYS_DEV_ID_CN2360_225:
391 devinfo->speed_capa = ETH_LINK_SPEED_25G;
394 devinfo->speed_capa = ETH_LINK_SPEED_10G;
396 "Unknown CN23XX subsystem device id. Setting 10G as default link speed.\n");
399 devinfo->max_rx_queues = lio_dev->max_rx_queues;
400 devinfo->max_tx_queues = lio_dev->max_tx_queues;
402 devinfo->min_rx_bufsize = LIO_MIN_RX_BUF_SIZE;
403 devinfo->max_rx_pktlen = LIO_MAX_RX_PKTLEN;
405 devinfo->max_mac_addrs = 1;
407 devinfo->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
408 DEV_RX_OFFLOAD_UDP_CKSUM |
409 DEV_RX_OFFLOAD_TCP_CKSUM |
410 DEV_RX_OFFLOAD_VLAN_STRIP);
411 devinfo->tx_offload_capa = (DEV_TX_OFFLOAD_IPV4_CKSUM |
412 DEV_TX_OFFLOAD_UDP_CKSUM |
413 DEV_TX_OFFLOAD_TCP_CKSUM |
414 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM);
416 devinfo->rx_desc_lim = lio_rx_desc_lim;
417 devinfo->tx_desc_lim = lio_tx_desc_lim;
419 devinfo->reta_size = LIO_RSS_MAX_TABLE_SZ;
420 devinfo->hash_key_size = LIO_RSS_MAX_KEY_SZ;
421 devinfo->flow_type_rss_offloads = (ETH_RSS_IPV4 |
422 ETH_RSS_NONFRAG_IPV4_TCP |
424 ETH_RSS_NONFRAG_IPV6_TCP |
426 ETH_RSS_IPV6_TCP_EX);
430 lio_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
432 struct lio_device *lio_dev = LIO_DEV(eth_dev);
433 uint16_t pf_mtu = lio_dev->linfo.link.s.mtu;
434 uint32_t frame_len = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
435 struct lio_dev_ctrl_cmd ctrl_cmd;
436 struct lio_ctrl_pkt ctrl_pkt;
438 PMD_INIT_FUNC_TRACE();
440 if (!lio_dev->intf_open) {
441 lio_dev_err(lio_dev, "Port %d down, can't set MTU\n",
446 /* check if VF MTU is within allowed range.
447 * New value should not exceed PF MTU.
449 if ((mtu < ETHER_MIN_MTU) || (mtu > pf_mtu)) {
450 lio_dev_err(lio_dev, "VF MTU should be >= %d and <= %d\n",
451 ETHER_MIN_MTU, pf_mtu);
455 /* flush added to prevent cmd failure
456 * incase the queue is full
458 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
460 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
461 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
463 ctrl_cmd.eth_dev = eth_dev;
466 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CHANGE_MTU;
467 ctrl_pkt.ncmd.s.param1 = mtu;
468 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
470 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
471 lio_dev_err(lio_dev, "Failed to send command to change MTU\n");
475 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
476 lio_dev_err(lio_dev, "Command to change MTU timed out\n");
480 if (frame_len > ETHER_MAX_LEN)
481 eth_dev->data->dev_conf.rxmode.jumbo_frame = 1;
483 eth_dev->data->dev_conf.rxmode.jumbo_frame = 0;
485 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_len;
486 eth_dev->data->mtu = mtu;
492 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
493 struct rte_eth_rss_reta_entry64 *reta_conf,
496 struct lio_device *lio_dev = LIO_DEV(eth_dev);
497 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
498 struct lio_rss_set *rss_param;
499 struct lio_dev_ctrl_cmd ctrl_cmd;
500 struct lio_ctrl_pkt ctrl_pkt;
503 if (!lio_dev->intf_open) {
504 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
509 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
511 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
512 reta_size, LIO_RSS_MAX_TABLE_SZ);
516 /* flush added to prevent cmd failure
517 * incase the queue is full
519 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
521 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
522 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
524 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
526 ctrl_cmd.eth_dev = eth_dev;
529 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
530 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
531 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
533 rss_param->param.flags = 0xF;
534 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
535 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
537 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
538 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
539 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
540 index = (i * RTE_RETA_GROUP_SIZE) + j;
541 rss_state->itable[index] = reta_conf[i].reta[j];
546 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
547 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
549 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
551 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
552 lio_dev_err(lio_dev, "Failed to set rss hash\n");
556 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
557 lio_dev_err(lio_dev, "Set rss hash timed out\n");
565 lio_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
566 struct rte_eth_rss_reta_entry64 *reta_conf,
569 struct lio_device *lio_dev = LIO_DEV(eth_dev);
570 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
573 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
575 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
576 reta_size, LIO_RSS_MAX_TABLE_SZ);
580 num = reta_size / RTE_RETA_GROUP_SIZE;
582 for (i = 0; i < num; i++) {
583 memcpy(reta_conf->reta,
584 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
585 RTE_RETA_GROUP_SIZE);
593 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
594 struct rte_eth_rss_conf *rss_conf)
596 struct lio_device *lio_dev = LIO_DEV(eth_dev);
597 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
598 uint8_t *hash_key = NULL;
601 if (rss_state->hash_disable) {
602 lio_dev_info(lio_dev, "RSS disabled in nic\n");
603 rss_conf->rss_hf = 0;
608 hash_key = rss_conf->rss_key;
609 if (hash_key != NULL)
610 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
613 rss_hf |= ETH_RSS_IPV4;
614 if (rss_state->tcp_hash)
615 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
617 rss_hf |= ETH_RSS_IPV6;
618 if (rss_state->ipv6_tcp_hash)
619 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
620 if (rss_state->ipv6_ex)
621 rss_hf |= ETH_RSS_IPV6_EX;
622 if (rss_state->ipv6_tcp_ex_hash)
623 rss_hf |= ETH_RSS_IPV6_TCP_EX;
625 rss_conf->rss_hf = rss_hf;
631 lio_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
632 struct rte_eth_rss_conf *rss_conf)
634 struct lio_device *lio_dev = LIO_DEV(eth_dev);
635 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
636 struct lio_rss_set *rss_param;
637 struct lio_dev_ctrl_cmd ctrl_cmd;
638 struct lio_ctrl_pkt ctrl_pkt;
640 if (!lio_dev->intf_open) {
641 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
646 /* flush added to prevent cmd failure
647 * incase the queue is full
649 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
651 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
652 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
654 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
656 ctrl_cmd.eth_dev = eth_dev;
659 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
660 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
661 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
663 rss_param->param.flags = 0xF;
665 if (rss_conf->rss_key) {
666 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
667 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
668 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
669 memcpy(rss_state->hash_key, rss_conf->rss_key,
670 rss_state->hash_key_size);
671 memcpy(rss_param->key, rss_state->hash_key,
672 rss_state->hash_key_size);
675 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
676 /* Can't disable rss through hash flags,
677 * if it is enabled by default during init
679 if (!rss_state->hash_disable)
682 /* This is for --disable-rss during testpmd launch */
683 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
685 uint32_t hashinfo = 0;
687 /* Can't enable rss if disabled by default during init */
688 if (rss_state->hash_disable)
691 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
692 hashinfo |= LIO_RSS_HASH_IPV4;
698 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
699 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
700 rss_state->tcp_hash = 1;
702 rss_state->tcp_hash = 0;
705 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
706 hashinfo |= LIO_RSS_HASH_IPV6;
712 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
713 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
714 rss_state->ipv6_tcp_hash = 1;
716 rss_state->ipv6_tcp_hash = 0;
719 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
720 hashinfo |= LIO_RSS_HASH_IPV6_EX;
721 rss_state->ipv6_ex = 1;
723 rss_state->ipv6_ex = 0;
726 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
727 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
728 rss_state->ipv6_tcp_ex_hash = 1;
730 rss_state->ipv6_tcp_ex_hash = 0;
733 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
734 rss_param->param.hashinfo = hashinfo;
737 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
739 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
740 lio_dev_err(lio_dev, "Failed to set rss hash\n");
744 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
745 lio_dev_err(lio_dev, "Set rss hash timed out\n");
753 * Add vxlan dest udp port for an interface.
756 * Pointer to the structure rte_eth_dev
761 * On success return 0
762 * On failure return -1
765 lio_dev_udp_tunnel_add(struct rte_eth_dev *eth_dev,
766 struct rte_eth_udp_tunnel *udp_tnl)
768 struct lio_device *lio_dev = LIO_DEV(eth_dev);
769 struct lio_dev_ctrl_cmd ctrl_cmd;
770 struct lio_ctrl_pkt ctrl_pkt;
775 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
776 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
780 /* flush added to prevent cmd failure
781 * incase the queue is full
783 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
785 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
786 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
788 ctrl_cmd.eth_dev = eth_dev;
791 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
792 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
793 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_ADD;
794 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
796 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
797 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_ADD command\n");
801 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
802 lio_dev_err(lio_dev, "VXLAN_PORT_ADD command timed out\n");
810 * Remove vxlan dest udp port for an interface.
813 * Pointer to the structure rte_eth_dev
818 * On success return 0
819 * On failure return -1
822 lio_dev_udp_tunnel_del(struct rte_eth_dev *eth_dev,
823 struct rte_eth_udp_tunnel *udp_tnl)
825 struct lio_device *lio_dev = LIO_DEV(eth_dev);
826 struct lio_dev_ctrl_cmd ctrl_cmd;
827 struct lio_ctrl_pkt ctrl_pkt;
832 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
833 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
837 /* flush added to prevent cmd failure
838 * incase the queue is full
840 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
842 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
843 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
845 ctrl_cmd.eth_dev = eth_dev;
848 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
849 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
850 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_DEL;
851 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
853 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
854 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_DEL command\n");
858 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
859 lio_dev_err(lio_dev, "VXLAN_PORT_DEL command timed out\n");
867 lio_dev_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id, int on)
869 struct lio_device *lio_dev = LIO_DEV(eth_dev);
870 struct lio_dev_ctrl_cmd ctrl_cmd;
871 struct lio_ctrl_pkt ctrl_pkt;
873 if (lio_dev->linfo.vlan_is_admin_assigned)
876 /* flush added to prevent cmd failure
877 * incase the queue is full
879 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
881 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
882 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
884 ctrl_cmd.eth_dev = eth_dev;
887 ctrl_pkt.ncmd.s.cmd = on ?
888 LIO_CMD_ADD_VLAN_FILTER : LIO_CMD_DEL_VLAN_FILTER;
889 ctrl_pkt.ncmd.s.param1 = vlan_id;
890 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
892 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
893 lio_dev_err(lio_dev, "Failed to %s VLAN port\n",
894 on ? "add" : "remove");
898 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
899 lio_dev_err(lio_dev, "Command to %s VLAN port timed out\n",
900 on ? "add" : "remove");
908 * Atomically writes the link status information into global
909 * structure rte_eth_dev.
912 * - Pointer to the structure rte_eth_dev to read from.
913 * - Pointer to the buffer to be saved with the link status.
916 * - On success, zero.
917 * - On failure, negative value.
920 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
921 struct rte_eth_link *link)
923 struct rte_eth_link *dst = ð_dev->data->dev_link;
924 struct rte_eth_link *src = link;
926 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
927 *(uint64_t *)src) == 0)
934 lio_hweight64(uint64_t w)
936 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
939 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
940 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
941 res = res + (res >> 8);
942 res = res + (res >> 16);
944 return (res + (res >> 32)) & 0x00000000000000FFul;
948 lio_dev_link_update(struct rte_eth_dev *eth_dev,
949 int wait_to_complete __rte_unused)
951 struct lio_device *lio_dev = LIO_DEV(eth_dev);
952 struct rte_eth_link link, old;
955 link.link_status = ETH_LINK_DOWN;
956 link.link_speed = ETH_SPEED_NUM_NONE;
957 link.link_duplex = ETH_LINK_HALF_DUPLEX;
958 link.link_autoneg = ETH_LINK_AUTONEG;
959 memset(&old, 0, sizeof(old));
961 /* Return what we found */
962 if (lio_dev->linfo.link.s.link_up == 0) {
963 /* Interface is down */
964 if (lio_dev_atomic_write_link_status(eth_dev, &link))
966 if (link.link_status == old.link_status)
971 link.link_status = ETH_LINK_UP; /* Interface is up */
972 link.link_duplex = ETH_LINK_FULL_DUPLEX;
973 switch (lio_dev->linfo.link.s.speed) {
974 case LIO_LINK_SPEED_10000:
975 link.link_speed = ETH_SPEED_NUM_10G;
977 case LIO_LINK_SPEED_25000:
978 link.link_speed = ETH_SPEED_NUM_25G;
981 link.link_speed = ETH_SPEED_NUM_NONE;
982 link.link_duplex = ETH_LINK_HALF_DUPLEX;
985 if (lio_dev_atomic_write_link_status(eth_dev, &link))
988 if (link.link_status == old.link_status)
995 * \brief Net device enable, disable allmulticast
996 * @param eth_dev Pointer to the structure rte_eth_dev
999 lio_change_dev_flag(struct rte_eth_dev *eth_dev)
1001 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1002 struct lio_dev_ctrl_cmd ctrl_cmd;
1003 struct lio_ctrl_pkt ctrl_pkt;
1005 /* flush added to prevent cmd failure
1006 * incase the queue is full
1008 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1010 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1011 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1013 ctrl_cmd.eth_dev = eth_dev;
1016 /* Create a ctrl pkt command to be sent to core app. */
1017 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CHANGE_DEVFLAGS;
1018 ctrl_pkt.ncmd.s.param1 = lio_dev->ifflags;
1019 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1021 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1022 lio_dev_err(lio_dev, "Failed to send change flag message\n");
1026 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1027 lio_dev_err(lio_dev, "Change dev flag command timed out\n");
1031 lio_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
1033 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1035 if (strcmp(lio_dev->firmware_version, LIO_VF_TRUST_MIN_VERSION) < 0) {
1036 lio_dev_err(lio_dev, "Require firmware version >= %s\n",
1037 LIO_VF_TRUST_MIN_VERSION);
1041 if (!lio_dev->intf_open) {
1042 lio_dev_err(lio_dev, "Port %d down, can't enable promiscuous\n",
1047 lio_dev->ifflags |= LIO_IFFLAG_PROMISC;
1048 lio_change_dev_flag(eth_dev);
1052 lio_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
1054 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1056 if (strcmp(lio_dev->firmware_version, LIO_VF_TRUST_MIN_VERSION) < 0) {
1057 lio_dev_err(lio_dev, "Require firmware version >= %s\n",
1058 LIO_VF_TRUST_MIN_VERSION);
1062 if (!lio_dev->intf_open) {
1063 lio_dev_err(lio_dev, "Port %d down, can't disable promiscuous\n",
1068 lio_dev->ifflags &= ~LIO_IFFLAG_PROMISC;
1069 lio_change_dev_flag(eth_dev);
1073 lio_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
1075 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1077 if (!lio_dev->intf_open) {
1078 lio_dev_err(lio_dev, "Port %d down, can't enable multicast\n",
1083 lio_dev->ifflags |= LIO_IFFLAG_ALLMULTI;
1084 lio_change_dev_flag(eth_dev);
1088 lio_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
1090 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1092 if (!lio_dev->intf_open) {
1093 lio_dev_err(lio_dev, "Port %d down, can't disable multicast\n",
1098 lio_dev->ifflags &= ~LIO_IFFLAG_ALLMULTI;
1099 lio_change_dev_flag(eth_dev);
1103 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
1105 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1106 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1107 struct rte_eth_rss_reta_entry64 reta_conf[8];
1108 struct rte_eth_rss_conf rss_conf;
1111 /* Configure the RSS key and the RSS protocols used to compute
1112 * the RSS hash of input packets.
1114 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
1115 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
1116 rss_state->hash_disable = 1;
1117 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1121 if (rss_conf.rss_key == NULL)
1122 rss_conf.rss_key = lio_rss_key; /* Default hash key */
1124 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1126 memset(reta_conf, 0, sizeof(reta_conf));
1127 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
1128 uint8_t q_idx, conf_idx, reta_idx;
1130 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
1131 i % eth_dev->data->nb_rx_queues : 0);
1132 conf_idx = i / RTE_RETA_GROUP_SIZE;
1133 reta_idx = i % RTE_RETA_GROUP_SIZE;
1134 reta_conf[conf_idx].reta[reta_idx] = q_idx;
1135 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
1138 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
1142 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
1144 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1145 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1146 struct rte_eth_rss_conf rss_conf;
1148 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
1150 lio_dev_rss_configure(eth_dev);
1152 case ETH_MQ_RX_NONE:
1153 /* if mq_mode is none, disable rss mode. */
1155 memset(&rss_conf, 0, sizeof(rss_conf));
1156 rss_state->hash_disable = 1;
1157 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1162 * Setup our receive queue/ringbuffer. This is the
1163 * queue the Octeon uses to send us packets and
1164 * responses. We are given a memory pool for our
1165 * packet buffers that are used to populate the receive
1169 * Pointer to the structure rte_eth_dev
1172 * @param num_rx_descs
1173 * Number of entries in the queue
1175 * Where to allocate memory
1177 * Pointer to the struction rte_eth_rxconf
1179 * Pointer to the packet pool
1182 * - On success, return 0
1183 * - On failure, return -1
1186 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1187 uint16_t num_rx_descs, unsigned int socket_id,
1188 const struct rte_eth_rxconf *rx_conf __rte_unused,
1189 struct rte_mempool *mp)
1191 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1192 struct rte_pktmbuf_pool_private *mbp_priv;
1193 uint32_t fw_mapped_oq;
1196 if (q_no >= lio_dev->nb_rx_queues) {
1197 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
1201 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
1203 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
1205 /* Free previous allocation if any */
1206 if (eth_dev->data->rx_queues[q_no] != NULL) {
1207 lio_dev_rx_queue_release(eth_dev->data->rx_queues[q_no]);
1208 eth_dev->data->rx_queues[q_no] = NULL;
1211 mbp_priv = rte_mempool_get_priv(mp);
1212 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
1214 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
1216 lio_dev_err(lio_dev, "droq allocation failed\n");
1220 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
1226 * Release the receive queue/ringbuffer. Called by
1230 * Opaque pointer to the receive queue to release
1236 lio_dev_rx_queue_release(void *rxq)
1238 struct lio_droq *droq = rxq;
1243 lio_delete_droq_queue(droq->lio_dev, oq_no);
1248 * Allocate and initialize SW ring. Initialize associated HW registers.
1251 * Pointer to structure rte_eth_dev
1256 * @param num_tx_descs
1257 * Number of ringbuffer descriptors
1260 * NUMA socket id, used for memory allocations
1263 * Pointer to the structure rte_eth_txconf
1266 * - On success, return 0
1267 * - On failure, return -errno value
1270 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1271 uint16_t num_tx_descs, unsigned int socket_id,
1272 const struct rte_eth_txconf *tx_conf __rte_unused)
1274 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1275 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
1278 if (q_no >= lio_dev->nb_tx_queues) {
1279 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
1283 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
1285 /* Free previous allocation if any */
1286 if (eth_dev->data->tx_queues[q_no] != NULL) {
1287 lio_dev_tx_queue_release(eth_dev->data->tx_queues[q_no]);
1288 eth_dev->data->tx_queues[q_no] = NULL;
1291 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
1292 num_tx_descs, lio_dev, socket_id);
1295 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
1299 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
1300 lio_dev->instr_queue[fw_mapped_iq]->nb_desc,
1304 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
1308 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
1314 * Release the transmit queue/ringbuffer. Called by
1318 * Opaque pointer to the transmit queue to release
1324 lio_dev_tx_queue_release(void *txq)
1326 struct lio_instr_queue *tq = txq;
1327 uint32_t fw_mapped_iq_no;
1332 lio_delete_sglist(tq);
1334 fw_mapped_iq_no = tq->txpciq.s.q_no;
1335 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
1340 * Api to check link state.
1343 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
1345 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1346 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1347 struct lio_link_status_resp *resp;
1348 union octeon_link_status *ls;
1349 struct lio_soft_command *sc;
1352 if (!lio_dev->intf_open)
1355 resp_size = sizeof(struct lio_link_status_resp);
1356 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1360 resp = (struct lio_link_status_resp *)sc->virtrptr;
1361 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1362 LIO_OPCODE_INFO, 0, 0, 0);
1364 /* Setting wait time in seconds */
1365 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1367 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
1368 goto get_status_fail;
1370 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1371 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1376 goto get_status_fail;
1378 ls = &resp->link_info.link;
1380 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
1382 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
1383 if (ls->s.mtu < eth_dev->data->mtu) {
1384 lio_dev_info(lio_dev, "Lowered VF MTU to %d as PF MTU dropped\n",
1386 eth_dev->data->mtu = ls->s.mtu;
1388 lio_dev->linfo.link.link_status64 = ls->link_status64;
1389 lio_dev_link_update(eth_dev, 0);
1392 lio_free_soft_command(sc);
1397 lio_free_soft_command(sc);
1400 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
1401 * and will update link state if it changes.
1404 lio_sync_link_state_check(void *eth_dev)
1406 struct lio_device *lio_dev =
1407 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
1409 if (lio_dev->port_configured)
1410 lio_dev_get_link_status(eth_dev);
1412 /* Schedule periodic link status check.
1413 * Stop check if interface is close and start again while opening.
1415 if (lio_dev->intf_open)
1416 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
1421 lio_dev_start(struct rte_eth_dev *eth_dev)
1424 uint32_t frame_len = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
1425 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1426 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1429 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
1431 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1434 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
1437 /* Ready for link status updates */
1438 lio_dev->intf_open = 1;
1441 /* Configure RSS if device configured with multiple RX queues. */
1442 lio_dev_mq_rx_configure(eth_dev);
1444 /* start polling for lsc */
1445 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
1446 lio_sync_link_state_check,
1449 lio_dev_err(lio_dev,
1450 "link state check handler creation failed\n");
1451 goto dev_lsc_handle_error;
1454 while ((lio_dev->linfo.link.link_status64 == 0) && (--timeout))
1457 if (lio_dev->linfo.link.link_status64 == 0) {
1459 goto dev_mtu_set_error;
1462 mtu = (uint16_t)(frame_len - ETHER_HDR_LEN - ETHER_CRC_LEN);
1463 if (mtu < ETHER_MIN_MTU)
1464 mtu = ETHER_MIN_MTU;
1466 if (eth_dev->data->mtu != mtu) {
1467 ret = lio_dev_mtu_set(eth_dev, mtu);
1469 goto dev_mtu_set_error;
1475 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1477 dev_lsc_handle_error:
1478 lio_dev->intf_open = 0;
1479 lio_send_rx_ctrl_cmd(eth_dev, 0);
1484 /* Stop device and disable input/output functions */
1486 lio_dev_stop(struct rte_eth_dev *eth_dev)
1488 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1490 lio_dev_info(lio_dev, "Stopping port %d\n", eth_dev->data->port_id);
1491 lio_dev->intf_open = 0;
1494 /* Cancel callback if still running. */
1495 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1497 lio_send_rx_ctrl_cmd(eth_dev, 0);
1499 lio_wait_for_instr_fetch(lio_dev);
1501 /* Clear recorded link status */
1502 lio_dev->linfo.link.link_status64 = 0;
1506 lio_dev_set_link_up(struct rte_eth_dev *eth_dev)
1508 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1510 if (!lio_dev->intf_open) {
1511 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1515 if (lio_dev->linfo.link.s.link_up) {
1516 lio_dev_info(lio_dev, "Link is already UP\n");
1520 if (lio_send_rx_ctrl_cmd(eth_dev, 1)) {
1521 lio_dev_err(lio_dev, "Unable to set Link UP\n");
1525 lio_dev->linfo.link.s.link_up = 1;
1526 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1532 lio_dev_set_link_down(struct rte_eth_dev *eth_dev)
1534 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1536 if (!lio_dev->intf_open) {
1537 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1541 if (!lio_dev->linfo.link.s.link_up) {
1542 lio_dev_info(lio_dev, "Link is already DOWN\n");
1546 lio_dev->linfo.link.s.link_up = 0;
1547 eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
1549 if (lio_send_rx_ctrl_cmd(eth_dev, 0)) {
1550 lio_dev->linfo.link.s.link_up = 1;
1551 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1552 lio_dev_err(lio_dev, "Unable to set Link Down\n");
1560 * Reset and stop the device. This occurs on the first
1561 * call to this routine. Subsequent calls will simply
1562 * return. NB: This will require the NIC to be rebooted.
1565 * Pointer to the structure rte_eth_dev
1571 lio_dev_close(struct rte_eth_dev *eth_dev)
1573 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1575 lio_dev_info(lio_dev, "closing port %d\n", eth_dev->data->port_id);
1577 if (lio_dev->intf_open)
1578 lio_dev_stop(eth_dev);
1580 /* Reset ioq regs */
1581 lio_dev->fn_list.setup_device_regs(lio_dev);
1583 if (lio_dev->pci_dev->kdrv == RTE_KDRV_IGB_UIO) {
1584 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1585 rte_delay_ms(LIO_PCI_FLR_WAIT);
1589 lio_dev->fn_list.free_mbox(lio_dev);
1591 /* Free glist resources */
1592 rte_free(lio_dev->glist_head);
1593 rte_free(lio_dev->glist_lock);
1594 lio_dev->glist_head = NULL;
1595 lio_dev->glist_lock = NULL;
1597 lio_dev->port_configured = 0;
1599 /* Delete all queues */
1600 lio_dev_clear_queues(eth_dev);
1604 * Enable tunnel rx checksum verification from firmware.
1607 lio_enable_hw_tunnel_rx_checksum(struct rte_eth_dev *eth_dev)
1609 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1610 struct lio_dev_ctrl_cmd ctrl_cmd;
1611 struct lio_ctrl_pkt ctrl_pkt;
1613 /* flush added to prevent cmd failure
1614 * incase the queue is full
1616 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1618 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1619 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1621 ctrl_cmd.eth_dev = eth_dev;
1624 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_RX_CSUM_CTL;
1625 ctrl_pkt.ncmd.s.param1 = LIO_CMD_RXCSUM_ENABLE;
1626 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1628 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1629 lio_dev_err(lio_dev, "Failed to send TNL_RX_CSUM command\n");
1633 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1634 lio_dev_err(lio_dev, "TNL_RX_CSUM command timed out\n");
1638 * Enable checksum calculation for inner packet in a tunnel.
1641 lio_enable_hw_tunnel_tx_checksum(struct rte_eth_dev *eth_dev)
1643 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1644 struct lio_dev_ctrl_cmd ctrl_cmd;
1645 struct lio_ctrl_pkt ctrl_pkt;
1647 /* flush added to prevent cmd failure
1648 * incase the queue is full
1650 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1652 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1653 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1655 ctrl_cmd.eth_dev = eth_dev;
1658 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_TX_CSUM_CTL;
1659 ctrl_pkt.ncmd.s.param1 = LIO_CMD_TXCSUM_ENABLE;
1660 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1662 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1663 lio_dev_err(lio_dev, "Failed to send TNL_TX_CSUM command\n");
1667 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1668 lio_dev_err(lio_dev, "TNL_TX_CSUM command timed out\n");
1672 lio_send_queue_count_update(struct rte_eth_dev *eth_dev, int num_txq,
1675 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1676 struct lio_dev_ctrl_cmd ctrl_cmd;
1677 struct lio_ctrl_pkt ctrl_pkt;
1679 if (strcmp(lio_dev->firmware_version, LIO_Q_RECONF_MIN_VERSION) < 0) {
1680 lio_dev_err(lio_dev, "Require firmware version >= %s\n",
1681 LIO_Q_RECONF_MIN_VERSION);
1685 /* flush added to prevent cmd failure
1686 * incase the queue is full
1688 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1690 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1691 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1693 ctrl_cmd.eth_dev = eth_dev;
1696 ctrl_pkt.ncmd.s.cmd = LIO_CMD_QUEUE_COUNT_CTL;
1697 ctrl_pkt.ncmd.s.param1 = num_txq;
1698 ctrl_pkt.ncmd.s.param2 = num_rxq;
1699 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1701 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1702 lio_dev_err(lio_dev, "Failed to send queue count control command\n");
1706 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
1707 lio_dev_err(lio_dev, "Queue count control command timed out\n");
1715 lio_reconf_queues(struct rte_eth_dev *eth_dev, int num_txq, int num_rxq)
1717 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1719 if (lio_dev->nb_rx_queues != num_rxq ||
1720 lio_dev->nb_tx_queues != num_txq) {
1721 if (lio_send_queue_count_update(eth_dev, num_txq, num_rxq))
1723 lio_dev->nb_rx_queues = num_rxq;
1724 lio_dev->nb_tx_queues = num_txq;
1727 if (lio_dev->intf_open)
1728 lio_dev_stop(eth_dev);
1730 /* Reset ioq registers */
1731 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1732 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1740 lio_dev_configure(struct rte_eth_dev *eth_dev)
1742 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1743 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1744 int retval, num_iqueues, num_oqueues;
1745 uint8_t mac[ETHER_ADDR_LEN], i;
1746 struct lio_if_cfg_resp *resp;
1747 struct lio_soft_command *sc;
1748 union lio_if_cfg if_cfg;
1751 PMD_INIT_FUNC_TRACE();
1753 /* Inform firmware about change in number of queues to use.
1754 * Disable IO queues and reset registers for re-configuration.
1756 if (lio_dev->port_configured)
1757 return lio_reconf_queues(eth_dev,
1758 eth_dev->data->nb_tx_queues,
1759 eth_dev->data->nb_rx_queues);
1761 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
1762 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
1764 /* Set max number of queues which can be re-configured. */
1765 lio_dev->max_rx_queues = eth_dev->data->nb_rx_queues;
1766 lio_dev->max_tx_queues = eth_dev->data->nb_tx_queues;
1768 resp_size = sizeof(struct lio_if_cfg_resp);
1769 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1773 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
1775 /* Firmware doesn't have capability to reconfigure the queues,
1776 * Claim all queues, and use as many required
1778 if_cfg.if_cfg64 = 0;
1779 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
1780 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
1781 if_cfg.s.base_queue = 0;
1783 if_cfg.s.gmx_port_id = lio_dev->pf_num;
1785 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1786 LIO_OPCODE_IF_CFG, 0,
1787 if_cfg.if_cfg64, 0);
1789 /* Setting wait time in seconds */
1790 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1792 retval = lio_send_soft_command(lio_dev, sc);
1793 if (retval == LIO_IQ_SEND_FAILED) {
1794 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
1796 /* Soft instr is freed by driver in case of failure. */
1797 goto nic_config_fail;
1800 /* Sleep on a wait queue till the cond flag indicates that the
1801 * response arrived or timed-out.
1803 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1804 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1805 lio_process_ordered_list(lio_dev);
1809 retval = resp->status;
1811 lio_dev_err(lio_dev, "iq/oq config failed\n");
1812 goto nic_config_fail;
1815 snprintf(lio_dev->firmware_version, LIO_FW_VERSION_LENGTH, "%s",
1816 resp->cfg_info.lio_firmware_version);
1818 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
1819 sizeof(struct octeon_if_cfg_info) >> 3);
1821 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
1822 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
1824 if (!(num_iqueues) || !(num_oqueues)) {
1825 lio_dev_err(lio_dev,
1826 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
1827 (unsigned long)resp->cfg_info.iqmask,
1828 (unsigned long)resp->cfg_info.oqmask);
1829 goto nic_config_fail;
1832 lio_dev_dbg(lio_dev,
1833 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
1834 eth_dev->data->port_id,
1835 (unsigned long)resp->cfg_info.iqmask,
1836 (unsigned long)resp->cfg_info.oqmask,
1837 num_iqueues, num_oqueues);
1839 lio_dev->linfo.num_rxpciq = num_oqueues;
1840 lio_dev->linfo.num_txpciq = num_iqueues;
1842 for (i = 0; i < num_oqueues; i++) {
1843 lio_dev->linfo.rxpciq[i].rxpciq64 =
1844 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
1845 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
1846 i, lio_dev->linfo.rxpciq[i].s.q_no);
1849 for (i = 0; i < num_iqueues; i++) {
1850 lio_dev->linfo.txpciq[i].txpciq64 =
1851 resp->cfg_info.linfo.txpciq[i].txpciq64;
1852 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
1853 i, lio_dev->linfo.txpciq[i].s.q_no);
1856 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1857 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1858 lio_dev->linfo.link.link_status64 =
1859 resp->cfg_info.linfo.link.link_status64;
1861 /* 64-bit swap required on LE machines */
1862 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
1863 for (i = 0; i < ETHER_ADDR_LEN; i++)
1864 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
1867 /* Copy the permanent MAC address */
1868 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
1870 /* enable firmware checksum support for tunnel packets */
1871 lio_enable_hw_tunnel_rx_checksum(eth_dev);
1872 lio_enable_hw_tunnel_tx_checksum(eth_dev);
1874 lio_dev->glist_lock =
1875 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
1876 if (lio_dev->glist_lock == NULL)
1879 lio_dev->glist_head =
1880 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
1882 if (lio_dev->glist_head == NULL) {
1883 rte_free(lio_dev->glist_lock);
1884 lio_dev->glist_lock = NULL;
1888 lio_dev_link_update(eth_dev, 0);
1890 lio_dev->port_configured = 1;
1892 lio_free_soft_command(sc);
1894 /* Reset ioq regs */
1895 lio_dev->fn_list.setup_device_regs(lio_dev);
1897 /* Free iq_0 used during init */
1898 lio_free_instr_queue0(lio_dev);
1903 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
1904 lio_free_soft_command(sc);
1905 lio_free_instr_queue0(lio_dev);
1910 /* Define our ethernet definitions */
1911 static const struct eth_dev_ops liovf_eth_dev_ops = {
1912 .dev_configure = lio_dev_configure,
1913 .dev_start = lio_dev_start,
1914 .dev_stop = lio_dev_stop,
1915 .dev_set_link_up = lio_dev_set_link_up,
1916 .dev_set_link_down = lio_dev_set_link_down,
1917 .dev_close = lio_dev_close,
1918 .promiscuous_enable = lio_dev_promiscuous_enable,
1919 .promiscuous_disable = lio_dev_promiscuous_disable,
1920 .allmulticast_enable = lio_dev_allmulticast_enable,
1921 .allmulticast_disable = lio_dev_allmulticast_disable,
1922 .link_update = lio_dev_link_update,
1923 .stats_get = lio_dev_stats_get,
1924 .xstats_get = lio_dev_xstats_get,
1925 .xstats_get_names = lio_dev_xstats_get_names,
1926 .stats_reset = lio_dev_stats_reset,
1927 .xstats_reset = lio_dev_xstats_reset,
1928 .dev_infos_get = lio_dev_info_get,
1929 .vlan_filter_set = lio_dev_vlan_filter_set,
1930 .rx_queue_setup = lio_dev_rx_queue_setup,
1931 .rx_queue_release = lio_dev_rx_queue_release,
1932 .tx_queue_setup = lio_dev_tx_queue_setup,
1933 .tx_queue_release = lio_dev_tx_queue_release,
1934 .reta_update = lio_dev_rss_reta_update,
1935 .reta_query = lio_dev_rss_reta_query,
1936 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
1937 .rss_hash_update = lio_dev_rss_hash_update,
1938 .udp_tunnel_port_add = lio_dev_udp_tunnel_add,
1939 .udp_tunnel_port_del = lio_dev_udp_tunnel_del,
1940 .mtu_set = lio_dev_mtu_set,
1944 lio_check_pf_hs_response(void *lio_dev)
1946 struct lio_device *dev = lio_dev;
1948 /* check till response arrives */
1949 if (dev->pfvf_hsword.coproc_tics_per_us)
1952 cn23xx_vf_handle_mbox(dev);
1954 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1958 * \brief Identify the LIO device and to map the BAR address space
1959 * @param lio_dev lio device
1962 lio_chip_specific_setup(struct lio_device *lio_dev)
1964 struct rte_pci_device *pdev = lio_dev->pci_dev;
1965 uint32_t dev_id = pdev->id.device_id;
1970 case LIO_CN23XX_VF_VID:
1971 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1972 ret = cn23xx_vf_setup_device(lio_dev);
1977 lio_dev_err(lio_dev, "Unsupported Chip\n");
1981 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1987 lio_first_time_init(struct lio_device *lio_dev,
1988 struct rte_pci_device *pdev)
1992 PMD_INIT_FUNC_TRACE();
1994 /* set dpdk specific pci device pointer */
1995 lio_dev->pci_dev = pdev;
1997 /* Identify the LIO type and set device ops */
1998 if (lio_chip_specific_setup(lio_dev)) {
1999 lio_dev_err(lio_dev, "Chip specific setup failed\n");
2003 /* Initialize soft command buffer pool */
2004 if (lio_setup_sc_buffer_pool(lio_dev)) {
2005 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
2009 /* Initialize lists to manage the requests of different types that
2010 * arrive from applications for this lio device.
2012 lio_setup_response_list(lio_dev);
2014 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
2015 lio_dev_err(lio_dev, "Mailbox setup failed\n");
2019 /* Check PF response */
2020 lio_check_pf_hs_response((void *)lio_dev);
2022 /* Do handshake and exit if incompatible PF driver */
2023 if (cn23xx_pfvf_handshake(lio_dev))
2026 /* Request and wait for device reset. */
2027 if (pdev->kdrv == RTE_KDRV_IGB_UIO) {
2028 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
2029 /* FLR wait time doubled as a precaution. */
2030 rte_delay_ms(LIO_PCI_FLR_WAIT * 2);
2033 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
2034 lio_dev_err(lio_dev, "Failed to configure device registers\n");
2038 if (lio_setup_instr_queue0(lio_dev)) {
2039 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
2043 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
2045 lio_dev->max_tx_queues = dpdk_queues;
2046 lio_dev->max_rx_queues = dpdk_queues;
2048 /* Enable input and output queues for this device */
2049 if (lio_dev->fn_list.enable_io_queues(lio_dev))
2055 lio_free_sc_buffer_pool(lio_dev);
2056 if (lio_dev->mbox[0])
2057 lio_dev->fn_list.free_mbox(lio_dev);
2058 if (lio_dev->instr_queue[0])
2059 lio_free_instr_queue0(lio_dev);
2065 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
2067 struct lio_device *lio_dev = LIO_DEV(eth_dev);
2069 PMD_INIT_FUNC_TRACE();
2071 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2074 /* lio_free_sc_buffer_pool */
2075 lio_free_sc_buffer_pool(lio_dev);
2077 rte_free(eth_dev->data->mac_addrs);
2078 eth_dev->data->mac_addrs = NULL;
2080 eth_dev->dev_ops = NULL;
2081 eth_dev->rx_pkt_burst = NULL;
2082 eth_dev->tx_pkt_burst = NULL;
2088 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
2090 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(eth_dev);
2091 struct lio_device *lio_dev = LIO_DEV(eth_dev);
2093 PMD_INIT_FUNC_TRACE();
2095 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
2096 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
2098 /* Primary does the initialization. */
2099 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2102 rte_eth_copy_pci_info(eth_dev, pdev);
2104 if (pdev->mem_resource[0].addr) {
2105 lio_dev->hw_addr = pdev->mem_resource[0].addr;
2107 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
2111 lio_dev->eth_dev = eth_dev;
2112 /* set lio device print string */
2113 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
2114 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
2115 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
2117 lio_dev->port_id = eth_dev->data->port_id;
2119 if (lio_first_time_init(lio_dev, pdev)) {
2120 lio_dev_err(lio_dev, "Device init failed\n");
2124 eth_dev->dev_ops = &liovf_eth_dev_ops;
2125 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
2126 if (eth_dev->data->mac_addrs == NULL) {
2127 lio_dev_err(lio_dev,
2128 "MAC addresses memory allocation failed\n");
2129 eth_dev->dev_ops = NULL;
2130 eth_dev->rx_pkt_burst = NULL;
2131 eth_dev->tx_pkt_burst = NULL;
2135 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
2138 lio_dev->port_configured = 0;
2139 /* Always allow unicast packets */
2140 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
2146 lio_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2147 struct rte_pci_device *pci_dev)
2149 struct rte_eth_dev *eth_dev;
2152 eth_dev = rte_eth_dev_pci_allocate(pci_dev,
2153 sizeof(struct lio_device));
2154 if (eth_dev == NULL)
2157 ret = lio_eth_dev_init(eth_dev);
2159 rte_eth_dev_pci_release(eth_dev);
2165 lio_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
2167 return rte_eth_dev_pci_generic_remove(pci_dev,
2168 lio_eth_dev_uninit);
2171 /* Set of PCI devices this driver supports */
2172 static const struct rte_pci_id pci_id_liovf_map[] = {
2173 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
2174 { .vendor_id = 0, /* sentinel */ }
2177 static struct rte_pci_driver rte_liovf_pmd = {
2178 .id_table = pci_id_liovf_map,
2179 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
2180 .probe = lio_eth_dev_pci_probe,
2181 .remove = lio_eth_dev_pci_remove,
2184 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd);
2185 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
2186 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio-pci");
2188 RTE_INIT(lio_init_log);
2192 lio_logtype_init = rte_log_register("pmd.lio.init");
2193 if (lio_logtype_init >= 0)
2194 rte_log_set_level(lio_logtype_init, RTE_LOG_NOTICE);
2195 lio_logtype_driver = rte_log_register("pmd.lio.driver");
2196 if (lio_logtype_driver >= 0)
2197 rte_log_set_level(lio_logtype_driver, RTE_LOG_NOTICE);