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_droq *droq;
133 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
134 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
135 droq = lio_dev->droq[oq_no];
137 oq_stats = &droq->stats;
138 pkts += oq_stats->rx_pkts_received;
139 drop += (oq_stats->rx_dropped +
140 oq_stats->dropped_toomany +
141 oq_stats->dropped_nomem);
142 bytes += oq_stats->rx_bytes_received;
145 stats->ibytes = bytes;
146 stats->ipackets = pkts;
147 stats->ierrors = drop;
151 lio_dev_stats_reset(struct rte_eth_dev *eth_dev)
153 struct lio_device *lio_dev = LIO_DEV(eth_dev);
154 struct lio_droq_stats *oq_stats;
155 struct lio_droq *droq;
158 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
159 oq_no = lio_dev->linfo.rxpciq[i].s.q_no;
160 droq = lio_dev->droq[oq_no];
162 oq_stats = &droq->stats;
163 memset(oq_stats, 0, sizeof(struct lio_droq_stats));
169 lio_dev_info_get(struct rte_eth_dev *eth_dev,
170 struct rte_eth_dev_info *devinfo)
172 struct lio_device *lio_dev = LIO_DEV(eth_dev);
174 devinfo->max_rx_queues = lio_dev->max_rx_queues;
175 devinfo->max_tx_queues = lio_dev->max_tx_queues;
177 devinfo->min_rx_bufsize = LIO_MIN_RX_BUF_SIZE;
178 devinfo->max_rx_pktlen = LIO_MAX_RX_PKTLEN;
180 devinfo->max_mac_addrs = 1;
182 devinfo->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
183 DEV_RX_OFFLOAD_UDP_CKSUM |
184 DEV_RX_OFFLOAD_TCP_CKSUM);
185 devinfo->tx_offload_capa = (DEV_TX_OFFLOAD_IPV4_CKSUM |
186 DEV_TX_OFFLOAD_UDP_CKSUM |
187 DEV_TX_OFFLOAD_TCP_CKSUM |
188 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM);
190 devinfo->rx_desc_lim = lio_rx_desc_lim;
191 devinfo->tx_desc_lim = lio_tx_desc_lim;
193 devinfo->reta_size = LIO_RSS_MAX_TABLE_SZ;
194 devinfo->hash_key_size = LIO_RSS_MAX_KEY_SZ;
195 devinfo->flow_type_rss_offloads = (ETH_RSS_IPV4 |
196 ETH_RSS_NONFRAG_IPV4_TCP |
198 ETH_RSS_NONFRAG_IPV6_TCP |
200 ETH_RSS_IPV6_TCP_EX);
204 lio_dev_validate_vf_mtu(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
206 struct lio_device *lio_dev = LIO_DEV(eth_dev);
208 PMD_INIT_FUNC_TRACE();
210 if (!lio_dev->intf_open) {
211 lio_dev_err(lio_dev, "Port %d down, can't check MTU\n",
216 /* Limit the MTU to make sure the ethernet packets are between
217 * ETHER_MIN_MTU bytes and PF's MTU
219 if ((new_mtu < ETHER_MIN_MTU) ||
220 (new_mtu > lio_dev->linfo.link.s.mtu)) {
221 lio_dev_err(lio_dev, "Invalid MTU: %d\n", new_mtu);
222 lio_dev_err(lio_dev, "Valid range %d and %d\n",
223 ETHER_MIN_MTU, lio_dev->linfo.link.s.mtu);
231 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
232 struct rte_eth_rss_reta_entry64 *reta_conf,
235 struct lio_device *lio_dev = LIO_DEV(eth_dev);
236 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
237 struct lio_rss_set *rss_param;
238 struct lio_dev_ctrl_cmd ctrl_cmd;
239 struct lio_ctrl_pkt ctrl_pkt;
242 if (!lio_dev->intf_open) {
243 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
248 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
250 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
251 reta_size, LIO_RSS_MAX_TABLE_SZ);
255 /* flush added to prevent cmd failure
256 * incase the queue is full
258 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
260 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
261 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
263 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
265 ctrl_cmd.eth_dev = eth_dev;
268 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
269 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
270 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
272 rss_param->param.flags = 0xF;
273 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
274 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
276 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
277 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
278 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
279 index = (i * RTE_RETA_GROUP_SIZE) + j;
280 rss_state->itable[index] = reta_conf[i].reta[j];
285 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
286 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
288 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
290 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
291 lio_dev_err(lio_dev, "Failed to set rss hash\n");
295 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
296 lio_dev_err(lio_dev, "Set rss hash timed out\n");
304 lio_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
305 struct rte_eth_rss_reta_entry64 *reta_conf,
308 struct lio_device *lio_dev = LIO_DEV(eth_dev);
309 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
312 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
314 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
315 reta_size, LIO_RSS_MAX_TABLE_SZ);
319 num = reta_size / RTE_RETA_GROUP_SIZE;
321 for (i = 0; i < num; i++) {
322 memcpy(reta_conf->reta,
323 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
324 RTE_RETA_GROUP_SIZE);
332 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
333 struct rte_eth_rss_conf *rss_conf)
335 struct lio_device *lio_dev = LIO_DEV(eth_dev);
336 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
337 uint8_t *hash_key = NULL;
340 if (rss_state->hash_disable) {
341 lio_dev_info(lio_dev, "RSS disabled in nic\n");
342 rss_conf->rss_hf = 0;
347 hash_key = rss_conf->rss_key;
348 if (hash_key != NULL)
349 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
352 rss_hf |= ETH_RSS_IPV4;
353 if (rss_state->tcp_hash)
354 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
356 rss_hf |= ETH_RSS_IPV6;
357 if (rss_state->ipv6_tcp_hash)
358 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
359 if (rss_state->ipv6_ex)
360 rss_hf |= ETH_RSS_IPV6_EX;
361 if (rss_state->ipv6_tcp_ex_hash)
362 rss_hf |= ETH_RSS_IPV6_TCP_EX;
364 rss_conf->rss_hf = rss_hf;
370 lio_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
371 struct rte_eth_rss_conf *rss_conf)
373 struct lio_device *lio_dev = LIO_DEV(eth_dev);
374 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
375 struct lio_rss_set *rss_param;
376 struct lio_dev_ctrl_cmd ctrl_cmd;
377 struct lio_ctrl_pkt ctrl_pkt;
379 if (!lio_dev->intf_open) {
380 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
385 /* flush added to prevent cmd failure
386 * incase the queue is full
388 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
390 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
391 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
393 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
395 ctrl_cmd.eth_dev = eth_dev;
398 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
399 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
400 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
402 rss_param->param.flags = 0xF;
404 if (rss_conf->rss_key) {
405 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
406 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
407 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
408 memcpy(rss_state->hash_key, rss_conf->rss_key,
409 rss_state->hash_key_size);
410 memcpy(rss_param->key, rss_state->hash_key,
411 rss_state->hash_key_size);
414 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
415 /* Can't disable rss through hash flags,
416 * if it is enabled by default during init
418 if (!rss_state->hash_disable)
421 /* This is for --disable-rss during testpmd launch */
422 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
424 uint32_t hashinfo = 0;
426 /* Can't enable rss if disabled by default during init */
427 if (rss_state->hash_disable)
430 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
431 hashinfo |= LIO_RSS_HASH_IPV4;
437 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
438 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
439 rss_state->tcp_hash = 1;
441 rss_state->tcp_hash = 0;
444 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
445 hashinfo |= LIO_RSS_HASH_IPV6;
451 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
452 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
453 rss_state->ipv6_tcp_hash = 1;
455 rss_state->ipv6_tcp_hash = 0;
458 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
459 hashinfo |= LIO_RSS_HASH_IPV6_EX;
460 rss_state->ipv6_ex = 1;
462 rss_state->ipv6_ex = 0;
465 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
466 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
467 rss_state->ipv6_tcp_ex_hash = 1;
469 rss_state->ipv6_tcp_ex_hash = 0;
472 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
473 rss_param->param.hashinfo = hashinfo;
476 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
478 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
479 lio_dev_err(lio_dev, "Failed to set rss hash\n");
483 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
484 lio_dev_err(lio_dev, "Set rss hash timed out\n");
492 * Add vxlan dest udp port for an interface.
495 * Pointer to the structure rte_eth_dev
500 * On success return 0
501 * On failure return -1
504 lio_dev_udp_tunnel_add(struct rte_eth_dev *eth_dev,
505 struct rte_eth_udp_tunnel *udp_tnl)
507 struct lio_device *lio_dev = LIO_DEV(eth_dev);
508 struct lio_dev_ctrl_cmd ctrl_cmd;
509 struct lio_ctrl_pkt ctrl_pkt;
514 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
515 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
519 /* flush added to prevent cmd failure
520 * incase the queue is full
522 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
524 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
525 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
527 ctrl_cmd.eth_dev = eth_dev;
530 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
531 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
532 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_ADD;
533 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
535 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
536 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_ADD command\n");
540 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
541 lio_dev_err(lio_dev, "VXLAN_PORT_ADD command timed out\n");
549 * Remove vxlan dest udp port for an interface.
552 * Pointer to the structure rte_eth_dev
557 * On success return 0
558 * On failure return -1
561 lio_dev_udp_tunnel_del(struct rte_eth_dev *eth_dev,
562 struct rte_eth_udp_tunnel *udp_tnl)
564 struct lio_device *lio_dev = LIO_DEV(eth_dev);
565 struct lio_dev_ctrl_cmd ctrl_cmd;
566 struct lio_ctrl_pkt ctrl_pkt;
571 if (udp_tnl->prot_type != RTE_TUNNEL_TYPE_VXLAN) {
572 lio_dev_err(lio_dev, "Unsupported tunnel type\n");
576 /* flush added to prevent cmd failure
577 * incase the queue is full
579 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
581 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
582 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
584 ctrl_cmd.eth_dev = eth_dev;
587 ctrl_pkt.ncmd.s.cmd = LIO_CMD_VXLAN_PORT_CONFIG;
588 ctrl_pkt.ncmd.s.param1 = udp_tnl->udp_port;
589 ctrl_pkt.ncmd.s.more = LIO_CMD_VXLAN_PORT_DEL;
590 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
592 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
593 lio_dev_err(lio_dev, "Failed to send VXLAN_PORT_DEL command\n");
597 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
598 lio_dev_err(lio_dev, "VXLAN_PORT_DEL command timed out\n");
606 * Atomically writes the link status information into global
607 * structure rte_eth_dev.
610 * - Pointer to the structure rte_eth_dev to read from.
611 * - Pointer to the buffer to be saved with the link status.
614 * - On success, zero.
615 * - On failure, negative value.
618 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
619 struct rte_eth_link *link)
621 struct rte_eth_link *dst = ð_dev->data->dev_link;
622 struct rte_eth_link *src = link;
624 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
625 *(uint64_t *)src) == 0)
632 lio_hweight64(uint64_t w)
634 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
637 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
638 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
639 res = res + (res >> 8);
640 res = res + (res >> 16);
642 return (res + (res >> 32)) & 0x00000000000000FFul;
646 lio_dev_link_update(struct rte_eth_dev *eth_dev,
647 int wait_to_complete __rte_unused)
649 struct lio_device *lio_dev = LIO_DEV(eth_dev);
650 struct rte_eth_link link, old;
653 link.link_status = ETH_LINK_DOWN;
654 link.link_speed = ETH_SPEED_NUM_NONE;
655 link.link_duplex = ETH_LINK_HALF_DUPLEX;
656 memset(&old, 0, sizeof(old));
658 /* Return what we found */
659 if (lio_dev->linfo.link.s.link_up == 0) {
660 /* Interface is down */
661 if (lio_dev_atomic_write_link_status(eth_dev, &link))
663 if (link.link_status == old.link_status)
668 link.link_status = ETH_LINK_UP; /* Interface is up */
669 link.link_duplex = ETH_LINK_FULL_DUPLEX;
670 switch (lio_dev->linfo.link.s.speed) {
671 case LIO_LINK_SPEED_10000:
672 link.link_speed = ETH_SPEED_NUM_10G;
675 link.link_speed = ETH_SPEED_NUM_NONE;
676 link.link_duplex = ETH_LINK_HALF_DUPLEX;
679 if (lio_dev_atomic_write_link_status(eth_dev, &link))
682 if (link.link_status == old.link_status)
689 * \brief Net device enable, disable allmulticast
690 * @param eth_dev Pointer to the structure rte_eth_dev
693 lio_change_dev_flag(struct rte_eth_dev *eth_dev)
695 struct lio_device *lio_dev = LIO_DEV(eth_dev);
696 struct lio_dev_ctrl_cmd ctrl_cmd;
697 struct lio_ctrl_pkt ctrl_pkt;
699 /* flush added to prevent cmd failure
700 * incase the queue is full
702 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
704 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
705 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
707 ctrl_cmd.eth_dev = eth_dev;
710 /* Create a ctrl pkt command to be sent to core app. */
711 ctrl_pkt.ncmd.s.cmd = LIO_CMD_CHANGE_DEVFLAGS;
712 ctrl_pkt.ncmd.s.param1 = lio_dev->ifflags;
713 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
715 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
716 lio_dev_err(lio_dev, "Failed to send change flag message\n");
720 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
721 lio_dev_err(lio_dev, "Change dev flag command timed out\n");
725 lio_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
727 struct lio_device *lio_dev = LIO_DEV(eth_dev);
729 if (!lio_dev->intf_open) {
730 lio_dev_err(lio_dev, "Port %d down, can't enable multicast\n",
735 lio_dev->ifflags |= LIO_IFFLAG_ALLMULTI;
736 lio_change_dev_flag(eth_dev);
740 lio_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
742 struct lio_device *lio_dev = LIO_DEV(eth_dev);
744 if (!lio_dev->intf_open) {
745 lio_dev_err(lio_dev, "Port %d down, can't disable multicast\n",
750 lio_dev->ifflags &= ~LIO_IFFLAG_ALLMULTI;
751 lio_change_dev_flag(eth_dev);
755 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
757 struct lio_device *lio_dev = LIO_DEV(eth_dev);
758 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
759 struct rte_eth_rss_reta_entry64 reta_conf[8];
760 struct rte_eth_rss_conf rss_conf;
763 /* Configure the RSS key and the RSS protocols used to compute
764 * the RSS hash of input packets.
766 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
767 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
768 rss_state->hash_disable = 1;
769 lio_dev_rss_hash_update(eth_dev, &rss_conf);
773 if (rss_conf.rss_key == NULL)
774 rss_conf.rss_key = lio_rss_key; /* Default hash key */
776 lio_dev_rss_hash_update(eth_dev, &rss_conf);
778 memset(reta_conf, 0, sizeof(reta_conf));
779 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
780 uint8_t q_idx, conf_idx, reta_idx;
782 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
783 i % eth_dev->data->nb_rx_queues : 0);
784 conf_idx = i / RTE_RETA_GROUP_SIZE;
785 reta_idx = i % RTE_RETA_GROUP_SIZE;
786 reta_conf[conf_idx].reta[reta_idx] = q_idx;
787 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
790 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
794 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
796 struct lio_device *lio_dev = LIO_DEV(eth_dev);
797 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
798 struct rte_eth_rss_conf rss_conf;
800 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
802 lio_dev_rss_configure(eth_dev);
805 /* if mq_mode is none, disable rss mode. */
807 memset(&rss_conf, 0, sizeof(rss_conf));
808 rss_state->hash_disable = 1;
809 lio_dev_rss_hash_update(eth_dev, &rss_conf);
814 * Setup our receive queue/ringbuffer. This is the
815 * queue the Octeon uses to send us packets and
816 * responses. We are given a memory pool for our
817 * packet buffers that are used to populate the receive
821 * Pointer to the structure rte_eth_dev
824 * @param num_rx_descs
825 * Number of entries in the queue
827 * Where to allocate memory
829 * Pointer to the struction rte_eth_rxconf
831 * Pointer to the packet pool
834 * - On success, return 0
835 * - On failure, return -1
838 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
839 uint16_t num_rx_descs, unsigned int socket_id,
840 const struct rte_eth_rxconf *rx_conf __rte_unused,
841 struct rte_mempool *mp)
843 struct lio_device *lio_dev = LIO_DEV(eth_dev);
844 struct rte_pktmbuf_pool_private *mbp_priv;
845 uint32_t fw_mapped_oq;
848 if (q_no >= lio_dev->nb_rx_queues) {
849 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
853 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
855 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
857 if ((lio_dev->droq[fw_mapped_oq]) &&
858 (num_rx_descs != lio_dev->droq[fw_mapped_oq]->max_count)) {
860 "Reconfiguring Rx descs not supported. Configure descs to same value %u or restart application\n",
861 lio_dev->droq[fw_mapped_oq]->max_count);
865 mbp_priv = rte_mempool_get_priv(mp);
866 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
868 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
870 lio_dev_err(lio_dev, "droq allocation failed\n");
874 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
880 * Release the receive queue/ringbuffer. Called by
884 * Opaque pointer to the receive queue to release
890 lio_dev_rx_queue_release(void *rxq)
892 struct lio_droq *droq = rxq;
893 struct lio_device *lio_dev = droq->lio_dev;
896 /* Run time queue deletion not supported */
897 if (lio_dev->port_configured)
902 lio_delete_droq_queue(droq->lio_dev, oq_no);
907 * Allocate and initialize SW ring. Initialize associated HW registers.
910 * Pointer to structure rte_eth_dev
915 * @param num_tx_descs
916 * Number of ringbuffer descriptors
919 * NUMA socket id, used for memory allocations
922 * Pointer to the structure rte_eth_txconf
925 * - On success, return 0
926 * - On failure, return -errno value
929 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
930 uint16_t num_tx_descs, unsigned int socket_id,
931 const struct rte_eth_txconf *tx_conf __rte_unused)
933 struct lio_device *lio_dev = LIO_DEV(eth_dev);
934 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
937 if (q_no >= lio_dev->nb_tx_queues) {
938 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
942 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
944 if ((lio_dev->instr_queue[fw_mapped_iq] != NULL) &&
945 (num_tx_descs != lio_dev->instr_queue[fw_mapped_iq]->max_count)) {
947 "Reconfiguring Tx descs not supported. Configure descs to same value %u or restart application\n",
948 lio_dev->instr_queue[fw_mapped_iq]->max_count);
952 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
953 num_tx_descs, lio_dev, socket_id);
956 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
960 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
961 lio_dev->instr_queue[fw_mapped_iq]->max_count,
965 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
969 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
975 * Release the transmit queue/ringbuffer. Called by
979 * Opaque pointer to the transmit queue to release
985 lio_dev_tx_queue_release(void *txq)
987 struct lio_instr_queue *tq = txq;
988 struct lio_device *lio_dev = tq->lio_dev;
989 uint32_t fw_mapped_iq_no;
991 /* Run time queue deletion not supported */
992 if (lio_dev->port_configured)
997 lio_delete_sglist(tq);
999 fw_mapped_iq_no = tq->txpciq.s.q_no;
1000 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
1005 * Api to check link state.
1008 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
1010 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1011 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1012 struct lio_link_status_resp *resp;
1013 union octeon_link_status *ls;
1014 struct lio_soft_command *sc;
1017 if (!lio_dev->intf_open)
1020 resp_size = sizeof(struct lio_link_status_resp);
1021 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1025 resp = (struct lio_link_status_resp *)sc->virtrptr;
1026 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1027 LIO_OPCODE_INFO, 0, 0, 0);
1029 /* Setting wait time in seconds */
1030 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1032 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
1033 goto get_status_fail;
1035 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1036 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1041 goto get_status_fail;
1043 ls = &resp->link_info.link;
1045 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
1047 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
1048 lio_dev->linfo.link.link_status64 = ls->link_status64;
1049 lio_dev_link_update(eth_dev, 0);
1052 lio_free_soft_command(sc);
1057 lio_free_soft_command(sc);
1060 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
1061 * and will update link state if it changes.
1064 lio_sync_link_state_check(void *eth_dev)
1066 struct lio_device *lio_dev =
1067 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
1069 if (lio_dev->port_configured)
1070 lio_dev_get_link_status(eth_dev);
1072 /* Schedule periodic link status check.
1073 * Stop check if interface is close and start again while opening.
1075 if (lio_dev->intf_open)
1076 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
1081 lio_dev_start(struct rte_eth_dev *eth_dev)
1083 uint16_t mtu = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
1084 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1085 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1088 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
1090 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1093 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
1096 /* Ready for link status updates */
1097 lio_dev->intf_open = 1;
1100 /* Configure RSS if device configured with multiple RX queues. */
1101 lio_dev_mq_rx_configure(eth_dev);
1103 /* start polling for lsc */
1104 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
1105 lio_sync_link_state_check,
1108 lio_dev_err(lio_dev,
1109 "link state check handler creation failed\n");
1110 goto dev_lsc_handle_error;
1113 while ((lio_dev->linfo.link.link_status64 == 0) && (--timeout))
1116 if (lio_dev->linfo.link.link_status64 == 0) {
1118 goto dev_mtu_check_error;
1121 if (lio_dev->linfo.link.s.mtu != mtu) {
1122 ret = lio_dev_validate_vf_mtu(eth_dev, mtu);
1124 goto dev_mtu_check_error;
1129 dev_mtu_check_error:
1130 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
1132 dev_lsc_handle_error:
1133 lio_dev->intf_open = 0;
1134 lio_send_rx_ctrl_cmd(eth_dev, 0);
1140 lio_dev_set_link_up(struct rte_eth_dev *eth_dev)
1142 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1144 if (!lio_dev->intf_open) {
1145 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1149 if (lio_dev->linfo.link.s.link_up) {
1150 lio_dev_info(lio_dev, "Link is already UP\n");
1154 if (lio_send_rx_ctrl_cmd(eth_dev, 1)) {
1155 lio_dev_err(lio_dev, "Unable to set Link UP\n");
1159 lio_dev->linfo.link.s.link_up = 1;
1160 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1166 lio_dev_set_link_down(struct rte_eth_dev *eth_dev)
1168 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1170 if (!lio_dev->intf_open) {
1171 lio_dev_info(lio_dev, "Port is stopped, Start the port first\n");
1175 if (!lio_dev->linfo.link.s.link_up) {
1176 lio_dev_info(lio_dev, "Link is already DOWN\n");
1180 lio_dev->linfo.link.s.link_up = 0;
1181 eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
1183 if (lio_send_rx_ctrl_cmd(eth_dev, 0)) {
1184 lio_dev->linfo.link.s.link_up = 1;
1185 eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1186 lio_dev_err(lio_dev, "Unable to set Link Down\n");
1194 * Enable tunnel rx checksum verification from firmware.
1197 lio_enable_hw_tunnel_rx_checksum(struct rte_eth_dev *eth_dev)
1199 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1200 struct lio_dev_ctrl_cmd ctrl_cmd;
1201 struct lio_ctrl_pkt ctrl_pkt;
1203 /* flush added to prevent cmd failure
1204 * incase the queue is full
1206 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1208 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1209 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1211 ctrl_cmd.eth_dev = eth_dev;
1214 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_RX_CSUM_CTL;
1215 ctrl_pkt.ncmd.s.param1 = LIO_CMD_RXCSUM_ENABLE;
1216 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1218 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1219 lio_dev_err(lio_dev, "Failed to send TNL_RX_CSUM command\n");
1223 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1224 lio_dev_err(lio_dev, "TNL_RX_CSUM command timed out\n");
1228 * Enable checksum calculation for inner packet in a tunnel.
1231 lio_enable_hw_tunnel_tx_checksum(struct rte_eth_dev *eth_dev)
1233 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1234 struct lio_dev_ctrl_cmd ctrl_cmd;
1235 struct lio_ctrl_pkt ctrl_pkt;
1237 /* flush added to prevent cmd failure
1238 * incase the queue is full
1240 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
1242 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
1243 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
1245 ctrl_cmd.eth_dev = eth_dev;
1248 ctrl_pkt.ncmd.s.cmd = LIO_CMD_TNL_TX_CSUM_CTL;
1249 ctrl_pkt.ncmd.s.param1 = LIO_CMD_TXCSUM_ENABLE;
1250 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
1252 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
1253 lio_dev_err(lio_dev, "Failed to send TNL_TX_CSUM command\n");
1257 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd))
1258 lio_dev_err(lio_dev, "TNL_TX_CSUM command timed out\n");
1261 static int lio_dev_configure(struct rte_eth_dev *eth_dev)
1263 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1264 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
1265 int retval, num_iqueues, num_oqueues;
1266 uint8_t mac[ETHER_ADDR_LEN], i;
1267 struct lio_if_cfg_resp *resp;
1268 struct lio_soft_command *sc;
1269 union lio_if_cfg if_cfg;
1272 PMD_INIT_FUNC_TRACE();
1274 /* Re-configuring firmware not supported.
1275 * Can't change tx/rx queues per port from initial value.
1277 if (lio_dev->port_configured) {
1278 if ((lio_dev->nb_rx_queues != eth_dev->data->nb_rx_queues) ||
1279 (lio_dev->nb_tx_queues != eth_dev->data->nb_tx_queues)) {
1280 lio_dev_err(lio_dev,
1281 "rxq/txq re-conf not supported. Restart application with new value.\n");
1287 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
1288 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
1290 resp_size = sizeof(struct lio_if_cfg_resp);
1291 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
1295 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
1297 /* Firmware doesn't have capability to reconfigure the queues,
1298 * Claim all queues, and use as many required
1300 if_cfg.if_cfg64 = 0;
1301 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
1302 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
1303 if_cfg.s.base_queue = 0;
1305 if_cfg.s.gmx_port_id = lio_dev->pf_num;
1307 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
1308 LIO_OPCODE_IF_CFG, 0,
1309 if_cfg.if_cfg64, 0);
1311 /* Setting wait time in seconds */
1312 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
1314 retval = lio_send_soft_command(lio_dev, sc);
1315 if (retval == LIO_IQ_SEND_FAILED) {
1316 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
1318 /* Soft instr is freed by driver in case of failure. */
1319 goto nic_config_fail;
1322 /* Sleep on a wait queue till the cond flag indicates that the
1323 * response arrived or timed-out.
1325 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
1326 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
1327 lio_process_ordered_list(lio_dev);
1331 retval = resp->status;
1333 lio_dev_err(lio_dev, "iq/oq config failed\n");
1334 goto nic_config_fail;
1337 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
1338 sizeof(struct octeon_if_cfg_info) >> 3);
1340 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
1341 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
1343 if (!(num_iqueues) || !(num_oqueues)) {
1344 lio_dev_err(lio_dev,
1345 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
1346 (unsigned long)resp->cfg_info.iqmask,
1347 (unsigned long)resp->cfg_info.oqmask);
1348 goto nic_config_fail;
1351 lio_dev_dbg(lio_dev,
1352 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
1353 eth_dev->data->port_id,
1354 (unsigned long)resp->cfg_info.iqmask,
1355 (unsigned long)resp->cfg_info.oqmask,
1356 num_iqueues, num_oqueues);
1358 lio_dev->linfo.num_rxpciq = num_oqueues;
1359 lio_dev->linfo.num_txpciq = num_iqueues;
1361 for (i = 0; i < num_oqueues; i++) {
1362 lio_dev->linfo.rxpciq[i].rxpciq64 =
1363 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
1364 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
1365 i, lio_dev->linfo.rxpciq[i].s.q_no);
1368 for (i = 0; i < num_iqueues; i++) {
1369 lio_dev->linfo.txpciq[i].txpciq64 =
1370 resp->cfg_info.linfo.txpciq[i].txpciq64;
1371 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
1372 i, lio_dev->linfo.txpciq[i].s.q_no);
1375 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1376 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1377 lio_dev->linfo.link.link_status64 =
1378 resp->cfg_info.linfo.link.link_status64;
1380 /* 64-bit swap required on LE machines */
1381 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
1382 for (i = 0; i < ETHER_ADDR_LEN; i++)
1383 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
1386 /* Copy the permanent MAC address */
1387 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
1389 /* enable firmware checksum support for tunnel packets */
1390 lio_enable_hw_tunnel_rx_checksum(eth_dev);
1391 lio_enable_hw_tunnel_tx_checksum(eth_dev);
1393 lio_dev->glist_lock =
1394 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
1395 if (lio_dev->glist_lock == NULL)
1398 lio_dev->glist_head =
1399 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
1401 if (lio_dev->glist_head == NULL) {
1402 rte_free(lio_dev->glist_lock);
1403 lio_dev->glist_lock = NULL;
1407 lio_dev_link_update(eth_dev, 0);
1409 lio_dev->port_configured = 1;
1411 lio_free_soft_command(sc);
1413 /* Disable iq_0 for reconf */
1414 lio_dev->fn_list.disable_io_queues(lio_dev);
1416 /* Reset ioq regs */
1417 lio_dev->fn_list.setup_device_regs(lio_dev);
1419 /* Free iq_0 used during init */
1420 lio_free_instr_queue0(lio_dev);
1425 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
1426 lio_free_soft_command(sc);
1427 lio_free_instr_queue0(lio_dev);
1432 /* Define our ethernet definitions */
1433 static const struct eth_dev_ops liovf_eth_dev_ops = {
1434 .dev_configure = lio_dev_configure,
1435 .dev_start = lio_dev_start,
1436 .dev_set_link_up = lio_dev_set_link_up,
1437 .dev_set_link_down = lio_dev_set_link_down,
1438 .allmulticast_enable = lio_dev_allmulticast_enable,
1439 .allmulticast_disable = lio_dev_allmulticast_disable,
1440 .link_update = lio_dev_link_update,
1441 .stats_get = lio_dev_stats_get,
1442 .stats_reset = lio_dev_stats_reset,
1443 .dev_infos_get = lio_dev_info_get,
1444 .rx_queue_setup = lio_dev_rx_queue_setup,
1445 .rx_queue_release = lio_dev_rx_queue_release,
1446 .tx_queue_setup = lio_dev_tx_queue_setup,
1447 .tx_queue_release = lio_dev_tx_queue_release,
1448 .reta_update = lio_dev_rss_reta_update,
1449 .reta_query = lio_dev_rss_reta_query,
1450 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
1451 .rss_hash_update = lio_dev_rss_hash_update,
1452 .udp_tunnel_port_add = lio_dev_udp_tunnel_add,
1453 .udp_tunnel_port_del = lio_dev_udp_tunnel_del,
1457 lio_check_pf_hs_response(void *lio_dev)
1459 struct lio_device *dev = lio_dev;
1461 /* check till response arrives */
1462 if (dev->pfvf_hsword.coproc_tics_per_us)
1465 cn23xx_vf_handle_mbox(dev);
1467 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1471 * \brief Identify the LIO device and to map the BAR address space
1472 * @param lio_dev lio device
1475 lio_chip_specific_setup(struct lio_device *lio_dev)
1477 struct rte_pci_device *pdev = lio_dev->pci_dev;
1478 uint32_t dev_id = pdev->id.device_id;
1483 case LIO_CN23XX_VF_VID:
1484 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1485 ret = cn23xx_vf_setup_device(lio_dev);
1490 lio_dev_err(lio_dev, "Unsupported Chip\n");
1494 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1500 lio_first_time_init(struct lio_device *lio_dev,
1501 struct rte_pci_device *pdev)
1505 PMD_INIT_FUNC_TRACE();
1507 /* set dpdk specific pci device pointer */
1508 lio_dev->pci_dev = pdev;
1510 /* Identify the LIO type and set device ops */
1511 if (lio_chip_specific_setup(lio_dev)) {
1512 lio_dev_err(lio_dev, "Chip specific setup failed\n");
1516 /* Initialize soft command buffer pool */
1517 if (lio_setup_sc_buffer_pool(lio_dev)) {
1518 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
1522 /* Initialize lists to manage the requests of different types that
1523 * arrive from applications for this lio device.
1525 lio_setup_response_list(lio_dev);
1527 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
1528 lio_dev_err(lio_dev, "Mailbox setup failed\n");
1532 /* Check PF response */
1533 lio_check_pf_hs_response((void *)lio_dev);
1535 /* Do handshake and exit if incompatible PF driver */
1536 if (cn23xx_pfvf_handshake(lio_dev))
1540 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1541 /* Wait for FLR for 100ms per SRIOV specification */
1544 if (cn23xx_vf_set_io_queues_off(lio_dev)) {
1545 lio_dev_err(lio_dev, "Setting io queues off failed\n");
1549 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1550 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1554 if (lio_setup_instr_queue0(lio_dev)) {
1555 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
1559 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
1561 lio_dev->max_tx_queues = dpdk_queues;
1562 lio_dev->max_rx_queues = dpdk_queues;
1564 /* Enable input and output queues for this device */
1565 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1571 lio_free_sc_buffer_pool(lio_dev);
1572 if (lio_dev->mbox[0])
1573 lio_dev->fn_list.free_mbox(lio_dev);
1574 if (lio_dev->instr_queue[0])
1575 lio_free_instr_queue0(lio_dev);
1581 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1583 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1585 PMD_INIT_FUNC_TRACE();
1587 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1590 /* lio_free_sc_buffer_pool */
1591 lio_free_sc_buffer_pool(lio_dev);
1593 rte_free(eth_dev->data->mac_addrs);
1594 eth_dev->data->mac_addrs = NULL;
1596 eth_dev->rx_pkt_burst = NULL;
1597 eth_dev->tx_pkt_burst = NULL;
1603 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
1605 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
1606 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1608 PMD_INIT_FUNC_TRACE();
1610 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
1611 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
1613 /* Primary does the initialization. */
1614 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1617 rte_eth_copy_pci_info(eth_dev, pdev);
1618 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1620 if (pdev->mem_resource[0].addr) {
1621 lio_dev->hw_addr = pdev->mem_resource[0].addr;
1623 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
1627 lio_dev->eth_dev = eth_dev;
1628 /* set lio device print string */
1629 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
1630 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
1631 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1633 lio_dev->port_id = eth_dev->data->port_id;
1635 if (lio_first_time_init(lio_dev, pdev)) {
1636 lio_dev_err(lio_dev, "Device init failed\n");
1640 eth_dev->dev_ops = &liovf_eth_dev_ops;
1641 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
1642 if (eth_dev->data->mac_addrs == NULL) {
1643 lio_dev_err(lio_dev,
1644 "MAC addresses memory allocation failed\n");
1645 eth_dev->dev_ops = NULL;
1646 eth_dev->rx_pkt_burst = NULL;
1647 eth_dev->tx_pkt_burst = NULL;
1651 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
1654 lio_dev->port_configured = 0;
1655 /* Always allow unicast packets */
1656 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
1661 /* Set of PCI devices this driver supports */
1662 static const struct rte_pci_id pci_id_liovf_map[] = {
1663 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
1664 { .vendor_id = 0, /* sentinel */ }
1667 static struct eth_driver rte_liovf_pmd = {
1669 .id_table = pci_id_liovf_map,
1670 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1671 .probe = rte_eth_dev_pci_probe,
1672 .remove = rte_eth_dev_pci_remove,
1674 .eth_dev_init = lio_eth_dev_init,
1675 .eth_dev_uninit = lio_eth_dev_uninit,
1676 .dev_private_size = sizeof(struct lio_device),
1679 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
1680 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
1681 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");