Blame view

drivers/scsi/bfa/bfa_fcs_rport.c 76.1 KB
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2
   * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
   * All rights reserved
   * www.brocade.com
   *
   * Linux driver for Brocade Fibre Channel Host Bus Adapter.
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License (GPL) Version 2 as
   * published by the Free Software Foundation
   *
   * This program is distributed in the hope that it will be useful, but
   * WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * General Public License for more details.
   */
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
17
  /*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
18
19
   *  rport.c Remote port implementation.
   */
f16a17507   Maggie Zhang   [SCSI] bfa: remov...
20
  #include "bfad_drv.h"
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
21
  #include "bfad_im.h"
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
22
23
  #include "bfa_fcs.h"
  #include "bfa_fcbuild.h"
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
24
25
  
  BFA_TRC_FILE(FCS, RPORT);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
26
27
28
  static u32
  bfa_fcs_rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT * 1000;
  	 /* In millisecs */
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
29
30
31
  /*
   * forward declarations
   */
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
32
33
34
35
36
37
38
39
40
41
  static struct bfa_fcs_rport_s *bfa_fcs_rport_alloc(
  		struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid);
  static void	bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport);
  static void	bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport);
  static void	bfa_fcs_rport_online_action(struct bfa_fcs_rport_s *rport);
  static void	bfa_fcs_rport_offline_action(struct bfa_fcs_rport_s *rport);
  static void	bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport,
  					struct fc_logi_s *plogi);
  static void	bfa_fcs_rport_timeout(void *arg);
  static void	bfa_fcs_rport_send_plogi(void *rport_cbarg,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
42
  					 struct bfa_fcxp_s *fcxp_alloced);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
43
44
45
46
47
48
49
  static void	bfa_fcs_rport_send_plogiacc(void *rport_cbarg,
  					struct bfa_fcxp_s *fcxp_alloced);
  static void	bfa_fcs_rport_plogi_response(void *fcsarg,
  				struct bfa_fcxp_s *fcxp, void *cbarg,
  				bfa_status_t req_status, u32 rsp_len,
  				u32 resid_len, struct fchs_s *rsp_fchs);
  static void	bfa_fcs_rport_send_adisc(void *rport_cbarg,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
50
  					 struct bfa_fcxp_s *fcxp_alloced);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
51
52
53
54
55
  static void	bfa_fcs_rport_adisc_response(void *fcsarg,
  				struct bfa_fcxp_s *fcxp, void *cbarg,
  				bfa_status_t req_status, u32 rsp_len,
  				u32 resid_len, struct fchs_s *rsp_fchs);
  static void	bfa_fcs_rport_send_nsdisc(void *rport_cbarg,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
56
  					 struct bfa_fcxp_s *fcxp_alloced);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
57
58
59
60
61
62
63
64
65
  static void	bfa_fcs_rport_gidpn_response(void *fcsarg,
  				struct bfa_fcxp_s *fcxp, void *cbarg,
  				bfa_status_t req_status, u32 rsp_len,
  				u32 resid_len, struct fchs_s *rsp_fchs);
  static void	bfa_fcs_rport_gpnid_response(void *fcsarg,
  				struct bfa_fcxp_s *fcxp, void *cbarg,
  				bfa_status_t req_status, u32 rsp_len,
  				u32 resid_len, struct fchs_s *rsp_fchs);
  static void	bfa_fcs_rport_send_logo(void *rport_cbarg,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
66
  					struct bfa_fcxp_s *fcxp_alloced);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
67
68
69
70
71
72
73
74
75
  static void	bfa_fcs_rport_send_logo_acc(void *rport_cbarg);
  static void	bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
  					struct fchs_s *rx_fchs, u16 len);
  static void	bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport,
  				struct fchs_s *rx_fchs, u8 reason_code,
  					  u8 reason_code_expl);
  static void	bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
  				struct fchs_s *rx_fchs, u16 len);
  static void bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
76

a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
77
  static void	bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
78
  					enum rport_event event);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
79
80
81
  static void	bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
82
  						  enum rport_event event);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
83
84
85
  static void	bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
86
  					enum rport_event event);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
87
88
89
90
91
  static void	bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport,
  					enum rport_event event);
  static void	bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
92
  						 enum rport_event event);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
93
  static void	bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
94
  					 enum rport_event event);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  static void	bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport,
  					enum rport_event event);
  static void	bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
114
  					 enum rport_event event);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
115
116
117
118
119
120
121
  static void	bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
  						enum rport_event event);
  static void	bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
122
  						enum rport_event event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
  
  static struct bfa_sm_table_s rport_sm_table[] = {
  	{BFA_SM(bfa_fcs_rport_sm_uninit), BFA_RPORT_UNINIT},
  	{BFA_SM(bfa_fcs_rport_sm_plogi_sending), BFA_RPORT_PLOGI},
  	{BFA_SM(bfa_fcs_rport_sm_plogiacc_sending), BFA_RPORT_ONLINE},
  	{BFA_SM(bfa_fcs_rport_sm_plogi_retry), BFA_RPORT_PLOGI_RETRY},
  	{BFA_SM(bfa_fcs_rport_sm_plogi), BFA_RPORT_PLOGI},
  	{BFA_SM(bfa_fcs_rport_sm_hal_online), BFA_RPORT_ONLINE},
  	{BFA_SM(bfa_fcs_rport_sm_online), BFA_RPORT_ONLINE},
  	{BFA_SM(bfa_fcs_rport_sm_nsquery_sending), BFA_RPORT_NSQUERY},
  	{BFA_SM(bfa_fcs_rport_sm_nsquery), BFA_RPORT_NSQUERY},
  	{BFA_SM(bfa_fcs_rport_sm_adisc_sending), BFA_RPORT_ADISC},
  	{BFA_SM(bfa_fcs_rport_sm_adisc), BFA_RPORT_ADISC},
  	{BFA_SM(bfa_fcs_rport_sm_fc4_logorcv), BFA_RPORT_LOGORCV},
  	{BFA_SM(bfa_fcs_rport_sm_fc4_logosend), BFA_RPORT_LOGO},
  	{BFA_SM(bfa_fcs_rport_sm_fc4_offline), BFA_RPORT_OFFLINE},
  	{BFA_SM(bfa_fcs_rport_sm_hcb_offline), BFA_RPORT_OFFLINE},
  	{BFA_SM(bfa_fcs_rport_sm_hcb_logorcv), BFA_RPORT_LOGORCV},
  	{BFA_SM(bfa_fcs_rport_sm_hcb_logosend), BFA_RPORT_LOGO},
  	{BFA_SM(bfa_fcs_rport_sm_logo_sending), BFA_RPORT_LOGO},
  	{BFA_SM(bfa_fcs_rport_sm_offline), BFA_RPORT_OFFLINE},
  	{BFA_SM(bfa_fcs_rport_sm_nsdisc_sending), BFA_RPORT_NSDISC},
  	{BFA_SM(bfa_fcs_rport_sm_nsdisc_retry), BFA_RPORT_NSDISC},
  	{BFA_SM(bfa_fcs_rport_sm_nsdisc_sent), BFA_RPORT_NSDISC},
  };
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
148
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
149
   *		Beginning state.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
   */
  static void
  bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport, enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_PLOGI_SEND:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  		rport->plogi_retries = 0;
  		bfa_fcs_rport_send_plogi(rport, NULL);
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  		bfa_fcs_rport_send_plogiacc(rport, NULL);
  		break;
  
  	case RPSM_EVENT_PLOGI_COMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  		bfa_fcs_rport_hal_online(rport);
  		break;
  
  	case RPSM_EVENT_ADDRESS_CHANGE:
  	case RPSM_EVENT_ADDRESS_DISC:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  		rport->ns_retries = 0;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
179
  		bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
180
  		break;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
181
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
182
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
183
184
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
185
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
186
   *		PLOGI is being sent.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
187
188
189
   */
  static void
  bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
190
  	 enum rport_event event)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_FCXP_SENT:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi);
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_free(rport);
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_send_plogiacc(rport, NULL);
  		break;
  
  	case RPSM_EVENT_ADDRESS_CHANGE:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
214
215
  	case RPSM_EVENT_SCN:
  		/* query the NS */
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
216
217
218
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  		rport->ns_retries = 0;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
219
  		bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
220
221
222
223
224
225
226
227
228
229
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  		rport->pid = 0;
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_timer_start(rport->fcs->bfa, &rport->timer,
  				bfa_fcs_rport_timeout, rport,
  				bfa_fcs_rport_del_timeout);
  		break;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
230
231
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
232
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
233
234
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
235
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
236
   *		PLOGI is being sent.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
237
238
239
   */
  static void
  bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
240
  	 enum rport_event event)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_FCXP_SENT:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  		bfa_fcs_rport_hal_online(rport);
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_free(rport);
  		break;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
257
  	case RPSM_EVENT_PLOGI_RCVD:
d7be54cc5   Krishna Gudipati   [SCSI] bfa: FCS b...
258
  	case RPSM_EVENT_PLOGI_COMP:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
259
  	case RPSM_EVENT_SCN:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
260
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
261
262
263
264
265
266
267
268
  		 * Ignore, SCN is possibly online notification.
  		 */
  		break;
  
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  		rport->ns_retries = 0;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
269
  		bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
270
271
272
273
274
275
276
277
278
279
280
281
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  		rport->pid = 0;
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_timer_start(rport->fcs->bfa, &rport->timer,
  				bfa_fcs_rport_timeout, rport,
  				bfa_fcs_rport_del_timeout);
  		break;
  
  	case RPSM_EVENT_HCB_OFFLINE:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
282
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
283
284
285
286
287
  		 * Ignore BFA callback, on a PLOGI receive we call bfa offline.
  		 */
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
288
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
289
290
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
291
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
292
   *		PLOGI is sent.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
293
294
295
296
297
298
299
300
301
302
   */
  static void
  bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
  			enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
303
  	case RPSM_EVENT_TIMEOUT:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
304
305
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  		bfa_fcs_rport_send_plogi(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
306
307
308
309
310
311
312
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_timer_stop(&rport->timer);
  		bfa_fcs_rport_free(rport);
  		break;
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
313
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
314
315
316
317
318
319
320
321
322
323
  	case RPSM_EVENT_LOGO_RCVD:
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  		bfa_timer_stop(&rport->timer);
  		bfa_fcs_rport_send_plogiacc(rport, NULL);
  		break;
  
  	case RPSM_EVENT_ADDRESS_CHANGE:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
324
  	case RPSM_EVENT_SCN:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
325
326
327
  		bfa_timer_stop(&rport->timer);
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  		rport->ns_retries = 0;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
328
  		bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  		rport->pid = 0;
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  		bfa_timer_stop(&rport->timer);
  		bfa_timer_start(rport->fcs->bfa, &rport->timer,
  				bfa_fcs_rport_timeout, rport,
  				bfa_fcs_rport_del_timeout);
  		break;
  
  	case RPSM_EVENT_PLOGI_COMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  		bfa_timer_stop(&rport->timer);
  		bfa_fcs_rport_hal_online(rport);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
347
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
348
349
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
350
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
351
   *		PLOGI is sent.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
   */
  static void
  bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport, enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_ACCEPTED:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  		rport->plogi_retries = 0;
  		bfa_fcs_rport_hal_online(rport);
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
  		bfa_fcs_rport_send_logo_acc(rport);
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
369
370
371
372
373
374
  		/*
  		 * !! fall through !!
  		 */
  	case RPSM_EVENT_PRLO_RCVD:
  		if (rport->prlo == BFA_TRUE)
  			bfa_fcs_rport_send_prlo_acc(rport);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
375
376
377
378
379
  		bfa_fcxp_discard(rport->fcxp);
  		/*
  		 * !! fall through !!
  		 */
  	case RPSM_EVENT_FAILED:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
  		if (rport->plogi_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  			rport->plogi_retries++;
  			bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
  			bfa_timer_start(rport->fcs->bfa, &rport->timer,
  					bfa_fcs_rport_timeout, rport,
  					BFA_FCS_RETRY_TIMEOUT);
  		} else {
  			bfa_stats(rport->port, rport_del_max_plogi_retry);
  			rport->pid = 0;
  			bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  			bfa_timer_start(rport->fcs->bfa, &rport->timer,
  					bfa_fcs_rport_timeout, rport,
  					bfa_fcs_rport_del_timeout);
  		}
  		break;
  
  	case	RPSM_EVENT_PLOGI_RETRY:
  		rport->plogi_retries = 0;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
398
399
400
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
  		bfa_timer_start(rport->fcs->bfa, &rport->timer,
  				bfa_fcs_rport_timeout, rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
401
  				(FC_RA_TOV * 1000));
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
402
403
404
405
406
407
408
409
410
411
412
413
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  		rport->pid = 0;
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_timer_start(rport->fcs->bfa, &rport->timer,
  				bfa_fcs_rport_timeout, rport,
  				bfa_fcs_rport_del_timeout);
  		break;
  
  	case RPSM_EVENT_ADDRESS_CHANGE:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
414
  	case RPSM_EVENT_SCN:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
415
416
417
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  		rport->ns_retries = 0;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
418
  		bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
419
420
421
422
423
424
425
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_send_plogiacc(rport, NULL);
  		break;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
426
427
428
429
430
431
432
433
434
435
436
437
438
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_free(rport);
  		break;
  
  	case RPSM_EVENT_PLOGI_COMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_hal_online(rport);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
439
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
440
441
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
442
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
443
444
   *		PLOGI is complete. Awaiting BFA rport online callback. FC-4s
   *		are offline.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
445
446
447
448
449
450
451
452
453
454
455
456
457
458
   */
  static void
  bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
  			enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_HCB_ONLINE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
  		bfa_fcs_rport_online_action(rport);
  		break;
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
459
  	case RPSM_EVENT_PRLO_RCVD:
d7be54cc5   Krishna Gudipati   [SCSI] bfa: FCS b...
460
  	case RPSM_EVENT_PLOGI_COMP:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
461
  		break;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
462
463
  	case RPSM_EVENT_LOGO_RCVD:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
464
  		bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
465
466
467
468
469
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
470
  		bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
471
472
473
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
d7be54cc5   Krishna Gudipati   [SCSI] bfa: FCS b...
474
475
  		rport->plogi_pending = BFA_TRUE;
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
476
  		bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
477
478
479
480
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
481
  		bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
482
483
484
  		break;
  
  	case RPSM_EVENT_SCN:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
485
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
486
487
488
489
490
491
492
  		 * @todo
  		 * Ignore SCN - PLOGI just completed, FC-4 login should detect
  		 * device failures.
  		 */
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
493
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
494
495
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
496
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
497
   *		Rport is ONLINE. FC-4s active.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
498
499
500
501
502
503
504
505
506
507
   */
  static void
  bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport, enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_SCN:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
508
509
510
511
  		if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  			bfa_sm_set_state(rport,
  					 bfa_fcs_rport_sm_nsquery_sending);
  			rport->ns_retries = 0;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
512
  			bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
  		} else {
  			bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
  			bfa_fcs_rport_send_adisc(rport, NULL);
  		}
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  	case RPSM_EVENT_LOGO_IMP:
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
532
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
533
534
535
536
537
538
539
540
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_PLOGI_COMP:
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
541
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
542
543
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
544
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
545
546
   *		An SCN event is received in ONLINE state. NS query is being sent
   *		prior to ADISC authentication with rport. FC-4s are paused.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
547
548
549
   */
  static void
  bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
550
  	 enum rport_event event)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_FCXP_SENT:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsquery);
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_SCN:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
568
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
569
570
571
572
573
  		 * ignore SCN, wait for response to query itself
  		 */
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
574
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  		rport->pid = 0;
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_timer_start(rport->fcs->bfa, &rport->timer,
  				bfa_fcs_rport_timeout, rport,
  				bfa_fcs_rport_del_timeout);
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  	case RPSM_EVENT_ADDRESS_CHANGE:
  	case RPSM_EVENT_PLOGI_COMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
598
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
599
600
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
601
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
602
603
   *	An SCN event is received in ONLINE state. NS query is sent to rport.
   *	FC-4s are paused.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
   */
  static void
  bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_ACCEPTED:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
  		bfa_fcs_rport_send_adisc(rport, NULL);
  		break;
  
  	case RPSM_EVENT_FAILED:
  		rport->ns_retries++;
  		if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  			bfa_sm_set_state(rport,
  					 bfa_fcs_rport_sm_nsquery_sending);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
623
  			bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
  		} else {
  			bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  			bfa_fcs_rport_offline_action(rport);
  		}
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_SCN:
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
640
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_PLOGI_COMP:
  	case RPSM_EVENT_ADDRESS_CHANGE:
  	case RPSM_EVENT_PLOGI_RCVD:
  	case RPSM_EVENT_LOGO_IMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
656
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
657
658
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
659
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
660
661
   *	An SCN event is received in ONLINE state. ADISC is being sent for
   *	authenticating with rport. FC-4s are paused.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
662
663
664
   */
  static void
  bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
665
  	 enum rport_event event)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_FCXP_SENT:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc);
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
690
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_SCN:
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
706
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
707
708
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
709
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
710
711
   *		An SCN event is received in ONLINE state. ADISC is to rport.
   *		FC-4s are paused.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
712
713
714
715
716
717
718
719
720
721
722
   */
  static void
  bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport, enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_ACCEPTED:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
723
724
725
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
726
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
  		 * Too complex to cleanup FC-4 & rport and then acc to PLOGI.
  		 * At least go offline when a PLOGI is received.
  		 */
  		bfa_fcxp_discard(rport->fcxp);
  		/*
  		 * !!! fall through !!!
  		 */
  
  	case RPSM_EVENT_FAILED:
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_SCN:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
748
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
749
750
751
752
753
754
755
756
757
758
759
  		 * already processing RSCN
  		 */
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
760
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
761
762
763
764
765
766
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_offline_action(rport);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
767
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
768
769
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
770
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
771
   *		Rport has sent LOGO. Awaiting FC-4 offline completion callback.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
772
773
774
775
776
777
778
779
780
781
782
783
   */
  static void
  bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
  			enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_FC4_OFFLINE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
784
  		bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
785
786
787
788
789
790
791
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
792
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
793
794
795
796
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
797
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
798
799
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
800
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
801
802
   *		LOGO needs to be sent to rport. Awaiting FC-4 offline completion
   *		callback.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
803
804
805
   */
  static void
  bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
806
  	 enum rport_event event)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
807
808
809
810
811
812
813
814
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_FC4_OFFLINE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
815
  		bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
816
817
818
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
819
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
820
821
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
822
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
823
   *	Rport is going offline. Awaiting FC-4 offline completion callback.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
824
825
826
827
828
829
830
831
832
833
834
835
   */
  static void
  bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
  			enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_FC4_OFFLINE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
836
  		bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
837
838
839
840
841
  		break;
  
  	case RPSM_EVENT_SCN:
  	case RPSM_EVENT_LOGO_IMP:
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
842
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
843
  	case RPSM_EVENT_ADDRESS_CHANGE:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
844
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
845
846
847
848
849
850
851
852
853
854
  		 * rport is already going offline.
  		 * SCN - ignore and wait till transitioning to offline state
  		 */
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
855
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
856
857
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
858
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
859
860
   *		Rport is offline. FC-4s are offline. Awaiting BFA rport offline
   *		callback.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
861
862
863
   */
  static void
  bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
864
  				enum rport_event event)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
865
866
867
868
869
870
871
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_HCB_OFFLINE:
d7be54cc5   Krishna Gudipati   [SCSI] bfa: FCS b...
872
873
874
875
876
877
878
879
880
881
882
  		if (bfa_fcs_lport_is_online(rport->port) &&
  		    (rport->plogi_pending)) {
  			rport->plogi_pending = BFA_FALSE;
  			bfa_sm_set_state(rport,
  				bfa_fcs_rport_sm_plogiacc_sending);
  			bfa_fcs_rport_send_plogiacc(rport, NULL);
  			break;
  		}
  		/*
  		 * !! fall through !!
  		 */
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
883
  	case RPSM_EVENT_ADDRESS_CHANGE:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
884
  		if (bfa_fcs_lport_is_online(rport->port)) {
72041ed8f   Krishna Gudipati   [SCSI] bfa: RPORT...
885
886
887
888
  			if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  				bfa_sm_set_state(rport,
  					bfa_fcs_rport_sm_nsdisc_sending);
  				rport->ns_retries = 0;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
889
  				bfa_fcs_rport_send_nsdisc(rport, NULL);
72041ed8f   Krishna Gudipati   [SCSI] bfa: RPORT...
890
891
892
893
894
895
  			} else {
  				bfa_sm_set_state(rport,
  					bfa_fcs_rport_sm_plogi_sending);
  				rport->plogi_retries = 0;
  				bfa_fcs_rport_send_plogi(rport, NULL);
  			}
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
  		} else {
  			rport->pid = 0;
  			bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  			bfa_timer_start(rport->fcs->bfa, &rport->timer,
  					bfa_fcs_rport_timeout, rport,
  					bfa_fcs_rport_del_timeout);
  		}
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_fcs_rport_free(rport);
  		break;
  
  	case RPSM_EVENT_SCN:
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
912
  	case RPSM_EVENT_PRLO_RCVD:
d7be54cc5   Krishna Gudipati   [SCSI] bfa: FCS b...
913
914
  	case RPSM_EVENT_PLOGI_RCVD:
  	case RPSM_EVENT_LOGO_IMP:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
915
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
916
917
918
919
920
  		 * Ignore, already offline.
  		 */
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
921
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
922
923
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
924
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
925
926
   *		Rport is offline. FC-4s are offline. Awaiting BFA rport offline
   *		callback to send LOGO accept.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
927
928
929
930
931
932
933
934
935
936
937
938
   */
  static void
  bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
  			enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_HCB_OFFLINE:
  	case RPSM_EVENT_ADDRESS_CHANGE:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
939
940
941
  		if (rport->pid && (rport->prlo == BFA_TRUE))
  			bfa_fcs_rport_send_prlo_acc(rport);
  		if (rport->pid && (rport->prlo == BFA_FALSE))
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
942
943
  			bfa_fcs_rport_send_logo_acc(rport);
  		/*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
944
945
946
  		 * If the lport is online and if the rport is not a well
  		 * known address port,
  		 * we try to re-discover the r-port.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
947
  		 */
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
948
949
  		if (bfa_fcs_lport_is_online(rport->port) &&
  			(!BFA_FCS_PID_IS_WKA(rport->pid))) {
d7be54cc5   Krishna Gudipati   [SCSI] bfa: FCS b...
950
951
952
953
954
955
956
957
958
959
960
961
  			if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  				bfa_sm_set_state(rport,
  					bfa_fcs_rport_sm_nsdisc_sending);
  				rport->ns_retries = 0;
  				bfa_fcs_rport_send_nsdisc(rport, NULL);
  			} else {
  				/* For N2N  Direct Attach, try to re-login */
  				bfa_sm_set_state(rport,
  					bfa_fcs_rport_sm_plogi_sending);
  				rport->plogi_retries = 0;
  				bfa_fcs_rport_send_plogi(rport, NULL);
  			}
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
962
963
  		} else {
  			/*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
964
965
  			 * if it is not a well known address, reset the
  			 * pid to 0.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
  			 */
  			if (!BFA_FCS_PID_IS_WKA(rport->pid))
  				rport->pid = 0;
  			bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  			bfa_timer_start(rport->fcs->bfa, &rport->timer,
  					bfa_fcs_rport_timeout, rport,
  					bfa_fcs_rport_del_timeout);
  		}
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
985
  	case RPSM_EVENT_PRLO_RCVD:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
986
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
987
988
989
990
991
  		 * Ignore - already processing a LOGO.
  		 */
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
992
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
993
994
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
995
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
996
997
998
   *		Rport is being deleted. FC-4s are offline.
   *  Awaiting BFA rport offline
   *		callback to send LOGO.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
999
1000
1001
   */
  static void
  bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1002
  		 enum rport_event event)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_HCB_OFFLINE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_logo_sending);
  		bfa_fcs_rport_send_logo(rport, NULL);
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
1015
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1016
1017
1018
1019
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
1020
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1021
1022
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1023
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1024
   *		Rport is being deleted. FC-4s are offline. LOGO is being sent.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1025
1026
1027
   */
  static void
  bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1028
  	 enum rport_event event)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1029
1030
1031
1032
1033
1034
1035
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_FCXP_SENT:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1036
  		/* Once LOGO is sent, we donot wait for the response */
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1037
1038
1039
1040
1041
1042
1043
1044
1045
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_fcs_rport_free(rport);
  		break;
  
  	case RPSM_EVENT_SCN:
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
1046
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1047
1048
1049
1050
1051
1052
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_free(rport);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
1053
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1054
1055
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1056
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1057
1058
   *		Rport is offline. FC-4s are offline. BFA rport is offline.
   *		Timer active to delete stale rport.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
   */
  static void
  bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport, enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_TIMEOUT:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_fcs_rport_free(rport);
  		break;
  
  	case RPSM_EVENT_SCN:
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  		bfa_timer_stop(&rport->timer);
  		rport->ns_retries = 0;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1078
  		bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_timer_stop(&rport->timer);
  		bfa_fcs_rport_free(rport);
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  		bfa_timer_stop(&rport->timer);
  		bfa_fcs_rport_send_plogiacc(rport, NULL);
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
1094
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
  	case RPSM_EVENT_LOGO_IMP:
  		break;
  
  	case RPSM_EVENT_PLOGI_COMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  		bfa_timer_stop(&rport->timer);
  		bfa_fcs_rport_hal_online(rport);
  		break;
  
  	case RPSM_EVENT_PLOGI_SEND:
  		bfa_timer_stop(&rport->timer);
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  		rport->plogi_retries = 0;
  		bfa_fcs_rport_send_plogi(rport, NULL);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
1112
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1113
1114
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1115
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1116
   *	Rport address has changed. Nameserver discovery request is being sent.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1117
1118
1119
   */
  static void
  bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1120
  	 enum rport_event event)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_FCXP_SENT:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sent);
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_free(rport);
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_send_plogiacc(rport, NULL);
  		break;
  
  	case RPSM_EVENT_SCN:
  	case RPSM_EVENT_LOGO_RCVD:
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
1145
  	case RPSM_EVENT_PRLO_RCVD:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1146
1147
1148
1149
  	case RPSM_EVENT_PLOGI_SEND:
  		break;
  
  	case RPSM_EVENT_ADDRESS_CHANGE:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1150
  		rport->ns_retries = 0; /* reset the retry count */
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_timer_start(rport->fcs->bfa, &rport->timer,
  				bfa_fcs_rport_timeout, rport,
  				bfa_fcs_rport_del_timeout);
  		break;
  
  	case RPSM_EVENT_PLOGI_COMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  		bfa_fcs_rport_hal_online(rport);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
1168
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1169
1170
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1171
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1172
   *		Nameserver discovery failed. Waiting for timeout to retry.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1173
1174
1175
   */
  static void
  bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1176
  	 enum rport_event event)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1177
1178
1179
1180
1181
1182
1183
1184
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_TIMEOUT:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1185
  		bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1186
1187
1188
1189
1190
1191
1192
  		break;
  
  	case RPSM_EVENT_SCN:
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  		bfa_timer_stop(&rport->timer);
  		rport->ns_retries = 0;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1193
  		bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_timer_stop(&rport->timer);
  		bfa_fcs_rport_free(rport);
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  		bfa_timer_stop(&rport->timer);
  		bfa_fcs_rport_send_plogiacc(rport, NULL);
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  		rport->pid = 0;
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  		bfa_timer_stop(&rport->timer);
  		bfa_timer_start(rport->fcs->bfa, &rport->timer,
  				bfa_fcs_rport_timeout, rport,
  				bfa_fcs_rport_del_timeout);
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
  		bfa_fcs_rport_send_logo_acc(rport);
  		break;
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
1220
1221
1222
  	case RPSM_EVENT_PRLO_RCVD:
  		bfa_fcs_rport_send_prlo_acc(rport);
  		break;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1223
1224
1225
1226
1227
1228
1229
  	case RPSM_EVENT_PLOGI_COMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  		bfa_timer_stop(&rport->timer);
  		bfa_fcs_rport_hal_online(rport);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
1230
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1231
1232
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1233
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1234
   *		Rport address has changed. Nameserver discovery request is sent.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
   */
  static void
  bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
  			enum rport_event event)
  {
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPSM_EVENT_ACCEPTED:
  	case RPSM_EVENT_ADDRESS_CHANGE:
  		if (rport->pid) {
  			bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  			bfa_fcs_rport_send_plogi(rport, NULL);
  		} else {
  			bfa_sm_set_state(rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1252
  				 bfa_fcs_rport_sm_nsdisc_sending);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1253
  			rport->ns_retries = 0;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1254
  			bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1255
1256
1257
1258
1259
1260
1261
  		}
  		break;
  
  	case RPSM_EVENT_FAILED:
  		rport->ns_retries++;
  		if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  			bfa_sm_set_state(rport,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1262
1263
  				 bfa_fcs_rport_sm_nsdisc_sending);
  			bfa_fcs_rport_send_nsdisc(rport, NULL);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
  		} else {
  			rport->pid = 0;
  			bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  			bfa_timer_start(rport->fcs->bfa, &rport->timer,
  					bfa_fcs_rport_timeout, rport,
  					bfa_fcs_rport_del_timeout);
  		};
  		break;
  
  	case RPSM_EVENT_DELETE:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_free(rport);
  		break;
  
  	case RPSM_EVENT_PLOGI_RCVD:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_send_plogiacc(rport, NULL);
  		break;
  
  	case RPSM_EVENT_LOGO_IMP:
  		rport->pid = 0;
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_timer_start(rport->fcs->bfa, &rport->timer,
  				bfa_fcs_rport_timeout, rport,
  				bfa_fcs_rport_del_timeout);
  		break;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1293

4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
1294
1295
1296
  	case RPSM_EVENT_PRLO_RCVD:
  		bfa_fcs_rport_send_prlo_acc(rport);
  		break;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1297
  	case RPSM_EVENT_SCN:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1298
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1299
1300
1301
1302
1303
  		 * ignore, wait for NS query response
  		 */
  		break;
  
  	case RPSM_EVENT_LOGO_RCVD:
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1304
  		/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
  		 * Not logged-in yet. Accept LOGO.
  		 */
  		bfa_fcs_rport_send_logo_acc(rport);
  		break;
  
  	case RPSM_EVENT_PLOGI_COMP:
  		bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  		bfa_fcxp_discard(rport->fcxp);
  		bfa_fcs_rport_hal_online(rport);
  		break;
  
  	default:
e641de37e   Krishna Gudipati   [SCSI] bfa: Repla...
1317
  		bfa_sm_fault(rport->fcs, event);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1318
1319
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1320
  /*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1321
1322
1323
1324
1325
1326
1327
   *  fcs_rport_private FCS RPORT provate functions
   */
  
  static void
  bfa_fcs_rport_send_plogi(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  {
  	struct bfa_fcs_rport_s *rport = rport_cbarg;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1328
1329
1330
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct fchs_s	fchs;
  	int		len;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1331
1332
1333
1334
1335
1336
  	struct bfa_fcxp_s *fcxp;
  
  	bfa_trc(rport->fcs, rport->pwwn);
  
  	fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  	if (!fcxp) {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1337
1338
  		bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  					bfa_fcs_rport_send_plogi, rport);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1339
1340
1341
1342
1343
  		return;
  	}
  	rport->fcxp = fcxp;
  
  	len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1344
1345
  				bfa_fcs_lport_get_fcid(port), 0,
  				port->port_cfg.pwwn, port->port_cfg.nwwn,
be540a991   Krishna Gudipati   [SCSI] bfa: FC cr...
1346
1347
  				bfa_fcport_get_maxfrsize(port->fcs->bfa),
  				bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1348
1349
  
  	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1350
1351
  			FC_CLASS_3, len, &fchs, bfa_fcs_rport_plogi_response,
  			(void *)rport, FC_MAX_PDUSZ, FC_ELS_TOV);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1352
1353
1354
1355
1356
1357
1358
  
  	rport->stats.plogis++;
  	bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  }
  
  static void
  bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1359
1360
  				bfa_status_t req_status, u32 rsp_len,
  				u32 resid_len, struct fchs_s *rsp_fchs)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1361
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1362
  	struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1363
1364
1365
  	struct fc_logi_s	*plogi_rsp;
  	struct fc_ls_rjt_s	*ls_rjt;
  	struct bfa_fcs_rport_s *twin;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1366
  	struct list_head	*qe;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
  
  	bfa_trc(rport->fcs, rport->pwwn);
  
  	/*
  	 * Sanity Checks
  	 */
  	if (req_status != BFA_STATUS_OK) {
  		bfa_trc(rport->fcs, req_status);
  		rport->stats.plogi_failed++;
  		bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  		return;
  	}
  
  	plogi_rsp = (struct fc_logi_s *) BFA_FCXP_RSP_PLD(fcxp);
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1381
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1382
1383
1384
1385
1386
1387
1388
  	 * Check for failure first.
  	 */
  	if (plogi_rsp->els_cmd.els_code != FC_ELS_ACC) {
  		ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  
  		bfa_trc(rport->fcs, ls_rjt->reason_code);
  		bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1389
1390
1391
1392
1393
1394
  		if ((ls_rjt->reason_code == FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD) &&
  		 (ls_rjt->reason_code_expl == FC_LS_RJT_EXP_INSUFF_RES)) {
  			rport->stats.rjt_insuff_res++;
  			bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RETRY);
  			return;
  		}
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1395
1396
1397
1398
  		rport->stats.plogi_rejects++;
  		bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  		return;
  	}
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1399
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1400
1401
1402
1403
  	 * PLOGI is complete. Make sure this device is not one of the known
  	 * device with a new FC port address.
  	 */
  	list_for_each(qe, &rport->port->rport_q) {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1404
  		twin = (struct bfa_fcs_rport_s *) qe;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1405
1406
1407
1408
1409
  		if (twin == rport)
  			continue;
  		if (!rport->pwwn && (plogi_rsp->port_name == twin->pwwn)) {
  			bfa_trc(rport->fcs, twin->pid);
  			bfa_trc(rport->fcs, rport->pid);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1410
1411
1412
1413
1414
1415
1416
1417
1418
  			/* Update plogi stats in twin */
  			twin->stats.plogis  += rport->stats.plogis;
  			twin->stats.plogi_rejects  +=
  				 rport->stats.plogi_rejects;
  			twin->stats.plogi_timeouts  +=
  				 rport->stats.plogi_timeouts;
  			twin->stats.plogi_failed +=
  				 rport->stats.plogi_failed;
  			twin->stats.plogi_rcvd	  += rport->stats.plogi_rcvd;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1419
  			twin->stats.plogi_accs++;
f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
1420
  			bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1421
1422
1423
1424
1425
1426
1427
  
  			bfa_fcs_rport_update(twin, plogi_rsp);
  			twin->pid = rsp_fchs->s_id;
  			bfa_sm_send_event(twin, RPSM_EVENT_PLOGI_COMP);
  			return;
  		}
  	}
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1428
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
  	 * Normal login path -- no evil twins.
  	 */
  	rport->stats.plogi_accs++;
  	bfa_fcs_rport_update(rport, plogi_rsp);
  	bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  }
  
  static void
  bfa_fcs_rport_send_plogiacc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  {
  	struct bfa_fcs_rport_s *rport = rport_cbarg;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1440
1441
1442
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct fchs_s		fchs;
  	int		len;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1443
1444
1445
1446
1447
1448
1449
  	struct bfa_fcxp_s *fcxp;
  
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->reply_oxid);
  
  	fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  	if (!fcxp) {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1450
1451
  		bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  					bfa_fcs_rport_send_plogiacc, rport);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1452
1453
1454
  		return;
  	}
  	rport->fcxp = fcxp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1455
1456
1457
1458
  	len = fc_plogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  				 rport->pid, bfa_fcs_lport_get_fcid(port),
  				 rport->reply_oxid, port->port_cfg.pwwn,
  				 port->port_cfg.nwwn,
be540a991   Krishna Gudipati   [SCSI] bfa: FC cr...
1459
1460
  				 bfa_fcport_get_maxfrsize(port->fcs->bfa),
  				 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1461
1462
  
  	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1463
  			FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1464
1465
1466
1467
1468
1469
1470
1471
  
  	bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  }
  
  static void
  bfa_fcs_rport_send_adisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  {
  	struct bfa_fcs_rport_s *rport = rport_cbarg;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1472
1473
1474
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct fchs_s		fchs;
  	int		len;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1475
1476
1477
1478
1479
1480
  	struct bfa_fcxp_s *fcxp;
  
  	bfa_trc(rport->fcs, rport->pwwn);
  
  	fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  	if (!fcxp) {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1481
1482
  		bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  					bfa_fcs_rport_send_adisc, rport);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1483
1484
1485
1486
1487
  		return;
  	}
  	rport->fcxp = fcxp;
  
  	len = fc_adisc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1488
1489
  				bfa_fcs_lport_get_fcid(port), 0,
  				port->port_cfg.pwwn, port->port_cfg.nwwn);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1490
1491
  
  	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1492
1493
  			FC_CLASS_3, len, &fchs, bfa_fcs_rport_adisc_response,
  			rport, FC_MAX_PDUSZ, FC_ELS_TOV);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1494
1495
1496
1497
1498
1499
1500
  
  	rport->stats.adisc_sent++;
  	bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  }
  
  static void
  bfa_fcs_rport_adisc_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1501
1502
  				bfa_status_t req_status, u32 rsp_len,
  				u32 resid_len, struct fchs_s *rsp_fchs)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1503
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1504
1505
1506
  	struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  	void		*pld = bfa_fcxp_get_rspbuf(fcxp);
  	struct fc_ls_rjt_s	*ls_rjt;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1507
1508
1509
1510
1511
1512
1513
1514
1515
  
  	if (req_status != BFA_STATUS_OK) {
  		bfa_trc(rport->fcs, req_status);
  		rport->stats.adisc_failed++;
  		bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  		return;
  	}
  
  	if (fc_adisc_rsp_parse((struct fc_adisc_s *)pld, rsp_len, rport->pwwn,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1516
  				rport->nwwn)  == FC_PARSE_OK) {
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
  		rport->stats.adisc_accs++;
  		bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  		return;
  	}
  
  	rport->stats.adisc_rejects++;
  	ls_rjt = pld;
  	bfa_trc(rport->fcs, ls_rjt->els_cmd.els_code);
  	bfa_trc(rport->fcs, ls_rjt->reason_code);
  	bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
  	bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  }
  
  static void
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1531
  bfa_fcs_rport_send_nsdisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1532
1533
  {
  	struct bfa_fcs_rport_s *rport = rport_cbarg;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1534
1535
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct fchs_s	fchs;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1536
  	struct bfa_fcxp_s *fcxp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1537
1538
  	int		len;
  	bfa_cb_fcxp_send_t cbfn;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1539
1540
1541
1542
1543
  
  	bfa_trc(rport->fcs, rport->pid);
  
  	fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  	if (!fcxp) {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1544
1545
  		bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  					bfa_fcs_rport_send_nsdisc, rport);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1546
1547
1548
  		return;
  	}
  	rport->fcxp = fcxp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1549
1550
1551
1552
1553
1554
1555
1556
1557
  	if (rport->pwwn) {
  		len = fc_gidpn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  				bfa_fcs_lport_get_fcid(port), 0, rport->pwwn);
  		cbfn = bfa_fcs_rport_gidpn_response;
  	} else {
  		len = fc_gpnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  				bfa_fcs_lport_get_fcid(port), 0, rport->pid);
  		cbfn = bfa_fcs_rport_gpnid_response;
  	}
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1558
1559
  
  	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1560
1561
  			FC_CLASS_3, len, &fchs, cbfn,
  			(void *)rport, FC_MAX_PDUSZ, FC_FCCT_TOV);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1562
1563
1564
1565
1566
1567
  
  	bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  }
  
  static void
  bfa_fcs_rport_gidpn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1568
1569
  				bfa_status_t req_status, u32 rsp_len,
  				u32 resid_len, struct fchs_s *rsp_fchs)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1570
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1571
1572
  	struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  	struct ct_hdr_s	*cthdr;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1573
  	struct fcgs_gidpn_resp_s	*gidpn_rsp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1574
1575
  	struct bfa_fcs_rport_s	*twin;
  	struct list_head	*qe;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1576
1577
1578
1579
  
  	bfa_trc(rport->fcs, rport->pwwn);
  
  	cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
ba816ea8e   Jing Huang   [SCSI] bfa: repla...
1580
  	cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1581
1582
  
  	if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1583
  		/* Check if the pid is the same as before. */
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1584
1585
1586
  		gidpn_rsp = (struct fcgs_gidpn_resp_s *) (cthdr + 1);
  
  		if (gidpn_rsp->dap == rport->pid) {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1587
  			/* Device is online  */
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1588
1589
1590
  			bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  		} else {
  			/*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1591
1592
1593
1594
  			 * Device's PID has changed. We need to cleanup
  			 * and re-login. If there is another device with
  			 * the the newly discovered pid, send an scn notice
  			 * so that its new pid can be discovered.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1595
1596
  			 */
  			list_for_each(qe, &rport->port->rport_q) {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1597
  				twin = (struct bfa_fcs_rport_s *) qe;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1598
1599
1600
1601
1602
1603
1604
1605
  				if (twin == rport)
  					continue;
  				if (gidpn_rsp->dap == twin->pid) {
  					bfa_trc(rport->fcs, twin->pid);
  					bfa_trc(rport->fcs, rport->pid);
  
  					twin->pid = 0;
  					bfa_sm_send_event(twin,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1606
  					 RPSM_EVENT_ADDRESS_CHANGE);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
  				}
  			}
  			rport->pid = gidpn_rsp->dap;
  			bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_CHANGE);
  		}
  		return;
  	}
  
  	/*
  	 * Reject Response
  	 */
  	switch (cthdr->reason_code) {
  	case CT_RSN_LOGICAL_BUSY:
  		/*
  		 * Need to retry
  		 */
  		bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
  		break;
  
  	case CT_RSN_UNABLE_TO_PERF:
  		/*
  		 * device doesn't exist : Start timer to cleanup this later.
  		 */
  		bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  		break;
  
  	default:
  		bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  		break;
  	}
  }
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
  static void
  bfa_fcs_rport_gpnid_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  				bfa_status_t req_status, u32 rsp_len,
  				u32 resid_len, struct fchs_s *rsp_fchs)
  {
  	struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
  	struct ct_hdr_s	*cthdr;
  
  	bfa_trc(rport->fcs, rport->pwwn);
  
  	cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
ba816ea8e   Jing Huang   [SCSI] bfa: repla...
1649
  	cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
  
  	if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  		bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  		return;
  	}
  
  	/*
  	 * Reject Response
  	 */
  	switch (cthdr->reason_code) {
  	case CT_RSN_LOGICAL_BUSY:
  		/*
  		 * Need to retry
  		 */
  		bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
  		break;
  
  	case CT_RSN_UNABLE_TO_PERF:
  		/*
  		 * device doesn't exist : Start timer to cleanup this later.
  		 */
  		bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  		break;
  
  	default:
  		bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  		break;
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1679
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1680
   *	Called to send a logout to the rport.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1681
1682
1683
1684
1685
   */
  static void
  bfa_fcs_rport_send_logo(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  {
  	struct bfa_fcs_rport_s *rport = rport_cbarg;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1686
1687
  	struct bfa_fcs_lport_s *port;
  	struct fchs_s	fchs;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1688
  	struct bfa_fcxp_s *fcxp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1689
  	u16	len;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1690
1691
1692
1693
1694
1695
1696
  
  	bfa_trc(rport->fcs, rport->pid);
  
  	port = rport->port;
  
  	fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  	if (!fcxp) {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1697
1698
  		bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  					bfa_fcs_rport_send_logo, rport);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1699
1700
1701
1702
1703
  		return;
  	}
  	rport->fcxp = fcxp;
  
  	len = fc_logo_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1704
1705
  				bfa_fcs_lport_get_fcid(port), 0,
  				bfa_fcs_lport_get_pwwn(port));
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1706
1707
  
  	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1708
1709
  			FC_CLASS_3, len, &fchs, NULL,
  			rport, FC_MAX_PDUSZ, FC_ELS_TOV);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1710
1711
1712
1713
1714
  
  	rport->stats.logos++;
  	bfa_fcxp_discard(rport->fcxp);
  	bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1715
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1716
   *	Send ACC for a LOGO received.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1717
1718
1719
1720
1721
   */
  static void
  bfa_fcs_rport_send_logo_acc(void *rport_cbarg)
  {
  	struct bfa_fcs_rport_s *rport = rport_cbarg;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1722
1723
  	struct bfa_fcs_lport_s *port;
  	struct fchs_s	fchs;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1724
  	struct bfa_fcxp_s *fcxp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1725
  	u16	len;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
  
  	bfa_trc(rport->fcs, rport->pid);
  
  	port = rport->port;
  
  	fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  	if (!fcxp)
  		return;
  
  	rport->stats.logo_rcvd++;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1736
1737
1738
  	len = fc_logo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  				rport->pid, bfa_fcs_lport_get_fcid(port),
  				rport->reply_oxid);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1739
1740
  
  	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1741
  			FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1742
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1743
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1744
1745
   *	brief
   *	This routine will be called by bfa_timer on timer timeouts.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1746
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1747
1748
   *	param[in]	rport			- pointer to bfa_fcs_lport_ns_t.
   *	param[out]	rport_status	- pointer to return vport status in
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1749
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1750
1751
   *	return
   *		void
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1752
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1753
   *	Special Considerations:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1754
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1755
   *	note
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1756
1757
1758
1759
   */
  static void
  bfa_fcs_rport_timeout(void *arg)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1760
  	struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) arg;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1761
1762
  
  	rport->stats.plogi_timeouts++;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1763
  	bfa_stats(rport->port, rport_plogi_timeouts);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1764
1765
1766
1767
1768
1769
1770
1771
  	bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
  }
  
  static void
  bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
  			struct fchs_s *rx_fchs, u16 len)
  {
  	struct bfa_fcxp_s *fcxp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1772
1773
1774
  	struct fchs_s	fchs;
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct fc_prli_s	*prli;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1775
1776
1777
1778
1779
  
  	bfa_trc(port->fcs, rx_fchs->s_id);
  	bfa_trc(port->fcs, rx_fchs->d_id);
  
  	rport->stats.prli_rcvd++;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1780
  	/*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1781
  	 * We are in Initiator Mode
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1782
1783
  	 */
  	prli = (struct fc_prli_s *) (rx_fchs + 1);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1784
  	if (prli->parampage.servparams.target) {
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1785
  		/*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1786
1787
1788
1789
  		 * PRLI from a target ?
  		 * Send the Acc.
  		 * PRLI sent by us will be used to transition the IT nexus,
  		 * once the response is received from the target.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1790
1791
1792
  		 */
  		bfa_trc(port->fcs, rx_fchs->s_id);
  		rport->scsi_function = BFA_RPORT_TARGET;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1793
1794
1795
1796
  	} else {
  		bfa_trc(rport->fcs, prli->parampage.type);
  		rport->scsi_function = BFA_RPORT_INITIATOR;
  		bfa_fcs_itnim_is_initiator(rport->itnim);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1797
1798
1799
1800
1801
  	}
  
  	fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  	if (!fcxp)
  		return;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1802
1803
1804
  	len = fc_prli_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  				rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  				rx_fchs->ox_id, port->port_cfg.roles);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1805
1806
  
  	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1807
  			FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1808
1809
1810
1811
1812
1813
1814
  }
  
  static void
  bfa_fcs_rport_process_rpsc(struct bfa_fcs_rport_s *rport,
  			struct fchs_s *rx_fchs, u16 len)
  {
  	struct bfa_fcxp_s *fcxp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1815
1816
  	struct fchs_s	fchs;
  	struct bfa_fcs_lport_s *port = rport->port;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1817
  	struct fc_rpsc_speed_info_s speeds;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1818
  	struct bfa_port_attr_s pport_attr;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
  
  	bfa_trc(port->fcs, rx_fchs->s_id);
  	bfa_trc(port->fcs, rx_fchs->d_id);
  
  	rport->stats.rpsc_rcvd++;
  	speeds.port_speed_cap =
  		RPSC_SPEED_CAP_1G | RPSC_SPEED_CAP_2G | RPSC_SPEED_CAP_4G |
  		RPSC_SPEED_CAP_8G;
  
  	/*
  	 * get curent speed from pport attributes from BFA
  	 */
1c8a4c374   Krishna Gudipati   [SCSI] bfa: Renam...
1831
  	bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1832
1833
1834
1835
1836
1837
  
  	speeds.port_op_speed = fc_bfa_speed_to_rpsc_operspeed(pport_attr.speed);
  
  	fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  	if (!fcxp)
  		return;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1838
1839
1840
  	len = fc_rpsc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  				rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  				rx_fchs->ox_id, &speeds);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1841
1842
  
  	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1843
  			FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1844
1845
1846
1847
1848
1849
1850
  }
  
  static void
  bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
  			struct fchs_s *rx_fchs, u16 len)
  {
  	struct bfa_fcxp_s *fcxp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1851
1852
1853
  	struct fchs_s	fchs;
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct fc_adisc_s	*adisc;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1854
1855
1856
1857
1858
  
  	bfa_trc(port->fcs, rx_fchs->s_id);
  	bfa_trc(port->fcs, rx_fchs->d_id);
  
  	rport->stats.adisc_rcvd++;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1859
1860
1861
  	adisc = (struct fc_adisc_s *) (rx_fchs + 1);
  
  	/*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1862
1863
  	 * Accept if the itnim for this rport is online.
  	 * Else reject the ADISC.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1864
1865
1866
1867
1868
1869
1870
1871
  	 */
  	if (bfa_fcs_itnim_get_online_state(rport->itnim) == BFA_STATUS_OK) {
  
  		fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  		if (!fcxp)
  			return;
  
  		len = fc_adisc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1872
1873
1874
  			 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  			 rx_fchs->ox_id, port->port_cfg.pwwn,
  			 port->port_cfg.nwwn);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1875
1876
  
  		bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1877
1878
  				BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  				FC_MAX_PDUSZ, 0);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1879
1880
1881
1882
1883
1884
  	} else {
  		rport->stats.adisc_rejected++;
  		bfa_fcs_rport_send_ls_rjt(rport, rx_fchs,
  					  FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
  					  FC_LS_RJT_EXP_LOGIN_REQUIRED);
  	}
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1885
1886
1887
1888
1889
  }
  
  static void
  bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1890
  	struct bfa_fcs_lport_s *port = rport->port;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
  	struct bfa_rport_info_s rport_info;
  
  	rport_info.pid = rport->pid;
  	rport_info.local_pid = port->pid;
  	rport_info.lp_tag = port->lp_tag;
  	rport_info.vf_id = port->fabric->vf_id;
  	rport_info.vf_en = port->fabric->is_vf;
  	rport_info.fc_class = rport->fc_cos;
  	rport_info.cisc = rport->cisc;
  	rport_info.max_frmsz = rport->maxfrsize;
  	bfa_rport_online(rport->bfa_rport, &rport_info);
  }
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1903
  static struct bfa_fcs_rport_s *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1904
  bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1905
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1906
  	struct bfa_fcs_s	*fcs = port->fcs;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1907
  	struct bfa_fcs_rport_s *rport;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1908
  	struct bfad_rport_s	*rport_drv;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1909

5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1910
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1911
1912
1913
  	 * allocate rport
  	 */
  	if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv)
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1914
  		!= BFA_STATUS_OK) {
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
  		bfa_trc(fcs, rpid);
  		return NULL;
  	}
  
  	/*
  	 * Initialize r-port
  	 */
  	rport->port = port;
  	rport->fcs = fcs;
  	rport->rp_drv = rport_drv;
  	rport->pid = rpid;
  	rport->pwwn = pwwn;
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1927
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1928
1929
1930
1931
1932
1933
1934
1935
  	 * allocate BFA rport
  	 */
  	rport->bfa_rport = bfa_rport_create(port->fcs->bfa, rport);
  	if (!rport->bfa_rport) {
  		bfa_trc(fcs, rpid);
  		kfree(rport_drv);
  		return NULL;
  	}
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1936
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1937
1938
  	 * allocate FC-4s
  	 */
d4b671c58   Jing Huang   [SCSI] bfa: repla...
1939
  	WARN_ON(!bfa_fcs_lport_is_initiator(port));
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1940

a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1941
  	if (bfa_fcs_lport_is_initiator(port)) {
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1942
1943
1944
  		rport->itnim = bfa_fcs_itnim_create(rport);
  		if (!rport->itnim) {
  			bfa_trc(fcs, rpid);
da99dcc98   Maggie Zhang   [SCSI] bfa: remov...
1945
1946
  			bfa_sm_send_event(rport->bfa_rport,
  						BFA_RPORT_SM_DELETE);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1947
1948
1949
1950
  			kfree(rport_drv);
  			return NULL;
  		}
  	}
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1951
  	bfa_fcs_lport_add_rport(port, rport);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1952
1953
  
  	bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1954
  	/* Initialize the Rport Features(RPF) Sub Module  */
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
  	if (!BFA_FCS_PID_IS_WKA(rport->pid))
  		bfa_fcs_rpf_init(rport);
  
  	return rport;
  }
  
  
  static void
  bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1965
  	struct bfa_fcs_lport_s *port = rport->port;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1966

5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
1967
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1968
1969
1970
1971
  	 * - delete FC-4s
  	 * - delete BFA rport
  	 * - remove from queue of rports
  	 */
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1972
  	if (bfa_fcs_lport_is_initiator(port)) {
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1973
  		bfa_fcs_itnim_delete(rport->itnim);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1974
1975
1976
  		if (rport->pid != 0 && !BFA_FCS_PID_IS_WKA(rport->pid))
  			bfa_fcs_rpf_rport_offline(rport);
  	}
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1977

f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
1978
  	bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_DELETE);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
1979
  	bfa_fcs_lport_del_rport(port, rport);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
1980
1981
1982
1983
  	kfree(rport->rp_drv);
  }
  
  static void
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
  bfa_fcs_rport_aen_post(struct bfa_fcs_rport_s *rport,
  			enum bfa_rport_aen_event event,
  			struct bfa_rport_aen_data_s *data)
  {
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  	struct bfa_aen_entry_s  *aen_entry;
  
  	bfad_get_aen_entry(bfad, aen_entry);
  	if (!aen_entry)
  		return;
  
  	if (event == BFA_RPORT_AEN_QOS_PRIO)
  		aen_entry->aen_data.rport.priv.qos = data->priv.qos;
  	else if (event == BFA_RPORT_AEN_QOS_FLOWID)
  		aen_entry->aen_data.rport.priv.qos = data->priv.qos;
  
  	aen_entry->aen_data.rport.vf_id = rport->port->fabric->vf_id;
  	aen_entry->aen_data.rport.ppwwn = bfa_fcs_lport_get_pwwn(
  					bfa_fcs_get_base_port(rport->fcs));
  	aen_entry->aen_data.rport.lpwwn = bfa_fcs_lport_get_pwwn(rport->port);
  	aen_entry->aen_data.rport.rpwwn = rport->pwwn;
  
  	/* Send the AEN notification */
  	bfad_im_post_vendor_event(aen_entry, bfad, ++rport->fcs->fcs_aen_seq,
  				  BFA_AEN_CAT_RPORT, event);
  }
  
  static void
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2013
2014
  bfa_fcs_rport_online_action(struct bfa_fcs_rport_s *rport)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2015
2016
2017
2018
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  	char	lpwwn_buf[BFA_STRING_32];
  	char	rpwwn_buf[BFA_STRING_32];
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2019
2020
  
  	rport->stats.onlines++;
d7be54cc5   Krishna Gudipati   [SCSI] bfa: FCS b...
2021
2022
2023
2024
  	if ((!rport->pid) || (!rport->pwwn)) {
  		bfa_trc(rport->fcs, rport->pid);
  		bfa_sm_fault(rport->fcs, rport->pid);
  	}
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2025
  	if (bfa_fcs_lport_is_initiator(port)) {
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2026
2027
2028
2029
  		bfa_fcs_itnim_rport_online(rport->itnim);
  		if (!BFA_FCS_PID_IS_WKA(rport->pid))
  			bfa_fcs_rpf_rport_online(rport);
  	};
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2030
2031
  	wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
  	wwn2str(rpwwn_buf, rport->pwwn);
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
2032
  	if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
881662422   Jing Huang   [SCSI] bfa: renam...
2033
  		BFA_LOG(KERN_INFO, bfad, bfa_log_level,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2034
2035
2036
  		"Remote port (WWN = %s) online for logical port (WWN = %s)
  ",
  		rpwwn_buf, lpwwn_buf);
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
2037
2038
  		bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_ONLINE, NULL);
  	}
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2039
2040
2041
2042
2043
  }
  
  static void
  bfa_fcs_rport_offline_action(struct bfa_fcs_rport_s *rport)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2044
2045
2046
2047
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  	char	lpwwn_buf[BFA_STRING_32];
  	char	rpwwn_buf[BFA_STRING_32];
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2048
2049
  
  	rport->stats.offlines++;
d7be54cc5   Krishna Gudipati   [SCSI] bfa: FCS b...
2050
  	rport->plogi_pending = BFA_FALSE;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2051

a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2052
2053
  	wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
  	wwn2str(rpwwn_buf, rport->pwwn);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2054
  	if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
2055
  		if (bfa_fcs_lport_is_online(rport->port) == BFA_TRUE) {
881662422   Jing Huang   [SCSI] bfa: renam...
2056
  			BFA_LOG(KERN_ERR, bfad, bfa_log_level,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2057
2058
2059
2060
  				"Remote port (WWN = %s) connectivity lost for "
  				"logical port (WWN = %s)
  ",
  				rpwwn_buf, lpwwn_buf);
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
2061
2062
2063
  			bfa_fcs_rport_aen_post(rport,
  				BFA_RPORT_AEN_DISCONNECT, NULL);
  		} else {
881662422   Jing Huang   [SCSI] bfa: renam...
2064
  			BFA_LOG(KERN_INFO, bfad, bfa_log_level,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2065
2066
2067
2068
  				"Remote port (WWN = %s) offlined by "
  				"logical port (WWN = %s)
  ",
  				rpwwn_buf, lpwwn_buf);
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
2069
2070
2071
  			bfa_fcs_rport_aen_post(rport,
  				BFA_RPORT_AEN_OFFLINE, NULL);
  		}
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2072
  	}
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2073
  	if (bfa_fcs_lport_is_initiator(port)) {
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2074
2075
2076
2077
  		bfa_fcs_itnim_rport_offline(rport->itnim);
  		if (!BFA_FCS_PID_IS_WKA(rport->pid))
  			bfa_fcs_rpf_rport_offline(rport);
  	}
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2078
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2079
  /*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2080
2081
2082
2083
2084
   * Update rport parameters from PLOGI or PLOGI accept.
   */
  static void
  bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2085
  	bfa_fcs_lport_t *port = rport->port;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2086

5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2087
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2088
2089
2090
2091
2092
  	 * - port name
  	 * - node name
  	 */
  	rport->pwwn = plogi->port_name;
  	rport->nwwn = plogi->node_name;
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2093
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2094
2095
2096
2097
2098
2099
2100
2101
  	 * - class of service
  	 */
  	rport->fc_cos = 0;
  	if (plogi->class3.class_valid)
  		rport->fc_cos = FC_CLASS_3;
  
  	if (plogi->class2.class_valid)
  		rport->fc_cos |= FC_CLASS_2;
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2102
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2103
2104
2105
2106
  	 * - CISC
  	 * - MAX receive frame size
  	 */
  	rport->cisc = plogi->csp.cisc;
ba816ea8e   Jing Huang   [SCSI] bfa: repla...
2107
  	rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2108

ba816ea8e   Jing Huang   [SCSI] bfa: repla...
2109
  	bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2110
  	bfa_trc(port->fcs, port->fabric->bb_credit);
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2111
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2112
2113
  	 * Direct Attach P2P mode :
  	 * This is to handle a bug (233476) in IBM targets in Direct Attach
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2114
2115
2116
2117
  	 *  Mode. Basically, in FLOGI Accept the target would have
  	 * erroneously set the BB Credit to the value used in the FLOGI
  	 * sent by the HBA. It uses the correct value (its own BB credit)
  	 * in PLOGI.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2118
  	 */
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2119
  	if ((!bfa_fcs_fabric_is_switched(port->fabric))	 &&
ba816ea8e   Jing Huang   [SCSI] bfa: repla...
2120
  		(be16_to_cpu(plogi->csp.bbcred) < port->fabric->bb_credit)) {
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2121

ba816ea8e   Jing Huang   [SCSI] bfa: repla...
2122
  		bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2123
  		bfa_trc(port->fcs, port->fabric->bb_credit);
ba816ea8e   Jing Huang   [SCSI] bfa: repla...
2124
  		port->fabric->bb_credit = be16_to_cpu(plogi->csp.bbcred);
1c8a4c374   Krishna Gudipati   [SCSI] bfa: Renam...
2125
  		bfa_fcport_set_tx_bbcredit(port->fcs->bfa,
be540a991   Krishna Gudipati   [SCSI] bfa: FC cr...
2126
  					  port->fabric->bb_credit, 0);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2127
2128
2129
  	}
  
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2130
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2131
   *	Called to handle LOGO received from an existing remote port.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2132
2133
2134
2135
2136
2137
   */
  static void
  bfa_fcs_rport_process_logo(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs)
  {
  	rport->reply_oxid = fchs->ox_id;
  	bfa_trc(rport->fcs, rport->reply_oxid);
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
2138
  	rport->prlo = BFA_FALSE;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2139
2140
2141
  	rport->stats.logo_rcvd++;
  	bfa_sm_send_event(rport, RPSM_EVENT_LOGO_RCVD);
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2142
  /*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2143
2144
   *  fcs_rport_public FCS rport public interfaces
   */
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2145
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2146
2147
   *	Called by bport/vport to create a remote port instance for a discovered
   *	remote device.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2148
2149
2150
2151
2152
2153
2154
   *
   * @param[in] port	- base port or vport
   * @param[in] rpid	- remote port ID
   *
   * @return None
   */
  struct bfa_fcs_rport_s *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2155
  bfa_fcs_rport_create(struct bfa_fcs_lport_s *port, u32 rpid)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
  {
  	struct bfa_fcs_rport_s *rport;
  
  	bfa_trc(port->fcs, rpid);
  	rport = bfa_fcs_rport_alloc(port, WWN_NULL, rpid);
  	if (!rport)
  		return NULL;
  
  	bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
  	return rport;
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2167
  /*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2168
2169
2170
2171
2172
2173
2174
2175
   * Called to create a rport for which only the wwn is known.
   *
   * @param[in] port	- base port
   * @param[in] rpwwn	- remote port wwn
   *
   * @return None
   */
  struct bfa_fcs_rport_s *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2176
  bfa_fcs_rport_create_by_wwn(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2177
2178
  {
  	struct bfa_fcs_rport_s *rport;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2179
2180
2181
2182
2183
2184
2185
2186
  	bfa_trc(port->fcs, rpwwn);
  	rport = bfa_fcs_rport_alloc(port, rpwwn, 0);
  	if (!rport)
  		return NULL;
  
  	bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC);
  	return rport;
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2187
  /*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2188
2189
2190
2191
2192
2193
2194
   * Called by bport in private loop topology to indicate that a
   * rport has been discovered and plogi has been completed.
   *
   * @param[in] port	- base port or vport
   * @param[in] rpid	- remote port ID
   */
  void
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2195
2196
  bfa_fcs_rport_start(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
  	 struct fc_logi_s *plogi)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
  {
  	struct bfa_fcs_rport_s *rport;
  
  	rport = bfa_fcs_rport_alloc(port, WWN_NULL, fchs->s_id);
  	if (!rport)
  		return;
  
  	bfa_fcs_rport_update(rport, plogi);
  
  	bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP);
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2208
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2209
2210
   *	Called by bport/vport to handle PLOGI received from a new remote port.
   *	If an existing rport does a plogi, it will be handled separately.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2211
2212
   */
  void
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2213
2214
  bfa_fcs_rport_plogi_create(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
  				struct fc_logi_s *plogi)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
  {
  	struct bfa_fcs_rport_s *rport;
  
  	rport = bfa_fcs_rport_alloc(port, plogi->port_name, fchs->s_id);
  	if (!rport)
  		return;
  
  	bfa_fcs_rport_update(rport, plogi);
  
  	rport->reply_oxid = fchs->ox_id;
  	bfa_trc(rport->fcs, rport->reply_oxid);
  
  	rport->stats.plogi_rcvd++;
  	bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2230
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2231
2232
   *	Called by bport/vport to handle PLOGI received from an existing
   *	 remote port.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2233
2234
2235
   */
  void
  bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2236
  			struct fc_logi_s *plogi)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2237
  {
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2238
  	/*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2239
2240
2241
2242
2243
2244
2245
  	 * @todo Handle P2P and initiator-initiator.
  	 */
  
  	bfa_fcs_rport_update(rport, plogi);
  
  	rport->reply_oxid = rx_fchs->ox_id;
  	bfa_trc(rport->fcs, rport->reply_oxid);
d7be54cc5   Krishna Gudipati   [SCSI] bfa: FCS b...
2246
2247
  	rport->pid = rx_fchs->s_id;
  	bfa_trc(rport->fcs, rport->pid);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2248
2249
2250
  	rport->stats.plogi_rcvd++;
  	bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
  }
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2251

5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2252
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2253
   *	Called by bport/vport to notify SCN for the remote port
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2254
2255
2256
2257
   */
  void
  bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport)
  {
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2258
2259
2260
  	rport->stats.rscns++;
  	bfa_sm_send_event(rport, RPSM_EVENT_SCN);
  }
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2261

5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2262
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2263
2264
   *	brief
   *	This routine BFA callback for bfa_rport_online() call.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2265
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2266
   *	param[in]	cb_arg	-  rport struct.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2267
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2268
2269
   *	return
   *		void
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2270
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2271
   *	Special Considerations:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2272
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2273
   *	note
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2274
2275
2276
2277
   */
  void
  bfa_cb_rport_online(void *cbarg)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2278
  	struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2279
2280
2281
2282
  
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE);
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2283
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2284
2285
   *	brief
   *	This routine BFA callback for bfa_rport_offline() call.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2286
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2287
   *	param[in]	rport	-
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2288
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2289
2290
   *	return
   *		void
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2291
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2292
   *	Special Considerations:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2293
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2294
   *	note
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2295
2296
2297
2298
   */
  void
  bfa_cb_rport_offline(void *cbarg)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2299
  	struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2300
2301
2302
2303
  
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE);
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2304
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2305
2306
2307
   *	brief
   *	This routine is a static BFA callback when there is a QoS flow_id
   *	change notification
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2308
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2309
   *	param[in]	rport	-
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2310
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2311
2312
   *	return
   *		void
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2313
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2314
   *	Special Considerations:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2315
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2316
   *	note
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2317
2318
2319
   */
  void
  bfa_cb_rport_qos_scn_flowid(void *cbarg,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2320
2321
  		struct bfa_rport_qos_attr_s old_qos_attr,
  		struct bfa_rport_qos_attr_s new_qos_attr)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2322
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2323
  	struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
2324
  	struct bfa_rport_aen_data_s aen_data;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2325
2326
  
  	bfa_trc(rport->fcs, rport->pwwn);
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
2327
2328
  	aen_data.priv.qos = new_qos_attr;
  	bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_FLOWID, &aen_data);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2329
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2330
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2331
2332
2333
   *	brief
   *	This routine is a static BFA callback when there is a QoS priority
   *	change notification
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2334
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2335
   *	param[in]	rport	-
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2336
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2337
2338
   *	return
   *		void
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2339
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2340
   *	Special Considerations:
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2341
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2342
   *	note
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2343
2344
   */
  void
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2345
2346
2347
  bfa_cb_rport_qos_scn_prio(void *cbarg,
  		struct bfa_rport_qos_attr_s old_qos_attr,
  		struct bfa_rport_qos_attr_s new_qos_attr)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2348
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2349
  	struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
2350
  	struct bfa_rport_aen_data_s aen_data;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2351
2352
  
  	bfa_trc(rport->fcs, rport->pwwn);
7826f304b   Krishna Gudipati   [SCSI] bfa: Add F...
2353
2354
  	aen_data.priv.qos = new_qos_attr;
  	bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_PRIO, &aen_data);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2355
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2356
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2357
   *		Called to process any unsolicted frames from this remote port
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2358
2359
   */
  void
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2360
2361
  bfa_fcs_rport_uf_recv(struct bfa_fcs_rport_s *rport,
  			struct fchs_s *fchs, u16 len)
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2362
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2363
2364
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct fc_els_cmd_s	*els_cmd;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
  
  	bfa_trc(rport->fcs, fchs->s_id);
  	bfa_trc(rport->fcs, fchs->d_id);
  	bfa_trc(rport->fcs, fchs->type);
  
  	if (fchs->type != FC_TYPE_ELS)
  		return;
  
  	els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  
  	bfa_trc(rport->fcs, els_cmd->els_code);
  
  	switch (els_cmd->els_code) {
  	case FC_ELS_LOGO:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2379
  		bfa_stats(port, plogi_rcvd);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2380
2381
2382
2383
  		bfa_fcs_rport_process_logo(rport, fchs);
  		break;
  
  	case FC_ELS_ADISC:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2384
  		bfa_stats(port, adisc_rcvd);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2385
2386
2387
2388
  		bfa_fcs_rport_process_adisc(rport, fchs, len);
  		break;
  
  	case FC_ELS_PRLO:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2389
2390
  		bfa_stats(port, prlo_rcvd);
  		if (bfa_fcs_lport_is_initiator(port))
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2391
  			bfa_fcs_fcpim_uf_recv(rport->itnim, fchs, len);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2392
2393
2394
  		break;
  
  	case FC_ELS_PRLI:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2395
  		bfa_stats(port, prli_rcvd);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2396
2397
2398
2399
  		bfa_fcs_rport_process_prli(rport, fchs, len);
  		break;
  
  	case FC_ELS_RPSC:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2400
  		bfa_stats(port, rpsc_rcvd);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2401
2402
2403
2404
  		bfa_fcs_rport_process_rpsc(rport, fchs, len);
  		break;
  
  	default:
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2405
  		bfa_stats(port, un_handled_els_rcvd);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2406
2407
2408
2409
2410
2411
  		bfa_fcs_rport_send_ls_rjt(rport, fchs,
  					  FC_LS_RJT_RSN_CMD_NOT_SUPP,
  					  FC_LS_RJT_EXP_NO_ADDL_INFO);
  		break;
  	}
  }
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2412
  /* send best case  acc to prlo */
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
2413
2414
2415
  static void
  bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2416
2417
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct fchs_s	fchs;
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
2418
  	struct bfa_fcxp_s *fcxp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2419
  	int		len;
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
2420
2421
2422
2423
2424
2425
  
  	bfa_trc(rport->fcs, rport->pid);
  
  	fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  	if (!fcxp)
  		return;
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
2426
  	len = fc_prlo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2427
  			rport->pid, bfa_fcs_lport_get_fcid(port),
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
2428
2429
2430
  			rport->reply_oxid, 0);
  
  	bfa_fcxp_send(fcxp, rport->bfa_rport, port->fabric->vf_id,
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2431
2432
  		port->lp_tag, BFA_FALSE, FC_CLASS_3, len, &fchs,
  		NULL, NULL, FC_MAX_PDUSZ, 0);
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
2433
  }
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2434
2435
2436
2437
2438
2439
2440
  /*
   * Send a LS reject
   */
  static void
  bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
  			  u8 reason_code, u8 reason_code_expl)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2441
2442
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct fchs_s	fchs;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2443
  	struct bfa_fcxp_s *fcxp;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2444
  	int		len;
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2445
2446
2447
2448
2449
2450
  
  	bfa_trc(rport->fcs, rx_fchs->s_id);
  
  	fcxp = bfa_fcs_fcxp_alloc(rport->fcs);
  	if (!fcxp)
  		return;
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2451
2452
2453
  	len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  				rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  				rx_fchs->ox_id, reason_code, reason_code_expl);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2454

a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2455
2456
2457
  	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
  			BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  			FC_MAX_PDUSZ, 0);
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2458
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2459
  /*
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2460
2461
2462
2463
2464
2465
2466
   * Return state of rport.
   */
  int
  bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport)
  {
  	return bfa_sm_to_state(rport_sm_table, rport->sm);
  }
f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
2467

5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2468
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2469
2470
   *	brief
   *		 Called by the Driver to set rport delete/ageout timeout
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2471
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2472
   *	param[in]		rport timeout value in seconds.
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2473
   *
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2474
   *	return None
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2475
2476
2477
2478
   */
  void
  bfa_fcs_rport_set_del_timeout(u8 rport_tmo)
  {
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2479
  	/* convert to Millisecs */
7725ccfda   Jing Huang   [SCSI] bfa: Broca...
2480
2481
2482
  	if (rport_tmo > 0)
  		bfa_fcs_rport_del_timeout = rport_tmo * 1000;
  }
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
2483
  void
50444a340   Maggie   [SCSI] bfa: fix e...
2484
  bfa_fcs_rport_prlo(struct bfa_fcs_rport_s *rport, __be16 ox_id)
4b5e759dc   Jing Huang   [SCSI] bfa: fix u...
2485
2486
2487
2488
2489
2490
2491
  {
  	bfa_trc(rport->fcs, rport->pid);
  
  	rport->prlo = BFA_TRUE;
  	rport->reply_oxid = ox_id;
  	bfa_sm_send_event(rport, RPSM_EVENT_PRLO_RCVD);
  }
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2492

601380669   Krishna Gudipati   [SCSI] bfa: Exten...
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
  void
  bfa_fcs_rport_get_attr(struct bfa_fcs_rport_s *rport,
  		struct bfa_rport_attr_s *rport_attr)
  {
  	struct bfa_rport_qos_attr_s qos_attr;
  	struct bfa_fcs_lport_s *port = rport->port;
  	bfa_port_speed_t rport_speed = rport->rpf.rpsc_speed;
  
  	memset(rport_attr, 0, sizeof(struct bfa_rport_attr_s));
  	memset(&qos_attr, 0, sizeof(struct bfa_rport_qos_attr_s));
  
  	rport_attr->pid = rport->pid;
  	rport_attr->pwwn = rport->pwwn;
  	rport_attr->nwwn = rport->nwwn;
  	rport_attr->cos_supported = rport->fc_cos;
  	rport_attr->df_sz = rport->maxfrsize;
  	rport_attr->state = bfa_fcs_rport_get_state(rport);
  	rport_attr->fc_cos = rport->fc_cos;
  	rport_attr->cisc = rport->cisc;
  	rport_attr->scsi_function = rport->scsi_function;
  	rport_attr->curr_speed  = rport->rpf.rpsc_speed;
  	rport_attr->assigned_speed  = rport->rpf.assigned_speed;
  
  	qos_attr.qos_priority = rport->bfa_rport->qos_attr.qos_priority;
  	qos_attr.qos_flow_id =
  		cpu_to_be32(rport->bfa_rport->qos_attr.qos_flow_id);
  	rport_attr->qos_attr = qos_attr;
  
  	rport_attr->trl_enforced = BFA_FALSE;
  	if (bfa_fcport_is_ratelim(port->fcs->bfa) &&
  	    (rport->scsi_function == BFA_RPORT_TARGET)) {
  		if (rport_speed == BFA_PORT_SPEED_UNKNOWN)
  			rport_speed =
  				bfa_fcport_get_ratelim_speed(rport->fcs->bfa);
  
  		if (rport_speed < bfa_fcs_lport_get_rport_max_speed(port))
  			rport_attr->trl_enforced = BFA_TRUE;
  	}
  }
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2532

5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2533
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2534
2535
   * Remote port implementation.
   */
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2536
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2537
2538
   *  fcs_rport_api FCS rport API.
   */
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
  struct bfa_fcs_rport_s *
  bfa_fcs_rport_lookup(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
  {
  	struct bfa_fcs_rport_s *rport;
  
  	rport = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn);
  	if (rport == NULL) {
  		/*
  		 * TBD Error handling
  		 */
  	}
  
  	return rport;
  }
  
  struct bfa_fcs_rport_s *
  bfa_fcs_rport_lookup_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t rnwwn)
  {
  	struct bfa_fcs_rport_s *rport;
  
  	rport = bfa_fcs_lport_get_rport_by_nwwn(port, rnwwn);
  	if (rport == NULL) {
  		/*
  		 * TBD Error handling
  		 */
  	}
  
  	return rport;
  }
  
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
   * Remote port features (RPF) implementation.
   */
  
  #define BFA_FCS_RPF_RETRIES	(3)
  #define BFA_FCS_RPF_RETRY_TIMEOUT  (1000) /* 1 sec (In millisecs) */
  
  static void     bfa_fcs_rpf_send_rpsc2(void *rport_cbarg,
  				struct bfa_fcxp_s *fcxp_alloced);
  static void     bfa_fcs_rpf_rpsc2_response(void *fcsarg,
  			struct bfa_fcxp_s *fcxp,
  			void *cbarg,
  			bfa_status_t req_status,
  			u32 rsp_len,
  			u32 resid_len,
  			struct fchs_s *rsp_fchs);
  
  static void     bfa_fcs_rpf_timeout(void *arg);
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2587
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
   *  fcs_rport_ftrs_sm FCS rport state machine events
   */
  
  enum rpf_event {
  	RPFSM_EVENT_RPORT_OFFLINE  = 1, /* Rport offline		*/
  	RPFSM_EVENT_RPORT_ONLINE   = 2,	/* Rport online			*/
  	RPFSM_EVENT_FCXP_SENT      = 3,	/* Frame from has been sent	*/
  	RPFSM_EVENT_TIMEOUT	   = 4, /* Rport SM timeout event	*/
  	RPFSM_EVENT_RPSC_COMP      = 5,
  	RPFSM_EVENT_RPSC_FAIL      = 6,
  	RPFSM_EVENT_RPSC_ERROR     = 7,
  };
  
  static void	bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf,
  					enum rpf_event event);
  static void     bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf,
  				       enum rpf_event event);
  static void     bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf,
  				       enum rpf_event event);
  static void	bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf,
  					enum rpf_event event);
  static void     bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf,
  					enum rpf_event event);
  static void     bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf,
  					enum rpf_event event);
  
  static void
  bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  {
  	struct bfa_fcs_rport_s *rport = rpf->rport;
  	struct bfa_fcs_fabric_s *fabric = &rport->fcs->fabric;
  
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPFSM_EVENT_RPORT_ONLINE:
  		/* Send RPSC2 to a Brocade fabric only. */
  		if ((!BFA_FCS_PID_IS_WKA(rport->pid)) &&
f7f73812e   Maggie Zhang   [SCSI] bfa: clean...
2628
  			((rport->port->fabric->lps->brcd_switch) ||
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
  			(bfa_fcs_fabric_get_switch_oui(fabric) ==
  						BFA_FCS_BRCD_SWITCH_OUI))) {
  			bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  			rpf->rpsc_retries = 0;
  			bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  		}
  		break;
  
  	case RPFSM_EVENT_RPORT_OFFLINE:
  		break;
  
  	default:
  		bfa_sm_fault(rport->fcs, event);
  	}
  }
  
  static void
  bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  {
  	struct bfa_fcs_rport_s *rport = rpf->rport;
  
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPFSM_EVENT_FCXP_SENT:
  		bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc);
  		break;
  
  	case RPFSM_EVENT_RPORT_OFFLINE:
  		bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  		bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rpf->fcxp_wqe);
  		rpf->rpsc_retries = 0;
  		break;
  
  	default:
  		bfa_sm_fault(rport->fcs, event);
  	}
  }
  
  static void
  bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  {
  	struct bfa_fcs_rport_s *rport = rpf->rport;
  
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPFSM_EVENT_RPSC_COMP:
  		bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  		/* Update speed info in f/w via BFA */
  		if (rpf->rpsc_speed != BFA_PORT_SPEED_UNKNOWN)
  			bfa_rport_speed(rport->bfa_rport, rpf->rpsc_speed);
  		else if (rpf->assigned_speed != BFA_PORT_SPEED_UNKNOWN)
  			bfa_rport_speed(rport->bfa_rport, rpf->assigned_speed);
  		break;
  
  	case RPFSM_EVENT_RPSC_FAIL:
  		/* RPSC not supported by rport */
  		bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  		break;
  
  	case RPFSM_EVENT_RPSC_ERROR:
  		/* need to retry...delayed a bit. */
  		if (rpf->rpsc_retries++ < BFA_FCS_RPF_RETRIES) {
  			bfa_timer_start(rport->fcs->bfa, &rpf->timer,
  				    bfa_fcs_rpf_timeout, rpf,
  				    BFA_FCS_RPF_RETRY_TIMEOUT);
  			bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_retry);
  		} else {
  			bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  		}
  		break;
  
  	case RPFSM_EVENT_RPORT_OFFLINE:
  		bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  		bfa_fcxp_discard(rpf->fcxp);
  		rpf->rpsc_retries = 0;
  		break;
  
  	default:
  		bfa_sm_fault(rport->fcs, event);
  	}
  }
  
  static void
  bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  {
  	struct bfa_fcs_rport_s *rport = rpf->rport;
  
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPFSM_EVENT_TIMEOUT:
  		/* re-send the RPSC */
  		bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  		bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  		break;
  
  	case RPFSM_EVENT_RPORT_OFFLINE:
  		bfa_timer_stop(&rpf->timer);
  		bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  		rpf->rpsc_retries = 0;
  		break;
  
  	default:
  		bfa_sm_fault(rport->fcs, event);
  	}
  }
  
  static void
  bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  {
  	struct bfa_fcs_rport_s *rport = rpf->rport;
  
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPFSM_EVENT_RPORT_OFFLINE:
  		bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  		rpf->rpsc_retries = 0;
  		break;
  
  	default:
  		bfa_sm_fault(rport->fcs, event);
  	}
  }
  
  static void
  bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  {
  	struct bfa_fcs_rport_s *rport = rpf->rport;
  
  	bfa_trc(rport->fcs, rport->pwwn);
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_trc(rport->fcs, event);
  
  	switch (event) {
  	case RPFSM_EVENT_RPORT_ONLINE:
  		bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  		bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  		break;
  
  	case RPFSM_EVENT_RPORT_OFFLINE:
  		break;
  
  	default:
  		bfa_sm_fault(rport->fcs, event);
  	}
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2782
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
   * Called when Rport is created.
   */
  void
  bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport)
  {
  	struct bfa_fcs_rpf_s *rpf = &rport->rpf;
  
  	bfa_trc(rport->fcs, rport->pid);
  	rpf->rport = rport;
  
  	bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit);
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2795
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
   * Called when Rport becomes online
   */
  void
  bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport)
  {
  	bfa_trc(rport->fcs, rport->pid);
  
  	if (__fcs_min_cfg(rport->port->fcs))
  		return;
  
  	if (bfa_fcs_fabric_is_switched(rport->port->fabric))
  		bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE);
  }
5fbe25c7a   Jing Huang   [SCSI] bfa: fix c...
2809
  /*
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
   * Called when Rport becomes offline
   */
  void
  bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport)
  {
  	bfa_trc(rport->fcs, rport->pid);
  
  	if (__fcs_min_cfg(rport->port->fcs))
  		return;
  
  	rport->rpf.rpsc_speed = 0;
  	bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_OFFLINE);
  }
  
  static void
  bfa_fcs_rpf_timeout(void *arg)
  {
  	struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) arg;
  	struct bfa_fcs_rport_s *rport = rpf->rport;
  
  	bfa_trc(rport->fcs, rport->pid);
  	bfa_sm_send_event(rpf, RPFSM_EVENT_TIMEOUT);
  }
  
  static void
  bfa_fcs_rpf_send_rpsc2(void *rpf_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  {
  	struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *)rpf_cbarg;
  	struct bfa_fcs_rport_s *rport = rpf->rport;
  	struct bfa_fcs_lport_s *port = rport->port;
  	struct fchs_s	fchs;
  	int		len;
  	struct bfa_fcxp_s *fcxp;
  
  	bfa_trc(rport->fcs, rport->pwwn);
  
  	fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  	if (!fcxp) {
  		bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rpf->fcxp_wqe,
  					bfa_fcs_rpf_send_rpsc2, rpf);
  		return;
  	}
  	rpf->fcxp = fcxp;
  
  	len = fc_rpsc2_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  			    bfa_fcs_lport_get_fcid(port), &rport->pid, 1);
  
  	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  			  FC_CLASS_3, len, &fchs, bfa_fcs_rpf_rpsc2_response,
  			  rpf, FC_MAX_PDUSZ, FC_ELS_TOV);
  	rport->stats.rpsc_sent++;
  	bfa_sm_send_event(rpf, RPFSM_EVENT_FCXP_SENT);
  
  }
  
  static void
  bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  			    bfa_status_t req_status, u32 rsp_len,
  			    u32 resid_len, struct fchs_s *rsp_fchs)
  {
  	struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) cbarg;
  	struct bfa_fcs_rport_s *rport = rpf->rport;
  	struct fc_ls_rjt_s *ls_rjt;
  	struct fc_rpsc2_acc_s *rpsc2_acc;
  	u16	num_ents;
  
  	bfa_trc(rport->fcs, req_status);
  
  	if (req_status != BFA_STATUS_OK) {
  		bfa_trc(rport->fcs, req_status);
  		if (req_status == BFA_STATUS_ETIMER)
  			rport->stats.rpsc_failed++;
  		bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  		return;
  	}
  
  	rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp);
  	if (rpsc2_acc->els_cmd == FC_ELS_ACC) {
  		rport->stats.rpsc_accs++;
ba816ea8e   Jing Huang   [SCSI] bfa: repla...
2889
  		num_ents = be16_to_cpu(rpsc2_acc->num_pids);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2890
2891
  		bfa_trc(rport->fcs, num_ents);
  		if (num_ents > 0) {
d4b671c58   Jing Huang   [SCSI] bfa: repla...
2892
  			WARN_ON(rpsc2_acc->port_info[0].pid == rport->pid);
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2893
  			bfa_trc(rport->fcs,
ba816ea8e   Jing Huang   [SCSI] bfa: repla...
2894
  				be16_to_cpu(rpsc2_acc->port_info[0].pid));
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2895
  			bfa_trc(rport->fcs,
ba816ea8e   Jing Huang   [SCSI] bfa: repla...
2896
  				be16_to_cpu(rpsc2_acc->port_info[0].speed));
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2897
  			bfa_trc(rport->fcs,
ba816ea8e   Jing Huang   [SCSI] bfa: repla...
2898
  				be16_to_cpu(rpsc2_acc->port_info[0].index));
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2899
2900
2901
2902
2903
2904
2905
2906
2907
  			bfa_trc(rport->fcs,
  				rpsc2_acc->port_info[0].type);
  
  			if (rpsc2_acc->port_info[0].speed == 0) {
  				bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  				return;
  			}
  
  			rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed(
ba816ea8e   Jing Huang   [SCSI] bfa: repla...
2908
  				be16_to_cpu(rpsc2_acc->port_info[0].speed));
a36c61f90   Krishna Gudipati   [SCSI] bfa: clean...
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
  
  			bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP);
  		}
  	} else {
  		ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  		bfa_trc(rport->fcs, ls_rjt->reason_code);
  		bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
  		rport->stats.rpsc_rejects++;
  		if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP)
  			bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_FAIL);
  		else
  			bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  	}
  }