]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.6/intel-legacy-field-get-conversion.patch
e788a72fd02144ba80d1612705f4152477030519
[thirdparty/kernel/stable-queue.git] / queue-6.6 / intel-legacy-field-get-conversion.patch
1 From 9ecba4151dd81e086d29a7173fe45ef6f6644065 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Tue, 5 Dec 2023 17:01:08 -0800
4 Subject: intel: legacy: field get conversion
5
6 From: Jesse Brandeburg <jesse.brandeburg@intel.com>
7
8 [ Upstream commit b9a4525450758dd75edbdaee97425ba7546c2b5c ]
9
10 Refactor several older Intel drivers to use FIELD_GET(), which reduces
11 lines of code and adds clarity of intent.
12
13 This code was generated by the following coccinelle/spatch script and
14 then manually repaired.
15
16 @get@
17 constant shift,mask;
18 type T;
19 expression a;
20 @@
21 (
22 -((T)((a) & mask) >> shift)
23 +FIELD_GET(mask, a)
24
25 and applied via:
26 spatch --sp-file field_prep.cocci --in-place --dir \
27 drivers/net/ethernet/intel/
28
29 Cc: Julia Lawall <Julia.Lawall@inria.fr>
30 CC: Alexander Lobakin <aleksander.lobakin@intel.com>
31 Reviewed-by: Marcin Szycik <marcin.szycik@linux.intel.com>
32 Reviewed-by: Simon Horman <horms@kernel.org>
33 Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
34 Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel)
35 Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
36 Stable-dep-of: 6dbdd4de0362 ("e1000e: Workaround for sporadic MDI error on Meteor Lake systems")
37 Signed-off-by: Sasha Levin <sashal@kernel.org>
38 ---
39 drivers/net/ethernet/intel/e1000/e1000_hw.c | 45 ++++++++-----------
40 .../net/ethernet/intel/e1000e/80003es2lan.c | 3 +-
41 drivers/net/ethernet/intel/e1000e/82571.c | 3 +-
42 drivers/net/ethernet/intel/e1000e/ethtool.c | 7 ++-
43 drivers/net/ethernet/intel/e1000e/ich8lan.c | 18 +++-----
44 drivers/net/ethernet/intel/e1000e/mac.c | 2 +-
45 drivers/net/ethernet/intel/e1000e/netdev.c | 11 ++---
46 drivers/net/ethernet/intel/e1000e/phy.c | 17 +++----
47 drivers/net/ethernet/intel/fm10k/fm10k_pf.c | 3 +-
48 drivers/net/ethernet/intel/fm10k/fm10k_vf.c | 9 ++--
49 drivers/net/ethernet/intel/igb/e1000_82575.c | 29 +++++-------
50 drivers/net/ethernet/intel/igb/e1000_i210.c | 15 ++++---
51 drivers/net/ethernet/intel/igb/e1000_mac.c | 2 +-
52 drivers/net/ethernet/intel/igb/e1000_nvm.c | 14 +++---
53 drivers/net/ethernet/intel/igb/e1000_phy.c | 9 ++--
54 drivers/net/ethernet/intel/igb/igb_ethtool.c | 8 ++--
55 drivers/net/ethernet/intel/igb/igb_main.c | 4 +-
56 drivers/net/ethernet/intel/igbvf/mbx.c | 1 +
57 drivers/net/ethernet/intel/igbvf/netdev.c | 5 +--
58 .../net/ethernet/intel/ixgbe/ixgbe_common.c | 30 ++++++-------
59 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 +-
60 drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c | 8 ++--
61 .../net/ethernet/intel/ixgbe/ixgbe_sriov.c | 8 ++--
62 drivers/net/ethernet/intel/ixgbe/ixgbe_x540.c | 8 ++--
63 drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c | 19 ++++----
64 25 files changed, 118 insertions(+), 162 deletions(-)
65
66 diff --git a/drivers/net/ethernet/intel/e1000/e1000_hw.c b/drivers/net/ethernet/intel/e1000/e1000_hw.c
67 index 4576511c99f56..f9328f2e669f8 100644
68 --- a/drivers/net/ethernet/intel/e1000/e1000_hw.c
69 +++ b/drivers/net/ethernet/intel/e1000/e1000_hw.c
70 @@ -3261,8 +3261,7 @@ static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
71 return ret_val;
72
73 phy_info->mdix_mode =
74 - (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
75 - IGP01E1000_PSSR_MDIX_SHIFT);
76 + (e1000_auto_x_mode)FIELD_GET(IGP01E1000_PSSR_MDIX, phy_data);
77
78 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
79 IGP01E1000_PSSR_SPEED_1000MBPS) {
80 @@ -3273,11 +3272,11 @@ static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
81 if (ret_val)
82 return ret_val;
83
84 - phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
85 - SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
86 + phy_info->local_rx = FIELD_GET(SR_1000T_LOCAL_RX_STATUS,
87 + phy_data) ?
88 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
89 - phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
90 - SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
91 + phy_info->remote_rx = FIELD_GET(SR_1000T_REMOTE_RX_STATUS,
92 + phy_data) ?
93 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
94
95 /* Get cable length */
96 @@ -3327,14 +3326,12 @@ static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
97 return ret_val;
98
99 phy_info->extended_10bt_distance =
100 - ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
101 - M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
102 + FIELD_GET(M88E1000_PSCR_10BT_EXT_DIST_ENABLE, phy_data) ?
103 e1000_10bt_ext_dist_enable_lower :
104 e1000_10bt_ext_dist_enable_normal;
105
106 phy_info->polarity_correction =
107 - ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
108 - M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
109 + FIELD_GET(M88E1000_PSCR_POLARITY_REVERSAL, phy_data) ?
110 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
111
112 /* Check polarity status */
113 @@ -3348,27 +3345,25 @@ static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
114 return ret_val;
115
116 phy_info->mdix_mode =
117 - (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
118 - M88E1000_PSSR_MDIX_SHIFT);
119 + (e1000_auto_x_mode)FIELD_GET(M88E1000_PSSR_MDIX, phy_data);
120
121 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
122 /* Cable Length Estimation and Local/Remote Receiver Information
123 * are only valid at 1000 Mbps.
124 */
125 phy_info->cable_length =
126 - (e1000_cable_length) ((phy_data &
127 - M88E1000_PSSR_CABLE_LENGTH) >>
128 - M88E1000_PSSR_CABLE_LENGTH_SHIFT);
129 + (e1000_cable_length)FIELD_GET(M88E1000_PSSR_CABLE_LENGTH,
130 + phy_data);
131
132 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
133 if (ret_val)
134 return ret_val;
135
136 - phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
137 - SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
138 + phy_info->local_rx = FIELD_GET(SR_1000T_LOCAL_RX_STATUS,
139 + phy_data) ?
140 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
141 - phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
142 - SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
143 + phy_info->remote_rx = FIELD_GET(SR_1000T_REMOTE_RX_STATUS,
144 + phy_data) ?
145 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
146 }
147
148 @@ -3516,7 +3511,7 @@ s32 e1000_init_eeprom_params(struct e1000_hw *hw)
149 if (ret_val)
150 return ret_val;
151 eeprom_size =
152 - (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
153 + FIELD_GET(EEPROM_SIZE_MASK, eeprom_size);
154 /* 256B eeprom size was not supported in earlier hardware, so we
155 * bump eeprom_size up one to ensure that "1" (which maps to
156 * 256B) is never the result used in the shifting logic below.
157 @@ -4892,8 +4887,7 @@ static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
158 &phy_data);
159 if (ret_val)
160 return ret_val;
161 - cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
162 - M88E1000_PSSR_CABLE_LENGTH_SHIFT;
163 + cable_length = FIELD_GET(M88E1000_PSSR_CABLE_LENGTH, phy_data);
164
165 /* Convert the enum value to ranged values */
166 switch (cable_length) {
167 @@ -5002,8 +4996,7 @@ static s32 e1000_check_polarity(struct e1000_hw *hw,
168 &phy_data);
169 if (ret_val)
170 return ret_val;
171 - *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
172 - M88E1000_PSSR_REV_POLARITY_SHIFT) ?
173 + *polarity = FIELD_GET(M88E1000_PSSR_REV_POLARITY, phy_data) ?
174 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
175
176 } else if (hw->phy_type == e1000_phy_igp) {
177 @@ -5073,8 +5066,8 @@ static s32 e1000_check_downshift(struct e1000_hw *hw)
178 if (ret_val)
179 return ret_val;
180
181 - hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
182 - M88E1000_PSSR_DOWNSHIFT_SHIFT;
183 + hw->speed_downgraded = FIELD_GET(M88E1000_PSSR_DOWNSHIFT,
184 + phy_data);
185 }
186
187 return E1000_SUCCESS;
188 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
189 index be9c695dde127..c51fb6bf9c4e0 100644
190 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
191 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
192 @@ -92,8 +92,7 @@ static s32 e1000_init_nvm_params_80003es2lan(struct e1000_hw *hw)
193
194 nvm->type = e1000_nvm_eeprom_spi;
195
196 - size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
197 - E1000_EECD_SIZE_EX_SHIFT);
198 + size = (u16)FIELD_GET(E1000_EECD_SIZE_EX_MASK, eecd);
199
200 /* Added to a constant, "size" becomes the left-shift value
201 * for setting word_size.
202 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
203 index 0b1e890dd583b..969f855a79ee6 100644
204 --- a/drivers/net/ethernet/intel/e1000e/82571.c
205 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
206 @@ -157,8 +157,7 @@ static s32 e1000_init_nvm_params_82571(struct e1000_hw *hw)
207 fallthrough;
208 default:
209 nvm->type = e1000_nvm_eeprom_spi;
210 - size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
211 - E1000_EECD_SIZE_EX_SHIFT);
212 + size = (u16)FIELD_GET(E1000_EECD_SIZE_EX_MASK, eecd);
213 /* Added to a constant, "size" becomes the left-shift value
214 * for setting word_size.
215 */
216 diff --git a/drivers/net/ethernet/intel/e1000e/ethtool.c b/drivers/net/ethernet/intel/e1000e/ethtool.c
217 index 9835e6a90d56c..fc0f98ea61332 100644
218 --- a/drivers/net/ethernet/intel/e1000e/ethtool.c
219 +++ b/drivers/net/ethernet/intel/e1000e/ethtool.c
220 @@ -654,8 +654,8 @@ static void e1000_get_drvinfo(struct net_device *netdev,
221 */
222 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
223 "%d.%d-%d",
224 - (adapter->eeprom_vers & 0xF000) >> 12,
225 - (adapter->eeprom_vers & 0x0FF0) >> 4,
226 + FIELD_GET(0xF000, adapter->eeprom_vers),
227 + FIELD_GET(0x0FF0, adapter->eeprom_vers),
228 (adapter->eeprom_vers & 0x000F));
229
230 strscpy(drvinfo->bus_info, pci_name(adapter->pdev),
231 @@ -925,8 +925,7 @@ static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
232 }
233
234 if (mac->type >= e1000_pch_lpt)
235 - wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
236 - E1000_FWSM_WLOCK_MAC_SHIFT;
237 + wlock_mac = FIELD_GET(E1000_FWSM_WLOCK_MAC_MASK, er32(FWSM));
238
239 for (i = 0; i < mac->rar_entry_count; i++) {
240 if (mac->type >= e1000_pch_lpt) {
241 diff --git a/drivers/net/ethernet/intel/e1000e/ich8lan.c b/drivers/net/ethernet/intel/e1000e/ich8lan.c
242 index 39e9fc601bf5a..a2788fd5f8bb8 100644
243 --- a/drivers/net/ethernet/intel/e1000e/ich8lan.c
244 +++ b/drivers/net/ethernet/intel/e1000e/ich8lan.c
245 @@ -1072,13 +1072,11 @@ static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
246
247 lat_enc_d = (lat_enc & E1000_LTRV_VALUE_MASK) *
248 (1U << (E1000_LTRV_SCALE_FACTOR *
249 - ((lat_enc & E1000_LTRV_SCALE_MASK)
250 - >> E1000_LTRV_SCALE_SHIFT)));
251 + FIELD_GET(E1000_LTRV_SCALE_MASK, lat_enc)));
252
253 max_ltr_enc_d = (max_ltr_enc & E1000_LTRV_VALUE_MASK) *
254 - (1U << (E1000_LTRV_SCALE_FACTOR *
255 - ((max_ltr_enc & E1000_LTRV_SCALE_MASK)
256 - >> E1000_LTRV_SCALE_SHIFT)));
257 + (1U << (E1000_LTRV_SCALE_FACTOR *
258 + FIELD_GET(E1000_LTRV_SCALE_MASK, max_ltr_enc)));
259
260 if (lat_enc_d > max_ltr_enc_d)
261 lat_enc = max_ltr_enc;
262 @@ -2075,8 +2073,7 @@ static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
263 {
264 u16 phy_data;
265 u32 strap = er32(STRAP);
266 - u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
267 - E1000_STRAP_SMT_FREQ_SHIFT;
268 + u32 freq = FIELD_GET(E1000_STRAP_SMT_FREQ_MASK, strap);
269 s32 ret_val;
270
271 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
272 @@ -2562,8 +2559,7 @@ void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
273 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
274 (u16)(mac_reg & 0xFFFF));
275 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
276 - (u16)((mac_reg & E1000_RAH_AV)
277 - >> 16));
278 + FIELD_GET(E1000_RAH_AV, mac_reg));
279 }
280
281 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
282 @@ -3205,7 +3201,7 @@ static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
283 &nvm_dword);
284 if (ret_val)
285 return ret_val;
286 - sig_byte = (u8)((nvm_dword & 0xFF00) >> 8);
287 + sig_byte = FIELD_GET(0xFF00, nvm_dword);
288 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
289 E1000_ICH_NVM_SIG_VALUE) {
290 *bank = 0;
291 @@ -3218,7 +3214,7 @@ static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
292 &nvm_dword);
293 if (ret_val)
294 return ret_val;
295 - sig_byte = (u8)((nvm_dword & 0xFF00) >> 8);
296 + sig_byte = FIELD_GET(0xFF00, nvm_dword);
297 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
298 E1000_ICH_NVM_SIG_VALUE) {
299 *bank = 1;
300 diff --git a/drivers/net/ethernet/intel/e1000e/mac.c b/drivers/net/ethernet/intel/e1000e/mac.c
301 index 5df7ad93f3d77..30515bfb259ea 100644
302 --- a/drivers/net/ethernet/intel/e1000e/mac.c
303 +++ b/drivers/net/ethernet/intel/e1000e/mac.c
304 @@ -52,7 +52,7 @@ void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw)
305 * for the device regardless of function swap state.
306 */
307 reg = er32(STATUS);
308 - bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
309 + bus->func = FIELD_GET(E1000_STATUS_FUNC_MASK, reg);
310 }
311
312 /**
313 diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c
314 index f536c856727cb..af5d9d97a0d6c 100644
315 --- a/drivers/net/ethernet/intel/e1000e/netdev.c
316 +++ b/drivers/net/ethernet/intel/e1000e/netdev.c
317 @@ -1788,8 +1788,7 @@ static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
318 adapter->corr_errors +=
319 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
320 adapter->uncorr_errors +=
321 - (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
322 - E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
323 + FIELD_GET(E1000_PBECCSTS_UNCORR_ERR_CNT_MASK, pbeccsts);
324
325 /* Do the reset outside of interrupt context */
326 schedule_work(&adapter->reset_task);
327 @@ -1868,8 +1867,7 @@ static irqreturn_t e1000_intr(int __always_unused irq, void *data)
328 adapter->corr_errors +=
329 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
330 adapter->uncorr_errors +=
331 - (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
332 - E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
333 + FIELD_GET(E1000_PBECCSTS_UNCORR_ERR_CNT_MASK, pbeccsts);
334
335 /* Do the reset outside of interrupt context */
336 schedule_work(&adapter->reset_task);
337 @@ -5031,8 +5029,7 @@ static void e1000e_update_stats(struct e1000_adapter *adapter)
338 adapter->corr_errors +=
339 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
340 adapter->uncorr_errors +=
341 - (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
342 - E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
343 + FIELD_GET(E1000_PBECCSTS_UNCORR_ERR_CNT_MASK, pbeccsts);
344 }
345 }
346
347 @@ -6249,7 +6246,7 @@ static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
348 phy_reg |= BM_RCTL_MPE;
349 phy_reg &= ~(BM_RCTL_MO_MASK);
350 if (mac_reg & E1000_RCTL_MO_3)
351 - phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
352 + phy_reg |= (FIELD_GET(E1000_RCTL_MO_3, mac_reg)
353 << BM_RCTL_MO_SHIFT);
354 if (mac_reg & E1000_RCTL_BAM)
355 phy_reg |= BM_RCTL_BAM;
356 diff --git a/drivers/net/ethernet/intel/e1000e/phy.c b/drivers/net/ethernet/intel/e1000e/phy.c
357 index 08c3d477dd6f7..96ff0ca561b6c 100644
358 --- a/drivers/net/ethernet/intel/e1000e/phy.c
359 +++ b/drivers/net/ethernet/intel/e1000e/phy.c
360 @@ -154,10 +154,9 @@ s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
361 e_dbg("MDI Read PHY Reg Address %d Error\n", offset);
362 return -E1000_ERR_PHY;
363 }
364 - if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
365 + if (FIELD_GET(E1000_MDIC_REG_MASK, mdic) != offset) {
366 e_dbg("MDI Read offset error - requested %d, returned %d\n",
367 - offset,
368 - (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
369 + offset, FIELD_GET(E1000_MDIC_REG_MASK, mdic));
370 return -E1000_ERR_PHY;
371 }
372 *data = (u16)mdic;
373 @@ -167,7 +166,6 @@ s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
374 */
375 if (hw->mac.type == e1000_pch2lan)
376 udelay(100);
377 -
378 return 0;
379 }
380
381 @@ -218,10 +216,9 @@ s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
382 e_dbg("MDI Write PHY Red Address %d Error\n", offset);
383 return -E1000_ERR_PHY;
384 }
385 - if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
386 + if (FIELD_GET(E1000_MDIC_REG_MASK, mdic) != offset) {
387 e_dbg("MDI Write offset error - requested %d, returned %d\n",
388 - offset,
389 - (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
390 + offset, FIELD_GET(E1000_MDIC_REG_MASK, mdic));
391 return -E1000_ERR_PHY;
392 }
393
394 @@ -1793,8 +1790,7 @@ s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
395 if (ret_val)
396 return ret_val;
397
398 - index = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
399 - M88E1000_PSSR_CABLE_LENGTH_SHIFT);
400 + index = FIELD_GET(M88E1000_PSSR_CABLE_LENGTH, phy_data);
401
402 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
403 return -E1000_ERR_PHY;
404 @@ -3234,8 +3230,7 @@ s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
405 if (ret_val)
406 return ret_val;
407
408 - length = ((phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
409 - I82577_DSTATUS_CABLE_LENGTH_SHIFT);
410 + length = FIELD_GET(I82577_DSTATUS_CABLE_LENGTH, phy_data);
411
412 if (length == E1000_CABLE_LENGTH_UNDEFINED)
413 return -E1000_ERR_PHY;
414 diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_pf.c b/drivers/net/ethernet/intel/fm10k/fm10k_pf.c
415 index ae700a1807c65..aed5e0bf6313e 100644
416 --- a/drivers/net/ethernet/intel/fm10k/fm10k_pf.c
417 +++ b/drivers/net/ethernet/intel/fm10k/fm10k_pf.c
418 @@ -1576,8 +1576,7 @@ static s32 fm10k_get_fault_pf(struct fm10k_hw *hw, int type,
419 if (func & FM10K_FAULT_FUNC_PF)
420 fault->func = 0;
421 else
422 - fault->func = 1 + ((func & FM10K_FAULT_FUNC_VF_MASK) >>
423 - FM10K_FAULT_FUNC_VF_SHIFT);
424 + fault->func = 1 + FIELD_GET(FM10K_FAULT_FUNC_VF_MASK, func);
425
426 /* record fault type */
427 fault->type = func & FM10K_FAULT_FUNC_TYPE_MASK;
428 diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_vf.c b/drivers/net/ethernet/intel/fm10k/fm10k_vf.c
429 index c50928ec14fff..7fb1961f29210 100644
430 --- a/drivers/net/ethernet/intel/fm10k/fm10k_vf.c
431 +++ b/drivers/net/ethernet/intel/fm10k/fm10k_vf.c
432 @@ -127,15 +127,14 @@ static s32 fm10k_init_hw_vf(struct fm10k_hw *hw)
433 hw->mac.max_queues = i;
434
435 /* fetch default VLAN and ITR scale */
436 - hw->mac.default_vid = (fm10k_read_reg(hw, FM10K_TXQCTL(0)) &
437 - FM10K_TXQCTL_VID_MASK) >> FM10K_TXQCTL_VID_SHIFT;
438 + hw->mac.default_vid = FIELD_GET(FM10K_TXQCTL_VID_MASK,
439 + fm10k_read_reg(hw, FM10K_TXQCTL(0)));
440 /* Read the ITR scale from TDLEN. See the definition of
441 * FM10K_TDLEN_ITR_SCALE_SHIFT for more information about how TDLEN is
442 * used here.
443 */
444 - hw->mac.itr_scale = (fm10k_read_reg(hw, FM10K_TDLEN(0)) &
445 - FM10K_TDLEN_ITR_SCALE_MASK) >>
446 - FM10K_TDLEN_ITR_SCALE_SHIFT;
447 + hw->mac.itr_scale = FIELD_GET(FM10K_TDLEN_ITR_SCALE_MASK,
448 + fm10k_read_reg(hw, FM10K_TDLEN(0)));
449
450 return 0;
451
452 diff --git a/drivers/net/ethernet/intel/igb/e1000_82575.c b/drivers/net/ethernet/intel/igb/e1000_82575.c
453 index 8d6e44ee1895a..64dfc362d1dc4 100644
454 --- a/drivers/net/ethernet/intel/igb/e1000_82575.c
455 +++ b/drivers/net/ethernet/intel/igb/e1000_82575.c
456 @@ -222,8 +222,7 @@ static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
457 }
458
459 /* set lan id */
460 - hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
461 - E1000_STATUS_FUNC_SHIFT;
462 + hw->bus.func = FIELD_GET(E1000_STATUS_FUNC_MASK, rd32(E1000_STATUS));
463
464 /* Set phy->phy_addr and phy->id. */
465 ret_val = igb_get_phy_id_82575(hw);
466 @@ -262,8 +261,8 @@ static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
467 if (ret_val)
468 goto out;
469
470 - data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
471 - E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
472 + data = FIELD_GET(E1000_M88E1112_MAC_CTRL_1_MODE_MASK,
473 + data);
474 if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
475 data == E1000_M88E1112_AUTO_COPPER_BASEX)
476 hw->mac.ops.check_for_link =
477 @@ -330,8 +329,7 @@ static s32 igb_init_nvm_params_82575(struct e1000_hw *hw)
478 u32 eecd = rd32(E1000_EECD);
479 u16 size;
480
481 - size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
482 - E1000_EECD_SIZE_EX_SHIFT);
483 + size = FIELD_GET(E1000_EECD_SIZE_EX_MASK, eecd);
484
485 /* Added to a constant, "size" becomes the left-shift value
486 * for setting word_size.
487 @@ -2798,7 +2796,7 @@ static s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
488 return 0;
489
490 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
491 - if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
492 + if (FIELD_GET(NVM_ETS_TYPE_MASK, ets_cfg)
493 != NVM_ETS_TYPE_EMC)
494 return E1000_NOT_IMPLEMENTED;
495
496 @@ -2808,10 +2806,8 @@ static s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
497
498 for (i = 1; i < num_sensors; i++) {
499 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
500 - sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
501 - NVM_ETS_DATA_INDEX_SHIFT);
502 - sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
503 - NVM_ETS_DATA_LOC_SHIFT);
504 + sensor_index = FIELD_GET(NVM_ETS_DATA_INDEX_MASK, ets_sensor);
505 + sensor_location = FIELD_GET(NVM_ETS_DATA_LOC_MASK, ets_sensor);
506
507 if (sensor_location != 0)
508 hw->phy.ops.read_i2c_byte(hw,
509 @@ -2859,20 +2855,17 @@ static s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
510 return 0;
511
512 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
513 - if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
514 + if (FIELD_GET(NVM_ETS_TYPE_MASK, ets_cfg)
515 != NVM_ETS_TYPE_EMC)
516 return E1000_NOT_IMPLEMENTED;
517
518 - low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
519 - NVM_ETS_LTHRES_DELTA_SHIFT);
520 + low_thresh_delta = FIELD_GET(NVM_ETS_LTHRES_DELTA_MASK, ets_cfg);
521 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
522
523 for (i = 1; i <= num_sensors; i++) {
524 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
525 - sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
526 - NVM_ETS_DATA_INDEX_SHIFT);
527 - sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
528 - NVM_ETS_DATA_LOC_SHIFT);
529 + sensor_index = FIELD_GET(NVM_ETS_DATA_INDEX_MASK, ets_sensor);
530 + sensor_location = FIELD_GET(NVM_ETS_DATA_LOC_MASK, ets_sensor);
531 therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
532
533 hw->phy.ops.write_i2c_byte(hw,
534 diff --git a/drivers/net/ethernet/intel/igb/e1000_i210.c b/drivers/net/ethernet/intel/igb/e1000_i210.c
535 index 53b396fd194a3..503b239868e8e 100644
536 --- a/drivers/net/ethernet/intel/igb/e1000_i210.c
537 +++ b/drivers/net/ethernet/intel/igb/e1000_i210.c
538 @@ -473,7 +473,7 @@ s32 igb_read_invm_version(struct e1000_hw *hw,
539 /* Check if we have second version location used */
540 else if ((i == 1) &&
541 ((*record & E1000_INVM_VER_FIELD_TWO) == 0)) {
542 - version = (*record & E1000_INVM_VER_FIELD_ONE) >> 3;
543 + version = FIELD_GET(E1000_INVM_VER_FIELD_ONE, *record);
544 status = 0;
545 break;
546 }
547 @@ -483,8 +483,8 @@ s32 igb_read_invm_version(struct e1000_hw *hw,
548 else if ((((*record & E1000_INVM_VER_FIELD_ONE) == 0) &&
549 ((*record & 0x3) == 0)) || (((*record & 0x3) != 0) &&
550 (i != 1))) {
551 - version = (*next_record & E1000_INVM_VER_FIELD_TWO)
552 - >> 13;
553 + version = FIELD_GET(E1000_INVM_VER_FIELD_TWO,
554 + *next_record);
555 status = 0;
556 break;
557 }
558 @@ -493,15 +493,15 @@ s32 igb_read_invm_version(struct e1000_hw *hw,
559 */
560 else if (((*record & E1000_INVM_VER_FIELD_TWO) == 0) &&
561 ((*record & 0x3) == 0)) {
562 - version = (*record & E1000_INVM_VER_FIELD_ONE) >> 3;
563 + version = FIELD_GET(E1000_INVM_VER_FIELD_ONE, *record);
564 status = 0;
565 break;
566 }
567 }
568
569 if (!status) {
570 - invm_ver->invm_major = (version & E1000_INVM_MAJOR_MASK)
571 - >> E1000_INVM_MAJOR_SHIFT;
572 + invm_ver->invm_major = FIELD_GET(E1000_INVM_MAJOR_MASK,
573 + version);
574 invm_ver->invm_minor = version & E1000_INVM_MINOR_MASK;
575 }
576 /* Read Image Type */
577 @@ -520,7 +520,8 @@ s32 igb_read_invm_version(struct e1000_hw *hw,
578 ((*record & E1000_INVM_IMGTYPE_FIELD) == 0)) ||
579 ((((*record & 0x3) != 0) && (i != 1)))) {
580 invm_ver->invm_img_type =
581 - (*next_record & E1000_INVM_IMGTYPE_FIELD) >> 23;
582 + FIELD_GET(E1000_INVM_IMGTYPE_FIELD,
583 + *next_record);
584 status = 0;
585 break;
586 }
587 diff --git a/drivers/net/ethernet/intel/igb/e1000_mac.c b/drivers/net/ethernet/intel/igb/e1000_mac.c
588 index caf91c6f52b4d..ceaec2cf08a43 100644
589 --- a/drivers/net/ethernet/intel/igb/e1000_mac.c
590 +++ b/drivers/net/ethernet/intel/igb/e1000_mac.c
591 @@ -56,7 +56,7 @@ s32 igb_get_bus_info_pcie(struct e1000_hw *hw)
592 }
593
594 reg = rd32(E1000_STATUS);
595 - bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
596 + bus->func = FIELD_GET(E1000_STATUS_FUNC_MASK, reg);
597
598 return 0;
599 }
600 diff --git a/drivers/net/ethernet/intel/igb/e1000_nvm.c b/drivers/net/ethernet/intel/igb/e1000_nvm.c
601 index 0da57e89593a0..2dcd64d6dec31 100644
602 --- a/drivers/net/ethernet/intel/igb/e1000_nvm.c
603 +++ b/drivers/net/ethernet/intel/igb/e1000_nvm.c
604 @@ -708,10 +708,10 @@ void igb_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers)
605 */
606 if ((etrack_test & NVM_MAJOR_MASK) != NVM_ETRACK_VALID) {
607 hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
608 - fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK)
609 - >> NVM_MAJOR_SHIFT;
610 - fw_vers->eep_minor = (fw_version & NVM_MINOR_MASK)
611 - >> NVM_MINOR_SHIFT;
612 + fw_vers->eep_major = FIELD_GET(NVM_MAJOR_MASK,
613 + fw_version);
614 + fw_vers->eep_minor = FIELD_GET(NVM_MINOR_MASK,
615 + fw_version);
616 fw_vers->eep_build = (fw_version & NVM_IMAGE_ID_MASK);
617 goto etrack_id;
618 }
619 @@ -753,15 +753,13 @@ void igb_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers)
620 return;
621 }
622 hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
623 - fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK)
624 - >> NVM_MAJOR_SHIFT;
625 + fw_vers->eep_major = FIELD_GET(NVM_MAJOR_MASK, fw_version);
626
627 /* check for old style version format in newer images*/
628 if ((fw_version & NVM_NEW_DEC_MASK) == 0x0) {
629 eeprom_verl = (fw_version & NVM_COMB_VER_MASK);
630 } else {
631 - eeprom_verl = (fw_version & NVM_MINOR_MASK)
632 - >> NVM_MINOR_SHIFT;
633 + eeprom_verl = FIELD_GET(NVM_MINOR_MASK, fw_version);
634 }
635 /* Convert minor value to hex before assigning to output struct
636 * Val to be converted will not be higher than 99, per tool output
637 diff --git a/drivers/net/ethernet/intel/igb/e1000_phy.c b/drivers/net/ethernet/intel/igb/e1000_phy.c
638 index 3c1b562a3271c..bed94e50a6693 100644
639 --- a/drivers/net/ethernet/intel/igb/e1000_phy.c
640 +++ b/drivers/net/ethernet/intel/igb/e1000_phy.c
641 @@ -1682,8 +1682,7 @@ s32 igb_get_cable_length_m88(struct e1000_hw *hw)
642 if (ret_val)
643 goto out;
644
645 - index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
646 - M88E1000_PSSR_CABLE_LENGTH_SHIFT;
647 + index = FIELD_GET(M88E1000_PSSR_CABLE_LENGTH, phy_data);
648 if (index >= ARRAY_SIZE(e1000_m88_cable_length_table) - 1) {
649 ret_val = -E1000_ERR_PHY;
650 goto out;
651 @@ -1796,8 +1795,7 @@ s32 igb_get_cable_length_m88_gen2(struct e1000_hw *hw)
652 if (ret_val)
653 goto out;
654
655 - index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
656 - M88E1000_PSSR_CABLE_LENGTH_SHIFT;
657 + index = FIELD_GET(M88E1000_PSSR_CABLE_LENGTH, phy_data);
658 if (index >= ARRAY_SIZE(e1000_m88_cable_length_table) - 1) {
659 ret_val = -E1000_ERR_PHY;
660 goto out;
661 @@ -2578,8 +2576,7 @@ s32 igb_get_cable_length_82580(struct e1000_hw *hw)
662 if (ret_val)
663 goto out;
664
665 - length = (phy_data & I82580_DSTATUS_CABLE_LENGTH) >>
666 - I82580_DSTATUS_CABLE_LENGTH_SHIFT;
667 + length = FIELD_GET(I82580_DSTATUS_CABLE_LENGTH, phy_data);
668
669 if (length == E1000_CABLE_LENGTH_UNDEFINED)
670 ret_val = -E1000_ERR_PHY;
671 diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
672 index 4ee849985e2b8..92b2be06a6e93 100644
673 --- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
674 +++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
675 @@ -2434,7 +2434,7 @@ static int igb_get_ts_info(struct net_device *dev,
676 }
677 }
678
679 -#define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
680 +#define ETHER_TYPE_FULL_MASK cpu_to_be16(FIELD_MAX(U16_MAX))
681 static int igb_get_ethtool_nfc_entry(struct igb_adapter *adapter,
682 struct ethtool_rxnfc *cmd)
683 {
684 @@ -2733,8 +2733,8 @@ static int igb_rxnfc_write_vlan_prio_filter(struct igb_adapter *adapter,
685 u32 vlapqf;
686
687 vlapqf = rd32(E1000_VLAPQF);
688 - vlan_priority = (ntohs(input->filter.vlan_tci) & VLAN_PRIO_MASK)
689 - >> VLAN_PRIO_SHIFT;
690 + vlan_priority = FIELD_GET(VLAN_PRIO_MASK,
691 + ntohs(input->filter.vlan_tci));
692 queue_index = (vlapqf >> (vlan_priority * 4)) & E1000_VLAPQF_QUEUE_MASK;
693
694 /* check whether this vlan prio is already set */
695 @@ -2817,7 +2817,7 @@ static void igb_clear_vlan_prio_filter(struct igb_adapter *adapter,
696 u8 vlan_priority;
697 u32 vlapqf;
698
699 - vlan_priority = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
700 + vlan_priority = FIELD_GET(VLAN_PRIO_MASK, vlan_tci);
701
702 vlapqf = rd32(E1000_VLAPQF);
703 vlapqf &= ~E1000_VLAPQF_P_VALID(vlan_priority);
704 diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
705 index 11921141b6079..4431e7693d45f 100644
706 --- a/drivers/net/ethernet/intel/igb/igb_main.c
707 +++ b/drivers/net/ethernet/intel/igb/igb_main.c
708 @@ -7283,7 +7283,7 @@ static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
709 static int igb_set_vf_multicasts(struct igb_adapter *adapter,
710 u32 *msgbuf, u32 vf)
711 {
712 - int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
713 + int n = FIELD_GET(E1000_VT_MSGINFO_MASK, msgbuf[0]);
714 u16 *hash_list = (u16 *)&msgbuf[1];
715 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
716 int i;
717 @@ -7543,7 +7543,7 @@ static int igb_ndo_set_vf_vlan(struct net_device *netdev, int vf,
718
719 static int igb_set_vf_vlan_msg(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
720 {
721 - int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
722 + int add = FIELD_GET(E1000_VT_MSGINFO_MASK, msgbuf[0]);
723 int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
724 int ret;
725
726 diff --git a/drivers/net/ethernet/intel/igbvf/mbx.c b/drivers/net/ethernet/intel/igbvf/mbx.c
727 index a3cd7ac48d4b6..d15282ee5ea8f 100644
728 --- a/drivers/net/ethernet/intel/igbvf/mbx.c
729 +++ b/drivers/net/ethernet/intel/igbvf/mbx.c
730 @@ -1,6 +1,7 @@
731 // SPDX-License-Identifier: GPL-2.0
732 /* Copyright(c) 2009 - 2018 Intel Corporation. */
733
734 +#include <linux/bitfield.h>
735 #include "mbx.h"
736
737 /**
738 diff --git a/drivers/net/ethernet/intel/igbvf/netdev.c b/drivers/net/ethernet/intel/igbvf/netdev.c
739 index c748668bf2fce..c5012fa36af2f 100644
740 --- a/drivers/net/ethernet/intel/igbvf/netdev.c
741 +++ b/drivers/net/ethernet/intel/igbvf/netdev.c
742 @@ -273,9 +273,8 @@ static bool igbvf_clean_rx_irq(struct igbvf_adapter *adapter,
743 * that case, it fills the header buffer and spills the rest
744 * into the page.
745 */
746 - hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info)
747 - & E1000_RXDADV_HDRBUFLEN_MASK) >>
748 - E1000_RXDADV_HDRBUFLEN_SHIFT;
749 + hlen = le16_get_bits(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info,
750 + E1000_RXDADV_HDRBUFLEN_MASK);
751 if (hlen > adapter->rx_ps_hdr_size)
752 hlen = adapter->rx_ps_hdr_size;
753
754 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
755 index b2a0f2aaa05be..2e6e0365154a1 100644
756 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
757 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
758 @@ -684,7 +684,7 @@ void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
759 u32 reg;
760
761 reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
762 - bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
763 + bus->func = FIELD_GET(IXGBE_STATUS_LAN_ID, reg);
764 bus->lan_id = bus->func;
765
766 /* check for a port swap */
767 @@ -695,8 +695,8 @@ void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
768 /* Get MAC instance from EEPROM for configuring CS4227 */
769 if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SFP) {
770 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CTRL_4, &ee_ctrl_4);
771 - bus->instance_id = (ee_ctrl_4 & IXGBE_EE_CTRL_4_INST_ID) >>
772 - IXGBE_EE_CTRL_4_INST_ID_SHIFT;
773 + bus->instance_id = FIELD_GET(IXGBE_EE_CTRL_4_INST_ID,
774 + ee_ctrl_4);
775 }
776 }
777
778 @@ -870,10 +870,9 @@ s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
779 * SPI EEPROM is assumed here. This code would need to
780 * change if a future EEPROM is not SPI.
781 */
782 - eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
783 - IXGBE_EEC_SIZE_SHIFT);
784 + eeprom_size = FIELD_GET(IXGBE_EEC_SIZE, eec);
785 eeprom->word_size = BIT(eeprom_size +
786 - IXGBE_EEPROM_WORD_SIZE_SHIFT);
787 + IXGBE_EEPROM_WORD_SIZE_SHIFT);
788 }
789
790 if (eec & IXGBE_EEC_ADDR_SIZE)
791 @@ -3935,10 +3934,10 @@ s32 ixgbe_get_thermal_sensor_data_generic(struct ixgbe_hw *hw)
792 if (status)
793 return status;
794
795 - sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
796 - IXGBE_ETS_DATA_INDEX_SHIFT);
797 - sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
798 - IXGBE_ETS_DATA_LOC_SHIFT);
799 + sensor_index = FIELD_GET(IXGBE_ETS_DATA_INDEX_MASK,
800 + ets_sensor);
801 + sensor_location = FIELD_GET(IXGBE_ETS_DATA_LOC_MASK,
802 + ets_sensor);
803
804 if (sensor_location != 0) {
805 status = hw->phy.ops.read_i2c_byte(hw,
806 @@ -3982,8 +3981,7 @@ s32 ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw *hw)
807 if (status)
808 return status;
809
810 - low_thresh_delta = ((ets_cfg & IXGBE_ETS_LTHRES_DELTA_MASK) >>
811 - IXGBE_ETS_LTHRES_DELTA_SHIFT);
812 + low_thresh_delta = FIELD_GET(IXGBE_ETS_LTHRES_DELTA_MASK, ets_cfg);
813 num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
814 if (num_sensors > IXGBE_MAX_SENSORS)
815 num_sensors = IXGBE_MAX_SENSORS;
816 @@ -3997,10 +3995,10 @@ s32 ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw *hw)
817 ets_offset + 1 + i);
818 continue;
819 }
820 - sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
821 - IXGBE_ETS_DATA_INDEX_SHIFT);
822 - sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
823 - IXGBE_ETS_DATA_LOC_SHIFT);
824 + sensor_index = FIELD_GET(IXGBE_ETS_DATA_INDEX_MASK,
825 + ets_sensor);
826 + sensor_location = FIELD_GET(IXGBE_ETS_DATA_LOC_MASK,
827 + ets_sensor);
828 therm_limit = ets_sensor & IXGBE_ETS_DATA_HTHRESH_MASK;
829
830 hw->phy.ops.write_i2c_byte(hw,
831 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
832 index cb23aad5953b0..f245f3df40fca 100644
833 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
834 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
835 @@ -11409,7 +11409,7 @@ static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
836 if ((pf_func & 1) == (pdev->devfn & 1)) {
837 unsigned int device_id;
838
839 - vf = (req_id & 0x7F) >> 1;
840 + vf = FIELD_GET(0x7F, req_id);
841 e_dev_err("VF %d has caused a PCIe error\n", vf);
842 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
843 "%8.8x\tdw3: %8.8x\n",
844 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
845 index 930dc50719364..f28140a05f091 100644
846 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
847 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
848 @@ -276,9 +276,8 @@ s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
849 return 0;
850
851 if (hw->phy.nw_mng_if_sel) {
852 - phy_addr = (hw->phy.nw_mng_if_sel &
853 - IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD) >>
854 - IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT;
855 + phy_addr = FIELD_GET(IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD,
856 + hw->phy.nw_mng_if_sel);
857 if (ixgbe_probe_phy(hw, phy_addr))
858 return 0;
859 else
860 @@ -1447,8 +1446,7 @@ s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
861 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
862 if (ret_val)
863 goto err_eeprom;
864 - control = (eword & IXGBE_CONTROL_MASK_NL) >>
865 - IXGBE_CONTROL_SHIFT_NL;
866 + control = FIELD_GET(IXGBE_CONTROL_MASK_NL, eword);
867 edata = eword & IXGBE_DATA_MASK_NL;
868 switch (control) {
869 case IXGBE_DELAY_NL:
870 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
871 index 198ab9d97618c..d0a6c220a12ac 100644
872 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
873 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
874 @@ -363,8 +363,7 @@ int ixgbe_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
875 static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter,
876 u32 *msgbuf, u32 vf)
877 {
878 - int entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
879 - >> IXGBE_VT_MSGINFO_SHIFT;
880 + int entries = FIELD_GET(IXGBE_VT_MSGINFO_MASK, msgbuf[0]);
881 u16 *hash_list = (u16 *)&msgbuf[1];
882 struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
883 struct ixgbe_hw *hw = &adapter->hw;
884 @@ -971,7 +970,7 @@ static int ixgbe_set_vf_mac_addr(struct ixgbe_adapter *adapter,
885 static int ixgbe_set_vf_vlan_msg(struct ixgbe_adapter *adapter,
886 u32 *msgbuf, u32 vf)
887 {
888 - u32 add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> IXGBE_VT_MSGINFO_SHIFT;
889 + u32 add = FIELD_GET(IXGBE_VT_MSGINFO_MASK, msgbuf[0]);
890 u32 vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK);
891 u8 tcs = adapter->hw_tcs;
892
893 @@ -994,8 +993,7 @@ static int ixgbe_set_vf_macvlan_msg(struct ixgbe_adapter *adapter,
894 u32 *msgbuf, u32 vf)
895 {
896 u8 *new_mac = ((u8 *)(&msgbuf[1]));
897 - int index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >>
898 - IXGBE_VT_MSGINFO_SHIFT;
899 + int index = FIELD_GET(IXGBE_VT_MSGINFO_MASK, msgbuf[0]);
900 int err;
901
902 if (adapter->vfinfo[vf].pf_set_mac && !adapter->vfinfo[vf].trusted &&
903 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_x540.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_x540.c
904 index 15325c549d9b5..57a912e4653fc 100644
905 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_x540.c
906 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_x540.c
907 @@ -187,16 +187,16 @@ s32 ixgbe_start_hw_X540(struct ixgbe_hw *hw)
908 s32 ixgbe_init_eeprom_params_X540(struct ixgbe_hw *hw)
909 {
910 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
911 - u32 eec;
912 - u16 eeprom_size;
913
914 if (eeprom->type == ixgbe_eeprom_uninitialized) {
915 + u16 eeprom_size;
916 + u32 eec;
917 +
918 eeprom->semaphore_delay = 10;
919 eeprom->type = ixgbe_flash;
920
921 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
922 - eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
923 - IXGBE_EEC_SIZE_SHIFT);
924 + eeprom_size = FIELD_GET(IXGBE_EEC_SIZE, eec);
925 eeprom->word_size = BIT(eeprom_size +
926 IXGBE_EEPROM_WORD_SIZE_SHIFT);
927
928 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c
929 index cdc912bba8089..c1adc94a5a657 100644
930 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c
931 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c
932 @@ -630,16 +630,16 @@ static s32 ixgbe_fc_autoneg_fw(struct ixgbe_hw *hw)
933 static s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw)
934 {
935 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
936 - u32 eec;
937 - u16 eeprom_size;
938
939 if (eeprom->type == ixgbe_eeprom_uninitialized) {
940 + u16 eeprom_size;
941 + u32 eec;
942 +
943 eeprom->semaphore_delay = 10;
944 eeprom->type = ixgbe_flash;
945
946 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
947 - eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
948 - IXGBE_EEC_SIZE_SHIFT);
949 + eeprom_size = FIELD_GET(IXGBE_EEC_SIZE, eec);
950 eeprom->word_size = BIT(eeprom_size +
951 IXGBE_EEPROM_WORD_SIZE_SHIFT);
952
953 @@ -714,8 +714,7 @@ static s32 ixgbe_read_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
954 ret = ixgbe_iosf_wait(hw, &command);
955
956 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
957 - error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
958 - IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
959 + error = FIELD_GET(IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK, command);
960 hw_dbg(hw, "Failed to read, error %x\n", error);
961 ret = -EIO;
962 goto out;
963 @@ -1415,8 +1414,7 @@ static s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
964 ret = ixgbe_iosf_wait(hw, &command);
965
966 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
967 - error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
968 - IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
969 + error = FIELD_GET(IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK, command);
970 hw_dbg(hw, "Failed to write, error %x\n", error);
971 return -EIO;
972 }
973 @@ -3229,9 +3227,8 @@ static void ixgbe_read_mng_if_sel_x550em(struct ixgbe_hw *hw)
974 */
975 if (hw->mac.type == ixgbe_mac_x550em_a &&
976 hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_MDIO_ACT) {
977 - hw->phy.mdio.prtad = (hw->phy.nw_mng_if_sel &
978 - IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD) >>
979 - IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT;
980 + hw->phy.mdio.prtad = FIELD_GET(IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD,
981 + hw->phy.nw_mng_if_sel);
982 }
983 }
984
985 --
986 2.43.0
987