libertas: convert DATA_RATE to a direct command
authorDan Williams <dcbw@redhat.com>
Tue, 11 Dec 2007 20:50:59 +0000 (15:50 -0500)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Jan 2008 23:06:49 +0000 (15:06 -0800)
Signed-off-by: Dan Williams <dcbw@redhat.com>
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/cmd.h
drivers/net/wireless/libertas/cmdresp.c
drivers/net/wireless/libertas/hostcmd.h
drivers/net/wireless/libertas/main.c
drivers/net/wireless/libertas/wext.c

index 9d621fe7f08afee3a8f3001638d09af0bff6725a..eff78792fc6ff859607c08059bad59441ceb4438 100644 (file)
@@ -706,30 +706,86 @@ static int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
        return 0;
 }
 
-static int lbs_cmd_802_11_data_rate(struct lbs_private *priv,
-                                    struct cmd_ds_command *cmd,
-                                    u16 cmd_action)
+/**
+ *  @brief Get the current data rate
+ *
+ *  @param priv        A pointer to struct lbs_private structure
+ *
+ *  @return            The data rate on success, error on failure
+ */
+int lbs_get_data_rate(struct lbs_private *priv)
 {
-       struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
+       struct cmd_ds_802_11_data_rate cmd;
+       int ret = -1;
 
        lbs_deb_enter(LBS_DEB_CMD);
 
-       cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
-                            S_DS_GEN);
-       cmd->command = cpu_to_le16(CMD_802_11_DATA_RATE);
-       memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
-       pdatarate->action = cpu_to_le16(cmd_action);
-
-       if (cmd_action == CMD_ACT_SET_TX_FIX_RATE) {
-               pdatarate->rates[0] = lbs_data_rate_to_fw_index(priv->cur_rate);
-               lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n",
-                      priv->cur_rate);
-       } else if (cmd_action == CMD_ACT_SET_TX_AUTO) {
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.hdr.size = cpu_to_le16(sizeof(cmd));
+       cmd.action = cpu_to_le16(CMD_ACT_GET_TX_RATE);
+
+       ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, cmd);
+       if (ret)
+               goto out;
+
+       lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
+
+       ret = (int) lbs_fw_index_to_data_rate(cmd.rates[0]);
+       lbs_deb_cmd("DATA_RATE: current rate 0x%02x\n", ret);
+
+out:
+       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
+       return ret;
+}
+
+/**
+ *  @brief Set the data rate
+ *
+ *  @param priv        A pointer to struct lbs_private structure
+ *  @param rate        The desired data rate, or 0 to clear a locked rate
+ *
+ *  @return            0 on success, error on failure
+ */
+int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
+{
+       struct cmd_ds_802_11_data_rate cmd;
+       int ret = 0;
+
+       lbs_deb_enter(LBS_DEB_CMD);
+
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.hdr.size = cpu_to_le16(sizeof(cmd));
+
+       if (rate > 0) {
+               cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
+               cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
+               if (cmd.rates[0] == 0) {
+                       lbs_deb_cmd("DATA_RATE: invalid requested rate of"
+                                   " 0x%02X\n", rate);
+                       ret = 0;
+                       goto out;
+               }
+               lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
+       } else {
+               cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
                lbs_deb_cmd("DATA_RATE: setting auto\n");
        }
 
-       lbs_deb_leave(LBS_DEB_CMD);
-       return 0;
+       ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, cmd);
+       if (ret)
+               goto out;
+
+       lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
+
+       /* FIXME: get actual rates FW can do if this command actually returns
+        * all data rates supported.
+        */
+       priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
+       lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
+
+out:
+       lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
+       return ret;
 }
 
 static int lbs_cmd_mac_multicast_adr(struct lbs_private *priv,
@@ -1348,9 +1404,6 @@ int lbs_prepare_and_send_command(struct lbs_private *priv,
                ret = lbs_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
                break;
 
-       case CMD_802_11_DATA_RATE:
-               ret = lbs_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
-               break;
        case CMD_802_11_RATE_ADAPT_RATESET:
                ret = lbs_cmd_802_11_rate_adapt_rateset(priv,
                                                         cmdptr, cmd_action);
index 950acce3baafd0a6b873c6a2c5f765ecf0ec90db..4bd6f56281f6dde5ccfdf8d3b1093a3d3dbd87fd 100644 (file)
@@ -27,4 +27,7 @@ int lbs_update_hw_spec(struct lbs_private *priv);
 int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
                    struct cmd_ds_mesh_access *cmd);
 
+int lbs_get_data_rate(struct lbs_private *priv);
+int lbs_set_data_rate(struct lbs_private *priv, u8 rate);
+
 #endif /* _LBS_CMD_H */
index 6ff705b49ddc73ae54e4c3f4bc774f0bf8042919..797c943457eb892583dc99a23a25794f52aca3e4 100644 (file)
@@ -325,26 +325,6 @@ static int lbs_ret_802_11_rate_adapt_rateset(struct lbs_private *priv,
        return 0;
 }
 
-static int lbs_ret_802_11_data_rate(struct lbs_private *priv,
-                                    struct cmd_ds_command *resp)
-{
-       struct cmd_ds_802_11_data_rate *pdatarate = &resp->params.drate;
-
-       lbs_deb_enter(LBS_DEB_CMD);
-
-       lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) pdatarate,
-               sizeof(struct cmd_ds_802_11_data_rate));
-
-       /* FIXME: get actual rates FW can do if this command actually returns
-        * all data rates supported.
-        */
-       priv->cur_rate = lbs_fw_index_to_data_rate(pdatarate->rates[0]);
-       lbs_deb_cmd("DATA_RATE: current rate 0x%02x\n", priv->cur_rate);
-
-       lbs_deb_leave(LBS_DEB_CMD);
-       return 0;
-}
-
 static int lbs_ret_802_11_rf_channel(struct lbs_private *priv,
                                      struct cmd_ds_command *resp)
 {
@@ -565,9 +545,6 @@ static inline int handle_cmd_response(struct lbs_private *priv,
                ret = lbs_ret_802_11_enable_rsn(priv, resp);
                break;
 
-       case CMD_RET(CMD_802_11_DATA_RATE):
-               ret = lbs_ret_802_11_data_rate(priv, resp);
-               break;
        case CMD_RET(CMD_802_11_RATE_ADAPT_RATESET):
                ret = lbs_ret_802_11_rate_adapt_rateset(priv, resp);
                break;
index d9b151a2880185ab6706b5ed478692a53130d55e..d51010c47b5b1b032ea9e015482c43b76da2d0e2 100644 (file)
@@ -461,6 +461,8 @@ struct PS_CMD_ConfirmSleep {
 };
 
 struct cmd_ds_802_11_data_rate {
+       struct cmd_header hdr;
+
        __le16 action;
        __le16 reserved;
        u8 rates[MAX_RATES];
@@ -659,7 +661,6 @@ struct cmd_ds_command {
                struct cmd_ds_802_11_rf_tx_power txp;
                struct cmd_ds_802_11_rf_antenna rant;
                struct cmd_ds_802_11_monitor_mode monitor;
-               struct cmd_ds_802_11_data_rate drate;
                struct cmd_ds_802_11_rate_adapt_rateset rateset;
                struct cmd_ds_mac_multicast_adr madr;
                struct cmd_ds_802_11_ad_hoc_join adj;
index 7f6b3ccef0c27beb37702009c3ca322e695207dd..2fe7ad0f8327aab4df520566ab39c2f129112894 100644 (file)
@@ -854,12 +854,8 @@ static int lbs_setup_firmware(struct lbs_private *priv)
 
        lbs_set_mac_packet_filter(priv);
 
-       /* Get the supported Data rates */
-       ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
-                                   CMD_ACT_GET_TX_RATE,
-                                   CMD_OPTION_WAITFORRSP, 0, NULL);
-
-       if (ret) {
+       ret = lbs_get_data_rate(priv);
+       if (ret < 0) {
                ret = -1;
                goto done;
        }
index 1e0b2245db56b157db6b71f093ae8b5fc941aa0b..e44c0ce804edd0407aac2939fdd6ec5e3fb869df 100644 (file)
@@ -19,6 +19,7 @@
 #include "join.h"
 #include "wext.h"
 #include "assoc.h"
+#include "cmd.h"
 
 
 static inline void lbs_postpone_association_work(struct lbs_private *priv)
@@ -962,8 +963,7 @@ static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
                  struct iw_param *vwrq, char *extra)
 {
        struct lbs_private *priv = dev->priv;
-       u32 new_rate;
-       u16 action;
+       u8 new_rate = 0;
        int ret = -EINVAL;
        u8 rates[MAX_RATES + 1];
 
@@ -972,7 +972,6 @@ static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
 
        /* Auto rate? */
        if (vwrq->value == -1) {
-               action = CMD_ACT_SET_TX_AUTO;
                priv->auto_rate = 1;
                priv->cur_rate = 0;
        } else {
@@ -989,12 +988,10 @@ static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
                }
 
                priv->cur_rate = new_rate;
-               action = CMD_ACT_SET_TX_FIX_RATE;
                priv->auto_rate = 0;
        }
 
-       ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
-                                   action, CMD_OPTION_WAITFORRSP, 0, NULL);
+       ret = lbs_set_data_rate(priv, new_rate);
 
 out:
        lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);