blob: f5e4e61a0fd7ba5bd461e0f79bd2f333317bf74a [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 Gudipatibc0e2c22012-09-21 17:23:59 -070026/*
27 * ALPA to LIXA bitmap mapping
28 *
29 * ALPA 0x00 (Word 0, Bit 30) is invalid for N_Ports. Also Word 0 Bit 31
30 * is for L_bit (login required) and is filled as ALPA 0x00 here.
31 */
32static const u8 loop_alpa_map[] = {
33 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x0F, 0x10, /* Word 0 Bits 31..24 */
34 0x17, 0x18, 0x1B, 0x1D, 0x1E, 0x1F, 0x23, 0x25, /* Word 0 Bits 23..16 */
35 0x26, 0x27, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, /* Word 0 Bits 15..08 */
36 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x39, 0x3A, /* Word 0 Bits 07..00 */
37
38 0x3C, 0x43, 0x45, 0x46, 0x47, 0x49, 0x4A, 0x4B, /* Word 1 Bits 31..24 */
39 0x4C, 0x4D, 0x4E, 0x51, 0x52, 0x53, 0x54, 0x55, /* Word 1 Bits 23..16 */
40 0x56, 0x59, 0x5A, 0x5C, 0x63, 0x65, 0x66, 0x67, /* Word 1 Bits 15..08 */
41 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x71, 0x72, /* Word 1 Bits 07..00 */
42
43 0x73, 0x74, 0x75, 0x76, 0x79, 0x7A, 0x7C, 0x80, /* Word 2 Bits 31..24 */
44 0x81, 0x82, 0x84, 0x88, 0x8F, 0x90, 0x97, 0x98, /* Word 2 Bits 23..16 */
45 0x9B, 0x9D, 0x9E, 0x9F, 0xA3, 0xA5, 0xA6, 0xA7, /* Word 2 Bits 15..08 */
46 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xB1, 0xB2, /* Word 2 Bits 07..00 */
47
48 0xB3, 0xB4, 0xB5, 0xB6, 0xB9, 0xBA, 0xBC, 0xC3, /* Word 3 Bits 31..24 */
49 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, /* Word 3 Bits 23..16 */
50 0xCE, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD9, /* Word 3 Bits 15..08 */
51 0xDA, 0xDC, 0xE0, 0xE1, 0xE2, 0xE4, 0xE8, 0xEF, /* Word 3 Bits 07..00 */
52};
53
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070054static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port,
55 struct fchs_s *rx_fchs, u8 reason_code,
56 u8 reason_code_expl);
57static void bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
58 struct fchs_s *rx_fchs, struct fc_logi_s *plogi);
59static void bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port);
60static void bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port);
61static void bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port);
62static void bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port);
63static void bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port);
64static void bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port);
65static void bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -070066 struct fchs_s *rx_fchs,
67 struct fc_echo_s *echo, u16 len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070068static void bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -070069 struct fchs_s *rx_fchs,
70 struct fc_rnid_cmd_s *rnid, u16 len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070071static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -070072 struct fc_rnid_general_topology_data_s *gen_topo_data);
73
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070074static void bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port);
75static void bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port);
76static void bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port);
77
78static void bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port);
79static void bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port);
80static void bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port);
81
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -070082static void bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port);
83static void bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port);
84static void bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port);
85
Jing Huang7725ccf2009-09-23 17:46:15 -070086static struct {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070087 void (*init) (struct bfa_fcs_lport_s *port);
88 void (*online) (struct bfa_fcs_lport_s *port);
89 void (*offline) (struct bfa_fcs_lport_s *port);
Jing Huang7725ccf2009-09-23 17:46:15 -070090} __port_action[] = {
91 {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070092 bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
93 bfa_fcs_lport_unknown_offline}, {
94 bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
95 bfa_fcs_lport_fab_offline}, {
96 bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -070097 bfa_fcs_lport_n2n_offline}, {
98 bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
99 bfa_fcs_lport_loop_offline},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700100 };
Jing Huang7725ccf2009-09-23 17:46:15 -0700101
Jing Huang5fbe25c2010-10-18 17:17:23 -0700102/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700103 * fcs_port_sm FCS logical port state machine
104 */
105
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700106enum bfa_fcs_lport_event {
Jing Huang7725ccf2009-09-23 17:46:15 -0700107 BFA_FCS_PORT_SM_CREATE = 1,
108 BFA_FCS_PORT_SM_ONLINE = 2,
109 BFA_FCS_PORT_SM_OFFLINE = 3,
110 BFA_FCS_PORT_SM_DELETE = 4,
111 BFA_FCS_PORT_SM_DELRPORT = 5,
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700112 BFA_FCS_PORT_SM_STOP = 6,
Jing Huang7725ccf2009-09-23 17:46:15 -0700113};
114
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700115static void bfa_fcs_lport_sm_uninit(struct bfa_fcs_lport_s *port,
116 enum bfa_fcs_lport_event event);
117static void bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
118 enum bfa_fcs_lport_event event);
119static void bfa_fcs_lport_sm_online(struct bfa_fcs_lport_s *port,
120 enum bfa_fcs_lport_event event);
121static void bfa_fcs_lport_sm_offline(struct bfa_fcs_lport_s *port,
122 enum bfa_fcs_lport_event event);
123static void bfa_fcs_lport_sm_deleting(struct bfa_fcs_lport_s *port,
124 enum bfa_fcs_lport_event event);
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700125static void bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
126 enum bfa_fcs_lport_event event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700127
128static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700129bfa_fcs_lport_sm_uninit(
130 struct bfa_fcs_lport_s *port,
131 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700132{
133 bfa_trc(port->fcs, port->port_cfg.pwwn);
134 bfa_trc(port->fcs, event);
135
136 switch (event) {
137 case BFA_FCS_PORT_SM_CREATE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700138 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
Jing Huang7725ccf2009-09-23 17:46:15 -0700139 break;
140
141 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_init(struct bfa_fcs_lport_s *port,
148 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700149{
150 bfa_trc(port->fcs, port->port_cfg.pwwn);
151 bfa_trc(port->fcs, event);
152
153 switch (event) {
154 case BFA_FCS_PORT_SM_ONLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700155 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
156 bfa_fcs_lport_online_actions(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700157 break;
158
159 case BFA_FCS_PORT_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700160 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
161 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700162 break;
163
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700164 case BFA_FCS_PORT_SM_STOP:
165 /* If vport - send completion call back */
166 if (port->vport)
167 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700168 else
169 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700170 break;
171
Jing Huang3e98cc02010-07-08 19:52:46 -0700172 case BFA_FCS_PORT_SM_OFFLINE:
173 break;
174
Jing Huang7725ccf2009-09-23 17:46:15 -0700175 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800176 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700177 }
178}
179
180static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700181bfa_fcs_lport_sm_online(
182 struct bfa_fcs_lport_s *port,
183 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700184{
185 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700186 struct list_head *qe, *qen;
Jing Huang7725ccf2009-09-23 17:46:15 -0700187
188 bfa_trc(port->fcs, port->port_cfg.pwwn);
189 bfa_trc(port->fcs, event);
190
191 switch (event) {
192 case BFA_FCS_PORT_SM_OFFLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700193 bfa_sm_set_state(port, bfa_fcs_lport_sm_offline);
194 bfa_fcs_lport_offline_actions(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700195 break;
196
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700197 case BFA_FCS_PORT_SM_STOP:
198 __port_action[port->fabric->fab_type].offline(port);
199
200 if (port->num_rports == 0) {
201 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
202 /* If vport - send completion call back */
203 if (port->vport)
204 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700205 else
206 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700207 } else {
208 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
209 list_for_each_safe(qe, qen, &port->rport_q) {
210 rport = (struct bfa_fcs_rport_s *) qe;
211 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
212 }
213 }
214 break;
215
Jing Huang7725ccf2009-09-23 17:46:15 -0700216 case BFA_FCS_PORT_SM_DELETE:
217
218 __port_action[port->fabric->fab_type].offline(port);
219
220 if (port->num_rports == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700221 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
222 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700223 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700224 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
Jing Huang7725ccf2009-09-23 17:46:15 -0700225 list_for_each_safe(qe, qen, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700226 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800227 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700228 }
229 }
230 break;
231
232 case BFA_FCS_PORT_SM_DELRPORT:
233 break;
234
235 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800236 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700237 }
238}
239
240static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700241bfa_fcs_lport_sm_offline(
242 struct bfa_fcs_lport_s *port,
243 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700244{
245 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700246 struct list_head *qe, *qen;
Jing Huang7725ccf2009-09-23 17:46:15 -0700247
248 bfa_trc(port->fcs, port->port_cfg.pwwn);
249 bfa_trc(port->fcs, event);
250
251 switch (event) {
252 case BFA_FCS_PORT_SM_ONLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700253 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
254 bfa_fcs_lport_online_actions(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700255 break;
256
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700257 case BFA_FCS_PORT_SM_STOP:
258 if (port->num_rports == 0) {
259 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
260 /* If vport - send completion call back */
261 if (port->vport)
262 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700263 else
264 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700265 } else {
266 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
267 list_for_each_safe(qe, qen, &port->rport_q) {
268 rport = (struct bfa_fcs_rport_s *) qe;
269 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
270 }
271 }
272 break;
273
Jing Huang7725ccf2009-09-23 17:46:15 -0700274 case BFA_FCS_PORT_SM_DELETE:
275 if (port->num_rports == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700276 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
277 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700278 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700279 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
Jing Huang7725ccf2009-09-23 17:46:15 -0700280 list_for_each_safe(qe, qen, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700281 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800282 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700283 }
284 }
285 break;
286
287 case BFA_FCS_PORT_SM_DELRPORT:
288 case BFA_FCS_PORT_SM_OFFLINE:
289 break;
290
291 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800292 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700293 }
294}
295
296static void
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700297bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
298 enum bfa_fcs_lport_event event)
299{
300 bfa_trc(port->fcs, port->port_cfg.pwwn);
301 bfa_trc(port->fcs, event);
302
303 switch (event) {
304 case BFA_FCS_PORT_SM_DELRPORT:
305 if (port->num_rports == 0) {
306 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
307 /* If vport - send completion call back */
308 if (port->vport)
309 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700310 else
311 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700312 }
313 break;
314
315 default:
316 bfa_sm_fault(port->fcs, event);
317 }
318}
319
320static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700321bfa_fcs_lport_sm_deleting(
322 struct bfa_fcs_lport_s *port,
323 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700324{
325 bfa_trc(port->fcs, port->port_cfg.pwwn);
326 bfa_trc(port->fcs, event);
327
328 switch (event) {
329 case BFA_FCS_PORT_SM_DELRPORT:
330 if (port->num_rports == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700331 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
332 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700333 }
334 break;
335
336 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800337 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700338 }
339}
340
Jing Huang5fbe25c2010-10-18 17:17:23 -0700341/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700342 * fcs_port_pvt
343 */
344
Jing Huang7725ccf2009-09-23 17:46:15 -0700345/*
Krishna Gudipati7826f302011-07-20 16:59:13 -0700346 * Send AEN notification
347 */
348static void
349bfa_fcs_lport_aen_post(struct bfa_fcs_lport_s *port,
350 enum bfa_lport_aen_event event)
351{
352 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
353 struct bfa_aen_entry_s *aen_entry;
354
355 bfad_get_aen_entry(bfad, aen_entry);
356 if (!aen_entry)
357 return;
358
359 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
360 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
361 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
362 bfa_fcs_get_base_port(port->fcs));
363 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
364
365 /* Send the AEN notification */
366 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
367 BFA_AEN_CAT_LPORT, event);
368}
369
370/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700371 * Send a LS reject
372 */
373static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700374bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
Jing Huang7725ccf2009-09-23 17:46:15 -0700375 u8 reason_code, u8 reason_code_expl)
376{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700377 struct fchs_s fchs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700378 struct bfa_fcxp_s *fcxp;
379 struct bfa_rport_s *bfa_rport = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700380 int len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700381
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700382 bfa_trc(port->fcs, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700383 bfa_trc(port->fcs, rx_fchs->s_id);
384
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700385 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700386 if (!fcxp)
387 return;
388
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700389 len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
390 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
391 rx_fchs->ox_id, reason_code, reason_code_expl);
Jing Huang7725ccf2009-09-23 17:46:15 -0700392
393 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700394 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
395 FC_MAX_PDUSZ, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700396}
397
Jing Huang5fbe25c2010-10-18 17:17:23 -0700398/*
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700399 * Send a FCCT Reject
400 */
401static void
402bfa_fcs_lport_send_fcgs_rjt(struct bfa_fcs_lport_s *port,
403 struct fchs_s *rx_fchs, u8 reason_code, u8 reason_code_expl)
404{
405 struct fchs_s fchs;
406 struct bfa_fcxp_s *fcxp;
407 struct bfa_rport_s *bfa_rport = NULL;
408 int len;
409 struct ct_hdr_s *rx_cthdr = (struct ct_hdr_s *)(rx_fchs + 1);
410 struct ct_hdr_s *ct_hdr;
411
412 bfa_trc(port->fcs, rx_fchs->d_id);
413 bfa_trc(port->fcs, rx_fchs->s_id);
414
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700415 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700416 if (!fcxp)
417 return;
418
419 ct_hdr = bfa_fcxp_get_reqbuf(fcxp);
420 ct_hdr->gs_type = rx_cthdr->gs_type;
421 ct_hdr->gs_sub_type = rx_cthdr->gs_sub_type;
422
423 len = fc_gs_rjt_build(&fchs, ct_hdr, rx_fchs->s_id,
424 bfa_fcs_lport_get_fcid(port),
425 rx_fchs->ox_id, reason_code, reason_code_expl);
426
427 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
428 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
429 FC_MAX_PDUSZ, 0);
430}
431
432/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700433 * Process incoming plogi from a remote port.
434 */
435static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700436bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
437 struct fchs_s *rx_fchs, struct fc_logi_s *plogi)
Jing Huang7725ccf2009-09-23 17:46:15 -0700438{
439 struct bfa_fcs_rport_s *rport;
440
441 bfa_trc(port->fcs, rx_fchs->d_id);
442 bfa_trc(port->fcs, rx_fchs->s_id);
443
444 /*
445 * If min cfg mode is enabled, drop any incoming PLOGIs
446 */
447 if (__fcs_min_cfg(port->fcs)) {
448 bfa_trc(port->fcs, rx_fchs->s_id);
449 return;
450 }
451
452 if (fc_plogi_parse(rx_fchs) != FC_PARSE_OK) {
453 bfa_trc(port->fcs, rx_fchs->s_id);
454 /*
455 * send a LS reject
456 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700457 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
458 FC_LS_RJT_RSN_PROTOCOL_ERROR,
459 FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS);
Jing Huang7725ccf2009-09-23 17:46:15 -0700460 return;
461 }
462
Jing Huang5fbe25c2010-10-18 17:17:23 -0700463 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700464 * Direct Attach P2P mode : verify address assigned by the r-port.
Jing Huang7725ccf2009-09-23 17:46:15 -0700465 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700466 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
467 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
468 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700469 if (BFA_FCS_PID_IS_WKA(rx_fchs->d_id)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700470 /* Address assigned to us cannot be a WKA */
471 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
Jing Huang7725ccf2009-09-23 17:46:15 -0700472 FC_LS_RJT_RSN_PROTOCOL_ERROR,
473 FC_LS_RJT_EXP_INVALID_NPORT_ID);
474 return;
475 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700476 port->pid = rx_fchs->d_id;
Krishna Gudipatib7044952010-12-13 16:17:42 -0800477 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700478 }
479
Jing Huang5fbe25c2010-10-18 17:17:23 -0700480 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700481 * First, check if we know the device by pwwn.
482 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700483 rport = bfa_fcs_lport_get_rport_by_pwwn(port, plogi->port_name);
Jing Huang7725ccf2009-09-23 17:46:15 -0700484 if (rport) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700485 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700486 * Direct Attach P2P mode : handle address assigned by r-port.
Jing Huang7725ccf2009-09-23 17:46:15 -0700487 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700488 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
489 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
490 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
491 port->pid = rx_fchs->d_id;
Krishna Gudipatib7044952010-12-13 16:17:42 -0800492 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700493 rport->pid = rx_fchs->s_id;
494 }
495 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
496 return;
497 }
498
Jing Huang5fbe25c2010-10-18 17:17:23 -0700499 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700500 * Next, lookup rport by PID.
501 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700502 rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700503 if (!rport) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700504 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700505 * Inbound PLOGI from a new device.
506 */
507 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
508 return;
509 }
510
Jing Huang5fbe25c2010-10-18 17:17:23 -0700511 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700512 * Rport is known only by PID.
513 */
514 if (rport->pwwn) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700515 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700516 * This is a different device with the same pid. Old device
517 * disappeared. Send implicit LOGO to old device.
518 */
Jing Huangd4b671c2010-12-26 21:46:35 -0800519 WARN_ON(rport->pwwn == plogi->port_name);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800520 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700521
Jing Huang5fbe25c2010-10-18 17:17:23 -0700522 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700523 * Inbound PLOGI from a new device (with old PID).
524 */
525 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
526 return;
527 }
528
Jing Huang5fbe25c2010-10-18 17:17:23 -0700529 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700530 * PLOGI crossing each other.
531 */
Jing Huangd4b671c2010-12-26 21:46:35 -0800532 WARN_ON(rport->pwwn != WWN_NULL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700533 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
534}
535
536/*
537 * Process incoming ECHO.
538 * Since it does not require a login, it is processed here.
539 */
540static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700541bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
542 struct fc_echo_s *echo, u16 rx_len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700543{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700544 struct fchs_s fchs;
545 struct bfa_fcxp_s *fcxp;
546 struct bfa_rport_s *bfa_rport = NULL;
547 int len, pyld_len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700548
549 bfa_trc(port->fcs, rx_fchs->s_id);
550 bfa_trc(port->fcs, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700551
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700552 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700553 if (!fcxp)
554 return;
555
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700556 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
557 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
558 rx_fchs->ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700559
560 /*
561 * Copy the payload (if any) from the echo frame
562 */
563 pyld_len = rx_len - sizeof(struct fchs_s);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700564 bfa_trc(port->fcs, rx_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700565 bfa_trc(port->fcs, pyld_len);
566
567 if (pyld_len > len)
568 memcpy(((u8 *) bfa_fcxp_get_reqbuf(fcxp)) +
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700569 sizeof(struct fc_echo_s), (echo + 1),
570 (pyld_len - sizeof(struct fc_echo_s)));
Jing Huang7725ccf2009-09-23 17:46:15 -0700571
572 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700573 BFA_FALSE, FC_CLASS_3, pyld_len, &fchs, NULL, NULL,
574 FC_MAX_PDUSZ, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700575}
576
577/*
578 * Process incoming RNID.
579 * Since it does not require a login, it is processed here.
580 */
581static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700582bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
583 struct fc_rnid_cmd_s *rnid, u16 rx_len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700584{
585 struct fc_rnid_common_id_data_s common_id_data;
586 struct fc_rnid_general_topology_data_s gen_topo_data;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700587 struct fchs_s fchs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700588 struct bfa_fcxp_s *fcxp;
589 struct bfa_rport_s *bfa_rport = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700590 u16 len;
591 u32 data_format;
Jing Huang7725ccf2009-09-23 17:46:15 -0700592
593 bfa_trc(port->fcs, rx_fchs->s_id);
594 bfa_trc(port->fcs, rx_fchs->d_id);
595 bfa_trc(port->fcs, rx_len);
596
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700597 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700598 if (!fcxp)
599 return;
600
601 /*
602 * Check Node Indentification Data Format
603 * We only support General Topology Discovery Format.
604 * For any other requested Data Formats, we return Common Node Id Data
605 * only, as per FC-LS.
606 */
607 bfa_trc(port->fcs, rnid->node_id_data_format);
608 if (rnid->node_id_data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
609 data_format = RNID_NODEID_DATA_FORMAT_DISCOVERY;
610 /*
611 * Get General topology data for this port
612 */
613 bfa_fs_port_get_gen_topo_data(port, &gen_topo_data);
614 } else {
615 data_format = RNID_NODEID_DATA_FORMAT_COMMON;
616 }
617
618 /*
619 * Copy the Node Id Info
620 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700621 common_id_data.port_name = bfa_fcs_lport_get_pwwn(port);
622 common_id_data.node_name = bfa_fcs_lport_get_nwwn(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700623
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700624 len = fc_rnid_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
625 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
626 rx_fchs->ox_id, data_format, &common_id_data,
627 &gen_topo_data);
Jing Huang7725ccf2009-09-23 17:46:15 -0700628
629 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700630 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
631 FC_MAX_PDUSZ, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700632}
633
634/*
635 * Fill out General Topolpgy Discovery Data for RNID ELS.
636 */
637static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700638bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -0700639 struct fc_rnid_general_topology_data_s *gen_topo_data)
640{
Jing Huang6a18b162010-10-18 17:08:54 -0700641 memset(gen_topo_data, 0,
Jing Huang7725ccf2009-09-23 17:46:15 -0700642 sizeof(struct fc_rnid_general_topology_data_s));
643
Jing Huangba816ea2010-10-18 17:10:50 -0700644 gen_topo_data->asso_type = cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST);
Jing Huang7725ccf2009-09-23 17:46:15 -0700645 gen_topo_data->phy_port_num = 0; /* @todo */
Jing Huangba816ea2010-10-18 17:10:50 -0700646 gen_topo_data->num_attached_nodes = cpu_to_be32(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700647}
648
649static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700650bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700651{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700652 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
653 char lpwwn_buf[BFA_STRING_32];
654
Jing Huang7725ccf2009-09-23 17:46:15 -0700655 bfa_trc(port->fcs, port->fabric->oper_type);
656
657 __port_action[port->fabric->fab_type].init(port);
658 __port_action[port->fabric->fab_type].online(port);
659
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700660 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
Krishna Gudipatia3f29cc2012-04-09 18:41:18 -0700661 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700662 "Logical port online: WWN = %s Role = %s\n",
663 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700664 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_ONLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700665
666 bfad->bfad_flags |= BFAD_PORT_ONLINE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700667}
668
669static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700670bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700671{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700672 struct list_head *qe, *qen;
Jing Huang7725ccf2009-09-23 17:46:15 -0700673 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700674 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
675 char lpwwn_buf[BFA_STRING_32];
Jing Huang7725ccf2009-09-23 17:46:15 -0700676
677 bfa_trc(port->fcs, port->fabric->oper_type);
678
679 __port_action[port->fabric->fab_type].offline(port);
680
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700681 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
Maggie Zhangf7f738122010-12-09 19:08:43 -0800682 if (bfa_sm_cmp_state(port->fabric,
Krishna Gudipati7826f302011-07-20 16:59:13 -0700683 bfa_fcs_fabric_sm_online) == BFA_TRUE) {
Krishna Gudipatia3f29cc2012-04-09 18:41:18 -0700684 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700685 "Logical port lost fabric connectivity: WWN = %s Role = %s\n",
686 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700687 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DISCONNECT);
688 } else {
Krishna Gudipatia3f29cc2012-04-09 18:41:18 -0700689 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700690 "Logical port taken offline: WWN = %s Role = %s\n",
691 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700692 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_OFFLINE);
693 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700694
695 list_for_each_safe(qe, qen, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700696 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800697 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700698 }
699}
700
701static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700702bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700703{
Jing Huangd4b671c2010-12-26 21:46:35 -0800704 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700705}
706
707static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700708bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700709{
Jing Huangd4b671c2010-12-26 21:46:35 -0800710 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700711}
712
713static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700714bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700715{
Jing Huangd4b671c2010-12-26 21:46:35 -0800716 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700717}
718
719static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700720bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs)
Jing Huang7725ccf2009-09-23 17:46:15 -0700721{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700722 struct fchs_s fchs;
723 struct bfa_fcxp_s *fcxp;
724 int len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700725
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700726 bfa_trc(port->fcs, rx_fchs->d_id);
727 bfa_trc(port->fcs, rx_fchs->s_id);
728
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700729 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700730 if (!fcxp)
731 return;
732
733 len = fc_ba_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
734 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
735 rx_fchs->ox_id, 0);
736
737 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
738 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
739 FC_MAX_PDUSZ, 0);
740}
741static void
742bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port)
743{
744 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
745 char lpwwn_buf[BFA_STRING_32];
746
747 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
Jing Huang88166242010-12-09 17:11:53 -0800748 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700749 "Logical port deleted: WWN = %s Role = %s\n",
750 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700751 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DELETE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700752
753 /* Base port will be deleted by the OS driver */
Krishna Gudipati17c201b2012-04-09 18:40:01 -0700754 if (port->vport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700755 bfa_fcs_vport_delete_comp(port->vport);
Krishna Gudipati17c201b2012-04-09 18:40:01 -0700756 else
Maggie Zhangf7f738122010-12-09 19:08:43 -0800757 bfa_wc_down(&port->fabric->wc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700758}
759
760
Jing Huang5fbe25c2010-10-18 17:17:23 -0700761/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700762 * Unsolicited frame receive handling.
Jing Huang7725ccf2009-09-23 17:46:15 -0700763 */
764void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700765bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
766 struct fchs_s *fchs, u16 len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700767{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700768 u32 pid = fchs->s_id;
Jing Huang7725ccf2009-09-23 17:46:15 -0700769 struct bfa_fcs_rport_s *rport = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700770 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700771
772 bfa_stats(lport, uf_recvs);
Krishna Gudipati15821f02010-12-13 16:23:27 -0800773 bfa_trc(lport->fcs, fchs->type);
Jing Huang7725ccf2009-09-23 17:46:15 -0700774
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700775 if (!bfa_fcs_lport_is_online(lport)) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700776 bfa_stats(lport, uf_recv_drops);
777 return;
778 }
779
Jing Huang5fbe25c2010-10-18 17:17:23 -0700780 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700781 * First, handle ELSs that donot require a login.
782 */
783 /*
784 * Handle PLOGI first
785 */
786 if ((fchs->type == FC_TYPE_ELS) &&
787 (els_cmd->els_code == FC_ELS_PLOGI)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700788 bfa_fcs_lport_plogi(lport, fchs, (struct fc_logi_s *) els_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -0700789 return;
790 }
791
792 /*
793 * Handle ECHO separately.
794 */
795 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_ECHO)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700796 bfa_fcs_lport_echo(lport, fchs,
797 (struct fc_echo_s *)els_cmd, len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700798 return;
799 }
800
801 /*
802 * Handle RNID separately.
803 */
804 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_RNID)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700805 bfa_fcs_lport_rnid(lport, fchs,
Jing Huang7725ccf2009-09-23 17:46:15 -0700806 (struct fc_rnid_cmd_s *) els_cmd, len);
807 return;
808 }
809
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700810 if (fchs->type == FC_TYPE_BLS) {
811 if ((fchs->routing == FC_RTG_BASIC_LINK) &&
812 (fchs->cat_info == FC_CAT_ABTS))
813 bfa_fcs_lport_abts_acc(lport, fchs);
814 return;
815 }
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700816
817 if (fchs->type == FC_TYPE_SERVICES) {
818 /*
819 * Unhandled FC-GS frames. Send a FC-CT Reject
820 */
821 bfa_fcs_lport_send_fcgs_rjt(lport, fchs, CT_RSN_NOT_SUPP,
822 CT_NS_EXP_NOADDITIONAL);
823 return;
824 }
825
Jing Huang5fbe25c2010-10-18 17:17:23 -0700826 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700827 * look for a matching remote port ID
828 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700829 rport = bfa_fcs_lport_get_rport_by_pid(lport, pid);
Jing Huang7725ccf2009-09-23 17:46:15 -0700830 if (rport) {
831 bfa_trc(rport->fcs, fchs->s_id);
832 bfa_trc(rport->fcs, fchs->d_id);
833 bfa_trc(rport->fcs, fchs->type);
834
835 bfa_fcs_rport_uf_recv(rport, fchs, len);
836 return;
837 }
838
Jing Huang5fbe25c2010-10-18 17:17:23 -0700839 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700840 * Only handles ELS frames for now.
841 */
842 if (fchs->type != FC_TYPE_ELS) {
Krishna Gudipati15821f02010-12-13 16:23:27 -0800843 bfa_trc(lport->fcs, fchs->s_id);
844 bfa_trc(lport->fcs, fchs->d_id);
845 /* ignore type FC_TYPE_FC_FSS */
846 if (fchs->type != FC_TYPE_FC_FSS)
847 bfa_sm_fault(lport->fcs, fchs->type);
Jing Huang7725ccf2009-09-23 17:46:15 -0700848 return;
849 }
850
851 bfa_trc(lport->fcs, els_cmd->els_code);
852 if (els_cmd->els_code == FC_ELS_RSCN) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700853 bfa_fcs_lport_scn_process_rscn(lport, fchs, len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700854 return;
855 }
856
857 if (els_cmd->els_code == FC_ELS_LOGO) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700858 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700859 * @todo Handle LOGO frames received.
860 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700861 return;
862 }
863
864 if (els_cmd->els_code == FC_ELS_PRLI) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700865 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700866 * @todo Handle PRLI frames received.
867 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700868 return;
869 }
870
Jing Huang5fbe25c2010-10-18 17:17:23 -0700871 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700872 * Unhandled ELS frames. Send a LS_RJT.
873 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700874 bfa_fcs_lport_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP,
Jing Huang7725ccf2009-09-23 17:46:15 -0700875 FC_LS_RJT_EXP_NO_ADDL_INFO);
876
877}
878
Jing Huang5fbe25c2010-10-18 17:17:23 -0700879/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700880 * PID based Lookup for a R-Port in the Port R-Port Queue
881 */
882struct bfa_fcs_rport_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700883bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s *port, u32 pid)
Jing Huang7725ccf2009-09-23 17:46:15 -0700884{
885 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700886 struct list_head *qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700887
888 list_for_each(qe, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700889 rport = (struct bfa_fcs_rport_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700890 if (rport->pid == pid)
891 return rport;
892 }
893
894 bfa_trc(port->fcs, pid);
895 return NULL;
896}
897
Jing Huang5fbe25c2010-10-18 17:17:23 -0700898/*
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -0700899 * OLD_PID based Lookup for a R-Port in the Port R-Port Queue
900 */
901struct bfa_fcs_rport_s *
902bfa_fcs_lport_get_rport_by_old_pid(struct bfa_fcs_lport_s *port, u32 pid)
903{
904 struct bfa_fcs_rport_s *rport;
905 struct list_head *qe;
906
907 list_for_each(qe, &port->rport_q) {
908 rport = (struct bfa_fcs_rport_s *) qe;
909 if (rport->old_pid == pid)
910 return rport;
911 }
912
913 bfa_trc(port->fcs, pid);
914 return NULL;
915}
916
917/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700918 * PWWN based Lookup for a R-Port in the Port R-Port Queue
919 */
920struct bfa_fcs_rport_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700921bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s *port, wwn_t pwwn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700922{
923 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700924 struct list_head *qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700925
926 list_for_each(qe, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700927 rport = (struct bfa_fcs_rport_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700928 if (wwn_is_equal(rport->pwwn, pwwn))
929 return rport;
930 }
931
932 bfa_trc(port->fcs, pwwn);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700933 return NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700934}
935
Jing Huang5fbe25c2010-10-18 17:17:23 -0700936/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700937 * NWWN based Lookup for a R-Port in the Port R-Port Queue
938 */
939struct bfa_fcs_rport_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700940bfa_fcs_lport_get_rport_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t nwwn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700941{
942 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700943 struct list_head *qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700944
945 list_for_each(qe, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700946 rport = (struct bfa_fcs_rport_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700947 if (wwn_is_equal(rport->nwwn, nwwn))
948 return rport;
949 }
950
951 bfa_trc(port->fcs, nwwn);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700952 return NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700953}
954
Jing Huang5fbe25c2010-10-18 17:17:23 -0700955/*
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -0700956 * PWWN & PID based Lookup for a R-Port in the Port R-Port Queue
957 */
958struct bfa_fcs_rport_s *
959bfa_fcs_lport_get_rport_by_qualifier(struct bfa_fcs_lport_s *port,
960 wwn_t pwwn, u32 pid)
961{
962 struct bfa_fcs_rport_s *rport;
963 struct list_head *qe;
964
965 list_for_each(qe, &port->rport_q) {
966 rport = (struct bfa_fcs_rport_s *) qe;
967 if (wwn_is_equal(rport->pwwn, pwwn) && rport->pid == pid)
968 return rport;
969 }
970
971 bfa_trc(port->fcs, pwwn);
972 return NULL;
973}
974
975/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700976 * Called by rport module when new rports are discovered.
977 */
978void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700979bfa_fcs_lport_add_rport(
980 struct bfa_fcs_lport_s *port,
981 struct bfa_fcs_rport_s *rport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700982{
983 list_add_tail(&rport->qe, &port->rport_q);
984 port->num_rports++;
985}
986
Jing Huang5fbe25c2010-10-18 17:17:23 -0700987/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700988 * Called by rport module to when rports are deleted.
989 */
990void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700991bfa_fcs_lport_del_rport(
992 struct bfa_fcs_lport_s *port,
993 struct bfa_fcs_rport_s *rport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700994{
Jing Huangd4b671c2010-12-26 21:46:35 -0800995 WARN_ON(!bfa_q_is_on_q(&port->rport_q, rport));
Jing Huang7725ccf2009-09-23 17:46:15 -0700996 list_del(&rport->qe);
997 port->num_rports--;
998
999 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT);
1000}
1001
Jing Huang5fbe25c2010-10-18 17:17:23 -07001002/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001003 * Called by fabric for base port when fabric login is complete.
1004 * Called by vport for virtual ports when FDISC is complete.
1005 */
1006void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001007bfa_fcs_lport_online(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -07001008{
1009 bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE);
1010}
1011
Jing Huang5fbe25c2010-10-18 17:17:23 -07001012/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001013 * Called by fabric for base port when fabric goes offline.
1014 * Called by vport for virtual ports when virtual port becomes offline.
1015 */
1016void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001017bfa_fcs_lport_offline(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -07001018{
1019 bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE);
1020}
1021
Jing Huang5fbe25c2010-10-18 17:17:23 -07001022/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001023 * Called by fabric for base port and by vport for virtual ports
1024 * when target mode driver is unloaded.
1025 */
1026void
1027bfa_fcs_lport_stop(struct bfa_fcs_lport_s *port)
1028{
1029 bfa_sm_send_event(port, BFA_FCS_PORT_SM_STOP);
1030}
1031
1032/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001033 * Called by fabric to delete base lport and associated resources.
1034 *
1035 * Called by vport to delete lport and associated resources. Should call
1036 * bfa_fcs_vport_delete_comp() for vports on completion.
1037 */
1038void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001039bfa_fcs_lport_delete(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -07001040{
1041 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE);
1042}
1043
Jing Huang5fbe25c2010-10-18 17:17:23 -07001044/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001045 * Return TRUE if port is online, else return FALSE
1046 */
1047bfa_boolean_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001048bfa_fcs_lport_is_online(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -07001049{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001050 return bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online);
Jing Huang7725ccf2009-09-23 17:46:15 -07001051}
1052
Jing Huang5fbe25c2010-10-18 17:17:23 -07001053/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001054 * Attach time initialization of logical ports.
Jing Huang7725ccf2009-09-23 17:46:15 -07001055 */
1056void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001057bfa_fcs_lport_attach(struct bfa_fcs_lport_s *lport, struct bfa_fcs_s *fcs,
1058 u16 vf_id, struct bfa_fcs_vport_s *vport)
Jing Huang7725ccf2009-09-23 17:46:15 -07001059{
1060 lport->fcs = fcs;
1061 lport->fabric = bfa_fcs_vf_lookup(fcs, vf_id);
Jing Huang7725ccf2009-09-23 17:46:15 -07001062 lport->vport = vport;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001063 lport->lp_tag = (vport) ? vport->lps->bfa_tag :
1064 lport->fabric->lps->bfa_tag;
Jing Huang7725ccf2009-09-23 17:46:15 -07001065
1066 INIT_LIST_HEAD(&lport->rport_q);
1067 lport->num_rports = 0;
Krishna Gudipatie6714322010-03-03 17:44:02 -08001068}
Jing Huang7725ccf2009-09-23 17:46:15 -07001069
Jing Huang5fbe25c2010-10-18 17:17:23 -07001070/*
Krishna Gudipatie6714322010-03-03 17:44:02 -08001071 * Logical port initialization of base or virtual port.
1072 * Called by fabric for base port or by vport for virtual ports.
1073 */
1074
1075void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001076bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
1077 struct bfa_lport_cfg_s *port_cfg)
Krishna Gudipatie6714322010-03-03 17:44:02 -08001078{
1079 struct bfa_fcs_vport_s *vport = lport->vport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001080 struct bfad_s *bfad = (struct bfad_s *)lport->fcs->bfad;
1081 char lpwwn_buf[BFA_STRING_32];
Krishna Gudipatie6714322010-03-03 17:44:02 -08001082
Jing Huang6a18b162010-10-18 17:08:54 -07001083 lport->port_cfg = *port_cfg;
Krishna Gudipatie6714322010-03-03 17:44:02 -08001084
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001085 lport->bfad_port = bfa_fcb_lport_new(lport->fcs->bfad, lport,
1086 lport->port_cfg.roles,
1087 lport->fabric->vf_drv,
1088 vport ? vport->vport_drv : NULL);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001089
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001090 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(lport));
Jing Huang88166242010-12-09 17:11:53 -08001091 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001092 "New logical port created: WWN = %s Role = %s\n",
1093 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -07001094 bfa_fcs_lport_aen_post(lport, BFA_LPORT_AEN_NEW);
Jing Huang7725ccf2009-09-23 17:46:15 -07001095
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001096 bfa_sm_set_state(lport, bfa_fcs_lport_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -07001097 bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE);
1098}
1099
Vijaya Mohan Guvva22a08532013-11-21 01:37:49 -08001100void
1101bfa_fcs_lport_set_symname(struct bfa_fcs_lport_s *port,
1102 char *symname)
1103{
1104 strcpy(port->port_cfg.sym_name.symname, symname);
1105
1106 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
1107 bfa_fcs_lport_ns_util_send_rspn_id(
1108 BFA_FCS_GET_NS_FROM_PORT(port), NULL);
1109}
1110
Jing Huang5fbe25c2010-10-18 17:17:23 -07001111/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001112 * fcs_lport_api
1113 */
1114
1115void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001116bfa_fcs_lport_get_attr(
1117 struct bfa_fcs_lport_s *port,
1118 struct bfa_lport_attr_s *port_attr)
Jing Huang7725ccf2009-09-23 17:46:15 -07001119{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001120 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
Jing Huang7725ccf2009-09-23 17:46:15 -07001121 port_attr->pid = port->pid;
1122 else
1123 port_attr->pid = 0;
1124
1125 port_attr->port_cfg = port->port_cfg;
1126
1127 if (port->fabric) {
Maggie Zhangf7f738122010-12-09 19:08:43 -08001128 port_attr->port_type = port->fabric->oper_type;
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001129 port_attr->loopback = bfa_sm_cmp_state(port->fabric,
1130 bfa_fcs_fabric_sm_loopback);
Krishna Gudipatif926a052010-03-05 19:36:00 -08001131 port_attr->authfail =
Maggie Zhangf7f738122010-12-09 19:08:43 -08001132 bfa_sm_cmp_state(port->fabric,
1133 bfa_fcs_fabric_sm_auth_failed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001134 port_attr->fabric_name = bfa_fcs_lport_get_fabric_name(port);
Jing Huang7725ccf2009-09-23 17:46:15 -07001135 memcpy(port_attr->fabric_ip_addr,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001136 bfa_fcs_lport_get_fabric_ipaddr(port),
1137 BFA_FCS_FABRIC_IPADDR_SZ);
Jing Huang7725ccf2009-09-23 17:46:15 -07001138
Krishna Gudipati86e32da2010-03-05 19:35:33 -08001139 if (port->vport != NULL) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001140 port_attr->port_type = BFA_PORT_TYPE_VPORT;
Krishna Gudipati86e32da2010-03-05 19:35:33 -08001141 port_attr->fpma_mac =
Maggie Zhangf7f738122010-12-09 19:08:43 -08001142 port->vport->lps->lp_mac;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001143 } else {
Krishna Gudipati86e32da2010-03-05 19:35:33 -08001144 port_attr->fpma_mac =
Maggie Zhangf7f738122010-12-09 19:08:43 -08001145 port->fabric->lps->lp_mac;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001146 }
Jing Huang7725ccf2009-09-23 17:46:15 -07001147 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001148 port_attr->port_type = BFA_PORT_TYPE_UNKNOWN;
1149 port_attr->state = BFA_LPORT_UNINIT;
Jing Huang7725ccf2009-09-23 17:46:15 -07001150 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001151}
1152
Jing Huang5fbe25c2010-10-18 17:17:23 -07001153/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001154 * bfa_fcs_lport_fab port fab functions
1155 */
1156
Jing Huang5fbe25c2010-10-18 17:17:23 -07001157/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001158 * Called by port to initialize fabric services of the base port.
1159 */
1160static void
1161bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port)
1162{
1163 bfa_fcs_lport_ns_init(port);
1164 bfa_fcs_lport_scn_init(port);
1165 bfa_fcs_lport_ms_init(port);
1166}
1167
Jing Huang5fbe25c2010-10-18 17:17:23 -07001168/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001169 * Called by port to notify transition to online state.
1170 */
1171static void
1172bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port)
1173{
1174 bfa_fcs_lport_ns_online(port);
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07001175 bfa_fcs_lport_fab_scn_online(port);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001176}
1177
Jing Huang5fbe25c2010-10-18 17:17:23 -07001178/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001179 * Called by port to notify transition to offline state.
1180 */
1181static void
1182bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port)
1183{
1184 bfa_fcs_lport_ns_offline(port);
1185 bfa_fcs_lport_scn_offline(port);
1186 bfa_fcs_lport_ms_offline(port);
1187}
1188
Jing Huang5fbe25c2010-10-18 17:17:23 -07001189/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001190 * bfa_fcs_lport_n2n functions
1191 */
1192
Jing Huang5fbe25c2010-10-18 17:17:23 -07001193/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001194 * Called by fcs/port to initialize N2N topology.
1195 */
1196static void
1197bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port)
1198{
1199}
1200
Jing Huang5fbe25c2010-10-18 17:17:23 -07001201/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001202 * Called by fcs/port to notify transition to online state.
1203 */
1204static void
1205bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port)
1206{
1207 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1208 struct bfa_lport_cfg_s *pcfg = &port->port_cfg;
1209 struct bfa_fcs_rport_s *rport;
1210
1211 bfa_trc(port->fcs, pcfg->pwwn);
1212
1213 /*
1214 * If our PWWN is > than that of the r-port, we have to initiate PLOGI
1215 * and assign an Address. if not, we need to wait for its PLOGI.
1216 *
1217 * If our PWWN is < than that of the remote port, it will send a PLOGI
1218 * with the PIDs assigned. The rport state machine take care of this
1219 * incoming PLOGI.
1220 */
1221 if (memcmp
1222 ((void *)&pcfg->pwwn, (void *)&n2n_port->rem_port_wwn,
1223 sizeof(wwn_t)) > 0) {
1224 port->pid = N2N_LOCAL_PID;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001225 bfa_lps_set_n2n_pid(port->fabric->lps, N2N_LOCAL_PID);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001226 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001227 * First, check if we know the device by pwwn.
1228 */
1229 rport = bfa_fcs_lport_get_rport_by_pwwn(port,
1230 n2n_port->rem_port_wwn);
1231 if (rport) {
1232 bfa_trc(port->fcs, rport->pid);
1233 bfa_trc(port->fcs, rport->pwwn);
1234 rport->pid = N2N_REMOTE_PID;
Maggie Zhangf7f738122010-12-09 19:08:43 -08001235 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001236 return;
1237 }
1238
1239 /*
1240 * In n2n there can be only one rport. Delete the old one
1241 * whose pid should be zero, because it is offline.
1242 */
1243 if (port->num_rports > 0) {
1244 rport = bfa_fcs_lport_get_rport_by_pid(port, 0);
Jing Huangd4b671c2010-12-26 21:46:35 -08001245 WARN_ON(rport == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001246 if (rport) {
1247 bfa_trc(port->fcs, rport->pwwn);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001248 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001249 }
1250 }
1251 bfa_fcs_rport_create(port, N2N_REMOTE_PID);
1252 }
1253}
1254
Jing Huang5fbe25c2010-10-18 17:17:23 -07001255/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001256 * Called by fcs/port to notify transition to offline state.
1257 */
1258static void
1259bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port)
1260{
1261 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1262
1263 bfa_trc(port->fcs, port->pid);
1264 port->pid = 0;
1265 n2n_port->rem_port_wwn = 0;
1266 n2n_port->reply_oxid = 0;
1267}
1268
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07001269void
1270bfa_fcport_get_loop_attr(struct bfa_fcs_lport_s *port)
1271{
1272 int i = 0, j = 0, bit = 0, alpa_bit = 0;
1273 u8 k = 0;
1274 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(port->fcs->bfa);
1275
1276 port->port_topo.ploop.alpabm_valid = fcport->alpabm_valid;
1277 port->pid = fcport->myalpa;
1278 port->pid = bfa_hton3b(port->pid);
1279
1280 for (i = 0; i < (FC_ALPA_MAX / 8); i++) {
1281 for (j = 0, alpa_bit = 0; j < 8; j++, alpa_bit++) {
1282 bfa_trc(port->fcs->bfa, fcport->alpabm.alpa_bm[i]);
1283 bit = (fcport->alpabm.alpa_bm[i] & (1 << (7 - j)));
1284 if (bit) {
1285 port->port_topo.ploop.alpa_pos_map[k] =
1286 loop_alpa_map[(i * 8) + alpa_bit];
1287 k++;
1288 bfa_trc(port->fcs->bfa, k);
1289 bfa_trc(port->fcs->bfa,
1290 port->port_topo.ploop.alpa_pos_map[k]);
1291 }
1292 }
1293 }
1294 port->port_topo.ploop.num_alpa = k;
1295}
1296
1297/*
1298 * Called by fcs/port to initialize Loop topology.
1299 */
1300static void
1301bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port)
1302{
1303}
1304
1305/*
1306 * Called by fcs/port to notify transition to online state.
1307 */
1308static void
1309bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port)
1310{
1311 u8 num_alpa = 0, alpabm_valid = 0;
1312 struct bfa_fcs_rport_s *rport;
1313 u8 *alpa_map = NULL;
1314 int i = 0;
1315 u32 pid;
1316
1317 bfa_fcport_get_loop_attr(port);
1318
1319 num_alpa = port->port_topo.ploop.num_alpa;
1320 alpabm_valid = port->port_topo.ploop.alpabm_valid;
1321 alpa_map = port->port_topo.ploop.alpa_pos_map;
1322
1323 bfa_trc(port->fcs->bfa, port->pid);
1324 bfa_trc(port->fcs->bfa, num_alpa);
1325 if (alpabm_valid == 1) {
1326 for (i = 0; i < num_alpa; i++) {
1327 bfa_trc(port->fcs->bfa, alpa_map[i]);
1328 if (alpa_map[i] != bfa_hton3b(port->pid)) {
1329 pid = alpa_map[i];
1330 bfa_trc(port->fcs->bfa, pid);
1331 rport = bfa_fcs_lport_get_rport_by_pid(port,
1332 bfa_hton3b(pid));
1333 if (!rport)
1334 rport = bfa_fcs_rport_create(port,
1335 bfa_hton3b(pid));
1336 }
1337 }
1338 } else {
1339 for (i = 0; i < MAX_ALPA_COUNT; i++) {
1340 if (alpa_map[i] != port->pid) {
1341 pid = loop_alpa_map[i];
1342 bfa_trc(port->fcs->bfa, pid);
1343 rport = bfa_fcs_lport_get_rport_by_pid(port,
1344 bfa_hton3b(pid));
1345 if (!rport)
1346 rport = bfa_fcs_rport_create(port,
1347 bfa_hton3b(pid));
1348 }
1349 }
1350 }
1351}
1352
1353/*
1354 * Called by fcs/port to notify transition to offline state.
1355 */
1356static void
1357bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port)
1358{
1359}
1360
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001361#define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
1362
1363/*
1364 * forward declarations
1365 */
1366static void bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg,
1367 struct bfa_fcxp_s *fcxp_alloced);
1368static void bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg,
1369 struct bfa_fcxp_s *fcxp_alloced);
1370static void bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg,
1371 struct bfa_fcxp_s *fcxp_alloced);
1372static void bfa_fcs_lport_fdmi_rhba_response(void *fcsarg,
1373 struct bfa_fcxp_s *fcxp,
1374 void *cbarg,
1375 bfa_status_t req_status,
1376 u32 rsp_len,
1377 u32 resid_len,
1378 struct fchs_s *rsp_fchs);
1379static void bfa_fcs_lport_fdmi_rprt_response(void *fcsarg,
1380 struct bfa_fcxp_s *fcxp,
1381 void *cbarg,
1382 bfa_status_t req_status,
1383 u32 rsp_len,
1384 u32 resid_len,
1385 struct fchs_s *rsp_fchs);
1386static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg,
1387 struct bfa_fcxp_s *fcxp,
1388 void *cbarg,
1389 bfa_status_t req_status,
1390 u32 rsp_len,
1391 u32 resid_len,
1392 struct fchs_s *rsp_fchs);
1393static void bfa_fcs_lport_fdmi_timeout(void *arg);
1394static u16 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1395 u8 *pyld);
1396static u16 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1397 u8 *pyld);
1398static u16 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1399 u8 *pyld);
1400static u16 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *
1401 fdmi, u8 *pyld);
1402static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1403 struct bfa_fcs_fdmi_hba_attr_s *hba_attr);
1404static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1405 struct bfa_fcs_fdmi_port_attr_s *port_attr);
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001406u32 bfa_fcs_fdmi_convert_speed(enum bfa_port_speed pport_speed);
1407
Jing Huang5fbe25c2010-10-18 17:17:23 -07001408/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001409 * fcs_fdmi_sm FCS FDMI state machine
1410 */
1411
Jing Huang5fbe25c2010-10-18 17:17:23 -07001412/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001413 * FDMI State Machine events
1414 */
1415enum port_fdmi_event {
1416 FDMISM_EVENT_PORT_ONLINE = 1,
1417 FDMISM_EVENT_PORT_OFFLINE = 2,
1418 FDMISM_EVENT_RSP_OK = 4,
1419 FDMISM_EVENT_RSP_ERROR = 5,
1420 FDMISM_EVENT_TIMEOUT = 6,
1421 FDMISM_EVENT_RHBA_SENT = 7,
1422 FDMISM_EVENT_RPRT_SENT = 8,
1423 FDMISM_EVENT_RPA_SENT = 9,
1424};
1425
1426static void bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1427 enum port_fdmi_event event);
1428static void bfa_fcs_lport_fdmi_sm_sending_rhba(
1429 struct bfa_fcs_lport_fdmi_s *fdmi,
1430 enum port_fdmi_event event);
1431static void bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1432 enum port_fdmi_event event);
1433static void bfa_fcs_lport_fdmi_sm_rhba_retry(
1434 struct bfa_fcs_lport_fdmi_s *fdmi,
1435 enum port_fdmi_event event);
1436static void bfa_fcs_lport_fdmi_sm_sending_rprt(
1437 struct bfa_fcs_lport_fdmi_s *fdmi,
1438 enum port_fdmi_event event);
1439static void bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1440 enum port_fdmi_event event);
1441static void bfa_fcs_lport_fdmi_sm_rprt_retry(
1442 struct bfa_fcs_lport_fdmi_s *fdmi,
1443 enum port_fdmi_event event);
1444static void bfa_fcs_lport_fdmi_sm_sending_rpa(
1445 struct bfa_fcs_lport_fdmi_s *fdmi,
1446 enum port_fdmi_event event);
1447static void bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1448 enum port_fdmi_event event);
1449static void bfa_fcs_lport_fdmi_sm_rpa_retry(
1450 struct bfa_fcs_lport_fdmi_s *fdmi,
1451 enum port_fdmi_event event);
1452static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1453 enum port_fdmi_event event);
1454static void bfa_fcs_lport_fdmi_sm_disabled(
1455 struct bfa_fcs_lport_fdmi_s *fdmi,
1456 enum port_fdmi_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001457/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001458 * Start in offline state - awaiting MS to send start.
1459 */
1460static void
1461bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1462 enum port_fdmi_event event)
1463{
1464 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1465
1466 bfa_trc(port->fcs, port->port_cfg.pwwn);
1467 bfa_trc(port->fcs, event);
1468
1469 fdmi->retry_cnt = 0;
1470
1471 switch (event) {
1472 case FDMISM_EVENT_PORT_ONLINE:
1473 if (port->vport) {
1474 /*
1475 * For Vports, register a new port.
1476 */
1477 bfa_sm_set_state(fdmi,
1478 bfa_fcs_lport_fdmi_sm_sending_rprt);
1479 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1480 } else {
1481 /*
1482 * For a base port, we should first register the HBA
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001483 * attribute. The HBA attribute also contains the base
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001484 * port registration.
1485 */
1486 bfa_sm_set_state(fdmi,
1487 bfa_fcs_lport_fdmi_sm_sending_rhba);
1488 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1489 }
1490 break;
1491
1492 case FDMISM_EVENT_PORT_OFFLINE:
1493 break;
1494
1495 default:
1496 bfa_sm_fault(port->fcs, event);
1497 }
1498}
1499
1500static void
1501bfa_fcs_lport_fdmi_sm_sending_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1502 enum port_fdmi_event event)
1503{
1504 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1505
1506 bfa_trc(port->fcs, port->port_cfg.pwwn);
1507 bfa_trc(port->fcs, event);
1508
1509 switch (event) {
1510 case FDMISM_EVENT_RHBA_SENT:
1511 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rhba);
1512 break;
1513
1514 case FDMISM_EVENT_PORT_OFFLINE:
1515 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1516 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1517 &fdmi->fcxp_wqe);
1518 break;
1519
1520 default:
1521 bfa_sm_fault(port->fcs, event);
1522 }
1523}
1524
1525static void
1526bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1527 enum port_fdmi_event event)
1528{
1529 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1530
1531 bfa_trc(port->fcs, port->port_cfg.pwwn);
1532 bfa_trc(port->fcs, event);
1533
1534 switch (event) {
1535 case FDMISM_EVENT_RSP_ERROR:
1536 /*
1537 * if max retries have not been reached, start timer for a
1538 * delayed retry
1539 */
1540 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1541 bfa_sm_set_state(fdmi,
1542 bfa_fcs_lport_fdmi_sm_rhba_retry);
1543 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1544 &fdmi->timer,
1545 bfa_fcs_lport_fdmi_timeout, fdmi,
1546 BFA_FCS_RETRY_TIMEOUT);
1547 } else {
1548 /*
1549 * set state to offline
1550 */
1551 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1552 }
1553 break;
1554
1555 case FDMISM_EVENT_RSP_OK:
1556 /*
1557 * Initiate Register Port Attributes
1558 */
1559 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1560 fdmi->retry_cnt = 0;
1561 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1562 break;
1563
1564 case FDMISM_EVENT_PORT_OFFLINE:
1565 bfa_fcxp_discard(fdmi->fcxp);
1566 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1567 break;
1568
1569 default:
1570 bfa_sm_fault(port->fcs, event);
1571 }
1572}
1573
1574static void
1575bfa_fcs_lport_fdmi_sm_rhba_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1576 enum port_fdmi_event event)
1577{
1578 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1579
1580 bfa_trc(port->fcs, port->port_cfg.pwwn);
1581 bfa_trc(port->fcs, event);
1582
1583 switch (event) {
1584 case FDMISM_EVENT_TIMEOUT:
1585 /*
1586 * Retry Timer Expired. Re-send
1587 */
1588 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rhba);
1589 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1590 break;
1591
1592 case FDMISM_EVENT_PORT_OFFLINE:
1593 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1594 bfa_timer_stop(&fdmi->timer);
1595 break;
1596
1597 default:
1598 bfa_sm_fault(port->fcs, event);
1599 }
1600}
1601
1602/*
1603* RPRT : Register Port
1604 */
1605static void
1606bfa_fcs_lport_fdmi_sm_sending_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1607 enum port_fdmi_event event)
1608{
1609 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1610
1611 bfa_trc(port->fcs, port->port_cfg.pwwn);
1612 bfa_trc(port->fcs, event);
1613
1614 switch (event) {
1615 case FDMISM_EVENT_RPRT_SENT:
1616 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rprt);
1617 break;
1618
1619 case FDMISM_EVENT_PORT_OFFLINE:
1620 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1621 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1622 &fdmi->fcxp_wqe);
1623 break;
1624
1625 default:
1626 bfa_sm_fault(port->fcs, event);
1627 }
1628}
1629
1630static void
1631bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1632 enum port_fdmi_event event)
1633{
1634 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1635
1636 bfa_trc(port->fcs, port->port_cfg.pwwn);
1637 bfa_trc(port->fcs, event);
1638
1639 switch (event) {
1640 case FDMISM_EVENT_RSP_ERROR:
1641 /*
1642 * if max retries have not been reached, start timer for a
1643 * delayed retry
1644 */
1645 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1646 bfa_sm_set_state(fdmi,
1647 bfa_fcs_lport_fdmi_sm_rprt_retry);
1648 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1649 &fdmi->timer,
1650 bfa_fcs_lport_fdmi_timeout, fdmi,
1651 BFA_FCS_RETRY_TIMEOUT);
1652
1653 } else {
1654 /*
1655 * set state to offline
1656 */
1657 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1658 fdmi->retry_cnt = 0;
1659 }
1660 break;
1661
1662 case FDMISM_EVENT_RSP_OK:
1663 fdmi->retry_cnt = 0;
1664 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1665 break;
1666
1667 case FDMISM_EVENT_PORT_OFFLINE:
1668 bfa_fcxp_discard(fdmi->fcxp);
1669 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1670 break;
1671
1672 default:
1673 bfa_sm_fault(port->fcs, event);
1674 }
1675}
1676
1677static void
1678bfa_fcs_lport_fdmi_sm_rprt_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1679 enum port_fdmi_event event)
1680{
1681 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1682
1683 bfa_trc(port->fcs, port->port_cfg.pwwn);
1684 bfa_trc(port->fcs, event);
1685
1686 switch (event) {
1687 case FDMISM_EVENT_TIMEOUT:
1688 /*
1689 * Retry Timer Expired. Re-send
1690 */
1691 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rprt);
1692 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1693 break;
1694
1695 case FDMISM_EVENT_PORT_OFFLINE:
1696 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1697 bfa_timer_stop(&fdmi->timer);
1698 break;
1699
1700 default:
1701 bfa_sm_fault(port->fcs, event);
1702 }
1703}
1704
1705/*
1706 * Register Port Attributes
1707 */
1708static void
1709bfa_fcs_lport_fdmi_sm_sending_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1710 enum port_fdmi_event event)
1711{
1712 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1713
1714 bfa_trc(port->fcs, port->port_cfg.pwwn);
1715 bfa_trc(port->fcs, event);
1716
1717 switch (event) {
1718 case FDMISM_EVENT_RPA_SENT:
1719 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa);
1720 break;
1721
1722 case FDMISM_EVENT_PORT_OFFLINE:
1723 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1724 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1725 &fdmi->fcxp_wqe);
1726 break;
1727
1728 default:
1729 bfa_sm_fault(port->fcs, event);
1730 }
1731}
1732
1733static void
1734bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1735 enum port_fdmi_event event)
1736{
1737 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1738
1739 bfa_trc(port->fcs, port->port_cfg.pwwn);
1740 bfa_trc(port->fcs, event);
1741
1742 switch (event) {
1743 case FDMISM_EVENT_RSP_ERROR:
1744 /*
1745 * if max retries have not been reached, start timer for a
1746 * delayed retry
1747 */
1748 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1749 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa_retry);
1750 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1751 &fdmi->timer,
1752 bfa_fcs_lport_fdmi_timeout, fdmi,
1753 BFA_FCS_RETRY_TIMEOUT);
1754 } else {
1755 /*
1756 * set state to offline
1757 */
1758 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1759 fdmi->retry_cnt = 0;
1760 }
1761 break;
1762
1763 case FDMISM_EVENT_RSP_OK:
1764 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1765 fdmi->retry_cnt = 0;
1766 break;
1767
1768 case FDMISM_EVENT_PORT_OFFLINE:
1769 bfa_fcxp_discard(fdmi->fcxp);
1770 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1771 break;
1772
1773 default:
1774 bfa_sm_fault(port->fcs, event);
1775 }
1776}
1777
1778static void
1779bfa_fcs_lport_fdmi_sm_rpa_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1780 enum port_fdmi_event event)
1781{
1782 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1783
1784 bfa_trc(port->fcs, port->port_cfg.pwwn);
1785 bfa_trc(port->fcs, event);
1786
1787 switch (event) {
1788 case FDMISM_EVENT_TIMEOUT:
1789 /*
1790 * Retry Timer Expired. Re-send
1791 */
1792 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1793 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1794 break;
1795
1796 case FDMISM_EVENT_PORT_OFFLINE:
1797 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1798 bfa_timer_stop(&fdmi->timer);
1799 break;
1800
1801 default:
1802 bfa_sm_fault(port->fcs, event);
1803 }
1804}
1805
1806static void
1807bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1808 enum port_fdmi_event event)
1809{
1810 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1811
1812 bfa_trc(port->fcs, port->port_cfg.pwwn);
1813 bfa_trc(port->fcs, event);
1814
1815 switch (event) {
1816 case FDMISM_EVENT_PORT_OFFLINE:
1817 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1818 break;
1819
1820 default:
1821 bfa_sm_fault(port->fcs, event);
1822 }
1823}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001824/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001825 * FDMI is disabled state.
1826 */
1827static void
1828bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s *fdmi,
1829 enum port_fdmi_event event)
1830{
1831 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1832
1833 bfa_trc(port->fcs, port->port_cfg.pwwn);
1834 bfa_trc(port->fcs, event);
1835
1836 /* No op State. It can only be enabled at Driver Init. */
1837}
1838
Jing Huang5fbe25c2010-10-18 17:17:23 -07001839/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001840* RHBA : Register HBA Attributes.
1841 */
1842static void
1843bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1844{
1845 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
1846 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1847 struct fchs_s fchs;
1848 int len, attr_len;
1849 struct bfa_fcxp_s *fcxp;
1850 u8 *pyld;
1851
1852 bfa_trc(port->fcs, port->port_cfg.pwwn);
1853
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001854 fcxp = fcxp_alloced ? fcxp_alloced :
1855 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001856 if (!fcxp) {
1857 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001858 bfa_fcs_lport_fdmi_send_rhba, fdmi, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001859 return;
1860 }
1861 fdmi->fcxp = fcxp;
1862
1863 pyld = bfa_fcxp_get_reqbuf(fcxp);
Jing Huang6a18b162010-10-18 17:08:54 -07001864 memset(pyld, 0, FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001865
1866 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
1867 FDMI_RHBA);
1868
1869 attr_len =
1870 bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi,
1871 (u8 *) ((struct ct_hdr_s *) pyld
1872 + 1));
1873
1874 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1875 FC_CLASS_3, (len + attr_len), &fchs,
1876 bfa_fcs_lport_fdmi_rhba_response, (void *)fdmi,
1877 FC_MAX_PDUSZ, FC_FCCT_TOV);
1878
1879 bfa_sm_send_event(fdmi, FDMISM_EVENT_RHBA_SENT);
1880}
1881
1882static u16
1883bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1884{
1885 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1886 struct bfa_fcs_fdmi_hba_attr_s hba_attr;
1887 struct bfa_fcs_fdmi_hba_attr_s *fcs_hba_attr = &hba_attr;
1888 struct fdmi_rhba_s *rhba = (struct fdmi_rhba_s *) pyld;
1889 struct fdmi_attr_s *attr;
1890 u8 *curr_ptr;
1891 u16 len, count;
Maggie50444a32010-11-29 18:26:32 -08001892 u16 templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001893
1894 /*
1895 * get hba attributes
1896 */
1897 bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr);
1898
1899 rhba->hba_id = bfa_fcs_lport_get_pwwn(port);
Jing Huangba816ea2010-10-18 17:10:50 -07001900 rhba->port_list.num_ports = cpu_to_be32(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001901 rhba->port_list.port_entry = bfa_fcs_lport_get_pwwn(port);
1902
1903 len = sizeof(rhba->hba_id) + sizeof(rhba->port_list);
1904
1905 count = 0;
1906 len += sizeof(rhba->hba_attr_blk.attr_count);
1907
1908 /*
1909 * fill out the invididual entries of the HBA attrib Block
1910 */
1911 curr_ptr = (u8 *) &rhba->hba_attr_blk.hba_attr;
1912
1913 /*
1914 * Node Name
1915 */
1916 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001917 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME);
Maggie50444a32010-11-29 18:26:32 -08001918 templen = sizeof(wwn_t);
1919 memcpy(attr->value, &bfa_fcs_lport_get_nwwn(port), templen);
1920 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1921 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001922 count++;
Maggie50444a32010-11-29 18:26:32 -08001923 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1924 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001925
1926 /*
1927 * Manufacturer
1928 */
1929 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001930 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MANUFACTURER);
Maggie50444a32010-11-29 18:26:32 -08001931 templen = (u16) strlen(fcs_hba_attr->manufacturer);
1932 memcpy(attr->value, fcs_hba_attr->manufacturer, templen);
1933 templen = fc_roundup(templen, sizeof(u32));
1934 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1935 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001936 count++;
Maggie50444a32010-11-29 18:26:32 -08001937 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1938 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001939
1940 /*
1941 * Serial Number
1942 */
1943 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001944 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_SERIALNUM);
Maggie50444a32010-11-29 18:26:32 -08001945 templen = (u16) strlen(fcs_hba_attr->serial_num);
1946 memcpy(attr->value, fcs_hba_attr->serial_num, templen);
1947 templen = fc_roundup(templen, sizeof(u32));
1948 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1949 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001950 count++;
Maggie50444a32010-11-29 18:26:32 -08001951 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1952 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001953
1954 /*
1955 * Model
1956 */
1957 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001958 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL);
Maggie50444a32010-11-29 18:26:32 -08001959 templen = (u16) strlen(fcs_hba_attr->model);
1960 memcpy(attr->value, fcs_hba_attr->model, templen);
1961 templen = fc_roundup(templen, sizeof(u32));
1962 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1963 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001964 count++;
Maggie50444a32010-11-29 18:26:32 -08001965 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1966 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001967
1968 /*
1969 * Model Desc
1970 */
1971 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001972 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC);
Maggie50444a32010-11-29 18:26:32 -08001973 templen = (u16) strlen(fcs_hba_attr->model_desc);
1974 memcpy(attr->value, fcs_hba_attr->model_desc, templen);
1975 templen = fc_roundup(templen, sizeof(u32));
1976 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1977 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001978 count++;
Maggie50444a32010-11-29 18:26:32 -08001979 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1980 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001981
1982 /*
1983 * H/W Version
1984 */
1985 if (fcs_hba_attr->hw_version[0] != '\0') {
1986 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001987 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION);
Maggie50444a32010-11-29 18:26:32 -08001988 templen = (u16) strlen(fcs_hba_attr->hw_version);
1989 memcpy(attr->value, fcs_hba_attr->hw_version, templen);
1990 templen = fc_roundup(templen, sizeof(u32));
1991 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1992 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001993 count++;
Maggie50444a32010-11-29 18:26:32 -08001994 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1995 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001996 }
1997
1998 /*
1999 * Driver Version
2000 */
2001 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002002 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION);
Maggie50444a32010-11-29 18:26:32 -08002003 templen = (u16) strlen(fcs_hba_attr->driver_version);
2004 memcpy(attr->value, fcs_hba_attr->driver_version, templen);
2005 templen = fc_roundup(templen, sizeof(u32));
2006 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07002007 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002008 count++;
Maggie50444a32010-11-29 18:26:32 -08002009 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2010 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002011
2012 /*
2013 * Option Rom Version
2014 */
2015 if (fcs_hba_attr->option_rom_ver[0] != '\0') {
2016 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002017 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION);
Maggie50444a32010-11-29 18:26:32 -08002018 templen = (u16) strlen(fcs_hba_attr->option_rom_ver);
2019 memcpy(attr->value, fcs_hba_attr->option_rom_ver, templen);
2020 templen = fc_roundup(templen, sizeof(u32));
2021 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2022 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002023 count++;
Maggie50444a32010-11-29 18:26:32 -08002024 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2025 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002026 }
2027
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002028 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002029 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION);
Krishna Gudipatib480a322012-09-21 17:25:20 -07002030 templen = (u16) strlen(fcs_hba_attr->fw_version);
2031 memcpy(attr->value, fcs_hba_attr->fw_version, templen);
Maggie50444a32010-11-29 18:26:32 -08002032 templen = fc_roundup(templen, sizeof(u32));
2033 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2034 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002035 count++;
Maggie50444a32010-11-29 18:26:32 -08002036 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2037 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002038
2039 /*
2040 * OS Name
2041 */
2042 if (fcs_hba_attr->os_name[0] != '\0') {
2043 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002044 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME);
Maggie50444a32010-11-29 18:26:32 -08002045 templen = (u16) strlen(fcs_hba_attr->os_name);
2046 memcpy(attr->value, fcs_hba_attr->os_name, templen);
2047 templen = fc_roundup(templen, sizeof(u32));
2048 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2049 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002050 count++;
Maggie50444a32010-11-29 18:26:32 -08002051 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2052 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002053 }
2054
2055 /*
2056 * MAX_CT_PAYLOAD
2057 */
2058 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002059 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT);
Maggie50444a32010-11-29 18:26:32 -08002060 templen = sizeof(fcs_hba_attr->max_ct_pyld);
2061 memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, templen);
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002062 templen = fc_roundup(templen, sizeof(u32));
2063 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
Maggie50444a32010-11-29 18:26:32 -08002064 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002065 count++;
Maggie50444a32010-11-29 18:26:32 -08002066 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2067 sizeof(templen));
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002068 /*
2069 * Send extended attributes ( FOS 7.1 support )
2070 */
2071 if (fdmi->retry_cnt == 0) {
2072 attr = (struct fdmi_attr_s *) curr_ptr;
2073 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODE_SYM_NAME);
2074 templen = sizeof(fcs_hba_attr->node_sym_name);
2075 memcpy(attr->value, &fcs_hba_attr->node_sym_name, templen);
2076 templen = fc_roundup(templen, sizeof(u32));
2077 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2078 len += templen;
2079 count++;
2080 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2081 sizeof(templen));
2082
2083 attr = (struct fdmi_attr_s *) curr_ptr;
2084 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_VENDOR_ID);
2085 templen = sizeof(fcs_hba_attr->vendor_info);
2086 memcpy(attr->value, &fcs_hba_attr->vendor_info, templen);
2087 templen = fc_roundup(templen, sizeof(u32));
2088 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2089 len += templen;
2090 count++;
2091 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2092 sizeof(templen));
2093
2094 attr = (struct fdmi_attr_s *) curr_ptr;
2095 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NUM_PORTS);
2096 templen = sizeof(fcs_hba_attr->num_ports);
2097 memcpy(attr->value, &fcs_hba_attr->num_ports, templen);
2098 templen = fc_roundup(templen, sizeof(u32));
2099 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2100 len += templen;
2101 count++;
2102 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2103 sizeof(templen));
2104
2105 attr = (struct fdmi_attr_s *) curr_ptr;
2106 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FABRIC_NAME);
2107 templen = sizeof(fcs_hba_attr->fabric_name);
2108 memcpy(attr->value, &fcs_hba_attr->fabric_name, templen);
2109 templen = fc_roundup(templen, sizeof(u32));
2110 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2111 len += templen;
2112 count++;
2113 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2114 sizeof(templen));
2115
2116 attr = (struct fdmi_attr_s *) curr_ptr;
2117 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_BIOS_VER);
2118 templen = sizeof(fcs_hba_attr->bios_ver);
2119 memcpy(attr->value, &fcs_hba_attr->bios_ver, templen);
2120 templen = fc_roundup(attr->len, sizeof(u32));
2121 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2122 len += templen;
2123 count++;
2124 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2125 sizeof(templen));
2126 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002127
2128 /*
2129 * Update size of payload
2130 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07002131 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002132
Jing Huangba816ea2010-10-18 17:10:50 -07002133 rhba->hba_attr_blk.attr_count = cpu_to_be32(count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002134 return len;
2135}
2136
2137static void
2138bfa_fcs_lport_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2139 void *cbarg, bfa_status_t req_status,
2140 u32 rsp_len, u32 resid_len,
2141 struct fchs_s *rsp_fchs)
2142{
2143 struct bfa_fcs_lport_fdmi_s *fdmi =
2144 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2145 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2146 struct ct_hdr_s *cthdr = NULL;
2147
2148 bfa_trc(port->fcs, port->port_cfg.pwwn);
2149
2150 /*
2151 * Sanity Checks
2152 */
2153 if (req_status != BFA_STATUS_OK) {
2154 bfa_trc(port->fcs, req_status);
2155 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2156 return;
2157 }
2158
2159 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07002160 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002161
2162 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2163 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2164 return;
2165 }
2166
2167 bfa_trc(port->fcs, cthdr->reason_code);
2168 bfa_trc(port->fcs, cthdr->exp_code);
2169 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2170}
2171
Jing Huang5fbe25c2010-10-18 17:17:23 -07002172/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002173* RPRT : Register Port
2174 */
2175static void
2176bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2177{
2178 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2179 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2180 struct fchs_s fchs;
2181 u16 len, attr_len;
2182 struct bfa_fcxp_s *fcxp;
2183 u8 *pyld;
2184
2185 bfa_trc(port->fcs, port->port_cfg.pwwn);
2186
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002187 fcxp = fcxp_alloced ? fcxp_alloced :
2188 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002189 if (!fcxp) {
2190 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002191 bfa_fcs_lport_fdmi_send_rprt, fdmi, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002192 return;
2193 }
2194 fdmi->fcxp = fcxp;
2195
2196 pyld = bfa_fcxp_get_reqbuf(fcxp);
Jing Huang6a18b162010-10-18 17:08:54 -07002197 memset(pyld, 0, FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002198
2199 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2200 FDMI_RPRT);
2201
2202 attr_len =
2203 bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi,
2204 (u8 *) ((struct ct_hdr_s *) pyld
2205 + 1));
2206
2207 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2208 FC_CLASS_3, len + attr_len, &fchs,
2209 bfa_fcs_lport_fdmi_rprt_response, (void *)fdmi,
2210 FC_MAX_PDUSZ, FC_FCCT_TOV);
2211
2212 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT);
2213}
2214
Jing Huang5fbe25c2010-10-18 17:17:23 -07002215/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002216 * This routine builds Port Attribute Block that used in RPA, RPRT commands.
2217 */
2218static u16
2219bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
2220 u8 *pyld)
2221{
2222 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
2223 struct fdmi_port_attr_s *port_attrib = (struct fdmi_port_attr_s *) pyld;
2224 struct fdmi_attr_s *attr;
2225 u8 *curr_ptr;
2226 u16 len;
2227 u8 count = 0;
Maggie50444a32010-11-29 18:26:32 -08002228 u16 templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002229
2230 /*
2231 * get port attributes
2232 */
2233 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2234
2235 len = sizeof(port_attrib->attr_count);
2236
2237 /*
2238 * fill out the invididual entries
2239 */
2240 curr_ptr = (u8 *) &port_attrib->port_attr;
2241
2242 /*
2243 * FC4 Types
2244 */
2245 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002246 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FC4_TYPES);
Maggie50444a32010-11-29 18:26:32 -08002247 templen = sizeof(fcs_port_attr.supp_fc4_types);
2248 memcpy(attr->value, fcs_port_attr.supp_fc4_types, templen);
2249 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2250 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002251 ++count;
2252 attr->len =
Maggie50444a32010-11-29 18:26:32 -08002253 cpu_to_be16(templen + sizeof(attr->type) +
2254 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002255
2256 /*
2257 * Supported Speed
2258 */
2259 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002260 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_SPEED);
Maggie50444a32010-11-29 18:26:32 -08002261 templen = sizeof(fcs_port_attr.supp_speed);
2262 memcpy(attr->value, &fcs_port_attr.supp_speed, templen);
2263 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2264 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002265 ++count;
2266 attr->len =
Maggie50444a32010-11-29 18:26:32 -08002267 cpu_to_be16(templen + sizeof(attr->type) +
2268 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002269
2270 /*
2271 * current Port Speed
2272 */
2273 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002274 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED);
Maggie50444a32010-11-29 18:26:32 -08002275 templen = sizeof(fcs_port_attr.curr_speed);
2276 memcpy(attr->value, &fcs_port_attr.curr_speed, templen);
2277 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2278 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002279 ++count;
Maggie50444a32010-11-29 18:26:32 -08002280 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2281 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002282
2283 /*
2284 * max frame size
2285 */
2286 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002287 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE);
Maggie50444a32010-11-29 18:26:32 -08002288 templen = sizeof(fcs_port_attr.max_frm_size);
2289 memcpy(attr->value, &fcs_port_attr.max_frm_size, templen);
2290 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2291 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002292 ++count;
Maggie50444a32010-11-29 18:26:32 -08002293 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2294 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002295
2296 /*
2297 * OS Device Name
2298 */
2299 if (fcs_port_attr.os_device_name[0] != '\0') {
2300 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002301 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME);
Maggie50444a32010-11-29 18:26:32 -08002302 templen = (u16) strlen(fcs_port_attr.os_device_name);
2303 memcpy(attr->value, fcs_port_attr.os_device_name, templen);
2304 templen = fc_roundup(templen, sizeof(u32));
2305 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2306 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002307 ++count;
Maggie50444a32010-11-29 18:26:32 -08002308 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2309 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002310 }
2311 /*
2312 * Host Name
2313 */
2314 if (fcs_port_attr.host_name[0] != '\0') {
2315 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002316 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME);
Maggie50444a32010-11-29 18:26:32 -08002317 templen = (u16) strlen(fcs_port_attr.host_name);
2318 memcpy(attr->value, fcs_port_attr.host_name, templen);
2319 templen = fc_roundup(templen, sizeof(u32));
2320 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2321 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002322 ++count;
Maggie50444a32010-11-29 18:26:32 -08002323 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2324 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002325 }
2326
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002327 if (fdmi->retry_cnt == 0) {
2328 attr = (struct fdmi_attr_s *) curr_ptr;
2329 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_NODE_NAME);
2330 templen = sizeof(fcs_port_attr.node_name);
2331 memcpy(attr->value, &fcs_port_attr.node_name, templen);
2332 templen = fc_roundup(templen, sizeof(u32));
2333 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2334 len += templen;
2335 ++count;
2336 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2337 sizeof(templen));
2338
2339 attr = (struct fdmi_attr_s *) curr_ptr;
2340 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NAME);
2341 templen = sizeof(fcs_port_attr.port_name);
2342 memcpy(attr->value, &fcs_port_attr.port_name, templen);
2343 templen = fc_roundup(templen, sizeof(u32));
2344 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + templen;
2345 len += templen;
2346 ++count;
2347 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2348 sizeof(templen));
2349
2350 if (fcs_port_attr.port_sym_name.symname[0] != '\0') {
2351 attr = (struct fdmi_attr_s *) curr_ptr;
2352 attr->type =
2353 cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SYM_NAME);
2354 templen = sizeof(fcs_port_attr.port_sym_name);
2355 memcpy(attr->value,
2356 &fcs_port_attr.port_sym_name, templen);
2357 templen = fc_roundup(templen, sizeof(u32));
2358 curr_ptr += sizeof(attr->type) +
2359 sizeof(templen) + templen;
2360 len += templen;
2361 ++count;
2362 attr->len = cpu_to_be16(templen +
2363 sizeof(attr->type) + sizeof(templen));
2364 }
2365
2366 attr = (struct fdmi_attr_s *) curr_ptr;
2367 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_TYPE);
2368 templen = sizeof(fcs_port_attr.port_type);
2369 memcpy(attr->value, &fcs_port_attr.port_type, templen);
2370 templen = fc_roundup(templen, sizeof(u32));
2371 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2372 len += templen;
2373 ++count;
2374 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2375 sizeof(templen));
2376
2377 attr = (struct fdmi_attr_s *) curr_ptr;
2378 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_COS);
2379 templen = sizeof(fcs_port_attr.scos);
2380 memcpy(attr->value, &fcs_port_attr.scos, templen);
2381 templen = fc_roundup(templen, sizeof(u32));
2382 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2383 len += templen;
2384 ++count;
2385 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2386 sizeof(templen));
2387
2388 attr = (struct fdmi_attr_s *) curr_ptr;
2389 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FAB_NAME);
2390 templen = sizeof(fcs_port_attr.port_fabric_name);
2391 memcpy(attr->value, &fcs_port_attr.port_fabric_name, templen);
2392 templen = fc_roundup(templen, sizeof(u32));
2393 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2394 len += templen;
2395 ++count;
2396 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2397 sizeof(templen));
2398
2399 attr = (struct fdmi_attr_s *) curr_ptr;
2400 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FC4_TYPE);
2401 templen = sizeof(fcs_port_attr.port_act_fc4_type);
2402 memcpy(attr->value, fcs_port_attr.port_act_fc4_type,
2403 templen);
2404 templen = fc_roundup(templen, sizeof(u32));
2405 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2406 len += templen;
2407 ++count;
2408 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2409 sizeof(templen));
2410
2411 attr = (struct fdmi_attr_s *) curr_ptr;
2412 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_STATE);
2413 templen = sizeof(fcs_port_attr.port_state);
2414 memcpy(attr->value, &fcs_port_attr.port_state, templen);
2415 templen = fc_roundup(templen, sizeof(u32));
2416 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2417 len += templen;
2418 ++count;
2419 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2420 sizeof(templen));
2421
2422 attr = (struct fdmi_attr_s *) curr_ptr;
2423 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NUM_RPRT);
2424 templen = sizeof(fcs_port_attr.num_ports);
2425 memcpy(attr->value, &fcs_port_attr.num_ports, templen);
2426 templen = fc_roundup(templen, sizeof(u32));
2427 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2428 len += templen;
2429 ++count;
2430 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2431 sizeof(templen));
2432 }
2433
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002434 /*
2435 * Update size of payload
2436 */
Jing Huangba816ea2010-10-18 17:10:50 -07002437 port_attrib->attr_count = cpu_to_be32(count);
Jing Huang5fbe25c2010-10-18 17:17:23 -07002438 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002439 return len;
2440}
2441
2442static u16
2443bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2444{
2445 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2446 struct fdmi_rprt_s *rprt = (struct fdmi_rprt_s *) pyld;
2447 u16 len;
2448
2449 rprt->hba_id = bfa_fcs_lport_get_pwwn(bfa_fcs_get_base_port(port->fcs));
2450 rprt->port_name = bfa_fcs_lport_get_pwwn(port);
2451
2452 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2453 (u8 *) &rprt->port_attr_blk);
2454
2455 len += sizeof(rprt->hba_id) + sizeof(rprt->port_name);
2456
2457 return len;
2458}
2459
2460static void
2461bfa_fcs_lport_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2462 void *cbarg, bfa_status_t req_status,
2463 u32 rsp_len, u32 resid_len,
2464 struct fchs_s *rsp_fchs)
2465{
2466 struct bfa_fcs_lport_fdmi_s *fdmi =
2467 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2468 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2469 struct ct_hdr_s *cthdr = NULL;
2470
2471 bfa_trc(port->fcs, port->port_cfg.pwwn);
2472
2473 /*
2474 * Sanity Checks
2475 */
2476 if (req_status != BFA_STATUS_OK) {
2477 bfa_trc(port->fcs, req_status);
2478 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2479 return;
2480 }
2481
2482 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07002483 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002484
2485 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2486 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2487 return;
2488 }
2489
2490 bfa_trc(port->fcs, cthdr->reason_code);
2491 bfa_trc(port->fcs, cthdr->exp_code);
2492 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2493}
2494
Jing Huang5fbe25c2010-10-18 17:17:23 -07002495/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002496* RPA : Register Port Attributes.
2497 */
2498static void
2499bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2500{
2501 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2502 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2503 struct fchs_s fchs;
2504 u16 len, attr_len;
2505 struct bfa_fcxp_s *fcxp;
2506 u8 *pyld;
2507
2508 bfa_trc(port->fcs, port->port_cfg.pwwn);
2509
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002510 fcxp = fcxp_alloced ? fcxp_alloced :
2511 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002512 if (!fcxp) {
2513 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002514 bfa_fcs_lport_fdmi_send_rpa, fdmi, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002515 return;
2516 }
2517 fdmi->fcxp = fcxp;
2518
2519 pyld = bfa_fcxp_get_reqbuf(fcxp);
Jing Huang6a18b162010-10-18 17:08:54 -07002520 memset(pyld, 0, FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002521
2522 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2523 FDMI_RPA);
2524
Jing Huang5fbe25c2010-10-18 17:17:23 -07002525 attr_len = bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi,
2526 (u8 *) ((struct ct_hdr_s *) pyld + 1));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002527
2528 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2529 FC_CLASS_3, len + attr_len, &fchs,
2530 bfa_fcs_lport_fdmi_rpa_response, (void *)fdmi,
2531 FC_MAX_PDUSZ, FC_FCCT_TOV);
2532
2533 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPA_SENT);
2534}
2535
2536static u16
2537bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2538{
2539 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2540 struct fdmi_rpa_s *rpa = (struct fdmi_rpa_s *) pyld;
2541 u16 len;
2542
2543 rpa->port_name = bfa_fcs_lport_get_pwwn(port);
2544
2545 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2546 (u8 *) &rpa->port_attr_blk);
2547
2548 len += sizeof(rpa->port_name);
2549
2550 return len;
2551}
2552
2553static void
2554bfa_fcs_lport_fdmi_rpa_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2555 void *cbarg, bfa_status_t req_status, u32 rsp_len,
2556 u32 resid_len, struct fchs_s *rsp_fchs)
2557{
2558 struct bfa_fcs_lport_fdmi_s *fdmi =
2559 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2560 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2561 struct ct_hdr_s *cthdr = NULL;
2562
2563 bfa_trc(port->fcs, port->port_cfg.pwwn);
2564
2565 /*
2566 * Sanity Checks
2567 */
2568 if (req_status != BFA_STATUS_OK) {
2569 bfa_trc(port->fcs, req_status);
2570 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2571 return;
2572 }
2573
2574 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07002575 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002576
2577 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2578 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2579 return;
2580 }
2581
2582 bfa_trc(port->fcs, cthdr->reason_code);
2583 bfa_trc(port->fcs, cthdr->exp_code);
2584 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2585}
2586
2587static void
2588bfa_fcs_lport_fdmi_timeout(void *arg)
2589{
2590 struct bfa_fcs_lport_fdmi_s *fdmi = (struct bfa_fcs_lport_fdmi_s *) arg;
2591
2592 bfa_sm_send_event(fdmi, FDMISM_EVENT_TIMEOUT);
2593}
2594
Maggie52f94b62010-11-29 18:21:32 -08002595static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002596bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2597 struct bfa_fcs_fdmi_hba_attr_s *hba_attr)
2598{
2599 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2600 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
Krishna Gudipatib480a322012-09-21 17:25:20 -07002601 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002602
Jing Huang6a18b162010-10-18 17:08:54 -07002603 memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002604
2605 bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc,
2606 hba_attr->manufacturer);
2607 bfa_ioc_get_adapter_serial_num(&port->fcs->bfa->ioc,
2608 hba_attr->serial_num);
2609 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2610 hba_attr->model);
2611 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2612 hba_attr->model_desc);
2613 bfa_ioc_get_pci_chip_rev(&port->fcs->bfa->ioc,
2614 hba_attr->hw_version);
2615 bfa_ioc_get_adapter_optrom_ver(&port->fcs->bfa->ioc,
2616 hba_attr->option_rom_ver);
2617 bfa_ioc_get_adapter_fw_ver(&port->fcs->bfa->ioc,
2618 hba_attr->fw_version);
2619
2620 strncpy(hba_attr->driver_version, (char *)driver_info->version,
2621 sizeof(hba_attr->driver_version));
2622
2623 strncpy(hba_attr->os_name, driver_info->host_os_name,
2624 sizeof(hba_attr->os_name));
2625
2626 /*
2627 * If there is a patch level, append it
2628 * to the os name along with a separator
2629 */
2630 if (driver_info->host_os_patch[0] != '\0') {
2631 strncat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
2632 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
2633 strncat(hba_attr->os_name, driver_info->host_os_patch,
2634 sizeof(driver_info->host_os_patch));
2635 }
2636
Krishna Gudipatib480a322012-09-21 17:25:20 -07002637 /* Retrieve the max frame size from the port attr */
2638 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2639 hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002640
2641 strncpy(hba_attr->node_sym_name.symname,
2642 port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
2643 strcpy(hba_attr->vendor_info, "BROCADE");
2644 hba_attr->num_ports =
2645 cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
2646 hba_attr->fabric_name = port->fabric->lps->pr_nwwn;
2647 strncpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
2648
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002649}
2650
Maggie52f94b62010-11-29 18:21:32 -08002651static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002652bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2653 struct bfa_fcs_fdmi_port_attr_s *port_attr)
2654{
2655 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2656 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2657 struct bfa_port_attr_s pport_attr;
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002658 struct bfa_lport_attr_s lport_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002659
Jing Huang6a18b162010-10-18 17:08:54 -07002660 memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002661
2662 /*
2663 * get pport attributes from hal
2664 */
2665 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
2666
2667 /*
2668 * get FC4 type Bitmask
2669 */
2670 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->supp_fc4_types);
2671
2672 /*
2673 * Supported Speeds
2674 */
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002675 switch (pport_attr.speed_supported) {
2676 case BFA_PORT_SPEED_16GBPS:
2677 port_attr->supp_speed =
2678 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_16G);
2679 break;
2680
2681 case BFA_PORT_SPEED_10GBPS:
2682 port_attr->supp_speed =
2683 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_10G);
2684 break;
2685
2686 case BFA_PORT_SPEED_8GBPS:
2687 port_attr->supp_speed =
2688 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_8G);
2689 break;
2690
2691 case BFA_PORT_SPEED_4GBPS:
2692 port_attr->supp_speed =
2693 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_4G);
2694 break;
2695
2696 default:
2697 bfa_sm_fault(port->fcs, pport_attr.speed_supported);
2698 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002699
2700 /*
2701 * Current Speed
2702 */
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002703 port_attr->curr_speed = cpu_to_be32(
2704 bfa_fcs_fdmi_convert_speed(pport_attr.speed));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002705
2706 /*
2707 * Max PDU Size.
2708 */
Krishna Gudipatib480a322012-09-21 17:25:20 -07002709 port_attr->max_frm_size = cpu_to_be32(pport_attr.pport_cfg.maxfrsize);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002710
2711 /*
2712 * OS device Name
2713 */
2714 strncpy(port_attr->os_device_name, (char *)driver_info->os_device_name,
2715 sizeof(port_attr->os_device_name));
2716
2717 /*
2718 * Host name
2719 */
2720 strncpy(port_attr->host_name, (char *)driver_info->host_machine_name,
2721 sizeof(port_attr->host_name));
Jing Huang7725ccf2009-09-23 17:46:15 -07002722
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002723 port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
2724 port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
2725
2726 strncpy(port_attr->port_sym_name.symname,
2727 (char *)&bfa_fcs_lport_get_psym_name(port), BFA_SYMNAME_MAXLEN);
2728 bfa_fcs_lport_get_attr(port, &lport_attr);
2729 port_attr->port_type = cpu_to_be32(lport_attr.port_type);
2730 port_attr->scos = pport_attr.cos_supported;
2731 port_attr->port_fabric_name = port->fabric->lps->pr_nwwn;
2732 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->port_act_fc4_type);
2733 port_attr->port_state = cpu_to_be32(pport_attr.port_state);
2734 port_attr->num_ports = cpu_to_be32(port->num_rports);
Jing Huang7725ccf2009-09-23 17:46:15 -07002735}
2736
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002737/*
2738 * Convert BFA speed to FDMI format.
2739 */
2740u32
2741bfa_fcs_fdmi_convert_speed(bfa_port_speed_t pport_speed)
2742{
2743 u32 ret;
2744
2745 switch (pport_speed) {
2746 case BFA_PORT_SPEED_1GBPS:
2747 case BFA_PORT_SPEED_2GBPS:
2748 ret = pport_speed;
2749 break;
2750
2751 case BFA_PORT_SPEED_4GBPS:
2752 ret = FDMI_TRANS_SPEED_4G;
2753 break;
2754
2755 case BFA_PORT_SPEED_8GBPS:
2756 ret = FDMI_TRANS_SPEED_8G;
2757 break;
2758
2759 case BFA_PORT_SPEED_10GBPS:
2760 ret = FDMI_TRANS_SPEED_10G;
2761 break;
2762
2763 case BFA_PORT_SPEED_16GBPS:
2764 ret = FDMI_TRANS_SPEED_16G;
2765 break;
2766
2767 default:
2768 ret = FDMI_TRANS_SPEED_UNKNOWN;
2769 }
2770 return ret;
2771}
Jing Huang7725ccf2009-09-23 17:46:15 -07002772
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002773void
2774bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s *ms)
2775{
2776 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2777
2778 fdmi->ms = ms;
2779 if (ms->port->fcs->fdmi_enabled)
2780 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
2781 else
2782 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_disabled);
2783}
2784
2785void
2786bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s *ms)
2787{
2788 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2789
2790 fdmi->ms = ms;
2791 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
2792}
2793
2794void
2795bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s *ms)
2796{
2797 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2798
2799 fdmi->ms = ms;
2800 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_ONLINE);
2801}
2802
2803#define BFA_FCS_MS_CMD_MAX_RETRIES 2
2804
2805/*
2806 * forward declarations
2807 */
2808static void bfa_fcs_lport_ms_send_plogi(void *ms_cbarg,
2809 struct bfa_fcxp_s *fcxp_alloced);
2810static void bfa_fcs_lport_ms_timeout(void *arg);
2811static void bfa_fcs_lport_ms_plogi_response(void *fcsarg,
2812 struct bfa_fcxp_s *fcxp,
2813 void *cbarg,
2814 bfa_status_t req_status,
2815 u32 rsp_len,
2816 u32 resid_len,
2817 struct fchs_s *rsp_fchs);
2818
2819static void bfa_fcs_lport_ms_send_gmal(void *ms_cbarg,
2820 struct bfa_fcxp_s *fcxp_alloced);
2821static void bfa_fcs_lport_ms_gmal_response(void *fcsarg,
2822 struct bfa_fcxp_s *fcxp,
2823 void *cbarg,
2824 bfa_status_t req_status,
2825 u32 rsp_len,
2826 u32 resid_len,
2827 struct fchs_s *rsp_fchs);
2828static void bfa_fcs_lport_ms_send_gfn(void *ms_cbarg,
2829 struct bfa_fcxp_s *fcxp_alloced);
2830static void bfa_fcs_lport_ms_gfn_response(void *fcsarg,
2831 struct bfa_fcxp_s *fcxp,
2832 void *cbarg,
2833 bfa_status_t req_status,
2834 u32 rsp_len,
2835 u32 resid_len,
2836 struct fchs_s *rsp_fchs);
Jing Huang5fbe25c2010-10-18 17:17:23 -07002837/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002838 * fcs_ms_sm FCS MS state machine
2839 */
2840
Jing Huang5fbe25c2010-10-18 17:17:23 -07002841/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002842 * MS State Machine events
2843 */
2844enum port_ms_event {
2845 MSSM_EVENT_PORT_ONLINE = 1,
2846 MSSM_EVENT_PORT_OFFLINE = 2,
2847 MSSM_EVENT_RSP_OK = 3,
2848 MSSM_EVENT_RSP_ERROR = 4,
2849 MSSM_EVENT_TIMEOUT = 5,
2850 MSSM_EVENT_FCXP_SENT = 6,
2851 MSSM_EVENT_PORT_FABRIC_RSCN = 7
2852};
2853
2854static void bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2855 enum port_ms_event event);
2856static void bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2857 enum port_ms_event event);
2858static void bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2859 enum port_ms_event event);
2860static void bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2861 enum port_ms_event event);
2862static void bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
2863 enum port_ms_event event);
2864static void bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
2865 enum port_ms_event event);
2866static void bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
2867 enum port_ms_event event);
2868static void bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
2869 enum port_ms_event event);
2870static void bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
2871 enum port_ms_event event);
2872static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
2873 enum port_ms_event event);
2874static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
2875 enum port_ms_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -07002876/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002877 * Start in offline state - awaiting NS to send start.
2878 */
2879static void
2880bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2881 enum port_ms_event event)
2882{
2883 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2884 bfa_trc(ms->port->fcs, event);
2885
2886 switch (event) {
2887 case MSSM_EVENT_PORT_ONLINE:
2888 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
2889 bfa_fcs_lport_ms_send_plogi(ms, NULL);
2890 break;
2891
2892 case MSSM_EVENT_PORT_OFFLINE:
2893 break;
2894
2895 default:
2896 bfa_sm_fault(ms->port->fcs, event);
2897 }
2898}
2899
2900static void
2901bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2902 enum port_ms_event event)
2903{
2904 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2905 bfa_trc(ms->port->fcs, event);
2906
2907 switch (event) {
2908 case MSSM_EVENT_FCXP_SENT:
2909 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi);
2910 break;
2911
2912 case MSSM_EVENT_PORT_OFFLINE:
2913 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2914 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2915 &ms->fcxp_wqe);
2916 break;
2917
2918 default:
2919 bfa_sm_fault(ms->port->fcs, event);
2920 }
2921}
2922
2923static void
2924bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2925 enum port_ms_event event)
2926{
2927 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2928 bfa_trc(ms->port->fcs, event);
2929
2930 switch (event) {
2931 case MSSM_EVENT_RSP_ERROR:
2932 /*
2933 * Start timer for a delayed retry
2934 */
2935 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_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 break;
2941
2942 case MSSM_EVENT_RSP_OK:
2943 /*
2944 * since plogi is done, now invoke MS related sub-modules
2945 */
2946 bfa_fcs_lport_fdmi_online(ms);
2947
Jing Huang5fbe25c2010-10-18 17:17:23 -07002948 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002949 * if this is a Vport, go to online state.
2950 */
2951 if (ms->port->vport) {
2952 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
2953 break;
2954 }
2955
2956 /*
2957 * For a base port we need to get the
2958 * switch's IP address.
2959 */
2960 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
2961 bfa_fcs_lport_ms_send_gmal(ms, NULL);
2962 break;
2963
2964 case MSSM_EVENT_PORT_OFFLINE:
2965 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2966 bfa_fcxp_discard(ms->fcxp);
2967 break;
2968
2969 default:
2970 bfa_sm_fault(ms->port->fcs, event);
2971 }
2972}
2973
2974static void
2975bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2976 enum port_ms_event event)
2977{
2978 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2979 bfa_trc(ms->port->fcs, event);
2980
2981 switch (event) {
2982 case MSSM_EVENT_TIMEOUT:
2983 /*
2984 * Retry Timer Expired. Re-send
2985 */
2986 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
2987 bfa_fcs_lport_ms_send_plogi(ms, NULL);
2988 break;
2989
2990 case MSSM_EVENT_PORT_OFFLINE:
2991 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2992 bfa_timer_stop(&ms->timer);
2993 break;
2994
2995 default:
2996 bfa_sm_fault(ms->port->fcs, event);
2997 }
2998}
2999
3000static void
3001bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
3002 enum port_ms_event event)
3003{
3004 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3005 bfa_trc(ms->port->fcs, event);
3006
3007 switch (event) {
3008 case MSSM_EVENT_PORT_OFFLINE:
3009 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3010 break;
3011
3012 case MSSM_EVENT_PORT_FABRIC_RSCN:
3013 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3014 ms->retry_cnt = 0;
3015 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3016 break;
3017
3018 default:
3019 bfa_sm_fault(ms->port->fcs, event);
3020 }
3021}
3022
3023static void
3024bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
3025 enum port_ms_event event)
3026{
3027 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3028 bfa_trc(ms->port->fcs, event);
3029
3030 switch (event) {
3031 case MSSM_EVENT_FCXP_SENT:
3032 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal);
3033 break;
3034
3035 case MSSM_EVENT_PORT_OFFLINE:
3036 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3037 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3038 &ms->fcxp_wqe);
3039 break;
3040
3041 default:
3042 bfa_sm_fault(ms->port->fcs, event);
3043 }
3044}
3045
3046static void
3047bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
3048 enum port_ms_event event)
3049{
3050 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3051 bfa_trc(ms->port->fcs, event);
3052
3053 switch (event) {
3054 case MSSM_EVENT_RSP_ERROR:
3055 /*
3056 * Start timer for a delayed retry
3057 */
3058 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
3059 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_retry);
3060 ms->port->stats.ms_retries++;
3061 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3062 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
3063 BFA_FCS_RETRY_TIMEOUT);
3064 } else {
3065 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3066 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3067 ms->retry_cnt = 0;
3068 }
3069 break;
3070
3071 case MSSM_EVENT_RSP_OK:
3072 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3073 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3074 break;
3075
3076 case MSSM_EVENT_PORT_OFFLINE:
3077 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3078 bfa_fcxp_discard(ms->fcxp);
3079 break;
3080
3081 default:
3082 bfa_sm_fault(ms->port->fcs, event);
3083 }
3084}
3085
3086static void
3087bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
3088 enum port_ms_event event)
3089{
3090 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3091 bfa_trc(ms->port->fcs, event);
3092
3093 switch (event) {
3094 case MSSM_EVENT_TIMEOUT:
3095 /*
3096 * Retry Timer Expired. Re-send
3097 */
3098 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
3099 bfa_fcs_lport_ms_send_gmal(ms, NULL);
3100 break;
3101
3102 case MSSM_EVENT_PORT_OFFLINE:
3103 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3104 bfa_timer_stop(&ms->timer);
3105 break;
3106
3107 default:
3108 bfa_sm_fault(ms->port->fcs, event);
3109 }
3110}
Jing Huang5fbe25c2010-10-18 17:17:23 -07003111/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003112 * ms_pvt MS local functions
3113 */
3114
3115static void
3116bfa_fcs_lport_ms_send_gmal(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3117{
3118 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3119 bfa_fcs_lport_t *port = ms->port;
3120 struct fchs_s fchs;
3121 int len;
3122 struct bfa_fcxp_s *fcxp;
3123
3124 bfa_trc(port->fcs, port->pid);
3125
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003126 fcxp = fcxp_alloced ? fcxp_alloced :
3127 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003128 if (!fcxp) {
3129 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003130 bfa_fcs_lport_ms_send_gmal, ms, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003131 return;
3132 }
3133 ms->fcxp = fcxp;
3134
3135 len = fc_gmal_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3136 bfa_fcs_lport_get_fcid(port),
Maggie Zhangf7f738122010-12-09 19:08:43 -08003137 port->fabric->lps->pr_nwwn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003138
3139 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3140 FC_CLASS_3, len, &fchs,
3141 bfa_fcs_lport_ms_gmal_response, (void *)ms,
3142 FC_MAX_PDUSZ, FC_FCCT_TOV);
3143
3144 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3145}
3146
3147static void
3148bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3149 void *cbarg, bfa_status_t req_status,
3150 u32 rsp_len, u32 resid_len,
3151 struct fchs_s *rsp_fchs)
3152{
3153 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3154 bfa_fcs_lport_t *port = ms->port;
3155 struct ct_hdr_s *cthdr = NULL;
3156 struct fcgs_gmal_resp_s *gmal_resp;
3157 struct fcgs_gmal_entry_s *gmal_entry;
3158 u32 num_entries;
3159 u8 *rsp_str;
3160
3161 bfa_trc(port->fcs, req_status);
3162 bfa_trc(port->fcs, port->port_cfg.pwwn);
3163
3164 /*
3165 * Sanity Checks
3166 */
3167 if (req_status != BFA_STATUS_OK) {
3168 bfa_trc(port->fcs, req_status);
3169 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3170 return;
3171 }
3172
3173 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07003174 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003175
3176 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3177 gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
3178
Jing Huangba816ea2010-10-18 17:10:50 -07003179 num_entries = be32_to_cpu(gmal_resp->ms_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003180 if (num_entries == 0) {
3181 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3182 return;
3183 }
3184 /*
3185 * The response could contain multiple Entries.
3186 * Entries for SNMP interface, etc.
3187 * We look for the entry with a telnet prefix.
3188 * First "http://" entry refers to IP addr
3189 */
3190
3191 gmal_entry = (struct fcgs_gmal_entry_s *)gmal_resp->ms_ma;
3192 while (num_entries > 0) {
3193 if (strncmp(gmal_entry->prefix,
3194 CT_GMAL_RESP_PREFIX_HTTP,
3195 sizeof(gmal_entry->prefix)) == 0) {
3196
3197 /*
3198 * if the IP address is terminating with a '/',
3199 * remove it.
3200 * Byte 0 consists of the length of the string.
3201 */
3202 rsp_str = &(gmal_entry->prefix[0]);
3203 if (rsp_str[gmal_entry->len-1] == '/')
3204 rsp_str[gmal_entry->len-1] = 0;
3205
3206 /* copy IP Address to fabric */
3207 strncpy(bfa_fcs_lport_get_fabric_ipaddr(port),
3208 gmal_entry->ip_addr,
3209 BFA_FCS_FABRIC_IPADDR_SZ);
3210 break;
3211 } else {
3212 --num_entries;
3213 ++gmal_entry;
3214 }
3215 }
3216
3217 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3218 return;
3219 }
3220
3221 bfa_trc(port->fcs, cthdr->reason_code);
3222 bfa_trc(port->fcs, cthdr->exp_code);
3223 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3224}
3225
3226static void
3227bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
3228 enum port_ms_event event)
3229{
3230 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3231 bfa_trc(ms->port->fcs, event);
3232
3233 switch (event) {
3234 case MSSM_EVENT_FCXP_SENT:
3235 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn);
3236 break;
3237
3238 case MSSM_EVENT_PORT_OFFLINE:
3239 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3240 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3241 &ms->fcxp_wqe);
3242 break;
3243
3244 default:
3245 bfa_sm_fault(ms->port->fcs, event);
3246 }
3247}
3248
3249static void
3250bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
3251 enum port_ms_event event)
3252{
3253 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3254 bfa_trc(ms->port->fcs, event);
3255
3256 switch (event) {
3257 case MSSM_EVENT_RSP_ERROR:
3258 /*
3259 * Start timer for a delayed retry
3260 */
3261 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
3262 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_retry);
3263 ms->port->stats.ms_retries++;
3264 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3265 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
3266 BFA_FCS_RETRY_TIMEOUT);
3267 } else {
3268 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3269 ms->retry_cnt = 0;
3270 }
3271 break;
3272
3273 case MSSM_EVENT_RSP_OK:
3274 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3275 break;
3276
3277 case MSSM_EVENT_PORT_OFFLINE:
3278 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3279 bfa_fcxp_discard(ms->fcxp);
3280 break;
3281
3282 default:
3283 bfa_sm_fault(ms->port->fcs, event);
3284 }
3285}
3286
3287static void
3288bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
3289 enum port_ms_event event)
3290{
3291 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3292 bfa_trc(ms->port->fcs, event);
3293
3294 switch (event) {
3295 case MSSM_EVENT_TIMEOUT:
3296 /*
3297 * Retry Timer Expired. Re-send
3298 */
3299 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3300 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3301 break;
3302
3303 case MSSM_EVENT_PORT_OFFLINE:
3304 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3305 bfa_timer_stop(&ms->timer);
3306 break;
3307
3308 default:
3309 bfa_sm_fault(ms->port->fcs, event);
3310 }
3311}
Jing Huang5fbe25c2010-10-18 17:17:23 -07003312/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003313 * ms_pvt MS local functions
3314 */
3315
3316static void
3317bfa_fcs_lport_ms_send_gfn(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3318{
3319 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3320 bfa_fcs_lport_t *port = ms->port;
3321 struct fchs_s fchs;
3322 int len;
3323 struct bfa_fcxp_s *fcxp;
3324
3325 bfa_trc(port->fcs, port->pid);
3326
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003327 fcxp = fcxp_alloced ? fcxp_alloced :
3328 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003329 if (!fcxp) {
3330 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003331 bfa_fcs_lport_ms_send_gfn, ms, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003332 return;
3333 }
3334 ms->fcxp = fcxp;
3335
3336 len = fc_gfn_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3337 bfa_fcs_lport_get_fcid(port),
Maggie Zhangf7f738122010-12-09 19:08:43 -08003338 port->fabric->lps->pr_nwwn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003339
3340 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3341 FC_CLASS_3, len, &fchs,
3342 bfa_fcs_lport_ms_gfn_response, (void *)ms,
3343 FC_MAX_PDUSZ, FC_FCCT_TOV);
3344
3345 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3346}
3347
3348static void
3349bfa_fcs_lport_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3350 void *cbarg, bfa_status_t req_status, u32 rsp_len,
3351 u32 resid_len, struct fchs_s *rsp_fchs)
3352{
3353 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3354 bfa_fcs_lport_t *port = ms->port;
3355 struct ct_hdr_s *cthdr = NULL;
3356 wwn_t *gfn_resp;
3357
3358 bfa_trc(port->fcs, req_status);
3359 bfa_trc(port->fcs, port->port_cfg.pwwn);
3360
3361 /*
3362 * Sanity Checks
3363 */
3364 if (req_status != BFA_STATUS_OK) {
3365 bfa_trc(port->fcs, req_status);
3366 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3367 return;
3368 }
3369
3370 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07003371 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003372
3373 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3374 gfn_resp = (wwn_t *)(cthdr + 1);
3375 /* check if it has actually changed */
3376 if ((memcmp((void *)&bfa_fcs_lport_get_fabric_name(port),
3377 gfn_resp, sizeof(wwn_t)) != 0)) {
3378 bfa_fcs_fabric_set_fabric_name(port->fabric, *gfn_resp);
3379 }
3380 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3381 return;
3382 }
3383
3384 bfa_trc(port->fcs, cthdr->reason_code);
3385 bfa_trc(port->fcs, cthdr->exp_code);
3386 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3387}
3388
Jing Huang5fbe25c2010-10-18 17:17:23 -07003389/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003390 * ms_pvt MS local functions
3391 */
3392
3393static void
3394bfa_fcs_lport_ms_send_plogi(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3395{
3396 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3397 struct bfa_fcs_lport_s *port = ms->port;
3398 struct fchs_s fchs;
3399 int len;
3400 struct bfa_fcxp_s *fcxp;
3401
3402 bfa_trc(port->fcs, port->pid);
3403
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003404 fcxp = fcxp_alloced ? fcxp_alloced :
3405 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003406 if (!fcxp) {
3407 port->stats.ms_plogi_alloc_wait++;
3408 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003409 bfa_fcs_lport_ms_send_plogi, ms, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003410 return;
3411 }
3412 ms->fcxp = fcxp;
3413
3414 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08003415 bfa_hton3b(FC_MGMT_SERVER),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003416 bfa_fcs_lport_get_fcid(port), 0,
3417 port->port_cfg.pwwn, port->port_cfg.nwwn,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003418 bfa_fcport_get_maxfrsize(port->fcs->bfa),
3419 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003420
3421 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3422 FC_CLASS_3, len, &fchs,
3423 bfa_fcs_lport_ms_plogi_response, (void *)ms,
3424 FC_MAX_PDUSZ, FC_ELS_TOV);
3425
3426 port->stats.ms_plogi_sent++;
3427 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3428}
3429
3430static void
3431bfa_fcs_lport_ms_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3432 void *cbarg, bfa_status_t req_status,
3433 u32 rsp_len, u32 resid_len, struct fchs_s *rsp_fchs)
3434{
3435 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3436 struct bfa_fcs_lport_s *port = ms->port;
3437 struct fc_els_cmd_s *els_cmd;
3438 struct fc_ls_rjt_s *ls_rjt;
3439
3440 bfa_trc(port->fcs, req_status);
3441 bfa_trc(port->fcs, port->port_cfg.pwwn);
3442
3443 /*
3444 * Sanity Checks
3445 */
3446 if (req_status != BFA_STATUS_OK) {
3447 port->stats.ms_plogi_rsp_err++;
3448 bfa_trc(port->fcs, req_status);
3449 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3450 return;
3451 }
3452
3453 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
3454
3455 switch (els_cmd->els_code) {
3456
3457 case FC_ELS_ACC:
3458 if (rsp_len < sizeof(struct fc_logi_s)) {
3459 bfa_trc(port->fcs, rsp_len);
3460 port->stats.ms_plogi_acc_err++;
3461 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3462 break;
3463 }
3464 port->stats.ms_plogi_accepts++;
3465 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3466 break;
3467
3468 case FC_ELS_LS_RJT:
3469 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
3470
3471 bfa_trc(port->fcs, ls_rjt->reason_code);
3472 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
3473
3474 port->stats.ms_rejects++;
3475 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3476 break;
3477
3478 default:
3479 port->stats.ms_plogi_unknown_rsp++;
3480 bfa_trc(port->fcs, els_cmd->els_code);
3481 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3482 }
3483}
3484
3485static void
3486bfa_fcs_lport_ms_timeout(void *arg)
3487{
3488 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) arg;
3489
3490 ms->port->stats.ms_timeouts++;
3491 bfa_sm_send_event(ms, MSSM_EVENT_TIMEOUT);
3492}
3493
3494
3495void
3496bfa_fcs_lport_ms_init(struct bfa_fcs_lport_s *port)
3497{
3498 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3499
3500 ms->port = port;
3501 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3502
3503 /*
3504 * Invoke init routines of sub modules.
3505 */
3506 bfa_fcs_lport_fdmi_init(ms);
3507}
3508
3509void
3510bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s *port)
3511{
3512 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3513
3514 ms->port = port;
3515 bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
3516 bfa_fcs_lport_fdmi_offline(ms);
3517}
3518
3519void
3520bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s *port)
3521{
3522 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3523
3524 ms->port = port;
3525 bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
3526}
3527void
3528bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s *port)
3529{
3530 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3531
3532 /* todo. Handle this only when in Online state */
3533 if (bfa_sm_cmp_state(ms, bfa_fcs_lport_ms_sm_online))
3534 bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
3535}
3536
Jing Huang5fbe25c2010-10-18 17:17:23 -07003537/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003538 * @page ns_sm_info VPORT NS State Machine
3539 *
3540 * @section ns_sm_interactions VPORT NS State Machine Interactions
3541 *
3542 * @section ns_sm VPORT NS State Machine
3543 * img ns_sm.jpg
3544 */
3545
3546/*
3547 * forward declarations
3548 */
3549static void bfa_fcs_lport_ns_send_plogi(void *ns_cbarg,
3550 struct bfa_fcxp_s *fcxp_alloced);
3551static void bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg,
3552 struct bfa_fcxp_s *fcxp_alloced);
3553static void bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg,
3554 struct bfa_fcxp_s *fcxp_alloced);
3555static void bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg,
3556 struct bfa_fcxp_s *fcxp_alloced);
3557static void bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg,
3558 struct bfa_fcxp_s *fcxp_alloced);
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003559static void bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg,
3560 struct bfa_fcxp_s *fcxp_alloced);
3561static void bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg,
3562 struct bfa_fcxp_s *fcxp_alloced);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003563static void bfa_fcs_lport_ns_timeout(void *arg);
3564static void bfa_fcs_lport_ns_plogi_response(void *fcsarg,
3565 struct bfa_fcxp_s *fcxp,
3566 void *cbarg,
3567 bfa_status_t req_status,
3568 u32 rsp_len,
3569 u32 resid_len,
3570 struct fchs_s *rsp_fchs);
3571static void bfa_fcs_lport_ns_rspn_id_response(void *fcsarg,
3572 struct bfa_fcxp_s *fcxp,
3573 void *cbarg,
3574 bfa_status_t req_status,
3575 u32 rsp_len,
3576 u32 resid_len,
3577 struct fchs_s *rsp_fchs);
3578static void bfa_fcs_lport_ns_rft_id_response(void *fcsarg,
3579 struct bfa_fcxp_s *fcxp,
3580 void *cbarg,
3581 bfa_status_t req_status,
3582 u32 rsp_len,
3583 u32 resid_len,
3584 struct fchs_s *rsp_fchs);
3585static void bfa_fcs_lport_ns_rff_id_response(void *fcsarg,
3586 struct bfa_fcxp_s *fcxp,
3587 void *cbarg,
3588 bfa_status_t req_status,
3589 u32 rsp_len,
3590 u32 resid_len,
3591 struct fchs_s *rsp_fchs);
3592static void bfa_fcs_lport_ns_gid_ft_response(void *fcsarg,
3593 struct bfa_fcxp_s *fcxp,
3594 void *cbarg,
3595 bfa_status_t req_status,
3596 u32 rsp_len,
3597 u32 resid_len,
3598 struct fchs_s *rsp_fchs);
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003599static void bfa_fcs_lport_ns_rnn_id_response(void *fcsarg,
3600 struct bfa_fcxp_s *fcxp,
3601 void *cbarg,
3602 bfa_status_t req_status,
3603 u32 rsp_len,
3604 u32 resid_len,
3605 struct fchs_s *rsp_fchs);
3606static void bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg,
3607 struct bfa_fcxp_s *fcxp,
3608 void *cbarg,
3609 bfa_status_t req_status,
3610 u32 rsp_len,
3611 u32 resid_len,
3612 struct fchs_s *rsp_fchs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003613static void bfa_fcs_lport_ns_process_gidft_pids(
3614 struct bfa_fcs_lport_s *port,
3615 u32 *pid_buf, u32 n_pids);
3616
3617static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port);
Jing Huang5fbe25c2010-10-18 17:17:23 -07003618/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003619 * fcs_ns_sm FCS nameserver interface state machine
3620 */
3621
Jing Huang5fbe25c2010-10-18 17:17:23 -07003622/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003623 * VPort NS State Machine events
3624 */
3625enum vport_ns_event {
3626 NSSM_EVENT_PORT_ONLINE = 1,
3627 NSSM_EVENT_PORT_OFFLINE = 2,
3628 NSSM_EVENT_PLOGI_SENT = 3,
3629 NSSM_EVENT_RSP_OK = 4,
3630 NSSM_EVENT_RSP_ERROR = 5,
3631 NSSM_EVENT_TIMEOUT = 6,
3632 NSSM_EVENT_NS_QUERY = 7,
3633 NSSM_EVENT_RSPNID_SENT = 8,
3634 NSSM_EVENT_RFTID_SENT = 9,
3635 NSSM_EVENT_RFFID_SENT = 10,
3636 NSSM_EVENT_GIDFT_SENT = 11,
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003637 NSSM_EVENT_RNNID_SENT = 12,
3638 NSSM_EVENT_RSNN_NN_SENT = 13,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003639};
3640
3641static void bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3642 enum vport_ns_event event);
3643static void bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3644 enum vport_ns_event event);
3645static void bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3646 enum vport_ns_event event);
3647static void bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3648 enum vport_ns_event event);
3649static void bfa_fcs_lport_ns_sm_sending_rspn_id(
3650 struct bfa_fcs_lport_ns_s *ns,
3651 enum vport_ns_event event);
3652static void bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3653 enum vport_ns_event event);
3654static void bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3655 enum vport_ns_event event);
3656static void bfa_fcs_lport_ns_sm_sending_rft_id(
3657 struct bfa_fcs_lport_ns_s *ns,
3658 enum vport_ns_event event);
3659static void bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
3660 enum vport_ns_event event);
3661static void bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
3662 enum vport_ns_event event);
3663static void bfa_fcs_lport_ns_sm_sending_rff_id(
3664 struct bfa_fcs_lport_ns_s *ns,
3665 enum vport_ns_event event);
3666static void bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
3667 enum vport_ns_event event);
3668static void bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
3669 enum vport_ns_event event);
3670static void bfa_fcs_lport_ns_sm_sending_gid_ft(
3671 struct bfa_fcs_lport_ns_s *ns,
3672 enum vport_ns_event event);
3673static void bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
3674 enum vport_ns_event event);
3675static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
3676 enum vport_ns_event event);
3677static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
3678 enum vport_ns_event event);
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003679static void bfa_fcs_lport_ns_sm_sending_rnn_id(
3680 struct bfa_fcs_lport_ns_s *ns,
3681 enum vport_ns_event event);
3682static void bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3683 enum vport_ns_event event);
3684static void bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3685 enum vport_ns_event event);
3686static void bfa_fcs_lport_ns_sm_sending_rsnn_nn(
3687 struct bfa_fcs_lport_ns_s *ns,
3688 enum vport_ns_event event);
3689static void bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3690 enum vport_ns_event event);
3691static void bfa_fcs_lport_ns_sm_rsnn_nn_retry(
3692 struct bfa_fcs_lport_ns_s *ns,
3693 enum vport_ns_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -07003694/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003695 * Start in offline state - awaiting linkup
3696 */
3697static void
3698bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3699 enum vport_ns_event event)
3700{
3701 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3702 bfa_trc(ns->port->fcs, event);
3703
3704 switch (event) {
3705 case NSSM_EVENT_PORT_ONLINE:
3706 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3707 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3708 break;
3709
3710 case NSSM_EVENT_PORT_OFFLINE:
3711 break;
3712
3713 default:
3714 bfa_sm_fault(ns->port->fcs, event);
3715 }
3716}
3717
3718static void
3719bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3720 enum vport_ns_event event)
3721{
3722 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3723 bfa_trc(ns->port->fcs, event);
3724
3725 switch (event) {
3726 case NSSM_EVENT_PLOGI_SENT:
3727 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi);
3728 break;
3729
3730 case NSSM_EVENT_PORT_OFFLINE:
3731 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3732 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3733 &ns->fcxp_wqe);
3734 break;
3735
3736 default:
3737 bfa_sm_fault(ns->port->fcs, event);
3738 }
3739}
3740
3741static void
3742bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3743 enum vport_ns_event event)
3744{
3745 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3746 bfa_trc(ns->port->fcs, event);
3747
3748 switch (event) {
3749 case NSSM_EVENT_RSP_ERROR:
3750 /*
3751 * Start timer for a delayed retry
3752 */
3753 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_retry);
3754 ns->port->stats.ns_retries++;
3755 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3756 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3757 BFA_FCS_RETRY_TIMEOUT);
3758 break;
3759
3760 case NSSM_EVENT_RSP_OK:
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003761 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3762 ns->num_rnnid_retries = 0;
3763 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003764 break;
3765
3766 case NSSM_EVENT_PORT_OFFLINE:
3767 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3768 bfa_fcxp_discard(ns->fcxp);
3769 break;
3770
3771 default:
3772 bfa_sm_fault(ns->port->fcs, event);
3773 }
3774}
3775
3776static void
3777bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3778 enum vport_ns_event event)
3779{
3780 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3781 bfa_trc(ns->port->fcs, event);
3782
3783 switch (event) {
3784 case NSSM_EVENT_TIMEOUT:
3785 /*
3786 * Retry Timer Expired. Re-send
3787 */
3788 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3789 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3790 break;
3791
3792 case NSSM_EVENT_PORT_OFFLINE:
3793 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3794 bfa_timer_stop(&ns->timer);
3795 break;
3796
3797 default:
3798 bfa_sm_fault(ns->port->fcs, event);
3799 }
3800}
3801
3802static void
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003803bfa_fcs_lport_ns_sm_sending_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3804 enum vport_ns_event event)
3805{
3806 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3807 bfa_trc(ns->port->fcs, event);
3808
3809 switch (event) {
3810 case NSSM_EVENT_RNNID_SENT:
3811 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id);
3812 break;
3813
3814 case NSSM_EVENT_PORT_OFFLINE:
3815 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3816 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3817 &ns->fcxp_wqe);
3818 break;
3819 default:
3820 bfa_sm_fault(ns->port->fcs, event);
3821 }
3822}
3823
3824static void
3825bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3826 enum vport_ns_event event)
3827{
3828 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3829 bfa_trc(ns->port->fcs, event);
3830
3831 switch (event) {
3832 case NSSM_EVENT_RSP_OK:
3833 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3834 ns->num_rnnid_retries = 0;
3835 ns->num_rsnn_nn_retries = 0;
3836 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3837 break;
3838
3839 case NSSM_EVENT_RSP_ERROR:
3840 if (ns->num_rnnid_retries < BFA_FCS_MAX_NS_RETRIES) {
3841 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id_retry);
3842 ns->port->stats.ns_retries++;
3843 ns->num_rnnid_retries++;
3844 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3845 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3846 BFA_FCS_RETRY_TIMEOUT);
3847 } else {
3848 bfa_sm_set_state(ns,
3849 bfa_fcs_lport_ns_sm_sending_rspn_id);
3850 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3851 }
3852 break;
3853
3854 case NSSM_EVENT_PORT_OFFLINE:
3855 bfa_fcxp_discard(ns->fcxp);
3856 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3857 break;
3858
3859 default:
3860 bfa_sm_fault(ns->port->fcs, event);
3861 }
3862}
3863
3864static void
3865bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3866 enum vport_ns_event event)
3867{
3868 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3869 bfa_trc(ns->port->fcs, event);
3870
3871 switch (event) {
3872 case NSSM_EVENT_TIMEOUT:
3873 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3874 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
3875 break;
3876
3877 case NSSM_EVENT_PORT_OFFLINE:
3878 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3879 bfa_timer_stop(&ns->timer);
3880 break;
3881
3882 default:
3883 bfa_sm_fault(ns->port->fcs, event);
3884 }
3885}
3886
3887static void
3888bfa_fcs_lport_ns_sm_sending_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3889 enum vport_ns_event event)
3890{
3891 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3892 bfa_trc(ns->port->fcs, event);
3893
3894 switch (event) {
3895 case NSSM_EVENT_RSNN_NN_SENT:
3896 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn);
3897 break;
3898
3899 case NSSM_EVENT_PORT_OFFLINE:
3900 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3901 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3902 &ns->fcxp_wqe);
3903 break;
3904
3905 default:
3906 bfa_sm_fault(ns->port->fcs, event);
3907 }
3908}
3909
3910static void
3911bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3912 enum vport_ns_event event)
3913{
3914 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3915 bfa_trc(ns->port->fcs, event);
3916
3917 switch (event) {
3918 case NSSM_EVENT_RSP_OK:
3919 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
3920 ns->num_rsnn_nn_retries = 0;
3921 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3922 break;
3923
3924 case NSSM_EVENT_RSP_ERROR:
3925 if (ns->num_rsnn_nn_retries < BFA_FCS_MAX_NS_RETRIES) {
3926 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn_retry);
3927 ns->port->stats.ns_retries++;
3928 ns->num_rsnn_nn_retries++;
3929 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3930 &ns->timer, bfa_fcs_lport_ns_timeout,
3931 ns, BFA_FCS_RETRY_TIMEOUT);
3932 } else {
3933 bfa_sm_set_state(ns,
3934 bfa_fcs_lport_ns_sm_sending_rspn_id);
3935 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3936 }
3937 break;
3938
3939 case NSSM_EVENT_PORT_OFFLINE:
3940 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3941 bfa_fcxp_discard(ns->fcxp);
3942 break;
3943
3944 default:
3945 bfa_sm_fault(ns->port->fcs, event);
3946 }
3947}
3948
3949static void
3950bfa_fcs_lport_ns_sm_rsnn_nn_retry(struct bfa_fcs_lport_ns_s *ns,
3951 enum vport_ns_event event)
3952{
3953 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3954 bfa_trc(ns->port->fcs, event);
3955
3956 switch (event) {
3957 case NSSM_EVENT_TIMEOUT:
3958 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3959 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3960 break;
3961
3962 case NSSM_EVENT_PORT_OFFLINE:
3963 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3964 bfa_timer_stop(&ns->timer);
3965 break;
3966
3967 default:
3968 bfa_sm_fault(ns->port->fcs, event);
3969 }
3970}
3971
3972static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003973bfa_fcs_lport_ns_sm_sending_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3974 enum vport_ns_event event)
3975{
3976 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3977 bfa_trc(ns->port->fcs, event);
3978
3979 switch (event) {
3980 case NSSM_EVENT_RSPNID_SENT:
3981 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id);
3982 break;
3983
3984 case NSSM_EVENT_PORT_OFFLINE:
3985 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3986 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3987 &ns->fcxp_wqe);
3988 break;
3989
3990 default:
3991 bfa_sm_fault(ns->port->fcs, event);
3992 }
3993}
3994
3995static void
3996bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3997 enum vport_ns_event event)
3998{
3999 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4000 bfa_trc(ns->port->fcs, event);
4001
4002 switch (event) {
4003 case NSSM_EVENT_RSP_ERROR:
4004 /*
4005 * Start timer for a delayed retry
4006 */
4007 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry);
4008 ns->port->stats.ns_retries++;
4009 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4010 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4011 BFA_FCS_RETRY_TIMEOUT);
4012 break;
4013
4014 case NSSM_EVENT_RSP_OK:
4015 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
4016 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
4017 break;
4018
4019 case NSSM_EVENT_PORT_OFFLINE:
4020 bfa_fcxp_discard(ns->fcxp);
4021 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4022 break;
4023
4024 default:
4025 bfa_sm_fault(ns->port->fcs, event);
4026 }
4027}
4028
4029static void
4030bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
4031 enum vport_ns_event event)
4032{
4033 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4034 bfa_trc(ns->port->fcs, event);
4035
4036 switch (event) {
4037 case NSSM_EVENT_TIMEOUT:
4038 /*
4039 * Retry Timer Expired. Re-send
4040 */
4041 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
4042 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
4043 break;
4044
4045 case NSSM_EVENT_PORT_OFFLINE:
4046 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4047 bfa_timer_stop(&ns->timer);
4048 break;
4049
4050 default:
4051 bfa_sm_fault(ns->port->fcs, event);
4052 }
4053}
4054
4055static void
4056bfa_fcs_lport_ns_sm_sending_rft_id(struct bfa_fcs_lport_ns_s *ns,
4057 enum vport_ns_event event)
4058{
4059 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4060 bfa_trc(ns->port->fcs, event);
4061
4062 switch (event) {
4063 case NSSM_EVENT_RFTID_SENT:
4064 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id);
4065 break;
4066
4067 case NSSM_EVENT_PORT_OFFLINE:
4068 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4069 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4070 &ns->fcxp_wqe);
4071 break;
4072
4073 default:
4074 bfa_sm_fault(ns->port->fcs, event);
4075 }
4076}
4077
4078static void
4079bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
4080 enum vport_ns_event event)
4081{
4082 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4083 bfa_trc(ns->port->fcs, event);
4084
4085 switch (event) {
4086 case NSSM_EVENT_RSP_OK:
4087 /* Now move to register FC4 Features */
4088 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
4089 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
4090 break;
4091
4092 case NSSM_EVENT_RSP_ERROR:
4093 /*
4094 * Start timer for a delayed retry
4095 */
4096 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id_retry);
4097 ns->port->stats.ns_retries++;
4098 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4099 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4100 BFA_FCS_RETRY_TIMEOUT);
4101 break;
4102
4103 case NSSM_EVENT_PORT_OFFLINE:
4104 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4105 bfa_fcxp_discard(ns->fcxp);
4106 break;
4107
4108 default:
4109 bfa_sm_fault(ns->port->fcs, event);
4110 }
4111}
4112
4113static void
4114bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
4115 enum vport_ns_event event)
4116{
4117 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4118 bfa_trc(ns->port->fcs, event);
4119
4120 switch (event) {
4121 case NSSM_EVENT_TIMEOUT:
4122 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
4123 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
4124 break;
4125
4126 case NSSM_EVENT_PORT_OFFLINE:
4127 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4128 bfa_timer_stop(&ns->timer);
4129 break;
4130
4131 default:
4132 bfa_sm_fault(ns->port->fcs, event);
4133 }
4134}
4135
4136static void
4137bfa_fcs_lport_ns_sm_sending_rff_id(struct bfa_fcs_lport_ns_s *ns,
4138 enum vport_ns_event event)
4139{
4140 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4141 bfa_trc(ns->port->fcs, event);
4142
4143 switch (event) {
4144 case NSSM_EVENT_RFFID_SENT:
4145 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id);
4146 break;
4147
4148 case NSSM_EVENT_PORT_OFFLINE:
4149 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4150 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4151 &ns->fcxp_wqe);
4152 break;
4153
4154 default:
4155 bfa_sm_fault(ns->port->fcs, event);
4156 }
4157}
4158
4159static void
4160bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
4161 enum vport_ns_event event)
4162{
4163 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4164 bfa_trc(ns->port->fcs, event);
4165
4166 switch (event) {
4167 case NSSM_EVENT_RSP_OK:
4168
4169 /*
4170 * If min cfg mode is enabled, we donot initiate rport
4171 * discovery with the fabric. Instead, we will retrieve the
4172 * boot targets from HAL/FW.
4173 */
4174 if (__fcs_min_cfg(ns->port->fcs)) {
4175 bfa_fcs_lport_ns_boot_target_disc(ns->port);
4176 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
4177 return;
4178 }
4179
4180 /*
4181 * If the port role is Initiator Mode issue NS query.
4182 * If it is Target Mode, skip this and go to online.
4183 */
4184 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4185 bfa_sm_set_state(ns,
4186 bfa_fcs_lport_ns_sm_sending_gid_ft);
4187 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4188 }
4189 /*
4190 * kick off mgmt srvr state machine
4191 */
4192 bfa_fcs_lport_ms_online(ns->port);
4193 break;
4194
4195 case NSSM_EVENT_RSP_ERROR:
4196 /*
4197 * Start timer for a delayed retry
4198 */
4199 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id_retry);
4200 ns->port->stats.ns_retries++;
4201 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4202 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4203 BFA_FCS_RETRY_TIMEOUT);
4204 break;
4205
4206 case NSSM_EVENT_PORT_OFFLINE:
4207 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4208 bfa_fcxp_discard(ns->fcxp);
4209 break;
4210
4211 default:
4212 bfa_sm_fault(ns->port->fcs, event);
4213 }
4214}
4215
4216static void
4217bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
4218 enum vport_ns_event event)
4219{
4220 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4221 bfa_trc(ns->port->fcs, event);
4222
4223 switch (event) {
4224 case NSSM_EVENT_TIMEOUT:
4225 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
4226 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
4227 break;
4228
4229 case NSSM_EVENT_PORT_OFFLINE:
4230 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4231 bfa_timer_stop(&ns->timer);
4232 break;
4233
4234 default:
4235 bfa_sm_fault(ns->port->fcs, event);
4236 }
4237}
4238static void
4239bfa_fcs_lport_ns_sm_sending_gid_ft(struct bfa_fcs_lport_ns_s *ns,
4240 enum vport_ns_event event)
4241{
4242 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4243 bfa_trc(ns->port->fcs, event);
4244
4245 switch (event) {
4246 case NSSM_EVENT_GIDFT_SENT:
4247 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft);
4248 break;
4249
4250 case NSSM_EVENT_PORT_OFFLINE:
4251 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4252 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4253 &ns->fcxp_wqe);
4254 break;
4255
4256 default:
4257 bfa_sm_fault(ns->port->fcs, event);
4258 }
4259}
4260
4261static void
4262bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
4263 enum vport_ns_event event)
4264{
4265 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4266 bfa_trc(ns->port->fcs, event);
4267
4268 switch (event) {
4269 case NSSM_EVENT_RSP_OK:
4270 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
4271 break;
4272
4273 case NSSM_EVENT_RSP_ERROR:
4274 /*
4275 * TBD: for certain reject codes, we don't need to retry
4276 */
4277 /*
4278 * Start timer for a delayed retry
4279 */
4280 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft_retry);
4281 ns->port->stats.ns_retries++;
4282 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4283 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4284 BFA_FCS_RETRY_TIMEOUT);
4285 break;
4286
4287 case NSSM_EVENT_PORT_OFFLINE:
4288 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4289 bfa_fcxp_discard(ns->fcxp);
4290 break;
4291
4292 case NSSM_EVENT_NS_QUERY:
4293 break;
4294
4295 default:
4296 bfa_sm_fault(ns->port->fcs, event);
4297 }
4298}
4299
4300static void
4301bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
4302 enum vport_ns_event event)
4303{
4304 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4305 bfa_trc(ns->port->fcs, event);
4306
4307 switch (event) {
4308 case NSSM_EVENT_TIMEOUT:
4309 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_gid_ft);
4310 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4311 break;
4312
4313 case NSSM_EVENT_PORT_OFFLINE:
4314 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4315 bfa_timer_stop(&ns->timer);
4316 break;
4317
4318 default:
4319 bfa_sm_fault(ns->port->fcs, event);
4320 }
4321}
4322
4323static void
4324bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
4325 enum vport_ns_event event)
4326{
4327 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4328 bfa_trc(ns->port->fcs, event);
4329
4330 switch (event) {
4331 case NSSM_EVENT_PORT_OFFLINE:
4332 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4333 break;
4334
4335 case NSSM_EVENT_NS_QUERY:
4336 /*
4337 * If the port role is Initiator Mode issue NS query.
4338 * If it is Target Mode, skip this and go to online.
4339 */
4340 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4341 bfa_sm_set_state(ns,
4342 bfa_fcs_lport_ns_sm_sending_gid_ft);
4343 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4344 };
4345 break;
4346
4347 default:
4348 bfa_sm_fault(ns->port->fcs, event);
4349 }
4350}
4351
4352
4353
Jing Huang5fbe25c2010-10-18 17:17:23 -07004354/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004355 * ns_pvt Nameserver local functions
4356 */
4357
4358static void
4359bfa_fcs_lport_ns_send_plogi(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4360{
4361 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4362 struct bfa_fcs_lport_s *port = ns->port;
4363 struct fchs_s fchs;
4364 int len;
4365 struct bfa_fcxp_s *fcxp;
4366
4367 bfa_trc(port->fcs, port->pid);
4368
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004369 fcxp = fcxp_alloced ? fcxp_alloced :
4370 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004371 if (!fcxp) {
4372 port->stats.ns_plogi_alloc_wait++;
4373 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004374 bfa_fcs_lport_ns_send_plogi, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004375 return;
4376 }
4377 ns->fcxp = fcxp;
4378
4379 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08004380 bfa_hton3b(FC_NAME_SERVER),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004381 bfa_fcs_lport_get_fcid(port), 0,
4382 port->port_cfg.pwwn, port->port_cfg.nwwn,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07004383 bfa_fcport_get_maxfrsize(port->fcs->bfa),
4384 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004385
4386 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4387 FC_CLASS_3, len, &fchs,
4388 bfa_fcs_lport_ns_plogi_response, (void *)ns,
4389 FC_MAX_PDUSZ, FC_ELS_TOV);
4390 port->stats.ns_plogi_sent++;
4391
4392 bfa_sm_send_event(ns, NSSM_EVENT_PLOGI_SENT);
4393}
4394
4395static void
4396bfa_fcs_lport_ns_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4397 void *cbarg, bfa_status_t req_status, u32 rsp_len,
4398 u32 resid_len, struct fchs_s *rsp_fchs)
4399{
4400 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4401 struct bfa_fcs_lport_s *port = ns->port;
4402 /* struct fc_logi_s *plogi_resp; */
4403 struct fc_els_cmd_s *els_cmd;
4404 struct fc_ls_rjt_s *ls_rjt;
4405
4406 bfa_trc(port->fcs, req_status);
4407 bfa_trc(port->fcs, port->port_cfg.pwwn);
4408
4409 /*
4410 * Sanity Checks
4411 */
4412 if (req_status != BFA_STATUS_OK) {
4413 bfa_trc(port->fcs, req_status);
4414 port->stats.ns_plogi_rsp_err++;
4415 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4416 return;
4417 }
4418
4419 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
4420
4421 switch (els_cmd->els_code) {
4422
4423 case FC_ELS_ACC:
4424 if (rsp_len < sizeof(struct fc_logi_s)) {
4425 bfa_trc(port->fcs, rsp_len);
4426 port->stats.ns_plogi_acc_err++;
4427 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4428 break;
4429 }
4430 port->stats.ns_plogi_accepts++;
4431 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4432 break;
4433
4434 case FC_ELS_LS_RJT:
4435 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
4436
4437 bfa_trc(port->fcs, ls_rjt->reason_code);
4438 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
4439
4440 port->stats.ns_rejects++;
4441
4442 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4443 break;
4444
4445 default:
4446 port->stats.ns_plogi_unknown_rsp++;
4447 bfa_trc(port->fcs, els_cmd->els_code);
4448 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4449 }
4450}
4451
Jing Huang5fbe25c2010-10-18 17:17:23 -07004452/*
Krishna Gudipatice7242b2012-08-22 19:52:43 -07004453 * Register node name for port_id
4454 */
4455static void
4456bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4457{
4458 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4459 struct bfa_fcs_lport_s *port = ns->port;
4460 struct fchs_s fchs;
4461 int len;
4462 struct bfa_fcxp_s *fcxp;
4463
4464 bfa_trc(port->fcs, port->port_cfg.pwwn);
4465
4466 fcxp = fcxp_alloced ? fcxp_alloced :
4467 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4468 if (!fcxp) {
4469 port->stats.ns_rnnid_alloc_wait++;
4470 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4471 bfa_fcs_lport_ns_send_rnn_id, ns, BFA_TRUE);
4472 return;
4473 }
4474
4475 ns->fcxp = fcxp;
4476
4477 len = fc_rnnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4478 bfa_fcs_lport_get_fcid(port),
4479 bfa_fcs_lport_get_fcid(port),
4480 bfa_fcs_lport_get_nwwn(port));
4481
4482 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4483 FC_CLASS_3, len, &fchs,
4484 bfa_fcs_lport_ns_rnn_id_response, (void *)ns,
4485 FC_MAX_PDUSZ, FC_FCCT_TOV);
4486
4487 port->stats.ns_rnnid_sent++;
4488 bfa_sm_send_event(ns, NSSM_EVENT_RNNID_SENT);
4489}
4490
4491static void
4492bfa_fcs_lport_ns_rnn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4493 void *cbarg, bfa_status_t req_status,
4494 u32 rsp_len, u32 resid_len,
4495 struct fchs_s *rsp_fchs)
4496
4497{
4498 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4499 struct bfa_fcs_lport_s *port = ns->port;
4500 struct ct_hdr_s *cthdr = NULL;
4501
4502 bfa_trc(port->fcs, port->port_cfg.pwwn);
4503
4504 /*
4505 * Sanity Checks
4506 */
4507 if (req_status != BFA_STATUS_OK) {
4508 bfa_trc(port->fcs, req_status);
4509 port->stats.ns_rnnid_rsp_err++;
4510 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4511 return;
4512 }
4513
4514 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4515 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4516
4517 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4518 port->stats.ns_rnnid_accepts++;
4519 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4520 return;
4521 }
4522
4523 port->stats.ns_rnnid_rejects++;
4524 bfa_trc(port->fcs, cthdr->reason_code);
4525 bfa_trc(port->fcs, cthdr->exp_code);
4526 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4527}
4528
4529/*
4530 * Register the symbolic node name for a given node name.
4531 */
4532static void
4533bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4534{
4535 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4536 struct bfa_fcs_lport_s *port = ns->port;
4537 struct fchs_s fchs;
4538 int len;
4539 struct bfa_fcxp_s *fcxp;
4540 u8 *nsymbl;
4541
4542 bfa_trc(port->fcs, port->port_cfg.pwwn);
4543
4544 fcxp = fcxp_alloced ? fcxp_alloced :
4545 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4546 if (!fcxp) {
4547 port->stats.ns_rsnn_nn_alloc_wait++;
4548 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4549 bfa_fcs_lport_ns_send_rsnn_nn, ns, BFA_TRUE);
4550 return;
4551 }
4552 ns->fcxp = fcxp;
4553
4554 nsymbl = (u8 *) &(bfa_fcs_lport_get_nsym_name(
4555 bfa_fcs_get_base_port(port->fcs)));
4556
4557 len = fc_rsnn_nn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4558 bfa_fcs_lport_get_fcid(port),
4559 bfa_fcs_lport_get_nwwn(port), nsymbl);
4560
4561 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4562 FC_CLASS_3, len, &fchs,
4563 bfa_fcs_lport_ns_rsnn_nn_response, (void *)ns,
4564 FC_MAX_PDUSZ, FC_FCCT_TOV);
4565
4566 port->stats.ns_rsnn_nn_sent++;
4567
4568 bfa_sm_send_event(ns, NSSM_EVENT_RSNN_NN_SENT);
4569}
4570
4571static void
4572bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4573 void *cbarg, bfa_status_t req_status,
4574 u32 rsp_len, u32 resid_len,
4575 struct fchs_s *rsp_fchs)
4576{
4577 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4578 struct bfa_fcs_lport_s *port = ns->port;
4579 struct ct_hdr_s *cthdr = NULL;
4580
4581 bfa_trc(port->fcs, port->port_cfg.pwwn);
4582
4583 /*
4584 * Sanity Checks
4585 */
4586 if (req_status != BFA_STATUS_OK) {
4587 bfa_trc(port->fcs, req_status);
4588 port->stats.ns_rsnn_nn_rsp_err++;
4589 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4590 return;
4591 }
4592
4593 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4594 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4595
4596 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4597 port->stats.ns_rsnn_nn_accepts++;
4598 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4599 return;
4600 }
4601
4602 port->stats.ns_rsnn_nn_rejects++;
4603 bfa_trc(port->fcs, cthdr->reason_code);
4604 bfa_trc(port->fcs, cthdr->exp_code);
4605 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4606}
4607
4608/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004609 * Register the symbolic port name.
4610 */
4611static void
4612bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4613{
4614 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4615 struct bfa_fcs_lport_s *port = ns->port;
4616 struct fchs_s fchs;
4617 int len;
4618 struct bfa_fcxp_s *fcxp;
4619 u8 symbl[256];
4620 u8 *psymbl = &symbl[0];
4621
Jing Huang6a18b162010-10-18 17:08:54 -07004622 memset(symbl, 0, sizeof(symbl));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004623
4624 bfa_trc(port->fcs, port->port_cfg.pwwn);
4625
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004626 fcxp = fcxp_alloced ? fcxp_alloced :
4627 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004628 if (!fcxp) {
4629 port->stats.ns_rspnid_alloc_wait++;
4630 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004631 bfa_fcs_lport_ns_send_rspn_id, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004632 return;
4633 }
4634 ns->fcxp = fcxp;
4635
4636 /*
4637 * for V-Port, form a Port Symbolic Name
4638 */
4639 if (port->vport) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07004640 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004641 * For Vports, we append the vport's port symbolic name
4642 * to that of the base port.
4643 */
4644
4645 strncpy((char *)psymbl,
4646 (char *) &
4647 (bfa_fcs_lport_get_psym_name
4648 (bfa_fcs_get_base_port(port->fcs))),
4649 strlen((char *) &
4650 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
4651 (port->fcs))));
4652
4653 /* Ensure we have a null terminating string. */
4654 ((char *)psymbl)[strlen((char *) &
4655 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
4656 (port->fcs)))] = 0;
4657 strncat((char *)psymbl,
4658 (char *) &(bfa_fcs_lport_get_psym_name(port)),
4659 strlen((char *) &bfa_fcs_lport_get_psym_name(port)));
4660 } else {
4661 psymbl = (u8 *) &(bfa_fcs_lport_get_psym_name(port));
4662 }
4663
4664 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4665 bfa_fcs_lport_get_fcid(port), 0, psymbl);
4666
4667 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4668 FC_CLASS_3, len, &fchs,
4669 bfa_fcs_lport_ns_rspn_id_response, (void *)ns,
4670 FC_MAX_PDUSZ, FC_FCCT_TOV);
4671
4672 port->stats.ns_rspnid_sent++;
4673
4674 bfa_sm_send_event(ns, NSSM_EVENT_RSPNID_SENT);
4675}
4676
4677static void
4678bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4679 void *cbarg, bfa_status_t req_status,
4680 u32 rsp_len, u32 resid_len,
4681 struct fchs_s *rsp_fchs)
4682{
4683 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4684 struct bfa_fcs_lport_s *port = ns->port;
4685 struct ct_hdr_s *cthdr = NULL;
4686
4687 bfa_trc(port->fcs, port->port_cfg.pwwn);
4688
4689 /*
4690 * Sanity Checks
4691 */
4692 if (req_status != BFA_STATUS_OK) {
4693 bfa_trc(port->fcs, req_status);
4694 port->stats.ns_rspnid_rsp_err++;
4695 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4696 return;
4697 }
4698
4699 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004700 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004701
4702 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4703 port->stats.ns_rspnid_accepts++;
4704 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4705 return;
4706 }
4707
4708 port->stats.ns_rspnid_rejects++;
4709 bfa_trc(port->fcs, cthdr->reason_code);
4710 bfa_trc(port->fcs, cthdr->exp_code);
4711 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4712}
4713
Jing Huang5fbe25c2010-10-18 17:17:23 -07004714/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004715 * Register FC4-Types
4716 */
4717static void
4718bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4719{
4720 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4721 struct bfa_fcs_lport_s *port = ns->port;
4722 struct fchs_s fchs;
4723 int len;
4724 struct bfa_fcxp_s *fcxp;
4725
4726 bfa_trc(port->fcs, port->port_cfg.pwwn);
4727
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004728 fcxp = fcxp_alloced ? fcxp_alloced :
4729 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004730 if (!fcxp) {
4731 port->stats.ns_rftid_alloc_wait++;
4732 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004733 bfa_fcs_lport_ns_send_rft_id, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004734 return;
4735 }
4736 ns->fcxp = fcxp;
4737
4738 len = fc_rftid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4739 bfa_fcs_lport_get_fcid(port), 0, port->port_cfg.roles);
4740
4741 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4742 FC_CLASS_3, len, &fchs,
4743 bfa_fcs_lport_ns_rft_id_response, (void *)ns,
4744 FC_MAX_PDUSZ, FC_FCCT_TOV);
4745
4746 port->stats.ns_rftid_sent++;
4747 bfa_sm_send_event(ns, NSSM_EVENT_RFTID_SENT);
4748}
4749
4750static void
4751bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4752 void *cbarg, bfa_status_t req_status,
4753 u32 rsp_len, u32 resid_len,
4754 struct fchs_s *rsp_fchs)
4755{
4756 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4757 struct bfa_fcs_lport_s *port = ns->port;
4758 struct ct_hdr_s *cthdr = NULL;
4759
4760 bfa_trc(port->fcs, port->port_cfg.pwwn);
4761
4762 /*
4763 * Sanity Checks
4764 */
4765 if (req_status != BFA_STATUS_OK) {
4766 bfa_trc(port->fcs, req_status);
4767 port->stats.ns_rftid_rsp_err++;
4768 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4769 return;
4770 }
4771
4772 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004773 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004774
4775 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4776 port->stats.ns_rftid_accepts++;
4777 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4778 return;
4779 }
4780
4781 port->stats.ns_rftid_rejects++;
4782 bfa_trc(port->fcs, cthdr->reason_code);
4783 bfa_trc(port->fcs, cthdr->exp_code);
4784 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4785}
4786
Jing Huang5fbe25c2010-10-18 17:17:23 -07004787/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004788 * Register FC4-Features : Should be done after RFT_ID
4789 */
4790static void
4791bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4792{
4793 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4794 struct bfa_fcs_lport_s *port = ns->port;
4795 struct fchs_s fchs;
4796 int len;
4797 struct bfa_fcxp_s *fcxp;
4798 u8 fc4_ftrs = 0;
4799
4800 bfa_trc(port->fcs, port->port_cfg.pwwn);
4801
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004802 fcxp = fcxp_alloced ? fcxp_alloced :
4803 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004804 if (!fcxp) {
4805 port->stats.ns_rffid_alloc_wait++;
4806 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004807 bfa_fcs_lport_ns_send_rff_id, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004808 return;
4809 }
4810 ns->fcxp = fcxp;
4811
4812 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port))
4813 fc4_ftrs = FC_GS_FCP_FC4_FEATURE_INITIATOR;
4814
4815 len = fc_rffid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4816 bfa_fcs_lport_get_fcid(port), 0,
4817 FC_TYPE_FCP, fc4_ftrs);
4818
4819 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4820 FC_CLASS_3, len, &fchs,
4821 bfa_fcs_lport_ns_rff_id_response, (void *)ns,
4822 FC_MAX_PDUSZ, FC_FCCT_TOV);
4823
4824 port->stats.ns_rffid_sent++;
4825 bfa_sm_send_event(ns, NSSM_EVENT_RFFID_SENT);
4826}
4827
4828static void
4829bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4830 void *cbarg, bfa_status_t req_status,
4831 u32 rsp_len, u32 resid_len,
4832 struct fchs_s *rsp_fchs)
4833{
4834 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4835 struct bfa_fcs_lport_s *port = ns->port;
4836 struct ct_hdr_s *cthdr = NULL;
4837
4838 bfa_trc(port->fcs, port->port_cfg.pwwn);
4839
4840 /*
4841 * Sanity Checks
4842 */
4843 if (req_status != BFA_STATUS_OK) {
4844 bfa_trc(port->fcs, req_status);
4845 port->stats.ns_rffid_rsp_err++;
4846 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4847 return;
4848 }
4849
4850 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004851 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004852
4853 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4854 port->stats.ns_rffid_accepts++;
4855 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4856 return;
4857 }
4858
4859 port->stats.ns_rffid_rejects++;
4860 bfa_trc(port->fcs, cthdr->reason_code);
4861 bfa_trc(port->fcs, cthdr->exp_code);
4862
4863 if (cthdr->reason_code == CT_RSN_NOT_SUPP) {
4864 /* if this command is not supported, we don't retry */
4865 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4866 } else
4867 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4868}
Jing Huang5fbe25c2010-10-18 17:17:23 -07004869/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004870 * Query Fabric for FC4-Types Devices.
4871 *
4872* TBD : Need to use a local (FCS private) response buffer, since the response
4873 * can be larger than 2K.
4874 */
4875static void
4876bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4877{
4878 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4879 struct bfa_fcs_lport_s *port = ns->port;
4880 struct fchs_s fchs;
4881 int len;
4882 struct bfa_fcxp_s *fcxp;
4883
4884 bfa_trc(port->fcs, port->pid);
4885
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004886 fcxp = fcxp_alloced ? fcxp_alloced :
4887 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004888 if (!fcxp) {
4889 port->stats.ns_gidft_alloc_wait++;
4890 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004891 bfa_fcs_lport_ns_send_gid_ft, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004892 return;
4893 }
4894 ns->fcxp = fcxp;
4895
4896 /*
4897 * This query is only initiated for FCP initiator mode.
4898 */
4899 len = fc_gid_ft_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4900 ns->port->pid, FC_TYPE_FCP);
4901
4902 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4903 FC_CLASS_3, len, &fchs,
4904 bfa_fcs_lport_ns_gid_ft_response, (void *)ns,
4905 bfa_fcxp_get_maxrsp(port->fcs->bfa), FC_FCCT_TOV);
4906
4907 port->stats.ns_gidft_sent++;
4908
4909 bfa_sm_send_event(ns, NSSM_EVENT_GIDFT_SENT);
4910}
4911
4912static void
4913bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4914 void *cbarg, bfa_status_t req_status,
4915 u32 rsp_len, u32 resid_len,
4916 struct fchs_s *rsp_fchs)
4917{
4918 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4919 struct bfa_fcs_lport_s *port = ns->port;
4920 struct ct_hdr_s *cthdr = NULL;
4921 u32 n_pids;
4922
4923 bfa_trc(port->fcs, port->port_cfg.pwwn);
4924
4925 /*
4926 * Sanity Checks
4927 */
4928 if (req_status != BFA_STATUS_OK) {
4929 bfa_trc(port->fcs, req_status);
4930 port->stats.ns_gidft_rsp_err++;
4931 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4932 return;
4933 }
4934
4935 if (resid_len != 0) {
4936 /*
4937 * TBD : we will need to allocate a larger buffer & retry the
4938 * command
4939 */
4940 bfa_trc(port->fcs, rsp_len);
4941 bfa_trc(port->fcs, resid_len);
4942 return;
4943 }
4944
4945 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004946 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004947
4948 switch (cthdr->cmd_rsp_code) {
4949
4950 case CT_RSP_ACCEPT:
4951
4952 port->stats.ns_gidft_accepts++;
4953 n_pids = (fc_get_ctresp_pyld_len(rsp_len) / sizeof(u32));
4954 bfa_trc(port->fcs, n_pids);
4955 bfa_fcs_lport_ns_process_gidft_pids(port,
4956 (u32 *) (cthdr + 1),
4957 n_pids);
4958 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4959 break;
4960
4961 case CT_RSP_REJECT:
4962
4963 /*
4964 * Check the reason code & explanation.
4965 * There may not have been any FC4 devices in the fabric
4966 */
4967 port->stats.ns_gidft_rejects++;
4968 bfa_trc(port->fcs, cthdr->reason_code);
4969 bfa_trc(port->fcs, cthdr->exp_code);
4970
4971 if ((cthdr->reason_code == CT_RSN_UNABLE_TO_PERF)
4972 && (cthdr->exp_code == CT_NS_EXP_FT_NOT_REG)) {
4973
4974 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4975 } else {
4976 /*
4977 * for all other errors, retry
4978 */
4979 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4980 }
4981 break;
4982
4983 default:
4984 port->stats.ns_gidft_unknown_rsp++;
4985 bfa_trc(port->fcs, cthdr->cmd_rsp_code);
4986 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4987 }
4988}
4989
Jing Huang5fbe25c2010-10-18 17:17:23 -07004990/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004991 * This routine will be called by bfa_timer on timer timeouts.
4992 *
4993 * param[in] port - pointer to bfa_fcs_lport_t.
4994 *
4995 * return
4996 * void
4997 *
4998 * Special Considerations:
4999 *
5000 * note
5001 */
5002static void
5003bfa_fcs_lport_ns_timeout(void *arg)
5004{
5005 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) arg;
5006
5007 ns->port->stats.ns_timeouts++;
5008 bfa_sm_send_event(ns, NSSM_EVENT_TIMEOUT);
5009}
5010
5011/*
5012 * Process the PID list in GID_FT response
5013 */
5014static void
5015bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s *port, u32 *pid_buf,
5016 u32 n_pids)
5017{
5018 struct fcgs_gidft_resp_s *gidft_entry;
5019 struct bfa_fcs_rport_s *rport;
5020 u32 ii;
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005021 struct bfa_fcs_fabric_s *fabric = port->fabric;
5022 struct bfa_fcs_vport_s *vport;
5023 struct list_head *qe;
5024 u8 found = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005025
5026 for (ii = 0; ii < n_pids; ii++) {
5027 gidft_entry = (struct fcgs_gidft_resp_s *) &pid_buf[ii];
5028
5029 if (gidft_entry->pid == port->pid)
5030 continue;
5031
5032 /*
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005033 * Ignore PID if it is of base port
5034 * (Avoid vports discovering base port as remote port)
5035 */
5036 if (gidft_entry->pid == fabric->bport.pid)
5037 continue;
5038
5039 /*
5040 * Ignore PID if it is of vport created on the same base port
5041 * (Avoid vport discovering every other vport created on the
5042 * same port as remote port)
5043 */
5044 list_for_each(qe, &fabric->vport_q) {
5045 vport = (struct bfa_fcs_vport_s *) qe;
5046 if (vport->lport.pid == gidft_entry->pid)
5047 found = 1;
5048 }
5049
5050 if (found) {
5051 found = 0;
5052 continue;
5053 }
5054
5055 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005056 * Check if this rport already exists
5057 */
5058 rport = bfa_fcs_lport_get_rport_by_pid(port, gidft_entry->pid);
5059 if (rport == NULL) {
5060 /*
5061 * this is a new device. create rport
5062 */
5063 rport = bfa_fcs_rport_create(port, gidft_entry->pid);
5064 } else {
5065 /*
5066 * this rport already exists
5067 */
5068 bfa_fcs_rport_scn(rport);
5069 }
5070
5071 bfa_trc(port->fcs, gidft_entry->pid);
5072
5073 /*
5074 * if the last entry bit is set, bail out.
5075 */
5076 if (gidft_entry->last)
5077 return;
5078 }
5079}
5080
Jing Huang5fbe25c2010-10-18 17:17:23 -07005081/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005082 * fcs_ns_public FCS nameserver public interfaces
5083 */
5084
5085/*
5086 * Functions called by port/fab.
5087 * These will send relevant Events to the ns state machine.
5088 */
5089void
5090bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s *port)
5091{
5092 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5093
5094 ns->port = port;
5095 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
5096}
5097
5098void
5099bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s *port)
5100{
5101 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5102
5103 ns->port = port;
5104 bfa_sm_send_event(ns, NSSM_EVENT_PORT_OFFLINE);
5105}
5106
5107void
5108bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s *port)
5109{
5110 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5111
5112 ns->port = port;
5113 bfa_sm_send_event(ns, NSSM_EVENT_PORT_ONLINE);
5114}
5115
5116void
5117bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s *port)
5118{
5119 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5120
5121 bfa_trc(port->fcs, port->pid);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005122 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_online))
5123 bfa_sm_send_event(ns, NSSM_EVENT_NS_QUERY);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005124}
5125
Maggie52f94b62010-11-29 18:21:32 -08005126static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005127bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port)
5128{
5129
5130 struct bfa_fcs_rport_s *rport;
5131 u8 nwwns;
5132 wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
5133 int ii;
5134
5135 bfa_iocfc_get_bootwwns(port->fcs->bfa, &nwwns, wwns);
5136
5137 for (ii = 0 ; ii < nwwns; ++ii) {
5138 rport = bfa_fcs_rport_create_by_wwn(port, wwns[ii]);
Jing Huangd4b671c2010-12-26 21:46:35 -08005139 WARN_ON(!rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005140 }
5141}
5142
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005143void
5144bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
5145{
5146 struct bfa_fcs_lport_ns_s *ns = cbarg;
5147 struct bfa_fcs_lport_s *port = ns->port;
5148 struct fchs_s fchs;
5149 struct bfa_fcxp_s *fcxp;
5150 u8 symbl[256];
5151 u8 *psymbl = &symbl[0];
5152 int len;
5153
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005154 /* Avoid sending RSPN in the following states. */
5155 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_offline) ||
5156 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_sending) ||
5157 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi) ||
5158 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_retry) ||
5159 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry))
5160 return;
5161
5162 memset(symbl, 0, sizeof(symbl));
5163 bfa_trc(port->fcs, port->port_cfg.pwwn);
5164
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07005165 fcxp = fcxp_alloced ? fcxp_alloced :
5166 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005167 if (!fcxp) {
5168 port->stats.ns_rspnid_alloc_wait++;
5169 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07005170 bfa_fcs_lport_ns_util_send_rspn_id, ns, BFA_FALSE);
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005171 return;
5172 }
5173
5174 ns->fcxp = fcxp;
5175
5176 if (port->vport) {
5177 /*
5178 * For Vports, we append the vport's port symbolic name
5179 * to that of the base port.
5180 */
5181 strncpy((char *)psymbl, (char *)&(bfa_fcs_lport_get_psym_name
5182 (bfa_fcs_get_base_port(port->fcs))),
5183 strlen((char *)&bfa_fcs_lport_get_psym_name(
5184 bfa_fcs_get_base_port(port->fcs))));
5185
5186 /* Ensure we have a null terminating string. */
5187 ((char *)psymbl)[strlen((char *)&bfa_fcs_lport_get_psym_name(
5188 bfa_fcs_get_base_port(port->fcs)))] = 0;
5189
5190 strncat((char *)psymbl,
5191 (char *)&(bfa_fcs_lport_get_psym_name(port)),
5192 strlen((char *)&bfa_fcs_lport_get_psym_name(port)));
5193 }
5194
5195 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5196 bfa_fcs_lport_get_fcid(port), 0, psymbl);
5197
5198 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5199 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
5200
5201 port->stats.ns_rspnid_sent++;
5202}
5203
Jing Huang5fbe25c2010-10-18 17:17:23 -07005204/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005205 * FCS SCN
5206 */
5207
5208#define FC_QOS_RSCN_EVENT 0x0c
5209#define FC_FABRIC_NAME_RSCN_EVENT 0x0d
5210
5211/*
5212 * forward declarations
5213 */
5214static void bfa_fcs_lport_scn_send_scr(void *scn_cbarg,
5215 struct bfa_fcxp_s *fcxp_alloced);
5216static void bfa_fcs_lport_scn_scr_response(void *fcsarg,
5217 struct bfa_fcxp_s *fcxp,
5218 void *cbarg,
5219 bfa_status_t req_status,
5220 u32 rsp_len,
5221 u32 resid_len,
5222 struct fchs_s *rsp_fchs);
5223static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5224 struct fchs_s *rx_fchs);
5225static void bfa_fcs_lport_scn_timeout(void *arg);
5226
Jing Huang5fbe25c2010-10-18 17:17:23 -07005227/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005228 * fcs_scm_sm FCS SCN state machine
5229 */
5230
Jing Huang5fbe25c2010-10-18 17:17:23 -07005231/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005232 * VPort SCN State Machine events
5233 */
5234enum port_scn_event {
5235 SCNSM_EVENT_PORT_ONLINE = 1,
5236 SCNSM_EVENT_PORT_OFFLINE = 2,
5237 SCNSM_EVENT_RSP_OK = 3,
5238 SCNSM_EVENT_RSP_ERROR = 4,
5239 SCNSM_EVENT_TIMEOUT = 5,
5240 SCNSM_EVENT_SCR_SENT = 6,
5241};
5242
5243static void bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
5244 enum port_scn_event event);
5245static void bfa_fcs_lport_scn_sm_sending_scr(
5246 struct bfa_fcs_lport_scn_s *scn,
5247 enum port_scn_event event);
5248static void bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
5249 enum port_scn_event event);
5250static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5251 enum port_scn_event event);
5252static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5253 enum port_scn_event event);
5254
Jing Huang5fbe25c2010-10-18 17:17:23 -07005255/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005256 * Starting state - awaiting link up.
5257 */
5258static void
5259bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
5260 enum port_scn_event event)
5261{
5262 switch (event) {
5263 case SCNSM_EVENT_PORT_ONLINE:
5264 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5265 bfa_fcs_lport_scn_send_scr(scn, NULL);
5266 break;
5267
5268 case SCNSM_EVENT_PORT_OFFLINE:
5269 break;
5270
5271 default:
5272 bfa_sm_fault(scn->port->fcs, event);
5273 }
5274}
5275
5276static void
5277bfa_fcs_lport_scn_sm_sending_scr(struct bfa_fcs_lport_scn_s *scn,
5278 enum port_scn_event event)
5279{
5280 switch (event) {
5281 case SCNSM_EVENT_SCR_SENT:
5282 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr);
5283 break;
5284
5285 case SCNSM_EVENT_PORT_OFFLINE:
5286 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5287 bfa_fcxp_walloc_cancel(scn->port->fcs->bfa, &scn->fcxp_wqe);
5288 break;
5289
5290 default:
5291 bfa_sm_fault(scn->port->fcs, event);
5292 }
5293}
5294
5295static void
5296bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
5297 enum port_scn_event event)
5298{
5299 struct bfa_fcs_lport_s *port = scn->port;
5300
5301 switch (event) {
5302 case SCNSM_EVENT_RSP_OK:
5303 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_online);
5304 break;
5305
5306 case SCNSM_EVENT_RSP_ERROR:
5307 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr_retry);
5308 bfa_timer_start(port->fcs->bfa, &scn->timer,
5309 bfa_fcs_lport_scn_timeout, scn,
5310 BFA_FCS_RETRY_TIMEOUT);
5311 break;
5312
5313 case SCNSM_EVENT_PORT_OFFLINE:
5314 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5315 bfa_fcxp_discard(scn->fcxp);
5316 break;
5317
5318 default:
5319 bfa_sm_fault(port->fcs, event);
5320 }
5321}
5322
5323static void
5324bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5325 enum port_scn_event event)
5326{
5327 switch (event) {
5328 case SCNSM_EVENT_TIMEOUT:
5329 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5330 bfa_fcs_lport_scn_send_scr(scn, NULL);
5331 break;
5332
5333 case SCNSM_EVENT_PORT_OFFLINE:
5334 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5335 bfa_timer_stop(&scn->timer);
5336 break;
5337
5338 default:
5339 bfa_sm_fault(scn->port->fcs, event);
5340 }
5341}
5342
5343static void
5344bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5345 enum port_scn_event event)
5346{
5347 switch (event) {
5348 case SCNSM_EVENT_PORT_OFFLINE:
5349 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5350 break;
5351
5352 default:
5353 bfa_sm_fault(scn->port->fcs, event);
5354 }
5355}
5356
5357
5358
Jing Huang5fbe25c2010-10-18 17:17:23 -07005359/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005360 * fcs_scn_private FCS SCN private functions
5361 */
5362
Jing Huang5fbe25c2010-10-18 17:17:23 -07005363/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005364 * This routine will be called to send a SCR command.
5365 */
5366static void
5367bfa_fcs_lport_scn_send_scr(void *scn_cbarg, struct bfa_fcxp_s *fcxp_alloced)
5368{
5369 struct bfa_fcs_lport_scn_s *scn = scn_cbarg;
5370 struct bfa_fcs_lport_s *port = scn->port;
5371 struct fchs_s fchs;
5372 int len;
5373 struct bfa_fcxp_s *fcxp;
5374
5375 bfa_trc(port->fcs, port->pid);
5376 bfa_trc(port->fcs, port->port_cfg.pwwn);
5377
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07005378 fcxp = fcxp_alloced ? fcxp_alloced :
5379 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005380 if (!fcxp) {
5381 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &scn->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07005382 bfa_fcs_lport_scn_send_scr, scn, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005383 return;
5384 }
5385 scn->fcxp = fcxp;
5386
5387 /* Handle VU registrations for Base port only */
5388 if ((!port->vport) && bfa_ioc_get_fcmode(&port->fcs->bfa->ioc)) {
5389 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf7f738122010-12-09 19:08:43 -08005390 port->fabric->lps->brcd_switch,
5391 port->pid, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005392 } else {
5393 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5394 BFA_FALSE,
5395 port->pid, 0);
5396 }
5397
5398 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5399 FC_CLASS_3, len, &fchs,
5400 bfa_fcs_lport_scn_scr_response,
5401 (void *)scn, FC_MAX_PDUSZ, FC_ELS_TOV);
5402
5403 bfa_sm_send_event(scn, SCNSM_EVENT_SCR_SENT);
5404}
5405
5406static void
5407bfa_fcs_lport_scn_scr_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
5408 void *cbarg, bfa_status_t req_status, u32 rsp_len,
5409 u32 resid_len, struct fchs_s *rsp_fchs)
5410{
5411 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) cbarg;
5412 struct bfa_fcs_lport_s *port = scn->port;
5413 struct fc_els_cmd_s *els_cmd;
5414 struct fc_ls_rjt_s *ls_rjt;
5415
5416 bfa_trc(port->fcs, port->port_cfg.pwwn);
5417
5418 /*
5419 * Sanity Checks
5420 */
5421 if (req_status != BFA_STATUS_OK) {
5422 bfa_trc(port->fcs, req_status);
5423 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5424 return;
5425 }
5426
5427 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
5428
5429 switch (els_cmd->els_code) {
5430
5431 case FC_ELS_ACC:
5432 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_OK);
5433 break;
5434
5435 case FC_ELS_LS_RJT:
5436
5437 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
5438
5439 bfa_trc(port->fcs, ls_rjt->reason_code);
5440 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
5441
5442 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5443 break;
5444
5445 default:
5446 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5447 }
5448}
5449
5450/*
5451 * Send a LS Accept
5452 */
5453static void
5454bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5455 struct fchs_s *rx_fchs)
5456{
5457 struct fchs_s fchs;
5458 struct bfa_fcxp_s *fcxp;
5459 struct bfa_rport_s *bfa_rport = NULL;
5460 int len;
5461
5462 bfa_trc(port->fcs, rx_fchs->s_id);
5463
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07005464 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005465 if (!fcxp)
5466 return;
5467
5468 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5469 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
5470 rx_fchs->ox_id);
5471
5472 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
5473 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
5474 FC_MAX_PDUSZ, 0);
5475}
5476
Jing Huang5fbe25c2010-10-18 17:17:23 -07005477/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005478 * This routine will be called by bfa_timer on timer timeouts.
5479 *
5480 * param[in] vport - pointer to bfa_fcs_lport_t.
5481 * param[out] vport_status - pointer to return vport status in
5482 *
5483 * return
5484 * void
5485 *
5486 * Special Considerations:
5487 *
5488 * note
5489 */
5490static void
5491bfa_fcs_lport_scn_timeout(void *arg)
5492{
5493 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) arg;
5494
5495 bfa_sm_send_event(scn, SCNSM_EVENT_TIMEOUT);
5496}
5497
5498
5499
Jing Huang5fbe25c2010-10-18 17:17:23 -07005500/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005501 * fcs_scn_public FCS state change notification public interfaces
5502 */
5503
5504/*
5505 * Functions called by port/fab
5506 */
5507void
5508bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s *port)
5509{
5510 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5511
5512 scn->port = port;
5513 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5514}
5515
5516void
5517bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s *port)
5518{
5519 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5520
5521 scn->port = port;
5522 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_OFFLINE);
5523}
5524
5525void
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07005526bfa_fcs_lport_fab_scn_online(struct bfa_fcs_lport_s *port)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005527{
5528 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5529
5530 scn->port = port;
5531 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_ONLINE);
5532}
5533
5534static void
5535bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s *port, u32 rpid)
5536{
5537 struct bfa_fcs_rport_s *rport;
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005538 struct bfa_fcs_fabric_s *fabric = port->fabric;
5539 struct bfa_fcs_vport_s *vport;
5540 struct list_head *qe;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005541
5542 bfa_trc(port->fcs, rpid);
5543
Jing Huang5fbe25c2010-10-18 17:17:23 -07005544 /*
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005545 * Ignore PID if it is of base port or of vports created on the
5546 * same base port. It is to avoid vports discovering base port or
5547 * other vports created on same base port as remote port
5548 */
5549 if (rpid == fabric->bport.pid)
5550 return;
5551
5552 list_for_each(qe, &fabric->vport_q) {
5553 vport = (struct bfa_fcs_vport_s *) qe;
5554 if (vport->lport.pid == rpid)
5555 return;
5556 }
5557 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005558 * If this is an unknown device, then it just came online.
5559 * Otherwise let rport handle the RSCN event.
5560 */
5561 rport = bfa_fcs_lport_get_rport_by_pid(port, rpid);
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -07005562 if (!rport)
5563 rport = bfa_fcs_lport_get_rport_by_old_pid(port, rpid);
5564
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005565 if (rport == NULL) {
5566 /*
5567 * If min cfg mode is enabled, we donot need to
5568 * discover any new rports.
5569 */
5570 if (!__fcs_min_cfg(port->fcs))
5571 rport = bfa_fcs_rport_create(port, rpid);
5572 } else
5573 bfa_fcs_rport_scn(rport);
5574}
5575
Jing Huang5fbe25c2010-10-18 17:17:23 -07005576/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005577 * rscn format based PID comparison
5578 */
5579#define __fc_pid_match(__c0, __c1, __fmt) \
5580 (((__fmt) == FC_RSCN_FORMAT_FABRIC) || \
5581 (((__fmt) == FC_RSCN_FORMAT_DOMAIN) && \
5582 ((__c0)[0] == (__c1)[0])) || \
5583 (((__fmt) == FC_RSCN_FORMAT_AREA) && \
5584 ((__c0)[0] == (__c1)[0]) && \
5585 ((__c0)[1] == (__c1)[1])))
5586
5587static void
5588bfa_fcs_lport_scn_multiport_rscn(struct bfa_fcs_lport_s *port,
5589 enum fc_rscn_format format,
5590 u32 rscn_pid)
5591{
5592 struct bfa_fcs_rport_s *rport;
5593 struct list_head *qe, *qe_next;
5594 u8 *c0, *c1;
5595
5596 bfa_trc(port->fcs, format);
5597 bfa_trc(port->fcs, rscn_pid);
5598
5599 c0 = (u8 *) &rscn_pid;
5600
5601 list_for_each_safe(qe, qe_next, &port->rport_q) {
5602 rport = (struct bfa_fcs_rport_s *) qe;
5603 c1 = (u8 *) &rport->pid;
5604 if (__fc_pid_match(c0, c1, format))
5605 bfa_fcs_rport_scn(rport);
5606 }
5607}
5608
5609
5610void
5611bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
5612 struct fchs_s *fchs, u32 len)
5613{
5614 struct fc_rscn_pl_s *rscn = (struct fc_rscn_pl_s *) (fchs + 1);
5615 int num_entries;
5616 u32 rscn_pid;
5617 bfa_boolean_t nsquery = BFA_FALSE, found;
5618 int i = 0, j;
5619
5620 num_entries =
Jing Huangba816ea2010-10-18 17:10:50 -07005621 (be16_to_cpu(rscn->payldlen) -
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005622 sizeof(u32)) / sizeof(rscn->event[0]);
5623
5624 bfa_trc(port->fcs, num_entries);
5625
5626 port->stats.num_rscn++;
5627
5628 bfa_fcs_lport_scn_send_ls_acc(port, fchs);
5629
5630 for (i = 0; i < num_entries; i++) {
5631 rscn_pid = rscn->event[i].portid;
5632
5633 bfa_trc(port->fcs, rscn->event[i].format);
5634 bfa_trc(port->fcs, rscn_pid);
5635
5636 /* check for duplicate entries in the list */
5637 found = BFA_FALSE;
5638 for (j = 0; j < i; j++) {
5639 if (rscn->event[j].portid == rscn_pid) {
5640 found = BFA_TRUE;
5641 break;
5642 }
5643 }
5644
5645 /* if found in down the list, pid has been already processed */
5646 if (found) {
5647 bfa_trc(port->fcs, rscn_pid);
5648 continue;
5649 }
5650
5651 switch (rscn->event[i].format) {
5652 case FC_RSCN_FORMAT_PORTID:
5653 if (rscn->event[i].qualifier == FC_QOS_RSCN_EVENT) {
5654 /*
5655 * Ignore this event.
5656 * f/w would have processed it
5657 */
5658 bfa_trc(port->fcs, rscn_pid);
5659 } else {
5660 port->stats.num_portid_rscn++;
5661 bfa_fcs_lport_scn_portid_rscn(port, rscn_pid);
5662 }
5663 break;
5664
5665 case FC_RSCN_FORMAT_FABRIC:
5666 if (rscn->event[i].qualifier ==
5667 FC_FABRIC_NAME_RSCN_EVENT) {
5668 bfa_fcs_lport_ms_fabric_rscn(port);
5669 break;
5670 }
5671 /* !!!!!!!!! Fall Through !!!!!!!!!!!!! */
5672
5673 case FC_RSCN_FORMAT_AREA:
5674 case FC_RSCN_FORMAT_DOMAIN:
5675 nsquery = BFA_TRUE;
5676 bfa_fcs_lport_scn_multiport_rscn(port,
5677 rscn->event[i].format,
5678 rscn_pid);
5679 break;
5680
5681
5682 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08005683 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005684 nsquery = BFA_TRUE;
5685 }
5686 }
5687
Jing Huang5fbe25c2010-10-18 17:17:23 -07005688 /*
5689 * If any of area, domain or fabric RSCN is received, do a fresh
5690 * discovery to find new devices.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005691 */
5692 if (nsquery)
5693 bfa_fcs_lport_ns_query(port);
5694}
5695
Jing Huang5fbe25c2010-10-18 17:17:23 -07005696/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005697 * BFA FCS port
5698 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07005699/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005700 * fcs_port_api BFA FCS port API
5701 */
5702struct bfa_fcs_lport_s *
5703bfa_fcs_get_base_port(struct bfa_fcs_s *fcs)
5704{
5705 return &fcs->fabric.bport;
5706}
5707
5708wwn_t
5709bfa_fcs_lport_get_rport(struct bfa_fcs_lport_s *port, wwn_t wwn, int index,
5710 int nrports, bfa_boolean_t bwwn)
5711{
5712 struct list_head *qh, *qe;
5713 struct bfa_fcs_rport_s *rport = NULL;
5714 int i;
5715 struct bfa_fcs_s *fcs;
5716
5717 if (port == NULL || nrports == 0)
5718 return (wwn_t) 0;
5719
5720 fcs = port->fcs;
5721 bfa_trc(fcs, (u32) nrports);
5722
5723 i = 0;
5724 qh = &port->rport_q;
5725 qe = bfa_q_first(qh);
5726
5727 while ((qe != qh) && (i < nrports)) {
5728 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf16a1752010-12-09 19:12:32 -08005729 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005730 qe = bfa_q_next(qe);
5731 bfa_trc(fcs, (u32) rport->pwwn);
5732 bfa_trc(fcs, rport->pid);
5733 bfa_trc(fcs, i);
5734 continue;
5735 }
5736
5737 if (bwwn) {
5738 if (!memcmp(&wwn, &rport->pwwn, 8))
5739 break;
5740 } else {
5741 if (i == index)
5742 break;
5743 }
5744
5745 i++;
5746 qe = bfa_q_next(qe);
5747 }
5748
5749 bfa_trc(fcs, i);
5750 if (rport)
5751 return rport->pwwn;
5752 else
5753 return (wwn_t) 0;
5754}
5755
5756void
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -07005757bfa_fcs_lport_get_rport_quals(struct bfa_fcs_lport_s *port,
5758 struct bfa_rport_qualifier_s rports[], int *nrports)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005759{
5760 struct list_head *qh, *qe;
5761 struct bfa_fcs_rport_s *rport = NULL;
5762 int i;
5763 struct bfa_fcs_s *fcs;
5764
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -07005765 if (port == NULL || rports == NULL || *nrports == 0)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005766 return;
5767
5768 fcs = port->fcs;
5769 bfa_trc(fcs, (u32) *nrports);
5770
5771 i = 0;
5772 qh = &port->rport_q;
5773 qe = bfa_q_first(qh);
5774
5775 while ((qe != qh) && (i < *nrports)) {
5776 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf16a1752010-12-09 19:12:32 -08005777 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005778 qe = bfa_q_next(qe);
5779 bfa_trc(fcs, (u32) rport->pwwn);
5780 bfa_trc(fcs, rport->pid);
5781 bfa_trc(fcs, i);
5782 continue;
5783 }
5784
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -07005785 if (!rport->pwwn && !rport->pid) {
5786 qe = bfa_q_next(qe);
5787 continue;
5788 }
5789
5790 rports[i].pwwn = rport->pwwn;
5791 rports[i].pid = rport->pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005792
5793 i++;
5794 qe = bfa_q_next(qe);
5795 }
5796
5797 bfa_trc(fcs, i);
5798 *nrports = i;
5799}
5800
5801/*
5802 * Iterate's through all the rport's in the given port to
5803 * determine the maximum operating speed.
5804 *
5805 * !!!! To be used in TRL Functionality only !!!!
5806 */
5807bfa_port_speed_t
5808bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t *port)
5809{
5810 struct list_head *qh, *qe;
5811 struct bfa_fcs_rport_s *rport = NULL;
5812 struct bfa_fcs_s *fcs;
5813 bfa_port_speed_t max_speed = 0;
5814 struct bfa_port_attr_s port_attr;
5815 bfa_port_speed_t port_speed, rport_speed;
5816 bfa_boolean_t trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
5817
5818
5819 if (port == NULL)
5820 return 0;
5821
5822 fcs = port->fcs;
5823
5824 /* Get Physical port's current speed */
5825 bfa_fcport_get_attr(port->fcs->bfa, &port_attr);
5826 port_speed = port_attr.speed;
5827 bfa_trc(fcs, port_speed);
5828
5829 qh = &port->rport_q;
5830 qe = bfa_q_first(qh);
5831
5832 while (qe != qh) {
5833 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf16a1752010-12-09 19:12:32 -08005834 if ((bfa_ntoh3b(rport->pid) > 0xFFF000) ||
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07005835 (bfa_fcs_rport_get_state(rport) == BFA_RPORT_OFFLINE) ||
5836 (rport->scsi_function != BFA_RPORT_TARGET)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005837 qe = bfa_q_next(qe);
5838 continue;
5839 }
5840
5841 rport_speed = rport->rpf.rpsc_speed;
5842 if ((trl_enabled) && (rport_speed ==
5843 BFA_PORT_SPEED_UNKNOWN)) {
5844 /* Use default ratelim speed setting */
5845 rport_speed =
5846 bfa_fcport_get_ratelim_speed(port->fcs->bfa);
5847 }
5848
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07005849 if (rport_speed > max_speed)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005850 max_speed = rport_speed;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005851
5852 qe = bfa_q_next(qe);
5853 }
5854
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07005855 if (max_speed > port_speed)
5856 max_speed = port_speed;
5857
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005858 bfa_trc(fcs, max_speed);
5859 return max_speed;
5860}
5861
5862struct bfa_fcs_lport_s *
5863bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
5864{
5865 struct bfa_fcs_vport_s *vport;
5866 bfa_fcs_vf_t *vf;
5867
Jing Huangd4b671c2010-12-26 21:46:35 -08005868 WARN_ON(fcs == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005869
5870 vf = bfa_fcs_vf_lookup(fcs, vf_id);
5871 if (vf == NULL) {
5872 bfa_trc(fcs, vf_id);
5873 return NULL;
5874 }
5875
5876 if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
5877 return &vf->bport;
5878
5879 vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
5880 if (vport)
5881 return &vport->lport;
5882
5883 return NULL;
5884}
5885
5886/*
5887 * API corresponding to NPIV_VPORT_GETINFO.
5888 */
5889void
5890bfa_fcs_lport_get_info(struct bfa_fcs_lport_s *port,
5891 struct bfa_lport_info_s *port_info)
5892{
5893
5894 bfa_trc(port->fcs, port->fabric->fabric_name);
5895
5896 if (port->vport == NULL) {
5897 /*
5898 * This is a Physical port
5899 */
5900 port_info->port_type = BFA_LPORT_TYPE_PHYSICAL;
5901
5902 /*
5903 * @todo : need to fix the state & reason
5904 */
5905 port_info->port_state = 0;
5906 port_info->offline_reason = 0;
5907
5908 port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
5909 port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
5910
5911 port_info->max_vports_supp =
5912 bfa_lps_get_max_vport(port->fcs->bfa);
5913 port_info->num_vports_inuse =
Maggie Zhangf7f738122010-12-09 19:08:43 -08005914 port->fabric->num_vports;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005915 port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
5916 port_info->num_rports_inuse = port->num_rports;
5917 } else {
5918 /*
5919 * This is a virtual port
5920 */
5921 port_info->port_type = BFA_LPORT_TYPE_VIRTUAL;
5922
5923 /*
5924 * @todo : need to fix the state & reason
5925 */
5926 port_info->port_state = 0;
5927 port_info->offline_reason = 0;
5928
5929 port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
5930 port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
5931 }
5932}
5933
5934void
5935bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s *fcs_port,
5936 struct bfa_lport_stats_s *port_stats)
5937{
5938 *port_stats = fcs_port->stats;
5939}
5940
5941void
5942bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port)
5943{
Jing Huang6a18b162010-10-18 17:08:54 -07005944 memset(&fcs_port->stats, 0, sizeof(struct bfa_lport_stats_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005945}
5946
Jing Huang5fbe25c2010-10-18 17:17:23 -07005947/*
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07005948 * Let new loop map create missing rports
5949 */
5950void
5951bfa_fcs_lport_lip_scn_online(struct bfa_fcs_lport_s *port)
5952{
5953 bfa_fcs_lport_loop_online(port);
5954}
5955
5956/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005957 * FCS virtual port state machine
5958 */
5959
5960#define __vport_fcs(__vp) ((__vp)->lport.fcs)
5961#define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
5962#define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
5963#define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
5964#define __vport_fcid(__vp) ((__vp)->lport.pid)
5965#define __vport_fabric(__vp) ((__vp)->lport.fabric)
5966#define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
5967
5968#define BFA_FCS_VPORT_MAX_RETRIES 5
5969/*
5970 * Forward declarations
5971 */
5972static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport);
5973static void bfa_fcs_vport_timeout(void *vport_arg);
5974static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
5975static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
5976
Jing Huang5fbe25c2010-10-18 17:17:23 -07005977/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005978 * fcs_vport_sm FCS virtual port state machine
5979 */
5980
Jing Huang5fbe25c2010-10-18 17:17:23 -07005981/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005982 * VPort State Machine events
5983 */
5984enum bfa_fcs_vport_event {
5985 BFA_FCS_VPORT_SM_CREATE = 1, /* vport create event */
5986 BFA_FCS_VPORT_SM_DELETE = 2, /* vport delete event */
5987 BFA_FCS_VPORT_SM_START = 3, /* vport start request */
5988 BFA_FCS_VPORT_SM_STOP = 4, /* stop: unsupported */
5989 BFA_FCS_VPORT_SM_ONLINE = 5, /* fabric online */
5990 BFA_FCS_VPORT_SM_OFFLINE = 6, /* fabric offline event */
5991 BFA_FCS_VPORT_SM_FRMSENT = 7, /* fdisc/logo sent events */
5992 BFA_FCS_VPORT_SM_RSP_OK = 8, /* good response */
5993 BFA_FCS_VPORT_SM_RSP_ERROR = 9, /* error/bad response */
5994 BFA_FCS_VPORT_SM_TIMEOUT = 10, /* delay timer event */
5995 BFA_FCS_VPORT_SM_DELCOMP = 11, /* lport delete completion */
5996 BFA_FCS_VPORT_SM_RSP_DUP_WWN = 12, /* Dup wnn error*/
5997 BFA_FCS_VPORT_SM_RSP_FAILED = 13, /* non-retryable failure */
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07005998 BFA_FCS_VPORT_SM_STOPCOMP = 14, /* vport delete completion */
Vijaya Mohan Guvvaf2a0cc32013-05-13 02:33:25 -07005999 BFA_FCS_VPORT_SM_FABRIC_MAX = 15, /* max vports on fabric */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006000};
6001
6002static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
6003 enum bfa_fcs_vport_event event);
6004static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
6005 enum bfa_fcs_vport_event event);
6006static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
6007 enum bfa_fcs_vport_event event);
6008static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
6009 enum bfa_fcs_vport_event event);
6010static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
6011 enum bfa_fcs_vport_event event);
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07006012static void bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
6013 enum bfa_fcs_vport_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006014static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
6015 enum bfa_fcs_vport_event event);
6016static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
6017 enum bfa_fcs_vport_event event);
6018static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
6019 enum bfa_fcs_vport_event event);
6020static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
6021 enum bfa_fcs_vport_event event);
6022static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
6023 enum bfa_fcs_vport_event event);
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07006024static void bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
6025 enum bfa_fcs_vport_event event);
6026static void bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
6027 enum bfa_fcs_vport_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006028
6029static struct bfa_sm_table_s vport_sm_table[] = {
6030 {BFA_SM(bfa_fcs_vport_sm_uninit), BFA_FCS_VPORT_UNINIT},
6031 {BFA_SM(bfa_fcs_vport_sm_created), BFA_FCS_VPORT_CREATED},
6032 {BFA_SM(bfa_fcs_vport_sm_offline), BFA_FCS_VPORT_OFFLINE},
6033 {BFA_SM(bfa_fcs_vport_sm_fdisc), BFA_FCS_VPORT_FDISC},
6034 {BFA_SM(bfa_fcs_vport_sm_fdisc_retry), BFA_FCS_VPORT_FDISC_RETRY},
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07006035 {BFA_SM(bfa_fcs_vport_sm_fdisc_rsp_wait), BFA_FCS_VPORT_FDISC_RSP_WAIT},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006036 {BFA_SM(bfa_fcs_vport_sm_online), BFA_FCS_VPORT_ONLINE},
6037 {BFA_SM(bfa_fcs_vport_sm_deleting), BFA_FCS_VPORT_DELETING},
6038 {BFA_SM(bfa_fcs_vport_sm_cleanup), BFA_FCS_VPORT_CLEANUP},
6039 {BFA_SM(bfa_fcs_vport_sm_logo), BFA_FCS_VPORT_LOGO},
6040 {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
6041};
6042
Jing Huang5fbe25c2010-10-18 17:17:23 -07006043/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006044 * Beginning state.
6045 */
6046static void
6047bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
6048 enum bfa_fcs_vport_event event)
6049{
6050 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6051 bfa_trc(__vport_fcs(vport), event);
6052
6053 switch (event) {
6054 case BFA_FCS_VPORT_SM_CREATE:
6055 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6056 bfa_fcs_fabric_addvport(__vport_fabric(vport), vport);
6057 break;
6058
6059 default:
6060 bfa_sm_fault(__vport_fcs(vport), event);
6061 }
6062}
6063
Jing Huang5fbe25c2010-10-18 17:17:23 -07006064/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006065 * Created state - a start event is required to start up the state machine.
6066 */
6067static void
6068bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
6069 enum bfa_fcs_vport_event event)
6070{
6071 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6072 bfa_trc(__vport_fcs(vport), event);
6073
6074 switch (event) {
6075 case BFA_FCS_VPORT_SM_START:
Maggie Zhangf7f738122010-12-09 19:08:43 -08006076 if (bfa_sm_cmp_state(__vport_fabric(vport),
6077 bfa_fcs_fabric_sm_online)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006078 && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport))) {
6079 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6080 bfa_fcs_vport_do_fdisc(vport);
6081 } else {
Jing Huang5fbe25c2010-10-18 17:17:23 -07006082 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006083 * Fabric is offline or not NPIV capable, stay in
6084 * offline state.
6085 */
6086 vport->vport_stats.fab_no_npiv++;
6087 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6088 }
6089 break;
6090
6091 case BFA_FCS_VPORT_SM_DELETE:
6092 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6093 bfa_fcs_lport_delete(&vport->lport);
6094 break;
6095
6096 case BFA_FCS_VPORT_SM_ONLINE:
6097 case BFA_FCS_VPORT_SM_OFFLINE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07006098 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006099 * Ignore ONLINE/OFFLINE events from fabric
6100 * till vport is started.
6101 */
6102 break;
6103
6104 default:
6105 bfa_sm_fault(__vport_fcs(vport), event);
6106 }
6107}
6108
Jing Huang5fbe25c2010-10-18 17:17:23 -07006109/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006110 * Offline state - awaiting ONLINE event from fabric SM.
6111 */
6112static void
6113bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
6114 enum bfa_fcs_vport_event event)
6115{
6116 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6117 bfa_trc(__vport_fcs(vport), event);
6118
6119 switch (event) {
6120 case BFA_FCS_VPORT_SM_DELETE:
6121 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6122 bfa_fcs_lport_delete(&vport->lport);
6123 break;
6124
6125 case BFA_FCS_VPORT_SM_ONLINE:
6126 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6127 vport->fdisc_retries = 0;
6128 bfa_fcs_vport_do_fdisc(vport);
6129 break;
6130
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07006131 case BFA_FCS_VPORT_SM_STOP:
6132 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6133 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
6134 break;
6135
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006136 case BFA_FCS_VPORT_SM_OFFLINE:
6137 /*
6138 * This can happen if the vport couldn't be initialzied
6139 * due the fact that the npiv was not enabled on the switch.
6140 * In that case we will put the vport in offline state.
6141 * However, the link can go down and cause the this event to
6142 * be sent when we are already offline. Ignore it.
6143 */
6144 break;
6145
6146 default:
6147 bfa_sm_fault(__vport_fcs(vport), event);
6148 }
6149}
6150
6151
Jing Huang5fbe25c2010-10-18 17:17:23 -07006152/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006153 * FDISC is sent and awaiting reply from fabric.
6154 */
6155static void
6156bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
6157 enum bfa_fcs_vport_event event)
6158{
6159 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6160 bfa_trc(__vport_fcs(vport), event);
6161
6162 switch (event) {
6163 case BFA_FCS_VPORT_SM_DELETE:
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07006164 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_rsp_wait);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006165 break;
6166
6167 case BFA_FCS_VPORT_SM_OFFLINE:
6168 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
Maggie Zhangf7f738122010-12-09 19:08:43 -08006169 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006170 break;
6171
6172 case BFA_FCS_VPORT_SM_RSP_OK:
6173 bfa_sm_set_state(vport, bfa_fcs_vport_sm_online);
6174 bfa_fcs_lport_online(&vport->lport);
6175 break;
6176
6177 case BFA_FCS_VPORT_SM_RSP_ERROR:
6178 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_retry);
6179 bfa_timer_start(__vport_bfa(vport), &vport->timer,
6180 bfa_fcs_vport_timeout, vport,
6181 BFA_FCS_RETRY_TIMEOUT);
6182 break;
6183
6184 case BFA_FCS_VPORT_SM_RSP_FAILED:
Vijaya Mohan Guvvaf2a0cc32013-05-13 02:33:25 -07006185 case BFA_FCS_VPORT_SM_FABRIC_MAX:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006186 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6187 break;
6188
6189 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
6190 bfa_sm_set_state(vport, bfa_fcs_vport_sm_error);
6191 break;
6192
6193 default:
6194 bfa_sm_fault(__vport_fcs(vport), event);
6195 }
6196}
6197
Jing Huang5fbe25c2010-10-18 17:17:23 -07006198/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006199 * FDISC attempt failed - a timer is active to retry FDISC.
6200 */
6201static void
6202bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
6203 enum bfa_fcs_vport_event event)
6204{
6205 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6206 bfa_trc(__vport_fcs(vport), event);
6207
6208 switch (event) {
6209 case BFA_FCS_VPORT_SM_DELETE:
6210 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6211 bfa_timer_stop(&vport->timer);
6212 bfa_fcs_lport_delete(&vport->lport);
6213 break;
6214
6215 case BFA_FCS_VPORT_SM_OFFLINE:
6216 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6217 bfa_timer_stop(&vport->timer);
6218 break;
6219
6220 case BFA_FCS_VPORT_SM_TIMEOUT:
6221 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6222 vport->vport_stats.fdisc_retries++;
6223 vport->fdisc_retries++;
6224 bfa_fcs_vport_do_fdisc(vport);
6225 break;
6226
6227 default:
6228 bfa_sm_fault(__vport_fcs(vport), event);
6229 }
6230}
6231
Jing Huang5fbe25c2010-10-18 17:17:23 -07006232/*
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07006233 * FDISC is in progress and we got a vport delete request -
6234 * this is a wait state while we wait for fdisc response and
6235 * we will transition to the appropriate state - on rsp status.
6236 */
6237static void
6238bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
6239 enum bfa_fcs_vport_event event)
6240{
6241 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6242 bfa_trc(__vport_fcs(vport), event);
6243
6244 switch (event) {
6245 case BFA_FCS_VPORT_SM_RSP_OK:
6246 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
6247 bfa_fcs_lport_delete(&vport->lport);
6248 break;
6249
6250 case BFA_FCS_VPORT_SM_DELETE:
6251 break;
6252
6253 case BFA_FCS_VPORT_SM_OFFLINE:
6254 case BFA_FCS_VPORT_SM_RSP_ERROR:
6255 case BFA_FCS_VPORT_SM_RSP_FAILED:
Vijaya Mohan Guvvaf2a0cc32013-05-13 02:33:25 -07006256 case BFA_FCS_VPORT_SM_FABRIC_MAX:
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07006257 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
6258 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6259 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6260 bfa_fcs_lport_delete(&vport->lport);
6261 break;
6262
6263 default:
6264 bfa_sm_fault(__vport_fcs(vport), event);
6265 }
6266}
6267
6268/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006269 * Vport is online (FDISC is complete).
6270 */
6271static void
6272bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
6273 enum bfa_fcs_vport_event event)
6274{
6275 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6276 bfa_trc(__vport_fcs(vport), event);
6277
6278 switch (event) {
6279 case BFA_FCS_VPORT_SM_DELETE:
6280 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
6281 bfa_fcs_lport_delete(&vport->lport);
6282 break;
6283
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07006284 case BFA_FCS_VPORT_SM_STOP:
6285 bfa_sm_set_state(vport, bfa_fcs_vport_sm_stopping);
6286 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
6287 break;
6288
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006289 case BFA_FCS_VPORT_SM_OFFLINE:
6290 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
Maggie Zhangf7f738122010-12-09 19:08:43 -08006291 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006292 bfa_fcs_lport_offline(&vport->lport);
6293 break;
6294
6295 default:
6296 bfa_sm_fault(__vport_fcs(vport), event);
6297 }
6298}
6299
Jing Huang5fbe25c2010-10-18 17:17:23 -07006300/*
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07006301 * Vport is being stopped - awaiting lport stop completion to send
6302 * LOGO to fabric.
6303 */
6304static void
6305bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
6306 enum bfa_fcs_vport_event event)
6307{
6308 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6309 bfa_trc(__vport_fcs(vport), event);
6310
6311 switch (event) {
6312 case BFA_FCS_VPORT_SM_STOPCOMP:
6313 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo_for_stop);
6314 bfa_fcs_vport_do_logo(vport);
6315 break;
6316
6317 case BFA_FCS_VPORT_SM_OFFLINE:
6318 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6319 break;
6320
6321 default:
6322 bfa_sm_fault(__vport_fcs(vport), event);
6323 }
6324}
6325
6326/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006327 * Vport is being deleted - awaiting lport delete completion to send
6328 * LOGO to fabric.
6329 */
6330static void
6331bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
6332 enum bfa_fcs_vport_event event)
6333{
6334 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6335 bfa_trc(__vport_fcs(vport), event);
6336
6337 switch (event) {
6338 case BFA_FCS_VPORT_SM_DELETE:
6339 break;
6340
6341 case BFA_FCS_VPORT_SM_DELCOMP:
6342 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
6343 bfa_fcs_vport_do_logo(vport);
6344 break;
6345
6346 case BFA_FCS_VPORT_SM_OFFLINE:
6347 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6348 break;
6349
6350 default:
6351 bfa_sm_fault(__vport_fcs(vport), event);
6352 }
6353}
6354
Jing Huang5fbe25c2010-10-18 17:17:23 -07006355/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006356 * Error State.
6357 * This state will be set when the Vport Creation fails due
6358 * to errors like Dup WWN. In this state only operation allowed
6359 * is a Vport Delete.
6360 */
6361static void
6362bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
6363 enum bfa_fcs_vport_event event)
6364{
6365 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6366 bfa_trc(__vport_fcs(vport), event);
6367
6368 switch (event) {
6369 case BFA_FCS_VPORT_SM_DELETE:
6370 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6371 bfa_fcs_lport_delete(&vport->lport);
6372 break;
6373
6374 default:
6375 bfa_trc(__vport_fcs(vport), event);
6376 }
6377}
6378
Jing Huang5fbe25c2010-10-18 17:17:23 -07006379/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006380 * Lport cleanup is in progress since vport is being deleted. Fabric is
6381 * offline, so no LOGO is needed to complete vport deletion.
6382 */
6383static void
6384bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
6385 enum bfa_fcs_vport_event event)
6386{
6387 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6388 bfa_trc(__vport_fcs(vport), event);
6389
6390 switch (event) {
6391 case BFA_FCS_VPORT_SM_DELCOMP:
6392 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6393 bfa_fcs_vport_free(vport);
6394 break;
6395
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07006396 case BFA_FCS_VPORT_SM_STOPCOMP:
6397 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6398 break;
6399
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006400 case BFA_FCS_VPORT_SM_DELETE:
6401 break;
6402
6403 default:
6404 bfa_sm_fault(__vport_fcs(vport), event);
6405 }
6406}
6407
Jing Huang5fbe25c2010-10-18 17:17:23 -07006408/*
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07006409 * LOGO is sent to fabric. Vport stop is in progress. Lport stop cleanup
6410 * is done.
6411 */
6412static void
6413bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
6414 enum bfa_fcs_vport_event event)
6415{
6416 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6417 bfa_trc(__vport_fcs(vport), event);
6418
6419 switch (event) {
6420 case BFA_FCS_VPORT_SM_OFFLINE:
6421 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6422 /*
6423 * !!! fall through !!!
6424 */
6425
6426 case BFA_FCS_VPORT_SM_RSP_OK:
6427 case BFA_FCS_VPORT_SM_RSP_ERROR:
6428 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6429 break;
6430
6431 default:
6432 bfa_sm_fault(__vport_fcs(vport), event);
6433 }
6434}
6435
6436/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006437 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
6438 * is done.
6439 */
6440static void
6441bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
6442 enum bfa_fcs_vport_event event)
6443{
6444 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6445 bfa_trc(__vport_fcs(vport), event);
6446
6447 switch (event) {
6448 case BFA_FCS_VPORT_SM_OFFLINE:
Maggie Zhangf7f738122010-12-09 19:08:43 -08006449 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006450 /*
6451 * !!! fall through !!!
6452 */
6453
6454 case BFA_FCS_VPORT_SM_RSP_OK:
6455 case BFA_FCS_VPORT_SM_RSP_ERROR:
6456 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6457 bfa_fcs_vport_free(vport);
6458 break;
6459
6460 case BFA_FCS_VPORT_SM_DELETE:
6461 break;
6462
6463 default:
6464 bfa_sm_fault(__vport_fcs(vport), event);
6465 }
6466}
6467
6468
6469
Jing Huang5fbe25c2010-10-18 17:17:23 -07006470/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006471 * fcs_vport_private FCS virtual port private functions
6472 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07006473/*
Krishna Gudipati7826f302011-07-20 16:59:13 -07006474 * Send AEN notification
6475 */
6476static void
6477bfa_fcs_vport_aen_post(struct bfa_fcs_lport_s *port,
6478 enum bfa_lport_aen_event event)
6479{
6480 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
6481 struct bfa_aen_entry_s *aen_entry;
6482
6483 bfad_get_aen_entry(bfad, aen_entry);
6484 if (!aen_entry)
6485 return;
6486
6487 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
6488 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
6489 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
6490 bfa_fcs_get_base_port(port->fcs));
6491 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
6492
6493 /* Send the AEN notification */
6494 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
6495 BFA_AEN_CAT_LPORT, event);
6496}
6497
6498/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006499 * This routine will be called to send a FDISC command.
6500 */
6501static void
6502bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
6503{
6504 bfa_lps_fdisc(vport->lps, vport,
6505 bfa_fcport_get_maxfrsize(__vport_bfa(vport)),
6506 __vport_pwwn(vport), __vport_nwwn(vport));
6507 vport->vport_stats.fdisc_sent++;
6508}
6509
6510static void
6511bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
6512{
Maggie Zhangf7f738122010-12-09 19:08:43 -08006513 u8 lsrjt_rsn = vport->lps->lsrjt_rsn;
6514 u8 lsrjt_expl = vport->lps->lsrjt_expl;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006515
6516 bfa_trc(__vport_fcs(vport), lsrjt_rsn);
6517 bfa_trc(__vport_fcs(vport), lsrjt_expl);
6518
6519 /* For certain reason codes, we don't want to retry. */
Maggie Zhangf7f738122010-12-09 19:08:43 -08006520 switch (vport->lps->lsrjt_expl) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006521 case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
6522 case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
6523 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6524 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
Krishna Gudipati7826f302011-07-20 16:59:13 -07006525 else {
6526 bfa_fcs_vport_aen_post(&vport->lport,
6527 BFA_LPORT_AEN_NPIV_DUP_WWN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006528 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
Krishna Gudipati7826f302011-07-20 16:59:13 -07006529 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006530 break;
6531
6532 case FC_LS_RJT_EXP_INSUFF_RES:
6533 /*
6534 * This means max logins per port/switch setting on the
6535 * switch was exceeded.
6536 */
6537 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6538 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
Krishna Gudipati7826f302011-07-20 16:59:13 -07006539 else {
6540 bfa_fcs_vport_aen_post(&vport->lport,
6541 BFA_LPORT_AEN_NPIV_FABRIC_MAX);
Vijaya Mohan Guvvaf2a0cc32013-05-13 02:33:25 -07006542 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_FABRIC_MAX);
Krishna Gudipati7826f302011-07-20 16:59:13 -07006543 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006544 break;
6545
6546 default:
Krishna Gudipati7826f302011-07-20 16:59:13 -07006547 if (vport->fdisc_retries == 0)
6548 bfa_fcs_vport_aen_post(&vport->lport,
6549 BFA_LPORT_AEN_NPIV_UNKNOWN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006550 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6551 }
6552}
6553
Jing Huang5fbe25c2010-10-18 17:17:23 -07006554/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006555 * Called to send a logout to the fabric. Used when a V-Port is
6556 * deleted/stopped.
6557 */
6558static void
6559bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
6560{
6561 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6562
6563 vport->vport_stats.logo_sent++;
6564 bfa_lps_fdisclogo(vport->lps);
6565}
6566
6567
Jing Huang5fbe25c2010-10-18 17:17:23 -07006568/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006569 * This routine will be called by bfa_timer on timer timeouts.
6570 *
6571 * param[in] vport - pointer to bfa_fcs_vport_t.
6572 * param[out] vport_status - pointer to return vport status in
6573 *
6574 * return
6575 * void
6576 *
6577 * Special Considerations:
6578 *
6579 * note
6580 */
6581static void
6582bfa_fcs_vport_timeout(void *vport_arg)
6583{
6584 struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *) vport_arg;
6585
6586 vport->vport_stats.fdisc_timeouts++;
6587 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
6588}
6589
6590static void
6591bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
6592{
6593 struct bfad_vport_s *vport_drv =
6594 (struct bfad_vport_s *)vport->vport_drv;
6595
6596 bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006597 bfa_lps_delete(vport->lps);
Krishna Gudipati17c201b2012-04-09 18:40:01 -07006598
6599 if (vport_drv->comp_del) {
6600 complete(vport_drv->comp_del);
6601 return;
6602 }
6603
6604 /*
6605 * We queue the vport delete work to the IM work_q from here.
6606 * The memory for the bfad_vport_s is freed from the FC function
6607 * template vport_delete entry point.
6608 */
Krishna Gudipati529f9a72012-07-13 16:08:22 -07006609 bfad_im_port_delete(vport_drv->drv_port.bfad, &vport_drv->drv_port);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006610}
6611
Jing Huang5fbe25c2010-10-18 17:17:23 -07006612/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006613 * fcs_vport_public FCS virtual port public interfaces
6614 */
6615
Jing Huang5fbe25c2010-10-18 17:17:23 -07006616/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006617 * Online notification from fabric SM.
6618 */
6619void
6620bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
6621{
6622 vport->vport_stats.fab_online++;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07006623 if (bfa_fcs_fabric_npiv_capable(__vport_fabric(vport)))
6624 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
6625 else
6626 vport->vport_stats.fab_no_npiv++;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006627}
6628
Jing Huang5fbe25c2010-10-18 17:17:23 -07006629/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006630 * Offline notification from fabric SM.
6631 */
6632void
6633bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
6634{
6635 vport->vport_stats.fab_offline++;
6636 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6637}
6638
Jing Huang5fbe25c2010-10-18 17:17:23 -07006639/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006640 * Cleanup notification from fabric SM on link timer expiry.
6641 */
6642void
6643bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
6644{
6645 vport->vport_stats.fab_cleanup++;
6646}
Krishna Gudipati881c1b32012-08-22 19:52:02 -07006647
6648/*
6649 * Stop notification from fabric SM. To be invoked from within FCS.
6650 */
6651void
6652bfa_fcs_vport_fcs_stop(struct bfa_fcs_vport_s *vport)
6653{
6654 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6655}
6656
Jing Huang5fbe25c2010-10-18 17:17:23 -07006657/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006658 * delete notification from fabric SM. To be invoked from within FCS.
6659 */
6660void
6661bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport)
6662{
6663 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6664}
6665
Jing Huang5fbe25c2010-10-18 17:17:23 -07006666/*
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07006667 * Stop completion callback from associated lport
6668 */
6669void
6670bfa_fcs_vport_stop_comp(struct bfa_fcs_vport_s *vport)
6671{
6672 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOPCOMP);
6673}
6674
6675/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006676 * Delete completion callback from associated lport
6677 */
6678void
6679bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
6680{
6681 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
6682}
6683
6684
6685
Jing Huang5fbe25c2010-10-18 17:17:23 -07006686/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006687 * fcs_vport_api Virtual port API
6688 */
6689
Jing Huang5fbe25c2010-10-18 17:17:23 -07006690/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006691 * Use this function to instantiate a new FCS vport object. This
6692 * function will not trigger any HW initialization process (which will be
6693 * done in vport_start() call)
6694 *
6695 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6696 * needs to be allocated by the driver.
6697 * param[in] fcs - FCS instance
6698 * param[in] vport_cfg - vport configuration
6699 * param[in] vf_id - VF_ID if vport is created within a VF.
6700 * FC_VF_ID_NULL to specify base fabric.
6701 * param[in] vport_drv - Opaque handle back to the driver's vport
6702 * structure
6703 *
6704 * retval BFA_STATUS_OK - on success.
6705 * retval BFA_STATUS_FAILED - on failure.
6706 */
6707bfa_status_t
6708bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6709 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6710 struct bfad_vport_s *vport_drv)
6711{
6712 if (vport_cfg->pwwn == 0)
6713 return BFA_STATUS_INVALID_WWN;
6714
6715 if (bfa_fcs_lport_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
6716 return BFA_STATUS_VPORT_WWN_BP;
6717
6718 if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
6719 return BFA_STATUS_VPORT_EXISTS;
6720
Maggie Zhangf7f738122010-12-09 19:08:43 -08006721 if (fcs->fabric.num_vports ==
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006722 bfa_lps_get_max_vport(fcs->bfa))
6723 return BFA_STATUS_VPORT_MAX;
6724
6725 vport->lps = bfa_lps_alloc(fcs->bfa);
6726 if (!vport->lps)
6727 return BFA_STATUS_VPORT_MAX;
6728
6729 vport->vport_drv = vport_drv;
6730 vport_cfg->preboot_vp = BFA_FALSE;
6731
6732 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6733 bfa_fcs_lport_attach(&vport->lport, fcs, vf_id, vport);
6734 bfa_fcs_lport_init(&vport->lport, vport_cfg);
6735 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
6736
6737 return BFA_STATUS_OK;
6738}
6739
Jing Huang5fbe25c2010-10-18 17:17:23 -07006740/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006741 * Use this function to instantiate a new FCS PBC vport object. This
6742 * function will not trigger any HW initialization process (which will be
6743 * done in vport_start() call)
6744 *
6745 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6746 * needs to be allocated by the driver.
6747 * param[in] fcs - FCS instance
6748 * param[in] vport_cfg - vport configuration
6749 * param[in] vf_id - VF_ID if vport is created within a VF.
6750 * FC_VF_ID_NULL to specify base fabric.
6751 * param[in] vport_drv - Opaque handle back to the driver's vport
6752 * structure
6753 *
6754 * retval BFA_STATUS_OK - on success.
6755 * retval BFA_STATUS_FAILED - on failure.
6756 */
6757bfa_status_t
6758bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6759 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6760 struct bfad_vport_s *vport_drv)
6761{
6762 bfa_status_t rc;
6763
6764 rc = bfa_fcs_vport_create(vport, fcs, vf_id, vport_cfg, vport_drv);
6765 vport->lport.port_cfg.preboot_vp = BFA_TRUE;
6766
6767 return rc;
6768}
6769
Jing Huang5fbe25c2010-10-18 17:17:23 -07006770/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006771 * Use this function to findout if this is a pbc vport or not.
6772 *
6773 * @param[in] vport - pointer to bfa_fcs_vport_t.
6774 *
6775 * @returns None
6776 */
6777bfa_boolean_t
6778bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s *vport)
6779{
6780
6781 if (vport && (vport->lport.port_cfg.preboot_vp == BFA_TRUE))
6782 return BFA_TRUE;
6783 else
6784 return BFA_FALSE;
6785
6786}
6787
Jing Huang5fbe25c2010-10-18 17:17:23 -07006788/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006789 * Use this function initialize the vport.
6790 *
6791 * @param[in] vport - pointer to bfa_fcs_vport_t.
6792 *
6793 * @returns None
6794 */
6795bfa_status_t
6796bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
6797{
6798 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
6799
6800 return BFA_STATUS_OK;
6801}
6802
Jing Huang5fbe25c2010-10-18 17:17:23 -07006803/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006804 * Use this function quiese the vport object. This function will return
6805 * immediately, when the vport is actually stopped, the
6806 * bfa_drv_vport_stop_cb() will be called.
6807 *
6808 * param[in] vport - pointer to bfa_fcs_vport_t.
6809 *
6810 * return None
6811 */
6812bfa_status_t
6813bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
6814{
6815 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6816
6817 return BFA_STATUS_OK;
6818}
6819
Jing Huang5fbe25c2010-10-18 17:17:23 -07006820/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006821 * Use this function to delete a vport object. Fabric object should
6822 * be stopped before this function call.
6823 *
6824 * !!!!!!! Donot invoke this from within FCS !!!!!!!
6825 *
6826 * param[in] vport - pointer to bfa_fcs_vport_t.
6827 *
6828 * return None
6829 */
6830bfa_status_t
6831bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
6832{
6833
6834 if (vport->lport.port_cfg.preboot_vp)
6835 return BFA_STATUS_PBC;
6836
6837 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6838
6839 return BFA_STATUS_OK;
6840}
6841
Jing Huang5fbe25c2010-10-18 17:17:23 -07006842/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006843 * Use this function to get vport's current status info.
6844 *
6845 * param[in] vport pointer to bfa_fcs_vport_t.
6846 * param[out] attr pointer to return vport attributes
6847 *
6848 * return None
6849 */
6850void
6851bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
6852 struct bfa_vport_attr_s *attr)
6853{
6854 if (vport == NULL || attr == NULL)
6855 return;
6856
Jing Huang6a18b162010-10-18 17:08:54 -07006857 memset(attr, 0, sizeof(struct bfa_vport_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006858
6859 bfa_fcs_lport_get_attr(&vport->lport, &attr->port_attr);
6860 attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
6861}
6862
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006863
Jing Huang5fbe25c2010-10-18 17:17:23 -07006864/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006865 * Lookup a virtual port. Excludes base port from lookup.
6866 */
6867struct bfa_fcs_vport_s *
6868bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
6869{
6870 struct bfa_fcs_vport_s *vport;
6871 struct bfa_fcs_fabric_s *fabric;
6872
6873 bfa_trc(fcs, vf_id);
6874 bfa_trc(fcs, vpwwn);
6875
6876 fabric = bfa_fcs_vf_lookup(fcs, vf_id);
6877 if (!fabric) {
6878 bfa_trc(fcs, vf_id);
6879 return NULL;
6880 }
6881
6882 vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
6883 return vport;
6884}
6885
Jing Huang5fbe25c2010-10-18 17:17:23 -07006886/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006887 * FDISC Response
6888 */
6889void
6890bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
6891{
6892 struct bfa_fcs_vport_s *vport = uarg;
6893
6894 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6895 bfa_trc(__vport_fcs(vport), status);
6896
6897 switch (status) {
6898 case BFA_STATUS_OK:
6899 /*
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04006900 * Initialize the V-Port fields
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006901 */
Maggie Zhangf7f738122010-12-09 19:08:43 -08006902 __vport_fcid(vport) = vport->lps->lp_pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006903 vport->vport_stats.fdisc_accepts++;
6904 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6905 break;
6906
6907 case BFA_STATUS_INVALID_MAC:
6908 /* Only for CNA */
6909 vport->vport_stats.fdisc_acc_bad++;
6910 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6911
6912 break;
6913
6914 case BFA_STATUS_EPROTOCOL:
Maggie Zhangf7f738122010-12-09 19:08:43 -08006915 switch (vport->lps->ext_status) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006916 case BFA_EPROTO_BAD_ACCEPT:
6917 vport->vport_stats.fdisc_acc_bad++;
6918 break;
6919
6920 case BFA_EPROTO_UNKNOWN_RSP:
6921 vport->vport_stats.fdisc_unknown_rsp++;
6922 break;
6923
6924 default:
6925 break;
6926 }
6927
Vijaya Mohan Guvvaf2a0cc32013-05-13 02:33:25 -07006928 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6929 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6930 else
6931 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
6932
6933 break;
6934
6935 case BFA_STATUS_ETIMER:
6936 vport->vport_stats.fdisc_timeouts++;
6937 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6938 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6939 else
6940 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006941 break;
6942
6943 case BFA_STATUS_FABRIC_RJT:
6944 vport->vport_stats.fdisc_rejects++;
6945 bfa_fcs_vport_fdisc_rejected(vport);
6946 break;
6947
6948 default:
6949 vport->vport_stats.fdisc_rsp_err++;
6950 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6951 }
6952}
6953
Jing Huang5fbe25c2010-10-18 17:17:23 -07006954/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006955 * LOGO response
6956 */
6957void
6958bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
6959{
6960 struct bfa_fcs_vport_s *vport = uarg;
6961 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6962}
6963
Jing Huang5fbe25c2010-10-18 17:17:23 -07006964/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006965 * Received clear virtual link
6966 */
6967void
6968bfa_cb_lps_cvl_event(void *bfad, void *uarg)
6969{
6970 struct bfa_fcs_vport_s *vport = uarg;
6971
6972 /* Send an Offline followed by an ONLINE */
6973 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6974 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
6975}