Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | 9497182 | 2012-01-06 03:24:16 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2012 Intel Corporation. |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
| 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 28 | #include <linux/types.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/in.h> |
| 35 | #include <linux/ip.h> |
| 36 | #include <linux/tcp.h> |
| 37 | #include <linux/ipv6.h> |
| 38 | #ifdef NETIF_F_HW_VLAN_TX |
| 39 | #include <linux/if_vlan.h> |
| 40 | #endif |
| 41 | |
| 42 | #include "ixgbe.h" |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 43 | #include "ixgbe_type.h" |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 44 | #include "ixgbe_sriov.h" |
| 45 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 46 | #ifdef CONFIG_PCI_IOV |
| 47 | static int ixgbe_find_enabled_vfs(struct ixgbe_adapter *adapter) |
| 48 | { |
| 49 | struct pci_dev *pdev = adapter->pdev; |
| 50 | struct pci_dev *pvfdev; |
| 51 | u16 vf_devfn = 0; |
| 52 | int device_id; |
| 53 | int vfs_found = 0; |
| 54 | |
| 55 | switch (adapter->hw.mac.type) { |
| 56 | case ixgbe_mac_82599EB: |
| 57 | device_id = IXGBE_DEV_ID_82599_VF; |
| 58 | break; |
| 59 | case ixgbe_mac_X540: |
| 60 | device_id = IXGBE_DEV_ID_X540_VF; |
| 61 | break; |
| 62 | default: |
| 63 | device_id = 0; |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | vf_devfn = pdev->devfn + 0x80; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 68 | pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 69 | while (pvfdev) { |
Greg Rose | a4b0832 | 2012-02-03 00:54:13 +0000 | [diff] [blame] | 70 | if (pvfdev->devfn == vf_devfn && |
| 71 | (pvfdev->bus->number >= pdev->bus->number)) |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 72 | vfs_found++; |
| 73 | vf_devfn += 2; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 74 | pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 75 | device_id, pvfdev); |
| 76 | } |
| 77 | |
| 78 | return vfs_found; |
| 79 | } |
| 80 | |
| 81 | void ixgbe_enable_sriov(struct ixgbe_adapter *adapter, |
| 82 | const struct ixgbe_info *ii) |
| 83 | { |
| 84 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 85 | int num_vf_macvlans, i; |
| 86 | struct vf_macvlans *mv_list; |
| 87 | int pre_existing_vfs = 0; |
| 88 | |
| 89 | pre_existing_vfs = ixgbe_find_enabled_vfs(adapter); |
| 90 | if (!pre_existing_vfs && !adapter->num_vfs) |
| 91 | return; |
| 92 | |
| 93 | /* If there are pre-existing VFs then we have to force |
| 94 | * use of that many because they were not deleted the last |
| 95 | * time someone removed the PF driver. That would have |
| 96 | * been because they were allocated to guest VMs and can't |
| 97 | * be removed. Go ahead and just re-enable the old amount. |
| 98 | * If the user wants to change the number of VFs they can |
| 99 | * use ethtool while making sure no VFs are allocated to |
| 100 | * guest VMs... i.e. the right way. |
| 101 | */ |
| 102 | if (pre_existing_vfs) { |
| 103 | adapter->num_vfs = pre_existing_vfs; |
| 104 | dev_warn(&adapter->pdev->dev, "Virtual Functions already " |
| 105 | "enabled for this device - Please reload all " |
| 106 | "VF drivers to avoid spoofed packet errors\n"); |
| 107 | } else { |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame^] | 108 | int err; |
| 109 | /* |
| 110 | * The 82599 supports up to 64 VFs per physical function |
| 111 | * but this implementation limits allocation to 63 so that |
| 112 | * basic networking resources are still available to the |
| 113 | * physical function. If the user requests greater thn |
| 114 | * 63 VFs then it is an error - reset to default of zero. |
| 115 | */ |
| 116 | adapter->num_vfs = min_t(unsigned int, adapter->num_vfs, 63); |
| 117 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 118 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 119 | if (err) { |
| 120 | e_err(probe, "Failed to enable PCI sriov: %d\n", err); |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame^] | 121 | adapter->num_vfs = 0; |
| 122 | return; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 123 | } |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 124 | } |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 125 | |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 126 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 127 | e_info(probe, "SR-IOV enabled with %d VFs\n", adapter->num_vfs); |
| 128 | |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 129 | /* Enable VMDq flag so device will be set in VM mode */ |
| 130 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED; |
| 131 | if (!adapter->ring_feature[RING_F_VMDQ].limit) |
| 132 | adapter->ring_feature[RING_F_VMDQ].limit = 1; |
| 133 | adapter->ring_feature[RING_F_VMDQ].offset = adapter->num_vfs; |
| 134 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 135 | num_vf_macvlans = hw->mac.num_rar_entries - |
| 136 | (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs); |
| 137 | |
| 138 | adapter->mv_list = mv_list = kcalloc(num_vf_macvlans, |
| 139 | sizeof(struct vf_macvlans), |
| 140 | GFP_KERNEL); |
| 141 | if (mv_list) { |
| 142 | /* Initialize list of VF macvlans */ |
| 143 | INIT_LIST_HEAD(&adapter->vf_mvs.l); |
| 144 | for (i = 0; i < num_vf_macvlans; i++) { |
| 145 | mv_list->vf = -1; |
| 146 | mv_list->free = true; |
| 147 | mv_list->rar_entry = hw->mac.num_rar_entries - |
| 148 | (i + adapter->num_vfs + 1); |
| 149 | list_add(&mv_list->l, &adapter->vf_mvs.l); |
| 150 | mv_list++; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /* If call to enable VFs succeeded then allocate memory |
| 155 | * for per VF control structures. |
| 156 | */ |
| 157 | adapter->vfinfo = |
| 158 | kcalloc(adapter->num_vfs, |
| 159 | sizeof(struct vf_data_storage), GFP_KERNEL); |
| 160 | if (adapter->vfinfo) { |
| 161 | /* Now that we're sure SR-IOV is enabled |
| 162 | * and memory allocated set up the mailbox parameters |
| 163 | */ |
| 164 | ixgbe_init_mbx_params_pf(hw); |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 165 | memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops)); |
| 166 | |
| 167 | /* limit trafffic classes based on VFs enabled */ |
| 168 | if ((adapter->hw.mac.type == ixgbe_mac_82599EB) && |
| 169 | (adapter->num_vfs < 16)) { |
| 170 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 171 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 172 | } else if (adapter->num_vfs < 32) { |
| 173 | adapter->dcb_cfg.num_tcs.pg_tcs = 4; |
| 174 | adapter->dcb_cfg.num_tcs.pfc_tcs = 4; |
| 175 | } else { |
| 176 | adapter->dcb_cfg.num_tcs.pg_tcs = 1; |
| 177 | adapter->dcb_cfg.num_tcs.pfc_tcs = 1; |
| 178 | } |
| 179 | |
| 180 | /* We do not support RSS w/ SR-IOV */ |
| 181 | adapter->ring_feature[RING_F_RSS].limit = 1; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 182 | |
| 183 | /* Disable RSC when in SR-IOV mode */ |
| 184 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | |
| 185 | IXGBE_FLAG2_RSC_ENABLED); |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 186 | |
| 187 | #ifdef IXGBE_FCOE |
| 188 | /* |
| 189 | * When SR-IOV is enabled 82599 cannot support jumbo frames |
| 190 | * so we must disable FCoE because we cannot support FCoE MTU. |
| 191 | */ |
| 192 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 193 | adapter->flags &= ~(IXGBE_FLAG_FCOE_ENABLED | |
| 194 | IXGBE_FLAG_FCOE_CAPABLE); |
| 195 | #endif |
| 196 | |
| 197 | /* enable spoof checking for all VFs */ |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 198 | for (i = 0; i < adapter->num_vfs; i++) |
| 199 | adapter->vfinfo[i].spoofchk_enabled = true; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 200 | return; |
| 201 | } |
| 202 | |
| 203 | /* Oh oh */ |
| 204 | e_err(probe, "Unable to allocate memory for VF Data Storage - " |
| 205 | "SRIOV disabled\n"); |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame^] | 206 | ixgbe_disable_sriov(adapter); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 207 | } |
| 208 | #endif /* #ifdef CONFIG_PCI_IOV */ |
| 209 | |
| 210 | void ixgbe_disable_sriov(struct ixgbe_adapter *adapter) |
| 211 | { |
| 212 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 213 | u32 gpie; |
| 214 | u32 vmdctl; |
| 215 | int i; |
| 216 | |
Alexander Duyck | d773d13 | 2012-05-05 05:32:26 +0000 | [diff] [blame] | 217 | /* set num VFs to 0 to prevent access to vfinfo */ |
| 218 | adapter->num_vfs = 0; |
| 219 | |
| 220 | /* free VF control structures */ |
| 221 | kfree(adapter->vfinfo); |
| 222 | adapter->vfinfo = NULL; |
| 223 | |
| 224 | /* free macvlan list */ |
| 225 | kfree(adapter->mv_list); |
| 226 | adapter->mv_list = NULL; |
| 227 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame^] | 228 | /* if SR-IOV is already disabled then there is nothing to do */ |
| 229 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 230 | return; |
| 231 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 232 | #ifdef CONFIG_PCI_IOV |
| 233 | /* disable iov and allow time for transactions to clear */ |
| 234 | pci_disable_sriov(adapter->pdev); |
| 235 | #endif |
| 236 | |
| 237 | /* turn off device IOV mode */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 238 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, 0); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 239 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 240 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 241 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 242 | |
| 243 | /* set default pool back to 0 */ |
| 244 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 245 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
| 246 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
| 247 | IXGBE_WRITE_FLUSH(hw); |
| 248 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 249 | /* Disable VMDq flag so device will be set in VM mode */ |
| 250 | if (adapter->ring_feature[RING_F_VMDQ].limit == 1) |
| 251 | adapter->flags &= ~IXGBE_FLAG_VMDQ_ENABLED; |
| 252 | adapter->ring_feature[RING_F_VMDQ].offset = 0; |
| 253 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 254 | /* take a breather then clean up driver data */ |
| 255 | msleep(100); |
| 256 | |
| 257 | /* Release reference to VF devices */ |
| 258 | for (i = 0; i < adapter->num_vfs; i++) { |
| 259 | if (adapter->vfinfo[i].vfdev) |
| 260 | pci_dev_put(adapter->vfinfo[i].vfdev); |
| 261 | } |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 262 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 263 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 264 | } |
| 265 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 266 | static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter, |
| 267 | int entries, u16 *hash_list, u32 vf) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 268 | { |
| 269 | struct vf_data_storage *vfinfo = &adapter->vfinfo[vf]; |
Greg Rose | 8a07a22 | 2010-05-05 19:57:30 +0000 | [diff] [blame] | 270 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 271 | int i; |
Greg Rose | 8a07a22 | 2010-05-05 19:57:30 +0000 | [diff] [blame] | 272 | u32 vector_bit; |
| 273 | u32 vector_reg; |
| 274 | u32 mta_reg; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 275 | |
| 276 | /* only so many hash values supported */ |
| 277 | entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES); |
| 278 | |
| 279 | /* |
| 280 | * salt away the number of multi cast addresses assigned |
| 281 | * to this VF for later use to restore when the PF multi cast |
| 282 | * list changes |
| 283 | */ |
| 284 | vfinfo->num_vf_mc_hashes = entries; |
| 285 | |
| 286 | /* |
| 287 | * VFs are limited to using the MTA hash table for their multicast |
| 288 | * addresses |
| 289 | */ |
| 290 | for (i = 0; i < entries; i++) { |
Joe Perches | e81a1ba | 2010-11-14 17:04:33 +0000 | [diff] [blame] | 291 | vfinfo->vf_mc_hashes[i] = hash_list[i]; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Greg Rose | 8a07a22 | 2010-05-05 19:57:30 +0000 | [diff] [blame] | 294 | for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) { |
| 295 | vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F; |
| 296 | vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F; |
| 297 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); |
| 298 | mta_reg |= (1 << vector_bit); |
| 299 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); |
| 300 | } |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 305 | static void ixgbe_restore_vf_macvlans(struct ixgbe_adapter *adapter) |
| 306 | { |
| 307 | struct ixgbe_hw *hw = &adapter->hw; |
| 308 | struct list_head *pos; |
| 309 | struct vf_macvlans *entry; |
| 310 | |
| 311 | list_for_each(pos, &adapter->vf_mvs.l) { |
| 312 | entry = list_entry(pos, struct vf_macvlans, l); |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 313 | if (!entry->free) |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 314 | hw->mac.ops.set_rar(hw, entry->rar_entry, |
| 315 | entry->vf_macvlan, |
| 316 | entry->vf, IXGBE_RAH_AV); |
| 317 | } |
| 318 | } |
| 319 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 320 | void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter) |
| 321 | { |
| 322 | struct ixgbe_hw *hw = &adapter->hw; |
| 323 | struct vf_data_storage *vfinfo; |
| 324 | int i, j; |
| 325 | u32 vector_bit; |
| 326 | u32 vector_reg; |
| 327 | u32 mta_reg; |
| 328 | |
| 329 | for (i = 0; i < adapter->num_vfs; i++) { |
| 330 | vfinfo = &adapter->vfinfo[i]; |
| 331 | for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) { |
| 332 | hw->addr_ctrl.mta_in_use++; |
| 333 | vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F; |
| 334 | vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F; |
| 335 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); |
| 336 | mta_reg |= (1 << vector_bit); |
| 337 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); |
| 338 | } |
| 339 | } |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 340 | |
| 341 | /* Restore any VF macvlans */ |
| 342 | ixgbe_restore_vf_macvlans(adapter); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 345 | static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid, |
| 346 | u32 vf) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 347 | { |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 348 | return adapter->hw.mac.ops.set_vfta(&adapter->hw, vid, vf, (bool)add); |
| 349 | } |
| 350 | |
John Fastabend | b32c8dc | 2011-04-12 02:44:55 +0000 | [diff] [blame] | 351 | static void ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf) |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 352 | { |
| 353 | struct ixgbe_hw *hw = &adapter->hw; |
| 354 | int new_mtu = msgbuf[1]; |
| 355 | u32 max_frs; |
| 356 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 357 | |
| 358 | /* Only X540 supports jumbo frames in IOV mode */ |
| 359 | if (adapter->hw.mac.type != ixgbe_mac_X540) |
| 360 | return; |
| 361 | |
| 362 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 363 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) { |
| 364 | e_err(drv, "VF mtu %d out of range\n", new_mtu); |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) & |
| 369 | IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT; |
| 370 | if (max_frs < new_mtu) { |
| 371 | max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT; |
| 372 | IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs); |
| 373 | } |
| 374 | |
| 375 | e_info(hw, "VF requests change max MTU to %d\n", new_mtu); |
| 376 | } |
| 377 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 378 | static void ixgbe_set_vmolr(struct ixgbe_hw *hw, u32 vf, bool aupe) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 379 | { |
| 380 | u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf)); |
Greg Rose | f041277 | 2010-05-04 22:11:46 +0000 | [diff] [blame] | 381 | vmolr |= (IXGBE_VMOLR_ROMPE | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 382 | IXGBE_VMOLR_BAM); |
Greg Rose | f041277 | 2010-05-04 22:11:46 +0000 | [diff] [blame] | 383 | if (aupe) |
| 384 | vmolr |= IXGBE_VMOLR_AUPE; |
| 385 | else |
| 386 | vmolr &= ~IXGBE_VMOLR_AUPE; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 387 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr); |
| 388 | } |
| 389 | |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 390 | static void ixgbe_set_vmvir(struct ixgbe_adapter *adapter, u32 vid, u32 vf) |
| 391 | { |
| 392 | struct ixgbe_hw *hw = &adapter->hw; |
| 393 | |
| 394 | if (vid) |
| 395 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), |
| 396 | (vid | IXGBE_VMVIR_VLANA_DEFAULT)); |
| 397 | else |
| 398 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0); |
| 399 | } |
| 400 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 401 | static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 402 | { |
| 403 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 404 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 405 | |
| 406 | /* reset offloads to defaults */ |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 407 | if (adapter->vfinfo[vf].pf_vlan) { |
| 408 | ixgbe_set_vf_vlan(adapter, true, |
| 409 | adapter->vfinfo[vf].pf_vlan, vf); |
| 410 | ixgbe_set_vmvir(adapter, |
| 411 | (adapter->vfinfo[vf].pf_vlan | |
| 412 | (adapter->vfinfo[vf].pf_qos << |
| 413 | VLAN_PRIO_SHIFT)), vf); |
| 414 | ixgbe_set_vmolr(hw, vf, false); |
| 415 | } else { |
| 416 | ixgbe_set_vmvir(adapter, 0, vf); |
| 417 | ixgbe_set_vmolr(hw, vf, true); |
| 418 | } |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 419 | |
| 420 | /* reset multicast table array for vf */ |
| 421 | adapter->vfinfo[vf].num_vf_mc_hashes = 0; |
| 422 | |
| 423 | /* Flush and reset the mta with the new values */ |
| 424 | ixgbe_set_rx_mode(adapter->netdev); |
| 425 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 426 | hw->mac.ops.clear_rar(hw, rar_entry); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 429 | static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter, |
| 430 | int vf, unsigned char *mac_addr) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 431 | { |
| 432 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 433 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 434 | |
| 435 | memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, 6); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 436 | hw->mac.ops.set_rar(hw, rar_entry, mac_addr, vf, IXGBE_RAH_AV); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 441 | static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter, |
| 442 | int vf, int index, unsigned char *mac_addr) |
| 443 | { |
| 444 | struct ixgbe_hw *hw = &adapter->hw; |
| 445 | struct list_head *pos; |
| 446 | struct vf_macvlans *entry; |
| 447 | |
| 448 | if (index <= 1) { |
| 449 | list_for_each(pos, &adapter->vf_mvs.l) { |
| 450 | entry = list_entry(pos, struct vf_macvlans, l); |
| 451 | if (entry->vf == vf) { |
| 452 | entry->vf = -1; |
| 453 | entry->free = true; |
| 454 | entry->is_macvlan = false; |
| 455 | hw->mac.ops.clear_rar(hw, entry->rar_entry); |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | /* |
| 461 | * If index was zero then we were asked to clear the uc list |
| 462 | * for the VF. We're done. |
| 463 | */ |
| 464 | if (!index) |
| 465 | return 0; |
| 466 | |
| 467 | entry = NULL; |
| 468 | |
| 469 | list_for_each(pos, &adapter->vf_mvs.l) { |
| 470 | entry = list_entry(pos, struct vf_macvlans, l); |
| 471 | if (entry->free) |
| 472 | break; |
| 473 | } |
| 474 | |
| 475 | /* |
| 476 | * If we traversed the entire list and didn't find a free entry |
| 477 | * then we're out of space on the RAR table. Also entry may |
| 478 | * be NULL because the original memory allocation for the list |
| 479 | * failed, which is not fatal but does mean we can't support |
| 480 | * VF requests for MACVLAN because we couldn't allocate |
| 481 | * memory for the list management required. |
| 482 | */ |
| 483 | if (!entry || !entry->free) |
| 484 | return -ENOSPC; |
| 485 | |
| 486 | entry->free = false; |
| 487 | entry->is_macvlan = true; |
| 488 | entry->vf = vf; |
| 489 | memcpy(entry->vf_macvlan, mac_addr, ETH_ALEN); |
| 490 | |
| 491 | hw->mac.ops.set_rar(hw, entry->rar_entry, mac_addr, vf, IXGBE_RAH_AV); |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 496 | int ixgbe_check_vf_assignment(struct ixgbe_adapter *adapter) |
| 497 | { |
Rose, Gregory V | 0126410 | 2011-11-07 07:44:17 +0000 | [diff] [blame] | 498 | #ifdef CONFIG_PCI_IOV |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 499 | int i; |
| 500 | for (i = 0; i < adapter->num_vfs; i++) { |
| 501 | if (adapter->vfinfo[i].vfdev->dev_flags & |
| 502 | PCI_DEV_FLAGS_ASSIGNED) |
| 503 | return true; |
| 504 | } |
Rose, Gregory V | 0126410 | 2011-11-07 07:44:17 +0000 | [diff] [blame] | 505 | #endif |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 506 | return false; |
| 507 | } |
| 508 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 509 | int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask) |
| 510 | { |
| 511 | unsigned char vf_mac_addr[6]; |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 512 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 513 | unsigned int vfn = (event_mask & 0x3f); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 514 | struct pci_dev *pvfdev; |
| 515 | unsigned int device_id; |
| 516 | u16 thisvf_devfn = (pdev->devfn + 0x80 + (vfn << 1)) | |
| 517 | (pdev->devfn & 1); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 518 | |
| 519 | bool enable = ((event_mask & 0x10000000U) != 0); |
| 520 | |
| 521 | if (enable) { |
Joe Perches | 7efd26d | 2012-07-12 19:33:06 +0000 | [diff] [blame] | 522 | eth_random_addr(vf_mac_addr); |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 523 | e_info(probe, "IOV: VF %d is enabled MAC %pM\n", |
| 524 | vfn, vf_mac_addr); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 525 | /* |
| 526 | * Store away the VF "permananet" MAC address, it will ask |
| 527 | * for it later. |
| 528 | */ |
| 529 | memcpy(adapter->vfinfo[vfn].vf_mac_addresses, vf_mac_addr, 6); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 530 | |
| 531 | switch (adapter->hw.mac.type) { |
| 532 | case ixgbe_mac_82599EB: |
| 533 | device_id = IXGBE_DEV_ID_82599_VF; |
| 534 | break; |
| 535 | case ixgbe_mac_X540: |
| 536 | device_id = IXGBE_DEV_ID_X540_VF; |
| 537 | break; |
| 538 | default: |
| 539 | device_id = 0; |
| 540 | break; |
| 541 | } |
| 542 | |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 543 | pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 544 | while (pvfdev) { |
| 545 | if (pvfdev->devfn == thisvf_devfn) |
| 546 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 547 | pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 548 | device_id, pvfdev); |
| 549 | } |
| 550 | if (pvfdev) |
| 551 | adapter->vfinfo[vfn].vfdev = pvfdev; |
| 552 | else |
| 553 | e_err(drv, "Couldn't find pci dev ptr for VF %4.4x\n", |
| 554 | thisvf_devfn); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | return 0; |
| 558 | } |
| 559 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 560 | static inline void ixgbe_vf_reset_msg(struct ixgbe_adapter *adapter, u32 vf) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 561 | { |
| 562 | struct ixgbe_hw *hw = &adapter->hw; |
| 563 | u32 reg; |
| 564 | u32 reg_offset, vf_shift; |
| 565 | |
| 566 | vf_shift = vf % 32; |
| 567 | reg_offset = vf / 32; |
| 568 | |
| 569 | /* enable transmit and receive for vf */ |
| 570 | reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset)); |
| 571 | reg |= (reg | (1 << vf_shift)); |
| 572 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg); |
| 573 | |
| 574 | reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset)); |
| 575 | reg |= (reg | (1 << vf_shift)); |
| 576 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg); |
| 577 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 578 | /* Enable counting of spoofed packets in the SSVPC register */ |
| 579 | reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset)); |
| 580 | reg |= (1 << vf_shift); |
| 581 | IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg); |
| 582 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 583 | ixgbe_vf_reset_event(adapter, vf); |
| 584 | } |
| 585 | |
| 586 | static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf) |
| 587 | { |
| 588 | u32 mbx_size = IXGBE_VFMAILBOX_SIZE; |
Emil Tantilov | c050999 | 2011-05-07 06:49:18 +0000 | [diff] [blame] | 589 | u32 msgbuf[IXGBE_VFMAILBOX_SIZE]; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 590 | struct ixgbe_hw *hw = &adapter->hw; |
| 591 | s32 retval; |
| 592 | int entries; |
| 593 | u16 *hash_list; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 594 | int add, vid, index; |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 595 | u8 *new_mac; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 596 | |
| 597 | retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf); |
| 598 | |
Alexander Duyck | dcaccc8 | 2012-03-28 08:03:38 +0000 | [diff] [blame] | 599 | if (retval) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 600 | pr_err("Error receiving message from VF\n"); |
Alexander Duyck | dcaccc8 | 2012-03-28 08:03:38 +0000 | [diff] [blame] | 601 | return retval; |
| 602 | } |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 603 | |
| 604 | /* this is a message we already processed, do nothing */ |
| 605 | if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK)) |
| 606 | return retval; |
| 607 | |
Alexander Duyck | dcaccc8 | 2012-03-28 08:03:38 +0000 | [diff] [blame] | 608 | /* flush the ack before we write any messages back */ |
| 609 | IXGBE_WRITE_FLUSH(hw); |
| 610 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 611 | /* |
| 612 | * until the vf completes a virtual function reset it should not be |
| 613 | * allowed to start any configuration. |
| 614 | */ |
| 615 | |
| 616 | if (msgbuf[0] == IXGBE_VF_RESET) { |
| 617 | unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses; |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 618 | new_mac = (u8 *)(&msgbuf[1]); |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 619 | e_info(probe, "VF Reset msg received from vf %d\n", vf); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 620 | adapter->vfinfo[vf].clear_to_send = false; |
| 621 | ixgbe_vf_reset_msg(adapter, vf); |
| 622 | adapter->vfinfo[vf].clear_to_send = true; |
| 623 | |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 624 | if (is_valid_ether_addr(new_mac) && |
| 625 | !adapter->vfinfo[vf].pf_set_mac) |
| 626 | ixgbe_set_vf_mac(adapter, vf, vf_mac); |
| 627 | else |
| 628 | ixgbe_set_vf_mac(adapter, |
| 629 | vf, adapter->vfinfo[vf].vf_mac_addresses); |
| 630 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 631 | /* reply to reset with ack and vf mac address */ |
| 632 | msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK; |
Joe Perches | ea99d83 | 2011-09-20 15:32:52 +0000 | [diff] [blame] | 633 | memcpy(new_mac, vf_mac, ETH_ALEN); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 634 | /* |
| 635 | * Piggyback the multicast filter type so VF can compute the |
| 636 | * correct vectors |
| 637 | */ |
| 638 | msgbuf[3] = hw->mac.mc_filter_type; |
| 639 | ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf); |
| 640 | |
| 641 | return retval; |
| 642 | } |
| 643 | |
| 644 | if (!adapter->vfinfo[vf].clear_to_send) { |
| 645 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; |
| 646 | ixgbe_write_mbx(hw, msgbuf, 1, vf); |
| 647 | return retval; |
| 648 | } |
| 649 | |
| 650 | switch ((msgbuf[0] & 0xFFFF)) { |
| 651 | case IXGBE_VF_SET_MAC_ADDR: |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 652 | new_mac = ((u8 *)(&msgbuf[1])); |
| 653 | if (is_valid_ether_addr(new_mac) && |
| 654 | !adapter->vfinfo[vf].pf_set_mac) { |
| 655 | ixgbe_set_vf_mac(adapter, vf, new_mac); |
| 656 | } else if (memcmp(adapter->vfinfo[vf].vf_mac_addresses, |
| 657 | new_mac, ETH_ALEN)) { |
| 658 | e_warn(drv, "VF %d attempted to override " |
| 659 | "administratively set MAC address\nReload " |
| 660 | "the VF driver to resume operations\n", vf); |
| 661 | retval = -1; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 662 | } |
| 663 | break; |
| 664 | case IXGBE_VF_SET_MULTICAST: |
| 665 | entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) |
| 666 | >> IXGBE_VT_MSGINFO_SHIFT; |
| 667 | hash_list = (u16 *)&msgbuf[1]; |
| 668 | retval = ixgbe_set_vf_multicasts(adapter, entries, |
| 669 | hash_list, vf); |
| 670 | break; |
| 671 | case IXGBE_VF_SET_LPE: |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 672 | ixgbe_set_vf_lpe(adapter, msgbuf); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 673 | break; |
| 674 | case IXGBE_VF_SET_VLAN: |
| 675 | add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) |
| 676 | >> IXGBE_VT_MSGINFO_SHIFT; |
| 677 | vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK); |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 678 | if (adapter->vfinfo[vf].pf_vlan) { |
| 679 | e_warn(drv, "VF %d attempted to override " |
| 680 | "administratively set VLAN configuration\n" |
| 681 | "Reload the VF driver to resume operations\n", |
| 682 | vf); |
| 683 | retval = -1; |
| 684 | } else { |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 685 | if (add) |
| 686 | adapter->vfinfo[vf].vlan_count++; |
| 687 | else if (adapter->vfinfo[vf].vlan_count) |
| 688 | adapter->vfinfo[vf].vlan_count--; |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 689 | retval = ixgbe_set_vf_vlan(adapter, add, vid, vf); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 690 | if (!retval && adapter->vfinfo[vf].spoofchk_enabled) |
| 691 | hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf); |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 692 | } |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 693 | break; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 694 | case IXGBE_VF_SET_MACVLAN: |
Greg Rose | 44b82dd | 2012-04-21 00:54:28 +0000 | [diff] [blame] | 695 | index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> |
| 696 | IXGBE_VT_MSGINFO_SHIFT; |
| 697 | if (adapter->vfinfo[vf].pf_set_mac && index > 0) { |
Greg Rose | 2ee7065 | 2012-03-24 00:26:44 +0000 | [diff] [blame] | 698 | e_warn(drv, "VF %d requested MACVLAN filter but is " |
| 699 | "administratively denied\n", vf); |
| 700 | retval = -1; |
| 701 | break; |
| 702 | } |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 703 | /* |
| 704 | * If the VF is allowed to set MAC filters then turn off |
| 705 | * anti-spoofing to avoid false positives. An index |
| 706 | * greater than 0 will indicate the VF is setting a |
| 707 | * macvlan MAC filter. |
| 708 | */ |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 709 | if (index > 0 && adapter->vfinfo[vf].spoofchk_enabled) |
| 710 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, vf, false); |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 711 | retval = ixgbe_set_vf_macvlan(adapter, vf, index, |
| 712 | (unsigned char *)(&msgbuf[1])); |
Greg Rose | 68d6d4a | 2012-01-05 07:58:11 +0000 | [diff] [blame] | 713 | if (retval == -ENOSPC) |
| 714 | e_warn(drv, "VF %d has requested a MACVLAN filter " |
| 715 | "but there is no space for it\n", vf); |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 716 | break; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 717 | default: |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 718 | e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 719 | retval = IXGBE_ERR_MBX; |
| 720 | break; |
| 721 | } |
| 722 | |
| 723 | /* notify the VF of the results of what it sent us */ |
| 724 | if (retval) |
| 725 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; |
| 726 | else |
| 727 | msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK; |
| 728 | |
| 729 | msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS; |
| 730 | |
| 731 | ixgbe_write_mbx(hw, msgbuf, 1, vf); |
| 732 | |
| 733 | return retval; |
| 734 | } |
| 735 | |
| 736 | static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf) |
| 737 | { |
| 738 | struct ixgbe_hw *hw = &adapter->hw; |
| 739 | u32 msg = IXGBE_VT_MSGTYPE_NACK; |
| 740 | |
| 741 | /* if device isn't clear to send it shouldn't be reading either */ |
| 742 | if (!adapter->vfinfo[vf].clear_to_send) |
| 743 | ixgbe_write_mbx(hw, &msg, 1, vf); |
| 744 | } |
| 745 | |
| 746 | void ixgbe_msg_task(struct ixgbe_adapter *adapter) |
| 747 | { |
| 748 | struct ixgbe_hw *hw = &adapter->hw; |
| 749 | u32 vf; |
| 750 | |
| 751 | for (vf = 0; vf < adapter->num_vfs; vf++) { |
| 752 | /* process any reset requests */ |
| 753 | if (!ixgbe_check_for_rst(hw, vf)) |
| 754 | ixgbe_vf_reset_event(adapter, vf); |
| 755 | |
| 756 | /* process any messages pending */ |
| 757 | if (!ixgbe_check_for_msg(hw, vf)) |
| 758 | ixgbe_rcv_msg_from_vf(adapter, vf); |
| 759 | |
| 760 | /* process any acks */ |
| 761 | if (!ixgbe_check_for_ack(hw, vf)) |
| 762 | ixgbe_rcv_ack_from_vf(adapter, vf); |
| 763 | } |
| 764 | } |
| 765 | |
Greg Rose | 767081a | 2010-01-22 22:46:40 +0000 | [diff] [blame] | 766 | void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter) |
| 767 | { |
| 768 | struct ixgbe_hw *hw = &adapter->hw; |
| 769 | |
| 770 | /* disable transmit and receive for all vfs */ |
| 771 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0); |
| 772 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0); |
| 773 | |
| 774 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0); |
| 775 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0); |
| 776 | } |
| 777 | |
| 778 | void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter) |
| 779 | { |
| 780 | struct ixgbe_hw *hw = &adapter->hw; |
| 781 | u32 ping; |
| 782 | int i; |
| 783 | |
| 784 | for (i = 0 ; i < adapter->num_vfs; i++) { |
| 785 | ping = IXGBE_PF_CONTROL_MSG; |
| 786 | if (adapter->vfinfo[i].clear_to_send) |
| 787 | ping |= IXGBE_VT_MSGTYPE_CTS; |
| 788 | ixgbe_write_mbx(hw, &ping, 1, i); |
| 789 | } |
| 790 | } |
| 791 | |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 792 | int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 793 | { |
| 794 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 795 | if (!is_valid_ether_addr(mac) || (vf >= adapter->num_vfs)) |
| 796 | return -EINVAL; |
| 797 | adapter->vfinfo[vf].pf_set_mac = true; |
| 798 | dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf); |
| 799 | dev_info(&adapter->pdev->dev, "Reload the VF driver to make this" |
| 800 | " change effective."); |
| 801 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 802 | dev_warn(&adapter->pdev->dev, "The VF MAC address has been set," |
| 803 | " but the PF device is not up.\n"); |
| 804 | dev_warn(&adapter->pdev->dev, "Bring the PF device up before" |
| 805 | " attempting to use the VF device.\n"); |
| 806 | } |
| 807 | return ixgbe_set_vf_mac(adapter, vf, mac); |
| 808 | } |
| 809 | |
| 810 | int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos) |
| 811 | { |
| 812 | int err = 0; |
| 813 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 814 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 815 | |
| 816 | if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7)) |
| 817 | return -EINVAL; |
| 818 | if (vlan || qos) { |
| 819 | err = ixgbe_set_vf_vlan(adapter, true, vlan, vf); |
| 820 | if (err) |
| 821 | goto out; |
| 822 | ixgbe_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 823 | ixgbe_set_vmolr(hw, vf, false); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 824 | if (adapter->vfinfo[vf].spoofchk_enabled) |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 825 | hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 826 | adapter->vfinfo[vf].vlan_count++; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 827 | adapter->vfinfo[vf].pf_vlan = vlan; |
| 828 | adapter->vfinfo[vf].pf_qos = qos; |
| 829 | dev_info(&adapter->pdev->dev, |
| 830 | "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf); |
| 831 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 832 | dev_warn(&adapter->pdev->dev, |
| 833 | "The VF VLAN has been set," |
| 834 | " but the PF device is not up.\n"); |
| 835 | dev_warn(&adapter->pdev->dev, |
| 836 | "Bring the PF device up before" |
| 837 | " attempting to use the VF device.\n"); |
| 838 | } |
| 839 | } else { |
| 840 | err = ixgbe_set_vf_vlan(adapter, false, |
| 841 | adapter->vfinfo[vf].pf_vlan, vf); |
| 842 | ixgbe_set_vmvir(adapter, vlan, vf); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 843 | ixgbe_set_vmolr(hw, vf, true); |
| 844 | hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 845 | if (adapter->vfinfo[vf].vlan_count) |
| 846 | adapter->vfinfo[vf].vlan_count--; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 847 | adapter->vfinfo[vf].pf_vlan = 0; |
| 848 | adapter->vfinfo[vf].pf_qos = 0; |
| 849 | } |
| 850 | out: |
| 851 | return err; |
| 852 | } |
| 853 | |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 854 | static int ixgbe_link_mbps(int internal_link_speed) |
| 855 | { |
| 856 | switch (internal_link_speed) { |
| 857 | case IXGBE_LINK_SPEED_100_FULL: |
| 858 | return 100; |
| 859 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 860 | return 1000; |
| 861 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 862 | return 10000; |
| 863 | default: |
| 864 | return 0; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | static void ixgbe_set_vf_rate_limit(struct ixgbe_hw *hw, int vf, int tx_rate, |
| 869 | int link_speed) |
| 870 | { |
| 871 | int rf_dec, rf_int; |
| 872 | u32 bcnrc_val; |
| 873 | |
| 874 | if (tx_rate != 0) { |
| 875 | /* Calculate the rate factor values to set */ |
| 876 | rf_int = link_speed / tx_rate; |
| 877 | rf_dec = (link_speed - (rf_int * tx_rate)); |
| 878 | rf_dec = (rf_dec * (1<<IXGBE_RTTBCNRC_RF_INT_SHIFT)) / tx_rate; |
| 879 | |
| 880 | bcnrc_val = IXGBE_RTTBCNRC_RS_ENA; |
| 881 | bcnrc_val |= ((rf_int<<IXGBE_RTTBCNRC_RF_INT_SHIFT) & |
| 882 | IXGBE_RTTBCNRC_RF_INT_MASK); |
| 883 | bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK); |
| 884 | } else { |
| 885 | bcnrc_val = 0; |
| 886 | } |
| 887 | |
| 888 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, 2*vf); /* vf Y uses queue 2*Y */ |
Lior Levy | 7555e83 | 2011-06-25 00:09:08 -0700 | [diff] [blame] | 889 | /* |
| 890 | * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM |
| 891 | * register. Typically MMW_SIZE=0x014 if 9728-byte jumbo is supported |
| 892 | * and 0x004 otherwise. |
| 893 | */ |
| 894 | switch (hw->mac.type) { |
| 895 | case ixgbe_mac_82599EB: |
| 896 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x4); |
| 897 | break; |
| 898 | case ixgbe_mac_X540: |
| 899 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x14); |
| 900 | break; |
| 901 | default: |
| 902 | break; |
| 903 | } |
| 904 | |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 905 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
| 906 | } |
| 907 | |
| 908 | void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter) |
| 909 | { |
| 910 | int actual_link_speed, i; |
| 911 | bool reset_rate = false; |
| 912 | |
| 913 | /* VF Tx rate limit was not set */ |
| 914 | if (adapter->vf_rate_link_speed == 0) |
| 915 | return; |
| 916 | |
| 917 | actual_link_speed = ixgbe_link_mbps(adapter->link_speed); |
| 918 | if (actual_link_speed != adapter->vf_rate_link_speed) { |
| 919 | reset_rate = true; |
| 920 | adapter->vf_rate_link_speed = 0; |
| 921 | dev_info(&adapter->pdev->dev, |
| 922 | "Link speed has been changed. VF Transmit rate " |
| 923 | "is disabled\n"); |
| 924 | } |
| 925 | |
| 926 | for (i = 0; i < adapter->num_vfs; i++) { |
| 927 | if (reset_rate) |
| 928 | adapter->vfinfo[i].tx_rate = 0; |
| 929 | |
| 930 | ixgbe_set_vf_rate_limit(&adapter->hw, i, |
| 931 | adapter->vfinfo[i].tx_rate, |
| 932 | actual_link_speed); |
| 933 | } |
| 934 | } |
| 935 | |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 936 | int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate) |
| 937 | { |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 938 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 939 | struct ixgbe_hw *hw = &adapter->hw; |
| 940 | int actual_link_speed; |
| 941 | |
| 942 | actual_link_speed = ixgbe_link_mbps(adapter->link_speed); |
| 943 | if ((vf >= adapter->num_vfs) || (!adapter->link_up) || |
| 944 | (tx_rate > actual_link_speed) || (actual_link_speed != 10000) || |
| 945 | ((tx_rate != 0) && (tx_rate <= 10))) |
| 946 | /* rate limit cannot be set to 10Mb or less in 10Gb adapters */ |
| 947 | return -EINVAL; |
| 948 | |
| 949 | adapter->vf_rate_link_speed = actual_link_speed; |
| 950 | adapter->vfinfo[vf].tx_rate = (u16)tx_rate; |
| 951 | ixgbe_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed); |
| 952 | |
| 953 | return 0; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 956 | int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting) |
| 957 | { |
| 958 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 959 | int vf_target_reg = vf >> 3; |
| 960 | int vf_target_shift = vf % 8; |
| 961 | struct ixgbe_hw *hw = &adapter->hw; |
| 962 | u32 regval; |
| 963 | |
| 964 | adapter->vfinfo[vf].spoofchk_enabled = setting; |
| 965 | |
| 966 | regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg)); |
| 967 | regval &= ~(1 << vf_target_shift); |
| 968 | regval |= (setting << vf_target_shift); |
| 969 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), regval); |
| 970 | |
| 971 | if (adapter->vfinfo[vf].vlan_count) { |
| 972 | vf_target_shift += IXGBE_SPOOF_VLANAS_SHIFT; |
| 973 | regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg)); |
| 974 | regval &= ~(1 << vf_target_shift); |
| 975 | regval |= (setting << vf_target_shift); |
| 976 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), regval); |
| 977 | } |
| 978 | |
| 979 | return 0; |
| 980 | } |
| 981 | |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 982 | int ixgbe_ndo_get_vf_config(struct net_device *netdev, |
| 983 | int vf, struct ifla_vf_info *ivi) |
| 984 | { |
| 985 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 986 | if (vf >= adapter->num_vfs) |
| 987 | return -EINVAL; |
| 988 | ivi->vf = vf; |
| 989 | memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN); |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 990 | ivi->tx_rate = adapter->vfinfo[vf].tx_rate; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 991 | ivi->vlan = adapter->vfinfo[vf].pf_vlan; |
| 992 | ivi->qos = adapter->vfinfo[vf].pf_qos; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 993 | ivi->spoofchk = adapter->vfinfo[vf].spoofchk_enabled; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 994 | return 0; |
| 995 | } |