Home | History | Annotate | Line # | Download | only in mscp
mscp.c revision 1.29.4.1
      1  1.29.4.1      yamt /*	$NetBSD: mscp.c,v 1.29.4.1 2009/05/04 08:12:53 yamt Exp $	*/
      2       1.1     ragge 
      3       1.1     ragge /*
      4       1.1     ragge  * Copyright (c) 1988 Regents of the University of California.
      5       1.1     ragge  * All rights reserved.
      6       1.1     ragge  *
      7       1.1     ragge  * This code is derived from software contributed to Berkeley by
      8       1.1     ragge  * Chris Torek.
      9       1.1     ragge  *
     10       1.1     ragge  * Redistribution and use in source and binary forms, with or without
     11       1.1     ragge  * modification, are permitted provided that the following conditions
     12       1.1     ragge  * are met:
     13       1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     14       1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     15       1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     17       1.1     ragge  *    documentation and/or other materials provided with the distribution.
     18      1.20       agc  * 3. Neither the name of the University nor the names of its contributors
     19      1.20       agc  *    may be used to endorse or promote products derived from this software
     20      1.20       agc  *    without specific prior written permission.
     21      1.20       agc  *
     22      1.20       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23      1.20       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24      1.20       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25      1.20       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26      1.20       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27      1.20       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28      1.20       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29      1.20       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30      1.20       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31      1.20       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32      1.20       agc  * SUCH DAMAGE.
     33      1.20       agc  *
     34      1.20       agc  *	@(#)mscp.c	7.5 (Berkeley) 12/16/90
     35      1.20       agc  */
     36      1.20       agc 
     37      1.20       agc /*
     38      1.20       agc  * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
     39      1.20       agc  *
     40      1.20       agc  * This code is derived from software contributed to Berkeley by
     41      1.20       agc  * Chris Torek.
     42      1.20       agc  *
     43      1.20       agc  * Redistribution and use in source and binary forms, with or without
     44      1.20       agc  * modification, are permitted provided that the following conditions
     45      1.20       agc  * are met:
     46      1.20       agc  * 1. Redistributions of source code must retain the above copyright
     47      1.20       agc  *    notice, this list of conditions and the following disclaimer.
     48      1.20       agc  * 2. Redistributions in binary form must reproduce the above copyright
     49      1.20       agc  *    notice, this list of conditions and the following disclaimer in the
     50      1.20       agc  *    documentation and/or other materials provided with the distribution.
     51       1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     52       1.1     ragge  *    must display the following acknowledgement:
     53       1.1     ragge  *	This product includes software developed by the University of
     54       1.1     ragge  *	California, Berkeley and its contributors.
     55       1.1     ragge  * 4. Neither the name of the University nor the names of its contributors
     56       1.1     ragge  *    may be used to endorse or promote products derived from this software
     57       1.1     ragge  *    without specific prior written permission.
     58       1.1     ragge  *
     59       1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60       1.1     ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61       1.1     ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62       1.1     ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63       1.1     ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64       1.1     ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65       1.1     ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66       1.1     ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67       1.1     ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68       1.1     ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69       1.1     ragge  * SUCH DAMAGE.
     70       1.1     ragge  *
     71       1.1     ragge  *	@(#)mscp.c	7.5 (Berkeley) 12/16/90
     72       1.1     ragge  */
     73       1.1     ragge 
     74       1.1     ragge /*
     75       1.1     ragge  * MSCP generic driver routines
     76       1.1     ragge  */
     77      1.16     lukem 
     78      1.16     lukem #include <sys/cdefs.h>
     79  1.29.4.1      yamt __KERNEL_RCSID(0, "$NetBSD: mscp.c,v 1.29.4.1 2009/05/04 08:12:53 yamt Exp $");
     80       1.1     ragge 
     81       1.1     ragge #include <sys/param.h>
     82       1.1     ragge #include <sys/buf.h>
     83      1.21        he #include <sys/bufq.h>
     84      1.18    simonb #include <sys/kernel.h>
     85       1.1     ragge #include <sys/malloc.h>
     86       1.1     ragge #include <sys/device.h>
     87       1.8     ragge #include <sys/proc.h>
     88       1.8     ragge #include <sys/systm.h>
     89       1.1     ragge 
     90      1.27        ad #include <sys/bus.h>
     91      1.11     ragge 
     92      1.11     ragge #include <dev/mscp/mscp.h>
     93      1.11     ragge #include <dev/mscp/mscpreg.h>
     94      1.11     ragge #include <dev/mscp/mscpvar.h>
     95       1.1     ragge 
     96       1.7     ragge #define PCMD	PSWP		/* priority for command packet waits */
     97       1.1     ragge 
     98       1.1     ragge /*
     99       1.1     ragge  * Get a command packet.  Second argument is true iff we are
    100       1.1     ragge  * to wait if necessary.  Return NULL if none are available and
    101       1.1     ragge  * we cannot wait.
    102       1.1     ragge  */
    103       1.1     ragge struct mscp *
    104  1.29.4.1      yamt mscp_getcp(struct mscp_softc *mi, int canwait)
    105       1.1     ragge {
    106       1.7     ragge #define mri	(&mi->mi_cmd)
    107      1.12  augustss 	struct mscp *mp;
    108      1.12  augustss 	int i;
    109      1.15   thorpej 	int s = spluba();
    110       1.1     ragge 
    111       1.1     ragge again:
    112       1.1     ragge 	/*
    113       1.1     ragge 	 * Ensure that we have some command credits, and
    114       1.1     ragge 	 * that the next command packet is free.
    115       1.1     ragge 	 */
    116       1.1     ragge 	if (mi->mi_credits <= MSCP_MINCREDITS) {
    117       1.1     ragge 		if (!canwait) {
    118       1.1     ragge 			splx(s);
    119       1.1     ragge 			return (NULL);
    120       1.1     ragge 		}
    121       1.1     ragge 		mi->mi_wantcredits = 1;
    122      1.13   thorpej 		(void) tsleep(&mi->mi_wantcredits, PCMD, "mscpwcrd", 0);
    123       1.1     ragge 		goto again;
    124       1.1     ragge 	}
    125       1.1     ragge 	i = mri->mri_next;
    126       1.1     ragge 	if (mri->mri_desc[i] & MSCP_OWN) {
    127       1.1     ragge 		if (!canwait) {
    128       1.1     ragge 			splx(s);
    129       1.1     ragge 			return (NULL);
    130       1.1     ragge 		}
    131       1.1     ragge 		mi->mi_wantcmd = 1;
    132      1.13   thorpej 		(void) tsleep(&mi->mi_wantcmd, PCMD, "mscpwcmd", 0);
    133       1.1     ragge 		goto again;
    134       1.1     ragge 	}
    135       1.1     ragge 	mi->mi_credits--;
    136       1.1     ragge 	mri->mri_desc[i] &= ~MSCP_INT;
    137       1.1     ragge 	mri->mri_next = (mri->mri_next + 1) % mri->mri_size;
    138       1.1     ragge 	splx(s);
    139       1.1     ragge 	mp = &mri->mri_ring[i];
    140       1.1     ragge 
    141       1.1     ragge 	/*
    142       1.1     ragge 	 * Initialise some often-zero fields.
    143       1.1     ragge 	 * ARE THE LAST TWO NECESSARY IN GENERAL?  IT SURE WOULD BE
    144       1.1     ragge 	 * NICE IF DEC SOLD DOCUMENTATION FOR THEIR OWN CONTROLLERS.
    145       1.1     ragge 	 */
    146       1.1     ragge 	mp->mscp_msglen = MSCP_MSGLEN;
    147       1.1     ragge 	mp->mscp_flags = 0;
    148       1.1     ragge 	mp->mscp_modifier = 0;
    149       1.1     ragge 	mp->mscp_seq.seq_bytecount = 0;
    150       1.1     ragge 	mp->mscp_seq.seq_buffer = 0;
    151       1.1     ragge 	mp->mscp_seq.seq_mapbase = 0;
    152       1.7     ragge /*???*/ mp->mscp_sccc.sccc_errlgfl = 0;
    153       1.7     ragge /*???*/ mp->mscp_sccc.sccc_copyspd = 0;
    154       1.1     ragge 	return (mp);
    155       1.1     ragge #undef	mri
    156       1.1     ragge }
    157       1.1     ragge 
    158       1.1     ragge #ifdef AVOID_EMULEX_BUG
    159       1.1     ragge int	mscp_aeb_xor = 0x8000bb80;
    160       1.1     ragge #endif
    161       1.1     ragge 
    162       1.1     ragge /*
    163       1.1     ragge  * Handle a response ring transition.
    164       1.1     ragge  */
    165       1.1     ragge void
    166  1.29.4.1      yamt mscp_dorsp(struct mscp_softc *mi)
    167       1.1     ragge {
    168       1.1     ragge 	struct device *drive;
    169       1.1     ragge 	struct mscp_device *me = mi->mi_me;
    170       1.1     ragge 	struct mscp_ctlr *mc = mi->mi_mc;
    171      1.11     ragge 	struct buf *bp;
    172      1.11     ragge 	struct mscp *mp;
    173      1.11     ragge 	struct mscp_xi *mxi;
    174      1.11     ragge 	int nextrsp;
    175      1.11     ragge 	int st, error;
    176       1.1     ragge 	extern struct mscp slavereply;
    177       1.1     ragge 
    178       1.1     ragge 	nextrsp = mi->mi_rsp.mri_next;
    179       1.1     ragge loop:
    180       1.1     ragge 	if (mi->mi_rsp.mri_desc[nextrsp] & MSCP_OWN) {
    181       1.1     ragge 		/*
    182       1.1     ragge 		 * No more responses.  Remember the next expected
    183       1.1     ragge 		 * response index.  Check to see if we have some
    184       1.1     ragge 		 * credits back, and wake up sleepers if so.
    185       1.1     ragge 		 */
    186       1.1     ragge 		mi->mi_rsp.mri_next = nextrsp;
    187       1.1     ragge 		if (mi->mi_wantcredits && mi->mi_credits > MSCP_MINCREDITS) {
    188       1.1     ragge 			mi->mi_wantcredits = 0;
    189      1.25  christos 			wakeup((void *) &mi->mi_wantcredits);
    190       1.1     ragge 		}
    191       1.1     ragge 		return;
    192       1.1     ragge 	}
    193       1.1     ragge 
    194       1.1     ragge 	mp = &mi->mi_rsp.mri_ring[nextrsp];
    195       1.1     ragge 	mi->mi_credits += MSCP_CREDITS(mp->mscp_msgtc);
    196       1.1     ragge 	/*
    197       1.1     ragge 	 * Controllers are allowed to interrupt as any drive, so we
    198       1.1     ragge 	 * must check the command before checking for a drive.
    199       1.1     ragge 	 */
    200       1.1     ragge 	if (mp->mscp_opcode == (M_OP_SETCTLRC | M_OP_END)) {
    201       1.1     ragge 		if ((mp->mscp_status & M_ST_MASK) == M_ST_SUCCESS) {
    202       1.1     ragge 			mi->mi_flags |= MSC_READY;
    203       1.1     ragge 		} else {
    204       1.4  christos 			printf("%s: SETCTLRC failed: %d ",
    205      1.29    cegger 			    device_xname(&mi->mi_dev), mp->mscp_status);
    206       1.1     ragge 			mscp_printevent(mp);
    207       1.1     ragge 		}
    208       1.1     ragge 		goto done;
    209       1.1     ragge 	}
    210       1.1     ragge 
    211       1.1     ragge 	/*
    212       1.1     ragge 	 * Found a response.  Update credit information.  If there is
    213       1.1     ragge 	 * nothing else to do, jump to `done' to get the next response.
    214       1.1     ragge 	 */
    215       1.2     ragge 	if (mp->mscp_unit >= mi->mi_driveno) { /* Must expand drive table */
    216      1.19      matt 		int tmpno = (mp->mscp_unit + 32) & ~31;
    217       1.2     ragge 		struct device **tmp = (struct device **)
    218      1.19      matt 		    malloc(tmpno * sizeof(tmp[0]), M_DEVBUF, M_NOWAIT|M_ZERO);
    219      1.19      matt 		/* XXX tmp should be checked for NULL */
    220       1.2     ragge 		if (mi->mi_driveno) {
    221      1.19      matt 			memcpy(tmp, mi->mi_dp, mi->mi_driveno * sizeof(tmp[0]));
    222      1.19      matt 			free(mi->mi_dp, M_DEVBUF);
    223       1.2     ragge 		}
    224       1.2     ragge 		mi->mi_driveno = tmpno;
    225       1.2     ragge 		mi->mi_dp = tmp;
    226       1.2     ragge 	}
    227       1.2     ragge 
    228       1.1     ragge 	drive = mi->mi_dp[mp->mscp_unit];
    229       1.1     ragge 
    230       1.1     ragge 	switch (MSCP_MSGTYPE(mp->mscp_msgtc)) {
    231       1.1     ragge 
    232       1.1     ragge 	case MSCPT_SEQ:
    233       1.1     ragge 		break;
    234       1.1     ragge 
    235       1.1     ragge 	case MSCPT_DATAGRAM:
    236       1.2     ragge 		(*me->me_dgram)(drive, mp, mi);
    237       1.1     ragge 		goto done;
    238       1.1     ragge 
    239       1.1     ragge 	case MSCPT_CREDITS:
    240       1.1     ragge 		goto done;
    241       1.1     ragge 
    242       1.1     ragge 	case MSCPT_MAINTENANCE:
    243       1.1     ragge 	default:
    244       1.4  christos 		printf("%s: unit %d: unknown message type 0x%x ignored\n",
    245      1.29    cegger 			device_xname(&mi->mi_dev), mp->mscp_unit,
    246       1.1     ragge 			MSCP_MSGTYPE(mp->mscp_msgtc));
    247       1.1     ragge 		goto done;
    248       1.1     ragge 	}
    249       1.1     ragge 
    250       1.1     ragge 	/*
    251       1.1     ragge 	 * Handle individual responses.
    252       1.1     ragge 	 */
    253       1.1     ragge 	st = mp->mscp_status & M_ST_MASK;
    254       1.1     ragge 	error = 0;
    255       1.1     ragge 	switch (mp->mscp_opcode) {
    256       1.1     ragge 
    257       1.1     ragge 	case M_OP_END:
    258       1.1     ragge 		/*
    259       1.1     ragge 		 * The controller presents a bogus END packet when
    260       1.1     ragge 		 * a read/write command is given with an illegal
    261       1.1     ragge 		 * block number.  This is contrary to the MSCP
    262       1.1     ragge 		 * specification (ENDs are to be given only for
    263       1.1     ragge 		 * invalid commands), but that is the way of it.
    264       1.1     ragge 		 */
    265       1.1     ragge 		if (st == M_ST_INVALCMD && mp->mscp_cmdref != 0) {
    266      1.29    cegger 			printf("%s: bad lbn (%d)?\n", device_xname(drive),
    267       1.1     ragge 				(int)mp->mscp_seq.seq_lbn);
    268       1.1     ragge 			error = EIO;
    269       1.1     ragge 			goto rwend;
    270       1.1     ragge 		}
    271       1.1     ragge 		goto unknown;
    272       1.1     ragge 
    273       1.1     ragge 	case M_OP_ONLINE | M_OP_END:
    274       1.1     ragge 		/*
    275       1.7     ragge 		 * Finished an ON LINE request.	 Call the driver to
    276       1.1     ragge 		 * find out whether it succeeded.  If so, mark it on
    277       1.1     ragge 		 * line.
    278       1.1     ragge 		 */
    279       1.1     ragge 		(*me->me_online)(drive, mp);
    280       1.1     ragge 		break;
    281       1.1     ragge 
    282       1.1     ragge 	case M_OP_GETUNITST | M_OP_END:
    283       1.1     ragge 		/*
    284       1.1     ragge 		 * Got unit status.  If we are autoconfiguring, save
    285       1.1     ragge 		 * the mscp struct so that mscp_attach know what to do.
    286       1.1     ragge 		 * If the drive isn't configured, call config_found()
    287       1.1     ragge 		 * to set it up, otherwise it's just a "normal" unit
    288       1.1     ragge 		 * status.
    289       1.1     ragge 		 */
    290       1.1     ragge 		if (cold)
    291  1.29.4.1      yamt 			memcpy(&slavereply, mp, sizeof(struct mscp));
    292       1.1     ragge 
    293       1.2     ragge 		if (mp->mscp_status == (M_ST_OFFLINE|M_OFFLINE_UNKNOWN))
    294       1.2     ragge 			break;
    295       1.2     ragge 
    296       1.1     ragge 		if (drive == 0) {
    297  1.29.4.1      yamt 			struct mscp_work *mw;
    298       1.1     ragge 
    299  1.29.4.1      yamt 			mutex_spin_enter(&mi->mi_mtx);
    300  1.29.4.1      yamt 
    301  1.29.4.1      yamt 			mw = SLIST_FIRST(&mi->mi_freelist);
    302  1.29.4.1      yamt 			if (mw == NULL) {
    303  1.29.4.1      yamt 				aprint_error_dev(&mi->mi_dev,
    304  1.29.4.1      yamt 				    "couldn't attach drive (no free items)\n");
    305  1.29.4.1      yamt 				mutex_spin_exit(&mi->mi_mtx);
    306  1.29.4.1      yamt 			} else {
    307  1.29.4.1      yamt 				SLIST_REMOVE_HEAD(&mi->mi_freelist, mw_list);
    308  1.29.4.1      yamt 				mutex_spin_exit(&mi->mi_mtx);
    309  1.29.4.1      yamt 
    310  1.29.4.1      yamt 				mw->mw_mi = mi;
    311  1.29.4.1      yamt 				mw->mw_mp = *mp;
    312  1.29.4.1      yamt 				workqueue_enqueue(mi->mi_wq,
    313  1.29.4.1      yamt 				    (struct work *)mw, NULL);
    314  1.29.4.1      yamt 			}
    315       1.1     ragge 		} else
    316       1.2     ragge 			/* Hack to avoid complaints */
    317       1.2     ragge 			if (!(((mp->mscp_event & M_ST_MASK) == M_ST_AVAILABLE)
    318       1.2     ragge 			    && cold))
    319       1.2     ragge 				(*me->me_gotstatus)(drive, mp);
    320       1.1     ragge 		break;
    321       1.1     ragge 
    322       1.1     ragge 	case M_OP_AVAILATTN:
    323       1.1     ragge 		/*
    324       1.1     ragge 		 * The drive went offline and we did not notice.
    325       1.1     ragge 		 * Mark it off line now, to force an on line request
    326       1.1     ragge 		 * next, so we can make sure it is still the same
    327       1.1     ragge 		 * drive.
    328       1.1     ragge 		 *
    329       1.1     ragge 		 * IF THE UDA DRIVER HAS A COMMAND AWAITING UNIBUS
    330       1.1     ragge 		 * RESOURCES, THAT COMMAND MAY GO OUT BEFORE THE ON
    331       1.1     ragge 		 * LINE.  IS IT WORTH FIXING??
    332       1.1     ragge 		 */
    333       1.1     ragge #ifdef notyet
    334       1.1     ragge 		(*md->md_offline)(ui, mp);
    335       1.1     ragge #endif
    336       1.1     ragge 		break;
    337       1.1     ragge 
    338       1.2     ragge 	case M_OP_POS | M_OP_END:
    339       1.2     ragge 	case M_OP_WRITM | M_OP_END:
    340       1.9     ragge 	case M_OP_AVAILABLE | M_OP_END:
    341       1.2     ragge 		/*
    342       1.2     ragge 		 * A non-data transfer operation completed.
    343       1.2     ragge 		 */
    344       1.2     ragge 		(*me->me_cmddone)(drive, mp);
    345       1.2     ragge 		break;
    346       1.2     ragge 
    347       1.1     ragge 	case M_OP_READ | M_OP_END:
    348       1.1     ragge 	case M_OP_WRITE | M_OP_END:
    349       1.1     ragge 		/*
    350       1.7     ragge 		 * A transfer finished.	 Get the buffer, and release its
    351       1.7     ragge 		 * map registers via ubadone().	 If the command finished
    352       1.1     ragge 		 * with an off line or available status, the drive went
    353       1.1     ragge 		 * off line (the idiot controller does not tell us until
    354       1.1     ragge 		 * it comes back *on* line, or until we try to use it).
    355       1.1     ragge 		 */
    356       1.6     ragge rwend:
    357       1.5     ragge #ifdef DIAGNOSTIC
    358      1.11     ragge 		if (mp->mscp_cmdref >= NCMD) {
    359       1.1     ragge 			/*
    360       1.1     ragge 			 * No buffer means there is a bug somewhere!
    361       1.1     ragge 			 */
    362      1.11     ragge 			printf("%s: io done, but bad xfer number?\n",
    363      1.29    cegger 			    device_xname(drive));
    364       1.1     ragge 			mscp_hexdump(mp);
    365       1.1     ragge 			break;
    366       1.1     ragge 		}
    367       1.5     ragge #endif
    368       1.1     ragge 
    369       1.6     ragge 		if (mp->mscp_cmdref == -1) {
    370       1.6     ragge 			(*me->me_cmddone)(drive, mp);
    371       1.6     ragge 			break;
    372       1.6     ragge 		}
    373      1.11     ragge 		mxi = &mi->mi_xi[mp->mscp_cmdref];
    374      1.11     ragge 		if (mxi->mxi_inuse == 0)
    375      1.11     ragge 			panic("mxi not inuse");
    376      1.11     ragge 		bp = mxi->mxi_bp;
    377       1.1     ragge 		/*
    378       1.1     ragge 		 * Mark any error-due-to-bad-LBN (via `goto rwend').
    379       1.7     ragge 		 * WHAT STATUS WILL THESE HAVE?	 IT SURE WOULD BE NICE
    380       1.1     ragge 		 * IF DEC SOLD DOCUMENTATION FOR THEIR OWN CONTROLLERS.
    381       1.1     ragge 		 */
    382      1.26        ad 		bp->b_error = error;
    383       1.1     ragge 		if (st == M_ST_OFFLINE || st == M_ST_AVAILABLE) {
    384       1.1     ragge #ifdef notyet
    385       1.1     ragge 			(*md->md_offline)(ui, mp);
    386       1.1     ragge #endif
    387       1.1     ragge 		}
    388       1.1     ragge 
    389       1.1     ragge 		/*
    390       1.1     ragge 		 * If the transfer failed, give the driver a crack
    391       1.1     ragge 		 * at fixing things up.
    392       1.1     ragge 		 */
    393       1.1     ragge 		if (st != M_ST_SUCCESS) {
    394       1.1     ragge 			switch ((*me->me_ioerr)(drive, mp, bp)) {
    395       1.1     ragge 
    396       1.1     ragge 			case MSCP_DONE:		/* fixed */
    397       1.1     ragge 				break;
    398       1.1     ragge 
    399       1.1     ragge 			case MSCP_RESTARTED:	/* still working on it */
    400       1.1     ragge 				goto out;
    401       1.1     ragge 
    402       1.1     ragge 			case MSCP_FAILED:	/* no luck */
    403       1.1     ragge 				/* XXX must move to ra.c */
    404       1.1     ragge 				mscp_printevent(mp);
    405       1.1     ragge 				break;
    406       1.1     ragge 			}
    407       1.1     ragge 		}
    408       1.1     ragge 
    409       1.1     ragge 		/*
    410       1.1     ragge 		 * Set the residual count and mark the transfer as
    411       1.1     ragge 		 * done.  If the I/O wait queue is now empty, release
    412       1.1     ragge 		 * the shared BDP, if any.
    413       1.1     ragge 		 */
    414       1.1     ragge 		bp->b_resid = bp->b_bcount - mp->mscp_seq.seq_bytecount;
    415      1.11     ragge 		bus_dmamap_unload(mi->mi_dmat, mxi->mxi_dmam);
    416       1.1     ragge 
    417      1.24   thorpej 		(*mc->mc_ctlrdone)(device_parent(&mi->mi_dev));
    418       1.1     ragge 		(*me->me_iodone)(drive, bp);
    419       1.1     ragge out:
    420      1.11     ragge 		mxi->mxi_inuse = 0;
    421      1.11     ragge 		mi->mi_mxiuse |= (1 << mp->mscp_cmdref);
    422       1.1     ragge 		break;
    423      1.22     perry 
    424       1.1     ragge 	case M_OP_REPLACE | M_OP_END:
    425       1.1     ragge 		/*
    426       1.1     ragge 		 * A replace operation finished.  Just let the driver
    427       1.1     ragge 		 * handle it (if it does replaces).
    428       1.1     ragge 		 */
    429       1.1     ragge 		if (me->me_replace == NULL)
    430      1.29    cegger 			printf("%s: bogus REPLACE end\n", device_xname(drive));
    431       1.1     ragge 		else
    432       1.1     ragge 			(*me->me_replace)(drive, mp);
    433       1.1     ragge 		break;
    434       1.1     ragge 
    435       1.1     ragge 	default:
    436       1.1     ragge 		/*
    437       1.1     ragge 		 * If it is not one of the above, we cannot handle it.
    438       1.1     ragge 		 * (And we should not have received it, for that matter.)
    439       1.1     ragge 		 */
    440       1.1     ragge unknown:
    441       1.4  christos 		printf("%s: unknown opcode 0x%x status 0x%x ignored\n",
    442      1.29    cegger 			device_xname(drive), mp->mscp_opcode, mp->mscp_status);
    443       1.5     ragge #ifdef DIAGNOSTIC
    444       1.1     ragge 		mscp_hexdump(mp);
    445       1.5     ragge #endif
    446       1.1     ragge 		break;
    447       1.1     ragge 	}
    448       1.1     ragge 
    449       1.1     ragge 	/*
    450       1.1     ragge 	 * If the drive needs to be put back in the controller queue,
    451       1.7     ragge 	 * do that now.	 (`bp' below ought to be `dp', but they are all
    452       1.1     ragge 	 * struct buf *.)  Note that b_active was cleared in the driver;
    453       1.1     ragge 	 * we presume that there is something to be done, hence reassert it.
    454       1.1     ragge 	 */
    455       1.1     ragge #ifdef notyet /* XXX */
    456       1.1     ragge 	if (ui->ui_flags & UNIT_REQUEUE) {
    457      1.11     ragge 		...
    458       1.1     ragge 	}
    459       1.1     ragge #endif
    460       1.1     ragge done:
    461       1.1     ragge 	/*
    462       1.1     ragge 	 * Give back the response packet, and take a look at the next.
    463       1.1     ragge 	 */
    464       1.1     ragge 	mp->mscp_msglen = MSCP_MSGLEN;
    465       1.1     ragge 	mi->mi_rsp.mri_desc[nextrsp] |= MSCP_OWN;
    466       1.1     ragge 	nextrsp = (nextrsp + 1) % mi->mi_rsp.mri_size;
    467       1.1     ragge 	goto loop;
    468       1.1     ragge }
    469       1.1     ragge 
    470       1.1     ragge /*
    471       1.1     ragge  * Requeue outstanding transfers, e.g., after bus reset.
    472       1.1     ragge  * Also requeue any drives that have on line or unit status
    473       1.1     ragge  * info pending.
    474       1.1     ragge  */
    475       1.1     ragge void
    476  1.29.4.1      yamt mscp_requeue(struct mscp_softc *mi)
    477       1.1     ragge {
    478      1.11     ragge 	panic("mscp_requeue");
    479       1.1     ragge }
    480       1.1     ragge 
    481  1.29.4.1      yamt void
    482  1.29.4.1      yamt mscp_worker(struct work *wk, void *dummy)
    483  1.29.4.1      yamt {
    484  1.29.4.1      yamt 	struct mscp_softc *mi;
    485  1.29.4.1      yamt 	struct mscp_work *mw;
    486  1.29.4.1      yamt 	struct	drive_attach_args da;
    487  1.29.4.1      yamt 
    488  1.29.4.1      yamt 	mw = (struct mscp_work *)wk;
    489  1.29.4.1      yamt 	mi = mw->mw_mi;
    490  1.29.4.1      yamt 
    491  1.29.4.1      yamt 	da.da_mp = &mw->mw_mp;
    492  1.29.4.1      yamt 	da.da_typ = mi->mi_type;
    493  1.29.4.1      yamt 
    494  1.29.4.1      yamt 	config_found(&mi->mi_dev, (void *)&da, mscp_print);
    495  1.29.4.1      yamt 
    496  1.29.4.1      yamt 	mutex_spin_enter(&mi->mi_mtx);
    497  1.29.4.1      yamt 	SLIST_INSERT_HEAD(&mw->mw_mi->mi_freelist, mw, mw_list);
    498  1.29.4.1      yamt 	mutex_spin_exit(&mi->mi_mtx);
    499  1.29.4.1      yamt }
    500