18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/****************************************************************************** 38c2ecf20Sopenharmony_ci * usbatm.c - Generic USB xDSL driver core 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2001, Alcatel 68c2ecf20Sopenharmony_ci * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas 78c2ecf20Sopenharmony_ci * Copyright (C) 2004, David Woodhouse, Roman Kagan 88c2ecf20Sopenharmony_ci ******************************************************************************/ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci/* 118c2ecf20Sopenharmony_ci * Written by Johan Verrept, Duncan Sands (duncan.sands@free.fr) and David Woodhouse 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * 1.7+: - See the check-in logs 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * 1.6: - No longer opens a connection if the firmware is not loaded 168c2ecf20Sopenharmony_ci * - Added support for the speedtouch 330 178c2ecf20Sopenharmony_ci * - Removed the limit on the number of devices 188c2ecf20Sopenharmony_ci * - Module now autoloads on device plugin 198c2ecf20Sopenharmony_ci * - Merged relevant parts of sarlib 208c2ecf20Sopenharmony_ci * - Replaced the kernel thread with a tasklet 218c2ecf20Sopenharmony_ci * - New packet transmission code 228c2ecf20Sopenharmony_ci * - Changed proc file contents 238c2ecf20Sopenharmony_ci * - Fixed all known SMP races 248c2ecf20Sopenharmony_ci * - Many fixes and cleanups 258c2ecf20Sopenharmony_ci * - Various fixes by Oliver Neukum (oliver@neukum.name) 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * 1.5A: - Version for inclusion in 2.5 series kernel 288c2ecf20Sopenharmony_ci * - Modifications by Richard Purdie (rpurdie@rpsys.net) 298c2ecf20Sopenharmony_ci * - made compatible with kernel 2.5.6 onwards by changing 308c2ecf20Sopenharmony_ci * usbatm_usb_send_data_context->urb to a pointer and adding code 318c2ecf20Sopenharmony_ci * to alloc and free it 328c2ecf20Sopenharmony_ci * - remove_wait_queue() added to usbatm_atm_processqueue_thread() 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * 1.5: - fixed memory leak when atmsar_decode_aal5 returned NULL. 358c2ecf20Sopenharmony_ci * (reported by stephen.robinson@zen.co.uk) 368c2ecf20Sopenharmony_ci * 378c2ecf20Sopenharmony_ci * 1.4: - changed the spin_lock() under interrupt to spin_lock_irqsave() 388c2ecf20Sopenharmony_ci * - unlink all active send urbs of a vcc that is being closed. 398c2ecf20Sopenharmony_ci * 408c2ecf20Sopenharmony_ci * 1.3.1: - added the version number 418c2ecf20Sopenharmony_ci * 428c2ecf20Sopenharmony_ci * 1.3: - Added multiple send urb support 438c2ecf20Sopenharmony_ci * - fixed memory leak and vcc->tx_inuse starvation bug 448c2ecf20Sopenharmony_ci * when not enough memory left in vcc. 458c2ecf20Sopenharmony_ci * 468c2ecf20Sopenharmony_ci * 1.2: - Fixed race condition in usbatm_usb_send_data() 478c2ecf20Sopenharmony_ci * 1.1: - Turned off packet debugging 488c2ecf20Sopenharmony_ci * 498c2ecf20Sopenharmony_ci */ 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#include "usbatm.h" 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 548c2ecf20Sopenharmony_ci#include <linux/crc32.h> 558c2ecf20Sopenharmony_ci#include <linux/errno.h> 568c2ecf20Sopenharmony_ci#include <linux/init.h> 578c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 588c2ecf20Sopenharmony_ci#include <linux/kernel.h> 598c2ecf20Sopenharmony_ci#include <linux/module.h> 608c2ecf20Sopenharmony_ci#include <linux/moduleparam.h> 618c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 628c2ecf20Sopenharmony_ci#include <linux/proc_fs.h> 638c2ecf20Sopenharmony_ci#include <linux/sched/signal.h> 648c2ecf20Sopenharmony_ci#include <linux/signal.h> 658c2ecf20Sopenharmony_ci#include <linux/slab.h> 668c2ecf20Sopenharmony_ci#include <linux/stat.h> 678c2ecf20Sopenharmony_ci#include <linux/timer.h> 688c2ecf20Sopenharmony_ci#include <linux/wait.h> 698c2ecf20Sopenharmony_ci#include <linux/kthread.h> 708c2ecf20Sopenharmony_ci#include <linux/ratelimit.h> 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#ifdef VERBOSE_DEBUG 738c2ecf20Sopenharmony_cistatic int usbatm_print_packet(struct usbatm_data *instance, const unsigned char *data, int len); 748c2ecf20Sopenharmony_ci#define PACKETDEBUG(arg...) usbatm_print_packet(arg) 758c2ecf20Sopenharmony_ci#define vdbg(arg...) dev_dbg(arg) 768c2ecf20Sopenharmony_ci#else 778c2ecf20Sopenharmony_ci#define PACKETDEBUG(arg...) 788c2ecf20Sopenharmony_ci#define vdbg(arg...) 798c2ecf20Sopenharmony_ci#endif 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" 828c2ecf20Sopenharmony_ci#define DRIVER_DESC "Generic USB ATM/DSL I/O" 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistatic const char usbatm_driver_name[] = "usbatm"; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci#define UDSL_MAX_RCV_URBS 16 878c2ecf20Sopenharmony_ci#define UDSL_MAX_SND_URBS 16 888c2ecf20Sopenharmony_ci#define UDSL_MAX_BUF_SIZE 65536 898c2ecf20Sopenharmony_ci#define UDSL_DEFAULT_RCV_URBS 4 908c2ecf20Sopenharmony_ci#define UDSL_DEFAULT_SND_URBS 4 918c2ecf20Sopenharmony_ci#define UDSL_DEFAULT_RCV_BUF_SIZE 3392 /* 64 * ATM_CELL_SIZE */ 928c2ecf20Sopenharmony_ci#define UDSL_DEFAULT_SND_BUF_SIZE 3392 /* 64 * ATM_CELL_SIZE */ 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD) 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci#define THROTTLE_MSECS 100 /* delay to recover processing after urb submission fails */ 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistatic unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS; 998c2ecf20Sopenharmony_cistatic unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS; 1008c2ecf20Sopenharmony_cistatic unsigned int rcv_buf_bytes = UDSL_DEFAULT_RCV_BUF_SIZE; 1018c2ecf20Sopenharmony_cistatic unsigned int snd_buf_bytes = UDSL_DEFAULT_SND_BUF_SIZE; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_cimodule_param(num_rcv_urbs, uint, S_IRUGO); 1048c2ecf20Sopenharmony_ciMODULE_PARM_DESC(num_rcv_urbs, 1058c2ecf20Sopenharmony_ci "Number of urbs used for reception (range: 0-" 1068c2ecf20Sopenharmony_ci __MODULE_STRING(UDSL_MAX_RCV_URBS) ", default: " 1078c2ecf20Sopenharmony_ci __MODULE_STRING(UDSL_DEFAULT_RCV_URBS) ")"); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cimodule_param(num_snd_urbs, uint, S_IRUGO); 1108c2ecf20Sopenharmony_ciMODULE_PARM_DESC(num_snd_urbs, 1118c2ecf20Sopenharmony_ci "Number of urbs used for transmission (range: 0-" 1128c2ecf20Sopenharmony_ci __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: " 1138c2ecf20Sopenharmony_ci __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")"); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cimodule_param(rcv_buf_bytes, uint, S_IRUGO); 1168c2ecf20Sopenharmony_ciMODULE_PARM_DESC(rcv_buf_bytes, 1178c2ecf20Sopenharmony_ci "Size of the buffers used for reception, in bytes (range: 1-" 1188c2ecf20Sopenharmony_ci __MODULE_STRING(UDSL_MAX_BUF_SIZE) ", default: " 1198c2ecf20Sopenharmony_ci __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")"); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cimodule_param(snd_buf_bytes, uint, S_IRUGO); 1228c2ecf20Sopenharmony_ciMODULE_PARM_DESC(snd_buf_bytes, 1238c2ecf20Sopenharmony_ci "Size of the buffers used for transmission, in bytes (range: 1-" 1248c2ecf20Sopenharmony_ci __MODULE_STRING(UDSL_MAX_BUF_SIZE) ", default: " 1258c2ecf20Sopenharmony_ci __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")"); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/* receive */ 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistruct usbatm_vcc_data { 1318c2ecf20Sopenharmony_ci /* vpi/vci lookup */ 1328c2ecf20Sopenharmony_ci struct list_head list; 1338c2ecf20Sopenharmony_ci short vpi; 1348c2ecf20Sopenharmony_ci int vci; 1358c2ecf20Sopenharmony_ci struct atm_vcc *vcc; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci /* raw cell reassembly */ 1388c2ecf20Sopenharmony_ci struct sk_buff *sarb; 1398c2ecf20Sopenharmony_ci}; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci/* send */ 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cistruct usbatm_control { 1458c2ecf20Sopenharmony_ci struct atm_skb_data atm; 1468c2ecf20Sopenharmony_ci u32 len; 1478c2ecf20Sopenharmony_ci u32 crc; 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci#define UDSL_SKB(x) ((struct usbatm_control *)(x)->cb) 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci/* ATM */ 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic void usbatm_atm_dev_close(struct atm_dev *atm_dev); 1568c2ecf20Sopenharmony_cistatic int usbatm_atm_open(struct atm_vcc *vcc); 1578c2ecf20Sopenharmony_cistatic void usbatm_atm_close(struct atm_vcc *vcc); 1588c2ecf20Sopenharmony_cistatic int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, void __user *arg); 1598c2ecf20Sopenharmony_cistatic int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb); 1608c2ecf20Sopenharmony_cistatic int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page); 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_cistatic const struct atmdev_ops usbatm_atm_devops = { 1638c2ecf20Sopenharmony_ci .dev_close = usbatm_atm_dev_close, 1648c2ecf20Sopenharmony_ci .open = usbatm_atm_open, 1658c2ecf20Sopenharmony_ci .close = usbatm_atm_close, 1668c2ecf20Sopenharmony_ci .ioctl = usbatm_atm_ioctl, 1678c2ecf20Sopenharmony_ci .send = usbatm_atm_send, 1688c2ecf20Sopenharmony_ci .proc_read = usbatm_atm_proc_read, 1698c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 1708c2ecf20Sopenharmony_ci}; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci/*********** 1748c2ecf20Sopenharmony_ci** misc ** 1758c2ecf20Sopenharmony_ci***********/ 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_cistatic inline unsigned int usbatm_pdu_length(unsigned int length) 1788c2ecf20Sopenharmony_ci{ 1798c2ecf20Sopenharmony_ci length += ATM_CELL_PAYLOAD - 1 + ATM_AAL5_TRAILER; 1808c2ecf20Sopenharmony_ci return length - length % ATM_CELL_PAYLOAD; 1818c2ecf20Sopenharmony_ci} 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_cistatic inline void usbatm_pop(struct atm_vcc *vcc, struct sk_buff *skb) 1848c2ecf20Sopenharmony_ci{ 1858c2ecf20Sopenharmony_ci if (vcc->pop) 1868c2ecf20Sopenharmony_ci vcc->pop(vcc, skb); 1878c2ecf20Sopenharmony_ci else 1888c2ecf20Sopenharmony_ci dev_kfree_skb_any(skb); 1898c2ecf20Sopenharmony_ci} 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci/*********** 1938c2ecf20Sopenharmony_ci** urbs ** 1948c2ecf20Sopenharmony_ci************/ 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_cistatic struct urb *usbatm_pop_urb(struct usbatm_channel *channel) 1978c2ecf20Sopenharmony_ci{ 1988c2ecf20Sopenharmony_ci struct urb *urb; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci spin_lock_irq(&channel->lock); 2018c2ecf20Sopenharmony_ci if (list_empty(&channel->list)) { 2028c2ecf20Sopenharmony_ci spin_unlock_irq(&channel->lock); 2038c2ecf20Sopenharmony_ci return NULL; 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci urb = list_entry(channel->list.next, struct urb, urb_list); 2078c2ecf20Sopenharmony_ci list_del(&urb->urb_list); 2088c2ecf20Sopenharmony_ci spin_unlock_irq(&channel->lock); 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci return urb; 2118c2ecf20Sopenharmony_ci} 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_cistatic int usbatm_submit_urb(struct urb *urb) 2148c2ecf20Sopenharmony_ci{ 2158c2ecf20Sopenharmony_ci struct usbatm_channel *channel = urb->context; 2168c2ecf20Sopenharmony_ci int ret; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci /* vdbg("%s: submitting urb 0x%p, size %u", 2198c2ecf20Sopenharmony_ci __func__, urb, urb->transfer_buffer_length); */ 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci ret = usb_submit_urb(urb, GFP_ATOMIC); 2228c2ecf20Sopenharmony_ci if (ret) { 2238c2ecf20Sopenharmony_ci if (printk_ratelimit()) 2248c2ecf20Sopenharmony_ci atm_warn(channel->usbatm, "%s: urb 0x%p submission failed (%d)!\n", 2258c2ecf20Sopenharmony_ci __func__, urb, ret); 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci /* consider all errors transient and return the buffer back to the queue */ 2288c2ecf20Sopenharmony_ci urb->status = -EAGAIN; 2298c2ecf20Sopenharmony_ci spin_lock_irq(&channel->lock); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci /* must add to the front when sending; doesn't matter when receiving */ 2328c2ecf20Sopenharmony_ci list_add(&urb->urb_list, &channel->list); 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci spin_unlock_irq(&channel->lock); 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci /* make sure the channel doesn't stall */ 2378c2ecf20Sopenharmony_ci mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS)); 2388c2ecf20Sopenharmony_ci } 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci return ret; 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic void usbatm_complete(struct urb *urb) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci struct usbatm_channel *channel = urb->context; 2468c2ecf20Sopenharmony_ci unsigned long flags; 2478c2ecf20Sopenharmony_ci int status = urb->status; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci /* vdbg("%s: urb 0x%p, status %d, actual_length %d", 2508c2ecf20Sopenharmony_ci __func__, urb, status, urb->actual_length); */ 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci /* usually in_interrupt(), but not always */ 2538c2ecf20Sopenharmony_ci spin_lock_irqsave(&channel->lock, flags); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci /* must add to the back when receiving; doesn't matter when sending */ 2568c2ecf20Sopenharmony_ci list_add_tail(&urb->urb_list, &channel->list); 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&channel->lock, flags); 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci if (unlikely(status) && 2618c2ecf20Sopenharmony_ci (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) || 2628c2ecf20Sopenharmony_ci status != -EILSEQ)) { 2638c2ecf20Sopenharmony_ci if (status == -ESHUTDOWN) 2648c2ecf20Sopenharmony_ci return; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci if (printk_ratelimit()) 2678c2ecf20Sopenharmony_ci atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n", 2688c2ecf20Sopenharmony_ci __func__, urb, status); 2698c2ecf20Sopenharmony_ci /* throttle processing in case of an error */ 2708c2ecf20Sopenharmony_ci mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS)); 2718c2ecf20Sopenharmony_ci } else 2728c2ecf20Sopenharmony_ci tasklet_schedule(&channel->tasklet); 2738c2ecf20Sopenharmony_ci} 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci/************* 2778c2ecf20Sopenharmony_ci** decode ** 2788c2ecf20Sopenharmony_ci*************/ 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_cistatic inline struct usbatm_vcc_data *usbatm_find_vcc(struct usbatm_data *instance, 2818c2ecf20Sopenharmony_ci short vpi, int vci) 2828c2ecf20Sopenharmony_ci{ 2838c2ecf20Sopenharmony_ci struct usbatm_vcc_data *vcc_data; 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci list_for_each_entry(vcc_data, &instance->vcc_list, list) 2868c2ecf20Sopenharmony_ci if ((vcc_data->vci == vci) && (vcc_data->vpi == vpi)) 2878c2ecf20Sopenharmony_ci return vcc_data; 2888c2ecf20Sopenharmony_ci return NULL; 2898c2ecf20Sopenharmony_ci} 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_cistatic void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char *source) 2928c2ecf20Sopenharmony_ci{ 2938c2ecf20Sopenharmony_ci struct atm_vcc *vcc; 2948c2ecf20Sopenharmony_ci struct sk_buff *sarb; 2958c2ecf20Sopenharmony_ci short vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4); 2968c2ecf20Sopenharmony_ci int vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4); 2978c2ecf20Sopenharmony_ci u8 pti = ((source[3] & 0xe) >> 1); 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci if ((vci != instance->cached_vci) || (vpi != instance->cached_vpi)) { 3008c2ecf20Sopenharmony_ci instance->cached_vpi = vpi; 3018c2ecf20Sopenharmony_ci instance->cached_vci = vci; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci instance->cached_vcc = usbatm_find_vcc(instance, vpi, vci); 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci if (!instance->cached_vcc) 3068c2ecf20Sopenharmony_ci atm_rldbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci); 3078c2ecf20Sopenharmony_ci } 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci if (!instance->cached_vcc) 3108c2ecf20Sopenharmony_ci return; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci vcc = instance->cached_vcc->vcc; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci /* OAM F5 end-to-end */ 3158c2ecf20Sopenharmony_ci if (pti == ATM_PTI_E2EF5) { 3168c2ecf20Sopenharmony_ci if (printk_ratelimit()) 3178c2ecf20Sopenharmony_ci atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n", 3188c2ecf20Sopenharmony_ci __func__, vpi, vci); 3198c2ecf20Sopenharmony_ci atomic_inc(&vcc->stats->rx_err); 3208c2ecf20Sopenharmony_ci return; 3218c2ecf20Sopenharmony_ci } 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci sarb = instance->cached_vcc->sarb; 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) { 3268c2ecf20Sopenharmony_ci atm_rldbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n", 3278c2ecf20Sopenharmony_ci __func__, sarb->len, vcc); 3288c2ecf20Sopenharmony_ci /* discard cells already received */ 3298c2ecf20Sopenharmony_ci skb_trim(sarb, 0); 3308c2ecf20Sopenharmony_ci } 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci memcpy(skb_tail_pointer(sarb), source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD); 3338c2ecf20Sopenharmony_ci __skb_put(sarb, ATM_CELL_PAYLOAD); 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci if (pti & 1) { 3368c2ecf20Sopenharmony_ci struct sk_buff *skb; 3378c2ecf20Sopenharmony_ci unsigned int length; 3388c2ecf20Sopenharmony_ci unsigned int pdu_length; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5]; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci /* guard against overflow */ 3438c2ecf20Sopenharmony_ci if (length > ATM_MAX_AAL5_PDU) { 3448c2ecf20Sopenharmony_ci atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n", 3458c2ecf20Sopenharmony_ci __func__, length, vcc); 3468c2ecf20Sopenharmony_ci atomic_inc(&vcc->stats->rx_err); 3478c2ecf20Sopenharmony_ci goto out; 3488c2ecf20Sopenharmony_ci } 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci pdu_length = usbatm_pdu_length(length); 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci if (sarb->len < pdu_length) { 3538c2ecf20Sopenharmony_ci atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n", 3548c2ecf20Sopenharmony_ci __func__, pdu_length, sarb->len, vcc); 3558c2ecf20Sopenharmony_ci atomic_inc(&vcc->stats->rx_err); 3568c2ecf20Sopenharmony_ci goto out; 3578c2ecf20Sopenharmony_ci } 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) { 3608c2ecf20Sopenharmony_ci atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n", 3618c2ecf20Sopenharmony_ci __func__, vcc); 3628c2ecf20Sopenharmony_ci atomic_inc(&vcc->stats->rx_err); 3638c2ecf20Sopenharmony_ci goto out; 3648c2ecf20Sopenharmony_ci } 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci vdbg(&instance->usb_intf->dev, 3678c2ecf20Sopenharmony_ci "%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", 3688c2ecf20Sopenharmony_ci __func__, length, pdu_length, vcc); 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci skb = dev_alloc_skb(length); 3718c2ecf20Sopenharmony_ci if (!skb) { 3728c2ecf20Sopenharmony_ci if (printk_ratelimit()) 3738c2ecf20Sopenharmony_ci atm_err(instance, "%s: no memory for skb (length: %u)!\n", 3748c2ecf20Sopenharmony_ci __func__, length); 3758c2ecf20Sopenharmony_ci atomic_inc(&vcc->stats->rx_drop); 3768c2ecf20Sopenharmony_ci goto out; 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci vdbg(&instance->usb_intf->dev, 3808c2ecf20Sopenharmony_ci "%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", 3818c2ecf20Sopenharmony_ci __func__, skb, skb->truesize); 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci if (!atm_charge(vcc, skb->truesize)) { 3848c2ecf20Sopenharmony_ci atm_rldbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n", 3858c2ecf20Sopenharmony_ci __func__, skb->truesize); 3868c2ecf20Sopenharmony_ci dev_kfree_skb_any(skb); 3878c2ecf20Sopenharmony_ci goto out; /* atm_charge increments rx_drop */ 3888c2ecf20Sopenharmony_ci } 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci skb_copy_to_linear_data(skb, 3918c2ecf20Sopenharmony_ci skb_tail_pointer(sarb) - pdu_length, 3928c2ecf20Sopenharmony_ci length); 3938c2ecf20Sopenharmony_ci __skb_put(skb, length); 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci vdbg(&instance->usb_intf->dev, 3968c2ecf20Sopenharmony_ci "%s: sending skb 0x%p, skb->len %u, skb->truesize %u", 3978c2ecf20Sopenharmony_ci __func__, skb, skb->len, skb->truesize); 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci PACKETDEBUG(instance, skb->data, skb->len); 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci vcc->push(vcc, skb); 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci atomic_inc(&vcc->stats->rx); 4048c2ecf20Sopenharmony_ci out: 4058c2ecf20Sopenharmony_ci skb_trim(sarb, 0); 4068c2ecf20Sopenharmony_ci } 4078c2ecf20Sopenharmony_ci} 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_cistatic void usbatm_extract_cells(struct usbatm_data *instance, 4108c2ecf20Sopenharmony_ci unsigned char *source, unsigned int avail_data) 4118c2ecf20Sopenharmony_ci{ 4128c2ecf20Sopenharmony_ci unsigned int stride = instance->rx_channel.stride; 4138c2ecf20Sopenharmony_ci unsigned int buf_usage = instance->buf_usage; 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci /* extract cells from incoming data, taking into account that 4168c2ecf20Sopenharmony_ci * the length of avail data may not be a multiple of stride */ 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci if (buf_usage > 0) { 4198c2ecf20Sopenharmony_ci /* we have a partially received atm cell */ 4208c2ecf20Sopenharmony_ci unsigned char *cell_buf = instance->cell_buf; 4218c2ecf20Sopenharmony_ci unsigned int space_left = stride - buf_usage; 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci if (avail_data >= space_left) { 4248c2ecf20Sopenharmony_ci /* add new data and process cell */ 4258c2ecf20Sopenharmony_ci memcpy(cell_buf + buf_usage, source, space_left); 4268c2ecf20Sopenharmony_ci source += space_left; 4278c2ecf20Sopenharmony_ci avail_data -= space_left; 4288c2ecf20Sopenharmony_ci usbatm_extract_one_cell(instance, cell_buf); 4298c2ecf20Sopenharmony_ci instance->buf_usage = 0; 4308c2ecf20Sopenharmony_ci } else { 4318c2ecf20Sopenharmony_ci /* not enough data to fill the cell */ 4328c2ecf20Sopenharmony_ci memcpy(cell_buf + buf_usage, source, avail_data); 4338c2ecf20Sopenharmony_ci instance->buf_usage = buf_usage + avail_data; 4348c2ecf20Sopenharmony_ci return; 4358c2ecf20Sopenharmony_ci } 4368c2ecf20Sopenharmony_ci } 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci for (; avail_data >= stride; avail_data -= stride, source += stride) 4398c2ecf20Sopenharmony_ci usbatm_extract_one_cell(instance, source); 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci if (avail_data > 0) { 4428c2ecf20Sopenharmony_ci /* length was not a multiple of stride - 4438c2ecf20Sopenharmony_ci * save remaining data for next call */ 4448c2ecf20Sopenharmony_ci memcpy(instance->cell_buf, source, avail_data); 4458c2ecf20Sopenharmony_ci instance->buf_usage = avail_data; 4468c2ecf20Sopenharmony_ci } 4478c2ecf20Sopenharmony_ci} 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci/************* 4518c2ecf20Sopenharmony_ci** encode ** 4528c2ecf20Sopenharmony_ci*************/ 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_cistatic unsigned int usbatm_write_cells(struct usbatm_data *instance, 4558c2ecf20Sopenharmony_ci struct sk_buff *skb, 4568c2ecf20Sopenharmony_ci u8 *target, unsigned int avail_space) 4578c2ecf20Sopenharmony_ci{ 4588c2ecf20Sopenharmony_ci struct usbatm_control *ctrl = UDSL_SKB(skb); 4598c2ecf20Sopenharmony_ci struct atm_vcc *vcc = ctrl->atm.vcc; 4608c2ecf20Sopenharmony_ci unsigned int bytes_written; 4618c2ecf20Sopenharmony_ci unsigned int stride = instance->tx_channel.stride; 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci for (bytes_written = 0; bytes_written < avail_space && ctrl->len; 4648c2ecf20Sopenharmony_ci bytes_written += stride, target += stride) { 4658c2ecf20Sopenharmony_ci unsigned int data_len = min_t(unsigned int, skb->len, ATM_CELL_PAYLOAD); 4668c2ecf20Sopenharmony_ci unsigned int left = ATM_CELL_PAYLOAD - data_len; 4678c2ecf20Sopenharmony_ci u8 *ptr = target; 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci ptr[0] = vcc->vpi >> 4; 4708c2ecf20Sopenharmony_ci ptr[1] = (vcc->vpi << 4) | (vcc->vci >> 12); 4718c2ecf20Sopenharmony_ci ptr[2] = vcc->vci >> 4; 4728c2ecf20Sopenharmony_ci ptr[3] = vcc->vci << 4; 4738c2ecf20Sopenharmony_ci ptr[4] = 0xec; 4748c2ecf20Sopenharmony_ci ptr += ATM_CELL_HEADER; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci skb_copy_from_linear_data(skb, ptr, data_len); 4778c2ecf20Sopenharmony_ci ptr += data_len; 4788c2ecf20Sopenharmony_ci __skb_pull(skb, data_len); 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci if (!left) 4818c2ecf20Sopenharmony_ci continue; 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci memset(ptr, 0, left); 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci if (left >= ATM_AAL5_TRAILER) { /* trailer will go in this cell */ 4868c2ecf20Sopenharmony_ci u8 *trailer = target + ATM_CELL_SIZE - ATM_AAL5_TRAILER; 4878c2ecf20Sopenharmony_ci /* trailer[0] = 0; UU = 0 */ 4888c2ecf20Sopenharmony_ci /* trailer[1] = 0; CPI = 0 */ 4898c2ecf20Sopenharmony_ci trailer[2] = ctrl->len >> 8; 4908c2ecf20Sopenharmony_ci trailer[3] = ctrl->len; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci ctrl->crc = ~crc32_be(ctrl->crc, ptr, left - 4); 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci trailer[4] = ctrl->crc >> 24; 4958c2ecf20Sopenharmony_ci trailer[5] = ctrl->crc >> 16; 4968c2ecf20Sopenharmony_ci trailer[6] = ctrl->crc >> 8; 4978c2ecf20Sopenharmony_ci trailer[7] = ctrl->crc; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci target[3] |= 0x2; /* adjust PTI */ 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci ctrl->len = 0; /* tag this skb finished */ 5028c2ecf20Sopenharmony_ci } else 5038c2ecf20Sopenharmony_ci ctrl->crc = crc32_be(ctrl->crc, ptr, left); 5048c2ecf20Sopenharmony_ci } 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci return bytes_written; 5078c2ecf20Sopenharmony_ci} 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci/************** 5118c2ecf20Sopenharmony_ci** receive ** 5128c2ecf20Sopenharmony_ci**************/ 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_cistatic void usbatm_rx_process(struct tasklet_struct *t) 5158c2ecf20Sopenharmony_ci{ 5168c2ecf20Sopenharmony_ci struct usbatm_data *instance = from_tasklet(instance, t, 5178c2ecf20Sopenharmony_ci rx_channel.tasklet); 5188c2ecf20Sopenharmony_ci struct urb *urb; 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci while ((urb = usbatm_pop_urb(&instance->rx_channel))) { 5218c2ecf20Sopenharmony_ci vdbg(&instance->usb_intf->dev, 5228c2ecf20Sopenharmony_ci "%s: processing urb 0x%p", __func__, urb); 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci if (usb_pipeisoc(urb->pipe)) { 5258c2ecf20Sopenharmony_ci unsigned char *merge_start = NULL; 5268c2ecf20Sopenharmony_ci unsigned int merge_length = 0; 5278c2ecf20Sopenharmony_ci const unsigned int packet_size = instance->rx_channel.packet_size; 5288c2ecf20Sopenharmony_ci int i; 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci for (i = 0; i < urb->number_of_packets; i++) { 5318c2ecf20Sopenharmony_ci if (!urb->iso_frame_desc[i].status) { 5328c2ecf20Sopenharmony_ci unsigned int actual_length = urb->iso_frame_desc[i].actual_length; 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci if (!merge_length) 5358c2ecf20Sopenharmony_ci merge_start = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset; 5368c2ecf20Sopenharmony_ci merge_length += actual_length; 5378c2ecf20Sopenharmony_ci if (merge_length && (actual_length < packet_size)) { 5388c2ecf20Sopenharmony_ci usbatm_extract_cells(instance, merge_start, merge_length); 5398c2ecf20Sopenharmony_ci merge_length = 0; 5408c2ecf20Sopenharmony_ci } 5418c2ecf20Sopenharmony_ci } else { 5428c2ecf20Sopenharmony_ci atm_rldbg(instance, "%s: status %d in frame %d!\n", __func__, urb->status, i); 5438c2ecf20Sopenharmony_ci if (merge_length) 5448c2ecf20Sopenharmony_ci usbatm_extract_cells(instance, merge_start, merge_length); 5458c2ecf20Sopenharmony_ci merge_length = 0; 5468c2ecf20Sopenharmony_ci instance->buf_usage = 0; 5478c2ecf20Sopenharmony_ci } 5488c2ecf20Sopenharmony_ci } 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci if (merge_length) 5518c2ecf20Sopenharmony_ci usbatm_extract_cells(instance, merge_start, merge_length); 5528c2ecf20Sopenharmony_ci } else 5538c2ecf20Sopenharmony_ci if (!urb->status) 5548c2ecf20Sopenharmony_ci usbatm_extract_cells(instance, urb->transfer_buffer, urb->actual_length); 5558c2ecf20Sopenharmony_ci else 5568c2ecf20Sopenharmony_ci instance->buf_usage = 0; 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci if (usbatm_submit_urb(urb)) 5598c2ecf20Sopenharmony_ci return; 5608c2ecf20Sopenharmony_ci } 5618c2ecf20Sopenharmony_ci} 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci/*********** 5658c2ecf20Sopenharmony_ci** send ** 5668c2ecf20Sopenharmony_ci***********/ 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_cistatic void usbatm_tx_process(struct tasklet_struct *t) 5698c2ecf20Sopenharmony_ci{ 5708c2ecf20Sopenharmony_ci struct usbatm_data *instance = from_tasklet(instance, t, 5718c2ecf20Sopenharmony_ci tx_channel.tasklet); 5728c2ecf20Sopenharmony_ci struct sk_buff *skb = instance->current_skb; 5738c2ecf20Sopenharmony_ci struct urb *urb = NULL; 5748c2ecf20Sopenharmony_ci const unsigned int buf_size = instance->tx_channel.buf_size; 5758c2ecf20Sopenharmony_ci unsigned int bytes_written = 0; 5768c2ecf20Sopenharmony_ci u8 *buffer = NULL; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci if (!skb) 5798c2ecf20Sopenharmony_ci skb = skb_dequeue(&instance->sndqueue); 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci while (skb) { 5828c2ecf20Sopenharmony_ci if (!urb) { 5838c2ecf20Sopenharmony_ci urb = usbatm_pop_urb(&instance->tx_channel); 5848c2ecf20Sopenharmony_ci if (!urb) 5858c2ecf20Sopenharmony_ci break; /* no more senders */ 5868c2ecf20Sopenharmony_ci buffer = urb->transfer_buffer; 5878c2ecf20Sopenharmony_ci bytes_written = (urb->status == -EAGAIN) ? 5888c2ecf20Sopenharmony_ci urb->transfer_buffer_length : 0; 5898c2ecf20Sopenharmony_ci } 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci bytes_written += usbatm_write_cells(instance, skb, 5928c2ecf20Sopenharmony_ci buffer + bytes_written, 5938c2ecf20Sopenharmony_ci buf_size - bytes_written); 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci vdbg(&instance->usb_intf->dev, 5968c2ecf20Sopenharmony_ci "%s: wrote %u bytes from skb 0x%p to urb 0x%p", 5978c2ecf20Sopenharmony_ci __func__, bytes_written, skb, urb); 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci if (!UDSL_SKB(skb)->len) { 6008c2ecf20Sopenharmony_ci struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc; 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci usbatm_pop(vcc, skb); 6038c2ecf20Sopenharmony_ci atomic_inc(&vcc->stats->tx); 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci skb = skb_dequeue(&instance->sndqueue); 6068c2ecf20Sopenharmony_ci } 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci if (bytes_written == buf_size || (!skb && bytes_written)) { 6098c2ecf20Sopenharmony_ci urb->transfer_buffer_length = bytes_written; 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci if (usbatm_submit_urb(urb)) 6128c2ecf20Sopenharmony_ci break; 6138c2ecf20Sopenharmony_ci urb = NULL; 6148c2ecf20Sopenharmony_ci } 6158c2ecf20Sopenharmony_ci } 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci instance->current_skb = skb; 6188c2ecf20Sopenharmony_ci} 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_cistatic void usbatm_cancel_send(struct usbatm_data *instance, 6218c2ecf20Sopenharmony_ci struct atm_vcc *vcc) 6228c2ecf20Sopenharmony_ci{ 6238c2ecf20Sopenharmony_ci struct sk_buff *skb, *n; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci spin_lock_irq(&instance->sndqueue.lock); 6268c2ecf20Sopenharmony_ci skb_queue_walk_safe(&instance->sndqueue, skb, n) { 6278c2ecf20Sopenharmony_ci if (UDSL_SKB(skb)->atm.vcc == vcc) { 6288c2ecf20Sopenharmony_ci atm_dbg(instance, "%s: popping skb 0x%p\n", __func__, skb); 6298c2ecf20Sopenharmony_ci __skb_unlink(skb, &instance->sndqueue); 6308c2ecf20Sopenharmony_ci usbatm_pop(vcc, skb); 6318c2ecf20Sopenharmony_ci } 6328c2ecf20Sopenharmony_ci } 6338c2ecf20Sopenharmony_ci spin_unlock_irq(&instance->sndqueue.lock); 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci tasklet_disable(&instance->tx_channel.tasklet); 6368c2ecf20Sopenharmony_ci if ((skb = instance->current_skb) && (UDSL_SKB(skb)->atm.vcc == vcc)) { 6378c2ecf20Sopenharmony_ci atm_dbg(instance, "%s: popping current skb (0x%p)\n", __func__, skb); 6388c2ecf20Sopenharmony_ci instance->current_skb = NULL; 6398c2ecf20Sopenharmony_ci usbatm_pop(vcc, skb); 6408c2ecf20Sopenharmony_ci } 6418c2ecf20Sopenharmony_ci tasklet_enable(&instance->tx_channel.tasklet); 6428c2ecf20Sopenharmony_ci} 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_cistatic int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb) 6458c2ecf20Sopenharmony_ci{ 6468c2ecf20Sopenharmony_ci struct usbatm_data *instance = vcc->dev->dev_data; 6478c2ecf20Sopenharmony_ci struct usbatm_control *ctrl = UDSL_SKB(skb); 6488c2ecf20Sopenharmony_ci int err; 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci /* racy disconnection check - fine */ 6518c2ecf20Sopenharmony_ci if (!instance || instance->disconnected) { 6528c2ecf20Sopenharmony_ci#ifdef VERBOSE_DEBUG 6538c2ecf20Sopenharmony_ci printk_ratelimited(KERN_DEBUG "%s: %s!\n", __func__, instance ? "disconnected" : "NULL instance"); 6548c2ecf20Sopenharmony_ci#endif 6558c2ecf20Sopenharmony_ci err = -ENODEV; 6568c2ecf20Sopenharmony_ci goto fail; 6578c2ecf20Sopenharmony_ci } 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci if (vcc->qos.aal != ATM_AAL5) { 6608c2ecf20Sopenharmony_ci atm_rldbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 6618c2ecf20Sopenharmony_ci err = -EINVAL; 6628c2ecf20Sopenharmony_ci goto fail; 6638c2ecf20Sopenharmony_ci } 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci if (skb->len > ATM_MAX_AAL5_PDU) { 6668c2ecf20Sopenharmony_ci atm_rldbg(instance, "%s: packet too long (%d vs %d)!\n", 6678c2ecf20Sopenharmony_ci __func__, skb->len, ATM_MAX_AAL5_PDU); 6688c2ecf20Sopenharmony_ci err = -EINVAL; 6698c2ecf20Sopenharmony_ci goto fail; 6708c2ecf20Sopenharmony_ci } 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_ci PACKETDEBUG(instance, skb->data, skb->len); 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci /* initialize the control block */ 6758c2ecf20Sopenharmony_ci ctrl->atm.vcc = vcc; 6768c2ecf20Sopenharmony_ci ctrl->len = skb->len; 6778c2ecf20Sopenharmony_ci ctrl->crc = crc32_be(~0, skb->data, skb->len); 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci skb_queue_tail(&instance->sndqueue, skb); 6808c2ecf20Sopenharmony_ci tasklet_schedule(&instance->tx_channel.tasklet); 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci return 0; 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci fail: 6858c2ecf20Sopenharmony_ci usbatm_pop(vcc, skb); 6868c2ecf20Sopenharmony_ci return err; 6878c2ecf20Sopenharmony_ci} 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci/******************** 6918c2ecf20Sopenharmony_ci** bean counting ** 6928c2ecf20Sopenharmony_ci********************/ 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_cistatic void usbatm_destroy_instance(struct kref *kref) 6958c2ecf20Sopenharmony_ci{ 6968c2ecf20Sopenharmony_ci struct usbatm_data *instance = container_of(kref, struct usbatm_data, refcount); 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci tasklet_kill(&instance->rx_channel.tasklet); 6998c2ecf20Sopenharmony_ci tasklet_kill(&instance->tx_channel.tasklet); 7008c2ecf20Sopenharmony_ci usb_put_dev(instance->usb_dev); 7018c2ecf20Sopenharmony_ci kfree(instance); 7028c2ecf20Sopenharmony_ci} 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_cistatic void usbatm_get_instance(struct usbatm_data *instance) 7058c2ecf20Sopenharmony_ci{ 7068c2ecf20Sopenharmony_ci kref_get(&instance->refcount); 7078c2ecf20Sopenharmony_ci} 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_cistatic void usbatm_put_instance(struct usbatm_data *instance) 7108c2ecf20Sopenharmony_ci{ 7118c2ecf20Sopenharmony_ci kref_put(&instance->refcount, usbatm_destroy_instance); 7128c2ecf20Sopenharmony_ci} 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci/********** 7168c2ecf20Sopenharmony_ci** ATM ** 7178c2ecf20Sopenharmony_ci**********/ 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_cistatic void usbatm_atm_dev_close(struct atm_dev *atm_dev) 7208c2ecf20Sopenharmony_ci{ 7218c2ecf20Sopenharmony_ci struct usbatm_data *instance = atm_dev->dev_data; 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci if (!instance) 7248c2ecf20Sopenharmony_ci return; 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci atm_dev->dev_data = NULL; /* catch bugs */ 7278c2ecf20Sopenharmony_ci usbatm_put_instance(instance); /* taken in usbatm_atm_init */ 7288c2ecf20Sopenharmony_ci} 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_cistatic int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page) 7318c2ecf20Sopenharmony_ci{ 7328c2ecf20Sopenharmony_ci struct usbatm_data *instance = atm_dev->dev_data; 7338c2ecf20Sopenharmony_ci int left = *pos; 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci if (!instance) 7368c2ecf20Sopenharmony_ci return -ENODEV; 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci if (!left--) 7398c2ecf20Sopenharmony_ci return sprintf(page, "%s\n", instance->description); 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci if (!left--) 7428c2ecf20Sopenharmony_ci return sprintf(page, "MAC: %pM\n", atm_dev->esi); 7438c2ecf20Sopenharmony_ci 7448c2ecf20Sopenharmony_ci if (!left--) 7458c2ecf20Sopenharmony_ci return sprintf(page, 7468c2ecf20Sopenharmony_ci "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n", 7478c2ecf20Sopenharmony_ci atomic_read(&atm_dev->stats.aal5.tx), 7488c2ecf20Sopenharmony_ci atomic_read(&atm_dev->stats.aal5.tx_err), 7498c2ecf20Sopenharmony_ci atomic_read(&atm_dev->stats.aal5.rx), 7508c2ecf20Sopenharmony_ci atomic_read(&atm_dev->stats.aal5.rx_err), 7518c2ecf20Sopenharmony_ci atomic_read(&atm_dev->stats.aal5.rx_drop)); 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci if (!left--) { 7548c2ecf20Sopenharmony_ci if (instance->disconnected) 7558c2ecf20Sopenharmony_ci return sprintf(page, "Disconnected\n"); 7568c2ecf20Sopenharmony_ci else 7578c2ecf20Sopenharmony_ci switch (atm_dev->signal) { 7588c2ecf20Sopenharmony_ci case ATM_PHY_SIG_FOUND: 7598c2ecf20Sopenharmony_ci return sprintf(page, "Line up\n"); 7608c2ecf20Sopenharmony_ci case ATM_PHY_SIG_LOST: 7618c2ecf20Sopenharmony_ci return sprintf(page, "Line down\n"); 7628c2ecf20Sopenharmony_ci default: 7638c2ecf20Sopenharmony_ci return sprintf(page, "Line state unknown\n"); 7648c2ecf20Sopenharmony_ci } 7658c2ecf20Sopenharmony_ci } 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ci return 0; 7688c2ecf20Sopenharmony_ci} 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_cistatic int usbatm_atm_open(struct atm_vcc *vcc) 7718c2ecf20Sopenharmony_ci{ 7728c2ecf20Sopenharmony_ci struct usbatm_data *instance = vcc->dev->dev_data; 7738c2ecf20Sopenharmony_ci struct usbatm_vcc_data *new = NULL; 7748c2ecf20Sopenharmony_ci int ret; 7758c2ecf20Sopenharmony_ci int vci = vcc->vci; 7768c2ecf20Sopenharmony_ci short vpi = vcc->vpi; 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci if (!instance) 7798c2ecf20Sopenharmony_ci return -ENODEV; 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci /* only support AAL5 */ 7828c2ecf20Sopenharmony_ci if ((vcc->qos.aal != ATM_AAL5)) { 7838c2ecf20Sopenharmony_ci atm_warn(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 7848c2ecf20Sopenharmony_ci return -EINVAL; 7858c2ecf20Sopenharmony_ci } 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci /* sanity checks */ 7888c2ecf20Sopenharmony_ci if ((vcc->qos.rxtp.max_sdu < 0) || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) { 7898c2ecf20Sopenharmony_ci atm_dbg(instance, "%s: max_sdu %d out of range!\n", __func__, vcc->qos.rxtp.max_sdu); 7908c2ecf20Sopenharmony_ci return -EINVAL; 7918c2ecf20Sopenharmony_ci } 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_ci mutex_lock(&instance->serialize); /* vs self, usbatm_atm_close, usbatm_usb_disconnect */ 7948c2ecf20Sopenharmony_ci 7958c2ecf20Sopenharmony_ci if (instance->disconnected) { 7968c2ecf20Sopenharmony_ci atm_dbg(instance, "%s: disconnected!\n", __func__); 7978c2ecf20Sopenharmony_ci ret = -ENODEV; 7988c2ecf20Sopenharmony_ci goto fail; 7998c2ecf20Sopenharmony_ci } 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_ci if (usbatm_find_vcc(instance, vpi, vci)) { 8028c2ecf20Sopenharmony_ci atm_dbg(instance, "%s: %hd/%d already in use!\n", __func__, vpi, vci); 8038c2ecf20Sopenharmony_ci ret = -EADDRINUSE; 8048c2ecf20Sopenharmony_ci goto fail; 8058c2ecf20Sopenharmony_ci } 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci new = kzalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL); 8088c2ecf20Sopenharmony_ci if (!new) { 8098c2ecf20Sopenharmony_ci ret = -ENOMEM; 8108c2ecf20Sopenharmony_ci goto fail; 8118c2ecf20Sopenharmony_ci } 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_ci new->vcc = vcc; 8148c2ecf20Sopenharmony_ci new->vpi = vpi; 8158c2ecf20Sopenharmony_ci new->vci = vci; 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci new->sarb = alloc_skb(usbatm_pdu_length(vcc->qos.rxtp.max_sdu), GFP_KERNEL); 8188c2ecf20Sopenharmony_ci if (!new->sarb) { 8198c2ecf20Sopenharmony_ci atm_err(instance, "%s: no memory for SAR buffer!\n", __func__); 8208c2ecf20Sopenharmony_ci ret = -ENOMEM; 8218c2ecf20Sopenharmony_ci goto fail; 8228c2ecf20Sopenharmony_ci } 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_ci vcc->dev_data = new; 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci tasklet_disable(&instance->rx_channel.tasklet); 8278c2ecf20Sopenharmony_ci instance->cached_vcc = new; 8288c2ecf20Sopenharmony_ci instance->cached_vpi = vpi; 8298c2ecf20Sopenharmony_ci instance->cached_vci = vci; 8308c2ecf20Sopenharmony_ci list_add(&new->list, &instance->vcc_list); 8318c2ecf20Sopenharmony_ci tasklet_enable(&instance->rx_channel.tasklet); 8328c2ecf20Sopenharmony_ci 8338c2ecf20Sopenharmony_ci set_bit(ATM_VF_ADDR, &vcc->flags); 8348c2ecf20Sopenharmony_ci set_bit(ATM_VF_PARTIAL, &vcc->flags); 8358c2ecf20Sopenharmony_ci set_bit(ATM_VF_READY, &vcc->flags); 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci mutex_unlock(&instance->serialize); 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_ci atm_dbg(instance, "%s: allocated vcc data 0x%p\n", __func__, new); 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci return 0; 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_cifail: 8448c2ecf20Sopenharmony_ci kfree(new); 8458c2ecf20Sopenharmony_ci mutex_unlock(&instance->serialize); 8468c2ecf20Sopenharmony_ci return ret; 8478c2ecf20Sopenharmony_ci} 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_cistatic void usbatm_atm_close(struct atm_vcc *vcc) 8508c2ecf20Sopenharmony_ci{ 8518c2ecf20Sopenharmony_ci struct usbatm_data *instance = vcc->dev->dev_data; 8528c2ecf20Sopenharmony_ci struct usbatm_vcc_data *vcc_data = vcc->dev_data; 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_ci if (!instance || !vcc_data) 8558c2ecf20Sopenharmony_ci return; 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci usbatm_cancel_send(instance, vcc); 8588c2ecf20Sopenharmony_ci 8598c2ecf20Sopenharmony_ci mutex_lock(&instance->serialize); /* vs self, usbatm_atm_open, usbatm_usb_disconnect */ 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci tasklet_disable(&instance->rx_channel.tasklet); 8628c2ecf20Sopenharmony_ci if (instance->cached_vcc == vcc_data) { 8638c2ecf20Sopenharmony_ci instance->cached_vcc = NULL; 8648c2ecf20Sopenharmony_ci instance->cached_vpi = ATM_VPI_UNSPEC; 8658c2ecf20Sopenharmony_ci instance->cached_vci = ATM_VCI_UNSPEC; 8668c2ecf20Sopenharmony_ci } 8678c2ecf20Sopenharmony_ci list_del(&vcc_data->list); 8688c2ecf20Sopenharmony_ci tasklet_enable(&instance->rx_channel.tasklet); 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci kfree_skb(vcc_data->sarb); 8718c2ecf20Sopenharmony_ci vcc_data->sarb = NULL; 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_ci kfree(vcc_data); 8748c2ecf20Sopenharmony_ci vcc->dev_data = NULL; 8758c2ecf20Sopenharmony_ci 8768c2ecf20Sopenharmony_ci vcc->vpi = ATM_VPI_UNSPEC; 8778c2ecf20Sopenharmony_ci vcc->vci = ATM_VCI_UNSPEC; 8788c2ecf20Sopenharmony_ci clear_bit(ATM_VF_READY, &vcc->flags); 8798c2ecf20Sopenharmony_ci clear_bit(ATM_VF_PARTIAL, &vcc->flags); 8808c2ecf20Sopenharmony_ci clear_bit(ATM_VF_ADDR, &vcc->flags); 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci mutex_unlock(&instance->serialize); 8838c2ecf20Sopenharmony_ci} 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_cistatic int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, 8868c2ecf20Sopenharmony_ci void __user *arg) 8878c2ecf20Sopenharmony_ci{ 8888c2ecf20Sopenharmony_ci struct usbatm_data *instance = atm_dev->dev_data; 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci if (!instance || instance->disconnected) 8918c2ecf20Sopenharmony_ci return -ENODEV; 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_ci switch (cmd) { 8948c2ecf20Sopenharmony_ci case ATM_QUERYLOOP: 8958c2ecf20Sopenharmony_ci return put_user(ATM_LM_NONE, (int __user *)arg) ? -EFAULT : 0; 8968c2ecf20Sopenharmony_ci default: 8978c2ecf20Sopenharmony_ci return -ENOIOCTLCMD; 8988c2ecf20Sopenharmony_ci } 8998c2ecf20Sopenharmony_ci} 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_cistatic int usbatm_atm_init(struct usbatm_data *instance) 9028c2ecf20Sopenharmony_ci{ 9038c2ecf20Sopenharmony_ci struct atm_dev *atm_dev; 9048c2ecf20Sopenharmony_ci int ret, i; 9058c2ecf20Sopenharmony_ci 9068c2ecf20Sopenharmony_ci /* ATM init. The ATM initialization scheme suffers from an intrinsic race 9078c2ecf20Sopenharmony_ci * condition: callbacks we register can be executed at once, before we have 9088c2ecf20Sopenharmony_ci * initialized the struct atm_dev. To protect against this, all callbacks 9098c2ecf20Sopenharmony_ci * abort if atm_dev->dev_data is NULL. */ 9108c2ecf20Sopenharmony_ci atm_dev = atm_dev_register(instance->driver_name, 9118c2ecf20Sopenharmony_ci &instance->usb_intf->dev, &usbatm_atm_devops, 9128c2ecf20Sopenharmony_ci -1, NULL); 9138c2ecf20Sopenharmony_ci if (!atm_dev) { 9148c2ecf20Sopenharmony_ci usb_err(instance, "%s: failed to register ATM device!\n", __func__); 9158c2ecf20Sopenharmony_ci return -1; 9168c2ecf20Sopenharmony_ci } 9178c2ecf20Sopenharmony_ci 9188c2ecf20Sopenharmony_ci instance->atm_dev = atm_dev; 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_ci atm_dev->ci_range.vpi_bits = ATM_CI_MAX; 9218c2ecf20Sopenharmony_ci atm_dev->ci_range.vci_bits = ATM_CI_MAX; 9228c2ecf20Sopenharmony_ci atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 9238c2ecf20Sopenharmony_ci 9248c2ecf20Sopenharmony_ci /* temp init ATM device, set to 128kbit */ 9258c2ecf20Sopenharmony_ci atm_dev->link_rate = 128 * 1000 / 424; 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) { 9288c2ecf20Sopenharmony_ci atm_err(instance, "%s: atm_start failed: %d!\n", __func__, ret); 9298c2ecf20Sopenharmony_ci goto fail; 9308c2ecf20Sopenharmony_ci } 9318c2ecf20Sopenharmony_ci 9328c2ecf20Sopenharmony_ci usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */ 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ci /* ready for ATM callbacks */ 9358c2ecf20Sopenharmony_ci mb(); 9368c2ecf20Sopenharmony_ci atm_dev->dev_data = instance; 9378c2ecf20Sopenharmony_ci 9388c2ecf20Sopenharmony_ci /* submit all rx URBs */ 9398c2ecf20Sopenharmony_ci for (i = 0; i < num_rcv_urbs; i++) 9408c2ecf20Sopenharmony_ci usbatm_submit_urb(instance->urbs[i]); 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_ci return 0; 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci fail: 9458c2ecf20Sopenharmony_ci instance->atm_dev = NULL; 9468c2ecf20Sopenharmony_ci atm_dev_deregister(atm_dev); /* usbatm_atm_dev_close will eventually be called */ 9478c2ecf20Sopenharmony_ci return ret; 9488c2ecf20Sopenharmony_ci} 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci/********** 9528c2ecf20Sopenharmony_ci** USB ** 9538c2ecf20Sopenharmony_ci**********/ 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_cistatic int usbatm_do_heavy_init(void *arg) 9568c2ecf20Sopenharmony_ci{ 9578c2ecf20Sopenharmony_ci struct usbatm_data *instance = arg; 9588c2ecf20Sopenharmony_ci int ret; 9598c2ecf20Sopenharmony_ci 9608c2ecf20Sopenharmony_ci allow_signal(SIGTERM); 9618c2ecf20Sopenharmony_ci complete(&instance->thread_started); 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci ret = instance->driver->heavy_init(instance, instance->usb_intf); 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ci if (!ret) 9668c2ecf20Sopenharmony_ci ret = usbatm_atm_init(instance); 9678c2ecf20Sopenharmony_ci 9688c2ecf20Sopenharmony_ci mutex_lock(&instance->serialize); 9698c2ecf20Sopenharmony_ci instance->thread = NULL; 9708c2ecf20Sopenharmony_ci mutex_unlock(&instance->serialize); 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci complete_and_exit(&instance->thread_exited, ret); 9738c2ecf20Sopenharmony_ci} 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_cistatic int usbatm_heavy_init(struct usbatm_data *instance) 9768c2ecf20Sopenharmony_ci{ 9778c2ecf20Sopenharmony_ci struct task_struct *t; 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ci t = kthread_create(usbatm_do_heavy_init, instance, "%s", 9808c2ecf20Sopenharmony_ci instance->driver->driver_name); 9818c2ecf20Sopenharmony_ci if (IS_ERR(t)) { 9828c2ecf20Sopenharmony_ci usb_err(instance, "%s: failed to create kernel_thread (%ld)!\n", 9838c2ecf20Sopenharmony_ci __func__, PTR_ERR(t)); 9848c2ecf20Sopenharmony_ci return PTR_ERR(t); 9858c2ecf20Sopenharmony_ci } 9868c2ecf20Sopenharmony_ci 9878c2ecf20Sopenharmony_ci instance->thread = t; 9888c2ecf20Sopenharmony_ci wake_up_process(t); 9898c2ecf20Sopenharmony_ci wait_for_completion(&instance->thread_started); 9908c2ecf20Sopenharmony_ci 9918c2ecf20Sopenharmony_ci return 0; 9928c2ecf20Sopenharmony_ci} 9938c2ecf20Sopenharmony_ci 9948c2ecf20Sopenharmony_cistatic void usbatm_tasklet_schedule(struct timer_list *t) 9958c2ecf20Sopenharmony_ci{ 9968c2ecf20Sopenharmony_ci struct usbatm_channel *channel = from_timer(channel, t, delay); 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci tasklet_schedule(&channel->tasklet); 9998c2ecf20Sopenharmony_ci} 10008c2ecf20Sopenharmony_ci 10018c2ecf20Sopenharmony_cistatic void usbatm_init_channel(struct usbatm_channel *channel) 10028c2ecf20Sopenharmony_ci{ 10038c2ecf20Sopenharmony_ci spin_lock_init(&channel->lock); 10048c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&channel->list); 10058c2ecf20Sopenharmony_ci timer_setup(&channel->delay, usbatm_tasklet_schedule, 0); 10068c2ecf20Sopenharmony_ci} 10078c2ecf20Sopenharmony_ci 10088c2ecf20Sopenharmony_ciint usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id, 10098c2ecf20Sopenharmony_ci struct usbatm_driver *driver) 10108c2ecf20Sopenharmony_ci{ 10118c2ecf20Sopenharmony_ci struct device *dev = &intf->dev; 10128c2ecf20Sopenharmony_ci struct usb_device *usb_dev = interface_to_usbdev(intf); 10138c2ecf20Sopenharmony_ci struct usbatm_data *instance; 10148c2ecf20Sopenharmony_ci char *buf; 10158c2ecf20Sopenharmony_ci int error = -ENOMEM; 10168c2ecf20Sopenharmony_ci int i, length; 10178c2ecf20Sopenharmony_ci unsigned int maxpacket, num_packets; 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_ci /* instance init */ 10208c2ecf20Sopenharmony_ci instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL); 10218c2ecf20Sopenharmony_ci if (!instance) 10228c2ecf20Sopenharmony_ci return -ENOMEM; 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci /* public fields */ 10258c2ecf20Sopenharmony_ci 10268c2ecf20Sopenharmony_ci instance->driver = driver; 10278c2ecf20Sopenharmony_ci strlcpy(instance->driver_name, driver->driver_name, 10288c2ecf20Sopenharmony_ci sizeof(instance->driver_name)); 10298c2ecf20Sopenharmony_ci 10308c2ecf20Sopenharmony_ci instance->usb_dev = usb_dev; 10318c2ecf20Sopenharmony_ci instance->usb_intf = intf; 10328c2ecf20Sopenharmony_ci 10338c2ecf20Sopenharmony_ci buf = instance->description; 10348c2ecf20Sopenharmony_ci length = sizeof(instance->description); 10358c2ecf20Sopenharmony_ci 10368c2ecf20Sopenharmony_ci if ((i = usb_string(usb_dev, usb_dev->descriptor.iProduct, buf, length)) < 0) 10378c2ecf20Sopenharmony_ci goto bind; 10388c2ecf20Sopenharmony_ci 10398c2ecf20Sopenharmony_ci buf += i; 10408c2ecf20Sopenharmony_ci length -= i; 10418c2ecf20Sopenharmony_ci 10428c2ecf20Sopenharmony_ci i = scnprintf(buf, length, " ("); 10438c2ecf20Sopenharmony_ci buf += i; 10448c2ecf20Sopenharmony_ci length -= i; 10458c2ecf20Sopenharmony_ci 10468c2ecf20Sopenharmony_ci if (length <= 0 || (i = usb_make_path(usb_dev, buf, length)) < 0) 10478c2ecf20Sopenharmony_ci goto bind; 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci buf += i; 10508c2ecf20Sopenharmony_ci length -= i; 10518c2ecf20Sopenharmony_ci 10528c2ecf20Sopenharmony_ci snprintf(buf, length, ")"); 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_ci bind: 10558c2ecf20Sopenharmony_ci if (driver->bind && (error = driver->bind(instance, intf, id)) < 0) { 10568c2ecf20Sopenharmony_ci dev_err(dev, "%s: bind failed: %d!\n", __func__, error); 10578c2ecf20Sopenharmony_ci goto fail_free; 10588c2ecf20Sopenharmony_ci } 10598c2ecf20Sopenharmony_ci 10608c2ecf20Sopenharmony_ci /* private fields */ 10618c2ecf20Sopenharmony_ci 10628c2ecf20Sopenharmony_ci kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */ 10638c2ecf20Sopenharmony_ci mutex_init(&instance->serialize); 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_ci instance->thread = NULL; 10668c2ecf20Sopenharmony_ci init_completion(&instance->thread_started); 10678c2ecf20Sopenharmony_ci init_completion(&instance->thread_exited); 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&instance->vcc_list); 10708c2ecf20Sopenharmony_ci skb_queue_head_init(&instance->sndqueue); 10718c2ecf20Sopenharmony_ci 10728c2ecf20Sopenharmony_ci usbatm_init_channel(&instance->rx_channel); 10738c2ecf20Sopenharmony_ci usbatm_init_channel(&instance->tx_channel); 10748c2ecf20Sopenharmony_ci tasklet_setup(&instance->rx_channel.tasklet, usbatm_rx_process); 10758c2ecf20Sopenharmony_ci tasklet_setup(&instance->tx_channel.tasklet, usbatm_tx_process); 10768c2ecf20Sopenharmony_ci instance->rx_channel.stride = ATM_CELL_SIZE + driver->rx_padding; 10778c2ecf20Sopenharmony_ci instance->tx_channel.stride = ATM_CELL_SIZE + driver->tx_padding; 10788c2ecf20Sopenharmony_ci instance->rx_channel.usbatm = instance->tx_channel.usbatm = instance; 10798c2ecf20Sopenharmony_ci 10808c2ecf20Sopenharmony_ci if ((instance->flags & UDSL_USE_ISOC) && driver->isoc_in) 10818c2ecf20Sopenharmony_ci instance->rx_channel.endpoint = usb_rcvisocpipe(usb_dev, driver->isoc_in); 10828c2ecf20Sopenharmony_ci else 10838c2ecf20Sopenharmony_ci instance->rx_channel.endpoint = usb_rcvbulkpipe(usb_dev, driver->bulk_in); 10848c2ecf20Sopenharmony_ci 10858c2ecf20Sopenharmony_ci instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->bulk_out); 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci /* tx buffer size must be a positive multiple of the stride */ 10888c2ecf20Sopenharmony_ci instance->tx_channel.buf_size = max(instance->tx_channel.stride, 10898c2ecf20Sopenharmony_ci snd_buf_bytes - (snd_buf_bytes % instance->tx_channel.stride)); 10908c2ecf20Sopenharmony_ci 10918c2ecf20Sopenharmony_ci /* rx buffer size must be a positive multiple of the endpoint maxpacket */ 10928c2ecf20Sopenharmony_ci maxpacket = usb_maxpacket(usb_dev, instance->rx_channel.endpoint, 0); 10938c2ecf20Sopenharmony_ci 10948c2ecf20Sopenharmony_ci if ((maxpacket < 1) || (maxpacket > UDSL_MAX_BUF_SIZE)) { 10958c2ecf20Sopenharmony_ci dev_err(dev, "%s: invalid endpoint %02x!\n", __func__, 10968c2ecf20Sopenharmony_ci usb_pipeendpoint(instance->rx_channel.endpoint)); 10978c2ecf20Sopenharmony_ci error = -EINVAL; 10988c2ecf20Sopenharmony_ci goto fail_unbind; 10998c2ecf20Sopenharmony_ci } 11008c2ecf20Sopenharmony_ci 11018c2ecf20Sopenharmony_ci num_packets = max(1U, (rcv_buf_bytes + maxpacket / 2) / maxpacket); /* round */ 11028c2ecf20Sopenharmony_ci 11038c2ecf20Sopenharmony_ci if (num_packets * maxpacket > UDSL_MAX_BUF_SIZE) 11048c2ecf20Sopenharmony_ci num_packets--; 11058c2ecf20Sopenharmony_ci 11068c2ecf20Sopenharmony_ci instance->rx_channel.buf_size = num_packets * maxpacket; 11078c2ecf20Sopenharmony_ci instance->rx_channel.packet_size = maxpacket; 11088c2ecf20Sopenharmony_ci 11098c2ecf20Sopenharmony_ci for (i = 0; i < 2; i++) { 11108c2ecf20Sopenharmony_ci struct usbatm_channel *channel = i ? 11118c2ecf20Sopenharmony_ci &instance->tx_channel : &instance->rx_channel; 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_ci dev_dbg(dev, "%s: using %d byte buffer for %s channel 0x%p\n", 11148c2ecf20Sopenharmony_ci __func__, channel->buf_size, i ? "tx" : "rx", channel); 11158c2ecf20Sopenharmony_ci } 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_ci /* initialize urbs */ 11188c2ecf20Sopenharmony_ci 11198c2ecf20Sopenharmony_ci for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) { 11208c2ecf20Sopenharmony_ci u8 *buffer; 11218c2ecf20Sopenharmony_ci struct usbatm_channel *channel = i < num_rcv_urbs ? 11228c2ecf20Sopenharmony_ci &instance->rx_channel : &instance->tx_channel; 11238c2ecf20Sopenharmony_ci struct urb *urb; 11248c2ecf20Sopenharmony_ci unsigned int iso_packets = usb_pipeisoc(channel->endpoint) ? channel->buf_size / channel->packet_size : 0; 11258c2ecf20Sopenharmony_ci 11268c2ecf20Sopenharmony_ci urb = usb_alloc_urb(iso_packets, GFP_KERNEL); 11278c2ecf20Sopenharmony_ci if (!urb) { 11288c2ecf20Sopenharmony_ci error = -ENOMEM; 11298c2ecf20Sopenharmony_ci goto fail_unbind; 11308c2ecf20Sopenharmony_ci } 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_ci instance->urbs[i] = urb; 11338c2ecf20Sopenharmony_ci 11348c2ecf20Sopenharmony_ci /* zero the tx padding to avoid leaking information */ 11358c2ecf20Sopenharmony_ci buffer = kzalloc(channel->buf_size, GFP_KERNEL); 11368c2ecf20Sopenharmony_ci if (!buffer) { 11378c2ecf20Sopenharmony_ci error = -ENOMEM; 11388c2ecf20Sopenharmony_ci goto fail_unbind; 11398c2ecf20Sopenharmony_ci } 11408c2ecf20Sopenharmony_ci 11418c2ecf20Sopenharmony_ci usb_fill_bulk_urb(urb, instance->usb_dev, channel->endpoint, 11428c2ecf20Sopenharmony_ci buffer, channel->buf_size, usbatm_complete, channel); 11438c2ecf20Sopenharmony_ci if (iso_packets) { 11448c2ecf20Sopenharmony_ci int j; 11458c2ecf20Sopenharmony_ci urb->interval = 1; 11468c2ecf20Sopenharmony_ci urb->transfer_flags = URB_ISO_ASAP; 11478c2ecf20Sopenharmony_ci urb->number_of_packets = iso_packets; 11488c2ecf20Sopenharmony_ci for (j = 0; j < iso_packets; j++) { 11498c2ecf20Sopenharmony_ci urb->iso_frame_desc[j].offset = channel->packet_size * j; 11508c2ecf20Sopenharmony_ci urb->iso_frame_desc[j].length = channel->packet_size; 11518c2ecf20Sopenharmony_ci } 11528c2ecf20Sopenharmony_ci } 11538c2ecf20Sopenharmony_ci 11548c2ecf20Sopenharmony_ci /* put all tx URBs on the list of spares */ 11558c2ecf20Sopenharmony_ci if (i >= num_rcv_urbs) 11568c2ecf20Sopenharmony_ci list_add_tail(&urb->urb_list, &channel->list); 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci vdbg(&intf->dev, "%s: alloced buffer 0x%p buf size %u urb 0x%p", 11598c2ecf20Sopenharmony_ci __func__, urb->transfer_buffer, urb->transfer_buffer_length, urb); 11608c2ecf20Sopenharmony_ci } 11618c2ecf20Sopenharmony_ci 11628c2ecf20Sopenharmony_ci instance->cached_vpi = ATM_VPI_UNSPEC; 11638c2ecf20Sopenharmony_ci instance->cached_vci = ATM_VCI_UNSPEC; 11648c2ecf20Sopenharmony_ci instance->cell_buf = kmalloc(instance->rx_channel.stride, GFP_KERNEL); 11658c2ecf20Sopenharmony_ci 11668c2ecf20Sopenharmony_ci if (!instance->cell_buf) { 11678c2ecf20Sopenharmony_ci error = -ENOMEM; 11688c2ecf20Sopenharmony_ci goto fail_unbind; 11698c2ecf20Sopenharmony_ci } 11708c2ecf20Sopenharmony_ci 11718c2ecf20Sopenharmony_ci if (!(instance->flags & UDSL_SKIP_HEAVY_INIT) && driver->heavy_init) { 11728c2ecf20Sopenharmony_ci error = usbatm_heavy_init(instance); 11738c2ecf20Sopenharmony_ci } else { 11748c2ecf20Sopenharmony_ci complete(&instance->thread_exited); /* pretend that heavy_init was run */ 11758c2ecf20Sopenharmony_ci error = usbatm_atm_init(instance); 11768c2ecf20Sopenharmony_ci } 11778c2ecf20Sopenharmony_ci 11788c2ecf20Sopenharmony_ci if (error < 0) 11798c2ecf20Sopenharmony_ci goto fail_unbind; 11808c2ecf20Sopenharmony_ci 11818c2ecf20Sopenharmony_ci usb_get_dev(usb_dev); 11828c2ecf20Sopenharmony_ci usb_set_intfdata(intf, instance); 11838c2ecf20Sopenharmony_ci 11848c2ecf20Sopenharmony_ci return 0; 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci fail_unbind: 11878c2ecf20Sopenharmony_ci if (instance->driver->unbind) 11888c2ecf20Sopenharmony_ci instance->driver->unbind(instance, intf); 11898c2ecf20Sopenharmony_ci fail_free: 11908c2ecf20Sopenharmony_ci kfree(instance->cell_buf); 11918c2ecf20Sopenharmony_ci 11928c2ecf20Sopenharmony_ci for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) { 11938c2ecf20Sopenharmony_ci if (instance->urbs[i]) 11948c2ecf20Sopenharmony_ci kfree(instance->urbs[i]->transfer_buffer); 11958c2ecf20Sopenharmony_ci usb_free_urb(instance->urbs[i]); 11968c2ecf20Sopenharmony_ci } 11978c2ecf20Sopenharmony_ci 11988c2ecf20Sopenharmony_ci kfree(instance); 11998c2ecf20Sopenharmony_ci 12008c2ecf20Sopenharmony_ci return error; 12018c2ecf20Sopenharmony_ci} 12028c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(usbatm_usb_probe); 12038c2ecf20Sopenharmony_ci 12048c2ecf20Sopenharmony_civoid usbatm_usb_disconnect(struct usb_interface *intf) 12058c2ecf20Sopenharmony_ci{ 12068c2ecf20Sopenharmony_ci struct device *dev = &intf->dev; 12078c2ecf20Sopenharmony_ci struct usbatm_data *instance = usb_get_intfdata(intf); 12088c2ecf20Sopenharmony_ci struct usbatm_vcc_data *vcc_data; 12098c2ecf20Sopenharmony_ci int i; 12108c2ecf20Sopenharmony_ci 12118c2ecf20Sopenharmony_ci if (!instance) { 12128c2ecf20Sopenharmony_ci dev_dbg(dev, "%s: NULL instance!\n", __func__); 12138c2ecf20Sopenharmony_ci return; 12148c2ecf20Sopenharmony_ci } 12158c2ecf20Sopenharmony_ci 12168c2ecf20Sopenharmony_ci usb_set_intfdata(intf, NULL); 12178c2ecf20Sopenharmony_ci 12188c2ecf20Sopenharmony_ci mutex_lock(&instance->serialize); 12198c2ecf20Sopenharmony_ci instance->disconnected = 1; 12208c2ecf20Sopenharmony_ci if (instance->thread != NULL) 12218c2ecf20Sopenharmony_ci send_sig(SIGTERM, instance->thread, 1); 12228c2ecf20Sopenharmony_ci mutex_unlock(&instance->serialize); 12238c2ecf20Sopenharmony_ci 12248c2ecf20Sopenharmony_ci wait_for_completion(&instance->thread_exited); 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_ci mutex_lock(&instance->serialize); 12278c2ecf20Sopenharmony_ci list_for_each_entry(vcc_data, &instance->vcc_list, list) 12288c2ecf20Sopenharmony_ci vcc_release_async(vcc_data->vcc, -EPIPE); 12298c2ecf20Sopenharmony_ci mutex_unlock(&instance->serialize); 12308c2ecf20Sopenharmony_ci 12318c2ecf20Sopenharmony_ci tasklet_disable(&instance->rx_channel.tasklet); 12328c2ecf20Sopenharmony_ci tasklet_disable(&instance->tx_channel.tasklet); 12338c2ecf20Sopenharmony_ci 12348c2ecf20Sopenharmony_ci for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) 12358c2ecf20Sopenharmony_ci usb_kill_urb(instance->urbs[i]); 12368c2ecf20Sopenharmony_ci 12378c2ecf20Sopenharmony_ci del_timer_sync(&instance->rx_channel.delay); 12388c2ecf20Sopenharmony_ci del_timer_sync(&instance->tx_channel.delay); 12398c2ecf20Sopenharmony_ci 12408c2ecf20Sopenharmony_ci /* turn usbatm_[rt]x_process into something close to a no-op */ 12418c2ecf20Sopenharmony_ci /* no need to take the spinlock */ 12428c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&instance->rx_channel.list); 12438c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&instance->tx_channel.list); 12448c2ecf20Sopenharmony_ci 12458c2ecf20Sopenharmony_ci tasklet_enable(&instance->rx_channel.tasklet); 12468c2ecf20Sopenharmony_ci tasklet_enable(&instance->tx_channel.tasklet); 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_ci if (instance->atm_dev && instance->driver->atm_stop) 12498c2ecf20Sopenharmony_ci instance->driver->atm_stop(instance, instance->atm_dev); 12508c2ecf20Sopenharmony_ci 12518c2ecf20Sopenharmony_ci if (instance->driver->unbind) 12528c2ecf20Sopenharmony_ci instance->driver->unbind(instance, intf); 12538c2ecf20Sopenharmony_ci 12548c2ecf20Sopenharmony_ci instance->driver_data = NULL; 12558c2ecf20Sopenharmony_ci 12568c2ecf20Sopenharmony_ci for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) { 12578c2ecf20Sopenharmony_ci kfree(instance->urbs[i]->transfer_buffer); 12588c2ecf20Sopenharmony_ci usb_free_urb(instance->urbs[i]); 12598c2ecf20Sopenharmony_ci } 12608c2ecf20Sopenharmony_ci 12618c2ecf20Sopenharmony_ci kfree(instance->cell_buf); 12628c2ecf20Sopenharmony_ci 12638c2ecf20Sopenharmony_ci /* ATM finalize */ 12648c2ecf20Sopenharmony_ci if (instance->atm_dev) { 12658c2ecf20Sopenharmony_ci atm_dev_deregister(instance->atm_dev); 12668c2ecf20Sopenharmony_ci instance->atm_dev = NULL; 12678c2ecf20Sopenharmony_ci } 12688c2ecf20Sopenharmony_ci 12698c2ecf20Sopenharmony_ci usbatm_put_instance(instance); /* taken in usbatm_usb_probe */ 12708c2ecf20Sopenharmony_ci} 12718c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(usbatm_usb_disconnect); 12728c2ecf20Sopenharmony_ci 12738c2ecf20Sopenharmony_ci 12748c2ecf20Sopenharmony_ci/*********** 12758c2ecf20Sopenharmony_ci** init ** 12768c2ecf20Sopenharmony_ci***********/ 12778c2ecf20Sopenharmony_ci 12788c2ecf20Sopenharmony_cistatic int __init usbatm_usb_init(void) 12798c2ecf20Sopenharmony_ci{ 12808c2ecf20Sopenharmony_ci if (sizeof(struct usbatm_control) > sizeof_field(struct sk_buff, cb)) { 12818c2ecf20Sopenharmony_ci printk(KERN_ERR "%s unusable with this kernel!\n", usbatm_driver_name); 12828c2ecf20Sopenharmony_ci return -EIO; 12838c2ecf20Sopenharmony_ci } 12848c2ecf20Sopenharmony_ci 12858c2ecf20Sopenharmony_ci if ((num_rcv_urbs > UDSL_MAX_RCV_URBS) 12868c2ecf20Sopenharmony_ci || (num_snd_urbs > UDSL_MAX_SND_URBS) 12878c2ecf20Sopenharmony_ci || (rcv_buf_bytes < 1) 12888c2ecf20Sopenharmony_ci || (rcv_buf_bytes > UDSL_MAX_BUF_SIZE) 12898c2ecf20Sopenharmony_ci || (snd_buf_bytes < 1) 12908c2ecf20Sopenharmony_ci || (snd_buf_bytes > UDSL_MAX_BUF_SIZE)) 12918c2ecf20Sopenharmony_ci return -EINVAL; 12928c2ecf20Sopenharmony_ci 12938c2ecf20Sopenharmony_ci return 0; 12948c2ecf20Sopenharmony_ci} 12958c2ecf20Sopenharmony_cimodule_init(usbatm_usb_init); 12968c2ecf20Sopenharmony_ci 12978c2ecf20Sopenharmony_cistatic void __exit usbatm_usb_exit(void) 12988c2ecf20Sopenharmony_ci{ 12998c2ecf20Sopenharmony_ci} 13008c2ecf20Sopenharmony_cimodule_exit(usbatm_usb_exit); 13018c2ecf20Sopenharmony_ci 13028c2ecf20Sopenharmony_ciMODULE_AUTHOR(DRIVER_AUTHOR); 13038c2ecf20Sopenharmony_ciMODULE_DESCRIPTION(DRIVER_DESC); 13048c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 13058c2ecf20Sopenharmony_ci 13068c2ecf20Sopenharmony_ci/************ 13078c2ecf20Sopenharmony_ci** debug ** 13088c2ecf20Sopenharmony_ci************/ 13098c2ecf20Sopenharmony_ci 13108c2ecf20Sopenharmony_ci#ifdef VERBOSE_DEBUG 13118c2ecf20Sopenharmony_cistatic int usbatm_print_packet(struct usbatm_data *instance, 13128c2ecf20Sopenharmony_ci const unsigned char *data, int len) 13138c2ecf20Sopenharmony_ci{ 13148c2ecf20Sopenharmony_ci unsigned char buffer[256]; 13158c2ecf20Sopenharmony_ci int i = 0, j = 0; 13168c2ecf20Sopenharmony_ci 13178c2ecf20Sopenharmony_ci for (i = 0; i < len;) { 13188c2ecf20Sopenharmony_ci buffer[0] = '\0'; 13198c2ecf20Sopenharmony_ci sprintf(buffer, "%.3d :", i); 13208c2ecf20Sopenharmony_ci for (j = 0; (j < 16) && (i < len); j++, i++) 13218c2ecf20Sopenharmony_ci sprintf(buffer, "%s %2.2x", buffer, data[i]); 13228c2ecf20Sopenharmony_ci dev_dbg(&instance->usb_intf->dev, "%s", buffer); 13238c2ecf20Sopenharmony_ci } 13248c2ecf20Sopenharmony_ci return i; 13258c2ecf20Sopenharmony_ci} 13268c2ecf20Sopenharmony_ci#endif 1327