1 /* $Id: os_bsd.h,v 1.20 2010/05/11 03:12:11 lcn Exp $ */
3 * HighPoint RAID Driver for FreeBSD
4 * Copyright (C) 2005-2011 HighPoint Technologies, Inc. All Rights Reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <dev/hptnr/hptnr_config.h>
40 #include <sys/param.h>
41 #include <sys/types.h>
43 #if (__FreeBSD_version >= 500000)
45 #include <sys/systm.h>
47 #include <machine/clock.h> /*to support DELAY function under 4.x BSD versions*/
51 #include <sys/malloc.h>
53 #include <sys/libkern.h>
54 #include <sys/kernel.h>
56 #if (__FreeBSD_version >= 500000)
57 #include <sys/kthread.h>
58 #include <sys/mutex.h>
59 #include <sys/module.h>
62 #include <sys/eventhandler.h>
64 #include <sys/taskqueue.h>
65 #include <sys/ioccom.h>
67 #include <machine/resource.h>
68 #if __FreeBSD_version >= 500043
69 #include <machine/pci_cfgreg.h>
71 #include <machine/bus.h>
72 #include <machine/stdarg.h>
78 #if (__FreeBSD_version >= 500000)
79 #include <dev/pci/pcireg.h>
80 #include <dev/pci/pcivar.h>
82 #include <pci/pcivar.h>
83 #include <pci/pcireg.h>
86 #if (__FreeBSD_version <= 500043)
87 #include <sys/devicestat.h>
91 #include <cam/cam_ccb.h>
92 #include <cam/cam_sim.h>
93 #include <cam/cam_xpt_sim.h>
94 #include <cam/cam_debug.h>
95 #include <cam/cam_xpt_periph.h>
96 #include <cam/cam_periph.h>
97 #include <cam/scsi/scsi_all.h>
98 #include <cam/scsi/scsi_message.h>
100 #if (__FreeBSD_version < 500043)
101 #include <sys/bus_private.h>
105 typedef struct _INQUIRYDATA {
106 u_char DeviceType : 5;
107 u_char DeviceTypeQualifier : 3;
108 u_char DeviceTypeModifier : 7;
109 u_char RemovableMedia : 1;
111 u_char ResponseDataFormat;
112 u_char AdditionalLength;
114 u_char SoftReset : 1;
115 u_char CommandQueue : 1;
116 u_char Reserved2 : 1;
117 u_char LinkedCommands : 1;
118 u_char Synchronous : 1;
119 u_char Wide16Bit : 1;
120 u_char Wide32Bit : 1;
121 u_char RelativeAddressing : 1;
123 u_char ProductId[16];
124 u_char ProductRevisionLevel[4];
125 u_char VendorSpecific[20];
126 u_char Reserved3[40];
128 __attribute__((packed))
129 INQUIRYDATA, *PINQUIRYDATA;
133 /* private headers */
135 #include <dev/hptnr/osm.h>
136 #include <dev/hptnr/him.h>
137 #include <dev/hptnr/ldm.h>
139 /* driver parameters */
140 extern const char driver_name[];
141 extern const char driver_name_long[];
142 extern const char driver_ver[];
143 extern int osm_max_targets;
146 * adapter/vbus extensions:
147 * each physical controller has an adapter_ext, passed to him.create_adapter()
148 * each vbus has a vbus_ext passed to ldm_create_vbus().
150 #define EXT_TYPE_HBA 1
151 #define EXT_TYPE_VBUS 2
153 typedef struct _hba {
155 LDM_ADAPTER ldm_adapter;
158 struct _vbus_ext *vbus_ext;
162 struct resource *res;
169 struct resource *irq_res;
174 typedef struct _os_cmdext {
175 struct _vbus_ext *vbus_ext;
176 struct _os_cmdext *next;
178 bus_dmamap_t dma_map;
179 SG psg[os_max_sg_descriptors];
181 OS_CMDEXT, *POS_CMDEXT;
183 typedef struct _vbus_ext {
185 struct _vbus_ext *next;
187 struct freelist *freelist_head;
188 struct freelist *freelist_dma_head;
190 struct cam_sim *sim; /* sim for this vbus */
191 struct cam_path *path; /* peripheral, path, tgt, lun with this vbus */
192 #if (__FreeBSD_version >= 500000)
193 struct mtx lock; /* general purpose lock */
197 bus_dma_tag_t io_dmat; /* I/O buffer DMA tag */
199 POS_CMDEXT cmdext_list;
204 struct callout_handle timer;
206 eventhandler_tag shutdown_eh;
208 /* the LDM vbus instance continues */
209 unsigned long vbus[0] __attribute__((aligned(sizeof(unsigned long))));
211 VBUS_EXT, *PVBUS_EXT;
213 #if __FreeBSD_version >= 500000
214 #define hpt_lock_vbus(vbus_ext) mtx_lock(&(vbus_ext)->lock)
215 #define hpt_unlock_vbus(vbus_ext) mtx_unlock(&(vbus_ext)->lock)
217 static __inline void hpt_lock_vbus(PVBUS_EXT vbus_ext)
219 vbus_ext->hpt_splx = splcam();
221 static __inline void hpt_unlock_vbus(PVBUS_EXT vbus_ext)
223 splx(vbus_ext->hpt_splx);
228 #define HPT_OSM_TIMEOUT (20*hz) /* timeout value for OS commands */
230 #define HPT_DO_IOCONTROL _IOW('H', 0, HPT_IOCTL_PARAM)
232 #define HPT_SCAN_BUS _IO('H', 1)
234 #if __FreeBSD_version >= 501000
235 #define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi_giant,(task));
237 #define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi,(task));
240 #if __FreeBSD_version >= 500000
241 static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
243 return msleep(ident, &vbus_ext->lock, priority, wmesg, timo);
246 static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
250 asleep(ident, priority, wmesg, timo);
251 hpt_unlock_vbus(vbus_ext);
252 retval = await(priority, timo);
253 hpt_lock_vbus(vbus_ext);
259 #if __FreeBSD_version < 501000
261 #define WRITE_16 0x8a
262 #define SERVICE_ACTION_IN 0x9e
265 #define HPT_DEV_MAJOR 200