-/* $OpenBSD: if_iwm.c,v 1.362 2021/08/26 07:11:09 kevlo Exp $ */
+/* $OpenBSD: if_iwm.c,v 1.363 2021/08/29 20:31:18 gnezdo Exp $ */
/*
* Copyright (c) 2014, 2016 genua gmbh <info@genua.de>
int iwm_nic_lock(struct iwm_softc *);
void iwm_nic_assert_locked(struct iwm_softc *);
void iwm_nic_unlock(struct iwm_softc *);
-void iwm_set_bits_mask_prph(struct iwm_softc *, uint32_t, uint32_t,
+int iwm_set_bits_mask_prph(struct iwm_softc *, uint32_t, uint32_t,
uint32_t);
-void iwm_set_bits_prph(struct iwm_softc *, uint32_t, uint32_t);
-void iwm_clear_bits_prph(struct iwm_softc *, uint32_t, uint32_t);
+int iwm_set_bits_prph(struct iwm_softc *, uint32_t, uint32_t);
+int iwm_clear_bits_prph(struct iwm_softc *, uint32_t, uint32_t);
int iwm_dma_contig_alloc(bus_dma_tag_t, struct iwm_dma_info *, bus_size_t,
bus_size_t);
void iwm_dma_contig_free(struct iwm_dma_info *);
printf("%s: NIC already unlocked\n", DEVNAME(sc));
}
-void
+int
iwm_set_bits_mask_prph(struct iwm_softc *sc, uint32_t reg, uint32_t bits,
uint32_t mask)
{
uint32_t val;
- /* XXX: no error path? */
if (iwm_nic_lock(sc)) {
val = iwm_read_prph(sc, reg) & mask;
val |= bits;
iwm_write_prph(sc, reg, val);
iwm_nic_unlock(sc);
+ return 0;
}
+ return EBUSY;
}
-void
+int
iwm_set_bits_prph(struct iwm_softc *sc, uint32_t reg, uint32_t bits)
{
- iwm_set_bits_mask_prph(sc, reg, bits, ~0);
+ return iwm_set_bits_mask_prph(sc, reg, bits, ~0);
}
-void
+int
iwm_clear_bits_prph(struct iwm_softc *sc, uint32_t reg, uint32_t bits)
{
- iwm_set_bits_mask_prph(sc, reg, 0, ~bits);
+ return iwm_set_bits_mask_prph(sc, reg, 0, ~bits);
}
int
iwm_read_prph(sc, IWM_OSC_CLK);
iwm_nic_unlock(sc);
}
- iwm_set_bits_prph(sc, IWM_OSC_CLK, IWM_OSC_CLK_FORCE_CONTROL);
+ err = iwm_set_bits_prph(sc, IWM_OSC_CLK,
+ IWM_OSC_CLK_FORCE_CONTROL);
+ if (err)
+ goto out;
if (iwm_nic_lock(sc)) {
iwm_read_prph(sc, IWM_OSC_CLK);
iwm_read_prph(sc, IWM_OSC_CLK);
DELAY(20);
/* Disable L1-Active */
- iwm_set_bits_prph(sc, IWM_APMG_PCIDEV_STT_REG,
+ err = iwm_set_bits_prph(sc, IWM_APMG_PCIDEV_STT_REG,
IWM_APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
+ if (err)
+ goto out;
/* Clear the interrupt in APMG if the NIC is in RFKILL */
if (iwm_nic_lock(sc)) {
int
iwm_nic_tx_init(struct iwm_softc *sc)
{
- int qid;
+ int qid, err;
if (!iwm_nic_lock(sc))
return EBUSY;
txq->desc_dma.paddr >> 8);
}
- iwm_set_bits_prph(sc, IWM_SCD_GP_CTRL,
+ err = iwm_set_bits_prph(sc, IWM_SCD_GP_CTRL,
IWM_SCD_GP_CTRL_AUTO_ACTIVE_MODE |
IWM_SCD_GP_CTRL_ENABLE_31_QUEUES);
iwm_nic_unlock(sc);
- return 0;
+ return err;
}
int
int
iwm_enable_ac_txq(struct iwm_softc *sc, int qid, int fifo)
{
+ int err;
iwm_nic_assert_locked(sc);
IWM_WRITE(sc, IWM_HBUS_TARG_WRPTR, qid << 8 | 0);
(0 << IWM_SCD_QUEUE_STTS_REG_POS_ACTIVE)
| (1 << IWM_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
- iwm_clear_bits_prph(sc, IWM_SCD_AGGR_SEL, (1 << qid));
+ err = iwm_clear_bits_prph(sc, IWM_SCD_AGGR_SEL, (1 << qid));
+ if (err) {
+ return err;
+ }
iwm_write_prph(sc, IWM_SCD_QUEUE_RDPTR(qid), 0);
iwm_nic_unlock(sc);
/* Enable L1-Active */
- if (sc->sc_device_family < IWM_DEVICE_FAMILY_8000)
- iwm_clear_bits_prph(sc, IWM_APMG_PCIDEV_STT_REG,
+ if (sc->sc_device_family < IWM_DEVICE_FAMILY_8000) {
+ err = iwm_clear_bits_prph(sc, IWM_APMG_PCIDEV_STT_REG,
IWM_APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
+ }
return err;
}
dma->map, 0, byte_cnt, BUS_DMASYNC_PREWRITE);
if (dst_addr >= IWM_FW_MEM_EXTENDED_START &&
- dst_addr <= IWM_FW_MEM_EXTENDED_END)
- iwm_set_bits_prph(sc, IWM_LMPM_CHICK,
+ dst_addr <= IWM_FW_MEM_EXTENDED_END) {
+ err = iwm_set_bits_prph(sc, IWM_LMPM_CHICK,
IWM_LMPM_CHICK_EXTENDED_ADDR_SPACE);
+ if (err)
+ return err;
+ }
sc->sc_fw_chunk_done = 0;
if (dst_addr >= IWM_FW_MEM_EXTENDED_START &&
dst_addr <= IWM_FW_MEM_EXTENDED_END) {
- iwm_clear_bits_prph(sc, IWM_LMPM_CHICK,
+ int err2 = iwm_clear_bits_prph(sc, IWM_LMPM_CHICK,
IWM_LMPM_CHICK_EXTENDED_ADDR_SPACE);
+ if (!err)
+ err = err2;
}
return err;
-/* $OpenBSD: if_iwx.c,v 1.97 2021/08/26 07:11:09 kevlo Exp $ */
+/* $OpenBSD: if_iwx.c,v 1.98 2021/08/29 20:31:18 gnezdo Exp $ */
/*
* Copyright (c) 2014, 2016 genua gmbh <info@genua.de>
int iwx_nic_lock(struct iwx_softc *);
void iwx_nic_assert_locked(struct iwx_softc *);
void iwx_nic_unlock(struct iwx_softc *);
-void iwx_set_bits_mask_prph(struct iwx_softc *, uint32_t, uint32_t,
+int iwx_set_bits_mask_prph(struct iwx_softc *, uint32_t, uint32_t,
uint32_t);
-void iwx_set_bits_prph(struct iwx_softc *, uint32_t, uint32_t);
-void iwx_clear_bits_prph(struct iwx_softc *, uint32_t, uint32_t);
+int iwx_set_bits_prph(struct iwx_softc *, uint32_t, uint32_t);
+int iwx_clear_bits_prph(struct iwx_softc *, uint32_t, uint32_t);
int iwx_dma_contig_alloc(bus_dma_tag_t, struct iwx_dma_info *, bus_size_t,
bus_size_t);
void iwx_dma_contig_free(struct iwx_dma_info *);
void iwx_ict_reset(struct iwx_softc *);
int iwx_set_hw_ready(struct iwx_softc *);
int iwx_prepare_card_hw(struct iwx_softc *);
-void iwx_force_power_gating(struct iwx_softc *);
+int iwx_force_power_gating(struct iwx_softc *);
void iwx_apm_config(struct iwx_softc *);
int iwx_apm_init(struct iwx_softc *);
void iwx_apm_stop(struct iwx_softc *);
iwx_write_prph(sc, addr, val);
break;
case PRPH_SETBIT:
- iwx_set_bits_prph(sc, addr, (1 << val));
+ err = iwx_set_bits_prph(sc, addr, (1 << val));
+ if (err)
+ return err;
break;
case PRPH_CLEARBIT:
- iwx_clear_bits_prph(sc, addr, (1 << val));
+ err = iwx_clear_bits_prph(sc, addr, (1 << val));
+ if (err)
+ return err;
break;
case PRPH_BLOCKBIT:
if (iwx_read_prph(sc, addr) & (1 << val))
printf("%s: NIC already unlocked\n", DEVNAME(sc));
}
-void
+int
iwx_set_bits_mask_prph(struct iwx_softc *sc, uint32_t reg, uint32_t bits,
uint32_t mask)
{
uint32_t val;
- /* XXX: no error path? */
if (iwx_nic_lock(sc)) {
val = iwx_read_prph(sc, reg) & mask;
val |= bits;
iwx_write_prph(sc, reg, val);
iwx_nic_unlock(sc);
+ return 0;
}
+ return EBUSY;
}
-void
+int
iwx_set_bits_prph(struct iwx_softc *sc, uint32_t reg, uint32_t bits)
{
- iwx_set_bits_mask_prph(sc, reg, bits, ~0);
+ return iwx_set_bits_mask_prph(sc, reg, bits, ~0);
}
-void
+int
iwx_clear_bits_prph(struct iwx_softc *sc, uint32_t reg, uint32_t bits)
{
- iwx_set_bits_mask_prph(sc, reg, 0, ~bits);
+ return iwx_set_bits_mask_prph(sc, reg, 0, ~bits);
}
int
return ETIMEDOUT;
}
-void
+int
iwx_force_power_gating(struct iwx_softc *sc)
{
- iwx_set_bits_prph(sc, IWX_HPM_HIPM_GEN_CFG,
+ int err;
+
+ err = iwx_set_bits_prph(sc, IWX_HPM_HIPM_GEN_CFG,
IWX_HPM_HIPM_GEN_CFG_CR_FORCE_ACTIVE);
+ if (err)
+ return err;
DELAY(20);
- iwx_set_bits_prph(sc, IWX_HPM_HIPM_GEN_CFG,
+ err = iwx_set_bits_prph(sc, IWX_HPM_HIPM_GEN_CFG,
IWX_HPM_HIPM_GEN_CFG_CR_PG_EN |
IWX_HPM_HIPM_GEN_CFG_CR_SLP_EN);
+ if (err)
+ return err;
DELAY(20);
- iwx_clear_bits_prph(sc, IWX_HPM_HIPM_GEN_CFG,
+ err = iwx_clear_bits_prph(sc, IWX_HPM_HIPM_GEN_CFG,
IWX_HPM_HIPM_GEN_CFG_CR_FORCE_ACTIVE);
+ return err;
}
void
return ETIMEDOUT;
}
- iwx_force_power_gating(sc);
+ err = iwx_force_power_gating(sc);
+ if (err)
+ return err;
/* Reset the entire device */
IWX_SETBITS(sc, IWX_CSR_RESET, IWX_CSR_RESET_REG_FLAG_SW_RESET);
err = tsleep_nsec(&sc->sc_uc, 0, "iwxuc", MSEC_TO_NSEC(100));
}
if (err || !sc->sc_uc.uc_ok)
- printf("%s: could not load firmware\n", DEVNAME(sc));
+ printf("%s: could not load firmware, %d\n", DEVNAME(sc), err);
iwx_ctxt_info_free_fw_img(sc);