Home | History | Annotate | Line # | Download | only in pci
twavar.h revision 1.1
      1 /*	$wasabi: twavar.h,v 1.11 2006/04/27 17:12:39 wrstuden Exp $	*/
      2 /*
      3  * Copyright (c) 2005-2006 Wasabi Systems, Inc.
      4  * All rights reserved.
      5  *
      6  * Your Wasabi Systems License Agreement specifies the terms and
      7  * conditions for use and redistribution.
      8  */
      9 
     10 /*-
     11  * Copyright (c) 2003-04 3ware, Inc.
     12  * Copyright (c) 2000 Michael Smith
     13  * Copyright (c) 2000 BSDi
     14  * All rights reserved.
     15  *
     16  * Redistribution and use in source and binary forms, with or without
     17  * modification, are permitted provided that the following conditions
     18  * are met:
     19  * 1. Redistributions of source code must retain the above copyright
     20  *    notice, this list of conditions and the following disclaimer.
     21  * 2. Redistributions in binary form must reproduce the above copyright
     22  *    notice, this list of conditions and the following disclaimer in the
     23  *    documentation and/or other materials provided with the distribution.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  *	$FreeBSD: src/sys/dev/twa/twa.h,v 1.4 2004/06/16 09:47:00 phk Exp $
     38  */
     39 
     40 /*
     41  * 3ware driver for 9000 series storage controllers.
     42  *
     43  * Author: Vinod Kashyap
     44  */
     45 #ifndef _PCI_TWAVAR_H_
     46 #define	_PCI_TWAVAR_H_
     47 
     48 #include "locators.h"
     49 
     50 struct twa_callbacks {
     51 	void	(*tcb_openings)(struct device *, int);
     52 };
     53 
     54 struct twa_drive {
     55 	uint32_t	td_id;
     56 	uint64_t	td_size;
     57 	struct device	*td_dev;
     58 	const struct twa_callbacks *td_callbacks;
     59 };
     60 
     61 /* Per-controller structure. */
     62 struct twa_softc {
     63 	struct device		twa_dv;
     64 	bus_space_tag_t		twa_bus_iot;	/* bus space tag */
     65 	bus_space_handle_t	twa_bus_ioh;	/* bus space handle */
     66 	bus_dma_tag_t		twa_dma_tag;	/* data buffer DMA tag */
     67 	bus_dmamap_t		twa_cmd_map;	/* DMA map for the array of cmd pkts */
     68 	void			*twa_ih;	/* interrupt handle cookie */
     69 	caddr_t			twa_cmds;
     70 	bus_addr_t		twa_cmd_pkt_phys;/* phys addr of first of array of cmd pkts */
     71 
     72 	pci_chipset_tag_t 	pc;
     73 	pcitag_t		tag;
     74 	/* Request queues and arrays. */
     75 	TAILQ_HEAD(, twa_request) twa_free;	/* free request packets */
     76 	TAILQ_HEAD(, twa_request) twa_busy;	/* requests busy in the controller */
     77 	TAILQ_HEAD(, twa_request) twa_pending;	/* internal requests pending */
     78 
     79 	struct twa_request	*twa_lookup[TWA_Q_LENGTH];/* requests indexed by request_id */
     80 
     81 	struct twa_request	*twa_req_buf;
     82 	struct twa_command_packet *twa_cmd_pkt_buf;
     83 
     84 	struct twa_drive	sc_units[TWA_MAX_UNITS];
     85 	/* AEN handler fields. */
     86 	struct tw_cl_event_packet *twa_aen_queue[TWA_Q_LENGTH];/* circular queue of AENs from firmware */
     87 	uint16_t		working_srl;	/* driver & firmware negotiated srl */
     88 	uint16_t		working_branch;	/* branch # of the firmware that the driver is compatible with */
     89 	uint16_t		working_build;	/* build # of the firmware that the driver is compatible with */
     90 	u_int32_t		twa_operating_mode; /* base mode/current mode */
     91 	u_int32_t		twa_aen_head;	/* AEN queue head */
     92 	u_int32_t		twa_aen_tail;	/* AEN queue tail */
     93 	u_int32_t		twa_current_sequence_id;/* index of the last event + 1 */
     94 	u_int32_t		twa_aen_queue_overflow;	/* indicates if unretrieved events were overwritten */
     95 	u_int32_t		twa_aen_queue_wrapped;	/* indicates if AEN queue ever wrapped */
     96 	/* Controller state. */
     97 	u_int32_t		twa_state;
     98 	u_int32_t		twa_sc_flags;
     99 #ifdef TWA_DEBUG
    100 	struct twa_q_statistics	twa_qstats[TWAQ_COUNT];	/* queue statistics */
    101 #endif /* TWA_DEBUG */
    102 
    103 	struct _twa_ioctl_lock{
    104 		u_int32_t	lock;		/* lock state */
    105 		u_int32_t	timeout;	/* time at which the lock
    106 						 * will become available,
    107 						 * even if not released
    108 						 */
    109 	} twa_ioctl_lock;			/* lock for use by user
    110 						 * applications,
    111 						 * for synchronization between
    112 						 * ioctl calls
    113 						 */
    114 	int			sc_openings;
    115 	int			sc_nunits;
    116 
    117 	struct twa_request      *sc_twa_request;
    118 };
    119 
    120 
    121 
    122 /* Possible values of tr->tr_status. */
    123 #define TWA_CMD_SETUP		0x0	/* being assembled */
    124 #define TWA_CMD_BUSY		0x1	/* submitted to controller */
    125 #define TWA_CMD_PENDING		0x2	/* in pending queue */
    126 #define TWA_CMD_COMPLETE	0x3	/* completed by controller */
    127 
    128 /* Possible values of tr->tr_flags. */
    129 #define TWA_CMD_DATA_IN			(1 << 0)
    130 #define TWA_CMD_DATA_OUT		(1 << 1)
    131 #define TWA_CMD_DATA_COPY_NEEDED	(1 << 2)
    132 #define TWA_CMD_SLEEP_ON_REQUEST	(1 << 3)
    133 #define TWA_CMD_IN_PROGRESS		(1 << 4)
    134 #define TWA_CMD_AEN			(1 << 5)
    135 #define TWA_CMD_AEN_BUSY		(1 << 6)
    136 
    137 /* Possible values of tr->tr_cmd_pkt_type. */
    138 #define TWA_CMD_PKT_TYPE_7K		(1<<0)
    139 #define TWA_CMD_PKT_TYPE_9K		(1<<1)
    140 #define TWA_CMD_PKT_TYPE_INTERNAL	(1<<2)
    141 #define TWA_CMD_PKT_TYPE_IOCTL		(1<<3)
    142 #define TWA_CMD_PKT_TYPE_EXTERNAL	(1<<4)
    143 
    144 /* Possible values of sc->twa_state. */
    145 #define TWA_STATE_INTR_ENABLED		(1<<0)	/* interrupts have been enabled */
    146 #define TWA_STATE_SHUTDOWN		(1<<1)	/* controller is shut down */
    147 #define TWA_STATE_OPEN			(1<<2)	/* control device is open */
    148 #define TWA_STATE_SIMQ_FROZEN		(1<<3)	/* simq frozen */
    149 #define TWA_STATE_REQUEST_WAIT		(1<<4)
    150 
    151 /* Possible values of sc->twa_ioctl_lock.lock. */
    152 #define TWA_LOCK_FREE		0x0	/* lock is free */
    153 #define TWA_LOCK_HELD		0x1	/* lock is held */
    154 
    155 /* Driver's request packet. */
    156 struct twa_request {
    157 	struct twa_command_packet *tr_command;
    158 	/* ptr to cmd pkt submitted to controller */
    159 	u_int32_t		tr_request_id;
    160 	/* request id for tracking with firmware */
    161 	void			*tr_data;
    162 	/* ptr to data being passed to firmware */
    163 	size_t			tr_length;
    164 	/* length of buffer being passed to firmware */
    165 	void			*tr_real_data;
    166 	/* ptr to, and length of data passed */
    167 	size_t			tr_real_length;
    168 	/* to us from above, in case a buffer copy
    169 	 * was done due to non-compliance to
    170 	 * alignment requirements
    171 	 */
    172 	TAILQ_ENTRY(twa_request) tr_link;
    173 	/* to link this request in a list */
    174 	struct twa_softc	*tr_sc;
    175 	/* controller that owns us */
    176 	u_int32_t		tr_status;
    177 	/* command status */
    178 	u_int32_t		tr_flags;
    179 	/* request flags */
    180 	u_int32_t		tr_error;
    181 	/* error encountered before request submission */
    182 	u_int32_t		tr_cmd_pkt_type;
    183 	/* request specific data to use during callback */
    184 	void			(*tr_callback)(struct twa_request *tr);
    185 	/* callback handler */
    186 	bus_addr_t		tr_cmd_phys;
    187 	/* physical address of command in controller space */
    188 	bus_dmamap_t		tr_dma_map;
    189 	/* DMA map for data */
    190 	struct buf		*bp;
    191 
    192 	struct ld_twa_softc	*tr_ld_sc;
    193 };
    194 
    195 static __inline__ size_t twa_get_maxsegs(void) {
    196 	size_t max_segs = ((MAXPHYS + PAGE_SIZE - 1) / PAGE_SIZE) + 1;
    197 #ifdef TWA_SG_SIZE
    198 	if (TWA_MAX_SG_ELEMENTS < max_segs)
    199 	    max_segs = TWA_MAX_SG_ELEMENTS;
    200 #endif
    201 	return max_segs;
    202 }
    203 
    204 static __inline__ size_t twa_get_maxxfer(size_t maxsegs) {
    205 	return (maxsegs - 1) * PAGE_SIZE;
    206 }
    207 
    208 struct twa_attach_args {
    209 	int	twaa_unit;
    210 };
    211 
    212 #define twaacf_unit	cf_loc[TWACF_UNIT]
    213 
    214 struct twa_request *twa_get_request(struct twa_softc *, int);
    215 struct twa_request *twa_get_request_wait(struct twa_softc *, int);
    216 int twa_map_request(struct twa_request *);
    217 void	twa_register_callbacks(struct twa_softc *sc, int unit,
    218 		const struct twa_callbacks *);
    219 void	twa_request_wait_handler(struct twa_request *);
    220 void	twa_release_request(struct twa_request *);
    221 
    222 /* Error/AEN message structure. */
    223 struct twa_message {
    224 	u_int32_t	code;
    225 	const char	*message;
    226 };
    227 
    228 #endif	/* !_PCI_TWAVAR_H_ */
    229