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