2 * HighPoint RR3xxx controller driver for Linux
3 * Copyright (C) 2006 HighPoint Technologies, Inc. All Rights Reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * Please report bugs/comments/suggestions to linux@highpoint-tech.com
16 * For more information, visit http://www.highpoint-tech.com
22 * logical device type.
23 * Identify array (logical device) and physical device.
38 #define MAX_NAME_LENGTH 36
39 #define MAX_ARRAYNAME_LEN 16
41 #define MAX_ARRAY_MEMBERS_V1 8
42 #define MAX_ARRAY_MEMBERS_V2 16
44 /* keep definition for source code compatiblity */
45 #define MAX_ARRAY_MEMBERS MAX_ARRAY_MEMBERS_V1
50 #define ARRAY_FLAG_DISABLED 0x00000001 /* The array is disabled */
51 #define ARRAY_FLAG_NEEDBUILDING 0x00000002 /* need to be rebuilt */
52 #define ARRAY_FLAG_REBUILDING 0x00000004 /* in rebuilding process */
53 #define ARRAY_FLAG_BROKEN 0x00000008 /* broken but still working */
54 #define ARRAY_FLAG_BOOTDISK 0x00000010 /* has a active partition */
55 #define ARRAY_FLAG_BOOTMARK 0x00000040 /* array has boot mark set */
56 #define ARRAY_FLAG_NEED_AUTOREBUILD 0x00000080 /* auto-rebuild should start */
57 #define ARRAY_FLAG_VERIFYING 0x00000100 /* is being verified */
58 #define ARRAY_FLAG_INITIALIZING 0x00000200 /* is being initialized */
59 #define ARRAY_FLAG_TRANSFORMING 0x00000400 /* tranform in progress */
60 #define ARRAY_FLAG_NEEDTRANSFORM 0x00000800 /* array need tranform */
61 #define ARRAY_FLAG_NEEDINITIALIZING 0x00001000 /* initialization not done */
62 #define ARRAY_FLAG_BROKEN_REDUNDANT 0x00002000 /* broken but redundant */
67 #define DEVICE_FLAG_DISABLED 0x00000001 /* device is disabled */
68 #define DEVICE_FLAG_UNINITIALIZED 0x00010000 /* device is not initialized */
69 #define DEVICE_FLAG_LEGACY 0x00020000 /* lagacy drive */
70 #define DEVICE_FLAG_IS_SPARE 0x80000000 /* is a spare disk */
75 #define HPT_CTL_CODE(x) (x+0xFF00)
76 #define HPT_CTL_CODE_LINUX_TO_IOP(x) ((x)-0xff00)
78 #define HPT_IOCTL_GET_CONTROLLER_INFO HPT_CTL_CODE(2)
79 #define HPT_IOCTL_GET_CHANNEL_INFO HPT_CTL_CODE(3)
80 #define HPT_IOCTL_GET_LOGICAL_DEVICES HPT_CTL_CODE(4)
81 #define HPT_IOCTL_GET_DRIVER_CAPABILITIES HPT_CTL_CODE(19)
82 #define HPT_IOCTL_GET_DEVICE_INFO_V3 HPT_CTL_CODE(46)
83 #define HPT_IOCTL_GET_CONTROLLER_INFO_V2 HPT_CTL_CODE(47)
86 * Controller information.
88 struct hpt_controller_info
{
89 u8 chip_type
; /* chip type */
90 u8 interrupt_level
; /* IRQ level */
91 u8 num_buses
; /* bus count */
94 u8 product_id
[MAX_NAME_LENGTH
];/* product name */
95 u8 vendor_id
[MAX_NAME_LENGTH
]; /* vendor name */
97 __attribute__((packed
));
100 * Channel information.
102 struct hpt_channel_info
{
103 __le32 io_port
; /* IDE Base Port Address */
104 __le32 control_port
; /* IDE Control Port Address */
105 __le32 devices
[2]; /* device connected to this channel */
107 __attribute__((packed
));
112 struct hpt_array_info_v3
{
113 u8 name
[MAX_ARRAYNAME_LEN
]; /* array name */
114 u8 description
[64]; /* array description */
115 u8 create_manager
[16]; /* who created it */
116 __le32 create_time
; /* when created it */
118 u8 array_type
; /* array type */
119 u8 block_size_shift
; /* stripe size */
120 u8 ndisk
; /* Number of ID in Members[] */
123 __le32 flags
; /* working flags, see ARRAY_FLAG_XXX */
124 __le32 members
[MAX_ARRAY_MEMBERS_V2
]; /* member array/disks */
126 __le32 rebuilding_progress
;
127 __le64 rebuilt_sectors
; /* rebuilding point (LBA) for single member */
129 __le32 transform_source
;
130 __le32 transform_target
; /* destination device ID */
131 __le32 transforming_progress
;
132 __le32 signature
; /* persistent identification*/
133 __le16 critical_members
; /* bit mask of critical members */
137 __attribute__((packed
));
140 * physical device information.
142 #define MAX_PARENTS_PER_DISK 8
144 struct hpt_device_info_v2
{
145 u8 ctlr_id
; /* controller id */
146 u8 path_id
; /* bus */
147 u8 target_id
; /* id */
148 u8 device_mode_setting
; /* Current Data Transfer mode: 0-4 PIO0-4 */
149 /* 5-7 MW DMA0-2, 8-13 UDMA0-5 */
150 u8 device_type
; /* device type */
151 u8 usable_mode
; /* highest usable mode */
153 #ifdef __BIG_ENDIAN_BITFIELD
158 u8 write_cache_enabled
: 1;
159 u8 write_cache_supported
: 1;
160 u8 read_ahead_enabled
: 1;
161 u8 read_ahead_supported
: 1;
165 u8 read_ahead_supported
: 1;
166 u8 read_ahead_enabled
: 1;
167 u8 write_cache_supported
: 1;
168 u8 write_cache_enabled
: 1;
177 __le32 flags
; /* working flags, see DEVICE_FLAG_XXX */
178 u8 ident
[150]; /* (partitial) Identify Data of this device */
183 __le32 parent_arrays
[MAX_PARENTS_PER_DISK
];
185 __attribute__((packed
));
188 * Logical device information.
190 #define INVALID_TARGET_ID 0xFF
191 #define INVALID_BUS_ID 0xFF
193 struct hpt_logical_device_info_v3
{
194 u8 type
; /* LDT_ARRAY or LDT_DEVICE */
195 u8 cache_policy
; /* refer to CACHE_POLICY_xxx */
196 u8 vbus_id
; /* vbus sequence in vbus_list */
197 u8 target_id
; /* OS target id. 0xFF is invalid */
198 /* OS name: DISK $VBusId_$TargetId */
199 __le64 capacity
; /* array capacity */
200 __le32 parent_array
; /* don't use this field for physical
201 device. use ParentArrays field in
202 hpt_device_info_v2 */
203 /* reserved statistic fields */
210 struct hpt_array_info_v3 array
;
211 struct hpt_device_info_v2 device
;
212 } __attribute__((packed
)) u
;
215 __attribute__((packed
));
220 #define HPT_IOCTL_MAGIC 0xA1B2C3D4
223 u32 magic
; /* used to check if it's a valid ioctl packet */
224 u32 ioctl_code
; /* operation control code */
225 void __user
*inbuf
; /* input data buffer */
226 u32 inbuf_size
; /* size of input data buffer */
227 void __user
*outbuf
; /* output data buffer */
228 u32 outbuf_size
; /* size of output data buffer */
229 void __user
*bytes_returned
; /* count of bytes returned */
231 __attribute__((packed
));
237 __le32 inbound_msgaddr0
;
238 __le32 inbound_msgaddr1
;
239 __le32 outbound_msgaddr0
;
240 __le32 outbound_msgaddr1
;
241 __le32 inbound_doorbell
;
242 __le32 inbound_intstatus
;
243 __le32 inbound_intmask
;
244 __le32 outbound_doorbell
;
245 __le32 outbound_intstatus
;
246 __le32 outbound_intmask
;
248 __le32 inbound_queue
;
249 __le32 outbound_queue
;
252 #define IOPMU_QUEUE_EMPTY 0xffffffff
253 #define IOPMU_QUEUE_MASK_HOST_BITS 0xf0000000
254 #define IOPMU_QUEUE_ADDR_HOST_BIT 0x80000000
256 #define IOPMU_OUTBOUND_INT_MSG0 1
257 #define IOPMU_OUTBOUND_INT_MSG1 2
258 #define IOPMU_OUTBOUND_INT_DOORBELL 4
259 #define IOPMU_OUTBOUND_INT_POSTQUEUE 8
260 #define IOPMU_OUTBOUND_INT_PCI 0x10
262 #define IOPMU_INBOUND_INT_MSG0 1
263 #define IOPMU_INBOUND_INT_MSG1 2
264 #define IOPMU_INBOUND_INT_DOORBELL 4
265 #define IOPMU_INBOUND_INT_ERROR 8
266 #define IOPMU_INBOUND_INT_POSTQUEUE 0x10
268 enum hpt_iopmu_message
{
269 /* host-to-iop messages */
270 IOPMU_INBOUND_MSG0_NOP
= 0,
271 IOPMU_INBOUND_MSG0_RESET
,
272 IOPMU_INBOUND_MSG0_FLUSH
,
273 IOPMU_INBOUND_MSG0_SHUTDOWN
,
274 IOPMU_INBOUND_MSG0_STOP_BACKGROUND_TASK
,
275 IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK
,
276 IOPMU_INBOUND_MSG0_MAX
= 0xff,
277 /* iop-to-host messages */
278 IOPMU_OUTBOUND_MSG0_REGISTER_DEVICE_0
= 0x100,
279 IOPMU_OUTBOUND_MSG0_REGISTER_DEVICE_MAX
= 0x1ff,
280 IOPMU_OUTBOUND_MSG0_UNREGISTER_DEVICE_0
= 0x200,
281 IOPMU_OUTBOUND_MSG0_UNREGISTER_DEVICE_MAX
= 0x2ff,
282 IOPMU_OUTBOUND_MSG0_REVALIDATE_DEVICE_0
= 0x300,
283 IOPMU_OUTBOUND_MSG0_REVALIDATE_DEVICE_MAX
= 0x3ff,
286 struct hpt_iop_request_header
292 __le32 context
; /* host context */
296 #define IOP_REQUEST_FLAG_SYNC_REQUEST 1
297 #define IOP_REQUEST_FLAG_BIST_REQUEST 2
298 #define IOP_REQUEST_FLAG_REMAPPED 4
299 #define IOP_REQUEST_FLAG_OUTPUT_CONTEXT 8
301 enum hpt_iop_request_type
{
302 IOP_REQUEST_TYPE_GET_CONFIG
= 0,
303 IOP_REQUEST_TYPE_SET_CONFIG
,
304 IOP_REQUEST_TYPE_BLOCK_COMMAND
,
305 IOP_REQUEST_TYPE_SCSI_COMMAND
,
306 IOP_REQUEST_TYPE_IOCTL_COMMAND
,
310 enum hpt_iop_result_type
{
311 IOP_RESULT_PENDING
= 0,
316 IOP_RESULT_INVALID_REQUEST
,
317 IOP_RESULT_BAD_TARGET
,
318 IOP_RESULT_MODE_SENSE_CHECK_CONDITION
,
321 struct hpt_iop_request_get_config
323 struct hpt_iop_request_header header
;
324 __le32 interface_version
;
325 __le32 firmware_version
;
329 __le32 data_transfer_length
;
330 __le32 alignment_mask
;
335 struct hpt_iop_request_set_config
337 struct hpt_iop_request_header header
;
346 __le32 eot
; /* non-zero: end of table */
350 struct hpt_iop_request_block_command
352 struct hpt_iop_request_header header
;
357 __le16 command
; /* IOP_BLOCK_COMMAND_{READ,WRITE} */
360 struct hpt_iopsg sg_list
[1];
363 #define IOP_BLOCK_COMMAND_READ 1
364 #define IOP_BLOCK_COMMAND_WRITE 2
365 #define IOP_BLOCK_COMMAND_VERIFY 3
366 #define IOP_BLOCK_COMMAND_FLUSH 4
367 #define IOP_BLOCK_COMMAND_SHUTDOWN 5
369 struct hpt_iop_request_scsi_command
371 struct hpt_iop_request_header header
;
377 __le32 dataxfer_length
;
378 struct hpt_iopsg sg_list
[1];
381 struct hpt_iop_request_ioctl_command
383 struct hpt_iop_request_header header
;
387 __le32 bytes_returned
;
389 /* out data should be put at buf[(inbuf_size+3)&~3] */
392 #define HPTIOP_MAX_REQUESTS 256u
394 struct hptiop_request
{
395 struct hptiop_request
* next
;
398 struct scsi_cmnd
* scp
;
402 struct hpt_scsi_pointer
{
405 dma_addr_t dma_handle
;
408 #define HPT_SCP(scp) ((struct hpt_scsi_pointer *)&(scp)->SCp)
411 struct hpt_iopmu __iomem
* iop
;
412 struct Scsi_Host
* host
;
413 struct pci_dev
* pcidev
;
415 struct list_head link
;
417 /* IOP config info */
418 u32 firmware_version
;
422 u32 max_request_size
;
423 u32 max_sg_descriptors
;
425 u32 req_size
; /* host-allocated request buffer size */
429 struct hptiop_request
* req_list
;
430 struct hptiop_request reqs
[HPTIOP_MAX_REQUESTS
];
432 /* used to free allocated dma area */
434 dma_addr_t dma_coherent_handle
;
436 atomic_t reset_count
;
439 wait_queue_head_t reset_wq
;
440 wait_queue_head_t ioctl_wq
;
445 struct hptiop_hba
* hba
;
451 u32
* bytes_returned
;
452 void (*done
)(struct hpt_ioctl_k
*);
453 int result
; /* HPT_IOCTL_RESULT_ */
456 #define HPT_IOCTL_RESULT_OK 0
457 #define HPT_IOCTL_RESULT_FAILED (-1)
460 #define dprintk(fmt, args...) do { printk(fmt, ##args); } while(0)
462 #define dprintk(fmt, args...)