1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2011 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".
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 static int ixgbe_find_enabled_vfs(struct ixgbe_adapter *adapter)
49 struct pci_dev *pdev = adapter->pdev;
50 struct pci_dev *pvfdev;
55 switch (adapter->hw.mac.type) {
56 case ixgbe_mac_82599EB:
57 device_id = IXGBE_DEV_ID_82599_VF;
60 device_id = IXGBE_DEV_ID_X540_VF;
67 vf_devfn = pdev->devfn + 0x80;
68 pvfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
70 if (pvfdev->devfn == vf_devfn)
73 pvfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
80 void ixgbe_enable_sriov(struct ixgbe_adapter *adapter,
81 const struct ixgbe_info *ii)
83 struct ixgbe_hw *hw = &adapter->hw;
85 int num_vf_macvlans, i;
86 struct vf_macvlans *mv_list;
87 int pre_existing_vfs = 0;
89 pre_existing_vfs = ixgbe_find_enabled_vfs(adapter);
90 if (!pre_existing_vfs && !adapter->num_vfs)
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.
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");
108 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
111 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
114 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
116 e_info(probe, "SR-IOV enabled with %d VFs\n", adapter->num_vfs);
118 num_vf_macvlans = hw->mac.num_rar_entries -
119 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
121 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
122 sizeof(struct vf_macvlans),
125 /* Initialize list of VF macvlans */
126 INIT_LIST_HEAD(&adapter->vf_mvs.l);
127 for (i = 0; i < num_vf_macvlans; i++) {
129 mv_list->free = true;
130 mv_list->rar_entry = hw->mac.num_rar_entries -
131 (i + adapter->num_vfs + 1);
132 list_add(&mv_list->l, &adapter->vf_mvs.l);
137 /* If call to enable VFs succeeded then allocate memory
138 * for per VF control structures.
141 kcalloc(adapter->num_vfs,
142 sizeof(struct vf_data_storage), GFP_KERNEL);
143 if (adapter->vfinfo) {
144 /* Now that we're sure SR-IOV is enabled
145 * and memory allocated set up the mailbox parameters
147 ixgbe_init_mbx_params_pf(hw);
148 memcpy(&hw->mbx.ops, ii->mbx_ops,
149 sizeof(hw->mbx.ops));
151 /* Disable RSC when in SR-IOV mode */
152 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
153 IXGBE_FLAG2_RSC_ENABLED);
154 for (i = 0; i < adapter->num_vfs; i++)
155 adapter->vfinfo[i].spoofchk_enabled = true;
160 e_err(probe, "Unable to allocate memory for VF Data Storage - "
162 pci_disable_sriov(adapter->pdev);
165 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
166 adapter->num_vfs = 0;
168 #endif /* #ifdef CONFIG_PCI_IOV */
170 void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
172 struct ixgbe_hw *hw = &adapter->hw;
178 #ifdef CONFIG_PCI_IOV
179 /* disable iov and allow time for transactions to clear */
180 pci_disable_sriov(adapter->pdev);
183 /* turn off device IOV mode */
184 gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
185 gcr &= ~(IXGBE_GCR_EXT_SRIOV);
186 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
187 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
188 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
189 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
191 /* set default pool back to 0 */
192 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
193 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
194 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
195 IXGBE_WRITE_FLUSH(hw);
197 /* take a breather then clean up driver data */
200 /* Release reference to VF devices */
201 for (i = 0; i < adapter->num_vfs; i++) {
202 if (adapter->vfinfo[i].vfdev)
203 pci_dev_put(adapter->vfinfo[i].vfdev);
205 kfree(adapter->vfinfo);
206 kfree(adapter->mv_list);
207 adapter->vfinfo = NULL;
209 adapter->num_vfs = 0;
210 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
213 static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter,
214 int entries, u16 *hash_list, u32 vf)
216 struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
217 struct ixgbe_hw *hw = &adapter->hw;
223 /* only so many hash values supported */
224 entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES);
227 * salt away the number of multi cast addresses assigned
228 * to this VF for later use to restore when the PF multi cast
231 vfinfo->num_vf_mc_hashes = entries;
234 * VFs are limited to using the MTA hash table for their multicast
237 for (i = 0; i < entries; i++) {
238 vfinfo->vf_mc_hashes[i] = hash_list[i];
241 for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
242 vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F;
243 vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F;
244 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
245 mta_reg |= (1 << vector_bit);
246 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
252 static void ixgbe_restore_vf_macvlans(struct ixgbe_adapter *adapter)
254 struct ixgbe_hw *hw = &adapter->hw;
255 struct list_head *pos;
256 struct vf_macvlans *entry;
258 list_for_each(pos, &adapter->vf_mvs.l) {
259 entry = list_entry(pos, struct vf_macvlans, l);
260 if (entry->free == false)
261 hw->mac.ops.set_rar(hw, entry->rar_entry,
263 entry->vf, IXGBE_RAH_AV);
267 void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter)
269 struct ixgbe_hw *hw = &adapter->hw;
270 struct vf_data_storage *vfinfo;
276 for (i = 0; i < adapter->num_vfs; i++) {
277 vfinfo = &adapter->vfinfo[i];
278 for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) {
279 hw->addr_ctrl.mta_in_use++;
280 vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F;
281 vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F;
282 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
283 mta_reg |= (1 << vector_bit);
284 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
288 /* Restore any VF macvlans */
289 ixgbe_restore_vf_macvlans(adapter);
292 static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid,
295 return adapter->hw.mac.ops.set_vfta(&adapter->hw, vid, vf, (bool)add);
298 static void ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf)
300 struct ixgbe_hw *hw = &adapter->hw;
301 int new_mtu = msgbuf[1];
303 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
305 /* Only X540 supports jumbo frames in IOV mode */
306 if (adapter->hw.mac.type != ixgbe_mac_X540)
309 /* MTU < 68 is an error and causes problems on some kernels */
310 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) {
311 e_err(drv, "VF mtu %d out of range\n", new_mtu);
315 max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) &
316 IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT;
317 if (max_frs < new_mtu) {
318 max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT;
319 IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs);
322 e_info(hw, "VF requests change max MTU to %d\n", new_mtu);
325 static void ixgbe_set_vmolr(struct ixgbe_hw *hw, u32 vf, bool aupe)
327 u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
328 vmolr |= (IXGBE_VMOLR_ROMPE |
331 vmolr |= IXGBE_VMOLR_AUPE;
333 vmolr &= ~IXGBE_VMOLR_AUPE;
334 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
337 static void ixgbe_set_vmvir(struct ixgbe_adapter *adapter, u32 vid, u32 vf)
339 struct ixgbe_hw *hw = &adapter->hw;
342 IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf),
343 (vid | IXGBE_VMVIR_VLANA_DEFAULT));
345 IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0);
348 static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf)
350 struct ixgbe_hw *hw = &adapter->hw;
351 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
353 /* reset offloads to defaults */
354 if (adapter->vfinfo[vf].pf_vlan) {
355 ixgbe_set_vf_vlan(adapter, true,
356 adapter->vfinfo[vf].pf_vlan, vf);
357 ixgbe_set_vmvir(adapter,
358 (adapter->vfinfo[vf].pf_vlan |
359 (adapter->vfinfo[vf].pf_qos <<
360 VLAN_PRIO_SHIFT)), vf);
361 ixgbe_set_vmolr(hw, vf, false);
363 ixgbe_set_vmvir(adapter, 0, vf);
364 ixgbe_set_vmolr(hw, vf, true);
367 /* reset multicast table array for vf */
368 adapter->vfinfo[vf].num_vf_mc_hashes = 0;
370 /* Flush and reset the mta with the new values */
371 ixgbe_set_rx_mode(adapter->netdev);
373 hw->mac.ops.clear_rar(hw, rar_entry);
376 static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter,
377 int vf, unsigned char *mac_addr)
379 struct ixgbe_hw *hw = &adapter->hw;
380 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
382 memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, 6);
383 hw->mac.ops.set_rar(hw, rar_entry, mac_addr, vf, IXGBE_RAH_AV);
388 static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter,
389 int vf, int index, unsigned char *mac_addr)
391 struct ixgbe_hw *hw = &adapter->hw;
392 struct list_head *pos;
393 struct vf_macvlans *entry;
396 list_for_each(pos, &adapter->vf_mvs.l) {
397 entry = list_entry(pos, struct vf_macvlans, l);
398 if (entry->vf == vf) {
401 entry->is_macvlan = false;
402 hw->mac.ops.clear_rar(hw, entry->rar_entry);
408 * If index was zero then we were asked to clear the uc list
409 * for the VF. We're done.
416 list_for_each(pos, &adapter->vf_mvs.l) {
417 entry = list_entry(pos, struct vf_macvlans, l);
423 * If we traversed the entire list and didn't find a free entry
424 * then we're out of space on the RAR table. Also entry may
425 * be NULL because the original memory allocation for the list
426 * failed, which is not fatal but does mean we can't support
427 * VF requests for MACVLAN because we couldn't allocate
428 * memory for the list management required.
430 if (!entry || !entry->free)
434 entry->is_macvlan = true;
436 memcpy(entry->vf_macvlan, mac_addr, ETH_ALEN);
438 hw->mac.ops.set_rar(hw, entry->rar_entry, mac_addr, vf, IXGBE_RAH_AV);
443 int ixgbe_check_vf_assignment(struct ixgbe_adapter *adapter)
445 #ifdef CONFIG_PCI_IOV
447 for (i = 0; i < adapter->num_vfs; i++) {
448 if (adapter->vfinfo[i].vfdev->dev_flags &
449 PCI_DEV_FLAGS_ASSIGNED)
456 int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask)
458 unsigned char vf_mac_addr[6];
459 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
460 unsigned int vfn = (event_mask & 0x3f);
461 struct pci_dev *pvfdev;
462 unsigned int device_id;
463 u16 thisvf_devfn = (pdev->devfn + 0x80 + (vfn << 1)) |
466 bool enable = ((event_mask & 0x10000000U) != 0);
469 random_ether_addr(vf_mac_addr);
470 e_info(probe, "IOV: VF %d is enabled MAC %pM\n",
473 * Store away the VF "permananet" MAC address, it will ask
476 memcpy(adapter->vfinfo[vfn].vf_mac_addresses, vf_mac_addr, 6);
478 switch (adapter->hw.mac.type) {
479 case ixgbe_mac_82599EB:
480 device_id = IXGBE_DEV_ID_82599_VF;
483 device_id = IXGBE_DEV_ID_X540_VF;
490 pvfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
492 if (pvfdev->devfn == thisvf_devfn)
494 pvfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
498 adapter->vfinfo[vfn].vfdev = pvfdev;
500 e_err(drv, "Couldn't find pci dev ptr for VF %4.4x\n",
507 static inline void ixgbe_vf_reset_msg(struct ixgbe_adapter *adapter, u32 vf)
509 struct ixgbe_hw *hw = &adapter->hw;
511 u32 reg_offset, vf_shift;
514 reg_offset = vf / 32;
516 /* enable transmit and receive for vf */
517 reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset));
518 reg |= (reg | (1 << vf_shift));
519 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg);
521 reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset));
522 reg |= (reg | (1 << vf_shift));
523 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg);
525 /* Enable counting of spoofed packets in the SSVPC register */
526 reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset));
527 reg |= (1 << vf_shift);
528 IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg);
530 ixgbe_vf_reset_event(adapter, vf);
533 static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf)
535 u32 mbx_size = IXGBE_VFMAILBOX_SIZE;
536 u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
537 struct ixgbe_hw *hw = &adapter->hw;
544 retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf);
547 pr_err("Error receiving message from VF\n");
549 /* this is a message we already processed, do nothing */
550 if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK))
554 * until the vf completes a virtual function reset it should not be
555 * allowed to start any configuration.
558 if (msgbuf[0] == IXGBE_VF_RESET) {
559 unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses;
560 new_mac = (u8 *)(&msgbuf[1]);
561 e_info(probe, "VF Reset msg received from vf %d\n", vf);
562 adapter->vfinfo[vf].clear_to_send = false;
563 ixgbe_vf_reset_msg(adapter, vf);
564 adapter->vfinfo[vf].clear_to_send = true;
566 if (is_valid_ether_addr(new_mac) &&
567 !adapter->vfinfo[vf].pf_set_mac)
568 ixgbe_set_vf_mac(adapter, vf, vf_mac);
570 ixgbe_set_vf_mac(adapter,
571 vf, adapter->vfinfo[vf].vf_mac_addresses);
573 /* reply to reset with ack and vf mac address */
574 msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK;
575 memcpy(new_mac, vf_mac, ETH_ALEN);
577 * Piggyback the multicast filter type so VF can compute the
580 msgbuf[3] = hw->mac.mc_filter_type;
581 ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf);
586 if (!adapter->vfinfo[vf].clear_to_send) {
587 msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
588 ixgbe_write_mbx(hw, msgbuf, 1, vf);
592 switch ((msgbuf[0] & 0xFFFF)) {
593 case IXGBE_VF_SET_MAC_ADDR:
594 new_mac = ((u8 *)(&msgbuf[1]));
595 if (is_valid_ether_addr(new_mac) &&
596 !adapter->vfinfo[vf].pf_set_mac) {
597 ixgbe_set_vf_mac(adapter, vf, new_mac);
598 } else if (memcmp(adapter->vfinfo[vf].vf_mac_addresses,
599 new_mac, ETH_ALEN)) {
600 e_warn(drv, "VF %d attempted to override "
601 "administratively set MAC address\nReload "
602 "the VF driver to resume operations\n", vf);
606 case IXGBE_VF_SET_MULTICAST:
607 entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
608 >> IXGBE_VT_MSGINFO_SHIFT;
609 hash_list = (u16 *)&msgbuf[1];
610 retval = ixgbe_set_vf_multicasts(adapter, entries,
613 case IXGBE_VF_SET_LPE:
614 ixgbe_set_vf_lpe(adapter, msgbuf);
616 case IXGBE_VF_SET_VLAN:
617 add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
618 >> IXGBE_VT_MSGINFO_SHIFT;
619 vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK);
620 if (adapter->vfinfo[vf].pf_vlan) {
621 e_warn(drv, "VF %d attempted to override "
622 "administratively set VLAN configuration\n"
623 "Reload the VF driver to resume operations\n",
628 adapter->vfinfo[vf].vlan_count++;
629 else if (adapter->vfinfo[vf].vlan_count)
630 adapter->vfinfo[vf].vlan_count--;
631 retval = ixgbe_set_vf_vlan(adapter, add, vid, vf);
632 if (!retval && adapter->vfinfo[vf].spoofchk_enabled)
633 hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf);
636 case IXGBE_VF_SET_MACVLAN:
637 index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >>
638 IXGBE_VT_MSGINFO_SHIFT;
640 * If the VF is allowed to set MAC filters then turn off
641 * anti-spoofing to avoid false positives. An index
642 * greater than 0 will indicate the VF is setting a
643 * macvlan MAC filter.
645 if (index > 0 && adapter->vfinfo[vf].spoofchk_enabled)
646 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, vf, false);
647 retval = ixgbe_set_vf_macvlan(adapter, vf, index,
648 (unsigned char *)(&msgbuf[1]));
651 e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]);
652 retval = IXGBE_ERR_MBX;
656 /* notify the VF of the results of what it sent us */
658 msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
660 msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK;
662 msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS;
664 ixgbe_write_mbx(hw, msgbuf, 1, vf);
669 static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf)
671 struct ixgbe_hw *hw = &adapter->hw;
672 u32 msg = IXGBE_VT_MSGTYPE_NACK;
674 /* if device isn't clear to send it shouldn't be reading either */
675 if (!adapter->vfinfo[vf].clear_to_send)
676 ixgbe_write_mbx(hw, &msg, 1, vf);
679 void ixgbe_msg_task(struct ixgbe_adapter *adapter)
681 struct ixgbe_hw *hw = &adapter->hw;
684 for (vf = 0; vf < adapter->num_vfs; vf++) {
685 /* process any reset requests */
686 if (!ixgbe_check_for_rst(hw, vf))
687 ixgbe_vf_reset_event(adapter, vf);
689 /* process any messages pending */
690 if (!ixgbe_check_for_msg(hw, vf))
691 ixgbe_rcv_msg_from_vf(adapter, vf);
693 /* process any acks */
694 if (!ixgbe_check_for_ack(hw, vf))
695 ixgbe_rcv_ack_from_vf(adapter, vf);
699 void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter)
701 struct ixgbe_hw *hw = &adapter->hw;
703 /* disable transmit and receive for all vfs */
704 IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0);
705 IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0);
707 IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0);
708 IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0);
711 void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter)
713 struct ixgbe_hw *hw = &adapter->hw;
717 for (i = 0 ; i < adapter->num_vfs; i++) {
718 ping = IXGBE_PF_CONTROL_MSG;
719 if (adapter->vfinfo[i].clear_to_send)
720 ping |= IXGBE_VT_MSGTYPE_CTS;
721 ixgbe_write_mbx(hw, &ping, 1, i);
725 int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
727 struct ixgbe_adapter *adapter = netdev_priv(netdev);
728 if (!is_valid_ether_addr(mac) || (vf >= adapter->num_vfs))
730 adapter->vfinfo[vf].pf_set_mac = true;
731 dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
732 dev_info(&adapter->pdev->dev, "Reload the VF driver to make this"
733 " change effective.");
734 if (test_bit(__IXGBE_DOWN, &adapter->state)) {
735 dev_warn(&adapter->pdev->dev, "The VF MAC address has been set,"
736 " but the PF device is not up.\n");
737 dev_warn(&adapter->pdev->dev, "Bring the PF device up before"
738 " attempting to use the VF device.\n");
740 return ixgbe_set_vf_mac(adapter, vf, mac);
743 int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos)
746 struct ixgbe_adapter *adapter = netdev_priv(netdev);
747 struct ixgbe_hw *hw = &adapter->hw;
749 if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7))
752 err = ixgbe_set_vf_vlan(adapter, true, vlan, vf);
755 ixgbe_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
756 ixgbe_set_vmolr(hw, vf, false);
757 if (adapter->vfinfo[vf].spoofchk_enabled)
758 hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf);
759 adapter->vfinfo[vf].vlan_count++;
760 adapter->vfinfo[vf].pf_vlan = vlan;
761 adapter->vfinfo[vf].pf_qos = qos;
762 dev_info(&adapter->pdev->dev,
763 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
764 if (test_bit(__IXGBE_DOWN, &adapter->state)) {
765 dev_warn(&adapter->pdev->dev,
766 "The VF VLAN has been set,"
767 " but the PF device is not up.\n");
768 dev_warn(&adapter->pdev->dev,
769 "Bring the PF device up before"
770 " attempting to use the VF device.\n");
773 err = ixgbe_set_vf_vlan(adapter, false,
774 adapter->vfinfo[vf].pf_vlan, vf);
775 ixgbe_set_vmvir(adapter, vlan, vf);
776 ixgbe_set_vmolr(hw, vf, true);
777 hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf);
778 if (adapter->vfinfo[vf].vlan_count)
779 adapter->vfinfo[vf].vlan_count--;
780 adapter->vfinfo[vf].pf_vlan = 0;
781 adapter->vfinfo[vf].pf_qos = 0;
787 static int ixgbe_link_mbps(int internal_link_speed)
789 switch (internal_link_speed) {
790 case IXGBE_LINK_SPEED_100_FULL:
792 case IXGBE_LINK_SPEED_1GB_FULL:
794 case IXGBE_LINK_SPEED_10GB_FULL:
801 static void ixgbe_set_vf_rate_limit(struct ixgbe_hw *hw, int vf, int tx_rate,
808 /* Calculate the rate factor values to set */
809 rf_int = link_speed / tx_rate;
810 rf_dec = (link_speed - (rf_int * tx_rate));
811 rf_dec = (rf_dec * (1<<IXGBE_RTTBCNRC_RF_INT_SHIFT)) / tx_rate;
813 bcnrc_val = IXGBE_RTTBCNRC_RS_ENA;
814 bcnrc_val |= ((rf_int<<IXGBE_RTTBCNRC_RF_INT_SHIFT) &
815 IXGBE_RTTBCNRC_RF_INT_MASK);
816 bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK);
821 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, 2*vf); /* vf Y uses queue 2*Y */
823 * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
824 * register. Typically MMW_SIZE=0x014 if 9728-byte jumbo is supported
825 * and 0x004 otherwise.
827 switch (hw->mac.type) {
828 case ixgbe_mac_82599EB:
829 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x4);
832 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x14);
838 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
841 void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter)
843 int actual_link_speed, i;
844 bool reset_rate = false;
846 /* VF Tx rate limit was not set */
847 if (adapter->vf_rate_link_speed == 0)
850 actual_link_speed = ixgbe_link_mbps(adapter->link_speed);
851 if (actual_link_speed != adapter->vf_rate_link_speed) {
853 adapter->vf_rate_link_speed = 0;
854 dev_info(&adapter->pdev->dev,
855 "Link speed has been changed. VF Transmit rate "
859 for (i = 0; i < adapter->num_vfs; i++) {
861 adapter->vfinfo[i].tx_rate = 0;
863 ixgbe_set_vf_rate_limit(&adapter->hw, i,
864 adapter->vfinfo[i].tx_rate,
869 int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate)
871 struct ixgbe_adapter *adapter = netdev_priv(netdev);
872 struct ixgbe_hw *hw = &adapter->hw;
873 int actual_link_speed;
875 actual_link_speed = ixgbe_link_mbps(adapter->link_speed);
876 if ((vf >= adapter->num_vfs) || (!adapter->link_up) ||
877 (tx_rate > actual_link_speed) || (actual_link_speed != 10000) ||
878 ((tx_rate != 0) && (tx_rate <= 10)))
879 /* rate limit cannot be set to 10Mb or less in 10Gb adapters */
882 adapter->vf_rate_link_speed = actual_link_speed;
883 adapter->vfinfo[vf].tx_rate = (u16)tx_rate;
884 ixgbe_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed);
889 int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
891 struct ixgbe_adapter *adapter = netdev_priv(netdev);
892 int vf_target_reg = vf >> 3;
893 int vf_target_shift = vf % 8;
894 struct ixgbe_hw *hw = &adapter->hw;
897 adapter->vfinfo[vf].spoofchk_enabled = setting;
899 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
900 regval &= ~(1 << vf_target_shift);
901 regval |= (setting << vf_target_shift);
902 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), regval);
904 if (adapter->vfinfo[vf].vlan_count) {
905 vf_target_shift += IXGBE_SPOOF_VLANAS_SHIFT;
906 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
907 regval &= ~(1 << vf_target_shift);
908 regval |= (setting << vf_target_shift);
909 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), regval);
915 int ixgbe_ndo_get_vf_config(struct net_device *netdev,
916 int vf, struct ifla_vf_info *ivi)
918 struct ixgbe_adapter *adapter = netdev_priv(netdev);
919 if (vf >= adapter->num_vfs)
922 memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN);
923 ivi->tx_rate = adapter->vfinfo[vf].tx_rate;
924 ivi->vlan = adapter->vfinfo[vf].pf_vlan;
925 ivi->qos = adapter->vfinfo[vf].pf_qos;
926 ivi->spoofchk = adapter->vfinfo[vf].spoofchk_enabled;