1358aa5ceSSaeed Mahameed /*
2358aa5ceSSaeed Mahameed  * Copyright (c) 2016, Mellanox Technologies, Ltd.  All rights reserved.
3358aa5ceSSaeed Mahameed  *
4358aa5ceSSaeed Mahameed  * This software is available to you under a choice of one of two
5358aa5ceSSaeed Mahameed  * licenses.  You may choose to be licensed under the terms of the GNU
6358aa5ceSSaeed Mahameed  * General Public License (GPL) Version 2, available from the file
7358aa5ceSSaeed Mahameed  * COPYING in the main directory of this source tree, or the
8358aa5ceSSaeed Mahameed  * OpenIB.org BSD license below:
9358aa5ceSSaeed Mahameed  *
10358aa5ceSSaeed Mahameed  *     Redistribution and use in source and binary forms, with or
11358aa5ceSSaeed Mahameed  *     without modification, are permitted provided that the following
12358aa5ceSSaeed Mahameed  *     conditions are met:
13358aa5ceSSaeed Mahameed  *
14358aa5ceSSaeed Mahameed  *      - Redistributions of source code must retain the above
15358aa5ceSSaeed Mahameed  *        copyright notice, this list of conditions and the following
16358aa5ceSSaeed Mahameed  *        disclaimer.
17358aa5ceSSaeed Mahameed  *
18358aa5ceSSaeed Mahameed  *      - Redistributions in binary form must reproduce the above
19358aa5ceSSaeed Mahameed  *        copyright notice, this list of conditions and the following
20358aa5ceSSaeed Mahameed  *        disclaimer in the documentation and/or other materials
21358aa5ceSSaeed Mahameed  *        provided with the distribution.
22358aa5ceSSaeed Mahameed  *
23358aa5ceSSaeed Mahameed  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24358aa5ceSSaeed Mahameed  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25358aa5ceSSaeed Mahameed  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26358aa5ceSSaeed Mahameed  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27358aa5ceSSaeed Mahameed  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28358aa5ceSSaeed Mahameed  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29358aa5ceSSaeed Mahameed  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30358aa5ceSSaeed Mahameed  * SOFTWARE.
31358aa5ceSSaeed Mahameed  */
32358aa5ceSSaeed Mahameed #ifndef __MLX5_VXLAN_H__
33358aa5ceSSaeed Mahameed #define __MLX5_VXLAN_H__
34358aa5ceSSaeed Mahameed 
35358aa5ceSSaeed Mahameed #include <linux/mlx5/driver.h>
36358aa5ceSSaeed Mahameed 
37358aa5ceSSaeed Mahameed struct mlx5_vxlan;
38358aa5ceSSaeed Mahameed struct mlx5_vxlan_port;
39358aa5ceSSaeed Mahameed 
mlx5_vxlan_max_udp_ports(struct mlx5_core_dev * mdev)4018a2b7f9SJakub Kicinski static inline u8 mlx5_vxlan_max_udp_ports(struct mlx5_core_dev *mdev)
4118a2b7f9SJakub Kicinski {
4218a2b7f9SJakub Kicinski 	return MLX5_CAP_ETH(mdev, max_vxlan_udp_ports) ?: 4;
4318a2b7f9SJakub Kicinski }
4418a2b7f9SJakub Kicinski 
mlx5_vxlan_allowed(struct mlx5_vxlan * vxlan)45358aa5ceSSaeed Mahameed static inline bool mlx5_vxlan_allowed(struct mlx5_vxlan *vxlan)
46358aa5ceSSaeed Mahameed {
47358aa5ceSSaeed Mahameed 	/* not allowed reason is encoded in vxlan pointer as error,
48358aa5ceSSaeed Mahameed 	 * on mlx5_vxlan_create
49358aa5ceSSaeed Mahameed 	 */
50358aa5ceSSaeed Mahameed 	return !IS_ERR_OR_NULL(vxlan);
51358aa5ceSSaeed Mahameed }
52358aa5ceSSaeed Mahameed 
53c5791ab0SSaeed Mahameed #if IS_ENABLED(CONFIG_VXLAN)
54358aa5ceSSaeed Mahameed struct mlx5_vxlan *mlx5_vxlan_create(struct mlx5_core_dev *mdev);
55358aa5ceSSaeed Mahameed void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan);
56358aa5ceSSaeed Mahameed int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port);
57358aa5ceSSaeed Mahameed int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port);
58efbb974dSSaeed Mahameed bool mlx5_vxlan_lookup_port(struct mlx5_vxlan *vxlan, u16 port);
59*c5eb51adSAya Levin void mlx5_vxlan_reset_to_default(struct mlx5_vxlan *vxlan);
60358aa5ceSSaeed Mahameed #else
61358aa5ceSSaeed Mahameed static inline struct mlx5_vxlan*
mlx5_vxlan_create(struct mlx5_core_dev * mdev)62c5791ab0SSaeed Mahameed mlx5_vxlan_create(struct mlx5_core_dev *mdev) { return ERR_PTR(-EOPNOTSUPP); }
mlx5_vxlan_destroy(struct mlx5_vxlan * vxlan)63358aa5ceSSaeed Mahameed static inline void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan) { return; }
mlx5_vxlan_add_port(struct mlx5_vxlan * vxlan,u16 port)64c5791ab0SSaeed Mahameed static inline int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port) { return -EOPNOTSUPP; }
mlx5_vxlan_del_port(struct mlx5_vxlan * vxlan,u16 port)65c5791ab0SSaeed Mahameed static inline int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port) { return -EOPNOTSUPP; }
mlx5_vxlan_lookup_port(struct mlx5_vxlan * vxlan,u16 port)66efbb974dSSaeed Mahameed static inline bool mlx5_vxlan_lookup_port(struct mlx5_vxlan *vxlan, u16 port) { return false; }
mlx5_vxlan_reset_to_default(struct mlx5_vxlan * vxlan)67*c5eb51adSAya Levin static inline void mlx5_vxlan_reset_to_default(struct mlx5_vxlan *vxlan) { return; }
68358aa5ceSSaeed Mahameed #endif
69358aa5ceSSaeed Mahameed 
70358aa5ceSSaeed Mahameed #endif /* __MLX5_VXLAN_H__ */
71