Skip to contentSkip to conversation

i40e: Fix endianness conversions

PATCH Superseded Mateusz Palczewski 2 participants 2 messages Jan 29, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i40e: Fix endianness conversions

From: Norbert Ciosek <[email protected]>

Fixes the following sparse warnings:
i40e_main.c:5953:32: warning: cast from restricted __le16 i40e_main.c:8008:29: warning: incorrect type in assignment (different base types)
i40e_main.c:8008:29: expected unsigned int [assigned] [usertype] ipa
i40e_main.c:8008:29: got restricted __le32 [usertype]
i40e_main.c:8008:29: warning: incorrect type in assignment (different base types)
i40e_main.c:8008:29: expected unsigned int [assigned] [usertype] ipa
i40e_main.c:8008:29: got restricted __le32 [usertype]
i40e_txrx.c:1950:59: warning: incorrect type in initializer (different base types)
i40e_txrx.c:1950:59: expected unsigned short [usertype] vlan_tag
i40e_txrx.c:1950:59: got restricted __le16 [usertype] l2tag1
i40e_txrx.c:1953:40: warning: cast to restricted __le16 i40e_xsk.c:448:38: warning: invalid assignment: |=
i40e_xsk.c:448:38: left side has type restricted __le64
i40e_xsk.c:448:38: right side has type int

Fixes 2f4b411a3d67 ("i40e: Enable cloud filters via tc-flower")
Fixes 2a508c64ad27 ("i40e: fix VLAN.TCI == 0 RX HW offload")
Fixes 3106c580fb7c ("i40e: Use batched xsk Tx interfaces to increase performance")
Fixes 8f88b3034db3 ("i40e: Add infrastructure for queue channel support")
---
 drivers/net/ethernet/intel/i40e/i40e_main.c | 18 +++++++++---------
 drivers/net/ethernet/intel/i40e/i40e_txrx.c |  2 +-
 drivers/net/ethernet/intel/i40e/i40e_xsk.c  |  2 +-
 3 files changed, 11 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +9 -9
index 3ed7f0e..8f635ac 100644
@@ -5950,7 +5950,7 @@ static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid,
 	ch->enabled_tc = !i40e_is_channel_macvlan(ch) && enabled_tc;
 	ch->seid = ctxt.seid;
 	ch->vsi_number = ctxt.vsi_number;
-	ch->stat_counter_idx = cpu_to_le16(ctxt.info.stat_counter_idx);
+	ch->stat_counter_idx = le16_to_cpu(ctxt.info.stat_counter_idx);
 
 	/* copy just the sections touched not the entire info
 	 * since not all sections are valid as returned by
@@ -7990,8 +7990,7 @@ static inline void
 i40e_set_cld_element(struct i40e_cloud_filter *filter,
 		     struct i40e_aqc_cloud_filters_element_data *cld)
 {
-	int i, j;
-	u32 ipa;
+	int i;
 
 	memset(cld, 0, sizeof(*cld));
 	ether_addr_copy(cld->outer_mac, filter->dst_mac);
@@ -8002,14 +8001,15 @@ i40e_set_cld_element(struct i40e_cloud_filter *filter,
 
 	if (filter->n_proto == ETH_P_IPV6) {
 #define IPV6_MAX_INDEX	(ARRAY_SIZE(filter->dst_ipv6) - 1)
-		for (i = 0, j = 0; i < ARRAY_SIZE(filter->dst_ipv6);
-		     i++, j += 2) {
-			ipa = be32_to_cpu(filter->dst_ipv6[IPV6_MAX_INDEX - i]);
-			ipa = cpu_to_le32(ipa);
-			memcpy(&cld->ipaddr.raw_v6.data[j], &ipa, sizeof(ipa));
+		for (i = 0; i < ARRAY_SIZE(filter->dst_ipv6); i++) {
+			__le32 ipa = cpu_to_le32(be32_to_cpu
+				(filter->dst_ipv6[IPV6_MAX_INDEX - i]));
+
+			memcpy(&cld->ipaddr.raw_v6.data[i * 2], &ipa, sizeof(ipa));
 		}
 	} else {
-		ipa = be32_to_cpu(filter->dst_ipv4);
+		u32 ipa = be32_to_cpu(filter->dst_ipv4);
+
 		memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
 	}
 
drivers/net/ethernet/intel/i40e/i40e_txrx.c +1 -1
index 15feecd..c7759cb 100644
@@ -1948,7 +1948,7 @@ void i40e_process_skb_fields(struct i40e_ring *rx_ring,
 	skb_record_rx_queue(skb, rx_ring->queue_index);
 
 	if (qword & BIT(I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) {
-		u16 vlan_tag = rx_desc->wb.qword0.lo_dword.l2tag1;
+		__le16 vlan_tag = rx_desc->wb.qword0.lo_dword.l2tag1;
 
 		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
 				       le16_to_cpu(vlan_tag));
drivers/net/ethernet/intel/i40e/i40e_xsk.c +1 -1
index b42300b..df1ec8c 100644
@@ -457,7 +457,7 @@ static void i40e_set_rs_bit(struct i40e_ring *xdp_ring)
 	struct i40e_tx_desc *tx_desc;
 
 	tx_desc = I40E_TX_DESC(xdp_ring, ntu);
-	tx_desc->cmd_type_offset_bsz |= (I40E_TX_DESC_CMD_RS << I40E_TXD_QW1_CMD_SHIFT);
+	tx_desc->cmd_type_offset_bsz |= cpu_to_le64(I40E_TX_DESC_CMD_RS << I40E_TXD_QW1_CMD_SHIFT);
 }
 
 /**
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 i40e: Fix endianness conversions

Quoted 57 lines · Mateusz Palczewski

From: Norbert Ciosek <[email protected]>

Fixes the following sparse warnings:
i40e_main.c:5953:32: warning: cast from restricted __le16 i40e_main.c:8008:29: warning: incorrect type in assignment (different base types)
i40e_main.c:8008:29: expected unsigned int [assigned] [usertype] ipa
i40e_main.c:8008:29: got restricted __le32 [usertype]
i40e_main.c:8008:29: warning: incorrect type in assignment (different base types)
i40e_main.c:8008:29: expected unsigned int [assigned] [usertype] ipa
i40e_main.c:8008:29: got restricted __le32 [usertype]
i40e_txrx.c:1950:59: warning: incorrect type in initializer (different base types)
i40e_txrx.c:1950:59: expected unsigned short [usertype] vlan_tag
i40e_txrx.c:1950:59: got restricted __le16 [usertype] l2tag1
i40e_txrx.c:1953:40: warning: cast to restricted __le16 i40e_xsk.c:448:38: warning: invalid assignment: |=
i40e_xsk.c:448:38: left side has type restricted __le64
i40e_xsk.c:448:38: right side has type int

Fixes 2f4b411a3d67 ("i40e: Enable cloud filters via tc-flower")
Fixes 2a508c64ad27 ("i40e: fix VLAN.TCI == 0 RX HW offload")
Fixes 3106c580fb7c ("i40e: Use batched xsk Tx interfaces to increase performance")
Fixes 8f88b3034db3 ("i40e: Add infrastructure for queue channel support")
---
 drivers/net/ethernet/intel/i40e/i40e_main.c | 18 +++++++++---------
 drivers/net/ethernet/intel/i40e/i40e_txrx.c |  2 +-
 drivers/net/ethernet/intel/i40e/i40e_xsk.c  |  2 +-
 3 files changed, 11 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +2 -3
index 3ed7f0e..8f635ac 100644
@@ -5950,7 +5950,7 @@ static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid,
        ch->enabled_tc = !i40e_is_channel_macvlan(ch) && enabled_tc;
        ch->seid = ctxt.seid;
        ch->vsi_number = ctxt.vsi_number;
-       ch->stat_counter_idx = cpu_to_le16(ctxt.info.stat_counter_idx);
+       ch->stat_counter_idx = le16_to_cpu(ctxt.info.stat_counter_idx);
 
        /* copy just the sections touched not the entire info
         * since not all sections are valid as returned by
@@ -7990,8 +7990,7 @@ static inline void
 i40e_set_cld_element(struct i40e_cloud_filter *filter,
                     struct i40e_aqc_cloud_filters_element_data *cld)
 {
-       int i, j;
-       u32 ipa;
+       int i;
 
        memset(cld, 0, sizeof(*cld));
        ether_addr_copy(cld->outer_mac, filter->dst_mac);
@@ -8002,14 +8001,15 @@ i40e_set_cld_element(struct i40e_cloud_filter *filter,
 
        if (filter->n_proto == ETH_P_IPV6) {
 #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)

drivers/net/ethernet/intel/i40e/i40e_main.c i40e_set_cld_element(struct i40e_cloud_filter *filter, · line 8008

Quoted 10 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +5 -5
-               for (i = 0, j = 0; i < ARRAY_SIZE(filter->dst_ipv6);
-                    i++, j += 2) {
-                       ipa = be32_to_cpu(filter->dst_ipv6[IPV6_MAX_INDEX - i]);
-                       ipa = cpu_to_le32(ipa);
-                       memcpy(&cld->ipaddr.raw_v6.data[j], &ipa, sizeof(ipa));
+               for (i = 0; i < ARRAY_SIZE(filter->dst_ipv6); i++) {
+                       __le32 ipa = cpu_to_le32(be32_to_cpu
+                               (filter->dst_ipv6[IPV6_MAX_INDEX - i]));
+
+                       memcpy(&cld->ipaddr.raw_v6.data[i * 2], &ipa, sizeof(ipa));

I would argue the code you had before was more readable than what this is now.

Instead of changing things this way it might be better to instead do just drop the last two lines and do something like:

    *(__le32 *)&cld->ipaddr.raw_v6.data[i * 2] = cpu_to_le32(ipa);

Also from what I can tell it looks like the raw_v6 field is only used here so you could drop the need to cast this if you were to change the type for data from an __le16 to an __le32 and just drop the array length by half.

Quoted 41 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +2 -1
                }
        } else {
-               ipa = be32_to_cpu(filter->dst_ipv4);
+               u32 ipa = be32_to_cpu(filter->dst_ipv4);
+
                memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
        }
 
drivers/net/ethernet/intel/i40e/i40e_txrx.c +1 -1
index 15feecd..c7759cb 100644
@@ -1948,7 +1948,7 @@ void i40e_process_skb_fields(struct i40e_ring *rx_ring,
        skb_record_rx_queue(skb, rx_ring->queue_index);
 
        if (qword & BIT(I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) {
-               u16 vlan_tag = rx_desc->wb.qword0.lo_dword.l2tag1;
+               __le16 vlan_tag = rx_desc->wb.qword0.lo_dword.l2tag1;
 
                __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
                                       le16_to_cpu(vlan_tag));
drivers/net/ethernet/intel/i40e/i40e_xsk.c +1 -2
index b42300b..df1ec8c 100644
@@ -457,7 +457,7 @@ static void i40e_set_rs_bit(struct i40e_ring *xdp_ring)
        struct i40e_tx_desc *tx_desc;
 
        tx_desc = I40E_TX_DESC(xdp_ring, ntu);
-       tx_desc->cmd_type_offset_bsz |= (I40E_TX_DESC_CMD_RS << I40E_TXD_QW1_CMD_SHIFT);
+       tx_desc->cmd_type_offset_bsz |= cpu_to_le64(I40E_TX_DESC_CMD_RS << I40E_TXD_QW1_CMD_SHIFT);
 }
 
 /**
--

2.17.1

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan