Skip to content

Commit 65db56d

Browse files
jbrandebanguy11
authored andcommitted
iavf: field get conversion
Refactor the iavf driver to use FIELD_GET() for mask and shift reads, which reduces lines of code and adds clarity of intent. This code was generated by the following coccinelle/spatch script and then manually repaired in a later patch. @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]> Reviewed-by: Marcin Szycik <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Jesse Brandeburg <[email protected]> Tested-by: Rafal Romanowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 6258980 commit 65db56d

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

drivers/net/ethernet/intel/iavf/iavf_ethtool.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,7 @@ iavf_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
10171017
#define IAVF_USERDEF_FLEX_MAX_OFFS_VAL 504
10181018
flex = &fltr->flex_words[cnt++];
10191019
flex->word = value & IAVF_USERDEF_FLEX_WORD_M;
1020-
flex->offset = (value & IAVF_USERDEF_FLEX_OFFS_M) >>
1021-
IAVF_USERDEF_FLEX_OFFS_S;
1020+
flex->offset = FIELD_GET(IAVF_USERDEF_FLEX_OFFS_M, value);
10221021
if (flex->offset > IAVF_USERDEF_FLEX_MAX_OFFS_VAL)
10231022
return -EINVAL;
10241023
}

drivers/net/ethernet/intel/iavf/iavf_txrx.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,9 @@ static void iavf_rx_checksum(struct iavf_vsi *vsi,
989989
u64 qword;
990990

991991
qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len);
992-
ptype = (qword & IAVF_RXD_QW1_PTYPE_MASK) >> IAVF_RXD_QW1_PTYPE_SHIFT;
993-
rx_error = (qword & IAVF_RXD_QW1_ERROR_MASK) >>
994-
IAVF_RXD_QW1_ERROR_SHIFT;
995-
rx_status = (qword & IAVF_RXD_QW1_STATUS_MASK) >>
996-
IAVF_RXD_QW1_STATUS_SHIFT;
992+
ptype = FIELD_GET(IAVF_RXD_QW1_PTYPE_MASK, qword);
993+
rx_error = FIELD_GET(IAVF_RXD_QW1_ERROR_MASK, qword);
994+
rx_status = FIELD_GET(IAVF_RXD_QW1_STATUS_MASK, qword);
997995
decoded = decode_rx_desc_ptype(ptype);
998996

999997
skb->ip_summed = CHECKSUM_NONE;
@@ -1534,8 +1532,7 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)
15341532
if (!iavf_test_staterr(rx_desc, IAVF_RXD_DD))
15351533
break;
15361534

1537-
size = (qword & IAVF_RXD_QW1_LENGTH_PBUF_MASK) >>
1538-
IAVF_RXD_QW1_LENGTH_PBUF_SHIFT;
1535+
size = FIELD_GET(IAVF_RXD_QW1_LENGTH_PBUF_MASK, qword);
15391536

15401537
iavf_trace(clean_rx_irq, rx_ring, rx_desc, skb);
15411538
rx_buffer = iavf_get_rx_buffer(rx_ring, size);
@@ -1582,8 +1579,7 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)
15821579
total_rx_bytes += skb->len;
15831580

15841581
qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len);
1585-
rx_ptype = (qword & IAVF_RXD_QW1_PTYPE_MASK) >>
1586-
IAVF_RXD_QW1_PTYPE_SHIFT;
1582+
rx_ptype = FIELD_GET(IAVF_RXD_QW1_PTYPE_MASK, qword);
15871583

15881584
/* populate checksum, VLAN, and protocol */
15891585
iavf_process_skb_fields(rx_ring, rx_desc, skb, rx_ptype);
@@ -2291,8 +2287,7 @@ static void iavf_tx_map(struct iavf_ring *tx_ring, struct sk_buff *skb,
22912287

22922288
if (tx_flags & IAVF_TX_FLAGS_HW_VLAN) {
22932289
td_cmd |= IAVF_TX_DESC_CMD_IL2TAG1;
2294-
td_tag = (tx_flags & IAVF_TX_FLAGS_VLAN_MASK) >>
2295-
IAVF_TX_FLAGS_VLAN_SHIFT;
2290+
td_tag = FIELD_GET(IAVF_TX_FLAGS_VLAN_MASK, tx_flags);
22962291
}
22972292

22982293
first->tx_flags = tx_flags;
@@ -2468,8 +2463,7 @@ static netdev_tx_t iavf_xmit_frame_ring(struct sk_buff *skb,
24682463
if (tx_flags & IAVF_TX_FLAGS_HW_OUTER_SINGLE_VLAN) {
24692464
cd_type_cmd_tso_mss |= IAVF_TX_CTX_DESC_IL2TAG2 <<
24702465
IAVF_TXD_CTX_QW1_CMD_SHIFT;
2471-
cd_l2tag2 = (tx_flags & IAVF_TX_FLAGS_VLAN_MASK) >>
2472-
IAVF_TX_FLAGS_VLAN_SHIFT;
2466+
cd_l2tag2 = FIELD_GET(IAVF_TX_FLAGS_VLAN_MASK, tx_flags);
24732467
}
24742468

24752469
/* obtain protocol of skb */

0 commit comments

Comments
 (0)