From owner-svn-src-head@freebsd.org Wed Oct 14 23:48:17 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D5050A15D20; Wed, 14 Oct 2015 23:48:17 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 955D1EC3; Wed, 14 Oct 2015 23:48:17 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t9ENmGh0050879; Wed, 14 Oct 2015 23:48:16 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9ENmGSK050878; Wed, 14 Oct 2015 23:48:16 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201510142348.t9ENmGSK050878@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Wed, 14 Oct 2015 23:48:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r289348 - head/sys/dev/ntb/ntb_hw X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Oct 2015 23:48:17 -0000 Author: cem Date: Wed Oct 14 23:48:16 2015 New Revision: 289348 URL: https://svnweb.freebsd.org/changeset/base/289348 Log: NTB: MFV 1db97f25: Pull out platform detection logic Pull out read of PPD and platform detection logic to new functions, ntb_detect_xeon(), ntb_detect_soc(). No functional change -- mostly this is just shuffling the code to more closely match the Linux driver. Linux commit log: To simplify some of the platform detection code. Move the platform detection to a function to be called earlier. Authored by: Dave Jiang Obtained from: Linux (Dual BSD/GPL driver) Sponsored by: EMC / Isilon Storage Division Modified: head/sys/dev/ntb/ntb_hw/ntb_hw.c Modified: head/sys/dev/ntb/ntb_hw/ntb_hw.c ============================================================================== --- head/sys/dev/ntb/ntb_hw/ntb_hw.c Wed Oct 14 23:48:03 2015 (r289347) +++ head/sys/dev/ntb/ntb_hw/ntb_hw.c Wed Oct 14 23:48:16 2015 (r289348) @@ -146,6 +146,7 @@ struct ntb_softc { uint32_t lnk_stat; uint32_t spci_cmd; } reg_ofs; + uint32_t ppd; uint8_t conn_type; uint8_t dev_type; uint8_t bits_per_vector; @@ -218,6 +219,8 @@ static void unmask_ldb_interrupt(struct static int ntb_create_callbacks(struct ntb_softc *ntb, uint32_t num_vectors); static void ntb_free_callbacks(struct ntb_softc *ntb); static struct ntb_hw_info *ntb_get_device_info(uint32_t device_id); +static int ntb_detect_xeon(struct ntb_softc *ntb); +static int ntb_detect_soc(struct ntb_softc *ntb); static int ntb_setup_xeon(struct ntb_softc *ntb); static int ntb_setup_soc(struct ntb_softc *ntb); static void ntb_teardown_xeon(struct ntb_softc *ntb); @@ -311,6 +314,13 @@ ntb_attach(device_t device) callout_init(&ntb->heartbeat_timer, 1); callout_init(&ntb->lr_timer, 1); + if (ntb->type == NTB_SOC) + error = ntb_detect_soc(ntb); + else + error = ntb_detect_xeon(ntb); + if (error) + goto out; + error = ntb_map_pci_bars(ntb); if (error) goto out; @@ -874,29 +884,70 @@ ntb_teardown_xeon(struct ntb_softc *ntb) } static int -ntb_setup_xeon(struct ntb_softc *ntb) +ntb_detect_xeon(struct ntb_softc *ntb) { - uint8_t val, connection_type; - - val = pci_read_config(ntb->device, NTB_PPD_OFFSET, 1); + uint8_t ppd, conn_type; - connection_type = val & XEON_PPD_CONN_TYPE; + ppd = pci_read_config(ntb->device, NTB_PPD_OFFSET, 1); + ntb->ppd = ppd; - if ((val & XEON_PPD_DEV_TYPE) != 0) + if ((ppd & XEON_PPD_DEV_TYPE) != 0) ntb->dev_type = NTB_DEV_USD; else ntb->dev_type = NTB_DEV_DSD; + conn_type = ppd & XEON_PPD_CONN_TYPE; + switch (conn_type) { + case NTB_CONN_B2B: + ntb->conn_type = conn_type; + break; + case NTB_CONN_RP: + case NTB_CONN_TRANSPARENT: + default: + device_printf(ntb->device, "Unsupported connection type: %u\n", + (unsigned)conn_type); + return (ENXIO); + } + return (0); +} + +static int +ntb_detect_soc(struct ntb_softc *ntb) +{ + uint32_t ppd, conn_type; + + ppd = pci_read_config(ntb->device, NTB_PPD_OFFSET, 4); + ntb->ppd = ppd; + + if ((ppd & SOC_PPD_DEV_TYPE) != 0) + ntb->dev_type = NTB_DEV_DSD; + else + ntb->dev_type = NTB_DEV_USD; + + conn_type = (ppd & SOC_PPD_CONN_TYPE) >> 8; + switch (conn_type) { + case NTB_CONN_B2B: + ntb->conn_type = conn_type; + break; + default: + device_printf(ntb->device, "Unsupported NTB configuration\n"); + return (ENXIO); + } + return (0); +} + +static int +ntb_setup_xeon(struct ntb_softc *ntb) +{ + ntb->reg_ofs.ldb = XEON_PDOORBELL_OFFSET; ntb->reg_ofs.ldb_mask = XEON_PDBMSK_OFFSET; ntb->reg_ofs.spad_local = XEON_SPAD_OFFSET; ntb->reg_ofs.bar2_xlat = XEON_SBAR2XLAT_OFFSET; ntb->reg_ofs.bar4_xlat = XEON_SBAR4XLAT_OFFSET; - switch (connection_type) { + switch (ntb->conn_type) { case NTB_CONN_B2B: - ntb->conn_type = NTB_CONN_B2B; - /* * reg_ofs.rdb and reg_ofs.spad_remote are effectively ignored * with the NTB_REGS_THRU_MW errata mode enabled. (See @@ -922,7 +973,7 @@ ntb_setup_xeon(struct ntb_softc *ntb) case NTB_CONN_TRANSPARENT: default: device_printf(ntb->device, "Connection type %d not supported\n", - connection_type); + ntb->conn_type); return (ENXIO); } @@ -971,7 +1022,7 @@ ntb_setup_xeon(struct ntb_softc *ntb) */ if (HAS_FEATURE(NTB_B2BDOORBELL_BIT14) && !HAS_FEATURE(NTB_REGS_THRU_MW) && - connection_type == NTB_CONN_B2B) + ntb->conn_type == NTB_CONN_B2B) ntb->limits.max_db_bits = XEON_MAX_DB_BITS - 1; configure_xeon_secondary_side_bars(ntb); @@ -990,29 +1041,13 @@ ntb_setup_xeon(struct ntb_softc *ntb) static int ntb_setup_soc(struct ntb_softc *ntb) { - uint32_t val, connection_type; - - val = pci_read_config(ntb->device, NTB_PPD_OFFSET, 4); - - connection_type = (val & SOC_PPD_CONN_TYPE) >> 8; - switch (connection_type) { - case NTB_CONN_B2B: - ntb->conn_type = NTB_CONN_B2B; - break; - default: - device_printf(ntb->device, - "Unsupported NTB configuration (%d)\n", connection_type); - return (ENXIO); - } - if ((val & SOC_PPD_DEV_TYPE) != 0) - ntb->dev_type = NTB_DEV_DSD; - else - ntb->dev_type = NTB_DEV_USD; + KASSERT(ntb->conn_type == NTB_CONN_B2B, + ("Unsupported NTB configuration (%d)\n", ntb->conn_type)); /* Initiate PCI-E link training */ - pci_write_config(ntb->device, NTB_PPD_OFFSET, val | SOC_PPD_INIT_LINK, - 4); + pci_write_config(ntb->device, NTB_PPD_OFFSET, + ntb->ppd | SOC_PPD_INIT_LINK, 4); ntb->reg_ofs.ldb = SOC_PDOORBELL_OFFSET; ntb->reg_ofs.ldb_mask = SOC_PDBMSK_OFFSET;