blob: 593fdd54f9ab41eac6bf7ca6036621fa03af5fc3 [file] [log] [blame]
Greg Rose17367272010-01-09 02:25:48 +00001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Greg Rose17367272010-01-09 02:25:48 +00005
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 Rose17367272010-01-09 02:25:48 +000028#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 Rosec6bda302011-08-24 02:37:55 +000043#include "ixgbe_type.h"
Greg Rose17367272010-01-09 02:25:48 +000044#include "ixgbe_sriov.h"
45
Greg Rosec6bda302011-08-24 02:37:55 +000046#ifdef CONFIG_PCI_IOV
47static int ixgbe_find_enabled_vfs(struct ixgbe_adapter *adapter)
48{
49 struct pci_dev *pdev = adapter->pdev;
50 struct pci_dev *pvfdev;
51 u16 vf_devfn = 0;
52 int device_id;
53 int vfs_found = 0;
54
55 switch (adapter->hw.mac.type) {
56 case ixgbe_mac_82599EB:
57 device_id = IXGBE_DEV_ID_82599_VF;
58 break;
59 case ixgbe_mac_X540:
60 device_id = IXGBE_DEV_ID_X540_VF;
61 break;
62 default:
63 device_id = 0;
64 break;
65 }
66
67 vf_devfn = pdev->devfn + 0x80;
Jon Mason36e90312012-07-19 21:02:09 +000068 pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rosec6bda302011-08-24 02:37:55 +000069 while (pvfdev) {
Greg Rosea4b08322012-02-03 00:54:13 +000070 if (pvfdev->devfn == vf_devfn &&
71 (pvfdev->bus->number >= pdev->bus->number))
Greg Rosec6bda302011-08-24 02:37:55 +000072 vfs_found++;
73 vf_devfn += 2;
Jon Mason36e90312012-07-19 21:02:09 +000074 pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rosec6bda302011-08-24 02:37:55 +000075 device_id, pvfdev);
76 }
77
78 return vfs_found;
79}
80
81void ixgbe_enable_sriov(struct ixgbe_adapter *adapter,
82 const struct ixgbe_info *ii)
83{
84 struct ixgbe_hw *hw = &adapter->hw;
Greg Rosec6bda302011-08-24 02:37:55 +000085 int num_vf_macvlans, i;
86 struct vf_macvlans *mv_list;
87 int pre_existing_vfs = 0;
88
89 pre_existing_vfs = ixgbe_find_enabled_vfs(adapter);
90 if (!pre_existing_vfs && !adapter->num_vfs)
91 return;
92
93 /* If there are pre-existing VFs then we have to force
94 * use of that many because they were not deleted the last
95 * time someone removed the PF driver. That would have
96 * been because they were allocated to guest VMs and can't
97 * be removed. Go ahead and just re-enable the old amount.
98 * If the user wants to change the number of VFs they can
99 * use ethtool while making sure no VFs are allocated to
100 * guest VMs... i.e. the right way.
101 */
102 if (pre_existing_vfs) {
103 adapter->num_vfs = pre_existing_vfs;
104 dev_warn(&adapter->pdev->dev, "Virtual Functions already "
105 "enabled for this device - Please reload all "
106 "VF drivers to avoid spoofed packet errors\n");
107 } else {
Alexander Duyck99d74482012-05-09 08:09:25 +0000108 int err;
109 /*
110 * The 82599 supports up to 64 VFs per physical function
111 * but this implementation limits allocation to 63 so that
112 * basic networking resources are still available to the
113 * physical function. If the user requests greater thn
114 * 63 VFs then it is an error - reset to default of zero.
115 */
116 adapter->num_vfs = min_t(unsigned int, adapter->num_vfs, 63);
117
Greg Rosec6bda302011-08-24 02:37:55 +0000118 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
Alexander Duyck73079ea2012-07-14 06:48:49 +0000119 if (err) {
120 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Alexander Duyck99d74482012-05-09 08:09:25 +0000121 adapter->num_vfs = 0;
122 return;
Alexander Duyck73079ea2012-07-14 06:48:49 +0000123 }
Greg Rosec6bda302011-08-24 02:37:55 +0000124 }
Greg Rosec6bda302011-08-24 02:37:55 +0000125
Alexander Duyck73079ea2012-07-14 06:48:49 +0000126 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
Greg Rosec6bda302011-08-24 02:37:55 +0000127 e_info(probe, "SR-IOV enabled with %d VFs\n", adapter->num_vfs);
128
Alexander Duyck73079ea2012-07-14 06:48:49 +0000129 /* Enable VMDq flag so device will be set in VM mode */
130 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED;
131 if (!adapter->ring_feature[RING_F_VMDQ].limit)
132 adapter->ring_feature[RING_F_VMDQ].limit = 1;
133 adapter->ring_feature[RING_F_VMDQ].offset = adapter->num_vfs;
134
Greg Rosec6bda302011-08-24 02:37:55 +0000135 num_vf_macvlans = hw->mac.num_rar_entries -
136 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
137
138 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
139 sizeof(struct vf_macvlans),
140 GFP_KERNEL);
141 if (mv_list) {
142 /* Initialize list of VF macvlans */
143 INIT_LIST_HEAD(&adapter->vf_mvs.l);
144 for (i = 0; i < num_vf_macvlans; i++) {
145 mv_list->vf = -1;
146 mv_list->free = true;
147 mv_list->rar_entry = hw->mac.num_rar_entries -
148 (i + adapter->num_vfs + 1);
149 list_add(&mv_list->l, &adapter->vf_mvs.l);
150 mv_list++;
151 }
152 }
153
154 /* If call to enable VFs succeeded then allocate memory
155 * for per VF control structures.
156 */
157 adapter->vfinfo =
158 kcalloc(adapter->num_vfs,
159 sizeof(struct vf_data_storage), GFP_KERNEL);
160 if (adapter->vfinfo) {
161 /* Now that we're sure SR-IOV is enabled
162 * and memory allocated set up the mailbox parameters
163 */
164 ixgbe_init_mbx_params_pf(hw);
Alexander Duyck73079ea2012-07-14 06:48:49 +0000165 memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
166
167 /* limit trafffic classes based on VFs enabled */
168 if ((adapter->hw.mac.type == ixgbe_mac_82599EB) &&
169 (adapter->num_vfs < 16)) {
170 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
171 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
172 } else if (adapter->num_vfs < 32) {
173 adapter->dcb_cfg.num_tcs.pg_tcs = 4;
174 adapter->dcb_cfg.num_tcs.pfc_tcs = 4;
175 } else {
176 adapter->dcb_cfg.num_tcs.pg_tcs = 1;
177 adapter->dcb_cfg.num_tcs.pfc_tcs = 1;
178 }
179
180 /* We do not support RSS w/ SR-IOV */
181 adapter->ring_feature[RING_F_RSS].limit = 1;
Greg Rosec6bda302011-08-24 02:37:55 +0000182
183 /* Disable RSC when in SR-IOV mode */
184 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
185 IXGBE_FLAG2_RSC_ENABLED);
Alexander Duyck73079ea2012-07-14 06:48:49 +0000186
187#ifdef IXGBE_FCOE
188 /*
189 * When SR-IOV is enabled 82599 cannot support jumbo frames
190 * so we must disable FCoE because we cannot support FCoE MTU.
191 */
192 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
193 adapter->flags &= ~(IXGBE_FLAG_FCOE_ENABLED |
194 IXGBE_FLAG_FCOE_CAPABLE);
195#endif
196
197 /* enable spoof checking for all VFs */
Greg Rosede4c7f62011-09-29 05:57:33 +0000198 for (i = 0; i < adapter->num_vfs; i++)
199 adapter->vfinfo[i].spoofchk_enabled = true;
Greg Rosec6bda302011-08-24 02:37:55 +0000200 return;
201 }
202
203 /* Oh oh */
204 e_err(probe, "Unable to allocate memory for VF Data Storage - "
205 "SRIOV disabled\n");
Alexander Duyck99d74482012-05-09 08:09:25 +0000206 ixgbe_disable_sriov(adapter);
Greg Rosec6bda302011-08-24 02:37:55 +0000207}
208#endif /* #ifdef CONFIG_PCI_IOV */
209
210void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
211{
212 struct ixgbe_hw *hw = &adapter->hw;
Greg Rosec6bda302011-08-24 02:37:55 +0000213 u32 gpie;
214 u32 vmdctl;
215 int i;
216
Alexander Duyckd773d132012-05-05 05:32:26 +0000217 /* set num VFs to 0 to prevent access to vfinfo */
218 adapter->num_vfs = 0;
219
220 /* free VF control structures */
221 kfree(adapter->vfinfo);
222 adapter->vfinfo = NULL;
223
224 /* free macvlan list */
225 kfree(adapter->mv_list);
226 adapter->mv_list = NULL;
227
Alexander Duyck99d74482012-05-09 08:09:25 +0000228 /* if SR-IOV is already disabled then there is nothing to do */
229 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
230 return;
231
Greg Rosec6bda302011-08-24 02:37:55 +0000232#ifdef CONFIG_PCI_IOV
233 /* disable iov and allow time for transactions to clear */
234 pci_disable_sriov(adapter->pdev);
235#endif
236
237 /* turn off device IOV mode */
Alexander Duyck73079ea2012-07-14 06:48:49 +0000238 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, 0);
Greg Rosec6bda302011-08-24 02:37:55 +0000239 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
240 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
241 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
242
243 /* set default pool back to 0 */
244 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
245 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
246 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
247 IXGBE_WRITE_FLUSH(hw);
248
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +0000249 /* Disable VMDq flag so device will be set in VM mode */
250 if (adapter->ring_feature[RING_F_VMDQ].limit == 1)
251 adapter->flags &= ~IXGBE_FLAG_VMDQ_ENABLED;
252 adapter->ring_feature[RING_F_VMDQ].offset = 0;
253
Greg Rosec6bda302011-08-24 02:37:55 +0000254 /* take a breather then clean up driver data */
255 msleep(100);
256
257 /* Release reference to VF devices */
258 for (i = 0; i < adapter->num_vfs; i++) {
259 if (adapter->vfinfo[i].vfdev)
260 pci_dev_put(adapter->vfinfo[i].vfdev);
261 }
Greg Rosec6bda302011-08-24 02:37:55 +0000262
Greg Rosec6bda302011-08-24 02:37:55 +0000263 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
264}
265
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000266static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter,
267 int entries, u16 *hash_list, u32 vf)
Greg Rose17367272010-01-09 02:25:48 +0000268{
269 struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
Greg Rose8a07a222010-05-05 19:57:30 +0000270 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose17367272010-01-09 02:25:48 +0000271 int i;
Greg Rose8a07a222010-05-05 19:57:30 +0000272 u32 vector_bit;
273 u32 vector_reg;
274 u32 mta_reg;
Greg Rose17367272010-01-09 02:25:48 +0000275
276 /* only so many hash values supported */
277 entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES);
278
279 /*
280 * salt away the number of multi cast addresses assigned
281 * to this VF for later use to restore when the PF multi cast
282 * list changes
283 */
284 vfinfo->num_vf_mc_hashes = entries;
285
286 /*
287 * VFs are limited to using the MTA hash table for their multicast
288 * addresses
289 */
290 for (i = 0; i < entries; i++) {
Joe Perchese81a1ba2010-11-14 17:04:33 +0000291 vfinfo->vf_mc_hashes[i] = hash_list[i];
Greg Rose17367272010-01-09 02:25:48 +0000292 }
293
Greg Rose8a07a222010-05-05 19:57:30 +0000294 for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
295 vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F;
296 vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F;
297 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
298 mta_reg |= (1 << vector_bit);
299 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
300 }
Greg Rose17367272010-01-09 02:25:48 +0000301
302 return 0;
303}
304
Greg Rosea1cbb15c2011-05-13 01:33:48 +0000305static void ixgbe_restore_vf_macvlans(struct ixgbe_adapter *adapter)
306{
307 struct ixgbe_hw *hw = &adapter->hw;
308 struct list_head *pos;
309 struct vf_macvlans *entry;
310
311 list_for_each(pos, &adapter->vf_mvs.l) {
312 entry = list_entry(pos, struct vf_macvlans, l);
Joe Perches23677ce2012-02-09 11:17:23 +0000313 if (!entry->free)
Greg Rosea1cbb15c2011-05-13 01:33:48 +0000314 hw->mac.ops.set_rar(hw, entry->rar_entry,
315 entry->vf_macvlan,
316 entry->vf, IXGBE_RAH_AV);
317 }
318}
319
Greg Rose17367272010-01-09 02:25:48 +0000320void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter)
321{
322 struct ixgbe_hw *hw = &adapter->hw;
323 struct vf_data_storage *vfinfo;
324 int i, j;
325 u32 vector_bit;
326 u32 vector_reg;
327 u32 mta_reg;
328
329 for (i = 0; i < adapter->num_vfs; i++) {
330 vfinfo = &adapter->vfinfo[i];
331 for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) {
332 hw->addr_ctrl.mta_in_use++;
333 vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F;
334 vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F;
335 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
336 mta_reg |= (1 << vector_bit);
337 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
338 }
339 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +0000340
341 /* Restore any VF macvlans */
342 ixgbe_restore_vf_macvlans(adapter);
Greg Rose17367272010-01-09 02:25:48 +0000343}
344
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000345static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid,
346 u32 vf)
Greg Rose17367272010-01-09 02:25:48 +0000347{
Greg Rose17367272010-01-09 02:25:48 +0000348 return adapter->hw.mac.ops.set_vfta(&adapter->hw, vid, vf, (bool)add);
349}
350
John Fastabendb32c8dc2011-04-12 02:44:55 +0000351static void ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf)
Greg Rosee9f98072011-01-26 01:06:07 +0000352{
353 struct ixgbe_hw *hw = &adapter->hw;
354 int new_mtu = msgbuf[1];
355 u32 max_frs;
356 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
357
358 /* Only X540 supports jumbo frames in IOV mode */
359 if (adapter->hw.mac.type != ixgbe_mac_X540)
360 return;
361
362 /* MTU < 68 is an error and causes problems on some kernels */
363 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) {
364 e_err(drv, "VF mtu %d out of range\n", new_mtu);
365 return;
366 }
367
368 max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) &
369 IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT;
370 if (max_frs < new_mtu) {
371 max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT;
372 IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs);
373 }
374
375 e_info(hw, "VF requests change max MTU to %d\n", new_mtu);
376}
377
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000378static void ixgbe_set_vmolr(struct ixgbe_hw *hw, u32 vf, bool aupe)
Greg Rose17367272010-01-09 02:25:48 +0000379{
380 u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
Greg Rosef0412772010-05-04 22:11:46 +0000381 vmolr |= (IXGBE_VMOLR_ROMPE |
Greg Rose17367272010-01-09 02:25:48 +0000382 IXGBE_VMOLR_BAM);
Greg Rosef0412772010-05-04 22:11:46 +0000383 if (aupe)
384 vmolr |= IXGBE_VMOLR_AUPE;
385 else
386 vmolr &= ~IXGBE_VMOLR_AUPE;
Greg Rose17367272010-01-09 02:25:48 +0000387 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
388}
389
Greg Rose7f016482010-05-04 22:12:06 +0000390static void ixgbe_set_vmvir(struct ixgbe_adapter *adapter, u32 vid, u32 vf)
391{
392 struct ixgbe_hw *hw = &adapter->hw;
393
394 if (vid)
395 IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf),
396 (vid | IXGBE_VMVIR_VLANA_DEFAULT));
397 else
398 IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0);
399}
400
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000401static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf)
Greg Rose17367272010-01-09 02:25:48 +0000402{
403 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +0000404 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
Greg Rose17367272010-01-09 02:25:48 +0000405
406 /* reset offloads to defaults */
Greg Rose7f016482010-05-04 22:12:06 +0000407 if (adapter->vfinfo[vf].pf_vlan) {
408 ixgbe_set_vf_vlan(adapter, true,
409 adapter->vfinfo[vf].pf_vlan, vf);
410 ixgbe_set_vmvir(adapter,
411 (adapter->vfinfo[vf].pf_vlan |
412 (adapter->vfinfo[vf].pf_qos <<
413 VLAN_PRIO_SHIFT)), vf);
414 ixgbe_set_vmolr(hw, vf, false);
415 } else {
416 ixgbe_set_vmvir(adapter, 0, vf);
417 ixgbe_set_vmolr(hw, vf, true);
418 }
Greg Rose17367272010-01-09 02:25:48 +0000419
420 /* reset multicast table array for vf */
421 adapter->vfinfo[vf].num_vf_mc_hashes = 0;
422
423 /* Flush and reset the mta with the new values */
424 ixgbe_set_rx_mode(adapter->netdev);
425
Alexander Duyck28500622010-06-15 09:25:48 +0000426 hw->mac.ops.clear_rar(hw, rar_entry);
Greg Rose17367272010-01-09 02:25:48 +0000427}
428
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000429static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter,
430 int vf, unsigned char *mac_addr)
Greg Rose17367272010-01-09 02:25:48 +0000431{
432 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +0000433 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
Greg Rose17367272010-01-09 02:25:48 +0000434
435 memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, 6);
Alexander Duyck28500622010-06-15 09:25:48 +0000436 hw->mac.ops.set_rar(hw, rar_entry, mac_addr, vf, IXGBE_RAH_AV);
Greg Rose17367272010-01-09 02:25:48 +0000437
438 return 0;
439}
440
Greg Rosea1cbb15c2011-05-13 01:33:48 +0000441static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter,
442 int vf, int index, unsigned char *mac_addr)
443{
444 struct ixgbe_hw *hw = &adapter->hw;
445 struct list_head *pos;
446 struct vf_macvlans *entry;
447
448 if (index <= 1) {
449 list_for_each(pos, &adapter->vf_mvs.l) {
450 entry = list_entry(pos, struct vf_macvlans, l);
451 if (entry->vf == vf) {
452 entry->vf = -1;
453 entry->free = true;
454 entry->is_macvlan = false;
455 hw->mac.ops.clear_rar(hw, entry->rar_entry);
456 }
457 }
458 }
459
460 /*
461 * If index was zero then we were asked to clear the uc list
462 * for the VF. We're done.
463 */
464 if (!index)
465 return 0;
466
467 entry = NULL;
468
469 list_for_each(pos, &adapter->vf_mvs.l) {
470 entry = list_entry(pos, struct vf_macvlans, l);
471 if (entry->free)
472 break;
473 }
474
475 /*
476 * If we traversed the entire list and didn't find a free entry
477 * then we're out of space on the RAR table. Also entry may
478 * be NULL because the original memory allocation for the list
479 * failed, which is not fatal but does mean we can't support
480 * VF requests for MACVLAN because we couldn't allocate
481 * memory for the list management required.
482 */
483 if (!entry || !entry->free)
484 return -ENOSPC;
485
486 entry->free = false;
487 entry->is_macvlan = true;
488 entry->vf = vf;
489 memcpy(entry->vf_macvlan, mac_addr, ETH_ALEN);
490
491 hw->mac.ops.set_rar(hw, entry->rar_entry, mac_addr, vf, IXGBE_RAH_AV);
492
493 return 0;
494}
495
Greg Rosec6bda302011-08-24 02:37:55 +0000496int ixgbe_check_vf_assignment(struct ixgbe_adapter *adapter)
497{
Rose, Gregory V01264102011-11-07 07:44:17 +0000498#ifdef CONFIG_PCI_IOV
Greg Rosec6bda302011-08-24 02:37:55 +0000499 int i;
500 for (i = 0; i < adapter->num_vfs; i++) {
501 if (adapter->vfinfo[i].vfdev->dev_flags &
502 PCI_DEV_FLAGS_ASSIGNED)
503 return true;
504 }
Rose, Gregory V01264102011-11-07 07:44:17 +0000505#endif
Greg Rosec6bda302011-08-24 02:37:55 +0000506 return false;
507}
508
Greg Rose17367272010-01-09 02:25:48 +0000509int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask)
510{
511 unsigned char vf_mac_addr[6];
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800512 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Greg Rose17367272010-01-09 02:25:48 +0000513 unsigned int vfn = (event_mask & 0x3f);
Greg Rosec6bda302011-08-24 02:37:55 +0000514 struct pci_dev *pvfdev;
515 unsigned int device_id;
516 u16 thisvf_devfn = (pdev->devfn + 0x80 + (vfn << 1)) |
517 (pdev->devfn & 1);
Greg Rose17367272010-01-09 02:25:48 +0000518
519 bool enable = ((event_mask & 0x10000000U) != 0);
520
521 if (enable) {
Joe Perches7efd26d2012-07-12 19:33:06 +0000522 eth_random_addr(vf_mac_addr);
Emil Tantilov396e7992010-07-01 20:05:12 +0000523 e_info(probe, "IOV: VF %d is enabled MAC %pM\n",
524 vfn, vf_mac_addr);
Greg Rose17367272010-01-09 02:25:48 +0000525 /*
526 * Store away the VF "permananet" MAC address, it will ask
527 * for it later.
528 */
529 memcpy(adapter->vfinfo[vfn].vf_mac_addresses, vf_mac_addr, 6);
Greg Rosec6bda302011-08-24 02:37:55 +0000530
531 switch (adapter->hw.mac.type) {
532 case ixgbe_mac_82599EB:
533 device_id = IXGBE_DEV_ID_82599_VF;
534 break;
535 case ixgbe_mac_X540:
536 device_id = IXGBE_DEV_ID_X540_VF;
537 break;
538 default:
539 device_id = 0;
540 break;
541 }
542
Jon Mason36e90312012-07-19 21:02:09 +0000543 pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rosec6bda302011-08-24 02:37:55 +0000544 while (pvfdev) {
545 if (pvfdev->devfn == thisvf_devfn)
546 break;
Jon Mason36e90312012-07-19 21:02:09 +0000547 pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rosec6bda302011-08-24 02:37:55 +0000548 device_id, pvfdev);
549 }
550 if (pvfdev)
551 adapter->vfinfo[vfn].vfdev = pvfdev;
552 else
553 e_err(drv, "Couldn't find pci dev ptr for VF %4.4x\n",
554 thisvf_devfn);
Greg Rose17367272010-01-09 02:25:48 +0000555 }
556
557 return 0;
558}
559
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000560static inline void ixgbe_vf_reset_msg(struct ixgbe_adapter *adapter, u32 vf)
Greg Rose17367272010-01-09 02:25:48 +0000561{
562 struct ixgbe_hw *hw = &adapter->hw;
563 u32 reg;
564 u32 reg_offset, vf_shift;
565
566 vf_shift = vf % 32;
567 reg_offset = vf / 32;
568
569 /* enable transmit and receive for vf */
570 reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset));
571 reg |= (reg | (1 << vf_shift));
572 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg);
573
574 reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset));
575 reg |= (reg | (1 << vf_shift));
576 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg);
577
Greg Rosea985b6c32010-11-18 03:02:52 +0000578 /* Enable counting of spoofed packets in the SSVPC register */
579 reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset));
580 reg |= (1 << vf_shift);
581 IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg);
582
Greg Rose17367272010-01-09 02:25:48 +0000583 ixgbe_vf_reset_event(adapter, vf);
584}
585
586static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf)
587{
588 u32 mbx_size = IXGBE_VFMAILBOX_SIZE;
Emil Tantilovc0509992011-05-07 06:49:18 +0000589 u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
Greg Rose17367272010-01-09 02:25:48 +0000590 struct ixgbe_hw *hw = &adapter->hw;
591 s32 retval;
592 int entries;
593 u16 *hash_list;
Greg Rosea1cbb15c2011-05-13 01:33:48 +0000594 int add, vid, index;
Greg Rosed3306c22010-11-18 03:03:23 +0000595 u8 *new_mac;
Greg Rose17367272010-01-09 02:25:48 +0000596
597 retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf);
598
Alexander Duyckdcaccc82012-03-28 08:03:38 +0000599 if (retval) {
Emil Tantilov849c4542010-06-03 16:53:41 +0000600 pr_err("Error receiving message from VF\n");
Alexander Duyckdcaccc82012-03-28 08:03:38 +0000601 return retval;
602 }
Greg Rose17367272010-01-09 02:25:48 +0000603
604 /* this is a message we already processed, do nothing */
605 if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK))
606 return retval;
607
Alexander Duyckdcaccc82012-03-28 08:03:38 +0000608 /* flush the ack before we write any messages back */
609 IXGBE_WRITE_FLUSH(hw);
610
Greg Rose17367272010-01-09 02:25:48 +0000611 /*
612 * until the vf completes a virtual function reset it should not be
613 * allowed to start any configuration.
614 */
615
616 if (msgbuf[0] == IXGBE_VF_RESET) {
617 unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses;
Greg Rosed3306c22010-11-18 03:03:23 +0000618 new_mac = (u8 *)(&msgbuf[1]);
Emil Tantilov396e7992010-07-01 20:05:12 +0000619 e_info(probe, "VF Reset msg received from vf %d\n", vf);
Greg Rose17367272010-01-09 02:25:48 +0000620 adapter->vfinfo[vf].clear_to_send = false;
621 ixgbe_vf_reset_msg(adapter, vf);
622 adapter->vfinfo[vf].clear_to_send = true;
623
Greg Rosed3306c22010-11-18 03:03:23 +0000624 if (is_valid_ether_addr(new_mac) &&
625 !adapter->vfinfo[vf].pf_set_mac)
626 ixgbe_set_vf_mac(adapter, vf, vf_mac);
627 else
628 ixgbe_set_vf_mac(adapter,
629 vf, adapter->vfinfo[vf].vf_mac_addresses);
630
Greg Rose17367272010-01-09 02:25:48 +0000631 /* reply to reset with ack and vf mac address */
632 msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK;
Joe Perchesea99d832011-09-20 15:32:52 +0000633 memcpy(new_mac, vf_mac, ETH_ALEN);
Greg Rose17367272010-01-09 02:25:48 +0000634 /*
635 * Piggyback the multicast filter type so VF can compute the
636 * correct vectors
637 */
638 msgbuf[3] = hw->mac.mc_filter_type;
639 ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf);
640
641 return retval;
642 }
643
644 if (!adapter->vfinfo[vf].clear_to_send) {
645 msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
646 ixgbe_write_mbx(hw, msgbuf, 1, vf);
647 return retval;
648 }
649
650 switch ((msgbuf[0] & 0xFFFF)) {
651 case IXGBE_VF_SET_MAC_ADDR:
Greg Rosed3306c22010-11-18 03:03:23 +0000652 new_mac = ((u8 *)(&msgbuf[1]));
653 if (is_valid_ether_addr(new_mac) &&
654 !adapter->vfinfo[vf].pf_set_mac) {
655 ixgbe_set_vf_mac(adapter, vf, new_mac);
656 } else if (memcmp(adapter->vfinfo[vf].vf_mac_addresses,
657 new_mac, ETH_ALEN)) {
658 e_warn(drv, "VF %d attempted to override "
659 "administratively set MAC address\nReload "
660 "the VF driver to resume operations\n", vf);
661 retval = -1;
Greg Rose17367272010-01-09 02:25:48 +0000662 }
663 break;
664 case IXGBE_VF_SET_MULTICAST:
665 entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
666 >> IXGBE_VT_MSGINFO_SHIFT;
667 hash_list = (u16 *)&msgbuf[1];
668 retval = ixgbe_set_vf_multicasts(adapter, entries,
669 hash_list, vf);
670 break;
671 case IXGBE_VF_SET_LPE:
Greg Rosee9f98072011-01-26 01:06:07 +0000672 ixgbe_set_vf_lpe(adapter, msgbuf);
Greg Rose17367272010-01-09 02:25:48 +0000673 break;
674 case IXGBE_VF_SET_VLAN:
675 add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
676 >> IXGBE_VT_MSGINFO_SHIFT;
677 vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK);
Greg Rosed3306c22010-11-18 03:03:23 +0000678 if (adapter->vfinfo[vf].pf_vlan) {
679 e_warn(drv, "VF %d attempted to override "
680 "administratively set VLAN configuration\n"
681 "Reload the VF driver to resume operations\n",
682 vf);
683 retval = -1;
684 } else {
Greg Rosede4c7f62011-09-29 05:57:33 +0000685 if (add)
686 adapter->vfinfo[vf].vlan_count++;
687 else if (adapter->vfinfo[vf].vlan_count)
688 adapter->vfinfo[vf].vlan_count--;
Greg Rosed3306c22010-11-18 03:03:23 +0000689 retval = ixgbe_set_vf_vlan(adapter, add, vid, vf);
Greg Rosede4c7f62011-09-29 05:57:33 +0000690 if (!retval && adapter->vfinfo[vf].spoofchk_enabled)
691 hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf);
Greg Rosed3306c22010-11-18 03:03:23 +0000692 }
Greg Rose17367272010-01-09 02:25:48 +0000693 break;
Greg Rosea1cbb15c2011-05-13 01:33:48 +0000694 case IXGBE_VF_SET_MACVLAN:
Greg Rose44b82dd2012-04-21 00:54:28 +0000695 index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >>
696 IXGBE_VT_MSGINFO_SHIFT;
697 if (adapter->vfinfo[vf].pf_set_mac && index > 0) {
Greg Rose2ee70652012-03-24 00:26:44 +0000698 e_warn(drv, "VF %d requested MACVLAN filter but is "
699 "administratively denied\n", vf);
700 retval = -1;
701 break;
702 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +0000703 /*
704 * If the VF is allowed to set MAC filters then turn off
705 * anti-spoofing to avoid false positives. An index
706 * greater than 0 will indicate the VF is setting a
707 * macvlan MAC filter.
708 */
Greg Rosede4c7f62011-09-29 05:57:33 +0000709 if (index > 0 && adapter->vfinfo[vf].spoofchk_enabled)
710 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, vf, false);
Greg Rosea1cbb15c2011-05-13 01:33:48 +0000711 retval = ixgbe_set_vf_macvlan(adapter, vf, index,
712 (unsigned char *)(&msgbuf[1]));
Greg Rose68d6d4a2012-01-05 07:58:11 +0000713 if (retval == -ENOSPC)
714 e_warn(drv, "VF %d has requested a MACVLAN filter "
715 "but there is no space for it\n", vf);
Greg Rosea1cbb15c2011-05-13 01:33:48 +0000716 break;
Greg Rose17367272010-01-09 02:25:48 +0000717 default:
Emil Tantilov396e7992010-07-01 20:05:12 +0000718 e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]);
Greg Rose17367272010-01-09 02:25:48 +0000719 retval = IXGBE_ERR_MBX;
720 break;
721 }
722
723 /* notify the VF of the results of what it sent us */
724 if (retval)
725 msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
726 else
727 msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK;
728
729 msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS;
730
731 ixgbe_write_mbx(hw, msgbuf, 1, vf);
732
733 return retval;
734}
735
736static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf)
737{
738 struct ixgbe_hw *hw = &adapter->hw;
739 u32 msg = IXGBE_VT_MSGTYPE_NACK;
740
741 /* if device isn't clear to send it shouldn't be reading either */
742 if (!adapter->vfinfo[vf].clear_to_send)
743 ixgbe_write_mbx(hw, &msg, 1, vf);
744}
745
746void ixgbe_msg_task(struct ixgbe_adapter *adapter)
747{
748 struct ixgbe_hw *hw = &adapter->hw;
749 u32 vf;
750
751 for (vf = 0; vf < adapter->num_vfs; vf++) {
752 /* process any reset requests */
753 if (!ixgbe_check_for_rst(hw, vf))
754 ixgbe_vf_reset_event(adapter, vf);
755
756 /* process any messages pending */
757 if (!ixgbe_check_for_msg(hw, vf))
758 ixgbe_rcv_msg_from_vf(adapter, vf);
759
760 /* process any acks */
761 if (!ixgbe_check_for_ack(hw, vf))
762 ixgbe_rcv_ack_from_vf(adapter, vf);
763 }
764}
765
Greg Rose767081a2010-01-22 22:46:40 +0000766void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter)
767{
768 struct ixgbe_hw *hw = &adapter->hw;
769
770 /* disable transmit and receive for all vfs */
771 IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0);
772 IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0);
773
774 IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0);
775 IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0);
776}
777
778void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter)
779{
780 struct ixgbe_hw *hw = &adapter->hw;
781 u32 ping;
782 int i;
783
784 for (i = 0 ; i < adapter->num_vfs; i++) {
785 ping = IXGBE_PF_CONTROL_MSG;
786 if (adapter->vfinfo[i].clear_to_send)
787 ping |= IXGBE_VT_MSGTYPE_CTS;
788 ixgbe_write_mbx(hw, &ping, 1, i);
789 }
790}
791
Greg Rose7f016482010-05-04 22:12:06 +0000792int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
793{
794 struct ixgbe_adapter *adapter = netdev_priv(netdev);
795 if (!is_valid_ether_addr(mac) || (vf >= adapter->num_vfs))
796 return -EINVAL;
797 adapter->vfinfo[vf].pf_set_mac = true;
798 dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
799 dev_info(&adapter->pdev->dev, "Reload the VF driver to make this"
800 " change effective.");
801 if (test_bit(__IXGBE_DOWN, &adapter->state)) {
802 dev_warn(&adapter->pdev->dev, "The VF MAC address has been set,"
803 " but the PF device is not up.\n");
804 dev_warn(&adapter->pdev->dev, "Bring the PF device up before"
805 " attempting to use the VF device.\n");
806 }
807 return ixgbe_set_vf_mac(adapter, vf, mac);
808}
809
810int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos)
811{
812 int err = 0;
813 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Greg Rosea985b6c32010-11-18 03:02:52 +0000814 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose7f016482010-05-04 22:12:06 +0000815
816 if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7))
817 return -EINVAL;
818 if (vlan || qos) {
819 err = ixgbe_set_vf_vlan(adapter, true, vlan, vf);
820 if (err)
821 goto out;
822 ixgbe_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
Greg Rosea985b6c32010-11-18 03:02:52 +0000823 ixgbe_set_vmolr(hw, vf, false);
Greg Rosede4c7f62011-09-29 05:57:33 +0000824 if (adapter->vfinfo[vf].spoofchk_enabled)
Greg Rosea1cbb15c2011-05-13 01:33:48 +0000825 hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf);
Greg Rosede4c7f62011-09-29 05:57:33 +0000826 adapter->vfinfo[vf].vlan_count++;
Greg Rose7f016482010-05-04 22:12:06 +0000827 adapter->vfinfo[vf].pf_vlan = vlan;
828 adapter->vfinfo[vf].pf_qos = qos;
829 dev_info(&adapter->pdev->dev,
830 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
831 if (test_bit(__IXGBE_DOWN, &adapter->state)) {
832 dev_warn(&adapter->pdev->dev,
833 "The VF VLAN has been set,"
834 " but the PF device is not up.\n");
835 dev_warn(&adapter->pdev->dev,
836 "Bring the PF device up before"
837 " attempting to use the VF device.\n");
838 }
839 } else {
840 err = ixgbe_set_vf_vlan(adapter, false,
841 adapter->vfinfo[vf].pf_vlan, vf);
842 ixgbe_set_vmvir(adapter, vlan, vf);
Greg Rosea985b6c32010-11-18 03:02:52 +0000843 ixgbe_set_vmolr(hw, vf, true);
844 hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf);
Greg Rosede4c7f62011-09-29 05:57:33 +0000845 if (adapter->vfinfo[vf].vlan_count)
846 adapter->vfinfo[vf].vlan_count--;
Greg Rose7f016482010-05-04 22:12:06 +0000847 adapter->vfinfo[vf].pf_vlan = 0;
848 adapter->vfinfo[vf].pf_qos = 0;
849 }
850out:
851 return err;
852}
853
Lior Levyff4ab202011-03-11 02:03:07 +0000854static int ixgbe_link_mbps(int internal_link_speed)
855{
856 switch (internal_link_speed) {
857 case IXGBE_LINK_SPEED_100_FULL:
858 return 100;
859 case IXGBE_LINK_SPEED_1GB_FULL:
860 return 1000;
861 case IXGBE_LINK_SPEED_10GB_FULL:
862 return 10000;
863 default:
864 return 0;
865 }
866}
867
868static void ixgbe_set_vf_rate_limit(struct ixgbe_hw *hw, int vf, int tx_rate,
869 int link_speed)
870{
871 int rf_dec, rf_int;
872 u32 bcnrc_val;
873
874 if (tx_rate != 0) {
875 /* Calculate the rate factor values to set */
876 rf_int = link_speed / tx_rate;
877 rf_dec = (link_speed - (rf_int * tx_rate));
878 rf_dec = (rf_dec * (1<<IXGBE_RTTBCNRC_RF_INT_SHIFT)) / tx_rate;
879
880 bcnrc_val = IXGBE_RTTBCNRC_RS_ENA;
881 bcnrc_val |= ((rf_int<<IXGBE_RTTBCNRC_RF_INT_SHIFT) &
882 IXGBE_RTTBCNRC_RF_INT_MASK);
883 bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK);
884 } else {
885 bcnrc_val = 0;
886 }
887
888 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, 2*vf); /* vf Y uses queue 2*Y */
Lior Levy7555e832011-06-25 00:09:08 -0700889 /*
890 * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
891 * register. Typically MMW_SIZE=0x014 if 9728-byte jumbo is supported
892 * and 0x004 otherwise.
893 */
894 switch (hw->mac.type) {
895 case ixgbe_mac_82599EB:
896 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x4);
897 break;
898 case ixgbe_mac_X540:
899 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x14);
900 break;
901 default:
902 break;
903 }
904
Lior Levyff4ab202011-03-11 02:03:07 +0000905 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
906}
907
908void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter)
909{
910 int actual_link_speed, i;
911 bool reset_rate = false;
912
913 /* VF Tx rate limit was not set */
914 if (adapter->vf_rate_link_speed == 0)
915 return;
916
917 actual_link_speed = ixgbe_link_mbps(adapter->link_speed);
918 if (actual_link_speed != adapter->vf_rate_link_speed) {
919 reset_rate = true;
920 adapter->vf_rate_link_speed = 0;
921 dev_info(&adapter->pdev->dev,
922 "Link speed has been changed. VF Transmit rate "
923 "is disabled\n");
924 }
925
926 for (i = 0; i < adapter->num_vfs; i++) {
927 if (reset_rate)
928 adapter->vfinfo[i].tx_rate = 0;
929
930 ixgbe_set_vf_rate_limit(&adapter->hw, i,
931 adapter->vfinfo[i].tx_rate,
932 actual_link_speed);
933 }
934}
935
Greg Rose7f016482010-05-04 22:12:06 +0000936int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate)
937{
Lior Levyff4ab202011-03-11 02:03:07 +0000938 struct ixgbe_adapter *adapter = netdev_priv(netdev);
939 struct ixgbe_hw *hw = &adapter->hw;
940 int actual_link_speed;
941
942 actual_link_speed = ixgbe_link_mbps(adapter->link_speed);
943 if ((vf >= adapter->num_vfs) || (!adapter->link_up) ||
944 (tx_rate > actual_link_speed) || (actual_link_speed != 10000) ||
945 ((tx_rate != 0) && (tx_rate <= 10)))
946 /* rate limit cannot be set to 10Mb or less in 10Gb adapters */
947 return -EINVAL;
948
949 adapter->vf_rate_link_speed = actual_link_speed;
950 adapter->vfinfo[vf].tx_rate = (u16)tx_rate;
951 ixgbe_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed);
952
953 return 0;
Greg Rose7f016482010-05-04 22:12:06 +0000954}
955
Greg Rosede4c7f62011-09-29 05:57:33 +0000956int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
957{
958 struct ixgbe_adapter *adapter = netdev_priv(netdev);
959 int vf_target_reg = vf >> 3;
960 int vf_target_shift = vf % 8;
961 struct ixgbe_hw *hw = &adapter->hw;
962 u32 regval;
963
964 adapter->vfinfo[vf].spoofchk_enabled = setting;
965
966 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
967 regval &= ~(1 << vf_target_shift);
968 regval |= (setting << vf_target_shift);
969 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), regval);
970
971 if (adapter->vfinfo[vf].vlan_count) {
972 vf_target_shift += IXGBE_SPOOF_VLANAS_SHIFT;
973 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
974 regval &= ~(1 << vf_target_shift);
975 regval |= (setting << vf_target_shift);
976 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), regval);
977 }
978
979 return 0;
980}
981
Greg Rose7f016482010-05-04 22:12:06 +0000982int ixgbe_ndo_get_vf_config(struct net_device *netdev,
983 int vf, struct ifla_vf_info *ivi)
984{
985 struct ixgbe_adapter *adapter = netdev_priv(netdev);
986 if (vf >= adapter->num_vfs)
987 return -EINVAL;
988 ivi->vf = vf;
989 memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN);
Lior Levyff4ab202011-03-11 02:03:07 +0000990 ivi->tx_rate = adapter->vfinfo[vf].tx_rate;
Greg Rose7f016482010-05-04 22:12:06 +0000991 ivi->vlan = adapter->vfinfo[vf].pf_vlan;
992 ivi->qos = adapter->vfinfo[vf].pf_qos;
Greg Rosede4c7f62011-09-29 05:57:33 +0000993 ivi->spoofchk = adapter->vfinfo[vf].spoofchk_enabled;
Greg Rose7f016482010-05-04 22:12:06 +0000994 return 0;
995}