Lines Matching +full:sata +full:- +full:oob
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Aic94xx SAS/SATA driver SCB management.
19 /* ---------- EMPTY SCB ---------- */
38 struct sas_phy *sas_phy = phy->sas_phy.phy; in get_lrate_mode()
43 phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS; in get_lrate_mode()
44 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS; in get_lrate_mode()
47 phy->sas_phy.linkrate = SAS_LINK_RATE_3_0_GBPS; in get_lrate_mode()
48 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS; in get_lrate_mode()
51 phy->sas_phy.linkrate = SAS_LINK_RATE_1_5_GBPS; in get_lrate_mode()
52 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS; in get_lrate_mode()
55 sas_phy->negotiated_linkrate = phy->sas_phy.linkrate; in get_lrate_mode()
56 sas_phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS; in get_lrate_mode()
57 sas_phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; in get_lrate_mode()
58 sas_phy->maximum_linkrate = phy->phy_desc->max_sas_lrate; in get_lrate_mode()
59 sas_phy->minimum_linkrate = phy->phy_desc->min_sas_lrate; in get_lrate_mode()
62 phy->sas_phy.oob_mode = SAS_OOB_MODE; in get_lrate_mode()
64 phy->sas_phy.oob_mode = SATA_OOB_MODE; in get_lrate_mode()
70 struct asd_ha_struct *asd_ha = ascb->ha; in asd_phy_event_tasklet()
71 int phy_id = dl->status_block[0] & DL_PHY_MASK; in asd_phy_event_tasklet()
72 struct asd_phy *phy = &asd_ha->phys[phy_id]; in asd_phy_event_tasklet()
74 u8 oob_status = dl->status_block[1] & PHY_EVENTS_STATUS; in asd_phy_event_tasklet()
75 u8 oob_mode = dl->status_block[2]; in asd_phy_event_tasklet()
82 sas_phy_disconnected(&phy->sas_phy); in asd_phy_event_tasklet()
83 sas_notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL, in asd_phy_event_tasklet()
91 phy_id, phy->sas_phy.linkrate, phy->sas_phy.iproto); in asd_phy_event_tasklet()
92 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC); in asd_phy_event_tasklet()
95 /* hot plug SATA, no COMWAKE sent */ in asd_phy_event_tasklet()
97 sas_notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD, in asd_phy_event_tasklet()
102 ASD_DPRINTK("phy%d error while OOB: oob status:0x%x\n", phy_id, in asd_phy_event_tasklet()
103 dl->status_block[1]); in asd_phy_event_tasklet()
105 sas_phy_disconnected(&phy->sas_phy); in asd_phy_event_tasklet()
106 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR, GFP_ATOMIC); in asd_phy_event_tasklet()
114 u8 enabled_mask = asd_ha->hw_prof.enabled_phys; in ord_phy()
118 if (&asd_ha->phys[i] == phy) in ord_phy()
126 * asd_get_attached_sas_addr -- extract/generate attached SAS address
131 * received. If OOB is SATA, then a SAS address is generated from the
139 if (phy->sas_phy.frame_rcvd[0] == 0x34 in asd_get_attached_sas_addr()
140 && phy->sas_phy.oob_mode == SATA_OOB_MODE) { in asd_get_attached_sas_addr()
141 struct asd_ha_struct *asd_ha = phy->sas_phy.ha->lldd_ha; in asd_get_attached_sas_addr()
142 /* FIS device-to-host */ in asd_get_attached_sas_addr()
143 u64 addr = be64_to_cpu(*(__be64 *)phy->phy_desc->sas_addr); in asd_get_attached_sas_addr()
145 addr += asd_ha->hw_prof.sata_name_base + ord_phy(asd_ha, phy); in asd_get_attached_sas_addr()
149 (void *) phy->sas_phy.frame_rcvd; in asd_get_attached_sas_addr()
150 memcpy(sas_addr, idframe->sas_addr, SAS_ADDR_SIZE); in asd_get_attached_sas_addr()
159 struct asd_sas_phy *sas_phy = &phy->sas_phy; in asd_form_port()
162 spin_lock_irqsave(&asd_ha->asd_ports_lock, flags); in asd_form_port()
163 if (!phy->asd_port) { in asd_form_port()
165 port = &asd_ha->asd_ports[i]; in asd_form_port()
168 if (port->num_phys > 0 && in asd_form_port()
169 memcmp(port->sas_addr, sas_phy->sas_addr, in asd_form_port()
171 memcmp(port->attached_sas_addr, in asd_form_port()
172 sas_phy->attached_sas_addr, in asd_form_port()
178 if (port->num_phys == 0 && free_port == NULL) { in asd_form_port()
187 memcpy(port->sas_addr, sas_phy->sas_addr, in asd_form_port()
189 memcpy(port->attached_sas_addr, in asd_form_port()
190 sas_phy->attached_sas_addr, in asd_form_port()
193 port->num_phys++; in asd_form_port()
194 port->phy_mask |= (1U << sas_phy->id); in asd_form_port()
195 phy->asd_port = port; in asd_form_port()
198 __func__, phy->asd_port->phy_mask, sas_phy->id); in asd_form_port()
200 spin_unlock_irqrestore(&asd_ha->asd_ports_lock, flags); in asd_form_port()
205 struct asd_port *port = phy->asd_port; in asd_deform_port()
206 struct asd_sas_phy *sas_phy = &phy->sas_phy; in asd_deform_port()
209 spin_lock_irqsave(&asd_ha->asd_ports_lock, flags); in asd_deform_port()
211 port->num_phys--; in asd_deform_port()
212 port->phy_mask &= ~(1U << sas_phy->id); in asd_deform_port()
213 phy->asd_port = NULL; in asd_deform_port()
215 spin_unlock_irqrestore(&asd_ha->asd_ports_lock, flags); in asd_deform_port()
223 int edb_el = edb_id + ascb->edb_index; in asd_bytes_dmaed_tasklet()
224 struct asd_dma_tok *edb = ascb->ha->seq.edb_arr[edb_el]; in asd_bytes_dmaed_tasklet()
225 struct asd_phy *phy = &ascb->ha->phys[phy_id]; in asd_bytes_dmaed_tasklet()
226 u16 size = ((dl->status_block[3] & 7) << 8) | dl->status_block[2]; in asd_bytes_dmaed_tasklet()
228 size = min(size, (u16) sizeof(phy->frame_rcvd)); in asd_bytes_dmaed_tasklet()
230 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags); in asd_bytes_dmaed_tasklet()
231 memcpy(phy->sas_phy.frame_rcvd, edb->vaddr, size); in asd_bytes_dmaed_tasklet()
232 phy->sas_phy.frame_rcvd_size = size; in asd_bytes_dmaed_tasklet()
233 asd_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr); in asd_bytes_dmaed_tasklet()
234 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags); in asd_bytes_dmaed_tasklet()
236 asd_form_port(ascb->ha, phy); in asd_bytes_dmaed_tasklet()
237 sas_notify_port_event(&phy->sas_phy, PORTE_BYTES_DMAED, GFP_ATOMIC); in asd_bytes_dmaed_tasklet()
244 struct asd_ha_struct *asd_ha = ascb->ha; in asd_link_reset_err_tasklet()
245 struct sas_ha_struct *sas_ha = &asd_ha->sas_ha; in asd_link_reset_err_tasklet()
246 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id]; in asd_link_reset_err_tasklet()
247 struct asd_phy *phy = &asd_ha->phys[phy_id]; in asd_link_reset_err_tasklet()
248 u8 lr_error = dl->status_block[1]; in asd_link_reset_err_tasklet()
249 u8 retries_left = dl->status_block[2]; in asd_link_reset_err_tasklet()
277 struct asd_ascb *cp = asd_ascb_alloc_list(ascb->ha, &num, in asd_link_reset_err_tasklet()
286 if (asd_post_ascb_list(ascb->ha, cp, 1) != 0) in asd_link_reset_err_tasklet()
298 struct sas_ha_struct *sas_ha = &ascb->ha->sas_ha; in asd_primitive_rcvd_tasklet()
299 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id]; in asd_primitive_rcvd_tasklet()
300 struct asd_ha_struct *asd_ha = ascb->ha; in asd_primitive_rcvd_tasklet()
301 struct asd_phy *phy = &asd_ha->phys[phy_id]; in asd_primitive_rcvd_tasklet()
302 u8 reg = dl->status_block[1]; in asd_primitive_rcvd_tasklet()
303 u32 cont = dl->status_block[2] << ((reg & 3)*8); in asd_primitive_rcvd_tasklet()
315 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags); in asd_primitive_rcvd_tasklet()
316 sas_phy->sas_prim = ffs(cont); in asd_primitive_rcvd_tasklet()
317 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags); in asd_primitive_rcvd_tasklet()
338 * We have to re-enable the phys ourselves. */ in asd_primitive_rcvd_tasklet()
352 dl->status_block[1]); in asd_primitive_rcvd_tasklet()
358 * asd_invalidate_edb -- invalidate an EDB and if necessary post the ESCB
368 struct asd_seq_data *seq = &ascb->ha->seq; in asd_invalidate_edb()
369 struct empty_scb *escb = &ascb->scb->escb; in asd_invalidate_edb()
370 struct sg_el *eb = &escb->eb[edb_id]; in asd_invalidate_edb()
371 struct asd_dma_tok *edb = seq->edb_arr[ascb->edb_index + edb_id]; in asd_invalidate_edb()
373 memset(edb->vaddr, 0, ASD_EDB_SIZE); in asd_invalidate_edb()
374 eb->flags |= ELEMENT_NOT_VALID; in asd_invalidate_edb()
375 escb->num_valid--; in asd_invalidate_edb()
377 if (escb->num_valid == 0) { in asd_invalidate_edb()
382 ascb->dma_scb.vaddr, in asd_invalidate_edb()
383 (u64)ascb->dma_scb.dma_handle, in asd_invalidate_edb()
384 le64_to_cpu(ascb->scb->header.next_scb), in asd_invalidate_edb()
385 le16_to_cpu(ascb->scb->header.index), in asd_invalidate_edb()
386 ascb->scb->header.opcode); in asd_invalidate_edb()
388 escb->num_valid = ASD_EDBS_PER_SCB; in asd_invalidate_edb()
390 escb->eb[i].flags = 0; in asd_invalidate_edb()
391 if (!list_empty(&ascb->list)) in asd_invalidate_edb()
392 list_del_init(&ascb->list); in asd_invalidate_edb()
393 i = asd_post_escb_list(ascb->ha, ascb, 1); in asd_invalidate_edb()
402 struct asd_ha_struct *asd_ha = ascb->ha; in escb_tasklet_complete()
403 struct sas_ha_struct *sas_ha = &asd_ha->sas_ha; in escb_tasklet_complete()
404 int edb = (dl->opcode & DL_PHY_MASK) - 1; /* [0xc1,0xc7] -> [0,6] */ in escb_tasklet_complete()
405 u8 sb_opcode = dl->status_block[0]; in escb_tasklet_complete()
407 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id]; in escb_tasklet_complete()
408 struct asd_phy *phy = &asd_ha->phys[phy_id]; in escb_tasklet_complete()
411 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n", in escb_tasklet_complete()
412 edb, dl->opcode); in escb_tasklet_complete()
418 ascb->dma_scb.vaddr, in escb_tasklet_complete()
419 (unsigned long long)ascb->dma_scb.dma_handle, in escb_tasklet_complete()
421 le64_to_cpu(ascb->scb->header.next_scb), in escb_tasklet_complete()
422 le16_to_cpu(ascb->scb->header.index), in escb_tasklet_complete()
423 ascb->scb->header.opcode); in escb_tasklet_complete()
434 __func__, dl->status_block[3]); in escb_tasklet_complete()
441 tc_abort = *((u16*)(&dl->status_block[1])); in escb_tasklet_complete()
444 list_for_each_entry_safe(a, b, &asd_ha->seq.pend_q, list) { in escb_tasklet_complete()
445 struct sas_task *task = a->uldd_task; in escb_tasklet_complete()
447 if (a->tc_index != tc_abort) in escb_tasklet_complete()
451 failed_dev = task->dev; in escb_tasklet_complete()
455 a->scb->header.opcode); in escb_tasklet_complete()
470 list_for_each_entry_safe(a, b, &asd_ha->seq.pend_q, list) { in escb_tasklet_complete()
471 struct sas_task *task = a->uldd_task; in escb_tasklet_complete()
474 task->dev == failed_dev && in escb_tasklet_complete()
475 a->tc_index != tc_abort) in escb_tasklet_complete()
487 conn_handle = *((u16*)(&dl->status_block[1])); in escb_tasklet_complete()
491 dl->status_block[3]); in escb_tasklet_complete()
494 list_for_each_entry(a, &asd_ha->seq.pend_q, list) { in escb_tasklet_complete()
497 struct sas_task *task = a->uldd_task; in escb_tasklet_complete()
501 dev = task->dev; in escb_tasklet_complete()
503 x = (unsigned long)dev->lldd_dev; in escb_tasklet_complete()
515 spin_lock_irqsave(&last_dev_task->task_state_lock, flags); in escb_tasklet_complete()
516 last_dev_task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; in escb_tasklet_complete()
517 spin_unlock_irqrestore(&last_dev_task->task_state_lock, flags); in escb_tasklet_complete()
520 list_for_each_entry(a, &asd_ha->seq.pend_q, list) { in escb_tasklet_complete()
523 struct sas_task *task = a->uldd_task; in escb_tasklet_complete()
527 dev = task->dev; in escb_tasklet_complete()
529 x = (unsigned long)dev->lldd_dev; in escb_tasklet_complete()
577 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n", in escb_tasklet_complete()
578 edb, dl->opcode); in escb_tasklet_complete()
584 ascb->dma_scb.vaddr, in escb_tasklet_complete()
585 (unsigned long long)ascb->dma_scb.dma_handle, in escb_tasklet_complete()
587 le64_to_cpu(ascb->scb->header.next_scb), in escb_tasklet_complete()
588 le16_to_cpu(ascb->scb->header.index), in escb_tasklet_complete()
589 ascb->scb->header.opcode); in escb_tasklet_complete()
599 struct asd_seq_data *seq = &asd_ha->seq; in asd_init_post_escbs()
602 for (i = 0; i < seq->num_escbs; i++) in asd_init_post_escbs()
603 seq->escb_arr[i]->tasklet_complete = escb_tasklet_complete; in asd_init_post_escbs()
606 return asd_post_escb_list(asd_ha, seq->escb_arr[0], seq->num_escbs); in asd_init_post_escbs()
609 /* ---------- CONTROL PHY ---------- */
616 * control_phy_tasklet_complete -- tasklet complete for CONTROL PHY ascb
622 * - an LED blinks if there is IO though it,
623 * - if a device is connected to the LED, it is lit,
624 * - if no device is connected to the LED, is is dimmed (off).
629 struct asd_ha_struct *asd_ha = ascb->ha; in control_phy_tasklet_complete()
630 struct scb *scb = ascb->scb; in control_phy_tasklet_complete()
631 struct control_phy *control_phy = &scb->control_phy; in control_phy_tasklet_complete()
632 u8 phy_id = control_phy->phy_id; in control_phy_tasklet_complete()
633 struct asd_phy *phy = &ascb->ha->phys[phy_id]; in control_phy_tasklet_complete()
635 u8 status = dl->status_block[0]; in control_phy_tasklet_complete()
636 u8 oob_status = dl->status_block[1]; in control_phy_tasklet_complete()
637 u8 oob_mode = dl->status_block[2]; in control_phy_tasklet_complete()
638 /* u8 oob_signals= dl->status_block[3]; */ in control_phy_tasklet_complete()
646 switch (control_phy->sub_func) { in control_phy_tasklet_complete()
648 asd_ha->hw_prof.enabled_phys &= ~(1 << phy_id); in control_phy_tasklet_complete()
657 asd_ha->hw_prof.enabled_phys |= (1 << phy_id); in control_phy_tasklet_complete()
661 __func__, phy_id,phy->sas_phy.linkrate, in control_phy_tasklet_complete()
662 phy->sas_phy.iproto); in control_phy_tasklet_complete()
664 asd_ha->hw_prof.enabled_phys |= (1 << phy_id); in control_phy_tasklet_complete()
670 ASD_DPRINTK("%s: phy%d: error: oob status:0x%02x\n", in control_phy_tasklet_complete()
674 asd_ha->hw_prof.enabled_phys |= (1 << phy_id); in control_phy_tasklet_complete()
679 asd_ha->hw_prof.enabled_phys |= (1 << phy_id); in control_phy_tasklet_complete()
690 phy_id, control_phy->sub_func); in control_phy_tasklet_complete()
695 phy_id, control_phy->sub_func); in control_phy_tasklet_complete()
708 switch (pd->max_sas_lrate) { in set_speed_mask()
720 switch (pd->min_sas_lrate) { in set_speed_mask()
733 switch (pd->max_sata_lrate) { in set_speed_mask()
742 switch (pd->min_sata_lrate) { in set_speed_mask()
754 * asd_build_control_phy -- build a CONTROL PHY SCB
761 * The caller can override the ascb->tasklet_complete to point
768 struct asd_phy *phy = &ascb->ha->phys[phy_id]; in asd_build_control_phy()
769 struct scb *scb = ascb->scb; in asd_build_control_phy()
770 struct control_phy *control_phy = &scb->control_phy; in asd_build_control_phy()
772 scb->header.opcode = CONTROL_PHY; in asd_build_control_phy()
773 control_phy->phy_id = (u8) phy_id; in asd_build_control_phy()
774 control_phy->sub_func = subfunc; in asd_build_control_phy()
780 control_phy->hot_plug_delay = HOTPLUG_DELAY_TIMEOUT; in asd_build_control_phy()
783 set_speed_mask(&control_phy->speed_mask, phy->phy_desc); in asd_build_control_phy()
786 if (phy->sas_phy.role == PHY_ROLE_INITIATOR) in asd_build_control_phy()
787 control_phy->port_type = SAS_PROTOCOL_ALL << 4; in asd_build_control_phy()
788 else if (phy->sas_phy.role == PHY_ROLE_TARGET) in asd_build_control_phy()
789 control_phy->port_type = SAS_PROTOCOL_ALL; in asd_build_control_phy()
791 control_phy->port_type = in asd_build_control_phy()
795 control_phy->link_reset_retries = 10; in asd_build_control_phy()
800 control_phy->func_mask = FUNCTION_MASK_DEFAULT; in asd_build_control_phy()
801 if (phy->phy_desc->flags & ASD_SATA_SPINUP_HOLD) in asd_build_control_phy()
802 control_phy->func_mask &= ~SPINUP_HOLD_DIS; in asd_build_control_phy()
804 control_phy->func_mask |= SPINUP_HOLD_DIS; in asd_build_control_phy()
807 control_phy->conn_handle = cpu_to_le16(0xFFFF); in asd_build_control_phy()
809 ascb->tasklet_complete = control_phy_tasklet_complete; in asd_build_control_phy()
812 /* ---------- INITIATE LINK ADM TASK ---------- */
819 u8 opcode = dl->opcode;
820 struct initiate_link_adm *link_adm = &ascb->scb->link_adm;
821 u8 phy_id = link_adm->phy_id;
825 "0x%x\n", phy_id, link_adm->sub_func, opcode);
828 phy_id, link_adm->sub_func, opcode);
836 struct scb *scb = ascb->scb;
837 struct initiate_link_adm *link_adm = &scb->link_adm;
839 scb->header.opcode = INITIATE_LINK_ADM_TASK;
841 link_adm->phy_id = phy_id;
842 link_adm->sub_func = subfunc;
843 link_adm->conn_handle = cpu_to_le16(0xFFFF);
845 ascb->tasklet_complete = link_adm_tasklet_complete;
850 /* ---------- SCB timer ---------- */
853 * asd_ascb_timedout -- called when a pending SCB's timer has expired
860 * the ascb->timer.{function, expires} prior to calling the post
866 struct asd_seq_data *seq = &ascb->ha->seq; in asd_ascb_timedout()
869 ASD_DPRINTK("scb:0x%x timed out\n", ascb->scb->header.opcode); in asd_ascb_timedout()
871 spin_lock_irqsave(&seq->pend_q_lock, flags); in asd_ascb_timedout()
872 seq->pending--; in asd_ascb_timedout()
873 list_del_init(&ascb->list); in asd_ascb_timedout()
874 spin_unlock_irqrestore(&seq->pend_q_lock, flags); in asd_ascb_timedout()
879 /* ---------- CONTROL PHY ---------- */
892 struct asd_ha_struct *asd_ha = phy->ha->lldd_ha; in asd_control_phy()
893 struct asd_phy_desc *pd = asd_ha->phys[phy->id].phy_desc; in asd_control_phy()
901 return -ENOSYS; in asd_control_phy()
904 if (rates->minimum_linkrate) { in asd_control_phy()
905 pd->min_sas_lrate = rates->minimum_linkrate; in asd_control_phy()
906 pd->min_sata_lrate = rates->minimum_linkrate; in asd_control_phy()
908 if (rates->maximum_linkrate) { in asd_control_phy()
909 pd->max_sas_lrate = rates->maximum_linkrate; in asd_control_phy()
910 pd->max_sata_lrate = rates->maximum_linkrate; in asd_control_phy()
920 return -ENOMEM; in asd_control_phy()
922 asd_build_control_phy(ascb, phy->id, phy_func_table[func]); in asd_control_phy()