1 /* $FreeBSD$ */ 2 /* $Id: isp_freebsd.c,v 1.1 1998/04/22 17:54:50 mjacob Exp $ */ 3 /* 4 * Platform (FreeBSD) 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 #include <dev/isp/isp_freebsd.h> 37 38 static void ispminphys __P((struct buf *)); 39 static u_int32_t isp_adapter_info __P((int)); 40 41 static struct scsi_adapter isp_switch = { 42 ispscsicmd, ispminphys, 0, 0, isp_adapter_info, "isp", { 0, 0 } 43 }; 44 static struct scsi_device isp_dev = { 45 NULL, NULL, NULL, NULL, "isp", 0, { 0, 0 } 46 }; 47 48 /* 49 * Complete attachment of hardware, include subdevices. 50 */ 51 void 52 isp_attach(isp) 53 struct ispsoftc *isp; 54 { 55 struct scsibus_data *scbus; 56 57 scbus = scsi_alloc_bus(); 58 if(!scbus) { 59 return; 60 } 61 isp->isp_state = ISP_RUNSTATE; 62 63 isp->isp_osinfo._link.adapter_unit = isp->isp_osinfo.unit; 64 isp->isp_osinfo._link.adapter_softc = isp; 65 isp->isp_osinfo._link.adapter = &isp_switch; 66 isp->isp_osinfo._link.device = &isp_dev; 67 isp->isp_osinfo._link.flags = 0; 68 if (isp->isp_type & ISP_HA_FC) { 69 isp->isp_osinfo._link.adapter_targ = 0xff; 70 #if 0 71 isp->isp_osinfo._link.openings = 72 RQUEST_QUEUE_LEN(isp) / (MAX_FC_TARG-1); 73 #endif 74 scbus->maxtarg = MAX_FC_TARG-1; 75 } else { 76 isp->isp_osinfo._link.adapter_targ = 77 ((sdparam *)isp->isp_param)->isp_initiator_id; 78 #if 0 79 isp->isp_osinfo._link.openings = 80 RQUEST_QUEUE_LEN(isp) / (MAX_TARGETS-1); 81 #endif 82 scbus->maxtarg = MAX_TARGETS-1; 83 } 84 /* 85 * Prepare the scsibus_data area for the upperlevel scsi code. 86 */ 87 scbus->adapter_link = &isp->isp_osinfo._link; 88 89 /* 90 * ask the adapter what subunits are present 91 */ 92 scsi_attachdevs(scbus); 93 } 94 95 96 /* 97 * minphys our xfers 98 * 99 * Unfortunately, the buffer pointer describes the target device- not the 100 * adapter device, so we can't use the pointer to find out what kind of 101 * adapter we are and adjust accordingly. 102 */ 103 104 static void 105 ispminphys(bp) 106 struct buf *bp; 107 { 108 /* 109 * XX: Only the 1020 has a 24 bit limit. 110 */ 111 if (bp->b_bcount >= (1 << 24)) { 112 bp->b_bcount = (1 << 24); 113 } 114 } 115 116 static u_int32_t 117 isp_adapter_info(unit) 118 int unit; 119 { 120 /* 121 * XXX: FIND ISP BASED UPON UNIT AND GET REAL QUEUE LIMIT FROM THAT 122 */ 123 return (2); 124 } 125