Commit Graph

82 Commits

Author SHA1 Message Date
Jiri Slaby 3ec2ff3723 tty: make use of tty_get_{char,frame}_size
In the previous patch, we introduced tty_get_char_size() and
tty_get_frame_size() for computing character and frame sizes,
respectively. Here, we make use of them in various tty drivers where
applicable.

The stats look nice: 12 insertions, 169 deletions.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Andy Gross <agross@kernel.org>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Oliver Neukum <oneukum@suse.com>
Acked-by: Alex Elder <elder@kernel.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210610090247.2593-4-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-15 14:03:27 +02:00
Jiri Slaby fff4ef17a9 tty: make tty_operations::chars_in_buffer return uint
tty_operations::chars_in_buffer is another hook which is expected to
return values >= 0. So make it explicit by the return type too -- use
unsigned int.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Acked-by: David Sterba <dsterba@suse.com>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Cc: Jens Taprogge <jens.taprogge@taprogge.org>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Link: https://lore.kernel.org/r/20210505091928.22010-27-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-05-13 18:29:11 +02:00
Jiri Slaby 03b3b1a240 tty: make tty_operations::write_room return uint
Line disciplines expect a positive value or zero returned from
tty->ops->write_room (invoked by tty_write_room). So make this
assumption explicit by using unsigned int as a return value. Both of
tty->ops->write_room and tty_write_room.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Acked-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Acked-by: Alex Elder <elder@linaro.org>
Acked-by: Max Filippov <jcmvbkbc@gmail.com> # xtensa
Acked-by: David Sterba <dsterba@suse.com>
Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Chris Zankel <chris@zankel.net>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Cc: Jens Taprogge <jens.taprogge@taprogge.org>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: Scott Branden <scott.branden@broadcom.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Link: https://lore.kernel.org/r/20210505091928.22010-23-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-05-13 17:03:20 +02:00
Johan Hovold d38be70245 staging: greybus: uart: clean up TIOCGSERIAL
TIOCSSERIAL is a horrid, underspecified, legacy interface which for most
serial devices is only useful for setting the close_delay and
closing_wait parameters.

The xmit_fifo_size parameter could be used to set the hardware transmit
fifo size of a legacy UART when it could not be detected, but the
interface is limited to eight bits and should be left unset when not
used.

Similarly, baud_base could be used to set the UART base clock when it
could not be detected but might as well be left unset when it is not
known.

The type parameter could be used to set the UART type, but is
better left unspecified (type unknown) when it isn't used.

Note that some applications have historically expected TIOCGSERIAL to be
implemented, but judging from the Debian sources, the port type not
being PORT_UNKNOWN is only used to check for the existence of legacy
serial ports (ttySn). Notably USB serial drivers like ftdi_sio have been
using PORT_UNKNOWN for twenty years without any problems.

Drop the bogus values provided by the greybus implementation.

Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20210407102334.32361-8-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-07 17:22:07 +02:00
Johan Hovold 60c6b305c1 staging: greybus: uart: fix unprivileged TIOCCSERIAL
TIOCSSERIAL is a horrid, underspecified, legacy interface which for most
serial devices is only useful for setting the close_delay and
closing_wait parameters.

A non-privileged user has only ever been able to set the since long
deprecated ASYNC_SPD flags and trying to change any other *supported*
feature should result in -EPERM being returned. Setting the current
values for any supported features should return success.

Fix the greybus implementation which instead indicated that the
TIOCSSERIAL ioctl was not even implemented when a non-privileged user
set the current values.

Fixes: e68453ed28 ("greybus: uart-gb: now builds, more framework added")
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20210407102334.32361-7-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-07 17:22:07 +02:00
Johan Hovold b71e571ada staging: greybus: uart: fix TIOCSSERIAL jiffies conversions
The port close_delay and closing_wait parameters set by TIOCSSERIAL are
specified in jiffies and not milliseconds.

Add the missing conversions so that TIOCSSERIAL works as expected also
when HZ is not 1000.

Fixes: e68453ed28 ("greybus: uart-gb: now builds, more framework added")
Cc: stable@vger.kernel.org	# 4.9
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20210407102334.32361-6-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-07 17:22:07 +02:00
Greg Kroah-Hartman c2312ff575 Merge 5.7-rc7 into staging-next
We need the staging/iio fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-05-25 09:11:19 +02:00
Johan Hovold 6064aeefa8 staging: greybus: uart: replace driver line-coding struct
Drop the driver version of the line-coding request and use the protocol
definition directly as was originally intended instead.

This specifically avoids having the two versions of what is supposed to
be the same struct ever getting out of sync.

Note that this has in fact already happened once when the protocol
definition had its implicit padding removed while the driver struct
wasn't updated. The fact that we used the size of the then larger driver
struct when memcpying its content to the stack didn't exactly make
things better. A later addition of a flow-control field incidentally
made the structures match again.

Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20200514070548.4423-1-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-05-15 15:47:31 +02:00
Oscar Carter 34625c1931 staging: greybus: Fix uninitialized scalar variable
In the "gb_tty_set_termios" function the "newline" variable is declared
but not initialized. So the "flow_control" member is not initialized and
the OR / AND operations with itself results in an undefined value in
this member.

The purpose of the code is to set the flow control type, so remove the
OR / AND self operator and set the value directly.

Addresses-Coverity-ID: 1374016 ("Uninitialized scalar variable")
Fixes: e55c25206d ("greybus: uart: Handle CRTSCTS flag in termios")
Signed-off-by: Oscar Carter <oscar.carter@gmx.com>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20200510101426.23631-1-oscar.carter@gmx.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-05-13 14:00:21 +02:00
Greg Kroah-Hartman ec0ad86817 staging: greybus: move core include files to include/linux/greybus/
With the goal of moving the core of the greybus code out of staging, the
include files need to be moved to include/linux/greybus.h and
include/linux/greybus/

Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Vaibhav Agarwal <vaibhav.sr@gmail.com>
Cc: Rui Miguel Silva <rmfrfs@gmail.com>
Cc: David Lin <dtwlin@gmail.com>
Cc: "Bryan O'Donoghue" <pure.logic@nexus-software.ie>
Cc: greybus-dev@lists.linaro.org
Cc: devel@driverdev.osuosl.org
Acked-by: Mark Greer <mgreer@animalcreek.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Alex Elder <elder@kernel.org>
Link: https://lore.kernel.org/r/20190825055429.18547-8-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-27 19:02:59 +02:00
Ioannis Valasakis 327f276963 staging: greybus: remove space before tab
Remove extra space before a tab character.
Reported by checkpatch.

Signed-off-by: Ioannis Valasakis <code@wizofe.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-09 09:49:03 -08:00
Al Viro 0aad5ad563 greybus/uart: switch to ->[sg]et_serial()
Reviewed-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-09-14 11:19:51 -04:00
Greg Kroah-Hartman 863dbc52e7 staging: greybus: Remove redundant license text
Now that the SPDX tag is in all greybus files, that identifies the
license in a specific and legally-defined manner.  So the extra GPL text
wording can be removed as it is no longer needed at all.

This is done on a quest to remove the 700+ different ways that files in
the kernel describe the GPL license text.  And there's unneeded stuff
like the address (sometimes incorrect) for the FSF which is never
needed.

No copyright headers or other non-license-description text was removed.

Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Acked-by: Vaibhav Agarwal <vaibhav.sr@gmail.com>
Acked-by: David Lin <dtwlin@gmail.com>
Acked-by: Johan Hovold <johan@kernel.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Mark Greer <mgreer@animalcreek.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Acked-by: "Bryan O'Donoghue" <pure.logic@nexus-software.ie>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-11 14:46:21 +01:00
Greg Kroah-Hartman eb50fd3a22 staging: greybus: add SPDX identifiers to all greybus driver files
It's good to have SPDX identifiers in all files to make it easier to
audit the kernel tree for correct licenses.

Update the drivers/staging/greybus files files with the correct SPDX
license identifier based on the license text in the file itself.  The
SPDX identifier is a legally binding shorthand, which can be used
instead of the full boiler plate text.

This work is based on a script and data from Thomas Gleixner, Philippe
Ombredanne, and Kate Stewart.

Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com>
Cc: "Bryan O'Donoghue" <pure.logic@nexus-software.ie>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Acked-by: Vaibhav Agarwal <vaibhav.sr@gmail.com>
Acked-by: David Lin <dtwlin@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Acked-by: Johan Hovold <johan@kernel.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Mark Greer <mgreer@animalcreek.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-11 14:46:20 +01:00
Darryl T. Agostinelli 4330887f2e staging: greybus: uart.c: Remove include linux/serial.h
$ make includecheck | grep staging
./drivers/staging/greybus/uart.c: linux/serial.h is included more than once.

Signed-off-by: Darryl T. Agostinelli <dagostinelli@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-04-18 13:27:16 +02:00
simran singhal 4452b090a1 staging: greybus: Replace "is is" with "is"
This patch replace "is is " with "is". The replacement couldn't be
automated because sometimes the first "is" was meant to be another
word.

Signed-off-by: simran singhal <singhalsimran0@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-03-07 07:38:13 +01:00
Ingo Molnar 174cd4b1e5 sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h>
Fix up affected files that include this signal functionality via sched.h.

Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-03-02 08:42:32 +01:00
Gioh Kim 461ab8077d staging: greybus: fix "line over 80 characters" coding style issues
This patch fixes only obvious lines.
There are still more issues.

Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-02-12 13:26:14 +01:00
Johan Hovold 414850d9ce staging: greybus: uart: fix TIOCGSERIAL flags
This driver does not have a low-latency mode and should not report
anything else.

Also drop the skip-test flag which isn't used either.

Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-01-27 09:29:23 +01:00
Johan Hovold 424a4b595e staging: greybus: use get_icount tty operation
Use the tty get_icount operation instead of implementing TIOCGICOUNT
directly.

Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-11-10 14:06:23 +01:00
Johan Hovold 4dfc109c71 staging: greybus: uart: fix invalid user-pointer check
Drop invalid user-pointer check from TIOCGSERIAL handler.

A NULL-pointer can be valid in user space and copy_to_user() takes care
of sanity checking.

Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-11-10 14:04:12 +01:00
Greg Kroah-Hartman bdc065666a Merge 4.9-rc3 into staging-next
This resolves a merge issue with
drivers/staging/iio/accel/sca3000_core.c and we want the fixes all in
here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-10-30 06:38:44 -04:00
Bhumika Goyal 4d79f43191 Staging: greybus: uart: constify tty_port_operations structure
Declare tty_port_operations structure as const as it is only stored in
the ops field of a tty_port structure which is a field of a gb_tty
structure. The ops field is of type const struct tty_port_operations *,
so tty_port_operations structures having this property can be
declared as const.
Done using Coccinelle:

@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct tty_port_operations i@p = {...};

@ok1@
identifier r1.i;
position p;
struct gb_tty q;
@@
q.port.ops=&i@p

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct tty_port_operations i={...};

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct tty_port_operations i;

File size before:
   text	   data	    bss	    dec	    hex	filename
   7646	    512	     56	   8214	   2016	drivers/staging/greybus/uart.o

File size after:
   text	   data	    bss	    dec	    hex	filename
   7710	    448	     56	   8214	   2016	drivers/staging/greybus/uart.o

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
Acked-by: Johan Hovold <johan@kernel.org>
Reviewed-by: David Lin <dtwlin@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-10-17 09:38:37 +02:00
Viresh Kumar 4fa589126f Staging: greybus: uart: Use gbphy_dev->dev instead of bundle->dev
Some of the print messages are using the incorrect device pointer, fix
them.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-10-17 09:14:55 +02:00
Chaehyun Lim 319b78c3c4 staging: greybus: uart.c: fix alignment to match open parenthesis
Fixes checkpatch.pl warning:
CHECK: Alignment should match open parenthesis

Signed-off-by: Chaehyun Lim <chaehyun.lim@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-22 11:54:47 +02:00
Chaehyun Lim 26746a3603 staging: greybus: uart.c: change 'unsigned' to 'unsigned int'
Fixes checkpatch.pl warning:
WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: Chaehyun Lim <chaehyun.lim@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-22 11:54:47 +02:00
Axel Haslam 22b8708725 greybus: uart: Add runtime pm support
This adds runtime pm support for the uart driver.

Testing Done: Using the test daughter board, let
the gpb bridge enter standby and do a uart transfer
operation.

Signed-off-by: Axel Haslam <haslam_axel@projectara.com>
Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
Johan Hovold 2aae92bdc2 greybus: Revert "greybus: uart: don't use spin_lock_irq()"
This reverts commit bd3c4aa99dc23449699432e0744bcb5af7afa98c.

Someone decided that all use of spin_lock_irq was to be considered a bug
and went on a search-and-replace type "bug-fixing" spree last week.

This is however just plain wrong. Using spin_lock_irq is perfectly fine
in paths were interrupts have not been disabled, and this is in fact
even preferred over the lazy approach of always using spin_lock_irqsave
instead of understanding the code that is being written or modified.

All current uses of spin_lock_irq have already been vetted in this
respect. Also note that it is only used in functions that may sleep,
that is, in functions that must not be called with interrupts disabled
in the first place.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-29 16:37:17 -07:00
Viresh Kumar e9f80f3363 greybus: uart: don't use spin_lock_irq()
spin_[un]lock_irq() routines should be used carefully as they things can
go wrong, if they are mixed with spin_lock_irqsave() or other variants.

The main problem is that spin_[un]lock_irq() routines doesn't check if
the IRQs are already disabled/enabled on the local CPU and so
spin_unlock_irq() will forcefully enable interrupts for example.

This may not work well, if some other code was relying on interrupts
being disabled.

Use spin_lock_irqsave() and spin_unlock_restore() instead.

This patch doesn't claim that it fixes the JIRA completely, but
the issue was harder to reproduce for some iterations after this, which
was quite easy to reproduce earlier on.

Tested on EVT 2.0 with lots of debug patches to kernel and greybus.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 15:17:46 -07:00
Greg Kroah-Hartman 19cdabcf0b greybus: Revert "greybus: don't use spin_lock_irq()"
This reverts commit 469fbe5da0229edcb42aa08bef8e10feaa37e6d7.

It isn't correct in places.

Reported-by: Gjorgji Rosikopulos <rosikopulos_gjorgji@projectara.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 14:20:02 -07:00
Viresh Kumar 5e2b63915c greybus: don't use spin_lock_irq()
spin_[un]lock_irq() routines should be used carefully as they things can
go wrong, if they are mixed with spin_lock_irqsave() or other variants.

The main problem is that spin_[un]lock_irq() routines doesn't check if
the IRQs are already disabled/enabled on the local CPU and so
spin_unlock_irq() will forcefully enable interrupts for example.

This may not work well, if some other code was relying on interrupts
being disabled.

Use spin_lock_irqsave() and spin_unlock_restore() instead.

This patch doesn't claim that it fixes the JIRA completely, but
the issue was harder to reproduce for some iterations after this, which
was quite easy to reproduce earlier on.

Tested on EVT 2.0 with lots of debug patches to kernel and greybus.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 14:15:21 -07:00
Viresh Kumar 60fb3405c7 greybus: Remove extra blank lines
This patch removes few blank lines across the repository at places where
two blank lines were present together or when a blank line is present at
the start or end of a routine.

Note that this doesn't remove most of them from greybus_protocols.h as
they were added on purpose.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-10 16:32:33 -07:00
Bryan O'Donoghue 6db9cc68d7 greybus: uart: Fix minor number leak
On the gb_uart_remove() path we are forgetting to do a release_minor()
leading to a minor number leak. This is a simple one-line fix.

Tested on EVT 2.0

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-10 16:26:31 -07:00
Viresh Kumar 64060fe954 greybus: gbphy: Remove protocol specific version handling
We should be using the generic version handling at bundle level, instead
of at protocol level for bridged PHY devices as well.

The bundle version handling is already in place, though it is *not* used
today as we haven't bumped the version of control protocol yet.

Remove protocol specific handling for bridged PHY devices.

Tested on EVT 1.5 with gpbridge-test module. No nuttx changes are
required with this.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-31 22:02:58 -07:00
Axel Haslam 5dad5c314b greybus: uart: wait for credits on shutdown
We should try to wait until all credits are accounted
for before returning from shutdown.

For this purpose add a helper function that will
wait on completion, and call it form the shutdown.
This helper will also be useful when "wait until sent" is
implemented.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-31 17:18:18 -07:00
Axel Haslam 2b3b87f056 greybus: uart: Implement flush_buffer
Data may be held pening in the hardware because of flow
control mechanisms. When the port is closed, we need to flush
all data that was not sent.

For this, use the greybus message GB_UART_TYPE_FLUSH_FIFOS
which will flush all data queued on the module but not
yet sent on the data line.

Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-31 17:18:18 -07:00
Axel Haslam a8bc00fb88 greybus: uart: Add credits based tracking for transmit path
To avoid polling the firmware for space, a credit based system
is implemented.

The host will keep track of how many credits (bytes) it has
sent to the firmware, and stop sending data when the quota
is filled.

The host will be informed that the firmware has more
room for data when it handles the receive_credits request
message from the firmware, and will continue to write data
as credits become available.

The firmware and the host may implement an algorithm to aggregate
credits, and avoid extra greybus traffic.

Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-31 17:18:18 -07:00
Axel Haslam 8d6fbe9bf9 greybus: uart: Use a fifo to send data to the modules
The firmware now buffers data instead of blocking while the transfer
is sent, and the write operation cannot sleep.

Instead of using gb_transfer_sync (which sleeps) in the write callback,
buffer data in a fifo and send it from from a work queue.

The write_room callback will will report 1 byte less that what is really
available in the fifo, to leave space for extra characters that may
be added by the tty layer.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-31 17:18:18 -07:00
Axel Haslam 219ffcf3a5 greybus: uart: Implement dtr_rts callback.
Dtr_dts allows the tty layer to set the flow control lines
to the correct state during open and close.

Note that locking for newctrl is missing throughout the
driver and will be addressed on a separate patch.

Suggested-and-reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-31 17:18:18 -07:00
Axel Haslam e55c25206d greybus: uart: Handle CRTSCTS flag in termios
Handle the CRTSCTS flag in set_termios, so that auto
flow control can be turned off. For this, add a new flag
in the line coding request specifically for this purpose.

Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-31 17:18:18 -07:00
Sandeep Patil e54b106dd1 greybus: gpbridge: rename 'gpbridge' to 'gbphy' everywhere
The 'gpbridge' name didn't relaly reflect what the bus is; which
is a bus for bridged-phy devices. So, rename all instances
of 'gpbridge' to more appropriate 'gbphy'

Testing Done:
Build and boot tested. 'lsgb' will stop displaying 'GPBridge' devices
until I change the library to reflect this change.

Signed-off-by: Sandeep Patil <patil_sandeep@projectara.com>
Suggested-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-19 10:09:13 -07:00
Axel Haslam 9bc63b7ff5 greybus: uart fix missing negation on DTR setting
The unset the DTR flag is missing "~"

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-18 16:53:54 -07:00
Viresh Kumar 66b9e09e28 greybus: uart: Create separate module
Create separate module for uart gpbridge driver.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-14 19:13:57 +02:00
Viresh Kumar 73d292d838 greybus: uart: Kill reference_count hack
This was done long back and was probably the best bet then, but it looks
really bad to have it this way now.

Kill the hack and implement proper driver init()/exit() routines to do
the same thing.

Tested using gbsim by hotplugging uart manifest and removing it later.
Also tried removing the gb-phy module to test the exit path properly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-05 13:38:57 -07:00
Greg Kroah-Hartman 7dbe1f497b greybus: UART: convert to a gpbridge driver
This converts the UART driver to be a gpbridge driver, moving it away
from the "legacy" interface.

Testing Done: Tested on gbsim.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
[vaibhav.hiremath@linaro.org: 1.Changed code to retain init/exit fns of
drivers. 2.Exit path fix. 3. Fixed review comments]
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-05 13:38:57 -07:00
Axel Haslam b4b1b7eda9 greybus: uart: Update line coding settings only when needed
The check for line coding changed should use memcmp and not memcpy.

Testing done: trivial

Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-21 10:33:47 +09:00
Greg Kroah-Hartman 0ec3063244 greybus: convert drivers to use connection->private set/get
This converts all drivers to use the gb_connection_get_data() and
gb_connection_set_data() functions to make it a bit more explicit as to
what is going on.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-03-22 16:47:28 -04:00
Greg Kroah-Hartman c7b0726504 greybus: gpbridge.h: move protocol init/exit prototypes
Create gpbridge.h for the gpbridge-specific function prototypes, the
rest of the greybus drivers don't care about them.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
2016-03-03 13:52:02 -08:00
Johan Hovold c5f338c4a0 greybus: uart: fix incomplete receive-data sanity checks
Fix incomplete receive-data sanity checks.

The payload size was never verified before parsing the uart header and
neither was the uart-header data size verified against the actual
payload size, something which could lead to information leaks when
passing data beyond the payload buffer to the tty layer.

Also remove the incorrect check against the maximum (tx-buffer) payload
size.

Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-24 17:26:05 -08:00
Johan Hovold cb7f00ba5f greybus: uart: add missing serial-state sanity check
Add dedicated serial-state request handler and add the missing sanity
check on the incoming request.

Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-24 17:26:05 -08:00