ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / usb / image / hpusbscsi.h
1 /* Header file for the hpusbscsi driver */
2 /* (C) Copyright 2001 Oliver Neukum */
3 /* sponsored by the Linux Usb Project */
4 /* large parts based on or taken from code by John Fremlin and Matt Dharm */
5 /* this file is licensed under the GPL */
6
7 /* A big thanks to Jose for untiring testing */
8
9 typedef void (*scsi_callback)(Scsi_Cmnd *);
10
11 #define SENSE_COMMAND_SIZE 6
12 #define HPUSBSCSI_SENSE_LENGTH 0x16
13
14 struct hpusbscsi
15 {
16         struct usb_device *dev; /* NULL indicates unplugged device */
17         int ep_out;
18         int ep_in;
19         int ep_int;
20         int interrupt_interval;
21         int number;
22         int fragment;
23         struct Scsi_Host *host;
24
25         scsi_callback scallback;
26         Scsi_Cmnd *srb;
27
28
29         wait_queue_head_t pending;
30         wait_queue_head_t deathrow;
31
32         struct urb *dataurb;
33         struct urb *controlurb;
34
35
36         int state;
37         int current_data_pipe;
38         u8 sense_command[SENSE_COMMAND_SIZE];
39         u8 scsi_state_byte;
40 };
41
42 #define SCSI_ERR_MASK ~0x3fu
43
44 static const unsigned char scsi_command_direction[256/8] = {
45         0x28, 0x81, 0x14, 0x14, 0x20, 0x01, 0x90, 0x77,
46         0x0C, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
47         0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
48         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
49 };
50
51 #define DIRECTION_IS_IN(x) ((scsi_command_direction[x>>3] >> (x & 7)) & 1)
52
53 static void simple_command_callback(struct urb *u, struct pt_regs *regs);
54 static void scatter_gather_callback(struct urb *u, struct pt_regs *regs);
55 static void simple_payload_callback (struct urb *u, struct pt_regs *regs);
56 static void request_sense_callback (struct urb *u, struct pt_regs *regs);
57 static void control_interrupt_callback (struct urb *u, struct pt_regs *regs);
58 static void simple_done (struct urb *u, struct pt_regs *regs);
59 static int hpusbscsi_scsi_queuecommand (Scsi_Cmnd *srb, scsi_callback callback);
60 static int hpusbscsi_scsi_host_reset (Scsi_Cmnd *srb);
61 static int hpusbscsi_scsi_abort (Scsi_Cmnd *srb);
62 static void issue_request_sense (struct hpusbscsi *hpusbscsi);
63
64 /* defines for internal driver state */
65 #define HP_STATE_FREE                 0  /*ready for next request */
66 #define HP_STATE_BEGINNING      1  /*command being transferred */
67 #define HP_STATE_WORKING         2  /* data transfer stage */
68 #define HP_STATE_ERROR             3  /* error has been reported */
69 #define HP_STATE_WAIT                 4  /* waiting for status transfer */
70 #define HP_STATE_PREMATURE              5 /* status prematurely reported */
71
72
73