]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_freebsd.h
Imported upstream version 5.38~cvs20071118
[mirror_smartmontools-debian.git] / os_freebsd.h
1 /*
2 * os_freebsd.h
3 *
4 * Home page of code is: http://smartmontools.sourceforge.net
5 *
6 * Copyright (C) 2003-6 Eduard Martinescu <smartmontools-support@lists.sourceforge.net>
7 *
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)
11 * any later version.
12 *
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.
16 *
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/
21 *
22 */
23
24 /*-
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.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
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.
39 *
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
50 * SUCH DAMAGE.
51 *
52 */
53
54 /*
55 * Copyright (c) 2004-05 Applied Micro Circuits Corporation.
56 * Copyright (c) 2004-05 Vinod Kashyap
57 * All rights reserved.
58 *
59 * Redistribution and use in source and binary forms, with or without
60 * modification, are permitted provided that the following conditions
61 * are met:
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.
67 *
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
78 * SUCH DAMAGE.
79 *
80 */
81
82 #ifndef OS_FREEBSD_H_
83 #define OS_FREEBSD_H_
84
85 #define OS_FREEBSD_H_CVSID "$Id: os_freebsd.h,v 1.21 2007/09/06 08:48:55 ballen4705 Exp $\n"
86
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
94 };
95
96 #define FREEBSD_MAXDEV 64
97 #define FREEBSD_FDOFFSET 16;
98 #define MAX_NUM_DEV 26
99
100 #ifdef HAVE_SYS_TWEREG_H
101 #include <sys/twereg.h>
102 #else
103 /**
104 * The following cut out of twereg.h
105 *
106 */
107 #if __FreeBSD_version < 500040
108 #define __packed __attribute__((__packed__))
109 #endif
110
111 #define TWE_MAX_SGL_LENGTH 62
112 #define TWE_MAX_ATA_SGL_LENGTH 60
113 #define TWE_OP_ATA_PASSTHROUGH 0x11
114
115 /* scatter/gather list entry */
116 typedef struct
117 {
118 u_int32_t address;
119 u_int32_t length;
120 } __packed TWE_SG_Entry;
121
122 typedef struct {
123 u_int8_t opcode:5; /* TWE_OP_INITCONNECTION */
124 u_int8_t res1:3;
125 u_int8_t size;
126 u_int8_t request_id;
127 u_int8_t res2:4;
128 u_int8_t host_id:4;
129 u_int8_t status;
130 u_int8_t flags;
131 u_int16_t message_credits;
132 u_int32_t response_queue_pointer;
133 } __packed TWE_Command_INITCONNECTION;
134
135 typedef struct
136 {
137 u_int8_t opcode:5; /* TWE_OP_READ/TWE_OP_WRITE */
138 u_int8_t res1:3;
139 u_int8_t size;
140 u_int8_t request_id;
141 u_int8_t unit:4;
142 u_int8_t host_id:4;
143 u_int8_t status;
144 u_int8_t flags;
145 u_int16_t block_count;
146 u_int32_t lba;
147 TWE_SG_Entry sgl[TWE_MAX_SGL_LENGTH];
148 } __packed TWE_Command_IO;
149
150 typedef struct
151 {
152 u_int8_t opcode:5; /* TWE_OP_HOTSWAP */
153 u_int8_t res1:3;
154 u_int8_t size;
155 u_int8_t request_id;
156 u_int8_t unit:4;
157 u_int8_t host_id:4;
158 u_int8_t status;
159 u_int8_t flags;
160 u_int8_t action;
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 */
164 u_int8_t aport;
165 } __packed TWE_Command_HOTSWAP;
166
167 typedef struct
168 {
169 u_int8_t opcode:5; /* TWE_OP_SETATAFEATURE */
170 u_int8_t res1:3;
171 u_int8_t size;
172 u_int8_t request_id;
173 u_int8_t unit:4;
174 u_int8_t host_id:4;
175 u_int8_t status;
176 u_int8_t flags;
177 u_int8_t feature;
178 #define TWE_OP_SETATAFEATURE_WCE 0x02
179 #define TWE_OP_SETATAFEATURE_DIS_WCE 0x82
180 u_int8_t feature_mode;
181 u_int16_t all_units;
182 u_int16_t persistence;
183 } __packed TWE_Command_SETATAFEATURE;
184
185 typedef struct
186 {
187 u_int8_t opcode:5; /* TWE_OP_CHECKSTATUS */
188 u_int8_t res1:3;
189 u_int8_t size;
190 u_int8_t request_id;
191 u_int8_t unit:4;
192 u_int8_t res2:4;
193 u_int8_t status;
194 u_int8_t flags;
195 u_int16_t target_status; /* set low byte to target request's ID */
196 } __packed TWE_Command_CHECKSTATUS;
197
198 typedef struct
199 {
200 u_int8_t opcode:5; /* TWE_OP_GETPARAM, TWE_OP_SETPARAM */
201 u_int8_t res1:3;
202 u_int8_t size;
203 u_int8_t request_id;
204 u_int8_t unit:4;
205 u_int8_t host_id:4;
206 u_int8_t status;
207 u_int8_t flags;
208 u_int16_t param_count;
209 TWE_SG_Entry sgl[TWE_MAX_SGL_LENGTH];
210 } __packed TWE_Command_PARAM;
211
212 typedef struct
213 {
214 u_int8_t opcode:5; /* TWE_OP_REBUILDUNIT */
215 u_int8_t res1:3;
216 u_int8_t size;
217 u_int8_t request_id;
218 u_int8_t src_unit:4;
219 u_int8_t host_id:4;
220 u_int8_t status;
221 u_int8_t flags;
222 u_int8_t action:7;
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;
230
231 typedef struct
232 {
233 u_int8_t opcode:5;
234 u_int8_t sgl_offset:3;
235 u_int8_t size;
236 u_int8_t request_id;
237 u_int8_t unit;
238 u_int8_t status;
239 u_int8_t flags;
240 u_int16_t param;
241 u_int16_t features;
242 u_int16_t sector_count;
243 u_int16_t sector_num;
244 u_int16_t cylinder_lo;
245 u_int16_t cylinder_hi;
246 u_int8_t drive_head;
247 u_int8_t command;
248 TWE_SG_Entry sgl[TWE_MAX_ATA_SGL_LENGTH];
249 } __packed TWE_Command_ATA;
250
251 typedef struct
252 {
253 u_int8_t opcode:5;
254 u_int8_t sgl_offset:3;
255 u_int8_t size;
256 u_int8_t request_id;
257 u_int8_t unit:4;
258 u_int8_t host_id:4;
259 u_int8_t status;
260 u_int8_t flags;
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;
268
269 /* command packet - must be TWE_ALIGNMENT aligned */
270 typedef union
271 {
272 TWE_Command_INITCONNECTION initconnection;
273 TWE_Command_IO io;
274 TWE_Command_PARAM param;
275 TWE_Command_CHECKSTATUS checkstatus;
276 TWE_Command_REBUILDUNIT rebuildunit;
277 TWE_Command_SETATAFEATURE setatafeature;
278 TWE_Command_ATA ata;
279 TWE_Command_Generic generic;
280 u_int8_t pad[512];
281 } TWE_Command;
282
283 /* response queue entry */
284 typedef union
285 {
286 struct
287 {
288 u_int32_t undefined_1:4;
289 u_int32_t response_id:8;
290 u_int32_t undefined_2:20;
291 } u;
292 u_int32_t value;
293 } TWE_Response_Queue;
294
295 #endif
296
297 #ifdef HAVE_SYS_TWEIO_H
298 #include <sys/tweio.h>
299 #else
300 /*
301 * Following cut out of tweio.h
302 *
303 */
304 /*
305 * User-space command
306 *
307 * Note that the command's scatter/gather list will be computed by the
308 * driver, and cannot be filled in by the consumer.
309 */
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 */
314 };
315
316 #define TWEIO_COMMAND _IOWR('T', 100, struct twe_usercommand)
317
318 #endif
319
320 #ifdef HAVE_SYS_TW_OSL_IOCTL_H
321 #include <sys/tw_osl_ioctl.h>
322 #else
323 /*
324 * Following cut out of tw_osl_types.h
325 *
326 */
327
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;
337
338 /*
339 * Following cut out of tw_cl_share.h
340 *
341 */
342
343 #pragma pack(1)
344
345 struct tw_cl_event_packet {
346 TW_UINT32 sequence_id;
347 TW_UINT32 time_stamp_sec;
348 TW_UINT16 aen_code;
349 TW_UINT8 severity;
350 TW_UINT8 retrieved;
351 TW_UINT8 repeat_count;
352 TW_UINT8 parameter_len;
353 TW_UINT8 parameter_data[98];
354 TW_UINT32 event_src;
355 TW_UINT8 severity_str[20];
356 };
357
358 #pragma pack()
359
360 /*
361 * Following cut out of tw_cl_fwif.h
362 *
363 */
364
365 #define TWA_FW_CMD_ATA_PASSTHROUGH 0x11
366
367 #define TWA_SENSE_DATA_LENGTH 18
368
369 #pragma pack(1)
370 /* 7000 structures. */
371 struct tw_cl_command_init_connect {
372 TW_UINT8 res1__opcode; /* 3:5 */
373 TW_UINT8 size;
374 TW_UINT8 request_id;
375 TW_UINT8 res2;
376 TW_UINT8 status;
377 TW_UINT8 flags;
378 TW_UINT16 message_credits;
379 TW_UINT32 features;
380 TW_UINT16 fw_srl;
381 TW_UINT16 fw_arch_id;
382 TW_UINT16 fw_branch;
383 TW_UINT16 fw_build;
384 TW_UINT32 result;
385 };
386
387
388 /* Structure for downloading firmware onto the controller. */
389 struct tw_cl_command_download_firmware {
390 TW_UINT8 sgl_off__opcode;/* 3:5 */
391 TW_UINT8 size;
392 TW_UINT8 request_id;
393 TW_UINT8 unit;
394 TW_UINT8 status;
395 TW_UINT8 flags;
396 TW_UINT16 param;
397 TW_UINT8 sgl[1];
398 };
399
400
401 /* Structure for hard resetting the controller. */
402 struct tw_cl_command_reset_firmware {
403 TW_UINT8 res1__opcode; /* 3:5 */
404 TW_UINT8 size;
405 TW_UINT8 request_id;
406 TW_UINT8 unit;
407 TW_UINT8 status;
408 TW_UINT8 flags;
409 TW_UINT8 res2;
410 TW_UINT8 param;
411 };
412
413
414 /* Structure for sending get/set param commands. */
415 struct tw_cl_command_param {
416 TW_UINT8 sgl_off__opcode;/* 3:5 */
417 TW_UINT8 size;
418 TW_UINT8 request_id;
419 TW_UINT8 host_id__unit; /* 4:4 */
420 TW_UINT8 status;
421 TW_UINT8 flags;
422 TW_UINT16 param_count;
423 TW_UINT8 sgl[1];
424 };
425
426
427 /* Generic command packet. */
428 struct tw_cl_command_generic {
429 TW_UINT8 sgl_off__opcode;/* 3:5 */
430 TW_UINT8 size;
431 TW_UINT8 request_id;
432 TW_UINT8 host_id__unit; /* 4:4 */
433 TW_UINT8 status;
434 TW_UINT8 flags;
435 TW_UINT16 count; /* block cnt, parameter cnt, message credits */
436 };
437
438
439 /* Command packet header. */
440 struct tw_cl_command_header {
441 TW_UINT8 sense_data[TWA_SENSE_DATA_LENGTH];
442 struct {
443 TW_INT8 reserved[4];
444 TW_UINT16 error;
445 TW_UINT8 padding;
446 TW_UINT8 res__severity; /* 5:3 */
447 } status_block;
448 TW_UINT8 err_specific_desc[98];
449 struct {
450 TW_UINT8 size_header;
451 TW_UINT16 reserved;
452 TW_UINT8 size_sense;
453 } header_desc;
454 };
455
456
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)];
465 };
466
467
468 /* 9000 Command Packet. */
469 struct tw_cl_command_9k {
470 TW_UINT8 res__opcode; /* 3:5 */
471 TW_UINT8 unit;
472 TW_UINT16 lun_l4__req_id; /* 4:12 */
473 TW_UINT8 status;
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;
477 TW_UINT8 cdb[16];
478 TW_UINT8 sg_list[872];/* total struct size =
479 1024-sizeof(cmd_hdr) */
480 };
481
482
483 /* Full command packet. */
484 struct tw_cl_command_packet {
485 struct tw_cl_command_header cmd_hdr;
486 union {
487 union tw_cl_command_7k cmd_pkt_7k;
488 struct tw_cl_command_9k cmd_pkt_9k;
489 } command;
490 };
491
492 #pragma pack()
493
494 /*
495 * Following cut out of tw_cl_ioctl.h
496 *
497 */
498
499 #pragma pack(1)
500
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;
506 };
507
508
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 */
517 };
518
519
520 /* Driver understandable part of the ioctl packet built by the API. */
521 struct tw_cl_driver_packet {
522 TW_UINT32 control_code;
523 TW_UINT32 status;
524 TW_UINT32 unique_id;
525 TW_UINT32 sequence_id;
526 TW_UINT32 os_status;
527 TW_UINT32 buffer_length;
528 };
529
530 #pragma pack()
531
532 /*
533 * Following cut out of tw_osl_ioctl.h
534 *
535 */
536
537 #pragma pack(1)
538 /*
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.
545 */
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;
552
553 #pragma pack()
554
555 #define TW_OSL_IOCTL_FIRMWARE_PASS_THROUGH \
556 _IOWR('T', 202, TW_OSLI_IOCTL_NO_DATA_BUF)
557
558 #pragma pack(1)
559
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;
564 union {
565 struct tw_cl_event_packet event_pkt;
566 struct tw_cl_lock_packet lock_pkt;
567 struct tw_cl_compatibility_packet compat_pkt;
568 TW_INT8 data_buf[1];
569 } payload;
570 } TW_OSLI_IOCTL_WITH_PAYLOAD;
571
572 #pragma pack()
573
574 #endif
575
576
577 #ifndef __unused
578 #define __unused __attribute__ ((__unused__))
579 #endif
580
581 #endif /* OS_FREEBSD_H_ */