Skip to content

Commit b9a4525

Browse files
jbrandebanguy11
authored andcommitted
intel: legacy: field get conversion
Refactor several older Intel drivers to use FIELD_GET(), which reduces lines of code and adds clarity of intent. This code was generated by the following coccinelle/spatch script and then manually repaired. @get@ constant shift,mask; type T; expression a; @@ ( -((T)((a) & mask) >> shift) +FIELD_GET(mask, a) and applied via: spatch --sp-file field_prep.cocci --in-place --dir \ drivers/net/ethernet/intel/ Cc: Julia Lawall <[email protected]> CC: Alexander Lobakin <[email protected]> Reviewed-by: Marcin Szycik <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Jesse Brandeburg <[email protected]> Tested-by: Pucha Himasekhar Reddy <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent c82e648 commit b9a4525

25 files changed

+118
-162
lines changed

drivers/net/ethernet/intel/e1000/e1000_hw.c

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,8 +3261,7 @@ static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
32613261
return ret_val;
32623262

32633263
phy_info->mdix_mode =
3264-
(e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
3265-
IGP01E1000_PSSR_MDIX_SHIFT);
3264+
(e1000_auto_x_mode)FIELD_GET(IGP01E1000_PSSR_MDIX, phy_data);
32663265

32673266
if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
32683267
IGP01E1000_PSSR_SPEED_1000MBPS) {
@@ -3273,11 +3272,11 @@ static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
32733272
if (ret_val)
32743273
return ret_val;
32753274

3276-
phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3277-
SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3275+
phy_info->local_rx = FIELD_GET(SR_1000T_LOCAL_RX_STATUS,
3276+
phy_data) ?
32783277
e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3279-
phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3280-
SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3278+
phy_info->remote_rx = FIELD_GET(SR_1000T_REMOTE_RX_STATUS,
3279+
phy_data) ?
32813280
e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
32823281

32833282
/* Get cable length */
@@ -3327,14 +3326,12 @@ static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
33273326
return ret_val;
33283327

33293328
phy_info->extended_10bt_distance =
3330-
((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3331-
M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3329+
FIELD_GET(M88E1000_PSCR_10BT_EXT_DIST_ENABLE, phy_data) ?
33323330
e1000_10bt_ext_dist_enable_lower :
33333331
e1000_10bt_ext_dist_enable_normal;
33343332

33353333
phy_info->polarity_correction =
3336-
((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3337-
M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3334+
FIELD_GET(M88E1000_PSCR_POLARITY_REVERSAL, phy_data) ?
33383335
e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
33393336

33403337
/* Check polarity status */
@@ -3348,27 +3345,25 @@ static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
33483345
return ret_val;
33493346

33503347
phy_info->mdix_mode =
3351-
(e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
3352-
M88E1000_PSSR_MDIX_SHIFT);
3348+
(e1000_auto_x_mode)FIELD_GET(M88E1000_PSSR_MDIX, phy_data);
33533349

33543350
if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
33553351
/* Cable Length Estimation and Local/Remote Receiver Information
33563352
* are only valid at 1000 Mbps.
33573353
*/
33583354
phy_info->cable_length =
3359-
(e1000_cable_length) ((phy_data &
3360-
M88E1000_PSSR_CABLE_LENGTH) >>
3361-
M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3355+
(e1000_cable_length)FIELD_GET(M88E1000_PSSR_CABLE_LENGTH,
3356+
phy_data);
33623357

33633358
ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
33643359
if (ret_val)
33653360
return ret_val;
33663361

3367-
phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3368-
SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3362+
phy_info->local_rx = FIELD_GET(SR_1000T_LOCAL_RX_STATUS,
3363+
phy_data) ?
33693364
e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3370-
phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3371-
SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3365+
phy_info->remote_rx = FIELD_GET(SR_1000T_REMOTE_RX_STATUS,
3366+
phy_data) ?
33723367
e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
33733368
}
33743369

@@ -3516,7 +3511,7 @@ s32 e1000_init_eeprom_params(struct e1000_hw *hw)
35163511
if (ret_val)
35173512
return ret_val;
35183513
eeprom_size =
3519-
(eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3514+
FIELD_GET(EEPROM_SIZE_MASK, eeprom_size);
35203515
/* 256B eeprom size was not supported in earlier hardware, so we
35213516
* bump eeprom_size up one to ensure that "1" (which maps to
35223517
* 256B) is never the result used in the shifting logic below.
@@ -4892,8 +4887,7 @@ static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
48924887
&phy_data);
48934888
if (ret_val)
48944889
return ret_val;
4895-
cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4896-
M88E1000_PSSR_CABLE_LENGTH_SHIFT;
4890+
cable_length = FIELD_GET(M88E1000_PSSR_CABLE_LENGTH, phy_data);
48974891

48984892
/* Convert the enum value to ranged values */
48994893
switch (cable_length) {
@@ -5002,8 +4996,7 @@ static s32 e1000_check_polarity(struct e1000_hw *hw,
50024996
&phy_data);
50034997
if (ret_val)
50044998
return ret_val;
5005-
*polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5006-
M88E1000_PSSR_REV_POLARITY_SHIFT) ?
4999+
*polarity = FIELD_GET(M88E1000_PSSR_REV_POLARITY, phy_data) ?
50075000
e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
50085001

50095002
} else if (hw->phy_type == e1000_phy_igp) {
@@ -5073,8 +5066,8 @@ static s32 e1000_check_downshift(struct e1000_hw *hw)
50735066
if (ret_val)
50745067
return ret_val;
50755068

5076-
hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5077-
M88E1000_PSSR_DOWNSHIFT_SHIFT;
5069+
hw->speed_downgraded = FIELD_GET(M88E1000_PSSR_DOWNSHIFT,
5070+
phy_data);
50785071
}
50795072

50805073
return E1000_SUCCESS;

drivers/net/ethernet/intel/e1000e/80003es2lan.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ static s32 e1000_init_nvm_params_80003es2lan(struct e1000_hw *hw)
9292

9393
nvm->type = e1000_nvm_eeprom_spi;
9494

95-
size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
96-
E1000_EECD_SIZE_EX_SHIFT);
95+
size = (u16)FIELD_GET(E1000_EECD_SIZE_EX_MASK, eecd);
9796

9897
/* Added to a constant, "size" becomes the left-shift value
9998
* for setting word_size.

drivers/net/ethernet/intel/e1000e/82571.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ static s32 e1000_init_nvm_params_82571(struct e1000_hw *hw)
157157
fallthrough;
158158
default:
159159
nvm->type = e1000_nvm_eeprom_spi;
160-
size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
161-
E1000_EECD_SIZE_EX_SHIFT);
160+
size = (u16)FIELD_GET(E1000_EECD_SIZE_EX_MASK, eecd);
162161
/* Added to a constant, "size" becomes the left-shift value
163162
* for setting word_size.
164163
*/

drivers/net/ethernet/intel/e1000e/ethtool.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ static void e1000_get_drvinfo(struct net_device *netdev,
654654
*/
655655
snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
656656
"%d.%d-%d",
657-
(adapter->eeprom_vers & 0xF000) >> 12,
658-
(adapter->eeprom_vers & 0x0FF0) >> 4,
657+
FIELD_GET(0xF000, adapter->eeprom_vers),
658+
FIELD_GET(0x0FF0, adapter->eeprom_vers),
659659
(adapter->eeprom_vers & 0x000F));
660660

661661
strscpy(drvinfo->bus_info, pci_name(adapter->pdev),
@@ -925,8 +925,7 @@ static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
925925
}
926926

927927
if (mac->type >= e1000_pch_lpt)
928-
wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
929-
E1000_FWSM_WLOCK_MAC_SHIFT;
928+
wlock_mac = FIELD_GET(E1000_FWSM_WLOCK_MAC_MASK, er32(FWSM));
930929

931930
for (i = 0; i < mac->rar_entry_count; i++) {
932931
if (mac->type >= e1000_pch_lpt) {

drivers/net/ethernet/intel/e1000e/ich8lan.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,13 +1072,11 @@ static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
10721072

10731073
lat_enc_d = (lat_enc & E1000_LTRV_VALUE_MASK) *
10741074
(1U << (E1000_LTRV_SCALE_FACTOR *
1075-
((lat_enc & E1000_LTRV_SCALE_MASK)
1076-
>> E1000_LTRV_SCALE_SHIFT)));
1075+
FIELD_GET(E1000_LTRV_SCALE_MASK, lat_enc)));
10771076

10781077
max_ltr_enc_d = (max_ltr_enc & E1000_LTRV_VALUE_MASK) *
1079-
(1U << (E1000_LTRV_SCALE_FACTOR *
1080-
((max_ltr_enc & E1000_LTRV_SCALE_MASK)
1081-
>> E1000_LTRV_SCALE_SHIFT)));
1078+
(1U << (E1000_LTRV_SCALE_FACTOR *
1079+
FIELD_GET(E1000_LTRV_SCALE_MASK, max_ltr_enc)));
10821080

10831081
if (lat_enc_d > max_ltr_enc_d)
10841082
lat_enc = max_ltr_enc;
@@ -2075,8 +2073,7 @@ static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
20752073
{
20762074
u16 phy_data;
20772075
u32 strap = er32(STRAP);
2078-
u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
2079-
E1000_STRAP_SMT_FREQ_SHIFT;
2076+
u32 freq = FIELD_GET(E1000_STRAP_SMT_FREQ_MASK, strap);
20802077
s32 ret_val;
20812078

20822079
strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
@@ -2562,8 +2559,7 @@ void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
25622559
hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
25632560
(u16)(mac_reg & 0xFFFF));
25642561
hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
2565-
(u16)((mac_reg & E1000_RAH_AV)
2566-
>> 16));
2562+
FIELD_GET(E1000_RAH_AV, mac_reg));
25672563
}
25682564

25692565
e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
@@ -3205,7 +3201,7 @@ static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
32053201
&nvm_dword);
32063202
if (ret_val)
32073203
return ret_val;
3208-
sig_byte = (u8)((nvm_dword & 0xFF00) >> 8);
3204+
sig_byte = FIELD_GET(0xFF00, nvm_dword);
32093205
if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
32103206
E1000_ICH_NVM_SIG_VALUE) {
32113207
*bank = 0;
@@ -3218,7 +3214,7 @@ static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
32183214
&nvm_dword);
32193215
if (ret_val)
32203216
return ret_val;
3221-
sig_byte = (u8)((nvm_dword & 0xFF00) >> 8);
3217+
sig_byte = FIELD_GET(0xFF00, nvm_dword);
32223218
if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
32233219
E1000_ICH_NVM_SIG_VALUE) {
32243220
*bank = 1;

drivers/net/ethernet/intel/e1000e/mac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw)
5050
* for the device regardless of function swap state.
5151
*/
5252
reg = er32(STATUS);
53-
bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
53+
bus->func = FIELD_GET(E1000_STATUS_FUNC_MASK, reg);
5454
}
5555

5656
/**

drivers/net/ethernet/intel/e1000e/netdev.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,8 +1788,7 @@ static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
17881788
adapter->corr_errors +=
17891789
pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
17901790
adapter->uncorr_errors +=
1791-
(pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1792-
E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1791+
FIELD_GET(E1000_PBECCSTS_UNCORR_ERR_CNT_MASK, pbeccsts);
17931792

17941793
/* Do the reset outside of interrupt context */
17951794
schedule_work(&adapter->reset_task);
@@ -1868,8 +1867,7 @@ static irqreturn_t e1000_intr(int __always_unused irq, void *data)
18681867
adapter->corr_errors +=
18691868
pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
18701869
adapter->uncorr_errors +=
1871-
(pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1872-
E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1870+
FIELD_GET(E1000_PBECCSTS_UNCORR_ERR_CNT_MASK, pbeccsts);
18731871

18741872
/* Do the reset outside of interrupt context */
18751873
schedule_work(&adapter->reset_task);
@@ -5031,8 +5029,7 @@ static void e1000e_update_stats(struct e1000_adapter *adapter)
50315029
adapter->corr_errors +=
50325030
pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
50335031
adapter->uncorr_errors +=
5034-
(pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
5035-
E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
5032+
FIELD_GET(E1000_PBECCSTS_UNCORR_ERR_CNT_MASK, pbeccsts);
50365033
}
50375034
}
50385035

@@ -6249,7 +6246,7 @@ static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
62496246
phy_reg |= BM_RCTL_MPE;
62506247
phy_reg &= ~(BM_RCTL_MO_MASK);
62516248
if (mac_reg & E1000_RCTL_MO_3)
6252-
phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
6249+
phy_reg |= (FIELD_GET(E1000_RCTL_MO_3, mac_reg)
62536250
<< BM_RCTL_MO_SHIFT);
62546251
if (mac_reg & E1000_RCTL_BAM)
62556252
phy_reg |= BM_RCTL_BAM;

drivers/net/ethernet/intel/e1000e/phy.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,9 @@ s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
154154
e_dbg("MDI Read PHY Reg Address %d Error\n", offset);
155155
return -E1000_ERR_PHY;
156156
}
157-
if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
157+
if (FIELD_GET(E1000_MDIC_REG_MASK, mdic) != offset) {
158158
e_dbg("MDI Read offset error - requested %d, returned %d\n",
159-
offset,
160-
(mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
159+
offset, FIELD_GET(E1000_MDIC_REG_MASK, mdic));
161160
return -E1000_ERR_PHY;
162161
}
163162
*data = (u16)mdic;
@@ -167,7 +166,6 @@ s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
167166
*/
168167
if (hw->mac.type == e1000_pch2lan)
169168
udelay(100);
170-
171169
return 0;
172170
}
173171

@@ -218,10 +216,9 @@ s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
218216
e_dbg("MDI Write PHY Red Address %d Error\n", offset);
219217
return -E1000_ERR_PHY;
220218
}
221-
if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
219+
if (FIELD_GET(E1000_MDIC_REG_MASK, mdic) != offset) {
222220
e_dbg("MDI Write offset error - requested %d, returned %d\n",
223-
offset,
224-
(mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
221+
offset, FIELD_GET(E1000_MDIC_REG_MASK, mdic));
225222
return -E1000_ERR_PHY;
226223
}
227224

@@ -1792,8 +1789,7 @@ s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
17921789
if (ret_val)
17931790
return ret_val;
17941791

1795-
index = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1796-
M88E1000_PSSR_CABLE_LENGTH_SHIFT);
1792+
index = FIELD_GET(M88E1000_PSSR_CABLE_LENGTH, phy_data);
17971793

17981794
if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
17991795
return -E1000_ERR_PHY;
@@ -3233,8 +3229,7 @@ s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
32333229
if (ret_val)
32343230
return ret_val;
32353231

3236-
length = ((phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
3237-
I82577_DSTATUS_CABLE_LENGTH_SHIFT);
3232+
length = FIELD_GET(I82577_DSTATUS_CABLE_LENGTH, phy_data);
32383233

32393234
if (length == E1000_CABLE_LENGTH_UNDEFINED)
32403235
return -E1000_ERR_PHY;

drivers/net/ethernet/intel/fm10k/fm10k_pf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,8 +1575,7 @@ static s32 fm10k_get_fault_pf(struct fm10k_hw *hw, int type,
15751575
if (func & FM10K_FAULT_FUNC_PF)
15761576
fault->func = 0;
15771577
else
1578-
fault->func = 1 + ((func & FM10K_FAULT_FUNC_VF_MASK) >>
1579-
FM10K_FAULT_FUNC_VF_SHIFT);
1578+
fault->func = 1 + FIELD_GET(FM10K_FAULT_FUNC_VF_MASK, func);
15801579

15811580
/* record fault type */
15821581
fault->type = func & FM10K_FAULT_FUNC_TYPE_MASK;

drivers/net/ethernet/intel/fm10k/fm10k_vf.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,14 @@ static s32 fm10k_init_hw_vf(struct fm10k_hw *hw)
127127
hw->mac.max_queues = i;
128128

129129
/* fetch default VLAN and ITR scale */
130-
hw->mac.default_vid = (fm10k_read_reg(hw, FM10K_TXQCTL(0)) &
131-
FM10K_TXQCTL_VID_MASK) >> FM10K_TXQCTL_VID_SHIFT;
130+
hw->mac.default_vid = FIELD_GET(FM10K_TXQCTL_VID_MASK,
131+
fm10k_read_reg(hw, FM10K_TXQCTL(0)));
132132
/* Read the ITR scale from TDLEN. See the definition of
133133
* FM10K_TDLEN_ITR_SCALE_SHIFT for more information about how TDLEN is
134134
* used here.
135135
*/
136-
hw->mac.itr_scale = (fm10k_read_reg(hw, FM10K_TDLEN(0)) &
137-
FM10K_TDLEN_ITR_SCALE_MASK) >>
138-
FM10K_TDLEN_ITR_SCALE_SHIFT;
136+
hw->mac.itr_scale = FIELD_GET(FM10K_TDLEN_ITR_SCALE_MASK,
137+
fm10k_read_reg(hw, FM10K_TDLEN(0)));
139138

140139
return 0;
141140

0 commit comments

Comments
 (0)