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 /* Retrieve the device statistics (# packets in/out, # bytes in/out, etc */
122 lio_dev_stats_get(struct rte_eth_dev *eth_dev,
123 struct rte_eth_stats *stats)
125 struct lio_device *lio_dev = LIO_DEV(eth_dev);
126 struct lio_droq_stats *oq_stats;
127 struct lio_iq_stats *iq_stats;
128 struct lio_instr_queue *txq;
129 struct lio_droq *droq;
135 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
136 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
137 txq = lio_dev->instr_queue[iq_no];
139 iq_stats = &txq->stats;
140 pkts += iq_stats->tx_done;
141 drop += iq_stats->tx_dropped;
142 bytes += iq_stats->tx_tot_bytes;
146 stats->opackets = pkts;
147 stats->obytes = bytes;
148 stats->oerrors = drop;
154 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
155 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
156 droq = lio_dev->droq[oq_no];
158 oq_stats = &droq->stats;
159 pkts += oq_stats->rx_pkts_received;
160 drop += (oq_stats->rx_dropped +
161 oq_stats->dropped_toomany +
162 oq_stats->dropped_nomem);
163 bytes += oq_stats->rx_bytes_received;
166 stats->ibytes = bytes;
167 stats->ipackets = pkts;
168 stats->ierrors = drop;
172 lio_dev_stats_reset(struct rte_eth_dev *eth_dev)
174 struct lio_device *lio_dev = LIO_DEV(eth_dev);
175 struct lio_droq_stats *oq_stats;
176 struct lio_iq_stats *iq_stats;
177 struct lio_instr_queue *txq;
178 struct lio_droq *droq;
181 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
182 iq_no = lio_dev->linfo.txpciq[i].s.q_no;
183 txq = lio_dev->instr_queue[iq_no];
185 iq_stats = &txq->stats;
186 memset(iq_stats, 0, sizeof(struct lio_iq_stats));
190 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
191 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
192 droq = lio_dev->droq[oq_no];
194 oq_stats = &droq->stats;
195 memset(oq_stats, 0, sizeof(struct lio_droq_stats));
201 lio_dev_info_get(struct rte_eth_dev *eth_dev,
202 struct rte_eth_dev_info *devinfo)
204 struct lio_device *lio_dev = LIO_DEV(eth_dev);
206 devinfo->max_rx_queues = lio_dev->max_rx_queues;
207 devinfo->max_tx_queues = lio_dev->max_tx_queues;
209 devinfo->min_rx_bufsize = LIO_MIN_RX_BUF_SIZE;
210 devinfo->max_rx_pktlen = LIO_MAX_RX_PKTLEN;
212 devinfo->max_mac_addrs = 1;
214 devinfo->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
215 DEV_RX_OFFLOAD_UDP_CKSUM |
216 DEV_RX_OFFLOAD_TCP_CKSUM);
217 devinfo->tx_offload_capa = (DEV_TX_OFFLOAD_IPV4_CKSUM |
218 DEV_TX_OFFLOAD_UDP_CKSUM |
219 DEV_TX_OFFLOAD_TCP_CKSUM |
220 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM);
222 devinfo->rx_desc_lim = lio_rx_desc_lim;
223 devinfo->tx_desc_lim = lio_tx_desc_lim;
225 devinfo->reta_size = LIO_RSS_MAX_TABLE_SZ;
226 devinfo->hash_key_size = LIO_RSS_MAX_KEY_SZ;
227 devinfo->flow_type_rss_offloads = (ETH_RSS_IPV4 |
228 ETH_RSS_NONFRAG_IPV4_TCP |
230 ETH_RSS_NONFRAG_IPV6_TCP |
232 ETH_RSS_IPV6_TCP_EX);
236 lio_dev_validate_vf_mtu(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
238 struct lio_device *lio_dev = LIO_DEV(eth_dev);
240 PMD_INIT_FUNC_TRACE();
242 if (!lio_dev->intf_open) {
243 lio_dev_err(lio_dev, "Port %d down, can't check MTU\n",
248 /* Limit the MTU to make sure the ethernet packets are between
249 * ETHER_MIN_MTU bytes and PF's MTU
251 if ((new_mtu < ETHER_MIN_MTU) ||
252 (new_mtu > lio_dev->linfo.link.s.mtu)) {
253 lio_dev_err(lio_dev, "Invalid MTU: %d\n", new_mtu);
254 lio_dev_err(lio_dev, "Valid range %d and %d\n",
255 ETHER_MIN_MTU, lio_dev->linfo.link.s.mtu);
263 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
264 struct rte_eth_rss_reta_entry64 *reta_conf,
267 struct lio_device *lio_dev = LIO_DEV(eth_dev);
268 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
269 struct lio_rss_set *rss_param;
270 struct lio_dev_ctrl_cmd ctrl_cmd;
271 struct lio_ctrl_pkt ctrl_pkt;
274 if (!lio_dev->intf_open) {
275 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
280 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
282 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
283 reta_size, LIO_RSS_MAX_TABLE_SZ);
287 /* flush added to prevent cmd failure
288 * incase the queue is full
290 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
292 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
293 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
295 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
297 ctrl_cmd.eth_dev = eth_dev;
300 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
301 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
302 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
304 rss_param->param.flags = 0xF;
305 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
306 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
308 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
309 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
310 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
311 index = (i * RTE_RETA_GROUP_SIZE) + j;
312 rss_state->itable[index] = reta_conf[i].reta[j];
317 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
318 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
320 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
322 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
323 lio_dev_err(lio_dev, "Failed to set rss hash\n");
327 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
328 lio_dev_err(lio_dev, "Set rss hash timed out\n");
336 lio_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
337 struct rte_eth_rss_reta_entry64 *reta_conf,
340 struct lio_device *lio_dev = LIO_DEV(eth_dev);
341 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
344 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
346 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
347 reta_size, LIO_RSS_MAX_TABLE_SZ);
351 num = reta_size / RTE_RETA_GROUP_SIZE;
353 for (i = 0; i < num; i++) {
354 memcpy(reta_conf->reta,
355 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
356 RTE_RETA_GROUP_SIZE);
364 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
365 struct rte_eth_rss_conf *rss_conf)
367 struct lio_device *lio_dev = LIO_DEV(eth_dev);
368 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
369 uint8_t *hash_key = NULL;
372 if (rss_state->hash_disable) {
373 lio_dev_info(lio_dev, "RSS disabled in nic\n");
374 rss_conf->rss_hf = 0;
379 hash_key = rss_conf->rss_key;
380 if (hash_key != NULL)
381 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
384 rss_hf |= ETH_RSS_IPV4;
385 if (rss_state->tcp_hash)
386 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
388 rss_hf |= ETH_RSS_IPV6;
389 if (rss_state->ipv6_tcp_hash)
390 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
391 if (rss_state->ipv6_ex)
392 rss_hf |= ETH_RSS_IPV6_EX;
393 if (rss_state->ipv6_tcp_ex_hash)
394 rss_hf |= ETH_RSS_IPV6_TCP_EX;
396 rss_conf->rss_hf = rss_hf;
402 lio_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
403 struct rte_eth_rss_conf *rss_conf)
405 struct lio_device *lio_dev = LIO_DEV(eth_dev);
406 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
407 struct lio_rss_set *rss_param;
408 struct lio_dev_ctrl_cmd ctrl_cmd;
409 struct lio_ctrl_pkt ctrl_pkt;
411 if (!lio_dev->intf_open) {
412 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
417 /* flush added to prevent cmd failure
418 * incase the queue is full
420 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
422 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
423 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
425 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
427 ctrl_cmd.eth_dev = eth_dev;
430 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
431 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
432 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
434 rss_param->param.flags = 0xF;
436 if (rss_conf->rss_key) {
437 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
438 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
439 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
440 memcpy(rss_state->hash_key, rss_conf->rss_key,
441 rss_state->hash_key_size);
442 memcpy(rss_param->key, rss_state->hash_key,
443 rss_state->hash_key_size);
446 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
447 /* Can't disable rss through hash flags,
448 * if it is enabled by default during init
450 if (!rss_state->hash_disable)
453 /* This is for --disable-rss during testpmd launch */
454 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
456 uint32_t hashinfo = 0;
458 /* Can't enable rss if disabled by default during init */
459 if (rss_state->hash_disable)
462 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
463 hashinfo |= LIO_RSS_HASH_IPV4;
469 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
470 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
471 rss_state->tcp_hash = 1;
473 rss_state->tcp_hash = 0;
476 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
477 hashinfo |= LIO_RSS_HASH_IPV6;
483 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
484 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
485 rss_state->ipv6_tcp_hash = 1;
487 rss_state->ipv6_tcp_hash = 0;
490 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
491 hashinfo |= LIO_RSS_HASH_IPV6_EX;
492 rss_state->ipv6_ex = 1;
494 rss_state->ipv6_ex = 0;
497 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
498 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
499 rss_state->ipv6_tcp_ex_hash = 1;
501 rss_state->ipv6_tcp_ex_hash = 0;
504 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
505 rss_param->param.hashinfo = hashinfo;
508 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
510 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
511 lio_dev_err(lio_dev, "Failed to set rss hash\n");
515 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
516 lio_dev_err(lio_dev, "Set rss hash timed out\n");
524 * Add vxlan dest udp port for an interface.
527 * Pointer to the structure rte_eth_dev
532 * On success return 0
533 * On failure return -1
536 lio_dev_udp_tunnel_add(struct rte_eth_dev *eth_dev,
537 struct rte_eth_udp_tunnel *udp_tnl)
539 struct lio_device *lio_dev = LIO_DEV(eth_dev);
540 struct lio_dev_ctrl_cmd ctrl_cmd;
541 struct lio_ctrl_pkt ctrl_pkt;
546 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
547 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
551 /* flush added to prevent cmd failure
552 * incase the queue is full
554 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
556 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
557 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
559 ctrl_cmd.eth_dev = eth_dev;
562 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
563 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
564 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_ADD;
565 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
567 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
568 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_ADD command\n");
572 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
573 lio_dev_err(lio_dev, "VXLAN_PORT_ADD command timed out\n");
581 * Remove vxlan dest udp port for an interface.
584 * Pointer to the structure rte_eth_dev
589 * On success return 0
590 * On failure return -1
593 lio_dev_udp_tunnel_del(struct rte_eth_dev *eth_dev,
594 struct rte_eth_udp_tunnel *udp_tnl)
596 struct lio_device *lio_dev = LIO_DEV(eth_dev);
597 struct lio_dev_ctrl_cmd ctrl_cmd;
598 struct lio_ctrl_pkt ctrl_pkt;
603 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
604 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
608 /* flush added to prevent cmd failure
609 * incase the queue is full
611 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
613 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
614 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
616 ctrl_cmd.eth_dev = eth_dev;
619 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
620 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
621 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_DEL;
622 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
624 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
625 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_DEL command\n");
629 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
630 lio_dev_err(lio_dev, "VXLAN_PORT_DEL command timed out\n");
638 * Atomically writes the link status information into global
639 * structure rte_eth_dev.
642 * - Pointer to the structure rte_eth_dev to read from.
643 * - Pointer to the buffer to be saved with the link status.
646 * - On success, zero.
647 * - On failure, negative value.
650 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
651 struct rte_eth_link *link)
653 struct rte_eth_link *dst = ð_dev->data->dev_link;
654 struct rte_eth_link *src = link;
656 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
657 *(uint64_t *)src) == 0)
664 lio_hweight64(uint64_t w)
666 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
669 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
670 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
671 res = res + (res >> 8);
672 res = res + (res >> 16);
674 return (res + (res >> 32)) & 0x00000000000000FFul;
678 lio_dev_link_update(struct rte_eth_dev *eth_dev,
679 int wait_to_complete __rte_unused)
681 struct lio_device *lio_dev = LIO_DEV(eth_dev);
682 struct rte_eth_link link, old;
685 link.link_status = ETH_LINK_DOWN;
686 link.link_speed = ETH_SPEED_NUM_NONE;
687 link.link_duplex = ETH_LINK_HALF_DUPLEX;
688 memset(&old, 0, sizeof(old));
690 /* Return what we found */
691 if (lio_dev->linfo.link.s.link_up == 0) {
692 /* Interface is down */
693 if (lio_dev_atomic_write_link_status(eth_dev, &link))
695 if (link.link_status == old.link_status)
700 link.link_status = ETH_LINK_UP; /* Interface is up */
701 link.link_duplex = ETH_LINK_FULL_DUPLEX;
702 switch (lio_dev->linfo.link.s.speed) {
703 case LIO_LINK_SPEED_10000:
704 link.link_speed = ETH_SPEED_NUM_10G;
707 link.link_speed = ETH_SPEED_NUM_NONE;
708 link.link_duplex = ETH_LINK_HALF_DUPLEX;
711 if (lio_dev_atomic_write_link_status(eth_dev, &link))
714 if (link.link_status == old.link_status)
721 * \brief Net device enable, disable allmulticast
722 * @param eth_dev Pointer to the structure rte_eth_dev
725 lio_change_dev_flag(struct rte_eth_dev *eth_dev)
727 struct lio_device *lio_dev = LIO_DEV(eth_dev);
728 struct lio_dev_ctrl_cmd ctrl_cmd;
729 struct lio_ctrl_pkt ctrl_pkt;
731 /* flush added to prevent cmd failure
732 * incase the queue is full
734 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
736 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
737 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
739 ctrl_cmd.eth_dev = eth_dev;
742 /* Create a ctrl pkt command to be sent to core app. */
743 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CHANGE_DEVFLAGS;
744 ctrl_pkt.ncmd.s.param1 = lio_dev->ifflags;
745 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
747 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
748 lio_dev_err(lio_dev, "Failed to send change flag message\n");
752 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
753 lio_dev_err(lio_dev, "Change dev flag command timed out\n");
757 lio_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
759 struct lio_device *lio_dev = LIO_DEV(eth_dev);
761 if (!lio_dev->intf_open) {
762 lio_dev_err(lio_dev, "Port %d down, can't enable multicast\n",
767 lio_dev->ifflags |= LIO_IFFLAG_ALLMULTI;
768 lio_change_dev_flag(eth_dev);
772 lio_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
774 struct lio_device *lio_dev = LIO_DEV(eth_dev);
776 if (!lio_dev->intf_open) {
777 lio_dev_err(lio_dev, "Port %d down, can't disable multicast\n",
782 lio_dev->ifflags &= ~LIO_IFFLAG_ALLMULTI;
783 lio_change_dev_flag(eth_dev);
787 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
789 struct lio_device *lio_dev = LIO_DEV(eth_dev);
790 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
791 struct rte_eth_rss_reta_entry64 reta_conf[8];
792 struct rte_eth_rss_conf rss_conf;
795 /* Configure the RSS key and the RSS protocols used to compute
796 * the RSS hash of input packets.
798 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
799 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
800 rss_state->hash_disable = 1;
801 lio_dev_rss_hash_update(eth_dev, &rss_conf);
805 if (rss_conf.rss_key == NULL)
806 rss_conf.rss_key = lio_rss_key; /* Default hash key */
808 lio_dev_rss_hash_update(eth_dev, &rss_conf);
810 memset(reta_conf, 0, sizeof(reta_conf));
811 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
812 uint8_t q_idx, conf_idx, reta_idx;
814 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
815 i % eth_dev->data->nb_rx_queues : 0);
816 conf_idx = i / RTE_RETA_GROUP_SIZE;
817 reta_idx = i % RTE_RETA_GROUP_SIZE;
818 reta_conf[conf_idx].reta[reta_idx] = q_idx;
819 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
822 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
826 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
828 struct lio_device *lio_dev = LIO_DEV(eth_dev);
829 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
830 struct rte_eth_rss_conf rss_conf;
832 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
834 lio_dev_rss_configure(eth_dev);
837 /* if mq_mode is none, disable rss mode. */
839 memset(&rss_conf, 0, sizeof(rss_conf));
840 rss_state->hash_disable = 1;
841 lio_dev_rss_hash_update(eth_dev, &rss_conf);
846 * Setup our receive queue/ringbuffer. This is the
847 * queue the Octeon uses to send us packets and
848 * responses. We are given a memory pool for our
849 * packet buffers that are used to populate the receive
853 * Pointer to the structure rte_eth_dev
856 * @param num_rx_descs
857 * Number of entries in the queue
859 * Where to allocate memory
861 * Pointer to the struction rte_eth_rxconf
863 * Pointer to the packet pool
866 * - On success, return 0
867 * - On failure, return -1
870 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
871 uint16_t num_rx_descs, unsigned int socket_id,
872 const struct rte_eth_rxconf *rx_conf __rte_unused,
873 struct rte_mempool *mp)
875 struct lio_device *lio_dev = LIO_DEV(eth_dev);
876 struct rte_pktmbuf_pool_private *mbp_priv;
877 uint32_t fw_mapped_oq;
880 if (q_no >= lio_dev->nb_rx_queues) {
881 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
885 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
887 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
889 if ((lio_dev->droq[fw_mapped_oq]) &&
890 (num_rx_descs != lio_dev->droq[fw_mapped_oq]->max_count)) {
892 "Reconfiguring Rx descs not supported. Configure descs to same value %u or restart application\n",
893 lio_dev->droq[fw_mapped_oq]->max_count);
897 mbp_priv = rte_mempool_get_priv(mp);
898 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
900 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
902 lio_dev_err(lio_dev, "droq allocation failed\n");
906 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
912 * Release the receive queue/ringbuffer. Called by
916 * Opaque pointer to the receive queue to release
922 lio_dev_rx_queue_release(void *rxq)
924 struct lio_droq *droq = rxq;
925 struct lio_device *lio_dev = droq->lio_dev;
928 /* Run time queue deletion not supported */
929 if (lio_dev->port_configured)
934 lio_delete_droq_queue(droq->lio_dev, oq_no);
939 * Allocate and initialize SW ring. Initialize associated HW registers.
942 * Pointer to structure rte_eth_dev
947 * @param num_tx_descs
948 * Number of ringbuffer descriptors
951 * NUMA socket id, used for memory allocations
954 * Pointer to the structure rte_eth_txconf
957 * - On success, return 0
958 * - On failure, return -errno value
961 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
962 uint16_t num_tx_descs, unsigned int socket_id,
963 const struct rte_eth_txconf *tx_conf __rte_unused)
965 struct lio_device *lio_dev = LIO_DEV(eth_dev);
966 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
969 if (q_no >= lio_dev->nb_tx_queues) {
970 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
974 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
976 if ((lio_dev->instr_queue[fw_mapped_iq] != NULL) &&
977 (num_tx_descs != lio_dev->instr_queue[fw_mapped_iq]->max_count)) {
979 "Reconfiguring Tx descs not supported. Configure descs to same value %u or restart application\n",
980 lio_dev->instr_queue[fw_mapped_iq]->max_count);
984 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
985 num_tx_descs, lio_dev, socket_id);
988 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
992 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
993 lio_dev->instr_queue[fw_mapped_iq]->max_count,
997 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
1001 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
1007 * Release the transmit queue/ringbuffer. Called by
1011 * Opaque pointer to the transmit queue to release
1017 lio_dev_tx_queue_release(void *txq)
1019 struct lio_instr_queue *tq = txq;
1020 struct lio_device *lio_dev = tq->lio_dev;
1021 uint32_t fw_mapped_iq_no;
1023 /* Run time queue deletion not supported */
1024 if (lio_dev->port_configured)
1029 lio_delete_sglist(tq);
1031 fw_mapped_iq_no = tq->txpciq.s.q_no;
1032 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
1037 * Api to check link state.
1040 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
1042 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1043 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1044 struct lio_link_status_resp *resp;
1045 union octeon_link_status *ls;
1046 struct lio_soft_command *sc;
1049 if (!lio_dev->intf_open)
1052 resp_size = sizeof(struct lio_link_status_resp);
1053 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1057 resp = (struct lio_link_status_resp *)sc->virtrptr;
1058 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1059 LIO_OPCODE_INFO, 0, 0, 0);
1061 /* Setting wait time in seconds */
1062 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1064 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
1065 goto get_status_fail;
1067 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1068 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1073 goto get_status_fail;
1075 ls = &resp->link_info.link;
1077 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
1079 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
1080 lio_dev->linfo.link.link_status64 = ls->link_status64;
1081 lio_dev_link_update(eth_dev, 0);
1084 lio_free_soft_command(sc);
1089 lio_free_soft_command(sc);
1092 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
1093 * and will update link state if it changes.
1096 lio_sync_link_state_check(void *eth_dev)
1098 struct lio_device *lio_dev =
1099 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
1101 if (lio_dev->port_configured)
1102 lio_dev_get_link_status(eth_dev);
1104 /* Schedule periodic link status check.
1105 * Stop check if interface is close and start again while opening.
1107 if (lio_dev->intf_open)
1108 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
1113 lio_dev_start(struct rte_eth_dev *eth_dev)
1115 uint16_t mtu = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
1116 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1117 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1120 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
1122 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1125 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
1128 /* Ready for link status updates */
1129 lio_dev->intf_open = 1;
1132 /* Configure RSS if device configured with multiple RX queues. */
1133 lio_dev_mq_rx_configure(eth_dev);
1135 /* start polling for lsc */
1136 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
1137 lio_sync_link_state_check,
1140 lio_dev_err(lio_dev,
1141 "link state check handler creation failed\n");
1142 goto dev_lsc_handle_error;
1145 while ((lio_dev->linfo.link.link_status64 == 0) && (--timeout))
1148 if (lio_dev->linfo.link.link_status64 == 0) {
1150 goto dev_mtu_check_error;
1153 if (lio_dev->linfo.link.s.mtu != mtu) {
1154 ret = lio_dev_validate_vf_mtu(eth_dev, mtu);
1156 goto dev_mtu_check_error;
1161 dev_mtu_check_error:
1162 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1164 dev_lsc_handle_error:
1165 lio_dev->intf_open = 0;
1166 lio_send_rx_ctrl_cmd(eth_dev, 0);
1172 lio_dev_set_link_up(struct rte_eth_dev *eth_dev)
1174 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1176 if (!lio_dev->intf_open) {
1177 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1181 if (lio_dev->linfo.link.s.link_up) {
1182 lio_dev_info(lio_dev, "Link is already UP\n");
1186 if (lio_send_rx_ctrl_cmd(eth_dev, 1)) {
1187 lio_dev_err(lio_dev, "Unable to set Link UP\n");
1191 lio_dev->linfo.link.s.link_up = 1;
1192 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1198 lio_dev_set_link_down(struct rte_eth_dev *eth_dev)
1200 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1202 if (!lio_dev->intf_open) {
1203 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1207 if (!lio_dev->linfo.link.s.link_up) {
1208 lio_dev_info(lio_dev, "Link is already DOWN\n");
1212 lio_dev->linfo.link.s.link_up = 0;
1213 eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
1215 if (lio_send_rx_ctrl_cmd(eth_dev, 0)) {
1216 lio_dev->linfo.link.s.link_up = 1;
1217 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1218 lio_dev_err(lio_dev, "Unable to set Link Down\n");
1226 * Enable tunnel rx checksum verification from firmware.
1229 lio_enable_hw_tunnel_rx_checksum(struct rte_eth_dev *eth_dev)
1231 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1232 struct lio_dev_ctrl_cmd ctrl_cmd;
1233 struct lio_ctrl_pkt ctrl_pkt;
1235 /* flush added to prevent cmd failure
1236 * incase the queue is full
1238 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1240 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1241 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1243 ctrl_cmd.eth_dev = eth_dev;
1246 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_RX_CSUM_CTL;
1247 ctrl_pkt.ncmd.s.param1 = LIO_CMD_RXCSUM_ENABLE;
1248 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1250 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1251 lio_dev_err(lio_dev, "Failed to send TNL_RX_CSUM command\n");
1255 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1256 lio_dev_err(lio_dev, "TNL_RX_CSUM command timed out\n");
1260 * Enable checksum calculation for inner packet in a tunnel.
1263 lio_enable_hw_tunnel_tx_checksum(struct rte_eth_dev *eth_dev)
1265 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1266 struct lio_dev_ctrl_cmd ctrl_cmd;
1267 struct lio_ctrl_pkt ctrl_pkt;
1269 /* flush added to prevent cmd failure
1270 * incase the queue is full
1272 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1274 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1275 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1277 ctrl_cmd.eth_dev = eth_dev;
1280 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_TX_CSUM_CTL;
1281 ctrl_pkt.ncmd.s.param1 = LIO_CMD_TXCSUM_ENABLE;
1282 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1284 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1285 lio_dev_err(lio_dev, "Failed to send TNL_TX_CSUM command\n");
1289 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1290 lio_dev_err(lio_dev, "TNL_TX_CSUM command timed out\n");
1293 static int lio_dev_configure(struct rte_eth_dev *eth_dev)
1295 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1296 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1297 int retval, num_iqueues, num_oqueues;
1298 uint8_t mac[ETHER_ADDR_LEN], i;
1299 struct lio_if_cfg_resp *resp;
1300 struct lio_soft_command *sc;
1301 union lio_if_cfg if_cfg;
1304 PMD_INIT_FUNC_TRACE();
1306 /* Re-configuring firmware not supported.
1307 * Can't change tx/rx queues per port from initial value.
1309 if (lio_dev->port_configured) {
1310 if ((lio_dev->nb_rx_queues != eth_dev->data->nb_rx_queues) ||
1311 (lio_dev->nb_tx_queues != eth_dev->data->nb_tx_queues)) {
1312 lio_dev_err(lio_dev,
1313 "rxq/txq re-conf not supported. Restart application with new value.\n");
1319 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
1320 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
1322 resp_size = sizeof(struct lio_if_cfg_resp);
1323 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1327 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
1329 /* Firmware doesn't have capability to reconfigure the queues,
1330 * Claim all queues, and use as many required
1332 if_cfg.if_cfg64 = 0;
1333 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
1334 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
1335 if_cfg.s.base_queue = 0;
1337 if_cfg.s.gmx_port_id = lio_dev->pf_num;
1339 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1340 LIO_OPCODE_IF_CFG, 0,
1341 if_cfg.if_cfg64, 0);
1343 /* Setting wait time in seconds */
1344 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1346 retval = lio_send_soft_command(lio_dev, sc);
1347 if (retval == LIO_IQ_SEND_FAILED) {
1348 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
1350 /* Soft instr is freed by driver in case of failure. */
1351 goto nic_config_fail;
1354 /* Sleep on a wait queue till the cond flag indicates that the
1355 * response arrived or timed-out.
1357 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1358 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1359 lio_process_ordered_list(lio_dev);
1363 retval = resp->status;
1365 lio_dev_err(lio_dev, "iq/oq config failed\n");
1366 goto nic_config_fail;
1369 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
1370 sizeof(struct octeon_if_cfg_info) >> 3);
1372 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
1373 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
1375 if (!(num_iqueues) || !(num_oqueues)) {
1376 lio_dev_err(lio_dev,
1377 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
1378 (unsigned long)resp->cfg_info.iqmask,
1379 (unsigned long)resp->cfg_info.oqmask);
1380 goto nic_config_fail;
1383 lio_dev_dbg(lio_dev,
1384 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
1385 eth_dev->data->port_id,
1386 (unsigned long)resp->cfg_info.iqmask,
1387 (unsigned long)resp->cfg_info.oqmask,
1388 num_iqueues, num_oqueues);
1390 lio_dev->linfo.num_rxpciq = num_oqueues;
1391 lio_dev->linfo.num_txpciq = num_iqueues;
1393 for (i = 0; i < num_oqueues; i++) {
1394 lio_dev->linfo.rxpciq[i].rxpciq64 =
1395 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
1396 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
1397 i, lio_dev->linfo.rxpciq[i].s.q_no);
1400 for (i = 0; i < num_iqueues; i++) {
1401 lio_dev->linfo.txpciq[i].txpciq64 =
1402 resp->cfg_info.linfo.txpciq[i].txpciq64;
1403 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
1404 i, lio_dev->linfo.txpciq[i].s.q_no);
1407 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1408 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1409 lio_dev->linfo.link.link_status64 =
1410 resp->cfg_info.linfo.link.link_status64;
1412 /* 64-bit swap required on LE machines */
1413 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
1414 for (i = 0; i < ETHER_ADDR_LEN; i++)
1415 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
1418 /* Copy the permanent MAC address */
1419 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
1421 /* enable firmware checksum support for tunnel packets */
1422 lio_enable_hw_tunnel_rx_checksum(eth_dev);
1423 lio_enable_hw_tunnel_tx_checksum(eth_dev);
1425 lio_dev->glist_lock =
1426 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
1427 if (lio_dev->glist_lock == NULL)
1430 lio_dev->glist_head =
1431 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
1433 if (lio_dev->glist_head == NULL) {
1434 rte_free(lio_dev->glist_lock);
1435 lio_dev->glist_lock = NULL;
1439 lio_dev_link_update(eth_dev, 0);
1441 lio_dev->port_configured = 1;
1443 lio_free_soft_command(sc);
1445 /* Disable iq_0 for reconf */
1446 lio_dev->fn_list.disable_io_queues(lio_dev);
1448 /* Reset ioq regs */
1449 lio_dev->fn_list.setup_device_regs(lio_dev);
1451 /* Free iq_0 used during init */
1452 lio_free_instr_queue0(lio_dev);
1457 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
1458 lio_free_soft_command(sc);
1459 lio_free_instr_queue0(lio_dev);
1464 /* Define our ethernet definitions */
1465 static const struct eth_dev_ops liovf_eth_dev_ops = {
1466 .dev_configure = lio_dev_configure,
1467 .dev_start = lio_dev_start,
1468 .dev_set_link_up = lio_dev_set_link_up,
1469 .dev_set_link_down = lio_dev_set_link_down,
1470 .allmulticast_enable = lio_dev_allmulticast_enable,
1471 .allmulticast_disable = lio_dev_allmulticast_disable,
1472 .link_update = lio_dev_link_update,
1473 .stats_get = lio_dev_stats_get,
1474 .stats_reset = lio_dev_stats_reset,
1475 .dev_infos_get = lio_dev_info_get,
1476 .rx_queue_setup = lio_dev_rx_queue_setup,
1477 .rx_queue_release = lio_dev_rx_queue_release,
1478 .tx_queue_setup = lio_dev_tx_queue_setup,
1479 .tx_queue_release = lio_dev_tx_queue_release,
1480 .reta_update = lio_dev_rss_reta_update,
1481 .reta_query = lio_dev_rss_reta_query,
1482 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
1483 .rss_hash_update = lio_dev_rss_hash_update,
1484 .udp_tunnel_port_add = lio_dev_udp_tunnel_add,
1485 .udp_tunnel_port_del = lio_dev_udp_tunnel_del,
1489 lio_check_pf_hs_response(void *lio_dev)
1491 struct lio_device *dev = lio_dev;
1493 /* check till response arrives */
1494 if (dev->pfvf_hsword.coproc_tics_per_us)
1497 cn23xx_vf_handle_mbox(dev);
1499 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1503 * \brief Identify the LIO device and to map the BAR address space
1504 * @param lio_dev lio device
1507 lio_chip_specific_setup(struct lio_device *lio_dev)
1509 struct rte_pci_device *pdev = lio_dev->pci_dev;
1510 uint32_t dev_id = pdev->id.device_id;
1515 case LIO_CN23XX_VF_VID:
1516 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1517 ret = cn23xx_vf_setup_device(lio_dev);
1522 lio_dev_err(lio_dev, "Unsupported Chip\n");
1526 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1532 lio_first_time_init(struct lio_device *lio_dev,
1533 struct rte_pci_device *pdev)
1537 PMD_INIT_FUNC_TRACE();
1539 /* set dpdk specific pci device pointer */
1540 lio_dev->pci_dev = pdev;
1542 /* Identify the LIO type and set device ops */
1543 if (lio_chip_specific_setup(lio_dev)) {
1544 lio_dev_err(lio_dev, "Chip specific setup failed\n");
1548 /* Initialize soft command buffer pool */
1549 if (lio_setup_sc_buffer_pool(lio_dev)) {
1550 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
1554 /* Initialize lists to manage the requests of different types that
1555 * arrive from applications for this lio device.
1557 lio_setup_response_list(lio_dev);
1559 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
1560 lio_dev_err(lio_dev, "Mailbox setup failed\n");
1564 /* Check PF response */
1565 lio_check_pf_hs_response((void *)lio_dev);
1567 /* Do handshake and exit if incompatible PF driver */
1568 if (cn23xx_pfvf_handshake(lio_dev))
1572 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1573 /* Wait for FLR for 100ms per SRIOV specification */
1576 if (cn23xx_vf_set_io_queues_off(lio_dev)) {
1577 lio_dev_err(lio_dev, "Setting io queues off failed\n");
1581 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1582 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1586 if (lio_setup_instr_queue0(lio_dev)) {
1587 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
1591 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
1593 lio_dev->max_tx_queues = dpdk_queues;
1594 lio_dev->max_rx_queues = dpdk_queues;
1596 /* Enable input and output queues for this device */
1597 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1603 lio_free_sc_buffer_pool(lio_dev);
1604 if (lio_dev->mbox[0])
1605 lio_dev->fn_list.free_mbox(lio_dev);
1606 if (lio_dev->instr_queue[0])
1607 lio_free_instr_queue0(lio_dev);
1613 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1615 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1617 PMD_INIT_FUNC_TRACE();
1619 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1622 /* lio_free_sc_buffer_pool */
1623 lio_free_sc_buffer_pool(lio_dev);
1625 rte_free(eth_dev->data->mac_addrs);
1626 eth_dev->data->mac_addrs = NULL;
1628 eth_dev->rx_pkt_burst = NULL;
1629 eth_dev->tx_pkt_burst = NULL;
1635 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
1637 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
1638 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1640 PMD_INIT_FUNC_TRACE();
1642 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
1643 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
1645 /* Primary does the initialization. */
1646 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1649 rte_eth_copy_pci_info(eth_dev, pdev);
1650 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1652 if (pdev->mem_resource[0].addr) {
1653 lio_dev->hw_addr = pdev->mem_resource[0].addr;
1655 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
1659 lio_dev->eth_dev = eth_dev;
1660 /* set lio device print string */
1661 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
1662 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
1663 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1665 lio_dev->port_id = eth_dev->data->port_id;
1667 if (lio_first_time_init(lio_dev, pdev)) {
1668 lio_dev_err(lio_dev, "Device init failed\n");
1672 eth_dev->dev_ops = &liovf_eth_dev_ops;
1673 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
1674 if (eth_dev->data->mac_addrs == NULL) {
1675 lio_dev_err(lio_dev,
1676 "MAC addresses memory allocation failed\n");
1677 eth_dev->dev_ops = NULL;
1678 eth_dev->rx_pkt_burst = NULL;
1679 eth_dev->tx_pkt_burst = NULL;
1683 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
1686 lio_dev->port_configured = 0;
1687 /* Always allow unicast packets */
1688 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
1693 /* Set of PCI devices this driver supports */
1694 static const struct rte_pci_id pci_id_liovf_map[] = {
1695 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
1696 { .vendor_id = 0, /* sentinel */ }
1699 static struct eth_driver rte_liovf_pmd = {
1701 .id_table = pci_id_liovf_map,
1702 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1703 .probe = rte_eth_dev_pci_probe,
1704 .remove = rte_eth_dev_pci_remove,
1706 .eth_dev_init = lio_eth_dev_init,
1707 .eth_dev_uninit = lio_eth_dev_uninit,
1708 .dev_private_size = sizeof(struct lio_device),
1711 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
1712 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
1713 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");