]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - os_freebsd.h
debian/rules: - remove autogenerated files
[mirror_smartmontools-debian.git] / os_freebsd.h
CommitLineData
832b75ed
GG
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.20 2006/04/12 14:54:28 ballen4705 Exp $\n"
86
87struct 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 */
116typedef struct
117{
118 u_int32_t address;
119 u_int32_t length;
120} __packed TWE_SG_Entry;
121
122typedef 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
135typedef 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
150typedef 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
167typedef 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
185typedef 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
198typedef 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
212typedef 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
231typedef 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:4;
238 u_int8_t host_id:4;
239 u_int8_t status;
240 u_int8_t flags;
241 u_int16_t param;
242 u_int16_t features;
243 u_int16_t sector_count;
244 u_int16_t sector_num;
245 u_int16_t cylinder_lo;
246 u_int16_t cylinder_hi;
247 u_int8_t drive_head;
248 u_int8_t command;
249 TWE_SG_Entry sgl[TWE_MAX_ATA_SGL_LENGTH];
250} __packed TWE_Command_ATA;
251
252typedef struct
253{
254 u_int8_t opcode:5;
255 u_int8_t sgl_offset:3;
256 u_int8_t size;
257 u_int8_t request_id;
258 u_int8_t unit:4;
259 u_int8_t host_id:4;
260 u_int8_t status;
261 u_int8_t flags;
262#define TWE_FLAGS_SUCCESS 0x00
263#define TWE_FLAGS_INFORMATIONAL 0x01
264#define TWE_FLAGS_WARNING 0x02
265#define TWE_FLAGS_FATAL 0x03
266#define TWE_FLAGS_PERCENTAGE (1<<8) /* bits 0-6 indicate completion percentage */
267 u_int16_t count; /* block count, parameter count, message credits */
268} __packed TWE_Command_Generic;
269
270/* command packet - must be TWE_ALIGNMENT aligned */
271typedef union
272{
273 TWE_Command_INITCONNECTION initconnection;
274 TWE_Command_IO io;
275 TWE_Command_PARAM param;
276 TWE_Command_CHECKSTATUS checkstatus;
277 TWE_Command_REBUILDUNIT rebuildunit;
278 TWE_Command_SETATAFEATURE setatafeature;
279 TWE_Command_ATA ata;
280 TWE_Command_Generic generic;
281 u_int8_t pad[512];
282} TWE_Command;
283
284/* response queue entry */
285typedef union
286{
287 struct
288 {
289 u_int32_t undefined_1:4;
290 u_int32_t response_id:8;
291 u_int32_t undefined_2:20;
292 } u;
293 u_int32_t value;
294} TWE_Response_Queue;
295
296#endif
297
298#ifdef HAVE_SYS_TWEIO_H
299#include <sys/tweio.h>
300#else
301/*
302 * Following cut out of tweio.h
303 *
304 */
305/*
306 * User-space command
307 *
308 * Note that the command's scatter/gather list will be computed by the
309 * driver, and cannot be filled in by the consumer.
310 */
311struct twe_usercommand {
312 TWE_Command tu_command; /* command ready for the controller */
313 void *tu_data; /* pointer to data in userspace */
314 size_t tu_size; /* userspace data length */
315};
316
317#define TWEIO_COMMAND _IOWR('T', 100, struct twe_usercommand)
318
319#endif
320
321#ifdef HAVE_SYS_TW_OSL_IOCTL_H
322#include <sys/tw_osl_ioctl.h>
323#else
324/*
325 * Following cut out of tw_osl_types.h
326 *
327 */
328
329typedef void TW_VOID;
330typedef char TW_INT8;
331typedef unsigned char TW_UINT8;
332typedef short TW_INT16;
333typedef unsigned short TW_UINT16;
334typedef int TW_INT32;
335typedef unsigned int TW_UINT32;
336typedef long long TW_INT64;
337typedef unsigned long long TW_UINT64;
338
339/*
340 * Following cut out of tw_cl_share.h
341 *
342 */
343
344#pragma pack(1)
345
346struct tw_cl_event_packet {
347 TW_UINT32 sequence_id;
348 TW_UINT32 time_stamp_sec;
349 TW_UINT16 aen_code;
350 TW_UINT8 severity;
351 TW_UINT8 retrieved;
352 TW_UINT8 repeat_count;
353 TW_UINT8 parameter_len;
354 TW_UINT8 parameter_data[98];
355 TW_UINT32 event_src;
356 TW_UINT8 severity_str[20];
357};
358
359#pragma pack()
360
361/*
362 * Following cut out of tw_cl_fwif.h
363 *
364 */
365
366#define TWA_FW_CMD_ATA_PASSTHROUGH 0x11
367
368#define TWA_SENSE_DATA_LENGTH 18
369
370#pragma pack(1)
371/* 7000 structures. */
372struct tw_cl_command_init_connect {
373 TW_UINT8 res1__opcode; /* 3:5 */
374 TW_UINT8 size;
375 TW_UINT8 request_id;
376 TW_UINT8 res2;
377 TW_UINT8 status;
378 TW_UINT8 flags;
379 TW_UINT16 message_credits;
380 TW_UINT32 features;
381 TW_UINT16 fw_srl;
382 TW_UINT16 fw_arch_id;
383 TW_UINT16 fw_branch;
384 TW_UINT16 fw_build;
385 TW_UINT32 result;
386};
387
388
389/* Structure for downloading firmware onto the controller. */
390struct tw_cl_command_download_firmware {
391 TW_UINT8 sgl_off__opcode;/* 3:5 */
392 TW_UINT8 size;
393 TW_UINT8 request_id;
394 TW_UINT8 unit;
395 TW_UINT8 status;
396 TW_UINT8 flags;
397 TW_UINT16 param;
398 TW_UINT8 sgl[1];
399};
400
401
402/* Structure for hard resetting the controller. */
403struct tw_cl_command_reset_firmware {
404 TW_UINT8 res1__opcode; /* 3:5 */
405 TW_UINT8 size;
406 TW_UINT8 request_id;
407 TW_UINT8 unit;
408 TW_UINT8 status;
409 TW_UINT8 flags;
410 TW_UINT8 res2;
411 TW_UINT8 param;
412};
413
414
415/* Structure for sending get/set param commands. */
416struct tw_cl_command_param {
417 TW_UINT8 sgl_off__opcode;/* 3:5 */
418 TW_UINT8 size;
419 TW_UINT8 request_id;
420 TW_UINT8 host_id__unit; /* 4:4 */
421 TW_UINT8 status;
422 TW_UINT8 flags;
423 TW_UINT16 param_count;
424 TW_UINT8 sgl[1];
425};
426
427
428/* Generic command packet. */
429struct tw_cl_command_generic {
430 TW_UINT8 sgl_off__opcode;/* 3:5 */
431 TW_UINT8 size;
432 TW_UINT8 request_id;
433 TW_UINT8 host_id__unit; /* 4:4 */
434 TW_UINT8 status;
435 TW_UINT8 flags;
436 TW_UINT16 count; /* block cnt, parameter cnt, message credits */
437};
438
439
440/* Command packet header. */
441struct tw_cl_command_header {
442 TW_UINT8 sense_data[TWA_SENSE_DATA_LENGTH];
443 struct {
444 TW_INT8 reserved[4];
445 TW_UINT16 error;
446 TW_UINT8 padding;
447 TW_UINT8 res__severity; /* 5:3 */
448 } status_block;
449 TW_UINT8 err_specific_desc[98];
450 struct {
451 TW_UINT8 size_header;
452 TW_UINT16 reserved;
453 TW_UINT8 size_sense;
454 } header_desc;
455};
456
457
458/* 7000 Command packet. */
459union tw_cl_command_7k {
460 struct tw_cl_command_init_connect init_connect;
461 struct tw_cl_command_download_firmware download_fw;
462 struct tw_cl_command_reset_firmware reset_fw;
463 struct tw_cl_command_param param;
464 struct tw_cl_command_generic generic;
465 TW_UINT8 padding[1024 - sizeof(struct tw_cl_command_header)];
466};
467
468
469/* 9000 Command Packet. */
470struct tw_cl_command_9k {
471 TW_UINT8 res__opcode; /* 3:5 */
472 TW_UINT8 unit;
473 TW_UINT16 lun_l4__req_id; /* 4:12 */
474 TW_UINT8 status;
475 TW_UINT8 sgl_offset; /* offset (in bytes) to sg_list, from the
476 end of sgl_entries */
477 TW_UINT16 lun_h4__sgl_entries;
478 TW_UINT8 cdb[16];
479 TW_UINT8 sg_list[872];/* total struct size =
480 1024-sizeof(cmd_hdr) */
481};
482
483
484/* Full command packet. */
485struct tw_cl_command_packet {
486 struct tw_cl_command_header cmd_hdr;
487 union {
488 union tw_cl_command_7k cmd_pkt_7k;
489 struct tw_cl_command_9k cmd_pkt_9k;
490 } command;
491};
492
493#pragma pack()
494
495/*
496 * Following cut out of tw_cl_ioctl.h
497 *
498 */
499
500#pragma pack(1)
501
502/* Structure used to handle GET/RELEASE LOCK ioctls. */
503struct tw_cl_lock_packet {
504 TW_UINT32 timeout_msec;
505 TW_UINT32 time_remaining_msec;
506 TW_UINT32 force_flag;
507};
508
509
510/* Structure used to handle GET COMPATIBILITY INFO ioctl. */
511struct tw_cl_compatibility_packet {
512 TW_UINT8 driver_version[32];/* driver version */
513 TW_UINT16 working_srl; /* driver & firmware negotiated srl */
514 TW_UINT16 working_branch; /* branch # of the firmware that the
515 driver is compatible with */
516 TW_UINT16 working_build; /* build # of the firmware that the
517 driver is compatible with */
518};
519
520
521/* Driver understandable part of the ioctl packet built by the API. */
522struct tw_cl_driver_packet {
523 TW_UINT32 control_code;
524 TW_UINT32 status;
525 TW_UINT32 unique_id;
526 TW_UINT32 sequence_id;
527 TW_UINT32 os_status;
528 TW_UINT32 buffer_length;
529};
530
531#pragma pack()
532
533/*
534 * Following cut out of tw_osl_ioctl.h
535 *
536 */
537
538#pragma pack(1)
539/*
540 * We need the structure below to ensure that the first byte of
541 * data_buf is not overwritten by the kernel, after we return
542 * from the ioctl call. Note that cmd_pkt has been reduced
543 * to an array of 1024 bytes even though it's actually 2048 bytes
544 * in size. This is because, we don't expect requests from user
545 * land requiring 2048 (273 sg elements) byte cmd pkts.
546 */
547typedef struct tw_osli_ioctl_no_data_buf {
548 struct tw_cl_driver_packet driver_pkt;
549 TW_VOID *pdata; /* points to data_buf */
550 TW_INT8 padding[488 - sizeof(TW_VOID *)];
551 struct tw_cl_command_packet cmd_pkt;
552} TW_OSLI_IOCTL_NO_DATA_BUF;
553
554#pragma pack()
555
556#define TW_OSL_IOCTL_FIRMWARE_PASS_THROUGH \
557 _IOWR('T', 202, TW_OSLI_IOCTL_NO_DATA_BUF)
558
559#pragma pack(1)
560
561typedef struct tw_osli_ioctl_with_payload {
562 struct tw_cl_driver_packet driver_pkt;
563 TW_INT8 padding[488];
564 struct tw_cl_command_packet cmd_pkt;
565 union {
566 struct tw_cl_event_packet event_pkt;
567 struct tw_cl_lock_packet lock_pkt;
568 struct tw_cl_compatibility_packet compat_pkt;
569 TW_INT8 data_buf[1];
570 } payload;
571} TW_OSLI_IOCTL_WITH_PAYLOAD;
572
573#pragma pack()
574
575#endif
576
577
578#ifndef __unused
579#define __unused __attribute__ ((__unused__))
580#endif
581
582#endif /* OS_FREEBSD_H_ */