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