2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2013 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
8 #include "qlcnic_sriov.h"
10 #include <linux/types.h>
12 #define QLCNIC_SRIOV_VF_MAX_MAC 7
13 #define QLC_VF_MIN_TX_RATE 100
14 #define QLC_VF_MAX_TX_RATE 9999
15 #define QLC_MAC_OPCODE_MASK 0x7
16 #define QLC_VF_FLOOD_BIT BIT_16
17 #define QLC_FLOOD_MODE 0x5
18 #define QLC_SRIOV_ALLOW_VLAN0 BIT_19
19 #define QLC_INTR_COAL_TYPE_MASK 0x7
21 static int qlcnic_sriov_pf_get_vport_handle(struct qlcnic_adapter *, u8);
23 struct qlcnic_sriov_cmd_handler {
24 int (*fn) (struct qlcnic_bc_trans *, struct qlcnic_cmd_args *);
27 struct qlcnic_sriov_fw_cmd_handler {
29 int (*fn) (struct qlcnic_bc_trans *, struct qlcnic_cmd_args *);
32 static int qlcnic_sriov_pf_set_vport_info(struct qlcnic_adapter *adapter,
33 struct qlcnic_info *npar_info,
36 struct qlcnic_cmd_args cmd;
39 if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_SET_NIC_INFO))
42 cmd.req.arg[1] = (vport_id << 16) | 0x1;
43 cmd.req.arg[2] = npar_info->bit_offsets;
44 cmd.req.arg[2] |= npar_info->min_tx_bw << 16;
45 cmd.req.arg[3] = npar_info->max_tx_bw | (npar_info->max_tx_ques << 16);
46 cmd.req.arg[4] = npar_info->max_tx_mac_filters;
47 cmd.req.arg[4] |= npar_info->max_rx_mcast_mac_filters << 16;
48 cmd.req.arg[5] = npar_info->max_rx_ucast_mac_filters |
49 (npar_info->max_rx_ip_addr << 16);
50 cmd.req.arg[6] = npar_info->max_rx_lro_flow |
51 (npar_info->max_rx_status_rings << 16);
52 cmd.req.arg[7] = npar_info->max_rx_buf_rings |
53 (npar_info->max_rx_ques << 16);
54 cmd.req.arg[8] = npar_info->max_tx_vlan_keys;
55 cmd.req.arg[8] |= npar_info->max_local_ipv6_addrs << 16;
56 cmd.req.arg[9] = npar_info->max_remote_ipv6_addrs;
58 err = qlcnic_issue_cmd(adapter, &cmd);
60 dev_err(&adapter->pdev->dev,
61 "Failed to set vport info, err=%d\n", err);
63 qlcnic_free_mbx_args(&cmd);
67 static int qlcnic_sriov_pf_cal_res_limit(struct qlcnic_adapter *adapter,
68 struct qlcnic_info *info, u16 func)
70 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
71 struct qlcnic_resources *res = &sriov->ff_max;
72 u16 num_macs = sriov->num_allowed_vlans + 1;
73 int ret = -EIO, vpid, id;
74 struct qlcnic_vport *vp;
75 u32 num_vfs, max, temp;
77 vpid = qlcnic_sriov_pf_get_vport_handle(adapter, func);
81 num_vfs = sriov->num_vfs;
83 info->bit_offsets = 0xffff;
84 info->max_tx_ques = res->num_tx_queues / max;
86 if (qlcnic_83xx_pf_check(adapter))
87 num_macs = QLCNIC_83XX_SRIOV_VF_MAX_MAC;
89 info->max_rx_mcast_mac_filters = res->num_rx_mcast_mac_filters;
91 if (adapter->ahw->pci_func == func) {
93 info->max_tx_bw = MAX_BW;
95 temp = res->num_rx_ucast_mac_filters - num_macs * num_vfs;
96 info->max_rx_ucast_mac_filters = temp;
97 temp = res->num_tx_mac_filters - num_macs * num_vfs;
98 info->max_tx_mac_filters = temp;
99 temp = num_macs * num_vfs * QLCNIC_SRIOV_VF_MAX_MAC;
100 temp = res->num_rx_mcast_mac_filters - temp;
101 info->max_rx_mcast_mac_filters = temp;
103 info->max_tx_ques = res->num_tx_queues - sriov->num_vfs;
105 id = qlcnic_sriov_func_to_index(adapter, func);
108 vp = sriov->vf_info[id].vp;
109 info->min_tx_bw = vp->min_tx_bw;
110 info->max_tx_bw = vp->max_tx_bw;
112 info->max_rx_ucast_mac_filters = num_macs;
113 info->max_tx_mac_filters = num_macs;
114 temp = num_macs * QLCNIC_SRIOV_VF_MAX_MAC;
115 info->max_rx_mcast_mac_filters = temp;
117 info->max_tx_ques = QLCNIC_SINGLE_RING;
120 info->max_rx_ip_addr = res->num_destip / max;
121 info->max_rx_status_rings = res->num_rx_status_rings / max;
122 info->max_rx_buf_rings = res->num_rx_buf_rings / max;
123 info->max_rx_ques = res->num_rx_queues / max;
124 info->max_rx_lro_flow = res->num_lro_flows_supported / max;
125 info->max_tx_vlan_keys = res->num_txvlan_keys;
126 info->max_local_ipv6_addrs = res->max_local_ipv6_addrs;
127 info->max_remote_ipv6_addrs = res->max_remote_ipv6_addrs;
129 ret = qlcnic_sriov_pf_set_vport_info(adapter, info, vpid);
136 static void qlcnic_sriov_pf_set_ff_max_res(struct qlcnic_adapter *adapter,
137 struct qlcnic_info *info)
139 struct qlcnic_resources *ff_max = &adapter->ahw->sriov->ff_max;
141 ff_max->num_tx_mac_filters = info->max_tx_mac_filters;
142 ff_max->num_rx_ucast_mac_filters = info->max_rx_ucast_mac_filters;
143 ff_max->num_rx_mcast_mac_filters = info->max_rx_mcast_mac_filters;
144 ff_max->num_txvlan_keys = info->max_tx_vlan_keys;
145 ff_max->num_rx_queues = info->max_rx_ques;
146 ff_max->num_tx_queues = info->max_tx_ques;
147 ff_max->num_lro_flows_supported = info->max_rx_lro_flow;
148 ff_max->num_destip = info->max_rx_ip_addr;
149 ff_max->num_rx_buf_rings = info->max_rx_buf_rings;
150 ff_max->num_rx_status_rings = info->max_rx_status_rings;
151 ff_max->max_remote_ipv6_addrs = info->max_remote_ipv6_addrs;
152 ff_max->max_local_ipv6_addrs = info->max_local_ipv6_addrs;
155 static void qlcnic_sriov_set_vf_max_vlan(struct qlcnic_adapter *adapter,
156 struct qlcnic_info *npar_info)
158 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
161 temp = npar_info->max_rx_mcast_mac_filters;
162 total_fn = sriov->num_vfs + 1;
164 temp = temp / (QLCNIC_SRIOV_VF_MAX_MAC * total_fn);
165 sriov->num_allowed_vlans = temp - 1;
167 if (qlcnic_83xx_pf_check(adapter))
168 sriov->num_allowed_vlans = 1;
170 netdev_info(adapter->netdev, "Max Guest VLANs supported per VF = %d\n",
171 sriov->num_allowed_vlans);
174 static int qlcnic_sriov_get_pf_info(struct qlcnic_adapter *adapter,
175 struct qlcnic_info *npar_info)
178 struct qlcnic_cmd_args cmd;
180 if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_GET_NIC_INFO))
183 cmd.req.arg[1] = 0x2;
184 err = qlcnic_issue_cmd(adapter, &cmd);
186 dev_err(&adapter->pdev->dev,
187 "Failed to get PF info, err=%d\n", err);
191 npar_info->total_pf = cmd.rsp.arg[2] & 0xff;
192 npar_info->total_rss_engines = (cmd.rsp.arg[2] >> 8) & 0xff;
193 npar_info->max_vports = MSW(cmd.rsp.arg[2]);
194 npar_info->max_tx_ques = LSW(cmd.rsp.arg[3]);
195 npar_info->max_tx_mac_filters = MSW(cmd.rsp.arg[3]);
196 npar_info->max_rx_mcast_mac_filters = LSW(cmd.rsp.arg[4]);
197 npar_info->max_rx_ucast_mac_filters = MSW(cmd.rsp.arg[4]);
198 npar_info->max_rx_ip_addr = LSW(cmd.rsp.arg[5]);
199 npar_info->max_rx_lro_flow = MSW(cmd.rsp.arg[5]);
200 npar_info->max_rx_status_rings = LSW(cmd.rsp.arg[6]);
201 npar_info->max_rx_buf_rings = MSW(cmd.rsp.arg[6]);
202 npar_info->max_rx_ques = LSW(cmd.rsp.arg[7]);
203 npar_info->max_tx_vlan_keys = MSW(cmd.rsp.arg[7]);
204 npar_info->max_local_ipv6_addrs = LSW(cmd.rsp.arg[8]);
205 npar_info->max_remote_ipv6_addrs = MSW(cmd.rsp.arg[8]);
207 qlcnic_sriov_set_vf_max_vlan(adapter, npar_info);
208 qlcnic_sriov_pf_set_ff_max_res(adapter, npar_info);
209 dev_info(&adapter->pdev->dev,
210 "\n\ttotal_pf: %d,\n"
211 "\n\ttotal_rss_engines: %d max_vports: %d max_tx_ques %d,\n"
212 "\tmax_tx_mac_filters: %d max_rx_mcast_mac_filters: %d,\n"
213 "\tmax_rx_ucast_mac_filters: 0x%x, max_rx_ip_addr: %d,\n"
214 "\tmax_rx_lro_flow: %d max_rx_status_rings: %d,\n"
215 "\tmax_rx_buf_rings: %d, max_rx_ques: %d, max_tx_vlan_keys %d\n"
216 "\tmax_local_ipv6_addrs: %d, max_remote_ipv6_addrs: %d\n",
217 npar_info->total_pf, npar_info->total_rss_engines,
218 npar_info->max_vports, npar_info->max_tx_ques,
219 npar_info->max_tx_mac_filters,
220 npar_info->max_rx_mcast_mac_filters,
221 npar_info->max_rx_ucast_mac_filters, npar_info->max_rx_ip_addr,
222 npar_info->max_rx_lro_flow, npar_info->max_rx_status_rings,
223 npar_info->max_rx_buf_rings, npar_info->max_rx_ques,
224 npar_info->max_tx_vlan_keys, npar_info->max_local_ipv6_addrs,
225 npar_info->max_remote_ipv6_addrs);
228 qlcnic_free_mbx_args(&cmd);
232 static void qlcnic_sriov_pf_reset_vport_handle(struct qlcnic_adapter *adapter,
235 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
236 struct qlcnic_vport *vp;
239 if (adapter->ahw->pci_func == func) {
240 sriov->vp_handle = 0;
242 index = qlcnic_sriov_func_to_index(adapter, func);
245 vp = sriov->vf_info[index].vp;
250 static void qlcnic_sriov_pf_set_vport_handle(struct qlcnic_adapter *adapter,
251 u16 vport_handle, u8 func)
253 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
254 struct qlcnic_vport *vp;
257 if (adapter->ahw->pci_func == func) {
258 sriov->vp_handle = vport_handle;
260 index = qlcnic_sriov_func_to_index(adapter, func);
263 vp = sriov->vf_info[index].vp;
264 vp->handle = vport_handle;
268 static int qlcnic_sriov_pf_get_vport_handle(struct qlcnic_adapter *adapter,
271 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
272 struct qlcnic_vf_info *vf_info;
275 if (adapter->ahw->pci_func == func) {
276 return sriov->vp_handle;
278 index = qlcnic_sriov_func_to_index(adapter, func);
280 vf_info = &sriov->vf_info[index];
281 return vf_info->vp->handle;
288 static int qlcnic_sriov_pf_config_vport(struct qlcnic_adapter *adapter,
291 struct qlcnic_cmd_args cmd;
295 if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_CONFIG_VPORT))
299 cmd.req.arg[3] = func << 8;
301 vpid = qlcnic_sriov_pf_get_vport_handle(adapter, func);
306 cmd.req.arg[3] = ((vpid & 0xffff) << 8) | 1;
309 ret = qlcnic_issue_cmd(adapter, &cmd);
311 dev_err(&adapter->pdev->dev,
312 "Failed %s vport, err %d for func 0x%x\n",
313 (flag ? "enable" : "disable"), ret, func);
318 vpid = cmd.rsp.arg[2] & 0xffff;
319 qlcnic_sriov_pf_set_vport_handle(adapter, vpid, func);
321 qlcnic_sriov_pf_reset_vport_handle(adapter, func);
325 qlcnic_free_mbx_args(&cmd);
329 static int qlcnic_sriov_pf_cfg_vlan_filtering(struct qlcnic_adapter *adapter,
332 struct qlcnic_cmd_args cmd;
335 err = qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_SET_NIC_INFO);
339 cmd.req.arg[1] = 0x4;
341 adapter->flags |= QLCNIC_VLAN_FILTERING;
342 cmd.req.arg[1] |= BIT_16;
343 if (qlcnic_84xx_check(adapter))
344 cmd.req.arg[1] |= QLC_SRIOV_ALLOW_VLAN0;
346 adapter->flags &= ~QLCNIC_VLAN_FILTERING;
349 err = qlcnic_issue_cmd(adapter, &cmd);
351 dev_err(&adapter->pdev->dev,
352 "Failed to configure VLAN filtering, err=%d\n", err);
354 qlcnic_free_mbx_args(&cmd);
358 /* On configuring VF flood bit, PFD will receive traffic from all VFs */
359 static int qlcnic_sriov_pf_cfg_flood(struct qlcnic_adapter *adapter)
361 struct qlcnic_cmd_args cmd;
364 err = qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_SET_NIC_INFO);
368 cmd.req.arg[1] = QLC_FLOOD_MODE | QLC_VF_FLOOD_BIT;
370 err = qlcnic_issue_cmd(adapter, &cmd);
372 dev_err(&adapter->pdev->dev,
373 "Failed to configure VF Flood bit on PF, err=%d\n",
376 qlcnic_free_mbx_args(&cmd);
380 static int qlcnic_sriov_pf_cfg_eswitch(struct qlcnic_adapter *adapter,
383 struct qlcnic_cmd_args cmd;
386 if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_TOGGLE_ESWITCH))
389 cmd.req.arg[0] |= (3 << 29);
390 cmd.req.arg[1] = ((func & 0xf) << 2) | BIT_6 | BIT_1;
392 cmd.req.arg[1] |= BIT_0;
394 err = qlcnic_issue_cmd(adapter, &cmd);
396 if (err != QLCNIC_RCODE_SUCCESS) {
397 dev_err(&adapter->pdev->dev,
398 "Failed to enable sriov eswitch%d\n", err);
402 qlcnic_free_mbx_args(&cmd);
406 static void qlcnic_sriov_pf_del_flr_queue(struct qlcnic_adapter *adapter)
408 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
409 struct qlcnic_back_channel *bc = &sriov->bc;
412 for (i = 0; i < sriov->num_vfs; i++)
413 cancel_work_sync(&sriov->vf_info[i].flr_work);
415 destroy_workqueue(bc->bc_flr_wq);
418 static int qlcnic_sriov_pf_create_flr_queue(struct qlcnic_adapter *adapter)
420 struct qlcnic_back_channel *bc = &adapter->ahw->sriov->bc;
421 struct workqueue_struct *wq;
423 wq = create_singlethread_workqueue("qlcnic-flr");
425 dev_err(&adapter->pdev->dev, "Cannot create FLR workqueue\n");
433 void qlcnic_sriov_pf_cleanup(struct qlcnic_adapter *adapter)
435 u8 func = adapter->ahw->pci_func;
437 if (!qlcnic_sriov_enable_check(adapter))
440 qlcnic_sriov_pf_del_flr_queue(adapter);
441 qlcnic_sriov_cfg_bc_intr(adapter, 0);
442 qlcnic_sriov_pf_config_vport(adapter, 0, func);
443 qlcnic_sriov_pf_cfg_eswitch(adapter, func, 0);
444 qlcnic_sriov_pf_cfg_vlan_filtering(adapter, 0);
445 __qlcnic_sriov_cleanup(adapter);
446 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
447 clear_bit(__QLCNIC_SRIOV_ENABLE, &adapter->state);
450 void qlcnic_sriov_pf_disable(struct qlcnic_adapter *adapter)
452 if (!qlcnic_sriov_pf_check(adapter))
455 if (!qlcnic_sriov_enable_check(adapter))
458 pci_disable_sriov(adapter->pdev);
459 netdev_info(adapter->netdev,
460 "SR-IOV is disabled successfully on port %d\n",
464 static int qlcnic_pci_sriov_disable(struct qlcnic_adapter *adapter)
466 struct net_device *netdev = adapter->netdev;
468 if (pci_vfs_assigned(adapter->pdev)) {
469 netdev_err(adapter->netdev,
470 "SR-IOV VFs belonging to port %d are assigned to VMs. SR-IOV can not be disabled on this port\n",
472 netdev_info(adapter->netdev,
473 "Please detach SR-IOV VFs belonging to port %d from VMs, and then try to disable SR-IOV on this port\n",
478 qlcnic_sriov_pf_disable(adapter);
481 if (netif_running(netdev))
482 __qlcnic_down(adapter, netdev);
484 qlcnic_sriov_free_vlans(adapter);
486 qlcnic_sriov_pf_cleanup(adapter);
488 /* After disabling SRIOV re-init the driver in default mode
489 configure opmode based on op_mode of function
491 if (qlcnic_83xx_configure_opmode(adapter)) {
496 if (netif_running(netdev))
497 __qlcnic_up(adapter, netdev);
503 static int qlcnic_sriov_pf_init(struct qlcnic_adapter *adapter)
505 struct qlcnic_hardware_context *ahw = adapter->ahw;
506 struct qlcnic_info nic_info, pf_info, vp_info;
508 u8 func = ahw->pci_func;
510 if (!qlcnic_sriov_enable_check(adapter))
513 err = qlcnic_sriov_pf_cfg_vlan_filtering(adapter, 1);
517 if (qlcnic_84xx_check(adapter)) {
518 err = qlcnic_sriov_pf_cfg_flood(adapter);
520 goto disable_vlan_filtering;
523 err = qlcnic_sriov_pf_cfg_eswitch(adapter, func, 1);
525 goto disable_vlan_filtering;
527 err = qlcnic_sriov_pf_config_vport(adapter, 1, func);
529 goto disable_eswitch;
531 err = qlcnic_sriov_get_pf_info(adapter, &pf_info);
535 err = qlcnic_get_nic_info(adapter, &nic_info, func);
539 err = qlcnic_sriov_pf_cal_res_limit(adapter, &vp_info, func);
543 err = qlcnic_sriov_cfg_bc_intr(adapter, 1);
547 ahw->physical_port = (u8) nic_info.phys_port;
548 ahw->switch_mode = nic_info.switch_mode;
549 ahw->max_mtu = nic_info.max_mtu;
550 ahw->capabilities = nic_info.capabilities;
551 ahw->nic_mode = QLC_83XX_SRIOV_MODE;
555 qlcnic_sriov_pf_config_vport(adapter, 0, func);
558 qlcnic_sriov_pf_cfg_eswitch(adapter, func, 0);
560 disable_vlan_filtering:
561 qlcnic_sriov_pf_cfg_vlan_filtering(adapter, 0);
566 static int qlcnic_sriov_pf_enable(struct qlcnic_adapter *adapter, int num_vfs)
570 if (!qlcnic_sriov_enable_check(adapter))
573 err = pci_enable_sriov(adapter->pdev, num_vfs);
575 qlcnic_sriov_pf_cleanup(adapter);
580 static int __qlcnic_pci_sriov_enable(struct qlcnic_adapter *adapter,
585 set_bit(__QLCNIC_SRIOV_ENABLE, &adapter->state);
586 adapter->ahw->op_mode = QLCNIC_SRIOV_PF_FUNC;
588 err = qlcnic_sriov_init(adapter, num_vfs);
592 err = qlcnic_sriov_pf_create_flr_queue(adapter);
596 err = qlcnic_sriov_pf_init(adapter);
600 qlcnic_sriov_alloc_vlans(adapter);
605 qlcnic_sriov_pf_del_flr_queue(adapter);
608 __qlcnic_sriov_cleanup(adapter);
611 clear_bit(__QLCNIC_SRIOV_ENABLE, &adapter->state);
612 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
616 static int qlcnic_pci_sriov_enable(struct qlcnic_adapter *adapter, int num_vfs)
618 struct net_device *netdev = adapter->netdev;
621 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) {
623 "SR-IOV cannot be enabled, when legacy interrupts are enabled\n");
628 if (netif_running(netdev))
629 __qlcnic_down(adapter, netdev);
631 err = __qlcnic_pci_sriov_enable(adapter, num_vfs);
635 if (netif_running(netdev))
636 __qlcnic_up(adapter, netdev);
639 err = qlcnic_sriov_pf_enable(adapter, num_vfs);
642 "SR-IOV is enabled successfully on port %d\n",
644 /* Return number of vfs enabled */
649 if (netif_running(netdev))
650 __qlcnic_down(adapter, netdev);
653 if (!qlcnic_83xx_configure_opmode(adapter)) {
654 if (netif_running(netdev))
655 __qlcnic_up(adapter, netdev);
659 netdev_info(netdev, "Failed to enable SR-IOV on port %d\n",
665 int qlcnic_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
667 struct qlcnic_adapter *adapter = pci_get_drvdata(dev);
670 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
674 err = qlcnic_pci_sriov_disable(adapter);
676 err = qlcnic_pci_sriov_enable(adapter, num_vfs);
678 clear_bit(__QLCNIC_RESETTING, &adapter->state);
682 static int qlcnic_sriov_set_vf_acl(struct qlcnic_adapter *adapter, u8 func)
684 struct qlcnic_cmd_args cmd;
685 struct qlcnic_vport *vp;
689 id = qlcnic_sriov_func_to_index(adapter, func);
693 vp = adapter->ahw->sriov->vf_info[id].vp;
694 err = qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_SET_NIC_INFO);
698 cmd.req.arg[1] = 0x3 | func << 16;
699 if (vp->spoofchk == true) {
701 cmd.req.arg[2] |= BIT_1 | BIT_3 | BIT_8;
702 cmd.req.arg[4] = mac[5] | mac[4] << 8 | mac[3] << 16 |
704 cmd.req.arg[5] = mac[1] | mac[0] << 8;
707 if (vp->vlan_mode == QLC_PVID_MODE) {
708 cmd.req.arg[2] |= BIT_6;
709 cmd.req.arg[3] |= vp->pvid << 8;
712 err = qlcnic_issue_cmd(adapter, &cmd);
714 dev_err(&adapter->pdev->dev, "Failed to set ACL, err=%d\n",
717 qlcnic_free_mbx_args(&cmd);
721 static int qlcnic_sriov_set_vf_vport_info(struct qlcnic_adapter *adapter,
724 struct qlcnic_info defvp_info;
727 err = qlcnic_sriov_pf_cal_res_limit(adapter, &defvp_info, func);
731 err = qlcnic_sriov_set_vf_acl(adapter, func);
738 static int qlcnic_sriov_pf_channel_cfg_cmd(struct qlcnic_bc_trans *trans,
739 struct qlcnic_cmd_args *cmd)
741 struct qlcnic_vf_info *vf = trans->vf;
742 struct qlcnic_vport *vp = vf->vp;
743 struct qlcnic_adapter *adapter;
744 struct qlcnic_sriov *sriov;
745 u16 func = vf->pci_func;
749 adapter = vf->adapter;
750 sriov = adapter->ahw->sriov;
752 if (trans->req_hdr->cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT) {
753 err = qlcnic_sriov_pf_config_vport(adapter, 1, func);
755 err = qlcnic_sriov_set_vf_vport_info(adapter, func);
757 qlcnic_sriov_pf_config_vport(adapter, 0, func);
760 if (vp->vlan_mode == QLC_GUEST_VLAN_MODE) {
761 size = sizeof(*vf->sriov_vlans);
762 size = size * sriov->num_allowed_vlans;
763 memset(vf->sriov_vlans, 0, size);
766 err = qlcnic_sriov_pf_config_vport(adapter, 0, func);
772 cmd->rsp.arg[0] |= (1 << 25);
774 if (trans->req_hdr->cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT)
775 set_bit(QLC_BC_VF_STATE, &vf->state);
777 clear_bit(QLC_BC_VF_STATE, &vf->state);
782 cmd->rsp.arg[0] |= (2 << 25);
786 static int qlcnic_sriov_cfg_vf_def_mac(struct qlcnic_adapter *adapter,
787 struct qlcnic_vf_info *vf,
790 struct qlcnic_cmd_args *cmd;
791 struct qlcnic_macvlan_mbx mv;
792 struct qlcnic_vport *vp;
800 cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC);
804 err = qlcnic_alloc_mbx_args(cmd, adapter, QLCNIC_CMD_CONFIG_MAC_VLAN);
808 cmd->type = QLC_83XX_MBX_CMD_NO_WAIT;
809 vpid = qlcnic_sriov_pf_get_vport_handle(adapter, vf->pci_func);
816 op = ((op == QLCNIC_MAC_ADD || op == QLCNIC_MAC_VLAN_ADD) ?
817 QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_VLAN_DEL);
819 cmd->req.arg[1] = op | (1 << 8) | (3 << 6);
820 cmd->req.arg[1] |= ((vpid & 0xffff) << 16) | BIT_31;
824 mv.mac_addr0 = addr[0];
825 mv.mac_addr1 = addr[1];
826 mv.mac_addr2 = addr[2];
827 mv.mac_addr3 = addr[3];
828 mv.mac_addr4 = addr[4];
829 mv.mac_addr5 = addr[5];
830 buf = &cmd->req.arg[2];
831 memcpy(buf, &mv, sizeof(struct qlcnic_macvlan_mbx));
833 err = qlcnic_issue_cmd(adapter, cmd);
839 qlcnic_free_mbx_args(cmd);
845 static int qlcnic_sriov_validate_create_rx_ctx(struct qlcnic_cmd_args *cmd)
847 if ((cmd->req.arg[0] >> 29) != 0x3)
853 static void qlcnic_83xx_cfg_default_mac_vlan(struct qlcnic_adapter *adapter,
854 struct qlcnic_vf_info *vf,
857 struct qlcnic_sriov *sriov;
861 sriov = adapter->ahw->sriov;
863 spin_lock_bh(&vf->vlan_list_lock);
865 for (i = 0; i < sriov->num_allowed_vlans; i++) {
866 vlan = vf->sriov_vlans[i];
868 qlcnic_sriov_cfg_vf_def_mac(adapter, vf, vlan,
872 spin_unlock_bh(&vf->vlan_list_lock);
874 if (vf->vp->vlan_mode != QLC_PVID_MODE) {
875 if (qlcnic_83xx_pf_check(adapter) &&
876 qlcnic_sriov_check_any_vlan(vf))
878 qlcnic_sriov_cfg_vf_def_mac(adapter, vf, 0, opcode);
882 static int qlcnic_sriov_pf_create_rx_ctx_cmd(struct qlcnic_bc_trans *tran,
883 struct qlcnic_cmd_args *cmd)
885 struct qlcnic_vf_info *vf = tran->vf;
886 struct qlcnic_adapter *adapter = vf->adapter;
887 struct qlcnic_rcv_mbx_out *mbx_out;
890 err = qlcnic_sriov_validate_create_rx_ctx(cmd);
892 cmd->rsp.arg[0] |= (0x6 << 25);
896 cmd->req.arg[6] = vf->vp->handle;
897 err = qlcnic_issue_cmd(adapter, cmd);
900 mbx_out = (struct qlcnic_rcv_mbx_out *)&cmd->rsp.arg[1];
901 vf->rx_ctx_id = mbx_out->ctx_id;
902 qlcnic_83xx_cfg_default_mac_vlan(adapter, vf, QLCNIC_MAC_ADD);
910 static int qlcnic_sriov_pf_mac_address_cmd(struct qlcnic_bc_trans *trans,
911 struct qlcnic_cmd_args *cmd)
913 struct qlcnic_vf_info *vf = trans->vf;
916 type = cmd->req.arg[1];
918 case QLCNIC_SET_STATION_MAC:
919 case QLCNIC_SET_FAC_DEF_MAC:
920 cmd->rsp.arg[0] = (2 << 25);
922 case QLCNIC_GET_CURRENT_MAC:
923 cmd->rsp.arg[0] = (1 << 25);
925 cmd->rsp.arg[2] = mac[1] | ((mac[0] << 8) & 0xff00);
926 cmd->rsp.arg[1] = mac[5] | ((mac[4] << 8) & 0xff00) |
927 ((mac[3]) << 16 & 0xff0000) |
928 ((mac[2]) << 24 & 0xff000000);
934 static int qlcnic_sriov_validate_create_tx_ctx(struct qlcnic_cmd_args *cmd)
936 if ((cmd->req.arg[0] >> 29) != 0x3)
942 static int qlcnic_sriov_pf_create_tx_ctx_cmd(struct qlcnic_bc_trans *trans,
943 struct qlcnic_cmd_args *cmd)
945 struct qlcnic_vf_info *vf = trans->vf;
946 struct qlcnic_adapter *adapter = vf->adapter;
947 struct qlcnic_tx_mbx_out *mbx_out;
950 err = qlcnic_sriov_validate_create_tx_ctx(cmd);
952 cmd->rsp.arg[0] |= (0x6 << 25);
956 cmd->req.arg[5] |= vf->vp->handle << 16;
957 err = qlcnic_issue_cmd(adapter, cmd);
959 mbx_out = (struct qlcnic_tx_mbx_out *)&cmd->rsp.arg[2];
960 vf->tx_ctx_id = mbx_out->ctx_id;
968 static int qlcnic_sriov_validate_del_rx_ctx(struct qlcnic_vf_info *vf,
969 struct qlcnic_cmd_args *cmd)
971 if ((cmd->req.arg[0] >> 29) != 0x3)
974 if ((cmd->req.arg[1] & 0xffff) != vf->rx_ctx_id)
980 static int qlcnic_sriov_pf_del_rx_ctx_cmd(struct qlcnic_bc_trans *trans,
981 struct qlcnic_cmd_args *cmd)
983 struct qlcnic_vf_info *vf = trans->vf;
984 struct qlcnic_adapter *adapter = vf->adapter;
987 err = qlcnic_sriov_validate_del_rx_ctx(vf, cmd);
989 cmd->rsp.arg[0] |= (0x6 << 25);
993 qlcnic_83xx_cfg_default_mac_vlan(adapter, vf, QLCNIC_MAC_DEL);
994 cmd->req.arg[1] |= vf->vp->handle << 16;
995 err = qlcnic_issue_cmd(adapter, cmd);
1003 static int qlcnic_sriov_validate_del_tx_ctx(struct qlcnic_vf_info *vf,
1004 struct qlcnic_cmd_args *cmd)
1006 if ((cmd->req.arg[0] >> 29) != 0x3)
1009 if ((cmd->req.arg[1] & 0xffff) != vf->tx_ctx_id)
1015 static int qlcnic_sriov_pf_del_tx_ctx_cmd(struct qlcnic_bc_trans *trans,
1016 struct qlcnic_cmd_args *cmd)
1018 struct qlcnic_vf_info *vf = trans->vf;
1019 struct qlcnic_adapter *adapter = vf->adapter;
1022 err = qlcnic_sriov_validate_del_tx_ctx(vf, cmd);
1024 cmd->rsp.arg[0] |= (0x6 << 25);
1028 cmd->req.arg[1] |= vf->vp->handle << 16;
1029 err = qlcnic_issue_cmd(adapter, cmd);
1037 static int qlcnic_sriov_validate_cfg_lro(struct qlcnic_vf_info *vf,
1038 struct qlcnic_cmd_args *cmd)
1040 if ((cmd->req.arg[1] >> 16) != vf->rx_ctx_id)
1046 static int qlcnic_sriov_pf_cfg_lro_cmd(struct qlcnic_bc_trans *trans,
1047 struct qlcnic_cmd_args *cmd)
1049 struct qlcnic_vf_info *vf = trans->vf;
1050 struct qlcnic_adapter *adapter = vf->adapter;
1053 err = qlcnic_sriov_validate_cfg_lro(vf, cmd);
1055 cmd->rsp.arg[0] |= (0x6 << 25);
1059 err = qlcnic_issue_cmd(adapter, cmd);
1063 static int qlcnic_sriov_pf_cfg_ip_cmd(struct qlcnic_bc_trans *trans,
1064 struct qlcnic_cmd_args *cmd)
1066 struct qlcnic_vf_info *vf = trans->vf;
1067 struct qlcnic_adapter *adapter = vf->adapter;
1071 op = cmd->req.arg[1] & 0xff;
1073 cmd->req.arg[1] |= vf->vp->handle << 16;
1074 cmd->req.arg[1] |= BIT_31;
1076 err = qlcnic_issue_cmd(adapter, cmd);
1080 static int qlcnic_sriov_validate_cfg_intrpt(struct qlcnic_vf_info *vf,
1081 struct qlcnic_cmd_args *cmd)
1083 if (((cmd->req.arg[1] >> 8) & 0xff) != vf->pci_func)
1086 if (!(cmd->req.arg[1] & BIT_16))
1089 if ((cmd->req.arg[1] & 0xff) != 0x1)
1095 static int qlcnic_sriov_pf_cfg_intrpt_cmd(struct qlcnic_bc_trans *trans,
1096 struct qlcnic_cmd_args *cmd)
1098 struct qlcnic_vf_info *vf = trans->vf;
1099 struct qlcnic_adapter *adapter = vf->adapter;
1102 err = qlcnic_sriov_validate_cfg_intrpt(vf, cmd);
1104 cmd->rsp.arg[0] |= (0x6 << 25);
1106 err = qlcnic_issue_cmd(adapter, cmd);
1111 static int qlcnic_sriov_validate_mtu(struct qlcnic_adapter *adapter,
1112 struct qlcnic_vf_info *vf,
1113 struct qlcnic_cmd_args *cmd)
1115 if (cmd->req.arg[1] != vf->rx_ctx_id)
1118 if (cmd->req.arg[2] > adapter->ahw->max_mtu)
1124 static int qlcnic_sriov_pf_set_mtu_cmd(struct qlcnic_bc_trans *trans,
1125 struct qlcnic_cmd_args *cmd)
1127 struct qlcnic_vf_info *vf = trans->vf;
1128 struct qlcnic_adapter *adapter = vf->adapter;
1131 err = qlcnic_sriov_validate_mtu(adapter, vf, cmd);
1133 cmd->rsp.arg[0] |= (0x6 << 25);
1135 err = qlcnic_issue_cmd(adapter, cmd);
1140 static int qlcnic_sriov_validate_get_nic_info(struct qlcnic_vf_info *vf,
1141 struct qlcnic_cmd_args *cmd)
1143 if (cmd->req.arg[1] & BIT_31) {
1144 if (((cmd->req.arg[1] >> 16) & 0x7fff) != vf->pci_func)
1147 cmd->req.arg[1] |= vf->vp->handle << 16;
1153 static int qlcnic_sriov_pf_get_nic_info_cmd(struct qlcnic_bc_trans *trans,
1154 struct qlcnic_cmd_args *cmd)
1156 struct qlcnic_vf_info *vf = trans->vf;
1157 struct qlcnic_adapter *adapter = vf->adapter;
1160 err = qlcnic_sriov_validate_get_nic_info(vf, cmd);
1162 cmd->rsp.arg[0] |= (0x6 << 25);
1166 err = qlcnic_issue_cmd(adapter, cmd);
1170 static int qlcnic_sriov_validate_cfg_rss(struct qlcnic_vf_info *vf,
1171 struct qlcnic_cmd_args *cmd)
1173 if (cmd->req.arg[1] != vf->rx_ctx_id)
1179 static int qlcnic_sriov_pf_cfg_rss_cmd(struct qlcnic_bc_trans *trans,
1180 struct qlcnic_cmd_args *cmd)
1182 struct qlcnic_vf_info *vf = trans->vf;
1183 struct qlcnic_adapter *adapter = vf->adapter;
1186 err = qlcnic_sriov_validate_cfg_rss(vf, cmd);
1188 cmd->rsp.arg[0] |= (0x6 << 25);
1190 err = qlcnic_issue_cmd(adapter, cmd);
1195 static int qlcnic_sriov_validate_cfg_intrcoal(struct qlcnic_adapter *adapter,
1196 struct qlcnic_vf_info *vf,
1197 struct qlcnic_cmd_args *cmd)
1199 struct qlcnic_nic_intr_coalesce *coal = &adapter->ahw->coal;
1200 u16 ctx_id, pkts, time;
1204 type = cmd->req.arg[1] & QLC_INTR_COAL_TYPE_MASK;
1205 ctx_id = cmd->req.arg[1] >> 16;
1206 pkts = cmd->req.arg[2] & 0xffff;
1207 time = cmd->req.arg[2] >> 16;
1210 case QLCNIC_INTR_COAL_TYPE_RX:
1211 if (ctx_id != vf->rx_ctx_id || pkts > coal->rx_packets ||
1212 time < coal->rx_time_us)
1215 case QLCNIC_INTR_COAL_TYPE_TX:
1216 if (ctx_id != vf->tx_ctx_id || pkts > coal->tx_packets ||
1217 time < coal->tx_time_us)
1221 netdev_err(adapter->netdev, "Invalid coalescing type 0x%x received\n",
1229 netdev_err(adapter->netdev, "Expected: rx_ctx_id 0x%x rx_packets 0x%x rx_time_us 0x%x tx_ctx_id 0x%x tx_packets 0x%x tx_time_us 0x%x\n",
1230 vf->rx_ctx_id, coal->rx_packets, coal->rx_time_us,
1231 vf->tx_ctx_id, coal->tx_packets, coal->tx_time_us);
1232 netdev_err(adapter->netdev, "Received: ctx_id 0x%x packets 0x%x time_us 0x%x type 0x%x\n",
1233 ctx_id, pkts, time, type);
1238 static int qlcnic_sriov_pf_cfg_intrcoal_cmd(struct qlcnic_bc_trans *tran,
1239 struct qlcnic_cmd_args *cmd)
1241 struct qlcnic_vf_info *vf = tran->vf;
1242 struct qlcnic_adapter *adapter = vf->adapter;
1245 err = qlcnic_sriov_validate_cfg_intrcoal(adapter, vf, cmd);
1247 cmd->rsp.arg[0] |= (0x6 << 25);
1251 err = qlcnic_issue_cmd(adapter, cmd);
1255 static int qlcnic_sriov_validate_cfg_macvlan(struct qlcnic_adapter *adapter,
1256 struct qlcnic_vf_info *vf,
1257 struct qlcnic_cmd_args *cmd)
1259 struct qlcnic_vport *vp = vf->vp;
1262 if (!(cmd->req.arg[1] & BIT_8))
1265 cmd->req.arg[1] |= (vf->vp->handle << 16);
1266 cmd->req.arg[1] |= BIT_31;
1268 if (vp->vlan_mode == QLC_PVID_MODE) {
1269 op = cmd->req.arg[1] & 0x7;
1270 cmd->req.arg[1] &= ~0x7;
1271 new_op = (op == QLCNIC_MAC_ADD || op == QLCNIC_MAC_VLAN_ADD) ?
1272 QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_VLAN_DEL;
1273 cmd->req.arg[3] |= vp->pvid << 16;
1274 cmd->req.arg[1] |= new_op;
1280 static int qlcnic_sriov_pf_cfg_macvlan_cmd(struct qlcnic_bc_trans *trans,
1281 struct qlcnic_cmd_args *cmd)
1283 struct qlcnic_vf_info *vf = trans->vf;
1284 struct qlcnic_adapter *adapter = vf->adapter;
1287 err = qlcnic_sriov_validate_cfg_macvlan(adapter, vf, cmd);
1289 cmd->rsp.arg[0] |= (0x6 << 25);
1293 err = qlcnic_issue_cmd(adapter, cmd);
1297 static int qlcnic_sriov_validate_linkevent(struct qlcnic_vf_info *vf,
1298 struct qlcnic_cmd_args *cmd)
1300 if ((cmd->req.arg[1] >> 16) != vf->rx_ctx_id)
1306 static int qlcnic_sriov_pf_linkevent_cmd(struct qlcnic_bc_trans *trans,
1307 struct qlcnic_cmd_args *cmd)
1309 struct qlcnic_vf_info *vf = trans->vf;
1310 struct qlcnic_adapter *adapter = vf->adapter;
1313 err = qlcnic_sriov_validate_linkevent(vf, cmd);
1315 cmd->rsp.arg[0] |= (0x6 << 25);
1319 err = qlcnic_issue_cmd(adapter, cmd);
1323 static int qlcnic_sriov_pf_cfg_promisc_cmd(struct qlcnic_bc_trans *trans,
1324 struct qlcnic_cmd_args *cmd)
1326 struct qlcnic_vf_info *vf = trans->vf;
1327 struct qlcnic_adapter *adapter = vf->adapter;
1330 cmd->req.arg[1] |= vf->vp->handle << 16;
1331 cmd->req.arg[1] |= BIT_31;
1332 err = qlcnic_issue_cmd(adapter, cmd);
1336 static int qlcnic_sriov_pf_get_acl_cmd(struct qlcnic_bc_trans *trans,
1337 struct qlcnic_cmd_args *cmd)
1339 struct qlcnic_vf_info *vf = trans->vf;
1340 struct qlcnic_vport *vp = vf->vp;
1341 u8 cmd_op, mode = vp->vlan_mode;
1342 struct qlcnic_adapter *adapter;
1343 struct qlcnic_sriov *sriov;
1345 adapter = vf->adapter;
1346 sriov = adapter->ahw->sriov;
1348 cmd_op = trans->req_hdr->cmd_op;
1349 cmd->rsp.arg[0] |= 1 << 25;
1351 /* For 84xx adapter in case of PVID , PFD should send vlan mode as
1352 * QLC_NO_VLAN_MODE to VFD which is zero in mailbox response
1354 if (qlcnic_84xx_check(adapter) && mode == QLC_PVID_MODE)
1358 case QLC_GUEST_VLAN_MODE:
1359 cmd->rsp.arg[1] = mode | 1 << 8;
1360 cmd->rsp.arg[2] = sriov->num_allowed_vlans << 16;
1363 cmd->rsp.arg[1] = mode | 1 << 8 | vp->pvid << 16;
1370 static int qlcnic_sriov_pf_del_guest_vlan(struct qlcnic_adapter *adapter,
1371 struct qlcnic_vf_info *vf,
1372 struct qlcnic_cmd_args *cmd)
1374 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
1377 if (!qlcnic_sriov_check_any_vlan(vf))
1380 vlan = cmd->req.arg[1] >> 16;
1381 if (!vf->rx_ctx_id) {
1382 qlcnic_sriov_del_vlan_id(sriov, vf, vlan);
1386 qlcnic_sriov_cfg_vf_def_mac(adapter, vf, vlan, QLCNIC_MAC_DEL);
1387 qlcnic_sriov_del_vlan_id(sriov, vf, vlan);
1389 if (qlcnic_83xx_pf_check(adapter))
1390 qlcnic_sriov_cfg_vf_def_mac(adapter, vf,
1395 static int qlcnic_sriov_pf_add_guest_vlan(struct qlcnic_adapter *adapter,
1396 struct qlcnic_vf_info *vf,
1397 struct qlcnic_cmd_args *cmd)
1399 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
1403 if (qlcnic_83xx_pf_check(adapter) && qlcnic_sriov_check_any_vlan(vf))
1406 vlan = cmd->req.arg[1] >> 16;
1408 if (!vf->rx_ctx_id) {
1409 qlcnic_sriov_add_vlan_id(sriov, vf, vlan);
1413 if (qlcnic_83xx_pf_check(adapter)) {
1414 err = qlcnic_sriov_cfg_vf_def_mac(adapter, vf, 0,
1420 err = qlcnic_sriov_cfg_vf_def_mac(adapter, vf, vlan, QLCNIC_MAC_ADD);
1423 if (qlcnic_83xx_pf_check(adapter))
1424 qlcnic_sriov_cfg_vf_def_mac(adapter, vf, 0,
1429 qlcnic_sriov_add_vlan_id(sriov, vf, vlan);
1433 static int qlcnic_sriov_pf_cfg_guest_vlan_cmd(struct qlcnic_bc_trans *tran,
1434 struct qlcnic_cmd_args *cmd)
1436 struct qlcnic_vf_info *vf = tran->vf;
1437 struct qlcnic_adapter *adapter = vf->adapter;
1438 struct qlcnic_vport *vp = vf->vp;
1442 if (vp->vlan_mode != QLC_GUEST_VLAN_MODE) {
1443 cmd->rsp.arg[0] |= 2 << 25;
1447 op = cmd->req.arg[1] & 0xf;
1450 err = qlcnic_sriov_pf_add_guest_vlan(adapter, vf, cmd);
1452 err = qlcnic_sriov_pf_del_guest_vlan(adapter, vf, cmd);
1454 cmd->rsp.arg[0] |= err ? 2 << 25 : 1 << 25;
1458 static const int qlcnic_pf_passthru_supp_cmds[] = {
1459 QLCNIC_CMD_GET_STATISTICS,
1460 QLCNIC_CMD_GET_PORT_CONFIG,
1461 QLCNIC_CMD_GET_LINK_STATUS,
1462 QLCNIC_CMD_INIT_NIC_FUNC,
1463 QLCNIC_CMD_STOP_NIC_FUNC,
1466 static const struct qlcnic_sriov_cmd_handler qlcnic_pf_bc_cmd_hdlr[] = {
1467 [QLCNIC_BC_CMD_CHANNEL_INIT] = {&qlcnic_sriov_pf_channel_cfg_cmd},
1468 [QLCNIC_BC_CMD_CHANNEL_TERM] = {&qlcnic_sriov_pf_channel_cfg_cmd},
1469 [QLCNIC_BC_CMD_GET_ACL] = {&qlcnic_sriov_pf_get_acl_cmd},
1470 [QLCNIC_BC_CMD_CFG_GUEST_VLAN] = {&qlcnic_sriov_pf_cfg_guest_vlan_cmd},
1473 static const struct qlcnic_sriov_fw_cmd_handler qlcnic_pf_fw_cmd_hdlr[] = {
1474 {QLCNIC_CMD_CREATE_RX_CTX, qlcnic_sriov_pf_create_rx_ctx_cmd},
1475 {QLCNIC_CMD_CREATE_TX_CTX, qlcnic_sriov_pf_create_tx_ctx_cmd},
1476 {QLCNIC_CMD_MAC_ADDRESS, qlcnic_sriov_pf_mac_address_cmd},
1477 {QLCNIC_CMD_DESTROY_RX_CTX, qlcnic_sriov_pf_del_rx_ctx_cmd},
1478 {QLCNIC_CMD_DESTROY_TX_CTX, qlcnic_sriov_pf_del_tx_ctx_cmd},
1479 {QLCNIC_CMD_CONFIGURE_HW_LRO, qlcnic_sriov_pf_cfg_lro_cmd},
1480 {QLCNIC_CMD_CONFIGURE_IP_ADDR, qlcnic_sriov_pf_cfg_ip_cmd},
1481 {QLCNIC_CMD_CONFIG_INTRPT, qlcnic_sriov_pf_cfg_intrpt_cmd},
1482 {QLCNIC_CMD_SET_MTU, qlcnic_sriov_pf_set_mtu_cmd},
1483 {QLCNIC_CMD_GET_NIC_INFO, qlcnic_sriov_pf_get_nic_info_cmd},
1484 {QLCNIC_CMD_CONFIGURE_RSS, qlcnic_sriov_pf_cfg_rss_cmd},
1485 {QLCNIC_CMD_CONFIG_INTR_COAL, qlcnic_sriov_pf_cfg_intrcoal_cmd},
1486 {QLCNIC_CMD_CONFIG_MAC_VLAN, qlcnic_sriov_pf_cfg_macvlan_cmd},
1487 {QLCNIC_CMD_GET_LINK_EVENT, qlcnic_sriov_pf_linkevent_cmd},
1488 {QLCNIC_CMD_CONFIGURE_MAC_RX_MODE, qlcnic_sriov_pf_cfg_promisc_cmd},
1491 void qlcnic_sriov_pf_process_bc_cmd(struct qlcnic_adapter *adapter,
1492 struct qlcnic_bc_trans *trans,
1493 struct qlcnic_cmd_args *cmd)
1497 cmd_op = trans->req_hdr->cmd_op;
1499 if (trans->req_hdr->op_type == QLC_BC_CMD) {
1500 size = ARRAY_SIZE(qlcnic_pf_bc_cmd_hdlr);
1501 if (cmd_op < size) {
1502 qlcnic_pf_bc_cmd_hdlr[cmd_op].fn(trans, cmd);
1507 size = ARRAY_SIZE(qlcnic_pf_fw_cmd_hdlr);
1508 for (i = 0; i < size; i++) {
1509 if (cmd_op == qlcnic_pf_fw_cmd_hdlr[i].cmd) {
1510 qlcnic_pf_fw_cmd_hdlr[i].fn(trans, cmd);
1515 size = ARRAY_SIZE(qlcnic_pf_passthru_supp_cmds);
1516 for (i = 0; i < size; i++) {
1517 if (cmd_op == qlcnic_pf_passthru_supp_cmds[i]) {
1518 qlcnic_issue_cmd(adapter, cmd);
1524 cmd->rsp.arg[0] |= (0x9 << 25);
1527 void qlcnic_pf_set_interface_id_create_rx_ctx(struct qlcnic_adapter *adapter,
1532 vpid = qlcnic_sriov_pf_get_vport_handle(adapter,
1533 adapter->ahw->pci_func);
1537 void qlcnic_pf_set_interface_id_del_rx_ctx(struct qlcnic_adapter *adapter,
1542 vpid = qlcnic_sriov_pf_get_vport_handle(adapter,
1543 adapter->ahw->pci_func);
1544 *int_id |= vpid << 16;
1547 void qlcnic_pf_set_interface_id_create_tx_ctx(struct qlcnic_adapter *adapter,
1552 vpid = qlcnic_sriov_pf_get_vport_handle(adapter,
1553 adapter->ahw->pci_func);
1554 *int_id |= vpid << 16;
1557 void qlcnic_pf_set_interface_id_del_tx_ctx(struct qlcnic_adapter *adapter,
1562 vpid = qlcnic_sriov_pf_get_vport_handle(adapter,
1563 adapter->ahw->pci_func);
1564 *int_id |= vpid << 16;
1567 void qlcnic_pf_set_interface_id_promisc(struct qlcnic_adapter *adapter,
1572 vpid = qlcnic_sriov_pf_get_vport_handle(adapter,
1573 adapter->ahw->pci_func);
1574 *int_id |= (vpid << 16) | BIT_31;
1577 void qlcnic_pf_set_interface_id_ipaddr(struct qlcnic_adapter *adapter,
1582 vpid = qlcnic_sriov_pf_get_vport_handle(adapter,
1583 adapter->ahw->pci_func);
1584 *int_id |= (vpid << 16) | BIT_31;
1587 void qlcnic_pf_set_interface_id_macaddr(struct qlcnic_adapter *adapter,
1592 vpid = qlcnic_sriov_pf_get_vport_handle(adapter,
1593 adapter->ahw->pci_func);
1594 *int_id |= (vpid << 16) | BIT_31;
1597 static void qlcnic_sriov_del_rx_ctx(struct qlcnic_adapter *adapter,
1598 struct qlcnic_vf_info *vf)
1600 struct qlcnic_cmd_args cmd;
1606 if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_DESTROY_RX_CTX))
1609 vpid = qlcnic_sriov_pf_get_vport_handle(adapter, vf->pci_func);
1611 cmd.req.arg[1] = vf->rx_ctx_id | (vpid & 0xffff) << 16;
1612 if (qlcnic_issue_cmd(adapter, &cmd))
1613 dev_err(&adapter->pdev->dev,
1614 "Failed to delete Tx ctx in firmware for func 0x%x\n",
1620 qlcnic_free_mbx_args(&cmd);
1623 static void qlcnic_sriov_del_tx_ctx(struct qlcnic_adapter *adapter,
1624 struct qlcnic_vf_info *vf)
1626 struct qlcnic_cmd_args cmd;
1632 if (qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_DESTROY_TX_CTX))
1635 vpid = qlcnic_sriov_pf_get_vport_handle(adapter, vf->pci_func);
1637 cmd.req.arg[1] |= vf->tx_ctx_id | (vpid & 0xffff) << 16;
1638 if (qlcnic_issue_cmd(adapter, &cmd))
1639 dev_err(&adapter->pdev->dev,
1640 "Failed to delete Tx ctx in firmware for func 0x%x\n",
1646 qlcnic_free_mbx_args(&cmd);
1649 static int qlcnic_sriov_add_act_list_irqsave(struct qlcnic_sriov *sriov,
1650 struct qlcnic_vf_info *vf,
1651 struct qlcnic_bc_trans *trans)
1653 struct qlcnic_trans_list *t_list = &vf->rcv_act;
1656 spin_lock_irqsave(&t_list->lock, flag);
1658 __qlcnic_sriov_add_act_list(sriov, vf, trans);
1660 spin_unlock_irqrestore(&t_list->lock, flag);
1664 static void __qlcnic_sriov_process_flr(struct qlcnic_vf_info *vf)
1666 struct qlcnic_adapter *adapter = vf->adapter;
1668 qlcnic_sriov_cleanup_list(&vf->rcv_pend);
1669 cancel_work_sync(&vf->trans_work);
1670 qlcnic_sriov_cleanup_list(&vf->rcv_act);
1672 if (test_bit(QLC_BC_VF_SOFT_FLR, &vf->state)) {
1673 qlcnic_sriov_del_tx_ctx(adapter, vf);
1674 qlcnic_sriov_del_rx_ctx(adapter, vf);
1677 qlcnic_sriov_pf_config_vport(adapter, 0, vf->pci_func);
1679 clear_bit(QLC_BC_VF_FLR, &vf->state);
1680 if (test_bit(QLC_BC_VF_SOFT_FLR, &vf->state)) {
1681 qlcnic_sriov_add_act_list_irqsave(adapter->ahw->sriov, vf,
1683 clear_bit(QLC_BC_VF_SOFT_FLR, &vf->state);
1684 vf->flr_trans = NULL;
1688 static void qlcnic_sriov_pf_process_flr(struct work_struct *work)
1690 struct qlcnic_vf_info *vf;
1692 vf = container_of(work, struct qlcnic_vf_info, flr_work);
1693 __qlcnic_sriov_process_flr(vf);
1697 static void qlcnic_sriov_schedule_flr(struct qlcnic_sriov *sriov,
1698 struct qlcnic_vf_info *vf,
1701 if (test_bit(__QLCNIC_RESETTING, &vf->adapter->state))
1704 INIT_WORK(&vf->flr_work, func);
1705 queue_work(sriov->bc.bc_flr_wq, &vf->flr_work);
1708 static void qlcnic_sriov_handle_soft_flr(struct qlcnic_adapter *adapter,
1709 struct qlcnic_bc_trans *trans,
1710 struct qlcnic_vf_info *vf)
1712 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
1714 set_bit(QLC_BC_VF_FLR, &vf->state);
1715 clear_bit(QLC_BC_VF_STATE, &vf->state);
1716 set_bit(QLC_BC_VF_SOFT_FLR, &vf->state);
1717 vf->flr_trans = trans;
1718 qlcnic_sriov_schedule_flr(sriov, vf, qlcnic_sriov_pf_process_flr);
1719 netdev_info(adapter->netdev, "Software FLR for PCI func %d\n",
1723 bool qlcnic_sriov_soft_flr_check(struct qlcnic_adapter *adapter,
1724 struct qlcnic_bc_trans *trans,
1725 struct qlcnic_vf_info *vf)
1727 struct qlcnic_bc_hdr *hdr = trans->req_hdr;
1729 if ((hdr->cmd_op == QLCNIC_BC_CMD_CHANNEL_INIT) &&
1730 (hdr->op_type == QLC_BC_CMD) &&
1731 test_bit(QLC_BC_VF_STATE, &vf->state)) {
1732 qlcnic_sriov_handle_soft_flr(adapter, trans, vf);
1739 void qlcnic_sriov_pf_handle_flr(struct qlcnic_sriov *sriov,
1740 struct qlcnic_vf_info *vf)
1742 struct net_device *dev = vf->adapter->netdev;
1743 struct qlcnic_vport *vp = vf->vp;
1745 if (!test_and_clear_bit(QLC_BC_VF_STATE, &vf->state)) {
1746 clear_bit(QLC_BC_VF_FLR, &vf->state);
1750 if (test_and_set_bit(QLC_BC_VF_FLR, &vf->state)) {
1751 netdev_info(dev, "FLR for PCI func %d in progress\n",
1756 if (vp->vlan_mode == QLC_GUEST_VLAN_MODE)
1757 memset(vf->sriov_vlans, 0,
1758 sizeof(*vf->sriov_vlans) * sriov->num_allowed_vlans);
1760 qlcnic_sriov_schedule_flr(sriov, vf, qlcnic_sriov_pf_process_flr);
1761 netdev_info(dev, "FLR received for PCI func %d\n", vf->pci_func);
1764 void qlcnic_sriov_pf_reset(struct qlcnic_adapter *adapter)
1766 struct qlcnic_hardware_context *ahw = adapter->ahw;
1767 struct qlcnic_sriov *sriov = ahw->sriov;
1768 struct qlcnic_vf_info *vf;
1769 u16 num_vfs = sriov->num_vfs;
1772 for (i = 0; i < num_vfs; i++) {
1773 vf = &sriov->vf_info[i];
1776 cancel_work_sync(&vf->flr_work);
1777 __qlcnic_sriov_process_flr(vf);
1778 clear_bit(QLC_BC_VF_STATE, &vf->state);
1781 qlcnic_sriov_pf_reset_vport_handle(adapter, ahw->pci_func);
1782 QLCWRX(ahw, QLCNIC_MBX_INTR_ENBL, (ahw->num_msix - 1) << 8);
1785 int qlcnic_sriov_pf_reinit(struct qlcnic_adapter *adapter)
1787 struct qlcnic_hardware_context *ahw = adapter->ahw;
1790 if (!qlcnic_sriov_enable_check(adapter))
1793 ahw->op_mode = QLCNIC_SRIOV_PF_FUNC;
1795 err = qlcnic_sriov_pf_init(adapter);
1799 dev_info(&adapter->pdev->dev, "%s: op_mode %d\n",
1800 __func__, ahw->op_mode);
1804 int qlcnic_sriov_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
1806 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1807 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
1809 struct qlcnic_vf_info *vf_info;
1812 if (!qlcnic_sriov_pf_check(adapter))
1815 num_vfs = sriov->num_vfs;
1817 if (!is_valid_ether_addr(mac) || vf >= num_vfs)
1820 if (ether_addr_equal(adapter->mac_addr, mac)) {
1821 netdev_err(netdev, "MAC address is already in use by the PF\n");
1825 for (i = 0; i < num_vfs; i++) {
1826 vf_info = &sriov->vf_info[i];
1827 if (ether_addr_equal(vf_info->vp->mac, mac)) {
1829 "MAC address is already in use by VF %d\n",
1835 vf_info = &sriov->vf_info[vf];
1836 curr_mac = vf_info->vp->mac;
1838 if (test_bit(QLC_BC_VF_STATE, &vf_info->state)) {
1840 "MAC address change failed for VF %d, as VF driver is loaded. Please unload VF driver and retry the operation\n",
1845 memcpy(curr_mac, mac, netdev->addr_len);
1846 netdev_info(netdev, "MAC Address %pM is configured for VF %d\n",
1851 int qlcnic_sriov_set_vf_tx_rate(struct net_device *netdev, int vf,
1852 int min_tx_rate, int max_tx_rate)
1854 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1855 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
1856 struct qlcnic_vf_info *vf_info;
1857 struct qlcnic_info nic_info;
1858 struct qlcnic_vport *vp;
1861 if (!qlcnic_sriov_pf_check(adapter))
1864 if (vf >= sriov->num_vfs)
1867 vf_info = &sriov->vf_info[vf];
1872 min_tx_rate = QLC_VF_MIN_TX_RATE;
1875 (max_tx_rate >= 10000 || max_tx_rate < min_tx_rate)) {
1877 "Invalid max Tx rate, allowed range is [%d - %d]",
1878 min_tx_rate, QLC_VF_MAX_TX_RATE);
1883 max_tx_rate = 10000;
1886 (min_tx_rate > max_tx_rate || min_tx_rate < QLC_VF_MIN_TX_RATE)) {
1888 "Invalid min Tx rate, allowed range is [%d - %d]",
1889 QLC_VF_MIN_TX_RATE, max_tx_rate);
1893 if (test_bit(QLC_BC_VF_STATE, &vf_info->state)) {
1894 if (qlcnic_sriov_get_vf_vport_info(adapter, &nic_info, vpid))
1897 nic_info.max_tx_bw = max_tx_rate / 100;
1898 nic_info.min_tx_bw = min_tx_rate / 100;
1899 nic_info.bit_offsets = BIT_0;
1901 if (qlcnic_sriov_pf_set_vport_info(adapter, &nic_info, vpid))
1905 vp->max_tx_bw = max_tx_rate / 100;
1907 "Setting Max Tx rate %d (Mbps), %d %% of PF bandwidth, for VF %d\n",
1908 max_tx_rate, vp->max_tx_bw, vf);
1909 vp->min_tx_bw = min_tx_rate / 100;
1911 "Setting Min Tx rate %d (Mbps), %d %% of PF bandwidth, for VF %d\n",
1912 min_tx_rate, vp->min_tx_bw, vf);
1916 int qlcnic_sriov_set_vf_vlan(struct net_device *netdev, int vf,
1919 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1920 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
1921 struct qlcnic_vf_info *vf_info;
1922 struct qlcnic_vport *vp;
1924 if (!qlcnic_sriov_pf_check(adapter))
1927 if (vf >= sriov->num_vfs || qos > 7)
1930 if (vlan > MAX_VLAN_ID) {
1932 "Invalid VLAN ID, allowed range is [0 - %d]\n",
1937 vf_info = &sriov->vf_info[vf];
1939 if (test_bit(QLC_BC_VF_STATE, &vf_info->state)) {
1941 "VLAN change failed for VF %d, as VF driver is loaded. Please unload VF driver and retry the operation\n",
1946 memset(vf_info->sriov_vlans, 0,
1947 sizeof(*vf_info->sriov_vlans) * sriov->num_allowed_vlans);
1951 vp->vlan_mode = QLC_GUEST_VLAN_MODE;
1954 vp->vlan_mode = QLC_NO_VLAN_MODE;
1958 vp->vlan_mode = QLC_PVID_MODE;
1959 qlcnic_sriov_add_vlan_id(sriov, vf_info, vlan);
1964 netdev_info(netdev, "Setting VLAN %d, QoS %d, for VF %d\n",
1969 static __u32 qlcnic_sriov_get_vf_vlan(struct qlcnic_adapter *adapter,
1970 struct qlcnic_vport *vp, int vf)
1974 switch (vp->vlan_mode) {
1978 case QLC_GUEST_VLAN_MODE:
1981 case QLC_NO_VLAN_MODE:
1985 netdev_info(adapter->netdev, "Invalid VLAN mode = %d for VF %d\n",
1992 int qlcnic_sriov_get_vf_config(struct net_device *netdev,
1993 int vf, struct ifla_vf_info *ivi)
1995 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1996 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
1997 struct qlcnic_vport *vp;
1999 if (!qlcnic_sriov_pf_check(adapter))
2002 if (vf >= sriov->num_vfs)
2005 vp = sriov->vf_info[vf].vp;
2006 memcpy(&ivi->mac, vp->mac, ETH_ALEN);
2007 ivi->vlan = qlcnic_sriov_get_vf_vlan(adapter, vp, vf);
2009 ivi->spoofchk = vp->spoofchk;
2010 if (vp->max_tx_bw == MAX_BW)
2011 ivi->max_tx_rate = 0;
2013 ivi->max_tx_rate = vp->max_tx_bw * 100;
2014 if (vp->min_tx_bw == MIN_BW)
2015 ivi->min_tx_rate = 0;
2017 ivi->min_tx_rate = vp->min_tx_bw * 100;
2023 int qlcnic_sriov_set_vf_spoofchk(struct net_device *netdev, int vf, bool chk)
2025 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2026 struct qlcnic_sriov *sriov = adapter->ahw->sriov;
2027 struct qlcnic_vf_info *vf_info;
2028 struct qlcnic_vport *vp;
2030 if (!qlcnic_sriov_pf_check(adapter))
2033 if (vf >= sriov->num_vfs)
2036 vf_info = &sriov->vf_info[vf];
2038 if (test_bit(QLC_BC_VF_STATE, &vf_info->state)) {
2040 "Spoof check change failed for VF %d, as VF driver is loaded. Please unload VF driver and retry the operation\n",