1 // SPDX-License-Identifier: GPL-2.0-only
3 * Aic94xx SAS/SATA driver SCB management.
5 * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
6 * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
10 #include <scsi/scsi_host.h>
13 #include "aic94xx_reg.h"
14 #include "aic94xx_hwi.h"
15 #include "aic94xx_seq.h"
17 #include "aic94xx_dump.h"
19 /* ---------- EMPTY SCB ---------- */
23 #define PRIMITIVE_RECVD 0x08
24 #define PHY_EVENT 0x10
25 #define LINK_RESET_ERROR 0x18
26 #define TIMER_EVENT 0x20
27 #define REQ_TASK_ABORT 0xF0
28 #define REQ_DEVICE_RESET 0xF1
29 #define SIGNAL_NCQ_ERROR 0xF2
30 #define CLEAR_NCQ_ERROR 0xF3
32 #define PHY_EVENTS_STATUS (CURRENT_LOSS_OF_SIGNAL | CURRENT_OOB_DONE \
33 | CURRENT_SPINUP_HOLD | CURRENT_GTO_TIMEOUT \
36 static void get_lrate_mode(struct asd_phy
*phy
, u8 oob_mode
)
38 struct sas_phy
*sas_phy
= phy
->sas_phy
.phy
;
40 switch (oob_mode
& 7) {
42 /* FIXME: sas transport class doesn't have this */
43 phy
->sas_phy
.linkrate
= SAS_LINK_RATE_6_0_GBPS
;
44 phy
->sas_phy
.phy
->negotiated_linkrate
= SAS_LINK_RATE_6_0_GBPS
;
47 phy
->sas_phy
.linkrate
= SAS_LINK_RATE_3_0_GBPS
;
48 phy
->sas_phy
.phy
->negotiated_linkrate
= SAS_LINK_RATE_3_0_GBPS
;
51 phy
->sas_phy
.linkrate
= SAS_LINK_RATE_1_5_GBPS
;
52 phy
->sas_phy
.phy
->negotiated_linkrate
= SAS_LINK_RATE_1_5_GBPS
;
55 sas_phy
->negotiated_linkrate
= phy
->sas_phy
.linkrate
;
56 sas_phy
->maximum_linkrate_hw
= SAS_LINK_RATE_3_0_GBPS
;
57 sas_phy
->minimum_linkrate_hw
= SAS_LINK_RATE_1_5_GBPS
;
58 sas_phy
->maximum_linkrate
= phy
->phy_desc
->max_sas_lrate
;
59 sas_phy
->minimum_linkrate
= phy
->phy_desc
->min_sas_lrate
;
61 if (oob_mode
& SAS_MODE
)
62 phy
->sas_phy
.oob_mode
= SAS_OOB_MODE
;
63 else if (oob_mode
& SATA_MODE
)
64 phy
->sas_phy
.oob_mode
= SATA_OOB_MODE
;
67 static void asd_phy_event_tasklet(struct asd_ascb
*ascb
,
68 struct done_list_struct
*dl
)
70 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
71 struct sas_ha_struct
*sas_ha
= &asd_ha
->sas_ha
;
72 int phy_id
= dl
->status_block
[0] & DL_PHY_MASK
;
73 struct asd_phy
*phy
= &asd_ha
->phys
[phy_id
];
75 u8 oob_status
= dl
->status_block
[1] & PHY_EVENTS_STATUS
;
76 u8 oob_mode
= dl
->status_block
[2];
79 case CURRENT_LOSS_OF_SIGNAL
:
80 /* directly attached device was removed */
81 ASD_DPRINTK("phy%d: device unplugged\n", phy_id
);
82 asd_turn_led(asd_ha
, phy_id
, 0);
83 sas_phy_disconnected(&phy
->sas_phy
);
84 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_LOSS_OF_SIGNAL
);
86 case CURRENT_OOB_DONE
:
87 /* hot plugged device */
88 asd_turn_led(asd_ha
, phy_id
, 1);
89 get_lrate_mode(phy
, oob_mode
);
90 ASD_DPRINTK("phy%d device plugged: lrate:0x%x, proto:0x%x\n",
91 phy_id
, phy
->sas_phy
.linkrate
, phy
->sas_phy
.iproto
);
92 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_OOB_DONE
);
94 case CURRENT_SPINUP_HOLD
:
95 /* hot plug SATA, no COMWAKE sent */
96 asd_turn_led(asd_ha
, phy_id
, 1);
97 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_SPINUP_HOLD
);
99 case CURRENT_GTO_TIMEOUT
:
100 case CURRENT_OOB_ERROR
:
101 ASD_DPRINTK("phy%d error while OOB: oob status:0x%x\n", phy_id
,
102 dl
->status_block
[1]);
103 asd_turn_led(asd_ha
, phy_id
, 0);
104 sas_phy_disconnected(&phy
->sas_phy
);
105 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_OOB_ERROR
);
110 /* If phys are enabled sparsely, this will do the right thing. */
111 static unsigned ord_phy(struct asd_ha_struct
*asd_ha
, struct asd_phy
*phy
)
113 u8 enabled_mask
= asd_ha
->hw_prof
.enabled_phys
;
116 for_each_phy(enabled_mask
, enabled_mask
, i
) {
117 if (&asd_ha
->phys
[i
] == phy
)
125 * asd_get_attached_sas_addr -- extract/generate attached SAS address
126 * phy: pointer to asd_phy
127 * sas_addr: pointer to buffer where the SAS address is to be written
129 * This function extracts the SAS address from an IDENTIFY frame
130 * received. If OOB is SATA, then a SAS address is generated from the
133 * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame
136 static void asd_get_attached_sas_addr(struct asd_phy
*phy
, u8
*sas_addr
)
138 if (phy
->sas_phy
.frame_rcvd
[0] == 0x34
139 && phy
->sas_phy
.oob_mode
== SATA_OOB_MODE
) {
140 struct asd_ha_struct
*asd_ha
= phy
->sas_phy
.ha
->lldd_ha
;
141 /* FIS device-to-host */
142 u64 addr
= be64_to_cpu(*(__be64
*)phy
->phy_desc
->sas_addr
);
144 addr
+= asd_ha
->hw_prof
.sata_name_base
+ ord_phy(asd_ha
, phy
);
145 *(__be64
*)sas_addr
= cpu_to_be64(addr
);
147 struct sas_identify_frame
*idframe
=
148 (void *) phy
->sas_phy
.frame_rcvd
;
149 memcpy(sas_addr
, idframe
->sas_addr
, SAS_ADDR_SIZE
);
153 static void asd_form_port(struct asd_ha_struct
*asd_ha
, struct asd_phy
*phy
)
156 struct asd_port
*free_port
= NULL
;
157 struct asd_port
*port
;
158 struct asd_sas_phy
*sas_phy
= &phy
->sas_phy
;
161 spin_lock_irqsave(&asd_ha
->asd_ports_lock
, flags
);
162 if (!phy
->asd_port
) {
163 for (i
= 0; i
< ASD_MAX_PHYS
; i
++) {
164 port
= &asd_ha
->asd_ports
[i
];
166 /* Check for wide port */
167 if (port
->num_phys
> 0 &&
168 memcmp(port
->sas_addr
, sas_phy
->sas_addr
,
169 SAS_ADDR_SIZE
) == 0 &&
170 memcmp(port
->attached_sas_addr
,
171 sas_phy
->attached_sas_addr
,
172 SAS_ADDR_SIZE
) == 0) {
176 /* Find a free port */
177 if (port
->num_phys
== 0 && free_port
== NULL
) {
182 /* Use a free port if this doesn't form a wide port */
183 if (i
>= ASD_MAX_PHYS
) {
186 memcpy(port
->sas_addr
, sas_phy
->sas_addr
,
188 memcpy(port
->attached_sas_addr
,
189 sas_phy
->attached_sas_addr
,
193 port
->phy_mask
|= (1U << sas_phy
->id
);
194 phy
->asd_port
= port
;
196 ASD_DPRINTK("%s: updating phy_mask 0x%x for phy%d\n",
197 __func__
, phy
->asd_port
->phy_mask
, sas_phy
->id
);
198 asd_update_port_links(asd_ha
, phy
);
199 spin_unlock_irqrestore(&asd_ha
->asd_ports_lock
, flags
);
202 static void asd_deform_port(struct asd_ha_struct
*asd_ha
, struct asd_phy
*phy
)
204 struct asd_port
*port
= phy
->asd_port
;
205 struct asd_sas_phy
*sas_phy
= &phy
->sas_phy
;
208 spin_lock_irqsave(&asd_ha
->asd_ports_lock
, flags
);
211 port
->phy_mask
&= ~(1U << sas_phy
->id
);
212 phy
->asd_port
= NULL
;
214 spin_unlock_irqrestore(&asd_ha
->asd_ports_lock
, flags
);
217 static void asd_bytes_dmaed_tasklet(struct asd_ascb
*ascb
,
218 struct done_list_struct
*dl
,
219 int edb_id
, int phy_id
)
222 int edb_el
= edb_id
+ ascb
->edb_index
;
223 struct asd_dma_tok
*edb
= ascb
->ha
->seq
.edb_arr
[edb_el
];
224 struct asd_phy
*phy
= &ascb
->ha
->phys
[phy_id
];
225 struct sas_ha_struct
*sas_ha
= phy
->sas_phy
.ha
;
226 u16 size
= ((dl
->status_block
[3] & 7) << 8) | dl
->status_block
[2];
228 size
= min(size
, (u16
) sizeof(phy
->frame_rcvd
));
230 spin_lock_irqsave(&phy
->sas_phy
.frame_rcvd_lock
, flags
);
231 memcpy(phy
->sas_phy
.frame_rcvd
, edb
->vaddr
, size
);
232 phy
->sas_phy
.frame_rcvd_size
= size
;
233 asd_get_attached_sas_addr(phy
, phy
->sas_phy
.attached_sas_addr
);
234 spin_unlock_irqrestore(&phy
->sas_phy
.frame_rcvd_lock
, flags
);
235 asd_dump_frame_rcvd(phy
, dl
);
236 asd_form_port(ascb
->ha
, phy
);
237 sas_ha
->notify_port_event(&phy
->sas_phy
, PORTE_BYTES_DMAED
);
240 static void asd_link_reset_err_tasklet(struct asd_ascb
*ascb
,
241 struct done_list_struct
*dl
,
244 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
245 struct sas_ha_struct
*sas_ha
= &asd_ha
->sas_ha
;
246 struct asd_sas_phy
*sas_phy
= sas_ha
->sas_phy
[phy_id
];
247 struct asd_phy
*phy
= &asd_ha
->phys
[phy_id
];
248 u8 lr_error
= dl
->status_block
[1];
249 u8 retries_left
= dl
->status_block
[2];
253 ASD_DPRINTK("phy%d: Receive ID timer expired\n", phy_id
);
256 ASD_DPRINTK("phy%d: Loss of signal\n", phy_id
);
259 ASD_DPRINTK("phy%d: Loss of dword sync\n", phy_id
);
262 ASD_DPRINTK("phy%d: Receive FIS timeout\n", phy_id
);
265 ASD_DPRINTK("phy%d: unknown link reset error code: 0x%x\n",
270 asd_turn_led(asd_ha
, phy_id
, 0);
271 sas_phy_disconnected(sas_phy
);
272 asd_deform_port(asd_ha
, phy
);
273 sas_ha
->notify_port_event(sas_phy
, PORTE_LINK_RESET_ERR
);
275 if (retries_left
== 0) {
277 struct asd_ascb
*cp
= asd_ascb_alloc_list(ascb
->ha
, &num
,
280 asd_printk("%s: out of memory\n", __func__
);
283 ASD_DPRINTK("phy%d: retries:0 performing link reset seq\n",
285 asd_build_control_phy(cp
, phy_id
, ENABLE_PHY
);
286 if (asd_post_ascb_list(ascb
->ha
, cp
, 1) != 0)
293 static void asd_primitive_rcvd_tasklet(struct asd_ascb
*ascb
,
294 struct done_list_struct
*dl
,
298 struct sas_ha_struct
*sas_ha
= &ascb
->ha
->sas_ha
;
299 struct asd_sas_phy
*sas_phy
= sas_ha
->sas_phy
[phy_id
];
300 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
301 struct asd_phy
*phy
= &asd_ha
->phys
[phy_id
];
302 u8 reg
= dl
->status_block
[1];
303 u32 cont
= dl
->status_block
[2] << ((reg
& 3)*8);
307 case LmPRMSTAT0BYTE0
:
313 ASD_DPRINTK("phy%d: BROADCAST change received:%d\n",
315 spin_lock_irqsave(&sas_phy
->sas_prim_lock
, flags
);
316 sas_phy
->sas_prim
= ffs(cont
);
317 spin_unlock_irqrestore(&sas_phy
->sas_prim_lock
, flags
);
318 sas_ha
->notify_port_event(sas_phy
,PORTE_BROADCAST_RCVD
);
322 ASD_DPRINTK("phy%d: unknown BREAK\n", phy_id
);
326 ASD_DPRINTK("phy%d: primitive reg:0x%x, cont:0x%04x\n",
331 case LmPRMSTAT1BYTE0
:
334 ASD_DPRINTK("phy%d: HARD_RESET primitive rcvd\n",
336 /* The sequencer disables all phys on that port.
337 * We have to re-enable the phys ourselves. */
338 asd_deform_port(asd_ha
, phy
);
339 sas_ha
->notify_port_event(sas_phy
, PORTE_HARD_RESET
);
343 ASD_DPRINTK("phy%d: primitive reg:0x%x, cont:0x%04x\n",
349 ASD_DPRINTK("unknown primitive register:0x%x\n",
350 dl
->status_block
[1]);
356 * asd_invalidate_edb -- invalidate an EDB and if necessary post the ESCB
357 * @ascb: pointer to Empty SCB
358 * @edb_id: index [0,6] to the empty data buffer which is to be invalidated
360 * After an EDB has been invalidated, if all EDBs in this ESCB have been
361 * invalidated, the ESCB is posted back to the sequencer.
362 * Context is tasklet/IRQ.
364 void asd_invalidate_edb(struct asd_ascb
*ascb
, int edb_id
)
366 struct asd_seq_data
*seq
= &ascb
->ha
->seq
;
367 struct empty_scb
*escb
= &ascb
->scb
->escb
;
368 struct sg_el
*eb
= &escb
->eb
[edb_id
];
369 struct asd_dma_tok
*edb
= seq
->edb_arr
[ascb
->edb_index
+ edb_id
];
371 memset(edb
->vaddr
, 0, ASD_EDB_SIZE
);
372 eb
->flags
|= ELEMENT_NOT_VALID
;
375 if (escb
->num_valid
== 0) {
377 /* ASD_DPRINTK("reposting escb: vaddr: 0x%p, "
378 "dma_handle: 0x%08llx, next: 0x%08llx, "
379 "index:%d, opcode:0x%02x\n",
381 (u64)ascb->dma_scb.dma_handle,
382 le64_to_cpu(ascb->scb->header.next_scb),
383 le16_to_cpu(ascb->scb->header.index),
384 ascb->scb->header.opcode);
386 escb
->num_valid
= ASD_EDBS_PER_SCB
;
387 for (i
= 0; i
< ASD_EDBS_PER_SCB
; i
++)
388 escb
->eb
[i
].flags
= 0;
389 if (!list_empty(&ascb
->list
))
390 list_del_init(&ascb
->list
);
391 i
= asd_post_escb_list(ascb
->ha
, ascb
, 1);
393 asd_printk("couldn't post escb, err:%d\n", i
);
397 static void escb_tasklet_complete(struct asd_ascb
*ascb
,
398 struct done_list_struct
*dl
)
400 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
401 struct sas_ha_struct
*sas_ha
= &asd_ha
->sas_ha
;
402 int edb
= (dl
->opcode
& DL_PHY_MASK
) - 1; /* [0xc1,0xc7] -> [0,6] */
403 u8 sb_opcode
= dl
->status_block
[0];
404 int phy_id
= sb_opcode
& DL_PHY_MASK
;
405 struct asd_sas_phy
*sas_phy
= sas_ha
->sas_phy
[phy_id
];
406 struct asd_phy
*phy
= &asd_ha
->phys
[phy_id
];
408 if (edb
> 6 || edb
< 0) {
409 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n",
411 ASD_DPRINTK("sb_opcode : 0x%x, phy_id: 0x%x\n",
413 ASD_DPRINTK("escb: vaddr: 0x%p, "
414 "dma_handle: 0x%llx, next: 0x%llx, "
415 "index:%d, opcode:0x%02x\n",
417 (unsigned long long)ascb
->dma_scb
.dma_handle
,
419 le64_to_cpu(ascb
->scb
->header
.next_scb
),
420 le16_to_cpu(ascb
->scb
->header
.index
),
421 ascb
->scb
->header
.opcode
);
424 /* Catch these before we mask off the sb_opcode bits */
426 case REQ_TASK_ABORT
: {
427 struct asd_ascb
*a
, *b
;
429 struct domain_device
*failed_dev
= NULL
;
431 ASD_DPRINTK("%s: REQ_TASK_ABORT, reason=0x%X\n",
432 __func__
, dl
->status_block
[3]);
435 * Find the task that caused the abort and abort it first.
436 * The sequencer won't put anything on the done list until
439 tc_abort
= *((u16
*)(&dl
->status_block
[1]));
440 tc_abort
= le16_to_cpu(tc_abort
);
442 list_for_each_entry_safe(a
, b
, &asd_ha
->seq
.pend_q
, list
) {
443 struct sas_task
*task
= a
->uldd_task
;
445 if (a
->tc_index
!= tc_abort
)
449 failed_dev
= task
->dev
;
450 sas_task_abort(task
);
452 ASD_DPRINTK("R_T_A for non TASK scb 0x%x\n",
453 a
->scb
->header
.opcode
);
459 ASD_DPRINTK("%s: Can't find task (tc=%d) to abort!\n",
465 * Now abort everything else for that device (hba?) so
466 * that the EH will wake up and do something.
468 list_for_each_entry_safe(a
, b
, &asd_ha
->seq
.pend_q
, list
) {
469 struct sas_task
*task
= a
->uldd_task
;
472 task
->dev
== failed_dev
&&
473 a
->tc_index
!= tc_abort
)
474 sas_task_abort(task
);
479 case REQ_DEVICE_RESET
: {
483 struct sas_task
*last_dev_task
= NULL
;
485 conn_handle
= *((u16
*)(&dl
->status_block
[1]));
486 conn_handle
= le16_to_cpu(conn_handle
);
488 ASD_DPRINTK("%s: REQ_DEVICE_RESET, reason=0x%X\n", __func__
,
489 dl
->status_block
[3]);
491 /* Find the last pending task for the device... */
492 list_for_each_entry(a
, &asd_ha
->seq
.pend_q
, list
) {
494 struct domain_device
*dev
;
495 struct sas_task
*task
= a
->uldd_task
;
501 x
= (unsigned long)dev
->lldd_dev
;
502 if (x
== conn_handle
)
503 last_dev_task
= task
;
506 if (!last_dev_task
) {
507 ASD_DPRINTK("%s: Device reset for idle device %d?\n",
508 __func__
, conn_handle
);
512 /* ...and set the reset flag */
513 spin_lock_irqsave(&last_dev_task
->task_state_lock
, flags
);
514 last_dev_task
->task_state_flags
|= SAS_TASK_NEED_DEV_RESET
;
515 spin_unlock_irqrestore(&last_dev_task
->task_state_lock
, flags
);
517 /* Kill all pending tasks for the device */
518 list_for_each_entry(a
, &asd_ha
->seq
.pend_q
, list
) {
520 struct domain_device
*dev
;
521 struct sas_task
*task
= a
->uldd_task
;
527 x
= (unsigned long)dev
->lldd_dev
;
528 if (x
== conn_handle
)
529 sas_task_abort(task
);
534 case SIGNAL_NCQ_ERROR
:
535 ASD_DPRINTK("%s: SIGNAL_NCQ_ERROR\n", __func__
);
537 case CLEAR_NCQ_ERROR
:
538 ASD_DPRINTK("%s: CLEAR_NCQ_ERROR\n", __func__
);
542 sb_opcode
&= ~DL_PHY_MASK
;
546 ASD_DPRINTK("%s: phy%d: BYTES_DMAED\n", __func__
, phy_id
);
547 asd_bytes_dmaed_tasklet(ascb
, dl
, edb
, phy_id
);
549 case PRIMITIVE_RECVD
:
550 ASD_DPRINTK("%s: phy%d: PRIMITIVE_RECVD\n", __func__
,
552 asd_primitive_rcvd_tasklet(ascb
, dl
, phy_id
);
555 ASD_DPRINTK("%s: phy%d: PHY_EVENT\n", __func__
, phy_id
);
556 asd_phy_event_tasklet(ascb
, dl
);
558 case LINK_RESET_ERROR
:
559 ASD_DPRINTK("%s: phy%d: LINK_RESET_ERROR\n", __func__
,
561 asd_link_reset_err_tasklet(ascb
, dl
, phy_id
);
564 ASD_DPRINTK("%s: phy%d: TIMER_EVENT, lost dw sync\n",
566 asd_turn_led(asd_ha
, phy_id
, 0);
567 /* the device is gone */
568 sas_phy_disconnected(sas_phy
);
569 asd_deform_port(asd_ha
, phy
);
570 sas_ha
->notify_port_event(sas_phy
, PORTE_TIMER_EVENT
);
573 ASD_DPRINTK("%s: phy%d: unknown event:0x%x\n", __func__
,
575 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n",
577 ASD_DPRINTK("sb_opcode : 0x%x, phy_id: 0x%x\n",
579 ASD_DPRINTK("escb: vaddr: 0x%p, "
580 "dma_handle: 0x%llx, next: 0x%llx, "
581 "index:%d, opcode:0x%02x\n",
583 (unsigned long long)ascb
->dma_scb
.dma_handle
,
585 le64_to_cpu(ascb
->scb
->header
.next_scb
),
586 le16_to_cpu(ascb
->scb
->header
.index
),
587 ascb
->scb
->header
.opcode
);
592 asd_invalidate_edb(ascb
, edb
);
595 int asd_init_post_escbs(struct asd_ha_struct
*asd_ha
)
597 struct asd_seq_data
*seq
= &asd_ha
->seq
;
600 for (i
= 0; i
< seq
->num_escbs
; i
++)
601 seq
->escb_arr
[i
]->tasklet_complete
= escb_tasklet_complete
;
603 ASD_DPRINTK("posting %d escbs\n", i
);
604 return asd_post_escb_list(asd_ha
, seq
->escb_arr
[0], seq
->num_escbs
);
607 /* ---------- CONTROL PHY ---------- */
609 #define CONTROL_PHY_STATUS (CURRENT_DEVICE_PRESENT | CURRENT_OOB_DONE \
610 | CURRENT_SPINUP_HOLD | CURRENT_GTO_TIMEOUT \
614 * control_phy_tasklet_complete -- tasklet complete for CONTROL PHY ascb
615 * @ascb: pointer to an ascb
616 * @dl: pointer to the done list entry
618 * This function completes a CONTROL PHY scb and frees the ascb.
620 * - an LED blinks if there is IO though it,
621 * - if a device is connected to the LED, it is lit,
622 * - if no device is connected to the LED, is is dimmed (off).
624 static void control_phy_tasklet_complete(struct asd_ascb
*ascb
,
625 struct done_list_struct
*dl
)
627 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
628 struct scb
*scb
= ascb
->scb
;
629 struct control_phy
*control_phy
= &scb
->control_phy
;
630 u8 phy_id
= control_phy
->phy_id
;
631 struct asd_phy
*phy
= &ascb
->ha
->phys
[phy_id
];
633 u8 status
= dl
->status_block
[0];
634 u8 oob_status
= dl
->status_block
[1];
635 u8 oob_mode
= dl
->status_block
[2];
636 /* u8 oob_signals= dl->status_block[3]; */
639 ASD_DPRINTK("%s: phy%d status block opcode:0x%x\n",
640 __func__
, phy_id
, status
);
644 switch (control_phy
->sub_func
) {
646 asd_ha
->hw_prof
.enabled_phys
&= ~(1 << phy_id
);
647 asd_turn_led(asd_ha
, phy_id
, 0);
648 asd_control_led(asd_ha
, phy_id
, 0);
649 ASD_DPRINTK("%s: disable phy%d\n", __func__
, phy_id
);
653 asd_control_led(asd_ha
, phy_id
, 1);
654 if (oob_status
& CURRENT_OOB_DONE
) {
655 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
656 get_lrate_mode(phy
, oob_mode
);
657 asd_turn_led(asd_ha
, phy_id
, 1);
658 ASD_DPRINTK("%s: phy%d, lrate:0x%x, proto:0x%x\n",
659 __func__
, phy_id
,phy
->sas_phy
.linkrate
,
660 phy
->sas_phy
.iproto
);
661 } else if (oob_status
& CURRENT_SPINUP_HOLD
) {
662 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
663 asd_turn_led(asd_ha
, phy_id
, 1);
664 ASD_DPRINTK("%s: phy%d, spinup hold\n", __func__
,
666 } else if (oob_status
& CURRENT_ERR_MASK
) {
667 asd_turn_led(asd_ha
, phy_id
, 0);
668 ASD_DPRINTK("%s: phy%d: error: oob status:0x%02x\n",
669 __func__
, phy_id
, oob_status
);
670 } else if (oob_status
& (CURRENT_HOT_PLUG_CNCT
671 | CURRENT_DEVICE_PRESENT
)) {
672 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
673 asd_turn_led(asd_ha
, phy_id
, 1);
674 ASD_DPRINTK("%s: phy%d: hot plug or device present\n",
677 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
678 asd_turn_led(asd_ha
, phy_id
, 0);
679 ASD_DPRINTK("%s: phy%d: no device present: "
681 __func__
, phy_id
, oob_status
);
684 case RELEASE_SPINUP_HOLD
:
686 case EXECUTE_HARD_RESET
:
687 ASD_DPRINTK("%s: phy%d: sub_func:0x%x\n", __func__
,
688 phy_id
, control_phy
->sub_func
);
692 ASD_DPRINTK("%s: phy%d: sub_func:0x%x?\n", __func__
,
693 phy_id
, control_phy
->sub_func
);
700 static void set_speed_mask(u8
*speed_mask
, struct asd_phy_desc
*pd
)
702 /* disable all speeds, then enable defaults */
703 *speed_mask
= SAS_SPEED_60_DIS
| SAS_SPEED_30_DIS
| SAS_SPEED_15_DIS
704 | SATA_SPEED_30_DIS
| SATA_SPEED_15_DIS
;
706 switch (pd
->max_sas_lrate
) {
707 case SAS_LINK_RATE_6_0_GBPS
:
708 *speed_mask
&= ~SAS_SPEED_60_DIS
;
711 case SAS_LINK_RATE_3_0_GBPS
:
712 *speed_mask
&= ~SAS_SPEED_30_DIS
;
714 case SAS_LINK_RATE_1_5_GBPS
:
715 *speed_mask
&= ~SAS_SPEED_15_DIS
;
718 switch (pd
->min_sas_lrate
) {
719 case SAS_LINK_RATE_6_0_GBPS
:
720 *speed_mask
|= SAS_SPEED_30_DIS
;
722 case SAS_LINK_RATE_3_0_GBPS
:
723 *speed_mask
|= SAS_SPEED_15_DIS
;
725 case SAS_LINK_RATE_1_5_GBPS
:
730 switch (pd
->max_sata_lrate
) {
731 case SAS_LINK_RATE_3_0_GBPS
:
732 *speed_mask
&= ~SATA_SPEED_30_DIS
;
735 case SAS_LINK_RATE_1_5_GBPS
:
736 *speed_mask
&= ~SATA_SPEED_15_DIS
;
739 switch (pd
->min_sata_lrate
) {
740 case SAS_LINK_RATE_3_0_GBPS
:
741 *speed_mask
|= SATA_SPEED_15_DIS
;
743 case SAS_LINK_RATE_1_5_GBPS
:
750 * asd_build_control_phy -- build a CONTROL PHY SCB
751 * @ascb: pointer to an ascb
752 * @phy_id: phy id to control, integer
753 * @subfunc: subfunction, what to actually to do the phy
755 * This function builds a CONTROL PHY scb. No allocation of any kind
756 * is performed. @ascb is allocated with the list function.
757 * The caller can override the ascb->tasklet_complete to point
758 * to its own callback function. It must call asd_ascb_free()
759 * at its tasklet complete function.
760 * See the default implementation.
762 void asd_build_control_phy(struct asd_ascb
*ascb
, int phy_id
, u8 subfunc
)
764 struct asd_phy
*phy
= &ascb
->ha
->phys
[phy_id
];
765 struct scb
*scb
= ascb
->scb
;
766 struct control_phy
*control_phy
= &scb
->control_phy
;
768 scb
->header
.opcode
= CONTROL_PHY
;
769 control_phy
->phy_id
= (u8
) phy_id
;
770 control_phy
->sub_func
= subfunc
;
773 case EXECUTE_HARD_RESET
: /* 0x81 */
774 case ENABLE_PHY
: /* 0x01 */
775 /* decide hot plug delay */
776 control_phy
->hot_plug_delay
= HOTPLUG_DELAY_TIMEOUT
;
778 /* decide speed mask */
779 set_speed_mask(&control_phy
->speed_mask
, phy
->phy_desc
);
781 /* initiator port settings are in the hi nibble */
782 if (phy
->sas_phy
.role
== PHY_ROLE_INITIATOR
)
783 control_phy
->port_type
= SAS_PROTOCOL_ALL
<< 4;
784 else if (phy
->sas_phy
.role
== PHY_ROLE_TARGET
)
785 control_phy
->port_type
= SAS_PROTOCOL_ALL
;
787 control_phy
->port_type
=
788 (SAS_PROTOCOL_ALL
<< 4) | SAS_PROTOCOL_ALL
;
790 /* link reset retries, this should be nominal */
791 control_phy
->link_reset_retries
= 10;
794 case RELEASE_SPINUP_HOLD
: /* 0x02 */
795 /* decide the func_mask */
796 control_phy
->func_mask
= FUNCTION_MASK_DEFAULT
;
797 if (phy
->phy_desc
->flags
& ASD_SATA_SPINUP_HOLD
)
798 control_phy
->func_mask
&= ~SPINUP_HOLD_DIS
;
800 control_phy
->func_mask
|= SPINUP_HOLD_DIS
;
803 control_phy
->conn_handle
= cpu_to_le16(0xFFFF);
805 ascb
->tasklet_complete
= control_phy_tasklet_complete
;
808 /* ---------- INITIATE LINK ADM TASK ---------- */
812 static void link_adm_tasklet_complete(struct asd_ascb
*ascb
,
813 struct done_list_struct
*dl
)
815 u8 opcode
= dl
->opcode
;
816 struct initiate_link_adm
*link_adm
= &ascb
->scb
->link_adm
;
817 u8 phy_id
= link_adm
->phy_id
;
819 if (opcode
!= TC_NO_ERROR
) {
820 asd_printk("phy%d: link adm task 0x%x completed with error "
821 "0x%x\n", phy_id
, link_adm
->sub_func
, opcode
);
823 ASD_DPRINTK("phy%d: link adm task 0x%x: 0x%x\n",
824 phy_id
, link_adm
->sub_func
, opcode
);
829 void asd_build_initiate_link_adm_task(struct asd_ascb
*ascb
, int phy_id
,
832 struct scb
*scb
= ascb
->scb
;
833 struct initiate_link_adm
*link_adm
= &scb
->link_adm
;
835 scb
->header
.opcode
= INITIATE_LINK_ADM_TASK
;
837 link_adm
->phy_id
= phy_id
;
838 link_adm
->sub_func
= subfunc
;
839 link_adm
->conn_handle
= cpu_to_le16(0xFFFF);
841 ascb
->tasklet_complete
= link_adm_tasklet_complete
;
846 /* ---------- SCB timer ---------- */
849 * asd_ascb_timedout -- called when a pending SCB's timer has expired
850 * @data: unsigned long, a pointer to the ascb in question
852 * This is the default timeout function which does the most necessary.
853 * Upper layers can implement their own timeout function, say to free
854 * resources they have with this SCB, and then call this one at the
855 * end of their timeout function. To do this, one should initialize
856 * the ascb->timer.{function, expires} prior to calling the post
857 * function. The timer is started by the post function.
859 void asd_ascb_timedout(struct timer_list
*t
)
861 struct asd_ascb
*ascb
= from_timer(ascb
, t
, timer
);
862 struct asd_seq_data
*seq
= &ascb
->ha
->seq
;
865 ASD_DPRINTK("scb:0x%x timed out\n", ascb
->scb
->header
.opcode
);
867 spin_lock_irqsave(&seq
->pend_q_lock
, flags
);
869 list_del_init(&ascb
->list
);
870 spin_unlock_irqrestore(&seq
->pend_q_lock
, flags
);
875 /* ---------- CONTROL PHY ---------- */
877 /* Given the spec value, return a driver value. */
878 static const int phy_func_table
[] = {
879 [PHY_FUNC_NOP
] = PHY_NO_OP
,
880 [PHY_FUNC_LINK_RESET
] = ENABLE_PHY
,
881 [PHY_FUNC_HARD_RESET
] = EXECUTE_HARD_RESET
,
882 [PHY_FUNC_DISABLE
] = DISABLE_PHY
,
883 [PHY_FUNC_RELEASE_SPINUP_HOLD
] = RELEASE_SPINUP_HOLD
,
886 int asd_control_phy(struct asd_sas_phy
*phy
, enum phy_func func
, void *arg
)
888 struct asd_ha_struct
*asd_ha
= phy
->ha
->lldd_ha
;
889 struct asd_phy_desc
*pd
= asd_ha
->phys
[phy
->id
].phy_desc
;
890 struct asd_ascb
*ascb
;
891 struct sas_phy_linkrates
*rates
;
895 case PHY_FUNC_CLEAR_ERROR_LOG
:
896 case PHY_FUNC_GET_EVENTS
:
898 case PHY_FUNC_SET_LINK_RATE
:
900 if (rates
->minimum_linkrate
) {
901 pd
->min_sas_lrate
= rates
->minimum_linkrate
;
902 pd
->min_sata_lrate
= rates
->minimum_linkrate
;
904 if (rates
->maximum_linkrate
) {
905 pd
->max_sas_lrate
= rates
->maximum_linkrate
;
906 pd
->max_sata_lrate
= rates
->maximum_linkrate
;
908 func
= PHY_FUNC_LINK_RESET
;
914 ascb
= asd_ascb_alloc_list(asd_ha
, &res
, GFP_KERNEL
);
918 asd_build_control_phy(ascb
, phy
->id
, phy_func_table
[func
]);
919 res
= asd_post_ascb_list(asd_ha
, ascb
, 1);