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