4 * Copyright(c) 2017 Cavium, Inc.. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Cavium, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_ethdev.h>
35 #include <rte_ethdev_pci.h>
36 #include <rte_cycles.h>
37 #include <rte_malloc.h>
38 #include <rte_alarm.h>
39 #include <rte_ether.h>
42 #include "lio_23xx_vf.h"
43 #include "lio_ethdev.h"
46 /* Default RSS key in use */
47 static uint8_t lio_rss_key[40] = {
48 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
49 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
50 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
51 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
52 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
55 static const struct rte_eth_desc_lim lio_rx_desc_lim = {
56 .nb_max = CN23XX_MAX_OQ_DESCRIPTORS,
57 .nb_min = CN23XX_MIN_OQ_DESCRIPTORS,
61 static const struct rte_eth_desc_lim lio_tx_desc_lim = {
62 .nb_max = CN23XX_MAX_IQ_DESCRIPTORS,
63 .nb_min = CN23XX_MIN_IQ_DESCRIPTORS,
67 /* Wait for control command to reach nic. */
69 lio_wait_for_ctrl_cmd(struct lio_device *lio_dev,
70 struct lio_dev_ctrl_cmd *ctrl_cmd)
72 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
74 while ((ctrl_cmd->cond == 0) && --timeout) {
75 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
83 * \brief Send Rx control command
84 * @param eth_dev Pointer to the structure rte_eth_dev
85 * @param start_stop whether to start or stop
88 lio_send_rx_ctrl_cmd(struct rte_eth_dev *eth_dev, int start_stop)
90 struct lio_device *lio_dev = LIO_DEV(eth_dev);
91 struct lio_dev_ctrl_cmd ctrl_cmd;
92 struct lio_ctrl_pkt ctrl_pkt;
94 /* flush added to prevent cmd failure
95 * incase the queue is full
97 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
99 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
100 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
102 ctrl_cmd.eth_dev = eth_dev;
105 ctrl_pkt.ncmd.s.cmd = LIO_CMD_RX_CTL;
106 ctrl_pkt.ncmd.s.param1 = start_stop;
107 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
109 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
110 lio_dev_err(lio_dev, "Failed to send RX Control message\n");
114 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
115 lio_dev_err(lio_dev, "RX Control command timed out\n");
122 /* store statistics names and its offset in stats structure */
123 struct rte_lio_xstats_name_off {
124 char name[RTE_ETH_XSTATS_NAME_SIZE];
128 static const struct rte_lio_xstats_name_off rte_lio_stats_strings[] = {
129 {"rx_pkts", offsetof(struct octeon_rx_stats, total_rcvd)},
130 {"rx_bytes", offsetof(struct octeon_rx_stats, bytes_rcvd)},
131 {"rx_broadcast_pkts", offsetof(struct octeon_rx_stats, total_bcst)},
132 {"rx_multicast_pkts", offsetof(struct octeon_rx_stats, total_mcst)},
133 {"rx_flow_ctrl_pkts", offsetof(struct octeon_rx_stats, ctl_rcvd)},
134 {"rx_fifo_err", offsetof(struct octeon_rx_stats, fifo_err)},
135 {"rx_dmac_drop", offsetof(struct octeon_rx_stats, dmac_drop)},
136 {"rx_fcs_err", offsetof(struct octeon_rx_stats, fcs_err)},
137 {"rx_jabber_err", offsetof(struct octeon_rx_stats, jabber_err)},
138 {"rx_l2_err", offsetof(struct octeon_rx_stats, l2_err)},
139 {"rx_vxlan_pkts", offsetof(struct octeon_rx_stats, fw_rx_vxlan)},
140 {"rx_vxlan_err", offsetof(struct octeon_rx_stats, fw_rx_vxlan_err)},
141 {"rx_lro_pkts", offsetof(struct octeon_rx_stats, fw_lro_pkts)},
142 {"tx_pkts", (offsetof(struct octeon_tx_stats, total_pkts_sent)) +
143 sizeof(struct octeon_rx_stats)},
144 {"tx_bytes", (offsetof(struct octeon_tx_stats, total_bytes_sent)) +
145 sizeof(struct octeon_rx_stats)},
146 {"tx_broadcast_pkts",
147 (offsetof(struct octeon_tx_stats, bcast_pkts_sent)) +
148 sizeof(struct octeon_rx_stats)},
149 {"tx_multicast_pkts",
150 (offsetof(struct octeon_tx_stats, mcast_pkts_sent)) +
151 sizeof(struct octeon_rx_stats)},
152 {"tx_flow_ctrl_pkts", (offsetof(struct octeon_tx_stats, ctl_sent)) +
153 sizeof(struct octeon_rx_stats)},
154 {"tx_fifo_err", (offsetof(struct octeon_tx_stats, fifo_err)) +
155 sizeof(struct octeon_rx_stats)},
156 {"tx_total_collisions", (offsetof(struct octeon_tx_stats,
158 sizeof(struct octeon_rx_stats)},
159 {"tx_tso", (offsetof(struct octeon_tx_stats, fw_tso)) +
160 sizeof(struct octeon_rx_stats)},
161 {"tx_vxlan_pkts", (offsetof(struct octeon_tx_stats, fw_tx_vxlan)) +
162 sizeof(struct octeon_rx_stats)},
165 #define LIO_NB_XSTATS RTE_DIM(rte_lio_stats_strings)
167 /* Get hw stats of the port */
169 lio_dev_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *xstats,
172 struct lio_device *lio_dev = LIO_DEV(eth_dev);
173 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
174 struct octeon_link_stats *hw_stats;
175 struct lio_link_stats_resp *resp;
176 struct lio_soft_command *sc;
181 if (!lio_dev->intf_open) {
182 lio_dev_err(lio_dev, "Port %d down\n",
187 if (n < LIO_NB_XSTATS)
188 return LIO_NB_XSTATS;
190 resp_size = sizeof(struct lio_link_stats_resp);
191 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
195 resp = (struct lio_link_stats_resp *)sc->virtrptr;
196 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
197 LIO_OPCODE_PORT_STATS, 0, 0, 0);
199 /* Setting wait time in seconds */
200 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
202 retval = lio_send_soft_command(lio_dev, sc);
203 if (retval == LIO_IQ_SEND_FAILED) {
204 lio_dev_err(lio_dev, "failed to get port stats from firmware. status: %x\n",
209 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
210 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
211 lio_process_ordered_list(lio_dev);
215 retval = resp->status;
217 lio_dev_err(lio_dev, "failed to get port stats from firmware\n");
221 lio_swap_8B_data((uint64_t *)(&resp->link_stats),
222 sizeof(struct octeon_link_stats) >> 3);
224 hw_stats = &resp->link_stats;
226 for (i = 0; i < LIO_NB_XSTATS; i++) {
229 *(uint64_t *)(((char *)hw_stats) +
230 rte_lio_stats_strings[i].offset);
233 lio_free_soft_command(sc);
235 return LIO_NB_XSTATS;
238 lio_free_soft_command(sc);
244 lio_dev_xstats_get_names(struct rte_eth_dev *eth_dev,
245 struct rte_eth_xstat_name *xstats_names,
246 unsigned limit __rte_unused)
248 struct lio_device *lio_dev = LIO_DEV(eth_dev);
251 if (!lio_dev->intf_open) {
252 lio_dev_err(lio_dev, "Port %d down\n",
257 if (xstats_names == NULL)
258 return LIO_NB_XSTATS;
260 /* Note: limit checked in rte_eth_xstats_names() */
262 for (i = 0; i < LIO_NB_XSTATS; i++) {
263 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
264 "%s", rte_lio_stats_strings[i].name);
267 return LIO_NB_XSTATS;
270 /* Reset hw stats for the port */
272 lio_dev_xstats_reset(struct rte_eth_dev *eth_dev)
274 struct lio_device *lio_dev = LIO_DEV(eth_dev);
275 struct lio_dev_ctrl_cmd ctrl_cmd;
276 struct lio_ctrl_pkt ctrl_pkt;
278 if (!lio_dev->intf_open) {
279 lio_dev_err(lio_dev, "Port %d down\n",
284 /* flush added to prevent cmd failure
285 * incase the queue is full
287 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
289 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
290 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
292 ctrl_cmd.eth_dev = eth_dev;
295 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CLEAR_STATS;
296 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
298 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
299 lio_dev_err(lio_dev, "Failed to send clear stats command\n");
303 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
304 lio_dev_err(lio_dev, "Clear stats command timed out\n");
308 /* clear stored per queue stats */
309 RTE_FUNC_PTR_OR_RET(*eth_dev->dev_ops->stats_reset);
310 (*eth_dev->dev_ops->stats_reset)(eth_dev);
313 /* Retrieve the device statistics (# packets in/out, # bytes in/out, etc */
315 lio_dev_stats_get(struct rte_eth_dev *eth_dev,
316 struct rte_eth_stats *stats)
318 struct lio_device *lio_dev = LIO_DEV(eth_dev);
319 struct lio_droq_stats *oq_stats;
320 struct lio_iq_stats *iq_stats;
321 struct lio_instr_queue *txq;
322 struct lio_droq *droq;
328 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
329 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
330 txq = lio_dev->instr_queue[iq_no];
332 iq_stats = &txq->stats;
333 pkts += iq_stats->tx_done;
334 drop += iq_stats->tx_dropped;
335 bytes += iq_stats->tx_tot_bytes;
339 stats->opackets = pkts;
340 stats->obytes = bytes;
341 stats->oerrors = drop;
347 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
348 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
349 droq = lio_dev->droq[oq_no];
351 oq_stats = &droq->stats;
352 pkts += oq_stats->rx_pkts_received;
353 drop += (oq_stats->rx_dropped +
354 oq_stats->dropped_toomany +
355 oq_stats->dropped_nomem);
356 bytes += oq_stats->rx_bytes_received;
359 stats->ibytes = bytes;
360 stats->ipackets = pkts;
361 stats->ierrors = drop;
365 lio_dev_stats_reset(struct rte_eth_dev *eth_dev)
367 struct lio_device *lio_dev = LIO_DEV(eth_dev);
368 struct lio_droq_stats *oq_stats;
369 struct lio_iq_stats *iq_stats;
370 struct lio_instr_queue *txq;
371 struct lio_droq *droq;
374 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
375 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
376 txq = lio_dev->instr_queue[iq_no];
378 iq_stats = &txq->stats;
379 memset(iq_stats, 0, sizeof(struct lio_iq_stats));
383 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
384 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
385 droq = lio_dev->droq[oq_no];
387 oq_stats = &droq->stats;
388 memset(oq_stats, 0, sizeof(struct lio_droq_stats));
394 lio_dev_info_get(struct rte_eth_dev *eth_dev,
395 struct rte_eth_dev_info *devinfo)
397 struct lio_device *lio_dev = LIO_DEV(eth_dev);
399 devinfo->max_rx_queues = lio_dev->max_rx_queues;
400 devinfo->max_tx_queues = lio_dev->max_tx_queues;
402 devinfo->min_rx_bufsize = LIO_MIN_RX_BUF_SIZE;
403 devinfo->max_rx_pktlen = LIO_MAX_RX_PKTLEN;
405 devinfo->max_mac_addrs = 1;
407 devinfo->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
408 DEV_RX_OFFLOAD_UDP_CKSUM |
409 DEV_RX_OFFLOAD_TCP_CKSUM |
410 DEV_RX_OFFLOAD_VLAN_STRIP);
411 devinfo->tx_offload_capa = (DEV_TX_OFFLOAD_IPV4_CKSUM |
412 DEV_TX_OFFLOAD_UDP_CKSUM |
413 DEV_TX_OFFLOAD_TCP_CKSUM |
414 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM);
416 devinfo->rx_desc_lim = lio_rx_desc_lim;
417 devinfo->tx_desc_lim = lio_tx_desc_lim;
419 devinfo->reta_size = LIO_RSS_MAX_TABLE_SZ;
420 devinfo->hash_key_size = LIO_RSS_MAX_KEY_SZ;
421 devinfo->flow_type_rss_offloads = (ETH_RSS_IPV4 |
422 ETH_RSS_NONFRAG_IPV4_TCP |
424 ETH_RSS_NONFRAG_IPV6_TCP |
426 ETH_RSS_IPV6_TCP_EX);
430 lio_dev_validate_vf_mtu(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
432 struct lio_device *lio_dev = LIO_DEV(eth_dev);
434 PMD_INIT_FUNC_TRACE();
436 if (!lio_dev->intf_open) {
437 lio_dev_err(lio_dev, "Port %d down, can't check MTU\n",
442 /* Limit the MTU to make sure the ethernet packets are between
443 * ETHER_MIN_MTU bytes and PF's MTU
445 if ((new_mtu < ETHER_MIN_MTU) ||
446 (new_mtu > lio_dev->linfo.link.s.mtu)) {
447 lio_dev_err(lio_dev, "Invalid MTU: %d\n", new_mtu);
448 lio_dev_err(lio_dev, "Valid range %d and %d\n",
449 ETHER_MIN_MTU, lio_dev->linfo.link.s.mtu);
457 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
458 struct rte_eth_rss_reta_entry64 *reta_conf,
461 struct lio_device *lio_dev = LIO_DEV(eth_dev);
462 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
463 struct lio_rss_set *rss_param;
464 struct lio_dev_ctrl_cmd ctrl_cmd;
465 struct lio_ctrl_pkt ctrl_pkt;
468 if (!lio_dev->intf_open) {
469 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
474 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
476 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
477 reta_size, LIO_RSS_MAX_TABLE_SZ);
481 /* flush added to prevent cmd failure
482 * incase the queue is full
484 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
486 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
487 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
489 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
491 ctrl_cmd.eth_dev = eth_dev;
494 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
495 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
496 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
498 rss_param->param.flags = 0xF;
499 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
500 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
502 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
503 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
504 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
505 index = (i * RTE_RETA_GROUP_SIZE) + j;
506 rss_state->itable[index] = reta_conf[i].reta[j];
511 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
512 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
514 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
516 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
517 lio_dev_err(lio_dev, "Failed to set rss hash\n");
521 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
522 lio_dev_err(lio_dev, "Set rss hash timed out\n");
530 lio_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
531 struct rte_eth_rss_reta_entry64 *reta_conf,
534 struct lio_device *lio_dev = LIO_DEV(eth_dev);
535 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
538 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
540 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
541 reta_size, LIO_RSS_MAX_TABLE_SZ);
545 num = reta_size / RTE_RETA_GROUP_SIZE;
547 for (i = 0; i < num; i++) {
548 memcpy(reta_conf->reta,
549 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
550 RTE_RETA_GROUP_SIZE);
558 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
559 struct rte_eth_rss_conf *rss_conf)
561 struct lio_device *lio_dev = LIO_DEV(eth_dev);
562 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
563 uint8_t *hash_key = NULL;
566 if (rss_state->hash_disable) {
567 lio_dev_info(lio_dev, "RSS disabled in nic\n");
568 rss_conf->rss_hf = 0;
573 hash_key = rss_conf->rss_key;
574 if (hash_key != NULL)
575 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
578 rss_hf |= ETH_RSS_IPV4;
579 if (rss_state->tcp_hash)
580 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
582 rss_hf |= ETH_RSS_IPV6;
583 if (rss_state->ipv6_tcp_hash)
584 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
585 if (rss_state->ipv6_ex)
586 rss_hf |= ETH_RSS_IPV6_EX;
587 if (rss_state->ipv6_tcp_ex_hash)
588 rss_hf |= ETH_RSS_IPV6_TCP_EX;
590 rss_conf->rss_hf = rss_hf;
596 lio_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
597 struct rte_eth_rss_conf *rss_conf)
599 struct lio_device *lio_dev = LIO_DEV(eth_dev);
600 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
601 struct lio_rss_set *rss_param;
602 struct lio_dev_ctrl_cmd ctrl_cmd;
603 struct lio_ctrl_pkt ctrl_pkt;
605 if (!lio_dev->intf_open) {
606 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
611 /* flush added to prevent cmd failure
612 * incase the queue is full
614 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
616 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
617 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
619 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
621 ctrl_cmd.eth_dev = eth_dev;
624 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
625 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
626 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
628 rss_param->param.flags = 0xF;
630 if (rss_conf->rss_key) {
631 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
632 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
633 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
634 memcpy(rss_state->hash_key, rss_conf->rss_key,
635 rss_state->hash_key_size);
636 memcpy(rss_param->key, rss_state->hash_key,
637 rss_state->hash_key_size);
640 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
641 /* Can't disable rss through hash flags,
642 * if it is enabled by default during init
644 if (!rss_state->hash_disable)
647 /* This is for --disable-rss during testpmd launch */
648 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
650 uint32_t hashinfo = 0;
652 /* Can't enable rss if disabled by default during init */
653 if (rss_state->hash_disable)
656 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
657 hashinfo |= LIO_RSS_HASH_IPV4;
663 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
664 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
665 rss_state->tcp_hash = 1;
667 rss_state->tcp_hash = 0;
670 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
671 hashinfo |= LIO_RSS_HASH_IPV6;
677 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
678 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
679 rss_state->ipv6_tcp_hash = 1;
681 rss_state->ipv6_tcp_hash = 0;
684 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
685 hashinfo |= LIO_RSS_HASH_IPV6_EX;
686 rss_state->ipv6_ex = 1;
688 rss_state->ipv6_ex = 0;
691 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
692 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
693 rss_state->ipv6_tcp_ex_hash = 1;
695 rss_state->ipv6_tcp_ex_hash = 0;
698 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
699 rss_param->param.hashinfo = hashinfo;
702 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
704 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
705 lio_dev_err(lio_dev, "Failed to set rss hash\n");
709 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
710 lio_dev_err(lio_dev, "Set rss hash timed out\n");
718 * Add vxlan dest udp port for an interface.
721 * Pointer to the structure rte_eth_dev
726 * On success return 0
727 * On failure return -1
730 lio_dev_udp_tunnel_add(struct rte_eth_dev *eth_dev,
731 struct rte_eth_udp_tunnel *udp_tnl)
733 struct lio_device *lio_dev = LIO_DEV(eth_dev);
734 struct lio_dev_ctrl_cmd ctrl_cmd;
735 struct lio_ctrl_pkt ctrl_pkt;
740 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
741 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
745 /* flush added to prevent cmd failure
746 * incase the queue is full
748 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
750 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
751 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
753 ctrl_cmd.eth_dev = eth_dev;
756 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
757 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
758 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_ADD;
759 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
761 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
762 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_ADD command\n");
766 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
767 lio_dev_err(lio_dev, "VXLAN_PORT_ADD command timed out\n");
775 * Remove vxlan dest udp port for an interface.
778 * Pointer to the structure rte_eth_dev
783 * On success return 0
784 * On failure return -1
787 lio_dev_udp_tunnel_del(struct rte_eth_dev *eth_dev,
788 struct rte_eth_udp_tunnel *udp_tnl)
790 struct lio_device *lio_dev = LIO_DEV(eth_dev);
791 struct lio_dev_ctrl_cmd ctrl_cmd;
792 struct lio_ctrl_pkt ctrl_pkt;
797 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
798 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
802 /* flush added to prevent cmd failure
803 * incase the queue is full
805 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
807 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
808 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
810 ctrl_cmd.eth_dev = eth_dev;
813 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
814 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
815 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_DEL;
816 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
818 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
819 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_DEL command\n");
823 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
824 lio_dev_err(lio_dev, "VXLAN_PORT_DEL command timed out\n");
832 lio_dev_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id, int on)
834 struct lio_device *lio_dev = LIO_DEV(eth_dev);
835 struct lio_dev_ctrl_cmd ctrl_cmd;
836 struct lio_ctrl_pkt ctrl_pkt;
838 if (lio_dev->linfo.vlan_is_admin_assigned)
841 /* flush added to prevent cmd failure
842 * incase the queue is full
844 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
846 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
847 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
849 ctrl_cmd.eth_dev = eth_dev;
852 ctrl_pkt.ncmd.s.cmd = on ?
853 LIO_CMD_ADD_VLAN_FILTER : LIO_CMD_DEL_VLAN_FILTER;
854 ctrl_pkt.ncmd.s.param1 = vlan_id;
855 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
857 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
858 lio_dev_err(lio_dev, "Failed to %s VLAN port\n",
859 on ? "add" : "remove");
863 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
864 lio_dev_err(lio_dev, "Command to %s VLAN port timed out\n",
865 on ? "add" : "remove");
873 * Atomically writes the link status information into global
874 * structure rte_eth_dev.
877 * - Pointer to the structure rte_eth_dev to read from.
878 * - Pointer to the buffer to be saved with the link status.
881 * - On success, zero.
882 * - On failure, negative value.
885 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
886 struct rte_eth_link *link)
888 struct rte_eth_link *dst = ð_dev->data->dev_link;
889 struct rte_eth_link *src = link;
891 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
892 *(uint64_t *)src) == 0)
899 lio_hweight64(uint64_t w)
901 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
904 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
905 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
906 res = res + (res >> 8);
907 res = res + (res >> 16);
909 return (res + (res >> 32)) & 0x00000000000000FFul;
913 lio_dev_link_update(struct rte_eth_dev *eth_dev,
914 int wait_to_complete __rte_unused)
916 struct lio_device *lio_dev = LIO_DEV(eth_dev);
917 struct rte_eth_link link, old;
920 link.link_status = ETH_LINK_DOWN;
921 link.link_speed = ETH_SPEED_NUM_NONE;
922 link.link_duplex = ETH_LINK_HALF_DUPLEX;
923 memset(&old, 0, sizeof(old));
925 /* Return what we found */
926 if (lio_dev->linfo.link.s.link_up == 0) {
927 /* Interface is down */
928 if (lio_dev_atomic_write_link_status(eth_dev, &link))
930 if (link.link_status == old.link_status)
935 link.link_status = ETH_LINK_UP; /* Interface is up */
936 link.link_duplex = ETH_LINK_FULL_DUPLEX;
937 switch (lio_dev->linfo.link.s.speed) {
938 case LIO_LINK_SPEED_10000:
939 link.link_speed = ETH_SPEED_NUM_10G;
941 case LIO_LINK_SPEED_25000:
942 link.link_speed = ETH_SPEED_NUM_25G;
945 link.link_speed = ETH_SPEED_NUM_NONE;
946 link.link_duplex = ETH_LINK_HALF_DUPLEX;
949 if (lio_dev_atomic_write_link_status(eth_dev, &link))
952 if (link.link_status == old.link_status)
959 * \brief Net device enable, disable allmulticast
960 * @param eth_dev Pointer to the structure rte_eth_dev
963 lio_change_dev_flag(struct rte_eth_dev *eth_dev)
965 struct lio_device *lio_dev = LIO_DEV(eth_dev);
966 struct lio_dev_ctrl_cmd ctrl_cmd;
967 struct lio_ctrl_pkt ctrl_pkt;
969 /* flush added to prevent cmd failure
970 * incase the queue is full
972 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
974 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
975 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
977 ctrl_cmd.eth_dev = eth_dev;
980 /* Create a ctrl pkt command to be sent to core app. */
981 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CHANGE_DEVFLAGS;
982 ctrl_pkt.ncmd.s.param1 = lio_dev->ifflags;
983 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
985 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
986 lio_dev_err(lio_dev, "Failed to send change flag message\n");
990 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
991 lio_dev_err(lio_dev, "Change dev flag command timed out\n");
995 lio_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
997 struct lio_device *lio_dev = LIO_DEV(eth_dev);
999 if (!lio_dev->intf_open) {
1000 lio_dev_err(lio_dev, "Port %d down, can't enable multicast\n",
1005 lio_dev->ifflags |= LIO_IFFLAG_ALLMULTI;
1006 lio_change_dev_flag(eth_dev);
1010 lio_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
1012 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1014 if (!lio_dev->intf_open) {
1015 lio_dev_err(lio_dev, "Port %d down, can't disable multicast\n",
1020 lio_dev->ifflags &= ~LIO_IFFLAG_ALLMULTI;
1021 lio_change_dev_flag(eth_dev);
1025 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
1027 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1028 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1029 struct rte_eth_rss_reta_entry64 reta_conf[8];
1030 struct rte_eth_rss_conf rss_conf;
1033 /* Configure the RSS key and the RSS protocols used to compute
1034 * the RSS hash of input packets.
1036 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
1037 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
1038 rss_state->hash_disable = 1;
1039 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1043 if (rss_conf.rss_key == NULL)
1044 rss_conf.rss_key = lio_rss_key; /* Default hash key */
1046 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1048 memset(reta_conf, 0, sizeof(reta_conf));
1049 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
1050 uint8_t q_idx, conf_idx, reta_idx;
1052 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
1053 i % eth_dev->data->nb_rx_queues : 0);
1054 conf_idx = i / RTE_RETA_GROUP_SIZE;
1055 reta_idx = i % RTE_RETA_GROUP_SIZE;
1056 reta_conf[conf_idx].reta[reta_idx] = q_idx;
1057 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
1060 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
1064 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
1066 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1067 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
1068 struct rte_eth_rss_conf rss_conf;
1070 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
1072 lio_dev_rss_configure(eth_dev);
1074 case ETH_MQ_RX_NONE:
1075 /* if mq_mode is none, disable rss mode. */
1077 memset(&rss_conf, 0, sizeof(rss_conf));
1078 rss_state->hash_disable = 1;
1079 lio_dev_rss_hash_update(eth_dev, &rss_conf);
1084 * Setup our receive queue/ringbuffer. This is the
1085 * queue the Octeon uses to send us packets and
1086 * responses. We are given a memory pool for our
1087 * packet buffers that are used to populate the receive
1091 * Pointer to the structure rte_eth_dev
1094 * @param num_rx_descs
1095 * Number of entries in the queue
1097 * Where to allocate memory
1099 * Pointer to the struction rte_eth_rxconf
1101 * Pointer to the packet pool
1104 * - On success, return 0
1105 * - On failure, return -1
1108 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1109 uint16_t num_rx_descs, unsigned int socket_id,
1110 const struct rte_eth_rxconf *rx_conf __rte_unused,
1111 struct rte_mempool *mp)
1113 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1114 struct rte_pktmbuf_pool_private *mbp_priv;
1115 uint32_t fw_mapped_oq;
1118 if (q_no >= lio_dev->nb_rx_queues) {
1119 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
1123 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
1125 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
1127 if ((lio_dev->droq[fw_mapped_oq]) &&
1128 (num_rx_descs != lio_dev->droq[fw_mapped_oq]->max_count)) {
1129 lio_dev_err(lio_dev,
1130 "Reconfiguring Rx descs not supported. Configure descs to same value %u or restart application\n",
1131 lio_dev->droq[fw_mapped_oq]->max_count);
1135 mbp_priv = rte_mempool_get_priv(mp);
1136 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
1138 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
1140 lio_dev_err(lio_dev, "droq allocation failed\n");
1144 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
1150 * Release the receive queue/ringbuffer. Called by
1154 * Opaque pointer to the receive queue to release
1160 lio_dev_rx_queue_release(void *rxq)
1162 struct lio_droq *droq = rxq;
1166 /* Run time queue deletion not supported */
1167 if (droq->lio_dev->port_configured)
1171 lio_delete_droq_queue(droq->lio_dev, oq_no);
1176 * Allocate and initialize SW ring. Initialize associated HW registers.
1179 * Pointer to structure rte_eth_dev
1184 * @param num_tx_descs
1185 * Number of ringbuffer descriptors
1188 * NUMA socket id, used for memory allocations
1191 * Pointer to the structure rte_eth_txconf
1194 * - On success, return 0
1195 * - On failure, return -errno value
1198 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
1199 uint16_t num_tx_descs, unsigned int socket_id,
1200 const struct rte_eth_txconf *tx_conf __rte_unused)
1202 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1203 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
1206 if (q_no >= lio_dev->nb_tx_queues) {
1207 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
1211 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
1213 if ((lio_dev->instr_queue[fw_mapped_iq] != NULL) &&
1214 (num_tx_descs != lio_dev->instr_queue[fw_mapped_iq]->max_count)) {
1215 lio_dev_err(lio_dev,
1216 "Reconfiguring Tx descs not supported. Configure descs to same value %u or restart application\n",
1217 lio_dev->instr_queue[fw_mapped_iq]->max_count);
1221 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
1222 num_tx_descs, lio_dev, socket_id);
1225 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
1229 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
1230 lio_dev->instr_queue[fw_mapped_iq]->max_count,
1234 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
1238 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
1244 * Release the transmit queue/ringbuffer. Called by
1248 * Opaque pointer to the transmit queue to release
1254 lio_dev_tx_queue_release(void *txq)
1256 struct lio_instr_queue *tq = txq;
1257 uint32_t fw_mapped_iq_no;
1261 /* Run time queue deletion not supported */
1262 if (tq->lio_dev->port_configured)
1266 lio_delete_sglist(tq);
1268 fw_mapped_iq_no = tq->txpciq.s.q_no;
1269 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
1274 * Api to check link state.
1277 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
1279 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1280 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1281 struct lio_link_status_resp *resp;
1282 union octeon_link_status *ls;
1283 struct lio_soft_command *sc;
1286 if (!lio_dev->intf_open)
1289 resp_size = sizeof(struct lio_link_status_resp);
1290 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1294 resp = (struct lio_link_status_resp *)sc->virtrptr;
1295 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1296 LIO_OPCODE_INFO, 0, 0, 0);
1298 /* Setting wait time in seconds */
1299 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1301 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
1302 goto get_status_fail;
1304 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1305 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1310 goto get_status_fail;
1312 ls = &resp->link_info.link;
1314 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
1316 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
1317 lio_dev->linfo.link.link_status64 = ls->link_status64;
1318 lio_dev_link_update(eth_dev, 0);
1321 lio_free_soft_command(sc);
1326 lio_free_soft_command(sc);
1329 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
1330 * and will update link state if it changes.
1333 lio_sync_link_state_check(void *eth_dev)
1335 struct lio_device *lio_dev =
1336 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
1338 if (lio_dev->port_configured)
1339 lio_dev_get_link_status(eth_dev);
1341 /* Schedule periodic link status check.
1342 * Stop check if interface is close and start again while opening.
1344 if (lio_dev->intf_open)
1345 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
1350 lio_dev_start(struct rte_eth_dev *eth_dev)
1353 uint32_t frame_len = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
1354 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1355 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1358 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
1360 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1363 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
1366 /* Ready for link status updates */
1367 lio_dev->intf_open = 1;
1370 /* Configure RSS if device configured with multiple RX queues. */
1371 lio_dev_mq_rx_configure(eth_dev);
1373 /* start polling for lsc */
1374 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
1375 lio_sync_link_state_check,
1378 lio_dev_err(lio_dev,
1379 "link state check handler creation failed\n");
1380 goto dev_lsc_handle_error;
1383 while ((lio_dev->linfo.link.link_status64 == 0) && (--timeout))
1386 if (lio_dev->linfo.link.link_status64 == 0) {
1388 goto dev_mtu_check_error;
1391 if (eth_dev->data->dev_conf.rxmode.jumbo_frame == 1) {
1392 if (frame_len <= ETHER_MAX_LEN ||
1393 frame_len > LIO_MAX_RX_PKTLEN) {
1394 lio_dev_err(lio_dev, "max packet length should be >= %d and < %d when jumbo frame is enabled\n",
1395 ETHER_MAX_LEN, LIO_MAX_RX_PKTLEN);
1397 goto dev_mtu_check_error;
1399 mtu = (uint16_t)(frame_len - ETHER_HDR_LEN - ETHER_CRC_LEN);
1403 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len = ETHER_MAX_LEN;
1406 if (lio_dev->linfo.link.s.mtu != mtu) {
1407 ret = lio_dev_validate_vf_mtu(eth_dev, mtu);
1409 goto dev_mtu_check_error;
1412 eth_dev->data->mtu = mtu;
1416 dev_mtu_check_error:
1417 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1419 dev_lsc_handle_error:
1420 lio_dev->intf_open = 0;
1421 lio_send_rx_ctrl_cmd(eth_dev, 0);
1426 /* Stop device and disable input/output functions */
1428 lio_dev_stop(struct rte_eth_dev *eth_dev)
1430 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1432 lio_dev_info(lio_dev, "Stopping port %d\n", eth_dev->data->port_id);
1433 lio_dev->intf_open = 0;
1436 /* Cancel callback if still running. */
1437 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1439 lio_send_rx_ctrl_cmd(eth_dev, 0);
1441 /* Clear recorded link status */
1442 lio_dev->linfo.link.link_status64 = 0;
1446 lio_dev_set_link_up(struct rte_eth_dev *eth_dev)
1448 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1450 if (!lio_dev->intf_open) {
1451 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1455 if (lio_dev->linfo.link.s.link_up) {
1456 lio_dev_info(lio_dev, "Link is already UP\n");
1460 if (lio_send_rx_ctrl_cmd(eth_dev, 1)) {
1461 lio_dev_err(lio_dev, "Unable to set Link UP\n");
1465 lio_dev->linfo.link.s.link_up = 1;
1466 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1472 lio_dev_set_link_down(struct rte_eth_dev *eth_dev)
1474 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1476 if (!lio_dev->intf_open) {
1477 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1481 if (!lio_dev->linfo.link.s.link_up) {
1482 lio_dev_info(lio_dev, "Link is already DOWN\n");
1486 lio_dev->linfo.link.s.link_up = 0;
1487 eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
1489 if (lio_send_rx_ctrl_cmd(eth_dev, 0)) {
1490 lio_dev->linfo.link.s.link_up = 1;
1491 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1492 lio_dev_err(lio_dev, "Unable to set Link Down\n");
1500 * Reset and stop the device. This occurs on the first
1501 * call to this routine. Subsequent calls will simply
1502 * return. NB: This will require the NIC to be rebooted.
1505 * Pointer to the structure rte_eth_dev
1511 lio_dev_close(struct rte_eth_dev *eth_dev)
1513 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1516 lio_dev_info(lio_dev, "closing port %d\n", eth_dev->data->port_id);
1518 if (lio_dev->intf_open)
1519 lio_dev_stop(eth_dev);
1521 lio_wait_for_instr_fetch(lio_dev);
1523 lio_dev->fn_list.disable_io_queues(lio_dev);
1525 cn23xx_vf_set_io_queues_off(lio_dev);
1527 /* Reset iq regs (IQ_DBELL).
1528 * Clear sli_pktx_cnts (OQ_PKTS_SENT).
1530 for (i = 0; i < lio_dev->nb_rx_queues; i++) {
1531 struct lio_droq *droq = lio_dev->droq[i];
1536 uint32_t pkt_count = rte_read32(droq->pkts_sent_reg);
1538 lio_dev_dbg(lio_dev,
1539 "pending oq count %u\n", pkt_count);
1540 rte_write32(pkt_count, droq->pkts_sent_reg);
1543 /* Do FLR for the VF */
1544 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1547 lio_dev->fn_list.free_mbox(lio_dev);
1549 /* Free glist resources */
1550 rte_free(lio_dev->glist_head);
1551 rte_free(lio_dev->glist_lock);
1552 lio_dev->glist_head = NULL;
1553 lio_dev->glist_lock = NULL;
1555 lio_dev->port_configured = 0;
1557 /* Delete all queues */
1558 lio_dev_clear_queues(eth_dev);
1562 * Enable tunnel rx checksum verification from firmware.
1565 lio_enable_hw_tunnel_rx_checksum(struct rte_eth_dev *eth_dev)
1567 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1568 struct lio_dev_ctrl_cmd ctrl_cmd;
1569 struct lio_ctrl_pkt ctrl_pkt;
1571 /* flush added to prevent cmd failure
1572 * incase the queue is full
1574 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1576 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1577 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1579 ctrl_cmd.eth_dev = eth_dev;
1582 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_RX_CSUM_CTL;
1583 ctrl_pkt.ncmd.s.param1 = LIO_CMD_RXCSUM_ENABLE;
1584 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1586 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1587 lio_dev_err(lio_dev, "Failed to send TNL_RX_CSUM command\n");
1591 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1592 lio_dev_err(lio_dev, "TNL_RX_CSUM command timed out\n");
1596 * Enable checksum calculation for inner packet in a tunnel.
1599 lio_enable_hw_tunnel_tx_checksum(struct rte_eth_dev *eth_dev)
1601 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1602 struct lio_dev_ctrl_cmd ctrl_cmd;
1603 struct lio_ctrl_pkt ctrl_pkt;
1605 /* flush added to prevent cmd failure
1606 * incase the queue is full
1608 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1610 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1611 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1613 ctrl_cmd.eth_dev = eth_dev;
1616 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_TX_CSUM_CTL;
1617 ctrl_pkt.ncmd.s.param1 = LIO_CMD_TXCSUM_ENABLE;
1618 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1620 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1621 lio_dev_err(lio_dev, "Failed to send TNL_TX_CSUM command\n");
1625 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1626 lio_dev_err(lio_dev, "TNL_TX_CSUM command timed out\n");
1629 static int lio_dev_configure(struct rte_eth_dev *eth_dev)
1631 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1632 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1633 int retval, num_iqueues, num_oqueues;
1634 uint8_t mac[ETHER_ADDR_LEN], i;
1635 struct lio_if_cfg_resp *resp;
1636 struct lio_soft_command *sc;
1637 union lio_if_cfg if_cfg;
1640 PMD_INIT_FUNC_TRACE();
1642 /* Re-configuring firmware not supported.
1643 * Can't change tx/rx queues per port from initial value.
1645 if (lio_dev->port_configured) {
1646 if ((lio_dev->nb_rx_queues != eth_dev->data->nb_rx_queues) ||
1647 (lio_dev->nb_tx_queues != eth_dev->data->nb_tx_queues)) {
1648 lio_dev_err(lio_dev,
1649 "rxq/txq re-conf not supported. Restart application with new value.\n");
1655 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
1656 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
1658 resp_size = sizeof(struct lio_if_cfg_resp);
1659 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1663 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
1665 /* Firmware doesn't have capability to reconfigure the queues,
1666 * Claim all queues, and use as many required
1668 if_cfg.if_cfg64 = 0;
1669 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
1670 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
1671 if_cfg.s.base_queue = 0;
1673 if_cfg.s.gmx_port_id = lio_dev->pf_num;
1675 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1676 LIO_OPCODE_IF_CFG, 0,
1677 if_cfg.if_cfg64, 0);
1679 /* Setting wait time in seconds */
1680 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1682 retval = lio_send_soft_command(lio_dev, sc);
1683 if (retval == LIO_IQ_SEND_FAILED) {
1684 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
1686 /* Soft instr is freed by driver in case of failure. */
1687 goto nic_config_fail;
1690 /* Sleep on a wait queue till the cond flag indicates that the
1691 * response arrived or timed-out.
1693 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1694 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1695 lio_process_ordered_list(lio_dev);
1699 retval = resp->status;
1701 lio_dev_err(lio_dev, "iq/oq config failed\n");
1702 goto nic_config_fail;
1705 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
1706 sizeof(struct octeon_if_cfg_info) >> 3);
1708 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
1709 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
1711 if (!(num_iqueues) || !(num_oqueues)) {
1712 lio_dev_err(lio_dev,
1713 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
1714 (unsigned long)resp->cfg_info.iqmask,
1715 (unsigned long)resp->cfg_info.oqmask);
1716 goto nic_config_fail;
1719 lio_dev_dbg(lio_dev,
1720 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
1721 eth_dev->data->port_id,
1722 (unsigned long)resp->cfg_info.iqmask,
1723 (unsigned long)resp->cfg_info.oqmask,
1724 num_iqueues, num_oqueues);
1726 lio_dev->linfo.num_rxpciq = num_oqueues;
1727 lio_dev->linfo.num_txpciq = num_iqueues;
1729 for (i = 0; i < num_oqueues; i++) {
1730 lio_dev->linfo.rxpciq[i].rxpciq64 =
1731 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
1732 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
1733 i, lio_dev->linfo.rxpciq[i].s.q_no);
1736 for (i = 0; i < num_iqueues; i++) {
1737 lio_dev->linfo.txpciq[i].txpciq64 =
1738 resp->cfg_info.linfo.txpciq[i].txpciq64;
1739 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
1740 i, lio_dev->linfo.txpciq[i].s.q_no);
1743 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1744 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1745 lio_dev->linfo.link.link_status64 =
1746 resp->cfg_info.linfo.link.link_status64;
1748 /* 64-bit swap required on LE machines */
1749 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
1750 for (i = 0; i < ETHER_ADDR_LEN; i++)
1751 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
1754 /* Copy the permanent MAC address */
1755 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
1757 /* enable firmware checksum support for tunnel packets */
1758 lio_enable_hw_tunnel_rx_checksum(eth_dev);
1759 lio_enable_hw_tunnel_tx_checksum(eth_dev);
1761 lio_dev->glist_lock =
1762 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
1763 if (lio_dev->glist_lock == NULL)
1766 lio_dev->glist_head =
1767 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
1769 if (lio_dev->glist_head == NULL) {
1770 rte_free(lio_dev->glist_lock);
1771 lio_dev->glist_lock = NULL;
1775 lio_dev_link_update(eth_dev, 0);
1777 lio_dev->port_configured = 1;
1779 lio_free_soft_command(sc);
1781 /* Disable iq_0 for reconf */
1782 lio_dev->fn_list.disable_io_queues(lio_dev);
1784 /* Reset ioq regs */
1785 lio_dev->fn_list.setup_device_regs(lio_dev);
1787 /* Free iq_0 used during init */
1788 lio_free_instr_queue0(lio_dev);
1793 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
1794 lio_free_soft_command(sc);
1795 lio_free_instr_queue0(lio_dev);
1800 /* Define our ethernet definitions */
1801 static const struct eth_dev_ops liovf_eth_dev_ops = {
1802 .dev_configure = lio_dev_configure,
1803 .dev_start = lio_dev_start,
1804 .dev_stop = lio_dev_stop,
1805 .dev_set_link_up = lio_dev_set_link_up,
1806 .dev_set_link_down = lio_dev_set_link_down,
1807 .dev_close = lio_dev_close,
1808 .allmulticast_enable = lio_dev_allmulticast_enable,
1809 .allmulticast_disable = lio_dev_allmulticast_disable,
1810 .link_update = lio_dev_link_update,
1811 .stats_get = lio_dev_stats_get,
1812 .xstats_get = lio_dev_xstats_get,
1813 .xstats_get_names = lio_dev_xstats_get_names,
1814 .stats_reset = lio_dev_stats_reset,
1815 .xstats_reset = lio_dev_xstats_reset,
1816 .dev_infos_get = lio_dev_info_get,
1817 .vlan_filter_set = lio_dev_vlan_filter_set,
1818 .rx_queue_setup = lio_dev_rx_queue_setup,
1819 .rx_queue_release = lio_dev_rx_queue_release,
1820 .tx_queue_setup = lio_dev_tx_queue_setup,
1821 .tx_queue_release = lio_dev_tx_queue_release,
1822 .reta_update = lio_dev_rss_reta_update,
1823 .reta_query = lio_dev_rss_reta_query,
1824 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
1825 .rss_hash_update = lio_dev_rss_hash_update,
1826 .udp_tunnel_port_add = lio_dev_udp_tunnel_add,
1827 .udp_tunnel_port_del = lio_dev_udp_tunnel_del,
1831 lio_check_pf_hs_response(void *lio_dev)
1833 struct lio_device *dev = lio_dev;
1835 /* check till response arrives */
1836 if (dev->pfvf_hsword.coproc_tics_per_us)
1839 cn23xx_vf_handle_mbox(dev);
1841 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1845 * \brief Identify the LIO device and to map the BAR address space
1846 * @param lio_dev lio device
1849 lio_chip_specific_setup(struct lio_device *lio_dev)
1851 struct rte_pci_device *pdev = lio_dev->pci_dev;
1852 uint32_t dev_id = pdev->id.device_id;
1857 case LIO_CN23XX_VF_VID:
1858 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1859 ret = cn23xx_vf_setup_device(lio_dev);
1864 lio_dev_err(lio_dev, "Unsupported Chip\n");
1868 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1874 lio_first_time_init(struct lio_device *lio_dev,
1875 struct rte_pci_device *pdev)
1879 PMD_INIT_FUNC_TRACE();
1881 /* set dpdk specific pci device pointer */
1882 lio_dev->pci_dev = pdev;
1884 /* Identify the LIO type and set device ops */
1885 if (lio_chip_specific_setup(lio_dev)) {
1886 lio_dev_err(lio_dev, "Chip specific setup failed\n");
1890 /* Initialize soft command buffer pool */
1891 if (lio_setup_sc_buffer_pool(lio_dev)) {
1892 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
1896 /* Initialize lists to manage the requests of different types that
1897 * arrive from applications for this lio device.
1899 lio_setup_response_list(lio_dev);
1901 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
1902 lio_dev_err(lio_dev, "Mailbox setup failed\n");
1906 /* Check PF response */
1907 lio_check_pf_hs_response((void *)lio_dev);
1909 /* Do handshake and exit if incompatible PF driver */
1910 if (cn23xx_pfvf_handshake(lio_dev))
1914 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1915 /* Wait for FLR for 100ms per SRIOV specification */
1918 if (cn23xx_vf_set_io_queues_off(lio_dev)) {
1919 lio_dev_err(lio_dev, "Setting io queues off failed\n");
1923 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1924 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1928 if (lio_setup_instr_queue0(lio_dev)) {
1929 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
1933 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
1935 lio_dev->max_tx_queues = dpdk_queues;
1936 lio_dev->max_rx_queues = dpdk_queues;
1938 /* Enable input and output queues for this device */
1939 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1945 lio_free_sc_buffer_pool(lio_dev);
1946 if (lio_dev->mbox[0])
1947 lio_dev->fn_list.free_mbox(lio_dev);
1948 if (lio_dev->instr_queue[0])
1949 lio_free_instr_queue0(lio_dev);
1955 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1957 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1959 PMD_INIT_FUNC_TRACE();
1961 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1964 /* lio_free_sc_buffer_pool */
1965 lio_free_sc_buffer_pool(lio_dev);
1967 rte_free(eth_dev->data->mac_addrs);
1968 eth_dev->data->mac_addrs = NULL;
1970 eth_dev->dev_ops = NULL;
1971 eth_dev->rx_pkt_burst = NULL;
1972 eth_dev->tx_pkt_burst = NULL;
1978 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
1980 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
1981 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1983 PMD_INIT_FUNC_TRACE();
1985 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
1986 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
1988 /* Primary does the initialization. */
1989 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1992 rte_eth_copy_pci_info(eth_dev, pdev);
1993 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1995 if (pdev->mem_resource[0].addr) {
1996 lio_dev->hw_addr = pdev->mem_resource[0].addr;
1998 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
2002 lio_dev->eth_dev = eth_dev;
2003 /* set lio device print string */
2004 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
2005 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
2006 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
2008 lio_dev->port_id = eth_dev->data->port_id;
2010 if (lio_first_time_init(lio_dev, pdev)) {
2011 lio_dev_err(lio_dev, "Device init failed\n");
2015 eth_dev->dev_ops = &liovf_eth_dev_ops;
2016 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
2017 if (eth_dev->data->mac_addrs == NULL) {
2018 lio_dev_err(lio_dev,
2019 "MAC addresses memory allocation failed\n");
2020 eth_dev->dev_ops = NULL;
2021 eth_dev->rx_pkt_burst = NULL;
2022 eth_dev->tx_pkt_burst = NULL;
2026 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
2029 lio_dev->port_configured = 0;
2030 /* Always allow unicast packets */
2031 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
2037 lio_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2038 struct rte_pci_device *pci_dev)
2040 struct rte_eth_dev *eth_dev;
2043 eth_dev = rte_eth_dev_pci_allocate(pci_dev,
2044 sizeof(struct lio_device));
2045 if (eth_dev == NULL)
2048 ret = lio_eth_dev_init(eth_dev);
2050 rte_eth_dev_pci_release(eth_dev);
2056 lio_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
2058 return rte_eth_dev_pci_generic_remove(pci_dev,
2059 lio_eth_dev_uninit);
2062 /* Set of PCI devices this driver supports */
2063 static const struct rte_pci_id pci_id_liovf_map[] = {
2064 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
2065 { .vendor_id = 0, /* sentinel */ }
2068 static struct rte_pci_driver rte_liovf_pmd = {
2069 .id_table = pci_id_liovf_map,
2070 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
2071 .probe = lio_eth_dev_pci_probe,
2072 .remove = lio_eth_dev_pci_remove,
2075 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd);
2076 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
2077 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio-pci");