patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / scsi / qla1280.h
1 /******************************************************************************
2 *                  QLOGIC LINUX SOFTWARE
3 *
4 * QLogic ISP1280 (Ultra2) /12160 (Ultra3) SCSI driver
5 * Copyright (C) 2000 Qlogic Corporation
6 * (www.qlogic.com)
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 ******************************************************************************/
19
20 #ifndef _QLA1280_H
21 #define _QLA1280_H
22
23 /*
24  * Data bit definitions.
25  */
26 #define BIT_0   0x1
27 #define BIT_1   0x2
28 #define BIT_2   0x4
29 #define BIT_3   0x8
30 #define BIT_4   0x10
31 #define BIT_5   0x20
32 #define BIT_6   0x40
33 #define BIT_7   0x80
34 #define BIT_8   0x100
35 #define BIT_9   0x200
36 #define BIT_10  0x400
37 #define BIT_11  0x800
38 #define BIT_12  0x1000
39 #define BIT_13  0x2000
40 #define BIT_14  0x4000
41 #define BIT_15  0x8000
42 #define BIT_16  0x10000
43 #define BIT_17  0x20000
44 #define BIT_18  0x40000
45 #define BIT_19  0x80000
46 #define BIT_20  0x100000
47 #define BIT_21  0x200000
48 #define BIT_22  0x400000
49 #define BIT_23  0x800000
50 #define BIT_24  0x1000000
51 #define BIT_25  0x2000000
52 #define BIT_26  0x4000000
53 #define BIT_27  0x8000000
54 #define BIT_28  0x10000000
55 #define BIT_29  0x20000000
56 #define BIT_30  0x40000000
57 #define BIT_31  0x80000000
58
59 #if MEMORY_MAPPED_IO
60 #define RD_REG_WORD(addr)               readw_relaxed(addr)
61 #define RD_REG_WORD_dmasync(addr)       readw(addr)
62 #define WRT_REG_WORD(addr, data)        writew(data, addr)
63 #else                           /* MEMORY_MAPPED_IO */
64 #define RD_REG_WORD(addr)               inw((unsigned long)addr)
65 #define WRT_REG_WORD(addr, data)        outw(data, (unsigned long)addr)
66 #endif                          /* MEMORY_MAPPED_IO */
67
68 /*
69  * Host adapter default definitions.
70  */
71 #define MAX_BUSES       2       /* 2 */
72 #define MAX_B_BITS      1
73
74 #define MAX_TARGETS     16      /* 16 */
75 #define MAX_T_BITS      4       /* 4 */
76
77 #define MAX_LUNS        8       /* 32 */
78 #define MAX_L_BITS      3       /* 5 */
79
80 /*
81  * Watchdog time quantum
82  */
83 #define QLA1280_WDG_TIME_QUANTUM        5       /* In seconds */
84
85 /* Command retry count (0-65535) */
86 #define COMMAND_RETRY_COUNT             255
87
88 /* Maximum outstanding commands in ISP queues */
89 #define MAX_OUTSTANDING_COMMANDS        512
90 #define INVALID_HANDLE                  (MAX_OUTSTANDING_COMMANDS + 2)
91
92 /* ISP request and response entry counts (37-65535) */
93 #define REQUEST_ENTRY_CNT               256 /* Number of request entries. */
94 #define RESPONSE_ENTRY_CNT              16  /* Number of response entries. */
95
96 /* Number of segments 1 - 65535 */
97 #define SG_SEGMENTS                     32  /* Cmd entry + 6 continuations */
98
99 /*
100  * SCSI Request Block structure  (sp)  that is placed
101  * on cmd->SCp location of every I/O
102  */
103 struct srb {
104         struct list_head list;          /* (8/16) LU queue */
105         struct scsi_cmnd *cmd;  /* (4/8) SCSI command block */
106         /* NOTE: the sp->cmd will be NULL when this completion is
107          * called, so you should know the scsi_cmnd when using this */
108         struct completion *wait;
109         dma_addr_t saved_dma_handle;    /* for unmap of single transfers */
110         uint8_t flags;          /* (1) Status flags. */
111         uint8_t dir;            /* direction of transfer */
112 };
113
114 /*
115  * SRB flag definitions
116  */
117 #define SRB_TIMEOUT             (1 << 0)        /* Command timed out */
118 #define SRB_SENT                (1 << 1)        /* Command sent to ISP */
119 #define SRB_ABORT_PENDING       (1 << 2)        /* Command abort sent to device */
120 #define SRB_ABORTED             (1 << 3)        /* Command aborted command already */
121
122 /*
123  *  ISP I/O Register Set structure definitions.
124  */
125 struct device_reg {
126         uint16_t id_l;          /* ID low */
127         uint16_t id_h;          /* ID high */
128         uint16_t cfg_0;         /* Configuration 0 */
129         uint16_t cfg_1;         /* Configuration 1 */
130         uint16_t ictrl;         /* Interface control */
131 #define ISP_RESET        BIT_0  /* ISP soft reset */
132 #define ISP_EN_INT       BIT_1  /* ISP enable interrupts. */
133 #define ISP_EN_RISC      BIT_2  /* ISP enable RISC interrupts. */
134 #define ISP_FLASH_ENABLE BIT_8  /* Flash BIOS Read/Write enable */
135 #define ISP_FLASH_UPPER  BIT_9  /* Flash upper bank select */
136         uint16_t istatus;       /* Interface status */
137 #define PCI_64BIT_SLOT   BIT_14 /* PCI 64-bit slot indicator. */
138 #define RISC_INT         BIT_2  /* RISC interrupt */
139 #define PCI_INT          BIT_1  /* PCI interrupt */
140         uint16_t semaphore;     /* Semaphore */
141         uint16_t nvram;         /* NVRAM register. */
142 #define NV_DESELECT     0
143 #define NV_CLOCK        BIT_0
144 #define NV_SELECT       BIT_1
145 #define NV_DATA_OUT     BIT_2
146 #define NV_DATA_IN      BIT_3
147         uint16_t flash_data;    /* Flash BIOS data */
148         uint16_t flash_address; /* Flash BIOS address */
149
150         uint16_t unused_1[0x2e];        /* 0x14-0x6f Gap */
151
152         uint16_t mailbox0;      /* Mailbox 0 */
153         uint16_t mailbox1;      /* Mailbox 1 */
154         uint16_t mailbox2;      /* Mailbox 2 */
155         uint16_t mailbox3;      /* Mailbox 3 */
156         uint16_t mailbox4;      /* Mailbox 4 */
157         uint16_t mailbox5;      /* Mailbox 5 */
158         uint16_t mailbox6;      /* Mailbox 6 */
159         uint16_t mailbox7;      /* Mailbox 7 */
160
161         uint16_t unused_2[0x20];/* 0x80-0xbf Gap */
162
163         uint16_t host_cmd;      /* Host command and control */
164 #define HOST_INT      BIT_7     /* host interrupt bit */
165 #define BIOS_ENABLE   BIT_0
166
167         uint16_t unused_6[0x5]; /* 0xc2-0xcb Gap */
168
169         uint16_t gpio_data;
170         uint16_t gpio_enable;
171
172         uint16_t unused_7[0x11];        /* d0-f0 */
173         uint16_t scsiControlPins;       /* f2 */
174 };
175
176 #define MAILBOX_REGISTER_COUNT  8
177
178 /*
179  *  ISP product identification definitions in mailboxes after reset.
180  */
181 #define PROD_ID_1               0x4953
182 #define PROD_ID_2               0x0000
183 #define PROD_ID_2a              0x5020
184 #define PROD_ID_3               0x2020
185 #define PROD_ID_4               0x1
186
187 /*
188  * ISP host command and control register command definitions
189  */
190 #define HC_RESET_RISC           0x1000  /* Reset RISC */
191 #define HC_PAUSE_RISC           0x2000  /* Pause RISC */
192 #define HC_RELEASE_RISC         0x3000  /* Release RISC from reset. */
193 #define HC_SET_HOST_INT         0x5000  /* Set host interrupt */
194 #define HC_CLR_HOST_INT         0x6000  /* Clear HOST interrupt */
195 #define HC_CLR_RISC_INT         0x7000  /* Clear RISC interrupt */
196 #define HC_DISABLE_BIOS         0x9000  /* Disable BIOS. */
197
198 /*
199  * ISP mailbox Self-Test status codes
200  */
201 #define MBS_FRM_ALIVE           0       /* Firmware Alive. */
202 #define MBS_CHKSUM_ERR          1       /* Checksum Error. */
203 #define MBS_SHADOW_LD_ERR       2       /* Shadow Load Error. */
204 #define MBS_BUSY                4       /* Busy. */
205
206 /*
207  * ISP mailbox command complete status codes
208  */
209 #define MBS_CMD_CMP             0x4000  /* Command Complete. */
210 #define MBS_INV_CMD             0x4001  /* Invalid Command. */
211 #define MBS_HOST_INF_ERR        0x4002  /* Host Interface Error. */
212 #define MBS_TEST_FAILED         0x4003  /* Test Failed. */
213 #define MBS_CMD_ERR             0x4005  /* Command Error. */
214 #define MBS_CMD_PARAM_ERR       0x4006  /* Command Parameter Error. */
215
216 /*
217  * ISP mailbox asynchronous event status codes
218  */
219 #define MBA_ASYNC_EVENT         0x8000  /* Asynchronous event. */
220 #define MBA_BUS_RESET           0x8001  /* SCSI Bus Reset. */
221 #define MBA_SYSTEM_ERR          0x8002  /* System Error. */
222 #define MBA_REQ_TRANSFER_ERR    0x8003  /* Request Transfer Error. */
223 #define MBA_RSP_TRANSFER_ERR    0x8004  /* Response Transfer Error. */
224 #define MBA_WAKEUP_THRES        0x8005  /* Request Queue Wake-up. */
225 #define MBA_TIMEOUT_RESET       0x8006  /* Execution Timeout Reset. */
226 #define MBA_DEVICE_RESET        0x8007  /* Bus Device Reset. */
227 #define MBA_BUS_MODE_CHANGE     0x800E  /* SCSI bus mode transition. */
228 #define MBA_SCSI_COMPLETION     0x8020  /* Completion response. */
229
230 /*
231  * ISP mailbox commands
232  */
233 #define MBC_NOP                         0       /* No Operation */
234 #define MBC_LOAD_RAM                    1       /* Load RAM */
235 #define MBC_EXECUTE_FIRMWARE            2       /* Execute firmware */
236 #define MBC_DUMP_RAM                    3       /* Dump RAM contents */
237 #define MBC_WRITE_RAM_WORD              4       /* Write ram word */
238 #define MBC_READ_RAM_WORD               5       /* Read ram word */
239 #define MBC_MAILBOX_REGISTER_TEST       6       /* Wrap incoming mailboxes */
240 #define MBC_VERIFY_CHECKSUM             7       /* Verify checksum */
241 #define MBC_ABOUT_FIRMWARE              8       /* Get firmware revision */
242 #define MBC_INIT_REQUEST_QUEUE          0x10    /* Initialize request queue */
243 #define MBC_INIT_RESPONSE_QUEUE         0x11    /* Initialize response queue */
244 #define MBC_EXECUTE_IOCB                0x12    /* Execute IOCB command */
245 #define MBC_ABORT_COMMAND               0x15    /* Abort IOCB command */
246 #define MBC_ABORT_DEVICE                0x16    /* Abort device (ID/LUN) */
247 #define MBC_ABORT_TARGET                0x17    /* Abort target (ID) */
248 #define MBC_BUS_RESET                   0x18    /* SCSI bus reset */
249 #define MBC_GET_RETRY_COUNT             0x22    /* Get retry count and delay */
250 #define MBC_GET_TARGET_PARAMETERS       0x28    /* Get target parameters */
251 #define MBC_SET_INITIATOR_ID            0x30    /* Set initiator SCSI ID */
252 #define MBC_SET_SELECTION_TIMEOUT       0x31    /* Set selection timeout */
253 #define MBC_SET_RETRY_COUNT             0x32    /* Set retry count and delay */
254 #define MBC_SET_TAG_AGE_LIMIT           0x33    /* Set tag age limit */
255 #define MBC_SET_CLOCK_RATE              0x34    /* Set clock rate */
256 #define MBC_SET_ACTIVE_NEGATION         0x35    /* Set active negation state */
257 #define MBC_SET_ASYNC_DATA_SETUP        0x36    /* Set async data setup time */
258 #define MBC_SET_PCI_CONTROL             0x37    /* Set BUS control parameters */
259 #define MBC_SET_TARGET_PARAMETERS       0x38    /* Set target parameters */
260 #define MBC_SET_DEVICE_QUEUE            0x39    /* Set device queue parameters */
261 #define MBC_SET_RESET_DELAY_PARAMETERS  0x3A    /* Set reset delay parameters */
262 #define MBC_SET_SYSTEM_PARAMETER        0x45    /* Set system parameter word */
263 #define MBC_SET_FIRMWARE_FEATURES       0x4A    /* Set firmware feature word */
264 #define MBC_INIT_REQUEST_QUEUE_A64      0x52    /* Initialize request queue A64 */
265 #define MBC_INIT_RESPONSE_QUEUE_A64     0x53    /* Initialize response q A64 */
266 #define MBC_ENABLE_TARGET_MODE          0x55    /* Enable target mode */
267 #define MBC_SET_DATA_OVERRUN_RECOVERY   0x5A    /* Set data overrun recovery mode */
268
269 /*
270  * ISP Get/Set Target Parameters mailbox command control flags.
271  */
272 #define TP_PPR                  BIT_5   /* PPR */
273 #define TP_RENEGOTIATE          BIT_8   /* Renegotiate on error. */
274 #define TP_STOP_QUEUE           BIT_9   /* Stop que on check condition */
275 #define TP_AUTO_REQUEST_SENSE   BIT_10  /* Automatic request sense. */
276 #define TP_TAGGED_QUEUE         BIT_11  /* Tagged queuing. */
277 #define TP_SYNC                 BIT_12  /* Synchronous data transfers. */
278 #define TP_WIDE                 BIT_13  /* Wide data transfers. */
279 #define TP_PARITY               BIT_14  /* Parity checking. */
280 #define TP_DISCONNECT           BIT_15  /* Disconnect privilege. */
281
282 /*
283  * NVRAM Command values.
284  */
285 #define NV_START_BIT            BIT_2
286 #define NV_WRITE_OP             (BIT_26 | BIT_24)
287 #define NV_READ_OP              (BIT_26 | BIT_25)
288 #define NV_ERASE_OP             (BIT_26 | BIT_25 | BIT_24)
289 #define NV_MASK_OP              (BIT_26 | BIT_25 | BIT_24)
290 #define NV_DELAY_COUNT          10
291
292 /*
293  *  QLogic ISP1280/ISP12160 NVRAM structure definition.
294  */
295 struct nvram {
296         uint8_t id0;            /* 0 */
297         uint8_t id1;            /* 1 */
298         uint8_t id2;            /* 2 */
299         uint8_t id3;            /* 3 */
300         uint8_t version;        /* 4 */
301
302         struct {
303                 uint8_t bios_configuration_mode:2;
304                 uint8_t bios_disable:1;
305                 uint8_t selectable_scsi_boot_enable:1;
306                 uint8_t cd_rom_boot_enable:1;
307                 uint8_t disable_loading_risc_code:1;
308                 uint8_t enable_64bit_addressing:1;
309                 uint8_t unused_7:1;
310         } cntr_flags_1;         /* 5 */
311
312         struct {
313                 uint8_t boot_lun_number:5;
314                 uint8_t scsi_bus_number:1;
315                 uint8_t unused_6:1;
316                 uint8_t unused_7:1;
317         } cntr_flags_2l;        /* 7 */
318
319         struct {
320                 uint8_t boot_target_number:4;
321                 uint8_t unused_12:1;
322                 uint8_t unused_13:1;
323                 uint8_t unused_14:1;
324                 uint8_t unused_15:1;
325         } cntr_flags_2h;        /* 8 */
326
327         uint16_t unused_8;      /* 8, 9 */
328         uint16_t unused_10;     /* 10, 11 */
329         uint16_t unused_12;     /* 12, 13 */
330         uint16_t unused_14;     /* 14, 15 */
331
332         union {
333                 uint8_t c;
334                 struct {
335                         uint8_t reserved:2;
336                         uint8_t burst_enable:1;
337                         uint8_t reserved_1:1;
338                         uint8_t fifo_threshold:4;
339                 } f;
340         } isp_config;           /* 16 */
341
342         /* Termination
343          * 0 = Disable, 1 = high only, 3 = Auto term
344          */
345         union {
346                 uint8_t c;
347                 struct {
348                         uint8_t scsi_bus_1_control:2;
349                         uint8_t scsi_bus_0_control:2;
350                         uint8_t unused_0:1;
351                         uint8_t unused_1:1;
352                         uint8_t unused_2:1;
353                         uint8_t auto_term_support:1;
354                 } f;
355         } termination;          /* 17 */
356
357         uint16_t isp_parameter; /* 18, 19 */
358
359         union {
360                 uint16_t w;
361                 struct {
362                         uint16_t enable_fast_posting:1;
363                         uint16_t report_lvd_bus_transition:1;
364                         uint16_t unused_2:1;
365                         uint16_t unused_3:1;
366                         uint16_t disable_iosbs_with_bus_reset_status:1;
367                         uint16_t disable_synchronous_backoff:1;
368                         uint16_t unused_6:1;
369                         uint16_t synchronous_backoff_reporting:1;
370                         uint16_t disable_reselection_fairness:1;
371                         uint16_t unused_9:1;
372                         uint16_t unused_10:1;
373                         uint16_t unused_11:1;
374                         uint16_t unused_12:1;
375                         uint16_t unused_13:1;
376                         uint16_t unused_14:1;
377                         uint16_t unused_15:1;
378                 } f;
379         } firmware_feature;     /* 20, 21 */
380
381         uint16_t unused_22;     /* 22, 23 */
382
383         struct {
384                 struct {
385                         uint8_t initiator_id:4;
386                         uint8_t scsi_reset_disable:1;
387                         uint8_t scsi_bus_size:1;
388                         uint8_t scsi_bus_type:1;
389                         uint8_t unused_7:1;
390                 } config_1;     /* 24 */
391
392                 uint8_t bus_reset_delay;        /* 25 */
393                 uint8_t retry_count;    /* 26 */
394                 uint8_t retry_delay;    /* 27 */
395
396                 struct {
397                         uint8_t async_data_setup_time:4;
398                         uint8_t req_ack_active_negation:1;
399                         uint8_t data_line_active_negation:1;
400                         uint8_t unused_6:1;
401                         uint8_t unused_7:1;
402                 } config_2;     /* 28 */
403
404                 uint8_t unused_29;      /* 29 */
405
406                 uint16_t selection_timeout;     /* 30, 31 */
407                 uint16_t max_queue_depth;       /* 32, 33 */
408
409                 uint16_t unused_34;     /* 34, 35 */
410                 uint16_t unused_36;     /* 36, 37 */
411                 uint16_t unused_38;     /* 38, 39 */
412
413                 struct {
414                         union {
415                                 uint8_t c;
416                                 struct {
417                                         uint8_t renegotiate_on_error:1;
418                                         uint8_t stop_queue_on_check:1;
419                                         uint8_t auto_request_sense:1;
420                                         uint8_t tag_queuing:1;
421                                         uint8_t enable_sync:1;
422                                         uint8_t enable_wide:1;
423                                         uint8_t parity_checking:1;
424                                         uint8_t disconnect_allowed:1;
425                                 } f;
426                         } parameter;    /* 40 */
427
428                         uint8_t execution_throttle;     /* 41 */
429                         uint8_t sync_period;    /* 42 */
430
431                         union {         /* 43 */
432                                 uint8_t flags_43;
433                                 struct {
434                                         uint8_t sync_offset:4;
435                                         uint8_t device_enable:1;
436                                         uint8_t lun_disable:1;
437                                         uint8_t unused_6:1;
438                                         uint8_t unused_7:1;
439                                 } flags1x80;
440                                 struct {
441                                         uint8_t sync_offset:5;
442                                         uint8_t device_enable:1;
443                                         uint8_t unused_6:1;
444                                         uint8_t unused_7:1;
445                                 } flags1x160;
446                         } flags;
447                         union { /* PPR flags for the 1x160 controllers */
448                                 uint8_t unused_44;
449                                 struct {
450                                         uint8_t ppr_options:4;
451                                         uint8_t ppr_bus_width:2;
452                                         uint8_t unused_8:1;
453                                         uint8_t enable_ppr:1;
454                                 } flags;        /* 44 */
455                         } ppr_1x160;
456                         uint8_t unused_45;      /* 45 */
457                 } target[MAX_TARGETS];
458         } bus[MAX_BUSES];
459
460         uint16_t unused_248;    /* 248, 249 */
461
462         uint16_t subsystem_id[2];       /* 250, 251, 252, 253 */
463
464         union {                         /* 254 */
465                 uint8_t unused_254;
466                 uint8_t system_id_pointer;
467         } sysid_1x160;
468
469         uint8_t chksum;         /* 255 */
470 };
471
472 /*
473  * ISP queue - command entry structure definition.
474  */
475 #define MAX_CMDSZ       12              /* SCSI maximum CDB size. */
476 struct cmd_entry {
477         uint8_t entry_type;             /* Entry type. */
478 #define COMMAND_TYPE    1               /* Command entry */
479         uint8_t entry_count;            /* Entry count. */
480         uint8_t sys_define;             /* System defined. */
481         uint8_t entry_status;           /* Entry Status. */
482         uint32_t handle;                /* System handle. */
483         uint8_t lun;                    /* SCSI LUN */
484         uint8_t target;                 /* SCSI ID */
485         uint16_t cdb_len;               /* SCSI command length. */
486         uint16_t control_flags;         /* Control flags. */
487         uint16_t reserved;
488         uint16_t timeout;               /* Command timeout. */
489         uint16_t dseg_count;            /* Data segment count. */
490         uint8_t scsi_cdb[MAX_CMDSZ];    /* SCSI command words. */
491         uint32_t dseg_0_address;        /* Data segment 0 address. */
492         uint32_t dseg_0_length;         /* Data segment 0 length. */
493         uint32_t dseg_1_address;        /* Data segment 1 address. */
494         uint32_t dseg_1_length;         /* Data segment 1 length. */
495         uint32_t dseg_2_address;        /* Data segment 2 address. */
496         uint32_t dseg_2_length;         /* Data segment 2 length. */
497         uint32_t dseg_3_address;        /* Data segment 3 address. */
498         uint32_t dseg_3_length;         /* Data segment 3 length. */
499 };
500
501 /*
502  * ISP queue - continuation entry structure definition.
503  */
504 struct cont_entry {
505         uint8_t entry_type;             /* Entry type. */
506 #define CONTINUE_TYPE   2               /* Continuation entry. */
507         uint8_t entry_count;            /* Entry count. */
508         uint8_t sys_define;             /* System defined. */
509         uint8_t entry_status;           /* Entry Status. */
510         uint32_t reserved;              /* Reserved */
511         uint32_t dseg_0_address;        /* Data segment 0 address. */
512         uint32_t dseg_0_length;         /* Data segment 0 length. */
513         uint32_t dseg_1_address;        /* Data segment 1 address. */
514         uint32_t dseg_1_length;         /* Data segment 1 length. */
515         uint32_t dseg_2_address;        /* Data segment 2 address. */
516         uint32_t dseg_2_length;         /* Data segment 2 length. */
517         uint32_t dseg_3_address;        /* Data segment 3 address. */
518         uint32_t dseg_3_length;         /* Data segment 3 length. */
519         uint32_t dseg_4_address;        /* Data segment 4 address. */
520         uint32_t dseg_4_length;         /* Data segment 4 length. */
521         uint32_t dseg_5_address;        /* Data segment 5 address. */
522         uint32_t dseg_5_length;         /* Data segment 5 length. */
523         uint32_t dseg_6_address;        /* Data segment 6 address. */
524         uint32_t dseg_6_length;         /* Data segment 6 length. */
525 };
526
527 /*
528  * ISP queue - status entry structure definition.
529  */
530 struct response {
531         uint8_t entry_type;     /* Entry type. */
532 #define STATUS_TYPE     3       /* Status entry. */
533         uint8_t entry_count;    /* Entry count. */
534         uint8_t sys_define;     /* System defined. */
535         uint8_t entry_status;   /* Entry Status. */
536 #define RF_CONT         BIT_0   /* Continuation. */
537 #define RF_FULL         BIT_1   /* Full */
538 #define RF_BAD_HEADER   BIT_2   /* Bad header. */
539 #define RF_BAD_PAYLOAD  BIT_3   /* Bad payload. */
540         uint32_t handle;        /* System handle. */
541         uint16_t scsi_status;   /* SCSI status. */
542         uint16_t comp_status;   /* Completion status. */
543         uint16_t state_flags;   /* State flags. */
544 #define SF_TRANSFER_CMPL BIT_14 /* Transfer Complete. */
545 #define SF_GOT_SENSE    BIT_13  /* Got Sense */
546 #define SF_GOT_STATUS    BIT_12 /* Got Status */
547 #define SF_TRANSFERRED_DATA BIT_11      /* Transferred data */
548 #define SF_SENT_CDB   BIT_10    /* Send CDB */
549 #define SF_GOT_TARGET  BIT_9    /*  */
550 #define SF_GOT_BUS     BIT_8    /*  */
551         uint16_t status_flags;  /* Status flags. */
552         uint16_t time;          /* Time. */
553         uint16_t req_sense_length;      /* Request sense data length. */
554         uint32_t residual_length;       /* Residual transfer length. */
555         uint16_t reserved[4];
556         uint8_t req_sense_data[32];     /* Request sense data. */
557 };
558
559 /*
560  * ISP queue - marker entry structure definition.
561  */
562 struct mrk_entry {
563         uint8_t entry_type;     /* Entry type. */
564 #define MARKER_TYPE     4       /* Marker entry. */
565         uint8_t entry_count;    /* Entry count. */
566         uint8_t sys_define;     /* System defined. */
567         uint8_t entry_status;   /* Entry Status. */
568         uint32_t reserved;
569         uint8_t lun;            /* SCSI LUN */
570         uint8_t target;         /* SCSI ID */
571         uint8_t modifier;       /* Modifier (7-0). */
572 #define MK_SYNC_ID_LUN      0   /* Synchronize ID/LUN */
573 #define MK_SYNC_ID          1   /* Synchronize ID */
574 #define MK_SYNC_ALL         2   /* Synchronize all ID/LUN */
575         uint8_t reserved_1[53];
576 };
577
578 /*
579  * ISP queue - extended command entry structure definition.
580  *
581  * Unused by the driver!
582  */
583 struct ecmd_entry {
584         uint8_t entry_type;     /* Entry type. */
585 #define EXTENDED_CMD_TYPE  5    /* Extended command entry. */
586         uint8_t entry_count;    /* Entry count. */
587         uint8_t sys_define;     /* System defined. */
588         uint8_t entry_status;   /* Entry Status. */
589         uint32_t handle;        /* System handle. */
590         uint8_t lun;            /* SCSI LUN */
591         uint8_t target;         /* SCSI ID */
592         uint16_t cdb_len;       /* SCSI command length. */
593         uint16_t control_flags; /* Control flags. */
594         uint16_t reserved;
595         uint16_t timeout;       /* Command timeout. */
596         uint16_t dseg_count;    /* Data segment count. */
597         uint8_t scsi_cdb[88];   /* SCSI command words. */
598 };
599
600 /*
601  * ISP queue - 64-Bit addressing, command entry structure definition.
602  */
603 typedef struct {
604         uint8_t entry_type;     /* Entry type. */
605 #define COMMAND_A64_TYPE 9      /* Command A64 entry */
606         uint8_t entry_count;    /* Entry count. */
607         uint8_t sys_define;     /* System defined. */
608         uint8_t entry_status;   /* Entry Status. */
609         uint32_t handle;        /* System handle. */
610         uint8_t lun;            /* SCSI LUN */
611         uint8_t target;         /* SCSI ID */
612         uint16_t cdb_len;       /* SCSI command length. */
613         uint16_t control_flags; /* Control flags. */
614         uint16_t reserved;
615         uint16_t timeout;       /* Command timeout. */
616         uint16_t dseg_count;    /* Data segment count. */
617         uint8_t scsi_cdb[MAX_CMDSZ];    /* SCSI command words. */
618         uint32_t reserved_1[2]; /* unused */
619         uint32_t dseg_0_address[2];     /* Data segment 0 address. */
620         uint32_t dseg_0_length; /* Data segment 0 length. */
621         uint32_t dseg_1_address[2];     /* Data segment 1 address. */
622         uint32_t dseg_1_length; /* Data segment 1 length. */
623 } cmd_a64_entry_t, request_t;
624
625 /*
626  * ISP queue - 64-Bit addressing, continuation entry structure definition.
627  */
628 struct cont_a64_entry {
629         uint8_t entry_type;     /* Entry type. */
630 #define CONTINUE_A64_TYPE 0xA   /* Continuation A64 entry. */
631         uint8_t entry_count;    /* Entry count. */
632         uint8_t sys_define;     /* System defined. */
633         uint8_t entry_status;   /* Entry Status. */
634         uint32_t dseg_0_address[2];     /* Data segment 0 address. */
635         uint32_t dseg_0_length; /* Data segment 0 length. */
636         uint32_t dseg_1_address[2];     /* Data segment 1 address. */
637         uint32_t dseg_1_length; /* Data segment 1 length. */
638         uint32_t dseg_2_address[2];     /* Data segment 2 address. */
639         uint32_t dseg_2_length; /* Data segment 2 length. */
640         uint32_t dseg_3_address[2];     /* Data segment 3 address. */
641         uint32_t dseg_3_length; /* Data segment 3 length. */
642         uint32_t dseg_4_address[2];     /* Data segment 4 address. */
643         uint32_t dseg_4_length; /* Data segment 4 length. */
644 };
645
646 /*
647  * ISP queue - enable LUN entry structure definition.
648  */
649 struct elun_entry {
650         uint8_t entry_type;     /* Entry type. */
651 #define ENABLE_LUN_TYPE 0xB     /* Enable LUN entry. */
652         uint8_t entry_count;    /* Entry count. */
653         uint8_t reserved_1;
654         uint8_t entry_status;   /* Entry Status not used. */
655         uint32_t reserved_2;
656         uint16_t lun;           /* Bit 15 is bus number. */
657         uint16_t reserved_4;
658         uint32_t option_flags;
659         uint8_t status;
660         uint8_t reserved_5;
661         uint8_t command_count;  /* Number of ATIOs allocated. */
662         uint8_t immed_notify_count;     /* Number of Immediate Notify */
663         /* entries allocated. */
664         uint8_t group_6_length; /* SCSI CDB length for group 6 */
665         /* commands (2-26). */
666         uint8_t group_7_length; /* SCSI CDB length for group 7 */
667         /* commands (2-26). */
668         uint16_t timeout;       /* 0 = 30 seconds, 0xFFFF = disable */
669         uint16_t reserved_6[20];
670 };
671
672 /*
673  * ISP queue - modify LUN entry structure definition.
674  *
675  * Unused by the driver!
676  */
677 struct modify_lun_entry {
678         uint8_t entry_type;     /* Entry type. */
679 #define MODIFY_LUN_TYPE 0xC     /* Modify LUN entry. */
680         uint8_t entry_count;    /* Entry count. */
681         uint8_t reserved_1;
682         uint8_t entry_status;   /* Entry Status. */
683         uint32_t reserved_2;
684         uint8_t lun;            /* SCSI LUN */
685         uint8_t reserved_3;
686         uint8_t operators;
687         uint8_t reserved_4;
688         uint32_t option_flags;
689         uint8_t status;
690         uint8_t reserved_5;
691         uint8_t command_count;  /* Number of ATIOs allocated. */
692         uint8_t immed_notify_count;     /* Number of Immediate Notify */
693         /* entries allocated. */
694         uint16_t reserved_6;
695         uint16_t timeout;       /* 0 = 30 seconds, 0xFFFF = disable */
696         uint16_t reserved_7[20];
697 };
698
699 /*
700  * ISP queue - immediate notify entry structure definition.
701  */
702 struct notify_entry {
703         uint8_t entry_type;     /* Entry type. */
704 #define IMMED_NOTIFY_TYPE 0xD   /* Immediate notify entry. */
705         uint8_t entry_count;    /* Entry count. */
706         uint8_t reserved_1;
707         uint8_t entry_status;   /* Entry Status. */
708         uint32_t reserved_2;
709         uint8_t lun;
710         uint8_t initiator_id;
711         uint8_t reserved_3;
712         uint8_t target_id;
713         uint32_t option_flags;
714         uint8_t status;
715         uint8_t reserved_4;
716         uint8_t tag_value;      /* Received queue tag message value */
717         uint8_t tag_type;       /* Received queue tag message type */
718         /* entries allocated. */
719         uint16_t seq_id;
720         uint8_t scsi_msg[8];    /* SCSI message not handled by ISP */
721         uint16_t reserved_5[8];
722         uint8_t sense_data[18];
723 };
724
725 /*
726  * ISP queue - notify acknowledge entry structure definition.
727  */
728 struct nack_entry {
729         uint8_t entry_type;     /* Entry type. */
730 #define NOTIFY_ACK_TYPE 0xE     /* Notify acknowledge entry. */
731         uint8_t entry_count;    /* Entry count. */
732         uint8_t reserved_1;
733         uint8_t entry_status;   /* Entry Status. */
734         uint32_t reserved_2;
735         uint8_t lun;
736         uint8_t initiator_id;
737         uint8_t reserved_3;
738         uint8_t target_id;
739         uint32_t option_flags;
740         uint8_t status;
741         uint8_t event;
742         uint16_t seq_id;
743         uint16_t reserved_4[22];
744 };
745
746 /*
747  * ISP queue - Accept Target I/O (ATIO) entry structure definition.
748  */
749 struct atio_entry {
750         uint8_t entry_type;     /* Entry type. */
751 #define ACCEPT_TGT_IO_TYPE 6    /* Accept target I/O entry. */
752         uint8_t entry_count;    /* Entry count. */
753         uint8_t reserved_1;
754         uint8_t entry_status;   /* Entry Status. */
755         uint32_t reserved_2;
756         uint8_t lun;
757         uint8_t initiator_id;
758         uint8_t cdb_len;
759         uint8_t target_id;
760         uint32_t option_flags;
761         uint8_t status;
762         uint8_t scsi_status;
763         uint8_t tag_value;      /* Received queue tag message value */
764         uint8_t tag_type;       /* Received queue tag message type */
765         uint8_t cdb[26];
766         uint8_t sense_data[18];
767 };
768
769 /*
770  * ISP queue - Continue Target I/O (CTIO) entry structure definition.
771  */
772 struct ctio_entry {
773         uint8_t entry_type;     /* Entry type. */
774 #define CONTINUE_TGT_IO_TYPE 7  /* CTIO entry */
775         uint8_t entry_count;    /* Entry count. */
776         uint8_t reserved_1;
777         uint8_t entry_status;   /* Entry Status. */
778         uint32_t reserved_2;
779         uint8_t lun;            /* SCSI LUN */
780         uint8_t initiator_id;
781         uint8_t reserved_3;
782         uint8_t target_id;
783         uint32_t option_flags;
784         uint8_t status;
785         uint8_t scsi_status;
786         uint8_t tag_value;      /* Received queue tag message value */
787         uint8_t tag_type;       /* Received queue tag message type */
788         uint32_t transfer_length;
789         uint32_t residual;
790         uint16_t timeout;       /* 0 = 30 seconds, 0xFFFF = disable */
791         uint16_t dseg_count;    /* Data segment count. */
792         uint32_t dseg_0_address;        /* Data segment 0 address. */
793         uint32_t dseg_0_length; /* Data segment 0 length. */
794         uint32_t dseg_1_address;        /* Data segment 1 address. */
795         uint32_t dseg_1_length; /* Data segment 1 length. */
796         uint32_t dseg_2_address;        /* Data segment 2 address. */
797         uint32_t dseg_2_length; /* Data segment 2 length. */
798         uint32_t dseg_3_address;        /* Data segment 3 address. */
799         uint32_t dseg_3_length; /* Data segment 3 length. */
800 };
801
802 /*
803  * ISP queue - CTIO returned entry structure definition.
804  */
805 struct ctio_ret_entry {
806         uint8_t entry_type;     /* Entry type. */
807 #define CTIO_RET_TYPE   7       /* CTIO return entry */
808         uint8_t entry_count;    /* Entry count. */
809         uint8_t reserved_1;
810         uint8_t entry_status;   /* Entry Status. */
811         uint32_t reserved_2;
812         uint8_t lun;            /* SCSI LUN */
813         uint8_t initiator_id;
814         uint8_t reserved_3;
815         uint8_t target_id;
816         uint32_t option_flags;
817         uint8_t status;
818         uint8_t scsi_status;
819         uint8_t tag_value;      /* Received queue tag message value */
820         uint8_t tag_type;       /* Received queue tag message type */
821         uint32_t transfer_length;
822         uint32_t residual;
823         uint16_t timeout;       /* 0 = 30 seconds, 0xFFFF = disable */
824         uint16_t dseg_count;    /* Data segment count. */
825         uint32_t dseg_0_address;        /* Data segment 0 address. */
826         uint32_t dseg_0_length; /* Data segment 0 length. */
827         uint32_t dseg_1_address;        /* Data segment 1 address. */
828         uint16_t dseg_1_length; /* Data segment 1 length. */
829         uint8_t sense_data[18];
830 };
831
832 /*
833  * ISP queue - CTIO A64 entry structure definition.
834  */
835 struct ctio_a64_entry {
836         uint8_t entry_type;     /* Entry type. */
837 #define CTIO_A64_TYPE 0xF       /* CTIO A64 entry */
838         uint8_t entry_count;    /* Entry count. */
839         uint8_t reserved_1;
840         uint8_t entry_status;   /* Entry Status. */
841         uint32_t reserved_2;
842         uint8_t lun;            /* SCSI LUN */
843         uint8_t initiator_id;
844         uint8_t reserved_3;
845         uint8_t target_id;
846         uint32_t option_flags;
847         uint8_t status;
848         uint8_t scsi_status;
849         uint8_t tag_value;      /* Received queue tag message value */
850         uint8_t tag_type;       /* Received queue tag message type */
851         uint32_t transfer_length;
852         uint32_t residual;
853         uint16_t timeout;       /* 0 = 30 seconds, 0xFFFF = disable */
854         uint16_t dseg_count;    /* Data segment count. */
855         uint32_t reserved_4[2];
856         uint32_t dseg_0_address[2];     /* Data segment 0 address. */
857         uint32_t dseg_0_length; /* Data segment 0 length. */
858         uint32_t dseg_1_address[2];     /* Data segment 1 address. */
859         uint32_t dseg_1_length; /* Data segment 1 length. */
860 };
861
862 /*
863  * ISP queue - CTIO returned entry structure definition.
864  */
865 struct ctio_a64_ret_entry {
866         uint8_t entry_type;     /* Entry type. */
867 #define CTIO_A64_RET_TYPE 0xF   /* CTIO A64 returned entry */
868         uint8_t entry_count;    /* Entry count. */
869         uint8_t reserved_1;
870         uint8_t entry_status;   /* Entry Status. */
871         uint32_t reserved_2;
872         uint8_t lun;            /* SCSI LUN */
873         uint8_t initiator_id;
874         uint8_t reserved_3;
875         uint8_t target_id;
876         uint32_t option_flags;
877         uint8_t status;
878         uint8_t scsi_status;
879         uint8_t tag_value;      /* Received queue tag message value */
880         uint8_t tag_type;       /* Received queue tag message type */
881         uint32_t transfer_length;
882         uint32_t residual;
883         uint16_t timeout;       /* 0 = 30 seconds, 0xFFFF = disable */
884         uint16_t dseg_count;    /* Data segment count. */
885         uint16_t reserved_4[7];
886         uint8_t sense_data[18];
887 };
888
889 /*
890  * ISP request and response queue entry sizes
891  */
892 #define RESPONSE_ENTRY_SIZE     (sizeof(struct response))
893 #define REQUEST_ENTRY_SIZE      (sizeof(request_t))
894
895 /*
896  * ISP status entry - completion status definitions.
897  */
898 #define CS_COMPLETE         0x0 /* No errors */
899 #define CS_INCOMPLETE       0x1 /* Incomplete transfer of cmd. */
900 #define CS_DMA              0x2 /* A DMA direction error. */
901 #define CS_TRANSPORT        0x3 /* Transport error. */
902 #define CS_RESET            0x4 /* SCSI bus reset occurred */
903 #define CS_ABORTED          0x5 /* System aborted command. */
904 #define CS_TIMEOUT          0x6 /* Timeout error. */
905 #define CS_DATA_OVERRUN     0x7 /* Data overrun. */
906 #define CS_COMMAND_OVERRUN  0x8 /* Command Overrun. */
907 #define CS_STATUS_OVERRUN   0x9 /* Status Overrun. */
908 #define CS_BAD_MSG          0xA /* Bad msg after status phase. */
909 #define CS_NO_MSG_OUT       0xB /* No msg out after selection. */
910 #define CS_EXTENDED_ID      0xC /* Extended ID failed. */
911 #define CS_IDE_MSG          0xD /* Target rejected IDE msg. */
912 #define CS_ABORT_MSG        0xE /* Target rejected abort msg. */
913 #define CS_REJECT_MSG       0xF /* Target rejected reject msg. */
914 #define CS_NOP_MSG          0x10        /* Target rejected NOP msg. */
915 #define CS_PARITY_MSG       0x11        /* Target rejected parity msg. */
916 #define CS_DEV_RESET_MSG    0x12        /* Target rejected dev rst msg. */
917 #define CS_ID_MSG           0x13        /* Target rejected ID msg. */
918 #define CS_FREE             0x14        /* Unexpected bus free. */
919 #define CS_DATA_UNDERRUN    0x15        /* Data Underrun. */
920 #define CS_TRANACTION_1     0x18        /* Transaction error 1 */
921 #define CS_TRANACTION_2     0x19        /* Transaction error 2 */
922 #define CS_TRANACTION_3     0x1a        /* Transaction error 3 */
923 #define CS_INV_ENTRY_TYPE   0x1b        /* Invalid entry type */
924 #define CS_DEV_QUEUE_FULL   0x1c        /* Device queue full */
925 #define CS_PHASED_SKIPPED   0x1d        /* SCSI phase skipped */
926 #define CS_ARS_FAILED       0x1e        /* ARS failed */
927 #define CS_LVD_BUS_ERROR    0x21        /* LVD bus error */
928 #define CS_BAD_PAYLOAD      0x80        /* Driver defined */
929 #define CS_UNKNOWN          0x81        /* Driver defined */
930 #define CS_RETRY            0x82        /* Driver defined */
931
932 /*
933  * ISP status entry - SCSI status byte bit definitions.
934  */
935 #define SS_CHECK_CONDITION  BIT_1
936 #define SS_CONDITION_MET    BIT_2
937 #define SS_BUSY_CONDITION   BIT_3
938 #define SS_RESERVE_CONFLICT (BIT_4 | BIT_3)
939
940 /*
941  * ISP target entries - Option flags bit definitions.
942  */
943 #define OF_ENABLE_TAG       BIT_1       /* Tagged queue action enable */
944 #define OF_DATA_IN          BIT_6       /* Data in to initiator */
945                                         /*  (data from target to initiator) */
946 #define OF_DATA_OUT         BIT_7       /* Data out from initiator */
947                                         /*  (data from initiator to target) */
948 #define OF_NO_DATA          (BIT_7 | BIT_6)
949 #define OF_DISC_DISABLED    BIT_15      /* Disconnects disabled */
950 #define OF_DISABLE_SDP      BIT_24      /* Disable sending save data ptr */
951 #define OF_SEND_RDP         BIT_26      /* Send restore data pointers msg */
952 #define OF_FORCE_DISC       BIT_30      /* Disconnects mandatory */
953 #define OF_SSTS             BIT_31      /* Send SCSI status */
954
955
956 /*
957  * BUS parameters/settings structure - UNUSED
958  */
959 struct bus_param {
960         uint8_t id;             /* Host adapter SCSI id */
961         uint8_t bus_reset_delay;        /* SCSI bus reset delay. */
962         uint8_t failed_reset_count;     /* number of time reset failed */
963         uint8_t unused;
964         uint16_t device_enables;        /* Device enable bits. */
965         uint16_t lun_disables;  /* LUN disable bits. */
966         uint16_t qtag_enables;  /* Tag queue enables. */
967         uint16_t hiwat;         /* High water mark per device. */
968         uint8_t reset_marker:1;
969         uint8_t disable_scsi_reset:1;
970         uint8_t scsi_bus_dead:1;        /* SCSI Bus is Dead, when 5 back to back resets failed */
971 };
972
973
974 struct qla_driver_setup {
975         uint32_t no_sync:1;
976         uint32_t no_wide:1;
977         uint32_t no_ppr:1;
978         uint32_t no_nvram:1;
979         uint16_t sync_mask;
980         uint16_t wide_mask;
981         uint16_t ppr_mask;
982 };
983
984
985 /*
986  * Linux Host Adapter structure
987  */
988 struct scsi_qla_host {
989         /* Linux adapter configuration data */
990         struct Scsi_Host *host; /* pointer to host data */
991         struct scsi_qla_host *next;
992         struct device_reg *iobase;      /* Base Memory-mapped I/O address */
993
994         unsigned char *mmpbase; /* memory mapped address */
995         unsigned long host_no;
996         struct pci_dev *pdev;
997         uint8_t devnum;
998         uint8_t revision;
999         uint8_t ports;
1000
1001         unsigned long actthreads;
1002         unsigned long isr_count;        /* Interrupt count */
1003         unsigned long spurious_int;
1004
1005         /* Outstandings ISP commands. */
1006         struct srb *outstanding_cmds[MAX_OUTSTANDING_COMMANDS];
1007
1008         /* BUS configuration data */
1009         struct bus_param bus_settings[MAX_BUSES];
1010
1011         /* Received ISP mailbox data. */
1012         volatile uint16_t mailbox_out[MAILBOX_REGISTER_COUNT];
1013
1014         dma_addr_t request_dma;         /* Physical Address */
1015         request_t *request_ring;        /* Base virtual address */
1016         request_t *request_ring_ptr;    /* Current address. */
1017         uint16_t req_ring_index;        /* Current index. */
1018         uint16_t req_q_cnt;             /* Number of available entries. */
1019
1020         dma_addr_t response_dma;        /* Physical address. */
1021         struct response *response_ring; /* Base virtual address */
1022         struct response *response_ring_ptr;     /* Current address. */
1023         uint16_t rsp_ring_index;        /* Current index. */
1024
1025         struct list_head done_q;        /* Done queue */
1026
1027         struct completion *mailbox_wait;
1028
1029         volatile struct {
1030                 uint32_t online:1;                      /* 0 */
1031                 uint32_t reset_marker:1;                /* 1 */
1032                 uint32_t disable_host_adapter:1;        /* 2 */
1033                 uint32_t reset_active:1;                /* 3 */
1034                 uint32_t abort_isp_active:1;            /* 4 */
1035                 uint32_t disable_risc_code_load:1;      /* 5 */
1036                 uint32_t enable_64bit_addressing:1;     /* 6 */
1037                 uint32_t in_reset:1;                    /* 7 */
1038                 uint32_t ints_enabled:1;
1039                 uint32_t ignore_nvram:1;
1040 #ifdef __ia64__
1041                 uint32_t use_pci_vchannel:1;
1042 #endif
1043         } flags;
1044
1045         struct nvram nvram;
1046         int nvram_valid;
1047 };
1048
1049 #endif /* _QLA1280_H */