xref: /freebsd/sys/dev/hptrr/os_bsd.h (revision fcb560670601b2a4d87bb31d7531c8dcc37ee71b)
1 /*
2  * Copyright (c) HighPoint Technologies, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 #include <dev/hptrr/hptrr_config.h>
29 /* $Id: os_bsd.h,v 1.18 2006/04/11 08:19:02 gmm Exp $
30  *
31  * HighPoint RAID Driver for FreeBSD
32  * Copyright (C) 2005 HighPoint Technologies, Inc. All Rights Reserved.
33  */
34 
35 #ifndef _OS_BSD_H
36 #define _OS_BSD_H
37 
38 #ifndef DBG
39 #define  DBG	0
40 #endif
41 
42 #include <sys/param.h>
43 #include <sys/types.h>
44 #include <sys/cons.h>
45 #include <sys/time.h>
46 #include <sys/systm.h>
47 
48 #include <sys/stat.h>
49 #include <sys/malloc.h>
50 #include <sys/conf.h>
51 #include <sys/libkern.h>
52 #include <sys/kernel.h>
53 
54 #include <sys/kthread.h>
55 #include <sys/mutex.h>
56 #include <sys/module.h>
57 
58 #include <sys/eventhandler.h>
59 #include <sys/bus.h>
60 #include <sys/taskqueue.h>
61 #include <sys/ioccom.h>
62 
63 #include <machine/resource.h>
64 #include <machine/bus.h>
65 #include <machine/stdarg.h>
66 #include <sys/rman.h>
67 
68 #include <vm/vm.h>
69 #include <vm/pmap.h>
70 
71 #include <dev/pci/pcireg.h>
72 #include <dev/pci/pcivar.h>
73 
74 #include <cam/cam.h>
75 #include <cam/cam_ccb.h>
76 #include <cam/cam_sim.h>
77 #include <cam/cam_xpt_sim.h>
78 #include <cam/cam_debug.h>
79 #include <cam/cam_periph.h>
80 #include <cam/scsi/scsi_all.h>
81 #include <cam/scsi/scsi_message.h>
82 
83 
84 
85 typedef struct _INQUIRYDATA {
86 	u_char DeviceType : 5;
87 	u_char DeviceTypeQualifier : 3;
88 	u_char DeviceTypeModifier : 7;
89 	u_char RemovableMedia : 1;
90 	u_char Versions;
91 	u_char ResponseDataFormat;
92 	u_char AdditionalLength;
93 	u_char Reserved[2];
94 	u_char SoftReset : 1;
95 	u_char CommandQueue : 1;
96 	u_char Reserved2 : 1;
97 	u_char LinkedCommands : 1;
98 	u_char Synchronous : 1;
99 	u_char Wide16Bit : 1;
100 	u_char Wide32Bit : 1;
101 	u_char RelativeAddressing : 1;
102 	u_char VendorId[8];
103 	u_char ProductId[16];
104 	u_char ProductRevisionLevel[4];
105 	u_char VendorSpecific[20];
106 	u_char Reserved3[40];
107 }
108 __attribute__((packed))
109 INQUIRYDATA, *PINQUIRYDATA;
110 
111 #endif
112 
113 /* private headers */
114 
115 #include <dev/hptrr/osm.h>
116 #include <dev/hptrr/him.h>
117 #include <dev/hptrr/ldm.h>
118 
119 /* driver parameters */
120 extern char driver_name[];
121 extern char driver_name_long[];
122 extern char driver_ver[];
123 extern int  osm_max_targets;
124 
125 /*
126  * adapter/vbus extensions:
127  * each physical controller has an adapter_ext, passed to him.create_adapter()
128  * each vbus has a vbus_ext passed to ldm_create_vbus().
129  */
130 #define EXT_TYPE_HBA  1
131 #define EXT_TYPE_VBUS 2
132 
133 typedef struct _hba {
134 	int               ext_type;
135 	LDM_ADAPTER       ldm_adapter;
136 	device_t          pcidev;
137 	PCI_ADDRESS       pciaddr;
138 	struct _vbus_ext *vbus_ext;
139 	struct _hba      *next;
140 
141 	struct {
142 		struct resource *res;
143 		int type;
144 		int rid;
145 		void *base;
146 	}
147 	pcibar[6];
148 
149 	struct resource  *irq_res;
150 	void             *irq_handle;
151 }
152 HBA, *PHBA;
153 
154 typedef struct _os_cmdext {
155 	struct _vbus_ext  *vbus_ext;
156 	struct _os_cmdext *next;
157 	union ccb         *ccb;
158 	bus_dmamap_t       dma_map;
159 	struct callout     timeout;
160 	SG                 psg[os_max_sg_descriptors];
161 }
162 OS_CMDEXT, *POS_CMDEXT;
163 
164 typedef struct _vbus_ext {
165 	int               ext_type;
166 	struct _vbus_ext *next;
167 	PHBA              hba_list;
168 	struct freelist  *freelist_head;
169 	struct freelist  *freelist_dma_head;
170 
171 	struct cam_sim   *sim;    /* sim for this vbus */
172 	struct cam_path  *path;   /* peripheral, path, tgt, lun with this vbus */
173 	struct mtx        lock; /* general purpose lock */
174 	bus_dma_tag_t     io_dmat; /* I/O buffer DMA tag */
175 
176 	POS_CMDEXT        cmdext_list;
177 
178 	OSM_TASK         *tasks;
179 	struct task       worker;
180 
181 	struct callout    timer;
182 
183 	eventhandler_tag  shutdown_eh;
184 
185 	/* the LDM vbus instance continues */
186 	unsigned long vbus[0] __attribute__((aligned(sizeof(unsigned long))));
187 }
188 VBUS_EXT, *PVBUS_EXT;
189 
190 #define hpt_lock_vbus(vbus_ext)   mtx_lock(&(vbus_ext)->lock)
191 #define hpt_unlock_vbus(vbus_ext) mtx_unlock(&(vbus_ext)->lock)
192 #define hpt_assert_vbus_locked(vbus_ext)   mtx_assert(&(vbus_ext)->lock, MA_OWNED)
193 
194 
195 #define HPT_OSM_TIMEOUT (20*hz)  /* timeout value for OS commands */
196 
197 #define HPT_DO_IOCONTROL	_IOW('H', 0, HPT_IOCTL_PARAM)
198 
199 #define HPT_SCAN_BUS		_IO('H', 1)
200 
201 #define TASK_ENQUEUE(task)	taskqueue_enqueue(taskqueue_swi,(task));
202 
203 static	__inline	int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
204 {
205 	return	msleep(ident, &vbus_ext->lock, priority, wmesg, timo);
206 }
207