Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 4 | Copyright(c) 1999 - 2015 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: |
Jacob Keller | b89aae7 | 2014-02-22 01:23:50 +0000 | [diff] [blame] | 23 | Linux NICS <linux.nics@intel.com> |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 29 | #include <linux/types.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/vmalloc.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/in.h> |
| 36 | #include <linux/ip.h> |
| 37 | #include <linux/tcp.h> |
| 38 | #include <linux/ipv6.h> |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 39 | #include <linux/if_bridge.h> |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 40 | #ifdef NETIF_F_HW_VLAN_CTAG_TX |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 41 | #include <linux/if_vlan.h> |
| 42 | #endif |
| 43 | |
| 44 | #include "ixgbe.h" |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 45 | #include "ixgbe_type.h" |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 46 | #include "ixgbe_sriov.h" |
| 47 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 48 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 66dcfd7 | 2012-12-11 08:26:38 +0000 | [diff] [blame] | 49 | static int __ixgbe_enable_sriov(struct ixgbe_adapter *adapter) |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 50 | { |
| 51 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 52 | int num_vf_macvlans, i; |
| 53 | struct vf_macvlans *mv_list; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 54 | |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 55 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 56 | e_info(probe, "SR-IOV enabled with %d VFs\n", adapter->num_vfs); |
| 57 | |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 58 | /* Enable VMDq flag so device will be set in VM mode */ |
| 59 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED; |
| 60 | if (!adapter->ring_feature[RING_F_VMDQ].limit) |
| 61 | adapter->ring_feature[RING_F_VMDQ].limit = 1; |
| 62 | adapter->ring_feature[RING_F_VMDQ].offset = adapter->num_vfs; |
| 63 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 64 | num_vf_macvlans = hw->mac.num_rar_entries - |
| 65 | (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs); |
| 66 | |
| 67 | adapter->mv_list = mv_list = kcalloc(num_vf_macvlans, |
| 68 | sizeof(struct vf_macvlans), |
| 69 | GFP_KERNEL); |
| 70 | if (mv_list) { |
| 71 | /* Initialize list of VF macvlans */ |
| 72 | INIT_LIST_HEAD(&adapter->vf_mvs.l); |
| 73 | for (i = 0; i < num_vf_macvlans; i++) { |
| 74 | mv_list->vf = -1; |
| 75 | mv_list->free = true; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 76 | list_add(&mv_list->l, &adapter->vf_mvs.l); |
| 77 | mv_list++; |
| 78 | } |
| 79 | } |
| 80 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 81 | /* Initialize default switching mode VEB */ |
| 82 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 83 | adapter->bridge_mode = BRIDGE_MODE_VEB; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 84 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 85 | /* If call to enable VFs succeeded then allocate memory |
| 86 | * for per VF control structures. |
| 87 | */ |
| 88 | adapter->vfinfo = |
| 89 | kcalloc(adapter->num_vfs, |
| 90 | sizeof(struct vf_data_storage), GFP_KERNEL); |
| 91 | if (adapter->vfinfo) { |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 92 | /* limit trafffic classes based on VFs enabled */ |
| 93 | if ((adapter->hw.mac.type == ixgbe_mac_82599EB) && |
| 94 | (adapter->num_vfs < 16)) { |
| 95 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 96 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 97 | } else if (adapter->num_vfs < 32) { |
| 98 | adapter->dcb_cfg.num_tcs.pg_tcs = 4; |
| 99 | adapter->dcb_cfg.num_tcs.pfc_tcs = 4; |
| 100 | } else { |
| 101 | adapter->dcb_cfg.num_tcs.pg_tcs = 1; |
| 102 | adapter->dcb_cfg.num_tcs.pfc_tcs = 1; |
| 103 | } |
| 104 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 105 | /* Disable RSC when in SR-IOV mode */ |
| 106 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | |
| 107 | IXGBE_FLAG2_RSC_ENABLED); |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 108 | |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 109 | for (i = 0; i < adapter->num_vfs; i++) { |
| 110 | /* enable spoof checking for all VFs */ |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 111 | adapter->vfinfo[i].spoofchk_enabled = true; |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 112 | |
| 113 | /* We support VF RSS querying only for 82599 and x540 |
| 114 | * devices at the moment. These devices share RSS |
| 115 | * indirection table and RSS hash key with PF therefore |
| 116 | * we want to disable the querying by default. |
| 117 | */ |
| 118 | adapter->vfinfo[i].rss_query_enabled = 0; |
Hiroshi Shimamoto | 54011e4 | 2015-08-28 06:58:33 +0000 | [diff] [blame] | 119 | |
| 120 | /* Untrust all VFs */ |
| 121 | adapter->vfinfo[i].trusted = false; |
Hiroshi Shimamoto | 8443c1a4 | 2015-08-28 06:59:03 +0000 | [diff] [blame] | 122 | |
| 123 | /* set the default xcast mode */ |
| 124 | adapter->vfinfo[i].xcast_mode = IXGBEVF_XCAST_MODE_NONE; |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 125 | } |
| 126 | |
Greg Rose | 66dcfd7 | 2012-12-11 08:26:38 +0000 | [diff] [blame] | 127 | return 0; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Greg Rose | 66dcfd7 | 2012-12-11 08:26:38 +0000 | [diff] [blame] | 130 | return -ENOMEM; |
| 131 | } |
| 132 | |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 133 | /** |
| 134 | * ixgbe_get_vfs - Find and take references to all vf devices |
| 135 | * @adapter: Pointer to adapter struct |
| 136 | */ |
| 137 | static void ixgbe_get_vfs(struct ixgbe_adapter *adapter) |
| 138 | { |
| 139 | struct pci_dev *pdev = adapter->pdev; |
| 140 | u16 vendor = pdev->vendor; |
| 141 | struct pci_dev *vfdev; |
| 142 | int vf = 0; |
| 143 | u16 vf_id; |
| 144 | int pos; |
| 145 | |
| 146 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 147 | if (!pos) |
| 148 | return; |
| 149 | pci_read_config_word(pdev, pos + PCI_SRIOV_VF_DID, &vf_id); |
| 150 | |
| 151 | vfdev = pci_get_device(vendor, vf_id, NULL); |
| 152 | for (; vfdev; vfdev = pci_get_device(vendor, vf_id, vfdev)) { |
| 153 | if (!vfdev->is_virtfn) |
| 154 | continue; |
| 155 | if (vfdev->physfn != pdev) |
| 156 | continue; |
| 157 | if (vf >= adapter->num_vfs) |
| 158 | continue; |
| 159 | pci_dev_get(vfdev); |
| 160 | adapter->vfinfo[vf].vfdev = vfdev; |
| 161 | ++vf; |
| 162 | } |
| 163 | } |
| 164 | |
Greg Rose | 66dcfd7 | 2012-12-11 08:26:38 +0000 | [diff] [blame] | 165 | /* Note this function is called when the user wants to enable SR-IOV |
| 166 | * VFs using the now deprecated module parameter |
| 167 | */ |
| 168 | void ixgbe_enable_sriov(struct ixgbe_adapter *adapter) |
| 169 | { |
| 170 | int pre_existing_vfs = 0; |
| 171 | |
| 172 | pre_existing_vfs = pci_num_vf(adapter->pdev); |
| 173 | if (!pre_existing_vfs && !adapter->num_vfs) |
| 174 | return; |
| 175 | |
Greg Rose | 66dcfd7 | 2012-12-11 08:26:38 +0000 | [diff] [blame] | 176 | /* If there are pre-existing VFs then we have to force |
| 177 | * use of that many - over ride any module parameter value. |
| 178 | * This may result from the user unloading the PF driver |
| 179 | * while VFs were assigned to guest VMs or because the VFs |
| 180 | * have been created via the new PCI SR-IOV sysfs interface. |
| 181 | */ |
| 182 | if (pre_existing_vfs) { |
| 183 | adapter->num_vfs = pre_existing_vfs; |
| 184 | dev_warn(&adapter->pdev->dev, |
| 185 | "Virtual Functions already enabled for this device - Please reload all VF drivers to avoid spoofed packet errors\n"); |
| 186 | } else { |
| 187 | int err; |
| 188 | /* |
| 189 | * The 82599 supports up to 64 VFs per physical function |
| 190 | * but this implementation limits allocation to 63 so that |
| 191 | * basic networking resources are still available to the |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 192 | * physical function. If the user requests greater than |
Greg Rose | 66dcfd7 | 2012-12-11 08:26:38 +0000 | [diff] [blame] | 193 | * 63 VFs then it is an error - reset to default of zero. |
| 194 | */ |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 195 | adapter->num_vfs = min_t(unsigned int, adapter->num_vfs, IXGBE_MAX_VFS_DRV_LIMIT); |
Greg Rose | 66dcfd7 | 2012-12-11 08:26:38 +0000 | [diff] [blame] | 196 | |
| 197 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 198 | if (err) { |
| 199 | e_err(probe, "Failed to enable PCI sriov: %d\n", err); |
| 200 | adapter->num_vfs = 0; |
| 201 | return; |
| 202 | } |
| 203 | } |
| 204 | |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 205 | if (!__ixgbe_enable_sriov(adapter)) { |
| 206 | ixgbe_get_vfs(adapter); |
Greg Rose | 66dcfd7 | 2012-12-11 08:26:38 +0000 | [diff] [blame] | 207 | return; |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 208 | } |
Greg Rose | 66dcfd7 | 2012-12-11 08:26:38 +0000 | [diff] [blame] | 209 | |
| 210 | /* If we have gotten to this point then there is no memory available |
| 211 | * to manage the VF devices - print message and bail. |
| 212 | */ |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 213 | e_err(probe, "Unable to allocate memory for VF Data Storage - " |
| 214 | "SRIOV disabled\n"); |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 215 | ixgbe_disable_sriov(adapter); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 216 | } |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 217 | |
Alexander Duyck | 9297127 | 2012-05-23 02:58:40 +0000 | [diff] [blame] | 218 | #endif /* #ifdef CONFIG_PCI_IOV */ |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 219 | int ixgbe_disable_sriov(struct ixgbe_adapter *adapter) |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 220 | { |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 221 | unsigned int num_vfs = adapter->num_vfs, vf; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 222 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 223 | u32 gpie; |
| 224 | u32 vmdctl; |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 225 | int rss; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 226 | |
Alexander Duyck | d773d13 | 2012-05-05 05:32:26 +0000 | [diff] [blame] | 227 | /* set num VFs to 0 to prevent access to vfinfo */ |
| 228 | adapter->num_vfs = 0; |
| 229 | |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 230 | /* put the reference to all of the vf devices */ |
| 231 | for (vf = 0; vf < num_vfs; ++vf) { |
| 232 | struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev; |
| 233 | |
| 234 | if (!vfdev) |
| 235 | continue; |
| 236 | adapter->vfinfo[vf].vfdev = NULL; |
| 237 | pci_dev_put(vfdev); |
| 238 | } |
| 239 | |
Alexander Duyck | d773d13 | 2012-05-05 05:32:26 +0000 | [diff] [blame] | 240 | /* free VF control structures */ |
| 241 | kfree(adapter->vfinfo); |
| 242 | adapter->vfinfo = NULL; |
| 243 | |
| 244 | /* free macvlan list */ |
| 245 | kfree(adapter->mv_list); |
| 246 | adapter->mv_list = NULL; |
| 247 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 248 | /* if SR-IOV is already disabled then there is nothing to do */ |
| 249 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 250 | return 0; |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 251 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 252 | #ifdef CONFIG_PCI_IOV |
Alexander Duyck | 9297127 | 2012-05-23 02:58:40 +0000 | [diff] [blame] | 253 | /* |
| 254 | * If our VFs are assigned we cannot shut down SR-IOV |
| 255 | * without causing issues, so just leave the hardware |
| 256 | * available but disabled |
| 257 | */ |
Alexander Duyck | e507d0c | 2013-03-26 00:03:21 +0000 | [diff] [blame] | 258 | if (pci_vfs_assigned(adapter->pdev)) { |
Alexander Duyck | 9297127 | 2012-05-23 02:58:40 +0000 | [diff] [blame] | 259 | e_dev_warn("Unloading driver while VFs are assigned - VFs will not be deallocated\n"); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 260 | return -EPERM; |
David S. Miller | d47e12d | 2012-07-22 12:36:41 -0700 | [diff] [blame] | 261 | } |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 262 | /* disable iov and allow time for transactions to clear */ |
| 263 | pci_disable_sriov(adapter->pdev); |
| 264 | #endif |
| 265 | |
| 266 | /* turn off device IOV mode */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 267 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, 0); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 268 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 269 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 270 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 271 | |
| 272 | /* set default pool back to 0 */ |
| 273 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 274 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
| 275 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
| 276 | IXGBE_WRITE_FLUSH(hw); |
| 277 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 278 | /* Disable VMDq flag so device will be set in VM mode */ |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 279 | if (adapter->ring_feature[RING_F_VMDQ].limit == 1) { |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 280 | adapter->flags &= ~IXGBE_FLAG_VMDQ_ENABLED; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 281 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 282 | rss = min_t(int, ixgbe_max_rss_indices(adapter), |
| 283 | num_online_cpus()); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 284 | } else { |
| 285 | rss = min_t(int, IXGBE_MAX_L2A_QUEUES, num_online_cpus()); |
| 286 | } |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 287 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 288 | adapter->ring_feature[RING_F_VMDQ].offset = 0; |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 289 | adapter->ring_feature[RING_F_RSS].limit = rss; |
| 290 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 291 | /* take a breather then clean up driver data */ |
| 292 | msleep(100); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | static int ixgbe_pci_sriov_enable(struct pci_dev *dev, int num_vfs) |
| 297 | { |
| 298 | #ifdef CONFIG_PCI_IOV |
| 299 | struct ixgbe_adapter *adapter = pci_get_drvdata(dev); |
| 300 | int err = 0; |
| 301 | int i; |
| 302 | int pre_existing_vfs = pci_num_vf(dev); |
| 303 | |
| 304 | if (pre_existing_vfs && pre_existing_vfs != num_vfs) |
| 305 | err = ixgbe_disable_sriov(adapter); |
| 306 | else if (pre_existing_vfs && pre_existing_vfs == num_vfs) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 307 | return num_vfs; |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 308 | |
| 309 | if (err) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 310 | return err; |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 311 | |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 312 | /* While the SR-IOV capability structure reports total VFs to be 64, |
| 313 | * we have to limit the actual number allocated based on two factors. |
| 314 | * First, we reserve some transmit/receive resources for the PF. |
| 315 | * Second, VMDQ also uses the same pools that SR-IOV does. We need to |
| 316 | * account for this, so that we don't accidentally allocate more VFs |
| 317 | * than we have available pools. The PCI bus driver already checks for |
| 318 | * other values out of range. |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 319 | */ |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 320 | if ((num_vfs + adapter->num_rx_pools) > IXGBE_MAX_VF_FUNCTIONS) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 321 | return -EPERM; |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 322 | |
| 323 | adapter->num_vfs = num_vfs; |
| 324 | |
| 325 | err = __ixgbe_enable_sriov(adapter); |
| 326 | if (err) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 327 | return err; |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 328 | |
| 329 | for (i = 0; i < adapter->num_vfs; i++) |
| 330 | ixgbe_vf_configuration(dev, (i | 0x10000000)); |
| 331 | |
Emil Tantilov | 0c339bf | 2016-09-09 12:59:10 -0700 | [diff] [blame] | 332 | /* reset before enabling SRIOV to avoid mailbox issues */ |
| 333 | ixgbe_sriov_reinit(adapter); |
| 334 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 335 | err = pci_enable_sriov(dev, num_vfs); |
| 336 | if (err) { |
| 337 | e_dev_warn("Failed to enable PCI sriov: %d\n", err); |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 338 | return err; |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 339 | } |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 340 | ixgbe_get_vfs(adapter); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 341 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 342 | return num_vfs; |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 343 | #else |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 344 | return 0; |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 345 | #endif |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static int ixgbe_pci_sriov_disable(struct pci_dev *dev) |
| 349 | { |
| 350 | struct ixgbe_adapter *adapter = pci_get_drvdata(dev); |
| 351 | int err; |
Don Skidmore | 8f48f5b | 2013-11-22 04:27:23 +0000 | [diff] [blame] | 352 | #ifdef CONFIG_PCI_IOV |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 353 | u32 current_flags = adapter->flags; |
Don Skidmore | 8f48f5b | 2013-11-22 04:27:23 +0000 | [diff] [blame] | 354 | #endif |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 355 | |
| 356 | err = ixgbe_disable_sriov(adapter); |
| 357 | |
| 358 | /* Only reinit if no error and state changed */ |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 359 | #ifdef CONFIG_PCI_IOV |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 360 | if (!err && current_flags != adapter->flags) |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 361 | ixgbe_sriov_reinit(adapter); |
| 362 | #endif |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 363 | |
| 364 | return err; |
| 365 | } |
| 366 | |
| 367 | int ixgbe_pci_sriov_configure(struct pci_dev *dev, int num_vfs) |
| 368 | { |
| 369 | if (num_vfs == 0) |
| 370 | return ixgbe_pci_sriov_disable(dev); |
| 371 | else |
| 372 | return ixgbe_pci_sriov_enable(dev, num_vfs); |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 375 | static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter, |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 376 | u32 *msgbuf, u32 vf) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 377 | { |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 378 | int entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) |
| 379 | >> IXGBE_VT_MSGINFO_SHIFT; |
| 380 | u16 *hash_list = (u16 *)&msgbuf[1]; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 381 | struct vf_data_storage *vfinfo = &adapter->vfinfo[vf]; |
Greg Rose | 8a07a22 | 2010-05-05 19:57:30 +0000 | [diff] [blame] | 382 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 383 | int i; |
Greg Rose | 8a07a22 | 2010-05-05 19:57:30 +0000 | [diff] [blame] | 384 | u32 vector_bit; |
| 385 | u32 vector_reg; |
| 386 | u32 mta_reg; |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 387 | u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf)); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 388 | |
| 389 | /* only so many hash values supported */ |
| 390 | entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES); |
| 391 | |
| 392 | /* |
| 393 | * salt away the number of multi cast addresses assigned |
| 394 | * to this VF for later use to restore when the PF multi cast |
| 395 | * list changes |
| 396 | */ |
| 397 | vfinfo->num_vf_mc_hashes = entries; |
| 398 | |
| 399 | /* |
| 400 | * VFs are limited to using the MTA hash table for their multicast |
| 401 | * addresses |
| 402 | */ |
| 403 | for (i = 0; i < entries; i++) { |
Joe Perches | e81a1ba | 2010-11-14 17:04:33 +0000 | [diff] [blame] | 404 | vfinfo->vf_mc_hashes[i] = hash_list[i]; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Greg Rose | 8a07a22 | 2010-05-05 19:57:30 +0000 | [diff] [blame] | 407 | for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) { |
| 408 | vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F; |
| 409 | vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F; |
| 410 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 411 | mta_reg |= BIT(vector_bit); |
Greg Rose | 8a07a22 | 2010-05-05 19:57:30 +0000 | [diff] [blame] | 412 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); |
| 413 | } |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 414 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 415 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 420 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 421 | void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter) |
| 422 | { |
| 423 | struct ixgbe_hw *hw = &adapter->hw; |
| 424 | struct vf_data_storage *vfinfo; |
| 425 | int i, j; |
| 426 | u32 vector_bit; |
| 427 | u32 vector_reg; |
| 428 | u32 mta_reg; |
| 429 | |
| 430 | for (i = 0; i < adapter->num_vfs; i++) { |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 431 | u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(i)); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 432 | vfinfo = &adapter->vfinfo[i]; |
| 433 | for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) { |
| 434 | hw->addr_ctrl.mta_in_use++; |
| 435 | vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F; |
| 436 | vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F; |
| 437 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 438 | mta_reg |= BIT(vector_bit); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 439 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); |
| 440 | } |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 441 | |
| 442 | if (vfinfo->num_vf_mc_hashes) |
| 443 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 444 | else |
| 445 | vmolr &= ~IXGBE_VMOLR_ROMPE; |
| 446 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(i), vmolr); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 447 | } |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 448 | |
| 449 | /* Restore any VF macvlans */ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 450 | ixgbe_full_sync_mac_table(adapter); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 451 | } |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 452 | #endif |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 453 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 454 | static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid, |
| 455 | u32 vf) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 456 | { |
Alexander Duyck | b6488b6 | 2015-11-02 17:10:01 -0800 | [diff] [blame] | 457 | struct ixgbe_hw *hw = &adapter->hw; |
| 458 | int err; |
| 459 | |
Alexander Duyck | b6488b6 | 2015-11-02 17:10:01 -0800 | [diff] [blame] | 460 | /* If VLAN overlaps with one the PF is currently monitoring make |
| 461 | * sure that we are able to allocate a VLVF entry. This may be |
| 462 | * redundant but it guarantees PF will maintain visibility to |
| 463 | * the VLAN. |
| 464 | */ |
| 465 | if (add && test_bit(vid, adapter->active_vlans)) { |
| 466 | err = hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), true, false); |
| 467 | if (err) |
| 468 | return err; |
| 469 | } |
| 470 | |
| 471 | err = hw->mac.ops.set_vfta(hw, vid, vf, !!add, false); |
| 472 | |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 473 | if (add && !err) |
| 474 | return err; |
| 475 | |
| 476 | /* If we failed to add the VF VLAN or we are removing the VF VLAN |
| 477 | * we may need to drop the PF pool bit in order to allow us to free |
| 478 | * up the VLVF resources. |
| 479 | */ |
| 480 | if (test_bit(vid, adapter->active_vlans) || |
| 481 | (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 482 | ixgbe_update_pf_promisc_vlvf(adapter, vid); |
| 483 | |
Alexander Duyck | b6488b6 | 2015-11-02 17:10:01 -0800 | [diff] [blame] | 484 | return err; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 487 | static s32 ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf) |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 488 | { |
| 489 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 490 | int max_frame = msgbuf[1]; |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 491 | u32 max_frs; |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 492 | |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 493 | /* |
| 494 | * For 82599EB we have to keep all PFs and VFs operating with |
| 495 | * the same max_frame value in order to avoid sending an oversize |
| 496 | * frame to a VF. In order to guarantee this is handled correctly |
| 497 | * for all cases we have several special exceptions to take into |
| 498 | * account before we can enable the VF for receive |
| 499 | */ |
| 500 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 501 | struct net_device *dev = adapter->netdev; |
| 502 | int pf_max_frame = dev->mtu + ETH_HLEN; |
| 503 | u32 reg_offset, vf_shift, vfre; |
| 504 | s32 err = 0; |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 505 | |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 506 | #ifdef CONFIG_FCOE |
| 507 | if (dev->features & NETIF_F_FCOE_MTU) |
| 508 | pf_max_frame = max_t(int, pf_max_frame, |
| 509 | IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 510 | |
| 511 | #endif /* CONFIG_FCOE */ |
Alexander Duyck | bffb3bc | 2012-07-20 08:09:37 +0000 | [diff] [blame] | 512 | switch (adapter->vfinfo[vf].vf_api) { |
| 513 | case ixgbe_mbox_api_11: |
Vlad Zolotarov | 4ce37a4 | 2015-04-01 11:24:54 +0300 | [diff] [blame] | 514 | case ixgbe_mbox_api_12: |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 515 | case ixgbe_mbox_api_13: |
Alexander Duyck | bffb3bc | 2012-07-20 08:09:37 +0000 | [diff] [blame] | 516 | /* |
| 517 | * Version 1.1 supports jumbo frames on VFs if PF has |
| 518 | * jumbo frames enabled which means legacy VFs are |
| 519 | * disabled |
| 520 | */ |
| 521 | if (pf_max_frame > ETH_FRAME_LEN) |
| 522 | break; |
| 523 | default: |
| 524 | /* |
| 525 | * If the PF or VF are running w/ jumbo frames enabled |
| 526 | * we need to shut down the VF Rx path as we cannot |
| 527 | * support jumbo frames on legacy VFs |
| 528 | */ |
| 529 | if ((pf_max_frame > ETH_FRAME_LEN) || |
| 530 | (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN))) |
| 531 | err = -EINVAL; |
| 532 | break; |
| 533 | } |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 534 | |
| 535 | /* determine VF receive enable location */ |
| 536 | vf_shift = vf % 32; |
| 537 | reg_offset = vf / 32; |
| 538 | |
| 539 | /* enable or disable receive depending on error */ |
| 540 | vfre = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset)); |
| 541 | if (err) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 542 | vfre &= ~BIT(vf_shift); |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 543 | else |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 544 | vfre |= BIT(vf_shift); |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 545 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), vfre); |
| 546 | |
| 547 | if (err) { |
| 548 | e_err(drv, "VF max_frame %d out of range\n", max_frame); |
| 549 | return err; |
| 550 | } |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 553 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 554 | if (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE) { |
| 555 | e_err(drv, "VF max_frame %d out of range\n", max_frame); |
| 556 | return -EINVAL; |
| 557 | } |
| 558 | |
| 559 | /* pull current max frame size from hardware */ |
| 560 | max_frs = IXGBE_READ_REG(hw, IXGBE_MAXFRS); |
| 561 | max_frs &= IXGBE_MHADD_MFS_MASK; |
| 562 | max_frs >>= IXGBE_MHADD_MFS_SHIFT; |
| 563 | |
| 564 | if (max_frs < max_frame) { |
| 565 | max_frs = max_frame << IXGBE_MHADD_MFS_SHIFT; |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 566 | IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs); |
| 567 | } |
| 568 | |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 569 | e_info(hw, "VF requests change max MTU to %d\n", max_frame); |
| 570 | |
| 571 | return 0; |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 574 | 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] | 575 | { |
| 576 | u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf)); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 577 | vmolr |= IXGBE_VMOLR_BAM; |
Greg Rose | f041277 | 2010-05-04 22:11:46 +0000 | [diff] [blame] | 578 | if (aupe) |
| 579 | vmolr |= IXGBE_VMOLR_AUPE; |
| 580 | else |
| 581 | vmolr &= ~IXGBE_VMOLR_AUPE; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 582 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr); |
| 583 | } |
| 584 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 585 | static void ixgbe_clear_vmvir(struct ixgbe_adapter *adapter, u32 vf) |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 586 | { |
| 587 | struct ixgbe_hw *hw = &adapter->hw; |
| 588 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 589 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0); |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 590 | } |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 591 | |
| 592 | static void ixgbe_clear_vf_vlans(struct ixgbe_adapter *adapter, u32 vf) |
| 593 | { |
| 594 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 595 | u32 vlvfb_mask, pool_mask, i; |
| 596 | |
| 597 | /* create mask for VF and other pools */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 598 | pool_mask = ~BIT(VMDQ_P(0) % 32); |
| 599 | vlvfb_mask = BIT(vf % 32); |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 600 | |
| 601 | /* post increment loop, covers VLVF_ENTRIES - 1 to 0 */ |
| 602 | for (i = IXGBE_VLVF_ENTRIES; i--;) { |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 603 | u32 bits[2], vlvfb, vid, vfta, vlvf; |
Alexander Duyck | ab3a3b7 | 2015-12-23 09:00:35 -0800 | [diff] [blame] | 604 | u32 word = i * 2 + vf / 32; |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 605 | u32 mask; |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 606 | |
Alexander Duyck | ab3a3b7 | 2015-12-23 09:00:35 -0800 | [diff] [blame] | 607 | vlvfb = IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 608 | |
| 609 | /* if our bit isn't set we can skip it */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 610 | if (!(vlvfb & vlvfb_mask)) |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 611 | continue; |
| 612 | |
| 613 | /* clear our bit from vlvfb */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 614 | vlvfb ^= vlvfb_mask; |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 615 | |
| 616 | /* create 64b mask to chedk to see if we should clear VLVF */ |
| 617 | bits[word % 2] = vlvfb; |
Alexander Duyck | ab3a3b7 | 2015-12-23 09:00:35 -0800 | [diff] [blame] | 618 | bits[~word % 2] = IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1)); |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 619 | |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 620 | /* if other pools are present, just remove ourselves */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 621 | if (bits[(VMDQ_P(0) / 32) ^ 1] || |
| 622 | (bits[VMDQ_P(0) / 32] & pool_mask)) |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 623 | goto update_vlvfb; |
| 624 | |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 625 | /* if PF is present, leave VFTA */ |
| 626 | if (bits[0] || bits[1]) |
| 627 | goto update_vlvf; |
| 628 | |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 629 | /* if we cannot determine VLAN just remove ourselves */ |
| 630 | vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i)); |
| 631 | if (!vlvf) |
| 632 | goto update_vlvfb; |
| 633 | |
| 634 | vid = vlvf & VLAN_VID_MASK; |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 635 | mask = BIT(vid % 32); |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 636 | |
| 637 | /* clear bit from VFTA */ |
| 638 | vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(vid / 32)); |
| 639 | if (vfta & mask) |
| 640 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(vid / 32), vfta ^ mask); |
| 641 | update_vlvf: |
| 642 | /* clear POOL selection enable */ |
| 643 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(i), 0); |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 644 | |
| 645 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 646 | vlvfb = 0; |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 647 | update_vlvfb: |
| 648 | /* clear pool bits */ |
| 649 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), vlvfb); |
| 650 | } |
| 651 | } |
| 652 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 653 | 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] | 654 | { |
| 655 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 656 | struct vf_data_storage *vfinfo = &adapter->vfinfo[vf]; |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 657 | u8 num_tcs = netdev_get_num_tc(adapter->netdev); |
| 658 | |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 659 | /* remove VLAN filters beloning to this VF */ |
| 660 | ixgbe_clear_vf_vlans(adapter, vf); |
| 661 | |
| 662 | /* add back PF assigned VLAN or VLAN 0 */ |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 663 | ixgbe_set_vf_vlan(adapter, true, vfinfo->pf_vlan, vf); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 664 | |
| 665 | /* reset offloads to defaults */ |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 666 | ixgbe_set_vmolr(hw, vf, !vfinfo->pf_vlan); |
| 667 | |
| 668 | /* set outgoing tags for VFs */ |
| 669 | if (!vfinfo->pf_vlan && !vfinfo->pf_qos && !num_tcs) { |
| 670 | ixgbe_clear_vmvir(adapter, vf); |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 671 | } else { |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 672 | if (vfinfo->pf_qos || !num_tcs) |
| 673 | ixgbe_set_vmvir(adapter, vfinfo->pf_vlan, |
| 674 | vfinfo->pf_qos, vf); |
| 675 | else |
| 676 | ixgbe_set_vmvir(adapter, vfinfo->pf_vlan, |
| 677 | adapter->default_up, vf); |
| 678 | |
| 679 | if (vfinfo->spoofchk_enabled) |
| 680 | hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf); |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 681 | } |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 682 | |
| 683 | /* reset multicast table array for vf */ |
| 684 | adapter->vfinfo[vf].num_vf_mc_hashes = 0; |
| 685 | |
| 686 | /* Flush and reset the mta with the new values */ |
| 687 | ixgbe_set_rx_mode(adapter->netdev); |
| 688 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 689 | ixgbe_del_mac_filter(adapter, adapter->vfinfo[vf].vf_mac_addresses, vf); |
Alexander Duyck | 374c65d | 2012-07-20 08:09:22 +0000 | [diff] [blame] | 690 | |
| 691 | /* reset VF api back to unknown */ |
| 692 | adapter->vfinfo[vf].vf_api = ixgbe_mbox_api_10; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 695 | static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter, |
| 696 | int vf, unsigned char *mac_addr) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 697 | { |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 698 | ixgbe_del_mac_filter(adapter, adapter->vfinfo[vf].vf_mac_addresses, vf); |
Joe Perches | d458cdf | 2013-10-01 19:04:40 -0700 | [diff] [blame] | 699 | memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, ETH_ALEN); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 700 | ixgbe_add_mac_filter(adapter, adapter->vfinfo[vf].vf_mac_addresses, vf); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 705 | static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter, |
| 706 | int vf, int index, unsigned char *mac_addr) |
| 707 | { |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 708 | struct list_head *pos; |
| 709 | struct vf_macvlans *entry; |
| 710 | |
| 711 | if (index <= 1) { |
| 712 | list_for_each(pos, &adapter->vf_mvs.l) { |
| 713 | entry = list_entry(pos, struct vf_macvlans, l); |
| 714 | if (entry->vf == vf) { |
| 715 | entry->vf = -1; |
| 716 | entry->free = true; |
| 717 | entry->is_macvlan = false; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 718 | ixgbe_del_mac_filter(adapter, |
| 719 | entry->vf_macvlan, vf); |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | /* |
| 725 | * If index was zero then we were asked to clear the uc list |
| 726 | * for the VF. We're done. |
| 727 | */ |
| 728 | if (!index) |
| 729 | return 0; |
| 730 | |
| 731 | entry = NULL; |
| 732 | |
| 733 | list_for_each(pos, &adapter->vf_mvs.l) { |
| 734 | entry = list_entry(pos, struct vf_macvlans, l); |
| 735 | if (entry->free) |
| 736 | break; |
| 737 | } |
| 738 | |
| 739 | /* |
| 740 | * If we traversed the entire list and didn't find a free entry |
| 741 | * then we're out of space on the RAR table. Also entry may |
| 742 | * be NULL because the original memory allocation for the list |
| 743 | * failed, which is not fatal but does mean we can't support |
| 744 | * VF requests for MACVLAN because we couldn't allocate |
| 745 | * memory for the list management required. |
| 746 | */ |
| 747 | if (!entry || !entry->free) |
| 748 | return -ENOSPC; |
| 749 | |
| 750 | entry->free = false; |
| 751 | entry->is_macvlan = true; |
| 752 | entry->vf = vf; |
| 753 | memcpy(entry->vf_macvlan, mac_addr, ETH_ALEN); |
| 754 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 755 | ixgbe_add_mac_filter(adapter, mac_addr, vf); |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 756 | |
| 757 | return 0; |
| 758 | } |
| 759 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 760 | int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask) |
| 761 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 762 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 763 | unsigned int vfn = (event_mask & 0x3f); |
| 764 | |
| 765 | bool enable = ((event_mask & 0x10000000U) != 0); |
| 766 | |
Joe Perches | d458cdf | 2013-10-01 19:04:40 -0700 | [diff] [blame] | 767 | if (enable) |
| 768 | eth_zero_addr(adapter->vfinfo[vfn].vf_mac_addresses); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 769 | |
| 770 | return 0; |
| 771 | } |
| 772 | |
Don Skidmore | 8d697e7 | 2014-11-05 04:52:09 +0000 | [diff] [blame] | 773 | static inline void ixgbe_write_qde(struct ixgbe_adapter *adapter, u32 vf, |
| 774 | u32 qde) |
| 775 | { |
| 776 | struct ixgbe_hw *hw = &adapter->hw; |
| 777 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 778 | u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 779 | int i; |
| 780 | |
| 781 | for (i = vf * q_per_pool; i < ((vf + 1) * q_per_pool); i++) { |
| 782 | u32 reg; |
| 783 | |
| 784 | /* flush previous write */ |
| 785 | IXGBE_WRITE_FLUSH(hw); |
| 786 | |
| 787 | /* indicate to hardware that we want to set drop enable */ |
| 788 | reg = IXGBE_QDE_WRITE | IXGBE_QDE_ENABLE; |
| 789 | reg |= i << IXGBE_QDE_IDX_SHIFT; |
| 790 | IXGBE_WRITE_REG(hw, IXGBE_QDE, reg); |
| 791 | } |
| 792 | } |
| 793 | |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 794 | static int ixgbe_vf_reset_msg(struct ixgbe_adapter *adapter, u32 vf) |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 795 | { |
Alexander Duyck | 8739737 | 2014-01-15 17:38:40 -0800 | [diff] [blame] | 796 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 797 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 798 | unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses; |
Emil Tantilov | b08e1ed | 2013-07-26 07:34:54 +0000 | [diff] [blame] | 799 | u32 reg, reg_offset, vf_shift; |
| 800 | u32 msgbuf[4] = {0, 0, 0, 0}; |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 801 | u8 *addr = (u8 *)(&msgbuf[1]); |
Alexander Duyck | 8739737 | 2014-01-15 17:38:40 -0800 | [diff] [blame] | 802 | u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 803 | int i; |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 804 | |
| 805 | e_info(probe, "VF Reset msg received from vf %d\n", vf); |
| 806 | |
| 807 | /* reset the filters for the device */ |
| 808 | ixgbe_vf_reset_event(adapter, vf); |
| 809 | |
| 810 | /* set vf mac address */ |
Greg Rose | 3505592 | 2013-02-15 05:20:09 +0000 | [diff] [blame] | 811 | if (!is_zero_ether_addr(vf_mac)) |
| 812 | ixgbe_set_vf_mac(adapter, vf, vf_mac); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 813 | |
| 814 | vf_shift = vf % 32; |
| 815 | reg_offset = vf / 32; |
| 816 | |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 817 | /* enable transmit for vf */ |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 818 | reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset)); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 819 | reg |= BIT(vf_shift); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 820 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg); |
| 821 | |
Alexander Duyck | 8739737 | 2014-01-15 17:38:40 -0800 | [diff] [blame] | 822 | /* force drop enable for all VF Rx queues */ |
Don Skidmore | 8d697e7 | 2014-11-05 04:52:09 +0000 | [diff] [blame] | 823 | ixgbe_write_qde(adapter, vf, IXGBE_QDE_ENABLE); |
Alexander Duyck | 8739737 | 2014-01-15 17:38:40 -0800 | [diff] [blame] | 824 | |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 825 | /* enable receive for vf */ |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 826 | reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset)); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 827 | reg |= BIT(vf_shift); |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 828 | /* |
| 829 | * The 82599 cannot support a mix of jumbo and non-jumbo PF/VFs. |
| 830 | * For more info take a look at ixgbe_set_vf_lpe |
| 831 | */ |
| 832 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 833 | struct net_device *dev = adapter->netdev; |
| 834 | int pf_max_frame = dev->mtu + ETH_HLEN; |
| 835 | |
| 836 | #ifdef CONFIG_FCOE |
| 837 | if (dev->features & NETIF_F_FCOE_MTU) |
| 838 | pf_max_frame = max_t(int, pf_max_frame, |
| 839 | IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 840 | |
| 841 | #endif /* CONFIG_FCOE */ |
| 842 | if (pf_max_frame > ETH_FRAME_LEN) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 843 | reg &= ~BIT(vf_shift); |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 844 | } |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 845 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg); |
| 846 | |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 847 | /* enable VF mailbox for further messages */ |
| 848 | adapter->vfinfo[vf].clear_to_send = true; |
| 849 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 850 | /* Enable counting of spoofed packets in the SSVPC register */ |
| 851 | reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset)); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 852 | reg |= BIT(vf_shift); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 853 | IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg); |
| 854 | |
Alexander Duyck | dbf231a | 2014-01-15 17:38:41 -0800 | [diff] [blame] | 855 | /* |
| 856 | * Reset the VFs TDWBAL and TDWBAH registers |
| 857 | * which are not cleared by an FLR |
| 858 | */ |
| 859 | for (i = 0; i < q_per_pool; i++) { |
| 860 | IXGBE_WRITE_REG(hw, IXGBE_PVFTDWBAHn(q_per_pool, vf, i), 0); |
| 861 | IXGBE_WRITE_REG(hw, IXGBE_PVFTDWBALn(q_per_pool, vf, i), 0); |
| 862 | } |
| 863 | |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 864 | /* reply to reset with ack and vf mac address */ |
Greg Rose | 3505592 | 2013-02-15 05:20:09 +0000 | [diff] [blame] | 865 | msgbuf[0] = IXGBE_VF_RESET; |
| 866 | if (!is_zero_ether_addr(vf_mac)) { |
| 867 | msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK; |
| 868 | memcpy(addr, vf_mac, ETH_ALEN); |
| 869 | } else { |
| 870 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; |
| 871 | dev_warn(&adapter->pdev->dev, |
| 872 | "VF %d has no MAC address assigned, you may have to assign one manually\n", |
| 873 | vf); |
| 874 | } |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 875 | |
| 876 | /* |
| 877 | * Piggyback the multicast filter type so VF can compute the |
| 878 | * correct vectors |
| 879 | */ |
| 880 | msgbuf[3] = hw->mac.mc_filter_type; |
| 881 | ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf); |
| 882 | |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | static int ixgbe_set_vf_mac_addr(struct ixgbe_adapter *adapter, |
| 887 | u32 *msgbuf, u32 vf) |
| 888 | { |
| 889 | u8 *new_mac = ((u8 *)(&msgbuf[1])); |
| 890 | |
| 891 | if (!is_valid_ether_addr(new_mac)) { |
| 892 | e_warn(drv, "VF %d attempted to set invalid mac\n", vf); |
| 893 | return -1; |
| 894 | } |
| 895 | |
chas williams | 1d96cf9 | 2016-01-05 17:30:39 -0500 | [diff] [blame] | 896 | if (adapter->vfinfo[vf].pf_set_mac && !adapter->vfinfo[vf].trusted && |
dingtianhong | 4012dda | 2013-12-30 15:40:50 +0800 | [diff] [blame] | 897 | !ether_addr_equal(adapter->vfinfo[vf].vf_mac_addresses, new_mac)) { |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 898 | e_warn(drv, |
| 899 | "VF %d attempted to override administratively set MAC address\n" |
| 900 | "Reload the VF driver to resume operations\n", |
| 901 | vf); |
| 902 | return -1; |
| 903 | } |
| 904 | |
Greg Rose | 3970c32 | 2012-09-25 02:25:30 +0000 | [diff] [blame] | 905 | return ixgbe_set_vf_mac(adapter, vf, new_mac) < 0; |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | static int ixgbe_set_vf_vlan_msg(struct ixgbe_adapter *adapter, |
| 909 | u32 *msgbuf, u32 vf) |
| 910 | { |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 911 | u32 add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> IXGBE_VT_MSGINFO_SHIFT; |
| 912 | u32 vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK); |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 913 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 914 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 915 | if (adapter->vfinfo[vf].pf_vlan || tcs) { |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 916 | e_warn(drv, |
| 917 | "VF %d attempted to override administratively set VLAN configuration\n" |
| 918 | "Reload the VF driver to resume operations\n", |
| 919 | vf); |
| 920 | return -1; |
| 921 | } |
| 922 | |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 923 | /* VLAN 0 is a special case, don't allow it to be removed */ |
| 924 | if (!vid && !add) |
| 925 | return 0; |
| 926 | |
Emil Tantilov | d3dec7c | 2016-03-18 16:11:19 -0700 | [diff] [blame] | 927 | return ixgbe_set_vf_vlan(adapter, add, vid, vf); |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | static int ixgbe_set_vf_macvlan_msg(struct ixgbe_adapter *adapter, |
| 931 | u32 *msgbuf, u32 vf) |
| 932 | { |
| 933 | u8 *new_mac = ((u8 *)(&msgbuf[1])); |
| 934 | int index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> |
| 935 | IXGBE_VT_MSGINFO_SHIFT; |
| 936 | int err; |
| 937 | |
Ken Cox | a9d2d53 | 2016-11-15 13:00:37 -0600 | [diff] [blame] | 938 | if (adapter->vfinfo[vf].pf_set_mac && !adapter->vfinfo[vf].trusted && |
| 939 | index > 0) { |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 940 | e_warn(drv, |
| 941 | "VF %d requested MACVLAN filter but is administratively denied\n", |
| 942 | vf); |
| 943 | return -1; |
| 944 | } |
| 945 | |
| 946 | /* An non-zero index indicates the VF is setting a filter */ |
| 947 | if (index) { |
| 948 | if (!is_valid_ether_addr(new_mac)) { |
| 949 | e_warn(drv, "VF %d attempted to set invalid mac\n", vf); |
| 950 | return -1; |
| 951 | } |
| 952 | |
| 953 | /* |
| 954 | * If the VF is allowed to set MAC filters then turn off |
| 955 | * anti-spoofing to avoid false positives. |
| 956 | */ |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 957 | if (adapter->vfinfo[vf].spoofchk_enabled) { |
| 958 | struct ixgbe_hw *hw = &adapter->hw; |
| 959 | |
| 960 | hw->mac.ops.set_mac_anti_spoofing(hw, false, vf); |
Emil Tantilov | 581e0c7 | 2016-06-01 18:59:44 -0700 | [diff] [blame] | 961 | hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf); |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 962 | } |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | err = ixgbe_set_vf_macvlan(adapter, vf, index, new_mac); |
| 966 | if (err == -ENOSPC) |
| 967 | e_warn(drv, |
| 968 | "VF %d has requested a MACVLAN filter but there is no space for it\n", |
| 969 | vf); |
Greg Rose | a301340 | 2012-10-30 00:40:02 +0000 | [diff] [blame] | 970 | |
| 971 | return err < 0; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Alexander Duyck | 374c65d | 2012-07-20 08:09:22 +0000 | [diff] [blame] | 974 | static int ixgbe_negotiate_vf_api(struct ixgbe_adapter *adapter, |
| 975 | u32 *msgbuf, u32 vf) |
| 976 | { |
| 977 | int api = msgbuf[1]; |
| 978 | |
| 979 | switch (api) { |
| 980 | case ixgbe_mbox_api_10: |
Alexander Duyck | bffb3bc | 2012-07-20 08:09:37 +0000 | [diff] [blame] | 981 | case ixgbe_mbox_api_11: |
Vlad Zolotarov | 4ce37a4 | 2015-04-01 11:24:54 +0300 | [diff] [blame] | 982 | case ixgbe_mbox_api_12: |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 983 | case ixgbe_mbox_api_13: |
Alexander Duyck | 374c65d | 2012-07-20 08:09:22 +0000 | [diff] [blame] | 984 | adapter->vfinfo[vf].vf_api = api; |
| 985 | return 0; |
| 986 | default: |
| 987 | break; |
| 988 | } |
| 989 | |
| 990 | e_info(drv, "VF %d requested invalid api version %u\n", vf, api); |
| 991 | |
| 992 | return -1; |
| 993 | } |
| 994 | |
Alexander Duyck | f591cd9 | 2012-07-20 08:09:32 +0000 | [diff] [blame] | 995 | static int ixgbe_get_vf_queues(struct ixgbe_adapter *adapter, |
| 996 | u32 *msgbuf, u32 vf) |
| 997 | { |
| 998 | struct net_device *dev = adapter->netdev; |
| 999 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 1000 | unsigned int default_tc = 0; |
| 1001 | u8 num_tcs = netdev_get_num_tc(dev); |
| 1002 | |
| 1003 | /* verify the PF is supporting the correct APIs */ |
| 1004 | switch (adapter->vfinfo[vf].vf_api) { |
| 1005 | case ixgbe_mbox_api_20: |
| 1006 | case ixgbe_mbox_api_11: |
Vlad Zolotarov | 4ce37a4 | 2015-04-01 11:24:54 +0300 | [diff] [blame] | 1007 | case ixgbe_mbox_api_12: |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1008 | case ixgbe_mbox_api_13: |
Alexander Duyck | f591cd9 | 2012-07-20 08:09:32 +0000 | [diff] [blame] | 1009 | break; |
| 1010 | default: |
| 1011 | return -1; |
| 1012 | } |
| 1013 | |
| 1014 | /* only allow 1 Tx queue for bandwidth limiting */ |
| 1015 | msgbuf[IXGBE_VF_TX_QUEUES] = __ALIGN_MASK(1, ~vmdq->mask); |
| 1016 | msgbuf[IXGBE_VF_RX_QUEUES] = __ALIGN_MASK(1, ~vmdq->mask); |
| 1017 | |
| 1018 | /* if TCs > 1 determine which TC belongs to default user priority */ |
| 1019 | if (num_tcs > 1) |
| 1020 | default_tc = netdev_get_prio_tc_map(dev, adapter->default_up); |
| 1021 | |
| 1022 | /* notify VF of need for VLAN tag stripping, and correct queue */ |
| 1023 | if (num_tcs) |
| 1024 | msgbuf[IXGBE_VF_TRANS_VLAN] = num_tcs; |
| 1025 | else if (adapter->vfinfo[vf].pf_vlan || adapter->vfinfo[vf].pf_qos) |
| 1026 | msgbuf[IXGBE_VF_TRANS_VLAN] = 1; |
| 1027 | else |
| 1028 | msgbuf[IXGBE_VF_TRANS_VLAN] = 0; |
| 1029 | |
| 1030 | /* notify VF of default queue */ |
| 1031 | msgbuf[IXGBE_VF_DEF_QUEUE] = default_tc; |
| 1032 | |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
Vlad Zolotarov | 4ce37a4 | 2015-04-01 11:24:54 +0300 | [diff] [blame] | 1036 | static int ixgbe_get_vf_reta(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf) |
| 1037 | { |
| 1038 | u32 i, j; |
| 1039 | u32 *out_buf = &msgbuf[1]; |
| 1040 | const u8 *reta = adapter->rss_indir_tbl; |
| 1041 | u32 reta_size = ixgbe_rss_indir_tbl_entries(adapter); |
| 1042 | |
| 1043 | /* Check if operation is permitted */ |
| 1044 | if (!adapter->vfinfo[vf].rss_query_enabled) |
| 1045 | return -EPERM; |
| 1046 | |
| 1047 | /* verify the PF is supporting the correct API */ |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1048 | switch (adapter->vfinfo[vf].vf_api) { |
| 1049 | case ixgbe_mbox_api_13: |
| 1050 | case ixgbe_mbox_api_12: |
| 1051 | break; |
| 1052 | default: |
Vlad Zolotarov | 4ce37a4 | 2015-04-01 11:24:54 +0300 | [diff] [blame] | 1053 | return -EOPNOTSUPP; |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1054 | } |
Vlad Zolotarov | 4ce37a4 | 2015-04-01 11:24:54 +0300 | [diff] [blame] | 1055 | |
| 1056 | /* This mailbox command is supported (required) only for 82599 and x540 |
| 1057 | * VFs which support up to 4 RSS queues. Therefore we will compress the |
| 1058 | * RETA by saving only 2 bits from each entry. This way we will be able |
| 1059 | * to transfer the whole RETA in a single mailbox operation. |
| 1060 | */ |
| 1061 | for (i = 0; i < reta_size / 16; i++) { |
| 1062 | out_buf[i] = 0; |
| 1063 | for (j = 0; j < 16; j++) |
| 1064 | out_buf[i] |= (u32)(reta[16 * i + j] & 0x3) << (2 * j); |
| 1065 | } |
| 1066 | |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
Vlad Zolotarov | 3c0841a | 2015-03-30 21:35:27 +0300 | [diff] [blame] | 1070 | static int ixgbe_get_vf_rss_key(struct ixgbe_adapter *adapter, |
| 1071 | u32 *msgbuf, u32 vf) |
| 1072 | { |
| 1073 | u32 *rss_key = &msgbuf[1]; |
| 1074 | |
| 1075 | /* Check if the operation is permitted */ |
| 1076 | if (!adapter->vfinfo[vf].rss_query_enabled) |
| 1077 | return -EPERM; |
| 1078 | |
| 1079 | /* verify the PF is supporting the correct API */ |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1080 | switch (adapter->vfinfo[vf].vf_api) { |
| 1081 | case ixgbe_mbox_api_13: |
| 1082 | case ixgbe_mbox_api_12: |
| 1083 | break; |
| 1084 | default: |
Vlad Zolotarov | 3c0841a | 2015-03-30 21:35:27 +0300 | [diff] [blame] | 1085 | return -EOPNOTSUPP; |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1086 | } |
Vlad Zolotarov | 3c0841a | 2015-03-30 21:35:27 +0300 | [diff] [blame] | 1087 | |
| 1088 | memcpy(rss_key, adapter->rss_key, sizeof(adapter->rss_key)); |
| 1089 | |
| 1090 | return 0; |
| 1091 | } |
| 1092 | |
Hiroshi Shimamoto | 8443c1a4 | 2015-08-28 06:59:03 +0000 | [diff] [blame] | 1093 | static int ixgbe_update_vf_xcast_mode(struct ixgbe_adapter *adapter, |
| 1094 | u32 *msgbuf, u32 vf) |
| 1095 | { |
| 1096 | struct ixgbe_hw *hw = &adapter->hw; |
| 1097 | int xcast_mode = msgbuf[1]; |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1098 | u32 vmolr, fctrl, disable, enable; |
Hiroshi Shimamoto | 8443c1a4 | 2015-08-28 06:59:03 +0000 | [diff] [blame] | 1099 | |
| 1100 | /* verify the PF is supporting the correct APIs */ |
| 1101 | switch (adapter->vfinfo[vf].vf_api) { |
| 1102 | case ixgbe_mbox_api_12: |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1103 | /* promisc introduced in 1.3 version */ |
| 1104 | if (xcast_mode == IXGBEVF_XCAST_MODE_PROMISC) |
| 1105 | return -EOPNOTSUPP; |
| 1106 | /* Fall threw */ |
| 1107 | case ixgbe_mbox_api_13: |
Hiroshi Shimamoto | 8443c1a4 | 2015-08-28 06:59:03 +0000 | [diff] [blame] | 1108 | break; |
| 1109 | default: |
| 1110 | return -EOPNOTSUPP; |
| 1111 | } |
| 1112 | |
| 1113 | if (xcast_mode > IXGBEVF_XCAST_MODE_MULTI && |
| 1114 | !adapter->vfinfo[vf].trusted) { |
| 1115 | xcast_mode = IXGBEVF_XCAST_MODE_MULTI; |
| 1116 | } |
| 1117 | |
| 1118 | if (adapter->vfinfo[vf].xcast_mode == xcast_mode) |
| 1119 | goto out; |
| 1120 | |
| 1121 | switch (xcast_mode) { |
| 1122 | case IXGBEVF_XCAST_MODE_NONE: |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1123 | disable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE | |
| 1124 | IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE; |
Hiroshi Shimamoto | 8443c1a4 | 2015-08-28 06:59:03 +0000 | [diff] [blame] | 1125 | enable = 0; |
| 1126 | break; |
| 1127 | case IXGBEVF_XCAST_MODE_MULTI: |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1128 | disable = IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE; |
Hiroshi Shimamoto | 8443c1a4 | 2015-08-28 06:59:03 +0000 | [diff] [blame] | 1129 | enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE; |
| 1130 | break; |
| 1131 | case IXGBEVF_XCAST_MODE_ALLMULTI: |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1132 | disable = IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE; |
Hiroshi Shimamoto | 8443c1a4 | 2015-08-28 06:59:03 +0000 | [diff] [blame] | 1133 | enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_MPE; |
| 1134 | break; |
Don Skidmore | 07eea57 | 2016-12-15 21:18:32 -0500 | [diff] [blame] | 1135 | case IXGBEVF_XCAST_MODE_PROMISC: |
| 1136 | if (hw->mac.type <= ixgbe_mac_82599EB) |
| 1137 | return -EOPNOTSUPP; |
| 1138 | |
| 1139 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 1140 | if (!(fctrl & IXGBE_FCTRL_UPE)) { |
| 1141 | /* VF promisc requires PF in promisc */ |
| 1142 | e_warn(drv, |
| 1143 | "Enabling VF promisc requires PF in promisc\n"); |
| 1144 | return -EPERM; |
| 1145 | } |
| 1146 | |
| 1147 | disable = 0; |
| 1148 | enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE | |
| 1149 | IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE; |
| 1150 | break; |
Hiroshi Shimamoto | 8443c1a4 | 2015-08-28 06:59:03 +0000 | [diff] [blame] | 1151 | default: |
| 1152 | return -EOPNOTSUPP; |
| 1153 | } |
| 1154 | |
| 1155 | vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf)); |
| 1156 | vmolr &= ~disable; |
| 1157 | vmolr |= enable; |
| 1158 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr); |
| 1159 | |
| 1160 | adapter->vfinfo[vf].xcast_mode = xcast_mode; |
| 1161 | |
| 1162 | out: |
| 1163 | msgbuf[1] = xcast_mode; |
| 1164 | |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1168 | static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf) |
| 1169 | { |
| 1170 | u32 mbx_size = IXGBE_VFMAILBOX_SIZE; |
Emil Tantilov | c050999 | 2011-05-07 06:49:18 +0000 | [diff] [blame] | 1171 | u32 msgbuf[IXGBE_VFMAILBOX_SIZE]; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1172 | struct ixgbe_hw *hw = &adapter->hw; |
| 1173 | s32 retval; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1174 | |
| 1175 | retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf); |
| 1176 | |
Alexander Duyck | dcaccc8 | 2012-03-28 08:03:38 +0000 | [diff] [blame] | 1177 | if (retval) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 1178 | pr_err("Error receiving message from VF\n"); |
Alexander Duyck | dcaccc8 | 2012-03-28 08:03:38 +0000 | [diff] [blame] | 1179 | return retval; |
| 1180 | } |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1181 | |
| 1182 | /* this is a message we already processed, do nothing */ |
| 1183 | if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1184 | return 0; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1185 | |
Alexander Duyck | dcaccc8 | 2012-03-28 08:03:38 +0000 | [diff] [blame] | 1186 | /* flush the ack before we write any messages back */ |
| 1187 | IXGBE_WRITE_FLUSH(hw); |
| 1188 | |
Alexander Duyck | 374c65d | 2012-07-20 08:09:22 +0000 | [diff] [blame] | 1189 | if (msgbuf[0] == IXGBE_VF_RESET) |
| 1190 | return ixgbe_vf_reset_msg(adapter, vf); |
| 1191 | |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1192 | /* |
| 1193 | * until the vf completes a virtual function reset it should not be |
| 1194 | * allowed to start any configuration. |
| 1195 | */ |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1196 | if (!adapter->vfinfo[vf].clear_to_send) { |
| 1197 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; |
| 1198 | ixgbe_write_mbx(hw, msgbuf, 1, vf); |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1199 | return 0; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | switch ((msgbuf[0] & 0xFFFF)) { |
| 1203 | case IXGBE_VF_SET_MAC_ADDR: |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 1204 | retval = ixgbe_set_vf_mac_addr(adapter, msgbuf, vf); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1205 | break; |
| 1206 | case IXGBE_VF_SET_MULTICAST: |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 1207 | retval = ixgbe_set_vf_multicasts(adapter, msgbuf, vf); |
| 1208 | break; |
| 1209 | case IXGBE_VF_SET_VLAN: |
| 1210 | retval = ixgbe_set_vf_vlan_msg(adapter, msgbuf, vf); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1211 | break; |
| 1212 | case IXGBE_VF_SET_LPE: |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 1213 | retval = ixgbe_set_vf_lpe(adapter, msgbuf, vf); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1214 | break; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 1215 | case IXGBE_VF_SET_MACVLAN: |
Alexander Duyck | 58a02be | 2012-07-20 08:09:17 +0000 | [diff] [blame] | 1216 | retval = ixgbe_set_vf_macvlan_msg(adapter, msgbuf, vf); |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 1217 | break; |
Alexander Duyck | 374c65d | 2012-07-20 08:09:22 +0000 | [diff] [blame] | 1218 | case IXGBE_VF_API_NEGOTIATE: |
| 1219 | retval = ixgbe_negotiate_vf_api(adapter, msgbuf, vf); |
| 1220 | break; |
Alexander Duyck | f591cd9 | 2012-07-20 08:09:32 +0000 | [diff] [blame] | 1221 | case IXGBE_VF_GET_QUEUES: |
| 1222 | retval = ixgbe_get_vf_queues(adapter, msgbuf, vf); |
| 1223 | break; |
Vlad Zolotarov | 4ce37a4 | 2015-04-01 11:24:54 +0300 | [diff] [blame] | 1224 | case IXGBE_VF_GET_RETA: |
| 1225 | retval = ixgbe_get_vf_reta(adapter, msgbuf, vf); |
| 1226 | break; |
Vlad Zolotarov | 3c0841a | 2015-03-30 21:35:27 +0300 | [diff] [blame] | 1227 | case IXGBE_VF_GET_RSS_KEY: |
| 1228 | retval = ixgbe_get_vf_rss_key(adapter, msgbuf, vf); |
| 1229 | break; |
Hiroshi Shimamoto | 8443c1a4 | 2015-08-28 06:59:03 +0000 | [diff] [blame] | 1230 | case IXGBE_VF_UPDATE_XCAST_MODE: |
| 1231 | retval = ixgbe_update_vf_xcast_mode(adapter, msgbuf, vf); |
| 1232 | break; |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1233 | default: |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 1234 | e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1235 | retval = IXGBE_ERR_MBX; |
| 1236 | break; |
| 1237 | } |
| 1238 | |
| 1239 | /* notify the VF of the results of what it sent us */ |
| 1240 | if (retval) |
| 1241 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; |
| 1242 | else |
| 1243 | msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK; |
| 1244 | |
| 1245 | msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS; |
| 1246 | |
Alexander Duyck | 374c65d | 2012-07-20 08:09:22 +0000 | [diff] [blame] | 1247 | ixgbe_write_mbx(hw, msgbuf, mbx_size, vf); |
Greg Rose | 1736727 | 2010-01-09 02:25:48 +0000 | [diff] [blame] | 1248 | |
| 1249 | return retval; |
| 1250 | } |
| 1251 | |
| 1252 | static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf) |
| 1253 | { |
| 1254 | struct ixgbe_hw *hw = &adapter->hw; |
| 1255 | u32 msg = IXGBE_VT_MSGTYPE_NACK; |
| 1256 | |
| 1257 | /* if device isn't clear to send it shouldn't be reading either */ |
| 1258 | if (!adapter->vfinfo[vf].clear_to_send) |
| 1259 | ixgbe_write_mbx(hw, &msg, 1, vf); |
| 1260 | } |
| 1261 | |
| 1262 | void ixgbe_msg_task(struct ixgbe_adapter *adapter) |
| 1263 | { |
| 1264 | struct ixgbe_hw *hw = &adapter->hw; |
| 1265 | u32 vf; |
| 1266 | |
| 1267 | for (vf = 0; vf < adapter->num_vfs; vf++) { |
| 1268 | /* process any reset requests */ |
| 1269 | if (!ixgbe_check_for_rst(hw, vf)) |
| 1270 | ixgbe_vf_reset_event(adapter, vf); |
| 1271 | |
| 1272 | /* process any messages pending */ |
| 1273 | if (!ixgbe_check_for_msg(hw, vf)) |
| 1274 | ixgbe_rcv_msg_from_vf(adapter, vf); |
| 1275 | |
| 1276 | /* process any acks */ |
| 1277 | if (!ixgbe_check_for_ack(hw, vf)) |
| 1278 | ixgbe_rcv_ack_from_vf(adapter, vf); |
| 1279 | } |
| 1280 | } |
| 1281 | |
Greg Rose | 767081a | 2010-01-22 22:46:40 +0000 | [diff] [blame] | 1282 | void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter) |
| 1283 | { |
| 1284 | struct ixgbe_hw *hw = &adapter->hw; |
| 1285 | |
| 1286 | /* disable transmit and receive for all vfs */ |
| 1287 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0); |
| 1288 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0); |
| 1289 | |
| 1290 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0); |
| 1291 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0); |
| 1292 | } |
| 1293 | |
Hiroshi Shimamoto | 54011e4 | 2015-08-28 06:58:33 +0000 | [diff] [blame] | 1294 | static inline void ixgbe_ping_vf(struct ixgbe_adapter *adapter, int vf) |
| 1295 | { |
| 1296 | struct ixgbe_hw *hw = &adapter->hw; |
| 1297 | u32 ping; |
| 1298 | |
| 1299 | ping = IXGBE_PF_CONTROL_MSG; |
| 1300 | if (adapter->vfinfo[vf].clear_to_send) |
| 1301 | ping |= IXGBE_VT_MSGTYPE_CTS; |
| 1302 | ixgbe_write_mbx(hw, &ping, 1, vf); |
| 1303 | } |
| 1304 | |
Greg Rose | 767081a | 2010-01-22 22:46:40 +0000 | [diff] [blame] | 1305 | void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter) |
| 1306 | { |
| 1307 | struct ixgbe_hw *hw = &adapter->hw; |
| 1308 | u32 ping; |
| 1309 | int i; |
| 1310 | |
| 1311 | for (i = 0 ; i < adapter->num_vfs; i++) { |
| 1312 | ping = IXGBE_PF_CONTROL_MSG; |
| 1313 | if (adapter->vfinfo[i].clear_to_send) |
| 1314 | ping |= IXGBE_VT_MSGTYPE_CTS; |
| 1315 | ixgbe_write_mbx(hw, &ping, 1, i); |
| 1316 | } |
| 1317 | } |
| 1318 | |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1319 | int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 1320 | { |
| 1321 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1322 | if (!is_valid_ether_addr(mac) || (vf >= adapter->num_vfs)) |
| 1323 | return -EINVAL; |
| 1324 | adapter->vfinfo[vf].pf_set_mac = true; |
| 1325 | dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf); |
| 1326 | dev_info(&adapter->pdev->dev, "Reload the VF driver to make this" |
| 1327 | " change effective."); |
| 1328 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1329 | dev_warn(&adapter->pdev->dev, "The VF MAC address has been set," |
| 1330 | " but the PF device is not up.\n"); |
| 1331 | dev_warn(&adapter->pdev->dev, "Bring the PF device up before" |
| 1332 | " attempting to use the VF device.\n"); |
| 1333 | } |
| 1334 | return ixgbe_set_vf_mac(adapter, vf, mac); |
| 1335 | } |
| 1336 | |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1337 | static int ixgbe_enable_port_vlan(struct ixgbe_adapter *adapter, int vf, |
| 1338 | u16 vlan, u8 qos) |
| 1339 | { |
| 1340 | struct ixgbe_hw *hw = &adapter->hw; |
Emil Tantilov | 42ce2c8 | 2014-12-10 05:28:51 +0000 | [diff] [blame] | 1341 | int err; |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1342 | |
Emil Tantilov | 42ce2c8 | 2014-12-10 05:28:51 +0000 | [diff] [blame] | 1343 | err = ixgbe_set_vf_vlan(adapter, true, vlan, vf); |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1344 | if (err) |
| 1345 | goto out; |
Emil Tantilov | 42ce2c8 | 2014-12-10 05:28:51 +0000 | [diff] [blame] | 1346 | |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 1347 | /* Revoke tagless access via VLAN 0 */ |
| 1348 | ixgbe_set_vf_vlan(adapter, false, 0, vf); |
| 1349 | |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1350 | ixgbe_set_vmvir(adapter, vlan, qos, vf); |
| 1351 | ixgbe_set_vmolr(hw, vf, false); |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 1352 | |
| 1353 | /* enable hide vlan on X550 */ |
| 1354 | if (hw->mac.type >= ixgbe_mac_X550) |
| 1355 | ixgbe_write_qde(adapter, vf, IXGBE_QDE_ENABLE | |
| 1356 | IXGBE_QDE_HIDE_VLAN); |
| 1357 | |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1358 | adapter->vfinfo[vf].pf_vlan = vlan; |
| 1359 | adapter->vfinfo[vf].pf_qos = qos; |
| 1360 | dev_info(&adapter->pdev->dev, |
| 1361 | "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf); |
| 1362 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1363 | dev_warn(&adapter->pdev->dev, |
| 1364 | "The VF VLAN has been set, but the PF device is not up.\n"); |
| 1365 | dev_warn(&adapter->pdev->dev, |
| 1366 | "Bring the PF device up before attempting to use the VF device.\n"); |
| 1367 | } |
| 1368 | |
| 1369 | out: |
| 1370 | return err; |
| 1371 | } |
| 1372 | |
| 1373 | static int ixgbe_disable_port_vlan(struct ixgbe_adapter *adapter, int vf) |
| 1374 | { |
| 1375 | struct ixgbe_hw *hw = &adapter->hw; |
| 1376 | int err; |
| 1377 | |
| 1378 | err = ixgbe_set_vf_vlan(adapter, false, |
| 1379 | adapter->vfinfo[vf].pf_vlan, vf); |
Alexander Duyck | 4c7f35f | 2015-11-02 17:10:32 -0800 | [diff] [blame] | 1380 | /* Restore tagless access via VLAN 0 */ |
| 1381 | ixgbe_set_vf_vlan(adapter, true, 0, vf); |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1382 | ixgbe_clear_vmvir(adapter, vf); |
| 1383 | ixgbe_set_vmolr(hw, vf, true); |
Emil Tantilov | 42ce2c8 | 2014-12-10 05:28:51 +0000 | [diff] [blame] | 1384 | |
| 1385 | /* disable hide VLAN on X550 */ |
| 1386 | if (hw->mac.type >= ixgbe_mac_X550) |
| 1387 | ixgbe_write_qde(adapter, vf, IXGBE_QDE_ENABLE); |
| 1388 | |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1389 | adapter->vfinfo[vf].pf_vlan = 0; |
| 1390 | adapter->vfinfo[vf].pf_qos = 0; |
| 1391 | |
| 1392 | return err; |
| 1393 | } |
| 1394 | |
Moshe Shemesh | 79aab09 | 2016-09-22 12:11:15 +0300 | [diff] [blame] | 1395 | int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, |
| 1396 | u8 qos, __be16 vlan_proto) |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1397 | { |
| 1398 | int err = 0; |
| 1399 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1400 | |
| 1401 | if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7)) |
| 1402 | return -EINVAL; |
Moshe Shemesh | 79aab09 | 2016-09-22 12:11:15 +0300 | [diff] [blame] | 1403 | if (vlan_proto != htons(ETH_P_8021Q)) |
| 1404 | return -EPROTONOSUPPORT; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1405 | if (vlan || qos) { |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1406 | /* Check if there is already a port VLAN set, if so |
| 1407 | * we have to delete the old one first before we |
| 1408 | * can set the new one. The usage model had |
| 1409 | * previously assumed the user would delete the |
| 1410 | * old port VLAN before setting a new one but this |
| 1411 | * is not necessarily the case. |
| 1412 | */ |
Greg Rose | 026ac67 | 2013-04-17 20:41:35 +0000 | [diff] [blame] | 1413 | if (adapter->vfinfo[vf].pf_vlan) |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1414 | err = ixgbe_disable_port_vlan(adapter, vf); |
Greg Rose | 026ac67 | 2013-04-17 20:41:35 +0000 | [diff] [blame] | 1415 | if (err) |
| 1416 | goto out; |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1417 | err = ixgbe_enable_port_vlan(adapter, vf, vlan, qos); |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1418 | } else { |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1419 | err = ixgbe_disable_port_vlan(adapter, vf); |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1420 | } |
Don Skidmore | 2b509c0 | 2014-11-01 01:06:57 +0000 | [diff] [blame] | 1421 | |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1422 | out: |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1423 | return err; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 1426 | int ixgbe_link_mbps(struct ixgbe_adapter *adapter) |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1427 | { |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1428 | switch (adapter->link_speed) { |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1429 | case IXGBE_LINK_SPEED_100_FULL: |
| 1430 | return 100; |
| 1431 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 1432 | return 1000; |
| 1433 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 1434 | return 10000; |
| 1435 | default: |
| 1436 | return 0; |
| 1437 | } |
| 1438 | } |
| 1439 | |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1440 | static void ixgbe_set_vf_rate_limit(struct ixgbe_adapter *adapter, int vf) |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1441 | { |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1442 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 1443 | struct ixgbe_hw *hw = &adapter->hw; |
| 1444 | u32 bcnrc_val = 0; |
| 1445 | u16 queue, queues_per_pool; |
| 1446 | u16 tx_rate = adapter->vfinfo[vf].tx_rate; |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1447 | |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1448 | if (tx_rate) { |
| 1449 | /* start with base link speed value */ |
| 1450 | bcnrc_val = adapter->vf_rate_link_speed; |
| 1451 | |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1452 | /* Calculate the rate factor values to set */ |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1453 | bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT; |
| 1454 | bcnrc_val /= tx_rate; |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1455 | |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1456 | /* clear everything but the rate factor */ |
| 1457 | bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK | |
| 1458 | IXGBE_RTTBCNRC_RF_DEC_MASK; |
| 1459 | |
| 1460 | /* enable the rate scheduler */ |
| 1461 | bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA; |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Lior Levy | 7555e83 | 2011-06-25 00:09:08 -0700 | [diff] [blame] | 1464 | /* |
| 1465 | * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM |
| 1466 | * register. Typically MMW_SIZE=0x014 if 9728-byte jumbo is supported |
| 1467 | * and 0x004 otherwise. |
| 1468 | */ |
| 1469 | switch (hw->mac.type) { |
| 1470 | case ixgbe_mac_82599EB: |
| 1471 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x4); |
| 1472 | break; |
| 1473 | case ixgbe_mac_X540: |
| 1474 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x14); |
| 1475 | break; |
| 1476 | default: |
| 1477 | break; |
| 1478 | } |
| 1479 | |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1480 | /* determine how many queues per pool based on VMDq mask */ |
| 1481 | queues_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 1482 | |
| 1483 | /* write value for all Tx queues belonging to VF */ |
| 1484 | for (queue = 0; queue < queues_per_pool; queue++) { |
| 1485 | unsigned int reg_idx = (vf * queues_per_pool) + queue; |
| 1486 | |
| 1487 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, reg_idx); |
| 1488 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
| 1489 | } |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter) |
| 1493 | { |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1494 | int i; |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1495 | |
| 1496 | /* VF Tx rate limit was not set */ |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1497 | if (!adapter->vf_rate_link_speed) |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1498 | return; |
| 1499 | |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1500 | if (ixgbe_link_mbps(adapter) != adapter->vf_rate_link_speed) { |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1501 | adapter->vf_rate_link_speed = 0; |
| 1502 | dev_info(&adapter->pdev->dev, |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1503 | "Link speed has been changed. VF Transmit rate is disabled\n"); |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | for (i = 0; i < adapter->num_vfs; i++) { |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1507 | if (!adapter->vf_rate_link_speed) |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1508 | adapter->vfinfo[i].tx_rate = 0; |
| 1509 | |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1510 | ixgbe_set_vf_rate_limit(adapter, i); |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1511 | } |
| 1512 | } |
| 1513 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1514 | int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int min_tx_rate, |
| 1515 | int max_tx_rate) |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1516 | { |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1517 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1518 | int link_speed; |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1519 | |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1520 | /* verify VF is active */ |
| 1521 | if (vf >= adapter->num_vfs) |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1522 | return -EINVAL; |
| 1523 | |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1524 | /* verify link is up */ |
| 1525 | if (!adapter->link_up) |
| 1526 | return -EINVAL; |
| 1527 | |
| 1528 | /* verify we are linked at 10Gbps */ |
| 1529 | link_speed = ixgbe_link_mbps(adapter); |
| 1530 | if (link_speed != 10000) |
| 1531 | return -EINVAL; |
| 1532 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1533 | if (min_tx_rate) |
| 1534 | return -EINVAL; |
| 1535 | |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1536 | /* rate limit cannot be less than 10Mbs or greater than link speed */ |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1537 | if (max_tx_rate && ((max_tx_rate <= 10) || (max_tx_rate > link_speed))) |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1538 | return -EINVAL; |
| 1539 | |
| 1540 | /* store values */ |
| 1541 | adapter->vf_rate_link_speed = link_speed; |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1542 | adapter->vfinfo[vf].tx_rate = max_tx_rate; |
Alexander Duyck | 9f66d3e | 2012-07-20 08:09:06 +0000 | [diff] [blame] | 1543 | |
| 1544 | /* update hardware configuration */ |
| 1545 | ixgbe_set_vf_rate_limit(adapter, vf); |
Lior Levy | ff4ab20 | 2011-03-11 02:03:07 +0000 | [diff] [blame] | 1546 | |
| 1547 | return 0; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 1550 | int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting) |
| 1551 | { |
| 1552 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 1553 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 1554 | |
Emil Tantilov | 600a507 | 2014-10-16 15:49:02 +0000 | [diff] [blame] | 1555 | if (vf >= adapter->num_vfs) |
| 1556 | return -EINVAL; |
| 1557 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 1558 | adapter->vfinfo[vf].spoofchk_enabled = setting; |
| 1559 | |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 1560 | /* configure MAC spoofing */ |
| 1561 | hw->mac.ops.set_mac_anti_spoofing(hw, setting, vf); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 1562 | |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 1563 | /* configure VLAN spoofing */ |
Emil Tantilov | d3dec7c | 2016-03-18 16:11:19 -0700 | [diff] [blame] | 1564 | hw->mac.ops.set_vlan_anti_spoofing(hw, setting, vf); |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 1565 | |
| 1566 | /* Ensure LLDP and FC is set for Ethertype Antispoofing if we will be |
| 1567 | * calling set_ethertype_anti_spoofing for each VF in loop below |
| 1568 | */ |
| 1569 | if (hw->mac.ops.set_ethertype_anti_spoofing) { |
| 1570 | IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP), |
| 1571 | (IXGBE_ETQF_FILTER_EN | |
| 1572 | IXGBE_ETQF_TX_ANTISPOOF | |
| 1573 | IXGBE_ETH_P_LLDP)); |
| 1574 | |
| 1575 | IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FC), |
| 1576 | (IXGBE_ETQF_FILTER_EN | |
| 1577 | IXGBE_ETQF_TX_ANTISPOOF | |
| 1578 | ETH_P_PAUSE)); |
| 1579 | |
| 1580 | hw->mac.ops.set_ethertype_anti_spoofing(hw, setting, vf); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | return 0; |
| 1584 | } |
| 1585 | |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 1586 | int ixgbe_ndo_set_vf_rss_query_en(struct net_device *netdev, int vf, |
| 1587 | bool setting) |
| 1588 | { |
| 1589 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1590 | |
| 1591 | /* This operation is currently supported only for 82599 and x540 |
| 1592 | * devices. |
| 1593 | */ |
| 1594 | if (adapter->hw.mac.type < ixgbe_mac_82599EB || |
| 1595 | adapter->hw.mac.type >= ixgbe_mac_X550) |
| 1596 | return -EOPNOTSUPP; |
| 1597 | |
| 1598 | if (vf >= adapter->num_vfs) |
| 1599 | return -EINVAL; |
| 1600 | |
| 1601 | adapter->vfinfo[vf].rss_query_enabled = setting; |
| 1602 | |
| 1603 | return 0; |
| 1604 | } |
| 1605 | |
Hiroshi Shimamoto | 54011e4 | 2015-08-28 06:58:33 +0000 | [diff] [blame] | 1606 | int ixgbe_ndo_set_vf_trust(struct net_device *netdev, int vf, bool setting) |
| 1607 | { |
| 1608 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1609 | |
| 1610 | if (vf >= adapter->num_vfs) |
| 1611 | return -EINVAL; |
| 1612 | |
| 1613 | /* nothing to do */ |
| 1614 | if (adapter->vfinfo[vf].trusted == setting) |
| 1615 | return 0; |
| 1616 | |
| 1617 | adapter->vfinfo[vf].trusted = setting; |
| 1618 | |
| 1619 | /* reset VF to reconfigure features */ |
| 1620 | adapter->vfinfo[vf].clear_to_send = false; |
| 1621 | ixgbe_ping_vf(adapter, vf); |
| 1622 | |
| 1623 | e_info(drv, "VF %u is %strusted\n", vf, setting ? "" : "not "); |
| 1624 | |
| 1625 | return 0; |
| 1626 | } |
| 1627 | |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1628 | int ixgbe_ndo_get_vf_config(struct net_device *netdev, |
| 1629 | int vf, struct ifla_vf_info *ivi) |
| 1630 | { |
| 1631 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1632 | if (vf >= adapter->num_vfs) |
| 1633 | return -EINVAL; |
| 1634 | ivi->vf = vf; |
| 1635 | memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN); |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1636 | ivi->max_tx_rate = adapter->vfinfo[vf].tx_rate; |
| 1637 | ivi->min_tx_rate = 0; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1638 | ivi->vlan = adapter->vfinfo[vf].pf_vlan; |
| 1639 | ivi->qos = adapter->vfinfo[vf].pf_qos; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 1640 | ivi->spoofchk = adapter->vfinfo[vf].spoofchk_enabled; |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 1641 | ivi->rss_query_en = adapter->vfinfo[vf].rss_query_enabled; |
Hiroshi Shimamoto | 54011e4 | 2015-08-28 06:58:33 +0000 | [diff] [blame] | 1642 | ivi->trusted = adapter->vfinfo[vf].trusted; |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 1643 | return 0; |
| 1644 | } |