aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/zd1211rw/zd_chip.c
diff options
context:
space:
mode:
authorDaniel Drake <dsd@gentoo.org>2007-07-01 13:22:32 -0400
committerJohn W. Linville <linville@tuxdriver.com>2007-07-10 14:14:56 -0400
commit74553aedd46b3a2cae986f909cf2a3f99369decc (patch)
tree6904945b36c017c58249b1900fbbd531f3286e49 /drivers/net/wireless/zd1211rw/zd_chip.c
parent93f510bbac64f552ef6872a39ae12afa06c4e999 (diff)
[PATCH] zd1211rw: Defer firmware load until first ifup
While playing with the firmware a while back, I discovered a way to access the device's entire address space before the firmware has been loaded. Previously we were loading the firmware early on (during probe) so that we could read the MAC address from the EEPROM and register a netdevice. Now that we can read the EEPROM without having firmware, we can defer firmware loading until later while still reading the MAC address early on. This has the advantage that zd1211rw can now be built into the kernel -- previously if this was the case, zd1211rw would be loaded before the filesystem is available and firmware loading would fail. Firmware load and other device initialization operations now happen the first time the interface is brought up. Some architectural changes were needed: handling of the is_zd1211b flag was moved into the zd_usb structure, MAC address handling was obviously changed, and a preinit_hw stage was added (the order is now: init, preinit_hw, init_hw). Signed-off-by: Daniel Drake <dsd@gentoo.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/zd1211rw/zd_chip.c')
-rw-r--r--drivers/net/wireless/zd1211rw/zd_chip.c88
1 files changed, 15 insertions, 73 deletions
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.c b/drivers/net/wireless/zd1211rw/zd_chip.c
index 5b624bfc01a6..c39f1984b84d 100644
--- a/drivers/net/wireless/zd1211rw/zd_chip.c
+++ b/drivers/net/wireless/zd1211rw/zd_chip.c
@@ -49,8 +49,9 @@ void zd_chip_clear(struct zd_chip *chip)
49 ZD_MEMCLEAR(chip, sizeof(*chip)); 49 ZD_MEMCLEAR(chip, sizeof(*chip));
50} 50}
51 51
52static int scnprint_mac_oui(const u8 *addr, char *buffer, size_t size) 52static int scnprint_mac_oui(struct zd_chip *chip, char *buffer, size_t size)
53{ 53{
54 u8 *addr = zd_usb_to_netdev(&chip->usb)->dev_addr;
54 return scnprintf(buffer, size, "%02x-%02x-%02x", 55 return scnprintf(buffer, size, "%02x-%02x-%02x",
55 addr[0], addr[1], addr[2]); 56 addr[0], addr[1], addr[2]);
56} 57}
@@ -61,10 +62,10 @@ static int scnprint_id(struct zd_chip *chip, char *buffer, size_t size)
61 int i = 0; 62 int i = 0;
62 63
63 i = scnprintf(buffer, size, "zd1211%s chip ", 64 i = scnprintf(buffer, size, "zd1211%s chip ",
64 chip->is_zd1211b ? "b" : ""); 65 zd_chip_is_zd1211b(chip) ? "b" : "");
65 i += zd_usb_scnprint_id(&chip->usb, buffer+i, size-i); 66 i += zd_usb_scnprint_id(&chip->usb, buffer+i, size-i);
66 i += scnprintf(buffer+i, size-i, " "); 67 i += scnprintf(buffer+i, size-i, " ");
67 i += scnprint_mac_oui(chip->e2p_mac, buffer+i, size-i); 68 i += scnprint_mac_oui(chip, buffer+i, size-i);
68 i += scnprintf(buffer+i, size-i, " "); 69 i += scnprintf(buffer+i, size-i, " ");
69 i += zd_rf_scnprint_id(&chip->rf, buffer+i, size-i); 70 i += zd_rf_scnprint_id(&chip->rf, buffer+i, size-i);
70 i += scnprintf(buffer+i, size-i, " pa%1x %c%c%c%c%c", chip->pa_type, 71 i += scnprintf(buffer+i, size-i, " pa%1x %c%c%c%c%c", chip->pa_type,
@@ -366,64 +367,9 @@ error:
366 return r; 367 return r;
367} 368}
368 369
369static int _read_mac_addr(struct zd_chip *chip, u8 *mac_addr,
370 const zd_addr_t *addr)
371{
372 int r;
373 u32 parts[2];
374
375 r = zd_ioread32v_locked(chip, parts, (const zd_addr_t *)addr, 2);
376 if (r) {
377 dev_dbg_f(zd_chip_dev(chip),
378 "error: couldn't read e2p macs. Error number %d\n", r);
379 return r;
380 }
381
382 mac_addr[0] = parts[0];
383 mac_addr[1] = parts[0] >> 8;
384 mac_addr[2] = parts[0] >> 16;
385 mac_addr[3] = parts[0] >> 24;
386 mac_addr[4] = parts[1];
387 mac_addr[5] = parts[1] >> 8;
388
389 return 0;
390}
391
392static int read_e2p_mac_addr(struct zd_chip *chip)
393{
394 static const zd_addr_t addr[2] = { E2P_MAC_ADDR_P1, E2P_MAC_ADDR_P2 };
395
396 ZD_ASSERT(mutex_is_locked(&chip->mutex));
397 return _read_mac_addr(chip, chip->e2p_mac, (const zd_addr_t *)addr);
398}
399
400/* MAC address: if custom mac addresses are to to be used CR_MAC_ADDR_P1 and 370/* MAC address: if custom mac addresses are to to be used CR_MAC_ADDR_P1 and
401 * CR_MAC_ADDR_P2 must be overwritten 371 * CR_MAC_ADDR_P2 must be overwritten
402 */ 372 */
403void zd_get_e2p_mac_addr(struct zd_chip *chip, u8 *mac_addr)
404{
405 mutex_lock(&chip->mutex);
406 memcpy(mac_addr, chip->e2p_mac, ETH_ALEN);
407 mutex_unlock(&chip->mutex);
408}
409
410static int read_mac_addr(struct zd_chip *chip, u8 *mac_addr)
411{
412 static const zd_addr_t addr[2] = { CR_MAC_ADDR_P1, CR_MAC_ADDR_P2 };
413 return _read_mac_addr(chip, mac_addr, (const zd_addr_t *)addr);
414}
415
416int zd_read_mac_addr(struct zd_chip *chip, u8 *mac_addr)
417{
418 int r;
419
420 dev_dbg_f(zd_chip_dev(chip), "\n");
421 mutex_lock(&chip->mutex);
422 r = read_mac_addr(chip, mac_addr);
423 mutex_unlock(&chip->mutex);
424 return r;
425}
426
427int zd_write_mac_addr(struct zd_chip *chip, const u8 *mac_addr) 373int zd_write_mac_addr(struct zd_chip *chip, const u8 *mac_addr)
428{ 374{
429 int r; 375 int r;
@@ -444,12 +390,6 @@ int zd_write_mac_addr(struct zd_chip *chip, const u8 *mac_addr)
444 390
445 mutex_lock(&chip->mutex); 391 mutex_lock(&chip->mutex);
446 r = zd_iowrite32a_locked(chip, reqs, ARRAY_SIZE(reqs)); 392 r = zd_iowrite32a_locked(chip, reqs, ARRAY_SIZE(reqs));
447#ifdef DEBUG
448 {
449 u8 tmp[ETH_ALEN];
450 read_mac_addr(chip, tmp);
451 }
452#endif /* DEBUG */
453 mutex_unlock(&chip->mutex); 393 mutex_unlock(&chip->mutex);
454 return r; 394 return r;
455} 395}
@@ -809,7 +749,7 @@ out:
809 749
810static int hw_reset_phy(struct zd_chip *chip) 750static int hw_reset_phy(struct zd_chip *chip)
811{ 751{
812 return chip->is_zd1211b ? zd1211b_hw_reset_phy(chip) : 752 return zd_chip_is_zd1211b(chip) ? zd1211b_hw_reset_phy(chip) :
813 zd1211_hw_reset_phy(chip); 753 zd1211_hw_reset_phy(chip);
814} 754}
815 755
@@ -874,7 +814,7 @@ static int hw_init_hmac(struct zd_chip *chip)
874 if (r) 814 if (r)
875 return r; 815 return r;
876 816
877 return chip->is_zd1211b ? 817 return zd_chip_is_zd1211b(chip) ?
878 zd1211b_hw_init_hmac(chip) : zd1211_hw_init_hmac(chip); 818 zd1211b_hw_init_hmac(chip) : zd1211_hw_init_hmac(chip);
879} 819}
880 820
@@ -1136,8 +1076,15 @@ static int read_fw_regs_offset(struct zd_chip *chip)
1136 return 0; 1076 return 0;
1137} 1077}
1138 1078
1079/* Read mac address using pre-firmware interface */
1080int zd_chip_read_mac_addr_fw(struct zd_chip *chip, u8 *addr)
1081{
1082 dev_dbg_f(zd_chip_dev(chip), "\n");
1083 return zd_usb_read_fw(&chip->usb, E2P_MAC_ADDR_P1, addr,
1084 ETH_ALEN);
1085}
1139 1086
1140int zd_chip_init_hw(struct zd_chip *chip, u8 device_type) 1087int zd_chip_init_hw(struct zd_chip *chip)
1141{ 1088{
1142 int r; 1089 int r;
1143 u8 rf_type; 1090 u8 rf_type;
@@ -1145,7 +1092,6 @@ int zd_chip_init_hw(struct zd_chip *chip, u8 device_type)
1145 dev_dbg_f(zd_chip_dev(chip), "\n"); 1092 dev_dbg_f(zd_chip_dev(chip), "\n");
1146 1093
1147 mutex_lock(&chip->mutex); 1094 mutex_lock(&chip->mutex);
1148 chip->is_zd1211b = (device_type == DEVICE_ZD1211B) != 0;
1149 1095
1150#ifdef DEBUG 1096#ifdef DEBUG
1151 r = test_init(chip); 1097 r = test_init(chip);
@@ -1201,10 +1147,6 @@ int zd_chip_init_hw(struct zd_chip *chip, u8 device_type)
1201 goto out; 1147 goto out;
1202#endif /* DEBUG */ 1148#endif /* DEBUG */
1203 1149
1204 r = read_e2p_mac_addr(chip);
1205 if (r)
1206 goto out;
1207
1208 r = read_cal_int_tables(chip); 1150 r = read_cal_int_tables(chip);
1209 if (r) 1151 if (r)
1210 goto out; 1152 goto out;
@@ -1259,7 +1201,7 @@ static int update_channel_integration_and_calibration(struct zd_chip *chip,
1259 r = update_pwr_int(chip, channel); 1201 r = update_pwr_int(chip, channel);
1260 if (r) 1202 if (r)
1261 return r; 1203 return r;
1262 if (chip->is_zd1211b) { 1204 if (zd_chip_is_zd1211b(chip)) {
1263 static const struct zd_ioreq16 ioreqs[] = { 1205 static const struct zd_ioreq16 ioreqs[] = {
1264 { CR69, 0x28 }, 1206 { CR69, 0x28 },
1265 {}, 1207 {},