1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Copyright (c) 2025 Hisilicon Limited. 4 */ 5 6 #ifndef _HNS_ROCE_BOND_H 7 #define _HNS_ROCE_BOND_H 8 9 #include <linux/netdevice.h> 10 #include <net/bonding.h> 11 12 #define ROCE_BOND_FUNC_MAX 4 13 #define ROCE_BOND_NUM_MAX 2 14 15 #define BOND_ID(id) BIT(id) 16 17 #define BOND_ERR_LOG(fmt, ...) \ 18 pr_err("HNS RoCE Bonding: " fmt, ##__VA_ARGS__) 19 20 enum { 21 BOND_MODE_1, 22 BOND_MODE_2_4, 23 }; 24 25 enum hns_roce_bond_hashtype { 26 BOND_HASH_L2, 27 BOND_HASH_L34, 28 BOND_HASH_L23, 29 }; 30 31 enum bond_support_type { 32 BOND_NOT_SUPPORT, 33 /* 34 * bond_grp already exists, but in the current 35 * conditions it's no longer supported 36 */ 37 BOND_EXISTING_NOT_SUPPORT, 38 BOND_SUPPORT, 39 }; 40 41 enum hns_roce_bond_state { 42 HNS_ROCE_BOND_NOT_ATTACHED, 43 HNS_ROCE_BOND_NOT_BONDED, 44 HNS_ROCE_BOND_IS_BONDED, 45 HNS_ROCE_BOND_SLAVE_CHANGE_NUM, 46 HNS_ROCE_BOND_SLAVE_CHANGESTATE, 47 }; 48 49 enum hns_roce_bond_cmd_type { 50 HNS_ROCE_SET_BOND, 51 HNS_ROCE_CHANGE_BOND, 52 HNS_ROCE_CLEAR_BOND, 53 }; 54 55 struct hns_roce_func_info { 56 struct net_device *net_dev; 57 struct hnae3_handle *handle; 58 }; 59 60 struct hns_roce_bond_group { 61 struct net_device *upper_dev; 62 struct hns_roce_dev *main_hr_dev; 63 u8 active_slave_num; 64 u32 slave_map; 65 u32 active_slave_map; 66 u8 bond_id; 67 u8 bus_num; 68 struct hns_roce_func_info bond_func_info[ROCE_BOND_FUNC_MAX]; 69 bool bond_ready; 70 enum hns_roce_bond_state bond_state; 71 enum netdev_lag_tx_type tx_type; 72 enum netdev_lag_hash hash_type; 73 struct mutex bond_mutex; 74 struct notifier_block bond_nb; 75 struct delayed_work bond_work; 76 }; 77 78 struct hns_roce_die_info { 79 u8 bond_id_mask; 80 struct hns_roce_bond_group *bgrps[ROCE_BOND_NUM_MAX]; 81 struct mutex die_mutex; 82 u8 suspend_cnt; 83 }; 84 85 struct hns_roce_bond_group *hns_roce_get_bond_grp(struct net_device *net_dev, 86 u8 bus_num); 87 int hns_roce_alloc_bond_grp(struct hns_roce_dev *hr_dev); 88 void hns_roce_dealloc_bond_grp(void); 89 void hns_roce_cleanup_bond(struct hns_roce_bond_group *bond_grp); 90 bool hns_roce_bond_is_active(struct hns_roce_dev *hr_dev); 91 int hns_roce_bond_init(struct hns_roce_dev *hr_dev); 92 void hns_roce_bond_suspend(struct hnae3_handle *handle); 93 void hns_roce_bond_resume(struct hnae3_handle *handle); 94 95 #endif 96