2 * Aic94xx SAS/SATA driver SCB management.
4 * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
5 * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
7 * This file is licensed under GPLv2.
9 * This file is part of the aic94xx driver.
11 * The aic94xx driver is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; version 2 of the
16 * The aic94xx driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with the aic94xx driver; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <linux/gfp.h>
28 #include <scsi/scsi_host.h>
31 #include "aic94xx_reg.h"
32 #include "aic94xx_hwi.h"
33 #include "aic94xx_seq.h"
35 #include "aic94xx_dump.h"
37 /* ---------- EMPTY SCB ---------- */
41 #define PRIMITIVE_RECVD 0x08
42 #define PHY_EVENT 0x10
43 #define LINK_RESET_ERROR 0x18
44 #define TIMER_EVENT 0x20
45 #define REQ_TASK_ABORT 0xF0
46 #define REQ_DEVICE_RESET 0xF1
47 #define SIGNAL_NCQ_ERROR 0xF2
48 #define CLEAR_NCQ_ERROR 0xF3
50 #define PHY_EVENTS_STATUS (CURRENT_LOSS_OF_SIGNAL | CURRENT_OOB_DONE \
51 | CURRENT_SPINUP_HOLD | CURRENT_GTO_TIMEOUT \
54 static void get_lrate_mode(struct asd_phy
*phy
, u8 oob_mode
)
56 struct sas_phy
*sas_phy
= phy
->sas_phy
.phy
;
58 switch (oob_mode
& 7) {
60 /* FIXME: sas transport class doesn't have this */
61 phy
->sas_phy
.linkrate
= SAS_LINK_RATE_6_0_GBPS
;
62 phy
->sas_phy
.phy
->negotiated_linkrate
= SAS_LINK_RATE_6_0_GBPS
;
65 phy
->sas_phy
.linkrate
= SAS_LINK_RATE_3_0_GBPS
;
66 phy
->sas_phy
.phy
->negotiated_linkrate
= SAS_LINK_RATE_3_0_GBPS
;
69 phy
->sas_phy
.linkrate
= SAS_LINK_RATE_1_5_GBPS
;
70 phy
->sas_phy
.phy
->negotiated_linkrate
= SAS_LINK_RATE_1_5_GBPS
;
73 sas_phy
->negotiated_linkrate
= phy
->sas_phy
.linkrate
;
74 sas_phy
->maximum_linkrate_hw
= SAS_LINK_RATE_3_0_GBPS
;
75 sas_phy
->minimum_linkrate_hw
= SAS_LINK_RATE_1_5_GBPS
;
76 sas_phy
->maximum_linkrate
= phy
->phy_desc
->max_sas_lrate
;
77 sas_phy
->minimum_linkrate
= phy
->phy_desc
->min_sas_lrate
;
79 if (oob_mode
& SAS_MODE
)
80 phy
->sas_phy
.oob_mode
= SAS_OOB_MODE
;
81 else if (oob_mode
& SATA_MODE
)
82 phy
->sas_phy
.oob_mode
= SATA_OOB_MODE
;
85 static void asd_phy_event_tasklet(struct asd_ascb
*ascb
,
86 struct done_list_struct
*dl
)
88 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
89 struct sas_ha_struct
*sas_ha
= &asd_ha
->sas_ha
;
90 int phy_id
= dl
->status_block
[0] & DL_PHY_MASK
;
91 struct asd_phy
*phy
= &asd_ha
->phys
[phy_id
];
93 u8 oob_status
= dl
->status_block
[1] & PHY_EVENTS_STATUS
;
94 u8 oob_mode
= dl
->status_block
[2];
97 case CURRENT_LOSS_OF_SIGNAL
:
98 /* directly attached device was removed */
99 ASD_DPRINTK("phy%d: device unplugged\n", phy_id
);
100 asd_turn_led(asd_ha
, phy_id
, 0);
101 sas_phy_disconnected(&phy
->sas_phy
);
102 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_LOSS_OF_SIGNAL
);
104 case CURRENT_OOB_DONE
:
105 /* hot plugged device */
106 asd_turn_led(asd_ha
, phy_id
, 1);
107 get_lrate_mode(phy
, oob_mode
);
108 ASD_DPRINTK("phy%d device plugged: lrate:0x%x, proto:0x%x\n",
109 phy_id
, phy
->sas_phy
.linkrate
, phy
->sas_phy
.iproto
);
110 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_OOB_DONE
);
112 case CURRENT_SPINUP_HOLD
:
113 /* hot plug SATA, no COMWAKE sent */
114 asd_turn_led(asd_ha
, phy_id
, 1);
115 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_SPINUP_HOLD
);
117 case CURRENT_GTO_TIMEOUT
:
118 case CURRENT_OOB_ERROR
:
119 ASD_DPRINTK("phy%d error while OOB: oob status:0x%x\n", phy_id
,
120 dl
->status_block
[1]);
121 asd_turn_led(asd_ha
, phy_id
, 0);
122 sas_phy_disconnected(&phy
->sas_phy
);
123 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_OOB_ERROR
);
128 /* If phys are enabled sparsely, this will do the right thing. */
129 static unsigned ord_phy(struct asd_ha_struct
*asd_ha
, struct asd_phy
*phy
)
131 u8 enabled_mask
= asd_ha
->hw_prof
.enabled_phys
;
134 for_each_phy(enabled_mask
, enabled_mask
, i
) {
135 if (&asd_ha
->phys
[i
] == phy
)
143 * asd_get_attached_sas_addr -- extract/generate attached SAS address
144 * phy: pointer to asd_phy
145 * sas_addr: pointer to buffer where the SAS address is to be written
147 * This function extracts the SAS address from an IDENTIFY frame
148 * received. If OOB is SATA, then a SAS address is generated from the
151 * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame
154 static void asd_get_attached_sas_addr(struct asd_phy
*phy
, u8
*sas_addr
)
156 if (phy
->sas_phy
.frame_rcvd
[0] == 0x34
157 && phy
->sas_phy
.oob_mode
== SATA_OOB_MODE
) {
158 struct asd_ha_struct
*asd_ha
= phy
->sas_phy
.ha
->lldd_ha
;
159 /* FIS device-to-host */
160 u64 addr
= be64_to_cpu(*(__be64
*)phy
->phy_desc
->sas_addr
);
162 addr
+= asd_ha
->hw_prof
.sata_name_base
+ ord_phy(asd_ha
, phy
);
163 *(__be64
*)sas_addr
= cpu_to_be64(addr
);
165 struct sas_identify_frame
*idframe
=
166 (void *) phy
->sas_phy
.frame_rcvd
;
167 memcpy(sas_addr
, idframe
->sas_addr
, SAS_ADDR_SIZE
);
171 static void asd_form_port(struct asd_ha_struct
*asd_ha
, struct asd_phy
*phy
)
174 struct asd_port
*free_port
= NULL
;
175 struct asd_port
*port
;
176 struct asd_sas_phy
*sas_phy
= &phy
->sas_phy
;
179 spin_lock_irqsave(&asd_ha
->asd_ports_lock
, flags
);
180 if (!phy
->asd_port
) {
181 for (i
= 0; i
< ASD_MAX_PHYS
; i
++) {
182 port
= &asd_ha
->asd_ports
[i
];
184 /* Check for wide port */
185 if (port
->num_phys
> 0 &&
186 memcmp(port
->sas_addr
, sas_phy
->sas_addr
,
187 SAS_ADDR_SIZE
) == 0 &&
188 memcmp(port
->attached_sas_addr
,
189 sas_phy
->attached_sas_addr
,
190 SAS_ADDR_SIZE
) == 0) {
194 /* Find a free port */
195 if (port
->num_phys
== 0 && free_port
== NULL
) {
200 /* Use a free port if this doesn't form a wide port */
201 if (i
>= ASD_MAX_PHYS
) {
204 memcpy(port
->sas_addr
, sas_phy
->sas_addr
,
206 memcpy(port
->attached_sas_addr
,
207 sas_phy
->attached_sas_addr
,
211 port
->phy_mask
|= (1U << sas_phy
->id
);
212 phy
->asd_port
= port
;
214 ASD_DPRINTK("%s: updating phy_mask 0x%x for phy%d\n",
215 __func__
, phy
->asd_port
->phy_mask
, sas_phy
->id
);
216 asd_update_port_links(asd_ha
, phy
);
217 spin_unlock_irqrestore(&asd_ha
->asd_ports_lock
, flags
);
220 static void asd_deform_port(struct asd_ha_struct
*asd_ha
, struct asd_phy
*phy
)
222 struct asd_port
*port
= phy
->asd_port
;
223 struct asd_sas_phy
*sas_phy
= &phy
->sas_phy
;
226 spin_lock_irqsave(&asd_ha
->asd_ports_lock
, flags
);
229 port
->phy_mask
&= ~(1U << sas_phy
->id
);
230 phy
->asd_port
= NULL
;
232 spin_unlock_irqrestore(&asd_ha
->asd_ports_lock
, flags
);
235 static void asd_bytes_dmaed_tasklet(struct asd_ascb
*ascb
,
236 struct done_list_struct
*dl
,
237 int edb_id
, int phy_id
)
240 int edb_el
= edb_id
+ ascb
->edb_index
;
241 struct asd_dma_tok
*edb
= ascb
->ha
->seq
.edb_arr
[edb_el
];
242 struct asd_phy
*phy
= &ascb
->ha
->phys
[phy_id
];
243 struct sas_ha_struct
*sas_ha
= phy
->sas_phy
.ha
;
244 u16 size
= ((dl
->status_block
[3] & 7) << 8) | dl
->status_block
[2];
246 size
= min(size
, (u16
) sizeof(phy
->frame_rcvd
));
248 spin_lock_irqsave(&phy
->sas_phy
.frame_rcvd_lock
, flags
);
249 memcpy(phy
->sas_phy
.frame_rcvd
, edb
->vaddr
, size
);
250 phy
->sas_phy
.frame_rcvd_size
= size
;
251 asd_get_attached_sas_addr(phy
, phy
->sas_phy
.attached_sas_addr
);
252 spin_unlock_irqrestore(&phy
->sas_phy
.frame_rcvd_lock
, flags
);
253 asd_dump_frame_rcvd(phy
, dl
);
254 asd_form_port(ascb
->ha
, phy
);
255 sas_ha
->notify_port_event(&phy
->sas_phy
, PORTE_BYTES_DMAED
);
258 static void asd_link_reset_err_tasklet(struct asd_ascb
*ascb
,
259 struct done_list_struct
*dl
,
262 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
263 struct sas_ha_struct
*sas_ha
= &asd_ha
->sas_ha
;
264 struct asd_sas_phy
*sas_phy
= sas_ha
->sas_phy
[phy_id
];
265 struct asd_phy
*phy
= &asd_ha
->phys
[phy_id
];
266 u8 lr_error
= dl
->status_block
[1];
267 u8 retries_left
= dl
->status_block
[2];
271 ASD_DPRINTK("phy%d: Receive ID timer expired\n", phy_id
);
274 ASD_DPRINTK("phy%d: Loss of signal\n", phy_id
);
277 ASD_DPRINTK("phy%d: Loss of dword sync\n", phy_id
);
280 ASD_DPRINTK("phy%d: Receive FIS timeout\n", phy_id
);
283 ASD_DPRINTK("phy%d: unknown link reset error code: 0x%x\n",
288 asd_turn_led(asd_ha
, phy_id
, 0);
289 sas_phy_disconnected(sas_phy
);
290 asd_deform_port(asd_ha
, phy
);
291 sas_ha
->notify_port_event(sas_phy
, PORTE_LINK_RESET_ERR
);
293 if (retries_left
== 0) {
295 struct asd_ascb
*cp
= asd_ascb_alloc_list(ascb
->ha
, &num
,
298 asd_printk("%s: out of memory\n", __func__
);
301 ASD_DPRINTK("phy%d: retries:0 performing link reset seq\n",
303 asd_build_control_phy(cp
, phy_id
, ENABLE_PHY
);
304 if (asd_post_ascb_list(ascb
->ha
, cp
, 1) != 0)
311 static void asd_primitive_rcvd_tasklet(struct asd_ascb
*ascb
,
312 struct done_list_struct
*dl
,
316 struct sas_ha_struct
*sas_ha
= &ascb
->ha
->sas_ha
;
317 struct asd_sas_phy
*sas_phy
= sas_ha
->sas_phy
[phy_id
];
318 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
319 struct asd_phy
*phy
= &asd_ha
->phys
[phy_id
];
320 u8 reg
= dl
->status_block
[1];
321 u32 cont
= dl
->status_block
[2] << ((reg
& 3)*8);
325 case LmPRMSTAT0BYTE0
:
331 ASD_DPRINTK("phy%d: BROADCAST change received:%d\n",
333 spin_lock_irqsave(&sas_phy
->sas_prim_lock
, flags
);
334 sas_phy
->sas_prim
= ffs(cont
);
335 spin_unlock_irqrestore(&sas_phy
->sas_prim_lock
, flags
);
336 sas_ha
->notify_port_event(sas_phy
,PORTE_BROADCAST_RCVD
);
340 ASD_DPRINTK("phy%d: unknown BREAK\n", phy_id
);
344 ASD_DPRINTK("phy%d: primitive reg:0x%x, cont:0x%04x\n",
349 case LmPRMSTAT1BYTE0
:
352 ASD_DPRINTK("phy%d: HARD_RESET primitive rcvd\n",
354 /* The sequencer disables all phys on that port.
355 * We have to re-enable the phys ourselves. */
356 asd_deform_port(asd_ha
, phy
);
357 sas_ha
->notify_port_event(sas_phy
, PORTE_HARD_RESET
);
361 ASD_DPRINTK("phy%d: primitive reg:0x%x, cont:0x%04x\n",
367 ASD_DPRINTK("unknown primitive register:0x%x\n",
368 dl
->status_block
[1]);
374 * asd_invalidate_edb -- invalidate an EDB and if necessary post the ESCB
375 * @ascb: pointer to Empty SCB
376 * @edb_id: index [0,6] to the empty data buffer which is to be invalidated
378 * After an EDB has been invalidated, if all EDBs in this ESCB have been
379 * invalidated, the ESCB is posted back to the sequencer.
380 * Context is tasklet/IRQ.
382 void asd_invalidate_edb(struct asd_ascb
*ascb
, int edb_id
)
384 struct asd_seq_data
*seq
= &ascb
->ha
->seq
;
385 struct empty_scb
*escb
= &ascb
->scb
->escb
;
386 struct sg_el
*eb
= &escb
->eb
[edb_id
];
387 struct asd_dma_tok
*edb
= seq
->edb_arr
[ascb
->edb_index
+ edb_id
];
389 memset(edb
->vaddr
, 0, ASD_EDB_SIZE
);
390 eb
->flags
|= ELEMENT_NOT_VALID
;
393 if (escb
->num_valid
== 0) {
395 /* ASD_DPRINTK("reposting escb: vaddr: 0x%p, "
396 "dma_handle: 0x%08llx, next: 0x%08llx, "
397 "index:%d, opcode:0x%02x\n",
399 (u64)ascb->dma_scb.dma_handle,
400 le64_to_cpu(ascb->scb->header.next_scb),
401 le16_to_cpu(ascb->scb->header.index),
402 ascb->scb->header.opcode);
404 escb
->num_valid
= ASD_EDBS_PER_SCB
;
405 for (i
= 0; i
< ASD_EDBS_PER_SCB
; i
++)
406 escb
->eb
[i
].flags
= 0;
407 if (!list_empty(&ascb
->list
))
408 list_del_init(&ascb
->list
);
409 i
= asd_post_escb_list(ascb
->ha
, ascb
, 1);
411 asd_printk("couldn't post escb, err:%d\n", i
);
415 static void escb_tasklet_complete(struct asd_ascb
*ascb
,
416 struct done_list_struct
*dl
)
418 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
419 struct sas_ha_struct
*sas_ha
= &asd_ha
->sas_ha
;
420 int edb
= (dl
->opcode
& DL_PHY_MASK
) - 1; /* [0xc1,0xc7] -> [0,6] */
421 u8 sb_opcode
= dl
->status_block
[0];
422 int phy_id
= sb_opcode
& DL_PHY_MASK
;
423 struct asd_sas_phy
*sas_phy
= sas_ha
->sas_phy
[phy_id
];
424 struct asd_phy
*phy
= &asd_ha
->phys
[phy_id
];
426 if (edb
> 6 || edb
< 0) {
427 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n",
429 ASD_DPRINTK("sb_opcode : 0x%x, phy_id: 0x%x\n",
431 ASD_DPRINTK("escb: vaddr: 0x%p, "
432 "dma_handle: 0x%llx, next: 0x%llx, "
433 "index:%d, opcode:0x%02x\n",
435 (unsigned long long)ascb
->dma_scb
.dma_handle
,
437 le64_to_cpu(ascb
->scb
->header
.next_scb
),
438 le16_to_cpu(ascb
->scb
->header
.index
),
439 ascb
->scb
->header
.opcode
);
442 /* Catch these before we mask off the sb_opcode bits */
444 case REQ_TASK_ABORT
: {
445 struct asd_ascb
*a
, *b
;
447 struct domain_device
*failed_dev
= NULL
;
449 ASD_DPRINTK("%s: REQ_TASK_ABORT, reason=0x%X\n",
450 __func__
, dl
->status_block
[3]);
453 * Find the task that caused the abort and abort it first.
454 * The sequencer won't put anything on the done list until
457 tc_abort
= *((u16
*)(&dl
->status_block
[1]));
458 tc_abort
= le16_to_cpu(tc_abort
);
460 list_for_each_entry_safe(a
, b
, &asd_ha
->seq
.pend_q
, list
) {
461 struct sas_task
*task
= a
->uldd_task
;
463 if (a
->tc_index
!= tc_abort
)
467 failed_dev
= task
->dev
;
468 sas_task_abort(task
);
470 ASD_DPRINTK("R_T_A for non TASK scb 0x%x\n",
471 a
->scb
->header
.opcode
);
477 ASD_DPRINTK("%s: Can't find task (tc=%d) to abort!\n",
483 * Now abort everything else for that device (hba?) so
484 * that the EH will wake up and do something.
486 list_for_each_entry_safe(a
, b
, &asd_ha
->seq
.pend_q
, list
) {
487 struct sas_task
*task
= a
->uldd_task
;
490 task
->dev
== failed_dev
&&
491 a
->tc_index
!= tc_abort
)
492 sas_task_abort(task
);
497 case REQ_DEVICE_RESET
: {
501 struct sas_task
*last_dev_task
= NULL
;
503 conn_handle
= *((u16
*)(&dl
->status_block
[1]));
504 conn_handle
= le16_to_cpu(conn_handle
);
506 ASD_DPRINTK("%s: REQ_DEVICE_RESET, reason=0x%X\n", __func__
,
507 dl
->status_block
[3]);
509 /* Find the last pending task for the device... */
510 list_for_each_entry(a
, &asd_ha
->seq
.pend_q
, list
) {
512 struct domain_device
*dev
;
513 struct sas_task
*task
= a
->uldd_task
;
519 x
= (unsigned long)dev
->lldd_dev
;
520 if (x
== conn_handle
)
521 last_dev_task
= task
;
524 if (!last_dev_task
) {
525 ASD_DPRINTK("%s: Device reset for idle device %d?\n",
526 __func__
, conn_handle
);
530 /* ...and set the reset flag */
531 spin_lock_irqsave(&last_dev_task
->task_state_lock
, flags
);
532 last_dev_task
->task_state_flags
|= SAS_TASK_NEED_DEV_RESET
;
533 spin_unlock_irqrestore(&last_dev_task
->task_state_lock
, flags
);
535 /* Kill all pending tasks for the device */
536 list_for_each_entry(a
, &asd_ha
->seq
.pend_q
, list
) {
538 struct domain_device
*dev
;
539 struct sas_task
*task
= a
->uldd_task
;
545 x
= (unsigned long)dev
->lldd_dev
;
546 if (x
== conn_handle
)
547 sas_task_abort(task
);
552 case SIGNAL_NCQ_ERROR
:
553 ASD_DPRINTK("%s: SIGNAL_NCQ_ERROR\n", __func__
);
555 case CLEAR_NCQ_ERROR
:
556 ASD_DPRINTK("%s: CLEAR_NCQ_ERROR\n", __func__
);
560 sb_opcode
&= ~DL_PHY_MASK
;
564 ASD_DPRINTK("%s: phy%d: BYTES_DMAED\n", __func__
, phy_id
);
565 asd_bytes_dmaed_tasklet(ascb
, dl
, edb
, phy_id
);
567 case PRIMITIVE_RECVD
:
568 ASD_DPRINTK("%s: phy%d: PRIMITIVE_RECVD\n", __func__
,
570 asd_primitive_rcvd_tasklet(ascb
, dl
, phy_id
);
573 ASD_DPRINTK("%s: phy%d: PHY_EVENT\n", __func__
, phy_id
);
574 asd_phy_event_tasklet(ascb
, dl
);
576 case LINK_RESET_ERROR
:
577 ASD_DPRINTK("%s: phy%d: LINK_RESET_ERROR\n", __func__
,
579 asd_link_reset_err_tasklet(ascb
, dl
, phy_id
);
582 ASD_DPRINTK("%s: phy%d: TIMER_EVENT, lost dw sync\n",
584 asd_turn_led(asd_ha
, phy_id
, 0);
585 /* the device is gone */
586 sas_phy_disconnected(sas_phy
);
587 asd_deform_port(asd_ha
, phy
);
588 sas_ha
->notify_port_event(sas_phy
, PORTE_TIMER_EVENT
);
591 ASD_DPRINTK("%s: phy%d: unknown event:0x%x\n", __func__
,
593 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n",
595 ASD_DPRINTK("sb_opcode : 0x%x, phy_id: 0x%x\n",
597 ASD_DPRINTK("escb: vaddr: 0x%p, "
598 "dma_handle: 0x%llx, next: 0x%llx, "
599 "index:%d, opcode:0x%02x\n",
601 (unsigned long long)ascb
->dma_scb
.dma_handle
,
603 le64_to_cpu(ascb
->scb
->header
.next_scb
),
604 le16_to_cpu(ascb
->scb
->header
.index
),
605 ascb
->scb
->header
.opcode
);
610 asd_invalidate_edb(ascb
, edb
);
613 int asd_init_post_escbs(struct asd_ha_struct
*asd_ha
)
615 struct asd_seq_data
*seq
= &asd_ha
->seq
;
618 for (i
= 0; i
< seq
->num_escbs
; i
++)
619 seq
->escb_arr
[i
]->tasklet_complete
= escb_tasklet_complete
;
621 ASD_DPRINTK("posting %d escbs\n", i
);
622 return asd_post_escb_list(asd_ha
, seq
->escb_arr
[0], seq
->num_escbs
);
625 /* ---------- CONTROL PHY ---------- */
627 #define CONTROL_PHY_STATUS (CURRENT_DEVICE_PRESENT | CURRENT_OOB_DONE \
628 | CURRENT_SPINUP_HOLD | CURRENT_GTO_TIMEOUT \
632 * control_phy_tasklet_complete -- tasklet complete for CONTROL PHY ascb
633 * @ascb: pointer to an ascb
634 * @dl: pointer to the done list entry
636 * This function completes a CONTROL PHY scb and frees the ascb.
638 * - an LED blinks if there is IO though it,
639 * - if a device is connected to the LED, it is lit,
640 * - if no device is connected to the LED, is is dimmed (off).
642 static void control_phy_tasklet_complete(struct asd_ascb
*ascb
,
643 struct done_list_struct
*dl
)
645 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
646 struct scb
*scb
= ascb
->scb
;
647 struct control_phy
*control_phy
= &scb
->control_phy
;
648 u8 phy_id
= control_phy
->phy_id
;
649 struct asd_phy
*phy
= &ascb
->ha
->phys
[phy_id
];
651 u8 status
= dl
->status_block
[0];
652 u8 oob_status
= dl
->status_block
[1];
653 u8 oob_mode
= dl
->status_block
[2];
654 /* u8 oob_signals= dl->status_block[3]; */
657 ASD_DPRINTK("%s: phy%d status block opcode:0x%x\n",
658 __func__
, phy_id
, status
);
662 switch (control_phy
->sub_func
) {
664 asd_ha
->hw_prof
.enabled_phys
&= ~(1 << phy_id
);
665 asd_turn_led(asd_ha
, phy_id
, 0);
666 asd_control_led(asd_ha
, phy_id
, 0);
667 ASD_DPRINTK("%s: disable phy%d\n", __func__
, phy_id
);
671 asd_control_led(asd_ha
, phy_id
, 1);
672 if (oob_status
& CURRENT_OOB_DONE
) {
673 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
674 get_lrate_mode(phy
, oob_mode
);
675 asd_turn_led(asd_ha
, phy_id
, 1);
676 ASD_DPRINTK("%s: phy%d, lrate:0x%x, proto:0x%x\n",
677 __func__
, phy_id
,phy
->sas_phy
.linkrate
,
678 phy
->sas_phy
.iproto
);
679 } else if (oob_status
& CURRENT_SPINUP_HOLD
) {
680 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
681 asd_turn_led(asd_ha
, phy_id
, 1);
682 ASD_DPRINTK("%s: phy%d, spinup hold\n", __func__
,
684 } else if (oob_status
& CURRENT_ERR_MASK
) {
685 asd_turn_led(asd_ha
, phy_id
, 0);
686 ASD_DPRINTK("%s: phy%d: error: oob status:0x%02x\n",
687 __func__
, phy_id
, oob_status
);
688 } else if (oob_status
& (CURRENT_HOT_PLUG_CNCT
689 | CURRENT_DEVICE_PRESENT
)) {
690 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
691 asd_turn_led(asd_ha
, phy_id
, 1);
692 ASD_DPRINTK("%s: phy%d: hot plug or device present\n",
695 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
696 asd_turn_led(asd_ha
, phy_id
, 0);
697 ASD_DPRINTK("%s: phy%d: no device present: "
699 __func__
, phy_id
, oob_status
);
702 case RELEASE_SPINUP_HOLD
:
704 case EXECUTE_HARD_RESET
:
705 ASD_DPRINTK("%s: phy%d: sub_func:0x%x\n", __func__
,
706 phy_id
, control_phy
->sub_func
);
710 ASD_DPRINTK("%s: phy%d: sub_func:0x%x?\n", __func__
,
711 phy_id
, control_phy
->sub_func
);
718 static void set_speed_mask(u8
*speed_mask
, struct asd_phy_desc
*pd
)
720 /* disable all speeds, then enable defaults */
721 *speed_mask
= SAS_SPEED_60_DIS
| SAS_SPEED_30_DIS
| SAS_SPEED_15_DIS
722 | SATA_SPEED_30_DIS
| SATA_SPEED_15_DIS
;
724 switch (pd
->max_sas_lrate
) {
725 case SAS_LINK_RATE_6_0_GBPS
:
726 *speed_mask
&= ~SAS_SPEED_60_DIS
;
728 case SAS_LINK_RATE_3_0_GBPS
:
729 *speed_mask
&= ~SAS_SPEED_30_DIS
;
730 case SAS_LINK_RATE_1_5_GBPS
:
731 *speed_mask
&= ~SAS_SPEED_15_DIS
;
734 switch (pd
->min_sas_lrate
) {
735 case SAS_LINK_RATE_6_0_GBPS
:
736 *speed_mask
|= SAS_SPEED_30_DIS
;
737 case SAS_LINK_RATE_3_0_GBPS
:
738 *speed_mask
|= SAS_SPEED_15_DIS
;
740 case SAS_LINK_RATE_1_5_GBPS
:
745 switch (pd
->max_sata_lrate
) {
746 case SAS_LINK_RATE_3_0_GBPS
:
747 *speed_mask
&= ~SATA_SPEED_30_DIS
;
749 case SAS_LINK_RATE_1_5_GBPS
:
750 *speed_mask
&= ~SATA_SPEED_15_DIS
;
753 switch (pd
->min_sata_lrate
) {
754 case SAS_LINK_RATE_3_0_GBPS
:
755 *speed_mask
|= SATA_SPEED_15_DIS
;
757 case SAS_LINK_RATE_1_5_GBPS
:
764 * asd_build_control_phy -- build a CONTROL PHY SCB
765 * @ascb: pointer to an ascb
766 * @phy_id: phy id to control, integer
767 * @subfunc: subfunction, what to actually to do the phy
769 * This function builds a CONTROL PHY scb. No allocation of any kind
770 * is performed. @ascb is allocated with the list function.
771 * The caller can override the ascb->tasklet_complete to point
772 * to its own callback function. It must call asd_ascb_free()
773 * at its tasklet complete function.
774 * See the default implementation.
776 void asd_build_control_phy(struct asd_ascb
*ascb
, int phy_id
, u8 subfunc
)
778 struct asd_phy
*phy
= &ascb
->ha
->phys
[phy_id
];
779 struct scb
*scb
= ascb
->scb
;
780 struct control_phy
*control_phy
= &scb
->control_phy
;
782 scb
->header
.opcode
= CONTROL_PHY
;
783 control_phy
->phy_id
= (u8
) phy_id
;
784 control_phy
->sub_func
= subfunc
;
787 case EXECUTE_HARD_RESET
: /* 0x81 */
788 case ENABLE_PHY
: /* 0x01 */
789 /* decide hot plug delay */
790 control_phy
->hot_plug_delay
= HOTPLUG_DELAY_TIMEOUT
;
792 /* decide speed mask */
793 set_speed_mask(&control_phy
->speed_mask
, phy
->phy_desc
);
795 /* initiator port settings are in the hi nibble */
796 if (phy
->sas_phy
.role
== PHY_ROLE_INITIATOR
)
797 control_phy
->port_type
= SAS_PROTOCOL_ALL
<< 4;
798 else if (phy
->sas_phy
.role
== PHY_ROLE_TARGET
)
799 control_phy
->port_type
= SAS_PROTOCOL_ALL
;
801 control_phy
->port_type
=
802 (SAS_PROTOCOL_ALL
<< 4) | SAS_PROTOCOL_ALL
;
804 /* link reset retries, this should be nominal */
805 control_phy
->link_reset_retries
= 10;
807 case RELEASE_SPINUP_HOLD
: /* 0x02 */
808 /* decide the func_mask */
809 control_phy
->func_mask
= FUNCTION_MASK_DEFAULT
;
810 if (phy
->phy_desc
->flags
& ASD_SATA_SPINUP_HOLD
)
811 control_phy
->func_mask
&= ~SPINUP_HOLD_DIS
;
813 control_phy
->func_mask
|= SPINUP_HOLD_DIS
;
816 control_phy
->conn_handle
= cpu_to_le16(0xFFFF);
818 ascb
->tasklet_complete
= control_phy_tasklet_complete
;
821 /* ---------- INITIATE LINK ADM TASK ---------- */
825 static void link_adm_tasklet_complete(struct asd_ascb
*ascb
,
826 struct done_list_struct
*dl
)
828 u8 opcode
= dl
->opcode
;
829 struct initiate_link_adm
*link_adm
= &ascb
->scb
->link_adm
;
830 u8 phy_id
= link_adm
->phy_id
;
832 if (opcode
!= TC_NO_ERROR
) {
833 asd_printk("phy%d: link adm task 0x%x completed with error "
834 "0x%x\n", phy_id
, link_adm
->sub_func
, opcode
);
836 ASD_DPRINTK("phy%d: link adm task 0x%x: 0x%x\n",
837 phy_id
, link_adm
->sub_func
, opcode
);
842 void asd_build_initiate_link_adm_task(struct asd_ascb
*ascb
, int phy_id
,
845 struct scb
*scb
= ascb
->scb
;
846 struct initiate_link_adm
*link_adm
= &scb
->link_adm
;
848 scb
->header
.opcode
= INITIATE_LINK_ADM_TASK
;
850 link_adm
->phy_id
= phy_id
;
851 link_adm
->sub_func
= subfunc
;
852 link_adm
->conn_handle
= cpu_to_le16(0xFFFF);
854 ascb
->tasklet_complete
= link_adm_tasklet_complete
;
859 /* ---------- SCB timer ---------- */
862 * asd_ascb_timedout -- called when a pending SCB's timer has expired
863 * @data: unsigned long, a pointer to the ascb in question
865 * This is the default timeout function which does the most necessary.
866 * Upper layers can implement their own timeout function, say to free
867 * resources they have with this SCB, and then call this one at the
868 * end of their timeout function. To do this, one should initialize
869 * the ascb->timer.{function, expires} prior to calling the post
870 * function. The timer is started by the post function.
872 void asd_ascb_timedout(struct timer_list
*t
)
874 struct asd_ascb
*ascb
= from_timer(ascb
, t
, timer
);
875 struct asd_seq_data
*seq
= &ascb
->ha
->seq
;
878 ASD_DPRINTK("scb:0x%x timed out\n", ascb
->scb
->header
.opcode
);
880 spin_lock_irqsave(&seq
->pend_q_lock
, flags
);
882 list_del_init(&ascb
->list
);
883 spin_unlock_irqrestore(&seq
->pend_q_lock
, flags
);
888 /* ---------- CONTROL PHY ---------- */
890 /* Given the spec value, return a driver value. */
891 static const int phy_func_table
[] = {
892 [PHY_FUNC_NOP
] = PHY_NO_OP
,
893 [PHY_FUNC_LINK_RESET
] = ENABLE_PHY
,
894 [PHY_FUNC_HARD_RESET
] = EXECUTE_HARD_RESET
,
895 [PHY_FUNC_DISABLE
] = DISABLE_PHY
,
896 [PHY_FUNC_RELEASE_SPINUP_HOLD
] = RELEASE_SPINUP_HOLD
,
899 int asd_control_phy(struct asd_sas_phy
*phy
, enum phy_func func
, void *arg
)
901 struct asd_ha_struct
*asd_ha
= phy
->ha
->lldd_ha
;
902 struct asd_phy_desc
*pd
= asd_ha
->phys
[phy
->id
].phy_desc
;
903 struct asd_ascb
*ascb
;
904 struct sas_phy_linkrates
*rates
;
908 case PHY_FUNC_CLEAR_ERROR_LOG
:
909 case PHY_FUNC_GET_EVENTS
:
911 case PHY_FUNC_SET_LINK_RATE
:
913 if (rates
->minimum_linkrate
) {
914 pd
->min_sas_lrate
= rates
->minimum_linkrate
;
915 pd
->min_sata_lrate
= rates
->minimum_linkrate
;
917 if (rates
->maximum_linkrate
) {
918 pd
->max_sas_lrate
= rates
->maximum_linkrate
;
919 pd
->max_sata_lrate
= rates
->maximum_linkrate
;
921 func
= PHY_FUNC_LINK_RESET
;
927 ascb
= asd_ascb_alloc_list(asd_ha
, &res
, GFP_KERNEL
);
931 asd_build_control_phy(ascb
, phy
->id
, phy_func_table
[func
]);
932 res
= asd_post_ascb_list(asd_ha
, ascb
, 1);