Merge to Fedora kernel-2.6.18-1.2255_FC5-vs2.0.2.2-rc9 patched with stable patch...
[linux-2.6.git] / drivers / usb / class / usblp.c
1 /*
2  * usblp.c  Version 0.13
3  *
4  * Copyright (c) 1999 Michael Gee       <michael@linuxspecific.com>
5  * Copyright (c) 1999 Pavel Machek      <pavel@suse.cz>
6  * Copyright (c) 2000 Randy Dunlap      <rdunlap@xenotime.net>
7  * Copyright (c) 2000 Vojtech Pavlik    <vojtech@suse.cz>
8  # Copyright (c) 2001 Pete Zaitcev      <zaitcev@redhat.com>
9  # Copyright (c) 2001 David Paschal     <paschal@rcsis.com>
10  * Copyright (c) 2006 Oliver Neukum     <oliver@neukum.name>
11  *
12  * USB Printer Device Class driver for USB printers and printer cables
13  *
14  * Sponsored by SuSE
15  *
16  * ChangeLog:
17  *      v0.1 - thorough cleaning, URBification, almost a rewrite
18  *      v0.2 - some more cleanups
19  *      v0.3 - cleaner again, waitqueue fixes
20  *      v0.4 - fixes in unidirectional mode
21  *      v0.5 - add DEVICE_ID string support
22  *      v0.6 - never time out
23  *      v0.7 - fixed bulk-IN read and poll (David Paschal)
24  *      v0.8 - add devfs support
25  *      v0.9 - fix unplug-while-open paths
26  *      v0.10- remove sleep_on, fix error on oom (oliver@neukum.org)
27  *      v0.11 - add proto_bias option (Pete Zaitcev)
28  *      v0.12 - add hpoj.sourceforge.net ioctls (David Paschal)
29  *      v0.13 - alloc space for statusbuf (<status> not on stack);
30  *              use usb_buffer_alloc() for read buf & write buf;
31  */
32
33 /*
34  * This program is free software; you can redistribute it and/or modify
35  * it under the terms of the GNU General Public License as published by
36  * the Free Software Foundation; either version 2 of the License, or
37  * (at your option) any later version.
38  *
39  * This program is distributed in the hope that it will be useful,
40  * but WITHOUT ANY WARRANTY; without even the implied warranty of
41  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42  * GNU General Public License for more details.
43  *
44  * You should have received a copy of the GNU General Public License
45  * along with this program; if not, write to the Free Software
46  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47  */
48
49 #include <linux/module.h>
50 #include <linux/kernel.h>
51 #include <linux/sched.h>
52 #include <linux/smp_lock.h>
53 #include <linux/signal.h>
54 #include <linux/poll.h>
55 #include <linux/init.h>
56 #include <linux/slab.h>
57 #include <linux/lp.h>
58 #include <linux/mutex.h>
59 #undef DEBUG
60 #include <linux/usb.h>
61
62 /*
63  * Version Information
64  */
65 #define DRIVER_VERSION "v0.13"
66 #define DRIVER_AUTHOR "Michael Gee, Pavel Machek, Vojtech Pavlik, Randy Dunlap, Pete Zaitcev, David Paschal"
67 #define DRIVER_DESC "USB Printer Device Class driver"
68
69 #define USBLP_BUF_SIZE          8192
70 #define USBLP_DEVICE_ID_SIZE    1024
71
72 /* ioctls: */
73 #define LPGETSTATUS             0x060b          /* same as in drivers/char/lp.c */
74 #define IOCNR_GET_DEVICE_ID             1
75 #define IOCNR_GET_PROTOCOLS             2
76 #define IOCNR_SET_PROTOCOL              3
77 #define IOCNR_HP_SET_CHANNEL            4
78 #define IOCNR_GET_BUS_ADDRESS           5
79 #define IOCNR_GET_VID_PID               6
80 #define IOCNR_SOFT_RESET                7
81 /* Get device_id string: */
82 #define LPIOC_GET_DEVICE_ID(len) _IOC(_IOC_READ, 'P', IOCNR_GET_DEVICE_ID, len)
83 /* The following ioctls were added for http://hpoj.sourceforge.net: */
84 /* Get two-int array:
85  * [0]=current protocol (1=7/1/1, 2=7/1/2, 3=7/1/3),
86  * [1]=supported protocol mask (mask&(1<<n)!=0 means 7/1/n supported): */
87 #define LPIOC_GET_PROTOCOLS(len) _IOC(_IOC_READ, 'P', IOCNR_GET_PROTOCOLS, len)
88 /* Set protocol (arg: 1=7/1/1, 2=7/1/2, 3=7/1/3): */
89 #define LPIOC_SET_PROTOCOL _IOC(_IOC_WRITE, 'P', IOCNR_SET_PROTOCOL, 0)
90 /* Set channel number (HP Vendor-specific command): */
91 #define LPIOC_HP_SET_CHANNEL _IOC(_IOC_WRITE, 'P', IOCNR_HP_SET_CHANNEL, 0)
92 /* Get two-int array: [0]=bus number, [1]=device address: */
93 #define LPIOC_GET_BUS_ADDRESS(len) _IOC(_IOC_READ, 'P', IOCNR_GET_BUS_ADDRESS, len)
94 /* Get two-int array: [0]=vendor ID, [1]=product ID: */
95 #define LPIOC_GET_VID_PID(len) _IOC(_IOC_READ, 'P', IOCNR_GET_VID_PID, len)
96 /* Perform class specific soft reset */
97 #define LPIOC_SOFT_RESET _IOC(_IOC_NONE, 'P', IOCNR_SOFT_RESET, 0);
98
99 /*
100  * A DEVICE_ID string may include the printer's serial number.
101  * It should end with a semi-colon (';').
102  * An example from an HP 970C DeskJet printer is (this is one long string,
103  * with the serial number changed):
104 MFG:HEWLETT-PACKARD;MDL:DESKJET 970C;CMD:MLC,PCL,PML;CLASS:PRINTER;DESCRIPTION:Hewlett-Packard DeskJet 970C;SERN:US970CSEPROF;VSTATUS:$HB0$NC0,ff,DN,IDLE,CUT,K1,C0,DP,NR,KP000,CP027;VP:0800,FL,B0;VJ:                    ;
105  */
106
107 /*
108  * USB Printer Requests
109  */
110
111 #define USBLP_REQ_GET_ID                        0x00
112 #define USBLP_REQ_GET_STATUS                    0x01
113 #define USBLP_REQ_RESET                         0x02
114 #define USBLP_REQ_HP_CHANNEL_CHANGE_REQUEST     0x00    /* HP Vendor-specific */
115
116 #define USBLP_MINORS            16
117 #define USBLP_MINOR_BASE        0
118
119 #define USBLP_WRITE_TIMEOUT     (5000)                  /* 5 seconds */
120
121 #define USBLP_FIRST_PROTOCOL    1
122 #define USBLP_LAST_PROTOCOL     3
123 #define USBLP_MAX_PROTOCOLS     (USBLP_LAST_PROTOCOL+1)
124
125 /*
126  * some arbitrary status buffer size;
127  * need a status buffer that is allocated via kmalloc(), not on stack
128  */
129 #define STATUS_BUF_SIZE         8
130
131 struct usblp {
132         struct usb_device       *dev;                   /* USB device */
133         struct semaphore        sem;                    /* locks this struct, especially "dev" */
134         char                    *writebuf;              /* write transfer_buffer */
135         char                    *readbuf;               /* read transfer_buffer */
136         char                    *statusbuf;             /* status transfer_buffer */
137         struct urb              *readurb, *writeurb;    /* The urbs */
138         wait_queue_head_t       wait;                   /* Zzzzz ... */
139         int                     readcount;              /* Counter for reads */
140         int                     ifnum;                  /* Interface number */
141         struct usb_interface    *intf;                  /* The interface */
142         /* Alternate-setting numbers and endpoints for each protocol
143          * (7/1/{index=1,2,3}) that the device supports: */
144         struct {
145                 int                             alt_setting;
146                 struct usb_endpoint_descriptor  *epwrite;
147                 struct usb_endpoint_descriptor  *epread;
148         }                       protocol[USBLP_MAX_PROTOCOLS];
149         int                     current_protocol;
150         int                     minor;                  /* minor number of device */
151         int                     wcomplete;              /* writing is completed */
152         int                     rcomplete;              /* reading is completed */
153         unsigned int            quirks;                 /* quirks flags */
154         unsigned char           used;                   /* True if open */
155         unsigned char           present;                /* True if not disconnected */
156         unsigned char           bidir;                  /* interface is bidirectional */
157         unsigned char           *device_id_string;      /* IEEE 1284 DEVICE ID string (ptr) */
158                                                         /* first 2 bytes are (big-endian) length */
159 };
160
161 #ifdef DEBUG
162 static void usblp_dump(struct usblp *usblp) {
163         int p;
164
165         dbg("usblp=0x%p", usblp);
166         dbg("dev=0x%p", usblp->dev);
167         dbg("present=%d", usblp->present);
168         dbg("readbuf=0x%p", usblp->readbuf);
169         dbg("writebuf=0x%p", usblp->writebuf);
170         dbg("readurb=0x%p", usblp->readurb);
171         dbg("writeurb=0x%p", usblp->writeurb);
172         dbg("readcount=%d", usblp->readcount);
173         dbg("ifnum=%d", usblp->ifnum);
174     for (p = USBLP_FIRST_PROTOCOL; p <= USBLP_LAST_PROTOCOL; p++) {
175         dbg("protocol[%d].alt_setting=%d", p, usblp->protocol[p].alt_setting);
176         dbg("protocol[%d].epwrite=%p", p, usblp->protocol[p].epwrite);
177         dbg("protocol[%d].epread=%p", p, usblp->protocol[p].epread);
178     }
179         dbg("current_protocol=%d", usblp->current_protocol);
180         dbg("minor=%d", usblp->minor);
181         dbg("wcomplete=%d", usblp->wcomplete);
182         dbg("rcomplete=%d", usblp->rcomplete);
183         dbg("quirks=%d", usblp->quirks);
184         dbg("used=%d", usblp->used);
185         dbg("bidir=%d", usblp->bidir);
186         dbg("device_id_string=\"%s\"",
187                 usblp->device_id_string ?
188                         usblp->device_id_string + 2 :
189                         (unsigned char *)"(null)");
190 }
191 #endif
192
193 /* Quirks: various printer quirks are handled by this table & its flags. */
194
195 struct quirk_printer_struct {
196         __u16 vendorId;
197         __u16 productId;
198         unsigned int quirks;
199 };
200
201 #define USBLP_QUIRK_BIDIR       0x1     /* reports bidir but requires unidirectional mode (no INs/reads) */
202 #define USBLP_QUIRK_USB_INIT    0x2     /* needs vendor USB init string */
203
204 static const struct quirk_printer_struct quirk_printers[] = {
205         { 0x03f0, 0x0004, USBLP_QUIRK_BIDIR }, /* HP DeskJet 895C */
206         { 0x03f0, 0x0104, USBLP_QUIRK_BIDIR }, /* HP DeskJet 880C */
207         { 0x03f0, 0x0204, USBLP_QUIRK_BIDIR }, /* HP DeskJet 815C */
208         { 0x03f0, 0x0304, USBLP_QUIRK_BIDIR }, /* HP DeskJet 810C/812C */
209         { 0x03f0, 0x0404, USBLP_QUIRK_BIDIR }, /* HP DeskJet 830C */
210         { 0x03f0, 0x0504, USBLP_QUIRK_BIDIR }, /* HP DeskJet 885C */
211         { 0x03f0, 0x0604, USBLP_QUIRK_BIDIR }, /* HP DeskJet 840C */   
212         { 0x03f0, 0x0804, USBLP_QUIRK_BIDIR }, /* HP DeskJet 816C */   
213         { 0x03f0, 0x1104, USBLP_QUIRK_BIDIR }, /* HP Deskjet 959C */
214         { 0x0409, 0xefbe, USBLP_QUIRK_BIDIR }, /* NEC Picty900 (HP OEM) */
215         { 0x0409, 0xbef4, USBLP_QUIRK_BIDIR }, /* NEC Picty760 (HP OEM) */
216         { 0x0409, 0xf0be, USBLP_QUIRK_BIDIR }, /* NEC Picty920 (HP OEM) */
217         { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */
218         { 0, 0 }
219 };
220
221 static int usblp_select_alts(struct usblp *usblp);
222 static int usblp_set_protocol(struct usblp *usblp, int protocol);
223 static int usblp_cache_device_id_string(struct usblp *usblp);
224
225 /* forward reference to make our lives easier */
226 static struct usb_driver usblp_driver;
227 static DEFINE_MUTEX(usblp_mutex);       /* locks the existence of usblp's */
228
229 /*
230  * Functions for usblp control messages.
231  */
232
233 static int usblp_ctrl_msg(struct usblp *usblp, int request, int type, int dir, int recip, int value, void *buf, int len)
234 {
235         int retval;
236         int index = usblp->ifnum;
237
238         /* High byte has the interface index.
239            Low byte has the alternate setting.
240          */
241         if ((request == USBLP_REQ_GET_ID) && (type == USB_TYPE_CLASS)) {
242           index = (usblp->ifnum<<8)|usblp->protocol[usblp->current_protocol].alt_setting;
243         }
244
245         retval = usb_control_msg(usblp->dev,
246                 dir ? usb_rcvctrlpipe(usblp->dev, 0) : usb_sndctrlpipe(usblp->dev, 0),
247                 request, type | dir | recip, value, index, buf, len, USBLP_WRITE_TIMEOUT);
248         dbg("usblp_control_msg: rq: 0x%02x dir: %d recip: %d value: %d idx: %d len: %#x result: %d",
249                 request, !!dir, recip, value, index, len, retval);
250         return retval < 0 ? retval : 0;
251 }
252
253 #define usblp_read_status(usblp, status)\
254         usblp_ctrl_msg(usblp, USBLP_REQ_GET_STATUS, USB_TYPE_CLASS, USB_DIR_IN, USB_RECIP_INTERFACE, 0, status, 1)
255 #define usblp_get_id(usblp, config, id, maxlen)\
256         usblp_ctrl_msg(usblp, USBLP_REQ_GET_ID, USB_TYPE_CLASS, USB_DIR_IN, USB_RECIP_INTERFACE, config, id, maxlen)
257 #define usblp_reset(usblp)\
258         usblp_ctrl_msg(usblp, USBLP_REQ_RESET, USB_TYPE_CLASS, USB_DIR_OUT, USB_RECIP_OTHER, 0, NULL, 0)
259
260 #define usblp_hp_channel_change_request(usblp, channel, buffer) \
261         usblp_ctrl_msg(usblp, USBLP_REQ_HP_CHANNEL_CHANGE_REQUEST, USB_TYPE_VENDOR, USB_DIR_IN, USB_RECIP_INTERFACE, channel, buffer, 1)
262
263 /*
264  * See the description for usblp_select_alts() below for the usage
265  * explanation.  Look into your /proc/bus/usb/devices and dmesg in
266  * case of any trouble.
267  */
268 static int proto_bias = -1;
269
270 /*
271  * URB callback.
272  */
273
274 static void usblp_bulk_read(struct urb *urb, struct pt_regs *regs)
275 {
276         struct usblp *usblp = urb->context;
277
278         if (unlikely(!usblp || !usblp->dev || !usblp->used))
279                 return;
280
281         if (unlikely(!usblp->present))
282                 goto unplug;
283         if (unlikely(urb->status))
284                 warn("usblp%d: nonzero read/write bulk status received: %d",
285                         usblp->minor, urb->status);
286         usblp->rcomplete = 1;
287 unplug:
288         wake_up_interruptible(&usblp->wait);
289 }
290
291 static void usblp_bulk_write(struct urb *urb, struct pt_regs *regs)
292 {
293         struct usblp *usblp = urb->context;
294
295         if (unlikely(!usblp || !usblp->dev || !usblp->used))
296                 return;
297         if (unlikely(!usblp->present))
298                 goto unplug;
299         if (unlikely(urb->status))
300                 warn("usblp%d: nonzero read/write bulk status received: %d",
301                         usblp->minor, urb->status);
302         usblp->wcomplete = 1;
303 unplug:
304         wake_up_interruptible(&usblp->wait);
305 }
306
307 /*
308  * Get and print printer errors.
309  */
310
311 static const char *usblp_messages[] = { "ok", "out of paper", "off-line", "on fire" };
312
313 static int usblp_check_status(struct usblp *usblp, int err)
314 {
315         unsigned char status, newerr = 0;
316         int error;
317
318         error = usblp_read_status (usblp, usblp->statusbuf);
319         if (error < 0) {
320                 if (printk_ratelimit())
321                         err("usblp%d: error %d reading printer status",
322                                 usblp->minor, error);
323                 return 0;
324         }
325
326         status = *usblp->statusbuf;
327
328         if (~status & LP_PERRORP)
329                 newerr = 3;
330         if (status & LP_POUTPA)
331                 newerr = 1;
332         if (~status & LP_PSELECD)
333                 newerr = 2;
334
335         if (newerr != err)
336                 info("usblp%d: %s", usblp->minor, usblp_messages[newerr]);
337
338         return newerr;
339 }
340
341 /*
342  * File op functions.
343  */
344
345 static int usblp_open(struct inode *inode, struct file *file)
346 {
347         int minor = iminor(inode);
348         struct usblp *usblp;
349         struct usb_interface *intf;
350         int retval;
351
352         if (minor < 0)
353                 return -ENODEV;
354
355         mutex_lock (&usblp_mutex);
356
357         retval = -ENODEV;
358         intf = usb_find_interface(&usblp_driver, minor);
359         if (!intf) {
360                 goto out;
361         }
362         usblp = usb_get_intfdata (intf);
363         if (!usblp || !usblp->dev || !usblp->present)
364                 goto out;
365
366         retval = -EBUSY;
367         if (usblp->used)
368                 goto out;
369
370         /*
371          * TODO: need to implement LP_ABORTOPEN + O_NONBLOCK as in drivers/char/lp.c ???
372          * This is #if 0-ed because we *don't* want to fail an open
373          * just because the printer is off-line.
374          */
375 #if 0
376         if ((retval = usblp_check_status(usblp, 0))) {
377                 retval = retval > 1 ? -EIO : -ENOSPC;
378                 goto out;
379         }
380 #else
381         retval = 0;
382 #endif
383
384         usblp->used = 1;
385         file->private_data = usblp;
386
387         usblp->writeurb->transfer_buffer_length = 0;
388         usblp->wcomplete = 1; /* we begin writeable */
389         usblp->rcomplete = 0;
390         usblp->writeurb->status = 0;
391         usblp->readurb->status = 0;
392
393         if (usblp->bidir) {
394                 usblp->readcount = 0;
395                 usblp->readurb->dev = usblp->dev;
396                 if (usb_submit_urb(usblp->readurb, GFP_KERNEL) < 0) {
397                         retval = -EIO;
398                         usblp->used = 0;
399                         file->private_data = NULL;
400                 }
401         }
402 out:
403         mutex_unlock (&usblp_mutex);
404         return retval;
405 }
406
407 static void usblp_cleanup (struct usblp *usblp)
408 {
409         info("usblp%d: removed", usblp->minor);
410
411         kfree (usblp->device_id_string);
412         kfree (usblp->statusbuf);
413         usb_free_urb(usblp->writeurb);
414         usb_free_urb(usblp->readurb);
415         kfree (usblp);
416 }
417
418 static void usblp_unlink_urbs(struct usblp *usblp)
419 {
420         usb_kill_urb(usblp->writeurb);
421         if (usblp->bidir)
422                 usb_kill_urb(usblp->readurb);
423 }
424
425 static int usblp_release(struct inode *inode, struct file *file)
426 {
427         struct usblp *usblp = file->private_data;
428
429         mutex_lock (&usblp_mutex);
430         usblp->used = 0;
431         if (usblp->present) {
432                 usblp_unlink_urbs(usblp);
433         } else          /* finish cleanup from disconnect */
434                 usblp_cleanup (usblp);
435         mutex_unlock (&usblp_mutex);
436         return 0;
437 }
438
439 /* No kernel lock - fine */
440 static unsigned int usblp_poll(struct file *file, struct poll_table_struct *wait)
441 {
442         struct usblp *usblp = file->private_data;
443         poll_wait(file, &usblp->wait, wait);
444         return ((!usblp->bidir || !usblp->rcomplete) ? 0 : POLLIN  | POLLRDNORM)
445                                | (!usblp->wcomplete ? 0 : POLLOUT | POLLWRNORM);
446 }
447
448 static long usblp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
449 {
450         struct usblp *usblp = file->private_data;
451         int length, err, i;
452         unsigned char newChannel;
453         int status;
454         int twoints[2];
455         int retval = 0;
456
457         down (&usblp->sem);
458         if (!usblp->present) {
459                 retval = -ENODEV;
460                 goto done;
461         }
462
463         dbg("usblp_ioctl: cmd=0x%x (%c nr=%d len=%d dir=%d)", cmd, _IOC_TYPE(cmd),
464                 _IOC_NR(cmd), _IOC_SIZE(cmd), _IOC_DIR(cmd) );
465
466         if (_IOC_TYPE(cmd) == 'P')      /* new-style ioctl number */
467
468                 switch (_IOC_NR(cmd)) {
469
470                         case IOCNR_GET_DEVICE_ID: /* get the DEVICE_ID string */
471                                 if (_IOC_DIR(cmd) != _IOC_READ) {
472                                         retval = -EINVAL;
473                                         goto done;
474                                 }
475
476                                 length = usblp_cache_device_id_string(usblp);
477                                 if (length < 0) {
478                                         retval = length;
479                                         goto done;
480                                 }
481                                 if (length > _IOC_SIZE(cmd))
482                                         length = _IOC_SIZE(cmd); /* truncate */
483
484                                 if (copy_to_user((void __user *) arg,
485                                                 usblp->device_id_string,
486                                                 (unsigned long) length)) {
487                                         retval = -EFAULT;
488                                         goto done;
489                                 }
490
491                                 break;
492
493                         case IOCNR_GET_PROTOCOLS:
494                                 if (_IOC_DIR(cmd) != _IOC_READ ||
495                                     _IOC_SIZE(cmd) < sizeof(twoints)) {
496                                         retval = -EINVAL;
497                                         goto done;
498                                 }
499
500                                 twoints[0] = usblp->current_protocol;
501                                 twoints[1] = 0;
502                                 for (i = USBLP_FIRST_PROTOCOL;
503                                      i <= USBLP_LAST_PROTOCOL; i++) {
504                                         if (usblp->protocol[i].alt_setting >= 0)
505                                                 twoints[1] |= (1<<i);
506                                 }
507
508                                 if (copy_to_user((void __user *)arg,
509                                                 (unsigned char *)twoints,
510                                                 sizeof(twoints))) {
511                                         retval = -EFAULT;
512                                         goto done;
513                                 }
514
515                                 break;
516
517                         case IOCNR_SET_PROTOCOL:
518                                 if (_IOC_DIR(cmd) != _IOC_WRITE) {
519                                         retval = -EINVAL;
520                                         goto done;
521                                 }
522
523 #ifdef DEBUG
524                                 if (arg == -10) {
525                                         usblp_dump(usblp);
526                                         break;
527                                 }
528 #endif
529
530                                 usblp_unlink_urbs(usblp);
531                                 retval = usblp_set_protocol(usblp, arg);
532                                 if (retval < 0) {
533                                         usblp_set_protocol(usblp,
534                                                 usblp->current_protocol);
535                                 }
536                                 break;
537
538                         case IOCNR_HP_SET_CHANNEL:
539                                 if (_IOC_DIR(cmd) != _IOC_WRITE ||
540                                     le16_to_cpu(usblp->dev->descriptor.idVendor) != 0x03F0 ||
541                                     usblp->quirks & USBLP_QUIRK_BIDIR) {
542                                         retval = -EINVAL;
543                                         goto done;
544                                 }
545
546                                 err = usblp_hp_channel_change_request(usblp,
547                                         arg, &newChannel);
548                                 if (err < 0) {
549                                         err("usblp%d: error = %d setting "
550                                                 "HP channel",
551                                                 usblp->minor, err);
552                                         retval = -EIO;
553                                         goto done;
554                                 }
555
556                                 dbg("usblp%d requested/got HP channel %ld/%d",
557                                         usblp->minor, arg, newChannel);
558                                 break;
559
560                         case IOCNR_GET_BUS_ADDRESS:
561                                 if (_IOC_DIR(cmd) != _IOC_READ ||
562                                     _IOC_SIZE(cmd) < sizeof(twoints)) {
563                                         retval = -EINVAL;
564                                         goto done;
565                                 }
566
567                                 twoints[0] = usblp->dev->bus->busnum;
568                                 twoints[1] = usblp->dev->devnum;
569                                 if (copy_to_user((void __user *)arg,
570                                                 (unsigned char *)twoints,
571                                                 sizeof(twoints))) {
572                                         retval = -EFAULT;
573                                         goto done;
574                                 }
575
576                                 dbg("usblp%d is bus=%d, device=%d",
577                                         usblp->minor, twoints[0], twoints[1]);
578                                 break;
579
580                         case IOCNR_GET_VID_PID:
581                                 if (_IOC_DIR(cmd) != _IOC_READ ||
582                                     _IOC_SIZE(cmd) < sizeof(twoints)) {
583                                         retval = -EINVAL;
584                                         goto done;
585                                 }
586
587                                 twoints[0] = le16_to_cpu(usblp->dev->descriptor.idVendor);
588                                 twoints[1] = le16_to_cpu(usblp->dev->descriptor.idProduct);
589                                 if (copy_to_user((void __user *)arg,
590                                                 (unsigned char *)twoints,
591                                                 sizeof(twoints))) {
592                                         retval = -EFAULT;
593                                         goto done;
594                                 }
595
596                                 dbg("usblp%d is VID=0x%4.4X, PID=0x%4.4X",
597                                         usblp->minor, twoints[0], twoints[1]);
598                                 break;
599
600                         case IOCNR_SOFT_RESET:
601                                 if (_IOC_DIR(cmd) != _IOC_NONE) {
602                                         retval = -EINVAL;
603                                         goto done;
604                                 }
605                                 retval = usblp_reset(usblp);
606                                 break;
607                         default:
608                                 retval = -ENOTTY;
609                 }
610         else    /* old-style ioctl value */
611                 switch (cmd) {
612
613                         case LPGETSTATUS:
614                                 if (usblp_read_status(usblp, usblp->statusbuf)) {
615                                         if (printk_ratelimit())
616                                                 err("usblp%d: failed reading printer status",
617                                                         usblp->minor);
618                                         retval = -EIO;
619                                         goto done;
620                                 }
621                                 status = *usblp->statusbuf;
622                                 if (copy_to_user ((void __user *)arg, &status, sizeof(int)))
623                                         retval = -EFAULT;
624                                 break;
625
626                         default:
627                                 retval = -ENOTTY;
628                 }
629
630 done:
631         up (&usblp->sem);
632         return retval;
633 }
634
635 static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
636 {
637         struct usblp *usblp = file->private_data;
638         int timeout, rv, err = 0, transfer_length = 0;
639         size_t writecount = 0;
640
641         while (writecount < count) {
642                 if (!usblp->wcomplete) {
643                         barrier();
644                         if (file->f_flags & O_NONBLOCK) {
645                                 writecount += transfer_length;
646                                 return writecount ? writecount : -EAGAIN;
647                         }
648
649                         timeout = USBLP_WRITE_TIMEOUT;
650
651                         rv = wait_event_interruptible_timeout(usblp->wait, usblp->wcomplete || !usblp->present , timeout);
652                         if (rv < 0)
653                                 return writecount ? writecount : -EINTR;
654                 }
655                 down (&usblp->sem);
656                 if (!usblp->present) {
657                         up (&usblp->sem);
658                         return -ENODEV;
659                 }
660
661                 if (usblp->writeurb->status != 0) {
662                         if (usblp->quirks & USBLP_QUIRK_BIDIR) {
663                                 if (!usblp->wcomplete)
664                                         err("usblp%d: error %d writing to printer",
665                                                 usblp->minor, usblp->writeurb->status);
666                                 err = usblp->writeurb->status;
667                         } else
668                                 err = usblp_check_status(usblp, err);
669                         up (&usblp->sem);
670
671                         /* if the fault was due to disconnect, let khubd's
672                          * call to usblp_disconnect() grab usblp->sem ...
673                          */
674                         schedule ();
675                         continue;
676                 }
677
678                 /* We must increment writecount here, and not at the
679                  * end of the loop. Otherwise, the final loop iteration may
680                  * be skipped, leading to incomplete printer output.
681                  */
682                 writecount += transfer_length;
683                 if (writecount == count) {
684                         up(&usblp->sem);
685                         break;
686                 }
687
688                 transfer_length=(count - writecount);
689                 if (transfer_length > USBLP_BUF_SIZE)
690                         transfer_length = USBLP_BUF_SIZE;
691
692                 usblp->writeurb->transfer_buffer_length = transfer_length;
693
694                 if (copy_from_user(usblp->writeurb->transfer_buffer, 
695                                    buffer + writecount, transfer_length)) {
696                         up(&usblp->sem);
697                         return writecount ? writecount : -EFAULT;
698                 }
699
700                 usblp->writeurb->dev = usblp->dev;
701                 usblp->wcomplete = 0;
702                 err = usb_submit_urb(usblp->writeurb, GFP_KERNEL);
703                 if (err) {
704                         usblp->wcomplete = 1;
705                         if (err != -ENOMEM)
706                                 count = -EIO;
707                         else
708                                 count = writecount ? writecount : -ENOMEM;
709                         up (&usblp->sem);
710                         break;
711                 }
712                 up (&usblp->sem);
713         }
714
715         return count;
716 }
717
718 static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
719 {
720         struct usblp *usblp = file->private_data;
721         int rv;
722
723         if (!usblp->bidir)
724                 return -EINVAL;
725
726         down (&usblp->sem);
727         if (!usblp->present) {
728                 count = -ENODEV;
729                 goto done;
730         }
731
732         if (!usblp->rcomplete) {
733                 barrier();
734
735                 if (file->f_flags & O_NONBLOCK) {
736                         count = -EAGAIN;
737                         goto done;
738                 }
739                 up(&usblp->sem);
740                 rv = wait_event_interruptible(usblp->wait, usblp->rcomplete || !usblp->present);
741                 down(&usblp->sem);
742                 if (rv < 0) {
743                         count = -EINTR;
744                         goto done;
745                 }
746         }
747
748         if (!usblp->present) {
749                 count = -ENODEV;
750                 goto done;
751         }
752
753         if (usblp->readurb->status) {
754                 err("usblp%d: error %d reading from printer",
755                         usblp->minor, usblp->readurb->status);
756                 usblp->readurb->dev = usblp->dev;
757                 usblp->readcount = 0;
758                 usblp->rcomplete = 0;
759                 if (usb_submit_urb(usblp->readurb, GFP_KERNEL) < 0)
760                         dbg("error submitting urb");
761                 count = -EIO;
762                 goto done;
763         }
764
765         count = count < usblp->readurb->actual_length - usblp->readcount ?
766                 count : usblp->readurb->actual_length - usblp->readcount;
767
768         if (copy_to_user(buffer, usblp->readurb->transfer_buffer + usblp->readcount, count)) {
769                 count = -EFAULT;
770                 goto done;
771         }
772
773         if ((usblp->readcount += count) == usblp->readurb->actual_length) {
774                 usblp->readcount = 0;
775                 usblp->readurb->dev = usblp->dev;
776                 usblp->rcomplete = 0;
777                 if (usb_submit_urb(usblp->readurb, GFP_KERNEL)) {
778                         count = -EIO;
779                         goto done;
780                 }
781         }
782
783 done:
784         up (&usblp->sem);
785         return count;
786 }
787
788 /*
789  * Checks for printers that have quirks, such as requiring unidirectional
790  * communication but reporting bidirectional; currently some HP printers
791  * have this flaw (HP 810, 880, 895, etc.), or needing an init string
792  * sent at each open (like some Epsons).
793  * Returns 1 if found, 0 if not found.
794  *
795  * HP recommended that we use the bidirectional interface but
796  * don't attempt any bulk IN transfers from the IN endpoint.
797  * Here's some more detail on the problem:
798  * The problem is not that it isn't bidirectional though. The problem
799  * is that if you request a device ID, or status information, while
800  * the buffers are full, the return data will end up in the print data
801  * buffer. For example if you make sure you never request the device ID
802  * while you are sending print data, and you don't try to query the
803  * printer status every couple of milliseconds, you will probably be OK.
804  */
805 static unsigned int usblp_quirks (__u16 vendor, __u16 product)
806 {
807         int i;
808
809         for (i = 0; quirk_printers[i].vendorId; i++) {
810                 if (vendor == quirk_printers[i].vendorId &&
811                     product == quirk_printers[i].productId)
812                         return quirk_printers[i].quirks;
813         }
814         return 0;
815 }
816
817 static struct file_operations usblp_fops = {
818         .owner =        THIS_MODULE,
819         .read =         usblp_read,
820         .write =        usblp_write,
821         .poll =         usblp_poll,
822         .unlocked_ioctl =       usblp_ioctl,
823         .compat_ioctl =         usblp_ioctl,
824         .open =         usblp_open,
825         .release =      usblp_release,
826 };
827
828 static struct usb_class_driver usblp_class = {
829         .name =         "lp%d",
830         .fops =         &usblp_fops,
831         .minor_base =   USBLP_MINOR_BASE,
832 };
833
834 static ssize_t usblp_show_ieee1284_id(struct device *dev, struct device_attribute *attr, char *buf)
835 {
836         struct usb_interface *intf = to_usb_interface(dev);
837         struct usblp *usblp = usb_get_intfdata (intf);
838
839         if (usblp->device_id_string[0] == 0 &&
840             usblp->device_id_string[1] == 0)
841                 return 0;
842
843         return sprintf(buf, "%s", usblp->device_id_string+2);
844 }
845
846 static DEVICE_ATTR(ieee1284_id, S_IRUGO, usblp_show_ieee1284_id, NULL);
847
848 static int usblp_probe(struct usb_interface *intf,
849                        const struct usb_device_id *id)
850 {
851         struct usb_device *dev = interface_to_usbdev (intf);
852         struct usblp *usblp = NULL;
853         int protocol;
854         int retval;
855
856         /* Malloc and start initializing usblp structure so we can use it
857          * directly. */
858         if (!(usblp = kzalloc(sizeof(struct usblp), GFP_KERNEL))) {
859                 err("out of memory for usblp");
860                 goto abort;
861         }
862         usblp->dev = dev;
863         init_MUTEX (&usblp->sem);
864         init_waitqueue_head(&usblp->wait);
865         usblp->ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
866         usblp->intf = intf;
867
868         usblp->writeurb = usb_alloc_urb(0, GFP_KERNEL);
869         if (!usblp->writeurb) {
870                 err("out of memory");
871                 goto abort;
872         }
873         usblp->readurb = usb_alloc_urb(0, GFP_KERNEL);
874         if (!usblp->readurb) {
875                 err("out of memory");
876                 goto abort;
877         }
878
879         /* Malloc device ID string buffer to the largest expected length,
880          * since we can re-query it on an ioctl and a dynamic string
881          * could change in length. */
882         if (!(usblp->device_id_string = kmalloc(USBLP_DEVICE_ID_SIZE, GFP_KERNEL))) {
883                 err("out of memory for device_id_string");
884                 goto abort;
885         }
886
887         usblp->writebuf = usblp->readbuf = NULL;
888         usblp->writeurb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
889         usblp->readurb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
890         /* Malloc write & read buffers.  We somewhat wastefully
891          * malloc both regardless of bidirectionality, because the
892          * alternate setting can be changed later via an ioctl. */
893         if (!(usblp->writebuf = usb_buffer_alloc(dev, USBLP_BUF_SIZE,
894                                 GFP_KERNEL, &usblp->writeurb->transfer_dma))) {
895                 err("out of memory for write buf");
896                 goto abort;
897         }
898         if (!(usblp->readbuf = usb_buffer_alloc(dev, USBLP_BUF_SIZE,
899                                 GFP_KERNEL, &usblp->readurb->transfer_dma))) {
900                 err("out of memory for read buf");
901                 goto abort;
902         }
903
904         /* Allocate buffer for printer status */
905         usblp->statusbuf = kmalloc(STATUS_BUF_SIZE, GFP_KERNEL);
906         if (!usblp->statusbuf) {
907                 err("out of memory for statusbuf");
908                 goto abort;
909         }
910
911         /* Lookup quirks for this printer. */
912         usblp->quirks = usblp_quirks(
913                 le16_to_cpu(dev->descriptor.idVendor),
914                 le16_to_cpu(dev->descriptor.idProduct));
915
916         /* Analyze and pick initial alternate settings and endpoints. */
917         protocol = usblp_select_alts(usblp);
918         if (protocol < 0) {
919                 dbg("incompatible printer-class device 0x%4.4X/0x%4.4X",
920                         le16_to_cpu(dev->descriptor.idVendor),
921                         le16_to_cpu(dev->descriptor.idProduct));
922                 goto abort;
923         }
924
925         /* Setup the selected alternate setting and endpoints. */
926         if (usblp_set_protocol(usblp, protocol) < 0)
927                 goto abort;
928
929         /* Retrieve and store the device ID string. */
930         usblp_cache_device_id_string(usblp);
931         device_create_file(&intf->dev, &dev_attr_ieee1284_id);
932
933 #ifdef DEBUG
934         usblp_check_status(usblp, 0);
935 #endif
936
937         usb_set_intfdata (intf, usblp);
938
939         usblp->present = 1;
940
941         retval = usb_register_dev(intf, &usblp_class);
942         if (retval) {
943                 err("Not able to get a minor for this device.");
944                 goto abort_intfdata;
945         }
946         usblp->minor = intf->minor;
947         info("usblp%d: USB %sdirectional printer dev %d "
948                 "if %d alt %d proto %d vid 0x%4.4X pid 0x%4.4X",
949                 usblp->minor, usblp->bidir ? "Bi" : "Uni", dev->devnum,
950                 usblp->ifnum,
951                 usblp->protocol[usblp->current_protocol].alt_setting,
952                 usblp->current_protocol,
953                 le16_to_cpu(usblp->dev->descriptor.idVendor),
954                 le16_to_cpu(usblp->dev->descriptor.idProduct));
955
956         return 0;
957
958 abort_intfdata:
959         usb_set_intfdata (intf, NULL);
960         device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
961 abort:
962         if (usblp) {
963                 if (usblp->writebuf)
964                         usb_buffer_free (usblp->dev, USBLP_BUF_SIZE,
965                                 usblp->writebuf, usblp->writeurb->transfer_dma);
966                 if (usblp->readbuf)
967                         usb_buffer_free (usblp->dev, USBLP_BUF_SIZE,
968                                 usblp->readbuf, usblp->writeurb->transfer_dma);
969                 kfree(usblp->statusbuf);
970                 kfree(usblp->device_id_string);
971                 usb_free_urb(usblp->writeurb);
972                 usb_free_urb(usblp->readurb);
973                 kfree(usblp);
974         }
975         return -EIO;
976 }
977
978 /*
979  * We are a "new" style driver with usb_device_id table,
980  * but our requirements are too intricate for simple match to handle.
981  *
982  * The "proto_bias" option may be used to specify the preferred protocol
983  * for all USB printers (1=7/1/1, 2=7/1/2, 3=7/1/3).  If the device
984  * supports the preferred protocol, then we bind to it.
985  *
986  * The best interface for us is 7/1/2, because it is compatible
987  * with a stream of characters. If we find it, we bind to it.
988  *
989  * Note that the people from hpoj.sourceforge.net need to be able to
990  * bind to 7/1/3 (MLC/1284.4), so we provide them ioctls for this purpose.
991  *
992  * Failing 7/1/2, we look for 7/1/3, even though it's probably not
993  * stream-compatible, because this matches the behaviour of the old code.
994  *
995  * If nothing else, we bind to 7/1/1 - the unidirectional interface.
996  */
997 static int usblp_select_alts(struct usblp *usblp)
998 {
999         struct usb_interface *if_alt;
1000         struct usb_host_interface *ifd;
1001         struct usb_endpoint_descriptor *epd, *epwrite, *epread;
1002         int p, i, e;
1003
1004         if_alt = usblp->intf;
1005
1006         for (p = 0; p < USBLP_MAX_PROTOCOLS; p++)
1007                 usblp->protocol[p].alt_setting = -1;
1008
1009         /* Find out what we have. */
1010         for (i = 0; i < if_alt->num_altsetting; i++) {
1011                 ifd = &if_alt->altsetting[i];
1012
1013                 if (ifd->desc.bInterfaceClass != 7 || ifd->desc.bInterfaceSubClass != 1)
1014                         continue;
1015
1016                 if (ifd->desc.bInterfaceProtocol < USBLP_FIRST_PROTOCOL ||
1017                     ifd->desc.bInterfaceProtocol > USBLP_LAST_PROTOCOL)
1018                         continue;
1019
1020                 /* Look for bulk OUT and IN endpoints. */
1021                 epwrite = epread = NULL;
1022                 for (e = 0; e < ifd->desc.bNumEndpoints; e++) {
1023                         epd = &ifd->endpoint[e].desc;
1024
1025                         if ((epd->bmAttributes&USB_ENDPOINT_XFERTYPE_MASK)!=
1026                             USB_ENDPOINT_XFER_BULK)
1027                                 continue;
1028
1029                         if (!(epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK)) {
1030                                 if (!epwrite)
1031                                         epwrite = epd;
1032
1033                         } else {
1034                                 if (!epread)
1035                                         epread = epd;
1036                         }
1037                 }
1038
1039                 /* Ignore buggy hardware without the right endpoints. */
1040                 if (!epwrite || (ifd->desc.bInterfaceProtocol > 1 && !epread))
1041                         continue;
1042
1043                 /* Turn off reads for 7/1/1 (unidirectional) interfaces
1044                  * and buggy bidirectional printers. */
1045                 if (ifd->desc.bInterfaceProtocol == 1) {
1046                         epread = NULL;
1047                 } else if (usblp->quirks & USBLP_QUIRK_BIDIR) {
1048                         info("Disabling reads from problem bidirectional "
1049                                 "printer on usblp%d", usblp->minor);
1050                         epread = NULL;
1051                 }
1052
1053                 usblp->protocol[ifd->desc.bInterfaceProtocol].alt_setting =
1054                                 ifd->desc.bAlternateSetting;
1055                 usblp->protocol[ifd->desc.bInterfaceProtocol].epwrite = epwrite;
1056                 usblp->protocol[ifd->desc.bInterfaceProtocol].epread = epread;
1057         }
1058
1059         /* If our requested protocol is supported, then use it. */
1060         if (proto_bias >= USBLP_FIRST_PROTOCOL &&
1061             proto_bias <= USBLP_LAST_PROTOCOL &&
1062             usblp->protocol[proto_bias].alt_setting != -1)
1063                 return proto_bias;
1064
1065         /* Ordering is important here. */
1066         if (usblp->protocol[2].alt_setting != -1)
1067                 return 2;
1068         if (usblp->protocol[1].alt_setting != -1)
1069                 return 1;
1070         if (usblp->protocol[3].alt_setting != -1)
1071                 return 3;
1072
1073         /* If nothing is available, then don't bind to this device. */
1074         return -1;
1075 }
1076
1077 static int usblp_set_protocol(struct usblp *usblp, int protocol)
1078 {
1079         int r, alts;
1080
1081         if (protocol < USBLP_FIRST_PROTOCOL || protocol > USBLP_LAST_PROTOCOL)
1082                 return -EINVAL;
1083
1084         alts = usblp->protocol[protocol].alt_setting;
1085         if (alts < 0)
1086                 return -EINVAL;
1087         r = usb_set_interface(usblp->dev, usblp->ifnum, alts);
1088         if (r < 0) {
1089                 err("can't set desired altsetting %d on interface %d",
1090                         alts, usblp->ifnum);
1091                 return r;
1092         }
1093
1094         usb_fill_bulk_urb(usblp->writeurb, usblp->dev,
1095                 usb_sndbulkpipe(usblp->dev,
1096                   usblp->protocol[protocol].epwrite->bEndpointAddress),
1097                 usblp->writebuf, 0,
1098                 usblp_bulk_write, usblp);
1099
1100         usblp->bidir = (usblp->protocol[protocol].epread != NULL);
1101         if (usblp->bidir)
1102                 usb_fill_bulk_urb(usblp->readurb, usblp->dev,
1103                         usb_rcvbulkpipe(usblp->dev,
1104                           usblp->protocol[protocol].epread->bEndpointAddress),
1105                         usblp->readbuf, USBLP_BUF_SIZE,
1106                         usblp_bulk_read, usblp);
1107
1108         usblp->current_protocol = protocol;
1109         dbg("usblp%d set protocol %d", usblp->minor, protocol);
1110         return 0;
1111 }
1112
1113 /* Retrieves and caches device ID string.
1114  * Returns length, including length bytes but not null terminator.
1115  * On error, returns a negative errno value. */
1116 static int usblp_cache_device_id_string(struct usblp *usblp)
1117 {
1118         int err, length;
1119
1120         err = usblp_get_id(usblp, 0, usblp->device_id_string, USBLP_DEVICE_ID_SIZE - 1);
1121         if (err < 0) {
1122                 dbg("usblp%d: error = %d reading IEEE-1284 Device ID string",
1123                         usblp->minor, err);
1124                 usblp->device_id_string[0] = usblp->device_id_string[1] = '\0';
1125                 return -EIO;
1126         }
1127
1128         /* First two bytes are length in big-endian.
1129          * They count themselves, and we copy them into
1130          * the user's buffer. */
1131         length = be16_to_cpu(*((__be16 *)usblp->device_id_string));
1132         if (length < 2)
1133                 length = 2;
1134         else if (length >= USBLP_DEVICE_ID_SIZE)
1135                 length = USBLP_DEVICE_ID_SIZE - 1;
1136         usblp->device_id_string[length] = '\0';
1137
1138         dbg("usblp%d Device ID string [len=%d]=\"%s\"",
1139                 usblp->minor, length, &usblp->device_id_string[2]);
1140
1141         return length;
1142 }
1143
1144 static void usblp_disconnect(struct usb_interface *intf)
1145 {
1146         struct usblp *usblp = usb_get_intfdata (intf);
1147
1148         usb_deregister_dev(intf, &usblp_class);
1149
1150         if (!usblp || !usblp->dev) {
1151                 err("bogus disconnect");
1152                 BUG ();
1153         }
1154
1155         device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
1156
1157         mutex_lock (&usblp_mutex);
1158         down (&usblp->sem);
1159         usblp->present = 0;
1160         usb_set_intfdata (intf, NULL);
1161
1162         usblp_unlink_urbs(usblp);
1163         usb_buffer_free (usblp->dev, USBLP_BUF_SIZE,
1164                         usblp->writebuf, usblp->writeurb->transfer_dma);
1165         usb_buffer_free (usblp->dev, USBLP_BUF_SIZE,
1166                         usblp->readbuf, usblp->readurb->transfer_dma);
1167         up (&usblp->sem);
1168
1169         if (!usblp->used)
1170                 usblp_cleanup (usblp);
1171         mutex_unlock (&usblp_mutex);
1172 }
1173
1174 static struct usb_device_id usblp_ids [] = {
1175         { USB_DEVICE_INFO(7, 1, 1) },
1176         { USB_DEVICE_INFO(7, 1, 2) },
1177         { USB_DEVICE_INFO(7, 1, 3) },
1178         { USB_INTERFACE_INFO(7, 1, 1) },
1179         { USB_INTERFACE_INFO(7, 1, 2) },
1180         { USB_INTERFACE_INFO(7, 1, 3) },
1181         { }                                             /* Terminating entry */
1182 };
1183
1184 MODULE_DEVICE_TABLE (usb, usblp_ids);
1185
1186 static struct usb_driver usblp_driver = {
1187         .name =         "usblp",
1188         .probe =        usblp_probe,
1189         .disconnect =   usblp_disconnect,
1190         .id_table =     usblp_ids,
1191 };
1192
1193 static int __init usblp_init(void)
1194 {
1195         int retval;
1196         retval = usb_register(&usblp_driver);
1197         if (!retval)
1198                 info(DRIVER_VERSION ": " DRIVER_DESC);
1199
1200         return retval;
1201 }
1202
1203 static void __exit usblp_exit(void)
1204 {
1205         usb_deregister(&usblp_driver);
1206 }
1207
1208 module_init(usblp_init);
1209 module_exit(usblp_exit);
1210
1211 MODULE_AUTHOR( DRIVER_AUTHOR );
1212 MODULE_DESCRIPTION( DRIVER_DESC );
1213 module_param(proto_bias, int, S_IRUGO | S_IWUSR);
1214 MODULE_PARM_DESC(proto_bias, "Favourite protocol number");
1215 MODULE_LICENSE("GPL");