speedtch speedtch.c,1.48,1.49
Duncan Sands
duncan at infradead.org
Fri Apr 15 08:09:22 EDT 2005
Update of /home/cvs/speedtch
In directory phoenix.infradead.org:/tmp/cvs-serv9142
Modified Files:
speedtch.c
Log Message:
The stack is not DMA-able on all architectures, so you can't use it for
transfer buffers. Changed some names and did some other cleanups while
I was there.
Index: speedtch.c
===================================================================
RCS file: /home/cvs/speedtch/speedtch.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- speedtch.c 15 Apr 2005 10:22:35 -0000 1.48
+++ speedtch.c 15 Apr 2005 12:09:19 -0000 1.49
@@ -97,6 +97,8 @@
unsigned char int_data[16];
struct work_struct poll_work;
struct timer_list poll_timer;
+
+ unsigned char scratch_buffer[TOTAL];
};
/***************
@@ -123,7 +125,7 @@
{
struct usbatm_data *usbatm = instance->usbatm;
struct usb_device *usb_dev = usbatm->usb_dev;
- unsigned char buf[10];
+ unsigned char *buf = instance->scratch_buffer;
int ret;
/* URB 147 */
@@ -217,125 +219,6 @@
// err("%s - usb_submit_urb failed with result %d", __func__, ret);
//}
//
-//static int speedtch_get_status(struct speedtch_instance_data *instance,
-// unsigned char *buf)
-//{
-// struct usb_device *dev = instance->u.usb_dev;
-// int ret;
-//
-// memset(buf, 0, TOTAL);
-//
-// ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
-// 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7,
-// CTRL_TIMEOUT);
-// if (ret < 0) {
-// dbg("MSG 7 failed");
-// return ret;
-// }
-//
-// ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
-// 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b,
-// CTRL_TIMEOUT);
-// if (ret < 0) {
-// dbg("MSG B failed");
-// return ret;
-// }
-//
-// ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
-// 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d,
-// CTRL_TIMEOUT);
-// if (ret < 0) {
-// dbg("MSG D failed");
-// return ret;
-// }
-//
-// ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
-// 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e,
-// CTRL_TIMEOUT);
-// if (ret < 0) {
-// dbg("MSG E failed");
-// return ret;
-// }
-//
-// ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
-// 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f,
-// CTRL_TIMEOUT);
-// if (ret < 0) {
-// dbg("MSG F failed");
-// return ret;
-// }
-//
-// return 0;
-//}
-//
-//static void speedtch_poll_status(struct speedtch_instance_data *instance)
-//{
-// unsigned char buf[TOTAL];
-// int ret;
-//
-// ret = speedtch_get_status(instance, buf);
-// if (ret) {
-// printk(KERN_WARNING
-// "SpeedTouch: Error %d fetching device status\n", ret);
-// return;
-// }
-//
-// dbg("Line state %02x", buf[OFFSET_7]);
-//
-// switch (buf[OFFSET_7]) {
-// case 0:
-// if (instance->u.atm_dev->signal != ATM_PHY_SIG_LOST) {
-// instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
-// printk(KERN_NOTICE "ADSL line is down\n");
-//+ /* It'll never resync again unless we ask it to... */
-//+ speedtch_start_synchro(instance);
-// }
-// break;
-//
-// case 0x08:
-// if (instance->u.atm_dev->signal != ATM_PHY_SIG_UNKNOWN) {
-// instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
-// printk(KERN_NOTICE "ADSL line is blocked?\n");
-// }
-// break;
-//
-// case 0x10:
-// if (instance->u.atm_dev->signal != ATM_PHY_SIG_LOST) {
-// instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
-// printk(KERN_NOTICE "ADSL line is synchronising\n");
-// }
-// break;
-//
-// case 0x20:
-// if (instance->u.atm_dev->signal != ATM_PHY_SIG_FOUND) {
-// int down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8)
-// | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24);
-// int up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8)
-// | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24);
-//
-// if (!(down_speed & 0x0000ffff) &&
-// !(up_speed & 0x0000ffff)) {
-// down_speed >>= 16;
-// up_speed >>= 16;
-// }
-// instance->u.atm_dev->link_rate = down_speed * 1000 / 424;
-// instance->u.atm_dev->signal = ATM_PHY_SIG_FOUND;
-//
-// printk(KERN_NOTICE
-// "ADSL line is up (%d Kib/s down | %d Kib/s up)\n",
-// down_speed, up_speed);
-// }
-// break;
-//
-// default:
-// if (instance->u.atm_dev->signal != ATM_PHY_SIG_UNKNOWN) {
-// instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
-// printk(KERN_NOTICE "Unknown line state %02x\n", buf[OFFSET_7]);
-// }
-// break;
-// }
-//}
-//
//static void speedtch_timer_poll(unsigned long data)
//{
// struct speedtch_instance_data *instance = (void *)data;
@@ -511,29 +394,153 @@
}
-/*********
-** ATM *
-*********/
+/**********
+** ATM **
+**********/
+
+static int speedtch_read_status(struct speedtch_instance_data *instance)
+{
+ struct usbatm_data *usbatm = instance->usbatm;
+ struct usb_device *usb_dev = usbatm->usb_dev;
+ unsigned char *buf = instance->scratch_buffer;
+ int ret;
+
+ memset(buf, 0, TOTAL);
+
+ ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
+ 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7,
+ CTRL_TIMEOUT);
+ if (ret < 0) {
+ atm_dbg(usbatm, "%s: MSG 7 failed\n", __func__);
+ return ret;
+ }
+
+ ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
+ 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b,
+ CTRL_TIMEOUT);
+ if (ret < 0) {
+ atm_dbg(usbatm, "%s: MSG B failed\n", __func__);
+ return ret;
+ }
+
+ ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
+ 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d,
+ CTRL_TIMEOUT);
+ if (ret < 0) {
+ atm_dbg(usbatm, "%s: MSG D failed\n", __func__);
+ return ret;
+ }
+
+ ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
+ 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e,
+ CTRL_TIMEOUT);
+ if (ret < 0) {
+ atm_dbg(usbatm, "%s: MSG E failed\n", __func__);
+ return ret;
+ }
+
+ ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
+ 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f,
+ CTRL_TIMEOUT);
+ if (ret < 0) {
+ atm_dbg(usbatm, "%s: MSG F failed\n", __func__);
+ return ret;
+ }
+
+ return 0;
+}
static int speedtch_start_synchro(struct speedtch_instance_data *instance)
{
struct usbatm_data *usbatm = instance->usbatm;
struct usb_device *usb_dev = usbatm->usb_dev;
- unsigned char buf[2];
+ unsigned char *buf = instance->scratch_buffer;
int ret;
+ memset(buf, 0, 2);
+
ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
0x12, 0xc0, 0x04, 0x00,
- buf, sizeof(buf), CTRL_TIMEOUT);
+ buf, 2, CTRL_TIMEOUT);
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", __func__, ret, buf[0], buf[1]);
+ atm_dbg(usbatm, "%s: modem prodded. %d Bytes returned: %02x %02x\n",
+ __func__, ret, buf[0], buf[1]);
return ret;
}
+static void speedtch_check_status(struct speedtch_instance_data *instance)
+{
+ struct usbatm_data *usbatm = instance->usbatm;
+ struct atm_dev *atm_dev = usbatm->atm_dev;
+ unsigned char *buf = instance->scratch_buffer;
+ int ret;
+
+ ret = speedtch_read_status(instance);
+ if (ret < 0) {
+ atm_warn(usbatm, "error %d fetching device status\n", ret);
+ return;
+ }
+
+ atm_dbg(usbatm, "%s: line state %02x\n", __func__, buf[OFFSET_7]);
+
+ switch (buf[OFFSET_7]) {
+ case 0:
+ if (atm_dev->signal != ATM_PHY_SIG_LOST) {
+ 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);
+ }
+ break;
+
+ case 0x08:
+ if (atm_dev->signal != ATM_PHY_SIG_UNKNOWN) {
+ atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
+ atm_info(usbatm, "ADSL line is blocked?\n");
+ }
+ break;
+
+ case 0x10:
+ if (atm_dev->signal != ATM_PHY_SIG_LOST) {
+ atm_dev->signal = ATM_PHY_SIG_LOST;
+ atm_info(usbatm, "ADSL line is synchronising\n");
+ }
+ break;
+
+ case 0x20:
+ if (atm_dev->signal != ATM_PHY_SIG_FOUND) {
+ int down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8)
+ | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24);
+ int up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8)
+ | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24);
+
+ if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) {
+ down_speed >>= 16;
+ up_speed >>= 16;
+ }
+
+ atm_dev->link_rate = down_speed * 1000 / 424;
+ atm_dev->signal = ATM_PHY_SIG_FOUND;
+
+ atm_info(usbatm,
+ "ADSL line is up (%d Kib/s down | %d Kib/s up)\n",
+ down_speed, up_speed);
+ }
+ break;
+
+ default:
+ if (atm_dev->signal != ATM_PHY_SIG_UNKNOWN) {
+ atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
+ atm_info(usbatm, "Unknown line state %02x\n", buf[OFFSET_7]);
+ }
+ break;
+ }
+}
+
static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
{
struct usb_device *usb_dev = usbatm->usb_dev;
@@ -638,7 +645,7 @@
// instance->poll_timer.function = speedtch_timer_poll;
// instance->poll_timer.data = (unsigned long)instance;
//
-// INIT_WORK(&instance->poll_work, (void *)speedtch_poll_status, 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));
@@ -655,7 +662,7 @@
// if (ret == SIZE_7) {
// dbg("firmware appears to be already loaded");
// speedtch_got_firmware(instance, 1);
-// speedtch_poll_status(instance);
+// speedtch_check_status(instance);
// } else {
// speedtch_firmware_start(instance);
// }
@@ -745,7 +752,6 @@
int ifnum = intf->altsetting->desc.bInterfaceNumber;
int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces;
int i, ret;
- char buf7[SIZE_7];
usb_dbg(usbatm, "%s entered\n", __func__);
@@ -784,7 +790,8 @@
/* check whether the modem already seems to be alive */
ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
- 0x12, 0xc0, 0x07, 0x00, buf7, SIZE_7, 500);
+ 0x12, 0xc0, 0x07, 0x00,
+ instance->scratch_buffer + OFFSET_7, SIZE_7, 500);
*need_heavy_init = (ret != SIZE_7);
More information about the Usbatm-commits
mailing list