speedtch speedtch2.c,1.3,1.4 speedtch2.h,1.2,1.3 usbatm2.c,1.3,1.4
Duncan Sands
duncan at infradead.org
Fri Jan 21 07:46:36 EST 2005
- Previous message: speedtch cxacru2.h, 1.1, 1.2 speedtch2.c, 1.2, 1.3 speedtch2.h, 1.1,
1.2 usbatm2.c, 1.2, 1.3
- Next message: speedtch minidrivers.h, NONE, 1.1 speedtch2.c, 1.4, 1.5 speedtch2.h,
1.3, 1.4 usbatm2.c, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/speedtch
In directory phoenix.infradead.org:/tmp/cvs-serv21149
Modified Files:
speedtch2.c speedtch2.h usbatm2.c
Log Message:
Added generic atm initialization method. Looks like I need to do some thinking about
the lifecycle model...
Index: speedtch2.c
===================================================================
RCS file: /home/cvs/speedtch/speedtch2.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- speedtch2.c 21 Jan 2005 09:50:31 -0000 1.3
+++ speedtch2.c 21 Jan 2005 12:46:31 -0000 1.4
@@ -108,6 +108,7 @@
static void speedtch_firmware_disconnect(struct usb_interface *intf);
static void speedtch_handle_int(struct urb *urb, struct pt_regs *regs);
static void speedtch_poll_status(struct speedtch_instance_data *instance);
+static void speedtch_timer_poll(unsigned long data);
struct usb_driver speedtch_firmware_driver = {
.owner = THIS_MODULE,
@@ -116,6 +117,35 @@
.disconnect = speedtch_firmware_disconnect,
};
+/**********
+** ATM **
+**********/
+
+int speedtch_atm_init(struct usbatm_data *usbatm_data, struct atm_dev *atm_dev)
+{
+ struct speedtch_instance_data *instance = usbatm_data->driver_data;
+ struct usb_device *usb_dev = usbatm_data->usb_dev;
+ int i;
+ unsigned char mac_str[13];
+
+ /* set MAC address, it is stored in the serial number */
+ memset(atm_dev->esi, 0, sizeof(atm_dev->esi));
+ if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) {
+ for (i = 0; i < 6; i++)
+ atm_dev->esi[i] =
+ (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1]));
+ }
+
+ 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_poll_status, instance);
+
+ return 0;
+}
+
+
/***************
** firmware **
***************/
@@ -441,6 +471,7 @@
int actual_length;
int ret;
int offset;
+ char buf7[SIZE_7];
dbg("speedtch_upload_firmware");
@@ -459,7 +490,17 @@
usb_driver_claim_interface(&speedtch_firmware_driver, intf, NULL)) < 0) {
dbg("speedtch_upload_firmware: interface in use (%d)!", ret);
ret = -EBUSY;
- goto fail_free;
+ goto out_free;
+ }
+
+ /* First 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, HZ / 2);
+
+ if (ret == SIZE_7) {
+ dbg("firmware appears to be already loaded");
+ ret = 0;
+ goto out_free;
}
/* URB 7 */
@@ -483,7 +524,7 @@
if (ret < 0) {
dbg("speedtch_upload_firmware: write BLOCK1 to modem failed (%d)!", ret);
- goto fail_release;
+ goto out_release;
}
dbg("speedtch_upload_firmware: BLOCK1 uploaded (%zd bytes)", fw1->size);
}
@@ -496,7 +537,7 @@
if (ret < 0) {
dbg("speedtch_upload_firmware: read BLOCK2 from modem failed (%d)!", ret);
- goto fail_release;
+ goto out_release;
}
dbg("speedtch_upload_firmware: BLOCK2 downloaded (%d bytes)", actual_length);
@@ -510,7 +551,7 @@
if (ret < 0) {
dbg("speedtch_upload_firmware: write BLOCK3 to modem failed (%d)!", ret);
- goto fail_release;
+ goto out_release;
}
}
dbg("speedtch_upload_firmware: BLOCK3 uploaded (%zd bytes)", fw2->size);
@@ -523,7 +564,7 @@
if (ret < 0) {
dbg("speedtch_upload_firmware: read BLOCK4 from modem failed (%d)!", ret);
- goto fail_release;
+ goto out_release;
}
/* success */
@@ -544,17 +585,15 @@
if (speedtch_start_synchro(instance))
dbg("speedtch_start_synchro: failed");
-//QQ speedtch_got_firmware(instance, 1);
-
free_page((unsigned long)buffer);
return 0;
- fail_release:
+ out_release:
/* Only release interface #2 if uploading failed; we don't release it if
we succeeded. This prevents the userspace tools from trying to load
the firmware themselves */
usb_driver_release_interface(&speedtch_firmware_driver, intf);
- fail_free:
+ out_free:
free_page((unsigned long)buffer);
return ret;
}
@@ -632,10 +671,7 @@
struct usb_device *dev = interface_to_usbdev(intf);
int ifnum = intf->altsetting->desc.bInterfaceNumber;
struct speedtch_instance_data *instance;
-//QQ unsigned char mac_str[13];
-//QQ int i;
int ret;
-//QQ char buf7[SIZE_7];
if (ifnum != 1)
return -ENODEV;
@@ -657,32 +693,6 @@
if ((ret = usb_set_interface(dev, 2, 0)) < 0)
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_poll_status, instance);
-
-//QQ /* set MAC address, it is stored in the serial number */
-//QQ memset(instance->u.atm_dev->esi, 0, sizeof(instance->u.atm_dev->esi));
-//QQ if (usb_string(dev, dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) {
-//QQ for (i = 0; i < 6; i++)
-//QQ instance->u.atm_dev->esi[i] =
-//QQ (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1]));
-//QQ }
-//QQ
-//QQ /* First check whether the modem already seems to be alive */
-//QQ ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
-//QQ 0x12, 0xc0, 0x07, 0x00, buf7, SIZE_7, HZ / 2);
-//QQ
-//QQ if (ret == SIZE_7) {
-//QQ dbg("firmware appears to be already loaded");
-//QQ speedtch_got_firmware(instance, 1);
-//QQ speedtch_poll_status(instance);
-//QQ } else {
-//QQ speedtch_firmware_start(instance);
-//QQ }
-
usbatm->driver_data = instance;
return 0;
@@ -693,33 +703,22 @@
return -ENOMEM;
}
-//QQstatic void speedtch_usb_disconnect(struct usb_interface *intf)
-//QQ{
-//QQ struct speedtch_instance_data *instance = usb_get_intfdata(intf);
-//QQ
-//QQ dbg("speedtch_usb_disconnect entered");
-//QQ
-//QQ if (!instance) {
-//QQ dbg("speedtch_usb_disconnect: NULL instance!");
-//QQ return;
-//QQ }
-//QQ
-//QQ if (instance->int_urb) {
-//QQ struct urb *int_urb = instance->int_urb;
-//QQ instance->int_urb = NULL;
-//QQ wmb();
-//QQ usb_unlink_urb(int_urb);
-//QQ usb_free_urb(int_urb);
-//QQ }
-//QQ
-//QQ instance->int_data[0] = 1;
-//QQ del_timer_sync(&instance->poll_timer);
-//QQ wmb();
-//QQ flush_scheduled_work();
-//QQ
-//QQ udsl_instance_disconnect(&instance->u);
-//QQ
-//QQ /* clean up */
-//QQ usb_set_intfdata(intf, NULL);
-//QQ udsl_put_instance(&instance->u);
-//QQ}
+void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
+{
+ struct speedtch_instance_data *instance = usbatm->driver_data;
+
+ dbg("speedtch_usb_unbind entered");
+
+ 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();
+}
Index: speedtch2.h
===================================================================
RCS file: /home/cvs/speedtch/speedtch2.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- speedtch2.h 21 Jan 2005 09:50:31 -0000 1.2
+++ speedtch2.h 21 Jan 2005 12:46:31 -0000 1.3
@@ -28,13 +28,16 @@
#include "usbatm.h"
int speedtch_bind(struct usbatm_data *usbatm, struct usb_interface *intf);
+void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf);
int speedtch_load_firmware(struct usbatm_data *usbatm, struct usb_interface *intf);
+int speedtch_atm_init(struct usbatm_data *usbatm_data, struct atm_dev *atm_dev);
static const struct usbatm_driver speedtch_driver = {
- .driver_name = "speedtch",
- .bind = speedtch_bind,
+ .driver_name = "speedtch",
+ .bind = speedtch_bind,
+ .unbind = speedtch_unbind,
#ifdef CONFIG_FW_LOADER
- .heavy_init = speedtch_load_firmware,
+ .heavy_init = speedtch_load_firmware,
#endif
.in = 7, .out = 7
};
Index: usbatm2.c
===================================================================
RCS file: /home/cvs/speedtch/usbatm2.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- usbatm2.c 21 Jan 2005 09:50:31 -0000 1.3
+++ usbatm2.c 21 Jan 2005 12:46:31 -0000 1.4
@@ -968,10 +968,12 @@
static int usbatm_atm_init(struct usbatm_data *instance)
{
+ struct atm_dev *atm_dev;
+ int ret;
+
/* ATM init */
- instance->atm_dev = atm_dev_register(instance->driver->driver_name,
- &udsl_atm_devops, -1, NULL);
- if (!instance->atm_dev) {
+ atm_dev = atm_dev_register(instance->driver->driver_name, &udsl_atm_devops, -1, NULL);
+ if (!atm_dev) {
dbg("usbatm_atm_init: failed to register ATM device!");
return -1;
}
@@ -983,11 +985,24 @@
/* temp init ATM device, set to 128kbit */
instance->atm_dev->link_rate = 128 * 1000 / 424;
+ instance->atm_dev = atm_dev;
+
+ if (instance->driver->atm_init && ((ret = instance->driver->atm_init(instance, atm_dev)) < 0))
+ goto fail_free;
+
+ udsl_get_instance(instance); /* one for ATM */
+
/* ready for ATM callbacks */
wmb();
instance->atm_dev->dev_data = instance;
return 0;
+
+ fail_free:
+ shutdown_atm_dev(atm_dev); //QQ is this the right thing to use?
+ kfree(atm_dev); //QQ should we be doing this?
+ instance->atm_dev = NULL; //QQ likewise
+ return ret;
}
@@ -1004,6 +1019,9 @@
ret = instance->driver->heavy_init(instance, instance->usb_intf);
+ if (!ret)
+ ret = usbatm_atm_init(instance);
+
module_put(THIS_MODULE);
udsl_put_instance(instance);
@@ -1056,7 +1074,6 @@
memset(instance, 0, sizeof(*instance));
kref_init(&instance->refcount); /* one for USB */
-//QQset later udsl_get_instance(instance); /* one for ATM */
init_MUTEX(&instance->serialize);
@@ -1202,8 +1219,9 @@
return error;
}
-static void udsl_instance_disconnect(struct usbatm_data *instance)
+static void usbatm_disconnect(struct usb_interface *intf)
{
+ struct usbatm_data *instance = usb_get_intfdata(intf);
int i;
dbg("udsl_instance_disconnect entered");
@@ -1213,6 +1231,11 @@
return;
}
+ usb_set_intfdata(intf, NULL);
+
+ if (instance->driver->unbind)
+ instance->driver->unbind(instance, intf);
+
/* receive finalize */
tasklet_disable(&instance->receive_tasklet);
@@ -1251,7 +1274,9 @@
kfree(instance->send_buffers[i].base);
/* ATM finalize */
- shutdown_atm_dev(instance->atm_dev);
+ shutdown_atm_dev(instance->atm_dev); //QQ what if never initialized?
+
+ udsl_put_instance(instance);
}
@@ -1337,7 +1362,7 @@
.owner = THIS_MODULE,
.name = driver_name,
.probe = usbatm_usb_probe,
-//QQ .disconnect = usbatm_disconnect,
+ .disconnect = usbatm_disconnect,
.id_table = products,
};
- Previous message: speedtch cxacru2.h, 1.1, 1.2 speedtch2.c, 1.2, 1.3 speedtch2.h, 1.1,
1.2 usbatm2.c, 1.2, 1.3
- Next message: speedtch minidrivers.h, NONE, 1.1 speedtch2.c, 1.4, 1.5 speedtch2.h,
1.3, 1.4 usbatm2.c, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Usbatm-commits
mailing list