This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / scsi / lpfc / lpfc_sli.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_sli.h 1.36 2004/11/23 16:56:58EST sf_support Exp  $
23  */
24
25 #ifndef _H_LPFC_SLI
26 #define _H_LPFC_SLI
27
28 #include "lpfc_hw.h"
29
30 /* forward declaration for LPFC_IOCB_t's use */
31 struct lpfc_hba;
32
33 /* This structure is used to handle IOCB requests / responses */
34 struct lpfc_iocbq {
35         /* lpfc_iocbqs are used in double linked lists */
36         struct list_head list;
37         IOCB_t iocb;            /* IOCB cmd */
38         uint8_t retry;          /* retry counter for IOCB cmd - if needed */
39         uint8_t iocb_flag;
40 #define LPFC_IO_POLL    1       /* Polling mode iocb */
41 #define LPFC_IO_LIBDFC  2       /* libdfc iocb */
42 #define LPFC_IO_WAIT    4
43 #define LPFC_IO_HIPRI   8       /* High Priority Queue signal flag */
44
45         uint8_t abort_count;
46         uint8_t rsvd2;
47         uint32_t drvrTimeout;   /* driver timeout in seconds */
48         void *context1;         /* caller context information */
49         void *context2;         /* caller context information */
50         void *context3;         /* caller context information */
51         union {
52                 wait_queue_head_t *hipri_wait_queue; /* High Priority Queue wait
53                                                         queue */
54                 struct lpfc_iocbq  *rsp_iocb;
55                 struct lpfcMboxq   *mbox;
56         } context_un;
57
58         void (*iocb_cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
59                            struct lpfc_iocbq *);
60
61 };
62
63 #define SLI_IOCB_RET_IOCB      1        /* Return IOCB if cmd ring full */
64 #define SLI_IOCB_HIGH_PRIORITY 2        /* High priority command */
65
66 #define IOCB_SUCCESS        0
67 #define IOCB_BUSY           1
68 #define IOCB_ERROR          2
69 #define IOCB_TIMEDOUT       3
70
71 typedef struct lpfcMboxq {
72         /* MBOXQs are used in single linked lists */
73         struct list_head list;  /* ptr to next mailbox command */
74         MAILBOX_t mb;           /* Mailbox cmd */
75         void *context1;         /* caller context information */
76         void *context2;         /* caller context information */
77
78         void (*mbox_cmpl) (struct lpfc_hba *, struct lpfcMboxq *);
79
80 } LPFC_MBOXQ_t;
81
82 #define MBX_POLL        1       /* poll mailbox till command done, then
83                                    return */
84 #define MBX_NOWAIT      2       /* issue command then return immediately */
85 #define MBX_STOP_IOCB   4       /* Stop iocb processing till mbox cmds
86                                    complete */
87
88 #define LPFC_MAX_RING_MASK  4   /* max num of rctl/type masks allowed per
89                                    ring */
90 #define LPFC_MAX_RING       4   /* max num of SLI rings used by driver */
91
92 /* Structure used to hold SLI ring information */
93 struct lpfc_sli_ring {
94         uint16_t flag;          /* ring flags */
95 #define LPFC_DEFERRED_RING_EVENT 0x001  /* Deferred processing a ring event */
96 #define LPFC_CALL_RING_AVAILABLE 0x002  /* indicates cmd was full */
97 #define LPFC_STOP_IOCB_MBX       0x010  /* Stop processing IOCB cmds mbox */
98 #define LPFC_STOP_IOCB_EVENT     0x020  /* Stop processing IOCB cmds event */
99 #define LPFC_STOP_IOCB_MASK      0x030  /* Stop processing IOCB cmds mask */
100         uint16_t abtsiotag;     /* tracks next iotag to use for ABTS */
101
102         uint32_t local_getidx;   /* last available cmd index (from cmdGetInx) */
103         uint32_t next_cmdidx;    /* next_cmd index */
104         uint8_t rsvd;
105         uint8_t ringno;         /* ring number */
106         uint8_t rspidx;         /* current index in response ring */
107         uint8_t cmdidx;         /* current index in command ring */
108         struct lpfc_iocbq ** fast_lookup; /* array of IOCB ptrs indexed by
109                                            iotag */
110         struct list_head txq;
111         uint16_t txq_cnt;       /* current length of queue */
112         uint16_t txq_max;       /* max length */
113         struct list_head txcmplq;
114         uint16_t txcmplq_cnt;   /* current length of queue */
115         uint16_t txcmplq_max;   /* max length */
116         volatile uint32_t *cmdringaddr; /* virtual address for cmd rings */
117         volatile uint32_t *rspringaddr; /* virtual address for rsp rings */
118         uint32_t missbufcnt;    /* keep track of buffers to post */
119         struct list_head postbufq;
120         uint16_t postbufq_cnt;  /* current length of queue */
121         uint16_t postbufq_max;  /* max length */
122         struct list_head iocb_continueq;
123         uint16_t iocb_continueq_cnt;    /* current length of queue */
124         uint16_t iocb_continueq_max;    /* max length */
125 };
126
127 typedef struct {
128         uint8_t profile;        /* profile associated with ring */
129         uint8_t rctl;   /* rctl / type pair configured for ring */
130         uint8_t type;   /* rctl / type pair configured for ring */
131         uint8_t rsvd;
132         /* rcv'd unsol event */
133         void (*lpfc_sli_rcv_unsol_event) (struct lpfc_hba *,
134                                          struct lpfc_sli_ring *,
135                                          struct lpfc_iocbq *);
136 } LPFC_RING_MASK_t;
137
138 /* Structure used for configuring rings to a specific profile or rctl / type */
139 typedef struct {
140         LPFC_RING_MASK_t prt[LPFC_MAX_RING_MASK];
141         uint32_t num_mask;      /* number of mask entries in prt array */
142         uint32_t iotag_ctr;     /* keeps track of the next iotag to use */
143         uint32_t iotag_max;     /* max iotag value to use               */
144         uint32_t fast_iotag;    /* max fastlookup based iotag           */
145         uint16_t numCiocb;      /* number of command iocb's per ring */
146         uint16_t numRiocb;      /* number of rsp iocb's per ring */
147         /* cmd ring available */
148         void (*lpfc_sli_cmd_available) (struct lpfc_hba *,
149                                         struct lpfc_sli_ring *);
150 } LPFC_RING_INIT_t;
151
152 typedef struct {
153         LPFC_RING_INIT_t ringinit[LPFC_MAX_RING]; /* ring initialization info */
154         uint32_t num_rings;
155         uint32_t sli_flag;
156 } LPFC_SLI_INIT_t;
157
158 /* Structure used to hold SLI statistical counters and info */
159 typedef struct {
160         uint64_t iocbEvent[LPFC_MAX_RING];      /* IOCB event counters */
161         uint64_t iocbCmd[LPFC_MAX_RING];        /* IOCB cmd issued */
162         uint64_t iocbRsp[LPFC_MAX_RING];        /* IOCB rsp received */
163         uint64_t iocbCmdDelay[LPFC_MAX_RING];   /* IOCB cmd ring delay */
164         uint64_t iocbCmdFull[LPFC_MAX_RING];    /* IOCB cmd ring full */
165         uint64_t iocbCmdEmpty[LPFC_MAX_RING];   /* IOCB cmd ring is now empty */
166         uint64_t iocbRspFull[LPFC_MAX_RING];    /* IOCB rsp ring full */
167         uint64_t mboxStatErr;   /* Mbox cmds completed status error */
168         uint64_t mboxCmd;       /* Mailbox commands issued */
169         uint64_t sliIntr;       /* Count of Host Attention interrupts */
170         uint32_t errAttnEvent;  /* Error Attn event counters */
171         uint32_t linkEvent;     /* Link event counters */
172         uint32_t mboxEvent;     /* Mailbox event counters */
173         uint32_t mboxBusy;      /* Mailbox cmd busy */
174 } LPFC_SLI_STAT_t;
175
176 /* Structure used to hold SLI information */
177 struct lpfc_sli {
178         LPFC_SLI_INIT_t sliinit;        /* initialization info */
179         /* Additional sli_flags */
180 #define LPFC_SLI_MBOX_ACTIVE      0x100 /* HBA mailbox is currently active */
181 #define LPFC_SLI2_ACTIVE          0x200 /* SLI2 overlay in firmware is active */
182 #define LPFC_PROCESS_LA           0x400 /* Able to process link attention */
183
184         struct lpfc_sli_ring ring[LPFC_MAX_RING];
185         int fcp_ring;           /* ring used for FCP initiator commands */
186         int next_ring;
187
188         int ip_ring;            /* ring used for IP network drv cmds */
189
190         LPFC_SLI_STAT_t slistat;        /* SLI statistical info */
191         struct list_head mboxq;
192         uint16_t mboxq_cnt;     /* current length of queue */
193         uint16_t mboxq_max;     /* max length */
194         LPFC_MBOXQ_t *mbox_active;      /* active mboxq information */
195
196         struct timer_list mbox_tmo;     /* Hold clk to timeout active mbox
197                                            cmd */
198
199         volatile uint32_t *MBhostaddr;  /* virtual address for mbox cmds */
200 };
201
202 /* Given a pointer to the start of the ring, and the slot number of
203  * the desired iocb entry, calc a pointer to that entry.
204  * (assume iocb entry size is 32 bytes, or 8 words)
205  */
206 #define IOCB_ENTRY(ring,slot) ((IOCB_t *)(((char *)(ring)) + ((slot) * 32)))
207
208 #define LPFC_SLI_ABORT_IMED     0       /* Immediate abort of IOCB, deque and
209                                            call compl routine immediately. */
210 #define LPFC_MBOX_TMO           30      /* Sec tmo for outstanding mbox
211                                            command */
212
213 /* Flags for aborting I/Os on tx and txcmpl queues */
214 #define LPFC_ABORT_TXQ          1       /* Abort I/Os on txq */
215 #define LPFC_ABORT_TXCMPLQ      2       /* Abort I/Os on txcmplq */
216 #define LPFC_ABORT_ALLQ         3       /* Abort I/Os both txq and txcmplq */
217
218 #endif                          /* _H_LPFC_SLI */