diff options
author | Brett Creeley <brett.creeley@intel.com> | 2019-02-28 18:26:01 -0500 |
---|---|---|
committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2019-05-02 04:27:11 -0400 |
commit | c2a23e00613bde4a6d5f88c2b4facd5c7be6be87 (patch) | |
tree | e7e2f7b607076e9f5fa642a6a51a7ae433eed68d /drivers/net/ethernet/intel/ice/ice_main.c | |
parent | 49a6a5d7ebfbf99ea5ba8fa4d55a29b7a446cbae (diff) |
ice: Refactor link event flow
Currently the link event flow works, but can be much better.
Refactor the link event flow to make it cleaner and more clear
on what is going on.
Signed-off-by: Brett Creeley <brett.creeley@intel.com>
Signed-off-by: Anirudh Venkataramanan <anirudh.venkataramanan@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet/intel/ice/ice_main.c')
-rw-r--r-- | drivers/net/ethernet/intel/ice/ice_main.c | 93 |
1 files changed, 45 insertions, 48 deletions
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index 51af6b9a7ea2..6b27be93bdf5 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c | |||
@@ -590,6 +590,9 @@ void ice_print_link_msg(struct ice_vsi *vsi, bool isup) | |||
590 | const char *speed; | 590 | const char *speed; |
591 | const char *fc; | 591 | const char *fc; |
592 | 592 | ||
593 | if (!vsi) | ||
594 | return; | ||
595 | |||
593 | if (vsi->current_isup == isup) | 596 | if (vsi->current_isup == isup) |
594 | return; | 597 | return; |
595 | 598 | ||
@@ -659,15 +662,16 @@ void ice_print_link_msg(struct ice_vsi *vsi, bool isup) | |||
659 | */ | 662 | */ |
660 | static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up) | 663 | static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up) |
661 | { | 664 | { |
662 | if (!vsi || test_bit(__ICE_DOWN, vsi->state)) | 665 | if (!vsi) |
666 | return; | ||
667 | |||
668 | if (test_bit(__ICE_DOWN, vsi->state) || !vsi->netdev) | ||
663 | return; | 669 | return; |
664 | 670 | ||
665 | if (vsi->type == ICE_VSI_PF) { | 671 | if (vsi->type == ICE_VSI_PF) { |
666 | if (!vsi->netdev) { | 672 | if (link_up == netif_carrier_ok(vsi->netdev)) |
667 | dev_dbg(&vsi->back->pdev->dev, | ||
668 | "vsi->netdev is not initialized!\n"); | ||
669 | return; | 673 | return; |
670 | } | 674 | |
671 | if (link_up) { | 675 | if (link_up) { |
672 | netif_carrier_on(vsi->netdev); | 676 | netif_carrier_on(vsi->netdev); |
673 | netif_tx_wake_all_queues(vsi->netdev); | 677 | netif_tx_wake_all_queues(vsi->netdev); |
@@ -682,61 +686,51 @@ static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up) | |||
682 | * ice_link_event - process the link event | 686 | * ice_link_event - process the link event |
683 | * @pf: pf that the link event is associated with | 687 | * @pf: pf that the link event is associated with |
684 | * @pi: port_info for the port that the link event is associated with | 688 | * @pi: port_info for the port that the link event is associated with |
689 | * @link_up: true if the physical link is up and false if it is down | ||
690 | * @link_speed: current link speed received from the link event | ||
685 | * | 691 | * |
686 | * Returns -EIO if ice_get_link_status() fails | 692 | * Returns 0 on success and negative on failure |
687 | * Returns 0 on success | ||
688 | */ | 693 | */ |
689 | static int | 694 | static int |
690 | ice_link_event(struct ice_pf *pf, struct ice_port_info *pi) | 695 | ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up, |
696 | u16 link_speed) | ||
691 | { | 697 | { |
692 | u8 new_link_speed, old_link_speed; | ||
693 | struct ice_phy_info *phy_info; | 698 | struct ice_phy_info *phy_info; |
694 | bool new_link_same_as_old; | 699 | struct ice_vsi *vsi; |
695 | bool new_link, old_link; | 700 | u16 old_link_speed; |
696 | u8 lport; | 701 | bool old_link; |
697 | u16 v; | 702 | int result; |
698 | 703 | ||
699 | phy_info = &pi->phy; | 704 | phy_info = &pi->phy; |
700 | phy_info->link_info_old = phy_info->link_info; | 705 | phy_info->link_info_old = phy_info->link_info; |
701 | /* Force ice_get_link_status() to update link info */ | ||
702 | phy_info->get_link_info = true; | ||
703 | 706 | ||
704 | old_link = (phy_info->link_info_old.link_info & ICE_AQ_LINK_UP); | 707 | old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP); |
705 | old_link_speed = phy_info->link_info_old.link_speed; | 708 | old_link_speed = phy_info->link_info_old.link_speed; |
706 | 709 | ||
707 | lport = pi->lport; | 710 | /* update the link info structures and re-enable link events, |
708 | if (ice_get_link_status(pi, &new_link)) { | 711 | * don't bail on failure due to other book keeping needed |
712 | */ | ||
713 | result = ice_update_link_info(pi); | ||
714 | if (result) | ||
709 | dev_dbg(&pf->pdev->dev, | 715 | dev_dbg(&pf->pdev->dev, |
710 | "Could not get link status for port %d\n", lport); | 716 | "Failed to update link status and re-enable link events for port %d\n", |
711 | return -EIO; | 717 | pi->lport); |
712 | } | ||
713 | |||
714 | new_link_speed = phy_info->link_info.link_speed; | ||
715 | |||
716 | new_link_same_as_old = (new_link == old_link && | ||
717 | new_link_speed == old_link_speed); | ||
718 | 718 | ||
719 | ice_for_each_vsi(pf, v) { | 719 | /* if the old link up/down and speed is the same as the new */ |
720 | struct ice_vsi *vsi = pf->vsi[v]; | 720 | if (link_up == old_link && link_speed == old_link_speed) |
721 | return result; | ||
721 | 722 | ||
722 | if (!vsi || !vsi->port_info) | 723 | vsi = ice_find_vsi_by_type(pf, ICE_VSI_PF); |
723 | continue; | 724 | if (!vsi || !vsi->port_info) |
725 | return -EINVAL; | ||
724 | 726 | ||
725 | if (new_link_same_as_old && | 727 | ice_vsi_link_event(vsi, link_up); |
726 | (test_bit(__ICE_DOWN, vsi->state) || | 728 | ice_print_link_msg(vsi, link_up); |
727 | new_link == netif_carrier_ok(vsi->netdev))) | ||
728 | continue; | ||
729 | 729 | ||
730 | if (vsi->port_info->lport == lport) { | 730 | if (pf->num_alloc_vfs) |
731 | ice_print_link_msg(vsi, new_link); | ||
732 | ice_vsi_link_event(vsi, new_link); | ||
733 | } | ||
734 | } | ||
735 | |||
736 | if (!new_link_same_as_old && pf->num_alloc_vfs) | ||
737 | ice_vc_notify_link_state(pf); | 731 | ice_vc_notify_link_state(pf); |
738 | 732 | ||
739 | return 0; | 733 | return result; |
740 | } | 734 | } |
741 | 735 | ||
742 | /** | 736 | /** |
@@ -801,20 +795,23 @@ static int ice_init_link_events(struct ice_port_info *pi) | |||
801 | /** | 795 | /** |
802 | * ice_handle_link_event - handle link event via ARQ | 796 | * ice_handle_link_event - handle link event via ARQ |
803 | * @pf: pf that the link event is associated with | 797 | * @pf: pf that the link event is associated with |
804 | * | 798 | * @event: event structure containing link status info |
805 | * Return -EINVAL if port_info is null | ||
806 | * Return status on success | ||
807 | */ | 799 | */ |
808 | static int ice_handle_link_event(struct ice_pf *pf) | 800 | static int |
801 | ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event) | ||
809 | { | 802 | { |
803 | struct ice_aqc_get_link_status_data *link_data; | ||
810 | struct ice_port_info *port_info; | 804 | struct ice_port_info *port_info; |
811 | int status; | 805 | int status; |
812 | 806 | ||
807 | link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf; | ||
813 | port_info = pf->hw.port_info; | 808 | port_info = pf->hw.port_info; |
814 | if (!port_info) | 809 | if (!port_info) |
815 | return -EINVAL; | 810 | return -EINVAL; |
816 | 811 | ||
817 | status = ice_link_event(pf, port_info); | 812 | status = ice_link_event(pf, port_info, |
813 | !!(link_data->link_info & ICE_AQ_LINK_UP), | ||
814 | le16_to_cpu(link_data->link_speed)); | ||
818 | if (status) | 815 | if (status) |
819 | dev_dbg(&pf->pdev->dev, | 816 | dev_dbg(&pf->pdev->dev, |
820 | "Could not process link event, error %d\n", status); | 817 | "Could not process link event, error %d\n", status); |
@@ -926,7 +923,7 @@ static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type) | |||
926 | 923 | ||
927 | switch (opcode) { | 924 | switch (opcode) { |
928 | case ice_aqc_opc_get_link_status: | 925 | case ice_aqc_opc_get_link_status: |
929 | if (ice_handle_link_event(pf)) | 926 | if (ice_handle_link_event(pf, &event)) |
930 | dev_err(&pf->pdev->dev, | 927 | dev_err(&pf->pdev->dev, |
931 | "Could not handle link event\n"); | 928 | "Could not handle link event\n"); |
932 | break; | 929 | break; |