4 * Copyright(c) 2017 Cavium, Inc.. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Cavium, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_ethdev.h>
35 #include <rte_ethdev_pci.h>
36 #include <rte_cycles.h>
37 #include <rte_malloc.h>
38 #include <rte_alarm.h>
41 #include "lio_23xx_vf.h"
42 #include "lio_ethdev.h"
45 /* Default RSS key in use */
46 static uint8_t lio_rss_key[40] = {
47 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
48 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
49 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
50 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
51 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
54 static const struct rte_eth_desc_lim lio_rx_desc_lim = {
55 .nb_max = CN23XX_MAX_OQ_DESCRIPTORS,
56 .nb_min = CN23XX_MIN_OQ_DESCRIPTORS,
60 static const struct rte_eth_desc_lim lio_tx_desc_lim = {
61 .nb_max = CN23XX_MAX_IQ_DESCRIPTORS,
62 .nb_min = CN23XX_MIN_IQ_DESCRIPTORS,
66 /* Wait for control command to reach nic. */
68 lio_wait_for_ctrl_cmd(struct lio_device *lio_dev,
69 struct lio_dev_ctrl_cmd *ctrl_cmd)
71 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
73 while ((ctrl_cmd->cond == 0) && --timeout) {
74 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
82 * \brief Send Rx control command
83 * @param eth_dev Pointer to the structure rte_eth_dev
84 * @param start_stop whether to start or stop
87 lio_send_rx_ctrl_cmd(struct rte_eth_dev *eth_dev, int start_stop)
89 struct lio_device *lio_dev = LIO_DEV(eth_dev);
90 struct lio_dev_ctrl_cmd ctrl_cmd;
91 struct lio_ctrl_pkt ctrl_pkt;
93 /* flush added to prevent cmd failure
94 * incase the queue is full
96 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
98 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
99 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
101 ctrl_cmd.eth_dev = eth_dev;
104 ctrl_pkt.ncmd.s.cmd = LIO_CMD_RX_CTL;
105 ctrl_pkt.ncmd.s.param1 = start_stop;
106 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
108 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
109 lio_dev_err(lio_dev, "Failed to send RX Control message\n");
113 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
114 lio_dev_err(lio_dev, "RX Control command timed out\n");
121 /* store statistics names and its offset in stats structure */
122 struct rte_lio_xstats_name_off {
123 char name[RTE_ETH_XSTATS_NAME_SIZE];
127 static const struct rte_lio_xstats_name_off rte_lio_stats_strings[] = {
128 {"rx_pkts", offsetof(struct octeon_rx_stats, total_rcvd)},
129 {"rx_bytes", offsetof(struct octeon_rx_stats, bytes_rcvd)},
130 {"rx_broadcast_pkts", offsetof(struct octeon_rx_stats, total_bcst)},
131 {"rx_multicast_pkts", offsetof(struct octeon_rx_stats, total_mcst)},
132 {"rx_flow_ctrl_pkts", offsetof(struct octeon_rx_stats, ctl_rcvd)},
133 {"rx_fifo_err", offsetof(struct octeon_rx_stats, fifo_err)},
134 {"rx_dmac_drop", offsetof(struct octeon_rx_stats, dmac_drop)},
135 {"rx_fcs_err", offsetof(struct octeon_rx_stats, fcs_err)},
136 {"rx_jabber_err", offsetof(struct octeon_rx_stats, jabber_err)},
137 {"rx_l2_err", offsetof(struct octeon_rx_stats, l2_err)},
138 {"rx_vxlan_pkts", offsetof(struct octeon_rx_stats, fw_rx_vxlan)},
139 {"rx_vxlan_err", offsetof(struct octeon_rx_stats, fw_rx_vxlan_err)},
140 {"rx_lro_pkts", offsetof(struct octeon_rx_stats, fw_lro_pkts)},
141 {"tx_pkts", (offsetof(struct octeon_tx_stats, total_pkts_sent)) +
142 sizeof(struct octeon_rx_stats)},
143 {"tx_bytes", (offsetof(struct octeon_tx_stats, total_bytes_sent)) +
144 sizeof(struct octeon_rx_stats)},
145 {"tx_broadcast_pkts",
146 (offsetof(struct octeon_tx_stats, bcast_pkts_sent)) +
147 sizeof(struct octeon_rx_stats)},
148 {"tx_multicast_pkts",
149 (offsetof(struct octeon_tx_stats, mcast_pkts_sent)) +
150 sizeof(struct octeon_rx_stats)},
151 {"tx_flow_ctrl_pkts", (offsetof(struct octeon_tx_stats, ctl_sent)) +
152 sizeof(struct octeon_rx_stats)},
153 {"tx_fifo_err", (offsetof(struct octeon_tx_stats, fifo_err)) +
154 sizeof(struct octeon_rx_stats)},
155 {"tx_total_collisions", (offsetof(struct octeon_tx_stats,
157 sizeof(struct octeon_rx_stats)},
158 {"tx_tso", (offsetof(struct octeon_tx_stats, fw_tso)) +
159 sizeof(struct octeon_rx_stats)},
160 {"tx_vxlan_pkts", (offsetof(struct octeon_tx_stats, fw_tx_vxlan)) +
161 sizeof(struct octeon_rx_stats)},
164 #define LIO_NB_XSTATS RTE_DIM(rte_lio_stats_strings)
166 /* Get hw stats of the port */
168 lio_dev_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *xstats,
171 struct lio_device *lio_dev = LIO_DEV(eth_dev);
172 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
173 struct octeon_link_stats *hw_stats;
174 struct lio_link_stats_resp *resp;
175 struct lio_soft_command *sc;
180 if (!lio_dev->intf_open) {
181 lio_dev_err(lio_dev, "Port %d down\n",
186 if (n < LIO_NB_XSTATS)
187 return LIO_NB_XSTATS;
189 resp_size = sizeof(struct lio_link_stats_resp);
190 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
194 resp = (struct lio_link_stats_resp *)sc->virtrptr;
195 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
196 LIO_OPCODE_PORT_STATS, 0, 0, 0);
198 /* Setting wait time in seconds */
199 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
201 retval = lio_send_soft_command(lio_dev, sc);
202 if (retval == LIO_IQ_SEND_FAILED) {
203 lio_dev_err(lio_dev, "failed to get port stats from firmware. status: %x\n",
208 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
209 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
210 lio_process_ordered_list(lio_dev);
214 retval = resp->status;
216 lio_dev_err(lio_dev, "failed to get port stats from firmware\n");
220 lio_swap_8B_data((uint64_t *)(&resp->link_stats),
221 sizeof(struct octeon_link_stats) >> 3);
223 hw_stats = &resp->link_stats;
225 for (i = 0; i < LIO_NB_XSTATS; i++) {
228 *(uint64_t *)(((char *)hw_stats) +
229 rte_lio_stats_strings[i].offset);
232 lio_free_soft_command(sc);
234 return LIO_NB_XSTATS;
237 lio_free_soft_command(sc);
243 lio_dev_xstats_get_names(struct rte_eth_dev *eth_dev,
244 struct rte_eth_xstat_name *xstats_names,
245 unsigned limit __rte_unused)
247 struct lio_device *lio_dev = LIO_DEV(eth_dev);
250 if (!lio_dev->intf_open) {
251 lio_dev_err(lio_dev, "Port %d down\n",
256 if (xstats_names == NULL)
257 return LIO_NB_XSTATS;
259 /* Note: limit checked in rte_eth_xstats_names() */
261 for (i = 0; i < LIO_NB_XSTATS; i++) {
262 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
263 "%s", rte_lio_stats_strings[i].name);
266 return LIO_NB_XSTATS;
269 /* Reset hw stats for the port */
271 lio_dev_xstats_reset(struct rte_eth_dev *eth_dev)
273 struct lio_device *lio_dev = LIO_DEV(eth_dev);
274 struct lio_dev_ctrl_cmd ctrl_cmd;
275 struct lio_ctrl_pkt ctrl_pkt;
277 if (!lio_dev->intf_open) {
278 lio_dev_err(lio_dev, "Port %d down\n",
283 /* flush added to prevent cmd failure
284 * incase the queue is full
286 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
288 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
289 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
291 ctrl_cmd.eth_dev = eth_dev;
294 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CLEAR_STATS;
295 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
297 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
298 lio_dev_err(lio_dev, "Failed to send clear stats command\n");
302 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
303 lio_dev_err(lio_dev, "Clear stats command timed out\n");
307 /* clear stored per queue stats */
308 RTE_FUNC_PTR_OR_RET(*eth_dev->dev_ops->stats_reset);
309 (*eth_dev->dev_ops->stats_reset)(eth_dev);
312 /* Retrieve the device statistics (# packets in/out, # bytes in/out, etc */
314 lio_dev_stats_get(struct rte_eth_dev *eth_dev,
315 struct rte_eth_stats *stats)
317 struct lio_device *lio_dev = LIO_DEV(eth_dev);
318 struct lio_droq_stats *oq_stats;
319 struct lio_iq_stats *iq_stats;
320 struct lio_instr_queue *txq;
321 struct lio_droq *droq;
327 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
328 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
329 txq = lio_dev->instr_queue[iq_no];
331 iq_stats = &txq->stats;
332 pkts += iq_stats->tx_done;
333 drop += iq_stats->tx_dropped;
334 bytes += iq_stats->tx_tot_bytes;
338 stats->opackets = pkts;
339 stats->obytes = bytes;
340 stats->oerrors = drop;
346 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
347 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
348 droq = lio_dev->droq[oq_no];
350 oq_stats = &droq->stats;
351 pkts += oq_stats->rx_pkts_received;
352 drop += (oq_stats->rx_dropped +
353 oq_stats->dropped_toomany +
354 oq_stats->dropped_nomem);
355 bytes += oq_stats->rx_bytes_received;
358 stats->ibytes = bytes;
359 stats->ipackets = pkts;
360 stats->ierrors = drop;
364 lio_dev_stats_reset(struct rte_eth_dev *eth_dev)
366 struct lio_device *lio_dev = LIO_DEV(eth_dev);
367 struct lio_droq_stats *oq_stats;
368 struct lio_iq_stats *iq_stats;
369 struct lio_instr_queue *txq;
370 struct lio_droq *droq;
373 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
374 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
375 txq = lio_dev->instr_queue[iq_no];
377 iq_stats = &txq->stats;
378 memset(iq_stats, 0, sizeof(struct lio_iq_stats));
382 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
383 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
384 droq = lio_dev->droq[oq_no];
386 oq_stats = &droq->stats;
387 memset(oq_stats, 0, sizeof(struct lio_droq_stats));
393 lio_dev_info_get(struct rte_eth_dev *eth_dev,
394 struct rte_eth_dev_info *devinfo)
396 struct lio_device *lio_dev = LIO_DEV(eth_dev);
398 devinfo->max_rx_queues = lio_dev->max_rx_queues;
399 devinfo->max_tx_queues = lio_dev->max_tx_queues;
401 devinfo->min_rx_bufsize = LIO_MIN_RX_BUF_SIZE;
402 devinfo->max_rx_pktlen = LIO_MAX_RX_PKTLEN;
404 devinfo->max_mac_addrs = 1;
406 devinfo->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
407 DEV_RX_OFFLOAD_UDP_CKSUM |
408 DEV_RX_OFFLOAD_TCP_CKSUM |
409 DEV_RX_OFFLOAD_VLAN_STRIP);
410 devinfo->tx_offload_capa = (DEV_TX_OFFLOAD_IPV4_CKSUM |
411 DEV_TX_OFFLOAD_UDP_CKSUM |
412 DEV_TX_OFFLOAD_TCP_CKSUM |
413 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM);
415 devinfo->rx_desc_lim = lio_rx_desc_lim;
416 devinfo->tx_desc_lim = lio_tx_desc_lim;
418 devinfo->reta_size = LIO_RSS_MAX_TABLE_SZ;
419 devinfo->hash_key_size = LIO_RSS_MAX_KEY_SZ;
420 devinfo->flow_type_rss_offloads = (ETH_RSS_IPV4 |
421 ETH_RSS_NONFRAG_IPV4_TCP |
423 ETH_RSS_NONFRAG_IPV6_TCP |
425 ETH_RSS_IPV6_TCP_EX);
429 lio_dev_validate_vf_mtu(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
431 struct lio_device *lio_dev = LIO_DEV(eth_dev);
433 PMD_INIT_FUNC_TRACE();
435 if (!lio_dev->intf_open) {
436 lio_dev_err(lio_dev, "Port %d down, can't check MTU\n",
441 /* Limit the MTU to make sure the ethernet packets are between
442 * ETHER_MIN_MTU bytes and PF's MTU
444 if ((new_mtu < ETHER_MIN_MTU) ||
445 (new_mtu > lio_dev->linfo.link.s.mtu)) {
446 lio_dev_err(lio_dev, "Invalid MTU: %d\n", new_mtu);
447 lio_dev_err(lio_dev, "Valid range %d and %d\n",
448 ETHER_MIN_MTU, lio_dev->linfo.link.s.mtu);
456 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
457 struct rte_eth_rss_reta_entry64 *reta_conf,
460 struct lio_device *lio_dev = LIO_DEV(eth_dev);
461 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
462 struct lio_rss_set *rss_param;
463 struct lio_dev_ctrl_cmd ctrl_cmd;
464 struct lio_ctrl_pkt ctrl_pkt;
467 if (!lio_dev->intf_open) {
468 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
473 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
475 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
476 reta_size, LIO_RSS_MAX_TABLE_SZ);
480 /* flush added to prevent cmd failure
481 * incase the queue is full
483 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
485 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
486 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
488 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
490 ctrl_cmd.eth_dev = eth_dev;
493 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
494 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
495 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
497 rss_param->param.flags = 0xF;
498 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
499 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
501 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
502 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
503 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
504 index = (i * RTE_RETA_GROUP_SIZE) + j;
505 rss_state->itable[index] = reta_conf[i].reta[j];
510 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
511 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
513 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
515 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
516 lio_dev_err(lio_dev, "Failed to set rss hash\n");
520 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
521 lio_dev_err(lio_dev, "Set rss hash timed out\n");
529 lio_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
530 struct rte_eth_rss_reta_entry64 *reta_conf,
533 struct lio_device *lio_dev = LIO_DEV(eth_dev);
534 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
537 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
539 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
540 reta_size, LIO_RSS_MAX_TABLE_SZ);
544 num = reta_size / RTE_RETA_GROUP_SIZE;
546 for (i = 0; i < num; i++) {
547 memcpy(reta_conf->reta,
548 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
549 RTE_RETA_GROUP_SIZE);
557 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
558 struct rte_eth_rss_conf *rss_conf)
560 struct lio_device *lio_dev = LIO_DEV(eth_dev);
561 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
562 uint8_t *hash_key = NULL;
565 if (rss_state->hash_disable) {
566 lio_dev_info(lio_dev, "RSS disabled in nic\n");
567 rss_conf->rss_hf = 0;
572 hash_key = rss_conf->rss_key;
573 if (hash_key != NULL)
574 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
577 rss_hf |= ETH_RSS_IPV4;
578 if (rss_state->tcp_hash)
579 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
581 rss_hf |= ETH_RSS_IPV6;
582 if (rss_state->ipv6_tcp_hash)
583 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
584 if (rss_state->ipv6_ex)
585 rss_hf |= ETH_RSS_IPV6_EX;
586 if (rss_state->ipv6_tcp_ex_hash)
587 rss_hf |= ETH_RSS_IPV6_TCP_EX;
589 rss_conf->rss_hf = rss_hf;
595 lio_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
596 struct rte_eth_rss_conf *rss_conf)
598 struct lio_device *lio_dev = LIO_DEV(eth_dev);
599 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
600 struct lio_rss_set *rss_param;
601 struct lio_dev_ctrl_cmd ctrl_cmd;
602 struct lio_ctrl_pkt ctrl_pkt;
604 if (!lio_dev->intf_open) {
605 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
610 /* flush added to prevent cmd failure
611 * incase the queue is full
613 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
615 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
616 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
618 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
620 ctrl_cmd.eth_dev = eth_dev;
623 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
624 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
625 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
627 rss_param->param.flags = 0xF;
629 if (rss_conf->rss_key) {
630 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
631 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
632 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
633 memcpy(rss_state->hash_key, rss_conf->rss_key,
634 rss_state->hash_key_size);
635 memcpy(rss_param->key, rss_state->hash_key,
636 rss_state->hash_key_size);
639 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
640 /* Can't disable rss through hash flags,
641 * if it is enabled by default during init
643 if (!rss_state->hash_disable)
646 /* This is for --disable-rss during testpmd launch */
647 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
649 uint32_t hashinfo = 0;
651 /* Can't enable rss if disabled by default during init */
652 if (rss_state->hash_disable)
655 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
656 hashinfo |= LIO_RSS_HASH_IPV4;
662 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
663 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
664 rss_state->tcp_hash = 1;
666 rss_state->tcp_hash = 0;
669 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
670 hashinfo |= LIO_RSS_HASH_IPV6;
676 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
677 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
678 rss_state->ipv6_tcp_hash = 1;
680 rss_state->ipv6_tcp_hash = 0;
683 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
684 hashinfo |= LIO_RSS_HASH_IPV6_EX;
685 rss_state->ipv6_ex = 1;
687 rss_state->ipv6_ex = 0;
690 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
691 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
692 rss_state->ipv6_tcp_ex_hash = 1;
694 rss_state->ipv6_tcp_ex_hash = 0;
697 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
698 rss_param->param.hashinfo = hashinfo;
701 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
703 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
704 lio_dev_err(lio_dev, "Failed to set rss hash\n");
708 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
709 lio_dev_err(lio_dev, "Set rss hash timed out\n");
717 * Add vxlan dest udp port for an interface.
720 * Pointer to the structure rte_eth_dev
725 * On success return 0
726 * On failure return -1
729 lio_dev_udp_tunnel_add(struct rte_eth_dev *eth_dev,
730 struct rte_eth_udp_tunnel *udp_tnl)
732 struct lio_device *lio_dev = LIO_DEV(eth_dev);
733 struct lio_dev_ctrl_cmd ctrl_cmd;
734 struct lio_ctrl_pkt ctrl_pkt;
739 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
740 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
744 /* flush added to prevent cmd failure
745 * incase the queue is full
747 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
749 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
750 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
752 ctrl_cmd.eth_dev = eth_dev;
755 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
756 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
757 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_ADD;
758 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
760 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
761 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_ADD command\n");
765 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
766 lio_dev_err(lio_dev, "VXLAN_PORT_ADD command timed out\n");
774 * Remove vxlan dest udp port for an interface.
777 * Pointer to the structure rte_eth_dev
782 * On success return 0
783 * On failure return -1
786 lio_dev_udp_tunnel_del(struct rte_eth_dev *eth_dev,
787 struct rte_eth_udp_tunnel *udp_tnl)
789 struct lio_device *lio_dev = LIO_DEV(eth_dev);
790 struct lio_dev_ctrl_cmd ctrl_cmd;
791 struct lio_ctrl_pkt ctrl_pkt;
796 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
797 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
801 /* flush added to prevent cmd failure
802 * incase the queue is full
804 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
806 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
807 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
809 ctrl_cmd.eth_dev = eth_dev;
812 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
813 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
814 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_DEL;
815 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
817 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
818 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_DEL command\n");
822 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
823 lio_dev_err(lio_dev, "VXLAN_PORT_DEL command timed out\n");
831 lio_dev_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id, int on)
833 struct lio_device *lio_dev = LIO_DEV(eth_dev);
834 struct lio_dev_ctrl_cmd ctrl_cmd;
835 struct lio_ctrl_pkt ctrl_pkt;
837 if (lio_dev->linfo.vlan_is_admin_assigned)
840 /* flush added to prevent cmd failure
841 * incase the queue is full
843 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
845 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
846 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
848 ctrl_cmd.eth_dev = eth_dev;
851 ctrl_pkt.ncmd.s.cmd = on ?
852 LIO_CMD_ADD_VLAN_FILTER : LIO_CMD_DEL_VLAN_FILTER;
853 ctrl_pkt.ncmd.s.param1 = vlan_id;
854 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
856 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
857 lio_dev_err(lio_dev, "Failed to %s VLAN port\n",
858 on ? "add" : "remove");
862 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
863 lio_dev_err(lio_dev, "Command to %s VLAN port timed out\n",
864 on ? "add" : "remove");
872 * Atomically writes the link status information into global
873 * structure rte_eth_dev.
876 * - Pointer to the structure rte_eth_dev to read from.
877 * - Pointer to the buffer to be saved with the link status.
880 * - On success, zero.
881 * - On failure, negative value.
884 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
885 struct rte_eth_link *link)
887 struct rte_eth_link *dst = ð_dev->data->dev_link;
888 struct rte_eth_link *src = link;
890 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
891 *(uint64_t *)src) == 0)
898 lio_hweight64(uint64_t w)
900 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
903 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
904 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
905 res = res + (res >> 8);
906 res = res + (res >> 16);
908 return (res + (res >> 32)) & 0x00000000000000FFul;
912 lio_dev_link_update(struct rte_eth_dev *eth_dev,
913 int wait_to_complete __rte_unused)
915 struct lio_device *lio_dev = LIO_DEV(eth_dev);
916 struct rte_eth_link link, old;
919 link.link_status = ETH_LINK_DOWN;
920 link.link_speed = ETH_SPEED_NUM_NONE;
921 link.link_duplex = ETH_LINK_HALF_DUPLEX;
922 memset(&old, 0, sizeof(old));
924 /* Return what we found */
925 if (lio_dev->linfo.link.s.link_up == 0) {
926 /* Interface is down */
927 if (lio_dev_atomic_write_link_status(eth_dev, &link))
929 if (link.link_status == old.link_status)
934 link.link_status = ETH_LINK_UP; /* Interface is up */
935 link.link_duplex = ETH_LINK_FULL_DUPLEX;
936 switch (lio_dev->linfo.link.s.speed) {
937 case LIO_LINK_SPEED_10000:
938 link.link_speed = ETH_SPEED_NUM_10G;
940 case LIO_LINK_SPEED_25000:
941 link.link_speed = ETH_SPEED_NUM_25G;
944 link.link_speed = ETH_SPEED_NUM_NONE;
945 link.link_duplex = ETH_LINK_HALF_DUPLEX;
948 if (lio_dev_atomic_write_link_status(eth_dev, &link))
951 if (link.link_status == old.link_status)
958 * \brief Net device enable, disable allmulticast
959 * @param eth_dev Pointer to the structure rte_eth_dev
962 lio_change_dev_flag(struct rte_eth_dev *eth_dev)
964 struct lio_device *lio_dev = LIO_DEV(eth_dev);
965 struct lio_dev_ctrl_cmd ctrl_cmd;
966 struct lio_ctrl_pkt ctrl_pkt;
968 /* flush added to prevent cmd failure
969 * incase the queue is full
971 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
973 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
974 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
976 ctrl_cmd.eth_dev = eth_dev;
979 /* Create a ctrl pkt command to be sent to core app. */
980 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CHANGE_DEVFLAGS;
981 ctrl_pkt.ncmd.s.param1 = lio_dev->ifflags;
982 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
984 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
985 lio_dev_err(lio_dev, "Failed to send change flag message\n");
989 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
990 lio_dev_err(lio_dev, "Change dev flag command timed out\n");
994 lio_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
996 struct lio_device *lio_dev = LIO_DEV(eth_dev);
998 if (!lio_dev->intf_open) {
999 lio_dev_err(lio_dev, "Port %d down, can't enable multicast\n",
1004 lio_dev->ifflags |= LIO_IFFLAG_ALLMULTI;
1005 lio_change_dev_flag(eth_dev);
1009 lio_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
1011 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1013 if (!lio_dev->intf_open) {
1014 lio_dev_err(lio_dev, "Port %d down, can't disable multicast\n",
1019 lio_dev->ifflags &= ~LIO_IFFLAG_ALLMULTI;
1020 lio_change_dev_flag(eth_dev);
1024 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
1026 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1027 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1028 struct rte_eth_rss_reta_entry64 reta_conf[8];
1029 struct rte_eth_rss_conf rss_conf;
1032 /* Configure the RSS key and the RSS protocols used to compute
1033 * the RSS hash of input packets.
1035 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
1036 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
1037 rss_state->hash_disable = 1;
1038 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1042 if (rss_conf.rss_key == NULL)
1043 rss_conf.rss_key = lio_rss_key; /* Default hash key */
1045 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1047 memset(reta_conf, 0, sizeof(reta_conf));
1048 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
1049 uint8_t q_idx, conf_idx, reta_idx;
1051 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
1052 i % eth_dev->data->nb_rx_queues : 0);
1053 conf_idx = i / RTE_RETA_GROUP_SIZE;
1054 reta_idx = i % RTE_RETA_GROUP_SIZE;
1055 reta_conf[conf_idx].reta[reta_idx] = q_idx;
1056 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
1059 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
1063 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
1065 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1066 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1067 struct rte_eth_rss_conf rss_conf;
1069 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
1071 lio_dev_rss_configure(eth_dev);
1073 case ETH_MQ_RX_NONE:
1074 /* if mq_mode is none, disable rss mode. */
1076 memset(&rss_conf, 0, sizeof(rss_conf));
1077 rss_state->hash_disable = 1;
1078 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1083 * Setup our receive queue/ringbuffer. This is the
1084 * queue the Octeon uses to send us packets and
1085 * responses. We are given a memory pool for our
1086 * packet buffers that are used to populate the receive
1090 * Pointer to the structure rte_eth_dev
1093 * @param num_rx_descs
1094 * Number of entries in the queue
1096 * Where to allocate memory
1098 * Pointer to the struction rte_eth_rxconf
1100 * Pointer to the packet pool
1103 * - On success, return 0
1104 * - On failure, return -1
1107 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1108 uint16_t num_rx_descs, unsigned int socket_id,
1109 const struct rte_eth_rxconf *rx_conf __rte_unused,
1110 struct rte_mempool *mp)
1112 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1113 struct rte_pktmbuf_pool_private *mbp_priv;
1114 uint32_t fw_mapped_oq;
1117 if (q_no >= lio_dev->nb_rx_queues) {
1118 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
1122 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
1124 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
1126 if ((lio_dev->droq[fw_mapped_oq]) &&
1127 (num_rx_descs != lio_dev->droq[fw_mapped_oq]->max_count)) {
1128 lio_dev_err(lio_dev,
1129 "Reconfiguring Rx descs not supported. Configure descs to same value %u or restart application\n",
1130 lio_dev->droq[fw_mapped_oq]->max_count);
1134 mbp_priv = rte_mempool_get_priv(mp);
1135 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
1137 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
1139 lio_dev_err(lio_dev, "droq allocation failed\n");
1143 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
1149 * Release the receive queue/ringbuffer. Called by
1153 * Opaque pointer to the receive queue to release
1159 lio_dev_rx_queue_release(void *rxq)
1161 struct lio_droq *droq = rxq;
1165 /* Run time queue deletion not supported */
1166 if (droq->lio_dev->port_configured)
1170 lio_delete_droq_queue(droq->lio_dev, oq_no);
1175 * Allocate and initialize SW ring. Initialize associated HW registers.
1178 * Pointer to structure rte_eth_dev
1183 * @param num_tx_descs
1184 * Number of ringbuffer descriptors
1187 * NUMA socket id, used for memory allocations
1190 * Pointer to the structure rte_eth_txconf
1193 * - On success, return 0
1194 * - On failure, return -errno value
1197 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1198 uint16_t num_tx_descs, unsigned int socket_id,
1199 const struct rte_eth_txconf *tx_conf __rte_unused)
1201 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1202 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
1205 if (q_no >= lio_dev->nb_tx_queues) {
1206 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
1210 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
1212 if ((lio_dev->instr_queue[fw_mapped_iq] != NULL) &&
1213 (num_tx_descs != lio_dev->instr_queue[fw_mapped_iq]->max_count)) {
1214 lio_dev_err(lio_dev,
1215 "Reconfiguring Tx descs not supported. Configure descs to same value %u or restart application\n",
1216 lio_dev->instr_queue[fw_mapped_iq]->max_count);
1220 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
1221 num_tx_descs, lio_dev, socket_id);
1224 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
1228 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
1229 lio_dev->instr_queue[fw_mapped_iq]->max_count,
1233 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
1237 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
1243 * Release the transmit queue/ringbuffer. Called by
1247 * Opaque pointer to the transmit queue to release
1253 lio_dev_tx_queue_release(void *txq)
1255 struct lio_instr_queue *tq = txq;
1256 uint32_t fw_mapped_iq_no;
1260 /* Run time queue deletion not supported */
1261 if (tq->lio_dev->port_configured)
1265 lio_delete_sglist(tq);
1267 fw_mapped_iq_no = tq->txpciq.s.q_no;
1268 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
1273 * Api to check link state.
1276 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
1278 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1279 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1280 struct lio_link_status_resp *resp;
1281 union octeon_link_status *ls;
1282 struct lio_soft_command *sc;
1285 if (!lio_dev->intf_open)
1288 resp_size = sizeof(struct lio_link_status_resp);
1289 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1293 resp = (struct lio_link_status_resp *)sc->virtrptr;
1294 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1295 LIO_OPCODE_INFO, 0, 0, 0);
1297 /* Setting wait time in seconds */
1298 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1300 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
1301 goto get_status_fail;
1303 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1304 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1309 goto get_status_fail;
1311 ls = &resp->link_info.link;
1313 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
1315 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
1316 lio_dev->linfo.link.link_status64 = ls->link_status64;
1317 lio_dev_link_update(eth_dev, 0);
1320 lio_free_soft_command(sc);
1325 lio_free_soft_command(sc);
1328 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
1329 * and will update link state if it changes.
1332 lio_sync_link_state_check(void *eth_dev)
1334 struct lio_device *lio_dev =
1335 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
1337 if (lio_dev->port_configured)
1338 lio_dev_get_link_status(eth_dev);
1340 /* Schedule periodic link status check.
1341 * Stop check if interface is close and start again while opening.
1343 if (lio_dev->intf_open)
1344 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
1349 lio_dev_start(struct rte_eth_dev *eth_dev)
1351 uint16_t mtu = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
1352 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1353 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1356 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
1358 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1361 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
1364 /* Ready for link status updates */
1365 lio_dev->intf_open = 1;
1368 /* Configure RSS if device configured with multiple RX queues. */
1369 lio_dev_mq_rx_configure(eth_dev);
1371 /* start polling for lsc */
1372 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
1373 lio_sync_link_state_check,
1376 lio_dev_err(lio_dev,
1377 "link state check handler creation failed\n");
1378 goto dev_lsc_handle_error;
1381 while ((lio_dev->linfo.link.link_status64 == 0) && (--timeout))
1384 if (lio_dev->linfo.link.link_status64 == 0) {
1386 goto dev_mtu_check_error;
1389 if (lio_dev->linfo.link.s.mtu != mtu) {
1390 ret = lio_dev_validate_vf_mtu(eth_dev, mtu);
1392 goto dev_mtu_check_error;
1397 dev_mtu_check_error:
1398 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1400 dev_lsc_handle_error:
1401 lio_dev->intf_open = 0;
1402 lio_send_rx_ctrl_cmd(eth_dev, 0);
1407 /* Stop device and disable input/output functions */
1409 lio_dev_stop(struct rte_eth_dev *eth_dev)
1411 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1413 lio_dev_info(lio_dev, "Stopping port %d\n", eth_dev->data->port_id);
1414 lio_dev->intf_open = 0;
1417 /* Cancel callback if still running. */
1418 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1420 lio_send_rx_ctrl_cmd(eth_dev, 0);
1422 /* Clear recorded link status */
1423 lio_dev->linfo.link.link_status64 = 0;
1427 lio_dev_set_link_up(struct rte_eth_dev *eth_dev)
1429 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1431 if (!lio_dev->intf_open) {
1432 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1436 if (lio_dev->linfo.link.s.link_up) {
1437 lio_dev_info(lio_dev, "Link is already UP\n");
1441 if (lio_send_rx_ctrl_cmd(eth_dev, 1)) {
1442 lio_dev_err(lio_dev, "Unable to set Link UP\n");
1446 lio_dev->linfo.link.s.link_up = 1;
1447 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1453 lio_dev_set_link_down(struct rte_eth_dev *eth_dev)
1455 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1457 if (!lio_dev->intf_open) {
1458 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1462 if (!lio_dev->linfo.link.s.link_up) {
1463 lio_dev_info(lio_dev, "Link is already DOWN\n");
1467 lio_dev->linfo.link.s.link_up = 0;
1468 eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
1470 if (lio_send_rx_ctrl_cmd(eth_dev, 0)) {
1471 lio_dev->linfo.link.s.link_up = 1;
1472 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1473 lio_dev_err(lio_dev, "Unable to set Link Down\n");
1481 * Reset and stop the device. This occurs on the first
1482 * call to this routine. Subsequent calls will simply
1483 * return. NB: This will require the NIC to be rebooted.
1486 * Pointer to the structure rte_eth_dev
1492 lio_dev_close(struct rte_eth_dev *eth_dev)
1494 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1497 lio_dev_info(lio_dev, "closing port %d\n", eth_dev->data->port_id);
1499 if (lio_dev->intf_open)
1500 lio_dev_stop(eth_dev);
1502 lio_wait_for_instr_fetch(lio_dev);
1504 lio_dev->fn_list.disable_io_queues(lio_dev);
1506 cn23xx_vf_set_io_queues_off(lio_dev);
1508 /* Reset iq regs (IQ_DBELL).
1509 * Clear sli_pktx_cnts (OQ_PKTS_SENT).
1511 for (i = 0; i < lio_dev->nb_rx_queues; i++) {
1512 struct lio_droq *droq = lio_dev->droq[i];
1517 uint32_t pkt_count = rte_read32(droq->pkts_sent_reg);
1519 lio_dev_dbg(lio_dev,
1520 "pending oq count %u\n", pkt_count);
1521 rte_write32(pkt_count, droq->pkts_sent_reg);
1524 /* Do FLR for the VF */
1525 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1528 lio_dev->fn_list.free_mbox(lio_dev);
1530 /* Free glist resources */
1531 rte_free(lio_dev->glist_head);
1532 rte_free(lio_dev->glist_lock);
1533 lio_dev->glist_head = NULL;
1534 lio_dev->glist_lock = NULL;
1536 lio_dev->port_configured = 0;
1538 /* Delete all queues */
1539 lio_dev_clear_queues(eth_dev);
1543 * Enable tunnel rx checksum verification from firmware.
1546 lio_enable_hw_tunnel_rx_checksum(struct rte_eth_dev *eth_dev)
1548 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1549 struct lio_dev_ctrl_cmd ctrl_cmd;
1550 struct lio_ctrl_pkt ctrl_pkt;
1552 /* flush added to prevent cmd failure
1553 * incase the queue is full
1555 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1557 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1558 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1560 ctrl_cmd.eth_dev = eth_dev;
1563 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_RX_CSUM_CTL;
1564 ctrl_pkt.ncmd.s.param1 = LIO_CMD_RXCSUM_ENABLE;
1565 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1567 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1568 lio_dev_err(lio_dev, "Failed to send TNL_RX_CSUM command\n");
1572 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1573 lio_dev_err(lio_dev, "TNL_RX_CSUM command timed out\n");
1577 * Enable checksum calculation for inner packet in a tunnel.
1580 lio_enable_hw_tunnel_tx_checksum(struct rte_eth_dev *eth_dev)
1582 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1583 struct lio_dev_ctrl_cmd ctrl_cmd;
1584 struct lio_ctrl_pkt ctrl_pkt;
1586 /* flush added to prevent cmd failure
1587 * incase the queue is full
1589 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1591 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1592 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1594 ctrl_cmd.eth_dev = eth_dev;
1597 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_TX_CSUM_CTL;
1598 ctrl_pkt.ncmd.s.param1 = LIO_CMD_TXCSUM_ENABLE;
1599 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1601 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1602 lio_dev_err(lio_dev, "Failed to send TNL_TX_CSUM command\n");
1606 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1607 lio_dev_err(lio_dev, "TNL_TX_CSUM command timed out\n");
1610 static int lio_dev_configure(struct rte_eth_dev *eth_dev)
1612 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1613 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1614 int retval, num_iqueues, num_oqueues;
1615 uint8_t mac[ETHER_ADDR_LEN], i;
1616 struct lio_if_cfg_resp *resp;
1617 struct lio_soft_command *sc;
1618 union lio_if_cfg if_cfg;
1621 PMD_INIT_FUNC_TRACE();
1623 /* Re-configuring firmware not supported.
1624 * Can't change tx/rx queues per port from initial value.
1626 if (lio_dev->port_configured) {
1627 if ((lio_dev->nb_rx_queues != eth_dev->data->nb_rx_queues) ||
1628 (lio_dev->nb_tx_queues != eth_dev->data->nb_tx_queues)) {
1629 lio_dev_err(lio_dev,
1630 "rxq/txq re-conf not supported. Restart application with new value.\n");
1636 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
1637 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
1639 resp_size = sizeof(struct lio_if_cfg_resp);
1640 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1644 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
1646 /* Firmware doesn't have capability to reconfigure the queues,
1647 * Claim all queues, and use as many required
1649 if_cfg.if_cfg64 = 0;
1650 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
1651 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
1652 if_cfg.s.base_queue = 0;
1654 if_cfg.s.gmx_port_id = lio_dev->pf_num;
1656 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1657 LIO_OPCODE_IF_CFG, 0,
1658 if_cfg.if_cfg64, 0);
1660 /* Setting wait time in seconds */
1661 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1663 retval = lio_send_soft_command(lio_dev, sc);
1664 if (retval == LIO_IQ_SEND_FAILED) {
1665 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
1667 /* Soft instr is freed by driver in case of failure. */
1668 goto nic_config_fail;
1671 /* Sleep on a wait queue till the cond flag indicates that the
1672 * response arrived or timed-out.
1674 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1675 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1676 lio_process_ordered_list(lio_dev);
1680 retval = resp->status;
1682 lio_dev_err(lio_dev, "iq/oq config failed\n");
1683 goto nic_config_fail;
1686 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
1687 sizeof(struct octeon_if_cfg_info) >> 3);
1689 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
1690 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
1692 if (!(num_iqueues) || !(num_oqueues)) {
1693 lio_dev_err(lio_dev,
1694 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
1695 (unsigned long)resp->cfg_info.iqmask,
1696 (unsigned long)resp->cfg_info.oqmask);
1697 goto nic_config_fail;
1700 lio_dev_dbg(lio_dev,
1701 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
1702 eth_dev->data->port_id,
1703 (unsigned long)resp->cfg_info.iqmask,
1704 (unsigned long)resp->cfg_info.oqmask,
1705 num_iqueues, num_oqueues);
1707 lio_dev->linfo.num_rxpciq = num_oqueues;
1708 lio_dev->linfo.num_txpciq = num_iqueues;
1710 for (i = 0; i < num_oqueues; i++) {
1711 lio_dev->linfo.rxpciq[i].rxpciq64 =
1712 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
1713 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
1714 i, lio_dev->linfo.rxpciq[i].s.q_no);
1717 for (i = 0; i < num_iqueues; i++) {
1718 lio_dev->linfo.txpciq[i].txpciq64 =
1719 resp->cfg_info.linfo.txpciq[i].txpciq64;
1720 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
1721 i, lio_dev->linfo.txpciq[i].s.q_no);
1724 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1725 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1726 lio_dev->linfo.link.link_status64 =
1727 resp->cfg_info.linfo.link.link_status64;
1729 /* 64-bit swap required on LE machines */
1730 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
1731 for (i = 0; i < ETHER_ADDR_LEN; i++)
1732 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
1735 /* Copy the permanent MAC address */
1736 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
1738 /* enable firmware checksum support for tunnel packets */
1739 lio_enable_hw_tunnel_rx_checksum(eth_dev);
1740 lio_enable_hw_tunnel_tx_checksum(eth_dev);
1742 lio_dev->glist_lock =
1743 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
1744 if (lio_dev->glist_lock == NULL)
1747 lio_dev->glist_head =
1748 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
1750 if (lio_dev->glist_head == NULL) {
1751 rte_free(lio_dev->glist_lock);
1752 lio_dev->glist_lock = NULL;
1756 lio_dev_link_update(eth_dev, 0);
1758 lio_dev->port_configured = 1;
1760 lio_free_soft_command(sc);
1762 /* Disable iq_0 for reconf */
1763 lio_dev->fn_list.disable_io_queues(lio_dev);
1765 /* Reset ioq regs */
1766 lio_dev->fn_list.setup_device_regs(lio_dev);
1768 /* Free iq_0 used during init */
1769 lio_free_instr_queue0(lio_dev);
1774 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
1775 lio_free_soft_command(sc);
1776 lio_free_instr_queue0(lio_dev);
1781 /* Define our ethernet definitions */
1782 static const struct eth_dev_ops liovf_eth_dev_ops = {
1783 .dev_configure = lio_dev_configure,
1784 .dev_start = lio_dev_start,
1785 .dev_stop = lio_dev_stop,
1786 .dev_set_link_up = lio_dev_set_link_up,
1787 .dev_set_link_down = lio_dev_set_link_down,
1788 .dev_close = lio_dev_close,
1789 .allmulticast_enable = lio_dev_allmulticast_enable,
1790 .allmulticast_disable = lio_dev_allmulticast_disable,
1791 .link_update = lio_dev_link_update,
1792 .stats_get = lio_dev_stats_get,
1793 .xstats_get = lio_dev_xstats_get,
1794 .xstats_get_names = lio_dev_xstats_get_names,
1795 .stats_reset = lio_dev_stats_reset,
1796 .xstats_reset = lio_dev_xstats_reset,
1797 .dev_infos_get = lio_dev_info_get,
1798 .vlan_filter_set = lio_dev_vlan_filter_set,
1799 .rx_queue_setup = lio_dev_rx_queue_setup,
1800 .rx_queue_release = lio_dev_rx_queue_release,
1801 .tx_queue_setup = lio_dev_tx_queue_setup,
1802 .tx_queue_release = lio_dev_tx_queue_release,
1803 .reta_update = lio_dev_rss_reta_update,
1804 .reta_query = lio_dev_rss_reta_query,
1805 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
1806 .rss_hash_update = lio_dev_rss_hash_update,
1807 .udp_tunnel_port_add = lio_dev_udp_tunnel_add,
1808 .udp_tunnel_port_del = lio_dev_udp_tunnel_del,
1812 lio_check_pf_hs_response(void *lio_dev)
1814 struct lio_device *dev = lio_dev;
1816 /* check till response arrives */
1817 if (dev->pfvf_hsword.coproc_tics_per_us)
1820 cn23xx_vf_handle_mbox(dev);
1822 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1826 * \brief Identify the LIO device and to map the BAR address space
1827 * @param lio_dev lio device
1830 lio_chip_specific_setup(struct lio_device *lio_dev)
1832 struct rte_pci_device *pdev = lio_dev->pci_dev;
1833 uint32_t dev_id = pdev->id.device_id;
1838 case LIO_CN23XX_VF_VID:
1839 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1840 ret = cn23xx_vf_setup_device(lio_dev);
1845 lio_dev_err(lio_dev, "Unsupported Chip\n");
1849 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1855 lio_first_time_init(struct lio_device *lio_dev,
1856 struct rte_pci_device *pdev)
1860 PMD_INIT_FUNC_TRACE();
1862 /* set dpdk specific pci device pointer */
1863 lio_dev->pci_dev = pdev;
1865 /* Identify the LIO type and set device ops */
1866 if (lio_chip_specific_setup(lio_dev)) {
1867 lio_dev_err(lio_dev, "Chip specific setup failed\n");
1871 /* Initialize soft command buffer pool */
1872 if (lio_setup_sc_buffer_pool(lio_dev)) {
1873 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
1877 /* Initialize lists to manage the requests of different types that
1878 * arrive from applications for this lio device.
1880 lio_setup_response_list(lio_dev);
1882 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
1883 lio_dev_err(lio_dev, "Mailbox setup failed\n");
1887 /* Check PF response */
1888 lio_check_pf_hs_response((void *)lio_dev);
1890 /* Do handshake and exit if incompatible PF driver */
1891 if (cn23xx_pfvf_handshake(lio_dev))
1895 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1896 /* Wait for FLR for 100ms per SRIOV specification */
1899 if (cn23xx_vf_set_io_queues_off(lio_dev)) {
1900 lio_dev_err(lio_dev, "Setting io queues off failed\n");
1904 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1905 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1909 if (lio_setup_instr_queue0(lio_dev)) {
1910 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
1914 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
1916 lio_dev->max_tx_queues = dpdk_queues;
1917 lio_dev->max_rx_queues = dpdk_queues;
1919 /* Enable input and output queues for this device */
1920 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1926 lio_free_sc_buffer_pool(lio_dev);
1927 if (lio_dev->mbox[0])
1928 lio_dev->fn_list.free_mbox(lio_dev);
1929 if (lio_dev->instr_queue[0])
1930 lio_free_instr_queue0(lio_dev);
1936 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1938 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1940 PMD_INIT_FUNC_TRACE();
1942 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1945 /* lio_free_sc_buffer_pool */
1946 lio_free_sc_buffer_pool(lio_dev);
1948 rte_free(eth_dev->data->mac_addrs);
1949 eth_dev->data->mac_addrs = NULL;
1951 eth_dev->dev_ops = NULL;
1952 eth_dev->rx_pkt_burst = NULL;
1953 eth_dev->tx_pkt_burst = NULL;
1959 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
1961 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
1962 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1964 PMD_INIT_FUNC_TRACE();
1966 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
1967 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
1969 /* Primary does the initialization. */
1970 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1973 rte_eth_copy_pci_info(eth_dev, pdev);
1974 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1976 if (pdev->mem_resource[0].addr) {
1977 lio_dev->hw_addr = pdev->mem_resource[0].addr;
1979 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
1983 lio_dev->eth_dev = eth_dev;
1984 /* set lio device print string */
1985 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
1986 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
1987 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1989 lio_dev->port_id = eth_dev->data->port_id;
1991 if (lio_first_time_init(lio_dev, pdev)) {
1992 lio_dev_err(lio_dev, "Device init failed\n");
1996 eth_dev->dev_ops = &liovf_eth_dev_ops;
1997 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
1998 if (eth_dev->data->mac_addrs == NULL) {
1999 lio_dev_err(lio_dev,
2000 "MAC addresses memory allocation failed\n");
2001 eth_dev->dev_ops = NULL;
2002 eth_dev->rx_pkt_burst = NULL;
2003 eth_dev->tx_pkt_burst = NULL;
2007 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
2010 lio_dev->port_configured = 0;
2011 /* Always allow unicast packets */
2012 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
2018 lio_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2019 struct rte_pci_device *pci_dev)
2021 struct rte_eth_dev *eth_dev;
2024 eth_dev = rte_eth_dev_pci_allocate(pci_dev,
2025 sizeof(struct lio_device));
2026 if (eth_dev == NULL)
2029 ret = lio_eth_dev_init(eth_dev);
2031 rte_eth_dev_pci_release(eth_dev);
2037 lio_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
2039 return rte_eth_dev_pci_generic_remove(pci_dev,
2040 lio_eth_dev_uninit);
2043 /* Set of PCI devices this driver supports */
2044 static const struct rte_pci_id pci_id_liovf_map[] = {
2045 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
2046 { .vendor_id = 0, /* sentinel */ }
2049 static struct rte_pci_driver rte_liovf_pmd = {
2050 .id_table = pci_id_liovf_map,
2051 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
2052 .probe = lio_eth_dev_pci_probe,
2053 .remove = lio_eth_dev_pci_remove,
2056 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd);
2057 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
2058 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");