28 #include <linux/types.h>
29 #include <linux/module.h>
30 #include <linux/pci.h>
31 #include <linux/netdevice.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>
51 int num_vf_macvlans,
i;
53 int pre_existing_vfs = 0;
56 if (!pre_existing_vfs && !adapter->
num_vfs)
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");
86 e_err(probe,
"Failed to enable PCI sriov: %d\n", err);
93 e_info(probe,
"SR-IOV enabled with %d VFs\n", adapter->
num_vfs);
101 num_vf_macvlans = hw->
mac.num_rar_entries -
104 adapter->
mv_list = mv_list = kcalloc(num_vf_macvlans,
109 INIT_LIST_HEAD(&adapter->
vf_mvs.l);
110 for (i = 0; i < num_vf_macvlans; i++) {
112 mv_list->
free =
true;
115 list_add(&mv_list->
l, &adapter->
vf_mvs.l);
130 ixgbe_init_mbx_params_pf(hw);
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;
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 - "
175 static bool ixgbe_vfs_are_assigned(
struct ixgbe_adapter *adapter)
181 switch (adapter->
hw.mac.type) {
196 if (vfdev->
is_virtfn && vfdev->physfn == pdev) {
230 #ifdef CONFIG_PCI_IOV
236 if (ixgbe_vfs_are_assigned(adapter)) {
237 e_dev_warn(
"Unloading driver while VFs are assigned - VFs will not be deallocated\n");
267 static int ixgbe_set_vf_multicasts(
struct ixgbe_adapter *adapter,
291 for (i = 0; i <
entries; i++) {
299 mta_reg |= (1 << vector_bit);
306 static void ixgbe_restore_vf_macvlans(
struct ixgbe_adapter *adapter)
330 for (i = 0; i < adapter->
num_vfs; i++) {
337 mta_reg |= (1 << vector_bit);
343 ixgbe_restore_vf_macvlans(adapter);
353 return adapter->
hw.mac.ops.set_vfta(&adapter->
hw, vid, vf, (
bool)add);
359 int new_mtu = msgbuf[1];
369 e_err(drv,
"VF mtu %d out of range\n", new_mtu);
375 if (max_frs < new_mtu) {
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)
406 static inline void ixgbe_vf_reset_event(
struct ixgbe_adapter *adapter,
u32 vf)
409 int rar_entry = hw->
mac.num_rar_entries - (vf + 1);
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 <<
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);
427 adapter->
vfinfo[
vf].num_vf_mc_hashes = 0;
432 hw->
mac.ops.clear_rar(hw, rar_entry);
439 int rar_entry = hw->
mac.num_rar_entries - (vf + 1);
441 memcpy(adapter->
vfinfo[vf].vf_mac_addresses, mac_addr, 6);
447 static int ixgbe_set_vf_macvlan(
struct ixgbe_adapter *adapter,
448 int vf,
int index,
unsigned char *mac_addr)
457 if (entry->
vf == vf) {
489 if (!entry || !entry->
free)
504 unsigned char vf_mac_addr[6];
506 unsigned int vfn = (event_mask & 0x3f);
508 bool enable = ((event_mask & 0x10000000
U) != 0);
511 eth_random_addr(vf_mac_addr);
512 e_info(probe,
"IOV: VF %d is enabled MAC %pM\n",
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)
528 u32 reg_offset, vf_shift;
531 reg_offset = vf / 32;
535 reg |= (reg | (1 << vf_shift));
539 reg |= (reg | (1 << vf_shift));
544 reg |= (1 << vf_shift);
547 ixgbe_vf_reset_event(adapter, vf);
564 pr_err(
"Error receiving message from VF\n");
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);
602 msgbuf[3] = hw->
mac.mc_filter_type;
608 if (!adapter->
vfinfo[vf].clear_to_send) {
614 switch ((msgbuf[0] & 0xFFFF)) {
616 new_mac = ((
u8 *)(&msgbuf[1]));
617 if (is_valid_ether_addr(new_mac) &&
619 ixgbe_set_vf_mac(adapter, vf, new_mac);
622 e_warn(drv,
"VF %d attempted to override "
623 "administratively set MAC address\nReload "
624 "the VF driver to resume operations\n", vf);
631 hash_list = (
u16 *)&msgbuf[1];
632 retval = ixgbe_set_vf_multicasts(adapter, entries,
636 ixgbe_set_vf_lpe(adapter, msgbuf);
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",
651 else if (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);
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);
673 if (index > 0 && adapter->
vfinfo[vf].spoofchk_enabled)
675 retval = ixgbe_set_vf_macvlan(adapter, vf, index,
676 (
unsigned char *)(&msgbuf[1]));
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]);
706 if (!adapter->
vfinfo[vf].clear_to_send)
715 for (vf = 0; vf < adapter->
num_vfs; vf++) {
718 ixgbe_vf_reset_event(adapter, vf);
722 ixgbe_rcv_msg_from_vf(adapter, vf);
726 ixgbe_rcv_ack_from_vf(adapter, vf);
748 for (i = 0 ; i < adapter->
num_vfs; i++) {
750 if (adapter->
vfinfo[i].clear_to_send)
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.");
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);
780 if ((vf >= adapter->
num_vfs) || (vlan > 4095) || (qos > 7))
783 err = ixgbe_set_vf_vlan(adapter,
true, vlan, 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);
794 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
797 "The VF VLAN has been set,"
798 " but the PF device is not up.\n");
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)
832 static void ixgbe_set_vf_rate_limit(
struct ixgbe_adapter *adapter,
int vf)
846 bcnrc_val /= tx_rate;
861 switch (hw->
mac.type) {
876 for (queue = 0; queue < queues_per_pool; queue++) {
877 unsigned int reg_idx = (vf * queues_per_pool) + queue;
895 "Link speed has been changed. VF Transmit rate is disabled\n");
898 for (i = 0; i < adapter->
num_vfs; i++) {
900 adapter->
vfinfo[
i].tx_rate = 0;
902 ixgbe_set_vf_rate_limit(adapter, i);
920 link_speed = ixgbe_link_mbps(adapter);
921 if (link_speed != 10000)
925 if (tx_rate && ((tx_rate <= 10) || (tx_rate > link_speed)))
930 adapter->
vfinfo[
vf].tx_rate = tx_rate;
933 ixgbe_set_vf_rate_limit(adapter, vf);
941 int vf_target_reg = vf >> 3;
942 int vf_target_shift = vf % 8;
946 adapter->
vfinfo[
vf].spoofchk_enabled = setting;
949 regval &= ~(1 << vf_target_shift);
950 regval |= (setting << vf_target_shift);
953 if (adapter->
vfinfo[vf].vlan_count) {
956 regval &= ~(1 << vf_target_shift);
957 regval |= (setting << vf_target_shift);