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 | */ |
Shyam Saini | 4b5b1ac | 2017-01-16 09:26:21 +0530 | [diff] [blame] | 9 | #include <linux/etherdevice.h> |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 10 | #include <linux/pci.h> |
| 11 | #include <linux/module.h> |
| 12 | #include "net_driver.h" |
| 13 | #include "ef10_sriov.h" |
| 14 | #include "efx.h" |
| 15 | #include "nic.h" |
| 16 | #include "mcdi_pcol.h" |
| 17 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 18 | static int efx_ef10_evb_port_assign(struct efx_nic *efx, unsigned int port_id, |
| 19 | unsigned int vf_fn) |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 20 | { |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 21 | MCDI_DECLARE_BUF(inbuf, MC_CMD_EVB_PORT_ASSIGN_IN_LEN); |
| 22 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 23 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 24 | MCDI_SET_DWORD(inbuf, EVB_PORT_ASSIGN_IN_PORT_ID, port_id); |
| 25 | MCDI_POPULATE_DWORD_2(inbuf, EVB_PORT_ASSIGN_IN_FUNCTION, |
| 26 | EVB_PORT_ASSIGN_IN_PF, nic_data->pf_index, |
| 27 | EVB_PORT_ASSIGN_IN_VF, vf_fn); |
| 28 | |
| 29 | return efx_mcdi_rpc(efx, MC_CMD_EVB_PORT_ASSIGN, inbuf, sizeof(inbuf), |
| 30 | NULL, 0, NULL); |
Shradha Shah | 834e23d | 2015-05-06 00:55:58 +0100 | [diff] [blame] | 31 | } |
| 32 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 33 | static int efx_ef10_vswitch_alloc(struct efx_nic *efx, unsigned int port_id, |
| 34 | unsigned int vswitch_type) |
| 35 | { |
| 36 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VSWITCH_ALLOC_IN_LEN); |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 37 | int rc; |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 38 | |
| 39 | MCDI_SET_DWORD(inbuf, VSWITCH_ALLOC_IN_UPSTREAM_PORT_ID, port_id); |
| 40 | MCDI_SET_DWORD(inbuf, VSWITCH_ALLOC_IN_TYPE, vswitch_type); |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 41 | MCDI_SET_DWORD(inbuf, VSWITCH_ALLOC_IN_NUM_VLAN_TAGS, 2); |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 42 | MCDI_POPULATE_DWORD_1(inbuf, VSWITCH_ALLOC_IN_FLAGS, |
| 43 | VSWITCH_ALLOC_IN_FLAG_AUTO_PORT, 0); |
| 44 | |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 45 | /* Quietly try to allocate 2 VLAN tags */ |
| 46 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VSWITCH_ALLOC, inbuf, sizeof(inbuf), |
| 47 | NULL, 0, NULL); |
| 48 | |
| 49 | /* If 2 VLAN tags is too many, revert to trying with 1 VLAN tags */ |
| 50 | if (rc == -EPROTO) { |
| 51 | MCDI_SET_DWORD(inbuf, VSWITCH_ALLOC_IN_NUM_VLAN_TAGS, 1); |
| 52 | rc = efx_mcdi_rpc(efx, MC_CMD_VSWITCH_ALLOC, inbuf, |
| 53 | sizeof(inbuf), NULL, 0, NULL); |
| 54 | } else if (rc) { |
| 55 | efx_mcdi_display_error(efx, MC_CMD_VSWITCH_ALLOC, |
| 56 | MC_CMD_VSWITCH_ALLOC_IN_LEN, |
| 57 | NULL, 0, rc); |
| 58 | } |
| 59 | return rc; |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static int efx_ef10_vswitch_free(struct efx_nic *efx, unsigned int port_id) |
| 63 | { |
| 64 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VSWITCH_FREE_IN_LEN); |
| 65 | |
| 66 | MCDI_SET_DWORD(inbuf, VSWITCH_FREE_IN_UPSTREAM_PORT_ID, port_id); |
| 67 | |
| 68 | return efx_mcdi_rpc(efx, MC_CMD_VSWITCH_FREE, inbuf, sizeof(inbuf), |
| 69 | NULL, 0, NULL); |
| 70 | } |
| 71 | |
| 72 | static int efx_ef10_vport_alloc(struct efx_nic *efx, |
| 73 | unsigned int port_id_in, |
| 74 | unsigned int vport_type, |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 75 | u16 vlan, |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 76 | unsigned int *port_id_out) |
| 77 | { |
| 78 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ALLOC_IN_LEN); |
| 79 | MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_ALLOC_OUT_LEN); |
| 80 | size_t outlen; |
| 81 | int rc; |
| 82 | |
| 83 | EFX_WARN_ON_PARANOID(!port_id_out); |
| 84 | |
| 85 | MCDI_SET_DWORD(inbuf, VPORT_ALLOC_IN_UPSTREAM_PORT_ID, port_id_in); |
| 86 | MCDI_SET_DWORD(inbuf, VPORT_ALLOC_IN_TYPE, vport_type); |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 87 | MCDI_SET_DWORD(inbuf, VPORT_ALLOC_IN_NUM_VLAN_TAGS, |
| 88 | (vlan != EFX_EF10_NO_VLAN)); |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 89 | MCDI_POPULATE_DWORD_1(inbuf, VPORT_ALLOC_IN_FLAGS, |
| 90 | VPORT_ALLOC_IN_FLAG_AUTO_PORT, 0); |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 91 | if (vlan != EFX_EF10_NO_VLAN) |
| 92 | MCDI_POPULATE_DWORD_1(inbuf, VPORT_ALLOC_IN_VLAN_TAGS, |
| 93 | VPORT_ALLOC_IN_VLAN_TAG_0, vlan); |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 94 | |
| 95 | rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_ALLOC, inbuf, sizeof(inbuf), |
| 96 | outbuf, sizeof(outbuf), &outlen); |
| 97 | if (rc) |
| 98 | return rc; |
| 99 | if (outlen < MC_CMD_VPORT_ALLOC_OUT_LEN) |
| 100 | return -EIO; |
| 101 | |
| 102 | *port_id_out = MCDI_DWORD(outbuf, VPORT_ALLOC_OUT_VPORT_ID); |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static int efx_ef10_vport_free(struct efx_nic *efx, unsigned int port_id) |
| 107 | { |
| 108 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_FREE_IN_LEN); |
| 109 | |
| 110 | MCDI_SET_DWORD(inbuf, VPORT_FREE_IN_VPORT_ID, port_id); |
| 111 | |
| 112 | return efx_mcdi_rpc(efx, MC_CMD_VPORT_FREE, inbuf, sizeof(inbuf), |
| 113 | NULL, 0, NULL); |
| 114 | } |
| 115 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 116 | static void efx_ef10_sriov_free_vf_vports(struct efx_nic *efx) |
| 117 | { |
| 118 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 119 | int i; |
| 120 | |
| 121 | if (!nic_data->vf) |
| 122 | return; |
| 123 | |
| 124 | for (i = 0; i < efx->vf_count; i++) { |
| 125 | struct ef10_vf *vf = nic_data->vf + i; |
| 126 | |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 127 | /* If VF is assigned, do not free the vport */ |
| 128 | if (vf->pci_dev && |
| 129 | vf->pci_dev->dev_flags & PCI_DEV_FLAGS_ASSIGNED) |
| 130 | continue; |
| 131 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 132 | if (vf->vport_assigned) { |
| 133 | efx_ef10_evb_port_assign(efx, EVB_PORT_ID_NULL, i); |
| 134 | vf->vport_assigned = 0; |
| 135 | } |
| 136 | |
| 137 | if (!is_zero_ether_addr(vf->mac)) { |
| 138 | efx_ef10_vport_del_mac(efx, vf->vport_id, vf->mac); |
| 139 | eth_zero_addr(vf->mac); |
| 140 | } |
| 141 | |
| 142 | if (vf->vport_id) { |
| 143 | efx_ef10_vport_free(efx, vf->vport_id); |
| 144 | vf->vport_id = 0; |
| 145 | } |
Shradha Shah | f1122a3 | 2015-05-20 11:09:46 +0100 | [diff] [blame] | 146 | |
| 147 | vf->efx = NULL; |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
| 151 | static void efx_ef10_sriov_free_vf_vswitching(struct efx_nic *efx) |
| 152 | { |
| 153 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 154 | |
| 155 | efx_ef10_sriov_free_vf_vports(efx); |
| 156 | kfree(nic_data->vf); |
| 157 | nic_data->vf = NULL; |
| 158 | } |
| 159 | |
| 160 | static int efx_ef10_sriov_assign_vf_vport(struct efx_nic *efx, |
| 161 | unsigned int vf_i) |
| 162 | { |
| 163 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 164 | struct ef10_vf *vf = nic_data->vf + vf_i; |
| 165 | int rc; |
| 166 | |
| 167 | if (WARN_ON_ONCE(!nic_data->vf)) |
| 168 | return -EOPNOTSUPP; |
| 169 | |
| 170 | rc = efx_ef10_vport_alloc(efx, EVB_PORT_ID_ASSIGNED, |
| 171 | MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL, |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 172 | vf->vlan, &vf->vport_id); |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 173 | if (rc) |
| 174 | return rc; |
| 175 | |
| 176 | rc = efx_ef10_vport_add_mac(efx, vf->vport_id, vf->mac); |
| 177 | if (rc) { |
| 178 | eth_zero_addr(vf->mac); |
| 179 | return rc; |
| 180 | } |
| 181 | |
| 182 | rc = efx_ef10_evb_port_assign(efx, vf->vport_id, vf_i); |
| 183 | if (rc) |
| 184 | return rc; |
| 185 | |
| 186 | vf->vport_assigned = 1; |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | static int efx_ef10_sriov_alloc_vf_vswitching(struct efx_nic *efx) |
| 191 | { |
| 192 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 193 | unsigned int i; |
| 194 | int rc; |
| 195 | |
| 196 | nic_data->vf = kcalloc(efx->vf_count, sizeof(struct ef10_vf), |
| 197 | GFP_KERNEL); |
| 198 | if (!nic_data->vf) |
| 199 | return -ENOMEM; |
| 200 | |
| 201 | for (i = 0; i < efx->vf_count; i++) { |
| 202 | random_ether_addr(nic_data->vf[i].mac); |
Shradha Shah | f1122a3 | 2015-05-20 11:09:46 +0100 | [diff] [blame] | 203 | nic_data->vf[i].efx = NULL; |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 204 | nic_data->vf[i].vlan = EFX_EF10_NO_VLAN; |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 205 | |
| 206 | rc = efx_ef10_sriov_assign_vf_vport(efx, i); |
| 207 | if (rc) |
| 208 | goto fail; |
| 209 | } |
| 210 | |
| 211 | return 0; |
| 212 | fail: |
| 213 | efx_ef10_sriov_free_vf_vports(efx); |
| 214 | kfree(nic_data->vf); |
| 215 | nic_data->vf = NULL; |
| 216 | return rc; |
| 217 | } |
| 218 | |
| 219 | static int efx_ef10_sriov_restore_vf_vswitching(struct efx_nic *efx) |
| 220 | { |
| 221 | unsigned int i; |
| 222 | int rc; |
| 223 | |
| 224 | for (i = 0; i < efx->vf_count; i++) { |
| 225 | rc = efx_ef10_sriov_assign_vf_vport(efx, i); |
| 226 | if (rc) |
| 227 | goto fail; |
| 228 | } |
| 229 | |
| 230 | return 0; |
| 231 | fail: |
| 232 | efx_ef10_sriov_free_vf_vswitching(efx); |
| 233 | return rc; |
| 234 | } |
| 235 | |
Andrew Rybchenko | 38d27f3 | 2016-06-15 17:52:08 +0100 | [diff] [blame] | 236 | static int efx_ef10_vadaptor_alloc_set_features(struct efx_nic *efx) |
| 237 | { |
| 238 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 239 | u32 port_flags; |
| 240 | int rc; |
| 241 | |
| 242 | rc = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id); |
| 243 | if (rc) |
| 244 | goto fail_vadaptor_alloc; |
| 245 | |
| 246 | rc = efx_ef10_vadaptor_query(efx, nic_data->vport_id, |
| 247 | &port_flags, NULL, NULL); |
| 248 | if (rc) |
| 249 | goto fail_vadaptor_query; |
| 250 | |
| 251 | if (port_flags & |
| 252 | (1 << MC_CMD_VPORT_ALLOC_IN_FLAG_VLAN_RESTRICT_LBN)) |
| 253 | efx->fixed_features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
| 254 | else |
| 255 | efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
| 256 | |
| 257 | return 0; |
| 258 | |
| 259 | fail_vadaptor_query: |
| 260 | efx_ef10_vadaptor_free(efx, EVB_PORT_ID_ASSIGNED); |
| 261 | fail_vadaptor_alloc: |
| 262 | return rc; |
| 263 | } |
| 264 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 265 | /* On top of the default firmware vswitch setup, create a VEB vswitch and |
| 266 | * expansion vport for use by this function. |
| 267 | */ |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 268 | int efx_ef10_vswitching_probe_pf(struct efx_nic *efx) |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 269 | { |
| 270 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 271 | struct net_device *net_dev = efx->net_dev; |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 272 | int rc; |
| 273 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 274 | if (pci_sriov_get_totalvfs(efx->pci_dev) <= 0) { |
| 275 | /* vswitch not needed as we have no VFs */ |
Andrew Rybchenko | 38d27f3 | 2016-06-15 17:52:08 +0100 | [diff] [blame] | 276 | efx_ef10_vadaptor_alloc_set_features(efx); |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 277 | return 0; |
| 278 | } |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 279 | |
| 280 | rc = efx_ef10_vswitch_alloc(efx, EVB_PORT_ID_ASSIGNED, |
| 281 | MC_CMD_VSWITCH_ALLOC_IN_VSWITCH_TYPE_VEB); |
| 282 | if (rc) |
| 283 | goto fail1; |
| 284 | |
| 285 | rc = efx_ef10_vport_alloc(efx, EVB_PORT_ID_ASSIGNED, |
| 286 | MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL, |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 287 | EFX_EF10_NO_VLAN, &nic_data->vport_id); |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 288 | if (rc) |
| 289 | goto fail2; |
| 290 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 291 | rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id, net_dev->dev_addr); |
| 292 | if (rc) |
| 293 | goto fail3; |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 294 | ether_addr_copy(nic_data->vport_mac, net_dev->dev_addr); |
| 295 | |
Andrew Rybchenko | 38d27f3 | 2016-06-15 17:52:08 +0100 | [diff] [blame] | 296 | rc = efx_ef10_vadaptor_alloc_set_features(efx); |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 297 | if (rc) |
| 298 | goto fail4; |
| 299 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 300 | return 0; |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 301 | fail4: |
| 302 | efx_ef10_vport_del_mac(efx, nic_data->vport_id, nic_data->vport_mac); |
| 303 | eth_zero_addr(nic_data->vport_mac); |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 304 | fail3: |
| 305 | efx_ef10_vport_free(efx, nic_data->vport_id); |
| 306 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 307 | fail2: |
| 308 | efx_ef10_vswitch_free(efx, EVB_PORT_ID_ASSIGNED); |
| 309 | fail1: |
| 310 | return rc; |
| 311 | } |
| 312 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 313 | int efx_ef10_vswitching_probe_vf(struct efx_nic *efx) |
| 314 | { |
Andrew Rybchenko | 38d27f3 | 2016-06-15 17:52:08 +0100 | [diff] [blame] | 315 | return efx_ef10_vadaptor_alloc_set_features(efx); |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | int efx_ef10_vswitching_restore_pf(struct efx_nic *efx) |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 319 | { |
| 320 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 321 | int rc; |
| 322 | |
| 323 | if (!nic_data->must_probe_vswitching) |
| 324 | return 0; |
| 325 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 326 | rc = efx_ef10_vswitching_probe_pf(efx); |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 327 | if (rc) |
| 328 | goto fail; |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 329 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 330 | rc = efx_ef10_sriov_restore_vf_vswitching(efx); |
| 331 | if (rc) |
| 332 | goto fail; |
| 333 | |
| 334 | nic_data->must_probe_vswitching = false; |
| 335 | fail: |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 336 | return rc; |
| 337 | } |
| 338 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 339 | int efx_ef10_vswitching_restore_vf(struct efx_nic *efx) |
| 340 | { |
| 341 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 342 | int rc; |
| 343 | |
| 344 | if (!nic_data->must_probe_vswitching) |
| 345 | return 0; |
| 346 | |
| 347 | rc = efx_ef10_vadaptor_free(efx, EVB_PORT_ID_ASSIGNED); |
| 348 | if (rc) |
| 349 | return rc; |
| 350 | |
| 351 | nic_data->must_probe_vswitching = false; |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | void efx_ef10_vswitching_remove_pf(struct efx_nic *efx) |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 356 | { |
| 357 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 358 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 359 | efx_ef10_sriov_free_vf_vswitching(efx); |
| 360 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 361 | efx_ef10_vadaptor_free(efx, nic_data->vport_id); |
| 362 | |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 363 | if (nic_data->vport_id == EVB_PORT_ID_ASSIGNED) |
| 364 | return; /* No vswitch was ever created */ |
| 365 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 366 | if (!is_zero_ether_addr(nic_data->vport_mac)) { |
| 367 | efx_ef10_vport_del_mac(efx, nic_data->vport_id, |
| 368 | efx->net_dev->dev_addr); |
| 369 | eth_zero_addr(nic_data->vport_mac); |
| 370 | } |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 371 | efx_ef10_vport_free(efx, nic_data->vport_id); |
| 372 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
| 373 | |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 374 | /* Only free the vswitch if no VFs are assigned */ |
| 375 | if (!pci_vfs_assigned(efx->pci_dev)) |
| 376 | efx_ef10_vswitch_free(efx, nic_data->vport_id); |
Daniel Pieczko | 6d8aaaf | 2015-05-06 00:57:34 +0100 | [diff] [blame] | 377 | } |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 378 | |
Shradha Shah | 7b8c7b5 | 2015-05-06 00:58:54 +0100 | [diff] [blame] | 379 | void efx_ef10_vswitching_remove_vf(struct efx_nic *efx) |
| 380 | { |
| 381 | efx_ef10_vadaptor_free(efx, EVB_PORT_ID_ASSIGNED); |
| 382 | } |
| 383 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 384 | static int efx_ef10_pci_sriov_enable(struct efx_nic *efx, int num_vfs) |
| 385 | { |
| 386 | int rc = 0; |
| 387 | struct pci_dev *dev = efx->pci_dev; |
| 388 | |
| 389 | efx->vf_count = num_vfs; |
| 390 | |
| 391 | rc = efx_ef10_sriov_alloc_vf_vswitching(efx); |
| 392 | if (rc) |
| 393 | goto fail1; |
| 394 | |
| 395 | rc = pci_enable_sriov(dev, num_vfs); |
| 396 | if (rc) |
| 397 | goto fail2; |
| 398 | |
| 399 | return 0; |
| 400 | fail2: |
| 401 | efx_ef10_sriov_free_vf_vswitching(efx); |
| 402 | fail1: |
| 403 | efx->vf_count = 0; |
| 404 | netif_err(efx, probe, efx->net_dev, |
| 405 | "Failed to enable SRIOV VFs\n"); |
| 406 | return rc; |
| 407 | } |
| 408 | |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 409 | static int efx_ef10_pci_sriov_disable(struct efx_nic *efx, bool force) |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 410 | { |
| 411 | struct pci_dev *dev = efx->pci_dev; |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 412 | unsigned int vfs_assigned = 0; |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 413 | |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 414 | vfs_assigned = pci_vfs_assigned(dev); |
Daniel Pieczko | 71158bf | 2015-06-02 11:40:31 +0100 | [diff] [blame] | 415 | |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 416 | if (vfs_assigned && !force) { |
| 417 | netif_info(efx, drv, efx->net_dev, "VFs are assigned to guests; " |
| 418 | "please detach them before disabling SR-IOV\n"); |
Daniel Pieczko | 71158bf | 2015-06-02 11:40:31 +0100 | [diff] [blame] | 419 | return -EBUSY; |
| 420 | } |
| 421 | |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 422 | if (!vfs_assigned) |
| 423 | pci_disable_sriov(dev); |
| 424 | |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 425 | efx_ef10_sriov_free_vf_vswitching(efx); |
| 426 | efx->vf_count = 0; |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | int efx_ef10_sriov_configure(struct efx_nic *efx, int num_vfs) |
| 431 | { |
| 432 | if (num_vfs == 0) |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 433 | return efx_ef10_pci_sriov_disable(efx, false); |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 434 | else |
| 435 | return efx_ef10_pci_sriov_enable(efx, num_vfs); |
| 436 | } |
| 437 | |
| 438 | int efx_ef10_sriov_init(struct efx_nic *efx) |
| 439 | { |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | void efx_ef10_sriov_fini(struct efx_nic *efx) |
| 444 | { |
| 445 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
Daniel Pieczko | 2a3fc31 | 2015-06-02 11:40:46 +0100 | [diff] [blame] | 446 | unsigned int i; |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 447 | int rc; |
| 448 | |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 449 | if (!nic_data->vf) { |
| 450 | /* Remove any un-assigned orphaned VFs */ |
| 451 | if (pci_num_vf(efx->pci_dev) && !pci_vfs_assigned(efx->pci_dev)) |
| 452 | pci_disable_sriov(efx->pci_dev); |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 453 | return; |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 454 | } |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 455 | |
Daniel Pieczko | 2a3fc31 | 2015-06-02 11:40:46 +0100 | [diff] [blame] | 456 | /* Remove any VFs in the host */ |
| 457 | for (i = 0; i < efx->vf_count; ++i) { |
| 458 | struct efx_nic *vf_efx = nic_data->vf[i].efx; |
| 459 | |
| 460 | if (vf_efx) |
| 461 | vf_efx->pci_dev->driver->remove(vf_efx->pci_dev); |
| 462 | } |
| 463 | |
Daniel Pieczko | 6598dad | 2015-06-02 11:41:00 +0100 | [diff] [blame] | 464 | rc = efx_ef10_pci_sriov_disable(efx, true); |
Shradha Shah | 3c5eb87 | 2015-05-06 00:58:31 +0100 | [diff] [blame] | 465 | if (rc) |
| 466 | netif_dbg(efx, drv, efx->net_dev, |
| 467 | "Disabling SRIOV was not successful rc=%d\n", rc); |
| 468 | else |
| 469 | netif_dbg(efx, drv, efx->net_dev, "SRIOV disabled\n"); |
| 470 | } |
Shradha Shah | e340be9 | 2015-05-20 11:11:03 +0100 | [diff] [blame] | 471 | |
| 472 | static int efx_ef10_vport_del_vf_mac(struct efx_nic *efx, unsigned int port_id, |
| 473 | u8 *mac) |
| 474 | { |
| 475 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN); |
| 476 | MCDI_DECLARE_BUF_ERR(outbuf); |
| 477 | size_t outlen; |
| 478 | int rc; |
| 479 | |
| 480 | MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id); |
| 481 | ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac); |
| 482 | |
| 483 | rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf, |
| 484 | sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); |
| 485 | |
| 486 | return rc; |
| 487 | } |
| 488 | |
| 489 | int efx_ef10_sriov_set_vf_mac(struct efx_nic *efx, int vf_i, u8 *mac) |
| 490 | { |
| 491 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 492 | struct ef10_vf *vf; |
| 493 | int rc; |
| 494 | |
| 495 | if (!nic_data->vf) |
| 496 | return -EOPNOTSUPP; |
| 497 | |
| 498 | if (vf_i >= efx->vf_count) |
| 499 | return -EINVAL; |
| 500 | vf = nic_data->vf + vf_i; |
| 501 | |
| 502 | if (vf->efx) { |
| 503 | efx_device_detach_sync(vf->efx); |
| 504 | efx_net_stop(vf->efx->net_dev); |
| 505 | |
| 506 | down_write(&vf->efx->filter_sem); |
| 507 | vf->efx->type->filter_table_remove(vf->efx); |
| 508 | |
| 509 | rc = efx_ef10_vadaptor_free(vf->efx, EVB_PORT_ID_ASSIGNED); |
| 510 | if (rc) { |
| 511 | up_write(&vf->efx->filter_sem); |
| 512 | return rc; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | rc = efx_ef10_evb_port_assign(efx, EVB_PORT_ID_NULL, vf_i); |
| 517 | if (rc) |
| 518 | return rc; |
| 519 | |
| 520 | if (!is_zero_ether_addr(vf->mac)) { |
| 521 | rc = efx_ef10_vport_del_vf_mac(efx, vf->vport_id, vf->mac); |
| 522 | if (rc) |
| 523 | return rc; |
| 524 | } |
| 525 | |
| 526 | if (!is_zero_ether_addr(mac)) { |
| 527 | rc = efx_ef10_vport_add_mac(efx, vf->vport_id, mac); |
| 528 | if (rc) { |
| 529 | eth_zero_addr(vf->mac); |
| 530 | goto fail; |
| 531 | } |
| 532 | if (vf->efx) |
| 533 | ether_addr_copy(vf->efx->net_dev->dev_addr, mac); |
| 534 | } |
| 535 | |
| 536 | ether_addr_copy(vf->mac, mac); |
| 537 | |
| 538 | rc = efx_ef10_evb_port_assign(efx, vf->vport_id, vf_i); |
| 539 | if (rc) |
| 540 | goto fail; |
| 541 | |
| 542 | if (vf->efx) { |
| 543 | /* VF cannot use the vport_id that the PF created */ |
| 544 | rc = efx_ef10_vadaptor_alloc(vf->efx, EVB_PORT_ID_ASSIGNED); |
| 545 | if (rc) { |
| 546 | up_write(&vf->efx->filter_sem); |
| 547 | return rc; |
| 548 | } |
| 549 | vf->efx->type->filter_table_probe(vf->efx); |
| 550 | up_write(&vf->efx->filter_sem); |
| 551 | efx_net_open(vf->efx->net_dev); |
Peter Dunning | 9c568fd | 2017-02-17 15:50:43 +0000 | [diff] [blame] | 552 | efx_device_attach_if_not_resetting(vf->efx); |
Shradha Shah | e340be9 | 2015-05-20 11:11:03 +0100 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | return 0; |
| 556 | |
| 557 | fail: |
Shyam Saini | 4b5b1ac | 2017-01-16 09:26:21 +0530 | [diff] [blame] | 558 | eth_zero_addr(vf->mac); |
Shradha Shah | e340be9 | 2015-05-20 11:11:03 +0100 | [diff] [blame] | 559 | return rc; |
| 560 | } |
Shradha Shah | b9af904 | 2015-05-20 11:11:18 +0100 | [diff] [blame] | 561 | |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 562 | int efx_ef10_sriov_set_vf_vlan(struct efx_nic *efx, int vf_i, u16 vlan, |
| 563 | u8 qos) |
| 564 | { |
| 565 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 566 | struct ef10_vf *vf; |
| 567 | u16 old_vlan, new_vlan; |
| 568 | int rc = 0, rc2 = 0; |
| 569 | |
| 570 | if (vf_i >= efx->vf_count) |
| 571 | return -EINVAL; |
| 572 | if (qos != 0) |
| 573 | return -EINVAL; |
| 574 | |
| 575 | vf = nic_data->vf + vf_i; |
| 576 | |
| 577 | new_vlan = (vlan == 0) ? EFX_EF10_NO_VLAN : vlan; |
| 578 | if (new_vlan == vf->vlan) |
| 579 | return 0; |
| 580 | |
| 581 | if (vf->efx) { |
| 582 | efx_device_detach_sync(vf->efx); |
| 583 | efx_net_stop(vf->efx->net_dev); |
| 584 | |
Martin Habets | d248953 | 2016-06-15 17:48:49 +0100 | [diff] [blame] | 585 | mutex_lock(&vf->efx->mac_lock); |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 586 | down_write(&vf->efx->filter_sem); |
| 587 | vf->efx->type->filter_table_remove(vf->efx); |
| 588 | |
| 589 | rc = efx_ef10_vadaptor_free(vf->efx, EVB_PORT_ID_ASSIGNED); |
| 590 | if (rc) |
| 591 | goto restore_filters; |
| 592 | } |
| 593 | |
| 594 | if (vf->vport_assigned) { |
| 595 | rc = efx_ef10_evb_port_assign(efx, EVB_PORT_ID_NULL, vf_i); |
| 596 | if (rc) { |
| 597 | netif_warn(efx, drv, efx->net_dev, |
| 598 | "Failed to change vlan on VF %d.\n", vf_i); |
| 599 | netif_warn(efx, drv, efx->net_dev, |
| 600 | "This is likely because the VF is bound to a driver in a VM.\n"); |
| 601 | netif_warn(efx, drv, efx->net_dev, |
| 602 | "Please unload the driver in the VM.\n"); |
| 603 | goto restore_vadaptor; |
| 604 | } |
| 605 | vf->vport_assigned = 0; |
| 606 | } |
| 607 | |
| 608 | if (!is_zero_ether_addr(vf->mac)) { |
| 609 | rc = efx_ef10_vport_del_mac(efx, vf->vport_id, vf->mac); |
| 610 | if (rc) |
| 611 | goto restore_evb_port; |
| 612 | } |
| 613 | |
| 614 | if (vf->vport_id) { |
| 615 | rc = efx_ef10_vport_free(efx, vf->vport_id); |
| 616 | if (rc) |
| 617 | goto restore_mac; |
| 618 | vf->vport_id = 0; |
| 619 | } |
| 620 | |
| 621 | /* Do the actual vlan change */ |
| 622 | old_vlan = vf->vlan; |
| 623 | vf->vlan = new_vlan; |
| 624 | |
| 625 | /* Restore everything in reverse order */ |
| 626 | rc = efx_ef10_vport_alloc(efx, EVB_PORT_ID_ASSIGNED, |
| 627 | MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL, |
| 628 | vf->vlan, &vf->vport_id); |
| 629 | if (rc) |
Shradha Shah | 671b53e | 2015-07-08 10:12:45 +0100 | [diff] [blame] | 630 | goto reset_nic_up_write; |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 631 | |
| 632 | restore_mac: |
| 633 | if (!is_zero_ether_addr(vf->mac)) { |
| 634 | rc2 = efx_ef10_vport_add_mac(efx, vf->vport_id, vf->mac); |
| 635 | if (rc2) { |
| 636 | eth_zero_addr(vf->mac); |
Shradha Shah | 671b53e | 2015-07-08 10:12:45 +0100 | [diff] [blame] | 637 | goto reset_nic_up_write; |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
| 641 | restore_evb_port: |
| 642 | rc2 = efx_ef10_evb_port_assign(efx, vf->vport_id, vf_i); |
| 643 | if (rc2) |
Shradha Shah | 671b53e | 2015-07-08 10:12:45 +0100 | [diff] [blame] | 644 | goto reset_nic_up_write; |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 645 | else |
| 646 | vf->vport_assigned = 1; |
| 647 | |
| 648 | restore_vadaptor: |
| 649 | if (vf->efx) { |
| 650 | rc2 = efx_ef10_vadaptor_alloc(vf->efx, EVB_PORT_ID_ASSIGNED); |
| 651 | if (rc2) |
Shradha Shah | 671b53e | 2015-07-08 10:12:45 +0100 | [diff] [blame] | 652 | goto reset_nic_up_write; |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | restore_filters: |
| 656 | if (vf->efx) { |
| 657 | rc2 = vf->efx->type->filter_table_probe(vf->efx); |
| 658 | if (rc2) |
Shradha Shah | 671b53e | 2015-07-08 10:12:45 +0100 | [diff] [blame] | 659 | goto reset_nic_up_write; |
| 660 | |
| 661 | up_write(&vf->efx->filter_sem); |
Martin Habets | d248953 | 2016-06-15 17:48:49 +0100 | [diff] [blame] | 662 | mutex_unlock(&vf->efx->mac_lock); |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 663 | |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 664 | rc2 = efx_net_open(vf->efx->net_dev); |
| 665 | if (rc2) |
| 666 | goto reset_nic; |
| 667 | |
Peter Dunning | 9c568fd | 2017-02-17 15:50:43 +0000 | [diff] [blame] | 668 | efx_device_attach_if_not_resetting(vf->efx); |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 669 | } |
| 670 | return rc; |
| 671 | |
Shradha Shah | 671b53e | 2015-07-08 10:12:45 +0100 | [diff] [blame] | 672 | reset_nic_up_write: |
Martin Habets | d248953 | 2016-06-15 17:48:49 +0100 | [diff] [blame] | 673 | if (vf->efx) { |
Shradha Shah | 671b53e | 2015-07-08 10:12:45 +0100 | [diff] [blame] | 674 | up_write(&vf->efx->filter_sem); |
Martin Habets | d248953 | 2016-06-15 17:48:49 +0100 | [diff] [blame] | 675 | mutex_unlock(&vf->efx->mac_lock); |
| 676 | } |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 677 | reset_nic: |
| 678 | if (vf->efx) { |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 679 | netif_err(efx, drv, efx->net_dev, |
| 680 | "Failed to restore VF - scheduling reset.\n"); |
| 681 | efx_schedule_reset(vf->efx, RESET_TYPE_DATAPATH); |
| 682 | } else { |
| 683 | netif_err(efx, drv, efx->net_dev, |
| 684 | "Failed to restore the VF and cannot reset the VF " |
| 685 | "- VF is not functional.\n"); |
| 686 | netif_err(efx, drv, efx->net_dev, |
| 687 | "Please reload the driver attached to the VF.\n"); |
| 688 | } |
| 689 | |
| 690 | return rc ? rc : rc2; |
| 691 | } |
| 692 | |
Shradha Shah | 860d2ff | 2015-05-20 11:12:30 +0100 | [diff] [blame] | 693 | int efx_ef10_sriov_set_vf_spoofchk(struct efx_nic *efx, int vf_i, |
| 694 | bool spoofchk) |
| 695 | { |
| 696 | return spoofchk ? -EOPNOTSUPP : 0; |
| 697 | } |
| 698 | |
Edward Cree | 4392dc6 | 2015-05-20 11:12:13 +0100 | [diff] [blame] | 699 | int efx_ef10_sriov_set_vf_link_state(struct efx_nic *efx, int vf_i, |
| 700 | int link_state) |
| 701 | { |
| 702 | MCDI_DECLARE_BUF(inbuf, MC_CMD_LINK_STATE_MODE_IN_LEN); |
| 703 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 704 | |
| 705 | BUILD_BUG_ON(IFLA_VF_LINK_STATE_AUTO != |
| 706 | MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_AUTO); |
| 707 | BUILD_BUG_ON(IFLA_VF_LINK_STATE_ENABLE != |
| 708 | MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_UP); |
| 709 | BUILD_BUG_ON(IFLA_VF_LINK_STATE_DISABLE != |
| 710 | MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_DOWN); |
| 711 | MCDI_POPULATE_DWORD_2(inbuf, LINK_STATE_MODE_IN_FUNCTION, |
| 712 | LINK_STATE_MODE_IN_FUNCTION_PF, |
| 713 | nic_data->pf_index, |
| 714 | LINK_STATE_MODE_IN_FUNCTION_VF, vf_i); |
| 715 | MCDI_SET_DWORD(inbuf, LINK_STATE_MODE_IN_NEW_MODE, link_state); |
| 716 | return efx_mcdi_rpc(efx, MC_CMD_LINK_STATE_MODE, inbuf, sizeof(inbuf), |
| 717 | NULL, 0, NULL); /* don't care what old mode was */ |
| 718 | } |
| 719 | |
Shradha Shah | b9af904 | 2015-05-20 11:11:18 +0100 | [diff] [blame] | 720 | int efx_ef10_sriov_get_vf_config(struct efx_nic *efx, int vf_i, |
| 721 | struct ifla_vf_info *ivf) |
| 722 | { |
Edward Cree | 4392dc6 | 2015-05-20 11:12:13 +0100 | [diff] [blame] | 723 | MCDI_DECLARE_BUF(inbuf, MC_CMD_LINK_STATE_MODE_IN_LEN); |
| 724 | MCDI_DECLARE_BUF(outbuf, MC_CMD_LINK_STATE_MODE_OUT_LEN); |
| 725 | |
Shradha Shah | b9af904 | 2015-05-20 11:11:18 +0100 | [diff] [blame] | 726 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
| 727 | struct ef10_vf *vf; |
Edward Cree | 4392dc6 | 2015-05-20 11:12:13 +0100 | [diff] [blame] | 728 | size_t outlen; |
| 729 | int rc; |
Shradha Shah | b9af904 | 2015-05-20 11:11:18 +0100 | [diff] [blame] | 730 | |
| 731 | if (vf_i >= efx->vf_count) |
| 732 | return -EINVAL; |
| 733 | |
| 734 | if (!nic_data->vf) |
| 735 | return -EOPNOTSUPP; |
| 736 | |
| 737 | vf = nic_data->vf + vf_i; |
| 738 | |
| 739 | ivf->vf = vf_i; |
| 740 | ivf->min_tx_rate = 0; |
| 741 | ivf->max_tx_rate = 0; |
| 742 | ether_addr_copy(ivf->mac, vf->mac); |
Shradha Shah | 2d432f2 | 2015-05-20 11:11:54 +0100 | [diff] [blame] | 743 | ivf->vlan = (vf->vlan == EFX_EF10_NO_VLAN) ? 0 : vf->vlan; |
Shradha Shah | b9af904 | 2015-05-20 11:11:18 +0100 | [diff] [blame] | 744 | ivf->qos = 0; |
| 745 | |
Edward Cree | 4392dc6 | 2015-05-20 11:12:13 +0100 | [diff] [blame] | 746 | MCDI_POPULATE_DWORD_2(inbuf, LINK_STATE_MODE_IN_FUNCTION, |
| 747 | LINK_STATE_MODE_IN_FUNCTION_PF, |
| 748 | nic_data->pf_index, |
| 749 | LINK_STATE_MODE_IN_FUNCTION_VF, vf_i); |
| 750 | MCDI_SET_DWORD(inbuf, LINK_STATE_MODE_IN_NEW_MODE, |
| 751 | MC_CMD_LINK_STATE_MODE_IN_DO_NOT_CHANGE); |
| 752 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_STATE_MODE, inbuf, sizeof(inbuf), |
| 753 | outbuf, sizeof(outbuf), &outlen); |
| 754 | if (rc) |
| 755 | return rc; |
| 756 | if (outlen < MC_CMD_LINK_STATE_MODE_OUT_LEN) |
| 757 | return -EIO; |
| 758 | ivf->linkstate = MCDI_DWORD(outbuf, LINK_STATE_MODE_OUT_OLD_MODE); |
| 759 | |
Shradha Shah | b9af904 | 2015-05-20 11:11:18 +0100 | [diff] [blame] | 760 | return 0; |
| 761 | } |