]>
Commit | Line | Data |
---|---|---|
02feda17 RB |
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 | #include "qlcnic_sriov.h" | |
9 | #include "qlcnic.h" | |
10 | #include <linux/types.h> | |
11 | ||
1414abea | 12 | #define QLCNIC_SRIOV_VF_MAX_MAC 7 |
4000e7a7 RB |
13 | #define QLC_VF_MIN_TX_RATE 100 |
14 | #define QLC_VF_MAX_TX_RATE 9999 | |
1414abea SC |
15 | #define QLC_MAC_OPCODE_MASK 0x7 |
16 | #define QLC_MAC_STAR_ADD 6 | |
17 | #define QLC_MAC_STAR_DEL 7 | |
02feda17 RB |
18 | |
19 | static int qlcnic_sriov_pf_get_vport_handle(struct qlcnic_adapter *, u8); | |
20 | ||
f197a7aa RB |
21 | struct qlcnic_sriov_cmd_handler { |
22 | int (*fn) (struct qlcnic_bc_trans *, struct qlcnic_cmd_args *); | |
23 | }; | |
24 | ||
7cb03b23 RB |
25 | struct qlcnic_sriov_fw_cmd_handler { |
26 | u32 cmd; | |
27 | int (*fn) (struct qlcnic_bc_trans *, struct qlcnic_cmd_args *); | |
28 | }; | |
29 | ||
02feda17 RB |
30 | static int qlcnic_sriov_pf_set_vport_info(struct qlcnic_adapter *adapter, |
31 | struct qlcnic_info *npar_info, | |
32 | u16 vport_id) | |
33 | { | |
34 | struct qlcnic_cmd_args cmd; | |
35 | int err; | |
36 | ||
37 | if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_SET_NIC_INFO)) | |
38 | return -ENOMEM; | |
39 | ||
40 | cmd.req.arg[1] = (vport_id << 16) | 0x1; | |
41 | cmd.req.arg[2] = npar_info->bit_offsets; | |
42 | cmd.req.arg[2] |= npar_info->min_tx_bw << 16; | |
43 | cmd.req.arg[3] = npar_info->max_tx_bw | (npar_info->max_tx_ques << 16); | |
44 | cmd.req.arg[4] = npar_info->max_tx_mac_filters; | |
45 | cmd.req.arg[4] |= npar_info->max_rx_mcast_mac_filters << 16; | |
46 | cmd.req.arg[5] = npar_info->max_rx_ucast_mac_filters | | |
47 | (npar_info->max_rx_ip_addr << 16); | |
48 | cmd.req.arg[6] = npar_info->max_rx_lro_flow | | |
49 | (npar_info->max_rx_status_rings << 16); | |
50 | cmd.req.arg[7] = npar_info->max_rx_buf_rings | | |
51 | (npar_info->max_rx_ques << 16); | |
52 | cmd.req.arg[8] = npar_info->max_tx_vlan_keys; | |
53 | cmd.req.arg[8] |= npar_info->max_local_ipv6_addrs << 16; | |
54 | cmd.req.arg[9] = npar_info->max_remote_ipv6_addrs; | |
55 | ||
56 | err = qlcnic_issue_cmd(adapter, &cmd); | |
57 | if (err) | |
58 | dev_err(&adapter->pdev->dev, | |
59 | "Failed to set vport info, err=%d\n", err); | |
60 | ||
61 | qlcnic_free_mbx_args(&cmd); | |
62 | return err; | |
63 | } | |
64 | ||
65 | static int qlcnic_sriov_pf_cal_res_limit(struct qlcnic_adapter *adapter, | |
66 | struct qlcnic_info *info, u16 func) | |
67 | { | |
68 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
69 | struct qlcnic_resources *res = &sriov->ff_max; | |
154d0c81 | 70 | u16 num_macs = sriov->num_allowed_vlans + 1; |
4000e7a7 RB |
71 | int ret = -EIO, vpid, id; |
72 | struct qlcnic_vport *vp; | |
154d0c81 | 73 | u32 num_vfs, max, temp; |
02feda17 RB |
74 | |
75 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, func); | |
76 | if (vpid < 0) | |
77 | return -EINVAL; | |
78 | ||
79 | num_vfs = sriov->num_vfs; | |
80 | max = num_vfs + 1; | |
81 | info->bit_offsets = 0xffff; | |
02feda17 | 82 | info->max_tx_ques = res->num_tx_queues / max; |
154d0c81 MC |
83 | |
84 | if (qlcnic_83xx_pf_check(adapter)) | |
85 | num_macs = 1; | |
02feda17 | 86 | |
02feda17 | 87 | info->max_rx_mcast_mac_filters = res->num_rx_mcast_mac_filters; |
02feda17 RB |
88 | |
89 | if (adapter->ahw->pci_func == func) { | |
4000e7a7 RB |
90 | info->min_tx_bw = 0; |
91 | info->max_tx_bw = MAX_BW; | |
56a4342d | 92 | |
154d0c81 MC |
93 | temp = res->num_rx_ucast_mac_filters - num_macs * num_vfs; |
94 | info->max_rx_ucast_mac_filters = temp; | |
95 | temp = res->num_tx_mac_filters - num_macs * num_vfs; | |
96 | info->max_tx_mac_filters = temp; | |
97 | temp = num_macs * num_vfs * QLCNIC_SRIOV_VF_MAX_MAC; | |
98 | temp = res->num_rx_mcast_mac_filters - temp; | |
99 | info->max_rx_mcast_mac_filters = temp; | |
100 | ||
f3e3ccf8 | 101 | info->max_tx_ques = res->num_tx_queues - sriov->num_vfs; |
02feda17 | 102 | } else { |
4000e7a7 RB |
103 | id = qlcnic_sriov_func_to_index(adapter, func); |
104 | if (id < 0) | |
105 | return id; | |
106 | vp = sriov->vf_info[id].vp; | |
107 | info->min_tx_bw = vp->min_tx_bw; | |
108 | info->max_tx_bw = vp->max_tx_bw; | |
56a4342d | 109 | |
154d0c81 MC |
110 | info->max_rx_ucast_mac_filters = num_macs; |
111 | info->max_tx_mac_filters = num_macs; | |
112 | temp = num_macs * QLCNIC_SRIOV_VF_MAX_MAC; | |
113 | info->max_rx_mcast_mac_filters = temp; | |
56a4342d | 114 | |
f3e3ccf8 | 115 | info->max_tx_ques = QLCNIC_SINGLE_RING; |
02feda17 RB |
116 | } |
117 | ||
118 | info->max_rx_ip_addr = res->num_destip / max; | |
119 | info->max_rx_status_rings = res->num_rx_status_rings / max; | |
120 | info->max_rx_buf_rings = res->num_rx_buf_rings / max; | |
121 | info->max_rx_ques = res->num_rx_queues / max; | |
122 | info->max_rx_lro_flow = res->num_lro_flows_supported / max; | |
123 | info->max_tx_vlan_keys = res->num_txvlan_keys; | |
124 | info->max_local_ipv6_addrs = res->max_local_ipv6_addrs; | |
125 | info->max_remote_ipv6_addrs = res->max_remote_ipv6_addrs; | |
126 | ||
127 | ret = qlcnic_sriov_pf_set_vport_info(adapter, info, vpid); | |
128 | if (ret) | |
129 | return ret; | |
130 | ||
131 | return 0; | |
132 | } | |
133 | ||
134 | static void qlcnic_sriov_pf_set_ff_max_res(struct qlcnic_adapter *adapter, | |
135 | struct qlcnic_info *info) | |
136 | { | |
137 | struct qlcnic_resources *ff_max = &adapter->ahw->sriov->ff_max; | |
138 | ||
139 | ff_max->num_tx_mac_filters = info->max_tx_mac_filters; | |
140 | ff_max->num_rx_ucast_mac_filters = info->max_rx_ucast_mac_filters; | |
141 | ff_max->num_rx_mcast_mac_filters = info->max_rx_mcast_mac_filters; | |
142 | ff_max->num_txvlan_keys = info->max_tx_vlan_keys; | |
143 | ff_max->num_rx_queues = info->max_rx_ques; | |
144 | ff_max->num_tx_queues = info->max_tx_ques; | |
145 | ff_max->num_lro_flows_supported = info->max_rx_lro_flow; | |
146 | ff_max->num_destip = info->max_rx_ip_addr; | |
147 | ff_max->num_rx_buf_rings = info->max_rx_buf_rings; | |
148 | ff_max->num_rx_status_rings = info->max_rx_status_rings; | |
149 | ff_max->max_remote_ipv6_addrs = info->max_remote_ipv6_addrs; | |
150 | ff_max->max_local_ipv6_addrs = info->max_local_ipv6_addrs; | |
151 | } | |
152 | ||
154d0c81 MC |
153 | static void qlcnic_sriov_set_vf_max_vlan(struct qlcnic_adapter *adapter, |
154 | struct qlcnic_info *npar_info) | |
155 | { | |
156 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
157 | int temp, total_fn; | |
158 | ||
159 | temp = npar_info->max_rx_mcast_mac_filters; | |
160 | total_fn = sriov->num_vfs + 1; | |
161 | ||
162 | temp = temp / (QLCNIC_SRIOV_VF_MAX_MAC * total_fn); | |
163 | sriov->num_allowed_vlans = temp - 1; | |
164 | ||
165 | if (qlcnic_83xx_pf_check(adapter)) | |
166 | sriov->num_allowed_vlans = 1; | |
167 | ||
168 | netdev_info(adapter->netdev, "Max Guest VLANs supported per VF = %d\n", | |
169 | sriov->num_allowed_vlans); | |
170 | } | |
171 | ||
02feda17 RB |
172 | static int qlcnic_sriov_get_pf_info(struct qlcnic_adapter *adapter, |
173 | struct qlcnic_info *npar_info) | |
174 | { | |
175 | int err; | |
176 | struct qlcnic_cmd_args cmd; | |
177 | ||
178 | if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_GET_NIC_INFO)) | |
179 | return -ENOMEM; | |
180 | ||
181 | cmd.req.arg[1] = 0x2; | |
182 | err = qlcnic_issue_cmd(adapter, &cmd); | |
183 | if (err) { | |
184 | dev_err(&adapter->pdev->dev, | |
185 | "Failed to get PF info, err=%d\n", err); | |
186 | goto out; | |
187 | } | |
188 | ||
189 | npar_info->total_pf = cmd.rsp.arg[2] & 0xff; | |
190 | npar_info->total_rss_engines = (cmd.rsp.arg[2] >> 8) & 0xff; | |
191 | npar_info->max_vports = MSW(cmd.rsp.arg[2]); | |
192 | npar_info->max_tx_ques = LSW(cmd.rsp.arg[3]); | |
193 | npar_info->max_tx_mac_filters = MSW(cmd.rsp.arg[3]); | |
194 | npar_info->max_rx_mcast_mac_filters = LSW(cmd.rsp.arg[4]); | |
195 | npar_info->max_rx_ucast_mac_filters = MSW(cmd.rsp.arg[4]); | |
196 | npar_info->max_rx_ip_addr = LSW(cmd.rsp.arg[5]); | |
197 | npar_info->max_rx_lro_flow = MSW(cmd.rsp.arg[5]); | |
198 | npar_info->max_rx_status_rings = LSW(cmd.rsp.arg[6]); | |
199 | npar_info->max_rx_buf_rings = MSW(cmd.rsp.arg[6]); | |
200 | npar_info->max_rx_ques = LSW(cmd.rsp.arg[7]); | |
201 | npar_info->max_tx_vlan_keys = MSW(cmd.rsp.arg[7]); | |
202 | npar_info->max_local_ipv6_addrs = LSW(cmd.rsp.arg[8]); | |
203 | npar_info->max_remote_ipv6_addrs = MSW(cmd.rsp.arg[8]); | |
204 | ||
154d0c81 | 205 | qlcnic_sriov_set_vf_max_vlan(adapter, npar_info); |
0c453de6 | 206 | qlcnic_sriov_pf_set_ff_max_res(adapter, npar_info); |
02feda17 RB |
207 | dev_info(&adapter->pdev->dev, |
208 | "\n\ttotal_pf: %d,\n" | |
209 | "\n\ttotal_rss_engines: %d max_vports: %d max_tx_ques %d,\n" | |
210 | "\tmax_tx_mac_filters: %d max_rx_mcast_mac_filters: %d,\n" | |
211 | "\tmax_rx_ucast_mac_filters: 0x%x, max_rx_ip_addr: %d,\n" | |
212 | "\tmax_rx_lro_flow: %d max_rx_status_rings: %d,\n" | |
213 | "\tmax_rx_buf_rings: %d, max_rx_ques: %d, max_tx_vlan_keys %d\n" | |
214 | "\tmax_local_ipv6_addrs: %d, max_remote_ipv6_addrs: %d\n", | |
215 | npar_info->total_pf, npar_info->total_rss_engines, | |
216 | npar_info->max_vports, npar_info->max_tx_ques, | |
217 | npar_info->max_tx_mac_filters, | |
218 | npar_info->max_rx_mcast_mac_filters, | |
219 | npar_info->max_rx_ucast_mac_filters, npar_info->max_rx_ip_addr, | |
220 | npar_info->max_rx_lro_flow, npar_info->max_rx_status_rings, | |
221 | npar_info->max_rx_buf_rings, npar_info->max_rx_ques, | |
222 | npar_info->max_tx_vlan_keys, npar_info->max_local_ipv6_addrs, | |
223 | npar_info->max_remote_ipv6_addrs); | |
224 | ||
225 | out: | |
226 | qlcnic_free_mbx_args(&cmd); | |
227 | return err; | |
228 | } | |
229 | ||
230 | static void qlcnic_sriov_pf_reset_vport_handle(struct qlcnic_adapter *adapter, | |
231 | u8 func) | |
232 | { | |
233 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
f197a7aa RB |
234 | struct qlcnic_vport *vp; |
235 | int index; | |
02feda17 | 236 | |
f197a7aa | 237 | if (adapter->ahw->pci_func == func) { |
02feda17 | 238 | sriov->vp_handle = 0; |
f197a7aa RB |
239 | } else { |
240 | index = qlcnic_sriov_func_to_index(adapter, func); | |
241 | if (index < 0) | |
242 | return; | |
243 | vp = sriov->vf_info[index].vp; | |
244 | vp->handle = 0; | |
245 | } | |
02feda17 RB |
246 | } |
247 | ||
248 | static void qlcnic_sriov_pf_set_vport_handle(struct qlcnic_adapter *adapter, | |
249 | u16 vport_handle, u8 func) | |
250 | { | |
251 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
f197a7aa RB |
252 | struct qlcnic_vport *vp; |
253 | int index; | |
02feda17 | 254 | |
f197a7aa | 255 | if (adapter->ahw->pci_func == func) { |
02feda17 | 256 | sriov->vp_handle = vport_handle; |
f197a7aa RB |
257 | } else { |
258 | index = qlcnic_sriov_func_to_index(adapter, func); | |
259 | if (index < 0) | |
260 | return; | |
261 | vp = sriov->vf_info[index].vp; | |
262 | vp->handle = vport_handle; | |
263 | } | |
02feda17 RB |
264 | } |
265 | ||
266 | static int qlcnic_sriov_pf_get_vport_handle(struct qlcnic_adapter *adapter, | |
267 | u8 func) | |
268 | { | |
269 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
f197a7aa RB |
270 | struct qlcnic_vf_info *vf_info; |
271 | int index; | |
02feda17 | 272 | |
f197a7aa | 273 | if (adapter->ahw->pci_func == func) { |
02feda17 | 274 | return sriov->vp_handle; |
f197a7aa RB |
275 | } else { |
276 | index = qlcnic_sriov_func_to_index(adapter, func); | |
277 | if (index >= 0) { | |
278 | vf_info = &sriov->vf_info[index]; | |
279 | return vf_info->vp->handle; | |
280 | } | |
281 | } | |
02feda17 RB |
282 | |
283 | return -EINVAL; | |
284 | } | |
285 | ||
286 | static int qlcnic_sriov_pf_config_vport(struct qlcnic_adapter *adapter, | |
287 | u8 flag, u16 func) | |
288 | { | |
289 | struct qlcnic_cmd_args cmd; | |
290 | int ret; | |
291 | int vpid; | |
292 | ||
293 | if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_CONFIG_VPORT)) | |
294 | return -ENOMEM; | |
295 | ||
296 | if (flag) { | |
297 | cmd.req.arg[3] = func << 8; | |
298 | } else { | |
299 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, func); | |
300 | if (vpid < 0) { | |
301 | ret = -EINVAL; | |
302 | goto out; | |
303 | } | |
304 | cmd.req.arg[3] = ((vpid & 0xffff) << 8) | 1; | |
305 | } | |
306 | ||
307 | ret = qlcnic_issue_cmd(adapter, &cmd); | |
308 | if (ret) { | |
309 | dev_err(&adapter->pdev->dev, | |
310 | "Failed %s vport, err %d for func 0x%x\n", | |
311 | (flag ? "enable" : "disable"), ret, func); | |
312 | goto out; | |
313 | } | |
314 | ||
315 | if (flag) { | |
316 | vpid = cmd.rsp.arg[2] & 0xffff; | |
317 | qlcnic_sriov_pf_set_vport_handle(adapter, vpid, func); | |
318 | } else { | |
319 | qlcnic_sriov_pf_reset_vport_handle(adapter, func); | |
320 | } | |
321 | ||
322 | out: | |
323 | qlcnic_free_mbx_args(&cmd); | |
324 | return ret; | |
325 | } | |
326 | ||
91b7282b RB |
327 | static int qlcnic_sriov_pf_cfg_vlan_filtering(struct qlcnic_adapter *adapter, |
328 | u8 enable) | |
329 | { | |
330 | struct qlcnic_cmd_args cmd; | |
331 | int err; | |
332 | ||
333 | err = qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_SET_NIC_INFO); | |
334 | if (err) | |
335 | return err; | |
336 | ||
337 | cmd.req.arg[1] = 0x4; | |
338 | if (enable) | |
339 | cmd.req.arg[1] |= BIT_16; | |
340 | ||
341 | err = qlcnic_issue_cmd(adapter, &cmd); | |
342 | if (err) | |
343 | dev_err(&adapter->pdev->dev, | |
344 | "Failed to configure VLAN filtering, err=%d\n", err); | |
345 | ||
346 | qlcnic_free_mbx_args(&cmd); | |
347 | return err; | |
348 | } | |
349 | ||
02feda17 RB |
350 | static int qlcnic_sriov_pf_cfg_eswitch(struct qlcnic_adapter *adapter, |
351 | u8 func, u8 enable) | |
352 | { | |
353 | struct qlcnic_cmd_args cmd; | |
354 | int err = -EIO; | |
355 | ||
356 | if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_TOGGLE_ESWITCH)) | |
357 | return -ENOMEM; | |
358 | ||
359 | cmd.req.arg[0] |= (3 << 29); | |
360 | cmd.req.arg[1] = ((func & 0xf) << 2) | BIT_6 | BIT_1; | |
361 | if (enable) | |
362 | cmd.req.arg[1] |= BIT_0; | |
363 | ||
364 | err = qlcnic_issue_cmd(adapter, &cmd); | |
365 | ||
366 | if (err != QLCNIC_RCODE_SUCCESS) { | |
367 | dev_err(&adapter->pdev->dev, | |
368 | "Failed to enable sriov eswitch%d\n", err); | |
369 | err = -EIO; | |
370 | } | |
371 | ||
372 | qlcnic_free_mbx_args(&cmd); | |
373 | return err; | |
374 | } | |
375 | ||
97d8105c RB |
376 | static void qlcnic_sriov_pf_del_flr_queue(struct qlcnic_adapter *adapter) |
377 | { | |
378 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
379 | struct qlcnic_back_channel *bc = &sriov->bc; | |
380 | int i; | |
381 | ||
382 | for (i = 0; i < sriov->num_vfs; i++) | |
383 | cancel_work_sync(&sriov->vf_info[i].flr_work); | |
384 | ||
385 | destroy_workqueue(bc->bc_flr_wq); | |
386 | } | |
387 | ||
388 | static int qlcnic_sriov_pf_create_flr_queue(struct qlcnic_adapter *adapter) | |
389 | { | |
390 | struct qlcnic_back_channel *bc = &adapter->ahw->sriov->bc; | |
391 | struct workqueue_struct *wq; | |
392 | ||
393 | wq = create_singlethread_workqueue("qlcnic-flr"); | |
394 | if (wq == NULL) { | |
395 | dev_err(&adapter->pdev->dev, "Cannot create FLR workqueue\n"); | |
396 | return -ENOMEM; | |
397 | } | |
398 | ||
399 | bc->bc_flr_wq = wq; | |
400 | return 0; | |
401 | } | |
402 | ||
02feda17 RB |
403 | void qlcnic_sriov_pf_cleanup(struct qlcnic_adapter *adapter) |
404 | { | |
405 | u8 func = adapter->ahw->pci_func; | |
406 | ||
407 | if (!qlcnic_sriov_enable_check(adapter)) | |
408 | return; | |
409 | ||
97d8105c | 410 | qlcnic_sriov_pf_del_flr_queue(adapter); |
f197a7aa | 411 | qlcnic_sriov_cfg_bc_intr(adapter, 0); |
02feda17 RB |
412 | qlcnic_sriov_pf_config_vport(adapter, 0, func); |
413 | qlcnic_sriov_pf_cfg_eswitch(adapter, func, 0); | |
91b7282b | 414 | qlcnic_sriov_pf_cfg_vlan_filtering(adapter, 0); |
02feda17 RB |
415 | __qlcnic_sriov_cleanup(adapter); |
416 | adapter->ahw->op_mode = QLCNIC_MGMT_FUNC; | |
417 | clear_bit(__QLCNIC_SRIOV_ENABLE, &adapter->state); | |
418 | } | |
419 | ||
420 | void qlcnic_sriov_pf_disable(struct qlcnic_adapter *adapter) | |
421 | { | |
422 | if (!qlcnic_sriov_pf_check(adapter)) | |
423 | return; | |
424 | ||
425 | if (!qlcnic_sriov_enable_check(adapter)) | |
426 | return; | |
427 | ||
428 | pci_disable_sriov(adapter->pdev); | |
429 | netdev_info(adapter->netdev, | |
430 | "SR-IOV is disabled successfully on port %d\n", | |
431 | adapter->portnum); | |
432 | } | |
433 | ||
434 | static int qlcnic_pci_sriov_disable(struct qlcnic_adapter *adapter) | |
435 | { | |
436 | struct net_device *netdev = adapter->netdev; | |
437 | ||
1ed98ed5 | 438 | rtnl_lock(); |
02feda17 RB |
439 | if (netif_running(netdev)) |
440 | __qlcnic_down(adapter, netdev); | |
441 | ||
442 | qlcnic_sriov_pf_disable(adapter); | |
443 | ||
154d0c81 MC |
444 | qlcnic_sriov_free_vlans(adapter); |
445 | ||
02feda17 RB |
446 | qlcnic_sriov_pf_cleanup(adapter); |
447 | ||
448 | /* After disabling SRIOV re-init the driver in default mode | |
449 | configure opmode based on op_mode of function | |
450 | */ | |
1ed98ed5 MC |
451 | if (qlcnic_83xx_configure_opmode(adapter)) { |
452 | rtnl_unlock(); | |
02feda17 | 453 | return -EIO; |
1ed98ed5 | 454 | } |
02feda17 RB |
455 | |
456 | if (netif_running(netdev)) | |
457 | __qlcnic_up(adapter, netdev); | |
458 | ||
1ed98ed5 | 459 | rtnl_unlock(); |
02feda17 RB |
460 | return 0; |
461 | } | |
462 | ||
463 | static int qlcnic_sriov_pf_init(struct qlcnic_adapter *adapter) | |
464 | { | |
465 | struct qlcnic_hardware_context *ahw = adapter->ahw; | |
466 | struct qlcnic_info nic_info, pf_info, vp_info; | |
467 | int err; | |
468 | u8 func = ahw->pci_func; | |
469 | ||
470 | if (!qlcnic_sriov_enable_check(adapter)) | |
471 | return 0; | |
472 | ||
91b7282b | 473 | err = qlcnic_sriov_pf_cfg_vlan_filtering(adapter, 1); |
02feda17 | 474 | if (err) |
97d8105c | 475 | return err; |
02feda17 | 476 | |
91b7282b RB |
477 | err = qlcnic_sriov_pf_cfg_eswitch(adapter, func, 1); |
478 | if (err) | |
479 | goto disable_vlan_filtering; | |
480 | ||
02feda17 RB |
481 | err = qlcnic_sriov_pf_config_vport(adapter, 1, func); |
482 | if (err) | |
483 | goto disable_eswitch; | |
484 | ||
485 | err = qlcnic_sriov_get_pf_info(adapter, &pf_info); | |
486 | if (err) | |
487 | goto delete_vport; | |
488 | ||
02feda17 RB |
489 | err = qlcnic_get_nic_info(adapter, &nic_info, func); |
490 | if (err) | |
491 | goto delete_vport; | |
492 | ||
493 | err = qlcnic_sriov_pf_cal_res_limit(adapter, &vp_info, func); | |
494 | if (err) | |
495 | goto delete_vport; | |
496 | ||
f197a7aa RB |
497 | err = qlcnic_sriov_cfg_bc_intr(adapter, 1); |
498 | if (err) | |
499 | goto delete_vport; | |
500 | ||
02feda17 RB |
501 | ahw->physical_port = (u8) nic_info.phys_port; |
502 | ahw->switch_mode = nic_info.switch_mode; | |
503 | ahw->max_mtu = nic_info.max_mtu; | |
504 | ahw->capabilities = nic_info.capabilities; | |
505 | ahw->nic_mode = QLC_83XX_SRIOV_MODE; | |
506 | return err; | |
507 | ||
508 | delete_vport: | |
509 | qlcnic_sriov_pf_config_vport(adapter, 0, func); | |
510 | ||
511 | disable_eswitch: | |
512 | qlcnic_sriov_pf_cfg_eswitch(adapter, func, 0); | |
513 | ||
91b7282b RB |
514 | disable_vlan_filtering: |
515 | qlcnic_sriov_pf_cfg_vlan_filtering(adapter, 0); | |
516 | ||
02feda17 RB |
517 | return err; |
518 | } | |
519 | ||
520 | static int qlcnic_sriov_pf_enable(struct qlcnic_adapter *adapter, int num_vfs) | |
521 | { | |
522 | int err; | |
523 | ||
524 | if (!qlcnic_sriov_enable_check(adapter)) | |
525 | return 0; | |
526 | ||
527 | err = pci_enable_sriov(adapter->pdev, num_vfs); | |
528 | if (err) | |
529 | qlcnic_sriov_pf_cleanup(adapter); | |
530 | ||
531 | return err; | |
532 | } | |
533 | ||
534 | static int __qlcnic_pci_sriov_enable(struct qlcnic_adapter *adapter, | |
535 | int num_vfs) | |
536 | { | |
537 | int err = 0; | |
538 | ||
539 | set_bit(__QLCNIC_SRIOV_ENABLE, &adapter->state); | |
540 | adapter->ahw->op_mode = QLCNIC_SRIOV_PF_FUNC; | |
541 | ||
97d8105c RB |
542 | err = qlcnic_sriov_init(adapter, num_vfs); |
543 | if (err) | |
544 | goto clear_op_mode; | |
02feda17 | 545 | |
97d8105c RB |
546 | err = qlcnic_sriov_pf_create_flr_queue(adapter); |
547 | if (err) | |
548 | goto sriov_cleanup; | |
549 | ||
550 | err = qlcnic_sriov_pf_init(adapter); | |
551 | if (err) | |
552 | goto del_flr_queue; | |
02feda17 | 553 | |
154d0c81 MC |
554 | qlcnic_sriov_alloc_vlans(adapter); |
555 | ||
02feda17 RB |
556 | err = qlcnic_sriov_pf_enable(adapter, num_vfs); |
557 | return err; | |
97d8105c RB |
558 | |
559 | del_flr_queue: | |
560 | qlcnic_sriov_pf_del_flr_queue(adapter); | |
561 | ||
562 | sriov_cleanup: | |
563 | __qlcnic_sriov_cleanup(adapter); | |
564 | ||
565 | clear_op_mode: | |
566 | clear_bit(__QLCNIC_SRIOV_ENABLE, &adapter->state); | |
567 | adapter->ahw->op_mode = QLCNIC_MGMT_FUNC; | |
568 | return err; | |
02feda17 RB |
569 | } |
570 | ||
571 | static int qlcnic_pci_sriov_enable(struct qlcnic_adapter *adapter, int num_vfs) | |
572 | { | |
573 | struct net_device *netdev = adapter->netdev; | |
574 | int err; | |
575 | ||
576 | if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) { | |
577 | netdev_err(netdev, | |
578 | "SR-IOV cannot be enabled, when legacy interrupts are enabled\n"); | |
579 | return -EIO; | |
580 | } | |
581 | ||
1ed98ed5 | 582 | rtnl_lock(); |
02feda17 RB |
583 | if (netif_running(netdev)) |
584 | __qlcnic_down(adapter, netdev); | |
585 | ||
586 | err = __qlcnic_pci_sriov_enable(adapter, num_vfs); | |
587 | if (err) { | |
588 | netdev_info(netdev, "Failed to enable SR-IOV on port %d\n", | |
589 | adapter->portnum); | |
590 | ||
97d8105c | 591 | err = -EIO; |
02feda17 RB |
592 | if (qlcnic_83xx_configure_opmode(adapter)) |
593 | goto error; | |
594 | } else { | |
97d8105c | 595 | netdev_info(netdev, |
02feda17 RB |
596 | "SR-IOV is enabled successfully on port %d\n", |
597 | adapter->portnum); | |
97d8105c RB |
598 | /* Return number of vfs enabled */ |
599 | err = num_vfs; | |
02feda17 RB |
600 | } |
601 | if (netif_running(netdev)) | |
602 | __qlcnic_up(adapter, netdev); | |
603 | ||
604 | error: | |
1ed98ed5 | 605 | rtnl_unlock(); |
02feda17 RB |
606 | return err; |
607 | } | |
608 | ||
609 | int qlcnic_pci_sriov_configure(struct pci_dev *dev, int num_vfs) | |
610 | { | |
611 | struct qlcnic_adapter *adapter = pci_get_drvdata(dev); | |
612 | int err; | |
613 | ||
614 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) | |
615 | return -EBUSY; | |
616 | ||
617 | if (num_vfs == 0) | |
618 | err = qlcnic_pci_sriov_disable(adapter); | |
619 | else | |
620 | err = qlcnic_pci_sriov_enable(adapter, num_vfs); | |
621 | ||
622 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
623 | return err; | |
624 | } | |
f197a7aa | 625 | |
91b7282b RB |
626 | static int qlcnic_sriov_set_vf_acl(struct qlcnic_adapter *adapter, u8 func) |
627 | { | |
628 | struct qlcnic_cmd_args cmd; | |
629 | struct qlcnic_vport *vp; | |
630 | int err, id; | |
a80be5a5 | 631 | u8 *mac; |
91b7282b RB |
632 | |
633 | id = qlcnic_sriov_func_to_index(adapter, func); | |
634 | if (id < 0) | |
635 | return id; | |
636 | ||
637 | vp = adapter->ahw->sriov->vf_info[id].vp; | |
638 | err = qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_SET_NIC_INFO); | |
639 | if (err) | |
640 | return err; | |
641 | ||
642 | cmd.req.arg[1] = 0x3 | func << 16; | |
a80be5a5 RB |
643 | if (vp->spoofchk == true) { |
644 | mac = vp->mac; | |
645 | cmd.req.arg[2] |= BIT_1 | BIT_3 | BIT_8; | |
646 | cmd.req.arg[4] = mac[5] | mac[4] << 8 | mac[3] << 16 | | |
647 | mac[2] << 24; | |
648 | cmd.req.arg[5] = mac[1] | mac[0] << 8; | |
649 | } | |
650 | ||
91b7282b RB |
651 | if (vp->vlan_mode == QLC_PVID_MODE) { |
652 | cmd.req.arg[2] |= BIT_6; | |
154d0c81 | 653 | cmd.req.arg[3] |= vp->pvid << 8; |
91b7282b RB |
654 | } |
655 | ||
656 | err = qlcnic_issue_cmd(adapter, &cmd); | |
657 | if (err) | |
658 | dev_err(&adapter->pdev->dev, "Failed to set ACL, err=%d\n", | |
659 | err); | |
660 | ||
661 | qlcnic_free_mbx_args(&cmd); | |
662 | return err; | |
663 | } | |
664 | ||
f197a7aa RB |
665 | static int qlcnic_sriov_set_vf_vport_info(struct qlcnic_adapter *adapter, |
666 | u16 func) | |
667 | { | |
668 | struct qlcnic_info defvp_info; | |
669 | int err; | |
670 | ||
671 | err = qlcnic_sriov_pf_cal_res_limit(adapter, &defvp_info, func); | |
672 | if (err) | |
673 | return -EIO; | |
674 | ||
91b7282b RB |
675 | err = qlcnic_sriov_set_vf_acl(adapter, func); |
676 | if (err) | |
677 | return err; | |
678 | ||
f197a7aa RB |
679 | return 0; |
680 | } | |
681 | ||
682 | static int qlcnic_sriov_pf_channel_cfg_cmd(struct qlcnic_bc_trans *trans, | |
683 | struct qlcnic_cmd_args *cmd) | |
684 | { | |
685 | struct qlcnic_vf_info *vf = trans->vf; | |
2f0a9afa MC |
686 | struct qlcnic_vport *vp = vf->vp; |
687 | struct qlcnic_adapter *adapter; | |
154d0c81 | 688 | struct qlcnic_sriov *sriov; |
f197a7aa | 689 | u16 func = vf->pci_func; |
154d0c81 | 690 | size_t size; |
2f0a9afa | 691 | int err; |
f197a7aa | 692 | |
2f0a9afa | 693 | adapter = vf->adapter; |
154d0c81 | 694 | sriov = adapter->ahw->sriov; |
f197a7aa RB |
695 | |
696 | if (trans->req_hdr->cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT) { | |
697 | err = qlcnic_sriov_pf_config_vport(adapter, 1, func); | |
698 | if (!err) { | |
699 | err = qlcnic_sriov_set_vf_vport_info(adapter, func); | |
700 | if (err) | |
701 | qlcnic_sriov_pf_config_vport(adapter, 0, func); | |
702 | } | |
703 | } else { | |
154d0c81 MC |
704 | if (vp->vlan_mode == QLC_GUEST_VLAN_MODE) { |
705 | size = sizeof(*vf->sriov_vlans); | |
706 | size = size * sriov->num_allowed_vlans; | |
707 | memset(vf->sriov_vlans, 0, size); | |
708 | } | |
709 | ||
f197a7aa RB |
710 | err = qlcnic_sriov_pf_config_vport(adapter, 0, func); |
711 | } | |
712 | ||
713 | if (err) | |
714 | goto err_out; | |
715 | ||
716 | cmd->rsp.arg[0] |= (1 << 25); | |
717 | ||
718 | if (trans->req_hdr->cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT) | |
719 | set_bit(QLC_BC_VF_STATE, &vf->state); | |
720 | else | |
721 | clear_bit(QLC_BC_VF_STATE, &vf->state); | |
722 | ||
723 | return err; | |
724 | ||
725 | err_out: | |
726 | cmd->rsp.arg[0] |= (2 << 25); | |
727 | return err; | |
728 | } | |
729 | ||
7cb03b23 | 730 | static int qlcnic_sriov_cfg_vf_def_mac(struct qlcnic_adapter *adapter, |
154d0c81 MC |
731 | struct qlcnic_vf_info *vf, |
732 | u16 vlan, u8 op) | |
7cb03b23 RB |
733 | { |
734 | struct qlcnic_cmd_args cmd; | |
735 | struct qlcnic_macvlan_mbx mv; | |
154d0c81 | 736 | struct qlcnic_vport *vp; |
7cb03b23 RB |
737 | u8 *addr; |
738 | int err; | |
739 | u32 *buf; | |
740 | int vpid; | |
741 | ||
154d0c81 MC |
742 | vp = vf->vp; |
743 | ||
7cb03b23 RB |
744 | if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_CONFIG_MAC_VLAN)) |
745 | return -ENOMEM; | |
746 | ||
154d0c81 | 747 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, vf->pci_func); |
7cb03b23 RB |
748 | if (vpid < 0) { |
749 | err = -EINVAL; | |
750 | goto out; | |
751 | } | |
752 | ||
753 | if (vlan) | |
754 | op = ((op == QLCNIC_MAC_ADD || op == QLCNIC_MAC_VLAN_ADD) ? | |
755 | QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_VLAN_DEL); | |
756 | ||
757 | cmd.req.arg[1] = op | (1 << 8) | (3 << 6); | |
758 | cmd.req.arg[1] |= ((vpid & 0xffff) << 16) | BIT_31; | |
759 | ||
760 | addr = vp->mac; | |
f80bc8fe | 761 | mv.vlan = vlan; |
7cb03b23 RB |
762 | mv.mac_addr0 = addr[0]; |
763 | mv.mac_addr1 = addr[1]; | |
764 | mv.mac_addr2 = addr[2]; | |
765 | mv.mac_addr3 = addr[3]; | |
766 | mv.mac_addr4 = addr[4]; | |
767 | mv.mac_addr5 = addr[5]; | |
768 | buf = &cmd.req.arg[2]; | |
769 | memcpy(buf, &mv, sizeof(struct qlcnic_macvlan_mbx)); | |
770 | ||
771 | err = qlcnic_issue_cmd(adapter, &cmd); | |
772 | ||
773 | if (err) | |
774 | dev_err(&adapter->pdev->dev, | |
775 | "MAC-VLAN %s to CAM failed, err=%d.\n", | |
776 | ((op == 1) ? "add " : "delete "), err); | |
777 | ||
778 | out: | |
779 | qlcnic_free_mbx_args(&cmd); | |
780 | return err; | |
781 | } | |
782 | ||
783 | static int qlcnic_sriov_validate_create_rx_ctx(struct qlcnic_cmd_args *cmd) | |
784 | { | |
785 | if ((cmd->req.arg[0] >> 29) != 0x3) | |
786 | return -EINVAL; | |
787 | ||
788 | return 0; | |
789 | } | |
790 | ||
154d0c81 MC |
791 | static void qlcnic_83xx_cfg_default_mac_vlan(struct qlcnic_adapter *adapter, |
792 | struct qlcnic_vf_info *vf, | |
793 | int opcode) | |
794 | { | |
795 | struct qlcnic_sriov *sriov; | |
796 | u16 vlan; | |
797 | int i; | |
798 | ||
799 | sriov = adapter->ahw->sriov; | |
800 | ||
801 | mutex_lock(&vf->vlan_list_lock); | |
802 | if (vf->num_vlan) { | |
803 | for (i = 0; i < sriov->num_allowed_vlans; i++) { | |
804 | vlan = vf->sriov_vlans[i]; | |
805 | if (vlan) | |
806 | qlcnic_sriov_cfg_vf_def_mac(adapter, vf, vlan, | |
807 | opcode); | |
808 | } | |
809 | } | |
810 | mutex_unlock(&vf->vlan_list_lock); | |
811 | ||
812 | if (vf->vp->vlan_mode != QLC_PVID_MODE) { | |
813 | if (qlcnic_83xx_pf_check(adapter) && | |
814 | qlcnic_sriov_check_any_vlan(vf)) | |
815 | return; | |
816 | qlcnic_sriov_cfg_vf_def_mac(adapter, vf, 0, opcode); | |
817 | } | |
818 | } | |
819 | ||
7cb03b23 RB |
820 | static int qlcnic_sriov_pf_create_rx_ctx_cmd(struct qlcnic_bc_trans *tran, |
821 | struct qlcnic_cmd_args *cmd) | |
822 | { | |
823 | struct qlcnic_vf_info *vf = tran->vf; | |
824 | struct qlcnic_adapter *adapter = vf->adapter; | |
825 | struct qlcnic_rcv_mbx_out *mbx_out; | |
826 | int err; | |
827 | ||
828 | err = qlcnic_sriov_validate_create_rx_ctx(cmd); | |
829 | if (err) { | |
830 | cmd->rsp.arg[0] |= (0x6 << 25); | |
831 | return err; | |
832 | } | |
833 | ||
834 | cmd->req.arg[6] = vf->vp->handle; | |
835 | err = qlcnic_issue_cmd(adapter, cmd); | |
836 | ||
837 | if (!err) { | |
838 | mbx_out = (struct qlcnic_rcv_mbx_out *)&cmd->rsp.arg[1]; | |
839 | vf->rx_ctx_id = mbx_out->ctx_id; | |
154d0c81 | 840 | qlcnic_83xx_cfg_default_mac_vlan(adapter, vf, QLCNIC_MAC_ADD); |
7cb03b23 RB |
841 | } else { |
842 | vf->rx_ctx_id = 0; | |
843 | } | |
844 | ||
845 | return err; | |
846 | } | |
847 | ||
848 | static int qlcnic_sriov_pf_mac_address_cmd(struct qlcnic_bc_trans *trans, | |
849 | struct qlcnic_cmd_args *cmd) | |
850 | { | |
851 | struct qlcnic_vf_info *vf = trans->vf; | |
852 | u8 type, *mac; | |
853 | ||
854 | type = cmd->req.arg[1]; | |
855 | switch (type) { | |
856 | case QLCNIC_SET_STATION_MAC: | |
857 | case QLCNIC_SET_FAC_DEF_MAC: | |
858 | cmd->rsp.arg[0] = (2 << 25); | |
859 | break; | |
860 | case QLCNIC_GET_CURRENT_MAC: | |
861 | cmd->rsp.arg[0] = (1 << 25); | |
862 | mac = vf->vp->mac; | |
863 | cmd->rsp.arg[2] = mac[1] | ((mac[0] << 8) & 0xff00); | |
864 | cmd->rsp.arg[1] = mac[5] | ((mac[4] << 8) & 0xff00) | | |
865 | ((mac[3]) << 16 & 0xff0000) | | |
866 | ((mac[2]) << 24 & 0xff000000); | |
867 | } | |
868 | ||
869 | return 0; | |
870 | } | |
871 | ||
872 | static int qlcnic_sriov_validate_create_tx_ctx(struct qlcnic_cmd_args *cmd) | |
873 | { | |
874 | if ((cmd->req.arg[0] >> 29) != 0x3) | |
875 | return -EINVAL; | |
876 | ||
877 | return 0; | |
878 | } | |
879 | ||
880 | static int qlcnic_sriov_pf_create_tx_ctx_cmd(struct qlcnic_bc_trans *trans, | |
881 | struct qlcnic_cmd_args *cmd) | |
882 | { | |
883 | struct qlcnic_vf_info *vf = trans->vf; | |
884 | struct qlcnic_adapter *adapter = vf->adapter; | |
885 | struct qlcnic_tx_mbx_out *mbx_out; | |
886 | int err; | |
887 | ||
888 | err = qlcnic_sriov_validate_create_tx_ctx(cmd); | |
889 | if (err) { | |
890 | cmd->rsp.arg[0] |= (0x6 << 25); | |
891 | return err; | |
892 | } | |
893 | ||
894 | cmd->req.arg[5] |= vf->vp->handle << 16; | |
895 | err = qlcnic_issue_cmd(adapter, cmd); | |
896 | if (!err) { | |
897 | mbx_out = (struct qlcnic_tx_mbx_out *)&cmd->rsp.arg[2]; | |
898 | vf->tx_ctx_id = mbx_out->ctx_id; | |
899 | } else { | |
900 | vf->tx_ctx_id = 0; | |
901 | } | |
902 | ||
903 | return err; | |
904 | } | |
905 | ||
906 | static int qlcnic_sriov_validate_del_rx_ctx(struct qlcnic_vf_info *vf, | |
907 | struct qlcnic_cmd_args *cmd) | |
908 | { | |
909 | if ((cmd->req.arg[0] >> 29) != 0x3) | |
910 | return -EINVAL; | |
911 | ||
912 | if ((cmd->req.arg[1] & 0xffff) != vf->rx_ctx_id) | |
913 | return -EINVAL; | |
914 | ||
915 | return 0; | |
916 | } | |
917 | ||
918 | static int qlcnic_sriov_pf_del_rx_ctx_cmd(struct qlcnic_bc_trans *trans, | |
919 | struct qlcnic_cmd_args *cmd) | |
920 | { | |
921 | struct qlcnic_vf_info *vf = trans->vf; | |
922 | struct qlcnic_adapter *adapter = vf->adapter; | |
923 | int err; | |
924 | ||
925 | err = qlcnic_sriov_validate_del_rx_ctx(vf, cmd); | |
926 | if (err) { | |
927 | cmd->rsp.arg[0] |= (0x6 << 25); | |
928 | return err; | |
929 | } | |
930 | ||
154d0c81 | 931 | qlcnic_83xx_cfg_default_mac_vlan(adapter, vf, QLCNIC_MAC_DEL); |
7cb03b23 RB |
932 | cmd->req.arg[1] |= vf->vp->handle << 16; |
933 | err = qlcnic_issue_cmd(adapter, cmd); | |
934 | ||
935 | if (!err) | |
936 | vf->rx_ctx_id = 0; | |
937 | ||
938 | return err; | |
939 | } | |
940 | ||
941 | static int qlcnic_sriov_validate_del_tx_ctx(struct qlcnic_vf_info *vf, | |
942 | struct qlcnic_cmd_args *cmd) | |
943 | { | |
944 | if ((cmd->req.arg[0] >> 29) != 0x3) | |
945 | return -EINVAL; | |
946 | ||
947 | if ((cmd->req.arg[1] & 0xffff) != vf->tx_ctx_id) | |
948 | return -EINVAL; | |
949 | ||
950 | return 0; | |
951 | } | |
952 | ||
953 | static int qlcnic_sriov_pf_del_tx_ctx_cmd(struct qlcnic_bc_trans *trans, | |
954 | struct qlcnic_cmd_args *cmd) | |
955 | { | |
956 | struct qlcnic_vf_info *vf = trans->vf; | |
957 | struct qlcnic_adapter *adapter = vf->adapter; | |
958 | int err; | |
959 | ||
960 | err = qlcnic_sriov_validate_del_tx_ctx(vf, cmd); | |
961 | if (err) { | |
962 | cmd->rsp.arg[0] |= (0x6 << 25); | |
963 | return err; | |
964 | } | |
965 | ||
966 | cmd->req.arg[1] |= vf->vp->handle << 16; | |
967 | err = qlcnic_issue_cmd(adapter, cmd); | |
968 | ||
969 | if (!err) | |
970 | vf->tx_ctx_id = 0; | |
971 | ||
972 | return err; | |
973 | } | |
974 | ||
975 | static int qlcnic_sriov_validate_cfg_lro(struct qlcnic_vf_info *vf, | |
976 | struct qlcnic_cmd_args *cmd) | |
977 | { | |
978 | if ((cmd->req.arg[1] >> 16) != vf->rx_ctx_id) | |
979 | return -EINVAL; | |
980 | ||
981 | return 0; | |
982 | } | |
983 | ||
984 | static int qlcnic_sriov_pf_cfg_lro_cmd(struct qlcnic_bc_trans *trans, | |
985 | struct qlcnic_cmd_args *cmd) | |
986 | { | |
987 | struct qlcnic_vf_info *vf = trans->vf; | |
988 | struct qlcnic_adapter *adapter = vf->adapter; | |
989 | int err; | |
990 | ||
991 | err = qlcnic_sriov_validate_cfg_lro(vf, cmd); | |
992 | if (err) { | |
993 | cmd->rsp.arg[0] |= (0x6 << 25); | |
994 | return err; | |
995 | } | |
996 | ||
997 | err = qlcnic_issue_cmd(adapter, cmd); | |
998 | return err; | |
999 | } | |
1000 | ||
1001 | static int qlcnic_sriov_pf_cfg_ip_cmd(struct qlcnic_bc_trans *trans, | |
1002 | struct qlcnic_cmd_args *cmd) | |
1003 | { | |
1004 | struct qlcnic_vf_info *vf = trans->vf; | |
1005 | struct qlcnic_adapter *adapter = vf->adapter; | |
1006 | int err = -EIO; | |
1007 | u8 op; | |
1008 | ||
1009 | op = cmd->req.arg[1] & 0xff; | |
1010 | ||
1011 | cmd->req.arg[1] |= vf->vp->handle << 16; | |
1012 | cmd->req.arg[1] |= BIT_31; | |
1013 | ||
1014 | err = qlcnic_issue_cmd(adapter, cmd); | |
1015 | return err; | |
1016 | } | |
1017 | ||
1018 | static int qlcnic_sriov_validate_cfg_intrpt(struct qlcnic_vf_info *vf, | |
1019 | struct qlcnic_cmd_args *cmd) | |
1020 | { | |
1021 | if (((cmd->req.arg[1] >> 8) & 0xff) != vf->pci_func) | |
1022 | return -EINVAL; | |
1023 | ||
1024 | if (!(cmd->req.arg[1] & BIT_16)) | |
1025 | return -EINVAL; | |
1026 | ||
1027 | if ((cmd->req.arg[1] & 0xff) != 0x1) | |
1028 | return -EINVAL; | |
1029 | ||
1030 | return 0; | |
1031 | } | |
1032 | ||
1033 | static int qlcnic_sriov_pf_cfg_intrpt_cmd(struct qlcnic_bc_trans *trans, | |
1034 | struct qlcnic_cmd_args *cmd) | |
1035 | { | |
1036 | struct qlcnic_vf_info *vf = trans->vf; | |
1037 | struct qlcnic_adapter *adapter = vf->adapter; | |
1038 | int err; | |
1039 | ||
1040 | err = qlcnic_sriov_validate_cfg_intrpt(vf, cmd); | |
1041 | if (err) | |
1042 | cmd->rsp.arg[0] |= (0x6 << 25); | |
1043 | else | |
1044 | err = qlcnic_issue_cmd(adapter, cmd); | |
1045 | ||
1046 | return err; | |
1047 | } | |
1048 | ||
1049 | static int qlcnic_sriov_validate_mtu(struct qlcnic_adapter *adapter, | |
1050 | struct qlcnic_vf_info *vf, | |
1051 | struct qlcnic_cmd_args *cmd) | |
1052 | { | |
1053 | if (cmd->req.arg[1] != vf->rx_ctx_id) | |
1054 | return -EINVAL; | |
1055 | ||
1056 | if (cmd->req.arg[2] > adapter->ahw->max_mtu) | |
1057 | return -EINVAL; | |
1058 | ||
1059 | return 0; | |
1060 | } | |
1061 | ||
1062 | static int qlcnic_sriov_pf_set_mtu_cmd(struct qlcnic_bc_trans *trans, | |
1063 | struct qlcnic_cmd_args *cmd) | |
1064 | { | |
1065 | struct qlcnic_vf_info *vf = trans->vf; | |
1066 | struct qlcnic_adapter *adapter = vf->adapter; | |
1067 | int err; | |
1068 | ||
1069 | err = qlcnic_sriov_validate_mtu(adapter, vf, cmd); | |
1070 | if (err) | |
1071 | cmd->rsp.arg[0] |= (0x6 << 25); | |
1072 | else | |
1073 | err = qlcnic_issue_cmd(adapter, cmd); | |
1074 | ||
1075 | return err; | |
1076 | } | |
1077 | ||
1078 | static int qlcnic_sriov_validate_get_nic_info(struct qlcnic_vf_info *vf, | |
1079 | struct qlcnic_cmd_args *cmd) | |
1080 | { | |
1081 | if (cmd->req.arg[1] & BIT_31) { | |
1082 | if (((cmd->req.arg[1] >> 16) & 0x7fff) != vf->pci_func) | |
1083 | return -EINVAL; | |
1084 | } else { | |
1085 | cmd->req.arg[1] |= vf->vp->handle << 16; | |
1086 | } | |
1087 | ||
1088 | return 0; | |
1089 | } | |
1090 | ||
1091 | static int qlcnic_sriov_pf_get_nic_info_cmd(struct qlcnic_bc_trans *trans, | |
1092 | struct qlcnic_cmd_args *cmd) | |
1093 | { | |
1094 | struct qlcnic_vf_info *vf = trans->vf; | |
1095 | struct qlcnic_adapter *adapter = vf->adapter; | |
1096 | int err; | |
1097 | ||
1098 | err = qlcnic_sriov_validate_get_nic_info(vf, cmd); | |
1099 | if (err) { | |
1100 | cmd->rsp.arg[0] |= (0x6 << 25); | |
1101 | return err; | |
1102 | } | |
1103 | ||
1104 | err = qlcnic_issue_cmd(adapter, cmd); | |
1105 | return err; | |
1106 | } | |
1107 | ||
1108 | static int qlcnic_sriov_validate_cfg_rss(struct qlcnic_vf_info *vf, | |
1109 | struct qlcnic_cmd_args *cmd) | |
1110 | { | |
1111 | if (cmd->req.arg[1] != vf->rx_ctx_id) | |
1112 | return -EINVAL; | |
1113 | ||
1114 | return 0; | |
1115 | } | |
1116 | ||
1117 | static int qlcnic_sriov_pf_cfg_rss_cmd(struct qlcnic_bc_trans *trans, | |
1118 | struct qlcnic_cmd_args *cmd) | |
1119 | { | |
1120 | struct qlcnic_vf_info *vf = trans->vf; | |
1121 | struct qlcnic_adapter *adapter = vf->adapter; | |
1122 | int err; | |
1123 | ||
1124 | err = qlcnic_sriov_validate_cfg_rss(vf, cmd); | |
1125 | if (err) | |
1126 | cmd->rsp.arg[0] |= (0x6 << 25); | |
1127 | else | |
1128 | err = qlcnic_issue_cmd(adapter, cmd); | |
1129 | ||
1130 | return err; | |
1131 | } | |
1132 | ||
1133 | static int qlcnic_sriov_validate_cfg_intrcoal(struct qlcnic_adapter *adapter, | |
1134 | struct qlcnic_vf_info *vf, | |
1135 | struct qlcnic_cmd_args *cmd) | |
1136 | { | |
1137 | struct qlcnic_nic_intr_coalesce *coal = &adapter->ahw->coal; | |
1138 | u16 ctx_id, pkts, time; | |
1139 | ||
1140 | ctx_id = cmd->req.arg[1] >> 16; | |
1141 | pkts = cmd->req.arg[2] & 0xffff; | |
1142 | time = cmd->req.arg[2] >> 16; | |
1143 | ||
1144 | if (ctx_id != vf->rx_ctx_id) | |
1145 | return -EINVAL; | |
1146 | if (pkts > coal->rx_packets) | |
1147 | return -EINVAL; | |
1148 | if (time < coal->rx_time_us) | |
1149 | return -EINVAL; | |
1150 | ||
1151 | return 0; | |
1152 | } | |
1153 | ||
1154 | static int qlcnic_sriov_pf_cfg_intrcoal_cmd(struct qlcnic_bc_trans *tran, | |
1155 | struct qlcnic_cmd_args *cmd) | |
1156 | { | |
1157 | struct qlcnic_vf_info *vf = tran->vf; | |
1158 | struct qlcnic_adapter *adapter = vf->adapter; | |
1159 | int err; | |
1160 | ||
1161 | err = qlcnic_sriov_validate_cfg_intrcoal(adapter, vf, cmd); | |
1162 | if (err) { | |
1163 | cmd->rsp.arg[0] |= (0x6 << 25); | |
1164 | return err; | |
1165 | } | |
1166 | ||
1167 | err = qlcnic_issue_cmd(adapter, cmd); | |
1168 | return err; | |
1169 | } | |
1170 | ||
1171 | static int qlcnic_sriov_validate_cfg_macvlan(struct qlcnic_adapter *adapter, | |
1172 | struct qlcnic_vf_info *vf, | |
1173 | struct qlcnic_cmd_args *cmd) | |
1174 | { | |
1175 | struct qlcnic_macvlan_mbx *macvlan; | |
91b7282b RB |
1176 | struct qlcnic_vport *vp = vf->vp; |
1177 | u8 op, new_op; | |
7cb03b23 | 1178 | |
1414abea SC |
1179 | if (((cmd->req.arg[1] & QLC_MAC_OPCODE_MASK) == QLC_MAC_STAR_ADD) || |
1180 | ((cmd->req.arg[1] & QLC_MAC_OPCODE_MASK) == QLC_MAC_STAR_DEL)) { | |
1181 | netdev_err(adapter->netdev, "MAC + any VLAN filter not allowed from VF %d\n", | |
1182 | vf->pci_func); | |
1183 | return -EINVAL; | |
1184 | } | |
1185 | ||
7cb03b23 RB |
1186 | if (!(cmd->req.arg[1] & BIT_8)) |
1187 | return -EINVAL; | |
1188 | ||
1189 | cmd->req.arg[1] |= (vf->vp->handle << 16); | |
1190 | cmd->req.arg[1] |= BIT_31; | |
1191 | ||
1192 | macvlan = (struct qlcnic_macvlan_mbx *)&cmd->req.arg[2]; | |
1193 | if (!(macvlan->mac_addr0 & BIT_0)) { | |
1194 | dev_err(&adapter->pdev->dev, | |
1195 | "MAC address change is not allowed from VF %d", | |
1196 | vf->pci_func); | |
1197 | return -EINVAL; | |
1198 | } | |
1199 | ||
91b7282b RB |
1200 | if (vp->vlan_mode == QLC_PVID_MODE) { |
1201 | op = cmd->req.arg[1] & 0x7; | |
1202 | cmd->req.arg[1] &= ~0x7; | |
1203 | new_op = (op == QLCNIC_MAC_ADD || op == QLCNIC_MAC_VLAN_ADD) ? | |
1204 | QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_VLAN_DEL; | |
154d0c81 | 1205 | cmd->req.arg[3] |= vp->pvid << 16; |
91b7282b RB |
1206 | cmd->req.arg[1] |= new_op; |
1207 | } | |
1208 | ||
7cb03b23 RB |
1209 | return 0; |
1210 | } | |
1211 | ||
1212 | static int qlcnic_sriov_pf_cfg_macvlan_cmd(struct qlcnic_bc_trans *trans, | |
1213 | struct qlcnic_cmd_args *cmd) | |
1214 | { | |
1215 | struct qlcnic_vf_info *vf = trans->vf; | |
1216 | struct qlcnic_adapter *adapter = vf->adapter; | |
1217 | int err; | |
1218 | ||
1219 | err = qlcnic_sriov_validate_cfg_macvlan(adapter, vf, cmd); | |
1220 | if (err) { | |
1221 | cmd->rsp.arg[0] |= (0x6 << 25); | |
1222 | return err; | |
1223 | } | |
1224 | ||
1225 | err = qlcnic_issue_cmd(adapter, cmd); | |
1226 | return err; | |
1227 | } | |
1228 | ||
1229 | static int qlcnic_sriov_validate_linkevent(struct qlcnic_vf_info *vf, | |
1230 | struct qlcnic_cmd_args *cmd) | |
1231 | { | |
1232 | if ((cmd->req.arg[1] >> 16) != vf->rx_ctx_id) | |
1233 | return -EINVAL; | |
1234 | ||
7cb03b23 RB |
1235 | return 0; |
1236 | } | |
1237 | ||
1238 | static int qlcnic_sriov_pf_linkevent_cmd(struct qlcnic_bc_trans *trans, | |
1239 | struct qlcnic_cmd_args *cmd) | |
1240 | { | |
1241 | struct qlcnic_vf_info *vf = trans->vf; | |
1242 | struct qlcnic_adapter *adapter = vf->adapter; | |
1243 | int err; | |
1244 | ||
1245 | err = qlcnic_sriov_validate_linkevent(vf, cmd); | |
1246 | if (err) { | |
1247 | cmd->rsp.arg[0] |= (0x6 << 25); | |
1248 | return err; | |
1249 | } | |
1250 | ||
1251 | err = qlcnic_issue_cmd(adapter, cmd); | |
1252 | return err; | |
1253 | } | |
1254 | ||
1255 | static int qlcnic_sriov_pf_cfg_promisc_cmd(struct qlcnic_bc_trans *trans, | |
1256 | struct qlcnic_cmd_args *cmd) | |
1257 | { | |
1258 | struct qlcnic_vf_info *vf = trans->vf; | |
1259 | struct qlcnic_adapter *adapter = vf->adapter; | |
1260 | int err; | |
1261 | ||
1262 | cmd->req.arg[1] |= vf->vp->handle << 16; | |
1263 | cmd->req.arg[1] |= BIT_31; | |
1264 | err = qlcnic_issue_cmd(adapter, cmd); | |
1265 | return err; | |
1266 | } | |
1267 | ||
91b7282b RB |
1268 | static int qlcnic_sriov_pf_get_acl_cmd(struct qlcnic_bc_trans *trans, |
1269 | struct qlcnic_cmd_args *cmd) | |
1270 | { | |
1271 | struct qlcnic_vf_info *vf = trans->vf; | |
1272 | struct qlcnic_vport *vp = vf->vp; | |
1273 | u8 cmd_op, mode = vp->vlan_mode; | |
991ca269 | 1274 | struct qlcnic_adapter *adapter; |
154d0c81 | 1275 | struct qlcnic_sriov *sriov; |
991ca269 MC |
1276 | |
1277 | adapter = vf->adapter; | |
154d0c81 | 1278 | sriov = adapter->ahw->sriov; |
91b7282b RB |
1279 | |
1280 | cmd_op = trans->req_hdr->cmd_op; | |
6226204b | 1281 | cmd->rsp.arg[0] |= 1 << 25; |
91b7282b | 1282 | |
991ca269 MC |
1283 | /* For 84xx adapter in case of PVID , PFD should send vlan mode as |
1284 | * QLC_NO_VLAN_MODE to VFD which is zero in mailbox response | |
1285 | */ | |
1286 | if (qlcnic_84xx_check(adapter) && mode == QLC_PVID_MODE) | |
1287 | return 0; | |
1288 | ||
91b7282b RB |
1289 | switch (mode) { |
1290 | case QLC_GUEST_VLAN_MODE: | |
1291 | cmd->rsp.arg[1] = mode | 1 << 8; | |
154d0c81 | 1292 | cmd->rsp.arg[2] = sriov->num_allowed_vlans << 16; |
91b7282b RB |
1293 | break; |
1294 | case QLC_PVID_MODE: | |
154d0c81 | 1295 | cmd->rsp.arg[1] = mode | 1 << 8 | vp->pvid << 16; |
91b7282b RB |
1296 | break; |
1297 | } | |
1298 | ||
1299 | return 0; | |
1300 | } | |
1301 | ||
1302 | static int qlcnic_sriov_pf_del_guest_vlan(struct qlcnic_adapter *adapter, | |
154d0c81 MC |
1303 | struct qlcnic_vf_info *vf, |
1304 | struct qlcnic_cmd_args *cmd) | |
91b7282b | 1305 | { |
154d0c81 MC |
1306 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; |
1307 | u16 vlan; | |
91b7282b | 1308 | |
154d0c81 | 1309 | if (!qlcnic_sriov_check_any_vlan(vf)) |
91b7282b RB |
1310 | return -EINVAL; |
1311 | ||
154d0c81 | 1312 | vlan = cmd->req.arg[1] >> 16; |
91b7282b | 1313 | if (!vf->rx_ctx_id) { |
154d0c81 | 1314 | qlcnic_sriov_del_vlan_id(sriov, vf, vlan); |
91b7282b RB |
1315 | return 0; |
1316 | } | |
1317 | ||
154d0c81 MC |
1318 | qlcnic_sriov_cfg_vf_def_mac(adapter, vf, vlan, QLCNIC_MAC_DEL); |
1319 | qlcnic_sriov_del_vlan_id(sriov, vf, vlan); | |
1320 | ||
1321 | if (qlcnic_83xx_pf_check(adapter)) | |
1322 | qlcnic_sriov_cfg_vf_def_mac(adapter, vf, | |
1323 | 0, QLCNIC_MAC_ADD); | |
91b7282b RB |
1324 | return 0; |
1325 | } | |
1326 | ||
1327 | static int qlcnic_sriov_pf_add_guest_vlan(struct qlcnic_adapter *adapter, | |
1328 | struct qlcnic_vf_info *vf, | |
1329 | struct qlcnic_cmd_args *cmd) | |
1330 | { | |
154d0c81 | 1331 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; |
91b7282b | 1332 | int err = -EIO; |
154d0c81 | 1333 | u16 vlan; |
91b7282b | 1334 | |
154d0c81 | 1335 | if (qlcnic_83xx_pf_check(adapter) && qlcnic_sriov_check_any_vlan(vf)) |
91b7282b RB |
1336 | return err; |
1337 | ||
154d0c81 MC |
1338 | vlan = cmd->req.arg[1] >> 16; |
1339 | ||
91b7282b | 1340 | if (!vf->rx_ctx_id) { |
154d0c81 | 1341 | qlcnic_sriov_add_vlan_id(sriov, vf, vlan); |
91b7282b RB |
1342 | return 0; |
1343 | } | |
1344 | ||
154d0c81 MC |
1345 | if (qlcnic_83xx_pf_check(adapter)) { |
1346 | err = qlcnic_sriov_cfg_vf_def_mac(adapter, vf, 0, | |
1347 | QLCNIC_MAC_DEL); | |
1348 | if (err) | |
1349 | return err; | |
1350 | } | |
91b7282b | 1351 | |
154d0c81 | 1352 | err = qlcnic_sriov_cfg_vf_def_mac(adapter, vf, vlan, QLCNIC_MAC_ADD); |
91b7282b RB |
1353 | |
1354 | if (err) { | |
154d0c81 MC |
1355 | if (qlcnic_83xx_pf_check(adapter)) |
1356 | qlcnic_sriov_cfg_vf_def_mac(adapter, vf, 0, | |
1357 | QLCNIC_MAC_ADD); | |
1358 | return err; | |
91b7282b RB |
1359 | } |
1360 | ||
154d0c81 | 1361 | qlcnic_sriov_add_vlan_id(sriov, vf, vlan); |
91b7282b RB |
1362 | return err; |
1363 | } | |
1364 | ||
1365 | static int qlcnic_sriov_pf_cfg_guest_vlan_cmd(struct qlcnic_bc_trans *tran, | |
1366 | struct qlcnic_cmd_args *cmd) | |
1367 | { | |
1368 | struct qlcnic_vf_info *vf = tran->vf; | |
1369 | struct qlcnic_adapter *adapter = vf->adapter; | |
1370 | struct qlcnic_vport *vp = vf->vp; | |
1371 | int err = -EIO; | |
1372 | u8 op; | |
1373 | ||
1374 | if (vp->vlan_mode != QLC_GUEST_VLAN_MODE) { | |
1375 | cmd->rsp.arg[0] |= 2 << 25; | |
1376 | return err; | |
1377 | } | |
1378 | ||
1379 | op = cmd->req.arg[1] & 0xf; | |
1380 | ||
1381 | if (op) | |
1382 | err = qlcnic_sriov_pf_add_guest_vlan(adapter, vf, cmd); | |
1383 | else | |
154d0c81 | 1384 | err = qlcnic_sriov_pf_del_guest_vlan(adapter, vf, cmd); |
91b7282b RB |
1385 | |
1386 | cmd->rsp.arg[0] |= err ? 2 << 25 : 1 << 25; | |
1387 | return err; | |
1388 | } | |
1389 | ||
7cb03b23 RB |
1390 | static const int qlcnic_pf_passthru_supp_cmds[] = { |
1391 | QLCNIC_CMD_GET_STATISTICS, | |
1392 | QLCNIC_CMD_GET_PORT_CONFIG, | |
1393 | QLCNIC_CMD_GET_LINK_STATUS, | |
2d8ebcab SC |
1394 | QLCNIC_CMD_INIT_NIC_FUNC, |
1395 | QLCNIC_CMD_STOP_NIC_FUNC, | |
7cb03b23 RB |
1396 | }; |
1397 | ||
f197a7aa RB |
1398 | static const struct qlcnic_sriov_cmd_handler qlcnic_pf_bc_cmd_hdlr[] = { |
1399 | [QLCNIC_BC_CMD_CHANNEL_INIT] = {&qlcnic_sriov_pf_channel_cfg_cmd}, | |
1400 | [QLCNIC_BC_CMD_CHANNEL_TERM] = {&qlcnic_sriov_pf_channel_cfg_cmd}, | |
91b7282b RB |
1401 | [QLCNIC_BC_CMD_GET_ACL] = {&qlcnic_sriov_pf_get_acl_cmd}, |
1402 | [QLCNIC_BC_CMD_CFG_GUEST_VLAN] = {&qlcnic_sriov_pf_cfg_guest_vlan_cmd}, | |
f197a7aa RB |
1403 | }; |
1404 | ||
7cb03b23 RB |
1405 | static const struct qlcnic_sriov_fw_cmd_handler qlcnic_pf_fw_cmd_hdlr[] = { |
1406 | {QLCNIC_CMD_CREATE_RX_CTX, qlcnic_sriov_pf_create_rx_ctx_cmd}, | |
1407 | {QLCNIC_CMD_CREATE_TX_CTX, qlcnic_sriov_pf_create_tx_ctx_cmd}, | |
1408 | {QLCNIC_CMD_MAC_ADDRESS, qlcnic_sriov_pf_mac_address_cmd}, | |
1409 | {QLCNIC_CMD_DESTROY_RX_CTX, qlcnic_sriov_pf_del_rx_ctx_cmd}, | |
1410 | {QLCNIC_CMD_DESTROY_TX_CTX, qlcnic_sriov_pf_del_tx_ctx_cmd}, | |
1411 | {QLCNIC_CMD_CONFIGURE_HW_LRO, qlcnic_sriov_pf_cfg_lro_cmd}, | |
1412 | {QLCNIC_CMD_CONFIGURE_IP_ADDR, qlcnic_sriov_pf_cfg_ip_cmd}, | |
1413 | {QLCNIC_CMD_CONFIG_INTRPT, qlcnic_sriov_pf_cfg_intrpt_cmd}, | |
1414 | {QLCNIC_CMD_SET_MTU, qlcnic_sriov_pf_set_mtu_cmd}, | |
1415 | {QLCNIC_CMD_GET_NIC_INFO, qlcnic_sriov_pf_get_nic_info_cmd}, | |
1416 | {QLCNIC_CMD_CONFIGURE_RSS, qlcnic_sriov_pf_cfg_rss_cmd}, | |
1417 | {QLCNIC_CMD_CONFIG_INTR_COAL, qlcnic_sriov_pf_cfg_intrcoal_cmd}, | |
1418 | {QLCNIC_CMD_CONFIG_MAC_VLAN, qlcnic_sriov_pf_cfg_macvlan_cmd}, | |
1419 | {QLCNIC_CMD_GET_LINK_EVENT, qlcnic_sriov_pf_linkevent_cmd}, | |
1420 | {QLCNIC_CMD_CONFIGURE_MAC_RX_MODE, qlcnic_sriov_pf_cfg_promisc_cmd}, | |
1421 | }; | |
1422 | ||
f197a7aa RB |
1423 | void qlcnic_sriov_pf_process_bc_cmd(struct qlcnic_adapter *adapter, |
1424 | struct qlcnic_bc_trans *trans, | |
1425 | struct qlcnic_cmd_args *cmd) | |
1426 | { | |
1427 | u8 size, cmd_op; | |
1428 | ||
1429 | cmd_op = trans->req_hdr->cmd_op; | |
1430 | ||
1431 | if (trans->req_hdr->op_type == QLC_BC_CMD) { | |
1432 | size = ARRAY_SIZE(qlcnic_pf_bc_cmd_hdlr); | |
1433 | if (cmd_op < size) { | |
1434 | qlcnic_pf_bc_cmd_hdlr[cmd_op].fn(trans, cmd); | |
1435 | return; | |
1436 | } | |
7cb03b23 RB |
1437 | } else { |
1438 | int i; | |
1439 | size = ARRAY_SIZE(qlcnic_pf_fw_cmd_hdlr); | |
1440 | for (i = 0; i < size; i++) { | |
1441 | if (cmd_op == qlcnic_pf_fw_cmd_hdlr[i].cmd) { | |
1442 | qlcnic_pf_fw_cmd_hdlr[i].fn(trans, cmd); | |
1443 | return; | |
1444 | } | |
1445 | } | |
1446 | ||
1447 | size = ARRAY_SIZE(qlcnic_pf_passthru_supp_cmds); | |
1448 | for (i = 0; i < size; i++) { | |
1449 | if (cmd_op == qlcnic_pf_passthru_supp_cmds[i]) { | |
1450 | qlcnic_issue_cmd(adapter, cmd); | |
1451 | return; | |
1452 | } | |
1453 | } | |
f197a7aa RB |
1454 | } |
1455 | ||
1456 | cmd->rsp.arg[0] |= (0x9 << 25); | |
1457 | } | |
7cb03b23 RB |
1458 | |
1459 | void qlcnic_pf_set_interface_id_create_rx_ctx(struct qlcnic_adapter *adapter, | |
1460 | u32 *int_id) | |
1461 | { | |
1462 | u16 vpid; | |
1463 | ||
1464 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, | |
1465 | adapter->ahw->pci_func); | |
1466 | *int_id |= vpid; | |
1467 | } | |
1468 | ||
1469 | void qlcnic_pf_set_interface_id_del_rx_ctx(struct qlcnic_adapter *adapter, | |
1470 | u32 *int_id) | |
1471 | { | |
1472 | u16 vpid; | |
1473 | ||
1474 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, | |
1475 | adapter->ahw->pci_func); | |
1476 | *int_id |= vpid << 16; | |
1477 | } | |
1478 | ||
1479 | void qlcnic_pf_set_interface_id_create_tx_ctx(struct qlcnic_adapter *adapter, | |
1480 | u32 *int_id) | |
1481 | { | |
1482 | int vpid; | |
1483 | ||
1484 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, | |
1485 | adapter->ahw->pci_func); | |
1486 | *int_id |= vpid << 16; | |
1487 | } | |
1488 | ||
1489 | void qlcnic_pf_set_interface_id_del_tx_ctx(struct qlcnic_adapter *adapter, | |
1490 | u32 *int_id) | |
1491 | { | |
1492 | u16 vpid; | |
1493 | ||
1494 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, | |
1495 | adapter->ahw->pci_func); | |
1496 | *int_id |= vpid << 16; | |
1497 | } | |
1498 | ||
1499 | void qlcnic_pf_set_interface_id_promisc(struct qlcnic_adapter *adapter, | |
1500 | u32 *int_id) | |
1501 | { | |
1502 | u16 vpid; | |
1503 | ||
1504 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, | |
1505 | adapter->ahw->pci_func); | |
1506 | *int_id |= (vpid << 16) | BIT_31; | |
1507 | } | |
1508 | ||
1509 | void qlcnic_pf_set_interface_id_ipaddr(struct qlcnic_adapter *adapter, | |
1510 | u32 *int_id) | |
1511 | { | |
1512 | u16 vpid; | |
1513 | ||
1514 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, | |
1515 | adapter->ahw->pci_func); | |
1516 | *int_id |= (vpid << 16) | BIT_31; | |
1517 | } | |
1518 | ||
1519 | void qlcnic_pf_set_interface_id_macaddr(struct qlcnic_adapter *adapter, | |
1520 | u32 *int_id) | |
1521 | { | |
1522 | u16 vpid; | |
1523 | ||
1524 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, | |
1525 | adapter->ahw->pci_func); | |
1526 | *int_id |= (vpid << 16) | BIT_31; | |
1527 | } | |
97d8105c RB |
1528 | |
1529 | static void qlcnic_sriov_del_rx_ctx(struct qlcnic_adapter *adapter, | |
1530 | struct qlcnic_vf_info *vf) | |
1531 | { | |
1532 | struct qlcnic_cmd_args cmd; | |
1533 | int vpid; | |
1534 | ||
1535 | if (!vf->rx_ctx_id) | |
1536 | return; | |
1537 | ||
1538 | if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_DESTROY_RX_CTX)) | |
1539 | return; | |
1540 | ||
1541 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, vf->pci_func); | |
1542 | if (vpid >= 0) { | |
1543 | cmd.req.arg[1] = vf->rx_ctx_id | (vpid & 0xffff) << 16; | |
1544 | if (qlcnic_issue_cmd(adapter, &cmd)) | |
1545 | dev_err(&adapter->pdev->dev, | |
1546 | "Failed to delete Tx ctx in firmware for func 0x%x\n", | |
1547 | vf->pci_func); | |
1548 | else | |
1549 | vf->rx_ctx_id = 0; | |
1550 | } | |
1551 | ||
1552 | qlcnic_free_mbx_args(&cmd); | |
1553 | } | |
1554 | ||
1555 | static void qlcnic_sriov_del_tx_ctx(struct qlcnic_adapter *adapter, | |
1556 | struct qlcnic_vf_info *vf) | |
1557 | { | |
1558 | struct qlcnic_cmd_args cmd; | |
1559 | int vpid; | |
1560 | ||
1561 | if (!vf->tx_ctx_id) | |
1562 | return; | |
1563 | ||
1564 | if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_DESTROY_TX_CTX)) | |
1565 | return; | |
1566 | ||
1567 | vpid = qlcnic_sriov_pf_get_vport_handle(adapter, vf->pci_func); | |
1568 | if (vpid >= 0) { | |
1569 | cmd.req.arg[1] |= vf->tx_ctx_id | (vpid & 0xffff) << 16; | |
1570 | if (qlcnic_issue_cmd(adapter, &cmd)) | |
1571 | dev_err(&adapter->pdev->dev, | |
1572 | "Failed to delete Tx ctx in firmware for func 0x%x\n", | |
1573 | vf->pci_func); | |
1574 | else | |
1575 | vf->tx_ctx_id = 0; | |
1576 | } | |
1577 | ||
1578 | qlcnic_free_mbx_args(&cmd); | |
1579 | } | |
1580 | ||
1581 | static int qlcnic_sriov_add_act_list_irqsave(struct qlcnic_sriov *sriov, | |
1582 | struct qlcnic_vf_info *vf, | |
1583 | struct qlcnic_bc_trans *trans) | |
1584 | { | |
1585 | struct qlcnic_trans_list *t_list = &vf->rcv_act; | |
1586 | unsigned long flag; | |
1587 | ||
1588 | spin_lock_irqsave(&t_list->lock, flag); | |
1589 | ||
1590 | __qlcnic_sriov_add_act_list(sriov, vf, trans); | |
1591 | ||
1592 | spin_unlock_irqrestore(&t_list->lock, flag); | |
1593 | return 0; | |
1594 | } | |
1595 | ||
1596 | static void __qlcnic_sriov_process_flr(struct qlcnic_vf_info *vf) | |
1597 | { | |
1598 | struct qlcnic_adapter *adapter = vf->adapter; | |
1599 | ||
1600 | qlcnic_sriov_cleanup_list(&vf->rcv_pend); | |
1601 | cancel_work_sync(&vf->trans_work); | |
1602 | qlcnic_sriov_cleanup_list(&vf->rcv_act); | |
1603 | ||
1604 | if (test_bit(QLC_BC_VF_SOFT_FLR, &vf->state)) { | |
1605 | qlcnic_sriov_del_tx_ctx(adapter, vf); | |
1606 | qlcnic_sriov_del_rx_ctx(adapter, vf); | |
1607 | } | |
1608 | ||
1609 | qlcnic_sriov_pf_config_vport(adapter, 0, vf->pci_func); | |
1610 | ||
1611 | clear_bit(QLC_BC_VF_FLR, &vf->state); | |
1612 | if (test_bit(QLC_BC_VF_SOFT_FLR, &vf->state)) { | |
1613 | qlcnic_sriov_add_act_list_irqsave(adapter->ahw->sriov, vf, | |
1614 | vf->flr_trans); | |
1615 | clear_bit(QLC_BC_VF_SOFT_FLR, &vf->state); | |
1616 | vf->flr_trans = NULL; | |
1617 | } | |
1618 | } | |
1619 | ||
1620 | static void qlcnic_sriov_pf_process_flr(struct work_struct *work) | |
1621 | { | |
1622 | struct qlcnic_vf_info *vf; | |
1623 | ||
1624 | vf = container_of(work, struct qlcnic_vf_info, flr_work); | |
1625 | __qlcnic_sriov_process_flr(vf); | |
1626 | return; | |
1627 | } | |
1628 | ||
1629 | static void qlcnic_sriov_schedule_flr(struct qlcnic_sriov *sriov, | |
1630 | struct qlcnic_vf_info *vf, | |
1631 | work_func_t func) | |
1632 | { | |
1633 | if (test_bit(__QLCNIC_RESETTING, &vf->adapter->state)) | |
1634 | return; | |
1635 | ||
1636 | INIT_WORK(&vf->flr_work, func); | |
1637 | queue_work(sriov->bc.bc_flr_wq, &vf->flr_work); | |
1638 | } | |
1639 | ||
1640 | static void qlcnic_sriov_handle_soft_flr(struct qlcnic_adapter *adapter, | |
1641 | struct qlcnic_bc_trans *trans, | |
1642 | struct qlcnic_vf_info *vf) | |
1643 | { | |
1644 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
1645 | ||
1646 | set_bit(QLC_BC_VF_FLR, &vf->state); | |
1647 | clear_bit(QLC_BC_VF_STATE, &vf->state); | |
1648 | set_bit(QLC_BC_VF_SOFT_FLR, &vf->state); | |
1649 | vf->flr_trans = trans; | |
1650 | qlcnic_sriov_schedule_flr(sriov, vf, qlcnic_sriov_pf_process_flr); | |
1651 | netdev_info(adapter->netdev, "Software FLR for PCI func %d\n", | |
1652 | vf->pci_func); | |
1653 | } | |
1654 | ||
1655 | bool qlcnic_sriov_soft_flr_check(struct qlcnic_adapter *adapter, | |
1656 | struct qlcnic_bc_trans *trans, | |
1657 | struct qlcnic_vf_info *vf) | |
1658 | { | |
1659 | struct qlcnic_bc_hdr *hdr = trans->req_hdr; | |
1660 | ||
1661 | if ((hdr->cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT) && | |
1662 | (hdr->op_type == QLC_BC_CMD) && | |
1663 | test_bit(QLC_BC_VF_STATE, &vf->state)) { | |
1664 | qlcnic_sriov_handle_soft_flr(adapter, trans, vf); | |
1665 | return true; | |
1666 | } | |
1667 | ||
1668 | return false; | |
1669 | } | |
1670 | ||
1671 | void qlcnic_sriov_pf_handle_flr(struct qlcnic_sriov *sriov, | |
1672 | struct qlcnic_vf_info *vf) | |
1673 | { | |
1674 | struct net_device *dev = vf->adapter->netdev; | |
2f0a9afa | 1675 | struct qlcnic_vport *vp = vf->vp; |
97d8105c RB |
1676 | |
1677 | if (!test_and_clear_bit(QLC_BC_VF_STATE, &vf->state)) { | |
1678 | clear_bit(QLC_BC_VF_FLR, &vf->state); | |
1679 | return; | |
1680 | } | |
1681 | ||
1682 | if (test_and_set_bit(QLC_BC_VF_FLR, &vf->state)) { | |
1683 | netdev_info(dev, "FLR for PCI func %d in progress\n", | |
1684 | vf->pci_func); | |
1685 | return; | |
1686 | } | |
1687 | ||
2f0a9afa | 1688 | if (vp->vlan_mode == QLC_GUEST_VLAN_MODE) |
154d0c81 MC |
1689 | memset(vf->sriov_vlans, 0, |
1690 | sizeof(*vf->sriov_vlans) * sriov->num_allowed_vlans); | |
2f0a9afa | 1691 | |
97d8105c RB |
1692 | qlcnic_sriov_schedule_flr(sriov, vf, qlcnic_sriov_pf_process_flr); |
1693 | netdev_info(dev, "FLR received for PCI func %d\n", vf->pci_func); | |
1694 | } | |
f036e4f4 RB |
1695 | |
1696 | void qlcnic_sriov_pf_reset(struct qlcnic_adapter *adapter) | |
1697 | { | |
1698 | struct qlcnic_hardware_context *ahw = adapter->ahw; | |
1699 | struct qlcnic_sriov *sriov = ahw->sriov; | |
1700 | struct qlcnic_vf_info *vf; | |
1701 | u16 num_vfs = sriov->num_vfs; | |
1702 | int i; | |
1703 | ||
1704 | for (i = 0; i < num_vfs; i++) { | |
1705 | vf = &sriov->vf_info[i]; | |
1706 | vf->rx_ctx_id = 0; | |
1707 | vf->tx_ctx_id = 0; | |
1708 | cancel_work_sync(&vf->flr_work); | |
1709 | __qlcnic_sriov_process_flr(vf); | |
1710 | clear_bit(QLC_BC_VF_STATE, &vf->state); | |
1711 | } | |
1712 | ||
1713 | qlcnic_sriov_pf_reset_vport_handle(adapter, ahw->pci_func); | |
1714 | QLCWRX(ahw, QLCNIC_MBX_INTR_ENBL, (ahw->num_msix - 1) << 8); | |
1715 | } | |
1716 | ||
1717 | int qlcnic_sriov_pf_reinit(struct qlcnic_adapter *adapter) | |
1718 | { | |
1719 | struct qlcnic_hardware_context *ahw = adapter->ahw; | |
1720 | int err; | |
1721 | ||
1722 | if (!qlcnic_sriov_enable_check(adapter)) | |
1723 | return 0; | |
1724 | ||
1725 | ahw->op_mode = QLCNIC_SRIOV_PF_FUNC; | |
1726 | ||
1727 | err = qlcnic_sriov_pf_init(adapter); | |
1728 | if (err) | |
1729 | return err; | |
1730 | ||
1731 | dev_info(&adapter->pdev->dev, "%s: op_mode %d\n", | |
1732 | __func__, ahw->op_mode); | |
1733 | return err; | |
1734 | } | |
4000e7a7 RB |
1735 | |
1736 | int qlcnic_sriov_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) | |
1737 | { | |
1738 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1739 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
cab150b5 | 1740 | int i, num_vfs; |
4000e7a7 RB |
1741 | struct qlcnic_vf_info *vf_info; |
1742 | u8 *curr_mac; | |
1743 | ||
1744 | if (!qlcnic_sriov_pf_check(adapter)) | |
1745 | return -EOPNOTSUPP; | |
1746 | ||
cab150b5 MC |
1747 | num_vfs = sriov->num_vfs; |
1748 | ||
4000e7a7 RB |
1749 | if (!is_valid_ether_addr(mac) || vf >= num_vfs) |
1750 | return -EINVAL; | |
1751 | ||
7367d0b5 | 1752 | if (ether_addr_equal(adapter->mac_addr, mac)) { |
4000e7a7 RB |
1753 | netdev_err(netdev, "MAC address is already in use by the PF\n"); |
1754 | return -EINVAL; | |
1755 | } | |
1756 | ||
1757 | for (i = 0; i < num_vfs; i++) { | |
1758 | vf_info = &sriov->vf_info[i]; | |
7367d0b5 | 1759 | if (ether_addr_equal(vf_info->vp->mac, mac)) { |
4000e7a7 RB |
1760 | netdev_err(netdev, |
1761 | "MAC address is already in use by VF %d\n", | |
1762 | i); | |
1763 | return -EINVAL; | |
1764 | } | |
1765 | } | |
1766 | ||
1767 | vf_info = &sriov->vf_info[vf]; | |
1768 | curr_mac = vf_info->vp->mac; | |
1769 | ||
1770 | if (test_bit(QLC_BC_VF_STATE, &vf_info->state)) { | |
1771 | netdev_err(netdev, | |
1772 | "MAC address change failed for VF %d, as VF driver is loaded. Please unload VF driver and retry the operation\n", | |
1773 | vf); | |
1774 | return -EOPNOTSUPP; | |
1775 | } | |
1776 | ||
1777 | memcpy(curr_mac, mac, netdev->addr_len); | |
1778 | netdev_info(netdev, "MAC Address %pM is configured for VF %d\n", | |
1779 | mac, vf); | |
1780 | return 0; | |
1781 | } | |
1782 | ||
1783 | int qlcnic_sriov_set_vf_tx_rate(struct net_device *netdev, int vf, int tx_rate) | |
1784 | { | |
1785 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1786 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
1787 | struct qlcnic_vf_info *vf_info; | |
1788 | struct qlcnic_info nic_info; | |
1789 | struct qlcnic_vport *vp; | |
1790 | u16 vpid; | |
1791 | ||
1792 | if (!qlcnic_sriov_pf_check(adapter)) | |
1793 | return -EOPNOTSUPP; | |
1794 | ||
1795 | if (vf >= sriov->num_vfs) | |
1796 | return -EINVAL; | |
1797 | ||
1798 | if (tx_rate >= 10000 || tx_rate < 100) { | |
1799 | netdev_err(netdev, | |
1800 | "Invalid Tx rate, allowed range is [%d - %d]", | |
1801 | QLC_VF_MIN_TX_RATE, QLC_VF_MAX_TX_RATE); | |
1802 | return -EINVAL; | |
1803 | } | |
1804 | ||
1805 | if (tx_rate == 0) | |
1806 | tx_rate = 10000; | |
1807 | ||
1808 | vf_info = &sriov->vf_info[vf]; | |
1809 | vp = vf_info->vp; | |
1810 | vpid = vp->handle; | |
1811 | ||
1812 | if (test_bit(QLC_BC_VF_STATE, &vf_info->state)) { | |
1813 | if (qlcnic_sriov_get_vf_vport_info(adapter, &nic_info, vpid)) | |
1814 | return -EIO; | |
1815 | ||
1816 | nic_info.max_tx_bw = tx_rate / 100; | |
1817 | nic_info.bit_offsets = BIT_0; | |
1818 | ||
1819 | if (qlcnic_sriov_pf_set_vport_info(adapter, &nic_info, vpid)) | |
1820 | return -EIO; | |
1821 | } | |
1822 | ||
1823 | vp->max_tx_bw = tx_rate / 100; | |
1824 | netdev_info(netdev, | |
1825 | "Setting Tx rate %d (Mbps), %d %% of PF bandwidth, for VF %d\n", | |
1826 | tx_rate, vp->max_tx_bw, vf); | |
1827 | return 0; | |
1828 | } | |
1829 | ||
91b7282b RB |
1830 | int qlcnic_sriov_set_vf_vlan(struct net_device *netdev, int vf, |
1831 | u16 vlan, u8 qos) | |
1832 | { | |
1833 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1834 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
1835 | struct qlcnic_vf_info *vf_info; | |
1836 | struct qlcnic_vport *vp; | |
1837 | ||
1838 | if (!qlcnic_sriov_pf_check(adapter)) | |
1839 | return -EOPNOTSUPP; | |
1840 | ||
1841 | if (vf >= sriov->num_vfs || qos > 7) | |
1842 | return -EINVAL; | |
1843 | ||
1844 | if (vlan > MAX_VLAN_ID) { | |
1845 | netdev_err(netdev, | |
1846 | "Invalid VLAN ID, allowed range is [0 - %d]\n", | |
1847 | MAX_VLAN_ID); | |
1848 | return -EINVAL; | |
1849 | } | |
1850 | ||
1851 | vf_info = &sriov->vf_info[vf]; | |
1852 | vp = vf_info->vp; | |
1853 | if (test_bit(QLC_BC_VF_STATE, &vf_info->state)) { | |
1854 | netdev_err(netdev, | |
1855 | "VLAN change failed for VF %d, as VF driver is loaded. Please unload VF driver and retry the operation\n", | |
1856 | vf); | |
1857 | return -EOPNOTSUPP; | |
1858 | } | |
1859 | ||
154d0c81 MC |
1860 | memset(vf_info->sriov_vlans, 0, |
1861 | sizeof(*vf_info->sriov_vlans) * sriov->num_allowed_vlans); | |
1862 | ||
91b7282b RB |
1863 | switch (vlan) { |
1864 | case 4095: | |
1865 | vp->vlan_mode = QLC_GUEST_VLAN_MODE; | |
1866 | break; | |
1867 | case 0: | |
1868 | vp->vlan_mode = QLC_NO_VLAN_MODE; | |
91b7282b RB |
1869 | vp->qos = 0; |
1870 | break; | |
1871 | default: | |
1872 | vp->vlan_mode = QLC_PVID_MODE; | |
154d0c81 | 1873 | qlcnic_sriov_add_vlan_id(sriov, vf_info, vlan); |
91b7282b | 1874 | vp->qos = qos; |
154d0c81 | 1875 | vp->pvid = vlan; |
91b7282b RB |
1876 | } |
1877 | ||
1878 | netdev_info(netdev, "Setting VLAN %d, QoS %d, for VF %d\n", | |
1879 | vlan, qos, vf); | |
1880 | return 0; | |
1881 | } | |
1882 | ||
60dcbcb0 MC |
1883 | static __u32 qlcnic_sriov_get_vf_vlan(struct qlcnic_adapter *adapter, |
1884 | struct qlcnic_vport *vp, int vf) | |
7cfc1ceb MC |
1885 | { |
1886 | __u32 vlan = 0; | |
1887 | ||
1888 | switch (vp->vlan_mode) { | |
1889 | case QLC_PVID_MODE: | |
154d0c81 | 1890 | vlan = vp->pvid; |
7cfc1ceb MC |
1891 | break; |
1892 | case QLC_GUEST_VLAN_MODE: | |
1893 | vlan = MAX_VLAN_ID; | |
1894 | break; | |
1895 | case QLC_NO_VLAN_MODE: | |
1896 | vlan = 0; | |
1897 | break; | |
1898 | default: | |
1899 | netdev_info(adapter->netdev, "Invalid VLAN mode = %d for VF %d\n", | |
1900 | vp->vlan_mode, vf); | |
1901 | } | |
1902 | ||
1903 | return vlan; | |
1904 | } | |
1905 | ||
4000e7a7 RB |
1906 | int qlcnic_sriov_get_vf_config(struct net_device *netdev, |
1907 | int vf, struct ifla_vf_info *ivi) | |
1908 | { | |
1909 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1910 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
1911 | struct qlcnic_vport *vp; | |
1912 | ||
1913 | if (!qlcnic_sriov_pf_check(adapter)) | |
1914 | return -EOPNOTSUPP; | |
1915 | ||
1916 | if (vf >= sriov->num_vfs) | |
1917 | return -EINVAL; | |
1918 | ||
1919 | vp = sriov->vf_info[vf].vp; | |
1920 | memcpy(&ivi->mac, vp->mac, ETH_ALEN); | |
7cfc1ceb | 1921 | ivi->vlan = qlcnic_sriov_get_vf_vlan(adapter, vp, vf); |
91b7282b | 1922 | ivi->qos = vp->qos; |
a80be5a5 | 1923 | ivi->spoofchk = vp->spoofchk; |
4000e7a7 RB |
1924 | if (vp->max_tx_bw == MAX_BW) |
1925 | ivi->tx_rate = 0; | |
1926 | else | |
1927 | ivi->tx_rate = vp->max_tx_bw * 100; | |
1928 | ||
1929 | ivi->vf = vf; | |
1930 | return 0; | |
1931 | } | |
a80be5a5 RB |
1932 | |
1933 | int qlcnic_sriov_set_vf_spoofchk(struct net_device *netdev, int vf, bool chk) | |
1934 | { | |
1935 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1936 | struct qlcnic_sriov *sriov = adapter->ahw->sriov; | |
1937 | struct qlcnic_vf_info *vf_info; | |
1938 | struct qlcnic_vport *vp; | |
1939 | ||
1940 | if (!qlcnic_sriov_pf_check(adapter)) | |
1941 | return -EOPNOTSUPP; | |
1942 | ||
1943 | if (vf >= sriov->num_vfs) | |
1944 | return -EINVAL; | |
1945 | ||
1946 | vf_info = &sriov->vf_info[vf]; | |
1947 | vp = vf_info->vp; | |
1948 | if (test_bit(QLC_BC_VF_STATE, &vf_info->state)) { | |
1949 | netdev_err(netdev, | |
1950 | "Spoof check change failed for VF %d, as VF driver is loaded. Please unload VF driver and retry the operation\n", | |
1951 | vf); | |
1952 | return -EOPNOTSUPP; | |
1953 | } | |
1954 | ||
1955 | vp->spoofchk = chk; | |
1956 | return 0; | |
1957 | } |