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_
38 #include <rte_ethdev.h>
39 #include <rte_devargs.h>
41 #define FAILSAFE_DRIVER_NAME "Fail-safe PMD"
43 #define PMD_FAILSAFE_MAC_KVARG "mac"
44 #define PMD_FAILSAFE_PARAM_STRING \
49 #define FAILSAFE_MAX_ETHPORTS 2
50 #define FAILSAFE_MAX_ETHADDR 128
57 /* id of last sub_device polled */
59 unsigned int socket_id;
60 struct rte_eth_rxq_info info;
66 unsigned int socket_id;
67 struct rte_eth_txq_info info;
79 /* Exhaustive DPDK device description */
80 struct rte_devargs devargs;
82 struct rte_device *dev;
83 struct rte_eth_dev *edev;
84 /* Device state machine */
89 struct rte_eth_dev *dev;
92 * subs[0] is the preferred device
93 * any other is just another slave
95 struct sub_device *subs;
96 uint8_t subs_head; /* if head == tail, no subs */
97 uint8_t subs_tail; /* first invalid */
98 uint8_t subs_tx; /* current emitting device */
99 uint8_t current_probed;
100 /* current number of mac_addr slots allocated. */
101 uint32_t nb_mac_addr;
102 struct ether_addr mac_addrs[FAILSAFE_MAX_ETHADDR];
103 uint32_t mac_addr_pool[FAILSAFE_MAX_ETHADDR];
104 /* current capabilities */
105 struct rte_eth_dev_info infos;
110 uint16_t failsafe_rx_burst(void *rxq,
111 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
112 uint16_t failsafe_tx_burst(void *txq,
113 struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
117 int failsafe_args_parse(struct rte_eth_dev *dev, const char *params);
118 void failsafe_args_free(struct rte_eth_dev *dev);
119 int failsafe_args_count_subdevice(struct rte_eth_dev *dev, const char *params);
123 int failsafe_eal_init(struct rte_eth_dev *dev);
124 int failsafe_eal_uninit(struct rte_eth_dev *dev);
128 extern const char pmd_failsafe_driver_name[];
129 extern const struct eth_dev_ops failsafe_ops;
130 extern int mac_from_arg;
134 /* dev: (struct rte_eth_dev *) fail-safe device */
136 ((struct fs_priv *)(dev)->data->dev_private)
138 /* sdev: (struct sub_device *) */
142 /* sdev: (struct sub_device *) */
143 #define PORT_ID(sdev) \
144 (ETH(sdev)->data->port_id)
147 * Stateful iterator construct over fail-safe sub-devices:
148 * s: (struct sub_device *), iterator
149 * i: (uint8_t), increment
150 * dev: (struct rte_eth_dev *), fail-safe ethdev
151 * state: (enum dev_state), minimum acceptable device state
153 #define FOREACH_SUBDEV_STATE(s, i, dev, state) \
154 for (i = fs_find_next((dev), 0, state); \
155 i < PRIV(dev)->subs_tail && (s = &PRIV(dev)->subs[i]); \
156 i = fs_find_next((dev), i + 1, state))
159 * Iterator construct over fail-safe sub-devices:
160 * s: (struct sub_device *), iterator
161 * i: (uint8_t), increment
162 * dev: (struct rte_eth_dev *), fail-safe ethdev
164 #define FOREACH_SUBDEV(s, i, dev) \
165 FOREACH_SUBDEV_STATE(s, i, dev, DEV_UNDEFINED)
167 /* dev: (struct rte_eth_dev *) fail-safe device */
168 #define PREFERRED_SUBDEV(dev) \
169 (&PRIV(dev)->subs[0])
171 /* dev: (struct rte_eth_dev *) fail-safe device */
172 #define TX_SUBDEV(dev) \
173 (PRIV(dev)->subs_tx >= PRIV(dev)->subs_tail ? NULL \
174 : (PRIV(dev)->subs[PRIV(dev)->subs_tx].state < DEV_PROBED ? NULL \
175 : &PRIV(dev)->subs[PRIV(dev)->subs_tx]))
178 * s: (struct sub_device *)
179 * ops: (struct eth_dev_ops) member
181 #define SUBOPS(s, ops) \
182 (ETH(s)->dev_ops->ops)
184 #define LOG__(level, m, ...) \
185 RTE_LOG(level, PMD, "net_failsafe: " m "%c", __VA_ARGS__)
186 #define LOG_(level, ...) LOG__(level, __VA_ARGS__, '\n')
187 #define DEBUG(...) LOG_(DEBUG, __VA_ARGS__)
188 #define INFO(...) LOG_(INFO, __VA_ARGS__)
189 #define WARN(...) LOG_(WARNING, __VA_ARGS__)
190 #define ERROR(...) LOG_(ERR, __VA_ARGS__)
192 /* inlined functions */
194 static inline uint8_t
195 fs_find_next(struct rte_eth_dev *dev, uint8_t sid,
196 enum dev_state min_state)
198 while (sid < PRIV(dev)->subs_tail) {
199 if (PRIV(dev)->subs[sid].state >= min_state)
203 if (sid >= PRIV(dev)->subs_tail)
204 return PRIV(dev)->subs_tail;
208 #endif /* _RTE_ETH_FAILSAFE_PRIVATE_H_ */