summaryrefslogtreecommitdiffstats
path: root/sys/dev/hptnr/os_bsd.h
blob: 8fda2677c7cb57ef933dbb78428658ae9be3b6e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/* $Id: os_bsd.h,v 1.20 2010/05/11 03:12:11 lcn Exp $ */
/*-
 * HighPoint RAID Driver for FreeBSD
 * Copyright (C) 2005-2011 HighPoint Technologies, Inc. All Rights Reserved.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#include <dev/hptnr/hptnr_config.h>

#ifndef _OS_BSD_H
#define _OS_BSD_H

#ifndef DBG
#define  DBG	0
#endif

#include <sys/param.h>
#include <sys/types.h>
#include <sys/cons.h>
#if (__FreeBSD_version >= 500000) 
#include <sys/time.h>
#include <sys/systm.h> 
#else 
#include <machine/clock.h>	/*to support DELAY function under 4.x BSD versions*/
#endif

#include <sys/stat.h>
#include <sys/malloc.h>
#include <sys/conf.h>
#include <sys/libkern.h>
#include <sys/kernel.h>

#if (__FreeBSD_version >= 500000)
#include <sys/kthread.h>
#include <sys/mutex.h>
#include <sys/module.h>
#endif

#include <sys/eventhandler.h>
#include <sys/bus.h>
#include <sys/taskqueue.h>
#include <sys/ioccom.h>

#include <machine/resource.h>
#if __FreeBSD_version >= 500043
#include <machine/pci_cfgreg.h>
#endif
#include <machine/bus.h>
#include <machine/stdarg.h>
#include <sys/rman.h>

#include <vm/vm.h>
#include <vm/pmap.h>

#if (__FreeBSD_version >= 500000)
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#else 
#include <pci/pcivar.h>
#include <pci/pcireg.h>
#endif

#if (__FreeBSD_version <= 500043)
#include <sys/devicestat.h>
#endif

#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_sim.h>
#include <cam/cam_xpt_sim.h>
#include <cam/cam_debug.h>
#include <cam/cam_xpt_periph.h>
#include <cam/cam_periph.h>
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_message.h>

#if (__FreeBSD_version < 500043)
#include <sys/bus_private.h>
#endif


typedef struct _INQUIRYDATA {
	u_char DeviceType : 5;
	u_char DeviceTypeQualifier : 3;
	u_char DeviceTypeModifier : 7;
	u_char RemovableMedia : 1;
	u_char Versions;
	u_char ResponseDataFormat;
	u_char AdditionalLength;
	u_char Reserved[2];
	u_char SoftReset : 1;
	u_char CommandQueue : 1;
	u_char Reserved2 : 1;
	u_char LinkedCommands : 1;
	u_char Synchronous : 1;
	u_char Wide16Bit : 1;
	u_char Wide32Bit : 1;
	u_char RelativeAddressing : 1;
	u_char VendorId[8];
	u_char ProductId[16];
	u_char ProductRevisionLevel[4];
	u_char VendorSpecific[20];
	u_char Reserved3[40];
} 
__attribute__((packed))
INQUIRYDATA, *PINQUIRYDATA;

#endif

/* private headers */

#include <dev/hptnr/osm.h>
#include <dev/hptnr/him.h>
#include <dev/hptnr/ldm.h>

/* driver parameters */
extern const char driver_name[];
extern const char driver_name_long[];
extern const char driver_ver[];
extern int  osm_max_targets;

/*
 * adapter/vbus extensions:
 * each physical controller has an adapter_ext, passed to him.create_adapter()
 * each vbus has a vbus_ext passed to ldm_create_vbus().
 */
#define EXT_TYPE_HBA  1
#define EXT_TYPE_VBUS 2

typedef struct _hba {
	int               ext_type;
	LDM_ADAPTER       ldm_adapter;
	device_t          pcidev;
	PCI_ADDRESS       pciaddr;
	struct _vbus_ext *vbus_ext;
	struct _hba      *next;
	
	struct {
		struct resource *res;
		int type;
		int rid;
		void *base;
	}
	pcibar[6];

	struct resource  *irq_res;
	void             *irq_handle;
}
HBA, *PHBA;

typedef struct _os_cmdext {
	struct _vbus_ext  *vbus_ext;
	struct _os_cmdext *next;
	union ccb         *ccb;
	bus_dmamap_t       dma_map;
	struct callout_handle timeout_ch;
	SG                 psg[os_max_sg_descriptors];
}
OS_CMDEXT, *POS_CMDEXT;

typedef struct _vbus_ext {
	int               ext_type;
	struct _vbus_ext *next;
	PHBA              hba_list;
	struct freelist  *freelist_head;
	struct freelist  *freelist_dma_head;
	
	struct cam_sim   *sim;    /* sim for this vbus */
	struct cam_path  *path;   /* peripheral, path, tgt, lun with this vbus */
#if (__FreeBSD_version >= 500000)
	struct mtx        lock; /* general purpose lock */
#else 
	int  			hpt_splx;
#endif
	bus_dma_tag_t     io_dmat; /* I/O buffer DMA tag */
	
	POS_CMDEXT        cmdext_list;

	OSM_TASK         *tasks;
	struct task       worker;
	
	struct callout_handle timer;

	eventhandler_tag  shutdown_eh;
	
	/* the LDM vbus instance continues */
	unsigned long vbus[0] __attribute__((aligned(sizeof(unsigned long))));
}
VBUS_EXT, *PVBUS_EXT;

#if __FreeBSD_version >= 500000
#define hpt_lock_vbus(vbus_ext)   mtx_lock(&(vbus_ext)->lock)
#define hpt_unlock_vbus(vbus_ext) mtx_unlock(&(vbus_ext)->lock)
#else 
static __inline	void	hpt_lock_vbus(PVBUS_EXT	vbus_ext)
{
	vbus_ext->hpt_splx = splcam();
}
static __inline	void	hpt_unlock_vbus(PVBUS_EXT vbus_ext)
{
	splx(vbus_ext->hpt_splx);
}
#endif


#define HPT_OSM_TIMEOUT (20*hz)  /* timeout value for OS commands */

#define HPT_DO_IOCONTROL	_IOW('H', 0, HPT_IOCTL_PARAM)

#define HPT_SCAN_BUS		_IO('H', 1)

#if __FreeBSD_version >= 501000
#define TASK_ENQUEUE(task)	taskqueue_enqueue(taskqueue_swi_giant,(task));
#else 
#define TASK_ENQUEUE(task)	taskqueue_enqueue(taskqueue_swi,(task));
#endif

#if __FreeBSD_version >= 500000
static	__inline	int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
{
	return	msleep(ident, &vbus_ext->lock, priority, wmesg, timo);
}
#else 
static	__inline	int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
{
	int retval = 0;
	
	asleep(ident, priority, wmesg, timo);
	hpt_unlock_vbus(vbus_ext);
	retval = await(priority, timo);
	hpt_lock_vbus(vbus_ext);
	
	return retval;
}
#endif

#if __FreeBSD_version < 501000
#define	READ_16				0x88
#define WRITE_16			0x8a
#define SERVICE_ACTION_IN	0x9e
#endif

#define	HPT_DEV_MAJOR	200

OpenPOWER on IntegriCloud