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_cycles.h>
36 #include <rte_malloc.h>
37 #include <rte_alarm.h>
40 #include "lio_23xx_vf.h"
41 #include "lio_ethdev.h"
44 /* Default RSS key in use */
45 static uint8_t lio_rss_key[40] = {
46 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
47 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
48 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
49 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
50 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
53 static const struct rte_eth_desc_lim lio_rx_desc_lim = {
54 .nb_max = CN23XX_MAX_OQ_DESCRIPTORS,
55 .nb_min = CN23XX_MIN_OQ_DESCRIPTORS,
59 static const struct rte_eth_desc_lim lio_tx_desc_lim = {
60 .nb_max = CN23XX_MAX_IQ_DESCRIPTORS,
61 .nb_min = CN23XX_MIN_IQ_DESCRIPTORS,
65 /* Wait for control command to reach nic. */
67 lio_wait_for_ctrl_cmd(struct lio_device *lio_dev,
68 struct lio_dev_ctrl_cmd *ctrl_cmd)
70 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
72 while ((ctrl_cmd->cond == 0) && --timeout) {
73 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
81 * \brief Send Rx control command
82 * @param eth_dev Pointer to the structure rte_eth_dev
83 * @param start_stop whether to start or stop
86 lio_send_rx_ctrl_cmd(struct rte_eth_dev *eth_dev, int start_stop)
88 struct lio_device *lio_dev = LIO_DEV(eth_dev);
89 struct lio_dev_ctrl_cmd ctrl_cmd;
90 struct lio_ctrl_pkt ctrl_pkt;
92 /* flush added to prevent cmd failure
93 * incase the queue is full
95 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
97 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
98 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
100 ctrl_cmd.eth_dev = eth_dev;
103 ctrl_pkt.ncmd.s.cmd = LIO_CMD_RX_CTL;
104 ctrl_pkt.ncmd.s.param1 = start_stop;
105 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
107 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
108 lio_dev_err(lio_dev, "Failed to send RX Control message\n");
112 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
113 lio_dev_err(lio_dev, "RX Control command timed out\n");
120 /* store statistics names and its offset in stats structure */
121 struct rte_lio_xstats_name_off {
122 char name[RTE_ETH_XSTATS_NAME_SIZE];
126 static const struct rte_lio_xstats_name_off rte_lio_stats_strings[] = {
127 {"rx_pkts", offsetof(struct octeon_rx_stats, total_rcvd)},
128 {"rx_bytes", offsetof(struct octeon_rx_stats, bytes_rcvd)},
129 {"rx_broadcast_pkts", offsetof(struct octeon_rx_stats, total_bcst)},
130 {"rx_multicast_pkts", offsetof(struct octeon_rx_stats, total_mcst)},
131 {"rx_flow_ctrl_pkts", offsetof(struct octeon_rx_stats, ctl_rcvd)},
132 {"rx_fifo_err", offsetof(struct octeon_rx_stats, fifo_err)},
133 {"rx_dmac_drop", offsetof(struct octeon_rx_stats, dmac_drop)},
134 {"rx_fcs_err", offsetof(struct octeon_rx_stats, fcs_err)},
135 {"rx_jabber_err", offsetof(struct octeon_rx_stats, jabber_err)},
136 {"rx_l2_err", offsetof(struct octeon_rx_stats, l2_err)},
137 {"rx_vxlan_pkts", offsetof(struct octeon_rx_stats, fw_rx_vxlan)},
138 {"rx_vxlan_err", offsetof(struct octeon_rx_stats, fw_rx_vxlan_err)},
139 {"rx_lro_pkts", offsetof(struct octeon_rx_stats, fw_lro_pkts)},
140 {"tx_pkts", (offsetof(struct octeon_tx_stats, total_pkts_sent)) +
141 sizeof(struct octeon_rx_stats)},
142 {"tx_bytes", (offsetof(struct octeon_tx_stats, total_bytes_sent)) +
143 sizeof(struct octeon_rx_stats)},
144 {"tx_broadcast_pkts",
145 (offsetof(struct octeon_tx_stats, bcast_pkts_sent)) +
146 sizeof(struct octeon_rx_stats)},
147 {"tx_multicast_pkts",
148 (offsetof(struct octeon_tx_stats, mcast_pkts_sent)) +
149 sizeof(struct octeon_rx_stats)},
150 {"tx_flow_ctrl_pkts", (offsetof(struct octeon_tx_stats, ctl_sent)) +
151 sizeof(struct octeon_rx_stats)},
152 {"tx_fifo_err", (offsetof(struct octeon_tx_stats, fifo_err)) +
153 sizeof(struct octeon_rx_stats)},
154 {"tx_total_collisions", (offsetof(struct octeon_tx_stats,
156 sizeof(struct octeon_rx_stats)},
157 {"tx_tso", (offsetof(struct octeon_tx_stats, fw_tso)) +
158 sizeof(struct octeon_rx_stats)},
159 {"tx_vxlan_pkts", (offsetof(struct octeon_tx_stats, fw_tx_vxlan)) +
160 sizeof(struct octeon_rx_stats)},
163 #define LIO_NB_XSTATS RTE_DIM(rte_lio_stats_strings)
165 /* Get hw stats of the port */
167 lio_dev_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *xstats,
170 struct lio_device *lio_dev = LIO_DEV(eth_dev);
171 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
172 struct octeon_link_stats *hw_stats;
173 struct lio_link_stats_resp *resp;
174 struct lio_soft_command *sc;
179 if (!lio_dev->intf_open) {
180 lio_dev_err(lio_dev, "Port %d down\n",
185 if (n < LIO_NB_XSTATS)
186 return LIO_NB_XSTATS;
188 resp_size = sizeof(struct lio_link_stats_resp);
189 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
193 resp = (struct lio_link_stats_resp *)sc->virtrptr;
194 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
195 LIO_OPCODE_PORT_STATS, 0, 0, 0);
197 /* Setting wait time in seconds */
198 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
200 retval = lio_send_soft_command(lio_dev, sc);
201 if (retval == LIO_IQ_SEND_FAILED) {
202 lio_dev_err(lio_dev, "failed to get port stats from firmware. status: %x\n",
207 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
208 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
209 lio_process_ordered_list(lio_dev);
213 retval = resp->status;
215 lio_dev_err(lio_dev, "failed to get port stats from firmware\n");
219 lio_swap_8B_data((uint64_t *)(&resp->link_stats),
220 sizeof(struct octeon_link_stats) >> 3);
222 hw_stats = &resp->link_stats;
224 for (i = 0; i < LIO_NB_XSTATS; i++) {
227 *(uint64_t *)(((char *)hw_stats) +
228 rte_lio_stats_strings[i].offset);
231 lio_free_soft_command(sc);
233 return LIO_NB_XSTATS;
236 lio_free_soft_command(sc);
242 lio_dev_xstats_get_names(struct rte_eth_dev *eth_dev,
243 struct rte_eth_xstat_name *xstats_names,
244 unsigned limit __rte_unused)
246 struct lio_device *lio_dev = LIO_DEV(eth_dev);
249 if (!lio_dev->intf_open) {
250 lio_dev_err(lio_dev, "Port %d down\n",
255 if (xstats_names == NULL)
256 return LIO_NB_XSTATS;
258 /* Note: limit checked in rte_eth_xstats_names() */
260 for (i = 0; i < LIO_NB_XSTATS; i++) {
261 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
262 "%s", rte_lio_stats_strings[i].name);
265 return LIO_NB_XSTATS;
268 /* Reset hw stats for the port */
270 lio_dev_xstats_reset(struct rte_eth_dev *eth_dev)
272 struct lio_device *lio_dev = LIO_DEV(eth_dev);
273 struct lio_dev_ctrl_cmd ctrl_cmd;
274 struct lio_ctrl_pkt ctrl_pkt;
276 if (!lio_dev->intf_open) {
277 lio_dev_err(lio_dev, "Port %d down\n",
282 /* flush added to prevent cmd failure
283 * incase the queue is full
285 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
287 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
288 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
290 ctrl_cmd.eth_dev = eth_dev;
293 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CLEAR_STATS;
294 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
296 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
297 lio_dev_err(lio_dev, "Failed to send clear stats command\n");
301 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
302 lio_dev_err(lio_dev, "Clear stats command timed out\n");
306 /* clear stored per queue stats */
307 RTE_FUNC_PTR_OR_RET(*eth_dev->dev_ops->stats_reset);
308 (*eth_dev->dev_ops->stats_reset)(eth_dev);
311 /* Retrieve the device statistics (# packets in/out, # bytes in/out, etc */
313 lio_dev_stats_get(struct rte_eth_dev *eth_dev,
314 struct rte_eth_stats *stats)
316 struct lio_device *lio_dev = LIO_DEV(eth_dev);
317 struct lio_droq_stats *oq_stats;
318 struct lio_iq_stats *iq_stats;
319 struct lio_instr_queue *txq;
320 struct lio_droq *droq;
326 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
327 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
328 txq = lio_dev->instr_queue[iq_no];
330 iq_stats = &txq->stats;
331 pkts += iq_stats->tx_done;
332 drop += iq_stats->tx_dropped;
333 bytes += iq_stats->tx_tot_bytes;
337 stats->opackets = pkts;
338 stats->obytes = bytes;
339 stats->oerrors = drop;
345 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
346 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
347 droq = lio_dev->droq[oq_no];
349 oq_stats = &droq->stats;
350 pkts += oq_stats->rx_pkts_received;
351 drop += (oq_stats->rx_dropped +
352 oq_stats->dropped_toomany +
353 oq_stats->dropped_nomem);
354 bytes += oq_stats->rx_bytes_received;
357 stats->ibytes = bytes;
358 stats->ipackets = pkts;
359 stats->ierrors = drop;
363 lio_dev_stats_reset(struct rte_eth_dev *eth_dev)
365 struct lio_device *lio_dev = LIO_DEV(eth_dev);
366 struct lio_droq_stats *oq_stats;
367 struct lio_iq_stats *iq_stats;
368 struct lio_instr_queue *txq;
369 struct lio_droq *droq;
372 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
373 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
374 txq = lio_dev->instr_queue[iq_no];
376 iq_stats = &txq->stats;
377 memset(iq_stats, 0, sizeof(struct lio_iq_stats));
381 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
382 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
383 droq = lio_dev->droq[oq_no];
385 oq_stats = &droq->stats;
386 memset(oq_stats, 0, sizeof(struct lio_droq_stats));
392 lio_dev_info_get(struct rte_eth_dev *eth_dev,
393 struct rte_eth_dev_info *devinfo)
395 struct lio_device *lio_dev = LIO_DEV(eth_dev);
397 devinfo->max_rx_queues = lio_dev->max_rx_queues;
398 devinfo->max_tx_queues = lio_dev->max_tx_queues;
400 devinfo->min_rx_bufsize = LIO_MIN_RX_BUF_SIZE;
401 devinfo->max_rx_pktlen = LIO_MAX_RX_PKTLEN;
403 devinfo->max_mac_addrs = 1;
405 devinfo->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
406 DEV_RX_OFFLOAD_UDP_CKSUM |
407 DEV_RX_OFFLOAD_TCP_CKSUM);
408 devinfo->tx_offload_capa = (DEV_TX_OFFLOAD_IPV4_CKSUM |
409 DEV_TX_OFFLOAD_UDP_CKSUM |
410 DEV_TX_OFFLOAD_TCP_CKSUM |
411 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM);
413 devinfo->rx_desc_lim = lio_rx_desc_lim;
414 devinfo->tx_desc_lim = lio_tx_desc_lim;
416 devinfo->reta_size = LIO_RSS_MAX_TABLE_SZ;
417 devinfo->hash_key_size = LIO_RSS_MAX_KEY_SZ;
418 devinfo->flow_type_rss_offloads = (ETH_RSS_IPV4 |
419 ETH_RSS_NONFRAG_IPV4_TCP |
421 ETH_RSS_NONFRAG_IPV6_TCP |
423 ETH_RSS_IPV6_TCP_EX);
427 lio_dev_validate_vf_mtu(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
429 struct lio_device *lio_dev = LIO_DEV(eth_dev);
431 PMD_INIT_FUNC_TRACE();
433 if (!lio_dev->intf_open) {
434 lio_dev_err(lio_dev, "Port %d down, can't check MTU\n",
439 /* Limit the MTU to make sure the ethernet packets are between
440 * ETHER_MIN_MTU bytes and PF's MTU
442 if ((new_mtu < ETHER_MIN_MTU) ||
443 (new_mtu > lio_dev->linfo.link.s.mtu)) {
444 lio_dev_err(lio_dev, "Invalid MTU: %d\n", new_mtu);
445 lio_dev_err(lio_dev, "Valid range %d and %d\n",
446 ETHER_MIN_MTU, lio_dev->linfo.link.s.mtu);
454 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
455 struct rte_eth_rss_reta_entry64 *reta_conf,
458 struct lio_device *lio_dev = LIO_DEV(eth_dev);
459 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
460 struct lio_rss_set *rss_param;
461 struct lio_dev_ctrl_cmd ctrl_cmd;
462 struct lio_ctrl_pkt ctrl_pkt;
465 if (!lio_dev->intf_open) {
466 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
471 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
473 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
474 reta_size, LIO_RSS_MAX_TABLE_SZ);
478 /* flush added to prevent cmd failure
479 * incase the queue is full
481 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
483 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
484 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
486 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
488 ctrl_cmd.eth_dev = eth_dev;
491 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
492 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
493 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
495 rss_param->param.flags = 0xF;
496 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
497 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
499 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
500 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
501 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
502 index = (i * RTE_RETA_GROUP_SIZE) + j;
503 rss_state->itable[index] = reta_conf[i].reta[j];
508 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
509 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
511 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
513 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
514 lio_dev_err(lio_dev, "Failed to set rss hash\n");
518 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
519 lio_dev_err(lio_dev, "Set rss hash timed out\n");
527 lio_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
528 struct rte_eth_rss_reta_entry64 *reta_conf,
531 struct lio_device *lio_dev = LIO_DEV(eth_dev);
532 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
535 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
537 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
538 reta_size, LIO_RSS_MAX_TABLE_SZ);
542 num = reta_size / RTE_RETA_GROUP_SIZE;
544 for (i = 0; i < num; i++) {
545 memcpy(reta_conf->reta,
546 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
547 RTE_RETA_GROUP_SIZE);
555 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
556 struct rte_eth_rss_conf *rss_conf)
558 struct lio_device *lio_dev = LIO_DEV(eth_dev);
559 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
560 uint8_t *hash_key = NULL;
563 if (rss_state->hash_disable) {
564 lio_dev_info(lio_dev, "RSS disabled in nic\n");
565 rss_conf->rss_hf = 0;
570 hash_key = rss_conf->rss_key;
571 if (hash_key != NULL)
572 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
575 rss_hf |= ETH_RSS_IPV4;
576 if (rss_state->tcp_hash)
577 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
579 rss_hf |= ETH_RSS_IPV6;
580 if (rss_state->ipv6_tcp_hash)
581 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
582 if (rss_state->ipv6_ex)
583 rss_hf |= ETH_RSS_IPV6_EX;
584 if (rss_state->ipv6_tcp_ex_hash)
585 rss_hf |= ETH_RSS_IPV6_TCP_EX;
587 rss_conf->rss_hf = rss_hf;
593 lio_dev_rss_hash_update(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 struct lio_rss_set *rss_param;
599 struct lio_dev_ctrl_cmd ctrl_cmd;
600 struct lio_ctrl_pkt ctrl_pkt;
602 if (!lio_dev->intf_open) {
603 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
608 /* flush added to prevent cmd failure
609 * incase the queue is full
611 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
613 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
614 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
616 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
618 ctrl_cmd.eth_dev = eth_dev;
621 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
622 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
623 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
625 rss_param->param.flags = 0xF;
627 if (rss_conf->rss_key) {
628 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
629 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
630 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
631 memcpy(rss_state->hash_key, rss_conf->rss_key,
632 rss_state->hash_key_size);
633 memcpy(rss_param->key, rss_state->hash_key,
634 rss_state->hash_key_size);
637 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
638 /* Can't disable rss through hash flags,
639 * if it is enabled by default during init
641 if (!rss_state->hash_disable)
644 /* This is for --disable-rss during testpmd launch */
645 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
647 uint32_t hashinfo = 0;
649 /* Can't enable rss if disabled by default during init */
650 if (rss_state->hash_disable)
653 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
654 hashinfo |= LIO_RSS_HASH_IPV4;
660 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
661 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
662 rss_state->tcp_hash = 1;
664 rss_state->tcp_hash = 0;
667 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
668 hashinfo |= LIO_RSS_HASH_IPV6;
674 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
675 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
676 rss_state->ipv6_tcp_hash = 1;
678 rss_state->ipv6_tcp_hash = 0;
681 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
682 hashinfo |= LIO_RSS_HASH_IPV6_EX;
683 rss_state->ipv6_ex = 1;
685 rss_state->ipv6_ex = 0;
688 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
689 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
690 rss_state->ipv6_tcp_ex_hash = 1;
692 rss_state->ipv6_tcp_ex_hash = 0;
695 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
696 rss_param->param.hashinfo = hashinfo;
699 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
701 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
702 lio_dev_err(lio_dev, "Failed to set rss hash\n");
706 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
707 lio_dev_err(lio_dev, "Set rss hash timed out\n");
715 * Add vxlan dest udp port for an interface.
718 * Pointer to the structure rte_eth_dev
723 * On success return 0
724 * On failure return -1
727 lio_dev_udp_tunnel_add(struct rte_eth_dev *eth_dev,
728 struct rte_eth_udp_tunnel *udp_tnl)
730 struct lio_device *lio_dev = LIO_DEV(eth_dev);
731 struct lio_dev_ctrl_cmd ctrl_cmd;
732 struct lio_ctrl_pkt ctrl_pkt;
737 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
738 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
742 /* flush added to prevent cmd failure
743 * incase the queue is full
745 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
747 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
748 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
750 ctrl_cmd.eth_dev = eth_dev;
753 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
754 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
755 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_ADD;
756 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
758 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
759 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_ADD command\n");
763 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
764 lio_dev_err(lio_dev, "VXLAN_PORT_ADD command timed out\n");
772 * Remove vxlan dest udp port for an interface.
775 * Pointer to the structure rte_eth_dev
780 * On success return 0
781 * On failure return -1
784 lio_dev_udp_tunnel_del(struct rte_eth_dev *eth_dev,
785 struct rte_eth_udp_tunnel *udp_tnl)
787 struct lio_device *lio_dev = LIO_DEV(eth_dev);
788 struct lio_dev_ctrl_cmd ctrl_cmd;
789 struct lio_ctrl_pkt ctrl_pkt;
794 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
795 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
799 /* flush added to prevent cmd failure
800 * incase the queue is full
802 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
804 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
805 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
807 ctrl_cmd.eth_dev = eth_dev;
810 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
811 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
812 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_DEL;
813 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
815 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
816 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_DEL command\n");
820 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
821 lio_dev_err(lio_dev, "VXLAN_PORT_DEL command timed out\n");
829 * Atomically writes the link status information into global
830 * structure rte_eth_dev.
833 * - Pointer to the structure rte_eth_dev to read from.
834 * - Pointer to the buffer to be saved with the link status.
837 * - On success, zero.
838 * - On failure, negative value.
841 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
842 struct rte_eth_link *link)
844 struct rte_eth_link *dst = ð_dev->data->dev_link;
845 struct rte_eth_link *src = link;
847 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
848 *(uint64_t *)src) == 0)
855 lio_hweight64(uint64_t w)
857 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
860 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
861 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
862 res = res + (res >> 8);
863 res = res + (res >> 16);
865 return (res + (res >> 32)) & 0x00000000000000FFul;
869 lio_dev_link_update(struct rte_eth_dev *eth_dev,
870 int wait_to_complete __rte_unused)
872 struct lio_device *lio_dev = LIO_DEV(eth_dev);
873 struct rte_eth_link link, old;
876 link.link_status = ETH_LINK_DOWN;
877 link.link_speed = ETH_SPEED_NUM_NONE;
878 link.link_duplex = ETH_LINK_HALF_DUPLEX;
879 memset(&old, 0, sizeof(old));
881 /* Return what we found */
882 if (lio_dev->linfo.link.s.link_up == 0) {
883 /* Interface is down */
884 if (lio_dev_atomic_write_link_status(eth_dev, &link))
886 if (link.link_status == old.link_status)
891 link.link_status = ETH_LINK_UP; /* Interface is up */
892 link.link_duplex = ETH_LINK_FULL_DUPLEX;
893 switch (lio_dev->linfo.link.s.speed) {
894 case LIO_LINK_SPEED_10000:
895 link.link_speed = ETH_SPEED_NUM_10G;
898 link.link_speed = ETH_SPEED_NUM_NONE;
899 link.link_duplex = ETH_LINK_HALF_DUPLEX;
902 if (lio_dev_atomic_write_link_status(eth_dev, &link))
905 if (link.link_status == old.link_status)
912 * \brief Net device enable, disable allmulticast
913 * @param eth_dev Pointer to the structure rte_eth_dev
916 lio_change_dev_flag(struct rte_eth_dev *eth_dev)
918 struct lio_device *lio_dev = LIO_DEV(eth_dev);
919 struct lio_dev_ctrl_cmd ctrl_cmd;
920 struct lio_ctrl_pkt ctrl_pkt;
922 /* flush added to prevent cmd failure
923 * incase the queue is full
925 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
927 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
928 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
930 ctrl_cmd.eth_dev = eth_dev;
933 /* Create a ctrl pkt command to be sent to core app. */
934 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CHANGE_DEVFLAGS;
935 ctrl_pkt.ncmd.s.param1 = lio_dev->ifflags;
936 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
938 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
939 lio_dev_err(lio_dev, "Failed to send change flag message\n");
943 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
944 lio_dev_err(lio_dev, "Change dev flag command timed out\n");
948 lio_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
950 struct lio_device *lio_dev = LIO_DEV(eth_dev);
952 if (!lio_dev->intf_open) {
953 lio_dev_err(lio_dev, "Port %d down, can't enable multicast\n",
958 lio_dev->ifflags |= LIO_IFFLAG_ALLMULTI;
959 lio_change_dev_flag(eth_dev);
963 lio_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
965 struct lio_device *lio_dev = LIO_DEV(eth_dev);
967 if (!lio_dev->intf_open) {
968 lio_dev_err(lio_dev, "Port %d down, can't disable multicast\n",
973 lio_dev->ifflags &= ~LIO_IFFLAG_ALLMULTI;
974 lio_change_dev_flag(eth_dev);
978 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
980 struct lio_device *lio_dev = LIO_DEV(eth_dev);
981 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
982 struct rte_eth_rss_reta_entry64 reta_conf[8];
983 struct rte_eth_rss_conf rss_conf;
986 /* Configure the RSS key and the RSS protocols used to compute
987 * the RSS hash of input packets.
989 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
990 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
991 rss_state->hash_disable = 1;
992 lio_dev_rss_hash_update(eth_dev, &rss_conf);
996 if (rss_conf.rss_key == NULL)
997 rss_conf.rss_key = lio_rss_key; /* Default hash key */
999 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1001 memset(reta_conf, 0, sizeof(reta_conf));
1002 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
1003 uint8_t q_idx, conf_idx, reta_idx;
1005 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
1006 i % eth_dev->data->nb_rx_queues : 0);
1007 conf_idx = i / RTE_RETA_GROUP_SIZE;
1008 reta_idx = i % RTE_RETA_GROUP_SIZE;
1009 reta_conf[conf_idx].reta[reta_idx] = q_idx;
1010 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
1013 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
1017 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
1019 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1020 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1021 struct rte_eth_rss_conf rss_conf;
1023 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
1025 lio_dev_rss_configure(eth_dev);
1027 case ETH_MQ_RX_NONE:
1028 /* if mq_mode is none, disable rss mode. */
1030 memset(&rss_conf, 0, sizeof(rss_conf));
1031 rss_state->hash_disable = 1;
1032 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1037 * Setup our receive queue/ringbuffer. This is the
1038 * queue the Octeon uses to send us packets and
1039 * responses. We are given a memory pool for our
1040 * packet buffers that are used to populate the receive
1044 * Pointer to the structure rte_eth_dev
1047 * @param num_rx_descs
1048 * Number of entries in the queue
1050 * Where to allocate memory
1052 * Pointer to the struction rte_eth_rxconf
1054 * Pointer to the packet pool
1057 * - On success, return 0
1058 * - On failure, return -1
1061 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1062 uint16_t num_rx_descs, unsigned int socket_id,
1063 const struct rte_eth_rxconf *rx_conf __rte_unused,
1064 struct rte_mempool *mp)
1066 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1067 struct rte_pktmbuf_pool_private *mbp_priv;
1068 uint32_t fw_mapped_oq;
1071 if (q_no >= lio_dev->nb_rx_queues) {
1072 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
1076 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
1078 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
1080 if ((lio_dev->droq[fw_mapped_oq]) &&
1081 (num_rx_descs != lio_dev->droq[fw_mapped_oq]->max_count)) {
1082 lio_dev_err(lio_dev,
1083 "Reconfiguring Rx descs not supported. Configure descs to same value %u or restart application\n",
1084 lio_dev->droq[fw_mapped_oq]->max_count);
1088 mbp_priv = rte_mempool_get_priv(mp);
1089 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
1091 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
1093 lio_dev_err(lio_dev, "droq allocation failed\n");
1097 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
1103 * Release the receive queue/ringbuffer. Called by
1107 * Opaque pointer to the receive queue to release
1113 lio_dev_rx_queue_release(void *rxq)
1115 struct lio_droq *droq = rxq;
1116 struct lio_device *lio_dev = droq->lio_dev;
1119 /* Run time queue deletion not supported */
1120 if (lio_dev->port_configured)
1125 lio_delete_droq_queue(droq->lio_dev, oq_no);
1130 * Allocate and initialize SW ring. Initialize associated HW registers.
1133 * Pointer to structure rte_eth_dev
1138 * @param num_tx_descs
1139 * Number of ringbuffer descriptors
1142 * NUMA socket id, used for memory allocations
1145 * Pointer to the structure rte_eth_txconf
1148 * - On success, return 0
1149 * - On failure, return -errno value
1152 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1153 uint16_t num_tx_descs, unsigned int socket_id,
1154 const struct rte_eth_txconf *tx_conf __rte_unused)
1156 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1157 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
1160 if (q_no >= lio_dev->nb_tx_queues) {
1161 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
1165 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
1167 if ((lio_dev->instr_queue[fw_mapped_iq] != NULL) &&
1168 (num_tx_descs != lio_dev->instr_queue[fw_mapped_iq]->max_count)) {
1169 lio_dev_err(lio_dev,
1170 "Reconfiguring Tx descs not supported. Configure descs to same value %u or restart application\n",
1171 lio_dev->instr_queue[fw_mapped_iq]->max_count);
1175 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
1176 num_tx_descs, lio_dev, socket_id);
1179 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
1183 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
1184 lio_dev->instr_queue[fw_mapped_iq]->max_count,
1188 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
1192 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
1198 * Release the transmit queue/ringbuffer. Called by
1202 * Opaque pointer to the transmit queue to release
1208 lio_dev_tx_queue_release(void *txq)
1210 struct lio_instr_queue *tq = txq;
1211 struct lio_device *lio_dev = tq->lio_dev;
1212 uint32_t fw_mapped_iq_no;
1214 /* Run time queue deletion not supported */
1215 if (lio_dev->port_configured)
1220 lio_delete_sglist(tq);
1222 fw_mapped_iq_no = tq->txpciq.s.q_no;
1223 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
1228 * Api to check link state.
1231 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
1233 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1234 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1235 struct lio_link_status_resp *resp;
1236 union octeon_link_status *ls;
1237 struct lio_soft_command *sc;
1240 if (!lio_dev->intf_open)
1243 resp_size = sizeof(struct lio_link_status_resp);
1244 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1248 resp = (struct lio_link_status_resp *)sc->virtrptr;
1249 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1250 LIO_OPCODE_INFO, 0, 0, 0);
1252 /* Setting wait time in seconds */
1253 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1255 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
1256 goto get_status_fail;
1258 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1259 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1264 goto get_status_fail;
1266 ls = &resp->link_info.link;
1268 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
1270 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
1271 lio_dev->linfo.link.link_status64 = ls->link_status64;
1272 lio_dev_link_update(eth_dev, 0);
1275 lio_free_soft_command(sc);
1280 lio_free_soft_command(sc);
1283 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
1284 * and will update link state if it changes.
1287 lio_sync_link_state_check(void *eth_dev)
1289 struct lio_device *lio_dev =
1290 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
1292 if (lio_dev->port_configured)
1293 lio_dev_get_link_status(eth_dev);
1295 /* Schedule periodic link status check.
1296 * Stop check if interface is close and start again while opening.
1298 if (lio_dev->intf_open)
1299 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
1304 lio_dev_start(struct rte_eth_dev *eth_dev)
1306 uint16_t mtu = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
1307 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1308 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1311 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
1313 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1316 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
1319 /* Ready for link status updates */
1320 lio_dev->intf_open = 1;
1323 /* Configure RSS if device configured with multiple RX queues. */
1324 lio_dev_mq_rx_configure(eth_dev);
1326 /* start polling for lsc */
1327 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
1328 lio_sync_link_state_check,
1331 lio_dev_err(lio_dev,
1332 "link state check handler creation failed\n");
1333 goto dev_lsc_handle_error;
1336 while ((lio_dev->linfo.link.link_status64 == 0) && (--timeout))
1339 if (lio_dev->linfo.link.link_status64 == 0) {
1341 goto dev_mtu_check_error;
1344 if (lio_dev->linfo.link.s.mtu != mtu) {
1345 ret = lio_dev_validate_vf_mtu(eth_dev, mtu);
1347 goto dev_mtu_check_error;
1352 dev_mtu_check_error:
1353 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1355 dev_lsc_handle_error:
1356 lio_dev->intf_open = 0;
1357 lio_send_rx_ctrl_cmd(eth_dev, 0);
1363 lio_dev_set_link_up(struct rte_eth_dev *eth_dev)
1365 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1367 if (!lio_dev->intf_open) {
1368 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1372 if (lio_dev->linfo.link.s.link_up) {
1373 lio_dev_info(lio_dev, "Link is already UP\n");
1377 if (lio_send_rx_ctrl_cmd(eth_dev, 1)) {
1378 lio_dev_err(lio_dev, "Unable to set Link UP\n");
1382 lio_dev->linfo.link.s.link_up = 1;
1383 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1389 lio_dev_set_link_down(struct rte_eth_dev *eth_dev)
1391 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1393 if (!lio_dev->intf_open) {
1394 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1398 if (!lio_dev->linfo.link.s.link_up) {
1399 lio_dev_info(lio_dev, "Link is already DOWN\n");
1403 lio_dev->linfo.link.s.link_up = 0;
1404 eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
1406 if (lio_send_rx_ctrl_cmd(eth_dev, 0)) {
1407 lio_dev->linfo.link.s.link_up = 1;
1408 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1409 lio_dev_err(lio_dev, "Unable to set Link Down\n");
1417 * Enable tunnel rx checksum verification from firmware.
1420 lio_enable_hw_tunnel_rx_checksum(struct rte_eth_dev *eth_dev)
1422 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1423 struct lio_dev_ctrl_cmd ctrl_cmd;
1424 struct lio_ctrl_pkt ctrl_pkt;
1426 /* flush added to prevent cmd failure
1427 * incase the queue is full
1429 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1431 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1432 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1434 ctrl_cmd.eth_dev = eth_dev;
1437 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_RX_CSUM_CTL;
1438 ctrl_pkt.ncmd.s.param1 = LIO_CMD_RXCSUM_ENABLE;
1439 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1441 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1442 lio_dev_err(lio_dev, "Failed to send TNL_RX_CSUM command\n");
1446 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1447 lio_dev_err(lio_dev, "TNL_RX_CSUM command timed out\n");
1451 * Enable checksum calculation for inner packet in a tunnel.
1454 lio_enable_hw_tunnel_tx_checksum(struct rte_eth_dev *eth_dev)
1456 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1457 struct lio_dev_ctrl_cmd ctrl_cmd;
1458 struct lio_ctrl_pkt ctrl_pkt;
1460 /* flush added to prevent cmd failure
1461 * incase the queue is full
1463 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1465 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1466 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1468 ctrl_cmd.eth_dev = eth_dev;
1471 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_TX_CSUM_CTL;
1472 ctrl_pkt.ncmd.s.param1 = LIO_CMD_TXCSUM_ENABLE;
1473 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1475 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1476 lio_dev_err(lio_dev, "Failed to send TNL_TX_CSUM command\n");
1480 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1481 lio_dev_err(lio_dev, "TNL_TX_CSUM command timed out\n");
1484 static int lio_dev_configure(struct rte_eth_dev *eth_dev)
1486 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1487 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1488 int retval, num_iqueues, num_oqueues;
1489 uint8_t mac[ETHER_ADDR_LEN], i;
1490 struct lio_if_cfg_resp *resp;
1491 struct lio_soft_command *sc;
1492 union lio_if_cfg if_cfg;
1495 PMD_INIT_FUNC_TRACE();
1497 /* Re-configuring firmware not supported.
1498 * Can't change tx/rx queues per port from initial value.
1500 if (lio_dev->port_configured) {
1501 if ((lio_dev->nb_rx_queues != eth_dev->data->nb_rx_queues) ||
1502 (lio_dev->nb_tx_queues != eth_dev->data->nb_tx_queues)) {
1503 lio_dev_err(lio_dev,
1504 "rxq/txq re-conf not supported. Restart application with new value.\n");
1510 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
1511 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
1513 resp_size = sizeof(struct lio_if_cfg_resp);
1514 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1518 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
1520 /* Firmware doesn't have capability to reconfigure the queues,
1521 * Claim all queues, and use as many required
1523 if_cfg.if_cfg64 = 0;
1524 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
1525 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
1526 if_cfg.s.base_queue = 0;
1528 if_cfg.s.gmx_port_id = lio_dev->pf_num;
1530 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1531 LIO_OPCODE_IF_CFG, 0,
1532 if_cfg.if_cfg64, 0);
1534 /* Setting wait time in seconds */
1535 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1537 retval = lio_send_soft_command(lio_dev, sc);
1538 if (retval == LIO_IQ_SEND_FAILED) {
1539 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
1541 /* Soft instr is freed by driver in case of failure. */
1542 goto nic_config_fail;
1545 /* Sleep on a wait queue till the cond flag indicates that the
1546 * response arrived or timed-out.
1548 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1549 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1550 lio_process_ordered_list(lio_dev);
1554 retval = resp->status;
1556 lio_dev_err(lio_dev, "iq/oq config failed\n");
1557 goto nic_config_fail;
1560 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
1561 sizeof(struct octeon_if_cfg_info) >> 3);
1563 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
1564 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
1566 if (!(num_iqueues) || !(num_oqueues)) {
1567 lio_dev_err(lio_dev,
1568 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
1569 (unsigned long)resp->cfg_info.iqmask,
1570 (unsigned long)resp->cfg_info.oqmask);
1571 goto nic_config_fail;
1574 lio_dev_dbg(lio_dev,
1575 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
1576 eth_dev->data->port_id,
1577 (unsigned long)resp->cfg_info.iqmask,
1578 (unsigned long)resp->cfg_info.oqmask,
1579 num_iqueues, num_oqueues);
1581 lio_dev->linfo.num_rxpciq = num_oqueues;
1582 lio_dev->linfo.num_txpciq = num_iqueues;
1584 for (i = 0; i < num_oqueues; i++) {
1585 lio_dev->linfo.rxpciq[i].rxpciq64 =
1586 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
1587 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
1588 i, lio_dev->linfo.rxpciq[i].s.q_no);
1591 for (i = 0; i < num_iqueues; i++) {
1592 lio_dev->linfo.txpciq[i].txpciq64 =
1593 resp->cfg_info.linfo.txpciq[i].txpciq64;
1594 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
1595 i, lio_dev->linfo.txpciq[i].s.q_no);
1598 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1599 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1600 lio_dev->linfo.link.link_status64 =
1601 resp->cfg_info.linfo.link.link_status64;
1603 /* 64-bit swap required on LE machines */
1604 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
1605 for (i = 0; i < ETHER_ADDR_LEN; i++)
1606 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
1609 /* Copy the permanent MAC address */
1610 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
1612 /* enable firmware checksum support for tunnel packets */
1613 lio_enable_hw_tunnel_rx_checksum(eth_dev);
1614 lio_enable_hw_tunnel_tx_checksum(eth_dev);
1616 lio_dev->glist_lock =
1617 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
1618 if (lio_dev->glist_lock == NULL)
1621 lio_dev->glist_head =
1622 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
1624 if (lio_dev->glist_head == NULL) {
1625 rte_free(lio_dev->glist_lock);
1626 lio_dev->glist_lock = NULL;
1630 lio_dev_link_update(eth_dev, 0);
1632 lio_dev->port_configured = 1;
1634 lio_free_soft_command(sc);
1636 /* Disable iq_0 for reconf */
1637 lio_dev->fn_list.disable_io_queues(lio_dev);
1639 /* Reset ioq regs */
1640 lio_dev->fn_list.setup_device_regs(lio_dev);
1642 /* Free iq_0 used during init */
1643 lio_free_instr_queue0(lio_dev);
1648 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
1649 lio_free_soft_command(sc);
1650 lio_free_instr_queue0(lio_dev);
1655 /* Define our ethernet definitions */
1656 static const struct eth_dev_ops liovf_eth_dev_ops = {
1657 .dev_configure = lio_dev_configure,
1658 .dev_start = lio_dev_start,
1659 .dev_set_link_up = lio_dev_set_link_up,
1660 .dev_set_link_down = lio_dev_set_link_down,
1661 .allmulticast_enable = lio_dev_allmulticast_enable,
1662 .allmulticast_disable = lio_dev_allmulticast_disable,
1663 .link_update = lio_dev_link_update,
1664 .stats_get = lio_dev_stats_get,
1665 .xstats_get = lio_dev_xstats_get,
1666 .xstats_get_names = lio_dev_xstats_get_names,
1667 .stats_reset = lio_dev_stats_reset,
1668 .xstats_reset = lio_dev_xstats_reset,
1669 .dev_infos_get = lio_dev_info_get,
1670 .rx_queue_setup = lio_dev_rx_queue_setup,
1671 .rx_queue_release = lio_dev_rx_queue_release,
1672 .tx_queue_setup = lio_dev_tx_queue_setup,
1673 .tx_queue_release = lio_dev_tx_queue_release,
1674 .reta_update = lio_dev_rss_reta_update,
1675 .reta_query = lio_dev_rss_reta_query,
1676 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
1677 .rss_hash_update = lio_dev_rss_hash_update,
1678 .udp_tunnel_port_add = lio_dev_udp_tunnel_add,
1679 .udp_tunnel_port_del = lio_dev_udp_tunnel_del,
1683 lio_check_pf_hs_response(void *lio_dev)
1685 struct lio_device *dev = lio_dev;
1687 /* check till response arrives */
1688 if (dev->pfvf_hsword.coproc_tics_per_us)
1691 cn23xx_vf_handle_mbox(dev);
1693 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1697 * \brief Identify the LIO device and to map the BAR address space
1698 * @param lio_dev lio device
1701 lio_chip_specific_setup(struct lio_device *lio_dev)
1703 struct rte_pci_device *pdev = lio_dev->pci_dev;
1704 uint32_t dev_id = pdev->id.device_id;
1709 case LIO_CN23XX_VF_VID:
1710 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1711 ret = cn23xx_vf_setup_device(lio_dev);
1716 lio_dev_err(lio_dev, "Unsupported Chip\n");
1720 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1726 lio_first_time_init(struct lio_device *lio_dev,
1727 struct rte_pci_device *pdev)
1731 PMD_INIT_FUNC_TRACE();
1733 /* set dpdk specific pci device pointer */
1734 lio_dev->pci_dev = pdev;
1736 /* Identify the LIO type and set device ops */
1737 if (lio_chip_specific_setup(lio_dev)) {
1738 lio_dev_err(lio_dev, "Chip specific setup failed\n");
1742 /* Initialize soft command buffer pool */
1743 if (lio_setup_sc_buffer_pool(lio_dev)) {
1744 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
1748 /* Initialize lists to manage the requests of different types that
1749 * arrive from applications for this lio device.
1751 lio_setup_response_list(lio_dev);
1753 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
1754 lio_dev_err(lio_dev, "Mailbox setup failed\n");
1758 /* Check PF response */
1759 lio_check_pf_hs_response((void *)lio_dev);
1761 /* Do handshake and exit if incompatible PF driver */
1762 if (cn23xx_pfvf_handshake(lio_dev))
1766 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1767 /* Wait for FLR for 100ms per SRIOV specification */
1770 if (cn23xx_vf_set_io_queues_off(lio_dev)) {
1771 lio_dev_err(lio_dev, "Setting io queues off failed\n");
1775 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1776 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1780 if (lio_setup_instr_queue0(lio_dev)) {
1781 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
1785 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
1787 lio_dev->max_tx_queues = dpdk_queues;
1788 lio_dev->max_rx_queues = dpdk_queues;
1790 /* Enable input and output queues for this device */
1791 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1797 lio_free_sc_buffer_pool(lio_dev);
1798 if (lio_dev->mbox[0])
1799 lio_dev->fn_list.free_mbox(lio_dev);
1800 if (lio_dev->instr_queue[0])
1801 lio_free_instr_queue0(lio_dev);
1807 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1809 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1811 PMD_INIT_FUNC_TRACE();
1813 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1816 /* lio_free_sc_buffer_pool */
1817 lio_free_sc_buffer_pool(lio_dev);
1819 rte_free(eth_dev->data->mac_addrs);
1820 eth_dev->data->mac_addrs = NULL;
1822 eth_dev->rx_pkt_burst = NULL;
1823 eth_dev->tx_pkt_burst = NULL;
1829 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
1831 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
1832 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1834 PMD_INIT_FUNC_TRACE();
1836 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
1837 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
1839 /* Primary does the initialization. */
1840 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1843 rte_eth_copy_pci_info(eth_dev, pdev);
1844 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1846 if (pdev->mem_resource[0].addr) {
1847 lio_dev->hw_addr = pdev->mem_resource[0].addr;
1849 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
1853 lio_dev->eth_dev = eth_dev;
1854 /* set lio device print string */
1855 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
1856 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
1857 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1859 lio_dev->port_id = eth_dev->data->port_id;
1861 if (lio_first_time_init(lio_dev, pdev)) {
1862 lio_dev_err(lio_dev, "Device init failed\n");
1866 eth_dev->dev_ops = &liovf_eth_dev_ops;
1867 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
1868 if (eth_dev->data->mac_addrs == NULL) {
1869 lio_dev_err(lio_dev,
1870 "MAC addresses memory allocation failed\n");
1871 eth_dev->dev_ops = NULL;
1872 eth_dev->rx_pkt_burst = NULL;
1873 eth_dev->tx_pkt_burst = NULL;
1877 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
1880 lio_dev->port_configured = 0;
1881 /* Always allow unicast packets */
1882 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
1887 /* Set of PCI devices this driver supports */
1888 static const struct rte_pci_id pci_id_liovf_map[] = {
1889 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
1890 { .vendor_id = 0, /* sentinel */ }
1893 static struct eth_driver rte_liovf_pmd = {
1895 .id_table = pci_id_liovf_map,
1896 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1897 .probe = rte_eth_dev_pci_probe,
1898 .remove = rte_eth_dev_pci_remove,
1900 .eth_dev_init = lio_eth_dev_init,
1901 .eth_dev_uninit = lio_eth_dev_uninit,
1902 .dev_private_size = sizeof(struct lio_device),
1905 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
1906 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
1907 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");