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