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