| 1 |
/* |
| 2 |
* Copyright (c) 2017, Mellanox Technologies, Ltd. All rights reserved. |
| 3 |
* |
| 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: |
| 9 |
* |
| 10 |
* Redistribution and use in source and binary forms, with or |
| 11 |
* without modification, are permitted provided that the following |
| 12 |
* conditions are met: |
| 13 |
* |
| 14 |
* - Redistributions of source code must retain the above |
| 15 |
* copyright notice, this list of conditions and the following |
| 16 |
* disclaimer. |
| 17 |
* |
| 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. |
| 22 |
* |
| 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 |
| 30 |
* SOFTWARE. |
| 31 |
*/ |
| 32 |
|
| 33 |
#ifndef __MLX5_MPFS_H__ |
| 34 |
#define __MLX5_MPFS_H__ |
| 35 |
|
| 36 |
#include <linux/if_ether.h> |
| 37 |
#include <linux/mlx5/device.h> |
| 38 |
|
| 39 |
/* L2 -mac address based- hash helpers */ |
| 40 |
#define MLX5_L2_ADDR_HASH_SIZE (BIT(BITS_PER_BYTE)) |
| 41 |
#define MLX5_L2_ADDR_HASH(addr) (addr[5]) |
| 42 |
|
| 43 |
struct l2addr_node { |
| 44 |
struct hlist_node hlist; |
| 45 |
u8 addr[ETH_ALEN]; |
| 46 |
}; |
| 47 |
|
| 48 |
#define mlx5_mpfs_foreach(hs, tmp, mpfs, i) \ |
| 49 |
for (i = 0; i < MLX5_L2_ADDR_HASH_SIZE; i++) \ |
| 50 |
hlist_for_each_entry_safe(hs, tmp, &(mpfs)->hash[i], node.hlist) |
| 51 |
|
| 52 |
#define for_each_l2hash_node(hn, tmp, hash, i) \ |
| 53 |
for (i = 0; i < MLX5_L2_ADDR_HASH_SIZE; i++) \ |
| 54 |
hlist_for_each_entry_safe(hn, tmp, &(hash)[i], hlist) |
| 55 |
|
| 56 |
#define l2addr_hash_find(hash, mac, type) ({ \ |
| 57 |
int ix = MLX5_L2_ADDR_HASH(mac); \ |
| 58 |
bool found = false; \ |
| 59 |
type *ptr = NULL; \ |
| 60 |
\ |
| 61 |
hlist_for_each_entry(ptr, &(hash)[ix], node.hlist) \ |
| 62 |
if (ether_addr_equal(ptr->node.addr, mac)) {\ |
| 63 |
found = true; \ |
| 64 |
break; \ |
| 65 |
} \ |
| 66 |
if (!found) \ |
| 67 |
ptr = NULL; \ |
| 68 |
ptr; \ |
| 69 |
}) |
| 70 |
|
| 71 |
#define l2addr_hash_add(hash, mac, type, gfp) ({ \ |
| 72 |
int ix = MLX5_L2_ADDR_HASH(mac); \ |
| 73 |
type *ptr = NULL; \ |
| 74 |
\ |
| 75 |
ptr = kzalloc_obj(type, gfp); \ |
| 76 |
if (ptr) { \ |
| 77 |
ether_addr_copy(ptr->node.addr, mac); \ |
| 78 |
hlist_add_head(&ptr->node.hlist, &(hash)[ix]);\ |
| 79 |
} \ |
| 80 |
ptr; \ |
| 81 |
}) |
| 82 |
|
| 83 |
#define l2addr_hash_del(ptr) ({ \ |
| 84 |
hlist_del(&(ptr)->node.hlist); \ |
| 85 |
kfree(ptr); \ |
| 86 |
}) |
| 87 |
|
| 88 |
#ifdef CONFIG_MLX5_MPFS |
| 89 |
struct mlx5_core_dev; |
| 90 |
int mlx5_mpfs_init(struct mlx5_core_dev *dev); |
| 91 |
void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev); |
| 92 |
int mlx5_mpfs_enable(struct mlx5_core_dev *dev); |
| 93 |
void mlx5_mpfs_disable(struct mlx5_core_dev *dev); |
| 94 |
#else /* #ifndef CONFIG_MLX5_MPFS */ |
| 95 |
static inline int mlx5_mpfs_init(struct mlx5_core_dev *dev) { return 0; } |
| 96 |
static inline void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev) {} |
| 97 |
static inline int mlx5_mpfs_enable(struct mlx5_core_dev *dev) { return 0; } |
| 98 |
static inline void mlx5_mpfs_disable(struct mlx5_core_dev *dev) {} |
| 99 |
#endif |
| 100 |
|
| 101 |
#endif |