1 /* 2 * QLogic qlcnic NIC Driver 3 * Copyright (c) 2009-2013 QLogic Corporation 4 * 5 * See LICENSE.qlcnic for copyright and licensing details. 6 */ 7 8 #ifndef _QLCNIC_83XX_SRIOV_H_ 9 #define _QLCNIC_83XX_SRIOV_H_ 10 11 #include "qlcnic.h" 12 #include <linux/types.h> 13 #include <linux/pci.h> 14 15 extern const u32 qlcnic_83xx_reg_tbl[]; 16 extern const u32 qlcnic_83xx_ext_reg_tbl[]; 17 18 struct qlcnic_bc_payload { 19 u64 payload[126]; 20 }; 21 22 struct qlcnic_bc_hdr { 23 #if defined(__LITTLE_ENDIAN) 24 u8 version; 25 u8 msg_type:4; 26 u8 rsvd1:3; 27 u8 op_type:1; 28 u8 num_cmds; 29 u8 num_frags; 30 u8 frag_num; 31 u8 cmd_op; 32 u16 seq_id; 33 u64 rsvd3; 34 #elif defined(__BIG_ENDIAN) 35 u8 num_frags; 36 u8 num_cmds; 37 u8 op_type:1; 38 u8 rsvd1:3; 39 u8 msg_type:4; 40 u8 version; 41 u16 seq_id; 42 u8 cmd_op; 43 u8 frag_num; 44 u64 rsvd3; 45 #endif 46 }; 47 48 enum qlcnic_bc_commands { 49 QLCNIC_BC_CMD_CHANNEL_INIT = 0x0, 50 QLCNIC_BC_CMD_CHANNEL_TERM = 0x1, 51 QLCNIC_BC_CMD_GET_ACL = 0x2, 52 QLCNIC_BC_CMD_CFG_GUEST_VLAN = 0x3, 53 }; 54 55 #define QLC_BC_CMD 1 56 57 struct qlcnic_trans_list { 58 /* Lock for manipulating list */ 59 spinlock_t lock; 60 struct list_head wait_list; 61 int count; 62 }; 63 64 enum qlcnic_trans_state { 65 QLC_INIT = 0, 66 QLC_WAIT_FOR_CHANNEL_FREE, 67 QLC_WAIT_FOR_RESP, 68 QLC_ABORT, 69 QLC_END, 70 }; 71 72 struct qlcnic_bc_trans { 73 u8 func_id; 74 u8 active; 75 u8 curr_rsp_frag; 76 u8 curr_req_frag; 77 u16 cmd_id; 78 u16 req_pay_size; 79 u16 rsp_pay_size; 80 u32 trans_id; 81 enum qlcnic_trans_state trans_state; 82 struct list_head list; 83 struct qlcnic_bc_hdr *req_hdr; 84 struct qlcnic_bc_hdr *rsp_hdr; 85 struct qlcnic_bc_payload *req_pay; 86 struct qlcnic_bc_payload *rsp_pay; 87 struct completion resp_cmpl; 88 struct qlcnic_vf_info *vf; 89 }; 90 91 enum qlcnic_vf_state { 92 QLC_BC_VF_SEND = 0, 93 QLC_BC_VF_RECV, 94 QLC_BC_VF_CHANNEL, 95 QLC_BC_VF_STATE, 96 QLC_BC_VF_FLR, 97 QLC_BC_VF_SOFT_FLR, 98 }; 99 100 enum qlcnic_vlan_mode { 101 QLC_NO_VLAN_MODE = 0, 102 QLC_PVID_MODE, 103 QLC_GUEST_VLAN_MODE, 104 }; 105 106 struct qlcnic_resources { 107 u16 num_tx_mac_filters; 108 u16 num_rx_ucast_mac_filters; 109 u16 num_rx_mcast_mac_filters; 110 111 u16 num_txvlan_keys; 112 113 u16 num_rx_queues; 114 u16 num_tx_queues; 115 116 u16 num_rx_buf_rings; 117 u16 num_rx_status_rings; 118 119 u16 num_destip; 120 u32 num_lro_flows_supported; 121 u16 max_local_ipv6_addrs; 122 u16 max_remote_ipv6_addrs; 123 }; 124 125 struct qlcnic_vport { 126 u16 handle; 127 u16 max_tx_bw; 128 u16 min_tx_bw; 129 u8 vlan_mode; 130 u16 vlan; 131 u8 qos; 132 bool spoofchk; 133 u8 mac[6]; 134 }; 135 136 struct qlcnic_vf_info { 137 u8 pci_func; 138 u16 rx_ctx_id; 139 u16 tx_ctx_id; 140 unsigned long state; 141 struct completion ch_free_cmpl; 142 struct work_struct trans_work; 143 struct work_struct flr_work; 144 /* It synchronizes commands sent from VF */ 145 struct mutex send_cmd_lock; 146 struct qlcnic_bc_trans *send_cmd; 147 struct qlcnic_bc_trans *flr_trans; 148 struct qlcnic_trans_list rcv_act; 149 struct qlcnic_trans_list rcv_pend; 150 struct qlcnic_adapter *adapter; 151 struct qlcnic_vport *vp; 152 }; 153 154 struct qlcnic_async_work_list { 155 struct list_head list; 156 struct work_struct work; 157 void *ptr; 158 }; 159 160 struct qlcnic_back_channel { 161 u16 trans_counter; 162 struct workqueue_struct *bc_trans_wq; 163 struct workqueue_struct *bc_async_wq; 164 struct workqueue_struct *bc_flr_wq; 165 struct list_head async_list; 166 }; 167 168 struct qlcnic_sriov { 169 u16 vp_handle; 170 u8 num_vfs; 171 u8 any_vlan; 172 u8 vlan_mode; 173 u16 num_allowed_vlans; 174 u16 *allowed_vlans; 175 u16 vlan; 176 struct qlcnic_resources ff_max; 177 struct qlcnic_back_channel bc; 178 struct qlcnic_vf_info *vf_info; 179 }; 180 181 int qlcnic_sriov_init(struct qlcnic_adapter *, int); 182 void qlcnic_sriov_cleanup(struct qlcnic_adapter *); 183 void __qlcnic_sriov_cleanup(struct qlcnic_adapter *); 184 void qlcnic_sriov_vf_register_map(struct qlcnic_hardware_context *); 185 int qlcnic_sriov_vf_init(struct qlcnic_adapter *, int); 186 void qlcnic_sriov_vf_set_ops(struct qlcnic_adapter *); 187 int qlcnic_sriov_func_to_index(struct qlcnic_adapter *, u8); 188 int qlcnic_sriov_channel_cfg_cmd(struct qlcnic_adapter *, u8); 189 void qlcnic_sriov_handle_bc_event(struct qlcnic_adapter *, u32); 190 int qlcnic_sriov_cfg_bc_intr(struct qlcnic_adapter *, u8); 191 void qlcnic_sriov_cleanup_async_list(struct qlcnic_back_channel *); 192 void qlcnic_sriov_cleanup_list(struct qlcnic_trans_list *); 193 int __qlcnic_sriov_add_act_list(struct qlcnic_sriov *, struct qlcnic_vf_info *, 194 struct qlcnic_bc_trans *); 195 int qlcnic_sriov_get_vf_vport_info(struct qlcnic_adapter *, 196 struct qlcnic_info *, u16); 197 int qlcnic_sriov_cfg_vf_guest_vlan(struct qlcnic_adapter *, u16, u8); 198 int qlcnic_sriov_vf_shutdown(struct pci_dev *); 199 int qlcnic_sriov_vf_resume(struct qlcnic_adapter *); 200 201 static inline bool qlcnic_sriov_enable_check(struct qlcnic_adapter *adapter) 202 { 203 return test_bit(__QLCNIC_SRIOV_ENABLE, &adapter->state) ? true : false; 204 } 205 206 #ifdef CONFIG_QLCNIC_SRIOV 207 void qlcnic_sriov_pf_process_bc_cmd(struct qlcnic_adapter *, 208 struct qlcnic_bc_trans *, 209 struct qlcnic_cmd_args *); 210 void qlcnic_sriov_pf_disable(struct qlcnic_adapter *); 211 void qlcnic_sriov_pf_cleanup(struct qlcnic_adapter *); 212 int qlcnic_pci_sriov_configure(struct pci_dev *, int); 213 void qlcnic_pf_set_interface_id_create_rx_ctx(struct qlcnic_adapter *, u32 *); 214 void qlcnic_pf_set_interface_id_create_tx_ctx(struct qlcnic_adapter *, u32 *); 215 void qlcnic_pf_set_interface_id_del_rx_ctx(struct qlcnic_adapter *, u32 *); 216 void qlcnic_pf_set_interface_id_del_tx_ctx(struct qlcnic_adapter *, u32 *); 217 void qlcnic_pf_set_interface_id_promisc(struct qlcnic_adapter *, u32 *); 218 void qlcnic_pf_set_interface_id_ipaddr(struct qlcnic_adapter *, u32 *); 219 void qlcnic_pf_set_interface_id_macaddr(struct qlcnic_adapter *, u32 *); 220 void qlcnic_sriov_pf_handle_flr(struct qlcnic_sriov *, struct qlcnic_vf_info *); 221 bool qlcnic_sriov_soft_flr_check(struct qlcnic_adapter *, 222 struct qlcnic_bc_trans *, 223 struct qlcnic_vf_info *); 224 void qlcnic_sriov_pf_reset(struct qlcnic_adapter *); 225 int qlcnic_sriov_pf_reinit(struct qlcnic_adapter *); 226 int qlcnic_sriov_set_vf_mac(struct net_device *, int, u8 *); 227 int qlcnic_sriov_set_vf_tx_rate(struct net_device *, int, int); 228 int qlcnic_sriov_get_vf_config(struct net_device *, int , 229 struct ifla_vf_info *); 230 int qlcnic_sriov_set_vf_vlan(struct net_device *, int, u16, u8); 231 int qlcnic_sriov_set_vf_spoofchk(struct net_device *, int, bool); 232 #else 233 static inline void qlcnic_sriov_pf_disable(struct qlcnic_adapter *adapter) {} 234 static inline void qlcnic_sriov_pf_cleanup(struct qlcnic_adapter *adapter) {} 235 static inline void 236 qlcnic_pf_set_interface_id_create_rx_ctx(struct qlcnic_adapter *adapter, 237 u32 *int_id) {} 238 static inline void 239 qlcnic_pf_set_interface_id_create_tx_ctx(struct qlcnic_adapter *adapter, 240 u32 *int_id) {} 241 static inline void 242 qlcnic_pf_set_interface_id_del_rx_ctx(struct qlcnic_adapter *adapter, 243 u32 *int_id) {} 244 static inline void 245 qlcnic_pf_set_interface_id_del_tx_ctx(struct qlcnic_adapter *adapter, 246 u32 *int_id) {} 247 static inline void 248 qlcnic_pf_set_interface_id_ipaddr(struct qlcnic_adapter *adapter, u32 *int_id) 249 {} 250 static inline void 251 qlcnic_pf_set_interface_id_macaddr(struct qlcnic_adapter *adapter, u32 *int_id) 252 {} 253 static inline void 254 qlcnic_pf_set_interface_id_promisc(struct qlcnic_adapter *adapter, u32 *int_id) 255 {} 256 static inline void qlcnic_sriov_pf_handle_flr(struct qlcnic_sriov *sriov, 257 struct qlcnic_vf_info *vf) {} 258 static inline bool qlcnic_sriov_soft_flr_check(struct qlcnic_adapter *adapter, 259 struct qlcnic_bc_trans *trans, 260 struct qlcnic_vf_info *vf) 261 { return false; } 262 static inline void qlcnic_sriov_pf_reset(struct qlcnic_adapter *adapter) {} 263 static inline int qlcnic_sriov_pf_reinit(struct qlcnic_adapter *adapter) 264 { return 0; } 265 #endif 266 267 #endif 268