blob: eb87949b00c105ed54044d2e231cec57e866483a [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05002 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
Jing Huang7725ccf2009-09-23 17:46:15 -07004 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05005 * www.qlogic.com
Jing Huang7725ccf2009-09-23 17:46:15 -07006 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05007 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Jing Huang7725ccf2009-09-23 17:46:15 -07008 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
Maggie Zhangf16a1752010-12-09 19:12:32 -080019#include "bfad_drv.h"
Krishna Gudipati7826f302011-07-20 16:59:13 -070020#include "bfad_im.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070021#include "bfa_fcs.h"
22#include "bfa_fcbuild.h"
23#include "bfa_fc.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070024
25BFA_TRC_FILE(FCS, PORT);
26
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -070027/*
28 * ALPA to LIXA bitmap mapping
29 *
30 * ALPA 0x00 (Word 0, Bit 30) is invalid for N_Ports. Also Word 0 Bit 31
31 * is for L_bit (login required) and is filled as ALPA 0x00 here.
32 */
33static const u8 loop_alpa_map[] = {
34 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x0F, 0x10, /* Word 0 Bits 31..24 */
35 0x17, 0x18, 0x1B, 0x1D, 0x1E, 0x1F, 0x23, 0x25, /* Word 0 Bits 23..16 */
36 0x26, 0x27, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, /* Word 0 Bits 15..08 */
37 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x39, 0x3A, /* Word 0 Bits 07..00 */
38
39 0x3C, 0x43, 0x45, 0x46, 0x47, 0x49, 0x4A, 0x4B, /* Word 1 Bits 31..24 */
40 0x4C, 0x4D, 0x4E, 0x51, 0x52, 0x53, 0x54, 0x55, /* Word 1 Bits 23..16 */
41 0x56, 0x59, 0x5A, 0x5C, 0x63, 0x65, 0x66, 0x67, /* Word 1 Bits 15..08 */
42 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x71, 0x72, /* Word 1 Bits 07..00 */
43
44 0x73, 0x74, 0x75, 0x76, 0x79, 0x7A, 0x7C, 0x80, /* Word 2 Bits 31..24 */
45 0x81, 0x82, 0x84, 0x88, 0x8F, 0x90, 0x97, 0x98, /* Word 2 Bits 23..16 */
46 0x9B, 0x9D, 0x9E, 0x9F, 0xA3, 0xA5, 0xA6, 0xA7, /* Word 2 Bits 15..08 */
47 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xB1, 0xB2, /* Word 2 Bits 07..00 */
48
49 0xB3, 0xB4, 0xB5, 0xB6, 0xB9, 0xBA, 0xBC, 0xC3, /* Word 3 Bits 31..24 */
50 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, /* Word 3 Bits 23..16 */
51 0xCE, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD9, /* Word 3 Bits 15..08 */
52 0xDA, 0xDC, 0xE0, 0xE1, 0xE2, 0xE4, 0xE8, 0xEF, /* Word 3 Bits 07..00 */
53};
54
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070055static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port,
56 struct fchs_s *rx_fchs, u8 reason_code,
57 u8 reason_code_expl);
58static void bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
59 struct fchs_s *rx_fchs, struct fc_logi_s *plogi);
60static void bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port);
61static void bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port);
62static void bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port);
63static void bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port);
64static void bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port);
65static void bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port);
66static void bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -070067 struct fchs_s *rx_fchs,
68 struct fc_echo_s *echo, u16 len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070069static void bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -070070 struct fchs_s *rx_fchs,
71 struct fc_rnid_cmd_s *rnid, u16 len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070072static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -070073 struct fc_rnid_general_topology_data_s *gen_topo_data);
74
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070075static void bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port);
76static void bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port);
77static void bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port);
78
79static void bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port);
80static void bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port);
81static void bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port);
82
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -070083static void bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port);
84static void bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port);
85static void bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port);
86
Jing Huang7725ccf2009-09-23 17:46:15 -070087static struct {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070088 void (*init) (struct bfa_fcs_lport_s *port);
89 void (*online) (struct bfa_fcs_lport_s *port);
90 void (*offline) (struct bfa_fcs_lport_s *port);
Jing Huang7725ccf2009-09-23 17:46:15 -070091} __port_action[] = {
92 {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070093 bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
94 bfa_fcs_lport_unknown_offline}, {
95 bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
96 bfa_fcs_lport_fab_offline}, {
97 bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -070098 bfa_fcs_lport_n2n_offline}, {
99 bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
100 bfa_fcs_lport_loop_offline},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700101 };
Jing Huang7725ccf2009-09-23 17:46:15 -0700102
Jing Huang5fbe25c2010-10-18 17:17:23 -0700103/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700104 * fcs_port_sm FCS logical port state machine
105 */
106
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700107enum bfa_fcs_lport_event {
Jing Huang7725ccf2009-09-23 17:46:15 -0700108 BFA_FCS_PORT_SM_CREATE = 1,
109 BFA_FCS_PORT_SM_ONLINE = 2,
110 BFA_FCS_PORT_SM_OFFLINE = 3,
111 BFA_FCS_PORT_SM_DELETE = 4,
112 BFA_FCS_PORT_SM_DELRPORT = 5,
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700113 BFA_FCS_PORT_SM_STOP = 6,
Jing Huang7725ccf2009-09-23 17:46:15 -0700114};
115
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700116static void bfa_fcs_lport_sm_uninit(struct bfa_fcs_lport_s *port,
117 enum bfa_fcs_lport_event event);
118static void bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
119 enum bfa_fcs_lport_event event);
120static void bfa_fcs_lport_sm_online(struct bfa_fcs_lport_s *port,
121 enum bfa_fcs_lport_event event);
122static void bfa_fcs_lport_sm_offline(struct bfa_fcs_lport_s *port,
123 enum bfa_fcs_lport_event event);
124static void bfa_fcs_lport_sm_deleting(struct bfa_fcs_lport_s *port,
125 enum bfa_fcs_lport_event event);
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700126static void bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
127 enum bfa_fcs_lport_event event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700128
129static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130bfa_fcs_lport_sm_uninit(
131 struct bfa_fcs_lport_s *port,
132 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700133{
134 bfa_trc(port->fcs, port->port_cfg.pwwn);
135 bfa_trc(port->fcs, event);
136
137 switch (event) {
138 case BFA_FCS_PORT_SM_CREATE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700139 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
Jing Huang7725ccf2009-09-23 17:46:15 -0700140 break;
141
142 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800143 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700144 }
145}
146
147static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700148bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
149 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700150{
151 bfa_trc(port->fcs, port->port_cfg.pwwn);
152 bfa_trc(port->fcs, event);
153
154 switch (event) {
155 case BFA_FCS_PORT_SM_ONLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700156 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
157 bfa_fcs_lport_online_actions(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700158 break;
159
160 case BFA_FCS_PORT_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700161 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
162 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700163 break;
164
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700165 case BFA_FCS_PORT_SM_STOP:
166 /* If vport - send completion call back */
167 if (port->vport)
168 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700169 else
170 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700171 break;
172
Jing Huang3e98cc02010-07-08 19:52:46 -0700173 case BFA_FCS_PORT_SM_OFFLINE:
174 break;
175
Jing Huang7725ccf2009-09-23 17:46:15 -0700176 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800177 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700178 }
179}
180
181static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700182bfa_fcs_lport_sm_online(
183 struct bfa_fcs_lport_s *port,
184 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700185{
186 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700187 struct list_head *qe, *qen;
Jing Huang7725ccf2009-09-23 17:46:15 -0700188
189 bfa_trc(port->fcs, port->port_cfg.pwwn);
190 bfa_trc(port->fcs, event);
191
192 switch (event) {
193 case BFA_FCS_PORT_SM_OFFLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700194 bfa_sm_set_state(port, bfa_fcs_lport_sm_offline);
195 bfa_fcs_lport_offline_actions(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700196 break;
197
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700198 case BFA_FCS_PORT_SM_STOP:
199 __port_action[port->fabric->fab_type].offline(port);
200
201 if (port->num_rports == 0) {
202 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
203 /* If vport - send completion call back */
204 if (port->vport)
205 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700206 else
207 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700208 } else {
209 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
210 list_for_each_safe(qe, qen, &port->rport_q) {
211 rport = (struct bfa_fcs_rport_s *) qe;
212 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
213 }
214 }
215 break;
216
Jing Huang7725ccf2009-09-23 17:46:15 -0700217 case BFA_FCS_PORT_SM_DELETE:
218
219 __port_action[port->fabric->fab_type].offline(port);
220
221 if (port->num_rports == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700222 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
223 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700224 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700225 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
Jing Huang7725ccf2009-09-23 17:46:15 -0700226 list_for_each_safe(qe, qen, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700227 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800228 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700229 }
230 }
231 break;
232
233 case BFA_FCS_PORT_SM_DELRPORT:
234 break;
235
236 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800237 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700238 }
239}
240
241static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700242bfa_fcs_lport_sm_offline(
243 struct bfa_fcs_lport_s *port,
244 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700245{
246 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700247 struct list_head *qe, *qen;
Jing Huang7725ccf2009-09-23 17:46:15 -0700248
249 bfa_trc(port->fcs, port->port_cfg.pwwn);
250 bfa_trc(port->fcs, event);
251
252 switch (event) {
253 case BFA_FCS_PORT_SM_ONLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700254 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
255 bfa_fcs_lport_online_actions(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700256 break;
257
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700258 case BFA_FCS_PORT_SM_STOP:
259 if (port->num_rports == 0) {
260 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
261 /* If vport - send completion call back */
262 if (port->vport)
263 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700264 else
265 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700266 } else {
267 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
268 list_for_each_safe(qe, qen, &port->rport_q) {
269 rport = (struct bfa_fcs_rport_s *) qe;
270 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
271 }
272 }
273 break;
274
Jing Huang7725ccf2009-09-23 17:46:15 -0700275 case BFA_FCS_PORT_SM_DELETE:
276 if (port->num_rports == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700277 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
278 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700279 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700280 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
Jing Huang7725ccf2009-09-23 17:46:15 -0700281 list_for_each_safe(qe, qen, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700282 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800283 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700284 }
285 }
286 break;
287
288 case BFA_FCS_PORT_SM_DELRPORT:
289 case BFA_FCS_PORT_SM_OFFLINE:
290 break;
291
292 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800293 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700294 }
295}
296
297static void
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700298bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
299 enum bfa_fcs_lport_event event)
300{
301 bfa_trc(port->fcs, port->port_cfg.pwwn);
302 bfa_trc(port->fcs, event);
303
304 switch (event) {
305 case BFA_FCS_PORT_SM_DELRPORT:
306 if (port->num_rports == 0) {
307 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
308 /* If vport - send completion call back */
309 if (port->vport)
310 bfa_fcs_vport_stop_comp(port->vport);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700311 else
312 bfa_wc_down(&(port->fabric->stop_wc));
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700313 }
314 break;
315
316 default:
317 bfa_sm_fault(port->fcs, event);
318 }
319}
320
321static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700322bfa_fcs_lport_sm_deleting(
323 struct bfa_fcs_lport_s *port,
324 enum bfa_fcs_lport_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700325{
326 bfa_trc(port->fcs, port->port_cfg.pwwn);
327 bfa_trc(port->fcs, event);
328
329 switch (event) {
330 case BFA_FCS_PORT_SM_DELRPORT:
331 if (port->num_rports == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700332 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
333 bfa_fcs_lport_deleted(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700334 }
335 break;
336
337 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800338 bfa_sm_fault(port->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700339 }
340}
341
Jing Huang5fbe25c2010-10-18 17:17:23 -0700342/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700343 * fcs_port_pvt
344 */
345
Jing Huang7725ccf2009-09-23 17:46:15 -0700346/*
Krishna Gudipati7826f302011-07-20 16:59:13 -0700347 * Send AEN notification
348 */
349static void
350bfa_fcs_lport_aen_post(struct bfa_fcs_lport_s *port,
351 enum bfa_lport_aen_event event)
352{
353 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
354 struct bfa_aen_entry_s *aen_entry;
355
356 bfad_get_aen_entry(bfad, aen_entry);
357 if (!aen_entry)
358 return;
359
360 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
361 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
362 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
363 bfa_fcs_get_base_port(port->fcs));
364 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
365
366 /* Send the AEN notification */
367 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
368 BFA_AEN_CAT_LPORT, event);
369}
370
371/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700372 * Send a LS reject
373 */
374static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700375bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
Jing Huang7725ccf2009-09-23 17:46:15 -0700376 u8 reason_code, u8 reason_code_expl)
377{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700378 struct fchs_s fchs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700379 struct bfa_fcxp_s *fcxp;
380 struct bfa_rport_s *bfa_rport = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700381 int len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700382
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700383 bfa_trc(port->fcs, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700384 bfa_trc(port->fcs, rx_fchs->s_id);
385
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700386 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700387 if (!fcxp)
388 return;
389
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700390 len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
391 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
392 rx_fchs->ox_id, reason_code, reason_code_expl);
Jing Huang7725ccf2009-09-23 17:46:15 -0700393
394 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700395 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
396 FC_MAX_PDUSZ, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700397}
398
Jing Huang5fbe25c2010-10-18 17:17:23 -0700399/*
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700400 * Send a FCCT Reject
401 */
402static void
403bfa_fcs_lport_send_fcgs_rjt(struct bfa_fcs_lport_s *port,
404 struct fchs_s *rx_fchs, u8 reason_code, u8 reason_code_expl)
405{
406 struct fchs_s fchs;
407 struct bfa_fcxp_s *fcxp;
408 struct bfa_rport_s *bfa_rport = NULL;
409 int len;
410 struct ct_hdr_s *rx_cthdr = (struct ct_hdr_s *)(rx_fchs + 1);
411 struct ct_hdr_s *ct_hdr;
412
413 bfa_trc(port->fcs, rx_fchs->d_id);
414 bfa_trc(port->fcs, rx_fchs->s_id);
415
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700416 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700417 if (!fcxp)
418 return;
419
420 ct_hdr = bfa_fcxp_get_reqbuf(fcxp);
421 ct_hdr->gs_type = rx_cthdr->gs_type;
422 ct_hdr->gs_sub_type = rx_cthdr->gs_sub_type;
423
424 len = fc_gs_rjt_build(&fchs, ct_hdr, rx_fchs->s_id,
425 bfa_fcs_lport_get_fcid(port),
426 rx_fchs->ox_id, reason_code, reason_code_expl);
427
428 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
429 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
430 FC_MAX_PDUSZ, 0);
431}
432
433/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700434 * Process incoming plogi from a remote port.
435 */
436static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700437bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
438 struct fchs_s *rx_fchs, struct fc_logi_s *plogi)
Jing Huang7725ccf2009-09-23 17:46:15 -0700439{
440 struct bfa_fcs_rport_s *rport;
441
442 bfa_trc(port->fcs, rx_fchs->d_id);
443 bfa_trc(port->fcs, rx_fchs->s_id);
444
445 /*
446 * If min cfg mode is enabled, drop any incoming PLOGIs
447 */
448 if (__fcs_min_cfg(port->fcs)) {
449 bfa_trc(port->fcs, rx_fchs->s_id);
450 return;
451 }
452
453 if (fc_plogi_parse(rx_fchs) != FC_PARSE_OK) {
454 bfa_trc(port->fcs, rx_fchs->s_id);
455 /*
456 * send a LS reject
457 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700458 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
459 FC_LS_RJT_RSN_PROTOCOL_ERROR,
460 FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS);
Jing Huang7725ccf2009-09-23 17:46:15 -0700461 return;
462 }
463
Jing Huang5fbe25c2010-10-18 17:17:23 -0700464 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700465 * Direct Attach P2P mode : verify address assigned by the r-port.
Jing Huang7725ccf2009-09-23 17:46:15 -0700466 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700467 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
468 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
469 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700470 if (BFA_FCS_PID_IS_WKA(rx_fchs->d_id)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700471 /* Address assigned to us cannot be a WKA */
472 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
Jing Huang7725ccf2009-09-23 17:46:15 -0700473 FC_LS_RJT_RSN_PROTOCOL_ERROR,
474 FC_LS_RJT_EXP_INVALID_NPORT_ID);
475 return;
476 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700477 port->pid = rx_fchs->d_id;
Krishna Gudipatib7044952010-12-13 16:17:42 -0800478 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700479 }
480
Jing Huang5fbe25c2010-10-18 17:17:23 -0700481 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700482 * First, check if we know the device by pwwn.
483 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700484 rport = bfa_fcs_lport_get_rport_by_pwwn(port, plogi->port_name);
Jing Huang7725ccf2009-09-23 17:46:15 -0700485 if (rport) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700486 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700487 * Direct Attach P2P mode : handle address assigned by r-port.
Jing Huang7725ccf2009-09-23 17:46:15 -0700488 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700489 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
490 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
491 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
492 port->pid = rx_fchs->d_id;
Krishna Gudipatib7044952010-12-13 16:17:42 -0800493 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700494 rport->pid = rx_fchs->s_id;
495 }
496 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
497 return;
498 }
499
Jing Huang5fbe25c2010-10-18 17:17:23 -0700500 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700501 * Next, lookup rport by PID.
502 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700503 rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700504 if (!rport) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700505 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700506 * Inbound PLOGI from a new device.
507 */
508 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
509 return;
510 }
511
Jing Huang5fbe25c2010-10-18 17:17:23 -0700512 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700513 * Rport is known only by PID.
514 */
515 if (rport->pwwn) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700516 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700517 * This is a different device with the same pid. Old device
518 * disappeared. Send implicit LOGO to old device.
519 */
Jing Huangd4b671c2010-12-26 21:46:35 -0800520 WARN_ON(rport->pwwn == plogi->port_name);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800521 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700522
Jing Huang5fbe25c2010-10-18 17:17:23 -0700523 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700524 * Inbound PLOGI from a new device (with old PID).
525 */
526 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
527 return;
528 }
529
Jing Huang5fbe25c2010-10-18 17:17:23 -0700530 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700531 * PLOGI crossing each other.
532 */
Jing Huangd4b671c2010-12-26 21:46:35 -0800533 WARN_ON(rport->pwwn != WWN_NULL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700534 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
535}
536
537/*
538 * Process incoming ECHO.
539 * Since it does not require a login, it is processed here.
540 */
541static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700542bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
543 struct fc_echo_s *echo, u16 rx_len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700544{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700545 struct fchs_s fchs;
546 struct bfa_fcxp_s *fcxp;
547 struct bfa_rport_s *bfa_rport = NULL;
548 int len, pyld_len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700549
550 bfa_trc(port->fcs, rx_fchs->s_id);
551 bfa_trc(port->fcs, rx_fchs->d_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700552
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700553 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700554 if (!fcxp)
555 return;
556
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700557 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
558 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
559 rx_fchs->ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700560
561 /*
562 * Copy the payload (if any) from the echo frame
563 */
564 pyld_len = rx_len - sizeof(struct fchs_s);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700565 bfa_trc(port->fcs, rx_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700566 bfa_trc(port->fcs, pyld_len);
567
568 if (pyld_len > len)
569 memcpy(((u8 *) bfa_fcxp_get_reqbuf(fcxp)) +
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700570 sizeof(struct fc_echo_s), (echo + 1),
571 (pyld_len - sizeof(struct fc_echo_s)));
Jing Huang7725ccf2009-09-23 17:46:15 -0700572
573 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700574 BFA_FALSE, FC_CLASS_3, pyld_len, &fchs, NULL, NULL,
575 FC_MAX_PDUSZ, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700576}
577
578/*
579 * Process incoming RNID.
580 * Since it does not require a login, it is processed here.
581 */
582static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700583bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
584 struct fc_rnid_cmd_s *rnid, u16 rx_len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700585{
586 struct fc_rnid_common_id_data_s common_id_data;
587 struct fc_rnid_general_topology_data_s gen_topo_data;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700588 struct fchs_s fchs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700589 struct bfa_fcxp_s *fcxp;
590 struct bfa_rport_s *bfa_rport = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700591 u16 len;
592 u32 data_format;
Jing Huang7725ccf2009-09-23 17:46:15 -0700593
594 bfa_trc(port->fcs, rx_fchs->s_id);
595 bfa_trc(port->fcs, rx_fchs->d_id);
596 bfa_trc(port->fcs, rx_len);
597
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700598 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700599 if (!fcxp)
600 return;
601
602 /*
603 * Check Node Indentification Data Format
604 * We only support General Topology Discovery Format.
605 * For any other requested Data Formats, we return Common Node Id Data
606 * only, as per FC-LS.
607 */
608 bfa_trc(port->fcs, rnid->node_id_data_format);
609 if (rnid->node_id_data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
610 data_format = RNID_NODEID_DATA_FORMAT_DISCOVERY;
611 /*
612 * Get General topology data for this port
613 */
614 bfa_fs_port_get_gen_topo_data(port, &gen_topo_data);
615 } else {
616 data_format = RNID_NODEID_DATA_FORMAT_COMMON;
617 }
618
619 /*
620 * Copy the Node Id Info
621 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700622 common_id_data.port_name = bfa_fcs_lport_get_pwwn(port);
623 common_id_data.node_name = bfa_fcs_lport_get_nwwn(port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700624
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700625 len = fc_rnid_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
626 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
627 rx_fchs->ox_id, data_format, &common_id_data,
628 &gen_topo_data);
Jing Huang7725ccf2009-09-23 17:46:15 -0700629
630 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700631 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
632 FC_MAX_PDUSZ, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700633}
634
635/*
636 * Fill out General Topolpgy Discovery Data for RNID ELS.
637 */
638static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700639bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
Jing Huang7725ccf2009-09-23 17:46:15 -0700640 struct fc_rnid_general_topology_data_s *gen_topo_data)
641{
Jing Huang6a18b162010-10-18 17:08:54 -0700642 memset(gen_topo_data, 0,
Jing Huang7725ccf2009-09-23 17:46:15 -0700643 sizeof(struct fc_rnid_general_topology_data_s));
644
Jing Huangba816ea2010-10-18 17:10:50 -0700645 gen_topo_data->asso_type = cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST);
Jing Huang7725ccf2009-09-23 17:46:15 -0700646 gen_topo_data->phy_port_num = 0; /* @todo */
Jing Huangba816ea2010-10-18 17:10:50 -0700647 gen_topo_data->num_attached_nodes = cpu_to_be32(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700648}
649
650static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700651bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700652{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700653 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
654 char lpwwn_buf[BFA_STRING_32];
655
Jing Huang7725ccf2009-09-23 17:46:15 -0700656 bfa_trc(port->fcs, port->fabric->oper_type);
657
658 __port_action[port->fabric->fab_type].init(port);
659 __port_action[port->fabric->fab_type].online(port);
660
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700661 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
Krishna Gudipatia3f29cc2012-04-09 18:41:18 -0700662 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700663 "Logical port online: WWN = %s Role = %s\n",
664 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700665 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_ONLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700666
667 bfad->bfad_flags |= BFAD_PORT_ONLINE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700668}
669
670static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700671bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700672{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700673 struct list_head *qe, *qen;
Jing Huang7725ccf2009-09-23 17:46:15 -0700674 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700675 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
676 char lpwwn_buf[BFA_STRING_32];
Jing Huang7725ccf2009-09-23 17:46:15 -0700677
678 bfa_trc(port->fcs, port->fabric->oper_type);
679
680 __port_action[port->fabric->fab_type].offline(port);
681
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700682 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
Maggie Zhangf7f738122010-12-09 19:08:43 -0800683 if (bfa_sm_cmp_state(port->fabric,
Krishna Gudipati7826f302011-07-20 16:59:13 -0700684 bfa_fcs_fabric_sm_online) == BFA_TRUE) {
Krishna Gudipatia3f29cc2012-04-09 18:41:18 -0700685 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700686 "Logical port lost fabric connectivity: WWN = %s Role = %s\n",
687 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700688 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DISCONNECT);
689 } else {
Krishna Gudipatia3f29cc2012-04-09 18:41:18 -0700690 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700691 "Logical port taken offline: WWN = %s Role = %s\n",
692 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700693 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_OFFLINE);
694 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700695
696 list_for_each_safe(qe, qen, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700697 rport = (struct bfa_fcs_rport_s *) qe;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800698 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700699 }
700}
701
702static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700703bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700704{
Jing Huangd4b671c2010-12-26 21:46:35 -0800705 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700706}
707
708static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700709bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700710{
Jing Huangd4b671c2010-12-26 21:46:35 -0800711 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700712}
713
714static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700715bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -0700716{
Jing Huangd4b671c2010-12-26 21:46:35 -0800717 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700718}
719
720static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700721bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs)
Jing Huang7725ccf2009-09-23 17:46:15 -0700722{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700723 struct fchs_s fchs;
724 struct bfa_fcxp_s *fcxp;
725 int len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700726
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700727 bfa_trc(port->fcs, rx_fchs->d_id);
728 bfa_trc(port->fcs, rx_fchs->s_id);
729
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700730 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700731 if (!fcxp)
732 return;
733
734 len = fc_ba_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
735 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
736 rx_fchs->ox_id, 0);
737
738 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
739 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
740 FC_MAX_PDUSZ, 0);
741}
742static void
743bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port)
744{
745 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
746 char lpwwn_buf[BFA_STRING_32];
747
748 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
Jing Huang88166242010-12-09 17:11:53 -0800749 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700750 "Logical port deleted: WWN = %s Role = %s\n",
751 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700752 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DELETE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700753
754 /* Base port will be deleted by the OS driver */
Krishna Gudipati17c201b2012-04-09 18:40:01 -0700755 if (port->vport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700756 bfa_fcs_vport_delete_comp(port->vport);
Krishna Gudipati17c201b2012-04-09 18:40:01 -0700757 else
Maggie Zhangf7f738122010-12-09 19:08:43 -0800758 bfa_wc_down(&port->fabric->wc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700759}
760
761
Jing Huang5fbe25c2010-10-18 17:17:23 -0700762/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700763 * Unsolicited frame receive handling.
Jing Huang7725ccf2009-09-23 17:46:15 -0700764 */
765void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700766bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
767 struct fchs_s *fchs, u16 len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700768{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700769 u32 pid = fchs->s_id;
Jing Huang7725ccf2009-09-23 17:46:15 -0700770 struct bfa_fcs_rport_s *rport = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700771 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700772
773 bfa_stats(lport, uf_recvs);
Krishna Gudipati15821f02010-12-13 16:23:27 -0800774 bfa_trc(lport->fcs, fchs->type);
Jing Huang7725ccf2009-09-23 17:46:15 -0700775
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700776 if (!bfa_fcs_lport_is_online(lport)) {
Vijaya Mohan Guvva97818512013-11-21 01:37:45 -0800777 /*
778 * In direct attach topology, it is possible to get a PLOGI
779 * before the lport is online due to port feature
780 * (QoS/Trunk/FEC/CR), so send a rjt
781 */
782 if ((fchs->type == FC_TYPE_ELS) &&
783 (els_cmd->els_code == FC_ELS_PLOGI)) {
784 bfa_fcs_lport_send_ls_rjt(lport, fchs,
785 FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
786 FC_LS_RJT_EXP_NO_ADDL_INFO);
787 bfa_stats(lport, plogi_rcvd);
788 } else
789 bfa_stats(lport, uf_recv_drops);
790
Jing Huang7725ccf2009-09-23 17:46:15 -0700791 return;
792 }
793
Jing Huang5fbe25c2010-10-18 17:17:23 -0700794 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700795 * First, handle ELSs that donot require a login.
796 */
797 /*
798 * Handle PLOGI first
799 */
800 if ((fchs->type == FC_TYPE_ELS) &&
801 (els_cmd->els_code == FC_ELS_PLOGI)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700802 bfa_fcs_lport_plogi(lport, fchs, (struct fc_logi_s *) els_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -0700803 return;
804 }
805
806 /*
807 * Handle ECHO separately.
808 */
809 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_ECHO)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700810 bfa_fcs_lport_echo(lport, fchs,
811 (struct fc_echo_s *)els_cmd, len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700812 return;
813 }
814
815 /*
816 * Handle RNID separately.
817 */
818 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_RNID)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700819 bfa_fcs_lport_rnid(lport, fchs,
Jing Huang7725ccf2009-09-23 17:46:15 -0700820 (struct fc_rnid_cmd_s *) els_cmd, len);
821 return;
822 }
823
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700824 if (fchs->type == FC_TYPE_BLS) {
825 if ((fchs->routing == FC_RTG_BASIC_LINK) &&
826 (fchs->cat_info == FC_CAT_ABTS))
827 bfa_fcs_lport_abts_acc(lport, fchs);
828 return;
829 }
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700830
831 if (fchs->type == FC_TYPE_SERVICES) {
832 /*
833 * Unhandled FC-GS frames. Send a FC-CT Reject
834 */
835 bfa_fcs_lport_send_fcgs_rjt(lport, fchs, CT_RSN_NOT_SUPP,
836 CT_NS_EXP_NOADDITIONAL);
837 return;
838 }
839
Jing Huang5fbe25c2010-10-18 17:17:23 -0700840 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700841 * look for a matching remote port ID
842 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700843 rport = bfa_fcs_lport_get_rport_by_pid(lport, pid);
Jing Huang7725ccf2009-09-23 17:46:15 -0700844 if (rport) {
845 bfa_trc(rport->fcs, fchs->s_id);
846 bfa_trc(rport->fcs, fchs->d_id);
847 bfa_trc(rport->fcs, fchs->type);
848
849 bfa_fcs_rport_uf_recv(rport, fchs, len);
850 return;
851 }
852
Jing Huang5fbe25c2010-10-18 17:17:23 -0700853 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700854 * Only handles ELS frames for now.
855 */
856 if (fchs->type != FC_TYPE_ELS) {
Krishna Gudipati15821f02010-12-13 16:23:27 -0800857 bfa_trc(lport->fcs, fchs->s_id);
858 bfa_trc(lport->fcs, fchs->d_id);
859 /* ignore type FC_TYPE_FC_FSS */
860 if (fchs->type != FC_TYPE_FC_FSS)
861 bfa_sm_fault(lport->fcs, fchs->type);
Jing Huang7725ccf2009-09-23 17:46:15 -0700862 return;
863 }
864
865 bfa_trc(lport->fcs, els_cmd->els_code);
866 if (els_cmd->els_code == FC_ELS_RSCN) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700867 bfa_fcs_lport_scn_process_rscn(lport, fchs, len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700868 return;
869 }
870
871 if (els_cmd->els_code == FC_ELS_LOGO) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700872 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700873 * @todo Handle LOGO frames received.
874 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700875 return;
876 }
877
878 if (els_cmd->els_code == FC_ELS_PRLI) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700879 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700880 * @todo Handle PRLI frames received.
881 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700882 return;
883 }
884
Jing Huang5fbe25c2010-10-18 17:17:23 -0700885 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700886 * Unhandled ELS frames. Send a LS_RJT.
887 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700888 bfa_fcs_lport_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP,
Jing Huang7725ccf2009-09-23 17:46:15 -0700889 FC_LS_RJT_EXP_NO_ADDL_INFO);
890
891}
892
Jing Huang5fbe25c2010-10-18 17:17:23 -0700893/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700894 * PID based Lookup for a R-Port in the Port R-Port Queue
895 */
896struct bfa_fcs_rport_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700897bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s *port, u32 pid)
Jing Huang7725ccf2009-09-23 17:46:15 -0700898{
899 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700900 struct list_head *qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700901
902 list_for_each(qe, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700903 rport = (struct bfa_fcs_rport_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700904 if (rport->pid == pid)
905 return rport;
906 }
907
908 bfa_trc(port->fcs, pid);
909 return NULL;
910}
911
Jing Huang5fbe25c2010-10-18 17:17:23 -0700912/*
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -0700913 * OLD_PID based Lookup for a R-Port in the Port R-Port Queue
914 */
915struct bfa_fcs_rport_s *
916bfa_fcs_lport_get_rport_by_old_pid(struct bfa_fcs_lport_s *port, u32 pid)
917{
918 struct bfa_fcs_rport_s *rport;
919 struct list_head *qe;
920
921 list_for_each(qe, &port->rport_q) {
922 rport = (struct bfa_fcs_rport_s *) qe;
923 if (rport->old_pid == pid)
924 return rport;
925 }
926
927 bfa_trc(port->fcs, pid);
928 return NULL;
929}
930
931/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700932 * PWWN based Lookup for a R-Port in the Port R-Port Queue
933 */
934struct bfa_fcs_rport_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700935bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s *port, wwn_t pwwn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700936{
937 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700938 struct list_head *qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700939
940 list_for_each(qe, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700941 rport = (struct bfa_fcs_rport_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700942 if (wwn_is_equal(rport->pwwn, pwwn))
943 return rport;
944 }
945
946 bfa_trc(port->fcs, pwwn);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700947 return NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700948}
949
Jing Huang5fbe25c2010-10-18 17:17:23 -0700950/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700951 * NWWN based Lookup for a R-Port in the Port R-Port Queue
952 */
953struct bfa_fcs_rport_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700954bfa_fcs_lport_get_rport_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t nwwn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700955{
956 struct bfa_fcs_rport_s *rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700957 struct list_head *qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700958
959 list_for_each(qe, &port->rport_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700960 rport = (struct bfa_fcs_rport_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700961 if (wwn_is_equal(rport->nwwn, nwwn))
962 return rport;
963 }
964
965 bfa_trc(port->fcs, nwwn);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700966 return NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700967}
968
Jing Huang5fbe25c2010-10-18 17:17:23 -0700969/*
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -0700970 * PWWN & PID based Lookup for a R-Port in the Port R-Port Queue
971 */
972struct bfa_fcs_rport_s *
973bfa_fcs_lport_get_rport_by_qualifier(struct bfa_fcs_lport_s *port,
974 wwn_t pwwn, u32 pid)
975{
976 struct bfa_fcs_rport_s *rport;
977 struct list_head *qe;
978
979 list_for_each(qe, &port->rport_q) {
980 rport = (struct bfa_fcs_rport_s *) qe;
981 if (wwn_is_equal(rport->pwwn, pwwn) && rport->pid == pid)
982 return rport;
983 }
984
985 bfa_trc(port->fcs, pwwn);
986 return NULL;
987}
988
989/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700990 * Called by rport module when new rports are discovered.
991 */
992void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700993bfa_fcs_lport_add_rport(
994 struct bfa_fcs_lport_s *port,
995 struct bfa_fcs_rport_s *rport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700996{
997 list_add_tail(&rport->qe, &port->rport_q);
998 port->num_rports++;
999}
1000
Jing Huang5fbe25c2010-10-18 17:17:23 -07001001/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001002 * Called by rport module to when rports are deleted.
1003 */
1004void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001005bfa_fcs_lport_del_rport(
1006 struct bfa_fcs_lport_s *port,
1007 struct bfa_fcs_rport_s *rport)
Jing Huang7725ccf2009-09-23 17:46:15 -07001008{
Jing Huangd4b671c2010-12-26 21:46:35 -08001009 WARN_ON(!bfa_q_is_on_q(&port->rport_q, rport));
Jing Huang7725ccf2009-09-23 17:46:15 -07001010 list_del(&rport->qe);
1011 port->num_rports--;
1012
1013 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT);
1014}
1015
Jing Huang5fbe25c2010-10-18 17:17:23 -07001016/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001017 * Called by fabric for base port when fabric login is complete.
1018 * Called by vport for virtual ports when FDISC is complete.
1019 */
1020void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001021bfa_fcs_lport_online(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -07001022{
1023 bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE);
1024}
1025
Jing Huang5fbe25c2010-10-18 17:17:23 -07001026/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001027 * Called by fabric for base port when fabric goes offline.
1028 * Called by vport for virtual ports when virtual port becomes offline.
1029 */
1030void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001031bfa_fcs_lport_offline(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -07001032{
1033 bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE);
1034}
1035
Jing Huang5fbe25c2010-10-18 17:17:23 -07001036/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001037 * Called by fabric for base port and by vport for virtual ports
1038 * when target mode driver is unloaded.
1039 */
1040void
1041bfa_fcs_lport_stop(struct bfa_fcs_lport_s *port)
1042{
1043 bfa_sm_send_event(port, BFA_FCS_PORT_SM_STOP);
1044}
1045
1046/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001047 * Called by fabric to delete base lport and associated resources.
1048 *
1049 * Called by vport to delete lport and associated resources. Should call
1050 * bfa_fcs_vport_delete_comp() for vports on completion.
1051 */
1052void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001053bfa_fcs_lport_delete(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -07001054{
1055 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE);
1056}
1057
Jing Huang5fbe25c2010-10-18 17:17:23 -07001058/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001059 * Return TRUE if port is online, else return FALSE
1060 */
1061bfa_boolean_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001062bfa_fcs_lport_is_online(struct bfa_fcs_lport_s *port)
Jing Huang7725ccf2009-09-23 17:46:15 -07001063{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001064 return bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online);
Jing Huang7725ccf2009-09-23 17:46:15 -07001065}
1066
Jing Huang5fbe25c2010-10-18 17:17:23 -07001067/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001068 * Attach time initialization of logical ports.
Jing Huang7725ccf2009-09-23 17:46:15 -07001069 */
1070void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001071bfa_fcs_lport_attach(struct bfa_fcs_lport_s *lport, struct bfa_fcs_s *fcs,
1072 u16 vf_id, struct bfa_fcs_vport_s *vport)
Jing Huang7725ccf2009-09-23 17:46:15 -07001073{
1074 lport->fcs = fcs;
1075 lport->fabric = bfa_fcs_vf_lookup(fcs, vf_id);
Jing Huang7725ccf2009-09-23 17:46:15 -07001076 lport->vport = vport;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001077 lport->lp_tag = (vport) ? vport->lps->bfa_tag :
1078 lport->fabric->lps->bfa_tag;
Jing Huang7725ccf2009-09-23 17:46:15 -07001079
1080 INIT_LIST_HEAD(&lport->rport_q);
1081 lport->num_rports = 0;
Krishna Gudipatie6714322010-03-03 17:44:02 -08001082}
Jing Huang7725ccf2009-09-23 17:46:15 -07001083
Jing Huang5fbe25c2010-10-18 17:17:23 -07001084/*
Krishna Gudipatie6714322010-03-03 17:44:02 -08001085 * Logical port initialization of base or virtual port.
1086 * Called by fabric for base port or by vport for virtual ports.
1087 */
1088
1089void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001090bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
1091 struct bfa_lport_cfg_s *port_cfg)
Krishna Gudipatie6714322010-03-03 17:44:02 -08001092{
1093 struct bfa_fcs_vport_s *vport = lport->vport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001094 struct bfad_s *bfad = (struct bfad_s *)lport->fcs->bfad;
1095 char lpwwn_buf[BFA_STRING_32];
Krishna Gudipatie6714322010-03-03 17:44:02 -08001096
Jing Huang6a18b162010-10-18 17:08:54 -07001097 lport->port_cfg = *port_cfg;
Krishna Gudipatie6714322010-03-03 17:44:02 -08001098
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001099 lport->bfad_port = bfa_fcb_lport_new(lport->fcs->bfad, lport,
1100 lport->port_cfg.roles,
1101 lport->fabric->vf_drv,
1102 vport ? vport->vport_drv : NULL);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001103
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001104 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(lport));
Jing Huang88166242010-12-09 17:11:53 -08001105 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001106 "New logical port created: WWN = %s Role = %s\n",
1107 lpwwn_buf, "Initiator");
Krishna Gudipati7826f302011-07-20 16:59:13 -07001108 bfa_fcs_lport_aen_post(lport, BFA_LPORT_AEN_NEW);
Jing Huang7725ccf2009-09-23 17:46:15 -07001109
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001110 bfa_sm_set_state(lport, bfa_fcs_lport_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -07001111 bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE);
1112}
1113
Vijaya Mohan Guvva22a08532013-11-21 01:37:49 -08001114void
1115bfa_fcs_lport_set_symname(struct bfa_fcs_lport_s *port,
1116 char *symname)
1117{
1118 strcpy(port->port_cfg.sym_name.symname, symname);
1119
1120 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
1121 bfa_fcs_lport_ns_util_send_rspn_id(
1122 BFA_FCS_GET_NS_FROM_PORT(port), NULL);
1123}
1124
Jing Huang5fbe25c2010-10-18 17:17:23 -07001125/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001126 * fcs_lport_api
1127 */
1128
1129void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001130bfa_fcs_lport_get_attr(
1131 struct bfa_fcs_lport_s *port,
1132 struct bfa_lport_attr_s *port_attr)
Jing Huang7725ccf2009-09-23 17:46:15 -07001133{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001134 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
Jing Huang7725ccf2009-09-23 17:46:15 -07001135 port_attr->pid = port->pid;
1136 else
1137 port_attr->pid = 0;
1138
1139 port_attr->port_cfg = port->port_cfg;
1140
1141 if (port->fabric) {
Maggie Zhangf7f738122010-12-09 19:08:43 -08001142 port_attr->port_type = port->fabric->oper_type;
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001143 port_attr->loopback = bfa_sm_cmp_state(port->fabric,
1144 bfa_fcs_fabric_sm_loopback);
Krishna Gudipatif926a052010-03-05 19:36:00 -08001145 port_attr->authfail =
Maggie Zhangf7f738122010-12-09 19:08:43 -08001146 bfa_sm_cmp_state(port->fabric,
1147 bfa_fcs_fabric_sm_auth_failed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001148 port_attr->fabric_name = bfa_fcs_lport_get_fabric_name(port);
Jing Huang7725ccf2009-09-23 17:46:15 -07001149 memcpy(port_attr->fabric_ip_addr,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001150 bfa_fcs_lport_get_fabric_ipaddr(port),
1151 BFA_FCS_FABRIC_IPADDR_SZ);
Jing Huang7725ccf2009-09-23 17:46:15 -07001152
Krishna Gudipati86e32da2010-03-05 19:35:33 -08001153 if (port->vport != NULL) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001154 port_attr->port_type = BFA_PORT_TYPE_VPORT;
Krishna Gudipati86e32da2010-03-05 19:35:33 -08001155 port_attr->fpma_mac =
Maggie Zhangf7f738122010-12-09 19:08:43 -08001156 port->vport->lps->lp_mac;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001157 } else {
Krishna Gudipati86e32da2010-03-05 19:35:33 -08001158 port_attr->fpma_mac =
Maggie Zhangf7f738122010-12-09 19:08:43 -08001159 port->fabric->lps->lp_mac;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001160 }
Jing Huang7725ccf2009-09-23 17:46:15 -07001161 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001162 port_attr->port_type = BFA_PORT_TYPE_UNKNOWN;
1163 port_attr->state = BFA_LPORT_UNINIT;
Jing Huang7725ccf2009-09-23 17:46:15 -07001164 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001165}
1166
Jing Huang5fbe25c2010-10-18 17:17:23 -07001167/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001168 * bfa_fcs_lport_fab port fab functions
1169 */
1170
Jing Huang5fbe25c2010-10-18 17:17:23 -07001171/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001172 * Called by port to initialize fabric services of the base port.
1173 */
1174static void
1175bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port)
1176{
1177 bfa_fcs_lport_ns_init(port);
1178 bfa_fcs_lport_scn_init(port);
1179 bfa_fcs_lport_ms_init(port);
1180}
1181
Jing Huang5fbe25c2010-10-18 17:17:23 -07001182/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001183 * Called by port to notify transition to online state.
1184 */
1185static void
1186bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port)
1187{
1188 bfa_fcs_lport_ns_online(port);
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07001189 bfa_fcs_lport_fab_scn_online(port);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001190}
1191
Jing Huang5fbe25c2010-10-18 17:17:23 -07001192/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001193 * Called by port to notify transition to offline state.
1194 */
1195static void
1196bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port)
1197{
1198 bfa_fcs_lport_ns_offline(port);
1199 bfa_fcs_lport_scn_offline(port);
1200 bfa_fcs_lport_ms_offline(port);
1201}
1202
Jing Huang5fbe25c2010-10-18 17:17:23 -07001203/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001204 * bfa_fcs_lport_n2n functions
1205 */
1206
Jing Huang5fbe25c2010-10-18 17:17:23 -07001207/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001208 * Called by fcs/port to initialize N2N topology.
1209 */
1210static void
1211bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port)
1212{
1213}
1214
Jing Huang5fbe25c2010-10-18 17:17:23 -07001215/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001216 * Called by fcs/port to notify transition to online state.
1217 */
1218static void
1219bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port)
1220{
1221 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1222 struct bfa_lport_cfg_s *pcfg = &port->port_cfg;
1223 struct bfa_fcs_rport_s *rport;
1224
1225 bfa_trc(port->fcs, pcfg->pwwn);
1226
1227 /*
1228 * If our PWWN is > than that of the r-port, we have to initiate PLOGI
1229 * and assign an Address. if not, we need to wait for its PLOGI.
1230 *
1231 * If our PWWN is < than that of the remote port, it will send a PLOGI
1232 * with the PIDs assigned. The rport state machine take care of this
1233 * incoming PLOGI.
1234 */
1235 if (memcmp
1236 ((void *)&pcfg->pwwn, (void *)&n2n_port->rem_port_wwn,
1237 sizeof(wwn_t)) > 0) {
1238 port->pid = N2N_LOCAL_PID;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001239 bfa_lps_set_n2n_pid(port->fabric->lps, N2N_LOCAL_PID);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001240 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001241 * First, check if we know the device by pwwn.
1242 */
1243 rport = bfa_fcs_lport_get_rport_by_pwwn(port,
1244 n2n_port->rem_port_wwn);
1245 if (rport) {
1246 bfa_trc(port->fcs, rport->pid);
1247 bfa_trc(port->fcs, rport->pwwn);
1248 rport->pid = N2N_REMOTE_PID;
Maggie Zhangf7f738122010-12-09 19:08:43 -08001249 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001250 return;
1251 }
1252
1253 /*
1254 * In n2n there can be only one rport. Delete the old one
1255 * whose pid should be zero, because it is offline.
1256 */
1257 if (port->num_rports > 0) {
1258 rport = bfa_fcs_lport_get_rport_by_pid(port, 0);
Jing Huangd4b671c2010-12-26 21:46:35 -08001259 WARN_ON(rport == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001260 if (rport) {
1261 bfa_trc(port->fcs, rport->pwwn);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001262 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001263 }
1264 }
1265 bfa_fcs_rport_create(port, N2N_REMOTE_PID);
1266 }
1267}
1268
Jing Huang5fbe25c2010-10-18 17:17:23 -07001269/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001270 * Called by fcs/port to notify transition to offline state.
1271 */
1272static void
1273bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port)
1274{
1275 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1276
1277 bfa_trc(port->fcs, port->pid);
1278 port->pid = 0;
1279 n2n_port->rem_port_wwn = 0;
1280 n2n_port->reply_oxid = 0;
1281}
1282
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07001283void
1284bfa_fcport_get_loop_attr(struct bfa_fcs_lport_s *port)
1285{
1286 int i = 0, j = 0, bit = 0, alpa_bit = 0;
1287 u8 k = 0;
1288 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(port->fcs->bfa);
1289
1290 port->port_topo.ploop.alpabm_valid = fcport->alpabm_valid;
1291 port->pid = fcport->myalpa;
1292 port->pid = bfa_hton3b(port->pid);
1293
1294 for (i = 0; i < (FC_ALPA_MAX / 8); i++) {
1295 for (j = 0, alpa_bit = 0; j < 8; j++, alpa_bit++) {
1296 bfa_trc(port->fcs->bfa, fcport->alpabm.alpa_bm[i]);
1297 bit = (fcport->alpabm.alpa_bm[i] & (1 << (7 - j)));
1298 if (bit) {
1299 port->port_topo.ploop.alpa_pos_map[k] =
1300 loop_alpa_map[(i * 8) + alpa_bit];
1301 k++;
1302 bfa_trc(port->fcs->bfa, k);
1303 bfa_trc(port->fcs->bfa,
1304 port->port_topo.ploop.alpa_pos_map[k]);
1305 }
1306 }
1307 }
1308 port->port_topo.ploop.num_alpa = k;
1309}
1310
1311/*
1312 * Called by fcs/port to initialize Loop topology.
1313 */
1314static void
1315bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port)
1316{
1317}
1318
1319/*
1320 * Called by fcs/port to notify transition to online state.
1321 */
1322static void
1323bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port)
1324{
1325 u8 num_alpa = 0, alpabm_valid = 0;
1326 struct bfa_fcs_rport_s *rport;
1327 u8 *alpa_map = NULL;
1328 int i = 0;
1329 u32 pid;
1330
1331 bfa_fcport_get_loop_attr(port);
1332
1333 num_alpa = port->port_topo.ploop.num_alpa;
1334 alpabm_valid = port->port_topo.ploop.alpabm_valid;
1335 alpa_map = port->port_topo.ploop.alpa_pos_map;
1336
1337 bfa_trc(port->fcs->bfa, port->pid);
1338 bfa_trc(port->fcs->bfa, num_alpa);
1339 if (alpabm_valid == 1) {
1340 for (i = 0; i < num_alpa; i++) {
1341 bfa_trc(port->fcs->bfa, alpa_map[i]);
1342 if (alpa_map[i] != bfa_hton3b(port->pid)) {
1343 pid = alpa_map[i];
1344 bfa_trc(port->fcs->bfa, pid);
1345 rport = bfa_fcs_lport_get_rport_by_pid(port,
1346 bfa_hton3b(pid));
1347 if (!rport)
1348 rport = bfa_fcs_rport_create(port,
1349 bfa_hton3b(pid));
1350 }
1351 }
1352 } else {
1353 for (i = 0; i < MAX_ALPA_COUNT; i++) {
1354 if (alpa_map[i] != port->pid) {
1355 pid = loop_alpa_map[i];
1356 bfa_trc(port->fcs->bfa, pid);
1357 rport = bfa_fcs_lport_get_rport_by_pid(port,
1358 bfa_hton3b(pid));
1359 if (!rport)
1360 rport = bfa_fcs_rport_create(port,
1361 bfa_hton3b(pid));
1362 }
1363 }
1364 }
1365}
1366
1367/*
1368 * Called by fcs/port to notify transition to offline state.
1369 */
1370static void
1371bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port)
1372{
1373}
1374
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001375#define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
1376
1377/*
1378 * forward declarations
1379 */
1380static void bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg,
1381 struct bfa_fcxp_s *fcxp_alloced);
1382static void bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg,
1383 struct bfa_fcxp_s *fcxp_alloced);
1384static void bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg,
1385 struct bfa_fcxp_s *fcxp_alloced);
1386static void bfa_fcs_lport_fdmi_rhba_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_rprt_response(void *fcsarg,
1394 struct bfa_fcxp_s *fcxp,
1395 void *cbarg,
1396 bfa_status_t req_status,
1397 u32 rsp_len,
1398 u32 resid_len,
1399 struct fchs_s *rsp_fchs);
1400static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg,
1401 struct bfa_fcxp_s *fcxp,
1402 void *cbarg,
1403 bfa_status_t req_status,
1404 u32 rsp_len,
1405 u32 resid_len,
1406 struct fchs_s *rsp_fchs);
1407static void bfa_fcs_lport_fdmi_timeout(void *arg);
1408static u16 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1409 u8 *pyld);
1410static u16 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1411 u8 *pyld);
1412static u16 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1413 u8 *pyld);
1414static u16 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *
1415 fdmi, u8 *pyld);
1416static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1417 struct bfa_fcs_fdmi_hba_attr_s *hba_attr);
1418static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1419 struct bfa_fcs_fdmi_port_attr_s *port_attr);
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001420u32 bfa_fcs_fdmi_convert_speed(enum bfa_port_speed pport_speed);
1421
Jing Huang5fbe25c2010-10-18 17:17:23 -07001422/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001423 * fcs_fdmi_sm FCS FDMI state machine
1424 */
1425
Jing Huang5fbe25c2010-10-18 17:17:23 -07001426/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001427 * FDMI State Machine events
1428 */
1429enum port_fdmi_event {
1430 FDMISM_EVENT_PORT_ONLINE = 1,
1431 FDMISM_EVENT_PORT_OFFLINE = 2,
1432 FDMISM_EVENT_RSP_OK = 4,
1433 FDMISM_EVENT_RSP_ERROR = 5,
1434 FDMISM_EVENT_TIMEOUT = 6,
1435 FDMISM_EVENT_RHBA_SENT = 7,
1436 FDMISM_EVENT_RPRT_SENT = 8,
1437 FDMISM_EVENT_RPA_SENT = 9,
1438};
1439
1440static void bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1441 enum port_fdmi_event event);
1442static void bfa_fcs_lport_fdmi_sm_sending_rhba(
1443 struct bfa_fcs_lport_fdmi_s *fdmi,
1444 enum port_fdmi_event event);
1445static void bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1446 enum port_fdmi_event event);
1447static void bfa_fcs_lport_fdmi_sm_rhba_retry(
1448 struct bfa_fcs_lport_fdmi_s *fdmi,
1449 enum port_fdmi_event event);
1450static void bfa_fcs_lport_fdmi_sm_sending_rprt(
1451 struct bfa_fcs_lport_fdmi_s *fdmi,
1452 enum port_fdmi_event event);
1453static void bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1454 enum port_fdmi_event event);
1455static void bfa_fcs_lport_fdmi_sm_rprt_retry(
1456 struct bfa_fcs_lport_fdmi_s *fdmi,
1457 enum port_fdmi_event event);
1458static void bfa_fcs_lport_fdmi_sm_sending_rpa(
1459 struct bfa_fcs_lport_fdmi_s *fdmi,
1460 enum port_fdmi_event event);
1461static void bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1462 enum port_fdmi_event event);
1463static void bfa_fcs_lport_fdmi_sm_rpa_retry(
1464 struct bfa_fcs_lport_fdmi_s *fdmi,
1465 enum port_fdmi_event event);
1466static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1467 enum port_fdmi_event event);
1468static void bfa_fcs_lport_fdmi_sm_disabled(
1469 struct bfa_fcs_lport_fdmi_s *fdmi,
1470 enum port_fdmi_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001471/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001472 * Start in offline state - awaiting MS to send start.
1473 */
1474static void
1475bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1476 enum port_fdmi_event event)
1477{
1478 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1479
1480 bfa_trc(port->fcs, port->port_cfg.pwwn);
1481 bfa_trc(port->fcs, event);
1482
1483 fdmi->retry_cnt = 0;
1484
1485 switch (event) {
1486 case FDMISM_EVENT_PORT_ONLINE:
1487 if (port->vport) {
1488 /*
1489 * For Vports, register a new port.
1490 */
1491 bfa_sm_set_state(fdmi,
1492 bfa_fcs_lport_fdmi_sm_sending_rprt);
1493 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1494 } else {
1495 /*
1496 * For a base port, we should first register the HBA
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001497 * attribute. The HBA attribute also contains the base
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001498 * port registration.
1499 */
1500 bfa_sm_set_state(fdmi,
1501 bfa_fcs_lport_fdmi_sm_sending_rhba);
1502 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1503 }
1504 break;
1505
1506 case FDMISM_EVENT_PORT_OFFLINE:
1507 break;
1508
1509 default:
1510 bfa_sm_fault(port->fcs, event);
1511 }
1512}
1513
1514static void
1515bfa_fcs_lport_fdmi_sm_sending_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1516 enum port_fdmi_event event)
1517{
1518 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1519
1520 bfa_trc(port->fcs, port->port_cfg.pwwn);
1521 bfa_trc(port->fcs, event);
1522
1523 switch (event) {
1524 case FDMISM_EVENT_RHBA_SENT:
1525 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rhba);
1526 break;
1527
1528 case FDMISM_EVENT_PORT_OFFLINE:
1529 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1530 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1531 &fdmi->fcxp_wqe);
1532 break;
1533
1534 default:
1535 bfa_sm_fault(port->fcs, event);
1536 }
1537}
1538
1539static void
1540bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1541 enum port_fdmi_event event)
1542{
1543 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1544
1545 bfa_trc(port->fcs, port->port_cfg.pwwn);
1546 bfa_trc(port->fcs, event);
1547
1548 switch (event) {
1549 case FDMISM_EVENT_RSP_ERROR:
1550 /*
1551 * if max retries have not been reached, start timer for a
1552 * delayed retry
1553 */
1554 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1555 bfa_sm_set_state(fdmi,
1556 bfa_fcs_lport_fdmi_sm_rhba_retry);
1557 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1558 &fdmi->timer,
1559 bfa_fcs_lport_fdmi_timeout, fdmi,
1560 BFA_FCS_RETRY_TIMEOUT);
1561 } else {
1562 /*
1563 * set state to offline
1564 */
1565 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1566 }
1567 break;
1568
1569 case FDMISM_EVENT_RSP_OK:
1570 /*
1571 * Initiate Register Port Attributes
1572 */
1573 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1574 fdmi->retry_cnt = 0;
1575 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1576 break;
1577
1578 case FDMISM_EVENT_PORT_OFFLINE:
1579 bfa_fcxp_discard(fdmi->fcxp);
1580 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1581 break;
1582
1583 default:
1584 bfa_sm_fault(port->fcs, event);
1585 }
1586}
1587
1588static void
1589bfa_fcs_lport_fdmi_sm_rhba_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1590 enum port_fdmi_event event)
1591{
1592 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1593
1594 bfa_trc(port->fcs, port->port_cfg.pwwn);
1595 bfa_trc(port->fcs, event);
1596
1597 switch (event) {
1598 case FDMISM_EVENT_TIMEOUT:
1599 /*
1600 * Retry Timer Expired. Re-send
1601 */
1602 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rhba);
1603 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1604 break;
1605
1606 case FDMISM_EVENT_PORT_OFFLINE:
1607 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1608 bfa_timer_stop(&fdmi->timer);
1609 break;
1610
1611 default:
1612 bfa_sm_fault(port->fcs, event);
1613 }
1614}
1615
1616/*
1617* RPRT : Register Port
1618 */
1619static void
1620bfa_fcs_lport_fdmi_sm_sending_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1621 enum port_fdmi_event event)
1622{
1623 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1624
1625 bfa_trc(port->fcs, port->port_cfg.pwwn);
1626 bfa_trc(port->fcs, event);
1627
1628 switch (event) {
1629 case FDMISM_EVENT_RPRT_SENT:
1630 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rprt);
1631 break;
1632
1633 case FDMISM_EVENT_PORT_OFFLINE:
1634 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1635 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1636 &fdmi->fcxp_wqe);
1637 break;
1638
1639 default:
1640 bfa_sm_fault(port->fcs, event);
1641 }
1642}
1643
1644static void
1645bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1646 enum port_fdmi_event event)
1647{
1648 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1649
1650 bfa_trc(port->fcs, port->port_cfg.pwwn);
1651 bfa_trc(port->fcs, event);
1652
1653 switch (event) {
1654 case FDMISM_EVENT_RSP_ERROR:
1655 /*
1656 * if max retries have not been reached, start timer for a
1657 * delayed retry
1658 */
1659 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1660 bfa_sm_set_state(fdmi,
1661 bfa_fcs_lport_fdmi_sm_rprt_retry);
1662 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1663 &fdmi->timer,
1664 bfa_fcs_lport_fdmi_timeout, fdmi,
1665 BFA_FCS_RETRY_TIMEOUT);
1666
1667 } else {
1668 /*
1669 * set state to offline
1670 */
1671 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1672 fdmi->retry_cnt = 0;
1673 }
1674 break;
1675
1676 case FDMISM_EVENT_RSP_OK:
1677 fdmi->retry_cnt = 0;
1678 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1679 break;
1680
1681 case FDMISM_EVENT_PORT_OFFLINE:
1682 bfa_fcxp_discard(fdmi->fcxp);
1683 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1684 break;
1685
1686 default:
1687 bfa_sm_fault(port->fcs, event);
1688 }
1689}
1690
1691static void
1692bfa_fcs_lport_fdmi_sm_rprt_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1693 enum port_fdmi_event event)
1694{
1695 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1696
1697 bfa_trc(port->fcs, port->port_cfg.pwwn);
1698 bfa_trc(port->fcs, event);
1699
1700 switch (event) {
1701 case FDMISM_EVENT_TIMEOUT:
1702 /*
1703 * Retry Timer Expired. Re-send
1704 */
1705 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rprt);
1706 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1707 break;
1708
1709 case FDMISM_EVENT_PORT_OFFLINE:
1710 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1711 bfa_timer_stop(&fdmi->timer);
1712 break;
1713
1714 default:
1715 bfa_sm_fault(port->fcs, event);
1716 }
1717}
1718
1719/*
1720 * Register Port Attributes
1721 */
1722static void
1723bfa_fcs_lport_fdmi_sm_sending_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1724 enum port_fdmi_event event)
1725{
1726 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1727
1728 bfa_trc(port->fcs, port->port_cfg.pwwn);
1729 bfa_trc(port->fcs, event);
1730
1731 switch (event) {
1732 case FDMISM_EVENT_RPA_SENT:
1733 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa);
1734 break;
1735
1736 case FDMISM_EVENT_PORT_OFFLINE:
1737 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1738 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1739 &fdmi->fcxp_wqe);
1740 break;
1741
1742 default:
1743 bfa_sm_fault(port->fcs, event);
1744 }
1745}
1746
1747static void
1748bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1749 enum port_fdmi_event event)
1750{
1751 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1752
1753 bfa_trc(port->fcs, port->port_cfg.pwwn);
1754 bfa_trc(port->fcs, event);
1755
1756 switch (event) {
1757 case FDMISM_EVENT_RSP_ERROR:
1758 /*
1759 * if max retries have not been reached, start timer for a
1760 * delayed retry
1761 */
1762 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1763 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa_retry);
1764 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1765 &fdmi->timer,
1766 bfa_fcs_lport_fdmi_timeout, fdmi,
1767 BFA_FCS_RETRY_TIMEOUT);
1768 } else {
1769 /*
1770 * set state to offline
1771 */
1772 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1773 fdmi->retry_cnt = 0;
1774 }
1775 break;
1776
1777 case FDMISM_EVENT_RSP_OK:
1778 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1779 fdmi->retry_cnt = 0;
1780 break;
1781
1782 case FDMISM_EVENT_PORT_OFFLINE:
1783 bfa_fcxp_discard(fdmi->fcxp);
1784 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1785 break;
1786
1787 default:
1788 bfa_sm_fault(port->fcs, event);
1789 }
1790}
1791
1792static void
1793bfa_fcs_lport_fdmi_sm_rpa_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1794 enum port_fdmi_event event)
1795{
1796 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1797
1798 bfa_trc(port->fcs, port->port_cfg.pwwn);
1799 bfa_trc(port->fcs, event);
1800
1801 switch (event) {
1802 case FDMISM_EVENT_TIMEOUT:
1803 /*
1804 * Retry Timer Expired. Re-send
1805 */
1806 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1807 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1808 break;
1809
1810 case FDMISM_EVENT_PORT_OFFLINE:
1811 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1812 bfa_timer_stop(&fdmi->timer);
1813 break;
1814
1815 default:
1816 bfa_sm_fault(port->fcs, event);
1817 }
1818}
1819
1820static void
1821bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1822 enum port_fdmi_event event)
1823{
1824 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1825
1826 bfa_trc(port->fcs, port->port_cfg.pwwn);
1827 bfa_trc(port->fcs, event);
1828
1829 switch (event) {
1830 case FDMISM_EVENT_PORT_OFFLINE:
1831 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1832 break;
1833
1834 default:
1835 bfa_sm_fault(port->fcs, event);
1836 }
1837}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001838/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001839 * FDMI is disabled state.
1840 */
1841static void
1842bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s *fdmi,
1843 enum port_fdmi_event event)
1844{
1845 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1846
1847 bfa_trc(port->fcs, port->port_cfg.pwwn);
1848 bfa_trc(port->fcs, event);
1849
1850 /* No op State. It can only be enabled at Driver Init. */
1851}
1852
Jing Huang5fbe25c2010-10-18 17:17:23 -07001853/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001854* RHBA : Register HBA Attributes.
1855 */
1856static void
1857bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1858{
1859 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
1860 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1861 struct fchs_s fchs;
1862 int len, attr_len;
1863 struct bfa_fcxp_s *fcxp;
1864 u8 *pyld;
1865
1866 bfa_trc(port->fcs, port->port_cfg.pwwn);
1867
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001868 fcxp = fcxp_alloced ? fcxp_alloced :
1869 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001870 if (!fcxp) {
1871 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001872 bfa_fcs_lport_fdmi_send_rhba, fdmi, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001873 return;
1874 }
1875 fdmi->fcxp = fcxp;
1876
1877 pyld = bfa_fcxp_get_reqbuf(fcxp);
Jing Huang6a18b162010-10-18 17:08:54 -07001878 memset(pyld, 0, FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001879
1880 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
1881 FDMI_RHBA);
1882
1883 attr_len =
1884 bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi,
1885 (u8 *) ((struct ct_hdr_s *) pyld
1886 + 1));
1887
1888 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1889 FC_CLASS_3, (len + attr_len), &fchs,
1890 bfa_fcs_lport_fdmi_rhba_response, (void *)fdmi,
1891 FC_MAX_PDUSZ, FC_FCCT_TOV);
1892
1893 bfa_sm_send_event(fdmi, FDMISM_EVENT_RHBA_SENT);
1894}
1895
1896static u16
1897bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1898{
1899 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1900 struct bfa_fcs_fdmi_hba_attr_s hba_attr;
1901 struct bfa_fcs_fdmi_hba_attr_s *fcs_hba_attr = &hba_attr;
1902 struct fdmi_rhba_s *rhba = (struct fdmi_rhba_s *) pyld;
1903 struct fdmi_attr_s *attr;
1904 u8 *curr_ptr;
1905 u16 len, count;
Maggie50444a32010-11-29 18:26:32 -08001906 u16 templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001907
1908 /*
1909 * get hba attributes
1910 */
1911 bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr);
1912
1913 rhba->hba_id = bfa_fcs_lport_get_pwwn(port);
Jing Huangba816ea2010-10-18 17:10:50 -07001914 rhba->port_list.num_ports = cpu_to_be32(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001915 rhba->port_list.port_entry = bfa_fcs_lport_get_pwwn(port);
1916
1917 len = sizeof(rhba->hba_id) + sizeof(rhba->port_list);
1918
1919 count = 0;
1920 len += sizeof(rhba->hba_attr_blk.attr_count);
1921
1922 /*
1923 * fill out the invididual entries of the HBA attrib Block
1924 */
1925 curr_ptr = (u8 *) &rhba->hba_attr_blk.hba_attr;
1926
1927 /*
1928 * Node Name
1929 */
1930 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001931 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME);
Maggie50444a32010-11-29 18:26:32 -08001932 templen = sizeof(wwn_t);
1933 memcpy(attr->value, &bfa_fcs_lport_get_nwwn(port), templen);
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 * Manufacturer
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_MANUFACTURER);
Maggie50444a32010-11-29 18:26:32 -08001945 templen = (u16) strlen(fcs_hba_attr->manufacturer);
1946 memcpy(attr->value, fcs_hba_attr->manufacturer, 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 * Serial Number
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_SERIALNUM);
Maggie50444a32010-11-29 18:26:32 -08001959 templen = (u16) strlen(fcs_hba_attr->serial_num);
1960 memcpy(attr->value, fcs_hba_attr->serial_num, 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
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);
Maggie50444a32010-11-29 18:26:32 -08001973 templen = (u16) strlen(fcs_hba_attr->model);
1974 memcpy(attr->value, fcs_hba_attr->model, 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 * Model Desc
1984 */
1985 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07001986 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC);
Maggie50444a32010-11-29 18:26:32 -08001987 templen = (u16) strlen(fcs_hba_attr->model_desc);
1988 memcpy(attr->value, fcs_hba_attr->model_desc, templen);
1989 templen = fc_roundup(templen, sizeof(u32));
1990 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1991 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001992 count++;
Maggie50444a32010-11-29 18:26:32 -08001993 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1994 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001995
1996 /*
1997 * H/W Version
1998 */
1999 if (fcs_hba_attr->hw_version[0] != '\0') {
2000 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002001 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION);
Maggie50444a32010-11-29 18:26:32 -08002002 templen = (u16) strlen(fcs_hba_attr->hw_version);
2003 memcpy(attr->value, fcs_hba_attr->hw_version, templen);
2004 templen = fc_roundup(templen, sizeof(u32));
2005 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2006 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002007 count++;
Maggie50444a32010-11-29 18:26:32 -08002008 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2009 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002010 }
2011
2012 /*
2013 * Driver Version
2014 */
2015 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002016 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION);
Maggie50444a32010-11-29 18:26:32 -08002017 templen = (u16) strlen(fcs_hba_attr->driver_version);
2018 memcpy(attr->value, fcs_hba_attr->driver_version, templen);
2019 templen = fc_roundup(templen, sizeof(u32));
2020 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07002021 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002022 count++;
Maggie50444a32010-11-29 18:26:32 -08002023 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2024 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002025
2026 /*
2027 * Option Rom Version
2028 */
2029 if (fcs_hba_attr->option_rom_ver[0] != '\0') {
2030 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002031 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION);
Maggie50444a32010-11-29 18:26:32 -08002032 templen = (u16) strlen(fcs_hba_attr->option_rom_ver);
2033 memcpy(attr->value, fcs_hba_attr->option_rom_ver, templen);
2034 templen = fc_roundup(templen, sizeof(u32));
2035 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2036 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002037 count++;
Maggie50444a32010-11-29 18:26:32 -08002038 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2039 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002040 }
2041
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002042 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002043 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION);
Krishna Gudipatib480a322012-09-21 17:25:20 -07002044 templen = (u16) strlen(fcs_hba_attr->fw_version);
2045 memcpy(attr->value, fcs_hba_attr->fw_version, templen);
Maggie50444a32010-11-29 18:26:32 -08002046 templen = fc_roundup(templen, sizeof(u32));
2047 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2048 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002049 count++;
Maggie50444a32010-11-29 18:26:32 -08002050 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2051 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002052
2053 /*
2054 * OS Name
2055 */
2056 if (fcs_hba_attr->os_name[0] != '\0') {
2057 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002058 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME);
Maggie50444a32010-11-29 18:26:32 -08002059 templen = (u16) strlen(fcs_hba_attr->os_name);
2060 memcpy(attr->value, fcs_hba_attr->os_name, templen);
2061 templen = fc_roundup(templen, sizeof(u32));
2062 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2063 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002064 count++;
Maggie50444a32010-11-29 18:26:32 -08002065 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2066 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002067 }
2068
2069 /*
2070 * MAX_CT_PAYLOAD
2071 */
2072 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002073 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT);
Maggie50444a32010-11-29 18:26:32 -08002074 templen = sizeof(fcs_hba_attr->max_ct_pyld);
2075 memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, templen);
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002076 templen = fc_roundup(templen, sizeof(u32));
2077 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
Maggie50444a32010-11-29 18:26:32 -08002078 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002079 count++;
Maggie50444a32010-11-29 18:26:32 -08002080 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2081 sizeof(templen));
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002082 /*
2083 * Send extended attributes ( FOS 7.1 support )
2084 */
2085 if (fdmi->retry_cnt == 0) {
2086 attr = (struct fdmi_attr_s *) curr_ptr;
2087 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODE_SYM_NAME);
2088 templen = sizeof(fcs_hba_attr->node_sym_name);
2089 memcpy(attr->value, &fcs_hba_attr->node_sym_name, templen);
2090 templen = fc_roundup(templen, sizeof(u32));
2091 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2092 len += templen;
2093 count++;
2094 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2095 sizeof(templen));
2096
2097 attr = (struct fdmi_attr_s *) curr_ptr;
2098 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_VENDOR_ID);
2099 templen = sizeof(fcs_hba_attr->vendor_info);
2100 memcpy(attr->value, &fcs_hba_attr->vendor_info, templen);
2101 templen = fc_roundup(templen, sizeof(u32));
2102 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2103 len += templen;
2104 count++;
2105 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2106 sizeof(templen));
2107
2108 attr = (struct fdmi_attr_s *) curr_ptr;
2109 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NUM_PORTS);
2110 templen = sizeof(fcs_hba_attr->num_ports);
2111 memcpy(attr->value, &fcs_hba_attr->num_ports, templen);
2112 templen = fc_roundup(templen, sizeof(u32));
2113 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2114 len += templen;
2115 count++;
2116 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2117 sizeof(templen));
2118
2119 attr = (struct fdmi_attr_s *) curr_ptr;
2120 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FABRIC_NAME);
2121 templen = sizeof(fcs_hba_attr->fabric_name);
2122 memcpy(attr->value, &fcs_hba_attr->fabric_name, templen);
2123 templen = fc_roundup(templen, sizeof(u32));
2124 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2125 len += templen;
2126 count++;
2127 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2128 sizeof(templen));
2129
2130 attr = (struct fdmi_attr_s *) curr_ptr;
2131 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_BIOS_VER);
2132 templen = sizeof(fcs_hba_attr->bios_ver);
2133 memcpy(attr->value, &fcs_hba_attr->bios_ver, templen);
2134 templen = fc_roundup(attr->len, sizeof(u32));
2135 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2136 len += templen;
2137 count++;
2138 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2139 sizeof(templen));
2140 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002141
2142 /*
2143 * Update size of payload
2144 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07002145 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002146
Jing Huangba816ea2010-10-18 17:10:50 -07002147 rhba->hba_attr_blk.attr_count = cpu_to_be32(count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002148 return len;
2149}
2150
2151static void
2152bfa_fcs_lport_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2153 void *cbarg, bfa_status_t req_status,
2154 u32 rsp_len, u32 resid_len,
2155 struct fchs_s *rsp_fchs)
2156{
2157 struct bfa_fcs_lport_fdmi_s *fdmi =
2158 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2159 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2160 struct ct_hdr_s *cthdr = NULL;
2161
2162 bfa_trc(port->fcs, port->port_cfg.pwwn);
2163
2164 /*
2165 * Sanity Checks
2166 */
2167 if (req_status != BFA_STATUS_OK) {
2168 bfa_trc(port->fcs, req_status);
2169 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2170 return;
2171 }
2172
2173 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07002174 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002175
2176 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2177 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2178 return;
2179 }
2180
2181 bfa_trc(port->fcs, cthdr->reason_code);
2182 bfa_trc(port->fcs, cthdr->exp_code);
2183 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2184}
2185
Jing Huang5fbe25c2010-10-18 17:17:23 -07002186/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002187* RPRT : Register Port
2188 */
2189static void
2190bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2191{
2192 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2193 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2194 struct fchs_s fchs;
2195 u16 len, attr_len;
2196 struct bfa_fcxp_s *fcxp;
2197 u8 *pyld;
2198
2199 bfa_trc(port->fcs, port->port_cfg.pwwn);
2200
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002201 fcxp = fcxp_alloced ? fcxp_alloced :
2202 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002203 if (!fcxp) {
2204 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002205 bfa_fcs_lport_fdmi_send_rprt, fdmi, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002206 return;
2207 }
2208 fdmi->fcxp = fcxp;
2209
2210 pyld = bfa_fcxp_get_reqbuf(fcxp);
Jing Huang6a18b162010-10-18 17:08:54 -07002211 memset(pyld, 0, FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002212
2213 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2214 FDMI_RPRT);
2215
2216 attr_len =
2217 bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi,
2218 (u8 *) ((struct ct_hdr_s *) pyld
2219 + 1));
2220
2221 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2222 FC_CLASS_3, len + attr_len, &fchs,
2223 bfa_fcs_lport_fdmi_rprt_response, (void *)fdmi,
2224 FC_MAX_PDUSZ, FC_FCCT_TOV);
2225
2226 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT);
2227}
2228
Jing Huang5fbe25c2010-10-18 17:17:23 -07002229/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002230 * This routine builds Port Attribute Block that used in RPA, RPRT commands.
2231 */
2232static u16
2233bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
2234 u8 *pyld)
2235{
2236 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
2237 struct fdmi_port_attr_s *port_attrib = (struct fdmi_port_attr_s *) pyld;
2238 struct fdmi_attr_s *attr;
2239 u8 *curr_ptr;
2240 u16 len;
2241 u8 count = 0;
Maggie50444a32010-11-29 18:26:32 -08002242 u16 templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002243
2244 /*
2245 * get port attributes
2246 */
2247 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2248
2249 len = sizeof(port_attrib->attr_count);
2250
2251 /*
2252 * fill out the invididual entries
2253 */
2254 curr_ptr = (u8 *) &port_attrib->port_attr;
2255
2256 /*
2257 * FC4 Types
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_FC4_TYPES);
Maggie50444a32010-11-29 18:26:32 -08002261 templen = sizeof(fcs_port_attr.supp_fc4_types);
2262 memcpy(attr->value, fcs_port_attr.supp_fc4_types, 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 * Supported 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_SUPP_SPEED);
Maggie50444a32010-11-29 18:26:32 -08002275 templen = sizeof(fcs_port_attr.supp_speed);
2276 memcpy(attr->value, &fcs_port_attr.supp_speed, templen);
2277 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2278 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002279 ++count;
2280 attr->len =
Maggie50444a32010-11-29 18:26:32 -08002281 cpu_to_be16(templen + sizeof(attr->type) +
2282 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002283
2284 /*
2285 * current Port Speed
2286 */
2287 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002288 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED);
Maggie50444a32010-11-29 18:26:32 -08002289 templen = sizeof(fcs_port_attr.curr_speed);
2290 memcpy(attr->value, &fcs_port_attr.curr_speed, templen);
2291 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2292 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002293 ++count;
Maggie50444a32010-11-29 18:26:32 -08002294 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2295 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002296
2297 /*
2298 * max frame size
2299 */
2300 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002301 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE);
Maggie50444a32010-11-29 18:26:32 -08002302 templen = sizeof(fcs_port_attr.max_frm_size);
2303 memcpy(attr->value, &fcs_port_attr.max_frm_size, templen);
2304 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2305 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002306 ++count;
Maggie50444a32010-11-29 18:26:32 -08002307 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2308 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002309
2310 /*
2311 * OS Device Name
2312 */
2313 if (fcs_port_attr.os_device_name[0] != '\0') {
2314 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002315 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME);
Maggie50444a32010-11-29 18:26:32 -08002316 templen = (u16) strlen(fcs_port_attr.os_device_name);
2317 memcpy(attr->value, fcs_port_attr.os_device_name, templen);
2318 templen = fc_roundup(templen, sizeof(u32));
2319 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2320 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002321 ++count;
Maggie50444a32010-11-29 18:26:32 -08002322 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2323 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002324 }
2325 /*
2326 * Host Name
2327 */
2328 if (fcs_port_attr.host_name[0] != '\0') {
2329 attr = (struct fdmi_attr_s *) curr_ptr;
Jing Huangba816ea2010-10-18 17:10:50 -07002330 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME);
Maggie50444a32010-11-29 18:26:32 -08002331 templen = (u16) strlen(fcs_port_attr.host_name);
2332 memcpy(attr->value, fcs_port_attr.host_name, templen);
2333 templen = fc_roundup(templen, sizeof(u32));
2334 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2335 len += templen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002336 ++count;
Maggie50444a32010-11-29 18:26:32 -08002337 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2338 sizeof(templen));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002339 }
2340
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002341 if (fdmi->retry_cnt == 0) {
2342 attr = (struct fdmi_attr_s *) curr_ptr;
2343 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_NODE_NAME);
2344 templen = sizeof(fcs_port_attr.node_name);
2345 memcpy(attr->value, &fcs_port_attr.node_name, templen);
2346 templen = fc_roundup(templen, sizeof(u32));
2347 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2348 len += templen;
2349 ++count;
2350 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2351 sizeof(templen));
2352
2353 attr = (struct fdmi_attr_s *) curr_ptr;
2354 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NAME);
2355 templen = sizeof(fcs_port_attr.port_name);
2356 memcpy(attr->value, &fcs_port_attr.port_name, templen);
2357 templen = fc_roundup(templen, sizeof(u32));
2358 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + templen;
2359 len += templen;
2360 ++count;
2361 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2362 sizeof(templen));
2363
2364 if (fcs_port_attr.port_sym_name.symname[0] != '\0') {
2365 attr = (struct fdmi_attr_s *) curr_ptr;
2366 attr->type =
2367 cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SYM_NAME);
2368 templen = sizeof(fcs_port_attr.port_sym_name);
2369 memcpy(attr->value,
2370 &fcs_port_attr.port_sym_name, templen);
2371 templen = fc_roundup(templen, sizeof(u32));
2372 curr_ptr += sizeof(attr->type) +
2373 sizeof(templen) + templen;
2374 len += templen;
2375 ++count;
2376 attr->len = cpu_to_be16(templen +
2377 sizeof(attr->type) + sizeof(templen));
2378 }
2379
2380 attr = (struct fdmi_attr_s *) curr_ptr;
2381 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_TYPE);
2382 templen = sizeof(fcs_port_attr.port_type);
2383 memcpy(attr->value, &fcs_port_attr.port_type, templen);
2384 templen = fc_roundup(templen, sizeof(u32));
2385 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2386 len += templen;
2387 ++count;
2388 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2389 sizeof(templen));
2390
2391 attr = (struct fdmi_attr_s *) curr_ptr;
2392 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_COS);
2393 templen = sizeof(fcs_port_attr.scos);
2394 memcpy(attr->value, &fcs_port_attr.scos, templen);
2395 templen = fc_roundup(templen, sizeof(u32));
2396 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2397 len += templen;
2398 ++count;
2399 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2400 sizeof(templen));
2401
2402 attr = (struct fdmi_attr_s *) curr_ptr;
2403 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FAB_NAME);
2404 templen = sizeof(fcs_port_attr.port_fabric_name);
2405 memcpy(attr->value, &fcs_port_attr.port_fabric_name, templen);
2406 templen = fc_roundup(templen, sizeof(u32));
2407 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2408 len += templen;
2409 ++count;
2410 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2411 sizeof(templen));
2412
2413 attr = (struct fdmi_attr_s *) curr_ptr;
2414 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FC4_TYPE);
2415 templen = sizeof(fcs_port_attr.port_act_fc4_type);
2416 memcpy(attr->value, fcs_port_attr.port_act_fc4_type,
2417 templen);
2418 templen = fc_roundup(templen, sizeof(u32));
2419 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2420 len += templen;
2421 ++count;
2422 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2423 sizeof(templen));
2424
2425 attr = (struct fdmi_attr_s *) curr_ptr;
2426 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_STATE);
2427 templen = sizeof(fcs_port_attr.port_state);
2428 memcpy(attr->value, &fcs_port_attr.port_state, templen);
2429 templen = fc_roundup(templen, sizeof(u32));
2430 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2431 len += templen;
2432 ++count;
2433 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2434 sizeof(templen));
2435
2436 attr = (struct fdmi_attr_s *) curr_ptr;
2437 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NUM_RPRT);
2438 templen = sizeof(fcs_port_attr.num_ports);
2439 memcpy(attr->value, &fcs_port_attr.num_ports, templen);
2440 templen = fc_roundup(templen, sizeof(u32));
2441 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2442 len += templen;
2443 ++count;
2444 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2445 sizeof(templen));
2446 }
2447
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002448 /*
2449 * Update size of payload
2450 */
Jing Huangba816ea2010-10-18 17:10:50 -07002451 port_attrib->attr_count = cpu_to_be32(count);
Jing Huang5fbe25c2010-10-18 17:17:23 -07002452 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002453 return len;
2454}
2455
2456static u16
2457bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2458{
2459 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2460 struct fdmi_rprt_s *rprt = (struct fdmi_rprt_s *) pyld;
2461 u16 len;
2462
2463 rprt->hba_id = bfa_fcs_lport_get_pwwn(bfa_fcs_get_base_port(port->fcs));
2464 rprt->port_name = bfa_fcs_lport_get_pwwn(port);
2465
2466 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2467 (u8 *) &rprt->port_attr_blk);
2468
2469 len += sizeof(rprt->hba_id) + sizeof(rprt->port_name);
2470
2471 return len;
2472}
2473
2474static void
2475bfa_fcs_lport_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2476 void *cbarg, bfa_status_t req_status,
2477 u32 rsp_len, u32 resid_len,
2478 struct fchs_s *rsp_fchs)
2479{
2480 struct bfa_fcs_lport_fdmi_s *fdmi =
2481 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2482 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2483 struct ct_hdr_s *cthdr = NULL;
2484
2485 bfa_trc(port->fcs, port->port_cfg.pwwn);
2486
2487 /*
2488 * Sanity Checks
2489 */
2490 if (req_status != BFA_STATUS_OK) {
2491 bfa_trc(port->fcs, req_status);
2492 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2493 return;
2494 }
2495
2496 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07002497 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002498
2499 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2500 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2501 return;
2502 }
2503
2504 bfa_trc(port->fcs, cthdr->reason_code);
2505 bfa_trc(port->fcs, cthdr->exp_code);
2506 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2507}
2508
Jing Huang5fbe25c2010-10-18 17:17:23 -07002509/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002510* RPA : Register Port Attributes.
2511 */
2512static void
2513bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2514{
2515 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2516 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2517 struct fchs_s fchs;
2518 u16 len, attr_len;
2519 struct bfa_fcxp_s *fcxp;
2520 u8 *pyld;
2521
2522 bfa_trc(port->fcs, port->port_cfg.pwwn);
2523
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002524 fcxp = fcxp_alloced ? fcxp_alloced :
2525 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002526 if (!fcxp) {
2527 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002528 bfa_fcs_lport_fdmi_send_rpa, fdmi, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002529 return;
2530 }
2531 fdmi->fcxp = fcxp;
2532
2533 pyld = bfa_fcxp_get_reqbuf(fcxp);
Jing Huang6a18b162010-10-18 17:08:54 -07002534 memset(pyld, 0, FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002535
2536 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2537 FDMI_RPA);
2538
Jing Huang5fbe25c2010-10-18 17:17:23 -07002539 attr_len = bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi,
2540 (u8 *) ((struct ct_hdr_s *) pyld + 1));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002541
2542 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2543 FC_CLASS_3, len + attr_len, &fchs,
2544 bfa_fcs_lport_fdmi_rpa_response, (void *)fdmi,
2545 FC_MAX_PDUSZ, FC_FCCT_TOV);
2546
2547 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPA_SENT);
2548}
2549
2550static u16
2551bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2552{
2553 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2554 struct fdmi_rpa_s *rpa = (struct fdmi_rpa_s *) pyld;
2555 u16 len;
2556
2557 rpa->port_name = bfa_fcs_lport_get_pwwn(port);
2558
2559 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2560 (u8 *) &rpa->port_attr_blk);
2561
2562 len += sizeof(rpa->port_name);
2563
2564 return len;
2565}
2566
2567static void
2568bfa_fcs_lport_fdmi_rpa_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2569 void *cbarg, bfa_status_t req_status, u32 rsp_len,
2570 u32 resid_len, struct fchs_s *rsp_fchs)
2571{
2572 struct bfa_fcs_lport_fdmi_s *fdmi =
2573 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2574 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2575 struct ct_hdr_s *cthdr = NULL;
2576
2577 bfa_trc(port->fcs, port->port_cfg.pwwn);
2578
2579 /*
2580 * Sanity Checks
2581 */
2582 if (req_status != BFA_STATUS_OK) {
2583 bfa_trc(port->fcs, req_status);
2584 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2585 return;
2586 }
2587
2588 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07002589 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002590
2591 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2592 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2593 return;
2594 }
2595
2596 bfa_trc(port->fcs, cthdr->reason_code);
2597 bfa_trc(port->fcs, cthdr->exp_code);
2598 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2599}
2600
2601static void
2602bfa_fcs_lport_fdmi_timeout(void *arg)
2603{
2604 struct bfa_fcs_lport_fdmi_s *fdmi = (struct bfa_fcs_lport_fdmi_s *) arg;
2605
2606 bfa_sm_send_event(fdmi, FDMISM_EVENT_TIMEOUT);
2607}
2608
Maggie52f94b62010-11-29 18:21:32 -08002609static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002610bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2611 struct bfa_fcs_fdmi_hba_attr_s *hba_attr)
2612{
2613 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2614 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
Krishna Gudipatib480a322012-09-21 17:25:20 -07002615 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002616
Jing Huang6a18b162010-10-18 17:08:54 -07002617 memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002618
2619 bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc,
2620 hba_attr->manufacturer);
2621 bfa_ioc_get_adapter_serial_num(&port->fcs->bfa->ioc,
2622 hba_attr->serial_num);
2623 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2624 hba_attr->model);
2625 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2626 hba_attr->model_desc);
2627 bfa_ioc_get_pci_chip_rev(&port->fcs->bfa->ioc,
2628 hba_attr->hw_version);
2629 bfa_ioc_get_adapter_optrom_ver(&port->fcs->bfa->ioc,
2630 hba_attr->option_rom_ver);
2631 bfa_ioc_get_adapter_fw_ver(&port->fcs->bfa->ioc,
2632 hba_attr->fw_version);
2633
Arnd Bergmann2de75632017-12-04 15:47:00 +01002634 strlcpy(hba_attr->driver_version, (char *)driver_info->version,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002635 sizeof(hba_attr->driver_version));
2636
Arnd Bergmann2de75632017-12-04 15:47:00 +01002637 strlcpy(hba_attr->os_name, driver_info->host_os_name,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002638 sizeof(hba_attr->os_name));
2639
2640 /*
2641 * If there is a patch level, append it
2642 * to the os name along with a separator
2643 */
2644 if (driver_info->host_os_patch[0] != '\0') {
Arnd Bergmann2de75632017-12-04 15:47:00 +01002645 strlcat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
2646 sizeof(hba_attr->os_name));
2647 strlcat(hba_attr->os_name, driver_info->host_os_patch,
2648 sizeof(hba_attr->os_name));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002649 }
2650
Krishna Gudipatib480a322012-09-21 17:25:20 -07002651 /* Retrieve the max frame size from the port attr */
2652 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2653 hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002654
Arnd Bergmann2de75632017-12-04 15:47:00 +01002655 strlcpy(hba_attr->node_sym_name.symname,
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002656 port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05002657 strcpy(hba_attr->vendor_info, "QLogic");
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002658 hba_attr->num_ports =
2659 cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
2660 hba_attr->fabric_name = port->fabric->lps->pr_nwwn;
Arnd Bergmann2de75632017-12-04 15:47:00 +01002661 strlcpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002662
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002663}
2664
Maggie52f94b62010-11-29 18:21:32 -08002665static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002666bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2667 struct bfa_fcs_fdmi_port_attr_s *port_attr)
2668{
2669 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2670 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2671 struct bfa_port_attr_s pport_attr;
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002672 struct bfa_lport_attr_s lport_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002673
Jing Huang6a18b162010-10-18 17:08:54 -07002674 memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002675
2676 /*
2677 * get pport attributes from hal
2678 */
2679 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
2680
2681 /*
2682 * get FC4 type Bitmask
2683 */
2684 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->supp_fc4_types);
2685
2686 /*
2687 * Supported Speeds
2688 */
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002689 switch (pport_attr.speed_supported) {
2690 case BFA_PORT_SPEED_16GBPS:
2691 port_attr->supp_speed =
2692 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_16G);
2693 break;
2694
2695 case BFA_PORT_SPEED_10GBPS:
2696 port_attr->supp_speed =
2697 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_10G);
2698 break;
2699
2700 case BFA_PORT_SPEED_8GBPS:
2701 port_attr->supp_speed =
2702 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_8G);
2703 break;
2704
2705 case BFA_PORT_SPEED_4GBPS:
2706 port_attr->supp_speed =
2707 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_4G);
2708 break;
2709
2710 default:
2711 bfa_sm_fault(port->fcs, pport_attr.speed_supported);
2712 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002713
2714 /*
2715 * Current Speed
2716 */
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002717 port_attr->curr_speed = cpu_to_be32(
2718 bfa_fcs_fdmi_convert_speed(pport_attr.speed));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002719
2720 /*
2721 * Max PDU Size.
2722 */
Krishna Gudipatib480a322012-09-21 17:25:20 -07002723 port_attr->max_frm_size = cpu_to_be32(pport_attr.pport_cfg.maxfrsize);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002724
2725 /*
2726 * OS device Name
2727 */
Arnd Bergmann2de75632017-12-04 15:47:00 +01002728 strlcpy(port_attr->os_device_name, driver_info->os_device_name,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002729 sizeof(port_attr->os_device_name));
2730
2731 /*
2732 * Host name
2733 */
Arnd Bergmann2de75632017-12-04 15:47:00 +01002734 strlcpy(port_attr->host_name, driver_info->host_machine_name,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002735 sizeof(port_attr->host_name));
Jing Huang7725ccf2009-09-23 17:46:15 -07002736
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002737 port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
2738 port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
2739
Arnd Bergmann2de75632017-12-04 15:47:00 +01002740 strlcpy(port_attr->port_sym_name.symname,
2741 bfa_fcs_lport_get_psym_name(port).symname, BFA_SYMNAME_MAXLEN);
Vijaya Mohan Guvvad7cbc302013-05-13 02:33:23 -07002742 bfa_fcs_lport_get_attr(port, &lport_attr);
2743 port_attr->port_type = cpu_to_be32(lport_attr.port_type);
2744 port_attr->scos = pport_attr.cos_supported;
2745 port_attr->port_fabric_name = port->fabric->lps->pr_nwwn;
2746 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->port_act_fc4_type);
2747 port_attr->port_state = cpu_to_be32(pport_attr.port_state);
2748 port_attr->num_ports = cpu_to_be32(port->num_rports);
Jing Huang7725ccf2009-09-23 17:46:15 -07002749}
2750
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002751/*
2752 * Convert BFA speed to FDMI format.
2753 */
2754u32
2755bfa_fcs_fdmi_convert_speed(bfa_port_speed_t pport_speed)
2756{
2757 u32 ret;
2758
2759 switch (pport_speed) {
2760 case BFA_PORT_SPEED_1GBPS:
2761 case BFA_PORT_SPEED_2GBPS:
2762 ret = pport_speed;
2763 break;
2764
2765 case BFA_PORT_SPEED_4GBPS:
2766 ret = FDMI_TRANS_SPEED_4G;
2767 break;
2768
2769 case BFA_PORT_SPEED_8GBPS:
2770 ret = FDMI_TRANS_SPEED_8G;
2771 break;
2772
2773 case BFA_PORT_SPEED_10GBPS:
2774 ret = FDMI_TRANS_SPEED_10G;
2775 break;
2776
2777 case BFA_PORT_SPEED_16GBPS:
2778 ret = FDMI_TRANS_SPEED_16G;
2779 break;
2780
2781 default:
2782 ret = FDMI_TRANS_SPEED_UNKNOWN;
2783 }
2784 return ret;
2785}
Jing Huang7725ccf2009-09-23 17:46:15 -07002786
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002787void
2788bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s *ms)
2789{
2790 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2791
2792 fdmi->ms = ms;
2793 if (ms->port->fcs->fdmi_enabled)
2794 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
2795 else
2796 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_disabled);
2797}
2798
2799void
2800bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s *ms)
2801{
2802 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2803
2804 fdmi->ms = ms;
2805 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
2806}
2807
2808void
2809bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s *ms)
2810{
2811 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2812
2813 fdmi->ms = ms;
2814 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_ONLINE);
2815}
2816
2817#define BFA_FCS_MS_CMD_MAX_RETRIES 2
2818
2819/*
2820 * forward declarations
2821 */
2822static void bfa_fcs_lport_ms_send_plogi(void *ms_cbarg,
2823 struct bfa_fcxp_s *fcxp_alloced);
2824static void bfa_fcs_lport_ms_timeout(void *arg);
2825static void bfa_fcs_lport_ms_plogi_response(void *fcsarg,
2826 struct bfa_fcxp_s *fcxp,
2827 void *cbarg,
2828 bfa_status_t req_status,
2829 u32 rsp_len,
2830 u32 resid_len,
2831 struct fchs_s *rsp_fchs);
2832
2833static void bfa_fcs_lport_ms_send_gmal(void *ms_cbarg,
2834 struct bfa_fcxp_s *fcxp_alloced);
2835static void bfa_fcs_lport_ms_gmal_response(void *fcsarg,
2836 struct bfa_fcxp_s *fcxp,
2837 void *cbarg,
2838 bfa_status_t req_status,
2839 u32 rsp_len,
2840 u32 resid_len,
2841 struct fchs_s *rsp_fchs);
2842static void bfa_fcs_lport_ms_send_gfn(void *ms_cbarg,
2843 struct bfa_fcxp_s *fcxp_alloced);
2844static void bfa_fcs_lport_ms_gfn_response(void *fcsarg,
2845 struct bfa_fcxp_s *fcxp,
2846 void *cbarg,
2847 bfa_status_t req_status,
2848 u32 rsp_len,
2849 u32 resid_len,
2850 struct fchs_s *rsp_fchs);
Jing Huang5fbe25c2010-10-18 17:17:23 -07002851/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002852 * fcs_ms_sm FCS MS state machine
2853 */
2854
Jing Huang5fbe25c2010-10-18 17:17:23 -07002855/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002856 * MS State Machine events
2857 */
2858enum port_ms_event {
2859 MSSM_EVENT_PORT_ONLINE = 1,
2860 MSSM_EVENT_PORT_OFFLINE = 2,
2861 MSSM_EVENT_RSP_OK = 3,
2862 MSSM_EVENT_RSP_ERROR = 4,
2863 MSSM_EVENT_TIMEOUT = 5,
2864 MSSM_EVENT_FCXP_SENT = 6,
2865 MSSM_EVENT_PORT_FABRIC_RSCN = 7
2866};
2867
2868static void bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2869 enum port_ms_event event);
2870static void bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2871 enum port_ms_event event);
2872static void bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2873 enum port_ms_event event);
2874static void bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2875 enum port_ms_event event);
2876static void bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
2877 enum port_ms_event event);
2878static void bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
2879 enum port_ms_event event);
2880static void bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
2881 enum port_ms_event event);
2882static void bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
2883 enum port_ms_event event);
2884static void bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
2885 enum port_ms_event event);
2886static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
2887 enum port_ms_event event);
2888static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
2889 enum port_ms_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -07002890/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002891 * Start in offline state - awaiting NS to send start.
2892 */
2893static void
2894bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2895 enum port_ms_event event)
2896{
2897 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2898 bfa_trc(ms->port->fcs, event);
2899
2900 switch (event) {
2901 case MSSM_EVENT_PORT_ONLINE:
2902 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
2903 bfa_fcs_lport_ms_send_plogi(ms, NULL);
2904 break;
2905
2906 case MSSM_EVENT_PORT_OFFLINE:
2907 break;
2908
2909 default:
2910 bfa_sm_fault(ms->port->fcs, event);
2911 }
2912}
2913
2914static void
2915bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2916 enum port_ms_event event)
2917{
2918 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2919 bfa_trc(ms->port->fcs, event);
2920
2921 switch (event) {
2922 case MSSM_EVENT_FCXP_SENT:
2923 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi);
2924 break;
2925
2926 case MSSM_EVENT_PORT_OFFLINE:
2927 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2928 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2929 &ms->fcxp_wqe);
2930 break;
2931
2932 default:
2933 bfa_sm_fault(ms->port->fcs, event);
2934 }
2935}
2936
2937static void
2938bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2939 enum port_ms_event event)
2940{
2941 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2942 bfa_trc(ms->port->fcs, event);
2943
2944 switch (event) {
2945 case MSSM_EVENT_RSP_ERROR:
2946 /*
2947 * Start timer for a delayed retry
2948 */
2949 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_retry);
2950 ms->port->stats.ms_retries++;
2951 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2952 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
2953 BFA_FCS_RETRY_TIMEOUT);
2954 break;
2955
2956 case MSSM_EVENT_RSP_OK:
2957 /*
2958 * since plogi is done, now invoke MS related sub-modules
2959 */
2960 bfa_fcs_lport_fdmi_online(ms);
2961
Jing Huang5fbe25c2010-10-18 17:17:23 -07002962 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002963 * if this is a Vport, go to online state.
2964 */
2965 if (ms->port->vport) {
2966 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
2967 break;
2968 }
2969
2970 /*
2971 * For a base port we need to get the
2972 * switch's IP address.
2973 */
2974 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
2975 bfa_fcs_lport_ms_send_gmal(ms, NULL);
2976 break;
2977
2978 case MSSM_EVENT_PORT_OFFLINE:
2979 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2980 bfa_fcxp_discard(ms->fcxp);
2981 break;
2982
2983 default:
2984 bfa_sm_fault(ms->port->fcs, event);
2985 }
2986}
2987
2988static void
2989bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2990 enum port_ms_event event)
2991{
2992 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2993 bfa_trc(ms->port->fcs, event);
2994
2995 switch (event) {
2996 case MSSM_EVENT_TIMEOUT:
2997 /*
2998 * Retry Timer Expired. Re-send
2999 */
3000 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
3001 bfa_fcs_lport_ms_send_plogi(ms, NULL);
3002 break;
3003
3004 case MSSM_EVENT_PORT_OFFLINE:
3005 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3006 bfa_timer_stop(&ms->timer);
3007 break;
3008
3009 default:
3010 bfa_sm_fault(ms->port->fcs, event);
3011 }
3012}
3013
3014static void
3015bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
3016 enum port_ms_event event)
3017{
3018 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3019 bfa_trc(ms->port->fcs, event);
3020
3021 switch (event) {
3022 case MSSM_EVENT_PORT_OFFLINE:
3023 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3024 break;
3025
3026 case MSSM_EVENT_PORT_FABRIC_RSCN:
3027 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3028 ms->retry_cnt = 0;
3029 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3030 break;
3031
3032 default:
3033 bfa_sm_fault(ms->port->fcs, event);
3034 }
3035}
3036
3037static void
3038bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
3039 enum port_ms_event event)
3040{
3041 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3042 bfa_trc(ms->port->fcs, event);
3043
3044 switch (event) {
3045 case MSSM_EVENT_FCXP_SENT:
3046 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal);
3047 break;
3048
3049 case MSSM_EVENT_PORT_OFFLINE:
3050 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3051 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3052 &ms->fcxp_wqe);
3053 break;
3054
3055 default:
3056 bfa_sm_fault(ms->port->fcs, event);
3057 }
3058}
3059
3060static void
3061bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
3062 enum port_ms_event event)
3063{
3064 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3065 bfa_trc(ms->port->fcs, event);
3066
3067 switch (event) {
3068 case MSSM_EVENT_RSP_ERROR:
3069 /*
3070 * Start timer for a delayed retry
3071 */
3072 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
3073 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_retry);
3074 ms->port->stats.ms_retries++;
3075 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3076 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
3077 BFA_FCS_RETRY_TIMEOUT);
3078 } else {
3079 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3080 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3081 ms->retry_cnt = 0;
3082 }
3083 break;
3084
3085 case MSSM_EVENT_RSP_OK:
3086 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3087 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3088 break;
3089
3090 case MSSM_EVENT_PORT_OFFLINE:
3091 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3092 bfa_fcxp_discard(ms->fcxp);
3093 break;
3094
3095 default:
3096 bfa_sm_fault(ms->port->fcs, event);
3097 }
3098}
3099
3100static void
3101bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
3102 enum port_ms_event event)
3103{
3104 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3105 bfa_trc(ms->port->fcs, event);
3106
3107 switch (event) {
3108 case MSSM_EVENT_TIMEOUT:
3109 /*
3110 * Retry Timer Expired. Re-send
3111 */
3112 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
3113 bfa_fcs_lport_ms_send_gmal(ms, NULL);
3114 break;
3115
3116 case MSSM_EVENT_PORT_OFFLINE:
3117 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3118 bfa_timer_stop(&ms->timer);
3119 break;
3120
3121 default:
3122 bfa_sm_fault(ms->port->fcs, event);
3123 }
3124}
Jing Huang5fbe25c2010-10-18 17:17:23 -07003125/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003126 * ms_pvt MS local functions
3127 */
3128
3129static void
3130bfa_fcs_lport_ms_send_gmal(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3131{
3132 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3133 bfa_fcs_lport_t *port = ms->port;
3134 struct fchs_s fchs;
3135 int len;
3136 struct bfa_fcxp_s *fcxp;
3137
3138 bfa_trc(port->fcs, port->pid);
3139
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003140 fcxp = fcxp_alloced ? fcxp_alloced :
3141 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003142 if (!fcxp) {
3143 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003144 bfa_fcs_lport_ms_send_gmal, ms, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003145 return;
3146 }
3147 ms->fcxp = fcxp;
3148
3149 len = fc_gmal_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3150 bfa_fcs_lport_get_fcid(port),
Maggie Zhangf7f738122010-12-09 19:08:43 -08003151 port->fabric->lps->pr_nwwn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003152
3153 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3154 FC_CLASS_3, len, &fchs,
3155 bfa_fcs_lport_ms_gmal_response, (void *)ms,
3156 FC_MAX_PDUSZ, FC_FCCT_TOV);
3157
3158 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3159}
3160
3161static void
3162bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3163 void *cbarg, bfa_status_t req_status,
3164 u32 rsp_len, u32 resid_len,
3165 struct fchs_s *rsp_fchs)
3166{
3167 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3168 bfa_fcs_lport_t *port = ms->port;
3169 struct ct_hdr_s *cthdr = NULL;
3170 struct fcgs_gmal_resp_s *gmal_resp;
3171 struct fcgs_gmal_entry_s *gmal_entry;
3172 u32 num_entries;
3173 u8 *rsp_str;
3174
3175 bfa_trc(port->fcs, req_status);
3176 bfa_trc(port->fcs, port->port_cfg.pwwn);
3177
3178 /*
3179 * Sanity Checks
3180 */
3181 if (req_status != BFA_STATUS_OK) {
3182 bfa_trc(port->fcs, req_status);
3183 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3184 return;
3185 }
3186
3187 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07003188 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003189
3190 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3191 gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
3192
Jing Huangba816ea2010-10-18 17:10:50 -07003193 num_entries = be32_to_cpu(gmal_resp->ms_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003194 if (num_entries == 0) {
3195 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3196 return;
3197 }
3198 /*
3199 * The response could contain multiple Entries.
3200 * Entries for SNMP interface, etc.
3201 * We look for the entry with a telnet prefix.
3202 * First "http://" entry refers to IP addr
3203 */
3204
3205 gmal_entry = (struct fcgs_gmal_entry_s *)gmal_resp->ms_ma;
3206 while (num_entries > 0) {
3207 if (strncmp(gmal_entry->prefix,
3208 CT_GMAL_RESP_PREFIX_HTTP,
3209 sizeof(gmal_entry->prefix)) == 0) {
3210
3211 /*
3212 * if the IP address is terminating with a '/',
3213 * remove it.
3214 * Byte 0 consists of the length of the string.
3215 */
3216 rsp_str = &(gmal_entry->prefix[0]);
3217 if (rsp_str[gmal_entry->len-1] == '/')
3218 rsp_str[gmal_entry->len-1] = 0;
3219
3220 /* copy IP Address to fabric */
Arnd Bergmann2de75632017-12-04 15:47:00 +01003221 strlcpy(bfa_fcs_lport_get_fabric_ipaddr(port),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003222 gmal_entry->ip_addr,
3223 BFA_FCS_FABRIC_IPADDR_SZ);
3224 break;
3225 } else {
3226 --num_entries;
3227 ++gmal_entry;
3228 }
3229 }
3230
3231 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3232 return;
3233 }
3234
3235 bfa_trc(port->fcs, cthdr->reason_code);
3236 bfa_trc(port->fcs, cthdr->exp_code);
3237 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3238}
3239
3240static void
3241bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
3242 enum port_ms_event event)
3243{
3244 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3245 bfa_trc(ms->port->fcs, event);
3246
3247 switch (event) {
3248 case MSSM_EVENT_FCXP_SENT:
3249 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn);
3250 break;
3251
3252 case MSSM_EVENT_PORT_OFFLINE:
3253 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3254 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3255 &ms->fcxp_wqe);
3256 break;
3257
3258 default:
3259 bfa_sm_fault(ms->port->fcs, event);
3260 }
3261}
3262
3263static void
3264bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
3265 enum port_ms_event event)
3266{
3267 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3268 bfa_trc(ms->port->fcs, event);
3269
3270 switch (event) {
3271 case MSSM_EVENT_RSP_ERROR:
3272 /*
3273 * Start timer for a delayed retry
3274 */
3275 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
3276 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_retry);
3277 ms->port->stats.ms_retries++;
3278 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3279 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
3280 BFA_FCS_RETRY_TIMEOUT);
3281 } else {
3282 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3283 ms->retry_cnt = 0;
3284 }
3285 break;
3286
3287 case MSSM_EVENT_RSP_OK:
3288 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3289 break;
3290
3291 case MSSM_EVENT_PORT_OFFLINE:
3292 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3293 bfa_fcxp_discard(ms->fcxp);
3294 break;
3295
3296 default:
3297 bfa_sm_fault(ms->port->fcs, event);
3298 }
3299}
3300
3301static void
3302bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
3303 enum port_ms_event event)
3304{
3305 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3306 bfa_trc(ms->port->fcs, event);
3307
3308 switch (event) {
3309 case MSSM_EVENT_TIMEOUT:
3310 /*
3311 * Retry Timer Expired. Re-send
3312 */
3313 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3314 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3315 break;
3316
3317 case MSSM_EVENT_PORT_OFFLINE:
3318 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3319 bfa_timer_stop(&ms->timer);
3320 break;
3321
3322 default:
3323 bfa_sm_fault(ms->port->fcs, event);
3324 }
3325}
Jing Huang5fbe25c2010-10-18 17:17:23 -07003326/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003327 * ms_pvt MS local functions
3328 */
3329
3330static void
3331bfa_fcs_lport_ms_send_gfn(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3332{
3333 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3334 bfa_fcs_lport_t *port = ms->port;
3335 struct fchs_s fchs;
3336 int len;
3337 struct bfa_fcxp_s *fcxp;
3338
3339 bfa_trc(port->fcs, port->pid);
3340
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003341 fcxp = fcxp_alloced ? fcxp_alloced :
3342 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003343 if (!fcxp) {
3344 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003345 bfa_fcs_lport_ms_send_gfn, ms, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003346 return;
3347 }
3348 ms->fcxp = fcxp;
3349
3350 len = fc_gfn_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3351 bfa_fcs_lport_get_fcid(port),
Maggie Zhangf7f738122010-12-09 19:08:43 -08003352 port->fabric->lps->pr_nwwn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003353
3354 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3355 FC_CLASS_3, len, &fchs,
3356 bfa_fcs_lport_ms_gfn_response, (void *)ms,
3357 FC_MAX_PDUSZ, FC_FCCT_TOV);
3358
3359 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3360}
3361
3362static void
3363bfa_fcs_lport_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3364 void *cbarg, bfa_status_t req_status, u32 rsp_len,
3365 u32 resid_len, struct fchs_s *rsp_fchs)
3366{
3367 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3368 bfa_fcs_lport_t *port = ms->port;
3369 struct ct_hdr_s *cthdr = NULL;
3370 wwn_t *gfn_resp;
3371
3372 bfa_trc(port->fcs, req_status);
3373 bfa_trc(port->fcs, port->port_cfg.pwwn);
3374
3375 /*
3376 * Sanity Checks
3377 */
3378 if (req_status != BFA_STATUS_OK) {
3379 bfa_trc(port->fcs, req_status);
3380 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3381 return;
3382 }
3383
3384 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07003385 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003386
3387 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3388 gfn_resp = (wwn_t *)(cthdr + 1);
3389 /* check if it has actually changed */
3390 if ((memcmp((void *)&bfa_fcs_lport_get_fabric_name(port),
3391 gfn_resp, sizeof(wwn_t)) != 0)) {
3392 bfa_fcs_fabric_set_fabric_name(port->fabric, *gfn_resp);
3393 }
3394 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3395 return;
3396 }
3397
3398 bfa_trc(port->fcs, cthdr->reason_code);
3399 bfa_trc(port->fcs, cthdr->exp_code);
3400 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3401}
3402
Jing Huang5fbe25c2010-10-18 17:17:23 -07003403/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003404 * ms_pvt MS local functions
3405 */
3406
3407static void
3408bfa_fcs_lport_ms_send_plogi(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3409{
3410 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3411 struct bfa_fcs_lport_s *port = ms->port;
3412 struct fchs_s fchs;
3413 int len;
3414 struct bfa_fcxp_s *fcxp;
3415
3416 bfa_trc(port->fcs, port->pid);
3417
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003418 fcxp = fcxp_alloced ? fcxp_alloced :
3419 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003420 if (!fcxp) {
3421 port->stats.ms_plogi_alloc_wait++;
3422 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003423 bfa_fcs_lport_ms_send_plogi, ms, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003424 return;
3425 }
3426 ms->fcxp = fcxp;
3427
3428 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08003429 bfa_hton3b(FC_MGMT_SERVER),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003430 bfa_fcs_lport_get_fcid(port), 0,
3431 port->port_cfg.pwwn, port->port_cfg.nwwn,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003432 bfa_fcport_get_maxfrsize(port->fcs->bfa),
3433 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003434
3435 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3436 FC_CLASS_3, len, &fchs,
3437 bfa_fcs_lport_ms_plogi_response, (void *)ms,
3438 FC_MAX_PDUSZ, FC_ELS_TOV);
3439
3440 port->stats.ms_plogi_sent++;
3441 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3442}
3443
3444static void
3445bfa_fcs_lport_ms_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3446 void *cbarg, bfa_status_t req_status,
3447 u32 rsp_len, u32 resid_len, struct fchs_s *rsp_fchs)
3448{
3449 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3450 struct bfa_fcs_lport_s *port = ms->port;
3451 struct fc_els_cmd_s *els_cmd;
3452 struct fc_ls_rjt_s *ls_rjt;
3453
3454 bfa_trc(port->fcs, req_status);
3455 bfa_trc(port->fcs, port->port_cfg.pwwn);
3456
3457 /*
3458 * Sanity Checks
3459 */
3460 if (req_status != BFA_STATUS_OK) {
3461 port->stats.ms_plogi_rsp_err++;
3462 bfa_trc(port->fcs, req_status);
3463 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3464 return;
3465 }
3466
3467 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
3468
3469 switch (els_cmd->els_code) {
3470
3471 case FC_ELS_ACC:
3472 if (rsp_len < sizeof(struct fc_logi_s)) {
3473 bfa_trc(port->fcs, rsp_len);
3474 port->stats.ms_plogi_acc_err++;
3475 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3476 break;
3477 }
3478 port->stats.ms_plogi_accepts++;
3479 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3480 break;
3481
3482 case FC_ELS_LS_RJT:
3483 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
3484
3485 bfa_trc(port->fcs, ls_rjt->reason_code);
3486 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
3487
3488 port->stats.ms_rejects++;
3489 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3490 break;
3491
3492 default:
3493 port->stats.ms_plogi_unknown_rsp++;
3494 bfa_trc(port->fcs, els_cmd->els_code);
3495 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3496 }
3497}
3498
3499static void
3500bfa_fcs_lport_ms_timeout(void *arg)
3501{
3502 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) arg;
3503
3504 ms->port->stats.ms_timeouts++;
3505 bfa_sm_send_event(ms, MSSM_EVENT_TIMEOUT);
3506}
3507
3508
3509void
3510bfa_fcs_lport_ms_init(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_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3516
3517 /*
3518 * Invoke init routines of sub modules.
3519 */
3520 bfa_fcs_lport_fdmi_init(ms);
3521}
3522
3523void
3524bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s *port)
3525{
3526 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3527
3528 ms->port = port;
3529 bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
3530 bfa_fcs_lport_fdmi_offline(ms);
3531}
3532
3533void
3534bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s *port)
3535{
3536 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3537
3538 ms->port = port;
3539 bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
3540}
3541void
3542bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s *port)
3543{
3544 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3545
3546 /* todo. Handle this only when in Online state */
3547 if (bfa_sm_cmp_state(ms, bfa_fcs_lport_ms_sm_online))
3548 bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
3549}
3550
Jing Huang5fbe25c2010-10-18 17:17:23 -07003551/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003552 * @page ns_sm_info VPORT NS State Machine
3553 *
3554 * @section ns_sm_interactions VPORT NS State Machine Interactions
3555 *
3556 * @section ns_sm VPORT NS State Machine
3557 * img ns_sm.jpg
3558 */
3559
3560/*
3561 * forward declarations
3562 */
3563static void bfa_fcs_lport_ns_send_plogi(void *ns_cbarg,
3564 struct bfa_fcxp_s *fcxp_alloced);
3565static void bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg,
3566 struct bfa_fcxp_s *fcxp_alloced);
3567static void bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg,
3568 struct bfa_fcxp_s *fcxp_alloced);
3569static void bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg,
3570 struct bfa_fcxp_s *fcxp_alloced);
3571static void bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg,
3572 struct bfa_fcxp_s *fcxp_alloced);
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003573static void bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg,
3574 struct bfa_fcxp_s *fcxp_alloced);
3575static void bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg,
3576 struct bfa_fcxp_s *fcxp_alloced);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003577static void bfa_fcs_lport_ns_timeout(void *arg);
3578static void bfa_fcs_lport_ns_plogi_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_rspn_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_rft_id_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);
3599static void bfa_fcs_lport_ns_rff_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_gid_ft_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 Gudipatice7242b2012-08-22 19:52:43 -07003613static void bfa_fcs_lport_ns_rnn_id_response(void *fcsarg,
3614 struct bfa_fcxp_s *fcxp,
3615 void *cbarg,
3616 bfa_status_t req_status,
3617 u32 rsp_len,
3618 u32 resid_len,
3619 struct fchs_s *rsp_fchs);
3620static void bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg,
3621 struct bfa_fcxp_s *fcxp,
3622 void *cbarg,
3623 bfa_status_t req_status,
3624 u32 rsp_len,
3625 u32 resid_len,
3626 struct fchs_s *rsp_fchs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003627static void bfa_fcs_lport_ns_process_gidft_pids(
3628 struct bfa_fcs_lport_s *port,
3629 u32 *pid_buf, u32 n_pids);
3630
3631static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port);
Jing Huang5fbe25c2010-10-18 17:17:23 -07003632/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003633 * fcs_ns_sm FCS nameserver interface state machine
3634 */
3635
Jing Huang5fbe25c2010-10-18 17:17:23 -07003636/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003637 * VPort NS State Machine events
3638 */
3639enum vport_ns_event {
3640 NSSM_EVENT_PORT_ONLINE = 1,
3641 NSSM_EVENT_PORT_OFFLINE = 2,
3642 NSSM_EVENT_PLOGI_SENT = 3,
3643 NSSM_EVENT_RSP_OK = 4,
3644 NSSM_EVENT_RSP_ERROR = 5,
3645 NSSM_EVENT_TIMEOUT = 6,
3646 NSSM_EVENT_NS_QUERY = 7,
3647 NSSM_EVENT_RSPNID_SENT = 8,
3648 NSSM_EVENT_RFTID_SENT = 9,
3649 NSSM_EVENT_RFFID_SENT = 10,
3650 NSSM_EVENT_GIDFT_SENT = 11,
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003651 NSSM_EVENT_RNNID_SENT = 12,
3652 NSSM_EVENT_RSNN_NN_SENT = 13,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003653};
3654
3655static void bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3656 enum vport_ns_event event);
3657static void bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3658 enum vport_ns_event event);
3659static void bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3660 enum vport_ns_event event);
3661static void bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3662 enum vport_ns_event event);
3663static void bfa_fcs_lport_ns_sm_sending_rspn_id(
3664 struct bfa_fcs_lport_ns_s *ns,
3665 enum vport_ns_event event);
3666static void bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3667 enum vport_ns_event event);
3668static void bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3669 enum vport_ns_event event);
3670static void bfa_fcs_lport_ns_sm_sending_rft_id(
3671 struct bfa_fcs_lport_ns_s *ns,
3672 enum vport_ns_event event);
3673static void bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
3674 enum vport_ns_event event);
3675static void bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
3676 enum vport_ns_event event);
3677static void bfa_fcs_lport_ns_sm_sending_rff_id(
3678 struct bfa_fcs_lport_ns_s *ns,
3679 enum vport_ns_event event);
3680static void bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
3681 enum vport_ns_event event);
3682static void bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
3683 enum vport_ns_event event);
3684static void bfa_fcs_lport_ns_sm_sending_gid_ft(
3685 struct bfa_fcs_lport_ns_s *ns,
3686 enum vport_ns_event event);
3687static void bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
3688 enum vport_ns_event event);
3689static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
3690 enum vport_ns_event event);
3691static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
3692 enum vport_ns_event event);
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003693static void bfa_fcs_lport_ns_sm_sending_rnn_id(
3694 struct bfa_fcs_lport_ns_s *ns,
3695 enum vport_ns_event event);
3696static void bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3697 enum vport_ns_event event);
3698static void bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3699 enum vport_ns_event event);
3700static void bfa_fcs_lport_ns_sm_sending_rsnn_nn(
3701 struct bfa_fcs_lport_ns_s *ns,
3702 enum vport_ns_event event);
3703static void bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3704 enum vport_ns_event event);
3705static void bfa_fcs_lport_ns_sm_rsnn_nn_retry(
3706 struct bfa_fcs_lport_ns_s *ns,
3707 enum vport_ns_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -07003708/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003709 * Start in offline state - awaiting linkup
3710 */
3711static void
3712bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3713 enum vport_ns_event event)
3714{
3715 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3716 bfa_trc(ns->port->fcs, event);
3717
3718 switch (event) {
3719 case NSSM_EVENT_PORT_ONLINE:
3720 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3721 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3722 break;
3723
3724 case NSSM_EVENT_PORT_OFFLINE:
3725 break;
3726
3727 default:
3728 bfa_sm_fault(ns->port->fcs, event);
3729 }
3730}
3731
3732static void
3733bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3734 enum vport_ns_event event)
3735{
3736 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3737 bfa_trc(ns->port->fcs, event);
3738
3739 switch (event) {
3740 case NSSM_EVENT_PLOGI_SENT:
3741 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi);
3742 break;
3743
3744 case NSSM_EVENT_PORT_OFFLINE:
3745 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3746 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3747 &ns->fcxp_wqe);
3748 break;
3749
3750 default:
3751 bfa_sm_fault(ns->port->fcs, event);
3752 }
3753}
3754
3755static void
3756bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3757 enum vport_ns_event event)
3758{
3759 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3760 bfa_trc(ns->port->fcs, event);
3761
3762 switch (event) {
3763 case NSSM_EVENT_RSP_ERROR:
3764 /*
3765 * Start timer for a delayed retry
3766 */
3767 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_retry);
3768 ns->port->stats.ns_retries++;
3769 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3770 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3771 BFA_FCS_RETRY_TIMEOUT);
3772 break;
3773
3774 case NSSM_EVENT_RSP_OK:
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003775 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3776 ns->num_rnnid_retries = 0;
3777 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003778 break;
3779
3780 case NSSM_EVENT_PORT_OFFLINE:
3781 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3782 bfa_fcxp_discard(ns->fcxp);
3783 break;
3784
3785 default:
3786 bfa_sm_fault(ns->port->fcs, event);
3787 }
3788}
3789
3790static void
3791bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3792 enum vport_ns_event event)
3793{
3794 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3795 bfa_trc(ns->port->fcs, event);
3796
3797 switch (event) {
3798 case NSSM_EVENT_TIMEOUT:
3799 /*
3800 * Retry Timer Expired. Re-send
3801 */
3802 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3803 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3804 break;
3805
3806 case NSSM_EVENT_PORT_OFFLINE:
3807 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3808 bfa_timer_stop(&ns->timer);
3809 break;
3810
3811 default:
3812 bfa_sm_fault(ns->port->fcs, event);
3813 }
3814}
3815
3816static void
Krishna Gudipatice7242b2012-08-22 19:52:43 -07003817bfa_fcs_lport_ns_sm_sending_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3818 enum vport_ns_event event)
3819{
3820 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3821 bfa_trc(ns->port->fcs, event);
3822
3823 switch (event) {
3824 case NSSM_EVENT_RNNID_SENT:
3825 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id);
3826 break;
3827
3828 case NSSM_EVENT_PORT_OFFLINE:
3829 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3830 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3831 &ns->fcxp_wqe);
3832 break;
3833 default:
3834 bfa_sm_fault(ns->port->fcs, event);
3835 }
3836}
3837
3838static void
3839bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3840 enum vport_ns_event event)
3841{
3842 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3843 bfa_trc(ns->port->fcs, event);
3844
3845 switch (event) {
3846 case NSSM_EVENT_RSP_OK:
3847 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3848 ns->num_rnnid_retries = 0;
3849 ns->num_rsnn_nn_retries = 0;
3850 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3851 break;
3852
3853 case NSSM_EVENT_RSP_ERROR:
3854 if (ns->num_rnnid_retries < BFA_FCS_MAX_NS_RETRIES) {
3855 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id_retry);
3856 ns->port->stats.ns_retries++;
3857 ns->num_rnnid_retries++;
3858 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3859 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3860 BFA_FCS_RETRY_TIMEOUT);
3861 } else {
3862 bfa_sm_set_state(ns,
3863 bfa_fcs_lport_ns_sm_sending_rspn_id);
3864 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3865 }
3866 break;
3867
3868 case NSSM_EVENT_PORT_OFFLINE:
3869 bfa_fcxp_discard(ns->fcxp);
3870 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3871 break;
3872
3873 default:
3874 bfa_sm_fault(ns->port->fcs, event);
3875 }
3876}
3877
3878static void
3879bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3880 enum vport_ns_event event)
3881{
3882 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3883 bfa_trc(ns->port->fcs, event);
3884
3885 switch (event) {
3886 case NSSM_EVENT_TIMEOUT:
3887 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3888 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
3889 break;
3890
3891 case NSSM_EVENT_PORT_OFFLINE:
3892 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3893 bfa_timer_stop(&ns->timer);
3894 break;
3895
3896 default:
3897 bfa_sm_fault(ns->port->fcs, event);
3898 }
3899}
3900
3901static void
3902bfa_fcs_lport_ns_sm_sending_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3903 enum vport_ns_event event)
3904{
3905 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3906 bfa_trc(ns->port->fcs, event);
3907
3908 switch (event) {
3909 case NSSM_EVENT_RSNN_NN_SENT:
3910 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn);
3911 break;
3912
3913 case NSSM_EVENT_PORT_OFFLINE:
3914 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3915 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3916 &ns->fcxp_wqe);
3917 break;
3918
3919 default:
3920 bfa_sm_fault(ns->port->fcs, event);
3921 }
3922}
3923
3924static void
3925bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3926 enum vport_ns_event event)
3927{
3928 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3929 bfa_trc(ns->port->fcs, event);
3930
3931 switch (event) {
3932 case NSSM_EVENT_RSP_OK:
3933 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
3934 ns->num_rsnn_nn_retries = 0;
3935 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3936 break;
3937
3938 case NSSM_EVENT_RSP_ERROR:
3939 if (ns->num_rsnn_nn_retries < BFA_FCS_MAX_NS_RETRIES) {
3940 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn_retry);
3941 ns->port->stats.ns_retries++;
3942 ns->num_rsnn_nn_retries++;
3943 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3944 &ns->timer, bfa_fcs_lport_ns_timeout,
3945 ns, BFA_FCS_RETRY_TIMEOUT);
3946 } else {
3947 bfa_sm_set_state(ns,
3948 bfa_fcs_lport_ns_sm_sending_rspn_id);
3949 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3950 }
3951 break;
3952
3953 case NSSM_EVENT_PORT_OFFLINE:
3954 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3955 bfa_fcxp_discard(ns->fcxp);
3956 break;
3957
3958 default:
3959 bfa_sm_fault(ns->port->fcs, event);
3960 }
3961}
3962
3963static void
3964bfa_fcs_lport_ns_sm_rsnn_nn_retry(struct bfa_fcs_lport_ns_s *ns,
3965 enum vport_ns_event event)
3966{
3967 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3968 bfa_trc(ns->port->fcs, event);
3969
3970 switch (event) {
3971 case NSSM_EVENT_TIMEOUT:
3972 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3973 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3974 break;
3975
3976 case NSSM_EVENT_PORT_OFFLINE:
3977 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3978 bfa_timer_stop(&ns->timer);
3979 break;
3980
3981 default:
3982 bfa_sm_fault(ns->port->fcs, event);
3983 }
3984}
3985
3986static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003987bfa_fcs_lport_ns_sm_sending_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3988 enum vport_ns_event event)
3989{
3990 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3991 bfa_trc(ns->port->fcs, event);
3992
3993 switch (event) {
3994 case NSSM_EVENT_RSPNID_SENT:
3995 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id);
3996 break;
3997
3998 case NSSM_EVENT_PORT_OFFLINE:
3999 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4000 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4001 &ns->fcxp_wqe);
4002 break;
4003
4004 default:
4005 bfa_sm_fault(ns->port->fcs, event);
4006 }
4007}
4008
4009static void
4010bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
4011 enum vport_ns_event event)
4012{
4013 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4014 bfa_trc(ns->port->fcs, event);
4015
4016 switch (event) {
4017 case NSSM_EVENT_RSP_ERROR:
4018 /*
4019 * Start timer for a delayed retry
4020 */
4021 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry);
4022 ns->port->stats.ns_retries++;
4023 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4024 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4025 BFA_FCS_RETRY_TIMEOUT);
4026 break;
4027
4028 case NSSM_EVENT_RSP_OK:
4029 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
4030 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
4031 break;
4032
4033 case NSSM_EVENT_PORT_OFFLINE:
4034 bfa_fcxp_discard(ns->fcxp);
4035 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4036 break;
4037
4038 default:
4039 bfa_sm_fault(ns->port->fcs, event);
4040 }
4041}
4042
4043static void
4044bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
4045 enum vport_ns_event event)
4046{
4047 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4048 bfa_trc(ns->port->fcs, event);
4049
4050 switch (event) {
4051 case NSSM_EVENT_TIMEOUT:
4052 /*
4053 * Retry Timer Expired. Re-send
4054 */
4055 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
4056 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
4057 break;
4058
4059 case NSSM_EVENT_PORT_OFFLINE:
4060 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4061 bfa_timer_stop(&ns->timer);
4062 break;
4063
4064 default:
4065 bfa_sm_fault(ns->port->fcs, event);
4066 }
4067}
4068
4069static void
4070bfa_fcs_lport_ns_sm_sending_rft_id(struct bfa_fcs_lport_ns_s *ns,
4071 enum vport_ns_event event)
4072{
4073 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4074 bfa_trc(ns->port->fcs, event);
4075
4076 switch (event) {
4077 case NSSM_EVENT_RFTID_SENT:
4078 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id);
4079 break;
4080
4081 case NSSM_EVENT_PORT_OFFLINE:
4082 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4083 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4084 &ns->fcxp_wqe);
4085 break;
4086
4087 default:
4088 bfa_sm_fault(ns->port->fcs, event);
4089 }
4090}
4091
4092static void
4093bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
4094 enum vport_ns_event event)
4095{
4096 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4097 bfa_trc(ns->port->fcs, event);
4098
4099 switch (event) {
4100 case NSSM_EVENT_RSP_OK:
4101 /* Now move to register FC4 Features */
4102 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
4103 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
4104 break;
4105
4106 case NSSM_EVENT_RSP_ERROR:
4107 /*
4108 * Start timer for a delayed retry
4109 */
4110 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id_retry);
4111 ns->port->stats.ns_retries++;
4112 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4113 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4114 BFA_FCS_RETRY_TIMEOUT);
4115 break;
4116
4117 case NSSM_EVENT_PORT_OFFLINE:
4118 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4119 bfa_fcxp_discard(ns->fcxp);
4120 break;
4121
4122 default:
4123 bfa_sm_fault(ns->port->fcs, event);
4124 }
4125}
4126
4127static void
4128bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
4129 enum vport_ns_event event)
4130{
4131 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4132 bfa_trc(ns->port->fcs, event);
4133
4134 switch (event) {
4135 case NSSM_EVENT_TIMEOUT:
4136 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
4137 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
4138 break;
4139
4140 case NSSM_EVENT_PORT_OFFLINE:
4141 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4142 bfa_timer_stop(&ns->timer);
4143 break;
4144
4145 default:
4146 bfa_sm_fault(ns->port->fcs, event);
4147 }
4148}
4149
4150static void
4151bfa_fcs_lport_ns_sm_sending_rff_id(struct bfa_fcs_lport_ns_s *ns,
4152 enum vport_ns_event event)
4153{
4154 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4155 bfa_trc(ns->port->fcs, event);
4156
4157 switch (event) {
4158 case NSSM_EVENT_RFFID_SENT:
4159 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id);
4160 break;
4161
4162 case NSSM_EVENT_PORT_OFFLINE:
4163 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4164 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4165 &ns->fcxp_wqe);
4166 break;
4167
4168 default:
4169 bfa_sm_fault(ns->port->fcs, event);
4170 }
4171}
4172
4173static void
4174bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
4175 enum vport_ns_event event)
4176{
4177 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4178 bfa_trc(ns->port->fcs, event);
4179
4180 switch (event) {
4181 case NSSM_EVENT_RSP_OK:
4182
4183 /*
4184 * If min cfg mode is enabled, we donot initiate rport
4185 * discovery with the fabric. Instead, we will retrieve the
4186 * boot targets from HAL/FW.
4187 */
4188 if (__fcs_min_cfg(ns->port->fcs)) {
4189 bfa_fcs_lport_ns_boot_target_disc(ns->port);
4190 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
4191 return;
4192 }
4193
4194 /*
4195 * If the port role is Initiator Mode issue NS query.
4196 * If it is Target Mode, skip this and go to online.
4197 */
4198 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4199 bfa_sm_set_state(ns,
4200 bfa_fcs_lport_ns_sm_sending_gid_ft);
4201 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4202 }
4203 /*
4204 * kick off mgmt srvr state machine
4205 */
4206 bfa_fcs_lport_ms_online(ns->port);
4207 break;
4208
4209 case NSSM_EVENT_RSP_ERROR:
4210 /*
4211 * Start timer for a delayed retry
4212 */
4213 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id_retry);
4214 ns->port->stats.ns_retries++;
4215 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4216 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4217 BFA_FCS_RETRY_TIMEOUT);
4218 break;
4219
4220 case NSSM_EVENT_PORT_OFFLINE:
4221 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4222 bfa_fcxp_discard(ns->fcxp);
4223 break;
4224
4225 default:
4226 bfa_sm_fault(ns->port->fcs, event);
4227 }
4228}
4229
4230static void
4231bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
4232 enum vport_ns_event event)
4233{
4234 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4235 bfa_trc(ns->port->fcs, event);
4236
4237 switch (event) {
4238 case NSSM_EVENT_TIMEOUT:
4239 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
4240 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
4241 break;
4242
4243 case NSSM_EVENT_PORT_OFFLINE:
4244 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4245 bfa_timer_stop(&ns->timer);
4246 break;
4247
4248 default:
4249 bfa_sm_fault(ns->port->fcs, event);
4250 }
4251}
4252static void
4253bfa_fcs_lport_ns_sm_sending_gid_ft(struct bfa_fcs_lport_ns_s *ns,
4254 enum vport_ns_event event)
4255{
4256 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4257 bfa_trc(ns->port->fcs, event);
4258
4259 switch (event) {
4260 case NSSM_EVENT_GIDFT_SENT:
4261 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft);
4262 break;
4263
4264 case NSSM_EVENT_PORT_OFFLINE:
4265 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4266 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4267 &ns->fcxp_wqe);
4268 break;
4269
4270 default:
4271 bfa_sm_fault(ns->port->fcs, event);
4272 }
4273}
4274
4275static void
4276bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
4277 enum vport_ns_event event)
4278{
4279 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4280 bfa_trc(ns->port->fcs, event);
4281
4282 switch (event) {
4283 case NSSM_EVENT_RSP_OK:
4284 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
4285 break;
4286
4287 case NSSM_EVENT_RSP_ERROR:
4288 /*
4289 * TBD: for certain reject codes, we don't need to retry
4290 */
4291 /*
4292 * Start timer for a delayed retry
4293 */
4294 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft_retry);
4295 ns->port->stats.ns_retries++;
4296 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4297 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4298 BFA_FCS_RETRY_TIMEOUT);
4299 break;
4300
4301 case NSSM_EVENT_PORT_OFFLINE:
4302 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4303 bfa_fcxp_discard(ns->fcxp);
4304 break;
4305
4306 case NSSM_EVENT_NS_QUERY:
4307 break;
4308
4309 default:
4310 bfa_sm_fault(ns->port->fcs, event);
4311 }
4312}
4313
4314static void
4315bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
4316 enum vport_ns_event event)
4317{
4318 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4319 bfa_trc(ns->port->fcs, event);
4320
4321 switch (event) {
4322 case NSSM_EVENT_TIMEOUT:
4323 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_gid_ft);
4324 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4325 break;
4326
4327 case NSSM_EVENT_PORT_OFFLINE:
4328 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4329 bfa_timer_stop(&ns->timer);
4330 break;
4331
4332 default:
4333 bfa_sm_fault(ns->port->fcs, event);
4334 }
4335}
4336
4337static void
4338bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
4339 enum vport_ns_event event)
4340{
4341 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4342 bfa_trc(ns->port->fcs, event);
4343
4344 switch (event) {
4345 case NSSM_EVENT_PORT_OFFLINE:
4346 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4347 break;
4348
4349 case NSSM_EVENT_NS_QUERY:
4350 /*
4351 * If the port role is Initiator Mode issue NS query.
4352 * If it is Target Mode, skip this and go to online.
4353 */
4354 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4355 bfa_sm_set_state(ns,
4356 bfa_fcs_lport_ns_sm_sending_gid_ft);
4357 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4358 };
4359 break;
4360
4361 default:
4362 bfa_sm_fault(ns->port->fcs, event);
4363 }
4364}
4365
4366
4367
Jing Huang5fbe25c2010-10-18 17:17:23 -07004368/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004369 * ns_pvt Nameserver local functions
4370 */
4371
4372static void
4373bfa_fcs_lport_ns_send_plogi(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4374{
4375 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4376 struct bfa_fcs_lport_s *port = ns->port;
4377 struct fchs_s fchs;
4378 int len;
4379 struct bfa_fcxp_s *fcxp;
4380
4381 bfa_trc(port->fcs, port->pid);
4382
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004383 fcxp = fcxp_alloced ? fcxp_alloced :
4384 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004385 if (!fcxp) {
4386 port->stats.ns_plogi_alloc_wait++;
4387 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004388 bfa_fcs_lport_ns_send_plogi, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004389 return;
4390 }
4391 ns->fcxp = fcxp;
4392
4393 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08004394 bfa_hton3b(FC_NAME_SERVER),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004395 bfa_fcs_lport_get_fcid(port), 0,
4396 port->port_cfg.pwwn, port->port_cfg.nwwn,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07004397 bfa_fcport_get_maxfrsize(port->fcs->bfa),
4398 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004399
4400 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4401 FC_CLASS_3, len, &fchs,
4402 bfa_fcs_lport_ns_plogi_response, (void *)ns,
4403 FC_MAX_PDUSZ, FC_ELS_TOV);
4404 port->stats.ns_plogi_sent++;
4405
4406 bfa_sm_send_event(ns, NSSM_EVENT_PLOGI_SENT);
4407}
4408
4409static void
4410bfa_fcs_lport_ns_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4411 void *cbarg, bfa_status_t req_status, u32 rsp_len,
4412 u32 resid_len, struct fchs_s *rsp_fchs)
4413{
4414 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4415 struct bfa_fcs_lport_s *port = ns->port;
4416 /* struct fc_logi_s *plogi_resp; */
4417 struct fc_els_cmd_s *els_cmd;
4418 struct fc_ls_rjt_s *ls_rjt;
4419
4420 bfa_trc(port->fcs, req_status);
4421 bfa_trc(port->fcs, port->port_cfg.pwwn);
4422
4423 /*
4424 * Sanity Checks
4425 */
4426 if (req_status != BFA_STATUS_OK) {
4427 bfa_trc(port->fcs, req_status);
4428 port->stats.ns_plogi_rsp_err++;
4429 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4430 return;
4431 }
4432
4433 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
4434
4435 switch (els_cmd->els_code) {
4436
4437 case FC_ELS_ACC:
4438 if (rsp_len < sizeof(struct fc_logi_s)) {
4439 bfa_trc(port->fcs, rsp_len);
4440 port->stats.ns_plogi_acc_err++;
4441 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4442 break;
4443 }
4444 port->stats.ns_plogi_accepts++;
4445 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4446 break;
4447
4448 case FC_ELS_LS_RJT:
4449 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
4450
4451 bfa_trc(port->fcs, ls_rjt->reason_code);
4452 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
4453
4454 port->stats.ns_rejects++;
4455
4456 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4457 break;
4458
4459 default:
4460 port->stats.ns_plogi_unknown_rsp++;
4461 bfa_trc(port->fcs, els_cmd->els_code);
4462 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4463 }
4464}
4465
Jing Huang5fbe25c2010-10-18 17:17:23 -07004466/*
Krishna Gudipatice7242b2012-08-22 19:52:43 -07004467 * Register node name for port_id
4468 */
4469static void
4470bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4471{
4472 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4473 struct bfa_fcs_lport_s *port = ns->port;
4474 struct fchs_s fchs;
4475 int len;
4476 struct bfa_fcxp_s *fcxp;
4477
4478 bfa_trc(port->fcs, port->port_cfg.pwwn);
4479
4480 fcxp = fcxp_alloced ? fcxp_alloced :
4481 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4482 if (!fcxp) {
4483 port->stats.ns_rnnid_alloc_wait++;
4484 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4485 bfa_fcs_lport_ns_send_rnn_id, ns, BFA_TRUE);
4486 return;
4487 }
4488
4489 ns->fcxp = fcxp;
4490
4491 len = fc_rnnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4492 bfa_fcs_lport_get_fcid(port),
4493 bfa_fcs_lport_get_fcid(port),
4494 bfa_fcs_lport_get_nwwn(port));
4495
4496 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4497 FC_CLASS_3, len, &fchs,
4498 bfa_fcs_lport_ns_rnn_id_response, (void *)ns,
4499 FC_MAX_PDUSZ, FC_FCCT_TOV);
4500
4501 port->stats.ns_rnnid_sent++;
4502 bfa_sm_send_event(ns, NSSM_EVENT_RNNID_SENT);
4503}
4504
4505static void
4506bfa_fcs_lport_ns_rnn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4507 void *cbarg, bfa_status_t req_status,
4508 u32 rsp_len, u32 resid_len,
4509 struct fchs_s *rsp_fchs)
4510
4511{
4512 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4513 struct bfa_fcs_lport_s *port = ns->port;
4514 struct ct_hdr_s *cthdr = NULL;
4515
4516 bfa_trc(port->fcs, port->port_cfg.pwwn);
4517
4518 /*
4519 * Sanity Checks
4520 */
4521 if (req_status != BFA_STATUS_OK) {
4522 bfa_trc(port->fcs, req_status);
4523 port->stats.ns_rnnid_rsp_err++;
4524 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4525 return;
4526 }
4527
4528 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4529 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4530
4531 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4532 port->stats.ns_rnnid_accepts++;
4533 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4534 return;
4535 }
4536
4537 port->stats.ns_rnnid_rejects++;
4538 bfa_trc(port->fcs, cthdr->reason_code);
4539 bfa_trc(port->fcs, cthdr->exp_code);
4540 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4541}
4542
4543/*
4544 * Register the symbolic node name for a given node name.
4545 */
4546static void
4547bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4548{
4549 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4550 struct bfa_fcs_lport_s *port = ns->port;
4551 struct fchs_s fchs;
4552 int len;
4553 struct bfa_fcxp_s *fcxp;
4554 u8 *nsymbl;
4555
4556 bfa_trc(port->fcs, port->port_cfg.pwwn);
4557
4558 fcxp = fcxp_alloced ? fcxp_alloced :
4559 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4560 if (!fcxp) {
4561 port->stats.ns_rsnn_nn_alloc_wait++;
4562 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4563 bfa_fcs_lport_ns_send_rsnn_nn, ns, BFA_TRUE);
4564 return;
4565 }
4566 ns->fcxp = fcxp;
4567
4568 nsymbl = (u8 *) &(bfa_fcs_lport_get_nsym_name(
4569 bfa_fcs_get_base_port(port->fcs)));
4570
4571 len = fc_rsnn_nn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4572 bfa_fcs_lport_get_fcid(port),
4573 bfa_fcs_lport_get_nwwn(port), nsymbl);
4574
4575 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4576 FC_CLASS_3, len, &fchs,
4577 bfa_fcs_lport_ns_rsnn_nn_response, (void *)ns,
4578 FC_MAX_PDUSZ, FC_FCCT_TOV);
4579
4580 port->stats.ns_rsnn_nn_sent++;
4581
4582 bfa_sm_send_event(ns, NSSM_EVENT_RSNN_NN_SENT);
4583}
4584
4585static void
4586bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4587 void *cbarg, bfa_status_t req_status,
4588 u32 rsp_len, u32 resid_len,
4589 struct fchs_s *rsp_fchs)
4590{
4591 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4592 struct bfa_fcs_lport_s *port = ns->port;
4593 struct ct_hdr_s *cthdr = NULL;
4594
4595 bfa_trc(port->fcs, port->port_cfg.pwwn);
4596
4597 /*
4598 * Sanity Checks
4599 */
4600 if (req_status != BFA_STATUS_OK) {
4601 bfa_trc(port->fcs, req_status);
4602 port->stats.ns_rsnn_nn_rsp_err++;
4603 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4604 return;
4605 }
4606
4607 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4608 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4609
4610 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4611 port->stats.ns_rsnn_nn_accepts++;
4612 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4613 return;
4614 }
4615
4616 port->stats.ns_rsnn_nn_rejects++;
4617 bfa_trc(port->fcs, cthdr->reason_code);
4618 bfa_trc(port->fcs, cthdr->exp_code);
4619 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4620}
4621
4622/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004623 * Register the symbolic port name.
4624 */
4625static void
4626bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4627{
4628 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4629 struct bfa_fcs_lport_s *port = ns->port;
4630 struct fchs_s fchs;
4631 int len;
4632 struct bfa_fcxp_s *fcxp;
4633 u8 symbl[256];
4634 u8 *psymbl = &symbl[0];
4635
Jing Huang6a18b162010-10-18 17:08:54 -07004636 memset(symbl, 0, sizeof(symbl));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004637
4638 bfa_trc(port->fcs, port->port_cfg.pwwn);
4639
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004640 fcxp = fcxp_alloced ? fcxp_alloced :
4641 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004642 if (!fcxp) {
4643 port->stats.ns_rspnid_alloc_wait++;
4644 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004645 bfa_fcs_lport_ns_send_rspn_id, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004646 return;
4647 }
4648 ns->fcxp = fcxp;
4649
4650 /*
4651 * for V-Port, form a Port Symbolic Name
4652 */
4653 if (port->vport) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07004654 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004655 * For Vports, we append the vport's port symbolic name
4656 * to that of the base port.
4657 */
4658
Arnd Bergmann2de75632017-12-04 15:47:00 +01004659 strlcpy(symbl,
4660 (char *)&(bfa_fcs_lport_get_psym_name
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004661 (bfa_fcs_get_base_port(port->fcs))),
Arnd Bergmann2de75632017-12-04 15:47:00 +01004662 sizeof(symbl));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004663
Arnd Bergmann2de75632017-12-04 15:47:00 +01004664 strlcat(symbl, (char *)&(bfa_fcs_lport_get_psym_name(port)),
4665 sizeof(symbl));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004666 } else {
4667 psymbl = (u8 *) &(bfa_fcs_lport_get_psym_name(port));
4668 }
4669
4670 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4671 bfa_fcs_lport_get_fcid(port), 0, psymbl);
4672
4673 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4674 FC_CLASS_3, len, &fchs,
4675 bfa_fcs_lport_ns_rspn_id_response, (void *)ns,
4676 FC_MAX_PDUSZ, FC_FCCT_TOV);
4677
4678 port->stats.ns_rspnid_sent++;
4679
4680 bfa_sm_send_event(ns, NSSM_EVENT_RSPNID_SENT);
4681}
4682
4683static void
4684bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4685 void *cbarg, bfa_status_t req_status,
4686 u32 rsp_len, u32 resid_len,
4687 struct fchs_s *rsp_fchs)
4688{
4689 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4690 struct bfa_fcs_lport_s *port = ns->port;
4691 struct ct_hdr_s *cthdr = NULL;
4692
4693 bfa_trc(port->fcs, port->port_cfg.pwwn);
4694
4695 /*
4696 * Sanity Checks
4697 */
4698 if (req_status != BFA_STATUS_OK) {
4699 bfa_trc(port->fcs, req_status);
4700 port->stats.ns_rspnid_rsp_err++;
4701 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4702 return;
4703 }
4704
4705 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004706 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004707
4708 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4709 port->stats.ns_rspnid_accepts++;
4710 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4711 return;
4712 }
4713
4714 port->stats.ns_rspnid_rejects++;
4715 bfa_trc(port->fcs, cthdr->reason_code);
4716 bfa_trc(port->fcs, cthdr->exp_code);
4717 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4718}
4719
Jing Huang5fbe25c2010-10-18 17:17:23 -07004720/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004721 * Register FC4-Types
4722 */
4723static void
4724bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4725{
4726 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4727 struct bfa_fcs_lport_s *port = ns->port;
4728 struct fchs_s fchs;
4729 int len;
4730 struct bfa_fcxp_s *fcxp;
4731
4732 bfa_trc(port->fcs, port->port_cfg.pwwn);
4733
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004734 fcxp = fcxp_alloced ? fcxp_alloced :
4735 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004736 if (!fcxp) {
4737 port->stats.ns_rftid_alloc_wait++;
4738 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004739 bfa_fcs_lport_ns_send_rft_id, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004740 return;
4741 }
4742 ns->fcxp = fcxp;
4743
4744 len = fc_rftid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4745 bfa_fcs_lport_get_fcid(port), 0, port->port_cfg.roles);
4746
4747 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4748 FC_CLASS_3, len, &fchs,
4749 bfa_fcs_lport_ns_rft_id_response, (void *)ns,
4750 FC_MAX_PDUSZ, FC_FCCT_TOV);
4751
4752 port->stats.ns_rftid_sent++;
4753 bfa_sm_send_event(ns, NSSM_EVENT_RFTID_SENT);
4754}
4755
4756static void
4757bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4758 void *cbarg, bfa_status_t req_status,
4759 u32 rsp_len, u32 resid_len,
4760 struct fchs_s *rsp_fchs)
4761{
4762 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4763 struct bfa_fcs_lport_s *port = ns->port;
4764 struct ct_hdr_s *cthdr = NULL;
4765
4766 bfa_trc(port->fcs, port->port_cfg.pwwn);
4767
4768 /*
4769 * Sanity Checks
4770 */
4771 if (req_status != BFA_STATUS_OK) {
4772 bfa_trc(port->fcs, req_status);
4773 port->stats.ns_rftid_rsp_err++;
4774 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4775 return;
4776 }
4777
4778 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004779 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004780
4781 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4782 port->stats.ns_rftid_accepts++;
4783 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4784 return;
4785 }
4786
4787 port->stats.ns_rftid_rejects++;
4788 bfa_trc(port->fcs, cthdr->reason_code);
4789 bfa_trc(port->fcs, cthdr->exp_code);
4790 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4791}
4792
Jing Huang5fbe25c2010-10-18 17:17:23 -07004793/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004794 * Register FC4-Features : Should be done after RFT_ID
4795 */
4796static void
4797bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4798{
4799 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4800 struct bfa_fcs_lport_s *port = ns->port;
4801 struct fchs_s fchs;
4802 int len;
4803 struct bfa_fcxp_s *fcxp;
4804 u8 fc4_ftrs = 0;
4805
4806 bfa_trc(port->fcs, port->port_cfg.pwwn);
4807
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004808 fcxp = fcxp_alloced ? fcxp_alloced :
4809 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004810 if (!fcxp) {
4811 port->stats.ns_rffid_alloc_wait++;
4812 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004813 bfa_fcs_lport_ns_send_rff_id, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004814 return;
4815 }
4816 ns->fcxp = fcxp;
4817
4818 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port))
4819 fc4_ftrs = FC_GS_FCP_FC4_FEATURE_INITIATOR;
4820
4821 len = fc_rffid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4822 bfa_fcs_lport_get_fcid(port), 0,
4823 FC_TYPE_FCP, fc4_ftrs);
4824
4825 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4826 FC_CLASS_3, len, &fchs,
4827 bfa_fcs_lport_ns_rff_id_response, (void *)ns,
4828 FC_MAX_PDUSZ, FC_FCCT_TOV);
4829
4830 port->stats.ns_rffid_sent++;
4831 bfa_sm_send_event(ns, NSSM_EVENT_RFFID_SENT);
4832}
4833
4834static void
4835bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4836 void *cbarg, bfa_status_t req_status,
4837 u32 rsp_len, u32 resid_len,
4838 struct fchs_s *rsp_fchs)
4839{
4840 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4841 struct bfa_fcs_lport_s *port = ns->port;
4842 struct ct_hdr_s *cthdr = NULL;
4843
4844 bfa_trc(port->fcs, port->port_cfg.pwwn);
4845
4846 /*
4847 * Sanity Checks
4848 */
4849 if (req_status != BFA_STATUS_OK) {
4850 bfa_trc(port->fcs, req_status);
4851 port->stats.ns_rffid_rsp_err++;
4852 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4853 return;
4854 }
4855
4856 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004857 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004858
4859 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4860 port->stats.ns_rffid_accepts++;
4861 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4862 return;
4863 }
4864
4865 port->stats.ns_rffid_rejects++;
4866 bfa_trc(port->fcs, cthdr->reason_code);
4867 bfa_trc(port->fcs, cthdr->exp_code);
4868
4869 if (cthdr->reason_code == CT_RSN_NOT_SUPP) {
4870 /* if this command is not supported, we don't retry */
4871 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4872 } else
4873 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4874}
Jing Huang5fbe25c2010-10-18 17:17:23 -07004875/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004876 * Query Fabric for FC4-Types Devices.
4877 *
4878* TBD : Need to use a local (FCS private) response buffer, since the response
4879 * can be larger than 2K.
4880 */
4881static void
4882bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4883{
4884 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4885 struct bfa_fcs_lport_s *port = ns->port;
4886 struct fchs_s fchs;
4887 int len;
4888 struct bfa_fcxp_s *fcxp;
4889
4890 bfa_trc(port->fcs, port->pid);
4891
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004892 fcxp = fcxp_alloced ? fcxp_alloced :
4893 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004894 if (!fcxp) {
4895 port->stats.ns_gidft_alloc_wait++;
4896 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07004897 bfa_fcs_lport_ns_send_gid_ft, ns, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004898 return;
4899 }
4900 ns->fcxp = fcxp;
4901
4902 /*
4903 * This query is only initiated for FCP initiator mode.
4904 */
4905 len = fc_gid_ft_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4906 ns->port->pid, FC_TYPE_FCP);
4907
4908 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4909 FC_CLASS_3, len, &fchs,
4910 bfa_fcs_lport_ns_gid_ft_response, (void *)ns,
4911 bfa_fcxp_get_maxrsp(port->fcs->bfa), FC_FCCT_TOV);
4912
4913 port->stats.ns_gidft_sent++;
4914
4915 bfa_sm_send_event(ns, NSSM_EVENT_GIDFT_SENT);
4916}
4917
4918static void
4919bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4920 void *cbarg, bfa_status_t req_status,
4921 u32 rsp_len, u32 resid_len,
4922 struct fchs_s *rsp_fchs)
4923{
4924 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4925 struct bfa_fcs_lport_s *port = ns->port;
4926 struct ct_hdr_s *cthdr = NULL;
4927 u32 n_pids;
4928
4929 bfa_trc(port->fcs, port->port_cfg.pwwn);
4930
4931 /*
4932 * Sanity Checks
4933 */
4934 if (req_status != BFA_STATUS_OK) {
4935 bfa_trc(port->fcs, req_status);
4936 port->stats.ns_gidft_rsp_err++;
4937 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4938 return;
4939 }
4940
4941 if (resid_len != 0) {
4942 /*
4943 * TBD : we will need to allocate a larger buffer & retry the
4944 * command
4945 */
4946 bfa_trc(port->fcs, rsp_len);
4947 bfa_trc(port->fcs, resid_len);
4948 return;
4949 }
4950
4951 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07004952 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004953
4954 switch (cthdr->cmd_rsp_code) {
4955
4956 case CT_RSP_ACCEPT:
4957
4958 port->stats.ns_gidft_accepts++;
4959 n_pids = (fc_get_ctresp_pyld_len(rsp_len) / sizeof(u32));
4960 bfa_trc(port->fcs, n_pids);
4961 bfa_fcs_lport_ns_process_gidft_pids(port,
4962 (u32 *) (cthdr + 1),
4963 n_pids);
4964 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4965 break;
4966
4967 case CT_RSP_REJECT:
4968
4969 /*
4970 * Check the reason code & explanation.
4971 * There may not have been any FC4 devices in the fabric
4972 */
4973 port->stats.ns_gidft_rejects++;
4974 bfa_trc(port->fcs, cthdr->reason_code);
4975 bfa_trc(port->fcs, cthdr->exp_code);
4976
4977 if ((cthdr->reason_code == CT_RSN_UNABLE_TO_PERF)
4978 && (cthdr->exp_code == CT_NS_EXP_FT_NOT_REG)) {
4979
4980 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4981 } else {
4982 /*
4983 * for all other errors, retry
4984 */
4985 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4986 }
4987 break;
4988
4989 default:
4990 port->stats.ns_gidft_unknown_rsp++;
4991 bfa_trc(port->fcs, cthdr->cmd_rsp_code);
4992 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4993 }
4994}
4995
Jing Huang5fbe25c2010-10-18 17:17:23 -07004996/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004997 * This routine will be called by bfa_timer on timer timeouts.
4998 *
4999 * param[in] port - pointer to bfa_fcs_lport_t.
5000 *
5001 * return
5002 * void
5003 *
5004 * Special Considerations:
5005 *
5006 * note
5007 */
5008static void
5009bfa_fcs_lport_ns_timeout(void *arg)
5010{
5011 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) arg;
5012
5013 ns->port->stats.ns_timeouts++;
5014 bfa_sm_send_event(ns, NSSM_EVENT_TIMEOUT);
5015}
5016
5017/*
5018 * Process the PID list in GID_FT response
5019 */
5020static void
5021bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s *port, u32 *pid_buf,
5022 u32 n_pids)
5023{
5024 struct fcgs_gidft_resp_s *gidft_entry;
5025 struct bfa_fcs_rport_s *rport;
5026 u32 ii;
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005027 struct bfa_fcs_fabric_s *fabric = port->fabric;
5028 struct bfa_fcs_vport_s *vport;
5029 struct list_head *qe;
5030 u8 found = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005031
5032 for (ii = 0; ii < n_pids; ii++) {
5033 gidft_entry = (struct fcgs_gidft_resp_s *) &pid_buf[ii];
5034
5035 if (gidft_entry->pid == port->pid)
5036 continue;
5037
5038 /*
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005039 * Ignore PID if it is of base port
5040 * (Avoid vports discovering base port as remote port)
5041 */
5042 if (gidft_entry->pid == fabric->bport.pid)
5043 continue;
5044
5045 /*
5046 * Ignore PID if it is of vport created on the same base port
5047 * (Avoid vport discovering every other vport created on the
5048 * same port as remote port)
5049 */
5050 list_for_each(qe, &fabric->vport_q) {
5051 vport = (struct bfa_fcs_vport_s *) qe;
5052 if (vport->lport.pid == gidft_entry->pid)
5053 found = 1;
5054 }
5055
5056 if (found) {
5057 found = 0;
5058 continue;
5059 }
5060
5061 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005062 * Check if this rport already exists
5063 */
5064 rport = bfa_fcs_lport_get_rport_by_pid(port, gidft_entry->pid);
5065 if (rport == NULL) {
5066 /*
5067 * this is a new device. create rport
5068 */
5069 rport = bfa_fcs_rport_create(port, gidft_entry->pid);
5070 } else {
5071 /*
5072 * this rport already exists
5073 */
5074 bfa_fcs_rport_scn(rport);
5075 }
5076
5077 bfa_trc(port->fcs, gidft_entry->pid);
5078
5079 /*
5080 * if the last entry bit is set, bail out.
5081 */
5082 if (gidft_entry->last)
5083 return;
5084 }
5085}
5086
Jing Huang5fbe25c2010-10-18 17:17:23 -07005087/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005088 * fcs_ns_public FCS nameserver public interfaces
5089 */
5090
5091/*
5092 * Functions called by port/fab.
5093 * These will send relevant Events to the ns state machine.
5094 */
5095void
5096bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s *port)
5097{
5098 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5099
5100 ns->port = port;
5101 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
5102}
5103
5104void
5105bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s *port)
5106{
5107 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5108
5109 ns->port = port;
5110 bfa_sm_send_event(ns, NSSM_EVENT_PORT_OFFLINE);
5111}
5112
5113void
5114bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s *port)
5115{
5116 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5117
5118 ns->port = port;
5119 bfa_sm_send_event(ns, NSSM_EVENT_PORT_ONLINE);
5120}
5121
5122void
5123bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s *port)
5124{
5125 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5126
5127 bfa_trc(port->fcs, port->pid);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005128 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_online))
5129 bfa_sm_send_event(ns, NSSM_EVENT_NS_QUERY);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005130}
5131
Maggie52f94b62010-11-29 18:21:32 -08005132static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005133bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port)
5134{
5135
5136 struct bfa_fcs_rport_s *rport;
5137 u8 nwwns;
5138 wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
5139 int ii;
5140
5141 bfa_iocfc_get_bootwwns(port->fcs->bfa, &nwwns, wwns);
5142
5143 for (ii = 0 ; ii < nwwns; ++ii) {
5144 rport = bfa_fcs_rport_create_by_wwn(port, wwns[ii]);
Jing Huangd4b671c2010-12-26 21:46:35 -08005145 WARN_ON(!rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005146 }
5147}
5148
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005149void
5150bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
5151{
5152 struct bfa_fcs_lport_ns_s *ns = cbarg;
5153 struct bfa_fcs_lport_s *port = ns->port;
5154 struct fchs_s fchs;
5155 struct bfa_fcxp_s *fcxp;
5156 u8 symbl[256];
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005157 int len;
5158
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005159 /* Avoid sending RSPN in the following states. */
5160 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_offline) ||
5161 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_sending) ||
5162 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi) ||
5163 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_retry) ||
5164 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry))
5165 return;
5166
5167 memset(symbl, 0, sizeof(symbl));
5168 bfa_trc(port->fcs, port->port_cfg.pwwn);
5169
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07005170 fcxp = fcxp_alloced ? fcxp_alloced :
5171 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005172 if (!fcxp) {
5173 port->stats.ns_rspnid_alloc_wait++;
5174 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07005175 bfa_fcs_lport_ns_util_send_rspn_id, ns, BFA_FALSE);
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005176 return;
5177 }
5178
5179 ns->fcxp = fcxp;
5180
5181 if (port->vport) {
5182 /*
5183 * For Vports, we append the vport's port symbolic name
5184 * to that of the base port.
5185 */
Arnd Bergmann2de75632017-12-04 15:47:00 +01005186 strlcpy(symbl, (char *)&(bfa_fcs_lport_get_psym_name
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005187 (bfa_fcs_get_base_port(port->fcs))),
Arnd Bergmann2de75632017-12-04 15:47:00 +01005188 sizeof(symbl));
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005189
Arnd Bergmann2de75632017-12-04 15:47:00 +01005190 strlcat(symbl,
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005191 (char *)&(bfa_fcs_lport_get_psym_name(port)),
Arnd Bergmann2de75632017-12-04 15:47:00 +01005192 sizeof(symbl));
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005193 }
5194
5195 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Arnd Bergmann2de75632017-12-04 15:47:00 +01005196 bfa_fcs_lport_get_fcid(port), 0, symbl);
Krishna Gudipatiebfe8392012-08-22 19:50:20 -07005197
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;
Colin Ian King5f6ac2c2016-08-30 17:36:16 +01005816 bfa_boolean_t trl_enabled;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005817
5818 if (port == NULL)
5819 return 0;
5820
5821 fcs = port->fcs;
Colin Ian King5f6ac2c2016-08-30 17:36:16 +01005822 trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005823
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}