@@ -1012,7 +1012,7 @@ int ice_get_rss_key(struct ice_vsi *vsi, u8 *seed);
int ice_set_rss_hfunc(struct ice_vsi *vsi, u8 hfunc);
void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size);
int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset);
-void ice_print_link_msg(struct ice_vsi *vsi, bool isup);
+void ice_print_link_msg(struct ice_vsi *vsi, bool isup, u16 link_speed);
int ice_plug_aux_dev(struct ice_pf *pf);
void ice_unplug_aux_dev(struct ice_pf *pf);
void ice_rdma_finalize_setup(struct ice_pf *pf);
@@ -3639,36 +3639,43 @@ ice_aq_set_phy_cfg(struct ice_hw *hw, struct ice_port_info *pi,
return status;
}
+/**
+ * ice_update_media_caps - refresh the PHY capabilities of the present media
+ * @pi: port info structure of the interested logical port
+ *
+ * Return: 0 on success or if no media is available, negative on failure.
+ */
+int ice_update_media_caps(struct ice_port_info *pi)
+{
+ struct ice_aqc_get_phy_caps_data *pcaps __free(kfree) = NULL;
+
+ if (!(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
+ return 0;
+
+ pcaps = kzalloc_obj(*pcaps);
+ if (!pcaps)
+ return -ENOMEM;
+
+ return ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
+ pcaps, NULL);
+}
+
/**
* ice_update_link_info - update status of the HW network link
* @pi: port info structure of the interested logical port
*/
int ice_update_link_info(struct ice_port_info *pi)
{
- struct ice_link_status *li;
int status;
if (!pi)
return -EINVAL;
- li = &pi->phy.link_info;
-
status = ice_aq_get_link_info(pi, true, NULL, NULL);
if (status)
return status;
- if (li->link_info & ICE_AQ_MEDIA_AVAILABLE) {
- struct ice_aqc_get_phy_caps_data *pcaps __free(kfree) = NULL;
-
- pcaps = kzalloc_obj(*pcaps);
- if (!pcaps)
- return -ENOMEM;
-
- status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
- pcaps, NULL);
- }
-
- return status;
+ return ice_update_media_caps(pi);
}
/**
@@ -93,6 +93,7 @@ ice_clean_rq_elem(struct ice_hw *hw, struct ice_ctl_q_info *cq,
struct ice_rq_event_info *e, u16 *pending);
int
ice_get_link_status(struct ice_port_info *pi, bool *link_up);
+int ice_update_media_caps(struct ice_port_info *pi);
int ice_update_link_info(struct ice_port_info *pi);
int
ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res,
@@ -2775,7 +2775,7 @@ ice_set_link_ksettings(struct net_device *netdev,
/* Tell the OS link is going down, the link will go
* back up when fw says it is ready asynchronously
*/
- ice_print_link_msg(np->vsi, false);
+ ice_print_link_msg(np->vsi, false, 0);
netif_carrier_off(netdev);
netif_tx_stop_all_queues(netdev);
}
@@ -845,8 +845,9 @@ static void ice_print_topo_conflict(struct ice_vsi *vsi)
* ice_print_link_msg - print link up or down message
* @vsi: the VSI whose link status is being queried
* @isup: boolean for if the link is now up or down
+ * @link_speed: current link speed value to display
*/
-void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
+void ice_print_link_msg(struct ice_vsi *vsi, bool isup, u16 link_speed)
{
struct ice_aqc_get_phy_caps_data *caps;
const char *an_advertised;
@@ -870,7 +871,7 @@ void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
return;
}
- switch (vsi->port_info->phy.link_info.link_speed) {
+ switch (link_speed) {
case ICE_AQ_LINK_SPEED_200GB:
speed = "200 G";
break;
@@ -1181,7 +1182,8 @@ ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
struct ice_vsi *vsi;
u16 old_link_speed;
bool old_link;
- int status;
+ bool changed;
+ int err;
phy_info = &pi->phy;
phy_info->link_info_old = phy_info->link_info;
@@ -1189,23 +1191,32 @@ ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
old_link_speed = phy_info->link_info_old.link_speed;
+ /* don't drop an event that the refreshed link info no longer shows */
+ changed = link_up != old_link || link_speed != old_link_speed;
+
/* update the link info structures and re-enable link events,
* don't bail on failure due to other book keeping needed
*/
- status = ice_update_link_info(pi);
- if (status)
+ err = ice_aq_get_link_info(pi, true, NULL, NULL);
+ if (!err) {
+ link_up = phy_info->link_info.link_info & ICE_AQ_LINK_UP;
+ link_speed = phy_info->link_info.link_speed;
+ err = ice_update_media_caps(pi);
+ } else {
+ /* read failed, keep the cache in sync with the applied state */
+ if (link_up)
+ phy_info->link_info.link_info |= ICE_AQ_LINK_UP;
+ else
+ phy_info->link_info.link_info &= ~ICE_AQ_LINK_UP;
+ phy_info->link_info.link_speed = link_speed;
+ }
+ if (err)
dev_dbg(dev, "Failed to update link status on port %d, err %d aq_err %s\n",
- pi->lport, status,
+ pi->lport, err,
libie_aq_str(pi->hw->adminq.sq_last_status));
ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
- /* Check if the link state is up after updating link info, and treat
- * this event as an UP event since the link is actually UP now.
- */
- if (phy_info->link_info.link_info & ICE_AQ_LINK_UP)
- link_up = true;
-
vsi = ice_get_main_vsi(pf);
if (!vsi || !vsi->port_info)
return -EINVAL;
@@ -1217,8 +1228,9 @@ ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
ice_set_link(vsi, false);
}
- /* if the old link up/down and speed is the same as the new */
- if (link_up == old_link && link_speed == old_link_speed)
+ /* nothing to do if neither the event nor the refreshed state changed */
+ changed |= link_up != old_link || link_speed != old_link_speed;
+ if (!changed)
return 0;
if (!link_up && old_link)
@@ -1234,7 +1246,7 @@ ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
ice_set_dflt_mib(pf);
}
ice_vsi_link_event(vsi, link_up);
- ice_print_link_msg(vsi, link_up);
+ ice_print_link_msg(vsi, link_up, link_speed);
ice_vc_notify_link_state(pf);
@@ -6831,7 +6843,8 @@ static int ice_up_complete(struct ice_vsi *vsi)
(vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
((vsi->netdev && (vsi->type == ICE_VSI_PF ||
vsi->type == ICE_VSI_SF)))) {
- ice_print_link_msg(vsi, true);
+ ice_print_link_msg(vsi, true,
+ vsi->port_info->phy.link_info.link_speed);
netif_tx_start_all_queues(vsi->netdev);
netif_carrier_on(vsi->netdev);
}