aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLarry Finger <Larry.Finger@lwfinger.net>2007-11-09 17:56:25 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:04:41 -0500
commitc272ef4403c271799a7f09a4ab7a236c86643843 (patch)
tree8f2baf9c11159044b42233cea56aa5a62dcd7500 /drivers
parentac82fab44f6b981e3f6b53784e2f23838f4908e1 (diff)
ssb: Convert to use of the new SPROM structure
In disagreement with the SPROM specs, revision 3 devices appear to have moved the MAC address. Change ssb to handle the revision 4 SPROM, which is a different size. This change in size is handled by adding a new variable to the ssb_sprom struct and using it whenever possible. For those routines that do not have access to this structure, a 'u16 size' argument is added. The new PCI_ID for the BCM4328 is also added. Testing of the Revision 4 SPROM, which is used on the BCM4328, was done by Michael Gerdau <mgerdau@tiscali.de>. Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ssb/b43_pci_bridge.c1
-rw-r--r--drivers/ssb/main.c10
-rw-r--r--drivers/ssb/pci.c224
3 files changed, 142 insertions, 93 deletions
diff --git a/drivers/ssb/b43_pci_bridge.c b/drivers/ssb/b43_pci_bridge.c
index f145d8a4cfde..b8b7cb0b436a 100644
--- a/drivers/ssb/b43_pci_bridge.c
+++ b/drivers/ssb/b43_pci_bridge.c
@@ -27,6 +27,7 @@ static const struct pci_device_id b43_pci_bridge_tbl[] = {
27 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4321) }, 27 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4321) },
28 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4324) }, 28 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4324) },
29 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4325) }, 29 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4325) },
30 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4328) },
30 { 0, }, 31 { 0, },
31}; 32};
32MODULE_DEVICE_TABLE(pci, b43_pci_bridge_tbl); 33MODULE_DEVICE_TABLE(pci, b43_pci_bridge_tbl);
diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index 85a20546e827..9028ed5715a1 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -872,14 +872,22 @@ EXPORT_SYMBOL(ssb_clockspeed);
872 872
873static u32 ssb_tmslow_reject_bitmask(struct ssb_device *dev) 873static u32 ssb_tmslow_reject_bitmask(struct ssb_device *dev)
874{ 874{
875 u32 rev = ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_SSBREV;
876
875 /* The REJECT bit changed position in TMSLOW between 877 /* The REJECT bit changed position in TMSLOW between
876 * Backplane revisions. */ 878 * Backplane revisions. */
877 switch (ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_SSBREV) { 879 switch (rev) {
878 case SSB_IDLOW_SSBREV_22: 880 case SSB_IDLOW_SSBREV_22:
879 return SSB_TMSLOW_REJECT_22; 881 return SSB_TMSLOW_REJECT_22;
880 case SSB_IDLOW_SSBREV_23: 882 case SSB_IDLOW_SSBREV_23:
881 return SSB_TMSLOW_REJECT_23; 883 return SSB_TMSLOW_REJECT_23;
884 case SSB_IDLOW_SSBREV_24: /* TODO - find the proper REJECT bits */
885 case SSB_IDLOW_SSBREV_25: /* same here */
886 case SSB_IDLOW_SSBREV_26: /* same here */
887 case SSB_IDLOW_SSBREV_27: /* same here */
888 return SSB_TMSLOW_REJECT_23; /* this is a guess */
882 default: 889 default:
890 printk(KERN_INFO "ssb: Backplane Revision 0x%.8X\n", rev);
883 WARN_ON(1); 891 WARN_ON(1);
884 } 892 }
885 return (SSB_TMSLOW_REJECT_22 | SSB_TMSLOW_REJECT_23); 893 return (SSB_TMSLOW_REJECT_22 | SSB_TMSLOW_REJECT_23);
diff --git a/drivers/ssb/pci.c b/drivers/ssb/pci.c
index 7226a716acdf..8f600fcd2430 100644
--- a/drivers/ssb/pci.c
+++ b/drivers/ssb/pci.c
@@ -212,29 +212,29 @@ static inline u8 ssb_crc8(u8 crc, u8 data)
212 return t[crc ^ data]; 212 return t[crc ^ data];
213} 213}
214 214
215static u8 ssb_sprom_crc(const u16 *sprom) 215static u8 ssb_sprom_crc(const u16 *sprom, u16 size)
216{ 216{
217 int word; 217 int word;
218 u8 crc = 0xFF; 218 u8 crc = 0xFF;
219 219
220 for (word = 0; word < SSB_SPROMSIZE_WORDS - 1; word++) { 220 for (word = 0; word < size - 1; word++) {
221 crc = ssb_crc8(crc, sprom[word] & 0x00FF); 221 crc = ssb_crc8(crc, sprom[word] & 0x00FF);
222 crc = ssb_crc8(crc, (sprom[word] & 0xFF00) >> 8); 222 crc = ssb_crc8(crc, (sprom[word] & 0xFF00) >> 8);
223 } 223 }
224 crc = ssb_crc8(crc, sprom[SPOFF(SSB_SPROM_REVISION)] & 0x00FF); 224 crc = ssb_crc8(crc, sprom[size - 1] & 0x00FF);
225 crc ^= 0xFF; 225 crc ^= 0xFF;
226 226
227 return crc; 227 return crc;
228} 228}
229 229
230static int sprom_check_crc(const u16 *sprom) 230static int sprom_check_crc(const u16 *sprom, u16 size)
231{ 231{
232 u8 crc; 232 u8 crc;
233 u8 expected_crc; 233 u8 expected_crc;
234 u16 tmp; 234 u16 tmp;
235 235
236 crc = ssb_sprom_crc(sprom); 236 crc = ssb_sprom_crc(sprom, size);
237 tmp = sprom[SPOFF(SSB_SPROM_REVISION)] & SSB_SPROM_REVISION_CRC; 237 tmp = sprom[size - 1] & SSB_SPROM_REVISION_CRC;
238 expected_crc = tmp >> SSB_SPROM_REVISION_CRC_SHIFT; 238 expected_crc = tmp >> SSB_SPROM_REVISION_CRC_SHIFT;
239 if (crc != expected_crc) 239 if (crc != expected_crc)
240 return -EPROTO; 240 return -EPROTO;
@@ -246,7 +246,7 @@ static void sprom_do_read(struct ssb_bus *bus, u16 *sprom)
246{ 246{
247 int i; 247 int i;
248 248
249 for (i = 0; i < SSB_SPROMSIZE_WORDS; i++) 249 for (i = 0; i < bus->sprom_size; i++)
250 sprom[i] = readw(bus->mmio + SSB_SPROM_BASE + (i * 2)); 250 sprom[i] = readw(bus->mmio + SSB_SPROM_BASE + (i * 2));
251} 251}
252 252
@@ -255,6 +255,7 @@ static int sprom_do_write(struct ssb_bus *bus, const u16 *sprom)
255 struct pci_dev *pdev = bus->host_pci; 255 struct pci_dev *pdev = bus->host_pci;
256 int i, err; 256 int i, err;
257 u32 spromctl; 257 u32 spromctl;
258 u16 size = bus->sprom_size;
258 259
259 ssb_printk(KERN_NOTICE PFX "Writing SPROM. Do NOT turn off the power! Please stand by...\n"); 260 ssb_printk(KERN_NOTICE PFX "Writing SPROM. Do NOT turn off the power! Please stand by...\n");
260 err = pci_read_config_dword(pdev, SSB_SPROMCTL, &spromctl); 261 err = pci_read_config_dword(pdev, SSB_SPROMCTL, &spromctl);
@@ -266,12 +267,12 @@ static int sprom_do_write(struct ssb_bus *bus, const u16 *sprom)
266 goto err_ctlreg; 267 goto err_ctlreg;
267 ssb_printk(KERN_NOTICE PFX "[ 0%%"); 268 ssb_printk(KERN_NOTICE PFX "[ 0%%");
268 msleep(500); 269 msleep(500);
269 for (i = 0; i < SSB_SPROMSIZE_WORDS; i++) { 270 for (i = 0; i < size; i++) {
270 if (i == SSB_SPROMSIZE_WORDS / 4) 271 if (i == size / 4)
271 ssb_printk("25%%"); 272 ssb_printk("25%%");
272 else if (i == SSB_SPROMSIZE_WORDS / 2) 273 else if (i == size / 2)
273 ssb_printk("50%%"); 274 ssb_printk("50%%");
274 else if (i == (SSB_SPROMSIZE_WORDS / 4) * 3) 275 else if (i == (size * 3) / 4)
275 ssb_printk("75%%"); 276 ssb_printk("75%%");
276 else if (i % 2) 277 else if (i % 2)
277 ssb_printk("."); 278 ssb_printk(".");
@@ -350,95 +351,120 @@ static void sprom_extract_r1(struct ssb_sprom_r1 *out, const u16 *in)
350 SPEX(antenna_gain_a, SSB_SPROM1_AGAIN, SSB_SPROM1_AGAIN_A, 0); 351 SPEX(antenna_gain_a, SSB_SPROM1_AGAIN, SSB_SPROM1_AGAIN_A, 0);
351 SPEX(antenna_gain_bg, SSB_SPROM1_AGAIN, SSB_SPROM1_AGAIN_BG, 352 SPEX(antenna_gain_bg, SSB_SPROM1_AGAIN, SSB_SPROM1_AGAIN_BG,
352 SSB_SPROM1_AGAIN_BG_SHIFT); 353 SSB_SPROM1_AGAIN_BG_SHIFT);
353 for (i = 0; i < 4; i++) {
354 v = in[SPOFF(SSB_SPROM1_OEM) + i];
355 *(((__le16 *)out->oem) + i) = cpu_to_le16(v);
356 }
357} 354}
358 355
359static void sprom_extract_r2(struct ssb_sprom_r2 *out, const u16 *in) 356static void sprom_extract_r123(struct ssb_sprom *out, const u16 *in)
360{ 357{
361 int i; 358 int i;
362 u16 v; 359 u16 v;
360 u16 loc[3];
363 361
364 SPEX(boardflags_hi, SSB_SPROM2_BFLHI, 0xFFFF, 0); 362 if (out->revision == 3) { /* rev 3 moved MAC */
365 SPEX(maxpwr_a_hi, SSB_SPROM2_MAXP_A, SSB_SPROM2_MAXP_A_HI, 0); 363 loc[0] = SSB_SPROM3_IL0MAC;
366 SPEX(maxpwr_a_lo, SSB_SPROM2_MAXP_A, SSB_SPROM2_MAXP_A_LO, 364 loc[1] = SSB_SPROM3_ET0MAC;
367 SSB_SPROM2_MAXP_A_LO_SHIFT); 365 loc[2] = SSB_SPROM3_ET1MAC;
368 SPEX(pa1lob0, SSB_SPROM2_PA1LOB0, 0xFFFF, 0); 366 } else {
369 SPEX(pa1lob1, SSB_SPROM2_PA1LOB1, 0xFFFF, 0); 367 loc[0] = SSB_SPROM1_IL0MAC;
370 SPEX(pa1lob2, SSB_SPROM2_PA1LOB2, 0xFFFF, 0); 368 loc[1] = SSB_SPROM1_ET0MAC;
371 SPEX(pa1hib0, SSB_SPROM2_PA1HIB0, 0xFFFF, 0); 369 loc[2] = SSB_SPROM1_ET1MAC;
372 SPEX(pa1hib1, SSB_SPROM2_PA1HIB1, 0xFFFF, 0); 370 }
373 SPEX(pa1hib2, SSB_SPROM2_PA1HIB2, 0xFFFF, 0); 371 for (i = 0; i < 3; i++) {
374 SPEX(ofdm_pwr_off, SSB_SPROM2_OPO, SSB_SPROM2_OPO_VALUE, 0); 372 v = in[SPOFF(loc[0]) + i];
375 for (i = 0; i < 4; i++) { 373 *(((__be16 *)out->il0mac) + i) = cpu_to_be16(v);
376 v = in[SPOFF(SSB_SPROM2_CCODE) + i]; 374 }
377 *(((__le16 *)out->country_str) + i) = cpu_to_le16(v); 375 for (i = 0; i < 3; i++) {
376 v = in[SPOFF(loc[1]) + i];
377 *(((__be16 *)out->et0mac) + i) = cpu_to_be16(v);
378 }
379 for (i = 0; i < 3; i++) {
380 v = in[SPOFF(loc[2]) + i];
381 *(((__be16 *)out->et1mac) + i) = cpu_to_be16(v);
378 } 382 }
383 SPEX(et0phyaddr, SSB_SPROM1_ETHPHY, SSB_SPROM1_ETHPHY_ET0A, 0);
384 SPEX(et1phyaddr, SSB_SPROM1_ETHPHY, SSB_SPROM1_ETHPHY_ET1A,
385 SSB_SPROM1_ETHPHY_ET1A_SHIFT);
386 SPEX(country_code, SSB_SPROM1_BINF, SSB_SPROM1_BINF_CCODE,
387 SSB_SPROM1_BINF_CCODE_SHIFT);
388 SPEX(pa0b0, SSB_SPROM1_PA0B0, 0xFFFF, 0);
389 SPEX(pa0b1, SSB_SPROM1_PA0B1, 0xFFFF, 0);
390 SPEX(pa0b2, SSB_SPROM1_PA0B2, 0xFFFF, 0);
391 SPEX(pa1b0, SSB_SPROM1_PA1B0, 0xFFFF, 0);
392 SPEX(pa1b1, SSB_SPROM1_PA1B1, 0xFFFF, 0);
393 SPEX(pa1b2, SSB_SPROM1_PA1B2, 0xFFFF, 0);
394 SPEX(gpio0, SSB_SPROM1_GPIOA, SSB_SPROM1_GPIOA_P0, 0);
395 SPEX(gpio1, SSB_SPROM1_GPIOA, SSB_SPROM1_GPIOA_P1,
396 SSB_SPROM1_GPIOA_P1_SHIFT);
397 SPEX(gpio2, SSB_SPROM1_GPIOB, SSB_SPROM1_GPIOB_P2, 0);
398 SPEX(gpio3, SSB_SPROM1_GPIOB, SSB_SPROM1_GPIOB_P3,
399 SSB_SPROM1_GPIOB_P3_SHIFT);
400 SPEX(maxpwr_a, SSB_SPROM1_MAXPWR, SSB_SPROM1_MAXPWR_A,
401 SSB_SPROM1_MAXPWR_A_SHIFT);
402 SPEX(maxpwr_bg, SSB_SPROM1_MAXPWR, SSB_SPROM1_MAXPWR_BG, 0);
403 SPEX(itssi_a, SSB_SPROM1_ITSSI, SSB_SPROM1_ITSSI_A,
404 SSB_SPROM1_ITSSI_A_SHIFT);
405 SPEX(itssi_bg, SSB_SPROM1_ITSSI, SSB_SPROM1_ITSSI_BG, 0);
406 SPEX(boardflags_lo, SSB_SPROM1_BFLLO, 0xFFFF, 0);
407 SPEX(antenna_gain_a, SSB_SPROM1_AGAIN, SSB_SPROM1_AGAIN_A, 0);
408 SPEX(antenna_gain_bg, SSB_SPROM1_AGAIN, SSB_SPROM1_AGAIN_BG,
409 SSB_SPROM1_AGAIN_BG_SHIFT);
379} 410}
380 411
381static void sprom_extract_r3(struct ssb_sprom_r3 *out, const u16 *in) 412static void sprom_extract_r4(struct ssb_sprom *out, const u16 *in)
382{ 413{
383 out->ofdmapo = (in[SPOFF(SSB_SPROM3_OFDMAPO) + 0] & 0xFF00) >> 8; 414 int i;
384 out->ofdmapo |= (in[SPOFF(SSB_SPROM3_OFDMAPO) + 0] & 0x00FF) << 8; 415 u16 v;
385 out->ofdmapo <<= 16; 416
386 out->ofdmapo |= (in[SPOFF(SSB_SPROM3_OFDMAPO) + 1] & 0xFF00) >> 8; 417 /* extract the r1 variables */
387 out->ofdmapo |= (in[SPOFF(SSB_SPROM3_OFDMAPO) + 1] & 0x00FF) << 8; 418 for (i = 0; i < 3; i++) {
388 419 v = in[SPOFF(SSB_SPROM4_IL0MAC) + i];
389 out->ofdmalpo = (in[SPOFF(SSB_SPROM3_OFDMALPO) + 0] & 0xFF00) >> 8; 420 *(((__be16 *)out->il0mac) + i) = cpu_to_be16(v);
390 out->ofdmalpo |= (in[SPOFF(SSB_SPROM3_OFDMALPO) + 0] & 0x00FF) << 8; 421 }
391 out->ofdmalpo <<= 16; 422 for (i = 0; i < 3; i++) {
392 out->ofdmalpo |= (in[SPOFF(SSB_SPROM3_OFDMALPO) + 1] & 0xFF00) >> 8; 423 v = in[SPOFF(SSB_SPROM4_ET0MAC) + i];
393 out->ofdmalpo |= (in[SPOFF(SSB_SPROM3_OFDMALPO) + 1] & 0x00FF) << 8; 424 *(((__be16 *)out->et0mac) + i) = cpu_to_be16(v);
394 425 }
395 out->ofdmahpo = (in[SPOFF(SSB_SPROM3_OFDMAHPO) + 0] & 0xFF00) >> 8; 426 for (i = 0; i < 3; i++) {
396 out->ofdmahpo |= (in[SPOFF(SSB_SPROM3_OFDMAHPO) + 0] & 0x00FF) << 8; 427 v = in[SPOFF(SSB_SPROM4_ET1MAC) + i];
397 out->ofdmahpo <<= 16; 428 *(((__be16 *)out->et1mac) + i) = cpu_to_be16(v);
398 out->ofdmahpo |= (in[SPOFF(SSB_SPROM3_OFDMAHPO) + 1] & 0xFF00) >> 8; 429 }
399 out->ofdmahpo |= (in[SPOFF(SSB_SPROM3_OFDMAHPO) + 1] & 0x00FF) << 8; 430 SPEX(et0phyaddr, SSB_SPROM4_ETHPHY, SSB_SPROM4_ETHPHY_ET0A, 0);
400 431 SPEX(et1phyaddr, SSB_SPROM4_ETHPHY, SSB_SPROM4_ETHPHY_ET1A,
401 SPEX(gpioldc_on_cnt, SSB_SPROM3_GPIOLDC, SSB_SPROM3_GPIOLDC_ON, 432 SSB_SPROM4_ETHPHY_ET1A_SHIFT);
402 SSB_SPROM3_GPIOLDC_ON_SHIFT); 433 SPEX(country_code, SSB_SPROM4_CCODE, 0xFFFF, 0);
403 SPEX(gpioldc_off_cnt, SSB_SPROM3_GPIOLDC, SSB_SPROM3_GPIOLDC_OFF, 434 SPEX(boardflags_lo, SSB_SPROM4_BFLLO, 0xFFFF, 0);
404 SSB_SPROM3_GPIOLDC_OFF_SHIFT); 435 SPEX(antenna_gain_a, SSB_SPROM4_AGAIN, SSB_SPROM4_AGAIN_0, 0);
405 SPEX(cckpo_1M, SSB_SPROM3_CCKPO, SSB_SPROM3_CCKPO_1M, 0); 436 SPEX(antenna_gain_bg, SSB_SPROM4_AGAIN, SSB_SPROM4_AGAIN_1,
406 SPEX(cckpo_2M, SSB_SPROM3_CCKPO, SSB_SPROM3_CCKPO_2M, 437 SSB_SPROM4_AGAIN_1_SHIFT);
407 SSB_SPROM3_CCKPO_2M_SHIFT); 438 /* TODO - get remaining rev 4 stuff needed */
408 SPEX(cckpo_55M, SSB_SPROM3_CCKPO, SSB_SPROM3_CCKPO_55M,
409 SSB_SPROM3_CCKPO_55M_SHIFT);
410 SPEX(cckpo_11M, SSB_SPROM3_CCKPO, SSB_SPROM3_CCKPO_11M,
411 SSB_SPROM3_CCKPO_11M_SHIFT);
412
413 out->ofdmgpo = (in[SPOFF(SSB_SPROM3_OFDMGPO) + 0] & 0xFF00) >> 8;
414 out->ofdmgpo |= (in[SPOFF(SSB_SPROM3_OFDMGPO) + 0] & 0x00FF) << 8;
415 out->ofdmgpo <<= 16;
416 out->ofdmgpo |= (in[SPOFF(SSB_SPROM3_OFDMGPO) + 1] & 0xFF00) >> 8;
417 out->ofdmgpo |= (in[SPOFF(SSB_SPROM3_OFDMGPO) + 1] & 0x00FF) << 8;
418} 439}
419 440
420static int sprom_extract(struct ssb_bus *bus, 441static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out,
421 struct ssb_sprom *out, const u16 *in) 442 const u16 *in, u16 size)
422{ 443{
423 memset(out, 0, sizeof(*out)); 444 memset(out, 0, sizeof(*out));
424 445
425 SPEX(revision, SSB_SPROM_REVISION, SSB_SPROM_REVISION_REV, 0); 446 out->revision = in[size - 1] & 0x00FF;
426
427 if ((bus->chip_id & 0xFF00) == 0x4400) { 447 if ((bus->chip_id & 0xFF00) == 0x4400) {
428 /* Workaround: The BCM44XX chip has a stupid revision 448 /* Workaround: The BCM44XX chip has a stupid revision
429 * number stored in the SPROM. 449 * number stored in the SPROM.
430 * Always extract r1. */ 450 * Always extract r1. */
451 out->revision = 1;
452 sprom_extract_r123(out, in);
431 sprom_extract_r1(&out->r1, in); 453 sprom_extract_r1(&out->r1, in);
454 } else if (bus->chip_id == 0x4321) {
455 /* the BCM4328 has a chipid == 0x4321 and a rev 4 SPROM */
456 out->revision = 4;
457 sprom_extract_r4(out, in);
432 } else { 458 } else {
433 if (out->revision == 0) 459 if (out->revision == 0)
434 goto unsupported; 460 goto unsupported;
435 if (out->revision >= 1 && out->revision <= 3) 461 if (out->revision >= 1 && out->revision <= 3) {
462 sprom_extract_r123(out, in);
436 sprom_extract_r1(&out->r1, in); 463 sprom_extract_r1(&out->r1, in);
437 if (out->revision >= 2 && out->revision <= 3) 464 }
438 sprom_extract_r2(&out->r2, in); 465 if (out->revision == 4)
439 if (out->revision == 3) 466 sprom_extract_r4(out, in);
440 sprom_extract_r3(&out->r3, in); 467 if (out->revision >= 5)
441 if (out->revision >= 4)
442 goto unsupported; 468 goto unsupported;
443 } 469 }
444 470
@@ -456,16 +482,31 @@ static int ssb_pci_sprom_get(struct ssb_bus *bus,
456 int err = -ENOMEM; 482 int err = -ENOMEM;
457 u16 *buf; 483 u16 *buf;
458 484
459 buf = kcalloc(SSB_SPROMSIZE_WORDS, sizeof(u16), GFP_KERNEL); 485 buf = kcalloc(SSB_SPROMSIZE_WORDS_R123, sizeof(u16), GFP_KERNEL);
460 if (!buf) 486 if (!buf)
461 goto out; 487 goto out;
488 bus->sprom_size = SSB_SPROMSIZE_WORDS_R123;
462 sprom_do_read(bus, buf); 489 sprom_do_read(bus, buf);
463 err = sprom_check_crc(buf); 490 err = sprom_check_crc(buf, bus->sprom_size);
464 if (err) { 491 if (err) {
465 ssb_printk(KERN_WARNING PFX 492 /* check for rev 4 sprom - has special signature */
466 "WARNING: Invalid SPROM CRC (corrupt SPROM)\n"); 493 if (buf [32] == 0x5372) {
494 ssb_printk(KERN_WARNING PFX "Extracting a rev 4"
495 " SPROM\n");
496 kfree(buf);
497 buf = kcalloc(SSB_SPROMSIZE_WORDS_R4, sizeof(u16),
498 GFP_KERNEL);
499 if (!buf)
500 goto out;
501 bus->sprom_size = SSB_SPROMSIZE_WORDS_R4;
502 sprom_do_read(bus, buf);
503 err = sprom_check_crc(buf, bus->sprom_size);
504 }
505 if (err)
506 ssb_printk(KERN_WARNING PFX "WARNING: Invalid"
507 " SPROM CRC (corrupt SPROM)\n");
467 } 508 }
468 err = sprom_extract(bus, sprom, buf); 509 err = sprom_extract(bus, sprom, buf, bus->sprom_size);
469 510
470 kfree(buf); 511 kfree(buf);
471out: 512out:
@@ -579,29 +620,28 @@ const struct ssb_bus_ops ssb_pci_ops = {
579 .write32 = ssb_pci_write32, 620 .write32 = ssb_pci_write32,
580}; 621};
581 622
582static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len) 623static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len, u16 size)
583{ 624{
584 int i, pos = 0; 625 int i, pos = 0;
585 626
586 for (i = 0; i < SSB_SPROMSIZE_WORDS; i++) { 627 for (i = 0; i < size; i++)
587 pos += snprintf(buf + pos, buf_len - pos - 1, 628 pos += snprintf(buf + pos, buf_len - pos - 1,
588 "%04X", swab16(sprom[i]) & 0xFFFF); 629 "%04X", swab16(sprom[i]) & 0xFFFF);
589 }
590 pos += snprintf(buf + pos, buf_len - pos - 1, "\n"); 630 pos += snprintf(buf + pos, buf_len - pos - 1, "\n");
591 631
592 return pos + 1; 632 return pos + 1;
593} 633}
594 634
595static int hex2sprom(u16 *sprom, const char *dump, size_t len) 635static int hex2sprom(u16 *sprom, const char *dump, size_t len, u16 size)
596{ 636{
597 char tmp[5] = { 0 }; 637 char tmp[5] = { 0 };
598 int cnt = 0; 638 int cnt = 0;
599 unsigned long parsed; 639 unsigned long parsed;
600 640
601 if (len < SSB_SPROMSIZE_BYTES * 2) 641 if (len < size * 2)
602 return -EINVAL; 642 return -EINVAL;
603 643
604 while (cnt < SSB_SPROMSIZE_WORDS) { 644 while (cnt < size) {
605 memcpy(tmp, dump, 4); 645 memcpy(tmp, dump, 4);
606 dump += 4; 646 dump += 4;
607 parsed = simple_strtoul(tmp, NULL, 16); 647 parsed = simple_strtoul(tmp, NULL, 16);
@@ -625,7 +665,7 @@ static ssize_t ssb_pci_attr_sprom_show(struct device *pcidev,
625 if (!bus) 665 if (!bus)
626 goto out; 666 goto out;
627 err = -ENOMEM; 667 err = -ENOMEM;
628 sprom = kcalloc(SSB_SPROMSIZE_WORDS, sizeof(u16), GFP_KERNEL); 668 sprom = kcalloc(bus->sprom_size, sizeof(u16), GFP_KERNEL);
629 if (!sprom) 669 if (!sprom)
630 goto out; 670 goto out;
631 671
@@ -638,7 +678,7 @@ static ssize_t ssb_pci_attr_sprom_show(struct device *pcidev,
638 sprom_do_read(bus, sprom); 678 sprom_do_read(bus, sprom);
639 mutex_unlock(&bus->pci_sprom_mutex); 679 mutex_unlock(&bus->pci_sprom_mutex);
640 680
641 count = sprom2hex(sprom, buf, PAGE_SIZE); 681 count = sprom2hex(sprom, buf, PAGE_SIZE, bus->sprom_size);
642 err = 0; 682 err = 0;
643 683
644out_kfree: 684out_kfree:
@@ -660,15 +700,15 @@ static ssize_t ssb_pci_attr_sprom_store(struct device *pcidev,
660 if (!bus) 700 if (!bus)
661 goto out; 701 goto out;
662 err = -ENOMEM; 702 err = -ENOMEM;
663 sprom = kcalloc(SSB_SPROMSIZE_WORDS, sizeof(u16), GFP_KERNEL); 703 sprom = kcalloc(bus->sprom_size, sizeof(u16), GFP_KERNEL);
664 if (!sprom) 704 if (!sprom)
665 goto out; 705 goto out;
666 err = hex2sprom(sprom, buf, count); 706 err = hex2sprom(sprom, buf, count, bus->sprom_size);
667 if (err) { 707 if (err) {
668 err = -EINVAL; 708 err = -EINVAL;
669 goto out_kfree; 709 goto out_kfree;
670 } 710 }
671 err = sprom_check_crc(sprom); 711 err = sprom_check_crc(sprom, bus->sprom_size);
672 if (err) { 712 if (err) {
673 err = -EINVAL; 713 err = -EINVAL;
674 goto out_kfree; 714 goto out_kfree;