]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/hptmv/osbsd.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / hptmv / osbsd.h
1 /*
2  * Copyright (c) 2004-2005 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$
27  */
28 #ifndef _OSBSD_H_
29 #define _OSBSD_H_
30
31 #include <sys/bus.h>
32 #include <sys/resource.h>
33 #include <sys/eventhandler.h>
34 #include <sys/devicestat.h>
35
36 #if (__FreeBSD_version < 500043)
37 #include <stddef.h>
38 #include <sys/buf.h>
39 #endif
40
41 #include <vm/vm.h>
42 #include <vm/pmap.h>
43 #include <vm/vm_extern.h>
44
45 #if (__FreeBSD_version < 600000)
46 #include <machine/bus_memio.h>
47 #endif
48 #include <machine/bus.h>
49 #include <machine/resource.h>
50 #include <machine/bus.h>
51
52 #include <sys/rman.h>
53
54 #include <cam/cam.h>
55 #include <cam/cam_ccb.h>
56 #include <cam/cam_debug.h>
57 #include <cam/cam_sim.h>
58 #include <cam/cam_xpt_sim.h>
59 #include <cam/cam_periph.h>
60
61 #include <cam/scsi/scsi_all.h>
62 #include <cam/scsi/scsi_message.h>
63
64
65
66 extern intrmask_t lock_driver(void);
67 extern void unlock_driver(intrmask_t spl);
68
69 typedef struct 
70 {
71         UCHAR           status;                 /* 0 nonbootable; 80h bootable */
72         UCHAR           start_head;
73         USHORT          start_sector;
74         UCHAR           type;
75         UCHAR           end_head;
76         USHORT          end_sector;
77         ULONG           start_abs_sector;
78         ULONG           num_of_sector;
79 } partition;
80
81 typedef struct _INQUIRYDATA {
82         UCHAR DeviceType : 5;
83         UCHAR DeviceTypeQualifier : 3;
84         UCHAR DeviceTypeModifier : 7;
85         UCHAR RemovableMedia : 1;
86         UCHAR Versions;
87         UCHAR ResponseDataFormat;
88         UCHAR AdditionalLength;
89         UCHAR Reserved[2];
90         UCHAR SoftReset : 1;
91         UCHAR CommandQueue : 1;
92         UCHAR Reserved2 : 1;
93         UCHAR LinkedCommands : 1;
94         UCHAR Synchronous : 1;
95         UCHAR Wide16Bit : 1;
96         UCHAR Wide32Bit : 1;
97         UCHAR RelativeAddressing : 1;
98         UCHAR VendorId[8];
99         UCHAR ProductId[16];
100         UCHAR ProductRevisionLevel[4];
101         UCHAR VendorSpecific[20];
102         UCHAR Reserved3[40];
103 } INQUIRYDATA, *PINQUIRYDATA;
104
105 #define MV_IAL_HT_SACOALT_DEFAULT       1
106 #define MV_IAL_HT_SAITMTH_DEFAULT       1
107
108 /****************************************/
109 /*          GENERAL Definitions         */
110 /****************************************/
111
112 /* Bits for HD_ERROR */
113 #define NM_ERR                  0x02    /* media present */
114 #define ABRT_ERR                0x04    /* Command aborted */
115 #define MCR_ERR         0x08    /* media change request */
116 #define IDNF_ERR        0x10    /* ID field not found */
117 #define MC_ERR          0x20    /* media changed */
118 #define UNC_ERR         0x40    /* Uncorrect data */
119 #define WP_ERR          0x40    /* write protect */
120 #define ICRC_ERR        0x80    /* new meaning:  CRC error during transfer */
121
122 #define REQUESTS_ARRAY_SIZE                     (9 * MV_EDMA_REQUEST_QUEUE_SIZE) /* 9 K bytes */
123 #define RESPONSES_ARRAY_SIZE            (12 * MV_EDMA_RESPONSE_QUEUE_SIZE) /* 3 K bytes */
124
125 #define PRD_ENTRIES_PER_CMD         (MAX_SG_DESCRIPTORS+1)
126 #define PRD_ENTRIES_SIZE            (MV_EDMA_PRD_ENTRY_SIZE*PRD_ENTRIES_PER_CMD)
127 #define PRD_TABLES_FOR_VBUS         (MV_SATA_CHANNELS_NUM*MV_EDMA_QUEUE_LENGTH)
128
129 typedef enum _SataEvent
130 {
131     SATA_EVENT_NO_CHANGE = 0,
132         SATA_EVENT_CHANNEL_CONNECTED,
133         SATA_EVENT_CHANNEL_DISCONNECTED
134 } SATA_EVENT;
135
136 typedef ULONG_PTR dma_addr_t;
137
138 typedef struct _MV_CHANNEL
139 {
140         unsigned int            maxUltraDmaModeSupported;
141         unsigned int            maxDmaModeSupported;
142         unsigned int            maxPioModeSupported;
143         MV_BOOLEAN              online;
144         MV_BOOLEAN              writeCacheSupported;
145         MV_BOOLEAN              writeCacheEnabled;
146         MV_BOOLEAN              readAheadSupported;
147         MV_BOOLEAN              readAheadEnabled;
148         MV_U8                   queueDepth;
149         
150 } MV_CHANNEL;
151
152 typedef struct _BUS_DMAMAP
153 {       struct _BUS_DMAMAP              *next;
154         struct IALAdapter                       *pAdapter;
155         bus_dmamap_t                    dma_map;
156         struct callout_handle           timeout_ch;
157         SCAT_GATH                               psg[MAX_SG_DESCRIPTORS];
158 } BUS_DMAMAP, *PBUS_DMAMAP;
159
160 typedef struct IALAdapter 
161 {
162         struct cam_path         *path;
163
164         bus_dma_tag_t     io_dma_parent; /* I/O buffer DMA tag */
165         PBUS_DMAMAP       pbus_dmamap_list;
166         PBUS_DMAMAP       pbus_dmamap;
167
168         device_t                        hpt_dev;                                /* bus device */
169         struct resource         *hpt_irq;                                       /* interrupt */
170         struct resource         *mem_res;
171         void                            *hpt_intr;                              /* interrupt handle */
172         struct IALAdapter   *next;
173
174         MV_SATA_ADAPTER     mvSataAdapter;
175         MV_CHANNEL          mvChannel[MV_SATA_CHANNELS_NUM];
176         MV_U8                           *requestsArrayBaseAddr;
177         MV_U8                           *requestsArrayBaseAlignedAddr;
178         dma_addr_t                      requestsArrayBaseDmaAddr;
179         dma_addr_t                      requestsArrayBaseDmaAlignedAddr;
180         MV_U8                           *responsesArrayBaseAddr;
181         MV_U8                           *responsesArrayBaseAlignedAddr;
182         dma_addr_t                      responsesArrayBaseDmaAddr;
183         dma_addr_t                      responsesArrayBaseDmaAlignedAddr;
184         SATA_EVENT                      sataEvents[MV_SATA_CHANNELS_NUM];
185         
186         struct  callout_handle event_timer_connect;
187         struct  callout_handle event_timer_disconnect;
188
189         struct _VBus        VBus;
190         struct _VDevice     VDevices[MV_SATA_CHANNELS_NUM];
191         PCommand                        pCommandBlocks;
192         PUCHAR                          prdTableAddr;
193         PUCHAR                          prdTableAlignedAddr;
194         void*                           pFreePRDLink;
195
196         union ccb           *pending_Q;
197
198         MV_U8                           outstandingCommands;
199
200         UCHAR               status;
201         UCHAR               ver_601;
202         UCHAR               beeping;
203
204         eventhandler_tag        eh;
205 }
206 IAL_ADAPTER_T;
207
208 extern IAL_ADAPTER_T *gIal_Adapter;
209
210 /*entry.c*/
211 typedef void (*HPT_DPC)(IAL_ADAPTER_T *,void*,UCHAR);
212
213 int hpt_queue_dpc(HPT_DPC dpc, IAL_ADAPTER_T *pAdapter, void *arg, UCHAR flags);
214 void hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray, UCHAR flags);
215 void Check_Idle_Call(IAL_ADAPTER_T *pAdapter);
216 void fRescanAllDevice(_VBUS_ARG0);
217 int hpt_add_disk_to_array(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk);
218
219 int Kernel_DeviceIoControl(_VBUS_ARG
220                                                         DWORD dwIoControlCode,          /* operation control code */
221                                                         PVOID lpInBuffer,               /* input data buffer */
222                                                         DWORD nInBufferSize,            /* size of input data buffer */
223                                                         PVOID lpOutBuffer,              /* output data buffer */
224                                                         DWORD nOutBufferSize,           /* size of output data buffer */
225                                                         PDWORD lpBytesReturned          /* byte count */
226                                                 );
227
228
229 #define __str_direct(x) #x
230 #define __str(x) __str_direct(x)
231 #define KMSG_LEADING __str(PROC_DIR_NAME) ": "
232 #define hpt_printk(_x_) do { printf(KMSG_LEADING); printf _x_ ; } while (0)
233
234 #define DUPLICATE      0
235 #define INITIALIZE     1
236 #define REBUILD_PARITY 2
237 #define VERIFY         3
238
239 /***********************************************************/
240
241 static __inline struct cam_periph *
242 hpt_get_periph(int path_id,int target_id)
243 {
244         struct cam_periph       *periph = NULL;
245     struct cam_path     *path;
246     int                 status;
247
248     status = xpt_create_path(&path, NULL, path_id, target_id, 0);
249     if (status == CAM_REQ_CMP) {
250                 periph = cam_periph_find(path, "da");
251                 xpt_free_path(path);
252                         
253     }
254         return periph;  
255 }
256
257 #if (__FreeBSD_version < 500000)
258 #define YIELD_THREAD yield(curproc, 0)
259 #endif
260
261 #ifdef __i386__
262 #define BITS_PER_LONG 32
263 #define VDEV_TO_ID(pVDev) (DEVICEID)(pVDev)
264 #define ID_TO_VDEV(id) (PVDevice)(id)
265 #else /*Only support x86_64(AMD64 and EM64T)*/
266 #define BITS_PER_LONG 64
267 #define VDEV_TO_ID(pVDev) (DEVICEID)(ULONG_PTR)(pVDev)
268 #define ID_TO_VDEV(id) (PVDevice)(((ULONG_PTR)gIal_Adapter & 0xffffffff00000000) | (id))
269 #endif
270
271 #define INVALID_DEVICEID                (-1)
272 #define INVALID_STRIPSIZE               (-1)
273
274 #define shortswap(w) ((WORD)((w)>>8 | ((w) & 0xFF)<<8))
275
276 #ifndef MinBlockSizeShift
277 #define MinBlockSizeShift 5
278 #define MaxBlockSizeShift 12
279 #endif
280
281 #pragma pack(1)
282 typedef struct _HPT_IOCTL_TRANSFER_PARAM
283 {
284         ULONG nInBufferSize;
285         ULONG nOutBufferSize;
286         UCHAR buffer[0];
287 }HPT_IOCTL_TRANSFER_PARAM, *PHPT_IOCTL_TRANSFER_PARAM;
288
289 typedef struct _HPT_SET_STATE_PARAM
290 {
291         DEVICEID idArray;
292         DWORD state;
293 } HPT_SET_STATE_PARAM, *PHPT_SET_STATE_PARAM;
294
295 typedef struct _HPT_SET_ARRAY_INFO
296 {
297         DEVICEID idArray;
298         ALTERABLE_ARRAY_INFO Info;
299 } HPT_SET_ARRAY_INFO, *PHPT_SET_ARRAY_INFO;
300
301 typedef struct _HPT_SET_DEVICE_INFO
302 {
303         DEVICEID idDisk;
304         ALTERABLE_DEVICE_INFO Info;
305 } HPT_SET_DEVICE_INFO, *PHPT_SET_DEVICE_INFO;
306
307 typedef struct _HPT_SET_DEVICE_INFO_V2
308 {
309         DEVICEID idDisk;
310         ALTERABLE_DEVICE_INFO_V2 Info;
311 } HPT_SET_DEVICE_INFO_V2, *PHPT_SET_DEVICE_INFO_V2;
312
313 typedef struct _HPT_ADD_DISK_TO_ARRAY
314 {
315         DEVICEID idArray;
316         DEVICEID idDisk;
317 } HPT_ADD_DISK_TO_ARRAY, *PHPT_ADD_DISK_TO_ARRAY;
318
319 typedef struct _HPT_DEVICE_IO
320 {
321         DEVICEID        id;
322         int                     cmd;
323         ULONG           lba;
324         DWORD           nSector;
325         UCHAR           buffer[0];
326 } HPT_DEVICE_IO, *PHPT_DEVICE_IO;
327
328 int check_VDevice_valid(PVDevice);
329 int hpt_default_ioctl(_VBUS_ARG DWORD, PVOID, DWORD, PVOID, DWORD, PDWORD);
330
331 #define HPT_NULL_ID 0
332
333 #pragma pack()
334
335 #endif