speedtch speedtch.c,1.49,1.50

Duncan Sands duncan at infradead.org
Fri Apr 22 03:50:05 EDT 2005


Update of /home/cvs/speedtch
In directory phoenix.infradead.org:/tmp/cvs-serv24619

Modified Files:
	speedtch.c 
Log Message:
Restore line polling, with a simple throttling mechanism.  Untested.


Index: speedtch.c
===================================================================
RCS file: /home/cvs/speedtch/speedtch.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- speedtch.c	15 Apr 2005 12:09:19 -0000	1.49
+++ speedtch.c	22 Apr 2005 07:50:02 -0000	1.50
@@ -5,6 +5,8 @@
  *  Copyright (C) 2003, Duncan Sands
  *  Copyright (C) 2004, David Woodhouse
  *
+ *  Based on "modem_run.c", copyright (C) 2001, Benoit Papillault
+ *
  *  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)
@@ -43,9 +45,8 @@
 
 static const char speedtch_driver_name[] = "speedtch";
 
-/* Timeout in milliseconds */
-#define CTRL_TIMEOUT 2000
-#define DATA_TIMEOUT 2000
+#define CTRL_TIMEOUT 2000	/* milliseconds */
+#define DATA_TIMEOUT 2000	/* milliseconds */
 
 #define OFFSET_7	0		/* size 1 */
 #define OFFSET_b	1		/* size 8 */
@@ -60,6 +61,9 @@
 #define SIZE_e		1
 #define SIZE_f		1
 
+#define SPEEDTCH_MIN_POLL_DELAY		5000	/* milliseconds */
+#define SPEEDTCH_MAX_POLL_DELAY		60000	/* milliseconds */
+
 #define SPEEDTCH_DEFAULT_ALTSETTING	1
 #define SPEEDTCH_DEFAULT_DL_512_FIRST	0
 #define SPEEDTCH_DEFAULT_SW_BUFFERING	0
@@ -92,11 +96,13 @@
 struct speedtch_instance_data {
 	struct usbatm_data *usbatm;
 
-	/* Status */
+	struct work_struct check_status;
+	struct timer_list poll_timer;
+
+	int poll_delay; /* milliseconds */
+
 	struct urb *int_urb;
 	unsigned char int_data[16];
-	struct work_struct poll_work;
-	struct timer_list poll_timer;
 
 	unsigned char scratch_buffer[TOTAL];
 };
@@ -112,7 +118,7 @@
 	int ret;
 
 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
-			      0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, 100);
+			      0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, CTRL_TIMEOUT);
 	if (ret < 0)
 		usb_warn(usbatm,
 			 "%sabling SW buffering: usb_control_msg returned %d\n",
@@ -132,7 +138,7 @@
 	buf[0] = 0x1c;
 	buf[1] = 0x50;
 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
-			      0x01, 0x40, 0x0b, 0x00, buf, 2, 100);
+			      0x01, 0x40, 0x0b, 0x00, buf, 2, CTRL_TIMEOUT);
 	if (ret < 0)
 		usb_warn(usbatm, "%s failed on URB147: %d\n", __func__, ret);
 
@@ -140,7 +146,7 @@
 	buf[0] = 0x32;
 	buf[1] = 0x00;
 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
-			      0x01, 0x40, 0x02, 0x00, buf, 2, 100);
+			      0x01, 0x40, 0x02, 0x00, buf, 2, CTRL_TIMEOUT);
 	if (ret < 0)
 		usb_warn(usbatm, "%s failed on URB148: %d\n", __func__, ret);
 
@@ -149,7 +155,7 @@
 	buf[1] = 0x00;
 	buf[2] = 0x01;
 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
-			      0x01, 0x40, 0x03, 0x00, buf, 3, 100);
+			      0x01, 0x40, 0x03, 0x00, buf, 3, CTRL_TIMEOUT);
 	if (ret < 0)
 		usb_warn(usbatm, "%s failed on URB149: %d\n", __func__, ret);
 
@@ -158,7 +164,7 @@
 	buf[1] = 0x00;
 	buf[2] = 0x01;
 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
-			      0x01, 0x40, 0x04, 0x00, buf, 3, 100);
+			      0x01, 0x40, 0x04, 0x00, buf, 3, CTRL_TIMEOUT);
 	if (ret < 0)
 		usb_warn(usbatm, "%s failed on URB150: %d\n", __func__, ret);
 }
@@ -207,7 +213,7 @@
 //			printk(" %02x", instance->int_data[i]);
 //		printk("\n");
 //	}
-//	schedule_work(&instance->poll_work);
+//	schedule_work(&instance->check_status);
 //
 // exit:
 //	rmb();
@@ -219,13 +225,6 @@
 //		err("%s - usb_submit_urb failed with result %d", __func__, ret);
 //}
 //
-//static void speedtch_timer_poll(unsigned long data)
-//{
-//	struct speedtch_instance_data *instance = (void *)data;
-//
-//	schedule_work(&instance->poll_work);
-//	mod_timer(&instance->poll_timer, jiffies + (5 * HZ));
-//}
 
 static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
 				     const struct firmware *fw1,
@@ -457,6 +456,8 @@
 	unsigned char *buf = instance->scratch_buffer;
 	int ret;
 
+	atm_dbg(usbatm, "%s entered\n", __func__);
+
 	memset(buf, 0, 2);
 
 	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
@@ -466,7 +467,7 @@
 	if (ret < 0)
 		atm_warn(usbatm, "failed to start ADSL synchronisation: %d\n", ret);
 	else
-		atm_dbg(usbatm, "%s: modem prodded. %d Bytes returned: %02x %02x\n",
+		atm_dbg(usbatm, "%s: modem prodded. %d bytes returned: %02x %02x\n",
 			__func__, ret, buf[0], buf[1]);
 
 	return ret;
@@ -479,9 +480,13 @@
 	unsigned char *buf = instance->scratch_buffer;
 	int ret;
 
+	atm_dbg(usbatm, "%s entered\n", __func__);
+
 	ret = speedtch_read_status(instance);
 	if (ret < 0) {
 		atm_warn(usbatm, "error %d fetching device status\n", ret);
+		if (instance->poll_delay < SPEEDTCH_MAX_POLL_DELAY)
+			instance->poll_delay *= 2;
 		return;
 	}
 
@@ -493,7 +498,7 @@
 			atm_dev->signal = ATM_PHY_SIG_LOST;
 			atm_info(usbatm, "ADSL line is down\n");
 			/* It'll never resync again unless we ask it to... */
-			speedtch_start_synchro(instance);
+			ret = speedtch_start_synchro(instance);
 		}
 		break;
 
@@ -541,6 +546,17 @@
 	}
 }
 
+static void speedtch_status_poll(unsigned long data)
+{
+	struct speedtch_instance_data *instance = (void *)data;
+
+	schedule_work(&instance->check_status);
+
+	/* The following check is racy, but the race is harmless */
+	if (instance->poll_delay < SPEEDTCH_MAX_POLL_DELAY)
+		mod_timer(&instance->poll_timer, jiffies + msecs_to_jiffies(instance->poll_delay));
+}
+
 static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
 {
 	struct usb_device *usb_dev = usbatm->usb_dev;
@@ -584,129 +600,26 @@
 //			}
 //		}
 //	}
-//	/* Start status polling */
-//	mod_timer(&instance->poll_timer, jiffies + (1 * HZ));
 
 	/* Start modem synchronisation */
 	ret = speedtch_start_synchro(instance);
 
+	/* Start status polling */
+	mod_timer(&instance->poll_timer, jiffies + (1 * HZ));
+
 	return ret;
 }
 
+static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
+{
+	struct speedtch_instance_data *instance = usbatm->driver_data;
 
-///**********
-//**  USB  **
-//**********/
-//
-//static int speedtch_usb_probe(struct usb_interface *intf,
-//			      const struct usb_device_id *id)
-//{
-//	struct usb_device *dev = interface_to_usbdev(intf);
-//	int ifnum = intf->altsetting->desc.bInterfaceNumber;
-//	struct speedtch_instance_data *instance;
-//	unsigned char mac_str[13];
-//	int ret, i;
-//	char buf7[SIZE_7];
-//
-//	dbg("speedtch_bind: trying device with vendor=0x%x, product=0x%x, ifnum %d",
-//	    le16_to_cpu(dev->descriptor.idVendor),
-//	    le16_to_cpu(dev->descriptor.idProduct), ifnum);
-//
-//	if ((dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) || 
-//	    (ifnum != 1))
-//		return -ENODEV;
-//
-//	dbg("speedtch_bind: device accepted");
-//
-//	/* instance init */
-//	instance = kmalloc(sizeof(*instance), GFP_KERNEL);
-//	if (!instance) {
-//		dbg("speedtch_bind: no memory for instance data!");
-//		return -ENOMEM;
-//	}
-//
-//	memset(instance, 0, sizeof(struct speedtch_instance_data));
-//
-//	if ((ret = usb_set_interface(dev, 0, 0)) < 0)
-//		goto fail;
-//
-//	if ((ret = usb_set_interface(dev, 2, 0)) < 0)
-//		goto fail;
-//
-//	instance->u.data_endpoint = SPEEDTCH_ENDPOINT_DATA;
-//	instance->u.firmware_wait = speedtch_firmware_wait;
-//	instance->u.driver_name = speedtch_driver_name;
-//
-//	ret = udsl_instance_setup(dev, &instance->u);
-//	if (ret)
-//		goto fail;
-//
-//	init_timer(&instance->poll_timer);
-//	instance->poll_timer.function = speedtch_timer_poll;
-//	instance->poll_timer.data = (unsigned long)instance;
-//
-//	INIT_WORK(&instance->poll_work, (void *)speedtch_check_status, instance);
-//
-//	/* set MAC address, it is stored in the serial number */
-//	memset(instance->u.atm_dev->esi, 0, sizeof(instance->u.atm_dev->esi));
-//	if (usb_string(dev, dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) {
-//		for (i = 0; i < 6; i++)
-//			instance->u.atm_dev->esi[i] =
-//				(hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1]));
-//	}
-//
-//	/* First check whether the modem already seems to be alive */
-//	ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
-//			      0x12, 0xc0, 0x07, 0x00, buf7, SIZE_7, 500);
-//
-//	if (ret == SIZE_7) {
-//		dbg("firmware appears to be already loaded");
-//		speedtch_got_firmware(instance, 1);
-//		speedtch_check_status(instance);
-//	} else {
-//		speedtch_firmware_start(instance);
-//	}
-//
-//	usb_set_intfdata(intf, instance);
-//
-//	return 0;
-//
-// fail:
-//	kfree(instance);
-//
-//	return -ENOMEM;
-//}
-//
-//static void speedtch_usb_disconnect(struct usb_interface *intf)
-//{
-//	struct speedtch_instance_data *instance = usb_get_intfdata(intf);
-//
-//	dbg("speedtch_usb_disconnect entered");
-//
-//	if (!instance) {
-//		dbg("speedtch_usb_disconnect: NULL instance!");
-//		return;
-//	}
-//
-//	if (instance->int_urb) {
-//		struct urb *int_urb = instance->int_urb;
-//		instance->int_urb = NULL;
-//		wmb();
-//		usb_unlink_urb(int_urb);
-//		usb_free_urb(int_urb);
-//	}
-//
-//	instance->int_data[0] = 1;
-//	del_timer_sync(&instance->poll_timer);
-//	wmb();
-//	flush_scheduled_work();
-//
-//	udsl_instance_disconnect(&instance->u);
-//
-//	/* clean up */
-//	usb_set_intfdata(intf, NULL);
-//	udsl_put_instance(&instance->u);
-//}
+	atm_dbg(usbatm, "%s entered\n", __func__);
+
+	del_timer_sync(&instance->poll_timer);
+	wmb();
+	flush_scheduled_work();
+}
 
 
 /**********
@@ -788,6 +701,12 @@
 
 	instance->usbatm = usbatm;
 
+	INIT_WORK(&instance->check_status, (void *)speedtch_check_status, instance);
+	init_timer(&instance->poll_timer);
+	instance->poll_timer.function = speedtch_status_poll;
+	instance->poll_timer.data = (unsigned long)instance;
+	instance->poll_delay = SPEEDTCH_MIN_POLL_DELAY;
+
 	/* check whether the modem already seems to be alive */
 	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
 			      0x12, 0xc0, 0x07, 0x00,
@@ -835,7 +754,7 @@
 	.heavy_init	= speedtch_heavy_init,
 	.unbind		= speedtch_unbind,
 	.atm_start	= speedtch_atm_start,
-//QQ	.atm_stop	= speedtch_atm_stop,
+	.atm_stop	= speedtch_atm_stop,
 	.in		= SPEEDTCH_ENDPOINT_DATA,
 	.out		= SPEEDTCH_ENDPOINT_DATA
 };




More information about the Usbatm-commits mailing list