From patchwork Wed May 17 10:49:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 99950 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp159716qge; Wed, 17 May 2017 03:20:11 -0700 (PDT) X-Received: by 10.99.2.88 with SMTP id 85mr2947153pgc.23.1495016410946; Wed, 17 May 2017 03:20:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495016410; cv=none; d=google.com; s=arc-20160816; b=YGOaZRRjG+OiJ+1+V9uXj9NfslkeIvHUauFJNvVs5rx6LfnghgHzCr18OJk0rboeIL qqzo1Mkk8T8L37ZUnVvIvwm2zMgoQD535topabMyYPlCM0kaS4+DD0fnu/FOTWkxW/z9 e1H0QW+5+v9y3LljixoiNj++BZ0xOWFDvQDeo7s+o7Qgfxbj7cNb3a22YTrXZ1NYByqj OTtIOkHW54ApsDMrU67469yq3M78n/3dTpe/l/+Mn73qUIoCO2mzZN1tRKlQv9aXefZh XBDIpNWlhY6gexaouqBO63duf4u5A5hh7s36Wm9xL6RZh+uYWFYfBlzzv/Ry9axvO8YJ NnRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=Z6ONpScbgTfEg9V20RpPw0Z9rnBBkPqoL5o+kSR3NNo=; b=M4g/B5RYx38Fag+VUUz+IfJPuWOZB9exyAdt1qhtYQgdcieByQLOZNl8HiRg24oovu 24fvv0IaW4RylTMln7T0an7eZP1dvnIqJr5//f8+nhUjeUyi8s9+u91hum11tXaRTntk 3C9yI4w7zgwP5TuKOnEucFPvZvWr4/NrWuO2yzZlVi9qW2ovNom/haThCFyKEleJONUq Awv8c/kqZ9EOqx/Ed1211Pd2RURaoWdnkcnttHVvkUlwK4wwQhNmNBAKAwMUahf89vGy 6+3s/Rat7CqVvr3wrNYH2f46Hb1mHRdGBxEGt2MJSZu/rySvUKGoDof2/6u+vIrzkPUh VsIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g34si1658480pld.328.2017.05.17.03.20.10; Wed, 17 May 2017 03:20:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754486AbdEQKT6 (ORCPT + 25 others); Wed, 17 May 2017 06:19:58 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6316 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754445AbdEQKTw (ORCPT ); Wed, 17 May 2017 06:19:52 -0400 Received: from 172.30.72.55 (EHLO dggeml406-hub.china.huawei.com) ([172.30.72.55]) by dggrg01-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id AOT12432; Wed, 17 May 2017 18:19:44 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by dggeml406-hub.china.huawei.com (10.3.17.50) with Microsoft SMTP Server id 14.3.301.0; Wed, 17 May 2017 18:19:33 +0800 From: John Garry To: , CC: , , , , , John Garry Subject: [PATCH 09/22] scsi: hisi_sas: retrieve SAS address for pci-based controller Date: Wed, 17 May 2017 18:49:44 +0800 Message-ID: <1495018197-120535-10-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1495018197-120535-1-git-send-email-john.garry@huawei.com> References: <1495018197-120535-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.591C23C0.010C, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: e17a67d847dad4f76da9596091dfa19e Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For a pci-based controller, retrieve the SAS address from the ACPI tables. The retrieval is based on the ACPI device node name. Sample is as follows: Scope(_SB) { Device(SAS0) { Name(_HID, "HISI0163") Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { Package (2) {"sas-addr", Package() {0x50, 0x01, 0x88, 0x20, 0x16, 00, 00, 0x00}}, } }) } } If the ACPI node or node property is not available, then we fall back on a default address. Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas.h | 2 + drivers/scsi/hisi_sas/hisi_sas_pci_init.c | 104 ++++++++++++++++++++++++++++++ drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 2 +- 3 files changed, 107 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h index 9bc9550..9fd874d 100644 --- a/drivers/scsi/hisi_sas/hisi_sas.h +++ b/drivers/scsi/hisi_sas/hisi_sas.h @@ -190,6 +190,7 @@ struct hisi_sas_pci_hw { int n_phy; int queue_count; const struct hisi_sas_hw *hw; + const char *fw_name; }; struct hisi_hba { @@ -250,6 +251,7 @@ struct hisi_hba { struct hisi_sas_slot *slot_info; unsigned long flags; const struct hisi_sas_hw *hw; /* Low level hw interface */ + const char *fw_name; unsigned long sata_dev_bitmap[BITS_TO_LONGS(HISI_SAS_MAX_DEVICES)]; struct work_struct rst_work; }; diff --git a/drivers/scsi/hisi_sas/hisi_sas_pci_init.c b/drivers/scsi/hisi_sas/hisi_sas_pci_init.c index e00b482..6d92893 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_pci_init.c +++ b/drivers/scsi/hisi_sas/hisi_sas_pci_init.c @@ -11,6 +11,107 @@ #include "hisi_sas.h" #define DRV_NAME "hisi_sas_pci" + +static const u8 default_sas_addr[SAS_ADDR_SIZE] = { + 0x50, 0x01, 0x88, 0x20, 0x16, 0x0, 0x0, 0x0}; +static void hisi_sas_pci_set_sas_addr(struct hisi_hba *hisi_hba); + +static void +hisi_sas_pci_set_default_sas_addr(struct hisi_hba *hisi_hba) +{ + dev_warn(hisi_hba->dev, "using default SAS ADDR\n"); + memcpy(hisi_hba->sas_addr, default_sas_addr, SAS_ADDR_SIZE); +} + +#if defined(CONFIG_ACPI) +static int +acpi_get_sas_address(struct device *dev, struct acpi_device *adev, + u8 *dst) +{ + u8 addr[SAS_ADDR_SIZE]; + int rc; + + rc = fwnode_property_read_u8_array(acpi_fwnode_handle(adev), + "sas-addr", addr, SAS_ADDR_SIZE); + if (rc) { + dev_warn(dev, "could not read sas-addr (%d)\n", rc); + return rc; + } + + dev_info(dev, "SAS address set to: %pM\n", addr); + + memcpy(dst, addr, SAS_ADDR_SIZE); + + return 0; +} + +static acpi_status +hisi_sas_acpi_match_id(acpi_handle handle, u32 lvl, + void *context, void **ret_val) +{ + struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; + struct hisi_hba *hisi_hba = context; + struct device *dev = hisi_hba->dev; + struct acpi_device *adev; + int rc; + + if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &string))) { + dev_warn(dev, "Invalid link device\n"); + return AE_OK; + } + + if (strncmp(string.pointer, hisi_hba->fw_name, 4)) + return AE_OK; + + rc = acpi_bus_get_device(handle, &adev); + + if (rc == 0) + rc = acpi_get_sas_address(dev, adev, hisi_hba->sas_addr); + else + dev_warn(dev, "could not get acpi bus device (%d)\n", rc); + + if (rc == 0) + *(acpi_handle *)ret_val = handle; + + kfree(string.pointer); + return AE_CTRL_TERMINATE; +} + +static acpi_status +hisi_sas_acpi_set_sas_addr(struct hisi_hba *hisi_hba) +{ + acpi_status status1; + acpi_handle *acpi_handle = NULL; + + status1 = acpi_get_devices(NULL, hisi_sas_acpi_match_id, + hisi_hba, (void **)&acpi_handle); + + if (status1 != AE_OK) + return status1; + + if (!acpi_handle) + return AE_ERROR; + + return AE_OK; +} +#else +static acpi_status +hisi_sas_acpi_set_sas_addr(struct hisi_hba *hisi_hba) +{ + return AE_ERROR; +} +#endif + +static void hisi_sas_pci_set_sas_addr(struct hisi_hba *hisi_hba) +{ + acpi_status status = AE_ERROR; + if (!acpi_disabled) + status = hisi_sas_acpi_set_sas_addr(hisi_hba); + if (status == AE_OK) + return; + hisi_sas_pci_set_default_sas_addr(hisi_hba); +} + static struct Scsi_Host * hisi_sas_shost_alloc_pci(struct pci_dev *pdev, const struct hisi_sas_pci_hw *hw) @@ -32,6 +133,9 @@ hisi_hba->shost = shost; SHOST_TO_SAS_HA(shost) = &hisi_hba->sha; + hisi_hba->fw_name = hw->fw_name; + hisi_sas_pci_set_sas_addr(hisi_hba); + init_timer(&hisi_hba->timer); if (hisi_sas_alloc(hisi_hba, shost)) { diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index 80707f6..68b9b0e 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -20,7 +20,7 @@ enum { }; static const struct hisi_sas_pci_hw hisi_sas_pci_hw_info[] = { - [hip08] = {8, 16, &hisi_sas_v3_hw}, + [hip08] = {8, 16, &hisi_sas_v3_hw, "SAS0"}, }; static const struct pci_device_id sas_v3_pci_table[] = {