aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/wl12xx/wl1271_cmd.c
diff options
context:
space:
mode:
authorJuuso Oikarinen <juuso.oikarinen@nokia.com>2009-11-02 13:22:13 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-11-02 15:43:36 -0500
commitfa867e7355a1bdcd9bf7d55ebe9296f5b9c4028a (patch)
treede3ce5fe17f153c7303ed0c12df33e67c6c56a99 /drivers/net/wireless/wl12xx/wl1271_cmd.c
parentad150e966e987edcf737e1871d9e44a30d1aa58d (diff)
wl1271: Generalize command response reading
Responses to firmware commands are read in by the command transmission function, as part of command flow. Previously responses were read in multiple places. Signed-off-by: Juuso Oikarinen <juuso.oikarinen@nokia.com> Reviewed-by: Luciano Coelho <luciano.coelho@nokia.com> Signed-off-by: Luciano Coelho <luciano.coelho@nokia.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/wl12xx/wl1271_cmd.c')
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_cmd.c67
1 files changed, 27 insertions, 40 deletions
diff --git a/drivers/net/wireless/wl12xx/wl1271_cmd.c b/drivers/net/wireless/wl12xx/wl1271_cmd.c
index 8acee5cf0e61..990eb01b4c71 100644
--- a/drivers/net/wireless/wl12xx/wl1271_cmd.c
+++ b/drivers/net/wireless/wl12xx/wl1271_cmd.c
@@ -42,7 +42,8 @@
42 * @buf: buffer containing the command, must work with dma 42 * @buf: buffer containing the command, must work with dma
43 * @len: length of the buffer 43 * @len: length of the buffer
44 */ 44 */
45int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len) 45int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
46 size_t res_len)
46{ 47{
47 struct wl1271_cmd_header *cmd; 48 struct wl1271_cmd_header *cmd;
48 unsigned long timeout; 49 unsigned long timeout;
@@ -76,8 +77,9 @@ int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len)
76 } 77 }
77 78
78 /* read back the status code of the command */ 79 /* read back the status code of the command */
79 wl1271_spi_read(wl, wl->cmd_box_addr, cmd, 80 if (res_len == 0)
80 sizeof(struct wl1271_cmd_header), false); 81 res_len = sizeof(struct wl1271_cmd_header);
82 wl1271_spi_read(wl, wl->cmd_box_addr, cmd, res_len, false);
81 83
82 status = le16_to_cpu(cmd->status); 84 status = le16_to_cpu(cmd->status);
83 if (status != CMD_STATUS_SUCCESS) { 85 if (status != CMD_STATUS_SUCCESS) {
@@ -273,7 +275,7 @@ int wl1271_cmd_join(struct wl1271 *wl)
273 wl->tx_security_seq_16 = 0; 275 wl->tx_security_seq_16 = 0;
274 wl->tx_security_seq_32 = 0; 276 wl->tx_security_seq_32 = 0;
275 277
276 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join)); 278 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
277 if (ret < 0) { 279 if (ret < 0) {
278 wl1271_error("failed to initiate cmd join"); 280 wl1271_error("failed to initiate cmd join");
279 goto out_free; 281 goto out_free;
@@ -305,30 +307,21 @@ out:
305int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) 307int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
306{ 308{
307 int ret; 309 int ret;
310 size_t res_len = 0;
308 311
309 wl1271_debug(DEBUG_CMD, "cmd test"); 312 wl1271_debug(DEBUG_CMD, "cmd test");
310 313
311 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len); 314 if (answer)
315 res_len = buf_len;
316
317 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
312 318
313 if (ret < 0) { 319 if (ret < 0) {
314 wl1271_warning("TEST command failed"); 320 wl1271_warning("TEST command failed");
315 return ret; 321 return ret;
316 } 322 }
317 323
318 if (answer) { 324 return ret;
319 struct wl1271_command *cmd_answer;
320
321 /*
322 * The test command got in, we can read the answer.
323 * The answer would be a wl1271_command, where the
324 * parameter array contains the actual answer.
325 */
326 wl1271_spi_read(wl, wl->cmd_box_addr, buf, buf_len, false);
327
328 cmd_answer = buf;
329 }
330
331 return 0;
332} 325}
333 326
334/** 327/**
@@ -351,16 +344,10 @@ int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
351 /* payload length, does not include any headers */ 344 /* payload length, does not include any headers */
352 acx->len = cpu_to_le16(len - sizeof(*acx)); 345 acx->len = cpu_to_le16(len - sizeof(*acx));
353 346
354 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx)); 347 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
355 if (ret < 0) { 348 if (ret < 0)
356 wl1271_error("INTERROGATE command failed"); 349 wl1271_error("INTERROGATE command failed");
357 goto out;
358 }
359
360 /* the interrogate command got in, we can read the answer */
361 wl1271_spi_read(wl, wl->cmd_box_addr, buf, len, false);
362 350
363out:
364 return ret; 351 return ret;
365} 352}
366 353
@@ -384,7 +371,7 @@ int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
384 /* payload length, does not include any headers */ 371 /* payload length, does not include any headers */
385 acx->len = cpu_to_le16(len - sizeof(*acx)); 372 acx->len = cpu_to_le16(len - sizeof(*acx));
386 373
387 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len); 374 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
388 if (ret < 0) { 375 if (ret < 0) {
389 wl1271_warning("CONFIGURE command NOK"); 376 wl1271_warning("CONFIGURE command NOK");
390 return ret; 377 return ret;
@@ -417,7 +404,7 @@ int wl1271_cmd_data_path(struct wl1271 *wl, u8 channel, bool enable)
417 cmd_tx = CMD_DISABLE_TX; 404 cmd_tx = CMD_DISABLE_TX;
418 } 405 }
419 406
420 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd)); 407 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
421 if (ret < 0) { 408 if (ret < 0) {
422 wl1271_error("rx %s cmd for channel %d failed", 409 wl1271_error("rx %s cmd for channel %d failed",
423 enable ? "start" : "stop", channel); 410 enable ? "start" : "stop", channel);
@@ -427,7 +414,7 @@ int wl1271_cmd_data_path(struct wl1271 *wl, u8 channel, bool enable)
427 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", 414 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
428 enable ? "start" : "stop", channel); 415 enable ? "start" : "stop", channel);
429 416
430 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd)); 417 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
431 if (ret < 0) { 418 if (ret < 0) {
432 wl1271_error("tx %s cmd for channel %d failed", 419 wl1271_error("tx %s cmd for channel %d failed",
433 enable ? "start" : "stop", channel); 420 enable ? "start" : "stop", channel);
@@ -469,7 +456,7 @@ int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
469 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */ 456 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */
470 457
471 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, 458 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
472 sizeof(*ps_params)); 459 sizeof(*ps_params), 0);
473 if (ret < 0) { 460 if (ret < 0) {
474 wl1271_error("cmd set_ps_mode failed"); 461 wl1271_error("cmd set_ps_mode failed");
475 goto out; 462 goto out;
@@ -500,14 +487,14 @@ int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
500 cmd->addr = cpu_to_le32(addr); 487 cmd->addr = cpu_to_le32(addr);
501 cmd->size = cpu_to_le32(len); 488 cmd->size = cpu_to_le32(len);
502 489
503 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd)); 490 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
491 sizeof(*cmd));
504 if (ret < 0) { 492 if (ret < 0) {
505 wl1271_error("read memory command failed: %d", ret); 493 wl1271_error("read memory command failed: %d", ret);
506 goto out; 494 goto out;
507 } 495 }
508 496
509 /* the read command got in, we can now read the answer */ 497 /* the read command got in */
510 wl1271_spi_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd), false);
511 memcpy(answer, cmd->value, len); 498 memcpy(answer, cmd->value, len);
512 499
513out: 500out:
@@ -609,7 +596,7 @@ int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
609 trigger->timeout = 0; 596 trigger->timeout = 0;
610 597
611 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger, 598 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
612 sizeof(*trigger)); 599 sizeof(*trigger), 0);
613 if (ret < 0) { 600 if (ret < 0) {
614 wl1271_error("trigger scan to failed for hw scan"); 601 wl1271_error("trigger scan to failed for hw scan");
615 goto out; 602 goto out;
@@ -632,7 +619,7 @@ int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
632 } 619 }
633 } 620 }
634 621
635 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params)); 622 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params), 0);
636 if (ret < 0) { 623 if (ret < 0) {
637 wl1271_error("SCAN failed"); 624 wl1271_error("SCAN failed");
638 wl->scanning = false; 625 wl->scanning = false;
@@ -670,7 +657,7 @@ int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
670 if (buf) 657 if (buf)
671 memcpy(cmd->template_data, buf, buf_len); 658 memcpy(cmd->template_data, buf, buf_len);
672 659
673 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd)); 660 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
674 if (ret < 0) { 661 if (ret < 0) {
675 wl1271_warning("cmd set_template failed: %d", ret); 662 wl1271_warning("cmd set_template failed: %d", ret);
676 goto out_free; 663 goto out_free;
@@ -849,7 +836,7 @@ int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
849 cmd->key_action = cpu_to_le16(KEY_SET_ID); 836 cmd->key_action = cpu_to_le16(KEY_SET_ID);
850 cmd->key_type = KEY_WEP; 837 cmd->key_type = KEY_WEP;
851 838
852 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd)); 839 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
853 if (ret < 0) { 840 if (ret < 0) {
854 wl1271_warning("cmd set_default_wep_key failed: %d", ret); 841 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
855 goto out; 842 goto out;
@@ -906,7 +893,7 @@ int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
906 893
907 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); 894 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
908 895
909 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd)); 896 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
910 if (ret < 0) { 897 if (ret < 0) {
911 wl1271_warning("could not set keys"); 898 wl1271_warning("could not set keys");
912 goto out; 899 goto out;
@@ -936,7 +923,7 @@ int wl1271_cmd_disconnect(struct wl1271 *wl)
936 /* disconnect reason is not used in immediate disconnections */ 923 /* disconnect reason is not used in immediate disconnections */
937 cmd->type = DISCONNECT_IMMEDIATE; 924 cmd->type = DISCONNECT_IMMEDIATE;
938 925
939 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd)); 926 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
940 if (ret < 0) { 927 if (ret < 0) {
941 wl1271_error("failed to send disconnect command"); 928 wl1271_error("failed to send disconnect command");
942 goto out_free; 929 goto out_free;