From patchwork Tue Dec 20 18:15:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chang X-Patchwork-Id: 88624 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1863038qgi; Tue, 20 Dec 2016 10:15:47 -0800 (PST) X-Received: by 10.98.252.75 with SMTP id e72mr569068pfh.6.1482257747433; Tue, 20 Dec 2016 10:15:47 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x124si9047149pgb.117.2016.12.20.10.15.47; Tue, 20 Dec 2016 10:15:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-scsi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com; spf=pass (google.com: best guess record for domain of linux-scsi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754078AbcLTSPq (ORCPT + 1 other); Tue, 20 Dec 2016 13:15:46 -0500 Received: from mail-oi0-f53.google.com ([209.85.218.53]:33202 "EHLO mail-oi0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754784AbcLTSPp (ORCPT ); Tue, 20 Dec 2016 13:15:45 -0500 Received: by mail-oi0-f53.google.com with SMTP id w63so186301857oiw.0 for ; Tue, 20 Dec 2016 10:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=KuDO9bk8V7C4pSA957WWUdBe6aPnfJtXUwnlCbR/wig=; b=kIgh04yOuf5lVJShEQo6DIwyxpYglMKiYQAXxRbZ5dDI2ridK2dpFqqlREsjuCrHj5 no5XCbT9tv+G8i435qRb9RPXK1Zt8+aqmW9hRePh9amxagLwbjq1MdBeIYUPF+nSShhK BZPE5kqEWghgNh1HPRt+heklodr/j7QwFdCQDr1N2CMZH9E09f5bCb+v8xlEWBYLM7M9 dV3frYISIWjftEyQ4SEoeiiJDuDLy4n1ovIjL0QCmYqOZJlyRZYN7Od5yvOdKMEJZ3UN ie1Ot9hu/yDCcT0iLTszyVsTvJzdODsjNwGKaQycN/hf8TK50IT5aU5aPuFPjfT+NuO1 OCrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=KuDO9bk8V7C4pSA957WWUdBe6aPnfJtXUwnlCbR/wig=; b=ZG0BiGaKbqUzb+kmcTs3S8JHUobzwt4VzhuQsdH7gY1Ms6fJJhXudcGjSdQA8ubNXs 7Yfte38Zgt9RwYDq7EfChNA+fPP6Nrle7mQwUKIqfwBosPLVRVpcBQuAfq78Diy5vxRa 9blpqzNziIQRhfUeIcm6SDaMc285fmiuRQvaSf+wAo6DY8c1dnN+qoOSOLZ/r0EOJzpS m85ey30JOycgwgeCkR0wj7L9hA1ox8M7bHtj57NO3DFzX7fAhXHP0DgUsQAphtLjPwXf fNI1gAJzr/bCbZD9ejhc4Zjnfx8xdg+1HwoIlbeEvyRYnB8aaLPi1z92VTN0WeJdK8Rf OcHw== X-Gm-Message-State: AIkVDXJrrzF1wY8kxjZx7ZVtWqkgVc1r8YAko51nLBotkxnOHeFTFqxTR3GooSuUPE6AXpWC0zFuWxCeNZFB3oQh X-Received: by 10.157.12.10 with SMTP id 10mr387670otr.102.1482257744204; Tue, 20 Dec 2016 10:15:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.50.234 with HTTP; Tue, 20 Dec 2016 10:15:23 -0800 (PST) From: Peter Chang Date: Tue, 20 Dec 2016 10:15:23 -0800 Message-ID: Subject: [PATCH] set a base index for libsas based ata devices To: "linux-scsi@vger.kernel.org" , linux-ide@vger.kernel.org Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org we discovered this when futzing w/ the queue depth parameter for ata disks behind the pm8006 controller. setting depth == 1 should disable ncq, but the sysfs part silently fails and we continue sending the fpdma command variants. no one else probably cares about the disabling ncq path, but we do like to test. anyway, adding both the ide and scsi lists because i'm not quite sure there's a separate libsas list and a single commit seems better for this. \p >From 6bdfcb35a074d9c58c180f8c512706faf7d6c7cb Mon Sep 17 00:00:00 2001 From: peter chang Date: Tue, 20 Dec 2016 09:48:45 -0800 Subject: [PATCH] set a base index for libsas based ata devices libsas hosts allow multiple links, but when the controller supports SATA devices control is handed to libata. this means that an attached scsi device will be setup properly, but device management requests and sysfs futzing don't get routed correctly because the device lookup fails. Tested: - pre-patch: jkgg70:~# ls -d /sys/block/sd* /sys/block/sda jkgg70:~# modprobe pm80xx jkgg70:~# cat /sys/block/sdb/device/queue_depth 31 jkgg70:~# echo 1 > /sys/block/sdb/device/queue_depth jkgg70:~# cat /sys/block/sdb/device/queue_depth 31 - post-patch: jkgg70:~# modprobe pm80xx jkgg70:~# cat /sys/block/sdb/device/queue_depth 31 jkgg70:~# echo 1 > /sys/block/sdb/device/queue_depth jkgg70:~# cat /sys/block/sdb/device/queue_depth 1 Signed-off-by: peter chang --- drivers/ata/libata-scsi.c | 33 ++++++++++++++++++++++++++++++++- drivers/scsi/libsas/sas_scsi_host.c | 4 ++++ include/linux/libata.h | 3 +++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 1f863e7..340f144 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1088,7 +1088,7 @@ static void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, * passthrough command, so we use the following sense data: * sk = RECOVERED ERROR * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE - * + * * * LOCKING: * None. @@ -3052,6 +3052,16 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc) static struct ata_device *ata_find_dev(struct ata_port *ap, int devno) { + /* adjust if this port is behind a libsas host rather than a + * direct libata host. warn and fail if somehow we got out of + * sync and we've a negative device number. + */ + devno -= ap->link.sas_host_base; + if (unlikely(devno < 0)) { + WARN_ON(devno < 0); + return NULL; + } + if (!sata_pmp_attached(ap)) { if (likely(devno < ata_link_max_devices(&ap->link))) return &ap->link.device[devno]; @@ -4332,6 +4342,27 @@ int ata_scsi_queuecmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd) } /** + * ata_sas_set_link_base - set the libata link's 'base' because + * libsas hosts have more ports / links. + * @ap: ATA port to which the target is attached + * @starget: SCSI target being attached + */ +void ata_sas_set_link_base(struct ata_port *ap, struct scsi_target *starget) +{ + unsigned int host_base; + + if (!sata_pmp_attached(ap)) { + WARN_ON(starget->channel); + host_base = starget->id; + } else { + WARN_ON(starget->id); + host_base = starget->channel; + } + ap->link.sas_host_base = host_base; +} +EXPORT_SYMBOL_GPL(ata_sas_set_link_base); + +/** * ata_scsi_simulate - simulate SCSI command on ATA device * @dev: the target device * @cmd: SCSI command being sent to device. diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index 519dac4..d8300bc 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -859,6 +859,10 @@ int sas_target_alloc(struct scsi_target *starget) kref_get(&found_dev->kref); starget->hostdata = found_dev; + + if (dev_is_sata(found_dev)) + ata_sas_set_link_base(found_dev->sata_dev.ap, starget); + return 0; } diff --git a/include/linux/libata.h b/include/linux/libata.h index c170be5..323811f 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -791,6 +791,7 @@ struct ata_acpi_gtm { struct ata_link { struct ata_port *ap; int pmp; /* port multiplier port # */ + int sas_host_base; /* host relative id */ struct device tdev; unsigned int active_tag; /* active tag on this link */ @@ -1130,6 +1131,8 @@ extern int ata_sas_port_start(struct ata_port *ap); extern void ata_sas_port_stop(struct ata_port *ap); extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *); extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap); +extern void ata_sas_set_link_base(struct ata_port *ap, + struct scsi_target *starget); extern int sata_scr_valid(struct ata_link *link); extern int sata_scr_read(struct ata_link *link, int reg, u32 *val); extern int sata_scr_write(struct ata_link *link, int reg, u32 val); -- 2.8.0.rc3.226.g39d4020