From nobody Tue Sep 29 07:41:36 2026 Received: from OS8PR02CU002.outbound.protection.outlook.com (mail-japanwestazon11012060.outbound.protection.outlook.com [40.107.75.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9FFA37E5E5; Tue, 11 Aug 2026 06:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.75.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428362; cv=fail; b=HzmQp6QyICO/gy6EF3BzlSnK5KB4/5wDTPTYrvwMx5iJblqwqIPLaf7i/AQHUdSmB0uk2nr/u+EkIJWebqQ+Ij6xcSurLkJTeHwhGxKWrbUdPIs+JOdLrd5ckOxyleEID1I59779gCbbfSIbzhcAB9bxJdA51fXz5Fs0eMjapDY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428362; c=relaxed/simple; bh=hu1zmkiTuRHr+ewBmTDK4GBEgTmB2Jq7s1eaVbYi1qE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=gaTt/Mn3HOqiYjItxxKkfRZUgvtd7V2Fr7/cLqk81OJeEbzlags/jXrN7GeeaupcCXiEIj/4/4dWZv0wa+cDhqffyOQJLj9GtM1trrcwV8tBBo9KWmMnn5a9min/VXVI3qW1OOr5cE68CUugOUY5zpMCYNmbgdMNKxD53OQ2PUo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com; spf=pass smtp.mailfrom=moxa.com; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b=BapDemJt; arc=fail smtp.client-ip=40.107.75.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=moxa.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b="BapDemJt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Do2sDgBxQI97vKzEZAnuVeTUowSd2y5XpdvBVvZXAoWgwcHpJndISXmJMcgpKns7YJL9tcqgLp81pZlKS5StsPZCb0H0PqVwFdgUdp+8unmjBwXjOZ6ynHNHTJ/LKow+gkGadjVYOYIHBHRnPwDrcc7jNpp0C669X8oY5+UDqVm5DUh+RAemZ0uxRouBX3U4yd/0Z0fZhPTncDb83eI5XpY6LUDXiQ7tl9Y3FZezus48bgyh2jPVo2iiDLH0TWKwOQZxVjLZDE7mBvEFeiHRp3C5+LePBRBkZ2J1OxbPJIx6z0xJRKGQ+AxEt/GHLs/pxvrFlGFhm6SI1KFXXvS2PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=BPsC10oovsK3OEFbW5LPxy7lnf+G05pgzjZsAflmZyA=; b=Vr7fxcTLnBkCNjgkBuuRQ9zDtoQWC48W4A6T0DC2/SbFvssXzvKHgL3J6guOqf7TAvP5KMwQWiyhVJFOZQXHPP10htNSBg2HBoX3xLxfTfBPmtFtYuwEdYgRy1gmbiVkEimDwEZndFB8G1NxrBA6QaEKf61JOir9mAHAZ7NtyvsLo7L+hfvjDWRMJv5cU4r0bYN4N6tlfoZWCtbMDFVa0lSW3y9dCxWBxXIhFY/RASLyKwXxtx23CM8sp7ISKLvUK1IMsFL+xf6evcM21mJWsH98kWZcFPk49CtzgA+Eg6T3rBzWu/WR9EWQPt8O+UX0S0q5F6+ZaB33p3SAr0ND7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=moxa.com; dmarc=pass action=none header.from=moxa.com; dkim=pass header.d=moxa.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=moxa.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BPsC10oovsK3OEFbW5LPxy7lnf+G05pgzjZsAflmZyA=; b=BapDemJtf3cqJo5qUD8AQ+rwUf7bAV7y1/35w/r2yQoMY/W8oQc57uIM+MWyZ+h+Mtcpp702xSM9m10w0tJUYtKAWyGUyscZ5EFtDAqMlBTE1UNo3E7rlKbWq8dPDoUpbwV88BxZEwyxDXauDYLpMLt1rTZFbxZ9oavgZiGDcUM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=moxa.com; Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) by TYZPR01MB4211.apcprd01.prod.exchangelabs.com (2603:1096:400:1c4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.25; Tue, 11 Aug 2026 06:05:56 +0000 Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717]) by PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717%4]) with mapi id 15.21.0292.024; Tue, 11 Aug 2026 06:05:56 +0000 From: Crescent Hsieh To: Greg Kroah-Hartman , Johan Hovold Cc: FangpingFP.Cheng@moxa.com, Epson.Chiang@moxa.com, EddieSY.Lin@moxa.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Crescent Hsieh Subject: [PATCH v3 1/6] USB: serial: mxuport: clean up product ID definitions and device table Date: Tue, 11 Aug 2026 14:04:56 +0800 Message-ID: <20260811060501.2307836-2-crescentcy.hsieh@moxa.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> References: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TPYP295CA0054.TWNP295.PROD.OUTLOOK.COM (2603:1096:7d0:8::6) To PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR01MB5405:EE_|TYZPR01MB4211:EE_ X-MS-Office365-Filtering-Correlation-Id: 45eea465-23af-4389-1c81-08def76e9b25 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|52116014|366016|1800799024|376014|10067099003|56012099006|18002099003|22082099003|38350700014; X-Microsoft-Antispam-Message-Info: iIzujBHrJSNrwdAcqE5rXSeMWBM9gy6L2/ApI1kk/4SXM8JFXitKPJTRPXN30WSPViUTF1pEBG8eiyq2Rzje5Zq6SzHpcRcsZsku7Uds0uA8nqvzPmC1X3dcC3789vNEeZD0qTM30x3vyJEH1xLsaZA0/6l8pIpj7c00rtEJ5FJIsYWhG/dP/9LXlZfdVaDLDrvaluOzJtMtIUSzNnfYpqu4wNnZdcKbY0V1Bu9pmD7A/ydzFWmzxyUGWL0HYe1pLmlaDg0jSGo1te5JWVGGlztPC3nOPm4VTnF6WMSDfo8MKIS7APYIw+AVmd8rvE3YHGcwR3KdELfnZlwwl2G0fnRM+spfLcOagqFjVHLxyZaW3BuPeQQJedHsX6EfZ8nKFtjc7+jKx3BYhQvGVNtwdXUodq9VzzhMsjCKH+CqxGnxm8tgzSAXktlN8jV0KocG0fdCQJiaA8Fmf1ZB8M4/DXisHC3t1cvVEHULLlTthDxTsnhWpHXh+NiOMnV+m7Ukosl5PVsV8ZF1nHLdQikbKkUJn/QZZWaVs5yrOMHLIVwBOOWQgBaFnF94p9YybllijJR95q2T5T4DOKkGOn3lIYd/lQywnQePIJhMw6E+R+WS3qLXEOYAYb8y1avFNnTRDyb+dgIyWayiW65N6cM3TY5BFXC/LmaY97xejN91y1UhICZd7puVvks1q0vq7ZGji2BgNyyjDEAPXAoqIQSZtg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR01MB5405.apcprd01.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(52116014)(366016)(1800799024)(376014)(10067099003)(56012099006)(18002099003)(22082099003)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?mfW+uMV1GqgEsKPrd5/kcDCXBoCooelUm5NFoJOg0CKPH5UFRGhc271Hc/fE?= =?us-ascii?Q?NoHmAzooZ75doZA2W95vig21s+i6ywdAv9ret1Mg9tUvKBoGACWBrcfsDnFX?= =?us-ascii?Q?is6rg8GP82GpdFdxCoXRfRMUeQCEE/3aR+kvD6yn/4hqx2KDsPQt+jL3OqEv?= =?us-ascii?Q?HABqe3pnJ7WzdVllGnIEXZRi+PVDxPhDJssnHQM2l4ItcereOykoSvM/SbLr?= =?us-ascii?Q?kTKmVv9S04YooxPenaZ77EfJtOoCzrOzjZbrhxKdKTHFXYqF+mm/lgCMii8H?= =?us-ascii?Q?8QBj6ncxxSolzSWyrGoOkYr2eoTWIDapYCLUdjCADMAdONA4mGcNxs/4fZnh?= =?us-ascii?Q?96fOcTWxMkoTG6KpZmQKb9Kb7j9dmtPl+NHeojLhpEcSgPCBWjK/UxScYInv?= =?us-ascii?Q?NmAz5HKHAD6pu+7UT9d4uTw71E0FFzxf3OOxxMO0qzVrr2OC0w88mTjYGmjs?= =?us-ascii?Q?WvZsR5ZqqmZ0Yg5lwYmGfwFAbU+npeu42FLYxgwyWtDLemA5qXUYxFpTEEHZ?= =?us-ascii?Q?Y4u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1HcQLiFH?= =?us-ascii?Q?i4VyThftndLCkU/KyTtGKaauP7RiWAUSN4p+ALCdQS+sSB3EzDr8mDyhULZ1?= =?us-ascii?Q?nLFnofDE7gV4/2GVAvzRcvrtq4IBHmJ1L7EWW00bnTZ7nXQ4QNxf+gwQ9vCS?= =?us-ascii?Q?b+XTNQ/i4eMWpjKSrO/MHCxwAAAP3Ouc8+9r06i5QCSmKI+IrnnseLmcEY97?= =?us-ascii?Q?Po0JHeEQjwK6fxjFu/YLDBJr+eeJf1oJG4yC+9yNB7ksqcWbkDORDgRvMuQg?= =?us-ascii?Q?TrtEXwtYeNa6cNfbZ14SfkMb2r1QM7EIj4pcIruXATfFJsruI9aOGaiQ50BG?= =?us-ascii?Q?Xjn9+F2UZNDt6Qh2LTViYR9y+m8qNyE=3D?= X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45eea465-23af-4389-1c81-08def76e9b25 X-MS-Exchange-CrossTenant-AuthSource: PUZPR01MB5405.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2026 06:05:55.9835 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5571c7d4-286b-47f6-9dd5-0aa688773c8e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 55NGKCDZ3MureiGLuA6DMIooX/I7G7IbO2lzCZnuZXN/1skbVpgeblmg1TqRV1bpWtopAqf2xy5Hl06P+yXe9XSBc1Q3XXKkBuM8S0D8PDE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR01MB4211 Content-Type: text/plain; charset="utf-8" Rename the product ID definitions after the corresponding product names to make the product mapping explicit. Introduce a helper macro to keep each device-table entry on one line and make the table easier to scan. Signed-off-by: Crescent Hsieh --- drivers/usb/serial/mxuport.c | 43 ++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c index 088d5dd8abb5..a4e0467171c6 100644 --- a/drivers/usb/serial/mxuport.c +++ b/drivers/usb/serial/mxuport.c @@ -28,14 +28,14 @@ /* Definitions for the vendor ID and device ID */ #define MX_USBSERIAL_VID 0x110A #define MX_UPORT1250_PID 0x1250 -#define MX_UPORT1251_PID 0x1251 +#define MX_UPORT1250I_PID 0x1251 #define MX_UPORT1410_PID 0x1410 #define MX_UPORT1450_PID 0x1450 -#define MX_UPORT1451_PID 0x1451 -#define MX_UPORT1618_PID 0x1618 -#define MX_UPORT1658_PID 0x1658 -#define MX_UPORT1613_PID 0x1613 -#define MX_UPORT1653_PID 0x1653 +#define MX_UPORT1450I_PID 0x1451 +#define MX_UPORT1610_8_PID 0x1618 +#define MX_UPORT1650_8_PID 0x1658 +#define MX_UPORT1610_16_PID 0x1613 +#define MX_UPORT1650_16_PID 0x1653 =20 /* Definitions for USB info */ #define HEADER_SIZE 4 @@ -157,26 +157,21 @@ struct mxuport_port { #define MX_PORTS_OFFSET 1 #define MX_PORTS(n) (((n) - MX_PORTS_OFFSET) & MX_PORTS_MASK) =20 +#define MX_DEVICE(pid, ports) \ + { USB_DEVICE(MX_USBSERIAL_VID, pid), \ + .driver_info =3D MX_PORTS(ports) } + /* Table of devices that work with this driver */ static const struct usb_device_id mxuport_idtable[] =3D { - { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1250_PID), - .driver_info =3D MX_PORTS(2) }, - { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1251_PID), - .driver_info =3D MX_PORTS(2) }, - { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1410_PID), - .driver_info =3D MX_PORTS(4) }, - { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1450_PID), - .driver_info =3D MX_PORTS(4) }, - { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1451_PID), - .driver_info =3D MX_PORTS(4) }, - { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1618_PID), - .driver_info =3D MX_PORTS(8) }, - { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1658_PID), - .driver_info =3D MX_PORTS(8) }, - { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1613_PID), - .driver_info =3D MX_PORTS(16) }, - { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1653_PID), - .driver_info =3D MX_PORTS(16) }, + MX_DEVICE(MX_UPORT1250_PID, 2), + MX_DEVICE(MX_UPORT1250I_PID, 2), + MX_DEVICE(MX_UPORT1410_PID, 4), + MX_DEVICE(MX_UPORT1450_PID, 4), + MX_DEVICE(MX_UPORT1450I_PID, 4), + MX_DEVICE(MX_UPORT1610_8_PID, 8), + MX_DEVICE(MX_UPORT1650_8_PID, 8), + MX_DEVICE(MX_UPORT1610_16_PID, 16), + MX_DEVICE(MX_UPORT1650_16_PID, 16), {} /* Terminating entry */ }; =20 --=20 2.53.0 From nobody Tue Sep 29 07:41:36 2026 Received: from SEYPR02CU001.outbound.protection.outlook.com (mail-koreacentralazon11013020.outbound.protection.outlook.com [40.107.44.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD1B8386C3D; Tue, 11 Aug 2026 06:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.44.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428367; cv=fail; b=VdgUUTO5FwxflP/7TJ05W1dGDkwvPgzNTXnV25f6XTVhcVaKoWh4qwz7xfVIdOR8v3yMIM53rQIotP4R7SvUv+/PiCmpoM4aGj9rP0MkaH8q4yNd2M/pJorWTKQsK/zGhqW7kZkpCLus23IY7xkQYvqX5wQrueLnf7DmD2Bt5nQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428367; c=relaxed/simple; bh=1AHSHfOBIVwDmpP0WCtWg0Hw3BP04K8d92iF5J2w7wo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=the0FhO0MwG7Hlt2BO7ew3CNX8/yy6bJqItqntvz7bd8qUXRb4IhfxiA06igKfyRa6u6SwBPeeQGM9pHOc3SnlJYHE8iBhQQAb4N0eDUnfVeAuwZwxIAJGUCWNoZGYp6uBoMe8wit3HheehZZK4E6pyV/fBPllAqWNm9BE7VTM0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com; spf=pass smtp.mailfrom=moxa.com; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b=QitRcE2Q; arc=fail smtp.client-ip=40.107.44.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=moxa.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b="QitRcE2Q" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uDnl81AzgWlpSdn7mszIXOmLMro+Rz30XfRddIxN6qYavIq91B+YZY0X5huTKbcd7fqqWA0it0rEB7zI56PGFdKzH2UhiIe8o5LrNAVw2+rAB9VLhqgCCEhZziI07Bc9lR4WrWMCwVwjtBzk79AeREkc/Y9bw/aP8Mxn8bAtJho3bv8hPX4i2tPtXh0b+6tgqoTKEigWZvgjr873DhdZTWi+mm8b7sn2kt14xI3YAsYS6GNtYA/rY6KJl7RyAc6VNWfPLKSC16uHJW77rV+v0n2DK4zGngA/biSR5GlAkN8mKC63wUcocS7hrj6FgGTrX6Q+ALCqcpVqQNz6m1BZvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=MlNtxF99FYcqlEX41oLFrtnLsX9+S3tbKnxMEY8Lyhg=; b=cSLBIQbQOvfGmoCUg0YQBxSWfTUmAB/V/eXcKwE59Sd1NkC9dvdjmfTZkf4FwB8KAJ7XOtmw26zn/w9Vy98qo+3Cdw741aYtcy+vFpIIM0x2Cb8SjTALlVKLOCygO5J+xO7AP6vNJxazj2ZWNQGaWFdc3jae8CZTN0wA7MGx4wJE6kJIilQrmI3a2jm5iujGU2hp/I29i/KMoKA+WdL7l2qGA/ESh3XkYEUuzk2qv9q7bRSqIjs/BAgYPPW2JA+OtrZFuAhHoBz/xhALDyw5A6/mepyYdXKipqIncQzxUthok2njTWyNW9bynU5HjIC3YDoqd1Rb1PlpQ3b/Q13IPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=moxa.com; dmarc=pass action=none header.from=moxa.com; dkim=pass header.d=moxa.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=moxa.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MlNtxF99FYcqlEX41oLFrtnLsX9+S3tbKnxMEY8Lyhg=; b=QitRcE2QcBLnhUYG4bKQu5SGAf2U5bg0DiRNshOqpcZEzSVAMRINDtYyovBWGr8KLWdLAT57RdUVf/Qs/jyAZWyM5cyDaxwE3lhKzpR0oNzgI8RTWkWC9Ln4Q1MZQC7hnaJJnSJYLPAMZl/oKsjHn/DbkyCSFN3BgkjOWG/1GX8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=moxa.com; Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) by TYZPR01MB4211.apcprd01.prod.exchangelabs.com (2603:1096:400:1c4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.25; Tue, 11 Aug 2026 06:05:56 +0000 Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717]) by PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717%4]) with mapi id 15.21.0292.024; Tue, 11 Aug 2026 06:05:56 +0000 From: Crescent Hsieh To: Greg Kroah-Hartman , Johan Hovold Cc: FangpingFP.Cheng@moxa.com, Epson.Chiang@moxa.com, EddieSY.Lin@moxa.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Crescent Hsieh Subject: [PATCH v3 2/6] USB: serial: mxuport: clean up firmware version handling Date: Tue, 11 Aug 2026 14:04:57 +0800 Message-ID: <20260811060501.2307836-3-crescentcy.hsieh@moxa.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> References: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TPYP295CA0054.TWNP295.PROD.OUTLOOK.COM (2603:1096:7d0:8::6) To PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR01MB5405:EE_|TYZPR01MB4211:EE_ X-MS-Office365-Filtering-Correlation-Id: cb34eb45-5f93-4d12-d9b2-08def76e9bd2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|52116014|366016|1800799024|376014|10067099003|56012099006|18002099003|22082099003|38350700014; X-Microsoft-Antispam-Message-Info: yl0EWSitbQ8jk1zxREJm1xn0+uyG9aa38J/wI0hVxc9wdlq7MZCO5Obl3jOrdW++bC6/B02wuxkonAyZ7+/+Q/hbPqNv7XXA2nkhoSjWVhpndICeAm6P8m8fdjUhuVDpfT+t+YYsin+eedQa6Km7JfbCiB0ereHi2nZaDUZ7phM/Ai6SBJcja/Ov7XNUGUNS0bnFTt5zuHbdHGDSRbZtBLKvjIgD16kdjhtJrAxZDEi/cQ5R885k5StDpppCGyt75C38Z/7q0wKeIPbm3l0BOEfNqFVPBqgLbcaBMPUQ0DULiw+lOPwVba1P4UikoUy670ro6ZkMe5woCKfrW2a4Y6poVEkZqGpqaXbEoy+Sl7qxSWiEbYgI9xgiEGyKZqg/8BHGGVu/lbOP9h5IkO3CwXZ8XhugizqrbWaTa8zL+n0TECj+JHuYqsjl2Cn7T1pn3UhBVI1JUaiFffU4isuesQTEfUGCnTtvMQ4LB1w3R9Wzf8BSLDFCu6uhLlK6lJP0oM4kJA6lpLG6L3/pI51QB6hjbaDz8NSDAghbzfqcqiXpXGzYt/BVl+DvV74oAytH5tcxIh/0Y4otOd6hFo5v9c7DKEgyoLCDYv+k5sZoTayeX6AVPrmlum9zLrsRSVi7Dxej9aDUkpo6Y0bDAgxvpxash+HGkn76UG7dFDxF7D7HSMwnR5Jl4KqzMtTKyOOyUWOY+Q1fqFjIadvE4Nzn3iCzDq16mYqZQ/mbe/dT+YQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR01MB5405.apcprd01.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(52116014)(366016)(1800799024)(376014)(10067099003)(56012099006)(18002099003)(22082099003)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ExBAbl7/rkWUSsBh5rgdm1SgYOqvTk3vqHKsQyx2KqIPO+8rAk5IDepVJTqs?= =?us-ascii?Q?wLrOYgam1B1DE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CRnWfczpcv?= =?us-ascii?Q?9Jw2yQIkmKVnor2wRbKdbwGtWvDT5Zo1CueCbfnmTtgPIuP+6dY/MoPDSjoc?= =?us-ascii?Q?gOftwLAr2mt0157Rw7jWL39+7nV1Op5NI4CcBFiU0FWiKDuNYvm1gTOwFZr3?= =?us-ascii?Q?m81GTys7K+gAATf8s3XY4r7NPpl/2K8G/Dn50UV73P5XHfSlx8aeijUhuf2D?= =?us-ascii?Q?vUhdKfJ8CDU693pm4traBn7co69R0rIHSkSBvvQQRBcchM6ODV7rG/IH8X98?= =?us-ascii?Q?9IaoWgsXPr8+0p7pN/w2aJk369lvNrD9luo3JjDomTi9EYGK/tO/rmv8gm8J?= =?us-ascii?Q?rqE2siZ9wDr9EDQlOiycywS/MpXCc9JeZlL+givt2t4APJMRy/vl1k0c1dah?= =?us-ascii?Q?J5X/AlcAVGppwbbx6RarbA6KrPQcqhb4nlqBNVohDm3432zCGYggqX9TSwMg?= =?us-ascii?Q?AbfsY5nEJ5eRPX4BdpNfye9mUDBHher4DaJcyegif3+wymkCmkfXqHBWQ8lX?= =?us-ascii?Q?ozVS6d3+hpPQK9uvNOadHP2YRR18Mj2dAsjN/zThbajcTQCywxmkjyv8QkyI?= =?us-ascii?Q?5NPcrqj33CjE98v6HpoRTab+tFf3BOMAOV7qFZfwWukXNNOya6u2zeBstWbb?= =?us-ascii?Q?x7hOH2jCQjUCNJ3KthTW9a2nO+LKF5aEceBYZ6rc+8MHCE/gov7euCbL6CgM?= =?us-ascii?Q?fnA1wlWCq2SyP8jkBrK6hMo4r8YfcexsN+vZ836U4FETb0I8+6bNz8SYA0Lq?= =?us-ascii?Q?lcUB4mu1OYrtgq5GwjmzMr+4pUl2YlYqDP953NONuo5hMCPRK7jTzmkBujiv?= =?us-ascii?Q?H0ChuF+DbjarOBnZ4Y7y6r710Lepv3E=3D?= X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: cb34eb45-5f93-4d12-d9b2-08def76e9bd2 X-MS-Exchange-CrossTenant-AuthSource: PUZPR01MB5405.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2026 06:05:56.7965 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5571c7d4-286b-47f6-9dd5-0aa688773c8e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 26AyjrNm1rUBGe+Bd3UjSjjSgS68muPAf0nS+nE0zrtcY3s6LM3c/LzsjsusX/zWvTyPl91o3kT/EMSPFhOmEo5c6NyVS9zyw3bzTJ0m+c0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR01MB4211 Content-Type: text/plain; charset="utf-8" Add a small helper for parsing firmware versions and use it for the firmware image. This avoids open-coded firmware image offsets in probe() and retains the existing image-size validation before reading the version bytes. Keep the existing version comparison policy unchanged, but store the version components explicitly so that the version can be printed without unpacking a raw integer. Print the firmware version fields in decimal, as these fields represent readable version components rather than hexadecimal values. Signed-off-by: Crescent Hsieh --- drivers/usb/serial/mxuport.c | 78 ++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c index a4e0467171c6..61d4c6e1a9ce 100644 --- a/drivers/usb/serial/mxuport.c +++ b/drivers/usb/serial/mxuport.c @@ -43,9 +43,22 @@ #define DOWN_BLOCK_SIZE 64 =20 /* Definitions for firmware info */ -#define VER_ADDR_1 0x20 -#define VER_ADDR_2 0x24 -#define VER_ADDR_3 0x28 +#define MX_FW_VER_BYTE1_OFF 0x20 +#define MX_FW_VER_BYTE2_OFF 0x24 +#define MX_FW_VER_BYTE3_OFF 0x28 + +struct mxuport_fw_version { + u8 major; + u8 minor; + u8 build; + u32 value; +}; + +static const u16 mxuport_fw_ver_offsets[] =3D { + MX_FW_VER_BYTE1_OFF, + MX_FW_VER_BYTE2_OFF, + MX_FW_VER_BYTE3_OFF, +}; =20 /* Definitions for USB vendor request */ #define RQ_VENDOR_NONE 0x00 @@ -965,8 +978,31 @@ static int mxuport_calc_num_ports(struct usb_serial *s= erial, return num_ports; } =20 +static void mxuport_compose_fw_version(struct mxuport_fw_version *version, + u8 major, u8 minor, u8 build) +{ + version->major =3D major; + version->minor =3D minor; + version->build =3D build; + version->value =3D (major << 16) | (minor << 8) | build; +} + +static int mxuport_parse_fw_version(const struct firmware *fw, + const u16 *offsets, + struct mxuport_fw_version *version) +{ + if (fw->size <=3D offsets[2]) + return -EINVAL; + + mxuport_compose_fw_version(version, fw->data[offsets[0]], + fw->data[offsets[1]], fw->data[offsets[2]]); + + return 0; +} + /* Get the version of the firmware currently running. */ -static int mxuport_get_fw_version(struct usb_serial *serial, u32 *version) +static int mxuport_get_fw_version(struct usb_serial *serial, + struct mxuport_fw_version *version) { u8 *ver_buf; int err; @@ -983,7 +1019,7 @@ static int mxuport_get_fw_version(struct usb_serial *s= erial, u32 *version) goto out; } =20 - *version =3D (ver_buf[0] << 16) | (ver_buf[1] << 8) | ver_buf[2]; + mxuport_compose_fw_version(version, ver_buf[0], ver_buf[1], ver_buf[2]); err =3D 0; out: kfree(ver_buf); @@ -1043,9 +1079,8 @@ static int mxuport_probe(struct usb_serial *serial, const struct usb_device_id *id) { u16 productid =3D le16_to_cpu(serial->dev->descriptor.idProduct); + struct mxuport_fw_version version, local_ver; const struct firmware *fw_p =3D NULL; - u32 version; - int local_ver; char buf[32]; int err; =20 @@ -1060,10 +1095,8 @@ static int mxuport_probe(struct usb_serial *serial, if (err < 0) return err; =20 - dev_dbg(&serial->interface->dev, "Device firmware version v%x.%x.%x\n", - (version & 0xff0000) >> 16, - (version & 0xff00) >> 8, - (version & 0xff)); + dev_dbg(&serial->interface->dev, "Device firmware version v%u.%u.%u\n", + version.major, version.minor, version.build); =20 snprintf(buf, sizeof(buf) - 1, "moxa/moxa-%04x.fw", productid); =20 @@ -1075,35 +1108,30 @@ static int mxuport_probe(struct usb_serial *serial, /* Use the firmware already in the device */ err =3D 0; } else { - if (fw_p->size <=3D VER_ADDR_3) { + err =3D mxuport_parse_fw_version(fw_p, mxuport_fw_ver_offsets, &local_ve= r); + if (err) { dev_err(&serial->interface->dev, "Firmware %s is too short\n", buf); - err =3D -EINVAL; goto out; } =20 - local_ver =3D ((fw_p->data[VER_ADDR_1] << 16) | - (fw_p->data[VER_ADDR_2] << 8) | - fw_p->data[VER_ADDR_3]); dev_dbg(&serial->interface->dev, - "Available firmware version v%x.%x.%x\n", - fw_p->data[VER_ADDR_1], fw_p->data[VER_ADDR_2], - fw_p->data[VER_ADDR_3]); - if (local_ver > version) { + "Available firmware version v%u.%u.%u\n", + local_ver.major, local_ver.minor, local_ver.build); + + if (local_ver.value > version.value) { err =3D mxuport_download_fw(serial, fw_p); if (err) goto out; - err =3D mxuport_get_fw_version(serial, &version); + err =3D mxuport_get_fw_version(serial, &version); if (err < 0) goto out; } } =20 dev_info(&serial->interface->dev, - "Using device firmware version v%x.%x.%x\n", - (version & 0xff0000) >> 16, - (version & 0xff00) >> 8, - (version & 0xff)); + "Using device firmware version v%u.%u.%u\n", + version.major, version.minor, version.build); =20 /* * Contains the features of this hardware. Store away for --=20 2.53.0 From nobody Tue Sep 29 07:41:36 2026 Received: from OS8PR02CU002.outbound.protection.outlook.com (mail-japanwestazon11012060.outbound.protection.outlook.com [40.107.75.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23D7D383339; Tue, 11 Aug 2026 06:06:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.75.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428365; cv=fail; b=sRmzVpOyadG3gTzCVQ9g2Sk3oB2TJlR1UtN86biAP8Na+qpYYBY4CHwMqwScMZoCzonh4+RQlUNSXS+iRKpmNmw1xBtPKQDlOj/rEAU6Byvw4Bt6qOaljw7kWHgDckjrUPJHM4o+epjwsQ46PLdDWOJQiODArZ5asFGviO7QblM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428365; c=relaxed/simple; bh=K4OKuc+vPHzpfWVgMsR6IGT+Bm2mGhAzh4//EdEKjtk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=GPGP2wP+fAf4tFpihz8lS8+DFfBSynmQNnZHmML3KUCz0mTL5pLAE6KlBMsBWFopl/XhwWcHJyDypmmNlOCV3gsV4NO2FjLGVdJrsCROMqs6nuvfMDmGlaanqgJMmmY7R93p7PApyLa2eGRdFtmc5YBMaqviuhnQNhztZUI1etg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com; spf=pass smtp.mailfrom=moxa.com; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b=Zav+pkul; arc=fail smtp.client-ip=40.107.75.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=moxa.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b="Zav+pkul" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=usJr8b60YVogKco3UijPU/AQTVtHdANeGTttAkNvFaVkt+8cpCu7HN2jne++EcNLXCMX+lrjXK96/SqKc63kPETLzNv/oOzOBO6yOCh84zj+iRUSdoraybmdRqG5ghLAo7Qe5qfqJaVXGV27m8mcMp3SjI/dybTCW2UbVViQtXemDqln9GZNtjx3bjklXLnsW+k4O2hDptFI5ETBf+RttSG2bHMoiFhY9FoWEAfCkxpso+dhqnFJ9MK1Ov+uIdXrDCxhC9ev2ef8fq+0b4LmWguAf3L41XpiZTsdWClnLqba7j8HiAXduXcNsx2NCrPdagv6WvHCLANf6+Q3PGd3rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Es2rNjcCPZh76I+mrlu1G2HAaJeYyhXZNhGYGjYkPuk=; b=wPbeWzZhintGc0V1M+EG0VR/xloHAvRrTZaxmqF67K2JlLh5gfGyLBLA2etN6VIhvImf+sk8X0oF85gBkgk7Yb6HBWTU6X5S8sj+sXaTvtX7RvNIgqWhqZzKbM1a+ZoU+IEO6Cgk3JzcpxJdIleBQ3nKqAMiPYYjxWuXaNF4ZGlBoNzYgTFXOEs4BMP/TuEgV0/+SmigzS+wBdTKxaP6ykSfriwAyuBdzKjhouZku4Tf5D7w0RmWeTE7LKKCY3N9jGUeg48ekOpNPgoGGmi27spbj32K45j7XSeCLOTZTF/2XjmPDplgY4pjmo0YBD7Sn1RZA1i2MA4OYJtXV3nntw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=moxa.com; dmarc=pass action=none header.from=moxa.com; dkim=pass header.d=moxa.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=moxa.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Es2rNjcCPZh76I+mrlu1G2HAaJeYyhXZNhGYGjYkPuk=; b=Zav+pkul8azOgNrKJCNIETyiBPDXzO6yikndSd5Bt4jf0O/xx9XGW2ffrjDMjOFqLY60vuQBpNNVtI6Jvkfh9Ais1TDzwSgeB3xNaxFYwZE7eA/jm+hir9fRVQYBbiSJq6nhXupw72vKYDRzlr4Uf9HeXwl2FncXD/8jcaecq5A= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=moxa.com; Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) by TYZPR01MB4211.apcprd01.prod.exchangelabs.com (2603:1096:400:1c4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.25; Tue, 11 Aug 2026 06:05:57 +0000 Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717]) by PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717%4]) with mapi id 15.21.0292.024; Tue, 11 Aug 2026 06:05:57 +0000 From: Crescent Hsieh To: Greg Kroah-Hartman , Johan Hovold Cc: FangpingFP.Cheng@moxa.com, Epson.Chiang@moxa.com, EddieSY.Lin@moxa.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Crescent Hsieh Subject: [PATCH v3 3/6] USB: serial: mxuport: add MUX50U-based device support Date: Tue, 11 Aug 2026 14:04:58 +0800 Message-ID: <20260811060501.2307836-4-crescentcy.hsieh@moxa.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> References: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TPYP295CA0054.TWNP295.PROD.OUTLOOK.COM (2603:1096:7d0:8::6) To PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR01MB5405:EE_|TYZPR01MB4211:EE_ X-MS-Office365-Filtering-Correlation-Id: d945c7da-2afa-44e9-1954-08def76e9c52 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|52116014|366016|1800799024|376014|10067099003|56012099006|18002099003|22082099003|38350700014; X-Microsoft-Antispam-Message-Info: YKTtVDxrp40awUfGHbcb20c729GwwhRLTKmPHLFt+58Xc3qGYFoj8lq+h9LtB66M1UusBKlmRe8b6RwfwWZZdNQHXraARP3600cTmiDqS/DQrnk91G/RThOCeO0gBpa/5fq483UtUiQgDQuhwJyoHFqqzskk15HKa4MKKxbSopVJY20ONAcBdg7VBHH+ywcRkK0f8siLmFIWMr421fA48lg5jLu2AwZ8Gtjbk7w/34BzL5DsaiNDep4yLkz7ubcAMv5iLu5Bp2EqNbpausWI1gVbguSCjKwn8uVDNEIHHUc2sbYW2rpvTMrCn2GXNlC6A33VToRvBAbb4cO+li+21Hx1MrCgyD3Y7FaXooSe9glDe2MvCOVAIP19fHA1iwwrOg6uKvW3L8WIwHkw3FVVlR8NqdmXrZ1Z9PFR+h24LNH1y/E+DsP/i/9Sroeg53CPqkPKINF8ZFbb05Idu+AeaA8hW/uK3I6jx8ix4cVAiYMb+9QDiul6J66VQauWmhTeInvQY6XWQbrVmVvDtgLA1lkTA68Eu3X4sstBIslqPcR/GUsrGlgwrysWXcLzPGRLJRaQaztZSmyP36XVUpcOeSBt/bixNikBQVbrLp+yEzP4dQEgG6iS9K4bOuRHpo3uZI7UESSRh1vkVxuzYmZ92WRngJN3OaAhIXmW39xYc7FxTaKVPw1x3Y/naotvoLSe0dWML88y4c0gk4q7LSl/rX7llhaGQDj6sRGINV1zAeQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR01MB5405.apcprd01.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(52116014)(366016)(1800799024)(376014)(10067099003)(56012099006)(18002099003)(22082099003)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-M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ascii?Q?a6hxgVIuK64q9WJXiHLRXR7kh3QDkRY=3D?= X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: d945c7da-2afa-44e9-1954-08def76e9c52 X-MS-Exchange-CrossTenant-AuthSource: PUZPR01MB5405.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2026 06:05:57.6149 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5571c7d4-286b-47f6-9dd5-0aa688773c8e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jlRmO/HOZAvJFYiCpIYeB8JqhMa5lusKjvES+uhVmbRYzt1/9orD5jjJ6KaCM1muwNeR3FbrJ07LVlcUU50mvxWuWqoh5WlvCHRoDG9CsV8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR01MB4211 Content-Type: text/plain; charset="utf-8" Add support for MUX50U-based UPort G2 devices and Platform UARTs. Add their product IDs and list the supported products by family. Encode the number of ports and device family in each USB device ID entry. Use the family to select the firmware image and version offsets, and the method used to determine whether a firmware download is needed. UPort G2 devices use the shared UP firmware image (moxa-up-mux50u.fw), while Platform UARTs use the shared PF firmware image (moxa-pf-mux50u.fw). Platform UARTs are board-level UARTs accessed through the USB bus. The factory firmware on MUX50U-based devices reports its version in a different format from the runtime firmware image, so version comparison cannot reliably determine whether a firmware download is needed. Check the system-register remap state instead to determine whether the device is already running the runtime firmware from SRAM. Keep the existing per-product firmware selection and version comparison for UPort G1 devices. Signed-off-by: Crescent Hsieh --- drivers/usb/serial/mxuport.c | 170 +++++++++++++++++++++++++++++++---- 1 file changed, 152 insertions(+), 18 deletions(-) diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c index 61d4c6e1a9ce..35123572ca4d 100644 --- a/drivers/usb/serial/mxuport.c +++ b/drivers/usb/serial/mxuport.c @@ -6,10 +6,20 @@ * Copyright (c) 2013 Andrew Lunn * * Supports the following Moxa USB to serial converters: - * 2 ports : UPort 1250, UPort 1250I - * 4 ports : UPort 1410, UPort 1450, UPort 1450I - * 8 ports : UPort 1610-8, UPort 1650-8 - * 16 ports : UPort 1610-16, UPort 1650-16 + * + * UPort G1: + * UPort 1250, UPort 1250I + * UPort 1410, UPort 1450, UPort 1450I + * UPort 1610-8, UPort 1650-8 + * UPort 1610-16, UPort 1650-16 + * UPort G2: + * UPort 1250-G2, UPort 1250I-G2 + * UPort 1410-G2, UPort 1450-G2, UPort 1450I-G2 + * UPort 1610-8-G2, UPort 1650-8-G2 + * UPort 1650-8-G2-Hub, UPort 1650I-8-G2 + * Platform UART: + * MU250U, MU450U, MU850U + * MUx50U-3, MUx50U-5, MUx50U-6, MUx50U-7 */ =20 #include @@ -37,6 +47,24 @@ #define MX_UPORT1610_16_PID 0x1613 #define MX_UPORT1650_16_PID 0x1653 =20 +#define MX_UPORT1250_G2_PID 0x1252 +#define MX_UPORT1250I_G2_PID 0x1253 +#define MX_UPORT1410_G2_PID 0x1411 +#define MX_UPORT1450_G2_PID 0x1452 +#define MX_UPORT1450I_G2_PID 0x1453 +#define MX_UPORT1610_8_G2_PID 0x1619 +#define MX_UPORT1650_8_G2_PID 0x1659 +#define MX_UPORT1650_8_G2_HUB_PID 0x165a +#define MX_UPORT1650I_8_G2_PID 0x165b + +#define MX_MU250U_PID 0x0250 +#define MX_MU450U_PID 0x0450 +#define MX_MU850U_PID 0x0850 +#define MX_MUX50U_6_PID 0x7002 +#define MX_MUX50U_3_PID 0x7003 +#define MX_MUX50U_5_PID 0x7004 +#define MX_MUX50U_7_PID 0x7005 + /* Definitions for USB info */ #define HEADER_SIZE 4 #define EVENT_LENGTH 8 @@ -46,6 +74,13 @@ #define MX_FW_VER_BYTE1_OFF 0x20 #define MX_FW_VER_BYTE2_OFF 0x24 #define MX_FW_VER_BYTE3_OFF 0x28 +#define MX_MUX50U_FW_VER_BYTE1_OFF 0x86 +#define MX_MUX50U_FW_VER_BYTE2_OFF 0x88 +#define MX_MUX50U_FW_VER_BYTE3_OFF 0x8a + +#define MX_SYS_REG_REMAP_OFF 0x20 +#define MX_PWR_REMAP_MASK 0x03 +#define MX_REMAP_TO_SRAM 0x02 =20 struct mxuport_fw_version { u8 major; @@ -60,6 +95,12 @@ static const u16 mxuport_fw_ver_offsets[] =3D { MX_FW_VER_BYTE3_OFF, }; =20 +static const u16 mxuport_mux50u_fw_ver_offsets[] =3D { + MX_MUX50U_FW_VER_BYTE1_OFF, + MX_MUX50U_FW_VER_BYTE2_OFF, + MX_MUX50U_FW_VER_BYTE3_OFF, +}; + /* Definitions for USB vendor request */ #define RQ_VENDOR_NONE 0x00 #define RQ_VENDOR_SET_BAUD 0x01 /* Set baud rate */ @@ -96,6 +137,8 @@ static const u16 mxuport_fw_ver_offsets[] =3D { #define RQ_VENDOR_RESET_DEVICE 0x23 /* Try to reset the device */ #define RQ_VENDOR_QUERY_FW_CONFIG 0x24 =20 +#define RQ_VENDOR_GET_SYS_REG 0x34 + #define RQ_VENDOR_GET_VERSION 0x81 /* Get firmware version */ #define RQ_VENDOR_GET_PAGE 0x82 /* Read flash page */ #define RQ_VENDOR_GET_ROM_PROC 0x83 /* Get ROM process state */ @@ -170,21 +213,44 @@ struct mxuport_port { #define MX_PORTS_OFFSET 1 #define MX_PORTS(n) (((n) - MX_PORTS_OFFSET) & MX_PORTS_MASK) =20 -#define MX_DEVICE(pid, ports) \ +#define MX_FAMILY_MASK GENMASK(5, 4) +#define MX_UPORT_G1 0 +#define MX_UPORT_G2 BIT(4) +#define MX_PLATFORM_UART BIT(5) +#define MX_FAMILY(info) ((info) & MX_FAMILY_MASK) +#define MX_DEVICE_INFO(ports, family) (MX_PORTS(ports) | (family)) + +#define MX_DEVICE(pid, ports, family) \ { USB_DEVICE(MX_USBSERIAL_VID, pid), \ - .driver_info =3D MX_PORTS(ports) } + .driver_info =3D MX_DEVICE_INFO(ports, family) } =20 /* Table of devices that work with this driver */ static const struct usb_device_id mxuport_idtable[] =3D { - MX_DEVICE(MX_UPORT1250_PID, 2), - MX_DEVICE(MX_UPORT1250I_PID, 2), - MX_DEVICE(MX_UPORT1410_PID, 4), - MX_DEVICE(MX_UPORT1450_PID, 4), - MX_DEVICE(MX_UPORT1450I_PID, 4), - MX_DEVICE(MX_UPORT1610_8_PID, 8), - MX_DEVICE(MX_UPORT1650_8_PID, 8), - MX_DEVICE(MX_UPORT1610_16_PID, 16), - MX_DEVICE(MX_UPORT1650_16_PID, 16), + MX_DEVICE(MX_UPORT1250_PID, 2, MX_UPORT_G1), + MX_DEVICE(MX_UPORT1250I_PID, 2, MX_UPORT_G1), + MX_DEVICE(MX_UPORT1410_PID, 4, MX_UPORT_G1), + MX_DEVICE(MX_UPORT1450_PID, 4, MX_UPORT_G1), + MX_DEVICE(MX_UPORT1450I_PID, 4, MX_UPORT_G1), + MX_DEVICE(MX_UPORT1610_8_PID, 8, MX_UPORT_G1), + MX_DEVICE(MX_UPORT1650_8_PID, 8, MX_UPORT_G1), + MX_DEVICE(MX_UPORT1610_16_PID, 16, MX_UPORT_G1), + MX_DEVICE(MX_UPORT1650_16_PID, 16, MX_UPORT_G1), + MX_DEVICE(MX_UPORT1250_G2_PID, 2, MX_UPORT_G2), + MX_DEVICE(MX_UPORT1250I_G2_PID, 2, MX_UPORT_G2), + MX_DEVICE(MX_UPORT1410_G2_PID, 4, MX_UPORT_G2), + MX_DEVICE(MX_UPORT1450_G2_PID, 4, MX_UPORT_G2), + MX_DEVICE(MX_UPORT1450I_G2_PID, 4, MX_UPORT_G2), + MX_DEVICE(MX_UPORT1610_8_G2_PID, 8, MX_UPORT_G2), + MX_DEVICE(MX_UPORT1650_8_G2_PID, 8, MX_UPORT_G2), + MX_DEVICE(MX_UPORT1650_8_G2_HUB_PID, 8, MX_UPORT_G2), + MX_DEVICE(MX_UPORT1650I_8_G2_PID, 8, MX_UPORT_G2), + MX_DEVICE(MX_MU250U_PID, 2, MX_PLATFORM_UART), + MX_DEVICE(MX_MU450U_PID, 4, MX_PLATFORM_UART), + MX_DEVICE(MX_MU850U_PID, 8, MX_PLATFORM_UART), + MX_DEVICE(MX_MUX50U_6_PID, 6, MX_PLATFORM_UART), + MX_DEVICE(MX_MUX50U_3_PID, 3, MX_PLATFORM_UART), + MX_DEVICE(MX_MUX50U_5_PID, 5, MX_PLATFORM_UART), + MX_DEVICE(MX_MUX50U_7_PID, 7, MX_PLATFORM_UART), {} /* Terminating entry */ }; =20 @@ -1000,6 +1066,56 @@ static int mxuport_parse_fw_version(const struct fir= mware *fw, return 0; } =20 +static bool mxuport_is_mux50u_device(unsigned long features) +{ + switch (MX_FAMILY(features)) { + case MX_UPORT_G2: + case MX_PLATFORM_UART: + return true; + default: + return false; + } +} + +static void mxuport_get_fw_name(unsigned long features, u16 productid, + char *buf, size_t size) +{ + switch (MX_FAMILY(features)) { + case MX_UPORT_G2: + strscpy(buf, "moxa/moxa-up-mux50u.fw", size); + break; + case MX_PLATFORM_UART: + strscpy(buf, "moxa/moxa-pf-mux50u.fw", size); + break; + default: + snprintf(buf, size, "moxa/moxa-%04x.fw", productid); + break; + } +} + +static int mxuport_fw_running_from_sram(struct usb_serial *serial, bool *f= rom_sram) +{ + int err; + u32 reg; + u8 *buf; + + buf =3D kzalloc_objs(*buf, sizeof(reg)); + if (!buf) + return -ENOMEM; + + err =3D mxuport_recv_ctrl_urb(serial, RQ_VENDOR_GET_SYS_REG, + MX_SYS_REG_REMAP_OFF, 0, buf, sizeof(reg)); + if (err < 0) + goto out; + + reg =3D get_unaligned_be32(buf); + *from_sram =3D (((reg >> 24) & MX_PWR_REMAP_MASK) =3D=3D MX_REMAP_TO_SRAM= ); + err =3D 0; +out: + kfree(buf); + return err; +} + /* Get the version of the firmware currently running. */ static int mxuport_get_fw_version(struct usb_serial *serial, struct mxuport_fw_version *version) @@ -1080,7 +1196,10 @@ static int mxuport_probe(struct usb_serial *serial, { u16 productid =3D le16_to_cpu(serial->dev->descriptor.idProduct); struct mxuport_fw_version version, local_ver; + unsigned long features =3D id->driver_info; const struct firmware *fw_p =3D NULL; + const u16 *fw_version_offsets; + bool download_fw, from_sram; char buf[32]; int err; =20 @@ -1098,7 +1217,12 @@ static int mxuport_probe(struct usb_serial *serial, dev_dbg(&serial->interface->dev, "Device firmware version v%u.%u.%u\n", version.major, version.minor, version.build); =20 - snprintf(buf, sizeof(buf) - 1, "moxa/moxa-%04x.fw", productid); + if (mxuport_is_mux50u_device(features)) + fw_version_offsets =3D mxuport_mux50u_fw_ver_offsets; + else + fw_version_offsets =3D mxuport_fw_ver_offsets; + + mxuport_get_fw_name(features, productid, buf, sizeof(buf)); =20 err =3D request_firmware(&fw_p, buf, &serial->interface->dev); if (err) { @@ -1108,7 +1232,7 @@ static int mxuport_probe(struct usb_serial *serial, /* Use the firmware already in the device */ err =3D 0; } else { - err =3D mxuport_parse_fw_version(fw_p, mxuport_fw_ver_offsets, &local_ve= r); + err =3D mxuport_parse_fw_version(fw_p, fw_version_offsets, &local_ver); if (err) { dev_err(&serial->interface->dev, "Firmware %s is too short\n", buf); @@ -1119,7 +1243,17 @@ static int mxuport_probe(struct usb_serial *serial, "Available firmware version v%u.%u.%u\n", local_ver.major, local_ver.minor, local_ver.build); =20 - if (local_ver.value > version.value) { + if (mxuport_is_mux50u_device(features)) { + err =3D mxuport_fw_running_from_sram(serial, &from_sram); + if (err) + goto out; + + download_fw =3D !from_sram; + } else { + download_fw =3D local_ver.value > version.value; + } + + if (download_fw) { err =3D mxuport_download_fw(serial, fw_p); if (err) goto out; --=20 2.53.0 From nobody Tue Sep 29 07:41:36 2026 Received: from OS8PR02CU002.outbound.protection.outlook.com (mail-japanwestazon11012060.outbound.protection.outlook.com [40.107.75.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19D973876B0; Tue, 11 Aug 2026 06:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.75.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428367; cv=fail; b=nHbi5Wtvha14YzKcVDTnznuPZXA7j1vi/+YYa95/xStY6EABCVvmz9EdGXW5Hmovs51zFwNVKkaYQgvDkDheNp/h9RGDvpKwRFKC54ArQPfQEPrszNL3glRyfjyDWe57LMEx7UKs3zqeQFaddH2Y6gVU6ipfxJW5hNSDbxqZQmU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428367; c=relaxed/simple; bh=jVVsWNSwCiz1MPtuJRAXYtol3na3nK2xNvHEfeDIC0I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=o30rXceNF9wF4FawbIXOx9pcTrxwUQDytrlE8A1KG/Vmou3J8IsZMw/63kNzqM7OHdVJfHPgfOXo8+tG5MsHhNw+Mr+rM/GazmAziTse75GdSPZXhORPy6aVJ21jxfO/3T0OcdEOmbJCcQnoyLiQ5KdjLVFmZ58N8Mk1o7ubKnA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com; spf=pass smtp.mailfrom=moxa.com; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b=QnvKdF/v; arc=fail smtp.client-ip=40.107.75.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=moxa.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b="QnvKdF/v" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cI0ehN/aCtkLNB/tJAuMWj+PTBdNvZHvYDPCgGJmdXloTtw8bfTDDrKEBuRin8gLKpJm+Havx64fv/NwTv/hHAFUcRX1sgLLA6z1GHjZW8RX2rRpuRzEUXTASwPZHyWpOMXlOoe9y6dwAyZ0AkoTntOW4Ggx6Y8LG0ROzg1R6XiOCSAeiG/RmwRIAGFh/U6Snd09q/yF3Fygg4D9BFLGdG4Lb+mWyevq5qhTMA7H2cDOeBN5KZV7tCZzI9gwzrUqpG69Lpdv4QixQyr/gc6dc9hkoRhGf37F/Iue9pxc7ZIDm2plyjyGbaFQvGCDLRAk/D0cxIh0sMK3Caz87WGGZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=kRhHMF0NGYoqa0l/4TTeNDNPE3KSoSS/Gu7f6dsugFg=; b=WYAzgrgUEz05Gx8L0qa1S9sHnKdHMeb/eBUw7G5CIBmXxypH+Qv0KdsGGpQbBdOcwfyP/Q8N/JBW6j0W6+cmUwT4L/3uJWBlF8PjJOt1vbBw7Zd1hWvV+3xD6tsV7v2Ard5iZcKsaSmDSVC0vT0BDLsY66NQ6rvbSgZ+mC/uoUg19VOQrp+/g7xPy0Wt0VnUeGDfR7ujIH0bb7TNt2jHm9j6ZamYEG53PHTvityda0Bj5gFIY1ZuVqX2HDnSaWEhaMuaC7v5ZcZ6juUunXq1NuHD3WxzgjsxS6jFwD4LzaALyuEXOtkMCzf3IeQT06YEDvsfskJXtoHVoqGEbFyBIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=moxa.com; dmarc=pass action=none header.from=moxa.com; dkim=pass header.d=moxa.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=moxa.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kRhHMF0NGYoqa0l/4TTeNDNPE3KSoSS/Gu7f6dsugFg=; b=QnvKdF/vms3Lu+CvH4AWhcue9t42jiJVPmDR5pBtO60rNaMWOHKfk0hsuhMIybDiUsiYoso2E5CgGPHJLB//xqDN/0E5HdAuV0XYCkf7Kep8E5lr8y45HIzWcAMMTMKFGM66+kIl+tjC90GH4sMOtxpTy7QJnQgbTKrb2Kgp7IA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=moxa.com; Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) by TYZPR01MB4211.apcprd01.prod.exchangelabs.com (2603:1096:400:1c4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.25; Tue, 11 Aug 2026 06:05:58 +0000 Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717]) by PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717%4]) with mapi id 15.21.0292.024; Tue, 11 Aug 2026 06:05:58 +0000 From: Crescent Hsieh To: Greg Kroah-Hartman , Johan Hovold Cc: FangpingFP.Cheng@moxa.com, Epson.Chiang@moxa.com, EddieSY.Lin@moxa.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Crescent Hsieh Subject: [PATCH v3 4/6] USB: serial: add generic write control callbacks Date: Tue, 11 Aug 2026 14:04:59 +0800 Message-ID: <20260811060501.2307836-5-crescentcy.hsieh@moxa.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> References: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TPYP295CA0054.TWNP295.PROD.OUTLOOK.COM (2603:1096:7d0:8::6) To PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR01MB5405:EE_|TYZPR01MB4211:EE_ X-MS-Office365-Filtering-Correlation-Id: 888bc4a4-d9ba-4950-9f71-08def76e9cd1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|52116014|366016|1800799024|376014|10067099003|56012099006|18002099003|22082099003|38350700014; X-Microsoft-Antispam-Message-Info: dbpe4iPhP9qOgwlPDrA61tLYFcA4IjunOvOpv90OpQ/GRq1+JXHO0LIW/40IoiGcZleayU+95qA15mpUyDPOqvxLbXdS8Ty8aeojcN6zoMyjx7fiug1OscHshOUYEm5ogZ7pfcbHDeVbVR8aEhH9Sl4jMlqOrHuy3qHaIrRG4khe7Udx6EjaJlymkpQqrhGIVd5iBx6MWbjd5HwCrj6xE73+ZF1yCVzs7n1DiFO2AaLBZUvkOmrkqjLgTxHMI7iNZ27fWypruih1TrocV2Kagl2Sq157p/rWfJjvTUBxibmjAYVUPdYDHTxvBG7DHjQb+QUWrJ7Q7UdynxpjcQxfRnGrKuQhNVZ3FJKxZ0X5E2bSlLCWwU2TVReuQjZSkfMKSLat6A8FcWpVSoEBRT3IURW57JlsNMKG2S0CZVnE3z6TH0lyZxJsAylMN6HLoC2mZoUP4TBPlRatDvzoxKAEOxc57rHrKPrGd+cn8uTYZQ+gWS8z7jdYzDA9I2HX5c2JSR/IOmzYlQbAcZZmfdiD+YhdZN/6VwLkHBhQbUxsWqA1Kl9dPoAHVb8PSZchGXDxcpkeDHpDprv8TTDkTDQEAz21M62//2n9ezbUZKOZdQ1IxhFJV/TL+6h04JYff0eodxrQYa4siRmpepR5LF5KLE+dotQ5O2IXBWERK8vCWLcXZ9qRGhCQiCfUI13Yf7LC5vHvNEoF+/Ma8tvXSW1qxRMEkVJ7/zqTcaVx517zWrM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR01MB5405.apcprd01.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(52116014)(366016)(1800799024)(376014)(10067099003)(56012099006)(18002099003)(22082099003)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?a86lRRKZB33DHbx6Ri+wgPtOGPkbp4WbDmACZfTpdJUPM+6fC66osDMDciLb?= =?us-ascii?Q?da97GVSoFZ97xP5NwRYj3l70aCA9f37uccQoqY1mbgRDUkH0Tk/Af0vd7Ef+?= =?us-ascii?Q?CuY1+kJg6sTmb/bxW+PMVefocJ8AIj7y2OM6rOY+3HLLfFQumnszvCDExvlm?= =?us-ascii?Q?gLnaaqEILrlgwlXhbEKp5EmoR4i8ZVskzEGUrKd7IeI+QNagRUDds4PfgePT?= =?us-ascii?Q?BM8kYR1/k0OzrAWyOROdvkL99VIBUSZX6kE5eEiAss+7PcUKut/6+1hCxxTb?= =?us-ascii?Q?qMy4aP/gBFhJoljijE6IUqcsZ4GUYQyzMGFEyHy2xBow1md3yp9lvEQ4yTAS?= =?us-ascii?Q?zfCD8j2wLAob70jhvO2vbyKjxNJqsZzXvFWa+mdN2anB++xhCfbhSm9xQm6Z?= =?us-ascii?Q?Bo1GWYeT+9TaLWIAi+lqHBT7CT9TeWZsxeHP8xNhhPVDz2fG3UXMwfrWepWE?= =?us-ascii?Q?XzGMo4Cvl4GRplMAlTPDG+v6gJTQsIH9F6Y+rpzCHA4vlfbo/GvGzvNOtaS9?= =?us-ascii?Q?R4eM7C0Z9XjiHK1z0pidTIy1Cq6Gf+A0N+K8pokm3DaOuyp5NIwI9GESEOi9?= =?us-ascii?Q?0RH3XJGIRjlY05iHEDBd3mrMuj0EOsR9QZ+9CfS9sJ5Gp9DYa1L1VaG0jUg6?= =?us-ascii?Q?idfKF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Yv9ourvYhJ?= =?us-ascii?Q?cTHK/9GKD63qxHIQ8roCaGnILYtfEhVFNeV7a4lAFZXhFkcEhy3et+mKRgql?= =?us-ascii?Q?Aj6ORw0PMKbDcfW7tHUXGaStGn5GrBfwe21mYfUb1fYCaapEl4gHYNgyp/Rn?= =?us-ascii?Q?CcXG+hiPyJeugS7saHO8yTWlNMluJztgbmhasNug+FwLFHYtVKxy0G5SXZoX?= =?us-ascii?Q?yuP6gtjZiZdjMq7OJXTOl+l/pnIR7zY=3D?= X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: 888bc4a4-d9ba-4950-9f71-08def76e9cd1 X-MS-Exchange-CrossTenant-AuthSource: PUZPR01MB5405.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2026 06:05:58.4679 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5571c7d4-286b-47f6-9dd5-0aa688773c8e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rzm4qHLTXtCDLvNh/QFHsSu7mEFVMrcz/fqW4XX0QTZQLaPrmVl8ppL7PvZ0sd2jI+1NnOVuwJXPSc+aQJHzHlXBfz1qPr2FU+NGp5fU56c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR01MB4211 Content-Type: text/plain; charset="utf-8" Some USB serial devices use device-specific flow control to determine whether write submission may proceed. The generic write path currently provides no way to pause submission based on driver-specific state. It also provides no way for a driver to restore its state if URB submission fails. Add an optional write_ready() callback to struct usb_serial_driver. Call it with port->lock held after confirming that data is queued and a write URB is available. If the callback returns false, stop write processing and leave the data in the FIFO. The driver must call usb_serial_generic_write_start() when writes may proceed again. Add an optional write_rollback() callback for restoring driver-specific state after usb_submit_urb() fails. Call it with port->lock held after restoring the generic transmit accounting, and pass it the length of the prepared transfer. Drivers which do not provide these callbacks retain the existing generic write behaviour. Signed-off-by: Crescent Hsieh --- drivers/usb/serial/generic.c | 12 ++++++++---- include/linux/usb/serial.h | 9 ++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index 6eaf74930aa3..bb042b97893b 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c @@ -152,6 +152,7 @@ int usb_serial_generic_prepare_write_buffer(struct usb_= serial_port *port, int usb_serial_generic_write_start(struct usb_serial_port *port, gfp_t mem_flags) { + struct usb_serial_driver *type =3D port->serial->type; struct urb *urb; int count, result; unsigned long flags; @@ -161,7 +162,8 @@ int usb_serial_generic_write_start(struct usb_serial_po= rt *port, return 0; retry: spin_lock_irqsave(&port->lock, flags); - if (!port->write_urbs_free || !kfifo_len(&port->write_fifo)) { + if (!port->write_urbs_free || !kfifo_len(&port->write_fifo) || + (type->write_ready && !type->write_ready(port))) { clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); spin_unlock_irqrestore(&port->lock, flags); return 0; @@ -171,9 +173,7 @@ int usb_serial_generic_write_start(struct usb_serial_po= rt *port, spin_unlock_irqrestore(&port->lock, flags); =20 urb =3D port->write_urbs[i]; - count =3D port->serial->type->prepare_write_buffer(port, - urb->transfer_buffer, - port->bulk_out_size); + count =3D type->prepare_write_buffer(port, urb->transfer_buffer, port->bu= lk_out_size); urb->transfer_buffer_length =3D count; usb_serial_debug_data(&port->dev, __func__, count, urb->transfer_buffer); spin_lock_irqsave(&port->lock, flags); @@ -188,6 +188,10 @@ int usb_serial_generic_write_start(struct usb_serial_p= ort *port, set_bit(i, &port->write_urbs_free); spin_lock_irqsave(&port->lock, flags); port->tx_bytes -=3D count; + + if (type->write_rollback) + type->write_rollback(port, count); + spin_unlock_irqrestore(&port->lock, flags); =20 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h index 534e6650e2aa..d44ae5a9bf5d 100644 --- a/include/linux/usb/serial.h +++ b/include/linux/usb/serial.h @@ -305,9 +305,17 @@ struct usb_serial_driver { void (*write_bulk_callback)(struct urb *urb); /* Called by the generic read bulk callback */ void (*process_read_urb)(struct urb *urb); + /* + * Called with port->lock held before preparing another write URB. + * Drivers returning false must restart the generic write path when + * writes may proceed again. + */ + bool (*write_ready)(struct usb_serial_port *port); /* Called by the generic write implementation */ int (*prepare_write_buffer)(struct usb_serial_port *port, void *dest, size_t size); + /* Called with port->lock held to roll back a failed write submission */ + void (*write_rollback)(struct usb_serial_port *port, int count); }; #define to_usb_serial_driver(d) \ container_of(d, struct usb_serial_driver, driver) @@ -436,4 +444,3 @@ module_exit(usb_serial_module_exit); usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids) =20 #endif /* __LINUX_USB_SERIAL_H */ - --=20 2.53.0 From nobody Tue Sep 29 07:41:36 2026 Received: from SEYPR02CU001.outbound.protection.outlook.com (mail-koreacentralazon11013020.outbound.protection.outlook.com [40.107.44.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B63F938AC96; Tue, 11 Aug 2026 06:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.44.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428369; cv=fail; b=DWj92Ygg9lSpYilKyok5vk7/vjb3X8qqN21ZMm37OA/QoBD7zwUT1eP7j2KO+yJe3f0e7grV1Jv/O4FVgArh81Wf4RTPArYz6yu4mc8oRmsXg3pImXmj8rwyQR5s5otJskXdD70LOfwwcDxV3/Uenu5B8Ztx/M2z8tsGztm0VLs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428369; c=relaxed/simple; bh=6CTk8lRDwWxjYcd6UX8paRaWVsfXiMF6zol4BSRmIp0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=E/4FhnBb9hZVmiz+0vBUrJfkl71WB736vDgjjEz7u4a32WDT9Jd84MhEuvIXQZ8Wm4RGR4w5M1kmnHLOhlM34uJjwzgNPD2MgBOsZPEYX51zdqWcZKaKpS7TdWGDfciTVJcLYkgD9banJ9zLkpf9+AoovC5nfFwHekCSl5NBBi8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com; spf=pass smtp.mailfrom=moxa.com; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b=JLTnVmvR; arc=fail smtp.client-ip=40.107.44.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=moxa.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b="JLTnVmvR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XlOZPympZ4AzSoiSk2zAkUoVKezNwzCB9eMYJ+Bi166p4BOVtgKcbRUKWnK4Y8MQ0uPTWehQnQ95Aiqi0Uxmc0oDHSJWmrNA8X8h4mqiFDSZJCg/pUtZig1MzdVY1pJA1WvrBtWAx4KXpkPa5AZa+w1xw8YrPY1VB6vrOSdGhY7XkljkcwsDGPzFtJMU4i8jdvQNNepCF1BIiSxsaeZIFs8s58aGl9kGFbwTfOepGCFFutgoiriJq0L025TG2nfGdaMUY/SlwZ8jZi1lQcGO5BBqt211j0Pyaesd0fDw+591Cg62Nlt3v2tBy2GN1DNLPzEncMJ8MbHOc+GIdrYn6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=dcXXlzirzCE7BEV1hB9yXsBrtxM3DVLOvkXoeacLo04=; b=ayjAJY+cj1MJWrLloSPkBc+ZdaJhGve4h7W4BnLAMR0ZQXKF04QKfhcnRTRpq4vNIUfuBcSY6QcuRmOWL3K4cFecKk4x3VySlD07ezhi7Zv9Ad9HHLsgO2tGF1b59oYR4JXrfFO1HPptqVWh7ZY311YKlmw+b5pc6LEsWU9c7RGJ5whBeug9dWXnIhOfWPEzQ4mrUGzKyv46Igm+BeOIkbODYVWnz0PG9O2L3Wsr/LiGR/JEUHtzSUTf4WMYjdAfwcJ5riG96icdvLMt6tvZ/oA4//7jFkk0gNVynjcVmeFRLgZ+Eo+7Desixs1ShQj+0qIX9j+CTIonCSymorWaoA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=moxa.com; dmarc=pass action=none header.from=moxa.com; dkim=pass header.d=moxa.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=moxa.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dcXXlzirzCE7BEV1hB9yXsBrtxM3DVLOvkXoeacLo04=; b=JLTnVmvRftpggORrnRLuN3+RaSh8CB3vViovHG+WrvhIfTOWWDJGV3buuhuqVGgXYTwUObRKbgnaL3J5qqEDHB7tYG7e+SwbaxXhUEr3/4c1RDCSDV3Mh2hCfQMbQvfrWL4MwoUer+93wZl1giEOhNBoFM2aIp1/PXgIYagHfpQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=moxa.com; Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) by TYZPR01MB4211.apcprd01.prod.exchangelabs.com (2603:1096:400:1c4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.25; Tue, 11 Aug 2026 06:06:00 +0000 Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717]) by PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717%4]) with mapi id 15.21.0292.024; Tue, 11 Aug 2026 06:05:59 +0000 From: Crescent Hsieh To: Greg Kroah-Hartman , Johan Hovold Cc: FangpingFP.Cheng@moxa.com, Epson.Chiang@moxa.com, EddieSY.Lin@moxa.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Crescent Hsieh Subject: [PATCH v3 5/6] USB: serial: mxuport: handle SEND_NEXT transmit flow control Date: Tue, 11 Aug 2026 14:05:00 +0800 Message-ID: <20260811060501.2307836-6-crescentcy.hsieh@moxa.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> References: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TPYP295CA0054.TWNP295.PROD.OUTLOOK.COM (2603:1096:7d0:8::6) To PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR01MB5405:EE_|TYZPR01MB4211:EE_ X-MS-Office365-Filtering-Correlation-Id: eb9deca0-bec3-4803-0133-08def76e9d5c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|52116014|366016|1800799024|376014|10067099003|56012099006|3023799007|18002099003|22082099003|38350700014; X-Microsoft-Antispam-Message-Info: NZ0amk72WJfhYgIIRUulzBWBUVKfaV+FqiWDUT5vuBYxCux1YthkI86QT5GbjKwYoYcs04hS4rzJX90Vb3LtQUN/jwq8i/kwJdn4PvJtJJiHhE08fKXPGTU4+kIFx2493UPFBLpBb2NRYl/a3Yc4cz3RXzylB93Ik9e52u/INm+vypQFB1jRw7THkmW9h+KjDW1BH04Jnm191x4V9nIHLZS9bKUCKet3ebBwLYy7EkJD52rDs/5w7UGEGYfrEMcycMab85m9fq960R+rSa1wEgzIE4P2xzkvcJxPnP1oGKfmTE53pq8HWmQ7g3MIZWTyiZ7fMRvvD/E0z1eViPGbBKe+W85FngaioYrUoxko8hI1vTcumaYZD4ow105j7e1DSC3KXlCJ+sb+FXJU5Xaci397G/Cna/z4glJvPFRAzfCT6K8GkCRmgbkKIPm4uAEy2dBg/tf3iiwu+qSCWVSNsGhgfnWI0sqdHkUB+xc9e8PyJs+dp5MtNnOSdSWAceOqpl5AR5B86sQ6OeKV/rkdpfHIwuAAiDcL6ioiJ0AzmfCnnVsuctywMzsQARH+NdovL1SVzggCQ+MQWFzr6C0vvdH+DBzZDwilXAW5BIKUxXvsCuWG+C5Dlxzkwtmumaotc5U6CkuQ3dM1bz0znqpK/a6seFSMD8Xy5IBOGNXoDJ4mm1WFX2hxWQ6qlmDrc22ToJO04ZZ5umL14bF+WVIFrLTxP8LIr7mW++x+zieLWaY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR01MB5405.apcprd01.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(52116014)(366016)(1800799024)(376014)(10067099003)(56012099006)(3023799007)(18002099003)(22082099003)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?SYyAR3WQwo8hkLGoCiOXncK9EhqDvBGj7V7TKyEwJZMvqxuQbIQ7zRSXvCf+?= =?us-ascii?Q?luz9NsRV+uQtD6PqSBo7OiCQdv2q4nyZWdiimZgUGKbiU52DQCKlfEyYVJCT?= =?us-ascii?Q?WkXll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zByCa?= =?us-ascii?Q?U/MD078ok7KGkmEW/lSQ8w6RzV6d/CWFsOp6pTCFw7fpjFTCnwk468/c3h8C?= =?us-ascii?Q?iFT6YFfF0V0ak6/nZSC5EX5xGTWTnLYuOLOWFeMVKvNdkZiIeQxNOH64WIBC?= =?us-ascii?Q?E/W+CarLkyDl+7sUVuqQ1AlahBUBAZ8q30vQPJ+AqD2+jDjlZ256ZiwKFmhU?= =?us-ascii?Q?TBIoPwQgceARS74+XFgztsG/PQu+dUX7NL9WGqffytbrnxBl2zz++f8aX7b9?= =?us-ascii?Q?uCr6ppPeGNNdPvt8aqIoXKsZfPgqm/dML6iiYIxLo1/VfoSQ6jsDVryb/Azk?= =?us-ascii?Q?7JoZ07mYYEgeNz6qbO9qLHUMa+srDJLLI3SrormV9pbNKM4iDl1cChwnlJ1A?= =?us-ascii?Q?a9Is7FXuVS1qvrUt/a2aekGE/JiOVguoc4S8wL5QZIy6a9FggTCREu2xFhuz?= =?us-ascii?Q?zbsZqP0MWH62NYUkDh+PILiwDhPCz/kKezdXh7Lk306gfoXxTvfpukttLs0s?= =?us-ascii?Q?RSbQMWNcnsV0knXNqlvNU4gYmWpVXbdexuStd1wyEhvmEZc7CvATZciWZMIe?= =?us-ascii?Q?oj2wdaHysaIc722LRO4XB10/x3roOYUx9iQyTkmbG4Qtmfw0FtoztC3RKfr/?= =?us-ascii?Q?AtITLtA3GveaNIgRiAZzzkaY0UGKDYWtyHgFr2WU7HoEk7JIJ5bsBs/mV2XW?= =?us-ascii?Q?c2x5eWZ0M7rjllEN8VnUwihwbLznSqOMXYHg4EWLEur4veC1tIsps7RdxRjN?= =?us-ascii?Q?WEeK+hYlTabWNBrwtKAE8RP2U9yaOgQ=3D?= X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb9deca0-bec3-4803-0133-08def76e9d5c X-MS-Exchange-CrossTenant-AuthSource: PUZPR01MB5405.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2026 06:05:59.3356 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5571c7d4-286b-47f6-9dd5-0aa688773c8e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: P6+ac/1GA/o1tp7BETJsOmLU1d3/EQ+Xi8tip0hys4hiK9GJYAnsHeoU1/SLgFtZasQUmGx15Aq4q3XCTUmLAxgCRC4xSMfVimcb/lOsMPA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR01MB4211 Content-Type: text/plain; charset="utf-8" The device uses a per-port SEND_NEXT request and event to pace host-to-device transmission. During burn-in testing, sustained writes without waiting for this event resulted in per-port buffer overflows and data errors. The issue can be reproduced on existing G1 devices as well. The driver initiates the protocol by setting the SEND_NEXT bit in a bulk-out header and then stops submitting data for that port. The firmware reports a SEND_NEXT event when the corresponding per-port buffer is empty, at which point the driver resumes transmission. Track the payload placed in bulk-out transfers for each port and set the request bit when it reaches bulk_out_size. Use the generic write control callbacks to hold further submissions until the event arrives and to roll back the payload count and hold state if usb_submit_urb() fails. Use bulk_out_size as a common threshold for all device families instead of encoding their firmware buffer sizes in the driver. Signed-off-by: Crescent Hsieh --- drivers/usb/serial/mxuport.c | 61 +++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c index 35123572ca4d..96dc85defb0b 100644 --- a/drivers/usb/serial/mxuport.c +++ b/drivers/usb/serial/mxuport.c @@ -156,6 +156,8 @@ static const u16 mxuport_mux50u_fw_ver_offsets[] =3D { #define UPORT_EVENT_LSR 4 /* Line status */ #define UPORT_EVENT_MCR 5 /* Modem control */ =20 +#define UPORT_REQUEST_SEND_NEXT 0x80 + /* Definitions for serial event type */ #define SERIAL_EV_CTS 0x0008 /* CTS changed state */ #define SERIAL_EV_DSR 0x0010 /* DSR changed state */ @@ -202,6 +204,8 @@ static const u16 mxuport_mux50u_fw_ver_offsets[] =3D { =20 /* This structure holds all of the local port information */ struct mxuport_port { + u32 sent_payload; + u8 hold_reason; u8 mcr_state; /* Last MCR state */ u8 msr_state; /* Last MSR state */ struct mutex mutex; /* Protects mcr_state */ @@ -256,6 +260,13 @@ static const struct usb_device_id mxuport_idtable[] = =3D { =20 MODULE_DEVICE_TABLE(usb, mxuport_idtable); =20 +static bool mxuport_write_ready(struct usb_serial_port *port) +{ + struct mxuport_port *mxport =3D usb_get_serial_port_data(port); + + return !(mxport->hold_reason & MX_WAIT_FOR_SEND_NEXT); +} + /* * Add a four byte header containing the port number and the number of * bytes of data in the message. Return the number of bytes in the @@ -264,22 +275,40 @@ MODULE_DEVICE_TABLE(usb, mxuport_idtable); static int mxuport_prepare_write_buffer(struct usb_serial_port *port, void *dest, size_t size) { + struct mxuport_port *mxport =3D usb_get_serial_port_data(port); + bool request_send_next; + unsigned long flags; u8 *buf =3D dest; int count; =20 - count =3D kfifo_out_locked(&port->write_fifo, buf + HEADER_SIZE, - size - HEADER_SIZE, - &port->lock); + spin_lock_irqsave(&port->lock, flags); + count =3D kfifo_out(&port->write_fifo, buf + HEADER_SIZE, size - HEADER_S= IZE); + mxport->sent_payload +=3D count; + request_send_next =3D mxport->sent_payload >=3D port->bulk_out_size; + if (request_send_next) + mxport->hold_reason |=3D MX_WAIT_FOR_SEND_NEXT; + spin_unlock_irqrestore(&port->lock, flags); =20 put_unaligned_be16(port->port_number, buf); put_unaligned_be16(count, buf + 2); =20 + if (request_send_next) + buf[0] |=3D UPORT_REQUEST_SEND_NEXT; + dev_dbg(&port->dev, "%s - size %zd count %d\n", __func__, size, count); =20 return count + HEADER_SIZE; } =20 +static void mxuport_write_rollback(struct usb_serial_port *port, int count) +{ + struct mxuport_port *mxport =3D usb_get_serial_port_data(port); + + mxport->sent_payload -=3D count - HEADER_SIZE; + mxport->hold_reason &=3D ~MX_WAIT_FOR_SEND_NEXT; +} + /* Read the given buffer in from the control pipe. */ static int mxuport_recv_ctrl_urb(struct usb_serial *serial, u8 request, u16 value, u16 index, @@ -498,14 +527,24 @@ static void mxuport_lsr_event(struct usb_serial_port = *port, u8 buf[4]) static void mxuport_process_read_urb_event(struct usb_serial_port *port, u8 buf[4], u32 event) { + struct mxuport_port *mxport =3D usb_get_serial_port_data(port); + bool resume_tx =3D false; + unsigned long flags; + dev_dbg(&port->dev, "%s - receive event : %04x\n", __func__, event); =20 switch (event) { case UPORT_EVENT_SEND_NEXT: - /* - * Sent as part of the flow control on device buffers. - * Not currently used. - */ + spin_lock_irqsave(&port->lock, flags); + if (mxport->hold_reason & MX_WAIT_FOR_SEND_NEXT) { + mxport->hold_reason &=3D ~MX_WAIT_FOR_SEND_NEXT; + mxport->sent_payload =3D 0; + resume_tx =3D true; + } + spin_unlock_irqrestore(&port->lock, flags); + + if (resume_tx) + usb_serial_generic_write_start(port, GFP_ATOMIC); break; case UPORT_EVENT_MSR: mxuport_msr_event(port, buf); @@ -1353,6 +1392,7 @@ static int mxuport_open(struct tty_struct *tty, struc= t usb_serial_port *port) { struct mxuport_port *mxport =3D usb_get_serial_port_data(port); struct usb_serial *serial =3D port->serial; + unsigned long flags; int err; =20 /* Set receive host (enable) */ @@ -1373,6 +1413,11 @@ static int mxuport_open(struct tty_struct *tty, stru= ct usb_serial_port *port) if (tty) mxuport_set_termios(tty, port, NULL); =20 + spin_lock_irqsave(&port->lock, flags); + mxport->sent_payload =3D 0; + mxport->hold_reason &=3D ~MX_WAIT_FOR_SEND_NEXT; + spin_unlock_irqrestore(&port->lock, flags); + /* * TODO: use RQ_VENDOR_GET_MSR, once we know what it * returns. @@ -1466,7 +1511,9 @@ static struct usb_serial_driver mxuport_device =3D { .tiocmset =3D mxuport_tiocmset, .dtr_rts =3D mxuport_dtr_rts, .process_read_urb =3D mxuport_process_read_urb, + .write_ready =3D mxuport_write_ready, .prepare_write_buffer =3D mxuport_prepare_write_buffer, + .write_rollback =3D mxuport_write_rollback, .resume =3D mxuport_resume, }; =20 --=20 2.53.0 From nobody Tue Sep 29 07:41:36 2026 Received: from OS8PR02CU002.outbound.protection.outlook.com (mail-japanwestazon11012060.outbound.protection.outlook.com [40.107.75.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D66AC381B01; Tue, 11 Aug 2026 06:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.75.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428369; cv=fail; b=T80YuP1OEjDbVUKfm40GNnK/BLYsHVJOO8JJgi16lNBx7bYXMKahYO67Ff+lwgkqhRxSmox9j7VS4v2KYuEWbNWzFjTH7pV5sDwqtvyFvc7dEacZyZGmw9bT8cRBV5L9FcNiOtMqkv/bzquixzPR3ksy0MA9JBwJntsg5mAjZYw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786428369; c=relaxed/simple; bh=aMZAJbY5saOrGosMx7I+t0nEQyOVHtG80YEX14Rdh9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=JJrE9G6HhkududqzWV7NwfWHOnfZ6nqX7eVRdCU4B9txzUAYCEFNoChhetyWenjWSeRn+SrYF+72UK59umNzGarNaA0y9Hq90S9q/ej6TypoqM2gGWSlaN0qa6md1Oax5eO5MLBl0l93UyG7lE52HJip/CzDuZ2ud1cR8PVLgKo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com; spf=pass smtp.mailfrom=moxa.com; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b=URIwTZ8S; arc=fail smtp.client-ip=40.107.75.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=moxa.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=moxa.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=moxa.com header.i=@moxa.com header.b="URIwTZ8S" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oUKwyOHv2uTCFX82CDnGcmcEHvho1s/XjfJa2coewW1jgzQlH0ceTgF8bsd+3nZ2XCfNeOuMD9SOQRXbgH6pvUsPHwsQM+C7B82HMuQl2YexeM4Vi/Wq7kjqZJioBc1hPWQDYaZcUhzehVbJ0UnupUJnAlYH1MnVFBroMH5SCVnA9G4V8Q3hzneWlXFabAtxl5JOzmGU5/wSbnRaGXCKt2yvtIalqkCQNL9dR9aGvAP+9CAHZ31ecGf0J0sgjYS7vdW8l2ynI7v6zC8MiaWpb9Gwg22KpIzeBfcivETW17535Rc+02RqgPLZLRtAUUuSzrH7jzjlLKIm7FanavY5tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=WYComLqmOmmjy43m1n2x0BIar+Qcpslfx8LgCvbNB6U=; b=jdBz8cU/VblCEG57rOzGs9PKMnlcLtzMVyM8hYjsvVTjjnI37Vo+zJSicMXSdIT8g9tXyNfC1USI94jlaRALPr/3UExuOFHa5YRzK8KaUi6QWE7W+6swVxuAqL1B4L7wAGvNXFfLHwQ1O5aYVmvlAB8CIOmzk5N8856jqpcV4O7K7GimAa4b5APtlTPB78T84aS1M6k6lxCZ+G2ev/mvgLWQjfVT6XqGejVuCEkpCt75oxrwkSlV2qyjr4U3cJFcrgIuPtwNk6kSiuvvyAk9ePSPg9W/Q9YY6raHMQHrmJmCKn7l596So+JFGILHsB/kGXf+BYFloCYrCmIeBjFS3Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=moxa.com; dmarc=pass action=none header.from=moxa.com; dkim=pass header.d=moxa.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=moxa.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WYComLqmOmmjy43m1n2x0BIar+Qcpslfx8LgCvbNB6U=; b=URIwTZ8STqHhvwloY8OvFDYE+ab8FUFxhQTQ4/mtO8sMEqX5/su7FXKdWQfqMQW8101+SaKHcTof9921+Wm1xQHBUrpd1fiY3oR7qxX750YS2PegOZdoUgGTgdrnrTR9Ai7lE928NsPOK0OxDymSqq3wH+o+mMIcajB3F0O3F2A= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=moxa.com; Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) by TYZPR01MB4211.apcprd01.prod.exchangelabs.com (2603:1096:400:1c4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.25; Tue, 11 Aug 2026 06:06:01 +0000 Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717]) by PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::ae38:e821:cf7d:3717%4]) with mapi id 15.21.0292.024; Tue, 11 Aug 2026 06:06:01 +0000 From: Crescent Hsieh To: Greg Kroah-Hartman , Johan Hovold Cc: FangpingFP.Cheng@moxa.com, Epson.Chiang@moxa.com, EddieSY.Lin@moxa.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Crescent Hsieh Subject: [PATCH v3 6/6] USB: serial: mxuport: support RS485 mode configuration Date: Tue, 11 Aug 2026 14:05:01 +0800 Message-ID: <20260811060501.2307836-7-crescentcy.hsieh@moxa.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> References: <20260811060501.2307836-1-crescentcy.hsieh@moxa.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TPYP295CA0054.TWNP295.PROD.OUTLOOK.COM (2603:1096:7d0:8::6) To PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR01MB5405:EE_|TYZPR01MB4211:EE_ X-MS-Office365-Filtering-Correlation-Id: 09610100-f68c-4a2f-9bed-08def76e9dd7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|52116014|366016|1800799024|376014|10067099003|56012099006|6133799003|18002099003|22082099003|38350700014; X-Microsoft-Antispam-Message-Info: LOEofcqTPrukA/4CrkXHfYTGH/DWZy8nA4ybEmw6mIqICDH3h0gaNh1g2gizXANBDqL+Do6+XDwhGXvtAv5gpfJG8pOA3LjAtKf7qYY7dfA+3DuO1DFgdKIHM6nnodUgHPyDFxwVvpfd5FZJGv6+y8dDFiAM75ZTgGBXWAs0CY2lh4W+MF5UXwSxhebAWl5hSnN0pMbT9uFtscGie22mRLTJvAlKn7IUmFXasanoIzu9lgyMJ0qTBNYsboIqS3yXbUFVSTtLPf5WCdhRnzsSjPMZJ9P7md2ZeOTdJ2Cfem46cgIzJbRm7Zjd4/MbONKQ5ItJg0xMuU3I/UXtrsSV9U0VaVWmqK3yNyBGkbxQ79tfr0DvBMuA2m7h7Q5ffZNleofIfILuyANgKxlj/wHp8qyUXdPBi8mfrFrEz47vIB+aN/wxLchUmLLO1DS7nMi/dNsTOyTo7J1X9/HqTp9lAZOYCPLBzn2ht4txw5yxbzp/vjyYpW4jWHDlWsuKNN0piZaBZhI5exX3Jm/DvvhznxtpYuB73RV7XBhNUN/9VhjfuYy1IQT25pPwnZOCvcgx/V8jquEyBkxBlbAd6me8pMAVeIFGLuMZ7fmE0CsGPT/LUIQq6On/Xp2p0jHppaAO1Msp3F1/En/Ow/kXgUQvz8b+163jZH9JjOtrKIl3DWSNFLCC9vTWJ3Rqlgcr9EgqmdX0lMV87sCYaai0ZmDdQ4BixaVcXSoHJSwe1t/UgAY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR01MB5405.apcprd01.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(52116014)(366016)(1800799024)(376014)(10067099003)(56012099006)(6133799003)(18002099003)(22082099003)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Hk2nHuE+IwYnpIiFPaCpC7YKwbyT09AQZfea7bj78SAzGjO+PiUAcgV2geoF?= =?us-ascii?Q?GJ24+GyUWyNsvsgj5wGqxA54aoCgAE4YWxmAOJewuHOBROjg570Dy6KvhADy?= =?us-ascii?Q?YDVKd+wsPS+kr0xFw+CgBlBaFs5pLtDIiyICQiAvvYuDilaIea+iKyPePmLU?= =?us-ascii?Q?B5C9aPVAcm0nCC8IgX9eXRO/J4uiCQ+ciDWeik3y6eGfYKo0E3t6G9D1S7XO?= =?us-ascii?Q?pt/HKnezErtQDpyfU/CGykSMIY887Dyk7vditcRRmY2Zyw+Y/Y0kyFgHkTwA?= =?us-ascii?Q?nAAUL8GmbTamEKXa1dHUBOtgQlpenfj+ZAG5oB3ZNktZWIQn+YACSwHc2ItW?= =?us-ascii?Q?Ifhua6nejETQtOYafkG6G8TfV3eIQy3+e3sxG5MlcULWtpFRrR3Dj2/PJLyI?= =?us-ascii?Q?XXHWLGQyPTISsz8xTDLZ78yQ+DzQhzGyIUZ11Y/251cp3P5ezWXGQlOxDB6p?= =?us-ascii?Q?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zAjkiObl2/5Ks?= =?us-ascii?Q?lTZDRrTKhqUggV3E5lhwKjVFmE4k9j7FGHgOEm6tsGWCOfUpY9rm3urQ59HD?= =?us-ascii?Q?UfwVpDS2MJdnH74A/VXYFqzwG3Ty6NMX3blkLZiXO8eIRLjS7yPFc9LCeEKJ?= =?us-ascii?Q?701qFvfgRha/4uIFuok8jTHVAOOBsh0uevDVbI4jwi17MZE51y/R3gRN8q3m?= =?us-ascii?Q?ba3Klq/+MYsZXPBdV2t3rdNmFrBrIBPzzUbGO4ktP79L8I4S55i3+8HS+/1r?= =?us-ascii?Q?DZOuQ0X2YTWO2Dpi3hwKaLAn0yNOJvJnR4lM9L7yuYnobpohG1xEK89ZxpJ9?= =?us-ascii?Q?jQQWYuDCi9+qiE3fDSDM3KlXUjUlWKM5g6DlUmoDep+zF5T7ak7PfiSgX+IL?= =?us-ascii?Q?0Mla0Vzc6AKEWXO+N7Wb8q894Eu+jeg=3D?= X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09610100-f68c-4a2f-9bed-08def76e9dd7 X-MS-Exchange-CrossTenant-AuthSource: PUZPR01MB5405.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2026 06:06:00.1774 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5571c7d4-286b-47f6-9dd5-0aa688773c8e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: MhWxwfSMY64CkQfU+0I8FsZrKYzDn3L6QzMUsrqsSuvsFNM5UegeebIRkypIeT/QyIVUDhAF0+uKYK6C56DdMJgAKlPWAFS/0xliVYL3PGA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR01MB4211 Content-Type: text/plain; charset="utf-8" Add support for TIOCSRS485 and TIOCGRS485 so that userspace can configure the serial interface mode using struct serial_rs485. Map the serial_rs485 flags to the device interface modes as follows: - RS232 =3D no flags set - RS422 =3D SER_RS485_ENABLED | SER_RS485_MODE_RS422 - RS485_2W (half-duplex) =3D SER_RS485_ENABLED - RS485_4W (full-duplex) =3D SER_RS485_ENABLED | SER_RS485_RX_DURING_TX Unsupported flags and fields are cleared before applying the configuration. Cache the sanitized per-port configuration and serialize access with the per-port mutex. Signed-off-by: Crescent Hsieh --- drivers/usb/serial/mxuport.c | 98 +++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c index 96dc85defb0b..319704e64528 100644 --- a/drivers/usb/serial/mxuport.c +++ b/drivers/usb/serial/mxuport.c @@ -208,7 +208,8 @@ struct mxuport_port { u8 hold_reason; u8 mcr_state; /* Last MCR state */ u8 msr_state; /* Last MSR state */ - struct mutex mutex; /* Protects mcr_state */ + struct serial_rs485 rs485; + struct mutex mutex; /* Protects per-port control state */ spinlock_t spinlock; /* Protects msr_state */ }; =20 @@ -870,6 +871,100 @@ static int mxuport_tiocmget(struct tty_struct *tty) return result; } =20 +static void mxuport_sanitize_serial_rs485(struct serial_rs485 *rs485) +{ + if (!(rs485->flags & SER_RS485_ENABLED)) { + memset(rs485, 0, sizeof(*rs485)); + return; + } + + if (rs485->flags & SER_RS485_MODE_RS422) + rs485->flags &=3D SER_RS485_ENABLED | SER_RS485_MODE_RS422; + else + rs485->flags &=3D SER_RS485_ENABLED | SER_RS485_RX_DURING_TX; + + rs485->delay_rts_before_send =3D 0; + rs485->delay_rts_after_send =3D 0; + memset(rs485->padding, 0, sizeof(rs485->padding)); +} + +static int mxuport_rs485_config(struct usb_serial_port *port, + const struct serial_rs485 *rs485) +{ + struct usb_serial *serial =3D port->serial; + u16 mode =3D MX_INT_RS232; + + if (rs485->flags & SER_RS485_ENABLED) { + if (rs485->flags & SER_RS485_MODE_RS422) + mode =3D MX_INT_RS422; + else if (rs485->flags & SER_RS485_RX_DURING_TX) + mode =3D MX_INT_4W_RS485; + else + mode =3D MX_INT_2W_RS485; + } + + return mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_INTERFACE, mode, + port->port_number); +} + +static int mxuport_get_rs485_config(struct usb_serial_port *port, + struct serial_rs485 __user *argp) +{ + struct mxuport_port *mxport =3D usb_get_serial_port_data(port); + struct serial_rs485 rs485; + + mutex_lock(&mxport->mutex); + rs485 =3D mxport->rs485; + mutex_unlock(&mxport->mutex); + + if (copy_to_user(argp, &rs485, sizeof(rs485))) + return -EFAULT; + + return 0; +} + +static int mxuport_set_rs485_config(struct usb_serial_port *port, + struct serial_rs485 __user *argp) +{ + struct mxuport_port *mxport =3D usb_get_serial_port_data(port); + struct serial_rs485 rs485; + int err; + + if (copy_from_user(&rs485, argp, sizeof(rs485))) + return -EFAULT; + + mxuport_sanitize_serial_rs485(&rs485); + + mutex_lock(&mxport->mutex); + err =3D mxuport_rs485_config(port, &rs485); + if (!err) + mxport->rs485 =3D rs485; + mutex_unlock(&mxport->mutex); + if (err) + return err; + + if (copy_to_user(argp, &rs485, sizeof(rs485))) + return -EFAULT; + + return 0; +} + +static int mxuport_ioctl(struct tty_struct *tty, unsigned int cmd, + unsigned long arg) +{ + struct usb_serial_port *port =3D tty->driver_data; + void __user *argp =3D (void __user *)arg; + + switch (cmd) { + case TIOCGRS485: + return mxuport_get_rs485_config(port, argp); + case TIOCSRS485: + return mxuport_set_rs485_config(port, argp); + } + + return -ENOIOCTLCMD; +} + static int mxuport_set_termios_flow(struct tty_struct *tty, const struct ktermios *old_termios, struct usb_serial_port *port, @@ -1503,6 +1598,7 @@ static struct usb_serial_driver mxuport_device =3D { .set_termios =3D mxuport_set_termios, .break_ctl =3D mxuport_break_ctl, .tx_empty =3D mxuport_tx_empty, + .ioctl =3D mxuport_ioctl, .tiocmiwait =3D usb_serial_generic_tiocmiwait, .get_icount =3D usb_serial_generic_get_icount, .throttle =3D mxuport_throttle, --=20 2.53.0