blob: 53660186bb236f7fe09eec5a974d07d95d59cb34 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* drivers/usb/gadget/f_diag.c
2 * Diag Function Device - Route ARM9 and ARM11 DIAG messages
3 * between HOST and DEVICE.
4 * Copyright (C) 2007 Google, Inc.
5 * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved.
6 * Author: Brian Swetland <swetland@google.com>
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17#include <linux/init.h>
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/platform_device.h>
21
22#include <mach/usbdiag.h>
23#include <mach/rpc_hsusb.h>
24
25#include <linux/usb/composite.h>
26#include <linux/usb/gadget.h>
27#include <linux/workqueue.h>
28#include <linux/debugfs.h>
29
30static DEFINE_SPINLOCK(ch_lock);
31static LIST_HEAD(usb_diag_ch_list);
32
33static struct usb_interface_descriptor intf_desc = {
34 .bLength = sizeof intf_desc,
35 .bDescriptorType = USB_DT_INTERFACE,
36 .bNumEndpoints = 2,
37 .bInterfaceClass = 0xFF,
38 .bInterfaceSubClass = 0xFF,
39 .bInterfaceProtocol = 0xFF,
40};
41
42static struct usb_endpoint_descriptor hs_bulk_in_desc = {
43 .bLength = USB_DT_ENDPOINT_SIZE,
44 .bDescriptorType = USB_DT_ENDPOINT,
45 .bEndpointAddress = USB_DIR_IN,
46 .bmAttributes = USB_ENDPOINT_XFER_BULK,
47 .wMaxPacketSize = __constant_cpu_to_le16(512),
48 .bInterval = 0,
49};
50static struct usb_endpoint_descriptor fs_bulk_in_desc = {
51 .bLength = USB_DT_ENDPOINT_SIZE,
52 .bDescriptorType = USB_DT_ENDPOINT,
53 .bEndpointAddress = USB_DIR_IN,
54 .bmAttributes = USB_ENDPOINT_XFER_BULK,
55 .wMaxPacketSize = __constant_cpu_to_le16(64),
56 .bInterval = 0,
57};
58
59static struct usb_endpoint_descriptor hs_bulk_out_desc = {
60 .bLength = USB_DT_ENDPOINT_SIZE,
61 .bDescriptorType = USB_DT_ENDPOINT,
62 .bEndpointAddress = USB_DIR_OUT,
63 .bmAttributes = USB_ENDPOINT_XFER_BULK,
64 .wMaxPacketSize = __constant_cpu_to_le16(512),
65 .bInterval = 0,
66};
67
68static struct usb_endpoint_descriptor fs_bulk_out_desc = {
69 .bLength = USB_DT_ENDPOINT_SIZE,
70 .bDescriptorType = USB_DT_ENDPOINT,
71 .bEndpointAddress = USB_DIR_OUT,
72 .bmAttributes = USB_ENDPOINT_XFER_BULK,
73 .wMaxPacketSize = __constant_cpu_to_le16(64),
74 .bInterval = 0,
75};
76
77static struct usb_descriptor_header *fs_diag_desc[] = {
78 (struct usb_descriptor_header *) &intf_desc,
79 (struct usb_descriptor_header *) &fs_bulk_in_desc,
80 (struct usb_descriptor_header *) &fs_bulk_out_desc,
81 NULL,
82 };
83static struct usb_descriptor_header *hs_diag_desc[] = {
84 (struct usb_descriptor_header *) &intf_desc,
85 (struct usb_descriptor_header *) &hs_bulk_in_desc,
86 (struct usb_descriptor_header *) &hs_bulk_out_desc,
87 NULL,
88};
89
90/**
91 * struct diag_context - USB diag function driver private structure
92 * @function: function structure for USB interface
93 * @out: USB OUT endpoint struct
94 * @in: USB IN endpoint struct
95 * @in_desc: USB IN endpoint descriptor struct
96 * @out_desc: USB OUT endpoint descriptor struct
97 * @read_pool: List of requests used for Rx (OUT ep)
98 * @write_pool: List of requests used for Tx (IN ep)
99 * @config_work: Work item schedule after interface is configured to notify
100 * CONNECT event to diag char driver and updating product id
101 * and serial number to MODEM/IMEM.
102 * @lock: Spinlock to proctect read_pool, write_pool lists
103 * @cdev: USB composite device struct
104 * @ch: USB diag channel
105 *
106 */
107struct diag_context {
108 struct usb_function function;
109 struct usb_ep *out;
110 struct usb_ep *in;
111 struct usb_endpoint_descriptor *in_desc;
112 struct usb_endpoint_descriptor *out_desc;
113 struct list_head read_pool;
114 struct list_head write_pool;
115 struct work_struct config_work;
116 spinlock_t lock;
117 unsigned configured;
118 struct usb_composite_dev *cdev;
119 int (*update_pid_and_serial_num)(uint32_t, const char *);
120 struct usb_diag_ch ch;
121
122 /* pkt counters */
123 unsigned long dpkts_tolaptop;
124 unsigned long dpkts_tomodem;
125 unsigned dpkts_tolaptop_pending;
126};
127
128static inline struct diag_context *func_to_diag(struct usb_function *f)
129{
130 return container_of(f, struct diag_context, function);
131}
132
133static void usb_config_work_func(struct work_struct *work)
134{
135 struct diag_context *ctxt = container_of(work,
136 struct diag_context, config_work);
137 struct usb_composite_dev *cdev = ctxt->cdev;
138 struct usb_gadget_strings *table;
139 struct usb_string *s;
140
141 if (ctxt->ch.notify)
142 ctxt->ch.notify(ctxt->ch.priv, USB_DIAG_CONNECT, NULL);
143
144 if (!ctxt->update_pid_and_serial_num)
145 return;
146
147 /* pass on product id and serial number to dload */
148 if (!cdev->desc.iSerialNumber) {
149 ctxt->update_pid_and_serial_num(
150 cdev->desc.idProduct, 0);
151 return;
152 }
153
154 /*
155 * Serial number is filled by the composite driver. So
156 * it is fair enough to assume that it will always be
157 * found at first table of strings.
158 */
159 table = *(cdev->driver->strings);
160 for (s = table->strings; s && s->s; s++)
161 if (s->id == cdev->desc.iSerialNumber) {
162 ctxt->update_pid_and_serial_num(
163 cdev->desc.idProduct, s->s);
164 break;
165 }
166}
167
168static void diag_write_complete(struct usb_ep *ep,
169 struct usb_request *req)
170{
171 struct diag_context *ctxt = ep->driver_data;
172 struct diag_request *d_req = req->context;
173 unsigned long flags;
174
175 ctxt->dpkts_tolaptop_pending--;
176
177 if (!req->status) {
178 if ((req->length >= ep->maxpacket) &&
179 ((req->length % ep->maxpacket) == 0)) {
180 ctxt->dpkts_tolaptop_pending++;
181 req->length = 0;
182 d_req->actual = req->actual;
183 d_req->status = req->status;
184 /* Queue zero length packet */
185 usb_ep_queue(ctxt->in, req, GFP_ATOMIC);
186 return;
187 }
188 }
189
190 spin_lock_irqsave(&ctxt->lock, flags);
191 list_add_tail(&req->list, &ctxt->write_pool);
192 if (req->length != 0) {
193 d_req->actual = req->actual;
194 d_req->status = req->status;
195 }
196 spin_unlock_irqrestore(&ctxt->lock, flags);
197
198 if (ctxt->ch.notify)
199 ctxt->ch.notify(ctxt->ch.priv, USB_DIAG_WRITE_DONE, d_req);
200}
201
202static void diag_read_complete(struct usb_ep *ep,
203 struct usb_request *req)
204{
205 struct diag_context *ctxt = ep->driver_data;
206 struct diag_request *d_req = req->context;
207 unsigned long flags;
208
209 d_req->actual = req->actual;
210 d_req->status = req->status;
211
212 spin_lock_irqsave(&ctxt->lock, flags);
213 list_add_tail(&req->list, &ctxt->read_pool);
214 spin_unlock_irqrestore(&ctxt->lock, flags);
215
216 ctxt->dpkts_tomodem++;
217
218 if (ctxt->ch.notify)
219 ctxt->ch.notify(ctxt->ch.priv, USB_DIAG_READ_DONE, d_req);
220}
221
222/**
223 * usb_diag_open() - Open a diag channel over USB
224 * @name: Name of the channel
225 * @priv: Private structure pointer which will be passed in notify()
226 * @notify: Callback function to receive notifications
227 *
228 * This function iterates overs the available channels and returns
229 * the channel handler if the name matches. The notify callback is called
230 * for CONNECT, DISCONNECT, READ_DONE and WRITE_DONE events.
231 *
232 */
233struct usb_diag_ch *usb_diag_open(const char *name, void *priv,
234 void (*notify)(void *, unsigned, struct diag_request *))
235{
236 struct usb_diag_ch *ch;
237 struct diag_context *ctxt;
238 unsigned long flags;
239 int found = 0;
240
241 spin_lock_irqsave(&ch_lock, flags);
242 /* Check if we already have a channel with this name */
243 list_for_each_entry(ch, &usb_diag_ch_list, list) {
244 if (!strcmp(name, ch->name)) {
245 found = 1;
246 break;
247 }
248 }
249 spin_unlock_irqrestore(&ch_lock, flags);
250
251 if (!found) {
252 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
253 if (!ctxt)
254 return ERR_PTR(-ENOMEM);
255
256 ch = &ctxt->ch;
257 }
258
259 ch->name = name;
260 ch->priv = priv;
261 ch->notify = notify;
262
263 spin_lock_irqsave(&ch_lock, flags);
264 list_add_tail(&ch->list, &usb_diag_ch_list);
265 spin_unlock_irqrestore(&ch_lock, flags);
266
267 return ch;
268}
269EXPORT_SYMBOL(usb_diag_open);
270
271/**
272 * usb_diag_close() - Close a diag channel over USB
273 * @ch: Channel handler
274 *
275 * This function closes the diag channel.
276 *
277 */
278void usb_diag_close(struct usb_diag_ch *ch)
279{
280 struct diag_context *dev = container_of(ch, struct diag_context, ch);
281 unsigned long flags;
282
283 spin_lock_irqsave(&ch_lock, flags);
284 ch->priv = NULL;
285 ch->notify = NULL;
286 /* Free-up the resources if channel is no more active */
287 if (!ch->priv_usb) {
288 list_del(&ch->list);
289 kfree(dev);
290 }
291
292 spin_unlock_irqrestore(&ch_lock, flags);
293}
294EXPORT_SYMBOL(usb_diag_close);
295
296/**
297 * usb_diag_free_req() - Free USB requests
298 * @ch: Channel handler
299 *
300 * This function free read and write USB requests for the interface
301 * associated with this channel.
302 *
303 */
304void usb_diag_free_req(struct usb_diag_ch *ch)
305{
306 struct diag_context *ctxt = ch->priv_usb;
307 struct usb_request *req;
308 struct list_head *act, *tmp;
309
310 if (!ctxt)
311 return;
312
313 list_for_each_safe(act, tmp, &ctxt->write_pool) {
314 req = list_entry(act, struct usb_request, list);
315 list_del(&req->list);
316 usb_ep_free_request(ctxt->in, req);
317 }
318
319 list_for_each_safe(act, tmp, &ctxt->read_pool) {
320 req = list_entry(act, struct usb_request, list);
321 list_del(&req->list);
322 usb_ep_free_request(ctxt->out, req);
323 }
324}
325EXPORT_SYMBOL(usb_diag_free_req);
326
327/**
328 * usb_diag_alloc_req() - Allocate USB requests
329 * @ch: Channel handler
330 * @n_write: Number of requests for Tx
331 * @n_read: Number of requests for Rx
332 *
333 * This function allocate read and write USB requests for the interface
334 * associated with this channel. The actual buffer is not allocated.
335 * The buffer is passed by diag char driver.
336 *
337 */
338int usb_diag_alloc_req(struct usb_diag_ch *ch, int n_write, int n_read)
339{
340 struct diag_context *ctxt = ch->priv_usb;
341 struct usb_request *req;
342 int i;
343
344 if (!ctxt)
345 return -ENODEV;
346
347 for (i = 0; i < n_write; i++) {
348 req = usb_ep_alloc_request(ctxt->in, GFP_ATOMIC);
349 if (!req)
350 goto fail;
351 req->complete = diag_write_complete;
352 list_add_tail(&req->list, &ctxt->write_pool);
353 }
354
355 for (i = 0; i < n_read; i++) {
356 req = usb_ep_alloc_request(ctxt->out, GFP_ATOMIC);
357 if (!req)
358 goto fail;
359 req->complete = diag_read_complete;
360 list_add_tail(&req->list, &ctxt->read_pool);
361 }
362
363 return 0;
364
365fail:
366 usb_diag_free_req(ch);
367 return -ENOMEM;
368
369}
370EXPORT_SYMBOL(usb_diag_alloc_req);
371
372/**
373 * usb_diag_read() - Read data from USB diag channel
374 * @ch: Channel handler
375 * @d_req: Diag request struct
376 *
377 * Enqueue a request on OUT endpoint of the interface corresponding to this
378 * channel. This function returns proper error code when interface is not
379 * in configured state, no Rx requests available and ep queue is failed.
380 *
381 * This function operates asynchronously. READ_DONE event is notified after
382 * completion of OUT request.
383 *
384 */
385int usb_diag_read(struct usb_diag_ch *ch, struct diag_request *d_req)
386{
387 struct diag_context *ctxt = ch->priv_usb;
388 unsigned long flags;
389 struct usb_request *req;
390
391 spin_lock_irqsave(&ctxt->lock, flags);
392
393 if (!ctxt->configured) {
394 spin_unlock_irqrestore(&ctxt->lock, flags);
395 return -EIO;
396 }
397
398 if (list_empty(&ctxt->read_pool)) {
399 spin_unlock_irqrestore(&ctxt->lock, flags);
400 ERROR(ctxt->cdev, "%s: no requests available\n", __func__);
401 return -EAGAIN;
402 }
403
404 req = list_first_entry(&ctxt->read_pool, struct usb_request, list);
405 list_del(&req->list);
406 spin_unlock_irqrestore(&ctxt->lock, flags);
407
408 req->buf = d_req->buf;
409 req->length = d_req->length;
410 req->context = d_req;
411 if (usb_ep_queue(ctxt->out, req, GFP_ATOMIC)) {
412 /* If error add the link to linked list again*/
413 spin_lock_irqsave(&ctxt->lock, flags);
414 list_add_tail(&req->list, &ctxt->read_pool);
415 spin_unlock_irqrestore(&ctxt->lock, flags);
416 ERROR(ctxt->cdev, "%s: cannot queue"
417 " read request\n", __func__);
418 return -EIO;
419 }
420
421 return 0;
422}
423EXPORT_SYMBOL(usb_diag_read);
424
425/**
426 * usb_diag_write() - Write data from USB diag channel
427 * @ch: Channel handler
428 * @d_req: Diag request struct
429 *
430 * Enqueue a request on IN endpoint of the interface corresponding to this
431 * channel. This function returns proper error code when interface is not
432 * in configured state, no Tx requests available and ep queue is failed.
433 *
434 * This function operates asynchronously. WRITE_DONE event is notified after
435 * completion of IN request.
436 *
437 */
438int usb_diag_write(struct usb_diag_ch *ch, struct diag_request *d_req)
439{
440 struct diag_context *ctxt = ch->priv_usb;
441 unsigned long flags;
442 struct usb_request *req = NULL;
443
444 spin_lock_irqsave(&ctxt->lock, flags);
445
446 if (!ctxt->configured) {
447 spin_unlock_irqrestore(&ctxt->lock, flags);
448 return -EIO;
449 }
450
451 if (list_empty(&ctxt->write_pool)) {
452 spin_unlock_irqrestore(&ctxt->lock, flags);
453 ERROR(ctxt->cdev, "%s: no requests available\n", __func__);
454 return -EAGAIN;
455 }
456
457 req = list_first_entry(&ctxt->write_pool, struct usb_request, list);
458 list_del(&req->list);
459 spin_unlock_irqrestore(&ctxt->lock, flags);
460
461 req->buf = d_req->buf;
462 req->length = d_req->length;
463 req->context = d_req;
464 if (usb_ep_queue(ctxt->in, req, GFP_ATOMIC)) {
465 /* If error add the link to linked list again*/
466 spin_lock_irqsave(&ctxt->lock, flags);
467 list_add_tail(&req->list, &ctxt->write_pool);
468 spin_unlock_irqrestore(&ctxt->lock, flags);
469 ERROR(ctxt->cdev, "%s: cannot queue"
470 " read request\n", __func__);
471 return -EIO;
472 }
473
474 ctxt->dpkts_tolaptop++;
475 ctxt->dpkts_tolaptop_pending++;
476
477 return 0;
478}
479EXPORT_SYMBOL(usb_diag_write);
480
481static void diag_function_disable(struct usb_function *f)
482{
483 struct diag_context *dev = func_to_diag(f);
484 unsigned long flags;
485
486 DBG(dev->cdev, "diag_function_disable\n");
487
488 spin_lock_irqsave(&dev->lock, flags);
489 dev->configured = 0;
490 spin_unlock_irqrestore(&dev->lock, flags);
491
492 if (dev->ch.notify)
493 dev->ch.notify(dev->ch.priv, USB_DIAG_DISCONNECT, NULL);
494
495 usb_ep_disable(dev->in);
496 dev->in->driver_data = NULL;
497
498 usb_ep_disable(dev->out);
499 dev->out->driver_data = NULL;
500
501}
502
503static int diag_function_set_alt(struct usb_function *f,
504 unsigned intf, unsigned alt)
505{
506 struct diag_context *dev = func_to_diag(f);
507 struct usb_composite_dev *cdev = f->config->cdev;
508 unsigned long flags;
509 struct usb_diag_ch *ch;
510 int rc = 0;
511
512 dev->in_desc = ep_choose(cdev->gadget,
513 &hs_bulk_in_desc, &fs_bulk_in_desc);
514 dev->out_desc = ep_choose(cdev->gadget,
515 &hs_bulk_out_desc, &fs_bulk_out_desc);
516 dev->in->driver_data = dev;
517 rc = usb_ep_enable(dev->in, dev->in_desc);
518 if (rc) {
519 ERROR(dev->cdev, "can't enable %s, result %d\n",
520 dev->in->name, rc);
521 return rc;
522 }
523 dev->out->driver_data = dev;
524 rc = usb_ep_enable(dev->out, dev->out_desc);
525 if (rc) {
526 ERROR(dev->cdev, "can't enable %s, result %d\n",
527 dev->out->name, rc);
528 usb_ep_disable(dev->in);
529 return rc;
530 }
531 schedule_work(&dev->config_work);
532
533 list_for_each_entry(ch, &usb_diag_ch_list, list) {
534 struct diag_context *ctxt;
535
536 ctxt = ch->priv_usb;
537 ctxt->dpkts_tolaptop = 0;
538 ctxt->dpkts_tomodem = 0;
539 ctxt->dpkts_tolaptop_pending = 0;
540 }
541
542 spin_lock_irqsave(&dev->lock, flags);
543 dev->configured = 1;
544 spin_unlock_irqrestore(&dev->lock, flags);
545
546 return rc;
547}
548
549static void diag_function_unbind(struct usb_configuration *c,
550 struct usb_function *f)
551{
552 struct diag_context *ctxt = func_to_diag(f);
553
554 if (gadget_is_dualspeed(c->cdev->gadget))
555 usb_free_descriptors(f->hs_descriptors);
556
557 usb_free_descriptors(f->descriptors);
558 ctxt->ch.priv_usb = NULL;
559}
560
561static int diag_function_bind(struct usb_configuration *c,
562 struct usb_function *f)
563{
564 struct usb_composite_dev *cdev = c->cdev;
565 struct diag_context *ctxt = func_to_diag(f);
566 struct usb_ep *ep;
567 int status = -ENODEV;
568
569 intf_desc.bInterfaceNumber = usb_interface_id(c, f);
570
571 ep = usb_ep_autoconfig(cdev->gadget, &fs_bulk_in_desc);
572 ctxt->in = ep;
573 ep->driver_data = ctxt;
574
575 ep = usb_ep_autoconfig(cdev->gadget, &fs_bulk_out_desc);
576 ctxt->out = ep;
577 ep->driver_data = ctxt;
578
579 /* copy descriptors, and track endpoint copies */
580 f->descriptors = usb_copy_descriptors(fs_diag_desc);
581 if (!f->descriptors)
582 goto fail;
583
584 if (gadget_is_dualspeed(c->cdev->gadget)) {
585 hs_bulk_in_desc.bEndpointAddress =
586 fs_bulk_in_desc.bEndpointAddress;
587 hs_bulk_out_desc.bEndpointAddress =
588 fs_bulk_out_desc.bEndpointAddress;
589
590 /* copy descriptors, and track endpoint copies */
591 f->hs_descriptors = usb_copy_descriptors(hs_diag_desc);
592 }
593 return 0;
594fail:
595 if (ctxt->out)
596 ctxt->out->driver_data = NULL;
597 if (ctxt->in)
598 ctxt->in->driver_data = NULL;
599 return status;
600
601}
602
603int diag_function_add(struct usb_configuration *c, const char *name,
604 int (*update_pid)(uint32_t, const char *))
605{
606 struct diag_context *dev;
607 struct usb_diag_ch *_ch;
608 int found = 0, ret;
609
610 DBG(c->cdev, "diag_function_add\n");
611
612 list_for_each_entry(_ch, &usb_diag_ch_list, list) {
613 if (!strcmp(name, _ch->name)) {
614 found = 1;
615 break;
616 }
617 }
618 if (!found) {
619 ERROR(c->cdev, "unable to get diag usb channel\n");
620 return -ENODEV;
621 }
622
623 dev = container_of(_ch, struct diag_context, ch);
624 /* claim the channel for this USB interface */
625 _ch->priv_usb = dev;
626
627 dev->update_pid_and_serial_num = update_pid;
628 dev->cdev = c->cdev;
629 dev->function.name = _ch->name;
630 dev->function.descriptors = fs_diag_desc;
631 dev->function.hs_descriptors = hs_diag_desc;
632 dev->function.bind = diag_function_bind;
633 dev->function.unbind = diag_function_unbind;
634 dev->function.set_alt = diag_function_set_alt;
635 dev->function.disable = diag_function_disable;
636 spin_lock_init(&dev->lock);
637 INIT_LIST_HEAD(&dev->read_pool);
638 INIT_LIST_HEAD(&dev->write_pool);
639 INIT_WORK(&dev->config_work, usb_config_work_func);
640
641 ret = usb_add_function(c, &dev->function);
642 if (ret) {
643 INFO(c->cdev, "usb_add_function failed\n");
644 _ch->priv_usb = NULL;
645 }
646
647 return ret;
648}
649
650
651#if defined(CONFIG_DEBUG_FS)
652static char debug_buffer[PAGE_SIZE];
653
654static ssize_t debug_read_stats(struct file *file, char __user *ubuf,
655 size_t count, loff_t *ppos)
656{
657 char *buf = debug_buffer;
658 int temp = 0;
659 struct usb_diag_ch *ch;
660
661 list_for_each_entry(ch, &usb_diag_ch_list, list) {
662 struct diag_context *ctxt;
663
664 ctxt = ch->priv_usb;
665
666 temp += scnprintf(buf + temp, PAGE_SIZE - temp,
667 "---Name: %s---\n"
668 "dpkts_tolaptop: %lu\n"
669 "dpkts_tomodem: %lu\n"
670 "pkts_tolaptop_pending: %u\n",
671 ch->name, ctxt->dpkts_tolaptop,
672 ctxt->dpkts_tomodem,
673 ctxt->dpkts_tolaptop_pending);
674 }
675
676 return simple_read_from_buffer(ubuf, count, ppos, buf, temp);
677}
678
679static ssize_t debug_reset_stats(struct file *file, const char __user *buf,
680 size_t count, loff_t *ppos)
681{
682 struct usb_diag_ch *ch;
683
684 list_for_each_entry(ch, &usb_diag_ch_list, list) {
685 struct diag_context *ctxt;
686
687 ctxt = ch->priv_usb;
688
689 ctxt->dpkts_tolaptop = 0;
690 ctxt->dpkts_tomodem = 0;
691 ctxt->dpkts_tolaptop_pending = 0;
692 }
693
694 return count;
695}
696
697static int debug_open(struct inode *inode, struct file *file)
698{
699 return 0;
700}
701
702static const struct file_operations debug_fdiag_ops = {
703 .open = debug_open,
704 .read = debug_read_stats,
705 .write = debug_reset_stats,
706};
707
708static void fdiag_debugfs_init(void)
709{
710 struct dentry *dent;
711
712 dent = debugfs_create_dir("usb_diag", 0);
713 if (IS_ERR(dent))
714 return;
715
716 debugfs_create_file("status", 0444, dent, 0, &debug_fdiag_ops);
717}
718#else
719static void fdiag_debugfs_init(void)
720{
721 return;
722}
723#endif
724
725static void diag_cleanup(void)
726{
727 struct diag_context *dev;
728 struct list_head *act, *tmp;
729 struct usb_diag_ch *_ch;
730 unsigned long flags;
731
732 list_for_each_safe(act, tmp, &usb_diag_ch_list) {
733 _ch = list_entry(act, struct usb_diag_ch, list);
734 dev = container_of(_ch, struct diag_context, ch);
735
736 spin_lock_irqsave(&ch_lock, flags);
737 /* Free if diagchar is not using the channel anymore */
738 if (!_ch->priv) {
739 list_del(&_ch->list);
740 kfree(dev);
741 }
742 spin_unlock_irqrestore(&ch_lock, flags);
743
744 }
745}
746
747static int diag_setup(void)
748{
749 fdiag_debugfs_init();
750
751 return 0;
752}