]> err.no Git - linux-2.6/commitdiff
libertas: Switch to using a callback function pointer for commands
authorDavid Woodhouse <dwmw2@infradead.org>
Fri, 7 Dec 2007 15:13:05 +0000 (15:13 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Jan 2008 23:06:12 +0000 (15:06 -0800)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/libertas/cmd.c
drivers/net/wireless/libertas/cmdresp.c
drivers/net/wireless/libertas/hostcmd.h

index b1ea878863a821fefd6668a2a516a29ce7b9a8c2..ebfcb7bac68166bec077fa5d4bcdcd30a9893695 100644 (file)
@@ -1659,7 +1659,8 @@ static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
        wake_up_interruptible(&ptempnode->cmdwait_q);
        ptempnode->wait_option = 0;
        ptempnode->pdata_buf = NULL;
-       ptempnode->pdata_size = 0;
+       ptempnode->pdata_size = NULL;
+       ptempnode->callback = NULL;
 
        if (ptempnode->bufvirtualaddr != NULL)
                memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
@@ -1687,7 +1688,8 @@ void lbs_set_cmd_ctrl_node(struct lbs_private *priv,
 
        ptempnode->wait_option = wait_option;
        ptempnode->pdata_buf = pdata_buf;
-       ptempnode->pdata_size = 0;
+       ptempnode->pdata_size = NULL;
+       ptempnode->callback = NULL;
 
        lbs_deb_leave(LBS_DEB_HOST);
 }
@@ -2012,10 +2014,26 @@ void lbs_ps_confirm_sleep(struct lbs_private *priv, u16 psmode)
  *  @return            -1 in case of a higher level error, otherwise
  *                      the result code from the firmware
  */
-int lbs_cmd(struct lbs_private *priv,
-       u16 command,
-       void *cmd, int cmd_size,
-       void *rsp, int *rsp_size)
+
+static int lbs_cmd_callback(uint16_t respcmd, struct cmd_ds_command *resp, struct lbs_private *priv)
+{ 
+       struct cmd_ds_gen *r = (struct cmd_ds_gen *)resp;
+       struct lbs_adapter *adapter = priv->adapter;
+       u16 sz = cpu_to_le16(resp->size) - S_DS_GEN;
+
+       if (sz > *adapter->cur_cmd->pdata_size) {
+               lbs_pr_err("response 0x%04x doesn't fit into buffer (%d > %d)\n",
+                          respcmd, sz, *adapter->cur_cmd->pdata_size);
+               sz = *adapter->cur_cmd->pdata_size;
+       }
+       memcpy(adapter->cur_cmd->pdata_buf, r->cmdresp, sz);
+       *adapter->cur_cmd->pdata_size = sz;
+
+       return 0;
+}
+
+int lbs_cmd(struct lbs_private *priv, u16 command, void *cmd, int cmd_size,
+           void *rsp, int *rsp_size)
 {
        struct lbs_adapter *adapter = priv->adapter;
        struct cmd_ctrl_node *cmdnode;
@@ -2053,6 +2071,7 @@ int lbs_cmd(struct lbs_private *priv,
        cmdnode->wait_option = CMD_OPTION_WAITFORRSP;
        cmdnode->pdata_buf = rsp;
        cmdnode->pdata_size = rsp_size;
+       cmdnode->callback = lbs_cmd_callback;
 
        /* Set sequence number, clean result, move to buffer */
        adapter->seqnum++;
index 22a69736338197be61026a4cc200f216a16f562d..20ca38c7f87076cd93d04a973ffc599ca3e00c0c 100644 (file)
@@ -880,22 +880,15 @@ int lbs_process_rx_command(struct lbs_private *priv)
                goto done;
        }
 
-       if (adapter->cur_cmd->pdata_size) {
-               struct cmd_ds_gen *r = (struct cmd_ds_gen *)resp;
-               u16 sz = cpu_to_le16(resp->size) - S_DS_GEN;
-               if (sz > *adapter->cur_cmd->pdata_size) {
-                       lbs_pr_err("response 0x%04x doesn't fit into "
-                               "buffer (%d > %d)\n", respcmd,
-                               sz, *adapter->cur_cmd->pdata_size);
-                       sz = *adapter->cur_cmd->pdata_size;
-               }
-               memcpy(adapter->cur_cmd->pdata_buf, r->cmdresp, sz);
-               *adapter->cur_cmd->pdata_size = sz;
-       } else {
-               spin_unlock_irqrestore(&adapter->driver_lock, flags);
+       spin_unlock_irqrestore(&adapter->driver_lock, flags);
+
+       if (adapter->cur_cmd && adapter->cur_cmd->callback)
+               ret = adapter->cur_cmd->callback(respcmd, resp, priv);
+       else
                ret = handle_cmd_response(respcmd, resp, priv);
-               spin_lock_irqsave(&adapter->driver_lock, flags);
-       }
+
+       spin_lock_irqsave(&adapter->driver_lock, flags);
+
        if (adapter->cur_cmd) {
                /* Clean up and Put current command back to cmdfreeq */
                __lbs_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
index be69ae6529232309634dc79f6a4a6a38206ff518..5ef65ae0de5ad5f3b11e9ea98b8f7ad7e50806f3 100644 (file)
@@ -72,6 +72,7 @@ struct cmd_ctrl_node {
        /* command response */
        void *pdata_buf;
        int *pdata_size;
+       int (*callback)(uint16_t respcmd, struct cmd_ds_command *resp, struct lbs_private *priv);
        /* command data */
        u8 *bufvirtualaddr;
        /* wait queue */