static int asd_clear_nexus(struct sas_task *task) { int res = TMF_RESP_FUNC_FAILED; int leftover; struct asd_ascb *tascb = task->lldd_task; DECLARE_COMPLETION_ONSTACK(completion); unsigned long flags; tascb->completion = &completion; ASD_DPRINTK("task not done, clearing nexus\n"); if (tascb->tag_valid) res = asd_clear_nexus_tag(task); else res = asd_clear_nexus_index(task); leftover = wait_for_completion_timeout(&completion, AIC94XX_SCB_TIMEOUT); tascb->completion = NULL; ASD_DPRINTK("came back from clear nexus\n"); spin_lock_irqsave(&task->task_state_lock, flags); if (leftover < 1) res = TMF_RESP_FUNC_FAILED; if (task->task_state_flags & SAS_TASK_STATE_DONE) res = TMF_RESP_FUNC_COMPLETE; spin_unlock_irqrestore(&task->task_state_lock, flags); return res; }
static void asd_clear_nexus_tasklet_complete(struct asd_ascb *ascb, struct done_list_struct *dl) { ASD_DPRINTK("%s: here\n", __FUNCTION__); if (!del_timer(&ascb->timer)) { ASD_DPRINTK("%s: couldn't delete timer\n", __FUNCTION__); return; } ASD_DPRINTK("%s: opcode: 0x%x\n", __FUNCTION__, dl->opcode); ascb->uldd_task = (void *) (unsigned long) dl->opcode; complete(&ascb->completion); }
static void asd_clear_nexus_tasklet_complete(struct asd_ascb *ascb, struct done_list_struct *dl) { struct tasklet_completion_status *tcs = ascb->uldd_task; ASD_DPRINTK("%s: here\n", __func__); if (!del_timer(&ascb->timer)) { ASD_DPRINTK("%s: couldn't delete timer\n", __func__); return; } ASD_DPRINTK("%s: opcode: 0x%x\n", __func__, dl->opcode); tcs->dl_opcode = dl->opcode; complete(ascb->completion); asd_ascb_free(ascb); }
int asd_I_T_nexus_reset(struct domain_device *dev) { int res, tmp_res, i; struct sas_phy *phy = sas_find_local_phy(dev); /* Standard mandates link reset for ATA (type 0) and * hard reset for SSP (type 1) */ int reset_type = (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) ? 0 : 1; asd_clear_nexus_I_T(dev, NEXUS_PHASE_PRE); /* send a hard reset */ ASD_DPRINTK("sending %s reset to %s\n", reset_type ? "hard" : "soft", dev_name(&phy->dev)); res = sas_phy_reset(phy, reset_type); if (res == TMF_RESP_FUNC_COMPLETE) { /* wait for the maximum settle time */ msleep(500); /* clear all outstanding commands (keep nexus suspended) */ asd_clear_nexus_I_T(dev, NEXUS_PHASE_POST); } for (i = 0 ; i < 3; i++) { tmp_res = asd_clear_nexus_I_T(dev, NEXUS_PHASE_RESUME); if (tmp_res == TC_RESUME) return res; msleep(500); } /* This is a bit of a problem: the sequencer is still suspended * and is refusing to resume. Hope it will resume on a bigger hammer * or the disk is lost */ dev_printk(KERN_ERR, &phy->dev, "Failed to resume nexus after reset 0x%x\n", tmp_res); return TMF_RESP_FUNC_FAILED; }
int asd_I_T_nexus_reset(struct domain_device *dev) { int res, tmp_res, i; struct sas_phy *phy = sas_get_local_phy(dev); int reset_type = (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) ? 0 : 1; asd_clear_nexus_I_T(dev, NEXUS_PHASE_PRE); ASD_DPRINTK("sending %s reset to %s\n", reset_type ? "hard" : "soft", dev_name(&phy->dev)); res = sas_phy_reset(phy, reset_type); if (res == TMF_RESP_FUNC_COMPLETE || res == -ENODEV) { msleep(500); asd_clear_nexus_I_T(dev, NEXUS_PHASE_POST); } for (i = 0 ; i < 3; i++) { tmp_res = asd_clear_nexus_I_T(dev, NEXUS_PHASE_RESUME); if (tmp_res == TC_RESUME) goto out; msleep(500); } dev_printk(KERN_ERR, &phy->dev, "Failed to resume nexus after reset 0x%x\n", tmp_res); res = TMF_RESP_FUNC_FAILED; out: sas_put_local_phy(phy); return res; }
static int asd_get_tmf_resp_tasklet(struct asd_ascb *ascb, struct done_list_struct *dl) { struct asd_ha_struct *asd_ha = ascb->ha; unsigned long flags; struct tc_resp_sb_struct { __le16 index_escb; u8 len_lsb; u8 flags; } __attribute__ ((packed)) *resp_sb = (void *) dl->status_block; int edb_id = ((resp_sb->flags & 0x70) >> 4)-1; struct asd_ascb *escb; struct asd_dma_tok *edb; struct ssp_frame_hdr *fh; struct ssp_response_iu *ru; int res = TMF_RESP_FUNC_FAILED; ASD_DPRINTK("tmf resp tasklet\n"); spin_lock_irqsave(&asd_ha->seq.tc_index_lock, flags); escb = asd_tc_index_find(&asd_ha->seq, (int)le16_to_cpu(resp_sb->index_escb)); spin_unlock_irqrestore(&asd_ha->seq.tc_index_lock, flags); if (!escb) { ASD_DPRINTK("Uh-oh! No escb for this dl?!\n"); return res; } edb = asd_ha->seq.edb_arr[edb_id + escb->edb_index]; ascb->tag = *(__be16 *)(edb->vaddr+4); fh = edb->vaddr + 16; ru = edb->vaddr + 16 + sizeof(*fh); res = ru->status; if (ru->datapres == 1) /* Response data present */ res = ru->resp_data[3]; #if 0 ascb->tag = fh->tag; #endif ascb->tag_valid = 1; asd_invalidate_edb(escb, edb_id); return res; }
static void asd_clear_nexus_timedout(unsigned long data) { struct asd_ascb *ascb = (void *)data; struct tasklet_completion_status *tcs = ascb->uldd_task; ASD_DPRINTK("%s: here\n", __func__); tcs->dl_opcode = TMF_RESP_FUNC_FAILED; complete(ascb->completion); }
static void asd_clear_nexus_timedout(unsigned long data) { struct asd_ascb *ascb = (void *) data; ASD_DPRINTK("%s: here\n", __FUNCTION__); asd_timedout_common(data); ascb->uldd_task = (void *) TMF_RESP_FUNC_FAILED; complete(&ascb->completion); }
static void asd_tmf_timedout(unsigned long data) { struct asd_ascb *ascb = (void *) data; struct tasklet_completion_status *tcs = ascb->uldd_task; ASD_DPRINTK("tmf timed out\n"); tcs->tmf_state = TMF_RESP_FUNC_FAILED; complete(ascb->completion); }
static void asd_tmf_timedout(unsigned long data) { struct asd_ascb *ascb = (void *) data; ASD_DPRINTK("tmf timed out\n"); asd_timedout_common(data); ascb->uldd_task = (void *) TMF_RESP_FUNC_FAILED; complete(&ascb->completion); }
static void asd_tmf_tasklet_complete(struct asd_ascb *ascb, struct done_list_struct *dl) { if (!del_timer(&ascb->timer)) return; ASD_DPRINTK("tmf tasklet complete\n"); if (dl->opcode == TC_SSP_RESP) ascb->uldd_task = (void *) (unsigned long) asd_get_tmf_resp_tasklet(ascb, dl); else ascb->uldd_task = (void *) 0xFF00 + (unsigned long) dl->opcode; complete(&ascb->completion); }
/** * asd_unpause_cseq - unpause the central sequencer. * @asd_ha: pointer to host adapter structure. * * Return 0 on success, negative on error. */ int asd_unpause_cseq(struct asd_ha_struct *asd_ha) { u32 arp2ctl; int count = PAUSE_TRIES; arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL); if (!(arp2ctl & PAUSED)) return 0; asd_write_reg_dword(asd_ha, CARP2CTL, arp2ctl & ~EPAUSE); do { arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL); if (!(arp2ctl & PAUSED)) return 0; udelay(PAUSE_DELAY); } while (--count > 0); ASD_DPRINTK("couldn't unpause the CSEQ\n"); return -1; }
/** * asd_seq_pause_lseq - pause a link sequencer * @asd_ha: pointer to a host adapter structure * @lseq: link sequencer of interest * * Return 0 on success, negative on error. */ static inline int asd_seq_pause_lseq(struct asd_ha_struct *asd_ha, int lseq) { u32 arp2ctl; int count = PAUSE_TRIES; arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq)); if (arp2ctl & PAUSED) return 0; asd_write_reg_dword(asd_ha, LmARP2CTL(lseq), arp2ctl | EPAUSE); do { arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq)); if (arp2ctl & PAUSED) return 0; udelay(PAUSE_DELAY); } while (--count > 0); ASD_DPRINTK("couldn't pause LSEQ %d\n", lseq); return -1; }
static void asd_tmf_tasklet_complete(struct asd_ascb *ascb, struct done_list_struct *dl) { struct tasklet_completion_status *tcs; if (!del_timer(&ascb->timer)) return; tcs = ascb->uldd_task; ASD_DPRINTK("tmf tasklet complete\n"); tcs->dl_opcode = dl->opcode; if (dl->opcode == TC_SSP_RESP) { tcs->tmf_state = asd_get_tmf_resp_tasklet(ascb, dl); tcs->tag_valid = ascb->tag_valid; tcs->tag = ascb->tag; } complete(ascb->completion); asd_ascb_free(ascb); }
static void asd_get_response_tasklet(struct asd_ascb *ascb, struct done_list_struct *dl) { struct asd_ha_struct *asd_ha = ascb->ha; struct sas_task *task = ascb->uldd_task; struct task_status_struct *ts = &task->task_status; unsigned long flags; struct tc_resp_sb_struct { __le16 index_escb; u8 len_lsb; u8 flags; } __attribute__ ((packed)) *resp_sb = (void *) dl->status_block; /* int size = ((resp_sb->flags & 7) << 8) | resp_sb->len_lsb; */ int edb_id = ((resp_sb->flags & 0x70) >> 4)-1; struct asd_ascb *escb; struct asd_dma_tok *edb; void *r; spin_lock_irqsave(&asd_ha->seq.tc_index_lock, flags); escb = asd_tc_index_find(&asd_ha->seq, (int)le16_to_cpu(resp_sb->index_escb)); spin_unlock_irqrestore(&asd_ha->seq.tc_index_lock, flags); if (!escb) { ASD_DPRINTK("Uh-oh! No escb for this dl?!\n"); return; } ts->buf_valid_size = 0; edb = asd_ha->seq.edb_arr[edb_id + escb->edb_index]; r = edb->vaddr; if (task->task_proto == SAS_PROTO_SSP) { struct ssp_response_iu *iu = r + 16 + sizeof(struct ssp_frame_hdr); ts->residual = le32_to_cpu(*(__le32 *)r); ts->resp = SAS_TASK_COMPLETE; if (iu->datapres == 0) ts->stat = iu->status; else if (iu->datapres == 1) ts->stat = iu->resp_data[3]; else if (iu->datapres == 2) { ts->stat = SAM_CHECK_COND; ts->buf_valid_size = min((u32) SAS_STATUS_BUF_SIZE, be32_to_cpu(iu->sense_data_len)); memcpy(ts->buf, iu->sense_data, ts->buf_valid_size); if (iu->status != SAM_CHECK_COND) { ASD_DPRINTK("device %llx sent sense data, but " "stat(0x%x) is not CHECK_CONDITION" "\n", SAS_ADDR(task->dev->sas_addr), ts->stat); } } } else { struct ata_task_resp *resp = (void *) &ts->buf[0]; ts->residual = le32_to_cpu(*(__le32 *)r); if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) { resp->frame_len = le16_to_cpu(*(__le16 *)(r+6)); memcpy(&resp->ending_fis[0], r+16, 24); ts->buf_valid_size = sizeof(*resp); } } asd_invalidate_edb(escb, edb_id); }
static ssize_t asd_store_update_bios(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct asd_ha_struct *asd_ha = dev_to_asd_ha(dev); char *cmd_ptr, *filename_ptr; struct bios_file_header header, *hdr_ptr; int res, i; u32 csum = 0; int flash_command = FLASH_CMD_NONE; int err = 0; cmd_ptr = kcalloc(count, 2, GFP_KERNEL); if (!cmd_ptr) { err = FAIL_OUT_MEMORY; goto out; } filename_ptr = cmd_ptr + count; res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr); if (res != 2) { err = FAIL_PARAMETERS; goto out1; } for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) { if (!memcmp(flash_command_table[i].command, cmd_ptr, strlen(cmd_ptr))) { flash_command = flash_command_table[i].code; break; } } if (flash_command == FLASH_CMD_NONE) { err = FAIL_PARAMETERS; goto out1; } if (asd_ha->bios_status == FLASH_IN_PROGRESS) { err = FLASH_IN_PROGRESS; goto out1; } err = request_firmware(&asd_ha->bios_image, filename_ptr, &asd_ha->pcidev->dev); if (err) { asd_printk("Failed to load bios image file %s, error %d\n", filename_ptr, err); err = FAIL_OPEN_BIOS_FILE; goto out1; } hdr_ptr = (struct bios_file_header *)asd_ha->bios_image->data; if ((hdr_ptr->contrl_id.vendor != asd_ha->pcidev->vendor || hdr_ptr->contrl_id.device != asd_ha->pcidev->device) && (hdr_ptr->contrl_id.sub_vendor != asd_ha->pcidev->vendor || hdr_ptr->contrl_id.sub_device != asd_ha->pcidev->device)) { ASD_DPRINTK("The PCI vendor or device id does not match\n"); ASD_DPRINTK("vendor=%x dev=%x sub_vendor=%x sub_dev=%x" " pci vendor=%x pci dev=%x\n", hdr_ptr->contrl_id.vendor, hdr_ptr->contrl_id.device, hdr_ptr->contrl_id.sub_vendor, hdr_ptr->contrl_id.sub_device, asd_ha->pcidev->vendor, asd_ha->pcidev->device); err = FAIL_CHECK_PCI_ID; goto out2; } if (hdr_ptr->filelen != asd_ha->bios_image->size) { err = FAIL_FILE_SIZE; goto out2; } /* calculate checksum */ for (i = 0; i < hdr_ptr->filelen; i++) csum += asd_ha->bios_image->data[i]; if ((csum & 0x0000ffff) != hdr_ptr->checksum) { ASD_DPRINTK("BIOS file checksum mismatch\n"); err = FAIL_CHECK_SUM; goto out2; } if (flash_command == FLASH_CMD_UPDATE) { asd_ha->bios_status = FLASH_IN_PROGRESS; err = asd_write_flash_seg(asd_ha, &asd_ha->bios_image->data[sizeof(*hdr_ptr)], 0, hdr_ptr->filelen-sizeof(*hdr_ptr)); if (!err) err = asd_verify_flash_seg(asd_ha, &asd_ha->bios_image->data[sizeof(*hdr_ptr)], 0, hdr_ptr->filelen-sizeof(*hdr_ptr)); } else { asd_ha->bios_status = FLASH_IN_PROGRESS; err = asd_verify_flash_seg(asd_ha, &asd_ha->bios_image->data[sizeof(header)], 0, hdr_ptr->filelen-sizeof(header)); } out2: release_firmware(asd_ha->bios_image); out1: kfree(cmd_ptr); out: asd_ha->bios_status = err; if (!err) return count; else return -err; }
/** * asd_abort_task -- ABORT TASK TMF * @task: the task to be aborted * * Before calling ABORT TASK the task state flags should be ORed with * SAS_TASK_STATE_ABORTED (unless SAS_TASK_STATE_DONE is set) under * the task_state_lock IRQ spinlock, then ABORT TASK *must* be called. * * Implements the ABORT TASK TMF, I_T_L_Q nexus. * Returns: SAS TMF responses (see sas_task.h), * -ENOMEM, * -SAS_QUEUE_FULL. * * When ABORT TASK returns, the caller of ABORT TASK checks first the * task->task_state_flags, and then the return value of ABORT TASK. * * If the task has task state bit SAS_TASK_STATE_DONE set, then the * task was completed successfully prior to it being aborted. The * caller of ABORT TASK has responsibility to call task->task_done() * xor free the task, depending on their framework. The return code * is TMF_RESP_FUNC_FAILED in this case. * * Else the SAS_TASK_STATE_DONE bit is not set, * If the return code is TMF_RESP_FUNC_COMPLETE, then * the task was aborted successfully. The caller of * ABORT TASK has responsibility to call task->task_done() * to finish the task, xor free the task depending on their * framework. * else * the ABORT TASK returned some kind of error. The task * was _not_ cancelled. Nothing can be assumed. * The caller of ABORT TASK may wish to retry. */ int asd_abort_task(struct sas_task *task) { struct asd_ascb *tascb = task->lldd_task; struct asd_ha_struct *asd_ha = tascb->ha; int res = 1; unsigned long flags; struct asd_ascb *ascb = NULL; struct scb *scb; int leftover; spin_lock_irqsave(&task->task_state_lock, flags); if (task->task_state_flags & SAS_TASK_STATE_DONE) { spin_unlock_irqrestore(&task->task_state_lock, flags); res = TMF_RESP_FUNC_COMPLETE; ASD_DPRINTK("%s: task 0x%p done\n", __FUNCTION__, task); goto out_done; } spin_unlock_irqrestore(&task->task_state_lock, flags); ascb = asd_ascb_alloc_list(asd_ha, &res, GFP_KERNEL); if (!ascb) return -ENOMEM; scb = ascb->scb; scb->header.opcode = ABORT_TASK; switch (task->task_proto) { case SAS_PROTOCOL_SATA: case SAS_PROTOCOL_STP: scb->abort_task.proto_conn_rate = (1 << 5); /* STP */ break; case SAS_PROTOCOL_SSP: scb->abort_task.proto_conn_rate = (1 << 4); /* SSP */ scb->abort_task.proto_conn_rate |= task->dev->linkrate; break; case SAS_PROTOCOL_SMP: break; default: break; } if (task->task_proto == SAS_PROTOCOL_SSP) { scb->abort_task.ssp_frame.frame_type = SSP_TASK; memcpy(scb->abort_task.ssp_frame.hashed_dest_addr, task->dev->hashed_sas_addr, HASHED_SAS_ADDR_SIZE); memcpy(scb->abort_task.ssp_frame.hashed_src_addr, task->dev->port->ha->hashed_sas_addr, HASHED_SAS_ADDR_SIZE); scb->abort_task.ssp_frame.tptt = cpu_to_be16(0xFFFF); memcpy(scb->abort_task.ssp_task.lun, task->ssp_task.LUN, 8); scb->abort_task.ssp_task.tmf = TMF_ABORT_TASK; scb->abort_task.ssp_task.tag = cpu_to_be16(0xFFFF); } scb->abort_task.sister_scb = cpu_to_le16(0xFFFF); scb->abort_task.conn_handle = cpu_to_le16( (u16)(unsigned long)task->dev->lldd_dev); scb->abort_task.retry_count = 1; scb->abort_task.index = cpu_to_le16((u16)tascb->tc_index); scb->abort_task.itnl_to = cpu_to_le16(ITNL_TIMEOUT_CONST); res = asd_enqueue_internal(ascb, asd_tmf_tasklet_complete, asd_tmf_timedout); if (res) goto out; wait_for_completion(&ascb->completion); ASD_DPRINTK("tmf came back\n"); res = (int) (unsigned long) ascb->uldd_task; tascb->tag = ascb->tag; tascb->tag_valid = ascb->tag_valid; spin_lock_irqsave(&task->task_state_lock, flags); if (task->task_state_flags & SAS_TASK_STATE_DONE) { spin_unlock_irqrestore(&task->task_state_lock, flags); res = TMF_RESP_FUNC_COMPLETE; ASD_DPRINTK("%s: task 0x%p done\n", __FUNCTION__, task); goto out_done; } spin_unlock_irqrestore(&task->task_state_lock, flags); switch (res) { /* The task to be aborted has been sent to the device. * We got a Response IU for the ABORT TASK TMF. */ case TC_NO_ERROR + 0xFF00: case TMF_RESP_FUNC_COMPLETE: case TMF_RESP_FUNC_FAILED: res = asd_clear_nexus(task); break; case TMF_RESP_INVALID_FRAME: case TMF_RESP_OVERLAPPED_TAG: case TMF_RESP_FUNC_ESUPP: case TMF_RESP_NO_LUN: goto out_done; break; } /* In the following we assume that the managing layer * will _never_ make a mistake, when issuing ABORT TASK. */ switch (res) { default: res = asd_clear_nexus(task); /* fallthrough */ case TC_NO_ERROR + 0xFF00: case TMF_RESP_FUNC_COMPLETE: break; /* The task hasn't been sent to the device xor we never got * a (sane) Response IU for the ABORT TASK TMF. */ case TF_NAK_RECV + 0xFF00: res = TMF_RESP_INVALID_FRAME; break; case TF_TMF_TASK_DONE + 0xFF00: /* done but not reported yet */ res = TMF_RESP_FUNC_FAILED; leftover = wait_for_completion_timeout(&tascb->completion, AIC94XX_SCB_TIMEOUT); spin_lock_irqsave(&task->task_state_lock, flags); if (leftover < 1) res = TMF_RESP_FUNC_FAILED; if (task->task_state_flags & SAS_TASK_STATE_DONE) res = TMF_RESP_FUNC_COMPLETE; spin_unlock_irqrestore(&task->task_state_lock, flags); goto out_done; case TF_TMF_NO_TAG + 0xFF00: case TF_TMF_TAG_FREE + 0xFF00: /* the tag is in the free list */ case TF_TMF_NO_CONN_HANDLE + 0xFF00: /* no such device */ res = TMF_RESP_FUNC_COMPLETE; goto out_done; case TF_TMF_NO_CTX + 0xFF00: /* not in seq, or proto != SSP */ res = TMF_RESP_FUNC_ESUPP; goto out; } out_done: if (res == TMF_RESP_FUNC_COMPLETE) { task->lldd_task = NULL; mb(); asd_ascb_free(tascb); } out: asd_ascb_free(ascb); ASD_DPRINTK("task 0x%p aborted, res: 0x%x\n", task, res); return res; }
int asd_abort_task(struct sas_task *task) { struct asd_ascb *tascb = task->lldd_task; struct asd_ha_struct *asd_ha = tascb->ha; int res = 1; unsigned long flags; struct asd_ascb *ascb = NULL; struct scb *scb; int leftover; DECLARE_TCS(tcs); DECLARE_COMPLETION_ONSTACK(completion); DECLARE_COMPLETION_ONSTACK(tascb_completion); tascb->completion = &tascb_completion; spin_lock_irqsave(&task->task_state_lock, flags); if (task->task_state_flags & SAS_TASK_STATE_DONE) { spin_unlock_irqrestore(&task->task_state_lock, flags); res = TMF_RESP_FUNC_COMPLETE; ASD_DPRINTK("%s: task 0x%p done\n", __func__, task); goto out_done; } spin_unlock_irqrestore(&task->task_state_lock, flags); ascb = asd_ascb_alloc_list(asd_ha, &res, GFP_KERNEL); if (!ascb) return -ENOMEM; ascb->uldd_task = &tcs; ascb->completion = &completion; scb = ascb->scb; scb->header.opcode = SCB_ABORT_TASK; switch (task->task_proto) { case SAS_PROTOCOL_SATA: case SAS_PROTOCOL_STP: scb->abort_task.proto_conn_rate = (1 << 5); break; case SAS_PROTOCOL_SSP: scb->abort_task.proto_conn_rate = (1 << 4); scb->abort_task.proto_conn_rate |= task->dev->linkrate; break; case SAS_PROTOCOL_SMP: break; default: break; } if (task->task_proto == SAS_PROTOCOL_SSP) { scb->abort_task.ssp_frame.frame_type = SSP_TASK; memcpy(scb->abort_task.ssp_frame.hashed_dest_addr, task->dev->hashed_sas_addr, HASHED_SAS_ADDR_SIZE); memcpy(scb->abort_task.ssp_frame.hashed_src_addr, task->dev->port->ha->hashed_sas_addr, HASHED_SAS_ADDR_SIZE); scb->abort_task.ssp_frame.tptt = cpu_to_be16(0xFFFF); memcpy(scb->abort_task.ssp_task.lun, task->ssp_task.LUN, 8); scb->abort_task.ssp_task.tmf = TMF_ABORT_TASK; scb->abort_task.ssp_task.tag = cpu_to_be16(0xFFFF); } scb->abort_task.sister_scb = cpu_to_le16(0xFFFF); scb->abort_task.conn_handle = cpu_to_le16( (u16)(unsigned long)task->dev->lldd_dev); scb->abort_task.retry_count = 1; scb->abort_task.index = cpu_to_le16((u16)tascb->tc_index); scb->abort_task.itnl_to = cpu_to_le16(ITNL_TIMEOUT_CONST); res = asd_enqueue_internal(ascb, asd_tmf_tasklet_complete, asd_tmf_timedout); if (res) goto out_free; wait_for_completion(&completion); ASD_DPRINTK("tmf came back\n"); tascb->tag = tcs.tag; tascb->tag_valid = tcs.tag_valid; spin_lock_irqsave(&task->task_state_lock, flags); if (task->task_state_flags & SAS_TASK_STATE_DONE) { spin_unlock_irqrestore(&task->task_state_lock, flags); res = TMF_RESP_FUNC_COMPLETE; ASD_DPRINTK("%s: task 0x%p done\n", __func__, task); goto out_done; } spin_unlock_irqrestore(&task->task_state_lock, flags); if (tcs.dl_opcode == TC_SSP_RESP) { if (tcs.tmf_state == TMF_RESP_FUNC_COMPLETE) res = asd_clear_nexus(task); else res = tcs.tmf_state; } else if (tcs.dl_opcode == TC_NO_ERROR && tcs.tmf_state == TMF_RESP_FUNC_FAILED) { res = TMF_RESP_FUNC_FAILED; } else { switch (tcs.dl_opcode) { default: res = asd_clear_nexus(task); case TC_NO_ERROR: break; case TF_NAK_RECV: res = TMF_RESP_INVALID_FRAME; break; case TF_TMF_TASK_DONE: res = TMF_RESP_FUNC_FAILED; leftover = wait_for_completion_timeout(&tascb_completion, AIC94XX_SCB_TIMEOUT); spin_lock_irqsave(&task->task_state_lock, flags); if (leftover < 1) res = TMF_RESP_FUNC_FAILED; if (task->task_state_flags & SAS_TASK_STATE_DONE) res = TMF_RESP_FUNC_COMPLETE; spin_unlock_irqrestore(&task->task_state_lock, flags); break; case TF_TMF_NO_TAG: case TF_TMF_TAG_FREE: case TF_TMF_NO_CONN_HANDLE: res = TMF_RESP_FUNC_COMPLETE; break; case TF_TMF_NO_CTX: res = TMF_RESP_FUNC_ESUPP; break; } } out_done: tascb->completion = NULL; if (res == TMF_RESP_FUNC_COMPLETE) { task->lldd_task = NULL; mb(); asd_ascb_free(tascb); } ASD_DPRINTK("task 0x%p aborted, res: 0x%x\n", task, res); return res; out_free: asd_ascb_free(ascb); ASD_DPRINTK("task 0x%p aborted, res: 0x%x\n", task, res); return res; }
static void asd_task_tasklet_complete(struct asd_ascb *ascb, struct done_list_struct *dl) { struct sas_task *task = ascb->uldd_task; struct task_status_struct *ts = &task->task_status; unsigned long flags; u8 opcode = dl->opcode; asd_can_dequeue(ascb->ha, 1); Again: switch (opcode) { case TC_NO_ERROR: ts->resp = SAS_TASK_COMPLETE; ts->stat = SAM_GOOD; break; case TC_UNDERRUN: ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_UNDERRUN; ts->residual = le32_to_cpu(*(__le32 *)dl->status_block); break; case TC_OVERRUN: ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; ts->residual = 0; break; case TC_SSP_RESP: case TC_ATA_RESP: ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_PROTO_RESPONSE; asd_get_response_tasklet(ascb, dl); break; case TF_OPEN_REJECT: ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_OPEN_REJECT; if (dl->status_block[1] & 2) ts->open_rej_reason = 1 + dl->status_block[2]; else if (dl->status_block[1] & 1) ts->open_rej_reason = (dl->status_block[2] >> 4)+10; else ts->open_rej_reason = SAS_OREJ_UNKNOWN; break; case TF_OPEN_TO: ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_OPEN_TO; break; case TF_PHY_DOWN: case TU_PHY_DOWN: ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_PHY_DOWN; break; case TI_PHY_DOWN: ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_PHY_DOWN; break; case TI_BREAK: case TI_PROTO_ERR: case TI_NAK: case TI_ACK_NAK_TO: case TF_SMP_XMIT_RCV_ERR: case TC_ATA_R_ERR_RECV: ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_INTERRUPTED; break; case TF_BREAK: case TU_BREAK: case TU_ACK_NAK_TO: case TF_SMPRSP_TO: ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_DEV_NO_RESPONSE; break; case TF_NAK_RECV: ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_NAK_R_ERR; break; case TA_I_T_NEXUS_LOSS: opcode = dl->status_block[0]; goto Again; break; case TF_INV_CONN_HANDLE: ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_DEVICE_UNKNOWN; break; case TF_REQUESTED_N_PENDING: ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_PENDING; break; case TC_TASK_CLEARED: case TA_ON_REQ: ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_ABORTED_TASK; break; case TF_NO_SMP_CONN: case TF_TMF_NO_CTX: case TF_TMF_NO_TAG: case TF_TMF_TAG_FREE: case TF_TMF_TASK_DONE: case TF_TMF_NO_CONN_HANDLE: case TF_IRTT_TO: case TF_IU_SHORT: case TF_DATA_OFFS_ERR: ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_DEV_NO_RESPONSE; break; case TC_LINK_ADM_RESP: case TC_CONTROL_PHY: case TC_RESUME: case TC_PARTIAL_SG_LIST: default: ASD_DPRINTK("%s: dl opcode: 0x%x?\n", __FUNCTION__, opcode); break; }