All of lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-wired-lan] [PATCH net v1] i40e: Fix endianness conversions
@ 2021-01-29 10:15 Mateusz Palczewski
  2021-01-29 21:29 ` Alexander Duyck
  0 siblings, 1 reply; 2+ messages in thread
From: Mateusz Palczewski @ 2021-01-29 10:15 UTC (permalink / raw)
  To: intel-wired-lan

From: Norbert Ciosek <norbertx.ciosek@intel.com>

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")
Signed-off-by: Norbert Ciosek <norbertx.ciosek@intel.com>
---
 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(-)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 3ed7f0e..8f635ac 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -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));
 	}
 
diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
index 15feecd..c7759cb 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
@@ -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));
diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
index b42300b..df1ec8c 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
@@ -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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Intel-wired-lan] [PATCH net v1] i40e: Fix endianness conversions
  2021-01-29 10:15 [Intel-wired-lan] [PATCH net v1] i40e: Fix endianness conversions Mateusz Palczewski
@ 2021-01-29 21:29 ` Alexander Duyck
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Duyck @ 2021-01-29 21:29 UTC (permalink / raw)
  To: intel-wired-lan

On Fri, Jan 29, 2021 at 2:15 AM Mateusz Palczewski
<mateusz.palczewski@intel.com> wrote:
>
> From: Norbert Ciosek <norbertx.ciosek@intel.com>
>
> 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")
> Signed-off-by: Norbert Ciosek <norbertx.ciosek@intel.com>
> ---
>  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(-)
>
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
> index 3ed7f0e..8f635ac 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_main.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
> @@ -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));

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.

>                 }
>         } else {
> -               ipa = be32_to_cpu(filter->dst_ipv4);
> +               u32 ipa = be32_to_cpu(filter->dst_ipv4);
> +
>                 memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
>         }
>
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
> index 15feecd..c7759cb 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
> @@ -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));
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
> index b42300b..df1ec8c 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
> @@ -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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-29 21:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-29 10:15 [Intel-wired-lan] [PATCH net v1] i40e: Fix endianness conversions Mateusz Palczewski
2021-01-29 21:29 ` Alexander Duyck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.