xref: /titanic_41/usr/src/uts/common/sys/sata/sata_hba.h (revision 5aefb6555731130ca4fd295960123d71f2d21fe8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SATA_HBA_H
28 #define	_SATA_HBA_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/sata/sata_defs.h>
37 
38 /*
39  * SATA Host Bus Adapter (HBA) driver transport definitions
40  */
41 
42 #include <sys/types.h>
43 
44 #ifndef	TRUE
45 #define	TRUE	1
46 #define	FALSE	0
47 #endif
48 
49 #define	SATA_SUCCESS	0
50 #define	SATA_FAILURE	-1
51 
52 
53 /* SATA Framework definitions */
54 
55 #define	SATA_MAX_CPORTS		32	/* Max number of controller ports */
56 
57 					/* Multiplier (PMult) */
58 #define	SATA_MAX_PMPORTS	16	/* Maximum number of ports on PMult */
59 #define	SATA_PMULT_HOSTPORT	0xf	/* Port Multiplier host port number */
60 
61 
62 /*
63  * SATA device address
64  * Address qualifier flags are used to specify what is addressed (device
65  * or port) and where (controller or port multiplier data port).
66  */
67 struct sata_address {
68 	uint8_t		cport;		/* Controller's SATA port number */
69 	uint8_t 	pmport;		/* Port Multiplier SATA port number */
70 	uint8_t		qual;		/* Address Qualifier flags */
71 	uint8_t		pad;		/* Reserved */
72 };
73 
74 typedef struct sata_address sata_address_t;
75 
76 /*
77  * SATA address Qualifier flags (in qual field of sata_address struct).
78  * They are mutually exclusive.
79  */
80 
81 #define	SATA_ADDR_NULL		0x00	/* No address */
82 #define	SATA_ADDR_DCPORT	0x01	/* Device attched to controller port */
83 #define	SATA_ADDR_DPMPORT	0x02	/* Device attched to PM device port */
84 #define	SATA_ADDR_CPORT		0x04	/* Controller's device port */
85 #define	SATA_ADDR_PMPORT	0x08	/* Port Multiplier's device port */
86 #define	SATA_ADDR_CNTRL		0x10	/* Controller */
87 #define	SATA_ADDR_PMULT		0x20	/* Port Multiplier */
88 
89 /*
90  * SATA port status and control register block.
91  * The sstatus, serror, scontrol, sactive and snotific
92  * are the copies of the SATA port status and control registers.
93  * (Port SStatus, SError, SControl, SActive and SNotification are
94  * defined by Serial ATA r1.0a sepc and Serial ATA II spec.
95  */
96 
97 struct sata_port_scr
98 {
99 	uint32_t	sstatus;	/* Port SStatus register */
100 	uint32_t	serror;		/* Port SError register */
101 	uint32_t	scontrol;	/* Port SControl register */
102 	uint32_t	sactive;	/* Port SActive register */
103 	uint32_t	snotific; 	/* Port SNotification register */
104 };
105 
106 typedef struct sata_port_scr sata_port_scr_t;
107 
108 /*
109  * SATA Device Structure (rev 1)
110  * Used to request/return state of the controller, port, port multiplier
111  * or an attached drive:
112  *  	The satadev_addr.cport, satadev_addr.pmport and satadev_addr.qual
113  *  	fields are used to specify SATA address (see sata_address structure
114  *  	description).
115  * 	The satadev_scr structure is used to pass the content of a port
116  *	status and control registers.
117  *	The satadev_add_info field is used by SATA HBA driver to return an
118  *	additional information, which type depends on the function using
119  *	sata_device as argument. For example:
120  *	- in case of sata_tran_probe_port() this field should contain
121  *	a number of available Port Multiplier device ports;
122  *	- in case of sata_hba_event_notify() this field may contain
123  *	a value specific for a reported event.
124  */
125 #define	SATA_DEVICE_REV_1	1
126 #define	SATA_DEVICE_REV		SATA_DEVICE_REV_1
127 
128 struct sata_device
129 {
130 	int		satadev_rev;		/* structure  version */
131 	struct sata_address satadev_addr;	/* sata port/device address */
132 	uint32_t	satadev_state;		/* Port or device state */
133 	uint32_t	satadev_type;		/* Attached device type */
134 	struct sata_port_scr satadev_scr; 	/* Port status and ctrl regs */
135 	uint32_t	satadev_add_info;	/* additional information, */
136 						/* function specific */
137 };
138 
139 typedef struct sata_device sata_device_t;
140 
141 _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_device))
142 
143 
144 /*
145  * satadev_state field of sata_device structure.
146  * Common flags specifying current state of a port or an attached drive.
147  * These states are mutually exclusive, except SATA_STATE_PROBED and
148  * SATA_STATE_READY that may be set at the same time.
149  */
150 #define	SATA_STATE_UNKNOWN		0x000000
151 #define	SATA_STATE_PROBING		0x000001
152 #define	SATA_STATE_PROBED		0x000002
153 #define	SATA_STATE_READY		0x000010
154 
155 /*
156  * Attached drive specific states (satadev_state field of the sata_device
157  * structure).
158  * SATA_DSTATE_PWR_ACTIVE, SATA_DSTATE_PWR_IDLE and SATA_DSTATE_PWR_STANDBY
159  * are mutually exclusive. All other states may be combined with each other
160  * and with one of the power states.
161  * These flags may be used only if the address qualifier (satadev_addr.qual) is
162  * set to SATA_ADDR_DCPORT or SATA_ADDR_DPMPORT value.
163  */
164 
165 #define	SATA_DSTATE_PWR_ACTIVE		0x000100
166 #define	SATA_DSTATE_PWR_IDLE		0x000200
167 #define	SATA_DSTATE_PWR_STANDBY		0x000400
168 #define	SATA_DSTATE_RESET		0x001000
169 #define	SATA_DSTATE_FAILED		0x008000
170 
171 /* Mask for drive power states */
172 #define	SATA_DSTATE_PWR			(SATA_DSTATE_PWR_ACTIVE | \
173 					SATA_DSTATE_PWR_IDLE | \
174 					SATA_DSTATE_PWR_STANDBY)
175 /*
176  * SATA Port specific states (satadev_state field of sata_device structure).
177  * SATA_PSTATE_PWRON and SATA_PSTATE_PWROFF are mutually exclusive.
178  * All other states may be combined with each other and with one of the power
179  * level state.
180  * These flags may be used only if the address qualifier (satadev_addr.qual) is
181  * set to SATA_ADDR_CPORT or SATA_ADDR_PMPORT value.
182  */
183 
184 #define	SATA_PSTATE_PWRON		0x010000
185 #define	SATA_PSTATE_PWROFF		0X020000
186 #define	SATA_PSTATE_SHUTDOWN		0x040000
187 #define	SATA_PSTATE_FAILED		0x080000
188 
189 /* Mask for the valid port-specific state flags */
190 #define	SATA_PSTATE_VALID		(SATA_PSTATE_PWRON | \
191 					SATA_PSTATE_PWROFF | \
192 					SATA_PSTATE_SHUTDOWN | \
193 					SATA_PSTATE_FAILED)
194 
195 /* Mask for a port power states */
196 #define	SATA_PSTATE_PWR			(SATA_PSTATE_PWRON | \
197 					SATA_PSTATE_PWROFF)
198 /*
199  * Device type (in satadev_type field of sata_device structure).
200  * More device types may be added in the future.
201  */
202 
203 #define	SATA_DTYPE_NONE			0x00	/* No device attached */
204 #define	SATA_DTYPE_ATADISK		0x01	/* ATA Disk */
205 #define	SATA_DTYPE_ATAPICD		0x02	/* Atapi CD/DVD device */
206 #define	SATA_DTYPE_ATAPINONCD		0x03	/* Atapi non-CD/DVD device */
207 #define	SATA_DTYPE_PMULT		0x10	/* Port Multiplier */
208 #define	SATA_DTYPE_UNKNOWN		0x20	/* Device attached, unkown */
209 
210 
211 /*
212  * SATA cmd structure  (rev 1)
213  *
214  * SATA HBA framework always sets all fields except status_reg and error_reg.
215  * SATA HBA driver action depends on the addressing type specified by
216  * addr_type field:
217  * If LBA48 addressing is indicated, SATA HBA driver has to load values from
218  * satacmd_sec_count_msb_reg, satacmd_lba_low_msb_reg,
219  * satacmd_lba_mid_msb_reg and satacmd_lba_hi_msb_reg
220  * to appropriate registers prior to loading other registers.
221  * For other addressing modes, SATA HBA driver should skip loading values
222  * from satacmd_sec_count_msb_reg, satacmd_lba_low_msb_reg,
223  * satacmd_lba_mid_msb_reg and satacmd_lba_hi_msb_reg
224  * fields and load only remaining field values to corresponding registers.
225  *
226  * satacmd_sec_count_msb and satamcd_sec_count_lsb values are loaded into
227  * sec_count register, satacmd_sec_count_msb loaded first (if LBA48
228  * addressing is used).
229  * satacmd_lba_low_msb and satacmd_lba_low_lsb values are loaded into the
230  * lba_low register, satacmd_lba_low_msb loaded first (if LBA48 addressing
231  * is used). The lba_low register is the newer name for the old
232  * sector_number register.
233  * satacmd_lba_mid_msb and satacmd_lba_mid_lsb values are loaded into lba_mid
234  * register, satacmd_lba_mid_msb loaded first (if LBA48 addressing is used).
235  * The lba_mid register is the newer name for the old cylinder_low register.
236  * satacmd_lba_high_msb and satacmd_lba_high_lsb values are loaded into
237  * the lba_high regster, satacmd_lba_high_msb loaded first (if LBA48
238  * addressing is used). The lba_high register  is a newer name for the old
239  * cylinder_high register.
240  *
241  * No addressing mode is selected when an ata command does not involve actual
242  * reading/writing data from/to the media (for example IDENTIFY DEVICE or
243  * SET FEATURE command), or the ATAPI PACKET command is sent.
244  * If ATAPI PACKET command is sent and tagged commands are used,
245  * SATA HBA driver has to provide and manage a tag value and
246  * set it into the sector_count register.
247  *
248  * Device Control register is not specified in sata_cmd structure - SATA HBA
249  * driver shall set it accordingly to current mode of operation (interrupt
250  * enable/disable).
251  *
252  * Buffer structure's b_flags should be used to determine the
253  * address type of b_un.b_addr. However, there is no need to allocate DMA
254  * resources for the buffer in SATA HBA driver.
255  * DMA resources for a buffer structure are allocated by the SATA HBA
256  * framework. Scatter/gather list is to be used only for DMA transfers
257  * and it should be based on the DMA cookies list.
258  *
259  * Upon completion of a command, SATA HBA driver has to update
260  * satacmd_status_reg and satacmd_error_reg to reflect the contents of
261  * the corresponding device status and error registers.
262  * If the command completed with error, SATA HBA driver has to update
263  * satacmd_sec_count_msb, satacmd_sec_count_lsb, satacmd_lba_low_msb,
264  * satacmd_lba_low_lsb, satacmd_lba_mid_msb, satacmd_lba_mid_lsb,
265  * satacmd_lba_high_msb and satacmd_lba_high_lsb to values read from the
266  * corresponding device registers.
267  * If an operation could not complete because of the port error, the
268  * sata_pkt.satapkt_device.satadev_scr structure has to be updated.
269  *
270  * If ATAPI PACKET command was sent and command completed with error,
271  * rqsense structure has to be filed by SATA HBA driver. The satacmd_arq_cdb
272  * points to pre-set request sense cdb that may be used for issuing request
273  * sense data from the device.
274  *
275  * If FPDMA-type command was sent and command completed with error, the HBA
276  * driver may use pre-set command READ LOG EXTENDED command pointed to
277  * by satacmd_rle_sata_cmd field to retrieve error data from a device.
278  * Only ATA register fields of the sata_cmd are set-up for that purpose.
279  *
280  * If the READ MULTIPLIER command was specified in cmd_reg (command directed
281  * to a port multiplier host port rather then to an attached device),
282  * upon the command completion SATA HBA driver has to update_sector count
283  * and lba fields of the sata_cmd structure to values returned via
284  * command block registers (task file registers).
285  */
286 #define	SATA_CMD_REV_1	1
287 #define	SATA_CMD_REV_2	2
288 #define	SATA_CMD_REV	SATA_CMD_REV_2
289 
290 #define	SATA_ATAPI_MAX_CDB_LEN	16	/* Covers both 12 and 16 byte cdbs */
291 #define	SATA_ATAPI_RQSENSE_LEN	24	/* Fixed size Request Sense data */
292 
293 struct sata_cmd {
294 	int		satacmd_rev;		/* version */
295 	struct buf	*satacmd_bp;		/* ptr to buffer structure */
296 	struct sata_cmd_flags {
297 		uint32_t	sata_data_direction : 3;	 /* 0-2 */
298 		uint32_t	: 1;		/* reserved */	 /* 3 */
299 		uint32_t	sata_queue_stag : 1;		 /* 4 */
300 		uint32_t	sata_queue_otag : 1;		 /* 5 */
301 		uint32_t	: 2;		/* reserved */	 /* 6-7 */
302 		uint32_t	sata_queued : 1;		 /* 8 */
303 		uint32_t	: 3;		/* reserved */	 /* 9-11 */
304 		uint32_t	sata_ignore_dev_reset : 1;	 /* 12 */
305 		uint32_t	sata_clear_dev_reset : 1;	 /* 13 */
306 		uint32_t	: 2;		/* reserved */	 /* 14-15 */
307 		uint32_t	sata_special_regs : 1;		 /* 16 */
308 		uint32_t	sata_copy_out_sec_count_msb : 1; /* 17 */
309 		uint32_t	sata_copy_out_lba_low_msb : 1;	 /* 18 */
310 		uint32_t	sata_copy_out_lba_mid_msb : 1;	 /* 19 */
311 		uint32_t	sata_copy_out_lba_high_msb : 1;	 /* 20 */
312 		uint32_t	sata_copy_out_sec_count_lsb : 1; /* 21 */
313 		uint32_t	sata_copy_out_lba_low_lsb : 1;	 /* 22 */
314 		uint32_t	sata_copy_out_lba_mid_lsb : 1;	 /* 23 */
315 		uint32_t	sata_copy_out_lba_high_lsb : 1;	 /* 24 */
316 		uint32_t	sata_copy_out_device_reg : 1;	 /* 25 */
317 		uint32_t	sata_copy_out_error_reg : 1;	 /* 26 */
318 		uint32_t	: 5;		/* reserved */	 /* 27-31 */
319 	} satacmd_flags;
320 	uint8_t 	satacmd_addr_type; 	/* addr type: LBA28, LBA48 */
321 	uint8_t		satacmd_features_reg_ext; /* features reg extended */
322 	uint8_t		satacmd_sec_count_msb;	/* sector count MSB (LBA48) */
323 	uint8_t		satacmd_lba_low_msb; 	/* LBA Low MSB (LBA48) */
324 	uint8_t		satacmd_lba_mid_msb;	/* LBA Mid MSB (LBA48) */
325 	uint8_t		satacmd_lba_high_msb;	/* LBA High MSB (LBA48) */
326 	uint8_t		satacmd_sec_count_lsb;	/* sector count LSB */
327 	uint8_t		satacmd_lba_low_lsb;	/* LBA Low LSB */
328 	uint8_t		satacmd_lba_mid_lsb;	/* LBA Mid LSB */
329 	uint8_t		satacmd_lba_high_lsb;	/* LBA High LSB */
330 	uint8_t		satacmd_device_reg;	/* ATA dev reg & LBA28 MSB */
331 	uint8_t		satacmd_cmd_reg;	/* ata command code */
332 	uint8_t		satacmd_features_reg;	/* ATA features register */
333 	uint8_t		satacmd_status_reg;	/* ATA status register */
334 	uint8_t		satacmd_error_reg;	/* ATA error register  */
335 	uint8_t		satacmd_acdb_len;	/* ATAPI cdb length */
336 	uint8_t		satacmd_acdb[SATA_ATAPI_MAX_CDB_LEN]; /* ATAPI cdb */
337 
338 						/*
339 						 * Ptr to request sense cdb
340 						 * request sense buf
341 						 */
342 	uint8_t		*satacmd_arq_cdb;
343 
344 	uint8_t 	satacmd_rqsense[SATA_ATAPI_RQSENSE_LEN];
345 
346 						/*
347 						 * Ptr to FPDMA error
348 						 * retrieval cmd
349 						 */
350 	struct sata_cmd	*satacmd_rle_sata_cmd;
351 
352 	int		satacmd_num_dma_cookies; /* number of dma cookies */
353 						/* ptr to dma cookie list */
354 	ddi_dma_cookie_t *satacmd_dma_cookie_list;
355 };
356 
357 typedef struct sata_cmd sata_cmd_t;
358 
359 _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_cmd))
360 
361 
362 /* ATA address type (in satacmd_addr_type field */
363 #define	ATA_ADDR_LBA	0x1
364 #define	ATA_ADDR_LBA28	0x2
365 #define	ATA_ADDR_LBA48	0x4
366 
367 /*
368  * satacmd_flags : contain data transfer direction flags,
369  * tagged queuing type flags, queued command flag, and reset state handling
370  * flag.
371  */
372 
373 /*
374  * Data transfer direction flags (satacmd_flags.sata_data_direction)
375  * Direction flags are mutually exclusive.
376  */
377 #define	SATA_DIR_NODATA_XFER	0x0001	/* No data transfer */
378 #define	SATA_DIR_READ		0x0002	/* Reading data from a device */
379 #define	SATA_DIR_WRITE		0x0004	/* Writing data to a device */
380 
381 /*
382  * Tagged Queuing type flags (satacmd_flags).
383  * These flags indicate how the SATA command should be queued.
384  *
385  * SATA_QUEUE_STAG_CMD
386  * Simple-queue-tagged command. It may be executed out-of-order in respect
387  * to other queued commands.
388  * SATA_QUEUE_OTAG_CMD
389  * Ordered-queue-tagged command. It cannot be executed out-of-order in
390  * respect to other commands, i.e. it should be executed in the order of
391  * being transported to the HBA.
392  *
393  * Translated head-of-queue-tagged scsi commands and commands that are
394  * to be put at the head of the queue are treated as SATA_QUEUE_OTAG_CMD
395  * tagged commands.
396  */
397 #define	SATA_QUEUE_STAG_CMD	0x0010	/* simple-queue-tagged command */
398 #define	SATA_QUEUE_OTAG_CMD	0x0020	/* ordered-queue-tagged command */
399 
400 
401 /*
402  * Queuing command set-up flag (satacmd_flags).
403  * This flag indicates that sata_cmd was set-up for DMA Queued command
404  * (either READ_DMA_QUEUED, READ_DMA_QUEUED_EXT, WRITE_DMA_QUEUED or
405  * WRITE_DMA_QUEUED_EXT command) or one of the Native Command Queuing commands
406  * (either READ_FPDMA_QUEUED or WRITE_FPDMA_QUEUED).
407  * This flag will be used only if sata_tran_hba_flags indicates controller
408  * support for queuing and the device for which sata_cmd is prepared supports
409  * either legacy queuing (indicated by Device Identify data word 83 bit 2)
410  * or NCQ (indicated by  word 76 of Device Identify data).
411  */
412 #define	SATA_QUEUED_CMD			0x0100
413 
414 
415 /*
416  * Reset state handling (satacmd_flags).
417  * SATA HBA device enters reset state if the device was subjected to
418  * the Device Reset (may also enter this state if the device was reset
419  * as a side effect of port reset). SATA HBA driver sets this state.
420  * Device stays in this condition until explicit request from SATA HBA
421  * framework (SATA_CLEAR_DEV_RESET_STATE flag) to clear the state.
422  */
423 #define	SATA_IGNORE_DEV_RESET_STATE	0x1000
424 #define	SATA_CLEAR_DEV_RESET_STATE	0x2000
425 
426 /*
427  * SATA Packet structure (rev 1)
428  * hba_driver_private is for a private use of the SATA HBA driver;
429  * satapkt_framework_private is used only by SATA HBA framework;
430  * satapkt_comp is a callback function to be called when packet
431  * execution is completed (for any reason) if mode of operation is not
432  * synchronous (SATA_OPMODE_SYNCH);
433  * satapkt_reason specifies why the packet operation was completed
434  *
435  * NOTE: after the packet completion callback SATA HBA driver should not
436  * attempt to access any sata_pkt fields because sata_pkt is not valid anymore
437  * (it could have been destroyed).
438  * Since satapkt_hba_driver_private field cannot be retrieved, any hba private
439  * data respources allocated per packet and accessed via this pointer should
440  * either be freed before the completion callback is done, or the pointer has
441  * to be saved by the HBA driver before the completion callback.
442  */
443 #define	SATA_PKT_REV_1	1
444 #define	SATA_PKT_REV	SATA_PKT_REV_1
445 
446 struct sata_pkt {
447 	int		satapkt_rev;		/* version */
448 	struct sata_device satapkt_device;	/* Device address/type */
449 
450 						/* HBA driver private data */
451 	void		*satapkt_hba_driver_private;
452 
453 						/* SATA framework priv data */
454 	void		*satapkt_framework_private;
455 
456 						/* Rqsted mode of operation */
457 	uint32_t	satapkt_op_mode;
458 
459 	struct sata_cmd	satapkt_cmd;		/* composite sata command */
460 	int		satapkt_time;		/* time allotted to command */
461 	void		(*satapkt_comp)(struct sata_pkt *); /* callback */
462 	int		satapkt_reason; 	/* completion reason */
463 };
464 
465 typedef struct sata_pkt sata_pkt_t;
466 
467 _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_pkt))
468 
469 
470 /*
471  * Operation mode flags (in satapkt_op_mode field of sata_pkt structure).
472  * Use to specify what should be a mode of operation for specified command.
473  * Default (000b) means use Interrupt and Asynchronous mode to
474  * perform an operation.
475  * Synchronous operation menas that the packet operation has to be completed
476  * before the function called to initiate the operation returns.
477  */
478 #define	SATA_OPMODE_INTERRUPTS	0 /* Use interrupts (hint) */
479 #define	SATA_OPMODE_POLLING	1 /* Use polling instead of interrupts */
480 #define	SATA_OPMODE_ASYNCH	0 /* Return immediately after accepting pkt */
481 #define	SATA_OPMODE_SYNCH	4 /* Perform synchronous operation */
482 
483 /*
484  * satapkt_reason values:
485  *
486  * SATA_PKT_QUEUE_FULL - cmd not sent because of queue full (detected
487  * 	by the controller). If a device reject command for this reason, it
488  * 	should be reported as SATA_PKT_DEV_ERROR
489  *
490  * SATA_PKT_CMD_NOT_SUPPORTED - command not supported by a controller
491  *	Controller is unable to send such command to a device.
492  *	If device rejects a command, it should be reported as
493  *	SATA_PKT_DEV_ERROR.
494  *
495  * SATA_PKT_DEV_ERROR - cmd failed because of device reported an error.
496  *	The content of status_reg (ERROR bit has to be set) and error_reg
497  *	fields of the sata_cmd structure have to be set and will be used
498  *	by SATA HBA Framework to determine the error cause.
499  *
500  * SATA_PKT_PORT_ERROR - cmd failed because of a link or a port error.
501  *	Link failed / no communication with a device / communication error
502  *	or other port related error was detected by a controller.
503  *	sata_pkt.satapkt_device.satadev_scr.sXXXXXXX words have to be set.
504  *
505  * SATA_PKT_ABORTED - cmd execution was aborted by the request from the
506  *	framework. Abort mechanism is HBA driver specific.
507  *
508  * SATA_PKT_TIMEOUT - cmd execution has timed-out. Timeout specified by
509  *	 pkt_time was exceeded. The command was terminated by the SATA HBA
510  *	driver.
511  *
512  * SATA_PKT_COMPLETED - this is a value returned when an operation
513  *	completes without errors.
514  *
515  * SATA_PKT_BUSY - packet was not accepted for execution because the
516  *      driver was busy performing some other operation(s).
517  *
518  * SATA_PKT_RESET - packet execution was aborted because of device
519  * reset originated by either the HBA driver or the SATA framework.
520  *
521  */
522 
523 #define	SATA_PKT_BUSY			-1	/* Not completed, busy */
524 #define	SATA_PKT_COMPLETED		0	/* No error */
525 #define	SATA_PKT_DEV_ERROR		1	/* Device reported error */
526 #define	SATA_PKT_QUEUE_FULL		2	/* Not accepted, queue full */
527 #define	SATA_PKT_PORT_ERROR		3	/* Not completed, port error */
528 #define	SATA_PKT_CMD_UNSUPPORTED	4	/* Cmd unsupported */
529 #define	SATA_PKT_ABORTED		5	/* Aborted by request */
530 #define	SATA_PKT_TIMEOUT		6	/* Operation timeut */
531 #define	SATA_PKT_RESET			7	/* Aborted by reset request */
532 
533 /*
534  * Hoplug functions vector structure (rev 1)
535  */
536 #define	SATA_TRAN_HOTPLUG_OPS_REV_1	1
537 
538 struct sata_tran_hotplug_ops {
539 	int	sata_tran_hotplug_ops_rev; /* version */
540 	int	(*sata_tran_port_activate)(dev_info_t  *, sata_device_t *);
541 	int	(*sata_tran_port_deactivate)(dev_info_t  *, sata_device_t *);
542 };
543 
544 typedef struct sata_tran_hotplug_ops sata_tran_hotplug_ops_t;
545 
546 
547 /*
548  * Power management functions vector structure (rev 1)
549  * The embedded function returns information about the controller's
550  * power level.
551  * Additional functions may be added in the future without changes to
552  * sata_tran structure.
553  */
554 #define	SATA_TRAN_PWRMGT_OPS_REV_1	1
555 
556 struct sata_tran_pwrmgt_ops {
557 	int	sata_tran_pwrmgt_ops_rev; /* version */
558 	int	(*sata_tran_get_pwr_level)(dev_info_t  *, sata_device_t *);
559 };
560 
561 typedef struct sata_tran_pwrmgt_ops sata_tran_pwrmgt_ops_t;
562 
563 
564 /*
565  * SATA port PHY Power Level
566  * These states correspond to the interface power management state as defined
567  * in Serial ATA spec.
568  */
569 #define	SATA_TRAN_PORTPWR_LEVEL1	1 /* Interface in active PM state */
570 #define	SATA_TRAN_PORTPWR_LEVEL2	2 /* Interface in PARTIAL PM state */
571 #define	SATA_TRAN_PORTPWR_LEVEL3	3 /* Interface in SLUMBER PM state */
572 
573 /*
574  * SATA HBA Tran structure (rev 1)
575  * Registered with SATA Framework
576  *
577  * dma_attr is a pointer to data (buffer) dma attibutes of the controller
578  * DMA engine.
579  *
580  * The qdepth field specifies number of commands that may be accepted by
581  * the controller. Value range 1-32. A value greater than 1 indicates that
582  * the controller supports queuing. Support for Native Command Queuing
583  * indicated by SATA_CTLF_NCQ flag also requires qdepth set to a value
584  * greater then 1.
585  *
586  */
587 #define	SATA_TRAN_HBA_REV_1	1
588 #define	SATA_TRAN_HBA_REV	SATA_TRAN_HBA_REV_1
589 
590 struct sata_hba_tran {
591 	int		sata_tran_hba_rev;	/* version */
592 	dev_info_t	*sata_tran_hba_dip;	/* Controler dev info */
593 	ddi_dma_attr_t	*sata_tran_hba_dma_attr; /* DMA attributes */
594 	int		sata_tran_hba_num_cports; /* Num of HBA device ports */
595 	uint16_t	sata_tran_hba_features_support; /* HBA features */
596 	uint16_t	sata_tran_hba_qdepth;	/* HBA-supported queue depth */
597 
598 	int		(*sata_tran_probe_port)(dev_info_t *, sata_device_t *);
599 	int		(*sata_tran_start)(dev_info_t *, sata_pkt_t *);
600 	int		(*sata_tran_abort)(dev_info_t *, sata_pkt_t *, int);
601 	int		(*sata_tran_reset_dport)(dev_info_t *,
602 					sata_device_t *);
603 	int		(*sata_tran_selftest)(dev_info_t *, sata_device_t *);
604 
605 						/* Hotplug vector */
606 	struct sata_tran_hotplug_ops *sata_tran_hotplug_ops;
607 
608 						/* Power mgt vector */
609 	struct sata_tran_pwrmgt_ops *sata_tran_pwrmgt_ops;
610 
611 	int		(*sata_tran_ioctl)(dev_info_t *, int, intptr_t);
612 };
613 
614 typedef struct sata_hba_tran sata_hba_tran_t;
615 
616 
617 /*
618  * Controller's features support flags (sata_tran_hba_features_support).
619  * Note: SATA_CTLF_NCQ indicates that SATA controller supports NCQ in addition
620  * to legacy queuing commands, indicated by SATA_CTLF_QCMD flag.
621  */
622 
623 #define	SATA_CTLF_ATAPI			0x001 /* ATAPI support */
624 #define	SATA_CTLF_PORT_MULTIPLIER 	0x010 /* Port Multiplier suport */
625 #define	SATA_CTLF_HOTPLUG		0x020 /* Hotplug support */
626 #define	SATA_CTLF_ASN			0x040 /* Asynchronous Event Support */
627 #define	SATA_CTLF_QCMD			0x080 /* Queued commands support */
628 #define	SATA_CTLF_NCQ			0x100 /* NCQ support */
629 
630 /*
631  * sata_tran_start() return values.
632  * When pkt is not accepted, the satapkt_reason has to be updated
633  * before function returns - it should reflect the same reason for not being
634  * executed as the return status of above functions.
635  * If pkt was accepted and executed synchronously,
636  * satapk_reason should indicate a completion status.
637  */
638 #define	SATA_TRAN_ACCEPTED		0 /* accepted */
639 #define	SATA_TRAN_QUEUE_FULL		1 /* not accepted, queue full */
640 #define	SATA_TRAN_PORT_ERROR		2 /* not accepted, port error */
641 #define	SATA_TRAN_CMD_UNSUPPORTED	3 /* not accepted, cmd not supported */
642 #define	SATA_TRAN_BUSY			4 /* not accepted, busy */
643 
644 
645 /*
646  * sata_tran_abort() abort type flag
647  */
648 #define	SATA_ABORT_PACKET		0
649 #define	SATA_ABORT_ALL_PACKETS		1
650 
651 
652 /*
653  * Events handled by SATA HBA Framework
654  * More then one event may be reported at the same time
655  *
656  * SATA_EVNT__DEVICE_ATTACHED
657  * HBA detected the presence of a device ( electrical connection with
658  * a device was detected ).
659  *
660  * SATA_EVNT_DEVICE_DETACHED
661  * HBA detected the detachment of a device (electrical connection with
662  * a device was broken)
663  *
664  * SATA_EVNT_LINK_LOST
665  * HBA lost link with an attached device
666  *
667  * SATA_EVNT_LINK_ESTABLISHED
668  * HBA established a link with an attached device
669  *
670  * SATA_EVNT_PORT_FAILED
671  * HBA has determined that the port failed and is unuseable
672  *
673  * SATA_EVENT_DEVICE_RESET
674  * SATA device was reset, causing loss of the device setting
675  *
676  * SATA_EVNT_PWR_LEVEL_CHANGED
677  * A port or entire SATA controller power level has changed
678  *
679  */
680 #define	SATA_EVNT_DEVICE_ATTACHED	0x01
681 #define	SATA_EVNT_DEVICE_DETACHED	0x02
682 #define	SATA_EVNT_LINK_LOST		0x04
683 #define	SATA_EVNT_LINK_ESTABLISHED	0x08
684 #define	SATA_EVNT_PORT_FAILED		0x10
685 #define	SATA_EVNT_DEVICE_RESET		0x20
686 #define	SATA_EVNT_PWR_LEVEL_CHANGED	0x40
687 
688 /*
689  * SATA Framework interface entry points
690  */
691 int 	sata_hba_init(struct modlinkage *);
692 int 	sata_hba_attach(dev_info_t *, sata_hba_tran_t *, ddi_attach_cmd_t);
693 int 	sata_hba_detach(dev_info_t *, ddi_detach_cmd_t);
694 void 	sata_hba_fini(struct modlinkage *);
695 void 	sata_hba_event_notify(dev_info_t *, sata_device_t *, int);
696 
697 
698 #ifdef	__cplusplus
699 }
700 #endif
701 
702 #endif /* _SATA_HBA_H */
703