Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1799870imm; Thu, 12 Jul 2018 08:02:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeFPSLfsxEyOqtfKy130Ehdbni1r2Jr9z83XqOIajWfkaoHn3S5Yq+E01h0VgWjyPAcm+3W X-Received: by 2002:a17:902:d716:: with SMTP id w22-v6mr2550330ply.98.1531407770973; Thu, 12 Jul 2018 08:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531407770; cv=none; d=google.com; s=arc-20160816; b=bKvPwvh3sgcG6TPCgc7VPLEwafvLJ51Y3MVsproc56iCHuv+hqJeWEEDkzZlgb/Kzy rq4hbE7nLWNtoWav7+8X4t+q/DGYcxB1wO/DSBK/Sw9xbcao/H6fXuddRUMwnI9J9iNA Kef0A9yYq3lna8gVORVwoPz1ui3Hzt0G645n/Zj3VuHrHqt2O5aASXdYjBgSzx//onDh I2xjgtjuO42PBnlYMyJHMcUzC7eHhMoIt05aTOMrYMZw3GlF5qbc5gfkRu3J3SWsqMbz yfmyQBvwgrRbJK/dFk5xy4ecYWBk+ASbmqQyEJ+PDHIlB2x0U0F3BrJizUXKzKJNcicN Uh+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=RFYp1HAioR1vBV3xUnp6gT50epeHBHbAZ/pDmSqqbO8=; b=ZQlR9+pctSdceKR9tmfi2Sck5H2Fvgs6W2BfnfqHlU3MgynUgT8CkiBjYIVO8qcBcl 8fQu13CNnkEUM60E22IJxAM9rvQSPpg0no15omxq5WnVx7wLM20PsjzdWzM2gqmBw5/O COIauXcAkJkL6fgT3r2pWdl+o1RGIkY6JGLnxZegs8cZDvVX/tzfd/UDSYvC0NQ9u1SB CF/ecWweA1qs/ZZ1vkVoVJj32HjXoI/CKNqgOP5INP1W0FWXadCRxQnDp3VD+pi5jOFN NZXMyXjzwQ7Vkp+ViwsRJNZ3g6kmmBSuDGsXjLnGpkB+TTnNHtQW/oQnIOh4RG5o4DDR E2lA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91-v6si21411937ply.296.2018.07.12.08.02.33; Thu, 12 Jul 2018 08:02:50 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732574AbeGLPLw (ORCPT + 99 others); Thu, 12 Jul 2018 11:11:52 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50778 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732397AbeGLPLw (ORCPT ); Thu, 12 Jul 2018 11:11:52 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 28ADEBAC; Thu, 12 Jul 2018 15:01:55 +0000 (UTC) Date: Thu, 12 Jul 2018 17:01:53 +0200 From: Greg KH To: Ludovic Desroches Cc: linux-serial@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jslaby@suse.com, arnd@arndb.de, richard.genoud@gmail.com, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] tty/serial: atmel: add ISO7816 support Message-ID: <20180712150153.GD22502@kroah.com> References: <20180711131638.12622-1-ludovic.desroches@microchip.com> <20180711131638.12622-3-ludovic.desroches@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180711131638.12622-3-ludovic.desroches@microchip.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 11, 2018 at 03:16:37PM +0200, Ludovic Desroches wrote: > From: Nicolas Ferre > > When mode is set in atmel_config_iso7816() we backup last RS232 mode > for coming back to this mode if requested. > Also allow setup of T=0 and T=1 parameter and basic support in set_termios > function as well. > Report NACK and ITER errors in irq handler. > > Signed-off-by: Nicolas Ferre > [ludovic.desroches@microchip.com: rebase, add check on fidi ratio, checkpatch fixes] > Signed-off-by: Ludovic Desroches > --- > drivers/tty/serial/atmel_serial.c | 175 +++++++++++++++++++++++++++++++++++--- > drivers/tty/serial/atmel_serial.h | 3 +- > 2 files changed, 167 insertions(+), 11 deletions(-) > > diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c > index 8e4428725848..0118b219f3a8 100644 > --- a/drivers/tty/serial/atmel_serial.c > +++ b/drivers/tty/serial/atmel_serial.c > @@ -34,6 +34,7 @@ > #include > #include > > +#include > #include > #include > > @@ -147,6 +148,8 @@ struct atmel_uart_port { > struct circ_buf rx_ring; > > struct mctrl_gpios *gpios; > + u32 backup_mode; /* MR saved during iso7816 operations */ > + u32 backup_brgr; /* BRGR saved during iso7816 operations */ > unsigned int tx_done_mask; > u32 fifo_size; > u32 rts_high; > @@ -362,6 +365,136 @@ static int atmel_config_rs485(struct uart_port *port, > return 0; > } > > +static unsigned int atmel_calc_cd(struct uart_port *port, > + struct serial_iso7816 *iso7816conf) > +{ > + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); > + unsigned int cd; > + u64 mck_rate; > + > + mck_rate = (u64)clk_get_rate(atmel_port->clk); > + dev_dbg(port->dev, "ISO7816 mck_rate = %lld\n", mck_rate); > + do_div(mck_rate, iso7816conf->clk); > + cd = mck_rate; > + dev_dbg(port->dev, "ISO7816 clk = %d. CD = %d\n", iso7816conf->clk, cd); > + return cd; > +} > + > +static unsigned int atmel_calc_fidi(struct uart_port *port, > + struct serial_iso7816 *iso7816conf) > +{ > + u64 fidi = 0; > + > + dev_dbg(port->dev, "ISO7816 fi(%d) / di(%d)\n", > + iso7816conf->sc_fi, iso7816conf->sc_di); Do you still need all of the debugging code? Shouldn't ftrace give you all of this? > + if (iso7816conf->sc_fi && iso7816conf->sc_di) { > + fidi = (u64)iso7816conf->sc_fi; > + do_div(fidi, iso7816conf->sc_di); > + } > + dev_dbg(port->dev, "ISO7816 fidi = 0x%x\n", (u32)fidi); > + return (u32)fidi; > +} > + > +/* Enable or disable the iso7816 support */ > +/* Called with interrupts disabled */ > +static int atmel_config_iso7816(struct uart_port *port, > + struct serial_iso7816 *iso7816conf) > +{ > + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); > + unsigned int mode, t; > + unsigned int cd, fidi; > + int ret = 0; > + > + /* Disable RX and TX */ > + atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_RXDIS | ATMEL_US_TXDIS); > + /* Disable interrupts */ > + atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); > + > + mode = atmel_uart_readl(port, ATMEL_US_MR); > + > + if (!(port->iso7816.flags & SER_ISO7816_ENABLED)) { > + /* port not yet in iso7816 mode: store configuration */ > + atmel_port->backup_mode = mode; > + atmel_port->backup_brgr = atmel_uart_readl(port, ATMEL_US_BRGR); > + } Are you really validating all of the fields in this structure for valid values correctly? It feels like you are missing some here... > @@ -1281,6 +1417,9 @@ atmel_handle_status(struct uart_port *port, unsigned int pending, > wake_up_interruptible(&port->state->port.delta_msr_wait); > } > } > + > + if (pending & (ATMEL_US_NACK | ATMEL_US_ITERATION)) > + dev_err(port->dev, "ISO7816 ERROR (0x%08x)\n", pending); What can someone do with this? If nothing, then why check or tell the user about it? They will ignore it :( thanks, greg k-h