Skip to content

Commit 6aa7ca3

Browse files
jbrandebanguy11
authored andcommitted
idpf: refactor some missing field get/prep conversions
Most of idpf correctly uses FIELD_GET and FIELD_PREP, but a couple spots were missed so fix those. Automated conversion with coccinelle script and manually fixed up, including audits for opportunities to convert to {get,encode,replace} bits functions. Add conversions to le16_get/encode/replace_bits where appropriate. And in one place fix up a cast from a u16 to a u16. @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) @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: Alexander Lobakin <[email protected]> Reviewed-by: Przemek Kitszel <[email protected]> Signed-off-by: Jesse Brandeburg <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 316a28d commit 6aa7ca3

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,9 @@ static void idpf_tx_singleq_build_ctx_desc(struct idpf_queue *txq,
328328

329329
if (offload->tso_segs) {
330330
qw1 |= IDPF_TX_CTX_DESC_TSO << IDPF_TXD_CTX_QW1_CMD_S;
331-
qw1 |= ((u64)offload->tso_len << IDPF_TXD_CTX_QW1_TSO_LEN_S) &
332-
IDPF_TXD_CTX_QW1_TSO_LEN_M;
333-
qw1 |= ((u64)offload->mss << IDPF_TXD_CTX_QW1_MSS_S) &
334-
IDPF_TXD_CTX_QW1_MSS_M;
331+
qw1 |= FIELD_PREP(IDPF_TXD_CTX_QW1_TSO_LEN_M,
332+
offload->tso_len);
333+
qw1 |= FIELD_PREP(IDPF_TXD_CTX_QW1_MSS_M, offload->mss);
335334

336335
u64_stats_update_begin(&txq->stats_sync);
337336
u64_stats_inc(&txq->q_stats.tx.lso_pkts);

drivers/net/ethernet/intel/idpf/idpf_txrx.c

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,9 @@ static void idpf_rx_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id)
505505

506506
/* store the buffer ID and the SW maintained GEN bit to the refillq */
507507
refillq->ring[nta] =
508-
((buf_id << IDPF_RX_BI_BUFID_S) & IDPF_RX_BI_BUFID_M) |
509-
(!!(test_bit(__IDPF_Q_GEN_CHK, refillq->flags)) <<
510-
IDPF_RX_BI_GEN_S);
508+
FIELD_PREP(IDPF_RX_BI_BUFID_M, buf_id) |
509+
FIELD_PREP(IDPF_RX_BI_GEN_M,
510+
test_bit(__IDPF_Q_GEN_CHK, refillq->flags));
511511

512512
if (unlikely(++nta == refillq->desc_count)) {
513513
nta = 0;
@@ -1825,14 +1825,14 @@ static bool idpf_tx_clean_complq(struct idpf_queue *complq, int budget,
18251825
u16 gen;
18261826

18271827
/* if the descriptor isn't done, no work yet to do */
1828-
gen = (le16_to_cpu(tx_desc->qid_comptype_gen) &
1829-
IDPF_TXD_COMPLQ_GEN_M) >> IDPF_TXD_COMPLQ_GEN_S;
1828+
gen = le16_get_bits(tx_desc->qid_comptype_gen,
1829+
IDPF_TXD_COMPLQ_GEN_M);
18301830
if (test_bit(__IDPF_Q_GEN_CHK, complq->flags) != gen)
18311831
break;
18321832

18331833
/* Find necessary info of TX queue to clean buffers */
1834-
rel_tx_qid = (le16_to_cpu(tx_desc->qid_comptype_gen) &
1835-
IDPF_TXD_COMPLQ_QID_M) >> IDPF_TXD_COMPLQ_QID_S;
1834+
rel_tx_qid = le16_get_bits(tx_desc->qid_comptype_gen,
1835+
IDPF_TXD_COMPLQ_QID_M);
18361836
if (rel_tx_qid >= complq->txq_grp->num_txq ||
18371837
!complq->txq_grp->txqs[rel_tx_qid]) {
18381838
dev_err(&complq->vport->adapter->pdev->dev,
@@ -1842,9 +1842,8 @@ static bool idpf_tx_clean_complq(struct idpf_queue *complq, int budget,
18421842
tx_q = complq->txq_grp->txqs[rel_tx_qid];
18431843

18441844
/* Determine completion type */
1845-
ctype = (le16_to_cpu(tx_desc->qid_comptype_gen) &
1846-
IDPF_TXD_COMPLQ_COMPL_TYPE_M) >>
1847-
IDPF_TXD_COMPLQ_COMPL_TYPE_S;
1845+
ctype = le16_get_bits(tx_desc->qid_comptype_gen,
1846+
IDPF_TXD_COMPLQ_COMPL_TYPE_M);
18481847
switch (ctype) {
18491848
case IDPF_TXD_COMPLT_RE:
18501849
hw_head = le16_to_cpu(tx_desc->q_head_compl_tag.q_head);
@@ -1945,11 +1944,10 @@ void idpf_tx_splitq_build_ctb(union idpf_tx_flex_desc *desc,
19451944
u16 td_cmd, u16 size)
19461945
{
19471946
desc->q.qw1.cmd_dtype =
1948-
cpu_to_le16(params->dtype & IDPF_FLEX_TXD_QW1_DTYPE_M);
1947+
le16_encode_bits(params->dtype, IDPF_FLEX_TXD_QW1_DTYPE_M);
19491948
desc->q.qw1.cmd_dtype |=
1950-
cpu_to_le16((td_cmd << IDPF_FLEX_TXD_QW1_CMD_S) &
1951-
IDPF_FLEX_TXD_QW1_CMD_M);
1952-
desc->q.qw1.buf_size = cpu_to_le16((u16)size);
1949+
le16_encode_bits(td_cmd, IDPF_FLEX_TXD_QW1_CMD_M);
1950+
desc->q.qw1.buf_size = cpu_to_le16(size);
19531951
desc->q.qw1.l2tags.l2tag1 = cpu_to_le16(params->td_tag);
19541952
}
19551953

@@ -2843,8 +2841,9 @@ static void idpf_rx_splitq_extract_csum_bits(struct virtchnl2_rx_flex_desc_adv_n
28432841
qword1);
28442842
csum->ipv6exadd = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_IPV6EXADD_M,
28452843
qword0);
2846-
csum->raw_csum_inv = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_RAW_CSUM_INV_M,
2847-
le16_to_cpu(rx_desc->ptype_err_fflags0));
2844+
csum->raw_csum_inv =
2845+
le16_get_bits(rx_desc->ptype_err_fflags0,
2846+
VIRTCHNL2_RX_FLEX_DESC_ADV_RAW_CSUM_INV_M);
28482847
csum->raw_csum = le16_to_cpu(rx_desc->misc.raw_cs);
28492848
}
28502849

@@ -2938,8 +2937,8 @@ static int idpf_rx_process_skb_fields(struct idpf_queue *rxq,
29382937
struct idpf_rx_ptype_decoded decoded;
29392938
u16 rx_ptype;
29402939

2941-
rx_ptype = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_PTYPE_M,
2942-
le16_to_cpu(rx_desc->ptype_err_fflags0));
2940+
rx_ptype = le16_get_bits(rx_desc->ptype_err_fflags0,
2941+
VIRTCHNL2_RX_FLEX_DESC_ADV_PTYPE_M);
29432942

29442943
decoded = rxq->vport->rx_ptype_lkup[rx_ptype];
29452944
/* If we don't know the ptype we can't do anything else with it. Just
@@ -2953,8 +2952,8 @@ static int idpf_rx_process_skb_fields(struct idpf_queue *rxq,
29532952

29542953
skb->protocol = eth_type_trans(skb, rxq->vport->netdev);
29552954

2956-
if (FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_RSC_M,
2957-
le16_to_cpu(rx_desc->hdrlen_flags)))
2955+
if (le16_get_bits(rx_desc->hdrlen_flags,
2956+
VIRTCHNL2_RX_FLEX_DESC_ADV_RSC_M))
29582957
return idpf_rx_rsc(rxq, skb, rx_desc, &decoded);
29592958

29602959
idpf_rx_splitq_extract_csum_bits(rx_desc, &csum_bits);
@@ -3148,8 +3147,8 @@ static int idpf_rx_splitq_clean(struct idpf_queue *rxq, int budget)
31483147
dma_rmb();
31493148

31503149
/* if the descriptor isn't done, no work yet to do */
3151-
gen_id = le16_to_cpu(rx_desc->pktlen_gen_bufq_id);
3152-
gen_id = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_M, gen_id);
3150+
gen_id = le16_get_bits(rx_desc->pktlen_gen_bufq_id,
3151+
VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_M);
31533152

31543153
if (test_bit(__IDPF_Q_GEN_CHK, rxq->flags) != gen_id)
31553154
break;
@@ -3164,9 +3163,8 @@ static int idpf_rx_splitq_clean(struct idpf_queue *rxq, int budget)
31643163
continue;
31653164
}
31663165

3167-
pkt_len = le16_to_cpu(rx_desc->pktlen_gen_bufq_id);
3168-
pkt_len = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_PBUF_M,
3169-
pkt_len);
3166+
pkt_len = le16_get_bits(rx_desc->pktlen_gen_bufq_id,
3167+
VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_PBUF_M);
31703168

31713169
hbo = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_HBO_M,
31723170
rx_desc->status_err0_qw1);
@@ -3183,14 +3181,12 @@ static int idpf_rx_splitq_clean(struct idpf_queue *rxq, int budget)
31833181
goto bypass_hsplit;
31843182
}
31853183

3186-
hdr_len = le16_to_cpu(rx_desc->hdrlen_flags);
3187-
hdr_len = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_HDR_M,
3188-
hdr_len);
3184+
hdr_len = le16_get_bits(rx_desc->hdrlen_flags,
3185+
VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_HDR_M);
31893186

31903187
bypass_hsplit:
3191-
bufq_id = le16_to_cpu(rx_desc->pktlen_gen_bufq_id);
3192-
bufq_id = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_M,
3193-
bufq_id);
3188+
bufq_id = le16_get_bits(rx_desc->pktlen_gen_bufq_id,
3189+
VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_M);
31943190

31953191
rxq_set = container_of(rxq, struct idpf_rxq_set, rxq);
31963192
if (!bufq_id)

0 commit comments

Comments
 (0)