Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: hns3: refine the handling for VF heartbeat

Currently, the PF check the VF alive by the KEEP_ALVE
mailbox from VF. VF keep sending the mailbox per 2
seconds. Once PF lost the mailbox for more than 8
seconds, it will regards the VF is abnormal, and stop
notifying the state change to VF, include link state,
vf mac, reset, even though it receives the KEEP_ALIVE
mailbox again. It's inreasonable.

This patch fixes it. PF will record the state change which
need to notify VF when lost the VF's KEEP_ALIVE mailbox.
And notify VF when receive the mailbox again. Introduce a
new flag HCLGE_VPORT_STATE_INITED, used to distinguish the
case whether VF driver loaded or not. For VF will query
these states when initializing, so it's unnecessary to
notify it in this case.

Fixes: aa5c4f175be6 ("net: hns3: add reset handling for VF when doing PF reset")
Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Hao Lan <lanhao@huawei.com>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jian Shen and committed by
David S. Miller
fec73521 af691c94

+112 -23
+43 -14
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
··· 3910 3910 return ret; 3911 3911 } 3912 3912 3913 - if (!reset || !test_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state)) 3913 + if (!reset || 3914 + !test_bit(HCLGE_VPORT_STATE_INITED, &vport->state)) 3914 3915 continue; 3916 + 3917 + if (!test_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state) && 3918 + hdev->reset_type == HNAE3_FUNC_RESET) { 3919 + set_bit(HCLGE_VPORT_NEED_NOTIFY_RESET, 3920 + &vport->need_notify); 3921 + continue; 3922 + } 3915 3923 3916 3924 /* Inform VF to process the reset. 3917 3925 * hclge_inform_reset_assert_to_vf may fail if VF ··· 4617 4609 4618 4610 static void hclge_update_vport_alive(struct hclge_dev *hdev) 4619 4611 { 4612 + #define HCLGE_ALIVE_SECONDS_NORMAL 8 4613 + 4614 + unsigned long alive_time = HCLGE_ALIVE_SECONDS_NORMAL * HZ; 4620 4615 int i; 4621 4616 4622 4617 /* start from vport 1 for PF is always alive */ 4623 4618 for (i = 1; i < hdev->num_alloc_vport; i++) { 4624 4619 struct hclge_vport *vport = &hdev->vport[i]; 4625 4620 4626 - if (time_after(jiffies, vport->last_active_jiffies + 8 * HZ)) 4621 + if (!test_bit(HCLGE_VPORT_STATE_INITED, &vport->state) || 4622 + !test_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state)) 4623 + continue; 4624 + if (time_after(jiffies, vport->last_active_jiffies + 4625 + alive_time)) { 4627 4626 clear_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state); 4628 - 4629 - /* If vf is not alive, set to default value */ 4630 - if (!test_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state)) 4631 - vport->mps = HCLGE_MAC_DEFAULT_FRAME; 4627 + dev_warn(&hdev->pdev->dev, 4628 + "VF %u heartbeat timeout\n", 4629 + i - HCLGE_VF_VPORT_START_NUM); 4630 + } 4632 4631 } 4633 4632 } 4634 4633 ··· 8079 8064 { 8080 8065 struct hclge_dev *hdev = vport->back; 8081 8066 8067 + set_bit(HCLGE_VPORT_STATE_INITED, &vport->state); 8082 8068 set_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state); 8083 8069 set_bit(HCLGE_VPORT_STATE_PROMISC_CHANGE, &vport->state); 8084 8070 vport->last_active_jiffies = jiffies; 8071 + vport->need_notify = 0; 8085 8072 8086 8073 if (test_bit(vport->vport_id, hdev->vport_config_block)) { 8087 8074 if (vport->vport_id) { ··· 8101 8084 8102 8085 void hclge_vport_stop(struct hclge_vport *vport) 8103 8086 { 8087 + clear_bit(HCLGE_VPORT_STATE_INITED, &vport->state); 8104 8088 clear_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state); 8089 + vport->need_notify = 0; 8105 8090 } 8106 8091 8107 8092 static int hclge_client_start(struct hnae3_handle *handle) ··· 9227 9208 return 0; 9228 9209 } 9229 9210 9230 - dev_info(&hdev->pdev->dev, "MAC of VF %d has been set to %s\n", 9211 + dev_info(&hdev->pdev->dev, 9212 + "MAC of VF %d has been set to %s, will be active after VF reset\n", 9231 9213 vf, format_mac_addr); 9232 9214 return 0; 9233 9215 } ··· 10485 10465 * for DEVICE_VERSION_V3, vf doesn't need to know about the port based 10486 10466 * VLAN state. 10487 10467 */ 10488 - if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V3 && 10489 - test_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state)) 10490 - (void)hclge_push_vf_port_base_vlan_info(&hdev->vport[0], 10491 - vport->vport_id, 10492 - state, &vlan_info); 10493 - 10468 + if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V3) { 10469 + if (test_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state)) 10470 + (void)hclge_push_vf_port_base_vlan_info(&hdev->vport[0], 10471 + vport->vport_id, 10472 + state, 10473 + &vlan_info); 10474 + else 10475 + set_bit(HCLGE_VPORT_NEED_NOTIFY_VF_VLAN, 10476 + &vport->need_notify); 10477 + } 10494 10478 return 0; 10495 10479 } 10496 10480 ··· 11965 11941 int i; 11966 11942 11967 11943 for (i = 0; i < hdev->num_alloc_vport; i++) { 11968 - hclge_vport_stop(vport); 11944 + clear_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state); 11969 11945 vport++; 11970 11946 } 11971 11947 } ··· 12978 12954 struct hclge_dev *hdev = vport->back; 12979 12955 struct hclge_vlan_info vlan_info; 12980 12956 int ret; 12957 + 12958 + clear_bit(HCLGE_VPORT_STATE_INITED, &vport->state); 12959 + clear_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state); 12960 + vport->need_notify = 0; 12961 + vport->mps = 0; 12981 12962 12982 12963 /* after disable sriov, clean VF rate configured by PF */ 12983 12964 ret = hclge_tm_qs_shaper_cfg(vport, 0);
+7
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
··· 995 995 HCLGE_VPORT_STATE_MAC_TBL_CHANGE, 996 996 HCLGE_VPORT_STATE_PROMISC_CHANGE, 997 997 HCLGE_VPORT_STATE_VLAN_FLTR_CHANGE, 998 + HCLGE_VPORT_STATE_INITED, 998 999 HCLGE_VPORT_STATE_MAX 1000 + }; 1001 + 1002 + enum HCLGE_VPORT_NEED_NOTIFY { 1003 + HCLGE_VPORT_NEED_NOTIFY_RESET, 1004 + HCLGE_VPORT_NEED_NOTIFY_VF_VLAN, 999 1005 }; 1000 1006 1001 1007 struct hclge_vlan_info { ··· 1050 1044 struct hnae3_handle roce; 1051 1045 1052 1046 unsigned long state; 1047 + unsigned long need_notify; 1053 1048 unsigned long last_active_jiffies; 1054 1049 u32 mps; /* Max packet size */ 1055 1050 struct hclge_vf_info vf_info;
+62 -9
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
··· 124 124 return status; 125 125 } 126 126 127 + static int hclge_inform_vf_reset(struct hclge_vport *vport, u16 reset_type) 128 + { 129 + __le16 msg_data; 130 + u8 dest_vfid; 131 + 132 + dest_vfid = (u8)vport->vport_id; 133 + msg_data = cpu_to_le16(reset_type); 134 + 135 + /* send this requested info to VF */ 136 + return hclge_send_mbx_msg(vport, (u8 *)&msg_data, sizeof(msg_data), 137 + HCLGE_MBX_ASSERTING_RESET, dest_vfid); 138 + } 139 + 127 140 int hclge_inform_reset_assert_to_vf(struct hclge_vport *vport) 128 141 { 129 142 struct hclge_dev *hdev = vport->back; 130 - __le16 msg_data; 131 143 u16 reset_type; 132 - u8 dest_vfid; 133 144 134 145 BUILD_BUG_ON(HNAE3_MAX_RESET > U16_MAX); 135 - 136 - dest_vfid = (u8)vport->vport_id; 137 146 138 147 if (hdev->reset_type == HNAE3_FUNC_RESET) 139 148 reset_type = HNAE3_VF_PF_FUNC_RESET; ··· 151 142 else 152 143 reset_type = HNAE3_VF_FUNC_RESET; 153 144 154 - msg_data = cpu_to_le16(reset_type); 155 - 156 - /* send this requested info to VF */ 157 - return hclge_send_mbx_msg(vport, (u8 *)&msg_data, sizeof(msg_data), 158 - HCLGE_MBX_ASSERTING_RESET, dest_vfid); 145 + return hclge_inform_vf_reset(vport, reset_type); 159 146 } 160 147 161 148 static void hclge_free_vector_ring_chain(struct hnae3_ring_chain_node *head) ··· 657 652 return hclge_func_reset_cmd(hdev, vport->vport_id); 658 653 } 659 654 655 + static void hclge_notify_vf_config(struct hclge_vport *vport) 656 + { 657 + struct hclge_dev *hdev = vport->back; 658 + struct hnae3_ae_dev *ae_dev = pci_get_drvdata(hdev->pdev); 659 + struct hclge_port_base_vlan_config *vlan_cfg; 660 + int ret; 661 + 662 + hclge_push_vf_link_status(vport); 663 + if (test_bit(HCLGE_VPORT_NEED_NOTIFY_RESET, &vport->need_notify)) { 664 + ret = hclge_inform_vf_reset(vport, HNAE3_VF_PF_FUNC_RESET); 665 + if (ret) { 666 + dev_err(&hdev->pdev->dev, 667 + "failed to inform VF %u reset!", 668 + vport->vport_id - HCLGE_VF_VPORT_START_NUM); 669 + return; 670 + } 671 + vport->need_notify = 0; 672 + return; 673 + } 674 + 675 + if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V3 && 676 + test_bit(HCLGE_VPORT_NEED_NOTIFY_VF_VLAN, &vport->need_notify)) { 677 + vlan_cfg = &vport->port_base_vlan_cfg; 678 + ret = hclge_push_vf_port_base_vlan_info(&hdev->vport[0], 679 + vport->vport_id, 680 + vlan_cfg->state, 681 + &vlan_cfg->vlan_info); 682 + if (ret) { 683 + dev_err(&hdev->pdev->dev, 684 + "failed to inform VF %u port base vlan!", 685 + vport->vport_id - HCLGE_VF_VPORT_START_NUM); 686 + return; 687 + } 688 + clear_bit(HCLGE_VPORT_NEED_NOTIFY_VF_VLAN, &vport->need_notify); 689 + } 690 + } 691 + 660 692 static void hclge_vf_keep_alive(struct hclge_vport *vport) 661 693 { 694 + struct hclge_dev *hdev = vport->back; 695 + 662 696 vport->last_active_jiffies = jiffies; 697 + 698 + if (test_bit(HCLGE_VPORT_STATE_INITED, &vport->state) && 699 + !test_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state)) { 700 + set_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state); 701 + dev_info(&hdev->pdev->dev, "VF %u is alive!", 702 + vport->vport_id - HCLGE_VF_VPORT_START_NUM); 703 + hclge_notify_vf_config(vport); 704 + } 663 705 } 664 706 665 707 static int hclge_set_vf_mtu(struct hclge_vport *vport, ··· 1006 954 hclge_rm_vport_all_mac_table(param->vport, true, 1007 955 HCLGE_MAC_ADDR_MC); 1008 956 hclge_rm_vport_all_vlan_table(param->vport, true); 957 + param->vport->mps = 0; 1009 958 return 0; 1010 959 } 1011 960