Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4333863yba; Mon, 29 Apr 2019 18:24:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxpZSacXSe0fll34t4oUoE7w97SkJYcqTKYTf1W3wAgDJ3zzVLHyN9lbh2YJbfsvM7Mc7O X-Received: by 2002:a63:f64f:: with SMTP id u15mr55121912pgj.192.1556587459749; Mon, 29 Apr 2019 18:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556587459; cv=none; d=google.com; s=arc-20160816; b=SQmBqUwJpI6hQ94jTuvIWHemlURkhBAlM6B+eL9/abu/ucU4FhNw1bkQHkeg5VrM09 n6ZbjTcjl+Te3xb0ThIoMEIJALHOrBx9xX0CMuPeypzRqAJ0p/BDJkoiNWMqYHAnhA+4 AlpTE6g81bwD2wpMPCacbbwrdYjgP2sBvIOgvTtG9qKPwJCVcXQ0vE3m2bZv4AHRu5oR 8UGyWUoG7wnu5AWud0Ll41V7WdkU1+Y1zy+7e246exJKWtlKgl9D/PkBgRTl7dZXXEQh Xh78jgWg19azT7W2y7Al5apoV2rc2O4F6N72RCPLBuyowS22Fwp2cZ+31fgh2ssLTdeg lPXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=/34HtZ0ItBu2q8PiQCCmitcY2PUSurP/IKvZz4bka9M=; b=hRTy3WfZQznedT+nEJzVsgVWd3yIZDJg0QO1baQW8Kd/a6w2hKQ2XAXenkSExFA0q/ Lph3RbVJCuNaDu9LSAsPg3qLqBV/bS6uX6G0dic3+jYZPAVsUuv7Q4BwiXXuA4vwI/4X Pl4D2gJxadxv33Lek9ZM6RG7lvzIXQDGDdLZ34DYJ1sLM1VW0OFVHzENkQpP58+CSPTm k8DF/eXcAjXRsC6XXRlOeZZUJ/O+U1bsJ7WLXBx87czY0g0S/FwXaIZt0EUR10F1Aff9 m9sVGnY5rrvDgzUMAVeQorus7iiVGk/Sybd5f5U90JE47z8scRHVE69ENMAcML9QtLEU LR8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="J/pE20HB"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e15si20935779pgm.377.2019.04.29.18.24.04; Mon, 29 Apr 2019 18:24:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="J/pE20HB"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729817AbfD3BWr (ORCPT + 99 others); Mon, 29 Apr 2019 21:22:47 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37915 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729238AbfD3BWp (ORCPT ); Mon, 29 Apr 2019 21:22:45 -0400 Received: by mail-pf1-f196.google.com with SMTP id 10so6224870pfo.5; Mon, 29 Apr 2019 18:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/34HtZ0ItBu2q8PiQCCmitcY2PUSurP/IKvZz4bka9M=; b=J/pE20HByyCtHTBS0K8ialHsJw49MhV1FCQBXAT8dgF5VJ/P9TMTmVGydpAmM3BXD6 cJ2H8/4ZhNzHF/w03baN6TTQWLvqV+9FWKZ2lq4tntBV2oOrr76LvRkmb3Y7wR/ZE5pV V4AV49b2tZUiczidPJHQ9YCrR1oPQT3bqNFRCQVDZqiYFrFzu2tS9+e0khnhPyB6zU3L Mu+dzyifzVS5FWjCgVJe/u4Kg8YWJmTD+rLs16BMZ7GBx+xQK5knl1gR3tWu4U7DBY/K UKNocCw7KXUjFR6+ZLZCCdBBRJ01QP9NU2AaiXe0fUuJUeMKP2AHmn+KSxsVzVuoXqMb iwVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/34HtZ0ItBu2q8PiQCCmitcY2PUSurP/IKvZz4bka9M=; b=Gcv/rtGejbMdCVqn0WiRixRG0s0M4DSbzI4B2TL1oiSxCrw6qnH8tppvCD2ByOIkGR BMdeH/VZXz7FxH/dlQbYCORIYwEzyPDd3qzkTfDzD3tvkoSrrCpnBHoJsekgoKhjZlhQ d5DVduHVutMda3fvH6WE4zJp7riYCHbZ9sBeW6rLr5yhlj5714+FsR2gLjkIMF64XbRV A+M0mgB7lxXhw+DpYOdIkvCk8TdLBsZJ1Iz+5OTCdaJiSOLcnamv5HHKQkFwkCX9kyx/ xve/6NZYJTrocSO5cPM70IEw4OxD1LC4hAYPnyupG1CJTOkqjOa2ZyLhShnwTcJnIsct p1zA== X-Gm-Message-State: APjAAAUjlT89FaOpTY6z/zc8jaLBm+tyS4pz40lZpHgIUSrGbZPzgEgq zjeAptrorFhDvtaS+F2WkHA= X-Received: by 2002:aa7:8b11:: with SMTP id f17mr336712pfd.116.1556587364185; Mon, 29 Apr 2019 18:22:44 -0700 (PDT) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id m8sm53912262pgn.59.2019.04.29.18.22.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Apr 2019 18:22:43 -0700 (PDT) From: "Ji-Ze Hong (Peter Hong)" X-Google-Original-From: "Ji-Ze Hong (Peter Hong)" To: peter_hong@fintek.com.tw, johan@kernel.org, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Ji-Ze Hong (Peter Hong)" , Oliver Neukum Subject: [PATCH V9 2/4] USB: serial: f81232: clear overrun flag Date: Tue, 30 Apr 2019 09:22:30 +0800 Message-Id: <1556587352-19500-2-git-send-email-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556587352-19500-1-git-send-email-hpeter+linux_kernel@gmail.com> References: <1556587352-19500-1-git-send-email-hpeter+linux_kernel@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The F81232 will report data and LSR with bulk like following format: bulk-in data: [LSR(1Byte)+DATA(1Byte)][LSR(1Byte)+DATA(1Byte)]... LSR will auto clear frame/parity/break error flag when reading by H/W, but overrrun will only cleared when reading LSR. So this patch add a worker to read LSR when overrun and flush the worker on close() & suspend(). Cc: Oliver Neukum Signed-off-by: Ji-Ze Hong (Peter Hong) --- v9: 1: change the patch index from 1 to 2. v8: 1: Fix usb_submit_urb() in f81232_resume() with GFP_NOIO, not GFP_KERNEL. v7: 1: Remove serial->suspending check 2: Add port priv is_port_open to save port open state. We'll register interrupt-in urb in f81232_resume() when port is opened. 3: Using usb_kill_urb for read/interrupt urb to ensure urb stopped. v6: 1: Add deferred_lsr_work_needed to re-trigger when f81232_resume() v5: 1: Source code base revert to v3 and remove all v4 changes. 2: Add serial->suspending check in f81232_process_read_urb() before schedule_work(&priv->lsr_work) to avoid race condition. v4: 1: Add serial->suspending check in f81232_lsr_worker() to avoid re-trigger 2: Add port_priv-lsr_work_resched to re-trigger LSR worker v3: 1: Add flush_work(&port_priv->lsr_work) in f81232_suspend(). v2: 1: Add flush_work(&port_priv->lsr_work) in f81232_close(). drivers/usb/serial/f81232.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index d43ec999bc5e..f0de20a818cd 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -41,12 +41,14 @@ MODULE_DEVICE_TABLE(usb, id_table); #define FIFO_CONTROL_REGISTER (0x02 + SERIAL_BASE_ADDRESS) #define LINE_CONTROL_REGISTER (0x03 + SERIAL_BASE_ADDRESS) #define MODEM_CONTROL_REGISTER (0x04 + SERIAL_BASE_ADDRESS) +#define LINE_STATUS_REGISTER (0x05 + SERIAL_BASE_ADDRESS) #define MODEM_STATUS_REGISTER (0x06 + SERIAL_BASE_ADDRESS) struct f81232_private { struct mutex lock; u8 modem_control; u8 modem_status; + struct work_struct lsr_work; struct work_struct interrupt_work; struct usb_serial_port *port; }; @@ -282,6 +284,7 @@ static void f81232_read_int_callback(struct urb *urb) static void f81232_process_read_urb(struct urb *urb) { struct usb_serial_port *port = urb->context; + struct f81232_private *priv = usb_get_serial_port_data(port); unsigned char *data = urb->transfer_buffer; char tty_flag; unsigned int i; @@ -315,6 +318,7 @@ static void f81232_process_read_urb(struct urb *urb) if (lsr & UART_LSR_OE) { port->icount.overrun++; + schedule_work(&priv->lsr_work); tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); } @@ -562,6 +566,7 @@ static void f81232_close(struct usb_serial_port *port) usb_serial_generic_close(port); usb_kill_urb(port->interrupt_in_urb); flush_work(&port_priv->interrupt_work); + flush_work(&port_priv->lsr_work); } static void f81232_dtr_rts(struct usb_serial_port *port, int on) @@ -606,6 +611,21 @@ static void f81232_interrupt_work(struct work_struct *work) f81232_read_msr(priv->port); } +static void f81232_lsr_worker(struct work_struct *work) +{ + struct f81232_private *priv; + struct usb_serial_port *port; + int status; + u8 tmp; + + priv = container_of(work, struct f81232_private, lsr_work); + port = priv->port; + + status = f81232_get_register(port, LINE_STATUS_REGISTER, &tmp); + if (status) + dev_warn(&port->dev, "read LSR failed: %d\n", status); +} + static int f81232_port_probe(struct usb_serial_port *port) { struct f81232_private *priv; @@ -616,6 +636,7 @@ static int f81232_port_probe(struct usb_serial_port *port) mutex_init(&priv->lock); INIT_WORK(&priv->interrupt_work, f81232_interrupt_work); + INIT_WORK(&priv->lsr_work, f81232_lsr_worker); usb_set_serial_port_data(port, priv); @@ -646,8 +667,10 @@ static int f81232_suspend(struct usb_serial *serial, pm_message_t message) usb_kill_urb(port->interrupt_in_urb); - if (port_priv) + if (port_priv) { flush_work(&port_priv->interrupt_work); + flush_work(&port_priv->lsr_work); + } return 0; } -- 2.7.4