sync with OpenBSD -current

This commit is contained in:
purplerain 2024-05-21 00:16:53 +00:00
parent 57ecf9bd1d
commit b5356a44af
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
156 changed files with 3600 additions and 2644 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ociic.c,v 1.3 2022/04/06 18:59:28 naddy Exp $ */
/* $OpenBSD: ociic.c,v 1.4 2024/05/15 22:54:03 kettenis Exp $ */
/*
* Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org>
*
@ -53,6 +53,13 @@
#define I2C_SR_TIP (1 << 1)
#define I2C_SR_IF (1 << 0)
/*
* OpenSBI on the SiFive HiFive Unmatched board implements reboot and
* powerdown functionality through the Dialog DA9063 Power Management
* IC over I2C. The code expects the I2C controller to be enabled so
* we have to make sure we leave it in that state.
*/
struct ociic_softc {
struct device sc_dev;
bus_space_tag_t sc_iot;
@ -156,6 +163,8 @@ ociic_attach(struct device *parent, struct device *self, void *aux)
ociic_write(sc, I2C_PRER_HI, div >> 8);
}
ociic_set(sc, I2C_CTR, I2C_CTR_EN);
sc->sc_ic.ic_cookie = sc;
sc->sc_ic.ic_acquire_bus = ociic_acquire_bus;
sc->sc_ic.ic_release_bus = ociic_release_bus;
@ -174,18 +183,12 @@ ociic_attach(struct device *parent, struct device *self, void *aux)
int
ociic_acquire_bus(void *cookie, int flags)
{
struct ociic_softc *sc = cookie;
ociic_set(sc, I2C_CTR, I2C_CTR_EN);
return 0;
}
void
ociic_release_bus(void *cookie, int flags)
{
struct ociic_softc *sc = cookie;
ociic_clr(sc, I2C_CTR, I2C_CTR_EN);
}
int

View file

@ -1,4 +1,4 @@
/* $OpenBSD: virtio_mmio.c,v 1.12 2024/01/15 02:35:23 dv Exp $ */
/* $OpenBSD: virtio_mmio.c,v 1.13 2024/05/17 16:37:10 sf Exp $ */
/* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */
/*
@ -97,6 +97,7 @@ void virtio_mmio_write_device_config_4(struct virtio_softc *, int, uint32_t);
void virtio_mmio_write_device_config_8(struct virtio_softc *, int, uint64_t);
uint16_t virtio_mmio_read_queue_size(struct virtio_softc *, uint16_t);
void virtio_mmio_setup_queue(struct virtio_softc *, struct virtqueue *, uint64_t);
int virtio_mmio_get_status(struct virtio_softc *);
void virtio_mmio_set_status(struct virtio_softc *, int);
int virtio_mmio_negotiate_features(struct virtio_softc *,
const struct virtio_feature_name *);
@ -144,6 +145,7 @@ struct virtio_ops virtio_mmio_ops = {
virtio_mmio_write_device_config_8,
virtio_mmio_read_queue_size,
virtio_mmio_setup_queue,
virtio_mmio_get_status,
virtio_mmio_set_status,
virtio_mmio_negotiate_features,
virtio_mmio_intr,
@ -194,6 +196,15 @@ virtio_mmio_setup_queue(struct virtio_softc *vsc, struct virtqueue *vq,
}
}
int
virtio_mmio_get_status(struct virtio_softc *vsc)
{
struct virtio_mmio_softc *sc = (struct virtio_mmio_softc *)vsc;
return bus_space_read_4(sc->sc_iot, sc->sc_ioh,
VIRTIO_MMIO_STATUS);
}
void
virtio_mmio_set_status(struct virtio_softc *vsc, int status)
{

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ufshci.c,v 1.22 2024/05/15 18:01:10 mglocker Exp $ */
/* $OpenBSD: ufshci.c,v 1.24 2024/05/16 10:52:11 mglocker Exp $ */
/*
* Copyright (c) 2022 Marcus Glocker <mglocker@openbsd.org>
@ -186,9 +186,6 @@ ufshci_attach(struct ufshci_softc *sc)
DPRINTF(1, " BI=0x%04x\n", UFSHCI_REG_HCMID_BI(sc->sc_hcmid));
DPRINTF(1, " MIC=0x%04x\n", UFSHCI_REG_HCMID_MIC(sc->sc_hcmid));
/* XXX: Using more than one slot currently causes OCS errors */
sc->sc_nutrs = 1;
if (sc->sc_nutrs > 32) {
printf("%s: NUTRS can't be >32 (is %d)!\n",
sc->sc_dev.dv_xname, sc->sc_nutrs);
@ -513,7 +510,7 @@ ufshci_utr_cmd_nop(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
ucd->cmd.hdr.tc = UPIU_TC_I2T_NOP_OUT;
ucd->cmd.hdr.flags = 0;
ucd->cmd.hdr.lun = 0;
ucd->cmd.hdr.taskid = 0;
ucd->cmd.hdr.task_tag = slot;
ucd->cmd.hdr.cmd_set_type = 0; /* SCSI command */
ucd->cmd.hdr.query = 0;
ucd->cmd.hdr.response = 0;
@ -603,7 +600,7 @@ ufshci_utr_cmd_lun(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
ucd->cmd.hdr.tc = UPIU_TC_I2T_COMMAND;
ucd->cmd.hdr.flags = (1 << 6); /* Bit-5 = Write, Bit-6 = Read */
ucd->cmd.hdr.lun = 0;
ucd->cmd.hdr.taskid = 0;
ucd->cmd.hdr.task_tag = slot;
ucd->cmd.hdr.cmd_set_type = 0; /* SCSI command */
ucd->cmd.hdr.query = 0;
ucd->cmd.hdr.response = 0;
@ -710,7 +707,7 @@ ufshci_utr_cmd_inquiry(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
ucd->cmd.hdr.tc = UPIU_TC_I2T_COMMAND;
ucd->cmd.hdr.flags = (1 << 6); /* Bit-5 = Write, Bit-6 = Read */
ucd->cmd.hdr.lun = 0;
ucd->cmd.hdr.taskid = 0;
ucd->cmd.hdr.task_tag = slot;
ucd->cmd.hdr.cmd_set_type = 0; /* SCSI command */
ucd->cmd.hdr.query = 0;
ucd->cmd.hdr.response = 0;
@ -815,7 +812,7 @@ ufshci_utr_cmd_capacity16(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
ucd->cmd.hdr.tc = UPIU_TC_I2T_COMMAND;
ucd->cmd.hdr.flags = (1 << 6); /* Bit-5 = Write, Bit-6 = Read */
ucd->cmd.hdr.lun = 0;
ucd->cmd.hdr.taskid = 0;
ucd->cmd.hdr.task_tag = slot;
ucd->cmd.hdr.cmd_set_type = 0; /* SCSI command */
ucd->cmd.hdr.query = 0;
ucd->cmd.hdr.response = 0;
@ -924,7 +921,7 @@ ufshci_utr_cmd_capacity(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
ucd->cmd.hdr.tc = UPIU_TC_I2T_COMMAND;
ucd->cmd.hdr.flags = (1 << 6); /* Bit-5 = Write, Bit-6 = Read */
ucd->cmd.hdr.lun = 0;
ucd->cmd.hdr.taskid = 0;
ucd->cmd.hdr.task_tag = slot;
ucd->cmd.hdr.cmd_set_type = 0; /* SCSI command */
ucd->cmd.hdr.query = 0;
ucd->cmd.hdr.response = 0;
@ -1003,6 +1000,8 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
struct ufshci_utrd *utrd;
struct ufshci_ucd *ucd;
bus_dmamap_t dmap = ccb->ccb_dmamap;
uint32_t blocks;
uint64_t lba;
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 1) */
slot = ccb->ccb_slot;
@ -1038,7 +1037,7 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
else
ucd->cmd.hdr.flags = (1 << 5); /* Bit-5 = Write */
ucd->cmd.hdr.lun = 0;
ucd->cmd.hdr.taskid = 0;
ucd->cmd.hdr.task_tag = slot;
ucd->cmd.hdr.cmd_set_type = 0; /* SCSI command */
ucd->cmd.hdr.query = 0;
ucd->cmd.hdr.response = 0;
@ -1047,7 +1046,16 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
ucd->cmd.hdr.device_info = 0;
ucd->cmd.hdr.ds_len = 0;
ucd->cmd.expected_xfer_len = htobe32(xs->datalen);
/*
* JESD220C-2_1.pdf, page 88, d) Expected Data Transfer Length:
* "When the COMMAND UPIU encodes a SCSI WRITE or SCSI READ command
* (specifically WRITE (6), READ (6), WRITE (10), READ (10),
* WRITE (16), or READ (16)), the value of this field shall be the
* product of the Logical Block Size (bLogicalBlockSize) and the
* TRANSFER LENGTH field of the CDB."
*/
scsi_cmd_rw_decode(&xs->cmd, &lba, &blocks);
ucd->cmd.expected_xfer_len = htobe32(UFSHCI_LBS * blocks);
memcpy(ucd->cmd.cdb, &xs->cmd, sizeof(ucd->cmd.cdb));
@ -1140,7 +1148,7 @@ ufshci_utr_cmd_sync(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
ucd->cmd.hdr.tc = UPIU_TC_I2T_COMMAND;
ucd->cmd.hdr.flags = 0; /* No data transfer */
ucd->cmd.hdr.lun = 0;
ucd->cmd.hdr.taskid = 0;
ucd->cmd.hdr.task_tag = slot;
ucd->cmd.hdr.cmd_set_type = 0; /* SCSI command */
ucd->cmd.hdr.query = 0;
ucd->cmd.hdr.response = 0;
@ -1207,16 +1215,19 @@ ufshci_xfer_complete(struct ufshci_softc *sc)
{
struct ufshci_ccb *ccb;
uint32_t reg;
int i;
int i, timeout;
mtx_enter(&sc->sc_cmd_mtx);
/* Wait for all commands to complete. */
while ((reg = ufshci_doorbell_read(sc))) {
DPRINTF(3, "%s: doorbell reg=0x%x\n", __func__, reg);
for (timeout = 5000; timeout != 0; timeout--) {
reg = ufshci_doorbell_read(sc);
if (reg == 0)
break;
delay(10);
}
if (timeout == 0)
printf("%s: timeout (reg=0x%x)\n", __func__, reg);
for (i = 0; i < sc->sc_nutrs; i++) {
ccb = &sc->sc_ccbs[i];

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ufshcireg.h,v 1.7 2024/05/09 08:20:22 mglocker Exp $ */
/* $OpenBSD: ufshcireg.h,v 1.9 2024/05/16 10:52:11 mglocker Exp $ */
/*
* Copyright (c) 2022 Marcus Glocker <mglocker@openbsd.org>
@ -21,8 +21,11 @@
*/
#define UFSHCI_UCD_PRDT_MAX_SEGS 64
#define UFSHCI_UCD_PRDT_MAX_XFER (UFSHCI_UCD_PRDT_MAX_SEGS * PAGE_SIZE)
#define UFSHCI_INTR_AGGR_TIMEOUT 0x64 /* 4ms */
#define UFSHCI_INTR_AGGR_TIMEOUT 0x08 /* 320us (1 unit = 40us) */
#define UFSHCI_MAX_UNITS 32
#define UFSHCI_LBS 4096 /* UFS Logical Block Size:
For UFS minimum size shall be
4096 bytes */
/*
* Controller Capabilities Registers
@ -335,7 +338,7 @@ struct upiu_hdr {
uint8_t tc; /* Transaction Code */
uint8_t flags;
uint8_t lun;
uint8_t taskid;
uint8_t task_tag;
uint8_t cmd_set_type;
uint8_t query;
uint8_t response;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ufshcivar.h,v 1.4 2024/05/09 08:06:42 mglocker Exp $ */
/* $OpenBSD: ufshcivar.h,v 1.5 2024/05/15 20:15:33 mglocker Exp $ */
/*
* Copyright (c) 2022 Marcus Glocker <mglocker@openbsd.org>
@ -68,7 +68,6 @@ struct ufshci_softc {
uint8_t sc_nutmrs;
uint8_t sc_rtt;
uint8_t sc_nutrs;
uint8_t sc_taskid;
struct ufshci_dmamem *sc_dmamem_utmrd;
struct ufshci_dmamem *sc_dmamem_utrd;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: azalia.c,v 1.286 2024/03/06 00:11:25 jsg Exp $ */
/* $OpenBSD: azalia.c,v 1.287 2024/05/17 19:43:45 kettenis Exp $ */
/* $NetBSD: azalia.c,v 1.20 2006/05/07 08:31:44 kent Exp $ */
/*-
@ -176,6 +176,7 @@ typedef struct azalia_t {
int nistreams, nostreams, nbstreams;
stream_t pstream;
stream_t rstream;
uint32_t intctl;
} azalia_t;
#define XNAME(sc) ((sc)->dev.dv_xname)
#define AZ_READ_1(z, r) bus_space_read_1((z)->iot, (z)->ioh, HDA_##r)
@ -556,16 +557,6 @@ azalia_pci_attach(struct device *parent, struct device *self, void *aux)
azalia_pci_write(sc->pc, sc->tag, ICH_PCI_MMC, reg);
}
/* disable MSI for AMD Summit Ridge/Raven Ridge HD Audio */
if (PCI_VENDOR(sc->pciid) == PCI_VENDOR_AMD) {
switch (PCI_PRODUCT(sc->pciid)) {
case PCI_PRODUCT_AMD_17_HDA:
case PCI_PRODUCT_AMD_17_1X_HDA:
case PCI_PRODUCT_AMD_HUDSON2_HDA:
pa->pa_flags &= ~PCI_FLAGS_MSI_ENABLED;
}
}
/* interrupt */
if (pci_intr_map_msi(pa, &ih) && pci_intr_map(pa, &ih)) {
printf(": can't map interrupt\n");
@ -684,7 +675,6 @@ azalia_pci_detach(struct device *self, int flags)
AZ_WRITE_4(az, INTCTL, 0);
DPRINTF(("%s: clear interrupts\n", __func__));
AZ_WRITE_4(az, INTSTS, HDA_INTSTS_CIS | HDA_INTSTS_GIS);
AZ_WRITE_2(az, STATESTS, HDA_STATESTS_SDIWAKE);
AZ_WRITE_1(az, RIRBSTS, HDA_RIRBSTS_RINTFL | HDA_RIRBSTS_RIRBOIS);
}
@ -711,29 +701,27 @@ azalia_intr(void *v)
int ret = 0;
mtx_enter(&audio_lock);
intsts = AZ_READ_4(az, INTSTS);
if (intsts == 0 || intsts == 0xffffffff) {
mtx_leave(&audio_lock);
return (ret);
}
for (;;) {
intsts = AZ_READ_4(az, INTSTS);
if ((intsts & az->intctl) == 0 || intsts == 0xffffffff)
break;
AZ_WRITE_4(az, INTSTS, intsts);
if (intsts & az->pstream.intr_bit) {
azalia_stream_intr(&az->pstream);
ret = 1;
}
if (intsts & az->pstream.intr_bit) {
azalia_stream_intr(&az->pstream);
ret = 1;
}
if (intsts & az->rstream.intr_bit) {
azalia_stream_intr(&az->rstream);
ret = 1;
}
if (intsts & az->rstream.intr_bit) {
azalia_stream_intr(&az->rstream);
ret = 1;
}
if ((intsts & HDA_INTSTS_CIS) &&
(AZ_READ_1(az, RIRBCTL) & HDA_RIRBCTL_RINTCTL) &&
(AZ_READ_1(az, RIRBSTS) & HDA_RIRBSTS_RINTFL)) {
azalia_rirb_intr(az);
ret = 1;
if ((intsts & HDA_INTSTS_CIS) &&
(AZ_READ_1(az, RIRBCTL) & HDA_RIRBCTL_RINTCTL) &&
(AZ_READ_1(az, RIRBSTS) & HDA_RIRBSTS_RINTFL)) {
azalia_rirb_intr(az);
ret = 1;
}
}
mtx_leave(&audio_lock);
return (ret);
@ -918,7 +906,6 @@ azalia_init(azalia_t *az, int resuming)
/* clear interrupt status */
AZ_WRITE_2(az, STATESTS, HDA_STATESTS_SDIWAKE);
AZ_WRITE_1(az, RIRBSTS, HDA_RIRBSTS_RINTFL | HDA_RIRBSTS_RIRBOIS);
AZ_WRITE_4(az, INTSTS, HDA_INTSTS_CIS | HDA_INTSTS_GIS);
AZ_WRITE_4(az, DPLBASE, 0);
AZ_WRITE_4(az, DPUBASE, 0);
@ -932,8 +919,8 @@ azalia_init(azalia_t *az, int resuming)
if (err)
return(err);
AZ_WRITE_4(az, INTCTL,
AZ_READ_4(az, INTCTL) | HDA_INTCTL_CIE | HDA_INTCTL_GIE);
az->intctl = HDA_INTCTL_CIE | HDA_INTCTL_GIE;
AZ_WRITE_4(az, INTCTL, az->intctl);
return(0);
}
@ -1421,7 +1408,6 @@ azalia_suspend(azalia_t *az)
/* stop interrupts and clear status registers */
AZ_WRITE_4(az, INTCTL, 0);
AZ_WRITE_4(az, INTSTS, HDA_INTSTS_CIS | HDA_INTSTS_GIS);
AZ_WRITE_2(az, STATESTS, HDA_STATESTS_SDIWAKE);
AZ_WRITE_1(az, RIRBSTS, HDA_RIRBSTS_RINTFL | HDA_RIRBSTS_RIRBOIS);
@ -3723,7 +3709,6 @@ azalia_stream_start(stream_t *this)
bdlist_entry_t *bdlist;
bus_addr_t dmaaddr, dmaend;
int err, index;
uint32_t intctl;
uint8_t ctl2;
err = azalia_stream_reset(this);
@ -3768,9 +3753,8 @@ azalia_stream_start(stream_t *this)
if (err)
return EINVAL;
intctl = AZ_READ_4(this->az, INTCTL);
intctl |= this->intr_bit;
AZ_WRITE_4(this->az, INTCTL, intctl);
this->az->intctl |= this->intr_bit;
AZ_WRITE_4(this->az, INTCTL, this->az->intctl);
STR_WRITE_1(this, CTL, STR_READ_1(this, CTL) |
HDA_SD_CTL_DEIE | HDA_SD_CTL_FEIE | HDA_SD_CTL_IOCE |
@ -3786,8 +3770,8 @@ azalia_stream_halt(stream_t *this)
ctl = STR_READ_2(this, CTL);
ctl &= ~(HDA_SD_CTL_DEIE | HDA_SD_CTL_FEIE | HDA_SD_CTL_IOCE | HDA_SD_CTL_RUN);
STR_WRITE_2(this, CTL, ctl);
AZ_WRITE_4(this->az, INTCTL,
AZ_READ_4(this->az, INTCTL) & ~this->intr_bit);
this->az->intctl &= ~this->intr_bit;
AZ_WRITE_4(this->az, INTCTL, this->az->intctl);
azalia_codec_disconnect_stream(this);
return (0);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: virtio_pci.c,v 1.36 2024/01/15 02:35:23 dv Exp $ */
/* $OpenBSD: virtio_pci.c,v 1.37 2024/05/17 16:37:10 sf Exp $ */
/* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */
/*
@ -72,6 +72,7 @@ void virtio_pci_write_device_config_4(struct virtio_softc *, int, uint32_t);
void virtio_pci_write_device_config_8(struct virtio_softc *, int, uint64_t);
uint16_t virtio_pci_read_queue_size(struct virtio_softc *, uint16_t);
void virtio_pci_setup_queue(struct virtio_softc *, struct virtqueue *, uint64_t);
int virtio_pci_get_status(struct virtio_softc *);
void virtio_pci_set_status(struct virtio_softc *, int);
int virtio_pci_negotiate_features(struct virtio_softc *, const struct virtio_feature_name *);
int virtio_pci_negotiate_features_10(struct virtio_softc *, const struct virtio_feature_name *);
@ -155,6 +156,7 @@ struct virtio_ops virtio_pci_ops = {
virtio_pci_write_device_config_8,
virtio_pci_read_queue_size,
virtio_pci_setup_queue,
virtio_pci_get_status,
virtio_pci_set_status,
virtio_pci_negotiate_features,
virtio_pci_poll_intr,
@ -275,6 +277,18 @@ virtio_pci_setup_queue(struct virtio_softc *vsc, struct virtqueue *vq,
}
}
int
virtio_pci_get_status(struct virtio_softc *vsc)
{
struct virtio_pci_softc *sc = (struct virtio_pci_softc *)vsc;
if (sc->sc_sc.sc_version_1)
return CREAD(sc, device_status);
else
return bus_space_read_1(sc->sc_iot, sc->sc_ioh,
VIRTIO_CONFIG_DEVICE_STATUS);
}
void
virtio_pci_set_status(struct virtio_softc *vsc, int status)
{

View file

@ -1,4 +1,4 @@
/* $OpenBSD: if_vio.c,v 1.33 2024/05/07 18:35:23 jan Exp $ */
/* $OpenBSD: if_vio.c,v 1.34 2024/05/17 16:37:10 sf Exp $ */
/*
* Copyright (c) 2012 Stefan Fritsch, Alexander Fiveg.
@ -252,6 +252,7 @@ struct vio_softc {
#define VIRTIO_NET_TX_MAXNSEGS 16 /* for larger chains, defrag */
#define VIRTIO_NET_CTRL_MAC_MC_ENTRIES 64 /* for more entries, use ALLMULTI */
#define VIRTIO_NET_CTRL_MAC_UC_ENTRIES 1 /* one entry for own unicast addr */
#define VIRTIO_NET_CTRL_TIMEOUT (5*1000*1000*1000ULL) /* 5 seconds */
#define VIO_CTRL_MAC_INFO_SIZE \
(2*sizeof(struct virtio_net_ctrl_mac_tbl) + \
@ -512,6 +513,17 @@ vio_put_lladdr(struct arpcom *ac, struct virtio_softc *vsc)
}
}
static int vio_needs_reset(struct vio_softc *sc)
{
if (virtio_get_status(sc->sc_virtio) &
VIRTIO_CONFIG_DEVICE_STATUS_DEVICE_NEEDS_RESET) {
printf("%s: device needs reset", sc->sc_dev.dv_xname);
vio_ctrl_wakeup(sc, RESET);
return 1;
}
return 0;
}
void
vio_attach(struct device *parent, struct device *self, void *aux)
{
@ -649,6 +661,7 @@ vio_config_change(struct virtio_softc *vsc)
{
struct vio_softc *sc = (struct vio_softc *)vsc->sc_child;
vio_link_state(&sc->sc_ac.ac_if);
vio_needs_reset(sc);
return 1;
}
@ -703,7 +716,7 @@ vio_stop(struct ifnet *ifp, int disable)
virtio_reset(vsc);
vio_rxeof(sc);
if (vsc->sc_nvqs >= 3)
vio_ctrleof(&sc->sc_vq[VQCTL]);
vio_ctrl_wakeup(sc, RESET);
vio_tx_drain(sc);
if (disable)
vio_rx_drain(sc);
@ -714,11 +727,8 @@ vio_stop(struct ifnet *ifp, int disable)
if (vsc->sc_nvqs >= 3)
virtio_start_vq_intr(vsc, &sc->sc_vq[VQCTL]);
virtio_reinit_end(vsc);
if (vsc->sc_nvqs >= 3) {
if (sc->sc_ctrl_inuse != FREE)
sc->sc_ctrl_inuse = RESET;
wakeup(&sc->sc_ctrl_inuse);
}
if (vsc->sc_nvqs >= 3)
vio_ctrl_wakeup(sc, FREE);
}
static inline uint16_t
@ -1230,6 +1240,9 @@ vio_txeof(struct virtqueue *vq)
int r = 0;
int slot, len;
if (!ISSET(ifp->if_flags, IFF_RUNNING))
return 0;
while (virtio_dequeue(vsc, vq, &slot, &len) == 0) {
struct virtio_net_hdr *hdr = &sc->sc_tx_hdrs[slot];
r++;
@ -1363,32 +1376,15 @@ out:
return r;
}
/*
* XXXSMP As long as some per-ifp ioctl(2)s are executed with the
* NET_LOCK() deadlocks are possible. So release it here.
*/
static inline int
vio_sleep(struct vio_softc *sc, const char *wmesg)
{
int status = rw_status(&netlock);
if (status != RW_WRITE && status != RW_READ)
return tsleep_nsec(&sc->sc_ctrl_inuse, PRIBIO|PCATCH, wmesg,
INFSLP);
return rwsleep_nsec(&sc->sc_ctrl_inuse, &netlock, PRIBIO|PCATCH, wmesg,
INFSLP);
}
int
vio_wait_ctrl(struct vio_softc *sc)
{
int r = 0;
while (sc->sc_ctrl_inuse != FREE) {
r = vio_sleep(sc, "viowait");
if (r == EINTR)
return r;
if (sc->sc_ctrl_inuse == RESET || vio_needs_reset(sc))
return ENXIO;
r = tsleep_nsec(&sc->sc_ctrl_inuse, PRIBIO, "viowait", INFSLP);
}
sc->sc_ctrl_inuse = INUSE;
@ -1400,14 +1396,16 @@ vio_wait_ctrl_done(struct vio_softc *sc)
{
int r = 0;
while (sc->sc_ctrl_inuse != DONE && sc->sc_ctrl_inuse != RESET) {
if (sc->sc_ctrl_inuse == RESET) {
r = 1;
break;
while (sc->sc_ctrl_inuse != DONE) {
if (sc->sc_ctrl_inuse == RESET || vio_needs_reset(sc))
return ENXIO;
r = tsleep_nsec(&sc->sc_ctrl_inuse, PRIBIO, "viodone",
VIRTIO_NET_CTRL_TIMEOUT);
if (r == EWOULDBLOCK) {
printf("%s: ctrl queue timeout", sc->sc_dev.dv_xname);
vio_ctrl_wakeup(sc, RESET);
return ENXIO;
}
r = vio_sleep(sc, "viodone");
if (r == EINTR)
break;
}
return r;
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: virtiovar.h,v 1.17 2024/05/13 01:15:51 jsg Exp $ */
/* $OpenBSD: virtiovar.h,v 1.18 2024/05/17 16:37:10 sf Exp $ */
/* $NetBSD: virtiovar.h,v 1.1 2011/10/30 12:12:21 hannken Exp $ */
/*
@ -154,6 +154,7 @@ struct virtio_ops {
void (*write_dev_cfg_8)(struct virtio_softc *, int, uint64_t);
uint16_t (*read_queue_size)(struct virtio_softc *, uint16_t);
void (*setup_queue)(struct virtio_softc *, struct virtqueue *, uint64_t);
int (*get_status)(struct virtio_softc *);
void (*set_status)(struct virtio_softc *, int);
int (*neg_features)(struct virtio_softc *, const struct virtio_feature_name *);
int (*poll_intr)(void *);
@ -197,9 +198,10 @@ struct virtio_softc {
#define virtio_setup_queue(sc, i, v) (sc)->sc_ops->setup_queue(sc, i, v)
#define virtio_negotiate_features(sc, n) (sc)->sc_ops->neg_features(sc, n)
#define virtio_poll_intr(sc) (sc)->sc_ops->poll_intr(sc)
#define virtio_get_status(sc) (sc)->sc_ops->get_status(sc)
#define virtio_set_status(sc, i) (sc)->sc_ops->set_status(sc, i)
/* only for transport drivers */
#define virtio_set_status(sc, i) (sc)->sc_ops->set_status(sc, i)
#define virtio_device_reset(sc) virtio_set_status((sc), 0)
static inline int

View file

@ -1,4 +1,4 @@
/* $OpenBSD: esp_sbus.c,v 1.26 2022/03/13 13:34:54 mpi Exp $ */
/* $OpenBSD: esp_sbus.c,v 1.27 2024/05/17 20:03:13 miod Exp $ */
/* $NetBSD: esp_sbus.c,v 1.14 2001/04/25 17:53:37 bouyer Exp $ */
/*-
@ -262,18 +262,14 @@ espattach_sbus(struct device *parent, struct device *self, void *aux)
/*
* Find the DMA by poking around the dma device structures
*
* What happens here is that if the dma driver has not been
* configured, then this returns a NULL pointer. Then when the
* dma actually gets configured, it does the opposing test, and
* if the sc->sc_esp field in its softc is NULL, then tries to
* find the matching esp driver.
* configured, then this returns a NULL pointer.
*/
esc->sc_dma = (struct lsi64854_softc *)
getdevunit("dma", sc->sc_dev.dv_unit - esp_unit_offset);
/*
* and a back pointer to us, for DMA
* add a back pointer to us, for DMA
*/
if (esc->sc_dma)
esc->sc_dma->sc_client = sc;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: wsmouse.c,v 1.71 2024/03/25 13:01:49 mvs Exp $ */
/* $OpenBSD: wsmouse.c,v 1.72 2024/05/17 20:11:58 miod Exp $ */
/* $NetBSD: wsmouse.c,v 1.35 2005/02/27 00:27:52 perry Exp $ */
/*
@ -1255,6 +1255,7 @@ wsmouse_matching(int *matrix, int m, int n, int *buffer)
for (; p < mc; *p++ = 0) {}
for (col = 0; col < n; col++) {
delta = INT_MAX;
row = 0;
for (i = 0, p = matrix + col; i < m; i++, p += n) {
d = *p - red[i];
if (d < delta || (d == delta && r2c[i] < 0)) {