Home | History | Annotate | Line # | Download | only in ic
mpt_netbsd.h revision 1.10.2.1
      1 /*	$NetBSD: mpt_netbsd.h,v 1.10.2.1 2012/09/12 06:15:32 tls Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2003 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed for the NetBSD Project by
     20  *	Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * Copyright (c) 2000, 2001 by Greg Ansley, Adam Prewett
     40  *
     41  * Partially derived from Matt Jacobs ISP driver.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice immediately at the beginning of the file, without modification,
     48  *    this list of conditions, and the following disclaimer.
     49  * 2. The name of the author may not be used to endorse or promote products
     50  *    derived from this software without specific prior written permission.
     51  *
     52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     56  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61  */
     62 /*
     63  * Additional Copyright (c) 2002 by Matthew Jacob under same license.
     64  */
     65 
     66 /*
     67  * mpt_netbsd.h:
     68  *
     69  * NetBSD-specific definitions for LSI Fusion adapters.
     70  *
     71  * Adapted from the FreeBSD "mpt" driver by Jason R. Thorpe for
     72  * Wasabi Systems, Inc.
     73  *
     74  * Additional contributions by Garrett D'Amore on behalf of TELES AG.
     75  */
     76 
     77 #ifndef _DEV_IC_MPT_NETBSD_H_
     78 #define	_DEV_IC_MPT_NETBSD_H_
     79 
     80 #include <sys/param.h>
     81 #include <sys/systm.h>
     82 #include <sys/malloc.h>
     83 #include <sys/kernel.h>
     84 #include <sys/callout.h>
     85 #include <sys/errno.h>
     86 #include <sys/buf.h>
     87 #include <sys/queue.h>
     88 #include <sys/device.h>
     89 
     90 #include <sys/bus.h>
     91 #include <sys/intr.h>
     92 
     93 #include <dev/scsipi/scsi_all.h>
     94 #include <dev/scsipi/scsipi_all.h>
     95 #include <dev/scsipi/scsiconf.h>
     96 
     97 #include <dev/ic/mpt_mpilib.h>
     98 
     99 /* Max MPT Reply we are willing to accept (must be a power of 2). */
    100 #define	MPT_REPLY_SIZE		128
    101 
    102 #define	MPT_MAX_REQUESTS(mpt)	((mpt)->is_fc ? 1024 : 256)
    103 #define	MPT_REQUEST_AREA	512
    104 #define	MPT_SENSE_SIZE		32	/* included in MPT_REQUEST_AREA */
    105 #define	MPT_REQ_MEM_SIZE(mpt)	(MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA)
    106 
    107 /*
    108  * We cannot tell prior to getting IOC facts how big the IOC's request
    109  * area is. Because of this we cannot tell at compile time how many
    110  * simple SG elements we can fit within an IOC request prior to having
    111  * to put in a chain element.
    112  *
    113  * Experimentally we know that the Ultra4 parts have a 96 byte request
    114  * element size and the Fibre Channel units have a 144 byte request
    115  * element size. Therefore, if we have 512-32 (== 480) bytes of request
    116  * area to play with, we have room for between 3 and 5 request sized
    117  * regions- the first of which is the command  plus a simple SG list,
    118  * the rest of which are chained continuation SG lists. Given that the
    119  * normal request we use is 48 bytes w/o the first SG element, we can
    120  * assume we have 480-48 == 432 bytes to have simple SG elements and/or
    121  * chain elements. If we assume 32 bit addressing, this works out to
    122  * 54 SG or chain elements. If we assume 5 chain elements, then we have
    123  * a maximum of 49 separate actual SG segments.
    124  */
    125 #define	MPT_SGL_MAX		49
    126 
    127 #define	MPT_RQSL(mpt)		((mpt)->request_frame_size << 2)
    128 #define	MPT_NSGL(mpt)		(MPT_RQSL(mpt) / sizeof(SGE_SIMPLE32))
    129 
    130 #define	MPT_NSGL_FIRST(mpt)					\
    131 	((((mpt)->request_frame_size << 2) -			\
    132 	  sizeof(MSG_SCSI_IO_REQUEST) -				\
    133 	  sizeof(SGE_IO_UNION)) / sizeof(SGE_SIMPLE32))
    134 
    135 /*
    136  * Subtract one from the SGL limit, since we need an extra one to handle
    137  * an non-page-aligned transfer.
    138  */
    139 #define MPT_MAX_XFER		((MPT_SGL_MAX - 1) * PAGE_SIZE)
    140 
    141 /*
    142  * Convert a physical address returned from IOC to a virtual address
    143  * needed to access the data.
    144  */
    145 #define	MPT_REPLY_PTOV(m, x)					\
    146 	((void *)(&(m)->reply[(((x) << 1) - (m)->reply_phys)]))
    147 
    148 enum mpt_req_state {
    149 	REQ_FREE,
    150 	REQ_IN_PROGRESS,
    151 	REQ_TIMEOUT,
    152 	REQ_ON_CHIP,
    153 	REQ_DONE
    154 };
    155 typedef struct req_entry {
    156 	uint16_t	index;		/* index of this entry */
    157 	struct scsipi_xfer *xfer;	/* scsipi xfer request */
    158 	void		*req_vbuf;	/* virtual address of entry */
    159 	void		*sense_vbuf;	/* virtual address of sense data */
    160 	bus_addr_t	req_pbuf;	/* physical address of entry */
    161 	bus_addr_t	sense_pbuf;	/* physical address of sense data */
    162 	bus_dmamap_t	dmap;		/* DMA map for data buffer */
    163 	SLIST_ENTRY(req_entry) link;	/* pointer to next in list */
    164 	enum mpt_req_state debug;	/* debugging */
    165 	uint32_t	sequence;	/* sequence number */
    166 } request_t;
    167 
    168 typedef struct mpt_softc {
    169 	device_t	sc_dev;		/* base device glue */
    170 
    171 	/* Locking context */
    172 	int		mpt_splsaved;
    173 	uint32_t	mpt_islocked;
    174 
    175 	int		verbose : 3,
    176 			mpt_locksetup : 1,
    177 			is_fc : 1,
    178 			is_scsi : 1,
    179 			is_sas : 1,
    180 			bus : 1,
    181 			: 23;
    182 
    183 	/* IOC facts */
    184 	uint16_t	mpt_global_credits;
    185 	uint16_t	request_frame_size;
    186 	uint8_t		mpt_max_devices;
    187 	uint8_t		mpt_max_buses;
    188 
    189 	/* Port facts */
    190 	uint16_t	mpt_ini_id;
    191 
    192 	/* Device configuration information */
    193 	union {
    194 		struct mpt_spi_cfg {
    195 			fCONFIG_PAGE_SCSI_PORT_0	_port_page0;
    196 			fCONFIG_PAGE_SCSI_PORT_1	_port_page1;
    197 			fCONFIG_PAGE_SCSI_PORT_2	_port_page2;
    198 			fCONFIG_PAGE_SCSI_DEVICE_0	_dev_page0[16];
    199 			fCONFIG_PAGE_SCSI_DEVICE_1	_dev_page1[16];
    200 			uint16_t			_tag_enable;
    201 			uint16_t			_disc_enable;
    202 			uint16_t			_update_params0;
    203 			uint16_t			_update_params1;
    204 			uint16_t			_report_xfer_mode;
    205 		} spi;
    206 #define	mpt_port_page0		cfg.spi._port_page0
    207 #define	mpt_port_page1		cfg.spi._port_page1
    208 #define	mpt_port_page2		cfg.spi._port_page2
    209 #define	mpt_dev_page0		cfg.spi._dev_page0
    210 #define	mpt_dev_page1		cfg.spi._dev_page1
    211 #define	mpt_tag_enable		cfg.spi._tag_enable
    212 #define	mpt_disc_enable		cfg.spi._disc_enable
    213 #define	mpt_update_params0	cfg.spi._update_params0
    214 #define	mpt_update_params1	cfg.spi._update_params1
    215 #define	mpt_report_xfer_mode	cfg.spi._report_xfer_mode
    216 
    217 		struct mpt_fc_cfg {
    218 			uint8_t		nada;
    219 		} fc;
    220 	} cfg;
    221 
    222 	bus_space_tag_t		sc_st;
    223 	bus_space_handle_t	sc_sh;
    224 	bus_dma_tag_t		sc_dmat;
    225 
    226 	/* Reply memory */
    227 	bus_dmamap_t		reply_dmap;
    228 	char			*reply;
    229 	bus_addr_t		reply_phys;
    230 
    231 	/* Request memory */
    232 	bus_dmamap_t		request_dmap;
    233 	char			*request;
    234 	bus_addr_t		request_phys;
    235 
    236 	/* SCSIPI and software management */
    237 	request_t		*request_pool;
    238 	SLIST_HEAD(req_queue, req_entry) request_free_list;
    239 
    240 	struct scsipi_adapter	sc_adapter;
    241 	struct scsipi_channel	sc_channel;
    242 
    243 	uint32_t		sequence;	/* sequence number */
    244 	uint32_t		timeouts;	/* timeout count */
    245 	uint32_t		success;	/* success after timeout */
    246 
    247 	/* To restore configuration after hard reset. */
    248 	void			(*sc_set_config_regs)(struct mpt_softc *);
    249 } mpt_softc_t;
    250 
    251 #define	MPT_SYNC_REQ(mpt, req, ops)				\
    252 	bus_dmamap_sync((mpt)->sc_dmat, (mpt)->request_dmap,	\
    253 	    (req)->req_pbuf - (mpt)->request_phys,		\
    254 	    MPT_REQUEST_AREA, (ops))
    255 
    256 #define	mpt_read(mpt, reg)					\
    257 	bus_space_read_4((mpt)->sc_st, (mpt)->sc_sh, (reg))
    258 #define	mpt_write(mpt, reg, val)				\
    259 	bus_space_write_4((mpt)->sc_st, (mpt)->sc_sh, (reg), (val))
    260 
    261 void	mpt_scsipi_attach(mpt_softc_t *);
    262 int	mpt_dma_mem_alloc(mpt_softc_t *);
    263 int	mpt_intr(void *);
    264 void	mpt_prt(mpt_softc_t *, const char *, ...);
    265 
    266 #define	mpt_set_config_regs(mpt)				\
    267 do {								\
    268 	if ((mpt)->sc_set_config_regs != NULL)			\
    269 		(*(mpt)->sc_set_config_regs)((mpt));		\
    270 } while (/*CONSTCOND*/0)
    271 
    272 #endif /* _DEV_IC_MPT_NETBSD_H_ */
    273