linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Garry <john.garry@huawei.com>
To: JBottomley@odin.com, robh+dt@kernel.org, pawel.moll@arm.com,
	mark.rutland@arm.com, ijc+devicetree@hellion.org.uk,
	galak@codeaurora.org, arnd@arndb.de
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, linuxarm@huawei.com,
	john.garry2@mail.dcu.ie, hare@suse.de, xuwei5@hisilicon.com,
	zhangfei.gao@linaro.org, John Garry <john.garry@huawei.com>
Subject: [PATCH v2 07/32] scsi: hisi_sas: allocate memories and create pools
Date: Mon, 26 Oct 2015 22:14:38 +0800	[thread overview]
Message-ID: <1445868903-183817-8-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1445868903-183817-1-git-send-email-john.garry@huawei.com>

Allocate DMA and non-DMA memories for the controller. Also
create DMA pools.

These include:
- Delivery queues
- Completion queues
- Command status buffer
- Command table
- ITCT (For device context)
- Host slot info
- IO status
- Breakpoint
- host slot indexing
- SG data
- FIS
- interrupts names
---
 drivers/scsi/hisi_sas/hisi_sas.h      | 31 ++++++++++++
 drivers/scsi/hisi_sas/hisi_sas_main.c | 95 +++++++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+)

diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h
index d93e55a..c320c10 100644
--- a/drivers/scsi/hisi_sas/hisi_sas.h
+++ b/drivers/scsi/hisi_sas/hisi_sas.h
@@ -24,10 +24,17 @@
 #define DRV_VERSION "v1.0"
 
 #define HISI_SAS_MAX_PHYS	9
+#define HISI_SAS_MAX_QUEUES	32
+#define HISI_SAS_QUEUE_SLOTS 512
 #define HISI_SAS_MAX_ITCT_ENTRIES 4096
 #define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
 #define HISI_SAS_COMMAND_ENTRIES 8192
 
+#define HISI_SAS_STATUS_BUF_SZ \
+		(sizeof(struct hisi_sas_err_record) + 1024)
+#define HISI_SAS_COMMAND_TABLE_SZ \
+		(((sizeof(union hisi_sas_command_table)+3)/4)*4)
+
 #define HISI_SAS_NAME_LEN 32
 #define HISI_SAS_CTRL_REG_CNT 5
 
@@ -39,7 +46,11 @@ struct hisi_sas_port {
 	struct asd_sas_port	sas_port;
 };
 
+struct hisi_sas_slot {
+};
+
 struct hisi_sas_hw {
+	int complete_hdr_size;
 };
 
 struct hisi_hba {
@@ -52,6 +63,7 @@ struct hisi_hba {
 	u32 ctrl_reg[HISI_SAS_CTRL_REG_CNT];
 	u8 sas_addr[SAS_ADDR_SIZE];
 
+
 	int n_phy;
 
 	/* SCSI/SAS glue */
@@ -62,6 +74,25 @@ struct hisi_hba {
 
 	int	queue_count;
 	char	*int_names;
+
+	struct dma_pool *sge_page_pool;
+	struct dma_pool *command_table_pool;
+	struct dma_pool *status_buffer_pool;
+	struct hisi_sas_cmd_hdr	*cmd_hdr[HISI_SAS_MAX_QUEUES];
+	dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
+	void *complete_hdr[HISI_SAS_MAX_QUEUES];
+	dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
+	struct hisi_sas_initial_fis *initial_fis;
+	dma_addr_t initial_fis_dma;
+	struct hisi_sas_itct *itct;
+	dma_addr_t itct_dma;
+	struct hisi_sas_iost *iost;
+	dma_addr_t iost_dma;
+	struct hisi_sas_breakpoint *breakpoint;
+	dma_addr_t breakpoint_dma;
+	struct hisi_sas_breakpoint *sata_breakpoint;
+	dma_addr_t sata_breakpoint_dma;
+	struct hisi_sas_slot	*slot_info;
 	const struct hisi_sas_hw *hw;	/* Low level hw interface */
 };
 
diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 91f6504..e03a62b 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -37,6 +37,98 @@ static struct scsi_host_template hisi_sas_sht = {
 static struct sas_domain_function_template hisi_sas_transport_ops = {
 };
 
+static int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost)
+{
+	int i, s;
+	struct platform_device *pdev = hisi_hba->pdev;
+	struct device *dev = &pdev->dev;
+
+
+	for (i = 0; i < hisi_hba->queue_count; i++) {
+		/* Delivery queue */
+		s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS;
+		hisi_hba->cmd_hdr[i] = dma_alloc_coherent(dev, s,
+					&hisi_hba->cmd_hdr_dma[i], GFP_KERNEL);
+		if (!hisi_hba->cmd_hdr[i])
+			goto err_out;
+		memset(hisi_hba->cmd_hdr[i], 0, s);
+
+		/* Completion queue */
+		s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS;
+		hisi_hba->complete_hdr[i] = dma_alloc_coherent(dev, s,
+				&hisi_hba->complete_hdr_dma[i], GFP_KERNEL);
+		if (!hisi_hba->complete_hdr[i])
+			goto err_out;
+		memset(hisi_hba->complete_hdr[i], 0, s);
+	}
+
+	s = HISI_SAS_STATUS_BUF_SZ;
+	hisi_hba->status_buffer_pool = dma_pool_create("status_buffer",
+						       dev, s, 16, 0);
+	if (!hisi_hba->status_buffer_pool)
+		goto err_out;
+
+	s = HISI_SAS_COMMAND_TABLE_SZ;
+	hisi_hba->command_table_pool = dma_pool_create("command_table",
+						       dev, s, 16, 0);
+	if (!hisi_hba->command_table_pool)
+		goto err_out;
+
+	s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct);
+	hisi_hba->itct = dma_alloc_coherent(dev, s, &hisi_hba->itct_dma,
+					    GFP_KERNEL);
+	if (!hisi_hba->itct)
+		goto err_out;
+
+	memset(hisi_hba->itct, 0, s);
+
+	hisi_hba->slot_info = devm_kcalloc(dev, HISI_SAS_COMMAND_ENTRIES,
+					   sizeof(struct hisi_sas_slot),
+					   GFP_KERNEL);
+	if (!hisi_hba->slot_info)
+		goto err_out;
+
+	s = HISI_SAS_COMMAND_ENTRIES * sizeof(struct hisi_sas_iost);
+	hisi_hba->iost = dma_alloc_coherent(dev, s, &hisi_hba->iost_dma,
+					    GFP_KERNEL);
+	if (!hisi_hba->iost)
+		goto err_out;
+
+	memset(hisi_hba->iost, 0, s);
+
+	s = HISI_SAS_COMMAND_ENTRIES * sizeof(struct hisi_sas_breakpoint);
+	hisi_hba->breakpoint = dma_alloc_coherent(dev, s,
+				&hisi_hba->breakpoint_dma, GFP_KERNEL);
+	if (!hisi_hba->breakpoint)
+		goto err_out;
+
+	memset(hisi_hba->breakpoint, 0, s);
+
+	hisi_hba->sge_page_pool = dma_pool_create("status_sge", dev,
+				sizeof(struct hisi_sas_sge_page), 16, 0);
+	if (!hisi_hba->sge_page_pool)
+		goto err_out;
+
+	s = sizeof(struct hisi_sas_initial_fis) * HISI_SAS_MAX_PHYS;
+	hisi_hba->initial_fis = dma_alloc_coherent(dev, s,
+				&hisi_hba->initial_fis_dma, GFP_KERNEL);
+	if (!hisi_hba->initial_fis)
+		goto err_out;
+	memset(hisi_hba->initial_fis, 0, s);
+
+	s = HISI_SAS_COMMAND_ENTRIES * sizeof(struct hisi_sas_breakpoint) * 2;
+	hisi_hba->sata_breakpoint = dma_alloc_coherent(dev, s,
+				&hisi_hba->sata_breakpoint_dma, GFP_KERNEL);
+	if (!hisi_hba->sata_breakpoint)
+		goto err_out;
+	memset(hisi_hba->sata_breakpoint, 0, s);
+
+	return 0;
+err_out:
+	return -ENOMEM;
+}
+
+
 static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev,
 					      const struct hisi_sas_hw *hw)
 {
@@ -91,6 +183,9 @@ static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev,
 	if (IS_ERR(hisi_hba->ctrl))
 		goto err_out;
 
+	if (hisi_sas_alloc(hisi_hba, shost))
+		goto err_out;
+
 	return shost;
 err_out:
 	dev_err(dev, "shost alloc failed\n");
-- 
1.9.1

  parent reply	other threads:[~2015-10-26 14:14 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-26 14:14 [PATCH v2 00/32] HiSilicon SAS driver John Garry
2015-10-26 14:14 ` [PATCH v2 01/32] [SCSI] sas: centralise ssp frame information units John Garry
2015-10-26 14:14 ` [PATCH v2 02/32] devicetree: bindings: scsi: HiSi SAS John Garry
2015-10-26 14:45   ` Mark Rutland
2015-10-27 13:09     ` John Garry
2015-10-27 14:39       ` Mark Rutland
2015-10-27 14:54         ` zhangfei
2015-10-27 15:03           ` Mark Rutland
     [not found]           ` <562F9016.50807-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2015-10-27 15:06             ` John Garry
     [not found]   ` <1445868903-183817-3-git-send-email-john.garry-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2015-10-26 14:55     ` John Garry
2015-10-26 14:14 ` [PATCH v2 03/32] scsi: hisi_sas: add initial bare main driver John Garry
2015-10-26 14:14 ` [PATCH v2 04/32] scsi: hisi_sas: add scsi host registration John Garry
2015-10-26 14:14 ` [PATCH v2 06/32] scsi: hisi_sas: add HW DMA structures John Garry
2015-10-26 14:14 ` John Garry [this message]
2015-10-26 14:14 ` [PATCH v2 08/32] scsi: hisi_sas: add hisi_sas_remove John Garry
2015-10-26 14:14 ` [PATCH v2 09/32] scsi: hisi_sas: add slot init code John Garry
2015-10-26 14:14 ` [PATCH v2 10/32] scsi: hisi_sas: add cq structure initialization John Garry
2015-10-26 14:14 ` [PATCH v2 11/32] scsi: hisi_sas: add phy SAS ADDR initialization John Garry
2015-10-26 14:14 ` [PATCH v2 12/32] scsi: hisi_sas: set dev DMA mask John Garry
2015-10-26 14:14 ` [PATCH v2 13/32] scsi: hisi_sas: add hisi_hba workqueue John Garry
2015-10-26 14:14 ` [PATCH v2 14/32] scsi: hisi_sas: add hisi sas device type John Garry
2015-10-26 14:14 ` [PATCH v2 15/32] scsi: hisi_sas: add phy and port init John Garry
2015-10-26 14:14 ` [PATCH v2 16/32] scsi: hisi_sas: add timer and spinlock init John Garry
2015-10-26 14:14 ` [PATCH v2 17/32] scsi: hisi_sas: add v1 hw module init John Garry
2015-10-26 14:14 ` [PATCH v2 18/32] scsi: hisi_sas: add v1 hardware register definitions John Garry
     [not found] ` <1445868903-183817-1-git-send-email-john.garry-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2015-10-26 14:14   ` [PATCH v2 05/32] scsi: hisi_sas: scan device tree John Garry
     [not found]     ` <1445868903-183817-6-git-send-email-john.garry-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2015-10-26 14:48       ` Mark Rutland
2015-10-26 14:51         ` John Garry
2015-10-26 19:55       ` kbuild test robot
2015-10-26 14:14   ` [PATCH v2 19/32] scsi: hisi_sas: add v1 HW initialisation code John Garry
2015-10-26 14:14 ` [PATCH v2 20/32] scsi: hisi_sas: add v1 hw interrupt init John Garry
2015-10-26 14:14 ` [PATCH v2 21/32] scsi: hisi_sas: add path from phyup irq to SAS framework John Garry
2015-10-26 14:14 ` [PATCH v2 22/32] scsi: hisi_sas: add ssp command function John Garry
2015-10-26 14:14 ` [PATCH v2 23/32] scsi: hisi_sas: add cq interrupt handler John Garry
2015-10-26 14:14 ` [PATCH v2 24/32] scsi: hisi_sas: add dev_found and port_formed John Garry
2015-10-26 14:14 ` [PATCH v2 25/32] scsi: hisi_sas: add abnormal irq handler John Garry
     [not found]   ` <1445868903-183817-26-git-send-email-john.garry-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2015-10-30 14:10     ` Arnd Bergmann
2015-10-30 16:58       ` John Garry
2015-10-26 14:14 ` [PATCH v2 26/32] scsi: hisi_sas: add bcast interrupt handler John Garry
2015-10-26 14:14 ` [PATCH v2 27/32] scsi: hisi_sas: add smp protocol support John Garry
     [not found]   ` <1445868903-183817-28-git-send-email-john.garry-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2015-10-30 13:53     ` Arnd Bergmann
2015-10-30 16:22       ` John Garry
2015-11-02 17:03         ` John Garry
2015-11-02 20:29           ` Arnd Bergmann
2015-11-03 11:42             ` John Garry
     [not found]               ` <56389DA6.6070103-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2015-11-03 12:27                 ` Arnd Bergmann
2015-10-26 14:14 ` [PATCH v2 28/32] scsi: hisi_sas: add scan finished and start John Garry
2015-10-26 14:15 ` [PATCH v2 29/32] scsi: hisi_sas: add tmf methods John Garry
2015-10-26 14:15 ` [PATCH v2 30/32] scsi: hisi_sas: add control phy handler John Garry
2015-10-26 14:15 ` [PATCH v2 31/32] scsi: hisi_sas: add fatal irq handler John Garry
2015-10-26 14:15 ` [PATCH v2 32/32] MAINTAINERS: add maintainer for HiSi SAS driver 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=1445868903-183817-8-git-send-email-john.garry@huawei.com \
    --to=john.garry@huawei.com \
    --cc=JBottomley@odin.com \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=hare@suse.de \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=john.garry2@mail.dcu.ie \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=xuwei5@hisilicon.com \
    --cc=zhangfei.gao@linaro.org \
    /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).