Skip to content

Commit 4d893c1

Browse files
jbrandebanguy11
authored andcommitted
intel: legacy: field prep conversion
Refactor several older Intel drivers to use FIELD_PREP(), which reduces lines of code and adds clarity of intent. This code was generated by the following coccinelle/spatch script and then manually repaired. @prep2@ constant shift,mask; type T; expression a; @@ -(((T)(a) << shift) & mask) +FIELD_PREP(mask, a) @prep@ constant shift,mask; type T; expression a; @@ -((T)((a) << shift) & mask) +FIELD_PREP(mask, a) Cc: Julia Lawall <Julia.Lawall@inria.fr> Reviewed-by: Marcin Szycik <marcin.szycik@linux.intel.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com> Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent 3314f20 commit 4d893c1

8 files changed

Lines changed: 16 additions & 23 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,8 @@ static s32 e1000_read_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
12101210
if (ret_val)
12111211
return ret_val;
12121212

1213-
kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
1214-
E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
1213+
kmrnctrlsta = FIELD_PREP(E1000_KMRNCTRLSTA_OFFSET, offset) |
1214+
E1000_KMRNCTRLSTA_REN;
12151215
ew32(KMRNCTRLSTA, kmrnctrlsta);
12161216
e1e_flush();
12171217

@@ -1245,8 +1245,7 @@ static s32 e1000_write_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
12451245
if (ret_val)
12461246
return ret_val;
12471247

1248-
kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
1249-
E1000_KMRNCTRLSTA_OFFSET) | data;
1248+
kmrnctrlsta = FIELD_PREP(E1000_KMRNCTRLSTA_OFFSET, offset) | data;
12501249
ew32(KMRNCTRLSTA, kmrnctrlsta);
12511250
e1e_flush();
12521251

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
463463
return ret_val;
464464
}
465465

466-
kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
467-
E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
466+
kmrnctrlsta = FIELD_PREP(E1000_KMRNCTRLSTA_OFFSET, offset) |
467+
E1000_KMRNCTRLSTA_REN;
468468
ew32(KMRNCTRLSTA, kmrnctrlsta);
469469
e1e_flush();
470470

@@ -536,8 +536,7 @@ static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
536536
return ret_val;
537537
}
538538

539-
kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
540-
E1000_KMRNCTRLSTA_OFFSET) | data;
539+
kmrnctrlsta = FIELD_PREP(E1000_KMRNCTRLSTA_OFFSET, offset) | data;
541540
ew32(KMRNCTRLSTA, kmrnctrlsta);
542541
e1e_flush();
543542

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,7 @@ static s32 fm10k_iov_assign_default_mac_vlan_pf(struct fm10k_hw *hw,
866866
* register is RO from the VF, so the PF must do this even in the
867867
* case of notifying the VF of a new VID via the mailbox.
868868
*/
869-
txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) &
870-
FM10K_TXQCTL_VID_MASK;
869+
txqctl = FIELD_PREP(FM10K_TXQCTL_VID_MASK, vf_vid);
871870
txqctl |= (vf_idx << FM10K_TXQCTL_TC_SHIFT) |
872871
FM10K_TXQCTL_VF | vf_idx;
873872

drivers/net/ethernet/intel/igb/e1000_phy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
255255
}
256256

257257
/* Need to byte-swap the 16-bit value. */
258-
*data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
258+
*data = ((i2ccmd >> 8) & 0x00FF) | FIELD_PREP(0xFF00, i2ccmd);
259259

260260
return 0;
261261
}
@@ -282,7 +282,7 @@ s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
282282
}
283283

284284
/* Swap the data bytes for the I2C interface */
285-
phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
285+
phy_data_swapped = ((data >> 8) & 0x00FF) | FIELD_PREP(0xFF00, data);
286286

287287
/* Set up Op-code, Phy Address, and register address in the I2CCMD
288288
* register. The MAC will take care of interfacing with the

drivers/net/ethernet/intel/igb/igb_ethtool.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,8 +2711,7 @@ static int igb_rxnfc_write_etype_filter(struct igb_adapter *adapter,
27112711
etqf |= (etype & E1000_ETQF_ETYPE_MASK);
27122712

27132713
etqf &= ~E1000_ETQF_QUEUE_MASK;
2714-
etqf |= ((input->action << E1000_ETQF_QUEUE_SHIFT)
2715-
& E1000_ETQF_QUEUE_MASK);
2714+
etqf |= FIELD_PREP(E1000_ETQF_QUEUE_MASK, input->action);
27162715
etqf |= E1000_ETQF_QUEUE_ENABLE;
27172716

27182717
wr32(E1000_ETQF(i), etqf);

drivers/net/ethernet/intel/igb/igb_main.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9810,8 +9810,7 @@ static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
98109810
tx_rate;
98119811

98129812
bcnrc_val = E1000_RTTBCNRC_RS_ENA;
9813-
bcnrc_val |= ((rf_int << E1000_RTTBCNRC_RF_INT_SHIFT) &
9814-
E1000_RTTBCNRC_RF_INT_MASK);
9813+
bcnrc_val |= FIELD_PREP(E1000_RTTBCNRC_RF_INT_MASK, rf_int);
98159814
bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
98169815
} else {
98179816
bcnrc_val = 0;
@@ -10000,8 +9999,7 @@ static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
100009999
hwm = 64 * (pba - 6);
1000110000
reg = rd32(E1000_FCRTC);
1000210001
reg &= ~E1000_FCRTC_RTH_COAL_MASK;
10003-
reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
10004-
& E1000_FCRTC_RTH_COAL_MASK);
10002+
reg |= FIELD_PREP(E1000_FCRTC_RTH_COAL_MASK, hwm);
1000510003
wr32(E1000_FCRTC, reg);
1000610004

1000710005
/* Set the DMA Coalescing Rx threshold to PBA - 2 * max
@@ -10010,8 +10008,7 @@ static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
1001010008
dmac_thr = pba - 10;
1001110009
reg = rd32(E1000_DMACR);
1001210010
reg &= ~E1000_DMACR_DMACTHR_MASK;
10013-
reg |= ((dmac_thr << E1000_DMACR_DMACTHR_SHIFT)
10014-
& E1000_DMACR_DMACTHR_MASK);
10011+
reg |= FIELD_PREP(E1000_DMACR_DMACTHR_MASK, dmac_thr);
1001510012

1001610013
/* transition to L0x or L1 if available..*/
1001710014
reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);

drivers/net/ethernet/intel/ixgbe/ixgbe_82598.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ static s32 ixgbe_set_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
794794

795795
rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
796796
rar_high &= ~IXGBE_RAH_VIND_MASK;
797-
rar_high |= ((vmdq << IXGBE_RAH_VIND_SHIFT) & IXGBE_RAH_VIND_MASK);
797+
rar_high |= FIELD_PREP(IXGBE_RAH_VIND_MASK, vmdq);
798798
IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
799799
return 0;
800800
}

drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,8 @@ void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter)
670670
int fcoe_i_h = fcoe->offset + ((i + fcreta_size) %
671671
fcoe->indices);
672672
fcoe_q_h = adapter->rx_ring[fcoe_i_h]->reg_idx;
673-
fcoe_q_h = (fcoe_q_h << IXGBE_FCRETA_ENTRY_HIGH_SHIFT) &
674-
IXGBE_FCRETA_ENTRY_HIGH_MASK;
673+
fcoe_q_h = FIELD_PREP(IXGBE_FCRETA_ENTRY_HIGH_MASK,
674+
fcoe_q_h);
675675
}
676676

677677
fcoe_i = fcoe->offset + (i % fcoe->indices);

0 commit comments

Comments
 (0)