public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: torvalds@osdl.org, linux-serial@vger.kernel.org
Subject: [PATCH 40/75] tty: Rework istallion to use the tty port changes
Date: Fri, 02 Jan 2009 13:46:18 +0000	[thread overview]
Message-ID: <20090102134616.13472.88062.stgit@localhost.localdomain> (raw)
In-Reply-To: <20090102133822.13472.53912.stgit@localhost.localdomain>

From: Alan Cox <alan@redhat.com>

Signed-off-by: Alan Cox <alan@redhat.com>
---

 drivers/char/istallion.c  |  159 ++++++++++++---------------------------------
 include/linux/istallion.h |    1 
 2 files changed, 43 insertions(+), 117 deletions(-)


diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index c4682f9..4c69ab9 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -626,8 +626,6 @@ static int	stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
 static int	stli_initopen(struct tty_struct *tty, struct stlibrd *brdp, struct stliport *portp);
 static int	stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
 static int	stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
-static int	stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp,
-				struct stliport *portp, struct file *filp);
 static int	stli_setport(struct tty_struct *tty);
 static int	stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
 static void	stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
@@ -787,6 +785,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
 {
 	struct stlibrd *brdp;
 	struct stliport *portp;
+	struct tty_port *port;
 	unsigned int minordev, brdnr, portnr;
 	int rc;
 
@@ -808,30 +807,19 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
 		return -ENODEV;
 	if (portp->devnr < 1)
 		return -ENODEV;
-
-
-/*
- *	Check if this port is in the middle of closing. If so then wait
- *	until it is closed then return error status based on flag settings.
- *	The sleep here does not need interrupt protection since the wakeup
- *	for it is done with the same context.
- */
-	if (portp->port.flags & ASYNC_CLOSING) {
-		interruptible_sleep_on(&portp->port.close_wait);
-		if (portp->port.flags & ASYNC_HUP_NOTIFY)
-			return -EAGAIN;
-		return -ERESTARTSYS;
-	}
+	port = &portp->port;
 
 /*
  *	On the first open of the device setup the port hardware, and
  *	initialize the per port data structure. Since initializing the port
  *	requires several commands to the board we will need to wait for any
  *	other open that is already initializing the port.
+ *
+ *	Review - locking
  */
-	tty_port_tty_set(&portp->port, tty);
+	tty_port_tty_set(port, tty);
 	tty->driver_data = portp;
-	portp->port.count++;
+	port->count++;
 
 	wait_event_interruptible(portp->raw_wait,
 			!test_bit(ST_INITIALIZING, &portp->state));
@@ -841,7 +829,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
 	if ((portp->port.flags & ASYNC_INITIALIZED) == 0) {
 		set_bit(ST_INITIALIZING, &portp->state);
 		if ((rc = stli_initopen(tty, brdp, portp)) >= 0) {
-			portp->port.flags |= ASYNC_INITIALIZED;
+			/* Locking */
+			port->flags |= ASYNC_INITIALIZED;
 			clear_bit(TTY_IO_ERROR, &tty->flags);
 		}
 		clear_bit(ST_INITIALIZING, &portp->state);
@@ -849,31 +838,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
 		if (rc < 0)
 			return rc;
 	}
-
-/*
- *	Check if this port is in the middle of closing. If so then wait
- *	until it is closed then return error status, based on flag settings.
- *	The sleep here does not need interrupt protection since the wakeup
- *	for it is done with the same context.
- */
-	if (portp->port.flags & ASYNC_CLOSING) {
-		interruptible_sleep_on(&portp->port.close_wait);
-		if (portp->port.flags & ASYNC_HUP_NOTIFY)
-			return -EAGAIN;
-		return -ERESTARTSYS;
-	}
-
-/*
- *	Based on type of open being done check if it can overlap with any
- *	previous opens still in effect. If we are a normal serial device
- *	then also we might have to wait for carrier.
- */
-	if (!(filp->f_flags & O_NONBLOCK)) {
-		if ((rc = stli_waitcarrier(tty, brdp, portp, filp)) != 0)
-			return rc;
-	}
-	portp->port.flags |= ASYNC_NORMAL_ACTIVE;
-	return 0;
+	return tty_port_block_til_ready(&portp->port, tty, filp);
 }
 
 /*****************************************************************************/
@@ -882,25 +847,29 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
 {
 	struct stlibrd *brdp;
 	struct stliport *portp;
+	struct tty_port *port;
 	unsigned long flags;
 
 	portp = tty->driver_data;
 	if (portp == NULL)
 		return;
+	port = &portp->port;
 
-	spin_lock_irqsave(&stli_lock, flags);
+	spin_lock_irqsave(&port->lock, flags);
 	if (tty_hung_up_p(filp)) {
-		spin_unlock_irqrestore(&stli_lock, flags);
+		spin_unlock_irqrestore(&port->lock, flags);
 		return;
 	}
-	if ((tty->count == 1) && (portp->port.count != 1))
-		portp->port.count = 1;
-	if (portp->port.count-- > 1) {
-		spin_unlock_irqrestore(&stli_lock, flags);
+	if (tty->count == 1 && port->count != 1)
+		port->count = 1;
+	if (port->count-- > 1) {
+		spin_unlock_irqrestore(&port->lock, flags);
 		return;
 	}
 
-	portp->port.flags |= ASYNC_CLOSING;
+	port->flags |= ASYNC_CLOSING;
+	tty->closing = 1;
+	spin_unlock_irqrestore(&port->lock, flags);
 
 /*
  *	May want to wait for data to drain before closing. The BUSY flag
@@ -908,15 +877,17 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
  *	updated by messages from the slave - indicating when all chars
  *	really have drained.
  */
+ 	spin_lock_irqsave(&stli_lock, flags);
 	if (tty == stli_txcooktty)
 		stli_flushchars(tty);
-	tty->closing = 1;
 	spin_unlock_irqrestore(&stli_lock, flags);
 
 	if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
 		tty_wait_until_sent(tty, portp->closing_wait);
 
-	portp->port.flags &= ~ASYNC_INITIALIZED;
+	/* FIXME: port locking here needs attending to */
+	port->flags &= ~ASYNC_INITIALIZED;
+
 	brdp = stli_brds[portp->brdnr];
 	stli_rawclose(brdp, portp, 0, 0);
 	if (tty->termios->c_cflag & HUPCL) {
@@ -937,14 +908,14 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
 	tty->closing = 0;
 	tty_port_tty_set(&portp->port, NULL);
 
-	if (portp->openwaitcnt) {
+	if (port->blocked_open) {
 		if (portp->close_delay)
 			msleep_interruptible(jiffies_to_msecs(portp->close_delay));
-		wake_up_interruptible(&portp->port.open_wait);
+		wake_up_interruptible(&port->open_wait);
 	}
 
-	portp->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
-	wake_up_interruptible(&portp->port.close_wait);
+	port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
+	wake_up_interruptible(&port->close_wait);
 }
 
 /*****************************************************************************/
@@ -1189,63 +1160,17 @@ static int stli_carrier_raised(struct tty_port *port)
 	return (portp->sigs & TIOCM_CD) ? 1 : 0;
 }
 
-/*
- *	Possibly need to wait for carrier (DCD signal) to come high. Say
- *	maybe because if we are clocal then we don't need to wait...
- */
-
-static int stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp,
-				struct stliport *portp, struct file *filp)
+static void stli_raise_dtr_rts(struct tty_port *port)
 {
-	unsigned long flags;
-	int rc, doclocal;
-	struct tty_port *port = &portp->port;
-
-	rc = 0;
-	doclocal = 0;
-
-	if (tty->termios->c_cflag & CLOCAL)
-		doclocal++;
-
-	spin_lock_irqsave(&stli_lock, flags);
-	portp->openwaitcnt++;
-	if (! tty_hung_up_p(filp))
-		port->count--;
-	spin_unlock_irqrestore(&stli_lock, flags);
-
-	for (;;) {
-		stli_mkasysigs(&portp->asig, 1, 1);
-		if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
-		    &portp->asig, sizeof(asysigs_t), 0)) < 0)
-			break;
-		if (tty_hung_up_p(filp) ||
-		    ((port->flags & ASYNC_INITIALIZED) == 0)) {
-			if (port->flags & ASYNC_HUP_NOTIFY)
-				rc = -EBUSY;
-			else
-				rc = -ERESTARTSYS;
-			break;
-		}
-		if (((port->flags & ASYNC_CLOSING) == 0) &&
-		    (doclocal || tty_port_carrier_raised(port))) {
-			break;
-		}
-		if (signal_pending(current)) {
-			rc = -ERESTARTSYS;
-			break;
-		}
-		interruptible_sleep_on(&port->open_wait);
-	}
-
-	spin_lock_irqsave(&stli_lock, flags);
-	if (! tty_hung_up_p(filp))
-		port->count++;
-	portp->openwaitcnt--;
-	spin_unlock_irqrestore(&stli_lock, flags);
-
-	return rc;
+	struct stliport *portp = container_of(port, struct stliport, port);
+	struct stlibrd *brdp = stli_brds[portp->brdnr];
+	stli_mkasysigs(&portp->asig, 1, 1);
+	if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
+		sizeof(asysigs_t), 0) < 0)
+			printk(KERN_WARNING "istallion: dtr raise failed.\n");
 }
 
+
 /*****************************************************************************/
 
 /*
@@ -1828,6 +1753,7 @@ static void stli_hangup(struct tty_struct *tty)
 {
 	struct stliport *portp;
 	struct stlibrd *brdp;
+	struct tty_port *port;
 	unsigned long flags;
 
 	portp = tty->driver_data;
@@ -1838,8 +1764,11 @@ static void stli_hangup(struct tty_struct *tty)
 	brdp = stli_brds[portp->brdnr];
 	if (brdp == NULL)
 		return;
+	port = &portp->port;
 
-	portp->port.flags &= ~ASYNC_INITIALIZED;
+	spin_lock_irqsave(&port->lock, flags);
+	port->flags &= ~ASYNC_INITIALIZED;
+	spin_unlock_irqrestore(&port->lock, flags);
 
 	if (!test_bit(ST_CLOSING, &portp->state))
 		stli_rawclose(brdp, portp, 0, 0);
@@ -1860,12 +1789,9 @@ static void stli_hangup(struct tty_struct *tty)
 	clear_bit(ST_TXBUSY, &portp->state);
 	clear_bit(ST_RXSTOP, &portp->state);
 	set_bit(TTY_IO_ERROR, &tty->flags);
-	tty_port_tty_set(&portp->port, NULL);
-	portp->port.flags &= ~ASYNC_NORMAL_ACTIVE;
-	portp->port.count = 0;
 	spin_unlock_irqrestore(&stli_lock, flags);
 
-	wake_up_interruptible(&portp->port.open_wait);
+	tty_port_hangup(port);
 }
 
 /*****************************************************************************/
@@ -4528,6 +4454,7 @@ static const struct tty_operations stli_ops = {
 
 static const struct tty_port_operations stli_port_ops = {
 	.carrier_raised = stli_carrier_raised,
+	.raise_dtr_rts = stli_raise_dtr_rts,
 };
 
 /*****************************************************************************/
diff --git a/include/linux/istallion.h b/include/linux/istallion.h
index 0d18407..053d5ae 100644
--- a/include/linux/istallion.h
+++ b/include/linux/istallion.h
@@ -61,7 +61,6 @@ struct stliport {
 	int			custom_divisor;
 	int			close_delay;
 	int			closing_wait;
-	int			openwaitcnt;
 	int			rc;
 	int			argsize;
 	void			*argp;


  parent reply	other threads:[~2009-01-02 13:46 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-02 13:40 [PATCH 00/75] TTY updates for 2.6.29-rc Alan Cox
2009-01-02 13:40 ` [PATCH 01/75] Blackfin Serial Driver: updates kgdb over Blackfin serial driver with kgdb framework Alan Cox
2009-01-02 13:40 ` [PATCH 02/75] Blackfin Serial Driver: fix bug - SIR driver stop receiving randomly Alan Cox
2009-01-02 13:40 ` [PATCH 03/75] Blackfin Serial Driver: Clean serial console and early prink code Alan Cox
2009-01-02 13:40 ` [PATCH 04/75] Blackfin Serial Driver: Fix bug - BF527-EZKIT unable to receive large files over UART in DMA mode Alan Cox
2009-01-02 13:40 ` [PATCH 05/75] Blackfin Serial Driver: Remove BI status for known_good_char Alan Cox
2009-01-02 13:40 ` [PATCH 06/75] n_tty: Fix loss of echoed characters and remove bkl from n_tty Alan Cox
2009-01-02 13:41 ` [PATCH 07/75] n_tty: clean up coding style Alan Cox
2009-01-02 13:41 ` [PATCH 08/75] Remove devpts_root global Alan Cox
2009-01-02 13:41 ` [PATCH 09/75] Per-mount allocated_ptys Alan Cox
2009-01-02 19:47   ` Michał Mirosław
2009-01-02 13:41 ` [PATCH 10/75] Per-mount 'config' object Alan Cox
2009-01-02 13:41 ` [PATCH 11/75] Extract option parsing to new function Alan Cox
2009-01-02 13:41 ` [PATCH 12/75] Add DEVPTS_MULTIPLE_INSTANCES config token Alan Cox
2009-01-02 13:42 ` [PATCH 13/75] Define mknod_ptmx() Alan Cox
2009-01-02 13:42 ` [PATCH 14/75] Define get_init_pts_sb() Alan Cox
2009-01-02 13:42 ` [PATCH 15/75] Enable multiple instances of devpts Alan Cox
2009-01-02 13:42 ` [PATCH 16/75] Document usage of multiple-instances " Alan Cox
2009-01-02 13:42 ` [PATCH 17/75] devpts: Coding style clean up Alan Cox
2009-01-02 13:42 ` [PATCH 18/75] sierra: Fix formatting Alan Cox
2009-01-02 13:43 ` [PATCH 19/75] tty: Fix sparse static warning for tty_driver_lookup_tty Alan Cox
2009-01-02 13:43 ` [PATCH 20/75] pty: simplify resize Alan Cox
2009-01-02 13:43 ` [PATCH 21/75] n_tty: Fix handling of control characters and continuations Alan Cox
2009-01-02 13:43 ` [PATCH 22/75] n_tty: Fix hanfling of buffer full corner cases Alan Cox
2009-01-02 13:43 ` [PATCH 23/75] n_tty: Output bells immediately on a full buffer Alan Cox
2009-01-02 13:44 ` [PATCH 24/75] tty: Fix close races in USB serial Alan Cox
2009-01-02 13:44 ` [PATCH 25/75] devpts: fix unused function warning Alan Cox
2009-01-02 13:44 ` [PATCH 26/75] Convert the oxsemi tornado special cases to use the quirk interface and not Alan Cox
2009-01-02 13:44 ` [PATCH 27/75] And here's a patch (to be applied on top of the last) which prevents Alan Cox
2009-01-02 13:44 ` [PATCH 28/75] Add device function for USB serial console Alan Cox
2009-01-02 13:44 ` [PATCH 29/75] CRED: Wrap task credential accesses in the devpts filesystem Alan Cox
2009-01-02 13:44 ` [PATCH 30/75] tty: Fix PPP hang under load Alan Cox
2009-01-02 13:45 ` [PATCH 31/75] tty_port: Add a port level carrier detect operation Alan Cox
2009-01-02 13:45 ` [PATCH 32/75] rio: Kill off ckmalloc Alan Cox
2009-01-02 13:45 ` [PATCH 33/75] tty: Pull the dtr raise into tty port Alan Cox
2009-01-02 13:45 ` [PATCH 34/75] isicom: redo locking to use tty port locks Alan Cox
2009-01-02 13:45 ` [PATCH 35/75] tty: relock generic_serial Alan Cox
2009-01-02 13:45 ` [PATCH 36/75] tty: rocketport uses different port flags to everyone else Alan Cox
2009-01-02 13:45 ` [PATCH 37/75] tty: relock riscom8 using port locks Alan Cox
2009-01-02 13:45 ` [PATCH 38/75] tty: relock the mxser driver Alan Cox
2009-01-02 13:46 ` [PATCH 39/75] tty: Introduce a tty_port generic block_til_ready Alan Cox
2009-01-02 13:46 ` Alan Cox [this message]
2009-01-02 13:46 ` [PATCH 41/75] tty: rework stallion to use the tty_port bits Alan Cox
2009-01-02 13:46 ` [PATCH 42/75] tty: ESP has been broken for locking etc forver Alan Cox
2009-01-02 13:46 ` [PATCH 43/75] tty: tty port zero baud open Alan Cox
2009-01-02 13:46 ` [PATCH 44/75] tty: Introduce some close helpers for ports Alan Cox
2009-01-02 13:46 ` [PATCH 45/75] serial: set correct baud_base for Oxford Semiconductor Ltd EXSYS EX-41092 Dual 16950 Serial adapter Alan Cox
2009-01-02 13:47 ` [PATCH 46/75] tty: USB tty devices can block in tcdrain when unplugged Alan Cox
2009-01-02 13:47 ` [PATCH 47/75] tty: N_TTY SIGIO only works for read Alan Cox
2009-01-02 13:47 ` [PATCH 48/75] tty: PTYs set TTY_DO_WRITE_WAKEUP when they don't need to Alan Cox
2009-01-02 13:47 ` [PATCH 49/75] tty: Remove some pointless casts Alan Cox
2009-01-02 13:47 ` [PATCH 50/75] tty: kref nozomi Alan Cox
2009-01-02 13:47 ` [PATCH 51/75] hso: net driver using tty without locking Alan Cox
2009-01-02 13:47 ` [PATCH 52/75] tty: Fix the HSO termios handling a bit Alan Cox
2009-01-02 13:47 ` [PATCH 53/75] tty: Modem functions for the HSO driver Alan Cox
2009-01-02 13:47 ` [PATCH 54/75] tty: relock epca Alan Cox
2009-01-02 13:48 ` [PATCH 55/75] tty: refcount the epca driver Alan Cox
2009-01-02 13:48 ` [PATCH 56/75] tty: Make epca use the port helpers Alan Cox
2009-01-02 13:48 ` [PATCH 57/75] tty: Redo the rocket driver locking Alan Cox
2009-01-02 13:48 ` [PATCH 58/75] tty: make rocketport use standard port->flags Alan Cox
2009-01-02 13:48 ` [PATCH 59/75] tty: kref the rocket driver Alan Cox
2009-01-02 13:48 ` [PATCH 60/75] tty: use port methods for " Alan Cox
2009-01-02 13:48 ` [PATCH 61/75] synclink_cs: Convert to tty_port Alan Cox
2009-01-02 13:48 ` [PATCH 62/75] tty: Drop the lock_kernel in the private ioctl hook Alan Cox
2009-01-02 13:49 ` [PATCH 63/75] serial: RS485 ioctl structure uses __u32 include linux/types.h Alan Cox
2009-01-02 13:49 ` [PATCH 64/75] __FUNCTION__ is gcc-specific, use __func__ Alan Cox
2009-01-02 13:49 ` [PATCH 65/75] tty: We want the port object to be persistent Alan Cox
2009-01-02 13:49 ` [PATCH 66/75] fix for tty-serial-move-port Alan Cox
2009-01-02 13:49 ` [PATCH 67/75] 8250: Don't clobber spinlocks Alan Cox
2009-01-02 13:49 ` [PATCH 68/75] 8250: Serial driver changes to support future Cavium OCTEON serial patches Alan Cox
2009-01-02 13:49 ` [PATCH 69/75] Serial: Allow port type to be specified when calling serial8250_register_port Alan Cox
2009-01-02 13:50 ` [PATCH 70/75] Serial: UART driver changes for Cavium OCTEON Alan Cox
2009-01-02 13:50 ` [PATCH 71/75] drivers/char/cyclades.c: cy_pci_probe: fix error path Alan Cox
2009-01-02 13:50 ` [PATCH 72/75] tty: Fix an ircomm warning and note another bug Alan Cox
2009-01-05 17:42   ` Wolfram Sang
2009-01-05 18:01     ` Alan Cox
2009-01-02 13:50 ` [PATCH 73/75] hso modem detect fix patch against Alan Cox'es tty tree Alan Cox
2009-01-02 13:50 ` [PATCH 74/75] hso maintainers update patch Alan Cox
2009-01-02 13:50 ` [PATCH 75/75] serial_8250: support for Sealevel Systems Model 7803 COMM+8 Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090102134616.13472.88062.stgit@localhost.localdomain \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=linux-serial@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox