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