Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / usbfront / usbfront-dbg.c
1 /*
2  * usbfront-dbg.c
3  *
4  * Xen USB Virtual Host Controller - debugging
5  *
6  * Copyright (C) 2009, FUJITSU LABORATORIES LTD.
7  * Author: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, see <http://www.gnu.org/licenses/>.
21  *
22  * or, by your choice,
23  *
24  * When distributed separately from the Linux kernel or incorporated into
25  * other software packages, subject to the following license:
26  *
27  * Permission is hereby granted, free of charge, to any person obtaining a copy
28  * of this software and associated documentation files (the "Software"), to
29  * deal in the Software without restriction, including without limitation the
30  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
31  * sell copies of the Software, and to permit persons to whom the Software is
32  * furnished to do so, subject to the following conditions:
33  *
34  * The above copyright notice and this permission notice shall be included in
35  * all copies or substantial portions of the Software.
36  *
37  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
43  * DEALINGS IN THE SOFTWARE.
44  */
45
46 static ssize_t show_statistics(struct device *dev,
47                                struct device_attribute *attr, char *buf)
48 {
49         struct usb_hcd *hcd;
50         struct usbfront_info *info;
51         unsigned long flags;
52         unsigned temp, size;
53         char *next;
54
55         hcd = dev_get_drvdata(dev);
56         info = hcd_to_info(hcd);
57         next = buf;
58         size = PAGE_SIZE;
59
60         spin_lock_irqsave(&info->lock, flags);
61
62         temp = scnprintf(next, size,
63                         "bus %s, device %s\n"
64                         "%s\n"
65                         "xenhcd, hcd state %d\n",
66                         hcd->self.controller->bus->name,
67                         dev_name(hcd->self.controller),
68                         hcd->product_desc,
69                         hcd->state);
70         size -= temp;
71         next += temp;
72
73 #ifdef XENHCD_STATS
74         temp = scnprintf(next, size,
75                 "complete %ld unlink %ld ring_full %ld\n",
76                 info->stats.complete, info->stats.unlink,
77                 info->stats.ring_full);
78         size -= temp;
79         next += temp;
80 #endif
81
82         spin_unlock_irqrestore(&info->lock, flags);
83
84         return PAGE_SIZE - size;
85 }
86
87 static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
88
89 static inline void create_debug_file(struct usbfront_info *info)
90 {
91         struct device *dev = info_to_hcd(info)->self.controller;
92         if (device_create_file(dev, &dev_attr_statistics))
93                 pr_warning("statistics file not created for %s\n",
94                            info_to_hcd(info)->self.bus_name);
95 }
96
97 static inline void remove_debug_file(struct usbfront_info *info)
98 {
99         struct device *dev = info_to_hcd(info)->self.controller;
100         device_remove_file(dev, &dev_attr_statistics);
101 }