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 /* Wait for control command to reach nic. */
55 lio_wait_for_ctrl_cmd(struct lio_device *lio_dev,
56 struct lio_dev_ctrl_cmd *ctrl_cmd)
58 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
60 while ((ctrl_cmd->cond == 0) && --timeout) {
61 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
69 * \brief Send Rx control command
70 * @param eth_dev Pointer to the structure rte_eth_dev
71 * @param start_stop whether to start or stop
74 lio_send_rx_ctrl_cmd(struct rte_eth_dev *eth_dev, int start_stop)
76 struct lio_device *lio_dev = LIO_DEV(eth_dev);
77 struct lio_dev_ctrl_cmd ctrl_cmd;
78 struct lio_ctrl_pkt ctrl_pkt;
80 /* flush added to prevent cmd failure
81 * incase the queue is full
83 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
85 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
86 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
88 ctrl_cmd.eth_dev = eth_dev;
91 ctrl_pkt.ncmd.s.cmd = LIO_CMD_RX_CTL;
92 ctrl_pkt.ncmd.s.param1 = start_stop;
93 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
95 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
96 lio_dev_err(lio_dev, "Failed to send RX Control message\n");
100 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
101 lio_dev_err(lio_dev, "RX Control command timed out\n");
109 lio_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
110 struct rte_eth_rss_reta_entry64 *reta_conf,
113 struct lio_device *lio_dev = LIO_DEV(eth_dev);
114 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
115 struct lio_rss_set *rss_param;
116 struct lio_dev_ctrl_cmd ctrl_cmd;
117 struct lio_ctrl_pkt ctrl_pkt;
120 if (!lio_dev->intf_open) {
121 lio_dev_err(lio_dev, "Port %d down, can't update reta\n",
126 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
128 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
129 reta_size, LIO_RSS_MAX_TABLE_SZ);
133 /* flush added to prevent cmd failure
134 * incase the queue is full
136 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
138 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
139 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
141 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
143 ctrl_cmd.eth_dev = eth_dev;
146 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
147 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
148 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
150 rss_param->param.flags = 0xF;
151 rss_param->param.flags &= ~LIO_RSS_PARAM_ITABLE_UNCHANGED;
152 rss_param->param.itablesize = LIO_RSS_MAX_TABLE_SZ;
154 for (i = 0; i < (reta_size / RTE_RETA_GROUP_SIZE); i++) {
155 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
156 if ((reta_conf[i].mask) & ((uint64_t)1 << j)) {
157 index = (i * RTE_RETA_GROUP_SIZE) + j;
158 rss_state->itable[index] = reta_conf[i].reta[j];
163 rss_state->itable_size = LIO_RSS_MAX_TABLE_SZ;
164 memcpy(rss_param->itable, rss_state->itable, rss_state->itable_size);
166 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
168 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
169 lio_dev_err(lio_dev, "Failed to set rss hash\n");
173 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
174 lio_dev_err(lio_dev, "Set rss hash timed out\n");
182 lio_dev_rss_reta_query(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;
190 if (reta_size != LIO_RSS_MAX_TABLE_SZ) {
192 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)\n",
193 reta_size, LIO_RSS_MAX_TABLE_SZ);
197 num = reta_size / RTE_RETA_GROUP_SIZE;
199 for (i = 0; i < num; i++) {
200 memcpy(reta_conf->reta,
201 &rss_state->itable[i * RTE_RETA_GROUP_SIZE],
202 RTE_RETA_GROUP_SIZE);
210 lio_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
211 struct rte_eth_rss_conf *rss_conf)
213 struct lio_device *lio_dev = LIO_DEV(eth_dev);
214 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
215 uint8_t *hash_key = NULL;
218 if (rss_state->hash_disable) {
219 lio_dev_info(lio_dev, "RSS disabled in nic\n");
220 rss_conf->rss_hf = 0;
225 hash_key = rss_conf->rss_key;
226 if (hash_key != NULL)
227 memcpy(hash_key, rss_state->hash_key, rss_state->hash_key_size);
230 rss_hf |= ETH_RSS_IPV4;
231 if (rss_state->tcp_hash)
232 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
234 rss_hf |= ETH_RSS_IPV6;
235 if (rss_state->ipv6_tcp_hash)
236 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
237 if (rss_state->ipv6_ex)
238 rss_hf |= ETH_RSS_IPV6_EX;
239 if (rss_state->ipv6_tcp_ex_hash)
240 rss_hf |= ETH_RSS_IPV6_TCP_EX;
242 rss_conf->rss_hf = rss_hf;
248 lio_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
249 struct rte_eth_rss_conf *rss_conf)
251 struct lio_device *lio_dev = LIO_DEV(eth_dev);
252 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
253 struct lio_rss_set *rss_param;
254 struct lio_dev_ctrl_cmd ctrl_cmd;
255 struct lio_ctrl_pkt ctrl_pkt;
257 if (!lio_dev->intf_open) {
258 lio_dev_err(lio_dev, "Port %d down, can't update hash\n",
263 /* flush added to prevent cmd failure
264 * incase the queue is full
266 lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
268 memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
269 memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
271 rss_param = (struct lio_rss_set *)&ctrl_pkt.udd[0];
273 ctrl_cmd.eth_dev = eth_dev;
276 ctrl_pkt.ncmd.s.cmd = LIO_CMD_SET_RSS;
277 ctrl_pkt.ncmd.s.more = sizeof(struct lio_rss_set) >> 3;
278 ctrl_pkt.ctrl_cmd = &ctrl_cmd;
280 rss_param->param.flags = 0xF;
282 if (rss_conf->rss_key) {
283 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_KEY_UNCHANGED;
284 rss_state->hash_key_size = LIO_RSS_MAX_KEY_SZ;
285 rss_param->param.hashkeysize = LIO_RSS_MAX_KEY_SZ;
286 memcpy(rss_state->hash_key, rss_conf->rss_key,
287 rss_state->hash_key_size);
288 memcpy(rss_param->key, rss_state->hash_key,
289 rss_state->hash_key_size);
292 if ((rss_conf->rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
293 /* Can't disable rss through hash flags,
294 * if it is enabled by default during init
296 if (!rss_state->hash_disable)
299 /* This is for --disable-rss during testpmd launch */
300 rss_param->param.flags |= LIO_RSS_PARAM_DISABLE_RSS;
302 uint32_t hashinfo = 0;
304 /* Can't enable rss if disabled by default during init */
305 if (rss_state->hash_disable)
308 if (rss_conf->rss_hf & ETH_RSS_IPV4) {
309 hashinfo |= LIO_RSS_HASH_IPV4;
315 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
316 hashinfo |= LIO_RSS_HASH_TCP_IPV4;
317 rss_state->tcp_hash = 1;
319 rss_state->tcp_hash = 0;
322 if (rss_conf->rss_hf & ETH_RSS_IPV6) {
323 hashinfo |= LIO_RSS_HASH_IPV6;
329 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
330 hashinfo |= LIO_RSS_HASH_TCP_IPV6;
331 rss_state->ipv6_tcp_hash = 1;
333 rss_state->ipv6_tcp_hash = 0;
336 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) {
337 hashinfo |= LIO_RSS_HASH_IPV6_EX;
338 rss_state->ipv6_ex = 1;
340 rss_state->ipv6_ex = 0;
343 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) {
344 hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
345 rss_state->ipv6_tcp_ex_hash = 1;
347 rss_state->ipv6_tcp_ex_hash = 0;
350 rss_param->param.flags &= ~LIO_RSS_PARAM_HASH_INFO_UNCHANGED;
351 rss_param->param.hashinfo = hashinfo;
354 lio_swap_8B_data((uint64_t *)rss_param, LIO_RSS_PARAM_SIZE >> 3);
356 if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
357 lio_dev_err(lio_dev, "Failed to set rss hash\n");
361 if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
362 lio_dev_err(lio_dev, "Set rss hash timed out\n");
370 * Atomically writes the link status information into global
371 * structure rte_eth_dev.
374 * - Pointer to the structure rte_eth_dev to read from.
375 * - Pointer to the buffer to be saved with the link status.
378 * - On success, zero.
379 * - On failure, negative value.
382 lio_dev_atomic_write_link_status(struct rte_eth_dev *eth_dev,
383 struct rte_eth_link *link)
385 struct rte_eth_link *dst = ð_dev->data->dev_link;
386 struct rte_eth_link *src = link;
388 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
389 *(uint64_t *)src) == 0)
396 lio_hweight64(uint64_t w)
398 uint64_t res = w - ((w >> 1) & 0x5555555555555555ul);
401 (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
402 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
403 res = res + (res >> 8);
404 res = res + (res >> 16);
406 return (res + (res >> 32)) & 0x00000000000000FFul;
410 lio_dev_link_update(struct rte_eth_dev *eth_dev,
411 int wait_to_complete __rte_unused)
413 struct lio_device *lio_dev = LIO_DEV(eth_dev);
414 struct rte_eth_link link, old;
417 link.link_status = ETH_LINK_DOWN;
418 link.link_speed = ETH_SPEED_NUM_NONE;
419 link.link_duplex = ETH_LINK_HALF_DUPLEX;
420 memset(&old, 0, sizeof(old));
422 /* Return what we found */
423 if (lio_dev->linfo.link.s.link_up == 0) {
424 /* Interface is down */
425 if (lio_dev_atomic_write_link_status(eth_dev, &link))
427 if (link.link_status == old.link_status)
432 link.link_status = ETH_LINK_UP; /* Interface is up */
433 link.link_duplex = ETH_LINK_FULL_DUPLEX;
434 switch (lio_dev->linfo.link.s.speed) {
435 case LIO_LINK_SPEED_10000:
436 link.link_speed = ETH_SPEED_NUM_10G;
439 link.link_speed = ETH_SPEED_NUM_NONE;
440 link.link_duplex = ETH_LINK_HALF_DUPLEX;
443 if (lio_dev_atomic_write_link_status(eth_dev, &link))
446 if (link.link_status == old.link_status)
453 lio_dev_rss_configure(struct rte_eth_dev *eth_dev)
455 struct lio_device *lio_dev = LIO_DEV(eth_dev);
456 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
457 struct rte_eth_rss_reta_entry64 reta_conf[8];
458 struct rte_eth_rss_conf rss_conf;
461 /* Configure the RSS key and the RSS protocols used to compute
462 * the RSS hash of input packets.
464 rss_conf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
465 if ((rss_conf.rss_hf & LIO_RSS_OFFLOAD_ALL) == 0) {
466 rss_state->hash_disable = 1;
467 lio_dev_rss_hash_update(eth_dev, &rss_conf);
471 if (rss_conf.rss_key == NULL)
472 rss_conf.rss_key = lio_rss_key; /* Default hash key */
474 lio_dev_rss_hash_update(eth_dev, &rss_conf);
476 memset(reta_conf, 0, sizeof(reta_conf));
477 for (i = 0; i < LIO_RSS_MAX_TABLE_SZ; i++) {
478 uint8_t q_idx, conf_idx, reta_idx;
480 q_idx = (uint8_t)((eth_dev->data->nb_rx_queues > 1) ?
481 i % eth_dev->data->nb_rx_queues : 0);
482 conf_idx = i / RTE_RETA_GROUP_SIZE;
483 reta_idx = i % RTE_RETA_GROUP_SIZE;
484 reta_conf[conf_idx].reta[reta_idx] = q_idx;
485 reta_conf[conf_idx].mask |= ((uint64_t)1 << reta_idx);
488 lio_dev_rss_reta_update(eth_dev, reta_conf, LIO_RSS_MAX_TABLE_SZ);
492 lio_dev_mq_rx_configure(struct rte_eth_dev *eth_dev)
494 struct lio_device *lio_dev = LIO_DEV(eth_dev);
495 struct lio_rss_ctx *rss_state = &lio_dev->rss_state;
496 struct rte_eth_rss_conf rss_conf;
498 switch (eth_dev->data->dev_conf.rxmode.mq_mode) {
500 lio_dev_rss_configure(eth_dev);
503 /* if mq_mode is none, disable rss mode. */
505 memset(&rss_conf, 0, sizeof(rss_conf));
506 rss_state->hash_disable = 1;
507 lio_dev_rss_hash_update(eth_dev, &rss_conf);
512 * Setup our receive queue/ringbuffer. This is the
513 * queue the Octeon uses to send us packets and
514 * responses. We are given a memory pool for our
515 * packet buffers that are used to populate the receive
519 * Pointer to the structure rte_eth_dev
522 * @param num_rx_descs
523 * Number of entries in the queue
525 * Where to allocate memory
527 * Pointer to the struction rte_eth_rxconf
529 * Pointer to the packet pool
532 * - On success, return 0
533 * - On failure, return -1
536 lio_dev_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
537 uint16_t num_rx_descs, unsigned int socket_id,
538 const struct rte_eth_rxconf *rx_conf __rte_unused,
539 struct rte_mempool *mp)
541 struct lio_device *lio_dev = LIO_DEV(eth_dev);
542 struct rte_pktmbuf_pool_private *mbp_priv;
543 uint32_t fw_mapped_oq;
546 if (q_no >= lio_dev->nb_rx_queues) {
547 lio_dev_err(lio_dev, "Invalid rx queue number %u\n", q_no);
551 lio_dev_dbg(lio_dev, "setting up rx queue %u\n", q_no);
553 fw_mapped_oq = lio_dev->linfo.rxpciq[q_no].s.q_no;
555 if ((lio_dev->droq[fw_mapped_oq]) &&
556 (num_rx_descs != lio_dev->droq[fw_mapped_oq]->max_count)) {
558 "Reconfiguring Rx descs not supported. Configure descs to same value %u or restart application\n",
559 lio_dev->droq[fw_mapped_oq]->max_count);
563 mbp_priv = rte_mempool_get_priv(mp);
564 buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
566 if (lio_setup_droq(lio_dev, fw_mapped_oq, num_rx_descs, buf_size, mp,
568 lio_dev_err(lio_dev, "droq allocation failed\n");
572 eth_dev->data->rx_queues[q_no] = lio_dev->droq[fw_mapped_oq];
578 * Release the receive queue/ringbuffer. Called by
582 * Opaque pointer to the receive queue to release
588 lio_dev_rx_queue_release(void *rxq)
590 struct lio_droq *droq = rxq;
591 struct lio_device *lio_dev = droq->lio_dev;
594 /* Run time queue deletion not supported */
595 if (lio_dev->port_configured)
600 lio_delete_droq_queue(droq->lio_dev, oq_no);
605 * Allocate and initialize SW ring. Initialize associated HW registers.
608 * Pointer to structure rte_eth_dev
613 * @param num_tx_descs
614 * Number of ringbuffer descriptors
617 * NUMA socket id, used for memory allocations
620 * Pointer to the structure rte_eth_txconf
623 * - On success, return 0
624 * - On failure, return -errno value
627 lio_dev_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t q_no,
628 uint16_t num_tx_descs, unsigned int socket_id,
629 const struct rte_eth_txconf *tx_conf __rte_unused)
631 struct lio_device *lio_dev = LIO_DEV(eth_dev);
632 int fw_mapped_iq = lio_dev->linfo.txpciq[q_no].s.q_no;
635 if (q_no >= lio_dev->nb_tx_queues) {
636 lio_dev_err(lio_dev, "Invalid tx queue number %u\n", q_no);
640 lio_dev_dbg(lio_dev, "setting up tx queue %u\n", q_no);
642 if ((lio_dev->instr_queue[fw_mapped_iq] != NULL) &&
643 (num_tx_descs != lio_dev->instr_queue[fw_mapped_iq]->max_count)) {
645 "Reconfiguring Tx descs not supported. Configure descs to same value %u or restart application\n",
646 lio_dev->instr_queue[fw_mapped_iq]->max_count);
650 retval = lio_setup_iq(lio_dev, q_no, lio_dev->linfo.txpciq[q_no],
651 num_tx_descs, lio_dev, socket_id);
654 lio_dev_err(lio_dev, "Runtime IQ(TxQ) creation failed.\n");
658 retval = lio_setup_sglists(lio_dev, q_no, fw_mapped_iq,
659 lio_dev->instr_queue[fw_mapped_iq]->max_count,
663 lio_delete_instruction_queue(lio_dev, fw_mapped_iq);
667 eth_dev->data->tx_queues[q_no] = lio_dev->instr_queue[fw_mapped_iq];
673 * Release the transmit queue/ringbuffer. Called by
677 * Opaque pointer to the transmit queue to release
683 lio_dev_tx_queue_release(void *txq)
685 struct lio_instr_queue *tq = txq;
686 struct lio_device *lio_dev = tq->lio_dev;
687 uint32_t fw_mapped_iq_no;
689 /* Run time queue deletion not supported */
690 if (lio_dev->port_configured)
695 lio_delete_sglist(tq);
697 fw_mapped_iq_no = tq->txpciq.s.q_no;
698 lio_delete_instruction_queue(tq->lio_dev, fw_mapped_iq_no);
703 * Api to check link state.
706 lio_dev_get_link_status(struct rte_eth_dev *eth_dev)
708 struct lio_device *lio_dev = LIO_DEV(eth_dev);
709 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
710 struct lio_link_status_resp *resp;
711 union octeon_link_status *ls;
712 struct lio_soft_command *sc;
715 if (!lio_dev->intf_open)
718 resp_size = sizeof(struct lio_link_status_resp);
719 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
723 resp = (struct lio_link_status_resp *)sc->virtrptr;
724 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
725 LIO_OPCODE_INFO, 0, 0, 0);
727 /* Setting wait time in seconds */
728 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
730 if (lio_send_soft_command(lio_dev, sc) == LIO_IQ_SEND_FAILED)
731 goto get_status_fail;
733 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
734 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
739 goto get_status_fail;
741 ls = &resp->link_info.link;
743 lio_swap_8B_data((uint64_t *)ls, sizeof(union octeon_link_status) >> 3);
745 if (lio_dev->linfo.link.link_status64 != ls->link_status64) {
746 lio_dev->linfo.link.link_status64 = ls->link_status64;
747 lio_dev_link_update(eth_dev, 0);
750 lio_free_soft_command(sc);
755 lio_free_soft_command(sc);
758 /* This function will be invoked every LSC_TIMEOUT ns (100ms)
759 * and will update link state if it changes.
762 lio_sync_link_state_check(void *eth_dev)
764 struct lio_device *lio_dev =
765 (((struct rte_eth_dev *)eth_dev)->data->dev_private);
767 if (lio_dev->port_configured)
768 lio_dev_get_link_status(eth_dev);
770 /* Schedule periodic link status check.
771 * Stop check if interface is close and start again while opening.
773 if (lio_dev->intf_open)
774 rte_eal_alarm_set(LIO_LSC_TIMEOUT, lio_sync_link_state_check,
779 lio_dev_start(struct rte_eth_dev *eth_dev)
781 struct lio_device *lio_dev = LIO_DEV(eth_dev);
784 lio_dev_info(lio_dev, "Starting port %d\n", eth_dev->data->port_id);
786 if (lio_dev->fn_list.enable_io_queues(lio_dev))
789 if (lio_send_rx_ctrl_cmd(eth_dev, 1))
792 /* Ready for link status updates */
793 lio_dev->intf_open = 1;
796 /* Configure RSS if device configured with multiple RX queues. */
797 lio_dev_mq_rx_configure(eth_dev);
799 /* start polling for lsc */
800 ret = rte_eal_alarm_set(LIO_LSC_TIMEOUT,
801 lio_sync_link_state_check,
805 "link state check handler creation failed\n");
806 goto dev_lsc_handle_error;
811 dev_lsc_handle_error:
812 lio_dev->intf_open = 0;
813 lio_send_rx_ctrl_cmd(eth_dev, 0);
818 static int lio_dev_configure(struct rte_eth_dev *eth_dev)
820 struct lio_device *lio_dev = LIO_DEV(eth_dev);
821 uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
822 int retval, num_iqueues, num_oqueues;
823 uint8_t mac[ETHER_ADDR_LEN], i;
824 struct lio_if_cfg_resp *resp;
825 struct lio_soft_command *sc;
826 union lio_if_cfg if_cfg;
829 PMD_INIT_FUNC_TRACE();
831 /* Re-configuring firmware not supported.
832 * Can't change tx/rx queues per port from initial value.
834 if (lio_dev->port_configured) {
835 if ((lio_dev->nb_rx_queues != eth_dev->data->nb_rx_queues) ||
836 (lio_dev->nb_tx_queues != eth_dev->data->nb_tx_queues)) {
838 "rxq/txq re-conf not supported. Restart application with new value.\n");
844 lio_dev->nb_rx_queues = eth_dev->data->nb_rx_queues;
845 lio_dev->nb_tx_queues = eth_dev->data->nb_tx_queues;
847 resp_size = sizeof(struct lio_if_cfg_resp);
848 sc = lio_alloc_soft_command(lio_dev, 0, resp_size, 0);
852 resp = (struct lio_if_cfg_resp *)sc->virtrptr;
854 /* Firmware doesn't have capability to reconfigure the queues,
855 * Claim all queues, and use as many required
858 if_cfg.s.num_iqueues = lio_dev->nb_tx_queues;
859 if_cfg.s.num_oqueues = lio_dev->nb_rx_queues;
860 if_cfg.s.base_queue = 0;
862 if_cfg.s.gmx_port_id = lio_dev->pf_num;
864 lio_prepare_soft_command(lio_dev, sc, LIO_OPCODE,
865 LIO_OPCODE_IF_CFG, 0,
868 /* Setting wait time in seconds */
869 sc->wait_time = LIO_MAX_CMD_TIMEOUT / 1000;
871 retval = lio_send_soft_command(lio_dev, sc);
872 if (retval == LIO_IQ_SEND_FAILED) {
873 lio_dev_err(lio_dev, "iq/oq config failed status: %x\n",
875 /* Soft instr is freed by driver in case of failure. */
876 goto nic_config_fail;
879 /* Sleep on a wait queue till the cond flag indicates that the
880 * response arrived or timed-out.
882 while ((*sc->status_word == LIO_COMPLETION_WORD_INIT) && --timeout) {
883 lio_flush_iq(lio_dev, lio_dev->instr_queue[sc->iq_no]);
884 lio_process_ordered_list(lio_dev);
888 retval = resp->status;
890 lio_dev_err(lio_dev, "iq/oq config failed\n");
891 goto nic_config_fail;
894 lio_swap_8B_data((uint64_t *)(&resp->cfg_info),
895 sizeof(struct octeon_if_cfg_info) >> 3);
897 num_iqueues = lio_hweight64(resp->cfg_info.iqmask);
898 num_oqueues = lio_hweight64(resp->cfg_info.oqmask);
900 if (!(num_iqueues) || !(num_oqueues)) {
902 "Got bad iqueues (%016lx) or oqueues (%016lx) from firmware.\n",
903 (unsigned long)resp->cfg_info.iqmask,
904 (unsigned long)resp->cfg_info.oqmask);
905 goto nic_config_fail;
909 "interface %d, iqmask %016lx, oqmask %016lx, numiqueues %d, numoqueues %d\n",
910 eth_dev->data->port_id,
911 (unsigned long)resp->cfg_info.iqmask,
912 (unsigned long)resp->cfg_info.oqmask,
913 num_iqueues, num_oqueues);
915 lio_dev->linfo.num_rxpciq = num_oqueues;
916 lio_dev->linfo.num_txpciq = num_iqueues;
918 for (i = 0; i < num_oqueues; i++) {
919 lio_dev->linfo.rxpciq[i].rxpciq64 =
920 resp->cfg_info.linfo.rxpciq[i].rxpciq64;
921 lio_dev_dbg(lio_dev, "index %d OQ %d\n",
922 i, lio_dev->linfo.rxpciq[i].s.q_no);
925 for (i = 0; i < num_iqueues; i++) {
926 lio_dev->linfo.txpciq[i].txpciq64 =
927 resp->cfg_info.linfo.txpciq[i].txpciq64;
928 lio_dev_dbg(lio_dev, "index %d IQ %d\n",
929 i, lio_dev->linfo.txpciq[i].s.q_no);
932 lio_dev->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
933 lio_dev->linfo.gmxport = resp->cfg_info.linfo.gmxport;
934 lio_dev->linfo.link.link_status64 =
935 resp->cfg_info.linfo.link.link_status64;
937 /* 64-bit swap required on LE machines */
938 lio_swap_8B_data(&lio_dev->linfo.hw_addr, 1);
939 for (i = 0; i < ETHER_ADDR_LEN; i++)
940 mac[i] = *((uint8_t *)(((uint8_t *)&lio_dev->linfo.hw_addr) +
943 /* Copy the permanent MAC address */
944 ether_addr_copy((struct ether_addr *)mac, ð_dev->data->mac_addrs[0]);
946 lio_dev->glist_lock =
947 rte_zmalloc(NULL, sizeof(*lio_dev->glist_lock) * num_iqueues, 0);
948 if (lio_dev->glist_lock == NULL)
951 lio_dev->glist_head =
952 rte_zmalloc(NULL, sizeof(*lio_dev->glist_head) * num_iqueues,
954 if (lio_dev->glist_head == NULL) {
955 rte_free(lio_dev->glist_lock);
956 lio_dev->glist_lock = NULL;
960 lio_dev_link_update(eth_dev, 0);
962 lio_dev->port_configured = 1;
964 lio_free_soft_command(sc);
966 /* Disable iq_0 for reconf */
967 lio_dev->fn_list.disable_io_queues(lio_dev);
970 lio_dev->fn_list.setup_device_regs(lio_dev);
972 /* Free iq_0 used during init */
973 lio_free_instr_queue0(lio_dev);
978 lio_dev_err(lio_dev, "Failed retval %d\n", retval);
979 lio_free_soft_command(sc);
980 lio_free_instr_queue0(lio_dev);
985 /* Define our ethernet definitions */
986 static const struct eth_dev_ops liovf_eth_dev_ops = {
987 .dev_configure = lio_dev_configure,
988 .dev_start = lio_dev_start,
989 .link_update = lio_dev_link_update,
990 .rx_queue_setup = lio_dev_rx_queue_setup,
991 .rx_queue_release = lio_dev_rx_queue_release,
992 .tx_queue_setup = lio_dev_tx_queue_setup,
993 .tx_queue_release = lio_dev_tx_queue_release,
994 .reta_update = lio_dev_rss_reta_update,
995 .reta_query = lio_dev_rss_reta_query,
996 .rss_hash_conf_get = lio_dev_rss_hash_conf_get,
997 .rss_hash_update = lio_dev_rss_hash_update,
1001 lio_check_pf_hs_response(void *lio_dev)
1003 struct lio_device *dev = lio_dev;
1005 /* check till response arrives */
1006 if (dev->pfvf_hsword.coproc_tics_per_us)
1009 cn23xx_vf_handle_mbox(dev);
1011 rte_eal_alarm_set(1, lio_check_pf_hs_response, lio_dev);
1015 * \brief Identify the LIO device and to map the BAR address space
1016 * @param lio_dev lio device
1019 lio_chip_specific_setup(struct lio_device *lio_dev)
1021 struct rte_pci_device *pdev = lio_dev->pci_dev;
1022 uint32_t dev_id = pdev->id.device_id;
1027 case LIO_CN23XX_VF_VID:
1028 lio_dev->chip_id = LIO_CN23XX_VF_VID;
1029 ret = cn23xx_vf_setup_device(lio_dev);
1034 lio_dev_err(lio_dev, "Unsupported Chip\n");
1038 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
1044 lio_first_time_init(struct lio_device *lio_dev,
1045 struct rte_pci_device *pdev)
1049 PMD_INIT_FUNC_TRACE();
1051 /* set dpdk specific pci device pointer */
1052 lio_dev->pci_dev = pdev;
1054 /* Identify the LIO type and set device ops */
1055 if (lio_chip_specific_setup(lio_dev)) {
1056 lio_dev_err(lio_dev, "Chip specific setup failed\n");
1060 /* Initialize soft command buffer pool */
1061 if (lio_setup_sc_buffer_pool(lio_dev)) {
1062 lio_dev_err(lio_dev, "sc buffer pool allocation failed\n");
1066 /* Initialize lists to manage the requests of different types that
1067 * arrive from applications for this lio device.
1069 lio_setup_response_list(lio_dev);
1071 if (lio_dev->fn_list.setup_mbox(lio_dev)) {
1072 lio_dev_err(lio_dev, "Mailbox setup failed\n");
1076 /* Check PF response */
1077 lio_check_pf_hs_response((void *)lio_dev);
1079 /* Do handshake and exit if incompatible PF driver */
1080 if (cn23xx_pfvf_handshake(lio_dev))
1084 cn23xx_vf_ask_pf_to_do_flr(lio_dev);
1085 /* Wait for FLR for 100ms per SRIOV specification */
1088 if (cn23xx_vf_set_io_queues_off(lio_dev)) {
1089 lio_dev_err(lio_dev, "Setting io queues off failed\n");
1093 if (lio_dev->fn_list.setup_device_regs(lio_dev)) {
1094 lio_dev_err(lio_dev, "Failed to configure device registers\n");
1098 if (lio_setup_instr_queue0(lio_dev)) {
1099 lio_dev_err(lio_dev, "Failed to setup instruction queue 0\n");
1103 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
1105 lio_dev->max_tx_queues = dpdk_queues;
1106 lio_dev->max_rx_queues = dpdk_queues;
1108 /* Enable input and output queues for this device */
1109 if (lio_dev->fn_list.enable_io_queues(lio_dev))
1115 lio_free_sc_buffer_pool(lio_dev);
1116 if (lio_dev->mbox[0])
1117 lio_dev->fn_list.free_mbox(lio_dev);
1118 if (lio_dev->instr_queue[0])
1119 lio_free_instr_queue0(lio_dev);
1125 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
1127 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1129 PMD_INIT_FUNC_TRACE();
1131 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1134 /* lio_free_sc_buffer_pool */
1135 lio_free_sc_buffer_pool(lio_dev);
1137 rte_free(eth_dev->data->mac_addrs);
1138 eth_dev->data->mac_addrs = NULL;
1140 eth_dev->rx_pkt_burst = NULL;
1141 eth_dev->tx_pkt_burst = NULL;
1147 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
1149 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
1150 struct lio_device *lio_dev = LIO_DEV(eth_dev);
1152 PMD_INIT_FUNC_TRACE();
1154 eth_dev->rx_pkt_burst = &lio_dev_recv_pkts;
1155 eth_dev->tx_pkt_burst = &lio_dev_xmit_pkts;
1157 /* Primary does the initialization. */
1158 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1161 rte_eth_copy_pci_info(eth_dev, pdev);
1162 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1164 if (pdev->mem_resource[0].addr) {
1165 lio_dev->hw_addr = pdev->mem_resource[0].addr;
1167 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
1171 lio_dev->eth_dev = eth_dev;
1172 /* set lio device print string */
1173 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
1174 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
1175 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1177 lio_dev->port_id = eth_dev->data->port_id;
1179 if (lio_first_time_init(lio_dev, pdev)) {
1180 lio_dev_err(lio_dev, "Device init failed\n");
1184 eth_dev->dev_ops = &liovf_eth_dev_ops;
1185 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
1186 if (eth_dev->data->mac_addrs == NULL) {
1187 lio_dev_err(lio_dev,
1188 "MAC addresses memory allocation failed\n");
1189 eth_dev->dev_ops = NULL;
1190 eth_dev->rx_pkt_burst = NULL;
1191 eth_dev->tx_pkt_burst = NULL;
1195 rte_atomic64_set(&lio_dev->status, LIO_DEV_RUNNING);
1198 lio_dev->port_configured = 0;
1199 /* Always allow unicast packets */
1200 lio_dev->ifflags |= LIO_IFFLAG_UNICAST;
1205 /* Set of PCI devices this driver supports */
1206 static const struct rte_pci_id pci_id_liovf_map[] = {
1207 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
1208 { .vendor_id = 0, /* sentinel */ }
1211 static struct eth_driver rte_liovf_pmd = {
1213 .id_table = pci_id_liovf_map,
1214 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1215 .probe = rte_eth_dev_pci_probe,
1216 .remove = rte_eth_dev_pci_remove,
1218 .eth_dev_init = lio_eth_dev_init,
1219 .eth_dev_uninit = lio_eth_dev_uninit,
1220 .dev_private_size = sizeof(struct lio_device),
1223 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
1224 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
1225 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");