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 DEV_RX_OFFLOAD_VLAN_STRIP);
409 devinfo->tx_offload_capa = (DEV_TX_OFFLOAD_IPV4_CKSUM |
410 DEV_TX_OFFLOAD_UDP_CKSUM |
411 DEV_TX_OFFLOAD_TCP_CKSUM |
412 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM);
414 devinfo->rx_desc_lim = lio_rx_desc_lim;
415 devinfo->tx_desc_lim = lio_tx_desc_lim;
417 devinfo->reta_size = LIO_RSS_MAX_TABLE_SZ;
418 devinfo->hash_key_size = LIO_RSS_MAX_KEY_SZ;
419 devinfo->flow_type_rss_offloads = (ETH_RSS_IPV4 |
420 ETH_RSS_NONFRAG_IPV4_TCP |
422 ETH_RSS_NONFRAG_IPV6_TCP |
424 ETH_RSS_IPV6_TCP_EX);
428 lio_dev_validate_vf_mtu(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
430 struct lio_device *lio_dev = LIO_DEV(eth_dev);
432 PMD_INIT_FUNC_TRACE();
434 if (!lio_dev->intf_open) {
435 lio_dev_err(lio_dev, "Port %d down, can't check MTU\n",
440 /* Limit the MTU to make sure the ethernet packets are between
441 * ETHER_MIN_MTU bytes and PF's MTU
443 if ((new_mtu < ETHER_MIN_MTU) ||
444 (new_mtu > lio_dev->linfo.link.s.mtu)) {
445 lio_dev_err(lio_dev, "Invalid MTU: %d\n", new_mtu);
446 lio_dev_err(lio_dev, "Valid range %d and %d\n",
447 ETHER_MIN_MTU, lio_dev->linfo.link.s.mtu);
455 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
456 struct rte_eth_rss_reta_entry64 *reta_conf,
459 struct lio_device *lio_dev = LIO_DEV(eth_dev);
460 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
461 struct lio_rss_set *rss_param;
462 struct lio_dev_ctrl_cmd ctrl_cmd;
463 struct lio_ctrl_pkt ctrl_pkt;
466 if (!lio_dev->intf_open) {
467 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
472 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
474 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
475 reta_size, LIO_RSS_MAX_TABLE_SZ);
479 /* flush added to prevent cmd failure
480 * incase the queue is full
482 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
484 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
485 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
487 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
489 ctrl_cmd.eth_dev = eth_dev;
492 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
493 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
494 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
496 rss_param->param.flags = 0xF;
497 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
498 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
500 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
501 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
502 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
503 index = (i * RTE_RETA_GROUP_SIZE) + j;
504 rss_state->itable[index] = reta_conf[i].reta[j];
509 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
510 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
512 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
514 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
515 lio_dev_err(lio_dev, "Failed to set rss hash\n");
519 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
520 lio_dev_err(lio_dev, "Set rss hash timed out\n");
528 lio_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
529 struct rte_eth_rss_reta_entry64 *reta_conf,
532 struct lio_device *lio_dev = LIO_DEV(eth_dev);
533 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
536 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
538 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
539 reta_size, LIO_RSS_MAX_TABLE_SZ);
543 num = reta_size / RTE_RETA_GROUP_SIZE;
545 for (i = 0; i < num; i++) {
546 memcpy(reta_conf->reta,
547 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
548 RTE_RETA_GROUP_SIZE);
556 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
557 struct rte_eth_rss_conf *rss_conf)
559 struct lio_device *lio_dev = LIO_DEV(eth_dev);
560 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
561 uint8_t *hash_key = NULL;
564 if (rss_state->hash_disable) {
565 lio_dev_info(lio_dev, "RSS disabled in nic\n");
566 rss_conf->rss_hf = 0;
571 hash_key = rss_conf->rss_key;
572 if (hash_key != NULL)
573 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
576 rss_hf |= ETH_RSS_IPV4;
577 if (rss_state->tcp_hash)
578 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
580 rss_hf |= ETH_RSS_IPV6;
581 if (rss_state->ipv6_tcp_hash)
582 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
583 if (rss_state->ipv6_ex)
584 rss_hf |= ETH_RSS_IPV6_EX;
585 if (rss_state->ipv6_tcp_ex_hash)
586 rss_hf |= ETH_RSS_IPV6_TCP_EX;
588 rss_conf->rss_hf = rss_hf;
594 lio_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
595 struct rte_eth_rss_conf *rss_conf)
597 struct lio_device *lio_dev = LIO_DEV(eth_dev);
598 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
599 struct lio_rss_set *rss_param;
600 struct lio_dev_ctrl_cmd ctrl_cmd;
601 struct lio_ctrl_pkt ctrl_pkt;
603 if (!lio_dev->intf_open) {
604 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
609 /* flush added to prevent cmd failure
610 * incase the queue is full
612 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
614 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
615 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
617 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
619 ctrl_cmd.eth_dev = eth_dev;
622 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
623 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
624 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
626 rss_param->param.flags = 0xF;
628 if (rss_conf->rss_key) {
629 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
630 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
631 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
632 memcpy(rss_state->hash_key, rss_conf->rss_key,
633 rss_state->hash_key_size);
634 memcpy(rss_param->key, rss_state->hash_key,
635 rss_state->hash_key_size);
638 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
639 /* Can't disable rss through hash flags,
640 * if it is enabled by default during init
642 if (!rss_state->hash_disable)
645 /* This is for --disable-rss during testpmd launch */
646 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
648 uint32_t hashinfo = 0;
650 /* Can't enable rss if disabled by default during init */
651 if (rss_state->hash_disable)
654 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
655 hashinfo |= LIO_RSS_HASH_IPV4;
661 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
662 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
663 rss_state->tcp_hash = 1;
665 rss_state->tcp_hash = 0;
668 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
669 hashinfo |= LIO_RSS_HASH_IPV6;
675 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
676 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
677 rss_state->ipv6_tcp_hash = 1;
679 rss_state->ipv6_tcp_hash = 0;
682 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
683 hashinfo |= LIO_RSS_HASH_IPV6_EX;
684 rss_state->ipv6_ex = 1;
686 rss_state->ipv6_ex = 0;
689 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
690 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
691 rss_state->ipv6_tcp_ex_hash = 1;
693 rss_state->ipv6_tcp_ex_hash = 0;
696 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
697 rss_param->param.hashinfo = hashinfo;
700 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
702 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
703 lio_dev_err(lio_dev, "Failed to set rss hash\n");
707 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
708 lio_dev_err(lio_dev, "Set rss hash timed out\n");
716 * Add vxlan dest udp port for an interface.
719 * Pointer to the structure rte_eth_dev
724 * On success return 0
725 * On failure return -1
728 lio_dev_udp_tunnel_add(struct rte_eth_dev *eth_dev,
729 struct rte_eth_udp_tunnel *udp_tnl)
731 struct lio_device *lio_dev = LIO_DEV(eth_dev);
732 struct lio_dev_ctrl_cmd ctrl_cmd;
733 struct lio_ctrl_pkt ctrl_pkt;
738 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
739 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
743 /* flush added to prevent cmd failure
744 * incase the queue is full
746 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
748 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
749 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
751 ctrl_cmd.eth_dev = eth_dev;
754 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
755 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
756 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_ADD;
757 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
759 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
760 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_ADD command\n");
764 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
765 lio_dev_err(lio_dev, "VXLAN_PORT_ADD command timed out\n");
773 * Remove vxlan dest udp port for an interface.
776 * Pointer to the structure rte_eth_dev
781 * On success return 0
782 * On failure return -1
785 lio_dev_udp_tunnel_del(struct rte_eth_dev *eth_dev,
786 struct rte_eth_udp_tunnel *udp_tnl)
788 struct lio_device *lio_dev = LIO_DEV(eth_dev);
789 struct lio_dev_ctrl_cmd ctrl_cmd;
790 struct lio_ctrl_pkt ctrl_pkt;
795 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
796 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
800 /* flush added to prevent cmd failure
801 * incase the queue is full
803 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
805 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
806 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
808 ctrl_cmd.eth_dev = eth_dev;
811 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
812 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
813 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_DEL;
814 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
816 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
817 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_DEL command\n");
821 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
822 lio_dev_err(lio_dev, "VXLAN_PORT_DEL command timed out\n");
830 lio_dev_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id, int on)
832 struct lio_device *lio_dev = LIO_DEV(eth_dev);
833 struct lio_dev_ctrl_cmd ctrl_cmd;
834 struct lio_ctrl_pkt ctrl_pkt;
836 if (lio_dev->linfo.vlan_is_admin_assigned)
839 /* flush added to prevent cmd failure
840 * incase the queue is full
842 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
844 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
845 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
847 ctrl_cmd.eth_dev = eth_dev;
850 ctrl_pkt.ncmd.s.cmd = on ?
851 LIO_CMD_ADD_VLAN_FILTER : LIO_CMD_DEL_VLAN_FILTER;
852 ctrl_pkt.ncmd.s.param1 = vlan_id;
853 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
855 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
856 lio_dev_err(lio_dev, "Failed to %s VLAN port\n",
857 on ? "add" : "remove");
861 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
862 lio_dev_err(lio_dev, "Command to %s VLAN port timed out\n",
863 on ? "add" : "remove");
871 * Atomically writes the link status information into global
872 * structure rte_eth_dev.
875 * - Pointer to the structure rte_eth_dev to read from.
876 * - Pointer to the buffer to be saved with the link status.
879 * - On success, zero.
880 * - On failure, negative value.
883 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
884 struct rte_eth_link *link)
886 struct rte_eth_link *dst = ð_dev->data->dev_link;
887 struct rte_eth_link *src = link;
889 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
890 *(uint64_t *)src) == 0)
897 lio_hweight64(uint64_t w)
899 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
902 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
903 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
904 res = res + (res >> 8);
905 res = res + (res >> 16);
907 return (res + (res >> 32)) & 0x00000000000000FFul;
911 lio_dev_link_update(struct rte_eth_dev *eth_dev,
912 int wait_to_complete __rte_unused)
914 struct lio_device *lio_dev = LIO_DEV(eth_dev);
915 struct rte_eth_link link, old;
918 link.link_status = ETH_LINK_DOWN;
919 link.link_speed = ETH_SPEED_NUM_NONE;
920 link.link_duplex = ETH_LINK_HALF_DUPLEX;
921 memset(&old, 0, sizeof(old));
923 /* Return what we found */
924 if (lio_dev->linfo.link.s.link_up == 0) {
925 /* Interface is down */
926 if (lio_dev_atomic_write_link_status(eth_dev, &link))
928 if (link.link_status == old.link_status)
933 link.link_status = ETH_LINK_UP; /* Interface is up */
934 link.link_duplex = ETH_LINK_FULL_DUPLEX;
935 switch (lio_dev->linfo.link.s.speed) {
936 case LIO_LINK_SPEED_10000:
937 link.link_speed = ETH_SPEED_NUM_10G;
940 link.link_speed = ETH_SPEED_NUM_NONE;
941 link.link_duplex = ETH_LINK_HALF_DUPLEX;
944 if (lio_dev_atomic_write_link_status(eth_dev, &link))
947 if (link.link_status == old.link_status)
954 * \brief Net device enable, disable allmulticast
955 * @param eth_dev Pointer to the structure rte_eth_dev
958 lio_change_dev_flag(struct rte_eth_dev *eth_dev)
960 struct lio_device *lio_dev = LIO_DEV(eth_dev);
961 struct lio_dev_ctrl_cmd ctrl_cmd;
962 struct lio_ctrl_pkt ctrl_pkt;
964 /* flush added to prevent cmd failure
965 * incase the queue is full
967 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
969 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
970 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
972 ctrl_cmd.eth_dev = eth_dev;
975 /* Create a ctrl pkt command to be sent to core app. */
976 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CHANGE_DEVFLAGS;
977 ctrl_pkt.ncmd.s.param1 = lio_dev->ifflags;
978 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
980 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
981 lio_dev_err(lio_dev, "Failed to send change flag message\n");
985 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
986 lio_dev_err(lio_dev, "Change dev flag command timed out\n");
990 lio_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
992 struct lio_device *lio_dev = LIO_DEV(eth_dev);
994 if (!lio_dev->intf_open) {
995 lio_dev_err(lio_dev, "Port %d down, can't enable multicast\n",
1000 lio_dev->ifflags |= LIO_IFFLAG_ALLMULTI;
1001 lio_change_dev_flag(eth_dev);
1005 lio_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
1007 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1009 if (!lio_dev->intf_open) {
1010 lio_dev_err(lio_dev, "Port %d down, can't disable multicast\n",
1015 lio_dev->ifflags &= ~LIO_IFFLAG_ALLMULTI;
1016 lio_change_dev_flag(eth_dev);
1020 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
1022 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1023 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1024 struct rte_eth_rss_reta_entry64 reta_conf[8];
1025 struct rte_eth_rss_conf rss_conf;
1028 /* Configure the RSS key and the RSS protocols used to compute
1029 * the RSS hash of input packets.
1031 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
1032 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
1033 rss_state->hash_disable = 1;
1034 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1038 if (rss_conf.rss_key == NULL)
1039 rss_conf.rss_key = lio_rss_key; /* Default hash key */
1041 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1043 memset(reta_conf, 0, sizeof(reta_conf));
1044 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
1045 uint8_t q_idx, conf_idx, reta_idx;
1047 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
1048 i % eth_dev->data->nb_rx_queues : 0);
1049 conf_idx = i / RTE_RETA_GROUP_SIZE;
1050 reta_idx = i % RTE_RETA_GROUP_SIZE;
1051 reta_conf[conf_idx].reta[reta_idx] = q_idx;
1052 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
1055 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
1059 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
1061 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1062 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1063 struct rte_eth_rss_conf rss_conf;
1065 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
1067 lio_dev_rss_configure(eth_dev);
1069 case ETH_MQ_RX_NONE:
1070 /* if mq_mode is none, disable rss mode. */
1072 memset(&rss_conf, 0, sizeof(rss_conf));
1073 rss_state->hash_disable = 1;
1074 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1079 * Setup our receive queue/ringbuffer. This is the
1080 * queue the Octeon uses to send us packets and
1081 * responses. We are given a memory pool for our
1082 * packet buffers that are used to populate the receive
1086 * Pointer to the structure rte_eth_dev
1089 * @param num_rx_descs
1090 * Number of entries in the queue
1092 * Where to allocate memory
1094 * Pointer to the struction rte_eth_rxconf
1096 * Pointer to the packet pool
1099 * - On success, return 0
1100 * - On failure, return -1
1103 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1104 uint16_t num_rx_descs, unsigned int socket_id,
1105 const struct rte_eth_rxconf *rx_conf __rte_unused,
1106 struct rte_mempool *mp)
1108 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1109 struct rte_pktmbuf_pool_private *mbp_priv;
1110 uint32_t fw_mapped_oq;
1113 if (q_no >= lio_dev->nb_rx_queues) {
1114 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
1118 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
1120 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
1122 if ((lio_dev->droq[fw_mapped_oq]) &&
1123 (num_rx_descs != lio_dev->droq[fw_mapped_oq]->max_count)) {
1124 lio_dev_err(lio_dev,
1125 "Reconfiguring Rx descs not supported. Configure descs to same value %u or restart application\n",
1126 lio_dev->droq[fw_mapped_oq]->max_count);
1130 mbp_priv = rte_mempool_get_priv(mp);
1131 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
1133 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
1135 lio_dev_err(lio_dev, "droq allocation failed\n");
1139 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
1145 * Release the receive queue/ringbuffer. Called by
1149 * Opaque pointer to the receive queue to release
1155 lio_dev_rx_queue_release(void *rxq)
1157 struct lio_droq *droq = rxq;
1158 struct lio_device *lio_dev = droq->lio_dev;
1161 /* Run time queue deletion not supported */
1162 if (lio_dev->port_configured)
1167 lio_delete_droq_queue(droq->lio_dev, oq_no);
1172 * Allocate and initialize SW ring. Initialize associated HW registers.
1175 * Pointer to structure rte_eth_dev
1180 * @param num_tx_descs
1181 * Number of ringbuffer descriptors
1184 * NUMA socket id, used for memory allocations
1187 * Pointer to the structure rte_eth_txconf
1190 * - On success, return 0
1191 * - On failure, return -errno value
1194 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1195 uint16_t num_tx_descs, unsigned int socket_id,
1196 const struct rte_eth_txconf *tx_conf __rte_unused)
1198 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1199 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
1202 if (q_no >= lio_dev->nb_tx_queues) {
1203 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
1207 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
1209 if ((lio_dev->instr_queue[fw_mapped_iq] != NULL) &&
1210 (num_tx_descs != lio_dev->instr_queue[fw_mapped_iq]->max_count)) {
1211 lio_dev_err(lio_dev,
1212 "Reconfiguring Tx descs not supported. Configure descs to same value %u or restart application\n",
1213 lio_dev->instr_queue[fw_mapped_iq]->max_count);
1217 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
1218 num_tx_descs, lio_dev, socket_id);
1221 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
1225 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
1226 lio_dev->instr_queue[fw_mapped_iq]->max_count,
1230 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
1234 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
1240 * Release the transmit queue/ringbuffer. Called by
1244 * Opaque pointer to the transmit queue to release
1250 lio_dev_tx_queue_release(void *txq)
1252 struct lio_instr_queue *tq = txq;
1253 struct lio_device *lio_dev = tq->lio_dev;
1254 uint32_t fw_mapped_iq_no;
1256 /* Run time queue deletion not supported */
1257 if (lio_dev->port_configured)
1262 lio_delete_sglist(tq);
1264 fw_mapped_iq_no = tq->txpciq.s.q_no;
1265 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
1270 * Api to check link state.
1273 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
1275 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1276 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1277 struct lio_link_status_resp *resp;
1278 union octeon_link_status *ls;
1279 struct lio_soft_command *sc;
1282 if (!lio_dev->intf_open)
1285 resp_size = sizeof(struct lio_link_status_resp);
1286 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1290 resp = (struct lio_link_status_resp *)sc->virtrptr;
1291 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1292 LIO_OPCODE_INFO, 0, 0, 0);
1294 /* Setting wait time in seconds */
1295 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1297 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
1298 goto get_status_fail;
1300 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1301 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1306 goto get_status_fail;
1308 ls = &resp->link_info.link;
1310 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
1312 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
1313 lio_dev->linfo.link.link_status64 = ls->link_status64;
1314 lio_dev_link_update(eth_dev, 0);
1317 lio_free_soft_command(sc);
1322 lio_free_soft_command(sc);
1325 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
1326 * and will update link state if it changes.
1329 lio_sync_link_state_check(void *eth_dev)
1331 struct lio_device *lio_dev =
1332 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
1334 if (lio_dev->port_configured)
1335 lio_dev_get_link_status(eth_dev);
1337 /* Schedule periodic link status check.
1338 * Stop check if interface is close and start again while opening.
1340 if (lio_dev->intf_open)
1341 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
1346 lio_dev_start(struct rte_eth_dev *eth_dev)
1348 uint16_t mtu = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
1349 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1350 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1353 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
1355 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1358 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
1361 /* Ready for link status updates */
1362 lio_dev->intf_open = 1;
1365 /* Configure RSS if device configured with multiple RX queues. */
1366 lio_dev_mq_rx_configure(eth_dev);
1368 /* start polling for lsc */
1369 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
1370 lio_sync_link_state_check,
1373 lio_dev_err(lio_dev,
1374 "link state check handler creation failed\n");
1375 goto dev_lsc_handle_error;
1378 while ((lio_dev->linfo.link.link_status64 == 0) && (--timeout))
1381 if (lio_dev->linfo.link.link_status64 == 0) {
1383 goto dev_mtu_check_error;
1386 if (lio_dev->linfo.link.s.mtu != mtu) {
1387 ret = lio_dev_validate_vf_mtu(eth_dev, mtu);
1389 goto dev_mtu_check_error;
1394 dev_mtu_check_error:
1395 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1397 dev_lsc_handle_error:
1398 lio_dev->intf_open = 0;
1399 lio_send_rx_ctrl_cmd(eth_dev, 0);
1404 /* Stop device and disable input/output functions */
1406 lio_dev_stop(struct rte_eth_dev *eth_dev)
1408 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1410 lio_dev_info(lio_dev, "Stopping port %d\n", eth_dev->data->port_id);
1411 lio_dev->intf_open = 0;
1414 /* Cancel callback if still running. */
1415 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1417 lio_send_rx_ctrl_cmd(eth_dev, 0);
1419 /* Clear recorded link status */
1420 lio_dev->linfo.link.link_status64 = 0;
1424 lio_dev_set_link_up(struct rte_eth_dev *eth_dev)
1426 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1428 if (!lio_dev->intf_open) {
1429 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1433 if (lio_dev->linfo.link.s.link_up) {
1434 lio_dev_info(lio_dev, "Link is already UP\n");
1438 if (lio_send_rx_ctrl_cmd(eth_dev, 1)) {
1439 lio_dev_err(lio_dev, "Unable to set Link UP\n");
1443 lio_dev->linfo.link.s.link_up = 1;
1444 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1450 lio_dev_set_link_down(struct rte_eth_dev *eth_dev)
1452 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1454 if (!lio_dev->intf_open) {
1455 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1459 if (!lio_dev->linfo.link.s.link_up) {
1460 lio_dev_info(lio_dev, "Link is already DOWN\n");
1464 lio_dev->linfo.link.s.link_up = 0;
1465 eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
1467 if (lio_send_rx_ctrl_cmd(eth_dev, 0)) {
1468 lio_dev->linfo.link.s.link_up = 1;
1469 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1470 lio_dev_err(lio_dev, "Unable to set Link Down\n");
1478 * Reset and stop the device. This occurs on the first
1479 * call to this routine. Subsequent calls will simply
1480 * return. NB: This will require the NIC to be rebooted.
1483 * Pointer to the structure rte_eth_dev
1489 lio_dev_close(struct rte_eth_dev *eth_dev)
1491 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1494 lio_dev_info(lio_dev, "closing port %d\n", eth_dev->data->port_id);
1496 if (lio_dev->intf_open)
1497 lio_dev_stop(eth_dev);
1499 lio_wait_for_instr_fetch(lio_dev);
1501 lio_dev->fn_list.disable_io_queues(lio_dev);
1503 cn23xx_vf_set_io_queues_off(lio_dev);
1505 /* Reset iq regs (IQ_DBELL).
1506 * Clear sli_pktx_cnts (OQ_PKTS_SENT).
1508 for (i = 0; i < lio_dev->nb_rx_queues; i++) {
1509 struct lio_droq *droq = lio_dev->droq[i];
1514 uint32_t pkt_count = rte_read32(droq->pkts_sent_reg);
1516 lio_dev_dbg(lio_dev,
1517 "pending oq count %u\n", pkt_count);
1518 rte_write32(pkt_count, droq->pkts_sent_reg);
1521 /* Do FLR for the VF */
1522 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1525 lio_dev->fn_list.free_mbox(lio_dev);
1527 /* Free glist resources */
1528 rte_free(lio_dev->glist_head);
1529 rte_free(lio_dev->glist_lock);
1530 lio_dev->glist_head = NULL;
1531 lio_dev->glist_lock = NULL;
1533 lio_dev->port_configured = 0;
1535 /* Delete all queues */
1536 lio_dev_clear_queues(eth_dev);
1540 * Enable tunnel rx checksum verification from firmware.
1543 lio_enable_hw_tunnel_rx_checksum(struct rte_eth_dev *eth_dev)
1545 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1546 struct lio_dev_ctrl_cmd ctrl_cmd;
1547 struct lio_ctrl_pkt ctrl_pkt;
1549 /* flush added to prevent cmd failure
1550 * incase the queue is full
1552 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1554 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1555 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1557 ctrl_cmd.eth_dev = eth_dev;
1560 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_RX_CSUM_CTL;
1561 ctrl_pkt.ncmd.s.param1 = LIO_CMD_RXCSUM_ENABLE;
1562 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1564 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1565 lio_dev_err(lio_dev, "Failed to send TNL_RX_CSUM command\n");
1569 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1570 lio_dev_err(lio_dev, "TNL_RX_CSUM command timed out\n");
1574 * Enable checksum calculation for inner packet in a tunnel.
1577 lio_enable_hw_tunnel_tx_checksum(struct rte_eth_dev *eth_dev)
1579 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1580 struct lio_dev_ctrl_cmd ctrl_cmd;
1581 struct lio_ctrl_pkt ctrl_pkt;
1583 /* flush added to prevent cmd failure
1584 * incase the queue is full
1586 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1588 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1589 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1591 ctrl_cmd.eth_dev = eth_dev;
1594 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_TX_CSUM_CTL;
1595 ctrl_pkt.ncmd.s.param1 = LIO_CMD_TXCSUM_ENABLE;
1596 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1598 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1599 lio_dev_err(lio_dev, "Failed to send TNL_TX_CSUM command\n");
1603 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1604 lio_dev_err(lio_dev, "TNL_TX_CSUM command timed out\n");
1607 static int lio_dev_configure(struct rte_eth_dev *eth_dev)
1609 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1610 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1611 int retval, num_iqueues, num_oqueues;
1612 uint8_t mac[ETHER_ADDR_LEN], i;
1613 struct lio_if_cfg_resp *resp;
1614 struct lio_soft_command *sc;
1615 union lio_if_cfg if_cfg;
1618 PMD_INIT_FUNC_TRACE();
1620 /* Re-configuring firmware not supported.
1621 * Can't change tx/rx queues per port from initial value.
1623 if (lio_dev->port_configured) {
1624 if ((lio_dev->nb_rx_queues != eth_dev->data->nb_rx_queues) ||
1625 (lio_dev->nb_tx_queues != eth_dev->data->nb_tx_queues)) {
1626 lio_dev_err(lio_dev,
1627 "rxq/txq re-conf not supported. Restart application with new value.\n");
1633 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
1634 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
1636 resp_size = sizeof(struct lio_if_cfg_resp);
1637 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1641 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
1643 /* Firmware doesn't have capability to reconfigure the queues,
1644 * Claim all queues, and use as many required
1646 if_cfg.if_cfg64 = 0;
1647 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
1648 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
1649 if_cfg.s.base_queue = 0;
1651 if_cfg.s.gmx_port_id = lio_dev->pf_num;
1653 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1654 LIO_OPCODE_IF_CFG, 0,
1655 if_cfg.if_cfg64, 0);
1657 /* Setting wait time in seconds */
1658 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1660 retval = lio_send_soft_command(lio_dev, sc);
1661 if (retval == LIO_IQ_SEND_FAILED) {
1662 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
1664 /* Soft instr is freed by driver in case of failure. */
1665 goto nic_config_fail;
1668 /* Sleep on a wait queue till the cond flag indicates that the
1669 * response arrived or timed-out.
1671 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1672 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1673 lio_process_ordered_list(lio_dev);
1677 retval = resp->status;
1679 lio_dev_err(lio_dev, "iq/oq config failed\n");
1680 goto nic_config_fail;
1683 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
1684 sizeof(struct octeon_if_cfg_info) >> 3);
1686 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
1687 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
1689 if (!(num_iqueues) || !(num_oqueues)) {
1690 lio_dev_err(lio_dev,
1691 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
1692 (unsigned long)resp->cfg_info.iqmask,
1693 (unsigned long)resp->cfg_info.oqmask);
1694 goto nic_config_fail;
1697 lio_dev_dbg(lio_dev,
1698 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
1699 eth_dev->data->port_id,
1700 (unsigned long)resp->cfg_info.iqmask,
1701 (unsigned long)resp->cfg_info.oqmask,
1702 num_iqueues, num_oqueues);
1704 lio_dev->linfo.num_rxpciq = num_oqueues;
1705 lio_dev->linfo.num_txpciq = num_iqueues;
1707 for (i = 0; i < num_oqueues; i++) {
1708 lio_dev->linfo.rxpciq[i].rxpciq64 =
1709 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
1710 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
1711 i, lio_dev->linfo.rxpciq[i].s.q_no);
1714 for (i = 0; i < num_iqueues; i++) {
1715 lio_dev->linfo.txpciq[i].txpciq64 =
1716 resp->cfg_info.linfo.txpciq[i].txpciq64;
1717 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
1718 i, lio_dev->linfo.txpciq[i].s.q_no);
1721 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1722 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1723 lio_dev->linfo.link.link_status64 =
1724 resp->cfg_info.linfo.link.link_status64;
1726 /* 64-bit swap required on LE machines */
1727 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
1728 for (i = 0; i < ETHER_ADDR_LEN; i++)
1729 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
1732 /* Copy the permanent MAC address */
1733 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
1735 /* enable firmware checksum support for tunnel packets */
1736 lio_enable_hw_tunnel_rx_checksum(eth_dev);
1737 lio_enable_hw_tunnel_tx_checksum(eth_dev);
1739 lio_dev->glist_lock =
1740 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
1741 if (lio_dev->glist_lock == NULL)
1744 lio_dev->glist_head =
1745 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
1747 if (lio_dev->glist_head == NULL) {
1748 rte_free(lio_dev->glist_lock);
1749 lio_dev->glist_lock = NULL;
1753 lio_dev_link_update(eth_dev, 0);
1755 lio_dev->port_configured = 1;
1757 lio_free_soft_command(sc);
1759 /* Disable iq_0 for reconf */
1760 lio_dev->fn_list.disable_io_queues(lio_dev);
1762 /* Reset ioq regs */
1763 lio_dev->fn_list.setup_device_regs(lio_dev);
1765 /* Free iq_0 used during init */
1766 lio_free_instr_queue0(lio_dev);
1771 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
1772 lio_free_soft_command(sc);
1773 lio_free_instr_queue0(lio_dev);
1778 /* Define our ethernet definitions */
1779 static const struct eth_dev_ops liovf_eth_dev_ops = {
1780 .dev_configure = lio_dev_configure,
1781 .dev_start = lio_dev_start,
1782 .dev_stop = lio_dev_stop,
1783 .dev_set_link_up = lio_dev_set_link_up,
1784 .dev_set_link_down = lio_dev_set_link_down,
1785 .dev_close = lio_dev_close,
1786 .allmulticast_enable = lio_dev_allmulticast_enable,
1787 .allmulticast_disable = lio_dev_allmulticast_disable,
1788 .link_update = lio_dev_link_update,
1789 .stats_get = lio_dev_stats_get,
1790 .xstats_get = lio_dev_xstats_get,
1791 .xstats_get_names = lio_dev_xstats_get_names,
1792 .stats_reset = lio_dev_stats_reset,
1793 .xstats_reset = lio_dev_xstats_reset,
1794 .dev_infos_get = lio_dev_info_get,
1795 .vlan_filter_set = lio_dev_vlan_filter_set,
1796 .rx_queue_setup = lio_dev_rx_queue_setup,
1797 .rx_queue_release = lio_dev_rx_queue_release,
1798 .tx_queue_setup = lio_dev_tx_queue_setup,
1799 .tx_queue_release = lio_dev_tx_queue_release,
1800 .reta_update = lio_dev_rss_reta_update,
1801 .reta_query = lio_dev_rss_reta_query,
1802 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
1803 .rss_hash_update = lio_dev_rss_hash_update,
1804 .udp_tunnel_port_add = lio_dev_udp_tunnel_add,
1805 .udp_tunnel_port_del = lio_dev_udp_tunnel_del,
1809 lio_check_pf_hs_response(void *lio_dev)
1811 struct lio_device *dev = lio_dev;
1813 /* check till response arrives */
1814 if (dev->pfvf_hsword.coproc_tics_per_us)
1817 cn23xx_vf_handle_mbox(dev);
1819 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1823 * \brief Identify the LIO device and to map the BAR address space
1824 * @param lio_dev lio device
1827 lio_chip_specific_setup(struct lio_device *lio_dev)
1829 struct rte_pci_device *pdev = lio_dev->pci_dev;
1830 uint32_t dev_id = pdev->id.device_id;
1835 case LIO_CN23XX_VF_VID:
1836 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1837 ret = cn23xx_vf_setup_device(lio_dev);
1842 lio_dev_err(lio_dev, "Unsupported Chip\n");
1846 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1852 lio_first_time_init(struct lio_device *lio_dev,
1853 struct rte_pci_device *pdev)
1857 PMD_INIT_FUNC_TRACE();
1859 /* set dpdk specific pci device pointer */
1860 lio_dev->pci_dev = pdev;
1862 /* Identify the LIO type and set device ops */
1863 if (lio_chip_specific_setup(lio_dev)) {
1864 lio_dev_err(lio_dev, "Chip specific setup failed\n");
1868 /* Initialize soft command buffer pool */
1869 if (lio_setup_sc_buffer_pool(lio_dev)) {
1870 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
1874 /* Initialize lists to manage the requests of different types that
1875 * arrive from applications for this lio device.
1877 lio_setup_response_list(lio_dev);
1879 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
1880 lio_dev_err(lio_dev, "Mailbox setup failed\n");
1884 /* Check PF response */
1885 lio_check_pf_hs_response((void *)lio_dev);
1887 /* Do handshake and exit if incompatible PF driver */
1888 if (cn23xx_pfvf_handshake(lio_dev))
1892 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1893 /* Wait for FLR for 100ms per SRIOV specification */
1896 if (cn23xx_vf_set_io_queues_off(lio_dev)) {
1897 lio_dev_err(lio_dev, "Setting io queues off failed\n");
1901 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1902 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1906 if (lio_setup_instr_queue0(lio_dev)) {
1907 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
1911 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
1913 lio_dev->max_tx_queues = dpdk_queues;
1914 lio_dev->max_rx_queues = dpdk_queues;
1916 /* Enable input and output queues for this device */
1917 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1923 lio_free_sc_buffer_pool(lio_dev);
1924 if (lio_dev->mbox[0])
1925 lio_dev->fn_list.free_mbox(lio_dev);
1926 if (lio_dev->instr_queue[0])
1927 lio_free_instr_queue0(lio_dev);
1933 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1935 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1937 PMD_INIT_FUNC_TRACE();
1939 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1942 /* lio_free_sc_buffer_pool */
1943 lio_free_sc_buffer_pool(lio_dev);
1945 rte_free(eth_dev->data->mac_addrs);
1946 eth_dev->data->mac_addrs = NULL;
1948 eth_dev->dev_ops = NULL;
1949 eth_dev->rx_pkt_burst = NULL;
1950 eth_dev->tx_pkt_burst = NULL;
1956 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
1958 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
1959 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1961 PMD_INIT_FUNC_TRACE();
1963 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
1964 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
1966 /* Primary does the initialization. */
1967 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1970 rte_eth_copy_pci_info(eth_dev, pdev);
1971 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1973 if (pdev->mem_resource[0].addr) {
1974 lio_dev->hw_addr = pdev->mem_resource[0].addr;
1976 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
1980 lio_dev->eth_dev = eth_dev;
1981 /* set lio device print string */
1982 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
1983 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
1984 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1986 lio_dev->port_id = eth_dev->data->port_id;
1988 if (lio_first_time_init(lio_dev, pdev)) {
1989 lio_dev_err(lio_dev, "Device init failed\n");
1993 eth_dev->dev_ops = &liovf_eth_dev_ops;
1994 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
1995 if (eth_dev->data->mac_addrs == NULL) {
1996 lio_dev_err(lio_dev,
1997 "MAC addresses memory allocation failed\n");
1998 eth_dev->dev_ops = NULL;
1999 eth_dev->rx_pkt_burst = NULL;
2000 eth_dev->tx_pkt_burst = NULL;
2004 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
2007 lio_dev->port_configured = 0;
2008 /* Always allow unicast packets */
2009 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
2014 /* Set of PCI devices this driver supports */
2015 static const struct rte_pci_id pci_id_liovf_map[] = {
2016 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
2017 { .vendor_id = 0, /* sentinel */ }
2020 static struct eth_driver rte_liovf_pmd = {
2022 .id_table = pci_id_liovf_map,
2023 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
2024 .probe = rte_eth_dev_pci_probe,
2025 .remove = rte_eth_dev_pci_remove,
2027 .eth_dev_init = lio_eth_dev_init,
2028 .eth_dev_uninit = lio_eth_dev_uninit,
2029 .dev_private_size = sizeof(struct lio_device),
2032 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
2033 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
2034 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");