staticint prot_guard_mask = 3;
module_param(prot_guard_mask, int, 0);
MODULE_PARM_DESC(prot_guard_mask, " Host protection guard mask, def=3"); staticint logging_level;
module_param(logging_level, int, 0);
MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info (default=0)"); staticint max_sgl_entries = MPI3MR_DEFAULT_SGL_ENTRIES;
module_param(max_sgl_entries, int, 0444);
MODULE_PARM_DESC(max_sgl_entries, "Preferred max number of SG entries to be used for a single I/O\n" "The actual value will be determined by the driver\n" "(Minimum=256, Maximum=2048, default=256)");
/* * SAS Log info code for a NCQ collateral abort after an NCQ error: * IOC_LOGINFO_PREFIX_PL | PL_LOGINFO_CODE_SATA_NCQ_FAIL_ALL_CMDS_AFTR_ERR * See: drivers/message/fusion/lsi/mpi_log_sas.h
*/ #define IOC_LOGINFO_SATA_NCQ_FAIL_AFTER_ERR 0x31080000
/** * mpi3mr_host_tag_for_scmd - Get host tag for a scmd * @mrioc: Adapter instance reference * @scmd: SCSI command reference * * Calculate the host tag based on block tag for a given scmd. * * Return: Valid host tag or MPI3MR_HOSTTAG_INVALID.
*/ static u16 mpi3mr_host_tag_for_scmd(struct mpi3mr_ioc *mrioc, struct scsi_cmnd *scmd)
{ struct scmd_priv *priv = NULL;
u32 unique_tag;
u16 host_tag, hw_queue;
/** * mpi3mr_alloc_fwevt - Allocate firmware event * @len: length of firmware event data to allocate * * Allocate firmware event with required length and initialize * the reference counter. * * Return: firmware event reference.
*/ staticstruct mpi3mr_fwevt *mpi3mr_alloc_fwevt(int len)
{ struct mpi3mr_fwevt *fwevt;
fwevt = kzalloc(sizeof(*fwevt) + len, GFP_ATOMIC); if (!fwevt) return NULL;
kref_init(&fwevt->ref_count); return fwevt;
}
/** * mpi3mr_fwevt_add_to_list - Add firmware event to the list * @mrioc: Adapter instance reference * @fwevt: Firmware event reference * * Add the given firmware event to the firmware event list. * * Return: Nothing.
*/ staticvoid mpi3mr_fwevt_add_to_list(struct mpi3mr_ioc *mrioc, struct mpi3mr_fwevt *fwevt)
{ unsignedlong flags;
if (!mrioc->fwevt_worker_thread) return;
spin_lock_irqsave(&mrioc->fwevt_lock, flags); /* get fwevt reference count while adding it to fwevt_list */
mpi3mr_fwevt_get(fwevt);
INIT_LIST_HEAD(&fwevt->list);
list_add_tail(&fwevt->list, &mrioc->fwevt_list);
INIT_WORK(&fwevt->work, mpi3mr_fwevt_worker); /* get fwevt reference count while enqueueing it to worker queue */
mpi3mr_fwevt_get(fwevt);
queue_work(mrioc->fwevt_worker_thread, &fwevt->work);
spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
}
/** * mpi3mr_hdb_trigger_data_event - Add hdb trigger data event to * the list * @mrioc: Adapter instance reference * @event_data: Event data * * Add the given hdb trigger data event to the firmware event * list. * * Return: Nothing.
*/ void mpi3mr_hdb_trigger_data_event(struct mpi3mr_ioc *mrioc, struct trigger_event_data *event_data)
{ struct mpi3mr_fwevt *fwevt;
u16 sz = sizeof(*event_data);
fwevt = mpi3mr_alloc_fwevt(sz); if (!fwevt) {
ioc_warn(mrioc, "failed to queue hdb trigger data event\n"); return;
}
/** * mpi3mr_fwevt_del_from_list - Delete firmware event from list * @mrioc: Adapter instance reference * @fwevt: Firmware event reference * * Delete the given firmware event from the firmware event list. * * Return: Nothing.
*/ staticvoid mpi3mr_fwevt_del_from_list(struct mpi3mr_ioc *mrioc, struct mpi3mr_fwevt *fwevt)
{ unsignedlong flags;
spin_lock_irqsave(&mrioc->fwevt_lock, flags); if (!list_empty(&fwevt->list)) {
list_del_init(&fwevt->list); /* * Put fwevt reference count after * removing it from fwevt_list
*/
mpi3mr_fwevt_put(fwevt);
}
spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
}
/** * mpi3mr_dequeue_fwevt - Dequeue firmware event from the list * @mrioc: Adapter instance reference * * Dequeue a firmware event from the firmware event list. * * Return: firmware event.
*/ staticstruct mpi3mr_fwevt *mpi3mr_dequeue_fwevt( struct mpi3mr_ioc *mrioc)
{ unsignedlong flags; struct mpi3mr_fwevt *fwevt = NULL;
spin_lock_irqsave(&mrioc->fwevt_lock, flags); if (!list_empty(&mrioc->fwevt_list)) {
fwevt = list_first_entry(&mrioc->fwevt_list, struct mpi3mr_fwevt, list);
list_del_init(&fwevt->list); /* * Put fwevt reference count after * removing it from fwevt_list
*/
mpi3mr_fwevt_put(fwevt);
}
spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
return fwevt;
}
/** * mpi3mr_cancel_work - cancel firmware event * @fwevt: fwevt object which needs to be canceled * * Return: Nothing.
*/ staticvoid mpi3mr_cancel_work(struct mpi3mr_fwevt *fwevt)
{ /* * Wait on the fwevt to complete. If this returns 1, then * the event was never executed. * * If it did execute, we wait for it to finish, and the put will * happen from mpi3mr_process_fwevt()
*/ if (cancel_work_sync(&fwevt->work)) { /* * Put fwevt reference count after * dequeuing it from worker queue
*/
mpi3mr_fwevt_put(fwevt); /* * Put fwevt reference count to neutralize * kref_init increment
*/
mpi3mr_fwevt_put(fwevt);
}
}
if ((list_empty(&mrioc->fwevt_list) && !mrioc->current_event) ||
!mrioc->fwevt_worker_thread) return;
while ((fwevt = mpi3mr_dequeue_fwevt(mrioc)))
mpi3mr_cancel_work(fwevt);
if (mrioc->current_event) {
fwevt = mrioc->current_event; /* * Don't call cancel_work_sync() API for the * fwevt work if the controller reset is * get called as part of processing the * same fwevt work (or) when worker thread is * waiting for device add/remove APIs to complete. * Otherwise we will see deadlock.
*/ if (current_work() == &fwevt->work || fwevt->pending_at_sml) {
fwevt->discard = 1; return;
}
mpi3mr_cancel_work(fwevt);
}
}
/** * mpi3mr_queue_qd_reduction_event - Queue TG QD reduction event * @mrioc: Adapter instance reference * @tg: Throttle group information pointer * * Accessor to queue on synthetically generated driver event to * the event worker thread, the driver event will be used to * reduce the QD of all VDs in the TG from the worker thread. * * Return: None.
*/ staticvoid mpi3mr_queue_qd_reduction_event(struct mpi3mr_ioc *mrioc, struct mpi3mr_throttle_group_info *tg)
{ struct mpi3mr_fwevt *fwevt;
u16 sz = sizeof(struct mpi3mr_throttle_group_info *);
/* * If the QD reduction event is already queued due to throttle and if * the QD is not restored through device info change event * then dont queue further reduction events
*/ if (tg->fw_qd != tg->modified_qd) return;
/** * mpi3mr_count_dev_pending - Count commands pending for a lun * @rq: Block request * @data: SCSI device reference * * This is an iterator function called for each SCSI command in * a host and if the command is pending in the LLD for the * specific device(lun) then device specific pending I/O counter * is updated in the device structure. * * Return: true always.
*/
if (scmd) {
priv = scsi_cmd_priv(scmd); if (!priv->in_lld_scope) goto out; if (scmd->device == sdev)
sdev_priv_data->pend_count++;
}
out: returntrue;
}
/** * mpi3mr_count_tgt_pending - Count commands pending for target * @rq: Block request * @data: SCSI target reference * * This is an iterator function called for each SCSI command in * a host and if the command is pending in the LLD for the * specific target then target specific pending I/O counter is * updated in the target structure. * * Return: true always.
*/
if (scmd) {
priv = scsi_cmd_priv(scmd); if (!priv->in_lld_scope) goto out; if (scmd->device && (scsi_target(scmd->device) == starget))
stgt_priv_data->pend_count++;
}
out: returntrue;
}
/** * mpi3mr_flush_host_io - Flush host I/Os * @mrioc: Adapter instance reference * * Flush all of the pending I/Os by calling * blk_mq_tagset_busy_iter() for each possible tag. This is * executed post controller reset * * Return: Nothing.
*/ void mpi3mr_flush_host_io(struct mpi3mr_ioc *mrioc)
{ struct Scsi_Host *shost = mrioc->shost;
/** * mpi3mr_flush_cmds_for_unrecovered_controller - Flush all pending cmds * @mrioc: Adapter instance reference * * This function waits for currently running IO poll threads to * exit and then flushes all host I/Os and any internal pending * cmds. This is executed after controller is marked as * unrecoverable. * * Return: Nothing.
*/ void mpi3mr_flush_cmds_for_unrecovered_controller(struct mpi3mr_ioc *mrioc)
{ struct Scsi_Host *shost = mrioc->shost; int i;
if (!mrioc->unrecoverable) return;
if (mrioc->op_reply_qinfo) { for (i = 0; i < mrioc->num_queues; i++) { while (atomic_read(&mrioc->op_reply_qinfo[i].in_use))
udelay(500);
atomic_set(&mrioc->op_reply_qinfo[i].pend_ios, 0);
}
}
mrioc->flush_io_count = 0;
blk_mq_tagset_busy_iter(&shost->tag_set,
mpi3mr_flush_scmd, (void *)mrioc);
mpi3mr_flush_delayed_cmd_lists(mrioc);
mpi3mr_flush_drv_cmds(mrioc);
}
/** * mpi3mr_tgtdev_del_from_list -Delete tgtdevice from the list * @mrioc: Adapter instance reference * @tgtdev: Target device * @must_delete: Must delete the target device from the list irrespective * of the device state. * * Remove the target device from the target device list * * Return: Nothing.
*/ staticvoid mpi3mr_tgtdev_del_from_list(struct mpi3mr_ioc *mrioc, struct mpi3mr_tgt_dev *tgtdev, bool must_delete)
{ unsignedlong flags;
/** * __mpi3mr_get_tgtdev_from_tgtpriv -Get tgtdev from tgt private * @mrioc: Adapter instance reference * @tgt_priv: Target private data * * Accessor to return target device from the target private * data. Non Lock version * * Return: Target device reference.
*/ staticstruct mpi3mr_tgt_dev *__mpi3mr_get_tgtdev_from_tgtpriv( struct mpi3mr_ioc *mrioc, struct mpi3mr_stgt_priv_data *tgt_priv)
{ struct mpi3mr_tgt_dev *tgtdev;
assert_spin_locked(&mrioc->tgtdev_lock);
tgtdev = tgt_priv->tgt_dev; if (tgtdev)
mpi3mr_tgtdev_get(tgtdev); return tgtdev;
}
/** * mpi3mr_set_io_divert_for_all_vd_in_tg -set divert for TG VDs * @mrioc: Adapter instance reference * @tg: Throttle group information pointer * @divert_value: 1 or 0 * * Accessor to set io_divert flag for each device associated * with the given throttle group with the given value. * * Return: None.
*/ staticvoid mpi3mr_set_io_divert_for_all_vd_in_tg(struct mpi3mr_ioc *mrioc, struct mpi3mr_throttle_group_info *tg, u8 divert_value)
{ unsignedlong flags; struct mpi3mr_tgt_dev *tgtdev; struct mpi3mr_stgt_priv_data *tgt_priv;
/** * mpi3mr_print_device_event_notice - print notice related to post processing of * device event after controller reset. * * @mrioc: Adapter instance reference * @device_add: true for device add event and false for device removal event * * Return: None.
*/ void mpi3mr_print_device_event_notice(struct mpi3mr_ioc *mrioc, bool device_add)
{
ioc_notice(mrioc, "Device %s was in progress before the reset and\n",
(device_add ? "addition" : "removal"));
ioc_notice(mrioc, "completed after reset, verify whether the exposed devices\n");
ioc_notice(mrioc, "are matched with attached devices for correctness\n");
}
/** * mpi3mr_remove_tgtdev_from_host - Remove dev from upper layers * @mrioc: Adapter instance reference * @tgtdev: Target device structure * * Checks whether the device is exposed to upper layers and if it * is then remove the device from upper layers by calling * scsi_remove_target(). * * Return: 0 on success, non zero on failure.
*/ void mpi3mr_remove_tgtdev_from_host(struct mpi3mr_ioc *mrioc, struct mpi3mr_tgt_dev *tgtdev)
{ struct mpi3mr_stgt_priv_data *tgt_priv;
/** * mpi3mr_report_tgtdev_to_host - Expose device to upper layers * @mrioc: Adapter instance reference * @perst_id: Persistent ID of the device * * Checks whether the device can be exposed to upper layers and * if it is not then expose the device to upper layers by * calling scsi_scan_target(). * * Return: 0 on success, non zero on failure.
*/ staticint mpi3mr_report_tgtdev_to_host(struct mpi3mr_ioc *mrioc,
u16 perst_id)
{ int retval = 0; struct mpi3mr_tgt_dev *tgtdev;
if (mrioc->reset_in_progress || mrioc->pci_err_recovery) return -1;
tgtdev = mpi3mr_get_tgtdev_by_perst_id(mrioc, perst_id); if (!tgtdev) {
retval = -1; goto out;
} if (tgtdev->is_hidden || tgtdev->host_exposed) {
retval = -1; goto out;
} if (!mrioc->sas_transport_enabled || (tgtdev->dev_type !=
MPI3_DEVICE_DEVFORM_SAS_SATA) || tgtdev->non_stl){
tgtdev->host_exposed = 1; if (mrioc->current_event)
mrioc->current_event->pending_at_sml = 1;
scsi_scan_target(&mrioc->shost->shost_gendev,
mrioc->scsi_device_channel, tgtdev->perst_id,
SCAN_WILD_CARD, SCSI_SCAN_INITIAL); if (!tgtdev->starget)
tgtdev->host_exposed = 0; if (mrioc->current_event) {
mrioc->current_event->pending_at_sml = 0; if (mrioc->current_event->discard) {
mpi3mr_print_device_event_notice(mrioc, true); goto out;
}
}
dprint_event_bh(mrioc, "exposed target device with handle(0x%04x), perst_id(%d)\n",
tgtdev->dev_handle, perst_id); goto out;
} else
mpi3mr_report_tgtdev_to_sas_transport(mrioc, tgtdev);
out: if (tgtdev)
mpi3mr_tgtdev_put(tgtdev);
return retval;
}
/** * mpi3mr_change_queue_depth- Change QD callback handler * @sdev: SCSI device reference * @q_depth: Queue depth * * Validate and limit QD and call scsi_change_queue_depth. * * Return: return value of scsi_change_queue_depth
*/ staticint mpi3mr_change_queue_depth(struct scsi_device *sdev, int q_depth)
{ struct scsi_target *starget = scsi_target(sdev); struct Scsi_Host *shost = dev_to_shost(&starget->dev); int retval = 0;
/** * mpi3mr_update_sdev - Update SCSI device information * @sdev: SCSI device reference * @data: target device reference * * This is an iterator function called for each SCSI device in a * target to update the target specific information into each * SCSI device. * * Return: Nothing.
*/ staticvoid
mpi3mr_update_sdev(struct scsi_device *sdev, void *data)
{ struct mpi3mr_tgt_dev *tgtdev; struct queue_limits lim;
tgtdev = (struct mpi3mr_tgt_dev *)data; if (!tgtdev) return;
/** * mpi3mr_refresh_tgtdevs - Refresh target device exposure * @mrioc: Adapter instance reference * * This is executed post controller reset to identify any * missing devices during reset and remove from the upper layers * or expose any newly detected device to the upper layers. * * Return: Nothing.
*/ staticvoid mpi3mr_refresh_tgtdevs(struct mpi3mr_ioc *mrioc)
{ struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next; struct mpi3mr_stgt_priv_data *tgt_priv;
switch (dev_pg0->access_status) { case MPI3_DEVICE0_ASTATUS_NO_ERRORS: case MPI3_DEVICE0_ASTATUS_PREPARE: case MPI3_DEVICE0_ASTATUS_NEEDS_INITIALIZATION: case MPI3_DEVICE0_ASTATUS_DEVICE_MISSING_DELAY: break; default:
tgtdev->is_hidden = 1; break;
}
/** * mpi3mr_devstatuschg_evt_bh - DevStatusChange evt bottomhalf * @mrioc: Adapter instance reference * @fwevt: Firmware event information. * * Process Device status Change event and based on device's new * information, either expose the device to the upper layers, or * remove the device from upper layers. * * Return: Nothing.
*/ staticvoid mpi3mr_devstatuschg_evt_bh(struct mpi3mr_ioc *mrioc, struct mpi3mr_fwevt *fwevt)
{
u16 dev_handle = 0;
u8 uhide = 0, delete = 0, cleanup = 0; struct mpi3mr_tgt_dev *tgtdev = NULL; struct mpi3_event_data_device_status_change *evtdata =
(struct mpi3_event_data_device_status_change *)fwevt->event_data;
dev_handle = le16_to_cpu(evtdata->dev_handle);
dprint_event_bh(mrioc, "processing device status change event bottom half for handle(0x%04x), rc(0x%02x)\n",
dev_handle, evtdata->reason_code); switch (evtdata->reason_code) { case MPI3_EVENT_DEV_STAT_RC_HIDDEN: delete = 1; break; case MPI3_EVENT_DEV_STAT_RC_NOT_HIDDEN:
uhide = 1; break; case MPI3_EVENT_DEV_STAT_RC_VD_NOT_RESPONDING: delete = 1;
cleanup = 1; break; default:
ioc_info(mrioc, "%s :Unhandled reason code(0x%x)\n", __func__,
evtdata->reason_code); break;
}
tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, dev_handle); if (!tgtdev) {
dprint_event_bh(mrioc, "processing device status change event bottom half,\n" "cannot identify target device for handle(0x%04x), rc(0x%02x)\n",
dev_handle, evtdata->reason_code); goto out;
} if (uhide) {
tgtdev->is_hidden = 0; if (!tgtdev->host_exposed)
mpi3mr_report_tgtdev_to_host(mrioc, tgtdev->perst_id);
}
if (delete)
mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
if (cleanup) {
mpi3mr_tgtdev_del_from_list(mrioc, tgtdev, false);
mpi3mr_tgtdev_put(tgtdev);
}
out: if (tgtdev)
mpi3mr_tgtdev_put(tgtdev);
}
/** * mpi3mr_devinfochg_evt_bh - DeviceInfoChange evt bottomhalf * @mrioc: Adapter instance reference * @dev_pg0: New device page0 * * Process Device Info Change event and based on device's new * information, either expose the device to the upper layers, or * remove the device from upper layers or update the details of * the device. * * Return: Nothing.
*/ staticvoid mpi3mr_devinfochg_evt_bh(struct mpi3mr_ioc *mrioc, struct mpi3_device_page0 *dev_pg0)
{ struct mpi3mr_tgt_dev *tgtdev = NULL;
u16 dev_handle = 0, perst_id = 0;
perst_id = le16_to_cpu(dev_pg0->persistent_id);
dev_handle = le16_to_cpu(dev_pg0->dev_handle);
dprint_event_bh(mrioc, "processing device info change event bottom half for handle(0x%04x), perst_id(%d)\n",
dev_handle, perst_id);
tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, dev_handle); if (!tgtdev) {
dprint_event_bh(mrioc, "cannot identify target device for device info\n" "change event handle(0x%04x), perst_id(%d)\n",
dev_handle, perst_id); goto out;
}
mpi3mr_update_tgtdev(mrioc, tgtdev, dev_pg0, false); if (!tgtdev->is_hidden && !tgtdev->host_exposed)
mpi3mr_report_tgtdev_to_host(mrioc, perst_id); if (tgtdev->is_hidden && tgtdev->host_exposed)
mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev); if (!tgtdev->is_hidden && tgtdev->host_exposed && tgtdev->starget)
starget_for_each_device(tgtdev->starget, (void *)tgtdev,
mpi3mr_update_sdev);
out: if (tgtdev)
mpi3mr_tgtdev_put(tgtdev);
}
for (i = 0; i < event_data->num_entries; i++) { if (fwevt->discard) return;
handle = le16_to_cpu(event_data->phy_entry[i].attached_dev_handle); if (!handle) continue;
tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle); if (!tgtdev) continue;
switch (reason_code) { case MPI3_EVENT_SAS_TOPO_PHY_RC_TARG_NOT_RESPONDING: if (tgtdev->host_exposed)
mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
mpi3mr_tgtdev_del_from_list(mrioc, tgtdev, false);
mpi3mr_tgtdev_put(tgtdev); break; case MPI3_EVENT_SAS_TOPO_PHY_RC_RESPONDING: case MPI3_EVENT_SAS_TOPO_PHY_RC_PHY_CHANGED: case MPI3_EVENT_SAS_TOPO_PHY_RC_NO_CHANGE:
{ if (!mrioc->sas_transport_enabled || tgtdev->non_stl
|| tgtdev->is_hidden) break;
link_rate = event_data->phy_entry[i].link_rate >> 4;
prev_link_rate = event_data->phy_entry[i].link_rate & 0xF; if (link_rate == prev_link_rate) break; if (!parent_sas_address) break;
parent_phy_number = event_data->start_phy_num + i;
mpi3mr_update_links(mrioc, parent_sas_address, handle,
parent_phy_number, link_rate, hba_port); break;
} default: break;
} if (tgtdev)
mpi3mr_tgtdev_put(tgtdev);
}
if (mrioc->sas_transport_enabled && (event_data->exp_status ==
MPI3_EVENT_SAS_TOPO_ES_NOT_RESPONDING)) { if (sas_expander)
mpi3mr_expander_remove(mrioc, exp_sas_address,
hba_port);
}
}
/** * mpi3mr_pcietopochg_evt_debug - PCIeTopoChange details * @mrioc: Adapter instance reference * @event_data: PCIe topology change list event data * * Prints information about the PCIe topology change event. * * Return: Nothing.
*/ staticvoid
mpi3mr_pcietopochg_evt_debug(struct mpi3mr_ioc *mrioc, struct mpi3_event_data_pcie_topology_change_list *event_data)
{ int i;
u16 handle;
u16 reason_code;
u8 port_number; char *status_str = NULL;
u8 link_rate, prev_link_rate;
switch (event_data->switch_status) { case MPI3_EVENT_PCIE_TOPO_SS_NOT_RESPONDING:
status_str = "remove"; break; case MPI3_EVENT_PCIE_TOPO_SS_RESPONDING:
status_str = "responding"; break; case MPI3_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING:
status_str = "remove delay"; break; case MPI3_EVENT_PCIE_TOPO_SS_NO_PCIE_SWITCH:
status_str = "direct attached"; break; default:
status_str = "unknown status"; break;
}
ioc_info(mrioc, "%s :pcie topology change: (%s)\n",
__func__, status_str);
ioc_info(mrioc, "%s :\tswitch_handle(0x%04x), enclosure_handle(0x%04x) start_port(%02d), num_entries(%d)\n",
__func__, le16_to_cpu(event_data->switch_dev_handle),
le16_to_cpu(event_data->enclosure_handle),
event_data->start_port_num, event_data->num_entries); for (i = 0; i < event_data->num_entries; i++) {
handle =
le16_to_cpu(event_data->port_entry[i].attached_dev_handle); if (!handle) continue;
port_number = event_data->start_port_num + i;
reason_code = event_data->port_entry[i].port_status; switch (reason_code) { case MPI3_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
status_str = "target remove"; break; case MPI3_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING:
status_str = "delay target remove"; break; case MPI3_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
status_str = "link status change"; break; case MPI3_EVENT_PCIE_TOPO_PS_NO_CHANGE:
status_str = "link status no change"; break; case MPI3_EVENT_PCIE_TOPO_PS_RESPONDING:
status_str = "target responding"; break; default:
status_str = "unknown"; break;
}
link_rate = event_data->port_entry[i].current_port_info &
MPI3_EVENT_PCIE_TOPO_PI_RATE_MASK;
prev_link_rate = event_data->port_entry[i].previous_port_info &
MPI3_EVENT_PCIE_TOPO_PI_RATE_MASK;
ioc_info(mrioc, "%s :\tport(%02d), attached_handle(0x%04x): %s: link rate: new(0x%02x), old(0x%02x)\n",
__func__, port_number, handle, status_str, link_rate,
prev_link_rate);
}
}
/** * mpi3mr_pcietopochg_evt_bh - PCIeTopologyChange evt bottomhalf * @mrioc: Adapter instance reference * @fwevt: Firmware event reference * * Prints information about the PCIe topology change event and * for "not responding" event code, removes the device from the * upper layers. * * Return: Nothing.
*/ staticvoid mpi3mr_pcietopochg_evt_bh(struct mpi3mr_ioc *mrioc, struct mpi3mr_fwevt *fwevt)
{ struct mpi3_event_data_pcie_topology_change_list *event_data =
(struct mpi3_event_data_pcie_topology_change_list *)fwevt->event_data; int i;
u16 handle;
u8 reason_code; struct mpi3mr_tgt_dev *tgtdev = NULL;
mpi3mr_pcietopochg_evt_debug(mrioc, event_data);
for (i = 0; i < event_data->num_entries; i++) { if (fwevt->discard) return;
handle =
le16_to_cpu(event_data->port_entry[i].attached_dev_handle); if (!handle) continue;
tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle); if (!tgtdev) continue;
switch (reason_code) { case MPI3_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: if (tgtdev->host_exposed)
mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
mpi3mr_tgtdev_del_from_list(mrioc, tgtdev, false);
mpi3mr_tgtdev_put(tgtdev); break; default: break;
} if (tgtdev)
mpi3mr_tgtdev_put(tgtdev);
}
}
/** * mpi3mr_logdata_evt_bh - Log data event bottomhalf * @mrioc: Adapter instance reference * @fwevt: Firmware event reference * * Extracts the event data and calls application interfacing * function to process the event further. * * Return: Nothing.
*/ staticvoid mpi3mr_logdata_evt_bh(struct mpi3mr_ioc *mrioc, struct mpi3mr_fwevt *fwevt)
{
mpi3mr_app_save_logdata(mrioc, fwevt->event_data,
fwevt->event_data_size);
}
/** * mpi3mr_update_sdev_qd - Update SCSI device queue depath * @sdev: SCSI device reference * @data: Queue depth reference * * This is an iterator function called for each SCSI device in a * target to update the QD of each SCSI device. * * Return: Nothing.
*/ staticvoid mpi3mr_update_sdev_qd(struct scsi_device *sdev, void *data)
{
u16 *q_depth = (u16 *)data;
if (mrioc->stop_drv_processing) {
dprint_event_bh(mrioc, "ignoring event(0x%02x) in the bottom half handler\n" "due to stop_drv_processing\n", fwevt->event_id); goto out;
}
if (mrioc->unrecoverable) {
dprint_event_bh(mrioc, "ignoring event(0x%02x) in bottom half handler due to unrecoverable controller\n",
fwevt->event_id); goto out;
}
if (!fwevt->process_evt) goto evt_ack;
dprint_event_bh(mrioc, "processing event(0x%02x) -(0x%08x) in the bottom half handler\n",
fwevt->event_id, fwevt->evt_ctx);
if (mrioc->unrecoverable || mrioc->pci_err_recovery) break;
dprint_event_bh(mrioc, "scan for non responding and newly added devices after soft reset started\n"); if (mrioc->sas_transport_enabled) {
mpi3mr_refresh_sas_ports(mrioc);
mpi3mr_refresh_expanders(mrioc);
}
mpi3mr_refresh_tgtdevs(mrioc);
ioc_info(mrioc, "scan for non responding and newly added devices after soft reset completed\n"); break;
} case MPI3MR_DRIVER_EVENT_PROCESS_TRIGGER:
{
mpi3mr_process_trigger_data_event_bh(mrioc,
(struct trigger_event_data *)fwevt->event_data); break;
} default: break;
}
evt_ack: if (fwevt->send_ack)
mpi3mr_process_event_ack(mrioc, fwevt->event_id,
fwevt->evt_ctx);
out: /* Put fwevt reference count to neutralize kref_init increment */
mpi3mr_fwevt_put(fwevt);
mrioc->current_event = NULL;
}
/** * mpi3mr_fwevt_worker - Firmware event worker * @work: Work struct containing firmware event * * Extracts the firmware event and calls mpi3mr_fwevt_bh. * * Return: Nothing.
*/ staticvoid mpi3mr_fwevt_worker(struct work_struct *work)
{ struct mpi3mr_fwevt *fwevt = container_of(work, struct mpi3mr_fwevt,
work);
mpi3mr_fwevt_bh(fwevt->mrioc, fwevt); /* * Put fwevt reference count after * dequeuing it from worker queue
*/
mpi3mr_fwevt_put(fwevt);
}
/** * mpi3mr_create_tgtdev - Create and add a target device * @mrioc: Adapter instance reference * @dev_pg0: Device Page 0 data * * If the device specified by the device page 0 data is not * present in the driver's internal list, allocate the memory * for the device, populate the data and add to the list, else * update the device data. The key is persistent ID. * * Return: 0 on success, -ENOMEM on memory allocation failure
*/ staticint mpi3mr_create_tgtdev(struct mpi3mr_ioc *mrioc, struct mpi3_device_page0 *dev_pg0)
{ int retval = 0; struct mpi3mr_tgt_dev *tgtdev = NULL;
u16 perst_id = 0; unsignedlong flags;
perst_id = le16_to_cpu(dev_pg0->persistent_id); if (perst_id == MPI3_DEVICE0_PERSISTENTID_INVALID) return retval;
/** * mpi3mr_send_event_ack - Issue event acknwoledgment request * @mrioc: Adapter instance reference * @event: MPI3 event id * @cmdparam: Internal command tracker * @event_ctx: event context * * Issues event acknowledgment request to the firmware if there * is a free command to send the event ack else it to a pend * list so that it will be processed on a completion of a prior * event acknowledgment . * * Return: Nothing
*/ staticvoid mpi3mr_send_event_ack(struct mpi3mr_ioc *mrioc, u8 event, struct mpi3mr_drv_cmd *cmdparam, u32 event_ctx)
{ struct mpi3_event_ack_request evtack_req; int retval = 0;
u8 retrycount = 5;
u16 cmd_idx = MPI3MR_NUM_EVTACKCMD; struct mpi3mr_drv_cmd *drv_cmd = cmdparam; struct delayed_evt_ack_node *delayed_evtack = NULL;
if (drv_cmd) {
dprint_event_th(mrioc, "sending delayed event ack in the top half for event(0x%02x), event_ctx(0x%08x)\n",
event, event_ctx); goto issue_cmd;
}
dprint_event_th(mrioc, "sending event ack in the top half for event(0x%02x), event_ctx(0x%08x)\n",
event, event_ctx); do {
cmd_idx = find_first_zero_bit(mrioc->evtack_cmds_bitmap,
MPI3MR_NUM_EVTACKCMD); if (cmd_idx < MPI3MR_NUM_EVTACKCMD) { if (!test_and_set_bit(cmd_idx,
mrioc->evtack_cmds_bitmap)) break;
cmd_idx = MPI3MR_NUM_EVTACKCMD;
}
} while (retrycount--);
if (cmd_idx >= MPI3MR_NUM_EVTACKCMD) {
delayed_evtack = kzalloc(sizeof(*delayed_evtack),
GFP_ATOMIC); if (!delayed_evtack) return;
INIT_LIST_HEAD(&delayed_evtack->list);
delayed_evtack->event = event;
delayed_evtack->event_ctx = event_ctx;
list_add_tail(&delayed_evtack->list,
&mrioc->delayed_evtack_cmds_list);
dprint_event_th(mrioc, "event ack in the top half for event(0x%02x), event_ctx(0x%08x) is postponed\n",
event, event_ctx); return;
}
drv_cmd = &mrioc->evtack_cmds[cmd_idx];
dprint_event_th(mrioc, "event ack in the top half for event(0x%02x), event_ctx(0x%08x) is posted\n",
event, event_ctx);
out: return;
out_failed:
drv_cmd->state = MPI3MR_CMD_NOTUSED;
drv_cmd->callback = NULL;
clear_bit(cmd_idx, mrioc->evtack_cmds_bitmap);
}
/** * mpi3mr_pcietopochg_evt_th - PCIETopologyChange evt tophalf * @mrioc: Adapter instance reference * @event_reply: event data * * Checks for the reason code and based on that either block I/O * to device, or unblock I/O to the device, or start the device * removal handshake with reason as remove with the firmware for * PCIe devices. * * Return: Nothing
*/ staticvoid mpi3mr_pcietopochg_evt_th(struct mpi3mr_ioc *mrioc, struct mpi3_event_notification_reply *event_reply)
{ struct mpi3_event_data_pcie_topology_change_list *topo_evt =
(struct mpi3_event_data_pcie_topology_change_list *)event_reply->event_data; int i;
u16 handle;
u8 reason_code; struct mpi3mr_tgt_dev *tgtdev = NULL; struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL;
for (i = 0; i < topo_evt->num_entries; i++) {
handle = le16_to_cpu(topo_evt->port_entry[i].attached_dev_handle); if (!handle) continue;
reason_code = topo_evt->port_entry[i].port_status;
scsi_tgt_priv_data = NULL;
tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle); if (tgtdev && tgtdev->starget && tgtdev->starget->hostdata)
scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
tgtdev->starget->hostdata; switch (reason_code) { case MPI3_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: if (scsi_tgt_priv_data) {
scsi_tgt_priv_data->dev_removed = 1;
scsi_tgt_priv_data->dev_removedelay = 0;
atomic_set(&scsi_tgt_priv_data->block_io, 0);
}
mpi3mr_dev_rmhs_send_tm(mrioc, handle, NULL,
MPI3_CTRL_OP_REMOVE_DEVICE); break; case MPI3_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING: if (scsi_tgt_priv_data) {
scsi_tgt_priv_data->dev_removedelay = 1;
atomic_inc(&scsi_tgt_priv_data->block_io);
} break; case MPI3_EVENT_PCIE_TOPO_PS_RESPONDING: if (scsi_tgt_priv_data &&
scsi_tgt_priv_data->dev_removedelay) {
scsi_tgt_priv_data->dev_removedelay = 0;
atomic_dec_if_positive
(&scsi_tgt_priv_data->block_io);
} break; case MPI3_EVENT_PCIE_TOPO_PS_PORT_CHANGED: default: break;
} if (tgtdev)
mpi3mr_tgtdev_put(tgtdev);
}
}
/** * mpi3mr_sastopochg_evt_th - SASTopologyChange evt tophalf * @mrioc: Adapter instance reference * @event_reply: event data * * Checks for the reason code and based on that either block I/O * to device, or unblock I/O to the device, or start the device * removal handshake with reason as remove with the firmware for * SAS/SATA devices. * * Return: Nothing
*/ staticvoid mpi3mr_sastopochg_evt_th(struct mpi3mr_ioc *mrioc, struct mpi3_event_notification_reply *event_reply)
{ struct mpi3_event_data_sas_topology_change_list *topo_evt =
(struct mpi3_event_data_sas_topology_change_list *)event_reply->event_data; int i;
u16 handle;
u8 reason_code; struct mpi3mr_tgt_dev *tgtdev = NULL; struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL;
for (i = 0; i < topo_evt->num_entries; i++) {
handle = le16_to_cpu(topo_evt->phy_entry[i].attached_dev_handle); if (!handle) continue;
reason_code = topo_evt->phy_entry[i].status &
MPI3_EVENT_SAS_TOPO_PHY_RC_MASK;
scsi_tgt_priv_data = NULL;
tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle); if (tgtdev && tgtdev->starget && tgtdev->starget->hostdata)
scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
tgtdev->starget->hostdata; switch (reason_code) { case MPI3_EVENT_SAS_TOPO_PHY_RC_TARG_NOT_RESPONDING: if (scsi_tgt_priv_data) {
scsi_tgt_priv_data->dev_removed = 1;
scsi_tgt_priv_data->dev_removedelay = 0;
atomic_set(&scsi_tgt_priv_data->block_io, 0);
}
mpi3mr_dev_rmhs_send_tm(mrioc, handle, NULL,
MPI3_CTRL_OP_REMOVE_DEVICE); break; case MPI3_EVENT_SAS_TOPO_PHY_RC_DELAY_NOT_RESPONDING: if (scsi_tgt_priv_data) {
scsi_tgt_priv_data->dev_removedelay = 1;
atomic_inc(&scsi_tgt_priv_data->block_io);
} break; case MPI3_EVENT_SAS_TOPO_PHY_RC_RESPONDING: if (scsi_tgt_priv_data &&
scsi_tgt_priv_data->dev_removedelay) {
scsi_tgt_priv_data->dev_removedelay = 0;
atomic_dec_if_positive
(&scsi_tgt_priv_data->block_io);
} break; case MPI3_EVENT_SAS_TOPO_PHY_RC_PHY_CHANGED: default: break;
} if (tgtdev)
mpi3mr_tgtdev_put(tgtdev);
}
}
/** * mpi3mr_devstatuschg_evt_th - DeviceStatusChange evt tophalf * @mrioc: Adapter instance reference * @event_reply: event data * * Checks for the reason code and based on that either block I/O * to device, or unblock I/O to the device, or start the device * removal handshake with reason as remove/hide acknowledgment * with the firmware. * * Return: Nothing
*/ staticvoid mpi3mr_devstatuschg_evt_th(struct mpi3mr_ioc *mrioc, struct mpi3_event_notification_reply *event_reply)
{
u16 dev_handle = 0;
u8 ublock = 0, block = 0, hide = 0, delete = 0, remove = 0; struct mpi3mr_tgt_dev *tgtdev = NULL; struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL; struct mpi3_event_data_device_status_change *evtdata =
(struct mpi3_event_data_device_status_change *)event_reply->event_data;
if (mrioc->stop_drv_processing) goto out;
dev_handle = le16_to_cpu(evtdata->dev_handle);
dprint_event_th(mrioc, "device status change event top half with rc(0x%02x) for handle(0x%04x)\n",
evtdata->reason_code, dev_handle);
switch (evtdata->reason_code) { case MPI3_EVENT_DEV_STAT_RC_INT_DEVICE_RESET_STRT: case MPI3_EVENT_DEV_STAT_RC_INT_IT_NEXUS_RESET_STRT:
block = 1; break; case MPI3_EVENT_DEV_STAT_RC_HIDDEN: delete = 1;
hide = 1; break; case MPI3_EVENT_DEV_STAT_RC_VD_NOT_RESPONDING: delete = 1;
remove = 1; break; case MPI3_EVENT_DEV_STAT_RC_INT_DEVICE_RESET_CMP: case MPI3_EVENT_DEV_STAT_RC_INT_IT_NEXUS_RESET_CMP:
ublock = 1; break; default: break;
}
tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, dev_handle); if (!tgtdev) {
dprint_event_th(mrioc, "processing device status change event could not identify device for handle(0x%04x)\n",
dev_handle); goto out;
} if (hide)
tgtdev->is_hidden = hide; if (tgtdev->starget && tgtdev->starget->hostdata) {
scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *)
tgtdev->starget->hostdata; if (block)
atomic_inc(&scsi_tgt_priv_data->block_io); if (delete)
scsi_tgt_priv_data->dev_removed = 1; if (ublock)
atomic_dec_if_positive(&scsi_tgt_priv_data->block_io);
} if (remove)
mpi3mr_dev_rmhs_send_tm(mrioc, dev_handle, NULL,
MPI3_CTRL_OP_REMOVE_DEVICE); if (hide)
mpi3mr_dev_rmhs_send_tm(mrioc, dev_handle, NULL,
MPI3_CTRL_OP_HIDDEN_ACK);
out: if (tgtdev)
mpi3mr_tgtdev_put(tgtdev);
}
/** * mpi3mr_preparereset_evt_th - Prepare for reset event tophalf * @mrioc: Adapter instance reference * @event_reply: event data * * Blocks and unblocks host level I/O based on the reason code * * Return: Nothing
*/ staticvoid mpi3mr_preparereset_evt_th(struct mpi3mr_ioc *mrioc, struct mpi3_event_notification_reply *event_reply)
{ struct mpi3_event_data_prepare_for_reset *evtdata =
(struct mpi3_event_data_prepare_for_reset *)event_reply->event_data;
if (evtdata->reason_code == MPI3_EVENT_PREPARE_RESET_RC_START) {
dprint_event_th(mrioc, "prepare for reset event top half with rc=start\n"); if (mrioc->prepare_for_reset) return;
scsi_block_requests(mrioc->shost);
mrioc->prepare_for_reset = 1;
mrioc->prepare_for_reset_timeout_counter = 0;
} elseif (evtdata->reason_code == MPI3_EVENT_PREPARE_RESET_RC_ABORT) {
dprint_event_th(mrioc, "prepare for reset top half with rc=abort\n");
mrioc->prepare_for_reset = 0;
scsi_unblock_requests(mrioc->shost);
mrioc->prepare_for_reset_timeout_counter = 0;
} if ((event_reply->msg_flags & MPI3_EVENT_NOTIFY_MSGFLAGS_ACK_MASK)
== MPI3_EVENT_NOTIFY_MSGFLAGS_ACK_REQUIRED)
mpi3mr_send_event_ack(mrioc, event_reply->event, NULL,
le32_to_cpu(event_reply->event_context));
}
/** * mpi3mr_energypackchg_evt_th - Energy pack change evt tophalf * @mrioc: Adapter instance reference * @event_reply: event data * * Identifies the new shutdown timeout value and update. * * Return: Nothing
*/ staticvoid mpi3mr_energypackchg_evt_th(struct mpi3mr_ioc *mrioc, struct mpi3_event_notification_reply *event_reply)
{ struct mpi3_event_data_energy_pack_change *evtdata =
(struct mpi3_event_data_energy_pack_change *)event_reply->event_data;
u16 shutdown_timeout = le16_to_cpu(evtdata->shutdown_timeout);
if (shutdown_timeout <= 0) {
dprint_event_th(mrioc, "%s :Invalid Shutdown Timeout received = %d\n",
__func__, shutdown_timeout); return;
}
dprint_event_th(mrioc, "%s :Previous Shutdown Timeout Value = %d New Shutdown Timeout Value = %d\n",
__func__, mrioc->facts.shutdown_timeout, shutdown_timeout);
mrioc->facts.shutdown_timeout = shutdown_timeout;
}
switch (evtdata->status) { case MPI3_EVENT_CABLE_MGMT_STATUS_INSUFFICIENT_POWER:
{
ioc_info(mrioc, "An active cable with receptacle_id %d cannot be powered.\n" "Devices connected to this cable are not detected.\n" "This cable requires %d mW of power.\n",
evtdata->receptacle_id,
le32_to_cpu(evtdata->active_cable_power_requirement)); break;
} case MPI3_EVENT_CABLE_MGMT_STATUS_DEGRADED:
{
ioc_info(mrioc, "A cable with receptacle_id %d is not running at optimal speed\n",
evtdata->receptacle_id); break;
} default: break;
}
}
/** * mpi3mr_add_event_wait_for_device_refresh - Add Wait for Device Refresh Event * @mrioc: Adapter instance reference * * Add driver specific event to make sure that the driver won't process the * events until all the devices are refreshed during soft reset. * * Return: Nothing
*/ void mpi3mr_add_event_wait_for_device_refresh(struct mpi3mr_ioc *mrioc)
{ struct mpi3mr_fwevt *fwevt = NULL;
/** * mpi3mr_build_sense_buffer - Map sense information * @desc: Sense type * @buf: Sense buffer to populate * @key: Sense key * @asc: Additional sense code * @ascq: Additional sense code qualifier * * Maps the given sense information into either descriptor or * fixed format sense data. * * Return: Nothing
*/ staticinlinevoid mpi3mr_build_sense_buffer(int desc, u8 *buf, u8 key,
u8 asc, u8 ascq)
{ if (desc) {
buf[0] = 0x72; /* descriptor, current */
buf[1] = key;
buf[2] = asc;
buf[3] = ascq;
buf[7] = 0;
} else {
buf[0] = 0x70; /* fixed, current */
buf[2] = key;
buf[7] = 0xa;
buf[12] = asc;
buf[13] = ascq;
}
}
/** * mpi3mr_map_eedp_error - Map EEDP errors from IOC status * @scmd: SCSI command reference * @ioc_status: status of MPI3 request * * Maps the EEDP error status of the SCSI IO request to sense * data. * * Return: Nothing
*/ staticvoid mpi3mr_map_eedp_error(struct scsi_cmnd *scmd,
u16 ioc_status)
{
u8 ascq = 0;
switch (ioc_status) { case MPI3_IOCSTATUS_EEDP_GUARD_ERROR:
ascq = 0x01; break; case MPI3_IOCSTATUS_EEDP_APP_TAG_ERROR:
ascq = 0x02; break; case MPI3_IOCSTATUS_EEDP_REF_TAG_ERROR:
ascq = 0x03; break; default:
ascq = 0x00; break;
}
/** * mpi3mr_get_chain_idx - get free chain buffer index * @mrioc: Adapter instance reference * * Try to get a free chain buffer index from the free pool. * * Return: -1 on failure or the free chain buffer index
*/ staticint mpi3mr_get_chain_idx(struct mpi3mr_ioc *mrioc)
{
u8 retry_count = 5; int cmd_idx = -1; unsignedlong flags;
spin_lock_irqsave(&mrioc->chain_buf_lock, flags); do {
cmd_idx = find_first_zero_bit(mrioc->chain_bitmap,
mrioc->chain_buf_count); if (cmd_idx < mrioc->chain_buf_count) {
set_bit(cmd_idx, mrioc->chain_bitmap); break;
}
cmd_idx = -1;
} while (retry_count--);
spin_unlock_irqrestore(&mrioc->chain_buf_lock, flags); return cmd_idx;
}
/** * mpi3mr_prepare_sg_scmd - build scatter gather list * @mrioc: Adapter instance reference * @scmd: SCSI command reference * @scsiio_req: MPI3 SCSI IO request * * This function maps SCSI command's data and protection SGEs to * MPI request SGEs. If required additional 4K chain buffer is * used to send the SGEs. * * Return: 0 on success, -ENOMEM on dma_map_sg failure
*/ staticint mpi3mr_prepare_sg_scmd(struct mpi3mr_ioc *mrioc, struct scsi_cmnd *scmd, struct mpi3_scsi_io_request *scsiio_req)
{
dma_addr_t chain_dma; struct scatterlist *sg_scmd; void *sg_local, *chain;
u32 chain_length; int sges_left, chain_idx;
u32 sges_in_segment;
u8 simple_sgl_flags;
u8 simple_sgl_flags_last;
u8 last_chain_sgl_flags; struct chain_element *chain_req; struct scmd_priv *priv = NULL;
u32 meta_sg = le32_to_cpu(scsiio_req->flags) &
MPI3_SCSIIO_FLAGS_DMAOPERATION_HOST_PI;
if (meta_sg)
sg_local = &scsiio_req->sgl[MPI3_SCSIIO_METASGL_INDEX]; else
sg_local = &scsiio_req->sgl;
if (!scsiio_req->data_length && !meta_sg) {
mpi3mr_build_zero_len_sge(sg_local); return 0;
}
if (meta_sg) {
sg_scmd = scsi_prot_sglist(scmd);
sges_left = dma_map_sg(&mrioc->pdev->dev,
scsi_prot_sglist(scmd),
scsi_prot_sg_count(scmd),
scmd->sc_data_direction);
priv->meta_sg_valid = 1; /* To unmap meta sg DMA */
} else { /* * Some firmware versions byte-swap the REPORT ZONES command * reply from ATA-ZAC devices by directly accessing in the host * buffer. This does not respect the default command DMA * direction and causes IOMMU page faults on some architectures * with an IOMMU enforcing write mappings (e.g. AMD hosts). * Avoid such issue by making the REPORT ZONES buffer mapping * bi-directional.
*/ if (scmd->cmnd[0] == ZBC_IN && scmd->cmnd[1] == ZI_REPORT_ZONES)
scmd->sc_data_direction = DMA_BIDIRECTIONAL;
sg_scmd = scsi_sglist(scmd);
sges_left = scsi_dma_map(scmd);
}
if (sges_left < 0) {
sdev_printk(KERN_ERR, scmd->device, "scsi_dma_map failed: request for %d bytes!\n",
scsi_bufflen(scmd)); return -ENOMEM;
} if (sges_left > mrioc->max_sgl_entries) {
sdev_printk(KERN_ERR, scmd->device, "scsi_dma_map returned unsupported sge count %d!\n",
sges_left); return -ENOMEM;
}
if (scsiio_req->msg_flags ==
MPI3_SCSIIO_MSGFLAGS_METASGL_VALID && !meta_sg) {
sges_in_segment--; /* Reserve last segment (scsiio_req->sgl[3]) for meta sg */
}
if (meta_sg)
sges_in_segment = 1;
if (sges_left <= sges_in_segment) goto fill_in_last_segment;
/* fill in main message segment when there is a chain following */ while (sges_in_segment > 1) {
mpi3mr_add_sg_single(sg_local, simple_sgl_flags,
sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
sg_scmd = sg_next(sg_scmd);
sg_local += sizeof(struct mpi3_sge_common);
sges_left--;
sges_in_segment--;
}
/** * mpi3mr_build_sg_scmd - build scatter gather list for SCSI IO * @mrioc: Adapter instance reference * @scmd: SCSI command reference * @scsiio_req: MPI3 SCSI IO request * * This function calls mpi3mr_prepare_sg_scmd for constructing * both data SGEs and protection information SGEs in the MPI * format from the SCSI Command as appropriate . * * Return: return value of mpi3mr_prepare_sg_scmd.
*/ staticint mpi3mr_build_sg_scmd(struct mpi3mr_ioc *mrioc, struct scsi_cmnd *scmd, struct mpi3_scsi_io_request *scsiio_req)
{ int ret;
ret = mpi3mr_prepare_sg_scmd(mrioc, scmd, scsiio_req); if (ret) return ret;
if (scsiio_req->msg_flags == MPI3_SCSIIO_MSGFLAGS_METASGL_VALID) { /* There is a valid meta sg */
scsiio_req->flags |=
cpu_to_le32(MPI3_SCSIIO_FLAGS_DMAOPERATION_HOST_PI);
ret = mpi3mr_prepare_sg_scmd(mrioc, scmd, scsiio_req);
}
return ret;
}
/** * mpi3mr_tm_response_name - get TM response as a string * @resp_code: TM response code * * Convert known task management response code as a readable * string. * * Return: response code string.
*/ staticconstchar *mpi3mr_tm_response_name(u8 resp_code)
{ char *desc;
switch (resp_code) { case MPI3_SCSITASKMGMT_RSPCODE_TM_COMPLETE:
desc = "task management request completed"; break; case MPI3_SCSITASKMGMT_RSPCODE_INVALID_FRAME:
desc = "invalid frame"; break; case MPI3_SCSITASKMGMT_RSPCODE_TM_FUNCTION_NOT_SUPPORTED:
desc = "task management request not supported"; break; case MPI3_SCSITASKMGMT_RSPCODE_TM_FAILED:
desc = "task management request failed"; break; case MPI3_SCSITASKMGMT_RSPCODE_TM_SUCCEEDED:
desc = "task management request succeeded"; break; case MPI3_SCSITASKMGMT_RSPCODE_TM_INVALID_LUN:
desc = "invalid LUN"; break; case MPI3_SCSITASKMGMT_RSPCODE_TM_OVERLAPPED_TAG:
desc = "overlapped tag attempted"; break; case MPI3_SCSITASKMGMT_RSPCODE_IO_QUEUED_ON_IOC:
desc = "task queued, however not sent to target"; break; case MPI3_SCSITASKMGMT_RSPCODE_TM_NVME_DENIED:
desc = "task management request denied by NVMe device"; break; default:
desc = "unknown"; break;
}
return desc;
}
inlinevoid mpi3mr_poll_pend_io_completions(struct mpi3mr_ioc *mrioc)
{ int i; int num_of_reply_queues =
mrioc->num_op_reply_q + mrioc->op_reply_q_offset;
for (i = mrioc->op_reply_q_offset; i < num_of_reply_queues; i++)
mpi3mr_process_op_reply_q(mrioc,
mrioc->intr_info[i].op_reply_q);
}
/** * mpi3mr_issue_tm - Issue Task Management request * @mrioc: Adapter instance reference * @tm_type: Task Management type * @handle: Device handle * @lun: lun ID * @htag: Host tag of the TM request * @timeout: TM timeout value * @drv_cmd: Internal command tracker * @resp_code: Response code place holder * @scmd: SCSI command * * Issues a Task Management Request to the controller for a * specified target, lun and command and wait for its completion * and check TM response. Recover the TM if it timed out by * issuing controller reset. * * Return: 0 on success, non-zero on errors
*/ int mpi3mr_issue_tm(struct mpi3mr_ioc *mrioc, u8 tm_type,
u16 handle, uint lun, u16 htag, ulong timeout, struct mpi3mr_drv_cmd *drv_cmd,
u8 *resp_code, struct scsi_cmnd *scmd)
{ struct mpi3_scsi_task_mgmt_request tm_req; struct mpi3_scsi_task_mgmt_reply *tm_reply = NULL; int retval = 0; struct mpi3mr_tgt_dev *tgtdev = NULL; struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data = NULL; struct scmd_priv *cmd_priv = NULL; struct scsi_device *sdev = NULL; struct mpi3mr_sdev_priv_data *sdev_priv_data = NULL;
ioc_info(mrioc, "%s :Issue TM: TM type (0x%x) for devhandle 0x%04x\n",
__func__, tm_type, handle); if (mrioc->unrecoverable) {
retval = -1;
ioc_err(mrioc, "%s :Issue TM: Unrecoverable controller\n",
__func__); goto out;
}
memset(&tm_req, 0, sizeof(tm_req));
mutex_lock(&drv_cmd->mutex); if (drv_cmd->state & MPI3MR_CMD_PENDING) {
retval = -1;
ioc_err(mrioc, "%s :Issue TM: Command is in use\n", __func__);
mutex_unlock(&drv_cmd->mutex); goto out;
} if (mrioc->reset_in_progress) {
retval = -1;
ioc_err(mrioc, "%s :Issue TM: Reset in progress\n", __func__);
mutex_unlock(&drv_cmd->mutex); goto out;
} if (mrioc->block_on_pci_err) {
retval = -1;
dprint_tm(mrioc, "sending task management failed due to\n" "pci error recovery in progress\n");
mutex_unlock(&drv_cmd->mutex); goto out;
}
for (i = 0, qoff = 0; i < HCTX_MAX_TYPES; i++) {
map = &shost->tag_set.map[i];
map->nr_queues = 0;
if (i == HCTX_TYPE_DEFAULT)
map->nr_queues = mrioc->default_qcount; elseif (i == HCTX_TYPE_POLL)
map->nr_queues = mrioc->active_poll_qcount;
if (!map->nr_queues) {
BUG_ON(i == HCTX_TYPE_DEFAULT); continue;
}
/* * The poll queue(s) doesn't have an IRQ (and hence IRQ * affinity), so use the regular blk-mq cpu mapping
*/
map->queue_offset = qoff; if (i != HCTX_TYPE_POLL)
blk_mq_map_hw_queues(map, &mrioc->pdev->dev, offset); else
blk_mq_map_queues(map);
/** * mpi3mr_wait_for_host_io - block for I/Os to complete * @mrioc: Adapter instance reference * @timeout: time out in seconds * Waits for pending I/Os for the given adapter to complete or * to hit the timeout. * * Return: Nothing
*/ void mpi3mr_wait_for_host_io(struct mpi3mr_ioc *mrioc, u32 timeout)
{ enum mpi3mr_iocstate iocstate; int i = 0;
iocstate = mpi3mr_get_iocstate(mrioc); if (iocstate != MRIOC_STATE_READY) return;
if (!mpi3mr_get_fw_pending_ios(mrioc)) return;
ioc_info(mrioc, "%s :Waiting for %d seconds prior to reset for %d I/O\n",
__func__, timeout, mpi3mr_get_fw_pending_ios(mrioc));
for (i = 0; i < timeout; i++) { if (!mpi3mr_get_fw_pending_ios(mrioc)) break;
iocstate = mpi3mr_get_iocstate(mrioc); if (iocstate != MRIOC_STATE_READY) break;
msleep(1000);
}
ioc_info(mrioc, "%s :Pending I/Os after wait is: %d\n", __func__,
mpi3mr_get_fw_pending_ios(mrioc));
}
/** * mpi3mr_setup_divert_ws - Setup Divert IO flag for write same * @mrioc: Adapter instance reference * @scmd: SCSI command reference * @scsiio_req: MPI3 SCSI IO request * @scsiio_flags: Pointer to MPI3 SCSI IO Flags * @wslen: write same max length * * Gets values of unmap, ndob and number of blocks from write * same scsi io and based on these values it sets divert IO flag * and reason for diverting IO to firmware. * * Return: Nothing
*/ staticinlinevoid mpi3mr_setup_divert_ws(struct mpi3mr_ioc *mrioc, struct scsi_cmnd *scmd, struct mpi3_scsi_io_request *scsiio_req,
u32 *scsiio_flags, u16 wslen)
{
u8 unmap = 0, ndob = 0;
u8 opcode = scmd->cmnd[0];
u32 num_blocks = 0;
u16 sa = (scmd->cmnd[8] << 8) | (scmd->cmnd[9]);
mrioc->scan_started = 1;
ioc_info(mrioc, "%s :Issuing Port Enable\n", __func__); if (mpi3mr_issue_port_enable(mrioc, 1)) {
ioc_err(mrioc, "%s :Issuing port enable failed\n", __func__);
mrioc->scan_started = 0;
mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
}
}
/** * mpi3mr_scan_finished - Scan finished callback handler * @shost: SCSI host reference * @time: Jiffies from the scan start * * Checks whether the port enable is completed or timedout or * failed and set the scan status accordingly after taking any * recovery if required. * * Return: 1 on scan finished or timed out, 0 for in progress
*/ staticint mpi3mr_scan_finished(struct Scsi_Host *shost, unsignedlong time)
{ struct mpi3mr_ioc *mrioc = shost_priv(shost);
u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
u32 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
(ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
ioc_err(mrioc, "port enable failed due to fault or reset\n");
mpi3mr_print_fault_info(mrioc);
mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
mrioc->scan_started = 0;
mrioc->init_cmds.is_waiting = 0;
mrioc->init_cmds.callback = NULL;
mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
}
if (time >= (pe_timeout * HZ)) {
ioc_err(mrioc, "port enable failed due to time out\n");
mpi3mr_check_rh_fault_ioc(mrioc,
MPI3MR_RESET_FROM_PE_TIMEOUT);
mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
mrioc->scan_started = 0;
mrioc->init_cmds.is_waiting = 0;
mrioc->init_cmds.callback = NULL;
mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
}
if (mrioc->scan_started) return 0;
if (mrioc->scan_failed) {
ioc_err(mrioc, "port enable failed with status=0x%04x\n",
mrioc->scan_failed);
} else
ioc_info(mrioc, "port enable is successfully completed\n");
/** * mpi3mr_check_return_unmap - Whether an unmap is allowed * @mrioc: Adapter instance reference * @scmd: SCSI Command reference * * The controller hardware cannot handle certain unmap commands * for NVMe drives, this routine checks those and return true * and completes the SCSI command with proper status and sense * data. * * Return: TRUE for not allowed unmap, FALSE otherwise.
*/ staticbool mpi3mr_check_return_unmap(struct mpi3mr_ioc *mrioc, struct scsi_cmnd *scmd)
{ unsignedchar *buf;
u16 param_len, desc_len, trunc_param_len;
/** * mpi3mr_init_drv_cmd - Initialize internal command tracker * @cmdptr: Internal command tracker * @host_tag: Host tag used for the specific command * * Initialize the internal command tracker structure with * specified host tag. * * Return: Nothing.
*/ staticinlinevoid mpi3mr_init_drv_cmd(struct mpi3mr_drv_cmd *cmdptr,
u16 host_tag)
{
mutex_init(&cmdptr->mutex);
cmdptr->reply = NULL;
cmdptr->state = MPI3MR_CMD_NOTUSED;
cmdptr->dev_handle = MPI3MR_INVALID_DEV_HANDLE;
cmdptr->host_tag = host_tag;
}
/** * osintfc_mrioc_security_status -Check controller secure status * @pdev: PCI device instance * * Read the Device Serial Number capability from PCI config * space and decide whether the controller is secure or not. * * Return: 0 on success, non-zero on failure.
*/ staticint
osintfc_mrioc_security_status(struct pci_dev *pdev)
{
u32 cap_data; int base;
u32 ctlr_status;
u32 debug_status; int retval = 0;
base = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN); if (!base) {
dev_err(&pdev->dev, "%s: PCI_EXT_CAP_ID_DSN is not supported\n", __func__); return -1;
}
switch (ctlr_status) { case MPI3MR_INVALID_DEVICE:
dev_err(&pdev->dev, "%s: Non secure ctlr (Invalid) is detected: DID: 0x%x: SVID: 0x%x: SDID: 0x%x\n",
__func__, pdev->device, pdev->subsystem_vendor,
pdev->subsystem_device);
retval = -1; break; case MPI3MR_CONFIG_SECURE_DEVICE: if (!debug_status)
dev_info(&pdev->dev, "%s: Config secure ctlr is detected\n",
__func__); break; case MPI3MR_HARD_SECURE_DEVICE: break; case MPI3MR_TAMPERED_DEVICE:
dev_err(&pdev->dev, "%s: Non secure ctlr (Tampered) is detected: DID: 0x%x: SVID: 0x%x: SDID: 0x%x\n",
__func__, pdev->device, pdev->subsystem_vendor,
pdev->subsystem_device);
retval = -1; break; default:
retval = -1; break;
}
if (!retval && debug_status) {
dev_err(&pdev->dev, "%s: Non secure ctlr (Secure Dbg) is detected: DID: 0x%x: SVID: 0x%x: SDID: 0x%x\n",
__func__, pdev->device, pdev->subsystem_vendor,
pdev->subsystem_device);
retval = -1;
}
return retval;
}
/** * mpi3mr_probe - PCI probe callback * @pdev: PCI device instance * @id: PCI device ID details * * controller initialization routine. Checks the security status * of the controller and if it is invalid or tampered return the * probe without initializing the controller. Otherwise, * allocate per adapter instance through shost_priv and * initialize controller specific data structures, initializae * the controller hardware, add shost to the SCSI subsystem. * * Return: 0 on success, non-zero on failure.
*/
/** * mpi3mr_suspend - PCI power management suspend callback * @dev: Device struct * * Change the power state to the given value and cleanup the IOC * by issuing MUR and shutdown notification * * Return: 0 always.
*/ staticint __maybe_unused
mpi3mr_suspend(struct device *dev)
{ struct pci_dev *pdev = to_pci_dev(dev); struct Scsi_Host *shost = pci_get_drvdata(pdev); struct mpi3mr_ioc *mrioc;
/** * mpi3mr_pcierr_error_detected - PCI error detected callback * @pdev: PCI device instance * @state: channel state * * This function is called by the PCI error recovery driver and * based on the state passed the driver decides what actions to * be recommended back to PCI driver. * * For all of the states if there is no valid mrioc or scsi host * references in the PCI device then this function will return * the result as disconnect. * * For normal state, this function will return the result as can * recover. * * For frozen state, this function will block for any pending * controller initialization or re-initialization to complete, * stop any new interactions with the controller and return * status as reset required. * * For permanent failure state, this function will mark the * controller as unrecoverable and return status as disconnect. * * Returns: PCI_ERS_RESULT_NEED_RESET or CAN_RECOVER or * DISCONNECT based on the controller state.
*/ static pci_ers_result_t
mpi3mr_pcierr_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
{ struct Scsi_Host *shost; struct mpi3mr_ioc *mrioc; unsignedint timeout = MPI3MR_RESET_TIMEOUT;
/** * mpi3mr_pcierr_slot_reset - Post slot reset callback * @pdev: PCI device instance * * This function is called by the PCI error recovery driver * after a slot or link reset issued by it for the recovery, the * driver is expected to bring back the controller and * initialize it. * * This function restores PCI state and reinitializes controller * resources and the controller, this blocks for any pending * reset to complete. * * Returns: PCI_ERS_RESULT_DISCONNECT on failure or * PCI_ERS_RESULT_RECOVERED
*/ static pci_ers_result_t mpi3mr_pcierr_slot_reset(struct pci_dev *pdev)
{ struct Scsi_Host *shost; struct mpi3mr_ioc *mrioc; unsignedint timeout = MPI3MR_RESET_TIMEOUT;
if (mrioc->block_on_pci_err) {
mrioc->block_on_pci_err = false;
scsi_unblock_requests(shost);
mpi3mr_start_watchdog(mrioc);
}
}
/** * mpi3mr_pcierr_mmio_enabled - PCI error recovery callback * @pdev: PCI device instance * * This is called only if mpi3mr_pcierr_error_detected returns * PCI_ERS_RESULT_CAN_RECOVER. * * Return: PCI_ERS_RESULT_DISCONNECT when the controller is * unrecoverable or when the shost/mrioc reference cannot be * found, else return PCI_ERS_RESULT_RECOVERED
*/ static pci_ers_result_t mpi3mr_pcierr_mmio_enabled(struct pci_dev *pdev)
{ struct Scsi_Host *shost; struct mpi3mr_ioc *mrioc;
pr_info("Loading %s version %s\n", MPI3MR_DRIVER_NAME,
MPI3MR_DRIVER_VERSION);
mpi3mr_transport_template =
sas_attach_transport(&mpi3mr_transport_functions); if (!mpi3mr_transport_template) {
pr_err("%s failed to load due to sas transport attach failure\n",
MPI3MR_DRIVER_NAME); return -ENODEV;
}
ret_val = pci_register_driver(&mpi3mr_pci_driver); if (ret_val) {
pr_err("%s failed to load due to pci register driver failure\n",
MPI3MR_DRIVER_NAME); goto err_pci_reg_fail;
}
ret_val = driver_create_file(&mpi3mr_pci_driver.driver,
&driver_attr_event_counter); if (ret_val) goto err_event_counter;
staticvoid __exit mpi3mr_exit(void)
{ if (warn_non_secure_ctlr)
pr_warn( "Unloading %s version %s while managing a non secure controller\n",
MPI3MR_DRIVER_NAME, MPI3MR_DRIVER_VERSION); else
pr_info("Unloading %s version %s\n", MPI3MR_DRIVER_NAME,
MPI3MR_DRIVER_VERSION);
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.