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
15 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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,v 1.22 2008/03/04 22:09:47 ballen4705 Exp $\n"
87 struct freebsd_dev_channel
{
88 int channel
; // the ATA channel to work with
89 int device
; // the device on the channel
90 int atacommand
; // the ATA Command file descriptor (/dev/ata)
91 char* devname
; // the SCSI device name
92 int unitnum
; // the SCSI unit number
93 int scsicontrol
; // the SCSI control interface
96 #define FREEBSD_MAXDEV 64
97 #define FREEBSD_FDOFFSET 16;
98 #define MAX_NUM_DEV 26
100 #ifdef HAVE_SYS_TWEREG_H
101 #include <sys/twereg.h>
104 * The following cut out of twereg.h
107 #if __FreeBSD_version < 500040
108 #define __packed __attribute__((__packed__))
111 #define TWE_MAX_SGL_LENGTH 62
112 #define TWE_MAX_ATA_SGL_LENGTH 60
113 #define TWE_OP_ATA_PASSTHROUGH 0x11
115 /* scatter/gather list entry */
120 } __packed TWE_SG_Entry
;
123 u_int8_t opcode
:5; /* TWE_OP_INITCONNECTION */
131 u_int16_t message_credits
;
132 u_int32_t response_queue_pointer
;
133 } __packed TWE_Command_INITCONNECTION
;
137 u_int8_t opcode
:5; /* TWE_OP_READ/TWE_OP_WRITE */
145 u_int16_t block_count
;
147 TWE_SG_Entry sgl
[TWE_MAX_SGL_LENGTH
];
148 } __packed TWE_Command_IO
;
152 u_int8_t opcode
:5; /* TWE_OP_HOTSWAP */
161 #define TWE_OP_HOTSWAP_REMOVE 0x00 /* remove assumed-degraded unit */
162 #define TWE_OP_HOTSWAP_ADD_CBOD 0x01 /* add CBOD to empty port */
163 #define TWE_OP_HOTSWAP_ADD_SPARE 0x02 /* add spare to empty port */
165 } __packed TWE_Command_HOTSWAP
;
169 u_int8_t opcode
:5; /* TWE_OP_SETATAFEATURE */
178 #define TWE_OP_SETATAFEATURE_WCE 0x02
179 #define TWE_OP_SETATAFEATURE_DIS_WCE 0x82
180 u_int8_t feature_mode
;
182 u_int16_t persistence
;
183 } __packed TWE_Command_SETATAFEATURE
;
187 u_int8_t opcode
:5; /* TWE_OP_CHECKSTATUS */
195 u_int16_t target_status
; /* set low byte to target request's ID */
196 } __packed TWE_Command_CHECKSTATUS
;
200 u_int8_t opcode
:5; /* TWE_OP_GETPARAM, TWE_OP_SETPARAM */
208 u_int16_t param_count
;
209 TWE_SG_Entry sgl
[TWE_MAX_SGL_LENGTH
];
210 } __packed TWE_Command_PARAM
;
214 u_int8_t opcode
:5; /* TWE_OP_REBUILDUNIT */
223 #define TWE_OP_REBUILDUNIT_NOP 0
224 #define TWE_OP_REBUILDUNIT_STOP 2 /* stop all rebuilds */
225 #define TWE_OP_REBUILDUNIT_START 4 /* start rebuild with lowest unit */
226 #define TWE_OP_REBUILDUNIT_STARTUNIT 5 /* rebuild src_unit (not supported) */
227 u_int8_t cs
:1; /* request state change on src_unit */
228 u_int8_t logical_subunit
; /* for RAID10 rebuild of logical subunit */
229 } __packed TWE_Command_REBUILDUNIT
;
234 u_int8_t sgl_offset
:3;
242 u_int16_t sector_count
;
243 u_int16_t sector_num
;
244 u_int16_t cylinder_lo
;
245 u_int16_t cylinder_hi
;
248 TWE_SG_Entry sgl
[TWE_MAX_ATA_SGL_LENGTH
];
249 } __packed TWE_Command_ATA
;
254 u_int8_t sgl_offset
:3;
261 #define TWE_FLAGS_SUCCESS 0x00
262 #define TWE_FLAGS_INFORMATIONAL 0x01
263 #define TWE_FLAGS_WARNING 0x02
264 #define TWE_FLAGS_FATAL 0x03
265 #define TWE_FLAGS_PERCENTAGE (1<<8) /* bits 0-6 indicate completion percentage */
266 u_int16_t count
; /* block count, parameter count, message credits */
267 } __packed TWE_Command_Generic
;
269 /* command packet - must be TWE_ALIGNMENT aligned */
272 TWE_Command_INITCONNECTION initconnection
;
274 TWE_Command_PARAM param
;
275 TWE_Command_CHECKSTATUS checkstatus
;
276 TWE_Command_REBUILDUNIT rebuildunit
;
277 TWE_Command_SETATAFEATURE setatafeature
;
279 TWE_Command_Generic generic
;
283 /* response queue entry */
288 u_int32_t undefined_1
:4;
289 u_int32_t response_id
:8;
290 u_int32_t undefined_2
:20;
293 } TWE_Response_Queue
;
297 #ifdef HAVE_SYS_TWEIO_H
298 #include <sys/tweio.h>
301 * Following cut out of tweio.h
307 * Note that the command's scatter/gather list will be computed by the
308 * driver, and cannot be filled in by the consumer.
310 struct twe_usercommand
{
311 TWE_Command tu_command
; /* command ready for the controller */
312 void *tu_data
; /* pointer to data in userspace */
313 size_t tu_size
; /* userspace data length */
316 #define TWEIO_COMMAND _IOWR('T', 100, struct twe_usercommand)
320 #ifdef HAVE_SYS_TW_OSL_IOCTL_H
321 #include <sys/tw_osl_ioctl.h>
324 * Following cut out of tw_osl_types.h
328 typedef void TW_VOID
;
329 typedef char TW_INT8
;
330 typedef unsigned char TW_UINT8
;
331 typedef short TW_INT16
;
332 typedef unsigned short TW_UINT16
;
333 typedef int TW_INT32
;
334 typedef unsigned int TW_UINT32
;
335 typedef long long TW_INT64
;
336 typedef unsigned long long TW_UINT64
;
339 * Following cut out of tw_cl_share.h
345 struct tw_cl_event_packet
{
346 TW_UINT32 sequence_id
;
347 TW_UINT32 time_stamp_sec
;
351 TW_UINT8 repeat_count
;
352 TW_UINT8 parameter_len
;
353 TW_UINT8 parameter_data
[98];
355 TW_UINT8 severity_str
[20];
361 * Following cut out of tw_cl_fwif.h
365 #define TWA_FW_CMD_ATA_PASSTHROUGH 0x11
367 #define TWA_SENSE_DATA_LENGTH 18
370 /* 7000 structures. */
371 struct tw_cl_command_init_connect
{
372 TW_UINT8 res1__opcode
; /* 3:5 */
378 TW_UINT16 message_credits
;
381 TW_UINT16 fw_arch_id
;
388 /* Structure for downloading firmware onto the controller. */
389 struct tw_cl_command_download_firmware
{
390 TW_UINT8 sgl_off__opcode
;/* 3:5 */
401 /* Structure for hard resetting the controller. */
402 struct tw_cl_command_reset_firmware
{
403 TW_UINT8 res1__opcode
; /* 3:5 */
414 /* Structure for sending get/set param commands. */
415 struct tw_cl_command_param
{
416 TW_UINT8 sgl_off__opcode
;/* 3:5 */
419 TW_UINT8 host_id__unit
; /* 4:4 */
422 TW_UINT16 param_count
;
427 /* Generic command packet. */
428 struct tw_cl_command_generic
{
429 TW_UINT8 sgl_off__opcode
;/* 3:5 */
432 TW_UINT8 host_id__unit
; /* 4:4 */
435 TW_UINT16 count
; /* block cnt, parameter cnt, message credits */
439 /* Command packet header. */
440 struct tw_cl_command_header
{
441 TW_UINT8 sense_data
[TWA_SENSE_DATA_LENGTH
];
446 TW_UINT8 res__severity
; /* 5:3 */
448 TW_UINT8 err_specific_desc
[98];
450 TW_UINT8 size_header
;
457 /* 7000 Command packet. */
458 union tw_cl_command_7k
{
459 struct tw_cl_command_init_connect init_connect
;
460 struct tw_cl_command_download_firmware download_fw
;
461 struct tw_cl_command_reset_firmware reset_fw
;
462 struct tw_cl_command_param param
;
463 struct tw_cl_command_generic generic
;
464 TW_UINT8 padding
[1024 - sizeof(struct tw_cl_command_header
)];
468 /* 9000 Command Packet. */
469 struct tw_cl_command_9k
{
470 TW_UINT8 res__opcode
; /* 3:5 */
472 TW_UINT16 lun_l4__req_id
; /* 4:12 */
474 TW_UINT8 sgl_offset
; /* offset (in bytes) to sg_list, from the
475 end of sgl_entries */
476 TW_UINT16 lun_h4__sgl_entries
;
478 TW_UINT8 sg_list
[872];/* total struct size =
479 1024-sizeof(cmd_hdr) */
483 /* Full command packet. */
484 struct tw_cl_command_packet
{
485 struct tw_cl_command_header cmd_hdr
;
487 union tw_cl_command_7k cmd_pkt_7k
;
488 struct tw_cl_command_9k cmd_pkt_9k
;
495 * Following cut out of tw_cl_ioctl.h
501 /* Structure used to handle GET/RELEASE LOCK ioctls. */
502 struct tw_cl_lock_packet
{
503 TW_UINT32 timeout_msec
;
504 TW_UINT32 time_remaining_msec
;
505 TW_UINT32 force_flag
;
509 /* Structure used to handle GET COMPATIBILITY INFO ioctl. */
510 struct tw_cl_compatibility_packet
{
511 TW_UINT8 driver_version
[32];/* driver version */
512 TW_UINT16 working_srl
; /* driver & firmware negotiated srl */
513 TW_UINT16 working_branch
; /* branch # of the firmware that the
514 driver is compatible with */
515 TW_UINT16 working_build
; /* build # of the firmware that the
516 driver is compatible with */
520 /* Driver understandable part of the ioctl packet built by the API. */
521 struct tw_cl_driver_packet
{
522 TW_UINT32 control_code
;
525 TW_UINT32 sequence_id
;
527 TW_UINT32 buffer_length
;
533 * Following cut out of tw_osl_ioctl.h
539 * We need the structure below to ensure that the first byte of
540 * data_buf is not overwritten by the kernel, after we return
541 * from the ioctl call. Note that cmd_pkt has been reduced
542 * to an array of 1024 bytes even though it's actually 2048 bytes
543 * in size. This is because, we don't expect requests from user
544 * land requiring 2048 (273 sg elements) byte cmd pkts.
546 typedef struct tw_osli_ioctl_no_data_buf
{
547 struct tw_cl_driver_packet driver_pkt
;
548 TW_VOID
*pdata
; /* points to data_buf */
549 TW_INT8 padding
[488 - sizeof(TW_VOID
*)];
550 struct tw_cl_command_packet cmd_pkt
;
551 } TW_OSLI_IOCTL_NO_DATA_BUF
;
555 #define TW_OSL_IOCTL_FIRMWARE_PASS_THROUGH \
556 _IOWR('T', 202, TW_OSLI_IOCTL_NO_DATA_BUF)
560 typedef struct tw_osli_ioctl_with_payload
{
561 struct tw_cl_driver_packet driver_pkt
;
562 TW_INT8 padding
[488];
563 struct tw_cl_command_packet cmd_pkt
;
565 struct tw_cl_event_packet event_pkt
;
566 struct tw_cl_lock_packet lock_pkt
;
567 struct tw_cl_compatibility_packet compat_pkt
;
570 } TW_OSLI_IOCTL_WITH_PAYLOAD
;
578 #define __unused __attribute__ ((__unused__))
581 #endif /* OS_FREEBSD_H_ */