aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/libertas
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/libertas')
-rw-r--r--drivers/net/wireless/libertas/README4
-rw-r--r--drivers/net/wireless/libertas/cfg.c153
-rw-r--r--drivers/net/wireless/libertas/cmd.c315
-rw-r--r--drivers/net/wireless/libertas/cmdresp.c46
-rw-r--r--drivers/net/wireless/libertas/debugfs.c43
-rw-r--r--drivers/net/wireless/libertas/decl.h21
-rw-r--r--drivers/net/wireless/libertas/defs.h120
-rw-r--r--drivers/net/wireless/libertas/dev.h24
-rw-r--r--drivers/net/wireless/libertas/ethtool.c3
-rw-r--r--drivers/net/wireless/libertas/host.h35
-rw-r--r--drivers/net/wireless/libertas/if_cs.c265
-rw-r--r--drivers/net/wireless/libertas/if_sdio.c250
-rw-r--r--drivers/net/wireless/libertas/if_sdio.h4
-rw-r--r--drivers/net/wireless/libertas/if_spi.c727
-rw-r--r--drivers/net/wireless/libertas/if_spi.h75
-rw-r--r--drivers/net/wireless/libertas/if_usb.c232
-rw-r--r--drivers/net/wireless/libertas/if_usb.h15
-rw-r--r--drivers/net/wireless/libertas/main.c325
-rw-r--r--drivers/net/wireless/libertas/mesh.c231
-rw-r--r--drivers/net/wireless/libertas/mesh.h6
-rw-r--r--drivers/net/wireless/libertas/rx.c45
-rw-r--r--drivers/net/wireless/libertas/tx.c34
-rw-r--r--drivers/net/wireless/libertas/types.h18
23 files changed, 1775 insertions, 1216 deletions
diff --git a/drivers/net/wireless/libertas/README b/drivers/net/wireless/libertas/README
index 60fd1afe89ac..1453eec82a99 100644
--- a/drivers/net/wireless/libertas/README
+++ b/drivers/net/wireless/libertas/README
@@ -70,7 +70,7 @@ rdrf
70 These commands are used to read the MAC, BBP and RF registers from the 70 These commands are used to read the MAC, BBP and RF registers from the
71 card. These commands take one parameter that specifies the offset 71 card. These commands take one parameter that specifies the offset
72 location that is to be read. This parameter must be specified in 72 location that is to be read. This parameter must be specified in
73 hexadecimal (its possible to preceed preceding the number with a "0x"). 73 hexadecimal (its possible to precede preceding the number with a "0x").
74 74
75 Path: /sys/kernel/debug/libertas_wireless/ethX/registers/ 75 Path: /sys/kernel/debug/libertas_wireless/ethX/registers/
76 76
@@ -84,7 +84,7 @@ wrrf
84 These commands are used to write the MAC, BBP and RF registers in the 84 These commands are used to write the MAC, BBP and RF registers in the
85 card. These commands take two parameters that specify the offset 85 card. These commands take two parameters that specify the offset
86 location and the value that is to be written. This parameters must 86 location and the value that is to be written. This parameters must
87 be specified in hexadecimal (its possible to preceed the number 87 be specified in hexadecimal (its possible to precede the number
88 with a "0x"). 88 with a "0x").
89 89
90 Usage: 90 Usage:
diff --git a/drivers/net/wireless/libertas/cfg.c b/drivers/net/wireless/libertas/cfg.c
index 3e82f1627209..5d637af2d7c3 100644
--- a/drivers/net/wireless/libertas/cfg.c
+++ b/drivers/net/wireless/libertas/cfg.c
@@ -6,10 +6,11 @@
6 * 6 *
7 */ 7 */
8 8
9#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10
9#include <linux/sched.h> 11#include <linux/sched.h>
10#include <linux/wait.h> 12#include <linux/wait.h>
11#include <linux/slab.h> 13#include <linux/slab.h>
12#include <linux/sched.h>
13#include <linux/ieee80211.h> 14#include <linux/ieee80211.h>
14#include <net/cfg80211.h> 15#include <net/cfg80211.h>
15#include <asm/unaligned.h> 16#include <asm/unaligned.h>
@@ -123,8 +124,10 @@ static u8 lbs_auth_to_authtype(enum nl80211_auth_type auth_type)
123} 124}
124 125
125 126
126/* Various firmware commands need the list of supported rates, but with 127/*
127 the hight-bit set for basic rates */ 128 * Various firmware commands need the list of supported rates, but with
129 * the hight-bit set for basic rates
130 */
128static int lbs_add_rates(u8 *rates) 131static int lbs_add_rates(u8 *rates)
129{ 132{
130 size_t i; 133 size_t i;
@@ -426,7 +429,7 @@ static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len)
426 return ie_len + 2; 429 return ie_len + 2;
427} 430}
428 431
429/*************************************************************************** 432/*
430 * Set Channel 433 * Set Channel
431 */ 434 */
432 435
@@ -453,7 +456,7 @@ static int lbs_cfg_set_channel(struct wiphy *wiphy,
453 456
454 457
455 458
456/*************************************************************************** 459/*
457 * Scanning 460 * Scanning
458 */ 461 */
459 462
@@ -480,7 +483,6 @@ static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
480 struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp; 483 struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp;
481 int bsssize; 484 int bsssize;
482 const u8 *pos; 485 const u8 *pos;
483 u16 nr_sets;
484 const u8 *tsfdesc; 486 const u8 *tsfdesc;
485 int tsfsize; 487 int tsfsize;
486 int i; 488 int i;
@@ -489,12 +491,11 @@ static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
489 lbs_deb_enter(LBS_DEB_CFG80211); 491 lbs_deb_enter(LBS_DEB_CFG80211);
490 492
491 bsssize = get_unaligned_le16(&scanresp->bssdescriptsize); 493 bsssize = get_unaligned_le16(&scanresp->bssdescriptsize);
492 nr_sets = le16_to_cpu(scanresp->nr_sets);
493 494
494 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n", 495 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
495 nr_sets, bsssize, le16_to_cpu(resp->size)); 496 scanresp->nr_sets, bsssize, le16_to_cpu(resp->size));
496 497
497 if (nr_sets == 0) { 498 if (scanresp->nr_sets == 0) {
498 ret = 0; 499 ret = 0;
499 goto done; 500 goto done;
500 } 501 }
@@ -526,20 +527,33 @@ static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
526 527
527 pos = scanresp->bssdesc_and_tlvbuffer; 528 pos = scanresp->bssdesc_and_tlvbuffer;
528 529
530 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_RSP", scanresp->bssdesc_and_tlvbuffer,
531 scanresp->bssdescriptsize);
532
529 tsfdesc = pos + bsssize; 533 tsfdesc = pos + bsssize;
530 tsfsize = 4 + 8 * scanresp->nr_sets; 534 tsfsize = 4 + 8 * scanresp->nr_sets;
535 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TSF", (u8 *) tsfdesc, tsfsize);
531 536
532 /* Validity check: we expect a Marvell-Local TLV */ 537 /* Validity check: we expect a Marvell-Local TLV */
533 i = get_unaligned_le16(tsfdesc); 538 i = get_unaligned_le16(tsfdesc);
534 tsfdesc += 2; 539 tsfdesc += 2;
535 if (i != TLV_TYPE_TSFTIMESTAMP) 540 if (i != TLV_TYPE_TSFTIMESTAMP) {
541 lbs_deb_scan("scan response: invalid TSF Timestamp %d\n", i);
536 goto done; 542 goto done;
537 /* Validity check: the TLV holds TSF values with 8 bytes each, so 543 }
538 * the size in the TLV must match the nr_sets value */ 544
545 /*
546 * Validity check: the TLV holds TSF values with 8 bytes each, so
547 * the size in the TLV must match the nr_sets value
548 */
539 i = get_unaligned_le16(tsfdesc); 549 i = get_unaligned_le16(tsfdesc);
540 tsfdesc += 2; 550 tsfdesc += 2;
541 if (i / 8 != scanresp->nr_sets) 551 if (i / 8 != scanresp->nr_sets) {
552 lbs_deb_scan("scan response: invalid number of TSF timestamp "
553 "sets (expected %d got %d)\n", scanresp->nr_sets,
554 i / 8);
542 goto done; 555 goto done;
556 }
543 557
544 for (i = 0; i < scanresp->nr_sets; i++) { 558 for (i = 0; i < scanresp->nr_sets; i++) {
545 const u8 *bssid; 559 const u8 *bssid;
@@ -573,16 +587,21 @@ static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
573 587
574 /* To find out the channel, we must parse the IEs */ 588 /* To find out the channel, we must parse the IEs */
575 ie = pos; 589 ie = pos;
576 /* 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon 590 /*
577 interval, capabilities */ 591 * 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
592 * interval, capabilities
593 */
578 ielen = left = len - (6 + 1 + 8 + 2 + 2); 594 ielen = left = len - (6 + 1 + 8 + 2 + 2);
579 while (left >= 2) { 595 while (left >= 2) {
580 u8 id, elen; 596 u8 id, elen;
581 id = *pos++; 597 id = *pos++;
582 elen = *pos++; 598 elen = *pos++;
583 left -= 2; 599 left -= 2;
584 if (elen > left || elen == 0) 600 if (elen > left || elen == 0) {
601 lbs_deb_scan("scan response: invalid IE fmt\n");
585 goto done; 602 goto done;
603 }
604
586 if (id == WLAN_EID_DS_PARAMS) 605 if (id == WLAN_EID_DS_PARAMS)
587 chan_no = *pos; 606 chan_no = *pos;
588 if (id == WLAN_EID_SSID) { 607 if (id == WLAN_EID_SSID) {
@@ -596,7 +615,8 @@ static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
596 /* No channel, no luck */ 615 /* No channel, no luck */
597 if (chan_no != -1) { 616 if (chan_no != -1) {
598 struct wiphy *wiphy = priv->wdev->wiphy; 617 struct wiphy *wiphy = priv->wdev->wiphy;
599 int freq = ieee80211_channel_to_frequency(chan_no); 618 int freq = ieee80211_channel_to_frequency(chan_no,
619 IEEE80211_BAND_2GHZ);
600 struct ieee80211_channel *channel = 620 struct ieee80211_channel *channel =
601 ieee80211_get_channel(wiphy, freq); 621 ieee80211_get_channel(wiphy, freq);
602 622
@@ -606,14 +626,16 @@ static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
606 print_ssid(ssid_buf, ssid, ssid_len), 626 print_ssid(ssid_buf, ssid, ssid_len),
607 LBS_SCAN_RSSI_TO_MBM(rssi)/100); 627 LBS_SCAN_RSSI_TO_MBM(rssi)/100);
608 628
609 if (channel || 629 if (channel &&
610 !(channel->flags & IEEE80211_CHAN_DISABLED)) 630 !(channel->flags & IEEE80211_CHAN_DISABLED))
611 cfg80211_inform_bss(wiphy, channel, 631 cfg80211_inform_bss(wiphy, channel,
612 bssid, le64_to_cpu(*(__le64 *)tsfdesc), 632 bssid, le64_to_cpu(*(__le64 *)tsfdesc),
613 capa, intvl, ie, ielen, 633 capa, intvl, ie, ielen,
614 LBS_SCAN_RSSI_TO_MBM(rssi), 634 LBS_SCAN_RSSI_TO_MBM(rssi),
615 GFP_KERNEL); 635 GFP_KERNEL);
616 } 636 } else
637 lbs_deb_scan("scan response: missing BSS channel IE\n");
638
617 tsfdesc += 8; 639 tsfdesc += 8;
618 } 640 }
619 ret = 0; 641 ret = 0;
@@ -685,8 +707,9 @@ static void lbs_scan_worker(struct work_struct *work)
685 707
686 if (priv->scan_channel < priv->scan_req->n_channels) { 708 if (priv->scan_channel < priv->scan_req->n_channels) {
687 cancel_delayed_work(&priv->scan_work); 709 cancel_delayed_work(&priv->scan_work);
688 queue_delayed_work(priv->work_thread, &priv->scan_work, 710 if (!priv->stopping)
689 msecs_to_jiffies(300)); 711 queue_delayed_work(priv->work_thread, &priv->scan_work,
712 msecs_to_jiffies(300));
690 } 713 }
691 714
692 /* This is the final data we are about to send */ 715 /* This is the final data we are about to send */
@@ -775,7 +798,7 @@ static int lbs_cfg_scan(struct wiphy *wiphy,
775 798
776 799
777 800
778/*************************************************************************** 801/*
779 * Events 802 * Events
780 */ 803 */
781 804
@@ -810,7 +833,7 @@ void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
810 833
811 834
812 835
813/*************************************************************************** 836/*
814 * Connect/disconnect 837 * Connect/disconnect
815 */ 838 */
816 839
@@ -935,8 +958,10 @@ static int lbs_enable_rsn(struct lbs_private *priv, int enable)
935 * Set WPA/WPA key material 958 * Set WPA/WPA key material
936 */ 959 */
937 960
938/* like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we 961/*
939 * get rid of WEXT, this should go into host.h */ 962 * like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
963 * get rid of WEXT, this should go into host.h
964 */
940 965
941struct cmd_key_material { 966struct cmd_key_material {
942 struct cmd_header hdr; 967 struct cmd_header hdr;
@@ -1103,7 +1128,7 @@ static int lbs_associate(struct lbs_private *priv,
1103 lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp); 1128 lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp);
1104 1129
1105 /* add auth type TLV */ 1130 /* add auth type TLV */
1106 if (priv->fwrelease >= 0x09000000) 1131 if (MRVL_FW_MAJOR_REV(priv->fwrelease) >= 9)
1107 pos += lbs_add_auth_type_tlv(pos, sme->auth_type); 1132 pos += lbs_add_auth_type_tlv(pos, sme->auth_type);
1108 1133
1109 /* add WPA/WPA2 TLV */ 1134 /* add WPA/WPA2 TLV */
@@ -1114,6 +1139,9 @@ static int lbs_associate(struct lbs_private *priv,
1114 (u16)(pos - (u8 *) &cmd->iebuf); 1139 (u16)(pos - (u8 *) &cmd->iebuf);
1115 cmd->hdr.size = cpu_to_le16(len); 1140 cmd->hdr.size = cpu_to_le16(len);
1116 1141
1142 lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_CMD", (u8 *) cmd,
1143 le16_to_cpu(cmd->hdr.size));
1144
1117 /* store for later use */ 1145 /* store for later use */
1118 memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN); 1146 memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN);
1119 1147
@@ -1121,14 +1149,28 @@ static int lbs_associate(struct lbs_private *priv,
1121 if (ret) 1149 if (ret)
1122 goto done; 1150 goto done;
1123 1151
1124
1125 /* generate connect message to cfg80211 */ 1152 /* generate connect message to cfg80211 */
1126 1153
1127 resp = (void *) cmd; /* recast for easier field access */ 1154 resp = (void *) cmd; /* recast for easier field access */
1128 status = le16_to_cpu(resp->statuscode); 1155 status = le16_to_cpu(resp->statuscode);
1129 1156
1130 /* Convert statis code of old firmware */ 1157 /* Older FW versions map the IEEE 802.11 Status Code in the association
1131 if (priv->fwrelease < 0x09000000) 1158 * response to the following values returned in resp->statuscode:
1159 *
1160 * IEEE Status Code Marvell Status Code
1161 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
1162 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1163 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1164 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1165 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1166 * others -> 0x0003 ASSOC_RESULT_REFUSED
1167 *
1168 * Other response codes:
1169 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
1170 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
1171 * association response from the AP)
1172 */
1173 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1132 switch (status) { 1174 switch (status) {
1133 case 0: 1175 case 0:
1134 break; 1176 break;
@@ -1150,11 +1192,16 @@ static int lbs_associate(struct lbs_private *priv,
1150 break; 1192 break;
1151 default: 1193 default:
1152 lbs_deb_assoc("association failure %d\n", status); 1194 lbs_deb_assoc("association failure %d\n", status);
1153 status = WLAN_STATUS_UNSPECIFIED_FAILURE; 1195 /* v5 OLPC firmware does return the AP status code if
1196 * it's not one of the values above. Let that through.
1197 */
1198 break;
1199 }
1154 } 1200 }
1155 1201
1156 lbs_deb_assoc("status %d, capability 0x%04x\n", status, 1202 lbs_deb_assoc("status %d, statuscode 0x%04x, capability 0x%04x, "
1157 le16_to_cpu(resp->capability)); 1203 "aid 0x%04x\n", status, le16_to_cpu(resp->statuscode),
1204 le16_to_cpu(resp->capability), le16_to_cpu(resp->aid));
1158 1205
1159 resp_ie_len = le16_to_cpu(resp->hdr.size) 1206 resp_ie_len = le16_to_cpu(resp->hdr.size)
1160 - sizeof(resp->hdr) 1207 - sizeof(resp->hdr)
@@ -1174,7 +1221,6 @@ static int lbs_associate(struct lbs_private *priv,
1174 netif_tx_wake_all_queues(priv->dev); 1221 netif_tx_wake_all_queues(priv->dev);
1175 } 1222 }
1176 1223
1177
1178done: 1224done:
1179 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); 1225 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1180 return ret; 1226 return ret;
@@ -1278,8 +1324,8 @@ static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1278 sme->ssid, sme->ssid_len, 1324 sme->ssid, sme->ssid_len,
1279 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); 1325 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
1280 if (!bss) { 1326 if (!bss) {
1281 lbs_pr_err("assoc: bss %pM not in scan results\n", 1327 wiphy_err(wiphy, "assoc: bss %pM not in scan results\n",
1282 sme->bssid); 1328 sme->bssid);
1283 ret = -ENOENT; 1329 ret = -ENOENT;
1284 goto done; 1330 goto done;
1285 } 1331 }
@@ -1314,7 +1360,7 @@ static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1314 * we remove all keys like in the WPA/WPA2 setup, 1360 * we remove all keys like in the WPA/WPA2 setup,
1315 * we just don't set RSN. 1361 * we just don't set RSN.
1316 * 1362 *
1317 * Therefore: fall-throught 1363 * Therefore: fall-through
1318 */ 1364 */
1319 case WLAN_CIPHER_SUITE_TKIP: 1365 case WLAN_CIPHER_SUITE_TKIP:
1320 case WLAN_CIPHER_SUITE_CCMP: 1366 case WLAN_CIPHER_SUITE_CCMP:
@@ -1336,8 +1382,8 @@ static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1336 lbs_enable_rsn(priv, sme->crypto.cipher_group != 0); 1382 lbs_enable_rsn(priv, sme->crypto.cipher_group != 0);
1337 break; 1383 break;
1338 default: 1384 default:
1339 lbs_pr_err("unsupported cipher group 0x%x\n", 1385 wiphy_err(wiphy, "unsupported cipher group 0x%x\n",
1340 sme->crypto.cipher_group); 1386 sme->crypto.cipher_group);
1341 ret = -ENOTSUPP; 1387 ret = -ENOTSUPP;
1342 goto done; 1388 goto done;
1343 } 1389 }
@@ -1387,7 +1433,8 @@ static int lbs_cfg_disconnect(struct wiphy *wiphy, struct net_device *dev,
1387 1433
1388static int lbs_cfg_set_default_key(struct wiphy *wiphy, 1434static int lbs_cfg_set_default_key(struct wiphy *wiphy,
1389 struct net_device *netdev, 1435 struct net_device *netdev,
1390 u8 key_index) 1436 u8 key_index, bool unicast,
1437 bool multicast)
1391{ 1438{
1392 struct lbs_private *priv = wiphy_priv(wiphy); 1439 struct lbs_private *priv = wiphy_priv(wiphy);
1393 1440
@@ -1404,7 +1451,7 @@ static int lbs_cfg_set_default_key(struct wiphy *wiphy,
1404 1451
1405 1452
1406static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev, 1453static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev,
1407 u8 idx, const u8 *mac_addr, 1454 u8 idx, bool pairwise, const u8 *mac_addr,
1408 struct key_params *params) 1455 struct key_params *params)
1409{ 1456{
1410 struct lbs_private *priv = wiphy_priv(wiphy); 1457 struct lbs_private *priv = wiphy_priv(wiphy);
@@ -1454,7 +1501,7 @@ static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev,
1454 params->key, params->key_len); 1501 params->key, params->key_len);
1455 break; 1502 break;
1456 default: 1503 default:
1457 lbs_pr_err("unhandled cipher 0x%x\n", params->cipher); 1504 wiphy_err(wiphy, "unhandled cipher 0x%x\n", params->cipher);
1458 ret = -ENOTSUPP; 1505 ret = -ENOTSUPP;
1459 break; 1506 break;
1460 } 1507 }
@@ -1464,7 +1511,7 @@ static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev,
1464 1511
1465 1512
1466static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev, 1513static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev,
1467 u8 key_index, const u8 *mac_addr) 1514 u8 key_index, bool pairwise, const u8 *mac_addr)
1468{ 1515{
1469 1516
1470 lbs_deb_enter(LBS_DEB_CFG80211); 1517 lbs_deb_enter(LBS_DEB_CFG80211);
@@ -1499,7 +1546,7 @@ static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev,
1499} 1546}
1500 1547
1501 1548
1502/*************************************************************************** 1549/*
1503 * Get station 1550 * Get station
1504 */ 1551 */
1505 1552
@@ -1544,7 +1591,7 @@ static int lbs_cfg_get_station(struct wiphy *wiphy, struct net_device *dev,
1544 1591
1545 1592
1546 1593
1547/*************************************************************************** 1594/*
1548 * "Site survey", here just current channel and noise level 1595 * "Site survey", here just current channel and noise level
1549 */ 1596 */
1550 1597
@@ -1561,7 +1608,8 @@ static int lbs_get_survey(struct wiphy *wiphy, struct net_device *dev,
1561 lbs_deb_enter(LBS_DEB_CFG80211); 1608 lbs_deb_enter(LBS_DEB_CFG80211);
1562 1609
1563 survey->channel = ieee80211_get_channel(wiphy, 1610 survey->channel = ieee80211_get_channel(wiphy,
1564 ieee80211_channel_to_frequency(priv->channel)); 1611 ieee80211_channel_to_frequency(priv->channel,
1612 IEEE80211_BAND_2GHZ));
1565 1613
1566 ret = lbs_get_rssi(priv, &signal, &noise); 1614 ret = lbs_get_rssi(priv, &signal, &noise);
1567 if (ret == 0) { 1615 if (ret == 0) {
@@ -1576,7 +1624,7 @@ static int lbs_get_survey(struct wiphy *wiphy, struct net_device *dev,
1576 1624
1577 1625
1578 1626
1579/*************************************************************************** 1627/*
1580 * Change interface 1628 * Change interface
1581 */ 1629 */
1582 1630
@@ -1618,11 +1666,12 @@ static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev,
1618 1666
1619 1667
1620 1668
1621/*************************************************************************** 1669/*
1622 * IBSS (Ad-Hoc) 1670 * IBSS (Ad-Hoc)
1623 */ 1671 */
1624 1672
1625/* The firmware needs the following bits masked out of the beacon-derived 1673/*
1674 * The firmware needs the following bits masked out of the beacon-derived
1626 * capability field when associating/joining to a BSS: 1675 * capability field when associating/joining to a BSS:
1627 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused) 1676 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1628 */ 1677 */
@@ -1961,7 +2010,7 @@ static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1961 2010
1962 2011
1963 2012
1964/*************************************************************************** 2013/*
1965 * Initialization 2014 * Initialization
1966 */ 2015 */
1967 2016
@@ -2025,7 +2074,7 @@ static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv)
2025 }; 2074 };
2026 2075
2027 /* Section 5.17.2 */ 2076 /* Section 5.17.2 */
2028 static struct region_code_mapping regmap[] = { 2077 static const struct region_code_mapping regmap[] = {
2029 {"US ", 0x10}, /* US FCC */ 2078 {"US ", 0x10}, /* US FCC */
2030 {"CA ", 0x20}, /* Canada */ 2079 {"CA ", 0x20}, /* Canada */
2031 {"EU ", 0x30}, /* ETSI */ 2080 {"EU ", 0x30}, /* ETSI */
@@ -2080,13 +2129,13 @@ int lbs_cfg_register(struct lbs_private *priv)
2080 2129
2081 ret = wiphy_register(wdev->wiphy); 2130 ret = wiphy_register(wdev->wiphy);
2082 if (ret < 0) 2131 if (ret < 0)
2083 lbs_pr_err("cannot register wiphy device\n"); 2132 pr_err("cannot register wiphy device\n");
2084 2133
2085 priv->wiphy_registered = true; 2134 priv->wiphy_registered = true;
2086 2135
2087 ret = register_netdev(priv->dev); 2136 ret = register_netdev(priv->dev);
2088 if (ret) 2137 if (ret)
2089 lbs_pr_err("cannot register network device\n"); 2138 pr_err("cannot register network device\n");
2090 2139
2091 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker); 2140 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
2092 2141
diff --git a/drivers/net/wireless/libertas/cmd.c b/drivers/net/wireless/libertas/cmd.c
index 70745928f3f8..71c8f3fccfa1 100644
--- a/drivers/net/wireless/libertas/cmd.c
+++ b/drivers/net/wireless/libertas/cmd.c
@@ -1,7 +1,7 @@
1/** 1/*
2 * This file contains the handling of command. 2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready. 3 * It prepares command and sends it to firmware when it is ready.
4 */ 4 */
5 5
6#include <linux/kfifo.h> 6#include <linux/kfifo.h>
7#include <linux/sched.h> 7#include <linux/sched.h>
@@ -16,14 +16,14 @@
16#define CAL_RSSI(snr, nf) ((s32)((s32)(snr) + CAL_NF(nf))) 16#define CAL_RSSI(snr, nf) ((s32)((s32)(snr) + CAL_NF(nf)))
17 17
18/** 18/**
19 * @brief Simple callback that copies response back into command 19 * lbs_cmd_copyback - Simple callback that copies response back into command
20 * 20 *
21 * @param priv A pointer to struct lbs_private structure 21 * @priv: A pointer to &struct lbs_private structure
22 * @param extra A pointer to the original command structure for which 22 * @extra: A pointer to the original command structure for which
23 * 'resp' is a response 23 * 'resp' is a response
24 * @param resp A pointer to the command response 24 * @resp: A pointer to the command response
25 * 25 *
26 * @return 0 on success, error on failure 26 * returns: 0 on success, error on failure
27 */ 27 */
28int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra, 28int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
29 struct cmd_header *resp) 29 struct cmd_header *resp)
@@ -38,15 +38,15 @@ int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
38EXPORT_SYMBOL_GPL(lbs_cmd_copyback); 38EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
39 39
40/** 40/**
41 * @brief Simple callback that ignores the result. Use this if 41 * lbs_cmd_async_callback - Simple callback that ignores the result.
42 * you just want to send a command to the hardware, but don't 42 * Use this if you just want to send a command to the hardware, but don't
43 * care for the result. 43 * care for the result.
44 * 44 *
45 * @param priv ignored 45 * @priv: ignored
46 * @param extra ignored 46 * @extra: ignored
47 * @param resp ignored 47 * @resp: ignored
48 * 48 *
49 * @return 0 for success 49 * returns: 0 for success
50 */ 50 */
51static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra, 51static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
52 struct cmd_header *resp) 52 struct cmd_header *resp)
@@ -56,10 +56,11 @@ static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
56 56
57 57
58/** 58/**
59 * @brief Checks whether a command is allowed in Power Save mode 59 * is_command_allowed_in_ps - tests if a command is allowed in Power Save mode
60 *
61 * @cmd: the command ID
60 * 62 *
61 * @param command the command ID 63 * returns: 1 if allowed, 0 if not allowed
62 * @return 1 if allowed, 0 if not allowed
63 */ 64 */
64static u8 is_command_allowed_in_ps(u16 cmd) 65static u8 is_command_allowed_in_ps(u16 cmd)
65{ 66{
@@ -75,11 +76,12 @@ static u8 is_command_allowed_in_ps(u16 cmd)
75} 76}
76 77
77/** 78/**
78 * @brief Updates the hardware details like MAC address and regulatory region 79 * lbs_update_hw_spec - Updates the hardware details like MAC address
80 * and regulatory region
79 * 81 *
80 * @param priv A pointer to struct lbs_private structure 82 * @priv: A pointer to &struct lbs_private structure
81 * 83 *
82 * @return 0 on success, error on failure 84 * returns: 0 on success, error on failure
83 */ 85 */
84int lbs_update_hw_spec(struct lbs_private *priv) 86int lbs_update_hw_spec(struct lbs_private *priv)
85{ 87{
@@ -108,7 +110,7 @@ int lbs_update_hw_spec(struct lbs_private *priv)
108 * CF card firmware 5.0.16p0: cap 0x00000303 110 * CF card firmware 5.0.16p0: cap 0x00000303
109 * USB dongle firmware 5.110.17p2: cap 0x00000303 111 * USB dongle firmware 5.110.17p2: cap 0x00000303
110 */ 112 */
111 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n", 113 netdev_info(priv->dev, "%pM, fw %u.%u.%up%u, cap 0x%08x\n",
112 cmd.permanentaddr, 114 cmd.permanentaddr,
113 priv->fwrelease >> 24 & 0xff, 115 priv->fwrelease >> 24 & 0xff,
114 priv->fwrelease >> 16 & 0xff, 116 priv->fwrelease >> 16 & 0xff,
@@ -139,15 +141,20 @@ int lbs_update_hw_spec(struct lbs_private *priv)
139 /* if it's unidentified region code, use the default (USA) */ 141 /* if it's unidentified region code, use the default (USA) */
140 if (i >= MRVDRV_MAX_REGION_CODE) { 142 if (i >= MRVDRV_MAX_REGION_CODE) {
141 priv->regioncode = 0x10; 143 priv->regioncode = 0x10;
142 lbs_pr_info("unidentified region code; using the default (USA)\n"); 144 netdev_info(priv->dev,
145 "unidentified region code; using the default (USA)\n");
143 } 146 }
144 147
145 if (priv->current_addr[0] == 0xff) 148 if (priv->current_addr[0] == 0xff)
146 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN); 149 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
147 150
148 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN); 151 if (!priv->copied_hwaddr) {
149 if (priv->mesh_dev) 152 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
150 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN); 153 if (priv->mesh_dev)
154 memcpy(priv->mesh_dev->dev_addr,
155 priv->current_addr, ETH_ALEN);
156 priv->copied_hwaddr = 1;
157 }
151 158
152out: 159out:
153 lbs_deb_leave(LBS_DEB_CMD); 160 lbs_deb_leave(LBS_DEB_CMD);
@@ -177,6 +184,14 @@ int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
177 struct cmd_ds_host_sleep cmd_config; 184 struct cmd_ds_host_sleep cmd_config;
178 int ret; 185 int ret;
179 186
187 /*
188 * Certain firmware versions do not support EHS_REMOVE_WAKEUP command
189 * and the card will return a failure. Since we need to be
190 * able to reset the mask, in those cases we set a 0 mask instead.
191 */
192 if (criteria == EHS_REMOVE_WAKEUP && !priv->ehs_remove_supported)
193 criteria = 0;
194
180 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config)); 195 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
181 cmd_config.criteria = cpu_to_le32(criteria); 196 cmd_config.criteria = cpu_to_le32(criteria);
182 cmd_config.gpio = priv->wol_gpio; 197 cmd_config.gpio = priv->wol_gpio;
@@ -197,7 +212,7 @@ int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
197 (uint8_t *)&cmd_config.wol_conf, 212 (uint8_t *)&cmd_config.wol_conf,
198 sizeof(struct wol_config)); 213 sizeof(struct wol_config));
199 } else { 214 } else {
200 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret); 215 netdev_info(priv->dev, "HOST_SLEEP_CFG failed %d\n", ret);
201 } 216 }
202 217
203 return ret; 218 return ret;
@@ -205,14 +220,14 @@ int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
205EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg); 220EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
206 221
207/** 222/**
208 * @brief Sets the Power Save mode 223 * lbs_set_ps_mode - Sets the Power Save mode
209 * 224 *
210 * @param priv A pointer to struct lbs_private structure 225 * @priv: A pointer to &struct lbs_private structure
211 * @param cmd_action The Power Save operation (PS_MODE_ACTION_ENTER_PS or 226 * @cmd_action: The Power Save operation (PS_MODE_ACTION_ENTER_PS or
212 * PS_MODE_ACTION_EXIT_PS) 227 * PS_MODE_ACTION_EXIT_PS)
213 * @param block Whether to block on a response or not 228 * @block: Whether to block on a response or not
214 * 229 *
215 * @return 0 on success, error on failure 230 * returns: 0 on success, error on failure
216 */ 231 */
217int lbs_set_ps_mode(struct lbs_private *priv, u16 cmd_action, bool block) 232int lbs_set_ps_mode(struct lbs_private *priv, u16 cmd_action, bool block)
218{ 233{
@@ -300,7 +315,7 @@ static int lbs_wait_for_ds_awake(struct lbs_private *priv)
300 if (priv->is_deep_sleep) { 315 if (priv->is_deep_sleep) {
301 if (!wait_event_interruptible_timeout(priv->ds_awake_q, 316 if (!wait_event_interruptible_timeout(priv->ds_awake_q,
302 !priv->is_deep_sleep, (10 * HZ))) { 317 !priv->is_deep_sleep, (10 * HZ))) {
303 lbs_pr_err("ds_awake_q: timer expired\n"); 318 netdev_err(priv->dev, "ds_awake_q: timer expired\n");
304 ret = -1; 319 ret = -1;
305 } 320 }
306 } 321 }
@@ -325,7 +340,7 @@ int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
325 netif_carrier_off(priv->dev); 340 netif_carrier_off(priv->dev);
326 } 341 }
327 } else { 342 } else {
328 lbs_pr_err("deep sleep: already enabled\n"); 343 netdev_err(priv->dev, "deep sleep: already enabled\n");
329 } 344 }
330 } else { 345 } else {
331 if (priv->is_deep_sleep) { 346 if (priv->is_deep_sleep) {
@@ -335,8 +350,8 @@ int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
335 if (!ret) { 350 if (!ret) {
336 ret = lbs_wait_for_ds_awake(priv); 351 ret = lbs_wait_for_ds_awake(priv);
337 if (ret) 352 if (ret)
338 lbs_pr_err("deep sleep: wakeup" 353 netdev_err(priv->dev,
339 "failed\n"); 354 "deep sleep: wakeup failed\n");
340 } 355 }
341 } 356 }
342 } 357 }
@@ -370,8 +385,9 @@ int lbs_set_host_sleep(struct lbs_private *priv, int host_sleep)
370 ret = lbs_host_sleep_cfg(priv, priv->wol_criteria, 385 ret = lbs_host_sleep_cfg(priv, priv->wol_criteria,
371 (struct wol_config *)NULL); 386 (struct wol_config *)NULL);
372 if (ret) { 387 if (ret) {
373 lbs_pr_info("Host sleep configuration failed: " 388 netdev_info(priv->dev,
374 "%d\n", ret); 389 "Host sleep configuration failed: %d\n",
390 ret);
375 return ret; 391 return ret;
376 } 392 }
377 if (priv->psstate == PS_STATE_FULL_POWER) { 393 if (priv->psstate == PS_STATE_FULL_POWER) {
@@ -381,19 +397,21 @@ int lbs_set_host_sleep(struct lbs_private *priv, int host_sleep)
381 sizeof(cmd), 397 sizeof(cmd),
382 lbs_ret_host_sleep_activate, 0); 398 lbs_ret_host_sleep_activate, 0);
383 if (ret) 399 if (ret)
384 lbs_pr_info("HOST_SLEEP_ACTIVATE " 400 netdev_info(priv->dev,
385 "failed: %d\n", ret); 401 "HOST_SLEEP_ACTIVATE failed: %d\n",
402 ret);
386 } 403 }
387 404
388 if (!wait_event_interruptible_timeout( 405 if (!wait_event_interruptible_timeout(
389 priv->host_sleep_q, 406 priv->host_sleep_q,
390 priv->is_host_sleep_activated, 407 priv->is_host_sleep_activated,
391 (10 * HZ))) { 408 (10 * HZ))) {
392 lbs_pr_err("host_sleep_q: timer expired\n"); 409 netdev_err(priv->dev,
410 "host_sleep_q: timer expired\n");
393 ret = -1; 411 ret = -1;
394 } 412 }
395 } else { 413 } else {
396 lbs_pr_err("host sleep: already enabled\n"); 414 netdev_err(priv->dev, "host sleep: already enabled\n");
397 } 415 }
398 } else { 416 } else {
399 if (priv->is_host_sleep_activated) 417 if (priv->is_host_sleep_activated)
@@ -405,13 +423,13 @@ int lbs_set_host_sleep(struct lbs_private *priv, int host_sleep)
405} 423}
406 424
407/** 425/**
408 * @brief Set an SNMP MIB value 426 * lbs_set_snmp_mib - Set an SNMP MIB value
409 * 427 *
410 * @param priv A pointer to struct lbs_private structure 428 * @priv: A pointer to &struct lbs_private structure
411 * @param oid The OID to set in the firmware 429 * @oid: The OID to set in the firmware
412 * @param val Value to set the OID to 430 * @val: Value to set the OID to
413 * 431 *
414 * @return 0 on success, error on failure 432 * returns: 0 on success, error on failure
415 */ 433 */
416int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val) 434int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
417{ 435{
@@ -455,13 +473,13 @@ out:
455} 473}
456 474
457/** 475/**
458 * @brief Get an SNMP MIB value 476 * lbs_get_snmp_mib - Get an SNMP MIB value
459 * 477 *
460 * @param priv A pointer to struct lbs_private structure 478 * @priv: A pointer to &struct lbs_private structure
461 * @param oid The OID to retrieve from the firmware 479 * @oid: The OID to retrieve from the firmware
462 * @param out_val Location for the returned value 480 * @out_val: Location for the returned value
463 * 481 *
464 * @return 0 on success, error on failure 482 * returns: 0 on success, error on failure
465 */ 483 */
466int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val) 484int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
467{ 485{
@@ -498,14 +516,14 @@ out:
498} 516}
499 517
500/** 518/**
501 * @brief Get the min, max, and current TX power 519 * lbs_get_tx_power - Get the min, max, and current TX power
502 * 520 *
503 * @param priv A pointer to struct lbs_private structure 521 * @priv: A pointer to &struct lbs_private structure
504 * @param curlevel Current power level in dBm 522 * @curlevel: Current power level in dBm
505 * @param minlevel Minimum supported power level in dBm (optional) 523 * @minlevel: Minimum supported power level in dBm (optional)
506 * @param maxlevel Maximum supported power level in dBm (optional) 524 * @maxlevel: Maximum supported power level in dBm (optional)
507 * 525 *
508 * @return 0 on success, error on failure 526 * returns: 0 on success, error on failure
509 */ 527 */
510int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel, 528int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
511 s16 *maxlevel) 529 s16 *maxlevel)
@@ -533,12 +551,12 @@ int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
533} 551}
534 552
535/** 553/**
536 * @brief Set the TX power 554 * lbs_set_tx_power - Set the TX power
537 * 555 *
538 * @param priv A pointer to struct lbs_private structure 556 * @priv: A pointer to &struct lbs_private structure
539 * @param dbm The desired power level in dBm 557 * @dbm: The desired power level in dBm
540 * 558 *
541 * @return 0 on success, error on failure 559 * returns: 0 on success, error on failure
542 */ 560 */
543int lbs_set_tx_power(struct lbs_private *priv, s16 dbm) 561int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
544{ 562{
@@ -561,12 +579,13 @@ int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
561} 579}
562 580
563/** 581/**
564 * @brief Enable or disable monitor mode (only implemented on OLPC usb8388 FW) 582 * lbs_set_monitor_mode - Enable or disable monitor mode
583 * (only implemented on OLPC usb8388 FW)
565 * 584 *
566 * @param priv A pointer to struct lbs_private structure 585 * @priv: A pointer to &struct lbs_private structure
567 * @param enable 1 to enable monitor mode, 0 to disable 586 * @enable: 1 to enable monitor mode, 0 to disable
568 * 587 *
569 * @return 0 on success, error on failure 588 * returns: 0 on success, error on failure
570 */ 589 */
571int lbs_set_monitor_mode(struct lbs_private *priv, int enable) 590int lbs_set_monitor_mode(struct lbs_private *priv, int enable)
572{ 591{
@@ -592,11 +611,11 @@ int lbs_set_monitor_mode(struct lbs_private *priv, int enable)
592} 611}
593 612
594/** 613/**
595 * @brief Get the radio channel 614 * lbs_get_channel - Get the radio channel
596 * 615 *
597 * @param priv A pointer to struct lbs_private structure 616 * @priv: A pointer to &struct lbs_private structure
598 * 617 *
599 * @return The channel on success, error on failure 618 * returns: The channel on success, error on failure
600 */ 619 */
601static int lbs_get_channel(struct lbs_private *priv) 620static int lbs_get_channel(struct lbs_private *priv)
602{ 621{
@@ -638,12 +657,12 @@ int lbs_update_channel(struct lbs_private *priv)
638} 657}
639 658
640/** 659/**
641 * @brief Set the radio channel 660 * lbs_set_channel - Set the radio channel
642 * 661 *
643 * @param priv A pointer to struct lbs_private structure 662 * @priv: A pointer to &struct lbs_private structure
644 * @param channel The desired channel, or 0 to clear a locked channel 663 * @channel: The desired channel, or 0 to clear a locked channel
645 * 664 *
646 * @return 0 on success, error on failure 665 * returns: 0 on success, error on failure
647 */ 666 */
648int lbs_set_channel(struct lbs_private *priv, u8 channel) 667int lbs_set_channel(struct lbs_private *priv, u8 channel)
649{ 668{
@@ -674,12 +693,13 @@ out:
674} 693}
675 694
676/** 695/**
677 * @brief Get current RSSI and noise floor 696 * lbs_get_rssi - Get current RSSI and noise floor
678 * 697 *
679 * @param priv A pointer to struct lbs_private structure 698 * @priv: A pointer to &struct lbs_private structure
680 * @param rssi On successful return, signal level in mBm 699 * @rssi: On successful return, signal level in mBm
700 * @nf: On successful return, Noise floor
681 * 701 *
682 * @return The channel on success, error on failure 702 * returns: The channel on success, error on failure
683 */ 703 */
684int lbs_get_rssi(struct lbs_private *priv, s8 *rssi, s8 *nf) 704int lbs_get_rssi(struct lbs_private *priv, s8 *rssi, s8 *nf)
685{ 705{
@@ -707,13 +727,14 @@ int lbs_get_rssi(struct lbs_private *priv, s8 *rssi, s8 *nf)
707} 727}
708 728
709/** 729/**
710 * @brief Send regulatory and 802.11d domain information to the firmware 730 * lbs_set_11d_domain_info - Send regulatory and 802.11d domain information
731 * to the firmware
711 * 732 *
712 * @param priv pointer to struct lbs_private 733 * @priv: pointer to &struct lbs_private
713 * @param request cfg80211 regulatory request structure 734 * @request: cfg80211 regulatory request structure
714 * @param bands the device's supported bands and channels 735 * @bands: the device's supported bands and channels
715 * 736 *
716 * @return 0 on success, error code on failure 737 * returns: 0 on success, error code on failure
717*/ 738*/
718int lbs_set_11d_domain_info(struct lbs_private *priv, 739int lbs_set_11d_domain_info(struct lbs_private *priv,
719 struct regulatory_request *request, 740 struct regulatory_request *request,
@@ -830,15 +851,15 @@ int lbs_set_11d_domain_info(struct lbs_private *priv,
830} 851}
831 852
832/** 853/**
833 * @brief Read a MAC, Baseband, or RF register 854 * lbs_get_reg - Read a MAC, Baseband, or RF register
834 * 855 *
835 * @param priv pointer to struct lbs_private 856 * @priv: pointer to &struct lbs_private
836 * @param cmd register command, one of CMD_MAC_REG_ACCESS, 857 * @reg: register command, one of CMD_MAC_REG_ACCESS,
837 * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS 858 * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS
838 * @param offset byte offset of the register to get 859 * @offset: byte offset of the register to get
839 * @param value on success, the value of the register at 'offset' 860 * @value: on success, the value of the register at 'offset'
840 * 861 *
841 * @return 0 on success, error code on failure 862 * returns: 0 on success, error code on failure
842*/ 863*/
843int lbs_get_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 *value) 864int lbs_get_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 *value)
844{ 865{
@@ -874,15 +895,15 @@ out:
874} 895}
875 896
876/** 897/**
877 * @brief Write a MAC, Baseband, or RF register 898 * lbs_set_reg - Write a MAC, Baseband, or RF register
878 * 899 *
879 * @param priv pointer to struct lbs_private 900 * @priv: pointer to &struct lbs_private
880 * @param cmd register command, one of CMD_MAC_REG_ACCESS, 901 * @reg: register command, one of CMD_MAC_REG_ACCESS,
881 * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS 902 * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS
882 * @param offset byte offset of the register to set 903 * @offset: byte offset of the register to set
883 * @param value the value to write to the register at 'offset' 904 * @value: the value to write to the register at 'offset'
884 * 905 *
885 * @return 0 on success, error code on failure 906 * returns: 0 on success, error code on failure
886*/ 907*/
887int lbs_set_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 value) 908int lbs_set_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 value)
888{ 909{
@@ -973,6 +994,8 @@ static void lbs_submit_command(struct lbs_private *priv,
973 cmd = cmdnode->cmdbuf; 994 cmd = cmdnode->cmdbuf;
974 995
975 spin_lock_irqsave(&priv->driver_lock, flags); 996 spin_lock_irqsave(&priv->driver_lock, flags);
997 priv->seqnum++;
998 cmd->seqnum = cpu_to_le16(priv->seqnum);
976 priv->cur_cmd = cmdnode; 999 priv->cur_cmd = cmdnode;
977 spin_unlock_irqrestore(&priv->driver_lock, flags); 1000 spin_unlock_irqrestore(&priv->driver_lock, flags);
978 1001
@@ -990,7 +1013,8 @@ static void lbs_submit_command(struct lbs_private *priv,
990 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize); 1013 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
991 1014
992 if (ret) { 1015 if (ret) {
993 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret); 1016 netdev_info(priv->dev, "DNLD_CMD: hw_host_to_card failed: %d\n",
1017 ret);
994 /* Let the timer kick in and retry, and potentially reset 1018 /* Let the timer kick in and retry, and potentially reset
995 the whole thing if the condition persists */ 1019 the whole thing if the condition persists */
996 timeo = HZ/4; 1020 timeo = HZ/4;
@@ -1011,7 +1035,7 @@ static void lbs_submit_command(struct lbs_private *priv,
1011 lbs_deb_leave(LBS_DEB_HOST); 1035 lbs_deb_leave(LBS_DEB_HOST);
1012} 1036}
1013 1037
1014/** 1038/*
1015 * This function inserts command node to cmdfreeq 1039 * This function inserts command node to cmdfreeq
1016 * after cleans it. Requires priv->driver_lock held. 1040 * after cleans it. Requires priv->driver_lock held.
1017 */ 1041 */
@@ -1113,11 +1137,12 @@ void lbs_set_mac_control(struct lbs_private *priv)
1113} 1137}
1114 1138
1115/** 1139/**
1116 * @brief This function allocates the command buffer and link 1140 * lbs_allocate_cmd_buffer - allocates the command buffer and links
1117 * it to command free queue. 1141 * it to command free queue
1118 * 1142 *
1119 * @param priv A pointer to struct lbs_private structure 1143 * @priv: A pointer to &struct lbs_private structure
1120 * @return 0 or -1 1144 *
1145 * returns: 0 for success or -1 on error
1121 */ 1146 */
1122int lbs_allocate_cmd_buffer(struct lbs_private *priv) 1147int lbs_allocate_cmd_buffer(struct lbs_private *priv)
1123{ 1148{
@@ -1159,10 +1184,11 @@ done:
1159} 1184}
1160 1185
1161/** 1186/**
1162 * @brief This function frees the command buffer. 1187 * lbs_free_cmd_buffer - free the command buffer
1188 *
1189 * @priv: A pointer to &struct lbs_private structure
1163 * 1190 *
1164 * @param priv A pointer to struct lbs_private structure 1191 * returns: 0 for success
1165 * @return 0 or -1
1166 */ 1192 */
1167int lbs_free_cmd_buffer(struct lbs_private *priv) 1193int lbs_free_cmd_buffer(struct lbs_private *priv)
1168{ 1194{
@@ -1199,11 +1225,13 @@ done:
1199} 1225}
1200 1226
1201/** 1227/**
1202 * @brief This function gets a free command node if available in 1228 * lbs_get_free_cmd_node - gets a free command node if available in
1203 * command free queue. 1229 * command free queue
1204 * 1230 *
1205 * @param priv A pointer to struct lbs_private structure 1231 * @priv: A pointer to &struct lbs_private structure
1206 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL 1232 *
1233 * returns: A pointer to &cmd_ctrl_node structure on success
1234 * or %NULL on error
1207 */ 1235 */
1208static struct cmd_ctrl_node *lbs_get_free_cmd_node(struct lbs_private *priv) 1236static struct cmd_ctrl_node *lbs_get_free_cmd_node(struct lbs_private *priv)
1209{ 1237{
@@ -1233,12 +1261,12 @@ static struct cmd_ctrl_node *lbs_get_free_cmd_node(struct lbs_private *priv)
1233} 1261}
1234 1262
1235/** 1263/**
1236 * @brief This function executes next command in command 1264 * lbs_execute_next_command - execute next command in command
1237 * pending queue. It will put firmware back to PS mode 1265 * pending queue. Will put firmware back to PS mode if applicable.
1238 * if applicable. 1266 *
1267 * @priv: A pointer to &struct lbs_private structure
1239 * 1268 *
1240 * @param priv A pointer to struct lbs_private structure 1269 * returns: 0 on success or -1 on error
1241 * @return 0 or -1
1242 */ 1270 */
1243int lbs_execute_next_command(struct lbs_private *priv) 1271int lbs_execute_next_command(struct lbs_private *priv)
1244{ 1272{
@@ -1255,7 +1283,8 @@ int lbs_execute_next_command(struct lbs_private *priv)
1255 spin_lock_irqsave(&priv->driver_lock, flags); 1283 spin_lock_irqsave(&priv->driver_lock, flags);
1256 1284
1257 if (priv->cur_cmd) { 1285 if (priv->cur_cmd) {
1258 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n"); 1286 netdev_alert(priv->dev,
1287 "EXEC_NEXT_CMD: already processing command!\n");
1259 spin_unlock_irqrestore(&priv->driver_lock, flags); 1288 spin_unlock_irqrestore(&priv->driver_lock, flags);
1260 ret = -1; 1289 ret = -1;
1261 goto done; 1290 goto done;
@@ -1327,8 +1356,8 @@ int lbs_execute_next_command(struct lbs_private *priv)
1327 cpu_to_le16(PS_MODE_ACTION_EXIT_PS)) { 1356 cpu_to_le16(PS_MODE_ACTION_EXIT_PS)) {
1328 lbs_deb_host( 1357 lbs_deb_host(
1329 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n"); 1358 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1330 list_del(&cmdnode->list);
1331 spin_lock_irqsave(&priv->driver_lock, flags); 1359 spin_lock_irqsave(&priv->driver_lock, flags);
1360 list_del(&cmdnode->list);
1332 lbs_complete_command(priv, cmdnode, 0); 1361 lbs_complete_command(priv, cmdnode, 0);
1333 spin_unlock_irqrestore(&priv->driver_lock, flags); 1362 spin_unlock_irqrestore(&priv->driver_lock, flags);
1334 1363
@@ -1340,8 +1369,8 @@ int lbs_execute_next_command(struct lbs_private *priv)
1340 (priv->psstate == PS_STATE_PRE_SLEEP)) { 1369 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1341 lbs_deb_host( 1370 lbs_deb_host(
1342 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n"); 1371 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1343 list_del(&cmdnode->list);
1344 spin_lock_irqsave(&priv->driver_lock, flags); 1372 spin_lock_irqsave(&priv->driver_lock, flags);
1373 list_del(&cmdnode->list);
1345 lbs_complete_command(priv, cmdnode, 0); 1374 lbs_complete_command(priv, cmdnode, 0);
1346 spin_unlock_irqrestore(&priv->driver_lock, flags); 1375 spin_unlock_irqrestore(&priv->driver_lock, flags);
1347 priv->needtowakeup = 1; 1376 priv->needtowakeup = 1;
@@ -1354,7 +1383,9 @@ int lbs_execute_next_command(struct lbs_private *priv)
1354 "EXEC_NEXT_CMD: sending EXIT_PS\n"); 1383 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1355 } 1384 }
1356 } 1385 }
1386 spin_lock_irqsave(&priv->driver_lock, flags);
1357 list_del(&cmdnode->list); 1387 list_del(&cmdnode->list);
1388 spin_unlock_irqrestore(&priv->driver_lock, flags);
1358 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n", 1389 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1359 le16_to_cpu(cmd->command)); 1390 le16_to_cpu(cmd->command));
1360 lbs_submit_command(priv, cmdnode); 1391 lbs_submit_command(priv, cmdnode);
@@ -1417,7 +1448,7 @@ static void lbs_send_confirmsleep(struct lbs_private *priv)
1417 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep, 1448 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1418 sizeof(confirm_sleep)); 1449 sizeof(confirm_sleep));
1419 if (ret) { 1450 if (ret) {
1420 lbs_pr_alert("confirm_sleep failed\n"); 1451 netdev_alert(priv->dev, "confirm_sleep failed\n");
1421 goto out; 1452 goto out;
1422 } 1453 }
1423 1454
@@ -1442,12 +1473,12 @@ out:
1442} 1473}
1443 1474
1444/** 1475/**
1445 * @brief This function checks condition and prepares to 1476 * lbs_ps_confirm_sleep - checks condition and prepares to
1446 * send sleep confirm command to firmware if ok. 1477 * send sleep confirm command to firmware if ok
1447 * 1478 *
1448 * @param priv A pointer to struct lbs_private structure 1479 * @priv: A pointer to &struct lbs_private structure
1449 * @param psmode Power Saving mode 1480 *
1450 * @return n/a 1481 * returns: n/a
1451 */ 1482 */
1452void lbs_ps_confirm_sleep(struct lbs_private *priv) 1483void lbs_ps_confirm_sleep(struct lbs_private *priv)
1453{ 1484{
@@ -1487,16 +1518,16 @@ void lbs_ps_confirm_sleep(struct lbs_private *priv)
1487 1518
1488 1519
1489/** 1520/**
1490 * @brief Configures the transmission power control functionality. 1521 * lbs_set_tpc_cfg - Configures the transmission power control functionality
1491 * 1522 *
1492 * @param priv A pointer to struct lbs_private structure 1523 * @priv: A pointer to &struct lbs_private structure
1493 * @param enable Transmission power control enable 1524 * @enable: Transmission power control enable
1494 * @param p0 Power level when link quality is good (dBm). 1525 * @p0: Power level when link quality is good (dBm).
1495 * @param p1 Power level when link quality is fair (dBm). 1526 * @p1: Power level when link quality is fair (dBm).
1496 * @param p2 Power level when link quality is poor (dBm). 1527 * @p2: Power level when link quality is poor (dBm).
1497 * @param usesnr Use Signal to Noise Ratio in TPC 1528 * @usesnr: Use Signal to Noise Ratio in TPC
1498 * 1529 *
1499 * @return 0 on success 1530 * returns: 0 on success
1500 */ 1531 */
1501int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1, 1532int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1502 int8_t p2, int usesnr) 1533 int8_t p2, int usesnr)
@@ -1519,15 +1550,15 @@ int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1519} 1550}
1520 1551
1521/** 1552/**
1522 * @brief Configures the power adaptation settings. 1553 * lbs_set_power_adapt_cfg - Configures the power adaptation settings
1523 * 1554 *
1524 * @param priv A pointer to struct lbs_private structure 1555 * @priv: A pointer to &struct lbs_private structure
1525 * @param enable Power adaptation enable 1556 * @enable: Power adaptation enable
1526 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm). 1557 * @p0: Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1527 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm). 1558 * @p1: Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1528 * @param p2 Power level for 48 and 54 Mbps (dBm). 1559 * @p2: Power level for 48 and 54 Mbps (dBm).
1529 * 1560 *
1530 * @return 0 on Success 1561 * returns: 0 on Success
1531 */ 1562 */
1532 1563
1533int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0, 1564int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
@@ -1592,11 +1623,9 @@ struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
1592 /* Copy the incoming command to the buffer */ 1623 /* Copy the incoming command to the buffer */
1593 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size); 1624 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
1594 1625
1595 /* Set sequence number, clean result, move to buffer */ 1626 /* Set command, clean result, move to buffer */
1596 priv->seqnum++;
1597 cmdnode->cmdbuf->command = cpu_to_le16(command); 1627 cmdnode->cmdbuf->command = cpu_to_le16(command);
1598 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size); 1628 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
1599 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
1600 cmdnode->cmdbuf->result = 0; 1629 cmdnode->cmdbuf->result = 0;
1601 1630
1602 lbs_deb_host("PREP_CMD: command 0x%04x\n", command); 1631 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
@@ -1643,7 +1672,7 @@ int __lbs_cmd(struct lbs_private *priv, uint16_t command,
1643 spin_lock_irqsave(&priv->driver_lock, flags); 1672 spin_lock_irqsave(&priv->driver_lock, flags);
1644 ret = cmdnode->result; 1673 ret = cmdnode->result;
1645 if (ret) 1674 if (ret)
1646 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n", 1675 netdev_info(priv->dev, "PREP_CMD: command 0x%04x failed: %d\n",
1647 command, ret); 1676 command, ret);
1648 1677
1649 __lbs_cleanup_and_insert_cmd(priv, cmdnode); 1678 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
diff --git a/drivers/net/wireless/libertas/cmdresp.c b/drivers/net/wireless/libertas/cmdresp.c
index 5e95da9dcc2e..207fc361db84 100644
--- a/drivers/net/wireless/libertas/cmdresp.c
+++ b/drivers/net/wireless/libertas/cmdresp.c
@@ -1,7 +1,8 @@
1/** 1/*
2 * This file contains the handling of command 2 * This file contains the handling of command
3 * responses as well as events generated by firmware. 3 * responses as well as events generated by firmware.
4 */ 4 */
5
5#include <linux/slab.h> 6#include <linux/slab.h>
6#include <linux/delay.h> 7#include <linux/delay.h>
7#include <linux/sched.h> 8#include <linux/sched.h>
@@ -12,12 +13,13 @@
12#include "cmd.h" 13#include "cmd.h"
13 14
14/** 15/**
15 * @brief This function handles disconnect event. it 16 * lbs_mac_event_disconnected - handles disconnect event. It
16 * reports disconnect to upper layer, clean tx/rx packets, 17 * reports disconnect to upper layer, clean tx/rx packets,
17 * reset link state etc. 18 * reset link state etc.
19 *
20 * @priv: A pointer to struct lbs_private structure
18 * 21 *
19 * @param priv A pointer to struct lbs_private structure 22 * returns: n/a
20 * @return n/a
21 */ 23 */
22void lbs_mac_event_disconnected(struct lbs_private *priv) 24void lbs_mac_event_disconnected(struct lbs_private *priv)
23{ 25{
@@ -84,15 +86,18 @@ int lbs_process_command_response(struct lbs_private *priv, u8 *data, u32 len)
84 lbs_deb_hex(LBS_DEB_CMD, "CMD_RESP", (void *) resp, len); 86 lbs_deb_hex(LBS_DEB_CMD, "CMD_RESP", (void *) resp, len);
85 87
86 if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) { 88 if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) {
87 lbs_pr_info("Received CMD_RESP with invalid sequence %d (expected %d)\n", 89 netdev_info(priv->dev,
88 le16_to_cpu(resp->seqnum), le16_to_cpu(priv->cur_cmd->cmdbuf->seqnum)); 90 "Received CMD_RESP with invalid sequence %d (expected %d)\n",
91 le16_to_cpu(resp->seqnum),
92 le16_to_cpu(priv->cur_cmd->cmdbuf->seqnum));
89 spin_unlock_irqrestore(&priv->driver_lock, flags); 93 spin_unlock_irqrestore(&priv->driver_lock, flags);
90 ret = -1; 94 ret = -1;
91 goto done; 95 goto done;
92 } 96 }
93 if (respcmd != CMD_RET(curcmd) && 97 if (respcmd != CMD_RET(curcmd) &&
94 respcmd != CMD_RET_802_11_ASSOCIATE && curcmd != CMD_802_11_ASSOCIATE) { 98 respcmd != CMD_RET_802_11_ASSOCIATE && curcmd != CMD_802_11_ASSOCIATE) {
95 lbs_pr_info("Invalid CMD_RESP %x to command %x!\n", respcmd, curcmd); 99 netdev_info(priv->dev, "Invalid CMD_RESP %x to command %x!\n",
100 respcmd, curcmd);
96 spin_unlock_irqrestore(&priv->driver_lock, flags); 101 spin_unlock_irqrestore(&priv->driver_lock, flags);
97 ret = -1; 102 ret = -1;
98 goto done; 103 goto done;
@@ -101,7 +106,8 @@ int lbs_process_command_response(struct lbs_private *priv, u8 *data, u32 len)
101 if (resp->result == cpu_to_le16(0x0004)) { 106 if (resp->result == cpu_to_le16(0x0004)) {
102 /* 0x0004 means -EAGAIN. Drop the response, let it time out 107 /* 0x0004 means -EAGAIN. Drop the response, let it time out
103 and be resubmitted */ 108 and be resubmitted */
104 lbs_pr_info("Firmware returns DEFER to command %x. Will let it time out...\n", 109 netdev_info(priv->dev,
110 "Firmware returns DEFER to command %x. Will let it time out...\n",
105 le16_to_cpu(resp->command)); 111 le16_to_cpu(resp->command));
106 spin_unlock_irqrestore(&priv->driver_lock, flags); 112 spin_unlock_irqrestore(&priv->driver_lock, flags);
107 ret = -1; 113 ret = -1;
@@ -313,28 +319,28 @@ int lbs_process_event(struct lbs_private *priv, u32 event)
313 lbs_deb_cmd("EVENT: ADHOC beacon lost\n"); 319 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
314 break; 320 break;
315 case MACREG_INT_CODE_RSSI_LOW: 321 case MACREG_INT_CODE_RSSI_LOW:
316 lbs_pr_alert("EVENT: rssi low\n"); 322 netdev_alert(priv->dev, "EVENT: rssi low\n");
317 break; 323 break;
318 case MACREG_INT_CODE_SNR_LOW: 324 case MACREG_INT_CODE_SNR_LOW:
319 lbs_pr_alert("EVENT: snr low\n"); 325 netdev_alert(priv->dev, "EVENT: snr low\n");
320 break; 326 break;
321 case MACREG_INT_CODE_MAX_FAIL: 327 case MACREG_INT_CODE_MAX_FAIL:
322 lbs_pr_alert("EVENT: max fail\n"); 328 netdev_alert(priv->dev, "EVENT: max fail\n");
323 break; 329 break;
324 case MACREG_INT_CODE_RSSI_HIGH: 330 case MACREG_INT_CODE_RSSI_HIGH:
325 lbs_pr_alert("EVENT: rssi high\n"); 331 netdev_alert(priv->dev, "EVENT: rssi high\n");
326 break; 332 break;
327 case MACREG_INT_CODE_SNR_HIGH: 333 case MACREG_INT_CODE_SNR_HIGH:
328 lbs_pr_alert("EVENT: snr high\n"); 334 netdev_alert(priv->dev, "EVENT: snr high\n");
329 break; 335 break;
330 336
331 case MACREG_INT_CODE_MESH_AUTO_STARTED: 337 case MACREG_INT_CODE_MESH_AUTO_STARTED:
332 /* Ignore spurious autostart events */ 338 /* Ignore spurious autostart events */
333 lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n"); 339 netdev_info(priv->dev, "EVENT: MESH_AUTO_STARTED (ignoring)\n");
334 break; 340 break;
335 341
336 default: 342 default:
337 lbs_pr_alert("EVENT: unknown event id %d\n", event); 343 netdev_alert(priv->dev, "EVENT: unknown event id %d\n", event);
338 break; 344 break;
339 } 345 }
340 346
diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
index 651a79c8de8a..23250f621761 100644
--- a/drivers/net/wireless/libertas/debugfs.c
+++ b/drivers/net/wireless/libertas/debugfs.c
@@ -151,13 +151,14 @@ static ssize_t lbs_host_sleep_write(struct file *file,
151 ret = lbs_set_host_sleep(priv, 0); 151 ret = lbs_set_host_sleep(priv, 0);
152 else if (host_sleep == 1) { 152 else if (host_sleep == 1) {
153 if (priv->wol_criteria == EHS_REMOVE_WAKEUP) { 153 if (priv->wol_criteria == EHS_REMOVE_WAKEUP) {
154 lbs_pr_info("wake parameters not configured"); 154 netdev_info(priv->dev,
155 "wake parameters not configured\n");
155 ret = -EINVAL; 156 ret = -EINVAL;
156 goto out_unlock; 157 goto out_unlock;
157 } 158 }
158 ret = lbs_set_host_sleep(priv, 1); 159 ret = lbs_set_host_sleep(priv, 1);
159 } else { 160 } else {
160 lbs_pr_err("invalid option\n"); 161 netdev_err(priv->dev, "invalid option\n");
161 ret = -EINVAL; 162 ret = -EINVAL;
162 } 163 }
163 164
@@ -696,6 +697,7 @@ out_unlock:
696 .open = open_file_generic, \ 697 .open = open_file_generic, \
697 .read = (fread), \ 698 .read = (fread), \
698 .write = (fwrite), \ 699 .write = (fwrite), \
700 .llseek = generic_file_llseek, \
699} 701}
700 702
701struct lbs_debugfs_files { 703struct lbs_debugfs_files {
@@ -848,15 +850,14 @@ static struct debug_data items[] = {
848static int num_of_items = ARRAY_SIZE(items); 850static int num_of_items = ARRAY_SIZE(items);
849 851
850/** 852/**
851 * @brief proc read function 853 * lbs_debugfs_read - proc read function
852 * 854 *
853 * @param page pointer to buffer 855 * @file: file to read
854 * @param s read data starting position 856 * @userbuf: pointer to buffer
855 * @param off offset 857 * @count: number of bytes to read
856 * @param cnt counter 858 * @ppos: read data starting position
857 * @param eof end of file flag 859 *
858 * @param data data to output 860 * returns: amount of data read or negative error code
859 * @return number of output data
860 */ 861 */
861static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf, 862static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
862 size_t count, loff_t *ppos) 863 size_t count, loff_t *ppos)
@@ -896,13 +897,14 @@ static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
896} 897}
897 898
898/** 899/**
899 * @brief proc write function 900 * lbs_debugfs_write - proc write function
901 *
902 * @f: file pointer
903 * @buf: pointer to data buffer
904 * @cnt: data number to write
905 * @ppos: file position
900 * 906 *
901 * @param f file pointer 907 * returns: amount of data written
902 * @param buf pointer to data buffer
903 * @param cnt data number to write
904 * @param data data to write
905 * @return number of data
906 */ 908 */
907static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf, 909static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
908 size_t cnt, loff_t *ppos) 910 size_t cnt, loff_t *ppos)
@@ -961,14 +963,15 @@ static const struct file_operations lbs_debug_fops = {
961 .open = open_file_generic, 963 .open = open_file_generic,
962 .write = lbs_debugfs_write, 964 .write = lbs_debugfs_write,
963 .read = lbs_debugfs_read, 965 .read = lbs_debugfs_read,
966 .llseek = default_llseek,
964}; 967};
965 968
966/** 969/**
967 * @brief create debug proc file 970 * lbs_debug_init - create debug proc file
971 *
972 * @priv: pointer to &struct lbs_private
968 * 973 *
969 * @param priv pointer struct lbs_private 974 * returns: N/A
970 * @param dev pointer net_device
971 * @return N/A
972 */ 975 */
973static void lbs_debug_init(struct lbs_private *priv) 976static void lbs_debug_init(struct lbs_private *priv)
974{ 977{
diff --git a/drivers/net/wireless/libertas/decl.h b/drivers/net/wireless/libertas/decl.h
index 1d141fefd767..da0b05bb89fe 100644
--- a/drivers/net/wireless/libertas/decl.h
+++ b/drivers/net/wireless/libertas/decl.h
@@ -1,14 +1,21 @@
1 1
2/** 2/*
3 * This file contains declaration referring to 3 * This file contains declaration referring to
4 * functions defined in other source files 4 * functions defined in other source files
5 */ 5 */
6 6
7#ifndef _LBS_DECL_H_ 7#ifndef _LBS_DECL_H_
8#define _LBS_DECL_H_ 8#define _LBS_DECL_H_
9 9
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <linux/firmware.h>
11 12
13/* Should be terminated by a NULL entry */
14struct lbs_fw_table {
15 int model;
16 const char *helper;
17 const char *fwname;
18};
12 19
13struct lbs_private; 20struct lbs_private;
14struct sk_buff; 21struct sk_buff;
@@ -53,4 +60,10 @@ int lbs_exit_auto_deep_sleep(struct lbs_private *priv);
53u32 lbs_fw_index_to_data_rate(u8 index); 60u32 lbs_fw_index_to_data_rate(u8 index);
54u8 lbs_data_rate_to_fw_index(u32 rate); 61u8 lbs_data_rate_to_fw_index(u32 rate);
55 62
63int lbs_get_firmware(struct device *dev, const char *user_helper,
64 const char *user_mainfw, u32 card_model,
65 const struct lbs_fw_table *fw_table,
66 const struct firmware **helper,
67 const struct firmware **mainfw);
68
56#endif 69#endif
diff --git a/drivers/net/wireless/libertas/defs.h b/drivers/net/wireless/libertas/defs.h
index d00c728cec47..ab966f08024a 100644
--- a/drivers/net/wireless/libertas/defs.h
+++ b/drivers/net/wireless/libertas/defs.h
@@ -1,7 +1,7 @@
1/** 1/*
2 * This header file contains global constant/enum definitions, 2 * This header file contains global constant/enum definitions,
3 * global variable declaration. 3 * global variable declaration.
4 */ 4 */
5#ifndef _LBS_DEFS_H_ 5#ifndef _LBS_DEFS_H_
6#define _LBS_DEFS_H_ 6#define _LBS_DEFS_H_
7 7
@@ -89,13 +89,6 @@ do { if ((lbs_debug & (grp)) == (grp)) \
89#define lbs_deb_spi(fmt, args...) LBS_DEB_LL(LBS_DEB_SPI, " spi", fmt, ##args) 89#define lbs_deb_spi(fmt, args...) LBS_DEB_LL(LBS_DEB_SPI, " spi", fmt, ##args)
90#define lbs_deb_cfg80211(fmt, args...) LBS_DEB_LL(LBS_DEB_CFG80211, " cfg80211", fmt, ##args) 90#define lbs_deb_cfg80211(fmt, args...) LBS_DEB_LL(LBS_DEB_CFG80211, " cfg80211", fmt, ##args)
91 91
92#define lbs_pr_info(format, args...) \
93 printk(KERN_INFO DRV_NAME": " format, ## args)
94#define lbs_pr_err(format, args...) \
95 printk(KERN_ERR DRV_NAME": " format, ## args)
96#define lbs_pr_alert(format, args...) \
97 printk(KERN_ALERT DRV_NAME": " format, ## args)
98
99#ifdef DEBUG 92#ifdef DEBUG
100static inline void lbs_deb_hex(unsigned int grp, const char *prompt, u8 *buf, int len) 93static inline void lbs_deb_hex(unsigned int grp, const char *prompt, u8 *buf, int len)
101{ 94{
@@ -123,19 +116,19 @@ static inline void lbs_deb_hex(unsigned int grp, const char *prompt, u8 *buf, in
123 116
124 117
125 118
126/** Buffer Constants */ 119/* Buffer Constants */
127 120
128/* The size of SQ memory PPA, DPA are 8 DWORDs, that keep the physical 121/* The size of SQ memory PPA, DPA are 8 DWORDs, that keep the physical
129* addresses of TxPD buffers. Station has only 8 TxPD available, Whereas 122 * addresses of TxPD buffers. Station has only 8 TxPD available, Whereas
130* driver has more local TxPDs. Each TxPD on the host memory is associated 123 * driver has more local TxPDs. Each TxPD on the host memory is associated
131* with a Tx control node. The driver maintains 8 RxPD descriptors for 124 * with a Tx control node. The driver maintains 8 RxPD descriptors for
132* station firmware to store Rx packet information. 125 * station firmware to store Rx packet information.
133* 126 *
134* Current version of MAC has a 32x6 multicast address buffer. 127 * Current version of MAC has a 32x6 multicast address buffer.
135* 128 *
136* 802.11b can have up to 14 channels, the driver keeps the 129 * 802.11b can have up to 14 channels, the driver keeps the
137* BSSID(MAC address) of each APs or Ad hoc stations it has sensed. 130 * BSSID(MAC address) of each APs or Ad hoc stations it has sensed.
138*/ 131 */
139 132
140#define MRVDRV_MAX_MULTICAST_LIST_SIZE 32 133#define MRVDRV_MAX_MULTICAST_LIST_SIZE 32
141#define LBS_NUM_CMD_BUFFERS 10 134#define LBS_NUM_CMD_BUFFERS 10
@@ -166,7 +159,7 @@ static inline void lbs_deb_hex(unsigned int grp, const char *prompt, u8 *buf, in
166#define WOL_RESULT_NOSPC_ERR 1 159#define WOL_RESULT_NOSPC_ERR 1
167#define WOL_RESULT_EEXIST_ERR 2 160#define WOL_RESULT_EEXIST_ERR 2
168 161
169/** Misc constants */ 162/* Misc constants */
170/* This section defines 802.11 specific contants */ 163/* This section defines 802.11 specific contants */
171 164
172#define MRVDRV_MAX_BSS_DESCRIPTS 16 165#define MRVDRV_MAX_BSS_DESCRIPTS 16
@@ -183,7 +176,8 @@ static inline void lbs_deb_hex(unsigned int grp, const char *prompt, u8 *buf, in
183 176
184#define MARVELL_MESH_IE_LENGTH 9 177#define MARVELL_MESH_IE_LENGTH 9
185 178
186/* Values used to populate the struct mrvl_mesh_ie. The only time you need this 179/*
180 * Values used to populate the struct mrvl_mesh_ie. The only time you need this
187 * is when enabling the mesh using CMD_MESH_CONFIG. 181 * is when enabling the mesh using CMD_MESH_CONFIG.
188 */ 182 */
189#define MARVELL_MESH_IE_TYPE 4 183#define MARVELL_MESH_IE_TYPE 4
@@ -193,7 +187,7 @@ static inline void lbs_deb_hex(unsigned int grp, const char *prompt, u8 *buf, in
193#define MARVELL_MESH_METRIC_ID 0 187#define MARVELL_MESH_METRIC_ID 0
194#define MARVELL_MESH_CAPABILITY 0 188#define MARVELL_MESH_CAPABILITY 0
195 189
196/** INT status Bit Definition*/ 190/* INT status Bit Definition */
197#define MRVDRV_TX_DNLD_RDY 0x0001 191#define MRVDRV_TX_DNLD_RDY 0x0001
198#define MRVDRV_RX_UPLD_RDY 0x0002 192#define MRVDRV_RX_UPLD_RDY 0x0002
199#define MRVDRV_CMD_DNLD_RDY 0x0004 193#define MRVDRV_CMD_DNLD_RDY 0x0004
@@ -208,59 +202,63 @@ static inline void lbs_deb_hex(unsigned int grp, const char *prompt, u8 *buf, in
208#define TPC_DEFAULT_P1 10 202#define TPC_DEFAULT_P1 10
209#define TPC_DEFAULT_P2 13 203#define TPC_DEFAULT_P2 13
210 204
211/** TxPD status */ 205/* TxPD status */
212 206
213/* Station firmware use TxPD status field to report final Tx transmit 207/*
214* result, Bit masks are used to present combined situations. 208 * Station firmware use TxPD status field to report final Tx transmit
215*/ 209 * result, Bit masks are used to present combined situations.
210 */
216 211
217#define MRVDRV_TxPD_POWER_MGMT_NULL_PACKET 0x01 212#define MRVDRV_TxPD_POWER_MGMT_NULL_PACKET 0x01
218#define MRVDRV_TxPD_POWER_MGMT_LAST_PACKET 0x08 213#define MRVDRV_TxPD_POWER_MGMT_LAST_PACKET 0x08
219 214
220/** Tx mesh flag */ 215/* Tx mesh flag */
221/* Currently we are using normal WDS flag as mesh flag. 216/*
217 * Currently we are using normal WDS flag as mesh flag.
222 * TODO: change to proper mesh flag when MAC understands it. 218 * TODO: change to proper mesh flag when MAC understands it.
223 */ 219 */
224#define TxPD_CONTROL_WDS_FRAME (1<<17) 220#define TxPD_CONTROL_WDS_FRAME (1<<17)
225#define TxPD_MESH_FRAME TxPD_CONTROL_WDS_FRAME 221#define TxPD_MESH_FRAME TxPD_CONTROL_WDS_FRAME
226 222
227/** Mesh interface ID */ 223/* Mesh interface ID */
228#define MESH_IFACE_ID 0x0001 224#define MESH_IFACE_ID 0x0001
229/** Mesh id should be in bits 14-13-12 */ 225/* Mesh id should be in bits 14-13-12 */
230#define MESH_IFACE_BIT_OFFSET 0x000c 226#define MESH_IFACE_BIT_OFFSET 0x000c
231/** Mesh enable bit in FW capability */ 227/* Mesh enable bit in FW capability */
232#define MESH_CAPINFO_ENABLE_MASK (1<<16) 228#define MESH_CAPINFO_ENABLE_MASK (1<<16)
233 229
234/** FW definition from Marvell v4 */ 230/* FW definition from Marvell v4 */
235#define MRVL_FW_V4 (0x04) 231#define MRVL_FW_V4 (0x04)
236/** FW definition from Marvell v5 */ 232/* FW definition from Marvell v5 */
237#define MRVL_FW_V5 (0x05) 233#define MRVL_FW_V5 (0x05)
238/** FW definition from Marvell v10 */ 234/* FW definition from Marvell v10 */
239#define MRVL_FW_V10 (0x0a) 235#define MRVL_FW_V10 (0x0a)
240/** FW major revision definition */ 236/* FW major revision definition */
241#define MRVL_FW_MAJOR_REV(x) ((x)>>24) 237#define MRVL_FW_MAJOR_REV(x) ((x)>>24)
242 238
243/** RxPD status */ 239/* RxPD status */
244 240
245#define MRVDRV_RXPD_STATUS_OK 0x0001 241#define MRVDRV_RXPD_STATUS_OK 0x0001
246 242
247/** RxPD status - Received packet types */ 243/* RxPD status - Received packet types */
248/** Rx mesh flag */ 244/* Rx mesh flag */
249/* Currently we are using normal WDS flag as mesh flag. 245/*
246 * Currently we are using normal WDS flag as mesh flag.
250 * TODO: change to proper mesh flag when MAC understands it. 247 * TODO: change to proper mesh flag when MAC understands it.
251 */ 248 */
252#define RxPD_CONTROL_WDS_FRAME (0x40) 249#define RxPD_CONTROL_WDS_FRAME (0x40)
253#define RxPD_MESH_FRAME RxPD_CONTROL_WDS_FRAME 250#define RxPD_MESH_FRAME RxPD_CONTROL_WDS_FRAME
254 251
255/** RSSI-related defines */ 252/* RSSI-related defines */
256/* RSSI constants are used to implement 802.11 RSSI threshold 253/*
257* indication. if the Rx packet signal got too weak for 5 consecutive 254 * RSSI constants are used to implement 802.11 RSSI threshold
258* times, miniport driver (driver) will report this event to wrapper 255 * indication. if the Rx packet signal got too weak for 5 consecutive
259*/ 256 * times, miniport driver (driver) will report this event to wrapper
257 */
260 258
261#define MRVDRV_NF_DEFAULT_SCAN_VALUE (-96) 259#define MRVDRV_NF_DEFAULT_SCAN_VALUE (-96)
262 260
263/** RTS/FRAG related defines */ 261/* RTS/FRAG related defines */
264#define MRVDRV_RTS_MIN_VALUE 0 262#define MRVDRV_RTS_MIN_VALUE 0
265#define MRVDRV_RTS_MAX_VALUE 2347 263#define MRVDRV_RTS_MAX_VALUE 2347
266#define MRVDRV_FRAG_MIN_VALUE 256 264#define MRVDRV_FRAG_MIN_VALUE 256
@@ -300,36 +298,36 @@ static inline void lbs_deb_hex(unsigned int grp, const char *prompt, u8 *buf, in
300 298
301#define MAX_LEDS 8 299#define MAX_LEDS 8
302 300
303/** Global Variable Declaration */ 301/* Global Variable Declaration */
304extern const char lbs_driver_version[]; 302extern const char lbs_driver_version[];
305extern u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE]; 303extern u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE];
306 304
307 305
308/** ENUM definition*/ 306/* ENUM definition */
309/** SNRNF_TYPE */ 307/* SNRNF_TYPE */
310enum SNRNF_TYPE { 308enum SNRNF_TYPE {
311 TYPE_BEACON = 0, 309 TYPE_BEACON = 0,
312 TYPE_RXPD, 310 TYPE_RXPD,
313 MAX_TYPE_B 311 MAX_TYPE_B
314}; 312};
315 313
316/** SNRNF_DATA*/ 314/* SNRNF_DATA */
317enum SNRNF_DATA { 315enum SNRNF_DATA {
318 TYPE_NOAVG = 0, 316 TYPE_NOAVG = 0,
319 TYPE_AVG, 317 TYPE_AVG,
320 MAX_TYPE_AVG 318 MAX_TYPE_AVG
321}; 319};
322 320
323/** LBS_802_11_POWER_MODE */ 321/* LBS_802_11_POWER_MODE */
324enum LBS_802_11_POWER_MODE { 322enum LBS_802_11_POWER_MODE {
325 LBS802_11POWERMODECAM, 323 LBS802_11POWERMODECAM,
326 LBS802_11POWERMODEMAX_PSP, 324 LBS802_11POWERMODEMAX_PSP,
327 LBS802_11POWERMODEFAST_PSP, 325 LBS802_11POWERMODEFAST_PSP,
328 /*not a real mode, defined as an upper bound */ 326 /* not a real mode, defined as an upper bound */
329 LBS802_11POWEMODEMAX 327 LBS802_11POWEMODEMAX
330}; 328};
331 329
332/** PS_STATE */ 330/* PS_STATE */
333enum PS_STATE { 331enum PS_STATE {
334 PS_STATE_FULL_POWER, 332 PS_STATE_FULL_POWER,
335 PS_STATE_AWAKE, 333 PS_STATE_AWAKE,
@@ -337,7 +335,7 @@ enum PS_STATE {
337 PS_STATE_SLEEP 335 PS_STATE_SLEEP
338}; 336};
339 337
340/** DNLD_STATE */ 338/* DNLD_STATE */
341enum DNLD_STATE { 339enum DNLD_STATE {
342 DNLD_RES_RECEIVED, 340 DNLD_RES_RECEIVED,
343 DNLD_DATA_SENT, 341 DNLD_DATA_SENT,
@@ -345,19 +343,19 @@ enum DNLD_STATE {
345 DNLD_BOOTCMD_SENT, 343 DNLD_BOOTCMD_SENT,
346}; 344};
347 345
348/** LBS_MEDIA_STATE */ 346/* LBS_MEDIA_STATE */
349enum LBS_MEDIA_STATE { 347enum LBS_MEDIA_STATE {
350 LBS_CONNECTED, 348 LBS_CONNECTED,
351 LBS_DISCONNECTED 349 LBS_DISCONNECTED
352}; 350};
353 351
354/** LBS_802_11_PRIVACY_FILTER */ 352/* LBS_802_11_PRIVACY_FILTER */
355enum LBS_802_11_PRIVACY_FILTER { 353enum LBS_802_11_PRIVACY_FILTER {
356 LBS802_11PRIVFILTERACCEPTALL, 354 LBS802_11PRIVFILTERACCEPTALL,
357 LBS802_11PRIVFILTER8021XWEP 355 LBS802_11PRIVFILTER8021XWEP
358}; 356};
359 357
360/** mv_ms_type */ 358/* mv_ms_type */
361enum mv_ms_type { 359enum mv_ms_type {
362 MVMS_DAT = 0, 360 MVMS_DAT = 0,
363 MVMS_CMD = 1, 361 MVMS_CMD = 1,
@@ -365,14 +363,14 @@ enum mv_ms_type {
365 MVMS_EVENT 363 MVMS_EVENT
366}; 364};
367 365
368/** KEY_TYPE_ID */ 366/* KEY_TYPE_ID */
369enum KEY_TYPE_ID { 367enum KEY_TYPE_ID {
370 KEY_TYPE_ID_WEP = 0, 368 KEY_TYPE_ID_WEP = 0,
371 KEY_TYPE_ID_TKIP, 369 KEY_TYPE_ID_TKIP,
372 KEY_TYPE_ID_AES 370 KEY_TYPE_ID_AES
373}; 371};
374 372
375/** KEY_INFO_WPA (applies to both TKIP and AES/CCMP) */ 373/* KEY_INFO_WPA (applies to both TKIP and AES/CCMP) */
376enum KEY_INFO_WPA { 374enum KEY_INFO_WPA {
377 KEY_INFO_WPA_MCAST = 0x01, 375 KEY_INFO_WPA_MCAST = 0x01,
378 KEY_INFO_WPA_UNICAST = 0x02, 376 KEY_INFO_WPA_UNICAST = 0x02,
diff --git a/drivers/net/wireless/libertas/dev.h b/drivers/net/wireless/libertas/dev.h
index f062ed583901..76d018beebf4 100644
--- a/drivers/net/wireless/libertas/dev.h
+++ b/drivers/net/wireless/libertas/dev.h
@@ -1,8 +1,8 @@
1/** 1/*
2 * This file contains definitions and data structures specific 2 * This file contains definitions and data structures specific
3 * to Marvell 802.11 NIC. It contains the Device Information 3 * to Marvell 802.11 NIC. It contains the Device Information
4 * structure struct lbs_private.. 4 * structure struct lbs_private..
5 */ 5 */
6#ifndef _LBS_DEV_H_ 6#ifndef _LBS_DEV_H_
7#define _LBS_DEV_H_ 7#define _LBS_DEV_H_
8 8
@@ -12,7 +12,7 @@
12 12
13#include <linux/kfifo.h> 13#include <linux/kfifo.h>
14 14
15/** sleep_params */ 15/* sleep_params */
16struct sleep_params { 16struct sleep_params {
17 uint16_t sp_error; 17 uint16_t sp_error;
18 uint16_t sp_offset; 18 uint16_t sp_offset;
@@ -23,7 +23,7 @@ struct sleep_params {
23}; 23};
24 24
25 25
26/** Private structure for the MV device */ 26/* Private structure for the MV device */
27struct lbs_private { 27struct lbs_private {
28 28
29 /* Basic networking */ 29 /* Basic networking */
@@ -36,6 +36,7 @@ struct lbs_private {
36 /* CFG80211 */ 36 /* CFG80211 */
37 struct wireless_dev *wdev; 37 struct wireless_dev *wdev;
38 bool wiphy_registered; 38 bool wiphy_registered;
39 bool stopping;
39 struct cfg80211_scan_request *scan_req; 40 struct cfg80211_scan_request *scan_req;
40 u8 assoc_bss[ETH_ALEN]; 41 u8 assoc_bss[ETH_ALEN];
41 u8 disassoc_reason; 42 u8 disassoc_reason;
@@ -89,6 +90,7 @@ struct lbs_private {
89 void *card; 90 void *card;
90 u8 fw_ready; 91 u8 fw_ready;
91 u8 surpriseremoved; 92 u8 surpriseremoved;
93 u8 setup_fw_on_resume;
92 int (*hw_host_to_card) (struct lbs_private *priv, u8 type, u8 *payload, u16 nb); 94 int (*hw_host_to_card) (struct lbs_private *priv, u8 type, u8 *payload, u16 nb);
93 void (*reset_card) (struct lbs_private *priv); 95 void (*reset_card) (struct lbs_private *priv);
94 int (*enter_deep_sleep) (struct lbs_private *priv); 96 int (*enter_deep_sleep) (struct lbs_private *priv);
@@ -100,6 +102,7 @@ struct lbs_private {
100 u32 fwcapinfo; 102 u32 fwcapinfo;
101 u16 regioncode; 103 u16 regioncode;
102 u8 current_addr[ETH_ALEN]; 104 u8 current_addr[ETH_ALEN];
105 u8 copied_hwaddr;
103 106
104 /* Command download */ 107 /* Command download */
105 u8 dnld_sent; 108 u8 dnld_sent;
@@ -122,12 +125,12 @@ struct lbs_private {
122 /* Events sent from hardware to driver */ 125 /* Events sent from hardware to driver */
123 struct kfifo event_fifo; 126 struct kfifo event_fifo;
124 127
125 /** thread to service interrupts */ 128 /* thread to service interrupts */
126 struct task_struct *main_thread; 129 struct task_struct *main_thread;
127 wait_queue_head_t waitq; 130 wait_queue_head_t waitq;
128 struct workqueue_struct *work_thread; 131 struct workqueue_struct *work_thread;
129 132
130 /** Encryption stuff */ 133 /* Encryption stuff */
131 u8 authtype_auto; 134 u8 authtype_auto;
132 u8 wep_tx_key; 135 u8 wep_tx_key;
133 u8 wep_key[4][WLAN_KEY_LEN_WEP104]; 136 u8 wep_key[4][WLAN_KEY_LEN_WEP104];
@@ -137,6 +140,7 @@ struct lbs_private {
137 uint32_t wol_criteria; 140 uint32_t wol_criteria;
138 uint8_t wol_gpio; 141 uint8_t wol_gpio;
139 uint8_t wol_gap; 142 uint8_t wol_gap;
143 bool ehs_remove_supported;
140 144
141 /* Transmitting */ 145 /* Transmitting */
142 int tx_pending_len; /* -1 while building packet */ 146 int tx_pending_len; /* -1 while building packet */
@@ -158,7 +162,7 @@ struct lbs_private {
158 s16 txpower_min; 162 s16 txpower_min;
159 s16 txpower_max; 163 s16 txpower_max;
160 164
161 /** Scanning */ 165 /* Scanning */
162 struct delayed_work scan_work; 166 struct delayed_work scan_work;
163 int scan_channel; 167 int scan_channel;
164 /* Queue of things waiting for scan completion */ 168 /* Queue of things waiting for scan completion */
diff --git a/drivers/net/wireless/libertas/ethtool.c b/drivers/net/wireless/libertas/ethtool.c
index 50193aac679e..29dbce4a9f86 100644
--- a/drivers/net/wireless/libertas/ethtool.c
+++ b/drivers/net/wireless/libertas/ethtool.c
@@ -20,7 +20,8 @@ static void lbs_ethtool_get_drvinfo(struct net_device *dev,
20 strcpy(info->version, lbs_driver_version); 20 strcpy(info->version, lbs_driver_version);
21} 21}
22 22
23/* All 8388 parts have 16KiB EEPROM size at the time of writing. 23/*
24 * All 8388 parts have 16KiB EEPROM size at the time of writing.
24 * In case that changes this needs fixing. 25 * In case that changes this needs fixing.
25 */ 26 */
26#define LBS_EEPROM_LEN 16384 27#define LBS_EEPROM_LEN 16384
diff --git a/drivers/net/wireless/libertas/host.h b/drivers/net/wireless/libertas/host.h
index 5eac1351a021..2e2dbfa2ee50 100644
--- a/drivers/net/wireless/libertas/host.h
+++ b/drivers/net/wireless/libertas/host.h
@@ -1,7 +1,7 @@
1/** 1/*
2 * This file function prototypes, data structure 2 * This file function prototypes, data structure
3 * and definitions for all the host/station commands 3 * and definitions for all the host/station commands
4 */ 4 */
5 5
6#ifndef _LBS_HOST_H_ 6#ifndef _LBS_HOST_H_
7#define _LBS_HOST_H_ 7#define _LBS_HOST_H_
@@ -13,9 +13,10 @@
13 13
14#define CMD_OPTION_WAITFORRSP 0x0002 14#define CMD_OPTION_WAITFORRSP 0x0002
15 15
16/** Host command IDs */ 16/* Host command IDs */
17 17
18/* Return command are almost always the same as the host command, but with 18/*
19 * Return command are almost always the same as the host command, but with
19 * bit 15 set high. There are a few exceptions, though... 20 * bit 15 set high. There are a few exceptions, though...
20 */ 21 */
21#define CMD_RET(cmd) (0x8000 | cmd) 22#define CMD_RET(cmd) (0x8000 | cmd)
@@ -251,7 +252,7 @@ enum cmd_mesh_config_types {
251 CMD_TYPE_MESH_GET_MESH_IE, /* GET_DEFAULTS is superset of GET_MESHIE */ 252 CMD_TYPE_MESH_GET_MESH_IE, /* GET_DEFAULTS is superset of GET_MESHIE */
252}; 253};
253 254
254/** Card Event definition */ 255/* Card Event definition */
255#define MACREG_INT_CODE_TX_PPA_FREE 0 256#define MACREG_INT_CODE_TX_PPA_FREE 0
256#define MACREG_INT_CODE_TX_DMA_DONE 1 257#define MACREG_INT_CODE_TX_DMA_DONE 1
257#define MACREG_INT_CODE_LINK_LOST_W_SCAN 2 258#define MACREG_INT_CODE_LINK_LOST_W_SCAN 2
@@ -387,7 +388,7 @@ struct lbs_offset_value {
387struct mrvl_ie_domain_param_set { 388struct mrvl_ie_domain_param_set {
388 struct mrvl_ie_header header; 389 struct mrvl_ie_header header;
389 390
390 u8 country_code[3]; 391 u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
391 struct ieee80211_country_ie_triplet triplet[MAX_11D_TRIPLETS]; 392 struct ieee80211_country_ie_triplet triplet[MAX_11D_TRIPLETS];
392} __packed; 393} __packed;
393 394
@@ -624,12 +625,14 @@ struct cmd_ds_802_11_rf_channel {
624struct cmd_ds_802_11_rssi { 625struct cmd_ds_802_11_rssi {
625 struct cmd_header hdr; 626 struct cmd_header hdr;
626 627
627 /* request: number of beacons (N) to average the SNR and NF over 628 /*
629 * request: number of beacons (N) to average the SNR and NF over
628 * response: SNR of most recent beacon 630 * response: SNR of most recent beacon
629 */ 631 */
630 __le16 n_or_snr; 632 __le16 n_or_snr;
631 633
632 /* The following fields are only set in the response. 634 /*
635 * The following fields are only set in the response.
633 * In the request these are reserved and should be set to 0. 636 * In the request these are reserved and should be set to 0.
634 */ 637 */
635 __le16 nf; /* most recent beacon noise floor */ 638 __le16 nf; /* most recent beacon noise floor */
@@ -680,14 +683,16 @@ struct cmd_ds_802_11_ps_mode {
680 683
681 __le16 action; 684 __le16 action;
682 685
683 /* Interval for keepalive in PS mode: 686 /*
687 * Interval for keepalive in PS mode:
684 * 0x0000 = don't change 688 * 0x0000 = don't change
685 * 0x001E = firmware default 689 * 0x001E = firmware default
686 * 0xFFFF = disable 690 * 0xFFFF = disable
687 */ 691 */
688 __le16 nullpktinterval; 692 __le16 nullpktinterval;
689 693
690 /* Number of DTIM intervals to wake up for: 694 /*
695 * Number of DTIM intervals to wake up for:
691 * 0 = don't change 696 * 0 = don't change
692 * 1 = firmware default 697 * 1 = firmware default
693 * 5 = max 698 * 5 = max
@@ -697,7 +702,8 @@ struct cmd_ds_802_11_ps_mode {
697 __le16 reserved; 702 __le16 reserved;
698 __le16 locallisteninterval; 703 __le16 locallisteninterval;
699 704
700 /* AdHoc awake period (FW v9+ only): 705 /*
706 * AdHoc awake period (FW v9+ only):
701 * 0 = don't change 707 * 0 = don't change
702 * 1 = always awake (IEEE standard behavior) 708 * 1 = always awake (IEEE standard behavior)
703 * 2 - 31 = sleep for (n - 1) periods and awake for 1 period 709 * 2 - 31 = sleep for (n - 1) periods and awake for 1 period
@@ -771,7 +777,8 @@ struct adhoc_bssdesc {
771 __le16 capability; 777 __le16 capability;
772 u8 rates[MAX_RATES]; 778 u8 rates[MAX_RATES];
773 779
774 /* DO NOT ADD ANY FIELDS TO THIS STRUCTURE. It is used below in the 780 /*
781 * DO NOT ADD ANY FIELDS TO THIS STRUCTURE. It is used below in the
775 * Adhoc join command and will cause a binary layout mismatch with 782 * Adhoc join command and will cause a binary layout mismatch with
776 * the firmware 783 * the firmware
777 */ 784 */
diff --git a/drivers/net/wireless/libertas/if_cs.c b/drivers/net/wireless/libertas/if_cs.c
index 9c298396be50..e26935179861 100644
--- a/drivers/net/wireless/libertas/if_cs.c
+++ b/drivers/net/wireless/libertas/if_cs.c
@@ -21,6 +21,8 @@
21 21
22*/ 22*/
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include <linux/module.h> 26#include <linux/module.h>
25#include <linux/slab.h> 27#include <linux/slab.h>
26#include <linux/delay.h> 28#include <linux/delay.h>
@@ -28,7 +30,6 @@
28#include <linux/firmware.h> 30#include <linux/firmware.h>
29#include <linux/netdevice.h> 31#include <linux/netdevice.h>
30 32
31#include <pcmcia/cs.h>
32#include <pcmcia/cistpl.h> 33#include <pcmcia/cistpl.h>
33#include <pcmcia/ds.h> 34#include <pcmcia/ds.h>
34 35
@@ -48,7 +49,6 @@
48MODULE_AUTHOR("Holger Schurig <hs4233@mail.mn-solutions.de>"); 49MODULE_AUTHOR("Holger Schurig <hs4233@mail.mn-solutions.de>");
49MODULE_DESCRIPTION("Driver for Marvell 83xx compact flash WLAN cards"); 50MODULE_DESCRIPTION("Driver for Marvell 83xx compact flash WLAN cards");
50MODULE_LICENSE("GPL"); 51MODULE_LICENSE("GPL");
51MODULE_FIRMWARE("libertas_cs_helper.fw");
52 52
53 53
54 54
@@ -61,9 +61,34 @@ struct if_cs_card {
61 struct lbs_private *priv; 61 struct lbs_private *priv;
62 void __iomem *iobase; 62 void __iomem *iobase;
63 bool align_regs; 63 bool align_regs;
64 u32 model;
64}; 65};
65 66
66 67
68enum {
69 MODEL_UNKNOWN = 0x00,
70 MODEL_8305 = 0x01,
71 MODEL_8381 = 0x02,
72 MODEL_8385 = 0x03
73};
74
75static const struct lbs_fw_table fw_table[] = {
76 { MODEL_8305, "libertas/cf8305.bin", NULL },
77 { MODEL_8305, "libertas_cs_helper.fw", NULL },
78 { MODEL_8381, "libertas/cf8381_helper.bin", "libertas/cf8381.bin" },
79 { MODEL_8381, "libertas_cs_helper.fw", "libertas_cs.fw" },
80 { MODEL_8385, "libertas/cf8385_helper.bin", "libertas/cf8385.bin" },
81 { MODEL_8385, "libertas_cs_helper.fw", "libertas_cs.fw" },
82 { 0, NULL, NULL }
83};
84MODULE_FIRMWARE("libertas/cf8305.bin");
85MODULE_FIRMWARE("libertas/cf8381_helper.bin");
86MODULE_FIRMWARE("libertas/cf8381.bin");
87MODULE_FIRMWARE("libertas/cf8385_helper.bin");
88MODULE_FIRMWARE("libertas/cf8385.bin");
89MODULE_FIRMWARE("libertas_cs_helper.fw");
90MODULE_FIRMWARE("libertas_cs.fw");
91
67 92
68/********************************************************************/ 93/********************************************************************/
69/* Hardware access */ 94/* Hardware access */
@@ -289,22 +314,20 @@ static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 r
289#define CF8385_MANFID 0x02df 314#define CF8385_MANFID 0x02df
290#define CF8385_CARDID 0x8103 315#define CF8385_CARDID 0x8103
291 316
292static inline int if_cs_hw_is_cf8305(struct pcmcia_device *p_dev) 317/*
293{ 318 * FIXME: just use the 'driver_info' field of 'struct pcmcia_device_id' when
294 return (p_dev->manf_id == CF8305_MANFID && 319 * that gets fixed. Currently there's no way to access it from the probe hook.
295 p_dev->card_id == CF8305_CARDID); 320 */
296} 321static inline u32 get_model(u16 manf_id, u16 card_id)
297
298static inline int if_cs_hw_is_cf8381(struct pcmcia_device *p_dev)
299{
300 return (p_dev->manf_id == CF8381_MANFID &&
301 p_dev->card_id == CF8381_CARDID);
302}
303
304static inline int if_cs_hw_is_cf8385(struct pcmcia_device *p_dev)
305{ 322{
306 return (p_dev->manf_id == CF8385_MANFID && 323 /* NOTE: keep in sync with if_cs_ids */
307 p_dev->card_id == CF8385_CARDID); 324 if (manf_id == CF8305_MANFID && card_id == CF8305_CARDID)
325 return MODEL_8305;
326 else if (manf_id == CF8381_MANFID && card_id == CF8381_CARDID)
327 return MODEL_8381;
328 else if (manf_id == CF8385_MANFID && card_id == CF8385_CARDID)
329 return MODEL_8385;
330 return MODEL_UNKNOWN;
308} 331}
309 332
310/********************************************************************/ 333/********************************************************************/
@@ -341,7 +364,7 @@ static int if_cs_send_cmd(struct lbs_private *priv, u8 *buf, u16 nb)
341 if (status & IF_CS_BIT_COMMAND) 364 if (status & IF_CS_BIT_COMMAND)
342 break; 365 break;
343 if (++loops > 100) { 366 if (++loops > 100) {
344 lbs_pr_err("card not ready for commands\n"); 367 netdev_err(priv->dev, "card not ready for commands\n");
345 goto done; 368 goto done;
346 } 369 }
347 mdelay(1); 370 mdelay(1);
@@ -411,14 +434,16 @@ static int if_cs_receive_cmdres(struct lbs_private *priv, u8 *data, u32 *len)
411 /* is hardware ready? */ 434 /* is hardware ready? */
412 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS); 435 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
413 if ((status & IF_CS_BIT_RESP) == 0) { 436 if ((status & IF_CS_BIT_RESP) == 0) {
414 lbs_pr_err("no cmd response in card\n"); 437 netdev_err(priv->dev, "no cmd response in card\n");
415 *len = 0; 438 *len = 0;
416 goto out; 439 goto out;
417 } 440 }
418 441
419 *len = if_cs_read16(priv->card, IF_CS_RESP_LEN); 442 *len = if_cs_read16(priv->card, IF_CS_RESP_LEN);
420 if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) { 443 if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) {
421 lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len); 444 netdev_err(priv->dev,
445 "card cmd buffer has invalid # of bytes (%d)\n",
446 *len);
422 goto out; 447 goto out;
423 } 448 }
424 449
@@ -452,7 +477,9 @@ static struct sk_buff *if_cs_receive_data(struct lbs_private *priv)
452 477
453 len = if_cs_read16(priv->card, IF_CS_READ_LEN); 478 len = if_cs_read16(priv->card, IF_CS_READ_LEN);
454 if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) { 479 if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
455 lbs_pr_err("card data buffer has invalid # of bytes (%d)\n", len); 480 netdev_err(priv->dev,
481 "card data buffer has invalid # of bytes (%d)\n",
482 len);
456 priv->dev->stats.rx_dropped++; 483 priv->dev->stats.rx_dropped++;
457 goto dat_err; 484 goto dat_err;
458 } 485 }
@@ -558,12 +585,11 @@ static irqreturn_t if_cs_interrupt(int irq, void *data)
558 * 585 *
559 * Return 0 on success 586 * Return 0 on success
560 */ 587 */
561static int if_cs_prog_helper(struct if_cs_card *card) 588static int if_cs_prog_helper(struct if_cs_card *card, const struct firmware *fw)
562{ 589{
563 int ret = 0; 590 int ret = 0;
564 int sent = 0; 591 int sent = 0;
565 u8 scratch; 592 u8 scratch;
566 const struct firmware *fw;
567 593
568 lbs_deb_enter(LBS_DEB_CS); 594 lbs_deb_enter(LBS_DEB_CS);
569 595
@@ -589,14 +615,6 @@ static int if_cs_prog_helper(struct if_cs_card *card)
589 goto done; 615 goto done;
590 } 616 }
591 617
592 /* TODO: make firmware file configurable */
593 ret = request_firmware(&fw, "libertas_cs_helper.fw",
594 &card->p_dev->dev);
595 if (ret) {
596 lbs_pr_err("can't load helper firmware\n");
597 ret = -ENODEV;
598 goto done;
599 }
600 lbs_deb_cs("helper size %td\n", fw->size); 618 lbs_deb_cs("helper size %td\n", fw->size);
601 619
602 /* "Set the 5 bytes of the helper image to 0" */ 620 /* "Set the 5 bytes of the helper image to 0" */
@@ -610,8 +628,10 @@ static int if_cs_prog_helper(struct if_cs_card *card)
610 if (remain < count) 628 if (remain < count)
611 count = remain; 629 count = remain;
612 630
613 /* "write the number of bytes to be sent to the I/O Command 631 /*
614 * write length register" */ 632 * "write the number of bytes to be sent to the I/O Command
633 * write length register"
634 */
615 if_cs_write16(card, IF_CS_CMD_LEN, count); 635 if_cs_write16(card, IF_CS_CMD_LEN, count);
616 636
617 /* "write this to I/O Command port register as 16 bit writes */ 637 /* "write this to I/O Command port register as 16 bit writes */
@@ -620,22 +640,28 @@ static int if_cs_prog_helper(struct if_cs_card *card)
620 &fw->data[sent], 640 &fw->data[sent],
621 count >> 1); 641 count >> 1);
622 642
623 /* "Assert the download over interrupt command in the Host 643 /*
624 * status register" */ 644 * "Assert the download over interrupt command in the Host
645 * status register"
646 */
625 if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND); 647 if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
626 648
627 /* "Assert the download over interrupt command in the Card 649 /*
628 * interrupt case register" */ 650 * "Assert the download over interrupt command in the Card
651 * interrupt case register"
652 */
629 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND); 653 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
630 654
631 /* "The host polls the Card Status register ... for 50 ms before 655 /*
632 declaring a failure */ 656 * "The host polls the Card Status register ... for 50 ms before
657 * declaring a failure"
658 */
633 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS, 659 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
634 IF_CS_BIT_COMMAND); 660 IF_CS_BIT_COMMAND);
635 if (ret < 0) { 661 if (ret < 0) {
636 lbs_pr_err("can't download helper at 0x%x, ret %d\n", 662 pr_err("can't download helper at 0x%x, ret %d\n",
637 sent, ret); 663 sent, ret);
638 goto err_release; 664 goto done;
639 } 665 }
640 666
641 if (count == 0) 667 if (count == 0)
@@ -644,17 +670,14 @@ static int if_cs_prog_helper(struct if_cs_card *card)
644 sent += count; 670 sent += count;
645 } 671 }
646 672
647err_release:
648 release_firmware(fw);
649done: 673done:
650 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); 674 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
651 return ret; 675 return ret;
652} 676}
653 677
654 678
655static int if_cs_prog_real(struct if_cs_card *card) 679static int if_cs_prog_real(struct if_cs_card *card, const struct firmware *fw)
656{ 680{
657 const struct firmware *fw;
658 int ret = 0; 681 int ret = 0;
659 int retry = 0; 682 int retry = 0;
660 int len = 0; 683 int len = 0;
@@ -662,36 +685,28 @@ static int if_cs_prog_real(struct if_cs_card *card)
662 685
663 lbs_deb_enter(LBS_DEB_CS); 686 lbs_deb_enter(LBS_DEB_CS);
664 687
665 /* TODO: make firmware file configurable */
666 ret = request_firmware(&fw, "libertas_cs.fw",
667 &card->p_dev->dev);
668 if (ret) {
669 lbs_pr_err("can't load firmware\n");
670 ret = -ENODEV;
671 goto done;
672 }
673 lbs_deb_cs("fw size %td\n", fw->size); 688 lbs_deb_cs("fw size %td\n", fw->size);
674 689
675 ret = if_cs_poll_while_fw_download(card, IF_CS_SQ_READ_LOW, 690 ret = if_cs_poll_while_fw_download(card, IF_CS_SQ_READ_LOW,
676 IF_CS_SQ_HELPER_OK); 691 IF_CS_SQ_HELPER_OK);
677 if (ret < 0) { 692 if (ret < 0) {
678 lbs_pr_err("helper firmware doesn't answer\n"); 693 pr_err("helper firmware doesn't answer\n");
679 goto err_release; 694 goto done;
680 } 695 }
681 696
682 for (sent = 0; sent < fw->size; sent += len) { 697 for (sent = 0; sent < fw->size; sent += len) {
683 len = if_cs_read16(card, IF_CS_SQ_READ_LOW); 698 len = if_cs_read16(card, IF_CS_SQ_READ_LOW);
684 if (len & 1) { 699 if (len & 1) {
685 retry++; 700 retry++;
686 lbs_pr_info("odd, need to retry this firmware block\n"); 701 pr_info("odd, need to retry this firmware block\n");
687 } else { 702 } else {
688 retry = 0; 703 retry = 0;
689 } 704 }
690 705
691 if (retry > 20) { 706 if (retry > 20) {
692 lbs_pr_err("could not download firmware\n"); 707 pr_err("could not download firmware\n");
693 ret = -ENODEV; 708 ret = -ENODEV;
694 goto err_release; 709 goto done;
695 } 710 }
696 if (retry) { 711 if (retry) {
697 sent -= len; 712 sent -= len;
@@ -709,17 +724,14 @@ static int if_cs_prog_real(struct if_cs_card *card)
709 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS, 724 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
710 IF_CS_BIT_COMMAND); 725 IF_CS_BIT_COMMAND);
711 if (ret < 0) { 726 if (ret < 0) {
712 lbs_pr_err("can't download firmware at 0x%x\n", sent); 727 pr_err("can't download firmware at 0x%x\n", sent);
713 goto err_release; 728 goto done;
714 } 729 }
715 } 730 }
716 731
717 ret = if_cs_poll_while_fw_download(card, IF_CS_SCRATCH, 0x5a); 732 ret = if_cs_poll_while_fw_download(card, IF_CS_SCRATCH, 0x5a);
718 if (ret < 0) 733 if (ret < 0)
719 lbs_pr_err("firmware download failed\n"); 734 pr_err("firmware download failed\n");
720
721err_release:
722 release_firmware(fw);
723 735
724done: 736done:
725 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); 737 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
@@ -753,7 +765,8 @@ static int if_cs_host_to_card(struct lbs_private *priv,
753 ret = if_cs_send_cmd(priv, buf, nb); 765 ret = if_cs_send_cmd(priv, buf, nb);
754 break; 766 break;
755 default: 767 default:
756 lbs_pr_err("%s: unsupported type %d\n", __func__, type); 768 netdev_err(priv->dev, "%s: unsupported type %d\n",
769 __func__, type);
757 } 770 }
758 771
759 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); 772 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
@@ -761,15 +774,6 @@ static int if_cs_host_to_card(struct lbs_private *priv,
761} 774}
762 775
763 776
764/********************************************************************/
765/* Card Services */
766/********************************************************************/
767
768/*
769 * After a card is removed, if_cs_release() will unregister the
770 * device, and release the PCMCIA configuration. If the device is
771 * still open, this will be postponed until it is closed.
772 */
773static void if_cs_release(struct pcmcia_device *p_dev) 777static void if_cs_release(struct pcmcia_device *p_dev)
774{ 778{
775 struct if_cs_card *card = p_dev->priv; 779 struct if_cs_card *card = p_dev->priv;
@@ -785,32 +789,13 @@ static void if_cs_release(struct pcmcia_device *p_dev)
785} 789}
786 790
787 791
788/* 792static int if_cs_ioprobe(struct pcmcia_device *p_dev, void *priv_data)
789 * This creates an "instance" of the driver, allocating local data
790 * structures for one device. The device is registered with Card
791 * Services.
792 *
793 * The dev_link structure is initialized, but we don't actually
794 * configure the card at this point -- we wait until we receive a card
795 * insertion event.
796 */
797
798static int if_cs_ioprobe(struct pcmcia_device *p_dev,
799 cistpl_cftable_entry_t *cfg,
800 cistpl_cftable_entry_t *dflt,
801 unsigned int vcc,
802 void *priv_data)
803{ 793{
794 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
804 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 795 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
805 p_dev->resource[0]->start = cfg->io.win[0].base;
806 p_dev->resource[0]->end = cfg->io.win[0].len;
807 796
808 /* Do we need to allocate an interrupt? */ 797 if (p_dev->resource[1]->end) {
809 p_dev->conf.Attributes |= CONF_ENABLE_IRQ; 798 pr_err("wrong CIS (check number of IO windows)\n");
810
811 /* IO window settings */
812 if (cfg->io.nwin != 1) {
813 lbs_pr_err("wrong CIS (check number of IO windows)\n");
814 return -ENODEV; 799 return -ENODEV;
815 } 800 }
816 801
@@ -824,26 +809,26 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
824 unsigned int prod_id; 809 unsigned int prod_id;
825 struct lbs_private *priv; 810 struct lbs_private *priv;
826 struct if_cs_card *card; 811 struct if_cs_card *card;
812 const struct firmware *helper = NULL;
813 const struct firmware *mainfw = NULL;
827 814
828 lbs_deb_enter(LBS_DEB_CS); 815 lbs_deb_enter(LBS_DEB_CS);
829 816
830 card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL); 817 card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL);
831 if (!card) { 818 if (!card) {
832 lbs_pr_err("error in kzalloc\n"); 819 pr_err("error in kzalloc\n");
833 goto out; 820 goto out;
834 } 821 }
835 card->p_dev = p_dev; 822 card->p_dev = p_dev;
836 p_dev->priv = card; 823 p_dev->priv = card;
837 824
838 p_dev->conf.Attributes = 0; 825 p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
839 p_dev->conf.IntType = INT_MEMORY_AND_IO;
840 826
841 if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) { 827 if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) {
842 lbs_pr_err("error in pcmcia_loop_config\n"); 828 pr_err("error in pcmcia_loop_config\n");
843 goto out1; 829 goto out1;
844 } 830 }
845 831
846
847 /* 832 /*
848 * Allocate an interrupt line. Note that this does not assign 833 * Allocate an interrupt line. Note that this does not assign
849 * a handler to the interrupt, unless the 'Handler' member of 834 * a handler to the interrupt, unless the 'Handler' member of
@@ -856,19 +841,14 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
856 card->iobase = ioport_map(p_dev->resource[0]->start, 841 card->iobase = ioport_map(p_dev->resource[0]->start,
857 resource_size(p_dev->resource[0])); 842 resource_size(p_dev->resource[0]));
858 if (!card->iobase) { 843 if (!card->iobase) {
859 lbs_pr_err("error in ioport_map\n"); 844 pr_err("error in ioport_map\n");
860 ret = -EIO; 845 ret = -EIO;
861 goto out1; 846 goto out1;
862 } 847 }
863 848
864 /* 849 ret = pcmcia_enable_device(p_dev);
865 * This actually configures the PCMCIA socket -- setting up
866 * the I/O windows and the interrupt mapping, and putting the
867 * card and host interface into "Memory and IO" mode.
868 */
869 ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
870 if (ret) { 850 if (ret) {
871 lbs_pr_err("error in pcmcia_request_configuration\n"); 851 pr_err("error in pcmcia_enable_device\n");
872 goto out2; 852 goto out2;
873 } 853 }
874 854
@@ -877,38 +857,51 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
877 857
878 /* 858 /*
879 * Most of the libertas cards can do unaligned register access, but some 859 * Most of the libertas cards can do unaligned register access, but some
880 * weird ones can not. That's especially true for the CF8305 card. 860 * weird ones cannot. That's especially true for the CF8305 card.
881 */ 861 */
882 card->align_regs = 0; 862 card->align_regs = 0;
883 863
864 card->model = get_model(p_dev->manf_id, p_dev->card_id);
865 if (card->model == MODEL_UNKNOWN) {
866 pr_err("unsupported manf_id 0x%04x / card_id 0x%04x\n",
867 p_dev->manf_id, p_dev->card_id);
868 goto out2;
869 }
870
884 /* Check if we have a current silicon */ 871 /* Check if we have a current silicon */
885 prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID); 872 prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID);
886 if (if_cs_hw_is_cf8305(p_dev)) { 873 if (card->model == MODEL_8305) {
887 card->align_regs = 1; 874 card->align_regs = 1;
888 if (prod_id < IF_CS_CF8305_B1_REV) { 875 if (prod_id < IF_CS_CF8305_B1_REV) {
889 lbs_pr_err("old chips like 8305 rev B3 " 876 pr_err("8305 rev B0 and older are not supported\n");
890 "aren't supported\n");
891 ret = -ENODEV; 877 ret = -ENODEV;
892 goto out2; 878 goto out2;
893 } 879 }
894 } 880 }
895 881
896 if (if_cs_hw_is_cf8381(p_dev) && prod_id < IF_CS_CF8381_B3_REV) { 882 if ((card->model == MODEL_8381) && prod_id < IF_CS_CF8381_B3_REV) {
897 lbs_pr_err("old chips like 8381 rev B3 aren't supported\n"); 883 pr_err("8381 rev B2 and older are not supported\n");
898 ret = -ENODEV; 884 ret = -ENODEV;
899 goto out2; 885 goto out2;
900 } 886 }
901 887
902 if (if_cs_hw_is_cf8385(p_dev) && prod_id < IF_CS_CF8385_B1_REV) { 888 if ((card->model == MODEL_8385) && prod_id < IF_CS_CF8385_B1_REV) {
903 lbs_pr_err("old chips like 8385 rev B1 aren't supported\n"); 889 pr_err("8385 rev B0 and older are not supported\n");
904 ret = -ENODEV; 890 ret = -ENODEV;
905 goto out2; 891 goto out2;
906 } 892 }
907 893
894 ret = lbs_get_firmware(&p_dev->dev, NULL, NULL, card->model,
895 &fw_table[0], &helper, &mainfw);
896 if (ret) {
897 pr_err("failed to find firmware (%d)\n", ret);
898 goto out2;
899 }
900
908 /* Load the firmware early, before calling into libertas.ko */ 901 /* Load the firmware early, before calling into libertas.ko */
909 ret = if_cs_prog_helper(card); 902 ret = if_cs_prog_helper(card, helper);
910 if (ret == 0 && !if_cs_hw_is_cf8305(p_dev)) 903 if (ret == 0 && (card->model != MODEL_8305))
911 ret = if_cs_prog_real(card); 904 ret = if_cs_prog_real(card, mainfw);
912 if (ret) 905 if (ret)
913 goto out2; 906 goto out2;
914 907
@@ -932,18 +925,20 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
932 ret = request_irq(p_dev->irq, if_cs_interrupt, 925 ret = request_irq(p_dev->irq, if_cs_interrupt,
933 IRQF_SHARED, DRV_NAME, card); 926 IRQF_SHARED, DRV_NAME, card);
934 if (ret) { 927 if (ret) {
935 lbs_pr_err("error in request_irq\n"); 928 pr_err("error in request_irq\n");
936 goto out3; 929 goto out3;
937 } 930 }
938 931
939 /* Clear any interrupt cause that happend while sending 932 /*
940 * firmware/initializing card */ 933 * Clear any interrupt cause that happened while sending
934 * firmware/initializing card
935 */
941 if_cs_write16(card, IF_CS_CARD_INT_CAUSE, IF_CS_BIT_MASK); 936 if_cs_write16(card, IF_CS_CARD_INT_CAUSE, IF_CS_BIT_MASK);
942 if_cs_enable_ints(card); 937 if_cs_enable_ints(card);
943 938
944 /* And finally bring the card up */ 939 /* And finally bring the card up */
945 if (lbs_start_card(priv) != 0) { 940 if (lbs_start_card(priv) != 0) {
946 lbs_pr_err("could not activate card\n"); 941 pr_err("could not activate card\n");
947 goto out3; 942 goto out3;
948 } 943 }
949 944
@@ -957,17 +952,16 @@ out2:
957out1: 952out1:
958 pcmcia_disable_device(p_dev); 953 pcmcia_disable_device(p_dev);
959out: 954out:
955 if (helper)
956 release_firmware(helper);
957 if (mainfw)
958 release_firmware(mainfw);
959
960 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); 960 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
961 return ret; 961 return ret;
962} 962}
963 963
964 964
965/*
966 * This deletes a driver "instance". The device is de-registered with
967 * Card Services. If it has been released, all local data structures
968 * are freed. Otherwise, the structures will be freed when the device
969 * is released.
970 */
971static void if_cs_detach(struct pcmcia_device *p_dev) 965static void if_cs_detach(struct pcmcia_device *p_dev)
972{ 966{
973 struct if_cs_card *card = p_dev->priv; 967 struct if_cs_card *card = p_dev->priv;
@@ -989,10 +983,11 @@ static void if_cs_detach(struct pcmcia_device *p_dev)
989/* Module initialization */ 983/* Module initialization */
990/********************************************************************/ 984/********************************************************************/
991 985
992static struct pcmcia_device_id if_cs_ids[] = { 986static const struct pcmcia_device_id if_cs_ids[] = {
993 PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID, CF8305_CARDID), 987 PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID, CF8305_CARDID),
994 PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID), 988 PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID),
995 PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID), 989 PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID),
990 /* NOTE: keep in sync with get_model() */
996 PCMCIA_DEVICE_NULL, 991 PCMCIA_DEVICE_NULL,
997}; 992};
998MODULE_DEVICE_TABLE(pcmcia, if_cs_ids); 993MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
@@ -1000,9 +995,7 @@ MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
1000 995
1001static struct pcmcia_driver lbs_driver = { 996static struct pcmcia_driver lbs_driver = {
1002 .owner = THIS_MODULE, 997 .owner = THIS_MODULE,
1003 .drv = { 998 .name = DRV_NAME,
1004 .name = DRV_NAME,
1005 },
1006 .probe = if_cs_probe, 999 .probe = if_cs_probe,
1007 .remove = if_cs_detach, 1000 .remove = if_cs_detach,
1008 .id_table = if_cs_ids, 1001 .id_table = if_cs_ids,
diff --git a/drivers/net/wireless/libertas/if_sdio.c b/drivers/net/wireless/libertas/if_sdio.c
index 87b634978b35..224e9853c480 100644
--- a/drivers/net/wireless/libertas/if_sdio.c
+++ b/drivers/net/wireless/libertas/if_sdio.c
@@ -26,6 +26,8 @@
26 * if_sdio_card_to_host() to pad the data. 26 * if_sdio_card_to_host() to pad the data.
27 */ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/kernel.h> 31#include <linux/kernel.h>
30#include <linux/moduleparam.h> 32#include <linux/moduleparam.h>
31#include <linux/slab.h> 33#include <linux/slab.h>
@@ -76,36 +78,32 @@ static const struct sdio_device_id if_sdio_ids[] = {
76 78
77MODULE_DEVICE_TABLE(sdio, if_sdio_ids); 79MODULE_DEVICE_TABLE(sdio, if_sdio_ids);
78 80
79struct if_sdio_model { 81#define MODEL_8385 0x04
80 int model; 82#define MODEL_8686 0x0b
81 const char *helper; 83#define MODEL_8688 0x10
82 const char *firmware; 84
83}; 85static const struct lbs_fw_table fw_table[] = {
84 86 { MODEL_8385, "libertas/sd8385_helper.bin", "libertas/sd8385.bin" },
85static struct if_sdio_model if_sdio_models[] = { 87 { MODEL_8385, "sd8385_helper.bin", "sd8385.bin" },
86 { 88 { MODEL_8686, "libertas/sd8686_v9_helper.bin", "libertas/sd8686_v9.bin" },
87 /* 8385 */ 89 { MODEL_8686, "libertas/sd8686_v8_helper.bin", "libertas/sd8686_v8.bin" },
88 .model = IF_SDIO_MODEL_8385, 90 { MODEL_8686, "sd8686_helper.bin", "sd8686.bin" },
89 .helper = "sd8385_helper.bin", 91 { MODEL_8688, "libertas/sd8688_helper.bin", "libertas/sd8688.bin" },
90 .firmware = "sd8385.bin", 92 { MODEL_8688, "sd8688_helper.bin", "sd8688.bin" },
91 }, 93 { 0, NULL, NULL }
92 {
93 /* 8686 */
94 .model = IF_SDIO_MODEL_8686,
95 .helper = "sd8686_helper.bin",
96 .firmware = "sd8686.bin",
97 },
98 {
99 /* 8688 */
100 .model = IF_SDIO_MODEL_8688,
101 .helper = "sd8688_helper.bin",
102 .firmware = "sd8688.bin",
103 },
104}; 94};
95MODULE_FIRMWARE("libertas/sd8385_helper.bin");
96MODULE_FIRMWARE("libertas/sd8385.bin");
105MODULE_FIRMWARE("sd8385_helper.bin"); 97MODULE_FIRMWARE("sd8385_helper.bin");
106MODULE_FIRMWARE("sd8385.bin"); 98MODULE_FIRMWARE("sd8385.bin");
99MODULE_FIRMWARE("libertas/sd8686_v9_helper.bin");
100MODULE_FIRMWARE("libertas/sd8686_v9.bin");
101MODULE_FIRMWARE("libertas/sd8686_v8_helper.bin");
102MODULE_FIRMWARE("libertas/sd8686_v8.bin");
107MODULE_FIRMWARE("sd8686_helper.bin"); 103MODULE_FIRMWARE("sd8686_helper.bin");
108MODULE_FIRMWARE("sd8686.bin"); 104MODULE_FIRMWARE("sd8686.bin");
105MODULE_FIRMWARE("libertas/sd8688_helper.bin");
106MODULE_FIRMWARE("libertas/sd8688.bin");
109MODULE_FIRMWARE("sd8688_helper.bin"); 107MODULE_FIRMWARE("sd8688_helper.bin");
110MODULE_FIRMWARE("sd8688.bin"); 108MODULE_FIRMWARE("sd8688.bin");
111 109
@@ -187,11 +185,11 @@ static u16 if_sdio_read_rx_len(struct if_sdio_card *card, int *err)
187 u16 rx_len; 185 u16 rx_len;
188 186
189 switch (card->model) { 187 switch (card->model) {
190 case IF_SDIO_MODEL_8385: 188 case MODEL_8385:
191 case IF_SDIO_MODEL_8686: 189 case MODEL_8686:
192 rx_len = if_sdio_read_scratch(card, &ret); 190 rx_len = if_sdio_read_scratch(card, &ret);
193 break; 191 break;
194 case IF_SDIO_MODEL_8688: 192 case MODEL_8688:
195 default: /* for newer chipsets */ 193 default: /* for newer chipsets */
196 rx_len = sdio_readb(card->func, IF_SDIO_RX_LEN, &ret); 194 rx_len = sdio_readb(card->func, IF_SDIO_RX_LEN, &ret);
197 if (!ret) 195 if (!ret)
@@ -288,7 +286,7 @@ static int if_sdio_handle_event(struct if_sdio_card *card,
288 286
289 lbs_deb_enter(LBS_DEB_SDIO); 287 lbs_deb_enter(LBS_DEB_SDIO);
290 288
291 if (card->model == IF_SDIO_MODEL_8385) { 289 if (card->model == MODEL_8385) {
292 event = sdio_readb(card->func, IF_SDIO_EVENT, &ret); 290 event = sdio_readb(card->func, IF_SDIO_EVENT, &ret);
293 if (ret) 291 if (ret)
294 goto out; 292 goto out;
@@ -413,7 +411,7 @@ static int if_sdio_card_to_host(struct if_sdio_card *card)
413 411
414out: 412out:
415 if (ret) 413 if (ret)
416 lbs_pr_err("problem fetching packet from firmware\n"); 414 pr_err("problem fetching packet from firmware\n");
417 415
418 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); 416 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret);
419 417
@@ -450,7 +448,7 @@ static void if_sdio_host_to_card_worker(struct work_struct *work)
450 } 448 }
451 449
452 if (ret) 450 if (ret)
453 lbs_pr_err("error %d sending packet to firmware\n", ret); 451 pr_err("error %d sending packet to firmware\n", ret);
454 452
455 sdio_release_host(card->func); 453 sdio_release_host(card->func);
456 454
@@ -466,10 +464,10 @@ static void if_sdio_host_to_card_worker(struct work_struct *work)
466 464
467#define FW_DL_READY_STATUS (IF_SDIO_IO_RDY | IF_SDIO_DL_RDY) 465#define FW_DL_READY_STATUS (IF_SDIO_IO_RDY | IF_SDIO_DL_RDY)
468 466
469static int if_sdio_prog_helper(struct if_sdio_card *card) 467static int if_sdio_prog_helper(struct if_sdio_card *card,
468 const struct firmware *fw)
470{ 469{
471 int ret; 470 int ret;
472 const struct firmware *fw;
473 unsigned long timeout; 471 unsigned long timeout;
474 u8 *chunk_buffer; 472 u8 *chunk_buffer;
475 u32 chunk_size; 473 u32 chunk_size;
@@ -478,16 +476,10 @@ static int if_sdio_prog_helper(struct if_sdio_card *card)
478 476
479 lbs_deb_enter(LBS_DEB_SDIO); 477 lbs_deb_enter(LBS_DEB_SDIO);
480 478
481 ret = request_firmware(&fw, card->helper, &card->func->dev);
482 if (ret) {
483 lbs_pr_err("can't load helper firmware\n");
484 goto out;
485 }
486
487 chunk_buffer = kzalloc(64, GFP_KERNEL); 479 chunk_buffer = kzalloc(64, GFP_KERNEL);
488 if (!chunk_buffer) { 480 if (!chunk_buffer) {
489 ret = -ENOMEM; 481 ret = -ENOMEM;
490 goto release_fw; 482 goto out;
491 } 483 }
492 484
493 sdio_claim_host(card->func); 485 sdio_claim_host(card->func);
@@ -562,22 +554,19 @@ static int if_sdio_prog_helper(struct if_sdio_card *card)
562release: 554release:
563 sdio_release_host(card->func); 555 sdio_release_host(card->func);
564 kfree(chunk_buffer); 556 kfree(chunk_buffer);
565release_fw:
566 release_firmware(fw);
567 557
568out: 558out:
569 if (ret) 559 if (ret)
570 lbs_pr_err("failed to load helper firmware\n"); 560 pr_err("failed to load helper firmware\n");
571 561
572 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); 562 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret);
573
574 return ret; 563 return ret;
575} 564}
576 565
577static int if_sdio_prog_real(struct if_sdio_card *card) 566static int if_sdio_prog_real(struct if_sdio_card *card,
567 const struct firmware *fw)
578{ 568{
579 int ret; 569 int ret;
580 const struct firmware *fw;
581 unsigned long timeout; 570 unsigned long timeout;
582 u8 *chunk_buffer; 571 u8 *chunk_buffer;
583 u32 chunk_size; 572 u32 chunk_size;
@@ -586,16 +575,10 @@ static int if_sdio_prog_real(struct if_sdio_card *card)
586 575
587 lbs_deb_enter(LBS_DEB_SDIO); 576 lbs_deb_enter(LBS_DEB_SDIO);
588 577
589 ret = request_firmware(&fw, card->firmware, &card->func->dev);
590 if (ret) {
591 lbs_pr_err("can't load firmware\n");
592 goto out;
593 }
594
595 chunk_buffer = kzalloc(512, GFP_KERNEL); 578 chunk_buffer = kzalloc(512, GFP_KERNEL);
596 if (!chunk_buffer) { 579 if (!chunk_buffer) {
597 ret = -ENOMEM; 580 ret = -ENOMEM;
598 goto release_fw; 581 goto out;
599 } 582 }
600 583
601 sdio_claim_host(card->func); 584 sdio_claim_host(card->func);
@@ -685,15 +668,12 @@ static int if_sdio_prog_real(struct if_sdio_card *card)
685release: 668release:
686 sdio_release_host(card->func); 669 sdio_release_host(card->func);
687 kfree(chunk_buffer); 670 kfree(chunk_buffer);
688release_fw:
689 release_firmware(fw);
690 671
691out: 672out:
692 if (ret) 673 if (ret)
693 lbs_pr_err("failed to load firmware\n"); 674 pr_err("failed to load firmware\n");
694 675
695 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); 676 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret);
696
697 return ret; 677 return ret;
698} 678}
699 679
@@ -701,31 +681,66 @@ static int if_sdio_prog_firmware(struct if_sdio_card *card)
701{ 681{
702 int ret; 682 int ret;
703 u16 scratch; 683 u16 scratch;
684 const struct firmware *helper = NULL;
685 const struct firmware *mainfw = NULL;
704 686
705 lbs_deb_enter(LBS_DEB_SDIO); 687 lbs_deb_enter(LBS_DEB_SDIO);
706 688
689 /*
690 * Disable interrupts
691 */
692 sdio_claim_host(card->func);
693 sdio_writeb(card->func, 0x00, IF_SDIO_H_INT_MASK, &ret);
694 sdio_release_host(card->func);
695
707 sdio_claim_host(card->func); 696 sdio_claim_host(card->func);
708 scratch = if_sdio_read_scratch(card, &ret); 697 scratch = if_sdio_read_scratch(card, &ret);
709 sdio_release_host(card->func); 698 sdio_release_host(card->func);
710 699
700 lbs_deb_sdio("firmware status = %#x\n", scratch);
701 lbs_deb_sdio("scratch ret = %d\n", ret);
702
711 if (ret) 703 if (ret)
712 goto out; 704 goto out;
713 705
714 lbs_deb_sdio("firmware status = %#x\n", scratch);
715 706
707 /*
708 * The manual clearly describes that FEDC is the right code to use
709 * to detect firmware presence, but for SD8686 it is not that simple.
710 * Scratch is also used to store the RX packet length, so we lose
711 * the FEDC value early on. So we use a non-zero check in order
712 * to validate firmware presence.
713 * Additionally, the SD8686 in the Gumstix always has the high scratch
714 * bit set, even when the firmware is not loaded. So we have to
715 * exclude that from the test.
716 */
716 if (scratch == IF_SDIO_FIRMWARE_OK) { 717 if (scratch == IF_SDIO_FIRMWARE_OK) {
717 lbs_deb_sdio("firmware already loaded\n"); 718 lbs_deb_sdio("firmware already loaded\n");
718 goto success; 719 goto success;
720 } else if ((card->model == MODEL_8686) && (scratch & 0x7fff)) {
721 lbs_deb_sdio("firmware may be running\n");
722 goto success;
719 } 723 }
720 724
721 ret = if_sdio_prog_helper(card); 725 ret = lbs_get_firmware(&card->func->dev, lbs_helper_name, lbs_fw_name,
726 card->model, &fw_table[0], &helper, &mainfw);
727 if (ret) {
728 pr_err("failed to find firmware (%d)\n", ret);
729 goto out;
730 }
731
732 ret = if_sdio_prog_helper(card, helper);
722 if (ret) 733 if (ret)
723 goto out; 734 goto out;
724 735
725 ret = if_sdio_prog_real(card); 736 lbs_deb_sdio("Helper firmware loaded\n");
737
738 ret = if_sdio_prog_real(card, mainfw);
726 if (ret) 739 if (ret)
727 goto out; 740 goto out;
728 741
742 lbs_deb_sdio("Firmware loaded\n");
743
729success: 744success:
730 sdio_claim_host(card->func); 745 sdio_claim_host(card->func);
731 sdio_set_block_size(card->func, IF_SDIO_BLOCK_SIZE); 746 sdio_set_block_size(card->func, IF_SDIO_BLOCK_SIZE);
@@ -733,8 +748,12 @@ success:
733 ret = 0; 748 ret = 0;
734 749
735out: 750out:
736 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); 751 if (helper)
752 release_firmware(helper);
753 if (mainfw)
754 release_firmware(mainfw);
737 755
756 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret);
738 return ret; 757 return ret;
739} 758}
740 759
@@ -832,7 +851,7 @@ static int if_sdio_enter_deep_sleep(struct lbs_private *priv)
832 ret = __lbs_cmd(priv, CMD_802_11_DEEP_SLEEP, &cmd, sizeof(cmd), 851 ret = __lbs_cmd(priv, CMD_802_11_DEEP_SLEEP, &cmd, sizeof(cmd),
833 lbs_cmd_copyback, (unsigned long) &cmd); 852 lbs_cmd_copyback, (unsigned long) &cmd);
834 if (ret) 853 if (ret)
835 lbs_pr_err("DEEP_SLEEP cmd failed\n"); 854 netdev_err(priv->dev, "DEEP_SLEEP cmd failed\n");
836 855
837 mdelay(200); 856 mdelay(200);
838 return ret; 857 return ret;
@@ -848,7 +867,7 @@ static int if_sdio_exit_deep_sleep(struct lbs_private *priv)
848 867
849 sdio_writeb(card->func, HOST_POWER_UP, CONFIGURATION_REG, &ret); 868 sdio_writeb(card->func, HOST_POWER_UP, CONFIGURATION_REG, &ret);
850 if (ret) 869 if (ret)
851 lbs_pr_err("sdio_writeb failed!\n"); 870 netdev_err(priv->dev, "sdio_writeb failed!\n");
852 871
853 sdio_release_host(card->func); 872 sdio_release_host(card->func);
854 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); 873 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret);
@@ -865,7 +884,7 @@ static int if_sdio_reset_deep_sleep_wakeup(struct lbs_private *priv)
865 884
866 sdio_writeb(card->func, 0, CONFIGURATION_REG, &ret); 885 sdio_writeb(card->func, 0, CONFIGURATION_REG, &ret);
867 if (ret) 886 if (ret)
868 lbs_pr_err("sdio_writeb failed!\n"); 887 netdev_err(priv->dev, "sdio_writeb failed!\n");
869 888
870 sdio_release_host(card->func); 889 sdio_release_host(card->func);
871 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); 890 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret);
@@ -888,7 +907,7 @@ static void if_sdio_interrupt(struct sdio_func *func)
888 card = sdio_get_drvdata(func); 907 card = sdio_get_drvdata(func);
889 908
890 cause = sdio_readb(card->func, IF_SDIO_H_INT_STATUS, &ret); 909 cause = sdio_readb(card->func, IF_SDIO_H_INT_STATUS, &ret);
891 if (ret) 910 if (ret || !cause)
892 goto out; 911 goto out;
893 912
894 lbs_deb_sdio("interrupt: 0x%X\n", (unsigned)cause); 913 lbs_deb_sdio("interrupt: 0x%X\n", (unsigned)cause);
@@ -938,13 +957,13 @@ static int if_sdio_probe(struct sdio_func *func,
938 "ID: %x", &model) == 1) 957 "ID: %x", &model) == 1)
939 break; 958 break;
940 if (!strcmp(func->card->info[i], "IBIS Wireless SDIO Card")) { 959 if (!strcmp(func->card->info[i], "IBIS Wireless SDIO Card")) {
941 model = IF_SDIO_MODEL_8385; 960 model = MODEL_8385;
942 break; 961 break;
943 } 962 }
944 } 963 }
945 964
946 if (i == func->card->num_info) { 965 if (i == func->card->num_info) {
947 lbs_pr_err("unable to identify card model\n"); 966 pr_err("unable to identify card model\n");
948 return -ENODEV; 967 return -ENODEV;
949 } 968 }
950 969
@@ -956,13 +975,13 @@ static int if_sdio_probe(struct sdio_func *func,
956 card->model = model; 975 card->model = model;
957 976
958 switch (card->model) { 977 switch (card->model) {
959 case IF_SDIO_MODEL_8385: 978 case MODEL_8385:
960 card->scratch_reg = IF_SDIO_SCRATCH_OLD; 979 card->scratch_reg = IF_SDIO_SCRATCH_OLD;
961 break; 980 break;
962 case IF_SDIO_MODEL_8686: 981 case MODEL_8686:
963 card->scratch_reg = IF_SDIO_SCRATCH; 982 card->scratch_reg = IF_SDIO_SCRATCH;
964 break; 983 break;
965 case IF_SDIO_MODEL_8688: 984 case MODEL_8688:
966 default: /* for newer chipsets */ 985 default: /* for newer chipsets */
967 card->scratch_reg = IF_SDIO_FW_STATUS; 986 card->scratch_reg = IF_SDIO_FW_STATUS;
968 break; 987 break;
@@ -972,63 +991,27 @@ static int if_sdio_probe(struct sdio_func *func,
972 card->workqueue = create_workqueue("libertas_sdio"); 991 card->workqueue = create_workqueue("libertas_sdio");
973 INIT_WORK(&card->packet_worker, if_sdio_host_to_card_worker); 992 INIT_WORK(&card->packet_worker, if_sdio_host_to_card_worker);
974 993
975 for (i = 0;i < ARRAY_SIZE(if_sdio_models);i++) { 994 /* Check if we support this card */
976 if (card->model == if_sdio_models[i].model) 995 for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
996 if (card->model == fw_table[i].model)
977 break; 997 break;
978 } 998 }
979 999 if (i == ARRAY_SIZE(fw_table)) {
980 if (i == ARRAY_SIZE(if_sdio_models)) { 1000 pr_err("unknown card model 0x%x\n", card->model);
981 lbs_pr_err("unknown card model 0x%x\n", card->model);
982 ret = -ENODEV; 1001 ret = -ENODEV;
983 goto free; 1002 goto free;
984 } 1003 }
985 1004
986 card->helper = if_sdio_models[i].helper;
987 card->firmware = if_sdio_models[i].firmware;
988
989 kparam_block_sysfs_write(helper_name);
990 if (lbs_helper_name) {
991 char *helper = kstrdup(lbs_helper_name, GFP_KERNEL);
992 if (!helper) {
993 kparam_unblock_sysfs_write(helper_name);
994 ret = -ENOMEM;
995 goto free;
996 }
997 lbs_deb_sdio("overriding helper firmware: %s\n",
998 lbs_helper_name);
999 card->helper = helper;
1000 card->helper_allocated = true;
1001 }
1002 kparam_unblock_sysfs_write(helper_name);
1003
1004 kparam_block_sysfs_write(fw_name);
1005 if (lbs_fw_name) {
1006 char *fw_name = kstrdup(lbs_fw_name, GFP_KERNEL);
1007 if (!fw_name) {
1008 kparam_unblock_sysfs_write(fw_name);
1009 ret = -ENOMEM;
1010 goto free;
1011 }
1012 lbs_deb_sdio("overriding firmware: %s\n", lbs_fw_name);
1013 card->firmware = fw_name;
1014 card->firmware_allocated = true;
1015 }
1016 kparam_unblock_sysfs_write(fw_name);
1017
1018 sdio_claim_host(func); 1005 sdio_claim_host(func);
1019 1006
1020 ret = sdio_enable_func(func); 1007 ret = sdio_enable_func(func);
1021 if (ret) 1008 if (ret)
1022 goto release; 1009 goto release;
1023 1010
1024 ret = sdio_claim_irq(func, if_sdio_interrupt);
1025 if (ret)
1026 goto disable;
1027
1028 /* For 1-bit transfers to the 8686 model, we need to enable the 1011 /* For 1-bit transfers to the 8686 model, we need to enable the
1029 * interrupt flag in the CCCR register. Set the MMC_QUIRK_LENIENT_FN0 1012 * interrupt flag in the CCCR register. Set the MMC_QUIRK_LENIENT_FN0
1030 * bit to allow access to non-vendor registers. */ 1013 * bit to allow access to non-vendor registers. */
1031 if ((card->model == IF_SDIO_MODEL_8686) && 1014 if ((card->model == MODEL_8686) &&
1032 (host->caps & MMC_CAP_SDIO_IRQ) && 1015 (host->caps & MMC_CAP_SDIO_IRQ) &&
1033 (host->ios.bus_width == MMC_BUS_WIDTH_1)) { 1016 (host->ios.bus_width == MMC_BUS_WIDTH_1)) {
1034 u8 reg; 1017 u8 reg;
@@ -1083,21 +1066,34 @@ static int if_sdio_probe(struct sdio_func *func,
1083 priv->exit_deep_sleep = if_sdio_exit_deep_sleep; 1066 priv->exit_deep_sleep = if_sdio_exit_deep_sleep;
1084 priv->reset_deep_sleep_wakeup = if_sdio_reset_deep_sleep_wakeup; 1067 priv->reset_deep_sleep_wakeup = if_sdio_reset_deep_sleep_wakeup;
1085 1068
1086 priv->fw_ready = 1;
1087
1088 sdio_claim_host(func); 1069 sdio_claim_host(func);
1089 1070
1090 /* 1071 /*
1091 * Get rx_unit if the chip is SD8688 or newer. 1072 * Get rx_unit if the chip is SD8688 or newer.
1092 * SD8385 & SD8686 do not have rx_unit. 1073 * SD8385 & SD8686 do not have rx_unit.
1093 */ 1074 */
1094 if ((card->model != IF_SDIO_MODEL_8385) 1075 if ((card->model != MODEL_8385)
1095 && (card->model != IF_SDIO_MODEL_8686)) 1076 && (card->model != MODEL_8686))
1096 card->rx_unit = if_sdio_read_rx_unit(card); 1077 card->rx_unit = if_sdio_read_rx_unit(card);
1097 else 1078 else
1098 card->rx_unit = 0; 1079 card->rx_unit = 0;
1099 1080
1100 /* 1081 /*
1082 * Set up the interrupt handler late.
1083 *
1084 * If we set it up earlier, the (buggy) hardware generates a spurious
1085 * interrupt, even before the interrupt has been enabled, with
1086 * CCCR_INTx = 0.
1087 *
1088 * We register the interrupt handler late so that we can handle any
1089 * spurious interrupts, and also to avoid generation of that known
1090 * spurious interrupt in the first place.
1091 */
1092 ret = sdio_claim_irq(func, if_sdio_interrupt);
1093 if (ret)
1094 goto disable;
1095
1096 /*
1101 * Enable interrupts now that everything is set up 1097 * Enable interrupts now that everything is set up
1102 */ 1098 */
1103 sdio_writeb(func, 0x0f, IF_SDIO_H_INT_MASK, &ret); 1099 sdio_writeb(func, 0x0f, IF_SDIO_H_INT_MASK, &ret);
@@ -1105,10 +1101,12 @@ static int if_sdio_probe(struct sdio_func *func,
1105 if (ret) 1101 if (ret)
1106 goto reclaim; 1102 goto reclaim;
1107 1103
1104 priv->fw_ready = 1;
1105
1108 /* 1106 /*
1109 * FUNC_INIT is required for SD8688 WLAN/BT multiple functions 1107 * FUNC_INIT is required for SD8688 WLAN/BT multiple functions
1110 */ 1108 */
1111 if (card->model == IF_SDIO_MODEL_8688) { 1109 if (card->model == MODEL_8688) {
1112 struct cmd_header cmd; 1110 struct cmd_header cmd;
1113 1111
1114 memset(&cmd, 0, sizeof(cmd)); 1112 memset(&cmd, 0, sizeof(cmd));
@@ -1116,7 +1114,7 @@ static int if_sdio_probe(struct sdio_func *func,
1116 lbs_deb_sdio("send function INIT command\n"); 1114 lbs_deb_sdio("send function INIT command\n");
1117 if (__lbs_cmd(priv, CMD_FUNC_INIT, &cmd, sizeof(cmd), 1115 if (__lbs_cmd(priv, CMD_FUNC_INIT, &cmd, sizeof(cmd),
1118 lbs_cmd_copyback, (unsigned long) &cmd)) 1116 lbs_cmd_copyback, (unsigned long) &cmd))
1119 lbs_pr_alert("CMD_FUNC_INIT cmd failed\n"); 1117 netdev_alert(priv->dev, "CMD_FUNC_INIT cmd failed\n");
1120 } 1118 }
1121 1119
1122 ret = lbs_start_card(priv); 1120 ret = lbs_start_card(priv);
@@ -1165,7 +1163,7 @@ static void if_sdio_remove(struct sdio_func *func)
1165 1163
1166 card = sdio_get_drvdata(func); 1164 card = sdio_get_drvdata(func);
1167 1165
1168 if (user_rmmod && (card->model == IF_SDIO_MODEL_8688)) { 1166 if (user_rmmod && (card->model == MODEL_8688)) {
1169 /* 1167 /*
1170 * FUNC_SHUTDOWN is required for SD8688 WLAN/BT 1168 * FUNC_SHUTDOWN is required for SD8688 WLAN/BT
1171 * multiple functions 1169 * multiple functions
@@ -1178,14 +1176,13 @@ static void if_sdio_remove(struct sdio_func *func)
1178 if (__lbs_cmd(card->priv, CMD_FUNC_SHUTDOWN, 1176 if (__lbs_cmd(card->priv, CMD_FUNC_SHUTDOWN,
1179 &cmd, sizeof(cmd), lbs_cmd_copyback, 1177 &cmd, sizeof(cmd), lbs_cmd_copyback,
1180 (unsigned long) &cmd)) 1178 (unsigned long) &cmd))
1181 lbs_pr_alert("CMD_FUNC_SHUTDOWN cmd failed\n"); 1179 pr_alert("CMD_FUNC_SHUTDOWN cmd failed\n");
1182 } 1180 }
1183 1181
1184 1182
1185 lbs_deb_sdio("call remove card\n"); 1183 lbs_deb_sdio("call remove card\n");
1186 lbs_stop_card(card->priv); 1184 lbs_stop_card(card->priv);
1187 lbs_remove_card(card->priv); 1185 lbs_remove_card(card->priv);
1188 card->priv->surpriseremoved = 1;
1189 1186
1190 flush_workqueue(card->workqueue); 1187 flush_workqueue(card->workqueue);
1191 destroy_workqueue(card->workqueue); 1188 destroy_workqueue(card->workqueue);
@@ -1218,20 +1215,19 @@ static int if_sdio_suspend(struct device *dev)
1218 1215
1219 mmc_pm_flag_t flags = sdio_get_host_pm_caps(func); 1216 mmc_pm_flag_t flags = sdio_get_host_pm_caps(func);
1220 1217
1221 lbs_pr_info("%s: suspend: PM flags = 0x%x\n", 1218 dev_info(dev, "%s: suspend: PM flags = 0x%x\n",
1222 sdio_func_id(func), flags); 1219 sdio_func_id(func), flags);
1223 1220
1224 /* If we aren't being asked to wake on anything, we should bail out 1221 /* If we aren't being asked to wake on anything, we should bail out
1225 * and let the SD stack power down the card. 1222 * and let the SD stack power down the card.
1226 */ 1223 */
1227 if (card->priv->wol_criteria == EHS_REMOVE_WAKEUP) { 1224 if (card->priv->wol_criteria == EHS_REMOVE_WAKEUP) {
1228 lbs_pr_info("Suspend without wake params -- " 1225 dev_info(dev, "Suspend without wake params -- powering down card\n");
1229 "powering down card.");
1230 return -ENOSYS; 1226 return -ENOSYS;
1231 } 1227 }
1232 1228
1233 if (!(flags & MMC_PM_KEEP_POWER)) { 1229 if (!(flags & MMC_PM_KEEP_POWER)) {
1234 lbs_pr_err("%s: cannot remain alive while host is suspended\n", 1230 dev_err(dev, "%s: cannot remain alive while host is suspended\n",
1235 sdio_func_id(func)); 1231 sdio_func_id(func));
1236 return -ENOSYS; 1232 return -ENOSYS;
1237 } 1233 }
@@ -1253,7 +1249,7 @@ static int if_sdio_resume(struct device *dev)
1253 struct if_sdio_card *card = sdio_get_drvdata(func); 1249 struct if_sdio_card *card = sdio_get_drvdata(func);
1254 int ret; 1250 int ret;
1255 1251
1256 lbs_pr_info("%s: resume: we're back\n", sdio_func_id(func)); 1252 dev_info(dev, "%s: resume: we're back\n", sdio_func_id(func));
1257 1253
1258 ret = lbs_resume(card->priv); 1254 ret = lbs_resume(card->priv);
1259 1255
diff --git a/drivers/net/wireless/libertas/if_sdio.h b/drivers/net/wireless/libertas/if_sdio.h
index 12179c1dc9c9..62fda3592f67 100644
--- a/drivers/net/wireless/libertas/if_sdio.h
+++ b/drivers/net/wireless/libertas/if_sdio.h
@@ -12,10 +12,6 @@
12#ifndef _LBS_IF_SDIO_H 12#ifndef _LBS_IF_SDIO_H
13#define _LBS_IF_SDIO_H 13#define _LBS_IF_SDIO_H
14 14
15#define IF_SDIO_MODEL_8385 0x04
16#define IF_SDIO_MODEL_8686 0x0b
17#define IF_SDIO_MODEL_8688 0x10
18
19#define IF_SDIO_IOPORT 0x00 15#define IF_SDIO_IOPORT 0x00
20 16
21#define IF_SDIO_H_INT_MASK 0x04 17#define IF_SDIO_H_INT_MASK 0x04
diff --git a/drivers/net/wireless/libertas/if_spi.c b/drivers/net/wireless/libertas/if_spi.c
index fe3f08028eb3..463352c890d7 100644
--- a/drivers/net/wireless/libertas/if_spi.c
+++ b/drivers/net/wireless/libertas/if_spi.c
@@ -17,13 +17,13 @@
17 * (at your option) any later version. 17 * (at your option) any later version.
18 */ 18 */
19 19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
20#include <linux/moduleparam.h> 22#include <linux/moduleparam.h>
21#include <linux/firmware.h> 23#include <linux/firmware.h>
22#include <linux/jiffies.h> 24#include <linux/jiffies.h>
23#include <linux/kthread.h>
24#include <linux/list.h> 25#include <linux/list.h>
25#include <linux/netdevice.h> 26#include <linux/netdevice.h>
26#include <linux/semaphore.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/spi/libertas_spi.h> 28#include <linux/spi/libertas_spi.h>
29#include <linux/spi/spi.h> 29#include <linux/spi/spi.h>
@@ -34,14 +34,17 @@
34#include "dev.h" 34#include "dev.h"
35#include "if_spi.h" 35#include "if_spi.h"
36 36
37struct if_spi_packet {
38 struct list_head list;
39 u16 blen;
40 u8 buffer[0] __attribute__((aligned(4)));
41};
42
37struct if_spi_card { 43struct if_spi_card {
38 struct spi_device *spi; 44 struct spi_device *spi;
39 struct lbs_private *priv; 45 struct lbs_private *priv;
40 struct libertas_spi_platform_data *pdata; 46 struct libertas_spi_platform_data *pdata;
41 47
42 char helper_fw_name[IF_SPI_FW_NAME_MAX];
43 char main_fw_name[IF_SPI_FW_NAME_MAX];
44
45 /* The card ID and card revision, as reported by the hardware. */ 48 /* The card ID and card revision, as reported by the hardware. */
46 u16 card_id; 49 u16 card_id;
47 u8 card_rev; 50 u8 card_rev;
@@ -54,26 +57,66 @@ struct if_spi_card {
54 unsigned long spu_reg_delay; 57 unsigned long spu_reg_delay;
55 58
56 /* Handles all SPI communication (except for FW load) */ 59 /* Handles all SPI communication (except for FW load) */
57 struct task_struct *spi_thread; 60 struct workqueue_struct *workqueue;
58 int run_thread; 61 struct work_struct packet_work;
59 62 struct work_struct resume_work;
60 /* Used to wake up the spi_thread */
61 struct semaphore spi_ready;
62 struct semaphore spi_thread_terminated;
63 63
64 u8 cmd_buffer[IF_SPI_CMD_BUF_SIZE]; 64 u8 cmd_buffer[IF_SPI_CMD_BUF_SIZE];
65
66 /* A buffer of incoming packets from libertas core.
67 * Since we can't sleep in hw_host_to_card, we have to buffer
68 * them. */
69 struct list_head cmd_packet_list;
70 struct list_head data_packet_list;
71
72 /* Protects cmd_packet_list and data_packet_list */
73 spinlock_t buffer_lock;
74
75 /* True is card suspended */
76 u8 suspended;
65}; 77};
66 78
67static void free_if_spi_card(struct if_spi_card *card) 79static void free_if_spi_card(struct if_spi_card *card)
68{ 80{
81 struct list_head *cursor, *next;
82 struct if_spi_packet *packet;
83
84 list_for_each_safe(cursor, next, &card->cmd_packet_list) {
85 packet = container_of(cursor, struct if_spi_packet, list);
86 list_del(&packet->list);
87 kfree(packet);
88 }
89 list_for_each_safe(cursor, next, &card->data_packet_list) {
90 packet = container_of(cursor, struct if_spi_packet, list);
91 list_del(&packet->list);
92 kfree(packet);
93 }
69 spi_set_drvdata(card->spi, NULL); 94 spi_set_drvdata(card->spi, NULL);
70 kfree(card); 95 kfree(card);
71} 96}
72 97
73static struct chip_ident chip_id_to_device_name[] = { 98#define MODEL_8385 0x04
74 { .chip_id = 0x04, .name = 8385 }, 99#define MODEL_8686 0x0b
75 { .chip_id = 0x0b, .name = 8686 }, 100#define MODEL_8688 0x10
101
102static const struct lbs_fw_table fw_table[] = {
103 { MODEL_8385, "libertas/gspi8385_helper.bin", "libertas/gspi8385.bin" },
104 { MODEL_8385, "libertas/gspi8385_hlp.bin", "libertas/gspi8385.bin" },
105 { MODEL_8686, "libertas/gspi8686_v9_helper.bin", "libertas/gspi8686_v9.bin" },
106 { MODEL_8686, "libertas/gspi8686_hlp.bin", "libertas/gspi8686.bin" },
107 { MODEL_8688, "libertas/gspi8688_helper.bin", "libertas/gspi8688.bin" },
108 { 0, NULL, NULL }
76}; 109};
110MODULE_FIRMWARE("libertas/gspi8385_helper.bin");
111MODULE_FIRMWARE("libertas/gspi8385_hlp.bin");
112MODULE_FIRMWARE("libertas/gspi8385.bin");
113MODULE_FIRMWARE("libertas/gspi8686_v9_helper.bin");
114MODULE_FIRMWARE("libertas/gspi8686_v9.bin");
115MODULE_FIRMWARE("libertas/gspi8686_hlp.bin");
116MODULE_FIRMWARE("libertas/gspi8686.bin");
117MODULE_FIRMWARE("libertas/gspi8688_helper.bin");
118MODULE_FIRMWARE("libertas/gspi8688.bin");
119
77 120
78/* 121/*
79 * SPI Interface Unit Routines 122 * SPI Interface Unit Routines
@@ -102,8 +145,10 @@ static void spu_transaction_finish(struct if_spi_card *card)
102 card->prev_xfer_time = jiffies; 145 card->prev_xfer_time = jiffies;
103} 146}
104 147
105/* Write out a byte buffer to an SPI register, 148/*
106 * using a series of 16-bit transfers. */ 149 * Write out a byte buffer to an SPI register,
150 * using a series of 16-bit transfers.
151 */
107static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len) 152static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len)
108{ 153{
109 int err = 0; 154 int err = 0;
@@ -167,8 +212,10 @@ static int spu_read(struct if_spi_card *card, u16 reg, u8 *buf, int len)
167 struct spi_transfer dummy_trans; 212 struct spi_transfer dummy_trans;
168 struct spi_transfer data_trans; 213 struct spi_transfer data_trans;
169 214
170 /* You must take an even number of bytes from the SPU, even if you 215 /*
171 * don't care about the last one. */ 216 * You must take an even number of bytes from the SPU, even if you
217 * don't care about the last one.
218 */
172 BUG_ON(len & 0x1); 219 BUG_ON(len & 0x1);
173 220
174 spu_transaction_init(card); 221 spu_transaction_init(card);
@@ -217,8 +264,10 @@ static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val)
217 return ret; 264 return ret;
218} 265}
219 266
220/* Read 32 bits from an SPI register. 267/*
221 * The low 16 bits are read first. */ 268 * Read 32 bits from an SPI register.
269 * The low 16 bits are read first.
270 */
222static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val) 271static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val)
223{ 272{
224 __le32 buf; 273 __le32 buf;
@@ -230,13 +279,15 @@ static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val)
230 return err; 279 return err;
231} 280}
232 281
233/* Keep reading 16 bits from an SPI register until you get the correct result. 282/*
283 * Keep reading 16 bits from an SPI register until you get the correct result.
234 * 284 *
235 * If mask = 0, the correct result is any non-zero number. 285 * If mask = 0, the correct result is any non-zero number.
236 * If mask != 0, the correct result is any number where 286 * If mask != 0, the correct result is any number where
237 * number & target_mask == target 287 * number & target_mask == target
238 * 288 *
239 * Returns -ETIMEDOUT if a second passes without the correct result. */ 289 * Returns -ETIMEDOUT if a second passes without the correct result.
290 */
240static int spu_wait_for_u16(struct if_spi_card *card, u16 reg, 291static int spu_wait_for_u16(struct if_spi_card *card, u16 reg,
241 u16 target_mask, u16 target) 292 u16 target_mask, u16 target)
242{ 293{
@@ -256,16 +307,17 @@ static int spu_wait_for_u16(struct if_spi_card *card, u16 reg,
256 } 307 }
257 udelay(100); 308 udelay(100);
258 if (time_after(jiffies, timeout)) { 309 if (time_after(jiffies, timeout)) {
259 lbs_pr_err("%s: timeout with val=%02x, " 310 pr_err("%s: timeout with val=%02x, target_mask=%02x, target=%02x\n",
260 "target_mask=%02x, target=%02x\n",
261 __func__, val, target_mask, target); 311 __func__, val, target_mask, target);
262 return -ETIMEDOUT; 312 return -ETIMEDOUT;
263 } 313 }
264 } 314 }
265} 315}
266 316
267/* Read 16 bits from an SPI register until you receive a specific value. 317/*
268 * Returns -ETIMEDOUT if a 4 tries pass without success. */ 318 * Read 16 bits from an SPI register until you receive a specific value.
319 * Returns -ETIMEDOUT if a 4 tries pass without success.
320 */
269static int spu_wait_for_u32(struct if_spi_card *card, u32 reg, u32 target) 321static int spu_wait_for_u32(struct if_spi_card *card, u32 reg, u32 target)
270{ 322{
271 int err, try; 323 int err, try;
@@ -287,8 +339,10 @@ static int spu_set_interrupt_mode(struct if_spi_card *card,
287{ 339{
288 int err = 0; 340 int err = 0;
289 341
290 /* We can suppress a host interrupt by clearing the appropriate 342 /*
291 * bit in the "host interrupt status mask" register */ 343 * We can suppress a host interrupt by clearing the appropriate
344 * bit in the "host interrupt status mask" register
345 */
292 if (suppress_host_int) { 346 if (suppress_host_int) {
293 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0); 347 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0);
294 if (err) 348 if (err)
@@ -304,10 +358,12 @@ static int spu_set_interrupt_mode(struct if_spi_card *card,
304 return err; 358 return err;
305 } 359 }
306 360
307 /* If auto-interrupts are on, the completion of certain transactions 361 /*
362 * If auto-interrupts are on, the completion of certain transactions
308 * will trigger an interrupt automatically. If auto-interrupts 363 * will trigger an interrupt automatically. If auto-interrupts
309 * are off, we need to set the "Card Interrupt Cause" register to 364 * are off, we need to set the "Card Interrupt Cause" register to
310 * trigger a card interrupt. */ 365 * trigger a card interrupt.
366 */
311 if (auto_int) { 367 if (auto_int) {
312 err = spu_write_u16(card, IF_SPI_HOST_INT_CTRL_REG, 368 err = spu_write_u16(card, IF_SPI_HOST_INT_CTRL_REG,
313 IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO | 369 IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO |
@@ -350,7 +406,7 @@ static int spu_set_bus_mode(struct if_spi_card *card, u16 mode)
350 if (err) 406 if (err)
351 return err; 407 return err;
352 if ((rval & 0xF) != mode) { 408 if ((rval & 0xF) != mode) {
353 lbs_pr_err("Can't read bus mode register.\n"); 409 pr_err("Can't read bus mode register\n");
354 return -EIO; 410 return -EIO;
355 } 411 }
356 return 0; 412 return 0;
@@ -361,8 +417,10 @@ static int spu_init(struct if_spi_card *card, int use_dummy_writes)
361 int err = 0; 417 int err = 0;
362 u32 delay; 418 u32 delay;
363 419
364 /* We have to start up in timed delay mode so that we can safely 420 /*
365 * read the Delay Read Register. */ 421 * We have to start up in timed delay mode so that we can safely
422 * read the Delay Read Register.
423 */
366 card->use_dummy_writes = 0; 424 card->use_dummy_writes = 0;
367 err = spu_set_bus_mode(card, 425 err = spu_set_bus_mode(card,
368 IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING | 426 IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING |
@@ -399,46 +457,44 @@ static int spu_init(struct if_spi_card *card, int use_dummy_writes)
399 * Firmware Loading 457 * Firmware Loading
400 */ 458 */
401 459
402static int if_spi_prog_helper_firmware(struct if_spi_card *card) 460static int if_spi_prog_helper_firmware(struct if_spi_card *card,
461 const struct firmware *firmware)
403{ 462{
404 int err = 0; 463 int err = 0;
405 const struct firmware *firmware = NULL;
406 int bytes_remaining; 464 int bytes_remaining;
407 const u8 *fw; 465 const u8 *fw;
408 u8 temp[HELPER_FW_LOAD_CHUNK_SZ]; 466 u8 temp[HELPER_FW_LOAD_CHUNK_SZ];
409 struct spi_device *spi = card->spi;
410 467
411 lbs_deb_enter(LBS_DEB_SPI); 468 lbs_deb_enter(LBS_DEB_SPI);
412 469
413 err = spu_set_interrupt_mode(card, 1, 0); 470 err = spu_set_interrupt_mode(card, 1, 0);
414 if (err) 471 if (err)
415 goto out; 472 goto out;
416 /* Get helper firmware image */ 473
417 err = request_firmware(&firmware, card->helper_fw_name, &spi->dev);
418 if (err) {
419 lbs_pr_err("request_firmware failed with err = %d\n", err);
420 goto out;
421 }
422 bytes_remaining = firmware->size; 474 bytes_remaining = firmware->size;
423 fw = firmware->data; 475 fw = firmware->data;
424 476
425 /* Load helper firmware image */ 477 /* Load helper firmware image */
426 while (bytes_remaining > 0) { 478 while (bytes_remaining > 0) {
427 /* Scratch pad 1 should contain the number of bytes we 479 /*
428 * want to download to the firmware */ 480 * Scratch pad 1 should contain the number of bytes we
481 * want to download to the firmware
482 */
429 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, 483 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG,
430 HELPER_FW_LOAD_CHUNK_SZ); 484 HELPER_FW_LOAD_CHUNK_SZ);
431 if (err) 485 if (err)
432 goto release_firmware; 486 goto out;
433 487
434 err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG, 488 err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG,
435 IF_SPI_HIST_CMD_DOWNLOAD_RDY, 489 IF_SPI_HIST_CMD_DOWNLOAD_RDY,
436 IF_SPI_HIST_CMD_DOWNLOAD_RDY); 490 IF_SPI_HIST_CMD_DOWNLOAD_RDY);
437 if (err) 491 if (err)
438 goto release_firmware; 492 goto out;
439 493
440 /* Feed the data into the command read/write port reg 494 /*
441 * in chunks of 64 bytes */ 495 * Feed the data into the command read/write port reg
496 * in chunks of 64 bytes
497 */
442 memset(temp, 0, sizeof(temp)); 498 memset(temp, 0, sizeof(temp));
443 memcpy(temp, fw, 499 memcpy(temp, fw,
444 min(bytes_remaining, HELPER_FW_LOAD_CHUNK_SZ)); 500 min(bytes_remaining, HELPER_FW_LOAD_CHUNK_SZ));
@@ -446,59 +502,63 @@ static int if_spi_prog_helper_firmware(struct if_spi_card *card)
446 err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG, 502 err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG,
447 temp, HELPER_FW_LOAD_CHUNK_SZ); 503 temp, HELPER_FW_LOAD_CHUNK_SZ);
448 if (err) 504 if (err)
449 goto release_firmware; 505 goto out;
450 506
451 /* Interrupt the boot code */ 507 /* Interrupt the boot code */
452 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0); 508 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
453 if (err) 509 if (err)
454 goto release_firmware; 510 goto out;
455 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, 511 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG,
456 IF_SPI_CIC_CMD_DOWNLOAD_OVER); 512 IF_SPI_CIC_CMD_DOWNLOAD_OVER);
457 if (err) 513 if (err)
458 goto release_firmware; 514 goto out;
459 bytes_remaining -= HELPER_FW_LOAD_CHUNK_SZ; 515 bytes_remaining -= HELPER_FW_LOAD_CHUNK_SZ;
460 fw += HELPER_FW_LOAD_CHUNK_SZ; 516 fw += HELPER_FW_LOAD_CHUNK_SZ;
461 } 517 }
462 518
463 /* Once the helper / single stage firmware download is complete, 519 /*
520 * Once the helper / single stage firmware download is complete,
464 * write 0 to scratch pad 1 and interrupt the 521 * write 0 to scratch pad 1 and interrupt the
465 * bootloader. This completes the helper download. */ 522 * bootloader. This completes the helper download.
523 */
466 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, FIRMWARE_DNLD_OK); 524 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, FIRMWARE_DNLD_OK);
467 if (err) 525 if (err)
468 goto release_firmware; 526 goto out;
469 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0); 527 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
470 if (err) 528 if (err)
471 goto release_firmware; 529 goto out;
472 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, 530 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG,
473 IF_SPI_CIC_CMD_DOWNLOAD_OVER); 531 IF_SPI_CIC_CMD_DOWNLOAD_OVER);
474 goto release_firmware; 532 goto out;
475 533
476 lbs_deb_spi("waiting for helper to boot...\n"); 534 lbs_deb_spi("waiting for helper to boot...\n");
477 535
478release_firmware:
479 release_firmware(firmware);
480out: 536out:
481 if (err) 537 if (err)
482 lbs_pr_err("failed to load helper firmware (err=%d)\n", err); 538 pr_err("failed to load helper firmware (err=%d)\n", err);
483 lbs_deb_leave_args(LBS_DEB_SPI, "err %d", err); 539 lbs_deb_leave_args(LBS_DEB_SPI, "err %d", err);
484 return err; 540 return err;
485} 541}
486 542
487/* Returns the length of the next packet the firmware expects us to send 543/*
488 * Sets crc_err if the previous transfer had a CRC error. */ 544 * Returns the length of the next packet the firmware expects us to send.
545 * Sets crc_err if the previous transfer had a CRC error.
546 */
489static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card, 547static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card,
490 int *crc_err) 548 int *crc_err)
491{ 549{
492 u16 len; 550 u16 len;
493 int err = 0; 551 int err = 0;
494 552
495 /* wait until the host interrupt status register indicates 553 /*
496 * that we are ready to download */ 554 * wait until the host interrupt status register indicates
555 * that we are ready to download
556 */
497 err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG, 557 err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG,
498 IF_SPI_HIST_CMD_DOWNLOAD_RDY, 558 IF_SPI_HIST_CMD_DOWNLOAD_RDY,
499 IF_SPI_HIST_CMD_DOWNLOAD_RDY); 559 IF_SPI_HIST_CMD_DOWNLOAD_RDY);
500 if (err) { 560 if (err) {
501 lbs_pr_err("timed out waiting for host_int_status\n"); 561 pr_err("timed out waiting for host_int_status\n");
502 return err; 562 return err;
503 } 563 }
504 564
@@ -508,9 +568,8 @@ static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card,
508 return err; 568 return err;
509 569
510 if (len > IF_SPI_CMD_BUF_SIZE) { 570 if (len > IF_SPI_CMD_BUF_SIZE) {
511 lbs_pr_err("firmware load device requested a larger " 571 pr_err("firmware load device requested a larger transfer than we are prepared to handle (len = %d)\n",
512 "tranfer than we are prepared to " 572 len);
513 "handle. (len = %d)\n", len);
514 return -EIO; 573 return -EIO;
515 } 574 }
516 if (len & 0x1) { 575 if (len & 0x1) {
@@ -523,13 +582,13 @@ static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card,
523 return len; 582 return len;
524} 583}
525 584
526static int if_spi_prog_main_firmware(struct if_spi_card *card) 585static int if_spi_prog_main_firmware(struct if_spi_card *card,
586 const struct firmware *firmware)
527{ 587{
588 struct lbs_private *priv = card->priv;
528 int len, prev_len; 589 int len, prev_len;
529 int bytes, crc_err = 0, err = 0; 590 int bytes, crc_err = 0, err = 0;
530 const struct firmware *firmware = NULL;
531 const u8 *fw; 591 const u8 *fw;
532 struct spi_device *spi = card->spi;
533 u16 num_crc_errs; 592 u16 num_crc_errs;
534 593
535 lbs_deb_enter(LBS_DEB_SPI); 594 lbs_deb_enter(LBS_DEB_SPI);
@@ -538,19 +597,12 @@ static int if_spi_prog_main_firmware(struct if_spi_card *card)
538 if (err) 597 if (err)
539 goto out; 598 goto out;
540 599
541 /* Get firmware image */
542 err = request_firmware(&firmware, card->main_fw_name, &spi->dev);
543 if (err) {
544 lbs_pr_err("%s: can't get firmware '%s' from kernel. "
545 "err = %d\n", __func__, card->main_fw_name, err);
546 goto out;
547 }
548
549 err = spu_wait_for_u16(card, IF_SPI_SCRATCH_1_REG, 0, 0); 600 err = spu_wait_for_u16(card, IF_SPI_SCRATCH_1_REG, 0, 0);
550 if (err) { 601 if (err) {
551 lbs_pr_err("%s: timed out waiting for initial " 602 netdev_err(priv->dev,
552 "scratch reg = 0\n", __func__); 603 "%s: timed out waiting for initial scratch reg = 0\n",
553 goto release_firmware; 604 __func__);
605 goto out;
554 } 606 }
555 607
556 num_crc_errs = 0; 608 num_crc_errs = 0;
@@ -560,22 +612,23 @@ static int if_spi_prog_main_firmware(struct if_spi_card *card)
560 while ((len = if_spi_prog_main_firmware_check_len(card, &crc_err))) { 612 while ((len = if_spi_prog_main_firmware_check_len(card, &crc_err))) {
561 if (len < 0) { 613 if (len < 0) {
562 err = len; 614 err = len;
563 goto release_firmware; 615 goto out;
564 } 616 }
565 if (bytes < 0) { 617 if (bytes < 0) {
566 /* If there are no more bytes left, we would normally 618 /*
567 * expect to have terminated with len = 0 */ 619 * If there are no more bytes left, we would normally
568 lbs_pr_err("Firmware load wants more bytes " 620 * expect to have terminated with len = 0
569 "than we have to offer.\n"); 621 */
622 netdev_err(priv->dev,
623 "Firmware load wants more bytes than we have to offer.\n");
570 break; 624 break;
571 } 625 }
572 if (crc_err) { 626 if (crc_err) {
573 /* Previous transfer failed. */ 627 /* Previous transfer failed. */
574 if (++num_crc_errs > MAX_MAIN_FW_LOAD_CRC_ERR) { 628 if (++num_crc_errs > MAX_MAIN_FW_LOAD_CRC_ERR) {
575 lbs_pr_err("Too many CRC errors encountered " 629 pr_err("Too many CRC errors encountered in firmware load.\n");
576 "in firmware load.\n");
577 err = -EIO; 630 err = -EIO;
578 goto release_firmware; 631 goto out;
579 } 632 }
580 } else { 633 } else {
581 /* Previous transfer succeeded. Advance counters. */ 634 /* Previous transfer succeeded. Advance counters. */
@@ -590,36 +643,32 @@ static int if_spi_prog_main_firmware(struct if_spi_card *card)
590 643
591 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0); 644 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
592 if (err) 645 if (err)
593 goto release_firmware; 646 goto out;
594 err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG, 647 err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG,
595 card->cmd_buffer, len); 648 card->cmd_buffer, len);
596 if (err) 649 if (err)
597 goto release_firmware; 650 goto out;
598 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG , 651 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG ,
599 IF_SPI_CIC_CMD_DOWNLOAD_OVER); 652 IF_SPI_CIC_CMD_DOWNLOAD_OVER);
600 if (err) 653 if (err)
601 goto release_firmware; 654 goto out;
602 prev_len = len; 655 prev_len = len;
603 } 656 }
604 if (bytes > prev_len) { 657 if (bytes > prev_len) {
605 lbs_pr_err("firmware load wants fewer bytes than " 658 pr_err("firmware load wants fewer bytes than we have to offer\n");
606 "we have to offer.\n");
607 } 659 }
608 660
609 /* Confirm firmware download */ 661 /* Confirm firmware download */
610 err = spu_wait_for_u32(card, IF_SPI_SCRATCH_4_REG, 662 err = spu_wait_for_u32(card, IF_SPI_SCRATCH_4_REG,
611 SUCCESSFUL_FW_DOWNLOAD_MAGIC); 663 SUCCESSFUL_FW_DOWNLOAD_MAGIC);
612 if (err) { 664 if (err) {
613 lbs_pr_err("failed to confirm the firmware download\n"); 665 pr_err("failed to confirm the firmware download\n");
614 goto release_firmware; 666 goto out;
615 } 667 }
616 668
617release_firmware:
618 release_firmware(firmware);
619
620out: 669out:
621 if (err) 670 if (err)
622 lbs_pr_err("failed to load firmware (err=%d)\n", err); 671 pr_err("failed to load firmware (err=%d)\n", err);
623 lbs_deb_leave_args(LBS_DEB_SPI, "err %d", err); 672 lbs_deb_leave_args(LBS_DEB_SPI, "err %d", err);
624 return err; 673 return err;
625} 674}
@@ -627,7 +676,7 @@ out:
627/* 676/*
628 * SPI Transfer Thread 677 * SPI Transfer Thread
629 * 678 *
630 * The SPI thread handles all SPI transfers, so there is no need for a lock. 679 * The SPI worker handles all SPI transfers, so there is no need for a lock.
631 */ 680 */
632 681
633/* Move a command from the card to the host */ 682/* Move a command from the card to the host */
@@ -639,14 +688,18 @@ static int if_spi_c2h_cmd(struct if_spi_card *card)
639 u16 len; 688 u16 len;
640 u8 i; 689 u8 i;
641 690
642 /* We need a buffer big enough to handle whatever people send to 691 /*
643 * hw_host_to_card */ 692 * We need a buffer big enough to handle whatever people send to
693 * hw_host_to_card
694 */
644 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_CMD_BUFFER_SIZE); 695 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_CMD_BUFFER_SIZE);
645 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_UPLD_SIZE); 696 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_UPLD_SIZE);
646 697
647 /* It's just annoying if the buffer size isn't a multiple of 4, because 698 /*
648 * then we might have len < IF_SPI_CMD_BUF_SIZE but 699 * It's just annoying if the buffer size isn't a multiple of 4, because
649 * ALIGN(len, 4) > IF_SPI_CMD_BUF_SIZE */ 700 * then we might have len < IF_SPI_CMD_BUF_SIZE but
701 * ALIGN(len, 4) > IF_SPI_CMD_BUF_SIZE
702 */
650 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE % 4 != 0); 703 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE % 4 != 0);
651 704
652 lbs_deb_enter(LBS_DEB_SPI); 705 lbs_deb_enter(LBS_DEB_SPI);
@@ -656,13 +709,13 @@ static int if_spi_c2h_cmd(struct if_spi_card *card)
656 if (err) 709 if (err)
657 goto out; 710 goto out;
658 if (!len) { 711 if (!len) {
659 lbs_pr_err("%s: error: card has no data for host\n", 712 netdev_err(priv->dev, "%s: error: card has no data for host\n",
660 __func__); 713 __func__);
661 err = -EINVAL; 714 err = -EINVAL;
662 goto out; 715 goto out;
663 } else if (len > IF_SPI_CMD_BUF_SIZE) { 716 } else if (len > IF_SPI_CMD_BUF_SIZE) {
664 lbs_pr_err("%s: error: response packet too large: " 717 netdev_err(priv->dev,
665 "%d bytes, but maximum is %d\n", 718 "%s: error: response packet too large: %d bytes, but maximum is %d\n",
666 __func__, len, IF_SPI_CMD_BUF_SIZE); 719 __func__, len, IF_SPI_CMD_BUF_SIZE);
667 err = -EINVAL; 720 err = -EINVAL;
668 goto out; 721 goto out;
@@ -684,7 +737,7 @@ static int if_spi_c2h_cmd(struct if_spi_card *card)
684 737
685out: 738out:
686 if (err) 739 if (err)
687 lbs_pr_err("%s: err=%d\n", __func__, err); 740 netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
688 lbs_deb_leave(LBS_DEB_SPI); 741 lbs_deb_leave(LBS_DEB_SPI);
689 return err; 742 return err;
690} 743}
@@ -692,6 +745,7 @@ out:
692/* Move data from the card to the host */ 745/* Move data from the card to the host */
693static int if_spi_c2h_data(struct if_spi_card *card) 746static int if_spi_c2h_data(struct if_spi_card *card)
694{ 747{
748 struct lbs_private *priv = card->priv;
695 struct sk_buff *skb; 749 struct sk_buff *skb;
696 char *data; 750 char *data;
697 u16 len; 751 u16 len;
@@ -704,13 +758,13 @@ static int if_spi_c2h_data(struct if_spi_card *card)
704 if (err) 758 if (err)
705 goto out; 759 goto out;
706 if (!len) { 760 if (!len) {
707 lbs_pr_err("%s: error: card has no data for host\n", 761 netdev_err(priv->dev, "%s: error: card has no data for host\n",
708 __func__); 762 __func__);
709 err = -EINVAL; 763 err = -EINVAL;
710 goto out; 764 goto out;
711 } else if (len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) { 765 } else if (len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
712 lbs_pr_err("%s: error: card has %d bytes of data, but " 766 netdev_err(priv->dev,
713 "our maximum skb size is %zu\n", 767 "%s: error: card has %d bytes of data, but our maximum skb size is %zu\n",
714 __func__, len, MRVDRV_ETH_RX_PACKET_BUFFER_SIZE); 768 __func__, len, MRVDRV_ETH_RX_PACKET_BUFFER_SIZE);
715 err = -EINVAL; 769 err = -EINVAL;
716 goto out; 770 goto out;
@@ -742,11 +796,47 @@ free_skb:
742 dev_kfree_skb(skb); 796 dev_kfree_skb(skb);
743out: 797out:
744 if (err) 798 if (err)
745 lbs_pr_err("%s: err=%d\n", __func__, err); 799 netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
746 lbs_deb_leave(LBS_DEB_SPI); 800 lbs_deb_leave(LBS_DEB_SPI);
747 return err; 801 return err;
748} 802}
749 803
804/* Move data or a command from the host to the card. */
805static void if_spi_h2c(struct if_spi_card *card,
806 struct if_spi_packet *packet, int type)
807{
808 struct lbs_private *priv = card->priv;
809 int err = 0;
810 u16 int_type, port_reg;
811
812 switch (type) {
813 case MVMS_DAT:
814 int_type = IF_SPI_CIC_TX_DOWNLOAD_OVER;
815 port_reg = IF_SPI_DATA_RDWRPORT_REG;
816 break;
817 case MVMS_CMD:
818 int_type = IF_SPI_CIC_CMD_DOWNLOAD_OVER;
819 port_reg = IF_SPI_CMD_RDWRPORT_REG;
820 break;
821 default:
822 netdev_err(priv->dev, "can't transfer buffer of type %d\n",
823 type);
824 err = -EINVAL;
825 goto out;
826 }
827
828 /* Write the data to the card */
829 err = spu_write(card, port_reg, packet->buffer, packet->blen);
830 if (err)
831 goto out;
832
833out:
834 kfree(packet);
835
836 if (err)
837 netdev_err(priv->dev, "%s: error %d\n", __func__, err);
838}
839
750/* Inform the host about a card event */ 840/* Inform the host about a card event */
751static void if_spi_e2h(struct if_spi_card *card) 841static void if_spi_e2h(struct if_spi_card *card)
752{ 842{
@@ -768,102 +858,154 @@ static void if_spi_e2h(struct if_spi_card *card)
768 lbs_queue_event(priv, cause & 0xff); 858 lbs_queue_event(priv, cause & 0xff);
769out: 859out:
770 if (err) 860 if (err)
771 lbs_pr_err("%s: error %d\n", __func__, err); 861 netdev_err(priv->dev, "%s: error %d\n", __func__, err);
772} 862}
773 863
774static int lbs_spi_thread(void *data) 864static void if_spi_host_to_card_worker(struct work_struct *work)
775{ 865{
776 int err; 866 int err;
777 struct if_spi_card *card = data; 867 struct if_spi_card *card;
778 u16 hiStatus; 868 u16 hiStatus;
869 unsigned long flags;
870 struct if_spi_packet *packet;
871 struct lbs_private *priv;
779 872
780 while (1) { 873 card = container_of(work, struct if_spi_card, packet_work);
781 /* Wait to be woken up by one of two things. First, our ISR 874 priv = card->priv;
782 * could tell us that something happened on the WLAN.
783 * Secondly, libertas could call hw_host_to_card with more
784 * data, which we might be able to send.
785 */
786 do {
787 err = down_interruptible(&card->spi_ready);
788 if (!card->run_thread) {
789 up(&card->spi_thread_terminated);
790 do_exit(0);
791 }
792 } while (err == EINTR);
793 875
794 /* Read the host interrupt status register to see what we 876 lbs_deb_enter(LBS_DEB_SPI);
795 * can do. */ 877
796 err = spu_read_u16(card, IF_SPI_HOST_INT_STATUS_REG, 878 /*
797 &hiStatus); 879 * Read the host interrupt status register to see what we
798 if (err) { 880 * can do.
799 lbs_pr_err("I/O error\n"); 881 */
882 err = spu_read_u16(card, IF_SPI_HOST_INT_STATUS_REG,
883 &hiStatus);
884 if (err) {
885 netdev_err(priv->dev, "I/O error\n");
886 goto err;
887 }
888
889 if (hiStatus & IF_SPI_HIST_CMD_UPLOAD_RDY) {
890 err = if_spi_c2h_cmd(card);
891 if (err)
800 goto err; 892 goto err;
893 }
894 if (hiStatus & IF_SPI_HIST_RX_UPLOAD_RDY) {
895 err = if_spi_c2h_data(card);
896 if (err)
897 goto err;
898 }
899
900 /*
901 * workaround: in PS mode, the card does not set the Command
902 * Download Ready bit, but it sets TX Download Ready.
903 */
904 if (hiStatus & IF_SPI_HIST_CMD_DOWNLOAD_RDY ||
905 (card->priv->psstate != PS_STATE_FULL_POWER &&
906 (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY))) {
907 /*
908 * This means two things. First of all,
909 * if there was a previous command sent, the card has
910 * successfully received it.
911 * Secondly, it is now ready to download another
912 * command.
913 */
914 lbs_host_to_card_done(card->priv);
915
916 /* Do we have any command packets from the host to send? */
917 packet = NULL;
918 spin_lock_irqsave(&card->buffer_lock, flags);
919 if (!list_empty(&card->cmd_packet_list)) {
920 packet = (struct if_spi_packet *)(card->
921 cmd_packet_list.next);
922 list_del(&packet->list);
801 } 923 }
924 spin_unlock_irqrestore(&card->buffer_lock, flags);
802 925
803 if (hiStatus & IF_SPI_HIST_CMD_UPLOAD_RDY) 926 if (packet)
804 err = if_spi_c2h_cmd(card); 927 if_spi_h2c(card, packet, MVMS_CMD);
805 if (err) 928 }
806 goto err; 929 if (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY) {
807 if (hiStatus & IF_SPI_HIST_RX_UPLOAD_RDY) 930 /* Do we have any data packets from the host to send? */
808 err = if_spi_c2h_data(card); 931 packet = NULL;
809 if (err) 932 spin_lock_irqsave(&card->buffer_lock, flags);
810 goto err; 933 if (!list_empty(&card->data_packet_list)) {
811 934 packet = (struct if_spi_packet *)(card->
812 /* workaround: in PS mode, the card does not set the Command 935 data_packet_list.next);
813 * Download Ready bit, but it sets TX Download Ready. */ 936 list_del(&packet->list);
814 if (hiStatus & IF_SPI_HIST_CMD_DOWNLOAD_RDY ||
815 (card->priv->psstate != PS_STATE_FULL_POWER &&
816 (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY))) {
817 lbs_host_to_card_done(card->priv);
818 } 937 }
938 spin_unlock_irqrestore(&card->buffer_lock, flags);
819 939
820 if (hiStatus & IF_SPI_HIST_CARD_EVENT) 940 if (packet)
821 if_spi_e2h(card); 941 if_spi_h2c(card, packet, MVMS_DAT);
942 }
943 if (hiStatus & IF_SPI_HIST_CARD_EVENT)
944 if_spi_e2h(card);
822 945
823err: 946err:
824 if (err) 947 if (err)
825 lbs_pr_err("%s: got error %d\n", __func__, err); 948 netdev_err(priv->dev, "%s: got error %d\n", __func__, err);
826 }
827}
828 949
829/* Block until lbs_spi_thread thread has terminated */ 950 lbs_deb_leave(LBS_DEB_SPI);
830static void if_spi_terminate_spi_thread(struct if_spi_card *card)
831{
832 /* It would be nice to use kthread_stop here, but that function
833 * can't wake threads waiting for a semaphore. */
834 card->run_thread = 0;
835 up(&card->spi_ready);
836 down(&card->spi_thread_terminated);
837} 951}
838 952
839/* 953/*
840 * Host to Card 954 * Host to Card
841 * 955 *
842 * Called from Libertas to transfer some data to the WLAN device 956 * Called from Libertas to transfer some data to the WLAN device
843 * We can't sleep here. */ 957 * We can't sleep here.
958 */
844static int if_spi_host_to_card(struct lbs_private *priv, 959static int if_spi_host_to_card(struct lbs_private *priv,
845 u8 type, u8 *buf, u16 nb) 960 u8 type, u8 *buf, u16 nb)
846{ 961{
847 int err = 0; 962 int err = 0;
963 unsigned long flags;
848 struct if_spi_card *card = priv->card; 964 struct if_spi_card *card = priv->card;
965 struct if_spi_packet *packet;
966 u16 blen;
849 967
850 lbs_deb_enter_args(LBS_DEB_SPI, "type %d, bytes %d", type, nb); 968 lbs_deb_enter_args(LBS_DEB_SPI, "type %d, bytes %d", type, nb);
851 969
852 nb = ALIGN(nb, 4); 970 if (nb == 0) {
971 netdev_err(priv->dev, "%s: invalid size requested: %d\n",
972 __func__, nb);
973 err = -EINVAL;
974 goto out;
975 }
976 blen = ALIGN(nb, 4);
977 packet = kzalloc(sizeof(struct if_spi_packet) + blen, GFP_ATOMIC);
978 if (!packet) {
979 err = -ENOMEM;
980 goto out;
981 }
982 packet->blen = blen;
983 memcpy(packet->buffer, buf, nb);
984 memset(packet->buffer + nb, 0, blen - nb);
853 985
854 switch (type) { 986 switch (type) {
855 case MVMS_CMD: 987 case MVMS_CMD:
856 err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG, buf, nb); 988 priv->dnld_sent = DNLD_CMD_SENT;
989 spin_lock_irqsave(&card->buffer_lock, flags);
990 list_add_tail(&packet->list, &card->cmd_packet_list);
991 spin_unlock_irqrestore(&card->buffer_lock, flags);
857 break; 992 break;
858 case MVMS_DAT: 993 case MVMS_DAT:
859 err = spu_write(card, IF_SPI_DATA_RDWRPORT_REG, buf, nb); 994 priv->dnld_sent = DNLD_DATA_SENT;
995 spin_lock_irqsave(&card->buffer_lock, flags);
996 list_add_tail(&packet->list, &card->data_packet_list);
997 spin_unlock_irqrestore(&card->buffer_lock, flags);
860 break; 998 break;
861 default: 999 default:
862 lbs_pr_err("can't transfer buffer of type %d", type); 1000 netdev_err(priv->dev, "can't transfer buffer of type %d\n",
1001 type);
863 err = -EINVAL; 1002 err = -EINVAL;
864 break; 1003 break;
865 } 1004 }
866 1005
1006 /* Queue spi xfer work */
1007 queue_work(card->workqueue, &card->packet_work);
1008out:
867 lbs_deb_leave_args(LBS_DEB_SPI, "err=%d", err); 1009 lbs_deb_leave_args(LBS_DEB_SPI, "err=%d", err);
868 return err; 1010 return err;
869} 1011}
@@ -872,13 +1014,14 @@ static int if_spi_host_to_card(struct lbs_private *priv,
872 * Host Interrupts 1014 * Host Interrupts
873 * 1015 *
874 * Service incoming interrupts from the WLAN device. We can't sleep here, so 1016 * Service incoming interrupts from the WLAN device. We can't sleep here, so
875 * don't try to talk on the SPI bus, just wake up the SPI thread. 1017 * don't try to talk on the SPI bus, just queue the SPI xfer work.
876 */ 1018 */
877static irqreturn_t if_spi_host_interrupt(int irq, void *dev_id) 1019static irqreturn_t if_spi_host_interrupt(int irq, void *dev_id)
878{ 1020{
879 struct if_spi_card *card = dev_id; 1021 struct if_spi_card *card = dev_id;
880 1022
881 up(&card->spi_ready); 1023 queue_work(card->workqueue, &card->packet_work);
1024
882 return IRQ_HANDLED; 1025 return IRQ_HANDLED;
883} 1026}
884 1027
@@ -886,28 +1029,104 @@ static irqreturn_t if_spi_host_interrupt(int irq, void *dev_id)
886 * SPI callbacks 1029 * SPI callbacks
887 */ 1030 */
888 1031
889static int if_spi_calculate_fw_names(u16 card_id, 1032static int if_spi_init_card(struct if_spi_card *card)
890 char *helper_fw, char *main_fw)
891{ 1033{
892 int i; 1034 struct lbs_private *priv = card->priv;
893 for (i = 0; i < ARRAY_SIZE(chip_id_to_device_name); ++i) { 1035 struct spi_device *spi = card->spi;
894 if (card_id == chip_id_to_device_name[i].chip_id) 1036 int err, i;
895 break; 1037 u32 scratch;
1038 const struct firmware *helper = NULL;
1039 const struct firmware *mainfw = NULL;
1040
1041 lbs_deb_enter(LBS_DEB_SPI);
1042
1043 err = spu_init(card, card->pdata->use_dummy_writes);
1044 if (err)
1045 goto out;
1046 err = spu_get_chip_revision(card, &card->card_id, &card->card_rev);
1047 if (err)
1048 goto out;
1049
1050 err = spu_read_u32(card, IF_SPI_SCRATCH_4_REG, &scratch);
1051 if (err)
1052 goto out;
1053 if (scratch == SUCCESSFUL_FW_DOWNLOAD_MAGIC)
1054 lbs_deb_spi("Firmware is already loaded for "
1055 "Marvell WLAN 802.11 adapter\n");
1056 else {
1057 /* Check if we support this card */
1058 for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
1059 if (card->card_id == fw_table[i].model)
1060 break;
1061 }
1062 if (i == ARRAY_SIZE(fw_table)) {
1063 netdev_err(priv->dev, "Unsupported chip_id: 0x%02x\n",
1064 card->card_id);
1065 err = -ENODEV;
1066 goto out;
1067 }
1068
1069 err = lbs_get_firmware(&card->spi->dev, NULL, NULL,
1070 card->card_id, &fw_table[0], &helper,
1071 &mainfw);
1072 if (err) {
1073 netdev_err(priv->dev, "failed to find firmware (%d)\n",
1074 err);
1075 goto out;
1076 }
1077
1078 lbs_deb_spi("Initializing FW for Marvell WLAN 802.11 adapter "
1079 "(chip_id = 0x%04x, chip_rev = 0x%02x) "
1080 "attached to SPI bus_num %d, chip_select %d. "
1081 "spi->max_speed_hz=%d\n",
1082 card->card_id, card->card_rev,
1083 spi->master->bus_num, spi->chip_select,
1084 spi->max_speed_hz);
1085 err = if_spi_prog_helper_firmware(card, helper);
1086 if (err)
1087 goto out;
1088 err = if_spi_prog_main_firmware(card, mainfw);
1089 if (err)
1090 goto out;
1091 lbs_deb_spi("loaded FW for Marvell WLAN 802.11 adapter\n");
896 } 1092 }
897 if (i == ARRAY_SIZE(chip_id_to_device_name)) { 1093
898 lbs_pr_err("Unsupported chip_id: 0x%02x\n", card_id); 1094 err = spu_set_interrupt_mode(card, 0, 1);
899 return -EAFNOSUPPORT; 1095 if (err)
1096 goto out;
1097
1098out:
1099 if (helper)
1100 release_firmware(helper);
1101 if (mainfw)
1102 release_firmware(mainfw);
1103
1104 lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
1105
1106 return err;
1107}
1108
1109static void if_spi_resume_worker(struct work_struct *work)
1110{
1111 struct if_spi_card *card;
1112
1113 card = container_of(work, struct if_spi_card, resume_work);
1114
1115 if (card->suspended) {
1116 if (card->pdata->setup)
1117 card->pdata->setup(card->spi);
1118
1119 /* Init card ... */
1120 if_spi_init_card(card);
1121
1122 enable_irq(card->spi->irq);
1123
1124 /* And resume it ... */
1125 lbs_resume(card->priv);
1126
1127 card->suspended = 0;
900 } 1128 }
901 snprintf(helper_fw, IF_SPI_FW_NAME_MAX, "libertas/gspi%d_hlp.bin",
902 chip_id_to_device_name[i].name);
903 snprintf(main_fw, IF_SPI_FW_NAME_MAX, "libertas/gspi%d.bin",
904 chip_id_to_device_name[i].name);
905 return 0;
906} 1129}
907MODULE_FIRMWARE("libertas/gspi8385_hlp.bin");
908MODULE_FIRMWARE("libertas/gspi8385.bin");
909MODULE_FIRMWARE("libertas/gspi8686_hlp.bin");
910MODULE_FIRMWARE("libertas/gspi8686.bin");
911 1130
912static int __devinit if_spi_probe(struct spi_device *spi) 1131static int __devinit if_spi_probe(struct spi_device *spi)
913{ 1132{
@@ -915,8 +1134,6 @@ static int __devinit if_spi_probe(struct spi_device *spi)
915 struct lbs_private *priv = NULL; 1134 struct lbs_private *priv = NULL;
916 struct libertas_spi_platform_data *pdata = spi->dev.platform_data; 1135 struct libertas_spi_platform_data *pdata = spi->dev.platform_data;
917 int err = 0; 1136 int err = 0;
918 u32 scratch;
919 struct sched_param param = { .sched_priority = 1 };
920 1137
921 lbs_deb_enter(LBS_DEB_SPI); 1138 lbs_deb_enter(LBS_DEB_SPI);
922 1139
@@ -935,65 +1152,35 @@ static int __devinit if_spi_probe(struct spi_device *spi)
935 card = kzalloc(sizeof(struct if_spi_card), GFP_KERNEL); 1152 card = kzalloc(sizeof(struct if_spi_card), GFP_KERNEL);
936 if (!card) { 1153 if (!card) {
937 err = -ENOMEM; 1154 err = -ENOMEM;
938 goto out; 1155 goto teardown;
939 } 1156 }
940 spi_set_drvdata(spi, card); 1157 spi_set_drvdata(spi, card);
941 card->pdata = pdata; 1158 card->pdata = pdata;
942 card->spi = spi; 1159 card->spi = spi;
943 card->prev_xfer_time = jiffies; 1160 card->prev_xfer_time = jiffies;
944 1161
945 sema_init(&card->spi_ready, 0); 1162 INIT_LIST_HEAD(&card->cmd_packet_list);
946 sema_init(&card->spi_thread_terminated, 0); 1163 INIT_LIST_HEAD(&card->data_packet_list);
1164 spin_lock_init(&card->buffer_lock);
947 1165
948 /* Initialize the SPI Interface Unit */ 1166 /* Initialize the SPI Interface Unit */
949 err = spu_init(card, pdata->use_dummy_writes);
950 if (err)
951 goto free_card;
952 err = spu_get_chip_revision(card, &card->card_id, &card->card_rev);
953 if (err)
954 goto free_card;
955 1167
956 /* Firmware load */ 1168 /* Firmware load */
957 err = spu_read_u32(card, IF_SPI_SCRATCH_4_REG, &scratch); 1169 err = if_spi_init_card(card);
958 if (err) 1170 if (err)
959 goto free_card; 1171 goto free_card;
960 if (scratch == SUCCESSFUL_FW_DOWNLOAD_MAGIC)
961 lbs_deb_spi("Firmware is already loaded for "
962 "Marvell WLAN 802.11 adapter\n");
963 else {
964 err = if_spi_calculate_fw_names(card->card_id,
965 card->helper_fw_name, card->main_fw_name);
966 if (err)
967 goto free_card;
968 1172
969 lbs_deb_spi("Initializing FW for Marvell WLAN 802.11 adapter " 1173 /*
970 "(chip_id = 0x%04x, chip_rev = 0x%02x) " 1174 * Register our card with libertas.
971 "attached to SPI bus_num %d, chip_select %d. " 1175 * This will call alloc_etherdev.
972 "spi->max_speed_hz=%d\n", 1176 */
973 card->card_id, card->card_rev,
974 spi->master->bus_num, spi->chip_select,
975 spi->max_speed_hz);
976 err = if_spi_prog_helper_firmware(card);
977 if (err)
978 goto free_card;
979 err = if_spi_prog_main_firmware(card);
980 if (err)
981 goto free_card;
982 lbs_deb_spi("loaded FW for Marvell WLAN 802.11 adapter\n");
983 }
984
985 err = spu_set_interrupt_mode(card, 0, 1);
986 if (err)
987 goto free_card;
988
989 /* Register our card with libertas.
990 * This will call alloc_etherdev */
991 priv = lbs_add_card(card, &spi->dev); 1177 priv = lbs_add_card(card, &spi->dev);
992 if (!priv) { 1178 if (!priv) {
993 err = -ENOMEM; 1179 err = -ENOMEM;
994 goto free_card; 1180 goto free_card;
995 } 1181 }
996 card->priv = priv; 1182 card->priv = priv;
1183 priv->setup_fw_on_resume = 1;
997 priv->card = card; 1184 priv->card = card;
998 priv->hw_host_to_card = if_spi_host_to_card; 1185 priv->hw_host_to_card = if_spi_host_to_card;
999 priv->enter_deep_sleep = NULL; 1186 priv->enter_deep_sleep = NULL;
@@ -1002,30 +1189,22 @@ static int __devinit if_spi_probe(struct spi_device *spi)
1002 priv->fw_ready = 1; 1189 priv->fw_ready = 1;
1003 1190
1004 /* Initialize interrupt handling stuff. */ 1191 /* Initialize interrupt handling stuff. */
1005 card->run_thread = 1; 1192 card->workqueue = create_workqueue("libertas_spi");
1006 card->spi_thread = kthread_run(lbs_spi_thread, card, "lbs_spi_thread"); 1193 INIT_WORK(&card->packet_work, if_spi_host_to_card_worker);
1007 if (IS_ERR(card->spi_thread)) { 1194 INIT_WORK(&card->resume_work, if_spi_resume_worker);
1008 card->run_thread = 0;
1009 err = PTR_ERR(card->spi_thread);
1010 lbs_pr_err("error creating SPI thread: err=%d\n", err);
1011 goto remove_card;
1012 }
1013 if (sched_setscheduler(card->spi_thread, SCHED_FIFO, &param))
1014 lbs_pr_err("Error setting scheduler, using default.\n");
1015 1195
1016 err = request_irq(spi->irq, if_spi_host_interrupt, 1196 err = request_irq(spi->irq, if_spi_host_interrupt,
1017 IRQF_TRIGGER_FALLING, "libertas_spi", card); 1197 IRQF_TRIGGER_FALLING, "libertas_spi", card);
1018 if (err) { 1198 if (err) {
1019 lbs_pr_err("can't get host irq line-- request_irq failed\n"); 1199 pr_err("can't get host irq line-- request_irq failed\n");
1020 goto terminate_thread; 1200 goto terminate_workqueue;
1021 } 1201 }
1022 1202
1023 /* poke the IRQ handler so that we don't miss the first interrupt */ 1203 /*
1024 up(&card->spi_ready); 1204 * Start the card.
1025
1026 /* Start the card.
1027 * This will call register_netdev, and we'll start 1205 * This will call register_netdev, and we'll start
1028 * getting interrupts... */ 1206 * getting interrupts...
1207 */
1029 err = lbs_start_card(priv); 1208 err = lbs_start_card(priv);
1030 if (err) 1209 if (err)
1031 goto release_irq; 1210 goto release_irq;
@@ -1037,12 +1216,15 @@ static int __devinit if_spi_probe(struct spi_device *spi)
1037 1216
1038release_irq: 1217release_irq:
1039 free_irq(spi->irq, card); 1218 free_irq(spi->irq, card);
1040terminate_thread: 1219terminate_workqueue:
1041 if_spi_terminate_spi_thread(card); 1220 flush_workqueue(card->workqueue);
1042remove_card: 1221 destroy_workqueue(card->workqueue);
1043 lbs_remove_card(priv); /* will call free_netdev */ 1222 lbs_remove_card(priv); /* will call free_netdev */
1044free_card: 1223free_card:
1045 free_if_spi_card(card); 1224 free_if_spi_card(card);
1225teardown:
1226 if (pdata->teardown)
1227 pdata->teardown(spi);
1046out: 1228out:
1047 lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err); 1229 lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
1048 return err; 1230 return err;
@@ -1056,12 +1238,14 @@ static int __devexit libertas_spi_remove(struct spi_device *spi)
1056 lbs_deb_spi("libertas_spi_remove\n"); 1238 lbs_deb_spi("libertas_spi_remove\n");
1057 lbs_deb_enter(LBS_DEB_SPI); 1239 lbs_deb_enter(LBS_DEB_SPI);
1058 1240
1241 cancel_work_sync(&card->resume_work);
1242
1059 lbs_stop_card(priv); 1243 lbs_stop_card(priv);
1060 lbs_remove_card(priv); /* will call free_netdev */ 1244 lbs_remove_card(priv); /* will call free_netdev */
1061 1245
1062 priv->surpriseremoved = 1;
1063 free_irq(spi->irq, card); 1246 free_irq(spi->irq, card);
1064 if_spi_terminate_spi_thread(card); 1247 flush_workqueue(card->workqueue);
1248 destroy_workqueue(card->workqueue);
1065 if (card->pdata->teardown) 1249 if (card->pdata->teardown)
1066 card->pdata->teardown(spi); 1250 card->pdata->teardown(spi);
1067 free_if_spi_card(card); 1251 free_if_spi_card(card);
@@ -1069,6 +1253,40 @@ static int __devexit libertas_spi_remove(struct spi_device *spi)
1069 return 0; 1253 return 0;
1070} 1254}
1071 1255
1256static int if_spi_suspend(struct device *dev)
1257{
1258 struct spi_device *spi = to_spi_device(dev);
1259 struct if_spi_card *card = spi_get_drvdata(spi);
1260
1261 if (!card->suspended) {
1262 lbs_suspend(card->priv);
1263 flush_workqueue(card->workqueue);
1264 disable_irq(spi->irq);
1265
1266 if (card->pdata->teardown)
1267 card->pdata->teardown(spi);
1268 card->suspended = 1;
1269 }
1270
1271 return 0;
1272}
1273
1274static int if_spi_resume(struct device *dev)
1275{
1276 struct spi_device *spi = to_spi_device(dev);
1277 struct if_spi_card *card = spi_get_drvdata(spi);
1278
1279 /* Schedule delayed work */
1280 schedule_work(&card->resume_work);
1281
1282 return 0;
1283}
1284
1285static const struct dev_pm_ops if_spi_pm_ops = {
1286 .suspend = if_spi_suspend,
1287 .resume = if_spi_resume,
1288};
1289
1072static struct spi_driver libertas_spi_driver = { 1290static struct spi_driver libertas_spi_driver = {
1073 .probe = if_spi_probe, 1291 .probe = if_spi_probe,
1074 .remove = __devexit_p(libertas_spi_remove), 1292 .remove = __devexit_p(libertas_spi_remove),
@@ -1076,6 +1294,7 @@ static struct spi_driver libertas_spi_driver = {
1076 .name = "libertas_spi", 1294 .name = "libertas_spi",
1077 .bus = &spi_bus_type, 1295 .bus = &spi_bus_type,
1078 .owner = THIS_MODULE, 1296 .owner = THIS_MODULE,
1297 .pm = &if_spi_pm_ops,
1079 }, 1298 },
1080}; 1299};
1081 1300
diff --git a/drivers/net/wireless/libertas/if_spi.h b/drivers/net/wireless/libertas/if_spi.h
index f87eec410848..e450e31fd11d 100644
--- a/drivers/net/wireless/libertas/if_spi.h
+++ b/drivers/net/wireless/libertas/if_spi.h
@@ -25,11 +25,6 @@
25 25
26#define IF_SPI_FW_NAME_MAX 30 26#define IF_SPI_FW_NAME_MAX 30
27 27
28struct chip_ident {
29 u16 chip_id;
30 u16 name;
31};
32
33#define MAX_MAIN_FW_LOAD_CRC_ERR 10 28#define MAX_MAIN_FW_LOAD_CRC_ERR 10
34 29
35/* Chunk size when loading the helper firmware */ 30/* Chunk size when loading the helper firmware */
@@ -71,7 +66,7 @@ struct chip_ident {
71#define IF_SPI_HOST_INT_CTRL_REG 0x40 /* Host interrupt controller reg */ 66#define IF_SPI_HOST_INT_CTRL_REG 0x40 /* Host interrupt controller reg */
72 67
73#define IF_SPI_CARD_INT_CAUSE_REG 0x44 /* Card interrupt cause reg */ 68#define IF_SPI_CARD_INT_CAUSE_REG 0x44 /* Card interrupt cause reg */
74#define IF_SPI_CARD_INT_STATUS_REG 0x48 /* Card interupt status reg */ 69#define IF_SPI_CARD_INT_STATUS_REG 0x48 /* Card interrupt status reg */
75#define IF_SPI_CARD_INT_EVENT_MASK_REG 0x4C /* Card interrupt event mask */ 70#define IF_SPI_CARD_INT_EVENT_MASK_REG 0x4C /* Card interrupt event mask */
76#define IF_SPI_CARD_INT_STATUS_MASK_REG 0x50 /* Card interrupt status mask */ 71#define IF_SPI_CARD_INT_STATUS_MASK_REG 0x50 /* Card interrupt status mask */
77 72
@@ -91,34 +86,34 @@ struct chip_ident {
91#define IF_SPI_DEVICEID_CTRL_REG_TO_CARD_REV(dc) (dc & 0x000000ff) 86#define IF_SPI_DEVICEID_CTRL_REG_TO_CARD_REV(dc) (dc & 0x000000ff)
92 87
93/***************** IF_SPI_HOST_INT_CTRL_REG *****************/ 88/***************** IF_SPI_HOST_INT_CTRL_REG *****************/
94/** Host Interrupt Control bit : Wake up */ 89/* Host Interrupt Control bit : Wake up */
95#define IF_SPI_HICT_WAKE_UP (1<<0) 90#define IF_SPI_HICT_WAKE_UP (1<<0)
96/** Host Interrupt Control bit : WLAN ready */ 91/* Host Interrupt Control bit : WLAN ready */
97#define IF_SPI_HICT_WLAN_READY (1<<1) 92#define IF_SPI_HICT_WLAN_READY (1<<1)
98/*#define IF_SPI_HICT_FIFO_FIRST_HALF_EMPTY (1<<2) */ 93/*#define IF_SPI_HICT_FIFO_FIRST_HALF_EMPTY (1<<2) */
99/*#define IF_SPI_HICT_FIFO_SECOND_HALF_EMPTY (1<<3) */ 94/*#define IF_SPI_HICT_FIFO_SECOND_HALF_EMPTY (1<<3) */
100/*#define IF_SPI_HICT_IRQSRC_WLAN (1<<4) */ 95/*#define IF_SPI_HICT_IRQSRC_WLAN (1<<4) */
101/** Host Interrupt Control bit : Tx auto download */ 96/* Host Interrupt Control bit : Tx auto download */
102#define IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO (1<<5) 97#define IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO (1<<5)
103/** Host Interrupt Control bit : Rx auto upload */ 98/* Host Interrupt Control bit : Rx auto upload */
104#define IF_SPI_HICT_RX_UPLOAD_OVER_AUTO (1<<6) 99#define IF_SPI_HICT_RX_UPLOAD_OVER_AUTO (1<<6)
105/** Host Interrupt Control bit : Command auto download */ 100/* Host Interrupt Control bit : Command auto download */
106#define IF_SPI_HICT_CMD_DOWNLOAD_OVER_AUTO (1<<7) 101#define IF_SPI_HICT_CMD_DOWNLOAD_OVER_AUTO (1<<7)
107/** Host Interrupt Control bit : Command auto upload */ 102/* Host Interrupt Control bit : Command auto upload */
108#define IF_SPI_HICT_CMD_UPLOAD_OVER_AUTO (1<<8) 103#define IF_SPI_HICT_CMD_UPLOAD_OVER_AUTO (1<<8)
109 104
110/***************** IF_SPI_CARD_INT_CAUSE_REG *****************/ 105/***************** IF_SPI_CARD_INT_CAUSE_REG *****************/
111/** Card Interrupt Case bit : Tx download over */ 106/* Card Interrupt Case bit : Tx download over */
112#define IF_SPI_CIC_TX_DOWNLOAD_OVER (1<<0) 107#define IF_SPI_CIC_TX_DOWNLOAD_OVER (1<<0)
113/** Card Interrupt Case bit : Rx upload over */ 108/* Card Interrupt Case bit : Rx upload over */
114#define IF_SPI_CIC_RX_UPLOAD_OVER (1<<1) 109#define IF_SPI_CIC_RX_UPLOAD_OVER (1<<1)
115/** Card Interrupt Case bit : Command download over */ 110/* Card Interrupt Case bit : Command download over */
116#define IF_SPI_CIC_CMD_DOWNLOAD_OVER (1<<2) 111#define IF_SPI_CIC_CMD_DOWNLOAD_OVER (1<<2)
117/** Card Interrupt Case bit : Host event */ 112/* Card Interrupt Case bit : Host event */
118#define IF_SPI_CIC_HOST_EVENT (1<<3) 113#define IF_SPI_CIC_HOST_EVENT (1<<3)
119/** Card Interrupt Case bit : Command upload over */ 114/* Card Interrupt Case bit : Command upload over */
120#define IF_SPI_CIC_CMD_UPLOAD_OVER (1<<4) 115#define IF_SPI_CIC_CMD_UPLOAD_OVER (1<<4)
121/** Card Interrupt Case bit : Power down */ 116/* Card Interrupt Case bit : Power down */
122#define IF_SPI_CIC_POWER_DOWN (1<<5) 117#define IF_SPI_CIC_POWER_DOWN (1<<5)
123 118
124/***************** IF_SPI_CARD_INT_STATUS_REG *****************/ 119/***************** IF_SPI_CARD_INT_STATUS_REG *****************/
@@ -143,51 +138,51 @@ struct chip_ident {
143#define IF_SPI_HICU_CMD_RD_FIFO_UNDERFLOW (1<<10) 138#define IF_SPI_HICU_CMD_RD_FIFO_UNDERFLOW (1<<10)
144 139
145/***************** IF_SPI_HOST_INT_STATUS_REG *****************/ 140/***************** IF_SPI_HOST_INT_STATUS_REG *****************/
146/** Host Interrupt Status bit : Tx download ready */ 141/* Host Interrupt Status bit : Tx download ready */
147#define IF_SPI_HIST_TX_DOWNLOAD_RDY (1<<0) 142#define IF_SPI_HIST_TX_DOWNLOAD_RDY (1<<0)
148/** Host Interrupt Status bit : Rx upload ready */ 143/* Host Interrupt Status bit : Rx upload ready */
149#define IF_SPI_HIST_RX_UPLOAD_RDY (1<<1) 144#define IF_SPI_HIST_RX_UPLOAD_RDY (1<<1)
150/** Host Interrupt Status bit : Command download ready */ 145/* Host Interrupt Status bit : Command download ready */
151#define IF_SPI_HIST_CMD_DOWNLOAD_RDY (1<<2) 146#define IF_SPI_HIST_CMD_DOWNLOAD_RDY (1<<2)
152/** Host Interrupt Status bit : Card event */ 147/* Host Interrupt Status bit : Card event */
153#define IF_SPI_HIST_CARD_EVENT (1<<3) 148#define IF_SPI_HIST_CARD_EVENT (1<<3)
154/** Host Interrupt Status bit : Command upload ready */ 149/* Host Interrupt Status bit : Command upload ready */
155#define IF_SPI_HIST_CMD_UPLOAD_RDY (1<<4) 150#define IF_SPI_HIST_CMD_UPLOAD_RDY (1<<4)
156/** Host Interrupt Status bit : I/O write FIFO overflow */ 151/* Host Interrupt Status bit : I/O write FIFO overflow */
157#define IF_SPI_HIST_IO_WR_FIFO_OVERFLOW (1<<5) 152#define IF_SPI_HIST_IO_WR_FIFO_OVERFLOW (1<<5)
158/** Host Interrupt Status bit : I/O read FIFO underflow */ 153/* Host Interrupt Status bit : I/O read FIFO underflow */
159#define IF_SPI_HIST_IO_RD_FIFO_UNDRFLOW (1<<6) 154#define IF_SPI_HIST_IO_RD_FIFO_UNDRFLOW (1<<6)
160/** Host Interrupt Status bit : Data write FIFO overflow */ 155/* Host Interrupt Status bit : Data write FIFO overflow */
161#define IF_SPI_HIST_DATA_WR_FIFO_OVERFLOW (1<<7) 156#define IF_SPI_HIST_DATA_WR_FIFO_OVERFLOW (1<<7)
162/** Host Interrupt Status bit : Data read FIFO underflow */ 157/* Host Interrupt Status bit : Data read FIFO underflow */
163#define IF_SPI_HIST_DATA_RD_FIFO_UNDERFLOW (1<<8) 158#define IF_SPI_HIST_DATA_RD_FIFO_UNDERFLOW (1<<8)
164/** Host Interrupt Status bit : Command write FIFO overflow */ 159/* Host Interrupt Status bit : Command write FIFO overflow */
165#define IF_SPI_HIST_CMD_WR_FIFO_OVERFLOW (1<<9) 160#define IF_SPI_HIST_CMD_WR_FIFO_OVERFLOW (1<<9)
166/** Host Interrupt Status bit : Command read FIFO underflow */ 161/* Host Interrupt Status bit : Command read FIFO underflow */
167#define IF_SPI_HIST_CMD_RD_FIFO_UNDERFLOW (1<<10) 162#define IF_SPI_HIST_CMD_RD_FIFO_UNDERFLOW (1<<10)
168 163
169/***************** IF_SPI_HOST_INT_STATUS_MASK_REG *****************/ 164/***************** IF_SPI_HOST_INT_STATUS_MASK_REG *****************/
170/** Host Interrupt Status Mask bit : Tx download ready */ 165/* Host Interrupt Status Mask bit : Tx download ready */
171#define IF_SPI_HISM_TX_DOWNLOAD_RDY (1<<0) 166#define IF_SPI_HISM_TX_DOWNLOAD_RDY (1<<0)
172/** Host Interrupt Status Mask bit : Rx upload ready */ 167/* Host Interrupt Status Mask bit : Rx upload ready */
173#define IF_SPI_HISM_RX_UPLOAD_RDY (1<<1) 168#define IF_SPI_HISM_RX_UPLOAD_RDY (1<<1)
174/** Host Interrupt Status Mask bit : Command download ready */ 169/* Host Interrupt Status Mask bit : Command download ready */
175#define IF_SPI_HISM_CMD_DOWNLOAD_RDY (1<<2) 170#define IF_SPI_HISM_CMD_DOWNLOAD_RDY (1<<2)
176/** Host Interrupt Status Mask bit : Card event */ 171/* Host Interrupt Status Mask bit : Card event */
177#define IF_SPI_HISM_CARDEVENT (1<<3) 172#define IF_SPI_HISM_CARDEVENT (1<<3)
178/** Host Interrupt Status Mask bit : Command upload ready */ 173/* Host Interrupt Status Mask bit : Command upload ready */
179#define IF_SPI_HISM_CMD_UPLOAD_RDY (1<<4) 174#define IF_SPI_HISM_CMD_UPLOAD_RDY (1<<4)
180/** Host Interrupt Status Mask bit : I/O write FIFO overflow */ 175/* Host Interrupt Status Mask bit : I/O write FIFO overflow */
181#define IF_SPI_HISM_IO_WR_FIFO_OVERFLOW (1<<5) 176#define IF_SPI_HISM_IO_WR_FIFO_OVERFLOW (1<<5)
182/** Host Interrupt Status Mask bit : I/O read FIFO underflow */ 177/* Host Interrupt Status Mask bit : I/O read FIFO underflow */
183#define IF_SPI_HISM_IO_RD_FIFO_UNDERFLOW (1<<6) 178#define IF_SPI_HISM_IO_RD_FIFO_UNDERFLOW (1<<6)
184/** Host Interrupt Status Mask bit : Data write FIFO overflow */ 179/* Host Interrupt Status Mask bit : Data write FIFO overflow */
185#define IF_SPI_HISM_DATA_WR_FIFO_OVERFLOW (1<<7) 180#define IF_SPI_HISM_DATA_WR_FIFO_OVERFLOW (1<<7)
186/** Host Interrupt Status Mask bit : Data write FIFO underflow */ 181/* Host Interrupt Status Mask bit : Data write FIFO underflow */
187#define IF_SPI_HISM_DATA_RD_FIFO_UNDERFLOW (1<<8) 182#define IF_SPI_HISM_DATA_RD_FIFO_UNDERFLOW (1<<8)
188/** Host Interrupt Status Mask bit : Command write FIFO overflow */ 183/* Host Interrupt Status Mask bit : Command write FIFO overflow */
189#define IF_SPI_HISM_CMD_WR_FIFO_OVERFLOW (1<<9) 184#define IF_SPI_HISM_CMD_WR_FIFO_OVERFLOW (1<<9)
190/** Host Interrupt Status Mask bit : Command write FIFO underflow */ 185/* Host Interrupt Status Mask bit : Command write FIFO underflow */
191#define IF_SPI_HISM_CMD_RD_FIFO_UNDERFLOW (1<<10) 186#define IF_SPI_HISM_CMD_RD_FIFO_UNDERFLOW (1<<10)
192 187
193/***************** IF_SPI_SPU_BUS_MODE_REG *****************/ 188/***************** IF_SPI_SPU_BUS_MODE_REG *****************/
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 3ff61063671a..b5acc393a65a 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -1,6 +1,9 @@
1/** 1/*
2 * This file contains functions used in USB interface module. 2 * This file contains functions used in USB interface module.
3 */ 3 */
4
5#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6
4#include <linux/delay.h> 7#include <linux/delay.h>
5#include <linux/moduleparam.h> 8#include <linux/moduleparam.h>
6#include <linux/firmware.h> 9#include <linux/firmware.h>
@@ -26,15 +29,25 @@
26 29
27#define MESSAGE_HEADER_LEN 4 30#define MESSAGE_HEADER_LEN 4
28 31
29static char *lbs_fw_name = "usb8388.bin"; 32static char *lbs_fw_name = NULL;
30module_param_named(fw_name, lbs_fw_name, charp, 0644); 33module_param_named(fw_name, lbs_fw_name, charp, 0644);
31 34
35MODULE_FIRMWARE("libertas/usb8388_v9.bin");
36MODULE_FIRMWARE("libertas/usb8388_v5.bin");
37MODULE_FIRMWARE("libertas/usb8388.bin");
38MODULE_FIRMWARE("libertas/usb8682.bin");
32MODULE_FIRMWARE("usb8388.bin"); 39MODULE_FIRMWARE("usb8388.bin");
33 40
41enum {
42 MODEL_UNKNOWN = 0x0,
43 MODEL_8388 = 0x1,
44 MODEL_8682 = 0x2
45};
46
34static struct usb_device_id if_usb_table[] = { 47static struct usb_device_id if_usb_table[] = {
35 /* Enter the device signature inside */ 48 /* Enter the device signature inside */
36 { USB_DEVICE(0x1286, 0x2001) }, 49 { USB_DEVICE(0x1286, 0x2001), .driver_info = MODEL_8388 },
37 { USB_DEVICE(0x05a3, 0x8388) }, 50 { USB_DEVICE(0x05a3, 0x8388), .driver_info = MODEL_8388 },
38 {} /* Terminating entry */ 51 {} /* Terminating entry */
39}; 52};
40 53
@@ -56,7 +69,7 @@ static int if_usb_reset_device(struct if_usb_card *cardp);
56 69
57/* sysfs hooks */ 70/* sysfs hooks */
58 71
59/** 72/*
60 * Set function to write firmware to device's persistent memory 73 * Set function to write firmware to device's persistent memory
61 */ 74 */
62static ssize_t if_usb_firmware_set(struct device *dev, 75static ssize_t if_usb_firmware_set(struct device *dev,
@@ -66,6 +79,8 @@ static ssize_t if_usb_firmware_set(struct device *dev,
66 struct if_usb_card *cardp = priv->card; 79 struct if_usb_card *cardp = priv->card;
67 int ret; 80 int ret;
68 81
82 BUG_ON(buf == NULL);
83
69 ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_FW); 84 ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_FW);
70 if (ret == 0) 85 if (ret == 0)
71 return count; 86 return count;
@@ -73,7 +88,7 @@ static ssize_t if_usb_firmware_set(struct device *dev,
73 return ret; 88 return ret;
74} 89}
75 90
76/** 91/*
77 * lbs_flash_fw attribute to be exported per ethX interface through sysfs 92 * lbs_flash_fw attribute to be exported per ethX interface through sysfs
78 * (/sys/class/net/ethX/lbs_flash_fw). Use this like so to write firmware to 93 * (/sys/class/net/ethX/lbs_flash_fw). Use this like so to write firmware to
79 * the device's persistent memory: 94 * the device's persistent memory:
@@ -82,7 +97,14 @@ static ssize_t if_usb_firmware_set(struct device *dev,
82static DEVICE_ATTR(lbs_flash_fw, 0200, NULL, if_usb_firmware_set); 97static DEVICE_ATTR(lbs_flash_fw, 0200, NULL, if_usb_firmware_set);
83 98
84/** 99/**
85 * Set function to write firmware to device's persistent memory 100 * if_usb_boot2_set - write firmware to device's persistent memory
101 *
102 * @dev: target device
103 * @attr: device attributes
104 * @buf: firmware buffer to write
105 * @count: number of bytes to write
106 *
107 * returns: number of bytes written or negative error code
86 */ 108 */
87static ssize_t if_usb_boot2_set(struct device *dev, 109static ssize_t if_usb_boot2_set(struct device *dev,
88 struct device_attribute *attr, const char *buf, size_t count) 110 struct device_attribute *attr, const char *buf, size_t count)
@@ -91,6 +113,8 @@ static ssize_t if_usb_boot2_set(struct device *dev,
91 struct if_usb_card *cardp = priv->card; 113 struct if_usb_card *cardp = priv->card;
92 int ret; 114 int ret;
93 115
116 BUG_ON(buf == NULL);
117
94 ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_BOOT2); 118 ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_BOOT2);
95 if (ret == 0) 119 if (ret == 0)
96 return count; 120 return count;
@@ -98,7 +122,7 @@ static ssize_t if_usb_boot2_set(struct device *dev,
98 return ret; 122 return ret;
99} 123}
100 124
101/** 125/*
102 * lbs_flash_boot2 attribute to be exported per ethX interface through sysfs 126 * lbs_flash_boot2 attribute to be exported per ethX interface through sysfs
103 * (/sys/class/net/ethX/lbs_flash_boot2). Use this like so to write firmware 127 * (/sys/class/net/ethX/lbs_flash_boot2). Use this like so to write firmware
104 * to the device's persistent memory: 128 * to the device's persistent memory:
@@ -107,9 +131,10 @@ static ssize_t if_usb_boot2_set(struct device *dev,
107static DEVICE_ATTR(lbs_flash_boot2, 0200, NULL, if_usb_boot2_set); 131static DEVICE_ATTR(lbs_flash_boot2, 0200, NULL, if_usb_boot2_set);
108 132
109/** 133/**
110 * @brief call back function to handle the status of the URB 134 * if_usb_write_bulk_callback - callback function to handle the status
111 * @param urb pointer to urb structure 135 * of the URB
112 * @return N/A 136 * @urb: pointer to &urb structure
137 * returns: N/A
113 */ 138 */
114static void if_usb_write_bulk_callback(struct urb *urb) 139static void if_usb_write_bulk_callback(struct urb *urb)
115{ 140{
@@ -131,14 +156,14 @@ static void if_usb_write_bulk_callback(struct urb *urb)
131 lbs_host_to_card_done(priv); 156 lbs_host_to_card_done(priv);
132 } else { 157 } else {
133 /* print the failure status number for debug */ 158 /* print the failure status number for debug */
134 lbs_pr_info("URB in failure status: %d\n", urb->status); 159 pr_info("URB in failure status: %d\n", urb->status);
135 } 160 }
136} 161}
137 162
138/** 163/**
139 * @brief free tx/rx urb, skb and rx buffer 164 * if_usb_free - free tx/rx urb, skb and rx buffer
140 * @param cardp pointer if_usb_card 165 * @cardp: pointer to &if_usb_card
141 * @return N/A 166 * returns: N/A
142 */ 167 */
143static void if_usb_free(struct if_usb_card *cardp) 168static void if_usb_free(struct if_usb_card *cardp)
144{ 169{
@@ -181,7 +206,7 @@ static void if_usb_setup_firmware(struct lbs_private *priv)
181 wake_method.hdr.size = cpu_to_le16(sizeof(wake_method)); 206 wake_method.hdr.size = cpu_to_le16(sizeof(wake_method));
182 wake_method.action = cpu_to_le16(CMD_ACT_GET); 207 wake_method.action = cpu_to_le16(CMD_ACT_GET);
183 if (lbs_cmd_with_response(priv, CMD_802_11_FW_WAKE_METHOD, &wake_method)) { 208 if (lbs_cmd_with_response(priv, CMD_802_11_FW_WAKE_METHOD, &wake_method)) {
184 lbs_pr_info("Firmware does not seem to support PS mode\n"); 209 netdev_info(priv->dev, "Firmware does not seem to support PS mode\n");
185 priv->fwcapinfo &= ~FW_CAPINFO_PS; 210 priv->fwcapinfo &= ~FW_CAPINFO_PS;
186 } else { 211 } else {
187 if (le16_to_cpu(wake_method.method) == CMD_WAKE_METHOD_COMMAND_INT) { 212 if (le16_to_cpu(wake_method.method) == CMD_WAKE_METHOD_COMMAND_INT) {
@@ -190,7 +215,8 @@ static void if_usb_setup_firmware(struct lbs_private *priv)
190 /* The versions which boot up this way don't seem to 215 /* The versions which boot up this way don't seem to
191 work even if we set it to the command interrupt */ 216 work even if we set it to the command interrupt */
192 priv->fwcapinfo &= ~FW_CAPINFO_PS; 217 priv->fwcapinfo &= ~FW_CAPINFO_PS;
193 lbs_pr_info("Firmware doesn't wake via command interrupt; disabling PS mode\n"); 218 netdev_info(priv->dev,
219 "Firmware doesn't wake via command interrupt; disabling PS mode\n");
194 } 220 }
195 } 221 }
196} 222}
@@ -202,7 +228,7 @@ static void if_usb_fw_timeo(unsigned long priv)
202 if (cardp->fwdnldover) { 228 if (cardp->fwdnldover) {
203 lbs_deb_usb("Download complete, no event. Assuming success\n"); 229 lbs_deb_usb("Download complete, no event. Assuming success\n");
204 } else { 230 } else {
205 lbs_pr_err("Download timed out\n"); 231 pr_err("Download timed out\n");
206 cardp->surprise_removed = 1; 232 cardp->surprise_removed = 1;
207 } 233 }
208 wake_up(&cardp->fw_wq); 234 wake_up(&cardp->fw_wq);
@@ -217,10 +243,10 @@ static void if_usb_reset_olpc_card(struct lbs_private *priv)
217#endif 243#endif
218 244
219/** 245/**
220 * @brief sets the configuration values 246 * if_usb_probe - sets the configuration values
221 * @param ifnum interface number 247 * @intf: &usb_interface pointer
222 * @param id pointer to usb_device_id 248 * @id: pointer to usb_device_id
223 * @return 0 on success, error code on failure 249 * returns: 0 on success, error code on failure
224 */ 250 */
225static int if_usb_probe(struct usb_interface *intf, 251static int if_usb_probe(struct usb_interface *intf,
226 const struct usb_device_id *id) 252 const struct usb_device_id *id)
@@ -236,7 +262,7 @@ static int if_usb_probe(struct usb_interface *intf,
236 262
237 cardp = kzalloc(sizeof(struct if_usb_card), GFP_KERNEL); 263 cardp = kzalloc(sizeof(struct if_usb_card), GFP_KERNEL);
238 if (!cardp) { 264 if (!cardp) {
239 lbs_pr_err("Out of memory allocating private data.\n"); 265 pr_err("Out of memory allocating private data\n");
240 goto error; 266 goto error;
241 } 267 }
242 268
@@ -244,6 +270,7 @@ static int if_usb_probe(struct usb_interface *intf,
244 init_waitqueue_head(&cardp->fw_wq); 270 init_waitqueue_head(&cardp->fw_wq);
245 271
246 cardp->udev = udev; 272 cardp->udev = udev;
273 cardp->model = (uint32_t) id->driver_info;
247 iface_desc = intf->cur_altsetting; 274 iface_desc = intf->cur_altsetting;
248 275
249 lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X" 276 lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X"
@@ -325,10 +352,19 @@ static int if_usb_probe(struct usb_interface *intf,
325 usb_set_intfdata(intf, cardp); 352 usb_set_intfdata(intf, cardp);
326 353
327 if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_fw)) 354 if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_fw))
328 lbs_pr_err("cannot register lbs_flash_fw attribute\n"); 355 netdev_err(priv->dev,
356 "cannot register lbs_flash_fw attribute\n");
329 357
330 if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_boot2)) 358 if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_boot2))
331 lbs_pr_err("cannot register lbs_flash_boot2 attribute\n"); 359 netdev_err(priv->dev,
360 "cannot register lbs_flash_boot2 attribute\n");
361
362 /*
363 * EHS_REMOVE_WAKEUP is not supported on all versions of the firmware.
364 */
365 priv->wol_criteria = EHS_REMOVE_WAKEUP;
366 if (lbs_host_sleep_cfg(priv, priv->wol_criteria, NULL))
367 priv->ehs_remove_supported = false;
332 368
333 return 0; 369 return 0;
334 370
@@ -344,9 +380,9 @@ error:
344} 380}
345 381
346/** 382/**
347 * @brief free resource and cleanup 383 * if_usb_disconnect - free resource and cleanup
348 * @param intf USB interface structure 384 * @intf: USB interface structure
349 * @return N/A 385 * returns: N/A
350 */ 386 */
351static void if_usb_disconnect(struct usb_interface *intf) 387static void if_usb_disconnect(struct usb_interface *intf)
352{ 388{
@@ -376,9 +412,9 @@ static void if_usb_disconnect(struct usb_interface *intf)
376} 412}
377 413
378/** 414/**
379 * @brief This function download FW 415 * if_usb_send_fw_pkt - download FW
380 * @param priv pointer to struct lbs_private 416 * @cardp: pointer to &struct if_usb_card
381 * @return 0 417 * returns: 0
382 */ 418 */
383static int if_usb_send_fw_pkt(struct if_usb_card *cardp) 419static int if_usb_send_fw_pkt(struct if_usb_card *cardp)
384{ 420{
@@ -464,19 +500,20 @@ static int if_usb_reset_device(struct if_usb_card *cardp)
464} 500}
465 501
466/** 502/**
467 * @brief This function transfer the data to the device. 503 * usb_tx_block - transfer the data to the device
468 * @param priv pointer to struct lbs_private 504 * @cardp: pointer to &struct if_usb_card
469 * @param payload pointer to payload data 505 * @payload: pointer to payload data
470 * @param nb data length 506 * @nb: data length
471 * @return 0 or -1 507 * returns: 0 for success or negative error code
472 */ 508 */
473static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload, uint16_t nb) 509static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload, uint16_t nb)
474{ 510{
475 int ret = -1; 511 int ret;
476 512
477 /* check if device is removed */ 513 /* check if device is removed */
478 if (cardp->surprise_removed) { 514 if (cardp->surprise_removed) {
479 lbs_deb_usbd(&cardp->udev->dev, "Device removed\n"); 515 lbs_deb_usbd(&cardp->udev->dev, "Device removed\n");
516 ret = -ENODEV;
480 goto tx_ret; 517 goto tx_ret;
481 } 518 }
482 519
@@ -489,7 +526,6 @@ static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload, uint16_t nb
489 526
490 if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) { 527 if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) {
491 lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed: %d\n", ret); 528 lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed: %d\n", ret);
492 ret = -1;
493 } else { 529 } else {
494 lbs_deb_usb2(&cardp->udev->dev, "usb_submit_urb success\n"); 530 lbs_deb_usb2(&cardp->udev->dev, "usb_submit_urb success\n");
495 ret = 0; 531 ret = 0;
@@ -506,7 +542,7 @@ static int __if_usb_submit_rx_urb(struct if_usb_card *cardp,
506 int ret = -1; 542 int ret = -1;
507 543
508 if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) { 544 if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) {
509 lbs_pr_err("No free skb\n"); 545 pr_err("No free skb\n");
510 goto rx_ret; 546 goto rx_ret;
511 } 547 }
512 548
@@ -565,7 +601,7 @@ static void if_usb_receive_fwload(struct urb *urb)
565 601
566 if (tmp[0] == cpu_to_le32(CMD_TYPE_INDICATION) && 602 if (tmp[0] == cpu_to_le32(CMD_TYPE_INDICATION) &&
567 tmp[1] == cpu_to_le32(MACREG_INT_CODE_FIRMWARE_READY)) { 603 tmp[1] == cpu_to_le32(MACREG_INT_CODE_FIRMWARE_READY)) {
568 lbs_pr_info("Firmware ready event received\n"); 604 pr_info("Firmware ready event received\n");
569 wake_up(&cardp->fw_wq); 605 wake_up(&cardp->fw_wq);
570 } else { 606 } else {
571 lbs_deb_usb("Waiting for confirmation; got %x %x\n", 607 lbs_deb_usb("Waiting for confirmation; got %x %x\n",
@@ -592,20 +628,20 @@ static void if_usb_receive_fwload(struct urb *urb)
592 bootcmdresp.magic == cpu_to_le32(CMD_TYPE_DATA) || 628 bootcmdresp.magic == cpu_to_le32(CMD_TYPE_DATA) ||
593 bootcmdresp.magic == cpu_to_le32(CMD_TYPE_INDICATION)) { 629 bootcmdresp.magic == cpu_to_le32(CMD_TYPE_INDICATION)) {
594 if (!cardp->bootcmdresp) 630 if (!cardp->bootcmdresp)
595 lbs_pr_info("Firmware already seems alive; resetting\n"); 631 pr_info("Firmware already seems alive; resetting\n");
596 cardp->bootcmdresp = -1; 632 cardp->bootcmdresp = -1;
597 } else { 633 } else {
598 lbs_pr_info("boot cmd response wrong magic number (0x%x)\n", 634 pr_info("boot cmd response wrong magic number (0x%x)\n",
599 le32_to_cpu(bootcmdresp.magic)); 635 le32_to_cpu(bootcmdresp.magic));
600 } 636 }
601 } else if ((bootcmdresp.cmd != BOOT_CMD_FW_BY_USB) && 637 } else if ((bootcmdresp.cmd != BOOT_CMD_FW_BY_USB) &&
602 (bootcmdresp.cmd != BOOT_CMD_UPDATE_FW) && 638 (bootcmdresp.cmd != BOOT_CMD_UPDATE_FW) &&
603 (bootcmdresp.cmd != BOOT_CMD_UPDATE_BOOT2)) { 639 (bootcmdresp.cmd != BOOT_CMD_UPDATE_BOOT2)) {
604 lbs_pr_info("boot cmd response cmd_tag error (%d)\n", 640 pr_info("boot cmd response cmd_tag error (%d)\n",
605 bootcmdresp.cmd); 641 bootcmdresp.cmd);
606 } else if (bootcmdresp.result != BOOT_CMD_RESP_OK) { 642 } else if (bootcmdresp.result != BOOT_CMD_RESP_OK) {
607 lbs_pr_info("boot cmd response result error (%d)\n", 643 pr_info("boot cmd response result error (%d)\n",
608 bootcmdresp.result); 644 bootcmdresp.result);
609 } else { 645 } else {
610 cardp->bootcmdresp = 1; 646 cardp->bootcmdresp = 1;
611 lbs_deb_usbd(&cardp->udev->dev, 647 lbs_deb_usbd(&cardp->udev->dev,
@@ -705,11 +741,11 @@ static inline void process_cmdrequest(int recvlength, uint8_t *recvbuff,
705} 741}
706 742
707/** 743/**
708 * @brief This function reads of the packet into the upload buff, 744 * if_usb_receive - read the packet into the upload buffer,
709 * wake up the main thread and initialise the Rx callack. 745 * wake up the main thread and initialise the Rx callack
710 * 746 *
711 * @param urb pointer to struct urb 747 * @urb: pointer to &struct urb
712 * @return N/A 748 * returns: N/A
713 */ 749 */
714static void if_usb_receive(struct urb *urb) 750static void if_usb_receive(struct urb *urb)
715{ 751{
@@ -780,12 +816,12 @@ rx_exit:
780} 816}
781 817
782/** 818/**
783 * @brief This function downloads data to FW 819 * if_usb_host_to_card - downloads data to FW
784 * @param priv pointer to struct lbs_private structure 820 * @priv: pointer to &struct lbs_private structure
785 * @param type type of data 821 * @type: type of data
786 * @param buf pointer to data buffer 822 * @payload: pointer to data buffer
787 * @param len number of bytes 823 * @nb: number of bytes
788 * @return 0 or -1 824 * returns: 0 for success or negative error code
789 */ 825 */
790static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type, 826static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type,
791 uint8_t *payload, uint16_t nb) 827 uint8_t *payload, uint16_t nb)
@@ -809,10 +845,11 @@ static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type,
809} 845}
810 846
811/** 847/**
812 * @brief This function issues Boot command to the Boot2 code 848 * if_usb_issue_boot_command - issues Boot command to the Boot2 code
813 * @param ivalue 1:Boot from FW by USB-Download 849 * @cardp: pointer to &if_usb_card
814 * 2:Boot from FW in EEPROM 850 * @ivalue: 1:Boot from FW by USB-Download
815 * @return 0 851 * 2:Boot from FW in EEPROM
852 * returns: 0 for success or negative error code
816 */ 853 */
817static int if_usb_issue_boot_command(struct if_usb_card *cardp, int ivalue) 854static int if_usb_issue_boot_command(struct if_usb_card *cardp, int ivalue)
818{ 855{
@@ -831,11 +868,11 @@ static int if_usb_issue_boot_command(struct if_usb_card *cardp, int ivalue)
831 868
832 869
833/** 870/**
834 * @brief This function checks the validity of Boot2/FW image. 871 * check_fwfile_format - check the validity of Boot2/FW image
835 * 872 *
836 * @param data pointer to image 873 * @data: pointer to image
837 * len image length 874 * @totlen: image length
838 * @return 0 or -1 875 * returns: 0 (good) or 1 (failure)
839 */ 876 */
840static int check_fwfile_format(const uint8_t *data, uint32_t totlen) 877static int check_fwfile_format(const uint8_t *data, uint32_t totlen)
841{ 878{
@@ -870,7 +907,7 @@ static int check_fwfile_format(const uint8_t *data, uint32_t totlen)
870 } while (!exit); 907 } while (!exit);
871 908
872 if (ret) 909 if (ret)
873 lbs_pr_err("firmware file format check FAIL\n"); 910 pr_err("firmware file format check FAIL\n");
874 else 911 else
875 lbs_deb_fw("firmware file format check PASS\n"); 912 lbs_deb_fw("firmware file format check PASS\n");
876 913
@@ -879,13 +916,13 @@ static int check_fwfile_format(const uint8_t *data, uint32_t totlen)
879 916
880 917
881/** 918/**
882* @brief This function programs the firmware subject to cmd 919* if_usb_prog_firmware - programs the firmware subject to cmd
883* 920*
884* @param cardp the if_usb_card descriptor 921* @cardp: the if_usb_card descriptor
885* fwname firmware or boot2 image file name 922* @fwname: firmware or boot2 image file name
886* cmd either BOOT_CMD_FW_BY_USB, BOOT_CMD_UPDATE_FW, 923* @cmd: either BOOT_CMD_FW_BY_USB, BOOT_CMD_UPDATE_FW,
887* or BOOT_CMD_UPDATE_BOOT2. 924* or BOOT_CMD_UPDATE_BOOT2.
888* @return 0 or error code 925* returns: 0 or error code
889*/ 926*/
890static int if_usb_prog_firmware(struct if_usb_card *cardp, 927static int if_usb_prog_firmware(struct if_usb_card *cardp,
891 const char *fwname, int cmd) 928 const char *fwname, int cmd)
@@ -924,6 +961,38 @@ static int if_usb_prog_firmware(struct if_usb_card *cardp,
924 return ret; 961 return ret;
925} 962}
926 963
964/* table of firmware file names */
965static const struct {
966 u32 model;
967 const char *fwname;
968} fw_table[] = {
969 { MODEL_8388, "libertas/usb8388_v9.bin" },
970 { MODEL_8388, "libertas/usb8388_v5.bin" },
971 { MODEL_8388, "libertas/usb8388.bin" },
972 { MODEL_8388, "usb8388.bin" },
973 { MODEL_8682, "libertas/usb8682.bin" }
974};
975
976static int get_fw(struct if_usb_card *cardp, const char *fwname)
977{
978 int i;
979
980 /* Try user-specified firmware first */
981 if (fwname)
982 return request_firmware(&cardp->fw, fwname, &cardp->udev->dev);
983
984 /* Otherwise search for firmware to use */
985 for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
986 if (fw_table[i].model != cardp->model)
987 continue;
988 if (request_firmware(&cardp->fw, fw_table[i].fwname,
989 &cardp->udev->dev) == 0)
990 return 0;
991 }
992
993 return -ENOENT;
994}
995
927static int __if_usb_prog_firmware(struct if_usb_card *cardp, 996static int __if_usb_prog_firmware(struct if_usb_card *cardp,
928 const char *fwname, int cmd) 997 const char *fwname, int cmd)
929{ 998{
@@ -933,10 +1002,9 @@ static int __if_usb_prog_firmware(struct if_usb_card *cardp,
933 1002
934 lbs_deb_enter(LBS_DEB_USB); 1003 lbs_deb_enter(LBS_DEB_USB);
935 1004
936 ret = request_firmware(&cardp->fw, fwname, &cardp->udev->dev); 1005 ret = get_fw(cardp, fwname);
937 if (ret < 0) { 1006 if (ret) {
938 lbs_pr_err("request_firmware() failed with %#x\n", ret); 1007 pr_err("failed to find firmware (%d)\n", ret);
939 lbs_pr_err("firmware %s not found\n", fwname);
940 goto done; 1008 goto done;
941 } 1009 }
942 1010
@@ -1011,13 +1079,13 @@ restart:
1011 usb_kill_urb(cardp->rx_urb); 1079 usb_kill_urb(cardp->rx_urb);
1012 1080
1013 if (!cardp->fwdnldover) { 1081 if (!cardp->fwdnldover) {
1014 lbs_pr_info("failed to load fw, resetting device!\n"); 1082 pr_info("failed to load fw, resetting device!\n");
1015 if (--reset_count >= 0) { 1083 if (--reset_count >= 0) {
1016 if_usb_reset_device(cardp); 1084 if_usb_reset_device(cardp);
1017 goto restart; 1085 goto restart;
1018 } 1086 }
1019 1087
1020 lbs_pr_info("FW download failure, time = %d ms\n", i * 100); 1088 pr_info("FW download failure, time = %d ms\n", i * 100);
1021 ret = -EIO; 1089 ret = -EIO;
1022 goto release_fw; 1090 goto release_fw;
1023 } 1091 }
@@ -1044,12 +1112,6 @@ static int if_usb_suspend(struct usb_interface *intf, pm_message_t message)
1044 if (priv->psstate != PS_STATE_FULL_POWER) 1112 if (priv->psstate != PS_STATE_FULL_POWER)
1045 return -1; 1113 return -1;
1046 1114
1047 if (priv->wol_criteria == EHS_REMOVE_WAKEUP) {
1048 lbs_pr_info("Suspend attempt without "
1049 "configuring wake params!\n");
1050 return -ENOSYS;
1051 }
1052
1053 ret = lbs_suspend(priv); 1115 ret = lbs_suspend(priv);
1054 if (ret) 1116 if (ret)
1055 goto out; 1117 goto out;
diff --git a/drivers/net/wireless/libertas/if_usb.h b/drivers/net/wireless/libertas/if_usb.h
index 5ba0aee0eb2f..6e42eac331de 100644
--- a/drivers/net/wireless/libertas/if_usb.h
+++ b/drivers/net/wireless/libertas/if_usb.h
@@ -6,9 +6,9 @@
6 6
7struct lbs_private; 7struct lbs_private;
8 8
9/** 9/*
10 * This file contains definition for USB interface. 10 * This file contains definition for USB interface.
11 */ 11 */
12#define CMD_TYPE_REQUEST 0xF00DFACE 12#define CMD_TYPE_REQUEST 0xF00DFACE
13#define CMD_TYPE_DATA 0xBEADC0DE 13#define CMD_TYPE_DATA 0xBEADC0DE
14#define CMD_TYPE_INDICATION 0xBEEFFACE 14#define CMD_TYPE_INDICATION 0xBEEFFACE
@@ -40,9 +40,10 @@ struct bootcmdresp
40 uint8_t pad[2]; 40 uint8_t pad[2];
41}; 41};
42 42
43/** USB card description structure*/ 43/* USB card description structure*/
44struct if_usb_card { 44struct if_usb_card {
45 struct usb_device *udev; 45 struct usb_device *udev;
46 uint32_t model; /* MODEL_* */
46 struct urb *rx_urb, *tx_urb; 47 struct urb *rx_urb, *tx_urb;
47 struct lbs_private *priv; 48 struct lbs_private *priv;
48 49
@@ -76,7 +77,7 @@ struct if_usb_card {
76 __le16 boot2_version; 77 __le16 boot2_version;
77}; 78};
78 79
79/** fwheader */ 80/* fwheader */
80struct fwheader { 81struct fwheader {
81 __le32 dnldcmd; 82 __le32 dnldcmd;
82 __le32 baseaddr; 83 __le32 baseaddr;
@@ -85,14 +86,14 @@ struct fwheader {
85}; 86};
86 87
87#define FW_MAX_DATA_BLK_SIZE 600 88#define FW_MAX_DATA_BLK_SIZE 600
88/** FWData */ 89/* FWData */
89struct fwdata { 90struct fwdata {
90 struct fwheader hdr; 91 struct fwheader hdr;
91 __le32 seqnum; 92 __le32 seqnum;
92 uint8_t data[0]; 93 uint8_t data[0];
93}; 94};
94 95
95/** fwsyncheader */ 96/* fwsyncheader */
96struct fwsyncheader { 97struct fwsyncheader {
97 __le32 cmd; 98 __le32 cmd;
98 __le32 seqnum; 99 __le32 seqnum;
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index 24958a86747b..8c40949cb076 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -1,8 +1,10 @@
1/** 1/*
2 * This file contains the major functions in WLAN 2 * This file contains the major functions in WLAN
3 * driver. It includes init, exit, open, close and main 3 * driver. It includes init, exit, open, close and main
4 * thread etc.. 4 * thread etc..
5 */ 5 */
6
7#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6 8
7#include <linux/moduleparam.h> 9#include <linux/moduleparam.h>
8#include <linux/delay.h> 10#include <linux/delay.h>
@@ -34,19 +36,25 @@ unsigned int lbs_debug;
34EXPORT_SYMBOL_GPL(lbs_debug); 36EXPORT_SYMBOL_GPL(lbs_debug);
35module_param_named(libertas_debug, lbs_debug, int, 0644); 37module_param_named(libertas_debug, lbs_debug, int, 0644);
36 38
39unsigned int lbs_disablemesh;
40EXPORT_SYMBOL_GPL(lbs_disablemesh);
41module_param_named(libertas_disablemesh, lbs_disablemesh, int, 0644);
42
37 43
38/* This global structure is used to send the confirm_sleep command as 44/*
39 * fast as possible down to the firmware. */ 45 * This global structure is used to send the confirm_sleep command as
46 * fast as possible down to the firmware.
47 */
40struct cmd_confirm_sleep confirm_sleep; 48struct cmd_confirm_sleep confirm_sleep;
41 49
42 50
43/** 51/*
44 * the table to keep region code 52 * the table to keep region code
45 */ 53 */
46u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] = 54u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
47 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 }; 55 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
48 56
49/** 57/*
50 * FW rate table. FW refers to rates by their index in this table, not by the 58 * FW rate table. FW refers to rates by their index in this table, not by the
51 * rate value itself. Values of 0x00 are 59 * rate value itself. Values of 0x00 are
52 * reserved positions. 60 * reserved positions.
@@ -57,10 +65,10 @@ static u8 fw_data_rates[MAX_RATES] =
57}; 65};
58 66
59/** 67/**
60 * @brief use index to get the data rate 68 * lbs_fw_index_to_data_rate - use index to get the data rate
61 * 69 *
62 * @param idx The index of data rate 70 * @idx: The index of data rate
63 * @return data rate or 0 71 * returns: data rate or 0
64 */ 72 */
65u32 lbs_fw_index_to_data_rate(u8 idx) 73u32 lbs_fw_index_to_data_rate(u8 idx)
66{ 74{
@@ -70,10 +78,10 @@ u32 lbs_fw_index_to_data_rate(u8 idx)
70} 78}
71 79
72/** 80/**
73 * @brief use rate to get the index 81 * lbs_data_rate_to_fw_index - use rate to get the index
74 * 82 *
75 * @param rate data rate 83 * @rate: data rate
76 * @return index or 0 84 * returns: index or 0
77 */ 85 */
78u8 lbs_data_rate_to_fw_index(u32 rate) 86u8 lbs_data_rate_to_fw_index(u32 rate)
79{ 87{
@@ -91,10 +99,10 @@ u8 lbs_data_rate_to_fw_index(u32 rate)
91 99
92 100
93/** 101/**
94 * @brief This function opens the ethX interface 102 * lbs_dev_open - open the ethX interface
95 * 103 *
96 * @param dev A pointer to net_device structure 104 * @dev: A pointer to &net_device structure
97 * @return 0 or -EBUSY if monitor mode active 105 * returns: 0 or -EBUSY if monitor mode active
98 */ 106 */
99static int lbs_dev_open(struct net_device *dev) 107static int lbs_dev_open(struct net_device *dev)
100{ 108{
@@ -104,6 +112,7 @@ static int lbs_dev_open(struct net_device *dev)
104 lbs_deb_enter(LBS_DEB_NET); 112 lbs_deb_enter(LBS_DEB_NET);
105 113
106 spin_lock_irq(&priv->driver_lock); 114 spin_lock_irq(&priv->driver_lock);
115 priv->stopping = false;
107 116
108 if (priv->connect_status == LBS_CONNECTED) 117 if (priv->connect_status == LBS_CONNECTED)
109 netif_carrier_on(dev); 118 netif_carrier_on(dev);
@@ -119,10 +128,10 @@ static int lbs_dev_open(struct net_device *dev)
119} 128}
120 129
121/** 130/**
122 * @brief This function closes the ethX interface 131 * lbs_eth_stop - close the ethX interface
123 * 132 *
124 * @param dev A pointer to net_device structure 133 * @dev: A pointer to &net_device structure
125 * @return 0 134 * returns: 0
126 */ 135 */
127static int lbs_eth_stop(struct net_device *dev) 136static int lbs_eth_stop(struct net_device *dev)
128{ 137{
@@ -131,37 +140,21 @@ static int lbs_eth_stop(struct net_device *dev)
131 lbs_deb_enter(LBS_DEB_NET); 140 lbs_deb_enter(LBS_DEB_NET);
132 141
133 spin_lock_irq(&priv->driver_lock); 142 spin_lock_irq(&priv->driver_lock);
143 priv->stopping = true;
134 netif_stop_queue(dev); 144 netif_stop_queue(dev);
135 spin_unlock_irq(&priv->driver_lock); 145 spin_unlock_irq(&priv->driver_lock);
136 146
137 schedule_work(&priv->mcast_work); 147 schedule_work(&priv->mcast_work);
148 cancel_delayed_work_sync(&priv->scan_work);
149 if (priv->scan_req) {
150 cfg80211_scan_done(priv->scan_req, false);
151 priv->scan_req = NULL;
152 }
138 153
139 lbs_deb_leave(LBS_DEB_NET); 154 lbs_deb_leave(LBS_DEB_NET);
140 return 0; 155 return 0;
141} 156}
142 157
143static void lbs_tx_timeout(struct net_device *dev)
144{
145 struct lbs_private *priv = dev->ml_priv;
146
147 lbs_deb_enter(LBS_DEB_TX);
148
149 lbs_pr_err("tx watch dog timeout\n");
150
151 dev->trans_start = jiffies; /* prevent tx timeout */
152
153 if (priv->currenttxskb)
154 lbs_send_tx_feedback(priv, 0);
155
156 /* XX: Shouldn't we also call into the hw-specific driver
157 to kick it somehow? */
158 lbs_host_to_card_done(priv);
159
160 /* FIXME: reset the card */
161
162 lbs_deb_leave(LBS_DEB_TX);
163}
164
165void lbs_host_to_card_done(struct lbs_private *priv) 158void lbs_host_to_card_done(struct lbs_private *priv)
166{ 159{
167 unsigned long flags; 160 unsigned long flags;
@@ -329,12 +322,12 @@ void lbs_set_multicast_list(struct net_device *dev)
329} 322}
330 323
331/** 324/**
332 * @brief This function handles the major jobs in the LBS driver. 325 * lbs_thread - handles the major jobs in the LBS driver.
333 * It handles all events generated by firmware, RX data received 326 * It handles all events generated by firmware, RX data received
334 * from firmware and TX data sent from kernel. 327 * from firmware and TX data sent from kernel.
335 * 328 *
336 * @param data A pointer to lbs_thread structure 329 * @data: A pointer to &lbs_thread structure
337 * @return 0 330 * returns: 0
338 */ 331 */
339static int lbs_thread(void *data) 332static int lbs_thread(void *data)
340{ 333{
@@ -455,8 +448,8 @@ static int lbs_thread(void *data)
455 if (priv->cmd_timed_out && priv->cur_cmd) { 448 if (priv->cmd_timed_out && priv->cur_cmd) {
456 struct cmd_ctrl_node *cmdnode = priv->cur_cmd; 449 struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
457 450
458 lbs_pr_info("Timeout submitting command 0x%04x\n", 451 netdev_info(dev, "Timeout submitting command 0x%04x\n",
459 le16_to_cpu(cmdnode->cmdbuf->command)); 452 le16_to_cpu(cmdnode->cmdbuf->command));
460 lbs_complete_command(priv, cmdnode, -ETIMEDOUT); 453 lbs_complete_command(priv, cmdnode, -ETIMEDOUT);
461 if (priv->reset_card) 454 if (priv->reset_card)
462 priv->reset_card(priv); 455 priv->reset_card(priv);
@@ -483,8 +476,8 @@ static int lbs_thread(void *data)
483 * after firmware fixes it 476 * after firmware fixes it
484 */ 477 */
485 priv->psstate = PS_STATE_AWAKE; 478 priv->psstate = PS_STATE_AWAKE;
486 lbs_pr_alert("ignore PS_SleepConfirm in " 479 netdev_alert(dev,
487 "non-connected state\n"); 480 "ignore PS_SleepConfirm in non-connected state\n");
488 } 481 }
489 } 482 }
490 483
@@ -532,6 +525,43 @@ static int lbs_thread(void *data)
532 return 0; 525 return 0;
533} 526}
534 527
528/**
529 * lbs_setup_firmware - gets the HW spec from the firmware and sets
530 * some basic parameters
531 *
532 * @priv: A pointer to &struct lbs_private structure
533 * returns: 0 or -1
534 */
535static int lbs_setup_firmware(struct lbs_private *priv)
536{
537 int ret = -1;
538 s16 curlevel = 0, minlevel = 0, maxlevel = 0;
539
540 lbs_deb_enter(LBS_DEB_FW);
541
542 /* Read MAC address from firmware */
543 memset(priv->current_addr, 0xff, ETH_ALEN);
544 ret = lbs_update_hw_spec(priv);
545 if (ret)
546 goto done;
547
548 /* Read power levels if available */
549 ret = lbs_get_tx_power(priv, &curlevel, &minlevel, &maxlevel);
550 if (ret == 0) {
551 priv->txpower_cur = curlevel;
552 priv->txpower_min = minlevel;
553 priv->txpower_max = maxlevel;
554 }
555
556 /* Send cmd to FW to enable 11D function */
557 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_11D_ENABLE, 1);
558
559 lbs_set_mac_control(priv);
560done:
561 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
562 return ret;
563}
564
535int lbs_suspend(struct lbs_private *priv) 565int lbs_suspend(struct lbs_private *priv)
536{ 566{
537 int ret; 567 int ret;
@@ -541,7 +571,8 @@ int lbs_suspend(struct lbs_private *priv)
541 if (priv->is_deep_sleep) { 571 if (priv->is_deep_sleep) {
542 ret = lbs_set_deep_sleep(priv, 0); 572 ret = lbs_set_deep_sleep(priv, 0);
543 if (ret) { 573 if (ret) {
544 lbs_pr_err("deep sleep cancellation failed: %d\n", ret); 574 netdev_err(priv->dev,
575 "deep sleep cancellation failed: %d\n", ret);
545 return ret; 576 return ret;
546 } 577 }
547 priv->deep_sleep_required = 1; 578 priv->deep_sleep_required = 1;
@@ -574,54 +605,23 @@ int lbs_resume(struct lbs_private *priv)
574 priv->deep_sleep_required = 0; 605 priv->deep_sleep_required = 0;
575 ret = lbs_set_deep_sleep(priv, 1); 606 ret = lbs_set_deep_sleep(priv, 1);
576 if (ret) 607 if (ret)
577 lbs_pr_err("deep sleep activation failed: %d\n", ret); 608 netdev_err(priv->dev,
609 "deep sleep activation failed: %d\n", ret);
578 } 610 }
579 611
612 if (priv->setup_fw_on_resume)
613 ret = lbs_setup_firmware(priv);
614
580 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); 615 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
581 return ret; 616 return ret;
582} 617}
583EXPORT_SYMBOL_GPL(lbs_resume); 618EXPORT_SYMBOL_GPL(lbs_resume);
584 619
585/** 620/**
586 * @brief This function gets the HW spec from the firmware and sets 621 * lbs_cmd_timeout_handler - handles the timeout of command sending.
587 * some basic parameters. 622 * It will re-send the same command again.
588 * 623 *
589 * @param priv A pointer to struct lbs_private structure 624 * @data: &struct lbs_private pointer
590 * @return 0 or -1
591 */
592static int lbs_setup_firmware(struct lbs_private *priv)
593{
594 int ret = -1;
595 s16 curlevel = 0, minlevel = 0, maxlevel = 0;
596
597 lbs_deb_enter(LBS_DEB_FW);
598
599 /* Read MAC address from firmware */
600 memset(priv->current_addr, 0xff, ETH_ALEN);
601 ret = lbs_update_hw_spec(priv);
602 if (ret)
603 goto done;
604
605 /* Read power levels if available */
606 ret = lbs_get_tx_power(priv, &curlevel, &minlevel, &maxlevel);
607 if (ret == 0) {
608 priv->txpower_cur = curlevel;
609 priv->txpower_min = minlevel;
610 priv->txpower_max = maxlevel;
611 }
612
613 /* Send cmd to FW to enable 11D function */
614 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_11D_ENABLE, 1);
615
616 lbs_set_mac_control(priv);
617done:
618 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
619 return ret;
620}
621
622/**
623 * This function handles the timeout of command sending.
624 * It will re-send the same command again.
625 */ 625 */
626static void lbs_cmd_timeout_handler(unsigned long data) 626static void lbs_cmd_timeout_handler(unsigned long data)
627{ 627{
@@ -634,8 +634,8 @@ static void lbs_cmd_timeout_handler(unsigned long data)
634 if (!priv->cur_cmd) 634 if (!priv->cur_cmd)
635 goto out; 635 goto out;
636 636
637 lbs_pr_info("command 0x%04x timed out\n", 637 netdev_info(priv->dev, "command 0x%04x timed out\n",
638 le16_to_cpu(priv->cur_cmd->cmdbuf->command)); 638 le16_to_cpu(priv->cur_cmd->cmdbuf->command));
639 639
640 priv->cmd_timed_out = 1; 640 priv->cmd_timed_out = 1;
641 wake_up_interruptible(&priv->waitq); 641 wake_up_interruptible(&priv->waitq);
@@ -645,8 +645,10 @@ out:
645} 645}
646 646
647/** 647/**
648 * This function put the device back to deep sleep mode when timer expires 648 * auto_deepsleep_timer_fn - put the device back to deep sleep mode when
649 * and no activity (command, event, data etc.) is detected. 649 * timer expires and no activity (command, event, data etc.) is detected.
650 * @data: &struct lbs_private pointer
651 * returns: N/A
650 */ 652 */
651static void auto_deepsleep_timer_fn(unsigned long data) 653static void auto_deepsleep_timer_fn(unsigned long data)
652{ 654{
@@ -738,7 +740,7 @@ static int lbs_init_adapter(struct lbs_private *priv)
738 740
739 /* Allocate the command buffers */ 741 /* Allocate the command buffers */
740 if (lbs_allocate_cmd_buffer(priv)) { 742 if (lbs_allocate_cmd_buffer(priv)) {
741 lbs_pr_err("Out of memory allocating command buffers\n"); 743 pr_err("Out of memory allocating command buffers\n");
742 ret = -ENOMEM; 744 ret = -ENOMEM;
743 goto out; 745 goto out;
744 } 746 }
@@ -748,7 +750,7 @@ static int lbs_init_adapter(struct lbs_private *priv)
748 /* Create the event FIFO */ 750 /* Create the event FIFO */
749 ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL); 751 ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL);
750 if (ret) { 752 if (ret) {
751 lbs_pr_err("Out of memory allocating event FIFO buffer\n"); 753 pr_err("Out of memory allocating event FIFO buffer\n");
752 goto out; 754 goto out;
753 } 755 }
754 756
@@ -775,18 +777,18 @@ static const struct net_device_ops lbs_netdev_ops = {
775 .ndo_stop = lbs_eth_stop, 777 .ndo_stop = lbs_eth_stop,
776 .ndo_start_xmit = lbs_hard_start_xmit, 778 .ndo_start_xmit = lbs_hard_start_xmit,
777 .ndo_set_mac_address = lbs_set_mac_address, 779 .ndo_set_mac_address = lbs_set_mac_address,
778 .ndo_tx_timeout = lbs_tx_timeout,
779 .ndo_set_multicast_list = lbs_set_multicast_list, 780 .ndo_set_multicast_list = lbs_set_multicast_list,
780 .ndo_change_mtu = eth_change_mtu, 781 .ndo_change_mtu = eth_change_mtu,
781 .ndo_validate_addr = eth_validate_addr, 782 .ndo_validate_addr = eth_validate_addr,
782}; 783};
783 784
784/** 785/**
785 * @brief This function adds the card. it will probe the 786 * lbs_add_card - adds the card. It will probe the
786 * card, allocate the lbs_priv and initialize the device. 787 * card, allocate the lbs_priv and initialize the device.
787 * 788 *
788 * @param card A pointer to card 789 * @card: A pointer to card
789 * @return A pointer to struct lbs_private structure 790 * @dmdev: A pointer to &struct device
791 * returns: A pointer to &struct lbs_private structure
790 */ 792 */
791struct lbs_private *lbs_add_card(void *card, struct device *dmdev) 793struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
792{ 794{
@@ -799,7 +801,7 @@ struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
799 /* Allocate an Ethernet device and register it */ 801 /* Allocate an Ethernet device and register it */
800 wdev = lbs_cfg_alloc(dmdev); 802 wdev = lbs_cfg_alloc(dmdev);
801 if (IS_ERR(wdev)) { 803 if (IS_ERR(wdev)) {
802 lbs_pr_err("cfg80211 init failed\n"); 804 pr_err("cfg80211 init failed\n");
803 goto done; 805 goto done;
804 } 806 }
805 807
@@ -808,7 +810,7 @@ struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
808 priv->wdev = wdev; 810 priv->wdev = wdev;
809 811
810 if (lbs_init_adapter(priv)) { 812 if (lbs_init_adapter(priv)) {
811 lbs_pr_err("failed to initialize adapter structure.\n"); 813 pr_err("failed to initialize adapter structure\n");
812 goto err_wdev; 814 goto err_wdev;
813 } 815 }
814 816
@@ -844,9 +846,10 @@ struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
844 priv->work_thread = create_singlethread_workqueue("lbs_worker"); 846 priv->work_thread = create_singlethread_workqueue("lbs_worker");
845 INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker); 847 INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker);
846 848
847 priv->wol_criteria = 0xffffffff; 849 priv->wol_criteria = EHS_REMOVE_WAKEUP;
848 priv->wol_gpio = 0xff; 850 priv->wol_gpio = 0xff;
849 priv->wol_gap = 20; 851 priv->wol_gap = 20;
852 priv->ehs_remove_supported = true;
850 853
851 goto done; 854 goto done;
852 855
@@ -908,8 +911,6 @@ void lbs_remove_card(struct lbs_private *priv)
908 911
909 lbs_free_adapter(priv); 912 lbs_free_adapter(priv);
910 lbs_cfg_free(priv); 913 lbs_cfg_free(priv);
911
912 priv->dev = NULL;
913 free_netdev(dev); 914 free_netdev(dev);
914 915
915 lbs_deb_leave(LBS_DEB_MAIN); 916 lbs_deb_leave(LBS_DEB_MAIN);
@@ -941,17 +942,20 @@ int lbs_start_card(struct lbs_private *priv)
941 goto done; 942 goto done;
942 943
943 if (lbs_cfg_register(priv)) { 944 if (lbs_cfg_register(priv)) {
944 lbs_pr_err("cannot register device\n"); 945 pr_err("cannot register device\n");
945 goto done; 946 goto done;
946 } 947 }
947 948
948 lbs_update_channel(priv); 949 lbs_update_channel(priv);
949 950
950 lbs_init_mesh(priv); 951 if (!lbs_disablemesh)
952 lbs_init_mesh(priv);
953 else
954 pr_info("%s: mesh disabled\n", dev->name);
951 955
952 lbs_debugfs_init_one(priv, dev); 956 lbs_debugfs_init_one(priv, dev);
953 957
954 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name); 958 netdev_info(dev, "Marvell WLAN 802.11 adapter\n");
955 959
956 ret = 0; 960 ret = 0;
957 961
@@ -1047,6 +1051,111 @@ void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx)
1047} 1051}
1048EXPORT_SYMBOL_GPL(lbs_notify_command_response); 1052EXPORT_SYMBOL_GPL(lbs_notify_command_response);
1049 1053
1054/**
1055 * lbs_get_firmware - Retrieves two-stage firmware
1056 *
1057 * @dev: A pointer to &device structure
1058 * @user_helper: User-defined helper firmware file
1059 * @user_mainfw: User-defined main firmware file
1060 * @card_model: Bus-specific card model ID used to filter firmware table
1061 * elements
1062 * @fw_table: Table of firmware file names and device model numbers
1063 * terminated by an entry with a NULL helper name
1064 * @helper: On success, the helper firmware; caller must free
1065 * @mainfw: On success, the main firmware; caller must free
1066 *
1067 * returns: 0 on success, non-zero on failure
1068 */
1069int lbs_get_firmware(struct device *dev, const char *user_helper,
1070 const char *user_mainfw, u32 card_model,
1071 const struct lbs_fw_table *fw_table,
1072 const struct firmware **helper,
1073 const struct firmware **mainfw)
1074{
1075 const struct lbs_fw_table *iter;
1076 int ret;
1077
1078 BUG_ON(helper == NULL);
1079 BUG_ON(mainfw == NULL);
1080
1081 /* Try user-specified firmware first */
1082 if (user_helper) {
1083 ret = request_firmware(helper, user_helper, dev);
1084 if (ret) {
1085 dev_err(dev, "couldn't find helper firmware %s\n",
1086 user_helper);
1087 goto fail;
1088 }
1089 }
1090 if (user_mainfw) {
1091 ret = request_firmware(mainfw, user_mainfw, dev);
1092 if (ret) {
1093 dev_err(dev, "couldn't find main firmware %s\n",
1094 user_mainfw);
1095 goto fail;
1096 }
1097 }
1098
1099 if (*helper && *mainfw)
1100 return 0;
1101
1102 /* Otherwise search for firmware to use. If neither the helper or
1103 * the main firmware were specified by the user, then we need to
1104 * make sure that found helper & main are from the same entry in
1105 * fw_table.
1106 */
1107 iter = fw_table;
1108 while (iter && iter->helper) {
1109 if (iter->model != card_model)
1110 goto next;
1111
1112 if (*helper == NULL) {
1113 ret = request_firmware(helper, iter->helper, dev);
1114 if (ret)
1115 goto next;
1116
1117 /* If the device has one-stage firmware (ie cf8305) and
1118 * we've got it then we don't need to bother with the
1119 * main firmware.
1120 */
1121 if (iter->fwname == NULL)
1122 return 0;
1123 }
1124
1125 if (*mainfw == NULL) {
1126 ret = request_firmware(mainfw, iter->fwname, dev);
1127 if (ret && !user_helper) {
1128 /* Clear the helper if it wasn't user-specified
1129 * and the main firmware load failed, to ensure
1130 * we don't have mismatched firmware pairs.
1131 */
1132 release_firmware(*helper);
1133 *helper = NULL;
1134 }
1135 }
1136
1137 if (*helper && *mainfw)
1138 return 0;
1139
1140 next:
1141 iter++;
1142 }
1143
1144 fail:
1145 /* Failed */
1146 if (*helper) {
1147 release_firmware(*helper);
1148 *helper = NULL;
1149 }
1150 if (*mainfw) {
1151 release_firmware(*mainfw);
1152 *mainfw = NULL;
1153 }
1154
1155 return -ENOENT;
1156}
1157EXPORT_SYMBOL_GPL(lbs_get_firmware);
1158
1050static int __init lbs_init_module(void) 1159static int __init lbs_init_module(void)
1051{ 1160{
1052 lbs_deb_enter(LBS_DEB_MAIN); 1161 lbs_deb_enter(LBS_DEB_MAIN);
diff --git a/drivers/net/wireless/libertas/mesh.c b/drivers/net/wireless/libertas/mesh.c
index 194762ab0142..24cf06680c6b 100644
--- a/drivers/net/wireless/libertas/mesh.c
+++ b/drivers/net/wireless/libertas/mesh.c
@@ -1,3 +1,5 @@
1#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2
1#include <linux/delay.h> 3#include <linux/delay.h>
2#include <linux/etherdevice.h> 4#include <linux/etherdevice.h>
3#include <linux/netdevice.h> 5#include <linux/netdevice.h>
@@ -16,12 +18,15 @@
16 * Mesh sysfs support 18 * Mesh sysfs support
17 */ 19 */
18 20
19/** 21/*
20 * Attributes exported through sysfs 22 * Attributes exported through sysfs
21 */ 23 */
22 24
23/** 25/**
24 * @brief Get function for sysfs attribute anycast_mask 26 * lbs_anycast_get - Get function for sysfs attribute anycast_mask
27 * @dev: the &struct device
28 * @attr: device attributes
29 * @buf: buffer where data will be returned
25 */ 30 */
26static ssize_t lbs_anycast_get(struct device *dev, 31static ssize_t lbs_anycast_get(struct device *dev,
27 struct device_attribute *attr, char * buf) 32 struct device_attribute *attr, char * buf)
@@ -40,7 +45,11 @@ static ssize_t lbs_anycast_get(struct device *dev,
40} 45}
41 46
42/** 47/**
43 * @brief Set function for sysfs attribute anycast_mask 48 * lbs_anycast_set - Set function for sysfs attribute anycast_mask
49 * @dev: the &struct device
50 * @attr: device attributes
51 * @buf: buffer that contains new attribute value
52 * @count: size of buffer
44 */ 53 */
45static ssize_t lbs_anycast_set(struct device *dev, 54static ssize_t lbs_anycast_set(struct device *dev,
46 struct device_attribute *attr, const char * buf, size_t count) 55 struct device_attribute *attr, const char * buf, size_t count)
@@ -62,7 +71,10 @@ static ssize_t lbs_anycast_set(struct device *dev,
62} 71}
63 72
64/** 73/**
65 * @brief Get function for sysfs attribute prb_rsp_limit 74 * lbs_prb_rsp_limit_get - Get function for sysfs attribute prb_rsp_limit
75 * @dev: the &struct device
76 * @attr: device attributes
77 * @buf: buffer where data will be returned
66 */ 78 */
67static ssize_t lbs_prb_rsp_limit_get(struct device *dev, 79static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
68 struct device_attribute *attr, char *buf) 80 struct device_attribute *attr, char *buf)
@@ -85,7 +97,11 @@ static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
85} 97}
86 98
87/** 99/**
88 * @brief Set function for sysfs attribute prb_rsp_limit 100 * lbs_prb_rsp_limit_set - Set function for sysfs attribute prb_rsp_limit
101 * @dev: the &struct device
102 * @attr: device attributes
103 * @buf: buffer that contains new attribute value
104 * @count: size of buffer
89 */ 105 */
90static ssize_t lbs_prb_rsp_limit_set(struct device *dev, 106static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
91 struct device_attribute *attr, const char *buf, size_t count) 107 struct device_attribute *attr, const char *buf, size_t count)
@@ -114,7 +130,10 @@ static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
114} 130}
115 131
116/** 132/**
117 * Get function for sysfs attribute mesh 133 * lbs_mesh_get - Get function for sysfs attribute mesh
134 * @dev: the &struct device
135 * @attr: device attributes
136 * @buf: buffer where data will be returned
118 */ 137 */
119static ssize_t lbs_mesh_get(struct device *dev, 138static ssize_t lbs_mesh_get(struct device *dev,
120 struct device_attribute *attr, char * buf) 139 struct device_attribute *attr, char * buf)
@@ -124,7 +143,11 @@ static ssize_t lbs_mesh_get(struct device *dev,
124} 143}
125 144
126/** 145/**
127 * Set function for sysfs attribute mesh 146 * lbs_mesh_set - Set function for sysfs attribute mesh
147 * @dev: the &struct device
148 * @attr: device attributes
149 * @buf: buffer that contains new attribute value
150 * @count: size of buffer
128 */ 151 */
129static ssize_t lbs_mesh_set(struct device *dev, 152static ssize_t lbs_mesh_set(struct device *dev,
130 struct device_attribute *attr, const char * buf, size_t count) 153 struct device_attribute *attr, const char * buf, size_t count)
@@ -151,19 +174,19 @@ static ssize_t lbs_mesh_set(struct device *dev,
151 return count; 174 return count;
152} 175}
153 176
154/** 177/*
155 * lbs_mesh attribute to be exported per ethX interface 178 * lbs_mesh attribute to be exported per ethX interface
156 * through sysfs (/sys/class/net/ethX/lbs_mesh) 179 * through sysfs (/sys/class/net/ethX/lbs_mesh)
157 */ 180 */
158static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set); 181static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
159 182
160/** 183/*
161 * anycast_mask attribute to be exported per mshX interface 184 * anycast_mask attribute to be exported per mshX interface
162 * through sysfs (/sys/class/net/mshX/anycast_mask) 185 * through sysfs (/sys/class/net/mshX/anycast_mask)
163 */ 186 */
164static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set); 187static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
165 188
166/** 189/*
167 * prb_rsp_limit attribute to be exported per mshX interface 190 * prb_rsp_limit attribute to be exported per mshX interface
168 * through sysfs (/sys/class/net/mshX/prb_rsp_limit) 191 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
169 */ 192 */
@@ -246,7 +269,7 @@ int lbs_init_mesh(struct lbs_private *priv)
246 lbs_add_mesh(priv); 269 lbs_add_mesh(priv);
247 270
248 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh)) 271 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
249 lbs_pr_err("cannot register lbs_mesh attribute\n"); 272 netdev_err(dev, "cannot register lbs_mesh attribute\n");
250 273
251 ret = 1; 274 ret = 1;
252 } 275 }
@@ -274,10 +297,10 @@ int lbs_deinit_mesh(struct lbs_private *priv)
274 297
275 298
276/** 299/**
277 * @brief This function closes the mshX interface 300 * lbs_mesh_stop - close the mshX interface
278 * 301 *
279 * @param dev A pointer to net_device structure 302 * @dev: A pointer to &net_device structure
280 * @return 0 303 * returns: 0
281 */ 304 */
282static int lbs_mesh_stop(struct net_device *dev) 305static int lbs_mesh_stop(struct net_device *dev)
283{ 306{
@@ -301,10 +324,10 @@ static int lbs_mesh_stop(struct net_device *dev)
301} 324}
302 325
303/** 326/**
304 * @brief This function opens the mshX interface 327 * lbs_mesh_dev_open - open the mshX interface
305 * 328 *
306 * @param dev A pointer to net_device structure 329 * @dev: A pointer to &net_device structure
307 * @return 0 or -EBUSY if monitor mode active 330 * returns: 0 or -EBUSY if monitor mode active
308 */ 331 */
309static int lbs_mesh_dev_open(struct net_device *dev) 332static int lbs_mesh_dev_open(struct net_device *dev)
310{ 333{
@@ -342,10 +365,10 @@ static const struct net_device_ops mesh_netdev_ops = {
342}; 365};
343 366
344/** 367/**
345 * @brief This function adds mshX interface 368 * lbs_add_mesh - add mshX interface
346 * 369 *
347 * @param priv A pointer to the struct lbs_private structure 370 * @priv: A pointer to the &struct lbs_private structure
348 * @return 0 if successful, -X otherwise 371 * returns: 0 if successful, -X otherwise
349 */ 372 */
350int lbs_add_mesh(struct lbs_private *priv) 373int lbs_add_mesh(struct lbs_private *priv)
351{ 374{
@@ -374,7 +397,7 @@ int lbs_add_mesh(struct lbs_private *priv)
374 /* Register virtual mesh interface */ 397 /* Register virtual mesh interface */
375 ret = register_netdev(mesh_dev); 398 ret = register_netdev(mesh_dev);
376 if (ret) { 399 if (ret) {
377 lbs_pr_err("cannot register mshX virtual interface\n"); 400 pr_err("cannot register mshX virtual interface\n");
378 goto err_free; 401 goto err_free;
379 } 402 }
380 403
@@ -456,13 +479,13 @@ void lbs_mesh_set_txpd(struct lbs_private *priv,
456 */ 479 */
457 480
458/** 481/**
459 * @brief Add or delete Mesh Blinding Table entries 482 * lbs_mesh_bt_add_del - Add or delete Mesh Blinding Table entries
460 * 483 *
461 * @param priv A pointer to struct lbs_private structure 484 * @priv: A pointer to &struct lbs_private structure
462 * @param add TRUE to add the entry, FALSE to delete it 485 * @add: TRUE to add the entry, FALSE to delete it
463 * @param addr1 Destination address to blind or unblind 486 * @addr1: Destination address to blind or unblind
464 * 487 *
465 * @return 0 on success, error on failure 488 * returns: 0 on success, error on failure
466 */ 489 */
467int lbs_mesh_bt_add_del(struct lbs_private *priv, bool add, u8 *addr1) 490int lbs_mesh_bt_add_del(struct lbs_private *priv, bool add, u8 *addr1)
468{ 491{
@@ -493,11 +516,11 @@ int lbs_mesh_bt_add_del(struct lbs_private *priv, bool add, u8 *addr1)
493} 516}
494 517
495/** 518/**
496 * @brief Reset/clear the mesh blinding table 519 * lbs_mesh_bt_reset - Reset/clear the mesh blinding table
497 * 520 *
498 * @param priv A pointer to struct lbs_private structure 521 * @priv: A pointer to &struct lbs_private structure
499 * 522 *
500 * @return 0 on success, error on failure 523 * returns: 0 on success, error on failure
501 */ 524 */
502int lbs_mesh_bt_reset(struct lbs_private *priv) 525int lbs_mesh_bt_reset(struct lbs_private *priv)
503{ 526{
@@ -517,17 +540,18 @@ int lbs_mesh_bt_reset(struct lbs_private *priv)
517} 540}
518 541
519/** 542/**
520 * @brief Gets the inverted status of the mesh blinding table 543 * lbs_mesh_bt_get_inverted - Gets the inverted status of the mesh
544 * blinding table
521 * 545 *
522 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the 546 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
523 * table, but an inverted table allows *only* traffic from nodes listed in 547 * table, but an inverted table allows *only* traffic from nodes listed in
524 * the table. 548 * the table.
525 * 549 *
526 * @param priv A pointer to struct lbs_private structure 550 * @priv: A pointer to &struct lbs_private structure
527 * @param invert On success, TRUE if the blinding table is inverted, 551 * @inverted: On success, TRUE if the blinding table is inverted,
528 * FALSE if it is not inverted 552 * FALSE if it is not inverted
529 * 553 *
530 * @return 0 on success, error on failure 554 * returns: 0 on success, error on failure
531 */ 555 */
532int lbs_mesh_bt_get_inverted(struct lbs_private *priv, bool *inverted) 556int lbs_mesh_bt_get_inverted(struct lbs_private *priv, bool *inverted)
533{ 557{
@@ -551,18 +575,19 @@ int lbs_mesh_bt_get_inverted(struct lbs_private *priv, bool *inverted)
551} 575}
552 576
553/** 577/**
554 * @brief Sets the inverted status of the mesh blinding table 578 * lbs_mesh_bt_set_inverted - Sets the inverted status of the mesh
579 * blinding table
555 * 580 *
556 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the 581 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
557 * table, but an inverted table allows *only* traffic from nodes listed in 582 * table, but an inverted table allows *only* traffic from nodes listed in
558 * the table. 583 * the table.
559 * 584 *
560 * @param priv A pointer to struct lbs_private structure 585 * @priv: A pointer to &struct lbs_private structure
561 * @param invert TRUE to invert the blinding table (only traffic from 586 * @inverted: TRUE to invert the blinding table (only traffic from
562 * listed nodes allowed), FALSE to return it 587 * listed nodes allowed), FALSE to return it
563 * to normal state (listed nodes ignored) 588 * to normal state (listed nodes ignored)
564 * 589 *
565 * @return 0 on success, error on failure 590 * returns: 0 on success, error on failure
566 */ 591 */
567int lbs_mesh_bt_set_inverted(struct lbs_private *priv, bool inverted) 592int lbs_mesh_bt_set_inverted(struct lbs_private *priv, bool inverted)
568{ 593{
@@ -574,7 +599,7 @@ int lbs_mesh_bt_set_inverted(struct lbs_private *priv, bool inverted)
574 memset(&cmd, 0, sizeof(cmd)); 599 memset(&cmd, 0, sizeof(cmd));
575 cmd.hdr.size = cpu_to_le16(sizeof(cmd)); 600 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
576 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT); 601 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT);
577 cmd.id = !!inverted; 602 cmd.id = cpu_to_le32(!!inverted);
578 603
579 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd); 604 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
580 605
@@ -583,13 +608,13 @@ int lbs_mesh_bt_set_inverted(struct lbs_private *priv, bool inverted)
583} 608}
584 609
585/** 610/**
586 * @brief List an entry in the mesh blinding table 611 * lbs_mesh_bt_get_entry - List an entry in the mesh blinding table
587 * 612 *
588 * @param priv A pointer to struct lbs_private structure 613 * @priv: A pointer to &struct lbs_private structure
589 * @param id The ID of the entry to list 614 * @id: The ID of the entry to list
590 * @param addr1 MAC address associated with the table entry 615 * @addr1: MAC address associated with the table entry
591 * 616 *
592 * @return 0 on success, error on failure 617 * returns: 0 on success, error on failure
593 */ 618 */
594int lbs_mesh_bt_get_entry(struct lbs_private *priv, u32 id, u8 *addr1) 619int lbs_mesh_bt_get_entry(struct lbs_private *priv, u32 id, u8 *addr1)
595{ 620{
@@ -614,14 +639,14 @@ int lbs_mesh_bt_get_entry(struct lbs_private *priv, u32 id, u8 *addr1)
614} 639}
615 640
616/** 641/**
617 * @brief Access the mesh forwarding table 642 * lbs_cmd_fwt_access - Access the mesh forwarding table
618 * 643 *
619 * @param priv A pointer to struct lbs_private structure 644 * @priv: A pointer to &struct lbs_private structure
620 * @param cmd_action The forwarding table action to perform 645 * @cmd_action: The forwarding table action to perform
621 * @param cmd The pre-filled FWT_ACCESS command 646 * @cmd: The pre-filled FWT_ACCESS command
622 * 647 *
623 * @return 0 on success and 'cmd' will be filled with the 648 * returns: 0 on success and 'cmd' will be filled with the
624 * firmware's response 649 * firmware's response
625 */ 650 */
626int lbs_cmd_fwt_access(struct lbs_private *priv, u16 cmd_action, 651int lbs_cmd_fwt_access(struct lbs_private *priv, u16 cmd_action,
627 struct cmd_ds_fwt_access *cmd) 652 struct cmd_ds_fwt_access *cmd)
@@ -774,7 +799,10 @@ static int mesh_get_default_parameters(struct device *dev,
774} 799}
775 800
776/** 801/**
777 * @brief Get function for sysfs attribute bootflag 802 * bootflag_get - Get function for sysfs attribute bootflag
803 * @dev: the &struct device
804 * @attr: device attributes
805 * @buf: buffer where data will be returned
778 */ 806 */
779static ssize_t bootflag_get(struct device *dev, 807static ssize_t bootflag_get(struct device *dev,
780 struct device_attribute *attr, char *buf) 808 struct device_attribute *attr, char *buf)
@@ -791,7 +819,11 @@ static ssize_t bootflag_get(struct device *dev,
791} 819}
792 820
793/** 821/**
794 * @brief Set function for sysfs attribute bootflag 822 * bootflag_set - Set function for sysfs attribute bootflag
823 * @dev: the &struct device
824 * @attr: device attributes
825 * @buf: buffer that contains new attribute value
826 * @count: size of buffer
795 */ 827 */
796static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr, 828static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr,
797 const char *buf, size_t count) 829 const char *buf, size_t count)
@@ -817,7 +849,10 @@ static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr,
817} 849}
818 850
819/** 851/**
820 * @brief Get function for sysfs attribute boottime 852 * boottime_get - Get function for sysfs attribute boottime
853 * @dev: the &struct device
854 * @attr: device attributes
855 * @buf: buffer where data will be returned
821 */ 856 */
822static ssize_t boottime_get(struct device *dev, 857static ssize_t boottime_get(struct device *dev,
823 struct device_attribute *attr, char *buf) 858 struct device_attribute *attr, char *buf)
@@ -834,7 +869,11 @@ static ssize_t boottime_get(struct device *dev,
834} 869}
835 870
836/** 871/**
837 * @brief Set function for sysfs attribute boottime 872 * boottime_set - Set function for sysfs attribute boottime
873 * @dev: the &struct device
874 * @attr: device attributes
875 * @buf: buffer that contains new attribute value
876 * @count: size of buffer
838 */ 877 */
839static ssize_t boottime_set(struct device *dev, 878static ssize_t boottime_set(struct device *dev,
840 struct device_attribute *attr, const char *buf, size_t count) 879 struct device_attribute *attr, const char *buf, size_t count)
@@ -869,7 +908,10 @@ static ssize_t boottime_set(struct device *dev,
869} 908}
870 909
871/** 910/**
872 * @brief Get function for sysfs attribute channel 911 * channel_get - Get function for sysfs attribute channel
912 * @dev: the &struct device
913 * @attr: device attributes
914 * @buf: buffer where data will be returned
873 */ 915 */
874static ssize_t channel_get(struct device *dev, 916static ssize_t channel_get(struct device *dev,
875 struct device_attribute *attr, char *buf) 917 struct device_attribute *attr, char *buf)
@@ -886,7 +928,11 @@ static ssize_t channel_get(struct device *dev,
886} 928}
887 929
888/** 930/**
889 * @brief Set function for sysfs attribute channel 931 * channel_set - Set function for sysfs attribute channel
932 * @dev: the &struct device
933 * @attr: device attributes
934 * @buf: buffer that contains new attribute value
935 * @count: size of buffer
890 */ 936 */
891static ssize_t channel_set(struct device *dev, struct device_attribute *attr, 937static ssize_t channel_set(struct device *dev, struct device_attribute *attr,
892 const char *buf, size_t count) 938 const char *buf, size_t count)
@@ -912,13 +958,15 @@ static ssize_t channel_set(struct device *dev, struct device_attribute *attr,
912} 958}
913 959
914/** 960/**
915 * @brief Get function for sysfs attribute mesh_id 961 * mesh_id_get - Get function for sysfs attribute mesh_id
962 * @dev: the &struct device
963 * @attr: device attributes
964 * @buf: buffer where data will be returned
916 */ 965 */
917static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr, 966static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
918 char *buf) 967 char *buf)
919{ 968{
920 struct mrvl_mesh_defaults defs; 969 struct mrvl_mesh_defaults defs;
921 int maxlen;
922 int ret; 970 int ret;
923 971
924 ret = mesh_get_default_parameters(dev, &defs); 972 ret = mesh_get_default_parameters(dev, &defs);
@@ -927,21 +975,23 @@ static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
927 return ret; 975 return ret;
928 976
929 if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) { 977 if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) {
930 lbs_pr_err("inconsistent mesh ID length"); 978 dev_err(dev, "inconsistent mesh ID length\n");
931 defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN; 979 defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
932 } 980 }
933 981
934 /* SSID not null terminated: reserve room for \0 + \n */ 982 memcpy(buf, defs.meshie.val.mesh_id, defs.meshie.val.mesh_id_len);
935 maxlen = defs.meshie.val.mesh_id_len + 2; 983 buf[defs.meshie.val.mesh_id_len] = '\n';
936 maxlen = (PAGE_SIZE > maxlen) ? maxlen : PAGE_SIZE; 984 buf[defs.meshie.val.mesh_id_len + 1] = '\0';
937
938 defs.meshie.val.mesh_id[defs.meshie.val.mesh_id_len] = '\0';
939 985
940 return snprintf(buf, maxlen, "%s\n", defs.meshie.val.mesh_id); 986 return defs.meshie.val.mesh_id_len + 1;
941} 987}
942 988
943/** 989/**
944 * @brief Set function for sysfs attribute mesh_id 990 * mesh_id_set - Set function for sysfs attribute mesh_id
991 * @dev: the &struct device
992 * @attr: device attributes
993 * @buf: buffer that contains new attribute value
994 * @count: size of buffer
945 */ 995 */
946static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr, 996static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
947 const char *buf, size_t count) 997 const char *buf, size_t count)
@@ -983,7 +1033,10 @@ static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
983} 1033}
984 1034
985/** 1035/**
986 * @brief Get function for sysfs attribute protocol_id 1036 * protocol_id_get - Get function for sysfs attribute protocol_id
1037 * @dev: the &struct device
1038 * @attr: device attributes
1039 * @buf: buffer where data will be returned
987 */ 1040 */
988static ssize_t protocol_id_get(struct device *dev, 1041static ssize_t protocol_id_get(struct device *dev,
989 struct device_attribute *attr, char *buf) 1042 struct device_attribute *attr, char *buf)
@@ -1000,7 +1053,11 @@ static ssize_t protocol_id_get(struct device *dev,
1000} 1053}
1001 1054
1002/** 1055/**
1003 * @brief Set function for sysfs attribute protocol_id 1056 * protocol_id_set - Set function for sysfs attribute protocol_id
1057 * @dev: the &struct device
1058 * @attr: device attributes
1059 * @buf: buffer that contains new attribute value
1060 * @count: size of buffer
1004 */ 1061 */
1005static ssize_t protocol_id_set(struct device *dev, 1062static ssize_t protocol_id_set(struct device *dev,
1006 struct device_attribute *attr, const char *buf, size_t count) 1063 struct device_attribute *attr, const char *buf, size_t count)
@@ -1037,7 +1094,10 @@ static ssize_t protocol_id_set(struct device *dev,
1037} 1094}
1038 1095
1039/** 1096/**
1040 * @brief Get function for sysfs attribute metric_id 1097 * metric_id_get - Get function for sysfs attribute metric_id
1098 * @dev: the &struct device
1099 * @attr: device attributes
1100 * @buf: buffer where data will be returned
1041 */ 1101 */
1042static ssize_t metric_id_get(struct device *dev, 1102static ssize_t metric_id_get(struct device *dev,
1043 struct device_attribute *attr, char *buf) 1103 struct device_attribute *attr, char *buf)
@@ -1054,7 +1114,11 @@ static ssize_t metric_id_get(struct device *dev,
1054} 1114}
1055 1115
1056/** 1116/**
1057 * @brief Set function for sysfs attribute metric_id 1117 * metric_id_set - Set function for sysfs attribute metric_id
1118 * @dev: the &struct device
1119 * @attr: device attributes
1120 * @buf: buffer that contains new attribute value
1121 * @count: size of buffer
1058 */ 1122 */
1059static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr, 1123static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr,
1060 const char *buf, size_t count) 1124 const char *buf, size_t count)
@@ -1091,7 +1155,10 @@ static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr,
1091} 1155}
1092 1156
1093/** 1157/**
1094 * @brief Get function for sysfs attribute capability 1158 * capability_get - Get function for sysfs attribute capability
1159 * @dev: the &struct device
1160 * @attr: device attributes
1161 * @buf: buffer where data will be returned
1095 */ 1162 */
1096static ssize_t capability_get(struct device *dev, 1163static ssize_t capability_get(struct device *dev,
1097 struct device_attribute *attr, char *buf) 1164 struct device_attribute *attr, char *buf)
@@ -1108,7 +1175,11 @@ static ssize_t capability_get(struct device *dev,
1108} 1175}
1109 1176
1110/** 1177/**
1111 * @brief Set function for sysfs attribute capability 1178 * capability_set - Set function for sysfs attribute capability
1179 * @dev: the &struct device
1180 * @attr: device attributes
1181 * @buf: buffer that contains new attribute value
1182 * @count: size of buffer
1112 */ 1183 */
1113static ssize_t capability_set(struct device *dev, struct device_attribute *attr, 1184static ssize_t capability_set(struct device *dev, struct device_attribute *attr,
1114 const char *buf, size_t count) 1185 const char *buf, size_t count)
diff --git a/drivers/net/wireless/libertas/mesh.h b/drivers/net/wireless/libertas/mesh.h
index afb2e8dead3f..ee95c73ed5f4 100644
--- a/drivers/net/wireless/libertas/mesh.h
+++ b/drivers/net/wireless/libertas/mesh.h
@@ -1,6 +1,6 @@
1/** 1/*
2 * Contains all definitions needed for the Libertas' MESH implementation. 2 * Contains all definitions needed for the Libertas' MESH implementation.
3 */ 3 */
4#ifndef _LBS_MESH_H_ 4#ifndef _LBS_MESH_H_
5#define _LBS_MESH_H_ 5#define _LBS_MESH_H_
6 6
diff --git a/drivers/net/wireless/libertas/rx.c b/drivers/net/wireless/libertas/rx.c
index a4d0bca9ef2c..fdb0448301a0 100644
--- a/drivers/net/wireless/libertas/rx.c
+++ b/drivers/net/wireless/libertas/rx.c
@@ -1,6 +1,9 @@
1/** 1/*
2 * This file contains the handling of RX in wlan driver. 2 * This file contains the handling of RX in wlan driver.
3 */ 3 */
4
5#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6
4#include <linux/etherdevice.h> 7#include <linux/etherdevice.h>
5#include <linux/slab.h> 8#include <linux/slab.h>
6#include <linux/types.h> 9#include <linux/types.h>
@@ -40,12 +43,12 @@ static int process_rxed_802_11_packet(struct lbs_private *priv,
40 struct sk_buff *skb); 43 struct sk_buff *skb);
41 44
42/** 45/**
43 * @brief This function processes received packet and forwards it 46 * lbs_process_rxed_packet - processes received packet and forwards it
44 * to kernel/upper layer 47 * to kernel/upper layer
45 * 48 *
46 * @param priv A pointer to struct lbs_private 49 * @priv: A pointer to &struct lbs_private
47 * @param skb A pointer to skb which includes the received packet 50 * @skb: A pointer to skb which includes the received packet
48 * @return 0 or -1 51 * returns: 0 or -1
49 */ 52 */
50int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb) 53int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb)
51{ 54{
@@ -55,7 +58,9 @@ int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb)
55 struct rxpd *p_rx_pd; 58 struct rxpd *p_rx_pd;
56 int hdrchop; 59 int hdrchop;
57 struct ethhdr *p_ethhdr; 60 struct ethhdr *p_ethhdr;
58 const u8 rfc1042_eth_hdr[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 61 static const u8 rfc1042_eth_hdr[] = {
62 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
63 };
59 64
60 lbs_deb_enter(LBS_DEB_RX); 65 lbs_deb_enter(LBS_DEB_RX);
61 66
@@ -154,11 +159,11 @@ done:
154EXPORT_SYMBOL_GPL(lbs_process_rxed_packet); 159EXPORT_SYMBOL_GPL(lbs_process_rxed_packet);
155 160
156/** 161/**
157 * @brief This function converts Tx/Rx rates from the Marvell WLAN format 162 * convert_mv_rate_to_radiotap - converts Tx/Rx rates from Marvell WLAN format
158 * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s) 163 * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s)
159 * 164 *
160 * @param rate Input rate 165 * @rate: Input rate
161 * @return Output Rate (0 if invalid) 166 * returns: Output Rate (0 if invalid)
162 */ 167 */
163static u8 convert_mv_rate_to_radiotap(u8 rate) 168static u8 convert_mv_rate_to_radiotap(u8 rate)
164{ 169{
@@ -189,17 +194,17 @@ static u8 convert_mv_rate_to_radiotap(u8 rate)
189 case 12: /* 54 Mbps */ 194 case 12: /* 54 Mbps */
190 return 108; 195 return 108;
191 } 196 }
192 lbs_pr_alert("Invalid Marvell WLAN rate %i\n", rate); 197 pr_alert("Invalid Marvell WLAN rate %i\n", rate);
193 return 0; 198 return 0;
194} 199}
195 200
196/** 201/**
197 * @brief This function processes a received 802.11 packet and forwards it 202 * process_rxed_802_11_packet - processes a received 802.11 packet and forwards
198 * to kernel/upper layer 203 * it to kernel/upper layer
199 * 204 *
200 * @param priv A pointer to struct lbs_private 205 * @priv: A pointer to &struct lbs_private
201 * @param skb A pointer to skb which includes the received packet 206 * @skb: A pointer to skb which includes the received packet
202 * @return 0 or -1 207 * returns: 0 or -1
203 */ 208 */
204static int process_rxed_802_11_packet(struct lbs_private *priv, 209static int process_rxed_802_11_packet(struct lbs_private *priv,
205 struct sk_buff *skb) 210 struct sk_buff *skb)
@@ -246,7 +251,7 @@ static int process_rxed_802_11_packet(struct lbs_private *priv,
246 /* add space for the new radio header */ 251 /* add space for the new radio header */
247 if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) && 252 if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) &&
248 pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) { 253 pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) {
249 lbs_pr_alert("%s: couldn't pskb_expand_head\n", __func__); 254 netdev_alert(dev, "%s: couldn't pskb_expand_head\n", __func__);
250 ret = -ENOMEM; 255 ret = -ENOMEM;
251 kfree_skb(skb); 256 kfree_skb(skb);
252 goto done; 257 goto done;
diff --git a/drivers/net/wireless/libertas/tx.c b/drivers/net/wireless/libertas/tx.c
index 8000ca6165d0..bbb95f88dc01 100644
--- a/drivers/net/wireless/libertas/tx.c
+++ b/drivers/net/wireless/libertas/tx.c
@@ -1,6 +1,6 @@
1/** 1/*
2 * This file contains the handling of TX in wlan driver. 2 * This file contains the handling of TX in wlan driver.
3 */ 3 */
4#include <linux/netdevice.h> 4#include <linux/netdevice.h>
5#include <linux/etherdevice.h> 5#include <linux/etherdevice.h>
6#include <linux/sched.h> 6#include <linux/sched.h>
@@ -13,11 +13,11 @@
13#include "dev.h" 13#include "dev.h"
14 14
15/** 15/**
16 * @brief This function converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE 16 * convert_radiotap_rate_to_mv - converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE
17 * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1) 17 * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1)
18 * 18 *
19 * @param rate Input rate 19 * @rate: Input rate
20 * @return Output Rate (0 if invalid) 20 * returns: Output Rate (0 if invalid)
21 */ 21 */
22static u32 convert_radiotap_rate_to_mv(u8 rate) 22static u32 convert_radiotap_rate_to_mv(u8 rate)
23{ 23{
@@ -51,12 +51,12 @@ static u32 convert_radiotap_rate_to_mv(u8 rate)
51} 51}
52 52
53/** 53/**
54 * @brief This function checks the conditions and sends packet to IF 54 * lbs_hard_start_xmit - checks the conditions and sends packet to IF
55 * layer if everything is ok. 55 * layer if everything is ok
56 * 56 *
57 * @param priv A pointer to struct lbs_private structure 57 * @skb: A pointer to skb which includes TX packet
58 * @param skb A pointer to skb which includes TX packet 58 * @dev: A pointer to the &struct net_device
59 * @return 0 or -1 59 * returns: 0 or -1
60 */ 60 */
61netdev_tx_t lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) 61netdev_tx_t lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
62{ 62{
@@ -168,13 +168,13 @@ netdev_tx_t lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
168} 168}
169 169
170/** 170/**
171 * @brief This function sends to the host the last transmitted packet, 171 * lbs_send_tx_feedback - sends to the host the last transmitted packet,
172 * filling the radiotap headers with transmission information. 172 * filling the radiotap headers with transmission information.
173 * 173 *
174 * @param priv A pointer to struct lbs_private structure 174 * @priv: A pointer to &struct lbs_private structure
175 * @param status A 32 bit value containing transmission status. 175 * @try_count: A 32-bit value containing transmission retry status.
176 * 176 *
177 * @returns void 177 * returns: void
178 */ 178 */
179void lbs_send_tx_feedback(struct lbs_private *priv, u32 try_count) 179void lbs_send_tx_feedback(struct lbs_private *priv, u32 try_count)
180{ 180{
diff --git a/drivers/net/wireless/libertas/types.h b/drivers/net/wireless/libertas/types.h
index 462fbb4cb743..cf1d9b047ee6 100644
--- a/drivers/net/wireless/libertas/types.h
+++ b/drivers/net/wireless/libertas/types.h
@@ -1,6 +1,6 @@
1/** 1/*
2 * This header file contains definition for global types 2 * This header file contains definition for global types
3 */ 3 */
4#ifndef _LBS_TYPES_H_ 4#ifndef _LBS_TYPES_H_
5#define _LBS_TYPES_H_ 5#define _LBS_TYPES_H_
6 6
@@ -54,7 +54,7 @@ union ieee_phy_param_set {
54 struct ieee_ie_ds_param_set ds; 54 struct ieee_ie_ds_param_set ds;
55} __packed; 55} __packed;
56 56
57/** TLV type ID definition */ 57/* TLV type ID definition */
58#define PROPRIETARY_TLV_BASE_ID 0x0100 58#define PROPRIETARY_TLV_BASE_ID 0x0100
59 59
60/* Terminating TLV type */ 60/* Terminating TLV type */
@@ -96,7 +96,7 @@ union ieee_phy_param_set {
96#define TLV_TYPE_MESH_ID (PROPRIETARY_TLV_BASE_ID + 37) 96#define TLV_TYPE_MESH_ID (PROPRIETARY_TLV_BASE_ID + 37)
97#define TLV_TYPE_OLD_MESH_ID (PROPRIETARY_TLV_BASE_ID + 291) 97#define TLV_TYPE_OLD_MESH_ID (PROPRIETARY_TLV_BASE_ID + 291)
98 98
99/** TLV related data structures*/ 99/* TLV related data structures */
100struct mrvl_ie_header { 100struct mrvl_ie_header {
101 __le16 type; 101 __le16 type;
102 __le16 len; 102 __le16 len;
@@ -177,7 +177,7 @@ struct mrvl_ie_auth_type {
177 __le16 auth; 177 __le16 auth;
178} __packed; 178} __packed;
179 179
180/** Local Power capability */ 180/* Local Power capability */
181struct mrvl_ie_power_capability { 181struct mrvl_ie_power_capability {
182 struct mrvl_ie_header header; 182 struct mrvl_ie_header header;
183 s8 minpower; 183 s8 minpower;
@@ -235,9 +235,11 @@ struct mrvl_ie_ledbhv {
235 struct led_bhv ledbhv[1]; 235 struct led_bhv ledbhv[1];
236} __packed; 236} __packed;
237 237
238/* Meant to be packed as the value member of a struct ieee80211_info_element. 238/*
239 * Meant to be packed as the value member of a struct ieee80211_info_element.
239 * Note that the len member of the ieee80211_info_element varies depending on 240 * Note that the len member of the ieee80211_info_element varies depending on
240 * the mesh_id_len */ 241 * the mesh_id_len
242 */
241struct mrvl_meshie_val { 243struct mrvl_meshie_val {
242 uint8_t oui[3]; 244 uint8_t oui[3];
243 uint8_t type; 245 uint8_t type;