4 * Home page of code is: http://smartmontools.sourceforge.net
6 * Copyright (C) 2003-8 Eduard Martinescu <smartmontools-support@lists.sourceforge.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * You should have received a copy of the GNU General Public License
14 * (for example COPYING); if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 * This code was originally developed as a Senior Thesis by Michael Cornwell
18 * at the Concurrent Systems Laboratory (now part of the Storage Systems
19 * Research Center), Jack Baskin School of Engineering, University of
20 * California, Santa Cruz. http://ssrc.soe.ucsc.edu/
25 * Copyright (c) 2000 Michael Smith
26 * Copyright (c) 2003 Paul Saab
27 * Copyright (c) 2003 Vinod Kashyap
28 * Copyright (c) 2000 BSDi
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * Copyright (c) 2004-05 Applied Micro Circuits Corporation.
56 * Copyright (c) 2004-05 Vinod Kashyap
57 * All rights reserved.
59 * Redistribution and use in source and binary forms, with or without
60 * modification, are permitted provided that the following conditions
62 * 1. Redistributions of source code must retain the above copyright
63 * notice, this list of conditions and the following disclaimer.
64 * 2. Redistributions in binary form must reproduce the above copyright
65 * notice, this list of conditions and the following disclaimer in the
66 * documentation and/or other materials provided with the distribution.
68 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
69 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
71 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
72 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
73 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
74 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
75 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
76 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
77 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
85 #define OS_FREEBSD_H_CVSID "$Id: os_freebsd.h 3727 2012-12-13 17:23:06Z samm2 $"
87 #define MAX_NUM_DEV 26
89 #ifdef HAVE_SYS_TWEREG_H
90 #include <sys/twereg.h>
93 * The following cut out of twereg.h
96 #if __FreeBSD_version < 500040
97 #define __packed __attribute__((__packed__))
100 #define TWE_MAX_SGL_LENGTH 62
101 #define TWE_MAX_ATA_SGL_LENGTH 60
102 #define TWE_OP_ATA_PASSTHROUGH 0x11
104 /* scatter/gather list entry */
109 } __packed TWE_SG_Entry
;
112 u_int8_t opcode
:5; /* TWE_OP_INITCONNECTION */
120 u_int16_t message_credits
;
121 u_int32_t response_queue_pointer
;
122 } __packed TWE_Command_INITCONNECTION
;
126 u_int8_t opcode
:5; /* TWE_OP_READ/TWE_OP_WRITE */
134 u_int16_t block_count
;
136 TWE_SG_Entry sgl
[TWE_MAX_SGL_LENGTH
];
137 } __packed TWE_Command_IO
;
141 u_int8_t opcode
:5; /* TWE_OP_HOTSWAP */
150 #define TWE_OP_HOTSWAP_REMOVE 0x00 /* remove assumed-degraded unit */
151 #define TWE_OP_HOTSWAP_ADD_CBOD 0x01 /* add CBOD to empty port */
152 #define TWE_OP_HOTSWAP_ADD_SPARE 0x02 /* add spare to empty port */
154 } __packed TWE_Command_HOTSWAP
;
158 u_int8_t opcode
:5; /* TWE_OP_SETATAFEATURE */
167 #define TWE_OP_SETATAFEATURE_WCE 0x02
168 #define TWE_OP_SETATAFEATURE_DIS_WCE 0x82
169 u_int8_t feature_mode
;
171 u_int16_t persistence
;
172 } __packed TWE_Command_SETATAFEATURE
;
176 u_int8_t opcode
:5; /* TWE_OP_CHECKSTATUS */
184 u_int16_t target_status
; /* set low byte to target request's ID */
185 } __packed TWE_Command_CHECKSTATUS
;
189 u_int8_t opcode
:5; /* TWE_OP_GETPARAM, TWE_OP_SETPARAM */
197 u_int16_t param_count
;
198 TWE_SG_Entry sgl
[TWE_MAX_SGL_LENGTH
];
199 } __packed TWE_Command_PARAM
;
203 u_int8_t opcode
:5; /* TWE_OP_REBUILDUNIT */
212 #define TWE_OP_REBUILDUNIT_NOP 0
213 #define TWE_OP_REBUILDUNIT_STOP 2 /* stop all rebuilds */
214 #define TWE_OP_REBUILDUNIT_START 4 /* start rebuild with lowest unit */
215 #define TWE_OP_REBUILDUNIT_STARTUNIT 5 /* rebuild src_unit (not supported) */
216 u_int8_t cs
:1; /* request state change on src_unit */
217 u_int8_t logical_subunit
; /* for RAID10 rebuild of logical subunit */
218 } __packed TWE_Command_REBUILDUNIT
;
223 u_int8_t sgl_offset
:3;
231 u_int16_t sector_count
;
232 u_int16_t sector_num
;
233 u_int16_t cylinder_lo
;
234 u_int16_t cylinder_hi
;
237 TWE_SG_Entry sgl
[TWE_MAX_ATA_SGL_LENGTH
];
238 } __packed TWE_Command_ATA
;
243 u_int8_t sgl_offset
:3;
250 #define TWE_FLAGS_SUCCESS 0x00
251 #define TWE_FLAGS_INFORMATIONAL 0x01
252 #define TWE_FLAGS_WARNING 0x02
253 #define TWE_FLAGS_FATAL 0x03
254 #define TWE_FLAGS_PERCENTAGE (1<<8) /* bits 0-6 indicate completion percentage */
255 u_int16_t count
; /* block count, parameter count, message credits */
256 } __packed TWE_Command_Generic
;
258 /* command packet - must be TWE_ALIGNMENT aligned */
261 TWE_Command_INITCONNECTION initconnection
;
263 TWE_Command_PARAM param
;
264 TWE_Command_CHECKSTATUS checkstatus
;
265 TWE_Command_REBUILDUNIT rebuildunit
;
266 TWE_Command_SETATAFEATURE setatafeature
;
268 TWE_Command_Generic generic
;
272 /* response queue entry */
277 u_int32_t undefined_1
:4;
278 u_int32_t response_id
:8;
279 u_int32_t undefined_2
:20;
282 } TWE_Response_Queue
;
286 #ifdef HAVE_SYS_TWEIO_H
287 #include <sys/tweio.h>
290 * Following cut out of tweio.h
296 * Note that the command's scatter/gather list will be computed by the
297 * driver, and cannot be filled in by the consumer.
299 struct twe_usercommand
{
300 TWE_Command tu_command
; /* command ready for the controller */
301 void *tu_data
; /* pointer to data in userspace */
302 size_t tu_size
; /* userspace data length */
305 #define TWEIO_COMMAND _IOWR('T', 100, struct twe_usercommand)
309 #ifdef HAVE_SYS_TW_OSL_IOCTL_H
310 #include <sys/tw_osl_ioctl.h>
313 * Following cut out of tw_osl_types.h
317 typedef void TW_VOID
;
318 typedef char TW_INT8
;
319 typedef unsigned char TW_UINT8
;
320 typedef short TW_INT16
;
321 typedef unsigned short TW_UINT16
;
322 typedef int TW_INT32
;
323 typedef unsigned int TW_UINT32
;
324 typedef long long TW_INT64
;
325 typedef unsigned long long TW_UINT64
;
328 * Following cut out of tw_cl_share.h
334 struct tw_cl_event_packet
{
335 TW_UINT32 sequence_id
;
336 TW_UINT32 time_stamp_sec
;
340 TW_UINT8 repeat_count
;
341 TW_UINT8 parameter_len
;
342 TW_UINT8 parameter_data
[98];
344 TW_UINT8 severity_str
[20];
350 * Following cut out of tw_cl_fwif.h
354 #define TWA_FW_CMD_ATA_PASSTHROUGH 0x11
356 #define TWA_SENSE_DATA_LENGTH 18
359 /* 7000 structures. */
360 struct tw_cl_command_init_connect
{
361 TW_UINT8 res1__opcode
; /* 3:5 */
367 TW_UINT16 message_credits
;
370 TW_UINT16 fw_arch_id
;
377 /* Structure for downloading firmware onto the controller. */
378 struct tw_cl_command_download_firmware
{
379 TW_UINT8 sgl_off__opcode
;/* 3:5 */
390 /* Structure for hard resetting the controller. */
391 struct tw_cl_command_reset_firmware
{
392 TW_UINT8 res1__opcode
; /* 3:5 */
403 /* Structure for sending get/set param commands. */
404 struct tw_cl_command_param
{
405 TW_UINT8 sgl_off__opcode
;/* 3:5 */
408 TW_UINT8 host_id__unit
; /* 4:4 */
411 TW_UINT16 param_count
;
416 /* Generic command packet. */
417 struct tw_cl_command_generic
{
418 TW_UINT8 sgl_off__opcode
;/* 3:5 */
421 TW_UINT8 host_id__unit
; /* 4:4 */
424 TW_UINT16 count
; /* block cnt, parameter cnt, message credits */
428 /* Command packet header. */
429 struct tw_cl_command_header
{
430 TW_UINT8 sense_data
[TWA_SENSE_DATA_LENGTH
];
435 TW_UINT8 res__severity
; /* 5:3 */
437 TW_UINT8 err_specific_desc
[98];
439 TW_UINT8 size_header
;
446 /* 7000 Command packet. */
447 union tw_cl_command_7k
{
448 struct tw_cl_command_init_connect init_connect
;
449 struct tw_cl_command_download_firmware download_fw
;
450 struct tw_cl_command_reset_firmware reset_fw
;
451 struct tw_cl_command_param param
;
452 struct tw_cl_command_generic generic
;
453 TW_UINT8 padding
[1024 - sizeof(struct tw_cl_command_header
)];
457 /* 9000 Command Packet. */
458 struct tw_cl_command_9k
{
459 TW_UINT8 res__opcode
; /* 3:5 */
461 TW_UINT16 lun_l4__req_id
; /* 4:12 */
463 TW_UINT8 sgl_offset
; /* offset (in bytes) to sg_list, from the
464 end of sgl_entries */
465 TW_UINT16 lun_h4__sgl_entries
;
467 TW_UINT8 sg_list
[872];/* total struct size =
468 1024-sizeof(cmd_hdr) */
472 /* Full command packet. */
473 struct tw_cl_command_packet
{
474 struct tw_cl_command_header cmd_hdr
;
476 union tw_cl_command_7k cmd_pkt_7k
;
477 struct tw_cl_command_9k cmd_pkt_9k
;
484 * Following cut out of tw_cl_ioctl.h
490 /* Structure used to handle GET/RELEASE LOCK ioctls. */
491 struct tw_cl_lock_packet
{
492 TW_UINT32 timeout_msec
;
493 TW_UINT32 time_remaining_msec
;
494 TW_UINT32 force_flag
;
498 /* Structure used to handle GET COMPATIBILITY INFO ioctl. */
499 struct tw_cl_compatibility_packet
{
500 TW_UINT8 driver_version
[32];/* driver version */
501 TW_UINT16 working_srl
; /* driver & firmware negotiated srl */
502 TW_UINT16 working_branch
; /* branch # of the firmware that the
503 driver is compatible with */
504 TW_UINT16 working_build
; /* build # of the firmware that the
505 driver is compatible with */
509 /* Driver understandable part of the ioctl packet built by the API. */
510 struct tw_cl_driver_packet
{
511 TW_UINT32 control_code
;
514 TW_UINT32 sequence_id
;
516 TW_UINT32 buffer_length
;
522 * Following cut out of tw_osl_ioctl.h
528 * We need the structure below to ensure that the first byte of
529 * data_buf is not overwritten by the kernel, after we return
530 * from the ioctl call. Note that cmd_pkt has been reduced
531 * to an array of 1024 bytes even though it's actually 2048 bytes
532 * in size. This is because, we don't expect requests from user
533 * land requiring 2048 (273 sg elements) byte cmd pkts.
535 typedef struct tw_osli_ioctl_no_data_buf
{
536 struct tw_cl_driver_packet driver_pkt
;
537 TW_VOID
*pdata
; /* points to data_buf */
538 TW_INT8 padding
[488 - sizeof(TW_VOID
*)];
539 struct tw_cl_command_packet cmd_pkt
;
540 } TW_OSLI_IOCTL_NO_DATA_BUF
;
544 #define TW_OSL_IOCTL_FIRMWARE_PASS_THROUGH \
545 _IOWR('T', 202, TW_OSLI_IOCTL_NO_DATA_BUF)
549 typedef struct tw_osli_ioctl_with_payload
{
550 struct tw_cl_driver_packet driver_pkt
;
551 TW_INT8 padding
[488];
552 struct tw_cl_command_packet cmd_pkt
;
554 struct tw_cl_event_packet event_pkt
;
555 struct tw_cl_lock_packet lock_pkt
;
556 struct tw_cl_compatibility_packet compat_pkt
;
559 } TW_OSLI_IOCTL_WITH_PAYLOAD
;
565 #define HPT_CTL_CODE(x) (x+0xFF00)
566 #define HPT_IOCTL_GET_CHANNEL_INFO HPT_CTL_CODE(3)
567 #define HPT_IOCTL_GET_CHANNEL_INFO_V2 HPT_CTL_CODE(53)
568 #define HPT_IOCTL_IDE_PASS_THROUGH HPT_CTL_CODE(24)
573 #define HPT_IOCTL_MAGIC 0xA1B2C3D4
575 #define MAXDEV_PER_CHANNEL 2
576 #define PMPORT_PER_CHANNEL 15 /* max devices connected to this channel via pmport */
579 typedef struct _HPT_CHANNEL_INFO
{
580 unsigned int reserve1
;
581 unsigned int reserve2
;
582 unsigned int devices
[MAXDEV_PER_CHANNEL
];
583 } HPT_CHANNEL_INFO
, *PHPT_CHANNEL_INFO
;
585 typedef struct _HPT_CHANNEL_INFO_V2
{
586 unsigned int reserve1
;
587 unsigned int reserve2
;
588 unsigned int devices
[PMPORT_PER_CHANNEL
];
589 } HPT_CHANNEL_INFO_V2
, *PHPT_CHANNEL_INFO_V2
;
591 typedef struct _HPT_IOCTL_PARAM
{
592 unsigned int magic
; /* used to check if it's a valid ioctl packet */
593 unsigned int ctrl_code
; /* operation control code */
594 void* in
; /* input data buffer */
595 unsigned int in_size
; /* size of input data buffer */
596 void* out
; /* output data buffer */
597 unsigned int out_size
; /* size of output data buffer */
598 void* returned_size
; /* count of chars returned */
599 } HPT_IOCTL_PARAM
, *PHPT_IOCTL_PARAM
;
600 #define HPT_DO_IOCONTROL _IOW('H', 0, HPT_IOCTL_PARAM)
602 typedef struct _HPT_PASS_THROUGH_HEADER
{
603 unsigned int id
; /* disk ID */
604 unsigned char feature
;
605 unsigned char sectorcount
;
606 unsigned char lbalow
;
607 unsigned char lbamid
;
608 unsigned char lbahigh
;
609 unsigned char driverhead
;
610 unsigned char command
;
611 unsigned char sectors
; /* data size in sectors, if the command has data transfer */
612 unsigned char protocol
; /* HPT_(READ,WRITE) or zero for non-DATA */
613 unsigned char reserve
[3];
615 HPT_PASS_THROUGH_HEADER
, *PHPT_PASS_THROUGH_HEADER
;
619 #define __unused __attribute__ ((__unused__))
622 #endif /* OS_FREEBSD_H_ */