4 * Copyright 2017 6WIND S.A.
5 * Copyright 2017 Mellanox.
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 6WIND S.A. 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 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 #ifndef _RTE_ETH_FAILSAFE_PRIVATE_H_
35 #define _RTE_ETH_FAILSAFE_PRIVATE_H_
37 #include <sys/queue.h>
40 #include <rte_ethdev.h>
41 #include <rte_devargs.h>
43 #define FAILSAFE_DRIVER_NAME "Fail-safe PMD"
45 #define PMD_FAILSAFE_MAC_KVARG "mac"
46 #define PMD_FAILSAFE_HOTPLUG_POLL_KVARG "hotplug_poll"
47 #define PMD_FAILSAFE_PARAM_STRING \
49 "exec(<shell command>)," \
54 #define FAILSAFE_HOTPLUG_DEFAULT_TIMEOUT_MS 2000
56 #define FAILSAFE_MAX_ETHPORTS 2
57 #define FAILSAFE_MAX_ETHADDR 128
64 /* id of last sub_device polled */
66 unsigned int socket_id;
67 struct rte_eth_rxq_info info;
73 unsigned int socket_id;
74 struct rte_eth_txq_info info;
78 TAILQ_ENTRY(rte_flow) next;
80 struct rte_flow *flows[FAILSAFE_MAX_ETHPORTS];
81 /* flow description for synchronization */
82 struct rte_flow_desc *fd;
94 /* Exhaustive DPDK device description */
95 struct rte_devargs devargs;
97 struct rte_device *dev;
98 struct rte_eth_dev *edev;
100 /* Device state machine */
101 enum dev_state state;
102 /* Some device are defined as a command line */
107 struct rte_eth_dev *dev;
109 * Set of sub_devices.
110 * subs[0] is the preferred device
111 * any other is just another slave
113 struct sub_device *subs;
114 uint8_t subs_head; /* if head == tail, no subs */
115 uint8_t subs_tail; /* first invalid */
116 uint8_t subs_tx; /* current emitting device */
117 uint8_t current_probed;
119 TAILQ_HEAD(sub_flows, rte_flow) flow_list;
120 /* current number of mac_addr slots allocated. */
121 uint32_t nb_mac_addr;
122 struct ether_addr mac_addrs[FAILSAFE_MAX_ETHADDR];
123 uint32_t mac_addr_pool[FAILSAFE_MAX_ETHADDR];
124 /* current capabilities */
125 struct rte_eth_dev_info infos;
127 * Fail-safe state machine.
128 * This level will be tracking state of the EAL and eth
129 * layer at large as defined by the user application.
130 * It will then steer the sub_devices toward the same
131 * synchronized state.
133 enum dev_state state;
134 unsigned int pending_alarm:1; /* An alarm is pending */
139 int failsafe_hotplug_alarm_install(struct rte_eth_dev *dev);
140 int failsafe_hotplug_alarm_cancel(struct rte_eth_dev *dev);
144 void set_burst_fn(struct rte_eth_dev *dev, int force_safe);
146 uint16_t failsafe_rx_burst(void *rxq,
147 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
148 uint16_t failsafe_tx_burst(void *txq,
149 struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
151 uint16_t failsafe_rx_burst_fast(void *rxq,
152 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
153 uint16_t failsafe_tx_burst_fast(void *txq,
154 struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
158 int failsafe_args_parse(struct rte_eth_dev *dev, const char *params);
159 void failsafe_args_free(struct rte_eth_dev *dev);
160 int failsafe_args_count_subdevice(struct rte_eth_dev *dev, const char *params);
161 int failsafe_args_parse_subs(struct rte_eth_dev *dev);
165 int failsafe_eal_init(struct rte_eth_dev *dev);
166 int failsafe_eal_uninit(struct rte_eth_dev *dev);
170 int failsafe_eth_dev_state_sync(struct rte_eth_dev *dev);
174 extern const char pmd_failsafe_driver_name[];
175 extern const struct eth_dev_ops failsafe_ops;
176 extern const struct rte_flow_ops fs_flow_ops;
177 extern uint64_t hotplug_poll;
178 extern int mac_from_arg;
182 /* dev: (struct rte_eth_dev *) fail-safe device */
184 ((struct fs_priv *)(dev)->data->dev_private)
186 /* sdev: (struct sub_device *) */
190 /* sdev: (struct sub_device *) */
191 #define PORT_ID(sdev) \
192 (ETH(sdev)->data->port_id)
194 /* sdev: (struct sub_device *) */
195 #define SUB_ID(sdev) \
199 * Stateful iterator construct over fail-safe sub-devices:
200 * s: (struct sub_device *), iterator
201 * i: (uint8_t), increment
202 * dev: (struct rte_eth_dev *), fail-safe ethdev
203 * state: (enum dev_state), minimum acceptable device state
205 #define FOREACH_SUBDEV_STATE(s, i, dev, state) \
206 for (i = fs_find_next((dev), 0, state); \
207 i < PRIV(dev)->subs_tail && (s = &PRIV(dev)->subs[i]); \
208 i = fs_find_next((dev), i + 1, state))
211 * Iterator construct over fail-safe sub-devices:
212 * s: (struct sub_device *), iterator
213 * i: (uint8_t), increment
214 * dev: (struct rte_eth_dev *), fail-safe ethdev
216 #define FOREACH_SUBDEV(s, i, dev) \
217 FOREACH_SUBDEV_STATE(s, i, dev, DEV_UNDEFINED)
219 /* dev: (struct rte_eth_dev *) fail-safe device */
220 #define PREFERRED_SUBDEV(dev) \
221 (&PRIV(dev)->subs[0])
223 /* dev: (struct rte_eth_dev *) fail-safe device */
224 #define TX_SUBDEV(dev) \
225 (PRIV(dev)->subs_tx >= PRIV(dev)->subs_tail ? NULL \
226 : (PRIV(dev)->subs[PRIV(dev)->subs_tx].state < DEV_PROBED ? NULL \
227 : &PRIV(dev)->subs[PRIV(dev)->subs_tx]))
230 * s: (struct sub_device *)
231 * ops: (struct eth_dev_ops) member
233 #define SUBOPS(s, ops) \
234 (ETH(s)->dev_ops->ops)
236 #define LOG__(level, m, ...) \
237 RTE_LOG(level, PMD, "net_failsafe: " m "%c", __VA_ARGS__)
238 #define LOG_(level, ...) LOG__(level, __VA_ARGS__, '\n')
239 #define DEBUG(...) LOG_(DEBUG, __VA_ARGS__)
240 #define INFO(...) LOG_(INFO, __VA_ARGS__)
241 #define WARN(...) LOG_(WARNING, __VA_ARGS__)
242 #define ERROR(...) LOG_(ERR, __VA_ARGS__)
244 /* inlined functions */
246 static inline uint8_t
247 fs_find_next(struct rte_eth_dev *dev, uint8_t sid,
248 enum dev_state min_state)
250 while (sid < PRIV(dev)->subs_tail) {
251 if (PRIV(dev)->subs[sid].state >= min_state)
255 if (sid >= PRIV(dev)->subs_tail)
256 return PRIV(dev)->subs_tail;
261 fs_switch_dev(struct rte_eth_dev *dev)
263 enum dev_state req_state;
265 req_state = PRIV(dev)->state;
266 if (PREFERRED_SUBDEV(dev)->state >= req_state) {
267 if (TX_SUBDEV(dev) != PREFERRED_SUBDEV(dev) &&
268 (TX_SUBDEV(dev) == NULL ||
269 (req_state == DEV_STARTED) ||
270 (TX_SUBDEV(dev) && TX_SUBDEV(dev)->state < DEV_STARTED))) {
271 DEBUG("Switching tx_dev to preferred sub_device");
272 PRIV(dev)->subs_tx = 0;
274 } else if ((TX_SUBDEV(dev) && TX_SUBDEV(dev)->state < req_state) ||
275 TX_SUBDEV(dev) == NULL) {
276 struct sub_device *sdev;
279 /* Using acceptable device */
280 FOREACH_SUBDEV_STATE(sdev, i, dev, req_state) {
281 DEBUG("Switching tx_dev to sub_device %d",
283 PRIV(dev)->subs_tx = i;
286 } else if (TX_SUBDEV(dev) && TX_SUBDEV(dev)->state < req_state) {
287 DEBUG("No device ready, deactivating tx_dev");
288 PRIV(dev)->subs_tx = PRIV(dev)->subs_tail;
292 set_burst_fn(dev, 0);
296 #endif /* _RTE_ETH_FAILSAFE_PRIVATE_H_ */