usbatm.c 34 KB

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