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");
121 lio_dev_info_get(struct rte_eth_dev *eth_dev,
122 struct rte_eth_dev_info *devinfo)
124 struct lio_device *lio_dev = LIO_DEV(eth_dev);
126 devinfo->max_rx_queues = lio_dev->max_rx_queues;
127 devinfo->max_tx_queues = lio_dev->max_tx_queues;
129 devinfo->min_rx_bufsize = LIO_MIN_RX_BUF_SIZE;
130 devinfo->max_rx_pktlen = LIO_MAX_RX_PKTLEN;
132 devinfo->max_mac_addrs = 1;
134 devinfo->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM |
135 DEV_RX_OFFLOAD_UDP_CKSUM |
136 DEV_RX_OFFLOAD_TCP_CKSUM);
137 devinfo->tx_offload_capa = (DEV_TX_OFFLOAD_IPV4_CKSUM |
138 DEV_TX_OFFLOAD_UDP_CKSUM |
139 DEV_TX_OFFLOAD_TCP_CKSUM);
141 devinfo->rx_desc_lim = lio_rx_desc_lim;
142 devinfo->tx_desc_lim = lio_tx_desc_lim;
144 devinfo->reta_size = LIO_RSS_MAX_TABLE_SZ;
145 devinfo->hash_key_size = LIO_RSS_MAX_KEY_SZ;
146 devinfo->flow_type_rss_offloads = (ETH_RSS_IPV4 |
147 ETH_RSS_NONFRAG_IPV4_TCP |
149 ETH_RSS_NONFRAG_IPV6_TCP |
151 ETH_RSS_IPV6_TCP_EX);
155 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
156 struct rte_eth_rss_reta_entry64 *reta_conf,
159 struct lio_device *lio_dev = LIO_DEV(eth_dev);
160 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
161 struct lio_rss_set *rss_param;
162 struct lio_dev_ctrl_cmd ctrl_cmd;
163 struct lio_ctrl_pkt ctrl_pkt;
166 if (!lio_dev->intf_open) {
167 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
172 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
174 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
175 reta_size, LIO_RSS_MAX_TABLE_SZ);
179 /* flush added to prevent cmd failure
180 * incase the queue is full
182 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
184 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
185 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
187 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
189 ctrl_cmd.eth_dev = eth_dev;
192 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
193 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
194 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
196 rss_param->param.flags = 0xF;
197 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
198 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
200 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
201 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
202 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
203 index = (i * RTE_RETA_GROUP_SIZE) + j;
204 rss_state->itable[index] = reta_conf[i].reta[j];
209 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
210 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
212 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
214 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
215 lio_dev_err(lio_dev, "Failed to set rss hash\n");
219 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
220 lio_dev_err(lio_dev, "Set rss hash timed out\n");
228 lio_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
229 struct rte_eth_rss_reta_entry64 *reta_conf,
232 struct lio_device *lio_dev = LIO_DEV(eth_dev);
233 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
236 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
238 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
239 reta_size, LIO_RSS_MAX_TABLE_SZ);
243 num = reta_size / RTE_RETA_GROUP_SIZE;
245 for (i = 0; i < num; i++) {
246 memcpy(reta_conf->reta,
247 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
248 RTE_RETA_GROUP_SIZE);
256 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
257 struct rte_eth_rss_conf *rss_conf)
259 struct lio_device *lio_dev = LIO_DEV(eth_dev);
260 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
261 uint8_t *hash_key = NULL;
264 if (rss_state->hash_disable) {
265 lio_dev_info(lio_dev, "RSS disabled in nic\n");
266 rss_conf->rss_hf = 0;
271 hash_key = rss_conf->rss_key;
272 if (hash_key != NULL)
273 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
276 rss_hf |= ETH_RSS_IPV4;
277 if (rss_state->tcp_hash)
278 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
280 rss_hf |= ETH_RSS_IPV6;
281 if (rss_state->ipv6_tcp_hash)
282 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
283 if (rss_state->ipv6_ex)
284 rss_hf |= ETH_RSS_IPV6_EX;
285 if (rss_state->ipv6_tcp_ex_hash)
286 rss_hf |= ETH_RSS_IPV6_TCP_EX;
288 rss_conf->rss_hf = rss_hf;
294 lio_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
295 struct rte_eth_rss_conf *rss_conf)
297 struct lio_device *lio_dev = LIO_DEV(eth_dev);
298 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
299 struct lio_rss_set *rss_param;
300 struct lio_dev_ctrl_cmd ctrl_cmd;
301 struct lio_ctrl_pkt ctrl_pkt;
303 if (!lio_dev->intf_open) {
304 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
309 /* flush added to prevent cmd failure
310 * incase the queue is full
312 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
314 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
315 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
317 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
319 ctrl_cmd.eth_dev = eth_dev;
322 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
323 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
324 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
326 rss_param->param.flags = 0xF;
328 if (rss_conf->rss_key) {
329 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
330 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
331 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
332 memcpy(rss_state->hash_key, rss_conf->rss_key,
333 rss_state->hash_key_size);
334 memcpy(rss_param->key, rss_state->hash_key,
335 rss_state->hash_key_size);
338 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
339 /* Can't disable rss through hash flags,
340 * if it is enabled by default during init
342 if (!rss_state->hash_disable)
345 /* This is for --disable-rss during testpmd launch */
346 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
348 uint32_t hashinfo = 0;
350 /* Can't enable rss if disabled by default during init */
351 if (rss_state->hash_disable)
354 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
355 hashinfo |= LIO_RSS_HASH_IPV4;
361 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
362 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
363 rss_state->tcp_hash = 1;
365 rss_state->tcp_hash = 0;
368 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
369 hashinfo |= LIO_RSS_HASH_IPV6;
375 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
376 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
377 rss_state->ipv6_tcp_hash = 1;
379 rss_state->ipv6_tcp_hash = 0;
382 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
383 hashinfo |= LIO_RSS_HASH_IPV6_EX;
384 rss_state->ipv6_ex = 1;
386 rss_state->ipv6_ex = 0;
389 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
390 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
391 rss_state->ipv6_tcp_ex_hash = 1;
393 rss_state->ipv6_tcp_ex_hash = 0;
396 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
397 rss_param->param.hashinfo = hashinfo;
400 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
402 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
403 lio_dev_err(lio_dev, "Failed to set rss hash\n");
407 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
408 lio_dev_err(lio_dev, "Set rss hash timed out\n");
416 * Atomically writes the link status information into global
417 * structure rte_eth_dev.
420 * - Pointer to the structure rte_eth_dev to read from.
421 * - Pointer to the buffer to be saved with the link status.
424 * - On success, zero.
425 * - On failure, negative value.
428 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
429 struct rte_eth_link *link)
431 struct rte_eth_link *dst = ð_dev->data->dev_link;
432 struct rte_eth_link *src = link;
434 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
435 *(uint64_t *)src) == 0)
442 lio_hweight64(uint64_t w)
444 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
447 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
448 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
449 res = res + (res >> 8);
450 res = res + (res >> 16);
452 return (res + (res >> 32)) & 0x00000000000000FFul;
456 lio_dev_link_update(struct rte_eth_dev *eth_dev,
457 int wait_to_complete __rte_unused)
459 struct lio_device *lio_dev = LIO_DEV(eth_dev);
460 struct rte_eth_link link, old;
463 link.link_status = ETH_LINK_DOWN;
464 link.link_speed = ETH_SPEED_NUM_NONE;
465 link.link_duplex = ETH_LINK_HALF_DUPLEX;
466 memset(&old, 0, sizeof(old));
468 /* Return what we found */
469 if (lio_dev->linfo.link.s.link_up == 0) {
470 /* Interface is down */
471 if (lio_dev_atomic_write_link_status(eth_dev, &link))
473 if (link.link_status == old.link_status)
478 link.link_status = ETH_LINK_UP; /* Interface is up */
479 link.link_duplex = ETH_LINK_FULL_DUPLEX;
480 switch (lio_dev->linfo.link.s.speed) {
481 case LIO_LINK_SPEED_10000:
482 link.link_speed = ETH_SPEED_NUM_10G;
485 link.link_speed = ETH_SPEED_NUM_NONE;
486 link.link_duplex = ETH_LINK_HALF_DUPLEX;
489 if (lio_dev_atomic_write_link_status(eth_dev, &link))
492 if (link.link_status == old.link_status)
499 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
501 struct lio_device *lio_dev = LIO_DEV(eth_dev);
502 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
503 struct rte_eth_rss_reta_entry64 reta_conf[8];
504 struct rte_eth_rss_conf rss_conf;
507 /* Configure the RSS key and the RSS protocols used to compute
508 * the RSS hash of input packets.
510 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
511 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
512 rss_state->hash_disable = 1;
513 lio_dev_rss_hash_update(eth_dev, &rss_conf);
517 if (rss_conf.rss_key == NULL)
518 rss_conf.rss_key = lio_rss_key; /* Default hash key */
520 lio_dev_rss_hash_update(eth_dev, &rss_conf);
522 memset(reta_conf, 0, sizeof(reta_conf));
523 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
524 uint8_t q_idx, conf_idx, reta_idx;
526 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
527 i % eth_dev->data->nb_rx_queues : 0);
528 conf_idx = i / RTE_RETA_GROUP_SIZE;
529 reta_idx = i % RTE_RETA_GROUP_SIZE;
530 reta_conf[conf_idx].reta[reta_idx] = q_idx;
531 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
534 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
538 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
540 struct lio_device *lio_dev = LIO_DEV(eth_dev);
541 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
542 struct rte_eth_rss_conf rss_conf;
544 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
546 lio_dev_rss_configure(eth_dev);
549 /* if mq_mode is none, disable rss mode. */
551 memset(&rss_conf, 0, sizeof(rss_conf));
552 rss_state->hash_disable = 1;
553 lio_dev_rss_hash_update(eth_dev, &rss_conf);
558 * Setup our receive queue/ringbuffer. This is the
559 * queue the Octeon uses to send us packets and
560 * responses. We are given a memory pool for our
561 * packet buffers that are used to populate the receive
565 * Pointer to the structure rte_eth_dev
568 * @param num_rx_descs
569 * Number of entries in the queue
571 * Where to allocate memory
573 * Pointer to the struction rte_eth_rxconf
575 * Pointer to the packet pool
578 * - On success, return 0
579 * - On failure, return -1
582 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
583 uint16_t num_rx_descs, unsigned int socket_id,
584 const struct rte_eth_rxconf *rx_conf __rte_unused,
585 struct rte_mempool *mp)
587 struct lio_device *lio_dev = LIO_DEV(eth_dev);
588 struct rte_pktmbuf_pool_private *mbp_priv;
589 uint32_t fw_mapped_oq;
592 if (q_no >= lio_dev->nb_rx_queues) {
593 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
597 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
599 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
601 if ((lio_dev->droq[fw_mapped_oq]) &&
602 (num_rx_descs != lio_dev->droq[fw_mapped_oq]->max_count)) {
604 "Reconfiguring Rx descs not supported. Configure descs to same value %u or restart application\n",
605 lio_dev->droq[fw_mapped_oq]->max_count);
609 mbp_priv = rte_mempool_get_priv(mp);
610 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
612 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
614 lio_dev_err(lio_dev, "droq allocation failed\n");
618 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
624 * Release the receive queue/ringbuffer. Called by
628 * Opaque pointer to the receive queue to release
634 lio_dev_rx_queue_release(void *rxq)
636 struct lio_droq *droq = rxq;
637 struct lio_device *lio_dev = droq->lio_dev;
640 /* Run time queue deletion not supported */
641 if (lio_dev->port_configured)
646 lio_delete_droq_queue(droq->lio_dev, oq_no);
651 * Allocate and initialize SW ring. Initialize associated HW registers.
654 * Pointer to structure rte_eth_dev
659 * @param num_tx_descs
660 * Number of ringbuffer descriptors
663 * NUMA socket id, used for memory allocations
666 * Pointer to the structure rte_eth_txconf
669 * - On success, return 0
670 * - On failure, return -errno value
673 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
674 uint16_t num_tx_descs, unsigned int socket_id,
675 const struct rte_eth_txconf *tx_conf __rte_unused)
677 struct lio_device *lio_dev = LIO_DEV(eth_dev);
678 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
681 if (q_no >= lio_dev->nb_tx_queues) {
682 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
686 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
688 if ((lio_dev->instr_queue[fw_mapped_iq] != NULL) &&
689 (num_tx_descs != lio_dev->instr_queue[fw_mapped_iq]->max_count)) {
691 "Reconfiguring Tx descs not supported. Configure descs to same value %u or restart application\n",
692 lio_dev->instr_queue[fw_mapped_iq]->max_count);
696 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
697 num_tx_descs, lio_dev, socket_id);
700 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
704 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
705 lio_dev->instr_queue[fw_mapped_iq]->max_count,
709 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
713 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
719 * Release the transmit queue/ringbuffer. Called by
723 * Opaque pointer to the transmit queue to release
729 lio_dev_tx_queue_release(void *txq)
731 struct lio_instr_queue *tq = txq;
732 struct lio_device *lio_dev = tq->lio_dev;
733 uint32_t fw_mapped_iq_no;
735 /* Run time queue deletion not supported */
736 if (lio_dev->port_configured)
741 lio_delete_sglist(tq);
743 fw_mapped_iq_no = tq->txpciq.s.q_no;
744 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
749 * Api to check link state.
752 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
754 struct lio_device *lio_dev = LIO_DEV(eth_dev);
755 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
756 struct lio_link_status_resp *resp;
757 union octeon_link_status *ls;
758 struct lio_soft_command *sc;
761 if (!lio_dev->intf_open)
764 resp_size = sizeof(struct lio_link_status_resp);
765 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
769 resp = (struct lio_link_status_resp *)sc->virtrptr;
770 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
771 LIO_OPCODE_INFO, 0, 0, 0);
773 /* Setting wait time in seconds */
774 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
776 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
777 goto get_status_fail;
779 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
780 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
785 goto get_status_fail;
787 ls = &resp->link_info.link;
789 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
791 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
792 lio_dev->linfo.link.link_status64 = ls->link_status64;
793 lio_dev_link_update(eth_dev, 0);
796 lio_free_soft_command(sc);
801 lio_free_soft_command(sc);
804 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
805 * and will update link state if it changes.
808 lio_sync_link_state_check(void *eth_dev)
810 struct lio_device *lio_dev =
811 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
813 if (lio_dev->port_configured)
814 lio_dev_get_link_status(eth_dev);
816 /* Schedule periodic link status check.
817 * Stop check if interface is close and start again while opening.
819 if (lio_dev->intf_open)
820 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
825 lio_dev_start(struct rte_eth_dev *eth_dev)
827 struct lio_device *lio_dev = LIO_DEV(eth_dev);
830 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
832 if (lio_dev->fn_list.enable_io_queues(lio_dev))
835 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
838 /* Ready for link status updates */
839 lio_dev->intf_open = 1;
842 /* Configure RSS if device configured with multiple RX queues. */
843 lio_dev_mq_rx_configure(eth_dev);
845 /* start polling for lsc */
846 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
847 lio_sync_link_state_check,
851 "link state check handler creation failed\n");
852 goto dev_lsc_handle_error;
857 dev_lsc_handle_error:
858 lio_dev->intf_open = 0;
859 lio_send_rx_ctrl_cmd(eth_dev, 0);
864 static int lio_dev_configure(struct rte_eth_dev *eth_dev)
866 struct lio_device *lio_dev = LIO_DEV(eth_dev);
867 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
868 int retval, num_iqueues, num_oqueues;
869 uint8_t mac[ETHER_ADDR_LEN], i;
870 struct lio_if_cfg_resp *resp;
871 struct lio_soft_command *sc;
872 union lio_if_cfg if_cfg;
875 PMD_INIT_FUNC_TRACE();
877 /* Re-configuring firmware not supported.
878 * Can't change tx/rx queues per port from initial value.
880 if (lio_dev->port_configured) {
881 if ((lio_dev->nb_rx_queues != eth_dev->data->nb_rx_queues) ||
882 (lio_dev->nb_tx_queues != eth_dev->data->nb_tx_queues)) {
884 "rxq/txq re-conf not supported. Restart application with new value.\n");
890 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
891 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
893 resp_size = sizeof(struct lio_if_cfg_resp);
894 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
898 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
900 /* Firmware doesn't have capability to reconfigure the queues,
901 * Claim all queues, and use as many required
904 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
905 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
906 if_cfg.s.base_queue = 0;
908 if_cfg.s.gmx_port_id = lio_dev->pf_num;
910 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
911 LIO_OPCODE_IF_CFG, 0,
914 /* Setting wait time in seconds */
915 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
917 retval = lio_send_soft_command(lio_dev, sc);
918 if (retval == LIO_IQ_SEND_FAILED) {
919 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
921 /* Soft instr is freed by driver in case of failure. */
922 goto nic_config_fail;
925 /* Sleep on a wait queue till the cond flag indicates that the
926 * response arrived or timed-out.
928 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
929 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
930 lio_process_ordered_list(lio_dev);
934 retval = resp->status;
936 lio_dev_err(lio_dev, "iq/oq config failed\n");
937 goto nic_config_fail;
940 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
941 sizeof(struct octeon_if_cfg_info) >> 3);
943 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
944 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
946 if (!(num_iqueues) || !(num_oqueues)) {
948 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
949 (unsigned long)resp->cfg_info.iqmask,
950 (unsigned long)resp->cfg_info.oqmask);
951 goto nic_config_fail;
955 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
956 eth_dev->data->port_id,
957 (unsigned long)resp->cfg_info.iqmask,
958 (unsigned long)resp->cfg_info.oqmask,
959 num_iqueues, num_oqueues);
961 lio_dev->linfo.num_rxpciq = num_oqueues;
962 lio_dev->linfo.num_txpciq = num_iqueues;
964 for (i = 0; i < num_oqueues; i++) {
965 lio_dev->linfo.rxpciq[i].rxpciq64 =
966 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
967 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
968 i, lio_dev->linfo.rxpciq[i].s.q_no);
971 for (i = 0; i < num_iqueues; i++) {
972 lio_dev->linfo.txpciq[i].txpciq64 =
973 resp->cfg_info.linfo.txpciq[i].txpciq64;
974 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
975 i, lio_dev->linfo.txpciq[i].s.q_no);
978 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
979 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
980 lio_dev->linfo.link.link_status64 =
981 resp->cfg_info.linfo.link.link_status64;
983 /* 64-bit swap required on LE machines */
984 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
985 for (i = 0; i < ETHER_ADDR_LEN; i++)
986 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
989 /* Copy the permanent MAC address */
990 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
992 lio_dev->glist_lock =
993 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
994 if (lio_dev->glist_lock == NULL)
997 lio_dev->glist_head =
998 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
1000 if (lio_dev->glist_head == NULL) {
1001 rte_free(lio_dev->glist_lock);
1002 lio_dev->glist_lock = NULL;
1006 lio_dev_link_update(eth_dev, 0);
1008 lio_dev->port_configured = 1;
1010 lio_free_soft_command(sc);
1012 /* Disable iq_0 for reconf */
1013 lio_dev->fn_list.disable_io_queues(lio_dev);
1015 /* Reset ioq regs */
1016 lio_dev->fn_list.setup_device_regs(lio_dev);
1018 /* Free iq_0 used during init */
1019 lio_free_instr_queue0(lio_dev);
1024 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
1025 lio_free_soft_command(sc);
1026 lio_free_instr_queue0(lio_dev);
1031 /* Define our ethernet definitions */
1032 static const struct eth_dev_ops liovf_eth_dev_ops = {
1033 .dev_configure = lio_dev_configure,
1034 .dev_start = lio_dev_start,
1035 .link_update = lio_dev_link_update,
1036 .dev_infos_get = lio_dev_info_get,
1037 .rx_queue_setup = lio_dev_rx_queue_setup,
1038 .rx_queue_release = lio_dev_rx_queue_release,
1039 .tx_queue_setup = lio_dev_tx_queue_setup,
1040 .tx_queue_release = lio_dev_tx_queue_release,
1041 .reta_update = lio_dev_rss_reta_update,
1042 .reta_query = lio_dev_rss_reta_query,
1043 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
1044 .rss_hash_update = lio_dev_rss_hash_update,
1048 lio_check_pf_hs_response(void *lio_dev)
1050 struct lio_device *dev = lio_dev;
1052 /* check till response arrives */
1053 if (dev->pfvf_hsword.coproc_tics_per_us)
1056 cn23xx_vf_handle_mbox(dev);
1058 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1062 * \brief Identify the LIO device and to map the BAR address space
1063 * @param lio_dev lio device
1066 lio_chip_specific_setup(struct lio_device *lio_dev)
1068 struct rte_pci_device *pdev = lio_dev->pci_dev;
1069 uint32_t dev_id = pdev->id.device_id;
1074 case LIO_CN23XX_VF_VID:
1075 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1076 ret = cn23xx_vf_setup_device(lio_dev);
1081 lio_dev_err(lio_dev, "Unsupported Chip\n");
1085 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1091 lio_first_time_init(struct lio_device *lio_dev,
1092 struct rte_pci_device *pdev)
1096 PMD_INIT_FUNC_TRACE();
1098 /* set dpdk specific pci device pointer */
1099 lio_dev->pci_dev = pdev;
1101 /* Identify the LIO type and set device ops */
1102 if (lio_chip_specific_setup(lio_dev)) {
1103 lio_dev_err(lio_dev, "Chip specific setup failed\n");
1107 /* Initialize soft command buffer pool */
1108 if (lio_setup_sc_buffer_pool(lio_dev)) {
1109 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
1113 /* Initialize lists to manage the requests of different types that
1114 * arrive from applications for this lio device.
1116 lio_setup_response_list(lio_dev);
1118 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
1119 lio_dev_err(lio_dev, "Mailbox setup failed\n");
1123 /* Check PF response */
1124 lio_check_pf_hs_response((void *)lio_dev);
1126 /* Do handshake and exit if incompatible PF driver */
1127 if (cn23xx_pfvf_handshake(lio_dev))
1131 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1132 /* Wait for FLR for 100ms per SRIOV specification */
1135 if (cn23xx_vf_set_io_queues_off(lio_dev)) {
1136 lio_dev_err(lio_dev, "Setting io queues off failed\n");
1140 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1141 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1145 if (lio_setup_instr_queue0(lio_dev)) {
1146 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
1150 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
1152 lio_dev->max_tx_queues = dpdk_queues;
1153 lio_dev->max_rx_queues = dpdk_queues;
1155 /* Enable input and output queues for this device */
1156 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1162 lio_free_sc_buffer_pool(lio_dev);
1163 if (lio_dev->mbox[0])
1164 lio_dev->fn_list.free_mbox(lio_dev);
1165 if (lio_dev->instr_queue[0])
1166 lio_free_instr_queue0(lio_dev);
1172 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1174 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1176 PMD_INIT_FUNC_TRACE();
1178 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1181 /* lio_free_sc_buffer_pool */
1182 lio_free_sc_buffer_pool(lio_dev);
1184 rte_free(eth_dev->data->mac_addrs);
1185 eth_dev->data->mac_addrs = NULL;
1187 eth_dev->rx_pkt_burst = NULL;
1188 eth_dev->tx_pkt_burst = NULL;
1194 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
1196 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
1197 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1199 PMD_INIT_FUNC_TRACE();
1201 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
1202 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
1204 /* Primary does the initialization. */
1205 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1208 rte_eth_copy_pci_info(eth_dev, pdev);
1209 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1211 if (pdev->mem_resource[0].addr) {
1212 lio_dev->hw_addr = pdev->mem_resource[0].addr;
1214 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
1218 lio_dev->eth_dev = eth_dev;
1219 /* set lio device print string */
1220 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
1221 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
1222 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1224 lio_dev->port_id = eth_dev->data->port_id;
1226 if (lio_first_time_init(lio_dev, pdev)) {
1227 lio_dev_err(lio_dev, "Device init failed\n");
1231 eth_dev->dev_ops = &liovf_eth_dev_ops;
1232 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
1233 if (eth_dev->data->mac_addrs == NULL) {
1234 lio_dev_err(lio_dev,
1235 "MAC addresses memory allocation failed\n");
1236 eth_dev->dev_ops = NULL;
1237 eth_dev->rx_pkt_burst = NULL;
1238 eth_dev->tx_pkt_burst = NULL;
1242 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
1245 lio_dev->port_configured = 0;
1246 /* Always allow unicast packets */
1247 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
1252 /* Set of PCI devices this driver supports */
1253 static const struct rte_pci_id pci_id_liovf_map[] = {
1254 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
1255 { .vendor_id = 0, /* sentinel */ }
1258 static struct eth_driver rte_liovf_pmd = {
1260 .id_table = pci_id_liovf_map,
1261 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1262 .probe = rte_eth_dev_pci_probe,
1263 .remove = rte_eth_dev_pci_remove,
1265 .eth_dev_init = lio_eth_dev_init,
1266 .eth_dev_uninit = lio_eth_dev_uninit,
1267 .dev_private_size = sizeof(struct lio_device),
1270 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
1271 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
1272 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");