4 * Home page of code is: http://www.smartmontools.org
6 * Copyright (C) 2003-8 Eduard Martinescu
8 * SPDX-License-Identifier: GPL-2.0-or-later
12 * Copyright (c) 2000 Michael Smith
13 * Copyright (c) 2003 Paul Saab
14 * Copyright (c) 2003 Vinod Kashyap
15 * Copyright (c) 2000 BSDi
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * Copyright (c) 2004-05 Applied Micro Circuits Corporation.
43 * Copyright (c) 2004-05 Vinod Kashyap
44 * All rights reserved.
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
55 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 #define OS_FREEBSD_H_CVSID "$Id: os_freebsd.h 4760 2018-08-19 18:45:53Z chrfranke $"
74 #define MAX_NUM_DEV 26
76 #ifdef HAVE_SYS_TWEREG_H
77 #include <sys/twereg.h>
80 * The following cut out of twereg.h
83 #if __FreeBSD_version < 500040
84 #define __packed __attribute__((__packed__))
87 #define TWE_MAX_SGL_LENGTH 62
88 #define TWE_MAX_ATA_SGL_LENGTH 60
89 #define TWE_OP_ATA_PASSTHROUGH 0x11
91 /* scatter/gather list entry */
96 } __packed TWE_SG_Entry
;
99 u_int8_t opcode
:5; /* TWE_OP_INITCONNECTION */
107 u_int16_t message_credits
;
108 u_int32_t response_queue_pointer
;
109 } __packed TWE_Command_INITCONNECTION
;
113 u_int8_t opcode
:5; /* TWE_OP_READ/TWE_OP_WRITE */
121 u_int16_t block_count
;
123 TWE_SG_Entry sgl
[TWE_MAX_SGL_LENGTH
];
124 } __packed TWE_Command_IO
;
128 u_int8_t opcode
:5; /* TWE_OP_HOTSWAP */
137 #define TWE_OP_HOTSWAP_REMOVE 0x00 /* remove assumed-degraded unit */
138 #define TWE_OP_HOTSWAP_ADD_CBOD 0x01 /* add CBOD to empty port */
139 #define TWE_OP_HOTSWAP_ADD_SPARE 0x02 /* add spare to empty port */
141 } __packed TWE_Command_HOTSWAP
;
145 u_int8_t opcode
:5; /* TWE_OP_SETATAFEATURE */
154 #define TWE_OP_SETATAFEATURE_WCE 0x02
155 #define TWE_OP_SETATAFEATURE_DIS_WCE 0x82
156 u_int8_t feature_mode
;
158 u_int16_t persistence
;
159 } __packed TWE_Command_SETATAFEATURE
;
163 u_int8_t opcode
:5; /* TWE_OP_CHECKSTATUS */
171 u_int16_t target_status
; /* set low byte to target request's ID */
172 } __packed TWE_Command_CHECKSTATUS
;
176 u_int8_t opcode
:5; /* TWE_OP_GETPARAM, TWE_OP_SETPARAM */
184 u_int16_t param_count
;
185 TWE_SG_Entry sgl
[TWE_MAX_SGL_LENGTH
];
186 } __packed TWE_Command_PARAM
;
190 u_int8_t opcode
:5; /* TWE_OP_REBUILDUNIT */
199 #define TWE_OP_REBUILDUNIT_NOP 0
200 #define TWE_OP_REBUILDUNIT_STOP 2 /* stop all rebuilds */
201 #define TWE_OP_REBUILDUNIT_START 4 /* start rebuild with lowest unit */
202 #define TWE_OP_REBUILDUNIT_STARTUNIT 5 /* rebuild src_unit (not supported) */
203 u_int8_t cs
:1; /* request state change on src_unit */
204 u_int8_t logical_subunit
; /* for RAID10 rebuild of logical subunit */
205 } __packed TWE_Command_REBUILDUNIT
;
210 u_int8_t sgl_offset
:3;
218 u_int16_t sector_count
;
219 u_int16_t sector_num
;
220 u_int16_t cylinder_lo
;
221 u_int16_t cylinder_hi
;
224 TWE_SG_Entry sgl
[TWE_MAX_ATA_SGL_LENGTH
];
225 } __packed TWE_Command_ATA
;
230 u_int8_t sgl_offset
:3;
237 #define TWE_FLAGS_SUCCESS 0x00
238 #define TWE_FLAGS_INFORMATIONAL 0x01
239 #define TWE_FLAGS_WARNING 0x02
240 #define TWE_FLAGS_FATAL 0x03
241 #define TWE_FLAGS_PERCENTAGE (1<<8) /* bits 0-6 indicate completion percentage */
242 u_int16_t count
; /* block count, parameter count, message credits */
243 } __packed TWE_Command_Generic
;
245 /* command packet - must be TWE_ALIGNMENT aligned */
248 TWE_Command_INITCONNECTION initconnection
;
250 TWE_Command_PARAM param
;
251 TWE_Command_CHECKSTATUS checkstatus
;
252 TWE_Command_REBUILDUNIT rebuildunit
;
253 TWE_Command_SETATAFEATURE setatafeature
;
255 TWE_Command_Generic generic
;
259 /* response queue entry */
264 u_int32_t undefined_1
:4;
265 u_int32_t response_id
:8;
266 u_int32_t undefined_2
:20;
269 } TWE_Response_Queue
;
273 #ifdef HAVE_SYS_TWEIO_H
274 #include <sys/tweio.h>
277 * Following cut out of tweio.h
283 * Note that the command's scatter/gather list will be computed by the
284 * driver, and cannot be filled in by the consumer.
286 struct twe_usercommand
{
287 TWE_Command tu_command
; /* command ready for the controller */
288 void *tu_data
; /* pointer to data in userspace */
289 size_t tu_size
; /* userspace data length */
292 #define TWEIO_COMMAND _IOWR('T', 100, struct twe_usercommand)
296 #ifdef HAVE_SYS_TW_OSL_IOCTL_H
297 #include <sys/tw_osl_ioctl.h>
300 * Following cut out of tw_osl_types.h
304 typedef void TW_VOID
;
305 typedef char TW_INT8
;
306 typedef unsigned char TW_UINT8
;
307 typedef short TW_INT16
;
308 typedef unsigned short TW_UINT16
;
309 typedef int TW_INT32
;
310 typedef unsigned int TW_UINT32
;
311 typedef long long TW_INT64
;
312 typedef unsigned long long TW_UINT64
;
315 * Following cut out of tw_cl_share.h
321 struct tw_cl_event_packet
{
322 TW_UINT32 sequence_id
;
323 TW_UINT32 time_stamp_sec
;
327 TW_UINT8 repeat_count
;
328 TW_UINT8 parameter_len
;
329 TW_UINT8 parameter_data
[98];
331 TW_UINT8 severity_str
[20];
337 * Following cut out of tw_cl_fwif.h
341 #define TWA_FW_CMD_ATA_PASSTHROUGH 0x11
343 #define TWA_SENSE_DATA_LENGTH 18
346 /* 7000 structures. */
347 struct tw_cl_command_init_connect
{
348 TW_UINT8 res1__opcode
; /* 3:5 */
354 TW_UINT16 message_credits
;
357 TW_UINT16 fw_arch_id
;
364 /* Structure for downloading firmware onto the controller. */
365 struct tw_cl_command_download_firmware
{
366 TW_UINT8 sgl_off__opcode
;/* 3:5 */
377 /* Structure for hard resetting the controller. */
378 struct tw_cl_command_reset_firmware
{
379 TW_UINT8 res1__opcode
; /* 3:5 */
390 /* Structure for sending get/set param commands. */
391 struct tw_cl_command_param
{
392 TW_UINT8 sgl_off__opcode
;/* 3:5 */
395 TW_UINT8 host_id__unit
; /* 4:4 */
398 TW_UINT16 param_count
;
403 /* Generic command packet. */
404 struct tw_cl_command_generic
{
405 TW_UINT8 sgl_off__opcode
;/* 3:5 */
408 TW_UINT8 host_id__unit
; /* 4:4 */
411 TW_UINT16 count
; /* block cnt, parameter cnt, message credits */
415 /* Command packet header. */
416 struct tw_cl_command_header
{
417 TW_UINT8 sense_data
[TWA_SENSE_DATA_LENGTH
];
422 TW_UINT8 res__severity
; /* 5:3 */
424 TW_UINT8 err_specific_desc
[98];
426 TW_UINT8 size_header
;
433 /* 7000 Command packet. */
434 union tw_cl_command_7k
{
435 struct tw_cl_command_init_connect init_connect
;
436 struct tw_cl_command_download_firmware download_fw
;
437 struct tw_cl_command_reset_firmware reset_fw
;
438 struct tw_cl_command_param param
;
439 struct tw_cl_command_generic generic
;
440 TW_UINT8 padding
[1024 - sizeof(struct tw_cl_command_header
)];
444 /* 9000 Command Packet. */
445 struct tw_cl_command_9k
{
446 TW_UINT8 res__opcode
; /* 3:5 */
448 TW_UINT16 lun_l4__req_id
; /* 4:12 */
450 TW_UINT8 sgl_offset
; /* offset (in bytes) to sg_list, from the
451 end of sgl_entries */
452 TW_UINT16 lun_h4__sgl_entries
;
454 TW_UINT8 sg_list
[872];/* total struct size =
455 1024-sizeof(cmd_hdr) */
459 /* Full command packet. */
460 struct tw_cl_command_packet
{
461 struct tw_cl_command_header cmd_hdr
;
463 union tw_cl_command_7k cmd_pkt_7k
;
464 struct tw_cl_command_9k cmd_pkt_9k
;
471 * Following cut out of tw_cl_ioctl.h
477 /* Structure used to handle GET/RELEASE LOCK ioctls. */
478 struct tw_cl_lock_packet
{
479 TW_UINT32 timeout_msec
;
480 TW_UINT32 time_remaining_msec
;
481 TW_UINT32 force_flag
;
485 /* Structure used to handle GET COMPATIBILITY INFO ioctl. */
486 struct tw_cl_compatibility_packet
{
487 TW_UINT8 driver_version
[32];/* driver version */
488 TW_UINT16 working_srl
; /* driver & firmware negotiated srl */
489 TW_UINT16 working_branch
; /* branch # of the firmware that the
490 driver is compatible with */
491 TW_UINT16 working_build
; /* build # of the firmware that the
492 driver is compatible with */
496 /* Driver understandable part of the ioctl packet built by the API. */
497 struct tw_cl_driver_packet
{
498 TW_UINT32 control_code
;
501 TW_UINT32 sequence_id
;
503 TW_UINT32 buffer_length
;
509 * Following cut out of tw_osl_ioctl.h
515 * We need the structure below to ensure that the first byte of
516 * data_buf is not overwritten by the kernel, after we return
517 * from the ioctl call. Note that cmd_pkt has been reduced
518 * to an array of 1024 bytes even though it's actually 2048 bytes
519 * in size. This is because, we don't expect requests from user
520 * land requiring 2048 (273 sg elements) byte cmd pkts.
522 typedef struct tw_osli_ioctl_no_data_buf
{
523 struct tw_cl_driver_packet driver_pkt
;
524 TW_VOID
*pdata
; /* points to data_buf */
525 TW_INT8 padding
[488 - sizeof(TW_VOID
*)];
526 struct tw_cl_command_packet cmd_pkt
;
527 } TW_OSLI_IOCTL_NO_DATA_BUF
;
531 #define TW_OSL_IOCTL_FIRMWARE_PASS_THROUGH \
532 _IOWR('T', 202, TW_OSLI_IOCTL_NO_DATA_BUF)
536 typedef struct tw_osli_ioctl_with_payload
{
537 struct tw_cl_driver_packet driver_pkt
;
538 TW_INT8 padding
[488];
539 struct tw_cl_command_packet cmd_pkt
;
541 struct tw_cl_event_packet event_pkt
;
542 struct tw_cl_lock_packet lock_pkt
;
543 struct tw_cl_compatibility_packet compat_pkt
;
546 } TW_OSLI_IOCTL_WITH_PAYLOAD
;
552 #define HPT_CTL_CODE(x) (x+0xFF00)
553 #define HPT_IOCTL_GET_CHANNEL_INFO HPT_CTL_CODE(3)
554 #define HPT_IOCTL_GET_CHANNEL_INFO_V2 HPT_CTL_CODE(53)
555 #define HPT_IOCTL_IDE_PASS_THROUGH HPT_CTL_CODE(24)
560 #define HPT_IOCTL_MAGIC 0xA1B2C3D4
562 #define MAXDEV_PER_CHANNEL 2
563 #define PMPORT_PER_CHANNEL 15 /* max devices connected to this channel via pmport */
566 typedef struct _HPT_CHANNEL_INFO
{
567 unsigned int reserve1
;
568 unsigned int reserve2
;
569 unsigned int devices
[MAXDEV_PER_CHANNEL
];
570 } HPT_CHANNEL_INFO
, *PHPT_CHANNEL_INFO
;
572 typedef struct _HPT_CHANNEL_INFO_V2
{
573 unsigned int reserve1
;
574 unsigned int reserve2
;
575 unsigned int devices
[PMPORT_PER_CHANNEL
];
576 } HPT_CHANNEL_INFO_V2
, *PHPT_CHANNEL_INFO_V2
;
578 typedef struct _HPT_IOCTL_PARAM
{
579 unsigned int magic
; /* used to check if it's a valid ioctl packet */
580 unsigned int ctrl_code
; /* operation control code */
581 void* in
; /* input data buffer */
582 unsigned int in_size
; /* size of input data buffer */
583 void* out
; /* output data buffer */
584 unsigned int out_size
; /* size of output data buffer */
585 void* returned_size
; /* count of chars returned */
586 } HPT_IOCTL_PARAM
, *PHPT_IOCTL_PARAM
;
587 #define HPT_DO_IOCONTROL _IOW('H', 0, HPT_IOCTL_PARAM)
589 typedef struct _HPT_PASS_THROUGH_HEADER
{
590 unsigned int id
; /* disk ID */
591 unsigned char feature
;
592 unsigned char sectorcount
;
593 unsigned char lbalow
;
594 unsigned char lbamid
;
595 unsigned char lbahigh
;
596 unsigned char driverhead
;
597 unsigned char command
;
598 unsigned char sectors
; /* data size in sectors, if the command has data transfer */
599 unsigned char protocol
; /* HPT_(READ,WRITE) or zero for non-DATA */
600 unsigned char reserve
[3];
602 HPT_PASS_THROUGH_HEADER
, *PHPT_PASS_THROUGH_HEADER
;
606 #define __unused __attribute__ ((__unused__))
609 #endif /* OS_FREEBSD_H_ */