return 0 means link status changed, -1 means not changed */
| 2880 | |
| 2881 | /* return 0 means link status changed, -1 means not changed */ |
| 2882 | int |
| 2883 | txgbe_dev_link_update_share(struct rte_eth_dev *dev, |
| 2884 | int wait_to_complete) |
| 2885 | { |
| 2886 | struct txgbe_adapter *ad = TXGBE_DEV_ADAPTER(dev); |
| 2887 | struct txgbe_hw *hw = TXGBE_DEV_HW(dev); |
| 2888 | struct rte_eth_link link; |
| 2889 | u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN; |
| 2890 | struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev); |
| 2891 | bool link_up; |
| 2892 | int err; |
| 2893 | int wait = 1; |
| 2894 | u32 reg; |
| 2895 | |
| 2896 | memset(&link, 0, sizeof(link)); |
| 2897 | link.link_status = RTE_ETH_LINK_DOWN; |
| 2898 | link.link_speed = RTE_ETH_SPEED_NUM_NONE; |
| 2899 | link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX; |
| 2900 | link.link_autoneg = !(dev->data->dev_conf.link_speeds & |
| 2901 | RTE_ETH_LINK_SPEED_FIXED); |
| 2902 | |
| 2903 | hw->mac.get_link_status = true; |
| 2904 | |
| 2905 | if (intr->flags & TXGBE_FLAG_NEED_LINK_CONFIG) |
| 2906 | return rte_eth_linkstatus_set(dev, &link); |
| 2907 | |
| 2908 | /* check if it needs to wait to complete, if lsc interrupt is enabled */ |
| 2909 | if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0) |
| 2910 | wait = 0; |
| 2911 | |
| 2912 | err = hw->mac.check_link(hw, &link_speed, &link_up, wait); |
| 2913 | |
| 2914 | if (err != 0) { |
| 2915 | link.link_speed = RTE_ETH_SPEED_NUM_100M; |
| 2916 | link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX; |
| 2917 | return rte_eth_linkstatus_set(dev, &link); |
| 2918 | } |
| 2919 | |
| 2920 | if (link_up == 0) { |
| 2921 | if ((hw->subsystem_device_id & 0xFF) == |
| 2922 | TXGBE_DEV_ID_KR_KX_KX4) { |
| 2923 | hw->mac.bp_down_event(hw); |
| 2924 | } else if (hw->phy.media_type == txgbe_media_type_fiber && |
| 2925 | dev->data->dev_conf.intr_conf.lsc != 0) { |
| 2926 | txgbe_dev_wait_setup_link_complete(dev, 0); |
| 2927 | if (!__atomic_test_and_set(&ad->link_thread_running, __ATOMIC_SEQ_CST)) { |
| 2928 | /* To avoid race condition between threads, set |
| 2929 | * the TXGBE_FLAG_NEED_LINK_CONFIG flag only |
| 2930 | * when there is no link thread running. |
| 2931 | */ |
| 2932 | intr->flags |= TXGBE_FLAG_NEED_LINK_CONFIG; |
| 2933 | if (rte_thread_create_internal_control(&ad->link_thread_tid, |
| 2934 | "txgbe-link", |
| 2935 | txgbe_dev_setup_link_thread_handler, dev) < 0) { |
| 2936 | PMD_DRV_LOG(ERR, "Create link thread failed!"); |
| 2937 | __atomic_clear(&ad->link_thread_running, __ATOMIC_SEQ_CST); |
| 2938 | } |
| 2939 | } else { |
no test coverage detected