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