~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/staging/usbip/stub_main.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * USA.
18
18
 */
19
19
 
20
 
#include <linux/slab.h>
 
20
#include <linux/string.h>
21
21
 
22
22
#include "usbip_common.h"
23
23
#include "stub.h"
24
24
 
25
 
/* Version Information */
26
 
#define DRIVER_VERSION "1.0"
27
25
#define DRIVER_AUTHOR "Takahiro Hirofuchi"
28
 
#define DRIVER_DESC "Stub Driver for USB/IP"
 
26
#define DRIVER_DESC "USB/IP Host Driver"
29
27
 
30
28
/* stub_priv is allocated from stub_priv_cache */
31
29
struct kmem_cache *stub_priv_cache;
32
30
 
33
 
/*-------------------------------------------------------------------------*/
34
 
 
35
 
/* Define sysfs entries for the usbip driver */
36
 
 
37
 
 
38
31
/*
39
32
 * busid_tables defines matching busids that usbip can grab. A user can change
40
33
 * dynamically what device is locally used and what device is exported to a
44
37
static struct bus_id_priv busid_table[MAX_BUSID];
45
38
static spinlock_t busid_table_lock;
46
39
 
47
 
 
48
40
int match_busid(const char *busid)
49
41
{
50
42
        int i;
148
140
 
149
141
        return -1;
150
142
}
 
143
 
151
144
static void init_busid_table(void)
152
145
{
153
146
        int i;
154
147
 
155
 
 
156
148
        for (i = 0; i < MAX_BUSID; i++) {
157
149
                memset(busid_table[i].name, 0, BUSID_SIZE);
158
150
                busid_table[i].status = STUB_BUSID_OTHER;
160
152
                busid_table[i].sdev = NULL;
161
153
                busid_table[i].shutdown_busid = 0;
162
154
        }
 
155
 
163
156
        spin_lock_init(&busid_table_lock);
164
157
}
165
158
 
166
159
static ssize_t store_match_busid(struct device_driver *dev, const char *buf,
167
 
                size_t count)
 
160
                                 size_t count)
168
161
{
169
162
        int len;
170
163
        char busid[BUSID_SIZE];
181
174
 
182
175
        strncpy(busid, buf + 4, BUSID_SIZE);
183
176
 
184
 
 
185
177
        if (!strncmp(buf, "add ", 4)) {
186
178
                if (add_match_busid(busid) < 0)
187
179
                        return -ENOMEM;
188
180
                else {
189
 
                        usbip_udbg("add busid %s\n", busid);
 
181
                        pr_debug("add busid %s\n", busid);
190
182
                        return count;
191
183
                }
192
184
        } else if (!strncmp(buf, "del ", 4)) {
193
185
                if (del_match_busid(busid) < 0)
194
186
                        return -ENODEV;
195
187
                else {
196
 
                        usbip_udbg("del busid %s\n", busid);
 
188
                        pr_debug("del busid %s\n", busid);
197
189
                        return count;
198
190
                }
199
191
        } else
200
192
                return -EINVAL;
201
193
}
202
 
 
203
194
static DRIVER_ATTR(match_busid, S_IRUSR|S_IWUSR, show_match_busid,
204
 
                                                        store_match_busid);
205
 
 
206
 
 
207
 
 
208
 
/*-------------------------------------------------------------------------*/
209
 
 
210
 
/* Cleanup functions used to free private data */
 
195
                   store_match_busid);
211
196
 
212
197
static struct stub_priv *stub_priv_pop_from_listhead(struct list_head *listhead)
213
198
{
254
239
{
255
240
        struct stub_priv *priv;
256
241
 
257
 
        usbip_udbg("free sdev %p\n", sdev);
 
242
        dev_dbg(&sdev->udev->dev, "free sdev %p\n", sdev);
258
243
 
259
244
        while ((priv = stub_priv_pop(sdev))) {
260
245
                struct urb *urb = priv->urb;
261
246
 
262
 
                usbip_udbg("   free urb %p\n", urb);
 
247
                dev_dbg(&sdev->udev->dev, "free urb %p\n", urb);
263
248
                usb_kill_urb(urb);
264
249
 
265
250
                kmem_cache_free(stub_priv_cache, priv);
266
251
 
267
 
                if (urb->transfer_buffer != NULL)
268
 
                        kfree(urb->transfer_buffer);
269
 
 
270
 
                if (urb->setup_packet != NULL)
271
 
                        kfree(urb->setup_packet);
 
252
                kfree(urb->transfer_buffer);
 
253
                kfree(urb->setup_packet);
272
254
 
273
255
                usb_free_urb(urb);
274
256
        }
275
257
}
276
258
 
277
 
 
278
 
/*-------------------------------------------------------------------------*/
279
 
 
280
259
static int __init usb_stub_init(void)
281
260
{
282
261
        int ret;
286
265
                                            SLAB_HWCACHE_ALIGN, NULL);
287
266
 
288
267
        if (!stub_priv_cache) {
289
 
                printk(KERN_ERR KBUILD_MODNAME
290
 
                       ": create stub_priv_cache error\n");
 
268
                pr_err("create stub_priv_cache error\n");
291
269
                return -ENOMEM;
292
270
        }
293
271
 
294
272
        ret = usb_register(&stub_driver);
295
273
        if (ret) {
296
 
                printk(KERN_ERR KBUILD_MODNAME ": usb_register failed %d\n",
297
 
                       ret);
 
274
                pr_err("usb_register failed %d\n", ret);
298
275
                goto error_usb_register;
299
276
        }
300
277
 
301
 
        printk(KERN_INFO KBUILD_MODNAME ":"
302
 
               DRIVER_DESC ":" DRIVER_VERSION "\n");
 
278
        pr_info(DRIVER_DESC " " USBIP_VERSION "\n");
303
279
 
304
280
        init_busid_table();
305
281
 
307
283
                                 &driver_attr_match_busid);
308
284
 
309
285
        if (ret) {
310
 
                printk(KERN_ERR KBUILD_MODNAME ": create driver sysfs\n");
 
286
                pr_err("create driver sysfs\n");
311
287
                goto error_create_file;
312
288
        }
313
289
 
339
315
MODULE_AUTHOR(DRIVER_AUTHOR);
340
316
MODULE_DESCRIPTION(DRIVER_DESC);
341
317
MODULE_LICENSE("GPL");
 
318
MODULE_VERSION(USBIP_VERSION);