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 HPT_U32 logical_sector_size; 201 HPT_U8 logicalsectors_per_physicalsector; 202 HPT_U16 lowest_aligned; 203 204 DEVICE_FLAGS flags; 205 206 HPT_U8 path_id; 207 HPT_U8 target_id; 208 HPT_U8 max_queue_depth; 209 HPT_U8 spin_up_mode; 210 211 HPT_U8 reserved; 212 HPT_U8 transfer_mode; 213 HPT_U8 bMaxShowMode; 214 HPT_U8 bDeUsable_Mode; 215 216 HPT_U16 max_sectors_per_cmd; 217 218 PIDENTIFY_DATA pIdentifyData; 219 220 221 HPT_U8 fixed_path_id; /*equals to phy id */ 222 } 223 HIM_DEVICE_CONFIG, *PHIM_DEVICE_CONFIG; 224 225 226 #define _DIT_MODE 0 227 #define _DIT_601 1 228 #define _DIT_READ_AHEAD 2 229 #define _DIT_WRITE_CACHE 3 230 #define _DIT_TCQ 4 231 #define _DIT_NCQ 5 232 #define _DIT_BEEP_OFF 6 233 #define _DIT_SPIN_UP_MODE 7 234 #define _DIT_IDLE_STANDBY 8 235 #define _DIT_IDENTIFY 9 236 237 #define SPIN_UP_MODE_NOSUPPORT 0 238 #define SPIN_UP_MODE_FULL 1 239 #define SPIN_UP_MODE_STANDBY 2 240 241 struct tcq_control { 242 HPT_U8 enable; 243 HPT_U8 depth; 244 }; 245 246 struct ncq_control { 247 HPT_U8 enable; 248 HPT_U8 depth; 249 }; 250 251 typedef struct _HIM_ALTERABLE_DEV_INFO{ 252 HPT_U8 type; 253 union { 254 HPT_U8 mode; 255 HPT_U8 enable_read_ahead; 256 HPT_U8 enable_read_cache; 257 HPT_U8 enable_write_cache; 258 struct tcq_control tcq; 259 struct ncq_control ncq; 260 void * adapter; 261 HPT_U8 spin_up_mode; 262 HPT_U8 idle_standby_timeout; 263 HPT_U8 identify_indicator; 264 }u; 265 } HIM_ALTERABLE_DEV_INFO, *PHIM_ALTERABLE_DEV_INFO; 266 267 struct _COMMAND; 268 struct _IOCTL_ARG; 269 270 typedef void (*PROBE_CALLBACK)(void *arg, void *dev, int index); 271 272 typedef struct _HIM { 273 char *name; 274 struct _HIM *next; 275 HPT_UINT max_sg_descriptors; 276 #define _HIM_INTERFACE(_type, _fn, _args) _type (* _fn) _args; 277 #include <dev/hptnr/himfuncs.h> 278 } 279 HIM, *PHIM; 280 281 282 #pragma pack(1) 283 #ifdef SG_FLAG_EOT 284 #error "don't use SG_FLAG_EOT with _SG.eot. clean the code!" 285 #endif 286 287 typedef struct _SG { 288 HPT_U32 size; 289 HPT_UINT eot; 290 union { 291 HPT_U8 FAR * _logical; 292 BUS_ADDRESS bus; 293 } 294 addr; 295 } 296 SG, *PSG; 297 #pragma pack() 298 299 typedef struct _AtaCommand 300 { 301 HPT_U64 Lba; 302 HPT_U16 nSectors; 303 HPT_U16 pad; 304 } AtaComm, *PAtaComm; 305 306 #define ATA_CMD_NOP 0x0 307 308 #define ATA_CMD_SET_FEATURES 0xef 309 #define ATA_CMD_FLUSH 0xE7 310 #define ATA_CMD_VERIFY 0x40 311 #define ATA_CMD_STANDBY 0xe2 312 #define ATA_CMD_READ_MULTI 0xC4 313 #define ATA_CMD_READ_MULTI_EXT 0x29 314 #define ATA_CMD_WRITE_MULTI 0xC5 315 #define ATA_CMD_WRITE_MULTI_EXT 0x39 316 #define ATA_CMD_WRITE_MULTI_FUA_EXT 0xCE 317 318 #define ATA_CMD_READ_DMA 0xc8 /* IDE DMA read command */ 319 #define ATA_CMD_WRITE_DMA 0xca /* IDE DMA write command */ 320 #define ATA_CMD_READ_DMA_EXT 0x25 321 #define ATA_CMD_READ_QUEUE_EXT 0x26 322 #define ATA_CMD_READ_MAX_ADDR 0x27 323 #define ATA_CMD_READ_EXT 0x24 324 #define ATA_CMD_VERIFY_EXT 0x42 325 #define ATA_CMD_WRITE_DMA_EXT 0x35 326 #define ATA_CMD_WRITE_QUEUE_EXT 0x36 327 #define ATA_CMD_WRITE_EXT 0x34 328 329 #define ATA_SET_FEATURES_XFER 0x3 330 #define ATA_SECTOR_SIZE 512 331 332 typedef struct _PassthroughCmd { 333 HPT_U16 bFeaturesReg; 334 HPT_U16 bSectorCountReg; 335 HPT_U16 bLbaLowReg; 336 HPT_U16 bLbaMidReg; 337 HPT_U16 bLbaHighReg; 338 HPT_U8 bDriveHeadReg; 339 HPT_U8 bCommandReg; 340 HPT_U16 nSectors; 341 HPT_U8 *pDataBuffer; 342 } 343 PassthroughCmd; 344 345 typedef struct _ScsiComm { 346 HPT_U8 cdbLength; 347 HPT_U8 senseLength; 348 HPT_U8 scsiStatus; 349 HPT_U8 reserve1; 350 HPT_U32 dataLength; 351 HPT_U8 cdb[16]; 352 HPT_U8 *senseBuffer; 353 } 354 ScsiComm; 355 356 357 #define CTRL_CMD_REBUILD 1 358 #define CTRL_CMD_VERIFY 2 359 #define CTRL_CMD_INIT 3 360 361 362 typedef struct _R5ControlCmd { 363 HPT_U64 StripeLine; 364 HPT_U16 Offset; 365 HPT_U8 Command; 366 HPT_U8 CmdTarget; 367 } 368 R5ControlCmd, *PR5ControlCmd; 369 370 typedef struct _HPT_ADDRESS 371 { 372 HPT_U8 * logical; 373 BUS_ADDRESS bus; 374 } 375 HPT_ADDRESS; 376 377 378 typedef struct ctl_pages { 379 HPT_ADDRESS *pages; 380 HPT_UINT page_size; 381 HPT_UINT npages; 382 HPT_UINT min_sg_descriptors; 383 } CONTROL_PAGES, *PCONTROL_PAGES; 384 385 typedef struct _R1ControlCmd { 386 HPT_U64 Lba; 387 HPT_U16 nSectors; 388 HPT_U8 Command; 389 HPT_U8 CmdTarget; 390 PCONTROL_PAGES ctl_pages; 391 } 392 R1ControlCmd, *PR1ControlCmd; 393 394 typedef void (*TQ_PROC)(void *arg); 395 396 struct tq_item { 397 TQ_PROC proc; 398 void *arg; 399 struct tq_item *next; 400 }; 401 402 #define INIT_TQ_ITEM(t, p, a) \ 403 do { (t)->proc = p; (t)->arg = a; (t)->next = 0; } while (0) 404 405 typedef struct _COMMAND 406 { 407 408 struct _VBUS * vbus; 409 410 struct freelist *grplist; 411 HPT_UINT grpcnt; 412 413 414 struct list_head q_link; 415 struct tq_item done_dpc; 416 417 HPT_UINT extsize; 418 void *ext; 419 420 421 422 void *target; 423 void *priv; 424 HPT_UPTR priv2; 425 426 int priority; 427 struct lock_request *owned_lock; 428 struct lock_request *lock_req; 429 void (*dtor)(struct _COMMAND *, void *); 430 void *dtor_arg; 431 432 union{ 433 AtaComm Ide; 434 PassthroughCmd Passthrough; 435 ScsiComm Scsi; 436 R5ControlCmd R5Control; 437 R1ControlCmd R1Control; 438 } uCmd; 439 440 HPT_U8 type; /* CMD_TYPE_* */ 441 442 struct { 443 HPT_U8 physical_sg: 1; 444 HPT_U8 data_in: 1; 445 HPT_U8 data_out: 1; 446 HPT_U8 transform : 1; 447 HPT_U8 hard_flush: 2; 448 HPT_U8 from_cc: 1; 449 HPT_U8 force_cc: 1; 450 } flags; 451 452 /* return status */ 453 HPT_U8 Result; 454 /* retry count */ 455 HPT_U8 RetryCount; 456 457 458 PSG psg; 459 460 461 int (*buildsgl)(struct _COMMAND *cmd, PSG psg, int logical); 462 void (*done)(struct _COMMAND *cmd); 463 } 464 COMMAND, *PCOMMAND; 465 466 /* command types */ 467 #define CMD_TYPE_IO 0 468 #define CMD_TYPE_CONTROL 1 469 #define CMD_TYPE_ATAPI 2 470 #define CMD_TYPE_SCSI CMD_TYPE_ATAPI 471 #define CMD_TYPE_PASSTHROUGH 3 472 #define CMD_TYPE_FLUSH 4 473 #define CMD_TYPE_IO_INDIRECT 0x80 474 475 /* flush command flags */ 476 #define CF_HARD_FLUSH_CACHE 1 477 #define CF_HARD_FLUSH_STANDBY 2 478 479 /* command return values */ 480 #define RETURN_PENDING 0 481 #define RETURN_SUCCESS 1 482 #define RETURN_BAD_DEVICE 2 483 #define RETURN_BAD_PARAMETER 3 484 #define RETURN_WRITE_NO_DRQ 4 485 #define RETURN_DEVICE_BUSY 5 486 #define RETURN_INVALID_REQUEST 6 487 #define RETURN_SELECTION_TIMEOUT 7 488 #define RETURN_IDE_ERROR 8 489 #define RETURN_NEED_LOGICAL_SG 9 490 #define RETURN_NEED_PHYSICAL_SG 10 491 #define RETURN_RETRY 11 492 #define RETURN_DATA_ERROR 12 493 #define RETURN_BUS_RESET 13 494 #define RETURN_BAD_TRANSFER_LENGTH 14 495 #define RETURN_INSUFFICIENT_MEMORY 15 496 #define RETURN_SECTOR_ERROR 16 497 #define RETURN_NEED_SPINUP 17 498 499 #if defined(__cplusplus) 500 } 501 #endif 502 #endif 503