1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
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.
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
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #include <linux/types.h>
29 #include <linux/module.h>
30 #include <linux/pci.h>
31 #include <linux/netdevice.h>
32 #include <linux/vmalloc.h>
33 #include <linux/string.h>
36 #include <linux/tcp.h>
37 #include <linux/ipv6.h>
38 #ifdef NETIF_F_HW_VLAN_TX
39 #include <linux/if_vlan.h>
43 #include "ixgbe_type.h"
44 #include "ixgbe_sriov.h"
47 void ixgbe_enable_sriov(struct ixgbe_adapter *adapter,
48 const struct ixgbe_info *ii)
50 struct ixgbe_hw *hw = &adapter->hw;
51 int num_vf_macvlans, i;
52 struct vf_macvlans *mv_list;
53 int pre_existing_vfs = 0;
55 pre_existing_vfs = pci_num_vf(adapter->pdev);
56 if (!pre_existing_vfs && !adapter->num_vfs)
59 /* If there are pre-existing VFs then we have to force
60 * use of that many because they were not deleted the last
61 * time someone removed the PF driver. That would have
62 * been because they were allocated to guest VMs and can't
63 * be removed. Go ahead and just re-enable the old amount.
64 * If the user wants to change the number of VFs they can
65 * use ethtool while making sure no VFs are allocated to
66 * guest VMs... i.e. the right way.
68 if (pre_existing_vfs) {
69 adapter->num_vfs = pre_existing_vfs;
70 dev_warn(&adapter->pdev->dev, "Virtual Functions already "
71 "enabled for this device - Please reload all "
72 "VF drivers to avoid spoofed packet errors\n");
76 * The 82599 supports up to 64 VFs per physical function
77 * but this implementation limits allocation to 63 so that
78 * basic networking resources are still available to the
79 * physical function. If the user requests greater thn
80 * 63 VFs then it is an error - reset to default of zero.
82 adapter->num_vfs = min_t(unsigned int, adapter->num_vfs, 63);
84 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
86 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
92 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
93 e_info(probe, "SR-IOV enabled with %d VFs\n", adapter->num_vfs);
95 /* Enable VMDq flag so device will be set in VM mode */
96 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED;
97 if (!adapter->ring_feature[RING_F_VMDQ].limit)
98 adapter->ring_feature[RING_F_VMDQ].limit = 1;
99 adapter->ring_feature[RING_F_VMDQ].offset = adapter->num_vfs;
101 num_vf_macvlans = hw->mac.num_rar_entries -
102 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
104 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
105 sizeof(struct vf_macvlans),
108 /* Initialize list of VF macvlans */
109 INIT_LIST_HEAD(&adapter->vf_mvs.l);
110 for (i = 0; i < num_vf_macvlans; i++) {
112 mv_list->free = true;
113 mv_list->rar_entry = hw->mac.num_rar_entries -
114 (i + adapter->num_vfs + 1);
115 list_add(&mv_list->l, &adapter->vf_mvs.l);
120 /* If call to enable VFs succeeded then allocate memory
121 * for per VF control structures.
124 kcalloc(adapter->num_vfs,
125 sizeof(struct vf_data_storage), GFP_KERNEL);
126 if (adapter->vfinfo) {
127 /* Now that we're sure SR-IOV is enabled
128 * and memory allocated set up the mailbox parameters
130 ixgbe_init_mbx_params_pf(hw);
131 memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
133 /* limit trafffic classes based on VFs enabled */
134 if ((adapter->hw.mac.type == ixgbe_mac_82599EB) &&
135 (adapter->num_vfs < 16)) {
136 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
137 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
138 } else if (adapter->num_vfs < 32) {
139 adapter->dcb_cfg.num_tcs.pg_tcs = 4;
140 adapter->dcb_cfg.num_tcs.pfc_tcs = 4;
142 adapter->dcb_cfg.num_tcs.pg_tcs = 1;
143 adapter->dcb_cfg.num_tcs.pfc_tcs = 1;
146 /* We do not support RSS w/ SR-IOV */
147 adapter->ring_feature[RING_F_RSS].limit = 1;
149 /* Disable RSC when in SR-IOV mode */
150 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
151 IXGBE_FLAG2_RSC_ENABLED);
155 * When SR-IOV is enabled 82599 cannot support jumbo frames
156 * so we must disable FCoE because we cannot support FCoE MTU.
158 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
159 adapter->flags &= ~(IXGBE_FLAG_FCOE_ENABLED |
160 IXGBE_FLAG_FCOE_CAPABLE);
163 /* enable spoof checking for all VFs */
164 for (i = 0; i < adapter->num_vfs; i++)
165 adapter->vfinfo[i].spoofchk_enabled = true;
170 e_err(probe, "Unable to allocate memory for VF Data Storage - "
172 ixgbe_disable_sriov(adapter);
175 static bool ixgbe_vfs_are_assigned(struct ixgbe_adapter *adapter)
177 struct pci_dev *pdev = adapter->pdev;
178 struct pci_dev *vfdev;
181 switch (adapter->hw.mac.type) {
182 case ixgbe_mac_82599EB:
183 dev_id = IXGBE_DEV_ID_82599_VF;
186 dev_id = IXGBE_DEV_ID_X540_VF;
192 /* loop through all the VFs to see if we own any that are assigned */
193 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, NULL);
195 /* if we don't own it we don't care */
196 if (vfdev->is_virtfn && vfdev->physfn == pdev) {
197 /* if it is assigned we cannot release it */
198 if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
202 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, vfdev);
208 #endif /* #ifdef CONFIG_PCI_IOV */
209 void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
211 struct ixgbe_hw *hw = &adapter->hw;
215 /* set num VFs to 0 to prevent access to vfinfo */
216 adapter->num_vfs = 0;
218 /* free VF control structures */
219 kfree(adapter->vfinfo);
220 adapter->vfinfo = NULL;
222 /* free macvlan list */
223 kfree(adapter->mv_list);
224 adapter->mv_list = NULL;
226 /* if SR-IOV is already disabled then there is nothing to do */
227 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
230 #ifdef CONFIG_PCI_IOV
232 * If our VFs are assigned we cannot shut down SR-IOV
233 * without causing issues, so just leave the hardware
234 * available but disabled
236 if (ixgbe_vfs_are_assigned(adapter)) {
237 e_dev_warn("Unloading driver while VFs are assigned - VFs will not be deallocated\n");
240 /* disable iov and allow time for transactions to clear */
241 pci_disable_sriov(adapter->pdev);
244 /* turn off device IOV mode */
245 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, 0);
246 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
247 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
248 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
250 /* set default pool back to 0 */
251 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
252 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
253 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
254 IXGBE_WRITE_FLUSH(hw);
256 /* Disable VMDq flag so device will be set in VM mode */
257 if (adapter->ring_feature[RING_F_VMDQ].limit == 1)
258 adapter->flags &= ~IXGBE_FLAG_VMDQ_ENABLED;
259 adapter->ring_feature[RING_F_VMDQ].offset = 0;
261 /* take a breather then clean up driver data */
264 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
267 static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter,
268 int entries, u16 *hash_list, u32 vf)
270 struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
271 struct ixgbe_hw *hw = &adapter->hw;
277 /* only so many hash values supported */
278 entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES);
281 * salt away the number of multi cast addresses assigned
282 * to this VF for later use to restore when the PF multi cast
285 vfinfo->num_vf_mc_hashes = entries;
288 * VFs are limited to using the MTA hash table for their multicast
291 for (i = 0; i < entries; i++) {
292 vfinfo->vf_mc_hashes[i] = hash_list[i];
295 for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
296 vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F;
297 vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F;
298 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
299 mta_reg |= (1 << vector_bit);
300 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
306 static void ixgbe_restore_vf_macvlans(struct ixgbe_adapter *adapter)
308 struct ixgbe_hw *hw = &adapter->hw;
309 struct list_head *pos;
310 struct vf_macvlans *entry;
312 list_for_each(pos, &adapter->vf_mvs.l) {
313 entry = list_entry(pos, struct vf_macvlans, l);
315 hw->mac.ops.set_rar(hw, entry->rar_entry,
317 entry->vf, IXGBE_RAH_AV);
321 void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter)
323 struct ixgbe_hw *hw = &adapter->hw;
324 struct vf_data_storage *vfinfo;
330 for (i = 0; i < adapter->num_vfs; i++) {
331 vfinfo = &adapter->vfinfo[i];
332 for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) {
333 hw->addr_ctrl.mta_in_use++;
334 vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F;
335 vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F;
336 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
337 mta_reg |= (1 << vector_bit);
338 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
342 /* Restore any VF macvlans */
343 ixgbe_restore_vf_macvlans(adapter);
346 static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid,
349 /* VLAN 0 is a special case, don't allow it to be removed */
353 return adapter->hw.mac.ops.set_vfta(&adapter->hw, vid, vf, (bool)add);
356 static void ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf)
358 struct ixgbe_hw *hw = &adapter->hw;
359 int new_mtu = msgbuf[1];
361 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
363 /* Only X540 supports jumbo frames in IOV mode */
364 if (adapter->hw.mac.type != ixgbe_mac_X540)
367 /* MTU < 68 is an error and causes problems on some kernels */
368 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) {
369 e_err(drv, "VF mtu %d out of range\n", new_mtu);
373 max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) &
374 IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT;
375 if (max_frs < new_mtu) {
376 max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT;
377 IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs);
380 e_info(hw, "VF requests change max MTU to %d\n", new_mtu);
383 static void ixgbe_set_vmolr(struct ixgbe_hw *hw, u32 vf, bool aupe)
385 u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
386 vmolr |= (IXGBE_VMOLR_ROMPE |
389 vmolr |= IXGBE_VMOLR_AUPE;
391 vmolr &= ~IXGBE_VMOLR_AUPE;
392 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
395 static void ixgbe_set_vmvir(struct ixgbe_adapter *adapter, u32 vid, u32 vf)
397 struct ixgbe_hw *hw = &adapter->hw;
400 IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf),
401 (vid | IXGBE_VMVIR_VLANA_DEFAULT));
403 IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0);
406 static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf)
408 struct ixgbe_hw *hw = &adapter->hw;
409 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
411 /* reset offloads to defaults */
412 if (adapter->vfinfo[vf].pf_vlan) {
413 ixgbe_set_vf_vlan(adapter, true,
414 adapter->vfinfo[vf].pf_vlan, vf);
415 ixgbe_set_vmvir(adapter,
416 (adapter->vfinfo[vf].pf_vlan |
417 (adapter->vfinfo[vf].pf_qos <<
418 VLAN_PRIO_SHIFT)), vf);
419 ixgbe_set_vmolr(hw, vf, false);
421 ixgbe_set_vf_vlan(adapter, true, 0, vf);
422 ixgbe_set_vmvir(adapter, 0, vf);
423 ixgbe_set_vmolr(hw, vf, true);
426 /* reset multicast table array for vf */
427 adapter->vfinfo[vf].num_vf_mc_hashes = 0;
429 /* Flush and reset the mta with the new values */
430 ixgbe_set_rx_mode(adapter->netdev);
432 hw->mac.ops.clear_rar(hw, rar_entry);
435 static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter,
436 int vf, unsigned char *mac_addr)
438 struct ixgbe_hw *hw = &adapter->hw;
439 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
441 memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, 6);
442 hw->mac.ops.set_rar(hw, rar_entry, mac_addr, vf, IXGBE_RAH_AV);
447 static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter,
448 int vf, int index, unsigned char *mac_addr)
450 struct ixgbe_hw *hw = &adapter->hw;
451 struct list_head *pos;
452 struct vf_macvlans *entry;
455 list_for_each(pos, &adapter->vf_mvs.l) {
456 entry = list_entry(pos, struct vf_macvlans, l);
457 if (entry->vf == vf) {
460 entry->is_macvlan = false;
461 hw->mac.ops.clear_rar(hw, entry->rar_entry);
467 * If index was zero then we were asked to clear the uc list
468 * for the VF. We're done.
475 list_for_each(pos, &adapter->vf_mvs.l) {
476 entry = list_entry(pos, struct vf_macvlans, l);
482 * If we traversed the entire list and didn't find a free entry
483 * then we're out of space on the RAR table. Also entry may
484 * be NULL because the original memory allocation for the list
485 * failed, which is not fatal but does mean we can't support
486 * VF requests for MACVLAN because we couldn't allocate
487 * memory for the list management required.
489 if (!entry || !entry->free)
493 entry->is_macvlan = true;
495 memcpy(entry->vf_macvlan, mac_addr, ETH_ALEN);
497 hw->mac.ops.set_rar(hw, entry->rar_entry, mac_addr, vf, IXGBE_RAH_AV);
502 int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask)
504 unsigned char vf_mac_addr[6];
505 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
506 unsigned int vfn = (event_mask & 0x3f);
508 bool enable = ((event_mask & 0x10000000U) != 0);
511 eth_random_addr(vf_mac_addr);
512 e_info(probe, "IOV: VF %d is enabled MAC %pM\n",
515 * Store away the VF "permananet" MAC address, it will ask
518 memcpy(adapter->vfinfo[vfn].vf_mac_addresses, vf_mac_addr, 6);
524 static inline void ixgbe_vf_reset_msg(struct ixgbe_adapter *adapter, u32 vf)
526 struct ixgbe_hw *hw = &adapter->hw;
528 u32 reg_offset, vf_shift;
531 reg_offset = vf / 32;
533 /* enable transmit and receive for vf */
534 reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset));
535 reg |= (reg | (1 << vf_shift));
536 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg);
538 reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset));
539 reg |= (reg | (1 << vf_shift));
540 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg);
542 /* Enable counting of spoofed packets in the SSVPC register */
543 reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset));
544 reg |= (1 << vf_shift);
545 IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg);
547 ixgbe_vf_reset_event(adapter, vf);
550 static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf)
552 u32 mbx_size = IXGBE_VFMAILBOX_SIZE;
553 u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
554 struct ixgbe_hw *hw = &adapter->hw;
561 retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf);
564 pr_err("Error receiving message from VF\n");
568 /* this is a message we already processed, do nothing */
569 if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK))
572 /* flush the ack before we write any messages back */
573 IXGBE_WRITE_FLUSH(hw);
576 * until the vf completes a virtual function reset it should not be
577 * allowed to start any configuration.
580 if (msgbuf[0] == IXGBE_VF_RESET) {
581 unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses;
582 new_mac = (u8 *)(&msgbuf[1]);
583 e_info(probe, "VF Reset msg received from vf %d\n", vf);
584 adapter->vfinfo[vf].clear_to_send = false;
585 ixgbe_vf_reset_msg(adapter, vf);
586 adapter->vfinfo[vf].clear_to_send = true;
588 if (is_valid_ether_addr(new_mac) &&
589 !adapter->vfinfo[vf].pf_set_mac)
590 ixgbe_set_vf_mac(adapter, vf, vf_mac);
592 ixgbe_set_vf_mac(adapter,
593 vf, adapter->vfinfo[vf].vf_mac_addresses);
595 /* reply to reset with ack and vf mac address */
596 msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK;
597 memcpy(new_mac, vf_mac, ETH_ALEN);
599 * Piggyback the multicast filter type so VF can compute the
602 msgbuf[3] = hw->mac.mc_filter_type;
603 ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf);
608 if (!adapter->vfinfo[vf].clear_to_send) {
609 msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
610 ixgbe_write_mbx(hw, msgbuf, 1, vf);
614 switch ((msgbuf[0] & 0xFFFF)) {
615 case IXGBE_VF_SET_MAC_ADDR:
616 new_mac = ((u8 *)(&msgbuf[1]));
617 if (is_valid_ether_addr(new_mac) &&
618 !adapter->vfinfo[vf].pf_set_mac) {
619 ixgbe_set_vf_mac(adapter, vf, new_mac);
620 } else if (memcmp(adapter->vfinfo[vf].vf_mac_addresses,
621 new_mac, ETH_ALEN)) {
622 e_warn(drv, "VF %d attempted to override "
623 "administratively set MAC address\nReload "
624 "the VF driver to resume operations\n", vf);
628 case IXGBE_VF_SET_MULTICAST:
629 entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
630 >> IXGBE_VT_MSGINFO_SHIFT;
631 hash_list = (u16 *)&msgbuf[1];
632 retval = ixgbe_set_vf_multicasts(adapter, entries,
635 case IXGBE_VF_SET_LPE:
636 ixgbe_set_vf_lpe(adapter, msgbuf);
638 case IXGBE_VF_SET_VLAN:
639 add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
640 >> IXGBE_VT_MSGINFO_SHIFT;
641 vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK);
642 if (adapter->vfinfo[vf].pf_vlan) {
643 e_warn(drv, "VF %d attempted to override "
644 "administratively set VLAN configuration\n"
645 "Reload the VF driver to resume operations\n",
650 adapter->vfinfo[vf].vlan_count++;
651 else if (adapter->vfinfo[vf].vlan_count)
652 adapter->vfinfo[vf].vlan_count--;
653 retval = ixgbe_set_vf_vlan(adapter, add, vid, vf);
654 if (!retval && adapter->vfinfo[vf].spoofchk_enabled)
655 hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf);
658 case IXGBE_VF_SET_MACVLAN:
659 index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >>
660 IXGBE_VT_MSGINFO_SHIFT;
661 if (adapter->vfinfo[vf].pf_set_mac && index > 0) {
662 e_warn(drv, "VF %d requested MACVLAN filter but is "
663 "administratively denied\n", vf);
668 * If the VF is allowed to set MAC filters then turn off
669 * anti-spoofing to avoid false positives. An index
670 * greater than 0 will indicate the VF is setting a
671 * macvlan MAC filter.
673 if (index > 0 && adapter->vfinfo[vf].spoofchk_enabled)
674 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, vf, false);
675 retval = ixgbe_set_vf_macvlan(adapter, vf, index,
676 (unsigned char *)(&msgbuf[1]));
677 if (retval == -ENOSPC)
678 e_warn(drv, "VF %d has requested a MACVLAN filter "
679 "but there is no space for it\n", vf);
682 e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]);
683 retval = IXGBE_ERR_MBX;
687 /* notify the VF of the results of what it sent us */
689 msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
691 msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK;
693 msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS;
695 ixgbe_write_mbx(hw, msgbuf, 1, vf);
700 static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf)
702 struct ixgbe_hw *hw = &adapter->hw;
703 u32 msg = IXGBE_VT_MSGTYPE_NACK;
705 /* if device isn't clear to send it shouldn't be reading either */
706 if (!adapter->vfinfo[vf].clear_to_send)
707 ixgbe_write_mbx(hw, &msg, 1, vf);
710 void ixgbe_msg_task(struct ixgbe_adapter *adapter)
712 struct ixgbe_hw *hw = &adapter->hw;
715 for (vf = 0; vf < adapter->num_vfs; vf++) {
716 /* process any reset requests */
717 if (!ixgbe_check_for_rst(hw, vf))
718 ixgbe_vf_reset_event(adapter, vf);
720 /* process any messages pending */
721 if (!ixgbe_check_for_msg(hw, vf))
722 ixgbe_rcv_msg_from_vf(adapter, vf);
724 /* process any acks */
725 if (!ixgbe_check_for_ack(hw, vf))
726 ixgbe_rcv_ack_from_vf(adapter, vf);
730 void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter)
732 struct ixgbe_hw *hw = &adapter->hw;
734 /* disable transmit and receive for all vfs */
735 IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0);
736 IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0);
738 IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0);
739 IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0);
742 void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter)
744 struct ixgbe_hw *hw = &adapter->hw;
748 for (i = 0 ; i < adapter->num_vfs; i++) {
749 ping = IXGBE_PF_CONTROL_MSG;
750 if (adapter->vfinfo[i].clear_to_send)
751 ping |= IXGBE_VT_MSGTYPE_CTS;
752 ixgbe_write_mbx(hw, &ping, 1, i);
756 int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
758 struct ixgbe_adapter *adapter = netdev_priv(netdev);
759 if (!is_valid_ether_addr(mac) || (vf >= adapter->num_vfs))
761 adapter->vfinfo[vf].pf_set_mac = true;
762 dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
763 dev_info(&adapter->pdev->dev, "Reload the VF driver to make this"
764 " change effective.");
765 if (test_bit(__IXGBE_DOWN, &adapter->state)) {
766 dev_warn(&adapter->pdev->dev, "The VF MAC address has been set,"
767 " but the PF device is not up.\n");
768 dev_warn(&adapter->pdev->dev, "Bring the PF device up before"
769 " attempting to use the VF device.\n");
771 return ixgbe_set_vf_mac(adapter, vf, mac);
774 int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos)
777 struct ixgbe_adapter *adapter = netdev_priv(netdev);
778 struct ixgbe_hw *hw = &adapter->hw;
780 if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7))
783 err = ixgbe_set_vf_vlan(adapter, true, vlan, vf);
786 ixgbe_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
787 ixgbe_set_vmolr(hw, vf, false);
788 if (adapter->vfinfo[vf].spoofchk_enabled)
789 hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf);
790 adapter->vfinfo[vf].vlan_count++;
791 adapter->vfinfo[vf].pf_vlan = vlan;
792 adapter->vfinfo[vf].pf_qos = qos;
793 dev_info(&adapter->pdev->dev,
794 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
795 if (test_bit(__IXGBE_DOWN, &adapter->state)) {
796 dev_warn(&adapter->pdev->dev,
797 "The VF VLAN has been set,"
798 " but the PF device is not up.\n");
799 dev_warn(&adapter->pdev->dev,
800 "Bring the PF device up before"
801 " attempting to use the VF device.\n");
804 err = ixgbe_set_vf_vlan(adapter, false,
805 adapter->vfinfo[vf].pf_vlan, vf);
806 ixgbe_set_vmvir(adapter, vlan, vf);
807 ixgbe_set_vmolr(hw, vf, true);
808 hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf);
809 if (adapter->vfinfo[vf].vlan_count)
810 adapter->vfinfo[vf].vlan_count--;
811 adapter->vfinfo[vf].pf_vlan = 0;
812 adapter->vfinfo[vf].pf_qos = 0;
818 static int ixgbe_link_mbps(struct ixgbe_adapter *adapter)
820 switch (adapter->link_speed) {
821 case IXGBE_LINK_SPEED_100_FULL:
823 case IXGBE_LINK_SPEED_1GB_FULL:
825 case IXGBE_LINK_SPEED_10GB_FULL:
832 static void ixgbe_set_vf_rate_limit(struct ixgbe_adapter *adapter, int vf)
834 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
835 struct ixgbe_hw *hw = &adapter->hw;
837 u16 queue, queues_per_pool;
838 u16 tx_rate = adapter->vfinfo[vf].tx_rate;
841 /* start with base link speed value */
842 bcnrc_val = adapter->vf_rate_link_speed;
844 /* Calculate the rate factor values to set */
845 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
846 bcnrc_val /= tx_rate;
848 /* clear everything but the rate factor */
849 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
850 IXGBE_RTTBCNRC_RF_DEC_MASK;
852 /* enable the rate scheduler */
853 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
857 * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
858 * register. Typically MMW_SIZE=0x014 if 9728-byte jumbo is supported
859 * and 0x004 otherwise.
861 switch (hw->mac.type) {
862 case ixgbe_mac_82599EB:
863 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x4);
866 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x14);
872 /* determine how many queues per pool based on VMDq mask */
873 queues_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
875 /* write value for all Tx queues belonging to VF */
876 for (queue = 0; queue < queues_per_pool; queue++) {
877 unsigned int reg_idx = (vf * queues_per_pool) + queue;
879 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, reg_idx);
880 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
884 void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter)
888 /* VF Tx rate limit was not set */
889 if (!adapter->vf_rate_link_speed)
892 if (ixgbe_link_mbps(adapter) != adapter->vf_rate_link_speed) {
893 adapter->vf_rate_link_speed = 0;
894 dev_info(&adapter->pdev->dev,
895 "Link speed has been changed. VF Transmit rate is disabled\n");
898 for (i = 0; i < adapter->num_vfs; i++) {
899 if (!adapter->vf_rate_link_speed)
900 adapter->vfinfo[i].tx_rate = 0;
902 ixgbe_set_vf_rate_limit(adapter, i);
906 int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate)
908 struct ixgbe_adapter *adapter = netdev_priv(netdev);
911 /* verify VF is active */
912 if (vf >= adapter->num_vfs)
915 /* verify link is up */
916 if (!adapter->link_up)
919 /* verify we are linked at 10Gbps */
920 link_speed = ixgbe_link_mbps(adapter);
921 if (link_speed != 10000)
924 /* rate limit cannot be less than 10Mbs or greater than link speed */
925 if (tx_rate && ((tx_rate <= 10) || (tx_rate > link_speed)))
929 adapter->vf_rate_link_speed = link_speed;
930 adapter->vfinfo[vf].tx_rate = tx_rate;
932 /* update hardware configuration */
933 ixgbe_set_vf_rate_limit(adapter, vf);
938 int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
940 struct ixgbe_adapter *adapter = netdev_priv(netdev);
941 int vf_target_reg = vf >> 3;
942 int vf_target_shift = vf % 8;
943 struct ixgbe_hw *hw = &adapter->hw;
946 adapter->vfinfo[vf].spoofchk_enabled = setting;
948 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
949 regval &= ~(1 << vf_target_shift);
950 regval |= (setting << vf_target_shift);
951 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), regval);
953 if (adapter->vfinfo[vf].vlan_count) {
954 vf_target_shift += IXGBE_SPOOF_VLANAS_SHIFT;
955 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
956 regval &= ~(1 << vf_target_shift);
957 regval |= (setting << vf_target_shift);
958 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), regval);
964 int ixgbe_ndo_get_vf_config(struct net_device *netdev,
965 int vf, struct ifla_vf_info *ivi)
967 struct ixgbe_adapter *adapter = netdev_priv(netdev);
968 if (vf >= adapter->num_vfs)
971 memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN);
972 ivi->tx_rate = adapter->vfinfo[vf].tx_rate;
973 ivi->vlan = adapter->vfinfo[vf].pf_vlan;
974 ivi->qos = adapter->vfinfo[vf].pf_qos;
975 ivi->spoofchk = adapter->vfinfo[vf].spoofchk_enabled;