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