2 * Copyright (c) 2015, Mellanox Technologies, Ltd. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #ifndef __MLX5_ESWITCH_H__
34 #define __MLX5_ESWITCH_H__
36 #include <linux/mlx5/device.h>
38 #define MLX5_MAX_UC_PER_VPORT(dev) \
39 (1 << MLX5_CAP_GEN(dev, log_max_current_uc_list))
41 #define MLX5_MAX_MC_PER_VPORT(dev) \
42 (1 << MLX5_CAP_GEN(dev, log_max_current_mc_list))
44 #define MLX5_L2_ADDR_HASH_SIZE (BIT(BITS_PER_BYTE))
45 #define MLX5_L2_ADDR_HASH(addr) (addr[5])
47 /* L2 -mac address based- hash helpers */
49 struct hlist_node hlist;
53 #define for_each_l2hash_node(hn, tmp, hash, i) \
54 for (i = 0; i < MLX5_L2_ADDR_HASH_SIZE; i++) \
55 hlist_for_each_entry_safe(hn, tmp, &hash[i], hlist)
57 #define l2addr_hash_find(hash, mac, type) ({ \
58 int ix = MLX5_L2_ADDR_HASH(mac); \
62 hlist_for_each_entry(ptr, &hash[ix], node.hlist) \
63 if (ether_addr_equal(ptr->node.addr, mac)) {\
72 #define l2addr_hash_add(hash, mac, type, gfp) ({ \
73 int ix = MLX5_L2_ADDR_HASH(mac); \
76 ptr = kzalloc(sizeof(type), gfp); \
78 ether_addr_copy(ptr->node.addr, mac); \
79 hlist_add_head(&ptr->node.hlist, &hash[ix]);\
84 #define l2addr_hash_del(ptr) ({ \
85 hlist_del(&ptr->node.hlist); \
89 struct mlx5_flow_rule {
92 u8 match_criteria_enable;
99 struct mutex mutex; /* protect flow rule updates */
100 struct list_head dest_list;
104 struct mlx5_core_dev *dev;
106 struct hlist_head uc_list[MLX5_L2_ADDR_HASH_SIZE];
107 struct hlist_head mc_list[MLX5_L2_ADDR_HASH_SIZE];
108 struct work_struct vport_change_handler;
110 /* This spinlock protects access to vport data, between
111 * "esw_vport_disable" and ongoing interrupt "mlx5_eswitch_vport_event"
112 * once vport marked as disabled new interrupts are discarded.
114 spinlock_t lock; /* vport events sync */
119 struct mlx5_l2_table {
120 struct hlist_head l2_hash[MLX5_L2_ADDR_HASH_SIZE];
122 unsigned long *bitmap;
125 struct mlx5_eswitch_fdb {
129 struct mlx5_eswitch {
130 struct mlx5_core_dev *dev;
131 struct mlx5_l2_table l2_table;
132 struct mlx5_eswitch_fdb fdb_table;
133 struct hlist_head mc_table[MLX5_L2_ADDR_HASH_SIZE];
134 struct workqueue_struct *work_queue;
135 struct mlx5_vport *vports;
141 int mlx5_eswitch_init(struct mlx5_core_dev *dev);
142 void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw);
143 void mlx5_eswitch_vport_event(struct mlx5_eswitch *esw, struct mlx5_eqe *eqe);
144 int mlx5_eswitch_enable_sriov(struct mlx5_eswitch *esw, int nvfs);
145 void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw);
147 #endif /* __MLX5_ESWITCH_H__ */