Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame^] | 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 | |
| 28 | #define BFA_ITNIM_MIN 32 |
| 29 | #define BFA_ITNIM_MAX 1024 |
| 30 | |
| 31 | #define BFA_IOIM_MIN 8 |
| 32 | #define BFA_IOIM_MAX 2000 |
| 33 | |
| 34 | #define BFA_TSKIM_MIN 4 |
| 35 | #define BFA_TSKIM_MAX 512 |
| 36 | #define BFA_FCPIM_PATHTOV_DEF (30 * 1000) /* in millisecs */ |
| 37 | #define BFA_FCPIM_PATHTOV_MAX (90 * 1000) /* in millisecs */ |
| 38 | |
| 39 | |
| 40 | #define bfa_itnim_ioprofile_update(__itnim, __index) \ |
| 41 | (__itnim->ioprofile.iocomps[__index]++) |
| 42 | |
| 43 | #define BFA_IOIM_RETRY_TAG_OFFSET 11 |
| 44 | #define BFA_IOIM_RETRY_TAG_MASK 0x07ff /* 2K IOs */ |
| 45 | #define BFA_IOIM_RETRY_MAX 7 |
| 46 | |
| 47 | /* Buckets are are 512 bytes to 2MB */ |
| 48 | static inline u32 |
| 49 | bfa_ioim_get_index(u32 n) { |
| 50 | int pos = 0; |
| 51 | if (n >= (1UL)<<22) |
| 52 | return BFA_IOBUCKET_MAX - 1; |
| 53 | n >>= 8; |
| 54 | if (n >= (1UL)<<16) |
| 55 | n >>= 16; pos += 16; |
| 56 | if (n >= 1 << 8) |
| 57 | n >>= 8; pos += 8; |
| 58 | if (n >= 1 << 4) |
| 59 | n >>= 4; pos += 4; |
| 60 | if (n >= 1 << 2) |
| 61 | n >>= 2; pos += 2; |
| 62 | if (n >= 1 << 1) |
| 63 | pos += 1; |
| 64 | |
| 65 | return (n == 0) ? (0) : pos; |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * forward declarations |
| 70 | */ |
| 71 | struct bfa_ioim_s; |
| 72 | struct bfa_tskim_s; |
| 73 | struct bfad_ioim_s; |
| 74 | struct bfad_tskim_s; |
| 75 | |
| 76 | typedef void (*bfa_fcpim_profile_t) (struct bfa_ioim_s *ioim); |
| 77 | |
| 78 | struct bfa_fcpim_mod_s { |
| 79 | struct bfa_s *bfa; |
| 80 | struct bfa_itnim_s *itnim_arr; |
| 81 | struct bfa_ioim_s *ioim_arr; |
| 82 | struct bfa_ioim_sp_s *ioim_sp_arr; |
| 83 | struct bfa_tskim_s *tskim_arr; |
| 84 | struct bfa_dma_s snsbase; |
| 85 | int num_itnims; |
| 86 | int num_ioim_reqs; |
| 87 | int num_tskim_reqs; |
| 88 | u32 path_tov; |
| 89 | u16 q_depth; |
| 90 | u8 reqq; /* Request queue to be used */ |
| 91 | u8 rsvd; |
| 92 | struct list_head itnim_q; /* queue of active itnim */ |
| 93 | struct list_head ioim_free_q; /* free IO resources */ |
| 94 | struct list_head ioim_resfree_q; /* IOs waiting for f/w */ |
| 95 | struct list_head ioim_comp_q; /* IO global comp Q */ |
| 96 | struct list_head tskim_free_q; |
| 97 | u32 ios_active; /* current active IOs */ |
| 98 | u32 delay_comp; |
| 99 | struct bfa_fcpim_del_itn_stats_s del_itn_stats; |
| 100 | bfa_boolean_t ioredirect; |
| 101 | bfa_boolean_t io_profile; |
| 102 | u32 io_profile_start_time; |
| 103 | bfa_fcpim_profile_t profile_comp; |
| 104 | bfa_fcpim_profile_t profile_start; |
| 105 | }; |
| 106 | |
| 107 | /** |
| 108 | * BFA IO (initiator mode) |
| 109 | */ |
| 110 | struct bfa_ioim_s { |
| 111 | struct list_head qe; /* queue elememt */ |
| 112 | bfa_sm_t sm; /* BFA ioim state machine */ |
| 113 | struct bfa_s *bfa; /* BFA module */ |
| 114 | struct bfa_fcpim_mod_s *fcpim; /* parent fcpim module */ |
| 115 | struct bfa_itnim_s *itnim; /* i-t-n nexus for this IO */ |
| 116 | struct bfad_ioim_s *dio; /* driver IO handle */ |
| 117 | u16 iotag; /* FWI IO tag */ |
| 118 | u16 abort_tag; /* unqiue abort request tag */ |
| 119 | u16 nsges; /* number of SG elements */ |
| 120 | u16 nsgpgs; /* number of SG pages */ |
| 121 | struct bfa_sgpg_s *sgpg; /* first SG page */ |
| 122 | struct list_head sgpg_q; /* allocated SG pages */ |
| 123 | struct bfa_cb_qe_s hcb_qe; /* bfa callback qelem */ |
| 124 | bfa_cb_cbfn_t io_cbfn; /* IO completion handler */ |
| 125 | struct bfa_ioim_sp_s *iosp; /* slow-path IO handling */ |
| 126 | u8 reqq; /* Request queue for I/O */ |
| 127 | u64 start_time; /* IO's Profile start val */ |
| 128 | }; |
| 129 | |
| 130 | |
| 131 | struct bfa_ioim_sp_s { |
| 132 | struct bfi_msg_s comp_rspmsg; /* IO comp f/w response */ |
| 133 | u8 *snsinfo; /* sense info for this IO */ |
| 134 | struct bfa_sgpg_wqe_s sgpg_wqe; /* waitq elem for sgpg */ |
| 135 | struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */ |
| 136 | bfa_boolean_t abort_explicit; /* aborted by OS */ |
| 137 | struct bfa_tskim_s *tskim; /* Relevant TM cmd */ |
| 138 | }; |
| 139 | |
| 140 | /** |
| 141 | * BFA Task management command (initiator mode) |
| 142 | */ |
| 143 | struct bfa_tskim_s { |
| 144 | struct list_head qe; |
| 145 | bfa_sm_t sm; |
| 146 | struct bfa_s *bfa; /* BFA module */ |
| 147 | struct bfa_fcpim_mod_s *fcpim; /* parent fcpim module */ |
| 148 | struct bfa_itnim_s *itnim; /* i-t-n nexus for this IO */ |
| 149 | struct bfad_tskim_s *dtsk; /* driver task mgmt cmnd */ |
| 150 | bfa_boolean_t notify; /* notify itnim on TM comp */ |
| 151 | lun_t lun; /* lun if applicable */ |
| 152 | enum fcp_tm_cmnd tm_cmnd; /* task management command */ |
| 153 | u16 tsk_tag; /* FWI IO tag */ |
| 154 | u8 tsecs; /* timeout in seconds */ |
| 155 | struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */ |
| 156 | struct list_head io_q; /* queue of affected IOs */ |
| 157 | struct bfa_wc_s wc; /* waiting counter */ |
| 158 | struct bfa_cb_qe_s hcb_qe; /* bfa callback qelem */ |
| 159 | enum bfi_tskim_status tsk_status; /* TM status */ |
| 160 | }; |
| 161 | |
| 162 | |
| 163 | /** |
| 164 | * BFA i-t-n (initiator mode) |
| 165 | */ |
| 166 | struct bfa_itnim_s { |
| 167 | struct list_head qe; /* queue element */ |
| 168 | bfa_sm_t sm; /* i-t-n im BFA state machine */ |
| 169 | struct bfa_s *bfa; /* bfa instance */ |
| 170 | struct bfa_rport_s *rport; /* bfa rport */ |
| 171 | void *ditn; /* driver i-t-n structure */ |
| 172 | struct bfi_mhdr_s mhdr; /* pre-built mhdr */ |
| 173 | u8 msg_no; /* itnim/rport firmware handle */ |
| 174 | u8 reqq; /* CQ for requests */ |
| 175 | struct bfa_cb_qe_s hcb_qe; /* bfa callback qelem */ |
| 176 | struct list_head pending_q; /* queue of pending IO requests */ |
| 177 | struct list_head io_q; /* queue of active IO requests */ |
| 178 | struct list_head io_cleanup_q; /* IO being cleaned up */ |
| 179 | struct list_head tsk_q; /* queue of active TM commands */ |
| 180 | struct list_head delay_comp_q; /* queue of failed inflight cmds */ |
| 181 | bfa_boolean_t seq_rec; /* SQER supported */ |
| 182 | bfa_boolean_t is_online; /* itnim is ONLINE for IO */ |
| 183 | bfa_boolean_t iotov_active; /* IO TOV timer is active */ |
| 184 | struct bfa_wc_s wc; /* waiting counter */ |
| 185 | struct bfa_timer_s timer; /* pending IO TOV */ |
| 186 | struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */ |
| 187 | struct bfa_fcpim_mod_s *fcpim; /* fcpim module */ |
| 188 | struct bfa_itnim_iostats_s stats; |
| 189 | struct bfa_itnim_ioprofile_s ioprofile; |
| 190 | }; |
| 191 | |
| 192 | |
| 193 | #define bfa_itnim_is_online(_itnim) ((_itnim)->is_online) |
| 194 | #define BFA_FCPIM_MOD(_hal) (&(_hal)->modules.fcpim_mod) |
| 195 | #define BFA_IOIM_FROM_TAG(_fcpim, _iotag) \ |
| 196 | (&fcpim->ioim_arr[(_iotag & BFA_IOIM_RETRY_TAG_MASK)]) |
| 197 | #define BFA_TSKIM_FROM_TAG(_fcpim, _tmtag) \ |
| 198 | (&fcpim->tskim_arr[_tmtag & (fcpim->num_tskim_reqs - 1)]) |
| 199 | |
| 200 | #define bfa_io_profile_start_time(_bfa) \ |
| 201 | (_bfa->modules.fcpim_mod.io_profile_start_time) |
| 202 | #define bfa_fcpim_get_io_profile(_bfa) \ |
| 203 | (_bfa->modules.fcpim_mod.io_profile) |
| 204 | |
| 205 | static inline bfa_boolean_t |
| 206 | bfa_ioim_get_iotag(struct bfa_ioim_s *ioim) |
| 207 | { |
| 208 | u16 k = ioim->iotag; |
| 209 | |
| 210 | k >>= BFA_IOIM_RETRY_TAG_OFFSET; k++; |
| 211 | |
| 212 | if (k > BFA_IOIM_RETRY_MAX) |
| 213 | return BFA_FALSE; |
| 214 | ioim->iotag &= BFA_IOIM_RETRY_TAG_MASK; |
| 215 | ioim->iotag |= k<<BFA_IOIM_RETRY_TAG_OFFSET; |
| 216 | return BFA_TRUE; |
| 217 | } |
| 218 | /* |
| 219 | * function prototypes |
| 220 | */ |
| 221 | void bfa_ioim_attach(struct bfa_fcpim_mod_s *fcpim, |
| 222 | struct bfa_meminfo_s *minfo); |
| 223 | void bfa_ioim_detach(struct bfa_fcpim_mod_s *fcpim); |
| 224 | void bfa_ioim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg); |
| 225 | void bfa_ioim_good_comp_isr(struct bfa_s *bfa, |
| 226 | struct bfi_msg_s *msg); |
| 227 | void bfa_ioim_cleanup(struct bfa_ioim_s *ioim); |
| 228 | void bfa_ioim_cleanup_tm(struct bfa_ioim_s *ioim, |
| 229 | struct bfa_tskim_s *tskim); |
| 230 | void bfa_ioim_iocdisable(struct bfa_ioim_s *ioim); |
| 231 | void bfa_ioim_tov(struct bfa_ioim_s *ioim); |
| 232 | |
| 233 | void bfa_tskim_attach(struct bfa_fcpim_mod_s *fcpim, |
| 234 | struct bfa_meminfo_s *minfo); |
| 235 | void bfa_tskim_detach(struct bfa_fcpim_mod_s *fcpim); |
| 236 | void bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg); |
| 237 | void bfa_tskim_iodone(struct bfa_tskim_s *tskim); |
| 238 | void bfa_tskim_iocdisable(struct bfa_tskim_s *tskim); |
| 239 | void bfa_tskim_cleanup(struct bfa_tskim_s *tskim); |
| 240 | |
| 241 | void bfa_itnim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len, |
| 242 | u32 *dm_len); |
| 243 | void bfa_itnim_attach(struct bfa_fcpim_mod_s *fcpim, |
| 244 | struct bfa_meminfo_s *minfo); |
| 245 | void bfa_itnim_detach(struct bfa_fcpim_mod_s *fcpim); |
| 246 | void bfa_itnim_iocdisable(struct bfa_itnim_s *itnim); |
| 247 | void bfa_itnim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg); |
| 248 | void bfa_itnim_iodone(struct bfa_itnim_s *itnim); |
| 249 | void bfa_itnim_tskdone(struct bfa_itnim_s *itnim); |
| 250 | bfa_boolean_t bfa_itnim_hold_io(struct bfa_itnim_s *itnim); |
| 251 | void bfa_ioim_profile_comp(struct bfa_ioim_s *ioim); |
| 252 | void bfa_ioim_profile_start(struct bfa_ioim_s *ioim); |
| 253 | |
| 254 | |
| 255 | /* |
| 256 | * bfa fcpim module API functions |
| 257 | */ |
| 258 | void bfa_fcpim_path_tov_set(struct bfa_s *bfa, u16 path_tov); |
| 259 | u16 bfa_fcpim_path_tov_get(struct bfa_s *bfa); |
| 260 | void bfa_fcpim_qdepth_set(struct bfa_s *bfa, u16 q_depth); |
| 261 | u16 bfa_fcpim_qdepth_get(struct bfa_s *bfa); |
| 262 | bfa_status_t bfa_fcpim_get_modstats(struct bfa_s *bfa, |
| 263 | struct bfa_itnim_iostats_s *modstats); |
| 264 | bfa_status_t bfa_fcpim_port_iostats(struct bfa_s *bfa, |
| 265 | struct bfa_itnim_iostats_s *stats, u8 lp_tag); |
| 266 | bfa_status_t bfa_fcpim_get_del_itn_stats(struct bfa_s *bfa, |
| 267 | struct bfa_fcpim_del_itn_stats_s *modstats); |
| 268 | bfa_status_t bfa_fcpim_port_clear_iostats(struct bfa_s *bfa, u8 lp_tag); |
| 269 | void bfa_fcpim_add_stats(struct bfa_itnim_iostats_s *fcpim_stats, |
| 270 | struct bfa_itnim_iostats_s *itnim_stats); |
| 271 | bfa_status_t bfa_fcpim_clr_modstats(struct bfa_s *bfa); |
| 272 | void bfa_fcpim_set_ioredirect(struct bfa_s *bfa, |
| 273 | bfa_boolean_t state); |
| 274 | void bfa_fcpim_update_ioredirect(struct bfa_s *bfa); |
| 275 | bfa_status_t bfa_fcpim_profile_on(struct bfa_s *bfa, u32 time); |
| 276 | bfa_status_t bfa_fcpim_profile_off(struct bfa_s *bfa); |
| 277 | #define bfa_fcpim_ioredirect_enabled(__bfa) \ |
| 278 | (((struct bfa_fcpim_mod_s *)(BFA_FCPIM_MOD(__bfa)))->ioredirect) |
| 279 | |
| 280 | #define bfa_fcpim_get_next_reqq(__bfa, __qid) \ |
| 281 | { \ |
| 282 | struct bfa_fcpim_mod_s *__fcpim = BFA_FCPIM_MOD(__bfa); \ |
| 283 | __fcpim->reqq++; \ |
| 284 | __fcpim->reqq &= (BFI_IOC_MAX_CQS - 1); \ |
| 285 | *(__qid) = __fcpim->reqq; \ |
| 286 | } |
| 287 | |
| 288 | #define bfa_iocfc_map_msg_to_qid(__msg, __qid) \ |
| 289 | *(__qid) = (u8)((__msg) & (BFI_IOC_MAX_CQS - 1)); |
| 290 | /* |
| 291 | * bfa itnim API functions |
| 292 | */ |
| 293 | struct bfa_itnim_s *bfa_itnim_create(struct bfa_s *bfa, |
| 294 | struct bfa_rport_s *rport, void *itnim); |
| 295 | void bfa_itnim_delete(struct bfa_itnim_s *itnim); |
| 296 | void bfa_itnim_online(struct bfa_itnim_s *itnim, |
| 297 | bfa_boolean_t seq_rec); |
| 298 | void bfa_itnim_offline(struct bfa_itnim_s *itnim); |
| 299 | void bfa_itnim_get_stats(struct bfa_itnim_s *itnim, |
| 300 | struct bfa_itnim_iostats_s *stats); |
| 301 | void bfa_itnim_clear_stats(struct bfa_itnim_s *itnim); |
| 302 | bfa_status_t bfa_itnim_get_ioprofile(struct bfa_itnim_s *itnim, |
| 303 | struct bfa_itnim_ioprofile_s *ioprofile); |
| 304 | #define bfa_itnim_get_reqq(__ioim) (((struct bfa_ioim_s *)__ioim)->itnim->reqq) |
| 305 | |
| 306 | /** |
| 307 | * BFA completion callback for bfa_itnim_online(). |
| 308 | * |
| 309 | * @param[in] itnim FCS or driver itnim instance |
| 310 | * |
| 311 | * return None |
| 312 | */ |
| 313 | void bfa_cb_itnim_online(void *itnim); |
| 314 | |
| 315 | /** |
| 316 | * BFA completion callback for bfa_itnim_offline(). |
| 317 | * |
| 318 | * @param[in] itnim FCS or driver itnim instance |
| 319 | * |
| 320 | * return None |
| 321 | */ |
| 322 | void bfa_cb_itnim_offline(void *itnim); |
| 323 | void bfa_cb_itnim_tov_begin(void *itnim); |
| 324 | void bfa_cb_itnim_tov(void *itnim); |
| 325 | |
| 326 | /** |
| 327 | * BFA notification to FCS/driver for second level error recovery. |
| 328 | * |
| 329 | * Atleast one I/O request has timedout and target is unresponsive to |
| 330 | * repeated abort requests. Second level error recovery should be initiated |
| 331 | * by starting implicit logout and recovery procedures. |
| 332 | * |
| 333 | * @param[in] itnim FCS or driver itnim instance |
| 334 | * |
| 335 | * return None |
| 336 | */ |
| 337 | void bfa_cb_itnim_sler(void *itnim); |
| 338 | |
| 339 | /* |
| 340 | * bfa ioim API functions |
| 341 | */ |
| 342 | struct bfa_ioim_s *bfa_ioim_alloc(struct bfa_s *bfa, |
| 343 | struct bfad_ioim_s *dio, |
| 344 | struct bfa_itnim_s *itnim, |
| 345 | u16 nsgles); |
| 346 | |
| 347 | void bfa_ioim_free(struct bfa_ioim_s *ioim); |
| 348 | void bfa_ioim_start(struct bfa_ioim_s *ioim); |
| 349 | bfa_status_t bfa_ioim_abort(struct bfa_ioim_s *ioim); |
| 350 | void bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim, |
| 351 | bfa_boolean_t iotov); |
| 352 | |
| 353 | |
| 354 | /** |
| 355 | * I/O completion notification. |
| 356 | * |
| 357 | * @param[in] dio driver IO structure |
| 358 | * @param[in] io_status IO completion status |
| 359 | * @param[in] scsi_status SCSI status returned by target |
| 360 | * @param[in] sns_len SCSI sense length, 0 if none |
| 361 | * @param[in] sns_info SCSI sense data, if any |
| 362 | * @param[in] residue Residual length |
| 363 | * |
| 364 | * @return None |
| 365 | */ |
| 366 | void bfa_cb_ioim_done(void *bfad, struct bfad_ioim_s *dio, |
| 367 | enum bfi_ioim_status io_status, |
| 368 | u8 scsi_status, int sns_len, |
| 369 | u8 *sns_info, s32 residue); |
| 370 | |
| 371 | /** |
| 372 | * I/O good completion notification. |
| 373 | * |
| 374 | * @param[in] dio driver IO structure |
| 375 | * |
| 376 | * @return None |
| 377 | */ |
| 378 | void bfa_cb_ioim_good_comp(void *bfad, struct bfad_ioim_s *dio); |
| 379 | |
| 380 | /** |
| 381 | * I/O abort completion notification |
| 382 | * |
| 383 | * @param[in] dio driver IO that was aborted |
| 384 | * |
| 385 | * @return None |
| 386 | */ |
| 387 | void bfa_cb_ioim_abort(void *bfad, struct bfad_ioim_s *dio); |
| 388 | |
| 389 | /* |
| 390 | * bfa tskim API functions |
| 391 | */ |
| 392 | struct bfa_tskim_s *bfa_tskim_alloc(struct bfa_s *bfa, |
| 393 | struct bfad_tskim_s *dtsk); |
| 394 | void bfa_tskim_free(struct bfa_tskim_s *tskim); |
| 395 | void bfa_tskim_start(struct bfa_tskim_s *tskim, |
| 396 | struct bfa_itnim_s *itnim, lun_t lun, |
| 397 | enum fcp_tm_cmnd tm, u8 t_secs); |
| 398 | void bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk, |
| 399 | enum bfi_tskim_status tsk_status); |
| 400 | |
| 401 | #endif /* __BFA_FCPIM_H__ */ |