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_validate_vf_mtu(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
157 struct lio_device *lio_dev = LIO_DEV(eth_dev);
159 PMD_INIT_FUNC_TRACE();
161 if (!lio_dev->intf_open) {
162 lio_dev_err(lio_dev, "Port %d down, can't check MTU\n",
167 /* Limit the MTU to make sure the ethernet packets are between
168 * ETHER_MIN_MTU bytes and PF's MTU
170 if ((new_mtu < ETHER_MIN_MTU) ||
171 (new_mtu > lio_dev->linfo.link.s.mtu)) {
172 lio_dev_err(lio_dev, "Invalid MTU: %d\n", new_mtu);
173 lio_dev_err(lio_dev, "Valid range %d and %d\n",
174 ETHER_MIN_MTU, lio_dev->linfo.link.s.mtu);
182 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
183 struct rte_eth_rss_reta_entry64 *reta_conf,
186 struct lio_device *lio_dev = LIO_DEV(eth_dev);
187 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
188 struct lio_rss_set *rss_param;
189 struct lio_dev_ctrl_cmd ctrl_cmd;
190 struct lio_ctrl_pkt ctrl_pkt;
193 if (!lio_dev->intf_open) {
194 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
199 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
201 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
202 reta_size, LIO_RSS_MAX_TABLE_SZ);
206 /* flush added to prevent cmd failure
207 * incase the queue is full
209 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
211 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
212 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
214 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
216 ctrl_cmd.eth_dev = eth_dev;
219 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
220 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
221 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
223 rss_param->param.flags = 0xF;
224 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
225 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
227 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
228 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
229 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
230 index = (i * RTE_RETA_GROUP_SIZE) + j;
231 rss_state->itable[index] = reta_conf[i].reta[j];
236 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
237 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
239 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
241 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
242 lio_dev_err(lio_dev, "Failed to set rss hash\n");
246 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
247 lio_dev_err(lio_dev, "Set rss hash timed out\n");
255 lio_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
256 struct rte_eth_rss_reta_entry64 *reta_conf,
259 struct lio_device *lio_dev = LIO_DEV(eth_dev);
260 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
263 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
265 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
266 reta_size, LIO_RSS_MAX_TABLE_SZ);
270 num = reta_size / RTE_RETA_GROUP_SIZE;
272 for (i = 0; i < num; i++) {
273 memcpy(reta_conf->reta,
274 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
275 RTE_RETA_GROUP_SIZE);
283 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
284 struct rte_eth_rss_conf *rss_conf)
286 struct lio_device *lio_dev = LIO_DEV(eth_dev);
287 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
288 uint8_t *hash_key = NULL;
291 if (rss_state->hash_disable) {
292 lio_dev_info(lio_dev, "RSS disabled in nic\n");
293 rss_conf->rss_hf = 0;
298 hash_key = rss_conf->rss_key;
299 if (hash_key != NULL)
300 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
303 rss_hf |= ETH_RSS_IPV4;
304 if (rss_state->tcp_hash)
305 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
307 rss_hf |= ETH_RSS_IPV6;
308 if (rss_state->ipv6_tcp_hash)
309 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
310 if (rss_state->ipv6_ex)
311 rss_hf |= ETH_RSS_IPV6_EX;
312 if (rss_state->ipv6_tcp_ex_hash)
313 rss_hf |= ETH_RSS_IPV6_TCP_EX;
315 rss_conf->rss_hf = rss_hf;
321 lio_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
322 struct rte_eth_rss_conf *rss_conf)
324 struct lio_device *lio_dev = LIO_DEV(eth_dev);
325 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
326 struct lio_rss_set *rss_param;
327 struct lio_dev_ctrl_cmd ctrl_cmd;
328 struct lio_ctrl_pkt ctrl_pkt;
330 if (!lio_dev->intf_open) {
331 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
336 /* flush added to prevent cmd failure
337 * incase the queue is full
339 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
341 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
342 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
344 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
346 ctrl_cmd.eth_dev = eth_dev;
349 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
350 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
351 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
353 rss_param->param.flags = 0xF;
355 if (rss_conf->rss_key) {
356 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
357 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
358 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
359 memcpy(rss_state->hash_key, rss_conf->rss_key,
360 rss_state->hash_key_size);
361 memcpy(rss_param->key, rss_state->hash_key,
362 rss_state->hash_key_size);
365 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
366 /* Can't disable rss through hash flags,
367 * if it is enabled by default during init
369 if (!rss_state->hash_disable)
372 /* This is for --disable-rss during testpmd launch */
373 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
375 uint32_t hashinfo = 0;
377 /* Can't enable rss if disabled by default during init */
378 if (rss_state->hash_disable)
381 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
382 hashinfo |= LIO_RSS_HASH_IPV4;
388 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
389 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
390 rss_state->tcp_hash = 1;
392 rss_state->tcp_hash = 0;
395 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
396 hashinfo |= LIO_RSS_HASH_IPV6;
402 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
403 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
404 rss_state->ipv6_tcp_hash = 1;
406 rss_state->ipv6_tcp_hash = 0;
409 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
410 hashinfo |= LIO_RSS_HASH_IPV6_EX;
411 rss_state->ipv6_ex = 1;
413 rss_state->ipv6_ex = 0;
416 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
417 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
418 rss_state->ipv6_tcp_ex_hash = 1;
420 rss_state->ipv6_tcp_ex_hash = 0;
423 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
424 rss_param->param.hashinfo = hashinfo;
427 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
429 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
430 lio_dev_err(lio_dev, "Failed to set rss hash\n");
434 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
435 lio_dev_err(lio_dev, "Set rss hash timed out\n");
443 * Atomically writes the link status information into global
444 * structure rte_eth_dev.
447 * - Pointer to the structure rte_eth_dev to read from.
448 * - Pointer to the buffer to be saved with the link status.
451 * - On success, zero.
452 * - On failure, negative value.
455 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
456 struct rte_eth_link *link)
458 struct rte_eth_link *dst = ð_dev->data->dev_link;
459 struct rte_eth_link *src = link;
461 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
462 *(uint64_t *)src) == 0)
469 lio_hweight64(uint64_t w)
471 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
474 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
475 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
476 res = res + (res >> 8);
477 res = res + (res >> 16);
479 return (res + (res >> 32)) & 0x00000000000000FFul;
483 lio_dev_link_update(struct rte_eth_dev *eth_dev,
484 int wait_to_complete __rte_unused)
486 struct lio_device *lio_dev = LIO_DEV(eth_dev);
487 struct rte_eth_link link, old;
490 link.link_status = ETH_LINK_DOWN;
491 link.link_speed = ETH_SPEED_NUM_NONE;
492 link.link_duplex = ETH_LINK_HALF_DUPLEX;
493 memset(&old, 0, sizeof(old));
495 /* Return what we found */
496 if (lio_dev->linfo.link.s.link_up == 0) {
497 /* Interface is down */
498 if (lio_dev_atomic_write_link_status(eth_dev, &link))
500 if (link.link_status == old.link_status)
505 link.link_status = ETH_LINK_UP; /* Interface is up */
506 link.link_duplex = ETH_LINK_FULL_DUPLEX;
507 switch (lio_dev->linfo.link.s.speed) {
508 case LIO_LINK_SPEED_10000:
509 link.link_speed = ETH_SPEED_NUM_10G;
512 link.link_speed = ETH_SPEED_NUM_NONE;
513 link.link_duplex = ETH_LINK_HALF_DUPLEX;
516 if (lio_dev_atomic_write_link_status(eth_dev, &link))
519 if (link.link_status == old.link_status)
526 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
528 struct lio_device *lio_dev = LIO_DEV(eth_dev);
529 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
530 struct rte_eth_rss_reta_entry64 reta_conf[8];
531 struct rte_eth_rss_conf rss_conf;
534 /* Configure the RSS key and the RSS protocols used to compute
535 * the RSS hash of input packets.
537 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
538 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
539 rss_state->hash_disable = 1;
540 lio_dev_rss_hash_update(eth_dev, &rss_conf);
544 if (rss_conf.rss_key == NULL)
545 rss_conf.rss_key = lio_rss_key; /* Default hash key */
547 lio_dev_rss_hash_update(eth_dev, &rss_conf);
549 memset(reta_conf, 0, sizeof(reta_conf));
550 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
551 uint8_t q_idx, conf_idx, reta_idx;
553 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
554 i % eth_dev->data->nb_rx_queues : 0);
555 conf_idx = i / RTE_RETA_GROUP_SIZE;
556 reta_idx = i % RTE_RETA_GROUP_SIZE;
557 reta_conf[conf_idx].reta[reta_idx] = q_idx;
558 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
561 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
565 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
567 struct lio_device *lio_dev = LIO_DEV(eth_dev);
568 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
569 struct rte_eth_rss_conf rss_conf;
571 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
573 lio_dev_rss_configure(eth_dev);
576 /* if mq_mode is none, disable rss mode. */
578 memset(&rss_conf, 0, sizeof(rss_conf));
579 rss_state->hash_disable = 1;
580 lio_dev_rss_hash_update(eth_dev, &rss_conf);
585 * Setup our receive queue/ringbuffer. This is the
586 * queue the Octeon uses to send us packets and
587 * responses. We are given a memory pool for our
588 * packet buffers that are used to populate the receive
592 * Pointer to the structure rte_eth_dev
595 * @param num_rx_descs
596 * Number of entries in the queue
598 * Where to allocate memory
600 * Pointer to the struction rte_eth_rxconf
602 * Pointer to the packet pool
605 * - On success, return 0
606 * - On failure, return -1
609 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
610 uint16_t num_rx_descs, unsigned int socket_id,
611 const struct rte_eth_rxconf *rx_conf __rte_unused,
612 struct rte_mempool *mp)
614 struct lio_device *lio_dev = LIO_DEV(eth_dev);
615 struct rte_pktmbuf_pool_private *mbp_priv;
616 uint32_t fw_mapped_oq;
619 if (q_no >= lio_dev->nb_rx_queues) {
620 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
624 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
626 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
628 if ((lio_dev->droq[fw_mapped_oq]) &&
629 (num_rx_descs != lio_dev->droq[fw_mapped_oq]->max_count)) {
631 "Reconfiguring Rx descs not supported. Configure descs to same value %u or restart application\n",
632 lio_dev->droq[fw_mapped_oq]->max_count);
636 mbp_priv = rte_mempool_get_priv(mp);
637 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
639 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
641 lio_dev_err(lio_dev, "droq allocation failed\n");
645 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
651 * Release the receive queue/ringbuffer. Called by
655 * Opaque pointer to the receive queue to release
661 lio_dev_rx_queue_release(void *rxq)
663 struct lio_droq *droq = rxq;
664 struct lio_device *lio_dev = droq->lio_dev;
667 /* Run time queue deletion not supported */
668 if (lio_dev->port_configured)
673 lio_delete_droq_queue(droq->lio_dev, oq_no);
678 * Allocate and initialize SW ring. Initialize associated HW registers.
681 * Pointer to structure rte_eth_dev
686 * @param num_tx_descs
687 * Number of ringbuffer descriptors
690 * NUMA socket id, used for memory allocations
693 * Pointer to the structure rte_eth_txconf
696 * - On success, return 0
697 * - On failure, return -errno value
700 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
701 uint16_t num_tx_descs, unsigned int socket_id,
702 const struct rte_eth_txconf *tx_conf __rte_unused)
704 struct lio_device *lio_dev = LIO_DEV(eth_dev);
705 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
708 if (q_no >= lio_dev->nb_tx_queues) {
709 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
713 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
715 if ((lio_dev->instr_queue[fw_mapped_iq] != NULL) &&
716 (num_tx_descs != lio_dev->instr_queue[fw_mapped_iq]->max_count)) {
718 "Reconfiguring Tx descs not supported. Configure descs to same value %u or restart application\n",
719 lio_dev->instr_queue[fw_mapped_iq]->max_count);
723 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
724 num_tx_descs, lio_dev, socket_id);
727 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
731 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
732 lio_dev->instr_queue[fw_mapped_iq]->max_count,
736 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
740 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
746 * Release the transmit queue/ringbuffer. Called by
750 * Opaque pointer to the transmit queue to release
756 lio_dev_tx_queue_release(void *txq)
758 struct lio_instr_queue *tq = txq;
759 struct lio_device *lio_dev = tq->lio_dev;
760 uint32_t fw_mapped_iq_no;
762 /* Run time queue deletion not supported */
763 if (lio_dev->port_configured)
768 lio_delete_sglist(tq);
770 fw_mapped_iq_no = tq->txpciq.s.q_no;
771 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
776 * Api to check link state.
779 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
781 struct lio_device *lio_dev = LIO_DEV(eth_dev);
782 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
783 struct lio_link_status_resp *resp;
784 union octeon_link_status *ls;
785 struct lio_soft_command *sc;
788 if (!lio_dev->intf_open)
791 resp_size = sizeof(struct lio_link_status_resp);
792 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
796 resp = (struct lio_link_status_resp *)sc->virtrptr;
797 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
798 LIO_OPCODE_INFO, 0, 0, 0);
800 /* Setting wait time in seconds */
801 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
803 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
804 goto get_status_fail;
806 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
807 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
812 goto get_status_fail;
814 ls = &resp->link_info.link;
816 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
818 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
819 lio_dev->linfo.link.link_status64 = ls->link_status64;
820 lio_dev_link_update(eth_dev, 0);
823 lio_free_soft_command(sc);
828 lio_free_soft_command(sc);
831 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
832 * and will update link state if it changes.
835 lio_sync_link_state_check(void *eth_dev)
837 struct lio_device *lio_dev =
838 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
840 if (lio_dev->port_configured)
841 lio_dev_get_link_status(eth_dev);
843 /* Schedule periodic link status check.
844 * Stop check if interface is close and start again while opening.
846 if (lio_dev->intf_open)
847 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
852 lio_dev_start(struct rte_eth_dev *eth_dev)
854 uint16_t mtu = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
855 struct lio_device *lio_dev = LIO_DEV(eth_dev);
856 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
859 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
861 if (lio_dev->fn_list.enable_io_queues(lio_dev))
864 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
867 /* Ready for link status updates */
868 lio_dev->intf_open = 1;
871 /* Configure RSS if device configured with multiple RX queues. */
872 lio_dev_mq_rx_configure(eth_dev);
874 /* start polling for lsc */
875 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
876 lio_sync_link_state_check,
880 "link state check handler creation failed\n");
881 goto dev_lsc_handle_error;
884 while ((lio_dev->linfo.link.link_status64 == 0) && (--timeout))
887 if (lio_dev->linfo.link.link_status64 == 0) {
889 goto dev_mtu_check_error;
892 if (lio_dev->linfo.link.s.mtu != mtu) {
893 ret = lio_dev_validate_vf_mtu(eth_dev, mtu);
895 goto dev_mtu_check_error;
901 rte_eal_alarm_cancel(lio_sync_link_state_check, eth_dev);
903 dev_lsc_handle_error:
904 lio_dev->intf_open = 0;
905 lio_send_rx_ctrl_cmd(eth_dev, 0);
910 static int lio_dev_configure(struct rte_eth_dev *eth_dev)
912 struct lio_device *lio_dev = LIO_DEV(eth_dev);
913 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
914 int retval, num_iqueues, num_oqueues;
915 uint8_t mac[ETHER_ADDR_LEN], i;
916 struct lio_if_cfg_resp *resp;
917 struct lio_soft_command *sc;
918 union lio_if_cfg if_cfg;
921 PMD_INIT_FUNC_TRACE();
923 /* Re-configuring firmware not supported.
924 * Can't change tx/rx queues per port from initial value.
926 if (lio_dev->port_configured) {
927 if ((lio_dev->nb_rx_queues != eth_dev->data->nb_rx_queues) ||
928 (lio_dev->nb_tx_queues != eth_dev->data->nb_tx_queues)) {
930 "rxq/txq re-conf not supported. Restart application with new value.\n");
936 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
937 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
939 resp_size = sizeof(struct lio_if_cfg_resp);
940 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
944 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
946 /* Firmware doesn't have capability to reconfigure the queues,
947 * Claim all queues, and use as many required
950 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
951 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
952 if_cfg.s.base_queue = 0;
954 if_cfg.s.gmx_port_id = lio_dev->pf_num;
956 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
957 LIO_OPCODE_IF_CFG, 0,
960 /* Setting wait time in seconds */
961 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
963 retval = lio_send_soft_command(lio_dev, sc);
964 if (retval == LIO_IQ_SEND_FAILED) {
965 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
967 /* Soft instr is freed by driver in case of failure. */
968 goto nic_config_fail;
971 /* Sleep on a wait queue till the cond flag indicates that the
972 * response arrived or timed-out.
974 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
975 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
976 lio_process_ordered_list(lio_dev);
980 retval = resp->status;
982 lio_dev_err(lio_dev, "iq/oq config failed\n");
983 goto nic_config_fail;
986 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
987 sizeof(struct octeon_if_cfg_info) >> 3);
989 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
990 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
992 if (!(num_iqueues) || !(num_oqueues)) {
994 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
995 (unsigned long)resp->cfg_info.iqmask,
996 (unsigned long)resp->cfg_info.oqmask);
997 goto nic_config_fail;
1000 lio_dev_dbg(lio_dev,
1001 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
1002 eth_dev->data->port_id,
1003 (unsigned long)resp->cfg_info.iqmask,
1004 (unsigned long)resp->cfg_info.oqmask,
1005 num_iqueues, num_oqueues);
1007 lio_dev->linfo.num_rxpciq = num_oqueues;
1008 lio_dev->linfo.num_txpciq = num_iqueues;
1010 for (i = 0; i < num_oqueues; i++) {
1011 lio_dev->linfo.rxpciq[i].rxpciq64 =
1012 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
1013 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
1014 i, lio_dev->linfo.rxpciq[i].s.q_no);
1017 for (i = 0; i < num_iqueues; i++) {
1018 lio_dev->linfo.txpciq[i].txpciq64 =
1019 resp->cfg_info.linfo.txpciq[i].txpciq64;
1020 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
1021 i, lio_dev->linfo.txpciq[i].s.q_no);
1024 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
1025 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
1026 lio_dev->linfo.link.link_status64 =
1027 resp->cfg_info.linfo.link.link_status64;
1029 /* 64-bit swap required on LE machines */
1030 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
1031 for (i = 0; i < ETHER_ADDR_LEN; i++)
1032 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
1035 /* Copy the permanent MAC address */
1036 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
1038 lio_dev->glist_lock =
1039 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
1040 if (lio_dev->glist_lock == NULL)
1043 lio_dev->glist_head =
1044 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
1046 if (lio_dev->glist_head == NULL) {
1047 rte_free(lio_dev->glist_lock);
1048 lio_dev->glist_lock = NULL;
1052 lio_dev_link_update(eth_dev, 0);
1054 lio_dev->port_configured = 1;
1056 lio_free_soft_command(sc);
1058 /* Disable iq_0 for reconf */
1059 lio_dev->fn_list.disable_io_queues(lio_dev);
1061 /* Reset ioq regs */
1062 lio_dev->fn_list.setup_device_regs(lio_dev);
1064 /* Free iq_0 used during init */
1065 lio_free_instr_queue0(lio_dev);
1070 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
1071 lio_free_soft_command(sc);
1072 lio_free_instr_queue0(lio_dev);
1077 /* Define our ethernet definitions */
1078 static const struct eth_dev_ops liovf_eth_dev_ops = {
1079 .dev_configure = lio_dev_configure,
1080 .dev_start = lio_dev_start,
1081 .link_update = lio_dev_link_update,
1082 .dev_infos_get = lio_dev_info_get,
1083 .rx_queue_setup = lio_dev_rx_queue_setup,
1084 .rx_queue_release = lio_dev_rx_queue_release,
1085 .tx_queue_setup = lio_dev_tx_queue_setup,
1086 .tx_queue_release = lio_dev_tx_queue_release,
1087 .reta_update = lio_dev_rss_reta_update,
1088 .reta_query = lio_dev_rss_reta_query,
1089 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
1090 .rss_hash_update = lio_dev_rss_hash_update,
1094 lio_check_pf_hs_response(void *lio_dev)
1096 struct lio_device *dev = lio_dev;
1098 /* check till response arrives */
1099 if (dev->pfvf_hsword.coproc_tics_per_us)
1102 cn23xx_vf_handle_mbox(dev);
1104 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1108 * \brief Identify the LIO device and to map the BAR address space
1109 * @param lio_dev lio device
1112 lio_chip_specific_setup(struct lio_device *lio_dev)
1114 struct rte_pci_device *pdev = lio_dev->pci_dev;
1115 uint32_t dev_id = pdev->id.device_id;
1120 case LIO_CN23XX_VF_VID:
1121 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1122 ret = cn23xx_vf_setup_device(lio_dev);
1127 lio_dev_err(lio_dev, "Unsupported Chip\n");
1131 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1137 lio_first_time_init(struct lio_device *lio_dev,
1138 struct rte_pci_device *pdev)
1142 PMD_INIT_FUNC_TRACE();
1144 /* set dpdk specific pci device pointer */
1145 lio_dev->pci_dev = pdev;
1147 /* Identify the LIO type and set device ops */
1148 if (lio_chip_specific_setup(lio_dev)) {
1149 lio_dev_err(lio_dev, "Chip specific setup failed\n");
1153 /* Initialize soft command buffer pool */
1154 if (lio_setup_sc_buffer_pool(lio_dev)) {
1155 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
1159 /* Initialize lists to manage the requests of different types that
1160 * arrive from applications for this lio device.
1162 lio_setup_response_list(lio_dev);
1164 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
1165 lio_dev_err(lio_dev, "Mailbox setup failed\n");
1169 /* Check PF response */
1170 lio_check_pf_hs_response((void *)lio_dev);
1172 /* Do handshake and exit if incompatible PF driver */
1173 if (cn23xx_pfvf_handshake(lio_dev))
1177 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1178 /* Wait for FLR for 100ms per SRIOV specification */
1181 if (cn23xx_vf_set_io_queues_off(lio_dev)) {
1182 lio_dev_err(lio_dev, "Setting io queues off failed\n");
1186 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1187 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1191 if (lio_setup_instr_queue0(lio_dev)) {
1192 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
1196 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
1198 lio_dev->max_tx_queues = dpdk_queues;
1199 lio_dev->max_rx_queues = dpdk_queues;
1201 /* Enable input and output queues for this device */
1202 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1208 lio_free_sc_buffer_pool(lio_dev);
1209 if (lio_dev->mbox[0])
1210 lio_dev->fn_list.free_mbox(lio_dev);
1211 if (lio_dev->instr_queue[0])
1212 lio_free_instr_queue0(lio_dev);
1218 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1220 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1222 PMD_INIT_FUNC_TRACE();
1224 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1227 /* lio_free_sc_buffer_pool */
1228 lio_free_sc_buffer_pool(lio_dev);
1230 rte_free(eth_dev->data->mac_addrs);
1231 eth_dev->data->mac_addrs = NULL;
1233 eth_dev->rx_pkt_burst = NULL;
1234 eth_dev->tx_pkt_burst = NULL;
1240 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
1242 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
1243 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1245 PMD_INIT_FUNC_TRACE();
1247 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
1248 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
1250 /* Primary does the initialization. */
1251 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1254 rte_eth_copy_pci_info(eth_dev, pdev);
1255 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1257 if (pdev->mem_resource[0].addr) {
1258 lio_dev->hw_addr = pdev->mem_resource[0].addr;
1260 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
1264 lio_dev->eth_dev = eth_dev;
1265 /* set lio device print string */
1266 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
1267 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
1268 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1270 lio_dev->port_id = eth_dev->data->port_id;
1272 if (lio_first_time_init(lio_dev, pdev)) {
1273 lio_dev_err(lio_dev, "Device init failed\n");
1277 eth_dev->dev_ops = &liovf_eth_dev_ops;
1278 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
1279 if (eth_dev->data->mac_addrs == NULL) {
1280 lio_dev_err(lio_dev,
1281 "MAC addresses memory allocation failed\n");
1282 eth_dev->dev_ops = NULL;
1283 eth_dev->rx_pkt_burst = NULL;
1284 eth_dev->tx_pkt_burst = NULL;
1288 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
1291 lio_dev->port_configured = 0;
1292 /* Always allow unicast packets */
1293 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
1298 /* Set of PCI devices this driver supports */
1299 static const struct rte_pci_id pci_id_liovf_map[] = {
1300 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
1301 { .vendor_id = 0, /* sentinel */ }
1304 static struct eth_driver rte_liovf_pmd = {
1306 .id_table = pci_id_liovf_map,
1307 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1308 .probe = rte_eth_dev_pci_probe,
1309 .remove = rte_eth_dev_pci_remove,
1311 .eth_dev_init = lio_eth_dev_init,
1312 .eth_dev_uninit = lio_eth_dev_uninit,
1313 .dev_private_size = sizeof(struct lio_device),
1316 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
1317 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
1318 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");