blob: 3b75f6fb2de1fbf29b189715e5a3af9d17283343 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
Maggie Zhangf16a1752010-12-09 19:12:32 -080018#include "bfad_drv.h"
Krishna Gudipati7826f302011-07-20 16:59:13 -070019#include "bfad_im.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070020#include "bfa_fcs.h"
21#include "bfa_fcbuild.h"
22#include "bfa_fc.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070023
24BFA_TRC_FILE(FCS, PORT);
25
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070026static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port,
27 struct fchs_s *rx_fchs, u8 reason_code,
28 u8 reason_code_expl);
29static void bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
30 struct fchs_s *rx_fchs, struct fc_logi_s *plogi);
31static void bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port);
32static void bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port);
33static void bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port);
34static void bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port);
35static void bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port);
36static void bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port);
37static void bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -070038 struct fchs_s *rx_fchs,
39 struct fc_echo_s *echo, u16 len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070040static void bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -070041 struct fchs_s *rx_fchs,
42 struct fc_rnid_cmd_s *rnid, u16 len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070043static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -070044 struct fc_rnid_general_topology_data_s *gen_topo_data);
45
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070046static void bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port);
47static void bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port);
48static void bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port);
49
50static void bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port);
51static void bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port);
52static void bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port);
53
Jing Huang7725ccf2009-09-23 17:46:15 -070054static struct {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070055 void (*init) (struct bfa_fcs_lport_s *port);
56 void (*online) (struct bfa_fcs_lport_s *port);
57 void (*offline) (struct bfa_fcs_lport_s *port);
Jing Huang7725ccf2009-09-23 17:46:15 -070058} __port_action[] = {
59 {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070060 bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
61 bfa_fcs_lport_unknown_offline}, {
62 bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
63 bfa_fcs_lport_fab_offline}, {
64 bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
65 bfa_fcs_lport_n2n_offline},
66 };
Jing Huang7725ccf2009-09-23 17:46:15 -070067
Jing Huang5fbe25c2010-10-18 17:17:23 -070068/*
Jing Huang7725ccf2009-09-23 17:46:15 -070069 * fcs_port_sm FCS logical port state machine
70 */
71
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070072enum bfa_fcs_lport_event {
Jing Huang7725ccf2009-09-23 17:46:15 -070073 BFA_FCS_PORT_SM_CREATE = 1,
74 BFA_FCS_PORT_SM_ONLINE = 2,
75 BFA_FCS_PORT_SM_OFFLINE = 3,
76 BFA_FCS_PORT_SM_DELETE = 4,
77 BFA_FCS_PORT_SM_DELRPORT = 5,
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -070078 BFA_FCS_PORT_SM_STOP = 6,
Jing Huang7725ccf2009-09-23 17:46:15 -070079};
80
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070081static void bfa_fcs_lport_sm_uninit(struct bfa_fcs_lport_s *port,
82 enum bfa_fcs_lport_event event);
83static void bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
84 enum bfa_fcs_lport_event event);
85static void bfa_fcs_lport_sm_online(struct bfa_fcs_lport_s *port,
86 enum bfa_fcs_lport_event event);
87static void bfa_fcs_lport_sm_offline(struct bfa_fcs_lport_s *port,
88 enum bfa_fcs_lport_event event);
89static void bfa_fcs_lport_sm_deleting(struct bfa_fcs_lport_s *port,
90 enum bfa_fcs_lport_event event);
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -070091static void bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
92 enum bfa_fcs_lport_event event);
Jing Huang7725ccf2009-09-23 17:46:15 -070093
94static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070095bfa_fcs_lport_sm_uninit(
96 struct bfa_fcs_lport_s *port,
97 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -070098{
99 bfa_trc(port->fcs, port->port_cfg.pwwn);
100 bfa_trc(port->fcs, event);
101
102 switch (event) {
103 case BFA_FCS_PORT_SM_CREATE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700104 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
Jing Huang7725ccf2009-09-23 17:46:15 -0700105 break;
106
107 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800108 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700109 }
110}
111
112static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700113bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
114 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700115{
116 bfa_trc(port->fcs, port->port_cfg.pwwn);
117 bfa_trc(port->fcs, event);
118
119 switch (event) {
120 case BFA_FCS_PORT_SM_ONLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700121 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
122 bfa_fcs_lport_online_actions(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700123 break;
124
125 case BFA_FCS_PORT_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700126 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
127 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700128 break;
129
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700130 case BFA_FCS_PORT_SM_STOP:
131 /* If vport - send completion call back */
132 if (port->vport)
133 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700134 else
135 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700136 break;
137
Jing Huang3e98cc02010-07-08 19:52:46 -0700138 case BFA_FCS_PORT_SM_OFFLINE:
139 break;
140
Jing Huang7725ccf2009-09-23 17:46:15 -0700141 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800142 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700143 }
144}
145
146static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700147bfa_fcs_lport_sm_online(
148 struct bfa_fcs_lport_s *port,
149 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700150{
151 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700152 struct list_head *qe, *qen;
Jing Huang7725ccf2009-09-23 17:46:15 -0700153
154 bfa_trc(port->fcs, port->port_cfg.pwwn);
155 bfa_trc(port->fcs, event);
156
157 switch (event) {
158 case BFA_FCS_PORT_SM_OFFLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700159 bfa_sm_set_state(port, bfa_fcs_lport_sm_offline);
160 bfa_fcs_lport_offline_actions(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700161 break;
162
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700163 case BFA_FCS_PORT_SM_STOP:
164 __port_action[port->fabric->fab_type].offline(port);
165
166 if (port->num_rports == 0) {
167 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
168 /* If vport - send completion call back */
169 if (port->vport)
170 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700171 else
172 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700173 } else {
174 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
175 list_for_each_safe(qe, qen, &port->rport_q) {
176 rport = (struct bfa_fcs_rport_s *) qe;
177 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
178 }
179 }
180 break;
181
Jing Huang7725ccf2009-09-23 17:46:15 -0700182 case BFA_FCS_PORT_SM_DELETE:
183
184 __port_action[port->fabric->fab_type].offline(port);
185
186 if (port->num_rports == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700187 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
188 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700189 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700190 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
Jing Huang7725ccf2009-09-23 17:46:15 -0700191 list_for_each_safe(qe, qen, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700192 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800193 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700194 }
195 }
196 break;
197
198 case BFA_FCS_PORT_SM_DELRPORT:
199 break;
200
201 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800202 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700203 }
204}
205
206static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700207bfa_fcs_lport_sm_offline(
208 struct bfa_fcs_lport_s *port,
209 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700210{
211 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700212 struct list_head *qe, *qen;
Jing Huang7725ccf2009-09-23 17:46:15 -0700213
214 bfa_trc(port->fcs, port->port_cfg.pwwn);
215 bfa_trc(port->fcs, event);
216
217 switch (event) {
218 case BFA_FCS_PORT_SM_ONLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700219 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
220 bfa_fcs_lport_online_actions(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700221 break;
222
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700223 case BFA_FCS_PORT_SM_STOP:
224 if (port->num_rports == 0) {
225 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
226 /* If vport - send completion call back */
227 if (port->vport)
228 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700229 else
230 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700231 } else {
232 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
233 list_for_each_safe(qe, qen, &port->rport_q) {
234 rport = (struct bfa_fcs_rport_s *) qe;
235 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
236 }
237 }
238 break;
239
Jing Huang7725ccf2009-09-23 17:46:15 -0700240 case BFA_FCS_PORT_SM_DELETE:
241 if (port->num_rports == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700242 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
243 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700244 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700245 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
Jing Huang7725ccf2009-09-23 17:46:15 -0700246 list_for_each_safe(qe, qen, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700247 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800248 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700249 }
250 }
251 break;
252
253 case BFA_FCS_PORT_SM_DELRPORT:
254 case BFA_FCS_PORT_SM_OFFLINE:
255 break;
256
257 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800258 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700259 }
260}
261
262static void
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700263bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
264 enum bfa_fcs_lport_event event)
265{
266 bfa_trc(port->fcs, port->port_cfg.pwwn);
267 bfa_trc(port->fcs, event);
268
269 switch (event) {
270 case BFA_FCS_PORT_SM_DELRPORT:
271 if (port->num_rports == 0) {
272 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
273 /* If vport - send completion call back */
274 if (port->vport)
275 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700276 else
277 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700278 }
279 break;
280
281 default:
282 bfa_sm_fault(port->fcs, event);
283 }
284}
285
286static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700287bfa_fcs_lport_sm_deleting(
288 struct bfa_fcs_lport_s *port,
289 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700290{
291 bfa_trc(port->fcs, port->port_cfg.pwwn);
292 bfa_trc(port->fcs, event);
293
294 switch (event) {
295 case BFA_FCS_PORT_SM_DELRPORT:
296 if (port->num_rports == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700297 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
298 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700299 }
300 break;
301
302 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800303 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700304 }
305}
306
Jing Huang5fbe25c2010-10-18 17:17:23 -0700307/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700308 * fcs_port_pvt
309 */
310
Jing Huang7725ccf2009-09-23 17:46:15 -0700311/*
Krishna Gudipati7826f302011-07-20 16:59:13 -0700312 * Send AEN notification
313 */
314static void
315bfa_fcs_lport_aen_post(struct bfa_fcs_lport_s *port,
316 enum bfa_lport_aen_event event)
317{
318 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
319 struct bfa_aen_entry_s *aen_entry;
320
321 bfad_get_aen_entry(bfad, aen_entry);
322 if (!aen_entry)
323 return;
324
325 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
326 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
327 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
328 bfa_fcs_get_base_port(port->fcs));
329 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
330
331 /* Send the AEN notification */
332 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
333 BFA_AEN_CAT_LPORT, event);
334}
335
336/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700337 * Send a LS reject
338 */
339static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700340bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
Jing Huang7725ccf2009-09-23 17:46:15 -0700341 u8 reason_code, u8 reason_code_expl)
342{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700343 struct fchs_s fchs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700344 struct bfa_fcxp_s *fcxp;
345 struct bfa_rport_s *bfa_rport = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700346 int len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700347
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700348 bfa_trc(port->fcs, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700349 bfa_trc(port->fcs, rx_fchs->s_id);
350
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700351 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700352 if (!fcxp)
353 return;
354
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700355 len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
356 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
357 rx_fchs->ox_id, reason_code, reason_code_expl);
Jing Huang7725ccf2009-09-23 17:46:15 -0700358
359 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700360 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
361 FC_MAX_PDUSZ, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700362}
363
Jing Huang5fbe25c2010-10-18 17:17:23 -0700364/*
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700365 * Send a FCCT Reject
366 */
367static void
368bfa_fcs_lport_send_fcgs_rjt(struct bfa_fcs_lport_s *port,
369 struct fchs_s *rx_fchs, u8 reason_code, u8 reason_code_expl)
370{
371 struct fchs_s fchs;
372 struct bfa_fcxp_s *fcxp;
373 struct bfa_rport_s *bfa_rport = NULL;
374 int len;
375 struct ct_hdr_s *rx_cthdr = (struct ct_hdr_s *)(rx_fchs + 1);
376 struct ct_hdr_s *ct_hdr;
377
378 bfa_trc(port->fcs, rx_fchs->d_id);
379 bfa_trc(port->fcs, rx_fchs->s_id);
380
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700381 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700382 if (!fcxp)
383 return;
384
385 ct_hdr = bfa_fcxp_get_reqbuf(fcxp);
386 ct_hdr->gs_type = rx_cthdr->gs_type;
387 ct_hdr->gs_sub_type = rx_cthdr->gs_sub_type;
388
389 len = fc_gs_rjt_build(&fchs, ct_hdr, rx_fchs->s_id,
390 bfa_fcs_lport_get_fcid(port),
391 rx_fchs->ox_id, reason_code, reason_code_expl);
392
393 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
394 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
395 FC_MAX_PDUSZ, 0);
396}
397
398/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700399 * Process incoming plogi from a remote port.
400 */
401static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700402bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
403 struct fchs_s *rx_fchs, struct fc_logi_s *plogi)
Jing Huang7725ccf2009-09-23 17:46:15 -0700404{
405 struct bfa_fcs_rport_s *rport;
406
407 bfa_trc(port->fcs, rx_fchs->d_id);
408 bfa_trc(port->fcs, rx_fchs->s_id);
409
410 /*
411 * If min cfg mode is enabled, drop any incoming PLOGIs
412 */
413 if (__fcs_min_cfg(port->fcs)) {
414 bfa_trc(port->fcs, rx_fchs->s_id);
415 return;
416 }
417
418 if (fc_plogi_parse(rx_fchs) != FC_PARSE_OK) {
419 bfa_trc(port->fcs, rx_fchs->s_id);
420 /*
421 * send a LS reject
422 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700423 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
424 FC_LS_RJT_RSN_PROTOCOL_ERROR,
425 FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS);
Jing Huang7725ccf2009-09-23 17:46:15 -0700426 return;
427 }
428
Jing Huang5fbe25c2010-10-18 17:17:23 -0700429 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700430 * Direct Attach P2P mode : verify address assigned by the r-port.
Jing Huang7725ccf2009-09-23 17:46:15 -0700431 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700432 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
433 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
434 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700435 if (BFA_FCS_PID_IS_WKA(rx_fchs->d_id)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700436 /* Address assigned to us cannot be a WKA */
437 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
Jing Huang7725ccf2009-09-23 17:46:15 -0700438 FC_LS_RJT_RSN_PROTOCOL_ERROR,
439 FC_LS_RJT_EXP_INVALID_NPORT_ID);
440 return;
441 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700442 port->pid = rx_fchs->d_id;
Krishna Gudipatib7044952010-12-13 16:17:42 -0800443 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700444 }
445
Jing Huang5fbe25c2010-10-18 17:17:23 -0700446 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700447 * First, check if we know the device by pwwn.
448 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700449 rport = bfa_fcs_lport_get_rport_by_pwwn(port, plogi->port_name);
Jing Huang7725ccf2009-09-23 17:46:15 -0700450 if (rport) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700451 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700452 * Direct Attach P2P mode : handle address assigned by r-port.
Jing Huang7725ccf2009-09-23 17:46:15 -0700453 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700454 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
455 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
456 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
457 port->pid = rx_fchs->d_id;
Krishna Gudipatib7044952010-12-13 16:17:42 -0800458 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700459 rport->pid = rx_fchs->s_id;
460 }
461 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
462 return;
463 }
464
Jing Huang5fbe25c2010-10-18 17:17:23 -0700465 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700466 * Next, lookup rport by PID.
467 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700468 rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700469 if (!rport) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700470 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700471 * Inbound PLOGI from a new device.
472 */
473 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
474 return;
475 }
476
Jing Huang5fbe25c2010-10-18 17:17:23 -0700477 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700478 * Rport is known only by PID.
479 */
480 if (rport->pwwn) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700481 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700482 * This is a different device with the same pid. Old device
483 * disappeared. Send implicit LOGO to old device.
484 */
Jing Huangd4b671c2010-12-26 21:46:35 -0800485 WARN_ON(rport->pwwn == plogi->port_name);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800486 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700487
Jing Huang5fbe25c2010-10-18 17:17:23 -0700488 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700489 * Inbound PLOGI from a new device (with old PID).
490 */
491 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
492 return;
493 }
494
Jing Huang5fbe25c2010-10-18 17:17:23 -0700495 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700496 * PLOGI crossing each other.
497 */
Jing Huangd4b671c2010-12-26 21:46:35 -0800498 WARN_ON(rport->pwwn != WWN_NULL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700499 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
500}
501
502/*
503 * Process incoming ECHO.
504 * Since it does not require a login, it is processed here.
505 */
506static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700507bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
508 struct fc_echo_s *echo, u16 rx_len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700509{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700510 struct fchs_s fchs;
511 struct bfa_fcxp_s *fcxp;
512 struct bfa_rport_s *bfa_rport = NULL;
513 int len, pyld_len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700514
515 bfa_trc(port->fcs, rx_fchs->s_id);
516 bfa_trc(port->fcs, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700517
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700518 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700519 if (!fcxp)
520 return;
521
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700522 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
523 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
524 rx_fchs->ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700525
526 /*
527 * Copy the payload (if any) from the echo frame
528 */
529 pyld_len = rx_len - sizeof(struct fchs_s);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700530 bfa_trc(port->fcs, rx_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700531 bfa_trc(port->fcs, pyld_len);
532
533 if (pyld_len > len)
534 memcpy(((u8 *) bfa_fcxp_get_reqbuf(fcxp)) +
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700535 sizeof(struct fc_echo_s), (echo + 1),
536 (pyld_len - sizeof(struct fc_echo_s)));
Jing Huang7725ccf2009-09-23 17:46:15 -0700537
538 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700539 BFA_FALSE, FC_CLASS_3, pyld_len, &fchs, NULL, NULL,
540 FC_MAX_PDUSZ, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700541}
542
543/*
544 * Process incoming RNID.
545 * Since it does not require a login, it is processed here.
546 */
547static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700548bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
549 struct fc_rnid_cmd_s *rnid, u16 rx_len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700550{
551 struct fc_rnid_common_id_data_s common_id_data;
552 struct fc_rnid_general_topology_data_s gen_topo_data;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700553 struct fchs_s fchs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700554 struct bfa_fcxp_s *fcxp;
555 struct bfa_rport_s *bfa_rport = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700556 u16 len;
557 u32 data_format;
Jing Huang7725ccf2009-09-23 17:46:15 -0700558
559 bfa_trc(port->fcs, rx_fchs->s_id);
560 bfa_trc(port->fcs, rx_fchs->d_id);
561 bfa_trc(port->fcs, rx_len);
562
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700563 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700564 if (!fcxp)
565 return;
566
567 /*
568 * Check Node Indentification Data Format
569 * We only support General Topology Discovery Format.
570 * For any other requested Data Formats, we return Common Node Id Data
571 * only, as per FC-LS.
572 */
573 bfa_trc(port->fcs, rnid->node_id_data_format);
574 if (rnid->node_id_data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
575 data_format = RNID_NODEID_DATA_FORMAT_DISCOVERY;
576 /*
577 * Get General topology data for this port
578 */
579 bfa_fs_port_get_gen_topo_data(port, &gen_topo_data);
580 } else {
581 data_format = RNID_NODEID_DATA_FORMAT_COMMON;
582 }
583
584 /*
585 * Copy the Node Id Info
586 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700587 common_id_data.port_name = bfa_fcs_lport_get_pwwn(port);
588 common_id_data.node_name = bfa_fcs_lport_get_nwwn(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700589
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700590 len = fc_rnid_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
591 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
592 rx_fchs->ox_id, data_format, &common_id_data,
593 &gen_topo_data);
Jing Huang7725ccf2009-09-23 17:46:15 -0700594
595 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700596 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
597 FC_MAX_PDUSZ, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700598}
599
600/*
601 * Fill out General Topolpgy Discovery Data for RNID ELS.
602 */
603static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700604bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -0700605 struct fc_rnid_general_topology_data_s *gen_topo_data)
606{
Jing Huang6a18b162010-10-18 17:08:54 -0700607 memset(gen_topo_data, 0,
Jing Huang7725ccf2009-09-23 17:46:15 -0700608 sizeof(struct fc_rnid_general_topology_data_s));
609
Jing Huangba816ea2010-10-18 17:10:50 -0700610 gen_topo_data->asso_type = cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST);
Jing Huang7725ccf2009-09-23 17:46:15 -0700611 gen_topo_data->phy_port_num = 0; /* @todo */
Jing Huangba816ea2010-10-18 17:10:50 -0700612 gen_topo_data->num_attached_nodes = cpu_to_be32(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700613}
614
615static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700616bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700617{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700618 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
619 char lpwwn_buf[BFA_STRING_32];
620
Jing Huang7725ccf2009-09-23 17:46:15 -0700621 bfa_trc(port->fcs, port->fabric->oper_type);
622
623 __port_action[port->fabric->fab_type].init(port);
624 __port_action[port->fabric->fab_type].online(port);
625
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700626 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
Krishna Gudipatia3f29cc2012-04-09 18:41:18 -0700627 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700628 "Logical port online: WWN = %s Role = %s\n",
629 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700630 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_ONLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700631
632 bfad->bfad_flags |= BFAD_PORT_ONLINE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700633}
634
635static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700636bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700637{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700638 struct list_head *qe, *qen;
Jing Huang7725ccf2009-09-23 17:46:15 -0700639 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700640 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
641 char lpwwn_buf[BFA_STRING_32];
Jing Huang7725ccf2009-09-23 17:46:15 -0700642
643 bfa_trc(port->fcs, port->fabric->oper_type);
644
645 __port_action[port->fabric->fab_type].offline(port);
646
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700647 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
Maggie Zhangf7f738122010-12-09 19:08:43 -0800648 if (bfa_sm_cmp_state(port->fabric,
Krishna Gudipati7826f302011-07-20 16:59:13 -0700649 bfa_fcs_fabric_sm_online) == BFA_TRUE) {
Krishna Gudipatia3f29cc2012-04-09 18:41:18 -0700650 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700651 "Logical port lost fabric connectivity: WWN = %s Role = %s\n",
652 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700653 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DISCONNECT);
654 } else {
Krishna Gudipatia3f29cc2012-04-09 18:41:18 -0700655 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700656 "Logical port taken offline: WWN = %s Role = %s\n",
657 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700658 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_OFFLINE);
659 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700660
661 list_for_each_safe(qe, qen, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700662 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800663 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700664 }
665}
666
667static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700668bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700669{
Jing Huangd4b671c2010-12-26 21:46:35 -0800670 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700671}
672
673static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700674bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700675{
Jing Huangd4b671c2010-12-26 21:46:35 -0800676 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700677}
678
679static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700680bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700681{
Jing Huangd4b671c2010-12-26 21:46:35 -0800682 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700683}
684
685static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700686bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs)
Jing Huang7725ccf2009-09-23 17:46:15 -0700687{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700688 struct fchs_s fchs;
689 struct bfa_fcxp_s *fcxp;
690 int len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700691
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700692 bfa_trc(port->fcs, rx_fchs->d_id);
693 bfa_trc(port->fcs, rx_fchs->s_id);
694
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700695 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700696 if (!fcxp)
697 return;
698
699 len = fc_ba_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
700 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
701 rx_fchs->ox_id, 0);
702
703 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
704 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
705 FC_MAX_PDUSZ, 0);
706}
707static void
708bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port)
709{
710 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
711 char lpwwn_buf[BFA_STRING_32];
712
713 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
Jing Huang88166242010-12-09 17:11:53 -0800714 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700715 "Logical port deleted: WWN = %s Role = %s\n",
716 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700717 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DELETE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700718
719 /* Base port will be deleted by the OS driver */
Krishna Gudipati17c201b2012-04-09 18:40:01 -0700720 if (port->vport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700721 bfa_fcs_vport_delete_comp(port->vport);
Krishna Gudipati17c201b2012-04-09 18:40:01 -0700722 else
Maggie Zhangf7f738122010-12-09 19:08:43 -0800723 bfa_wc_down(&port->fabric->wc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700724}
725
726
Jing Huang5fbe25c2010-10-18 17:17:23 -0700727/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700728 * Unsolicited frame receive handling.
Jing Huang7725ccf2009-09-23 17:46:15 -0700729 */
730void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700731bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
732 struct fchs_s *fchs, u16 len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700733{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700734 u32 pid = fchs->s_id;
Jing Huang7725ccf2009-09-23 17:46:15 -0700735 struct bfa_fcs_rport_s *rport = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700736 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700737
738 bfa_stats(lport, uf_recvs);
Krishna Gudipati15821f02010-12-13 16:23:27 -0800739 bfa_trc(lport->fcs, fchs->type);
Jing Huang7725ccf2009-09-23 17:46:15 -0700740
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700741 if (!bfa_fcs_lport_is_online(lport)) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700742 bfa_stats(lport, uf_recv_drops);
743 return;
744 }
745
Jing Huang5fbe25c2010-10-18 17:17:23 -0700746 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700747 * First, handle ELSs that donot require a login.
748 */
749 /*
750 * Handle PLOGI first
751 */
752 if ((fchs->type == FC_TYPE_ELS) &&
753 (els_cmd->els_code == FC_ELS_PLOGI)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700754 bfa_fcs_lport_plogi(lport, fchs, (struct fc_logi_s *) els_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -0700755 return;
756 }
757
758 /*
759 * Handle ECHO separately.
760 */
761 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_ECHO)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700762 bfa_fcs_lport_echo(lport, fchs,
763 (struct fc_echo_s *)els_cmd, len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700764 return;
765 }
766
767 /*
768 * Handle RNID separately.
769 */
770 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_RNID)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700771 bfa_fcs_lport_rnid(lport, fchs,
Jing Huang7725ccf2009-09-23 17:46:15 -0700772 (struct fc_rnid_cmd_s *) els_cmd, len);
773 return;
774 }
775
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700776 if (fchs->type == FC_TYPE_BLS) {
777 if ((fchs->routing == FC_RTG_BASIC_LINK) &&
778 (fchs->cat_info == FC_CAT_ABTS))
779 bfa_fcs_lport_abts_acc(lport, fchs);
780 return;
781 }
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700782
783 if (fchs->type == FC_TYPE_SERVICES) {
784 /*
785 * Unhandled FC-GS frames. Send a FC-CT Reject
786 */
787 bfa_fcs_lport_send_fcgs_rjt(lport, fchs, CT_RSN_NOT_SUPP,
788 CT_NS_EXP_NOADDITIONAL);
789 return;
790 }
791
Jing Huang5fbe25c2010-10-18 17:17:23 -0700792 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700793 * look for a matching remote port ID
794 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700795 rport = bfa_fcs_lport_get_rport_by_pid(lport, pid);
Jing Huang7725ccf2009-09-23 17:46:15 -0700796 if (rport) {
797 bfa_trc(rport->fcs, fchs->s_id);
798 bfa_trc(rport->fcs, fchs->d_id);
799 bfa_trc(rport->fcs, fchs->type);
800
801 bfa_fcs_rport_uf_recv(rport, fchs, len);
802 return;
803 }
804
Jing Huang5fbe25c2010-10-18 17:17:23 -0700805 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700806 * Only handles ELS frames for now.
807 */
808 if (fchs->type != FC_TYPE_ELS) {
Krishna Gudipati15821f02010-12-13 16:23:27 -0800809 bfa_trc(lport->fcs, fchs->s_id);
810 bfa_trc(lport->fcs, fchs->d_id);
811 /* ignore type FC_TYPE_FC_FSS */
812 if (fchs->type != FC_TYPE_FC_FSS)
813 bfa_sm_fault(lport->fcs, fchs->type);
Jing Huang7725ccf2009-09-23 17:46:15 -0700814 return;
815 }
816
817 bfa_trc(lport->fcs, els_cmd->els_code);
818 if (els_cmd->els_code == FC_ELS_RSCN) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700819 bfa_fcs_lport_scn_process_rscn(lport, fchs, len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700820 return;
821 }
822
823 if (els_cmd->els_code == FC_ELS_LOGO) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700824 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700825 * @todo Handle LOGO frames received.
826 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700827 return;
828 }
829
830 if (els_cmd->els_code == FC_ELS_PRLI) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700831 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700832 * @todo Handle PRLI frames received.
833 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700834 return;
835 }
836
Jing Huang5fbe25c2010-10-18 17:17:23 -0700837 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700838 * Unhandled ELS frames. Send a LS_RJT.
839 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700840 bfa_fcs_lport_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP,
Jing Huang7725ccf2009-09-23 17:46:15 -0700841 FC_LS_RJT_EXP_NO_ADDL_INFO);
842
843}
844
Jing Huang5fbe25c2010-10-18 17:17:23 -0700845/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700846 * PID based Lookup for a R-Port in the Port R-Port Queue
847 */
848struct bfa_fcs_rport_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700849bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s *port, u32 pid)
Jing Huang7725ccf2009-09-23 17:46:15 -0700850{
851 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700852 struct list_head *qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700853
854 list_for_each(qe, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700855 rport = (struct bfa_fcs_rport_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700856 if (rport->pid == pid)
857 return rport;
858 }
859
860 bfa_trc(port->fcs, pid);
861 return NULL;
862}
863
Jing Huang5fbe25c2010-10-18 17:17:23 -0700864/*
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -0700865 * OLD_PID based Lookup for a R-Port in the Port R-Port Queue
866 */
867struct bfa_fcs_rport_s *
868bfa_fcs_lport_get_rport_by_old_pid(struct bfa_fcs_lport_s *port, u32 pid)
869{
870 struct bfa_fcs_rport_s *rport;
871 struct list_head *qe;
872
873 list_for_each(qe, &port->rport_q) {
874 rport = (struct bfa_fcs_rport_s *) qe;
875 if (rport->old_pid == pid)
876 return rport;
877 }
878
879 bfa_trc(port->fcs, pid);
880 return NULL;
881}
882
883/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700884 * PWWN based Lookup for a R-Port in the Port R-Port Queue
885 */
886struct bfa_fcs_rport_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700887bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s *port, wwn_t pwwn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700888{
889 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700890 struct list_head *qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700891
892 list_for_each(qe, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700893 rport = (struct bfa_fcs_rport_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700894 if (wwn_is_equal(rport->pwwn, pwwn))
895 return rport;
896 }
897
898 bfa_trc(port->fcs, pwwn);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700899 return NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700900}
901
Jing Huang5fbe25c2010-10-18 17:17:23 -0700902/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700903 * NWWN based Lookup for a R-Port in the Port R-Port Queue
904 */
905struct bfa_fcs_rport_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700906bfa_fcs_lport_get_rport_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t nwwn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700907{
908 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700909 struct list_head *qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700910
911 list_for_each(qe, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700912 rport = (struct bfa_fcs_rport_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700913 if (wwn_is_equal(rport->nwwn, nwwn))
914 return rport;
915 }
916
917 bfa_trc(port->fcs, nwwn);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700918 return NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700919}
920
Jing Huang5fbe25c2010-10-18 17:17:23 -0700921/*
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -0700922 * PWWN & PID based Lookup for a R-Port in the Port R-Port Queue
923 */
924struct bfa_fcs_rport_s *
925bfa_fcs_lport_get_rport_by_qualifier(struct bfa_fcs_lport_s *port,
926 wwn_t pwwn, u32 pid)
927{
928 struct bfa_fcs_rport_s *rport;
929 struct list_head *qe;
930
931 list_for_each(qe, &port->rport_q) {
932 rport = (struct bfa_fcs_rport_s *) qe;
933 if (wwn_is_equal(rport->pwwn, pwwn) && rport->pid == pid)
934 return rport;
935 }
936
937 bfa_trc(port->fcs, pwwn);
938 return NULL;
939}
940
941/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700942 * Called by rport module when new rports are discovered.
943 */
944void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700945bfa_fcs_lport_add_rport(
946 struct bfa_fcs_lport_s *port,
947 struct bfa_fcs_rport_s *rport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700948{
949 list_add_tail(&rport->qe, &port->rport_q);
950 port->num_rports++;
951}
952
Jing Huang5fbe25c2010-10-18 17:17:23 -0700953/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700954 * Called by rport module to when rports are deleted.
955 */
956void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700957bfa_fcs_lport_del_rport(
958 struct bfa_fcs_lport_s *port,
959 struct bfa_fcs_rport_s *rport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700960{
Jing Huangd4b671c2010-12-26 21:46:35 -0800961 WARN_ON(!bfa_q_is_on_q(&port->rport_q, rport));
Jing Huang7725ccf2009-09-23 17:46:15 -0700962 list_del(&rport->qe);
963 port->num_rports--;
964
965 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT);
966}
967
Jing Huang5fbe25c2010-10-18 17:17:23 -0700968/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700969 * Called by fabric for base port when fabric login is complete.
970 * Called by vport for virtual ports when FDISC is complete.
971 */
972void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700973bfa_fcs_lport_online(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700974{
975 bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE);
976}
977
Jing Huang5fbe25c2010-10-18 17:17:23 -0700978/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700979 * Called by fabric for base port when fabric goes offline.
980 * Called by vport for virtual ports when virtual port becomes offline.
981 */
982void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700983bfa_fcs_lport_offline(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700984{
985 bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE);
986}
987
Jing Huang5fbe25c2010-10-18 17:17:23 -0700988/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700989 * Called by fabric for base port and by vport for virtual ports
990 * when target mode driver is unloaded.
991 */
992void
993bfa_fcs_lport_stop(struct bfa_fcs_lport_s *port)
994{
995 bfa_sm_send_event(port, BFA_FCS_PORT_SM_STOP);
996}
997
998/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700999 * Called by fabric to delete base lport and associated resources.
1000 *
1001 * Called by vport to delete lport and associated resources. Should call
1002 * bfa_fcs_vport_delete_comp() for vports on completion.
1003 */
1004void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001005bfa_fcs_lport_delete(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -07001006{
1007 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE);
1008}
1009
Jing Huang5fbe25c2010-10-18 17:17:23 -07001010/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001011 * Return TRUE if port is online, else return FALSE
1012 */
1013bfa_boolean_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001014bfa_fcs_lport_is_online(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -07001015{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001016 return bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online);
Jing Huang7725ccf2009-09-23 17:46:15 -07001017}
1018
Jing Huang5fbe25c2010-10-18 17:17:23 -07001019/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001020 * Attach time initialization of logical ports.
Jing Huang7725ccf2009-09-23 17:46:15 -07001021 */
1022void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001023bfa_fcs_lport_attach(struct bfa_fcs_lport_s *lport, struct bfa_fcs_s *fcs,
1024 u16 vf_id, struct bfa_fcs_vport_s *vport)
Jing Huang7725ccf2009-09-23 17:46:15 -07001025{
1026 lport->fcs = fcs;
1027 lport->fabric = bfa_fcs_vf_lookup(fcs, vf_id);
Jing Huang7725ccf2009-09-23 17:46:15 -07001028 lport->vport = vport;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001029 lport->lp_tag = (vport) ? vport->lps->bfa_tag :
1030 lport->fabric->lps->bfa_tag;
Jing Huang7725ccf2009-09-23 17:46:15 -07001031
1032 INIT_LIST_HEAD(&lport->rport_q);
1033 lport->num_rports = 0;
Krishna Gudipatie6714322010-03-03 17:44:02 -08001034}
Jing Huang7725ccf2009-09-23 17:46:15 -07001035
Jing Huang5fbe25c2010-10-18 17:17:23 -07001036/*
Krishna Gudipatie6714322010-03-03 17:44:02 -08001037 * Logical port initialization of base or virtual port.
1038 * Called by fabric for base port or by vport for virtual ports.
1039 */
1040
1041void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001042bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
1043 struct bfa_lport_cfg_s *port_cfg)
Krishna Gudipatie6714322010-03-03 17:44:02 -08001044{
1045 struct bfa_fcs_vport_s *vport = lport->vport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001046 struct bfad_s *bfad = (struct bfad_s *)lport->fcs->bfad;
1047 char lpwwn_buf[BFA_STRING_32];
Krishna Gudipatie6714322010-03-03 17:44:02 -08001048
Jing Huang6a18b162010-10-18 17:08:54 -07001049 lport->port_cfg = *port_cfg;
Krishna Gudipatie6714322010-03-03 17:44:02 -08001050
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001051 lport->bfad_port = bfa_fcb_lport_new(lport->fcs->bfad, lport,
1052 lport->port_cfg.roles,
1053 lport->fabric->vf_drv,
1054 vport ? vport->vport_drv : NULL);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001055
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001056 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(lport));
Jing Huang88166242010-12-09 17:11:53 -08001057 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001058 "New logical port created: WWN = %s Role = %s\n",
1059 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -07001060 bfa_fcs_lport_aen_post(lport, BFA_LPORT_AEN_NEW);
Jing Huang7725ccf2009-09-23 17:46:15 -07001061
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001062 bfa_sm_set_state(lport, bfa_fcs_lport_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -07001063 bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE);
1064}
1065
Jing Huang5fbe25c2010-10-18 17:17:23 -07001066/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001067 * fcs_lport_api
1068 */
1069
1070void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001071bfa_fcs_lport_get_attr(
1072 struct bfa_fcs_lport_s *port,
1073 struct bfa_lport_attr_s *port_attr)
Jing Huang7725ccf2009-09-23 17:46:15 -07001074{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001075 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
Jing Huang7725ccf2009-09-23 17:46:15 -07001076 port_attr->pid = port->pid;
1077 else
1078 port_attr->pid = 0;
1079
1080 port_attr->port_cfg = port->port_cfg;
1081
1082 if (port->fabric) {
Maggie Zhangf7f738122010-12-09 19:08:43 -08001083 port_attr->port_type = port->fabric->oper_type;
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001084 port_attr->loopback = bfa_sm_cmp_state(port->fabric,
1085 bfa_fcs_fabric_sm_loopback);
Krishna Gudipatif926a052010-03-05 19:36:00 -08001086 port_attr->authfail =
Maggie Zhangf7f738122010-12-09 19:08:43 -08001087 bfa_sm_cmp_state(port->fabric,
1088 bfa_fcs_fabric_sm_auth_failed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001089 port_attr->fabric_name = bfa_fcs_lport_get_fabric_name(port);
Jing Huang7725ccf2009-09-23 17:46:15 -07001090 memcpy(port_attr->fabric_ip_addr,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001091 bfa_fcs_lport_get_fabric_ipaddr(port),
1092 BFA_FCS_FABRIC_IPADDR_SZ);
Jing Huang7725ccf2009-09-23 17:46:15 -07001093
Krishna Gudipati86e32da2010-03-05 19:35:33 -08001094 if (port->vport != NULL) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001095 port_attr->port_type = BFA_PORT_TYPE_VPORT;
Krishna Gudipati86e32da2010-03-05 19:35:33 -08001096 port_attr->fpma_mac =
Maggie Zhangf7f738122010-12-09 19:08:43 -08001097 port->vport->lps->lp_mac;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001098 } else {
Krishna Gudipati86e32da2010-03-05 19:35:33 -08001099 port_attr->fpma_mac =
Maggie Zhangf7f738122010-12-09 19:08:43 -08001100 port->fabric->lps->lp_mac;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001101 }
Jing Huang7725ccf2009-09-23 17:46:15 -07001102 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001103 port_attr->port_type = BFA_PORT_TYPE_UNKNOWN;
1104 port_attr->state = BFA_LPORT_UNINIT;
Jing Huang7725ccf2009-09-23 17:46:15 -07001105 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001106}
1107
Jing Huang5fbe25c2010-10-18 17:17:23 -07001108/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001109 * bfa_fcs_lport_fab port fab functions
1110 */
1111
Jing Huang5fbe25c2010-10-18 17:17:23 -07001112/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001113 * Called by port to initialize fabric services of the base port.
1114 */
1115static void
1116bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port)
1117{
1118 bfa_fcs_lport_ns_init(port);
1119 bfa_fcs_lport_scn_init(port);
1120 bfa_fcs_lport_ms_init(port);
1121}
1122
Jing Huang5fbe25c2010-10-18 17:17:23 -07001123/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001124 * Called by port to notify transition to online state.
1125 */
1126static void
1127bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port)
1128{
1129 bfa_fcs_lport_ns_online(port);
1130 bfa_fcs_lport_scn_online(port);
1131}
1132
Jing Huang5fbe25c2010-10-18 17:17:23 -07001133/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001134 * Called by port to notify transition to offline state.
1135 */
1136static void
1137bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port)
1138{
1139 bfa_fcs_lport_ns_offline(port);
1140 bfa_fcs_lport_scn_offline(port);
1141 bfa_fcs_lport_ms_offline(port);
1142}
1143
Jing Huang5fbe25c2010-10-18 17:17:23 -07001144/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001145 * bfa_fcs_lport_n2n functions
1146 */
1147
Jing Huang5fbe25c2010-10-18 17:17:23 -07001148/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001149 * Called by fcs/port to initialize N2N topology.
1150 */
1151static void
1152bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port)
1153{
1154}
1155
Jing Huang5fbe25c2010-10-18 17:17:23 -07001156/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001157 * Called by fcs/port to notify transition to online state.
1158 */
1159static void
1160bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port)
1161{
1162 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1163 struct bfa_lport_cfg_s *pcfg = &port->port_cfg;
1164 struct bfa_fcs_rport_s *rport;
1165
1166 bfa_trc(port->fcs, pcfg->pwwn);
1167
1168 /*
1169 * If our PWWN is > than that of the r-port, we have to initiate PLOGI
1170 * and assign an Address. if not, we need to wait for its PLOGI.
1171 *
1172 * If our PWWN is < than that of the remote port, it will send a PLOGI
1173 * with the PIDs assigned. The rport state machine take care of this
1174 * incoming PLOGI.
1175 */
1176 if (memcmp
1177 ((void *)&pcfg->pwwn, (void *)&n2n_port->rem_port_wwn,
1178 sizeof(wwn_t)) > 0) {
1179 port->pid = N2N_LOCAL_PID;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001180 bfa_lps_set_n2n_pid(port->fabric->lps, N2N_LOCAL_PID);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001181 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001182 * First, check if we know the device by pwwn.
1183 */
1184 rport = bfa_fcs_lport_get_rport_by_pwwn(port,
1185 n2n_port->rem_port_wwn);
1186 if (rport) {
1187 bfa_trc(port->fcs, rport->pid);
1188 bfa_trc(port->fcs, rport->pwwn);
1189 rport->pid = N2N_REMOTE_PID;
Maggie Zhangf7f738122010-12-09 19:08:43 -08001190 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001191 return;
1192 }
1193
1194 /*
1195 * In n2n there can be only one rport. Delete the old one
1196 * whose pid should be zero, because it is offline.
1197 */
1198 if (port->num_rports > 0) {
1199 rport = bfa_fcs_lport_get_rport_by_pid(port, 0);
Jing Huangd4b671c2010-12-26 21:46:35 -08001200 WARN_ON(rport == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001201 if (rport) {
1202 bfa_trc(port->fcs, rport->pwwn);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001203 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001204 }
1205 }
1206 bfa_fcs_rport_create(port, N2N_REMOTE_PID);
1207 }
1208}
1209
Jing Huang5fbe25c2010-10-18 17:17:23 -07001210/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001211 * Called by fcs/port to notify transition to offline state.
1212 */
1213static void
1214bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port)
1215{
1216 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1217
1218 bfa_trc(port->fcs, port->pid);
1219 port->pid = 0;
1220 n2n_port->rem_port_wwn = 0;
1221 n2n_port->reply_oxid = 0;
1222}
1223
1224#define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
1225
1226/*
1227 * forward declarations
1228 */
1229static void bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg,
1230 struct bfa_fcxp_s *fcxp_alloced);
1231static void bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg,
1232 struct bfa_fcxp_s *fcxp_alloced);
1233static void bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg,
1234 struct bfa_fcxp_s *fcxp_alloced);
1235static void bfa_fcs_lport_fdmi_rhba_response(void *fcsarg,
1236 struct bfa_fcxp_s *fcxp,
1237 void *cbarg,
1238 bfa_status_t req_status,
1239 u32 rsp_len,
1240 u32 resid_len,
1241 struct fchs_s *rsp_fchs);
1242static void bfa_fcs_lport_fdmi_rprt_response(void *fcsarg,
1243 struct bfa_fcxp_s *fcxp,
1244 void *cbarg,
1245 bfa_status_t req_status,
1246 u32 rsp_len,
1247 u32 resid_len,
1248 struct fchs_s *rsp_fchs);
1249static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg,
1250 struct bfa_fcxp_s *fcxp,
1251 void *cbarg,
1252 bfa_status_t req_status,
1253 u32 rsp_len,
1254 u32 resid_len,
1255 struct fchs_s *rsp_fchs);
1256static void bfa_fcs_lport_fdmi_timeout(void *arg);
1257static u16 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1258 u8 *pyld);
1259static u16 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1260 u8 *pyld);
1261static u16 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1262 u8 *pyld);
1263static u16 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *
1264 fdmi, u8 *pyld);
1265static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1266 struct bfa_fcs_fdmi_hba_attr_s *hba_attr);
1267static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1268 struct bfa_fcs_fdmi_port_attr_s *port_attr);
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001269u32 bfa_fcs_fdmi_convert_speed(enum bfa_port_speed pport_speed);
1270
Jing Huang5fbe25c2010-10-18 17:17:23 -07001271/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001272 * fcs_fdmi_sm FCS FDMI state machine
1273 */
1274
Jing Huang5fbe25c2010-10-18 17:17:23 -07001275/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001276 * FDMI State Machine events
1277 */
1278enum port_fdmi_event {
1279 FDMISM_EVENT_PORT_ONLINE = 1,
1280 FDMISM_EVENT_PORT_OFFLINE = 2,
1281 FDMISM_EVENT_RSP_OK = 4,
1282 FDMISM_EVENT_RSP_ERROR = 5,
1283 FDMISM_EVENT_TIMEOUT = 6,
1284 FDMISM_EVENT_RHBA_SENT = 7,
1285 FDMISM_EVENT_RPRT_SENT = 8,
1286 FDMISM_EVENT_RPA_SENT = 9,
1287};
1288
1289static void bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1290 enum port_fdmi_event event);
1291static void bfa_fcs_lport_fdmi_sm_sending_rhba(
1292 struct bfa_fcs_lport_fdmi_s *fdmi,
1293 enum port_fdmi_event event);
1294static void bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1295 enum port_fdmi_event event);
1296static void bfa_fcs_lport_fdmi_sm_rhba_retry(
1297 struct bfa_fcs_lport_fdmi_s *fdmi,
1298 enum port_fdmi_event event);
1299static void bfa_fcs_lport_fdmi_sm_sending_rprt(
1300 struct bfa_fcs_lport_fdmi_s *fdmi,
1301 enum port_fdmi_event event);
1302static void bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1303 enum port_fdmi_event event);
1304static void bfa_fcs_lport_fdmi_sm_rprt_retry(
1305 struct bfa_fcs_lport_fdmi_s *fdmi,
1306 enum port_fdmi_event event);
1307static void bfa_fcs_lport_fdmi_sm_sending_rpa(
1308 struct bfa_fcs_lport_fdmi_s *fdmi,
1309 enum port_fdmi_event event);
1310static void bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1311 enum port_fdmi_event event);
1312static void bfa_fcs_lport_fdmi_sm_rpa_retry(
1313 struct bfa_fcs_lport_fdmi_s *fdmi,
1314 enum port_fdmi_event event);
1315static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1316 enum port_fdmi_event event);
1317static void bfa_fcs_lport_fdmi_sm_disabled(
1318 struct bfa_fcs_lport_fdmi_s *fdmi,
1319 enum port_fdmi_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001320/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001321 * Start in offline state - awaiting MS to send start.
1322 */
1323static void
1324bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1325 enum port_fdmi_event event)
1326{
1327 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1328
1329 bfa_trc(port->fcs, port->port_cfg.pwwn);
1330 bfa_trc(port->fcs, event);
1331
1332 fdmi->retry_cnt = 0;
1333
1334 switch (event) {
1335 case FDMISM_EVENT_PORT_ONLINE:
1336 if (port->vport) {
1337 /*
1338 * For Vports, register a new port.
1339 */
1340 bfa_sm_set_state(fdmi,
1341 bfa_fcs_lport_fdmi_sm_sending_rprt);
1342 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1343 } else {
1344 /*
1345 * For a base port, we should first register the HBA
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001346 * attribute. The HBA attribute also contains the base
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001347 * port registration.
1348 */
1349 bfa_sm_set_state(fdmi,
1350 bfa_fcs_lport_fdmi_sm_sending_rhba);
1351 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1352 }
1353 break;
1354
1355 case FDMISM_EVENT_PORT_OFFLINE:
1356 break;
1357
1358 default:
1359 bfa_sm_fault(port->fcs, event);
1360 }
1361}
1362
1363static void
1364bfa_fcs_lport_fdmi_sm_sending_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1365 enum port_fdmi_event event)
1366{
1367 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1368
1369 bfa_trc(port->fcs, port->port_cfg.pwwn);
1370 bfa_trc(port->fcs, event);
1371
1372 switch (event) {
1373 case FDMISM_EVENT_RHBA_SENT:
1374 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rhba);
1375 break;
1376
1377 case FDMISM_EVENT_PORT_OFFLINE:
1378 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1379 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1380 &fdmi->fcxp_wqe);
1381 break;
1382
1383 default:
1384 bfa_sm_fault(port->fcs, event);
1385 }
1386}
1387
1388static void
1389bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1390 enum port_fdmi_event event)
1391{
1392 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1393
1394 bfa_trc(port->fcs, port->port_cfg.pwwn);
1395 bfa_trc(port->fcs, event);
1396
1397 switch (event) {
1398 case FDMISM_EVENT_RSP_ERROR:
1399 /*
1400 * if max retries have not been reached, start timer for a
1401 * delayed retry
1402 */
1403 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1404 bfa_sm_set_state(fdmi,
1405 bfa_fcs_lport_fdmi_sm_rhba_retry);
1406 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1407 &fdmi->timer,
1408 bfa_fcs_lport_fdmi_timeout, fdmi,
1409 BFA_FCS_RETRY_TIMEOUT);
1410 } else {
1411 /*
1412 * set state to offline
1413 */
1414 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1415 }
1416 break;
1417
1418 case FDMISM_EVENT_RSP_OK:
1419 /*
1420 * Initiate Register Port Attributes
1421 */
1422 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1423 fdmi->retry_cnt = 0;
1424 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1425 break;
1426
1427 case FDMISM_EVENT_PORT_OFFLINE:
1428 bfa_fcxp_discard(fdmi->fcxp);
1429 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1430 break;
1431
1432 default:
1433 bfa_sm_fault(port->fcs, event);
1434 }
1435}
1436
1437static void
1438bfa_fcs_lport_fdmi_sm_rhba_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1439 enum port_fdmi_event event)
1440{
1441 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1442
1443 bfa_trc(port->fcs, port->port_cfg.pwwn);
1444 bfa_trc(port->fcs, event);
1445
1446 switch (event) {
1447 case FDMISM_EVENT_TIMEOUT:
1448 /*
1449 * Retry Timer Expired. Re-send
1450 */
1451 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rhba);
1452 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1453 break;
1454
1455 case FDMISM_EVENT_PORT_OFFLINE:
1456 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1457 bfa_timer_stop(&fdmi->timer);
1458 break;
1459
1460 default:
1461 bfa_sm_fault(port->fcs, event);
1462 }
1463}
1464
1465/*
1466* RPRT : Register Port
1467 */
1468static void
1469bfa_fcs_lport_fdmi_sm_sending_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1470 enum port_fdmi_event event)
1471{
1472 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1473
1474 bfa_trc(port->fcs, port->port_cfg.pwwn);
1475 bfa_trc(port->fcs, event);
1476
1477 switch (event) {
1478 case FDMISM_EVENT_RPRT_SENT:
1479 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rprt);
1480 break;
1481
1482 case FDMISM_EVENT_PORT_OFFLINE:
1483 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1484 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1485 &fdmi->fcxp_wqe);
1486 break;
1487
1488 default:
1489 bfa_sm_fault(port->fcs, event);
1490 }
1491}
1492
1493static void
1494bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1495 enum port_fdmi_event event)
1496{
1497 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1498
1499 bfa_trc(port->fcs, port->port_cfg.pwwn);
1500 bfa_trc(port->fcs, event);
1501
1502 switch (event) {
1503 case FDMISM_EVENT_RSP_ERROR:
1504 /*
1505 * if max retries have not been reached, start timer for a
1506 * delayed retry
1507 */
1508 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1509 bfa_sm_set_state(fdmi,
1510 bfa_fcs_lport_fdmi_sm_rprt_retry);
1511 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1512 &fdmi->timer,
1513 bfa_fcs_lport_fdmi_timeout, fdmi,
1514 BFA_FCS_RETRY_TIMEOUT);
1515
1516 } else {
1517 /*
1518 * set state to offline
1519 */
1520 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1521 fdmi->retry_cnt = 0;
1522 }
1523 break;
1524
1525 case FDMISM_EVENT_RSP_OK:
1526 fdmi->retry_cnt = 0;
1527 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1528 break;
1529
1530 case FDMISM_EVENT_PORT_OFFLINE:
1531 bfa_fcxp_discard(fdmi->fcxp);
1532 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1533 break;
1534
1535 default:
1536 bfa_sm_fault(port->fcs, event);
1537 }
1538}
1539
1540static void
1541bfa_fcs_lport_fdmi_sm_rprt_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1542 enum port_fdmi_event event)
1543{
1544 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1545
1546 bfa_trc(port->fcs, port->port_cfg.pwwn);
1547 bfa_trc(port->fcs, event);
1548
1549 switch (event) {
1550 case FDMISM_EVENT_TIMEOUT:
1551 /*
1552 * Retry Timer Expired. Re-send
1553 */
1554 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rprt);
1555 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1556 break;
1557
1558 case FDMISM_EVENT_PORT_OFFLINE:
1559 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1560 bfa_timer_stop(&fdmi->timer);
1561 break;
1562
1563 default:
1564 bfa_sm_fault(port->fcs, event);
1565 }
1566}
1567
1568/*
1569 * Register Port Attributes
1570 */
1571static void
1572bfa_fcs_lport_fdmi_sm_sending_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1573 enum port_fdmi_event event)
1574{
1575 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1576
1577 bfa_trc(port->fcs, port->port_cfg.pwwn);
1578 bfa_trc(port->fcs, event);
1579
1580 switch (event) {
1581 case FDMISM_EVENT_RPA_SENT:
1582 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa);
1583 break;
1584
1585 case FDMISM_EVENT_PORT_OFFLINE:
1586 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1587 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1588 &fdmi->fcxp_wqe);
1589 break;
1590
1591 default:
1592 bfa_sm_fault(port->fcs, event);
1593 }
1594}
1595
1596static void
1597bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1598 enum port_fdmi_event event)
1599{
1600 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1601
1602 bfa_trc(port->fcs, port->port_cfg.pwwn);
1603 bfa_trc(port->fcs, event);
1604
1605 switch (event) {
1606 case FDMISM_EVENT_RSP_ERROR:
1607 /*
1608 * if max retries have not been reached, start timer for a
1609 * delayed retry
1610 */
1611 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1612 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa_retry);
1613 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1614 &fdmi->timer,
1615 bfa_fcs_lport_fdmi_timeout, fdmi,
1616 BFA_FCS_RETRY_TIMEOUT);
1617 } else {
1618 /*
1619 * set state to offline
1620 */
1621 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1622 fdmi->retry_cnt = 0;
1623 }
1624 break;
1625
1626 case FDMISM_EVENT_RSP_OK:
1627 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1628 fdmi->retry_cnt = 0;
1629 break;
1630
1631 case FDMISM_EVENT_PORT_OFFLINE:
1632 bfa_fcxp_discard(fdmi->fcxp);
1633 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1634 break;
1635
1636 default:
1637 bfa_sm_fault(port->fcs, event);
1638 }
1639}
1640
1641static void
1642bfa_fcs_lport_fdmi_sm_rpa_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1643 enum port_fdmi_event event)
1644{
1645 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1646
1647 bfa_trc(port->fcs, port->port_cfg.pwwn);
1648 bfa_trc(port->fcs, event);
1649
1650 switch (event) {
1651 case FDMISM_EVENT_TIMEOUT:
1652 /*
1653 * Retry Timer Expired. Re-send
1654 */
1655 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1656 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1657 break;
1658
1659 case FDMISM_EVENT_PORT_OFFLINE:
1660 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1661 bfa_timer_stop(&fdmi->timer);
1662 break;
1663
1664 default:
1665 bfa_sm_fault(port->fcs, event);
1666 }
1667}
1668
1669static void
1670bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1671 enum port_fdmi_event event)
1672{
1673 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1674
1675 bfa_trc(port->fcs, port->port_cfg.pwwn);
1676 bfa_trc(port->fcs, event);
1677
1678 switch (event) {
1679 case FDMISM_EVENT_PORT_OFFLINE:
1680 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1681 break;
1682
1683 default:
1684 bfa_sm_fault(port->fcs, event);
1685 }
1686}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001687/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001688 * FDMI is disabled state.
1689 */
1690static void
1691bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s *fdmi,
1692 enum port_fdmi_event event)
1693{
1694 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1695
1696 bfa_trc(port->fcs, port->port_cfg.pwwn);
1697 bfa_trc(port->fcs, event);
1698
1699 /* No op State. It can only be enabled at Driver Init. */
1700}
1701
Jing Huang5fbe25c2010-10-18 17:17:23 -07001702/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001703* RHBA : Register HBA Attributes.
1704 */
1705static void
1706bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1707{
1708 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
1709 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1710 struct fchs_s fchs;
1711 int len, attr_len;
1712 struct bfa_fcxp_s *fcxp;
1713 u8 *pyld;
1714
1715 bfa_trc(port->fcs, port->port_cfg.pwwn);
1716
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001717 fcxp = fcxp_alloced ? fcxp_alloced :
1718 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001719 if (!fcxp) {
1720 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001721 bfa_fcs_lport_fdmi_send_rhba, fdmi, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001722 return;
1723 }
1724 fdmi->fcxp = fcxp;
1725
1726 pyld = bfa_fcxp_get_reqbuf(fcxp);
Jing Huang6a18b162010-10-18 17:08:54 -07001727 memset(pyld, 0, FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001728
1729 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
1730 FDMI_RHBA);
1731
1732 attr_len =
1733 bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi,
1734 (u8 *) ((struct ct_hdr_s *) pyld
1735 + 1));
1736
1737 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1738 FC_CLASS_3, (len + attr_len), &fchs,
1739 bfa_fcs_lport_fdmi_rhba_response, (void *)fdmi,
1740 FC_MAX_PDUSZ, FC_FCCT_TOV);
1741
1742 bfa_sm_send_event(fdmi, FDMISM_EVENT_RHBA_SENT);
1743}
1744
1745static u16
1746bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1747{
1748 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1749 struct bfa_fcs_fdmi_hba_attr_s hba_attr;
1750 struct bfa_fcs_fdmi_hba_attr_s *fcs_hba_attr = &hba_attr;
1751 struct fdmi_rhba_s *rhba = (struct fdmi_rhba_s *) pyld;
1752 struct fdmi_attr_s *attr;
1753 u8 *curr_ptr;
1754 u16 len, count;
Maggie50444a32010-11-29 18:26:32 -08001755 u16 templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001756
1757 /*
1758 * get hba attributes
1759 */
1760 bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr);
1761
1762 rhba->hba_id = bfa_fcs_lport_get_pwwn(port);
Jing Huangba816ea2010-10-18 17:10:50 -07001763 rhba->port_list.num_ports = cpu_to_be32(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001764 rhba->port_list.port_entry = bfa_fcs_lport_get_pwwn(port);
1765
1766 len = sizeof(rhba->hba_id) + sizeof(rhba->port_list);
1767
1768 count = 0;
1769 len += sizeof(rhba->hba_attr_blk.attr_count);
1770
1771 /*
1772 * fill out the invididual entries of the HBA attrib Block
1773 */
1774 curr_ptr = (u8 *) &rhba->hba_attr_blk.hba_attr;
1775
1776 /*
1777 * Node Name
1778 */
1779 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001780 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME);
Maggie50444a32010-11-29 18:26:32 -08001781 templen = sizeof(wwn_t);
1782 memcpy(attr->value, &bfa_fcs_lport_get_nwwn(port), templen);
1783 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1784 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001785 count++;
Maggie50444a32010-11-29 18:26:32 -08001786 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1787 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001788
1789 /*
1790 * Manufacturer
1791 */
1792 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001793 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MANUFACTURER);
Maggie50444a32010-11-29 18:26:32 -08001794 templen = (u16) strlen(fcs_hba_attr->manufacturer);
1795 memcpy(attr->value, fcs_hba_attr->manufacturer, templen);
1796 templen = fc_roundup(templen, sizeof(u32));
1797 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1798 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001799 count++;
Maggie50444a32010-11-29 18:26:32 -08001800 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1801 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001802
1803 /*
1804 * Serial Number
1805 */
1806 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001807 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_SERIALNUM);
Maggie50444a32010-11-29 18:26:32 -08001808 templen = (u16) strlen(fcs_hba_attr->serial_num);
1809 memcpy(attr->value, fcs_hba_attr->serial_num, templen);
1810 templen = fc_roundup(templen, sizeof(u32));
1811 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1812 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001813 count++;
Maggie50444a32010-11-29 18:26:32 -08001814 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1815 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001816
1817 /*
1818 * Model
1819 */
1820 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001821 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL);
Maggie50444a32010-11-29 18:26:32 -08001822 templen = (u16) strlen(fcs_hba_attr->model);
1823 memcpy(attr->value, fcs_hba_attr->model, templen);
1824 templen = fc_roundup(templen, sizeof(u32));
1825 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1826 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001827 count++;
Maggie50444a32010-11-29 18:26:32 -08001828 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1829 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001830
1831 /*
1832 * Model Desc
1833 */
1834 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001835 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC);
Maggie50444a32010-11-29 18:26:32 -08001836 templen = (u16) strlen(fcs_hba_attr->model_desc);
1837 memcpy(attr->value, fcs_hba_attr->model_desc, templen);
1838 templen = fc_roundup(templen, sizeof(u32));
1839 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1840 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001841 count++;
Maggie50444a32010-11-29 18:26:32 -08001842 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1843 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001844
1845 /*
1846 * H/W Version
1847 */
1848 if (fcs_hba_attr->hw_version[0] != '\0') {
1849 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001850 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION);
Maggie50444a32010-11-29 18:26:32 -08001851 templen = (u16) strlen(fcs_hba_attr->hw_version);
1852 memcpy(attr->value, fcs_hba_attr->hw_version, templen);
1853 templen = fc_roundup(templen, sizeof(u32));
1854 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1855 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001856 count++;
Maggie50444a32010-11-29 18:26:32 -08001857 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1858 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001859 }
1860
1861 /*
1862 * Driver Version
1863 */
1864 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001865 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION);
Maggie50444a32010-11-29 18:26:32 -08001866 templen = (u16) strlen(fcs_hba_attr->driver_version);
1867 memcpy(attr->value, fcs_hba_attr->driver_version, templen);
1868 templen = fc_roundup(templen, sizeof(u32));
1869 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07001870 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001871 count++;
Maggie50444a32010-11-29 18:26:32 -08001872 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1873 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001874
1875 /*
1876 * Option Rom Version
1877 */
1878 if (fcs_hba_attr->option_rom_ver[0] != '\0') {
1879 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001880 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION);
Maggie50444a32010-11-29 18:26:32 -08001881 templen = (u16) strlen(fcs_hba_attr->option_rom_ver);
1882 memcpy(attr->value, fcs_hba_attr->option_rom_ver, templen);
1883 templen = fc_roundup(templen, sizeof(u32));
1884 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1885 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001886 count++;
Maggie50444a32010-11-29 18:26:32 -08001887 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1888 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001889 }
1890
1891 /*
1892 * f/w Version = driver version
1893 */
1894 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001895 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION);
Maggie50444a32010-11-29 18:26:32 -08001896 templen = (u16) strlen(fcs_hba_attr->driver_version);
1897 memcpy(attr->value, fcs_hba_attr->driver_version, templen);
1898 templen = fc_roundup(templen, sizeof(u32));
1899 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1900 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001901 count++;
Maggie50444a32010-11-29 18:26:32 -08001902 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1903 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001904
1905 /*
1906 * OS Name
1907 */
1908 if (fcs_hba_attr->os_name[0] != '\0') {
1909 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001910 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME);
Maggie50444a32010-11-29 18:26:32 -08001911 templen = (u16) strlen(fcs_hba_attr->os_name);
1912 memcpy(attr->value, fcs_hba_attr->os_name, templen);
1913 templen = fc_roundup(templen, sizeof(u32));
1914 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1915 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001916 count++;
Maggie50444a32010-11-29 18:26:32 -08001917 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1918 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001919 }
1920
1921 /*
1922 * MAX_CT_PAYLOAD
1923 */
1924 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001925 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT);
Maggie50444a32010-11-29 18:26:32 -08001926 templen = sizeof(fcs_hba_attr->max_ct_pyld);
1927 memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, templen);
1928 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001929 count++;
Maggie50444a32010-11-29 18:26:32 -08001930 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1931 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001932
1933 /*
1934 * Update size of payload
1935 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07001936 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001937
Jing Huangba816ea2010-10-18 17:10:50 -07001938 rhba->hba_attr_blk.attr_count = cpu_to_be32(count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001939 return len;
1940}
1941
1942static void
1943bfa_fcs_lport_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
1944 void *cbarg, bfa_status_t req_status,
1945 u32 rsp_len, u32 resid_len,
1946 struct fchs_s *rsp_fchs)
1947{
1948 struct bfa_fcs_lport_fdmi_s *fdmi =
1949 (struct bfa_fcs_lport_fdmi_s *) cbarg;
1950 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1951 struct ct_hdr_s *cthdr = NULL;
1952
1953 bfa_trc(port->fcs, port->port_cfg.pwwn);
1954
1955 /*
1956 * Sanity Checks
1957 */
1958 if (req_status != BFA_STATUS_OK) {
1959 bfa_trc(port->fcs, req_status);
1960 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
1961 return;
1962 }
1963
1964 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07001965 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001966
1967 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1968 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
1969 return;
1970 }
1971
1972 bfa_trc(port->fcs, cthdr->reason_code);
1973 bfa_trc(port->fcs, cthdr->exp_code);
1974 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
1975}
1976
Jing Huang5fbe25c2010-10-18 17:17:23 -07001977/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001978* RPRT : Register Port
1979 */
1980static void
1981bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1982{
1983 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
1984 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1985 struct fchs_s fchs;
1986 u16 len, attr_len;
1987 struct bfa_fcxp_s *fcxp;
1988 u8 *pyld;
1989
1990 bfa_trc(port->fcs, port->port_cfg.pwwn);
1991
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001992 fcxp = fcxp_alloced ? fcxp_alloced :
1993 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001994 if (!fcxp) {
1995 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001996 bfa_fcs_lport_fdmi_send_rprt, fdmi, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001997 return;
1998 }
1999 fdmi->fcxp = fcxp;
2000
2001 pyld = bfa_fcxp_get_reqbuf(fcxp);
Jing Huang6a18b162010-10-18 17:08:54 -07002002 memset(pyld, 0, FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002003
2004 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2005 FDMI_RPRT);
2006
2007 attr_len =
2008 bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi,
2009 (u8 *) ((struct ct_hdr_s *) pyld
2010 + 1));
2011
2012 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2013 FC_CLASS_3, len + attr_len, &fchs,
2014 bfa_fcs_lport_fdmi_rprt_response, (void *)fdmi,
2015 FC_MAX_PDUSZ, FC_FCCT_TOV);
2016
2017 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT);
2018}
2019
Jing Huang5fbe25c2010-10-18 17:17:23 -07002020/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002021 * This routine builds Port Attribute Block that used in RPA, RPRT commands.
2022 */
2023static u16
2024bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
2025 u8 *pyld)
2026{
2027 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
2028 struct fdmi_port_attr_s *port_attrib = (struct fdmi_port_attr_s *) pyld;
2029 struct fdmi_attr_s *attr;
2030 u8 *curr_ptr;
2031 u16 len;
2032 u8 count = 0;
Maggie50444a32010-11-29 18:26:32 -08002033 u16 templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002034
2035 /*
2036 * get port attributes
2037 */
2038 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2039
2040 len = sizeof(port_attrib->attr_count);
2041
2042 /*
2043 * fill out the invididual entries
2044 */
2045 curr_ptr = (u8 *) &port_attrib->port_attr;
2046
2047 /*
2048 * FC4 Types
2049 */
2050 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002051 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FC4_TYPES);
Maggie50444a32010-11-29 18:26:32 -08002052 templen = sizeof(fcs_port_attr.supp_fc4_types);
2053 memcpy(attr->value, fcs_port_attr.supp_fc4_types, templen);
2054 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2055 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002056 ++count;
2057 attr->len =
Maggie50444a32010-11-29 18:26:32 -08002058 cpu_to_be16(templen + sizeof(attr->type) +
2059 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002060
2061 /*
2062 * Supported Speed
2063 */
2064 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002065 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_SPEED);
Maggie50444a32010-11-29 18:26:32 -08002066 templen = sizeof(fcs_port_attr.supp_speed);
2067 memcpy(attr->value, &fcs_port_attr.supp_speed, templen);
2068 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2069 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002070 ++count;
2071 attr->len =
Maggie50444a32010-11-29 18:26:32 -08002072 cpu_to_be16(templen + sizeof(attr->type) +
2073 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002074
2075 /*
2076 * current Port Speed
2077 */
2078 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002079 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED);
Maggie50444a32010-11-29 18:26:32 -08002080 templen = sizeof(fcs_port_attr.curr_speed);
2081 memcpy(attr->value, &fcs_port_attr.curr_speed, templen);
2082 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2083 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002084 ++count;
Maggie50444a32010-11-29 18:26:32 -08002085 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2086 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002087
2088 /*
2089 * max frame size
2090 */
2091 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002092 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE);
Maggie50444a32010-11-29 18:26:32 -08002093 templen = sizeof(fcs_port_attr.max_frm_size);
2094 memcpy(attr->value, &fcs_port_attr.max_frm_size, templen);
2095 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2096 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002097 ++count;
Maggie50444a32010-11-29 18:26:32 -08002098 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2099 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002100
2101 /*
2102 * OS Device Name
2103 */
2104 if (fcs_port_attr.os_device_name[0] != '\0') {
2105 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002106 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME);
Maggie50444a32010-11-29 18:26:32 -08002107 templen = (u16) strlen(fcs_port_attr.os_device_name);
2108 memcpy(attr->value, fcs_port_attr.os_device_name, templen);
2109 templen = fc_roundup(templen, sizeof(u32));
2110 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2111 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002112 ++count;
Maggie50444a32010-11-29 18:26:32 -08002113 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2114 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002115 }
2116 /*
2117 * Host Name
2118 */
2119 if (fcs_port_attr.host_name[0] != '\0') {
2120 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002121 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME);
Maggie50444a32010-11-29 18:26:32 -08002122 templen = (u16) strlen(fcs_port_attr.host_name);
2123 memcpy(attr->value, fcs_port_attr.host_name, templen);
2124 templen = fc_roundup(templen, sizeof(u32));
2125 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2126 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002127 ++count;
Maggie50444a32010-11-29 18:26:32 -08002128 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2129 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002130 }
2131
2132 /*
2133 * Update size of payload
2134 */
Jing Huangba816ea2010-10-18 17:10:50 -07002135 port_attrib->attr_count = cpu_to_be32(count);
Jing Huang5fbe25c2010-10-18 17:17:23 -07002136 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002137 return len;
2138}
2139
2140static u16
2141bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2142{
2143 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2144 struct fdmi_rprt_s *rprt = (struct fdmi_rprt_s *) pyld;
2145 u16 len;
2146
2147 rprt->hba_id = bfa_fcs_lport_get_pwwn(bfa_fcs_get_base_port(port->fcs));
2148 rprt->port_name = bfa_fcs_lport_get_pwwn(port);
2149
2150 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2151 (u8 *) &rprt->port_attr_blk);
2152
2153 len += sizeof(rprt->hba_id) + sizeof(rprt->port_name);
2154
2155 return len;
2156}
2157
2158static void
2159bfa_fcs_lport_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2160 void *cbarg, bfa_status_t req_status,
2161 u32 rsp_len, u32 resid_len,
2162 struct fchs_s *rsp_fchs)
2163{
2164 struct bfa_fcs_lport_fdmi_s *fdmi =
2165 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2166 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2167 struct ct_hdr_s *cthdr = NULL;
2168
2169 bfa_trc(port->fcs, port->port_cfg.pwwn);
2170
2171 /*
2172 * Sanity Checks
2173 */
2174 if (req_status != BFA_STATUS_OK) {
2175 bfa_trc(port->fcs, req_status);
2176 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2177 return;
2178 }
2179
2180 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07002181 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002182
2183 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2184 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2185 return;
2186 }
2187
2188 bfa_trc(port->fcs, cthdr->reason_code);
2189 bfa_trc(port->fcs, cthdr->exp_code);
2190 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2191}
2192
Jing Huang5fbe25c2010-10-18 17:17:23 -07002193/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002194* RPA : Register Port Attributes.
2195 */
2196static void
2197bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2198{
2199 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2200 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2201 struct fchs_s fchs;
2202 u16 len, attr_len;
2203 struct bfa_fcxp_s *fcxp;
2204 u8 *pyld;
2205
2206 bfa_trc(port->fcs, port->port_cfg.pwwn);
2207
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002208 fcxp = fcxp_alloced ? fcxp_alloced :
2209 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002210 if (!fcxp) {
2211 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002212 bfa_fcs_lport_fdmi_send_rpa, fdmi, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002213 return;
2214 }
2215 fdmi->fcxp = fcxp;
2216
2217 pyld = bfa_fcxp_get_reqbuf(fcxp);
Jing Huang6a18b162010-10-18 17:08:54 -07002218 memset(pyld, 0, FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002219
2220 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2221 FDMI_RPA);
2222
Jing Huang5fbe25c2010-10-18 17:17:23 -07002223 attr_len = bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi,
2224 (u8 *) ((struct ct_hdr_s *) pyld + 1));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002225
2226 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2227 FC_CLASS_3, len + attr_len, &fchs,
2228 bfa_fcs_lport_fdmi_rpa_response, (void *)fdmi,
2229 FC_MAX_PDUSZ, FC_FCCT_TOV);
2230
2231 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPA_SENT);
2232}
2233
2234static u16
2235bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2236{
2237 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2238 struct fdmi_rpa_s *rpa = (struct fdmi_rpa_s *) pyld;
2239 u16 len;
2240
2241 rpa->port_name = bfa_fcs_lport_get_pwwn(port);
2242
2243 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2244 (u8 *) &rpa->port_attr_blk);
2245
2246 len += sizeof(rpa->port_name);
2247
2248 return len;
2249}
2250
2251static void
2252bfa_fcs_lport_fdmi_rpa_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2253 void *cbarg, bfa_status_t req_status, u32 rsp_len,
2254 u32 resid_len, struct fchs_s *rsp_fchs)
2255{
2256 struct bfa_fcs_lport_fdmi_s *fdmi =
2257 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2258 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2259 struct ct_hdr_s *cthdr = NULL;
2260
2261 bfa_trc(port->fcs, port->port_cfg.pwwn);
2262
2263 /*
2264 * Sanity Checks
2265 */
2266 if (req_status != BFA_STATUS_OK) {
2267 bfa_trc(port->fcs, req_status);
2268 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2269 return;
2270 }
2271
2272 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07002273 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002274
2275 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2276 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2277 return;
2278 }
2279
2280 bfa_trc(port->fcs, cthdr->reason_code);
2281 bfa_trc(port->fcs, cthdr->exp_code);
2282 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2283}
2284
2285static void
2286bfa_fcs_lport_fdmi_timeout(void *arg)
2287{
2288 struct bfa_fcs_lport_fdmi_s *fdmi = (struct bfa_fcs_lport_fdmi_s *) arg;
2289
2290 bfa_sm_send_event(fdmi, FDMISM_EVENT_TIMEOUT);
2291}
2292
Maggie52f94b62010-11-29 18:21:32 -08002293static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002294bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2295 struct bfa_fcs_fdmi_hba_attr_s *hba_attr)
2296{
2297 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2298 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2299
Jing Huang6a18b162010-10-18 17:08:54 -07002300 memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002301
2302 bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc,
2303 hba_attr->manufacturer);
2304 bfa_ioc_get_adapter_serial_num(&port->fcs->bfa->ioc,
2305 hba_attr->serial_num);
2306 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2307 hba_attr->model);
2308 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2309 hba_attr->model_desc);
2310 bfa_ioc_get_pci_chip_rev(&port->fcs->bfa->ioc,
2311 hba_attr->hw_version);
2312 bfa_ioc_get_adapter_optrom_ver(&port->fcs->bfa->ioc,
2313 hba_attr->option_rom_ver);
2314 bfa_ioc_get_adapter_fw_ver(&port->fcs->bfa->ioc,
2315 hba_attr->fw_version);
2316
2317 strncpy(hba_attr->driver_version, (char *)driver_info->version,
2318 sizeof(hba_attr->driver_version));
2319
2320 strncpy(hba_attr->os_name, driver_info->host_os_name,
2321 sizeof(hba_attr->os_name));
2322
2323 /*
2324 * If there is a patch level, append it
2325 * to the os name along with a separator
2326 */
2327 if (driver_info->host_os_patch[0] != '\0') {
2328 strncat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
2329 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
2330 strncat(hba_attr->os_name, driver_info->host_os_patch,
2331 sizeof(driver_info->host_os_patch));
2332 }
2333
Jing Huangba816ea2010-10-18 17:10:50 -07002334 hba_attr->max_ct_pyld = cpu_to_be32(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002335}
2336
Maggie52f94b62010-11-29 18:21:32 -08002337static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002338bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2339 struct bfa_fcs_fdmi_port_attr_s *port_attr)
2340{
2341 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2342 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2343 struct bfa_port_attr_s pport_attr;
2344
Jing Huang6a18b162010-10-18 17:08:54 -07002345 memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002346
2347 /*
2348 * get pport attributes from hal
2349 */
2350 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
2351
2352 /*
2353 * get FC4 type Bitmask
2354 */
2355 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->supp_fc4_types);
2356
2357 /*
2358 * Supported Speeds
2359 */
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002360 switch (pport_attr.speed_supported) {
2361 case BFA_PORT_SPEED_16GBPS:
2362 port_attr->supp_speed =
2363 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_16G);
2364 break;
2365
2366 case BFA_PORT_SPEED_10GBPS:
2367 port_attr->supp_speed =
2368 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_10G);
2369 break;
2370
2371 case BFA_PORT_SPEED_8GBPS:
2372 port_attr->supp_speed =
2373 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_8G);
2374 break;
2375
2376 case BFA_PORT_SPEED_4GBPS:
2377 port_attr->supp_speed =
2378 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_4G);
2379 break;
2380
2381 default:
2382 bfa_sm_fault(port->fcs, pport_attr.speed_supported);
2383 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002384
2385 /*
2386 * Current Speed
2387 */
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002388 port_attr->curr_speed = cpu_to_be32(
2389 bfa_fcs_fdmi_convert_speed(pport_attr.speed));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002390
2391 /*
2392 * Max PDU Size.
2393 */
Jing Huangba816ea2010-10-18 17:10:50 -07002394 port_attr->max_frm_size = cpu_to_be32(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002395
2396 /*
2397 * OS device Name
2398 */
2399 strncpy(port_attr->os_device_name, (char *)driver_info->os_device_name,
2400 sizeof(port_attr->os_device_name));
2401
2402 /*
2403 * Host name
2404 */
2405 strncpy(port_attr->host_name, (char *)driver_info->host_machine_name,
2406 sizeof(port_attr->host_name));
Jing Huang7725ccf2009-09-23 17:46:15 -07002407
2408}
2409
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002410/*
2411 * Convert BFA speed to FDMI format.
2412 */
2413u32
2414bfa_fcs_fdmi_convert_speed(bfa_port_speed_t pport_speed)
2415{
2416 u32 ret;
2417
2418 switch (pport_speed) {
2419 case BFA_PORT_SPEED_1GBPS:
2420 case BFA_PORT_SPEED_2GBPS:
2421 ret = pport_speed;
2422 break;
2423
2424 case BFA_PORT_SPEED_4GBPS:
2425 ret = FDMI_TRANS_SPEED_4G;
2426 break;
2427
2428 case BFA_PORT_SPEED_8GBPS:
2429 ret = FDMI_TRANS_SPEED_8G;
2430 break;
2431
2432 case BFA_PORT_SPEED_10GBPS:
2433 ret = FDMI_TRANS_SPEED_10G;
2434 break;
2435
2436 case BFA_PORT_SPEED_16GBPS:
2437 ret = FDMI_TRANS_SPEED_16G;
2438 break;
2439
2440 default:
2441 ret = FDMI_TRANS_SPEED_UNKNOWN;
2442 }
2443 return ret;
2444}
Jing Huang7725ccf2009-09-23 17:46:15 -07002445
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002446void
2447bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s *ms)
2448{
2449 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2450
2451 fdmi->ms = ms;
2452 if (ms->port->fcs->fdmi_enabled)
2453 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
2454 else
2455 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_disabled);
2456}
2457
2458void
2459bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s *ms)
2460{
2461 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2462
2463 fdmi->ms = ms;
2464 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
2465}
2466
2467void
2468bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s *ms)
2469{
2470 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2471
2472 fdmi->ms = ms;
2473 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_ONLINE);
2474}
2475
2476#define BFA_FCS_MS_CMD_MAX_RETRIES 2
2477
2478/*
2479 * forward declarations
2480 */
2481static void bfa_fcs_lport_ms_send_plogi(void *ms_cbarg,
2482 struct bfa_fcxp_s *fcxp_alloced);
2483static void bfa_fcs_lport_ms_timeout(void *arg);
2484static void bfa_fcs_lport_ms_plogi_response(void *fcsarg,
2485 struct bfa_fcxp_s *fcxp,
2486 void *cbarg,
2487 bfa_status_t req_status,
2488 u32 rsp_len,
2489 u32 resid_len,
2490 struct fchs_s *rsp_fchs);
2491
2492static void bfa_fcs_lport_ms_send_gmal(void *ms_cbarg,
2493 struct bfa_fcxp_s *fcxp_alloced);
2494static void bfa_fcs_lport_ms_gmal_response(void *fcsarg,
2495 struct bfa_fcxp_s *fcxp,
2496 void *cbarg,
2497 bfa_status_t req_status,
2498 u32 rsp_len,
2499 u32 resid_len,
2500 struct fchs_s *rsp_fchs);
2501static void bfa_fcs_lport_ms_send_gfn(void *ms_cbarg,
2502 struct bfa_fcxp_s *fcxp_alloced);
2503static void bfa_fcs_lport_ms_gfn_response(void *fcsarg,
2504 struct bfa_fcxp_s *fcxp,
2505 void *cbarg,
2506 bfa_status_t req_status,
2507 u32 rsp_len,
2508 u32 resid_len,
2509 struct fchs_s *rsp_fchs);
Jing Huang5fbe25c2010-10-18 17:17:23 -07002510/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002511 * fcs_ms_sm FCS MS state machine
2512 */
2513
Jing Huang5fbe25c2010-10-18 17:17:23 -07002514/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002515 * MS State Machine events
2516 */
2517enum port_ms_event {
2518 MSSM_EVENT_PORT_ONLINE = 1,
2519 MSSM_EVENT_PORT_OFFLINE = 2,
2520 MSSM_EVENT_RSP_OK = 3,
2521 MSSM_EVENT_RSP_ERROR = 4,
2522 MSSM_EVENT_TIMEOUT = 5,
2523 MSSM_EVENT_FCXP_SENT = 6,
2524 MSSM_EVENT_PORT_FABRIC_RSCN = 7
2525};
2526
2527static void bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2528 enum port_ms_event event);
2529static void bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2530 enum port_ms_event event);
2531static void bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2532 enum port_ms_event event);
2533static void bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2534 enum port_ms_event event);
2535static void bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
2536 enum port_ms_event event);
2537static void bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
2538 enum port_ms_event event);
2539static void bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
2540 enum port_ms_event event);
2541static void bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
2542 enum port_ms_event event);
2543static void bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
2544 enum port_ms_event event);
2545static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
2546 enum port_ms_event event);
2547static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
2548 enum port_ms_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -07002549/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002550 * Start in offline state - awaiting NS to send start.
2551 */
2552static void
2553bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2554 enum port_ms_event event)
2555{
2556 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2557 bfa_trc(ms->port->fcs, event);
2558
2559 switch (event) {
2560 case MSSM_EVENT_PORT_ONLINE:
2561 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
2562 bfa_fcs_lport_ms_send_plogi(ms, NULL);
2563 break;
2564
2565 case MSSM_EVENT_PORT_OFFLINE:
2566 break;
2567
2568 default:
2569 bfa_sm_fault(ms->port->fcs, event);
2570 }
2571}
2572
2573static void
2574bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2575 enum port_ms_event event)
2576{
2577 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2578 bfa_trc(ms->port->fcs, event);
2579
2580 switch (event) {
2581 case MSSM_EVENT_FCXP_SENT:
2582 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi);
2583 break;
2584
2585 case MSSM_EVENT_PORT_OFFLINE:
2586 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2587 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2588 &ms->fcxp_wqe);
2589 break;
2590
2591 default:
2592 bfa_sm_fault(ms->port->fcs, event);
2593 }
2594}
2595
2596static void
2597bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2598 enum port_ms_event event)
2599{
2600 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2601 bfa_trc(ms->port->fcs, event);
2602
2603 switch (event) {
2604 case MSSM_EVENT_RSP_ERROR:
2605 /*
2606 * Start timer for a delayed retry
2607 */
2608 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_retry);
2609 ms->port->stats.ms_retries++;
2610 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2611 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
2612 BFA_FCS_RETRY_TIMEOUT);
2613 break;
2614
2615 case MSSM_EVENT_RSP_OK:
2616 /*
2617 * since plogi is done, now invoke MS related sub-modules
2618 */
2619 bfa_fcs_lport_fdmi_online(ms);
2620
Jing Huang5fbe25c2010-10-18 17:17:23 -07002621 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002622 * if this is a Vport, go to online state.
2623 */
2624 if (ms->port->vport) {
2625 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
2626 break;
2627 }
2628
2629 /*
2630 * For a base port we need to get the
2631 * switch's IP address.
2632 */
2633 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
2634 bfa_fcs_lport_ms_send_gmal(ms, NULL);
2635 break;
2636
2637 case MSSM_EVENT_PORT_OFFLINE:
2638 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2639 bfa_fcxp_discard(ms->fcxp);
2640 break;
2641
2642 default:
2643 bfa_sm_fault(ms->port->fcs, event);
2644 }
2645}
2646
2647static void
2648bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2649 enum port_ms_event event)
2650{
2651 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2652 bfa_trc(ms->port->fcs, event);
2653
2654 switch (event) {
2655 case MSSM_EVENT_TIMEOUT:
2656 /*
2657 * Retry Timer Expired. Re-send
2658 */
2659 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
2660 bfa_fcs_lport_ms_send_plogi(ms, NULL);
2661 break;
2662
2663 case MSSM_EVENT_PORT_OFFLINE:
2664 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2665 bfa_timer_stop(&ms->timer);
2666 break;
2667
2668 default:
2669 bfa_sm_fault(ms->port->fcs, event);
2670 }
2671}
2672
2673static void
2674bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
2675 enum port_ms_event event)
2676{
2677 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2678 bfa_trc(ms->port->fcs, event);
2679
2680 switch (event) {
2681 case MSSM_EVENT_PORT_OFFLINE:
2682 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2683 break;
2684
2685 case MSSM_EVENT_PORT_FABRIC_RSCN:
2686 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
2687 ms->retry_cnt = 0;
2688 bfa_fcs_lport_ms_send_gfn(ms, NULL);
2689 break;
2690
2691 default:
2692 bfa_sm_fault(ms->port->fcs, event);
2693 }
2694}
2695
2696static void
2697bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
2698 enum port_ms_event event)
2699{
2700 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2701 bfa_trc(ms->port->fcs, event);
2702
2703 switch (event) {
2704 case MSSM_EVENT_FCXP_SENT:
2705 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal);
2706 break;
2707
2708 case MSSM_EVENT_PORT_OFFLINE:
2709 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2710 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2711 &ms->fcxp_wqe);
2712 break;
2713
2714 default:
2715 bfa_sm_fault(ms->port->fcs, event);
2716 }
2717}
2718
2719static void
2720bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
2721 enum port_ms_event event)
2722{
2723 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2724 bfa_trc(ms->port->fcs, event);
2725
2726 switch (event) {
2727 case MSSM_EVENT_RSP_ERROR:
2728 /*
2729 * Start timer for a delayed retry
2730 */
2731 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
2732 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_retry);
2733 ms->port->stats.ms_retries++;
2734 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2735 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
2736 BFA_FCS_RETRY_TIMEOUT);
2737 } else {
2738 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
2739 bfa_fcs_lport_ms_send_gfn(ms, NULL);
2740 ms->retry_cnt = 0;
2741 }
2742 break;
2743
2744 case MSSM_EVENT_RSP_OK:
2745 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
2746 bfa_fcs_lport_ms_send_gfn(ms, NULL);
2747 break;
2748
2749 case MSSM_EVENT_PORT_OFFLINE:
2750 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2751 bfa_fcxp_discard(ms->fcxp);
2752 break;
2753
2754 default:
2755 bfa_sm_fault(ms->port->fcs, event);
2756 }
2757}
2758
2759static void
2760bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
2761 enum port_ms_event event)
2762{
2763 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2764 bfa_trc(ms->port->fcs, event);
2765
2766 switch (event) {
2767 case MSSM_EVENT_TIMEOUT:
2768 /*
2769 * Retry Timer Expired. Re-send
2770 */
2771 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
2772 bfa_fcs_lport_ms_send_gmal(ms, NULL);
2773 break;
2774
2775 case MSSM_EVENT_PORT_OFFLINE:
2776 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2777 bfa_timer_stop(&ms->timer);
2778 break;
2779
2780 default:
2781 bfa_sm_fault(ms->port->fcs, event);
2782 }
2783}
Jing Huang5fbe25c2010-10-18 17:17:23 -07002784/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002785 * ms_pvt MS local functions
2786 */
2787
2788static void
2789bfa_fcs_lport_ms_send_gmal(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2790{
2791 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
2792 bfa_fcs_lport_t *port = ms->port;
2793 struct fchs_s fchs;
2794 int len;
2795 struct bfa_fcxp_s *fcxp;
2796
2797 bfa_trc(port->fcs, port->pid);
2798
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002799 fcxp = fcxp_alloced ? fcxp_alloced :
2800 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002801 if (!fcxp) {
2802 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002803 bfa_fcs_lport_ms_send_gmal, ms, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002804 return;
2805 }
2806 ms->fcxp = fcxp;
2807
2808 len = fc_gmal_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2809 bfa_fcs_lport_get_fcid(port),
Maggie Zhangf7f738122010-12-09 19:08:43 -08002810 port->fabric->lps->pr_nwwn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002811
2812 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2813 FC_CLASS_3, len, &fchs,
2814 bfa_fcs_lport_ms_gmal_response, (void *)ms,
2815 FC_MAX_PDUSZ, FC_FCCT_TOV);
2816
2817 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
2818}
2819
2820static void
2821bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2822 void *cbarg, bfa_status_t req_status,
2823 u32 rsp_len, u32 resid_len,
2824 struct fchs_s *rsp_fchs)
2825{
2826 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
2827 bfa_fcs_lport_t *port = ms->port;
2828 struct ct_hdr_s *cthdr = NULL;
2829 struct fcgs_gmal_resp_s *gmal_resp;
2830 struct fcgs_gmal_entry_s *gmal_entry;
2831 u32 num_entries;
2832 u8 *rsp_str;
2833
2834 bfa_trc(port->fcs, req_status);
2835 bfa_trc(port->fcs, port->port_cfg.pwwn);
2836
2837 /*
2838 * Sanity Checks
2839 */
2840 if (req_status != BFA_STATUS_OK) {
2841 bfa_trc(port->fcs, req_status);
2842 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
2843 return;
2844 }
2845
2846 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07002847 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002848
2849 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2850 gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
2851
Jing Huangba816ea2010-10-18 17:10:50 -07002852 num_entries = be32_to_cpu(gmal_resp->ms_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002853 if (num_entries == 0) {
2854 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
2855 return;
2856 }
2857 /*
2858 * The response could contain multiple Entries.
2859 * Entries for SNMP interface, etc.
2860 * We look for the entry with a telnet prefix.
2861 * First "http://" entry refers to IP addr
2862 */
2863
2864 gmal_entry = (struct fcgs_gmal_entry_s *)gmal_resp->ms_ma;
2865 while (num_entries > 0) {
2866 if (strncmp(gmal_entry->prefix,
2867 CT_GMAL_RESP_PREFIX_HTTP,
2868 sizeof(gmal_entry->prefix)) == 0) {
2869
2870 /*
2871 * if the IP address is terminating with a '/',
2872 * remove it.
2873 * Byte 0 consists of the length of the string.
2874 */
2875 rsp_str = &(gmal_entry->prefix[0]);
2876 if (rsp_str[gmal_entry->len-1] == '/')
2877 rsp_str[gmal_entry->len-1] = 0;
2878
2879 /* copy IP Address to fabric */
2880 strncpy(bfa_fcs_lport_get_fabric_ipaddr(port),
2881 gmal_entry->ip_addr,
2882 BFA_FCS_FABRIC_IPADDR_SZ);
2883 break;
2884 } else {
2885 --num_entries;
2886 ++gmal_entry;
2887 }
2888 }
2889
2890 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
2891 return;
2892 }
2893
2894 bfa_trc(port->fcs, cthdr->reason_code);
2895 bfa_trc(port->fcs, cthdr->exp_code);
2896 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
2897}
2898
2899static void
2900bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
2901 enum port_ms_event event)
2902{
2903 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2904 bfa_trc(ms->port->fcs, event);
2905
2906 switch (event) {
2907 case MSSM_EVENT_FCXP_SENT:
2908 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn);
2909 break;
2910
2911 case MSSM_EVENT_PORT_OFFLINE:
2912 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2913 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2914 &ms->fcxp_wqe);
2915 break;
2916
2917 default:
2918 bfa_sm_fault(ms->port->fcs, event);
2919 }
2920}
2921
2922static void
2923bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
2924 enum port_ms_event event)
2925{
2926 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2927 bfa_trc(ms->port->fcs, event);
2928
2929 switch (event) {
2930 case MSSM_EVENT_RSP_ERROR:
2931 /*
2932 * Start timer for a delayed retry
2933 */
2934 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
2935 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_retry);
2936 ms->port->stats.ms_retries++;
2937 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2938 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
2939 BFA_FCS_RETRY_TIMEOUT);
2940 } else {
2941 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
2942 ms->retry_cnt = 0;
2943 }
2944 break;
2945
2946 case MSSM_EVENT_RSP_OK:
2947 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
2948 break;
2949
2950 case MSSM_EVENT_PORT_OFFLINE:
2951 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2952 bfa_fcxp_discard(ms->fcxp);
2953 break;
2954
2955 default:
2956 bfa_sm_fault(ms->port->fcs, event);
2957 }
2958}
2959
2960static void
2961bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
2962 enum port_ms_event event)
2963{
2964 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2965 bfa_trc(ms->port->fcs, event);
2966
2967 switch (event) {
2968 case MSSM_EVENT_TIMEOUT:
2969 /*
2970 * Retry Timer Expired. Re-send
2971 */
2972 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
2973 bfa_fcs_lport_ms_send_gfn(ms, NULL);
2974 break;
2975
2976 case MSSM_EVENT_PORT_OFFLINE:
2977 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2978 bfa_timer_stop(&ms->timer);
2979 break;
2980
2981 default:
2982 bfa_sm_fault(ms->port->fcs, event);
2983 }
2984}
Jing Huang5fbe25c2010-10-18 17:17:23 -07002985/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002986 * ms_pvt MS local functions
2987 */
2988
2989static void
2990bfa_fcs_lport_ms_send_gfn(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2991{
2992 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
2993 bfa_fcs_lport_t *port = ms->port;
2994 struct fchs_s fchs;
2995 int len;
2996 struct bfa_fcxp_s *fcxp;
2997
2998 bfa_trc(port->fcs, port->pid);
2999
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003000 fcxp = fcxp_alloced ? fcxp_alloced :
3001 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003002 if (!fcxp) {
3003 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003004 bfa_fcs_lport_ms_send_gfn, ms, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003005 return;
3006 }
3007 ms->fcxp = fcxp;
3008
3009 len = fc_gfn_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3010 bfa_fcs_lport_get_fcid(port),
Maggie Zhangf7f738122010-12-09 19:08:43 -08003011 port->fabric->lps->pr_nwwn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003012
3013 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3014 FC_CLASS_3, len, &fchs,
3015 bfa_fcs_lport_ms_gfn_response, (void *)ms,
3016 FC_MAX_PDUSZ, FC_FCCT_TOV);
3017
3018 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3019}
3020
3021static void
3022bfa_fcs_lport_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3023 void *cbarg, bfa_status_t req_status, u32 rsp_len,
3024 u32 resid_len, struct fchs_s *rsp_fchs)
3025{
3026 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3027 bfa_fcs_lport_t *port = ms->port;
3028 struct ct_hdr_s *cthdr = NULL;
3029 wwn_t *gfn_resp;
3030
3031 bfa_trc(port->fcs, req_status);
3032 bfa_trc(port->fcs, port->port_cfg.pwwn);
3033
3034 /*
3035 * Sanity Checks
3036 */
3037 if (req_status != BFA_STATUS_OK) {
3038 bfa_trc(port->fcs, req_status);
3039 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3040 return;
3041 }
3042
3043 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07003044 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003045
3046 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3047 gfn_resp = (wwn_t *)(cthdr + 1);
3048 /* check if it has actually changed */
3049 if ((memcmp((void *)&bfa_fcs_lport_get_fabric_name(port),
3050 gfn_resp, sizeof(wwn_t)) != 0)) {
3051 bfa_fcs_fabric_set_fabric_name(port->fabric, *gfn_resp);
3052 }
3053 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3054 return;
3055 }
3056
3057 bfa_trc(port->fcs, cthdr->reason_code);
3058 bfa_trc(port->fcs, cthdr->exp_code);
3059 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3060}
3061
Jing Huang5fbe25c2010-10-18 17:17:23 -07003062/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003063 * ms_pvt MS local functions
3064 */
3065
3066static void
3067bfa_fcs_lport_ms_send_plogi(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3068{
3069 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3070 struct bfa_fcs_lport_s *port = ms->port;
3071 struct fchs_s fchs;
3072 int len;
3073 struct bfa_fcxp_s *fcxp;
3074
3075 bfa_trc(port->fcs, port->pid);
3076
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003077 fcxp = fcxp_alloced ? fcxp_alloced :
3078 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003079 if (!fcxp) {
3080 port->stats.ms_plogi_alloc_wait++;
3081 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003082 bfa_fcs_lport_ms_send_plogi, ms, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003083 return;
3084 }
3085 ms->fcxp = fcxp;
3086
3087 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08003088 bfa_hton3b(FC_MGMT_SERVER),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003089 bfa_fcs_lport_get_fcid(port), 0,
3090 port->port_cfg.pwwn, port->port_cfg.nwwn,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003091 bfa_fcport_get_maxfrsize(port->fcs->bfa),
3092 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003093
3094 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3095 FC_CLASS_3, len, &fchs,
3096 bfa_fcs_lport_ms_plogi_response, (void *)ms,
3097 FC_MAX_PDUSZ, FC_ELS_TOV);
3098
3099 port->stats.ms_plogi_sent++;
3100 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3101}
3102
3103static void
3104bfa_fcs_lport_ms_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3105 void *cbarg, bfa_status_t req_status,
3106 u32 rsp_len, u32 resid_len, struct fchs_s *rsp_fchs)
3107{
3108 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3109 struct bfa_fcs_lport_s *port = ms->port;
3110 struct fc_els_cmd_s *els_cmd;
3111 struct fc_ls_rjt_s *ls_rjt;
3112
3113 bfa_trc(port->fcs, req_status);
3114 bfa_trc(port->fcs, port->port_cfg.pwwn);
3115
3116 /*
3117 * Sanity Checks
3118 */
3119 if (req_status != BFA_STATUS_OK) {
3120 port->stats.ms_plogi_rsp_err++;
3121 bfa_trc(port->fcs, req_status);
3122 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3123 return;
3124 }
3125
3126 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
3127
3128 switch (els_cmd->els_code) {
3129
3130 case FC_ELS_ACC:
3131 if (rsp_len < sizeof(struct fc_logi_s)) {
3132 bfa_trc(port->fcs, rsp_len);
3133 port->stats.ms_plogi_acc_err++;
3134 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3135 break;
3136 }
3137 port->stats.ms_plogi_accepts++;
3138 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3139 break;
3140
3141 case FC_ELS_LS_RJT:
3142 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
3143
3144 bfa_trc(port->fcs, ls_rjt->reason_code);
3145 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
3146
3147 port->stats.ms_rejects++;
3148 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3149 break;
3150
3151 default:
3152 port->stats.ms_plogi_unknown_rsp++;
3153 bfa_trc(port->fcs, els_cmd->els_code);
3154 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3155 }
3156}
3157
3158static void
3159bfa_fcs_lport_ms_timeout(void *arg)
3160{
3161 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) arg;
3162
3163 ms->port->stats.ms_timeouts++;
3164 bfa_sm_send_event(ms, MSSM_EVENT_TIMEOUT);
3165}
3166
3167
3168void
3169bfa_fcs_lport_ms_init(struct bfa_fcs_lport_s *port)
3170{
3171 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3172
3173 ms->port = port;
3174 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3175
3176 /*
3177 * Invoke init routines of sub modules.
3178 */
3179 bfa_fcs_lport_fdmi_init(ms);
3180}
3181
3182void
3183bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s *port)
3184{
3185 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3186
3187 ms->port = port;
3188 bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
3189 bfa_fcs_lport_fdmi_offline(ms);
3190}
3191
3192void
3193bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s *port)
3194{
3195 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3196
3197 ms->port = port;
3198 bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
3199}
3200void
3201bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s *port)
3202{
3203 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3204
3205 /* todo. Handle this only when in Online state */
3206 if (bfa_sm_cmp_state(ms, bfa_fcs_lport_ms_sm_online))
3207 bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
3208}
3209
Jing Huang5fbe25c2010-10-18 17:17:23 -07003210/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003211 * @page ns_sm_info VPORT NS State Machine
3212 *
3213 * @section ns_sm_interactions VPORT NS State Machine Interactions
3214 *
3215 * @section ns_sm VPORT NS State Machine
3216 * img ns_sm.jpg
3217 */
3218
3219/*
3220 * forward declarations
3221 */
3222static void bfa_fcs_lport_ns_send_plogi(void *ns_cbarg,
3223 struct bfa_fcxp_s *fcxp_alloced);
3224static void bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg,
3225 struct bfa_fcxp_s *fcxp_alloced);
3226static void bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg,
3227 struct bfa_fcxp_s *fcxp_alloced);
3228static void bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg,
3229 struct bfa_fcxp_s *fcxp_alloced);
3230static void bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg,
3231 struct bfa_fcxp_s *fcxp_alloced);
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003232static void bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg,
3233 struct bfa_fcxp_s *fcxp_alloced);
3234static void bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg,
3235 struct bfa_fcxp_s *fcxp_alloced);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003236static void bfa_fcs_lport_ns_timeout(void *arg);
3237static void bfa_fcs_lport_ns_plogi_response(void *fcsarg,
3238 struct bfa_fcxp_s *fcxp,
3239 void *cbarg,
3240 bfa_status_t req_status,
3241 u32 rsp_len,
3242 u32 resid_len,
3243 struct fchs_s *rsp_fchs);
3244static void bfa_fcs_lport_ns_rspn_id_response(void *fcsarg,
3245 struct bfa_fcxp_s *fcxp,
3246 void *cbarg,
3247 bfa_status_t req_status,
3248 u32 rsp_len,
3249 u32 resid_len,
3250 struct fchs_s *rsp_fchs);
3251static void bfa_fcs_lport_ns_rft_id_response(void *fcsarg,
3252 struct bfa_fcxp_s *fcxp,
3253 void *cbarg,
3254 bfa_status_t req_status,
3255 u32 rsp_len,
3256 u32 resid_len,
3257 struct fchs_s *rsp_fchs);
3258static void bfa_fcs_lport_ns_rff_id_response(void *fcsarg,
3259 struct bfa_fcxp_s *fcxp,
3260 void *cbarg,
3261 bfa_status_t req_status,
3262 u32 rsp_len,
3263 u32 resid_len,
3264 struct fchs_s *rsp_fchs);
3265static void bfa_fcs_lport_ns_gid_ft_response(void *fcsarg,
3266 struct bfa_fcxp_s *fcxp,
3267 void *cbarg,
3268 bfa_status_t req_status,
3269 u32 rsp_len,
3270 u32 resid_len,
3271 struct fchs_s *rsp_fchs);
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003272static void bfa_fcs_lport_ns_rnn_id_response(void *fcsarg,
3273 struct bfa_fcxp_s *fcxp,
3274 void *cbarg,
3275 bfa_status_t req_status,
3276 u32 rsp_len,
3277 u32 resid_len,
3278 struct fchs_s *rsp_fchs);
3279static void bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg,
3280 struct bfa_fcxp_s *fcxp,
3281 void *cbarg,
3282 bfa_status_t req_status,
3283 u32 rsp_len,
3284 u32 resid_len,
3285 struct fchs_s *rsp_fchs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003286static void bfa_fcs_lport_ns_process_gidft_pids(
3287 struct bfa_fcs_lport_s *port,
3288 u32 *pid_buf, u32 n_pids);
3289
3290static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port);
Jing Huang5fbe25c2010-10-18 17:17:23 -07003291/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003292 * fcs_ns_sm FCS nameserver interface state machine
3293 */
3294
Jing Huang5fbe25c2010-10-18 17:17:23 -07003295/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003296 * VPort NS State Machine events
3297 */
3298enum vport_ns_event {
3299 NSSM_EVENT_PORT_ONLINE = 1,
3300 NSSM_EVENT_PORT_OFFLINE = 2,
3301 NSSM_EVENT_PLOGI_SENT = 3,
3302 NSSM_EVENT_RSP_OK = 4,
3303 NSSM_EVENT_RSP_ERROR = 5,
3304 NSSM_EVENT_TIMEOUT = 6,
3305 NSSM_EVENT_NS_QUERY = 7,
3306 NSSM_EVENT_RSPNID_SENT = 8,
3307 NSSM_EVENT_RFTID_SENT = 9,
3308 NSSM_EVENT_RFFID_SENT = 10,
3309 NSSM_EVENT_GIDFT_SENT = 11,
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003310 NSSM_EVENT_RNNID_SENT = 12,
3311 NSSM_EVENT_RSNN_NN_SENT = 13,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003312};
3313
3314static void bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3315 enum vport_ns_event event);
3316static void bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3317 enum vport_ns_event event);
3318static void bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3319 enum vport_ns_event event);
3320static void bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3321 enum vport_ns_event event);
3322static void bfa_fcs_lport_ns_sm_sending_rspn_id(
3323 struct bfa_fcs_lport_ns_s *ns,
3324 enum vport_ns_event event);
3325static void bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3326 enum vport_ns_event event);
3327static void bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3328 enum vport_ns_event event);
3329static void bfa_fcs_lport_ns_sm_sending_rft_id(
3330 struct bfa_fcs_lport_ns_s *ns,
3331 enum vport_ns_event event);
3332static void bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
3333 enum vport_ns_event event);
3334static void bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
3335 enum vport_ns_event event);
3336static void bfa_fcs_lport_ns_sm_sending_rff_id(
3337 struct bfa_fcs_lport_ns_s *ns,
3338 enum vport_ns_event event);
3339static void bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
3340 enum vport_ns_event event);
3341static void bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
3342 enum vport_ns_event event);
3343static void bfa_fcs_lport_ns_sm_sending_gid_ft(
3344 struct bfa_fcs_lport_ns_s *ns,
3345 enum vport_ns_event event);
3346static void bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
3347 enum vport_ns_event event);
3348static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
3349 enum vport_ns_event event);
3350static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
3351 enum vport_ns_event event);
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003352static void bfa_fcs_lport_ns_sm_sending_rnn_id(
3353 struct bfa_fcs_lport_ns_s *ns,
3354 enum vport_ns_event event);
3355static void bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3356 enum vport_ns_event event);
3357static void bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3358 enum vport_ns_event event);
3359static void bfa_fcs_lport_ns_sm_sending_rsnn_nn(
3360 struct bfa_fcs_lport_ns_s *ns,
3361 enum vport_ns_event event);
3362static void bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3363 enum vport_ns_event event);
3364static void bfa_fcs_lport_ns_sm_rsnn_nn_retry(
3365 struct bfa_fcs_lport_ns_s *ns,
3366 enum vport_ns_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -07003367/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003368 * Start in offline state - awaiting linkup
3369 */
3370static void
3371bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3372 enum vport_ns_event event)
3373{
3374 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3375 bfa_trc(ns->port->fcs, event);
3376
3377 switch (event) {
3378 case NSSM_EVENT_PORT_ONLINE:
3379 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3380 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3381 break;
3382
3383 case NSSM_EVENT_PORT_OFFLINE:
3384 break;
3385
3386 default:
3387 bfa_sm_fault(ns->port->fcs, event);
3388 }
3389}
3390
3391static void
3392bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3393 enum vport_ns_event event)
3394{
3395 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3396 bfa_trc(ns->port->fcs, event);
3397
3398 switch (event) {
3399 case NSSM_EVENT_PLOGI_SENT:
3400 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi);
3401 break;
3402
3403 case NSSM_EVENT_PORT_OFFLINE:
3404 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3405 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3406 &ns->fcxp_wqe);
3407 break;
3408
3409 default:
3410 bfa_sm_fault(ns->port->fcs, event);
3411 }
3412}
3413
3414static void
3415bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3416 enum vport_ns_event event)
3417{
3418 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3419 bfa_trc(ns->port->fcs, event);
3420
3421 switch (event) {
3422 case NSSM_EVENT_RSP_ERROR:
3423 /*
3424 * Start timer for a delayed retry
3425 */
3426 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_retry);
3427 ns->port->stats.ns_retries++;
3428 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3429 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3430 BFA_FCS_RETRY_TIMEOUT);
3431 break;
3432
3433 case NSSM_EVENT_RSP_OK:
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003434 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3435 ns->num_rnnid_retries = 0;
3436 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003437 break;
3438
3439 case NSSM_EVENT_PORT_OFFLINE:
3440 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3441 bfa_fcxp_discard(ns->fcxp);
3442 break;
3443
3444 default:
3445 bfa_sm_fault(ns->port->fcs, event);
3446 }
3447}
3448
3449static void
3450bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3451 enum vport_ns_event event)
3452{
3453 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3454 bfa_trc(ns->port->fcs, event);
3455
3456 switch (event) {
3457 case NSSM_EVENT_TIMEOUT:
3458 /*
3459 * Retry Timer Expired. Re-send
3460 */
3461 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3462 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3463 break;
3464
3465 case NSSM_EVENT_PORT_OFFLINE:
3466 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3467 bfa_timer_stop(&ns->timer);
3468 break;
3469
3470 default:
3471 bfa_sm_fault(ns->port->fcs, event);
3472 }
3473}
3474
3475static void
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003476bfa_fcs_lport_ns_sm_sending_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3477 enum vport_ns_event event)
3478{
3479 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3480 bfa_trc(ns->port->fcs, event);
3481
3482 switch (event) {
3483 case NSSM_EVENT_RNNID_SENT:
3484 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id);
3485 break;
3486
3487 case NSSM_EVENT_PORT_OFFLINE:
3488 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3489 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3490 &ns->fcxp_wqe);
3491 break;
3492 default:
3493 bfa_sm_fault(ns->port->fcs, event);
3494 }
3495}
3496
3497static void
3498bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3499 enum vport_ns_event event)
3500{
3501 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3502 bfa_trc(ns->port->fcs, event);
3503
3504 switch (event) {
3505 case NSSM_EVENT_RSP_OK:
3506 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3507 ns->num_rnnid_retries = 0;
3508 ns->num_rsnn_nn_retries = 0;
3509 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3510 break;
3511
3512 case NSSM_EVENT_RSP_ERROR:
3513 if (ns->num_rnnid_retries < BFA_FCS_MAX_NS_RETRIES) {
3514 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id_retry);
3515 ns->port->stats.ns_retries++;
3516 ns->num_rnnid_retries++;
3517 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3518 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3519 BFA_FCS_RETRY_TIMEOUT);
3520 } else {
3521 bfa_sm_set_state(ns,
3522 bfa_fcs_lport_ns_sm_sending_rspn_id);
3523 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3524 }
3525 break;
3526
3527 case NSSM_EVENT_PORT_OFFLINE:
3528 bfa_fcxp_discard(ns->fcxp);
3529 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3530 break;
3531
3532 default:
3533 bfa_sm_fault(ns->port->fcs, event);
3534 }
3535}
3536
3537static void
3538bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3539 enum vport_ns_event event)
3540{
3541 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3542 bfa_trc(ns->port->fcs, event);
3543
3544 switch (event) {
3545 case NSSM_EVENT_TIMEOUT:
3546 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3547 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
3548 break;
3549
3550 case NSSM_EVENT_PORT_OFFLINE:
3551 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3552 bfa_timer_stop(&ns->timer);
3553 break;
3554
3555 default:
3556 bfa_sm_fault(ns->port->fcs, event);
3557 }
3558}
3559
3560static void
3561bfa_fcs_lport_ns_sm_sending_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3562 enum vport_ns_event event)
3563{
3564 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3565 bfa_trc(ns->port->fcs, event);
3566
3567 switch (event) {
3568 case NSSM_EVENT_RSNN_NN_SENT:
3569 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn);
3570 break;
3571
3572 case NSSM_EVENT_PORT_OFFLINE:
3573 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3574 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3575 &ns->fcxp_wqe);
3576 break;
3577
3578 default:
3579 bfa_sm_fault(ns->port->fcs, event);
3580 }
3581}
3582
3583static void
3584bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3585 enum vport_ns_event event)
3586{
3587 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3588 bfa_trc(ns->port->fcs, event);
3589
3590 switch (event) {
3591 case NSSM_EVENT_RSP_OK:
3592 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
3593 ns->num_rsnn_nn_retries = 0;
3594 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3595 break;
3596
3597 case NSSM_EVENT_RSP_ERROR:
3598 if (ns->num_rsnn_nn_retries < BFA_FCS_MAX_NS_RETRIES) {
3599 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn_retry);
3600 ns->port->stats.ns_retries++;
3601 ns->num_rsnn_nn_retries++;
3602 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3603 &ns->timer, bfa_fcs_lport_ns_timeout,
3604 ns, BFA_FCS_RETRY_TIMEOUT);
3605 } else {
3606 bfa_sm_set_state(ns,
3607 bfa_fcs_lport_ns_sm_sending_rspn_id);
3608 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3609 }
3610 break;
3611
3612 case NSSM_EVENT_PORT_OFFLINE:
3613 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3614 bfa_fcxp_discard(ns->fcxp);
3615 break;
3616
3617 default:
3618 bfa_sm_fault(ns->port->fcs, event);
3619 }
3620}
3621
3622static void
3623bfa_fcs_lport_ns_sm_rsnn_nn_retry(struct bfa_fcs_lport_ns_s *ns,
3624 enum vport_ns_event event)
3625{
3626 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3627 bfa_trc(ns->port->fcs, event);
3628
3629 switch (event) {
3630 case NSSM_EVENT_TIMEOUT:
3631 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3632 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3633 break;
3634
3635 case NSSM_EVENT_PORT_OFFLINE:
3636 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3637 bfa_timer_stop(&ns->timer);
3638 break;
3639
3640 default:
3641 bfa_sm_fault(ns->port->fcs, event);
3642 }
3643}
3644
3645static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003646bfa_fcs_lport_ns_sm_sending_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3647 enum vport_ns_event event)
3648{
3649 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3650 bfa_trc(ns->port->fcs, event);
3651
3652 switch (event) {
3653 case NSSM_EVENT_RSPNID_SENT:
3654 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id);
3655 break;
3656
3657 case NSSM_EVENT_PORT_OFFLINE:
3658 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3659 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3660 &ns->fcxp_wqe);
3661 break;
3662
3663 default:
3664 bfa_sm_fault(ns->port->fcs, event);
3665 }
3666}
3667
3668static void
3669bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3670 enum vport_ns_event event)
3671{
3672 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3673 bfa_trc(ns->port->fcs, event);
3674
3675 switch (event) {
3676 case NSSM_EVENT_RSP_ERROR:
3677 /*
3678 * Start timer for a delayed retry
3679 */
3680 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry);
3681 ns->port->stats.ns_retries++;
3682 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3683 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3684 BFA_FCS_RETRY_TIMEOUT);
3685 break;
3686
3687 case NSSM_EVENT_RSP_OK:
3688 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
3689 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
3690 break;
3691
3692 case NSSM_EVENT_PORT_OFFLINE:
3693 bfa_fcxp_discard(ns->fcxp);
3694 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3695 break;
3696
3697 default:
3698 bfa_sm_fault(ns->port->fcs, event);
3699 }
3700}
3701
3702static void
3703bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3704 enum vport_ns_event event)
3705{
3706 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3707 bfa_trc(ns->port->fcs, event);
3708
3709 switch (event) {
3710 case NSSM_EVENT_TIMEOUT:
3711 /*
3712 * Retry Timer Expired. Re-send
3713 */
3714 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
3715 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3716 break;
3717
3718 case NSSM_EVENT_PORT_OFFLINE:
3719 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3720 bfa_timer_stop(&ns->timer);
3721 break;
3722
3723 default:
3724 bfa_sm_fault(ns->port->fcs, event);
3725 }
3726}
3727
3728static void
3729bfa_fcs_lport_ns_sm_sending_rft_id(struct bfa_fcs_lport_ns_s *ns,
3730 enum vport_ns_event event)
3731{
3732 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3733 bfa_trc(ns->port->fcs, event);
3734
3735 switch (event) {
3736 case NSSM_EVENT_RFTID_SENT:
3737 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id);
3738 break;
3739
3740 case NSSM_EVENT_PORT_OFFLINE:
3741 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3742 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3743 &ns->fcxp_wqe);
3744 break;
3745
3746 default:
3747 bfa_sm_fault(ns->port->fcs, event);
3748 }
3749}
3750
3751static void
3752bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
3753 enum vport_ns_event event)
3754{
3755 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3756 bfa_trc(ns->port->fcs, event);
3757
3758 switch (event) {
3759 case NSSM_EVENT_RSP_OK:
3760 /* Now move to register FC4 Features */
3761 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
3762 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
3763 break;
3764
3765 case NSSM_EVENT_RSP_ERROR:
3766 /*
3767 * Start timer for a delayed retry
3768 */
3769 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id_retry);
3770 ns->port->stats.ns_retries++;
3771 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3772 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3773 BFA_FCS_RETRY_TIMEOUT);
3774 break;
3775
3776 case NSSM_EVENT_PORT_OFFLINE:
3777 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3778 bfa_fcxp_discard(ns->fcxp);
3779 break;
3780
3781 default:
3782 bfa_sm_fault(ns->port->fcs, event);
3783 }
3784}
3785
3786static void
3787bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
3788 enum vport_ns_event event)
3789{
3790 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3791 bfa_trc(ns->port->fcs, event);
3792
3793 switch (event) {
3794 case NSSM_EVENT_TIMEOUT:
3795 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
3796 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
3797 break;
3798
3799 case NSSM_EVENT_PORT_OFFLINE:
3800 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3801 bfa_timer_stop(&ns->timer);
3802 break;
3803
3804 default:
3805 bfa_sm_fault(ns->port->fcs, event);
3806 }
3807}
3808
3809static void
3810bfa_fcs_lport_ns_sm_sending_rff_id(struct bfa_fcs_lport_ns_s *ns,
3811 enum vport_ns_event event)
3812{
3813 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3814 bfa_trc(ns->port->fcs, event);
3815
3816 switch (event) {
3817 case NSSM_EVENT_RFFID_SENT:
3818 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id);
3819 break;
3820
3821 case NSSM_EVENT_PORT_OFFLINE:
3822 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3823 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3824 &ns->fcxp_wqe);
3825 break;
3826
3827 default:
3828 bfa_sm_fault(ns->port->fcs, event);
3829 }
3830}
3831
3832static void
3833bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
3834 enum vport_ns_event event)
3835{
3836 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3837 bfa_trc(ns->port->fcs, event);
3838
3839 switch (event) {
3840 case NSSM_EVENT_RSP_OK:
3841
3842 /*
3843 * If min cfg mode is enabled, we donot initiate rport
3844 * discovery with the fabric. Instead, we will retrieve the
3845 * boot targets from HAL/FW.
3846 */
3847 if (__fcs_min_cfg(ns->port->fcs)) {
3848 bfa_fcs_lport_ns_boot_target_disc(ns->port);
3849 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
3850 return;
3851 }
3852
3853 /*
3854 * If the port role is Initiator Mode issue NS query.
3855 * If it is Target Mode, skip this and go to online.
3856 */
3857 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
3858 bfa_sm_set_state(ns,
3859 bfa_fcs_lport_ns_sm_sending_gid_ft);
3860 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
3861 }
3862 /*
3863 * kick off mgmt srvr state machine
3864 */
3865 bfa_fcs_lport_ms_online(ns->port);
3866 break;
3867
3868 case NSSM_EVENT_RSP_ERROR:
3869 /*
3870 * Start timer for a delayed retry
3871 */
3872 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id_retry);
3873 ns->port->stats.ns_retries++;
3874 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3875 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3876 BFA_FCS_RETRY_TIMEOUT);
3877 break;
3878
3879 case NSSM_EVENT_PORT_OFFLINE:
3880 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3881 bfa_fcxp_discard(ns->fcxp);
3882 break;
3883
3884 default:
3885 bfa_sm_fault(ns->port->fcs, event);
3886 }
3887}
3888
3889static void
3890bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
3891 enum vport_ns_event event)
3892{
3893 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3894 bfa_trc(ns->port->fcs, event);
3895
3896 switch (event) {
3897 case NSSM_EVENT_TIMEOUT:
3898 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
3899 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
3900 break;
3901
3902 case NSSM_EVENT_PORT_OFFLINE:
3903 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3904 bfa_timer_stop(&ns->timer);
3905 break;
3906
3907 default:
3908 bfa_sm_fault(ns->port->fcs, event);
3909 }
3910}
3911static void
3912bfa_fcs_lport_ns_sm_sending_gid_ft(struct bfa_fcs_lport_ns_s *ns,
3913 enum vport_ns_event event)
3914{
3915 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3916 bfa_trc(ns->port->fcs, event);
3917
3918 switch (event) {
3919 case NSSM_EVENT_GIDFT_SENT:
3920 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft);
3921 break;
3922
3923 case NSSM_EVENT_PORT_OFFLINE:
3924 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3925 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3926 &ns->fcxp_wqe);
3927 break;
3928
3929 default:
3930 bfa_sm_fault(ns->port->fcs, event);
3931 }
3932}
3933
3934static void
3935bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
3936 enum vport_ns_event event)
3937{
3938 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3939 bfa_trc(ns->port->fcs, event);
3940
3941 switch (event) {
3942 case NSSM_EVENT_RSP_OK:
3943 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
3944 break;
3945
3946 case NSSM_EVENT_RSP_ERROR:
3947 /*
3948 * TBD: for certain reject codes, we don't need to retry
3949 */
3950 /*
3951 * Start timer for a delayed retry
3952 */
3953 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft_retry);
3954 ns->port->stats.ns_retries++;
3955 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3956 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3957 BFA_FCS_RETRY_TIMEOUT);
3958 break;
3959
3960 case NSSM_EVENT_PORT_OFFLINE:
3961 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3962 bfa_fcxp_discard(ns->fcxp);
3963 break;
3964
3965 case NSSM_EVENT_NS_QUERY:
3966 break;
3967
3968 default:
3969 bfa_sm_fault(ns->port->fcs, event);
3970 }
3971}
3972
3973static void
3974bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
3975 enum vport_ns_event event)
3976{
3977 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3978 bfa_trc(ns->port->fcs, event);
3979
3980 switch (event) {
3981 case NSSM_EVENT_TIMEOUT:
3982 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_gid_ft);
3983 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
3984 break;
3985
3986 case NSSM_EVENT_PORT_OFFLINE:
3987 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3988 bfa_timer_stop(&ns->timer);
3989 break;
3990
3991 default:
3992 bfa_sm_fault(ns->port->fcs, event);
3993 }
3994}
3995
3996static void
3997bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
3998 enum vport_ns_event event)
3999{
4000 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4001 bfa_trc(ns->port->fcs, event);
4002
4003 switch (event) {
4004 case NSSM_EVENT_PORT_OFFLINE:
4005 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4006 break;
4007
4008 case NSSM_EVENT_NS_QUERY:
4009 /*
4010 * If the port role is Initiator Mode issue NS query.
4011 * If it is Target Mode, skip this and go to online.
4012 */
4013 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4014 bfa_sm_set_state(ns,
4015 bfa_fcs_lport_ns_sm_sending_gid_ft);
4016 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4017 };
4018 break;
4019
4020 default:
4021 bfa_sm_fault(ns->port->fcs, event);
4022 }
4023}
4024
4025
4026
Jing Huang5fbe25c2010-10-18 17:17:23 -07004027/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004028 * ns_pvt Nameserver local functions
4029 */
4030
4031static void
4032bfa_fcs_lport_ns_send_plogi(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4033{
4034 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4035 struct bfa_fcs_lport_s *port = ns->port;
4036 struct fchs_s fchs;
4037 int len;
4038 struct bfa_fcxp_s *fcxp;
4039
4040 bfa_trc(port->fcs, port->pid);
4041
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004042 fcxp = fcxp_alloced ? fcxp_alloced :
4043 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004044 if (!fcxp) {
4045 port->stats.ns_plogi_alloc_wait++;
4046 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004047 bfa_fcs_lport_ns_send_plogi, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004048 return;
4049 }
4050 ns->fcxp = fcxp;
4051
4052 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08004053 bfa_hton3b(FC_NAME_SERVER),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004054 bfa_fcs_lport_get_fcid(port), 0,
4055 port->port_cfg.pwwn, port->port_cfg.nwwn,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07004056 bfa_fcport_get_maxfrsize(port->fcs->bfa),
4057 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004058
4059 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4060 FC_CLASS_3, len, &fchs,
4061 bfa_fcs_lport_ns_plogi_response, (void *)ns,
4062 FC_MAX_PDUSZ, FC_ELS_TOV);
4063 port->stats.ns_plogi_sent++;
4064
4065 bfa_sm_send_event(ns, NSSM_EVENT_PLOGI_SENT);
4066}
4067
4068static void
4069bfa_fcs_lport_ns_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4070 void *cbarg, bfa_status_t req_status, u32 rsp_len,
4071 u32 resid_len, struct fchs_s *rsp_fchs)
4072{
4073 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4074 struct bfa_fcs_lport_s *port = ns->port;
4075 /* struct fc_logi_s *plogi_resp; */
4076 struct fc_els_cmd_s *els_cmd;
4077 struct fc_ls_rjt_s *ls_rjt;
4078
4079 bfa_trc(port->fcs, req_status);
4080 bfa_trc(port->fcs, port->port_cfg.pwwn);
4081
4082 /*
4083 * Sanity Checks
4084 */
4085 if (req_status != BFA_STATUS_OK) {
4086 bfa_trc(port->fcs, req_status);
4087 port->stats.ns_plogi_rsp_err++;
4088 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4089 return;
4090 }
4091
4092 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
4093
4094 switch (els_cmd->els_code) {
4095
4096 case FC_ELS_ACC:
4097 if (rsp_len < sizeof(struct fc_logi_s)) {
4098 bfa_trc(port->fcs, rsp_len);
4099 port->stats.ns_plogi_acc_err++;
4100 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4101 break;
4102 }
4103 port->stats.ns_plogi_accepts++;
4104 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4105 break;
4106
4107 case FC_ELS_LS_RJT:
4108 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
4109
4110 bfa_trc(port->fcs, ls_rjt->reason_code);
4111 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
4112
4113 port->stats.ns_rejects++;
4114
4115 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4116 break;
4117
4118 default:
4119 port->stats.ns_plogi_unknown_rsp++;
4120 bfa_trc(port->fcs, els_cmd->els_code);
4121 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4122 }
4123}
4124
Jing Huang5fbe25c2010-10-18 17:17:23 -07004125/*
Krishna Gudipatice7242b2012-08-22 19:52:43 -07004126 * Register node name for port_id
4127 */
4128static void
4129bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4130{
4131 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4132 struct bfa_fcs_lport_s *port = ns->port;
4133 struct fchs_s fchs;
4134 int len;
4135 struct bfa_fcxp_s *fcxp;
4136
4137 bfa_trc(port->fcs, port->port_cfg.pwwn);
4138
4139 fcxp = fcxp_alloced ? fcxp_alloced :
4140 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4141 if (!fcxp) {
4142 port->stats.ns_rnnid_alloc_wait++;
4143 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4144 bfa_fcs_lport_ns_send_rnn_id, ns, BFA_TRUE);
4145 return;
4146 }
4147
4148 ns->fcxp = fcxp;
4149
4150 len = fc_rnnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4151 bfa_fcs_lport_get_fcid(port),
4152 bfa_fcs_lport_get_fcid(port),
4153 bfa_fcs_lport_get_nwwn(port));
4154
4155 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4156 FC_CLASS_3, len, &fchs,
4157 bfa_fcs_lport_ns_rnn_id_response, (void *)ns,
4158 FC_MAX_PDUSZ, FC_FCCT_TOV);
4159
4160 port->stats.ns_rnnid_sent++;
4161 bfa_sm_send_event(ns, NSSM_EVENT_RNNID_SENT);
4162}
4163
4164static void
4165bfa_fcs_lport_ns_rnn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4166 void *cbarg, bfa_status_t req_status,
4167 u32 rsp_len, u32 resid_len,
4168 struct fchs_s *rsp_fchs)
4169
4170{
4171 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4172 struct bfa_fcs_lport_s *port = ns->port;
4173 struct ct_hdr_s *cthdr = NULL;
4174
4175 bfa_trc(port->fcs, port->port_cfg.pwwn);
4176
4177 /*
4178 * Sanity Checks
4179 */
4180 if (req_status != BFA_STATUS_OK) {
4181 bfa_trc(port->fcs, req_status);
4182 port->stats.ns_rnnid_rsp_err++;
4183 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4184 return;
4185 }
4186
4187 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4188 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4189
4190 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4191 port->stats.ns_rnnid_accepts++;
4192 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4193 return;
4194 }
4195
4196 port->stats.ns_rnnid_rejects++;
4197 bfa_trc(port->fcs, cthdr->reason_code);
4198 bfa_trc(port->fcs, cthdr->exp_code);
4199 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4200}
4201
4202/*
4203 * Register the symbolic node name for a given node name.
4204 */
4205static void
4206bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4207{
4208 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4209 struct bfa_fcs_lport_s *port = ns->port;
4210 struct fchs_s fchs;
4211 int len;
4212 struct bfa_fcxp_s *fcxp;
4213 u8 *nsymbl;
4214
4215 bfa_trc(port->fcs, port->port_cfg.pwwn);
4216
4217 fcxp = fcxp_alloced ? fcxp_alloced :
4218 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4219 if (!fcxp) {
4220 port->stats.ns_rsnn_nn_alloc_wait++;
4221 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4222 bfa_fcs_lport_ns_send_rsnn_nn, ns, BFA_TRUE);
4223 return;
4224 }
4225 ns->fcxp = fcxp;
4226
4227 nsymbl = (u8 *) &(bfa_fcs_lport_get_nsym_name(
4228 bfa_fcs_get_base_port(port->fcs)));
4229
4230 len = fc_rsnn_nn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4231 bfa_fcs_lport_get_fcid(port),
4232 bfa_fcs_lport_get_nwwn(port), nsymbl);
4233
4234 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4235 FC_CLASS_3, len, &fchs,
4236 bfa_fcs_lport_ns_rsnn_nn_response, (void *)ns,
4237 FC_MAX_PDUSZ, FC_FCCT_TOV);
4238
4239 port->stats.ns_rsnn_nn_sent++;
4240
4241 bfa_sm_send_event(ns, NSSM_EVENT_RSNN_NN_SENT);
4242}
4243
4244static void
4245bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4246 void *cbarg, bfa_status_t req_status,
4247 u32 rsp_len, u32 resid_len,
4248 struct fchs_s *rsp_fchs)
4249{
4250 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4251 struct bfa_fcs_lport_s *port = ns->port;
4252 struct ct_hdr_s *cthdr = NULL;
4253
4254 bfa_trc(port->fcs, port->port_cfg.pwwn);
4255
4256 /*
4257 * Sanity Checks
4258 */
4259 if (req_status != BFA_STATUS_OK) {
4260 bfa_trc(port->fcs, req_status);
4261 port->stats.ns_rsnn_nn_rsp_err++;
4262 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4263 return;
4264 }
4265
4266 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4267 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4268
4269 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4270 port->stats.ns_rsnn_nn_accepts++;
4271 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4272 return;
4273 }
4274
4275 port->stats.ns_rsnn_nn_rejects++;
4276 bfa_trc(port->fcs, cthdr->reason_code);
4277 bfa_trc(port->fcs, cthdr->exp_code);
4278 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4279}
4280
4281/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004282 * Register the symbolic port name.
4283 */
4284static void
4285bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4286{
4287 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4288 struct bfa_fcs_lport_s *port = ns->port;
4289 struct fchs_s fchs;
4290 int len;
4291 struct bfa_fcxp_s *fcxp;
4292 u8 symbl[256];
4293 u8 *psymbl = &symbl[0];
4294
Jing Huang6a18b162010-10-18 17:08:54 -07004295 memset(symbl, 0, sizeof(symbl));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004296
4297 bfa_trc(port->fcs, port->port_cfg.pwwn);
4298
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004299 fcxp = fcxp_alloced ? fcxp_alloced :
4300 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004301 if (!fcxp) {
4302 port->stats.ns_rspnid_alloc_wait++;
4303 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004304 bfa_fcs_lport_ns_send_rspn_id, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004305 return;
4306 }
4307 ns->fcxp = fcxp;
4308
4309 /*
4310 * for V-Port, form a Port Symbolic Name
4311 */
4312 if (port->vport) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07004313 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004314 * For Vports, we append the vport's port symbolic name
4315 * to that of the base port.
4316 */
4317
4318 strncpy((char *)psymbl,
4319 (char *) &
4320 (bfa_fcs_lport_get_psym_name
4321 (bfa_fcs_get_base_port(port->fcs))),
4322 strlen((char *) &
4323 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
4324 (port->fcs))));
4325
4326 /* Ensure we have a null terminating string. */
4327 ((char *)psymbl)[strlen((char *) &
4328 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
4329 (port->fcs)))] = 0;
4330 strncat((char *)psymbl,
4331 (char *) &(bfa_fcs_lport_get_psym_name(port)),
4332 strlen((char *) &bfa_fcs_lport_get_psym_name(port)));
4333 } else {
4334 psymbl = (u8 *) &(bfa_fcs_lport_get_psym_name(port));
4335 }
4336
4337 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4338 bfa_fcs_lport_get_fcid(port), 0, psymbl);
4339
4340 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4341 FC_CLASS_3, len, &fchs,
4342 bfa_fcs_lport_ns_rspn_id_response, (void *)ns,
4343 FC_MAX_PDUSZ, FC_FCCT_TOV);
4344
4345 port->stats.ns_rspnid_sent++;
4346
4347 bfa_sm_send_event(ns, NSSM_EVENT_RSPNID_SENT);
4348}
4349
4350static void
4351bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4352 void *cbarg, bfa_status_t req_status,
4353 u32 rsp_len, u32 resid_len,
4354 struct fchs_s *rsp_fchs)
4355{
4356 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4357 struct bfa_fcs_lport_s *port = ns->port;
4358 struct ct_hdr_s *cthdr = NULL;
4359
4360 bfa_trc(port->fcs, port->port_cfg.pwwn);
4361
4362 /*
4363 * Sanity Checks
4364 */
4365 if (req_status != BFA_STATUS_OK) {
4366 bfa_trc(port->fcs, req_status);
4367 port->stats.ns_rspnid_rsp_err++;
4368 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4369 return;
4370 }
4371
4372 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004373 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004374
4375 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4376 port->stats.ns_rspnid_accepts++;
4377 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4378 return;
4379 }
4380
4381 port->stats.ns_rspnid_rejects++;
4382 bfa_trc(port->fcs, cthdr->reason_code);
4383 bfa_trc(port->fcs, cthdr->exp_code);
4384 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4385}
4386
Jing Huang5fbe25c2010-10-18 17:17:23 -07004387/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004388 * Register FC4-Types
4389 */
4390static void
4391bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4392{
4393 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4394 struct bfa_fcs_lport_s *port = ns->port;
4395 struct fchs_s fchs;
4396 int len;
4397 struct bfa_fcxp_s *fcxp;
4398
4399 bfa_trc(port->fcs, port->port_cfg.pwwn);
4400
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004401 fcxp = fcxp_alloced ? fcxp_alloced :
4402 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004403 if (!fcxp) {
4404 port->stats.ns_rftid_alloc_wait++;
4405 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004406 bfa_fcs_lport_ns_send_rft_id, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004407 return;
4408 }
4409 ns->fcxp = fcxp;
4410
4411 len = fc_rftid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4412 bfa_fcs_lport_get_fcid(port), 0, port->port_cfg.roles);
4413
4414 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4415 FC_CLASS_3, len, &fchs,
4416 bfa_fcs_lport_ns_rft_id_response, (void *)ns,
4417 FC_MAX_PDUSZ, FC_FCCT_TOV);
4418
4419 port->stats.ns_rftid_sent++;
4420 bfa_sm_send_event(ns, NSSM_EVENT_RFTID_SENT);
4421}
4422
4423static void
4424bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4425 void *cbarg, bfa_status_t req_status,
4426 u32 rsp_len, u32 resid_len,
4427 struct fchs_s *rsp_fchs)
4428{
4429 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4430 struct bfa_fcs_lport_s *port = ns->port;
4431 struct ct_hdr_s *cthdr = NULL;
4432
4433 bfa_trc(port->fcs, port->port_cfg.pwwn);
4434
4435 /*
4436 * Sanity Checks
4437 */
4438 if (req_status != BFA_STATUS_OK) {
4439 bfa_trc(port->fcs, req_status);
4440 port->stats.ns_rftid_rsp_err++;
4441 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4442 return;
4443 }
4444
4445 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004446 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004447
4448 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4449 port->stats.ns_rftid_accepts++;
4450 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4451 return;
4452 }
4453
4454 port->stats.ns_rftid_rejects++;
4455 bfa_trc(port->fcs, cthdr->reason_code);
4456 bfa_trc(port->fcs, cthdr->exp_code);
4457 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4458}
4459
Jing Huang5fbe25c2010-10-18 17:17:23 -07004460/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004461 * Register FC4-Features : Should be done after RFT_ID
4462 */
4463static void
4464bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4465{
4466 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4467 struct bfa_fcs_lport_s *port = ns->port;
4468 struct fchs_s fchs;
4469 int len;
4470 struct bfa_fcxp_s *fcxp;
4471 u8 fc4_ftrs = 0;
4472
4473 bfa_trc(port->fcs, port->port_cfg.pwwn);
4474
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004475 fcxp = fcxp_alloced ? fcxp_alloced :
4476 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004477 if (!fcxp) {
4478 port->stats.ns_rffid_alloc_wait++;
4479 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004480 bfa_fcs_lport_ns_send_rff_id, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004481 return;
4482 }
4483 ns->fcxp = fcxp;
4484
4485 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port))
4486 fc4_ftrs = FC_GS_FCP_FC4_FEATURE_INITIATOR;
4487
4488 len = fc_rffid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4489 bfa_fcs_lport_get_fcid(port), 0,
4490 FC_TYPE_FCP, fc4_ftrs);
4491
4492 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4493 FC_CLASS_3, len, &fchs,
4494 bfa_fcs_lport_ns_rff_id_response, (void *)ns,
4495 FC_MAX_PDUSZ, FC_FCCT_TOV);
4496
4497 port->stats.ns_rffid_sent++;
4498 bfa_sm_send_event(ns, NSSM_EVENT_RFFID_SENT);
4499}
4500
4501static void
4502bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4503 void *cbarg, bfa_status_t req_status,
4504 u32 rsp_len, u32 resid_len,
4505 struct fchs_s *rsp_fchs)
4506{
4507 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4508 struct bfa_fcs_lport_s *port = ns->port;
4509 struct ct_hdr_s *cthdr = NULL;
4510
4511 bfa_trc(port->fcs, port->port_cfg.pwwn);
4512
4513 /*
4514 * Sanity Checks
4515 */
4516 if (req_status != BFA_STATUS_OK) {
4517 bfa_trc(port->fcs, req_status);
4518 port->stats.ns_rffid_rsp_err++;
4519 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4520 return;
4521 }
4522
4523 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004524 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004525
4526 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4527 port->stats.ns_rffid_accepts++;
4528 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4529 return;
4530 }
4531
4532 port->stats.ns_rffid_rejects++;
4533 bfa_trc(port->fcs, cthdr->reason_code);
4534 bfa_trc(port->fcs, cthdr->exp_code);
4535
4536 if (cthdr->reason_code == CT_RSN_NOT_SUPP) {
4537 /* if this command is not supported, we don't retry */
4538 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4539 } else
4540 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4541}
Jing Huang5fbe25c2010-10-18 17:17:23 -07004542/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004543 * Query Fabric for FC4-Types Devices.
4544 *
4545* TBD : Need to use a local (FCS private) response buffer, since the response
4546 * can be larger than 2K.
4547 */
4548static void
4549bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4550{
4551 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4552 struct bfa_fcs_lport_s *port = ns->port;
4553 struct fchs_s fchs;
4554 int len;
4555 struct bfa_fcxp_s *fcxp;
4556
4557 bfa_trc(port->fcs, port->pid);
4558
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004559 fcxp = fcxp_alloced ? fcxp_alloced :
4560 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004561 if (!fcxp) {
4562 port->stats.ns_gidft_alloc_wait++;
4563 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004564 bfa_fcs_lport_ns_send_gid_ft, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004565 return;
4566 }
4567 ns->fcxp = fcxp;
4568
4569 /*
4570 * This query is only initiated for FCP initiator mode.
4571 */
4572 len = fc_gid_ft_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4573 ns->port->pid, FC_TYPE_FCP);
4574
4575 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4576 FC_CLASS_3, len, &fchs,
4577 bfa_fcs_lport_ns_gid_ft_response, (void *)ns,
4578 bfa_fcxp_get_maxrsp(port->fcs->bfa), FC_FCCT_TOV);
4579
4580 port->stats.ns_gidft_sent++;
4581
4582 bfa_sm_send_event(ns, NSSM_EVENT_GIDFT_SENT);
4583}
4584
4585static void
4586bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4587 void *cbarg, bfa_status_t req_status,
4588 u32 rsp_len, u32 resid_len,
4589 struct fchs_s *rsp_fchs)
4590{
4591 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4592 struct bfa_fcs_lport_s *port = ns->port;
4593 struct ct_hdr_s *cthdr = NULL;
4594 u32 n_pids;
4595
4596 bfa_trc(port->fcs, port->port_cfg.pwwn);
4597
4598 /*
4599 * Sanity Checks
4600 */
4601 if (req_status != BFA_STATUS_OK) {
4602 bfa_trc(port->fcs, req_status);
4603 port->stats.ns_gidft_rsp_err++;
4604 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4605 return;
4606 }
4607
4608 if (resid_len != 0) {
4609 /*
4610 * TBD : we will need to allocate a larger buffer & retry the
4611 * command
4612 */
4613 bfa_trc(port->fcs, rsp_len);
4614 bfa_trc(port->fcs, resid_len);
4615 return;
4616 }
4617
4618 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004619 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004620
4621 switch (cthdr->cmd_rsp_code) {
4622
4623 case CT_RSP_ACCEPT:
4624
4625 port->stats.ns_gidft_accepts++;
4626 n_pids = (fc_get_ctresp_pyld_len(rsp_len) / sizeof(u32));
4627 bfa_trc(port->fcs, n_pids);
4628 bfa_fcs_lport_ns_process_gidft_pids(port,
4629 (u32 *) (cthdr + 1),
4630 n_pids);
4631 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4632 break;
4633
4634 case CT_RSP_REJECT:
4635
4636 /*
4637 * Check the reason code & explanation.
4638 * There may not have been any FC4 devices in the fabric
4639 */
4640 port->stats.ns_gidft_rejects++;
4641 bfa_trc(port->fcs, cthdr->reason_code);
4642 bfa_trc(port->fcs, cthdr->exp_code);
4643
4644 if ((cthdr->reason_code == CT_RSN_UNABLE_TO_PERF)
4645 && (cthdr->exp_code == CT_NS_EXP_FT_NOT_REG)) {
4646
4647 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4648 } else {
4649 /*
4650 * for all other errors, retry
4651 */
4652 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4653 }
4654 break;
4655
4656 default:
4657 port->stats.ns_gidft_unknown_rsp++;
4658 bfa_trc(port->fcs, cthdr->cmd_rsp_code);
4659 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4660 }
4661}
4662
Jing Huang5fbe25c2010-10-18 17:17:23 -07004663/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004664 * This routine will be called by bfa_timer on timer timeouts.
4665 *
4666 * param[in] port - pointer to bfa_fcs_lport_t.
4667 *
4668 * return
4669 * void
4670 *
4671 * Special Considerations:
4672 *
4673 * note
4674 */
4675static void
4676bfa_fcs_lport_ns_timeout(void *arg)
4677{
4678 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) arg;
4679
4680 ns->port->stats.ns_timeouts++;
4681 bfa_sm_send_event(ns, NSSM_EVENT_TIMEOUT);
4682}
4683
4684/*
4685 * Process the PID list in GID_FT response
4686 */
4687static void
4688bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s *port, u32 *pid_buf,
4689 u32 n_pids)
4690{
4691 struct fcgs_gidft_resp_s *gidft_entry;
4692 struct bfa_fcs_rport_s *rport;
4693 u32 ii;
Krishna Gudipati61ba4392012-08-22 19:52:58 -07004694 struct bfa_fcs_fabric_s *fabric = port->fabric;
4695 struct bfa_fcs_vport_s *vport;
4696 struct list_head *qe;
4697 u8 found = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004698
4699 for (ii = 0; ii < n_pids; ii++) {
4700 gidft_entry = (struct fcgs_gidft_resp_s *) &pid_buf[ii];
4701
4702 if (gidft_entry->pid == port->pid)
4703 continue;
4704
4705 /*
Krishna Gudipati61ba4392012-08-22 19:52:58 -07004706 * Ignore PID if it is of base port
4707 * (Avoid vports discovering base port as remote port)
4708 */
4709 if (gidft_entry->pid == fabric->bport.pid)
4710 continue;
4711
4712 /*
4713 * Ignore PID if it is of vport created on the same base port
4714 * (Avoid vport discovering every other vport created on the
4715 * same port as remote port)
4716 */
4717 list_for_each(qe, &fabric->vport_q) {
4718 vport = (struct bfa_fcs_vport_s *) qe;
4719 if (vport->lport.pid == gidft_entry->pid)
4720 found = 1;
4721 }
4722
4723 if (found) {
4724 found = 0;
4725 continue;
4726 }
4727
4728 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004729 * Check if this rport already exists
4730 */
4731 rport = bfa_fcs_lport_get_rport_by_pid(port, gidft_entry->pid);
4732 if (rport == NULL) {
4733 /*
4734 * this is a new device. create rport
4735 */
4736 rport = bfa_fcs_rport_create(port, gidft_entry->pid);
4737 } else {
4738 /*
4739 * this rport already exists
4740 */
4741 bfa_fcs_rport_scn(rport);
4742 }
4743
4744 bfa_trc(port->fcs, gidft_entry->pid);
4745
4746 /*
4747 * if the last entry bit is set, bail out.
4748 */
4749 if (gidft_entry->last)
4750 return;
4751 }
4752}
4753
Jing Huang5fbe25c2010-10-18 17:17:23 -07004754/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004755 * fcs_ns_public FCS nameserver public interfaces
4756 */
4757
4758/*
4759 * Functions called by port/fab.
4760 * These will send relevant Events to the ns state machine.
4761 */
4762void
4763bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s *port)
4764{
4765 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
4766
4767 ns->port = port;
4768 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4769}
4770
4771void
4772bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s *port)
4773{
4774 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
4775
4776 ns->port = port;
4777 bfa_sm_send_event(ns, NSSM_EVENT_PORT_OFFLINE);
4778}
4779
4780void
4781bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s *port)
4782{
4783 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
4784
4785 ns->port = port;
4786 bfa_sm_send_event(ns, NSSM_EVENT_PORT_ONLINE);
4787}
4788
4789void
4790bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s *port)
4791{
4792 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
4793
4794 bfa_trc(port->fcs, port->pid);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07004795 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_online))
4796 bfa_sm_send_event(ns, NSSM_EVENT_NS_QUERY);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004797}
4798
Maggie52f94b62010-11-29 18:21:32 -08004799static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004800bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port)
4801{
4802
4803 struct bfa_fcs_rport_s *rport;
4804 u8 nwwns;
4805 wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
4806 int ii;
4807
4808 bfa_iocfc_get_bootwwns(port->fcs->bfa, &nwwns, wwns);
4809
4810 for (ii = 0 ; ii < nwwns; ++ii) {
4811 rport = bfa_fcs_rport_create_by_wwn(port, wwns[ii]);
Jing Huangd4b671c2010-12-26 21:46:35 -08004812 WARN_ON(!rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004813 }
4814}
4815
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07004816void
4817bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
4818{
4819 struct bfa_fcs_lport_ns_s *ns = cbarg;
4820 struct bfa_fcs_lport_s *port = ns->port;
4821 struct fchs_s fchs;
4822 struct bfa_fcxp_s *fcxp;
4823 u8 symbl[256];
4824 u8 *psymbl = &symbl[0];
4825 int len;
4826
4827 if (!bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
4828 return;
4829
4830 /* Avoid sending RSPN in the following states. */
4831 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_offline) ||
4832 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_sending) ||
4833 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi) ||
4834 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_retry) ||
4835 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry))
4836 return;
4837
4838 memset(symbl, 0, sizeof(symbl));
4839 bfa_trc(port->fcs, port->port_cfg.pwwn);
4840
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004841 fcxp = fcxp_alloced ? fcxp_alloced :
4842 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07004843 if (!fcxp) {
4844 port->stats.ns_rspnid_alloc_wait++;
4845 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004846 bfa_fcs_lport_ns_util_send_rspn_id, ns, BFA_FALSE);
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07004847 return;
4848 }
4849
4850 ns->fcxp = fcxp;
4851
4852 if (port->vport) {
4853 /*
4854 * For Vports, we append the vport's port symbolic name
4855 * to that of the base port.
4856 */
4857 strncpy((char *)psymbl, (char *)&(bfa_fcs_lport_get_psym_name
4858 (bfa_fcs_get_base_port(port->fcs))),
4859 strlen((char *)&bfa_fcs_lport_get_psym_name(
4860 bfa_fcs_get_base_port(port->fcs))));
4861
4862 /* Ensure we have a null terminating string. */
4863 ((char *)psymbl)[strlen((char *)&bfa_fcs_lport_get_psym_name(
4864 bfa_fcs_get_base_port(port->fcs)))] = 0;
4865
4866 strncat((char *)psymbl,
4867 (char *)&(bfa_fcs_lport_get_psym_name(port)),
4868 strlen((char *)&bfa_fcs_lport_get_psym_name(port)));
4869 }
4870
4871 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4872 bfa_fcs_lport_get_fcid(port), 0, psymbl);
4873
4874 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4875 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
4876
4877 port->stats.ns_rspnid_sent++;
4878}
4879
Jing Huang5fbe25c2010-10-18 17:17:23 -07004880/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004881 * FCS SCN
4882 */
4883
4884#define FC_QOS_RSCN_EVENT 0x0c
4885#define FC_FABRIC_NAME_RSCN_EVENT 0x0d
4886
4887/*
4888 * forward declarations
4889 */
4890static void bfa_fcs_lport_scn_send_scr(void *scn_cbarg,
4891 struct bfa_fcxp_s *fcxp_alloced);
4892static void bfa_fcs_lport_scn_scr_response(void *fcsarg,
4893 struct bfa_fcxp_s *fcxp,
4894 void *cbarg,
4895 bfa_status_t req_status,
4896 u32 rsp_len,
4897 u32 resid_len,
4898 struct fchs_s *rsp_fchs);
4899static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
4900 struct fchs_s *rx_fchs);
4901static void bfa_fcs_lport_scn_timeout(void *arg);
4902
Jing Huang5fbe25c2010-10-18 17:17:23 -07004903/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004904 * fcs_scm_sm FCS SCN state machine
4905 */
4906
Jing Huang5fbe25c2010-10-18 17:17:23 -07004907/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004908 * VPort SCN State Machine events
4909 */
4910enum port_scn_event {
4911 SCNSM_EVENT_PORT_ONLINE = 1,
4912 SCNSM_EVENT_PORT_OFFLINE = 2,
4913 SCNSM_EVENT_RSP_OK = 3,
4914 SCNSM_EVENT_RSP_ERROR = 4,
4915 SCNSM_EVENT_TIMEOUT = 5,
4916 SCNSM_EVENT_SCR_SENT = 6,
4917};
4918
4919static void bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
4920 enum port_scn_event event);
4921static void bfa_fcs_lport_scn_sm_sending_scr(
4922 struct bfa_fcs_lport_scn_s *scn,
4923 enum port_scn_event event);
4924static void bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
4925 enum port_scn_event event);
4926static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
4927 enum port_scn_event event);
4928static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
4929 enum port_scn_event event);
4930
Jing Huang5fbe25c2010-10-18 17:17:23 -07004931/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004932 * Starting state - awaiting link up.
4933 */
4934static void
4935bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
4936 enum port_scn_event event)
4937{
4938 switch (event) {
4939 case SCNSM_EVENT_PORT_ONLINE:
4940 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
4941 bfa_fcs_lport_scn_send_scr(scn, NULL);
4942 break;
4943
4944 case SCNSM_EVENT_PORT_OFFLINE:
4945 break;
4946
4947 default:
4948 bfa_sm_fault(scn->port->fcs, event);
4949 }
4950}
4951
4952static void
4953bfa_fcs_lport_scn_sm_sending_scr(struct bfa_fcs_lport_scn_s *scn,
4954 enum port_scn_event event)
4955{
4956 switch (event) {
4957 case SCNSM_EVENT_SCR_SENT:
4958 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr);
4959 break;
4960
4961 case SCNSM_EVENT_PORT_OFFLINE:
4962 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
4963 bfa_fcxp_walloc_cancel(scn->port->fcs->bfa, &scn->fcxp_wqe);
4964 break;
4965
4966 default:
4967 bfa_sm_fault(scn->port->fcs, event);
4968 }
4969}
4970
4971static void
4972bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
4973 enum port_scn_event event)
4974{
4975 struct bfa_fcs_lport_s *port = scn->port;
4976
4977 switch (event) {
4978 case SCNSM_EVENT_RSP_OK:
4979 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_online);
4980 break;
4981
4982 case SCNSM_EVENT_RSP_ERROR:
4983 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr_retry);
4984 bfa_timer_start(port->fcs->bfa, &scn->timer,
4985 bfa_fcs_lport_scn_timeout, scn,
4986 BFA_FCS_RETRY_TIMEOUT);
4987 break;
4988
4989 case SCNSM_EVENT_PORT_OFFLINE:
4990 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
4991 bfa_fcxp_discard(scn->fcxp);
4992 break;
4993
4994 default:
4995 bfa_sm_fault(port->fcs, event);
4996 }
4997}
4998
4999static void
5000bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5001 enum port_scn_event event)
5002{
5003 switch (event) {
5004 case SCNSM_EVENT_TIMEOUT:
5005 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5006 bfa_fcs_lport_scn_send_scr(scn, NULL);
5007 break;
5008
5009 case SCNSM_EVENT_PORT_OFFLINE:
5010 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5011 bfa_timer_stop(&scn->timer);
5012 break;
5013
5014 default:
5015 bfa_sm_fault(scn->port->fcs, event);
5016 }
5017}
5018
5019static void
5020bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5021 enum port_scn_event event)
5022{
5023 switch (event) {
5024 case SCNSM_EVENT_PORT_OFFLINE:
5025 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5026 break;
5027
5028 default:
5029 bfa_sm_fault(scn->port->fcs, event);
5030 }
5031}
5032
5033
5034
Jing Huang5fbe25c2010-10-18 17:17:23 -07005035/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005036 * fcs_scn_private FCS SCN private functions
5037 */
5038
Jing Huang5fbe25c2010-10-18 17:17:23 -07005039/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005040 * This routine will be called to send a SCR command.
5041 */
5042static void
5043bfa_fcs_lport_scn_send_scr(void *scn_cbarg, struct bfa_fcxp_s *fcxp_alloced)
5044{
5045 struct bfa_fcs_lport_scn_s *scn = scn_cbarg;
5046 struct bfa_fcs_lport_s *port = scn->port;
5047 struct fchs_s fchs;
5048 int len;
5049 struct bfa_fcxp_s *fcxp;
5050
5051 bfa_trc(port->fcs, port->pid);
5052 bfa_trc(port->fcs, port->port_cfg.pwwn);
5053
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07005054 fcxp = fcxp_alloced ? fcxp_alloced :
5055 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005056 if (!fcxp) {
5057 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &scn->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07005058 bfa_fcs_lport_scn_send_scr, scn, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005059 return;
5060 }
5061 scn->fcxp = fcxp;
5062
5063 /* Handle VU registrations for Base port only */
5064 if ((!port->vport) && bfa_ioc_get_fcmode(&port->fcs->bfa->ioc)) {
5065 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf7f738122010-12-09 19:08:43 -08005066 port->fabric->lps->brcd_switch,
5067 port->pid, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005068 } else {
5069 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5070 BFA_FALSE,
5071 port->pid, 0);
5072 }
5073
5074 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5075 FC_CLASS_3, len, &fchs,
5076 bfa_fcs_lport_scn_scr_response,
5077 (void *)scn, FC_MAX_PDUSZ, FC_ELS_TOV);
5078
5079 bfa_sm_send_event(scn, SCNSM_EVENT_SCR_SENT);
5080}
5081
5082static void
5083bfa_fcs_lport_scn_scr_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
5084 void *cbarg, bfa_status_t req_status, u32 rsp_len,
5085 u32 resid_len, struct fchs_s *rsp_fchs)
5086{
5087 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) cbarg;
5088 struct bfa_fcs_lport_s *port = scn->port;
5089 struct fc_els_cmd_s *els_cmd;
5090 struct fc_ls_rjt_s *ls_rjt;
5091
5092 bfa_trc(port->fcs, port->port_cfg.pwwn);
5093
5094 /*
5095 * Sanity Checks
5096 */
5097 if (req_status != BFA_STATUS_OK) {
5098 bfa_trc(port->fcs, req_status);
5099 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5100 return;
5101 }
5102
5103 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
5104
5105 switch (els_cmd->els_code) {
5106
5107 case FC_ELS_ACC:
5108 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_OK);
5109 break;
5110
5111 case FC_ELS_LS_RJT:
5112
5113 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
5114
5115 bfa_trc(port->fcs, ls_rjt->reason_code);
5116 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
5117
5118 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5119 break;
5120
5121 default:
5122 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5123 }
5124}
5125
5126/*
5127 * Send a LS Accept
5128 */
5129static void
5130bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5131 struct fchs_s *rx_fchs)
5132{
5133 struct fchs_s fchs;
5134 struct bfa_fcxp_s *fcxp;
5135 struct bfa_rport_s *bfa_rport = NULL;
5136 int len;
5137
5138 bfa_trc(port->fcs, rx_fchs->s_id);
5139
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07005140 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005141 if (!fcxp)
5142 return;
5143
5144 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5145 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
5146 rx_fchs->ox_id);
5147
5148 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
5149 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
5150 FC_MAX_PDUSZ, 0);
5151}
5152
Jing Huang5fbe25c2010-10-18 17:17:23 -07005153/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005154 * This routine will be called by bfa_timer on timer timeouts.
5155 *
5156 * param[in] vport - pointer to bfa_fcs_lport_t.
5157 * param[out] vport_status - pointer to return vport status in
5158 *
5159 * return
5160 * void
5161 *
5162 * Special Considerations:
5163 *
5164 * note
5165 */
5166static void
5167bfa_fcs_lport_scn_timeout(void *arg)
5168{
5169 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) arg;
5170
5171 bfa_sm_send_event(scn, SCNSM_EVENT_TIMEOUT);
5172}
5173
5174
5175
Jing Huang5fbe25c2010-10-18 17:17:23 -07005176/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005177 * fcs_scn_public FCS state change notification public interfaces
5178 */
5179
5180/*
5181 * Functions called by port/fab
5182 */
5183void
5184bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s *port)
5185{
5186 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5187
5188 scn->port = port;
5189 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5190}
5191
5192void
5193bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s *port)
5194{
5195 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5196
5197 scn->port = port;
5198 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_OFFLINE);
5199}
5200
5201void
5202bfa_fcs_lport_scn_online(struct bfa_fcs_lport_s *port)
5203{
5204 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5205
5206 scn->port = port;
5207 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_ONLINE);
5208}
5209
5210static void
5211bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s *port, u32 rpid)
5212{
5213 struct bfa_fcs_rport_s *rport;
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005214 struct bfa_fcs_fabric_s *fabric = port->fabric;
5215 struct bfa_fcs_vport_s *vport;
5216 struct list_head *qe;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005217
5218 bfa_trc(port->fcs, rpid);
5219
Jing Huang5fbe25c2010-10-18 17:17:23 -07005220 /*
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005221 * Ignore PID if it is of base port or of vports created on the
5222 * same base port. It is to avoid vports discovering base port or
5223 * other vports created on same base port as remote port
5224 */
5225 if (rpid == fabric->bport.pid)
5226 return;
5227
5228 list_for_each(qe, &fabric->vport_q) {
5229 vport = (struct bfa_fcs_vport_s *) qe;
5230 if (vport->lport.pid == rpid)
5231 return;
5232 }
5233 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005234 * If this is an unknown device, then it just came online.
5235 * Otherwise let rport handle the RSCN event.
5236 */
5237 rport = bfa_fcs_lport_get_rport_by_pid(port, rpid);
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -07005238 if (!rport)
5239 rport = bfa_fcs_lport_get_rport_by_old_pid(port, rpid);
5240
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005241 if (rport == NULL) {
5242 /*
5243 * If min cfg mode is enabled, we donot need to
5244 * discover any new rports.
5245 */
5246 if (!__fcs_min_cfg(port->fcs))
5247 rport = bfa_fcs_rport_create(port, rpid);
5248 } else
5249 bfa_fcs_rport_scn(rport);
5250}
5251
Jing Huang5fbe25c2010-10-18 17:17:23 -07005252/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005253 * rscn format based PID comparison
5254 */
5255#define __fc_pid_match(__c0, __c1, __fmt) \
5256 (((__fmt) == FC_RSCN_FORMAT_FABRIC) || \
5257 (((__fmt) == FC_RSCN_FORMAT_DOMAIN) && \
5258 ((__c0)[0] == (__c1)[0])) || \
5259 (((__fmt) == FC_RSCN_FORMAT_AREA) && \
5260 ((__c0)[0] == (__c1)[0]) && \
5261 ((__c0)[1] == (__c1)[1])))
5262
5263static void
5264bfa_fcs_lport_scn_multiport_rscn(struct bfa_fcs_lport_s *port,
5265 enum fc_rscn_format format,
5266 u32 rscn_pid)
5267{
5268 struct bfa_fcs_rport_s *rport;
5269 struct list_head *qe, *qe_next;
5270 u8 *c0, *c1;
5271
5272 bfa_trc(port->fcs, format);
5273 bfa_trc(port->fcs, rscn_pid);
5274
5275 c0 = (u8 *) &rscn_pid;
5276
5277 list_for_each_safe(qe, qe_next, &port->rport_q) {
5278 rport = (struct bfa_fcs_rport_s *) qe;
5279 c1 = (u8 *) &rport->pid;
5280 if (__fc_pid_match(c0, c1, format))
5281 bfa_fcs_rport_scn(rport);
5282 }
5283}
5284
5285
5286void
5287bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
5288 struct fchs_s *fchs, u32 len)
5289{
5290 struct fc_rscn_pl_s *rscn = (struct fc_rscn_pl_s *) (fchs + 1);
5291 int num_entries;
5292 u32 rscn_pid;
5293 bfa_boolean_t nsquery = BFA_FALSE, found;
5294 int i = 0, j;
5295
5296 num_entries =
Jing Huangba816ea2010-10-18 17:10:50 -07005297 (be16_to_cpu(rscn->payldlen) -
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005298 sizeof(u32)) / sizeof(rscn->event[0]);
5299
5300 bfa_trc(port->fcs, num_entries);
5301
5302 port->stats.num_rscn++;
5303
5304 bfa_fcs_lport_scn_send_ls_acc(port, fchs);
5305
5306 for (i = 0; i < num_entries; i++) {
5307 rscn_pid = rscn->event[i].portid;
5308
5309 bfa_trc(port->fcs, rscn->event[i].format);
5310 bfa_trc(port->fcs, rscn_pid);
5311
5312 /* check for duplicate entries in the list */
5313 found = BFA_FALSE;
5314 for (j = 0; j < i; j++) {
5315 if (rscn->event[j].portid == rscn_pid) {
5316 found = BFA_TRUE;
5317 break;
5318 }
5319 }
5320
5321 /* if found in down the list, pid has been already processed */
5322 if (found) {
5323 bfa_trc(port->fcs, rscn_pid);
5324 continue;
5325 }
5326
5327 switch (rscn->event[i].format) {
5328 case FC_RSCN_FORMAT_PORTID:
5329 if (rscn->event[i].qualifier == FC_QOS_RSCN_EVENT) {
5330 /*
5331 * Ignore this event.
5332 * f/w would have processed it
5333 */
5334 bfa_trc(port->fcs, rscn_pid);
5335 } else {
5336 port->stats.num_portid_rscn++;
5337 bfa_fcs_lport_scn_portid_rscn(port, rscn_pid);
5338 }
5339 break;
5340
5341 case FC_RSCN_FORMAT_FABRIC:
5342 if (rscn->event[i].qualifier ==
5343 FC_FABRIC_NAME_RSCN_EVENT) {
5344 bfa_fcs_lport_ms_fabric_rscn(port);
5345 break;
5346 }
5347 /* !!!!!!!!! Fall Through !!!!!!!!!!!!! */
5348
5349 case FC_RSCN_FORMAT_AREA:
5350 case FC_RSCN_FORMAT_DOMAIN:
5351 nsquery = BFA_TRUE;
5352 bfa_fcs_lport_scn_multiport_rscn(port,
5353 rscn->event[i].format,
5354 rscn_pid);
5355 break;
5356
5357
5358 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08005359 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005360 nsquery = BFA_TRUE;
5361 }
5362 }
5363
Jing Huang5fbe25c2010-10-18 17:17:23 -07005364 /*
5365 * If any of area, domain or fabric RSCN is received, do a fresh
5366 * discovery to find new devices.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005367 */
5368 if (nsquery)
5369 bfa_fcs_lport_ns_query(port);
5370}
5371
Jing Huang5fbe25c2010-10-18 17:17:23 -07005372/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005373 * BFA FCS port
5374 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07005375/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005376 * fcs_port_api BFA FCS port API
5377 */
5378struct bfa_fcs_lport_s *
5379bfa_fcs_get_base_port(struct bfa_fcs_s *fcs)
5380{
5381 return &fcs->fabric.bport;
5382}
5383
5384wwn_t
5385bfa_fcs_lport_get_rport(struct bfa_fcs_lport_s *port, wwn_t wwn, int index,
5386 int nrports, bfa_boolean_t bwwn)
5387{
5388 struct list_head *qh, *qe;
5389 struct bfa_fcs_rport_s *rport = NULL;
5390 int i;
5391 struct bfa_fcs_s *fcs;
5392
5393 if (port == NULL || nrports == 0)
5394 return (wwn_t) 0;
5395
5396 fcs = port->fcs;
5397 bfa_trc(fcs, (u32) nrports);
5398
5399 i = 0;
5400 qh = &port->rport_q;
5401 qe = bfa_q_first(qh);
5402
5403 while ((qe != qh) && (i < nrports)) {
5404 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf16a1752010-12-09 19:12:32 -08005405 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005406 qe = bfa_q_next(qe);
5407 bfa_trc(fcs, (u32) rport->pwwn);
5408 bfa_trc(fcs, rport->pid);
5409 bfa_trc(fcs, i);
5410 continue;
5411 }
5412
5413 if (bwwn) {
5414 if (!memcmp(&wwn, &rport->pwwn, 8))
5415 break;
5416 } else {
5417 if (i == index)
5418 break;
5419 }
5420
5421 i++;
5422 qe = bfa_q_next(qe);
5423 }
5424
5425 bfa_trc(fcs, i);
5426 if (rport)
5427 return rport->pwwn;
5428 else
5429 return (wwn_t) 0;
5430}
5431
5432void
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -07005433bfa_fcs_lport_get_rport_quals(struct bfa_fcs_lport_s *port,
5434 struct bfa_rport_qualifier_s rports[], int *nrports)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005435{
5436 struct list_head *qh, *qe;
5437 struct bfa_fcs_rport_s *rport = NULL;
5438 int i;
5439 struct bfa_fcs_s *fcs;
5440
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -07005441 if (port == NULL || rports == NULL || *nrports == 0)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005442 return;
5443
5444 fcs = port->fcs;
5445 bfa_trc(fcs, (u32) *nrports);
5446
5447 i = 0;
5448 qh = &port->rport_q;
5449 qe = bfa_q_first(qh);
5450
5451 while ((qe != qh) && (i < *nrports)) {
5452 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf16a1752010-12-09 19:12:32 -08005453 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005454 qe = bfa_q_next(qe);
5455 bfa_trc(fcs, (u32) rport->pwwn);
5456 bfa_trc(fcs, rport->pid);
5457 bfa_trc(fcs, i);
5458 continue;
5459 }
5460
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -07005461 if (!rport->pwwn && !rport->pid) {
5462 qe = bfa_q_next(qe);
5463 continue;
5464 }
5465
5466 rports[i].pwwn = rport->pwwn;
5467 rports[i].pid = rport->pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005468
5469 i++;
5470 qe = bfa_q_next(qe);
5471 }
5472
5473 bfa_trc(fcs, i);
5474 *nrports = i;
5475}
5476
5477/*
5478 * Iterate's through all the rport's in the given port to
5479 * determine the maximum operating speed.
5480 *
5481 * !!!! To be used in TRL Functionality only !!!!
5482 */
5483bfa_port_speed_t
5484bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t *port)
5485{
5486 struct list_head *qh, *qe;
5487 struct bfa_fcs_rport_s *rport = NULL;
5488 struct bfa_fcs_s *fcs;
5489 bfa_port_speed_t max_speed = 0;
5490 struct bfa_port_attr_s port_attr;
5491 bfa_port_speed_t port_speed, rport_speed;
5492 bfa_boolean_t trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
5493
5494
5495 if (port == NULL)
5496 return 0;
5497
5498 fcs = port->fcs;
5499
5500 /* Get Physical port's current speed */
5501 bfa_fcport_get_attr(port->fcs->bfa, &port_attr);
5502 port_speed = port_attr.speed;
5503 bfa_trc(fcs, port_speed);
5504
5505 qh = &port->rport_q;
5506 qe = bfa_q_first(qh);
5507
5508 while (qe != qh) {
5509 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf16a1752010-12-09 19:12:32 -08005510 if ((bfa_ntoh3b(rport->pid) > 0xFFF000) ||
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07005511 (bfa_fcs_rport_get_state(rport) == BFA_RPORT_OFFLINE) ||
5512 (rport->scsi_function != BFA_RPORT_TARGET)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005513 qe = bfa_q_next(qe);
5514 continue;
5515 }
5516
5517 rport_speed = rport->rpf.rpsc_speed;
5518 if ((trl_enabled) && (rport_speed ==
5519 BFA_PORT_SPEED_UNKNOWN)) {
5520 /* Use default ratelim speed setting */
5521 rport_speed =
5522 bfa_fcport_get_ratelim_speed(port->fcs->bfa);
5523 }
5524
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07005525 if (rport_speed > max_speed)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005526 max_speed = rport_speed;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005527
5528 qe = bfa_q_next(qe);
5529 }
5530
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07005531 if (max_speed > port_speed)
5532 max_speed = port_speed;
5533
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005534 bfa_trc(fcs, max_speed);
5535 return max_speed;
5536}
5537
5538struct bfa_fcs_lport_s *
5539bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
5540{
5541 struct bfa_fcs_vport_s *vport;
5542 bfa_fcs_vf_t *vf;
5543
Jing Huangd4b671c2010-12-26 21:46:35 -08005544 WARN_ON(fcs == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005545
5546 vf = bfa_fcs_vf_lookup(fcs, vf_id);
5547 if (vf == NULL) {
5548 bfa_trc(fcs, vf_id);
5549 return NULL;
5550 }
5551
5552 if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
5553 return &vf->bport;
5554
5555 vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
5556 if (vport)
5557 return &vport->lport;
5558
5559 return NULL;
5560}
5561
5562/*
5563 * API corresponding to NPIV_VPORT_GETINFO.
5564 */
5565void
5566bfa_fcs_lport_get_info(struct bfa_fcs_lport_s *port,
5567 struct bfa_lport_info_s *port_info)
5568{
5569
5570 bfa_trc(port->fcs, port->fabric->fabric_name);
5571
5572 if (port->vport == NULL) {
5573 /*
5574 * This is a Physical port
5575 */
5576 port_info->port_type = BFA_LPORT_TYPE_PHYSICAL;
5577
5578 /*
5579 * @todo : need to fix the state & reason
5580 */
5581 port_info->port_state = 0;
5582 port_info->offline_reason = 0;
5583
5584 port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
5585 port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
5586
5587 port_info->max_vports_supp =
5588 bfa_lps_get_max_vport(port->fcs->bfa);
5589 port_info->num_vports_inuse =
Maggie Zhangf7f738122010-12-09 19:08:43 -08005590 port->fabric->num_vports;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005591 port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
5592 port_info->num_rports_inuse = port->num_rports;
5593 } else {
5594 /*
5595 * This is a virtual port
5596 */
5597 port_info->port_type = BFA_LPORT_TYPE_VIRTUAL;
5598
5599 /*
5600 * @todo : need to fix the state & reason
5601 */
5602 port_info->port_state = 0;
5603 port_info->offline_reason = 0;
5604
5605 port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
5606 port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
5607 }
5608}
5609
5610void
5611bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s *fcs_port,
5612 struct bfa_lport_stats_s *port_stats)
5613{
5614 *port_stats = fcs_port->stats;
5615}
5616
5617void
5618bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port)
5619{
Jing Huang6a18b162010-10-18 17:08:54 -07005620 memset(&fcs_port->stats, 0, sizeof(struct bfa_lport_stats_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005621}
5622
Jing Huang5fbe25c2010-10-18 17:17:23 -07005623/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005624 * FCS virtual port state machine
5625 */
5626
5627#define __vport_fcs(__vp) ((__vp)->lport.fcs)
5628#define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
5629#define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
5630#define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
5631#define __vport_fcid(__vp) ((__vp)->lport.pid)
5632#define __vport_fabric(__vp) ((__vp)->lport.fabric)
5633#define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
5634
5635#define BFA_FCS_VPORT_MAX_RETRIES 5
5636/*
5637 * Forward declarations
5638 */
5639static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport);
5640static void bfa_fcs_vport_timeout(void *vport_arg);
5641static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
5642static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
5643
Jing Huang5fbe25c2010-10-18 17:17:23 -07005644/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005645 * fcs_vport_sm FCS virtual port state machine
5646 */
5647
Jing Huang5fbe25c2010-10-18 17:17:23 -07005648/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005649 * VPort State Machine events
5650 */
5651enum bfa_fcs_vport_event {
5652 BFA_FCS_VPORT_SM_CREATE = 1, /* vport create event */
5653 BFA_FCS_VPORT_SM_DELETE = 2, /* vport delete event */
5654 BFA_FCS_VPORT_SM_START = 3, /* vport start request */
5655 BFA_FCS_VPORT_SM_STOP = 4, /* stop: unsupported */
5656 BFA_FCS_VPORT_SM_ONLINE = 5, /* fabric online */
5657 BFA_FCS_VPORT_SM_OFFLINE = 6, /* fabric offline event */
5658 BFA_FCS_VPORT_SM_FRMSENT = 7, /* fdisc/logo sent events */
5659 BFA_FCS_VPORT_SM_RSP_OK = 8, /* good response */
5660 BFA_FCS_VPORT_SM_RSP_ERROR = 9, /* error/bad response */
5661 BFA_FCS_VPORT_SM_TIMEOUT = 10, /* delay timer event */
5662 BFA_FCS_VPORT_SM_DELCOMP = 11, /* lport delete completion */
5663 BFA_FCS_VPORT_SM_RSP_DUP_WWN = 12, /* Dup wnn error*/
5664 BFA_FCS_VPORT_SM_RSP_FAILED = 13, /* non-retryable failure */
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07005665 BFA_FCS_VPORT_SM_STOPCOMP = 14, /* vport delete completion */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005666};
5667
5668static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
5669 enum bfa_fcs_vport_event event);
5670static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
5671 enum bfa_fcs_vport_event event);
5672static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
5673 enum bfa_fcs_vport_event event);
5674static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
5675 enum bfa_fcs_vport_event event);
5676static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
5677 enum bfa_fcs_vport_event event);
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07005678static void bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
5679 enum bfa_fcs_vport_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005680static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
5681 enum bfa_fcs_vport_event event);
5682static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
5683 enum bfa_fcs_vport_event event);
5684static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
5685 enum bfa_fcs_vport_event event);
5686static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
5687 enum bfa_fcs_vport_event event);
5688static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
5689 enum bfa_fcs_vport_event event);
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07005690static void bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
5691 enum bfa_fcs_vport_event event);
5692static void bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
5693 enum bfa_fcs_vport_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005694
5695static struct bfa_sm_table_s vport_sm_table[] = {
5696 {BFA_SM(bfa_fcs_vport_sm_uninit), BFA_FCS_VPORT_UNINIT},
5697 {BFA_SM(bfa_fcs_vport_sm_created), BFA_FCS_VPORT_CREATED},
5698 {BFA_SM(bfa_fcs_vport_sm_offline), BFA_FCS_VPORT_OFFLINE},
5699 {BFA_SM(bfa_fcs_vport_sm_fdisc), BFA_FCS_VPORT_FDISC},
5700 {BFA_SM(bfa_fcs_vport_sm_fdisc_retry), BFA_FCS_VPORT_FDISC_RETRY},
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07005701 {BFA_SM(bfa_fcs_vport_sm_fdisc_rsp_wait), BFA_FCS_VPORT_FDISC_RSP_WAIT},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005702 {BFA_SM(bfa_fcs_vport_sm_online), BFA_FCS_VPORT_ONLINE},
5703 {BFA_SM(bfa_fcs_vport_sm_deleting), BFA_FCS_VPORT_DELETING},
5704 {BFA_SM(bfa_fcs_vport_sm_cleanup), BFA_FCS_VPORT_CLEANUP},
5705 {BFA_SM(bfa_fcs_vport_sm_logo), BFA_FCS_VPORT_LOGO},
5706 {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
5707};
5708
Jing Huang5fbe25c2010-10-18 17:17:23 -07005709/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005710 * Beginning state.
5711 */
5712static void
5713bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
5714 enum bfa_fcs_vport_event event)
5715{
5716 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5717 bfa_trc(__vport_fcs(vport), event);
5718
5719 switch (event) {
5720 case BFA_FCS_VPORT_SM_CREATE:
5721 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
5722 bfa_fcs_fabric_addvport(__vport_fabric(vport), vport);
5723 break;
5724
5725 default:
5726 bfa_sm_fault(__vport_fcs(vport), event);
5727 }
5728}
5729
Jing Huang5fbe25c2010-10-18 17:17:23 -07005730/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005731 * Created state - a start event is required to start up the state machine.
5732 */
5733static void
5734bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
5735 enum bfa_fcs_vport_event event)
5736{
5737 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5738 bfa_trc(__vport_fcs(vport), event);
5739
5740 switch (event) {
5741 case BFA_FCS_VPORT_SM_START:
Maggie Zhangf7f738122010-12-09 19:08:43 -08005742 if (bfa_sm_cmp_state(__vport_fabric(vport),
5743 bfa_fcs_fabric_sm_online)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005744 && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport))) {
5745 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
5746 bfa_fcs_vport_do_fdisc(vport);
5747 } else {
Jing Huang5fbe25c2010-10-18 17:17:23 -07005748 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005749 * Fabric is offline or not NPIV capable, stay in
5750 * offline state.
5751 */
5752 vport->vport_stats.fab_no_npiv++;
5753 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
5754 }
5755 break;
5756
5757 case BFA_FCS_VPORT_SM_DELETE:
5758 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
5759 bfa_fcs_lport_delete(&vport->lport);
5760 break;
5761
5762 case BFA_FCS_VPORT_SM_ONLINE:
5763 case BFA_FCS_VPORT_SM_OFFLINE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07005764 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005765 * Ignore ONLINE/OFFLINE events from fabric
5766 * till vport is started.
5767 */
5768 break;
5769
5770 default:
5771 bfa_sm_fault(__vport_fcs(vport), event);
5772 }
5773}
5774
Jing Huang5fbe25c2010-10-18 17:17:23 -07005775/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005776 * Offline state - awaiting ONLINE event from fabric SM.
5777 */
5778static void
5779bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
5780 enum bfa_fcs_vport_event event)
5781{
5782 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5783 bfa_trc(__vport_fcs(vport), event);
5784
5785 switch (event) {
5786 case BFA_FCS_VPORT_SM_DELETE:
5787 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
5788 bfa_fcs_lport_delete(&vport->lport);
5789 break;
5790
5791 case BFA_FCS_VPORT_SM_ONLINE:
5792 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
5793 vport->fdisc_retries = 0;
5794 bfa_fcs_vport_do_fdisc(vport);
5795 break;
5796
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07005797 case BFA_FCS_VPORT_SM_STOP:
5798 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
5799 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
5800 break;
5801
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005802 case BFA_FCS_VPORT_SM_OFFLINE:
5803 /*
5804 * This can happen if the vport couldn't be initialzied
5805 * due the fact that the npiv was not enabled on the switch.
5806 * In that case we will put the vport in offline state.
5807 * However, the link can go down and cause the this event to
5808 * be sent when we are already offline. Ignore it.
5809 */
5810 break;
5811
5812 default:
5813 bfa_sm_fault(__vport_fcs(vport), event);
5814 }
5815}
5816
5817
Jing Huang5fbe25c2010-10-18 17:17:23 -07005818/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005819 * FDISC is sent and awaiting reply from fabric.
5820 */
5821static void
5822bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
5823 enum bfa_fcs_vport_event event)
5824{
5825 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5826 bfa_trc(__vport_fcs(vport), event);
5827
5828 switch (event) {
5829 case BFA_FCS_VPORT_SM_DELETE:
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07005830 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_rsp_wait);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005831 break;
5832
5833 case BFA_FCS_VPORT_SM_OFFLINE:
5834 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
Maggie Zhangf7f738122010-12-09 19:08:43 -08005835 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005836 break;
5837
5838 case BFA_FCS_VPORT_SM_RSP_OK:
5839 bfa_sm_set_state(vport, bfa_fcs_vport_sm_online);
5840 bfa_fcs_lport_online(&vport->lport);
5841 break;
5842
5843 case BFA_FCS_VPORT_SM_RSP_ERROR:
5844 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_retry);
5845 bfa_timer_start(__vport_bfa(vport), &vport->timer,
5846 bfa_fcs_vport_timeout, vport,
5847 BFA_FCS_RETRY_TIMEOUT);
5848 break;
5849
5850 case BFA_FCS_VPORT_SM_RSP_FAILED:
5851 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
5852 break;
5853
5854 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
5855 bfa_sm_set_state(vport, bfa_fcs_vport_sm_error);
5856 break;
5857
5858 default:
5859 bfa_sm_fault(__vport_fcs(vport), event);
5860 }
5861}
5862
Jing Huang5fbe25c2010-10-18 17:17:23 -07005863/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005864 * FDISC attempt failed - a timer is active to retry FDISC.
5865 */
5866static void
5867bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
5868 enum bfa_fcs_vport_event event)
5869{
5870 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5871 bfa_trc(__vport_fcs(vport), event);
5872
5873 switch (event) {
5874 case BFA_FCS_VPORT_SM_DELETE:
5875 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
5876 bfa_timer_stop(&vport->timer);
5877 bfa_fcs_lport_delete(&vport->lport);
5878 break;
5879
5880 case BFA_FCS_VPORT_SM_OFFLINE:
5881 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
5882 bfa_timer_stop(&vport->timer);
5883 break;
5884
5885 case BFA_FCS_VPORT_SM_TIMEOUT:
5886 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
5887 vport->vport_stats.fdisc_retries++;
5888 vport->fdisc_retries++;
5889 bfa_fcs_vport_do_fdisc(vport);
5890 break;
5891
5892 default:
5893 bfa_sm_fault(__vport_fcs(vport), event);
5894 }
5895}
5896
Jing Huang5fbe25c2010-10-18 17:17:23 -07005897/*
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07005898 * FDISC is in progress and we got a vport delete request -
5899 * this is a wait state while we wait for fdisc response and
5900 * we will transition to the appropriate state - on rsp status.
5901 */
5902static void
5903bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
5904 enum bfa_fcs_vport_event event)
5905{
5906 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5907 bfa_trc(__vport_fcs(vport), event);
5908
5909 switch (event) {
5910 case BFA_FCS_VPORT_SM_RSP_OK:
5911 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
5912 bfa_fcs_lport_delete(&vport->lport);
5913 break;
5914
5915 case BFA_FCS_VPORT_SM_DELETE:
5916 break;
5917
5918 case BFA_FCS_VPORT_SM_OFFLINE:
5919 case BFA_FCS_VPORT_SM_RSP_ERROR:
5920 case BFA_FCS_VPORT_SM_RSP_FAILED:
5921 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
5922 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
5923 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
5924 bfa_fcs_lport_delete(&vport->lport);
5925 break;
5926
5927 default:
5928 bfa_sm_fault(__vport_fcs(vport), event);
5929 }
5930}
5931
5932/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005933 * Vport is online (FDISC is complete).
5934 */
5935static void
5936bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
5937 enum bfa_fcs_vport_event event)
5938{
5939 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5940 bfa_trc(__vport_fcs(vport), event);
5941
5942 switch (event) {
5943 case BFA_FCS_VPORT_SM_DELETE:
5944 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
5945 bfa_fcs_lport_delete(&vport->lport);
5946 break;
5947
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07005948 case BFA_FCS_VPORT_SM_STOP:
5949 bfa_sm_set_state(vport, bfa_fcs_vport_sm_stopping);
5950 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
5951 break;
5952
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005953 case BFA_FCS_VPORT_SM_OFFLINE:
5954 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
Maggie Zhangf7f738122010-12-09 19:08:43 -08005955 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005956 bfa_fcs_lport_offline(&vport->lport);
5957 break;
5958
5959 default:
5960 bfa_sm_fault(__vport_fcs(vport), event);
5961 }
5962}
5963
Jing Huang5fbe25c2010-10-18 17:17:23 -07005964/*
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07005965 * Vport is being stopped - awaiting lport stop completion to send
5966 * LOGO to fabric.
5967 */
5968static void
5969bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
5970 enum bfa_fcs_vport_event event)
5971{
5972 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5973 bfa_trc(__vport_fcs(vport), event);
5974
5975 switch (event) {
5976 case BFA_FCS_VPORT_SM_STOPCOMP:
5977 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo_for_stop);
5978 bfa_fcs_vport_do_logo(vport);
5979 break;
5980
5981 case BFA_FCS_VPORT_SM_OFFLINE:
5982 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
5983 break;
5984
5985 default:
5986 bfa_sm_fault(__vport_fcs(vport), event);
5987 }
5988}
5989
5990/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005991 * Vport is being deleted - awaiting lport delete completion to send
5992 * LOGO to fabric.
5993 */
5994static void
5995bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
5996 enum bfa_fcs_vport_event event)
5997{
5998 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5999 bfa_trc(__vport_fcs(vport), event);
6000
6001 switch (event) {
6002 case BFA_FCS_VPORT_SM_DELETE:
6003 break;
6004
6005 case BFA_FCS_VPORT_SM_DELCOMP:
6006 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
6007 bfa_fcs_vport_do_logo(vport);
6008 break;
6009
6010 case BFA_FCS_VPORT_SM_OFFLINE:
6011 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6012 break;
6013
6014 default:
6015 bfa_sm_fault(__vport_fcs(vport), event);
6016 }
6017}
6018
Jing Huang5fbe25c2010-10-18 17:17:23 -07006019/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006020 * Error State.
6021 * This state will be set when the Vport Creation fails due
6022 * to errors like Dup WWN. In this state only operation allowed
6023 * is a Vport Delete.
6024 */
6025static void
6026bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
6027 enum bfa_fcs_vport_event event)
6028{
6029 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6030 bfa_trc(__vport_fcs(vport), event);
6031
6032 switch (event) {
6033 case BFA_FCS_VPORT_SM_DELETE:
6034 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6035 bfa_fcs_lport_delete(&vport->lport);
6036 break;
6037
6038 default:
6039 bfa_trc(__vport_fcs(vport), event);
6040 }
6041}
6042
Jing Huang5fbe25c2010-10-18 17:17:23 -07006043/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006044 * Lport cleanup is in progress since vport is being deleted. Fabric is
6045 * offline, so no LOGO is needed to complete vport deletion.
6046 */
6047static void
6048bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
6049 enum bfa_fcs_vport_event event)
6050{
6051 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6052 bfa_trc(__vport_fcs(vport), event);
6053
6054 switch (event) {
6055 case BFA_FCS_VPORT_SM_DELCOMP:
6056 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6057 bfa_fcs_vport_free(vport);
6058 break;
6059
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07006060 case BFA_FCS_VPORT_SM_STOPCOMP:
6061 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6062 break;
6063
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006064 case BFA_FCS_VPORT_SM_DELETE:
6065 break;
6066
6067 default:
6068 bfa_sm_fault(__vport_fcs(vport), event);
6069 }
6070}
6071
Jing Huang5fbe25c2010-10-18 17:17:23 -07006072/*
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07006073 * LOGO is sent to fabric. Vport stop is in progress. Lport stop cleanup
6074 * is done.
6075 */
6076static void
6077bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
6078 enum bfa_fcs_vport_event event)
6079{
6080 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6081 bfa_trc(__vport_fcs(vport), event);
6082
6083 switch (event) {
6084 case BFA_FCS_VPORT_SM_OFFLINE:
6085 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6086 /*
6087 * !!! fall through !!!
6088 */
6089
6090 case BFA_FCS_VPORT_SM_RSP_OK:
6091 case BFA_FCS_VPORT_SM_RSP_ERROR:
6092 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6093 break;
6094
6095 default:
6096 bfa_sm_fault(__vport_fcs(vport), event);
6097 }
6098}
6099
6100/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006101 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
6102 * is done.
6103 */
6104static void
6105bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
6106 enum bfa_fcs_vport_event event)
6107{
6108 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6109 bfa_trc(__vport_fcs(vport), event);
6110
6111 switch (event) {
6112 case BFA_FCS_VPORT_SM_OFFLINE:
Maggie Zhangf7f738122010-12-09 19:08:43 -08006113 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006114 /*
6115 * !!! fall through !!!
6116 */
6117
6118 case BFA_FCS_VPORT_SM_RSP_OK:
6119 case BFA_FCS_VPORT_SM_RSP_ERROR:
6120 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6121 bfa_fcs_vport_free(vport);
6122 break;
6123
6124 case BFA_FCS_VPORT_SM_DELETE:
6125 break;
6126
6127 default:
6128 bfa_sm_fault(__vport_fcs(vport), event);
6129 }
6130}
6131
6132
6133
Jing Huang5fbe25c2010-10-18 17:17:23 -07006134/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006135 * fcs_vport_private FCS virtual port private functions
6136 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07006137/*
Krishna Gudipati7826f302011-07-20 16:59:13 -07006138 * Send AEN notification
6139 */
6140static void
6141bfa_fcs_vport_aen_post(struct bfa_fcs_lport_s *port,
6142 enum bfa_lport_aen_event event)
6143{
6144 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
6145 struct bfa_aen_entry_s *aen_entry;
6146
6147 bfad_get_aen_entry(bfad, aen_entry);
6148 if (!aen_entry)
6149 return;
6150
6151 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
6152 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
6153 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
6154 bfa_fcs_get_base_port(port->fcs));
6155 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
6156
6157 /* Send the AEN notification */
6158 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
6159 BFA_AEN_CAT_LPORT, event);
6160}
6161
6162/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006163 * This routine will be called to send a FDISC command.
6164 */
6165static void
6166bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
6167{
6168 bfa_lps_fdisc(vport->lps, vport,
6169 bfa_fcport_get_maxfrsize(__vport_bfa(vport)),
6170 __vport_pwwn(vport), __vport_nwwn(vport));
6171 vport->vport_stats.fdisc_sent++;
6172}
6173
6174static void
6175bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
6176{
Maggie Zhangf7f738122010-12-09 19:08:43 -08006177 u8 lsrjt_rsn = vport->lps->lsrjt_rsn;
6178 u8 lsrjt_expl = vport->lps->lsrjt_expl;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006179
6180 bfa_trc(__vport_fcs(vport), lsrjt_rsn);
6181 bfa_trc(__vport_fcs(vport), lsrjt_expl);
6182
6183 /* For certain reason codes, we don't want to retry. */
Maggie Zhangf7f738122010-12-09 19:08:43 -08006184 switch (vport->lps->lsrjt_expl) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006185 case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
6186 case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
6187 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6188 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
Krishna Gudipati7826f302011-07-20 16:59:13 -07006189 else {
6190 bfa_fcs_vport_aen_post(&vport->lport,
6191 BFA_LPORT_AEN_NPIV_DUP_WWN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006192 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
Krishna Gudipati7826f302011-07-20 16:59:13 -07006193 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006194 break;
6195
6196 case FC_LS_RJT_EXP_INSUFF_RES:
6197 /*
6198 * This means max logins per port/switch setting on the
6199 * switch was exceeded.
6200 */
6201 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6202 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
Krishna Gudipati7826f302011-07-20 16:59:13 -07006203 else {
6204 bfa_fcs_vport_aen_post(&vport->lport,
6205 BFA_LPORT_AEN_NPIV_FABRIC_MAX);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006206 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
Krishna Gudipati7826f302011-07-20 16:59:13 -07006207 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006208 break;
6209
6210 default:
Krishna Gudipati7826f302011-07-20 16:59:13 -07006211 if (vport->fdisc_retries == 0)
6212 bfa_fcs_vport_aen_post(&vport->lport,
6213 BFA_LPORT_AEN_NPIV_UNKNOWN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006214 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6215 }
6216}
6217
Jing Huang5fbe25c2010-10-18 17:17:23 -07006218/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006219 * Called to send a logout to the fabric. Used when a V-Port is
6220 * deleted/stopped.
6221 */
6222static void
6223bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
6224{
6225 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6226
6227 vport->vport_stats.logo_sent++;
6228 bfa_lps_fdisclogo(vport->lps);
6229}
6230
6231
Jing Huang5fbe25c2010-10-18 17:17:23 -07006232/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006233 * This routine will be called by bfa_timer on timer timeouts.
6234 *
6235 * param[in] vport - pointer to bfa_fcs_vport_t.
6236 * param[out] vport_status - pointer to return vport status in
6237 *
6238 * return
6239 * void
6240 *
6241 * Special Considerations:
6242 *
6243 * note
6244 */
6245static void
6246bfa_fcs_vport_timeout(void *vport_arg)
6247{
6248 struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *) vport_arg;
6249
6250 vport->vport_stats.fdisc_timeouts++;
6251 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
6252}
6253
6254static void
6255bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
6256{
6257 struct bfad_vport_s *vport_drv =
6258 (struct bfad_vport_s *)vport->vport_drv;
6259
6260 bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006261 bfa_lps_delete(vport->lps);
Krishna Gudipati17c201b2012-04-09 18:40:01 -07006262
6263 if (vport_drv->comp_del) {
6264 complete(vport_drv->comp_del);
6265 return;
6266 }
6267
6268 /*
6269 * We queue the vport delete work to the IM work_q from here.
6270 * The memory for the bfad_vport_s is freed from the FC function
6271 * template vport_delete entry point.
6272 */
Krishna Gudipati529f9a72012-07-13 16:08:22 -07006273 bfad_im_port_delete(vport_drv->drv_port.bfad, &vport_drv->drv_port);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006274}
6275
Jing Huang5fbe25c2010-10-18 17:17:23 -07006276/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006277 * fcs_vport_public FCS virtual port public interfaces
6278 */
6279
Jing Huang5fbe25c2010-10-18 17:17:23 -07006280/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006281 * Online notification from fabric SM.
6282 */
6283void
6284bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
6285{
6286 vport->vport_stats.fab_online++;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07006287 if (bfa_fcs_fabric_npiv_capable(__vport_fabric(vport)))
6288 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
6289 else
6290 vport->vport_stats.fab_no_npiv++;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006291}
6292
Jing Huang5fbe25c2010-10-18 17:17:23 -07006293/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006294 * Offline notification from fabric SM.
6295 */
6296void
6297bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
6298{
6299 vport->vport_stats.fab_offline++;
6300 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6301}
6302
Jing Huang5fbe25c2010-10-18 17:17:23 -07006303/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006304 * Cleanup notification from fabric SM on link timer expiry.
6305 */
6306void
6307bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
6308{
6309 vport->vport_stats.fab_cleanup++;
6310}
Krishna Gudipati881c1b32012-08-22 19:52:02 -07006311
6312/*
6313 * Stop notification from fabric SM. To be invoked from within FCS.
6314 */
6315void
6316bfa_fcs_vport_fcs_stop(struct bfa_fcs_vport_s *vport)
6317{
6318 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6319}
6320
Jing Huang5fbe25c2010-10-18 17:17:23 -07006321/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006322 * delete notification from fabric SM. To be invoked from within FCS.
6323 */
6324void
6325bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport)
6326{
6327 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6328}
6329
Jing Huang5fbe25c2010-10-18 17:17:23 -07006330/*
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07006331 * Stop completion callback from associated lport
6332 */
6333void
6334bfa_fcs_vport_stop_comp(struct bfa_fcs_vport_s *vport)
6335{
6336 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOPCOMP);
6337}
6338
6339/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006340 * Delete completion callback from associated lport
6341 */
6342void
6343bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
6344{
6345 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
6346}
6347
6348
6349
Jing Huang5fbe25c2010-10-18 17:17:23 -07006350/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006351 * fcs_vport_api Virtual port API
6352 */
6353
Jing Huang5fbe25c2010-10-18 17:17:23 -07006354/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006355 * Use this function to instantiate a new FCS vport object. This
6356 * function will not trigger any HW initialization process (which will be
6357 * done in vport_start() call)
6358 *
6359 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6360 * needs to be allocated by the driver.
6361 * param[in] fcs - FCS instance
6362 * param[in] vport_cfg - vport configuration
6363 * param[in] vf_id - VF_ID if vport is created within a VF.
6364 * FC_VF_ID_NULL to specify base fabric.
6365 * param[in] vport_drv - Opaque handle back to the driver's vport
6366 * structure
6367 *
6368 * retval BFA_STATUS_OK - on success.
6369 * retval BFA_STATUS_FAILED - on failure.
6370 */
6371bfa_status_t
6372bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6373 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6374 struct bfad_vport_s *vport_drv)
6375{
6376 if (vport_cfg->pwwn == 0)
6377 return BFA_STATUS_INVALID_WWN;
6378
6379 if (bfa_fcs_lport_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
6380 return BFA_STATUS_VPORT_WWN_BP;
6381
6382 if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
6383 return BFA_STATUS_VPORT_EXISTS;
6384
Maggie Zhangf7f738122010-12-09 19:08:43 -08006385 if (fcs->fabric.num_vports ==
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006386 bfa_lps_get_max_vport(fcs->bfa))
6387 return BFA_STATUS_VPORT_MAX;
6388
6389 vport->lps = bfa_lps_alloc(fcs->bfa);
6390 if (!vport->lps)
6391 return BFA_STATUS_VPORT_MAX;
6392
6393 vport->vport_drv = vport_drv;
6394 vport_cfg->preboot_vp = BFA_FALSE;
6395
6396 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6397 bfa_fcs_lport_attach(&vport->lport, fcs, vf_id, vport);
6398 bfa_fcs_lport_init(&vport->lport, vport_cfg);
6399 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
6400
6401 return BFA_STATUS_OK;
6402}
6403
Jing Huang5fbe25c2010-10-18 17:17:23 -07006404/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006405 * Use this function to instantiate a new FCS PBC vport object. This
6406 * function will not trigger any HW initialization process (which will be
6407 * done in vport_start() call)
6408 *
6409 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6410 * needs to be allocated by the driver.
6411 * param[in] fcs - FCS instance
6412 * param[in] vport_cfg - vport configuration
6413 * param[in] vf_id - VF_ID if vport is created within a VF.
6414 * FC_VF_ID_NULL to specify base fabric.
6415 * param[in] vport_drv - Opaque handle back to the driver's vport
6416 * structure
6417 *
6418 * retval BFA_STATUS_OK - on success.
6419 * retval BFA_STATUS_FAILED - on failure.
6420 */
6421bfa_status_t
6422bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6423 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6424 struct bfad_vport_s *vport_drv)
6425{
6426 bfa_status_t rc;
6427
6428 rc = bfa_fcs_vport_create(vport, fcs, vf_id, vport_cfg, vport_drv);
6429 vport->lport.port_cfg.preboot_vp = BFA_TRUE;
6430
6431 return rc;
6432}
6433
Jing Huang5fbe25c2010-10-18 17:17:23 -07006434/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006435 * Use this function to findout if this is a pbc vport or not.
6436 *
6437 * @param[in] vport - pointer to bfa_fcs_vport_t.
6438 *
6439 * @returns None
6440 */
6441bfa_boolean_t
6442bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s *vport)
6443{
6444
6445 if (vport && (vport->lport.port_cfg.preboot_vp == BFA_TRUE))
6446 return BFA_TRUE;
6447 else
6448 return BFA_FALSE;
6449
6450}
6451
Jing Huang5fbe25c2010-10-18 17:17:23 -07006452/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006453 * Use this function initialize the vport.
6454 *
6455 * @param[in] vport - pointer to bfa_fcs_vport_t.
6456 *
6457 * @returns None
6458 */
6459bfa_status_t
6460bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
6461{
6462 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
6463
6464 return BFA_STATUS_OK;
6465}
6466
Jing Huang5fbe25c2010-10-18 17:17:23 -07006467/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006468 * Use this function quiese the vport object. This function will return
6469 * immediately, when the vport is actually stopped, the
6470 * bfa_drv_vport_stop_cb() will be called.
6471 *
6472 * param[in] vport - pointer to bfa_fcs_vport_t.
6473 *
6474 * return None
6475 */
6476bfa_status_t
6477bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
6478{
6479 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6480
6481 return BFA_STATUS_OK;
6482}
6483
Jing Huang5fbe25c2010-10-18 17:17:23 -07006484/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006485 * Use this function to delete a vport object. Fabric object should
6486 * be stopped before this function call.
6487 *
6488 * !!!!!!! Donot invoke this from within FCS !!!!!!!
6489 *
6490 * param[in] vport - pointer to bfa_fcs_vport_t.
6491 *
6492 * return None
6493 */
6494bfa_status_t
6495bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
6496{
6497
6498 if (vport->lport.port_cfg.preboot_vp)
6499 return BFA_STATUS_PBC;
6500
6501 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6502
6503 return BFA_STATUS_OK;
6504}
6505
Jing Huang5fbe25c2010-10-18 17:17:23 -07006506/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006507 * Use this function to get vport's current status info.
6508 *
6509 * param[in] vport pointer to bfa_fcs_vport_t.
6510 * param[out] attr pointer to return vport attributes
6511 *
6512 * return None
6513 */
6514void
6515bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
6516 struct bfa_vport_attr_s *attr)
6517{
6518 if (vport == NULL || attr == NULL)
6519 return;
6520
Jing Huang6a18b162010-10-18 17:08:54 -07006521 memset(attr, 0, sizeof(struct bfa_vport_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006522
6523 bfa_fcs_lport_get_attr(&vport->lport, &attr->port_attr);
6524 attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
6525}
6526
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006527
Jing Huang5fbe25c2010-10-18 17:17:23 -07006528/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006529 * Lookup a virtual port. Excludes base port from lookup.
6530 */
6531struct bfa_fcs_vport_s *
6532bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
6533{
6534 struct bfa_fcs_vport_s *vport;
6535 struct bfa_fcs_fabric_s *fabric;
6536
6537 bfa_trc(fcs, vf_id);
6538 bfa_trc(fcs, vpwwn);
6539
6540 fabric = bfa_fcs_vf_lookup(fcs, vf_id);
6541 if (!fabric) {
6542 bfa_trc(fcs, vf_id);
6543 return NULL;
6544 }
6545
6546 vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
6547 return vport;
6548}
6549
Jing Huang5fbe25c2010-10-18 17:17:23 -07006550/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006551 * FDISC Response
6552 */
6553void
6554bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
6555{
6556 struct bfa_fcs_vport_s *vport = uarg;
6557
6558 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6559 bfa_trc(__vport_fcs(vport), status);
6560
6561 switch (status) {
6562 case BFA_STATUS_OK:
6563 /*
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04006564 * Initialize the V-Port fields
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006565 */
Maggie Zhangf7f738122010-12-09 19:08:43 -08006566 __vport_fcid(vport) = vport->lps->lp_pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006567 vport->vport_stats.fdisc_accepts++;
6568 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6569 break;
6570
6571 case BFA_STATUS_INVALID_MAC:
6572 /* Only for CNA */
6573 vport->vport_stats.fdisc_acc_bad++;
6574 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6575
6576 break;
6577
6578 case BFA_STATUS_EPROTOCOL:
Maggie Zhangf7f738122010-12-09 19:08:43 -08006579 switch (vport->lps->ext_status) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006580 case BFA_EPROTO_BAD_ACCEPT:
6581 vport->vport_stats.fdisc_acc_bad++;
6582 break;
6583
6584 case BFA_EPROTO_UNKNOWN_RSP:
6585 vport->vport_stats.fdisc_unknown_rsp++;
6586 break;
6587
6588 default:
6589 break;
6590 }
6591
6592 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6593 break;
6594
6595 case BFA_STATUS_FABRIC_RJT:
6596 vport->vport_stats.fdisc_rejects++;
6597 bfa_fcs_vport_fdisc_rejected(vport);
6598 break;
6599
6600 default:
6601 vport->vport_stats.fdisc_rsp_err++;
6602 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6603 }
6604}
6605
Jing Huang5fbe25c2010-10-18 17:17:23 -07006606/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006607 * LOGO response
6608 */
6609void
6610bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
6611{
6612 struct bfa_fcs_vport_s *vport = uarg;
6613 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6614}
6615
Jing Huang5fbe25c2010-10-18 17:17:23 -07006616/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006617 * Received clear virtual link
6618 */
6619void
6620bfa_cb_lps_cvl_event(void *bfad, void *uarg)
6621{
6622 struct bfa_fcs_vport_s *vport = uarg;
6623
6624 /* Send an Offline followed by an ONLINE */
6625 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6626 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
6627}