From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1AC7C76190 for ; Sat, 27 Jul 2019 08:34:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B66202084C for ; Sat, 27 Jul 2019 08:34:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=xilinx.onmicrosoft.com header.i=@xilinx.onmicrosoft.com header.b="aUViqzof" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728664AbfG0IeH (ORCPT ); Sat, 27 Jul 2019 04:34:07 -0400 Received: from mail-eopbgr730074.outbound.protection.outlook.com ([40.107.73.74]:26186 "EHLO NAM05-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728596AbfG0IeH (ORCPT ); Sat, 27 Jul 2019 04:34:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NW3WC3cagRT3TrlwffGGbc84nZmBFQT2KSHq20IOm0BmNFWTHRxwXYozfkZ+tpu+givM1ndpCoSmSr9VXL4crIcPbPxEIU1Q/mQY4vhtQs9u5RB78hHbPBNr8yimGqiOsgYZsi3xnI9fg0D1RBq+yqZRpOTa6p4neLPJFWlXJ91TRNMtP9wgOstRIo6aXXPXatUbOaefU5C7aPU/BWDtGRHd7DVNnSPjI3ikFzae+9b3Ob/uVaJ86Isa5cTJDmTx2trCbxfjmu14Kl80q7gYxZTglitBvnHN6MBpXe6CbVWRl+4SexH3yRBrlDpd0Ogddf+NcHGUEuJV2Vq7rvplLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6TgtB0NlbbSswtxFVpF/K7CO2OY9Can9ybl2a7q6v8w=; b=lPz4DyOXWaKytFUy5wTUH7B/6ox6ZCclWARXyN0frbxrbbGw1ceHybSSDv90H4RTmHisPc8skRSc2KNhWhnZP5BG7pB1YKYJ7f+/YzF2Q5gi/oZEjvtx94VToCYWEj9Hd2BUwSxnJ2DsiHR9GSTvcQ3dblQEbczQ57geQQSbBgc0TQG5z4EVecD5XK/dmSElI3cLSsBk7Q5oRNiY3/Zy0nTTeEr8AdkSdqkwsBiiy6sHXaCEfl2AUpey1viXY+OpGJSFDI3lQH6FfUtkTbJLbsPLo2JSH0667VO3HJqIFx8jpt2y5W9Sw0yEPoq7Zpa+gBd7enUVIAsyib+n+IjQdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=pass (sender ip is 149.199.80.198) smtp.rcpttodomain=arndb.de smtp.mailfrom=xilinx.com;dmarc=bestguesspass action=none header.from=xilinx.com;dkim=none (message not signed);arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6TgtB0NlbbSswtxFVpF/K7CO2OY9Can9ybl2a7q6v8w=; b=aUViqzofrmbD15dDrzbdcrf6fqCCbsDb9VXLY6LFqFX82Pkl/r3cIPQ+gK9YD+K4qEpzidLZ1MYPS0/Wq3isZ9y59ji08zXMHvhVYHVCVWJ0uIN1chOWnEGnSnmzH0z685Knz3DXqau/T89a1zdJBuwxNqOJGBXnJJsr1LWmpNI= Received: from DM6PR02CA0047.namprd02.prod.outlook.com (2603:10b6:5:177::24) by SN6PR02MB4765.namprd02.prod.outlook.com (2603:10b6:805:90::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.10; Sat, 27 Jul 2019 08:34:04 +0000 Received: from BL2NAM02FT025.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::204) by DM6PR02CA0047.outlook.office365.com (2603:10b6:5:177::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2115.10 via Frontend Transport; Sat, 27 Jul 2019 08:34:04 +0000 Authentication-Results: spf=pass (sender IP is 149.199.80.198) smtp.mailfrom=xilinx.com; arndb.de; dkim=none (message not signed) header.d=none;arndb.de; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.80.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.80.198; helo=xir-pvapexch01.xlnx.xilinx.com; Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by BL2NAM02FT025.mail.protection.outlook.com (10.152.77.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2115.10 via Frontend Transport; Sat, 27 Jul 2019 08:34:03 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1531.3; Sat, 27 Jul 2019 09:33:59 +0100 Received: from smtp.xilinx.com (172.21.105.197) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server id 15.1.1531.3 via Frontend Transport; Sat, 27 Jul 2019 09:33:59 +0100 Envelope-to: arnd@arndb.de, gregkh@linuxfoundation.org, michal.simek@xilinx.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dragan.cvetic@xilinx.com, derek.kiernan@xilinx.com Received: from [149.199.110.15] (port=40508 helo=xirdraganc40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1hrI9P-00027X-St; Sat, 27 Jul 2019 09:33:59 +0100 From: Dragan Cvetic To: , , , CC: , Dragan Cvetic , Derek Kiernan Subject: [PATCH V9 2/8] misc: xilinx_sdfec: Add ability to configure turbo Date: Sat, 27 Jul 2019 09:33:52 +0100 Message-ID: <1564216438-322406-3-git-send-email-dragan.cvetic@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1564216438-322406-1-git-send-email-dragan.cvetic@xilinx.com> References: <1564216438-322406-1-git-send-email-dragan.cvetic@xilinx.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.80.198;IPV:CAL;CTRY:IE;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(39860400002)(136003)(346002)(396003)(376002)(2980300002)(189003)(199004)(50226002)(186003)(2201001)(426003)(478600001)(14444005)(11346002)(336012)(956004)(28376004)(316002)(5660300002)(476003)(2616005)(60926002)(106002)(8676002)(126002)(47776003)(110136005)(4326008)(446003)(8936002)(305945005)(486006)(54906003)(2906002)(36906005)(71366001)(16586007)(70206006)(44832011)(51416003)(7696005)(76130400001)(107886003)(9786002)(76176011)(6666004)(26005)(36756003)(246002)(48376002)(70586007)(356004)(7636002)(50466002)(26826003)(102446001)(461764006);DIR:OUT;SFP:1101;SCL:1;SRVR:SN6PR02MB4765;H:xir-pvapexch01.xlnx.xilinx.com;FPR:;SPF:Pass;LANG:en;PTR:unknown-80-198.xilinx.com;MX:1;A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cf6d4fda-f707-4a34-2bac-08d7126d2ebc X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(4709080)(1401327)(2017052603328);SRVR:SN6PR02MB4765; X-MS-TrafficTypeDiagnostic: SN6PR02MB4765: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-Forefront-PRVS: 01110342A5 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: nFq2dJ3Qs5RcOUuLPflhHRsvrZRlL1nZFS827gMG6T7tLP5gtApGKwUUrGZQodqp7r3QZHjnsT+cTy7mluZyQ4WENoeXWoT7yYjynxvMunDgwkkQsswIoOjiVchUsDuDLY3kkuSxx3GuW/qr+qR7E0ig8hmSIbk9tmhISaxfQJ6JPgWjyB5tp1mzIzAi0KivS40dkVbuU4LMTkKeuKLRkFthNtA05R30kfT7PyBFJ8O8VxGjCus00IGh1xzSv+pUqmAKphQ5pXvExVTu3h5bUAm9o0qZe6jnpFai5JPSVgH2zTqyZQH/HmJjPoSozscVL9C+9ExCsSlUYX4skJKxnjyn5kXAVMMlfe4EFMSvIpwZPNPb+LILVmY2EwpJHxLbzBm9vRl+9WK2Zp5CqGvA2nHG+qNc+mioRwLkEmP3cHI= X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2019 08:34:03.9402 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cf6d4fda-f707-4a34-2bac-08d7126d2ebc X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.80.198];Helo=[xir-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB4765 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the capability to configure and retrieve turbo mode via the ioctls XSDFEC_SET_TURBO and XSDFEC_GET_TURBO. Add char device interface per DT node present and support file operations: - open(), - close(), - unlocked_ioctl(), - compat_ioctl(). Tested-by: Dragan Cvetic Signed-off-by: Derek Kiernan Signed-off-by: Dragan Cvetic --- drivers/misc/xilinx_sdfec.c | 110 +++++++++++++++++++++++++++++++++++++++ include/uapi/misc/xilinx_sdfec.h | 67 ++++++++++++++++++++++++ 2 files changed, 177 insertions(+) diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c index 24d9f79..d3dba7e 100644 --- a/drivers/misc/xilinx_sdfec.c +++ b/drivers/misc/xilinx_sdfec.c @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -106,6 +107,12 @@ static struct mutex dev_idr_lock; /* BYPASS Register */ #define XSDFEC_BYPASS_ADDR (0x3C) +/* Turbo Code Register */ +#define XSDFEC_TURBO_ADDR (0x100) +#define XSDFEC_TURBO_SCALE_MASK (0xFFF) +#define XSDFEC_TURBO_SCALE_BIT_POS (8) +#define XSDFEC_TURBO_SCALE_MAX (15) + /** * struct xsdfec_clks - For managing SD-FEC clocks * @core_clk: Main processing clock for core @@ -214,6 +221,55 @@ static void update_config_from_hw(struct xsdfec_dev *xsdfec) xsdfec->state = XSDFEC_STOPPED; } +static int xsdfec_set_turbo(struct xsdfec_dev *xsdfec, void __user *arg) +{ + struct xsdfec_turbo turbo; + int err; + u32 turbo_write; + + err = copy_from_user(&turbo, arg, sizeof(turbo)); + if (err) + return -EFAULT; + + if (turbo.alg >= XSDFEC_TURBO_ALG_MAX) + return -EINVAL; + + if (turbo.scale > XSDFEC_TURBO_SCALE_MAX) + return -EINVAL; + + /* Check to see what device tree says about the FEC codes */ + if (xsdfec->config.code == XSDFEC_LDPC_CODE) + return -EIO; + + turbo_write = ((turbo.scale & XSDFEC_TURBO_SCALE_MASK) + << XSDFEC_TURBO_SCALE_BIT_POS) | + turbo.alg; + xsdfec_regwrite(xsdfec, XSDFEC_TURBO_ADDR, turbo_write); + return err; +} + +static int xsdfec_get_turbo(struct xsdfec_dev *xsdfec, void __user *arg) +{ + u32 reg_value; + struct xsdfec_turbo turbo_params; + int err; + + if (xsdfec->config.code == XSDFEC_LDPC_CODE) + return -EIO; + + reg_value = xsdfec_regread(xsdfec, XSDFEC_TURBO_ADDR); + + turbo_params.scale = (reg_value & XSDFEC_TURBO_SCALE_MASK) >> + XSDFEC_TURBO_SCALE_BIT_POS; + turbo_params.alg = reg_value & 0x1; + + err = copy_to_user(arg, &turbo_params, sizeof(turbo_params)); + if (err) + err = -EFAULT; + + return err; +} + static u32 xsdfec_translate_axis_width_cfg_val(enum xsdfec_axis_width axis_width_cfg) { @@ -277,8 +333,62 @@ static int xsdfec_cfg_axi_streams(struct xsdfec_dev *xsdfec) return 0; } +static int xsdfec_dev_open(struct inode *iptr, struct file *fptr) +{ + return 0; +} + +static int xsdfec_dev_release(struct inode *iptr, struct file *fptr) +{ + return 0; +} + +static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd, + unsigned long data) +{ + struct xsdfec_dev *xsdfec; + void __user *arg = NULL; + int rval = -EINVAL; + + xsdfec = container_of(fptr->private_data, struct xsdfec_dev, miscdev); + + /* check if ioctl argument is present and valid */ + if (_IOC_DIR(cmd) != _IOC_NONE) { + arg = (void __user *)data; + if (!arg) + return rval; + } + + switch (cmd) { + case XSDFEC_SET_TURBO: + rval = xsdfec_set_turbo(xsdfec, arg); + break; + case XSDFEC_GET_TURBO: + rval = xsdfec_get_turbo(xsdfec, arg); + break; + default: + /* Should not get here */ + break; + } + return rval; +} + +#ifdef CONFIG_COMPAT +static long xsdfec_dev_compat_ioctl(struct file *file, unsigned int cmd, + unsigned long data) +{ + return xsdfec_dev_ioctl(file, cmd, (unsigned long)compat_ptr(data)); +} +#endif + static const struct file_operations xsdfec_fops = { .owner = THIS_MODULE, + .open = xsdfec_dev_open, + .release = xsdfec_dev_release, + .unlocked_ioctl = xsdfec_dev_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = xsdfec_dev_compat_ioctl, +#endif }; static int xsdfec_parse_of(struct xsdfec_dev *xsdfec) diff --git a/include/uapi/misc/xilinx_sdfec.h b/include/uapi/misc/xilinx_sdfec.h index 330ea25..34f32c3 100644 --- a/include/uapi/misc/xilinx_sdfec.h +++ b/include/uapi/misc/xilinx_sdfec.h @@ -41,6 +41,22 @@ enum xsdfec_order { }; /** + * enum xsdfec_turbo_alg - Turbo Algorithm Type. + * @XSDFEC_MAX_SCALE: Max Log-Map algorithm with extrinsic scaling. When + * scaling is set to this is equivalent to the Max Log-Map + * algorithm. + * @XSDFEC_MAX_STAR: Log-Map algorithm. + * @XSDFEC_TURBO_ALG_MAX: Used to indicate out of bound Turbo algorithms. + * + * This enum specifies which Turbo Decode algorithm is in use. + */ +enum xsdfec_turbo_alg { + XSDFEC_MAX_SCALE = 0, + XSDFEC_MAX_STAR, + XSDFEC_TURBO_ALG_MAX, +}; + +/** * enum xsdfec_state - State. * @XSDFEC_INIT: Driver is initialized. * @XSDFEC_STARTED: Driver is started. @@ -98,6 +114,29 @@ enum xsdfec_axis_word_include { }; /** + * struct xsdfec_turbo - User data for Turbo codes. + * @alg: Specifies which Turbo decode algorithm to use + * @scale: Specifies the extrinsic scaling to apply when the Max Scale algorithm + * has been selected + * + * Turbo code structure to communicate parameters to XSDFEC driver. + */ +struct xsdfec_turbo { + __u32 alg; + __u8 scale; +}; + +/** + * struct xsdfec_status - Status of SD-FEC core. + * @state: State of the SD-FEC core + * @activity: Describes if the SD-FEC instance is Active + */ +struct xsdfec_status { + __u32 state; + __s8 activity; +}; + +/** * struct xsdfec_irq - Enabling or Disabling Interrupts. * @enable_isr: If true enables the ISR * @enable_ecc_isr: If true enables the ECC ISR @@ -135,4 +174,32 @@ struct xsdfec_config { * XSDFEC IOCTL List */ #define XSDFEC_MAGIC 'f' +/** + * DOC: XSDFEC_SET_TURBO + * @Parameters + * + * @struct xsdfec_turbo * + * Pointer to the &struct xsdfec_turbo that contains the Turbo decode + * settings for the SD-FEC core + * + * @Description + * + * ioctl that sets the SD-FEC Turbo parameter values + * + * This can only be used when the driver is in the XSDFEC_STOPPED state + */ +#define XSDFEC_SET_TURBO _IOW(XSDFEC_MAGIC, 4, struct xsdfec_turbo) +/** + * DOC: XSDFEC_GET_TURBO + * @Parameters + * + * @struct xsdfec_turbo * + * Pointer to the &struct xsdfec_turbo that contains the current Turbo + * decode settings of the SD-FEC Block + * + * @Description + * + * ioctl that returns SD-FEC turbo param values + */ +#define XSDFEC_GET_TURBO _IOR(XSDFEC_MAGIC, 7, struct xsdfec_turbo) #endif /* __XILINX_SDFEC_H__ */ -- 2.7.4