/drivers/net/ixgbe/ixgbe_sriov.c
C | 671 lines | 492 code | 94 blank | 85 comment | 75 complexity | 1d13136600801fd7926c52b2d026a8de MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
- /*******************************************************************************
- Intel 10 Gigabit PCI Express Linux driver
- Copyright(c) 1999 - 2011 Intel Corporation.
- This program is free software; you can redistribute it and/or modify it
- under the terms and conditions of the GNU General Public License,
- version 2, as published by the Free Software Foundation.
- This program is distributed in the hope it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- more details.
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- The full GNU General Public License is included in this distribution in
- the file called "COPYING".
- Contact Information:
- e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
- Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
- *******************************************************************************/
- #include <linux/types.h>
- #include <linux/module.h>
- #include <linux/pci.h>
- #include <linux/netdevice.h>
- #include <linux/vmalloc.h>
- #include <linux/string.h>
- #include <linux/in.h>
- #include <linux/ip.h>
- #include <linux/tcp.h>
- #include <linux/ipv6.h>
- #ifdef NETIF_F_HW_VLAN_TX
- #include <linux/if_vlan.h>
- #endif
- #include "ixgbe.h"
- #include "ixgbe_sriov.h"
- static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter,
- int entries, u16 *hash_list, u32 vf)
- {
- struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
- struct ixgbe_hw *hw = &adapter->hw;
- int i;
- u32 vector_bit;
- u32 vector_reg;
- u32 mta_reg;
- /* only so many hash values supported */
- entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES);
- /*
- * salt away the number of multi cast addresses assigned
- * to this VF for later use to restore when the PF multi cast
- * list changes
- */
- vfinfo->num_vf_mc_hashes = entries;
- /*
- * VFs are limited to using the MTA hash table for their multicast
- * addresses
- */
- for (i = 0; i < entries; i++) {
- vfinfo->vf_mc_hashes[i] = hash_list[i];
- }
- for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
- vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F;
- vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F;
- mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
- mta_reg |= (1 << vector_bit);
- IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
- }
- return 0;
- }
- static void ixgbe_restore_vf_macvlans(struct ixgbe_adapter *adapter)
- {
- struct ixgbe_hw *hw = &adapter->hw;
- struct list_head *pos;
- struct vf_macvlans *entry;
- list_for_each(pos, &adapter->vf_mvs.l) {
- entry = list_entry(pos, struct vf_macvlans, l);
- if (entry->free == false)
- hw->mac.ops.set_rar(hw, entry->rar_entry,
- entry->vf_macvlan,
- entry->vf, IXGBE_RAH_AV);
- }
- }
- void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter)
- {
- struct ixgbe_hw *hw = &adapter->hw;
- struct vf_data_storage *vfinfo;
- int i, j;
- u32 vector_bit;
- u32 vector_reg;
- u32 mta_reg;
- for (i = 0; i < adapter->num_vfs; i++) {
- vfinfo = &adapter->vfinfo[i];
- for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) {
- hw->addr_ctrl.mta_in_use++;
- vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F;
- vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F;
- mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
- mta_reg |= (1 << vector_bit);
- IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
- }
- }
- /* Restore any VF macvlans */
- ixgbe_restore_vf_macvlans(adapter);
- }
- static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid,
- u32 vf)
- {
- return adapter->hw.mac.ops.set_vfta(&adapter->hw, vid, vf, (bool)add);
- }
- static void ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf)
- {
- struct ixgbe_hw *hw = &adapter->hw;
- int new_mtu = msgbuf[1];
- u32 max_frs;
- int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
- /* Only X540 supports jumbo frames in IOV mode */
- if (adapter->hw.mac.type != ixgbe_mac_X540)
- return;
- /* MTU < 68 is an error and causes problems on some kernels */
- if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) {
- e_err(drv, "VF mtu %d out of range\n", new_mtu);
- return;
- }
- max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) &
- IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT;
- if (max_frs < new_mtu) {
- max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT;
- IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs);
- }
- e_info(hw, "VF requests change max MTU to %d\n", new_mtu);
- }
- static void ixgbe_set_vmolr(struct ixgbe_hw *hw, u32 vf, bool aupe)
- {
- u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
- vmolr |= (IXGBE_VMOLR_ROMPE |
- IXGBE_VMOLR_BAM);
- if (aupe)
- vmolr |= IXGBE_VMOLR_AUPE;
- else
- vmolr &= ~IXGBE_VMOLR_AUPE;
- IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
- }
- static void ixgbe_set_vmvir(struct ixgbe_adapter *adapter, u32 vid, u32 vf)
- {
- struct ixgbe_hw *hw = &adapter->hw;
- if (vid)
- IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf),
- (vid | IXGBE_VMVIR_VLANA_DEFAULT));
- else
- IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0);
- }
- static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf)
- {
- struct ixgbe_hw *hw = &adapter->hw;
- int rar_entry = hw->mac.num_rar_entries - (vf + 1);
- /* reset offloads to defaults */
- if (adapter->vfinfo[vf].pf_vlan) {
- ixgbe_set_vf_vlan(adapter, true,
- adapter->vfinfo[vf].pf_vlan, vf);
- ixgbe_set_vmvir(adapter,
- (adapter->vfinfo[vf].pf_vlan |
- (adapter->vfinfo[vf].pf_qos <<
- VLAN_PRIO_SHIFT)), vf);
- ixgbe_set_vmolr(hw, vf, false);
- } else {
- ixgbe_set_vmvir(adapter, 0, vf);
- ixgbe_set_vmolr(hw, vf, true);
- }
- /* reset multicast table array for vf */
- adapter->vfinfo[vf].num_vf_mc_hashes = 0;
- /* Flush and reset the mta with the new values */
- ixgbe_set_rx_mode(adapter->netdev);
- hw->mac.ops.clear_rar(hw, rar_entry);
- }
- static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter,
- int vf, unsigned char *mac_addr)
- {
- struct ixgbe_hw *hw = &adapter->hw;
- int rar_entry = hw->mac.num_rar_entries - (vf + 1);
- memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, 6);
- hw->mac.ops.set_rar(hw, rar_entry, mac_addr, vf, IXGBE_RAH_AV);
- return 0;
- }
- static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter,
- int vf, int index, unsigned char *mac_addr)
- {
- struct ixgbe_hw *hw = &adapter->hw;
- struct list_head *pos;
- struct vf_macvlans *entry;
- if (index <= 1) {
- list_for_each(pos, &adapter->vf_mvs.l) {
- entry = list_entry(pos, struct vf_macvlans, l);
- if (entry->vf == vf) {
- entry->vf = -1;
- entry->free = true;
- entry->is_macvlan = false;
- hw->mac.ops.clear_rar(hw, entry->rar_entry);
- }
- }
- }
- /*
- * If index was zero then we were asked to clear the uc list
- * for the VF. We're done.
- */
- if (!index)
- return 0;
- entry = NULL;