1a551c94aSIdo Barnea/*-
2a551c94aSIdo Barnea *   BSD LICENSE
3a551c94aSIdo Barnea *
4a551c94aSIdo Barnea *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5a551c94aSIdo Barnea *   All rights reserved.
6a551c94aSIdo Barnea *
7a551c94aSIdo Barnea *   Redistribution and use in source and binary forms, with or without
8a551c94aSIdo Barnea *   modification, are permitted provided that the following conditions
9a551c94aSIdo Barnea *   are met:
10a551c94aSIdo Barnea *
11a551c94aSIdo Barnea *     * Redistributions of source code must retain the above copyright
12a551c94aSIdo Barnea *       notice, this list of conditions and the following disclaimer.
13a551c94aSIdo Barnea *     * Redistributions in binary form must reproduce the above copyright
14a551c94aSIdo Barnea *       notice, this list of conditions and the following disclaimer in
15a551c94aSIdo Barnea *       the documentation and/or other materials provided with the
16a551c94aSIdo Barnea *       distribution.
17a551c94aSIdo Barnea *     * Neither the name of Intel Corporation nor the names of its
18a551c94aSIdo Barnea *       contributors may be used to endorse or promote products derived
19a551c94aSIdo Barnea *       from this software without specific prior written permission.
20a551c94aSIdo Barnea *
21a551c94aSIdo Barnea *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22a551c94aSIdo Barnea *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23a551c94aSIdo Barnea *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24a551c94aSIdo Barnea *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25a551c94aSIdo Barnea *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26a551c94aSIdo Barnea *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27a551c94aSIdo Barnea *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28a551c94aSIdo Barnea *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29a551c94aSIdo Barnea *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30a551c94aSIdo Barnea *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31a551c94aSIdo Barnea *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32a551c94aSIdo Barnea */
33a551c94aSIdo Barnea
34a551c94aSIdo Barnea#ifndef _RTE_ETH_BOND_PRIVATE_H_
35a551c94aSIdo Barnea#define _RTE_ETH_BOND_PRIVATE_H_
36a551c94aSIdo Barnea
37a551c94aSIdo Barnea#include <rte_ethdev.h>
38a551c94aSIdo Barnea#include <rte_spinlock.h>
399ca4a157SIdo Barnea#include <rte_bitmap.h>
40a551c94aSIdo Barnea
41a551c94aSIdo Barnea#include "rte_eth_bond.h"
42a551c94aSIdo Barnea#include "rte_eth_bond_8023ad_private.h"
43a551c94aSIdo Barnea#include "rte_eth_bond_alb.h"
44a551c94aSIdo Barnea
45a551c94aSIdo Barnea#define PMD_BOND_SLAVE_PORT_KVARG			("slave")
46a551c94aSIdo Barnea#define PMD_BOND_PRIMARY_SLAVE_KVARG		("primary")
47a551c94aSIdo Barnea#define PMD_BOND_MODE_KVARG					("mode")
48a551c94aSIdo Barnea#define PMD_BOND_XMIT_POLICY_KVARG			("xmit_policy")
49a551c94aSIdo Barnea#define PMD_BOND_SOCKET_ID_KVARG			("socket_id")
50a551c94aSIdo Barnea#define PMD_BOND_MAC_ADDR_KVARG				("mac")
51a551c94aSIdo Barnea#define PMD_BOND_LSC_POLL_PERIOD_KVARG		("lsc_poll_period_ms")
52a551c94aSIdo Barnea#define PMD_BOND_LINK_UP_PROP_DELAY_KVARG	("up_delay")
53a551c94aSIdo Barnea#define PMD_BOND_LINK_DOWN_PROP_DELAY_KVARG	("down_delay")
54a551c94aSIdo Barnea
55a551c94aSIdo Barnea#define PMD_BOND_XMIT_POLICY_LAYER2_KVARG	("l2")
56a551c94aSIdo Barnea#define PMD_BOND_XMIT_POLICY_LAYER23_KVARG	("l23")
57a551c94aSIdo Barnea#define PMD_BOND_XMIT_POLICY_LAYER34_KVARG	("l34")
58a551c94aSIdo Barnea
59a551c94aSIdo Barnea#define RTE_BOND_LOG(lvl, msg, ...)		\
60a551c94aSIdo Barnea	RTE_LOG(lvl, PMD, "%s(%d) - " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
61a551c94aSIdo Barnea
62a551c94aSIdo Barnea#define BONDING_MODE_INVALID 0xFF
63a551c94aSIdo Barnea
64a551c94aSIdo Barneaextern const char *pmd_bond_init_valid_arguments[];
65a551c94aSIdo Barnea
669ca4a157SIdo Barneaextern struct rte_vdev_driver pmd_bond_drv;
67a551c94aSIdo Barnea
68a551c94aSIdo Barnea/** Port Queue Mapping Structure */
69a551c94aSIdo Barneastruct bond_rx_queue {
70a551c94aSIdo Barnea	uint16_t queue_id;
71a551c94aSIdo Barnea	/**< Queue Id */
72a551c94aSIdo Barnea	struct bond_dev_private *dev_private;
73a551c94aSIdo Barnea	/**< Reference to eth_dev private structure */
74a551c94aSIdo Barnea	uint16_t nb_rx_desc;
75a551c94aSIdo Barnea	/**< Number of RX descriptors available for the queue */
76a551c94aSIdo Barnea	struct rte_eth_rxconf rx_conf;
77a551c94aSIdo Barnea	/**< Copy of RX configuration structure for queue */
78a551c94aSIdo Barnea	struct rte_mempool *mb_pool;
79a551c94aSIdo Barnea	/**< Reference to mbuf pool to use for RX queue */
80a551c94aSIdo Barnea};
81a551c94aSIdo Barnea
82a551c94aSIdo Barneastruct bond_tx_queue {
83a551c94aSIdo Barnea	uint16_t queue_id;
84a551c94aSIdo Barnea	/**< Queue Id */
85a551c94aSIdo Barnea	struct bond_dev_private *dev_private;
86a551c94aSIdo Barnea	/**< Reference to dev private structure */
87a551c94aSIdo Barnea	uint16_t nb_tx_desc;
88a551c94aSIdo Barnea	/**< Number of TX descriptors available for the queue */
89a551c94aSIdo Barnea	struct rte_eth_txconf tx_conf;
90a551c94aSIdo Barnea	/**< Copy of TX configuration structure for queue */
91a551c94aSIdo Barnea};
92a551c94aSIdo Barnea
93a551c94aSIdo Barnea/** Bonded slave devices structure */
94a551c94aSIdo Barneastruct bond_ethdev_slave_ports {
95a551c94aSIdo Barnea	uint8_t slaves[RTE_MAX_ETHPORTS];	/**< Slave port id array */
96a551c94aSIdo Barnea	uint8_t slave_count;				/**< Number of slaves */
97a551c94aSIdo Barnea};
98a551c94aSIdo Barnea
99a551c94aSIdo Barneastruct bond_slave_details {
100a551c94aSIdo Barnea	uint8_t port_id;
101a551c94aSIdo Barnea
102a551c94aSIdo Barnea	uint8_t link_status_poll_enabled;
103a551c94aSIdo Barnea	uint8_t link_status_wait_to_complete;
104a551c94aSIdo Barnea	uint8_t last_link_status;
105a551c94aSIdo Barnea	/**< Port Id of slave eth_dev */
106a551c94aSIdo Barnea	struct ether_addr persisted_mac_addr;
107a551c94aSIdo Barnea
108a551c94aSIdo Barnea	uint16_t reta_size;
109a551c94aSIdo Barnea};
110a551c94aSIdo Barnea
111a551c94aSIdo Barnea
112a551c94aSIdo Barneatypedef uint16_t (*xmit_hash_t)(const struct rte_mbuf *buf, uint8_t slave_count);
113a551c94aSIdo Barnea
114a551c94aSIdo Barnea/** Link Bonding PMD device private configuration Structure */
115a551c94aSIdo Barneastruct bond_dev_private {
116a551c94aSIdo Barnea	uint8_t port_id;					/**< Port Id of Bonded Port */
117a551c94aSIdo Barnea	uint8_t mode;						/**< Link Bonding Mode */
118a551c94aSIdo Barnea
119a551c94aSIdo Barnea	rte_spinlock_t lock;
120a551c94aSIdo Barnea
121a551c94aSIdo Barnea	uint8_t primary_port;				/**< Primary Slave Port */
122a551c94aSIdo Barnea	uint8_t current_primary_port;		/**< Primary Slave Port */
123a551c94aSIdo Barnea	uint8_t user_defined_primary_port;
124a551c94aSIdo Barnea	/**< Flag for whether primary port is user defined or not */
125a551c94aSIdo Barnea
126a551c94aSIdo Barnea	uint8_t balance_xmit_policy;
127a551c94aSIdo Barnea	/**< Transmit policy - l2 / l23 / l34 for operation in balance mode */
128a551c94aSIdo Barnea	xmit_hash_t xmit_hash;
129a551c94aSIdo Barnea	/**< Transmit policy hash function */
130a551c94aSIdo Barnea
131a551c94aSIdo Barnea	uint8_t user_defined_mac;
132a551c94aSIdo Barnea	/**< Flag for whether MAC address is user defined or not */
133a551c94aSIdo Barnea	uint8_t promiscuous_en;
134a551c94aSIdo Barnea	/**< Enabled/disable promiscuous mode on bonding device */
135a551c94aSIdo Barnea	uint8_t link_props_set;
136a551c94aSIdo Barnea	/**< flag to denote if the link properties are set */
137a551c94aSIdo Barnea
138a551c94aSIdo Barnea	uint8_t link_status_polling_enabled;
139a551c94aSIdo Barnea	uint32_t link_status_polling_interval_ms;
140a551c94aSIdo Barnea
141a551c94aSIdo Barnea	uint32_t link_down_delay_ms;
142a551c94aSIdo Barnea	uint32_t link_up_delay_ms;
143a551c94aSIdo Barnea
144a551c94aSIdo Barnea	uint16_t nb_rx_queues;			/**< Total number of rx queues */
145a551c94aSIdo Barnea	uint16_t nb_tx_queues;			/**< Total number of tx queues*/
146a551c94aSIdo Barnea
147a551c94aSIdo Barnea	uint8_t active_slave_count;		/**< Number of active slaves */
148a551c94aSIdo Barnea	uint8_t active_slaves[RTE_MAX_ETHPORTS];	/**< Active slave list */
149a551c94aSIdo Barnea
150a551c94aSIdo Barnea	uint8_t slave_count;			/**< Number of bonded slaves */
151a551c94aSIdo Barnea	struct bond_slave_details slaves[RTE_MAX_ETHPORTS];
152a551c94aSIdo Barnea	/**< Arary of bonded slaves details */
153a551c94aSIdo Barnea
154a551c94aSIdo Barnea	struct mode8023ad_private mode4;
155a551c94aSIdo Barnea	uint8_t tlb_slaves_order[RTE_MAX_ETHPORTS]; /* TLB active slaves send order */
156a551c94aSIdo Barnea	struct mode_alb_private mode6;
157a551c94aSIdo Barnea
158a551c94aSIdo Barnea	uint32_t rx_offload_capa;            /** Rx offload capability */
159a551c94aSIdo Barnea	uint32_t tx_offload_capa;            /** Tx offload capability */
160a551c94aSIdo Barnea
161a551c94aSIdo Barnea	/** Bit mask of RSS offloads, the bit offset also means flow type */
162a551c94aSIdo Barnea	uint64_t flow_type_rss_offloads;
163a551c94aSIdo Barnea
164a551c94aSIdo Barnea	uint16_t reta_size;
165a551c94aSIdo Barnea	struct rte_eth_rss_reta_entry64 reta_conf[ETH_RSS_RETA_SIZE_512 /
166a551c94aSIdo Barnea			RTE_RETA_GROUP_SIZE];
167a551c94aSIdo Barnea
168a551c94aSIdo Barnea	uint8_t rss_key[52];				/**< 52-byte hash key buffer. */
169a551c94aSIdo Barnea	uint8_t rss_key_len;				/**< hash key length in bytes. */
170a551c94aSIdo Barnea
171a551c94aSIdo Barnea	struct rte_kvargs *kvlist;
172a551c94aSIdo Barnea	uint8_t slave_update_idx;
173a551c94aSIdo Barnea
174a551c94aSIdo Barnea	uint32_t candidate_max_rx_pktlen;
175a551c94aSIdo Barnea	uint32_t max_rx_pktlen;
1769ca4a157SIdo Barnea
1779ca4a157SIdo Barnea	void *vlan_filter_bmpmem;		/* enabled vlan filter bitmap */
1789ca4a157SIdo Barnea	struct rte_bitmap *vlan_filter_bmp;
179a551c94aSIdo Barnea};
180a551c94aSIdo Barnea
181a551c94aSIdo Barneaextern const struct eth_dev_ops default_dev_ops;
182a551c94aSIdo Barnea
183a551c94aSIdo Barneaint
184a551c94aSIdo Barneacheck_for_bonded_ethdev(const struct rte_eth_dev *eth_dev);
185a551c94aSIdo Barnea
186a551c94aSIdo Barnea/* Search given slave array to find possition of given id.
187a551c94aSIdo Barnea * Return slave pos or slaves_count if not found. */
188a551c94aSIdo Barneastatic inline uint8_t
189a551c94aSIdo Barneafind_slave_by_id(uint8_t *slaves, uint8_t slaves_count, uint8_t slave_id) {
190a551c94aSIdo Barnea
191a551c94aSIdo Barnea	uint8_t pos;
192a551c94aSIdo Barnea	for (pos = 0; pos < slaves_count; pos++) {
193a551c94aSIdo Barnea		if (slave_id == slaves[pos])
194a551c94aSIdo Barnea			break;
195a551c94aSIdo Barnea	}
196a551c94aSIdo Barnea
197a551c94aSIdo Barnea	return pos;
198a551c94aSIdo Barnea}
199a551c94aSIdo Barnea
200a551c94aSIdo Barneaint
201a551c94aSIdo Barneavalid_port_id(uint8_t port_id);
202a551c94aSIdo Barnea
203a551c94aSIdo Barneaint
204a551c94aSIdo Barneavalid_bonded_port_id(uint8_t port_id);
205a551c94aSIdo Barnea
206a551c94aSIdo Barneaint
207a551c94aSIdo Barneavalid_slave_port_id(uint8_t port_id);
208a551c94aSIdo Barnea
209a551c94aSIdo Barneavoid
210a551c94aSIdo Barneadeactivate_slave(struct rte_eth_dev *eth_dev, uint8_t port_id);
211a551c94aSIdo Barnea
212a551c94aSIdo Barneavoid
213a551c94aSIdo Barneaactivate_slave(struct rte_eth_dev *eth_dev, uint8_t port_id);
214a551c94aSIdo Barnea
215a551c94aSIdo Barneavoid
216a551c94aSIdo Barnealink_properties_set(struct rte_eth_dev *bonded_eth_dev,
217a551c94aSIdo Barnea		struct rte_eth_link *slave_dev_link);
218a551c94aSIdo Barneavoid
219a551c94aSIdo Barnealink_properties_reset(struct rte_eth_dev *bonded_eth_dev);
220a551c94aSIdo Barnea
221a551c94aSIdo Barneaint
222a551c94aSIdo Barnealink_properties_valid(struct rte_eth_link *bonded_dev_link,
223a551c94aSIdo Barnea		struct rte_eth_link *slave_dev_link);
224a551c94aSIdo Barnea
225a551c94aSIdo Barneaint
226a551c94aSIdo Barneamac_address_set(struct rte_eth_dev *eth_dev, struct ether_addr *new_mac_addr);
227a551c94aSIdo Barnea
228a551c94aSIdo Barneaint
229a551c94aSIdo Barneamac_address_get(struct rte_eth_dev *eth_dev, struct ether_addr *dst_mac_addr);
230a551c94aSIdo Barnea
231a551c94aSIdo Barneaint
232a551c94aSIdo Barneamac_address_slaves_update(struct rte_eth_dev *bonded_eth_dev);
233a551c94aSIdo Barnea
234a551c94aSIdo Barneauint8_t
235a551c94aSIdo Barneanumber_of_sockets(void);
236a551c94aSIdo Barnea
237a551c94aSIdo Barneaint
238a551c94aSIdo Barneabond_ethdev_mode_set(struct rte_eth_dev *eth_dev, int mode);
239a551c94aSIdo Barnea
240a551c94aSIdo Barneaint
241a551c94aSIdo Barneaslave_configure(struct rte_eth_dev *bonded_eth_dev,
242a551c94aSIdo Barnea		struct rte_eth_dev *slave_eth_dev);
243a551c94aSIdo Barnea
244a551c94aSIdo Barneavoid
245a551c94aSIdo Barneaslave_remove(struct bond_dev_private *internals,
246a551c94aSIdo Barnea		struct rte_eth_dev *slave_eth_dev);
247a551c94aSIdo Barnea
248a551c94aSIdo Barneavoid
249a551c94aSIdo Barneaslave_add(struct bond_dev_private *internals,
250a551c94aSIdo Barnea		struct rte_eth_dev *slave_eth_dev);
251a551c94aSIdo Barnea
252a551c94aSIdo Barneauint16_t
253a551c94aSIdo Barneaxmit_l2_hash(const struct rte_mbuf *buf, uint8_t slave_count);
254a551c94aSIdo Barnea
255a551c94aSIdo Barneauint16_t
256a551c94aSIdo Barneaxmit_l23_hash(const struct rte_mbuf *buf, uint8_t slave_count);
257a551c94aSIdo Barnea
258a551c94aSIdo Barneauint16_t
259a551c94aSIdo Barneaxmit_l34_hash(const struct rte_mbuf *buf, uint8_t slave_count);
260a551c94aSIdo Barnea
261a551c94aSIdo Barneavoid
262a551c94aSIdo Barneabond_ethdev_primary_set(struct bond_dev_private *internals,
263a551c94aSIdo Barnea		uint8_t slave_port_id);
264a551c94aSIdo Barnea
265a551c94aSIdo Barneavoid
266a551c94aSIdo Barneabond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_eth_event_type type,
267a551c94aSIdo Barnea		void *param);
268a551c94aSIdo Barnea
269a551c94aSIdo Barneaint
270a551c94aSIdo Barneabond_ethdev_parse_slave_port_kvarg(const char *key __rte_unused,
271a551c94aSIdo Barnea		const char *value, void *extra_args);
272a551c94aSIdo Barnea
273a551c94aSIdo Barneaint
274a551c94aSIdo Barneabond_ethdev_parse_slave_mode_kvarg(const char *key __rte_unused,
275a551c94aSIdo Barnea		const char *value, void *extra_args);
276a551c94aSIdo Barnea
277a551c94aSIdo Barneaint
278a551c94aSIdo Barneabond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused,
279a551c94aSIdo Barnea		const char *value, void *extra_args);
280a551c94aSIdo Barnea
281a551c94aSIdo Barneaint
282a551c94aSIdo Barneabond_ethdev_parse_primary_slave_port_id_kvarg(const char *key __rte_unused,
283a551c94aSIdo Barnea		const char *value, void *extra_args);
284a551c94aSIdo Barnea
285a551c94aSIdo Barneaint
286a551c94aSIdo Barneabond_ethdev_parse_balance_xmit_policy_kvarg(const char *key __rte_unused,
287a551c94aSIdo Barnea		const char *value, void *extra_args);
288a551c94aSIdo Barnea
289a551c94aSIdo Barneaint
290a551c94aSIdo Barneabond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
291a551c94aSIdo Barnea		const char *value, void *extra_args);
292a551c94aSIdo Barnea
293a551c94aSIdo Barneaint
294a551c94aSIdo Barneabond_ethdev_parse_time_ms_kvarg(const char *key __rte_unused,
295a551c94aSIdo Barnea		const char *value, void *extra_args);
296a551c94aSIdo Barnea
297a551c94aSIdo Barneavoid
298a551c94aSIdo Barneabond_tlb_disable(struct bond_dev_private *internals);
299a551c94aSIdo Barnea
300a551c94aSIdo Barneavoid
301a551c94aSIdo Barneabond_tlb_enable(struct bond_dev_private *internals);
302a551c94aSIdo Barnea
303a551c94aSIdo Barneavoid
304a551c94aSIdo Barneabond_tlb_activate_slave(struct bond_dev_private *internals);
305a551c94aSIdo Barnea
306a551c94aSIdo Barneavoid
307a551c94aSIdo Barneabond_ethdev_stop(struct rte_eth_dev *eth_dev);
308a551c94aSIdo Barnea
309a551c94aSIdo Barneavoid
310a551c94aSIdo Barneabond_ethdev_close(struct rte_eth_dev *dev);
311a551c94aSIdo Barnea
312a551c94aSIdo Barnea#endif
313