]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - drivers/scsi/bfa/bfa_fcpim.h
Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
[linux-2.6.git] / drivers / scsi / bfa / bfa_fcpim.h
1 /*
2  * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3  * All rights reserved
4  * www.brocade.com
5  *
6  * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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 (GPL) Version 2 as
10  * published by the Free Software Foundation
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  */
17
18 #ifndef __BFA_FCPIM_H__
19 #define __BFA_FCPIM_H__
20
21 #include "bfa.h"
22 #include "bfa_svc.h"
23 #include "bfi_ms.h"
24 #include "bfa_defs_svc.h"
25 #include "bfa_cs.h"
26
27 /* FCP module related definitions */
28 #define BFA_IO_MAX      BFI_IO_MAX
29 #define BFA_FWTIO_MAX   2000
30
31 struct bfa_fcp_mod_s;
32 struct bfa_iotag_s {
33         struct list_head        qe;     /* queue element        */
34         u16     tag;                    /* FW IO tag            */
35 };
36
37 struct bfa_itn_s {
38         bfa_isr_func_t isr;
39 };
40
41 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
42                 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
43 void bfa_itn_isr(struct bfa_s *bfa, struct bfi_msg_s *m);
44 void bfa_iotag_attach(struct bfa_fcp_mod_s *fcp);
45 void bfa_fcp_res_recfg(struct bfa_s *bfa, u16 num_ioim_fw);
46
47 #define BFA_FCP_MOD(_hal)       (&(_hal)->modules.fcp_mod)
48 #define BFA_MEM_FCP_KVA(__bfa)  (&(BFA_FCP_MOD(__bfa)->kva_seg))
49 #define BFA_IOTAG_FROM_TAG(_fcp, _tag)  \
50         (&(_fcp)->iotag_arr[(_tag & BFA_IOIM_IOTAG_MASK)])
51 #define BFA_ITN_FROM_TAG(_fcp, _tag)    \
52         ((_fcp)->itn_arr + ((_tag) & ((_fcp)->num_itns - 1)))
53 #define BFA_SNSINFO_FROM_TAG(_fcp, _tag) \
54         bfa_mem_get_dmabuf_kva(_fcp, _tag, BFI_IOIM_SNSLEN)
55
56 #define BFA_ITNIM_MIN   32
57 #define BFA_ITNIM_MAX   1024
58
59 #define BFA_IOIM_MIN    8
60 #define BFA_IOIM_MAX    2000
61
62 #define BFA_TSKIM_MIN   4
63 #define BFA_TSKIM_MAX   512
64 #define BFA_FCPIM_PATHTOV_DEF   (30 * 1000)     /* in millisecs */
65 #define BFA_FCPIM_PATHTOV_MAX   (90 * 1000)     /* in millisecs */
66
67
68 #define bfa_itnim_ioprofile_update(__itnim, __index)                    \
69         (__itnim->ioprofile.iocomps[__index]++)
70
71 #define BFA_IOIM_RETRY_TAG_OFFSET 11
72 #define BFA_IOIM_IOTAG_MASK 0x07ff /* 2K IOs */
73 #define BFA_IOIM_RETRY_MAX 7
74
75 /* Buckets are are 512 bytes to 2MB */
76 static inline u32
77 bfa_ioim_get_index(u32 n) {
78         int pos = 0;
79         if (n >= (1UL)<<22)
80                 return BFA_IOBUCKET_MAX - 1;
81         n >>= 8;
82         if (n >= (1UL)<<16)
83                 n >>= 16; pos += 16;
84         if (n >= 1 << 8)
85                 n >>= 8; pos += 8;
86         if (n >= 1 << 4)
87                 n >>= 4; pos += 4;
88         if (n >= 1 << 2)
89                 n >>= 2; pos += 2;
90         if (n >= 1 << 1)
91                 pos += 1;
92
93         return (n == 0) ? (0) : pos;
94 }
95
96 /*
97  * forward declarations
98  */
99 struct bfa_ioim_s;
100 struct bfa_tskim_s;
101 struct bfad_ioim_s;
102 struct bfad_tskim_s;
103
104 typedef void    (*bfa_fcpim_profile_t) (struct bfa_ioim_s *ioim);
105
106 struct bfa_fcpim_s {
107         struct bfa_s            *bfa;
108         struct bfa_fcp_mod_s    *fcp;
109         struct bfa_itnim_s      *itnim_arr;
110         struct bfa_ioim_s       *ioim_arr;
111         struct bfa_ioim_sp_s    *ioim_sp_arr;
112         struct bfa_tskim_s      *tskim_arr;
113         int                     num_itnims;
114         int                     num_tskim_reqs;
115         u32                     path_tov;
116         u16                     q_depth;
117         u8                      reqq;           /*  Request queue to be used */
118         u8                      rsvd;
119         struct list_head        itnim_q;        /*  queue of active itnim */
120         struct list_head        ioim_resfree_q; /*  IOs waiting for f/w */
121         struct list_head        ioim_comp_q;    /*  IO global comp Q    */
122         struct list_head        tskim_free_q;
123         struct list_head        tskim_unused_q; /* Unused tskim Q */
124         u32                     ios_active;     /*  current active IOs  */
125         u32                     delay_comp;
126         struct bfa_fcpim_del_itn_stats_s del_itn_stats;
127         bfa_boolean_t           ioredirect;
128         bfa_boolean_t           io_profile;
129         u32                     io_profile_start_time;
130         bfa_fcpim_profile_t     profile_comp;
131         bfa_fcpim_profile_t     profile_start;
132 };
133
134 /* Max FCP dma segs required */
135 #define BFA_FCP_DMA_SEGS        BFI_IOIM_SNSBUF_SEGS
136
137 struct bfa_fcp_mod_s {
138         struct bfa_s            *bfa;
139         struct list_head        iotag_ioim_free_q;      /* free IO resources */
140         struct list_head        iotag_tio_free_q;       /* free IO resources */
141         struct list_head        iotag_unused_q; /* unused IO resources*/
142         struct bfa_iotag_s      *iotag_arr;
143         struct bfa_itn_s        *itn_arr;
144         int                     num_ioim_reqs;
145         int                     num_fwtio_reqs;
146         int                     num_itns;
147         struct bfa_dma_s        snsbase[BFA_FCP_DMA_SEGS];
148         struct bfa_fcpim_s      fcpim;
149         struct bfa_mem_dma_s    dma_seg[BFA_FCP_DMA_SEGS];
150         struct bfa_mem_kva_s    kva_seg;
151 };
152
153 /*
154  * BFA IO (initiator mode)
155  */
156 struct bfa_ioim_s {
157         struct list_head        qe;             /*  queue elememt       */
158         bfa_sm_t                sm;             /*  BFA ioim state machine */
159         struct bfa_s            *bfa;           /*  BFA module  */
160         struct bfa_fcpim_s      *fcpim;         /*  parent fcpim module */
161         struct bfa_itnim_s      *itnim;         /*  i-t-n nexus for this IO  */
162         struct bfad_ioim_s      *dio;           /*  driver IO handle    */
163         u16                     iotag;          /*  FWI IO tag  */
164         u16                     abort_tag;      /*  unqiue abort request tag */
165         u16                     nsges;          /*  number of SG elements */
166         u16                     nsgpgs;         /*  number of SG pages  */
167         struct bfa_sgpg_s       *sgpg;          /*  first SG page       */
168         struct list_head        sgpg_q;         /*  allocated SG pages  */
169         struct bfa_cb_qe_s      hcb_qe;         /*  bfa callback qelem  */
170         bfa_cb_cbfn_t           io_cbfn;        /*  IO completion handler */
171         struct bfa_ioim_sp_s    *iosp;          /*  slow-path IO handling */
172         u8                      reqq;           /*  Request queue for I/O */
173         u64                     start_time;     /*  IO's Profile start val */
174 };
175
176 struct bfa_ioim_sp_s {
177         struct bfi_msg_s        comp_rspmsg;    /*  IO comp f/w response */
178         struct bfa_sgpg_wqe_s   sgpg_wqe;       /*  waitq elem for sgpg */
179         struct bfa_reqq_wait_s  reqq_wait;      /*  to wait for room in reqq */
180         bfa_boolean_t           abort_explicit; /*  aborted by OS       */
181         struct bfa_tskim_s      *tskim;         /*  Relevant TM cmd     */
182 };
183
184 /*
185  * BFA Task management command (initiator mode)
186  */
187 struct bfa_tskim_s {
188         struct list_head        qe;
189         bfa_sm_t                sm;
190         struct bfa_s            *bfa;   /*  BFA module  */
191         struct bfa_fcpim_s      *fcpim; /*  parent fcpim module */
192         struct bfa_itnim_s      *itnim; /*  i-t-n nexus for this IO  */
193         struct bfad_tskim_s     *dtsk;  /*  driver task mgmt cmnd       */
194         bfa_boolean_t           notify; /*  notify itnim on TM comp  */
195         struct scsi_lun         lun;    /*  lun if applicable   */
196         enum fcp_tm_cmnd        tm_cmnd; /*  task management command  */
197         u16                     tsk_tag; /*  FWI IO tag */
198         u8                      tsecs;  /*  timeout in seconds  */
199         struct bfa_reqq_wait_s  reqq_wait;   /*  to wait for room in reqq */
200         struct list_head        io_q;   /*  queue of affected IOs       */
201         struct bfa_wc_s         wc;     /*  waiting counter     */
202         struct bfa_cb_qe_s      hcb_qe; /*  bfa callback qelem  */
203         enum bfi_tskim_status   tsk_status;  /*  TM status      */
204 };
205
206 /*
207  * BFA i-t-n (initiator mode)
208  */
209 struct bfa_itnim_s {
210         struct list_head        qe;     /*  queue element       */
211         bfa_sm_t                sm;     /*  i-t-n im BFA state machine  */
212         struct bfa_s            *bfa;   /*  bfa instance        */
213         struct bfa_rport_s      *rport; /*  bfa rport   */
214         void                    *ditn;  /*  driver i-t-n structure      */
215         struct bfi_mhdr_s       mhdr;   /*  pre-built mhdr      */
216         u8                      msg_no; /*  itnim/rport firmware handle */
217         u8                      reqq;   /*  CQ for requests     */
218         struct bfa_cb_qe_s      hcb_qe; /*  bfa callback qelem  */
219         struct list_head pending_q;     /*  queue of pending IO requests */
220         struct list_head io_q;          /*  queue of active IO requests */
221         struct list_head io_cleanup_q;  /*  IO being cleaned up */
222         struct list_head tsk_q;         /*  queue of active TM commands */
223         struct list_head  delay_comp_q; /*  queue of failed inflight cmds */
224         bfa_boolean_t   seq_rec;        /*  SQER supported      */
225         bfa_boolean_t   is_online;      /*  itnim is ONLINE for IO      */
226         bfa_boolean_t   iotov_active;   /*  IO TOV timer is active       */
227         struct bfa_wc_s wc;             /*  waiting counter     */
228         struct bfa_timer_s timer;       /*  pending IO TOV       */
229         struct bfa_reqq_wait_s reqq_wait; /*  to wait for room in reqq */
230         struct bfa_fcpim_s *fcpim;      /*  fcpim module        */
231         struct bfa_itnim_iostats_s      stats;
232         struct bfa_itnim_ioprofile_s  ioprofile;
233 };
234
235 #define bfa_itnim_is_online(_itnim) ((_itnim)->is_online)
236 #define BFA_FCPIM(_hal) (&(_hal)->modules.fcp_mod.fcpim)
237 #define BFA_IOIM_TAG_2_ID(_iotag)       ((_iotag) & BFA_IOIM_IOTAG_MASK)
238 #define BFA_IOIM_FROM_TAG(_fcpim, _iotag)       \
239         (&fcpim->ioim_arr[(_iotag & BFA_IOIM_IOTAG_MASK)])
240 #define BFA_TSKIM_FROM_TAG(_fcpim, _tmtag)      \
241         (&fcpim->tskim_arr[_tmtag & (fcpim->num_tskim_reqs - 1)])
242
243 #define bfa_io_profile_start_time(_bfa) \
244         ((_bfa)->modules.fcp_mod.fcpim.io_profile_start_time)
245 #define bfa_fcpim_get_io_profile(_bfa)  \
246         ((_bfa)->modules.fcp_mod.fcpim.io_profile)
247 #define bfa_ioim_update_iotag(__ioim) do {                              \
248         uint16_t k = (__ioim)->iotag >> BFA_IOIM_RETRY_TAG_OFFSET;      \
249         k++; (__ioim)->iotag &= BFA_IOIM_IOTAG_MASK;                    \
250         (__ioim)->iotag |= k << BFA_IOIM_RETRY_TAG_OFFSET;              \
251 } while (0)
252
253 static inline bfa_boolean_t
254 bfa_ioim_maxretry_reached(struct bfa_ioim_s *ioim)
255 {
256         uint16_t k = ioim->iotag >> BFA_IOIM_RETRY_TAG_OFFSET;
257         if (k < BFA_IOIM_RETRY_MAX)
258                 return BFA_FALSE;
259         return BFA_TRUE;
260 }
261
262 /*
263  * function prototypes
264  */
265 void    bfa_ioim_attach(struct bfa_fcpim_s *fcpim);
266 void    bfa_ioim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
267 void    bfa_ioim_good_comp_isr(struct bfa_s *bfa,
268                                         struct bfi_msg_s *msg);
269 void    bfa_ioim_cleanup(struct bfa_ioim_s *ioim);
270 void    bfa_ioim_cleanup_tm(struct bfa_ioim_s *ioim,
271                                         struct bfa_tskim_s *tskim);
272 void    bfa_ioim_iocdisable(struct bfa_ioim_s *ioim);
273 void    bfa_ioim_tov(struct bfa_ioim_s *ioim);
274
275 void    bfa_tskim_attach(struct bfa_fcpim_s *fcpim);
276 void    bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
277 void    bfa_tskim_iodone(struct bfa_tskim_s *tskim);
278 void    bfa_tskim_iocdisable(struct bfa_tskim_s *tskim);
279 void    bfa_tskim_cleanup(struct bfa_tskim_s *tskim);
280 void    bfa_tskim_res_recfg(struct bfa_s *bfa, u16 num_tskim_fw);
281
282 void    bfa_itnim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len);
283 void    bfa_itnim_attach(struct bfa_fcpim_s *fcpim);
284 void    bfa_itnim_iocdisable(struct bfa_itnim_s *itnim);
285 void    bfa_itnim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
286 void    bfa_itnim_iodone(struct bfa_itnim_s *itnim);
287 void    bfa_itnim_tskdone(struct bfa_itnim_s *itnim);
288 bfa_boolean_t   bfa_itnim_hold_io(struct bfa_itnim_s *itnim);
289
290 /*
291  * bfa fcpim module API functions
292  */
293 void    bfa_fcpim_path_tov_set(struct bfa_s *bfa, u16 path_tov);
294 u16     bfa_fcpim_path_tov_get(struct bfa_s *bfa);
295 u16     bfa_fcpim_qdepth_get(struct bfa_s *bfa);
296 bfa_status_t bfa_fcpim_port_iostats(struct bfa_s *bfa,
297                         struct bfa_itnim_iostats_s *stats, u8 lp_tag);
298 void bfa_fcpim_add_stats(struct bfa_itnim_iostats_s *fcpim_stats,
299                         struct bfa_itnim_iostats_s *itnim_stats);
300
301 #define bfa_fcpim_ioredirect_enabled(__bfa)                             \
302         (((struct bfa_fcpim_s *)(BFA_FCPIM(__bfa)))->ioredirect)
303
304 #define bfa_fcpim_get_next_reqq(__bfa, __qid)                           \
305 {                                                                       \
306         struct bfa_fcpim_s *__fcpim = BFA_FCPIM(__bfa);      \
307         __fcpim->reqq++;                                                \
308         __fcpim->reqq &= (BFI_IOC_MAX_CQS - 1);      \
309         *(__qid) = __fcpim->reqq;                                       \
310 }
311
312 #define bfa_iocfc_map_msg_to_qid(__msg, __qid)                          \
313         *(__qid) = (u8)((__msg) & (BFI_IOC_MAX_CQS - 1));
314 /*
315  * bfa itnim API functions
316  */
317 struct bfa_itnim_s *bfa_itnim_create(struct bfa_s *bfa,
318                 struct bfa_rport_s *rport, void *itnim);
319 void bfa_itnim_delete(struct bfa_itnim_s *itnim);
320 void bfa_itnim_online(struct bfa_itnim_s *itnim, bfa_boolean_t seq_rec);
321 void bfa_itnim_offline(struct bfa_itnim_s *itnim);
322 void bfa_itnim_clear_stats(struct bfa_itnim_s *itnim);
323 bfa_status_t bfa_itnim_get_ioprofile(struct bfa_itnim_s *itnim,
324                         struct bfa_itnim_ioprofile_s *ioprofile);
325
326 #define bfa_itnim_get_reqq(__ioim) (((struct bfa_ioim_s *)__ioim)->itnim->reqq)
327
328 /*
329  * BFA completion callback for bfa_itnim_online().
330  */
331 void    bfa_cb_itnim_online(void *itnim);
332
333 /*
334  * BFA completion callback for bfa_itnim_offline().
335  */
336 void    bfa_cb_itnim_offline(void *itnim);
337 void    bfa_cb_itnim_tov_begin(void *itnim);
338 void    bfa_cb_itnim_tov(void *itnim);
339
340 /*
341  * BFA notification to FCS/driver for second level error recovery.
342  * Atleast one I/O request has timedout and target is unresponsive to
343  * repeated abort requests. Second level error recovery should be initiated
344  * by starting implicit logout and recovery procedures.
345  */
346 void    bfa_cb_itnim_sler(void *itnim);
347
348 /*
349  * bfa ioim API functions
350  */
351 struct bfa_ioim_s       *bfa_ioim_alloc(struct bfa_s *bfa,
352                                         struct bfad_ioim_s *dio,
353                                         struct bfa_itnim_s *itnim,
354                                         u16 nsgles);
355
356 void            bfa_ioim_free(struct bfa_ioim_s *ioim);
357 void            bfa_ioim_start(struct bfa_ioim_s *ioim);
358 bfa_status_t    bfa_ioim_abort(struct bfa_ioim_s *ioim);
359 void            bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim,
360                                       bfa_boolean_t iotov);
361 /*
362  * I/O completion notification.
363  *
364  * @param[in]           dio                     driver IO structure
365  * @param[in]           io_status               IO completion status
366  * @param[in]           scsi_status             SCSI status returned by target
367  * @param[in]           sns_len                 SCSI sense length, 0 if none
368  * @param[in]           sns_info                SCSI sense data, if any
369  * @param[in]           residue                 Residual length
370  *
371  * @return None
372  */
373 void bfa_cb_ioim_done(void *bfad, struct bfad_ioim_s *dio,
374                         enum bfi_ioim_status io_status,
375                         u8 scsi_status, int sns_len,
376                         u8 *sns_info, s32 residue);
377
378 /*
379  * I/O good completion notification.
380  */
381 void bfa_cb_ioim_good_comp(void *bfad, struct bfad_ioim_s *dio);
382
383 /*
384  * I/O abort completion notification
385  */
386 void bfa_cb_ioim_abort(void *bfad, struct bfad_ioim_s *dio);
387
388 /*
389  * bfa tskim API functions
390  */
391 struct bfa_tskim_s *bfa_tskim_alloc(struct bfa_s *bfa,
392                         struct bfad_tskim_s *dtsk);
393 void bfa_tskim_free(struct bfa_tskim_s *tskim);
394 void bfa_tskim_start(struct bfa_tskim_s *tskim,
395                         struct bfa_itnim_s *itnim, struct scsi_lun lun,
396                         enum fcp_tm_cmnd tm, u8 t_secs);
397 void bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
398                         enum bfi_tskim_status tsk_status);
399
400 #endif /* __BFA_FCPIM_H__ */