linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Garry <john.garry@huawei.com>
To: martin.petersen@oracle.com, jejb@linux.vnet.ibm.com
Cc: linuxarm@huawei.com, arnd@arndb.de, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org, hch@infradead.org,
	John Garry <john.garry@huawei.com>
Subject: [PATCH v5 08/23] scsi: hisi_sas: create hisi_sas_get_fw_info()
Date: Fri, 9 Jun 2017 22:16:21 +0800	[thread overview]
Message-ID: <1497017796-105067-9-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1497017796-105067-1-git-send-email-john.garry@huawei.com>

Move the functionality to retrieve the fw info into
a dedicated device type-agnostic function,
hisi_sas_get_fw_info().

The reasoning is that this function will be required
for future pci-based platforms.

Also add some debug logs for failure.

Signed-off-by: John Garry <john.garry@huawei.com>
---
 drivers/scsi/hisi_sas/hisi_sas.h      |   1 +
 drivers/scsi/hisi_sas/hisi_sas_main.c | 107 ++++++++++++++++++++++------------
 2 files changed, 71 insertions(+), 37 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h
index 84cac98..c1f6669 100644
--- a/drivers/scsi/hisi_sas/hisi_sas.h
+++ b/drivers/scsi/hisi_sas/hisi_sas.h
@@ -371,6 +371,7 @@ struct hisi_sas_command_table_ssp {
 extern void hisi_sas_sata_done(struct sas_task *task,
 			    struct hisi_sas_slot *slot);
 extern int hisi_sas_get_ncq_tag(struct sas_task *task, u32 *tag);
+extern int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba);
 extern int hisi_sas_probe(struct platform_device *pdev,
 			  const struct hisi_sas_hw *ops);
 extern int hisi_sas_remove(struct platform_device *pdev);
diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index ff033bd..1a6adf7 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -1725,66 +1725,99 @@ static void hisi_sas_rst_work_handler(struct work_struct *work)
 	hisi_sas_controller_reset(hisi_hba);
 }
 
-static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev,
-					      const struct hisi_sas_hw *hw)
+int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba)
 {
-	struct resource *res;
-	struct Scsi_Host *shost;
-	struct hisi_hba *hisi_hba;
-	struct device *dev = &pdev->dev;
-	struct device_node *np = pdev->dev.of_node;
+	struct device *dev = hisi_hba->dev;
+	struct platform_device *pdev = hisi_hba->platform_dev;
+	struct device_node *np = pdev ? pdev->dev.of_node : NULL;
 	struct clk *refclk;
 
-	shost = scsi_host_alloc(&hisi_sas_sht, sizeof(*hisi_hba));
-	if (!shost) {
-		dev_err(dev, "scsi host alloc failed\n");
-		return NULL;
-	}
-	hisi_hba = shost_priv(shost);
-
-	INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler);
-	hisi_hba->hw = hw;
-	hisi_hba->platform_dev = pdev;
-	hisi_hba->dev = dev;
-	hisi_hba->shost = shost;
-	SHOST_TO_SAS_HA(shost) = &hisi_hba->sha;
-
-	init_timer(&hisi_hba->timer);
-
 	if (device_property_read_u8_array(dev, "sas-addr", hisi_hba->sas_addr,
-					  SAS_ADDR_SIZE))
-		goto err_out;
+					  SAS_ADDR_SIZE)) {
+		dev_err(dev, "could not get property sas-addr\n");
+		return -ENOENT;
+	}
 
 	if (np) {
+		/*
+		 * These properties are only required for platform device-based
+		 * controller with DT firmware.
+		 */
 		hisi_hba->ctrl = syscon_regmap_lookup_by_phandle(np,
 					"hisilicon,sas-syscon");
-		if (IS_ERR(hisi_hba->ctrl))
-			goto err_out;
+		if (IS_ERR(hisi_hba->ctrl)) {
+			dev_err(dev, "could not get syscon\n");
+			return -ENOENT;
+		}
 
 		if (device_property_read_u32(dev, "ctrl-reset-reg",
-					     &hisi_hba->ctrl_reset_reg))
-			goto err_out;
+					     &hisi_hba->ctrl_reset_reg)) {
+			dev_err(dev,
+				"could not get property ctrl-reset-reg\n");
+			return -ENOENT;
+		}
 
 		if (device_property_read_u32(dev, "ctrl-reset-sts-reg",
-					     &hisi_hba->ctrl_reset_sts_reg))
-			goto err_out;
+					     &hisi_hba->ctrl_reset_sts_reg)) {
+			dev_err(dev,
+				"could not get property ctrl-reset-sts-reg\n");
+			return -ENOENT;
+		}
 
 		if (device_property_read_u32(dev, "ctrl-clock-ena-reg",
-					     &hisi_hba->ctrl_clock_ena_reg))
-			goto err_out;
+					     &hisi_hba->ctrl_clock_ena_reg)) {
+			dev_err(dev,
+				"could not get property ctrl-clock-ena-reg\n");
+			return -ENOENT;
+		}
 	}
 
-	refclk = devm_clk_get(&pdev->dev, NULL);
+	refclk = devm_clk_get(dev, NULL);
 	if (IS_ERR(refclk))
 		dev_dbg(dev, "no ref clk property\n");
 	else
 		hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) / 1000000;
 
-	if (device_property_read_u32(dev, "phy-count", &hisi_hba->n_phy))
-		goto err_out;
+	if (device_property_read_u32(dev, "phy-count", &hisi_hba->n_phy)) {
+		dev_err(dev, "could not get property phy-count\n");
+		return -ENOENT;
+	}
 
 	if (device_property_read_u32(dev, "queue-count",
-				     &hisi_hba->queue_count))
+				     &hisi_hba->queue_count)) {
+		dev_err(dev, "could not get property queue-count\n");
+		return -ENOENT;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(hisi_sas_get_fw_info);
+
+static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev,
+					      const struct hisi_sas_hw *hw)
+{
+	struct resource *res;
+	struct Scsi_Host *shost;
+	struct hisi_hba *hisi_hba;
+	struct device *dev = &pdev->dev;
+
+	shost = scsi_host_alloc(&hisi_sas_sht, sizeof(*hisi_hba));
+	if (!shost) {
+		dev_err(dev, "scsi host alloc failed\n");
+		return NULL;
+	}
+	hisi_hba = shost_priv(shost);
+
+	INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler);
+	hisi_hba->hw = hw;
+	hisi_hba->dev = dev;
+	hisi_hba->platform_dev = pdev;
+	hisi_hba->shost = shost;
+	SHOST_TO_SAS_HA(shost) = &hisi_hba->sha;
+
+	init_timer(&hisi_hba->timer);
+
+	if (hisi_sas_get_fw_info(hisi_hba) < 0)
 		goto err_out;
 
 	if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) &&
-- 
1.9.1

  parent reply	other threads:[~2017-06-09 14:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-09 14:16 [PATCH v5 00/23] hisi_sas: hip08 support John Garry
2017-06-09 14:16 ` [PATCH v5 01/23] scsi: hisi_sas: fix timeout check in hisi_sas_internal_task_abort() John Garry
2017-06-09 14:16 ` [PATCH v5 02/23] scsi: hisi_sas: define hisi_sas_device.device_id as int John Garry
2017-06-09 14:16 ` [PATCH v5 03/23] scsi: hisi_sas: optimise the usage of hisi_hba.lock John Garry
2017-06-10 20:44   ` kbuild test robot
2017-06-12  8:26     ` John Garry
2017-06-12  9:45       ` Arnd Bergmann
2017-06-12 10:24         ` John Garry
2017-06-09 14:16 ` [PATCH v5 04/23] scsi: hisi_sas: relocate get_ata_protocol() John Garry
2017-06-09 14:16 ` [PATCH v5 05/23] scsi: hisi_sas: relocate sata_done_v2_hw() John Garry
2017-06-09 14:16 ` [PATCH v5 06/23] scsi: hisi_sas: relocate get_ncq_tag_v2_hw() John Garry
2017-06-09 14:16 ` [PATCH v5 07/23] scsi: hisi_sas: add pci_dev in hisi_hba struct John Garry
2017-06-09 14:16 ` John Garry [this message]
2017-06-09 14:16 ` [PATCH v5 09/23] scsi: hisi_sas: add skeleton v3 hw driver John Garry
2017-06-09 14:16 ` [PATCH v5 10/23] scsi: hisi_sas: add initialisation for v3 pci-based controller John Garry
2017-06-09 14:16 ` [PATCH v5 11/23] scsi: hisi_sas: add v3 hw init John Garry
2017-06-09 14:16 ` [PATCH v5 12/23] scsi: hisi_sas: add v3 hw PHY init John Garry
2017-06-09 14:16 ` [PATCH v5 13/23] scsi: hisi_sas: add phy up/down/bcast and channel ISR John Garry
2017-06-09 14:16 ` [PATCH v5 14/23] scsi: hisi_sas: add v3 cq interrupt handler John Garry
2017-06-09 14:16 ` [PATCH v5 15/23] scsi: hisi_sas: add v3 code to send SSP frame John Garry
2017-06-09 14:16 ` [PATCH v5 16/23] scsi: hisi_sas: add v3 code to send SMP frame John Garry
2017-06-09 14:16 ` [PATCH v5 17/23] scsi: hisi_sas: add v3 code to send ATA frame John Garry
2017-06-09 14:16 ` [PATCH v5 18/23] scsi: hisi_sas: add v3 code for itct setup and free John Garry
2017-06-09 14:16 ` [PATCH v5 19/23] scsi: hisi_sas: add v3 code to send internal abort command John Garry
2017-06-09 14:16 ` [PATCH v5 20/23] scsi: hisi_sas: add get_wideport_bitmap_v3_hw() John Garry
2017-06-09 14:16 ` [PATCH v5 21/23] scsi: hisi_sas: Add v3 code to support ECC and AXI bus fatal error John Garry
2017-06-09 14:16 ` [PATCH v5 22/23] scsi: hisi_sas: add v3 code to fill some more hw function pointers John Garry
2017-06-09 14:16 ` [PATCH v5 23/23] scsi: hisi_sas: modify internal abort dev flow for v3 hw John Garry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1497017796-105067-9-git-send-email-john.garry@huawei.com \
    --to=john.garry@huawei.com \
    --cc=arnd@arndb.de \
    --cc=hch@infradead.org \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).