X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/fdf877c54ec2598864f6193e8e1fbaedb5c05efb..a25d89aa7ffd590bb0d1e4dbaf6c79f579f26b21:/lincan/src/usbcan.c diff --git a/lincan/src/usbcan.c b/lincan/src/usbcan.c index 19b1dc6..54f3dcb 100644 --- a/lincan/src/usbcan.c +++ b/lincan/src/usbcan.c @@ -14,7 +14,10 @@ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)) #include #endif -#include +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)) + #include +#endif +#include static int usbcan_probe(struct usb_interface *interface, const struct usb_device_id *id); static void usbcan_disconnect(struct usb_interface *interface); @@ -751,7 +754,6 @@ void usbcan_kthread_read_handler(struct usbcan_usb *dev, struct usbcan_message * canque_filter_msg2edges(obj->qends, &obj->rx_msg); skip_msg: - set_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags); DEBUGMSG("Renewing RX urb\n"); usbcan_usb_message_move_list(dev, m, &dev->rx_pend_list); @@ -795,13 +797,12 @@ void usbcan_kthread_write_handler(struct usbcan_usb *dev, struct usbcan_message canque_free_outslot(obj->qends, m->qedge, m->slot); m->slot=NULL; } - + /*FIXME - why there*/ can_msgobj_clear_fl(obj,TX_PENDING); skip_msg: set_bit(USBCAN_FREE_TX_URB,&dev->flags); - set_bit(USBCAN_MESSAGE_FREE,&m->flags); set_bit(USBCAN_TX_PENDING,&dev->flags); @@ -828,7 +829,7 @@ void usbcan_kthread_write_request_handler(struct usbcan_usb *dev, struct msgobj_ clear_bit(USBCAN_FREE_TX_URB,&dev->flags); return; } - + m = list_first_entry(&dev->tx_idle_list, typeof(*m), list_node); cmd=canque_test_outslot(obj->qends, &m->qedge, &m->slot); @@ -837,7 +838,6 @@ void usbcan_kthread_write_request_handler(struct usbcan_usb *dev, struct msgobj_ can_msgobj_set_fl(obj,TX_PENDING); clear_bit(USBCAN_FREE_TX_URB,&dev->flags); - clear_bit(USBCAN_MESSAGE_FREE,&m->flags); *(u8 *)(m->msg)=0; len = m->slot->msg.length; @@ -854,16 +854,13 @@ void usbcan_kthread_write_request_handler(struct usbcan_usb *dev, struct msgobj_ *ptr=0; } - set_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags); usbcan_usb_message_move_list(dev, m, &dev->tx_pend_list); retval = usb_submit_urb (m->u, GFP_KERNEL); if (retval){ CANMSG("%d. URB error %d\n",i,retval); - clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags); set_bit(USBCAN_FREE_TX_URB,&dev->flags); - set_bit(USBCAN_MESSAGE_FREE,&m->flags); obj->ret = -1; canque_notify_inends(m->qedge, CANQUEUE_NOTIFY_ERRTX_SEND); canque_free_outslot(obj->qends, m->qedge, m->slot); @@ -1017,7 +1014,7 @@ int usbcan_init_chip_data(struct candevice_t *candev, int chipnr) usbcan_fill_chipspecops(chip); - candev->chip[chipnr]->flags|=CHIP_IRQ_CUSTOM; + candev->chip[chipnr]->flags|=CHIP_IRQ_CUSTOM|CHIP_KEEP_DATA; candev->chip[chipnr]->chip_base_addr=0; candev->chip[chipnr]->clock = 0; @@ -1073,7 +1070,6 @@ static void usbcan_tx_callback(struct urb *urb) set_bit(USBCAN_MESSAGE_DATA_OK,&m->flags); DEBUGMSG("%s > TX flag set\n", __FUNCTION__); set_bit(USBCAN_DATA_TX,&m->dev->flags); - clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags); usbcan_usb_message_move_list(m->dev, m, &m->dev->tx_ready_list); if (test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags)) wake_up_process(m->dev->comthread); @@ -1087,7 +1083,6 @@ static void usbcan_tx_callback(struct urb *urb) CANMSG("%s > Urb shutting down with status: %d\n", __FUNCTION__, urb->status); // set_bit(USBCAN_TERMINATE,&m->dev->flags); set_bit(USBCAN_MESSAGE_TERMINATE,&m->flags); - clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags); return; default: //CANMSG("%s > Nonzero status received: %d\n", __FUNCTION__, urb->status); @@ -1099,7 +1094,6 @@ static void usbcan_tx_callback(struct urb *urb) if (retval<0){ CANMSG("%s > Retrying urb failed with result %d\n", __FUNCTION__, retval); set_bit(USBCAN_ERROR,&m->dev->flags); - clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags); usbcan_usb_message_move_list(m->dev, m, &m->dev->tx_ready_list); if (test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags)) wake_up_process(m->dev->comthread); @@ -1111,7 +1105,7 @@ static void usbcan_rx_callback(struct urb *urb) struct usbcan_message *m = urb->context; int retval; - if (!test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags)) + if (!test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags)) return; if (test_bit(USBCAN_MESSAGE_TERMINATE,&m->flags)) return; @@ -1124,7 +1118,6 @@ static void usbcan_rx_callback(struct urb *urb) set_bit(USBCAN_MESSAGE_DATA_OK,&m->flags); DEBUGMSG("%s > RX flag set\n", __FUNCTION__); set_bit(USBCAN_DATA_RX,&m->dev->flags); - clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags); usbcan_usb_message_move_list(m->dev, m, &m->dev->rx_ready_list); if (test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags)) wake_up_process(m->dev->comthread); @@ -1138,7 +1131,6 @@ static void usbcan_rx_callback(struct urb *urb) CANMSG("%s > Urb shutting down with status: %d\n", __FUNCTION__, urb->status); // set_bit(USBCAN_TERMINATE,&m->dev->flags); set_bit(USBCAN_MESSAGE_TERMINATE,&m->flags); - clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags); return; default: //CANMSG("%s > Nonzero status received: %d\n", __FUNCTION__, urb->status); @@ -1150,7 +1142,6 @@ static void usbcan_rx_callback(struct urb *urb) if (retval<0){ CANMSG("%s > Retrying urb failed with result %d\n", __FUNCTION__, retval); set_bit(USBCAN_ERROR,&m->dev->flags); - clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags); usbcan_usb_message_move_list(m->dev, m, &m->dev->rx_ready_list); if (test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags)) wake_up_process(m->dev->comthread); @@ -1234,7 +1225,7 @@ int usbcan_kthread(void *data) CANMSG("Error allocating %d. usb receive urb\n",i); goto error; } - m = kmalloc(sizeof(struct usbcan_message), GFP_KERNEL); + m = kzalloc(sizeof(struct usbcan_message), GFP_KERNEL); if(!m) { usb_free_urb(u); CANMSG("Error allocating %d. receive usbcan_message\n",i); @@ -1246,7 +1237,7 @@ int usbcan_kthread(void *data) usb_fill_bulk_urb(u, dev->udev, usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), m->msg, USBCAN_TRANSFER_SIZE, usbcan_rx_callback, m); - set_bit(USBCAN_MESSAGE_TYPE_RX, &m->flags); + list_add_tail(&m->list_node, &dev->rx_ready_list); } @@ -1258,7 +1249,7 @@ int usbcan_kthread(void *data) CANMSG("Error allocating %d. usb transmit urb\n",i); goto error; } - m = kmalloc(sizeof(struct usbcan_message), GFP_KERNEL); + m = kzalloc(sizeof(struct usbcan_message), GFP_KERNEL); if(!m) { usb_free_urb(u); CANMSG("Error allocating %d. transmit usbcan_message\n",i); @@ -1270,9 +1261,7 @@ int usbcan_kthread(void *data) usb_fill_bulk_urb(u, dev->udev, usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), m->msg, USBCAN_TRANSFER_SIZE, usbcan_tx_callback, m); - - set_bit(USBCAN_MESSAGE_FREE,&m->flags); - set_bit(USBCAN_MESSAGE_TYPE_TX,&m->flags); + list_add_tail(&m->list_node, &dev->tx_idle_list); } @@ -1283,7 +1272,6 @@ int usbcan_kthread(void *data) for (i=0;irx_ready_list, typeof(*m), list_node); - set_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags); usbcan_usb_message_move_list(dev, m, &dev->rx_pend_list); retval=usb_submit_urb(m->u, GFP_KERNEL); @@ -1443,7 +1431,7 @@ static int usbcan_probe(struct usb_interface *interface, const struct usb_device } usb_get_dev(usbdevs->udev); - + /* save our data pointer in this interface device */ usb_set_intfdata(interface, usbdevs); @@ -1489,10 +1477,10 @@ void release_device(struct candevice_t *candev){ #endif struct usbcan_devs *usbdevs = (struct usbcan_devs *)candev->sysdevptr.anydev; int j; - + if (!usbdevs) return; - + cleanup_hotplug_dev(usbdevs->candev); if (usbdevs->devs){ @@ -1523,12 +1511,16 @@ static void usbcan_disconnect(struct usb_interface *interface) int j; /* prevent more I/O from starting */ +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)) lock_kernel(); +#endif usbdevs = usb_get_intfdata(interface); if (usbdevs==NULL){ CANMSG("USBCAN device seems to be already removed\n"); +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)) unlock_kernel(); +#endif return; } usb_set_intfdata(interface, NULL); @@ -1541,8 +1533,10 @@ static void usbcan_disconnect(struct usb_interface *interface) mutex_unlock(&usbdevs->devs[j]->io_mutex); } +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)) unlock_kernel(); - +#endif + #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)) kref_put(&usbdevs->candev->refcount,release_device); #else