static int bnad_set_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, u8 *bytes) { struct bnad *bnad = netdev_priv(netdev); struct bnad_iocmd_comp fcomp; u32 flash_part = 0, base_offset = 0; unsigned long flags = 0; int ret = 0; /* Check if the flash update request is valid */ if (eeprom->magic != (bnad->pcidev->vendor | (bnad->pcidev->device << 16))) return -EINVAL; /* Query the flash partition based on the offset */ flash_part = bnad_get_flash_partition_by_offset(bnad, eeprom->offset, &base_offset); if (flash_part == 0) return -EFAULT; fcomp.bnad = bnad; fcomp.comp_status = 0; init_completion(&fcomp.comp); spin_lock_irqsave(&bnad->bna_lock, flags); ret = bfa_nw_flash_update_part(&bnad->bna.flash, flash_part, bnad->id, bytes, eeprom->len, eeprom->offset - base_offset, bnad_cb_completion, &fcomp); if (ret != BFA_STATUS_OK) { spin_unlock_irqrestore(&bnad->bna_lock, flags); goto done; } spin_unlock_irqrestore(&bnad->bna_lock, flags); wait_for_completion(&fcomp.comp); ret = fcomp.comp_status; done: return ret; }
static int bnad_flash_device(struct net_device *netdev, struct ethtool_flash *eflash) { struct bnad *bnad = netdev_priv(netdev); struct bnad_iocmd_comp fcomp; const struct firmware *fw; int ret = 0; ret = request_firmware(&fw, eflash->data, &bnad->pcidev->dev); if (ret) { netdev_err(netdev, "can't load firmware %s\n", eflash->data); goto out; } fcomp.bnad = bnad; fcomp.comp_status = 0; init_completion(&fcomp.comp); spin_lock_irq(&bnad->bna_lock); ret = bfa_nw_flash_update_part(&bnad->bna.flash, BFA_FLASH_PART_FWIMG, bnad->id, (u8 *)fw->data, fw->size, 0, bnad_cb_completion, &fcomp); if (ret != BFA_STATUS_OK) { netdev_warn(netdev, "flash update failed with err=%d\n", ret); ret = -EIO; spin_unlock_irq(&bnad->bna_lock); goto out; } spin_unlock_irq(&bnad->bna_lock); wait_for_completion(&fcomp.comp); if (fcomp.comp_status != BFA_STATUS_OK) { ret = -EIO; netdev_warn(netdev, "firmware image update failed with err=%d\n", fcomp.comp_status); } out: release_firmware(fw); return ret; }