[SCSI] aic94xx: new driver
This is the end point of the separate aic94xx driver based on the original driver and transport class from Luben Tuikov <ltuikov@yahoo.com> The log of the separate development is: Alexis Bruemmer: o aic94xx: fix hotplug/unplug for expanderless systems o aic94xx: disable split completion timer/setting by default o aic94xx: wide port off expander support o aic94xx: remove various inline functions o aic94xx: use bitops o aic94xx: remove queue comment o aic94xx: remove sas_common.c o aic94xx: sas remove depot's o aic94xx: use available list_for_each_entry_safe_reverse() o aic94xx: sas header file merge James Bottomley: o aic94xx: fix TF_TMF_NO_CTX processing o aic94xx: convert to request_firmware interface o aic94xx: fix hotplug/unplug o aic94xx: add link error counts to the expander phys o aic94xx: add transport class phy reset capability o aic94xx: remove local_attached flag o Remove README o Fixup Makefile variable for libsas rename o Rename sas->libsas o aic94xx: correct return code for sas_discover_event o aic94xx: use parent backlink port o aic94xx: remove channel abstraction o aic94xx: fix routing algorithms o aic94xx: add backlink port o aic94xx: fix cascaded expander properties o aic94xx: fix sleep under lock o aic94xx: fix panic on module removal in complex topology o aic94xx: make use of the new sas_port o rename sas_port to asd_sas_port o Fix for eh_strategy_handler move o aic94xx: move entirely over to correct transport class formulation o remove last vestages of sas_rphy_alloc() o update for eh_timed_out move o Preliminary expander support for aic94xx o sas: remove event thread o minor warning cleanups o remove last vestiges of id mapping arrays o Further updates o Convert aic94xx over entirely to the transport class end device and o update aic94xx/sas to use the new sas transport class end device o [PATCH] aic94xx: attaching to the sas transport class o Add missing completion removal from prior patch o [PATCH] aic94xx: attaching to the sas transport class o Build fixes from akpm Jeff Garzik: o [scsi aic94xx] Remove ->owner from PCI info table Luben Tuikov: o initial aic94xx driver Mike Anderson: o aic94xx: fix panic on module insertion o aic94xx: stub out SATA_DEV case o aic94xx: compile warning cleanups o aic94xx: sas_alloc_task o aic94xx: ref count update o aic94xx nexus loss time value o [PATCH] aic94xx: driver assertion in non-x86 BIOS env Randy Dunlap: o libsas: externs not needed Robert Tarte: o aic94xx: sequence patch - fixes SATA support Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
This commit is contained in:
committed by
James Bottomley
parent
f4ad7b5807
commit
2908d778ab
39
drivers/scsi/libsas/Kconfig
Normal file
39
drivers/scsi/libsas/Kconfig
Normal file
@ -0,0 +1,39 @@
|
||||
#
|
||||
# Kernel configuration file for the SAS Class
|
||||
#
|
||||
# Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
# Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
#
|
||||
# This file is licensed under GPLv2.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; version 2 of the
|
||||
# License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
# USA
|
||||
#
|
||||
|
||||
config SCSI_SAS_LIBSAS
|
||||
tristate "SAS Domain Transport Attributes"
|
||||
depends on SCSI
|
||||
select SCSI_SAS_ATTRS
|
||||
help
|
||||
This provides transport specific helpers for SAS drivers which
|
||||
use the domain device construct (like the aic94xxx).
|
||||
|
||||
config SCSI_SAS_LIBSAS_DEBUG
|
||||
bool "Compile the SAS Domain Transport Attributes in debug mode"
|
||||
default y
|
||||
depends on SCSI_SAS_LIBSAS
|
||||
help
|
||||
Compiles the SAS Layer in debug mode. In debug mode, the
|
||||
SAS Layer prints diagnostic and debug messages.
|
36
drivers/scsi/libsas/Makefile
Normal file
36
drivers/scsi/libsas/Makefile
Normal file
@ -0,0 +1,36 @@
|
||||
#
|
||||
# Kernel Makefile for the libsas helpers
|
||||
#
|
||||
# Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
# Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
#
|
||||
# This file is licensed under GPLv2.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; version 2 of the
|
||||
# License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
# USA
|
||||
|
||||
ifeq ($(CONFIG_SCSI_SAS_LIBSAS_DEBUG),y)
|
||||
EXTRA_CFLAGS += -DSAS_DEBUG
|
||||
endif
|
||||
|
||||
obj-$(CONFIG_SCSI_SAS_LIBSAS) += libsas.o
|
||||
libsas-y += sas_init.o \
|
||||
sas_phy.o \
|
||||
sas_port.o \
|
||||
sas_event.o \
|
||||
sas_dump.o \
|
||||
sas_discover.o \
|
||||
sas_expander.o \
|
||||
sas_scsi_host.o
|
749
drivers/scsi/libsas/sas_discover.c
Normal file
749
drivers/scsi/libsas/sas_discover.c
Normal file
@ -0,0 +1,749 @@
|
||||
/*
|
||||
* Serial Attached SCSI (SAS) Discover process
|
||||
*
|
||||
* Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
* Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
*
|
||||
* This file is licensed under GPLv2.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/pci.h>
|
||||
#include <linux/scatterlist.h>
|
||||
#include <scsi/scsi_host.h>
|
||||
#include <scsi/scsi_eh.h>
|
||||
#include "sas_internal.h"
|
||||
|
||||
#include <scsi/scsi_transport.h>
|
||||
#include <scsi/scsi_transport_sas.h>
|
||||
#include "../scsi_sas_internal.h"
|
||||
|
||||
/* ---------- Basic task processing for discovery purposes ---------- */
|
||||
|
||||
void sas_init_dev(struct domain_device *dev)
|
||||
{
|
||||
INIT_LIST_HEAD(&dev->siblings);
|
||||
INIT_LIST_HEAD(&dev->dev_list_node);
|
||||
switch (dev->dev_type) {
|
||||
case SAS_END_DEV:
|
||||
break;
|
||||
case EDGE_DEV:
|
||||
case FANOUT_DEV:
|
||||
INIT_LIST_HEAD(&dev->ex_dev.children);
|
||||
break;
|
||||
case SATA_DEV:
|
||||
case SATA_PM:
|
||||
case SATA_PM_PORT:
|
||||
INIT_LIST_HEAD(&dev->sata_dev.children);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void sas_task_timedout(unsigned long _task)
|
||||
{
|
||||
struct sas_task *task = (void *) _task;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&task->task_state_lock, flags);
|
||||
if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
|
||||
task->task_state_flags |= SAS_TASK_STATE_ABORTED;
|
||||
spin_unlock_irqrestore(&task->task_state_lock, flags);
|
||||
|
||||
complete(&task->completion);
|
||||
}
|
||||
|
||||
static void sas_disc_task_done(struct sas_task *task)
|
||||
{
|
||||
if (!del_timer(&task->timer))
|
||||
return;
|
||||
complete(&task->completion);
|
||||
}
|
||||
|
||||
#define SAS_DEV_TIMEOUT 10
|
||||
|
||||
/**
|
||||
* sas_execute_task -- Basic task processing for discovery
|
||||
* @task: the task to be executed
|
||||
* @buffer: pointer to buffer to do I/O
|
||||
* @size: size of @buffer
|
||||
* @pci_dma_dir: PCI_DMA_...
|
||||
*/
|
||||
static int sas_execute_task(struct sas_task *task, void *buffer, int size,
|
||||
int pci_dma_dir)
|
||||
{
|
||||
int res = 0;
|
||||
struct scatterlist *scatter = NULL;
|
||||
struct task_status_struct *ts = &task->task_status;
|
||||
int num_scatter = 0;
|
||||
int retries = 0;
|
||||
struct sas_internal *i =
|
||||
to_sas_internal(task->dev->port->ha->core.shost->transportt);
|
||||
|
||||
if (pci_dma_dir != PCI_DMA_NONE) {
|
||||
scatter = kzalloc(sizeof(*scatter), GFP_KERNEL);
|
||||
if (!scatter)
|
||||
goto out;
|
||||
|
||||
sg_init_one(scatter, buffer, size);
|
||||
num_scatter = 1;
|
||||
}
|
||||
|
||||
task->task_proto = task->dev->tproto;
|
||||
task->scatter = scatter;
|
||||
task->num_scatter = num_scatter;
|
||||
task->total_xfer_len = size;
|
||||
task->data_dir = pci_dma_dir;
|
||||
task->task_done = sas_disc_task_done;
|
||||
|
||||
for (retries = 0; retries < 5; retries++) {
|
||||
task->task_state_flags = SAS_TASK_STATE_PENDING;
|
||||
init_completion(&task->completion);
|
||||
|
||||
task->timer.data = (unsigned long) task;
|
||||
task->timer.function = sas_task_timedout;
|
||||
task->timer.expires = jiffies + SAS_DEV_TIMEOUT*HZ;
|
||||
add_timer(&task->timer);
|
||||
|
||||
res = i->dft->lldd_execute_task(task, 1, GFP_KERNEL);
|
||||
if (res) {
|
||||
del_timer(&task->timer);
|
||||
SAS_DPRINTK("executing SAS discovery task failed:%d\n",
|
||||
res);
|
||||
goto ex_err;
|
||||
}
|
||||
wait_for_completion(&task->completion);
|
||||
res = -ETASK;
|
||||
if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
|
||||
int res2;
|
||||
SAS_DPRINTK("task aborted, flags:0x%x\n",
|
||||
task->task_state_flags);
|
||||
res2 = i->dft->lldd_abort_task(task);
|
||||
SAS_DPRINTK("came back from abort task\n");
|
||||
if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
|
||||
if (res2 == TMF_RESP_FUNC_COMPLETE)
|
||||
continue; /* Retry the task */
|
||||
else
|
||||
goto ex_err;
|
||||
}
|
||||
}
|
||||
if (task->task_status.stat == SAM_BUSY ||
|
||||
task->task_status.stat == SAM_TASK_SET_FULL ||
|
||||
task->task_status.stat == SAS_QUEUE_FULL) {
|
||||
SAS_DPRINTK("task: q busy, sleeping...\n");
|
||||
schedule_timeout_interruptible(HZ);
|
||||
} else if (task->task_status.stat == SAM_CHECK_COND) {
|
||||
struct scsi_sense_hdr shdr;
|
||||
|
||||
if (!scsi_normalize_sense(ts->buf, ts->buf_valid_size,
|
||||
&shdr)) {
|
||||
SAS_DPRINTK("couldn't normalize sense\n");
|
||||
continue;
|
||||
}
|
||||
if ((shdr.sense_key == 6 && shdr.asc == 0x29) ||
|
||||
(shdr.sense_key == 2 && shdr.asc == 4 &&
|
||||
shdr.ascq == 1)) {
|
||||
SAS_DPRINTK("device %016llx LUN: %016llx "
|
||||
"powering up or not ready yet, "
|
||||
"sleeping...\n",
|
||||
SAS_ADDR(task->dev->sas_addr),
|
||||
SAS_ADDR(task->ssp_task.LUN));
|
||||
|
||||
schedule_timeout_interruptible(5*HZ);
|
||||
} else if (shdr.sense_key == 1) {
|
||||
res = 0;
|
||||
break;
|
||||
} else if (shdr.sense_key == 5) {
|
||||
break;
|
||||
} else {
|
||||
SAS_DPRINTK("dev %016llx LUN: %016llx "
|
||||
"sense key:0x%x ASC:0x%x ASCQ:0x%x"
|
||||
"\n",
|
||||
SAS_ADDR(task->dev->sas_addr),
|
||||
SAS_ADDR(task->ssp_task.LUN),
|
||||
shdr.sense_key,
|
||||
shdr.asc, shdr.ascq);
|
||||
}
|
||||
} else if (task->task_status.resp != SAS_TASK_COMPLETE ||
|
||||
task->task_status.stat != SAM_GOOD) {
|
||||
SAS_DPRINTK("task finished with resp:0x%x, "
|
||||
"stat:0x%x\n",
|
||||
task->task_status.resp,
|
||||
task->task_status.stat);
|
||||
goto ex_err;
|
||||
} else {
|
||||
res = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ex_err:
|
||||
if (pci_dma_dir != PCI_DMA_NONE)
|
||||
kfree(scatter);
|
||||
out:
|
||||
return res;
|
||||
}
|
||||
|
||||
/* ---------- Domain device discovery ---------- */
|
||||
|
||||
/**
|
||||
* sas_get_port_device -- Discover devices which caused port creation
|
||||
* @port: pointer to struct sas_port of interest
|
||||
*
|
||||
* Devices directly attached to a HA port, have no parent. This is
|
||||
* how we know they are (domain) "root" devices. All other devices
|
||||
* do, and should have their "parent" pointer set appropriately as
|
||||
* soon as a child device is discovered.
|
||||
*/
|
||||
static int sas_get_port_device(struct asd_sas_port *port)
|
||||
{
|
||||
unsigned long flags;
|
||||
struct asd_sas_phy *phy;
|
||||
struct sas_rphy *rphy;
|
||||
struct domain_device *dev;
|
||||
|
||||
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
||||
if (!dev)
|
||||
return -ENOMEM;
|
||||
|
||||
spin_lock_irqsave(&port->phy_list_lock, flags);
|
||||
if (list_empty(&port->phy_list)) {
|
||||
spin_unlock_irqrestore(&port->phy_list_lock, flags);
|
||||
kfree(dev);
|
||||
return -ENODEV;
|
||||
}
|
||||
phy = container_of(port->phy_list.next, struct asd_sas_phy, port_phy_el);
|
||||
spin_lock(&phy->frame_rcvd_lock);
|
||||
memcpy(dev->frame_rcvd, phy->frame_rcvd, min(sizeof(dev->frame_rcvd),
|
||||
(size_t)phy->frame_rcvd_size));
|
||||
spin_unlock(&phy->frame_rcvd_lock);
|
||||
spin_unlock_irqrestore(&port->phy_list_lock, flags);
|
||||
|
||||
if (dev->frame_rcvd[0] == 0x34 && port->oob_mode == SATA_OOB_MODE) {
|
||||
struct dev_to_host_fis *fis =
|
||||
(struct dev_to_host_fis *) dev->frame_rcvd;
|
||||
if (fis->interrupt_reason == 1 && fis->lbal == 1 &&
|
||||
fis->byte_count_low==0x69 && fis->byte_count_high == 0x96
|
||||
&& (fis->device & ~0x10) == 0)
|
||||
dev->dev_type = SATA_PM;
|
||||
else
|
||||
dev->dev_type = SATA_DEV;
|
||||
dev->tproto = SATA_PROTO;
|
||||
} else {
|
||||
struct sas_identify_frame *id =
|
||||
(struct sas_identify_frame *) dev->frame_rcvd;
|
||||
dev->dev_type = id->dev_type;
|
||||
dev->iproto = id->initiator_bits;
|
||||
dev->tproto = id->target_bits;
|
||||
}
|
||||
|
||||
sas_init_dev(dev);
|
||||
|
||||
switch (dev->dev_type) {
|
||||
case SAS_END_DEV:
|
||||
rphy = sas_end_device_alloc(port->port);
|
||||
break;
|
||||
case EDGE_DEV:
|
||||
rphy = sas_expander_alloc(port->port,
|
||||
SAS_EDGE_EXPANDER_DEVICE);
|
||||
break;
|
||||
case FANOUT_DEV:
|
||||
rphy = sas_expander_alloc(port->port,
|
||||
SAS_FANOUT_EXPANDER_DEVICE);
|
||||
break;
|
||||
case SATA_DEV:
|
||||
default:
|
||||
printk("ERROR: Unidentified device type %d\n", dev->dev_type);
|
||||
rphy = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!rphy) {
|
||||
kfree(dev);
|
||||
return -ENODEV;
|
||||
}
|
||||
rphy->identify.phy_identifier = phy->phy->identify.phy_identifier;
|
||||
memcpy(dev->sas_addr, port->attached_sas_addr, SAS_ADDR_SIZE);
|
||||
sas_fill_in_rphy(dev, rphy);
|
||||
sas_hash_addr(dev->hashed_sas_addr, dev->sas_addr);
|
||||
port->port_dev = dev;
|
||||
dev->port = port;
|
||||
dev->linkrate = port->linkrate;
|
||||
dev->min_linkrate = port->linkrate;
|
||||
dev->max_linkrate = port->linkrate;
|
||||
dev->pathways = port->num_phys;
|
||||
memset(port->disc.fanout_sas_addr, 0, SAS_ADDR_SIZE);
|
||||
memset(port->disc.eeds_a, 0, SAS_ADDR_SIZE);
|
||||
memset(port->disc.eeds_b, 0, SAS_ADDR_SIZE);
|
||||
port->disc.max_level = 0;
|
||||
|
||||
dev->rphy = rphy;
|
||||
spin_lock(&port->dev_list_lock);
|
||||
list_add_tail(&dev->dev_list_node, &port->dev_list);
|
||||
spin_unlock(&port->dev_list_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------- Discover and Revalidate ---------- */
|
||||
|
||||
/* ---------- SATA ---------- */
|
||||
|
||||
static void sas_get_ata_command_set(struct domain_device *dev)
|
||||
{
|
||||
struct dev_to_host_fis *fis =
|
||||
(struct dev_to_host_fis *) dev->frame_rcvd;
|
||||
|
||||
if ((fis->sector_count == 1 && /* ATA */
|
||||
fis->lbal == 1 &&
|
||||
fis->lbam == 0 &&
|
||||
fis->lbah == 0 &&
|
||||
fis->device == 0)
|
||||
||
|
||||
(fis->sector_count == 0 && /* CE-ATA (mATA) */
|
||||
fis->lbal == 0 &&
|
||||
fis->lbam == 0xCE &&
|
||||
fis->lbah == 0xAA &&
|
||||
(fis->device & ~0x10) == 0))
|
||||
|
||||
dev->sata_dev.command_set = ATA_COMMAND_SET;
|
||||
|
||||
else if ((fis->interrupt_reason == 1 && /* ATAPI */
|
||||
fis->lbal == 1 &&
|
||||
fis->byte_count_low == 0x14 &&
|
||||
fis->byte_count_high == 0xEB &&
|
||||
(fis->device & ~0x10) == 0))
|
||||
|
||||
dev->sata_dev.command_set = ATAPI_COMMAND_SET;
|
||||
|
||||
else if ((fis->sector_count == 1 && /* SEMB */
|
||||
fis->lbal == 1 &&
|
||||
fis->lbam == 0x3C &&
|
||||
fis->lbah == 0xC3 &&
|
||||
fis->device == 0)
|
||||
||
|
||||
(fis->interrupt_reason == 1 && /* SATA PM */
|
||||
fis->lbal == 1 &&
|
||||
fis->byte_count_low == 0x69 &&
|
||||
fis->byte_count_high == 0x96 &&
|
||||
(fis->device & ~0x10) == 0))
|
||||
|
||||
/* Treat it as a superset? */
|
||||
dev->sata_dev.command_set = ATAPI_COMMAND_SET;
|
||||
}
|
||||
|
||||
/**
|
||||
* sas_issue_ata_cmd -- Basic SATA command processing for discovery
|
||||
* @dev: the device to send the command to
|
||||
* @command: the command register
|
||||
* @features: the features register
|
||||
* @buffer: pointer to buffer to do I/O
|
||||
* @size: size of @buffer
|
||||
* @pci_dma_dir: PCI_DMA_...
|
||||
*/
|
||||
static int sas_issue_ata_cmd(struct domain_device *dev, u8 command,
|
||||
u8 features, void *buffer, int size,
|
||||
int pci_dma_dir)
|
||||
{
|
||||
int res = 0;
|
||||
struct sas_task *task;
|
||||
struct dev_to_host_fis *d2h_fis = (struct dev_to_host_fis *)
|
||||
&dev->frame_rcvd[0];
|
||||
|
||||
res = -ENOMEM;
|
||||
task = sas_alloc_task(GFP_KERNEL);
|
||||
if (!task)
|
||||
goto out;
|
||||
|
||||
task->dev = dev;
|
||||
|
||||
task->ata_task.fis.command = command;
|
||||
task->ata_task.fis.features = features;
|
||||
task->ata_task.fis.device = d2h_fis->device;
|
||||
task->ata_task.retry_count = 1;
|
||||
|
||||
res = sas_execute_task(task, buffer, size, pci_dma_dir);
|
||||
|
||||
sas_free_task(task);
|
||||
out:
|
||||
return res;
|
||||
}
|
||||
|
||||
static void sas_sata_propagate_sas_addr(struct domain_device *dev)
|
||||
{
|
||||
unsigned long flags;
|
||||
struct asd_sas_port *port = dev->port;
|
||||
struct asd_sas_phy *phy;
|
||||
|
||||
BUG_ON(dev->parent);
|
||||
|
||||
memcpy(port->attached_sas_addr, dev->sas_addr, SAS_ADDR_SIZE);
|
||||
spin_lock_irqsave(&port->phy_list_lock, flags);
|
||||
list_for_each_entry(phy, &port->phy_list, port_phy_el)
|
||||
memcpy(phy->attached_sas_addr, dev->sas_addr, SAS_ADDR_SIZE);
|
||||
spin_unlock_irqrestore(&port->phy_list_lock, flags);
|
||||
}
|
||||
|
||||
#define ATA_IDENTIFY_DEV 0xEC
|
||||
#define ATA_IDENTIFY_PACKET_DEV 0xA1
|
||||
#define ATA_SET_FEATURES 0xEF
|
||||
#define ATA_FEATURE_PUP_STBY_SPIN_UP 0x07
|
||||
|
||||
/**
|
||||
* sas_discover_sata_dev -- discover a STP/SATA device (SATA_DEV)
|
||||
* @dev: STP/SATA device of interest (ATA/ATAPI)
|
||||
*
|
||||
* The LLDD has already been notified of this device, so that we can
|
||||
* send FISes to it. Here we try to get IDENTIFY DEVICE or IDENTIFY
|
||||
* PACKET DEVICE, if ATAPI device, so that the LLDD can fine-tune its
|
||||
* performance for this device.
|
||||
*/
|
||||
static int sas_discover_sata_dev(struct domain_device *dev)
|
||||
{
|
||||
int res;
|
||||
__le16 *identify_x;
|
||||
u8 command;
|
||||
|
||||
identify_x = kzalloc(512, GFP_KERNEL);
|
||||
if (!identify_x)
|
||||
return -ENOMEM;
|
||||
|
||||
if (dev->sata_dev.command_set == ATA_COMMAND_SET) {
|
||||
dev->sata_dev.identify_device = identify_x;
|
||||
command = ATA_IDENTIFY_DEV;
|
||||
} else {
|
||||
dev->sata_dev.identify_packet_device = identify_x;
|
||||
command = ATA_IDENTIFY_PACKET_DEV;
|
||||
}
|
||||
|
||||
res = sas_issue_ata_cmd(dev, command, 0, identify_x, 512,
|
||||
PCI_DMA_FROMDEVICE);
|
||||
if (res)
|
||||
goto out_err;
|
||||
|
||||
/* lives on the media? */
|
||||
if (le16_to_cpu(identify_x[0]) & 4) {
|
||||
/* incomplete response */
|
||||
SAS_DPRINTK("sending SET FEATURE/PUP_STBY_SPIN_UP to "
|
||||
"dev %llx\n", SAS_ADDR(dev->sas_addr));
|
||||
if (!le16_to_cpu(identify_x[83] & (1<<6)))
|
||||
goto cont1;
|
||||
res = sas_issue_ata_cmd(dev, ATA_SET_FEATURES,
|
||||
ATA_FEATURE_PUP_STBY_SPIN_UP,
|
||||
NULL, 0, PCI_DMA_NONE);
|
||||
if (res)
|
||||
goto cont1;
|
||||
|
||||
schedule_timeout_interruptible(5*HZ); /* More time? */
|
||||
res = sas_issue_ata_cmd(dev, command, 0, identify_x, 512,
|
||||
PCI_DMA_FROMDEVICE);
|
||||
if (res)
|
||||
goto out_err;
|
||||
}
|
||||
cont1:
|
||||
/* Get WWN */
|
||||
if (dev->port->oob_mode != SATA_OOB_MODE) {
|
||||
memcpy(dev->sas_addr, dev->sata_dev.rps_resp.rps.stp_sas_addr,
|
||||
SAS_ADDR_SIZE);
|
||||
} else if (dev->sata_dev.command_set == ATA_COMMAND_SET &&
|
||||
(le16_to_cpu(dev->sata_dev.identify_device[108]) & 0xF000)
|
||||
== 0x5000) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
dev->sas_addr[2*i] =
|
||||
(le16_to_cpu(dev->sata_dev.identify_device[108+i]) & 0xFF00) >> 8;
|
||||
dev->sas_addr[2*i+1] =
|
||||
le16_to_cpu(dev->sata_dev.identify_device[108+i]) & 0x00FF;
|
||||
}
|
||||
}
|
||||
sas_hash_addr(dev->hashed_sas_addr, dev->sas_addr);
|
||||
if (!dev->parent)
|
||||
sas_sata_propagate_sas_addr(dev);
|
||||
|
||||
/* XXX Hint: register this SATA device with SATL.
|
||||
When this returns, dev->sata_dev->lu is alive and
|
||||
present.
|
||||
sas_satl_register_dev(dev);
|
||||
*/
|
||||
return 0;
|
||||
out_err:
|
||||
dev->sata_dev.identify_packet_device = NULL;
|
||||
dev->sata_dev.identify_device = NULL;
|
||||
kfree(identify_x);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int sas_discover_sata_pm(struct domain_device *dev)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
int sas_notify_lldd_dev_found(struct domain_device *dev)
|
||||
{
|
||||
int res = 0;
|
||||
struct sas_ha_struct *sas_ha = dev->port->ha;
|
||||
struct Scsi_Host *shost = sas_ha->core.shost;
|
||||
struct sas_internal *i = to_sas_internal(shost->transportt);
|
||||
|
||||
if (i->dft->lldd_dev_found) {
|
||||
res = i->dft->lldd_dev_found(dev);
|
||||
if (res) {
|
||||
printk("sas: driver on pcidev %s cannot handle "
|
||||
"device %llx, error:%d\n",
|
||||
pci_name(sas_ha->pcidev),
|
||||
SAS_ADDR(dev->sas_addr), res);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void sas_notify_lldd_dev_gone(struct domain_device *dev)
|
||||
{
|
||||
struct sas_ha_struct *sas_ha = dev->port->ha;
|
||||
struct Scsi_Host *shost = sas_ha->core.shost;
|
||||
struct sas_internal *i = to_sas_internal(shost->transportt);
|
||||
|
||||
if (i->dft->lldd_dev_gone)
|
||||
i->dft->lldd_dev_gone(dev);
|
||||
}
|
||||
|
||||
/* ---------- Common/dispatchers ---------- */
|
||||
|
||||
/**
|
||||
* sas_discover_sata -- discover an STP/SATA domain device
|
||||
* @dev: pointer to struct domain_device of interest
|
||||
*
|
||||
* First we notify the LLDD of this device, so we can send frames to
|
||||
* it. Then depending on the type of device we call the appropriate
|
||||
* discover functions. Once device discover is done, we notify the
|
||||
* LLDD so that it can fine-tune its parameters for the device, by
|
||||
* removing it and then adding it. That is, the second time around,
|
||||
* the driver would have certain fields, that it is looking at, set.
|
||||
* Finally we initialize the kobj so that the device can be added to
|
||||
* the system at registration time. Devices directly attached to a HA
|
||||
* port, have no parents. All other devices do, and should have their
|
||||
* "parent" pointer set appropriately before calling this function.
|
||||
*/
|
||||
int sas_discover_sata(struct domain_device *dev)
|
||||
{
|
||||
int res;
|
||||
|
||||
sas_get_ata_command_set(dev);
|
||||
|
||||
res = sas_notify_lldd_dev_found(dev);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
switch (dev->dev_type) {
|
||||
case SATA_DEV:
|
||||
res = sas_discover_sata_dev(dev);
|
||||
break;
|
||||
case SATA_PM:
|
||||
res = sas_discover_sata_pm(dev);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
sas_notify_lldd_dev_gone(dev);
|
||||
if (!res) {
|
||||
sas_notify_lldd_dev_found(dev);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* sas_discover_end_dev -- discover an end device (SSP, etc)
|
||||
* @end: pointer to domain device of interest
|
||||
*
|
||||
* See comment in sas_discover_sata().
|
||||
*/
|
||||
int sas_discover_end_dev(struct domain_device *dev)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = sas_notify_lldd_dev_found(dev);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
res = sas_rphy_add(dev->rphy);
|
||||
if (res)
|
||||
goto out_err;
|
||||
|
||||
/* do this to get the end device port attributes which will have
|
||||
* been scanned in sas_rphy_add */
|
||||
sas_notify_lldd_dev_gone(dev);
|
||||
sas_notify_lldd_dev_found(dev);
|
||||
|
||||
return 0;
|
||||
|
||||
out_err:
|
||||
sas_notify_lldd_dev_gone(dev);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* ---------- Device registration and unregistration ---------- */
|
||||
|
||||
static inline void sas_unregister_common_dev(struct domain_device *dev)
|
||||
{
|
||||
sas_notify_lldd_dev_gone(dev);
|
||||
if (!dev->parent)
|
||||
dev->port->port_dev = NULL;
|
||||
else
|
||||
list_del_init(&dev->siblings);
|
||||
list_del_init(&dev->dev_list_node);
|
||||
}
|
||||
|
||||
void sas_unregister_dev(struct domain_device *dev)
|
||||
{
|
||||
if (dev->rphy) {
|
||||
sas_remove_children(&dev->rphy->dev);
|
||||
sas_rphy_delete(dev->rphy);
|
||||
dev->rphy = NULL;
|
||||
}
|
||||
if (dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV) {
|
||||
/* remove the phys and ports, everything else should be gone */
|
||||
kfree(dev->ex_dev.ex_phy);
|
||||
dev->ex_dev.ex_phy = NULL;
|
||||
}
|
||||
sas_unregister_common_dev(dev);
|
||||
}
|
||||
|
||||
void sas_unregister_domain_devices(struct asd_sas_port *port)
|
||||
{
|
||||
struct domain_device *dev, *n;
|
||||
|
||||
list_for_each_entry_safe_reverse(dev,n,&port->dev_list,dev_list_node)
|
||||
sas_unregister_dev(dev);
|
||||
|
||||
port->port->rphy = NULL;
|
||||
|
||||
}
|
||||
|
||||
/* ---------- Discovery and Revalidation ---------- */
|
||||
|
||||
/**
|
||||
* sas_discover_domain -- discover the domain
|
||||
* @port: port to the domain of interest
|
||||
*
|
||||
* NOTE: this process _must_ quit (return) as soon as any connection
|
||||
* errors are encountered. Connection recovery is done elsewhere.
|
||||
* Discover process only interrogates devices in order to discover the
|
||||
* domain.
|
||||
*/
|
||||
static void sas_discover_domain(void *data)
|
||||
{
|
||||
int error = 0;
|
||||
struct asd_sas_port *port = data;
|
||||
|
||||
sas_begin_event(DISCE_DISCOVER_DOMAIN, &port->disc.disc_event_lock,
|
||||
&port->disc.pending);
|
||||
|
||||
if (port->port_dev)
|
||||
return ;
|
||||
else {
|
||||
error = sas_get_port_device(port);
|
||||
if (error)
|
||||
return;
|
||||
}
|
||||
|
||||
SAS_DPRINTK("DOING DISCOVERY on port %d, pid:%d\n", port->id,
|
||||
current->pid);
|
||||
|
||||
switch (port->port_dev->dev_type) {
|
||||
case SAS_END_DEV:
|
||||
error = sas_discover_end_dev(port->port_dev);
|
||||
break;
|
||||
case EDGE_DEV:
|
||||
case FANOUT_DEV:
|
||||
error = sas_discover_root_expander(port->port_dev);
|
||||
break;
|
||||
case SATA_DEV:
|
||||
case SATA_PM:
|
||||
error = sas_discover_sata(port->port_dev);
|
||||
break;
|
||||
default:
|
||||
SAS_DPRINTK("unhandled device %d\n", port->port_dev->dev_type);
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
kfree(port->port_dev); /* not kobject_register-ed yet */
|
||||
port->port_dev = NULL;
|
||||
}
|
||||
|
||||
SAS_DPRINTK("DONE DISCOVERY on port %d, pid:%d, result:%d\n", port->id,
|
||||
current->pid, error);
|
||||
}
|
||||
|
||||
static void sas_revalidate_domain(void *data)
|
||||
{
|
||||
int res = 0;
|
||||
struct asd_sas_port *port = data;
|
||||
|
||||
sas_begin_event(DISCE_REVALIDATE_DOMAIN, &port->disc.disc_event_lock,
|
||||
&port->disc.pending);
|
||||
|
||||
SAS_DPRINTK("REVALIDATING DOMAIN on port %d, pid:%d\n", port->id,
|
||||
current->pid);
|
||||
if (port->port_dev)
|
||||
res = sas_ex_revalidate_domain(port->port_dev);
|
||||
|
||||
SAS_DPRINTK("done REVALIDATING DOMAIN on port %d, pid:%d, res 0x%x\n",
|
||||
port->id, current->pid, res);
|
||||
}
|
||||
|
||||
/* ---------- Events ---------- */
|
||||
|
||||
int sas_discover_event(struct asd_sas_port *port, enum discover_event ev)
|
||||
{
|
||||
struct sas_discovery *disc;
|
||||
|
||||
if (!port)
|
||||
return 0;
|
||||
disc = &port->disc;
|
||||
|
||||
BUG_ON(ev >= DISC_NUM_EVENTS);
|
||||
|
||||
sas_queue_event(ev, &disc->disc_event_lock, &disc->pending,
|
||||
&disc->disc_work[ev], port->ha->core.shost);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* sas_init_disc -- initialize the discovery struct in the port
|
||||
* @port: pointer to struct port
|
||||
*
|
||||
* Called when the ports are being initialized.
|
||||
*/
|
||||
void sas_init_disc(struct sas_discovery *disc, struct asd_sas_port *port)
|
||||
{
|
||||
int i;
|
||||
|
||||
static void (*sas_event_fns[DISC_NUM_EVENTS])(void *) = {
|
||||
[DISCE_DISCOVER_DOMAIN] = sas_discover_domain,
|
||||
[DISCE_REVALIDATE_DOMAIN] = sas_revalidate_domain,
|
||||
};
|
||||
|
||||
spin_lock_init(&disc->disc_event_lock);
|
||||
disc->pending = 0;
|
||||
for (i = 0; i < DISC_NUM_EVENTS; i++)
|
||||
INIT_WORK(&disc->disc_work[i], sas_event_fns[i], port);
|
||||
}
|
76
drivers/scsi/libsas/sas_dump.c
Normal file
76
drivers/scsi/libsas/sas_dump.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Serial Attached SCSI (SAS) Dump/Debugging routines
|
||||
*
|
||||
* Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
* Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
*
|
||||
* This file is licensed under GPLv2.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sas_dump.h"
|
||||
|
||||
#ifdef SAS_DEBUG
|
||||
|
||||
static const char *sas_hae_str[] = {
|
||||
[0] = "HAE_RESET",
|
||||
};
|
||||
|
||||
static const char *sas_porte_str[] = {
|
||||
[0] = "PORTE_BYTES_DMAED",
|
||||
[1] = "PORTE_BROADCAST_RCVD",
|
||||
[2] = "PORTE_LINK_RESET_ERR",
|
||||
[3] = "PORTE_TIMER_EVENT",
|
||||
[4] = "PORTE_HARD_RESET",
|
||||
};
|
||||
|
||||
static const char *sas_phye_str[] = {
|
||||
[0] = "PHYE_LOSS_OF_SIGNAL",
|
||||
[1] = "PHYE_OOB_DONE",
|
||||
[2] = "PHYE_OOB_ERROR",
|
||||
[3] = "PHYE_SPINUP_HOLD",
|
||||
};
|
||||
|
||||
void sas_dprint_porte(int phyid, enum port_event pe)
|
||||
{
|
||||
SAS_DPRINTK("phy%d: port event: %s\n", phyid, sas_porte_str[pe]);
|
||||
}
|
||||
void sas_dprint_phye(int phyid, enum phy_event pe)
|
||||
{
|
||||
SAS_DPRINTK("phy%d: phy event: %s\n", phyid, sas_phye_str[pe]);
|
||||
}
|
||||
|
||||
void sas_dprint_hae(struct sas_ha_struct *sas_ha, enum ha_event he)
|
||||
{
|
||||
SAS_DPRINTK("ha %s: %s event\n", pci_name(sas_ha->pcidev),
|
||||
sas_hae_str[he]);
|
||||
}
|
||||
|
||||
void sas_dump_port(struct asd_sas_port *port)
|
||||
{
|
||||
SAS_DPRINTK("port%d: class:0x%x\n", port->id, port->class);
|
||||
SAS_DPRINTK("port%d: sas_addr:%llx\n", port->id,
|
||||
SAS_ADDR(port->sas_addr));
|
||||
SAS_DPRINTK("port%d: attached_sas_addr:%llx\n", port->id,
|
||||
SAS_ADDR(port->attached_sas_addr));
|
||||
SAS_DPRINTK("port%d: iproto:0x%x\n", port->id, port->iproto);
|
||||
SAS_DPRINTK("port%d: tproto:0x%x\n", port->id, port->tproto);
|
||||
SAS_DPRINTK("port%d: oob_mode:0x%x\n", port->id, port->oob_mode);
|
||||
SAS_DPRINTK("port%d: num_phys:%d\n", port->id, port->num_phys);
|
||||
}
|
||||
|
||||
#endif /* SAS_DEBUG */
|
42
drivers/scsi/libsas/sas_dump.h
Normal file
42
drivers/scsi/libsas/sas_dump.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Serial Attached SCSI (SAS) Dump/Debugging routines header file
|
||||
*
|
||||
* Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
* Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
*
|
||||
* This file is licensed under GPLv2.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sas_internal.h"
|
||||
|
||||
#ifdef SAS_DEBUG
|
||||
|
||||
void sas_dprint_porte(int phyid, enum port_event pe);
|
||||
void sas_dprint_phye(int phyid, enum phy_event pe);
|
||||
void sas_dprint_hae(struct sas_ha_struct *sas_ha, enum ha_event he);
|
||||
void sas_dump_port(struct asd_sas_port *port);
|
||||
|
||||
#else /* SAS_DEBUG */
|
||||
|
||||
static inline void sas_dprint_porte(int phyid, enum port_event pe) { }
|
||||
static inline void sas_dprint_phye(int phyid, enum phy_event pe) { }
|
||||
static inline void sas_dprint_hae(struct sas_ha_struct *sas_ha,
|
||||
enum ha_event he) { }
|
||||
static inline void sas_dump_port(struct asd_sas_port *port) { }
|
||||
|
||||
#endif /* SAS_DEBUG */
|
75
drivers/scsi/libsas/sas_event.c
Normal file
75
drivers/scsi/libsas/sas_event.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Serial Attached SCSI (SAS) Event processing
|
||||
*
|
||||
* Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
* Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
*
|
||||
* This file is licensed under GPLv2.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <scsi/scsi_host.h>
|
||||
#include "sas_internal.h"
|
||||
#include "sas_dump.h"
|
||||
|
||||
static void notify_ha_event(struct sas_ha_struct *sas_ha, enum ha_event event)
|
||||
{
|
||||
BUG_ON(event >= HA_NUM_EVENTS);
|
||||
|
||||
sas_queue_event(event, &sas_ha->event_lock, &sas_ha->pending,
|
||||
&sas_ha->ha_events[event], sas_ha->core.shost);
|
||||
}
|
||||
|
||||
static void notify_port_event(struct asd_sas_phy *phy, enum port_event event)
|
||||
{
|
||||
struct sas_ha_struct *ha = phy->ha;
|
||||
|
||||
BUG_ON(event >= PORT_NUM_EVENTS);
|
||||
|
||||
sas_queue_event(event, &ha->event_lock, &phy->port_events_pending,
|
||||
&phy->port_events[event], ha->core.shost);
|
||||
}
|
||||
|
||||
static void notify_phy_event(struct asd_sas_phy *phy, enum phy_event event)
|
||||
{
|
||||
struct sas_ha_struct *ha = phy->ha;
|
||||
|
||||
BUG_ON(event >= PHY_NUM_EVENTS);
|
||||
|
||||
sas_queue_event(event, &ha->event_lock, &phy->phy_events_pending,
|
||||
&phy->phy_events[event], ha->core.shost);
|
||||
}
|
||||
|
||||
int sas_init_events(struct sas_ha_struct *sas_ha)
|
||||
{
|
||||
static void (*sas_ha_event_fns[HA_NUM_EVENTS])(void *) = {
|
||||
[HAE_RESET] = sas_hae_reset,
|
||||
};
|
||||
|
||||
int i;
|
||||
|
||||
spin_lock_init(&sas_ha->event_lock);
|
||||
|
||||
for (i = 0; i < HA_NUM_EVENTS; i++)
|
||||
INIT_WORK(&sas_ha->ha_events[i], sas_ha_event_fns[i], sas_ha);
|
||||
|
||||
sas_ha->notify_ha_event = notify_ha_event;
|
||||
sas_ha->notify_port_event = notify_port_event;
|
||||
sas_ha->notify_phy_event = notify_phy_event;
|
||||
|
||||
return 0;
|
||||
}
|
1862
drivers/scsi/libsas/sas_expander.c
Normal file
1862
drivers/scsi/libsas/sas_expander.c
Normal file
File diff suppressed because it is too large
Load Diff
227
drivers/scsi/libsas/sas_init.c
Normal file
227
drivers/scsi/libsas/sas_init.c
Normal file
@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Serial Attached SCSI (SAS) Transport Layer initialization
|
||||
*
|
||||
* Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
* Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
*
|
||||
* This file is licensed under GPLv2.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <scsi/scsi_host.h>
|
||||
#include <scsi/scsi_device.h>
|
||||
#include <scsi/scsi_transport.h>
|
||||
#include <scsi/scsi_transport_sas.h>
|
||||
|
||||
#include "sas_internal.h"
|
||||
|
||||
#include "../scsi_sas_internal.h"
|
||||
|
||||
kmem_cache_t *sas_task_cache;
|
||||
|
||||
/*------------ SAS addr hash -----------*/
|
||||
void sas_hash_addr(u8 *hashed, const u8 *sas_addr)
|
||||
{
|
||||
const u32 poly = 0x00DB2777;
|
||||
u32 r = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
int b;
|
||||
for (b = 7; b >= 0; b--) {
|
||||
r <<= 1;
|
||||
if ((1 << b) & sas_addr[i]) {
|
||||
if (!(r & 0x01000000))
|
||||
r ^= poly;
|
||||
} else if (r & 0x01000000)
|
||||
r ^= poly;
|
||||
}
|
||||
}
|
||||
|
||||
hashed[0] = (r >> 16) & 0xFF;
|
||||
hashed[1] = (r >> 8) & 0xFF ;
|
||||
hashed[2] = r & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- HA events ---------- */
|
||||
|
||||
void sas_hae_reset(void *data)
|
||||
{
|
||||
struct sas_ha_struct *ha = data;
|
||||
|
||||
sas_begin_event(HAE_RESET, &ha->event_lock,
|
||||
&ha->pending);
|
||||
}
|
||||
|
||||
int sas_register_ha(struct sas_ha_struct *sas_ha)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
spin_lock_init(&sas_ha->phy_port_lock);
|
||||
sas_hash_addr(sas_ha->hashed_sas_addr, sas_ha->sas_addr);
|
||||
|
||||
if (sas_ha->lldd_queue_size == 0)
|
||||
sas_ha->lldd_queue_size = 1;
|
||||
else if (sas_ha->lldd_queue_size == -1)
|
||||
sas_ha->lldd_queue_size = 128; /* Sanity */
|
||||
|
||||
error = sas_register_phys(sas_ha);
|
||||
if (error) {
|
||||
printk(KERN_NOTICE "couldn't register sas phys:%d\n", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
error = sas_register_ports(sas_ha);
|
||||
if (error) {
|
||||
printk(KERN_NOTICE "couldn't register sas ports:%d\n", error);
|
||||
goto Undo_phys;
|
||||
}
|
||||
|
||||
error = sas_init_events(sas_ha);
|
||||
if (error) {
|
||||
printk(KERN_NOTICE "couldn't start event thread:%d\n", error);
|
||||
goto Undo_ports;
|
||||
}
|
||||
|
||||
if (sas_ha->lldd_max_execute_num > 1) {
|
||||
error = sas_init_queue(sas_ha);
|
||||
if (error) {
|
||||
printk(KERN_NOTICE "couldn't start queue thread:%d, "
|
||||
"running in direct mode\n", error);
|
||||
sas_ha->lldd_max_execute_num = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Undo_ports:
|
||||
sas_unregister_ports(sas_ha);
|
||||
Undo_phys:
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int sas_unregister_ha(struct sas_ha_struct *sas_ha)
|
||||
{
|
||||
if (sas_ha->lldd_max_execute_num > 1) {
|
||||
sas_shutdown_queue(sas_ha);
|
||||
}
|
||||
|
||||
sas_unregister_ports(sas_ha);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sas_get_linkerrors(struct sas_phy *phy)
|
||||
{
|
||||
if (scsi_is_sas_phy_local(phy))
|
||||
/* FIXME: we have no local phy stats
|
||||
* gathering at this time */
|
||||
return -EINVAL;
|
||||
|
||||
return sas_smp_get_phy_events(phy);
|
||||
}
|
||||
|
||||
static int sas_phy_reset(struct sas_phy *phy, int hard_reset)
|
||||
{
|
||||
int ret;
|
||||
enum phy_func reset_type;
|
||||
|
||||
if (hard_reset)
|
||||
reset_type = PHY_FUNC_HARD_RESET;
|
||||
else
|
||||
reset_type = PHY_FUNC_LINK_RESET;
|
||||
|
||||
if (scsi_is_sas_phy_local(phy)) {
|
||||
struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
|
||||
struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
|
||||
struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number];
|
||||
struct sas_internal *i =
|
||||
to_sas_internal(sas_ha->core.shost->transportt);
|
||||
|
||||
ret = i->dft->lldd_control_phy(asd_phy, reset_type);
|
||||
} else {
|
||||
struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
|
||||
struct domain_device *ddev = sas_find_dev_by_rphy(rphy);
|
||||
ret = sas_smp_phy_control(ddev, phy->number, reset_type);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct sas_function_template sft = {
|
||||
.phy_reset = sas_phy_reset,
|
||||
.get_linkerrors = sas_get_linkerrors,
|
||||
};
|
||||
|
||||
struct scsi_transport_template *
|
||||
sas_domain_attach_transport(struct sas_domain_function_template *dft)
|
||||
{
|
||||
struct scsi_transport_template *stt = sas_attach_transport(&sft);
|
||||
struct sas_internal *i;
|
||||
|
||||
if (!stt)
|
||||
return stt;
|
||||
|
||||
i = to_sas_internal(stt);
|
||||
i->dft = dft;
|
||||
stt->create_work_queue = 1;
|
||||
stt->eh_timed_out = sas_scsi_timed_out;
|
||||
stt->eh_strategy_handler = sas_scsi_recover_host;
|
||||
|
||||
return stt;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(sas_domain_attach_transport);
|
||||
|
||||
|
||||
void sas_domain_release_transport(struct scsi_transport_template *stt)
|
||||
{
|
||||
sas_release_transport(stt);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(sas_domain_release_transport);
|
||||
|
||||
/* ---------- SAS Class register/unregister ---------- */
|
||||
|
||||
static int __init sas_class_init(void)
|
||||
{
|
||||
sas_task_cache = kmem_cache_create("sas_task", sizeof(struct sas_task),
|
||||
0, SLAB_HWCACHE_ALIGN, NULL, NULL);
|
||||
if (!sas_task_cache)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit sas_class_exit(void)
|
||||
{
|
||||
kmem_cache_destroy(sas_task_cache);
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Luben Tuikov <luben_tuikov@adaptec.com>");
|
||||
MODULE_DESCRIPTION("SAS Transport Layer");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
||||
module_init(sas_class_init);
|
||||
module_exit(sas_class_exit);
|
||||
|
||||
EXPORT_SYMBOL_GPL(sas_register_ha);
|
||||
EXPORT_SYMBOL_GPL(sas_unregister_ha);
|
146
drivers/scsi/libsas/sas_internal.h
Normal file
146
drivers/scsi/libsas/sas_internal.h
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Serial Attached SCSI (SAS) class internal header file
|
||||
*
|
||||
* Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
* Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
*
|
||||
* This file is licensed under GPLv2.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SAS_INTERNAL_H_
|
||||
#define _SAS_INTERNAL_H_
|
||||
|
||||
#include <scsi/scsi.h>
|
||||
#include <scsi/scsi_host.h>
|
||||
#include <scsi/scsi_transport_sas.h>
|
||||
#include <scsi/libsas.h>
|
||||
|
||||
#define sas_printk(fmt, ...) printk(KERN_NOTICE "sas: " fmt, ## __VA_ARGS__)
|
||||
|
||||
#ifdef SAS_DEBUG
|
||||
#define SAS_DPRINTK(fmt, ...) printk(KERN_NOTICE "sas: " fmt, ## __VA_ARGS__)
|
||||
#else
|
||||
#define SAS_DPRINTK(fmt, ...)
|
||||
#endif
|
||||
|
||||
void sas_scsi_recover_host(struct Scsi_Host *shost);
|
||||
|
||||
int sas_show_class(enum sas_class class, char *buf);
|
||||
int sas_show_proto(enum sas_proto proto, char *buf);
|
||||
int sas_show_linkrate(enum sas_phy_linkrate linkrate, char *buf);
|
||||
int sas_show_oob_mode(enum sas_oob_mode oob_mode, char *buf);
|
||||
|
||||
int sas_register_phys(struct sas_ha_struct *sas_ha);
|
||||
void sas_unregister_phys(struct sas_ha_struct *sas_ha);
|
||||
|
||||
int sas_register_ports(struct sas_ha_struct *sas_ha);
|
||||
void sas_unregister_ports(struct sas_ha_struct *sas_ha);
|
||||
|
||||
enum scsi_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *);
|
||||
|
||||
int sas_init_queue(struct sas_ha_struct *sas_ha);
|
||||
int sas_init_events(struct sas_ha_struct *sas_ha);
|
||||
void sas_shutdown_queue(struct sas_ha_struct *sas_ha);
|
||||
|
||||
void sas_deform_port(struct asd_sas_phy *phy);
|
||||
|
||||
void sas_porte_bytes_dmaed(void *);
|
||||
void sas_porte_broadcast_rcvd(void *);
|
||||
void sas_porte_link_reset_err(void *);
|
||||
void sas_porte_timer_event(void *);
|
||||
void sas_porte_hard_reset(void *);
|
||||
|
||||
int sas_notify_lldd_dev_found(struct domain_device *);
|
||||
void sas_notify_lldd_dev_gone(struct domain_device *);
|
||||
|
||||
int sas_smp_phy_control(struct domain_device *dev, int phy_id,
|
||||
enum phy_func phy_func);
|
||||
int sas_smp_get_phy_events(struct sas_phy *phy);
|
||||
|
||||
struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy);
|
||||
|
||||
void sas_hae_reset(void *);
|
||||
|
||||
static inline void sas_queue_event(int event, spinlock_t *lock,
|
||||
unsigned long *pending,
|
||||
struct work_struct *work,
|
||||
struct Scsi_Host *shost)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(lock, flags);
|
||||
if (test_bit(event, pending)) {
|
||||
spin_unlock_irqrestore(lock, flags);
|
||||
return;
|
||||
}
|
||||
__set_bit(event, pending);
|
||||
spin_unlock_irqrestore(lock, flags);
|
||||
scsi_queue_work(shost, work);
|
||||
}
|
||||
|
||||
static inline void sas_begin_event(int event, spinlock_t *lock,
|
||||
unsigned long *pending)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(lock, flags);
|
||||
__clear_bit(event, pending);
|
||||
spin_unlock_irqrestore(lock, flags);
|
||||
}
|
||||
|
||||
static inline void sas_fill_in_rphy(struct domain_device *dev,
|
||||
struct sas_rphy *rphy)
|
||||
{
|
||||
rphy->identify.sas_address = SAS_ADDR(dev->sas_addr);
|
||||
rphy->identify.initiator_port_protocols = dev->iproto;
|
||||
rphy->identify.target_port_protocols = dev->tproto;
|
||||
switch (dev->dev_type) {
|
||||
case SATA_DEV:
|
||||
/* FIXME: need sata device type */
|
||||
case SAS_END_DEV:
|
||||
rphy->identify.device_type = SAS_END_DEVICE;
|
||||
break;
|
||||
case EDGE_DEV:
|
||||
rphy->identify.device_type = SAS_EDGE_EXPANDER_DEVICE;
|
||||
break;
|
||||
case FANOUT_DEV:
|
||||
rphy->identify.device_type = SAS_FANOUT_EXPANDER_DEVICE;
|
||||
break;
|
||||
default:
|
||||
rphy->identify.device_type = SAS_PHY_UNUSED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void sas_add_parent_port(struct domain_device *dev, int phy_id)
|
||||
{
|
||||
struct expander_device *ex = &dev->ex_dev;
|
||||
struct ex_phy *ex_phy = &ex->ex_phy[phy_id];
|
||||
|
||||
if (!ex->parent_port) {
|
||||
ex->parent_port = sas_port_alloc(&dev->rphy->dev, phy_id);
|
||||
/* FIXME: error handling */
|
||||
BUG_ON(!ex->parent_port);
|
||||
BUG_ON(sas_port_add(ex->parent_port));
|
||||
sas_port_mark_backlink(ex->parent_port);
|
||||
}
|
||||
sas_port_add_phy(ex->parent_port, ex_phy->phy);
|
||||
}
|
||||
|
||||
#endif /* _SAS_INTERNAL_H_ */
|
157
drivers/scsi/libsas/sas_phy.c
Normal file
157
drivers/scsi/libsas/sas_phy.c
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Serial Attached SCSI (SAS) Phy class
|
||||
*
|
||||
* Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
* Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
*
|
||||
* This file is licensed under GPLv2.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sas_internal.h"
|
||||
#include <scsi/scsi_host.h>
|
||||
#include <scsi/scsi_transport.h>
|
||||
#include <scsi/scsi_transport_sas.h>
|
||||
#include "../scsi_sas_internal.h"
|
||||
|
||||
/* ---------- Phy events ---------- */
|
||||
|
||||
static void sas_phye_loss_of_signal(void *data)
|
||||
{
|
||||
struct asd_sas_phy *phy = data;
|
||||
|
||||
sas_begin_event(PHYE_LOSS_OF_SIGNAL, &phy->ha->event_lock,
|
||||
&phy->phy_events_pending);
|
||||
phy->error = 0;
|
||||
sas_deform_port(phy);
|
||||
}
|
||||
|
||||
static void sas_phye_oob_done(void *data)
|
||||
{
|
||||
struct asd_sas_phy *phy = data;
|
||||
|
||||
sas_begin_event(PHYE_OOB_DONE, &phy->ha->event_lock,
|
||||
&phy->phy_events_pending);
|
||||
phy->error = 0;
|
||||
}
|
||||
|
||||
static void sas_phye_oob_error(void *data)
|
||||
{
|
||||
struct asd_sas_phy *phy = data;
|
||||
struct sas_ha_struct *sas_ha = phy->ha;
|
||||
struct asd_sas_port *port = phy->port;
|
||||
struct sas_internal *i =
|
||||
to_sas_internal(sas_ha->core.shost->transportt);
|
||||
|
||||
sas_begin_event(PHYE_OOB_ERROR, &phy->ha->event_lock,
|
||||
&phy->phy_events_pending);
|
||||
|
||||
sas_deform_port(phy);
|
||||
|
||||
if (!port && phy->enabled && i->dft->lldd_control_phy) {
|
||||
phy->error++;
|
||||
switch (phy->error) {
|
||||
case 1:
|
||||
case 2:
|
||||
i->dft->lldd_control_phy(phy, PHY_FUNC_HARD_RESET);
|
||||
break;
|
||||
case 3:
|
||||
default:
|
||||
phy->error = 0;
|
||||
phy->enabled = 0;
|
||||
i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void sas_phye_spinup_hold(void *data)
|
||||
{
|
||||
struct asd_sas_phy *phy = data;
|
||||
struct sas_ha_struct *sas_ha = phy->ha;
|
||||
struct sas_internal *i =
|
||||
to_sas_internal(sas_ha->core.shost->transportt);
|
||||
|
||||
sas_begin_event(PHYE_SPINUP_HOLD, &phy->ha->event_lock,
|
||||
&phy->phy_events_pending);
|
||||
|
||||
phy->error = 0;
|
||||
i->dft->lldd_control_phy(phy, PHY_FUNC_RELEASE_SPINUP_HOLD);
|
||||
}
|
||||
|
||||
/* ---------- Phy class registration ---------- */
|
||||
|
||||
int sas_register_phys(struct sas_ha_struct *sas_ha)
|
||||
{
|
||||
int i;
|
||||
|
||||
static void (*sas_phy_event_fns[PHY_NUM_EVENTS])(void *) = {
|
||||
[PHYE_LOSS_OF_SIGNAL] = sas_phye_loss_of_signal,
|
||||
[PHYE_OOB_DONE] = sas_phye_oob_done,
|
||||
[PHYE_OOB_ERROR] = sas_phye_oob_error,
|
||||
[PHYE_SPINUP_HOLD] = sas_phye_spinup_hold,
|
||||
};
|
||||
|
||||
static void (*sas_port_event_fns[PORT_NUM_EVENTS])(void *) = {
|
||||
[PORTE_BYTES_DMAED] = sas_porte_bytes_dmaed,
|
||||
[PORTE_BROADCAST_RCVD] = sas_porte_broadcast_rcvd,
|
||||
[PORTE_LINK_RESET_ERR] = sas_porte_link_reset_err,
|
||||
[PORTE_TIMER_EVENT] = sas_porte_timer_event,
|
||||
[PORTE_HARD_RESET] = sas_porte_hard_reset,
|
||||
};
|
||||
|
||||
/* Now register the phys. */
|
||||
for (i = 0; i < sas_ha->num_phys; i++) {
|
||||
int k;
|
||||
struct asd_sas_phy *phy = sas_ha->sas_phy[i];
|
||||
|
||||
phy->error = 0;
|
||||
INIT_LIST_HEAD(&phy->port_phy_el);
|
||||
for (k = 0; k < PORT_NUM_EVENTS; k++)
|
||||
INIT_WORK(&phy->port_events[k], sas_port_event_fns[k],
|
||||
phy);
|
||||
|
||||
for (k = 0; k < PHY_NUM_EVENTS; k++)
|
||||
INIT_WORK(&phy->phy_events[k], sas_phy_event_fns[k],
|
||||
phy);
|
||||
phy->port = NULL;
|
||||
phy->ha = sas_ha;
|
||||
spin_lock_init(&phy->frame_rcvd_lock);
|
||||
spin_lock_init(&phy->sas_prim_lock);
|
||||
phy->frame_rcvd_size = 0;
|
||||
|
||||
phy->phy = sas_phy_alloc(&sas_ha->core.shost->shost_gendev,
|
||||
i);
|
||||
if (!phy->phy)
|
||||
return -ENOMEM;
|
||||
|
||||
phy->phy->identify.initiator_port_protocols =
|
||||
phy->iproto;
|
||||
phy->phy->identify.target_port_protocols = phy->tproto;
|
||||
phy->phy->identify.sas_address = SAS_ADDR(sas_ha->sas_addr);
|
||||
phy->phy->identify.phy_identifier = i;
|
||||
phy->phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
|
||||
phy->phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
|
||||
phy->phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
|
||||
phy->phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
|
||||
phy->phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
|
||||
|
||||
sas_phy_add(phy->phy);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
279
drivers/scsi/libsas/sas_port.c
Normal file
279
drivers/scsi/libsas/sas_port.c
Normal file
@ -0,0 +1,279 @@
|
||||
/*
|
||||
* Serial Attached SCSI (SAS) Port class
|
||||
*
|
||||
* Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
* Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
*
|
||||
* This file is licensed under GPLv2.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sas_internal.h"
|
||||
|
||||
#include <scsi/scsi_transport.h>
|
||||
#include <scsi/scsi_transport_sas.h>
|
||||
#include "../scsi_sas_internal.h"
|
||||
|
||||
/**
|
||||
* sas_form_port -- add this phy to a port
|
||||
* @phy: the phy of interest
|
||||
*
|
||||
* This function adds this phy to an existing port, thus creating a wide
|
||||
* port, or it creates a port and adds the phy to the port.
|
||||
*/
|
||||
static void sas_form_port(struct asd_sas_phy *phy)
|
||||
{
|
||||
int i;
|
||||
struct sas_ha_struct *sas_ha = phy->ha;
|
||||
struct asd_sas_port *port = phy->port;
|
||||
struct sas_internal *si =
|
||||
to_sas_internal(sas_ha->core.shost->transportt);
|
||||
|
||||
if (port) {
|
||||
if (memcmp(port->attached_sas_addr, phy->attached_sas_addr,
|
||||
SAS_ADDR_SIZE) == 0)
|
||||
sas_deform_port(phy);
|
||||
else {
|
||||
SAS_DPRINTK("%s: phy%d belongs to port%d already(%d)!\n",
|
||||
__FUNCTION__, phy->id, phy->port->id,
|
||||
phy->port->num_phys);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* find a port */
|
||||
spin_lock(&sas_ha->phy_port_lock);
|
||||
for (i = 0; i < sas_ha->num_phys; i++) {
|
||||
port = sas_ha->sas_port[i];
|
||||
spin_lock(&port->phy_list_lock);
|
||||
if (*(u64 *) port->sas_addr &&
|
||||
memcmp(port->attached_sas_addr,
|
||||
phy->attached_sas_addr, SAS_ADDR_SIZE) == 0 &&
|
||||
port->num_phys > 0) {
|
||||
/* wide port */
|
||||
SAS_DPRINTK("phy%d matched wide port%d\n", phy->id,
|
||||
port->id);
|
||||
break;
|
||||
} else if (*(u64 *) port->sas_addr == 0 && port->num_phys==0) {
|
||||
memcpy(port->sas_addr, phy->sas_addr, SAS_ADDR_SIZE);
|
||||
break;
|
||||
}
|
||||
spin_unlock(&port->phy_list_lock);
|
||||
}
|
||||
|
||||
if (i >= sas_ha->num_phys) {
|
||||
printk(KERN_NOTICE "%s: couldn't find a free port, bug?\n",
|
||||
__FUNCTION__);
|
||||
spin_unlock(&sas_ha->phy_port_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
/* add the phy to the port */
|
||||
list_add_tail(&phy->port_phy_el, &port->phy_list);
|
||||
phy->port = port;
|
||||
port->num_phys++;
|
||||
port->phy_mask |= (1U << phy->id);
|
||||
|
||||
if (!port->phy)
|
||||
port->phy = phy->phy;
|
||||
|
||||
SAS_DPRINTK("phy%d added to port%d, phy_mask:0x%x\n", phy->id,
|
||||
port->id, port->phy_mask);
|
||||
|
||||
if (*(u64 *)port->attached_sas_addr == 0) {
|
||||
port->class = phy->class;
|
||||
memcpy(port->attached_sas_addr, phy->attached_sas_addr,
|
||||
SAS_ADDR_SIZE);
|
||||
port->iproto = phy->iproto;
|
||||
port->tproto = phy->tproto;
|
||||
port->oob_mode = phy->oob_mode;
|
||||
port->linkrate = phy->linkrate;
|
||||
} else
|
||||
port->linkrate = max(port->linkrate, phy->linkrate);
|
||||
spin_unlock(&port->phy_list_lock);
|
||||
spin_unlock(&sas_ha->phy_port_lock);
|
||||
|
||||
if (!port->port) {
|
||||
port->port = sas_port_alloc(phy->phy->dev.parent, port->id);
|
||||
BUG_ON(!port->port);
|
||||
sas_port_add(port->port);
|
||||
}
|
||||
sas_port_add_phy(port->port, phy->phy);
|
||||
|
||||
if (port->port_dev)
|
||||
port->port_dev->pathways = port->num_phys;
|
||||
|
||||
/* Tell the LLDD about this port formation. */
|
||||
if (si->dft->lldd_port_formed)
|
||||
si->dft->lldd_port_formed(phy);
|
||||
|
||||
sas_discover_event(phy->port, DISCE_DISCOVER_DOMAIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* sas_deform_port -- remove this phy from the port it belongs to
|
||||
* @phy: the phy of interest
|
||||
*
|
||||
* This is called when the physical link to the other phy has been
|
||||
* lost (on this phy), in Event thread context. We cannot delay here.
|
||||
*/
|
||||
void sas_deform_port(struct asd_sas_phy *phy)
|
||||
{
|
||||
struct sas_ha_struct *sas_ha = phy->ha;
|
||||
struct asd_sas_port *port = phy->port;
|
||||
struct sas_internal *si =
|
||||
to_sas_internal(sas_ha->core.shost->transportt);
|
||||
|
||||
if (!port)
|
||||
return; /* done by a phy event */
|
||||
|
||||
if (port->port_dev)
|
||||
port->port_dev->pathways--;
|
||||
|
||||
if (port->num_phys == 1) {
|
||||
sas_unregister_domain_devices(port);
|
||||
sas_port_delete(port->port);
|
||||
port->port = NULL;
|
||||
} else
|
||||
sas_port_delete_phy(port->port, phy->phy);
|
||||
|
||||
|
||||
if (si->dft->lldd_port_deformed)
|
||||
si->dft->lldd_port_deformed(phy);
|
||||
|
||||
spin_lock(&sas_ha->phy_port_lock);
|
||||
spin_lock(&port->phy_list_lock);
|
||||
|
||||
list_del_init(&phy->port_phy_el);
|
||||
phy->port = NULL;
|
||||
port->num_phys--;
|
||||
port->phy_mask &= ~(1U << phy->id);
|
||||
|
||||
if (port->num_phys == 0) {
|
||||
INIT_LIST_HEAD(&port->phy_list);
|
||||
memset(port->sas_addr, 0, SAS_ADDR_SIZE);
|
||||
memset(port->attached_sas_addr, 0, SAS_ADDR_SIZE);
|
||||
port->class = 0;
|
||||
port->iproto = 0;
|
||||
port->tproto = 0;
|
||||
port->oob_mode = 0;
|
||||
port->phy_mask = 0;
|
||||
}
|
||||
spin_unlock(&port->phy_list_lock);
|
||||
spin_unlock(&sas_ha->phy_port_lock);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ---------- SAS port events ---------- */
|
||||
|
||||
void sas_porte_bytes_dmaed(void *data)
|
||||
{
|
||||
struct asd_sas_phy *phy = data;
|
||||
|
||||
sas_begin_event(PORTE_BYTES_DMAED, &phy->ha->event_lock,
|
||||
&phy->port_events_pending);
|
||||
|
||||
sas_form_port(phy);
|
||||
}
|
||||
|
||||
void sas_porte_broadcast_rcvd(void *data)
|
||||
{
|
||||
unsigned long flags;
|
||||
u32 prim;
|
||||
struct asd_sas_phy *phy = data;
|
||||
|
||||
sas_begin_event(PORTE_BROADCAST_RCVD, &phy->ha->event_lock,
|
||||
&phy->port_events_pending);
|
||||
|
||||
spin_lock_irqsave(&phy->sas_prim_lock, flags);
|
||||
prim = phy->sas_prim;
|
||||
spin_unlock_irqrestore(&phy->sas_prim_lock, flags);
|
||||
|
||||
SAS_DPRINTK("broadcast received: %d\n", prim);
|
||||
sas_discover_event(phy->port, DISCE_REVALIDATE_DOMAIN);
|
||||
}
|
||||
|
||||
void sas_porte_link_reset_err(void *data)
|
||||
{
|
||||
struct asd_sas_phy *phy = data;
|
||||
|
||||
sas_begin_event(PORTE_LINK_RESET_ERR, &phy->ha->event_lock,
|
||||
&phy->port_events_pending);
|
||||
|
||||
sas_deform_port(phy);
|
||||
}
|
||||
|
||||
void sas_porte_timer_event(void *data)
|
||||
{
|
||||
struct asd_sas_phy *phy = data;
|
||||
|
||||
sas_begin_event(PORTE_TIMER_EVENT, &phy->ha->event_lock,
|
||||
&phy->port_events_pending);
|
||||
|
||||
sas_deform_port(phy);
|
||||
}
|
||||
|
||||
void sas_porte_hard_reset(void *data)
|
||||
{
|
||||
struct asd_sas_phy *phy = data;
|
||||
|
||||
sas_begin_event(PORTE_HARD_RESET, &phy->ha->event_lock,
|
||||
&phy->port_events_pending);
|
||||
|
||||
sas_deform_port(phy);
|
||||
}
|
||||
|
||||
/* ---------- SAS port registration ---------- */
|
||||
|
||||
static void sas_init_port(struct asd_sas_port *port,
|
||||
struct sas_ha_struct *sas_ha, int i)
|
||||
{
|
||||
port->id = i;
|
||||
INIT_LIST_HEAD(&port->dev_list);
|
||||
spin_lock_init(&port->phy_list_lock);
|
||||
INIT_LIST_HEAD(&port->phy_list);
|
||||
port->num_phys = 0;
|
||||
port->phy_mask = 0;
|
||||
port->ha = sas_ha;
|
||||
|
||||
spin_lock_init(&port->dev_list_lock);
|
||||
}
|
||||
|
||||
int sas_register_ports(struct sas_ha_struct *sas_ha)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* initialize the ports and discovery */
|
||||
for (i = 0; i < sas_ha->num_phys; i++) {
|
||||
struct asd_sas_port *port = sas_ha->sas_port[i];
|
||||
|
||||
sas_init_port(port, sas_ha, i);
|
||||
sas_init_disc(&port->disc, port);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sas_unregister_ports(struct sas_ha_struct *sas_ha)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sas_ha->num_phys; i++)
|
||||
if (sas_ha->sas_phy[i]->port)
|
||||
sas_deform_port(sas_ha->sas_phy[i]);
|
||||
|
||||
}
|
786
drivers/scsi/libsas/sas_scsi_host.c
Normal file
786
drivers/scsi/libsas/sas_scsi_host.c
Normal file
@ -0,0 +1,786 @@
|
||||
/*
|
||||
* Serial Attached SCSI (SAS) class SCSI Host glue.
|
||||
*
|
||||
* Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
||||
* Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
||||
*
|
||||
* This file is licensed under GPLv2.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sas_internal.h"
|
||||
|
||||
#include <scsi/scsi_host.h>
|
||||
#include <scsi/scsi_device.h>
|
||||
#include <scsi/scsi_tcq.h>
|
||||
#include <scsi/scsi.h>
|
||||
#include <scsi/scsi_transport.h>
|
||||
#include <scsi/scsi_transport_sas.h>
|
||||
#include "../scsi_sas_internal.h"
|
||||
|
||||
#include <linux/err.h>
|
||||
#include <linux/blkdev.h>
|
||||
#include <linux/scatterlist.h>
|
||||
|
||||
/* ---------- SCSI Host glue ---------- */
|
||||
|
||||
#define TO_SAS_TASK(_scsi_cmd) ((void *)(_scsi_cmd)->host_scribble)
|
||||
#define ASSIGN_SAS_TASK(_sc, _t) do { (_sc)->host_scribble = (void *) _t; } while (0)
|
||||
|
||||
static void sas_scsi_task_done(struct sas_task *task)
|
||||
{
|
||||
struct task_status_struct *ts = &task->task_status;
|
||||
struct scsi_cmnd *sc = task->uldd_task;
|
||||
unsigned ts_flags = task->task_state_flags;
|
||||
int hs = 0, stat = 0;
|
||||
|
||||
if (unlikely(!sc)) {
|
||||
SAS_DPRINTK("task_done called with non existing SCSI cmnd!\n");
|
||||
list_del_init(&task->list);
|
||||
sas_free_task(task);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ts->resp == SAS_TASK_UNDELIVERED) {
|
||||
/* transport error */
|
||||
hs = DID_NO_CONNECT;
|
||||
} else { /* ts->resp == SAS_TASK_COMPLETE */
|
||||
/* task delivered, what happened afterwards? */
|
||||
switch (ts->stat) {
|
||||
case SAS_DEV_NO_RESPONSE:
|
||||
case SAS_INTERRUPTED:
|
||||
case SAS_PHY_DOWN:
|
||||
case SAS_NAK_R_ERR:
|
||||
case SAS_OPEN_TO:
|
||||
hs = DID_NO_CONNECT;
|
||||
break;
|
||||
case SAS_DATA_UNDERRUN:
|
||||
sc->resid = ts->residual;
|
||||
if (sc->request_bufflen - sc->resid < sc->underflow)
|
||||
hs = DID_ERROR;
|
||||
break;
|
||||
case SAS_DATA_OVERRUN:
|
||||
hs = DID_ERROR;
|
||||
break;
|
||||
case SAS_QUEUE_FULL:
|
||||
hs = DID_SOFT_ERROR; /* retry */
|
||||
break;
|
||||
case SAS_DEVICE_UNKNOWN:
|
||||
hs = DID_BAD_TARGET;
|
||||
break;
|
||||
case SAS_SG_ERR:
|
||||
hs = DID_PARITY;
|
||||
break;
|
||||
case SAS_OPEN_REJECT:
|
||||
if (ts->open_rej_reason == SAS_OREJ_RSVD_RETRY)
|
||||
hs = DID_SOFT_ERROR; /* retry */
|
||||
else
|
||||
hs = DID_ERROR;
|
||||
break;
|
||||
case SAS_PROTO_RESPONSE:
|
||||
SAS_DPRINTK("LLDD:%s sent SAS_PROTO_RESP for an SSP "
|
||||
"task; please report this\n",
|
||||
task->dev->port->ha->sas_ha_name);
|
||||
break;
|
||||
case SAS_ABORTED_TASK:
|
||||
hs = DID_ABORT;
|
||||
break;
|
||||
case SAM_CHECK_COND:
|
||||
memcpy(sc->sense_buffer, ts->buf,
|
||||
max(SCSI_SENSE_BUFFERSIZE, ts->buf_valid_size));
|
||||
stat = SAM_CHECK_COND;
|
||||
break;
|
||||
default:
|
||||
stat = ts->stat;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ASSIGN_SAS_TASK(sc, NULL);
|
||||
sc->result = (hs << 16) | stat;
|
||||
list_del_init(&task->list);
|
||||
sas_free_task(task);
|
||||
/* This is very ugly but this is how SCSI Core works. */
|
||||
if (ts_flags & SAS_TASK_STATE_ABORTED)
|
||||
scsi_finish_command(sc);
|
||||
else
|
||||
sc->scsi_done(sc);
|
||||
}
|
||||
|
||||
static enum task_attribute sas_scsi_get_task_attr(struct scsi_cmnd *cmd)
|
||||
{
|
||||
enum task_attribute ta = TASK_ATTR_SIMPLE;
|
||||
if (cmd->request && blk_rq_tagged(cmd->request)) {
|
||||
if (cmd->device->ordered_tags &&
|
||||
(cmd->request->flags & REQ_HARDBARRIER))
|
||||
ta = TASK_ATTR_HOQ;
|
||||
}
|
||||
return ta;
|
||||
}
|
||||
|
||||
static struct sas_task *sas_create_task(struct scsi_cmnd *cmd,
|
||||
struct domain_device *dev,
|
||||
unsigned long gfp_flags)
|
||||
{
|
||||
struct sas_task *task = sas_alloc_task(gfp_flags);
|
||||
struct scsi_lun lun;
|
||||
|
||||
if (!task)
|
||||
return NULL;
|
||||
|
||||
*(u32 *)cmd->sense_buffer = 0;
|
||||
task->uldd_task = cmd;
|
||||
ASSIGN_SAS_TASK(cmd, task);
|
||||
|
||||
task->dev = dev;
|
||||
task->task_proto = task->dev->tproto; /* BUG_ON(!SSP) */
|
||||
|
||||
task->ssp_task.retry_count = 1;
|
||||
int_to_scsilun(cmd->device->lun, &lun);
|
||||
memcpy(task->ssp_task.LUN, &lun.scsi_lun, 8);
|
||||
task->ssp_task.task_attr = sas_scsi_get_task_attr(cmd);
|
||||
memcpy(task->ssp_task.cdb, cmd->cmnd, 16);
|
||||
|
||||
task->scatter = cmd->request_buffer;
|
||||
task->num_scatter = cmd->use_sg;
|
||||
task->total_xfer_len = cmd->request_bufflen;
|
||||
task->data_dir = cmd->sc_data_direction;
|
||||
|
||||
task->task_done = sas_scsi_task_done;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
static int sas_queue_up(struct sas_task *task)
|
||||
{
|
||||
struct sas_ha_struct *sas_ha = task->dev->port->ha;
|
||||
struct scsi_core *core = &sas_ha->core;
|
||||
unsigned long flags;
|
||||
LIST_HEAD(list);
|
||||
|
||||
spin_lock_irqsave(&core->task_queue_lock, flags);
|
||||
if (sas_ha->lldd_queue_size < core->task_queue_size + 1) {
|
||||
spin_unlock_irqrestore(&core->task_queue_lock, flags);
|
||||
return -SAS_QUEUE_FULL;
|
||||
}
|
||||
list_add_tail(&task->list, &core->task_queue);
|
||||
core->task_queue_size += 1;
|
||||
spin_unlock_irqrestore(&core->task_queue_lock, flags);
|
||||
up(&core->queue_thread_sema);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* sas_queuecommand -- Enqueue a command for processing
|
||||
* @parameters: See SCSI Core documentation
|
||||
*
|
||||
* Note: XXX: Remove the host unlock/lock pair when SCSI Core can
|
||||
* call us without holding an IRQ spinlock...
|
||||
*/
|
||||
int sas_queuecommand(struct scsi_cmnd *cmd,
|
||||
void (*scsi_done)(struct scsi_cmnd *))
|
||||
{
|
||||
int res = 0;
|
||||
struct domain_device *dev = cmd_to_domain_dev(cmd);
|
||||
struct Scsi_Host *host = cmd->device->host;
|
||||
struct sas_internal *i = to_sas_internal(host->transportt);
|
||||
|
||||
spin_unlock_irq(host->host_lock);
|
||||
|
||||
{
|
||||
struct sas_ha_struct *sas_ha = dev->port->ha;
|
||||
struct sas_task *task;
|
||||
|
||||
res = -ENOMEM;
|
||||
task = sas_create_task(cmd, dev, GFP_ATOMIC);
|
||||
if (!task)
|
||||
goto out;
|
||||
|
||||
cmd->scsi_done = scsi_done;
|
||||
/* Queue up, Direct Mode or Task Collector Mode. */
|
||||
if (sas_ha->lldd_max_execute_num < 2)
|
||||
res = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC);
|
||||
else
|
||||
res = sas_queue_up(task);
|
||||
|
||||
/* Examine */
|
||||
if (res) {
|
||||
SAS_DPRINTK("lldd_execute_task returned: %d\n", res);
|
||||
ASSIGN_SAS_TASK(cmd, NULL);
|
||||
sas_free_task(task);
|
||||
if (res == -SAS_QUEUE_FULL) {
|
||||
cmd->result = DID_SOFT_ERROR << 16; /* retry */
|
||||
res = 0;
|
||||
scsi_done(cmd);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
out:
|
||||
spin_lock_irq(host->host_lock);
|
||||
return res;
|
||||
}
|
||||
|
||||
static void sas_scsi_clear_queue_lu(struct list_head *error_q, struct scsi_cmnd *my_cmd)
|
||||
{
|
||||
struct scsi_cmnd *cmd, *n;
|
||||
|
||||
list_for_each_entry_safe(cmd, n, error_q, eh_entry) {
|
||||
if (cmd == my_cmd)
|
||||
list_del_init(&cmd->eh_entry);
|
||||
}
|
||||
}
|
||||
|
||||
static void sas_scsi_clear_queue_I_T(struct list_head *error_q,
|
||||
struct domain_device *dev)
|
||||
{
|
||||
struct scsi_cmnd *cmd, *n;
|
||||
|
||||
list_for_each_entry_safe(cmd, n, error_q, eh_entry) {
|
||||
struct domain_device *x = cmd_to_domain_dev(cmd);
|
||||
|
||||
if (x == dev)
|
||||
list_del_init(&cmd->eh_entry);
|
||||
}
|
||||
}
|
||||
|
||||
static void sas_scsi_clear_queue_port(struct list_head *error_q,
|
||||
struct asd_sas_port *port)
|
||||
{
|
||||
struct scsi_cmnd *cmd, *n;
|
||||
|
||||
list_for_each_entry_safe(cmd, n, error_q, eh_entry) {
|
||||
struct domain_device *dev = cmd_to_domain_dev(cmd);
|
||||
struct asd_sas_port *x = dev->port;
|
||||
|
||||
if (x == port)
|
||||
list_del_init(&cmd->eh_entry);
|
||||
}
|
||||
}
|
||||
|
||||
enum task_disposition {
|
||||
TASK_IS_DONE,
|
||||
TASK_IS_ABORTED,
|
||||
TASK_IS_AT_LU,
|
||||
TASK_IS_NOT_AT_LU,
|
||||
};
|
||||
|
||||
static enum task_disposition sas_scsi_find_task(struct sas_task *task)
|
||||
{
|
||||
struct sas_ha_struct *ha = task->dev->port->ha;
|
||||
unsigned long flags;
|
||||
int i, res;
|
||||
struct sas_internal *si =
|
||||
to_sas_internal(task->dev->port->ha->core.shost->transportt);
|
||||
|
||||
if (ha->lldd_max_execute_num > 1) {
|
||||
struct scsi_core *core = &ha->core;
|
||||
struct sas_task *t, *n;
|
||||
|
||||
spin_lock_irqsave(&core->task_queue_lock, flags);
|
||||
list_for_each_entry_safe(t, n, &core->task_queue, list) {
|
||||
if (task == t) {
|
||||
list_del_init(&t->list);
|
||||
spin_unlock_irqrestore(&core->task_queue_lock,
|
||||
flags);
|
||||
SAS_DPRINTK("%s: task 0x%p aborted from "
|
||||
"task_queue\n",
|
||||
__FUNCTION__, task);
|
||||
return TASK_IS_ABORTED;
|
||||
}
|
||||
}
|
||||
spin_unlock_irqrestore(&core->task_queue_lock, flags);
|
||||
}
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
SAS_DPRINTK("%s: aborting task 0x%p\n", __FUNCTION__, task);
|
||||
res = si->dft->lldd_abort_task(task);
|
||||
|
||||
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);
|
||||
SAS_DPRINTK("%s: task 0x%p is done\n", __FUNCTION__,
|
||||
task);
|
||||
return TASK_IS_DONE;
|
||||
}
|
||||
spin_unlock_irqrestore(&task->task_state_lock, flags);
|
||||
|
||||
if (res == TMF_RESP_FUNC_COMPLETE) {
|
||||
SAS_DPRINTK("%s: task 0x%p is aborted\n",
|
||||
__FUNCTION__, task);
|
||||
return TASK_IS_ABORTED;
|
||||
} else if (si->dft->lldd_query_task) {
|
||||
SAS_DPRINTK("%s: querying task 0x%p\n",
|
||||
__FUNCTION__, task);
|
||||
res = si->dft->lldd_query_task(task);
|
||||
if (res == TMF_RESP_FUNC_SUCC) {
|
||||
SAS_DPRINTK("%s: task 0x%p at LU\n",
|
||||
__FUNCTION__, task);
|
||||
return TASK_IS_AT_LU;
|
||||
} else if (res == TMF_RESP_FUNC_COMPLETE) {
|
||||
SAS_DPRINTK("%s: task 0x%p not at LU\n",
|
||||
__FUNCTION__, task);
|
||||
return TASK_IS_NOT_AT_LU;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int sas_recover_lu(struct domain_device *dev, struct scsi_cmnd *cmd)
|
||||
{
|
||||
int res = TMF_RESP_FUNC_FAILED;
|
||||
struct scsi_lun lun;
|
||||
struct sas_internal *i =
|
||||
to_sas_internal(dev->port->ha->core.shost->transportt);
|
||||
|
||||
int_to_scsilun(cmd->device->lun, &lun);
|
||||
|
||||
SAS_DPRINTK("eh: device %llx LUN %x has the task\n",
|
||||
SAS_ADDR(dev->sas_addr),
|
||||
cmd->device->lun);
|
||||
|
||||
if (i->dft->lldd_abort_task_set)
|
||||
res = i->dft->lldd_abort_task_set(dev, lun.scsi_lun);
|
||||
|
||||
if (res == TMF_RESP_FUNC_FAILED) {
|
||||
if (i->dft->lldd_clear_task_set)
|
||||
res = i->dft->lldd_clear_task_set(dev, lun.scsi_lun);
|
||||
}
|
||||
|
||||
if (res == TMF_RESP_FUNC_FAILED) {
|
||||
if (i->dft->lldd_lu_reset)
|
||||
res = i->dft->lldd_lu_reset(dev, lun.scsi_lun);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int sas_recover_I_T(struct domain_device *dev)
|
||||
{
|
||||
int res = TMF_RESP_FUNC_FAILED;
|
||||
struct sas_internal *i =
|
||||
to_sas_internal(dev->port->ha->core.shost->transportt);
|
||||
|
||||
SAS_DPRINTK("I_T nexus reset for dev %016llx\n",
|
||||
SAS_ADDR(dev->sas_addr));
|
||||
|
||||
if (i->dft->lldd_I_T_nexus_reset)
|
||||
res = i->dft->lldd_I_T_nexus_reset(dev);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void sas_scsi_recover_host(struct Scsi_Host *shost)
|
||||
{
|
||||
struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
|
||||
unsigned long flags;
|
||||
LIST_HEAD(error_q);
|
||||
struct scsi_cmnd *cmd, *n;
|
||||
enum task_disposition res = TASK_IS_DONE;
|
||||
int tmf_resp;
|
||||
struct sas_internal *i = to_sas_internal(shost->transportt);
|
||||
|
||||
spin_lock_irqsave(shost->host_lock, flags);
|
||||
list_splice_init(&shost->eh_cmd_q, &error_q);
|
||||
spin_unlock_irqrestore(shost->host_lock, flags);
|
||||
|
||||
SAS_DPRINTK("Enter %s\n", __FUNCTION__);
|
||||
|
||||
/* All tasks on this list were marked SAS_TASK_STATE_ABORTED
|
||||
* by sas_scsi_timed_out() callback.
|
||||
*/
|
||||
Again:
|
||||
SAS_DPRINTK("going over list...\n");
|
||||
list_for_each_entry_safe(cmd, n, &error_q, eh_entry) {
|
||||
struct sas_task *task = TO_SAS_TASK(cmd);
|
||||
|
||||
SAS_DPRINTK("trying to find task 0x%p\n", task);
|
||||
list_del_init(&cmd->eh_entry);
|
||||
res = sas_scsi_find_task(task);
|
||||
|
||||
cmd->eh_eflags = 0;
|
||||
shost->host_failed--;
|
||||
|
||||
switch (res) {
|
||||
case TASK_IS_DONE:
|
||||
SAS_DPRINTK("%s: task 0x%p is done\n", __FUNCTION__,
|
||||
task);
|
||||
task->task_done(task);
|
||||
continue;
|
||||
case TASK_IS_ABORTED:
|
||||
SAS_DPRINTK("%s: task 0x%p is aborted\n",
|
||||
__FUNCTION__, task);
|
||||
task->task_done(task);
|
||||
continue;
|
||||
case TASK_IS_AT_LU:
|
||||
SAS_DPRINTK("task 0x%p is at LU: lu recover\n", task);
|
||||
tmf_resp = sas_recover_lu(task->dev, cmd);
|
||||
if (tmf_resp == TMF_RESP_FUNC_COMPLETE) {
|
||||
SAS_DPRINTK("dev %016llx LU %x is "
|
||||
"recovered\n",
|
||||
SAS_ADDR(task->dev),
|
||||
cmd->device->lun);
|
||||
task->task_done(task);
|
||||
sas_scsi_clear_queue_lu(&error_q, cmd);
|
||||
goto Again;
|
||||
}
|
||||
/* fallthrough */
|
||||
case TASK_IS_NOT_AT_LU:
|
||||
SAS_DPRINTK("task 0x%p is not at LU: I_T recover\n",
|
||||
task);
|
||||
tmf_resp = sas_recover_I_T(task->dev);
|
||||
if (tmf_resp == TMF_RESP_FUNC_COMPLETE) {
|
||||
SAS_DPRINTK("I_T %016llx recovered\n",
|
||||
SAS_ADDR(task->dev->sas_addr));
|
||||
task->task_done(task);
|
||||
sas_scsi_clear_queue_I_T(&error_q, task->dev);
|
||||
goto Again;
|
||||
}
|
||||
/* Hammer time :-) */
|
||||
if (i->dft->lldd_clear_nexus_port) {
|
||||
struct asd_sas_port *port = task->dev->port;
|
||||
SAS_DPRINTK("clearing nexus for port:%d\n",
|
||||
port->id);
|
||||
res = i->dft->lldd_clear_nexus_port(port);
|
||||
if (res == TMF_RESP_FUNC_COMPLETE) {
|
||||
SAS_DPRINTK("clear nexus port:%d "
|
||||
"succeeded\n", port->id);
|
||||
task->task_done(task);
|
||||
sas_scsi_clear_queue_port(&error_q,
|
||||
port);
|
||||
goto Again;
|
||||
}
|
||||
}
|
||||
if (i->dft->lldd_clear_nexus_ha) {
|
||||
SAS_DPRINTK("clear nexus ha\n");
|
||||
res = i->dft->lldd_clear_nexus_ha(ha);
|
||||
if (res == TMF_RESP_FUNC_COMPLETE) {
|
||||
SAS_DPRINTK("clear nexus ha "
|
||||
"succeeded\n");
|
||||
task->task_done(task);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
/* If we are here -- this means that no amount
|
||||
* of effort could recover from errors. Quite
|
||||
* possibly the HA just disappeared.
|
||||
*/
|
||||
SAS_DPRINTK("error from device %llx, LUN %x "
|
||||
"couldn't be recovered in any way\n",
|
||||
SAS_ADDR(task->dev->sas_addr),
|
||||
cmd->device->lun);
|
||||
|
||||
task->task_done(task);
|
||||
goto clear_q;
|
||||
}
|
||||
}
|
||||
out:
|
||||
SAS_DPRINTK("--- Exit %s\n", __FUNCTION__);
|
||||
return;
|
||||
clear_q:
|
||||
SAS_DPRINTK("--- Exit %s -- clear_q\n", __FUNCTION__);
|
||||
list_for_each_entry_safe(cmd, n, &error_q, eh_entry) {
|
||||
struct sas_task *task = TO_SAS_TASK(cmd);
|
||||
list_del_init(&cmd->eh_entry);
|
||||
task->task_done(task);
|
||||
}
|
||||
}
|
||||
|
||||
enum scsi_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd)
|
||||
{
|
||||
struct sas_task *task = TO_SAS_TASK(cmd);
|
||||
unsigned long flags;
|
||||
|
||||
if (!task) {
|
||||
SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_HANDLED\n",
|
||||
cmd, task);
|
||||
return EH_HANDLED;
|
||||
}
|
||||
|
||||
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);
|
||||
SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_HANDLED\n",
|
||||
cmd, task);
|
||||
return EH_HANDLED;
|
||||
}
|
||||
task->task_state_flags |= SAS_TASK_STATE_ABORTED;
|
||||
spin_unlock_irqrestore(&task->task_state_lock, flags);
|
||||
|
||||
SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_NOT_HANDLED\n",
|
||||
cmd, task);
|
||||
|
||||
return EH_NOT_HANDLED;
|
||||
}
|
||||
|
||||
struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy)
|
||||
{
|
||||
struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent);
|
||||
struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
|
||||
struct domain_device *found_dev = NULL;
|
||||
int i;
|
||||
|
||||
spin_lock(&ha->phy_port_lock);
|
||||
for (i = 0; i < ha->num_phys; i++) {
|
||||
struct asd_sas_port *port = ha->sas_port[i];
|
||||
struct domain_device *dev;
|
||||
|
||||
spin_lock(&port->dev_list_lock);
|
||||
list_for_each_entry(dev, &port->dev_list, dev_list_node) {
|
||||
if (rphy == dev->rphy) {
|
||||
found_dev = dev;
|
||||
spin_unlock(&port->dev_list_lock);
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
spin_unlock(&port->dev_list_lock);
|
||||
}
|
||||
found:
|
||||
spin_unlock(&ha->phy_port_lock);
|
||||
|
||||
return found_dev;
|
||||
}
|
||||
|
||||
static inline struct domain_device *sas_find_target(struct scsi_target *starget)
|
||||
{
|
||||
struct sas_rphy *rphy = dev_to_rphy(starget->dev.parent);
|
||||
|
||||
return sas_find_dev_by_rphy(rphy);
|
||||
}
|
||||
|
||||
int sas_target_alloc(struct scsi_target *starget)
|
||||
{
|
||||
struct domain_device *found_dev = sas_find_target(starget);
|
||||
|
||||
if (!found_dev)
|
||||
return -ENODEV;
|
||||
|
||||
starget->hostdata = found_dev;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SAS_DEF_QD 32
|
||||
#define SAS_MAX_QD 64
|
||||
|
||||
int sas_slave_configure(struct scsi_device *scsi_dev)
|
||||
{
|
||||
struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
|
||||
struct sas_ha_struct *sas_ha;
|
||||
|
||||
BUG_ON(dev->rphy->identify.device_type != SAS_END_DEVICE);
|
||||
|
||||
sas_ha = dev->port->ha;
|
||||
|
||||
sas_read_port_mode_page(scsi_dev);
|
||||
|
||||
if (scsi_dev->tagged_supported) {
|
||||
scsi_set_tag_type(scsi_dev, MSG_SIMPLE_TAG);
|
||||
scsi_activate_tcq(scsi_dev, SAS_DEF_QD);
|
||||
} else {
|
||||
SAS_DPRINTK("device %llx, LUN %x doesn't support "
|
||||
"TCQ\n", SAS_ADDR(dev->sas_addr),
|
||||
scsi_dev->lun);
|
||||
scsi_dev->tagged_supported = 0;
|
||||
scsi_set_tag_type(scsi_dev, 0);
|
||||
scsi_deactivate_tcq(scsi_dev, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sas_slave_destroy(struct scsi_device *scsi_dev)
|
||||
{
|
||||
}
|
||||
|
||||
int sas_change_queue_depth(struct scsi_device *scsi_dev, int new_depth)
|
||||
{
|
||||
int res = min(new_depth, SAS_MAX_QD);
|
||||
|
||||
if (scsi_dev->tagged_supported)
|
||||
scsi_adjust_queue_depth(scsi_dev, scsi_get_tag_type(scsi_dev),
|
||||
res);
|
||||
else {
|
||||
struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
|
||||
sas_printk("device %llx LUN %x queue depth changed to 1\n",
|
||||
SAS_ADDR(dev->sas_addr),
|
||||
scsi_dev->lun);
|
||||
scsi_adjust_queue_depth(scsi_dev, 0, 1);
|
||||
res = 1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int sas_change_queue_type(struct scsi_device *scsi_dev, int qt)
|
||||
{
|
||||
if (!scsi_dev->tagged_supported)
|
||||
return 0;
|
||||
|
||||
scsi_deactivate_tcq(scsi_dev, 1);
|
||||
|
||||
scsi_set_tag_type(scsi_dev, qt);
|
||||
scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth);
|
||||
|
||||
return qt;
|
||||
}
|
||||
|
||||
int sas_bios_param(struct scsi_device *scsi_dev,
|
||||
struct block_device *bdev,
|
||||
sector_t capacity, int *hsc)
|
||||
{
|
||||
hsc[0] = 255;
|
||||
hsc[1] = 63;
|
||||
sector_div(capacity, 255*63);
|
||||
hsc[2] = capacity;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------- Task Collector Thread implementation ---------- */
|
||||
|
||||
static void sas_queue(struct sas_ha_struct *sas_ha)
|
||||
{
|
||||
struct scsi_core *core = &sas_ha->core;
|
||||
unsigned long flags;
|
||||
LIST_HEAD(q);
|
||||
int can_queue;
|
||||
int res;
|
||||
struct sas_internal *i = to_sas_internal(core->shost->transportt);
|
||||
|
||||
spin_lock_irqsave(&core->task_queue_lock, flags);
|
||||
while (!core->queue_thread_kill &&
|
||||
!list_empty(&core->task_queue)) {
|
||||
|
||||
can_queue = sas_ha->lldd_queue_size - core->task_queue_size;
|
||||
if (can_queue >= 0) {
|
||||
can_queue = core->task_queue_size;
|
||||
list_splice_init(&core->task_queue, &q);
|
||||
} else {
|
||||
struct list_head *a, *n;
|
||||
|
||||
can_queue = sas_ha->lldd_queue_size;
|
||||
list_for_each_safe(a, n, &core->task_queue) {
|
||||
list_move_tail(a, &q);
|
||||
if (--can_queue == 0)
|
||||
break;
|
||||
}
|
||||
can_queue = sas_ha->lldd_queue_size;
|
||||
}
|
||||
core->task_queue_size -= can_queue;
|
||||
spin_unlock_irqrestore(&core->task_queue_lock, flags);
|
||||
{
|
||||
struct sas_task *task = list_entry(q.next,
|
||||
struct sas_task,
|
||||
list);
|
||||
list_del_init(&q);
|
||||
res = i->dft->lldd_execute_task(task, can_queue,
|
||||
GFP_KERNEL);
|
||||
if (unlikely(res))
|
||||
__list_add(&q, task->list.prev, &task->list);
|
||||
}
|
||||
spin_lock_irqsave(&core->task_queue_lock, flags);
|
||||
if (res) {
|
||||
list_splice_init(&q, &core->task_queue); /*at head*/
|
||||
core->task_queue_size += can_queue;
|
||||
}
|
||||
}
|
||||
spin_unlock_irqrestore(&core->task_queue_lock, flags);
|
||||
}
|
||||
|
||||
static DECLARE_COMPLETION(queue_th_comp);
|
||||
|
||||
/**
|
||||
* sas_queue_thread -- The Task Collector thread
|
||||
* @_sas_ha: pointer to struct sas_ha
|
||||
*/
|
||||
static int sas_queue_thread(void *_sas_ha)
|
||||
{
|
||||
struct sas_ha_struct *sas_ha = _sas_ha;
|
||||
struct scsi_core *core = &sas_ha->core;
|
||||
|
||||
daemonize("sas_queue_%d", core->shost->host_no);
|
||||
current->flags |= PF_NOFREEZE;
|
||||
|
||||
complete(&queue_th_comp);
|
||||
|
||||
while (1) {
|
||||
down_interruptible(&core->queue_thread_sema);
|
||||
sas_queue(sas_ha);
|
||||
if (core->queue_thread_kill)
|
||||
break;
|
||||
}
|
||||
|
||||
complete(&queue_th_comp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sas_init_queue(struct sas_ha_struct *sas_ha)
|
||||
{
|
||||
int res;
|
||||
struct scsi_core *core = &sas_ha->core;
|
||||
|
||||
spin_lock_init(&core->task_queue_lock);
|
||||
core->task_queue_size = 0;
|
||||
INIT_LIST_HEAD(&core->task_queue);
|
||||
init_MUTEX_LOCKED(&core->queue_thread_sema);
|
||||
|
||||
res = kernel_thread(sas_queue_thread, sas_ha, 0);
|
||||
if (res >= 0)
|
||||
wait_for_completion(&queue_th_comp);
|
||||
|
||||
return res < 0 ? res : 0;
|
||||
}
|
||||
|
||||
void sas_shutdown_queue(struct sas_ha_struct *sas_ha)
|
||||
{
|
||||
unsigned long flags;
|
||||
struct scsi_core *core = &sas_ha->core;
|
||||
struct sas_task *task, *n;
|
||||
|
||||
init_completion(&queue_th_comp);
|
||||
core->queue_thread_kill = 1;
|
||||
up(&core->queue_thread_sema);
|
||||
wait_for_completion(&queue_th_comp);
|
||||
|
||||
if (!list_empty(&core->task_queue))
|
||||
SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n",
|
||||
SAS_ADDR(sas_ha->sas_addr));
|
||||
|
||||
spin_lock_irqsave(&core->task_queue_lock, flags);
|
||||
list_for_each_entry_safe(task, n, &core->task_queue, list) {
|
||||
struct scsi_cmnd *cmd = task->uldd_task;
|
||||
|
||||
list_del_init(&task->list);
|
||||
|
||||
ASSIGN_SAS_TASK(cmd, NULL);
|
||||
sas_free_task(task);
|
||||
cmd->result = DID_ABORT << 16;
|
||||
cmd->scsi_done(cmd);
|
||||
}
|
||||
spin_unlock_irqrestore(&core->task_queue_lock, flags);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL_GPL(sas_queuecommand);
|
||||
EXPORT_SYMBOL_GPL(sas_target_alloc);
|
||||
EXPORT_SYMBOL_GPL(sas_slave_configure);
|
||||
EXPORT_SYMBOL_GPL(sas_slave_destroy);
|
||||
EXPORT_SYMBOL_GPL(sas_change_queue_depth);
|
||||
EXPORT_SYMBOL_GPL(sas_change_queue_type);
|
||||
EXPORT_SYMBOL_GPL(sas_bios_param);
|
Reference in New Issue
Block a user