From patchwork Mon May 21 11:03:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10414687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6FC5760365 for ; Mon, 21 May 2018 11:03:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5184726E96 for ; Mon, 21 May 2018 11:03:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4658B27D16; Mon, 21 May 2018 11:03:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71F6B26E96 for ; Mon, 21 May 2018 11:03:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751234AbeEULDO (ORCPT ); Mon, 21 May 2018 07:03:14 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:45167 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751173AbeEULDN (ORCPT ); Mon, 21 May 2018 07:03:13 -0400 Received: by mail-lf0-f68.google.com with SMTP id w202-v6so23247191lff.12 for ; Mon, 21 May 2018 04:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=LDd04ZtyZZE3gY5IXY1gQR72qo07RyszVQ2FZAKJCXA=; b=TdwiRdoe8y0sdTTSa8atq1n1IhT9woTuDFeT7psn03A2a4xorWPWK7bXanTfOwVhYw tx4oJ+xFL0xvwX4Fu0N/o15+sFvLt+GV1RbRk2OPVnEVRRIQuGzWOeXpMPKHffc/F0Yt l3V4taGHtWNI9L/zc47iUSA1OPgiRJ5kE+BFSd96UtSVBLS9b6jc2NiqUxcPjty59KML Uf+1LAS8/SHAI66fbtA5A741eZss50b+MdvdqzvLIUhbhhLgFUp/tZTaoMNiJADzZs3u 1OIh9RpC9hCzYJ20LI9Rvq9kQhAKISLHd+617C3mYH95EduggTfqWTA0WlWwC0jJBnd5 /v1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=LDd04ZtyZZE3gY5IXY1gQR72qo07RyszVQ2FZAKJCXA=; b=YELcW2HZxQfWiypxFwkFk3aPfEEFi8vKQvmLIvCug2/EKyKnjzMx1ImGsk3u1MAeUg w5o8dj91KppuALNgyQ/1L/T0VVNFI0f7oY6kgrqZpx6rTXc+HXrpdv6wVg2/uzm6LRNr HT3fS1ne8YSPeTCgUFlSZ8zhlllnwdahXOkb13gzO//5Zn5h3gVRMot51Lb94EpkJJ17 YZrbUX4HO3O5YC+PPiU3zKRixg4hUQ7GroggfWsxhTvEPQ7gVbRSmow4NtNMvItgr9Aq LfHmzbPwNWi+y7eQ8Dcnd5LwMQHbirt9UtYQH23tl2zaht+dJ3qOXKfY4pDpOPjKuA3T eVKw== X-Gm-Message-State: ALKqPwcJugEjcnjmHFN0NNu9n/NelHgFdkYQiU8nhv7HTRwNOj7XX3Rc eAEvLNZPPtudiU0DzXgNdc0= X-Google-Smtp-Source: AB8JxZrm3Q4bhCsfXDcl4GXThjH7l/3R4iubzEWSKnvAjIWfert3Lb8VoupRyrsxIEIz+3OBmt5BBA== X-Received: by 2002:a2e:3c04:: with SMTP id j4-v6mr12489763lja.149.1526900591724; Mon, 21 May 2018 04:03:11 -0700 (PDT) Received: from xi.terra (c-8bb2e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.178.139]) by smtp.gmail.com with ESMTPSA id a11-v6sm2455650ljk.79.2018.05.21.04.03.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 May 2018 04:03:10 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.90_1) (envelope-from ) id 1fKiao-0007wT-2V; Mon, 21 May 2018 13:03:06 +0200 Date: Mon, 21 May 2018 13:03:06 +0200 From: Johan Hovold To: Florian Zumbiehl Cc: Johan Hovold , linux-usb@vger.kernel.org Subject: Re: [PATCH v2] usbserial: pl2303 tx xon/xoff flow control Message-ID: <20180521110306.GQ30172@localhost> References: <20180514031510.GH4749@florz.florz.de> <20180516132840.GE30172@localhost> <20180517033921.GM4749@florz.florz.de> <20180517082914.GF30172@localhost> <20180517091918.GG30172@localhost> <20180518040653.GQ4749@florz.florz.de> <20180518131659.GL30172@localhost> <20180520002312.GT4749@florz.florz.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180520002312.GT4749@florz.florz.de> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Sun, May 20, 2018 at 02:23:12AM +0200, Florian Zumbiehl wrote: > Support hardware-level Xon/Xoff flow control in transmit direction with > pl2303. > > I only know how to get the hardware to do IXON/!IXANY with ^S/^Q as control > characters, so I preserve the old behaviour for all other cases. > > Signed-off-by: Florian Zumbiehl > --- > --- linux-4.16.9/drivers/usb/serial/pl2303.c.orig 2018-05-20 00:51:34.580966124 +0200 > +++ linux-4.16.9/drivers/usb/serial/pl2303.c 2018-05-20 01:16:49.532730098 +0200 > @@ -539,12 +539,18 @@ > struct usb_serial *serial = port->serial; > struct pl2303_serial_private *spriv = usb_get_serial_data(serial); > struct pl2303_private *priv = usb_get_serial_port_data(port); > + bool termios_unchanged; > unsigned long flags; > unsigned char *buf; > int ret; > u8 control; > > - if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios)) > + termios_unchanged = old_termios && > + !(tty_termios_hw_change(&tty->termios, old_termios) || > + ((tty->termios.c_iflag ^ old_termios->c_iflag) & (IXON | IXANY)) || > + tty->termios.c_cc[VSTOP] != old_termios->c_cc[VSTOP] || > + tty->termios.c_cc[VSTART] != old_termios->c_cc[VSTART]); > + if (termios_unchanged) This is slightly more readable, but you still violate indentation rules (e.g. two tabs for continuation lines) and the expression is just generally hard to parse. I played around with an ixon_changed intermediate (which what I had in mind when I suggested an intermediate), but in the end I settled on a helper function. The result, which I've applied for -next, can be found below. Thanks, Johan From 1f09807ed52bc530a1139c6ae6092b9176ded45f Mon Sep 17 00:00:00 2001 From: Florian Zumbiehl Date: Sun, 20 May 2018 02:23:12 +0200 Subject: [PATCH] USB: serial: pl2303: add support for tx xon/xoff flow control Support hardware-level Xon/Xoff flow control in transmit direction with pl2303. I only know how to get the hardware to do IXON/!IXANY with ^S/^Q as control characters, so I preserve the old behaviour for all other cases. Signed-off-by: Florian Zumbiehl [ johan: rewrite logic using pl2303_termios_change() helper ] Signed-off-by: Johan Hovold --- drivers/usb/serial/pl2303.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 46dd09da2434..ac231cdf48a6 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -533,6 +533,17 @@ static int pl2303_set_line_request(struct usb_serial_port *port, return 0; } +static bool pl2303_termios_change(struct ktermios *a, struct ktermios *b) +{ + bool ixon_change; + + ixon_change = ((a->c_iflag ^ b->c_iflag) & (IXON | IXANY)) || + a->c_cc[VSTART] != b->c_cc[VSTART] || + a->c_cc[VSTOP] != b->c_cc[VSTOP]; + + return tty_termios_hw_change(a, b) || ixon_change; +} + static void pl2303_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { @@ -544,7 +555,7 @@ static void pl2303_set_termios(struct tty_struct *tty, int ret; u8 control; - if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios)) + if (old_termios && !pl2303_termios_change(&tty->termios, old_termios)) return; buf = kzalloc(7, GFP_KERNEL); @@ -662,6 +673,9 @@ static void pl2303_set_termios(struct tty_struct *tty, pl2303_vendor_write(serial, 0x0, 0x41); else pl2303_vendor_write(serial, 0x0, 0x61); + } else if (I_IXON(tty) && !I_IXANY(tty) && START_CHAR(tty) == 0x11 && + STOP_CHAR(tty) == 0x13) { + pl2303_vendor_write(serial, 0x0, 0xc0); } else { pl2303_vendor_write(serial, 0x0, 0x0); }