Skip to content

Instantly share code, notes, and snippets.

@rokuyama
Created October 4, 2021 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rokuyama/72e261f74d8311cfbef9c701f60d5260 to your computer and use it in GitHub Desktop.
Save rokuyama/72e261f74d8311cfbef9c701f60d5260 to your computer and use it in GitHub Desktop.
Index: ata/ata.c
===================================================================
RCS file: /home/netbsd/src/sys/dev/ata/ata.c,v
retrieving revision 1.163
diff -p -u -r1.163 ata.c
--- ata/ata.c 29 Aug 2021 23:49:32 -0000 1.163
+++ ata/ata.c 3 Oct 2021 08:09:25 -0000
@@ -1231,10 +1231,11 @@ int
ata_xfer_start(struct ata_xfer *xfer)
{
struct ata_channel *chp = xfer->c_chp;
- int rv;
+ int rv, status;
KASSERT(mutex_owned(&chp->ch_lock));
+again:
rv = xfer->ops->c_start(chp, xfer);
switch (rv) {
case ATASTART_STARTED:
@@ -1248,8 +1249,10 @@ ata_xfer_start(struct ata_xfer *xfer)
/* can happen even in thread context for some ATAPI devices */
ata_channel_unlock(chp);
KASSERT(xfer->ops != NULL && xfer->ops->c_poll != NULL);
- xfer->ops->c_poll(chp, xfer);
+ status = xfer->ops->c_poll(chp, xfer);
ata_channel_lock(chp);
+ if (status == ATAPOLL_AGAIN)
+ goto again;
break;
case ATASTART_ABORT:
ata_channel_unlock(chp);
Index: ata/ata_wdc.c
===================================================================
RCS file: /home/netbsd/src/sys/dev/ata/ata_wdc.c,v
retrieving revision 1.119
diff -p -u -r1.119 ata_wdc.c
--- ata/ata_wdc.c 25 Dec 2020 08:55:40 -0000 1.119
+++ ata/ata_wdc.c 3 Oct 2021 08:10:52 -0000
@@ -105,7 +105,7 @@ extern int wdcdebug_wd_mask; /* inited i
static void wdc_ata_bio(struct ata_drive_datas*, struct ata_xfer *);
static int wdc_ata_bio_start(struct ata_channel *,struct ata_xfer *);
static int _wdc_ata_bio_start(struct ata_channel *,struct ata_xfer *);
-static void wdc_ata_bio_poll(struct ata_channel *,struct ata_xfer *);
+static int wdc_ata_bio_poll(struct ata_channel *,struct ata_xfer *);
static int wdc_ata_bio_intr(struct ata_channel *, struct ata_xfer *,
int);
static void wdc_ata_bio_kill_xfer(struct ata_channel *,
@@ -609,7 +609,7 @@ timeout:
return ATASTART_ABORT;
}
-static void
+static int
wdc_ata_bio_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
/* Wait for at last 400ns for status bit to be valid */
@@ -621,6 +621,7 @@ wdc_ata_bio_poll(struct ata_channel *chp
}
#endif
wdc_ata_bio_intr(chp, xfer, 0);
+ return (xfer->c_bio.flags & ATA_ITSDONE) ? ATAPOLL_DONE : ATAPOLL_AGAIN;
}
static int
Index: ata/atavar.h
===================================================================
RCS file: /home/netbsd/src/sys/dev/ata/atavar.h,v
retrieving revision 1.108
diff -p -u -r1.108 atavar.h
--- ata/atavar.h 25 May 2020 18:29:25 -0000 1.108
+++ ata/atavar.h 3 Oct 2021 08:11:55 -0000
@@ -178,7 +178,9 @@ struct ata_xfer_ops {
#define ATASTART_TH 1 /* xfer needs to be run in thread */
#define ATASTART_POLL 2 /* xfer needs to be polled */
#define ATASTART_ABORT 3 /* error occurred, abort xfer */
- void (*c_poll)(struct ata_channel *, struct ata_xfer *);
+ int (*c_poll)(struct ata_channel *, struct ata_xfer *);
+#define ATAPOLL_DONE 0
+#define ATAPOLL_AGAIN 1
void (*c_abort)(struct ata_channel *, struct ata_xfer *);
int (*c_intr)(struct ata_channel *, struct ata_xfer *, int);
void (*c_kill_xfer)(struct ata_channel *, struct ata_xfer *, int);
Index: ic/ahcisata_core.c
===================================================================
RCS file: /home/netbsd/src/sys/dev/ic/ahcisata_core.c,v
retrieving revision 1.101
diff -p -u -r1.101 ahcisata_core.c
--- ic/ahcisata_core.c 3 Sep 2021 01:23:33 -0000 1.101
+++ ic/ahcisata_core.c 3 Oct 2021 08:33:28 -0000
@@ -69,13 +69,13 @@ static void ahci_killpending(struct ata_
static int ahci_cmd_start(struct ata_channel *, struct ata_xfer *);
static int ahci_cmd_complete(struct ata_channel *, struct ata_xfer *, int);
-static void ahci_cmd_poll(struct ata_channel *, struct ata_xfer *);
+static int ahci_cmd_poll(struct ata_channel *, struct ata_xfer *);
static void ahci_cmd_abort(struct ata_channel *, struct ata_xfer *);
static void ahci_cmd_done(struct ata_channel *, struct ata_xfer *);
static void ahci_cmd_done_end(struct ata_channel *, struct ata_xfer *);
static void ahci_cmd_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
static int ahci_bio_start(struct ata_channel *, struct ata_xfer *);
-static void ahci_bio_poll(struct ata_channel *, struct ata_xfer *);
+static int ahci_bio_poll(struct ata_channel *, struct ata_xfer *);
static void ahci_bio_abort(struct ata_channel *, struct ata_xfer *);
static int ahci_bio_complete(struct ata_channel *, struct ata_xfer *, int);
static void ahci_bio_kill_xfer(struct ata_channel *, struct ata_xfer *, int) ;
@@ -93,7 +93,7 @@ static void ahci_atapi_minphys(struct bu
static void ahci_atapi_scsipi_request(struct scsipi_channel *,
scsipi_adapter_req_t, void *);
static int ahci_atapi_start(struct ata_channel *, struct ata_xfer *);
-static void ahci_atapi_poll(struct ata_channel *, struct ata_xfer *);
+static int ahci_atapi_poll(struct ata_channel *, struct ata_xfer *);
static void ahci_atapi_abort(struct ata_channel *, struct ata_xfer *);
static int ahci_atapi_complete(struct ata_channel *, struct ata_xfer *, int);
static void ahci_atapi_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
@@ -1208,7 +1208,7 @@ ahci_cmd_start(struct ata_channel *chp,
return ATASTART_POLL;
}
-static void
+static int
ahci_cmd_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
struct ahci_softc *sc = AHCI_CH2SC(chp);
@@ -1245,6 +1245,8 @@ ahci_cmd_poll(struct ata_channel *chp, s
}
/* reenable interrupts */
AHCI_WRITE(sc, AHCI_GHC, AHCI_READ(sc, AHCI_GHC) | AHCI_GHC_IE);
+
+ return ATAPOLL_DONE;
}
static void
@@ -1456,7 +1458,7 @@ ahci_bio_start(struct ata_channel *chp,
return ATASTART_POLL;
}
-static void
+static int
ahci_bio_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
@@ -1486,6 +1488,7 @@ ahci_bio_poll(struct ata_channel *chp, s
}
/* reenable interrupts */
AHCI_WRITE(sc, AHCI_GHC, AHCI_READ(sc, AHCI_GHC) | AHCI_GHC_IE);
+ return ATAPOLL_DONE;
}
static void
@@ -1953,7 +1956,7 @@ ahci_atapi_start(struct ata_channel *chp
return ATASTART_POLL;
}
-static void
+static int
ahci_atapi_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
@@ -1983,6 +1986,7 @@ ahci_atapi_poll(struct ata_channel *chp,
}
/* reenable interrupts */
AHCI_WRITE(sc, AHCI_GHC, AHCI_READ(sc, AHCI_GHC) | AHCI_GHC_IE);
+ return ATAPOLL_DONE;
}
static void
Index: ic/mvsata.c
===================================================================
RCS file: /home/netbsd/src/sys/dev/ic/mvsata.c,v
retrieving revision 1.60
diff -p -u -r1.60 mvsata.c
--- ic/mvsata.c 7 Aug 2021 16:19:12 -0000 1.60
+++ ic/mvsata.c 3 Oct 2021 08:36:10 -0000
@@ -143,14 +143,14 @@ static void mvsata_setup_channel(struct
#ifndef MVSATA_WITHOUTDMA
static int mvsata_bio_start(struct ata_channel *, struct ata_xfer *);
static int mvsata_bio_intr(struct ata_channel *, struct ata_xfer *, int);
-static void mvsata_bio_poll(struct ata_channel *, struct ata_xfer *);
+static int mvsata_bio_poll(struct ata_channel *, struct ata_xfer *);
static void mvsata_bio_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
static void mvsata_bio_done(struct ata_channel *, struct ata_xfer *);
static int mvsata_bio_ready(struct mvsata_port *, struct ata_bio *, int,
int);
static int mvsata_wdc_cmd_start(struct ata_channel *, struct ata_xfer *);
static int mvsata_wdc_cmd_intr(struct ata_channel *, struct ata_xfer *, int);
-static void mvsata_wdc_cmd_poll(struct ata_channel *, struct ata_xfer *);
+static int mvsata_wdc_cmd_poll(struct ata_channel *, struct ata_xfer *);
static void mvsata_wdc_cmd_kill_xfer(struct ata_channel *, struct ata_xfer *,
int);
static void mvsata_wdc_cmd_done(struct ata_channel *, struct ata_xfer *);
@@ -158,7 +158,7 @@ static void mvsata_wdc_cmd_done_end(stru
#if NATAPIBUS > 0
static int mvsata_atapi_start(struct ata_channel *, struct ata_xfer *);
static int mvsata_atapi_intr(struct ata_channel *, struct ata_xfer *, int);
-static void mvsata_atapi_poll(struct ata_channel *, struct ata_xfer *);
+static int mvsata_atapi_poll(struct ata_channel *, struct ata_xfer *);
static void mvsata_atapi_kill_xfer(struct ata_channel *, struct ata_xfer *,
int);
static void mvsata_atapi_reset(struct ata_channel *, struct ata_xfer *);
@@ -1245,7 +1245,7 @@ timeout:
return ATASTART_ABORT;
}
-static void
+static int
mvsata_bio_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
struct mvsata_port *mvport = (struct mvsata_port *)chp;
@@ -1259,10 +1259,9 @@ mvsata_bio_poll(struct ata_channel *chp,
chp->ch_flags &= ~ATACH_DMA_WAIT;
}
- if ((xfer->c_bio.flags & ATA_ITSDONE) == 0) {
- KASSERT(xfer->c_flags & C_TIMEOU);
- mvsata_bio_intr(chp, xfer, 0);
- }
+ mvsata_bio_intr(chp, xfer, 0);
+
+ return (xfer->c_bio.flags & ATA_ITSDONE) ? ATAPOLL_DONE : ATAPOLL_AGAIN;
}
static int
@@ -1680,7 +1679,7 @@ mvsata_wdc_cmd_start(struct ata_channel
return ATASTART_POLL;
}
-static void
+static int
mvsata_wdc_cmd_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
/*
@@ -1689,6 +1688,7 @@ mvsata_wdc_cmd_poll(struct ata_channel *
*/
delay(10); /* 400ns delay */
mvsata_wdc_cmd_intr(chp, xfer, 0);
+ return ATAPOLL_DONE;
}
static int
@@ -2165,7 +2165,7 @@ error:
return ATASTART_ABORT;
}
-static void
+static int
mvsata_atapi_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
/*
@@ -2180,7 +2180,7 @@ mvsata_atapi_poll(struct ata_channel *ch
mvsata_atapi_intr(chp, xfer, 0);
if (!poll)
- return;
+ return ATAPOLL_DONE;
if (chp->ch_flags & ATACH_DMA_WAIT) {
wdc_dmawait(chp, xfer, xfer->c_scsipi->timeout);
@@ -2192,6 +2192,8 @@ mvsata_atapi_poll(struct ata_channel *ch
DELAY(1);
mvsata_atapi_intr(chp, xfer, 0);
}
+
+ return ATAPOLL_DONE;
}
static int
Index: ic/siisata.c
===================================================================
RCS file: /home/netbsd/src/sys/dev/ic/siisata.c,v
retrieving revision 1.48
diff -p -u -r1.48 siisata.c
--- ic/siisata.c 7 Aug 2021 16:19:12 -0000 1.48
+++ ic/siisata.c 3 Oct 2021 08:37:41 -0000
@@ -149,7 +149,7 @@ void siisata_killpending(struct ata_driv
int siisata_cmd_start(struct ata_channel *, struct ata_xfer *);
int siisata_cmd_complete(struct ata_channel *, struct ata_xfer *, int);
-void siisata_cmd_poll(struct ata_channel *, struct ata_xfer *);
+int siisata_cmd_poll(struct ata_channel *, struct ata_xfer *);
void siisata_cmd_abort(struct ata_channel *, struct ata_xfer *);
void siisata_cmd_done(struct ata_channel *, struct ata_xfer *, int);
static void siisata_cmd_done_end(struct ata_channel *, struct ata_xfer *);
@@ -157,7 +157,7 @@ void siisata_cmd_kill_xfer(struct ata_ch
int siisata_bio_start(struct ata_channel *, struct ata_xfer *);
int siisata_bio_complete(struct ata_channel *, struct ata_xfer *, int);
-void siisata_bio_poll(struct ata_channel *, struct ata_xfer *);
+int siisata_bio_poll(struct ata_channel *, struct ata_xfer *);
void siisata_bio_abort(struct ata_channel *, struct ata_xfer *);
void siisata_bio_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
void siisata_exec_command(struct ata_drive_datas *, struct ata_xfer *);
@@ -175,7 +175,7 @@ void siisata_atapi_probe_device(struct a
void siisata_atapi_minphys(struct buf *);
int siisata_atapi_start(struct ata_channel *,struct ata_xfer *);
int siisata_atapi_complete(struct ata_channel *, struct ata_xfer *, int);
-void siisata_atapi_poll(struct ata_channel *, struct ata_xfer *);
+int siisata_atapi_poll(struct ata_channel *, struct ata_xfer *);
void siisata_atapi_abort(struct ata_channel *, struct ata_xfer *);
void siisata_atapi_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
void siisata_atapi_scsipi_request(struct scsipi_channel *,
@@ -1006,7 +1006,7 @@ siisata_cmd_start(struct ata_channel *ch
return ATASTART_POLL;
}
-void
+int
siisata_cmd_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
struct siisata_channel *schp = (struct siisata_channel *)chp;
@@ -1031,6 +1031,8 @@ siisata_cmd_poll(struct ata_channel *chp
SIISATA_DEBUG_PRINT(("%s: %s: done\n",
SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__),
DEBUG_FUNCS);
+
+ return ATAPOLL_DONE;
}
void
@@ -1233,7 +1235,7 @@ siisata_bio_start(struct ata_channel *ch
return ATASTART_POLL;
}
-void
+int
siisata_bio_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
struct siisata_channel *schp = (struct siisata_channel *)chp;
@@ -1257,6 +1259,8 @@ siisata_bio_poll(struct ata_channel *chp
SIISATA_DEBUG_PRINT(("%s: %s: done\n",
SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__),
DEBUG_FUNCS);
+
+ return ATAPOLL_DONE;
}
void
@@ -1835,7 +1839,7 @@ siisata_atapi_start(struct ata_channel *
return ATASTART_POLL;
}
-void
+int
siisata_atapi_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
struct siisata_channel *schp = (struct siisata_channel *)chp;
@@ -1858,6 +1862,8 @@ siisata_atapi_poll(struct ata_channel *c
SIISATA_DEBUG_PRINT(("%s: %s: done\n",
SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__),
DEBUG_FUNCS);
+
+ return ATAPOLL_DONE;
}
void
Index: ic/wdc.c
===================================================================
RCS file: /home/netbsd/src/sys/dev/ic/wdc.c,v
retrieving revision 1.307
diff -p -u -r1.307 wdc.c
--- ic/wdc.c 17 Sep 2021 10:15:35 -0000 1.307
+++ ic/wdc.c 3 Oct 2021 08:11:16 -0000
@@ -149,7 +149,7 @@ static int wdcreset(struct ata_channel *
static void __wdcerror(struct ata_channel *, const char *);
static int __wdcwait_reset(struct ata_channel *, int, int);
static void __wdccommand_done(struct ata_channel *, struct ata_xfer *);
-static void __wdccommand_poll(struct ata_channel *, struct ata_xfer *);
+static int __wdccommand_poll(struct ata_channel *, struct ata_xfer *);
static void __wdccommand_done_end(struct ata_channel *, struct ata_xfer *);
static void __wdccommand_kill_xfer(struct ata_channel *,
struct ata_xfer *, int);
@@ -1487,10 +1487,11 @@ __wdccommand_start(struct ata_channel *c
return ATASTART_POLL;
}
-static void
+static int
__wdccommand_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
__wdccommand_intr(chp, xfer, 0);
+ return ATAPOLL_DONE;
}
static int
Index: scsipi/atapi_wdc.c
===================================================================
RCS file: /home/netbsd/src/sys/dev/scsipi/atapi_wdc.c,v
retrieving revision 1.140
diff -p -u -r1.140 atapi_wdc.c
--- scsipi/atapi_wdc.c 7 Aug 2021 16:19:16 -0000 1.140
+++ scsipi/atapi_wdc.c 3 Oct 2021 08:34:20 -0000
@@ -90,7 +90,7 @@ static int wdc_atapi_intr(struct ata_cha
static void wdc_atapi_kill_xfer(struct ata_channel *,
struct ata_xfer *, int);
static void wdc_atapi_phase_complete(struct ata_xfer *, int);
-static void wdc_atapi_poll(struct ata_channel *, struct ata_xfer *);
+static int wdc_atapi_poll(struct ata_channel *, struct ata_xfer *);
static void wdc_atapi_done(struct ata_channel *, struct ata_xfer *);
static void wdc_atapi_reset(struct ata_channel *, struct ata_xfer *);
static void wdc_atapi_scsipi_request(struct scsipi_channel *,
@@ -696,7 +696,7 @@ error:
return ATASTART_ABORT;
}
-static void
+static int
wdc_atapi_poll(struct ata_channel *chp, struct ata_xfer *xfer)
{
/*
@@ -711,7 +711,7 @@ wdc_atapi_poll(struct ata_channel *chp,
wdc_atapi_intr(chp, xfer, 0);
if (!poll)
- return;
+ return ATAPOLL_DONE;
#if NATA_DMA
if (chp->ch_flags & ATACH_DMA_WAIT) {
@@ -724,6 +724,8 @@ wdc_atapi_poll(struct ata_channel *chp,
DELAY(1);
wdc_atapi_intr(chp, xfer, 0);
}
+
+ return ATAPOLL_DONE;
}
static int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment