Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp998978rdh; Fri, 27 Oct 2023 01:29:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4M+cNYrmOIPlgQa5c7DIL9lZILlTQOpbrlsTwX2+1G8aPNunHC7+h+IJLvvgSYQu8OQNj X-Received: by 2002:a05:690c:d83:b0:5ae:c0f2:cd42 with SMTP id da3-20020a05690c0d8300b005aec0f2cd42mr2376499ywb.43.1698395397860; Fri, 27 Oct 2023 01:29:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698395397; cv=none; d=google.com; s=arc-20160816; b=d9xvvf5QOi+XjQLCZPGaI3tnyUTUEERTldhf3gjwFircDI+SNuk3/2gNKqdDvd9TDR C1W7mBQOQ3w/CQbl4sqW03RlrhRRW8JDY3aVm60Cx0n0x9DKJpK0JjNAc1tgYHCgqZmD ju+/w15TBcZKfkAdBtRUt8sV3DtsvPAdPwiDwCi0eKR6RoaytShssaBXblma+Ggzph+Y 1uIh0UjB6x0Iq4p0eJdJjbvLvcUK468s/JPg+nUnPZlgUP8M3k8QGSGES+ZikKZYoj3J zLKxTwFkau1Lnx5ORubz8ak1Xvq+t34y9XzmsqnFQuPiQ9mdygTPvoU0vRL/aHnpdeqd O95w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id; bh=stJbb23w3VUqP0eHkdL98f2jZhQvcq9EYPxztKnA6VY=; fh=Dohtn8zJcMCIEnkl+6aNEtJyXLcnoEqLwY28K3Wa0As=; b=MdBKzY/MsVAwMSYlQSCZyNOAsIPrbvzNxVkiw7Y9jq/u06gLFnJpLxNTSDjfJlalmH 5b+agCduwcYkldQAylDJ/fTHp/DSOjv35IUCSKLDsICviN1SQJX28jf2Kj3VaDdr2i2V 1+FO7hw+5m+caUYCc6caIraJiEp71pXgpY8FYK7B7NUQxHx03DI545o5jOxQQDrUBI6l AakUqNfmyQ/crmJzULuPE61sPYU3R631z1dVMMW/H0gGR++ZNSSIICR0lJa0yra5aEBY eBinPlwyQSfgEDsBz/RtKx1RKnE/VCk/dU4+EHu+XfTAnz7Yn0aCJtrJ6CumgVn+zFlB ht3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id w10-20020a81a20a000000b0058cd7815d28si1602076ywg.190.2023.10.27.01.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:29:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DB51182CC45C; Fri, 27 Oct 2023 01:29:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235079AbjJ0I3s (ORCPT + 99 others); Fri, 27 Oct 2023 04:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235012AbjJ0I3q (ORCPT ); Fri, 27 Oct 2023 04:29:46 -0400 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 288801BE; Fri, 27 Oct 2023 01:29:42 -0700 (PDT) Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2c5071165d5so22086461fa.0; Fri, 27 Oct 2023 01:29:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698395380; x=1699000180; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=stJbb23w3VUqP0eHkdL98f2jZhQvcq9EYPxztKnA6VY=; b=VPrAr06OoUv+izTP6JFnd3aqFzGoVfW+XFE9VaWIESad/uJ7ubM0+aipB4mkgbbAZp Pe/HnQtd1MYaiozDbFQXj/d151ir7J1uSBf2BeNKrRYb+x7cKkJaWgVGxGyM9eA6sieA FvD+TVuZxgw644eb+XXoVWLToRgI4KXPLuhfJOMNkaES+UhPtxmqo1SPdgsInhVed2kL iZJKWyrL5KkhALmKCw6khebstE5c5b6sd0rUTJalzyhpnYWuDWyzjAZl17mv/KDYlWTg 5E6M3f/lye24dY6nQp93kKF3xRegFxeSJM1bgOuBQQ7n7geFwYkNVMZthbIBey0iTjYp HwaQ== X-Gm-Message-State: AOJu0YznJjuttF6XYwSL+PLxImspFlVwn7mk4axFmjwbz4aBOy9D0A2W eeCotNCXIvDoUr19eNLd1eI= X-Received: by 2002:a2e:a167:0:b0:2c5:12ae:adb3 with SMTP id u7-20020a2ea167000000b002c512aeadb3mr1517585ljl.44.1698395380014; Fri, 27 Oct 2023 01:29:40 -0700 (PDT) Received: from ?IPV6:2a0b:e7c0:0:107::aaaa:59? ([2a0b:e7c0:0:107::aaaa:59]) by smtp.gmail.com with ESMTPSA id bg9-20020a05600c3c8900b004063cd8105csm4602183wmb.22.2023.10.27.01.29.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Oct 2023 01:29:39 -0700 (PDT) Message-ID: <37a5e055-93b5-4f05-bcca-4caa5ed6f97f@kernel.org> Date: Fri, 27 Oct 2023 10:29:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface Content-Language: en-US To: Crescent CY Hsieh , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org References: <20231027062440.7749-1-crescentcy.hsieh@moxa.com> <20231027062440.7749-3-crescentcy.hsieh@moxa.com> From: Jiri Slaby Autocrypt: addr=jirislaby@kernel.org; keydata= xsFNBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckucNu6ZwXjFY0f3qIRg3Vqh5QxPkojGsq9tXVFVLEkSVz6FoqCHrUTx wr+aw6qqQVgvT/McQtsI0S66uIkQjzPUrgAEtWUv76rM4ekqL9stHyvTGw0Fjsualwb0Gwdx ReTZzMgheAyoy/umIOKrSEpWouVoBt5FFSZUyjuDdlPPYyPav+hpI6ggmCTld3u2hyiHji2H cDpcLM2LMhlHBipu80s9anNeZhCANDhbC5E+NZmuwgzHBcan8WC7xsPXPaiZSIm7TKaVoOcL 9tE5aN3jQmIlrT7ZUX52Ff/hSdx/JKDP3YMNtt4B0cH6ejIjtqTd+Ge8sSttsnNM0CQUkXps w98jwz+Lxw/bKMr3NSnnFpUZaxwji3BC9vYyxKMAwNelBCHEgS/OAa3EJoTfuYOK6wT6nadm YqYjwYbZE5V/SwzMbpWu7Jwlvuwyfo5mh7w5iMfnZE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pyMNVJ2ZwPmX2mWEoYuaBU0JN7wM+/zWgOf2zRwhEuD3A2cO2PxoiIfyUEfB9SSmffaK/ S4xXoB6wvGENZ85Hg37C7WDNdaAt6Xh2uQIly5grkgvWppkNy4ZHxE+jeNsU7tg= In-Reply-To: <20231027062440.7749-3-crescentcy.hsieh@moxa.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 27 Oct 2023 01:29:55 -0700 (PDT) On 27. 10. 23, 8:24, Crescent CY Hsieh wrote: > MOXA PCIe boards have 4 serial interfaces and don't require additional > stuff to switch between interfaces: > > - RS232 > - RS422 > - RS485_2W (half-duplex) > - RS485_4W (full-duplex) > > By using ioctl command "TIOCRS485", it can switch between default > interface and RS485 if supported. > > That means, for RS422/RS485 board, it can switch between RS422 and > RS485 by setting the flags within struct serial_rs485. > > However, for the RS232/RS422/RS485 board, it can only switch between > RS232 and RS485, there's no flag for switching interface into RS422. > > This patch adds a flag call "SER_RS422_ENALBED" in serial.h and modifies It's not "ENALBED". Anyway, I am afraid you have to split the patch into two: 1) add the flag and core support (but wait a bit for others if they agree with this approach) 2) add the support for moxa. > serial_core.c to make it possible to switch interface between RS232, > RS422 and RS485. ... > --- a/drivers/tty/serial/8250/8250_pci.c > +++ b/drivers/tty/serial/8250/8250_pci.c > @@ -2032,6 +2036,37 @@ static int pci_moxa_set_interface(const struct pci_dev *dev, > return 0; > } > > +/* > + * MOXA PCIe boards support switching the serial interface using the ioctl > + * command "TIOCSRS485". > + * > + * RS232 = (no flags are set) > + * RS422 = SER_RS422_ENABLED > + * RS485_2W (half-duplex) = SER_RS485_ENABLED > + * RS485_4W (full-duplex) = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX > + */ > +static int pci_moxa_rs485_config(struct uart_port *port, > + struct ktermios *termios, > + struct serial_rs485 *rs485) > +{ > + struct pci_dev *dev = to_pci_dev(port->dev); > + u8 mode = MOXA_RS232; > + > + if (rs485->flags & SER_RS485_ENABLED) { > + if (rs485->flags & SER_RS485_RX_DURING_TX) > + mode = MOXA_RS485_4W; > + else > + mode = MOXA_RS485_2W; > + } else if (rs485->flags & SER_RS422_ENABLED) { > + mode = MOXA_RS422; > + } else { > + if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232)) > + return -ENODEV; > + } > + > + return pci_moxa_set_interface(dev, port->port_id, mode); Looks good to me now. > --- a/drivers/tty/serial/serial_core.c > +++ b/drivers/tty/serial/serial_core.c > @@ -1305,7 +1305,7 @@ static int uart_get_icount(struct tty_struct *tty, > > #define SER_RS485_LEGACY_FLAGS (SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | \ > SER_RS485_RTS_AFTER_SEND | SER_RS485_RX_DURING_TX | \ > - SER_RS485_TERMINATE_BUS) > + SER_RS485_TERMINATE_BUS | SER_RS422_ENABLED) > > static int uart_check_rs485_flags(struct uart_port *port, struct serial_rs485 *rs485) > { > @@ -1371,11 +1371,26 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4 > { > u32 supported_flags = port->rs485_supported.flags; > > - if (!(rs485->flags & SER_RS485_ENABLED)) { > + if (!(rs485->flags & SER_RS485_ENABLED) && !(rs485->flags & SER_RS422_ENABLED)) { maybe easier: if (!(rs485->flags & (SER_RS485_ENABLED | SER_RS422_ENABLED))) { ? > memset(rs485, 0, sizeof(*rs485)); > return; > } > > + /* Pick sane setting if the user enables both interfaces */ > + if (rs485->flags & SER_RS485_ENABLED && rs485->flags & SER_RS422_ENABLED) { > + dev_warn_ratelimited(port->dev, > + "%s (%d): Invalid serial interface setting, using RS485 instead\n", > + port->name, port->line); > + rs485->flags &= ~(SER_RS422_ENABLED); No need for parens. > + } > + > + /* Clear other bits and return if enable RS422 */ "if RS422 is enabled" or "if enabling RS422" > + if (rs485->flags & SER_RS422_ENABLED) { > + memset(rs485, 0, sizeof(*rs485)); > + rs485->flags |= SER_RS422_ENABLED; > + return; > + } > + > /* Pick sane settings if the user hasn't */ > if ((supported_flags & (SER_RS485_RTS_ON_SEND|SER_RS485_RTS_AFTER_SEND)) && > !(rs485->flags & SER_RS485_RTS_ON_SEND) == > @@ -1400,7 +1415,7 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4 > static void uart_set_rs485_termination(struct uart_port *port, > const struct serial_rs485 *rs485) > { > - if (!(rs485->flags & SER_RS485_ENABLED)) > + if (!(rs485->flags & SER_RS485_ENABLED) && !(rs485->flags & SER_RS422_ENABLED)) if (!(rs485->flags & (SER_RS485_ENABLED | SER_RS422_ENABLED))) { thanks, -- js suse labs