xref: /dragonfly/sys/dev/raid/hpt27xx/os_bsd.h (revision ed183f8c)
1 /*-
2  * Copyright (c) 2011 HighPoint Technologies, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: src/sys/dev/hpt27xx/os_bsd.h,v 1.1 2011/12/28 23:26:58 delphij Exp $
27  */
28 
29 #include <dev/raid/hpt27xx/hpt27xx_config.h>
30 
31 #ifndef _OS_BSD_H
32 #define _OS_BSD_H
33 
34 #ifndef DBG
35 #define  DBG	0
36 #endif
37 
38 #include <sys/param.h>
39 #include <sys/types.h>
40 #include <sys/cons.h>
41 #include <sys/time.h>
42 #include <sys/systm.h>
43 
44 #include <sys/stat.h>
45 #include <sys/malloc.h>
46 #include <sys/conf.h>
47 #include <sys/kernel.h>
48 
49 #include <sys/kthread.h>
50 #include <sys/module.h>
51 
52 #include <sys/eventhandler.h>
53 #include <sys/bus.h>
54 #include <sys/taskqueue.h>
55 #include <sys/ioccom.h>
56 #include <sys/mplock2.h>
57 #include <sys/device.h>
58 
59 #include <bus/pci/pci_cfgreg.h>
60 #include <machine/stdarg.h>
61 #include <sys/rman.h>
62 
63 #include <vm/vm.h>
64 #include <vm/pmap.h>
65 
66 #include <bus/pci/pcireg.h>
67 #include <bus/pci/pcivar.h>
68 
69 #include <bus/cam/cam.h>
70 #include <bus/cam/cam_ccb.h>
71 #include <bus/cam/cam_sim.h>
72 #include <bus/cam/cam_xpt_sim.h>
73 #include <bus/cam/cam_debug.h>
74 #include <bus/cam/cam_xpt_periph.h>
75 #include <bus/cam/cam_periph.h>
76 #include <bus/cam/scsi/scsi_all.h>
77 #include <bus/cam/scsi/scsi_message.h>
78 
79 
80 
81 typedef struct _INQUIRYDATA {
82 	u_char DeviceType : 5;
83 	u_char DeviceTypeQualifier : 3;
84 	u_char DeviceTypeModifier : 7;
85 	u_char RemovableMedia : 1;
86 	u_char Versions;
87 	u_char ResponseDataFormat;
88 	u_char AdditionalLength;
89 	u_char Reserved[2];
90 	u_char SoftReset : 1;
91 	u_char CommandQueue : 1;
92 	u_char Reserved2 : 1;
93 	u_char LinkedCommands : 1;
94 	u_char Synchronous : 1;
95 	u_char Wide16Bit : 1;
96 	u_char Wide32Bit : 1;
97 	u_char RelativeAddressing : 1;
98 	u_char VendorId[8];
99 	u_char ProductId[16];
100 	u_char ProductRevisionLevel[4];
101 	u_char VendorSpecific[20];
102 	u_char Reserved3[40];
103 }
104 __attribute__((packed))
105 INQUIRYDATA, *PINQUIRYDATA;
106 
107 #endif
108 
109 /* private headers */
110 
111 #include <dev/raid/hpt27xx/osm.h>
112 #include <dev/raid/hpt27xx/him.h>
113 #include <dev/raid/hpt27xx/ldm.h>
114 
115 /* driver parameters */
116 extern char driver_name[];
117 extern char driver_name_long[];
118 extern char driver_ver[];
119 extern int  osm_max_targets;
120 
121 /*
122  * adapter/vbus extensions:
123  * each physical controller has an adapter_ext, passed to him.create_adapter()
124  * each vbus has a vbus_ext passed to ldm_create_vbus().
125  */
126 #define EXT_TYPE_HBA  1
127 #define EXT_TYPE_VBUS 2
128 
129 typedef struct _hba {
130 	int               ext_type;
131 	LDM_ADAPTER       ldm_adapter;
132 	device_t          pcidev;
133 	PCI_ADDRESS       pciaddr;
134 	struct _vbus_ext *vbus_ext;
135 	struct _hba      *next;
136 
137 	struct {
138 		struct resource *res;
139 		int type;
140 		int rid;
141 		void *base;
142 	}
143 	pcibar[6];
144 
145 	struct resource  *irq_res;
146 	void             *irq_handle;
147 }
148 HBA, *PHBA;
149 
150 typedef struct _os_cmdext {
151 	struct _vbus_ext  *vbus_ext;
152 	struct _os_cmdext *next;
153 	union ccb         *ccb;
154 	bus_dmamap_t       dma_map;
155 	SG                 psg[os_max_sg_descriptors];
156 }
157 OS_CMDEXT, *POS_CMDEXT;
158 
159 typedef struct _vbus_ext {
160 	int               ext_type;
161 	struct _vbus_ext *next;
162 	PHBA              hba_list;
163 	struct freelist  *freelist_head;
164 	struct freelist  *freelist_dma_head;
165 
166 	struct cam_sim   *sim;    /* sim for this vbus */
167 	struct cam_path  *path;   /* peripheral, path, tgt, lun with this vbus */
168 	struct lock       lock; /* general purpose lock */
169 	bus_dma_tag_t     io_dmat; /* I/O buffer DMA tag */
170 
171 	POS_CMDEXT        cmdext_list;
172 
173 	OSM_TASK         *tasks;
174 	struct task       worker;
175 
176 	struct callout    timer;
177 
178 	eventhandler_tag  shutdown_eh;
179 
180 	/* the LDM vbus instance continues */
181 	unsigned long vbus[0] __attribute__((aligned(sizeof(unsigned long))));
182 }
183 VBUS_EXT, *PVBUS_EXT;
184 
185 #define hpt_lock_vbus(vbus_ext)   lockmgr(&(vbus_ext)->lock, LK_EXCLUSIVE)
186 #define hpt_unlock_vbus(vbus_ext) lockmgr(&(vbus_ext)->lock, LK_RELEASE)
187 
188 #define HPT27XX_DFLTPHYS  (64 * 1024)
189 
190 #define HPT_OSM_TIMEOUT (20*hz)  /* timeout value for OS commands */
191 
192 #define HPT_DO_IOCONTROL	_IOW('H', 0, HPT_IOCTL_PARAM)
193 
194 #define HPT_SCAN_BUS		_IO('H', 1)
195 
196 #define TASK_ENQUEUE(task)	taskqueue_enqueue(taskqueue_swi,(task));
197 
198 static	__inline	int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
199 {
200 	return	lksleep(ident, &vbus_ext->lock, priority, wmesg, timo);
201 }
202