-/* $OpenBSD: if_bwfm_pci.c,v 1.72 2022/10/23 13:45:32 kettenis Exp $ */
+/* $OpenBSD: if_bwfm_pci.c,v 1.73 2022/11/08 18:28:10 kettenis Exp $ */
/*
* Copyright (c) 2010-2016 Broadcom Corporation
* Copyright (c) 2017 Patrick Wildt <patrick@blueri.se>
uint8_t sc_mbdata_done;
uint8_t sc_pcireg64;
+ uint8_t sc_mb_via_ctl;
};
struct bwfm_pci_dmamem {
int, char *, size_t);
void bwfm_pci_msgbuf_rxioctl(struct bwfm_pci_softc *,
struct msgbuf_ioctl_resp_hdr *);
+int bwfm_pci_msgbuf_h2d_mb_write(struct bwfm_pci_softc *,
+ uint32_t);
struct bwfm_buscore_ops bwfm_pci_buscore_ops = {
.bc_read = bwfm_pci_buscore_read,
return 1;
}
+ if (sc->sc_shared_version >= 6) {
+ uint32_t host_cap;
+
+ if ((sc->sc_shared_flags & BWFM_SHARED_INFO_USE_MAILBOX) == 0)
+ sc->sc_mb_via_ctl = 1;
+
+ host_cap = sc->sc_shared_version;
+ if (sc->sc_shared_flags & BWFM_SHARED_INFO_HOSTRDY_DB1)
+ host_cap |= BWFM_SHARED_HOST_CAP_H2D_ENABLE_HOSTRDY;
+ if (sc->sc_shared_flags & BWFM_SHARED_INFO_SHARED_DAR)
+ host_cap |= BWFM_SHARED_HOST_CAP_H2D_DAR;
+ host_cap |= BWFM_SHARED_HOST_CAP_DS_NO_OOB_DW;
+
+ bus_space_write_4(sc->sc_tcm_iot, sc->sc_tcm_ioh,
+ sc->sc_shared_address + BWFM_SHARED_HOST_CAP, host_cap);
+ bus_space_write_4(sc->sc_tcm_iot, sc->sc_tcm_ioh,
+ sc->sc_shared_address + BWFM_SHARED_HOST_CAP2, 0);
+ }
+
sc->sc_dma_idx_sz = 0;
if (sc->sc_shared_flags & BWFM_SHARED_INFO_DMA_INDEX) {
if (sc->sc_shared_flags & BWFM_SHARED_INFO_DMA_2B_IDX)
bwfm_pci_ring_bell(struct bwfm_pci_softc *sc,
struct bwfm_pci_msgring *ring)
{
- if (sc->sc_pcireg64)
+ if (sc->sc_shared_flags & BWFM_SHARED_INFO_SHARED_DAR)
bus_space_write_4(sc->sc_reg_iot, sc->sc_reg_ioh,
BWFM_PCI_64_PCIE2REG_H2D_MAILBOX_0, 1);
else
struct msgbuf_tx_status *tx;
struct msgbuf_rx_complete *rx;
struct msgbuf_rx_event *event;
+ struct msgbuf_d2h_mailbox_data *d2h;
struct msgbuf_common_hdr *msg;
struct msgbuf_flowring_create_resp *fcr;
struct msgbuf_flowring_delete_resp *fdr;
if_rxr_put(&sc->sc_rxbuf_ring, 1);
bwfm_pci_fill_rx_rings(sc);
break;
+ case MSGBUF_TYPE_D2H_MAILBOX_DATA:
+ d2h = (struct msgbuf_d2h_mailbox_data *)buf;
+ if (d2h->data & BWFM_PCI_D2H_DEV_D3_ACK) {
+ sc->sc_mbdata_done = 1;
+ wakeup(&sc->sc_mbdata_done);
+ }
+ break;
default:
printf("%s: msgtype 0x%08x\n", __func__, msg->msgtype);
break;
bwfm_pci_ring_write_commit(sc, &sc->sc_ctrl_submit);
splx(s);
+
+ tsleep_nsec(ring, PCATCH, DEVNAME(sc), SEC_TO_NSEC(2));
+ if (ring->status != RING_CLOSED)
+ printf("%s: flowring not closing\n", DEVNAME(sc));
}
void
ring = &sc->sc_flowrings[cmd->flowid];
bwfm_pci_dmamem_free(sc, ring->ring);
ring->status = RING_CLOSED;
+ wakeup(ring);
}
void
uint32_t reg;
int i;
+ if (sc->sc_mb_via_ctl)
+ return bwfm_pci_msgbuf_h2d_mb_write(sc, htod_mb_data);
+
for (i = 0; i < 100; i++) {
reg = bus_space_read_4(sc->sc_tcm_iot, sc->sc_tcm_ioh,
sc->sc_htod_mb_data_addr);
if ((sc->sc_shared_flags & BWFM_SHARED_INFO_HOSTRDY_DB1) == 0)
return;
- if (sc->sc_pcireg64)
+ if (sc->sc_shared_flags & BWFM_SHARED_INFO_SHARED_DAR)
bus_space_write_4(sc->sc_reg_iot, sc->sc_reg_ioh,
BWFM_PCI_64_PCIE2REG_H2D_MAILBOX_1, 1);
else
m_freem(m);
}
+
+int
+bwfm_pci_msgbuf_h2d_mb_write(struct bwfm_pci_softc *sc, uint32_t data)
+{
+ struct msgbuf_h2d_mailbox_data *req;
+ int s;
+
+ s = splnet();
+ req = bwfm_pci_ring_write_reserve(sc, &sc->sc_ctrl_submit);
+ if (req == NULL) {
+ splx(s);
+ return ENOBUFS;
+ }
+
+ req->msg.msgtype = MSGBUF_TYPE_H2D_MAILBOX_DATA;
+ req->msg.ifidx = -1;
+ req->msg.flags = 0;
+ req->msg.request_id = 0;
+ req->data = data;
+
+ bwfm_pci_ring_write_commit(sc, &sc->sc_ctrl_submit);
+ splx(s);
+
+ return 0;
+}
-/* $OpenBSD: if_bwfm_pci.h,v 1.8 2021/12/31 09:24:18 patrick Exp $ */
+/* $OpenBSD: if_bwfm_pci.h,v 1.9 2022/11/08 18:28:10 kettenis Exp $ */
/*
* Copyright (c) 2010-2016 Broadcom Corporation
* Copyright (c) 2017 Patrick Wildt <patrick@blueri.se>
#define BWFM_SHARED_INFO_VERSION_MASK 0x00FF
#define BWFM_SHARED_INFO_DMA_INDEX 0x10000
#define BWFM_SHARED_INFO_DMA_2B_IDX 0x100000
+#define BWFM_SHARED_INFO_USE_MAILBOX 0x2000000
+#define BWFM_SHARED_INFO_TIMESTAMP_DB0 0x8000000
#define BWFM_SHARED_INFO_HOSTRDY_DB1 0x10000000
+#define BWFM_SHARED_INFO_NO_OOB_DW 0x20000000
+#define BWFM_SHARED_INFO_INBAND_DS 0x40000000
+#define BWFM_SHARED_INFO_SHARED_DAR 0x80000000
#define BWFM_SHARED_CONSOLE_ADDR 0x14
#define BWFM_SHARED_MAX_RXBUFPOST 0x22
#define BWFM_SHARED_MAX_RXBUFPOST_DEFAULT 255
#define BWFM_SHARED_DMA_RINGUPD_LEN 0x40
#define BWFM_SHARED_DMA_RINGUPD_ADDR_LOW 0x44
#define BWFM_SHARED_DMA_RINGUPD_ADDR_HIGH 0x48
+#define BWFM_SHARED_HOST_CAP 0x54
+#define BWFM_SHARED_HOST_CAP_H2D_ENABLE_HOSTRDY 0x00000400
+#define BWFM_SHARED_HOST_CAP_DS_NO_OOB_DW 0x00001000
+#define BWFM_SHARED_HOST_CAP_H2D_DAR 0x00010000
+#define BWFM_SHARED_HOST_CAP2 0x70
#define BWFM_RING_MAX_ITEM 0x04
#define BWFM_RING_LEN_ITEMS 0x06
#define MSGBUF_TYPE_RX_CMPLT 0x12
#define MSGBUF_TYPE_LPBK_DMAXFER 0x13
#define MSGBUF_TYPE_LPBK_DMAXFER_CMPLT 0x14
+#define MSGBUF_TYPE_H2D_MAILBOX_DATA 0x23
+#define MSGBUF_TYPE_D2H_MAILBOX_DATA 0x24
struct msgbuf_common_hdr {
uint8_t msgtype;
struct msgbuf_completion_hdr compl_hdr;
uint32_t rsvd0[3];
};
+
+struct msgbuf_h2d_mailbox_data {
+ struct msgbuf_common_hdr msg;
+ uint32_t data;
+ uint32_t rsvd0[7];
+};
+
+struct msgbuf_d2h_mailbox_data {
+ struct msgbuf_common_hdr msg;
+ struct msgbuf_completion_hdr compl_hdr;
+ uint32_t data;
+ uint32_t rsvd0[2];
+};