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