xpp_usb.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. /*
  2. * Written by Oron Peled <oron@actcom.co.il>
  3. * Copyright (C) 2004-2006, Xorcom
  4. *
  5. * All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. */
  22. #include <linux/version.h>
  23. #include <linux/kernel.h>
  24. #include <linux/errno.h>
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/errno.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/delay.h> /* for udelay */
  30. #include <linux/seq_file.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/atomic.h>
  33. #include <asm/timex.h>
  34. #include <linux/proc_fs.h>
  35. #include <linux/usb.h>
  36. #include "xpd.h"
  37. #include "xproto.h"
  38. #include "xbus-core.h"
  39. #include "xframe_queue.h"
  40. #ifdef DEBUG
  41. #include "card_fxs.h"
  42. #include "card_fxo.h"
  43. #endif
  44. #include "parport_debug.h"
  45. static const char rcsid[] = "$Id$";
  46. static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before dahdi_debug.h */
  47. static DEF_PARM(int, usb1, 0, 0644, "Allow using USB 1.1 interfaces");
  48. static DEF_PARM(uint, tx_sluggish, 2000, 0644, "A sluggish transmit (usec)");
  49. static DEF_PARM(uint, drop_pcm_after, 6, 0644, "Number of consecutive tx_sluggish to drop a PCM frame");
  50. #include "dahdi_debug.h"
  51. #define XUSB_PRINTK(level, xusb, fmt, ...) \
  52. printk(KERN_ ## level "%s-%s: xusb-%d (%s) [%s]: " fmt, #level, \
  53. THIS_MODULE->name, (xusb)->index, xusb->path, xusb->serial, ## __VA_ARGS__)
  54. #define XUSB_DBG(bits, xusb, fmt, ...) \
  55. ((void)((debug & (DBG_ ## bits)) && XUSB_PRINTK(DEBUG, xusb, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__)))
  56. #define XUSB_ERR(xusb, fmt, ...) XUSB_PRINTK(ERR, xusb, fmt, ## __VA_ARGS__)
  57. #define XUSB_NOTICE(xusb, fmt, ...) XUSB_PRINTK(NOTICE, xusb, fmt, ## __VA_ARGS__)
  58. #define XUSB_INFO(xusb, fmt, ...) XUSB_PRINTK(INFO, xusb, fmt, ## __VA_ARGS__)
  59. /* FIXME: A flag that was deprecated at some point, and rather useless */
  60. /* anyway. Only used in the code or-ed to other flags */
  61. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
  62. # define URB_ASYNC_UNLINK 0
  63. #endif
  64. /* Get a minor range for your devices from the usb maintainer */
  65. #define USB_SKEL_MINOR_BASE 192
  66. #ifdef CONFIG_PROC_FS
  67. #define PROC_USBXPP_SUMMARY "xpp_usb"
  68. #endif
  69. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  70. # warning "This module is tested only with 2.6 kernels"
  71. #endif
  72. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34)
  73. # define usb_alloc_coherent(dev, size, mem_flags, dma) \
  74. usb_buffer_alloc(dev, size, mem_flags, dma)
  75. # define usb_free_coherent(dev, size, addr, dma) \
  76. usb_buffer_free(dev, size, addr, dma)
  77. #endif
  78. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
  79. # undef USB_FIELDS_MISSING
  80. #else
  81. # define USB_FIELDS_MISSING
  82. # define USB_MAX_STRING 128
  83. # define USB_GET_STRING(udev,field,buf) \
  84. do { \
  85. if((udev)->descriptor.field) { \
  86. char tmp[USB_MAX_STRING]; \
  87. if(usb_string((udev), (udev)->descriptor.field, tmp, sizeof(tmp)) > 0) \
  88. snprintf((buf), USB_MAX_STRING, "%s", tmp); \
  89. } \
  90. } while(0);
  91. # define USB_GET_IFACE_NAME(udev,iface,buf) \
  92. do { \
  93. if((iface)->desc.iInterface) { \
  94. char tmp[USB_MAX_STRING]; \
  95. if(usb_string((udev), (iface)->desc.iInterface, tmp, sizeof(tmp)) > 0) \
  96. snprintf((buf), USB_MAX_STRING, "%s", tmp); \
  97. } \
  98. } while(0);
  99. #endif
  100. #ifdef DEBUG_PCM_TIMING
  101. static cycles_t stamp_last_pcm_read;
  102. static cycles_t accumulate_diff;
  103. #endif
  104. struct xusb_model_info;
  105. struct xusb_endpoint {
  106. int ep_addr;
  107. int max_size;
  108. usb_complete_t callback;
  109. };
  110. enum xusb_dir {
  111. XUSB_RECV = 0,
  112. XUSB_SEND = 1,
  113. };
  114. static __must_check int xframe_send_pcm(xbus_t *xbus, xframe_t *xframe);
  115. static __must_check int xframe_send_cmd(xbus_t *xbus, xframe_t *xframe);
  116. static __must_check xframe_t *alloc_xframe(xbus_t *xbus, gfp_t flags);
  117. static void free_xframe(xbus_t *xbus, xframe_t *frm);
  118. static struct xbus_ops xusb_ops = {
  119. .xframe_send_pcm = xframe_send_pcm,
  120. .xframe_send_cmd = xframe_send_cmd,
  121. .alloc_xframe = alloc_xframe,
  122. .free_xframe = free_xframe,
  123. };
  124. enum {
  125. XUSB_N_RX_FRAMES,
  126. XUSB_N_TX_FRAMES,
  127. XUSB_N_RX_ERRORS,
  128. XUSB_N_TX_ERRORS,
  129. XUSB_N_RCV_ZERO_LEN,
  130. };
  131. #define XUSB_COUNTER(xusb, counter) ((xusb)->counters[XUSB_N_ ## counter])
  132. #define C_(x) [ XUSB_N_ ## x ] = { #x }
  133. static struct xusb_counters {
  134. char *name;
  135. } xusb_counters[] = {
  136. C_(RX_FRAMES),
  137. C_(TX_FRAMES),
  138. C_(RX_ERRORS),
  139. C_(TX_ERRORS),
  140. C_(RCV_ZERO_LEN),
  141. };
  142. #undef C_
  143. #define XUSB_COUNTER_MAX ARRAY_SIZE(xusb_counters)
  144. #define MAX_PENDING_WRITES 100
  145. static KMEM_CACHE_T *xusb_cache = NULL;
  146. typedef struct xusb xusb_t;
  147. /*
  148. * A uframe is our low level representation of a frame.
  149. *
  150. * It contains the metadata for the usb stack (a urb)
  151. * and the metadata for the xbus-core (an xframe)
  152. * as well as pointing to the data (transfer_buffer, transfer_buffer_length)
  153. * directionality (send/receive) and ownership (xusb).
  154. */
  155. struct uframe {
  156. unsigned long uframe_magic;
  157. #define UFRAME_MAGIC 654321L
  158. struct urb urb;
  159. xframe_t xframe;
  160. size_t transfer_buffer_length;
  161. void *transfer_buffer; /* max XFRAME_DATASIZE */
  162. xusb_t *xusb;
  163. };
  164. #define urb_to_uframe(urb) container_of(urb, struct uframe, urb)
  165. #define xframe_to_uframe(xframe) container_of(xframe, struct uframe, xframe)
  166. #define xusb_of(xbus) ((xusb_t *)((xbus)->transport.priv))
  167. #define USEC_BUCKET 100 /* usec */
  168. #define NUM_BUCKETS 15
  169. #define BUCKET_START (500/USEC_BUCKET) /* skip uninteresting */
  170. /*
  171. * USB XPP Bus (a USB Device)
  172. */
  173. struct xusb {
  174. uint xbus_num;
  175. struct usb_device *udev; /* save off the usb device pointer */
  176. struct usb_interface *interface; /* the interface for this device */
  177. unsigned char minor; /* the starting minor number for this device */
  178. uint index;
  179. char path[XBUS_DESCLEN]; /* a unique path */
  180. struct xusb_model_info *model_info;
  181. struct xusb_endpoint endpoints[2]; /* RECV/SEND endpoints */
  182. int present; /* if the device is not disconnected */
  183. atomic_t pending_writes; /* submited but not out yet */
  184. atomic_t pending_reads; /* submited but not in yet */
  185. struct semaphore sem; /* locks this structure */
  186. int counters[XUSB_COUNTER_MAX];
  187. /* metrics */
  188. struct timeval last_tx;
  189. unsigned int max_tx_delay;
  190. uint usb_tx_delay[NUM_BUCKETS];
  191. uint sluggish_debounce;
  192. bool drop_next_pcm; /* due to sluggishness */
  193. atomic_t pcm_tx_drops;
  194. atomic_t usb_sluggish_count;
  195. #ifdef USB_FIELDS_MISSING
  196. /* storage for missing strings in old kernels */
  197. char manufacturer[USB_MAX_STRING];
  198. char product[USB_MAX_STRING];
  199. char serial[USB_MAX_STRING];
  200. char interface_name[USB_MAX_STRING];
  201. #else
  202. const char *manufacturer;
  203. const char *product;
  204. const char *serial;
  205. const char *interface_name;
  206. #endif
  207. };
  208. static DEFINE_SPINLOCK(xusb_lock);
  209. static xusb_t *xusb_array[MAX_BUSES] = {};
  210. static unsigned bus_count = 0;
  211. /* prevent races between open() and disconnect() */
  212. static DEFINE_SEMAPHORE(disconnect_sem);
  213. /*
  214. * AsteriskNow kernel has backported the "lean" callback from 2.6.20
  215. * to 2.6.19 without any macro to notify of this fact -- how lovely.
  216. * Debian-Etch and Centos5 are using 2.6.18 for now (lucky for us).
  217. * Fedora6 jumped from 2.6.18 to 2.6.20. So far luck is on our side ;-)
  218. */
  219. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
  220. #define USB_PASS_CB(u) struct urb *u, struct pt_regs *regs
  221. #else
  222. #define USB_PASS_CB(u) struct urb *u
  223. #endif
  224. static void xpp_send_callback(USB_PASS_CB(urb));
  225. static void xpp_receive_callback(USB_PASS_CB(urb));
  226. static int xusb_probe (struct usb_interface *interface, const struct usb_device_id *id);
  227. static void xusb_disconnect (struct usb_interface *interface);
  228. #ifdef CONFIG_PROC_FS
  229. static int xusb_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data);
  230. #endif
  231. /*------------------------------------------------------------------*/
  232. /*
  233. * Updates the urb+xframe metadata from the uframe information.
  234. */
  235. static void uframe_recompute(struct uframe *uframe, enum xusb_dir dir)
  236. {
  237. struct urb *urb = &uframe->urb;
  238. xusb_t *xusb = uframe->xusb;
  239. struct usb_device *udev = xusb->udev;
  240. struct xusb_endpoint *xusb_ep = &xusb->endpoints[dir];
  241. unsigned int ep_addr = xusb_ep->ep_addr;
  242. usb_complete_t urb_cb = xusb_ep->callback;
  243. unsigned int epnum = ep_addr & USB_ENDPOINT_NUMBER_MASK;
  244. int pipe = usb_pipein(ep_addr)
  245. ? usb_rcvbulkpipe(udev, epnum)
  246. : usb_sndbulkpipe(udev, epnum);
  247. BUG_ON(uframe->uframe_magic != UFRAME_MAGIC);
  248. usb_fill_bulk_urb(urb, udev, pipe, uframe->transfer_buffer, uframe->transfer_buffer_length, urb_cb, uframe);
  249. urb->transfer_flags = (URB_NO_TRANSFER_DMA_MAP | URB_ASYNC_UNLINK);
  250. }
  251. static xframe_t *alloc_xframe(xbus_t *xbus, gfp_t gfp_flags)
  252. {
  253. struct uframe *uframe;
  254. xusb_t *xusb;
  255. void *p;
  256. int size;
  257. static int rate_limit;
  258. BUG_ON(!xbus);
  259. xusb = xusb_of(xbus);
  260. BUG_ON(!xusb);
  261. if(!xusb->present) {
  262. if((rate_limit++ % 1003) == 0)
  263. XUSB_ERR(xusb,
  264. "abort allocations during device disconnect (%d)\n", rate_limit);
  265. return NULL;
  266. }
  267. size = min(xusb->endpoints[XUSB_SEND].max_size, xusb->endpoints[XUSB_RECV].max_size);
  268. uframe = kmem_cache_alloc(xusb_cache, gfp_flags);
  269. if(!uframe) {
  270. if((rate_limit++ % 1003) == 0)
  271. XUSB_ERR(xusb, "frame allocation failed (%d)\n", rate_limit);
  272. return NULL;
  273. }
  274. usb_init_urb(&uframe->urb);
  275. p = usb_alloc_coherent(xusb->udev, size, gfp_flags, &uframe->urb.transfer_dma);
  276. if(!p) {
  277. if((rate_limit++ % 1003) == 0)
  278. XUSB_ERR(xusb, "buffer allocation failed (%d)\n", rate_limit);
  279. kmem_cache_free(xusb_cache, uframe);
  280. return NULL;
  281. }
  282. uframe->uframe_magic = UFRAME_MAGIC;
  283. uframe->transfer_buffer_length = size;
  284. uframe->transfer_buffer = p;
  285. uframe->xusb = xusb;
  286. xframe_init(xbus, &uframe->xframe, uframe->transfer_buffer, uframe->transfer_buffer_length, uframe);
  287. return &uframe->xframe;
  288. }
  289. static void free_xframe(xbus_t *xbus, xframe_t *xframe)
  290. {
  291. struct uframe *uframe = xframe_to_uframe(xframe);
  292. struct urb *urb = &uframe->urb;
  293. BUG_ON(xbus->transport.priv != uframe->xusb);
  294. //XUSB_INFO(uframe->xusb, "frame_free\n");
  295. usb_free_coherent(urb->dev, uframe->transfer_buffer_length,
  296. urb->transfer_buffer,
  297. urb->transfer_dma);
  298. memset(uframe, 0, sizeof(*uframe));
  299. kmem_cache_free(xusb_cache, uframe);
  300. }
  301. /*------------------------------------------------------------------*/
  302. /*
  303. * Actuall frame sending -- both PCM and commands.
  304. */
  305. static int do_send_xframe(xbus_t *xbus, xframe_t *xframe)
  306. {
  307. struct urb *urb;
  308. xusb_t *xusb;
  309. int ret = 0;
  310. struct uframe *uframe;
  311. BUG_ON(!xframe);
  312. BUG_ON(xframe->xframe_magic != XFRAME_MAGIC);
  313. xusb = xusb_of(xbus);
  314. BUG_ON(!xusb);
  315. if(!xusb->present) {
  316. static int rate_limit;
  317. if((rate_limit++ % 1003) == 0)
  318. XUSB_ERR(xusb,
  319. "abort do_send_xframe during device disconnect (%d)\n", rate_limit);
  320. ret = -ENODEV;
  321. goto failure;
  322. }
  323. /*
  324. * If something really bad happend, do not overflow the USB stack
  325. */
  326. if(atomic_read(&xusb->pending_writes) > MAX_PENDING_WRITES) {
  327. static int rate_limit;
  328. if((rate_limit++ % 5000) == 0)
  329. XUSB_ERR(xusb,
  330. "USB device is totaly stuck. Dropping packets (#%d).\n",
  331. rate_limit);
  332. ret = -ENODEV;
  333. goto failure;
  334. }
  335. uframe = xframe->priv;
  336. BUG_ON(!uframe);
  337. BUG_ON(uframe->uframe_magic != UFRAME_MAGIC);
  338. uframe_recompute(uframe, XUSB_SEND);
  339. urb = &uframe->urb;
  340. BUG_ON(!urb);
  341. /* update urb length */
  342. urb->transfer_buffer_length = XFRAME_LEN(xframe);
  343. do_gettimeofday(&xframe->tv_submitted);
  344. ret = usb_submit_urb(urb, GFP_ATOMIC);
  345. if(ret < 0) {
  346. static int rate_limit;
  347. if((rate_limit++ % 1000) == 0)
  348. XBUS_ERR(xbus, "%s: usb_submit_urb failed: %d\n",
  349. __FUNCTION__, ret);
  350. ret = -EBADF;
  351. goto failure;
  352. }
  353. // if (debug)
  354. // dump_xframe("USB_FRAME_SEND", xbus, xframe, debug);
  355. atomic_inc(&xusb->pending_writes);
  356. return 0;
  357. failure:
  358. XUSB_COUNTER(xusb, TX_ERRORS)++;
  359. FREE_SEND_XFRAME(xbus, xframe); /* return to pool */
  360. return ret;
  361. }
  362. /*
  363. * PCM wrapper
  364. */
  365. static int xframe_send_pcm(xbus_t *xbus, xframe_t *xframe)
  366. {
  367. xusb_t *xusb;
  368. BUG_ON(!xbus);
  369. BUG_ON(!xframe);
  370. xusb = xusb_of(xbus);
  371. BUG_ON(!xusb);
  372. if(xusb->drop_next_pcm) {
  373. FREE_SEND_XFRAME(xbus, xframe); /* return to pool */
  374. xusb->drop_next_pcm = 0;
  375. return -EIO;
  376. }
  377. return do_send_xframe(xbus, xframe);
  378. }
  379. /*
  380. * commands wrapper
  381. */
  382. static int xframe_send_cmd(xbus_t *xbus, xframe_t *xframe)
  383. {
  384. BUG_ON(!xbus);
  385. BUG_ON(!xframe);
  386. //XBUS_INFO(xbus, "%s:\n", __FUNCTION__);
  387. return do_send_xframe(xbus, xframe);
  388. }
  389. /*
  390. * get a urb from the receive_pool and submit it on the read endpoint.
  391. */
  392. static bool xusb_listen(xusb_t *xusb)
  393. {
  394. xbus_t *xbus = xbus_num(xusb->xbus_num);
  395. xframe_t *xframe;
  396. struct uframe *uframe;
  397. int ret = 0;
  398. BUG_ON(!xbus);
  399. xframe = ALLOC_RECV_XFRAME(xbus);
  400. if(!xframe) {
  401. XBUS_ERR(xbus, "Empty receive_pool\n");
  402. goto out;
  403. }
  404. uframe = xframe_to_uframe(xframe);
  405. uframe_recompute(uframe, XUSB_RECV);
  406. ret = usb_submit_urb(&uframe->urb, GFP_ATOMIC);
  407. if(ret < 0) {
  408. static int rate_limit;
  409. if((rate_limit++ % 1000) == 0)
  410. XBUS_ERR(xbus, "%s: usb_submit_urb failed: %d\n",
  411. __FUNCTION__, ret);
  412. FREE_RECV_XFRAME(xbus, xframe);
  413. goto out;
  414. }
  415. atomic_inc(&xusb->pending_reads);
  416. ret = 1;
  417. out:
  418. return ret;
  419. }
  420. /*------------------------- XPP USB Bus Handling -------------------*/
  421. enum XUSB_MODELS {
  422. MODEL_FPGA_XPD
  423. };
  424. static const struct xusb_model_info {
  425. const char *desc;
  426. int iface_num;
  427. struct xusb_endpoint in;
  428. struct xusb_endpoint out;
  429. } model_table[] = {
  430. [MODEL_FPGA_XPD] = {
  431. .iface_num = 0,
  432. .in = { .ep_addr = 0x86 },
  433. .out = { .ep_addr = 0x02 },
  434. .desc = "FPGA_XPD"
  435. },
  436. };
  437. /* table of devices that work with this driver */
  438. static const struct usb_device_id xusb_table [] = {
  439. { USB_DEVICE(0xE4E4, 0x1132), .driver_info=(kernel_ulong_t)&model_table[MODEL_FPGA_XPD] }, // FPGA_FXS
  440. { USB_DEVICE(0xE4E4, 0x1142), .driver_info=(kernel_ulong_t)&model_table[MODEL_FPGA_XPD] }, // FPGA_1141
  441. { USB_DEVICE(0xE4E4, 0x1152), .driver_info=(kernel_ulong_t)&model_table[MODEL_FPGA_XPD] }, // FPGA_1151
  442. { USB_DEVICE(0xE4E4, 0x1162), .driver_info=(kernel_ulong_t)&model_table[MODEL_FPGA_XPD] }, // FPGA_1161
  443. { } /* Terminating entry */
  444. };
  445. MODULE_DEVICE_TABLE (usb, xusb_table);
  446. /* usb specific object needed to register this driver with the usb subsystem */
  447. static struct usb_driver xusb_driver = {
  448. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
  449. .owner = THIS_MODULE,
  450. #endif
  451. .name = "xpp_usb",
  452. .probe = xusb_probe,
  453. .disconnect = xusb_disconnect,
  454. .id_table = xusb_table,
  455. };
  456. /*
  457. * File operations needed when we register this driver.
  458. * This assumes that this driver NEEDS file operations,
  459. * of course, which means that the driver is expected
  460. * to have a node in the /dev directory. If the USB
  461. * device were for a network interface then the driver
  462. * would use "struct net_driver" instead, and a serial
  463. * device would use "struct tty_driver".
  464. */
  465. static struct file_operations xusb_fops = {
  466. /*
  467. * The owner field is part of the module-locking
  468. * mechanism. The idea is that the kernel knows
  469. * which module to increment the use-counter of
  470. * BEFORE it calls the device's open() function.
  471. * This also means that the kernel can decrement
  472. * the use-counter again before calling release()
  473. * or should the open() function fail.
  474. */
  475. .owner = THIS_MODULE,
  476. };
  477. /*
  478. * usb class driver info in order to get a minor number from the usb core,
  479. * and to have the device registered with devfs and the driver core
  480. */
  481. static struct usb_class_driver xusb_class = {
  482. .name = "usb/xpp_usb%d",
  483. .fops = &xusb_fops,
  484. /* FIXME: The sysfs class interfase seems to have chaged around here */
  485. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
  486. .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
  487. #endif
  488. .minor_base = USB_SKEL_MINOR_BASE,
  489. };
  490. /*
  491. * Check that an endpoint's wMaxPacketSize attribute is 512. This
  492. * indicates that it is a USB2's high speed end point.
  493. *
  494. * If it is 64, it means we have a USB1 controller. By default we do not
  495. * support it and just fail the probe of the device. However if the user
  496. * has set usb1=1, we continue and just put a notice.
  497. *
  498. * Returns true if all OK, false otherwise.
  499. */
  500. static int check_usb1(struct usb_endpoint_descriptor *endpoint)
  501. {
  502. const char *msg = (usb_pipein(endpoint->bEndpointAddress))?"input":"output";
  503. if(endpoint->wMaxPacketSize >= sizeof(xpacket_t))
  504. return 1;
  505. if(usb1) {
  506. NOTICE("USB1 endpoint detected: USB %s endpoint 0x%X support only wMaxPacketSize=%d.\n",
  507. msg, endpoint->bEndpointAddress, endpoint->wMaxPacketSize);
  508. return 1;
  509. }
  510. NOTICE("USB1 endpoint detected. Device disabled. To enable: usb1=1, and read docs. (%s, endpoint %d, size %d).\n",
  511. msg, endpoint->bEndpointAddress, endpoint->wMaxPacketSize);
  512. return 0;
  513. }
  514. /*
  515. * set up the endpoint information
  516. * check out the endpoints
  517. * FIXME: Should be simplified (above 2.6.10) to use usb_dev->ep_in[0..16] and usb_dev->ep_out[0..16]
  518. */
  519. static int set_endpoints(xusb_t *xusb, struct usb_host_interface *iface_desc, struct xusb_model_info *model_info)
  520. {
  521. struct usb_endpoint_descriptor *endpoint;
  522. struct xusb_endpoint *xusb_ep;
  523. int ep_addr;
  524. int i;
  525. #define BULK_ENDPOINT(ep) (((ep)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)
  526. for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
  527. endpoint = &iface_desc->endpoint[i].desc;
  528. ep_addr = endpoint->bEndpointAddress;
  529. if(!BULK_ENDPOINT(endpoint)) {
  530. DBG(DEVICES, "endpoint 0x%x is not bulk: mbAttributes=0x%X\n",
  531. ep_addr, endpoint->bmAttributes);
  532. continue;
  533. }
  534. if(usb_pipein(ep_addr)) { // Input
  535. if(ep_addr == model_info->in.ep_addr) {
  536. if (!check_usb1(endpoint))
  537. return 0;
  538. xusb_ep = &xusb->endpoints[XUSB_RECV];
  539. xusb_ep->ep_addr = ep_addr;
  540. xusb_ep->max_size = endpoint->wMaxPacketSize;
  541. xusb_ep->callback = xpp_receive_callback;
  542. }
  543. } else { // Output
  544. if(ep_addr == model_info->out.ep_addr) {
  545. if (!check_usb1(endpoint))
  546. return 0;
  547. xusb_ep = &xusb->endpoints[XUSB_SEND];
  548. xusb_ep->ep_addr = ep_addr;
  549. xusb_ep->max_size = endpoint->wMaxPacketSize;
  550. xusb_ep->callback = xpp_send_callback;
  551. }
  552. }
  553. }
  554. if (!xusb->endpoints[XUSB_RECV].ep_addr || !xusb->endpoints[XUSB_SEND].ep_addr) {
  555. XUSB_ERR(xusb, "Couldn't find bulk-in or bulk-out endpoints\n");
  556. return 0;
  557. }
  558. DBG(DEVICES, "in=0x%02X out=0x%02X\n", xusb->endpoints[XUSB_RECV].ep_addr, xusb->endpoints[XUSB_SEND].ep_addr);
  559. return 1;
  560. }
  561. /*
  562. * The USB stack before 2.6.10 seems to be a bit shoddy. It seems that when
  563. * being called from the probe we may already have the lock to udev (the Usb DEVice).
  564. * Thus we call the internal __usb_reset_device instead.
  565. */
  566. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
  567. #define DO_USB_RESET_DEVICE(dev) __usb_reset_device(dev)
  568. #else
  569. #define DO_USB_RESET_DEVICE(dev) usb_reset_device(dev)
  570. #endif
  571. /**
  572. * xusb_probe
  573. *
  574. * Called by the usb core when a new device is connected that it thinks
  575. * this driver might be interested in.
  576. */
  577. static int xusb_probe(struct usb_interface *interface, const struct usb_device_id *id)
  578. {
  579. struct usb_device *udev = interface_to_usbdev(interface);
  580. struct usb_host_interface *iface_desc = usb_altnum_to_altsetting(interface, 0);
  581. xusb_t *xusb = NULL;
  582. struct xusb_model_info *model_info = (struct xusb_model_info*)id->driver_info;
  583. #ifdef CONFIG_PROC_FS
  584. struct proc_dir_entry *procsummary = NULL;
  585. #endif
  586. xbus_t *xbus = NULL;
  587. unsigned long flags;
  588. int retval = -ENOMEM;
  589. int i;
  590. DBG(DEVICES, "New XUSB device MODEL=%s\n", model_info->desc);
  591. if(iface_desc->desc.bInterfaceNumber != model_info->iface_num) {
  592. DBG(DEVICES, "Skip interface #%d != #%d\n",
  593. iface_desc->desc.bInterfaceNumber, model_info->iface_num);
  594. return -ENODEV;
  595. }
  596. if((retval = DO_USB_RESET_DEVICE(udev)) < 0) {
  597. ERR("usb_reset_device failed: %d\n", retval);
  598. goto probe_failed;
  599. }
  600. if (!model_info) {
  601. ERR("Missing endpoint setup for this device %d:%d\n",
  602. udev->descriptor.idVendor,udev->descriptor.idProduct);
  603. retval = -ENODEV;
  604. goto probe_failed;
  605. }
  606. /* allocate memory for our device state and initialize it */
  607. xusb = KZALLOC(sizeof(xusb_t), GFP_KERNEL);
  608. if (xusb == NULL) {
  609. ERR("xpp_usb: Unable to allocate new xpp usb bus\n");
  610. retval = -ENOMEM;
  611. goto probe_failed;
  612. }
  613. sema_init(&xusb->sem, 1);
  614. atomic_set(&xusb->pending_writes, 0);
  615. atomic_set(&xusb->pending_reads, 0);
  616. atomic_set(&xusb->pcm_tx_drops, 0);
  617. atomic_set(&xusb->usb_sluggish_count, 0);
  618. xusb->udev = udev;
  619. xusb->interface = interface;
  620. xusb->model_info = model_info;
  621. if(!set_endpoints(xusb, iface_desc, model_info)) {
  622. retval = -ENODEV;
  623. goto probe_failed;
  624. }
  625. #ifndef USB_FIELDS_MISSING
  626. xusb->serial = udev->serial;
  627. xusb->manufacturer = udev->manufacturer;
  628. xusb->product = udev->product;
  629. xusb->interface_name = iface_desc->string;
  630. #else
  631. USB_GET_STRING(udev, iSerialNumber, xusb->serial);
  632. USB_GET_STRING(udev, iManufacturer, xusb->manufacturer);
  633. USB_GET_STRING(udev, iProduct, xusb->product);
  634. USB_GET_IFACE_NAME(udev, iface_desc, xusb->interface_name);
  635. #endif
  636. INFO("XUSB: %s -- %s -- %s\n",
  637. xusb->manufacturer, xusb->product, xusb->interface_name);
  638. /* allow device read, write and ioctl */
  639. xusb->present = 1;
  640. /* we can register the device now, as it is ready */
  641. usb_set_intfdata(interface, xusb);
  642. retval = usb_register_dev (interface, &xusb_class);
  643. if (retval) {
  644. /* something prevented us from registering this driver */
  645. ERR ("Not able to get a minor for this device.\n");
  646. goto probe_failed;
  647. }
  648. xusb->minor = interface->minor;
  649. /* let the user know what node this device is now attached to */
  650. DBG(DEVICES, "USB XPP device now attached to minor %d\n", xusb->minor);
  651. xbus = xbus_new(&xusb_ops, min(xusb->endpoints[XUSB_SEND].max_size, xusb->endpoints[XUSB_RECV].max_size), &udev->dev, xusb);
  652. if(!xbus) {
  653. retval = -ENOMEM;
  654. goto probe_failed;
  655. }
  656. spin_lock_irqsave(&xusb_lock, flags);
  657. for(i = 0; i < MAX_BUSES; i++) {
  658. if(xusb_array[i] == NULL)
  659. break;
  660. }
  661. spin_unlock_irqrestore(&xusb_lock, flags);
  662. if(i >= MAX_BUSES) {
  663. ERR("xpp_usb: Too many XPP USB buses\n");
  664. retval = -ENOMEM;
  665. goto probe_failed;
  666. }
  667. usb_make_path(udev, xusb->path, XBUS_DESCLEN); // May trunacte... ignore
  668. snprintf(xbus->connector, XBUS_DESCLEN, "%s", xusb->path);
  669. if(xusb->serial && xusb->serial[0])
  670. snprintf(xbus->label, LABEL_SIZE, "usb:%s", xusb->serial);
  671. xusb->index = i;
  672. xusb_array[i] = xusb;
  673. XUSB_DBG(DEVICES, xusb, "GOT XPP USB BUS: %s\n", xbus->connector);
  674. #ifdef CONFIG_PROC_FS
  675. DBG(PROC, "Creating proc entry " PROC_USBXPP_SUMMARY " in bus proc dir.\n");
  676. procsummary = create_proc_read_entry(PROC_USBXPP_SUMMARY, 0444, xbus->proc_xbus_dir,
  677. xusb_read_proc, xusb);
  678. if (!procsummary) {
  679. XBUS_ERR(xbus, "Failed to create proc file '%s'\n", PROC_USBXPP_SUMMARY);
  680. // FIXME: better error handling
  681. retval = -EIO;
  682. goto probe_failed;
  683. }
  684. SET_PROC_DIRENTRY_OWNER(procsummary);
  685. #endif
  686. bus_count++;
  687. xusb->xbus_num = xbus->num;
  688. /* prepare several pending frames for receive side */
  689. for(i = 0; i < 10; i++)
  690. xusb_listen(xusb);
  691. xbus_connect(xbus);
  692. return retval;
  693. probe_failed:
  694. ERR("Failed to initialize xpp usb bus: %d\n", retval);
  695. usb_set_intfdata(interface, NULL);
  696. if(xusb) {
  697. if(xusb->minor) { // passed registration phase
  698. ERR("Calling usb_deregister_dev()\n");
  699. usb_deregister_dev(interface, &xusb_class);
  700. }
  701. ERR("Removing failed xusb\n");
  702. KZFREE(xusb);
  703. }
  704. if(xbus) {
  705. #ifdef CONFIG_PROC_FS
  706. if(procsummary) {
  707. XBUS_DBG(PROC, xbus, "Remove proc_entry: " PROC_USBXPP_SUMMARY "\n");
  708. remove_proc_entry(PROC_USBXPP_SUMMARY, xbus->proc_xbus_dir);
  709. procsummary = NULL;
  710. }
  711. #endif
  712. ERR("Calling xbus_disconnect()\n");
  713. xbus_disconnect(xbus); // Blocking until fully deactivated!
  714. }
  715. return retval;
  716. }
  717. /**
  718. * xusb_disconnect
  719. *
  720. * Called by the usb core when the device is removed from the system.
  721. *
  722. * This routine guarantees that the driver will not submit any more urbs
  723. * by clearing dev->udev. It is also supposed to terminate any currently
  724. * active urbs. Unfortunately, usb_bulk_msg(), used in xusb_read(), does
  725. * not provide any way to do this. But at least we can cancel an active
  726. * write.
  727. */
  728. static void xusb_disconnect(struct usb_interface *interface)
  729. {
  730. struct usb_host_interface *iface_desc = usb_altnum_to_altsetting(interface, 0);
  731. xusb_t *xusb;
  732. xbus_t *xbus;
  733. int minor;
  734. int i;
  735. DBG(DEVICES, "CALLED on interface #%d\n", iface_desc->desc.bInterfaceNumber);
  736. /* prevent races with open() */
  737. down (&disconnect_sem);
  738. xusb = usb_get_intfdata(interface);
  739. usb_set_intfdata(interface, NULL);
  740. xusb->present = 0;
  741. xbus = xbus_num(xusb->xbus_num);
  742. /* find our xusb */
  743. for(i = 0; i < MAX_BUSES; i++) {
  744. if(xusb_array[i] == xusb)
  745. break;
  746. }
  747. BUG_ON(i >= MAX_BUSES);
  748. xusb_array[i] = NULL;
  749. #ifdef CONFIG_PROC_FS
  750. if(xbus->proc_xbus_dir) {
  751. XBUS_DBG(PROC, xbus, "Remove proc_entry: " PROC_USBXPP_SUMMARY "\n");
  752. remove_proc_entry(PROC_USBXPP_SUMMARY, xbus->proc_xbus_dir);
  753. }
  754. #endif
  755. xbus_disconnect(xbus); // Blocking until fully deactivated!
  756. down (&xusb->sem);
  757. minor = xusb->minor;
  758. /* give back our minor */
  759. usb_deregister_dev(interface, &xusb_class);
  760. up (&xusb->sem);
  761. DBG(DEVICES, "Semaphore released\n");
  762. XUSB_INFO(xusb, "now disconnected\n");
  763. KZFREE(xusb);
  764. up (&disconnect_sem);
  765. }
  766. static void xpp_send_callback(USB_PASS_CB(urb))
  767. {
  768. struct uframe *uframe = urb_to_uframe(urb);
  769. xframe_t *xframe = &uframe->xframe;
  770. xusb_t *xusb = uframe->xusb;
  771. xbus_t *xbus = xbus_num(xusb->xbus_num);
  772. struct timeval now;
  773. long usec;
  774. int writes = atomic_read(&xusb->pending_writes);
  775. int i;
  776. if(!xbus) {
  777. XUSB_ERR(xusb, "Sent URB does not belong to a valid xbus anymore...\n");
  778. return;
  779. }
  780. //flip_parport_bit(6);
  781. atomic_dec(&xusb->pending_writes);
  782. do_gettimeofday(&now);
  783. xusb->last_tx = xframe->tv_submitted;
  784. usec = usec_diff(&now, &xframe->tv_submitted);
  785. if(usec > xusb->max_tx_delay)
  786. xusb->max_tx_delay = usec;
  787. i = usec / USEC_BUCKET;
  788. if(i >= NUM_BUCKETS)
  789. i = NUM_BUCKETS - 1;
  790. xusb->usb_tx_delay[i]++;
  791. if(unlikely(usec > tx_sluggish)) {
  792. atomic_inc(&xusb->usb_sluggish_count);
  793. if(xusb->sluggish_debounce++ > drop_pcm_after) {
  794. static int rate_limit;
  795. if((rate_limit++ % 1003) == 500) /* skip first messages */
  796. XUSB_NOTICE(xusb,
  797. "Sluggish USB. Dropping next PCM frame (pending_writes=%d)\n",
  798. writes);
  799. atomic_inc(&xusb->pcm_tx_drops);
  800. xusb->drop_next_pcm = 1;
  801. xusb->sluggish_debounce = 0;
  802. }
  803. } else
  804. xusb->sluggish_debounce = 0;
  805. /* sync/async unlink faults aren't errors */
  806. if (urb->status && !(urb->status == -ENOENT || urb->status == -ECONNRESET)) {
  807. static int rate_limit;
  808. if((rate_limit++ % 1000) < 10) {
  809. XUSB_ERR(xusb,
  810. "nonzero write bulk status received: %d (pending_writes=%d)\n",
  811. urb->status, writes);
  812. dump_xframe("usb-write-error", xbus, xframe, DBG_ANY);
  813. }
  814. XUSB_COUNTER(xusb, TX_ERRORS)++;
  815. } else
  816. XUSB_COUNTER(xusb, TX_FRAMES)++;
  817. FREE_SEND_XFRAME(xbus, xframe);
  818. if(!xusb->present)
  819. XUSB_ERR(xusb, "A urb from non-connected device?\n");
  820. }
  821. static void xpp_receive_callback(USB_PASS_CB(urb))
  822. {
  823. struct uframe *uframe = urb_to_uframe(urb);
  824. xframe_t *xframe = &uframe->xframe;
  825. xusb_t *xusb = uframe->xusb;
  826. xbus_t *xbus = xbus_num(xusb->xbus_num);
  827. size_t size;
  828. bool do_resubmit = 1;
  829. bool is_inuse = 0;
  830. struct timeval now;
  831. do_gettimeofday(&now);
  832. atomic_dec(&xusb->pending_reads);
  833. if(!xbus) {
  834. XUSB_ERR(xusb, "Received URB does not belong to a valid xbus anymore...\n");
  835. return;
  836. }
  837. is_inuse = 1;
  838. if(!xusb->present) {
  839. do_resubmit = 0;
  840. goto err;
  841. }
  842. if (urb->status) {
  843. DBG(GENERAL, "nonzero read bulk status received: %d\n", urb->status);
  844. XUSB_COUNTER(xusb, RX_ERRORS)++;
  845. goto err;
  846. }
  847. size = urb->actual_length;
  848. if(size == 0) {
  849. static int rate_limit;
  850. if((rate_limit++ % 5003) == 0)
  851. XUSB_NOTICE(xusb, "Received a zero length URBs (%d)\n", rate_limit);
  852. XUSB_COUNTER(xusb, RCV_ZERO_LEN)++;
  853. goto err;
  854. }
  855. atomic_set(&xframe->frame_len, size);
  856. xframe->tv_received = now;
  857. // if (debug)
  858. // dump_xframe("USB_FRAME_RECEIVE", xbus, xframe, debug);
  859. XUSB_COUNTER(xusb, RX_FRAMES)++;
  860. /* Send UP */
  861. xbus_receive_xframe(xbus, xframe);
  862. end:
  863. if(do_resubmit)
  864. xusb_listen(xusb);
  865. return;
  866. err:
  867. FREE_RECV_XFRAME(xbus, xframe);
  868. goto end;
  869. }
  870. /*------------------------- Initialization -------------------------*/
  871. static void xpp_usb_cleanup(void)
  872. {
  873. if(xusb_cache) {
  874. kmem_cache_destroy(xusb_cache);
  875. xusb_cache = NULL;
  876. }
  877. }
  878. static int __init xpp_usb_init(void)
  879. {
  880. int ret;
  881. //xusb_t *xusb;
  882. INFO("revision %s\n", XPP_VERSION);
  883. xusb_cache = kmem_cache_create("xusb_cache",
  884. sizeof(xframe_t) + XFRAME_DATASIZE,
  885. #if (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,22)) && defined(CONFIG_SLUB)
  886. 0, SLAB_STORE_USER,
  887. #else
  888. 0, 0,
  889. #endif
  890. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
  891. NULL,
  892. #endif
  893. NULL);
  894. if(!xusb_cache) {
  895. ret = -ENOMEM;
  896. goto failure;
  897. }
  898. /* register this driver with the USB subsystem */
  899. ret = usb_register(&xusb_driver);
  900. if (ret) {
  901. ERR("usb_register failed. Error number %d\n", ret);
  902. goto failure;
  903. }
  904. return 0;
  905. failure:
  906. xpp_usb_cleanup();
  907. return ret;
  908. }
  909. static void __exit xpp_usb_shutdown(void)
  910. {
  911. DBG(GENERAL, "\n");
  912. /* deregister this driver with the USB subsystem */
  913. usb_deregister(&xusb_driver);
  914. xpp_usb_cleanup();
  915. }
  916. #ifdef CONFIG_PROC_FS
  917. static int xusb_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)
  918. {
  919. int len = 0;
  920. unsigned long flags;
  921. int i;
  922. //unsigned long stamp = jiffies;
  923. xusb_t *xusb = data;
  924. uint usb_tx_delay[NUM_BUCKETS];
  925. const int mark_limit = tx_sluggish/USEC_BUCKET;
  926. if(!xusb)
  927. goto out;
  928. // TODO: probably needs a per-xusb lock:
  929. spin_lock_irqsave(&xusb_lock, flags);
  930. len += sprintf(page + len, "Device: %03d/%03d\n",
  931. xusb->udev->bus->busnum,
  932. xusb->udev->devnum
  933. );
  934. len += sprintf(page + len, "USB: manufacturer=%s\n", xusb->manufacturer);
  935. len += sprintf(page + len, "USB: product=%s\n", xusb->product);
  936. len += sprintf(page + len, "USB: serial=%s\n", xusb->serial);
  937. len += sprintf(page + len, "Minor: %d\nModel Info: %s\n",
  938. xusb->minor, xusb->model_info->desc);
  939. len += sprintf(page + len, "Endpoints:\n"
  940. "\tIn: 0x%02X - Size: %d)\n"
  941. "\tOut: 0x%02X - Size: %d)\n",
  942. xusb->endpoints[XUSB_RECV].ep_addr,
  943. xusb->endpoints[XUSB_RECV].max_size,
  944. xusb->endpoints[XUSB_SEND].ep_addr,
  945. xusb->endpoints[XUSB_SEND].max_size
  946. );
  947. len += sprintf(page + len, "\npending_writes=%d\n", atomic_read(&xusb->pending_writes));
  948. len += sprintf(page + len, "pending_reads=%d\n", atomic_read(&xusb->pending_reads));
  949. len += sprintf(page + len, "max_tx_delay=%d\n", xusb->max_tx_delay);
  950. xusb->max_tx_delay = 0;
  951. #ifdef DEBUG_PCM_TIMING
  952. len += sprintf(page + len, "\nstamp_last_pcm_read=%lld accumulate_diff=%lld\n", stamp_last_pcm_read, accumulate_diff);
  953. #endif
  954. memcpy(usb_tx_delay, xusb->usb_tx_delay, sizeof(usb_tx_delay));
  955. len += sprintf(page + len, "usb_tx_delay[%d,%d,%d]: ",
  956. USEC_BUCKET, BUCKET_START, NUM_BUCKETS);
  957. for(i = BUCKET_START; i < NUM_BUCKETS; i++) {
  958. len += sprintf(page + len, "%6d ",
  959. usb_tx_delay[i]);
  960. if(i == mark_limit)
  961. len += sprintf(page + len, "| ");
  962. }
  963. len += sprintf(page + len, "\nPCM_TX_DROPS: %5d (sluggish: %d)\n",
  964. atomic_read(&xusb->pcm_tx_drops),
  965. atomic_read(&xusb->usb_sluggish_count)
  966. );
  967. len += sprintf(page + len, "\nCOUNTERS:\n");
  968. for(i = 0; i < XUSB_COUNTER_MAX; i++) {
  969. len += sprintf(page + len, "\t%-15s = %d\n", xusb_counters[i].name, xusb->counters[i]);
  970. }
  971. #if 0
  972. len += sprintf(page + len, "<-- len=%d\n", len);
  973. #endif
  974. spin_unlock_irqrestore(&xusb_lock, flags);
  975. out:
  976. if (len <= off+count)
  977. *eof = 1;
  978. *start = page + off;
  979. len -= off;
  980. if (len > count)
  981. len = count;
  982. if (len < 0)
  983. len = 0;
  984. return len;
  985. }
  986. #endif
  987. MODULE_DESCRIPTION("XPP USB Transport Driver");
  988. MODULE_AUTHOR("Oron Peled <oron@actcom.co.il>");
  989. MODULE_LICENSE("GPL");
  990. MODULE_VERSION(XPP_VERSION);
  991. module_init(xpp_usb_init);
  992. module_exit(xpp_usb_shutdown);