static int sfxge_nvram_rw(struct sfxge_softc *sc, sfxge_ioc_t *ip, efx_nvram_type_t type, boolean_t write) { efx_nic_t *enp = sc->enp; size_t total_size = ip->u.nvram.size; size_t chunk_size; off_t off; int rc = 0; uint8_t *buf; if (type == EFX_NVRAM_DYNAMIC_CFG && sc->family == EFX_FAMILY_SIENA) { if (write) return (0); rc = copyout(fake_dynamic_cfg_nvram, ip->u.nvram.data, MIN(total_size, sizeof(fake_dynamic_cfg_nvram))); return (rc); } if ((rc = efx_nvram_rw_start(enp, type, &chunk_size)) != 0) goto fail1; buf = malloc(chunk_size, M_TEMP, M_WAITOK); off = 0; while (total_size) { size_t len = MIN(chunk_size, total_size); if (write) { rc = copyin(ip->u.nvram.data + off, buf, len); if (rc != 0) goto fail3; rc = efx_nvram_write_chunk(enp, type, ip->u.nvram.offset + off, buf, len); if (rc != 0) goto fail3; } else { rc = efx_nvram_read_chunk(enp, type, ip->u.nvram.offset + off, buf, len); if (rc != 0) goto fail3; rc = copyout(buf, ip->u.nvram.data + off, len); if (rc != 0) goto fail3; } total_size -= len; off += len; } fail3: free(buf, M_TEMP); efx_nvram_rw_finish(enp, type); fail1: return (rc); }
static int sfxge_nvram_erase(struct sfxge_softc *sc, efx_nvram_type_t type) { efx_nic_t *enp = sc->enp; size_t chunk_size; int rc = 0; if (type == EFX_NVRAM_DYNAMIC_CFG && sc->family == EFX_FAMILY_SIENA) return (0); if ((rc = efx_nvram_rw_start(enp, type, &chunk_size)) != 0) return (rc); rc = efx_nvram_erase(enp, type); efx_nvram_rw_finish(enp, type); return (rc); }
static int sfxge_nvram_rw(sfxge_t *sp, sfxge_nvram_ioc_t *snip, efx_nvram_type_t type, boolean_t write) { int (*op)(efx_nic_t *, efx_nvram_type_t, unsigned int, caddr_t, size_t); efx_nic_t *enp = sp->s_enp; size_t chunk_size; off_t off; int rc; op = (write) ? efx_nvram_write_chunk : efx_nvram_read_chunk; if ((rc = efx_nvram_rw_start(enp, type, &chunk_size)) != 0) goto fail1; off = 0; while (snip->sni_size) { size_t len = MIN(chunk_size, snip->sni_size); caddr_t buf = (caddr_t)(&snip->sni_data[off]); if ((rc = op(enp, type, snip->sni_offset + off, buf, len)) != 0) goto fail2; snip->sni_size -= len; off += len; } efx_nvram_rw_finish(enp, type); return (0); fail2: DTRACE_PROBE(fail2); efx_nvram_rw_finish(enp, type); fail1: DTRACE_PROBE1(fail1, int, rc); return (rc); }
static int sfxge_nvram_erase(sfxge_t *sp, sfxge_nvram_ioc_t *snip, efx_nvram_type_t type) { efx_nic_t *enp = sp->s_enp; size_t chunk_size; int rc; _NOTE(ARGUNUSED(snip)); if ((rc = efx_nvram_rw_start(enp, type, &chunk_size)) != 0) goto fail1; if ((rc = efx_nvram_erase(enp, type)) != 0) goto fail2; efx_nvram_rw_finish(enp, type); return (0); fail2: DTRACE_PROBE(fail2); efx_nvram_rw_finish(enp, type); fail1: DTRACE_PROBE1(fail1, int, rc); return (rc); }