Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2 | * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 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 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 18 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 19 | * fcpim.c - FCP initiator mode i-t nexus state machine |
| 20 | */ |
| 21 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 22 | #include "bfad_drv.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 23 | #include "bfa_fcs.h" |
| 24 | #include "bfa_fcbuild.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 25 | #include "bfad_im.h" |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 26 | |
| 27 | BFA_TRC_FILE(FCS, FCPIM); |
| 28 | |
| 29 | /* |
| 30 | * forward declarations |
| 31 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 32 | static void bfa_fcs_itnim_timeout(void *arg); |
| 33 | static void bfa_fcs_itnim_free(struct bfa_fcs_itnim_s *itnim); |
| 34 | static void bfa_fcs_itnim_send_prli(void *itnim_cbarg, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 35 | struct bfa_fcxp_s *fcxp_alloced); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 36 | static void bfa_fcs_itnim_prli_response(void *fcsarg, |
| 37 | struct bfa_fcxp_s *fcxp, void *cbarg, |
| 38 | bfa_status_t req_status, u32 rsp_len, |
| 39 | u32 resid_len, struct fchs_s *rsp_fchs); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 40 | static void bfa_fcs_itnim_aen_post(struct bfa_fcs_itnim_s *itnim, |
| 41 | enum bfa_itnim_aen_event event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 42 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 43 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 44 | * fcs_itnim_sm FCS itnim state machine events |
| 45 | */ |
| 46 | |
| 47 | enum bfa_fcs_itnim_event { |
| 48 | BFA_FCS_ITNIM_SM_ONLINE = 1, /* rport online event */ |
| 49 | BFA_FCS_ITNIM_SM_OFFLINE = 2, /* rport offline */ |
| 50 | BFA_FCS_ITNIM_SM_FRMSENT = 3, /* prli frame is sent */ |
| 51 | BFA_FCS_ITNIM_SM_RSP_OK = 4, /* good response */ |
| 52 | BFA_FCS_ITNIM_SM_RSP_ERROR = 5, /* error response */ |
| 53 | BFA_FCS_ITNIM_SM_TIMEOUT = 6, /* delay timeout */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 54 | BFA_FCS_ITNIM_SM_HCB_OFFLINE = 7, /* BFA online callback */ |
| 55 | BFA_FCS_ITNIM_SM_HCB_ONLINE = 8, /* BFA offline callback */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 56 | BFA_FCS_ITNIM_SM_INITIATOR = 9, /* rport is initiator */ |
| 57 | BFA_FCS_ITNIM_SM_DELETE = 10, /* delete event from rport */ |
| 58 | BFA_FCS_ITNIM_SM_PRLO = 11, /* delete event from rport */ |
Krishna Gudipati | d7be54c | 2011-06-24 20:24:52 -0700 | [diff] [blame] | 59 | BFA_FCS_ITNIM_SM_RSP_NOT_SUPP = 12, /* cmd not supported rsp */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 62 | static void bfa_fcs_itnim_sm_offline(struct bfa_fcs_itnim_s *itnim, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 63 | enum bfa_fcs_itnim_event event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 64 | static void bfa_fcs_itnim_sm_prli_send(struct bfa_fcs_itnim_s *itnim, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 65 | enum bfa_fcs_itnim_event event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 66 | static void bfa_fcs_itnim_sm_prli(struct bfa_fcs_itnim_s *itnim, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 67 | enum bfa_fcs_itnim_event event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 68 | static void bfa_fcs_itnim_sm_prli_retry(struct bfa_fcs_itnim_s *itnim, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 69 | enum bfa_fcs_itnim_event event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 70 | static void bfa_fcs_itnim_sm_hcb_online(struct bfa_fcs_itnim_s *itnim, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 71 | enum bfa_fcs_itnim_event event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 72 | static void bfa_fcs_itnim_sm_online(struct bfa_fcs_itnim_s *itnim, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 73 | enum bfa_fcs_itnim_event event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 74 | static void bfa_fcs_itnim_sm_hcb_offline(struct bfa_fcs_itnim_s *itnim, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 75 | enum bfa_fcs_itnim_event event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 76 | static void bfa_fcs_itnim_sm_initiator(struct bfa_fcs_itnim_s *itnim, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 77 | enum bfa_fcs_itnim_event event); |
| 78 | |
| 79 | static struct bfa_sm_table_s itnim_sm_table[] = { |
| 80 | {BFA_SM(bfa_fcs_itnim_sm_offline), BFA_ITNIM_OFFLINE}, |
| 81 | {BFA_SM(bfa_fcs_itnim_sm_prli_send), BFA_ITNIM_PRLI_SEND}, |
| 82 | {BFA_SM(bfa_fcs_itnim_sm_prli), BFA_ITNIM_PRLI_SENT}, |
| 83 | {BFA_SM(bfa_fcs_itnim_sm_prli_retry), BFA_ITNIM_PRLI_RETRY}, |
| 84 | {BFA_SM(bfa_fcs_itnim_sm_hcb_online), BFA_ITNIM_HCB_ONLINE}, |
| 85 | {BFA_SM(bfa_fcs_itnim_sm_online), BFA_ITNIM_ONLINE}, |
| 86 | {BFA_SM(bfa_fcs_itnim_sm_hcb_offline), BFA_ITNIM_HCB_OFFLINE}, |
| 87 | {BFA_SM(bfa_fcs_itnim_sm_initiator), BFA_ITNIM_INITIATIOR}, |
| 88 | }; |
| 89 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 90 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 91 | * fcs_itnim_sm FCS itnim state machine |
| 92 | */ |
| 93 | |
| 94 | static void |
| 95 | bfa_fcs_itnim_sm_offline(struct bfa_fcs_itnim_s *itnim, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 96 | enum bfa_fcs_itnim_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 97 | { |
| 98 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 99 | bfa_trc(itnim->fcs, event); |
| 100 | |
| 101 | switch (event) { |
| 102 | case BFA_FCS_ITNIM_SM_ONLINE: |
| 103 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_prli_send); |
Jing Huang | 41188cf | 2010-07-08 19:52:00 -0700 | [diff] [blame] | 104 | itnim->prli_retries = 0; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 105 | bfa_fcs_itnim_send_prli(itnim, NULL); |
| 106 | break; |
| 107 | |
| 108 | case BFA_FCS_ITNIM_SM_OFFLINE: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 109 | bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 110 | break; |
| 111 | |
| 112 | case BFA_FCS_ITNIM_SM_INITIATOR: |
| 113 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_initiator); |
| 114 | break; |
| 115 | |
| 116 | case BFA_FCS_ITNIM_SM_DELETE: |
| 117 | bfa_fcs_itnim_free(itnim); |
| 118 | break; |
| 119 | |
| 120 | default: |
Krishna Gudipati | e641de3 | 2010-03-05 19:35:02 -0800 | [diff] [blame] | 121 | bfa_sm_fault(itnim->fcs, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | } |
| 125 | |
| 126 | static void |
| 127 | bfa_fcs_itnim_sm_prli_send(struct bfa_fcs_itnim_s *itnim, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 128 | enum bfa_fcs_itnim_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 129 | { |
| 130 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 131 | bfa_trc(itnim->fcs, event); |
| 132 | |
| 133 | switch (event) { |
| 134 | case BFA_FCS_ITNIM_SM_FRMSENT: |
| 135 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_prli); |
| 136 | break; |
| 137 | |
| 138 | case BFA_FCS_ITNIM_SM_INITIATOR: |
| 139 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_initiator); |
| 140 | bfa_fcxp_walloc_cancel(itnim->fcs->bfa, &itnim->fcxp_wqe); |
| 141 | break; |
| 142 | |
| 143 | case BFA_FCS_ITNIM_SM_OFFLINE: |
| 144 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 145 | bfa_fcxp_walloc_cancel(itnim->fcs->bfa, &itnim->fcxp_wqe); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 146 | bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 147 | break; |
| 148 | |
| 149 | case BFA_FCS_ITNIM_SM_DELETE: |
| 150 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 151 | bfa_fcxp_walloc_cancel(itnim->fcs->bfa, &itnim->fcxp_wqe); |
| 152 | bfa_fcs_itnim_free(itnim); |
| 153 | break; |
| 154 | |
| 155 | default: |
Krishna Gudipati | e641de3 | 2010-03-05 19:35:02 -0800 | [diff] [blame] | 156 | bfa_sm_fault(itnim->fcs, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
| 160 | static void |
| 161 | bfa_fcs_itnim_sm_prli(struct bfa_fcs_itnim_s *itnim, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 162 | enum bfa_fcs_itnim_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 163 | { |
| 164 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 165 | bfa_trc(itnim->fcs, event); |
| 166 | |
| 167 | switch (event) { |
| 168 | case BFA_FCS_ITNIM_SM_RSP_OK: |
Jing Huang | 4b5e759 | 2010-07-08 19:55:41 -0700 | [diff] [blame] | 169 | if (itnim->rport->scsi_function == BFA_RPORT_INITIATOR) { |
| 170 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_initiator); |
| 171 | } else { |
| 172 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_hcb_online); |
| 173 | bfa_itnim_online(itnim->bfa_itnim, itnim->seq_rec); |
| 174 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 175 | break; |
| 176 | |
| 177 | case BFA_FCS_ITNIM_SM_RSP_ERROR: |
| 178 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_prli_retry); |
| 179 | bfa_timer_start(itnim->fcs->bfa, &itnim->timer, |
| 180 | bfa_fcs_itnim_timeout, itnim, |
| 181 | BFA_FCS_RETRY_TIMEOUT); |
| 182 | break; |
| 183 | |
Krishna Gudipati | d7be54c | 2011-06-24 20:24:52 -0700 | [diff] [blame] | 184 | case BFA_FCS_ITNIM_SM_RSP_NOT_SUPP: |
| 185 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 186 | break; |
| 187 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 188 | case BFA_FCS_ITNIM_SM_OFFLINE: |
| 189 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 190 | bfa_fcxp_discard(itnim->fcxp); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 191 | bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 192 | break; |
| 193 | |
| 194 | case BFA_FCS_ITNIM_SM_INITIATOR: |
| 195 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_initiator); |
Jing Huang | 4b5e759 | 2010-07-08 19:55:41 -0700 | [diff] [blame] | 196 | bfa_fcxp_discard(itnim->fcxp); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 197 | break; |
| 198 | |
| 199 | case BFA_FCS_ITNIM_SM_DELETE: |
| 200 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 201 | bfa_fcxp_discard(itnim->fcxp); |
| 202 | bfa_fcs_itnim_free(itnim); |
| 203 | break; |
| 204 | |
| 205 | default: |
Krishna Gudipati | e641de3 | 2010-03-05 19:35:02 -0800 | [diff] [blame] | 206 | bfa_sm_fault(itnim->fcs, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
| 210 | static void |
| 211 | bfa_fcs_itnim_sm_prli_retry(struct bfa_fcs_itnim_s *itnim, |
| 212 | enum bfa_fcs_itnim_event event) |
| 213 | { |
| 214 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 215 | bfa_trc(itnim->fcs, event); |
| 216 | |
| 217 | switch (event) { |
| 218 | case BFA_FCS_ITNIM_SM_TIMEOUT: |
Jing Huang | 41188cf | 2010-07-08 19:52:00 -0700 | [diff] [blame] | 219 | if (itnim->prli_retries < BFA_FCS_RPORT_MAX_RETRIES) { |
| 220 | itnim->prli_retries++; |
| 221 | bfa_trc(itnim->fcs, itnim->prli_retries); |
| 222 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_prli_send); |
| 223 | bfa_fcs_itnim_send_prli(itnim, NULL); |
| 224 | } else { |
| 225 | /* invoke target offline */ |
| 226 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 227 | bfa_sm_send_event(itnim->rport, RPSM_EVENT_LOGO_IMP); |
Jing Huang | 41188cf | 2010-07-08 19:52:00 -0700 | [diff] [blame] | 228 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 229 | break; |
| 230 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 231 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 232 | case BFA_FCS_ITNIM_SM_OFFLINE: |
| 233 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 234 | bfa_timer_stop(&itnim->timer); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 235 | bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 236 | break; |
| 237 | |
| 238 | case BFA_FCS_ITNIM_SM_INITIATOR: |
| 239 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_initiator); |
| 240 | bfa_timer_stop(&itnim->timer); |
| 241 | break; |
| 242 | |
| 243 | case BFA_FCS_ITNIM_SM_DELETE: |
| 244 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 245 | bfa_timer_stop(&itnim->timer); |
| 246 | bfa_fcs_itnim_free(itnim); |
| 247 | break; |
| 248 | |
| 249 | default: |
Krishna Gudipati | e641de3 | 2010-03-05 19:35:02 -0800 | [diff] [blame] | 250 | bfa_sm_fault(itnim->fcs, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | static void |
| 255 | bfa_fcs_itnim_sm_hcb_online(struct bfa_fcs_itnim_s *itnim, |
| 256 | enum bfa_fcs_itnim_event event) |
| 257 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 258 | struct bfad_s *bfad = (struct bfad_s *)itnim->fcs->bfad; |
| 259 | char lpwwn_buf[BFA_STRING_32]; |
| 260 | char rpwwn_buf[BFA_STRING_32]; |
| 261 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 262 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 263 | bfa_trc(itnim->fcs, event); |
| 264 | |
| 265 | switch (event) { |
| 266 | case BFA_FCS_ITNIM_SM_HCB_ONLINE: |
| 267 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_online); |
| 268 | bfa_fcb_itnim_online(itnim->itnim_drv); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 269 | wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(itnim->rport->port)); |
| 270 | wwn2str(rpwwn_buf, itnim->rport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 271 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 272 | "Target (WWN = %s) is online for initiator (WWN = %s)\n", |
| 273 | rpwwn_buf, lpwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 274 | bfa_fcs_itnim_aen_post(itnim, BFA_ITNIM_AEN_ONLINE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 275 | break; |
| 276 | |
| 277 | case BFA_FCS_ITNIM_SM_OFFLINE: |
| 278 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 279 | bfa_itnim_offline(itnim->bfa_itnim); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 280 | bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 281 | break; |
| 282 | |
| 283 | case BFA_FCS_ITNIM_SM_DELETE: |
| 284 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 285 | bfa_fcs_itnim_free(itnim); |
| 286 | break; |
| 287 | |
| 288 | default: |
Krishna Gudipati | e641de3 | 2010-03-05 19:35:02 -0800 | [diff] [blame] | 289 | bfa_sm_fault(itnim->fcs, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
| 293 | static void |
| 294 | bfa_fcs_itnim_sm_online(struct bfa_fcs_itnim_s *itnim, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 295 | enum bfa_fcs_itnim_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 296 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 297 | struct bfad_s *bfad = (struct bfad_s *)itnim->fcs->bfad; |
| 298 | char lpwwn_buf[BFA_STRING_32]; |
| 299 | char rpwwn_buf[BFA_STRING_32]; |
| 300 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 301 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 302 | bfa_trc(itnim->fcs, event); |
| 303 | |
| 304 | switch (event) { |
| 305 | case BFA_FCS_ITNIM_SM_OFFLINE: |
| 306 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_hcb_offline); |
| 307 | bfa_fcb_itnim_offline(itnim->itnim_drv); |
| 308 | bfa_itnim_offline(itnim->bfa_itnim); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 309 | wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(itnim->rport->port)); |
| 310 | wwn2str(rpwwn_buf, itnim->rport->pwwn); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 311 | if (bfa_fcs_lport_is_online(itnim->rport->port) == BFA_TRUE) { |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 312 | BFA_LOG(KERN_ERR, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 313 | "Target (WWN = %s) connectivity lost for " |
| 314 | "initiator (WWN = %s)\n", rpwwn_buf, lpwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 315 | bfa_fcs_itnim_aen_post(itnim, BFA_ITNIM_AEN_DISCONNECT); |
| 316 | } else { |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 317 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 318 | "Target (WWN = %s) offlined by initiator (WWN = %s)\n", |
| 319 | rpwwn_buf, lpwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 320 | bfa_fcs_itnim_aen_post(itnim, BFA_ITNIM_AEN_OFFLINE); |
| 321 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 322 | break; |
| 323 | |
| 324 | case BFA_FCS_ITNIM_SM_DELETE: |
| 325 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 326 | bfa_fcs_itnim_free(itnim); |
| 327 | break; |
| 328 | |
| 329 | default: |
Krishna Gudipati | e641de3 | 2010-03-05 19:35:02 -0800 | [diff] [blame] | 330 | bfa_sm_fault(itnim->fcs, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
| 334 | static void |
| 335 | bfa_fcs_itnim_sm_hcb_offline(struct bfa_fcs_itnim_s *itnim, |
| 336 | enum bfa_fcs_itnim_event event) |
| 337 | { |
| 338 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 339 | bfa_trc(itnim->fcs, event); |
| 340 | |
| 341 | switch (event) { |
| 342 | case BFA_FCS_ITNIM_SM_HCB_OFFLINE: |
| 343 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 344 | bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 345 | break; |
| 346 | |
| 347 | case BFA_FCS_ITNIM_SM_DELETE: |
| 348 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 349 | bfa_fcs_itnim_free(itnim); |
| 350 | break; |
| 351 | |
| 352 | default: |
Krishna Gudipati | e641de3 | 2010-03-05 19:35:02 -0800 | [diff] [blame] | 353 | bfa_sm_fault(itnim->fcs, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * This state is set when a discovered rport is also in intiator mode. |
| 359 | * This ITN is marked as no_op and is not active and will not be truned into |
| 360 | * online state. |
| 361 | */ |
| 362 | static void |
| 363 | bfa_fcs_itnim_sm_initiator(struct bfa_fcs_itnim_s *itnim, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 364 | enum bfa_fcs_itnim_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 365 | { |
| 366 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 367 | bfa_trc(itnim->fcs, event); |
| 368 | |
| 369 | switch (event) { |
| 370 | case BFA_FCS_ITNIM_SM_OFFLINE: |
| 371 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 372 | bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 373 | break; |
| 374 | |
| 375 | case BFA_FCS_ITNIM_SM_RSP_ERROR: |
| 376 | case BFA_FCS_ITNIM_SM_ONLINE: |
| 377 | case BFA_FCS_ITNIM_SM_INITIATOR: |
| 378 | break; |
| 379 | |
| 380 | case BFA_FCS_ITNIM_SM_DELETE: |
| 381 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 382 | bfa_fcs_itnim_free(itnim); |
| 383 | break; |
| 384 | |
| 385 | default: |
Krishna Gudipati | e641de3 | 2010-03-05 19:35:02 -0800 | [diff] [blame] | 386 | bfa_sm_fault(itnim->fcs, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 390 | static void |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 391 | bfa_fcs_itnim_aen_post(struct bfa_fcs_itnim_s *itnim, |
| 392 | enum bfa_itnim_aen_event event) |
| 393 | { |
| 394 | struct bfa_fcs_rport_s *rport = itnim->rport; |
| 395 | struct bfad_s *bfad = (struct bfad_s *)itnim->fcs->bfad; |
| 396 | struct bfa_aen_entry_s *aen_entry; |
| 397 | |
| 398 | /* Don't post events for well known addresses */ |
| 399 | if (BFA_FCS_PID_IS_WKA(rport->pid)) |
| 400 | return; |
| 401 | |
| 402 | bfad_get_aen_entry(bfad, aen_entry); |
| 403 | if (!aen_entry) |
| 404 | return; |
| 405 | |
| 406 | aen_entry->aen_data.itnim.vf_id = rport->port->fabric->vf_id; |
| 407 | aen_entry->aen_data.itnim.ppwwn = bfa_fcs_lport_get_pwwn( |
| 408 | bfa_fcs_get_base_port(itnim->fcs)); |
| 409 | aen_entry->aen_data.itnim.lpwwn = bfa_fcs_lport_get_pwwn(rport->port); |
| 410 | aen_entry->aen_data.itnim.rpwwn = rport->pwwn; |
| 411 | |
| 412 | /* Send the AEN notification */ |
| 413 | bfad_im_post_vendor_event(aen_entry, bfad, ++rport->fcs->fcs_aen_seq, |
| 414 | BFA_AEN_CAT_ITNIM, event); |
| 415 | } |
| 416 | |
| 417 | static void |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 418 | bfa_fcs_itnim_send_prli(void *itnim_cbarg, struct bfa_fcxp_s *fcxp_alloced) |
| 419 | { |
| 420 | struct bfa_fcs_itnim_s *itnim = itnim_cbarg; |
| 421 | struct bfa_fcs_rport_s *rport = itnim->rport; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 422 | struct bfa_fcs_lport_s *port = rport->port; |
| 423 | struct fchs_s fchs; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 424 | struct bfa_fcxp_s *fcxp; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 425 | int len; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 426 | |
| 427 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 428 | |
| 429 | fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs); |
| 430 | if (!fcxp) { |
| 431 | itnim->stats.fcxp_alloc_wait++; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 432 | bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &itnim->fcxp_wqe, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 433 | bfa_fcs_itnim_send_prli, itnim); |
| 434 | return; |
| 435 | } |
| 436 | itnim->fcxp = fcxp; |
| 437 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 438 | len = fc_prli_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), |
| 439 | itnim->rport->pid, bfa_fcs_lport_get_fcid(port), 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 440 | |
| 441 | bfa_fcxp_send(fcxp, rport->bfa_rport, port->fabric->vf_id, port->lp_tag, |
| 442 | BFA_FALSE, FC_CLASS_3, len, &fchs, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 443 | bfa_fcs_itnim_prli_response, (void *)itnim, |
| 444 | FC_MAX_PDUSZ, FC_ELS_TOV); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 445 | |
| 446 | itnim->stats.prli_sent++; |
| 447 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_FRMSENT); |
| 448 | } |
| 449 | |
| 450 | static void |
| 451 | bfa_fcs_itnim_prli_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg, |
| 452 | bfa_status_t req_status, u32 rsp_len, |
| 453 | u32 resid_len, struct fchs_s *rsp_fchs) |
| 454 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 455 | struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cbarg; |
| 456 | struct fc_els_cmd_s *els_cmd; |
| 457 | struct fc_prli_s *prli_resp; |
| 458 | struct fc_ls_rjt_s *ls_rjt; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 459 | struct fc_prli_params_s *sparams; |
| 460 | |
| 461 | bfa_trc(itnim->fcs, req_status); |
| 462 | |
| 463 | /* |
| 464 | * Sanity Checks |
| 465 | */ |
| 466 | if (req_status != BFA_STATUS_OK) { |
| 467 | itnim->stats.prli_rsp_err++; |
| 468 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_RSP_ERROR); |
| 469 | return; |
| 470 | } |
| 471 | |
| 472 | els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp); |
| 473 | |
| 474 | if (els_cmd->els_code == FC_ELS_ACC) { |
| 475 | prli_resp = (struct fc_prli_s *) els_cmd; |
| 476 | |
| 477 | if (fc_prli_rsp_parse(prli_resp, rsp_len) != FC_PARSE_OK) { |
| 478 | bfa_trc(itnim->fcs, rsp_len); |
| 479 | /* |
| 480 | * Check if this r-port is also in Initiator mode. |
| 481 | * If so, we need to set this ITN as a no-op. |
| 482 | */ |
| 483 | if (prli_resp->parampage.servparams.initiator) { |
| 484 | bfa_trc(itnim->fcs, prli_resp->parampage.type); |
| 485 | itnim->rport->scsi_function = |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 486 | BFA_RPORT_INITIATOR; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 487 | itnim->stats.prli_rsp_acc++; |
Krishna Gudipati | d7be54c | 2011-06-24 20:24:52 -0700 | [diff] [blame] | 488 | itnim->stats.initiator++; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 489 | bfa_sm_send_event(itnim, |
Jing Huang | 4b5e759 | 2010-07-08 19:55:41 -0700 | [diff] [blame] | 490 | BFA_FCS_ITNIM_SM_RSP_OK); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 491 | return; |
| 492 | } |
| 493 | |
| 494 | itnim->stats.prli_rsp_parse_err++; |
| 495 | return; |
| 496 | } |
| 497 | itnim->rport->scsi_function = BFA_RPORT_TARGET; |
| 498 | |
| 499 | sparams = &prli_resp->parampage.servparams; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 500 | itnim->seq_rec = sparams->retry; |
| 501 | itnim->rec_support = sparams->rec_support; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 502 | itnim->task_retry_id = sparams->task_retry_id; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 503 | itnim->conf_comp = sparams->confirm; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 504 | |
| 505 | itnim->stats.prli_rsp_acc++; |
| 506 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_RSP_OK); |
| 507 | } else { |
| 508 | ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp); |
| 509 | |
| 510 | bfa_trc(itnim->fcs, ls_rjt->reason_code); |
| 511 | bfa_trc(itnim->fcs, ls_rjt->reason_code_expl); |
| 512 | |
| 513 | itnim->stats.prli_rsp_rjt++; |
Krishna Gudipati | d7be54c | 2011-06-24 20:24:52 -0700 | [diff] [blame] | 514 | if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP) { |
| 515 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_RSP_NOT_SUPP); |
| 516 | return; |
| 517 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 518 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_RSP_ERROR); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | static void |
| 523 | bfa_fcs_itnim_timeout(void *arg) |
| 524 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 525 | struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) arg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 526 | |
| 527 | itnim->stats.timeout++; |
| 528 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_TIMEOUT); |
| 529 | } |
| 530 | |
| 531 | static void |
| 532 | bfa_fcs_itnim_free(struct bfa_fcs_itnim_s *itnim) |
| 533 | { |
| 534 | bfa_itnim_delete(itnim->bfa_itnim); |
| 535 | bfa_fcb_itnim_free(itnim->fcs->bfad, itnim->itnim_drv); |
| 536 | } |
| 537 | |
| 538 | |
| 539 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 540 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 541 | * itnim_public FCS ITNIM public interfaces |
| 542 | */ |
| 543 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 544 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 545 | * Called by rport when a new rport is created. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 546 | * |
| 547 | * @param[in] rport - remote port. |
| 548 | */ |
| 549 | struct bfa_fcs_itnim_s * |
| 550 | bfa_fcs_itnim_create(struct bfa_fcs_rport_s *rport) |
| 551 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 552 | struct bfa_fcs_lport_s *port = rport->port; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 553 | struct bfa_fcs_itnim_s *itnim; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 554 | struct bfad_itnim_s *itnim_drv; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 555 | struct bfa_itnim_s *bfa_itnim; |
| 556 | |
| 557 | /* |
| 558 | * call bfad to allocate the itnim |
| 559 | */ |
| 560 | bfa_fcb_itnim_alloc(port->fcs->bfad, &itnim, &itnim_drv); |
| 561 | if (itnim == NULL) { |
| 562 | bfa_trc(port->fcs, rport->pwwn); |
| 563 | return NULL; |
| 564 | } |
| 565 | |
| 566 | /* |
| 567 | * Initialize itnim |
| 568 | */ |
| 569 | itnim->rport = rport; |
| 570 | itnim->fcs = rport->fcs; |
| 571 | itnim->itnim_drv = itnim_drv; |
| 572 | |
| 573 | /* |
| 574 | * call BFA to create the itnim |
| 575 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 576 | bfa_itnim = |
| 577 | bfa_itnim_create(port->fcs->bfa, rport->bfa_rport, itnim); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 578 | |
| 579 | if (bfa_itnim == NULL) { |
| 580 | bfa_trc(port->fcs, rport->pwwn); |
| 581 | bfa_fcb_itnim_free(port->fcs->bfad, itnim_drv); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 582 | WARN_ON(1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 583 | return NULL; |
| 584 | } |
| 585 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 586 | itnim->bfa_itnim = bfa_itnim; |
| 587 | itnim->seq_rec = BFA_FALSE; |
| 588 | itnim->rec_support = BFA_FALSE; |
| 589 | itnim->conf_comp = BFA_FALSE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 590 | itnim->task_retry_id = BFA_FALSE; |
| 591 | |
| 592 | /* |
| 593 | * Set State machine |
| 594 | */ |
| 595 | bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline); |
| 596 | |
| 597 | return itnim; |
| 598 | } |
| 599 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 600 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 601 | * Called by rport to delete the instance of FCPIM. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 602 | * |
| 603 | * @param[in] rport - remote port. |
| 604 | */ |
| 605 | void |
| 606 | bfa_fcs_itnim_delete(struct bfa_fcs_itnim_s *itnim) |
| 607 | { |
| 608 | bfa_trc(itnim->fcs, itnim->rport->pid); |
| 609 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_DELETE); |
| 610 | } |
| 611 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 612 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 613 | * Notification from rport that PLOGI is complete to initiate FC-4 session. |
| 614 | */ |
| 615 | void |
| 616 | bfa_fcs_itnim_rport_online(struct bfa_fcs_itnim_s *itnim) |
| 617 | { |
| 618 | itnim->stats.onlines++; |
| 619 | |
| 620 | if (!BFA_FCS_PID_IS_WKA(itnim->rport->pid)) { |
| 621 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_ONLINE); |
| 622 | } else { |
| 623 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 624 | * For well known addresses, we set the itnim to initiator |
| 625 | * state |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 626 | */ |
| 627 | itnim->stats.initiator++; |
| 628 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_INITIATOR); |
| 629 | } |
| 630 | } |
| 631 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 632 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 633 | * Called by rport to handle a remote device offline. |
| 634 | */ |
| 635 | void |
| 636 | bfa_fcs_itnim_rport_offline(struct bfa_fcs_itnim_s *itnim) |
| 637 | { |
| 638 | itnim->stats.offlines++; |
| 639 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_OFFLINE); |
| 640 | } |
| 641 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 642 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 643 | * Called by rport when remote port is known to be an initiator from |
| 644 | * PRLI received. |
| 645 | */ |
| 646 | void |
| 647 | bfa_fcs_itnim_is_initiator(struct bfa_fcs_itnim_s *itnim) |
| 648 | { |
| 649 | bfa_trc(itnim->fcs, itnim->rport->pid); |
| 650 | itnim->stats.initiator++; |
| 651 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_INITIATOR); |
| 652 | } |
| 653 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 654 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 655 | * Called by rport to check if the itnim is online. |
| 656 | */ |
| 657 | bfa_status_t |
| 658 | bfa_fcs_itnim_get_online_state(struct bfa_fcs_itnim_s *itnim) |
| 659 | { |
| 660 | bfa_trc(itnim->fcs, itnim->rport->pid); |
| 661 | switch (bfa_sm_to_state(itnim_sm_table, itnim->sm)) { |
| 662 | case BFA_ITNIM_ONLINE: |
| 663 | case BFA_ITNIM_INITIATIOR: |
| 664 | return BFA_STATUS_OK; |
| 665 | |
| 666 | default: |
| 667 | return BFA_STATUS_NO_FCPIM_NEXUS; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 671 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 672 | * BFA completion callback for bfa_itnim_online(). |
| 673 | */ |
| 674 | void |
| 675 | bfa_cb_itnim_online(void *cbarg) |
| 676 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 677 | struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cbarg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 678 | |
| 679 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 680 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_HCB_ONLINE); |
| 681 | } |
| 682 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 683 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 684 | * BFA completion callback for bfa_itnim_offline(). |
| 685 | */ |
| 686 | void |
| 687 | bfa_cb_itnim_offline(void *cb_arg) |
| 688 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 689 | struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cb_arg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 690 | |
| 691 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
| 692 | bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_HCB_OFFLINE); |
| 693 | } |
| 694 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 695 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 696 | * Mark the beginning of PATH TOV handling. IO completion callbacks |
| 697 | * are still pending. |
| 698 | */ |
| 699 | void |
| 700 | bfa_cb_itnim_tov_begin(void *cb_arg) |
| 701 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 702 | struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cb_arg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 703 | |
| 704 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 707 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 708 | * Mark the end of PATH TOV handling. All pending IOs are already cleaned up. |
| 709 | */ |
| 710 | void |
| 711 | bfa_cb_itnim_tov(void *cb_arg) |
| 712 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 713 | struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cb_arg; |
| 714 | struct bfad_itnim_s *itnim_drv = itnim->itnim_drv; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 715 | |
| 716 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 717 | itnim_drv->state = ITNIM_STATE_TIMEOUT; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 720 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 721 | * BFA notification to FCS/driver for second level error recovery. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 722 | * |
| 723 | * Atleast one I/O request has timedout and target is unresponsive to |
| 724 | * repeated abort requests. Second level error recovery should be initiated |
| 725 | * by starting implicit logout and recovery procedures. |
| 726 | */ |
| 727 | void |
| 728 | bfa_cb_itnim_sler(void *cb_arg) |
| 729 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 730 | struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cb_arg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 731 | |
| 732 | itnim->stats.sler++; |
| 733 | bfa_trc(itnim->fcs, itnim->rport->pwwn); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 734 | bfa_sm_send_event(itnim->rport, RPSM_EVENT_LOGO_IMP); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | struct bfa_fcs_itnim_s * |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 738 | bfa_fcs_itnim_lookup(struct bfa_fcs_lport_s *port, wwn_t rpwwn) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 739 | { |
| 740 | struct bfa_fcs_rport_s *rport; |
| 741 | rport = bfa_fcs_rport_lookup(port, rpwwn); |
| 742 | |
| 743 | if (!rport) |
| 744 | return NULL; |
| 745 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 746 | WARN_ON(rport->itnim == NULL); |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 747 | return rport->itnim; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | bfa_status_t |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 751 | bfa_fcs_itnim_attr_get(struct bfa_fcs_lport_s *port, wwn_t rpwwn, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 752 | struct bfa_itnim_attr_s *attr) |
| 753 | { |
| 754 | struct bfa_fcs_itnim_s *itnim = NULL; |
| 755 | |
| 756 | itnim = bfa_fcs_itnim_lookup(port, rpwwn); |
| 757 | |
| 758 | if (itnim == NULL) |
| 759 | return BFA_STATUS_NO_FCPIM_NEXUS; |
| 760 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 761 | attr->state = bfa_sm_to_state(itnim_sm_table, itnim->sm); |
| 762 | attr->retry = itnim->seq_rec; |
| 763 | attr->rec_support = itnim->rec_support; |
| 764 | attr->conf_comp = itnim->conf_comp; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 765 | attr->task_retry_id = itnim->task_retry_id; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 766 | return BFA_STATUS_OK; |
| 767 | } |
| 768 | |
| 769 | bfa_status_t |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 770 | bfa_fcs_itnim_stats_get(struct bfa_fcs_lport_s *port, wwn_t rpwwn, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 771 | struct bfa_itnim_stats_s *stats) |
| 772 | { |
| 773 | struct bfa_fcs_itnim_s *itnim = NULL; |
| 774 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 775 | WARN_ON(port == NULL); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 776 | |
| 777 | itnim = bfa_fcs_itnim_lookup(port, rpwwn); |
| 778 | |
| 779 | if (itnim == NULL) |
| 780 | return BFA_STATUS_NO_FCPIM_NEXUS; |
| 781 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 782 | memcpy(stats, &itnim->stats, sizeof(struct bfa_itnim_stats_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 783 | |
| 784 | return BFA_STATUS_OK; |
| 785 | } |
| 786 | |
| 787 | bfa_status_t |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 788 | bfa_fcs_itnim_stats_clear(struct bfa_fcs_lport_s *port, wwn_t rpwwn) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 789 | { |
| 790 | struct bfa_fcs_itnim_s *itnim = NULL; |
| 791 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 792 | WARN_ON(port == NULL); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 793 | |
| 794 | itnim = bfa_fcs_itnim_lookup(port, rpwwn); |
| 795 | |
| 796 | if (itnim == NULL) |
| 797 | return BFA_STATUS_NO_FCPIM_NEXUS; |
| 798 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 799 | memset(&itnim->stats, 0, sizeof(struct bfa_itnim_stats_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 800 | return BFA_STATUS_OK; |
| 801 | } |
| 802 | |
| 803 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 804 | bfa_fcs_fcpim_uf_recv(struct bfa_fcs_itnim_s *itnim, |
| 805 | struct fchs_s *fchs, u16 len) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 806 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 807 | struct fc_els_cmd_s *els_cmd; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 808 | |
| 809 | bfa_trc(itnim->fcs, fchs->type); |
| 810 | |
| 811 | if (fchs->type != FC_TYPE_ELS) |
| 812 | return; |
| 813 | |
| 814 | els_cmd = (struct fc_els_cmd_s *) (fchs + 1); |
| 815 | |
| 816 | bfa_trc(itnim->fcs, els_cmd->els_code); |
| 817 | |
| 818 | switch (els_cmd->els_code) { |
| 819 | case FC_ELS_PRLO: |
Jing Huang | 4b5e759 | 2010-07-08 19:55:41 -0700 | [diff] [blame] | 820 | bfa_fcs_rport_prlo(itnim->rport, fchs->ox_id); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 821 | break; |
| 822 | |
| 823 | default: |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 824 | WARN_ON(1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 825 | } |
| 826 | } |