Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2011 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; |
| 68 | pvfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL); |
| 69 | while (pvfdev) { |
| 70 | if (pvfdev->devfn == vf_devfn) |
| 71 | vfs_found++; |
| 72 | vf_devfn += 2; |
| 73 | pvfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, |
| 74 | device_id, pvfdev); |
| 75 | } |
| 76 | |
| 77 | return vfs_found; |
| 78 | } |
| 79 | |
| 80 | void ixgbe_enable_sriov(struct ixgbe_adapter *adapter, |
| 81 | const struct ixgbe_info *ii) |
| 82 | { |
| 83 | struct ixgbe_hw *hw = &adapter->hw; |
| 84 | int err = 0; |
| 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 { |
| 108 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 109 | } |
| 110 | if (err) { |
| 111 | e_err(probe, "Failed to enable PCI sriov: %d\n", err); |
| 112 | goto err_novfs; |
| 113 | } |
| 114 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; |
| 115 | |
| 116 | e_info(probe, "SR-IOV enabled with %d VFs\n", adapter->num_vfs); |
| 117 | |
| 118 | num_vf_macvlans = hw->mac.num_rar_entries - |
| 119 | (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs); |
| 120 | |
| 121 | adapter->mv_list = mv_list = kcalloc(num_vf_macvlans, |
| 122 | sizeof(struct vf_macvlans), |
| 123 | GFP_KERNEL); |
| 124 | if (mv_list) { |
| 125 | /* Initialize list of VF macvlans */ |
| 126 | INIT_LIST_HEAD(&adapter->vf_mvs.l); |
| 127 | for (i = 0; i < num_vf_macvlans; i++) { |
| 128 | mv_list->vf = -1; |
| 129 | mv_list->free = true; |
| 130 | mv_list->rar_entry = hw->mac.num_rar_entries - |
| 131 | (i + adapter->num_vfs + 1); |
| 132 | list_add(&mv_list->l, &adapter->vf_mvs.l); |
| 133 | mv_list++; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | /* If call to enable VFs succeeded then allocate memory |
| 138 | * for per VF control structures. |
| 139 | */ |
| 140 | adapter->vfinfo = |
| 141 | kcalloc(adapter->num_vfs, |
| 142 | sizeof(struct vf_data_storage), GFP_KERNEL); |
| 143 | if (adapter->vfinfo) { |
| 144 | /* Now that we're sure SR-IOV is enabled |
| 145 | * and memory allocated set up the mailbox parameters |
| 146 | */ |
| 147 | ixgbe_init_mbx_params_pf(hw); |
| 148 | memcpy(&hw->mbx.ops, ii->mbx_ops, |
| 149 | sizeof(hw->mbx.ops)); |
| 150 | |
| 151 | /* Disable RSC when in SR-IOV mode */ |
| 152 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | |
| 153 | IXGBE_FLAG2_RSC_ENABLED); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | /* Oh oh */ |
| 158 | e_err(probe, "Unable to allocate memory for VF Data Storage - " |
| 159 | "SRIOV disabled\n"); |
| 160 | pci_disable_sriov(adapter->pdev); |
| 161 | |
| 162 | err_novfs: |
| 163 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 164 | adapter->num_vfs = 0; |
| 165 | } |
| 166 | #endif /* #ifdef CONFIG_PCI_IOV */ |
| 167 | |
| 168 | void ixgbe_disable_sriov(struct ixgbe_adapter *adapter) |
| 169 | { |
| 170 | struct ixgbe_hw *hw = &adapter->hw; |
| 171 | u32 gcr; |
| 172 | u32 gpie; |
| 173 | u32 vmdctl; |
| 174 | int i; |
| 175 | |
| 176 | #ifdef CONFIG_PCI_IOV |
| 177 | /* disable iov and allow time for transactions to clear */ |
| 178 | pci_disable_sriov(adapter->pdev); |
| 179 | #endif |
| 180 | |
| 181 | /* turn off device IOV mode */ |
| 182 | gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 183 | gcr &= ~(IXGBE_GCR_EXT_SRIOV); |
| 184 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr); |
| 185 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 186 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 187 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 188 | |
| 189 | /* set default pool back to 0 */ |
| 190 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 191 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
| 192 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
| 193 | IXGBE_WRITE_FLUSH(hw); |
| 194 | |
| 195 | /* take a breather then clean up driver data */ |
| 196 | msleep(100); |
| 197 | |
| 198 | /* Release reference to VF devices */ |
| 199 | for (i = 0; i < adapter->num_vfs; i++) { |
| 200 | if (adapter->vfinfo[i].vfdev) |
| 201 | pci_dev_put(adapter->vfinfo[i].vfdev); |
| 202 | } |
| 203 | kfree(adapter->vfinfo); |
| 204 | kfree(adapter->mv_list); |
| 205 | adapter->vfinfo = NULL; |
| 206 | |
| 207 | adapter->num_vfs = 0; |
| 208 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 209 | } |
| 210 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 211 | static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter, |
| 212 | int entries, u16 *hash_list, u32 vf) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 213 | { |
| 214 | struct vf_data_storage *vfinfo = &adapter->vfinfo[vf]; |
Greg Rose | 8a07a22 | 2010-05-05 19:57:30 +0000 | [diff] [blame] | 215 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 216 | int i; |
Greg Rose | 8a07a22 | 2010-05-05 19:57:30 +0000 | [diff] [blame] | 217 | u32 vector_bit; |
| 218 | u32 vector_reg; |
| 219 | u32 mta_reg; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 220 | |
| 221 | /* only so many hash values supported */ |
| 222 | entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES); |
| 223 | |
| 224 | /* |
| 225 | * salt away the number of multi cast addresses assigned |
| 226 | * to this VF for later use to restore when the PF multi cast |
| 227 | * list changes |
| 228 | */ |
| 229 | vfinfo->num_vf_mc_hashes = entries; |
| 230 | |
| 231 | /* |
| 232 | * VFs are limited to using the MTA hash table for their multicast |
| 233 | * addresses |
| 234 | */ |
| 235 | for (i = 0; i < entries; i++) { |
Joe Perches | e81a1ba | 2010-11-14 17:04:33 +0000 | [diff] [blame] | 236 | vfinfo->vf_mc_hashes[i] = hash_list[i]; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Greg Rose | 8a07a22 | 2010-05-05 19:57:30 +0000 | [diff] [blame] | 239 | for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) { |
| 240 | vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F; |
| 241 | vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F; |
| 242 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); |
| 243 | mta_reg |= (1 << vector_bit); |
| 244 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); |
| 245 | } |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 250 | static void ixgbe_restore_vf_macvlans(struct ixgbe_adapter *adapter) |
| 251 | { |
| 252 | struct ixgbe_hw *hw = &adapter->hw; |
| 253 | struct list_head *pos; |
| 254 | struct vf_macvlans *entry; |
| 255 | |
| 256 | list_for_each(pos, &adapter->vf_mvs.l) { |
| 257 | entry = list_entry(pos, struct vf_macvlans, l); |
| 258 | if (entry->free == false) |
| 259 | hw->mac.ops.set_rar(hw, entry->rar_entry, |
| 260 | entry->vf_macvlan, |
| 261 | entry->vf, IXGBE_RAH_AV); |
| 262 | } |
| 263 | } |
| 264 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 265 | void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter) |
| 266 | { |
| 267 | struct ixgbe_hw *hw = &adapter->hw; |
| 268 | struct vf_data_storage *vfinfo; |
| 269 | int i, j; |
| 270 | u32 vector_bit; |
| 271 | u32 vector_reg; |
| 272 | u32 mta_reg; |
| 273 | |
| 274 | for (i = 0; i < adapter->num_vfs; i++) { |
| 275 | vfinfo = &adapter->vfinfo[i]; |
| 276 | for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) { |
| 277 | hw->addr_ctrl.mta_in_use++; |
| 278 | vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F; |
| 279 | vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F; |
| 280 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); |
| 281 | mta_reg |= (1 << vector_bit); |
| 282 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); |
| 283 | } |
| 284 | } |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 285 | |
| 286 | /* Restore any VF macvlans */ |
| 287 | ixgbe_restore_vf_macvlans(adapter); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 290 | static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid, |
| 291 | u32 vf) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 292 | { |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 293 | return adapter->hw.mac.ops.set_vfta(&adapter->hw, vid, vf, (bool)add); |
| 294 | } |
| 295 | |
John Fastabend | b32c8dc | 2011-04-12 02:44:55 +0000 | [diff] [blame] | 296 | static void ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf) |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 297 | { |
| 298 | struct ixgbe_hw *hw = &adapter->hw; |
| 299 | int new_mtu = msgbuf[1]; |
| 300 | u32 max_frs; |
| 301 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 302 | |
| 303 | /* Only X540 supports jumbo frames in IOV mode */ |
| 304 | if (adapter->hw.mac.type != ixgbe_mac_X540) |
| 305 | return; |
| 306 | |
| 307 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 308 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) { |
| 309 | e_err(drv, "VF mtu %d out of range\n", new_mtu); |
| 310 | return; |
| 311 | } |
| 312 | |
| 313 | max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) & |
| 314 | IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT; |
| 315 | if (max_frs < new_mtu) { |
| 316 | max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT; |
| 317 | IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs); |
| 318 | } |
| 319 | |
| 320 | e_info(hw, "VF requests change max MTU to %d\n", new_mtu); |
| 321 | } |
| 322 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 323 | 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] | 324 | { |
| 325 | u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf)); |
Greg Rose | f041277 | 2010-05-04 22:11:46 +0000 | [diff] [blame] | 326 | vmolr |= (IXGBE_VMOLR_ROMPE | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 327 | IXGBE_VMOLR_BAM); |
Greg Rose | f041277 | 2010-05-04 22:11:46 +0000 | [diff] [blame] | 328 | if (aupe) |
| 329 | vmolr |= IXGBE_VMOLR_AUPE; |
| 330 | else |
| 331 | vmolr &= ~IXGBE_VMOLR_AUPE; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 332 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr); |
| 333 | } |
| 334 | |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 335 | static void ixgbe_set_vmvir(struct ixgbe_adapter *adapter, u32 vid, u32 vf) |
| 336 | { |
| 337 | struct ixgbe_hw *hw = &adapter->hw; |
| 338 | |
| 339 | if (vid) |
| 340 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), |
| 341 | (vid | IXGBE_VMVIR_VLANA_DEFAULT)); |
| 342 | else |
| 343 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0); |
| 344 | } |
| 345 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 346 | 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] | 347 | { |
| 348 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 349 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 350 | |
| 351 | /* reset offloads to defaults */ |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 352 | if (adapter->vfinfo[vf].pf_vlan) { |
| 353 | ixgbe_set_vf_vlan(adapter, true, |
| 354 | adapter->vfinfo[vf].pf_vlan, vf); |
| 355 | ixgbe_set_vmvir(adapter, |
| 356 | (adapter->vfinfo[vf].pf_vlan | |
| 357 | (adapter->vfinfo[vf].pf_qos << |
| 358 | VLAN_PRIO_SHIFT)), vf); |
| 359 | ixgbe_set_vmolr(hw, vf, false); |
| 360 | } else { |
| 361 | ixgbe_set_vmvir(adapter, 0, vf); |
| 362 | ixgbe_set_vmolr(hw, vf, true); |
| 363 | } |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 364 | |
| 365 | /* reset multicast table array for vf */ |
| 366 | adapter->vfinfo[vf].num_vf_mc_hashes = 0; |
| 367 | |
| 368 | /* Flush and reset the mta with the new values */ |
| 369 | ixgbe_set_rx_mode(adapter->netdev); |
| 370 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 371 | hw->mac.ops.clear_rar(hw, rar_entry); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 372 | } |
| 373 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 374 | static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter, |
| 375 | int vf, unsigned char *mac_addr) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 376 | { |
| 377 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 378 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 379 | |
| 380 | memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, 6); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 381 | 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] | 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 386 | static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter, |
| 387 | int vf, int index, unsigned char *mac_addr) |
| 388 | { |
| 389 | struct ixgbe_hw *hw = &adapter->hw; |
| 390 | struct list_head *pos; |
| 391 | struct vf_macvlans *entry; |
| 392 | |
| 393 | if (index <= 1) { |
| 394 | list_for_each(pos, &adapter->vf_mvs.l) { |
| 395 | entry = list_entry(pos, struct vf_macvlans, l); |
| 396 | if (entry->vf == vf) { |
| 397 | entry->vf = -1; |
| 398 | entry->free = true; |
| 399 | entry->is_macvlan = false; |
| 400 | hw->mac.ops.clear_rar(hw, entry->rar_entry); |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | /* |
| 406 | * If index was zero then we were asked to clear the uc list |
| 407 | * for the VF. We're done. |
| 408 | */ |
| 409 | if (!index) |
| 410 | return 0; |
| 411 | |
| 412 | entry = NULL; |
| 413 | |
| 414 | list_for_each(pos, &adapter->vf_mvs.l) { |
| 415 | entry = list_entry(pos, struct vf_macvlans, l); |
| 416 | if (entry->free) |
| 417 | break; |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * If we traversed the entire list and didn't find a free entry |
| 422 | * then we're out of space on the RAR table. Also entry may |
| 423 | * be NULL because the original memory allocation for the list |
| 424 | * failed, which is not fatal but does mean we can't support |
| 425 | * VF requests for MACVLAN because we couldn't allocate |
| 426 | * memory for the list management required. |
| 427 | */ |
| 428 | if (!entry || !entry->free) |
| 429 | return -ENOSPC; |
| 430 | |
| 431 | entry->free = false; |
| 432 | entry->is_macvlan = true; |
| 433 | entry->vf = vf; |
| 434 | memcpy(entry->vf_macvlan, mac_addr, ETH_ALEN); |
| 435 | |
| 436 | hw->mac.ops.set_rar(hw, entry->rar_entry, mac_addr, vf, IXGBE_RAH_AV); |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame^] | 441 | int ixgbe_check_vf_assignment(struct ixgbe_adapter *adapter) |
| 442 | { |
| 443 | int i; |
| 444 | for (i = 0; i < adapter->num_vfs; i++) { |
| 445 | if (adapter->vfinfo[i].vfdev->dev_flags & |
| 446 | PCI_DEV_FLAGS_ASSIGNED) |
| 447 | return true; |
| 448 | } |
| 449 | return false; |
| 450 | } |
| 451 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 452 | int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask) |
| 453 | { |
| 454 | unsigned char vf_mac_addr[6]; |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 455 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 456 | unsigned int vfn = (event_mask & 0x3f); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame^] | 457 | struct pci_dev *pvfdev; |
| 458 | unsigned int device_id; |
| 459 | u16 thisvf_devfn = (pdev->devfn + 0x80 + (vfn << 1)) | |
| 460 | (pdev->devfn & 1); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 461 | |
| 462 | bool enable = ((event_mask & 0x10000000U) != 0); |
| 463 | |
| 464 | if (enable) { |
| 465 | random_ether_addr(vf_mac_addr); |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 466 | e_info(probe, "IOV: VF %d is enabled MAC %pM\n", |
| 467 | vfn, vf_mac_addr); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 468 | /* |
| 469 | * Store away the VF "permananet" MAC address, it will ask |
| 470 | * for it later. |
| 471 | */ |
| 472 | memcpy(adapter->vfinfo[vfn].vf_mac_addresses, vf_mac_addr, 6); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame^] | 473 | |
| 474 | switch (adapter->hw.mac.type) { |
| 475 | case ixgbe_mac_82599EB: |
| 476 | device_id = IXGBE_DEV_ID_82599_VF; |
| 477 | break; |
| 478 | case ixgbe_mac_X540: |
| 479 | device_id = IXGBE_DEV_ID_X540_VF; |
| 480 | break; |
| 481 | default: |
| 482 | device_id = 0; |
| 483 | break; |
| 484 | } |
| 485 | |
| 486 | pvfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL); |
| 487 | while (pvfdev) { |
| 488 | if (pvfdev->devfn == thisvf_devfn) |
| 489 | break; |
| 490 | pvfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, |
| 491 | device_id, pvfdev); |
| 492 | } |
| 493 | if (pvfdev) |
| 494 | adapter->vfinfo[vfn].vfdev = pvfdev; |
| 495 | else |
| 496 | e_err(drv, "Couldn't find pci dev ptr for VF %4.4x\n", |
| 497 | thisvf_devfn); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 503 | 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] | 504 | { |
| 505 | struct ixgbe_hw *hw = &adapter->hw; |
| 506 | u32 reg; |
| 507 | u32 reg_offset, vf_shift; |
| 508 | |
| 509 | vf_shift = vf % 32; |
| 510 | reg_offset = vf / 32; |
| 511 | |
| 512 | /* enable transmit and receive for vf */ |
| 513 | reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset)); |
| 514 | reg |= (reg | (1 << vf_shift)); |
| 515 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg); |
| 516 | |
| 517 | reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset)); |
| 518 | reg |= (reg | (1 << vf_shift)); |
| 519 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg); |
| 520 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 521 | /* Enable counting of spoofed packets in the SSVPC register */ |
| 522 | reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset)); |
| 523 | reg |= (1 << vf_shift); |
| 524 | IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg); |
| 525 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 526 | ixgbe_vf_reset_event(adapter, vf); |
| 527 | } |
| 528 | |
| 529 | static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf) |
| 530 | { |
| 531 | u32 mbx_size = IXGBE_VFMAILBOX_SIZE; |
Emil Tantilov | c050999 | 2011-05-07 06:49:18 +0000 | [diff] [blame] | 532 | u32 msgbuf[IXGBE_VFMAILBOX_SIZE]; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 533 | struct ixgbe_hw *hw = &adapter->hw; |
| 534 | s32 retval; |
| 535 | int entries; |
| 536 | u16 *hash_list; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 537 | int add, vid, index; |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 538 | u8 *new_mac; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 539 | |
| 540 | retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf); |
| 541 | |
| 542 | if (retval) |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 543 | pr_err("Error receiving message from VF\n"); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 544 | |
| 545 | /* this is a message we already processed, do nothing */ |
| 546 | if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK)) |
| 547 | return retval; |
| 548 | |
| 549 | /* |
| 550 | * until the vf completes a virtual function reset it should not be |
| 551 | * allowed to start any configuration. |
| 552 | */ |
| 553 | |
| 554 | if (msgbuf[0] == IXGBE_VF_RESET) { |
| 555 | unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses; |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 556 | new_mac = (u8 *)(&msgbuf[1]); |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 557 | e_info(probe, "VF Reset msg received from vf %d\n", vf); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 558 | adapter->vfinfo[vf].clear_to_send = false; |
| 559 | ixgbe_vf_reset_msg(adapter, vf); |
| 560 | adapter->vfinfo[vf].clear_to_send = true; |
| 561 | |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 562 | if (is_valid_ether_addr(new_mac) && |
| 563 | !adapter->vfinfo[vf].pf_set_mac) |
| 564 | ixgbe_set_vf_mac(adapter, vf, vf_mac); |
| 565 | else |
| 566 | ixgbe_set_vf_mac(adapter, |
| 567 | vf, adapter->vfinfo[vf].vf_mac_addresses); |
| 568 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 569 | /* reply to reset with ack and vf mac address */ |
| 570 | msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK; |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 571 | memcpy(new_mac, vf_mac, IXGBE_ETH_LENGTH_OF_ADDRESS); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 572 | /* |
| 573 | * Piggyback the multicast filter type so VF can compute the |
| 574 | * correct vectors |
| 575 | */ |
| 576 | msgbuf[3] = hw->mac.mc_filter_type; |
| 577 | ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf); |
| 578 | |
| 579 | return retval; |
| 580 | } |
| 581 | |
| 582 | if (!adapter->vfinfo[vf].clear_to_send) { |
| 583 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; |
| 584 | ixgbe_write_mbx(hw, msgbuf, 1, vf); |
| 585 | return retval; |
| 586 | } |
| 587 | |
| 588 | switch ((msgbuf[0] & 0xFFFF)) { |
| 589 | case IXGBE_VF_SET_MAC_ADDR: |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 590 | new_mac = ((u8 *)(&msgbuf[1])); |
| 591 | if (is_valid_ether_addr(new_mac) && |
| 592 | !adapter->vfinfo[vf].pf_set_mac) { |
| 593 | ixgbe_set_vf_mac(adapter, vf, new_mac); |
| 594 | } else if (memcmp(adapter->vfinfo[vf].vf_mac_addresses, |
| 595 | new_mac, ETH_ALEN)) { |
| 596 | e_warn(drv, "VF %d attempted to override " |
| 597 | "administratively set MAC address\nReload " |
| 598 | "the VF driver to resume operations\n", vf); |
| 599 | retval = -1; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 600 | } |
| 601 | break; |
| 602 | case IXGBE_VF_SET_MULTICAST: |
| 603 | entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) |
| 604 | >> IXGBE_VT_MSGINFO_SHIFT; |
| 605 | hash_list = (u16 *)&msgbuf[1]; |
| 606 | retval = ixgbe_set_vf_multicasts(adapter, entries, |
| 607 | hash_list, vf); |
| 608 | break; |
| 609 | case IXGBE_VF_SET_LPE: |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 610 | ixgbe_set_vf_lpe(adapter, msgbuf); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 611 | break; |
| 612 | case IXGBE_VF_SET_VLAN: |
| 613 | add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) |
| 614 | >> IXGBE_VT_MSGINFO_SHIFT; |
| 615 | vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK); |
Greg Rose | d3306c2 | 2010-11-18 03:03:23 +0000 | [diff] [blame] | 616 | if (adapter->vfinfo[vf].pf_vlan) { |
| 617 | e_warn(drv, "VF %d attempted to override " |
| 618 | "administratively set VLAN configuration\n" |
| 619 | "Reload the VF driver to resume operations\n", |
| 620 | vf); |
| 621 | retval = -1; |
| 622 | } else { |
| 623 | retval = ixgbe_set_vf_vlan(adapter, add, vid, vf); |
| 624 | } |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 625 | break; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 626 | case IXGBE_VF_SET_MACVLAN: |
| 627 | index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> |
| 628 | IXGBE_VT_MSGINFO_SHIFT; |
| 629 | /* |
| 630 | * If the VF is allowed to set MAC filters then turn off |
| 631 | * anti-spoofing to avoid false positives. An index |
| 632 | * greater than 0 will indicate the VF is setting a |
| 633 | * macvlan MAC filter. |
| 634 | */ |
| 635 | if (index > 0 && adapter->antispoofing_enabled) { |
| 636 | hw->mac.ops.set_mac_anti_spoofing(hw, false, |
| 637 | adapter->num_vfs); |
| 638 | hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf); |
| 639 | adapter->antispoofing_enabled = false; |
| 640 | } |
| 641 | retval = ixgbe_set_vf_macvlan(adapter, vf, index, |
| 642 | (unsigned char *)(&msgbuf[1])); |
| 643 | break; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 644 | default: |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 645 | e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 646 | retval = IXGBE_ERR_MBX; |
| 647 | break; |
| 648 | } |
| 649 | |
| 650 | /* notify the VF of the results of what it sent us */ |
| 651 | if (retval) |
| 652 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; |
| 653 | else |
| 654 | msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK; |
| 655 | |
| 656 | msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS; |
| 657 | |
| 658 | ixgbe_write_mbx(hw, msgbuf, 1, vf); |
| 659 | |
| 660 | return retval; |
| 661 | } |
| 662 | |
| 663 | static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf) |
| 664 | { |
| 665 | struct ixgbe_hw *hw = &adapter->hw; |
| 666 | u32 msg = IXGBE_VT_MSGTYPE_NACK; |
| 667 | |
| 668 | /* if device isn't clear to send it shouldn't be reading either */ |
| 669 | if (!adapter->vfinfo[vf].clear_to_send) |
| 670 | ixgbe_write_mbx(hw, &msg, 1, vf); |
| 671 | } |
| 672 | |
| 673 | void ixgbe_msg_task(struct ixgbe_adapter *adapter) |
| 674 | { |
| 675 | struct ixgbe_hw *hw = &adapter->hw; |
| 676 | u32 vf; |
| 677 | |
| 678 | for (vf = 0; vf < adapter->num_vfs; vf++) { |
| 679 | /* process any reset requests */ |
| 680 | if (!ixgbe_check_for_rst(hw, vf)) |
| 681 | ixgbe_vf_reset_event(adapter, vf); |
| 682 | |
| 683 | /* process any messages pending */ |
| 684 | if (!ixgbe_check_for_msg(hw, vf)) |
| 685 | ixgbe_rcv_msg_from_vf(adapter, vf); |
| 686 | |
| 687 | /* process any acks */ |
| 688 | if (!ixgbe_check_for_ack(hw, vf)) |
| 689 | ixgbe_rcv_ack_from_vf(adapter, vf); |
| 690 | } |
| 691 | } |
| 692 | |
Greg Rose | 767081a | 2010-01-22 22:46:40 +0000 | [diff] [blame] | 693 | void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter) |
| 694 | { |
| 695 | struct ixgbe_hw *hw = &adapter->hw; |
| 696 | |
| 697 | /* disable transmit and receive for all vfs */ |
| 698 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0); |
| 699 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0); |
| 700 | |
| 701 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0); |
| 702 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0); |
| 703 | } |
| 704 | |
| 705 | void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter) |
| 706 | { |
| 707 | struct ixgbe_hw *hw = &adapter->hw; |
| 708 | u32 ping; |
| 709 | int i; |
| 710 | |
| 711 | for (i = 0 ; i < adapter->num_vfs; i++) { |
| 712 | ping = IXGBE_PF_CONTROL_MSG; |
| 713 | if (adapter->vfinfo[i].clear_to_send) |
| 714 | ping |= IXGBE_VT_MSGTYPE_CTS; |
| 715 | ixgbe_write_mbx(hw, &ping, 1, i); |
| 716 | } |
| 717 | } |
| 718 | |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 719 | int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 720 | { |
| 721 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 722 | if (!is_valid_ether_addr(mac) || (vf >= adapter->num_vfs)) |
| 723 | return -EINVAL; |
| 724 | adapter->vfinfo[vf].pf_set_mac = true; |
| 725 | dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf); |
| 726 | dev_info(&adapter->pdev->dev, "Reload the VF driver to make this" |
| 727 | " change effective."); |
| 728 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 729 | dev_warn(&adapter->pdev->dev, "The VF MAC address has been set," |
| 730 | " but the PF device is not up.\n"); |
| 731 | dev_warn(&adapter->pdev->dev, "Bring the PF device up before" |
| 732 | " attempting to use the VF device.\n"); |
| 733 | } |
| 734 | return ixgbe_set_vf_mac(adapter, vf, mac); |
| 735 | } |
| 736 | |
| 737 | int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos) |
| 738 | { |
| 739 | int err = 0; |
| 740 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 741 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 742 | |
| 743 | if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7)) |
| 744 | return -EINVAL; |
| 745 | if (vlan || qos) { |
| 746 | err = ixgbe_set_vf_vlan(adapter, true, vlan, vf); |
| 747 | if (err) |
| 748 | goto out; |
| 749 | ixgbe_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 750 | ixgbe_set_vmolr(hw, vf, false); |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 751 | if (adapter->antispoofing_enabled) |
| 752 | hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf); |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 753 | adapter->vfinfo[vf].pf_vlan = vlan; |
| 754 | adapter->vfinfo[vf].pf_qos = qos; |
| 755 | dev_info(&adapter->pdev->dev, |
| 756 | "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf); |
| 757 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 758 | dev_warn(&adapter->pdev->dev, |
| 759 | "The VF VLAN has been set," |
| 760 | " but the PF device is not up.\n"); |
| 761 | dev_warn(&adapter->pdev->dev, |
| 762 | "Bring the PF device up before" |
| 763 | " attempting to use the VF device.\n"); |
| 764 | } |
| 765 | } else { |
| 766 | err = ixgbe_set_vf_vlan(adapter, false, |
| 767 | adapter->vfinfo[vf].pf_vlan, vf); |
| 768 | ixgbe_set_vmvir(adapter, vlan, vf); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 769 | ixgbe_set_vmolr(hw, vf, true); |
| 770 | hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf); |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 771 | adapter->vfinfo[vf].pf_vlan = 0; |
| 772 | adapter->vfinfo[vf].pf_qos = 0; |
| 773 | } |
| 774 | out: |
| 775 | return err; |
| 776 | } |
| 777 | |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 778 | static int ixgbe_link_mbps(int internal_link_speed) |
| 779 | { |
| 780 | switch (internal_link_speed) { |
| 781 | case IXGBE_LINK_SPEED_100_FULL: |
| 782 | return 100; |
| 783 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 784 | return 1000; |
| 785 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 786 | return 10000; |
| 787 | default: |
| 788 | return 0; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | static void ixgbe_set_vf_rate_limit(struct ixgbe_hw *hw, int vf, int tx_rate, |
| 793 | int link_speed) |
| 794 | { |
| 795 | int rf_dec, rf_int; |
| 796 | u32 bcnrc_val; |
| 797 | |
| 798 | if (tx_rate != 0) { |
| 799 | /* Calculate the rate factor values to set */ |
| 800 | rf_int = link_speed / tx_rate; |
| 801 | rf_dec = (link_speed - (rf_int * tx_rate)); |
| 802 | rf_dec = (rf_dec * (1<<IXGBE_RTTBCNRC_RF_INT_SHIFT)) / tx_rate; |
| 803 | |
| 804 | bcnrc_val = IXGBE_RTTBCNRC_RS_ENA; |
| 805 | bcnrc_val |= ((rf_int<<IXGBE_RTTBCNRC_RF_INT_SHIFT) & |
| 806 | IXGBE_RTTBCNRC_RF_INT_MASK); |
| 807 | bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK); |
| 808 | } else { |
| 809 | bcnrc_val = 0; |
| 810 | } |
| 811 | |
| 812 | 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] | 813 | /* |
| 814 | * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM |
| 815 | * register. Typically MMW_SIZE=0x014 if 9728-byte jumbo is supported |
| 816 | * and 0x004 otherwise. |
| 817 | */ |
| 818 | switch (hw->mac.type) { |
| 819 | case ixgbe_mac_82599EB: |
| 820 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x4); |
| 821 | break; |
| 822 | case ixgbe_mac_X540: |
| 823 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x14); |
| 824 | break; |
| 825 | default: |
| 826 | break; |
| 827 | } |
| 828 | |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 829 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
| 830 | } |
| 831 | |
| 832 | void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter) |
| 833 | { |
| 834 | int actual_link_speed, i; |
| 835 | bool reset_rate = false; |
| 836 | |
| 837 | /* VF Tx rate limit was not set */ |
| 838 | if (adapter->vf_rate_link_speed == 0) |
| 839 | return; |
| 840 | |
| 841 | actual_link_speed = ixgbe_link_mbps(adapter->link_speed); |
| 842 | if (actual_link_speed != adapter->vf_rate_link_speed) { |
| 843 | reset_rate = true; |
| 844 | adapter->vf_rate_link_speed = 0; |
| 845 | dev_info(&adapter->pdev->dev, |
| 846 | "Link speed has been changed. VF Transmit rate " |
| 847 | "is disabled\n"); |
| 848 | } |
| 849 | |
| 850 | for (i = 0; i < adapter->num_vfs; i++) { |
| 851 | if (reset_rate) |
| 852 | adapter->vfinfo[i].tx_rate = 0; |
| 853 | |
| 854 | ixgbe_set_vf_rate_limit(&adapter->hw, i, |
| 855 | adapter->vfinfo[i].tx_rate, |
| 856 | actual_link_speed); |
| 857 | } |
| 858 | } |
| 859 | |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 860 | int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate) |
| 861 | { |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 862 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 863 | struct ixgbe_hw *hw = &adapter->hw; |
| 864 | int actual_link_speed; |
| 865 | |
| 866 | actual_link_speed = ixgbe_link_mbps(adapter->link_speed); |
| 867 | if ((vf >= adapter->num_vfs) || (!adapter->link_up) || |
| 868 | (tx_rate > actual_link_speed) || (actual_link_speed != 10000) || |
| 869 | ((tx_rate != 0) && (tx_rate <= 10))) |
| 870 | /* rate limit cannot be set to 10Mb or less in 10Gb adapters */ |
| 871 | return -EINVAL; |
| 872 | |
| 873 | adapter->vf_rate_link_speed = actual_link_speed; |
| 874 | adapter->vfinfo[vf].tx_rate = (u16)tx_rate; |
| 875 | ixgbe_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed); |
| 876 | |
| 877 | return 0; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | int ixgbe_ndo_get_vf_config(struct net_device *netdev, |
| 881 | int vf, struct ifla_vf_info *ivi) |
| 882 | { |
| 883 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 884 | if (vf >= adapter->num_vfs) |
| 885 | return -EINVAL; |
| 886 | ivi->vf = vf; |
| 887 | memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN); |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 888 | ivi->tx_rate = adapter->vfinfo[vf].tx_rate; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 889 | ivi->vlan = adapter->vfinfo[vf].pf_vlan; |
| 890 | ivi->qos = adapter->vfinfo[vf].pf_qos; |
| 891 | return 0; |
| 892 | } |