From patchwork Fri Feb 11 16:26:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 12743629 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98B58C4332F for ; Fri, 11 Feb 2022 16:27:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235564AbiBKQ1d (ORCPT ); Fri, 11 Feb 2022 11:27:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244685AbiBKQ1a (ORCPT ); Fri, 11 Feb 2022 11:27:30 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2061.outbound.protection.outlook.com [40.107.93.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AA5B3B0; Fri, 11 Feb 2022 08:27:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MsBd9tEfyQ9RBevuljecYHaL60YkWDGRLS1d+/k5z64GPw8+gGadtmW7VrHboL274S4dFJw2lYOUfr8fzaO0cxI4BY0YPEYGpzc7sLd8MtsPTxgtw/Lvr+O4B8RpWbpyya6BsPPEWSL0ENmr1E8SA3juiUP/lmqfKdzki6jYEJEtFgZQRXl1vh0odl+nYBsgOnOT5Zsi6aB+vYqfRPkAn/rZjY13OJfX6lLezWS8soclA1KV9niP5PMgDpohLUyXqER6wxSdQP/LQNc4+sBEG3VNr/3F+RJFVM8n9gK7RfbV6hcHVt3O3ykB6wHej//reLPWVyTLeHO2YOfe1jbFsQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E29EQU/4o7BCp/2H38+YLXVSDBSxcJY/BaocP9NI1vY=; b=Co0jUoKtuGKqIFc5zozwbRfmWKsaQxK0r4OS4a74ovzDoO1/bBDkJZrqfzId6YJGtrMTIUcI62dptaudsOlGqkFti/2J/r9vQbTJ1gYB+kZl+reipwO3EDQhWbm09bEFSCBNm4pLyg133ZbIXr/xGzFg2aznMb425x/RpwMzsAFCTPrdMXsG/CyQTtx/jGDjNZ1IHiLlzJ6KM+biKrnU6nweKnXWeNjEaXVwWFN0gTaaQoJRyGCDxpckAhrLOqxN348kQP7ZLvEAfNLurTFYZy3Rmfxc7Nc6jl4cpYMaiCMmGv/G4DfbLKn6ZyDyTRRAh/u449QWeQVDjlegecEQug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.onmicrosoft.com; s=selector2-silabs-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E29EQU/4o7BCp/2H38+YLXVSDBSxcJY/BaocP9NI1vY=; b=cl/KyfTlKD7lOnCin+E35cR36Mi69gdwWmCpMm5orBXLS85zgM9npqxxwJD+z4qBC23y2t4wZmjFrM1F84JyC5zcu1Zx0GApK4BN9j85lquVkd5IqARe6yfyZUPhrMc9P8cclusQHjSOl/1Wk5dv9AYx8Tff/LVyiL9z4SSJAeA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=silabs.com; Received: from PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) by BN6PR1101MB2196.namprd11.prod.outlook.com (2603:10b6:405:52::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Fri, 11 Feb 2022 16:27:27 +0000 Received: from PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::1b3:e483:7396:1f98]) by PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::1b3:e483:7396:1f98%3]) with mapi id 15.20.4975.014; Fri, 11 Feb 2022 16:27:26 +0000 From: Jerome Pouiller To: devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH 1/2] staging: wfx: allow new PDS format Date: Fri, 11 Feb 2022 17:26:58 +0100 Message-Id: <20220211162659.528333-2-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220211162659.528333-1-Jerome.Pouiller@silabs.com> References: <20220211162659.528333-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: PR1P264CA0011.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:19e::16) To PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2740a1e2-0bde-400b-4f1a-08d9ed7b63ef X-MS-TrafficTypeDiagnostic: BN6PR1101MB2196:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GT11tUA8llhitGfbWKgzWYOzQYrkWh3bvrjGTVHFoRdw2sIUq5f8Eo19N+I3X+je6NCEVoRf/8BybZlVcxTR+aN+UghvpTOCg+Mi07UrCjyFt/ZCYhp3bPam5r7tCNpqERZt3GvqWKl/qo2K1OMIiw/+Ok6euLrujg10qwJ9jdpOAHmUZ3Ffpx1NB17LvenkRz2kbt1iM6BWdhZ82Rbi/xhzWwsijdFAy7ZWaX6PRScOJd8mIVFpbgqTfbjMk4eHgfNM6urnXZoPJL5lckppUrxa45ZzHEb3Mw44KmaaYcW+/8SbZ/KPYYKCexGi4yqYEOd6OtdCvjGo01ihdTWjvEN7wAyXCeDRQ/PRb5/tW6JwKFh0tEKCIlzByWoB3CGQGIAaE4gJncRTVqAvPUMK0rSZUtHvkj+MdstwIx9FR56Io4sh93VLmBAre2k6owNIlhPKWkmrC391cUhW065zUf+Bd5IXZEq3c+ZrAtg/yb/B6WEoNt9OaTrG7MzucWYAAKVtfTqOXkpe2+spGxRXx6+r7PzVUQGK17TSOYkVjR8Jn0/OTtEjHhF9yGmrlXHKrpl2BuzYEi4D0E6dBMSCGlDckKeT00riQ7uaSzys9vluLIUqwdbcj7tl4h6PShy52+6N29Df1sH7VASFPXO9zbTN88Pfvy0YoGPxCo3RWc8Q65YilMu0Au/t3W6yUfwGUPgy/m58X24Ge2rlokf+7U8p9pGif/Oe9Hwy/HChug/gKUQITYRhWjwdqmU352+UCJ9BdELRw6RB8bRXu8oErdkO2V1bOIDus3ECskf1dDU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR11MB5657.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(186003)(26005)(86362001)(4326008)(36756003)(84970400001)(66476007)(83380400001)(508600001)(8936002)(66946007)(8676002)(66556008)(1076003)(2616005)(38100700002)(54906003)(38350700002)(966005)(6512007)(316002)(5660300002)(66574015)(52116002)(2906002)(6666004)(6506007)(6486002)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?+mdaiTthcwI/DWVQh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cGVEjl/naPRfSjmXi7gcC5OwkndQLQx3WDDjPbf/9MNfKE+wBPTnXOl?= =?utf-8?q?0wtKlKr0HsPyUUosqWjZDaSPkMordO9am6R84NEhKcqc2ChrjBeHJXVSH3HiPFfBu?= =?utf-8?q?bzrec6fBDgiOhYAwcGSOw8BuI24MXXaso8j3J/YTBkxVZ35dblif95/KS80f7Aq5G?= =?utf-8?q?M1nMsfXt5nuamEG8AWMsV2/Fot++8ElKiORNxjAyfyUiM/f54csYpCzGDGCfCCQ8l?= =?utf-8?q?FMsywGg8jzwz7j5nYpQN/Nip85GTAkqtiAt8ErHwkgnX5WXgp34LdenwpgtBWXAX6?= =?utf-8?q?X/0iz3vsUVbxKhJKe8iaBeZ/xE7M0bB1Y43KCMapbLiuIxgGseGfFVuBkDq2/tPkP?= =?utf-8?q?F69xaHr2GyXJfKDs5+BlRb0s0XhtwWDtYbmPIy9UiOZ1QoPgCMZ8g2x4R4W0RHMDf?= =?utf-8?q?j1S1braxszXF6DI3vggJGRtlzmW/zD1yoyh+RH2xCu8JB37Nsayr21b6+X9YNUubw?= =?utf-8?q?x9HLB6G4s68ABegEwV3hEiRgqYp2zX6t0j925T6bd84ChVHPVgQMyEycU+MMuh0gO?= =?utf-8?q?Jvy/av8dxTS9kD/YQRRRyjmlAJHb9frP3TG8Wf3T2l+qWYRTLXX32ta1cjVFHS0Dd?= =?utf-8?q?tmXEqHpryEto/WSaVaGXLCuikuPaCaAolYo5ktYIuOf7lsY0jjne6bk=3D?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2740a1e2-0bde-400b-4f1a-08d9ed7b63ef X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5657.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2022 16:27:26.5054 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: z2MAxIBJXBtIefiyQ+DFxoyjDtuc6aUr36eqH9WOGmqtV68m6kIHLU7AmVzB3hJ/znt7armGUZ7KAerL9GKZaA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1101MB2196 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jérôme Pouiller The device needs data about the antenna configuration. This information in provided by PDS (Platform Data Set, this is the wording used in WF200 documentation) files. Until now, the driver had to parse the PDS file before to send it. This solution was not acceptable for the vanilla kernel. We have slightly changed the PDS format so it is now an array of Type-Length-Value. This patch allows to support new format and keep compatibility with legacy format. probe: allow new PDS format Signed-off-by: Jérôme Pouiller --- drivers/staging/wfx/main.c | 74 +++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/drivers/staging/wfx/main.c b/drivers/staging/wfx/main.c index 8be9100847a7..a0f5e09c3c3f 100644 --- a/drivers/staging/wfx/main.c +++ b/drivers/staging/wfx/main.c @@ -33,7 +33,8 @@ #include "hif_tx_mib.h" #include "hif_api_cmd.h" -#define WFX_PDS_MAX_SIZE 1500 +#define WFX_PDS_TLV_TYPE 0x4450 // "PD" (Platform Data) in ascii little-endian +#define WFX_PDS_MAX_CHUNK_SIZE 1500 MODULE_DESCRIPTION("Silicon Labs 802.11 Wireless LAN driver for WF200"); MODULE_AUTHOR("Jérôme Pouiller "); @@ -162,29 +163,18 @@ bool wfx_api_older_than(struct wfx_dev *wdev, int major, int minor) return false; } -/* The device needs data about the antenna configuration. This information in provided by PDS - * (Platform Data Set, this is the wording used in WF200 documentation) files. For hardware - * integrators, the full process to create PDS files is described here: - * https:github.com/SiliconLabs/wfx-firmware/blob/master/PDS/README.md - * - * So this function aims to send PDS to the device. However, the PDS file is often bigger than Rx - * buffers of the chip, so it has to be sent in multiple parts. +/* In legacy format, the PDS file is often bigger than Rx buffers of the chip, so it has to be sent + * in multiple parts. * * In add, the PDS data cannot be split anywhere. The PDS files contains tree structures. Braces are * used to enter/leave a level of the tree (in a JSON fashion). PDS files can only been split * between root nodes. */ -int wfx_send_pds(struct wfx_dev *wdev, u8 *buf, size_t len) +int wfx_send_pds_legacy(struct wfx_dev *wdev, u8 *buf, size_t len) { int ret; - int start, brace_level, i; + int start = 0, brace_level = 0, i; - start = 0; - brace_level = 0; - if (buf[0] != '{') { - dev_err(wdev->dev, "valid PDS start with '{'. Did you forget to compress it?\n"); - return -EINVAL; - } for (i = 1; i < len - 1; i++) { if (buf[i] == '{') brace_level++; @@ -192,7 +182,7 @@ int wfx_send_pds(struct wfx_dev *wdev, u8 *buf, size_t len) brace_level--; if (buf[i] == '}' && !brace_level) { i++; - if (i - start + 1 > WFX_PDS_MAX_SIZE) + if (i - start + 1 > WFX_PDS_MAX_CHUNK_SIZE) return -EFBIG; buf[start] = '{'; buf[i] = 0; @@ -222,6 +212,56 @@ int wfx_send_pds(struct wfx_dev *wdev, u8 *buf, size_t len) return 0; } +/* The device needs data about the antenna configuration. This information in provided by PDS + * (Platform Data Set, this is the wording used in WF200 documentation) files. For hardware + * integrators, the full process to create PDS files is described here: + * https://github.com/SiliconLabs/wfx-firmware/blob/master/PDS/README.md + * + * The PDS file is an array of Time-Length-Value structs. + */ + int wfx_send_pds(struct wfx_dev *wdev, u8 *buf, size_t len) +{ + int ret, chunk_type, chunk_len, chunk_num = 0; + + if (*buf == '{') + return wfx_send_pds_legacy(wdev, buf, len); + while (len > 0) { + chunk_type = get_unaligned_le16(buf + 0); + chunk_len = get_unaligned_le16(buf + 2); + if (chunk_len > len) { + dev_err(wdev->dev, "PDS:%d: corrupted file\n", chunk_num); + return -EINVAL; + } + if (chunk_type != WFX_PDS_TLV_TYPE) { + dev_info(wdev->dev, "PDS:%d: skip unknown data\n", chunk_num); + goto next; + } + if (chunk_len > WFX_PDS_MAX_CHUNK_SIZE) + dev_warn(wdev->dev, "PDS:%d: unexpectly large chunk\n", chunk_num); + if (buf[4] != '{' || buf[chunk_len - 1] != '}') + dev_warn(wdev->dev, "PDS:%d: unexpected content\n", chunk_num); + + ret = wfx_hif_configuration(wdev, buf + 4, chunk_len - 4); + if (ret > 0) { + dev_err(wdev->dev, "PDS:%d: invalid data (unsupported options?)\n", chunk_num); + return -EINVAL; + } + if (ret == -ETIMEDOUT) { + dev_err(wdev->dev, "PDS:%d: chip didn't reply (corrupted file?)\n", chunk_num); + return ret; + } + if (ret) { + dev_err(wdev->dev, "PDS:%d: chip returned an unknown error\n", chunk_num); + return -EIO; + } +next: + chunk_num++; + len -= chunk_len; + buf += chunk_len; + } + return 0; +} + static int wfx_send_pdata_pds(struct wfx_dev *wdev) { int ret = 0;