staging: wfx: preserve endianness of struct hif_ind_startup
authorJérôme Pouiller <jerome.pouiller@silabs.com>
Thu, 13 Jan 2022 08:55:04 +0000 (09:55 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 25 Jan 2022 15:19:41 +0000 (16:19 +0100)
The hardware fills struct hif_ind_startup with little endian values. So,
declare it with little endian fields.

It is now a bit more verbose to access to fields of struct
hif_ind_startup, but it is less confusing.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Link: https://lore.kernel.org/r/20220113085524.1110708-12-Jerome.Pouiller@silabs.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/wfx/bh.c
drivers/staging/wfx/data_tx.c
drivers/staging/wfx/hif_api_general.h
drivers/staging/wfx/hif_rx.c

index a0f9d1b530191c4d3a106f84b014c1d6de96da57..bbcf8d6a39c4ca191f7235e1a803498c4a5696ad 100644 (file)
@@ -182,9 +182,9 @@ static void tx_helper(struct wfx_dev *wdev, struct hif_msg *hif)
        wdev->hif.tx_seqnum = (wdev->hif.tx_seqnum + 1) % (HIF_COUNTER_MAX + 1);
 
        data = hif;
-       WARN(len > wdev->hw_caps.size_inp_ch_buf,
-            "%s: request exceed the chip capability: %zu > %d\n", __func__,
-            len, wdev->hw_caps.size_inp_ch_buf);
+       WARN(len > le16_to_cpu(wdev->hw_caps.size_inp_ch_buf),
+            "request exceed the chip capability: %zu > %d\n",
+            len, le16_to_cpu(wdev->hw_caps.size_inp_ch_buf));
        len = wdev->hwbus_ops->align_size(wdev->hwbus_priv, len);
        ret = wfx_data_write(wdev, data, len);
        if (ret)
@@ -204,7 +204,7 @@ static int bh_work_tx(struct wfx_dev *wdev, int max_msg)
 
        for (i = 0; i < max_msg; i++) {
                hif = NULL;
-               if (wdev->hif.tx_buffers_used < wdev->hw_caps.num_inp_ch_bufs) {
+               if (wdev->hif.tx_buffers_used < le16_to_cpu(wdev->hw_caps.num_inp_ch_bufs)) {
                        if (try_wait_for_completion(&wdev->hif_cmd.ready)) {
                                WARN(!mutex_is_locked(&wdev->hif_cmd.lock), "data locking error");
                                hif = wdev->hif_cmd.buf_send;
index 052a19161dc5d1cd9cbd91ee6d3facdead4a4142..5492375fe80ab0c8116ebee5b424faa14124ad58 100644 (file)
@@ -359,10 +359,10 @@ static int wfx_tx_inner(struct wfx_vif *wvif, struct ieee80211_sta *sta,
        hif_msg->len = cpu_to_le16(skb->len);
        hif_msg->id = HIF_REQ_ID_TX;
        hif_msg->interface = wvif->id;
-       if (skb->len > wvif->wdev->hw_caps.size_inp_ch_buf) {
+       if (skb->len > le16_to_cpu(wvif->wdev->hw_caps.size_inp_ch_buf)) {
                dev_warn(wvif->wdev->dev,
                         "requested frame size (%d) is larger than maximum supported (%d)\n",
-                        skb->len, wvif->wdev->hw_caps.size_inp_ch_buf);
+                        skb->len, le16_to_cpu(wvif->wdev->hw_caps.size_inp_ch_buf));
                skb_pull(skb, wmsg_len);
                return -EIO;
        }
index 8244676112a5dad0d074e11a09b77f87cd828ee2..a57789ceb20981c1de830845bdbaf4325d9cf29b 100644 (file)
@@ -108,16 +108,12 @@ enum hif_api_rate_index {
 };
 
 struct hif_ind_startup {
-       /* As the others, this struct is interpreted as little endian by the
-        * device. However, this struct is also used by the driver. We prefer to
-        * declare it in native order and doing byte swap on reception.
-        */
        __le32 status;
-       u16    hardware_id;
+       __le16 hardware_id;
        u8     opn[14];
        u8     uid[8];
-       u16    num_inp_ch_bufs;
-       u16    size_inp_ch_buf;
+       __le16 num_inp_ch_bufs;
+       __le16 size_inp_ch_buf;
        u8     num_links_ap;
        u8     num_interfaces;
        u8     mac_addr[2][ETH_ALEN];
@@ -138,7 +134,7 @@ struct hif_ind_startup {
        u8     phy1_region:3;
        u8     phy0_region:3;
        u8     otp_phy_ver:2;
-       u32    supported_rate_mask;
+       __le32 supported_rate_mask;
        u8     firmware_label[128];
 } __packed;
 
index 5e675d2c3e8245618dc0f0bbe5fb30b55fad5cce..ea6d192ce28c19fbe83b4d23ae4520ef36a2f9db 100644 (file)
@@ -81,11 +81,6 @@ static int hif_startup_indication(struct wfx_dev *wdev,
                return -EINVAL;
        }
        memcpy(&wdev->hw_caps, body, sizeof(struct hif_ind_startup));
-       le16_to_cpus((__le16 *)&wdev->hw_caps.hardware_id);
-       le16_to_cpus((__le16 *)&wdev->hw_caps.num_inp_ch_bufs);
-       le16_to_cpus((__le16 *)&wdev->hw_caps.size_inp_ch_buf);
-       le32_to_cpus((__le32 *)&wdev->hw_caps.supported_rate_mask);
-
        complete(&wdev->firmware_ready);
        return 0;
 }