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