net/bonding: switch to new offloading API
[dpdk.git] / drivers / net / bonding / rte_eth_bond_private.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4
5 #ifndef _RTE_ETH_BOND_PRIVATE_H_
6 #define _RTE_ETH_BOND_PRIVATE_H_
7
8 #include <rte_ethdev_driver.h>
9 #include <rte_spinlock.h>
10 #include <rte_bitmap.h>
11
12 #include "rte_eth_bond.h"
13 #include "rte_eth_bond_8023ad_private.h"
14 #include "rte_eth_bond_alb.h"
15
16 #define PMD_BOND_SLAVE_PORT_KVARG                       ("slave")
17 #define PMD_BOND_PRIMARY_SLAVE_KVARG            ("primary")
18 #define PMD_BOND_MODE_KVARG                                     ("mode")
19 #define PMD_BOND_AGG_MODE_KVARG                         ("agg_mode")
20 #define PMD_BOND_XMIT_POLICY_KVARG                      ("xmit_policy")
21 #define PMD_BOND_SOCKET_ID_KVARG                        ("socket_id")
22 #define PMD_BOND_MAC_ADDR_KVARG                         ("mac")
23 #define PMD_BOND_LSC_POLL_PERIOD_KVARG          ("lsc_poll_period_ms")
24 #define PMD_BOND_LINK_UP_PROP_DELAY_KVARG       ("up_delay")
25 #define PMD_BOND_LINK_DOWN_PROP_DELAY_KVARG     ("down_delay")
26
27 #define PMD_BOND_XMIT_POLICY_LAYER2_KVARG       ("l2")
28 #define PMD_BOND_XMIT_POLICY_LAYER23_KVARG      ("l23")
29 #define PMD_BOND_XMIT_POLICY_LAYER34_KVARG      ("l34")
30
31 #define RTE_BOND_LOG(lvl, msg, ...)             \
32         RTE_LOG(lvl, PMD, "%s(%d) - " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
33
34 #define BONDING_MODE_INVALID 0xFF
35
36 extern const char *pmd_bond_init_valid_arguments[];
37
38 extern struct rte_vdev_driver pmd_bond_drv;
39
40 /** Port Queue Mapping Structure */
41 struct bond_rx_queue {
42         uint16_t queue_id;
43         /**< Queue Id */
44         struct bond_dev_private *dev_private;
45         /**< Reference to eth_dev private structure */
46         uint16_t nb_rx_desc;
47         /**< Number of RX descriptors available for the queue */
48         struct rte_eth_rxconf rx_conf;
49         /**< Copy of RX configuration structure for queue */
50         struct rte_mempool *mb_pool;
51         /**< Reference to mbuf pool to use for RX queue */
52 };
53
54 struct bond_tx_queue {
55         uint16_t queue_id;
56         /**< Queue Id */
57         struct bond_dev_private *dev_private;
58         /**< Reference to dev private structure */
59         uint16_t nb_tx_desc;
60         /**< Number of TX descriptors available for the queue */
61         struct rte_eth_txconf tx_conf;
62         /**< Copy of TX configuration structure for queue */
63 };
64
65 /** Bonded slave devices structure */
66 struct bond_ethdev_slave_ports {
67         uint16_t slaves[RTE_MAX_ETHPORTS];      /**< Slave port id array */
68         uint16_t slave_count;                           /**< Number of slaves */
69 };
70
71 struct bond_slave_details {
72         uint16_t port_id;
73
74         uint8_t link_status_poll_enabled;
75         uint8_t link_status_wait_to_complete;
76         uint8_t last_link_status;
77         /**< Port Id of slave eth_dev */
78         struct ether_addr persisted_mac_addr;
79
80         uint16_t reta_size;
81 };
82
83 typedef void (*burst_xmit_hash_t)(struct rte_mbuf **buf, uint16_t nb_pkts,
84                 uint8_t slave_count, uint16_t *slaves);
85
86 /** Link Bonding PMD device private configuration Structure */
87 struct bond_dev_private {
88         uint16_t port_id;                       /**< Port Id of Bonded Port */
89         uint8_t mode;                                           /**< Link Bonding Mode */
90
91         rte_spinlock_t lock;
92
93         uint16_t primary_port;                  /**< Primary Slave Port */
94         uint16_t current_primary_port;          /**< Primary Slave Port */
95         uint16_t user_defined_primary_port;
96         /**< Flag for whether primary port is user defined or not */
97
98         uint8_t balance_xmit_policy;
99         /**< Transmit policy - l2 / l23 / l34 for operation in balance mode */
100         burst_xmit_hash_t burst_xmit_hash;
101         /**< Transmit policy hash function */
102
103         uint8_t user_defined_mac;
104         /**< Flag for whether MAC address is user defined or not */
105         uint8_t promiscuous_en;
106         /**< Enabled/disable promiscuous mode on bonding device */
107
108
109         uint8_t link_status_polling_enabled;
110         uint32_t link_status_polling_interval_ms;
111
112         uint32_t link_down_delay_ms;
113         uint32_t link_up_delay_ms;
114
115         uint16_t nb_rx_queues;                  /**< Total number of rx queues */
116         uint16_t nb_tx_queues;                  /**< Total number of tx queues*/
117
118         uint16_t active_slave;          /**< Next active_slave to poll */
119         uint16_t active_slave_count;            /**< Number of active slaves */
120         uint16_t active_slaves[RTE_MAX_ETHPORTS];    /**< Active slave list */
121
122         uint16_t slave_count;                   /**< Number of bonded slaves */
123         struct bond_slave_details slaves[RTE_MAX_ETHPORTS];
124         /**< Arary of bonded slaves details */
125
126         struct mode8023ad_private mode4;
127         uint16_t tlb_slaves_order[RTE_MAX_ETHPORTS];
128         /**< TLB active slaves send order */
129         struct mode_alb_private mode6;
130
131         uint64_t rx_offload_capa;       /** Rx offload capability */
132         uint64_t tx_offload_capa;       /** Tx offload capability */
133         uint64_t rx_queue_offload_capa; /** per queue Rx offload capability */
134         uint64_t tx_queue_offload_capa; /** per queue Tx offload capability */
135
136         /** Bit mask of RSS offloads, the bit offset also means flow type */
137         uint64_t flow_type_rss_offloads;
138
139         uint16_t reta_size;
140         struct rte_eth_rss_reta_entry64 reta_conf[ETH_RSS_RETA_SIZE_512 /
141                         RTE_RETA_GROUP_SIZE];
142
143         uint8_t rss_key[52];                            /**< 52-byte hash key buffer. */
144         uint8_t rss_key_len;                            /**< hash key length in bytes. */
145
146         struct rte_kvargs *kvlist;
147         uint8_t slave_update_idx;
148
149         uint32_t candidate_max_rx_pktlen;
150         uint32_t max_rx_pktlen;
151
152         void *vlan_filter_bmpmem;               /* enabled vlan filter bitmap */
153         struct rte_bitmap *vlan_filter_bmp;
154 };
155
156 extern const struct eth_dev_ops default_dev_ops;
157
158 int
159 check_for_master_bonded_ethdev(const struct rte_eth_dev *eth_dev);
160
161 int
162 check_for_bonded_ethdev(const struct rte_eth_dev *eth_dev);
163
164 /* Search given slave array to find position of given id.
165  * Return slave pos or slaves_count if not found. */
166 static inline uint16_t
167 find_slave_by_id(uint16_t *slaves, uint16_t slaves_count, uint16_t slave_id) {
168
169         uint16_t pos;
170         for (pos = 0; pos < slaves_count; pos++) {
171                 if (slave_id == slaves[pos])
172                         break;
173         }
174
175         return pos;
176 }
177
178 int
179 valid_port_id(uint16_t port_id);
180
181 int
182 valid_bonded_port_id(uint16_t port_id);
183
184 int
185 valid_slave_port_id(uint16_t port_id, uint8_t mode);
186
187 void
188 deactivate_slave(struct rte_eth_dev *eth_dev, uint16_t port_id);
189
190 void
191 activate_slave(struct rte_eth_dev *eth_dev, uint16_t port_id);
192
193 void
194 link_properties_set(struct rte_eth_dev *bonded_eth_dev,
195                 struct rte_eth_link *slave_dev_link);
196 int
197 link_properties_valid(struct rte_eth_dev *bonded_eth_dev,
198                 struct rte_eth_link *slave_dev_link);
199
200 int
201 mac_address_set(struct rte_eth_dev *eth_dev, struct ether_addr *new_mac_addr);
202
203 int
204 mac_address_get(struct rte_eth_dev *eth_dev, struct ether_addr *dst_mac_addr);
205
206 int
207 mac_address_slaves_update(struct rte_eth_dev *bonded_eth_dev);
208
209 int
210 bond_ethdev_mode_set(struct rte_eth_dev *eth_dev, int mode);
211
212 int
213 slave_configure(struct rte_eth_dev *bonded_eth_dev,
214                 struct rte_eth_dev *slave_eth_dev);
215
216 void
217 slave_remove(struct bond_dev_private *internals,
218                 struct rte_eth_dev *slave_eth_dev);
219
220 void
221 slave_add(struct bond_dev_private *internals,
222                 struct rte_eth_dev *slave_eth_dev);
223
224 void
225 burst_xmit_l2_hash(struct rte_mbuf **buf, uint16_t nb_pkts,
226                 uint8_t slave_count, uint16_t *slaves);
227
228 void
229 burst_xmit_l23_hash(struct rte_mbuf **buf, uint16_t nb_pkts,
230                 uint8_t slave_count, uint16_t *slaves);
231
232 void
233 burst_xmit_l34_hash(struct rte_mbuf **buf, uint16_t nb_pkts,
234                 uint8_t slave_count, uint16_t *slaves);
235
236
237 void
238 bond_ethdev_primary_set(struct bond_dev_private *internals,
239                 uint16_t slave_port_id);
240
241 int
242 bond_ethdev_lsc_event_callback(uint16_t port_id, enum rte_eth_event_type type,
243                 void *param, void *ret_param);
244
245 int
246 bond_ethdev_parse_slave_port_kvarg(const char *key,
247                 const char *value, void *extra_args);
248
249 int
250 bond_ethdev_parse_slave_mode_kvarg(const char *key,
251                 const char *value, void *extra_args);
252
253 int
254 bond_ethdev_parse_slave_agg_mode_kvarg(const char *key __rte_unused,
255                 const char *value, void *extra_args);
256
257 int
258 bond_ethdev_parse_socket_id_kvarg(const char *key,
259                 const char *value, void *extra_args);
260
261 int
262 bond_ethdev_parse_primary_slave_port_id_kvarg(const char *key,
263                 const char *value, void *extra_args);
264
265 int
266 bond_ethdev_parse_balance_xmit_policy_kvarg(const char *key,
267                 const char *value, void *extra_args);
268
269 int
270 bond_ethdev_parse_bond_mac_addr_kvarg(const char *key,
271                 const char *value, void *extra_args);
272
273 int
274 bond_ethdev_parse_time_ms_kvarg(const char *key,
275                 const char *value, void *extra_args);
276
277 void
278 bond_tlb_disable(struct bond_dev_private *internals);
279
280 void
281 bond_tlb_enable(struct bond_dev_private *internals);
282
283 void
284 bond_tlb_activate_slave(struct bond_dev_private *internals);
285
286 void
287 bond_ethdev_stop(struct rte_eth_dev *eth_dev);
288
289 void
290 bond_ethdev_close(struct rte_eth_dev *dev);
291
292 #endif