patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / scsi / dpti.h
1 /***************************************************************************
2                           dpti.h  -  description
3                              -------------------
4     begin                : Thu Sep 7 2000
5     copyright            : (C) 2001 by Adaptec
6     email                : deanna_bonds@adaptec.com
7
8     See Documentation/scsi/dpti.txt for history, notes, license info
9     and credits
10  ***************************************************************************/
11
12 /***************************************************************************
13  *                                                                         *
14  *   This program is free software; you can redistribute it and/or modify  *
15  *   it under the terms of the GNU General Public License as published by  *
16  *   the Free Software Foundation; either version 2 of the License, or     *
17  *   (at your option) any later version.                                   *
18  *                                                                         *
19  ***************************************************************************/
20
21 #ifndef _DPT_H
22 #define _DPT_H
23
24 #ifndef LINUX_VERSION_CODE
25 #include <linux/version.h>
26 #endif
27
28 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,00)
29 #define MAX_TO_IOP_MESSAGES   (210)
30 #else
31 #define MAX_TO_IOP_MESSAGES   (255)
32 #endif
33 #define MAX_FROM_IOP_MESSAGES (255)
34
35
36 /*
37  * SCSI interface function Prototypes
38  */
39
40 static int adpt_detect(Scsi_Host_Template * sht);
41 static int adpt_queue(Scsi_Cmnd * cmd, void (*cmdcomplete) (Scsi_Cmnd *));
42 static int adpt_abort(Scsi_Cmnd * cmd);
43 static int adpt_reset(Scsi_Cmnd* cmd);
44 static int adpt_release(struct Scsi_Host *host);
45 static int adpt_slave_configure(Scsi_Device *);
46
47 static const char *adpt_info(struct Scsi_Host *pSHost);
48 static int adpt_bios_param(struct scsi_device * sdev, struct block_device *dev,
49                 sector_t, int geom[]);
50
51 static int adpt_bus_reset(Scsi_Cmnd* cmd);
52 static int adpt_device_reset(Scsi_Cmnd* cmd);
53
54
55 /*
56  * Scsi_Host_Template (see hosts.h) 
57  */
58
59 #define DPT_DRIVER_NAME "Adaptec I2O RAID"
60
61 #ifndef HOSTS_C
62
63 #include "dpt/sys_info.h"
64 #include <linux/wait.h>
65 #include "dpt/dpti_i2o.h"
66 #include "dpt/dpti_ioctl.h"
67
68 #define DPT_I2O_VERSION "2.4 Build 5go"
69 #define DPT_VERSION     2
70 #define DPT_REVISION    '4'
71 #define DPT_SUBREVISION '5'
72 #define DPT_BETA        ""
73 #define DPT_MONTH      8 
74 #define DPT_DAY        7
75 #define DPT_YEAR        (2001-1980)
76
77 #define DPT_DRIVER      "dpt_i2o"
78 #define DPTI_I2O_MAJOR  (151)
79 #define DPT_ORGANIZATION_ID (0x1B)        /* For Private Messages */
80 #define DPTI_MAX_HBA    (16)
81 #define MAX_CHANNEL     (5)     // Maximum Channel # Supported
82 #define MAX_ID          (128)   // Maximum Target ID Supported
83
84 /* Sizes in 4 byte words */
85 #define REPLY_FRAME_SIZE  (17)
86 #define MAX_MESSAGE_SIZE  (128)
87 #define SG_LIST_ELEMENTS  (56)
88
89 #define EMPTY_QUEUE           0xffffffff
90 #define I2O_INTERRUPT_PENDING_B   (0x08)
91
92 #define PCI_DPT_VENDOR_ID         (0x1044)      // DPT PCI Vendor ID
93 #define PCI_DPT_DEVICE_ID         (0xA501)      // DPT PCI I2O Device ID
94 #define PCI_DPT_RAPTOR_DEVICE_ID  (0xA511)      
95
96 //#define REBOOT_NOTIFIER 1
97 /* Debugging macro from Linux Device Drivers - Rubini */
98 #undef PDEBUG
99 #ifdef DEBUG
100 //TODO add debug level switch
101 #  define PDEBUG(fmt, args...)  printk(KERN_DEBUG "dpti: " fmt, ##args)
102 #  define PDEBUGV(fmt, args...) printk(KERN_DEBUG "dpti: " fmt, ##args)
103 #else
104 # define PDEBUG(fmt, args...) /* not debugging: nothing */
105 # define PDEBUGV(fmt, args...) /* not debugging: nothing */
106 #endif
107
108 #define PERROR(fmt, args...) printk(KERN_ERR fmt, ##args)
109 #define PWARN(fmt, args...) printk(KERN_WARNING fmt, ##args)
110 #define PINFO(fmt, args...) printk(KERN_INFO fmt, ##args)
111 #define PCRIT(fmt, args...) printk(KERN_CRIT fmt, ##args)
112
113 #define SHUTDOWN_SIGS   (sigmask(SIGKILL)|sigmask(SIGINT)|sigmask(SIGTERM))
114
115 // Command timeouts
116 #define FOREVER                 (0)
117 #define TMOUT_INQUIRY           (20)
118 #define TMOUT_FLUSH             (360/45)
119 #define TMOUT_ABORT             (30)
120 #define TMOUT_SCSI              (300)
121 #define TMOUT_IOPRESET          (360)
122 #define TMOUT_GETSTATUS         (15)
123 #define TMOUT_INITOUTBOUND      (15)
124 #define TMOUT_LCT               (360)
125
126
127 #define I2O_SCSI_DEVICE_DSC_MASK                0x00FF
128
129 #define I2O_DETAIL_STATUS_UNSUPPORTED_FUNCTION  0x000A
130
131 #define I2O_SCSI_DSC_MASK                   0xFF00
132 #define I2O_SCSI_DSC_SUCCESS                0x0000
133 #define I2O_SCSI_DSC_REQUEST_ABORTED        0x0200
134 #define I2O_SCSI_DSC_UNABLE_TO_ABORT        0x0300
135 #define I2O_SCSI_DSC_COMPLETE_WITH_ERROR    0x0400
136 #define I2O_SCSI_DSC_ADAPTER_BUSY           0x0500
137 #define I2O_SCSI_DSC_REQUEST_INVALID        0x0600
138 #define I2O_SCSI_DSC_PATH_INVALID           0x0700
139 #define I2O_SCSI_DSC_DEVICE_NOT_PRESENT     0x0800
140 #define I2O_SCSI_DSC_UNABLE_TO_TERMINATE    0x0900
141 #define I2O_SCSI_DSC_SELECTION_TIMEOUT      0x0A00
142 #define I2O_SCSI_DSC_COMMAND_TIMEOUT        0x0B00
143 #define I2O_SCSI_DSC_MR_MESSAGE_RECEIVED    0x0D00
144 #define I2O_SCSI_DSC_SCSI_BUS_RESET         0x0E00
145 #define I2O_SCSI_DSC_PARITY_ERROR_FAILURE   0x0F00
146 #define I2O_SCSI_DSC_AUTOSENSE_FAILED       0x1000
147 #define I2O_SCSI_DSC_NO_ADAPTER             0x1100
148 #define I2O_SCSI_DSC_DATA_OVERRUN           0x1200
149 #define I2O_SCSI_DSC_UNEXPECTED_BUS_FREE    0x1300
150 #define I2O_SCSI_DSC_SEQUENCE_FAILURE       0x1400
151 #define I2O_SCSI_DSC_REQUEST_LENGTH_ERROR   0x1500
152 #define I2O_SCSI_DSC_PROVIDE_FAILURE        0x1600
153 #define I2O_SCSI_DSC_BDR_MESSAGE_SENT       0x1700
154 #define I2O_SCSI_DSC_REQUEST_TERMINATED     0x1800
155 #define I2O_SCSI_DSC_IDE_MESSAGE_SENT       0x3300
156 #define I2O_SCSI_DSC_RESOURCE_UNAVAILABLE   0x3400
157 #define I2O_SCSI_DSC_UNACKNOWLEDGED_EVENT   0x3500
158 #define I2O_SCSI_DSC_MESSAGE_RECEIVED       0x3600
159 #define I2O_SCSI_DSC_INVALID_CDB            0x3700
160 #define I2O_SCSI_DSC_LUN_INVALID            0x3800
161 #define I2O_SCSI_DSC_SCSI_TID_INVALID       0x3900
162 #define I2O_SCSI_DSC_FUNCTION_UNAVAILABLE   0x3A00
163 #define I2O_SCSI_DSC_NO_NEXUS               0x3B00
164 #define I2O_SCSI_DSC_SCSI_IID_INVALID       0x3C00
165 #define I2O_SCSI_DSC_CDB_RECEIVED           0x3D00
166 #define I2O_SCSI_DSC_LUN_ALREADY_ENABLED    0x3E00
167 #define I2O_SCSI_DSC_BUS_BUSY               0x3F00
168 #define I2O_SCSI_DSC_QUEUE_FROZEN           0x4000
169
170
171 #ifndef TRUE
172 #define TRUE                  1
173 #define FALSE                 0
174 #endif
175
176 #define HBA_FLAGS_INSTALLED_B       0x00000001  // Adapter Was Installed
177 #define HBA_FLAGS_BLINKLED_B        0x00000002  // Adapter In Blink LED State
178 #define HBA_FLAGS_IN_RESET      0x00000040      /* in reset */
179 #define HBA_HOSTRESET_FAILED    0x00000080      /* adpt_resethost failed */
180
181
182 // Device state flags
183 #define DPTI_DEV_ONLINE    0x00
184 #define DPTI_DEV_UNSCANNED 0x01
185 #define DPTI_DEV_RESET     0x02
186 #define DPTI_DEV_OFFLINE   0x04
187
188
189 struct adpt_device {
190         struct adpt_device* next_lun;
191         u32     flags;
192         u32     type;
193         u32     capacity;
194         u32     block_size;
195         u8      scsi_channel;
196         u8      scsi_id;
197         u8      scsi_lun;
198         u8      state;
199         u16     tid;
200         struct i2o_device* pI2o_dev;
201         Scsi_Device *pScsi_dev;
202 };
203
204 struct adpt_channel {
205         struct adpt_device* device[MAX_ID];     /* used as an array of 128 scsi ids */
206         u8      scsi_id;
207         u8      type;
208         u16     tid;
209         u32     state;
210         struct i2o_device* pI2o_dev;
211 };
212
213 // HBA state flags
214 #define DPTI_STATE_RESET        (0x01)
215 #define DPTI_STATE_IOCTL        (0x02)
216
217 typedef struct _adpt_hba {
218         struct _adpt_hba *next;
219         struct pci_dev *pDev;
220         struct Scsi_Host *host;
221         u32 state;
222         spinlock_t state_lock;
223         int unit;
224         int host_no;            /* SCSI host number */
225         u8 initialized;
226         u8 in_use;              /* is the management node open*/
227
228         char name[32];
229         char detail[55];
230
231         ulong base_addr_virt;
232         ulong msg_addr_virt;
233         ulong base_addr_phys;
234         ulong  post_port;
235         ulong  reply_port;
236         ulong  irq_mask;
237         u16  post_count;
238         u32  post_fifo_size;
239         u32  reply_fifo_size;
240         u32* reply_pool;
241         u32  sg_tablesize;      // Scatter/Gather List Size.       
242         u8  top_scsi_channel;
243         u8  top_scsi_id;
244         u8  top_scsi_lun;
245
246         i2o_status_block* status_block;
247         i2o_hrt* hrt;
248         i2o_lct* lct;
249         uint lct_size;
250         struct i2o_device* devices;
251         struct adpt_channel channel[MAX_CHANNEL];
252         struct proc_dir_entry* proc_entry;      /* /proc dir */
253
254         ulong FwDebugBuffer_P;  // Virtual Address Of FW Debug Buffer
255         u32   FwDebugBufferSize;        // FW Debug Buffer Size In Bytes
256         ulong FwDebugStrLength_P;       // Virtual Addr Of FW Debug String Len
257         ulong FwDebugFlags_P;   // Virtual Address Of FW Debug Flags 
258         ulong FwDebugBLEDflag_P;        // Virtual Addr Of FW Debug BLED
259         ulong FwDebugBLEDvalue_P;       // Virtual Addr Of FW Debug BLED
260         u32 FwDebugFlags;
261 } adpt_hba;
262
263 struct sg_simple_element {
264    u32  flag_count;
265    u32 addr_bus;
266 }; 
267
268 /*
269  * Function Prototypes
270  */
271
272 static void adpt_i2o_sys_shutdown(void);
273 static int adpt_init(void);
274 static int adpt_i2o_build_sys_table(void);
275 static irqreturn_t adpt_isr(int irq, void *dev_id, struct pt_regs *regs);
276 #ifdef REBOOT_NOTIFIER
277 static int adpt_reboot_event(struct notifier_block *n, ulong code, void *p);
278 #endif
279
280 static void adpt_i2o_report_hba_unit(adpt_hba* pHba, struct i2o_device *d);
281 static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid, 
282                         int group, int field, void *buf, int buflen);
283 #ifdef DEBUG
284 static const char *adpt_i2o_get_class_name(int class);
285 #endif
286 static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid, 
287                   void *opblk, int oplen, void *resblk, int reslen);
288 static int adpt_i2o_post_wait(adpt_hba* pHba, u32* msg, int len, int timeout);
289 static int adpt_i2o_lct_get(adpt_hba* pHba);
290 static int adpt_i2o_parse_lct(adpt_hba* pHba);
291 static int adpt_i2o_activate_hba(adpt_hba* pHba);
292 static int adpt_i2o_enable_hba(adpt_hba* pHba);
293 static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d);
294 static s32 adpt_i2o_post_this(adpt_hba* pHba, u32* data, int len);
295 static s32 adpt_i2o_quiesce_hba(adpt_hba* pHba);
296 static s32 adpt_i2o_status_get(adpt_hba* pHba);
297 static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba);
298 static s32 adpt_i2o_hrt_get(adpt_hba* pHba);
299 static s32 adpt_scsi_to_i2o(adpt_hba* pHba, Scsi_Cmnd* cmd, struct adpt_device* dptdevice);
300 static s32 adpt_i2o_to_scsi(ulong reply, Scsi_Cmnd* cmd);
301 static s32 adpt_scsi_register(adpt_hba* pHba,Scsi_Host_Template * sht);
302 static s32 adpt_hba_reset(adpt_hba* pHba);
303 static s32 adpt_i2o_reset_hba(adpt_hba* pHba);
304 static s32 adpt_rescan(adpt_hba* pHba);
305 static s32 adpt_i2o_reparse_lct(adpt_hba* pHba);
306 static s32 adpt_send_nop(adpt_hba*pHba,u32 m);
307 static void adpt_i2o_delete_hba(adpt_hba* pHba);
308 static void adpt_inquiry(adpt_hba* pHba);
309 static void adpt_fail_posted_scbs(adpt_hba* pHba);
310 static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u32 lun);
311 static int adpt_install_hba(Scsi_Host_Template* sht, struct pci_dev* pDev) ;
312 static int adpt_i2o_online_hba(adpt_hba* pHba);
313 static void adpt_i2o_post_wait_complete(u32, int);
314 static int adpt_i2o_systab_send(adpt_hba* pHba);
315
316 static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg);
317 static int adpt_open(struct inode *inode, struct file *file);
318 static int adpt_close(struct inode *inode, struct file *file);
319
320
321 #ifdef UARTDELAY
322 static void adpt_delay(int millisec);
323 #endif
324
325 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
326 static struct pci_dev* adpt_pci_find_device(uint vendor, struct pci_dev* from);
327 #endif
328
329 #if defined __ia64__ 
330 static void adpt_ia64_info(sysInfo_S* si);
331 #endif
332 #if defined __sparc__ 
333 static void adpt_sparc_info(sysInfo_S* si);
334 #endif
335 #if defined __alpha__ 
336 static void adpt_sparc_info(sysInfo_S* si);
337 #endif
338 #if defined __i386__
339 static void adpt_i386_info(sysInfo_S* si);
340 #endif
341
342 #define PRINT_BUFFER_SIZE     512
343
344 #define HBA_FLAGS_DBG_FLAGS_MASK         0xffff0000     // Mask for debug flags
345 #define HBA_FLAGS_DBG_KERNEL_PRINT_B     0x00010000     // Kernel Debugger Print
346 #define HBA_FLAGS_DBG_FW_PRINT_B         0x00020000     // Firmware Debugger Print
347 #define HBA_FLAGS_DBG_FUNCTION_ENTRY_B   0x00040000     // Function Entry Point
348 #define HBA_FLAGS_DBG_FUNCTION_EXIT_B    0x00080000     // Function Exit
349 #define HBA_FLAGS_DBG_ERROR_B            0x00100000     // Error Conditions
350 #define HBA_FLAGS_DBG_INIT_B             0x00200000     // Init Prints
351 #define HBA_FLAGS_DBG_OS_COMMANDS_B      0x00400000     // OS Command Info
352 #define HBA_FLAGS_DBG_SCAN_B             0x00800000     // Device Scan
353
354 #define FW_DEBUG_STR_LENGTH_OFFSET 0
355 #define FW_DEBUG_FLAGS_OFFSET      4
356 #define FW_DEBUG_BLED_OFFSET       8
357
358 #define FW_DEBUG_FLAGS_NO_HEADERS_B    0x01
359 #endif                          /* !HOSTS_C */
360 #endif                          /* _DPT_H */