From patchwork Mon May 21 10:09:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 136450 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp122523lji; Mon, 21 May 2018 03:15:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqlD/pyQ4j8/FrMIhllPWP+8EEYh75ey0AQlJKmb72peSouUgqbhrCWp2+VnH+8dU6iNPmg X-Received: by 2002:a17:902:981:: with SMTP id 1-v6mr19863027pln.11.1526897715351; Mon, 21 May 2018 03:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526897715; cv=none; d=google.com; s=arc-20160816; b=AUAEKILmc8q2+gdIjWWACzUOtJ1fipFq3E4TZa5GCsDSg0iVjhCMODdTCs9VNRERjd aeDMSZg7yDdXkYivDlcvBxfdud1bSvJdIG59HfUXq2MFN7jlMM2frOlD+VTPeO/Z6Ruc sNt4OGUxMVAFmsIloNDAaQz3kRvmVeSRCIWxe3HiY3Xf+quF2Q0CSDLDPmAtv0maqRQn v1Lw62DJW92rKYInU8qi3GFtKe0VrQrNqynthDGEEXI/Z8f+9OvUVMJaZ+GOnAyqAF3v oy8eoT7WpJK4lKnZbvVQHCh/ik1zE7mKFOIMvwnLWoWF+5fhCvCHRSTusPXTkDcYjst9 3tGg== 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=u+JLtX8jGUnvXSjdWtYJO8/wtHh6H5J4Eq2kZzEG4X4=; b=Zsn8O1+szazR5VyLx2YNJ0aLGqBRSe/XUiZEpeB5B21g8Lf1IA6Z9KJetTX4vw3Hkp qZwGLLzfizW8gHNsYj2Tqvu0+Zkfgf7Fpn8h8QtmnqJDha3a6YRSqKzQ7n7ssOtBEIHF nqQixYN8nxoKM1GYYHvNZ3ChhpffTIS23Rr8/lNZs4PZ2o2PhkCjeHTfrf5VsEJfWVER 7Dx2S/48HuNUwB1fzfQwhXk3zlo93lDrEj4AE8iGfp+zajPm2hx9cioBfPtGxwgzkg1h oHzZJ7RG0oYrqlz2Fk6uZofhJc9ehd5HOYryfxVyJuqqXCMR8YnVLYdNuEbLG8+82Ql7 BI+w== 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 f11-v6si10959237pgo.406.2018.05.21.03.15.15; Mon, 21 May 2018 03:15:15 -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 S1752802AbeEUKPM (ORCPT + 29 others); Mon, 21 May 2018 06:15:12 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:55744 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751434AbeEUKLj (ORCPT ); Mon, 21 May 2018 06:11:39 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 52F00F12B4C7F; Mon, 21 May 2018 18:11:35 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.382.0; Mon, 21 May 2018 18:11:28 +0800 From: John Garry To: , CC: , , , John Garry Subject: [PATCH 01/13] scsi: hisi_sas: Introduce hisi_sas_phy_set_linkrate() Date: Mon, 21 May 2018 18:09:13 +0800 Message-ID: <1526897365-228549-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1526897365-228549-1-git-send-email-john.garry@huawei.com> References: <1526897365-228549-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is much common code and functionality between the HW versions to set the PHY linkrate. As such, this patch factors out the common code into a generic function hisi_sas_phy_set_linkrate(). Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 29 +++++++++++++++++++++++++++- drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 35 ++++------------------------------ drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 21 ++------------------ drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 21 ++------------------ 4 files changed, 36 insertions(+), 70 deletions(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 39f694e..f822d6f 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -866,6 +866,33 @@ static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags) return hisi_sas_task_exec(task, gfp_flags, 0, NULL); } +static void hisi_sas_phy_set_linkrate(struct hisi_hba *hisi_hba, int phy_no, + struct sas_phy_linkrates *r) +{ + struct sas_phy_linkrates _r; + + struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; + struct asd_sas_phy *sas_phy = &phy->sas_phy; + enum sas_linkrate min, max; + + if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { + max = sas_phy->phy->maximum_linkrate; + min = r->minimum_linkrate; + } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) { + max = r->maximum_linkrate; + min = sas_phy->phy->minimum_linkrate; + } else + return; + + _r.maximum_linkrate = max; + _r.minimum_linkrate = min; + + hisi_hba->hw->phy_disable(hisi_hba, phy_no); + msleep(100); + hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, &_r); + hisi_hba->hw->phy_start(hisi_hba, phy_no); +} + static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func, void *funcdata) { @@ -889,7 +916,7 @@ static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func, break; case PHY_FUNC_SET_LINK_RATE: - hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, funcdata); + hisi_sas_phy_set_linkrate(hisi_hba, phy_no, funcdata); break; case PHY_FUNC_GET_EVENTS: if (hisi_hba->hw->get_events) { diff --git a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c index abe175f..8fa79d0 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c @@ -855,39 +855,12 @@ static enum sas_linkrate phy_get_max_linkrate_v1_hw(void) static void phy_set_linkrate_v1_hw(struct hisi_hba *hisi_hba, int phy_no, struct sas_phy_linkrates *r) { - u32 prog_phy_link_rate = - hisi_sas_phy_read32(hisi_hba, phy_no, PROG_PHY_LINK_RATE); - struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; - struct asd_sas_phy *sas_phy = &phy->sas_phy; - int i; - enum sas_linkrate min, max; - u32 rate_mask = 0; - - if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { - max = sas_phy->phy->maximum_linkrate; - min = r->minimum_linkrate; - } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) { - max = r->maximum_linkrate; - min = sas_phy->phy->minimum_linkrate; - } else - return; - - sas_phy->phy->maximum_linkrate = max; - sas_phy->phy->minimum_linkrate = min; - - max -= SAS_LINK_RATE_1_5_GBPS; + enum sas_linkrate max = r->maximum_linkrate; + u32 prog_phy_link_rate = 0x800; - for (i = 0; i <= max; i++) - rate_mask |= 1 << (i * 2); - - prog_phy_link_rate &= ~0xff; - prog_phy_link_rate |= rate_mask; - - disable_phy_v1_hw(hisi_hba, phy_no); - msleep(100); + prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max); hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE, - prog_phy_link_rate); - start_phy_v1_hw(hisi_hba, phy_no); + prog_phy_link_rate); } static int get_wideport_bitmap_v1_hw(struct hisi_hba *hisi_hba, int port_id) diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index 911bb76..fb0e966 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -1600,29 +1600,12 @@ static enum sas_linkrate phy_get_max_linkrate_v2_hw(void) static void phy_set_linkrate_v2_hw(struct hisi_hba *hisi_hba, int phy_no, struct sas_phy_linkrates *r) { - struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; - struct asd_sas_phy *sas_phy = &phy->sas_phy; - enum sas_linkrate min, max; + enum sas_linkrate max = r->maximum_linkrate; u32 prog_phy_link_rate = 0x800; - if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { - max = sas_phy->phy->maximum_linkrate; - min = r->minimum_linkrate; - } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) { - max = r->maximum_linkrate; - min = sas_phy->phy->minimum_linkrate; - } else - return; - - sas_phy->phy->maximum_linkrate = max; - sas_phy->phy->minimum_linkrate = min; prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max); - - disable_phy_v2_hw(hisi_hba, phy_no); - msleep(100); hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE, - prog_phy_link_rate); - start_phy_v2_hw(hisi_hba, phy_no); + prog_phy_link_rate); } static int get_wideport_bitmap_v2_hw(struct hisi_hba *hisi_hba, int port_id) diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index c013673..0a80a39 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -1879,29 +1879,12 @@ static int hisi_sas_v3_init(struct hisi_hba *hisi_hba) static void phy_set_linkrate_v3_hw(struct hisi_hba *hisi_hba, int phy_no, struct sas_phy_linkrates *r) { - struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; - struct asd_sas_phy *sas_phy = &phy->sas_phy; - enum sas_linkrate min, max; + enum sas_linkrate max = r->maximum_linkrate; u32 prog_phy_link_rate = 0x800; - if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { - max = sas_phy->phy->maximum_linkrate; - min = r->minimum_linkrate; - } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) { - max = r->maximum_linkrate; - min = sas_phy->phy->minimum_linkrate; - } else - return; - - sas_phy->phy->maximum_linkrate = max; - sas_phy->phy->minimum_linkrate = min; prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max); - - disable_phy_v3_hw(hisi_hba, phy_no); - msleep(100); hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE, - prog_phy_link_rate); - start_phy_v3_hw(hisi_hba, phy_no); + prog_phy_link_rate); } static void interrupt_disable_v3_hw(struct hisi_hba *hisi_hba)