Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754650AbdCHV4o (ORCPT ); Wed, 8 Mar 2017 16:56:44 -0500 Received: from mail-cys01nam02on0040.outbound.protection.outlook.com ([104.47.37.40]:25824 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754190AbdCHV4D (ORCPT ); Wed, 8 Mar 2017 16:56:03 -0500 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; From: Roy Pledge To: CC: , , , , , , , , , , , Haiying Wang , Stuart Yoder Subject: [v6 7/8] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver Date: Wed, 8 Mar 2017 16:54:49 -0500 Message-ID: <1489010090-18025-8-git-send-email-roy.pledge@nxp.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1489010090-18025-1-git-send-email-roy.pledge@nxp.com> References: <1489010090-18025-1-git-send-email-roy.pledge@nxp.com> Reply-To: X-EOPAttributedMessage: 0 X-Matching-Connectors: 131334837100478707;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.158.2;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(336005)(39840400002)(39380400002)(39400400002)(39860400002)(39450400003)(39410400002)(39850400002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(9170700003)(38730400002)(2950100002)(77096006)(54906002)(104016004)(5660300001)(53936002)(50986999)(8936002)(36756003)(305945005)(4720700003)(5003940100001)(43066003)(85426001)(81166006)(6666003)(7416002)(189998001)(106466001)(48376002)(3450700001)(105606002)(4326008)(47776003)(2351001)(6916009)(76176999)(110136004)(50226002)(50466002)(33646002)(39060400002)(97736004)(2906002)(356003)(8656002)(8676002)(86362001)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:SN2PR03MB1951;H:az84smr01.freescale.net;FPR:;SPF:Fail;MLV:ovrnspm;A:1;MX:1;PTR:InfoDomainNonexistent;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD034;1:bSce9K2si5FWQwvRVX27qMnynGkkaa7ZIIzPKU/I7SXUOdGn4QFZXYxxH2iN8wqBUbme80VnSkLVB0/Gs3iiHNFO0NEBUtAcjx5FWmjeEZCcOtPnTfe3WsCpPhnG4KdBklD8pubyDvu4vGDnlHkLiyzHGZns+sP5WfbmyTgtgABC7rX83HEyzIYF3ADMqBJZpYIAMv5wlSsYUxCJXSjQ9LbyC70SLKmjVQF77n1P1JPrybMVD2F7rxw12I5xCRGrnWvJWOMp1PFECSznvifHM7HYFbxrwtdKoh8ZbhzK0jU0+pwRtf3GPMjenZWut9Ey0BqrV9WEhiT31ueJy8ZY9aVxGKUPOHWfUztSeJl0Ni98/UQnuMv6x6LQdrw3dBQoLFc6IgKbKvsydxEwtC9r5zL1dgdAmxEcIY/CNYwDRJgSsAeLPYOinlctCCI5tuOZFT+OvCqrtF4zVoPkhbR7nrJnxSa8nRiZf3/UuJSAGC/E3/ZHj2zKPd7gZkWH7MDvN7ZnDU3IN3VYhN6WLMfyi/wX3ouFJlkJx9FdxdeRZxKhgVSVkisYDeI412bkZ6JSmV1qzBmDX5J8Rg5K+SEDWJZAYYKXgdhIxMkGz9EZfA1p6W9QpX9/kXsRuNYvBMAmIc294n8Nqmu7lZiaEVUcKVhFQaCnvpHJBNcHbif3hndp4RrDAot1hjAfJxnIglVnqIBifSVv+Vo3VWTQHuCbnA== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 73d99585-4abd-4355-00f3-08d4666dca79 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:SN2PR03MB1951; X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB1951;3:CEdkGpHcTfU55eczSm/FadXAhI0l2PbR5UUmGJIa7VVpNvn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Ko7F96FNzVAADBUeGwyi0ea5gZWd1m6RWh2h1W1qtPhPsHA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(275809806118684); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095060)(601004)(2401047)(5005006)(8121501046)(13023025)(13015025)(13017025)(13018025)(13024025)(3002001)(10201501046)(6055026)(6096035)(20161123565025)(20161123559025)(20161123561025)(20161123563025)(20161123556025);SRVR:SN2PR03MB1951;BCL:0;PCL:0;RULEID:(400006);SRVR:SN2PR03MB1951; X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB1951;4:TTRAZHbcE+2qwmnKEy2JSNofUaykNnVxLSs1BGA8oOmL5+mRRKIqBgGhrADhskQCMDNF3fPHuEAJQt124nFZz4kCF0hk76QJQZ/cmpdCQwG0XIjc0YoY3AKI2DWOsB1wZK3yK9KmAsE1roA3rJ8A8HauWx8GYSIHmkrLFRdIGyOUreE3p3u7610it7PIP3HXhAD7q9OUbIQZ0SB8rVI8tCqqPd/Dp9F42W5d2Gg5hYv+cjSinqivHzej6dj3WT718I5Yc7Ow43036n9AaUioT7VrxLJGgG+gQ5X7OqAlKO2ObPcs7t3/ZmXL5HNMzM4hn0E4Du00Tw8c8kH+RNaNHy1moYqZQUSzzX2Jm9GXJ0cOxlCaFtQG4/v/j5c/75Najz7mmQPg9UWBji4OE+xTsA7pb4p8q8ghN2ohJOs/wXV5eY2eYCNtZaFeiOct6no97kVkRIaXBv07XclVQsT351mAfDRmxmoP+3E8Qheh4IZaUexZc6dtEBkAwoQ03mqsvQAHDP0CUzENEUiZ1RTMMwKiEVFnWQaBVjLtaLLN1h2fp1RPLK59yGM+bofUsvnU4W2zMnxuiaLI6szSK3pePWY3Lm+7kHpVLoCHz978Vf1ggijCDoAcy5mb7Tg8gqgG/OnHEiG9jP1DF3NLF86tKzkRKztpz85EayFb5jNMKGe8H84H3zzFi/jlh/m0nzGy8tZ+lur/+kKxTj7slZ1o1fOl4IETp4cjaRfJMY2nr5NSTLifeRWrf/I3wqCwjWzdUSNdVyNb6Htk4IajzNJyLg== X-Forefront-PRVS: 02408926C4 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR03MB1951;23:XhQPGLFQnWDzV1FAgU3aWLiPTUKK8thS4NLEewm4S?= =?us-ascii?Q?luNns+Om82Et9UA+4bgCLD0JeM0UA3D9Z5tGPMfoknp77mpO5l8Yiyqqr2Kv?= =?us-ascii?Q?pFJFIooGPzzDKV9mygYNX6cWMTHOsqtECUyRk3Ksn7AZWytXWU3toeODgqBo?= =?us-ascii?Q?R1uvNWtqdJWFcX1WihL9kFkJBK5nLDsN5Zrw7gWrGXCN4wLGssyNLdBb7MIN?= =?us-ascii?Q?vvyfj1YbTKyhfke0/jRP17TB91ZS/SU2LXmU1AmPNVBhdtINfquoAoU8sLV3?= =?us-ascii?Q?0/sTnJQBE+eXsdr1lcu5XxGnVifn7Ze1TJbdE2n/WJZguvHMtphITwqlyBoN?= =?us-ascii?Q?NVHxfL03FVdU2zlbam5r5xlD+xTd7RgGI0gTXW/6+fGNP+Pkp8m7S9JOwwRK?= =?us-ascii?Q?nILD/jHrnWGRqpWt7uhK3q4Ar6g9GgQlSnLWgGLUIOUyPy2tmSolUCgEceeF?= =?us-ascii?Q?L/VdbjrlP4OGyreDdRYPrtV4IAw4zoBPJS9Qt1yAsHkd75TT7fRguf4BY39N?= =?us-ascii?Q?JFk4MK1zFTJUDJXZoc8C85NZ2U8cWLVelrfHEvAVt9/8SWdkdzk7ozkx7RzI?= =?us-ascii?Q?g2TVVB65FFUqFGhWu3to4hH+OcrgQkHB1kvWAO9jwp/Czj4WETqzV8bTs8XI?= =?us-ascii?Q?7uci2r1lb2pmu3AKr9z8atBTHfrgVyE0qbo5cGpqstZs50V1+qNUzVAm2udj?= =?us-ascii?Q?y/Z/5eiEbbghjLLMxkH3dOc+RQHj9LGU4fDMFTVUY44enlLKeVWhuybX/FBU?= =?us-ascii?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AkH+lMx/MRZwXJ0Nx4QSQx9J+ITQ9bXjqmcF0rRZKXphIWz6w6aWH0GOmmvRDjFEIJwNk6rVNeu82qFlZTCaBiq1BBmTGGkSfbpZPX34EpOJo5Gk8w5n/9yD8+LHFSf5vmqJR0RJvrJJ7hDW3lszNLqEQzkUss=;5:kAeOpgy9npxPdV3wbOHVN6Ugh4bKVRfUpeiguFwxbWsuhxaL01av9bWDQfJkai2JLKpPtkwsGl1WpmBCLS3b+XHkYJYzaiJ7Lb2Ej01xGsylMbGrnWCWYt9sjK22L5WCddv1t54dBqdZQwcwRg+lJGBONgYJTtQ0RkOwf4eIZ2It2e48h4crssUIk7iskHSu;24:8oWzk/vHMa42DFXy4IJIbfUnvx1n4zyyymWQbcwaOAYTMPNWXWVCdzXfIfQ/HCKrS0IETlV7nC4YfA6ZitsSPb8M/ZahA1BEoigmNbqsAYY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB1951;7:seTTg8K8vOL60d/GxoV7pRAarima0/lPfs1vaRf5WnBAQxLUYS/5Nnk8c7jr/QkOfc0iRMCzlYvFkklM/OLkJngbpqPmBRkDhpsPQ0cmOrW2XVtUSpO6Uiz9Q6a60JjM1pdy+9bAbgUzgaTLtiGB2aepJiY+rIvYzPW6LoLNTDXxXpHDcUpnQsCpD1SfM8Gy4NLWiJZzQTznzzNrddktEdLoSCVojk4x4H9Nipoi1EaS6F7R09cRdQG7o627+w4L8+dljf2Uo6Td8T9mQ180SqV1WJFT/CgiwCB5+5anjVymBdnxoNCZYIhs1IMkL2HGKlvfllqXt3v6cawMs+ncjg== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2017 21:55:09.8138 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB1951 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9624 Lines: 328 The DPIO driver registers with the fsl-mc bus to handle bus-related events for DPIO objects. Key responsibility is mapping I/O regions, setting up interrupt handlers, and calling the DPIO service initialization during probe. Signed-off-by: Roy Pledge Signed-off-by: Haiying Wang Signed-off-by: Stuart Yoder --- drivers/staging/fsl-mc/bus/dpio/Makefile | 2 +- drivers/staging/fsl-mc/bus/dpio/dpio-driver.c | 296 +++++++++++++++++++++++++ 2 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio-driver.c diff --git a/drivers/staging/fsl-mc/bus/dpio/Makefile b/drivers/staging/fsl-mc/bus/dpio/Makefile index 0778da7..837d330 100644 --- a/drivers/staging/fsl-mc/bus/dpio/Makefile +++ b/drivers/staging/fsl-mc/bus/dpio/Makefile @@ -6,4 +6,4 @@ subdir-ccflags-y := -Werror obj-$(CONFIG_FSL_MC_DPIO) += fsl-mc-dpio.o -fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o +fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o dpio-driver.o diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c new file mode 100644 index 0000000..e36da20 --- /dev/null +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c @@ -0,0 +1,296 @@ +/* + * Copyright 2014-2016 Freescale Semiconductor Inc. + * Copyright NXP 2016 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Freescale Semiconductor nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../include/mc.h" +#include "../../include/dpaa2-io.h" + +#include "qbman-portal.h" +#include "dpio.h" +#include "dpio-cmd.h" + +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_AUTHOR("Freescale Semiconductor, Inc"); +MODULE_DESCRIPTION("DPIO Driver"); + +struct dpio_priv { + struct dpaa2_io *io; +}; + +static irqreturn_t dpio_irq_handler(int irq_num, void *arg) +{ + struct device *dev = (struct device *)arg; + struct dpio_priv *priv = dev_get_drvdata(dev); + + return dpaa2_io_irq(priv->io); +} + +static void unregister_dpio_irq_handlers(struct fsl_mc_device *dpio_dev) +{ + struct fsl_mc_device_irq *irq; + + irq = dpio_dev->irqs[0]; + + /* clear the affinity hint */ + irq_set_affinity_hint(irq->msi_desc->irq, NULL); +} + +static int register_dpio_irq_handlers(struct fsl_mc_device *dpio_dev, int cpu) +{ + struct dpio_priv *priv; + int error; + struct fsl_mc_device_irq *irq; + cpumask_t mask; + + priv = dev_get_drvdata(&dpio_dev->dev); + + irq = dpio_dev->irqs[0]; + error = devm_request_irq(&dpio_dev->dev, + irq->msi_desc->irq, + dpio_irq_handler, + 0, + dev_name(&dpio_dev->dev), + &dpio_dev->dev); + if (error < 0) { + dev_err(&dpio_dev->dev, + "devm_request_irq() failed: %d\n", + error); + return error; + } + + /* set the affinity hint */ + cpumask_clear(&mask); + cpumask_set_cpu(cpu, &mask); + if (irq_set_affinity_hint(irq->msi_desc->irq, &mask)) + dev_err(&dpio_dev->dev, + "irq_set_affinity failed irq %d cpu %d\n", + irq->msi_desc->irq, cpu); + + return 0; +} + +static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) +{ + struct dpio_attr dpio_attrs; + struct dpaa2_io_desc desc; + struct dpio_priv *priv; + int err = -ENOMEM; + struct device *dev = &dpio_dev->dev; + static int next_cpu = -1; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + goto err_priv_alloc; + + dev_set_drvdata(dev, priv); + + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io); + if (err) { + dev_dbg(dev, "MC portal allocation failed\n"); + err = -EPROBE_DEFER; + goto err_mcportal; + } + + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id, + &dpio_dev->mc_handle); + if (err) { + dev_err(dev, "dpio_open() failed\n"); + goto err_open; + } + + err = dpio_get_attributes(dpio_dev->mc_io, 0, dpio_dev->mc_handle, + &dpio_attrs); + if (err) { + dev_err(dev, "dpio_get_attributes() failed %d\n", err); + goto err_get_attr; + } + desc.qman_version = dpio_attrs.qbman_version; + + err = dpio_enable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + if (err) { + dev_err(dev, "dpio_enable() failed %d\n", err); + goto err_get_attr; + } + + /* initialize DPIO descriptor */ + desc.receives_notifications = dpio_attrs.num_priorities ? 1 : 0; + desc.has_8prio = dpio_attrs.num_priorities == 8 ? 1 : 0; + desc.dpio_id = dpio_dev->obj_desc.id; + + /* get the cpu to use for the affinity hint */ + if (next_cpu == -1) + next_cpu = cpumask_first(cpu_online_mask); + else + next_cpu = cpumask_next(next_cpu, cpu_online_mask); + + if (!cpu_possible(next_cpu)) { + dev_err(dev, "probe failed. Number of DPIOs exceeds NR_CPUS.\n"); + err = -ERANGE; + goto err_allocate_irqs; + } + desc.cpu = next_cpu; + + /* + * Set the CENA regs to be the cache inhibited area of the portal to + * avoid coherency issues if a user migrates to another core. + */ + desc.regs_cena = ioremap_wc(dpio_dev->regions[1].start, + resource_size(&dpio_dev->regions[1])); + desc.regs_cinh = ioremap(dpio_dev->regions[1].start, + resource_size(&dpio_dev->regions[1])); + + err = fsl_mc_allocate_irqs(dpio_dev); + if (err) { + dev_err(dev, "fsl_mc_allocate_irqs failed. err=%d\n", err); + goto err_allocate_irqs; + } + + err = register_dpio_irq_handlers(dpio_dev, desc.cpu); + if (err) + goto err_register_dpio_irq; + + priv->io = dpaa2_io_create(&desc); + if (!priv->io) { + dev_err(dev, "dpaa2_io_create failed\n"); + goto err_dpaa2_io_create; + } + + dev_info(dev, "probed\n"); + dev_dbg(dev, " receives_notifications = %d\n", + desc.receives_notifications); + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + fsl_mc_portal_free(dpio_dev->mc_io); + + return 0; + +err_dpaa2_io_create: + unregister_dpio_irq_handlers(dpio_dev); +err_register_dpio_irq: + fsl_mc_free_irqs(dpio_dev); +err_allocate_irqs: + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); +err_get_attr: + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); +err_open: + fsl_mc_portal_free(dpio_dev->mc_io); +err_mcportal: + dev_set_drvdata(dev, NULL); +err_priv_alloc: + return err; +} + +/* Tear down interrupts for a given DPIO object */ +static void dpio_teardown_irqs(struct fsl_mc_device *dpio_dev) +{ + unregister_dpio_irq_handlers(dpio_dev); + fsl_mc_free_irqs(dpio_dev); +} + +static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev) +{ + struct device *dev; + struct dpio_priv *priv; + int err; + + dev = &dpio_dev->dev; + priv = dev_get_drvdata(dev); + + dpaa2_io_down(priv->io); + + dpio_teardown_irqs(dpio_dev); + + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io); + if (err) { + dev_err(dev, "MC portal allocation failed\n"); + goto err_mcportal; + } + + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id, + &dpio_dev->mc_handle); + if (err) { + dev_err(dev, "dpio_open() failed\n"); + goto err_open; + } + + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + + fsl_mc_portal_free(dpio_dev->mc_io); + + dev_set_drvdata(dev, NULL); + + return 0; + +err_open: + fsl_mc_portal_free(dpio_dev->mc_io); +err_mcportal: + return err; +} + +static const struct fsl_mc_device_id dpaa2_dpio_match_id_table[] = { + { + .vendor = FSL_MC_VENDOR_FREESCALE, + .obj_type = "dpio", + }, + { .vendor = 0x0 } +}; + +static struct fsl_mc_driver dpaa2_dpio_driver = { + .driver = { + .name = KBUILD_MODNAME, + .owner = THIS_MODULE, + }, + .probe = dpaa2_dpio_probe, + .remove = dpaa2_dpio_remove, + .match_id_table = dpaa2_dpio_match_id_table +}; + +static int dpio_driver_init(void) +{ + return fsl_mc_driver_register(&dpaa2_dpio_driver); +} + +static void dpio_driver_exit(void) +{ + fsl_mc_driver_unregister(&dpaa2_dpio_driver); +} +module_init(dpio_driver_init); +module_exit(dpio_driver_exit); -- 1.7.9.5