Skip to contentSkip to conversation

drivers/isdn/gigaset: new M101 driver

PATCH In review Tilman Schmidt 4 participants 11 messages Feb 1, 2007 – Feb 12, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/isdn/gigaset: new M101 driver

The following patch is based on 2.6.20-rc6-mm3, and depends on the patches consolidate-line-discipline-number-definitions-v2*.patch in the -mm tree. Please consider for the 2.6.21 queue.

This adds the line discipline based driver for the Gigaset M101 wireless RS232 adapter. It also improves the documentation a bit.

---

 Documentation/isdn/README.gigaset  |   65 ++
 drivers/isdn/gigaset/Kconfig       |   25 -
 drivers/isdn/gigaset/Makefile      |    2 
 drivers/isdn/gigaset/asyncdata.c   |    5 
 drivers/isdn/gigaset/ser-gigaset.c |  853 +++++++++++++++++++++++++++++++++++++
 include/linux/gigaset_dev.h        |    2 
 6 files changed, 929 insertions(+), 23 deletions(-)
Documentation/isdn/README.gigaset +48 -17
diff -rupNX dont-diff linux-2.6.20-rc6-mm3-orig/Documentation/isdn/README.gigaset local/Documentation/isdn/README.gigaset
@@ -8,29 +8,33 @@ GigaSet 307x Device Driver
      This release supports the connection of the Gigaset 307x/417x family of
      ISDN DECT bases via Gigaset M101 Data, Gigaset M105 Data or direct USB
      connection. The following devices are reported to be compatible:
-     307x/417x:
-        Gigaset SX255isdn
-        Gigaset SX353isdn
-        Sinus 45 [AB] isdn (Deutsche Telekom)
-        Sinus 721X/XA
+
+     Bases:
+        Siemens Gigaset 3070/3075 isdn
+        Siemens Gigaset 4170/4175 isdn
+        Siemens Gigaset SX205/255
+        Siemens Gigaset SX353
+        T-Com Sinus 45 [AB] isdn
+        T-Com Sinus 721X[A] [SE]
         Vox Chicago 390 ISDN (KPN Telecom)
-     M101:
-        Sinus 45 Data 1 (Telekom)
-     M105:
-        Gigaset USB Adapter DECT
-        Sinus 45 Data 2 (Telekom)
-        Sinus 721 data
+
+     RS232 data boxes:
+        Siemens Gigaset M101 Data
+        T-Com Sinus 45 Data 1
+
+     USB data boxes:
+        Siemens Gigaset M105 Data
+        Siemens Gigaset USB Adapter DECT
+        T-Com Sinus 45 Data 2
+        T-Com Sinus 721 data
         Chicago 390 USB (KPN)
+
      See also http://www.erbze.info/sinus_gigaset.htm and
               http://gigaset307x.sourceforge.net/
 
      We had also reports from users of Gigaset M105 who could use the drivers
      with SX 100 and CX 100 ISDN bases (only in unimodem mode, see section 2.4.)
      If you have another device that works with our driver, please let us know.
-     For example, Gigaset SX205isdn/Sinus 721 X SE and Gigaset SX303isdn bases
-     are just versions without answering machine of models known to work, so
-     they should work just as well; but so far we are lacking positive reports
-     on these.
 
      Chances of getting an USB device to work are good if the output of
         lsusb
@@ -60,14 +64,28 @@ GigaSet 307x Device Driver
      To get the device working, you have to load the proper kernel module. You
      can do this using
          modprobe modulename
-     where modulename is usb_gigaset (M105) or bas_gigaset (direct USB
-     connection to the base).
+     where modulename is ser_gigaset (M101), usb_gigaset (M105), or
+     bas_gigaset (direct USB connection to the base).
+
+     The module ser_gigaset provides a serial line discipline N_GIGASET_M101
+     which drives the device through the regular serial line driver. To use it,
+     run the Gigaset M101 daemon "gigasetm101d" (also available from
+     http://sourceforge.net/projects/gigaset307x/) with the device file of the
+     RS232 port to the M101 as an argument, for example:
+	 gigasetm101d /dev/ttyS1
+     This will open the device file, set its line discipline to N_GIGASET_M101,
+     and then sleep in the background, keeping the device open so that the
+     line discipline remains active. To deactivate it, kill the daemon, for
+     example with
+	 killall gigasetm101d
+     before disconnecting the device.
 
 2.2. Device nodes for user space programs
      ------------------------------------
      The device can be accessed from user space (eg. by the user space tools
      mentioned in 1.2.) through the device nodes:
 
+     - /dev/ttyGS0 for M101 (RS232 data boxes)
      - /dev/ttyGU0 for M105 (USB data boxes)
      - /dev/ttyGB0 for the base driver (direct USB connection)
 
@@ -168,6 +186,19 @@ GigaSet 307x Device Driver
      You can also use /sys/class/tty/ttyGxy/cidmode for changing the CID mode
      setting (ttyGxy is ttyGU0 or ttyGB0).
 
+2.6. M105 Undocumented USB Requests
+     ------------------------------
+
+     The Gigaset M105 USB data box understands a couple of useful, but
+     undocumented USB commands. These requests are not used in normal
+     operation (for wireless access to the base), but are needed for access
+     to the M105's own configuration mode (registration to the base, baudrate
+     and line format settings, device status queries) via the gigacontr
+     utility. Their use is disabled in the driver by default for safety
+     reasons but can be enabled by setting the kernel configuration option
+     "Support for undocumented USB requests" (GIGASET_UNDOCREQ) to "Y" and
+     recompiling.
+
 
 3.   Troubleshooting
      ---------------
drivers/isdn/gigaset/Kconfig +21 -4
diff -rupNX dont-diff linux-2.6.20-rc6-mm3-orig/drivers/isdn/gigaset/Kconfig local/drivers/isdn/gigaset/Kconfig
@@ -7,7 +7,13 @@ config ISDN_DRV_GIGASET
 	select CRC_CCITT
 	select BITREVERSE
 	help
-	  Say m here if you have a Gigaset or Sinus isdn device.
+	  This driver supports the Siemens Gigaset SX205/255 family of
+	  ISDN DECT bases, including the predecessors Gigaset 3070/3075
+	  and 4170/4175 and their T-Com versions Sinus 45isdn and Sinus
+	  721X.
+	  If you have one of these devices, say M here and for at least
+	  one of the connection specific parts that follow.
+	  This will build a module called "gigaset".
 
 if ISDN_DRV_GIGASET!=n
 
@@ -15,14 +21,25 @@ config GIGASET_BASE
 	tristate "Gigaset base station support"
 	depends on ISDN_DRV_GIGASET && USB
 	help
-	  Say m here if you need to communicate with the base
-	  directly via USB.
+	  Say M here if you want to use the USB interface of the Gigaset
+	  base for connection to your system.
+	  This will build a module called "bas_gigaset".
 
 config GIGASET_M105
 	tristate "Gigaset M105 support"
 	depends on ISDN_DRV_GIGASET && USB
 	help
-	  Say m here if you need the driver for the Gigaset M105 device.
+	  Say M here if you want to connect to the Gigaset base via DECT
+	  using a Gigaset M105 (Sinus 45 Data 2) USB DECT device.
+	  This will build a module called "usb_gigaset".
+
+config GIGASET_M101
+	tristate "Gigaset M101 support"
+	depends on ISDN_DRV_GIGASET
+	help
+	  Say M here if you want to connect to the Gigaset base via DECT
+	  using a Gigaset M101 (Sinus 45 Data 1) RS232 DECT device.
+	  This will build a module called "ser_gigaset".
 
 config GIGASET_DEBUG
 	bool "Gigaset debugging"
drivers/isdn/gigaset/Makefile +2 -0
diff -rupNX dont-diff linux-2.6.20-rc6-mm3-orig/drivers/isdn/gigaset/Makefile local/drivers/isdn/gigaset/Makefile
@@ -1,6 +1,8 @@
 gigaset-y := common.o interface.o proc.o ev-layer.o i4l.o
 usb_gigaset-y := usb-gigaset.o asyncdata.o
 bas_gigaset-y := bas-gigaset.o isocdata.o
+ser_gigaset-y := ser-gigaset.o asyncdata.o
 
 obj-$(CONFIG_GIGASET_M105) += usb_gigaset.o gigaset.o
 obj-$(CONFIG_GIGASET_BASE) += bas_gigaset.o gigaset.o
+obj-$(CONFIG_GIGASET_M105) += ser_gigaset.o gigaset.o
drivers/isdn/gigaset/asyncdata.c +5 -0
diff -rupNX dont-diff linux-2.6.20-rc6-mm3-orig/drivers/isdn/gigaset/asyncdata.c local/drivers/isdn/gigaset/asyncdata.c
@@ -13,6 +13,11 @@
  * =====================================================================
  */
 
+/* Kbuild sometimes doesn't set this */
+#ifndef KBUILD_MODNAME
+#define KBUILD_MODNAME "asy_gigaset"
+#endif
+
 #include "gigaset.h"
 #include <linux/crc-ccitt.h>
 #include <linux/bitrev.h>
drivers/isdn/gigaset/ser-gigaset.c +853 -0

853 lines not on this page · raw message

include/linux/gigaset_dev.h +0 -2
diff -rupX dont-diff linux-2.6.20-rc6-mm3-orig/include/linux/gigaset_dev.h local/include/linux/gigaset_dev.h
@@ -9,8 +9,6 @@
  *    published by the Free Software Foundation; either version 2 of
  *    the License, or (at your option) any later version.
  * =====================================================================
- * Version: $Id: gigaset_dev.h,v 1.4.4.4 2005/11/21 22:28:09 hjlipp Exp $
- * =====================================================================
  */
 
 #ifndef GIGASET_INTERFACE_H
#1 lore raw

drivers/isdn/gigaset/asyncdata.c line 19

Quoted 4 lines · On Thu, 1 Feb 2007 22:12:24 +0100 Tilman Schmidt <[email protected]> wrote:
drivers/isdn/gigaset/asyncdata.c +4 -0
+/* Kbuild sometimes doesn't set this */
+#ifndef KBUILD_MODNAME
+#define KBUILD_MODNAME "asy_gigaset"
+#endif

That's a subtle way of reporting a kbuild bug ;)

What's the story here?

Quoted 38 lines
drivers/isdn/gigaset/ser-gigaset.c +35 -0
@@ -0,0 +1,853 @@
+/* This is the serial hardware link layer (HLL) for the Gigaset 307x isdn
+ * DECT base (aka Sinus 45 isdn) using the RS232 DECT data module M101,
+ * written as a line discipline.
+ *
+ * =====================================================================
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ * =====================================================================
+ */
+
+#include "gigaset.h"
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/platform_device.h>
+#include <linux/tty.h>
+#include <linux/poll.h>
+
+/* Version Information */
+#define DRIVER_AUTHOR "Tilman Schmidt"
+#define DRIVER_DESC "Serial Driver for Gigaset 307x using Siemens M101"
+
+#define GIGASET_MINORS     1
+#define GIGASET_MINOR      0
+#define GIGASET_MODULENAME "ser_gigaset"
+#define GIGASET_DEVNAME    "ttyGS"
+
+/* length limit according to Siemens 3070usb-protokoll.doc ch. 2.1 */
+#define IF_WRITEBUF 264
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");

drivers/isdn/gigaset/ser-gigaset.c line 45

Quoted 10 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+MODULE_ALIAS_LDISC(N_GIGASET_M101);
+
+static int startmode = SM_ISDN;
+module_param(startmode, int, S_IRUGO);
+MODULE_PARM_DESC(startmode, "initial operation mode");
+static int cidmode = 1;
+module_param(cidmode, int, S_IRUGO);
+MODULE_PARM_DESC(cidmode, "stay in CID mode when idle");
+
+static struct gigaset_driver *driver = NULL;

Unneeded initialisation.

Quoted 4 lines
drivers/isdn/gigaset/ser-gigaset.c +4 -0
+struct ser_cardstate {
+	struct platform_device	dev;
+	struct tty_struct	*tty;
+	atomic_t		refcnt;

drivers/isdn/gigaset/ser-gigaset.c line 60

Quoted 10 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+	struct semaphore	dead_sem;
+};
+
+static struct platform_driver device_driver = {
+	.driver = {
+		.name = GIGASET_MODULENAME,
+	},
+};
+
+struct ser_bc_state {};

Does this need kernel-wide scope?

Quoted 4 lines
drivers/isdn/gigaset/ser-gigaset.c +4 -0
+static void flush_send_queue(struct cardstate *);
+
+/* transmit data from current open skb
+ * result: number of bytes sent or error code < 0

drivers/isdn/gigaset/ser-gigaset.c line 75

Quoted 10 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+ */
+static int write_modem(struct cardstate *cs)
+{
+	struct tty_struct *tty = cs->hw.ser->tty;
+	struct bc_state *bcs = &cs->bcs[0];	/* only one channel */
+	struct sk_buff *skb = bcs->tx_skb;
+	int sent;
+
+	if (!tty || !tty->driver || !skb)
+		return -EFAULT;

Is EFAULT appropriate?

Can all these things happen?

drivers/isdn/gigaset/ser-gigaset.c line 83

Quoted 7 lines
drivers/isdn/gigaset/ser-gigaset.c +7 -0
+	if (!skb->len) {
+		dev_kfree_skb_any(skb);
+		bcs->tx_skb = NULL;
+		return -EINVAL;
+	}
+
+	set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);

Is a client of the tty interface supposed to be diddling tty flags like this?

Quoted 27 lines
drivers/isdn/gigaset/ser-gigaset.c +27 -0
+	sent = tty->driver->write(tty, skb->data, skb->len);
+	gig_dbg(DEBUG_OUTPUT, "write_modem: sent %d", sent);
+	if (sent < 0) {
+		/* error */
+		flush_send_queue(cs);
+		return sent;
+	}
+	skb_pull(skb, sent);
+	if (!skb->len) {
+		/* skb sent completely */
+		gigaset_skb_sent(bcs, skb);
+
+		gig_dbg(DEBUG_INTR, "kfree skb (Adr: %lx)!",
+			(unsigned long) skb);
+		dev_kfree_skb_any(skb);
+		bcs->tx_skb = NULL;
+	}
+	return sent;
+}
+
+/*
+ * transmit first queued command buffer
+ * result: number of bytes sent or error code < 0
+ */
+static int send_cb(struct cardstate *cs)
+{
+	struct tty_struct *tty = cs->hw.ser->tty;

drivers/isdn/gigaset/ser-gigaset.c line 120

Quoted 10 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+	struct cmdbuf_t *cb, *tcb;
+	unsigned long flags;
+	int sent = 0;
+
+	if (!tty || !tty->driver)
+		return -EFAULT;
+
+	spin_lock_irqsave(&cs->cmdlock, flags);
+	cb = cs->cmdbuf;
+	spin_unlock_irqrestore(&cs->cmdlock, flags);

It is doubtful if the locking here does anything useful.

Quoted 77 lines
drivers/isdn/gigaset/ser-gigaset.c +74 -0
+	if (!cb)
+		return 0;	/* nothing to do */
+
+	if (cb->len) {
+		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+		sent = tty->driver->write(tty, cb->buf + cb->offset, cb->len);
+		if (sent < 0) {
+			/* error */
+			gig_dbg(DEBUG_OUTPUT, "send_cb: write error %d", sent);
+			flush_send_queue(cs);
+			return sent;
+		}
+		cb->offset += sent;
+		cb->len -= sent;
+		gig_dbg(DEBUG_OUTPUT, "send_cb: sent %d, left %u, queued %u",
+			sent, cb->len, cs->cmdbytes);
+	}
+
+	while (cb && !cb->len) {
+		spin_lock_irqsave(&cs->cmdlock, flags);
+		cs->cmdbytes -= cs->curlen;
+		tcb = cb;
+		cs->cmdbuf = cb = cb->next;
+		if (cb) {
+			cb->prev = NULL;
+			cs->curlen = cb->len;
+		} else {
+			cs->lastcmdbuf = NULL;
+			cs->curlen = 0;
+		}
+		spin_unlock_irqrestore(&cs->cmdlock, flags);
+
+		if (tcb->wake_tasklet)
+			tasklet_schedule(tcb->wake_tasklet);
+		kfree(tcb);
+	}
+	return sent;
+}
+
 
...
 
+/*
+ * queue an AT command string for transmission to the Gigaset device
+ * parameters:
+ *	cs		controller state structure
+ *	buf		buffer containing the string to send
+ *	len		number of characters to send
+ *	wake_tasklet	tasklet to run when transmission is complete, or NULL
+ * return value:
+ *	number of bytes queued, or error code < 0
+ */
+static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
+                             int len, struct tasklet_struct *wake_tasklet)
+{
+	struct cmdbuf_t *cb;
+	unsigned long flags;
+
+	gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
+	                     DEBUG_TRANSCMD : DEBUG_LOCKCMD,
+	                   "CMD Transmit", len, buf);
+
+	if (len <= 0)
+		return 0;
+
+	if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
+		dev_err(cs->dev, "%s: out of memory!\n", __func__);
+		return -ENOMEM;
+	}
+
+	memcpy(cb->buf, buf, len);
+	cb->len = len;
+	cb->offset = 0;
+	cb->next = NULL;
+	cb->wake_tasklet = wake_tasklet;
+
+	spin_lock_irqsave(&cs->cmdlock, flags);

drivers/isdn/gigaset/ser-gigaset.c line 276

Quoted 10 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+	cb->prev = cs->lastcmdbuf;
+	if (cs->lastcmdbuf)
+		cs->lastcmdbuf->next = cb;
+	else {
+		cs->cmdbuf = cb;
+		cs->curlen = len;
+	}
+	cs->cmdbytes += len;
+	cs->lastcmdbuf = cb;
+	spin_unlock_irqrestore(&cs->cmdlock, flags);

Would the use of list_heads simplify things here? Or are we dealing with a hardware-imposed layout?

Quoted 11 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+	spin_lock_irqsave(&cs->lock, flags);
+	if (cs->connected)
+		tasklet_schedule(&cs->write_tasklet);
+	spin_unlock_irqrestore(&cs->lock, flags);
+	return len;
+}
+
...
+
+/*
+ * implementation of ioctl(GIGASET_BRKCHARS)

drivers/isdn/gigaset/ser-gigaset.c line 335

Quoted 10 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+ * parameter:
+ *	controller state structure
+ * return value:
+ *	-EINVAL (unimplemented function)
+ */
+static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
+{
+	/* not implemented */
+	return -EINVAL;
+}

ENOTTY might be more appropriate here.

drivers/isdn/gigaset/ser-gigaset.c line 394

Quoted 7 lines
drivers/isdn/gigaset/ser-gigaset.c +7 -0
+/*
+ * Free hardware specific device data
+ * This will be called by "gigaset_freecs" in common.c
+ */
+static void gigaset_freecshw(struct cardstate *cs)
+{
+	tasklet_kill(&cs->write_tasklet);

Does tasklet kill() wait for the tasklet to stop running on a different CPU? I thing so, but it was written in the days before we commented code.

drivers/isdn/gigaset/ser-gigaset.c line 407

Quoted 13 lines
drivers/isdn/gigaset/ser-gigaset.c +13 -0
+	if (!cs->hw.ser)
+		return;
+	dev_set_drvdata(&cs->hw.ser->dev.dev, NULL);
+	platform_device_unregister(&cs->hw.ser->dev);
+	kfree(cs->hw.ser);
+	cs->hw.ser = NULL;
+}
+
+/* dummy to shut up framework warning */
+static void gigaset_device_release(struct device *dev)
+{
+	//FIXME anything to do? cf. platform_device_release()
+}

Ask Greg ;)

drivers/isdn/gigaset/ser-gigaset.c line 588

Quoted 1 line
drivers/isdn/gigaset/ser-gigaset.c +1 -0
+			down(&cs->hw.ser->dead_sem);

Does this actually use the semaphore's counting feature? If not, can we switch it to a mutex?

Quoted 32 lines
drivers/isdn/gigaset/ser-gigaset.c +32 -0
+/*
+ * Ioctl on the tty.
+ * Called in process context only.
+ * May be re-entered by multiple ioctl calling threads.
+ */
+static int
+gigaset_tty_ioctl(struct tty_struct *tty, struct file *file,
+		  unsigned int cmd, unsigned long arg)
+{
+	struct cardstate *cs = cs_get(tty);
+	int rc, val;
+	int __user *p = (int __user *)arg;
+
+	if (!cs)
+		return -ENXIO;
+
+	switch (cmd) {
+	case TCGETS:
+	case TCGETA:
+		/* pass through to underlying serial device */
+		rc = n_tty_ioctl(tty, file, cmd, arg);
+		break;
+
+	case TCFLSH:
+		/* flush our buffers and the serial port's buffer */
+		switch (arg) {
+		case TCIFLUSH:
+			/* no own input buffer to flush */
+			break;
+		case TCIOFLUSH:
+		case TCOFLUSH:
+			flush_send_queue(cs);

drivers/isdn/gigaset/ser-gigaset.c line 677

Quoted 10 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+			break;
+		}
+		/* flush the serial port's buffer */
+		rc = n_tty_ioctl(tty, file, cmd, arg);
+		break;
+
+	case FIONREAD:
+		/* unused, always return zero */
+		val = 0;
+		rc = put_user(val, p) ? -EFAULT : 0;

I think

		rc = put_user(val, p);

will do the same thing here.

Quoted 36 lines

+ * Will not be re-entered while running but other ldisc functions
+ * may be called in parallel.
+ * Can be called from hard interrupt level as well as soft interrupt
+ * level or mainline.
+ * Parameters:
+ * tty tty structure
+ * buf buffer containing received characters
+ * cflags buffer containing error flags for received characters (ignored)
+ * count number of received characters
+ */

drivers/isdn/gigaset/ser-gigaset.c +26 -0
+static void
+gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
+		    char *cflags, int count)
+{
+	struct cardstate *cs = cs_get(tty);
+	unsigned tail, head, n;
+	struct inbuf_t *inbuf;
+
+	if (!cs)
+		return;
+	if (!(inbuf = cs->inbuf)) {
+		dev_err(cs->dev, "%s: no inbuf\n", __func__);
+		cs_put(cs);
+		return;
+	}
+
+	tail = atomic_read(&inbuf->tail);
+	head = atomic_read(&inbuf->head);
+	gig_dbg(DEBUG_INTR, "buffer state: %u -> %u, receive %u bytes",
+		head, tail, count);
+
+	if (head <= tail) {
+		n = RBUFSIZE - tail;
+		if (count >= n) {
+			/* buffer wraparound */
+			memcpy(inbuf->data + tail, buf, n);

drivers/isdn/gigaset/ser-gigaset.c line 745

Quoted 10 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+			tail = 0;
+			buf += n;
+			count -= n;
+		} else {
+			memcpy(inbuf->data + tail, buf, count);
+			tail += count;
+			buf += count;
+			count = 0;
+		}
+	}

Perhaps the (fairly revolting) circ_buf.h can be used for this stuff.

Quoted 22 lines
drivers/isdn/gigaset/ser-gigaset.c +22 -0
+	if (count > 0) {
+		/* tail < head and some data left */
+		n = head - tail - 1;
+		if (count > n) {
+			dev_err(cs->dev,
+				"inbuf overflow, discarding %d bytes\n",
+				count - n);
+			count = n;
+		}
+		memcpy(inbuf->data + tail, buf, count);
+		tail += count;
+	}
+
+	gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
+	atomic_set(&inbuf->tail, tail);
+
+	/* Everything was received .. Push data into handler */
+	gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
+	gigaset_schedule_event(cs);
+	cs_put(cs);
+}
+
#2 lore raw
Quoted 7 lines · Andrew Morton

drivers/isdn/gigaset/ser-gigaset.c line 407

Quoted 5 lines
drivers/isdn/gigaset/ser-gigaset.c +5 -0
+/* dummy to shut up framework warning */
+static void gigaset_device_release(struct device *dev)
+{
+	//FIXME anything to do? cf. platform_device_release()
+}

Ask Greg ;)

Oh come on people. Don't provide an empty function because the kernel is complaining that you don't provide a release function. Yes it will shut the kernel up but did you ever think _why_ the kernel was complaining? Did you think it did it just for fun?

Think people, think...

You need to free your memory here, don't just provide an empty function, that shows the driver is broken.

thanks,

greg k-h

#3 lore raw

Am 03.02.2007 17:09 schrieb Greg KH:

Quoted 8 lines · Andrew Morton
Quoted 6 lines

drivers/isdn/gigaset/ser-gigaset.c line 407

Quoted 5 lines
drivers/isdn/gigaset/ser-gigaset.c +5 -0
+/* dummy to shut up framework warning */
+static void gigaset_device_release(struct device *dev)
+{
+	//FIXME anything to do? cf. platform_device_release()
+}

Ask Greg ;)

Quoted 4 lines

Oh come on people. Don't provide an empty function because the kernel is complaining that you don't provide a release function. Yes it will shut the kernel up but did you ever think _why_ the kernel was complaining?

Actually, I did. Just guess how that FIXME came to be.
Hint: the kernel shuts up just as well without it.

Quoted 1 line

Did you think it did it just for fun?

No, that was not among the explanations I considered. Although, come to think of it ... nah, that would really be too weird.

Quoted 1 line

Think people, think...

Ahem.

Quoted 2 lines

You need to free your memory here, don't just provide an empty function, that shows the driver is broken.

Call me silly and incapable of thinking, but to me it's far from clear _what_ memory I am supposed to free there. Certainly neither memory I will still be needing after platform_device_unregister() nor memory that's being taken care of elsewhere. Between the two, in my case there's nothing left, so the release function is empty. If that shows my driver is broken, please explain in what way.

Thanks,
Tilman

Signature · 4 lines
Tilman Schmidt                          E-Mail: [email protected]
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)
#6 lore raw
In reply to Andrew Morton

Thanks, Andrew, for your review. Some replies:

Am 02.02.2007 02:13 schrieb Andrew Morton:

Quoted 11 lines

drivers/isdn/gigaset/asyncdata.c line 19

Quoted 4 lines · On Thu, 1 Feb 2007 22:12:24 +0100 Tilman Schmidt <[email protected]> wrote:
drivers/isdn/gigaset/asyncdata.c +4 -0
+/* Kbuild sometimes doesn't set this */
+#ifndef KBUILD_MODNAME
+#define KBUILD_MODNAME "asy_gigaset"
+#endif

That's a subtle way of reporting a kbuild bug ;)

What's the story here?

If an object file is linked into more than one module (like asyncdata.o which is linked into both ser_gigaset and usb_gigaset) then Kbuild compiles it only once but cannot decide which of the module names to put into KBUILD_MODNAME, so it takes the easy way out and doesn't define KBUILD_MODNAME at all. I'm not sure if that qualifies as a kbuild bug. I'd rather call it a limitation.

Quoted 11 lines

drivers/isdn/gigaset/ser-gigaset.c line 75

Quoted 9 lines
drivers/isdn/gigaset/ser-gigaset.c +9 -0
+static int write_modem(struct cardstate *cs)
+{
+	struct tty_struct *tty = cs->hw.ser->tty;
+	struct bc_state *bcs = &cs->bcs[0];	/* only one channel */
+	struct sk_buff *skb = bcs->tx_skb;
+	int sent;
+
+	if (!tty || !tty->driver || !skb)
+		return -EFAULT;

Is EFAULT appropriate?

It hardly matters, as it isn't propagated anywhere. -1 would work just as well.

Quoted 1 line

Can all these things happen?

Theoretically no, but this is called from a tasklet and I have already traced a bug which made one of these disappear. Not having the kernel crash completely in such an event considerably helps debugging.

Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);

Is a client of the tty interface supposed to be diddling tty flags like this?

Documentation/tty.txt says so. (Yes, I wrote that part myself, but nobody protested. ;-) Also, the PPP line discipline does the same.

Quoted 5 lines

drivers/isdn/gigaset/ser-gigaset.c line 120

Quoted 3 lines
drivers/isdn/gigaset/ser-gigaset.c +3 -0
+	spin_lock_irqsave(&cs->cmdlock, flags);
+	cb = cs->cmdbuf;
+	spin_unlock_irqrestore(&cs->cmdlock, flags);

It is doubtful if the locking here does anything useful.

It assures atomicity when reading the cs->cmdbuf pointer.

Quoted 5 lines
Quoted 5 lines
drivers/isdn/gigaset/ser-gigaset.c +5 -0
+	spin_lock_irqsave(&cs->cmdlock, flags);
+	cb->prev = cs->lastcmdbuf;
+	if (cs->lastcmdbuf)
+		cs->lastcmdbuf->next = cb;
+	else {
Quoted 8 lines

drivers/isdn/gigaset/ser-gigaset.c line 276

Quoted 6 lines
drivers/isdn/gigaset/ser-gigaset.c +6 -0
+		cs->cmdbuf = cb;
+		cs->curlen = len;
+	}
+	cs->cmdbytes += len;
+	cs->lastcmdbuf = cb;
+	spin_unlock_irqrestore(&cs->cmdlock, flags);

Would the use of list_heads simplify things here?

I don't think so. The operations in list.h do not keep track of the total byte count, and adding that in a race-free way appears non-trivial.

Quoted 10 lines

drivers/isdn/gigaset/ser-gigaset.c line 394

Quoted 7 lines
drivers/isdn/gigaset/ser-gigaset.c +7 -0
+/*
+ * Free hardware specific device data
+ * This will be called by "gigaset_freecs" in common.c
+ */
+static void gigaset_freecshw(struct cardstate *cs)
+{
+	tasklet_kill(&cs->write_tasklet);

Does tasklet kill() wait for the tasklet to stop running on a different CPU? I thing so, but it was written in the days before we commented code.

Its description in LDD3 ch. 7 seems to imply that it does.

Quoted 4 lines

drivers/isdn/gigaset/ser-gigaset.c line 588

Quoted 1 line
drivers/isdn/gigaset/ser-gigaset.c +1 -0
+			down(&cs->hw.ser->dead_sem);

Does this actually use the semaphore's counting feature? If not, can we switch it to a mutex?

I stole that code from the PPP line discipline. It is to assure all other ldisc methods have completed before the close method proceeds. This doesn't look like a case for a mutex to me, but I'm open to suggestions if it's important to avoid a semaphore here.

Quoted 14 lines
Quoted 14 lines
drivers/isdn/gigaset/ser-gigaset.c +14 -0
+	tail = atomic_read(&inbuf->tail);
+	head = atomic_read(&inbuf->head);
+	gig_dbg(DEBUG_INTR, "buffer state: %u -> %u, receive %u bytes",
+		head, tail, count);
+
+	if (head <= tail) {
+		n = RBUFSIZE - tail;
+		if (count >= n) {
+			/* buffer wraparound */
+			memcpy(inbuf->data + tail, buf, n);
+			tail = 0;
+			buf += n;
+			count -= n;
+		} else {
Quoted 8 lines

drivers/isdn/gigaset/ser-gigaset.c line 745

Quoted 6 lines
drivers/isdn/gigaset/ser-gigaset.c +6 -0
+			memcpy(inbuf->data + tail, buf, count);
+			tail += count;
+			buf += count;
+			count = 0;
+		}
+	}

Perhaps the (fairly revolting) circ_buf.h can be used for this stuff.

It probably could, but IMHO readability would suffer rather than improve.

Thanks,
Tilman

PS: My patch hasn't appeared on LKML so far. Any idea why?

Signature · 4 lines
Tilman Schmidt                          E-Mail: [email protected]
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)
#7 lore raw
Quoted 7 lines · On Sun, 04 Feb 2007 02:32:41 +0100 Tilman Schmidt <[email protected]> wrote:
Quoted 5 lines

drivers/isdn/gigaset/ser-gigaset.c line 120

Quoted 3 lines
drivers/isdn/gigaset/ser-gigaset.c +3 -0
+	spin_lock_irqsave(&cs->cmdlock, flags);
+	cb = cs->cmdbuf;
+	spin_unlock_irqrestore(&cs->cmdlock, flags);

It is doubtful if the locking here does anything useful.

It assures atomicity when reading the cs->cmdbuf pointer.

I think it's bogus. If the quantity being copied here is more than 32-bits then yes, a lock is appropriate. But if it's a single word then it's unlikely that the locking does anything useful. Or there might be a bug here.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/isdn/gigaset/ser-gigaset.c +5 -0
+	spin_lock_irqsave(&cs->cmdlock, flags);
+	cb->prev = cs->lastcmdbuf;
+	if (cs->lastcmdbuf)
+		cs->lastcmdbuf->next = cb;
+	else {
Quoted 8 lines

drivers/isdn/gigaset/ser-gigaset.c line 276

Quoted 6 lines
drivers/isdn/gigaset/ser-gigaset.c +6 -0
+		cs->cmdbuf = cb;
+		cs->curlen = len;
+	}
+	cs->cmdbytes += len;
+	cs->lastcmdbuf = cb;
+	spin_unlock_irqrestore(&cs->cmdlock, flags);

Would the use of list_heads simplify things here?

Quoted 3 lines

I don't think so. The operations in list.h do not keep track of the total byte count, and adding that in a race-free way appears non-trivial.

Maintaining a byte count isn't related to maintaining a list.

Quoted 9 lines
Quoted 4 lines

drivers/isdn/gigaset/ser-gigaset.c line 588

Quoted 1 line
drivers/isdn/gigaset/ser-gigaset.c +1 -0
+			down(&cs->hw.ser->dead_sem);

Does this actually use the semaphore's counting feature? If not, can we switch it to a mutex?

I stole that code from the PPP line discipline. It is to assure all other ldisc methods have completed before the close method proceeds. This doesn't look like a case for a mutex to me, but I'm open to suggestions if it's important to avoid a semaphore here.

If a sleeping lock is being used as a mutex, please use a mutex. We prefer that semaphores only be used in those situations where their counting feature is being used.

Reasons: a) mutexes have better runtime debugging support and b) Ingo had some plans to reimplement semaphores in an arch-neutral way and for some reason reducing the number of callers would help that. I forget what the reason was, actually.

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
drivers/isdn/gigaset/ser-gigaset.c +14 -0
+	tail = atomic_read(&inbuf->tail);
+	head = atomic_read(&inbuf->head);
+	gig_dbg(DEBUG_INTR, "buffer state: %u -> %u, receive %u bytes",
+		head, tail, count);
+
+	if (head <= tail) {
+		n = RBUFSIZE - tail;
+		if (count >= n) {
+			/* buffer wraparound */
+			memcpy(inbuf->data + tail, buf, n);
+			tail = 0;
+			buf += n;
+			count -= n;
+		} else {
Quoted 8 lines

drivers/isdn/gigaset/ser-gigaset.c line 745

Quoted 6 lines
drivers/isdn/gigaset/ser-gigaset.c +6 -0
+			memcpy(inbuf->data + tail, buf, count);
+			tail += count;
+			buf += count;
+			count = 0;
+		}
+	}

Perhaps the (fairly revolting) circ_buf.h can be used for this stuff.

Quoted 2 lines

It probably could, but IMHO readability would suffer rather than improve.

How about kernel/kfifo.c?

#8 lore raw

Am 04.02.2007 02:56 schrieb Andrew Morton:

Quoted 6 lines · On Sun, 04 Feb 2007 02:32:41 +0100 Tilman Schmidt <[email protected]> wrote:
Quoted 5 lines
Quoted 5 lines

drivers/isdn/gigaset/ser-gigaset.c line 120

Quoted 4 lines
drivers/isdn/gigaset/ser-gigaset.c +3 -0
+	spin_lock_irqsave(&cs->cmdlock, flags);
+	cb = cs->cmdbuf;
+	spin_unlock_irqrestore(&cs->cmdlock, flags);

It is doubtful if the locking here does anything useful.

Quoted 6 lines
Quoted 1 line

It assures atomicity when reading the cs->cmdbuf pointer.

I think it's bogus. If the quantity being copied here is more than 32-bits then yes, a lock is appropriate. But if it's a single word then it's unlikely that the locking does anything useful. Or there might be a bug here.

It's a pointer. Are reads and writes of pointer sized objects guaranteed to be atomic on every platform? If so, I'll happily omit the locking.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

drivers/isdn/gigaset/ser-gigaset.c line 276

Quoted 11 lines
drivers/isdn/gigaset/ser-gigaset.c +11 -0
+	spin_lock_irqsave(&cs->cmdlock, flags);
+	cb->prev = cs->lastcmdbuf;
+	if (cs->lastcmdbuf)
+		cs->lastcmdbuf->next = cb;
+	else {
+		cs->cmdbuf = cb;
+		cs->curlen = len;
+	}
+	cs->cmdbytes += len;
+	cs->lastcmdbuf = cb;
+	spin_unlock_irqrestore(&cs->cmdlock, flags);

Would the use of list_heads simplify things here?

Quoted 5 lines
Quoted 3 lines

I don't think so. The operations in list.h do not keep track of the total byte count, and adding that in a race-free way appears non-trivial.

Maintaining a byte count isn't related to maintaining a list.

Sure. But your question was whether the list.h operations would simplify this code. AFAICS it wouldn't, because the necessity of maintaining the byte count would complicate a list.h based solution beyond the current one. Also, this is part of the interface with the components of the Gigaset driver which are already part of the kernel. Changing this to a list_head now would require significant changes in those other parts, too.

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 10 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+	tail = atomic_read(&inbuf->tail);
+	head = atomic_read(&inbuf->head);
+	gig_dbg(DEBUG_INTR, "buffer state: %u -> %u, receive %u bytes",
+		head, tail, count);
+
+	if (head <= tail) {
+		n = RBUFSIZE - tail;
+		if (count >= n) {
+			/* buffer wraparound */
+			memcpy(inbuf->data + tail, buf, n);

drivers/isdn/gigaset/ser-gigaset.c line 745

Quoted 10 lines
drivers/isdn/gigaset/ser-gigaset.c +10 -0
+			tail = 0;
+			buf += n;
+			count -= n;
+		} else {
+			memcpy(inbuf->data + tail, buf, count);
+			tail += count;
+			buf += count;
+			count = 0;
+		}
+	}

Perhaps the (fairly revolting) circ_buf.h can be used for this stuff.

Quoted 3 lines
Quoted 1 line

It probably could, but IMHO readability would suffer rather than improve.

How about kernel/kfifo.c?

That would indeed fit the bill. But again, this code matches parts of drivers/isdn/gigaset which are already in the kernel, and changing it here would require significant corresponding changes in those other parts.

I'll gladly consider your last two propositions (list_head for cs->lastcmdbuf and kfifo for cs->inbuf) for a future revision of the entire set of drivers in drivers/isdn/gigaset, but it goes way beyond the scope of the present patch, which merely aims at adding the missing M101 hardware driver.

Thanks,
Tilman

Signature · 4 lines
Tilman Schmidt                          E-Mail: [email protected]
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)
#9 lore raw
Quoted 9 lines · On Mon, 05 Feb 2007 02:42:09 +0100 Tilman Schmidt <[email protected]> wrote:

Am 04.02.2007 02:56 schrieb Andrew Morton:

Quoted 8 lines · On Sun, 04 Feb 2007 02:32:41 +0100 Tilman Schmidt <[email protected]> wrote:
Quoted 6 lines
Quoted 5 lines

drivers/isdn/gigaset/ser-gigaset.c line 120

Quoted 4 lines
drivers/isdn/gigaset/ser-gigaset.c +3 -0
+	spin_lock_irqsave(&cs->cmdlock, flags);
+	cb = cs->cmdbuf;
+	spin_unlock_irqrestore(&cs->cmdlock, flags);

It is doubtful if the locking here does anything useful.

It assures atomicity when reading the cs->cmdbuf pointer.

Quoted 7 lines
Quoted 4 lines

I think it's bogus. If the quantity being copied here is more than 32-bits then yes, a lock is appropriate. But if it's a single word then it's unlikely that the locking does anything useful. Or there might be a bug here.

It's a pointer. Are reads and writes of pointer sized objects guaranteed to be atomic on every platform?

Yup - we make the same assumption about longs in various places.

It's a bit strange to read a pointer which can be changing at the same time. Because the local copy will no longer represent the thing which it was just copied from.

#10 lore raw
Quoted 10 lines · Andrew Morton
Quoted 2 lines · On Mon, 05 Feb 2007 02:42:09 +0100 Tilman Schmidt <[email protected]> wrote:

It's a pointer. Are reads and writes of pointer sized objects guaranteed to be atomic on every platform?

Yup - we make the same assumption about longs in various places.

It's a bit strange to read a pointer which can be changing at the same time. Because the local copy will no longer represent the thing which it was just copied from.

It's not that bad. The only possible concurrent change is from NULL to non-NULL. Fearing an inconsistent read in that event was too paranoid apparently.

Thanks for all your suggestions. I'll prepare a new patch based on them.

Signature · 4 lines
Tilman Schmidt                    E-Mail: [email protected]
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)
#4 lore raw
In reply to Tilman Schmidt
Quoted 9 lines · Tilman Schmidt

Am 03.02.2007 17:09 schrieb Greg KH:

Quoted 8 lines · Andrew Morton
Quoted 6 lines

drivers/isdn/gigaset/ser-gigaset.c line 407

Quoted 5 lines
drivers/isdn/gigaset/ser-gigaset.c +5 -0
+/* dummy to shut up framework warning */
+static void gigaset_device_release(struct device *dev)
+{
+	//FIXME anything to do? cf. platform_device_release()
+}

Ask Greg ;)

Quoted 7 lines
Quoted 4 lines

Oh come on people. Don't provide an empty function because the kernel is complaining that you don't provide a release function. Yes it will shut the kernel up but did you ever think _why_ the kernel was complaining?

Actually, I did. Just guess how that FIXME came to be.
Hint: the kernel shuts up just as well without it.

Sure, but only because I can't do a test for a function pointer that points to a function that does nothing :(

Quoted 9 lines
Quoted 2 lines

You need to free your memory here, don't just provide an empty function, that shows the driver is broken.

Call me silly and incapable of thinking, but to me it's far from clear _what_ memory I am supposed to free there. Certainly neither memory I will still be needing after platform_device_unregister() nor memory that's being taken care of elsewhere. Between the two, in my case there's nothing left, so the release function is empty. If that shows my driver is broken, please explain in what way.

The memory of the platform device itself needs to be freed here, otherwise, to do it earlier would cause race conditions and oopses. Look at how the other platform drivers do things.

thanks,

greg k-h

#5 lore raw

Am 12.02.2007 19:47 schrieb Greg KH:

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/isdn/gigaset/ser-gigaset.c line 407

Quoted 4 lines
drivers/isdn/gigaset/ser-gigaset.c +4 -0
+static void gigaset_device_release(struct device *dev)
+{
+	//FIXME anything to do? cf. platform_device_release()
+}

The memory of the platform device itself needs to be freed here, otherwise, to do it earlier would cause race conditions and oopses.

I don't do it earlier. I do it later. My platform_device structure is part of my driver's device state structure which is freed explicitly later after the call to platform_device_unregister(). Is that bad?

Quoted 1 line

Look at how the other platform drivers do things.

They do things differently from each other as well as from mine. block/floppy.c, for example, just has a call to complete() there.

Anyway, in the latest version of my driver, its platform_device release function finally does something, too: it frees dev->platform_data and pdev->resource just in case something might have materialized there. I hope that's ok.

Regards,
Tilman

Signature · 4 lines
Tilman Schmidt                          E-Mail: [email protected]
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)