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