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