1 #include <dev/rr232x/rr232x_config.h>
2 /* $Id: os_bsd.h,v 1.18 2006/04/11 08:19:02 gmm Exp $
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
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.
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
33 #include <sys/param.h>
34 #include <sys/types.h>
36 #if (__FreeBSD_version >= 500000)
38 #include <sys/systm.h>
40 #include <machine/clock.h> /*to support DELAY function under 4.x BSD versions*/
44 #include <sys/malloc.h>
46 #include <sys/libkern.h>
47 #include <sys/kernel.h>
49 #if (__FreeBSD_version >= 500000)
50 #include <sys/kthread.h>
51 #include <sys/mutex.h>
52 #include <sys/module.h>
55 #include <sys/eventhandler.h>
57 #include <sys/taskqueue.h>
58 #include <sys/ioccom.h>
60 #include <machine/resource.h>
61 #include <machine/bus.h>
62 #include <machine/stdarg.h>
68 #if (__FreeBSD_version >= 500000)
69 #include <dev/pci/pcireg.h>
70 #include <dev/pci/pcivar.h>
72 #include <pci/pcivar.h>
73 #include <pci/pcireg.h>
76 #if (__FreeBSD_version <= 500043)
77 #include <sys/devicestat.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>
90 #if (__FreeBSD_version < 500043)
91 #include <sys/bus_private.h>
95 typedef struct _INQUIRYDATA {
96 u_char DeviceType : 5;
97 u_char DeviceTypeQualifier : 3;
98 u_char DeviceTypeModifier : 7;
99 u_char RemovableMedia : 1;
101 u_char ResponseDataFormat;
102 u_char AdditionalLength;
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;
113 u_char ProductId[16];
114 u_char ProductRevisionLevel[4];
115 u_char VendorSpecific[20];
116 u_char Reserved3[40];
118 __attribute__((packed))
119 INQUIRYDATA, *PINQUIRYDATA;
123 /* private headers */
125 #include <dev/rr232x/osm.h>
126 #include <dev/rr232x/him.h>
127 #include <dev/rr232x/ldm.h>
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;
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().
140 #define EXT_TYPE_HBA 1
141 #define EXT_TYPE_VBUS 2
143 typedef struct _hba {
145 LDM_ADAPTER ldm_adapter;
148 struct _vbus_ext *vbus_ext;
152 struct resource *res;
159 struct resource *irq_res;
164 typedef struct _os_cmdext {
165 struct _vbus_ext *vbus_ext;
166 struct _os_cmdext *next;
168 bus_dmamap_t dma_map;
169 SG psg[os_max_sg_descriptors];
171 OS_CMDEXT, *POS_CMDEXT;
173 typedef struct _vbus_ext {
175 struct _vbus_ext *next;
177 struct freelist *freelist_head;
178 struct freelist *freelist_dma_head;
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 */
187 bus_dma_tag_t io_dmat; /* I/O buffer DMA tag */
189 POS_CMDEXT cmdext_list;
194 struct callout_handle timer;
196 eventhandler_tag shutdown_eh;
198 /* the LDM vbus instance continues */
199 unsigned long vbus[0] __attribute__((aligned(sizeof(unsigned long))));
201 VBUS_EXT, *PVBUS_EXT;
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)
207 static __inline void hpt_lock_vbus(PVBUS_EXT vbus_ext)
209 vbus_ext->hpt_splx = splcam();
211 static __inline void hpt_unlock_vbus(PVBUS_EXT vbus_ext)
213 splx(vbus_ext->hpt_splx);
218 #define HPT_OSM_TIMEOUT (20*hz) /* timeout value for OS commands */
220 #define HPT_DO_IOCONTROL _IOW('H', 0, HPT_IOCTL_PARAM)
222 #define HPT_SCAN_BUS _IO('H', 1)
224 #if __FreeBSD_version >= 501000
225 #define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi_giant,(task));
227 #define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi,(task));
230 #if __FreeBSD_version >= 500000
231 static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
233 return msleep(ident, &vbus_ext->lock, priority, wmesg, timo);
236 static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
240 asleep(ident, priority, wmesg, timo);
241 hpt_unlock_vbus(vbus_ext);
242 retval = await(priority, timo);
243 hpt_lock_vbus(vbus_ext);
249 #if __FreeBSD_version < 501000
251 #define WRITE_16 0x8a
252 #define SERVICE_ACTION_IN 0x9e
255 #define HPT_DEV_MAJOR 200