2019-05-02 00:14:10 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2006-08-29 22:22:51 +08:00
|
|
|
/*
|
|
|
|
* Serial Attached SCSI (SAS) Expander discovery and configuration
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Adaptec, Inc. All rights reserved.
|
|
|
|
* Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
|
|
|
|
*
|
|
|
|
* This file is licensed under GPLv2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/scatterlist.h>
|
2007-07-09 11:52:08 +08:00
|
|
|
#include <linux/blkdev.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2019-01-24 03:08:05 +08:00
|
|
|
#include <asm/unaligned.h>
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
#include "sas_internal.h"
|
|
|
|
|
2011-12-01 15:23:33 +08:00
|
|
|
#include <scsi/sas_ata.h>
|
2006-08-29 22:22:51 +08:00
|
|
|
#include <scsi/scsi_transport.h>
|
|
|
|
#include <scsi/scsi_transport_sas.h>
|
|
|
|
#include "../scsi_sas_internal.h"
|
|
|
|
|
|
|
|
static int sas_discover_expander(struct domain_device *dev);
|
|
|
|
static int sas_configure_routing(struct domain_device *dev, u8 *sas_addr);
|
|
|
|
static int sas_configure_phy(struct domain_device *dev, int phy_id,
|
|
|
|
u8 *sas_addr, int include);
|
|
|
|
static int sas_disable_routing(struct domain_device *dev, u8 *sas_addr);
|
|
|
|
|
|
|
|
/* ---------- SMP task management ---------- */
|
|
|
|
|
2017-08-23 07:05:14 +08:00
|
|
|
static void smp_task_timedout(struct timer_list *t)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
2017-08-23 07:05:14 +08:00
|
|
|
struct sas_task_slow *slow = from_timer(slow, t, timer);
|
|
|
|
struct sas_task *task = slow->task;
|
2006-08-29 22:22:51 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&task->task_state_lock, flags);
|
2018-09-25 10:56:54 +08:00
|
|
|
if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
|
2006-08-29 22:22:51 +08:00
|
|
|
task->task_state_flags |= SAS_TASK_STATE_ABORTED;
|
2018-09-25 10:56:54 +08:00
|
|
|
complete(&task->slow_task->completion);
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
spin_unlock_irqrestore(&task->task_state_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smp_task_done(struct sas_task *task)
|
|
|
|
{
|
2018-09-25 10:56:54 +08:00
|
|
|
del_timer(&task->slow_task->timer);
|
2012-06-22 14:36:30 +08:00
|
|
|
complete(&task->slow_task->completion);
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Give it some long enough timeout. In seconds. */
|
|
|
|
#define SMP_TIMEOUT 10
|
|
|
|
|
2017-08-25 23:37:41 +08:00
|
|
|
static int smp_execute_task_sg(struct domain_device *dev,
|
|
|
|
struct scatterlist *req, struct scatterlist *resp)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
2006-10-05 08:34:03 +08:00
|
|
|
int res, retry;
|
|
|
|
struct sas_task *task = NULL;
|
2006-08-29 22:22:51 +08:00
|
|
|
struct sas_internal *i =
|
|
|
|
to_sas_internal(dev->port->ha->core.shost->transportt);
|
2024-06-12 13:13:20 +08:00
|
|
|
struct sas_ha_struct *ha = dev->port->ha;
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2024-06-12 13:13:20 +08:00
|
|
|
pm_runtime_get_sync(ha->dev);
|
2011-11-16 17:44:13 +08:00
|
|
|
mutex_lock(&dev->ex_dev.cmd_mutex);
|
2006-10-05 08:34:03 +08:00
|
|
|
for (retry = 0; retry < 3; retry++) {
|
2011-12-22 07:19:56 +08:00
|
|
|
if (test_bit(SAS_DEV_GONE, &dev->state)) {
|
|
|
|
res = -ECOMM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-22 14:36:30 +08:00
|
|
|
task = sas_alloc_slow_task(GFP_KERNEL);
|
2011-11-16 17:44:13 +08:00
|
|
|
if (!task) {
|
|
|
|
res = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2006-10-05 08:34:03 +08:00
|
|
|
task->dev = dev;
|
|
|
|
task->task_proto = dev->tproto;
|
2017-08-25 23:37:41 +08:00
|
|
|
task->smp_task.smp_req = *req;
|
|
|
|
task->smp_task.smp_resp = *resp;
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2006-10-05 08:34:03 +08:00
|
|
|
task->task_done = smp_task_done;
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2017-10-23 15:40:42 +08:00
|
|
|
task->slow_task->timer.function = smp_task_timedout;
|
2012-06-22 14:36:30 +08:00
|
|
|
task->slow_task->timer.expires = jiffies + SMP_TIMEOUT*HZ;
|
|
|
|
add_timer(&task->slow_task->timer);
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2014-11-05 17:36:28 +08:00
|
|
|
res = i->dft->lldd_execute_task(task, GFP_KERNEL);
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2006-10-05 08:34:03 +08:00
|
|
|
if (res) {
|
2024-06-12 13:13:20 +08:00
|
|
|
del_timer_sync(&task->slow_task->timer);
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_notice("executing SMP task failed:%d\n", res);
|
2011-11-16 17:44:13 +08:00
|
|
|
break;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
2006-10-05 08:34:03 +08:00
|
|
|
|
2012-06-22 14:36:30 +08:00
|
|
|
wait_for_completion(&task->slow_task->completion);
|
2007-12-31 02:37:31 +08:00
|
|
|
res = -ECOMM;
|
2006-10-05 08:34:03 +08:00
|
|
|
if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_notice("smp task timed out or aborted\n");
|
2006-10-05 08:34:03 +08:00
|
|
|
i->dft->lldd_abort_task(task);
|
|
|
|
if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_notice("SMP task aborted and not done\n");
|
2011-11-16 17:44:13 +08:00
|
|
|
break;
|
2006-10-05 08:34:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (task->task_status.resp == SAS_TASK_COMPLETE &&
|
2010-07-28 04:51:13 +08:00
|
|
|
task->task_status.stat == SAM_STAT_GOOD) {
|
2006-10-05 08:34:03 +08:00
|
|
|
res = 0;
|
|
|
|
break;
|
2011-11-16 17:44:13 +08:00
|
|
|
}
|
|
|
|
if (task->task_status.resp == SAS_TASK_COMPLETE &&
|
|
|
|
task->task_status.stat == SAS_DATA_UNDERRUN) {
|
2007-12-30 01:49:53 +08:00
|
|
|
/* no error, but return the number of bytes of
|
|
|
|
* underrun */
|
|
|
|
res = task->task_status.residual;
|
|
|
|
break;
|
2011-11-16 17:44:13 +08:00
|
|
|
}
|
|
|
|
if (task->task_status.resp == SAS_TASK_COMPLETE &&
|
|
|
|
task->task_status.stat == SAS_DATA_OVERRUN) {
|
2007-12-30 01:49:53 +08:00
|
|
|
res = -EMSGSIZE;
|
|
|
|
break;
|
2011-11-18 09:59:54 +08:00
|
|
|
}
|
|
|
|
if (task->task_status.resp == SAS_TASK_UNDELIVERED &&
|
|
|
|
task->task_status.stat == SAS_DEVICE_UNKNOWN)
|
|
|
|
break;
|
|
|
|
else {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_notice("%s: task to dev %016llx response: 0x%x status 0x%x\n",
|
|
|
|
__func__,
|
|
|
|
SAS_ADDR(dev->sas_addr),
|
|
|
|
task->task_status.resp,
|
|
|
|
task->task_status.stat);
|
2006-10-05 08:34:03 +08:00
|
|
|
sas_free_task(task);
|
|
|
|
task = NULL;
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
2011-11-16 17:44:13 +08:00
|
|
|
mutex_unlock(&dev->ex_dev.cmd_mutex);
|
2024-06-12 13:13:20 +08:00
|
|
|
pm_runtime_put_sync(ha->dev);
|
2011-11-16 17:44:13 +08:00
|
|
|
|
2006-10-05 08:34:03 +08:00
|
|
|
BUG_ON(retry == 3 && task != NULL);
|
2011-11-16 17:44:13 +08:00
|
|
|
sas_free_task(task);
|
2006-08-29 22:22:51 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-08-25 23:37:41 +08:00
|
|
|
static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
|
|
|
|
void *resp, int resp_size)
|
|
|
|
{
|
|
|
|
struct scatterlist req_sg;
|
|
|
|
struct scatterlist resp_sg;
|
|
|
|
|
|
|
|
sg_init_one(&req_sg, req, req_size);
|
|
|
|
sg_init_one(&resp_sg, resp, resp_size);
|
|
|
|
return smp_execute_task_sg(dev, &req_sg, &resp_sg);
|
|
|
|
}
|
|
|
|
|
2006-08-29 22:22:51 +08:00
|
|
|
/* ---------- Allocations ---------- */
|
|
|
|
|
|
|
|
static inline void *alloc_smp_req(int size)
|
|
|
|
{
|
|
|
|
u8 *p = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (p)
|
|
|
|
p[0] = SMP_REQUEST;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *alloc_smp_resp(int size)
|
|
|
|
{
|
|
|
|
return kzalloc(size, GFP_KERNEL);
|
|
|
|
}
|
|
|
|
|
2012-01-17 03:56:50 +08:00
|
|
|
static char sas_route_char(struct domain_device *dev, struct ex_phy *phy)
|
|
|
|
{
|
|
|
|
switch (phy->routing_attr) {
|
|
|
|
case TABLE_ROUTING:
|
|
|
|
if (dev->ex_dev.t2t_supp)
|
|
|
|
return 'U';
|
|
|
|
else
|
|
|
|
return 'T';
|
|
|
|
case DIRECT_ROUTING:
|
|
|
|
return 'D';
|
|
|
|
case SUBTRACTIVE_ROUTING:
|
|
|
|
return 'S';
|
|
|
|
default:
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2013-05-08 05:44:06 +08:00
|
|
|
static enum sas_device_type to_dev_type(struct discover_resp *dr)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
2012-01-13 09:57:35 +08:00
|
|
|
/* This is detecting a failure to transmit initial dev to host
|
|
|
|
* FIS as described in section J.5 of sas-2 r16
|
|
|
|
*/
|
2013-05-08 05:44:06 +08:00
|
|
|
if (dr->attached_dev_type == SAS_PHY_UNUSED && dr->attached_sata_dev &&
|
2012-01-13 09:57:35 +08:00
|
|
|
dr->linkrate >= SAS_LINK_RATE_1_5_GBPS)
|
2013-05-08 05:44:06 +08:00
|
|
|
return SAS_SATA_PENDING;
|
2012-01-13 09:57:35 +08:00
|
|
|
else
|
|
|
|
return dr->attached_dev_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sas_set_ex_phy(struct domain_device *dev, int phy_id, void *rsp)
|
|
|
|
{
|
2013-05-08 05:44:06 +08:00
|
|
|
enum sas_device_type dev_type;
|
2012-01-13 09:57:35 +08:00
|
|
|
enum sas_linkrate linkrate;
|
|
|
|
u8 sas_addr[SAS_ADDR_SIZE];
|
|
|
|
struct smp_resp *resp = rsp;
|
|
|
|
struct discover_resp *dr = &resp->disc;
|
2012-03-21 04:24:29 +08:00
|
|
|
struct sas_ha_struct *ha = dev->port->ha;
|
2006-08-29 22:22:51 +08:00
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
struct ex_phy *phy = &ex->ex_phy[phy_id];
|
|
|
|
struct sas_rphy *rphy = dev->rphy;
|
2012-01-17 03:56:50 +08:00
|
|
|
bool new_phy = !phy->phy;
|
|
|
|
char *type;
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2012-01-17 03:56:50 +08:00
|
|
|
if (new_phy) {
|
2012-03-21 04:24:29 +08:00
|
|
|
if (WARN_ON_ONCE(test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)))
|
|
|
|
return;
|
2006-08-29 22:22:51 +08:00
|
|
|
phy->phy = sas_phy_alloc(&rphy->dev, phy_id);
|
|
|
|
|
|
|
|
/* FIXME: error_handling */
|
|
|
|
BUG_ON(!phy->phy);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (resp->result) {
|
|
|
|
case SMP_RESP_PHY_VACANT:
|
|
|
|
phy->phy_state = PHY_VACANT;
|
2010-10-06 16:05:35 +08:00
|
|
|
break;
|
2006-08-29 22:22:51 +08:00
|
|
|
default:
|
|
|
|
phy->phy_state = PHY_NOT_PRESENT;
|
2010-10-06 16:05:35 +08:00
|
|
|
break;
|
2006-08-29 22:22:51 +08:00
|
|
|
case SMP_RESP_FUNC_ACC:
|
|
|
|
phy->phy_state = PHY_EMPTY; /* do not know yet */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-13 09:57:35 +08:00
|
|
|
/* check if anything important changed to squelch debug */
|
|
|
|
dev_type = phy->attached_dev_type;
|
|
|
|
linkrate = phy->linkrate;
|
|
|
|
memcpy(sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
|
|
|
|
|
2013-04-03 16:27:17 +08:00
|
|
|
/* Handle vacant phy - rest of dr data is not valid so skip it */
|
|
|
|
if (phy->phy_state == PHY_VACANT) {
|
|
|
|
memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
|
2013-05-08 05:44:06 +08:00
|
|
|
phy->attached_dev_type = SAS_PHY_UNUSED;
|
2013-04-03 16:27:17 +08:00
|
|
|
if (!test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)) {
|
|
|
|
phy->phy_id = phy_id;
|
|
|
|
goto skip;
|
|
|
|
} else
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-01-13 09:57:35 +08:00
|
|
|
phy->attached_dev_type = to_dev_type(dr);
|
2012-03-21 04:24:29 +08:00
|
|
|
if (test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state))
|
|
|
|
goto out;
|
2006-08-29 22:22:51 +08:00
|
|
|
phy->phy_id = phy_id;
|
|
|
|
phy->linkrate = dr->linkrate;
|
|
|
|
phy->attached_sata_host = dr->attached_sata_host;
|
|
|
|
phy->attached_sata_dev = dr->attached_sata_dev;
|
|
|
|
phy->attached_sata_ps = dr->attached_sata_ps;
|
|
|
|
phy->attached_iproto = dr->iproto << 1;
|
|
|
|
phy->attached_tproto = dr->tproto << 1;
|
2012-03-21 01:50:27 +08:00
|
|
|
/* help some expanders that fail to zero sas_address in the 'no
|
|
|
|
* device' case
|
|
|
|
*/
|
2024-03-12 22:11:03 +08:00
|
|
|
if (phy->attached_dev_type == SAS_PHY_UNUSED)
|
2012-03-21 01:50:27 +08:00
|
|
|
memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
|
|
|
|
else
|
|
|
|
memcpy(phy->attached_sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE);
|
2006-08-29 22:22:51 +08:00
|
|
|
phy->attached_phy_id = dr->attached_phy_id;
|
|
|
|
phy->phy_change_count = dr->change_count;
|
|
|
|
phy->routing_attr = dr->routing_attr;
|
|
|
|
phy->virtual = dr->virtual;
|
|
|
|
phy->last_da_index = -1;
|
|
|
|
|
2011-09-23 14:32:32 +08:00
|
|
|
phy->phy->identify.sas_address = SAS_ADDR(phy->attached_sas_addr);
|
2012-01-13 09:57:35 +08:00
|
|
|
phy->phy->identify.device_type = dr->attached_dev_type;
|
2006-08-29 22:22:51 +08:00
|
|
|
phy->phy->identify.initiator_port_protocols = phy->attached_iproto;
|
|
|
|
phy->phy->identify.target_port_protocols = phy->attached_tproto;
|
2012-02-09 15:20:41 +08:00
|
|
|
if (!phy->attached_tproto && dr->attached_sata_dev)
|
|
|
|
phy->phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
|
2006-08-29 22:22:51 +08:00
|
|
|
phy->phy->identify.phy_identifier = phy_id;
|
2006-09-07 08:28:07 +08:00
|
|
|
phy->phy->minimum_linkrate_hw = dr->hmin_linkrate;
|
|
|
|
phy->phy->maximum_linkrate_hw = dr->hmax_linkrate;
|
|
|
|
phy->phy->minimum_linkrate = dr->pmin_linkrate;
|
|
|
|
phy->phy->maximum_linkrate = dr->pmax_linkrate;
|
2006-09-07 06:36:13 +08:00
|
|
|
phy->phy->negotiated_linkrate = phy->linkrate;
|
2018-01-04 21:04:33 +08:00
|
|
|
phy->phy->enabled = (phy->linkrate != SAS_PHY_DISABLED);
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2013-04-03 16:27:17 +08:00
|
|
|
skip:
|
2012-01-17 03:56:50 +08:00
|
|
|
if (new_phy)
|
2010-10-06 16:05:35 +08:00
|
|
|
if (sas_phy_add(phy->phy)) {
|
|
|
|
sas_phy_free(phy->phy);
|
|
|
|
return;
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2012-03-21 04:24:29 +08:00
|
|
|
out:
|
2012-01-17 03:56:50 +08:00
|
|
|
switch (phy->attached_dev_type) {
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_SATA_PENDING:
|
2012-01-13 09:57:35 +08:00
|
|
|
type = "stp pending";
|
|
|
|
break;
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_PHY_UNUSED:
|
2012-01-17 03:56:50 +08:00
|
|
|
type = "no device";
|
|
|
|
break;
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_END_DEVICE:
|
2012-01-17 03:56:50 +08:00
|
|
|
if (phy->attached_iproto) {
|
|
|
|
if (phy->attached_tproto)
|
|
|
|
type = "host+target";
|
|
|
|
else
|
|
|
|
type = "host";
|
|
|
|
} else {
|
|
|
|
if (dr->attached_sata_dev)
|
|
|
|
type = "stp";
|
|
|
|
else
|
|
|
|
type = "ssp";
|
|
|
|
}
|
|
|
|
break;
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_EDGE_EXPANDER_DEVICE:
|
|
|
|
case SAS_FANOUT_EXPANDER_DEVICE:
|
2012-01-17 03:56:50 +08:00
|
|
|
type = "smp";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "unknown";
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2012-01-13 09:57:35 +08:00
|
|
|
/* this routine is polled by libata error recovery so filter
|
|
|
|
* unimportant messages
|
|
|
|
*/
|
|
|
|
if (new_phy || phy->attached_dev_type != dev_type ||
|
|
|
|
phy->linkrate != linkrate ||
|
|
|
|
SAS_ADDR(phy->attached_sas_addr) != SAS_ADDR(sas_addr))
|
|
|
|
/* pass */;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2012-03-21 04:24:29 +08:00
|
|
|
/* if the attached device type changed and ata_eh is active,
|
|
|
|
* make sure we run revalidation when eh completes (see:
|
|
|
|
* sas_enable_revalidation)
|
|
|
|
*/
|
|
|
|
if (test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state))
|
|
|
|
set_bit(DISCE_REVALIDATE_DOMAIN, &dev->port->disc.pending);
|
|
|
|
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_debug("%sex %016llx phy%02d:%c:%X attached: %016llx (%s)\n",
|
|
|
|
test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state) ? "ata: " : "",
|
|
|
|
SAS_ADDR(dev->sas_addr), phy->phy_id,
|
|
|
|
sas_route_char(dev, phy), phy->linkrate,
|
|
|
|
SAS_ADDR(phy->attached_sas_addr), type);
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
2011-12-01 15:23:33 +08:00
|
|
|
/* check if we have an existing attached ata device on this expander phy */
|
2011-12-03 08:07:01 +08:00
|
|
|
struct domain_device *sas_ex_to_ata(struct domain_device *ex_dev, int phy_id)
|
2011-12-01 15:23:33 +08:00
|
|
|
{
|
|
|
|
struct ex_phy *ex_phy = &ex_dev->ex_dev.ex_phy[phy_id];
|
|
|
|
struct domain_device *dev;
|
|
|
|
struct sas_rphy *rphy;
|
|
|
|
|
|
|
|
if (!ex_phy->port)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
rphy = ex_phy->port->rphy;
|
|
|
|
if (!rphy)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dev = sas_find_dev_by_rphy(rphy);
|
|
|
|
|
|
|
|
if (dev && dev_is_sata(dev))
|
|
|
|
return dev;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-08-29 22:22:51 +08:00
|
|
|
#define DISCOVER_REQ_SIZE 16
|
|
|
|
#define DISCOVER_RESP_SIZE 56
|
|
|
|
|
2006-08-23 01:39:19 +08:00
|
|
|
static int sas_ex_phy_discover_helper(struct domain_device *dev, u8 *disc_req,
|
|
|
|
u8 *disc_resp, int single)
|
|
|
|
{
|
2012-01-13 09:57:35 +08:00
|
|
|
struct discover_resp *dr;
|
|
|
|
int res;
|
2006-08-23 01:39:19 +08:00
|
|
|
|
|
|
|
disc_req[9] = single;
|
|
|
|
|
2012-01-13 09:57:35 +08:00
|
|
|
res = smp_execute_task(dev, disc_req, DISCOVER_REQ_SIZE,
|
|
|
|
disc_resp, DISCOVER_RESP_SIZE);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
dr = &((struct smp_resp *)disc_resp)->disc;
|
|
|
|
if (memcmp(dev->sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE) == 0) {
|
2018-11-15 18:20:30 +08:00
|
|
|
pr_notice("Found loopback topology, just ignore it!\n");
|
2012-01-13 09:57:35 +08:00
|
|
|
return 0;
|
2006-08-23 01:39:19 +08:00
|
|
|
}
|
|
|
|
sas_set_ex_phy(dev, single, disc_resp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-13 09:57:35 +08:00
|
|
|
int sas_ex_phy_discover(struct domain_device *dev, int single)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
int res = 0;
|
|
|
|
u8 *disc_req;
|
|
|
|
u8 *disc_resp;
|
|
|
|
|
|
|
|
disc_req = alloc_smp_req(DISCOVER_REQ_SIZE);
|
|
|
|
if (!disc_req)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-03-06 10:43:03 +08:00
|
|
|
disc_resp = alloc_smp_resp(DISCOVER_RESP_SIZE);
|
2006-08-29 22:22:51 +08:00
|
|
|
if (!disc_resp) {
|
|
|
|
kfree(disc_req);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
disc_req[1] = SMP_DISCOVER;
|
|
|
|
|
|
|
|
if (0 <= single && single < ex->num_phys) {
|
2006-08-23 01:39:19 +08:00
|
|
|
res = sas_ex_phy_discover_helper(dev, disc_req, disc_resp, single);
|
2006-08-29 22:22:51 +08:00
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ex->num_phys; i++) {
|
2006-08-23 01:39:19 +08:00
|
|
|
res = sas_ex_phy_discover_helper(dev, disc_req,
|
|
|
|
disc_resp, i);
|
2006-08-29 22:22:51 +08:00
|
|
|
if (res)
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out_err:
|
|
|
|
kfree(disc_resp);
|
|
|
|
kfree(disc_req);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_expander_discover(struct domain_device *dev)
|
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
int res = -ENOMEM;
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:03:40 +08:00
|
|
|
ex->ex_phy = kcalloc(ex->num_phys, sizeof(*ex->ex_phy), GFP_KERNEL);
|
2006-08-29 22:22:51 +08:00
|
|
|
if (!ex->ex_phy)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
res = sas_ex_phy_discover(dev, -1);
|
|
|
|
if (res)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_err:
|
|
|
|
kfree(ex->ex_phy);
|
|
|
|
ex->ex_phy = NULL;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_EXPANDER_PHYS 128
|
|
|
|
|
|
|
|
static void ex_assign_report_general(struct domain_device *dev,
|
|
|
|
struct smp_resp *resp)
|
|
|
|
{
|
|
|
|
struct report_general_resp *rg = &resp->rg;
|
|
|
|
|
|
|
|
dev->ex_dev.ex_change_count = be16_to_cpu(rg->change_count);
|
|
|
|
dev->ex_dev.max_route_indexes = be16_to_cpu(rg->route_indexes);
|
|
|
|
dev->ex_dev.num_phys = min(rg->num_phys, (u8)MAX_EXPANDER_PHYS);
|
2011-09-23 00:41:36 +08:00
|
|
|
dev->ex_dev.t2t_supp = rg->t2t_supp;
|
2006-08-29 22:22:51 +08:00
|
|
|
dev->ex_dev.conf_route_table = rg->conf_route_table;
|
|
|
|
dev->ex_dev.configuring = rg->configuring;
|
|
|
|
memcpy(dev->ex_dev.enclosure_logical_id, rg->enclosure_logical_id, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RG_REQ_SIZE 8
|
|
|
|
#define RG_RESP_SIZE 32
|
|
|
|
|
|
|
|
static int sas_ex_general(struct domain_device *dev)
|
|
|
|
{
|
|
|
|
u8 *rg_req;
|
|
|
|
struct smp_resp *rg_resp;
|
|
|
|
int res;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rg_req = alloc_smp_req(RG_REQ_SIZE);
|
|
|
|
if (!rg_req)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rg_resp = alloc_smp_resp(RG_RESP_SIZE);
|
|
|
|
if (!rg_resp) {
|
|
|
|
kfree(rg_req);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
rg_req[1] = SMP_REPORT_GENERAL;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
res = smp_execute_task(dev, rg_req, RG_REQ_SIZE, rg_resp,
|
|
|
|
RG_RESP_SIZE);
|
|
|
|
|
|
|
|
if (res) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_notice("RG to ex %016llx failed:0x%x\n",
|
|
|
|
SAS_ADDR(dev->sas_addr), res);
|
2006-08-29 22:22:51 +08:00
|
|
|
goto out;
|
|
|
|
} else if (rg_resp->result != SMP_RESP_FUNC_ACC) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_debug("RG:ex %016llx returned SMP result:0x%x\n",
|
|
|
|
SAS_ADDR(dev->sas_addr), rg_resp->result);
|
2006-08-29 22:22:51 +08:00
|
|
|
res = rg_resp->result;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ex_assign_report_general(dev, rg_resp);
|
|
|
|
|
|
|
|
if (dev->ex_dev.configuring) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_debug("RG: ex %llx self-configuring...\n",
|
|
|
|
SAS_ADDR(dev->sas_addr));
|
2006-08-29 22:22:51 +08:00
|
|
|
schedule_timeout_interruptible(5*HZ);
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
kfree(rg_req);
|
|
|
|
kfree(rg_resp);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ex_assign_manuf_info(struct domain_device *dev, void
|
|
|
|
*_mi_resp)
|
|
|
|
{
|
|
|
|
u8 *mi_resp = _mi_resp;
|
|
|
|
struct sas_rphy *rphy = dev->rphy;
|
|
|
|
struct sas_expander_device *edev = rphy_to_expander_device(rphy);
|
|
|
|
|
|
|
|
memcpy(edev->vendor_id, mi_resp + 12, SAS_EXPANDER_VENDOR_ID_LEN);
|
|
|
|
memcpy(edev->product_id, mi_resp + 20, SAS_EXPANDER_PRODUCT_ID_LEN);
|
|
|
|
memcpy(edev->product_rev, mi_resp + 36,
|
|
|
|
SAS_EXPANDER_PRODUCT_REV_LEN);
|
|
|
|
|
|
|
|
if (mi_resp[8] & 1) {
|
|
|
|
memcpy(edev->component_vendor_id, mi_resp + 40,
|
|
|
|
SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
|
|
|
|
edev->component_id = mi_resp[48] << 8 | mi_resp[49];
|
|
|
|
edev->component_revision_id = mi_resp[50];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MI_REQ_SIZE 8
|
|
|
|
#define MI_RESP_SIZE 64
|
|
|
|
|
|
|
|
static int sas_ex_manuf_info(struct domain_device *dev)
|
|
|
|
{
|
|
|
|
u8 *mi_req;
|
|
|
|
u8 *mi_resp;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
mi_req = alloc_smp_req(MI_REQ_SIZE);
|
|
|
|
if (!mi_req)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
mi_resp = alloc_smp_resp(MI_RESP_SIZE);
|
|
|
|
if (!mi_resp) {
|
|
|
|
kfree(mi_req);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
mi_req[1] = SMP_REPORT_MANUF_INFO;
|
|
|
|
|
|
|
|
res = smp_execute_task(dev, mi_req, MI_REQ_SIZE, mi_resp,MI_RESP_SIZE);
|
|
|
|
if (res) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_notice("MI: ex %016llx failed:0x%x\n",
|
|
|
|
SAS_ADDR(dev->sas_addr), res);
|
2006-08-29 22:22:51 +08:00
|
|
|
goto out;
|
|
|
|
} else if (mi_resp[2] != SMP_RESP_FUNC_ACC) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_debug("MI ex %016llx returned SMP result:0x%x\n",
|
|
|
|
SAS_ADDR(dev->sas_addr), mi_resp[2]);
|
2006-08-29 22:22:51 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ex_assign_manuf_info(dev, mi_resp);
|
|
|
|
out:
|
|
|
|
kfree(mi_req);
|
|
|
|
kfree(mi_resp);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PC_REQ_SIZE 44
|
|
|
|
#define PC_RESP_SIZE 8
|
|
|
|
|
|
|
|
int sas_smp_phy_control(struct domain_device *dev, int phy_id,
|
2006-09-07 08:28:07 +08:00
|
|
|
enum phy_func phy_func,
|
|
|
|
struct sas_phy_linkrates *rates)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
|
|
|
u8 *pc_req;
|
|
|
|
u8 *pc_resp;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
pc_req = alloc_smp_req(PC_REQ_SIZE);
|
|
|
|
if (!pc_req)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pc_resp = alloc_smp_resp(PC_RESP_SIZE);
|
|
|
|
if (!pc_resp) {
|
|
|
|
kfree(pc_req);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
pc_req[1] = SMP_PHY_CONTROL;
|
|
|
|
pc_req[9] = phy_id;
|
|
|
|
pc_req[10]= phy_func;
|
2006-09-07 08:28:07 +08:00
|
|
|
if (rates) {
|
|
|
|
pc_req[32] = rates->minimum_linkrate << 4;
|
|
|
|
pc_req[33] = rates->maximum_linkrate << 4;
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
res = smp_execute_task(dev, pc_req, PC_REQ_SIZE, pc_resp,PC_RESP_SIZE);
|
2019-01-05 00:01:27 +08:00
|
|
|
if (res) {
|
|
|
|
pr_err("ex %016llx phy%02d PHY control failed: %d\n",
|
|
|
|
SAS_ADDR(dev->sas_addr), phy_id, res);
|
|
|
|
} else if (pc_resp[2] != SMP_RESP_FUNC_ACC) {
|
|
|
|
pr_err("ex %016llx phy%02d PHY control failed: function result 0x%x\n",
|
|
|
|
SAS_ADDR(dev->sas_addr), phy_id, pc_resp[2]);
|
|
|
|
res = pc_resp[2];
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
kfree(pc_resp);
|
|
|
|
kfree(pc_req);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sas_ex_disable_phy(struct domain_device *dev, int phy_id)
|
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
struct ex_phy *phy = &ex->ex_phy[phy_id];
|
|
|
|
|
2006-09-07 08:28:07 +08:00
|
|
|
sas_smp_phy_control(dev, phy_id, PHY_FUNC_DISABLE, NULL);
|
2006-09-07 06:36:13 +08:00
|
|
|
phy->linkrate = SAS_PHY_DISABLED;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sas_ex_disable_port(struct domain_device *dev, u8 *sas_addr)
|
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ex->num_phys; i++) {
|
|
|
|
struct ex_phy *phy = &ex->ex_phy[i];
|
|
|
|
|
|
|
|
if (phy->phy_state == PHY_VACANT ||
|
|
|
|
phy->phy_state == PHY_NOT_PRESENT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (SAS_ADDR(phy->attached_sas_addr) == SAS_ADDR(sas_addr))
|
|
|
|
sas_ex_disable_phy(dev, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_dev_present_in_domain(struct asd_sas_port *port,
|
|
|
|
u8 *sas_addr)
|
|
|
|
{
|
|
|
|
struct domain_device *dev;
|
|
|
|
|
|
|
|
if (SAS_ADDR(port->sas_addr) == SAS_ADDR(sas_addr))
|
|
|
|
return 1;
|
|
|
|
list_for_each_entry(dev, &port->dev_list, dev_list_node) {
|
|
|
|
if (SAS_ADDR(dev->sas_addr) == SAS_ADDR(sas_addr))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RPEL_REQ_SIZE 16
|
|
|
|
#define RPEL_RESP_SIZE 32
|
|
|
|
int sas_smp_get_phy_events(struct sas_phy *phy)
|
|
|
|
{
|
|
|
|
int res;
|
2007-07-28 07:13:33 +08:00
|
|
|
u8 *req;
|
|
|
|
u8 *resp;
|
2006-08-29 22:22:51 +08:00
|
|
|
struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
|
|
|
|
struct domain_device *dev = sas_find_dev_by_rphy(rphy);
|
|
|
|
|
2007-07-28 07:13:33 +08:00
|
|
|
req = alloc_smp_req(RPEL_REQ_SIZE);
|
|
|
|
if (!req)
|
2006-08-29 22:22:51 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2007-07-28 07:13:33 +08:00
|
|
|
resp = alloc_smp_resp(RPEL_RESP_SIZE);
|
|
|
|
if (!resp) {
|
|
|
|
kfree(req);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-08-29 22:22:51 +08:00
|
|
|
req[1] = SMP_REPORT_PHY_ERR_LOG;
|
|
|
|
req[9] = phy->number;
|
|
|
|
|
|
|
|
res = smp_execute_task(dev, req, RPEL_REQ_SIZE,
|
|
|
|
resp, RPEL_RESP_SIZE);
|
|
|
|
|
2018-01-04 21:04:32 +08:00
|
|
|
if (res)
|
2006-08-29 22:22:51 +08:00
|
|
|
goto out;
|
|
|
|
|
2019-01-24 03:08:05 +08:00
|
|
|
phy->invalid_dword_count = get_unaligned_be32(&resp[12]);
|
|
|
|
phy->running_disparity_error_count = get_unaligned_be32(&resp[16]);
|
|
|
|
phy->loss_of_dword_sync_count = get_unaligned_be32(&resp[20]);
|
|
|
|
phy->phy_reset_problem_count = get_unaligned_be32(&resp[24]);
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
out:
|
2018-01-04 21:04:31 +08:00
|
|
|
kfree(req);
|
2006-08-29 22:22:51 +08:00
|
|
|
kfree(resp);
|
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-07-23 02:15:55 +08:00
|
|
|
#ifdef CONFIG_SCSI_SAS_ATA
|
|
|
|
|
2006-08-29 22:22:51 +08:00
|
|
|
#define RPS_REQ_SIZE 16
|
|
|
|
#define RPS_RESP_SIZE 60
|
|
|
|
|
2012-01-13 09:57:35 +08:00
|
|
|
int sas_get_report_phy_sata(struct domain_device *dev, int phy_id,
|
|
|
|
struct smp_resp *rps_resp)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
u8 *rps_req = alloc_smp_req(RPS_REQ_SIZE);
|
2006-08-23 01:39:19 +08:00
|
|
|
u8 *resp = (u8 *)rps_resp;
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
if (!rps_req)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rps_req[1] = SMP_REPORT_PHY_SATA;
|
|
|
|
rps_req[9] = phy_id;
|
|
|
|
|
|
|
|
res = smp_execute_task(dev, rps_req, RPS_REQ_SIZE,
|
|
|
|
rps_resp, RPS_RESP_SIZE);
|
|
|
|
|
2006-08-23 01:39:19 +08:00
|
|
|
/* 0x34 is the FIS type for the D2H fis. There's a potential
|
|
|
|
* standards cockup here. sas-2 explicitly specifies the FIS
|
|
|
|
* should be encoded so that FIS type is in resp[24].
|
|
|
|
* However, some expanders endian reverse this. Undo the
|
|
|
|
* reversal here */
|
|
|
|
if (!res && resp[27] == 0x34 && resp[24] != 0x34) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
int j = 24 + (i*4);
|
|
|
|
u8 a, b;
|
|
|
|
a = resp[j + 0];
|
|
|
|
b = resp[j + 1];
|
|
|
|
resp[j + 0] = resp[j + 3];
|
|
|
|
resp[j + 1] = resp[j + 2];
|
|
|
|
resp[j + 2] = b;
|
|
|
|
resp[j + 3] = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-29 22:22:51 +08:00
|
|
|
kfree(rps_req);
|
2006-08-23 01:39:19 +08:00
|
|
|
return res;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
2007-07-23 02:15:55 +08:00
|
|
|
#endif
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
static void sas_ex_get_linkrate(struct domain_device *parent,
|
|
|
|
struct domain_device *child,
|
|
|
|
struct ex_phy *parent_phy)
|
|
|
|
{
|
|
|
|
struct expander_device *parent_ex = &parent->ex_dev;
|
|
|
|
struct sas_port *port;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
child->pathways = 0;
|
|
|
|
|
|
|
|
port = parent_phy->port;
|
|
|
|
|
|
|
|
for (i = 0; i < parent_ex->num_phys; i++) {
|
|
|
|
struct ex_phy *phy = &parent_ex->ex_phy[i];
|
|
|
|
|
|
|
|
if (phy->phy_state == PHY_VACANT ||
|
|
|
|
phy->phy_state == PHY_NOT_PRESENT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (SAS_ADDR(phy->attached_sas_addr) ==
|
|
|
|
SAS_ADDR(child->sas_addr)) {
|
|
|
|
|
|
|
|
child->min_linkrate = min(parent->min_linkrate,
|
|
|
|
phy->linkrate);
|
|
|
|
child->max_linkrate = max(parent->max_linkrate,
|
|
|
|
phy->linkrate);
|
|
|
|
child->pathways++;
|
|
|
|
sas_port_add_phy(port, phy->phy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
child->linkrate = min(parent_phy->linkrate, child->max_linkrate);
|
|
|
|
child->pathways = min(child->pathways, parent->pathways);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct domain_device *sas_ex_discover_end_dev(
|
|
|
|
struct domain_device *parent, int phy_id)
|
|
|
|
{
|
|
|
|
struct expander_device *parent_ex = &parent->ex_dev;
|
|
|
|
struct ex_phy *phy = &parent_ex->ex_phy[phy_id];
|
|
|
|
struct domain_device *child = NULL;
|
|
|
|
struct sas_rphy *rphy;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (phy->attached_sata_host || phy->attached_sata_ps)
|
|
|
|
return NULL;
|
|
|
|
|
2011-11-18 09:59:47 +08:00
|
|
|
child = sas_alloc_device();
|
2006-08-29 22:22:51 +08:00
|
|
|
if (!child)
|
|
|
|
return NULL;
|
|
|
|
|
2011-11-18 09:59:47 +08:00
|
|
|
kref_get(&parent->kref);
|
2006-08-29 22:22:51 +08:00
|
|
|
child->parent = parent;
|
|
|
|
child->port = parent->port;
|
|
|
|
child->iproto = phy->attached_iproto;
|
|
|
|
memcpy(child->sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
|
|
|
|
sas_hash_addr(child->hashed_sas_addr, child->sas_addr);
|
2006-11-16 08:03:07 +08:00
|
|
|
if (!phy->port) {
|
|
|
|
phy->port = sas_port_alloc(&parent->rphy->dev, phy_id);
|
|
|
|
if (unlikely(!phy->port))
|
|
|
|
goto out_err;
|
|
|
|
if (unlikely(sas_port_add(phy->port) != 0)) {
|
|
|
|
sas_port_free(phy->port);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
sas_ex_get_linkrate(parent, child, phy);
|
2011-12-22 13:33:17 +08:00
|
|
|
sas_device_set_phy(child, phy->port);
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2007-07-23 02:15:55 +08:00
|
|
|
#ifdef CONFIG_SCSI_SAS_ATA
|
2007-11-06 03:51:17 +08:00
|
|
|
if ((phy->attached_tproto & SAS_PROTOCOL_STP) || phy->attached_sata_dev) {
|
scsi: libsas: Support SATA PHY connection rate unmatch fixing during discovery
+----------+ +----------+
| | | |
| |--- 3.0 G ---| |--- 6.0 G --- SAS disk
| | | |
| |--- 3.0 G ---| |--- 6.0 G --- SAS disk
|initiator | | |
| device |--- 3.0 G ---| Expander |--- 6.0 G --- SAS disk
| | | |
| |--- 3.0 G ---| |--- 6.0 G --- SATA disk -->failed to connect
| | | |
| | | |--- 6.0 G --- SATA disk -->failed to connect
| | | |
+----------+ +----------+
According to Serial Attached SCSI - 1.1 (SAS-1.1):
If an expander PHY attached to a SATA PHY is using a physical link rate
greater than the maximum connection rate supported by the pathway from an
STP initiator port, a management application client should use the SMP PHY
CONTROL function (see 10.4.3.10) to set the PROGRAMMED MAXIMUM PHYSICAL
LINK RATE field of the expander PHY to the maximum connection rate
supported by the pathway from that STP initiator port.
Currently libsas does not support checking if this condition occurs, nor
rectifying when it does.
Such a condition is not at all common, however it has been seen on some
pre-silicon environments where the initiator PHY only supports a 1.5 Gbit
maximum linkrate, mated with 12G expander PHYs and 3/6G SATA phy.
This patch adds support for checking and rectifying this condition during
initial device discovery only.
We do support checking min pathway connection rate during revalidation phase,
when new devices can be detected in the topology. However we do not
support in the case of the the user reprogramming PHY linkrates, such that
min pathway condition is not met/maintained.
A note on root port PHY rates:
The libsas root port PHY rates calculation is broken. Libsas sets the
rates (min, max, and current linkrate) of a root port to the same linkrate
of the first PHY member of that same port. In doing so, it assumes that
all other PHYs which subsequently join the port to have the same
negotiated linkrate, when they could actually be different.
In practice this doesn't happen, as initiator and expander PHYs are
normally initialised with consistent min/max linkrates.
This has not caused an issue so far, so leave alone for now.
Tested-by: Jian Luo <luojian5@huawei.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2019-01-05 00:01:28 +08:00
|
|
|
if (child->linkrate > parent->min_linkrate) {
|
2019-04-12 16:57:53 +08:00
|
|
|
struct sas_phy *cphy = child->phy;
|
|
|
|
enum sas_linkrate min_prate = cphy->minimum_linkrate,
|
|
|
|
parent_min_lrate = parent->min_linkrate,
|
|
|
|
min_linkrate = (min_prate > parent_min_lrate) ?
|
|
|
|
parent_min_lrate : 0;
|
scsi: libsas: Support SATA PHY connection rate unmatch fixing during discovery
+----------+ +----------+
| | | |
| |--- 3.0 G ---| |--- 6.0 G --- SAS disk
| | | |
| |--- 3.0 G ---| |--- 6.0 G --- SAS disk
|initiator | | |
| device |--- 3.0 G ---| Expander |--- 6.0 G --- SAS disk
| | | |
| |--- 3.0 G ---| |--- 6.0 G --- SATA disk -->failed to connect
| | | |
| | | |--- 6.0 G --- SATA disk -->failed to connect
| | | |
+----------+ +----------+
According to Serial Attached SCSI - 1.1 (SAS-1.1):
If an expander PHY attached to a SATA PHY is using a physical link rate
greater than the maximum connection rate supported by the pathway from an
STP initiator port, a management application client should use the SMP PHY
CONTROL function (see 10.4.3.10) to set the PROGRAMMED MAXIMUM PHYSICAL
LINK RATE field of the expander PHY to the maximum connection rate
supported by the pathway from that STP initiator port.
Currently libsas does not support checking if this condition occurs, nor
rectifying when it does.
Such a condition is not at all common, however it has been seen on some
pre-silicon environments where the initiator PHY only supports a 1.5 Gbit
maximum linkrate, mated with 12G expander PHYs and 3/6G SATA phy.
This patch adds support for checking and rectifying this condition during
initial device discovery only.
We do support checking min pathway connection rate during revalidation phase,
when new devices can be detected in the topology. However we do not
support in the case of the the user reprogramming PHY linkrates, such that
min pathway condition is not met/maintained.
A note on root port PHY rates:
The libsas root port PHY rates calculation is broken. Libsas sets the
rates (min, max, and current linkrate) of a root port to the same linkrate
of the first PHY member of that same port. In doing so, it assumes that
all other PHYs which subsequently join the port to have the same
negotiated linkrate, when they could actually be different.
In practice this doesn't happen, as initiator and expander PHYs are
normally initialised with consistent min/max linkrates.
This has not caused an issue so far, so leave alone for now.
Tested-by: Jian Luo <luojian5@huawei.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2019-01-05 00:01:28 +08:00
|
|
|
struct sas_phy_linkrates rates = {
|
|
|
|
.maximum_linkrate = parent->min_linkrate,
|
2019-04-12 16:57:53 +08:00
|
|
|
.minimum_linkrate = min_linkrate,
|
scsi: libsas: Support SATA PHY connection rate unmatch fixing during discovery
+----------+ +----------+
| | | |
| |--- 3.0 G ---| |--- 6.0 G --- SAS disk
| | | |
| |--- 3.0 G ---| |--- 6.0 G --- SAS disk
|initiator | | |
| device |--- 3.0 G ---| Expander |--- 6.0 G --- SAS disk
| | | |
| |--- 3.0 G ---| |--- 6.0 G --- SATA disk -->failed to connect
| | | |
| | | |--- 6.0 G --- SATA disk -->failed to connect
| | | |
+----------+ +----------+
According to Serial Attached SCSI - 1.1 (SAS-1.1):
If an expander PHY attached to a SATA PHY is using a physical link rate
greater than the maximum connection rate supported by the pathway from an
STP initiator port, a management application client should use the SMP PHY
CONTROL function (see 10.4.3.10) to set the PROGRAMMED MAXIMUM PHYSICAL
LINK RATE field of the expander PHY to the maximum connection rate
supported by the pathway from that STP initiator port.
Currently libsas does not support checking if this condition occurs, nor
rectifying when it does.
Such a condition is not at all common, however it has been seen on some
pre-silicon environments where the initiator PHY only supports a 1.5 Gbit
maximum linkrate, mated with 12G expander PHYs and 3/6G SATA phy.
This patch adds support for checking and rectifying this condition during
initial device discovery only.
We do support checking min pathway connection rate during revalidation phase,
when new devices can be detected in the topology. However we do not
support in the case of the the user reprogramming PHY linkrates, such that
min pathway condition is not met/maintained.
A note on root port PHY rates:
The libsas root port PHY rates calculation is broken. Libsas sets the
rates (min, max, and current linkrate) of a root port to the same linkrate
of the first PHY member of that same port. In doing so, it assumes that
all other PHYs which subsequently join the port to have the same
negotiated linkrate, when they could actually be different.
In practice this doesn't happen, as initiator and expander PHYs are
normally initialised with consistent min/max linkrates.
This has not caused an issue so far, so leave alone for now.
Tested-by: Jian Luo <luojian5@huawei.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2019-01-05 00:01:28 +08:00
|
|
|
};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pr_notice("ex %016llx phy%02d SATA device linkrate > min pathway connection rate, attempting to lower device linkrate\n",
|
|
|
|
SAS_ADDR(child->sas_addr), phy_id);
|
|
|
|
ret = sas_smp_phy_control(parent, phy_id,
|
|
|
|
PHY_FUNC_LINK_RESET, &rates);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("ex %016llx phy%02d SATA device could not set linkrate (%d)\n",
|
|
|
|
SAS_ADDR(child->sas_addr), phy_id, ret);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
pr_notice("ex %016llx phy%02d SATA device set linkrate successfully\n",
|
|
|
|
SAS_ADDR(child->sas_addr), phy_id);
|
|
|
|
child->linkrate = child->min_linkrate;
|
|
|
|
}
|
2012-01-13 09:57:35 +08:00
|
|
|
res = sas_get_ata_info(child, phy);
|
|
|
|
if (res)
|
2006-11-16 08:03:07 +08:00
|
|
|
goto out_free;
|
2006-08-23 01:39:19 +08:00
|
|
|
|
2012-03-22 12:09:07 +08:00
|
|
|
sas_init_dev(child);
|
|
|
|
res = sas_ata_init(child);
|
|
|
|
if (res)
|
|
|
|
goto out_free;
|
2006-08-23 01:39:19 +08:00
|
|
|
rphy = sas_end_device_alloc(phy->port);
|
2012-03-22 12:09:07 +08:00
|
|
|
if (!rphy)
|
2006-10-16 23:57:05 +08:00
|
|
|
goto out_free;
|
2019-02-15 00:37:57 +08:00
|
|
|
rphy->identify.phy_identifier = phy_id;
|
2006-08-23 01:39:19 +08:00
|
|
|
|
|
|
|
child->rphy = rphy;
|
2012-03-21 01:53:24 +08:00
|
|
|
get_device(&rphy->dev);
|
2006-08-23 01:39:19 +08:00
|
|
|
|
2011-11-18 09:59:51 +08:00
|
|
|
list_add_tail(&child->disco_list_node, &parent->port->disco_list);
|
2006-08-23 01:39:19 +08:00
|
|
|
|
2006-08-29 22:22:51 +08:00
|
|
|
res = sas_discover_sata(child);
|
|
|
|
if (res) {
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_notice("sas_discover_sata() for device %16llx at %016llx:%02d returned 0x%x\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(child->sas_addr),
|
|
|
|
SAS_ADDR(parent->sas_addr), phy_id, res);
|
2006-08-23 01:39:19 +08:00
|
|
|
goto out_list_del;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
2007-07-23 02:15:55 +08:00
|
|
|
} else
|
|
|
|
#endif
|
2007-11-06 03:51:17 +08:00
|
|
|
if (phy->attached_tproto & SAS_PROTOCOL_SSP) {
|
2013-05-08 05:44:06 +08:00
|
|
|
child->dev_type = SAS_END_DEVICE;
|
2006-08-29 22:22:51 +08:00
|
|
|
rphy = sas_end_device_alloc(phy->port);
|
|
|
|
/* FIXME: error handling */
|
2006-11-16 08:03:07 +08:00
|
|
|
if (unlikely(!rphy))
|
|
|
|
goto out_free;
|
2006-08-29 22:22:51 +08:00
|
|
|
child->tproto = phy->attached_tproto;
|
|
|
|
sas_init_dev(child);
|
|
|
|
|
|
|
|
child->rphy = rphy;
|
2012-03-21 01:53:24 +08:00
|
|
|
get_device(&rphy->dev);
|
2019-02-15 00:37:57 +08:00
|
|
|
rphy->identify.phy_identifier = phy_id;
|
2006-08-29 22:22:51 +08:00
|
|
|
sas_fill_in_rphy(child, rphy);
|
|
|
|
|
2012-01-19 12:14:01 +08:00
|
|
|
list_add_tail(&child->disco_list_node, &parent->port->disco_list);
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
res = sas_discover_end_dev(child);
|
|
|
|
if (res) {
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_notice("sas_discover_end_dev() for device %16llx at %016llx:%02d returned 0x%x\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(child->sas_addr),
|
|
|
|
SAS_ADDR(parent->sas_addr), phy_id, res);
|
2006-11-16 08:03:07 +08:00
|
|
|
goto out_list_del;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
} else {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_notice("target proto 0x%x at %016llx:0x%x not handled\n",
|
|
|
|
phy->attached_tproto, SAS_ADDR(parent->sas_addr),
|
|
|
|
phy_id);
|
2007-07-23 02:15:55 +08:00
|
|
|
goto out_free;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&child->siblings, &parent_ex->children);
|
|
|
|
return child;
|
2006-11-16 08:03:07 +08:00
|
|
|
|
|
|
|
out_list_del:
|
2007-01-27 06:08:43 +08:00
|
|
|
sas_rphy_free(child->rphy);
|
2011-11-18 09:59:51 +08:00
|
|
|
list_del(&child->disco_list_node);
|
2011-09-22 13:05:34 +08:00
|
|
|
spin_lock_irq(&parent->port->dev_list_lock);
|
2006-11-16 08:03:07 +08:00
|
|
|
list_del(&child->dev_list_node);
|
2011-09-22 13:05:34 +08:00
|
|
|
spin_unlock_irq(&parent->port->dev_list_lock);
|
2006-11-16 08:03:07 +08:00
|
|
|
out_free:
|
|
|
|
sas_port_delete(phy->port);
|
|
|
|
out_err:
|
|
|
|
phy->port = NULL;
|
2011-11-18 09:59:47 +08:00
|
|
|
sas_put_device(child);
|
2006-11-16 08:03:07 +08:00
|
|
|
return NULL;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
2007-01-31 04:07:27 +08:00
|
|
|
/* See if this phy is part of a wide port */
|
2012-06-22 14:36:20 +08:00
|
|
|
static bool sas_ex_join_wide_port(struct domain_device *parent, int phy_id)
|
2007-01-31 04:07:27 +08:00
|
|
|
{
|
|
|
|
struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < parent->ex_dev.num_phys; i++) {
|
|
|
|
struct ex_phy *ephy = &parent->ex_dev.ex_phy[i];
|
|
|
|
|
|
|
|
if (ephy == phy)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!memcmp(phy->attached_sas_addr, ephy->attached_sas_addr,
|
|
|
|
SAS_ADDR_SIZE) && ephy->port) {
|
|
|
|
sas_port_add_phy(ephy->port, phy->phy);
|
2009-07-17 16:02:04 +08:00
|
|
|
phy->port = ephy->port;
|
2007-01-31 04:07:27 +08:00
|
|
|
phy->phy_state = PHY_DEVICE_DISCOVERED;
|
2012-06-22 14:36:20 +08:00
|
|
|
return true;
|
2007-01-31 04:07:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-22 14:36:20 +08:00
|
|
|
return false;
|
2007-01-31 04:07:27 +08:00
|
|
|
}
|
|
|
|
|
2006-08-29 22:22:51 +08:00
|
|
|
static struct domain_device *sas_ex_discover_expander(
|
|
|
|
struct domain_device *parent, int phy_id)
|
|
|
|
{
|
|
|
|
struct sas_expander_device *parent_ex = rphy_to_expander_device(parent->rphy);
|
|
|
|
struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id];
|
|
|
|
struct domain_device *child = NULL;
|
|
|
|
struct sas_rphy *rphy;
|
|
|
|
struct sas_expander_device *edev;
|
|
|
|
struct asd_sas_port *port;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (phy->routing_attr == DIRECT_ROUTING) {
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_warn("ex %016llx:%02d:D <--> ex %016llx:0x%x is not allowed\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(parent->sas_addr), phy_id,
|
|
|
|
SAS_ADDR(phy->attached_sas_addr),
|
|
|
|
phy->attached_phy_id);
|
2006-08-29 22:22:51 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-11-18 09:59:47 +08:00
|
|
|
child = sas_alloc_device();
|
2006-08-29 22:22:51 +08:00
|
|
|
if (!child)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
phy->port = sas_port_alloc(&parent->rphy->dev, phy_id);
|
|
|
|
/* FIXME: better error handling */
|
|
|
|
BUG_ON(sas_port_add(phy->port) != 0);
|
|
|
|
|
|
|
|
|
|
|
|
switch (phy->attached_dev_type) {
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_EDGE_EXPANDER_DEVICE:
|
2006-08-29 22:22:51 +08:00
|
|
|
rphy = sas_expander_alloc(phy->port,
|
|
|
|
SAS_EDGE_EXPANDER_DEVICE);
|
|
|
|
break;
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_FANOUT_EXPANDER_DEVICE:
|
2006-08-29 22:22:51 +08:00
|
|
|
rphy = sas_expander_alloc(phy->port,
|
|
|
|
SAS_FANOUT_EXPANDER_DEVICE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rphy = NULL; /* shut gcc up */
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
port = parent->port;
|
|
|
|
child->rphy = rphy;
|
2012-03-21 01:53:24 +08:00
|
|
|
get_device(&rphy->dev);
|
2006-08-29 22:22:51 +08:00
|
|
|
edev = rphy_to_expander_device(rphy);
|
|
|
|
child->dev_type = phy->attached_dev_type;
|
2011-11-18 09:59:47 +08:00
|
|
|
kref_get(&parent->kref);
|
2006-08-29 22:22:51 +08:00
|
|
|
child->parent = parent;
|
|
|
|
child->port = port;
|
|
|
|
child->iproto = phy->attached_iproto;
|
|
|
|
child->tproto = phy->attached_tproto;
|
|
|
|
memcpy(child->sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
|
|
|
|
sas_hash_addr(child->hashed_sas_addr, child->sas_addr);
|
|
|
|
sas_ex_get_linkrate(parent, child, phy);
|
|
|
|
edev->level = parent_ex->level + 1;
|
|
|
|
parent->port->disc.max_level = max(parent->port->disc.max_level,
|
|
|
|
edev->level);
|
|
|
|
sas_init_dev(child);
|
|
|
|
sas_fill_in_rphy(child, rphy);
|
|
|
|
sas_rphy_add(rphy);
|
|
|
|
|
2007-07-17 02:15:51 +08:00
|
|
|
spin_lock_irq(&parent->port->dev_list_lock);
|
2006-08-29 22:22:51 +08:00
|
|
|
list_add_tail(&child->dev_list_node, &parent->port->dev_list);
|
2007-07-17 02:15:51 +08:00
|
|
|
spin_unlock_irq(&parent->port->dev_list_lock);
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
res = sas_discover_expander(child);
|
|
|
|
if (res) {
|
2012-03-21 01:53:24 +08:00
|
|
|
sas_rphy_delete(rphy);
|
2011-07-27 14:10:48 +08:00
|
|
|
spin_lock_irq(&parent->port->dev_list_lock);
|
|
|
|
list_del(&child->dev_list_node);
|
|
|
|
spin_unlock_irq(&parent->port->dev_list_lock);
|
2011-11-18 09:59:47 +08:00
|
|
|
sas_put_device(child);
|
2019-05-14 10:42:39 +08:00
|
|
|
sas_port_delete(phy->port);
|
|
|
|
phy->port = NULL;
|
2006-08-29 22:22:51 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
list_add_tail(&child->siblings, &parent->ex_dev.children);
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_ex_discover_dev(struct domain_device *dev, int phy_id)
|
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
struct ex_phy *ex_phy = &ex->ex_phy[phy_id];
|
|
|
|
struct domain_device *child = NULL;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
/* Phy state */
|
2006-09-07 06:36:13 +08:00
|
|
|
if (ex_phy->linkrate == SAS_SATA_SPINUP_HOLD) {
|
2006-09-07 08:28:07 +08:00
|
|
|
if (!sas_smp_phy_control(dev, phy_id, PHY_FUNC_LINK_RESET, NULL))
|
2006-08-29 22:22:51 +08:00
|
|
|
res = sas_ex_phy_discover(dev, phy_id);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parent and domain coherency */
|
|
|
|
if (!dev->parent && (SAS_ADDR(ex_phy->attached_sas_addr) ==
|
|
|
|
SAS_ADDR(dev->port->sas_addr))) {
|
|
|
|
sas_add_parent_port(dev, phy_id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (dev->parent && (SAS_ADDR(ex_phy->attached_sas_addr) ==
|
|
|
|
SAS_ADDR(dev->parent->sas_addr))) {
|
|
|
|
sas_add_parent_port(dev, phy_id);
|
|
|
|
if (ex_phy->routing_attr == TABLE_ROUTING)
|
|
|
|
sas_configure_phy(dev, phy_id, dev->port->sas_addr, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sas_dev_present_in_domain(dev->port, ex_phy->attached_sas_addr))
|
|
|
|
sas_ex_disable_port(dev, ex_phy->attached_sas_addr);
|
|
|
|
|
2013-05-08 05:44:06 +08:00
|
|
|
if (ex_phy->attached_dev_type == SAS_PHY_UNUSED) {
|
2006-08-29 22:22:51 +08:00
|
|
|
if (ex_phy->routing_attr == DIRECT_ROUTING) {
|
|
|
|
memset(ex_phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
|
|
|
|
sas_configure_routing(dev, ex_phy->attached_sas_addr);
|
|
|
|
}
|
|
|
|
return 0;
|
2006-09-07 06:36:13 +08:00
|
|
|
} else if (ex_phy->linkrate == SAS_LINK_RATE_UNKNOWN)
|
2006-08-29 22:22:51 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-05-08 05:44:06 +08:00
|
|
|
if (ex_phy->attached_dev_type != SAS_END_DEVICE &&
|
|
|
|
ex_phy->attached_dev_type != SAS_FANOUT_EXPANDER_DEVICE &&
|
|
|
|
ex_phy->attached_dev_type != SAS_EDGE_EXPANDER_DEVICE &&
|
|
|
|
ex_phy->attached_dev_type != SAS_SATA_PENDING) {
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_warn("unknown device type(0x%x) attached to ex %016llx phy%02d\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
ex_phy->attached_dev_type,
|
|
|
|
SAS_ADDR(dev->sas_addr),
|
|
|
|
phy_id);
|
2006-08-29 22:22:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = sas_configure_routing(dev, ex_phy->attached_sas_addr);
|
|
|
|
if (res) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_notice("configure routing for dev %016llx reported 0x%x. Forgotten\n",
|
|
|
|
SAS_ADDR(ex_phy->attached_sas_addr), res);
|
2006-08-29 22:22:51 +08:00
|
|
|
sas_disable_routing(dev, ex_phy->attached_sas_addr);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-06-22 14:36:20 +08:00
|
|
|
if (sas_ex_join_wide_port(dev, phy_id)) {
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_debug("Attaching ex phy%02d to wide port %016llx\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
phy_id, SAS_ADDR(ex_phy->attached_sas_addr));
|
2007-01-31 04:07:27 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-08-29 22:22:51 +08:00
|
|
|
switch (ex_phy->attached_dev_type) {
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_END_DEVICE:
|
|
|
|
case SAS_SATA_PENDING:
|
2006-08-29 22:22:51 +08:00
|
|
|
child = sas_ex_discover_end_dev(dev, phy_id);
|
|
|
|
break;
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_FANOUT_EXPANDER_DEVICE:
|
2006-08-29 22:22:51 +08:00
|
|
|
if (SAS_ADDR(dev->port->disc.fanout_sas_addr)) {
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_debug("second fanout expander %016llx phy%02d attached to ex %016llx phy%02d\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(ex_phy->attached_sas_addr),
|
|
|
|
ex_phy->attached_phy_id,
|
|
|
|
SAS_ADDR(dev->sas_addr),
|
|
|
|
phy_id);
|
2006-08-29 22:22:51 +08:00
|
|
|
sas_ex_disable_phy(dev, phy_id);
|
2019-05-20 22:06:00 +08:00
|
|
|
return res;
|
2006-08-29 22:22:51 +08:00
|
|
|
} else
|
|
|
|
memcpy(dev->port->disc.fanout_sas_addr,
|
|
|
|
ex_phy->attached_sas_addr, SAS_ADDR_SIZE);
|
|
|
|
/* fallthrough */
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_EDGE_EXPANDER_DEVICE:
|
2006-08-29 22:22:51 +08:00
|
|
|
child = sas_ex_discover_expander(dev, phy_id);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:06:00 +08:00
|
|
|
if (!child)
|
|
|
|
pr_notice("ex %016llx phy%02d failed to discover\n",
|
|
|
|
SAS_ADDR(dev->sas_addr), phy_id);
|
2006-08-29 22:22:51 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_find_sub_addr(struct domain_device *dev, u8 *sub_addr)
|
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ex->num_phys; i++) {
|
|
|
|
struct ex_phy *phy = &ex->ex_phy[i];
|
|
|
|
|
|
|
|
if (phy->phy_state == PHY_VACANT ||
|
|
|
|
phy->phy_state == PHY_NOT_PRESENT)
|
|
|
|
continue;
|
|
|
|
|
2019-06-10 20:41:41 +08:00
|
|
|
if (dev_is_expander(phy->attached_dev_type) &&
|
2006-08-29 22:22:51 +08:00
|
|
|
phy->routing_attr == SUBTRACTIVE_ROUTING) {
|
|
|
|
|
2019-04-12 16:57:52 +08:00
|
|
|
memcpy(sub_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_check_level_subtractive_boundary(struct domain_device *dev)
|
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
struct domain_device *child;
|
2019-04-12 16:57:52 +08:00
|
|
|
u8 sub_addr[SAS_ADDR_SIZE] = {0, };
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
list_for_each_entry(child, &ex->children, siblings) {
|
2019-06-10 20:41:41 +08:00
|
|
|
if (!dev_is_expander(child->dev_type))
|
2006-08-29 22:22:51 +08:00
|
|
|
continue;
|
|
|
|
if (sub_addr[0] == 0) {
|
|
|
|
sas_find_sub_addr(child, sub_addr);
|
|
|
|
continue;
|
|
|
|
} else {
|
2019-04-12 16:57:52 +08:00
|
|
|
u8 s2[SAS_ADDR_SIZE];
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
if (sas_find_sub_addr(child, s2) &&
|
|
|
|
(SAS_ADDR(sub_addr) != SAS_ADDR(s2))) {
|
|
|
|
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_notice("ex %016llx->%016llx-?->%016llx diverges from subtractive boundary %016llx\n",
|
|
|
|
SAS_ADDR(dev->sas_addr),
|
|
|
|
SAS_ADDR(child->sas_addr),
|
|
|
|
SAS_ADDR(s2),
|
|
|
|
SAS_ADDR(sub_addr));
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
sas_ex_disable_port(child, s2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/**
|
2018-02-23 05:49:59 +08:00
|
|
|
* sas_ex_discover_devices - discover devices attached to this expander
|
|
|
|
* @dev: pointer to the expander domain device
|
|
|
|
* @single: if you want to do a single phy, else set to -1;
|
2006-08-29 22:22:51 +08:00
|
|
|
*
|
|
|
|
* Configure this expander for use with its devices and register the
|
|
|
|
* devices of this expander.
|
|
|
|
*/
|
|
|
|
static int sas_ex_discover_devices(struct domain_device *dev, int single)
|
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
int i = 0, end = ex->num_phys;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
if (0 <= single && single < end) {
|
|
|
|
i = single;
|
|
|
|
end = i+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( ; i < end; i++) {
|
|
|
|
struct ex_phy *ex_phy = &ex->ex_phy[i];
|
|
|
|
|
|
|
|
if (ex_phy->phy_state == PHY_VACANT ||
|
|
|
|
ex_phy->phy_state == PHY_NOT_PRESENT ||
|
|
|
|
ex_phy->phy_state == PHY_DEVICE_DISCOVERED)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (ex_phy->linkrate) {
|
2006-09-07 06:36:13 +08:00
|
|
|
case SAS_PHY_DISABLED:
|
|
|
|
case SAS_PHY_RESET_PROBLEM:
|
|
|
|
case SAS_SATA_PORT_SELECTOR:
|
2006-08-29 22:22:51 +08:00
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
res = sas_ex_discover_dev(dev, i);
|
|
|
|
if (res)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
sas_check_level_subtractive_boundary(dev);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_check_ex_subtractive_boundary(struct domain_device *dev)
|
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
int i;
|
|
|
|
u8 *sub_sas_addr = NULL;
|
|
|
|
|
2013-05-08 05:44:06 +08:00
|
|
|
if (dev->dev_type != SAS_EDGE_EXPANDER_DEVICE)
|
2006-08-29 22:22:51 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < ex->num_phys; i++) {
|
|
|
|
struct ex_phy *phy = &ex->ex_phy[i];
|
|
|
|
|
|
|
|
if (phy->phy_state == PHY_VACANT ||
|
|
|
|
phy->phy_state == PHY_NOT_PRESENT)
|
|
|
|
continue;
|
|
|
|
|
2019-06-10 20:41:41 +08:00
|
|
|
if (dev_is_expander(phy->attached_dev_type) &&
|
2006-08-29 22:22:51 +08:00
|
|
|
phy->routing_attr == SUBTRACTIVE_ROUTING) {
|
|
|
|
|
|
|
|
if (!sub_sas_addr)
|
|
|
|
sub_sas_addr = &phy->attached_sas_addr[0];
|
|
|
|
else if (SAS_ADDR(sub_sas_addr) !=
|
|
|
|
SAS_ADDR(phy->attached_sas_addr)) {
|
|
|
|
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_notice("ex %016llx phy%02d diverges(%016llx) on subtractive boundary(%016llx). Disabled\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(dev->sas_addr), i,
|
|
|
|
SAS_ADDR(phy->attached_sas_addr),
|
|
|
|
SAS_ADDR(sub_sas_addr));
|
2006-08-29 22:22:51 +08:00
|
|
|
sas_ex_disable_phy(dev, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sas_print_parent_topology_bug(struct domain_device *child,
|
|
|
|
struct ex_phy *parent_phy,
|
|
|
|
struct ex_phy *child_phy)
|
|
|
|
{
|
|
|
|
static const char *ex_type[] = {
|
2013-05-08 05:44:06 +08:00
|
|
|
[SAS_EDGE_EXPANDER_DEVICE] = "edge",
|
|
|
|
[SAS_FANOUT_EXPANDER_DEVICE] = "fanout",
|
2006-08-29 22:22:51 +08:00
|
|
|
};
|
|
|
|
struct domain_device *parent = child->parent;
|
|
|
|
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_notice("%s ex %016llx phy%02d <--> %s ex %016llx phy%02d has %c:%c routing link!\n",
|
2018-11-15 18:20:30 +08:00
|
|
|
ex_type[parent->dev_type],
|
|
|
|
SAS_ADDR(parent->sas_addr),
|
|
|
|
parent_phy->phy_id,
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2018-11-15 18:20:30 +08:00
|
|
|
ex_type[child->dev_type],
|
|
|
|
SAS_ADDR(child->sas_addr),
|
|
|
|
child_phy->phy_id,
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2018-11-15 18:20:30 +08:00
|
|
|
sas_route_char(parent, parent_phy),
|
|
|
|
sas_route_char(child, child_phy));
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_check_eeds(struct domain_device *child,
|
|
|
|
struct ex_phy *parent_phy,
|
|
|
|
struct ex_phy *child_phy)
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
struct domain_device *parent = child->parent;
|
|
|
|
|
|
|
|
if (SAS_ADDR(parent->port->disc.fanout_sas_addr) != 0) {
|
|
|
|
res = -ENODEV;
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_warn("edge ex %016llx phy S:%02d <--> edge ex %016llx phy S:%02d, while there is a fanout ex %016llx\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(parent->sas_addr),
|
|
|
|
parent_phy->phy_id,
|
|
|
|
SAS_ADDR(child->sas_addr),
|
|
|
|
child_phy->phy_id,
|
|
|
|
SAS_ADDR(parent->port->disc.fanout_sas_addr));
|
2006-08-29 22:22:51 +08:00
|
|
|
} else if (SAS_ADDR(parent->port->disc.eeds_a) == 0) {
|
|
|
|
memcpy(parent->port->disc.eeds_a, parent->sas_addr,
|
|
|
|
SAS_ADDR_SIZE);
|
|
|
|
memcpy(parent->port->disc.eeds_b, child->sas_addr,
|
|
|
|
SAS_ADDR_SIZE);
|
|
|
|
} else if (((SAS_ADDR(parent->port->disc.eeds_a) ==
|
|
|
|
SAS_ADDR(parent->sas_addr)) ||
|
|
|
|
(SAS_ADDR(parent->port->disc.eeds_a) ==
|
|
|
|
SAS_ADDR(child->sas_addr)))
|
|
|
|
&&
|
|
|
|
((SAS_ADDR(parent->port->disc.eeds_b) ==
|
|
|
|
SAS_ADDR(parent->sas_addr)) ||
|
|
|
|
(SAS_ADDR(parent->port->disc.eeds_b) ==
|
|
|
|
SAS_ADDR(child->sas_addr))))
|
|
|
|
;
|
|
|
|
else {
|
|
|
|
res = -ENODEV;
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_warn("edge ex %016llx phy%02d <--> edge ex %016llx phy%02d link forms a third EEDS!\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(parent->sas_addr),
|
|
|
|
parent_phy->phy_id,
|
|
|
|
SAS_ADDR(child->sas_addr),
|
|
|
|
child_phy->phy_id);
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Here we spill over 80 columns. It is intentional.
|
|
|
|
*/
|
|
|
|
static int sas_check_parent_topology(struct domain_device *child)
|
|
|
|
{
|
|
|
|
struct expander_device *child_ex = &child->ex_dev;
|
|
|
|
struct expander_device *parent_ex;
|
|
|
|
int i;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
if (!child->parent)
|
|
|
|
return 0;
|
|
|
|
|
2019-06-10 20:41:41 +08:00
|
|
|
if (!dev_is_expander(child->parent->dev_type))
|
2006-08-29 22:22:51 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
parent_ex = &child->parent->ex_dev;
|
|
|
|
|
|
|
|
for (i = 0; i < parent_ex->num_phys; i++) {
|
|
|
|
struct ex_phy *parent_phy = &parent_ex->ex_phy[i];
|
|
|
|
struct ex_phy *child_phy;
|
|
|
|
|
|
|
|
if (parent_phy->phy_state == PHY_VACANT ||
|
|
|
|
parent_phy->phy_state == PHY_NOT_PRESENT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (SAS_ADDR(parent_phy->attached_sas_addr) != SAS_ADDR(child->sas_addr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
child_phy = &child_ex->ex_phy[parent_phy->attached_phy_id];
|
|
|
|
|
|
|
|
switch (child->parent->dev_type) {
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_EDGE_EXPANDER_DEVICE:
|
|
|
|
if (child->dev_type == SAS_FANOUT_EXPANDER_DEVICE) {
|
2006-08-29 22:22:51 +08:00
|
|
|
if (parent_phy->routing_attr != SUBTRACTIVE_ROUTING ||
|
|
|
|
child_phy->routing_attr != TABLE_ROUTING) {
|
|
|
|
sas_print_parent_topology_bug(child, parent_phy, child_phy);
|
|
|
|
res = -ENODEV;
|
|
|
|
}
|
|
|
|
} else if (parent_phy->routing_attr == SUBTRACTIVE_ROUTING) {
|
|
|
|
if (child_phy->routing_attr == SUBTRACTIVE_ROUTING) {
|
|
|
|
res = sas_check_eeds(child, parent_phy, child_phy);
|
|
|
|
} else if (child_phy->routing_attr != TABLE_ROUTING) {
|
|
|
|
sas_print_parent_topology_bug(child, parent_phy, child_phy);
|
|
|
|
res = -ENODEV;
|
|
|
|
}
|
2011-09-23 00:41:36 +08:00
|
|
|
} else if (parent_phy->routing_attr == TABLE_ROUTING) {
|
|
|
|
if (child_phy->routing_attr == SUBTRACTIVE_ROUTING ||
|
|
|
|
(child_phy->routing_attr == TABLE_ROUTING &&
|
|
|
|
child_ex->t2t_supp && parent_ex->t2t_supp)) {
|
|
|
|
/* All good */;
|
|
|
|
} else {
|
|
|
|
sas_print_parent_topology_bug(child, parent_phy, child_phy);
|
|
|
|
res = -ENODEV;
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
break;
|
2013-05-08 05:44:06 +08:00
|
|
|
case SAS_FANOUT_EXPANDER_DEVICE:
|
2006-08-29 22:22:51 +08:00
|
|
|
if (parent_phy->routing_attr != TABLE_ROUTING ||
|
|
|
|
child_phy->routing_attr != SUBTRACTIVE_ROUTING) {
|
|
|
|
sas_print_parent_topology_bug(child, parent_phy, child_phy);
|
|
|
|
res = -ENODEV;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RRI_REQ_SIZE 16
|
|
|
|
#define RRI_RESP_SIZE 44
|
|
|
|
|
|
|
|
static int sas_configure_present(struct domain_device *dev, int phy_id,
|
|
|
|
u8 *sas_addr, int *index, int *present)
|
|
|
|
{
|
|
|
|
int i, res = 0;
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
struct ex_phy *phy = &ex->ex_phy[phy_id];
|
|
|
|
u8 *rri_req;
|
|
|
|
u8 *rri_resp;
|
|
|
|
|
|
|
|
*present = 0;
|
|
|
|
*index = 0;
|
|
|
|
|
|
|
|
rri_req = alloc_smp_req(RRI_REQ_SIZE);
|
|
|
|
if (!rri_req)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rri_resp = alloc_smp_resp(RRI_RESP_SIZE);
|
|
|
|
if (!rri_resp) {
|
|
|
|
kfree(rri_req);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
rri_req[1] = SMP_REPORT_ROUTE_INFO;
|
|
|
|
rri_req[9] = phy_id;
|
|
|
|
|
|
|
|
for (i = 0; i < ex->max_route_indexes ; i++) {
|
|
|
|
*(__be16 *)(rri_req+6) = cpu_to_be16(i);
|
|
|
|
res = smp_execute_task(dev, rri_req, RRI_REQ_SIZE, rri_resp,
|
|
|
|
RRI_RESP_SIZE);
|
|
|
|
if (res)
|
|
|
|
goto out;
|
|
|
|
res = rri_resp[2];
|
|
|
|
if (res == SMP_RESP_NO_INDEX) {
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_warn("overflow of indexes: dev %016llx phy%02d index 0x%x\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(dev->sas_addr), phy_id, i);
|
2006-08-29 22:22:51 +08:00
|
|
|
goto out;
|
|
|
|
} else if (res != SMP_RESP_FUNC_ACC) {
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_notice("%s: dev %016llx phy%02d index 0x%x result 0x%x\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
__func__, SAS_ADDR(dev->sas_addr), phy_id,
|
|
|
|
i, res);
|
2006-08-29 22:22:51 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (SAS_ADDR(sas_addr) != 0) {
|
|
|
|
if (SAS_ADDR(rri_resp+16) == SAS_ADDR(sas_addr)) {
|
|
|
|
*index = i;
|
|
|
|
if ((rri_resp[12] & 0x80) == 0x80)
|
|
|
|
*present = 0;
|
|
|
|
else
|
|
|
|
*present = 1;
|
|
|
|
goto out;
|
|
|
|
} else if (SAS_ADDR(rri_resp+16) == 0) {
|
|
|
|
*index = i;
|
|
|
|
*present = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else if (SAS_ADDR(rri_resp+16) == 0 &&
|
|
|
|
phy->last_da_index < i) {
|
|
|
|
phy->last_da_index = i;
|
|
|
|
*index = i;
|
|
|
|
*present = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = -1;
|
|
|
|
out:
|
|
|
|
kfree(rri_req);
|
|
|
|
kfree(rri_resp);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CRI_REQ_SIZE 44
|
|
|
|
#define CRI_RESP_SIZE 8
|
|
|
|
|
|
|
|
static int sas_configure_set(struct domain_device *dev, int phy_id,
|
|
|
|
u8 *sas_addr, int index, int include)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
u8 *cri_req;
|
|
|
|
u8 *cri_resp;
|
|
|
|
|
|
|
|
cri_req = alloc_smp_req(CRI_REQ_SIZE);
|
|
|
|
if (!cri_req)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
cri_resp = alloc_smp_resp(CRI_RESP_SIZE);
|
|
|
|
if (!cri_resp) {
|
|
|
|
kfree(cri_req);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
cri_req[1] = SMP_CONF_ROUTE_INFO;
|
|
|
|
*(__be16 *)(cri_req+6) = cpu_to_be16(index);
|
|
|
|
cri_req[9] = phy_id;
|
|
|
|
if (SAS_ADDR(sas_addr) == 0 || !include)
|
|
|
|
cri_req[12] |= 0x80;
|
|
|
|
memcpy(cri_req+16, sas_addr, SAS_ADDR_SIZE);
|
|
|
|
|
|
|
|
res = smp_execute_task(dev, cri_req, CRI_REQ_SIZE, cri_resp,
|
|
|
|
CRI_RESP_SIZE);
|
|
|
|
if (res)
|
|
|
|
goto out;
|
|
|
|
res = cri_resp[2];
|
|
|
|
if (res == SMP_RESP_NO_INDEX) {
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_warn("overflow of indexes: dev %016llx phy%02d index 0x%x\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(dev->sas_addr), phy_id, index);
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
kfree(cri_req);
|
|
|
|
kfree(cri_resp);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_configure_phy(struct domain_device *dev, int phy_id,
|
|
|
|
u8 *sas_addr, int include)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
int present;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = sas_configure_present(dev, phy_id, sas_addr, &index, &present);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
if (include ^ present)
|
|
|
|
return sas_configure_set(dev, phy_id, sas_addr, index,include);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-23 05:49:59 +08:00
|
|
|
* sas_configure_parent - configure routing table of parent
|
|
|
|
* @parent: parent expander
|
|
|
|
* @child: child expander
|
|
|
|
* @sas_addr: SAS port identifier of device directly attached to child
|
|
|
|
* @include: whether or not to include @child in the expander routing table
|
2006-08-29 22:22:51 +08:00
|
|
|
*/
|
|
|
|
static int sas_configure_parent(struct domain_device *parent,
|
|
|
|
struct domain_device *child,
|
|
|
|
u8 *sas_addr, int include)
|
|
|
|
{
|
|
|
|
struct expander_device *ex_parent = &parent->ex_dev;
|
|
|
|
int res = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (parent->parent) {
|
|
|
|
res = sas_configure_parent(parent->parent, parent, sas_addr,
|
|
|
|
include);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ex_parent->conf_route_table == 0) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_debug("ex %016llx has self-configuring routing table\n",
|
|
|
|
SAS_ADDR(parent->sas_addr));
|
2006-08-29 22:22:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ex_parent->num_phys; i++) {
|
|
|
|
struct ex_phy *phy = &ex_parent->ex_phy[i];
|
|
|
|
|
|
|
|
if ((phy->routing_attr == TABLE_ROUTING) &&
|
|
|
|
(SAS_ADDR(phy->attached_sas_addr) ==
|
|
|
|
SAS_ADDR(child->sas_addr))) {
|
|
|
|
res = sas_configure_phy(parent, i, sas_addr, include);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-23 05:49:59 +08:00
|
|
|
* sas_configure_routing - configure routing
|
|
|
|
* @dev: expander device
|
|
|
|
* @sas_addr: port identifier of device directly attached to the expander device
|
2006-08-29 22:22:51 +08:00
|
|
|
*/
|
|
|
|
static int sas_configure_routing(struct domain_device *dev, u8 *sas_addr)
|
|
|
|
{
|
|
|
|
if (dev->parent)
|
|
|
|
return sas_configure_parent(dev->parent, dev, sas_addr, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_disable_routing(struct domain_device *dev, u8 *sas_addr)
|
|
|
|
{
|
|
|
|
if (dev->parent)
|
|
|
|
return sas_configure_parent(dev->parent, dev, sas_addr, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-23 05:49:59 +08:00
|
|
|
* sas_discover_expander - expander discovery
|
|
|
|
* @dev: pointer to expander domain device
|
2006-08-29 22:22:51 +08:00
|
|
|
*
|
|
|
|
* See comment in sas_discover_sata().
|
|
|
|
*/
|
|
|
|
static int sas_discover_expander(struct domain_device *dev)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = sas_notify_lldd_dev_found(dev);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
res = sas_ex_general(dev);
|
|
|
|
if (res)
|
|
|
|
goto out_err;
|
|
|
|
res = sas_ex_manuf_info(dev);
|
|
|
|
if (res)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
res = sas_expander_discover(dev);
|
|
|
|
if (res) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_warn("expander %016llx discovery failed(0x%x)\n",
|
|
|
|
SAS_ADDR(dev->sas_addr), res);
|
2006-08-29 22:22:51 +08:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
sas_check_ex_subtractive_boundary(dev);
|
|
|
|
res = sas_check_parent_topology(dev);
|
|
|
|
if (res)
|
|
|
|
goto out_err;
|
|
|
|
return 0;
|
|
|
|
out_err:
|
|
|
|
sas_notify_lldd_dev_gone(dev);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_ex_level_discovery(struct asd_sas_port *port, const int level)
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
struct domain_device *dev;
|
|
|
|
|
|
|
|
list_for_each_entry(dev, &port->dev_list, dev_list_node) {
|
2019-06-10 20:41:41 +08:00
|
|
|
if (dev_is_expander(dev->dev_type)) {
|
2006-08-29 22:22:51 +08:00
|
|
|
struct sas_expander_device *ex =
|
|
|
|
rphy_to_expander_device(dev->rphy);
|
|
|
|
|
|
|
|
if (level == ex->level)
|
|
|
|
res = sas_ex_discover_devices(dev, -1);
|
|
|
|
else if (level > 0)
|
|
|
|
res = sas_ex_discover_devices(port->port_dev, -1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_ex_bfs_disc(struct asd_sas_port *port)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
int level;
|
|
|
|
|
|
|
|
do {
|
|
|
|
level = port->disc.max_level;
|
|
|
|
res = sas_ex_level_discovery(port, level);
|
|
|
|
mb();
|
|
|
|
} while (level < port->disc.max_level);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sas_discover_root_expander(struct domain_device *dev)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy);
|
|
|
|
|
2007-01-12 06:14:52 +08:00
|
|
|
res = sas_rphy_add(dev->rphy);
|
|
|
|
if (res)
|
|
|
|
goto out_err;
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
ex->level = dev->port->disc.max_level; /* 0 */
|
|
|
|
res = sas_discover_expander(dev);
|
2007-01-12 06:14:52 +08:00
|
|
|
if (res)
|
|
|
|
goto out_err2;
|
|
|
|
|
|
|
|
sas_ex_bfs_disc(dev->port);
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
return res;
|
2007-01-12 06:14:52 +08:00
|
|
|
|
|
|
|
out_err2:
|
2007-01-27 06:08:43 +08:00
|
|
|
sas_rphy_remove(dev->rphy);
|
2007-01-12 06:14:52 +08:00
|
|
|
out_err:
|
|
|
|
return res;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------- Domain revalidation ---------- */
|
|
|
|
|
|
|
|
static int sas_get_phy_discover(struct domain_device *dev,
|
|
|
|
int phy_id, struct smp_resp *disc_resp)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
u8 *disc_req;
|
|
|
|
|
|
|
|
disc_req = alloc_smp_req(DISCOVER_REQ_SIZE);
|
|
|
|
if (!disc_req)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
disc_req[1] = SMP_DISCOVER;
|
|
|
|
disc_req[9] = phy_id;
|
|
|
|
|
|
|
|
res = smp_execute_task(dev, disc_req, DISCOVER_REQ_SIZE,
|
|
|
|
disc_resp, DISCOVER_RESP_SIZE);
|
|
|
|
if (res)
|
|
|
|
goto out;
|
|
|
|
else if (disc_resp->result != SMP_RESP_FUNC_ACC) {
|
|
|
|
res = disc_resp->result;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
kfree(disc_req);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_get_phy_change_count(struct domain_device *dev,
|
|
|
|
int phy_id, int *pcc)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
struct smp_resp *disc_resp;
|
|
|
|
|
|
|
|
disc_resp = alloc_smp_resp(DISCOVER_RESP_SIZE);
|
|
|
|
if (!disc_resp)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
res = sas_get_phy_discover(dev, phy_id, disc_resp);
|
|
|
|
if (!res)
|
|
|
|
*pcc = disc_resp->disc.change_count;
|
|
|
|
|
|
|
|
kfree(disc_resp);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2024-06-12 13:13:20 +08:00
|
|
|
int sas_get_phy_attached_dev(struct domain_device *dev, int phy_id,
|
|
|
|
u8 *sas_addr, enum sas_device_type *type)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
struct smp_resp *disc_resp;
|
|
|
|
struct discover_resp *dr;
|
|
|
|
|
|
|
|
disc_resp = alloc_smp_resp(DISCOVER_RESP_SIZE);
|
|
|
|
if (!disc_resp)
|
|
|
|
return -ENOMEM;
|
|
|
|
dr = &disc_resp->disc;
|
|
|
|
|
|
|
|
res = sas_get_phy_discover(dev, phy_id, disc_resp);
|
2012-01-13 09:57:35 +08:00
|
|
|
if (res == 0) {
|
2019-04-12 16:57:52 +08:00
|
|
|
memcpy(sas_addr, disc_resp->disc.attached_sas_addr,
|
|
|
|
SAS_ADDR_SIZE);
|
2012-01-13 09:57:35 +08:00
|
|
|
*type = to_dev_type(dr);
|
|
|
|
if (*type == 0)
|
2019-04-12 16:57:52 +08:00
|
|
|
memset(sas_addr, 0, SAS_ADDR_SIZE);
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
kfree(disc_resp);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_find_bcast_phy(struct domain_device *dev, int *phy_id,
|
2009-07-17 16:02:04 +08:00
|
|
|
int from_phy, bool update)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
int res = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = from_phy; i < ex->num_phys; i++) {
|
|
|
|
int phy_change_count = 0;
|
|
|
|
|
|
|
|
res = sas_get_phy_change_count(dev, i, &phy_change_count);
|
2012-02-18 10:33:10 +08:00
|
|
|
switch (res) {
|
|
|
|
case SMP_RESP_PHY_VACANT:
|
|
|
|
case SMP_RESP_NO_PHY:
|
|
|
|
continue;
|
|
|
|
case SMP_RESP_FUNC_ACC:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phy_change_count != ex->ex_phy[i].phy_change_count) {
|
2009-07-17 16:02:04 +08:00
|
|
|
if (update)
|
|
|
|
ex->ex_phy[i].phy_change_count =
|
|
|
|
phy_change_count;
|
2006-08-29 22:22:51 +08:00
|
|
|
*phy_id = i;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-02-18 10:33:10 +08:00
|
|
|
return 0;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_get_ex_change_count(struct domain_device *dev, int *ecc)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
u8 *rg_req;
|
|
|
|
struct smp_resp *rg_resp;
|
|
|
|
|
|
|
|
rg_req = alloc_smp_req(RG_REQ_SIZE);
|
|
|
|
if (!rg_req)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rg_resp = alloc_smp_resp(RG_RESP_SIZE);
|
|
|
|
if (!rg_resp) {
|
|
|
|
kfree(rg_req);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
rg_req[1] = SMP_REPORT_GENERAL;
|
|
|
|
|
|
|
|
res = smp_execute_task(dev, rg_req, RG_REQ_SIZE, rg_resp,
|
|
|
|
RG_RESP_SIZE);
|
|
|
|
if (res)
|
|
|
|
goto out;
|
|
|
|
if (rg_resp->result != SMP_RESP_FUNC_ACC) {
|
|
|
|
res = rg_resp->result;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ecc = be16_to_cpu(rg_resp->rg.change_count);
|
|
|
|
out:
|
|
|
|
kfree(rg_resp);
|
|
|
|
kfree(rg_req);
|
|
|
|
return res;
|
|
|
|
}
|
2009-07-17 16:02:04 +08:00
|
|
|
/**
|
|
|
|
* sas_find_bcast_dev - find the device issue BROADCAST(CHANGE).
|
|
|
|
* @dev:domain device to be detect.
|
|
|
|
* @src_dev: the device which originated BROADCAST(CHANGE).
|
|
|
|
*
|
2012-08-22 18:11:26 +08:00
|
|
|
* Add self-configuration expander support. Suppose two expander cascading,
|
2009-07-17 16:02:04 +08:00
|
|
|
* when the first level expander is self-configuring, hotplug the disks in
|
|
|
|
* second level expander, BROADCAST(CHANGE) will not only be originated
|
|
|
|
* in the second level expander, but also be originated in the first level
|
|
|
|
* expander (see SAS protocol SAS 2r-14, 7.11 for detail), it is to say,
|
|
|
|
* expander changed count in two level expanders will all increment at least
|
|
|
|
* once, but the phy which chang count has changed is the source device which
|
|
|
|
* we concerned.
|
|
|
|
*/
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
static int sas_find_bcast_dev(struct domain_device *dev,
|
|
|
|
struct domain_device **src_dev)
|
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
int ex_change_count = -1;
|
2009-07-17 16:02:04 +08:00
|
|
|
int phy_id = -1;
|
2006-08-29 22:22:51 +08:00
|
|
|
int res;
|
2009-07-17 16:02:04 +08:00
|
|
|
struct domain_device *ch;
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
res = sas_get_ex_change_count(dev, &ex_change_count);
|
|
|
|
if (res)
|
|
|
|
goto out;
|
2009-07-17 16:02:04 +08:00
|
|
|
if (ex_change_count != -1 && ex_change_count != ex->ex_change_count) {
|
|
|
|
/* Just detect if this expander phys phy change count changed,
|
|
|
|
* in order to determine if this expander originate BROADCAST,
|
|
|
|
* and do not update phy change count field in our structure.
|
|
|
|
*/
|
|
|
|
res = sas_find_bcast_phy(dev, &phy_id, 0, false);
|
|
|
|
if (phy_id != -1) {
|
|
|
|
*src_dev = dev;
|
|
|
|
ex->ex_change_count = ex_change_count;
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_info("ex %016llx phy%02d change count has changed\n",
|
2019-04-12 16:57:54 +08:00
|
|
|
SAS_ADDR(dev->sas_addr), phy_id);
|
2009-07-17 16:02:04 +08:00
|
|
|
return res;
|
|
|
|
} else
|
2019-04-12 16:57:54 +08:00
|
|
|
pr_info("ex %016llx phys DID NOT change\n",
|
|
|
|
SAS_ADDR(dev->sas_addr));
|
2009-07-17 16:02:04 +08:00
|
|
|
}
|
|
|
|
list_for_each_entry(ch, &ex->children, siblings) {
|
2019-06-10 20:41:41 +08:00
|
|
|
if (dev_is_expander(ch->dev_type)) {
|
2009-07-17 16:02:04 +08:00
|
|
|
res = sas_find_bcast_dev(ch, src_dev);
|
2011-09-01 21:11:17 +08:00
|
|
|
if (*src_dev)
|
2009-07-17 16:02:04 +08:00
|
|
|
return res;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:05:34 +08:00
|
|
|
static void sas_unregister_ex_tree(struct asd_sas_port *port, struct domain_device *dev)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
struct domain_device *child, *n;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(child, n, &ex->children, siblings) {
|
2012-01-07 16:52:39 +08:00
|
|
|
set_bit(SAS_DEV_GONE, &child->state);
|
2019-06-10 20:41:41 +08:00
|
|
|
if (dev_is_expander(child->dev_type))
|
2011-09-22 13:05:34 +08:00
|
|
|
sas_unregister_ex_tree(port, child);
|
2006-08-29 22:22:51 +08:00
|
|
|
else
|
2011-09-22 13:05:34 +08:00
|
|
|
sas_unregister_dev(port, child);
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
2011-09-22 13:05:34 +08:00
|
|
|
sas_unregister_dev(port, dev);
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sas_unregister_devs_sas_addr(struct domain_device *parent,
|
2009-07-17 16:02:04 +08:00
|
|
|
int phy_id, bool last)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
|
|
|
struct expander_device *ex_dev = &parent->ex_dev;
|
|
|
|
struct ex_phy *phy = &ex_dev->ex_phy[phy_id];
|
2011-12-22 13:33:17 +08:00
|
|
|
struct domain_device *child, *n, *found = NULL;
|
2009-07-17 16:02:04 +08:00
|
|
|
if (last) {
|
|
|
|
list_for_each_entry_safe(child, n,
|
|
|
|
&ex_dev->children, siblings) {
|
|
|
|
if (SAS_ADDR(child->sas_addr) ==
|
|
|
|
SAS_ADDR(phy->attached_sas_addr)) {
|
2012-01-07 16:52:39 +08:00
|
|
|
set_bit(SAS_DEV_GONE, &child->state);
|
2019-06-10 20:41:41 +08:00
|
|
|
if (dev_is_expander(child->dev_type))
|
2011-09-22 13:05:34 +08:00
|
|
|
sas_unregister_ex_tree(parent->port, child);
|
2009-07-17 16:02:04 +08:00
|
|
|
else
|
2011-09-22 13:05:34 +08:00
|
|
|
sas_unregister_dev(parent->port, child);
|
2011-12-22 13:33:17 +08:00
|
|
|
found = child;
|
2009-07-17 16:02:04 +08:00
|
|
|
break;
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
2009-07-17 16:02:04 +08:00
|
|
|
sas_disable_routing(parent, phy->attached_sas_addr);
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
|
2011-09-22 23:32:23 +08:00
|
|
|
if (phy->port) {
|
|
|
|
sas_port_delete_phy(phy->port, phy->phy);
|
2011-12-22 13:33:17 +08:00
|
|
|
sas_device_set_phy(found, phy->port);
|
2011-09-22 23:32:23 +08:00
|
|
|
if (phy->port->num_phys == 0)
|
2017-12-08 17:42:09 +08:00
|
|
|
list_add_tail(&phy->port->del_list,
|
|
|
|
&parent->port->sas_port_del_list);
|
2011-09-22 23:32:23 +08:00
|
|
|
phy->port = NULL;
|
|
|
|
}
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_discover_bfs_by_root_level(struct domain_device *root,
|
|
|
|
const int level)
|
|
|
|
{
|
|
|
|
struct expander_device *ex_root = &root->ex_dev;
|
|
|
|
struct domain_device *child;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(child, &ex_root->children, siblings) {
|
2019-06-10 20:41:41 +08:00
|
|
|
if (dev_is_expander(child->dev_type)) {
|
2006-08-29 22:22:51 +08:00
|
|
|
struct sas_expander_device *ex =
|
|
|
|
rphy_to_expander_device(child->rphy);
|
|
|
|
|
|
|
|
if (level > ex->level)
|
|
|
|
res = sas_discover_bfs_by_root_level(child,
|
|
|
|
level);
|
|
|
|
else if (level == ex->level)
|
|
|
|
res = sas_ex_discover_devices(child, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_discover_bfs_by_root(struct domain_device *dev)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy);
|
|
|
|
int level = ex->level+1;
|
|
|
|
|
|
|
|
res = sas_ex_discover_devices(dev, -1);
|
|
|
|
if (res)
|
|
|
|
goto out;
|
|
|
|
do {
|
|
|
|
res = sas_discover_bfs_by_root_level(dev, level);
|
|
|
|
mb();
|
|
|
|
level += 1;
|
|
|
|
} while (level <= dev->port->disc.max_level);
|
|
|
|
out:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sas_discover_new(struct domain_device *dev, int phy_id)
|
|
|
|
{
|
|
|
|
struct ex_phy *ex_phy = &dev->ex_dev.ex_phy[phy_id];
|
|
|
|
struct domain_device *child;
|
2012-06-22 14:36:20 +08:00
|
|
|
int res;
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_debug("ex %016llx phy%02d new device attached\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(dev->sas_addr), phy_id);
|
2006-08-29 22:22:51 +08:00
|
|
|
res = sas_ex_phy_discover(dev, phy_id);
|
|
|
|
if (res)
|
2012-06-22 14:36:20 +08:00
|
|
|
return res;
|
|
|
|
|
|
|
|
if (sas_ex_join_wide_port(dev, phy_id))
|
2009-07-17 16:02:04 +08:00
|
|
|
return 0;
|
2012-06-22 14:36:20 +08:00
|
|
|
|
2006-08-29 22:22:51 +08:00
|
|
|
res = sas_ex_discover_devices(dev, phy_id);
|
2012-06-22 14:36:20 +08:00
|
|
|
if (res)
|
|
|
|
return res;
|
2006-08-29 22:22:51 +08:00
|
|
|
list_for_each_entry(child, &dev->ex_dev.children, siblings) {
|
|
|
|
if (SAS_ADDR(child->sas_addr) ==
|
|
|
|
SAS_ADDR(ex_phy->attached_sas_addr)) {
|
2019-06-10 20:41:41 +08:00
|
|
|
if (dev_is_expander(child->dev_type))
|
2006-08-29 22:22:51 +08:00
|
|
|
res = sas_discover_bfs_by_root(child);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-05-08 05:44:06 +08:00
|
|
|
static bool dev_type_flutter(enum sas_device_type new, enum sas_device_type old)
|
2012-01-13 09:57:35 +08:00
|
|
|
{
|
|
|
|
if (old == new)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* treat device directed resets as flutter, if we went
|
2013-05-08 05:44:06 +08:00
|
|
|
* SAS_END_DEVICE to SAS_SATA_PENDING the link needs recovery
|
2012-01-13 09:57:35 +08:00
|
|
|
*/
|
2013-05-08 05:44:06 +08:00
|
|
|
if ((old == SAS_SATA_PENDING && new == SAS_END_DEVICE) ||
|
|
|
|
(old == SAS_END_DEVICE && new == SAS_SATA_PENDING))
|
2012-01-13 09:57:35 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-12 16:57:54 +08:00
|
|
|
static int sas_rediscover_dev(struct domain_device *dev, int phy_id,
|
|
|
|
bool last, int sibling)
|
2006-08-29 22:22:51 +08:00
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
struct ex_phy *phy = &ex->ex_phy[phy_id];
|
2013-05-08 05:44:06 +08:00
|
|
|
enum sas_device_type type = SAS_PHY_UNUSED;
|
2019-04-12 16:57:52 +08:00
|
|
|
u8 sas_addr[SAS_ADDR_SIZE];
|
2019-04-12 16:57:54 +08:00
|
|
|
char msg[80] = "";
|
2006-08-29 22:22:51 +08:00
|
|
|
int res;
|
|
|
|
|
2019-04-12 16:57:54 +08:00
|
|
|
if (!last)
|
2019-04-12 16:57:57 +08:00
|
|
|
sprintf(msg, ", part of a wide port with phy%02d", sibling);
|
2019-04-12 16:57:54 +08:00
|
|
|
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_debug("ex %016llx rediscovering phy%02d%s\n",
|
|
|
|
SAS_ADDR(dev->sas_addr), phy_id, msg);
|
2019-04-12 16:57:54 +08:00
|
|
|
|
2019-04-12 16:57:52 +08:00
|
|
|
memset(sas_addr, 0, SAS_ADDR_SIZE);
|
2012-01-13 09:57:35 +08:00
|
|
|
res = sas_get_phy_attached_dev(dev, phy_id, sas_addr, &type);
|
2006-08-29 22:22:51 +08:00
|
|
|
switch (res) {
|
|
|
|
case SMP_RESP_NO_PHY:
|
|
|
|
phy->phy_state = PHY_NOT_PRESENT;
|
2009-07-17 16:02:04 +08:00
|
|
|
sas_unregister_devs_sas_addr(dev, phy_id, last);
|
2012-01-13 09:57:35 +08:00
|
|
|
return res;
|
2006-08-29 22:22:51 +08:00
|
|
|
case SMP_RESP_PHY_VACANT:
|
|
|
|
phy->phy_state = PHY_VACANT;
|
2009-07-17 16:02:04 +08:00
|
|
|
sas_unregister_devs_sas_addr(dev, phy_id, last);
|
2012-01-13 09:57:35 +08:00
|
|
|
return res;
|
2006-08-29 22:22:51 +08:00
|
|
|
case SMP_RESP_FUNC_ACC:
|
|
|
|
break;
|
2012-06-22 14:36:10 +08:00
|
|
|
case -ECOMM:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return res;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
2012-06-22 14:36:10 +08:00
|
|
|
if ((SAS_ADDR(sas_addr) == 0) || (res == -ECOMM)) {
|
2006-08-29 22:22:51 +08:00
|
|
|
phy->phy_state = PHY_EMPTY;
|
2009-07-17 16:02:04 +08:00
|
|
|
sas_unregister_devs_sas_addr(dev, phy_id, last);
|
2019-04-12 16:57:56 +08:00
|
|
|
/*
|
|
|
|
* Even though the PHY is empty, for convenience we discover
|
|
|
|
* the PHY to update the PHY info, like negotiated linkrate.
|
|
|
|
*/
|
|
|
|
sas_ex_phy_discover(dev, phy_id);
|
2012-01-13 09:57:35 +08:00
|
|
|
return res;
|
|
|
|
} else if (SAS_ADDR(sas_addr) == SAS_ADDR(phy->attached_sas_addr) &&
|
|
|
|
dev_type_flutter(type, phy->attached_dev_type)) {
|
|
|
|
struct domain_device *ata_dev = sas_ex_to_ata(dev, phy_id);
|
|
|
|
char *action = "";
|
|
|
|
|
2006-09-07 08:28:07 +08:00
|
|
|
sas_ex_phy_discover(dev, phy_id);
|
2012-01-13 09:57:35 +08:00
|
|
|
|
2013-05-08 05:44:06 +08:00
|
|
|
if (ata_dev && phy->attached_dev_type == SAS_SATA_PENDING)
|
2012-01-13 09:57:35 +08:00
|
|
|
action = ", needs recovery";
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_debug("ex %016llx phy%02d broadcast flutter%s\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(dev->sas_addr), phy_id, action);
|
2012-01-13 09:57:35 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-09-25 10:56:52 +08:00
|
|
|
/* we always have to delete the old device when we went here */
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_info("ex %016llx phy%02d replace %016llx\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(dev->sas_addr), phy_id,
|
|
|
|
SAS_ADDR(phy->attached_sas_addr));
|
2018-09-25 10:56:52 +08:00
|
|
|
sas_unregister_devs_sas_addr(dev, phy_id, last);
|
2012-01-20 10:43:08 +08:00
|
|
|
|
2012-01-13 09:57:35 +08:00
|
|
|
return sas_discover_new(dev, phy_id);
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
|
2009-07-17 16:02:04 +08:00
|
|
|
/**
|
|
|
|
* sas_rediscover - revalidate the domain.
|
|
|
|
* @dev:domain device to be detect.
|
|
|
|
* @phy_id: the phy id will be detected.
|
|
|
|
*
|
|
|
|
* 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.For plugging out, we un-register the device only when it is
|
|
|
|
* the last phy in the port, for other phys in this port, we just delete it
|
|
|
|
* from the port.For inserting, we do discovery when it is the
|
|
|
|
* first phy,for other phys in this port, we add it to the port to
|
|
|
|
* forming the wide-port.
|
|
|
|
*/
|
2006-08-29 22:22:51 +08:00
|
|
|
static int sas_rediscover(struct domain_device *dev, const int phy_id)
|
|
|
|
{
|
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
struct ex_phy *changed_phy = &ex->ex_phy[phy_id];
|
|
|
|
int res = 0;
|
|
|
|
int i;
|
2009-07-17 16:02:04 +08:00
|
|
|
bool last = true; /* is this the last phy of the port */
|
2006-08-29 22:22:51 +08:00
|
|
|
|
2019-04-12 16:57:57 +08:00
|
|
|
pr_debug("ex %016llx phy%02d originated BROADCAST(CHANGE)\n",
|
2018-11-15 18:20:31 +08:00
|
|
|
SAS_ADDR(dev->sas_addr), phy_id);
|
2006-08-29 22:22:51 +08:00
|
|
|
|
|
|
|
if (SAS_ADDR(changed_phy->attached_sas_addr) != 0) {
|
|
|
|
for (i = 0; i < ex->num_phys; i++) {
|
|
|
|
struct ex_phy *phy = &ex->ex_phy[i];
|
|
|
|
|
|
|
|
if (i == phy_id)
|
|
|
|
continue;
|
|
|
|
if (SAS_ADDR(phy->attached_sas_addr) ==
|
|
|
|
SAS_ADDR(changed_phy->attached_sas_addr)) {
|
2009-07-17 16:02:04 +08:00
|
|
|
last = false;
|
|
|
|
break;
|
2006-08-29 22:22:51 +08:00
|
|
|
}
|
|
|
|
}
|
2019-04-12 16:57:54 +08:00
|
|
|
res = sas_rediscover_dev(dev, phy_id, last, i);
|
2006-08-29 22:22:51 +08:00
|
|
|
} else
|
|
|
|
res = sas_discover_new(dev, phy_id);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-23 05:49:59 +08:00
|
|
|
* sas_ex_revalidate_domain - revalidate the domain
|
|
|
|
* @port_dev: port domain device.
|
2006-08-29 22:22:51 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
int sas_ex_revalidate_domain(struct domain_device *port_dev)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
struct domain_device *dev = NULL;
|
|
|
|
|
|
|
|
res = sas_find_bcast_dev(port_dev, &dev);
|
2017-12-08 17:42:09 +08:00
|
|
|
if (res == 0 && dev) {
|
2006-08-29 22:22:51 +08:00
|
|
|
struct expander_device *ex = &dev->ex_dev;
|
|
|
|
int i = 0, phy_id;
|
|
|
|
|
|
|
|
do {
|
|
|
|
phy_id = -1;
|
2009-07-17 16:02:04 +08:00
|
|
|
res = sas_find_bcast_phy(dev, &phy_id, i, true);
|
2006-08-29 22:22:51 +08:00
|
|
|
if (phy_id == -1)
|
|
|
|
break;
|
|
|
|
res = sas_rediscover(dev, phy_id);
|
|
|
|
i = phy_id + 1;
|
|
|
|
} while (i < ex->num_phys);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-08-25 23:37:41 +08:00
|
|
|
void sas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
|
|
|
|
struct sas_rphy *rphy)
|
2007-07-09 11:52:08 +08:00
|
|
|
{
|
|
|
|
struct domain_device *dev;
|
2017-12-11 15:03:33 +08:00
|
|
|
unsigned int rcvlen = 0;
|
2017-08-25 23:37:41 +08:00
|
|
|
int ret = -EINVAL;
|
2007-07-09 11:52:08 +08:00
|
|
|
|
2007-07-25 00:33:49 +08:00
|
|
|
/* no rphy means no smp target support (ie aic94xx host) */
|
2007-12-29 06:35:17 +08:00
|
|
|
if (!rphy)
|
2017-08-25 23:37:41 +08:00
|
|
|
return sas_smp_host_handler(job, shost);
|
2007-07-09 11:52:08 +08:00
|
|
|
|
2017-08-25 23:37:41 +08:00
|
|
|
switch (rphy->identify.device_type) {
|
|
|
|
case SAS_EDGE_EXPANDER_DEVICE:
|
|
|
|
case SAS_FANOUT_EXPANDER_DEVICE:
|
|
|
|
break;
|
|
|
|
default:
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_err("%s: can we send a smp request to a device?\n",
|
2008-07-04 14:47:27 +08:00
|
|
|
__func__);
|
2017-08-25 23:37:41 +08:00
|
|
|
goto out;
|
2007-07-09 11:52:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dev = sas_find_dev_by_rphy(rphy);
|
|
|
|
if (!dev) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_err("%s: fail to find a domain_device?\n", __func__);
|
2017-08-25 23:37:41 +08:00
|
|
|
goto out;
|
2007-07-09 11:52:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* do we need to support multiple segments? */
|
2017-08-25 23:37:41 +08:00
|
|
|
if (job->request_payload.sg_cnt > 1 ||
|
|
|
|
job->reply_payload.sg_cnt > 1) {
|
2018-11-15 18:20:31 +08:00
|
|
|
pr_info("%s: multiple segments req %u, rsp %u\n",
|
|
|
|
__func__, job->request_payload.payload_len,
|
|
|
|
job->reply_payload.payload_len);
|
2017-08-25 23:37:41 +08:00
|
|
|
goto out;
|
2007-07-09 11:52:08 +08:00
|
|
|
}
|
|
|
|
|
2017-08-25 23:37:41 +08:00
|
|
|
ret = smp_execute_task_sg(dev, job->request_payload.sg_list,
|
|
|
|
job->reply_payload.sg_list);
|
2017-12-11 15:03:33 +08:00
|
|
|
if (ret >= 0) {
|
|
|
|
/* bsg_job_done() requires the length received */
|
|
|
|
rcvlen = job->reply_payload.payload_len - ret;
|
2007-12-30 01:49:53 +08:00
|
|
|
ret = 0;
|
|
|
|
}
|
2007-07-09 11:52:08 +08:00
|
|
|
|
2017-08-25 23:37:41 +08:00
|
|
|
out:
|
2017-12-11 15:03:33 +08:00
|
|
|
bsg_job_done(job, ret, rcvlen);
|
2007-07-09 11:52:08 +08:00
|
|
|
}
|