2 * Copyright (c) HighPoint Technologies, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
28 #include <dev/hptrr/hptrr_config.h>
29 /* $Id: os_bsd.h,v 1.18 2006/04/11 08:19:02 gmm Exp $
31 * HighPoint RAID Driver for FreeBSD
32 * Copyright (C) 2005 HighPoint Technologies, Inc. All Rights Reserved.
42 #include <sys/param.h>
43 #include <sys/types.h>
45 #if (__FreeBSD_version >= 500000)
47 #include <sys/systm.h>
49 #include <machine/clock.h> /*to support DELAY function under 4.x BSD versions*/
53 #include <sys/malloc.h>
55 #include <sys/libkern.h>
56 #include <sys/kernel.h>
58 #if (__FreeBSD_version >= 500000)
59 #include <sys/kthread.h>
60 #include <sys/mutex.h>
61 #include <sys/module.h>
64 #include <sys/eventhandler.h>
66 #include <sys/taskqueue.h>
67 #include <sys/ioccom.h>
69 #include <machine/resource.h>
70 #include <machine/bus.h>
71 #include <machine/stdarg.h>
77 #if (__FreeBSD_version >= 500000)
78 #include <dev/pci/pcireg.h>
79 #include <dev/pci/pcivar.h>
81 #include <pci/pcivar.h>
82 #include <pci/pcireg.h>
85 #if (__FreeBSD_version <= 500043)
86 #include <sys/devicestat.h>
90 #include <cam/cam_ccb.h>
91 #include <cam/cam_sim.h>
92 #include <cam/cam_xpt_sim.h>
93 #include <cam/cam_debug.h>
94 #include <cam/cam_periph.h>
95 #include <cam/scsi/scsi_all.h>
96 #include <cam/scsi/scsi_message.h>
98 #if (__FreeBSD_version < 500043)
99 #include <sys/bus_private.h>
103 typedef struct _INQUIRYDATA {
104 u_char DeviceType : 5;
105 u_char DeviceTypeQualifier : 3;
106 u_char DeviceTypeModifier : 7;
107 u_char RemovableMedia : 1;
109 u_char ResponseDataFormat;
110 u_char AdditionalLength;
112 u_char SoftReset : 1;
113 u_char CommandQueue : 1;
114 u_char Reserved2 : 1;
115 u_char LinkedCommands : 1;
116 u_char Synchronous : 1;
117 u_char Wide16Bit : 1;
118 u_char Wide32Bit : 1;
119 u_char RelativeAddressing : 1;
121 u_char ProductId[16];
122 u_char ProductRevisionLevel[4];
123 u_char VendorSpecific[20];
124 u_char Reserved3[40];
126 __attribute__((packed))
127 INQUIRYDATA, *PINQUIRYDATA;
131 /* private headers */
133 #include <dev/hptrr/osm.h>
134 #include <dev/hptrr/him.h>
135 #include <dev/hptrr/ldm.h>
137 /* driver parameters */
138 extern char driver_name[];
139 extern char driver_name_long[];
140 extern char driver_ver[];
141 extern int osm_max_targets;
144 * adapter/vbus extensions:
145 * each physical controller has an adapter_ext, passed to him.create_adapter()
146 * each vbus has a vbus_ext passed to ldm_create_vbus().
148 #define EXT_TYPE_HBA 1
149 #define EXT_TYPE_VBUS 2
151 typedef struct _hba {
153 LDM_ADAPTER ldm_adapter;
156 struct _vbus_ext *vbus_ext;
160 struct resource *res;
167 struct resource *irq_res;
172 typedef struct _os_cmdext {
173 struct _vbus_ext *vbus_ext;
174 struct _os_cmdext *next;
176 bus_dmamap_t dma_map;
177 SG psg[os_max_sg_descriptors];
179 OS_CMDEXT, *POS_CMDEXT;
181 typedef struct _vbus_ext {
183 struct _vbus_ext *next;
185 struct freelist *freelist_head;
186 struct freelist *freelist_dma_head;
188 struct cam_sim *sim; /* sim for this vbus */
189 struct cam_path *path; /* peripheral, path, tgt, lun with this vbus */
190 #if (__FreeBSD_version >= 500000)
191 struct mtx lock; /* general purpose lock */
195 bus_dma_tag_t io_dmat; /* I/O buffer DMA tag */
197 POS_CMDEXT cmdext_list;
202 struct callout_handle timer;
204 eventhandler_tag shutdown_eh;
206 /* the LDM vbus instance continues */
207 unsigned long vbus[0] __attribute__((aligned(sizeof(unsigned long))));
209 VBUS_EXT, *PVBUS_EXT;
211 #if __FreeBSD_version >= 500000
212 #define hpt_lock_vbus(vbus_ext) mtx_lock(&(vbus_ext)->lock)
213 #define hpt_unlock_vbus(vbus_ext) mtx_unlock(&(vbus_ext)->lock)
215 static __inline void hpt_lock_vbus(PVBUS_EXT vbus_ext)
217 vbus_ext->hpt_splx = splcam();
219 static __inline void hpt_unlock_vbus(PVBUS_EXT vbus_ext)
221 splx(vbus_ext->hpt_splx);
226 #define HPT_OSM_TIMEOUT (20*hz) /* timeout value for OS commands */
228 #define HPT_DO_IOCONTROL _IOW('H', 0, HPT_IOCTL_PARAM)
230 #define HPT_SCAN_BUS _IO('H', 1)
232 #if __FreeBSD_version >= 501000
233 #define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi_giant,(task));
235 #define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi,(task));
238 #if __FreeBSD_version >= 500000
239 static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
241 return msleep(ident, &vbus_ext->lock, priority, wmesg, timo);
244 static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
248 asleep(ident, priority, wmesg, timo);
249 hpt_unlock_vbus(vbus_ext);
250 retval = await(priority, timo);
251 hpt_lock_vbus(vbus_ext);
257 #if __FreeBSD_version < 501000
259 #define WRITE_16 0x8a
260 #define SERVICE_ACTION_IN 0x9e
263 #define HPT_DEV_MAJOR 200