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/pci.h>
30 #include "aic94xx_reg.h"
31 #include "aic94xx_hwi.h"
32 #include "aic94xx_seq.h"
34 #include "aic94xx_dump.h"
36 /* ---------- EMPTY SCB ---------- */
40 #define PRIMITIVE_RECVD 0x08
41 #define PHY_EVENT 0x10
42 #define LINK_RESET_ERROR 0x18
43 #define TIMER_EVENT 0x20
44 #define REQ_TASK_ABORT 0xF0
45 #define REQ_DEVICE_RESET 0xF1
46 #define SIGNAL_NCQ_ERROR 0xF2
47 #define CLEAR_NCQ_ERROR 0xF3
49 #define PHY_EVENTS_STATUS (CURRENT_LOSS_OF_SIGNAL | CURRENT_OOB_DONE \
50 | CURRENT_SPINUP_HOLD | CURRENT_GTO_TIMEOUT \
53 static inline void get_lrate_mode(struct asd_phy
*phy
, u8 oob_mode
)
55 struct sas_phy
*sas_phy
= phy
->sas_phy
.phy
;
57 switch (oob_mode
& 7) {
59 /* FIXME: sas transport class doesn't have this */
60 phy
->sas_phy
.linkrate
= SAS_LINK_RATE_6_0_GBPS
;
61 phy
->sas_phy
.phy
->negotiated_linkrate
= SAS_LINK_RATE_6_0_GBPS
;
64 phy
->sas_phy
.linkrate
= SAS_LINK_RATE_3_0_GBPS
;
65 phy
->sas_phy
.phy
->negotiated_linkrate
= SAS_LINK_RATE_3_0_GBPS
;
68 phy
->sas_phy
.linkrate
= SAS_LINK_RATE_1_5_GBPS
;
69 phy
->sas_phy
.phy
->negotiated_linkrate
= SAS_LINK_RATE_1_5_GBPS
;
72 sas_phy
->negotiated_linkrate
= phy
->sas_phy
.linkrate
;
73 sas_phy
->maximum_linkrate_hw
= SAS_LINK_RATE_3_0_GBPS
;
74 sas_phy
->minimum_linkrate_hw
= SAS_LINK_RATE_1_5_GBPS
;
75 sas_phy
->maximum_linkrate
= phy
->phy_desc
->max_sas_lrate
;
76 sas_phy
->minimum_linkrate
= phy
->phy_desc
->min_sas_lrate
;
78 if (oob_mode
& SAS_MODE
)
79 phy
->sas_phy
.oob_mode
= SAS_OOB_MODE
;
80 else if (oob_mode
& SATA_MODE
)
81 phy
->sas_phy
.oob_mode
= SATA_OOB_MODE
;
84 static inline void asd_phy_event_tasklet(struct asd_ascb
*ascb
,
85 struct done_list_struct
*dl
)
87 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
88 struct sas_ha_struct
*sas_ha
= &asd_ha
->sas_ha
;
89 int phy_id
= dl
->status_block
[0] & DL_PHY_MASK
;
90 struct asd_phy
*phy
= &asd_ha
->phys
[phy_id
];
92 u8 oob_status
= dl
->status_block
[1] & PHY_EVENTS_STATUS
;
93 u8 oob_mode
= dl
->status_block
[2];
96 case CURRENT_LOSS_OF_SIGNAL
:
97 /* directly attached device was removed */
98 ASD_DPRINTK("phy%d: device unplugged\n", phy_id
);
99 asd_turn_led(asd_ha
, phy_id
, 0);
100 sas_phy_disconnected(&phy
->sas_phy
);
101 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_LOSS_OF_SIGNAL
);
103 case CURRENT_OOB_DONE
:
104 /* hot plugged device */
105 asd_turn_led(asd_ha
, phy_id
, 1);
106 get_lrate_mode(phy
, oob_mode
);
107 ASD_DPRINTK("phy%d device plugged: lrate:0x%x, proto:0x%x\n",
108 phy_id
, phy
->sas_phy
.linkrate
, phy
->sas_phy
.iproto
);
109 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_OOB_DONE
);
111 case CURRENT_SPINUP_HOLD
:
112 /* hot plug SATA, no COMWAKE sent */
113 asd_turn_led(asd_ha
, phy_id
, 1);
114 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_SPINUP_HOLD
);
116 case CURRENT_GTO_TIMEOUT
:
117 case CURRENT_OOB_ERROR
:
118 ASD_DPRINTK("phy%d error while OOB: oob status:0x%x\n", phy_id
,
119 dl
->status_block
[1]);
120 asd_turn_led(asd_ha
, phy_id
, 0);
121 sas_phy_disconnected(&phy
->sas_phy
);
122 sas_ha
->notify_phy_event(&phy
->sas_phy
, PHYE_OOB_ERROR
);
127 /* If phys are enabled sparsely, this will do the right thing. */
128 static inline unsigned ord_phy(struct asd_ha_struct
*asd_ha
,
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 inline 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 inline void asd_bytes_dmaed_tasklet(struct asd_ascb
*ascb
,
172 struct done_list_struct
*dl
,
173 int edb_id
, int phy_id
)
176 int edb_el
= edb_id
+ ascb
->edb_index
;
177 struct asd_dma_tok
*edb
= ascb
->ha
->seq
.edb_arr
[edb_el
];
178 struct asd_phy
*phy
= &ascb
->ha
->phys
[phy_id
];
179 struct sas_ha_struct
*sas_ha
= phy
->sas_phy
.ha
;
180 u16 size
= ((dl
->status_block
[3] & 7) << 8) | dl
->status_block
[2];
182 size
= min(size
, (u16
) sizeof(phy
->frame_rcvd
));
184 spin_lock_irqsave(&phy
->sas_phy
.frame_rcvd_lock
, flags
);
185 memcpy(phy
->sas_phy
.frame_rcvd
, edb
->vaddr
, size
);
186 phy
->sas_phy
.frame_rcvd_size
= size
;
187 asd_get_attached_sas_addr(phy
, phy
->sas_phy
.attached_sas_addr
);
188 spin_unlock_irqrestore(&phy
->sas_phy
.frame_rcvd_lock
, flags
);
189 asd_dump_frame_rcvd(phy
, dl
);
190 sas_ha
->notify_port_event(&phy
->sas_phy
, PORTE_BYTES_DMAED
);
193 static inline void asd_link_reset_err_tasklet(struct asd_ascb
*ascb
,
194 struct done_list_struct
*dl
,
197 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
198 struct sas_ha_struct
*sas_ha
= &asd_ha
->sas_ha
;
199 struct asd_sas_phy
*sas_phy
= sas_ha
->sas_phy
[phy_id
];
200 u8 lr_error
= dl
->status_block
[1];
201 u8 retries_left
= dl
->status_block
[2];
205 ASD_DPRINTK("phy%d: Receive ID timer expired\n", phy_id
);
208 ASD_DPRINTK("phy%d: Loss of signal\n", phy_id
);
211 ASD_DPRINTK("phy%d: Loss of dword sync\n", phy_id
);
214 ASD_DPRINTK("phy%d: Receive FIS timeout\n", phy_id
);
217 ASD_DPRINTK("phy%d: unknown link reset error code: 0x%x\n",
222 asd_turn_led(asd_ha
, phy_id
, 0);
223 sas_phy_disconnected(sas_phy
);
224 sas_ha
->notify_port_event(sas_phy
, PORTE_LINK_RESET_ERR
);
226 if (retries_left
== 0) {
228 struct asd_ascb
*cp
= asd_ascb_alloc_list(ascb
->ha
, &num
,
231 asd_printk("%s: out of memory\n", __FUNCTION__
);
234 ASD_DPRINTK("phy%d: retries:0 performing link reset seq\n",
236 asd_build_control_phy(cp
, phy_id
, ENABLE_PHY
);
237 if (asd_post_ascb_list(ascb
->ha
, cp
, 1) != 0)
244 static inline void asd_primitive_rcvd_tasklet(struct asd_ascb
*ascb
,
245 struct done_list_struct
*dl
,
249 struct sas_ha_struct
*sas_ha
= &ascb
->ha
->sas_ha
;
250 struct asd_sas_phy
*sas_phy
= sas_ha
->sas_phy
[phy_id
];
251 u8 reg
= dl
->status_block
[1];
252 u32 cont
= dl
->status_block
[2] << ((reg
& 3)*8);
256 case LmPRMSTAT0BYTE0
:
262 ASD_DPRINTK("phy%d: BROADCAST change received:%d\n",
264 spin_lock_irqsave(&sas_phy
->sas_prim_lock
, flags
);
265 sas_phy
->sas_prim
= ffs(cont
);
266 spin_unlock_irqrestore(&sas_phy
->sas_prim_lock
, flags
);
267 sas_ha
->notify_port_event(sas_phy
,PORTE_BROADCAST_RCVD
);
271 ASD_DPRINTK("phy%d: unknown BREAK\n", phy_id
);
275 ASD_DPRINTK("phy%d: primitive reg:0x%x, cont:0x%04x\n",
280 case LmPRMSTAT1BYTE0
:
283 ASD_DPRINTK("phy%d: HARD_RESET primitive rcvd\n",
285 /* The sequencer disables all phys on that port.
286 * We have to re-enable the phys ourselves. */
287 sas_ha
->notify_port_event(sas_phy
, PORTE_HARD_RESET
);
291 ASD_DPRINTK("phy%d: primitive reg:0x%x, cont:0x%04x\n",
297 ASD_DPRINTK("unknown primitive register:0x%x\n",
298 dl
->status_block
[1]);
304 * asd_invalidate_edb -- invalidate an EDB and if necessary post the ESCB
305 * @ascb: pointer to Empty SCB
306 * @edb_id: index [0,6] to the empty data buffer which is to be invalidated
308 * After an EDB has been invalidated, if all EDBs in this ESCB have been
309 * invalidated, the ESCB is posted back to the sequencer.
310 * Context is tasklet/IRQ.
312 void asd_invalidate_edb(struct asd_ascb
*ascb
, int edb_id
)
314 struct asd_seq_data
*seq
= &ascb
->ha
->seq
;
315 struct empty_scb
*escb
= &ascb
->scb
->escb
;
316 struct sg_el
*eb
= &escb
->eb
[edb_id
];
317 struct asd_dma_tok
*edb
= seq
->edb_arr
[ascb
->edb_index
+ edb_id
];
319 memset(edb
->vaddr
, 0, ASD_EDB_SIZE
);
320 eb
->flags
|= ELEMENT_NOT_VALID
;
323 if (escb
->num_valid
== 0) {
325 /* ASD_DPRINTK("reposting escb: vaddr: 0x%p, "
326 "dma_handle: 0x%08llx, next: 0x%08llx, "
327 "index:%d, opcode:0x%02x\n",
329 (u64)ascb->dma_scb.dma_handle,
330 le64_to_cpu(ascb->scb->header.next_scb),
331 le16_to_cpu(ascb->scb->header.index),
332 ascb->scb->header.opcode);
334 escb
->num_valid
= ASD_EDBS_PER_SCB
;
335 for (i
= 0; i
< ASD_EDBS_PER_SCB
; i
++)
336 escb
->eb
[i
].flags
= 0;
337 if (!list_empty(&ascb
->list
))
338 list_del_init(&ascb
->list
);
339 i
= asd_post_escb_list(ascb
->ha
, ascb
, 1);
341 asd_printk("couldn't post escb, err:%d\n", i
);
345 static void escb_tasklet_complete(struct asd_ascb
*ascb
,
346 struct done_list_struct
*dl
)
348 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
349 struct sas_ha_struct
*sas_ha
= &asd_ha
->sas_ha
;
350 int edb
= (dl
->opcode
& DL_PHY_MASK
) - 1; /* [0xc1,0xc7] -> [0,6] */
351 u8 sb_opcode
= dl
->status_block
[0];
352 int phy_id
= sb_opcode
& DL_PHY_MASK
;
353 struct asd_sas_phy
*sas_phy
= sas_ha
->sas_phy
[phy_id
];
355 if (edb
> 6 || edb
< 0) {
356 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n",
358 ASD_DPRINTK("sb_opcode : 0x%x, phy_id: 0x%x\n",
360 ASD_DPRINTK("escb: vaddr: 0x%p, "
361 "dma_handle: 0x%llx, next: 0x%llx, "
362 "index:%d, opcode:0x%02x\n",
364 (unsigned long long)ascb
->dma_scb
.dma_handle
,
366 le64_to_cpu(ascb
->scb
->header
.next_scb
),
367 le16_to_cpu(ascb
->scb
->header
.index
),
368 ascb
->scb
->header
.opcode
);
371 sb_opcode
&= ~DL_PHY_MASK
;
375 ASD_DPRINTK("%s: phy%d: BYTES_DMAED\n", __FUNCTION__
, phy_id
);
376 asd_bytes_dmaed_tasklet(ascb
, dl
, edb
, phy_id
);
378 case PRIMITIVE_RECVD
:
379 ASD_DPRINTK("%s: phy%d: PRIMITIVE_RECVD\n", __FUNCTION__
,
381 asd_primitive_rcvd_tasklet(ascb
, dl
, phy_id
);
384 ASD_DPRINTK("%s: phy%d: PHY_EVENT\n", __FUNCTION__
, phy_id
);
385 asd_phy_event_tasklet(ascb
, dl
);
387 case LINK_RESET_ERROR
:
388 ASD_DPRINTK("%s: phy%d: LINK_RESET_ERROR\n", __FUNCTION__
,
390 asd_link_reset_err_tasklet(ascb
, dl
, phy_id
);
393 ASD_DPRINTK("%s: phy%d: TIMER_EVENT, lost dw sync\n",
394 __FUNCTION__
, phy_id
);
395 asd_turn_led(asd_ha
, phy_id
, 0);
396 /* the device is gone */
397 sas_phy_disconnected(sas_phy
);
398 sas_ha
->notify_port_event(sas_phy
, PORTE_TIMER_EVENT
);
401 ASD_DPRINTK("%s: phy%d: REQ_TASK_ABORT\n", __FUNCTION__
,
404 case REQ_DEVICE_RESET
:
405 ASD_DPRINTK("%s: phy%d: REQ_DEVICE_RESET\n", __FUNCTION__
,
408 case SIGNAL_NCQ_ERROR
:
409 ASD_DPRINTK("%s: phy%d: SIGNAL_NCQ_ERROR\n", __FUNCTION__
,
412 case CLEAR_NCQ_ERROR
:
413 ASD_DPRINTK("%s: phy%d: CLEAR_NCQ_ERROR\n", __FUNCTION__
,
417 ASD_DPRINTK("%s: phy%d: unknown event:0x%x\n", __FUNCTION__
,
419 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n",
421 ASD_DPRINTK("sb_opcode : 0x%x, phy_id: 0x%x\n",
423 ASD_DPRINTK("escb: vaddr: 0x%p, "
424 "dma_handle: 0x%llx, next: 0x%llx, "
425 "index:%d, opcode:0x%02x\n",
427 (unsigned long long)ascb
->dma_scb
.dma_handle
,
429 le64_to_cpu(ascb
->scb
->header
.next_scb
),
430 le16_to_cpu(ascb
->scb
->header
.index
),
431 ascb
->scb
->header
.opcode
);
436 asd_invalidate_edb(ascb
, edb
);
439 int asd_init_post_escbs(struct asd_ha_struct
*asd_ha
)
441 struct asd_seq_data
*seq
= &asd_ha
->seq
;
444 for (i
= 0; i
< seq
->num_escbs
; i
++)
445 seq
->escb_arr
[i
]->tasklet_complete
= escb_tasklet_complete
;
447 ASD_DPRINTK("posting %d escbs\n", i
);
448 return asd_post_escb_list(asd_ha
, seq
->escb_arr
[0], seq
->num_escbs
);
451 /* ---------- CONTROL PHY ---------- */
453 #define CONTROL_PHY_STATUS (CURRENT_DEVICE_PRESENT | CURRENT_OOB_DONE \
454 | CURRENT_SPINUP_HOLD | CURRENT_GTO_TIMEOUT \
458 * control_phy_tasklet_complete -- tasklet complete for CONTROL PHY ascb
459 * @ascb: pointer to an ascb
460 * @dl: pointer to the done list entry
462 * This function completes a CONTROL PHY scb and frees the ascb.
464 * - an LED blinks if there is IO though it,
465 * - if a device is connected to the LED, it is lit,
466 * - if no device is connected to the LED, is is dimmed (off).
468 static void control_phy_tasklet_complete(struct asd_ascb
*ascb
,
469 struct done_list_struct
*dl
)
471 struct asd_ha_struct
*asd_ha
= ascb
->ha
;
472 struct scb
*scb
= ascb
->scb
;
473 struct control_phy
*control_phy
= &scb
->control_phy
;
474 u8 phy_id
= control_phy
->phy_id
;
475 struct asd_phy
*phy
= &ascb
->ha
->phys
[phy_id
];
477 u8 status
= dl
->status_block
[0];
478 u8 oob_status
= dl
->status_block
[1];
479 u8 oob_mode
= dl
->status_block
[2];
480 /* u8 oob_signals= dl->status_block[3]; */
483 ASD_DPRINTK("%s: phy%d status block opcode:0x%x\n",
484 __FUNCTION__
, phy_id
, status
);
488 switch (control_phy
->sub_func
) {
490 asd_ha
->hw_prof
.enabled_phys
&= ~(1 << phy_id
);
491 asd_turn_led(asd_ha
, phy_id
, 0);
492 asd_control_led(asd_ha
, phy_id
, 0);
493 ASD_DPRINTK("%s: disable phy%d\n", __FUNCTION__
, phy_id
);
497 asd_control_led(asd_ha
, phy_id
, 1);
498 if (oob_status
& CURRENT_OOB_DONE
) {
499 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
500 get_lrate_mode(phy
, oob_mode
);
501 asd_turn_led(asd_ha
, phy_id
, 1);
502 ASD_DPRINTK("%s: phy%d, lrate:0x%x, proto:0x%x\n",
503 __FUNCTION__
, phy_id
,phy
->sas_phy
.linkrate
,
504 phy
->sas_phy
.iproto
);
505 } else if (oob_status
& CURRENT_SPINUP_HOLD
) {
506 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
507 asd_turn_led(asd_ha
, phy_id
, 1);
508 ASD_DPRINTK("%s: phy%d, spinup hold\n", __FUNCTION__
,
510 } else if (oob_status
& CURRENT_ERR_MASK
) {
511 asd_turn_led(asd_ha
, phy_id
, 0);
512 ASD_DPRINTK("%s: phy%d: error: oob status:0x%02x\n",
513 __FUNCTION__
, phy_id
, oob_status
);
514 } else if (oob_status
& (CURRENT_HOT_PLUG_CNCT
515 | CURRENT_DEVICE_PRESENT
)) {
516 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
517 asd_turn_led(asd_ha
, phy_id
, 1);
518 ASD_DPRINTK("%s: phy%d: hot plug or device present\n",
519 __FUNCTION__
, phy_id
);
521 asd_ha
->hw_prof
.enabled_phys
|= (1 << phy_id
);
522 asd_turn_led(asd_ha
, phy_id
, 0);
523 ASD_DPRINTK("%s: phy%d: no device present: "
525 __FUNCTION__
, phy_id
, oob_status
);
528 case RELEASE_SPINUP_HOLD
:
530 case EXECUTE_HARD_RESET
:
531 ASD_DPRINTK("%s: phy%d: sub_func:0x%x\n", __FUNCTION__
,
532 phy_id
, control_phy
->sub_func
);
536 ASD_DPRINTK("%s: phy%d: sub_func:0x%x?\n", __FUNCTION__
,
537 phy_id
, control_phy
->sub_func
);
544 static inline void set_speed_mask(u8
*speed_mask
, struct asd_phy_desc
*pd
)
546 /* disable all speeds, then enable defaults */
547 *speed_mask
= SAS_SPEED_60_DIS
| SAS_SPEED_30_DIS
| SAS_SPEED_15_DIS
548 | SATA_SPEED_30_DIS
| SATA_SPEED_15_DIS
;
550 switch (pd
->max_sas_lrate
) {
551 case SAS_LINK_RATE_6_0_GBPS
:
552 *speed_mask
&= ~SAS_SPEED_60_DIS
;
554 case SAS_LINK_RATE_3_0_GBPS
:
555 *speed_mask
&= ~SAS_SPEED_30_DIS
;
556 case SAS_LINK_RATE_1_5_GBPS
:
557 *speed_mask
&= ~SAS_SPEED_15_DIS
;
560 switch (pd
->min_sas_lrate
) {
561 case SAS_LINK_RATE_6_0_GBPS
:
562 *speed_mask
|= SAS_SPEED_30_DIS
;
563 case SAS_LINK_RATE_3_0_GBPS
:
564 *speed_mask
|= SAS_SPEED_15_DIS
;
566 case SAS_LINK_RATE_1_5_GBPS
:
571 switch (pd
->max_sata_lrate
) {
572 case SAS_LINK_RATE_3_0_GBPS
:
573 *speed_mask
&= ~SATA_SPEED_30_DIS
;
575 case SAS_LINK_RATE_1_5_GBPS
:
576 *speed_mask
&= ~SATA_SPEED_15_DIS
;
579 switch (pd
->min_sata_lrate
) {
580 case SAS_LINK_RATE_3_0_GBPS
:
581 *speed_mask
|= SATA_SPEED_15_DIS
;
583 case SAS_LINK_RATE_1_5_GBPS
:
590 * asd_build_control_phy -- build a CONTROL PHY SCB
591 * @ascb: pointer to an ascb
592 * @phy_id: phy id to control, integer
593 * @subfunc: subfunction, what to actually to do the phy
595 * This function builds a CONTROL PHY scb. No allocation of any kind
596 * is performed. @ascb is allocated with the list function.
597 * The caller can override the ascb->tasklet_complete to point
598 * to its own callback function. It must call asd_ascb_free()
599 * at its tasklet complete function.
600 * See the default implementation.
602 void asd_build_control_phy(struct asd_ascb
*ascb
, int phy_id
, u8 subfunc
)
604 struct asd_phy
*phy
= &ascb
->ha
->phys
[phy_id
];
605 struct scb
*scb
= ascb
->scb
;
606 struct control_phy
*control_phy
= &scb
->control_phy
;
608 scb
->header
.opcode
= CONTROL_PHY
;
609 control_phy
->phy_id
= (u8
) phy_id
;
610 control_phy
->sub_func
= subfunc
;
613 case EXECUTE_HARD_RESET
: /* 0x81 */
614 case ENABLE_PHY
: /* 0x01 */
615 /* decide hot plug delay */
616 control_phy
->hot_plug_delay
= HOTPLUG_DELAY_TIMEOUT
;
618 /* decide speed mask */
619 set_speed_mask(&control_phy
->speed_mask
, phy
->phy_desc
);
621 /* initiator port settings are in the hi nibble */
622 if (phy
->sas_phy
.role
== PHY_ROLE_INITIATOR
)
623 control_phy
->port_type
= SAS_PROTO_ALL
<< 4;
624 else if (phy
->sas_phy
.role
== PHY_ROLE_TARGET
)
625 control_phy
->port_type
= SAS_PROTO_ALL
;
627 control_phy
->port_type
=
628 (SAS_PROTO_ALL
<< 4) | SAS_PROTO_ALL
;
630 /* link reset retries, this should be nominal */
631 control_phy
->link_reset_retries
= 10;
633 case RELEASE_SPINUP_HOLD
: /* 0x02 */
634 /* decide the func_mask */
635 control_phy
->func_mask
= FUNCTION_MASK_DEFAULT
;
636 if (phy
->phy_desc
->flags
& ASD_SATA_SPINUP_HOLD
)
637 control_phy
->func_mask
&= ~SPINUP_HOLD_DIS
;
639 control_phy
->func_mask
|= SPINUP_HOLD_DIS
;
642 control_phy
->conn_handle
= cpu_to_le16(0xFFFF);
644 ascb
->tasklet_complete
= control_phy_tasklet_complete
;
647 /* ---------- INITIATE LINK ADM TASK ---------- */
649 static void link_adm_tasklet_complete(struct asd_ascb
*ascb
,
650 struct done_list_struct
*dl
)
652 u8 opcode
= dl
->opcode
;
653 struct initiate_link_adm
*link_adm
= &ascb
->scb
->link_adm
;
654 u8 phy_id
= link_adm
->phy_id
;
656 if (opcode
!= TC_NO_ERROR
) {
657 asd_printk("phy%d: link adm task 0x%x completed with error "
658 "0x%x\n", phy_id
, link_adm
->sub_func
, opcode
);
660 ASD_DPRINTK("phy%d: link adm task 0x%x: 0x%x\n",
661 phy_id
, link_adm
->sub_func
, opcode
);
666 void asd_build_initiate_link_adm_task(struct asd_ascb
*ascb
, int phy_id
,
669 struct scb
*scb
= ascb
->scb
;
670 struct initiate_link_adm
*link_adm
= &scb
->link_adm
;
672 scb
->header
.opcode
= INITIATE_LINK_ADM_TASK
;
674 link_adm
->phy_id
= phy_id
;
675 link_adm
->sub_func
= subfunc
;
676 link_adm
->conn_handle
= cpu_to_le16(0xFFFF);
678 ascb
->tasklet_complete
= link_adm_tasklet_complete
;
681 /* ---------- SCB timer ---------- */
684 * asd_ascb_timedout -- called when a pending SCB's timer has expired
685 * @data: unsigned long, a pointer to the ascb in question
687 * This is the default timeout function which does the most necessary.
688 * Upper layers can implement their own timeout function, say to free
689 * resources they have with this SCB, and then call this one at the
690 * end of their timeout function. To do this, one should initialize
691 * the ascb->timer.{function, data, expires} prior to calling the post
692 * funcion. The timer is started by the post function.
694 void asd_ascb_timedout(unsigned long data
)
696 struct asd_ascb
*ascb
= (void *) data
;
697 struct asd_seq_data
*seq
= &ascb
->ha
->seq
;
700 ASD_DPRINTK("scb:0x%x timed out\n", ascb
->scb
->header
.opcode
);
702 spin_lock_irqsave(&seq
->pend_q_lock
, flags
);
704 list_del_init(&ascb
->list
);
705 spin_unlock_irqrestore(&seq
->pend_q_lock
, flags
);
710 /* ---------- CONTROL PHY ---------- */
712 /* Given the spec value, return a driver value. */
713 static const int phy_func_table
[] = {
714 [PHY_FUNC_NOP
] = PHY_NO_OP
,
715 [PHY_FUNC_LINK_RESET
] = ENABLE_PHY
,
716 [PHY_FUNC_HARD_RESET
] = EXECUTE_HARD_RESET
,
717 [PHY_FUNC_DISABLE
] = DISABLE_PHY
,
718 [PHY_FUNC_RELEASE_SPINUP_HOLD
] = RELEASE_SPINUP_HOLD
,
721 int asd_control_phy(struct asd_sas_phy
*phy
, enum phy_func func
, void *arg
)
723 struct asd_ha_struct
*asd_ha
= phy
->ha
->lldd_ha
;
724 struct asd_phy_desc
*pd
= asd_ha
->phys
[phy
->id
].phy_desc
;
725 struct asd_ascb
*ascb
;
726 struct sas_phy_linkrates
*rates
;
730 case PHY_FUNC_CLEAR_ERROR_LOG
:
732 case PHY_FUNC_SET_LINK_RATE
:
734 if (rates
->minimum_linkrate
) {
735 pd
->min_sas_lrate
= rates
->minimum_linkrate
;
736 pd
->min_sata_lrate
= rates
->minimum_linkrate
;
738 if (rates
->maximum_linkrate
) {
739 pd
->max_sas_lrate
= rates
->maximum_linkrate
;
740 pd
->max_sata_lrate
= rates
->maximum_linkrate
;
742 func
= PHY_FUNC_LINK_RESET
;
748 ascb
= asd_ascb_alloc_list(asd_ha
, &res
, GFP_KERNEL
);
752 asd_build_control_phy(ascb
, phy
->id
, phy_func_table
[func
]);
753 res
= asd_post_ascb_list(asd_ha
, ascb
, 1);