Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

p54: move eeprom code into common library

Both p54pci and p54usb uses a good chunk of device specific code to
get the data from the device's eeprom into the drivers memory.

So, this patch reduces the code size and will it make life easier if
someone wants to implement ethtool eeprom dumping features.

Signed-off-by: Christian Lamparter <chunkeey@web.de>
Signed-off-by: John W. Linville <linville@tuxdriver.com>

authored by

Christian Lamparter and committed by
John W. Linville
7cb77072 4e416a6f

+137 -235
+5 -4
drivers/net/wireless/p54/p54.h
··· 38 38 u8 data[0]; 39 39 } __attribute__ ((packed)); 40 40 41 - #define EEPROM_READBACK_LEN (sizeof(struct p54_control_hdr) + 4 /* p54_eeprom_lm86 */) 41 + #define EEPROM_READBACK_LEN 0x3fc 42 42 43 43 #define ISL38XX_DEV_FIRMWARE_ADDR 0x20000 44 44 ··· 63 63 struct pda_channel_output_limit *output_limit; 64 64 unsigned int output_limit_len; 65 65 struct pda_pa_curve_data *curve_data; 66 - __le16 rxhw; 66 + u16 rxhw; 67 67 u8 version; 68 68 unsigned int tx_hdr_len; 69 69 void *cached_vdcf; 70 70 unsigned int fw_var; 71 71 struct ieee80211_tx_queue_stats tx_stats[8]; 72 + void *eeprom; 73 + struct completion eeprom_comp; 72 74 }; 73 75 74 76 int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb); 75 77 int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw); 76 - int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len); 77 - void p54_fill_eeprom_readback(struct p54_control_hdr *hdr); 78 + int p54_read_eeprom(struct ieee80211_hw *dev); 78 79 struct ieee80211_hw *p54_init_common(size_t priv_data_len); 79 80 void p54_free_common(struct ieee80211_hw *dev); 80 81
+114 -17
drivers/net/wireless/p54/p54common.c
··· 249 249 return 0; 250 250 } 251 251 252 + const char* p54_rf_chips[] = { "NULL", "Indigo?", "Duette", 253 + "Frisbee", "Xbow", "Longbow" }; 254 + 252 255 int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len) 253 256 { 254 257 struct p54_common *priv = dev->priv; ··· 261 258 void *tmp; 262 259 int err; 263 260 u8 *end = (u8 *)eeprom + len; 261 + DECLARE_MAC_BUF(mac); 264 262 265 263 wrap = (struct eeprom_pda_wrap *) eeprom; 266 264 entry = (void *)wrap->data + le16_to_cpu(wrap->len); ··· 343 339 while ((u8 *)tmp < entry->data + data_len) { 344 340 struct bootrec_exp_if *exp_if = tmp; 345 341 if (le16_to_cpu(exp_if->if_id) == 0xF) 346 - priv->rxhw = exp_if->variant & cpu_to_le16(0x07); 342 + priv->rxhw = le16_to_cpu(exp_if->variant) & 0x07; 347 343 tmp += sizeof(struct bootrec_exp_if); 348 344 } 349 345 break; ··· 369 365 goto err; 370 366 } 371 367 368 + switch (priv->rxhw) { 369 + case 4: /* XBow */ 370 + case 1: /* Indigo? */ 371 + case 2: /* Duette */ 372 + /* TODO: 5GHz initialization goes here */ 373 + 374 + case 3: /* Frisbee */ 375 + case 5: /* Longbow */ 376 + dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz; 377 + break; 378 + default: 379 + printk(KERN_ERR "%s: unsupported RF-Chip\n", 380 + wiphy_name(dev->wiphy)); 381 + err = -EINVAL; 382 + goto err; 383 + } 384 + 385 + if (!is_valid_ether_addr(dev->wiphy->perm_addr)) { 386 + u8 perm_addr[ETH_ALEN]; 387 + 388 + printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n", 389 + wiphy_name(dev->wiphy)); 390 + random_ether_addr(perm_addr); 391 + SET_IEEE80211_PERM_ADDR(dev, perm_addr); 392 + } 393 + 394 + printk(KERN_INFO "%s: hwaddr %s, MAC:isl38%02x RF:%s\n", 395 + wiphy_name(dev->wiphy), 396 + print_mac(mac, dev->wiphy->perm_addr), 397 + priv->version, p54_rf_chips[priv->rxhw]); 398 + 372 399 return 0; 373 400 374 401 err: ··· 422 387 return err; 423 388 } 424 389 EXPORT_SYMBOL_GPL(p54_parse_eeprom); 425 - 426 - void p54_fill_eeprom_readback(struct p54_control_hdr *hdr) 427 - { 428 - struct p54_eeprom_lm86 *eeprom_hdr; 429 - 430 - hdr->magic1 = cpu_to_le16(0x8000); 431 - hdr->len = cpu_to_le16(sizeof(*eeprom_hdr) + 0x2000); 432 - hdr->type = cpu_to_le16(P54_CONTROL_TYPE_EEPROM_READBACK); 433 - hdr->retry1 = hdr->retry2 = 0; 434 - eeprom_hdr = (struct p54_eeprom_lm86 *) hdr->data; 435 - eeprom_hdr->offset = 0x0; 436 - eeprom_hdr->len = cpu_to_le16(0x2000); 437 - } 438 - EXPORT_SYMBOL_GPL(p54_fill_eeprom_readback); 439 390 440 391 static void p54_rx_data(struct ieee80211_hw *dev, struct sk_buff *skb) 441 392 { ··· 520 499 p54_wake_free_queues(dev); 521 500 } 522 501 502 + static void p54_rx_eeprom_readback(struct ieee80211_hw *dev, 503 + struct sk_buff *skb) 504 + { 505 + struct p54_control_hdr *hdr = (struct p54_control_hdr *) skb->data; 506 + struct p54_eeprom_lm86 *eeprom = (struct p54_eeprom_lm86 *) hdr->data; 507 + struct p54_common *priv = dev->priv; 508 + 509 + if (!priv->eeprom) 510 + return ; 511 + 512 + memcpy(priv->eeprom, eeprom->data, eeprom->len); 513 + 514 + complete(&priv->eeprom_comp); 515 + } 516 + 523 517 static void p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb) 524 518 { 525 519 struct p54_control_hdr *hdr = (struct p54_control_hdr *) skb->data; ··· 544 508 p54_rx_frame_sent(dev, skb); 545 509 break; 546 510 case P54_CONTROL_TYPE_BBP: 511 + break; 512 + case P54_CONTROL_TYPE_EEPROM_READBACK: 513 + p54_rx_eeprom_readback(dev, skb); 547 514 break; 548 515 default: 549 516 printk(KERN_DEBUG "%s: not handling 0x%02x type control frame\n", ··· 645 606 646 607 data->req_id = cpu_to_le32(target_addr + priv->headroom); 647 608 } 609 + 610 + int p54_read_eeprom(struct ieee80211_hw *dev) 611 + { 612 + struct p54_common *priv = dev->priv; 613 + struct p54_control_hdr *hdr = NULL; 614 + struct p54_eeprom_lm86 *eeprom_hdr; 615 + size_t eeprom_size = 0x2020, offset = 0, blocksize; 616 + int ret = -ENOMEM; 617 + void *eeprom = NULL; 618 + 619 + hdr = (struct p54_control_hdr *)kzalloc(sizeof(*hdr) + 620 + sizeof(*eeprom_hdr) + EEPROM_READBACK_LEN, GFP_KERNEL); 621 + if (!hdr) 622 + goto free; 623 + 624 + priv->eeprom = kzalloc(EEPROM_READBACK_LEN, GFP_KERNEL); 625 + if (!priv->eeprom) 626 + goto free; 627 + 628 + eeprom = kzalloc(eeprom_size, GFP_KERNEL); 629 + if (!eeprom) 630 + goto free; 631 + 632 + hdr->magic1 = cpu_to_le16(0x8000); 633 + hdr->type = cpu_to_le16(P54_CONTROL_TYPE_EEPROM_READBACK); 634 + hdr->retry1 = hdr->retry2 = 0; 635 + eeprom_hdr = (struct p54_eeprom_lm86 *) hdr->data; 636 + 637 + while (eeprom_size) { 638 + blocksize = min(eeprom_size, (size_t)EEPROM_READBACK_LEN); 639 + hdr->len = cpu_to_le16(blocksize + sizeof(*eeprom_hdr)); 640 + eeprom_hdr->offset = cpu_to_le16(offset); 641 + eeprom_hdr->len = cpu_to_le16(blocksize); 642 + p54_assign_address(dev, NULL, hdr, hdr->len + sizeof(*hdr)); 643 + priv->tx(dev, hdr, hdr->len + sizeof(*hdr), 0); 644 + 645 + if (!wait_for_completion_interruptible_timeout(&priv->eeprom_comp, HZ)) { 646 + printk(KERN_ERR "%s: device does not respond!\n", 647 + wiphy_name(dev->wiphy)); 648 + ret = -EBUSY; 649 + goto free; 650 + } 651 + 652 + memcpy(eeprom + offset, priv->eeprom, blocksize); 653 + offset += blocksize; 654 + eeprom_size -= blocksize; 655 + } 656 + 657 + ret = p54_parse_eeprom(dev, eeprom, offset); 658 + free: 659 + kfree(priv->eeprom); 660 + priv->eeprom = NULL; 661 + kfree(hdr); 662 + kfree(eeprom); 663 + 664 + return ret; 665 + } 666 + EXPORT_SYMBOL_GPL(p54_read_eeprom); 648 667 649 668 static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb) 650 669 { ··· 815 718 filter->magic3 = cpu_to_le32(magic3); 816 719 filter->rx_addr = cpu_to_le32(priv->rx_end); 817 720 filter->max_rx = cpu_to_le16(priv->rx_mtu); 818 - filter->rxhw = priv->rxhw; 721 + filter->rxhw = cpu_to_le16(priv->rxhw); 819 722 filter->magic8 = cpu_to_le16(magic8); 820 723 filter->magic9 = cpu_to_le16(magic9); 821 724 ··· 1178 1081 priv = dev->priv; 1179 1082 priv->mode = IEEE80211_IF_TYPE_INVALID; 1180 1083 skb_queue_head_init(&priv->tx_queue); 1181 - dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz; 1182 1084 dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | /* not sure */ 1183 1085 IEEE80211_HW_RX_INCLUDES_FCS | 1184 1086 IEEE80211_HW_SIGNAL_UNSPEC; ··· 1197 1101 sizeof(struct p54_tx_control_allocdata); 1198 1102 1199 1103 mutex_init(&priv->conf_mutex); 1104 + init_completion(&priv->eeprom_comp); 1200 1105 1201 1106 return dev; 1202 1107 }
+13 -131
drivers/net/wireless/p54/p54pci.c
··· 72 72 P54P_WRITE(ctrl_stat, reg); 73 73 wmb(); 74 74 75 - mdelay(50); 76 - 77 75 err = request_firmware(&fw_entry, "isl3886", &priv->pdev->dev); 78 76 if (err) { 79 77 printk(KERN_ERR "%s (p54pci): cannot find firmware " ··· 124 126 wmb(); 125 127 udelay(10); 126 128 127 - return 0; 128 - } 129 - 130 - static irqreturn_t p54p_simple_interrupt(int irq, void *dev_id) 131 - { 132 - struct p54p_priv *priv = (struct p54p_priv *) dev_id; 133 - __le32 reg; 134 - 135 - reg = P54P_READ(int_ident); 136 - P54P_WRITE(int_ack, reg); 137 - 138 - if (reg & P54P_READ(int_enable)) 139 - complete(&priv->boot_comp); 140 - 141 - return IRQ_HANDLED; 142 - } 143 - 144 - static int p54p_read_eeprom(struct ieee80211_hw *dev) 145 - { 146 - struct p54p_priv *priv = dev->priv; 147 - struct p54p_ring_control *ring_control = priv->ring_control; 148 - int err; 149 - struct p54_control_hdr *hdr; 150 - void *eeprom; 151 - dma_addr_t rx_mapping, tx_mapping; 152 - u16 alen; 153 - 154 - init_completion(&priv->boot_comp); 155 - err = request_irq(priv->pdev->irq, &p54p_simple_interrupt, 156 - IRQF_SHARED, "p54pci", priv); 157 - if (err) { 158 - printk(KERN_ERR "%s (p54pci): failed to register IRQ handler\n", 159 - pci_name(priv->pdev)); 160 - return err; 161 - } 162 - 163 - eeprom = kmalloc(0x2010 + EEPROM_READBACK_LEN, GFP_KERNEL); 164 - if (!eeprom) { 165 - printk(KERN_ERR "%s (p54pci): no memory for eeprom!\n", 166 - pci_name(priv->pdev)); 167 - err = -ENOMEM; 168 - goto out; 169 - } 170 - 171 - memset(ring_control, 0, sizeof(*ring_control)); 172 - P54P_WRITE(ring_control_base, cpu_to_le32(priv->ring_control_dma)); 173 - P54P_READ(ring_control_base); 174 - udelay(10); 175 - 176 - P54P_WRITE(int_enable, cpu_to_le32(ISL38XX_INT_IDENT_INIT)); 177 - P54P_READ(int_enable); 178 - udelay(10); 179 - 180 - P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_RESET)); 181 - 182 - if (!wait_for_completion_interruptible_timeout(&priv->boot_comp, HZ)) { 183 - printk(KERN_ERR "%s (p54pci): Cannot boot firmware!\n", 184 - pci_name(priv->pdev)); 185 - err = -EINVAL; 186 - goto out; 187 - } 188 - 189 - P54P_WRITE(int_enable, cpu_to_le32(ISL38XX_INT_IDENT_UPDATE)); 190 - P54P_READ(int_enable); 191 - 192 - hdr = eeprom + 0x2010; 193 - p54_fill_eeprom_readback(hdr); 194 - hdr->req_id = cpu_to_le32(priv->common.rx_start); 195 - 196 - rx_mapping = pci_map_single(priv->pdev, eeprom, 197 - 0x2010, PCI_DMA_FROMDEVICE); 198 - tx_mapping = pci_map_single(priv->pdev, (void *)hdr, 199 - EEPROM_READBACK_LEN, PCI_DMA_TODEVICE); 200 - 201 - ring_control->rx_mgmt[0].host_addr = cpu_to_le32(rx_mapping); 202 - ring_control->rx_mgmt[0].len = cpu_to_le16(0x2010); 203 - ring_control->tx_data[0].host_addr = cpu_to_le32(tx_mapping); 204 - ring_control->tx_data[0].device_addr = hdr->req_id; 205 - ring_control->tx_data[0].len = cpu_to_le16(EEPROM_READBACK_LEN); 206 - 207 - ring_control->host_idx[2] = cpu_to_le32(1); 208 - ring_control->host_idx[1] = cpu_to_le32(1); 209 - 210 - wmb(); 129 + /* wait for the firmware to boot properly */ 211 130 mdelay(100); 212 - P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_UPDATE)); 213 131 214 - wait_for_completion_interruptible_timeout(&priv->boot_comp, HZ); 215 - wait_for_completion_interruptible_timeout(&priv->boot_comp, HZ); 216 - 217 - pci_unmap_single(priv->pdev, tx_mapping, 218 - EEPROM_READBACK_LEN, PCI_DMA_TODEVICE); 219 - pci_unmap_single(priv->pdev, rx_mapping, 220 - 0x2010, PCI_DMA_FROMDEVICE); 221 - 222 - alen = le16_to_cpu(ring_control->rx_mgmt[0].len); 223 - if (le32_to_cpu(ring_control->device_idx[2]) != 1 || 224 - alen < 0x10) { 225 - printk(KERN_ERR "%s (p54pci): Cannot read eeprom!\n", 226 - pci_name(priv->pdev)); 227 - err = -EINVAL; 228 - goto out; 229 - } 230 - 231 - p54_parse_eeprom(dev, (u8 *)eeprom + 0x10, alen - 0x10); 232 - 233 - out: 234 - kfree(eeprom); 235 - P54P_WRITE(int_enable, cpu_to_le32(0)); 236 - P54P_READ(int_enable); 237 - udelay(10); 238 - free_irq(priv->pdev->irq, priv); 239 - P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_RESET)); 240 - return err; 132 + return 0; 241 133 } 242 134 243 135 static void p54p_refill_rx_ring(struct ieee80211_hw *dev, ··· 361 473 } 362 474 363 475 memset(priv->ring_control, 0, sizeof(*priv->ring_control)); 476 + err = p54p_upload_firmware(dev); 477 + if (err) { 478 + free_irq(priv->pdev->irq, dev); 479 + return err; 480 + } 364 481 priv->rx_idx_data = priv->tx_idx_data = 0; 365 482 priv->rx_idx_mgmt = priv->tx_idx_mgmt = 0; 366 483 ··· 374 481 375 482 p54p_refill_rx_ring(dev, 2, priv->ring_control->rx_mgmt, 376 483 ARRAY_SIZE(priv->ring_control->rx_mgmt), priv->rx_buf_mgmt); 377 - 378 - p54p_upload_firmware(dev); 379 484 380 485 P54P_WRITE(ring_control_base, cpu_to_le32(priv->ring_control_dma)); 381 486 P54P_READ(ring_control_base); ··· 549 658 err = -ENOMEM; 550 659 goto err_iounmap; 551 660 } 552 - memset(priv->ring_control, 0, sizeof(*priv->ring_control)); 553 - 554 - err = p54p_upload_firmware(dev); 555 - if (err) 556 - goto err_free_desc; 557 - 558 - err = p54p_read_eeprom(dev); 559 - if (err) 560 - goto err_free_desc; 561 - 562 661 priv->common.open = p54p_open; 563 662 priv->common.stop = p54p_stop; 564 663 priv->common.tx = p54p_tx; ··· 556 675 spin_lock_init(&priv->lock); 557 676 tasklet_init(&priv->rx_tasklet, p54p_rx_tasklet, (unsigned long)dev); 558 677 678 + p54p_open(dev); 679 + err = p54_read_eeprom(dev); 680 + p54p_stop(dev); 681 + if (err) 682 + goto err_free_desc; 683 + 559 684 err = ieee80211_register_hw(dev); 560 685 if (err) { 561 686 printk(KERN_ERR "%s (p54pci): Cannot register netdevice\n", 562 687 pci_name(pdev)); 563 688 goto err_free_common; 564 689 } 565 - 566 - printk(KERN_INFO "%s: hwaddr %s, isl38%02x\n", 567 - wiphy_name(dev->wiphy), 568 - print_mac(mac, dev->wiphy->perm_addr), 569 - priv->common.version); 570 690 571 691 return 0; 572 692
+5 -83
drivers/net/wireless/p54/p54usb.c
··· 315 315 data, len, &alen, 2000); 316 316 } 317 317 318 - static int p54u_read_eeprom(struct ieee80211_hw *dev) 319 - { 320 - struct p54u_priv *priv = dev->priv; 321 - void *buf; 322 - struct p54_control_hdr *hdr; 323 - int err, alen; 324 - size_t offset = priv->hw_type ? 0x10 : 0x20; 325 - 326 - buf = kmalloc(0x2020, GFP_KERNEL); 327 - if (!buf) { 328 - printk(KERN_ERR "p54usb: cannot allocate memory for " 329 - "eeprom readback!\n"); 330 - return -ENOMEM; 331 - } 332 - 333 - if (priv->hw_type) { 334 - *((u32 *) buf) = priv->common.rx_start; 335 - err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, sizeof(u32)); 336 - if (err) { 337 - printk(KERN_ERR "p54usb: addr send failed\n"); 338 - goto fail; 339 - } 340 - } else { 341 - struct net2280_reg_write *reg = buf; 342 - reg->port = cpu_to_le16(NET2280_DEV_U32); 343 - reg->addr = cpu_to_le32(P54U_DEV_BASE); 344 - reg->val = cpu_to_le32(ISL38XX_DEV_INT_DATA); 345 - err = p54u_bulk_msg(priv, P54U_PIPE_DEV, buf, sizeof(*reg)); 346 - if (err) { 347 - printk(KERN_ERR "p54usb: dev_int send failed\n"); 348 - goto fail; 349 - } 350 - } 351 - 352 - hdr = buf + priv->common.tx_hdr_len; 353 - p54_fill_eeprom_readback(hdr); 354 - hdr->req_id = cpu_to_le32(priv->common.rx_start); 355 - if (priv->common.tx_hdr_len) { 356 - struct net2280_tx_hdr *tx_hdr = buf; 357 - tx_hdr->device_addr = hdr->req_id; 358 - tx_hdr->len = cpu_to_le16(EEPROM_READBACK_LEN); 359 - } 360 - 361 - /* we can just pretend to send 0x2000 bytes of nothing in the headers */ 362 - err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 363 - EEPROM_READBACK_LEN + priv->common.tx_hdr_len); 364 - if (err) { 365 - printk(KERN_ERR "p54usb: eeprom req send failed\n"); 366 - goto fail; 367 - } 368 - 369 - err = usb_bulk_msg(priv->udev, 370 - usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), 371 - buf, 0x2020, &alen, 1000); 372 - if (!err && alen > offset) { 373 - p54_parse_eeprom(dev, (u8 *)buf + offset, alen - offset); 374 - } else { 375 - printk(KERN_ERR "p54usb: eeprom read failed!\n"); 376 - err = -EINVAL; 377 - goto fail; 378 - } 379 - 380 - fail: 381 - kfree(buf); 382 - return err; 383 - } 384 - 385 318 static int p54u_upload_firmware_3887(struct ieee80211_hw *dev) 386 319 { 387 320 static char start_string[] = "~~~~<\r"; ··· 794 861 if (err) 795 862 goto err_free_dev; 796 863 797 - err = p54u_read_eeprom(dev); 864 + skb_queue_head_init(&priv->rx_queue); 865 + 866 + p54u_open(dev); 867 + err = p54_read_eeprom(dev); 868 + p54u_stop(dev); 798 869 if (err) 799 870 goto err_free_dev; 800 - 801 - if (!is_valid_ether_addr(dev->wiphy->perm_addr)) { 802 - u8 perm_addr[ETH_ALEN]; 803 - 804 - printk(KERN_WARNING "p54usb: Invalid hwaddr! Using randomly generated MAC addr\n"); 805 - random_ether_addr(perm_addr); 806 - SET_IEEE80211_PERM_ADDR(dev, perm_addr); 807 - } 808 - 809 - skb_queue_head_init(&priv->rx_queue); 810 871 811 872 err = ieee80211_register_hw(dev); 812 873 if (err) { 813 874 printk(KERN_ERR "p54usb: Cannot register netdevice\n"); 814 875 goto err_free_dev; 815 876 } 816 - 817 - printk(KERN_INFO "%s: hwaddr %s, isl38%02x\n", 818 - wiphy_name(dev->wiphy), 819 - print_mac(mac, dev->wiphy->perm_addr), 820 - priv->common.version); 821 877 822 878 return 0; 823 879