mlxvar.h revision 195534
1279377Simp/*- 2279377Simp * Copyright (c) 1999 Michael Smith 3279377Simp * All rights reserved. 4279377Simp * 5279377Simp * Redistribution and use in source and binary forms, with or without 6279377Simp * modification, are permitted provided that the following conditions 7279377Simp * are met: 8279377Simp * 1. Redistributions of source code must retain the above copyright 9279377Simp * notice, this list of conditions and the following disclaimer. 10279377Simp * 2. Redistributions in binary form must reproduce the above copyright 11279377Simp * notice, this list of conditions and the following disclaimer in the 12279377Simp * documentation and/or other materials provided with the distribution. 13295436Sandrew * 14279377Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15295436Sandrew * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16295436Sandrew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17279377Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18279377Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19279377Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20279377Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21279377Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22279377Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23279377Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24279377Simp * SUCH DAMAGE. 25279377Simp * 26279377Simp * $FreeBSD: head/sys/dev/mlx/mlxvar.h 195534 2009-07-10 08:18:08Z scottl $ 27295436Sandrew */ 28295436Sandrew 29295436Sandrew/* 30295436Sandrew * Debugging levels: 31295436Sandrew * 0 - quiet, only emit warnings 32295436Sandrew * 1 - noisy, emit major function points and things done 33279377Simp * 2 - extremely noisy, emit trace items in loops, etc. 34279377Simp */ 35279377Simp#ifdef MLX_DEBUG 36279377Simp#define debug(level, fmt, args...) do { if (level <= MLX_DEBUG) printf("%s: " fmt "\n", __func__ , ##args); } while(0) 37279377Simp#define debug_called(level) do { if (level <= MLX_DEBUG) printf(__func__ ": called\n"); } while(0) 38279377Simp#else 39279377Simp#define debug(level, fmt, args...) 40295436Sandrew#define debug_called(level) 41295436Sandrew#endif 42295436Sandrew 43295436Sandrew/* 44295436Sandrew * Regardless of the actual capacity of the controller, we will allocate space 45295436Sandrew * for 64 s/g entries. Typically controllers support 17 or 33 entries (64k or 46279377Simp * 128k maximum transfer assuming 4k page size and non-optimal alignment), but 47279377Simp * making that fit cleanly without crossing page boundaries requires rounding up 48279377Simp * to the next power of two. 49279377Simp */ 50279377Simp#define MLX_MAXPHYS (128 * 124) 51279377Simp#define MLX_NSEG 64 52279377Simp 53279377Simp#define MLX_NSLOTS 256 /* max number of command slots */ 54279377Simp 55279377Simp#define MLX_MAXDRIVES 32 /* max number of system drives */ 56279377Simp 57279377Simp/* 58279377Simp * Structure describing a System Drive as attached to the controller. 59279377Simp */ 60279377Simpstruct mlx_sysdrive 61279377Simp{ 62279377Simp /* from MLX_CMD_ENQSYSDRIVE */ 63279377Simp u_int32_t ms_size; 64279377Simp int ms_state; 65279377Simp int ms_raidlevel; 66279377Simp 67279377Simp /* synthetic geometry */ 68279377Simp int ms_cylinders; 69279377Simp int ms_heads; 70279377Simp int ms_sectors; 71279377Simp 72279377Simp /* handle for attached driver */ 73279377Simp device_t ms_disk; 74279377Simp}; 75279377Simp 76279377Simp/* 77279377Simp * Per-command control structure. 78279377Simp */ 79279377Simpstruct mlx_command 80279377Simp{ 81279377Simp TAILQ_ENTRY(mlx_command) mc_link; /* list linkage */ 82279377Simp 83279377Simp struct mlx_softc *mc_sc; /* controller that owns us */ 84279377Simp u_int8_t mc_slot; /* command slot we occupy */ 85279377Simp u_int16_t mc_status; /* command completion status */ 86279377Simp time_t mc_timeout; /* when this command expires */ 87279377Simp u_int8_t mc_mailbox[16]; /* command mailbox */ 88279377Simp u_int32_t mc_sgphys; /* physical address of s/g array in controller space */ 89279377Simp int mc_nsgent; /* number of entries in s/g map */ 90279377Simp int mc_flags; 91279377Simp#define MLX_CMD_DATAIN (1<<0) 92279377Simp#define MLX_CMD_DATAOUT (1<<1) 93279377Simp#define MLX_CMD_PRIORITY (1<<2) /* high-priority command */ 94279377Simp 95279377Simp void *mc_data; /* data buffer */ 96279377Simp size_t mc_length; 97279377Simp bus_dmamap_t mc_dmamap; /* DMA map for data */ 98279377Simp u_int32_t mc_dataphys; /* data buffer base address controller space */ 99279377Simp 100279377Simp void (* mc_complete)(struct mlx_command *mc); /* completion handler */ 101279377Simp void *mc_private; /* submitter-private data or wait channel */ 102295436Sandrew int mc_command; 103295436Sandrew}; 104295436Sandrew 105295436Sandrew/* 106295436Sandrew * Per-controller structure. 107295436Sandrew */ 108295436Sandrewstruct mlx_softc 109295436Sandrew{ 110295436Sandrew /* bus connections */ 111279377Simp device_t mlx_dev; 112279377Simp struct cdev *mlx_dev_t; 113279377Simp struct resource *mlx_mem; /* mailbox interface window */ 114279377Simp int mlx_mem_rid; 115279377Simp int mlx_mem_type; 116279377Simp bus_space_handle_t mlx_bhandle; /* bus space handle */ 117279377Simp bus_space_tag_t mlx_btag; /* bus space tag */ 118279377Simp bus_dma_tag_t mlx_parent_dmat;/* parent DMA tag */ 119279377Simp bus_dma_tag_t mlx_buffer_dmat;/* data buffer DMA tag */ 120279377Simp struct resource *mlx_irq; /* interrupt */ 121279377Simp void *mlx_intr; /* interrupt handle */ 122279377Simp 123279377Simp /* scatter/gather lists and their controller-visible mappings */ 124279377Simp struct mlx_sgentry *mlx_sgtable; /* s/g lists */ 125279377Simp u_int32_t mlx_sgbusaddr; /* s/g table base address in bus space */ 126279377Simp bus_dma_tag_t mlx_sg_dmat; /* s/g buffer DMA tag */ 127279377Simp bus_dmamap_t mlx_sg_dmamap; /* map for s/g buffers */ 128279377Simp 129295436Sandrew /* controller limits and features */ 130279377Simp struct mlx_enquiry2 *mlx_enq2; 131279377Simp int mlx_feature; /* controller features/quirks */ 132279377Simp#define MLX_FEAT_PAUSEWORKS (1<<0) /* channel pause works as expected */ 133279377Simp 134279377Simp /* controller queues and arrays */ 135279377Simp TAILQ_HEAD(, mlx_command) mlx_freecmds; /* command structures available for reuse */ 136279377Simp TAILQ_HEAD(, mlx_command) mlx_work; /* active commands */ 137279377Simp struct mlx_command *mlx_busycmd[MLX_NSLOTS]; /* busy commands */ 138279377Simp int mlx_busycmds; /* count of busy commands */ 139279377Simp struct mlx_sysdrive mlx_sysdrive[MLX_MAXDRIVES]; /* system drives */ 140279377Simp mlx_bioq mlx_bioq; /* outstanding I/O operations */ 141279377Simp int mlx_waitbufs; /* number of bufs awaiting commands */ 142279377Simp 143279377Simp /* controller status */ 144279377Simp int mlx_geom; 145279377Simp#define MLX_GEOM_128_32 0 /* geoemetry translation modes */ 146279377Simp#define MLX_GEOM_256_63 1 147279377Simp int mlx_state; 148279377Simp#define MLX_STATE_INTEN (1<<0) /* interrupts have been enabled */ 149279377Simp#define MLX_STATE_SHUTDOWN (1<<1) /* controller is shut down */ 150279377Simp#define MLX_STATE_OPEN (1<<2) /* control device is open */ 151279377Simp#define MLX_STATE_SUSPEND (1<<3) /* controller is suspended */ 152279377Simp struct callout_handle mlx_timeout; /* periodic status monitor */ 153279377Simp time_t mlx_lastpoll; /* last time_second we polled for status */ 154279377Simp u_int16_t mlx_lastevent; /* sequence number of the last event we recorded */ 155279377Simp int mlx_currevent; /* sequence number last time we looked */ 156279377Simp int mlx_background; /* if != 0 rebuild or check is in progress */ 157279377Simp#define MLX_BACKGROUND_CHECK 1 /* we started a check */ 158279377Simp#define MLX_BACKGROUND_REBUILD 2 /* we started a rebuild */ 159279377Simp#define MLX_BACKGROUND_SPONTANEOUS 3 /* it just happened somehow */ 160279377Simp struct mlx_rebuild_status mlx_rebuildstat; /* last rebuild status */ 161279377Simp struct mlx_pause mlx_pause; /* pending pause operation details */ 162279377Simp 163279377Simp int mlx_locks; /* reentrancy avoidance */ 164279377Simp int mlx_flags; 165279377Simp#define MLX_SPINUP_REPORTED (1<<0) /* "spinning up drives" message displayed */ 166279377Simp#define MLX_EVENTLOG_BUSY (1<<1) /* currently reading event log */ 167279377Simp 168279377Simp /* interface-specific accessor functions */ 169279377Simp int mlx_iftype; /* interface protocol */ 170279377Simp#define MLX_IFTYPE_2 2 171279377Simp#define MLX_IFTYPE_3 3 172279377Simp#define MLX_IFTYPE_4 4 173279377Simp#define MLX_IFTYPE_5 5 174279377Simp int (* mlx_tryqueue)(struct mlx_softc *sc, struct mlx_command *mc); 175279377Simp int (* mlx_findcomplete)(struct mlx_softc *sc, u_int8_t *slot, u_int16_t *status); 176279377Simp void (* mlx_intaction)(struct mlx_softc *sc, int action); 177279377Simp int (* mlx_fw_handshake)(struct mlx_softc *sc, int *error, int *param1, int *param2); 178279377Simp#define MLX_INTACTION_DISABLE 0 179279377Simp#define MLX_INTACTION_ENABLE 1 180279377Simp}; 181279377Simp 182279377Simp/* 183279377Simp * Simple (stupid) locks. 184279377Simp * 185279377Simp * Note that these are designed to avoid reentrancy, not concurrency, and will 186279377Simp * need to be replaced with something better. 187279377Simp */ 188279377Simp#define MLX_LOCK_COMPLETING (1<<0) 189279377Simp#define MLX_LOCK_STARTING (1<<1) 190279377Simp 191279377Simpstatic __inline int 192279377Simpmlx_lock_tas(struct mlx_softc *sc, int lock) 193279377Simp{ 194279377Simp if ((sc)->mlx_locks & (lock)) 195279377Simp return(1); 196279377Simp atomic_set_int(&sc->mlx_locks, lock); 197279377Simp return(0); 198279377Simp} 199279377Simp 200279377Simpstatic __inline void 201279377Simpmlx_lock_clr(struct mlx_softc *sc, int lock) 202279377Simp{ 203279377Simp atomic_clear_int(&sc->mlx_locks, lock); 204279377Simp} 205279377Simp 206279377Simp/* 207279377Simp * Interface between bus connections and driver core. 208279377Simp */ 209279377Simpextern void mlx_free(struct mlx_softc *sc); 210279377Simpextern int mlx_attach(struct mlx_softc *sc); 211279377Simpextern void mlx_startup(struct mlx_softc *sc); 212279377Simpextern void mlx_intr(void *data); 213279377Simpextern int mlx_detach(device_t dev); 214279377Simpextern int mlx_shutdown(device_t dev); 215279377Simpextern int mlx_suspend(device_t dev); 216279377Simpextern int mlx_resume(device_t dev); 217279377Simpextern d_open_t mlx_open; 218279377Simpextern d_close_t mlx_close; 219279377Simpextern d_ioctl_t mlx_ioctl; 220279377Simp 221279377Simpextern devclass_t mlx_devclass; 222279377Simpextern devclass_t mlxd_devclass; 223279377Simp 224279377Simp/* 225279377Simp * Mylex System Disk driver 226279377Simp */ 227279377Simpstruct mlxd_softc 228279377Simp{ 229279377Simp device_t mlxd_dev; 230279377Simp struct mlx_softc *mlxd_controller; 231279377Simp struct mlx_sysdrive *mlxd_drive; 232279377Simp struct disk *mlxd_disk; 233279377Simp int mlxd_unit; 234279377Simp int mlxd_flags; 235279377Simp#define MLXD_OPEN (1<<0) /* drive is open (can't shut down) */ 236279377Simp}; 237279377Simp 238279377Simp/* 239279377Simp * Interface between driver core and disk driver (should be using a bus?) 240279377Simp */ 241279377Simpextern int mlx_submit_buf(struct mlx_softc *sc, mlx_bio *bp); 242279377Simpextern int mlx_submit_ioctl(struct mlx_softc *sc, 243279377Simp struct mlx_sysdrive *drive, u_long cmd, 244279377Simp caddr_t addr, int32_t flag, struct thread *td); 245279377Simpextern void mlxd_intr(void *data); 246279377Simp 247279377Simp 248279377Simp