Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2017, Mellanox Technologies, Ltd.  All rights reserved.
0003  *
0004  * This software is available to you under a choice of one of two
0005  * licenses.  You may choose to be licensed under the terms of the GNU
0006  * General Public License (GPL) Version 2, available from the file
0007  * COPYING in the main directory of this source tree, or the
0008  * OpenIB.org BSD license below:
0009  *
0010  *     Redistribution and use in source and binary forms, with or
0011  *     without modification, are permitted provided that the following
0012  *     conditions are met:
0013  *
0014  *      - Redistributions of source code must retain the above
0015  *        copyright notice, this list of conditions and the following
0016  *        disclaimer.
0017  *
0018  *      - Redistributions in binary form must reproduce the above
0019  *        copyright notice, this list of conditions and the following
0020  *        disclaimer in the documentation and/or other materials
0021  *        provided with the distribution.
0022  *
0023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0024  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0025  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0026  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0027  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0028  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0029  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0030  * SOFTWARE.
0031  */
0032 
0033 #ifndef __MLX5_MPFS_H__
0034 #define __MLX5_MPFS_H__
0035 
0036 #include <linux/if_ether.h>
0037 #include <linux/mlx5/device.h>
0038 
0039 /* L2 -mac address based- hash helpers */
0040 #define MLX5_L2_ADDR_HASH_SIZE (BIT(BITS_PER_BYTE))
0041 #define MLX5_L2_ADDR_HASH(addr) (addr[5])
0042 
0043 struct l2addr_node {
0044     struct hlist_node hlist;
0045     u8                addr[ETH_ALEN];
0046 };
0047 
0048 #define for_each_l2hash_node(hn, tmp, hash, i) \
0049     for (i = 0; i < MLX5_L2_ADDR_HASH_SIZE; i++) \
0050         hlist_for_each_entry_safe(hn, tmp, &(hash)[i], hlist)
0051 
0052 #define l2addr_hash_find(hash, mac, type) ({                \
0053     int ix = MLX5_L2_ADDR_HASH(mac);                    \
0054     bool found = false;                                 \
0055     type *ptr = NULL;                                   \
0056                                 \
0057     hlist_for_each_entry(ptr, &(hash)[ix], node.hlist)  \
0058         if (ether_addr_equal(ptr->node.addr, mac)) {\
0059             found = true;                       \
0060             break;                              \
0061         }                                           \
0062     if (!found)                                         \
0063         ptr = NULL;                                 \
0064     ptr;                                                \
0065 })
0066 
0067 #define l2addr_hash_add(hash, mac, type, gfp) ({            \
0068     int ix = MLX5_L2_ADDR_HASH(mac);                    \
0069     type *ptr = NULL;                                   \
0070                                 \
0071     ptr = kzalloc(sizeof(type), gfp);                   \
0072     if (ptr) {                                          \
0073         ether_addr_copy(ptr->node.addr, mac);       \
0074         hlist_add_head(&ptr->node.hlist, &(hash)[ix]);\
0075     }                                                   \
0076     ptr;                                                \
0077 })
0078 
0079 #define l2addr_hash_del(ptr) ({                             \
0080     hlist_del(&(ptr)->node.hlist);                      \
0081     kfree(ptr);                                         \
0082 })
0083 
0084 #ifdef CONFIG_MLX5_MPFS
0085 int  mlx5_mpfs_init(struct mlx5_core_dev *dev);
0086 void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev);
0087 #else /* #ifndef CONFIG_MLX5_MPFS */
0088 static inline int  mlx5_mpfs_init(struct mlx5_core_dev *dev) { return 0; }
0089 static inline void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev) {}
0090 #endif
0091 
0092 #endif