Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare network controllers and boards |
| 3 | * Copyright 2015 Solarflare Communications Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published |
| 7 | * by the Free Software Foundation, incorporated herein by reference. |
| 8 | */ |
| 9 | #include <linux/pci.h> |
| 10 | #include <linux/module.h> |
| 11 | #include "net_driver.h" |
| 12 | #include "ef10_sriov.h" |
| 13 | #include "efx.h" |
| 14 | #include "nic.h" |
| 15 | #include "mcdi_pcol.h" |
| 16 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 17 | static int efx_ef10_evb_port_assign(struct efx_nic *efx, unsigned int port_id, |
| 18 | unsigned int vf_fn) |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 19 | { |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 20 | MCDI_DECLARE_BUF(inbuf, MC_CMD_EVB_PORT_ASSIGN_IN_LEN); |
| 21 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 22 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 23 | MCDI_SET_DWORD(inbuf, EVB_PORT_ASSIGN_IN_PORT_ID, port_id); |
| 24 | MCDI_POPULATE_DWORD_2(inbuf, EVB_PORT_ASSIGN_IN_FUNCTION, |
| 25 | EVB_PORT_ASSIGN_IN_PF, nic_data->pf_index, |
| 26 | EVB_PORT_ASSIGN_IN_VF, vf_fn); |
| 27 | |
| 28 | return efx_mcdi_rpc(efx, MC_CMD_EVB_PORT_ASSIGN, inbuf, sizeof(inbuf), |
| 29 | NULL, 0, NULL); |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 30 | } |
| 31 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 32 | static int efx_ef10_vport_add_mac(struct efx_nic *efx, |
| 33 | unsigned int port_id, u8 *mac) |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 34 | { |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 35 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN); |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 36 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 37 | MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id); |
| 38 | ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac); |
| 39 | |
| 40 | return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf, |
| 41 | sizeof(inbuf), NULL, 0, NULL); |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 44 | static int efx_ef10_vport_del_mac(struct efx_nic *efx, |
| 45 | unsigned int port_id, u8 *mac) |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 46 | { |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 47 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN); |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 48 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 49 | MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id); |
| 50 | ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac); |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 51 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 52 | return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf, |
| 53 | sizeof(inbuf), NULL, 0, NULL); |
Shradha Shah | 02246a7 | 2015-05-06 00:58:14 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 56 | static int efx_ef10_vswitch_alloc(struct efx_nic *efx, unsigned int port_id, |
| 57 | unsigned int vswitch_type) |
| 58 | { |
| 59 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VSWITCH_ALLOC_IN_LEN); |
| 60 | |
| 61 | MCDI_SET_DWORD(inbuf, VSWITCH_ALLOC_IN_UPSTREAM_PORT_ID, port_id); |
| 62 | MCDI_SET_DWORD(inbuf, VSWITCH_ALLOC_IN_TYPE, vswitch_type); |
| 63 | MCDI_SET_DWORD(inbuf, VSWITCH_ALLOC_IN_NUM_VLAN_TAGS, 0); |
| 64 | MCDI_POPULATE_DWORD_1(inbuf, VSWITCH_ALLOC_IN_FLAGS, |
| 65 | VSWITCH_ALLOC_IN_FLAG_AUTO_PORT, 0); |
| 66 | |
| 67 | return efx_mcdi_rpc(efx, MC_CMD_VSWITCH_ALLOC, inbuf, sizeof(inbuf), |
| 68 | NULL, 0, NULL); |
| 69 | } |
| 70 | |
| 71 | static int efx_ef10_vswitch_free(struct efx_nic *efx, unsigned int port_id) |
| 72 | { |
| 73 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VSWITCH_FREE_IN_LEN); |
| 74 | |
| 75 | MCDI_SET_DWORD(inbuf, VSWITCH_FREE_IN_UPSTREAM_PORT_ID, port_id); |
| 76 | |
| 77 | return efx_mcdi_rpc(efx, MC_CMD_VSWITCH_FREE, inbuf, sizeof(inbuf), |
| 78 | NULL, 0, NULL); |
| 79 | } |
| 80 | |
| 81 | static int efx_ef10_vport_alloc(struct efx_nic *efx, |
| 82 | unsigned int port_id_in, |
| 83 | unsigned int vport_type, |
| 84 | unsigned int *port_id_out) |
| 85 | { |
| 86 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ALLOC_IN_LEN); |
| 87 | MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_ALLOC_OUT_LEN); |
| 88 | size_t outlen; |
| 89 | int rc; |
| 90 | |
| 91 | EFX_WARN_ON_PARANOID(!port_id_out); |
| 92 | |
| 93 | MCDI_SET_DWORD(inbuf, VPORT_ALLOC_IN_UPSTREAM_PORT_ID, port_id_in); |
| 94 | MCDI_SET_DWORD(inbuf, VPORT_ALLOC_IN_TYPE, vport_type); |
| 95 | MCDI_SET_DWORD(inbuf, VPORT_ALLOC_IN_NUM_VLAN_TAGS, 0); |
| 96 | MCDI_POPULATE_DWORD_1(inbuf, VPORT_ALLOC_IN_FLAGS, |
| 97 | VPORT_ALLOC_IN_FLAG_AUTO_PORT, 0); |
| 98 | |
| 99 | rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_ALLOC, inbuf, sizeof(inbuf), |
| 100 | outbuf, sizeof(outbuf), &outlen); |
| 101 | if (rc) |
| 102 | return rc; |
| 103 | if (outlen < MC_CMD_VPORT_ALLOC_OUT_LEN) |
| 104 | return -EIO; |
| 105 | |
| 106 | *port_id_out = MCDI_DWORD(outbuf, VPORT_ALLOC_OUT_VPORT_ID); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static int efx_ef10_vport_free(struct efx_nic *efx, unsigned int port_id) |
| 111 | { |
| 112 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_FREE_IN_LEN); |
| 113 | |
| 114 | MCDI_SET_DWORD(inbuf, VPORT_FREE_IN_VPORT_ID, port_id); |
| 115 | |
| 116 | return efx_mcdi_rpc(efx, MC_CMD_VPORT_FREE, inbuf, sizeof(inbuf), |
| 117 | NULL, 0, NULL); |
| 118 | } |
| 119 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 120 | static int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id) |
| 121 | { |
| 122 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN); |
| 123 | |
| 124 | MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id); |
| 125 | return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf), |
| 126 | NULL, 0, NULL); |
| 127 | } |
| 128 | |
| 129 | static int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id) |
| 130 | { |
| 131 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN); |
| 132 | |
| 133 | MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id); |
| 134 | return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf), |
| 135 | NULL, 0, NULL); |
| 136 | } |
| 137 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 138 | static void efx_ef10_sriov_free_vf_vports(struct efx_nic *efx) |
| 139 | { |
| 140 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 141 | int i; |
| 142 | |
| 143 | if (!nic_data->vf) |
| 144 | return; |
| 145 | |
| 146 | for (i = 0; i < efx->vf_count; i++) { |
| 147 | struct ef10_vf *vf = nic_data->vf + i; |
| 148 | |
| 149 | if (vf->vport_assigned) { |
| 150 | efx_ef10_evb_port_assign(efx, EVB_PORT_ID_NULL, i); |
| 151 | vf->vport_assigned = 0; |
| 152 | } |
| 153 | |
| 154 | if (!is_zero_ether_addr(vf->mac)) { |
| 155 | efx_ef10_vport_del_mac(efx, vf->vport_id, vf->mac); |
| 156 | eth_zero_addr(vf->mac); |
| 157 | } |
| 158 | |
| 159 | if (vf->vport_id) { |
| 160 | efx_ef10_vport_free(efx, vf->vport_id); |
| 161 | vf->vport_id = 0; |
| 162 | } |
Shradha Shah | f1122a3 | 2015-05-20 11:09:46 +0100 | [diff] [blame^] | 163 | |
| 164 | vf->efx = NULL; |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
| 168 | static void efx_ef10_sriov_free_vf_vswitching(struct efx_nic *efx) |
| 169 | { |
| 170 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 171 | |
| 172 | efx_ef10_sriov_free_vf_vports(efx); |
| 173 | kfree(nic_data->vf); |
| 174 | nic_data->vf = NULL; |
| 175 | } |
| 176 | |
| 177 | static int efx_ef10_sriov_assign_vf_vport(struct efx_nic *efx, |
| 178 | unsigned int vf_i) |
| 179 | { |
| 180 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 181 | struct ef10_vf *vf = nic_data->vf + vf_i; |
| 182 | int rc; |
| 183 | |
| 184 | if (WARN_ON_ONCE(!nic_data->vf)) |
| 185 | return -EOPNOTSUPP; |
| 186 | |
| 187 | rc = efx_ef10_vport_alloc(efx, EVB_PORT_ID_ASSIGNED, |
| 188 | MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL, |
| 189 | &vf->vport_id); |
| 190 | if (rc) |
| 191 | return rc; |
| 192 | |
| 193 | rc = efx_ef10_vport_add_mac(efx, vf->vport_id, vf->mac); |
| 194 | if (rc) { |
| 195 | eth_zero_addr(vf->mac); |
| 196 | return rc; |
| 197 | } |
| 198 | |
| 199 | rc = efx_ef10_evb_port_assign(efx, vf->vport_id, vf_i); |
| 200 | if (rc) |
| 201 | return rc; |
| 202 | |
| 203 | vf->vport_assigned = 1; |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | static int efx_ef10_sriov_alloc_vf_vswitching(struct efx_nic *efx) |
| 208 | { |
| 209 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 210 | unsigned int i; |
| 211 | int rc; |
| 212 | |
| 213 | nic_data->vf = kcalloc(efx->vf_count, sizeof(struct ef10_vf), |
| 214 | GFP_KERNEL); |
| 215 | if (!nic_data->vf) |
| 216 | return -ENOMEM; |
| 217 | |
| 218 | for (i = 0; i < efx->vf_count; i++) { |
| 219 | random_ether_addr(nic_data->vf[i].mac); |
Shradha Shah | f1122a3 | 2015-05-20 11:09:46 +0100 | [diff] [blame^] | 220 | nic_data->vf[i].efx = NULL; |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 221 | |
| 222 | rc = efx_ef10_sriov_assign_vf_vport(efx, i); |
| 223 | if (rc) |
| 224 | goto fail; |
| 225 | } |
| 226 | |
| 227 | return 0; |
| 228 | fail: |
| 229 | efx_ef10_sriov_free_vf_vports(efx); |
| 230 | kfree(nic_data->vf); |
| 231 | nic_data->vf = NULL; |
| 232 | return rc; |
| 233 | } |
| 234 | |
| 235 | static int efx_ef10_sriov_restore_vf_vswitching(struct efx_nic *efx) |
| 236 | { |
| 237 | unsigned int i; |
| 238 | int rc; |
| 239 | |
| 240 | for (i = 0; i < efx->vf_count; i++) { |
| 241 | rc = efx_ef10_sriov_assign_vf_vport(efx, i); |
| 242 | if (rc) |
| 243 | goto fail; |
| 244 | } |
| 245 | |
| 246 | return 0; |
| 247 | fail: |
| 248 | efx_ef10_sriov_free_vf_vswitching(efx); |
| 249 | return rc; |
| 250 | } |
| 251 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 252 | /* On top of the default firmware vswitch setup, create a VEB vswitch and |
| 253 | * expansion vport for use by this function. |
| 254 | */ |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 255 | int efx_ef10_vswitching_probe_pf(struct efx_nic *efx) |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 256 | { |
| 257 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 258 | struct net_device *net_dev = efx->net_dev; |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 259 | int rc; |
| 260 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 261 | if (pci_sriov_get_totalvfs(efx->pci_dev) <= 0) { |
| 262 | /* vswitch not needed as we have no VFs */ |
| 263 | efx_ef10_vadaptor_alloc(efx, nic_data->vport_id); |
| 264 | return 0; |
| 265 | } |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 266 | |
| 267 | rc = efx_ef10_vswitch_alloc(efx, EVB_PORT_ID_ASSIGNED, |
| 268 | MC_CMD_VSWITCH_ALLOC_IN_VSWITCH_TYPE_VEB); |
| 269 | if (rc) |
| 270 | goto fail1; |
| 271 | |
| 272 | rc = efx_ef10_vport_alloc(efx, EVB_PORT_ID_ASSIGNED, |
| 273 | MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL, |
| 274 | &nic_data->vport_id); |
| 275 | if (rc) |
| 276 | goto fail2; |
| 277 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 278 | rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id, net_dev->dev_addr); |
| 279 | if (rc) |
| 280 | goto fail3; |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 281 | ether_addr_copy(nic_data->vport_mac, net_dev->dev_addr); |
| 282 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 283 | rc = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id); |
| 284 | if (rc) |
| 285 | goto fail4; |
| 286 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 287 | return 0; |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 288 | fail4: |
| 289 | efx_ef10_vport_del_mac(efx, nic_data->vport_id, nic_data->vport_mac); |
| 290 | eth_zero_addr(nic_data->vport_mac); |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 291 | fail3: |
| 292 | efx_ef10_vport_free(efx, nic_data->vport_id); |
| 293 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 294 | fail2: |
| 295 | efx_ef10_vswitch_free(efx, EVB_PORT_ID_ASSIGNED); |
| 296 | fail1: |
| 297 | return rc; |
| 298 | } |
| 299 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 300 | int efx_ef10_vswitching_probe_vf(struct efx_nic *efx) |
| 301 | { |
| 302 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 303 | |
| 304 | return efx_ef10_vadaptor_alloc(efx, nic_data->vport_id); |
| 305 | } |
| 306 | |
| 307 | int efx_ef10_vswitching_restore_pf(struct efx_nic *efx) |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 308 | { |
| 309 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 310 | int rc; |
| 311 | |
| 312 | if (!nic_data->must_probe_vswitching) |
| 313 | return 0; |
| 314 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 315 | rc = efx_ef10_vswitching_probe_pf(efx); |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 316 | if (rc) |
| 317 | goto fail; |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 318 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 319 | rc = efx_ef10_sriov_restore_vf_vswitching(efx); |
| 320 | if (rc) |
| 321 | goto fail; |
| 322 | |
| 323 | nic_data->must_probe_vswitching = false; |
| 324 | fail: |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 325 | return rc; |
| 326 | } |
| 327 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 328 | int efx_ef10_vswitching_restore_vf(struct efx_nic *efx) |
| 329 | { |
| 330 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 331 | int rc; |
| 332 | |
| 333 | if (!nic_data->must_probe_vswitching) |
| 334 | return 0; |
| 335 | |
| 336 | rc = efx_ef10_vadaptor_free(efx, EVB_PORT_ID_ASSIGNED); |
| 337 | if (rc) |
| 338 | return rc; |
| 339 | |
| 340 | nic_data->must_probe_vswitching = false; |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | void efx_ef10_vswitching_remove_pf(struct efx_nic *efx) |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 345 | { |
| 346 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 347 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 348 | efx_ef10_sriov_free_vf_vswitching(efx); |
| 349 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 350 | efx_ef10_vadaptor_free(efx, nic_data->vport_id); |
| 351 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 352 | if (nic_data->vport_id == EVB_PORT_ID_ASSIGNED) |
| 353 | return; /* No vswitch was ever created */ |
| 354 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 355 | if (!is_zero_ether_addr(nic_data->vport_mac)) { |
| 356 | efx_ef10_vport_del_mac(efx, nic_data->vport_id, |
| 357 | efx->net_dev->dev_addr); |
| 358 | eth_zero_addr(nic_data->vport_mac); |
| 359 | } |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 360 | efx_ef10_vport_free(efx, nic_data->vport_id); |
| 361 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
| 362 | |
| 363 | efx_ef10_vswitch_free(efx, nic_data->vport_id); |
| 364 | } |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 365 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 366 | void efx_ef10_vswitching_remove_vf(struct efx_nic *efx) |
| 367 | { |
| 368 | efx_ef10_vadaptor_free(efx, EVB_PORT_ID_ASSIGNED); |
| 369 | } |
| 370 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 371 | static int efx_ef10_pci_sriov_enable(struct efx_nic *efx, int num_vfs) |
| 372 | { |
| 373 | int rc = 0; |
| 374 | struct pci_dev *dev = efx->pci_dev; |
| 375 | |
| 376 | efx->vf_count = num_vfs; |
| 377 | |
| 378 | rc = efx_ef10_sriov_alloc_vf_vswitching(efx); |
| 379 | if (rc) |
| 380 | goto fail1; |
| 381 | |
| 382 | rc = pci_enable_sriov(dev, num_vfs); |
| 383 | if (rc) |
| 384 | goto fail2; |
| 385 | |
| 386 | return 0; |
| 387 | fail2: |
| 388 | efx_ef10_sriov_free_vf_vswitching(efx); |
| 389 | fail1: |
| 390 | efx->vf_count = 0; |
| 391 | netif_err(efx, probe, efx->net_dev, |
| 392 | "Failed to enable SRIOV VFs\n"); |
| 393 | return rc; |
| 394 | } |
| 395 | |
| 396 | static int efx_ef10_pci_sriov_disable(struct efx_nic *efx) |
| 397 | { |
| 398 | struct pci_dev *dev = efx->pci_dev; |
| 399 | |
| 400 | pci_disable_sriov(dev); |
| 401 | efx_ef10_sriov_free_vf_vswitching(efx); |
| 402 | efx->vf_count = 0; |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | int efx_ef10_sriov_configure(struct efx_nic *efx, int num_vfs) |
| 407 | { |
| 408 | if (num_vfs == 0) |
| 409 | return efx_ef10_pci_sriov_disable(efx); |
| 410 | else |
| 411 | return efx_ef10_pci_sriov_enable(efx, num_vfs); |
| 412 | } |
| 413 | |
| 414 | int efx_ef10_sriov_init(struct efx_nic *efx) |
| 415 | { |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | void efx_ef10_sriov_fini(struct efx_nic *efx) |
| 420 | { |
| 421 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 422 | int rc; |
| 423 | |
| 424 | if (!nic_data->vf) |
| 425 | return; |
| 426 | |
| 427 | rc = efx_ef10_pci_sriov_disable(efx); |
| 428 | if (rc) |
| 429 | netif_dbg(efx, drv, efx->net_dev, |
| 430 | "Disabling SRIOV was not successful rc=%d\n", rc); |
| 431 | else |
| 432 | netif_dbg(efx, drv, efx->net_dev, "SRIOV disabled\n"); |
| 433 | } |