#include <linux/slab.h>
#include <linux/module.h>
#include <linux/init.h>
-#undef DEBUG /* include debug macros until it's done */
+#include <linux/wait.h>
#include <linux/usb.h>
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Forwards */
-static void auerswald_ctrlread_complete (struct urb * urb, struct pt_regs *regs);
+static void auerswald_ctrlread_complete (struct urb * urb);
static void auerswald_removeservice (pauerswald_t cp, pauerscon_t scp);
static struct usb_driver auerswald_driver;
/* -------------------------- */
/* completion function for chained urbs */
-static void auerchain_complete (struct urb * urb, struct pt_regs *regs)
+static void auerchain_complete (struct urb * urb)
{
unsigned long flags;
int result;
NOTE: this function may lead to more urbs submitted into the chain.
(no chain lock at calling complete()!)
acp->active != NULL is protecting us against recursion.*/
- urb->complete (urb, regs);
+ urb->complete (urb);
/* detach element from chain data structure */
spin_lock_irqsave (&acp->lock, flags);
urb->status = result;
dbg("auerchain_complete: usb_submit_urb with error code %d", result);
/* and do error handling via *this* completion function (recursive) */
- auerchain_complete( urb, NULL);
+ auerchain_complete( urb);
}
} else {
/* simple return without submitting a new urb.
urb->status = result;
dbg("auerchain_submit_urb: usb_submit_urb with error code %d", result);
/* and do error handling via completion function */
- auerchain_complete( urb, NULL);
+ auerchain_complete( urb);
}
}
/* cancel an urb which is submitted to the chain
the result is 0 if the urb is cancelled, or -EINPROGRESS if
- URB_ASYNC_UNLINK is set and the function is successfully started.
+ the function is successfully started.
*/
static int auerchain_unlink_urb (pauerchain_t acp, struct urb * urb)
{
spin_unlock_irqrestore (&acp->lock, flags);
dbg ("unlink waiting urb");
urb->status = -ENOENT;
- urb->complete (urb, NULL);
+ urb->complete (urb);
return 0;
}
}
spin_unlock_irqrestore (&acp->lock, flags);
dbg ("unlink waiting urb");
urbp->status = -ENOENT;
- urbp->complete (urbp, NULL);
+ urbp->complete (urbp);
spin_lock_irqsave (&acp->lock, flags);
}
spin_unlock_irqrestore (&acp->lock, flags);
acep = acp->active;
if (acep) {
urbp = acep->urbp;
- urbp->transfer_flags &= ~URB_ASYNC_UNLINK;
dbg ("unlink active urb");
usb_kill_urb (urbp);
}
/* fill the list of free elements */
for (;numElements; numElements--) {
- acep = (pauerchainelement_t) kmalloc (sizeof (auerchainelement_t), GFP_KERNEL);
+ acep = kzalloc(sizeof(auerchainelement_t), GFP_KERNEL);
if (!acep)
goto ac_fail;
- memset (acep, 0, sizeof (auerchainelement_t));
INIT_LIST_HEAD (&acep->list);
list_add_tail (&acep->list, &acp->free_list);
}
/* completion handler for synchronous chained URBs */
-static void auerchain_blocking_completion (struct urb *urb, struct pt_regs *regs)
+static void auerchain_blocking_completion (struct urb *urb)
{
pauerchain_chs_t pchs = (pauerchain_chs_t)urb->context;
pchs->done = 1;
/* Starts chained urb and waits for completion or timeout */
static int auerchain_start_wait_urb (pauerchain_t acp, struct urb *urb, int timeout, int* actual_length)
{
- DECLARE_WAITQUEUE (wait, current);
auerchain_chs_t chs;
int status;
init_waitqueue_head (&chs.wqh);
chs.done = 0;
- set_current_state (TASK_UNINTERRUPTIBLE);
- add_wait_queue (&chs.wqh, &wait);
urb->context = &chs;
status = auerchain_submit_urb (acp, urb);
- if (status) {
+ if (status)
/* something went wrong */
- set_current_state (TASK_RUNNING);
- remove_wait_queue (&chs.wqh, &wait);
return status;
- }
-
- while (timeout && !chs.done)
- {
- timeout = schedule_timeout (timeout);
- set_current_state(TASK_UNINTERRUPTIBLE);
- rmb();
- }
- set_current_state (TASK_RUNNING);
- remove_wait_queue (&chs.wqh, &wait);
+ timeout = wait_event_timeout(chs.wqh, chs.done, timeout);
if (!timeout && !chs.done) {
if (urb->status != -EINPROGRESS) { /* No callback?!! */
/* free a single auerbuf */
static void auerbuf_free (pauerbuf_t bp)
{
- if (bp->bufp) {
- kfree (bp->bufp);
- }
- if (bp->dr) {
- kfree (bp->dr);
- }
- if (bp->urbp) {
- usb_free_urb (bp->urbp);
- }
- kfree (bp);
+ kfree(bp->bufp);
+ kfree(bp->dr);
+ usb_free_urb(bp->urbp);
+ kfree(bp);
}
/* free the buffers from an auerbuf list */
/* fill the list of free elements */
for (;numElements; numElements--) {
- bep = (pauerbuf_t) kmalloc (sizeof (auerbuf_t), GFP_KERNEL);
+ bep = kzalloc(sizeof(auerbuf_t), GFP_KERNEL);
if (!bep)
goto bl_fail;
- memset (bep, 0, sizeof (auerbuf_t));
bep->list = bcp;
INIT_LIST_HEAD (&bep->buff_list);
- bep->bufp = (char *) kmalloc (bufsize, GFP_KERNEL);
+ bep->bufp = kmalloc (bufsize, GFP_KERNEL);
if (!bep->bufp)
goto bl_fail;
- bep->dr = (struct usb_ctrlrequest *) kmalloc (sizeof (struct usb_ctrlrequest), GFP_KERNEL);
+ bep->dr = kmalloc(sizeof (struct usb_ctrlrequest), GFP_KERNEL);
if (!bep->dr)
goto bl_fail;
bep->urbp = usb_alloc_urb (0, GFP_KERNEL);
bl_fail:/* not enough memory. Free allocated elements */
dbg ("auerbuf_setup: no more memory");
- kfree(bep);
+ auerbuf_free(bep);
auerbuf_free_buffers (bcp);
return -ENOMEM;
}
0 Initial, OK
-EINPROGRESS during submission until end
-ENOENT if urb is unlinked
--ETIMEDOUT Transfer timed out, NAK
+-ETIME Device did not respond
-ENOMEM Memory Overflow
-ENODEV Specified USB-device or bus doesn't exist
-ENXIO URB already queued
{
switch (status) {
case 0:
- case -ETIMEDOUT:
+ case -ETIME:
case -EOVERFLOW:
case -EAGAIN:
case -EPIPE:
}
/* Completion of asynchronous write block */
-static void auerchar_ctrlwrite_complete (struct urb * urb, struct pt_regs *regs)
+static void auerchar_ctrlwrite_complete (struct urb * urb)
{
pauerbuf_t bp = (pauerbuf_t) urb->context;
pauerswald_t cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl)));
}
/* Completion handler for dummy retry packet */
-static void auerswald_ctrlread_wretcomplete (struct urb * urb, struct pt_regs *regs)
+static void auerswald_ctrlread_wretcomplete (struct urb * urb)
{
pauerbuf_t bp = (pauerbuf_t) urb->context;
pauerswald_t cp;
if (ret) {
dbg ("auerswald_ctrlread_complete: nonzero result of auerchain_submit_urb_list %d", ret);
bp->urbp->status = ret;
- auerswald_ctrlread_complete (bp->urbp, NULL);
+ auerswald_ctrlread_complete (bp->urbp);
}
}
/* completion handler for receiving of control messages */
-static void auerswald_ctrlread_complete (struct urb * urb, struct pt_regs *regs)
+static void auerswald_ctrlread_complete (struct urb * urb)
{
unsigned int serviceid;
pauerswald_t cp;
if (ret) {
dbg ("auerswald_ctrlread_complete: nonzero result of auerchain_submit_urb_list %d", ret);
bp->urbp->status = ret;
- auerswald_ctrlread_wretcomplete (bp->urbp, regs);
+ auerswald_ctrlread_wretcomplete (bp->urbp);
}
return;
}
messages from the USB device.
*/
/* int completion handler. */
-static void auerswald_int_complete (struct urb * urb, struct pt_regs *regs)
+static void auerswald_int_complete (struct urb * urb)
{
unsigned long flags;
unsigned int channelid;
if (ret) {
dbg ("auerswald_int_complete: nonzero result of auerchain_submit_urb %d", ret);
bp->urbp->status = ret;
- auerswald_ctrlread_complete( bp->urbp, NULL);
+ auerswald_ctrlread_complete( bp->urbp);
/* here applies the same problem as above: device locking! */
}
exit:
*/
static void auerswald_int_free (pauerswald_t cp)
{
- if (cp->inturbp) {
- usb_free_urb (cp->inturbp);
- cp->inturbp = NULL;
- }
- if (cp->intbufp) {
- kfree (cp->intbufp);
- cp->intbufp = NULL;
- }
+ if (cp->inturbp) {
+ usb_free_urb(cp->inturbp);
+ cp->inturbp = NULL;
+ }
+ kfree(cp->intbufp);
+ cp->intbufp = NULL;
}
/* This function is called to activate the interrupt
static int auerswald_int_open (pauerswald_t cp)
{
int ret;
- struct usb_endpoint_descriptor *ep;
+ struct usb_host_endpoint *ep;
int irqsize;
dbg ("auerswald_int_open");
- ep = usb_epnum_to_ep_desc (cp->usbdev, USB_DIR_IN | AU_IRQENDP);
+ ep = cp->usbdev->ep_in[AU_IRQENDP];
if (!ep) {
ret = -EFAULT;
goto intoend;
}
- irqsize = ep->wMaxPacketSize;
+ irqsize = le16_to_cpu(ep->desc.wMaxPacketSize);
cp->irqsize = irqsize;
/* allocate the urb and data buffer */
}
}
if (!cp->intbufp) {
- cp->intbufp = (char *) kmalloc (irqsize, GFP_KERNEL);
+ cp->intbufp = kmalloc (irqsize, GFP_KERNEL);
if (!cp->intbufp) {
ret = -ENOMEM;
goto intoend;
}
}
/* setup urb */
- usb_fill_int_urb (cp->inturbp, cp->usbdev, usb_rcvintpipe (cp->usbdev,AU_IRQENDP), cp->intbufp, irqsize, auerswald_int_complete, cp, ep->bInterval);
+ usb_fill_int_urb (cp->inturbp, cp->usbdev,
+ usb_rcvintpipe (cp->usbdev,AU_IRQENDP), cp->intbufp,
+ irqsize, auerswald_int_complete, cp, ep->desc.bInterval);
/* start the urb */
cp->inturbp->status = 0; /* needed! */
ret = usb_submit_urb (cp->inturbp, GFP_KERNEL);
dbg ("auerswald_int_release");
/* stop the int endpoint */
- if (cp->inturbp)
- usb_kill_urb (cp->inturbp);
+ usb_kill_urb (cp->inturbp);
/* deallocate memory */
auerswald_int_free (cp);
}
/* we have access to the device. Now lets allocate memory */
- ccp = (pauerchar_t) kmalloc(sizeof(auerchar_t), GFP_KERNEL);
+ ccp = kzalloc(sizeof(auerchar_t), GFP_KERNEL);
if (ccp == NULL) {
err ("out of memory");
ret = -ENOMEM;
}
/* Initialize device descriptor */
- memset( ccp, 0, sizeof(auerchar_t));
init_MUTEX( &ccp->mutex);
init_MUTEX( &ccp->readmutex);
auerbuf_init (&ccp->bufctl);
int ret;
wait_queue_t wait;
- dbg ("auerchar_write %d bytes", len);
+ dbg ("auerchar_write %zd bytes", len);
/* Error checking */
if (!ccp)
/*----------------------------------------------------------------------*/
/* File operation structure */
-static struct file_operations auerswald_fops =
+static const struct file_operations auerswald_fops =
{
.owner = THIS_MODULE,
.llseek = no_llseek,
};
static struct usb_class_driver auerswald_class = {
- .name = "usb/auer%d",
+ .name = "auer%d",
.fops = &auerswald_fops,
- .mode = S_IFCHR | S_IRUGO | S_IWUGO,
.minor_base = AUER_MINOR_BASE,
};
int ret;
dbg ("probe: vendor id 0x%x, device id 0x%x",
- usbdev->descriptor.idVendor, usbdev->descriptor.idProduct);
-
- /* See if the device offered us matches that we can accept */
- if (usbdev->descriptor.idVendor != ID_AUERSWALD)
- return -ENODEV;
+ le16_to_cpu(usbdev->descriptor.idVendor),
+ le16_to_cpu(usbdev->descriptor.idProduct));
/* we use only the first -and only- interface */
if (intf->altsetting->desc.bInterfaceNumber != 0)
return -ENODEV;
/* allocate memory for our device and initialize it */
- cp = kmalloc (sizeof(auerswald_t), GFP_KERNEL);
+ cp = kzalloc (sizeof(auerswald_t), GFP_KERNEL);
if (cp == NULL) {
err ("out of memory");
goto pfail;
}
/* Initialize device descriptor */
- memset (cp, 0, sizeof(auerswald_t));
init_MUTEX (&cp->mutex);
cp->usbdev = usbdev;
auerchain_init (&cp->controlchain);
cp->dtindex = intf->minor;
/* Get the usb version of the device */
- cp->version = cp->usbdev->descriptor.bcdDevice;
+ cp->version = le16_to_cpu(cp->usbdev->descriptor.bcdDevice);
dbg ("Version is %X", cp->version);
/* allow some time to settle the device */
info("device is a %s", cp->dev_desc);
/* get the maximum allowed control transfer length */
- pbuf = (__le16 *) kmalloc (2, GFP_KERNEL); /* use an allocated buffer because of urb target */
+ pbuf = kmalloc(2, GFP_KERNEL); /* use an allocated buffer because of urb target */
if (!pbuf) {
err( "out of memory");
goto pfail;
AUDI_MBCTRANS, /* USB message index value */
pbuf, /* pointer to the receive buffer */
2, /* length of the buffer */
- HZ * 2); /* time to wait for the message to complete before timing out */
+ 2000); /* time to wait for the message to complete before timing out */
if (ret == 2) {
cp->maxControlLength = le16_to_cpup(pbuf);
kfree(pbuf);
static struct usb_device_id auerswald_ids [] = {
{ USB_DEVICE (ID_AUERSWALD, 0x00C0) }, /* COMpact 2104 USB */
{ USB_DEVICE (ID_AUERSWALD, 0x00DB) }, /* COMpact 4410/2206 USB */
+ { USB_DEVICE (ID_AUERSWALD, 0x00DC) }, /* COMpact 4406 DSL */
+ { USB_DEVICE (ID_AUERSWALD, 0x00DD) }, /* COMpact 2204 USB */
{ USB_DEVICE (ID_AUERSWALD, 0x00F1) }, /* Comfort 2000 System Telephone */
{ USB_DEVICE (ID_AUERSWALD, 0x00F2) }, /* Comfort 1200 System Telephone */
{ } /* Terminating entry */
/* Standard usb driver struct */
static struct usb_driver auerswald_driver = {
- .owner = THIS_MODULE,
.name = "auerswald",
.probe = auerswald_probe,
.disconnect = auerswald_disconnect,