This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / scsi / lpfc / lpfc.h
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for         *
3  * Enterprise Fibre Channel Host Bus Adapters.                     *
4  * Refer to the README file included with this package for         *
5  * driver version and adapter support.                             *
6  * Copyright (C) 2004 Emulex Corporation.                          *
7  * www.emulex.com                                                  *
8  *                                                                 *
9  * This program is free software; you can redistribute it and/or   *
10  * modify it under the terms of the GNU General Public License     *
11  * as published by the Free Software Foundation; either version 2  *
12  * of the License, or (at your option) any later version.          *
13  *                                                                 *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of  *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *
17  * GNU General Public License for more details, a copy of which    *
18  * can be found in the file COPYING included with this package.    *
19  *******************************************************************/
20
21 /*
22  * $Id: lpfc.h 1.134 2004/11/18 14:53:45EST sf_support Exp  $
23  */
24
25 #ifndef _H_LPFC
26 #define _H_LPFC
27
28 struct lpfc_sli2_slim;
29
30 #define LPFC_MAX_TARGET                 256     /* max nunber of targets
31                                                    supported */
32 #define LPFC_MAX_DISC_THREADS           64      /* max outstanding discovery els
33                                                    requests */
34 #define LPFC_MAX_NS_RETRY               3       /* Try to get to the NameServer
35                                                    3 times and then give up. */
36 #define LPFC_DFT_HBA_Q_DEPTH            2048    /* max cmds per hba */
37 #define LPFC_LC_HBA_Q_DEPTH             1024    /* max cmds per low cost hba */
38 #define LPFC_LP101_HBA_Q_DEPTH          128     /* max cmds per low cost hba */
39
40 /* Define the SLIM2 page size. */
41 #define LPFC_SLIM2_PAGE_AREA  8192
42
43 /* Define macros for 64 bit support */
44 #define putPaddrLow(addr)    ((uint32_t) (0xffffffff & (u64)(addr)))
45 #define putPaddrHigh(addr)   ((uint32_t) (0xffffffff & (((u64)(addr))>>32)))
46 #define getPaddr(high, low)  ((dma_addr_t)( \
47                              (( (u64)(high)<<16 ) << 16)|( (u64)(low))))
48 /* Provide maximum configuration definitions. */
49 #define LPFC_DRVR_TIMEOUT  16           /* driver iocb timeout value in sec */
50 #define MAX_FCP_TARGET     256          /* max num of FCP targets supported */
51 #define FC_MAX_ADPTMSG     64
52
53 #define MAX_HBAEVT 32
54
55 #if __LITTLE_ENDIAN
56
57 #define putLunLow(lunlow, lun)              \
58    {                                        \
59    lunlow = 0;                              \
60    }
61
62 #define putLunHigh(lunhigh, lun)            \
63    {                                        \
64    lunhigh = swab16(lun);                   \
65    }
66
67 #else                           /* BIG_ENDIAN_HOST */
68
69 #define putLunLow(lunlow, lun)              \
70    {                                        \
71    lunlow = 0;                              \
72    }
73
74 #define putLunHigh(lunhigh, lun)            \
75    {                                        \
76    lunhigh = (uint32_t)(lun << 16);         \
77    }
78 #endif
79
80 /****************************************************************************/
81 /*      Device VPD save area                                                */
82 /****************************************************************************/
83 typedef struct lpfc_vpd {
84         uint32_t status;        /* vpd status value */
85         uint32_t length;        /* number of bytes actually returned */
86         struct {
87                 uint32_t rsvd1; /* Revision numbers */
88                 uint32_t biuRev;
89                 uint32_t smRev;
90                 uint32_t smFwRev;
91                 uint32_t endecRev;
92                 uint16_t rBit;
93                 uint8_t fcphHigh;
94                 uint8_t fcphLow;
95                 uint8_t feaLevelHigh;
96                 uint8_t feaLevelLow;
97                 uint32_t postKernRev;
98                 uint32_t opFwRev;
99                 uint8_t opFwName[16];
100                 uint32_t sli1FwRev;
101                 uint8_t sli1FwName[16];
102                 uint32_t sli2FwRev;
103                 uint8_t sli2FwName[16];
104         } rev;
105 } lpfc_vpd_t;
106
107 struct lpfc_scsi_buf;
108
109 struct lpfc_hba_event {
110         uint32_t fc_eventcode;
111         uint32_t fc_evdata1;
112         uint32_t fc_evdata2;
113         uint32_t fc_evdata3;
114         uint32_t fc_evdata4;
115 };
116
117 /*
118  * lpfc stat counters
119  */
120 struct lpfc_stats {
121         /* Statistics for ELS commands */
122         uint32_t elsLogiCol;
123         uint32_t elsRetryExceeded;
124         uint32_t elsXmitRetry;
125         uint32_t elsDelayRetry;
126         uint32_t elsRcvDrop;
127         uint32_t elsRcvFrame;
128         uint32_t elsRcvRSCN;
129         uint32_t elsRcvRNID;
130         uint32_t elsRcvFARP;
131         uint32_t elsRcvFARPR;
132         uint32_t elsRcvFLOGI;
133         uint32_t elsRcvPLOGI;
134         uint32_t elsRcvADISC;
135         uint32_t elsRcvPDISC;
136         uint32_t elsRcvFAN;
137         uint32_t elsRcvLOGO;
138         uint32_t elsRcvPRLO;
139         uint32_t elsRcvPRLI;
140         uint32_t elsRcvRRQ;
141         uint32_t elsXmitFLOGI;
142         uint32_t elsXmitPLOGI;
143         uint32_t elsXmitPRLI;
144         uint32_t elsXmitADISC;
145         uint32_t elsXmitLOGO;
146         uint32_t elsXmitSCR;
147         uint32_t elsXmitRNID;
148         uint32_t elsXmitFARP;
149         uint32_t elsXmitFARPR;
150         uint32_t elsXmitACC;
151         uint32_t elsXmitLSRJT;
152
153         uint32_t frameRcvBcast;
154         uint32_t frameRcvMulti;
155         uint32_t strayXmitCmpl;
156         uint32_t frameXmitDelay;
157         uint32_t xriCmdCmpl;
158         uint32_t xriStatErr;
159         uint32_t LinkUp;
160         uint32_t LinkDown;
161         uint32_t LinkMultiEvent;
162         uint32_t NoRcvBuf;
163         uint32_t fcpCmd;
164         uint32_t fcpCmpl;
165         uint32_t fcpRspErr;
166         uint32_t fcpRemoteStop;
167         uint32_t fcpPortRjt;
168         uint32_t fcpPortBusy;
169         uint32_t fcpError;
170         uint32_t fcpLocalErr;
171 };
172
173 enum sysfs_mbox_state {
174         SMBOX_IDLE,
175         SMBOX_WRITING,
176         SMBOX_READING
177 };
178
179 struct lpfc_sysfs_mbox {
180         enum sysfs_mbox_state state;
181         size_t                offset;
182         struct lpfcMboxq *    mbox;
183 };
184
185 struct lpfc_hba {
186         uint32_t intr_inited;           /* flag for interrupt registration */
187         struct list_head hba_list;      /* List of hbas/ports */
188         struct lpfc_sli sli;
189         struct lpfc_sli2_slim *slim2p;
190         dma_addr_t slim2p_mapping;
191
192         uint32_t hba_state;
193
194 #define LPFC_INIT_START           1     /* Initial state after board reset */
195 #define LPFC_INIT_MBX_CMDS        2     /* Initialize HBA with mbox commands */
196 #define LPFC_LINK_DOWN            3     /* HBA initialized, link is down */
197 #define LPFC_LINK_UP              4     /* Link is up  - issue READ_LA */
198 #define LPFC_LOCAL_CFG_LINK       5     /* local NPORT Id configured */
199 #define LPFC_FLOGI                6     /* FLOGI sent to Fabric */
200 #define LPFC_FABRIC_CFG_LINK      7     /* Fabric assigned NPORT Id
201                                            configured */
202 #define LPFC_NS_REG               8     /* Register with NameServer */
203 #define LPFC_NS_QRY               9     /* Query NameServer for NPort ID list */
204 #define LPFC_BUILD_DISC_LIST      10    /* Build ADISC and PLOGI lists for
205                                          * device authentication / discovery */
206 #define LPFC_DISC_AUTH            11    /* Processing ADISC list */
207 #define LPFC_CLEAR_LA             12    /* authentication cmplt - issue
208                                            CLEAR_LA */
209 #define LPFC_HBA_READY            32
210 #define LPFC_HBA_ERROR            0xff
211
212         uint8_t fc_linkspeed;   /* Link speed after last READ_LA */
213
214         uint32_t fc_eventTag;   /* event tag for link attention */
215         uint32_t fc_prli_sent;  /* cntr for outstanding PRLIs */
216
217         uint32_t num_disc_nodes;        /*in addition to hba_state */
218
219         uint8_t fcp_mapping;    /* Map FCP devices based on WWNN WWPN or DID */
220 #define FCP_SEED_WWNN   0x1
221 #define FCP_SEED_WWPN   0x2
222 #define FCP_SEED_DID    0x4
223 #define FCP_SEED_MASK   0x7
224 #define FCP_SEED_AUTO   0x8     /* binding was created by auto mapping */
225
226         struct timer_list fc_estabtmo;  /* link establishment timer */
227         struct timer_list fc_disctmo;   /* Discovery rescue timer */
228         struct timer_list fc_fdmitmo;   /* fdmi timer */
229         struct timer_list fc_scantmo;   /* scsi scan host timer */
230
231
232         void *fc_evt_head;      /* waiting for event queue */
233         void *fc_evt_tail;      /* waiting for event queue */
234
235         uint16_t hba_event_put; /* hbaevent event put word anchor */
236         uint16_t hba_event_get; /* hbaevent event get word anchor */
237         uint32_t hba_event_missed;      /* hbaevent missed event word anchor */
238         uint32_t sid_cnt;       /* SCSI ID counter */
239
240         struct lpfc_hba_event hbaevt[MAX_HBAEVT];
241
242         /* These fields used to be binfo */
243         struct lpfc_name fc_nodename;   /* fc nodename */
244         struct lpfc_name fc_portname;   /* fc portname */
245         uint32_t fc_pref_DID;   /* preferred D_ID */
246         uint8_t fc_pref_ALPA;   /* preferred AL_PA */
247         uint32_t fc_edtov;      /* E_D_TOV timer value */
248         uint32_t fc_arbtov;     /* ARB_TOV timer value */
249         uint32_t fc_ratov;      /* R_A_TOV timer value */
250         uint32_t fc_rttov;      /* R_T_TOV timer value */
251         uint32_t fc_altov;      /* AL_TOV timer value */
252         uint32_t fc_crtov;      /* C_R_TOV timer value */
253         uint32_t fc_citov;      /* C_I_TOV timer value */
254         uint32_t fc_myDID;      /* fibre channel S_ID */
255         uint32_t fc_prevDID;    /* previous fibre channel S_ID */
256
257         struct serv_parm fc_sparam;     /* buffer for our service parameters */
258         struct serv_parm fc_fabparam;   /* fabric service parameters buffer */
259         uint8_t alpa_map[128];  /* AL_PA map from READ_LA */
260
261         uint8_t fc_ns_retry;    /* retries for fabric nameserver */
262         uint32_t fc_nlp_cnt;    /* outstanding NODELIST requests */
263         uint32_t fc_rscn_id_cnt;        /* count of RSCNs payloads in list */
264         struct lpfc_dmabuf *fc_rscn_id_list[FC_MAX_HOLD_RSCN];
265         uint32_t lmt;
266         uint32_t fc_flag;       /* FC flags */
267 #define FC_PT2PT                0x1     /* pt2pt with no fabric */
268 #define FC_PT2PT_PLOGI          0x2     /* pt2pt initiate PLOGI */
269 #define FC_DISC_TMO             0x4     /* Discovery timer running */
270 #define FC_PUBLIC_LOOP          0x8     /* Public loop */
271 #define FC_LBIT                 0x10    /* LOGIN bit in loopinit set */
272 #define FC_RSCN_MODE            0x20    /* RSCN cmd rcv'ed */
273 #define FC_NLP_MORE             0x40    /* More node to process in node tbl */
274 #define FC_OFFLINE_MODE         0x80    /* Interface is offline for diag */
275 #define FC_FABRIC               0x100   /* We are fabric attached */
276 #define FC_ESTABLISH_LINK       0x200   /* Reestablish Link */
277 #define FC_RSCN_DISCOVERY       0x400   /* Authenticate all devices after RSCN*/
278 #define FC_LOADING              0x1000  /* HBA in process of loading drvr */
279 #define FC_UNLOADING            0x2000  /* HBA in process of unloading drvr */
280 #define FC_SCSI_SCAN_TMO        0x4000  /* scsi scan timer running */
281 #define FC_ABORT_DISCOVERY      0x8000  /* we want to abort discovery */
282
283         uint32_t fc_topology;   /* link topology, from LINK INIT */
284
285         struct lpfc_stats fc_stat;
286
287         /* These are the head/tail pointers for the bind, plogi, adisc, unmap,
288          *  and map lists.  Their counters are immediately following.
289          */
290         struct list_head fc_nlpbind_list;
291         struct list_head fc_plogi_list;
292         struct list_head fc_adisc_list;
293         struct list_head fc_reglogin_list;
294         struct list_head fc_prli_list;
295         struct list_head fc_nlpunmap_list;
296         struct list_head fc_nlpmap_list;
297         struct list_head fc_npr_list;
298         struct list_head fc_unused_list;
299
300         /* Keep counters for the number of entries in each list. */
301         uint16_t fc_bind_cnt;
302         uint16_t fc_plogi_cnt;
303         uint16_t fc_adisc_cnt;
304         uint16_t fc_reglogin_cnt;
305         uint16_t fc_prli_cnt;
306         uint16_t fc_unmap_cnt;
307         uint16_t fc_map_cnt;
308         uint16_t fc_npr_cnt;
309         uint16_t fc_unused_cnt;
310         struct lpfc_nodelist fc_fcpnodev; /* nodelist entry for no device */
311         uint32_t nport_event_cnt;       /* timestamp for nlplist entry */
312
313         struct lpfc_target *device_queue_hash[MAX_FCP_TARGET];
314 #define LPFC_RPI_HASH_SIZE     64
315 #define LPFC_RPI_HASH_FUNC(x)  ((x) & (0x3f))
316         /* ptr to active D_ID / RPIs */
317         struct lpfc_nodelist *fc_nlplookup[LPFC_RPI_HASH_SIZE];
318         uint32_t wwnn[2];
319         uint32_t RandomData[7];
320
321         uint32_t cfg_log_verbose;
322         uint32_t cfg_lun_queue_depth;
323         uint32_t cfg_nodev_tmo;
324         uint32_t cfg_hba_queue_depth;
325         uint32_t cfg_automap;
326         uint32_t cfg_fcp_class;
327         uint32_t cfg_use_adisc;
328         uint32_t cfg_ack0;
329         uint32_t cfg_topology;
330         uint32_t cfg_scan_down;
331         uint32_t cfg_link_speed;
332         uint32_t cfg_cr_delay;
333         uint32_t cfg_cr_count;
334         uint32_t cfg_fdmi_on;
335         uint32_t cfg_fcp_bind_method;
336         uint32_t cfg_discovery_threads;
337         uint32_t cfg_max_luns;
338         uint32_t cfg_scsi_hotplug;
339
340         lpfc_vpd_t vpd;         /* vital product data */
341
342 #if defined(FC_TRANS_265_BLKPATCH)
343         /*
344          * Provide a per-HBA timer for 2.6.5 kernels patched with the
345          * block/unblock FC transport patch.
346          */
347         struct timer_list dev_loss_timer;
348 #endif
349
350         struct Scsi_Host *host;
351         struct pci_dev *pcidev;
352         struct list_head      dpc_disc;
353
354         pid_t                 dpc_pid;
355         int                   dpc_kill;
356         struct completion     dpc_startup;
357         struct completion     dpc_exiting;
358         struct semaphore     *dpc_wait;
359
360         unsigned long pci_bar0_map;     /* Physical address for PCI BAR0 */
361         unsigned long pci_bar2_map;     /* Physical address for PCI BAR2 */
362         void *slim_memmap_p;            /* Kernel memory mapped address for PCI
363                                            BAR0 */
364         void *ctrl_regs_memmap_p;       /* Kernel memory mapped address for PCI
365                                            BAR2 */
366
367         void *MBslimaddr;       /* virtual address for mbox cmds */
368         void *HAregaddr;        /* virtual address for host attn reg */
369         void *CAregaddr;        /* virtual address for chip attn reg */
370         void *HSregaddr;        /* virtual address for host status reg */
371         void *HCregaddr;        /* virtual address for host ctl reg */
372         wait_queue_head_t linkevtwq;
373         wait_queue_head_t rscnevtwq;
374         wait_queue_head_t ctevtwq;
375
376         uint8_t brd_no;         /* FC board number */
377
378         char SerialNumber[32];  /* adapter Serial Number */
379         char OptionROMVersion[32];      /* adapter BIOS / Fcode version */
380
381         struct timer_list els_tmofunc;
382
383         void *link_stats;
384
385         /*
386          * stat  counters
387          */
388         uint64_t fc4InputRequests;
389         uint64_t fc4OutputRequests;
390         uint64_t fc4ControlRequests;
391
392         struct lpfc_sysfs_mbox sysfs_mbox;
393 ;
394         /* pci_mem_pools */
395         struct pci_pool *lpfc_scsi_dma_ext_pool;
396         struct pci_pool *lpfc_mbuf_pool;
397         struct lpfc_dma_pool lpfc_mbuf_safety_pool;
398         mempool_t *scsibuf_mem_pool;
399
400         mempool_t *iocb_mem_pool;
401         mempool_t *mbox_mem_pool;
402         mempool_t *nlp_mem_pool;
403         mempool_t *bind_mem_pool;
404         struct list_head freebufList;
405         struct list_head ctrspbuflist;
406         struct list_head rnidrspbuflist;
407 };
408
409 /* event mask definitions */
410 #define FC_REG_LINK_EVENT       0x1     /* Register for link up / down events */
411 #define FC_REG_RSCN_EVENT       0x2     /* Register for RSCN events */
412 #define FC_REG_CT_EVENT         0x4     /* Register for CT request events */
413
414 #define FC_FSTYPE_ALL 0xffff    /* match on all fsTypes */
415
416 typedef struct fcEVT {          /* Kernel level Event structure */
417         uint32_t evt_handle;
418         uint32_t evt_mask;
419         uint32_t evt_data0;
420         uint16_t evt_sleep;
421         uint16_t evt_flags;
422         void    *evt_type;
423         void    *evt_next;
424         void    *evt_data1;
425         uint32_t evt_data2;
426 } fcEVT_t;
427
428 typedef struct fcEVTHDR {       /* Kernel level Event Header */
429         uint32_t e_handle;
430         uint32_t e_mask;
431         uint16_t e_mode;
432 #define E_SLEEPING_MODE     0x0001
433         uint16_t e_refcnt;
434         uint16_t e_flag;
435 #define E_GET_EVENT_ACTIVE  0x0001
436         fcEVT_t *e_head;
437         fcEVT_t *e_tail;
438         void    *e_next_header;
439         void    *e_type;
440 } fcEVTHDR_t;
441
442 struct rnidrsp {
443         void *buf;
444         uint32_t uniqueid;
445         struct list_head list;
446         uint32_t data;
447 };
448
449 #endif                          /* _H_LPFC */