Skip to content

Commit 1d0e28a

Browse files
bcreeley13anguy11
authored andcommitted
ice: Remove and replace ice speed defines with ethtool.h versions
The driver is currently using ICE_LINK_SPEED_* defines that mirror what ethtool.h defines, with one exception ICE_LINK_SPEED_UNKNOWN. This issue is fixed by the following changes: 1. replace ICE_LINK_SPEED_UNKNOWN with 0 because SPEED_UNKNOWN in ethtool.h is "-1" and that doesn't match the driver's expected behavior 2. transform ICE_LINK_SPEED_*MBPS to SPEED_* using static tables and fls()-1 to convert from BIT() to an index in a table. Suggested-by: Alexander Lobakin <[email protected]> Signed-off-by: Brett Creeley <[email protected]> Co-developed-by: Jesse Brandeburg <[email protected]> Signed-off-by: Jesse Brandeburg <[email protected]> Tested-by: Gurucharan G <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent a711a32 commit 1d0e28a

File tree

5 files changed

+69
-109
lines changed

5 files changed

+69
-109
lines changed

drivers/net/ethernet/intel/ice/ice_common.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,8 +2948,8 @@ bool ice_is_100m_speed_supported(struct ice_hw *hw)
29482948
* Note: In the structure of [phy_type_low, phy_type_high], there should
29492949
* be one bit set, as this function will convert one PHY type to its
29502950
* speed.
2951-
* If no bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
2952-
* If more than one bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
2951+
* If no bit gets set, ICE_AQ_LINK_SPEED_UNKNOWN will be returned
2952+
* If more than one bit gets set, ICE_AQ_LINK_SPEED_UNKNOWN will be returned
29532953
*/
29542954
static u16
29552955
ice_get_link_speed_based_on_phy_type(u64 phy_type_low, u64 phy_type_high)
@@ -5515,3 +5515,40 @@ bool ice_fw_supports_report_dflt_cfg(struct ice_hw *hw)
55155515
ICE_FW_API_REPORT_DFLT_CFG_MIN,
55165516
ICE_FW_API_REPORT_DFLT_CFG_PATCH);
55175517
}
5518+
5519+
/* each of the indexes into the following array match the speed of a return
5520+
* value from the list of AQ returned speeds like the range:
5521+
* ICE_AQ_LINK_SPEED_10MB .. ICE_AQ_LINK_SPEED_100GB excluding
5522+
* ICE_AQ_LINK_SPEED_UNKNOWN which is BIT(15) and maps to BIT(14) in this
5523+
* array. The array is defined as 15 elements long because the link_speed
5524+
* returned by the firmware is a 16 bit * value, but is indexed
5525+
* by [fls(speed) - 1]
5526+
*/
5527+
static const u32 ice_aq_to_link_speed[15] = {
5528+
SPEED_10, /* BIT(0) */
5529+
SPEED_100,
5530+
SPEED_1000,
5531+
SPEED_2500,
5532+
SPEED_5000,
5533+
SPEED_10000,
5534+
SPEED_20000,
5535+
SPEED_25000,
5536+
SPEED_40000,
5537+
SPEED_50000,
5538+
SPEED_100000, /* BIT(10) */
5539+
0,
5540+
0,
5541+
0,
5542+
0 /* BIT(14) */
5543+
};
5544+
5545+
/**
5546+
* ice_get_link_speed - get integer speed from table
5547+
* @index: array index from fls(aq speed) - 1
5548+
*
5549+
* Returns: u32 value containing integer speed
5550+
*/
5551+
u32 ice_get_link_speed(u16 index)
5552+
{
5553+
return ice_aq_to_link_speed[index];
5554+
}

drivers/net/ethernet/intel/ice/ice_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ int
163163
ice_aq_sff_eeprom(struct ice_hw *hw, u16 lport, u8 bus_addr,
164164
u16 mem_addr, u8 page, u8 set_page, u8 *data, u8 length,
165165
bool write, struct ice_sq_cd *cd);
166+
u32 ice_get_link_speed(u16 index);
166167

167168
int
168169
ice_cfg_vsi_rdma(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap,

drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -908,17 +908,5 @@ static inline struct ice_rx_ptype_decoded ice_decode_rx_desc_ptype(u16 ptype)
908908
return ice_ptype_lkup[ptype];
909909
}
910910

911-
#define ICE_LINK_SPEED_UNKNOWN 0
912-
#define ICE_LINK_SPEED_10MBPS 10
913-
#define ICE_LINK_SPEED_100MBPS 100
914-
#define ICE_LINK_SPEED_1000MBPS 1000
915-
#define ICE_LINK_SPEED_2500MBPS 2500
916-
#define ICE_LINK_SPEED_5000MBPS 5000
917-
#define ICE_LINK_SPEED_10000MBPS 10000
918-
#define ICE_LINK_SPEED_20000MBPS 20000
919-
#define ICE_LINK_SPEED_25000MBPS 25000
920-
#define ICE_LINK_SPEED_40000MBPS 40000
921-
#define ICE_LINK_SPEED_50000MBPS 50000
922-
#define ICE_LINK_SPEED_100000MBPS 100000
923911

924912
#endif /* _ICE_LAN_TX_RX_H_ */

drivers/net/ethernet/intel/ice/ice_lib.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,33 +3850,11 @@ int ice_clear_dflt_vsi(struct ice_vsi *vsi)
38503850
*/
38513851
int ice_get_link_speed_mbps(struct ice_vsi *vsi)
38523852
{
3853-
switch (vsi->port_info->phy.link_info.link_speed) {
3854-
case ICE_AQ_LINK_SPEED_100GB:
3855-
return SPEED_100000;
3856-
case ICE_AQ_LINK_SPEED_50GB:
3857-
return SPEED_50000;
3858-
case ICE_AQ_LINK_SPEED_40GB:
3859-
return SPEED_40000;
3860-
case ICE_AQ_LINK_SPEED_25GB:
3861-
return SPEED_25000;
3862-
case ICE_AQ_LINK_SPEED_20GB:
3863-
return SPEED_20000;
3864-
case ICE_AQ_LINK_SPEED_10GB:
3865-
return SPEED_10000;
3866-
case ICE_AQ_LINK_SPEED_5GB:
3867-
return SPEED_5000;
3868-
case ICE_AQ_LINK_SPEED_2500MB:
3869-
return SPEED_2500;
3870-
case ICE_AQ_LINK_SPEED_1000MB:
3871-
return SPEED_1000;
3872-
case ICE_AQ_LINK_SPEED_100MB:
3873-
return SPEED_100;
3874-
case ICE_AQ_LINK_SPEED_10MB:
3875-
return SPEED_10;
3876-
case ICE_AQ_LINK_SPEED_UNKNOWN:
3877-
default:
3878-
return 0;
3879-
}
3853+
unsigned int link_speed;
3854+
3855+
link_speed = vsi->port_info->phy.link_info.link_speed;
3856+
3857+
return (int)ice_get_link_speed(fls(link_speed) - 1);
38803858
}
38813859

38823860
/**

drivers/net/ethernet/intel/ice/ice_vf_mbx.c

Lines changed: 24 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ ice_aq_send_msg_to_vf(struct ice_hw *hw, u16 vfid, u32 v_opcode, u32 v_retval,
3939
return ice_sq_send_cmd(hw, &hw->mailboxq, &desc, msg, msglen, cd);
4040
}
4141

42+
static const u32 ice_legacy_aq_to_vc_speed[15] = {
43+
VIRTCHNL_LINK_SPEED_100MB, /* BIT(0) */
44+
VIRTCHNL_LINK_SPEED_100MB,
45+
VIRTCHNL_LINK_SPEED_1GB,
46+
VIRTCHNL_LINK_SPEED_1GB,
47+
VIRTCHNL_LINK_SPEED_1GB,
48+
VIRTCHNL_LINK_SPEED_10GB,
49+
VIRTCHNL_LINK_SPEED_20GB,
50+
VIRTCHNL_LINK_SPEED_25GB,
51+
VIRTCHNL_LINK_SPEED_40GB,
52+
VIRTCHNL_LINK_SPEED_40GB,
53+
VIRTCHNL_LINK_SPEED_40GB,
54+
VIRTCHNL_LINK_SPEED_UNKNOWN,
55+
VIRTCHNL_LINK_SPEED_UNKNOWN,
56+
VIRTCHNL_LINK_SPEED_UNKNOWN,
57+
VIRTCHNL_LINK_SPEED_UNKNOWN /* BIT(14) */
58+
};
59+
4260
/**
4361
* ice_conv_link_speed_to_virtchnl
4462
* @adv_link_support: determines the format of the returned link speed
@@ -55,79 +73,17 @@ u32 ice_conv_link_speed_to_virtchnl(bool adv_link_support, u16 link_speed)
5573
{
5674
u32 speed;
5775

58-
if (adv_link_support)
59-
switch (link_speed) {
60-
case ICE_AQ_LINK_SPEED_10MB:
61-
speed = ICE_LINK_SPEED_10MBPS;
62-
break;
63-
case ICE_AQ_LINK_SPEED_100MB:
64-
speed = ICE_LINK_SPEED_100MBPS;
65-
break;
66-
case ICE_AQ_LINK_SPEED_1000MB:
67-
speed = ICE_LINK_SPEED_1000MBPS;
68-
break;
69-
case ICE_AQ_LINK_SPEED_2500MB:
70-
speed = ICE_LINK_SPEED_2500MBPS;
71-
break;
72-
case ICE_AQ_LINK_SPEED_5GB:
73-
speed = ICE_LINK_SPEED_5000MBPS;
74-
break;
75-
case ICE_AQ_LINK_SPEED_10GB:
76-
speed = ICE_LINK_SPEED_10000MBPS;
77-
break;
78-
case ICE_AQ_LINK_SPEED_20GB:
79-
speed = ICE_LINK_SPEED_20000MBPS;
80-
break;
81-
case ICE_AQ_LINK_SPEED_25GB:
82-
speed = ICE_LINK_SPEED_25000MBPS;
83-
break;
84-
case ICE_AQ_LINK_SPEED_40GB:
85-
speed = ICE_LINK_SPEED_40000MBPS;
86-
break;
87-
case ICE_AQ_LINK_SPEED_50GB:
88-
speed = ICE_LINK_SPEED_50000MBPS;
89-
break;
90-
case ICE_AQ_LINK_SPEED_100GB:
91-
speed = ICE_LINK_SPEED_100000MBPS;
92-
break;
93-
default:
94-
speed = ICE_LINK_SPEED_UNKNOWN;
95-
break;
96-
}
97-
else
76+
if (adv_link_support) {
77+
/* convert a BIT() value into an array index */
78+
speed = ice_get_link_speed(fls(link_speed) - 1);
79+
} else {
9880
/* Virtchnl speeds are not defined for every speed supported in
9981
* the hardware. To maintain compatibility with older AVF
10082
* drivers, while reporting the speed the new speed values are
10183
* resolved to the closest known virtchnl speeds
10284
*/
103-
switch (link_speed) {
104-
case ICE_AQ_LINK_SPEED_10MB:
105-
case ICE_AQ_LINK_SPEED_100MB:
106-
speed = (u32)VIRTCHNL_LINK_SPEED_100MB;
107-
break;
108-
case ICE_AQ_LINK_SPEED_1000MB:
109-
case ICE_AQ_LINK_SPEED_2500MB:
110-
case ICE_AQ_LINK_SPEED_5GB:
111-
speed = (u32)VIRTCHNL_LINK_SPEED_1GB;
112-
break;
113-
case ICE_AQ_LINK_SPEED_10GB:
114-
speed = (u32)VIRTCHNL_LINK_SPEED_10GB;
115-
break;
116-
case ICE_AQ_LINK_SPEED_20GB:
117-
speed = (u32)VIRTCHNL_LINK_SPEED_20GB;
118-
break;
119-
case ICE_AQ_LINK_SPEED_25GB:
120-
speed = (u32)VIRTCHNL_LINK_SPEED_25GB;
121-
break;
122-
case ICE_AQ_LINK_SPEED_40GB:
123-
case ICE_AQ_LINK_SPEED_50GB:
124-
case ICE_AQ_LINK_SPEED_100GB:
125-
speed = (u32)VIRTCHNL_LINK_SPEED_40GB;
126-
break;
127-
default:
128-
speed = (u32)VIRTCHNL_LINK_SPEED_UNKNOWN;
129-
break;
130-
}
85+
speed = ice_legacy_aq_to_vc_speed[fls(link_speed) - 1];
86+
}
13187

13288
return speed;
13389
}

0 commit comments

Comments
 (0)