1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Aic94xx SAS/SATA driver SAS definitions and hardware interface header file.
5 * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
6 * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
9 #ifndef _AIC94XX_SAS_H_
10 #define _AIC94XX_SAS_H_
12 #include <scsi/libsas.h>
14 /* ---------- DDBs ---------- */
15 /* DDBs are device descriptor blocks which describe a device in the
16 * domain that this sequencer can maintain low-level connections for
17 * us. They are be 64 bytes.
19 #define ASD_MAX_DDBS 128
21 struct asd_ddb_ssp_smp_target_port
{
22 u8 conn_type
; /* byte 0 */
23 #define DDB_TP_CONN_TYPE 0x81 /* Initiator port and addr frame type 0x01 */
27 u8 dest_sas_addr
[8]; /* bytes 4-11 */
29 __le16 send_queue_head
;
31 u8 ddb_type
; /* DDB_TYPE_TARGET */
32 #define DDB_TYPE_UNUSED 0xFF
33 #define DDB_TYPE_TARGET 0xFE
34 #define DDB_TYPE_INITIATOR 0xFD
35 #define DDB_TYPE_PM_PORT 0xFC
40 u8 compat_features
; /* byte 20 */
41 u8 pathway_blocked_count
;
43 __be32 more_compat_features
; /* byte 24 */
46 u8 flags
; /* concurrent conn:2,2 and open:0(1) */
47 #define CONCURRENT_CONN_SUPP 0x04
48 #define OPEN_REQUIRED 0x01
51 __le16 exec_queue_tail
;
52 __le16 send_queue_tail
;
57 u8 max_concurrent_conn
;
58 u8 num_concurrent_conn
;
63 __le16 active_task_count
;
67 u8 itnl_reason
; /* I_T nexus loss reason */
72 #define ITNL_TIMEOUT_CONST 0x7D0 /* 2 seconds */
74 __le32 itnl_timestamp
;
75 } __attribute__ ((packed
));
77 struct asd_ddb_stp_sata_target_port
{
78 u8 conn_type
; /* byte 0 */
81 u8 dest_sas_addr
[8]; /* bytes 4-11 */
83 __le16 send_queue_head
;
85 u8 ddb_type
; /* DDB_TYPE_TARGET */
90 u8 compat_features
; /* byte 20 */
91 u8 pathway_blocked_count
;
93 __be32 more_compat_features
; /* byte 24 */
96 u8 flags
; /* concurrent conn:2,2 and open:0(1) */
97 #define SATA_MULTIPORT 0x80
98 #define SUPPORTS_AFFIL 0x40
99 #define STP_AFFIL_POL 0x20
102 u8 flags2
; /* STP close policy:0 */
103 #define STP_CL_POL_NO_TX 0x00
104 #define STP_CL_POL_BTW_CMDS 0x01
106 __le16 exec_queue_tail
;
107 __le16 send_queue_tail
;
109 __le16 ata_cmd_scbptr
;
110 __le32 sata_tag_alloc_mask
;
111 __le16 active_task_count
;
116 u8 sata_ending_status
;
117 u8 itnl_reason
; /* I_T nexus loss reason */
118 __le16 ncq_data_scb_ptr
;
120 __le32 itnl_timestamp
;
121 } __attribute__ ((packed
));
123 /* This struct asd_ddb_init_port, describes the device descriptor block
124 * of an initiator port (when the sequencer is operating in target mode).
125 * Bytes [0,11] and [20,27] are from the OPEN address frame.
126 * The sequencer allocates an initiator port DDB entry.
128 struct asd_ddb_init_port
{
129 u8 conn_type
; /* byte 0 */
131 __be16 init_conn_tag
; /* BE */
133 __le16 send_queue_head
; /* LE, byte 12 */
135 u8 ddb_type
; /* DDB_TYPE_INITIATOR */
137 __be16 awt_def
; /* BE */
139 u8 pathway_blocked_count
;
140 __be16 arb_wait_time
; /* BE */
141 __be32 more_compat_features
; /* BE */
145 __le16 exec_queue_tail
; /* execution queue tail */
146 __le16 send_queue_tail
;
148 __le16 init_resp_timeout
; /* initiator response timeout */
150 __le16 active_tasks
; /* active task count */
151 __le16 init_list
; /* initiator list link pointer */
153 u8 max_conn_to
[3]; /* from Conn-Disc mode page, in us, LE */
154 u8 itnl_reason
; /* I_T nexus loss reason */
155 __le16 bus_inact_to
; /* from Conn-Disc mode page, in 100 us, LE */
156 __le16 itnl_to
; /* from the Protocol Specific Port Ctrl MP */
157 __le32 itnl_timestamp
;
158 } __attribute__ ((packed
));
160 /* This struct asd_ddb_sata_tag, describes a look-up table to be used
161 * by the sequencers. SATA II, IDENTIFY DEVICE data, word 76, bit 8:
162 * NCQ support. This table is used by the sequencers to find the
163 * corresponding SCB, given a SATA II tag value.
165 struct asd_ddb_sata_tag
{
166 __le16 scb_pointer
[32];
167 } __attribute__ ((packed
));
169 /* This struct asd_ddb_sata_pm_table, describes a port number to
170 * connection handle look-up table. SATA targets attached to a port
171 * multiplier require a 4-bit port number value. There is one DDB
172 * entry of this type for each SATA port multiplier (sister DDB).
173 * Given a SATA PM port number, this table gives us the SATA PM Port
174 * DDB of the SATA port multiplier port (i.e. the SATA target
175 * discovered on the port).
177 struct asd_ddb_sata_pm_table
{
178 __le16 ddb_pointer
[16];
180 } __attribute__ ((packed
));
182 /* This struct asd_ddb_sata_pm_port, describes the SATA port multiplier
185 struct asd_ddb_sata_pm_port
{
190 #define PM_PORT_MASK 0xF0
191 #define PM_PORT_SET 0x02
194 __le16 ata_cmd_scbptr
;
195 __le32 sata_tag_alloc_mask
;
196 __le16 active_task_count
;
201 u8 sata_ending_status
;
203 } __attribute__ ((packed
));
205 /* This struct asd_ddb_seq_shared, describes a DDB shared by the
206 * central and link sequencers. port_map_by_links is indexed phy
207 * number [0,7]; each byte is a bit mask of all the phys that are in
208 * the same port as the indexed phy.
210 struct asd_ddb_seq_shared
{
211 __le16 q_free_ddb_head
;
212 __le16 q_free_ddb_tail
;
213 __le16 q_free_ddb_cnt
;
214 __le16 q_used_ddb_head
;
215 __le16 q_used_ddb_tail
;
216 __le16 shared_mem_lock
;
218 __le16 est_nexus_buf_cnt
;
219 __le16 est_nexus_buf_thresh
;
221 u8 settable_max_contexts
;
226 u8 port_map_by_links
[8];
227 } __attribute__ ((packed
));
229 /* ---------- SG Element ---------- */
231 /* This struct sg_el, describes the hardware scatter gather buffer
232 * element. All entries are little endian. In an SCB, there are 2 of
233 * this, plus one more, called a link element of this indicating a
236 * A link element has only the bus address set and the flags (DS) bit
237 * valid. The bus address points to the start of the sublist.
239 * If a sublist is needed, then that sublist should also include the 2
240 * sg_el embedded in the SCB, in which case next_sg_offset is 32,
241 * since sizeof(sg_el) = 16; EOS should be 1 and EOL 0 in this case.
249 #define ASD_SG_EL_DS_MASK 0x30
250 #define ASD_SG_EL_DS_OCM 0x10
251 #define ASD_SG_EL_DS_HM 0x00
252 #define ASD_SG_EL_LIST_MASK 0xC0
253 #define ASD_SG_EL_LIST_EOL 0x40
254 #define ASD_SG_EL_LIST_EOS 0x80
255 } __attribute__ ((packed
));
257 /* ---------- SCBs ---------- */
259 /* An SCB (sequencer control block) is comprised of a common header
260 * and a task part, for a total of 128 bytes. All fields are in LE
261 * order, unless otherwise noted.
264 /* This struct scb_header, defines the SCB header format.
268 __le16 index
; /* transaction context */
270 } __attribute__ ((packed
));
272 /* SCB opcodes: Execution queue
274 #define INITIATE_SSP_TASK 0x00
275 #define INITIATE_LONG_SSP_TASK 0x01
276 #define INITIATE_BIDIR_SSP_TASK 0x02
277 #define SCB_ABORT_TASK 0x03
278 #define INITIATE_SSP_TMF 0x04
279 #define SSP_TARG_GET_DATA 0x05
280 #define SSP_TARG_GET_DATA_GOOD 0x06
281 #define SSP_TARG_SEND_RESP 0x07
282 #define QUERY_SSP_TASK 0x08
283 #define INITIATE_ATA_TASK 0x09
284 #define INITIATE_ATAPI_TASK 0x0a
285 #define CONTROL_ATA_DEV 0x0b
286 #define INITIATE_SMP_TASK 0x0c
287 #define SMP_TARG_SEND_RESP 0x0f
289 /* SCB opcodes: Send Queue
291 #define SSP_TARG_SEND_DATA 0x40
292 #define SSP_TARG_SEND_DATA_GOOD 0x41
294 /* SCB opcodes: Link Queue
296 #define CONTROL_PHY 0x80
297 #define SEND_PRIMITIVE 0x81
298 #define INITIATE_LINK_ADM_TASK 0x82
300 /* SCB opcodes: other
302 #define EMPTY_SCB 0xc0
303 #define INITIATE_SEQ_ADM_TASK 0xc1
304 #define EST_ICL_TARG_WINDOW 0xc2
305 #define COPY_MEM 0xc3
306 #define CLEAR_NEXUS 0xc4
307 #define INITIATE_DDB_ADM_TASK 0xc6
308 #define ESTABLISH_NEXUS_ESCB 0xd0
312 #define EFB_MASK 0x80
313 #define TASK_PRIO_MASK 0x78
314 #define TASK_ATTR_MASK 0x07
315 /* ---------- SCB tasks ---------- */
317 /* This is both ssp_task and long_ssp_task
319 struct initiate_ssp_task
{
320 u8 proto_conn_rate
; /* proto:6,4, conn_rate:3,0 */
321 __le32 total_xfer_len
;
322 struct ssp_frame_hdr ssp_frame
;
323 struct ssp_command_iu ssp_cmd
;
324 __le16 sister_scb
; /* 0xFFFF */
325 __le16 conn_handle
; /* index to DDB for the intended target */
326 u8 data_dir
; /* :1,0 */
327 #define DATA_DIR_NONE 0x00
328 #define DATA_DIR_IN 0x01
329 #define DATA_DIR_OUT 0x02
330 #define DATA_DIR_BYRECIPIENT 0x03
335 struct sg_el sg_element
[3]; /* 2 real and 1 link */
336 } __attribute__ ((packed
));
338 /* This defines both ata_task and atapi_task.
339 * ata: C bit of FIS should be 1,
340 * atapi: C bit of FIS should be 1, and command register should be 0xA0,
341 * to indicate a packet command.
343 struct initiate_ata_task
{
345 __le32 total_xfer_len
;
346 struct host_to_dev_fis fis
;
352 u8 ata_flags
; /* CSMI:6,6, DTM:4,4, QT:3,3, data dir:1,0 */
353 #define CSMI_TASK 0x40
354 #define DATA_XFER_MODE_DMA 0x10
355 #define ATA_Q_TYPE_MASK 0x08
356 #define ATA_Q_TYPE_UNTAGGED 0x00
357 #define ATA_Q_TYPE_NCQ 0x08
363 #define STP_AFFIL_POLICY 0x20
364 #define SET_AFFIL_POLICY 0x10
365 #define RET_PARTIAL_SGLIST 0x02
368 struct sg_el sg_element
[3];
369 } __attribute__ ((packed
));
371 struct initiate_smp_task
{
374 struct sg_el smp_req
;
378 struct sg_el smp_resp
;
380 } __attribute__ ((packed
));
385 #define DISABLE_PHY 0x00
386 #define ENABLE_PHY 0x01
387 #define RELEASE_SPINUP_HOLD 0x02
388 #define ENABLE_PHY_NO_SAS_OOB 0x03
389 #define ENABLE_PHY_NO_SATA_OOB 0x04
390 #define PHY_NO_OP 0x05
391 #define EXECUTE_HARD_RESET 0x81
398 #define DEV_PRES_TIMER_OVERRIDE_ENABLE 0x01
399 #define DISABLE_PHY_IF_OOB_FAILS 0x02
401 __le32 timeout_override
;
402 u8 link_reset_retries
;
406 } __attribute__ ((packed
));
408 struct control_ata_dev
{
411 struct host_to_dev_fis fis
;
415 u8 ata_flags
; /* 0 */
417 } __attribute__ ((packed
));
422 #define ASD_EDBS_PER_SCB 7
423 /* header+data+CRC+DMA suffix data */
424 #define ASD_EDB_SIZE (24+1024+4+16)
425 struct sg_el eb
[ASD_EDBS_PER_SCB
];
426 #define ELEMENT_NOT_VALID 0xC0
427 } __attribute__ ((packed
));
429 struct initiate_link_adm
{
432 #define GET_LINK_ERROR_COUNT 0x00
433 #define RESET_LINK_ERROR_COUNT 0x01
434 #define ENABLE_NOTIFY_SPINUP_INTS 0x02
439 } __attribute__ ((packed
));
446 u8 src_ds
; /* See definition of sg_el */
451 u8 dest_ds
; /* See definition of sg_el */
453 } __attribute__ ((packed
));
458 struct ssp_frame_hdr ssp_frame
;
459 struct ssp_tmf_iu ssp_task
;
462 u8 flags
; /* ovrd_itnl_timer:3,3, suspend_data_trans:2,2 */
463 #define SUSPEND_DATA_TRANS 0x04
468 __le16 index
; /* Transaction context of task to be queried */
471 } __attribute__ ((packed
));
475 #define NEXUS_ADAPTER 0x00
476 #define NEXUS_PORT 0x01
477 #define NEXUS_I_T 0x02
478 #define NEXUS_I_T_L 0x03
479 #define NEXUS_TAG 0x04
480 #define NEXUS_TRANS_CX 0x05
481 #define NEXUS_SATA_TAG 0x06
482 #define NEXUS_T_L 0x07
484 #define NEXUS_T_TAG 0x09
488 #define SUSPEND_TX 0x80
489 #define RESUME_TX 0x40
497 struct ssp_tmf_iu ssp_task
; /* LUN and TAG */
501 __le16 index
; /* Transaction context of task to be cleared */
502 __le16 context
; /* Clear nexus context */
504 } __attribute__ ((packed
));
506 struct initiate_ssp_tmf
{
509 struct ssp_frame_hdr ssp_frame
;
510 struct ssp_tmf_iu ssp_task
;
513 u8 flags
; /* itnl override and suspend data tx */
514 #define OVERRIDE_ITNL_TIMER 8
519 __le16 index
; /* Transaction context of task to be queried */
522 } __attribute__ ((packed
));
524 /* Transmits an arbitrary primitive on the link.
525 * Used for NOTIFY and BROADCAST.
529 u8 wait_transmit
; /* :0,0 */
531 #define XMTPSIZE_MASK 0xF0
532 #define XMTPSIZE_SINGLE 0x10
533 #define XMTPSIZE_REPEATED 0x20
534 #define XMTPSIZE_CONT 0x20
535 #define XMTPSIZE_TRIPLE 0x30
536 #define XMTPSIZE_REDUNDANT 0x60
537 #define XMTPSIZE_INF 0
539 #define XMTCONTEN 0x04
540 #define XMTPFRM 0x02 /* Transmit at the next frame boundary */
541 #define XMTPIMM 0x01 /* Transmit immediately */
544 u8 prim
[4]; /* K, D0, D1, D2 */
548 } __attribute__ ((packed
));
550 /* This describes both SSP Target Get Data and SSP Target Get Data And
551 * Send Good Response SCBs. Used when the sequencer is operating in
554 struct ssp_targ_get_data
{
556 __le32 total_xfer_len
;
557 struct ssp_frame_hdr ssp_frame
;
558 struct xfer_rdy_iu xfer_rdy
;
563 u8 data_dir
; /* 01b */
567 struct sg_el sg_element
[3];
568 } __attribute__ ((packed
));
570 /* ---------- The actual SCB struct ---------- */
573 struct scb_header header
;
575 struct initiate_ssp_task ssp_task
;
576 struct initiate_ata_task ata_task
;
577 struct initiate_smp_task smp_task
;
578 struct control_phy control_phy
;
579 struct control_ata_dev control_ata_dev
;
580 struct empty_scb escb
;
581 struct initiate_link_adm link_adm
;
582 struct copy_memory cp_mem
;
583 struct abort_task abort_task
;
584 struct clear_nexus clear_nexus
;
585 struct initiate_ssp_tmf ssp_tmf
;
587 } __attribute__ ((packed
));
589 /* ---------- Done List ---------- */
590 /* The done list entry opcode field is defined below.
591 * The mnemonic encoding and meaning is as follows:
592 * TC - Task Complete, status was received and acknowledged
593 * TF - Task Failed, indicates an error prior to receiving acknowledgment
596 * - NACK or R_ERR received in response to this command,
597 * - credit blocked or not available, or in the case of SMP request,
598 * - no SMP response was received.
599 * In these four cases it is known that the target didn't receive the
601 * TI - Task Interrupted, error after the command was acknowledged. It is
602 * known that the command was received by the target.
603 * TU - Task Unacked, command was transmitted but neither ACK (R_OK) nor NAK
604 * (R_ERR) was received due to loss of signal, broken connection, loss of
605 * dword sync or other reason. The application client should send the
606 * appropriate task query.
607 * TA - Task Aborted, see TF.
608 * _RESP - The completion includes an empty buffer containing status.
611 #define TC_NO_ERROR 0x00
612 #define TC_UNDERRUN 0x01
613 #define TC_OVERRUN 0x02
614 #define TF_OPEN_TO 0x03
615 #define TF_OPEN_REJECT 0x04
616 #define TI_BREAK 0x05
617 #define TI_PROTO_ERR 0x06
618 #define TC_SSP_RESP 0x07
619 #define TI_PHY_DOWN 0x08
620 #define TF_PHY_DOWN 0x09
621 #define TC_LINK_ADM_RESP 0x0a
623 #define TC_ATA_RESP 0x0c
624 #define TU_PHY_DOWN 0x0d
625 #define TU_BREAK 0x0e
626 #define TI_SATA_TO 0x0f
628 #define TC_CONTROL_PHY 0x11
629 #define TF_BREAK 0x12
630 #define TC_RESUME 0x13
631 #define TI_ACK_NAK_TO 0x14
632 #define TF_SMPRSP_TO 0x15
633 #define TF_SMP_XMIT_RCV_ERR 0x16
634 #define TC_PARTIAL_SG_LIST 0x17
635 #define TU_ACK_NAK_TO 0x18
636 #define TU_SATA_TO 0x19
637 #define TF_NAK_RECV 0x1a
638 #define TA_I_T_NEXUS_LOSS 0x1b
639 #define TC_ATA_R_ERR_RECV 0x1c
640 #define TF_TMF_NO_CTX 0x1d
641 #define TA_ON_REQ 0x1e
642 #define TF_TMF_NO_TAG 0x1f
643 #define TF_TMF_TAG_FREE 0x20
644 #define TF_TMF_TASK_DONE 0x21
645 #define TF_TMF_NO_CONN_HANDLE 0x22
646 #define TC_TASK_CLEARED 0x23
647 #define TI_SYNCS_RECV 0x24
648 #define TU_SYNCS_RECV 0x25
649 #define TF_IRTT_TO 0x26
650 #define TF_NO_SMP_CONN 0x27
651 #define TF_IU_SHORT 0x28
652 #define TF_DATA_OFFS_ERR 0x29
653 #define TF_INV_CONN_HANDLE 0x2a
654 #define TF_REQUESTED_N_PENDING 0x2b
656 /* 0xc1 - 0xc7: empty buffer received,
657 0xd1 - 0xd7: establish nexus empty buffer received
659 /* This is the ESCB mask */
660 #define ESCB_RECVD 0xC0
663 /* This struct done_list_struct defines the done list entry.
666 struct done_list_struct
{
667 __le16 index
; /* aka transaction context */
670 u8 toggle
; /* bit 0 */
671 #define DL_TOGGLE_MASK 0x01
672 } __attribute__ ((packed
));
674 /* ---------- PHYS ---------- */
677 struct asd_sas_phy sas_phy
;
678 struct asd_phy_desc
*phy_desc
; /* hw profile */
680 struct sas_identify_frame
*identify_frame
;
681 struct asd_dma_tok
*id_frm_tok
;
682 struct asd_port
*asd_port
;
684 u8 frame_rcvd
[ASD_EDB_SIZE
];
688 #define ASD_SCB_SIZE sizeof(struct scb)
689 #define ASD_DDB_SIZE sizeof(struct asd_ddb_ssp_smp_target_port)
691 /* Define this to 0 if you do not want NOTIFY (ENABLE SPINIP) sent.
692 * Default: 0x10 (it's a mask)
694 #define ASD_NOTIFY_ENABLE_SPINUP 0x10
696 /* If enabled, set this to the interval between transmission
697 * of NOTIFY (ENABLE SPINUP). In units of 200 us.
699 #define ASD_NOTIFY_TIMEOUT 2500
701 /* Initial delay after OOB, before we transmit NOTIFY (ENABLE SPINUP).
702 * If 0, transmit immediately. In milliseconds.
704 #define ASD_NOTIFY_DOWN_COUNT 0
706 /* Device present timer timeout constant, 10 ms. */
707 #define ASD_DEV_PRESENT_TIMEOUT 0x2710
709 #define ASD_SATA_INTERLOCK_TIMEOUT 0
711 /* How long to wait before shutting down an STP connection, unless
712 * an STP target sent frame(s). 50 usec.
713 * IGNORED by the sequencer (i.e. value 0 always).
715 #define ASD_STP_SHUTDOWN_TIMEOUT 0x0
717 /* ATA soft reset timer timeout. 5 usec. */
718 #define ASD_SRST_ASSERT_TIMEOUT 0x05
721 #define ASD_RCV_FIS_TIMEOUT 0x01D905C0
723 #define ASD_ONE_MILLISEC_TIMEOUT 0x03e8
726 #define ASD_TEN_MILLISEC_TIMEOUT 0x2710
727 #define ASD_COMINIT_TIMEOUT ASD_TEN_MILLISEC_TIMEOUT
730 #define ASD_SMP_RCV_TIMEOUT 0x000F4240