2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #include <vnet/vnet.h>
16 #include <vppinfra/vec.h>
17 #include <vppinfra/format.h>
18 #include <vlib/unix/cj.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <dpdk/device/dpdk.h>
24 #include <dpdk/device/dpdk_priv.h>
25 #include <vppinfra/error.h>
28 dpdk_error_return (clib_error_t * error, char *str, dpdk_device_t * xd,
31 return clib_error_return (error, "%s[%d]: %s(%d)", str, xd->device_index,
32 rte_strerror (rv), rv);
36 dpdk_device_setup (dpdk_device_t * xd)
38 dpdk_main_t *dm = &dpdk_main;
39 clib_error_t *err = 0;
43 ASSERT (vlib_get_thread_index () == 0);
45 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
47 vnet_hw_interface_set_flags (dm->vnet_main, xd->hw_if_index, 0);
48 dpdk_device_stop (xd);
51 rv = rte_eth_dev_configure (xd->device_index, xd->rx_q_used,
52 xd->tx_q_used, &xd->port_conf);
55 return dpdk_error_return (err, "rte_eth_dev_configure", xd, rv);
57 /* Set up one TX-queue per worker thread */
58 for (j = 0; j < xd->tx_q_used; j++)
60 rv = rte_eth_tx_queue_setup (xd->device_index, j, xd->nb_tx_desc,
61 xd->cpu_socket, &xd->tx_conf);
63 /* retry with any other CPU socket */
65 rv = rte_eth_tx_queue_setup (xd->device_index, j, xd->nb_tx_desc,
66 SOCKET_ID_ANY, &xd->tx_conf);
68 err = dpdk_error_return (err, "rte_eth_tx_queue_setup", xd, rv);
71 for (j = 0; j < xd->rx_q_used; j++)
73 uword tidx = vnet_get_device_input_thread_index (dm->vnet_main,
75 unsigned lcore = vlib_worker_threads[tidx].lcore_id;
76 u16 socket_id = rte_lcore_to_socket_id (lcore);
78 rv = rte_eth_rx_queue_setup (xd->device_index, j, xd->nb_rx_desc,
80 dm->pktmbuf_pools[socket_id]);
82 /* retry with any other CPU socket */
84 rv = rte_eth_rx_queue_setup (xd->device_index, j, xd->nb_rx_desc,
86 dm->pktmbuf_pools[socket_id]);
89 err = dpdk_error_return (err, "rte_eth_rx_queue_setup", xd, rv);
95 if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
96 err = dpdk_device_start (xd);
102 dpdk_device_start (dpdk_device_t * xd)
105 clib_error_t *err = 0;
107 rv = rte_eth_dev_start (xd->device_index);
110 return dpdk_error_return (err, "rte_eth_dev_start", xd, rv);
112 if (xd->default_mac_address)
114 rte_eth_dev_default_mac_addr_set (xd->device_index,
115 (struct ether_addr *)
116 xd->default_mac_address);
119 err = dpdk_error_return (err, "rte_eth_dev_default_mac_addr_set", xd, rv);
121 if (xd->flags & DPDK_DEVICE_FLAG_PROMISC)
122 rte_eth_promiscuous_enable (xd->device_index);
124 rte_eth_promiscuous_disable (xd->device_index);
126 rte_eth_allmulticast_enable (xd->device_index);
128 if (xd->pmd == VNET_DPDK_PMD_BOND)
131 int nlink = rte_eth_bond_slaves_get (xd->device_index, slink, 16);
134 u8 dpdk_port = slink[--nlink];
135 rte_eth_allmulticast_enable (dpdk_port);
143 dpdk_device_stop (dpdk_device_t * xd)
145 rte_eth_dev_stop (xd->device_index);
151 * fd.io coding-style-patch-verification: ON
154 * eval: (c-set-style "gnu")