xref: /freebsd/sys/dev/hptnr/him.h (revision 7431dfd4580e850375fe5478d92ec770344db098)
1 /* $Id: him.h,v 1.57 2011/02/21 06:03:21 zsf Exp $ */
2 /*-
3  * Copyright (C) 2004-2005 HighPoint Technologies, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 #include <dev/hptnr/hptnr_config.h>
30 #ifndef _HPT_HIM_H_
31 #define _HPT_HIM_H_
32 
33 #define VERMAGIC_HIM 55
34 
35 #if defined(__cplusplus)
36 extern "C" {
37 #endif
38 
39 #include <dev/hptnr/list.h>
40 
41 #define SECTOR_TO_BYTE_SHIFT 9
42 #define SECTOR_TO_BYTE(x)       ((HPT_U32)(x) << SECTOR_TO_BYTE_SHIFT)
43 #define BYTE_TO_SECTOR(x)       ((x)>>SECTOR_TO_BYTE_SHIFT)
44 
45 typedef struct _PCI_ID
46 {
47 	HPT_U16 vid;
48 	HPT_U16 did;
49 	HPT_U32 subsys;
50 	HPT_U8  rev;
51 	HPT_U8  nbase;
52 	HPT_U16 reserve;
53 }
54 PCI_ID;
55 
56 typedef struct _PCI_ADDRESS
57 {
58 	HPT_U8 tree;
59 	HPT_U8 bus;
60 	HPT_U8 device;
61 	HPT_U8 function;
62 }
63 PCI_ADDRESS;
64 
65 typedef struct _HIM_ADAPTER_CONFIG
66 {
67 	PCI_ADDRESS pci_addr;
68 	PCI_ID  pci_id;
69 
70 	HPT_U8  max_devices;
71 
72 	HPT_U8  bProbeInInitializing:1;
73 
74 	HPT_U8  bSpinupOneDevEachTime:1;
75 
76 	HPT_U8  bGlobalNcq:1;
77 	HPT_U8  bSGPIOPartSupport:1;
78 
79 	HPT_U8  bNeedSASIdleTimer:1;
80 	HPT_U8  reserved:3;
81 
82 	HPT_U8  bDevsPerBus;
83 	HPT_U8  first_on_slot;
84 
85 	HPT_U8  bChipType;
86 	HPT_U8  bChipIntrNum;
87 	HPT_U8  bChipFlags;
88 	HPT_U8  bNumBuses;
89 
90 	HPT_U8  szVendorID[36];
91 	HPT_U8  szProductID[36];
92 	HPT_U32 nvramSize;
93 	HPT_U64 nvramAddress;
94 	HPT_U8  slot_index;
95 	HPT_U8  maxWidth;
96 	HPT_U8  currentWidth;
97 	HPT_U8  maxSpeed;
98 	HPT_U8  currentSpeed;
99 	HPT_U8  reserved2[7];
100 }
101 HIM_ADAPTER_CONFIG, *PHIM_ADAPTER_CONFIG;
102 
103 typedef struct _HIM_CHANNEL_CONFIG
104 {
105 	HPT_U32 io_port;
106 	HPT_U32 ctl_port;
107 } HIM_CHANNEL_CONFIG, *PHIM_CHANNEL_CONFIG;
108 
109 typedef struct _HIM_DEVICE_FLAGS
110 {
111 	HPT_UINT df_atapi               :1;
112 	HPT_UINT df_removable_drive     :1;
113 	HPT_UINT df_on_line             :1;
114 	HPT_UINT df_reduce_mode         :1;
115 	HPT_UINT df_sata                :1;
116 	HPT_UINT df_on_pm_port          :1;
117 	HPT_UINT df_support_read_ahead  :1;
118 	HPT_UINT df_read_ahead_enabled  :1;
119 	HPT_UINT df_support_write_cache :1;
120 	HPT_UINT df_write_cache_enabled :1;
121 	HPT_UINT df_cdrom_device        :1;
122 	HPT_UINT df_tape_device         :1;
123 	HPT_UINT df_support_tcq         :1;
124 	HPT_UINT df_tcq_enabled         :1;
125 	HPT_UINT df_support_ncq         :1;
126 	HPT_UINT df_ncq_enabled         :1;
127 	HPT_UINT df_sas                 :1;
128 	HPT_UINT df_in_enclosure        :1;
129 	HPT_UINT df_ssd                 :1;
130 } DEVICE_FLAGS, *PDEVICE_FLAGS;
131 
132 #pragma pack(1)
133 typedef struct _IDENTIFY_DATA {
134 	HPT_U16 GeneralConfiguration;
135 	HPT_U16 NumberOfCylinders;
136 	HPT_U16 Reserved1;
137 	HPT_U16 NumberOfHeads;
138 	HPT_U16 UnformattedBytesPerTrack;
139 	HPT_U16 UnformattedBytesPerSector;
140 	HPT_U8  SasAddress[8];
141 	HPT_U16 SerialNumber[10];
142 	HPT_U16 BufferType;
143 	HPT_U16 BufferSectorSize;
144 	HPT_U16 NumberOfEccBytes;
145 	HPT_U16 FirmwareRevision[4];
146 	HPT_U16 ModelNumber[20];
147 	HPT_U8  MaximumBlockTransfer;
148 	HPT_U8  VendorUnique2;
149 	HPT_U16 DoubleWordIo;
150 	HPT_U16 Capabilities;
151 	HPT_U16 Reserved2;
152 	HPT_U8  VendorUnique3;
153 	HPT_U8  PioCycleTimingMode;
154 	HPT_U8  VendorUnique4;
155 	HPT_U8  DmaCycleTimingMode;
156 	HPT_U16 TranslationFieldsValid;
157 	HPT_U16 NumberOfCurrentCylinders;
158 	HPT_U16 NumberOfCurrentHeads;
159 	HPT_U16 CurrentSectorsPerTrack;
160 	HPT_U32 CurrentSectorCapacity;
161 	HPT_U16 CurrentMultiSectorSetting;
162 	HPT_U32 UserAddressableSectors;
163 	HPT_U8  SingleWordDMASupport;
164 	HPT_U8  SingleWordDMAActive;
165 	HPT_U8  MultiWordDMASupport;
166 	HPT_U8  MultiWordDMAActive;
167 	HPT_U8  AdvancedPIOModes;
168 	HPT_U8  Reserved4;
169 	HPT_U16 MinimumMWXferCycleTime;
170 	HPT_U16 RecommendedMWXferCycleTime;
171 	HPT_U16 MinimumPIOCycleTime;
172 	HPT_U16 MinimumPIOCycleTimeIORDY;
173 	HPT_U16 Reserved5[2];
174 	HPT_U16 ReleaseTimeOverlapped;
175 	HPT_U16 ReleaseTimeServiceCommand;
176 	HPT_U16 MajorRevision;
177 	HPT_U16 MinorRevision;
178 	HPT_U16 MaxQueueDepth;
179 	HPT_U16 SataCapability;
180 	HPT_U16 Reserved6[9];
181 	HPT_U16 CommandSupport;
182 	HPT_U16 CommandEnable;
183 	HPT_U16 UtralDmaMode;
184 	HPT_U16 Reserved7[11];
185 	HPT_U32 Lba48BitLow;
186 	HPT_U32 Lba48BitHigh;
187 	HPT_U16 Reserved8[23];
188 	HPT_U16 SpecialFunctionsEnabled;
189 	HPT_U16 Reserved9[128];
190 }
191 #ifdef __GNUC__
192 __attribute__((packed))
193 #endif
194 IDENTIFY_DATA, *PIDENTIFY_DATA;
195 #pragma pack()
196 
197 typedef struct _HIM_DEVICE_CONFIG
198 {
199 	HPT_U64 capacity;
200 
201 	DEVICE_FLAGS flags;
202 
203 	HPT_U8  path_id;
204 	HPT_U8  target_id;
205 	HPT_U8  max_queue_depth;
206 	HPT_U8  spin_up_mode;
207 
208 	HPT_U8  reserved;
209 	HPT_U8  transfer_mode;
210 	HPT_U8  bMaxShowMode;
211 	HPT_U8  bDeUsable_Mode;
212 
213 	HPT_U16 max_sectors_per_cmd;
214 
215 	PIDENTIFY_DATA pIdentifyData;
216 
217 
218 	HPT_U8  fixed_path_id; /*equals to phy id */
219 }
220 HIM_DEVICE_CONFIG, *PHIM_DEVICE_CONFIG;
221 
222 
223 #define _DIT_MODE               0
224 #define _DIT_601                1
225 #define _DIT_READ_AHEAD         2
226 #define _DIT_WRITE_CACHE        3
227 #define _DIT_TCQ                4
228 #define _DIT_NCQ                5
229 #define _DIT_BEEP_OFF           6
230 #define _DIT_SPIN_UP_MODE       7
231 #define _DIT_IDLE_STANDBY       8
232 #define _DIT_IDENTIFY           9
233 
234 #define SPIN_UP_MODE_NOSUPPORT 0
235 #define SPIN_UP_MODE_FULL      1
236 #define SPIN_UP_MODE_STANDBY   2
237 
238 struct tcq_control {
239 	HPT_U8 enable;
240 	HPT_U8 depth;
241 };
242 
243 struct ncq_control {
244 	HPT_U8 enable;
245 	HPT_U8 depth;
246 };
247 
248 typedef struct _HIM_ALTERABLE_DEV_INFO{
249 	HPT_U8 type;
250 	union {
251 		HPT_U8 mode;
252 		HPT_U8 enable_read_ahead;
253 		HPT_U8 enable_read_cache;
254 		HPT_U8 enable_write_cache;
255 		struct tcq_control tcq;
256 		struct ncq_control ncq;
257 		void * adapter;
258 		HPT_U8 spin_up_mode;
259 		HPT_U8 idle_standby_timeout;
260 		HPT_U8 identify_indicator;
261 	}u;
262 } HIM_ALTERABLE_DEV_INFO, *PHIM_ALTERABLE_DEV_INFO;
263 
264 struct _COMMAND;
265 struct _IOCTL_ARG;
266 
267 typedef void (*PROBE_CALLBACK)(void *arg, void *dev, int index);
268 
269 typedef struct _HIM {
270 	char *name;
271 	struct _HIM *next;
272 	HPT_UINT max_sg_descriptors;
273 	#define _HIM_INTERFACE(_type, _fn, _args) _type (* _fn) _args;
274 	#include <dev/hptnr/himfuncs.h>
275 }
276 HIM, *PHIM;
277 
278 
279 #pragma pack(1)
280 #ifdef SG_FLAG_EOT
281 #error "don't use SG_FLAG_EOT with _SG.eot. clean the code!"
282 #endif
283 
284 typedef struct _SG {
285 	HPT_U32 size;
286 	HPT_UINT eot;
287 	union {
288 		HPT_U8 FAR * _logical;
289 		BUS_ADDRESS bus;
290 	}
291 	addr;
292 }
293 SG, *PSG;
294 #pragma pack()
295 
296 typedef struct _AtaCommand
297 {
298     HPT_U64     Lba;
299     HPT_U16     nSectors;
300     HPT_U16     pad;
301 } AtaComm, *PAtaComm;
302 
303 #define ATA_CMD_NOP          0x0
304 
305 #define ATA_CMD_SET_FEATURES    0xef
306 #define ATA_CMD_FLUSH           0xE7
307 #define ATA_CMD_VERIFY          0x40
308 #define ATA_CMD_STANDBY         0xe2
309 #define ATA_CMD_READ_MULTI      0xC4
310 #define ATA_CMD_READ_MULTI_EXT  0x29
311 #define ATA_CMD_WRITE_MULTI     0xC5
312 #define ATA_CMD_WRITE_MULTI_EXT 0x39
313 #define ATA_CMD_WRITE_MULTI_FUA_EXT     0xCE
314 
315 #define ATA_CMD_READ_DMA        0xc8  /* IDE DMA read command           */
316 #define ATA_CMD_WRITE_DMA       0xca  /* IDE DMA write command          */
317 #define ATA_CMD_READ_DMA_EXT        0x25
318 #define ATA_CMD_READ_QUEUE_EXT      0x26
319 #define ATA_CMD_READ_MAX_ADDR       0x27
320 #define ATA_CMD_READ_EXT            0x24
321 #define ATA_CMD_VERIFY_EXT          0x42
322 #define ATA_CMD_WRITE_DMA_EXT       0x35
323 #define ATA_CMD_WRITE_QUEUE_EXT     0x36
324 #define ATA_CMD_WRITE_EXT           0x34
325 
326 #define ATA_SET_FEATURES_XFER 0x3
327 #define ATA_SECTOR_SIZE 512
328 
329 typedef struct _PassthroughCmd {
330 	HPT_U16    bFeaturesReg;
331 	HPT_U16    bSectorCountReg;
332 	HPT_U16    bLbaLowReg;
333 	HPT_U16    bLbaMidReg;
334 	HPT_U16    bLbaHighReg;
335 	HPT_U8     bDriveHeadReg;
336 	HPT_U8     bCommandReg;
337 	HPT_U16    nSectors;
338 	HPT_U8    *pDataBuffer;
339 }
340 PassthroughCmd;
341 
342 typedef struct _ScsiComm {
343 	HPT_U8  cdbLength;
344 	HPT_U8  senseLength;
345 	HPT_U8  scsiStatus;
346 	HPT_U8  reserve1;
347 	HPT_U32 dataLength;
348 	HPT_U8 cdb[16];
349 	HPT_U8 *senseBuffer;
350 }
351 ScsiComm;
352 
353 
354 #define CTRL_CMD_REBUILD 1
355 #define CTRL_CMD_VERIFY  2
356 #define CTRL_CMD_INIT    3
357 
358 
359 typedef struct _R5ControlCmd {
360 	HPT_U64  StripeLine;
361 	HPT_U16 Offset;
362 	HPT_U8  Command;
363 	HPT_U8  CmdTarget;
364 }
365 R5ControlCmd, *PR5ControlCmd;
366 
367 typedef struct _HPT_ADDRESS
368 {
369 	HPT_U8 * logical;
370 	BUS_ADDRESS bus;
371 }
372 HPT_ADDRESS;
373 
374 
375 typedef struct ctl_pages {
376 	HPT_ADDRESS *pages;
377 	HPT_UINT        page_size;
378 	HPT_UINT        npages;
379 	HPT_UINT min_sg_descriptors;
380 } CONTROL_PAGES, *PCONTROL_PAGES;
381 
382 typedef struct _R1ControlCmd {
383 	HPT_U64  Lba;
384 	HPT_U16 nSectors;
385 	HPT_U8  Command;
386 	HPT_U8  CmdTarget;
387 	PCONTROL_PAGES ctl_pages;
388 }
389 R1ControlCmd, *PR1ControlCmd;
390 
391 typedef void (*TQ_PROC)(void *arg);
392 
393 struct tq_item {
394 	TQ_PROC proc;
395 	void *arg;
396 	struct tq_item *next;
397 };
398 
399 #define INIT_TQ_ITEM(t, p, a) \
400 	do { (t)->proc = p; (t)->arg = a; (t)->next = 0; } while (0)
401 
402 typedef struct _COMMAND
403 {
404 
405 	struct _VBUS * vbus;
406 
407 	struct freelist *grplist;
408 	HPT_UINT grpcnt;
409 
410 
411 	struct list_head q_link;
412 	struct tq_item done_dpc;
413 
414 	HPT_UINT extsize;
415 	void *ext;
416 
417 
418 
419 	void *target;
420 	void *priv;
421 	HPT_UPTR priv2;
422 
423 	int priority;
424 	struct lock_request *owned_lock;
425 	struct lock_request *lock_req;
426 	void (*dtor)(struct _COMMAND *, void *);
427 	void *dtor_arg;
428 
429 	union{
430 		AtaComm Ide;
431 		PassthroughCmd Passthrough;
432 		ScsiComm Scsi;
433 		R5ControlCmd R5Control;
434 		R1ControlCmd R1Control;
435 	} uCmd;
436 
437 	HPT_U8 type; /* CMD_TYPE_* */
438 
439 	struct {
440 		HPT_U8  physical_sg: 1;
441 		HPT_U8  data_in: 1;
442 		HPT_U8  data_out: 1;
443 		HPT_U8  transform : 1;
444 		HPT_U8  hard_flush: 2;
445 		HPT_U8  from_cc: 1;
446 		HPT_U8  force_cc: 1;
447 	} flags;
448 
449 	/* return status */
450 	HPT_U8  Result;
451 	/* retry count */
452 	HPT_U8  RetryCount;
453 
454 
455 	PSG psg;
456 
457 
458 	int  (*buildsgl)(struct _COMMAND *cmd, PSG psg, int logical);
459 	void (*done)(struct _COMMAND *cmd);
460 }
461 COMMAND, *PCOMMAND;
462 
463 /* command types */
464 #define   CMD_TYPE_IO           0
465 #define   CMD_TYPE_CONTROL      1
466 #define   CMD_TYPE_ATAPI        2
467 #define   CMD_TYPE_SCSI         CMD_TYPE_ATAPI
468 #define   CMD_TYPE_PASSTHROUGH  3
469 #define   CMD_TYPE_FLUSH        4
470 #define   CMD_TYPE_IO_INDIRECT  0x80
471 
472 /* flush command flags */
473 #define   CF_HARD_FLUSH_CACHE   1
474 #define   CF_HARD_FLUSH_STANDBY 2
475 
476 /* command return values */
477 #define   RETURN_PENDING             0
478 #define   RETURN_SUCCESS             1
479 #define   RETURN_BAD_DEVICE          2
480 #define   RETURN_BAD_PARAMETER       3
481 #define   RETURN_WRITE_NO_DRQ        4
482 #define   RETURN_DEVICE_BUSY         5
483 #define   RETURN_INVALID_REQUEST     6
484 #define   RETURN_SELECTION_TIMEOUT   7
485 #define   RETURN_IDE_ERROR           8
486 #define   RETURN_NEED_LOGICAL_SG     9
487 #define   RETURN_NEED_PHYSICAL_SG    10
488 #define   RETURN_RETRY               11
489 #define   RETURN_DATA_ERROR          12
490 #define   RETURN_BUS_RESET           13
491 #define   RETURN_BAD_TRANSFER_LENGTH 14
492 #define   RETURN_INSUFFICIENT_MEMORY 15
493 #define   RETURN_SECTOR_ERROR        16
494 #define   RETURN_NEED_SPINUP         17
495 
496 #if defined(__cplusplus)
497 }
498 #endif
499 #endif
500