Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.c revision 1.6
      1 /* $NetBSD: isp_netbsd.c,v 1.6 1998/11/19 21:53:00 thorpej Exp $ */
      2 /*
      3  * Platform (NetBSD) dependent common attachment code for Qlogic adapters.
      4  *
      5  *---------------------------------------
      6  * Copyright (c) 1997, 1998 by Matthew Jacob
      7  * NASA/Ames Research Center
      8  * All rights reserved.
      9  *---------------------------------------
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice immediately at the beginning of the file, without modification,
     16  *    this list of conditions, and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  * The author may be reached via electronic communications at
     36  *
     37  *  mjacob (at) nas.nasa.gov
     38  *  mjacob (at) feral.com
     39  *
     40  * or, via United States Postal Address
     41  *
     42  *  Matthew Jacob
     43  *  Feral Software
     44  *  2339 3rd Street
     45  *  Suite 24
     46  *  San Francisco, CA, 94107
     47  */
     48 
     49 #include <dev/ic/isp_netbsd.h>
     50 
     51 static void ispminphys __P((struct buf *));
     52 static int32_t ispcmd __P((ISP_SCSI_XFER_T *));
     53 
     54 static struct scsipi_device isp_dev = { NULL, NULL, NULL, NULL };
     55 static int isp_poll __P((struct ispsoftc *, ISP_SCSI_XFER_T *, int));
     56 
     57 /*
     58  * Complete attachment of hardware, include subdevices.
     59  */
     60 void
     61 isp_attach(isp)
     62 	struct ispsoftc *isp;
     63 {
     64 
     65 	isp->isp_osinfo._adapter.scsipi_cmd = ispcmd;
     66 	isp->isp_osinfo._adapter.scsipi_minphys = ispminphys;
     67 
     68 	isp->isp_state = ISP_RUNSTATE;
     69 	isp->isp_osinfo._link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
     70 	isp->isp_osinfo._link.adapter_softc = isp;
     71 	isp->isp_osinfo._link.device = &isp_dev;
     72 	isp->isp_osinfo._link.adapter = &isp->isp_osinfo._adapter;
     73 
     74 	if (isp->isp_type & ISP_HA_FC) {
     75 		isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_FC_TARG-1;
     76 		isp->isp_osinfo._link.openings =
     77 			RQUEST_QUEUE_LEN / (MAX_FC_TARG-1);
     78 		isp->isp_osinfo._link.scsipi_scsi.adapter_target = 0xff;
     79 	} else {
     80 		isp->isp_osinfo._link.openings =
     81 			RQUEST_QUEUE_LEN / (MAX_TARGETS-1);
     82 		isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_TARGETS-1;
     83 		isp->isp_osinfo._link.scsipi_scsi.adapter_target =
     84 			((sdparam *)isp->isp_param)->isp_initiator_id;
     85 	}
     86 	if (isp->isp_osinfo._link.openings < 2)
     87 		isp->isp_osinfo._link.openings = 2;
     88 	isp->isp_osinfo._link.type = BUS_SCSI;
     89 	config_found((void *)isp, &isp->isp_osinfo._link, scsiprint);
     90 }
     91 
     92 /*
     93  * minphys our xfers
     94  *
     95  * Unfortunately, the buffer pointer describes the target device- not the
     96  * adapter device, so we can't use the pointer to find out what kind of
     97  * adapter we are and adjust accordingly.
     98  */
     99 
    100 static void
    101 ispminphys(bp)
    102 	struct buf *bp;
    103 {
    104 	/*
    105 	 * XX: Only the 1020 has a 24 bit limit.
    106 	 */
    107 	if (bp->b_bcount >= (1 << 24)) {
    108 		bp->b_bcount = (1 << 24);
    109 	}
    110 	minphys(bp);
    111 }
    112 
    113 static int
    114 ispcmd(xs)
    115 	ISP_SCSI_XFER_T *xs;
    116 {
    117 	struct ispsoftc *isp;
    118 	int result;
    119 	ISP_LOCKVAL_DECL;
    120 
    121 	isp = XS_ISP(xs);
    122 	ISP_LOCK(isp);
    123 	/*
    124 	 * This is less efficient than I would like in that the
    125 	 * majority of cases will have to do some pointer deferences
    126 	 * to find out that things don't need to be updated.
    127 	 */
    128 	if ((xs->flags & SCSI_AUTOCONF) == 0 && (isp->isp_type & ISP_HA_SCSI)) {
    129 		sdparam *sdp = isp->isp_param;
    130 		if (sdp->isp_devparam[XS_TGT(xs)].dev_flags !=
    131 		    sdp->isp_devparam[XS_TGT(xs)].cur_dflags) {
    132 			u_int16_t f = DPARM_WIDE|DPARM_SYNC|DPARM_TQING;
    133 			if (xs->sc_link->quirks & SDEV_NOSYNC)
    134 				f &= ~DPARM_SYNC;
    135 			if (xs->sc_link->quirks & SDEV_NOWIDE)
    136 				f &= ~DPARM_WIDE;
    137 			if (xs->sc_link->quirks & SDEV_NOTAG)
    138 				f &= ~DPARM_TQING;
    139 			sdp->isp_devparam[XS_TGT(xs)].dev_flags &=
    140 				~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING);
    141 			sdp->isp_devparam[XS_TGT(xs)].dev_flags |= f;
    142 			sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
    143 			isp->isp_update = 1;
    144 		}
    145 	}
    146 	result = ispscsicmd(xs);
    147 	if (result != CMD_QUEUED || (xs->flags & SCSI_POLL) == 0) {
    148 		ISP_UNLOCK(isp);
    149 		return (result);
    150 	}
    151 
    152 	/*
    153 	 * If we can't use interrupts, poll on completion.
    154 	 */
    155 	if (isp_poll(isp, xs, XS_TIME(xs))) {
    156 		/*
    157 		 * If no other error occurred but we didn't finish,
    158 		 * something bad happened.
    159 		 */
    160 		if (XS_IS_CMD_DONE(xs) == 0) {
    161 			isp->isp_nactive--;
    162 			if (isp->isp_nactive < 0)
    163 				isp->isp_nactive = 0;
    164 			if (XS_NOERR(xs)) {
    165 				isp_lostcmd(isp, xs);
    166 				XS_SETERR(xs, HBA_BOTCH);
    167 			}
    168 		}
    169 	}
    170 	ISP_UNLOCK(isp);
    171 	return (CMD_COMPLETE);
    172 }
    173 
    174 static int
    175 isp_poll(isp, xs, mswait)
    176 	struct ispsoftc *isp;
    177 	ISP_SCSI_XFER_T *xs;
    178 	int mswait;
    179 {
    180 
    181 	while (mswait) {
    182 		/* Try the interrupt handling routine */
    183 		(void)isp_intr((void *)isp);
    184 
    185 		/* See if the xs is now done */
    186 		if (XS_IS_CMD_DONE(xs)) {
    187 			return (0);
    188 		}
    189 		SYS_DELAY(1000);	/* wait one millisecond */
    190 		mswait--;
    191 	}
    192 	return (1);
    193 }
    194