From patchwork Fri Jan 19 12:37:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suganath Prabu S X-Patchwork-Id: 10175181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C3F8C60386 for ; Fri, 19 Jan 2018 12:38:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4C6428607 for ; Fri, 19 Jan 2018 12:38:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A99FE2868D; Fri, 19 Jan 2018 12:38:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AECA28607 for ; Fri, 19 Jan 2018 12:38:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755256AbeASMiI (ORCPT ); Fri, 19 Jan 2018 07:38:08 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:40464 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755197AbeASMiH (ORCPT ); Fri, 19 Jan 2018 07:38:07 -0500 Received: by mail-qt0-f196.google.com with SMTP id s39so3395242qth.7 for ; Fri, 19 Jan 2018 04:38:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7ums088SKTLN56+A0JT5jZpS2xcvab0bKy4nvjdez/g=; b=bFRy2i4VeCyHmkQl4/FYw0TQebIPnsbbbQDEpbT78Q1BOULMZ5B6t+CLRF31LFCvfn 9A3sNfyF1OZBUqEaK10pn/No5UAn7PMHriYcymgFp083zifpOGsMRZ5oxDPlfFj528Pi LXeaVhotbD7HQ9f2TYo+d8Wdy/RBsgoi8iXrE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7ums088SKTLN56+A0JT5jZpS2xcvab0bKy4nvjdez/g=; b=ncN9Ap9O1E/qBRbBPD54C2N/jRNItQ/sycZwqCZBaoUequEu2mA1qs6fo2ee5XKN+S YYHp0vOIi7Zite921iehfzEW5ucAPBE5kmm+sGUdOkuIoBWSfFlDN2Ysj+yj7Mb9UjxD A4p+MP0Qd7n+2q+O+xnTpIsE5HuehHWFZHDH1MgWIq6qgroAanmik6+O7vwhfPoe5kG2 /zpWQUKZ2rr/SFjY4nh6KOl/pgE3WrnvW6IEtNdRCNxS0f46+8qk0LKZtG+ENJH9jv7m MxDwTPsMVpiQ2Dtk8tgM0hD1H9z+byCw77Kk2IT+EQ3q1TEMkM5omQNXyim0eyZ7rZS6 JxUQ== X-Gm-Message-State: AKwxyteokC6AiFzFfsOWbsbKJz187sExvexRC/qjkeK9HmEIw9futzym wyf6HMzfq73EIlOLNYVZ8/OpFUio X-Google-Smtp-Source: ACJfBouhTEK+hf+WctiJp7S29heC+eowrZv//pk+9H0RBf6cxFuYNwdPLveiY/jnQ8P1J/ctLplVfg== X-Received: by 10.237.37.154 with SMTP id x26mr50821555qtc.78.1516365486885; Fri, 19 Jan 2018 04:38:06 -0800 (PST) Received: from dhcp-135-24-192-103.dhcp.broadcom.net ([192.19.239.250]) by smtp.googlemail.com with ESMTPSA id p40sm6327885qtp.25.2018.01.19.04.38.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 04:38:06 -0800 (PST) From: Suganath Prabu S To: linux-scsi@vger.kernel.org, linux-nvme@lists.infradead.org Cc: Sathya.Prakash@broadcom.com, sreekanth.reddy@broadcom.com, chaitra.basappa@broadcom.com, Suganath Prabu S Subject: [PATCH 3/6] mpt3sas: Introduce API's to get BAR0 mapped buffer address. Date: Fri, 19 Jan 2018 04:37:39 -0800 Message-Id: <1516365462-14708-4-git-send-email-suganath-prabu.subramani@broadcom.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1516365462-14708-1-git-send-email-suganath-prabu.subramani@broadcom.com> References: <1516365462-14708-1-git-send-email-suganath-prabu.subramani@broadcom.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For MPI Endpoint/Mcpu, Driver should double buffer data buffer/sgl's. This is normally copied from host to internal memory of IOC by DMA engine of PCI Device. Since the interface to DMA from host to mCPU is not present for Mcpu/MPI Endpoint device, Driver does double copy of those buffer directly to the mCPU memory region via BAR-0 region. Introduced API's to calculate and return BAR0 mapped host buffer's physical and virtual address for the provided smid. Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_base.c | 93 +++++++++++++++++++++++++++++++++++++ drivers/scsi/mpt3sas/mpt3sas_base.h | 2 + 2 files changed, 95 insertions(+) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index c0a1c0f..dc289c0 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -126,6 +126,99 @@ module_param_call(mpt3sas_fwfault_debug, _scsih_set_fwfault_debug, param_get_int, &mpt3sas_fwfault_debug, 0644); /** + * _base_get_chain - Calculates and Returns virtual chain address + * for the provided smid in BAR0 space. + * + * @ioc: per adapter object + * @smid: system request message index + * @sge_chain_count: Scatter gather chain count. + * + * @Return: chain address. + */ +static inline void * +_base_get_chain(struct MPT3SAS_ADAPTER *ioc, u16 smid, + u8 sge_chain_count) +{ + void *base_chain, *chain_virt; + u16 cmd_credit = ioc->facts.RequestCredit + 1; + + base_chain = (void *)ioc->chip + MPI_FRAME_START_OFFSET + + (cmd_credit * ioc->request_sz) + + REPLY_FREE_POOL_SIZE; + chain_virt = base_chain + (smid * ioc->facts.MaxChainDepth * + ioc->request_sz) + (sge_chain_count * ioc->request_sz); + return chain_virt; +} + +/** + * _base_get_chain_phys - Calculates and Returns physical address + * in BAR0 for scatter gather chains, for + * the provided smid. + * + * @ioc: per adapter object + * @smid: system request message index + * @sge_chain_count: Scatter gather chain count. + * + * @Return - Physical chain address. + */ +static inline void * +_base_get_chain_phys(struct MPT3SAS_ADAPTER *ioc, u16 smid, + u8 sge_chain_count) +{ + void *base_chain_phys, *chain_phys; + u16 cmd_credit = ioc->facts.RequestCredit + 1; + + base_chain_phys = (void *)ioc->chip_phys + MPI_FRAME_START_OFFSET + + (cmd_credit * ioc->request_sz) + + REPLY_FREE_POOL_SIZE; + chain_phys = base_chain_phys + (smid * ioc->facts.MaxChainDepth * + ioc->request_sz) + (sge_chain_count * ioc->request_sz); + return chain_phys; +} + +/** + * _base_get_buffer_bar0 - Calculates and Returns BAR0 mapped Host + * buffer address for the provided smid. + * (Each smid can have 64K starts from 17024) + * + * @ioc: per adapter object + * @smid: system request message index + * + * @Returns - Pointer to buffer location in BAR0. + */ + +static void * +_base_get_buffer_bar0(struct MPT3SAS_ADAPTER *ioc, u16 smid) +{ + u16 cmd_credit = ioc->facts.RequestCredit + 1; + // Added extra 1 to reach end of chain. + void *chain_end = _base_get_chain(ioc, + cmd_credit + 1, + ioc->facts.MaxChainDepth); + return chain_end + (smid * 64 * 1024); +} + +/** + * _base_get_buffer_phys_bar0 - Calculates and Returns BAR0 mapped + * Host buffer Physical address for the provided smid. + * (Each smid can have 64K starts from 17024) + * + * @ioc: per adapter object + * @smid: system request message index + * + * @Returns - Pointer to buffer location in BAR0. + */ +static void * +_base_get_buffer_phys_bar0(struct MPT3SAS_ADAPTER *ioc, u16 smid) +{ + u16 cmd_credit = ioc->facts.RequestCredit + 1; + void *chain_end_phys = _base_get_chain_phys(ioc, + cmd_credit + 1, + ioc->facts.MaxChainDepth); + return chain_end_phys + (smid * 64 * 1024); +} + +/** * mpt3sas_remove_dead_ioc_func - kthread context to remove dead ioc * @arg: input argument, used to derive ioc * diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h index 897394d..2529d25 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.h +++ b/drivers/scsi/mpt3sas/mpt3sas_base.h @@ -120,6 +120,8 @@ #define MPT3SAS_NVME_QUEUE_DEPTH 128 #define MPT_NAME_LENGTH 32 /* generic length of strings */ #define MPT_STRING_LENGTH 64 +#define MPI_FRAME_START_OFFSET 256 +#define REPLY_FREE_POOL_SIZE 512 /*(32 maxcredix *4)*(4 times)*/ #define MPT_MAX_CALLBACKS 32