usbatm.c 32 KB

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