brcmfmac: Move common BCDC code in single function.
authorHante Meuleman <meuleman@broadcom.com>
Thu, 12 Dec 2013 10:59:00 +0000 (11:59 +0100)
committerJohn W. Linville <linville@tuxdriver.com>
Wed, 18 Dec 2013 20:22:50 +0000 (15:22 -0500)
The BCDC functions query_dcmd and set_dcmd both create a msgbuf to
be sent to dongle this code is very similar and for optimisation
best put in a function.

Reviewed-by: Arend Van Spriel <arend@broadcom.com>
Reviewed-by: Franky (Zhenhui) Lin <frankyl@broadcom.com>
Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
Signed-off-by: Hante Meuleman <meuleman@broadcom.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/brcm80211/brcmfmac/bcdc.c

index 06848e426f9adf408f4795e09f28a7d2a31946ea..ee861427117ee34066cf22978e15f15fd57285ce 100644 (file)
@@ -101,35 +101,41 @@ struct brcmf_proto_bcdc_header {
                                         * plus any space that might be needed
                                         * for bus alignment padding.
                                         */
-#define ROUND_UP_MARGIN        2048    /* Biggest bus block size possible for
-                                * round off at the end of buffer
-                                * Currently is SDIO
-                                */
-
 struct brcmf_bcdc {
        u16 reqid;
        u8 bus_header[BUS_HEADER_LEN];
        struct brcmf_proto_bcdc_dcmd msg;
-       unsigned char buf[BRCMF_DCMD_MAXLEN + ROUND_UP_MARGIN];
+       unsigned char buf[BRCMF_DCMD_MAXLEN];
 };
 
-static int brcmf_proto_bcdc_msg(struct brcmf_pub *drvr)
+
+static int
+brcmf_proto_bcdc_msg(struct brcmf_pub *drvr, int ifidx, uint cmd, void *buf,
+                    uint len, bool set)
 {
        struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd;
-       int len = le32_to_cpu(bcdc->msg.len) +
-                       sizeof(struct brcmf_proto_bcdc_dcmd);
+       struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg;
+       u32 flags;
 
        brcmf_dbg(BCDC, "Enter\n");
 
-       /* NOTE : bcdc->msg.len holds the desired length of the buffer to be
-        *        returned. Only up to BCDC_MAX_MSG_SIZE of this buffer area
-        *        is actually sent to the dongle
-        */
-       if (len > BCDC_MAX_MSG_SIZE)
-               len = BCDC_MAX_MSG_SIZE;
+       memset(msg, 0, sizeof(struct brcmf_proto_bcdc_dcmd));
+
+       msg->cmd = cpu_to_le32(cmd);
+       msg->len = cpu_to_le32(len);
+       flags = (++bcdc->reqid << BCDC_DCMD_ID_SHIFT);
+       if (set)
+               flags |= BCDC_DCMD_SET;
+       flags = (flags & ~BCDC_DCMD_IF_MASK) |
+               (ifidx << BCDC_DCMD_IF_SHIFT);
+       msg->flags = cpu_to_le32(flags);
+
+       if (buf)
+               memcpy(bcdc->buf, buf, len);
 
        /* Send request */
-       return brcmf_bus_txctl(drvr->bus_if, (unsigned char *)&bcdc->msg, len);
+       return brcmf_bus_txctl(drvr->bus_if, (unsigned char *)&bcdc->msg,
+                              len + sizeof(struct brcmf_proto_bcdc_dcmd));
 }
 
 static int brcmf_proto_bcdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len)
@@ -161,19 +167,7 @@ brcmf_proto_bcdc_query_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd,
 
        brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len);
 
-       memset(msg, 0, sizeof(struct brcmf_proto_bcdc_dcmd));
-
-       msg->cmd = cpu_to_le32(cmd);
-       msg->len = cpu_to_le32(len);
-       flags = (++bcdc->reqid << BCDC_DCMD_ID_SHIFT);
-       flags = (flags & ~BCDC_DCMD_IF_MASK) |
-               (ifidx << BCDC_DCMD_IF_SHIFT);
-       msg->flags = cpu_to_le32(flags);
-
-       if (buf)
-               memcpy(bcdc->buf, buf, len);
-
-       ret = brcmf_proto_bcdc_msg(drvr);
+       ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, false);
        if (ret < 0) {
                brcmf_err("brcmf_proto_bcdc_msg failed w/status %d\n",
                          ret);
@@ -227,19 +221,7 @@ brcmf_proto_bcdc_set_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd,
 
        brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len);
 
-       memset(msg, 0, sizeof(struct brcmf_proto_bcdc_dcmd));
-
-       msg->cmd = cpu_to_le32(cmd);
-       msg->len = cpu_to_le32(len);
-       flags = (++bcdc->reqid << BCDC_DCMD_ID_SHIFT) | BCDC_DCMD_SET;
-       flags = (flags & ~BCDC_DCMD_IF_MASK) |
-               (ifidx << BCDC_DCMD_IF_SHIFT);
-       msg->flags = cpu_to_le32(flags);
-
-       if (buf)
-               memcpy(bcdc->buf, buf, len);
-
-       ret = brcmf_proto_bcdc_msg(drvr);
+       ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, true);
        if (ret < 0)
                goto done;
 
@@ -369,7 +351,7 @@ int brcmf_proto_bcdc_attach(struct brcmf_pub *drvr)
 
        drvr->hdrlen += BCDC_HEADER_LEN + BRCMF_PROT_FW_SIGNAL_MAX_TXBYTES;
        drvr->bus_if->maxctl = BRCMF_DCMD_MAXLEN +
-                       sizeof(struct brcmf_proto_bcdc_dcmd) + ROUND_UP_MARGIN;
+                       sizeof(struct brcmf_proto_bcdc_dcmd);
        return 0;
 
 fail: