/* * PMC-Sierra PM8001/8081/8088/8089 SAS/SATA based host adapters driver * * Copyright (c) 2008-2009 USI Co., Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. *
*/
/** * pm8001_find_tag - from sas task to find out tag that belongs to this task * @task: the task sent to the LLDD * @tag: the found tag associated with the task
*/ staticint pm8001_find_tag(struct sas_task *task, u32 *tag)
{ if (task->lldd_task) { struct pm8001_ccb_info *ccb;
ccb = task->lldd_task;
*tag = ccb->ccb_tag; return 1;
} return 0;
}
/** * pm8001_tag_free - free the no more needed tag * @pm8001_ha: our hba struct * @tag: the found tag associated with the task
*/ void pm8001_tag_free(struct pm8001_hba_info *pm8001_ha, u32 tag)
{ void *bitmap = pm8001_ha->rsvd_tags; unsignedlong flags;
/** * pm8001_find_ha_by_dev - from domain device which come from sas layer to * find out our hba struct. * @dev: the domain device which from sas layer.
*/ static struct pm8001_hba_info *pm8001_find_ha_by_dev(struct domain_device *dev)
{ struct sas_ha_struct *sha = dev->port->ha; struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; return pm8001_ha;
}
/** * pm8001_phy_control - this function should be registered to * sas_domain_function_template to provide libsas used, note: this is just * control the HBA phy rather than other expander phy if you want control * other phy, you should use SMP command. * @sas_phy: which phy in HBA phys. * @func: the operation. * @funcdata: always NULL.
*/ int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func, void *funcdata)
{ int rc = 0, phy_id = sas_phy->id; struct pm8001_hba_info *pm8001_ha = NULL; struct sas_phy_linkrates *rates; struct pm8001_phy *phy;
DECLARE_COMPLETION_ONSTACK(completion); unsignedlong flags;
pm8001_ha = sas_phy->ha->lldd_ha;
phy = &pm8001_ha->phy[phy_id];
if (PM8001_CHIP_DISP->fatal_errors(pm8001_ha)) { /* * If the controller is in fatal error state, * we will not get a response from the controller
*/
pm8001_dbg(pm8001_ha, FAIL, "Phy control failed due to fatal errors\n"); return -EFAULT;
}
/** * pm8001_scan_start - we should enable all HBA phys by sending the phy_start * command to HBA. * @shost: the scsi host data.
*/ void pm8001_scan_start(struct Scsi_Host *shost)
{ int i; struct pm8001_hba_info *pm8001_ha; struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
DECLARE_COMPLETION_ONSTACK(completion);
pm8001_ha = sha->lldd_ha; /* SAS_RE_INITIALIZATION not available in SPCv/ve */ if (pm8001_ha->chip_id == chip_8001)
PM8001_CHIP_DISP->sas_re_init_req(pm8001_ha); for (i = 0; i < pm8001_ha->chip->n_phy; ++i) {
pm8001_ha->phy[i].enable_completion = &completion;
PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
wait_for_completion(&completion);
msleep(300);
}
}
/* give the phy enabling interrupt event time to come in (1s
* is empirically about all it takes) */ if (time < HZ) return 0; /* Wait for discovery to finish */
sas_drain_work(ha); return 1;
}
/** * pm8001_task_prep_smp - the dispatcher function, prepare data for smp task * @pm8001_ha: our hba card information * @ccb: the ccb which attached to smp task
*/ staticint pm8001_task_prep_smp(struct pm8001_hba_info *pm8001_ha, struct pm8001_ccb_info *ccb)
{ return PM8001_CHIP_DISP->smp_req(pm8001_ha, ccb);
}
/** * pm8001_task_prep_ata - the dispatcher function, prepare data for sata task * @pm8001_ha: our hba card information * @ccb: the ccb which attached to sata task
*/ staticint pm8001_task_prep_ata(struct pm8001_hba_info *pm8001_ha, struct pm8001_ccb_info *ccb)
{ return PM8001_CHIP_DISP->sata_req(pm8001_ha, ccb);
}
/** * pm8001_task_prep_internal_abort - the dispatcher function, prepare data * for internal abort task * @pm8001_ha: our hba card information * @ccb: the ccb which attached to sata task
*/ staticint pm8001_task_prep_internal_abort(struct pm8001_hba_info *pm8001_ha, struct pm8001_ccb_info *ccb)
{ return PM8001_CHIP_DISP->task_abort(pm8001_ha, ccb);
}
/** * pm8001_task_prep_ssp_tm - the dispatcher function, prepare task management data * @pm8001_ha: our hba card information * @ccb: the ccb which attached to TM * @tmf: the task management IU
*/ staticint pm8001_task_prep_ssp_tm(struct pm8001_hba_info *pm8001_ha, struct pm8001_ccb_info *ccb, struct sas_tmf_task *tmf)
{ return PM8001_CHIP_DISP->ssp_tm_req(pm8001_ha, ccb, tmf);
}
/** * pm8001_task_prep_ssp - the dispatcher function, prepare ssp data for ssp task * @pm8001_ha: our hba card information * @ccb: the ccb which attached to ssp task
*/ staticint pm8001_task_prep_ssp(struct pm8001_hba_info *pm8001_ha, struct pm8001_ccb_info *ccb)
{ return PM8001_CHIP_DISP->ssp_io_req(pm8001_ha, ccb);
}
/** * pm8001_dev_found_notify - libsas notify a device is found. * @dev: the device structure which sas layer used. * * when libsas find a sas domain device, it should tell the LLDD that * device is found, and then LLDD register this device to HBA firmware * by the command "OPC_INB_REG_DEV", after that the HBA will assign a * device ID(according to device's sas address) and returned it to LLDD. From * now on, we communicate with HBA FW with the device ID which HBA assigned * rather than sas address. it is the necessary step for our HBA but it is * the optional for other HBA driver.
*/ staticint pm8001_dev_found_notify(struct domain_device *dev)
{ unsignedlong flags = 0; int res = 0; struct pm8001_hba_info *pm8001_ha = NULL; struct domain_device *parent_dev = dev->parent; struct pm8001_device *pm8001_device;
DECLARE_COMPLETION_ONSTACK(completion);
u32 flag = 0;
pm8001_ha = pm8001_find_ha_by_dev(dev);
spin_lock_irqsave(&pm8001_ha->lock, flags);
pm8001_device = pm8001_alloc_dev(pm8001_ha); if (!pm8001_device) {
res = -1; goto found_out;
}
pm8001_device->sas_device = dev;
dev->lldd_dev = pm8001_device;
pm8001_device->dev_type = dev->dev_type;
pm8001_device->dcompletion = &completion; if (dev_parent_is_expander(dev)) { int phy_id;
phy_id = sas_find_attached_phy_id(&parent_dev->ex_dev, dev); if (phy_id < 0) {
pm8001_dbg(pm8001_ha, FAIL, "Error: no attached dev:%016llx at ex:%016llx.\n",
SAS_ADDR(dev->sas_addr),
SAS_ADDR(parent_dev->sas_addr));
res = phy_id;
} else {
pm8001_device->attached_phy = phy_id;
}
} else { if (dev->dev_type == SAS_SATA_DEV) {
pm8001_device->attached_phy =
dev->rphy->identify.phy_identifier;
flag = 1; /* directly sata */
}
} /*register this device to HBA*/
pm8001_dbg(pm8001_ha, DISC, "Found device\n");
PM8001_CHIP_DISP->reg_dev_req(pm8001_ha, pm8001_device, flag);
spin_unlock_irqrestore(&pm8001_ha->lock, flags);
wait_for_completion(&completion); if (dev->dev_type == SAS_END_DEVICE)
msleep(50);
pm8001_ha->flags = PM8001F_RUN_TIME; return 0;
found_out:
spin_unlock_irqrestore(&pm8001_ha->lock, flags); return res;
}
int pm8001_dev_found(struct domain_device *dev)
{ return pm8001_dev_found_notify(dev);
}
#define PM8001_TASK_TIMEOUT 20
/** * pm8001_dev_gone_notify - see the comments for "pm8001_dev_found_notify" * @dev: the device structure which sas layer used.
*/ staticvoid pm8001_dev_gone_notify(struct domain_device *dev)
{ unsignedlong flags = 0; struct pm8001_hba_info *pm8001_ha; struct pm8001_device *pm8001_dev = dev->lldd_dev;
pm8001_dbg(pm8001_ha, DISC, "found dev[%d:%x] is gone.\n",
pm8001_dev->device_id, pm8001_dev->dev_type); if (atomic_read(&pm8001_dev->running_req)) {
spin_unlock_irqrestore(&pm8001_ha->lock, flags);
sas_execute_internal_abort_dev(dev, 0, NULL); while (atomic_read(&pm8001_dev->running_req))
msleep(20);
spin_lock_irqsave(&pm8001_ha->lock, flags);
}
PM8001_CHIP_DISP->dereg_dev_req(pm8001_ha, device_id);
/* * The phy array only contains local phys. Thus, we cannot clear * phy_attached for a device behind an expander.
*/ if (!dev_parent_is_expander(dev))
pm8001_ha->phy[pm8001_dev->attached_phy].phy_attached = 0;
pm8001_free_dev(pm8001_dev);
} else {
pm8001_dbg(pm8001_ha, DISC, "Found dev has gone.\n");
}
dev->lldd_dev = NULL;
spin_unlock_irqrestore(&pm8001_ha->lock, flags);
}
/** * pm8001_I_T_nexus_reset() - reset the initiator/target connection * @dev: the device structure for the device to reset. * * Standard mandates link reset for ATA (type 0) and hard reset for * SSP (type 1), only for RECOVERY
*/ int pm8001_I_T_nexus_reset(struct domain_device *dev)
{ int rc = TMF_RESP_FUNC_FAILED; struct pm8001_device *pm8001_dev; struct pm8001_hba_info *pm8001_ha; struct sas_phy *phy;
/* * This function handle the IT_NEXUS_XXX event or completion * status code for SSP/SATA/SMP I/O request.
*/ int pm8001_I_T_nexus_event_handler(struct domain_device *dev)
{ int rc = TMF_RESP_FUNC_FAILED; struct pm8001_device *pm8001_dev; struct pm8001_hba_info *pm8001_ha; struct sas_phy *phy;
/* deregister the target device */
pm8001_dev_gone_notify(dev);
msleep(200);
/*send phy reset to hard reset target */
rc = sas_phy_reset(phy, 1);
msleep(2000);
}
pm8001_dbg(pm8001_ha, EH, " for device[%x]:rc=%d\n",
pm8001_dev->device_id, rc);
out:
sas_put_local_phy(phy);
return rc;
} /* mandatory SAM-3, the task reset the specified LUN*/ int pm8001_lu_reset(struct domain_device *dev, u8 *lun)
{ int rc = TMF_RESP_FUNC_FAILED; struct pm8001_device *pm8001_dev = dev->lldd_dev; struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
DECLARE_COMPLETION_ONSTACK(completion_setstate);
if (PM8001_CHIP_DISP->fatal_errors(pm8001_ha)) { /* * If the controller is in fatal error state, * we will not get a response from the controller
*/
pm8001_dbg(pm8001_ha, FAIL, "LUN reset failed due to fatal errors\n"); return rc;
}
rc = sas_query_task(task, tag); switch (rc) { /* The task is still in Lun, release it then */ case TMF_RESP_FUNC_SUCC:
pm8001_dbg(pm8001_ha, EH, "The task is still in Lun\n"); break; /* The task is not in Lun or failed, reset the phy */ case TMF_RESP_FUNC_FAILED: case TMF_RESP_FUNC_COMPLETE:
pm8001_dbg(pm8001_ha, EH, "The task is not in Lun or failed, reset the phy\n"); break;
}
}
pr_err("pm80xx: rc= %d\n", rc); return rc;
}
/* mandatory SAM-3, still need free task/ccb info, abort the specified task */ int pm8001_abort_task(struct sas_task *task)
{ struct pm8001_ccb_info *ccb = task->lldd_task; unsignedlong flags;
u32 tag; struct domain_device *dev ; struct pm8001_hba_info *pm8001_ha; struct pm8001_device *pm8001_dev; int rc = TMF_RESP_FUNC_FAILED, ret;
u32 port_id; struct sas_task_slow slow_task;
if (!task->lldd_task || !task->dev) return TMF_RESP_FUNC_FAILED;
dev = task->dev;
pm8001_dev = dev->lldd_dev;
pm8001_ha = pm8001_find_ha_by_dev(dev);
if (PM8001_CHIP_DISP->fatal_errors(pm8001_ha)) { // If the controller is seeing fatal errors // abort task will not get a response from the controller return TMF_RESP_FUNC_FAILED;
}
ret = pm8001_find_tag(task, &tag); if (ret == 0) {
pm8001_info(pm8001_ha, "no tag for task:%p\n", task); return TMF_RESP_FUNC_FAILED;
}
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); return TMF_RESP_FUNC_COMPLETE;
}
task->task_state_flags |= SAS_TASK_STATE_ABORTED; if (task->slow_task == NULL) {
init_completion(&slow_task.completion);
task->slow_task = &slow_task;
}
spin_unlock_irqrestore(&task->task_state_lock, flags); if (task->task_proto & SAS_PROTOCOL_SSP) {
rc = sas_abort_task(task, tag);
sas_execute_internal_abort_single(dev, tag, 0, NULL);
} elseif (task->task_proto & SAS_PROTOCOL_SATA ||
task->task_proto & SAS_PROTOCOL_STP) { if (pm8001_ha->chip_id == chip_8006) {
DECLARE_COMPLETION_ONSTACK(completion_reset);
DECLARE_COMPLETION_ONSTACK(completion);
u32 phy_id = pm80xx_get_local_phy_id(dev); struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
port_id = phy->port->port_id;
/* 1. Set Device state as Recovery */
pm8001_dev->setds_completion = &completion;
PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
pm8001_dev, DS_IN_RECOVERY);
wait_for_completion(&completion);
/* 2. Send Phy Control Hard Reset */
reinit_completion(&completion);
phy->port_reset_status = PORT_RESET_TMO;
phy->reset_success = false;
phy->enable_completion = &completion;
phy->reset_completion = &completion_reset;
ret = PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
PHY_HARD_RESET); if (ret) {
phy->enable_completion = NULL;
phy->reset_completion = NULL; goto out;
}
/* In the case of the reset timeout/fail we still * abort the command at the firmware. The assumption * here is that the drive is off doing something so * that it's not processing requests, and we want to * avoid getting a completion for this and either * leaking the task in libsas or losing the race and * getting a double free.
*/
pm8001_dbg(pm8001_ha, MSG, "Waiting for local phy ctl\n");
ret = wait_for_completion_timeout(&completion,
PM8001_TASK_TIMEOUT * HZ); if (!ret || !phy->reset_success) {
phy->enable_completion = NULL;
phy->reset_completion = NULL;
} else { /* 3. Wait for Port Reset complete or * Port reset TMO
*/
pm8001_dbg(pm8001_ha, MSG, "Waiting for Port reset\n");
ret = wait_for_completion_timeout(
&completion_reset,
PM8001_TASK_TIMEOUT * HZ); if (!ret)
phy->reset_completion = NULL;
WARN_ON(phy->port_reset_status ==
PORT_RESET_TMO); if (phy->port_reset_status == PORT_RESET_TMO) {
pm8001_dev_gone_notify(dev);
PM8001_CHIP_DISP->hw_event_ack_req(
pm8001_ha, 0,
0x07, /*HW_EVENT_PHY_DOWN ack*/
port_id, phy_id, 0, 0); goto out;
}
}
/* * 4. SATA Abort ALL * we wait for the task to be aborted so that the task * is removed from the ccb. on success the caller is * going to free the task.
*/
ret = sas_execute_internal_abort_dev(dev, 0, NULL); if (ret) goto out;
ret = wait_for_completion_timeout(
&task->slow_task->completion,
PM8001_TASK_TIMEOUT * HZ); if (!ret) goto out;
/* 5. Set Device State as Operational */
reinit_completion(&completion);
pm8001_dev->setds_completion = &completion;
PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
pm8001_dev, DS_OPERATIONAL);
wait_for_completion(&completion);
} else { /* * Ensure that if we see a completion for the ccb * associated with the task which we are trying to * abort then we should not touch the sas_task as it * may race with libsas freeing it when return here.
*/
ccb->task = NULL;
ret = sas_execute_internal_abort_single(dev, tag, 0, NULL);
}
rc = TMF_RESP_FUNC_COMPLETE;
} elseif (task->task_proto & SAS_PROTOCOL_SMP) { /* SMP */
rc = sas_execute_internal_abort_single(dev, tag, 0, NULL);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.