static int p54spi_request_eeprom(struct ieee80211_hw *dev) { struct p54s_priv *priv = dev->priv; const struct firmware *eeprom; int ret; /* allow users to customize their eeprom. */ ret = request_firmware_direct(&eeprom, "3826.eeprom", &priv->spi->dev); if (ret < 0) { #ifdef CONFIG_P54_SPI_DEFAULT_EEPROM dev_info(&priv->spi->dev, "loading default eeprom...\n"); ret = p54_parse_eeprom(dev, (void *) p54spi_eeprom, sizeof(p54spi_eeprom)); #else dev_err(&priv->spi->dev, "Failed to request user eeprom\n"); #endif /* CONFIG_P54_SPI_DEFAULT_EEPROM */ } else { dev_info(&priv->spi->dev, "loading user eeprom...\n"); ret = p54_parse_eeprom(dev, (void *) eeprom->data, (int)eeprom->size); release_firmware(eeprom); } return ret; }
int p54_read_eeprom(struct ieee80211_hw *dev) { struct p54_common *priv = dev->priv; size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize; int ret = -ENOMEM; void *eeprom; maxblocksize = EEPROM_READBACK_LEN; if (priv->fw_var >= 0x509) maxblocksize -= 0xc; else maxblocksize -= 0x4; eeprom = kzalloc(eeprom_size, GFP_KERNEL); if (unlikely(!eeprom)) goto free; while (eeprom_size) { blocksize = min(eeprom_size, maxblocksize); ret = p54_download_eeprom(priv, (void *) (eeprom + offset), offset, blocksize); if (unlikely(ret)) goto free; offset += blocksize; eeprom_size -= blocksize; } ret = p54_parse_eeprom(dev, eeprom, offset); free: kfree(eeprom); return ret; }
static int p54spi_request_eeprom(struct ieee80211_hw *dev) { struct p54s_priv *priv = dev->priv; const struct firmware *eeprom; int ret; /* * allow users to customize their eeprom. */ ret = request_firmware(&eeprom, "3826.eeprom", &priv->spi->dev); if (ret < 0) { dev_info(&priv->spi->dev, "loading default eeprom...\n"); ret = p54_parse_eeprom(dev, (void *) p54spi_eeprom, sizeof(p54spi_eeprom)); } else { dev_info(&priv->spi->dev, "loading user eeprom...\n"); ret = p54_parse_eeprom(dev, (void *) eeprom->data, (int)eeprom->size); release_firmware(eeprom); } return ret; }
static int p54u_read_eeprom(struct ieee80211_hw *dev) { struct p54u_priv *priv = dev->priv; void *buf; struct p54_control_hdr *hdr; int err, alen; size_t offset = priv->hw_type ? 0x10 : 0x20; buf = kmalloc(0x2020, GFP_KERNEL); if (!buf) { printk(KERN_ERR "prism54usb: cannot allocate memory for " "eeprom readback!\n"); return -ENOMEM; } if (priv->hw_type) { *((u32 *) buf) = priv->common.rx_start; err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, sizeof(u32)); if (err) { printk(KERN_ERR "prism54usb: addr send failed\n"); goto fail; } } else { struct net2280_reg_write *reg = buf; reg->port = cpu_to_le16(NET2280_DEV_U32); reg->addr = cpu_to_le32(P54U_DEV_BASE); reg->val = cpu_to_le32(ISL38XX_DEV_INT_DATA); err = p54u_bulk_msg(priv, P54U_PIPE_DEV, buf, sizeof(*reg)); if (err) { printk(KERN_ERR "prism54usb: dev_int send failed\n"); goto fail; } } hdr = buf + priv->common.tx_hdr_len; p54_fill_eeprom_readback(hdr); hdr->req_id = cpu_to_le32(priv->common.rx_start); if (priv->common.tx_hdr_len) { struct net2280_tx_hdr *tx_hdr = buf; tx_hdr->device_addr = hdr->req_id; tx_hdr->len = cpu_to_le16(EEPROM_READBACK_LEN); } /* we can just pretend to send 0x2000 bytes of nothing in the headers */ err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, EEPROM_READBACK_LEN + priv->common.tx_hdr_len); if (err) { printk(KERN_ERR "prism54usb: eeprom req send failed\n"); goto fail; } err = usb_bulk_msg(priv->udev, usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 0x2020, &alen, 1000); if (!err && alen > offset) { p54_parse_eeprom(dev, (u8 *)buf + offset, alen - offset); } else { printk(KERN_ERR "prism54usb: eeprom read failed!\n"); err = -EINVAL; goto fail; } fail: kfree(buf); return err; }
static int p54p_read_eeprom(struct ieee80211_hw *dev) { struct p54p_priv *priv = dev->priv; struct p54p_ring_control *ring_control = priv->ring_control; int err; struct p54_control_hdr *hdr; void *eeprom; dma_addr_t rx_mapping, tx_mapping; u16 alen; init_completion(&priv->boot_comp); err = request_irq(priv->pdev->irq, &p54p_simple_interrupt, IRQF_SHARED, "prism54pci", priv); if (err) { printk(KERN_ERR "%s (prism54pci): failed to register IRQ handler\n", pci_name(priv->pdev)); return err; } eeprom = kmalloc(0x2010 + EEPROM_READBACK_LEN, GFP_KERNEL); if (!eeprom) { printk(KERN_ERR "%s (prism54pci): no memory for eeprom!\n", pci_name(priv->pdev)); err = -ENOMEM; goto out; } memset(ring_control, 0, sizeof(*ring_control)); P54P_WRITE(ring_control_base, cpu_to_le32(priv->ring_control_dma)); P54P_READ(ring_control_base); udelay(10); P54P_WRITE(int_enable, cpu_to_le32(ISL38XX_INT_IDENT_INIT)); P54P_READ(int_enable); udelay(10); P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_RESET)); if (!wait_for_completion_interruptible_timeout(&priv->boot_comp, HZ)) { printk(KERN_ERR "%s (prism54pci): Cannot boot firmware!\n", pci_name(priv->pdev)); err = -EINVAL; goto out; } P54P_WRITE(int_enable, cpu_to_le32(ISL38XX_INT_IDENT_UPDATE)); P54P_READ(int_enable); hdr = eeprom + 0x2010; p54_fill_eeprom_readback(hdr); hdr->req_id = cpu_to_le32(priv->common.rx_start); rx_mapping = pci_map_single(priv->pdev, eeprom, 0x2010, PCI_DMA_FROMDEVICE); tx_mapping = pci_map_single(priv->pdev, (void *)hdr, EEPROM_READBACK_LEN, PCI_DMA_TODEVICE); ring_control->rx_mgmt[0].host_addr = cpu_to_le32(rx_mapping); ring_control->rx_mgmt[0].len = cpu_to_le16(0x2010); ring_control->tx_data[0].host_addr = cpu_to_le32(tx_mapping); ring_control->tx_data[0].device_addr = hdr->req_id; ring_control->tx_data[0].len = cpu_to_le16(EEPROM_READBACK_LEN); ring_control->host_idx[2] = cpu_to_le32(1); ring_control->host_idx[1] = cpu_to_le32(1); wmb(); mdelay(100); P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_UPDATE)); wait_for_completion_interruptible_timeout(&priv->boot_comp, HZ); wait_for_completion_interruptible_timeout(&priv->boot_comp, HZ); pci_unmap_single(priv->pdev, tx_mapping, EEPROM_READBACK_LEN, PCI_DMA_TODEVICE); pci_unmap_single(priv->pdev, rx_mapping, 0x2010, PCI_DMA_FROMDEVICE); alen = le16_to_cpu(ring_control->rx_mgmt[0].len); if (le32_to_cpu(ring_control->device_idx[2]) != 1 || alen < 0x10) { printk(KERN_ERR "%s (prism54pci): Cannot read eeprom!\n", pci_name(priv->pdev)); err = -EINVAL; goto out; } p54_parse_eeprom(dev, (u8 *)eeprom + 0x10, alen - 0x10); out: kfree(eeprom); P54P_WRITE(int_enable, cpu_to_le32(0)); P54P_READ(int_enable); udelay(10); free_irq(priv->pdev->irq, priv); P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_RESET)); return err; }