usbatm.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. /******************************************************************************
  2. * usbatm.c - Generic USB xDSL driver core
  3. *
  4. * Copyright (C) 2001, Alcatel
  5. * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
  6. * Copyright (C) 2004, David Woodhouse, Roman Kagan
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, write to the Free Software Foundation, Inc., 59
  20. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. *
  22. ******************************************************************************/
  23. /*
  24. * Written by Johan Verrept, Duncan Sands (duncan.sands@free.fr) and David Woodhouse
  25. *
  26. * 1.7+: - See the check-in logs
  27. *
  28. * 1.6: - No longer opens a connection if the firmware is not loaded
  29. * - Added support for the speedtouch 330
  30. * - Removed the limit on the number of devices
  31. * - Module now autoloads on device plugin
  32. * - Merged relevant parts of sarlib
  33. * - Replaced the kernel thread with a tasklet
  34. * - New packet transmission code
  35. * - Changed proc file contents
  36. * - Fixed all known SMP races
  37. * - Many fixes and cleanups
  38. * - Various fixes by Oliver Neukum (oliver@neukum.name)
  39. *
  40. * 1.5A: - Version for inclusion in 2.5 series kernel
  41. * - Modifications by Richard Purdie (rpurdie@rpsys.net)
  42. * - made compatible with kernel 2.5.6 onwards by changing
  43. * usbatm_usb_send_data_context->urb to a pointer and adding code
  44. * to alloc and free it
  45. * - remove_wait_queue() added to usbatm_atm_processqueue_thread()
  46. *
  47. * 1.5: - fixed memory leak when atmsar_decode_aal5 returned NULL.
  48. * (reported by stephen.robinson@zen.co.uk)
  49. *
  50. * 1.4: - changed the spin_lock() under interrupt to spin_lock_irqsave()
  51. * - unlink all active send urbs of a vcc that is being closed.
  52. *
  53. * 1.3.1: - added the version number
  54. *
  55. * 1.3: - Added multiple send urb support
  56. * - fixed memory leak and vcc->tx_inuse starvation bug
  57. * when not enough memory left in vcc.
  58. *
  59. * 1.2: - Fixed race condition in usbatm_usb_send_data()
  60. * 1.1: - Turned off packet debugging
  61. *
  62. */
  63. #include "usbatm.h"
  64. #include <asm/uaccess.h>
  65. #include <linux/crc32.h>
  66. #include <linux/errno.h>
  67. #include <linux/init.h>
  68. #include <linux/interrupt.h>
  69. #include <linux/kernel.h>
  70. #include <linux/module.h>
  71. #include <linux/moduleparam.h>
  72. #include <linux/proc_fs.h>
  73. #include <linux/sched.h>
  74. #include <linux/signal.h>
  75. #include <linux/slab.h>
  76. #include <linux/smp_lock.h>
  77. #include <linux/stat.h>
  78. #include <linux/timer.h>
  79. #include <linux/wait.h>
  80. #ifdef VERBOSE_DEBUG
  81. static int usbatm_print_packet(const unsigned char *data, int len);
  82. #define PACKETDEBUG(arg...) usbatm_print_packet (arg)
  83. #define vdbg(arg...) dbg (arg)
  84. #else
  85. #define PACKETDEBUG(arg...)
  86. #define vdbg(arg...)
  87. #endif
  88. #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
  89. #define DRIVER_VERSION "1.9"
  90. #define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION
  91. static const char usbatm_driver_name[] = "usbatm";
  92. #define UDSL_MAX_RCV_URBS 16
  93. #define UDSL_MAX_SND_URBS 16
  94. #define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */
  95. #define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */
  96. #define UDSL_DEFAULT_RCV_URBS 4
  97. #define UDSL_DEFAULT_SND_URBS 4
  98. #define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */
  99. #define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */
  100. #define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
  101. #define THROTTLE_MSECS 100 /* delay to recover processing after urb submission fails */
  102. static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS;
  103. static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS;
  104. static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE;
  105. static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE;
  106. module_param(num_rcv_urbs, uint, S_IRUGO);
  107. MODULE_PARM_DESC(num_rcv_urbs,
  108. "Number of urbs used for reception (range: 0-"
  109. __MODULE_STRING(UDSL_MAX_RCV_URBS) ", default: "
  110. __MODULE_STRING(UDSL_DEFAULT_RCV_URBS) ")");
  111. module_param(num_snd_urbs, uint, S_IRUGO);
  112. MODULE_PARM_DESC(num_snd_urbs,
  113. "Number of urbs used for transmission (range: 0-"
  114. __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: "
  115. __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")");
  116. module_param(rcv_buf_size, uint, S_IRUGO);
  117. MODULE_PARM_DESC(rcv_buf_size,
  118. "Size of the buffers used for reception in ATM cells (range: 1-"
  119. __MODULE_STRING(UDSL_MAX_RCV_BUF_SIZE) ", default: "
  120. __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")");
  121. module_param(snd_buf_size, uint, S_IRUGO);
  122. MODULE_PARM_DESC(snd_buf_size,
  123. "Size of the buffers used for transmission in ATM cells (range: 1-"
  124. __MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: "
  125. __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")");
  126. /* receive */
  127. struct usbatm_vcc_data {
  128. /* vpi/vci lookup */
  129. struct list_head list;
  130. short vpi;
  131. int vci;
  132. struct atm_vcc *vcc;
  133. /* raw cell reassembly */
  134. struct sk_buff *sarb;
  135. };
  136. /* send */
  137. struct usbatm_control {
  138. struct atm_skb_data atm;
  139. u32 len;
  140. u32 crc;
  141. };
  142. #define UDSL_SKB(x) ((struct usbatm_control *)(x)->cb)
  143. /* ATM */
  144. static void usbatm_atm_dev_close(struct atm_dev *atm_dev);
  145. static int usbatm_atm_open(struct atm_vcc *vcc);
  146. static void usbatm_atm_close(struct atm_vcc *vcc);
  147. static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, void __user * arg);
  148. static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb);
  149. static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page);
  150. static struct atmdev_ops usbatm_atm_devops = {
  151. .dev_close = usbatm_atm_dev_close,
  152. .open = usbatm_atm_open,
  153. .close = usbatm_atm_close,
  154. .ioctl = usbatm_atm_ioctl,
  155. .send = usbatm_atm_send,
  156. .proc_read = usbatm_atm_proc_read,
  157. .owner = THIS_MODULE,
  158. };
  159. /***********
  160. ** misc **
  161. ***********/
  162. static inline unsigned int usbatm_pdu_length(unsigned int length)
  163. {
  164. length += ATM_CELL_PAYLOAD - 1 + ATM_AAL5_TRAILER;
  165. return length - length % ATM_CELL_PAYLOAD;
  166. }
  167. static inline void usbatm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
  168. {
  169. if (vcc->pop)
  170. vcc->pop(vcc, skb);
  171. else
  172. dev_kfree_skb(skb);
  173. }
  174. /***********
  175. ** urbs **
  176. ************/
  177. static struct urb *usbatm_pop_urb(struct usbatm_channel *channel)
  178. {
  179. struct urb *urb;
  180. spin_lock_irq(&channel->lock);
  181. if (list_empty(&channel->list)) {
  182. spin_unlock_irq(&channel->lock);
  183. return NULL;
  184. }
  185. urb = list_entry(channel->list.next, struct urb, urb_list);
  186. list_del(&urb->urb_list);
  187. spin_unlock_irq(&channel->lock);
  188. return urb;
  189. }
  190. static int usbatm_submit_urb(struct urb *urb)
  191. {
  192. struct usbatm_channel *channel = urb->context;
  193. int ret;
  194. vdbg("%s: submitting urb 0x%p, size %u",
  195. __func__, urb, urb->transfer_buffer_length);
  196. ret = usb_submit_urb(urb, GFP_ATOMIC);
  197. if (ret) {
  198. if (printk_ratelimit())
  199. atm_warn(channel->usbatm, "%s: urb 0x%p submission failed (%d)!\n",
  200. __func__, urb, ret);
  201. /* consider all errors transient and return the buffer back to the queue */
  202. urb->status = -EAGAIN;
  203. spin_lock_irq(&channel->lock);
  204. /* must add to the front when sending; doesn't matter when receiving */
  205. list_add(&urb->urb_list, &channel->list);
  206. spin_unlock_irq(&channel->lock);
  207. /* make sure the channel doesn't stall */
  208. mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
  209. }
  210. return ret;
  211. }
  212. static void usbatm_complete(struct urb *urb, struct pt_regs *regs)
  213. {
  214. struct usbatm_channel *channel = urb->context;
  215. unsigned long flags;
  216. vdbg("%s: urb 0x%p, status %d, actual_length %d",
  217. __func__, urb, urb->status, urb->actual_length);
  218. /* usually in_interrupt(), but not always */
  219. spin_lock_irqsave(&channel->lock, flags);
  220. /* must add to the back when receiving; doesn't matter when sending */
  221. list_add_tail(&urb->urb_list, &channel->list);
  222. spin_unlock_irqrestore(&channel->lock, flags);
  223. if (unlikely(urb->status)) {
  224. if (printk_ratelimit())
  225. atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n",
  226. __func__, urb, urb->status);
  227. /* throttle processing in case of an error */
  228. mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
  229. } else
  230. tasklet_schedule(&channel->tasklet);
  231. }
  232. /*************
  233. ** decode **
  234. *************/
  235. static inline struct usbatm_vcc_data *usbatm_find_vcc(struct usbatm_data *instance,
  236. short vpi, int vci)
  237. {
  238. struct usbatm_vcc_data *vcc_data;
  239. list_for_each_entry(vcc_data, &instance->vcc_list, list)
  240. if ((vcc_data->vci == vci) && (vcc_data->vpi == vpi))
  241. return vcc_data;
  242. return NULL;
  243. }
  244. static void usbatm_extract_cells(struct usbatm_data *instance,
  245. unsigned char *source, unsigned int avail_data)
  246. {
  247. struct usbatm_vcc_data *cached_vcc = NULL;
  248. struct atm_vcc *vcc;
  249. struct sk_buff *sarb;
  250. unsigned int stride = instance->rx_channel.stride;
  251. int vci, cached_vci = 0;
  252. short vpi, cached_vpi = 0;
  253. u8 pti;
  254. for (; avail_data >= stride; avail_data -= stride, source += stride) {
  255. vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4);
  256. vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4);
  257. pti = ((source[3] & 0xe) >> 1);
  258. vdbg("%s: vpi %hd, vci %d, pti %d", __func__, vpi, vci, pti);
  259. if ((vci != cached_vci) || (vpi != cached_vpi)) {
  260. cached_vpi = vpi;
  261. cached_vci = vci;
  262. cached_vcc = usbatm_find_vcc(instance, vpi, vci);
  263. if (!cached_vcc)
  264. atm_rldbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci);
  265. }
  266. if (!cached_vcc)
  267. continue;
  268. vcc = cached_vcc->vcc;
  269. /* OAM F5 end-to-end */
  270. if (pti == ATM_PTI_E2EF5) {
  271. if (printk_ratelimit())
  272. atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
  273. __func__, vpi, vci);
  274. atomic_inc(&vcc->stats->rx_err);
  275. continue;
  276. }
  277. sarb = cached_vcc->sarb;
  278. if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) {
  279. atm_rldbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n",
  280. __func__, sarb->len, vcc);
  281. /* discard cells already received */
  282. skb_trim(sarb, 0);
  283. UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end);
  284. }
  285. memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
  286. __skb_put(sarb, ATM_CELL_PAYLOAD);
  287. if (pti & 1) {
  288. struct sk_buff *skb;
  289. unsigned int length;
  290. unsigned int pdu_length;
  291. length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5];
  292. /* guard against overflow */
  293. if (length > ATM_MAX_AAL5_PDU) {
  294. atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
  295. __func__, length, vcc);
  296. atomic_inc(&vcc->stats->rx_err);
  297. goto out;
  298. }
  299. pdu_length = usbatm_pdu_length(length);
  300. if (sarb->len < pdu_length) {
  301. atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
  302. __func__, pdu_length, sarb->len, vcc);
  303. atomic_inc(&vcc->stats->rx_err);
  304. goto out;
  305. }
  306. if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
  307. atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
  308. __func__, vcc);
  309. atomic_inc(&vcc->stats->rx_err);
  310. goto out;
  311. }
  312. vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", __func__, length, pdu_length, vcc);
  313. if (!(skb = dev_alloc_skb(length))) {
  314. if (printk_ratelimit())
  315. atm_err(instance, "%s: no memory for skb (length: %u)!\n",
  316. __func__, length);
  317. atomic_inc(&vcc->stats->rx_drop);
  318. goto out;
  319. }
  320. vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", __func__, skb, skb->truesize);
  321. if (!atm_charge(vcc, skb->truesize)) {
  322. atm_rldbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n",
  323. __func__, skb->truesize);
  324. dev_kfree_skb(skb);
  325. goto out; /* atm_charge increments rx_drop */
  326. }
  327. memcpy(skb->data, sarb->tail - pdu_length, length);
  328. __skb_put(skb, length);
  329. vdbg("%s: sending skb 0x%p, skb->len %u, skb->truesize %u",
  330. __func__, skb, skb->len, skb->truesize);
  331. PACKETDEBUG(skb->data, skb->len);
  332. vcc->push(vcc, skb);
  333. atomic_inc(&vcc->stats->rx);
  334. out:
  335. skb_trim(sarb, 0);
  336. }
  337. }
  338. }
  339. /*************
  340. ** encode **
  341. *************/
  342. static unsigned int usbatm_write_cells(struct usbatm_data *instance,
  343. struct sk_buff *skb,
  344. u8 *target, unsigned int avail_space)
  345. {
  346. struct usbatm_control *ctrl = UDSL_SKB(skb);
  347. struct atm_vcc *vcc = ctrl->atm.vcc;
  348. unsigned int num_written;
  349. unsigned int stride = instance->tx_channel.stride;
  350. vdbg("%s: skb->len=%d, avail_space=%u", __func__, skb->len, avail_space);
  351. UDSL_ASSERT(!(avail_space % stride));
  352. for (num_written = 0; num_written < avail_space && ctrl->len;
  353. num_written += stride, target += stride) {
  354. unsigned int data_len = min_t(unsigned int, skb->len, ATM_CELL_PAYLOAD);
  355. unsigned int left = ATM_CELL_PAYLOAD - data_len;
  356. u8 *ptr = target;
  357. ptr[0] = vcc->vpi >> 4;
  358. ptr[1] = (vcc->vpi << 4) | (vcc->vci >> 12);
  359. ptr[2] = vcc->vci >> 4;
  360. ptr[3] = vcc->vci << 4;
  361. ptr[4] = 0xec;
  362. ptr += ATM_CELL_HEADER;
  363. memcpy(ptr, skb->data, data_len);
  364. ptr += data_len;
  365. __skb_pull(skb, data_len);
  366. if(!left)
  367. continue;
  368. memset(ptr, 0, left);
  369. if (left >= ATM_AAL5_TRAILER) { /* trailer will go in this cell */
  370. u8 *trailer = target + ATM_CELL_SIZE - ATM_AAL5_TRAILER;
  371. /* trailer[0] = 0; UU = 0 */
  372. /* trailer[1] = 0; CPI = 0 */
  373. trailer[2] = ctrl->len >> 8;
  374. trailer[3] = ctrl->len;
  375. ctrl->crc = ~ crc32_be(ctrl->crc, ptr, left - 4);
  376. trailer[4] = ctrl->crc >> 24;
  377. trailer[5] = ctrl->crc >> 16;
  378. trailer[6] = ctrl->crc >> 8;
  379. trailer[7] = ctrl->crc;
  380. target[3] |= 0x2; /* adjust PTI */
  381. ctrl->len = 0; /* tag this skb finished */
  382. }
  383. else
  384. ctrl->crc = crc32_be(ctrl->crc, ptr, left);
  385. }
  386. return num_written;
  387. }
  388. /**************
  389. ** receive **
  390. **************/
  391. static void usbatm_rx_process(unsigned long data)
  392. {
  393. struct usbatm_data *instance = (struct usbatm_data *)data;
  394. struct urb *urb;
  395. while ((urb = usbatm_pop_urb(&instance->rx_channel))) {
  396. vdbg("%s: processing urb 0x%p", __func__, urb);
  397. if (usb_pipeisoc(urb->pipe)) {
  398. int i;
  399. for (i = 0; i < urb->number_of_packets; i++)
  400. if (!urb->iso_frame_desc[i].status)
  401. usbatm_extract_cells(instance,
  402. (u8 *)urb->transfer_buffer + urb->iso_frame_desc[i].offset,
  403. urb->iso_frame_desc[i].actual_length);
  404. }
  405. else
  406. if (!urb->status)
  407. usbatm_extract_cells(instance, urb->transfer_buffer, urb->actual_length);
  408. if (usbatm_submit_urb(urb))
  409. return;
  410. }
  411. }
  412. /***********
  413. ** send **
  414. ***********/
  415. static void usbatm_tx_process(unsigned long data)
  416. {
  417. struct usbatm_data *instance = (struct usbatm_data *)data;
  418. struct sk_buff *skb = instance->current_skb;
  419. struct urb *urb = NULL;
  420. const unsigned int buf_size = instance->tx_channel.buf_size;
  421. unsigned int num_written = 0;
  422. u8 *buffer = NULL;
  423. if (!skb)
  424. skb = skb_dequeue(&instance->sndqueue);
  425. while (skb) {
  426. if (!urb) {
  427. urb = usbatm_pop_urb(&instance->tx_channel);
  428. if (!urb)
  429. break; /* no more senders */
  430. buffer = urb->transfer_buffer;
  431. num_written = (urb->status == -EAGAIN) ?
  432. urb->transfer_buffer_length : 0;
  433. }
  434. num_written += usbatm_write_cells(instance, skb,
  435. buffer + num_written,
  436. buf_size - num_written);
  437. vdbg("%s: wrote %u bytes from skb 0x%p to urb 0x%p",
  438. __func__, num_written, skb, urb);
  439. if (!UDSL_SKB(skb)->len) {
  440. struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
  441. usbatm_pop(vcc, skb);
  442. atomic_inc(&vcc->stats->tx);
  443. skb = skb_dequeue(&instance->sndqueue);
  444. }
  445. if (num_written == buf_size || (!skb && num_written)) {
  446. urb->transfer_buffer_length = num_written;
  447. if (usbatm_submit_urb(urb))
  448. break;
  449. urb = NULL;
  450. }
  451. }
  452. instance->current_skb = skb;
  453. }
  454. static void usbatm_cancel_send(struct usbatm_data *instance,
  455. struct atm_vcc *vcc)
  456. {
  457. struct sk_buff *skb, *n;
  458. atm_dbg(instance, "%s entered\n", __func__);
  459. spin_lock_irq(&instance->sndqueue.lock);
  460. for (skb = instance->sndqueue.next, n = skb->next;
  461. skb != (struct sk_buff *)&instance->sndqueue;
  462. skb = n, n = skb->next)
  463. if (UDSL_SKB(skb)->atm.vcc == vcc) {
  464. atm_dbg(instance, "%s: popping skb 0x%p\n", __func__, skb);
  465. __skb_unlink(skb, &instance->sndqueue);
  466. usbatm_pop(vcc, skb);
  467. }
  468. spin_unlock_irq(&instance->sndqueue.lock);
  469. tasklet_disable(&instance->tx_channel.tasklet);
  470. if ((skb = instance->current_skb) && (UDSL_SKB(skb)->atm.vcc == vcc)) {
  471. atm_dbg(instance, "%s: popping current skb (0x%p)\n", __func__, skb);
  472. instance->current_skb = NULL;
  473. usbatm_pop(vcc, skb);
  474. }
  475. tasklet_enable(&instance->tx_channel.tasklet);
  476. atm_dbg(instance, "%s done\n", __func__);
  477. }
  478. static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
  479. {
  480. struct usbatm_data *instance = vcc->dev->dev_data;
  481. struct usbatm_control *ctrl = UDSL_SKB(skb);
  482. int err;
  483. vdbg("%s called (skb 0x%p, len %u)", __func__, skb, skb->len);
  484. /* racy disconnection check - fine */
  485. if (!instance || instance->disconnected) {
  486. #ifdef DEBUG
  487. if (printk_ratelimit())
  488. printk(KERN_DEBUG "%s: %s!\n", __func__, instance ? "disconnected" : "NULL instance");
  489. #endif
  490. err = -ENODEV;
  491. goto fail;
  492. }
  493. if (vcc->qos.aal != ATM_AAL5) {
  494. atm_rldbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
  495. err = -EINVAL;
  496. goto fail;
  497. }
  498. if (skb->len > ATM_MAX_AAL5_PDU) {
  499. atm_rldbg(instance, "%s: packet too long (%d vs %d)!\n",
  500. __func__, skb->len, ATM_MAX_AAL5_PDU);
  501. err = -EINVAL;
  502. goto fail;
  503. }
  504. PACKETDEBUG(skb->data, skb->len);
  505. /* initialize the control block */
  506. ctrl->atm.vcc = vcc;
  507. ctrl->len = skb->len;
  508. ctrl->crc = crc32_be(~0, skb->data, skb->len);
  509. skb_queue_tail(&instance->sndqueue, skb);
  510. tasklet_schedule(&instance->tx_channel.tasklet);
  511. return 0;
  512. fail:
  513. usbatm_pop(vcc, skb);
  514. return err;
  515. }
  516. /********************
  517. ** bean counting **
  518. ********************/
  519. static void usbatm_destroy_instance(struct kref *kref)
  520. {
  521. struct usbatm_data *instance = container_of(kref, struct usbatm_data, refcount);
  522. dbg("%s", __func__);
  523. tasklet_kill(&instance->rx_channel.tasklet);
  524. tasklet_kill(&instance->tx_channel.tasklet);
  525. usb_put_dev(instance->usb_dev);
  526. kfree(instance);
  527. }
  528. static void usbatm_get_instance(struct usbatm_data *instance)
  529. {
  530. dbg("%s", __func__);
  531. kref_get(&instance->refcount);
  532. }
  533. static void usbatm_put_instance(struct usbatm_data *instance)
  534. {
  535. dbg("%s", __func__);
  536. kref_put(&instance->refcount, usbatm_destroy_instance);
  537. }
  538. /**********
  539. ** ATM **
  540. **********/
  541. static void usbatm_atm_dev_close(struct atm_dev *atm_dev)
  542. {
  543. struct usbatm_data *instance = atm_dev->dev_data;
  544. dbg("%s", __func__);
  545. if (!instance)
  546. return;
  547. atm_dev->dev_data = NULL; /* catch bugs */
  548. usbatm_put_instance(instance); /* taken in usbatm_atm_init */
  549. }
  550. static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page)
  551. {
  552. struct usbatm_data *instance = atm_dev->dev_data;
  553. int left = *pos;
  554. if (!instance) {
  555. dbg("%s: NULL instance!", __func__);
  556. return -ENODEV;
  557. }
  558. if (!left--)
  559. return sprintf(page, "%s\n", instance->description);
  560. if (!left--)
  561. return sprintf(page, "MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
  562. atm_dev->esi[0], atm_dev->esi[1],
  563. atm_dev->esi[2], atm_dev->esi[3],
  564. atm_dev->esi[4], atm_dev->esi[5]);
  565. if (!left--)
  566. return sprintf(page,
  567. "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
  568. atomic_read(&atm_dev->stats.aal5.tx),
  569. atomic_read(&atm_dev->stats.aal5.tx_err),
  570. atomic_read(&atm_dev->stats.aal5.rx),
  571. atomic_read(&atm_dev->stats.aal5.rx_err),
  572. atomic_read(&atm_dev->stats.aal5.rx_drop));
  573. if (!left--) {
  574. if (instance->disconnected)
  575. return sprintf(page, "Disconnected\n");
  576. else
  577. switch (atm_dev->signal) {
  578. case ATM_PHY_SIG_FOUND:
  579. return sprintf(page, "Line up\n");
  580. case ATM_PHY_SIG_LOST:
  581. return sprintf(page, "Line down\n");
  582. default:
  583. return sprintf(page, "Line state unknown\n");
  584. }
  585. }
  586. return 0;
  587. }
  588. static int usbatm_atm_open(struct atm_vcc *vcc)
  589. {
  590. struct usbatm_data *instance = vcc->dev->dev_data;
  591. struct usbatm_vcc_data *new = NULL;
  592. int ret;
  593. int vci = vcc->vci;
  594. short vpi = vcc->vpi;
  595. if (!instance) {
  596. dbg("%s: NULL data!", __func__);
  597. return -ENODEV;
  598. }
  599. atm_dbg(instance, "%s: vpi %hd, vci %d\n", __func__, vpi, vci);
  600. /* only support AAL5 */
  601. if ((vcc->qos.aal != ATM_AAL5)) {
  602. atm_warn(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
  603. return -EINVAL;
  604. }
  605. /* sanity checks */
  606. if ((vcc->qos.rxtp.max_sdu < 0) || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) {
  607. atm_dbg(instance, "%s: max_sdu %d out of range!\n", __func__, vcc->qos.rxtp.max_sdu);
  608. return -EINVAL;
  609. }
  610. down(&instance->serialize); /* vs self, usbatm_atm_close, usbatm_usb_disconnect */
  611. if (instance->disconnected) {
  612. atm_dbg(instance, "%s: disconnected!\n", __func__);
  613. ret = -ENODEV;
  614. goto fail;
  615. }
  616. if (usbatm_find_vcc(instance, vpi, vci)) {
  617. atm_dbg(instance, "%s: %hd/%d already in use!\n", __func__, vpi, vci);
  618. ret = -EADDRINUSE;
  619. goto fail;
  620. }
  621. if (!(new = kzalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL))) {
  622. atm_err(instance, "%s: no memory for vcc_data!\n", __func__);
  623. ret = -ENOMEM;
  624. goto fail;
  625. }
  626. new->vcc = vcc;
  627. new->vpi = vpi;
  628. new->vci = vci;
  629. new->sarb = alloc_skb(usbatm_pdu_length(vcc->qos.rxtp.max_sdu), GFP_KERNEL);
  630. if (!new->sarb) {
  631. atm_err(instance, "%s: no memory for SAR buffer!\n", __func__);
  632. ret = -ENOMEM;
  633. goto fail;
  634. }
  635. vcc->dev_data = new;
  636. tasklet_disable(&instance->rx_channel.tasklet);
  637. list_add(&new->list, &instance->vcc_list);
  638. tasklet_enable(&instance->rx_channel.tasklet);
  639. set_bit(ATM_VF_ADDR, &vcc->flags);
  640. set_bit(ATM_VF_PARTIAL, &vcc->flags);
  641. set_bit(ATM_VF_READY, &vcc->flags);
  642. up(&instance->serialize);
  643. atm_dbg(instance, "%s: allocated vcc data 0x%p\n", __func__, new);
  644. return 0;
  645. fail:
  646. kfree(new);
  647. up(&instance->serialize);
  648. return ret;
  649. }
  650. static void usbatm_atm_close(struct atm_vcc *vcc)
  651. {
  652. struct usbatm_data *instance = vcc->dev->dev_data;
  653. struct usbatm_vcc_data *vcc_data = vcc->dev_data;
  654. if (!instance || !vcc_data) {
  655. dbg("%s: NULL data!", __func__);
  656. return;
  657. }
  658. atm_dbg(instance, "%s entered\n", __func__);
  659. atm_dbg(instance, "%s: deallocating vcc 0x%p with vpi %d vci %d\n",
  660. __func__, vcc_data, vcc_data->vpi, vcc_data->vci);
  661. usbatm_cancel_send(instance, vcc);
  662. down(&instance->serialize); /* vs self, usbatm_atm_open, usbatm_usb_disconnect */
  663. tasklet_disable(&instance->rx_channel.tasklet);
  664. list_del(&vcc_data->list);
  665. tasklet_enable(&instance->rx_channel.tasklet);
  666. kfree_skb(vcc_data->sarb);
  667. vcc_data->sarb = NULL;
  668. kfree(vcc_data);
  669. vcc->dev_data = NULL;
  670. vcc->vpi = ATM_VPI_UNSPEC;
  671. vcc->vci = ATM_VCI_UNSPEC;
  672. clear_bit(ATM_VF_READY, &vcc->flags);
  673. clear_bit(ATM_VF_PARTIAL, &vcc->flags);
  674. clear_bit(ATM_VF_ADDR, &vcc->flags);
  675. up(&instance->serialize);
  676. atm_dbg(instance, "%s successful\n", __func__);
  677. }
  678. static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd,
  679. void __user * arg)
  680. {
  681. struct usbatm_data *instance = atm_dev->dev_data;
  682. if (!instance || instance->disconnected) {
  683. dbg("%s: %s!", __func__, instance ? "disconnected" : "NULL instance");
  684. return -ENODEV;
  685. }
  686. switch (cmd) {
  687. case ATM_QUERYLOOP:
  688. return put_user(ATM_LM_NONE, (int __user *)arg) ? -EFAULT : 0;
  689. default:
  690. return -ENOIOCTLCMD;
  691. }
  692. }
  693. static int usbatm_atm_init(struct usbatm_data *instance)
  694. {
  695. struct atm_dev *atm_dev;
  696. int ret, i;
  697. /* ATM init. The ATM initialization scheme suffers from an intrinsic race
  698. * condition: callbacks we register can be executed at once, before we have
  699. * initialized the struct atm_dev. To protect against this, all callbacks
  700. * abort if atm_dev->dev_data is NULL. */
  701. atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL);
  702. if (!atm_dev) {
  703. usb_err(instance, "%s: failed to register ATM device!\n", __func__);
  704. return -1;
  705. }
  706. instance->atm_dev = atm_dev;
  707. atm_dev->ci_range.vpi_bits = ATM_CI_MAX;
  708. atm_dev->ci_range.vci_bits = ATM_CI_MAX;
  709. atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
  710. /* temp init ATM device, set to 128kbit */
  711. atm_dev->link_rate = 128 * 1000 / 424;
  712. if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) {
  713. atm_err(instance, "%s: atm_start failed: %d!\n", __func__, ret);
  714. goto fail;
  715. }
  716. usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */
  717. /* ready for ATM callbacks */
  718. mb();
  719. atm_dev->dev_data = instance;
  720. /* submit all rx URBs */
  721. for (i = 0; i < num_rcv_urbs; i++)
  722. usbatm_submit_urb(instance->urbs[i]);
  723. return 0;
  724. fail:
  725. instance->atm_dev = NULL;
  726. atm_dev_deregister(atm_dev); /* usbatm_atm_dev_close will eventually be called */
  727. return ret;
  728. }
  729. /**********
  730. ** USB **
  731. **********/
  732. static int usbatm_do_heavy_init(void *arg)
  733. {
  734. struct usbatm_data *instance = arg;
  735. int ret;
  736. daemonize(instance->driver->driver_name);
  737. allow_signal(SIGTERM);
  738. complete(&instance->thread_started);
  739. ret = instance->driver->heavy_init(instance, instance->usb_intf);
  740. if (!ret)
  741. ret = usbatm_atm_init(instance);
  742. down(&instance->serialize);
  743. instance->thread_pid = -1;
  744. up(&instance->serialize);
  745. complete_and_exit(&instance->thread_exited, ret);
  746. }
  747. static int usbatm_heavy_init(struct usbatm_data *instance)
  748. {
  749. int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL);
  750. if (ret < 0) {
  751. usb_err(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret);
  752. return ret;
  753. }
  754. down(&instance->serialize);
  755. instance->thread_pid = ret;
  756. up(&instance->serialize);
  757. wait_for_completion(&instance->thread_started);
  758. return 0;
  759. }
  760. static void usbatm_tasklet_schedule(unsigned long data)
  761. {
  762. tasklet_schedule((struct tasklet_struct *) data);
  763. }
  764. static inline void usbatm_init_channel(struct usbatm_channel *channel)
  765. {
  766. spin_lock_init(&channel->lock);
  767. INIT_LIST_HEAD(&channel->list);
  768. channel->delay.function = usbatm_tasklet_schedule;
  769. channel->delay.data = (unsigned long) &channel->tasklet;
  770. init_timer(&channel->delay);
  771. }
  772. int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
  773. struct usbatm_driver *driver)
  774. {
  775. struct device *dev = &intf->dev;
  776. struct usb_device *usb_dev = interface_to_usbdev(intf);
  777. struct usbatm_data *instance;
  778. char *buf;
  779. int error = -ENOMEM;
  780. int i, length;
  781. dev_dbg(dev, "%s: trying driver %s with vendor=%04x, product=%04x, ifnum %2d\n",
  782. __func__, driver->driver_name,
  783. le16_to_cpu(usb_dev->descriptor.idVendor),
  784. le16_to_cpu(usb_dev->descriptor.idProduct),
  785. intf->altsetting->desc.bInterfaceNumber);
  786. /* instance init */
  787. instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL);
  788. if (!instance) {
  789. dev_err(dev, "%s: no memory for instance data!\n", __func__);
  790. return -ENOMEM;
  791. }
  792. /* public fields */
  793. instance->driver = driver;
  794. snprintf(instance->driver_name, sizeof(instance->driver_name), driver->driver_name);
  795. instance->usb_dev = usb_dev;
  796. instance->usb_intf = intf;
  797. buf = instance->description;
  798. length = sizeof(instance->description);
  799. if ((i = usb_string(usb_dev, usb_dev->descriptor.iProduct, buf, length)) < 0)
  800. goto bind;
  801. buf += i;
  802. length -= i;
  803. i = scnprintf(buf, length, " (");
  804. buf += i;
  805. length -= i;
  806. if (length <= 0 || (i = usb_make_path(usb_dev, buf, length)) < 0)
  807. goto bind;
  808. buf += i;
  809. length -= i;
  810. snprintf(buf, length, ")");
  811. bind:
  812. if (driver->bind && (error = driver->bind(instance, intf, id)) < 0) {
  813. dev_err(dev, "%s: bind failed: %d!\n", __func__, error);
  814. goto fail_free;
  815. }
  816. /* private fields */
  817. kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */
  818. init_MUTEX(&instance->serialize);
  819. instance->thread_pid = -1;
  820. init_completion(&instance->thread_started);
  821. init_completion(&instance->thread_exited);
  822. INIT_LIST_HEAD(&instance->vcc_list);
  823. usbatm_init_channel(&instance->rx_channel);
  824. usbatm_init_channel(&instance->tx_channel);
  825. tasklet_init(&instance->rx_channel.tasklet, usbatm_rx_process, (unsigned long)instance);
  826. tasklet_init(&instance->tx_channel.tasklet, usbatm_tx_process, (unsigned long)instance);
  827. instance->rx_channel.endpoint = usb_rcvbulkpipe(usb_dev, driver->in);
  828. instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->out);
  829. instance->rx_channel.stride = ATM_CELL_SIZE + driver->rx_padding;
  830. instance->tx_channel.stride = ATM_CELL_SIZE + driver->tx_padding;
  831. instance->rx_channel.buf_size = rcv_buf_size * instance->rx_channel.stride;
  832. instance->tx_channel.buf_size = snd_buf_size * instance->tx_channel.stride;
  833. instance->rx_channel.usbatm = instance->tx_channel.usbatm = instance;
  834. skb_queue_head_init(&instance->sndqueue);
  835. for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
  836. struct urb *urb;
  837. u8 *buffer;
  838. unsigned int iso_packets = 0, iso_size = 0;
  839. struct usbatm_channel *channel = i < num_rcv_urbs ?
  840. &instance->rx_channel : &instance->tx_channel;
  841. if (usb_pipeisoc(channel->endpoint)) {
  842. /* don't expect iso out endpoints */
  843. iso_size = usb_maxpacket(instance->usb_dev, channel->endpoint, 0);
  844. iso_size -= iso_size % channel->stride; /* alignment */
  845. BUG_ON(!iso_size);
  846. iso_packets = (channel->buf_size - 1) / iso_size + 1;
  847. }
  848. urb = usb_alloc_urb(iso_packets, GFP_KERNEL);
  849. if (!urb) {
  850. dev_err(dev, "%s: no memory for urb %d!\n", __func__, i);
  851. goto fail_unbind;
  852. }
  853. instance->urbs[i] = urb;
  854. /* zero the tx padding to avoid leaking information */
  855. buffer = kzalloc(channel->buf_size, GFP_KERNEL);
  856. if (!buffer) {
  857. dev_err(dev, "%s: no memory for buffer %d!\n", __func__, i);
  858. goto fail_unbind;
  859. }
  860. usb_fill_bulk_urb(urb, instance->usb_dev, channel->endpoint,
  861. buffer, channel->buf_size, usbatm_complete, channel);
  862. if (iso_packets) {
  863. int j;
  864. urb->interval = 1;
  865. urb->transfer_flags = URB_ISO_ASAP;
  866. urb->number_of_packets = iso_packets;
  867. for (j = 0; j < iso_packets; j++) {
  868. urb->iso_frame_desc[j].offset = iso_size * j;
  869. urb->iso_frame_desc[j].length = min_t(int, iso_size,
  870. channel->buf_size - urb->iso_frame_desc[j].offset);
  871. }
  872. }
  873. /* put all tx URBs on the list of spares */
  874. if (i >= num_rcv_urbs)
  875. list_add_tail(&urb->urb_list, &channel->list);
  876. vdbg("%s: alloced buffer 0x%p buf size %u urb 0x%p",
  877. __func__, urb->transfer_buffer, urb->transfer_buffer_length, urb);
  878. }
  879. if (!(instance->flags & UDSL_SKIP_HEAVY_INIT) && driver->heavy_init) {
  880. error = usbatm_heavy_init(instance);
  881. } else {
  882. complete(&instance->thread_exited); /* pretend that heavy_init was run */
  883. error = usbatm_atm_init(instance);
  884. }
  885. if (error < 0)
  886. goto fail_unbind;
  887. usb_get_dev(usb_dev);
  888. usb_set_intfdata(intf, instance);
  889. return 0;
  890. fail_unbind:
  891. if (instance->driver->unbind)
  892. instance->driver->unbind(instance, intf);
  893. fail_free:
  894. for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
  895. if (instance->urbs[i])
  896. kfree(instance->urbs[i]->transfer_buffer);
  897. usb_free_urb(instance->urbs[i]);
  898. }
  899. kfree (instance);
  900. return error;
  901. }
  902. EXPORT_SYMBOL_GPL(usbatm_usb_probe);
  903. void usbatm_usb_disconnect(struct usb_interface *intf)
  904. {
  905. struct device *dev = &intf->dev;
  906. struct usbatm_data *instance = usb_get_intfdata(intf);
  907. struct usbatm_vcc_data *vcc_data;
  908. int i;
  909. dev_dbg(dev, "%s entered\n", __func__);
  910. if (!instance) {
  911. dev_dbg(dev, "%s: NULL instance!\n", __func__);
  912. return;
  913. }
  914. usb_set_intfdata(intf, NULL);
  915. down(&instance->serialize);
  916. instance->disconnected = 1;
  917. if (instance->thread_pid >= 0)
  918. kill_proc(instance->thread_pid, SIGTERM, 1);
  919. up(&instance->serialize);
  920. wait_for_completion(&instance->thread_exited);
  921. down(&instance->serialize);
  922. list_for_each_entry(vcc_data, &instance->vcc_list, list)
  923. vcc_release_async(vcc_data->vcc, -EPIPE);
  924. up(&instance->serialize);
  925. tasklet_disable(&instance->rx_channel.tasklet);
  926. tasklet_disable(&instance->tx_channel.tasklet);
  927. for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++)
  928. usb_kill_urb(instance->urbs[i]);
  929. del_timer_sync(&instance->rx_channel.delay);
  930. del_timer_sync(&instance->tx_channel.delay);
  931. /* turn usbatm_[rt]x_process into something close to a no-op */
  932. /* no need to take the spinlock */
  933. INIT_LIST_HEAD(&instance->rx_channel.list);
  934. INIT_LIST_HEAD(&instance->tx_channel.list);
  935. tasklet_enable(&instance->rx_channel.tasklet);
  936. tasklet_enable(&instance->tx_channel.tasklet);
  937. if (instance->atm_dev && instance->driver->atm_stop)
  938. instance->driver->atm_stop(instance, instance->atm_dev);
  939. if (instance->driver->unbind)
  940. instance->driver->unbind(instance, intf);
  941. instance->driver_data = NULL;
  942. for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
  943. kfree(instance->urbs[i]->transfer_buffer);
  944. usb_free_urb(instance->urbs[i]);
  945. }
  946. /* ATM finalize */
  947. if (instance->atm_dev)
  948. atm_dev_deregister(instance->atm_dev);
  949. usbatm_put_instance(instance); /* taken in usbatm_usb_probe */
  950. }
  951. EXPORT_SYMBOL_GPL(usbatm_usb_disconnect);
  952. /***********
  953. ** init **
  954. ***********/
  955. static int __init usbatm_usb_init(void)
  956. {
  957. dbg("%s: driver version %s", __func__, DRIVER_VERSION);
  958. if (sizeof(struct usbatm_control) > sizeof(((struct sk_buff *) 0)->cb)) {
  959. printk(KERN_ERR "%s unusable with this kernel!\n", usbatm_driver_name);
  960. return -EIO;
  961. }
  962. if ((num_rcv_urbs > UDSL_MAX_RCV_URBS)
  963. || (num_snd_urbs > UDSL_MAX_SND_URBS)
  964. || (rcv_buf_size < 1)
  965. || (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE)
  966. || (snd_buf_size < 1)
  967. || (snd_buf_size > UDSL_MAX_SND_BUF_SIZE))
  968. return -EINVAL;
  969. return 0;
  970. }
  971. module_init(usbatm_usb_init);
  972. static void __exit usbatm_usb_exit(void)
  973. {
  974. dbg("%s", __func__);
  975. }
  976. module_exit(usbatm_usb_exit);
  977. MODULE_AUTHOR(DRIVER_AUTHOR);
  978. MODULE_DESCRIPTION(DRIVER_DESC);
  979. MODULE_LICENSE("GPL");
  980. MODULE_VERSION(DRIVER_VERSION);
  981. /************
  982. ** debug **
  983. ************/
  984. #ifdef VERBOSE_DEBUG
  985. static int usbatm_print_packet(const unsigned char *data, int len)
  986. {
  987. unsigned char buffer[256];
  988. int i = 0, j = 0;
  989. for (i = 0; i < len;) {
  990. buffer[0] = '\0';
  991. sprintf(buffer, "%.3d :", i);
  992. for (j = 0; (j < 16) && (i < len); j++, i++) {
  993. sprintf(buffer, "%s %2.2x", buffer, data[i]);
  994. }
  995. dbg("%s", buffer);
  996. }
  997. return i;
  998. }
  999. #endif