blob: dd7d1e6bc2d80de787ddf36549232ee77bc52aa2 [file] [log] [blame]
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05002 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05005 * www.qlogic.com
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05007 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -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_plog.h"
22#include "bfa_cs.h"
23#include "bfa_modules.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070024
25BFA_TRC_FILE(HAL, FCXP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070026
Jing Huang5fbe25c2010-10-18 17:17:23 -070027/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070028 * LPS related definitions
29 */
30#define BFA_LPS_MIN_LPORTS (1)
31#define BFA_LPS_MAX_LPORTS (256)
32
33/*
34 * Maximum Vports supported per physical port or vf.
35 */
36#define BFA_LPS_MAX_VPORTS_SUPP_CB 255
37#define BFA_LPS_MAX_VPORTS_SUPP_CT 190
38
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070039
Jing Huang5fbe25c2010-10-18 17:17:23 -070040/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070041 * FC PORT related definitions
42 */
43/*
44 * The port is considered disabled if corresponding physical port or IOC are
45 * disabled explicitly
46 */
47#define BFA_PORT_IS_DISABLED(bfa) \
48 ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
49 (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
50
Jing Huang5fbe25c2010-10-18 17:17:23 -070051/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070052 * BFA port state machine events
53 */
54enum bfa_fcport_sm_event {
55 BFA_FCPORT_SM_START = 1, /* start port state machine */
56 BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
57 BFA_FCPORT_SM_ENABLE = 3, /* enable port */
58 BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
59 BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
60 BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
61 BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
62 BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
63 BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
Krishna Gudipatie3535462012-09-21 17:26:07 -070064 BFA_FCPORT_SM_DPORTENABLE = 10, /* enable dport */
65 BFA_FCPORT_SM_DPORTDISABLE = 11,/* disable dport */
Krishna Gudipati04ea6572012-09-21 17:26:18 -070066 BFA_FCPORT_SM_FAA_MISCONFIG = 12, /* FAA misconfiguratin */
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -070067 BFA_FCPORT_SM_DDPORTENABLE = 13, /* enable ddport */
68 BFA_FCPORT_SM_DDPORTDISABLE = 14, /* disable ddport */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070069};
70
Jing Huang5fbe25c2010-10-18 17:17:23 -070071/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070072 * BFA port link notification state machine events
73 */
74
75enum bfa_fcport_ln_sm_event {
76 BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
77 BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
78 BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
79};
80
Jing Huang5fbe25c2010-10-18 17:17:23 -070081/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070082 * RPORT related definitions
83 */
84#define bfa_rport_offline_cb(__rp) do { \
85 if ((__rp)->bfa->fcs) \
86 bfa_cb_rport_offline((__rp)->rport_drv); \
87 else { \
88 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
89 __bfa_cb_rport_offline, (__rp)); \
90 } \
91} while (0)
92
93#define bfa_rport_online_cb(__rp) do { \
94 if ((__rp)->bfa->fcs) \
95 bfa_cb_rport_online((__rp)->rport_drv); \
96 else { \
97 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
98 __bfa_cb_rport_online, (__rp)); \
99 } \
100} while (0)
101
Jing Huang5fbe25c2010-10-18 17:17:23 -0700102/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700103 * forward declarations FCXP related functions
104 */
105static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete);
106static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
107 struct bfi_fcxp_send_rsp_s *fcxp_rsp);
108static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen,
109 struct bfa_fcxp_s *fcxp, struct fchs_s *fchs);
110static void bfa_fcxp_qresume(void *cbarg);
111static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp,
112 struct bfi_fcxp_send_req_s *send_req);
113
Jing Huang5fbe25c2010-10-18 17:17:23 -0700114/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700115 * forward declarations for LPS functions
116 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700117static void bfa_lps_login_rsp(struct bfa_s *bfa,
118 struct bfi_lps_login_rsp_s *rsp);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700119static void bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700120static void bfa_lps_logout_rsp(struct bfa_s *bfa,
121 struct bfi_lps_logout_rsp_s *rsp);
122static void bfa_lps_reqq_resume(void *lps_arg);
123static void bfa_lps_free(struct bfa_lps_s *lps);
124static void bfa_lps_send_login(struct bfa_lps_s *lps);
125static void bfa_lps_send_logout(struct bfa_lps_s *lps);
Krishna Gudipatib7044952010-12-13 16:17:42 -0800126static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700127static void bfa_lps_login_comp(struct bfa_lps_s *lps);
128static void bfa_lps_logout_comp(struct bfa_lps_s *lps);
129static void bfa_lps_cvl_event(struct bfa_lps_s *lps);
130
Jing Huang5fbe25c2010-10-18 17:17:23 -0700131/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700132 * forward declaration for LPS state machine
133 */
134static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event);
135static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event);
136static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event
137 event);
138static void bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event);
Krishna Gudipatib7044952010-12-13 16:17:42 -0800139static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps,
140 enum bfa_lps_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700141static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event);
142static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event
143 event);
144
Jing Huang5fbe25c2010-10-18 17:17:23 -0700145/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700146 * forward declaration for FC Port functions
147 */
148static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
149static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
150static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
151static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
152static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
153static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
154static void bfa_fcport_scn(struct bfa_fcport_s *fcport,
155 enum bfa_port_linkstate event, bfa_boolean_t trunk);
156static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
157 enum bfa_port_linkstate event);
158static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
159static void bfa_fcport_stats_get_timeout(void *cbarg);
160static void bfa_fcport_stats_clr_timeout(void *cbarg);
161static void bfa_trunk_iocdisable(struct bfa_s *bfa);
162
Jing Huang5fbe25c2010-10-18 17:17:23 -0700163/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700164 * forward declaration for FC PORT state machine
165 */
166static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
167 enum bfa_fcport_sm_event event);
168static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
169 enum bfa_fcport_sm_event event);
170static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
171 enum bfa_fcport_sm_event event);
172static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
173 enum bfa_fcport_sm_event event);
174static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
175 enum bfa_fcport_sm_event event);
176static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
177 enum bfa_fcport_sm_event event);
178static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
179 enum bfa_fcport_sm_event event);
180static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
181 enum bfa_fcport_sm_event event);
182static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
183 enum bfa_fcport_sm_event event);
184static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
185 enum bfa_fcport_sm_event event);
186static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
187 enum bfa_fcport_sm_event event);
188static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
189 enum bfa_fcport_sm_event event);
Krishna Gudipatie3535462012-09-21 17:26:07 -0700190static void bfa_fcport_sm_dport(struct bfa_fcport_s *fcport,
191 enum bfa_fcport_sm_event event);
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -0700192static void bfa_fcport_sm_ddport(struct bfa_fcport_s *fcport,
193 enum bfa_fcport_sm_event event);
Krishna Gudipati04ea6572012-09-21 17:26:18 -0700194static void bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s *fcport,
195 enum bfa_fcport_sm_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700196
197static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
198 enum bfa_fcport_ln_sm_event event);
199static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
200 enum bfa_fcport_ln_sm_event event);
201static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
202 enum bfa_fcport_ln_sm_event event);
203static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
204 enum bfa_fcport_ln_sm_event event);
205static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
206 enum bfa_fcport_ln_sm_event event);
207static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
208 enum bfa_fcport_ln_sm_event event);
209static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
210 enum bfa_fcport_ln_sm_event event);
211
212static struct bfa_sm_table_s hal_port_sm_table[] = {
213 {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT},
214 {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT},
215 {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING},
216 {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN},
217 {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP},
218 {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT},
219 {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT},
220 {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING},
221 {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED},
222 {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED},
223 {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN},
224 {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN},
Krishna Gudipatie3535462012-09-21 17:26:07 -0700225 {BFA_SM(bfa_fcport_sm_dport), BFA_PORT_ST_DPORT},
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -0700226 {BFA_SM(bfa_fcport_sm_ddport), BFA_PORT_ST_DDPORT},
Krishna Gudipati04ea6572012-09-21 17:26:18 -0700227 {BFA_SM(bfa_fcport_sm_faa_misconfig), BFA_PORT_ST_FAA_MISCONFIG},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700228};
229
230
Jing Huang5fbe25c2010-10-18 17:17:23 -0700231/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700232 * forward declaration for RPORT related functions
233 */
234static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod);
235static void bfa_rport_free(struct bfa_rport_s *rport);
236static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp);
237static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp);
238static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp);
239static void __bfa_cb_rport_online(void *cbarg,
240 bfa_boolean_t complete);
241static void __bfa_cb_rport_offline(void *cbarg,
242 bfa_boolean_t complete);
243
Jing Huang5fbe25c2010-10-18 17:17:23 -0700244/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700245 * forward declaration for RPORT state machine
246 */
247static void bfa_rport_sm_uninit(struct bfa_rport_s *rp,
248 enum bfa_rport_event event);
249static void bfa_rport_sm_created(struct bfa_rport_s *rp,
250 enum bfa_rport_event event);
251static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp,
252 enum bfa_rport_event event);
253static void bfa_rport_sm_online(struct bfa_rport_s *rp,
254 enum bfa_rport_event event);
255static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp,
256 enum bfa_rport_event event);
257static void bfa_rport_sm_offline(struct bfa_rport_s *rp,
258 enum bfa_rport_event event);
259static void bfa_rport_sm_deleting(struct bfa_rport_s *rp,
260 enum bfa_rport_event event);
261static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
262 enum bfa_rport_event event);
263static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
264 enum bfa_rport_event event);
265static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp,
266 enum bfa_rport_event event);
267static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp,
268 enum bfa_rport_event event);
269static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp,
270 enum bfa_rport_event event);
271static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp,
272 enum bfa_rport_event event);
273
Jing Huang5fbe25c2010-10-18 17:17:23 -0700274/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700275 * PLOG related definitions
276 */
277static int
278plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
279{
280 if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
281 (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
282 return 1;
283
284 if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
285 (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
286 return 1;
287
288 return 0;
289}
290
Maggie Zhangf16a1752010-12-09 19:12:32 -0800291static u64
292bfa_get_log_time(void)
293{
294 u64 system_time = 0;
295 struct timeval tv;
296 do_gettimeofday(&tv);
297
298 /* We are interested in seconds only. */
299 system_time = tv.tv_sec;
300 return system_time;
301}
302
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700303static void
304bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
305{
306 u16 tail;
307 struct bfa_plog_rec_s *pl_recp;
308
309 if (plog->plog_enabled == 0)
310 return;
311
312 if (plkd_validate_logrec(pl_rec)) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800313 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700314 return;
315 }
316
317 tail = plog->tail;
318
319 pl_recp = &(plog->plog_recs[tail]);
320
Jing Huang6a18b162010-10-18 17:08:54 -0700321 memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700322
Maggie Zhangf16a1752010-12-09 19:12:32 -0800323 pl_recp->tv = bfa_get_log_time();
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700324 BFA_PL_LOG_REC_INCR(plog->tail);
325
326 if (plog->head == plog->tail)
327 BFA_PL_LOG_REC_INCR(plog->head);
328}
329
330void
331bfa_plog_init(struct bfa_plog_s *plog)
332{
Jing Huang6a18b162010-10-18 17:08:54 -0700333 memset((char *)plog, 0, sizeof(struct bfa_plog_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700334
Jing Huang6a18b162010-10-18 17:08:54 -0700335 memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700336 plog->head = plog->tail = 0;
337 plog->plog_enabled = 1;
338}
339
340void
341bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
342 enum bfa_plog_eid event,
343 u16 misc, char *log_str)
344{
345 struct bfa_plog_rec_s lp;
346
347 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700348 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700349 lp.mid = mid;
350 lp.eid = event;
351 lp.log_type = BFA_PL_LOG_TYPE_STRING;
352 lp.misc = misc;
353 strncpy(lp.log_entry.string_log, log_str,
354 BFA_PL_STRING_LOG_SZ - 1);
355 lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
356 bfa_plog_add(plog, &lp);
357 }
358}
359
360void
361bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
362 enum bfa_plog_eid event,
363 u16 misc, u32 *intarr, u32 num_ints)
364{
365 struct bfa_plog_rec_s lp;
366 u32 i;
367
368 if (num_ints > BFA_PL_INT_LOG_SZ)
369 num_ints = BFA_PL_INT_LOG_SZ;
370
371 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700372 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700373 lp.mid = mid;
374 lp.eid = event;
375 lp.log_type = BFA_PL_LOG_TYPE_INT;
376 lp.misc = misc;
377
378 for (i = 0; i < num_ints; i++)
Jing Huang6a18b162010-10-18 17:08:54 -0700379 lp.log_entry.int_log[i] = intarr[i];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700380
381 lp.log_num_ints = (u8) num_ints;
382
383 bfa_plog_add(plog, &lp);
384 }
385}
386
387void
388bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
389 enum bfa_plog_eid event,
390 u16 misc, struct fchs_s *fchdr)
391{
392 struct bfa_plog_rec_s lp;
393 u32 *tmp_int = (u32 *) fchdr;
394 u32 ints[BFA_PL_INT_LOG_SZ];
395
396 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700397 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700398
399 ints[0] = tmp_int[0];
400 ints[1] = tmp_int[1];
401 ints[2] = tmp_int[4];
402
403 bfa_plog_intarr(plog, mid, event, misc, ints, 3);
404 }
405}
406
407void
408bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
409 enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
410 u32 pld_w0)
411{
412 struct bfa_plog_rec_s lp;
413 u32 *tmp_int = (u32 *) fchdr;
414 u32 ints[BFA_PL_INT_LOG_SZ];
415
416 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700417 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700418
419 ints[0] = tmp_int[0];
420 ints[1] = tmp_int[1];
421 ints[2] = tmp_int[4];
422 ints[3] = pld_w0;
423
424 bfa_plog_intarr(plog, mid, event, misc, ints, 4);
425 }
426}
427
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700428
Jing Huang5fbe25c2010-10-18 17:17:23 -0700429/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700430 * fcxp_pvt BFA FCXP private functions
431 */
432
433static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700434claim_fcxps_mem(struct bfa_fcxp_mod_s *mod)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700435{
436 u16 i;
437 struct bfa_fcxp_s *fcxp;
438
Krishna Gudipati45070252011-06-24 20:24:29 -0700439 fcxp = (struct bfa_fcxp_s *) bfa_mem_kva_curp(mod);
Jing Huang6a18b162010-10-18 17:08:54 -0700440 memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700441
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700442 INIT_LIST_HEAD(&mod->fcxp_req_free_q);
443 INIT_LIST_HEAD(&mod->fcxp_rsp_free_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700444 INIT_LIST_HEAD(&mod->fcxp_active_q);
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700445 INIT_LIST_HEAD(&mod->fcxp_req_unused_q);
446 INIT_LIST_HEAD(&mod->fcxp_rsp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700447
448 mod->fcxp_list = fcxp;
449
450 for (i = 0; i < mod->num_fcxps; i++) {
451 fcxp->fcxp_mod = mod;
452 fcxp->fcxp_tag = i;
453
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700454 if (i < (mod->num_fcxps / 2)) {
455 list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q);
456 fcxp->req_rsp = BFA_TRUE;
457 } else {
458 list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q);
459 fcxp->req_rsp = BFA_FALSE;
460 }
461
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700462 bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp);
463 fcxp->reqq_waiting = BFA_FALSE;
464
465 fcxp = fcxp + 1;
466 }
467
Krishna Gudipati45070252011-06-24 20:24:29 -0700468 bfa_mem_kva_curp(mod) = (void *)fcxp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700469}
470
Christoph Hellwigc7c35242017-04-13 10:02:56 +0200471void
Krishna Gudipati45070252011-06-24 20:24:29 -0700472bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
473 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700474{
Krishna Gudipati45070252011-06-24 20:24:29 -0700475 struct bfa_fcxp_mod_s *fcxp_mod = BFA_FCXP_MOD(bfa);
476 struct bfa_mem_kva_s *fcxp_kva = BFA_MEM_FCXP_KVA(bfa);
477 struct bfa_mem_dma_s *seg_ptr;
478 u16 nsegs, idx, per_seg_fcxp;
479 u16 num_fcxps = cfg->fwcfg.num_fcxp_reqs;
480 u32 per_fcxp_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700481
Krishna Gudipati45070252011-06-24 20:24:29 -0700482 if (num_fcxps == 0)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700483 return;
484
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700485 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -0700486 per_fcxp_sz = 2 * BFA_FCXP_MAX_IBUF_SZ;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700487 else
Krishna Gudipati45070252011-06-24 20:24:29 -0700488 per_fcxp_sz = BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700489
Krishna Gudipati45070252011-06-24 20:24:29 -0700490 /* dma memory */
491 nsegs = BFI_MEM_DMA_NSEGS(num_fcxps, per_fcxp_sz);
492 per_seg_fcxp = BFI_MEM_NREQS_SEG(per_fcxp_sz);
493
494 bfa_mem_dma_seg_iter(fcxp_mod, seg_ptr, nsegs, idx) {
495 if (num_fcxps >= per_seg_fcxp) {
496 num_fcxps -= per_seg_fcxp;
497 bfa_mem_dma_setup(minfo, seg_ptr,
498 per_seg_fcxp * per_fcxp_sz);
499 } else
500 bfa_mem_dma_setup(minfo, seg_ptr,
501 num_fcxps * per_fcxp_sz);
502 }
503
504 /* kva memory */
505 bfa_mem_kva_setup(minfo, fcxp_kva,
506 cfg->fwcfg.num_fcxp_reqs * sizeof(struct bfa_fcxp_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700507}
508
Christoph Hellwigc7c35242017-04-13 10:02:56 +0200509void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700510bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -0700511 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700512{
513 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
514
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700515 mod->bfa = bfa;
516 mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
517
Jing Huang5fbe25c2010-10-18 17:17:23 -0700518 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700519 * Initialize FCXP request and response payload sizes.
520 */
521 mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
522 if (!cfg->drvcfg.min_cfg)
523 mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ;
524
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700525 INIT_LIST_HEAD(&mod->req_wait_q);
526 INIT_LIST_HEAD(&mod->rsp_wait_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700527
Krishna Gudipati45070252011-06-24 20:24:29 -0700528 claim_fcxps_mem(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700529}
530
Christoph Hellwigc7c35242017-04-13 10:02:56 +0200531void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700532bfa_fcxp_iocdisable(struct bfa_s *bfa)
533{
534 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
535 struct bfa_fcxp_s *fcxp;
536 struct list_head *qe, *qen;
537
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700538 /* Enqueue unused fcxp resources to free_q */
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700539 list_splice_tail_init(&mod->fcxp_req_unused_q, &mod->fcxp_req_free_q);
540 list_splice_tail_init(&mod->fcxp_rsp_unused_q, &mod->fcxp_rsp_free_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700541
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700542 list_for_each_safe(qe, qen, &mod->fcxp_active_q) {
543 fcxp = (struct bfa_fcxp_s *) qe;
544 if (fcxp->caller == NULL) {
545 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
546 BFA_STATUS_IOC_FAILURE, 0, 0, NULL);
547 bfa_fcxp_free(fcxp);
548 } else {
549 fcxp->rsp_status = BFA_STATUS_IOC_FAILURE;
550 bfa_cb_queue(bfa, &fcxp->hcb_qe,
551 __bfa_fcxp_send_cbfn, fcxp);
552 }
553 }
554}
555
556static struct bfa_fcxp_s *
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700557bfa_fcxp_get(struct bfa_fcxp_mod_s *fm, bfa_boolean_t req)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700558{
559 struct bfa_fcxp_s *fcxp;
560
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700561 if (req)
562 bfa_q_deq(&fm->fcxp_req_free_q, &fcxp);
563 else
564 bfa_q_deq(&fm->fcxp_rsp_free_q, &fcxp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700565
566 if (fcxp)
567 list_add_tail(&fcxp->qe, &fm->fcxp_active_q);
568
569 return fcxp;
570}
571
572static void
573bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
574 struct bfa_s *bfa,
575 u8 *use_ibuf,
576 u32 *nr_sgles,
577 bfa_fcxp_get_sgaddr_t *r_sga_cbfn,
578 bfa_fcxp_get_sglen_t *r_sglen_cbfn,
579 struct list_head *r_sgpg_q,
580 int n_sgles,
581 bfa_fcxp_get_sgaddr_t sga_cbfn,
582 bfa_fcxp_get_sglen_t sglen_cbfn)
583{
584
Jing Huangd4b671c2010-12-26 21:46:35 -0800585 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700586
587 bfa_trc(bfa, fcxp->fcxp_tag);
588
589 if (n_sgles == 0) {
590 *use_ibuf = 1;
591 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800592 WARN_ON(*sga_cbfn == NULL);
593 WARN_ON(*sglen_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700594
595 *use_ibuf = 0;
596 *r_sga_cbfn = sga_cbfn;
597 *r_sglen_cbfn = sglen_cbfn;
598
599 *nr_sgles = n_sgles;
600
601 /*
602 * alloc required sgpgs
603 */
604 if (n_sgles > BFI_SGE_INLINE)
Jing Huangd4b671c2010-12-26 21:46:35 -0800605 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700606 }
607
608}
609
610static void
611bfa_fcxp_init(struct bfa_fcxp_s *fcxp,
612 void *caller, struct bfa_s *bfa, int nreq_sgles,
613 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
614 bfa_fcxp_get_sglen_t req_sglen_cbfn,
615 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
616 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
617{
618
Jing Huangd4b671c2010-12-26 21:46:35 -0800619 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700620
621 bfa_trc(bfa, fcxp->fcxp_tag);
622
623 fcxp->caller = caller;
624
625 bfa_fcxp_init_reqrsp(fcxp, bfa,
626 &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn,
627 &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q,
628 nreq_sgles, req_sga_cbfn, req_sglen_cbfn);
629
630 bfa_fcxp_init_reqrsp(fcxp, bfa,
631 &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn,
632 &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q,
633 nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn);
634
635}
636
637static void
638bfa_fcxp_put(struct bfa_fcxp_s *fcxp)
639{
640 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
641 struct bfa_fcxp_wqe_s *wqe;
642
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700643 if (fcxp->req_rsp)
644 bfa_q_deq(&mod->req_wait_q, &wqe);
645 else
646 bfa_q_deq(&mod->rsp_wait_q, &wqe);
647
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700648 if (wqe) {
649 bfa_trc(mod->bfa, fcxp->fcxp_tag);
650
651 bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles,
652 wqe->nrsp_sgles, wqe->req_sga_cbfn,
653 wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn,
654 wqe->rsp_sglen_cbfn);
655
656 wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp);
657 return;
658 }
659
Jing Huangd4b671c2010-12-26 21:46:35 -0800660 WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700661 list_del(&fcxp->qe);
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700662
663 if (fcxp->req_rsp)
664 list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q);
665 else
666 list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700667}
668
669static void
670bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
671 bfa_status_t req_status, u32 rsp_len,
672 u32 resid_len, struct fchs_s *rsp_fchs)
673{
674 /* discarded fcxp completion */
675}
676
677static void
678__bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete)
679{
680 struct bfa_fcxp_s *fcxp = cbarg;
681
682 if (complete) {
683 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
684 fcxp->rsp_status, fcxp->rsp_len,
685 fcxp->residue_len, &fcxp->rsp_fchs);
686 } else {
687 bfa_fcxp_free(fcxp);
688 }
689}
690
691static void
692hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
693{
694 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
695 struct bfa_fcxp_s *fcxp;
Jing Huangba816ea2010-10-18 17:10:50 -0700696 u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700697
698 bfa_trc(bfa, fcxp_tag);
699
Jing Huangba816ea2010-10-18 17:10:50 -0700700 fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700701
Jing Huang5fbe25c2010-10-18 17:17:23 -0700702 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700703 * @todo f/w should not set residue to non-0 when everything
704 * is received.
705 */
706 if (fcxp_rsp->req_status == BFA_STATUS_OK)
707 fcxp_rsp->residue_len = 0;
708 else
Jing Huangba816ea2010-10-18 17:10:50 -0700709 fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700710
711 fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
712
Jing Huangd4b671c2010-12-26 21:46:35 -0800713 WARN_ON(fcxp->send_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700714
715 hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp);
716
717 if (fcxp->send_cbfn != NULL) {
718 bfa_trc(mod->bfa, (NULL == fcxp->caller));
719 if (fcxp->caller == NULL) {
720 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
721 fcxp_rsp->req_status, fcxp_rsp->rsp_len,
722 fcxp_rsp->residue_len, &fcxp_rsp->fchs);
723 /*
724 * fcxp automatically freed on return from the callback
725 */
726 bfa_fcxp_free(fcxp);
727 } else {
728 fcxp->rsp_status = fcxp_rsp->req_status;
729 fcxp->rsp_len = fcxp_rsp->rsp_len;
730 fcxp->residue_len = fcxp_rsp->residue_len;
731 fcxp->rsp_fchs = fcxp_rsp->fchs;
732
733 bfa_cb_queue(bfa, &fcxp->hcb_qe,
734 __bfa_fcxp_send_cbfn, fcxp);
735 }
736 } else {
737 bfa_trc(bfa, (NULL == fcxp->send_cbfn));
738 }
739}
740
741static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700742hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp,
743 struct fchs_s *fchs)
744{
745 /*
746 * TODO: TX ox_id
747 */
748 if (reqlen > 0) {
749 if (fcxp->use_ireqbuf) {
750 u32 pld_w0 =
751 *((u32 *) BFA_FCXP_REQ_PLD(fcxp));
752
753 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
754 BFA_PL_EID_TX,
755 reqlen + sizeof(struct fchs_s), fchs,
756 pld_w0);
757 } else {
758 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
759 BFA_PL_EID_TX,
760 reqlen + sizeof(struct fchs_s),
761 fchs);
762 }
763 } else {
764 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX,
765 reqlen + sizeof(struct fchs_s), fchs);
766 }
767}
768
769static void
770hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
771 struct bfi_fcxp_send_rsp_s *fcxp_rsp)
772{
773 if (fcxp_rsp->rsp_len > 0) {
774 if (fcxp->use_irspbuf) {
775 u32 pld_w0 =
776 *((u32 *) BFA_FCXP_RSP_PLD(fcxp));
777
778 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
779 BFA_PL_EID_RX,
780 (u16) fcxp_rsp->rsp_len,
781 &fcxp_rsp->fchs, pld_w0);
782 } else {
783 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
784 BFA_PL_EID_RX,
785 (u16) fcxp_rsp->rsp_len,
786 &fcxp_rsp->fchs);
787 }
788 } else {
789 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX,
790 (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs);
791 }
792}
793
Jing Huang5fbe25c2010-10-18 17:17:23 -0700794/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700795 * Handler to resume sending fcxp when space in available in cpe queue.
796 */
797static void
798bfa_fcxp_qresume(void *cbarg)
799{
800 struct bfa_fcxp_s *fcxp = cbarg;
801 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
802 struct bfi_fcxp_send_req_s *send_req;
803
804 fcxp->reqq_waiting = BFA_FALSE;
805 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
806 bfa_fcxp_queue(fcxp, send_req);
807}
808
Jing Huang5fbe25c2010-10-18 17:17:23 -0700809/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700810 * Queue fcxp send request to foimrware.
811 */
812static void
813bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
814{
815 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
816 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
817 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
818 struct bfa_rport_s *rport = reqi->bfa_rport;
819
820 bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700821 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700822
Jing Huangba816ea2010-10-18 17:10:50 -0700823 send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700824 if (rport) {
825 send_req->rport_fw_hndl = rport->fw_handle;
Jing Huangba816ea2010-10-18 17:10:50 -0700826 send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700827 if (send_req->max_frmsz == 0)
Jing Huangba816ea2010-10-18 17:10:50 -0700828 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700829 } else {
830 send_req->rport_fw_hndl = 0;
Jing Huangba816ea2010-10-18 17:10:50 -0700831 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700832 }
833
Jing Huangba816ea2010-10-18 17:10:50 -0700834 send_req->vf_id = cpu_to_be16(reqi->vf_id);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700835 send_req->lp_fwtag = bfa_lps_get_fwtag(bfa, reqi->lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700836 send_req->class = reqi->class;
837 send_req->rsp_timeout = rspi->rsp_timeout;
838 send_req->cts = reqi->cts;
839 send_req->fchs = reqi->fchs;
840
Jing Huangba816ea2010-10-18 17:10:50 -0700841 send_req->req_len = cpu_to_be32(reqi->req_tot_len);
842 send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700843
844 /*
845 * setup req sgles
846 */
847 if (fcxp->use_ireqbuf == 1) {
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700848 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700849 BFA_FCXP_REQ_PLD_PA(fcxp));
850 } else {
851 if (fcxp->nreq_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800852 WARN_ON(fcxp->nreq_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700853 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
854 fcxp->req_sga_cbfn(fcxp->caller, 0));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700855 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800856 WARN_ON(reqi->req_tot_len != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700857 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700858 }
859 }
860
861 /*
862 * setup rsp sgles
863 */
864 if (fcxp->use_irspbuf == 1) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800865 WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700866
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700867 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700868 BFA_FCXP_RSP_PLD_PA(fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700869 } else {
870 if (fcxp->nrsp_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800871 WARN_ON(fcxp->nrsp_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700872 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
873 fcxp->rsp_sga_cbfn(fcxp->caller, 0));
874
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700875 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800876 WARN_ON(rspi->rsp_maxlen != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700877 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700878 }
879 }
880
881 hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs);
882
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700883 bfa_reqq_produce(bfa, BFA_REQQ_FCXP, send_req->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700884
885 bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP));
886 bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
887}
888
Jing Huang5fbe25c2010-10-18 17:17:23 -0700889/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700890 * Allocate an FCXP instance to send a response or to send a request
891 * that has a response. Request/response buffers are allocated by caller.
892 *
893 * @param[in] bfa BFA bfa instance
894 * @param[in] nreq_sgles Number of SG elements required for request
895 * buffer. 0, if fcxp internal buffers are used.
896 * Use bfa_fcxp_get_reqbuf() to get the
897 * internal req buffer.
898 * @param[in] req_sgles SG elements describing request buffer. Will be
899 * copied in by BFA and hence can be freed on
900 * return from this function.
901 * @param[in] get_req_sga function ptr to be called to get a request SG
902 * Address (given the sge index).
903 * @param[in] get_req_sglen function ptr to be called to get a request SG
904 * len (given the sge index).
905 * @param[in] get_rsp_sga function ptr to be called to get a response SG
906 * Address (given the sge index).
907 * @param[in] get_rsp_sglen function ptr to be called to get a response SG
908 * len (given the sge index).
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700909 * @param[in] req Allocated FCXP is used to send req or rsp?
910 * request - BFA_TRUE, response - BFA_FALSE
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700911 *
912 * @return FCXP instance. NULL on failure.
913 */
914struct bfa_fcxp_s *
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700915bfa_fcxp_req_rsp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
916 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
917 bfa_fcxp_get_sglen_t req_sglen_cbfn,
918 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
919 bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700920{
921 struct bfa_fcxp_s *fcxp = NULL;
922
Jing Huangd4b671c2010-12-26 21:46:35 -0800923 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700924
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700925 fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa), req);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700926 if (fcxp == NULL)
927 return NULL;
928
929 bfa_trc(bfa, fcxp->fcxp_tag);
930
931 bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn,
932 req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn);
933
934 return fcxp;
935}
936
Jing Huang5fbe25c2010-10-18 17:17:23 -0700937/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700938 * Get the internal request buffer pointer
939 *
940 * @param[in] fcxp BFA fcxp pointer
941 *
942 * @return pointer to the internal request buffer
943 */
944void *
945bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp)
946{
947 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
948 void *reqbuf;
949
Jing Huangd4b671c2010-12-26 21:46:35 -0800950 WARN_ON(fcxp->use_ireqbuf != 1);
Krishna Gudipati45070252011-06-24 20:24:29 -0700951 reqbuf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
952 mod->req_pld_sz + mod->rsp_pld_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700953 return reqbuf;
954}
955
956u32
957bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
958{
959 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
960
961 return mod->req_pld_sz;
962}
963
Jing Huang5fbe25c2010-10-18 17:17:23 -0700964/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700965 * Get the internal response buffer pointer
966 *
967 * @param[in] fcxp BFA fcxp pointer
968 *
969 * @return pointer to the internal request buffer
970 */
971void *
972bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
973{
974 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
Krishna Gudipati45070252011-06-24 20:24:29 -0700975 void *fcxp_buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700976
Jing Huangd4b671c2010-12-26 21:46:35 -0800977 WARN_ON(fcxp->use_irspbuf != 1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700978
Krishna Gudipati45070252011-06-24 20:24:29 -0700979 fcxp_buf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
980 mod->req_pld_sz + mod->rsp_pld_sz);
981
982 /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
983 return ((u8 *) fcxp_buf) + mod->req_pld_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700984}
985
Jing Huang5fbe25c2010-10-18 17:17:23 -0700986/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800987 * Free the BFA FCXP
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700988 *
989 * @param[in] fcxp BFA fcxp pointer
990 *
991 * @return void
992 */
993void
994bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
995{
996 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
997
Jing Huangd4b671c2010-12-26 21:46:35 -0800998 WARN_ON(fcxp == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700999 bfa_trc(mod->bfa, fcxp->fcxp_tag);
1000 bfa_fcxp_put(fcxp);
1001}
1002
Jing Huang5fbe25c2010-10-18 17:17:23 -07001003/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001004 * Send a FCXP request
1005 *
1006 * @param[in] fcxp BFA fcxp pointer
1007 * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
1008 * @param[in] vf_id virtual Fabric ID
1009 * @param[in] lp_tag lport tag
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001010 * @param[in] cts use Continuous sequence
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001011 * @param[in] cos fc Class of Service
1012 * @param[in] reqlen request length, does not include FCHS length
1013 * @param[in] fchs fc Header Pointer. The header content will be copied
1014 * in by BFA.
1015 *
1016 * @param[in] cbfn call back function to be called on receiving
1017 * the response
1018 * @param[in] cbarg arg for cbfn
1019 * @param[in] rsp_timeout
1020 * response timeout
1021 *
1022 * @return bfa_status_t
1023 */
1024void
1025bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
1026 u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos,
1027 u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn,
1028 void *cbarg, u32 rsp_maxlen, u8 rsp_timeout)
1029{
1030 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
1031 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
1032 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
1033 struct bfi_fcxp_send_req_s *send_req;
1034
1035 bfa_trc(bfa, fcxp->fcxp_tag);
1036
Jing Huang5fbe25c2010-10-18 17:17:23 -07001037 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001038 * setup request/response info
1039 */
1040 reqi->bfa_rport = rport;
1041 reqi->vf_id = vf_id;
1042 reqi->lp_tag = lp_tag;
1043 reqi->class = cos;
1044 rspi->rsp_timeout = rsp_timeout;
1045 reqi->cts = cts;
1046 reqi->fchs = *fchs;
1047 reqi->req_tot_len = reqlen;
1048 rspi->rsp_maxlen = rsp_maxlen;
1049 fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
1050 fcxp->send_cbarg = cbarg;
1051
Jing Huang5fbe25c2010-10-18 17:17:23 -07001052 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001053 * If no room in CPE queue, wait for space in request queue
1054 */
1055 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
1056 if (!send_req) {
1057 bfa_trc(bfa, fcxp->fcxp_tag);
1058 fcxp->reqq_waiting = BFA_TRUE;
1059 bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe);
1060 return;
1061 }
1062
1063 bfa_fcxp_queue(fcxp, send_req);
1064}
1065
Jing Huang5fbe25c2010-10-18 17:17:23 -07001066/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001067 * Abort a BFA FCXP
1068 *
1069 * @param[in] fcxp BFA fcxp pointer
1070 *
1071 * @return void
1072 */
1073bfa_status_t
1074bfa_fcxp_abort(struct bfa_fcxp_s *fcxp)
1075{
1076 bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag);
Jing Huangd4b671c2010-12-26 21:46:35 -08001077 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001078 return BFA_STATUS_OK;
1079}
1080
1081void
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001082bfa_fcxp_req_rsp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001083 bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg,
1084 void *caller, int nreq_sgles,
1085 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
1086 bfa_fcxp_get_sglen_t req_sglen_cbfn,
1087 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001088 bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001089{
1090 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1091
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001092 if (req)
1093 WARN_ON(!list_empty(&mod->fcxp_req_free_q));
1094 else
1095 WARN_ON(!list_empty(&mod->fcxp_rsp_free_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001096
1097 wqe->alloc_cbfn = alloc_cbfn;
1098 wqe->alloc_cbarg = alloc_cbarg;
1099 wqe->caller = caller;
1100 wqe->bfa = bfa;
1101 wqe->nreq_sgles = nreq_sgles;
1102 wqe->nrsp_sgles = nrsp_sgles;
1103 wqe->req_sga_cbfn = req_sga_cbfn;
1104 wqe->req_sglen_cbfn = req_sglen_cbfn;
1105 wqe->rsp_sga_cbfn = rsp_sga_cbfn;
1106 wqe->rsp_sglen_cbfn = rsp_sglen_cbfn;
1107
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001108 if (req)
1109 list_add_tail(&wqe->qe, &mod->req_wait_q);
1110 else
1111 list_add_tail(&wqe->qe, &mod->rsp_wait_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001112}
1113
1114void
1115bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
1116{
1117 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1118
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001119 WARN_ON(!bfa_q_is_on_q(&mod->req_wait_q, wqe) ||
1120 !bfa_q_is_on_q(&mod->rsp_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001121 list_del(&wqe->qe);
1122}
1123
1124void
1125bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
1126{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001127 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001128 * If waiting for room in request queue, cancel reqq wait
1129 * and free fcxp.
1130 */
1131 if (fcxp->reqq_waiting) {
1132 fcxp->reqq_waiting = BFA_FALSE;
1133 bfa_reqq_wcancel(&fcxp->reqq_wqe);
1134 bfa_fcxp_free(fcxp);
1135 return;
1136 }
1137
1138 fcxp->send_cbfn = bfa_fcxp_null_comp;
1139}
1140
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001141void
1142bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
1143{
1144 switch (msg->mhdr.msg_id) {
1145 case BFI_FCXP_I2H_SEND_RSP:
1146 hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg);
1147 break;
1148
1149 default:
1150 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001151 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001152 }
1153}
1154
1155u32
1156bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
1157{
1158 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1159
1160 return mod->rsp_pld_sz;
1161}
1162
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001163void
1164bfa_fcxp_res_recfg(struct bfa_s *bfa, u16 num_fcxp_fw)
1165{
1166 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1167 struct list_head *qe;
1168 int i;
1169
1170 for (i = 0; i < (mod->num_fcxps - num_fcxp_fw); i++) {
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001171 if (i < ((mod->num_fcxps - num_fcxp_fw) / 2)) {
1172 bfa_q_deq_tail(&mod->fcxp_req_free_q, &qe);
1173 list_add_tail(qe, &mod->fcxp_req_unused_q);
1174 } else {
1175 bfa_q_deq_tail(&mod->fcxp_rsp_free_q, &qe);
1176 list_add_tail(qe, &mod->fcxp_rsp_unused_q);
1177 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001178 }
1179}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001180
Jing Huang5fbe25c2010-10-18 17:17:23 -07001181/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001182 * BFA LPS state machine functions
1183 */
1184
Jing Huang5fbe25c2010-10-18 17:17:23 -07001185/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001186 * Init state -- no login
1187 */
1188static void
1189bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
1190{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001191 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001192 bfa_trc(lps->bfa, event);
1193
1194 switch (event) {
1195 case BFA_LPS_SM_LOGIN:
1196 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1197 bfa_sm_set_state(lps, bfa_lps_sm_loginwait);
1198 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1199 } else {
1200 bfa_sm_set_state(lps, bfa_lps_sm_login);
1201 bfa_lps_send_login(lps);
1202 }
1203
1204 if (lps->fdisc)
1205 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1206 BFA_PL_EID_LOGIN, 0, "FDISC Request");
1207 else
1208 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1209 BFA_PL_EID_LOGIN, 0, "FLOGI Request");
1210 break;
1211
1212 case BFA_LPS_SM_LOGOUT:
1213 bfa_lps_logout_comp(lps);
1214 break;
1215
1216 case BFA_LPS_SM_DELETE:
1217 bfa_lps_free(lps);
1218 break;
1219
1220 case BFA_LPS_SM_RX_CVL:
1221 case BFA_LPS_SM_OFFLINE:
1222 break;
1223
1224 case BFA_LPS_SM_FWRSP:
1225 /*
1226 * Could happen when fabric detects loopback and discards
1227 * the lps request. Fw will eventually sent out the timeout
1228 * Just ignore
1229 */
1230 break;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07001231 case BFA_LPS_SM_SET_N2N_PID:
1232 /*
1233 * When topology is set to loop, bfa_lps_set_n2n_pid() sends
1234 * this event. Ignore this event.
1235 */
1236 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001237
1238 default:
1239 bfa_sm_fault(lps->bfa, event);
1240 }
1241}
1242
Jing Huang5fbe25c2010-10-18 17:17:23 -07001243/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001244 * login is in progress -- awaiting response from firmware
1245 */
1246static void
1247bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
1248{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001249 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001250 bfa_trc(lps->bfa, event);
1251
1252 switch (event) {
1253 case BFA_LPS_SM_FWRSP:
1254 if (lps->status == BFA_STATUS_OK) {
1255 bfa_sm_set_state(lps, bfa_lps_sm_online);
1256 if (lps->fdisc)
1257 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1258 BFA_PL_EID_LOGIN, 0, "FDISC Accept");
1259 else
1260 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1261 BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
Krishna Gudipatib7044952010-12-13 16:17:42 -08001262 /* If N2N, send the assigned PID to FW */
1263 bfa_trc(lps->bfa, lps->fport);
1264 bfa_trc(lps->bfa, lps->lp_pid);
1265
1266 if (!lps->fport && lps->lp_pid)
1267 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001268 } else {
1269 bfa_sm_set_state(lps, bfa_lps_sm_init);
1270 if (lps->fdisc)
1271 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1272 BFA_PL_EID_LOGIN, 0,
1273 "FDISC Fail (RJT or timeout)");
1274 else
1275 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1276 BFA_PL_EID_LOGIN, 0,
1277 "FLOGI Fail (RJT or timeout)");
1278 }
1279 bfa_lps_login_comp(lps);
1280 break;
1281
Vijay Mohan Guvva111ecbe2013-05-13 03:49:44 -06001282 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001283 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001284 bfa_sm_set_state(lps, bfa_lps_sm_init);
1285 break;
1286
Krishna Gudipatib7044952010-12-13 16:17:42 -08001287 case BFA_LPS_SM_SET_N2N_PID:
1288 bfa_trc(lps->bfa, lps->fport);
1289 bfa_trc(lps->bfa, lps->lp_pid);
1290 break;
1291
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001292 default:
1293 bfa_sm_fault(lps->bfa, event);
1294 }
1295}
1296
Jing Huang5fbe25c2010-10-18 17:17:23 -07001297/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001298 * login pending - awaiting space in request queue
1299 */
1300static void
1301bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1302{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001303 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001304 bfa_trc(lps->bfa, event);
1305
1306 switch (event) {
1307 case BFA_LPS_SM_RESUME:
1308 bfa_sm_set_state(lps, bfa_lps_sm_login);
Krishna Gudipatiff179e02012-03-13 17:40:31 -07001309 bfa_lps_send_login(lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001310 break;
1311
1312 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001313 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001314 bfa_sm_set_state(lps, bfa_lps_sm_init);
1315 bfa_reqq_wcancel(&lps->wqe);
1316 break;
1317
1318 case BFA_LPS_SM_RX_CVL:
1319 /*
1320 * Login was not even sent out; so when getting out
1321 * of this state, it will appear like a login retry
1322 * after Clear virtual link
1323 */
1324 break;
1325
1326 default:
1327 bfa_sm_fault(lps->bfa, event);
1328 }
1329}
1330
Jing Huang5fbe25c2010-10-18 17:17:23 -07001331/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001332 * login complete
1333 */
1334static void
1335bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
1336{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001337 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001338 bfa_trc(lps->bfa, event);
1339
1340 switch (event) {
1341 case BFA_LPS_SM_LOGOUT:
1342 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1343 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1344 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1345 } else {
1346 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1347 bfa_lps_send_logout(lps);
1348 }
1349 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1350 BFA_PL_EID_LOGO, 0, "Logout");
1351 break;
1352
1353 case BFA_LPS_SM_RX_CVL:
1354 bfa_sm_set_state(lps, bfa_lps_sm_init);
1355
1356 /* Let the vport module know about this event */
1357 bfa_lps_cvl_event(lps);
1358 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1359 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1360 break;
1361
Krishna Gudipatib7044952010-12-13 16:17:42 -08001362 case BFA_LPS_SM_SET_N2N_PID:
1363 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1364 bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
1365 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1366 } else
1367 bfa_lps_send_set_n2n_pid(lps);
1368 break;
1369
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001370 case BFA_LPS_SM_OFFLINE:
1371 case BFA_LPS_SM_DELETE:
1372 bfa_sm_set_state(lps, bfa_lps_sm_init);
1373 break;
1374
1375 default:
1376 bfa_sm_fault(lps->bfa, event);
1377 }
1378}
1379
Jing Huang8f4bfad2010-12-26 21:50:10 -08001380/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001381 * login complete
1382 */
1383static void
1384bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1385{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001386 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001387 bfa_trc(lps->bfa, event);
1388
1389 switch (event) {
1390 case BFA_LPS_SM_RESUME:
1391 bfa_sm_set_state(lps, bfa_lps_sm_online);
1392 bfa_lps_send_set_n2n_pid(lps);
1393 break;
1394
1395 case BFA_LPS_SM_LOGOUT:
1396 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1397 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1398 BFA_PL_EID_LOGO, 0, "Logout");
1399 break;
1400
1401 case BFA_LPS_SM_RX_CVL:
1402 bfa_sm_set_state(lps, bfa_lps_sm_init);
1403 bfa_reqq_wcancel(&lps->wqe);
1404
1405 /* Let the vport module know about this event */
1406 bfa_lps_cvl_event(lps);
1407 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1408 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1409 break;
1410
1411 case BFA_LPS_SM_OFFLINE:
1412 case BFA_LPS_SM_DELETE:
1413 bfa_sm_set_state(lps, bfa_lps_sm_init);
1414 bfa_reqq_wcancel(&lps->wqe);
1415 break;
1416
1417 default:
1418 bfa_sm_fault(lps->bfa, event);
1419 }
1420}
1421
Jing Huang5fbe25c2010-10-18 17:17:23 -07001422/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001423 * logout in progress - awaiting firmware response
1424 */
1425static void
1426bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
1427{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001428 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001429 bfa_trc(lps->bfa, event);
1430
1431 switch (event) {
1432 case BFA_LPS_SM_FWRSP:
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001433 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001434 bfa_sm_set_state(lps, bfa_lps_sm_init);
1435 bfa_lps_logout_comp(lps);
1436 break;
1437
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001438 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001439 bfa_sm_set_state(lps, bfa_lps_sm_init);
1440 break;
1441
1442 default:
1443 bfa_sm_fault(lps->bfa, event);
1444 }
1445}
1446
Jing Huang5fbe25c2010-10-18 17:17:23 -07001447/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001448 * logout pending -- awaiting space in request queue
1449 */
1450static void
1451bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1452{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001453 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001454 bfa_trc(lps->bfa, event);
1455
1456 switch (event) {
1457 case BFA_LPS_SM_RESUME:
1458 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1459 bfa_lps_send_logout(lps);
1460 break;
1461
1462 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001463 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001464 bfa_sm_set_state(lps, bfa_lps_sm_init);
1465 bfa_reqq_wcancel(&lps->wqe);
1466 break;
1467
1468 default:
1469 bfa_sm_fault(lps->bfa, event);
1470 }
1471}
1472
1473
1474
Jing Huang5fbe25c2010-10-18 17:17:23 -07001475/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001476 * lps_pvt BFA LPS private functions
1477 */
1478
Jing Huang5fbe25c2010-10-18 17:17:23 -07001479/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001480 * return memory requirement
1481 */
Christoph Hellwigc7c35242017-04-13 10:02:56 +02001482void
Krishna Gudipati45070252011-06-24 20:24:29 -07001483bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
1484 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001485{
Krishna Gudipati45070252011-06-24 20:24:29 -07001486 struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa);
1487
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001488 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -07001489 bfa_mem_kva_setup(minfo, lps_kva,
1490 sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001491 else
Krishna Gudipati45070252011-06-24 20:24:29 -07001492 bfa_mem_kva_setup(minfo, lps_kva,
1493 sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001494}
1495
Jing Huang5fbe25c2010-10-18 17:17:23 -07001496/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001497 * bfa module attach at initialization time
1498 */
Christoph Hellwigc7c35242017-04-13 10:02:56 +02001499void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001500bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07001501 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001502{
1503 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1504 struct bfa_lps_s *lps;
1505 int i;
1506
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001507 mod->num_lps = BFA_LPS_MAX_LPORTS;
1508 if (cfg->drvcfg.min_cfg)
1509 mod->num_lps = BFA_LPS_MIN_LPORTS;
1510 else
1511 mod->num_lps = BFA_LPS_MAX_LPORTS;
Krishna Gudipati45070252011-06-24 20:24:29 -07001512 mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001513
Krishna Gudipati45070252011-06-24 20:24:29 -07001514 bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001515
1516 INIT_LIST_HEAD(&mod->lps_free_q);
1517 INIT_LIST_HEAD(&mod->lps_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001518 INIT_LIST_HEAD(&mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001519
1520 for (i = 0; i < mod->num_lps; i++, lps++) {
1521 lps->bfa = bfa;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001522 lps->bfa_tag = (u8) i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001523 lps->reqq = BFA_REQQ_LPS;
1524 bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
1525 list_add_tail(&lps->qe, &mod->lps_free_q);
1526 }
1527}
1528
Jing Huang5fbe25c2010-10-18 17:17:23 -07001529/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001530 * IOC in disabled state -- consider all lps offline
1531 */
Christoph Hellwigc7c35242017-04-13 10:02:56 +02001532void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001533bfa_lps_iocdisable(struct bfa_s *bfa)
1534{
1535 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1536 struct bfa_lps_s *lps;
1537 struct list_head *qe, *qen;
1538
1539 list_for_each_safe(qe, qen, &mod->lps_active_q) {
1540 lps = (struct bfa_lps_s *) qe;
1541 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1542 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001543 list_for_each_safe(qe, qen, &mod->lps_login_q) {
1544 lps = (struct bfa_lps_s *) qe;
1545 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1546 }
1547 list_splice_tail_init(&mod->lps_login_q, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001548}
1549
Jing Huang5fbe25c2010-10-18 17:17:23 -07001550/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001551 * Firmware login response
1552 */
1553static void
1554bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
1555{
1556 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1557 struct bfa_lps_s *lps;
1558
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001559 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1560 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001561
1562 lps->status = rsp->status;
1563 switch (rsp->status) {
1564 case BFA_STATUS_OK:
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001565 lps->fw_tag = rsp->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001566 lps->fport = rsp->f_port;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001567 if (lps->fport)
1568 lps->lp_pid = rsp->lp_pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001569 lps->npiv_en = rsp->npiv_en;
Jing Huangba816ea2010-10-18 17:10:50 -07001570 lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001571 lps->pr_pwwn = rsp->port_name;
1572 lps->pr_nwwn = rsp->node_name;
1573 lps->auth_req = rsp->auth_req;
1574 lps->lp_mac = rsp->lp_mac;
1575 lps->brcd_switch = rsp->brcd_switch;
1576 lps->fcf_mac = rsp->fcf_mac;
1577
1578 break;
1579
1580 case BFA_STATUS_FABRIC_RJT:
1581 lps->lsrjt_rsn = rsp->lsrjt_rsn;
1582 lps->lsrjt_expl = rsp->lsrjt_expl;
1583
1584 break;
1585
1586 case BFA_STATUS_EPROTOCOL:
1587 lps->ext_status = rsp->ext_status;
1588
1589 break;
1590
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001591 case BFA_STATUS_VPORT_MAX:
Krishna Gudipatiff179e02012-03-13 17:40:31 -07001592 if (rsp->ext_status)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001593 bfa_lps_no_res(lps, rsp->ext_status);
1594 break;
1595
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001596 default:
1597 /* Nothing to do with other status */
1598 break;
1599 }
1600
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001601 list_del(&lps->qe);
1602 list_add_tail(&lps->qe, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001603 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1604}
1605
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001606static void
1607bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count)
1608{
1609 struct bfa_s *bfa = first_lps->bfa;
1610 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1611 struct list_head *qe, *qe_next;
1612 struct bfa_lps_s *lps;
1613
1614 bfa_trc(bfa, count);
1615
1616 qe = bfa_q_next(first_lps);
1617
1618 while (count && qe) {
1619 qe_next = bfa_q_next(qe);
1620 lps = (struct bfa_lps_s *)qe;
1621 bfa_trc(bfa, lps->bfa_tag);
1622 lps->status = first_lps->status;
1623 list_del(&lps->qe);
1624 list_add_tail(&lps->qe, &mod->lps_active_q);
1625 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1626 qe = qe_next;
1627 count--;
1628 }
1629}
1630
Jing Huang5fbe25c2010-10-18 17:17:23 -07001631/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001632 * Firmware logout response
1633 */
1634static void
1635bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
1636{
1637 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1638 struct bfa_lps_s *lps;
1639
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001640 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1641 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001642
1643 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1644}
1645
Jing Huang5fbe25c2010-10-18 17:17:23 -07001646/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001647 * Firmware received a Clear virtual link request (for FCoE)
1648 */
1649static void
1650bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
1651{
1652 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1653 struct bfa_lps_s *lps;
1654
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001655 lps = BFA_LPS_FROM_TAG(mod, cvl->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001656
1657 bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
1658}
1659
Jing Huang5fbe25c2010-10-18 17:17:23 -07001660/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001661 * Space is available in request queue, resume queueing request to firmware.
1662 */
1663static void
1664bfa_lps_reqq_resume(void *lps_arg)
1665{
1666 struct bfa_lps_s *lps = lps_arg;
1667
1668 bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
1669}
1670
Jing Huang5fbe25c2010-10-18 17:17:23 -07001671/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001672 * lps is freed -- triggered by vport delete
1673 */
1674static void
1675bfa_lps_free(struct bfa_lps_s *lps)
1676{
1677 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
1678
1679 lps->lp_pid = 0;
1680 list_del(&lps->qe);
1681 list_add_tail(&lps->qe, &mod->lps_free_q);
1682}
1683
Jing Huang5fbe25c2010-10-18 17:17:23 -07001684/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001685 * send login request to firmware
1686 */
1687static void
1688bfa_lps_send_login(struct bfa_lps_s *lps)
1689{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001690 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001691 struct bfi_lps_login_req_s *m;
1692
1693 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001694 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001695
1696 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001697 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001698
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001699 m->bfa_tag = lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001700 m->alpa = lps->alpa;
Jing Huangba816ea2010-10-18 17:10:50 -07001701 m->pdu_size = cpu_to_be16(lps->pdusz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001702 m->pwwn = lps->pwwn;
1703 m->nwwn = lps->nwwn;
1704 m->fdisc = lps->fdisc;
1705 m->auth_en = lps->auth_en;
1706
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001707 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
1708 list_del(&lps->qe);
1709 list_add_tail(&lps->qe, &mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001710}
1711
Jing Huang5fbe25c2010-10-18 17:17:23 -07001712/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001713 * send logout request to firmware
1714 */
1715static void
1716bfa_lps_send_logout(struct bfa_lps_s *lps)
1717{
1718 struct bfi_lps_logout_req_s *m;
1719
1720 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001721 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001722
1723 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001724 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001725
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001726 m->fw_tag = lps->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001727 m->port_name = lps->pwwn;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001728 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001729}
1730
Jing Huang8f4bfad2010-12-26 21:50:10 -08001731/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001732 * send n2n pid set request to firmware
1733 */
1734static void
1735bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
1736{
1737 struct bfi_lps_n2n_pid_req_s *m;
1738
1739 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001740 WARN_ON(!m);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001741
1742 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001743 bfa_fn_lpu(lps->bfa));
Krishna Gudipatib7044952010-12-13 16:17:42 -08001744
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001745 m->fw_tag = lps->fw_tag;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001746 m->lp_pid = lps->lp_pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001747 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001748}
1749
Jing Huang5fbe25c2010-10-18 17:17:23 -07001750/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001751 * Indirect login completion handler for non-fcs
1752 */
1753static void
1754bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
1755{
1756 struct bfa_lps_s *lps = arg;
1757
1758 if (!complete)
1759 return;
1760
1761 if (lps->fdisc)
1762 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1763 else
1764 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1765}
1766
Jing Huang5fbe25c2010-10-18 17:17:23 -07001767/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001768 * Login completion handler -- direct call for fcs, queue for others
1769 */
1770static void
1771bfa_lps_login_comp(struct bfa_lps_s *lps)
1772{
1773 if (!lps->bfa->fcs) {
1774 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
1775 lps);
1776 return;
1777 }
1778
1779 if (lps->fdisc)
1780 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1781 else
1782 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1783}
1784
Jing Huang5fbe25c2010-10-18 17:17:23 -07001785/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001786 * Indirect logout completion handler for non-fcs
1787 */
1788static void
1789bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
1790{
1791 struct bfa_lps_s *lps = arg;
1792
1793 if (!complete)
1794 return;
1795
1796 if (lps->fdisc)
1797 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001798 else
1799 bfa_cb_lps_flogo_comp(lps->bfa->bfad, lps->uarg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001800}
1801
Jing Huang5fbe25c2010-10-18 17:17:23 -07001802/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001803 * Logout completion handler -- direct call for fcs, queue for others
1804 */
1805static void
1806bfa_lps_logout_comp(struct bfa_lps_s *lps)
1807{
1808 if (!lps->bfa->fcs) {
1809 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
1810 lps);
1811 return;
1812 }
1813 if (lps->fdisc)
1814 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1815}
1816
Jing Huang5fbe25c2010-10-18 17:17:23 -07001817/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001818 * Clear virtual link completion handler for non-fcs
1819 */
1820static void
1821bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
1822{
1823 struct bfa_lps_s *lps = arg;
1824
1825 if (!complete)
1826 return;
1827
1828 /* Clear virtual link to base port will result in link down */
1829 if (lps->fdisc)
1830 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1831}
1832
Jing Huang5fbe25c2010-10-18 17:17:23 -07001833/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001834 * Received Clear virtual link event --direct call for fcs,
1835 * queue for others
1836 */
1837static void
1838bfa_lps_cvl_event(struct bfa_lps_s *lps)
1839{
1840 if (!lps->bfa->fcs) {
1841 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
1842 lps);
1843 return;
1844 }
1845
1846 /* Clear virtual link to base port will result in link down */
1847 if (lps->fdisc)
1848 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1849}
1850
1851
1852
Jing Huang5fbe25c2010-10-18 17:17:23 -07001853/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001854 * lps_public BFA LPS public functions
1855 */
1856
1857u32
1858bfa_lps_get_max_vport(struct bfa_s *bfa)
1859{
1860 if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
1861 return BFA_LPS_MAX_VPORTS_SUPP_CT;
1862 else
1863 return BFA_LPS_MAX_VPORTS_SUPP_CB;
1864}
1865
Jing Huang5fbe25c2010-10-18 17:17:23 -07001866/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001867 * Allocate a lport srvice tag.
1868 */
1869struct bfa_lps_s *
1870bfa_lps_alloc(struct bfa_s *bfa)
1871{
1872 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1873 struct bfa_lps_s *lps = NULL;
1874
1875 bfa_q_deq(&mod->lps_free_q, &lps);
1876
1877 if (lps == NULL)
1878 return NULL;
1879
1880 list_add_tail(&lps->qe, &mod->lps_active_q);
1881
1882 bfa_sm_set_state(lps, bfa_lps_sm_init);
1883 return lps;
1884}
1885
Jing Huang5fbe25c2010-10-18 17:17:23 -07001886/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001887 * Free lport service tag. This can be called anytime after an alloc.
1888 * No need to wait for any pending login/logout completions.
1889 */
1890void
1891bfa_lps_delete(struct bfa_lps_s *lps)
1892{
1893 bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
1894}
1895
Jing Huang5fbe25c2010-10-18 17:17:23 -07001896/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001897 * Initiate a lport login.
1898 */
1899void
1900bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07001901 wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001902{
1903 lps->uarg = uarg;
1904 lps->alpa = alpa;
1905 lps->pdusz = pdusz;
1906 lps->pwwn = pwwn;
1907 lps->nwwn = nwwn;
1908 lps->fdisc = BFA_FALSE;
1909 lps->auth_en = auth_en;
1910 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1911}
1912
Jing Huang5fbe25c2010-10-18 17:17:23 -07001913/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001914 * Initiate a lport fdisc login.
1915 */
1916void
1917bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
1918 wwn_t nwwn)
1919{
1920 lps->uarg = uarg;
1921 lps->alpa = 0;
1922 lps->pdusz = pdusz;
1923 lps->pwwn = pwwn;
1924 lps->nwwn = nwwn;
1925 lps->fdisc = BFA_TRUE;
1926 lps->auth_en = BFA_FALSE;
1927 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1928}
1929
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001930
Jing Huang5fbe25c2010-10-18 17:17:23 -07001931/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001932 * Initiate a lport FDSIC logout.
1933 */
1934void
1935bfa_lps_fdisclogo(struct bfa_lps_s *lps)
1936{
1937 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
1938}
1939
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001940u8
1941bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag)
1942{
1943 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1944
1945 return BFA_LPS_FROM_TAG(mod, lp_tag)->fw_tag;
1946}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001947
Jing Huang5fbe25c2010-10-18 17:17:23 -07001948/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001949 * Return lport services tag given the pid
1950 */
1951u8
1952bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
1953{
1954 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1955 struct bfa_lps_s *lps;
1956 int i;
1957
1958 for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
1959 if (lps->lp_pid == pid)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001960 return lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001961 }
1962
1963 /* Return base port tag anyway */
1964 return 0;
1965}
1966
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001967
Jing Huang5fbe25c2010-10-18 17:17:23 -07001968/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001969 * return port id assigned to the base lport
1970 */
1971u32
1972bfa_lps_get_base_pid(struct bfa_s *bfa)
1973{
1974 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1975
1976 return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
1977}
1978
Jing Huang8f4bfad2010-12-26 21:50:10 -08001979/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001980 * Set PID in case of n2n (which is assigned during PLOGI)
1981 */
1982void
1983bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
1984{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001985 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001986 bfa_trc(lps->bfa, n2n_pid);
1987
1988 lps->lp_pid = n2n_pid;
1989 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
1990}
1991
Jing Huang5fbe25c2010-10-18 17:17:23 -07001992/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001993 * LPS firmware message class handler.
1994 */
1995void
1996bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
1997{
1998 union bfi_lps_i2h_msg_u msg;
1999
2000 bfa_trc(bfa, m->mhdr.msg_id);
2001 msg.msg = m;
2002
2003 switch (m->mhdr.msg_id) {
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002004 case BFI_LPS_I2H_LOGIN_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002005 bfa_lps_login_rsp(bfa, msg.login_rsp);
2006 break;
2007
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002008 case BFI_LPS_I2H_LOGOUT_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002009 bfa_lps_logout_rsp(bfa, msg.logout_rsp);
2010 break;
2011
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002012 case BFI_LPS_I2H_CVL_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002013 bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
2014 break;
2015
2016 default:
2017 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08002018 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002019 }
2020}
2021
Krishna Gudipati7826f302011-07-20 16:59:13 -07002022static void
2023bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
2024{
2025 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2026 struct bfa_aen_entry_s *aen_entry;
2027
2028 bfad_get_aen_entry(bfad, aen_entry);
2029 if (!aen_entry)
2030 return;
2031
2032 aen_entry->aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
2033 aen_entry->aen_data.port.pwwn = fcport->pwwn;
2034
2035 /* Send the AEN notification */
2036 bfad_im_post_vendor_event(aen_entry, bfad, ++fcport->bfa->bfa_aen_seq,
2037 BFA_AEN_CAT_PORT, event);
2038}
2039
Jing Huang5fbe25c2010-10-18 17:17:23 -07002040/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002041 * FC PORT state machine functions
2042 */
2043static void
2044bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
2045 enum bfa_fcport_sm_event event)
2046{
2047 bfa_trc(fcport->bfa, event);
2048
2049 switch (event) {
2050 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002051 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002052 * Start event after IOC is configured and BFA is started.
2053 */
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08002054 fcport->use_flash_cfg = BFA_TRUE;
2055
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002056 if (bfa_fcport_send_enable(fcport)) {
2057 bfa_trc(fcport->bfa, BFA_TRUE);
2058 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2059 } else {
2060 bfa_trc(fcport->bfa, BFA_FALSE);
2061 bfa_sm_set_state(fcport,
2062 bfa_fcport_sm_enabling_qwait);
2063 }
2064 break;
2065
2066 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002067 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002068 * Port is persistently configured to be in enabled state. Do
2069 * not change state. Port enabling is done when START event is
2070 * received.
2071 */
2072 break;
2073
2074 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002075 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002076 * If a port is persistently configured to be disabled, the
2077 * first event will a port disable request.
2078 */
2079 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2080 break;
2081
2082 case BFA_FCPORT_SM_HWFAIL:
2083 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2084 break;
2085
2086 default:
2087 bfa_sm_fault(fcport->bfa, event);
2088 }
2089}
2090
2091static void
2092bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
2093 enum bfa_fcport_sm_event event)
2094{
2095 char pwwn_buf[BFA_STRING_32];
2096 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2097 bfa_trc(fcport->bfa, event);
2098
2099 switch (event) {
2100 case BFA_FCPORT_SM_QRESUME:
2101 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2102 bfa_fcport_send_enable(fcport);
2103 break;
2104
2105 case BFA_FCPORT_SM_STOP:
2106 bfa_reqq_wcancel(&fcport->reqq_wait);
2107 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2108 break;
2109
2110 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002111 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002112 * Already enable is in progress.
2113 */
2114 break;
2115
2116 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002117 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002118 * Just send disable request to firmware when room becomes
2119 * available in request queue.
2120 */
2121 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2122 bfa_reqq_wcancel(&fcport->reqq_wait);
2123 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2124 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2125 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002126 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002127 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002128 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002129 break;
2130
2131 case BFA_FCPORT_SM_LINKUP:
2132 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002133 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002134 * Possible to get link events when doing back-to-back
2135 * enable/disables.
2136 */
2137 break;
2138
2139 case BFA_FCPORT_SM_HWFAIL:
2140 bfa_reqq_wcancel(&fcport->reqq_wait);
2141 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2142 break;
2143
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002144 case BFA_FCPORT_SM_FAA_MISCONFIG:
2145 bfa_fcport_reset_linkinfo(fcport);
2146 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2147 bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
2148 break;
2149
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002150 default:
2151 bfa_sm_fault(fcport->bfa, event);
2152 }
2153}
2154
2155static void
2156bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
2157 enum bfa_fcport_sm_event event)
2158{
2159 char pwwn_buf[BFA_STRING_32];
2160 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2161 bfa_trc(fcport->bfa, event);
2162
2163 switch (event) {
2164 case BFA_FCPORT_SM_FWRSP:
2165 case BFA_FCPORT_SM_LINKDOWN:
2166 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2167 break;
2168
2169 case BFA_FCPORT_SM_LINKUP:
2170 bfa_fcport_update_linkinfo(fcport);
2171 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
2172
Jing Huangd4b671c2010-12-26 21:46:35 -08002173 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002174 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2175 break;
2176
2177 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002178 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002179 * Already being enabled.
2180 */
2181 break;
2182
2183 case BFA_FCPORT_SM_DISABLE:
2184 if (bfa_fcport_send_disable(fcport))
2185 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2186 else
2187 bfa_sm_set_state(fcport,
2188 bfa_fcport_sm_disabling_qwait);
2189
2190 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2191 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2192 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002193 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002194 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002195 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002196 break;
2197
2198 case BFA_FCPORT_SM_STOP:
2199 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2200 break;
2201
2202 case BFA_FCPORT_SM_HWFAIL:
2203 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2204 break;
2205
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002206 case BFA_FCPORT_SM_FAA_MISCONFIG:
2207 bfa_fcport_reset_linkinfo(fcport);
2208 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2209 bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
2210 break;
2211
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002212 default:
2213 bfa_sm_fault(fcport->bfa, event);
2214 }
2215}
2216
2217static void
2218bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
2219 enum bfa_fcport_sm_event event)
2220{
2221 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2222 char pwwn_buf[BFA_STRING_32];
2223 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2224
2225 bfa_trc(fcport->bfa, event);
2226
2227 switch (event) {
2228 case BFA_FCPORT_SM_LINKUP:
2229 bfa_fcport_update_linkinfo(fcport);
2230 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
Jing Huangd4b671c2010-12-26 21:46:35 -08002231 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002232 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2233 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
2234 if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
2235
2236 bfa_trc(fcport->bfa,
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002237 pevent->link_state.attr.vc_fcf.fcf.fipenabled);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002238 bfa_trc(fcport->bfa,
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002239 pevent->link_state.attr.vc_fcf.fcf.fipfailed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002240
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002241 if (pevent->link_state.attr.vc_fcf.fcf.fipfailed)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002242 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2243 BFA_PL_EID_FIP_FCF_DISC, 0,
2244 "FIP FCF Discovery Failed");
2245 else
2246 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2247 BFA_PL_EID_FIP_FCF_DISC, 0,
2248 "FIP FCF Discovered");
2249 }
2250
2251 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2252 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002253 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002254 "Base port online: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002255 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002256
2257 /* If QoS is enabled and it is not online, send AEN */
2258 if (fcport->cfg.qos_enabled &&
2259 fcport->qos_attr.state != BFA_QOS_ONLINE)
2260 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002261 break;
2262
2263 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002264 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002265 * Possible to get link down event.
2266 */
2267 break;
2268
2269 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002270 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002271 * Already enabled.
2272 */
2273 break;
2274
2275 case BFA_FCPORT_SM_DISABLE:
2276 if (bfa_fcport_send_disable(fcport))
2277 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2278 else
2279 bfa_sm_set_state(fcport,
2280 bfa_fcport_sm_disabling_qwait);
2281
2282 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2283 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2284 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002285 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002286 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002287 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002288 break;
2289
2290 case BFA_FCPORT_SM_STOP:
2291 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2292 break;
2293
2294 case BFA_FCPORT_SM_HWFAIL:
2295 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2296 break;
2297
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002298 case BFA_FCPORT_SM_FAA_MISCONFIG:
2299 bfa_fcport_reset_linkinfo(fcport);
2300 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2301 bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
2302 break;
2303
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002304 default:
2305 bfa_sm_fault(fcport->bfa, event);
2306 }
2307}
2308
2309static void
2310bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
2311 enum bfa_fcport_sm_event event)
2312{
2313 char pwwn_buf[BFA_STRING_32];
2314 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2315
2316 bfa_trc(fcport->bfa, event);
2317
2318 switch (event) {
2319 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002320 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002321 * Already enabled.
2322 */
2323 break;
2324
2325 case BFA_FCPORT_SM_DISABLE:
2326 if (bfa_fcport_send_disable(fcport))
2327 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2328 else
2329 bfa_sm_set_state(fcport,
2330 bfa_fcport_sm_disabling_qwait);
2331
2332 bfa_fcport_reset_linkinfo(fcport);
2333 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2334 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2335 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2336 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002337 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002338 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002339 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
Jing Huang88166242010-12-09 17:11:53 -08002340 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002341 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002342 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002343 break;
2344
2345 case BFA_FCPORT_SM_LINKDOWN:
2346 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2347 bfa_fcport_reset_linkinfo(fcport);
2348 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2349 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2350 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
2351 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002352 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002353 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002354 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002355 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2356 } else {
Jing Huang88166242010-12-09 17:11:53 -08002357 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002358 "Base port (WWN = %s) "
2359 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002360 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2361 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002362 break;
2363
2364 case BFA_FCPORT_SM_STOP:
2365 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2366 bfa_fcport_reset_linkinfo(fcport);
2367 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002368 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002369 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002370 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002371 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2372 } else {
Jing Huang88166242010-12-09 17:11:53 -08002373 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002374 "Base port (WWN = %s) "
2375 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002376 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2377 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002378 break;
2379
2380 case BFA_FCPORT_SM_HWFAIL:
2381 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2382 bfa_fcport_reset_linkinfo(fcport);
2383 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2384 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002385 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002386 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002387 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002388 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2389 } else {
Jing Huang88166242010-12-09 17:11:53 -08002390 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002391 "Base port (WWN = %s) "
2392 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002393 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2394 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002395 break;
2396
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002397 case BFA_FCPORT_SM_FAA_MISCONFIG:
2398 bfa_fcport_reset_linkinfo(fcport);
2399 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2400 bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
2401 break;
2402
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002403 default:
2404 bfa_sm_fault(fcport->bfa, event);
2405 }
2406}
2407
2408static void
2409bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
2410 enum bfa_fcport_sm_event event)
2411{
2412 bfa_trc(fcport->bfa, event);
2413
2414 switch (event) {
2415 case BFA_FCPORT_SM_QRESUME:
2416 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2417 bfa_fcport_send_disable(fcport);
2418 break;
2419
2420 case BFA_FCPORT_SM_STOP:
2421 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2422 bfa_reqq_wcancel(&fcport->reqq_wait);
2423 break;
2424
2425 case BFA_FCPORT_SM_ENABLE:
2426 bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
2427 break;
2428
2429 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002430 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002431 * Already being disabled.
2432 */
2433 break;
2434
2435 case BFA_FCPORT_SM_LINKUP:
2436 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002437 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002438 * Possible to get link events when doing back-to-back
2439 * enable/disables.
2440 */
2441 break;
2442
2443 case BFA_FCPORT_SM_HWFAIL:
2444 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2445 bfa_reqq_wcancel(&fcport->reqq_wait);
2446 break;
2447
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002448 case BFA_FCPORT_SM_FAA_MISCONFIG:
2449 bfa_fcport_reset_linkinfo(fcport);
2450 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2451 bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
2452 break;
2453
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002454 default:
2455 bfa_sm_fault(fcport->bfa, event);
2456 }
2457}
2458
2459static void
2460bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
2461 enum bfa_fcport_sm_event event)
2462{
2463 bfa_trc(fcport->bfa, event);
2464
2465 switch (event) {
2466 case BFA_FCPORT_SM_QRESUME:
2467 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2468 bfa_fcport_send_disable(fcport);
2469 if (bfa_fcport_send_enable(fcport))
2470 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2471 else
2472 bfa_sm_set_state(fcport,
2473 bfa_fcport_sm_enabling_qwait);
2474 break;
2475
2476 case BFA_FCPORT_SM_STOP:
2477 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2478 bfa_reqq_wcancel(&fcport->reqq_wait);
2479 break;
2480
2481 case BFA_FCPORT_SM_ENABLE:
2482 break;
2483
2484 case BFA_FCPORT_SM_DISABLE:
2485 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
2486 break;
2487
2488 case BFA_FCPORT_SM_LINKUP:
2489 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002490 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002491 * Possible to get link events when doing back-to-back
2492 * enable/disables.
2493 */
2494 break;
2495
2496 case BFA_FCPORT_SM_HWFAIL:
2497 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2498 bfa_reqq_wcancel(&fcport->reqq_wait);
2499 break;
2500
2501 default:
2502 bfa_sm_fault(fcport->bfa, event);
2503 }
2504}
2505
2506static void
2507bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
2508 enum bfa_fcport_sm_event event)
2509{
2510 char pwwn_buf[BFA_STRING_32];
2511 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2512 bfa_trc(fcport->bfa, event);
2513
2514 switch (event) {
2515 case BFA_FCPORT_SM_FWRSP:
2516 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2517 break;
2518
2519 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002520 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002521 * Already being disabled.
2522 */
2523 break;
2524
2525 case BFA_FCPORT_SM_ENABLE:
2526 if (bfa_fcport_send_enable(fcport))
2527 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2528 else
2529 bfa_sm_set_state(fcport,
2530 bfa_fcport_sm_enabling_qwait);
2531
2532 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2533 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2534 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002535 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002536 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002537 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002538 break;
2539
2540 case BFA_FCPORT_SM_STOP:
2541 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2542 break;
2543
2544 case BFA_FCPORT_SM_LINKUP:
2545 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002546 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002547 * Possible to get link events when doing back-to-back
2548 * enable/disables.
2549 */
2550 break;
2551
2552 case BFA_FCPORT_SM_HWFAIL:
2553 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2554 break;
2555
2556 default:
2557 bfa_sm_fault(fcport->bfa, event);
2558 }
2559}
2560
2561static void
2562bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
2563 enum bfa_fcport_sm_event event)
2564{
2565 char pwwn_buf[BFA_STRING_32];
2566 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2567 bfa_trc(fcport->bfa, event);
2568
2569 switch (event) {
2570 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002571 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002572 * Ignore start event for a port that is disabled.
2573 */
2574 break;
2575
2576 case BFA_FCPORT_SM_STOP:
2577 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2578 break;
2579
2580 case BFA_FCPORT_SM_ENABLE:
2581 if (bfa_fcport_send_enable(fcport))
2582 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2583 else
2584 bfa_sm_set_state(fcport,
2585 bfa_fcport_sm_enabling_qwait);
2586
2587 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2588 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2589 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002590 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002591 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002592 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002593 break;
2594
2595 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002596 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002597 * Already disabled.
2598 */
2599 break;
2600
2601 case BFA_FCPORT_SM_HWFAIL:
2602 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2603 break;
2604
Krishna Gudipatie3535462012-09-21 17:26:07 -07002605 case BFA_FCPORT_SM_DPORTENABLE:
2606 bfa_sm_set_state(fcport, bfa_fcport_sm_dport);
2607 break;
2608
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07002609 case BFA_FCPORT_SM_DDPORTENABLE:
2610 bfa_sm_set_state(fcport, bfa_fcport_sm_ddport);
2611 break;
2612
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002613 default:
2614 bfa_sm_fault(fcport->bfa, event);
2615 }
2616}
2617
2618static void
2619bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
2620 enum bfa_fcport_sm_event event)
2621{
2622 bfa_trc(fcport->bfa, event);
2623
2624 switch (event) {
2625 case BFA_FCPORT_SM_START:
2626 if (bfa_fcport_send_enable(fcport))
2627 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2628 else
2629 bfa_sm_set_state(fcport,
2630 bfa_fcport_sm_enabling_qwait);
2631 break;
2632
2633 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002634 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002635 * Ignore all other events.
2636 */
2637 ;
2638 }
2639}
2640
Jing Huang5fbe25c2010-10-18 17:17:23 -07002641/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002642 * Port is enabled. IOC is down/failed.
2643 */
2644static void
2645bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
2646 enum bfa_fcport_sm_event event)
2647{
2648 bfa_trc(fcport->bfa, event);
2649
2650 switch (event) {
2651 case BFA_FCPORT_SM_START:
2652 if (bfa_fcport_send_enable(fcport))
2653 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2654 else
2655 bfa_sm_set_state(fcport,
2656 bfa_fcport_sm_enabling_qwait);
2657 break;
2658
2659 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002660 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002661 * Ignore all events.
2662 */
2663 ;
2664 }
2665}
2666
Jing Huang5fbe25c2010-10-18 17:17:23 -07002667/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002668 * Port is disabled. IOC is down/failed.
2669 */
2670static void
2671bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
2672 enum bfa_fcport_sm_event event)
2673{
2674 bfa_trc(fcport->bfa, event);
2675
2676 switch (event) {
2677 case BFA_FCPORT_SM_START:
2678 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2679 break;
2680
2681 case BFA_FCPORT_SM_ENABLE:
2682 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2683 break;
2684
2685 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002686 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002687 * Ignore all events.
2688 */
2689 ;
2690 }
2691}
2692
Krishna Gudipatie3535462012-09-21 17:26:07 -07002693static void
2694bfa_fcport_sm_dport(struct bfa_fcport_s *fcport, enum bfa_fcport_sm_event event)
2695{
2696 bfa_trc(fcport->bfa, event);
2697
2698 switch (event) {
2699 case BFA_FCPORT_SM_DPORTENABLE:
2700 case BFA_FCPORT_SM_DISABLE:
2701 case BFA_FCPORT_SM_ENABLE:
2702 case BFA_FCPORT_SM_START:
2703 /*
2704 * Ignore event for a port that is dport
2705 */
2706 break;
2707
2708 case BFA_FCPORT_SM_STOP:
2709 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2710 break;
2711
2712 case BFA_FCPORT_SM_HWFAIL:
2713 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2714 break;
2715
2716 case BFA_FCPORT_SM_DPORTDISABLE:
2717 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2718 break;
2719
2720 default:
2721 bfa_sm_fault(fcport->bfa, event);
2722 }
2723}
2724
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002725static void
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07002726bfa_fcport_sm_ddport(struct bfa_fcport_s *fcport,
2727 enum bfa_fcport_sm_event event)
2728{
2729 bfa_trc(fcport->bfa, event);
2730
2731 switch (event) {
2732 case BFA_FCPORT_SM_DISABLE:
2733 case BFA_FCPORT_SM_DDPORTDISABLE:
2734 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2735 break;
2736
2737 case BFA_FCPORT_SM_DPORTENABLE:
2738 case BFA_FCPORT_SM_DPORTDISABLE:
2739 case BFA_FCPORT_SM_ENABLE:
2740 case BFA_FCPORT_SM_START:
2741 /**
2742 * Ignore event for a port that is ddport
2743 */
2744 break;
2745
2746 case BFA_FCPORT_SM_STOP:
2747 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2748 break;
2749
2750 case BFA_FCPORT_SM_HWFAIL:
2751 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2752 break;
2753
2754 default:
2755 bfa_sm_fault(fcport->bfa, event);
2756 }
2757}
2758
2759static void
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002760bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s *fcport,
2761 enum bfa_fcport_sm_event event)
2762{
2763 bfa_trc(fcport->bfa, event);
2764
2765 switch (event) {
2766 case BFA_FCPORT_SM_DPORTENABLE:
2767 case BFA_FCPORT_SM_ENABLE:
2768 case BFA_FCPORT_SM_START:
2769 /*
2770 * Ignore event for a port as there is FAA misconfig
2771 */
2772 break;
2773
2774 case BFA_FCPORT_SM_DISABLE:
2775 if (bfa_fcport_send_disable(fcport))
2776 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2777 else
2778 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
2779
2780 bfa_fcport_reset_linkinfo(fcport);
2781 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2782 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2783 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2784 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
2785 break;
2786
2787 case BFA_FCPORT_SM_STOP:
2788 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2789 break;
2790
2791 case BFA_FCPORT_SM_HWFAIL:
2792 bfa_fcport_reset_linkinfo(fcport);
2793 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2794 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2795 break;
2796
2797 default:
2798 bfa_sm_fault(fcport->bfa, event);
2799 }
2800}
2801
Jing Huang5fbe25c2010-10-18 17:17:23 -07002802/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002803 * Link state is down
2804 */
2805static void
2806bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
2807 enum bfa_fcport_ln_sm_event event)
2808{
2809 bfa_trc(ln->fcport->bfa, event);
2810
2811 switch (event) {
2812 case BFA_FCPORT_LN_SM_LINKUP:
2813 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2814 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2815 break;
2816
2817 default:
2818 bfa_sm_fault(ln->fcport->bfa, event);
2819 }
2820}
2821
Jing Huang5fbe25c2010-10-18 17:17:23 -07002822/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002823 * Link state is waiting for down notification
2824 */
2825static void
2826bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
2827 enum bfa_fcport_ln_sm_event event)
2828{
2829 bfa_trc(ln->fcport->bfa, event);
2830
2831 switch (event) {
2832 case BFA_FCPORT_LN_SM_LINKUP:
2833 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2834 break;
2835
2836 case BFA_FCPORT_LN_SM_NOTIFICATION:
2837 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2838 break;
2839
2840 default:
2841 bfa_sm_fault(ln->fcport->bfa, event);
2842 }
2843}
2844
Jing Huang5fbe25c2010-10-18 17:17:23 -07002845/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002846 * Link state is waiting for down notification and there is a pending up
2847 */
2848static void
2849bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
2850 enum bfa_fcport_ln_sm_event event)
2851{
2852 bfa_trc(ln->fcport->bfa, event);
2853
2854 switch (event) {
2855 case BFA_FCPORT_LN_SM_LINKDOWN:
2856 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2857 break;
2858
2859 case BFA_FCPORT_LN_SM_NOTIFICATION:
2860 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2861 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2862 break;
2863
2864 default:
2865 bfa_sm_fault(ln->fcport->bfa, event);
2866 }
2867}
2868
Jing Huang5fbe25c2010-10-18 17:17:23 -07002869/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002870 * Link state is up
2871 */
2872static void
2873bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
2874 enum bfa_fcport_ln_sm_event event)
2875{
2876 bfa_trc(ln->fcport->bfa, event);
2877
2878 switch (event) {
2879 case BFA_FCPORT_LN_SM_LINKDOWN:
2880 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2881 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2882 break;
2883
2884 default:
2885 bfa_sm_fault(ln->fcport->bfa, event);
2886 }
2887}
2888
Jing Huang5fbe25c2010-10-18 17:17:23 -07002889/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002890 * Link state is waiting for up notification
2891 */
2892static void
2893bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
2894 enum bfa_fcport_ln_sm_event event)
2895{
2896 bfa_trc(ln->fcport->bfa, event);
2897
2898 switch (event) {
2899 case BFA_FCPORT_LN_SM_LINKDOWN:
2900 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2901 break;
2902
2903 case BFA_FCPORT_LN_SM_NOTIFICATION:
2904 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
2905 break;
2906
2907 default:
2908 bfa_sm_fault(ln->fcport->bfa, event);
2909 }
2910}
2911
Jing Huang5fbe25c2010-10-18 17:17:23 -07002912/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002913 * Link state is waiting for up notification and there is a pending down
2914 */
2915static void
2916bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
2917 enum bfa_fcport_ln_sm_event event)
2918{
2919 bfa_trc(ln->fcport->bfa, event);
2920
2921 switch (event) {
2922 case BFA_FCPORT_LN_SM_LINKUP:
2923 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
2924 break;
2925
2926 case BFA_FCPORT_LN_SM_NOTIFICATION:
2927 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2928 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2929 break;
2930
2931 default:
2932 bfa_sm_fault(ln->fcport->bfa, event);
2933 }
2934}
2935
Jing Huang5fbe25c2010-10-18 17:17:23 -07002936/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002937 * Link state is waiting for up notification and there are pending down and up
2938 */
2939static void
2940bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
2941 enum bfa_fcport_ln_sm_event event)
2942{
2943 bfa_trc(ln->fcport->bfa, event);
2944
2945 switch (event) {
2946 case BFA_FCPORT_LN_SM_LINKDOWN:
2947 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2948 break;
2949
2950 case BFA_FCPORT_LN_SM_NOTIFICATION:
2951 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2952 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2953 break;
2954
2955 default:
2956 bfa_sm_fault(ln->fcport->bfa, event);
2957 }
2958}
2959
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002960static void
2961__bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
2962{
2963 struct bfa_fcport_ln_s *ln = cbarg;
2964
2965 if (complete)
2966 ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
2967 else
2968 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2969}
2970
Jing Huang5fbe25c2010-10-18 17:17:23 -07002971/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002972 * Send SCN notification to upper layers.
2973 * trunk - false if caller is fcport to ignore fcport event in trunked mode
2974 */
2975static void
2976bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
2977 bfa_boolean_t trunk)
2978{
2979 if (fcport->cfg.trunked && !trunk)
2980 return;
2981
2982 switch (event) {
2983 case BFA_PORT_LINKUP:
2984 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
2985 break;
2986 case BFA_PORT_LINKDOWN:
2987 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
2988 break;
2989 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08002990 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002991 }
2992}
2993
2994static void
2995bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
2996{
2997 struct bfa_fcport_s *fcport = ln->fcport;
2998
2999 if (fcport->bfa->fcs) {
3000 fcport->event_cbfn(fcport->event_cbarg, event);
3001 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
3002 } else {
3003 ln->ln_event = event;
3004 bfa_cb_queue(fcport->bfa, &ln->ln_qe,
3005 __bfa_cb_fcport_event, ln);
3006 }
3007}
3008
3009#define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
3010 BFA_CACHELINE_SZ))
3011
Christoph Hellwigc7c35242017-04-13 10:02:56 +02003012void
Krishna Gudipati45070252011-06-24 20:24:29 -07003013bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
3014 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003015{
Krishna Gudipati45070252011-06-24 20:24:29 -07003016 struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa);
3017
3018 bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003019}
3020
3021static void
3022bfa_fcport_qresume(void *cbarg)
3023{
3024 struct bfa_fcport_s *fcport = cbarg;
3025
3026 bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
3027}
3028
3029static void
Krishna Gudipati45070252011-06-24 20:24:29 -07003030bfa_fcport_mem_claim(struct bfa_fcport_s *fcport)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003031{
Krishna Gudipati45070252011-06-24 20:24:29 -07003032 struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003033
Krishna Gudipati45070252011-06-24 20:24:29 -07003034 fcport->stats_kva = bfa_mem_dma_virt(fcport_dma);
3035 fcport->stats_pa = bfa_mem_dma_phys(fcport_dma);
3036 fcport->stats = (union bfa_fcport_stats_u *)
3037 bfa_mem_dma_virt(fcport_dma);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003038}
3039
Jing Huang5fbe25c2010-10-18 17:17:23 -07003040/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003041 * Memory initialization.
3042 */
Christoph Hellwigc7c35242017-04-13 10:02:56 +02003043void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003044bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07003045 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003046{
3047 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3048 struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
3049 struct bfa_fcport_ln_s *ln = &fcport->ln;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003050
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003051 fcport->bfa = bfa;
3052 ln->fcport = fcport;
3053
Krishna Gudipati45070252011-06-24 20:24:29 -07003054 bfa_fcport_mem_claim(fcport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003055
3056 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
3057 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
3058
Jing Huang5fbe25c2010-10-18 17:17:23 -07003059 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003060 * initialize time stamp for stats reset
3061 */
Arnd Bergmann8f604a02017-11-10 16:37:10 +01003062 fcport->stats_reset_time = ktime_get_seconds();
Krishna Gudipati6894f012012-09-21 17:26:31 -07003063 fcport->stats_dma_ready = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003064
Jing Huang5fbe25c2010-10-18 17:17:23 -07003065 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003066 * initialize and set default configuration
3067 */
3068 port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
3069 port_cfg->speed = BFA_PORT_SPEED_AUTO;
3070 port_cfg->trunked = BFA_FALSE;
3071 port_cfg->maxfrsize = 0;
3072
3073 port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
Krishna Gudipati6894f012012-09-21 17:26:31 -07003074 port_cfg->qos_bw.high = BFA_QOS_BW_HIGH;
3075 port_cfg->qos_bw.med = BFA_QOS_BW_MED;
3076 port_cfg->qos_bw.low = BFA_QOS_BW_LOW;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003077
Vijaya Mohan Guvva4e1e0d82013-05-13 02:33:20 -07003078 fcport->fec_state = BFA_FEC_OFFLINE;
3079
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003080 INIT_LIST_HEAD(&fcport->stats_pending_q);
3081 INIT_LIST_HEAD(&fcport->statsclr_pending_q);
3082
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003083 bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
3084}
3085
Christoph Hellwigc7c35242017-04-13 10:02:56 +02003086void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003087bfa_fcport_start(struct bfa_s *bfa)
3088{
3089 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
3090}
3091
Jing Huang5fbe25c2010-10-18 17:17:23 -07003092/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003093 * Called when IOC failure is detected.
3094 */
Christoph Hellwigc7c35242017-04-13 10:02:56 +02003095void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003096bfa_fcport_iocdisable(struct bfa_s *bfa)
3097{
3098 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3099
3100 bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
3101 bfa_trunk_iocdisable(bfa);
3102}
3103
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003104/*
3105 * Update loop info in fcport for SCN online
3106 */
3107static void
3108bfa_fcport_update_loop_info(struct bfa_fcport_s *fcport,
3109 struct bfa_fcport_loop_info_s *loop_info)
3110{
3111 fcport->myalpa = loop_info->myalpa;
3112 fcport->alpabm_valid =
3113 loop_info->alpabm_val;
3114 memcpy(fcport->alpabm.alpa_bm,
3115 loop_info->alpabm.alpa_bm,
3116 sizeof(struct fc_alpabm_s));
3117}
3118
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003119static void
3120bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
3121{
3122 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
3123 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3124
3125 fcport->speed = pevent->link_state.speed;
3126 fcport->topology = pevent->link_state.topology;
3127
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003128 if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP) {
3129 bfa_fcport_update_loop_info(fcport,
3130 &pevent->link_state.attr.loop_info);
3131 return;
3132 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003133
3134 /* QoS Details */
Jing Huang6a18b162010-10-18 17:08:54 -07003135 fcport->qos_attr = pevent->link_state.qos_attr;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003136 fcport->qos_vc_attr = pevent->link_state.attr.vc_fcf.qos_vc_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003137
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07003138 if (fcport->cfg.bb_cr_enabled)
3139 fcport->bbcr_attr = pevent->link_state.attr.bbcr_attr;
Vijaya Mohan Guvva4e1e0d82013-05-13 02:33:20 -07003140
3141 fcport->fec_state = pevent->link_state.fec_state;
3142
Jing Huang5fbe25c2010-10-18 17:17:23 -07003143 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003144 * update trunk state if applicable
3145 */
3146 if (!fcport->cfg.trunked)
3147 trunk->attr.state = BFA_TRUNK_DISABLED;
3148
3149 /* update FCoE specific */
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003150 fcport->fcoe_vlan =
3151 be16_to_cpu(pevent->link_state.attr.vc_fcf.fcf.vlan);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003152
3153 bfa_trc(fcport->bfa, fcport->speed);
3154 bfa_trc(fcport->bfa, fcport->topology);
3155}
3156
3157static void
3158bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
3159{
3160 fcport->speed = BFA_PORT_SPEED_UNKNOWN;
3161 fcport->topology = BFA_PORT_TOPOLOGY_NONE;
Vijaya Mohan Guvva4e1e0d82013-05-13 02:33:20 -07003162 fcport->fec_state = BFA_FEC_OFFLINE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003163}
3164
Jing Huang5fbe25c2010-10-18 17:17:23 -07003165/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003166 * Send port enable message to firmware.
3167 */
3168static bfa_boolean_t
3169bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
3170{
3171 struct bfi_fcport_enable_req_s *m;
3172
Jing Huang5fbe25c2010-10-18 17:17:23 -07003173 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003174 * Increment message tag before queue check, so that responses to old
3175 * requests are discarded.
3176 */
3177 fcport->msgtag++;
3178
Jing Huang5fbe25c2010-10-18 17:17:23 -07003179 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003180 * check for room in queue to send request now
3181 */
3182 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3183 if (!m) {
3184 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3185 &fcport->reqq_wait);
3186 return BFA_FALSE;
3187 }
3188
3189 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003190 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003191 m->nwwn = fcport->nwwn;
3192 m->pwwn = fcport->pwwn;
3193 m->port_cfg = fcport->cfg;
3194 m->msgtag = fcport->msgtag;
Jing Huangba816ea2010-10-18 17:10:50 -07003195 m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003196 m->use_flash_cfg = fcport->use_flash_cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003197 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
3198 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
3199 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
3200
Jing Huang5fbe25c2010-10-18 17:17:23 -07003201 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003202 * queue I/O message to firmware
3203 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003204 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003205 return BFA_TRUE;
3206}
3207
Jing Huang5fbe25c2010-10-18 17:17:23 -07003208/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003209 * Send port disable message to firmware.
3210 */
3211static bfa_boolean_t
3212bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
3213{
3214 struct bfi_fcport_req_s *m;
3215
Jing Huang5fbe25c2010-10-18 17:17:23 -07003216 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003217 * Increment message tag before queue check, so that responses to old
3218 * requests are discarded.
3219 */
3220 fcport->msgtag++;
3221
Jing Huang5fbe25c2010-10-18 17:17:23 -07003222 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003223 * check for room in queue to send request now
3224 */
3225 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3226 if (!m) {
3227 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3228 &fcport->reqq_wait);
3229 return BFA_FALSE;
3230 }
3231
3232 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003233 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003234 m->msgtag = fcport->msgtag;
3235
Jing Huang5fbe25c2010-10-18 17:17:23 -07003236 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003237 * queue I/O message to firmware
3238 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003239 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003240
3241 return BFA_TRUE;
3242}
3243
3244static void
3245bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
3246{
Maggie Zhangf7f738122010-12-09 19:08:43 -08003247 fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
3248 fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003249
3250 bfa_trc(fcport->bfa, fcport->pwwn);
3251 bfa_trc(fcport->bfa, fcport->nwwn);
3252}
3253
3254static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003255bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
3256 struct bfa_qos_stats_s *s)
3257{
3258 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003259 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003260 int i;
3261
3262 /* Now swap the 32 bit fields */
3263 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
Jing Huangba816ea2010-10-18 17:10:50 -07003264 dip[i] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003265}
3266
3267static void
3268bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
3269 struct bfa_fcoe_stats_s *s)
3270{
3271 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003272 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003273 int i;
3274
3275 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
3276 i = i + 2) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003277#ifdef __BIG_ENDIAN
Jing Huangba816ea2010-10-18 17:10:50 -07003278 dip[i] = be32_to_cpu(sip[i]);
3279 dip[i + 1] = be32_to_cpu(sip[i + 1]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003280#else
Jing Huangba816ea2010-10-18 17:10:50 -07003281 dip[i] = be32_to_cpu(sip[i + 1]);
3282 dip[i + 1] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003283#endif
3284 }
3285}
3286
3287static void
3288__bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
3289{
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003290 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *)cbarg;
3291 struct bfa_cb_pending_q_s *cb;
3292 struct list_head *qe, *qen;
3293 union bfa_fcport_stats_u *ret;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003294
3295 if (complete) {
Arnd Bergmann8f604a02017-11-10 16:37:10 +01003296 time64_t time = ktime_get_seconds();
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003297
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003298 list_for_each_safe(qe, qen, &fcport->stats_pending_q) {
3299 bfa_q_deq(&fcport->stats_pending_q, &qe);
3300 cb = (struct bfa_cb_pending_q_s *)qe;
3301 if (fcport->stats_status == BFA_STATUS_OK) {
3302 ret = (union bfa_fcport_stats_u *)cb->data;
3303 /* Swap FC QoS or FCoE stats */
3304 if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
3305 bfa_fcport_qos_stats_swap(&ret->fcqos,
3306 &fcport->stats->fcqos);
3307 else {
3308 bfa_fcport_fcoe_stats_swap(&ret->fcoe,
3309 &fcport->stats->fcoe);
3310 ret->fcoe.secs_reset =
Arnd Bergmann8f604a02017-11-10 16:37:10 +01003311 time - fcport->stats_reset_time;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003312 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003313 }
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003314 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
3315 fcport->stats_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003316 }
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003317 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003318 } else {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003319 INIT_LIST_HEAD(&fcport->stats_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003320 fcport->stats_status = BFA_STATUS_OK;
3321 }
3322}
3323
3324static void
3325bfa_fcport_stats_get_timeout(void *cbarg)
3326{
3327 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3328
3329 bfa_trc(fcport->bfa, fcport->stats_qfull);
3330
3331 if (fcport->stats_qfull) {
3332 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3333 fcport->stats_qfull = BFA_FALSE;
3334 }
3335
3336 fcport->stats_status = BFA_STATUS_ETIMER;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003337 __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003338}
3339
3340static void
3341bfa_fcport_send_stats_get(void *cbarg)
3342{
3343 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3344 struct bfi_fcport_req_s *msg;
3345
3346 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3347
3348 if (!msg) {
3349 fcport->stats_qfull = BFA_TRUE;
3350 bfa_reqq_winit(&fcport->stats_reqq_wait,
3351 bfa_fcport_send_stats_get, fcport);
3352 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3353 &fcport->stats_reqq_wait);
3354 return;
3355 }
3356 fcport->stats_qfull = BFA_FALSE;
3357
Jing Huang6a18b162010-10-18 17:08:54 -07003358 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003359 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003360 bfa_fn_lpu(fcport->bfa));
3361 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003362}
3363
3364static void
3365__bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
3366{
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003367 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3368 struct bfa_cb_pending_q_s *cb;
3369 struct list_head *qe, *qen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003370
3371 if (complete) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07003372 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003373 * re-initialize time stamp for stats reset
3374 */
Arnd Bergmann8f604a02017-11-10 16:37:10 +01003375 fcport->stats_reset_time = ktime_get_seconds();
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003376 list_for_each_safe(qe, qen, &fcport->statsclr_pending_q) {
3377 bfa_q_deq(&fcport->statsclr_pending_q, &qe);
3378 cb = (struct bfa_cb_pending_q_s *)qe;
3379 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
3380 fcport->stats_status);
3381 }
3382 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003383 } else {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003384 INIT_LIST_HEAD(&fcport->statsclr_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003385 fcport->stats_status = BFA_STATUS_OK;
3386 }
3387}
3388
3389static void
3390bfa_fcport_stats_clr_timeout(void *cbarg)
3391{
3392 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3393
3394 bfa_trc(fcport->bfa, fcport->stats_qfull);
3395
3396 if (fcport->stats_qfull) {
3397 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3398 fcport->stats_qfull = BFA_FALSE;
3399 }
3400
3401 fcport->stats_status = BFA_STATUS_ETIMER;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003402 __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003403}
3404
3405static void
3406bfa_fcport_send_stats_clear(void *cbarg)
3407{
3408 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3409 struct bfi_fcport_req_s *msg;
3410
3411 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3412
3413 if (!msg) {
3414 fcport->stats_qfull = BFA_TRUE;
3415 bfa_reqq_winit(&fcport->stats_reqq_wait,
3416 bfa_fcport_send_stats_clear, fcport);
3417 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3418 &fcport->stats_reqq_wait);
3419 return;
3420 }
3421 fcport->stats_qfull = BFA_FALSE;
3422
Jing Huang6a18b162010-10-18 17:08:54 -07003423 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003424 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003425 bfa_fn_lpu(fcport->bfa));
3426 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003427}
3428
Jing Huang5fbe25c2010-10-18 17:17:23 -07003429/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003430 * Handle trunk SCN event from firmware.
3431 */
3432static void
3433bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3434{
3435 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3436 struct bfi_fcport_trunk_link_s *tlink;
3437 struct bfa_trunk_link_attr_s *lattr;
3438 enum bfa_trunk_state state_prev;
3439 int i;
3440 int link_bm = 0;
3441
3442 bfa_trc(fcport->bfa, fcport->cfg.trunked);
Jing Huangd4b671c2010-12-26 21:46:35 -08003443 WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
3444 scn->trunk_state != BFA_TRUNK_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003445
3446 bfa_trc(fcport->bfa, trunk->attr.state);
3447 bfa_trc(fcport->bfa, scn->trunk_state);
3448 bfa_trc(fcport->bfa, scn->trunk_speed);
3449
Jing Huang5fbe25c2010-10-18 17:17:23 -07003450 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003451 * Save off new state for trunk attribute query
3452 */
3453 state_prev = trunk->attr.state;
3454 if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
3455 trunk->attr.state = scn->trunk_state;
3456 trunk->attr.speed = scn->trunk_speed;
3457 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3458 lattr = &trunk->attr.link_attr[i];
3459 tlink = &scn->tlink[i];
3460
3461 lattr->link_state = tlink->state;
3462 lattr->trunk_wwn = tlink->trunk_wwn;
3463 lattr->fctl = tlink->fctl;
3464 lattr->speed = tlink->speed;
Jing Huangba816ea2010-10-18 17:10:50 -07003465 lattr->deskew = be32_to_cpu(tlink->deskew);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003466
3467 if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
3468 fcport->speed = tlink->speed;
3469 fcport->topology = BFA_PORT_TOPOLOGY_P2P;
3470 link_bm |= 1 << i;
3471 }
3472
3473 bfa_trc(fcport->bfa, lattr->link_state);
3474 bfa_trc(fcport->bfa, lattr->trunk_wwn);
3475 bfa_trc(fcport->bfa, lattr->fctl);
3476 bfa_trc(fcport->bfa, lattr->speed);
3477 bfa_trc(fcport->bfa, lattr->deskew);
3478 }
3479
3480 switch (link_bm) {
3481 case 3:
3482 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3483 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
3484 break;
3485 case 2:
3486 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3487 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
3488 break;
3489 case 1:
3490 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3491 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
3492 break;
3493 default:
3494 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3495 BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
3496 }
3497
Jing Huang5fbe25c2010-10-18 17:17:23 -07003498 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003499 * Notify upper layers if trunk state changed.
3500 */
3501 if ((state_prev != trunk->attr.state) ||
3502 (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
3503 bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
3504 BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
3505 }
3506}
3507
3508static void
3509bfa_trunk_iocdisable(struct bfa_s *bfa)
3510{
3511 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3512 int i = 0;
3513
Jing Huang5fbe25c2010-10-18 17:17:23 -07003514 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003515 * In trunked mode, notify upper layers that link is down
3516 */
3517 if (fcport->cfg.trunked) {
3518 if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
3519 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
3520
3521 fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
3522 fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
3523 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3524 fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
3525 fcport->trunk.attr.link_attr[i].fctl =
3526 BFA_TRUNK_LINK_FCTL_NORMAL;
3527 fcport->trunk.attr.link_attr[i].link_state =
3528 BFA_TRUNK_LINK_STATE_DN_LINKDN;
3529 fcport->trunk.attr.link_attr[i].speed =
3530 BFA_PORT_SPEED_UNKNOWN;
3531 fcport->trunk.attr.link_attr[i].deskew = 0;
3532 }
3533 }
3534}
3535
Jing Huang5fbe25c2010-10-18 17:17:23 -07003536/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003537 * Called to initialize port attributes
3538 */
3539void
3540bfa_fcport_init(struct bfa_s *bfa)
3541{
3542 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3543
Jing Huang5fbe25c2010-10-18 17:17:23 -07003544 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003545 * Initialize port attributes from IOC hardware data.
3546 */
3547 bfa_fcport_set_wwns(fcport);
3548 if (fcport->cfg.maxfrsize == 0)
3549 fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
3550 fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
3551 fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
3552
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003553 if (bfa_fcport_is_pbcdisabled(bfa))
3554 bfa->modules.port.pbc_disabled = BFA_TRUE;
3555
Jing Huangd4b671c2010-12-26 21:46:35 -08003556 WARN_ON(!fcport->cfg.maxfrsize);
3557 WARN_ON(!fcport->cfg.rx_bbcredit);
3558 WARN_ON(!fcport->speed_sup);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003559}
3560
Jing Huang5fbe25c2010-10-18 17:17:23 -07003561/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003562 * Firmware message handler.
3563 */
3564void
3565bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
3566{
3567 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3568 union bfi_fcport_i2h_msg_u i2hmsg;
3569
3570 i2hmsg.msg = msg;
3571 fcport->event_arg.i2hmsg = i2hmsg;
3572
3573 bfa_trc(bfa, msg->mhdr.msg_id);
3574 bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
3575
3576 switch (msg->mhdr.msg_id) {
3577 case BFI_FCPORT_I2H_ENABLE_RSP:
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003578 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
3579
Krishna Gudipati6894f012012-09-21 17:26:31 -07003580 fcport->stats_dma_ready = BFA_TRUE;
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003581 if (fcport->use_flash_cfg) {
3582 fcport->cfg = i2hmsg.penable_rsp->port_cfg;
3583 fcport->cfg.maxfrsize =
3584 cpu_to_be16(fcport->cfg.maxfrsize);
3585 fcport->cfg.path_tov =
3586 cpu_to_be16(fcport->cfg.path_tov);
3587 fcport->cfg.q_depth =
3588 cpu_to_be16(fcport->cfg.q_depth);
3589
3590 if (fcport->cfg.trunked)
3591 fcport->trunk.attr.state =
3592 BFA_TRUNK_OFFLINE;
3593 else
3594 fcport->trunk.attr.state =
3595 BFA_TRUNK_DISABLED;
Krishna Gudipati6894f012012-09-21 17:26:31 -07003596 fcport->qos_attr.qos_bw =
3597 i2hmsg.penable_rsp->port_cfg.qos_bw;
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003598 fcport->use_flash_cfg = BFA_FALSE;
3599 }
3600
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07003601 if (fcport->cfg.qos_enabled)
3602 fcport->qos_attr.state = BFA_QOS_OFFLINE;
3603 else
3604 fcport->qos_attr.state = BFA_QOS_DISABLED;
3605
Krishna Gudipati6894f012012-09-21 17:26:31 -07003606 fcport->qos_attr.qos_bw_op =
3607 i2hmsg.penable_rsp->port_cfg.qos_bw;
3608
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07003609 if (fcport->cfg.bb_cr_enabled)
3610 fcport->bbcr_attr.state = BFA_BBCR_OFFLINE;
3611 else
3612 fcport->bbcr_attr.state = BFA_BBCR_DISABLED;
3613
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003614 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003615 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003616 break;
3617
3618 case BFI_FCPORT_I2H_DISABLE_RSP:
3619 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
3620 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
3621 break;
3622
3623 case BFI_FCPORT_I2H_EVENT:
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07003624 if (fcport->cfg.bb_cr_enabled)
3625 fcport->bbcr_attr.state = BFA_BBCR_OFFLINE;
3626 else
3627 fcport->bbcr_attr.state = BFA_BBCR_DISABLED;
3628
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003629 if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
3630 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
Krishna Gudipati04ea6572012-09-21 17:26:18 -07003631 else {
3632 if (i2hmsg.event->link_state.linkstate_rsn ==
3633 BFA_PORT_LINKSTATE_RSN_FAA_MISCONFIG)
3634 bfa_sm_send_event(fcport,
3635 BFA_FCPORT_SM_FAA_MISCONFIG);
3636 else
3637 bfa_sm_send_event(fcport,
3638 BFA_FCPORT_SM_LINKDOWN);
3639 }
Krishna Gudipati6894f012012-09-21 17:26:31 -07003640 fcport->qos_attr.qos_bw_op =
3641 i2hmsg.event->link_state.qos_attr.qos_bw_op;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003642 break;
3643
3644 case BFI_FCPORT_I2H_TRUNK_SCN:
3645 bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
3646 break;
3647
3648 case BFI_FCPORT_I2H_STATS_GET_RSP:
3649 /*
3650 * check for timer pop before processing the rsp
3651 */
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003652 if (list_empty(&fcport->stats_pending_q) ||
3653 (fcport->stats_status == BFA_STATUS_ETIMER))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003654 break;
3655
3656 bfa_timer_stop(&fcport->timer);
3657 fcport->stats_status = i2hmsg.pstatsget_rsp->status;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003658 __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003659 break;
3660
3661 case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
3662 /*
3663 * check for timer pop before processing the rsp
3664 */
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003665 if (list_empty(&fcport->statsclr_pending_q) ||
3666 (fcport->stats_status == BFA_STATUS_ETIMER))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003667 break;
3668
3669 bfa_timer_stop(&fcport->timer);
3670 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003671 __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003672 break;
3673
3674 case BFI_FCPORT_I2H_ENABLE_AEN:
3675 bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
3676 break;
3677
3678 case BFI_FCPORT_I2H_DISABLE_AEN:
3679 bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
3680 break;
3681
3682 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08003683 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003684 break;
3685 }
3686}
3687
Jing Huang5fbe25c2010-10-18 17:17:23 -07003688/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003689 * Registered callback for port events.
3690 */
3691void
3692bfa_fcport_event_register(struct bfa_s *bfa,
3693 void (*cbfn) (void *cbarg,
3694 enum bfa_port_linkstate event),
3695 void *cbarg)
3696{
3697 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3698
3699 fcport->event_cbfn = cbfn;
3700 fcport->event_cbarg = cbarg;
3701}
3702
3703bfa_status_t
3704bfa_fcport_enable(struct bfa_s *bfa)
3705{
3706 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3707
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003708 if (bfa_fcport_is_pbcdisabled(bfa))
3709 return BFA_STATUS_PBC;
3710
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003711 if (bfa_ioc_is_disabled(&bfa->ioc))
3712 return BFA_STATUS_IOC_DISABLED;
3713
3714 if (fcport->diag_busy)
3715 return BFA_STATUS_DIAG_BUSY;
3716
3717 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
3718 return BFA_STATUS_OK;
3719}
3720
3721bfa_status_t
3722bfa_fcport_disable(struct bfa_s *bfa)
3723{
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003724 if (bfa_fcport_is_pbcdisabled(bfa))
3725 return BFA_STATUS_PBC;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003726
3727 if (bfa_ioc_is_disabled(&bfa->ioc))
3728 return BFA_STATUS_IOC_DISABLED;
3729
3730 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
3731 return BFA_STATUS_OK;
3732}
3733
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003734/* If PBC is disabled on port, return error */
3735bfa_status_t
3736bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
3737{
3738 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3739 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
3740 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
3741
3742 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
3743 bfa_trc(bfa, fcport->pwwn);
3744 return BFA_STATUS_PBC;
3745 }
3746 return BFA_STATUS_OK;
3747}
3748
Jing Huang5fbe25c2010-10-18 17:17:23 -07003749/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003750 * Configure port speed.
3751 */
3752bfa_status_t
3753bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3754{
3755 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3756
3757 bfa_trc(bfa, speed);
3758
3759 if (fcport->cfg.trunked == BFA_TRUE)
3760 return BFA_STATUS_TRUNK_ENABLED;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003761 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
3762 (speed == BFA_PORT_SPEED_16GBPS))
3763 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003764 if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
3765 bfa_trc(bfa, fcport->speed_sup);
3766 return BFA_STATUS_UNSUPP_SPEED;
3767 }
3768
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07003769 /* Port speed entered needs to be checked */
3770 if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
3771 /* For CT2, 1G is not supported */
3772 if ((speed == BFA_PORT_SPEED_1GBPS) &&
3773 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
3774 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia7141342011-06-24 20:23:19 -07003775
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07003776 /* Already checked for Auto Speed and Max Speed supp */
3777 if (!(speed == BFA_PORT_SPEED_1GBPS ||
3778 speed == BFA_PORT_SPEED_2GBPS ||
3779 speed == BFA_PORT_SPEED_4GBPS ||
3780 speed == BFA_PORT_SPEED_8GBPS ||
3781 speed == BFA_PORT_SPEED_16GBPS ||
3782 speed == BFA_PORT_SPEED_AUTO))
3783 return BFA_STATUS_UNSUPP_SPEED;
3784 } else {
3785 if (speed != BFA_PORT_SPEED_10GBPS)
3786 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia7141342011-06-24 20:23:19 -07003787 }
3788
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003789 fcport->cfg.speed = speed;
3790
3791 return BFA_STATUS_OK;
3792}
3793
Jing Huang5fbe25c2010-10-18 17:17:23 -07003794/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003795 * Get current speed.
3796 */
3797enum bfa_port_speed
3798bfa_fcport_get_speed(struct bfa_s *bfa)
3799{
3800 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3801
3802 return fcport->speed;
3803}
3804
Jing Huang5fbe25c2010-10-18 17:17:23 -07003805/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003806 * Configure port topology.
3807 */
3808bfa_status_t
3809bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
3810{
3811 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3812
3813 bfa_trc(bfa, topology);
3814 bfa_trc(bfa, fcport->cfg.topology);
3815
3816 switch (topology) {
3817 case BFA_PORT_TOPOLOGY_P2P:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003818 break;
3819
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003820 case BFA_PORT_TOPOLOGY_LOOP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003821 if ((bfa_fcport_is_qos_enabled(bfa) != BFA_FALSE) ||
3822 (fcport->qos_attr.state != BFA_QOS_DISABLED))
3823 return BFA_STATUS_ERROR_QOS_ENABLED;
3824 if (fcport->cfg.ratelimit != BFA_FALSE)
3825 return BFA_STATUS_ERROR_TRL_ENABLED;
3826 if ((bfa_fcport_is_trunk_enabled(bfa) != BFA_FALSE) ||
3827 (fcport->trunk.attr.state != BFA_TRUNK_DISABLED))
3828 return BFA_STATUS_ERROR_TRUNK_ENABLED;
3829 if ((bfa_fcport_get_speed(bfa) == BFA_PORT_SPEED_16GBPS) ||
3830 (fcport->cfg.speed == BFA_PORT_SPEED_16GBPS))
3831 return BFA_STATUS_UNSUPP_SPEED;
3832 if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type))
3833 return BFA_STATUS_LOOP_UNSUPP_MEZZ;
Krishna Gudipatie3535462012-09-21 17:26:07 -07003834 if (bfa_fcport_is_dport(bfa) != BFA_FALSE)
3835 return BFA_STATUS_DPORT_ERR;
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07003836 if (bfa_fcport_is_ddport(bfa) != BFA_FALSE)
3837 return BFA_STATUS_DPORT_ERR;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003838 break;
3839
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003840 case BFA_PORT_TOPOLOGY_AUTO:
3841 break;
3842
3843 default:
3844 return BFA_STATUS_EINVAL;
3845 }
3846
3847 fcport->cfg.topology = topology;
3848 return BFA_STATUS_OK;
3849}
3850
Jing Huang5fbe25c2010-10-18 17:17:23 -07003851/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003852 * Get current topology.
3853 */
3854enum bfa_port_topology
3855bfa_fcport_get_topology(struct bfa_s *bfa)
3856{
3857 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3858
3859 return fcport->topology;
3860}
3861
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003862/**
3863 * Get config topology.
3864 */
3865enum bfa_port_topology
3866bfa_fcport_get_cfg_topology(struct bfa_s *bfa)
3867{
3868 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3869
3870 return fcport->cfg.topology;
3871}
3872
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003873bfa_status_t
3874bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
3875{
3876 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3877
3878 bfa_trc(bfa, alpa);
3879 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3880 bfa_trc(bfa, fcport->cfg.hardalpa);
3881
3882 fcport->cfg.cfg_hardalpa = BFA_TRUE;
3883 fcport->cfg.hardalpa = alpa;
3884
3885 return BFA_STATUS_OK;
3886}
3887
3888bfa_status_t
3889bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
3890{
3891 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3892
3893 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3894 bfa_trc(bfa, fcport->cfg.hardalpa);
3895
3896 fcport->cfg.cfg_hardalpa = BFA_FALSE;
3897 return BFA_STATUS_OK;
3898}
3899
3900bfa_boolean_t
3901bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
3902{
3903 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3904
3905 *alpa = fcport->cfg.hardalpa;
3906 return fcport->cfg.cfg_hardalpa;
3907}
3908
3909u8
3910bfa_fcport_get_myalpa(struct bfa_s *bfa)
3911{
3912 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3913
3914 return fcport->myalpa;
3915}
3916
3917bfa_status_t
3918bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
3919{
3920 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3921
3922 bfa_trc(bfa, maxfrsize);
3923 bfa_trc(bfa, fcport->cfg.maxfrsize);
3924
3925 /* with in range */
3926 if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
3927 return BFA_STATUS_INVLD_DFSZ;
3928
3929 /* power of 2, if not the max frame size of 2112 */
3930 if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
3931 return BFA_STATUS_INVLD_DFSZ;
3932
3933 fcport->cfg.maxfrsize = maxfrsize;
3934 return BFA_STATUS_OK;
3935}
3936
3937u16
3938bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
3939{
3940 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3941
3942 return fcport->cfg.maxfrsize;
3943}
3944
3945u8
3946bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
3947{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003948 if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP)
3949 return (BFA_FCPORT_MOD(bfa))->cfg.rx_bbcredit;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003950
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003951 else
3952 return 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003953}
3954
3955void
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07003956bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003957{
3958 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3959
3960 fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003961}
3962
Jing Huang5fbe25c2010-10-18 17:17:23 -07003963/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003964 * Get port attributes.
3965 */
3966
3967wwn_t
3968bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
3969{
3970 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3971 if (node)
3972 return fcport->nwwn;
3973 else
3974 return fcport->pwwn;
3975}
3976
3977void
3978bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3979{
3980 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3981
Jing Huang6a18b162010-10-18 17:08:54 -07003982 memset(attr, 0, sizeof(struct bfa_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003983
3984 attr->nwwn = fcport->nwwn;
3985 attr->pwwn = fcport->pwwn;
3986
Maggie Zhangf7f738122010-12-09 19:08:43 -08003987 attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
3988 attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003989
Jing Huang6a18b162010-10-18 17:08:54 -07003990 memcpy(&attr->pport_cfg, &fcport->cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003991 sizeof(struct bfa_port_cfg_s));
3992 /* speed attributes */
3993 attr->pport_cfg.speed = fcport->cfg.speed;
3994 attr->speed_supported = fcport->speed_sup;
3995 attr->speed = fcport->speed;
3996 attr->cos_supported = FC_CLASS_3;
3997
3998 /* topology attributes */
3999 attr->pport_cfg.topology = fcport->cfg.topology;
4000 attr->topology = fcport->topology;
4001 attr->pport_cfg.trunked = fcport->cfg.trunked;
4002
4003 /* beacon attributes */
4004 attr->beacon = fcport->beacon;
4005 attr->link_e2e_beacon = fcport->link_e2e_beacon;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004006
4007 attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
4008 attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
4009 attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07004010
Vijaya Mohan Guvva4e1e0d82013-05-13 02:33:20 -07004011 attr->fec_state = fcport->fec_state;
4012
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07004013 /* PBC Disabled State */
4014 if (bfa_fcport_is_pbcdisabled(bfa))
4015 attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
4016 else {
4017 if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
4018 attr->port_state = BFA_PORT_ST_IOCDIS;
4019 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
4020 attr->port_state = BFA_PORT_ST_FWMISMATCH;
4021 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004022
4023 /* FCoE vlan */
4024 attr->fcoe_vlan = fcport->fcoe_vlan;
4025}
4026
4027#define BFA_FCPORT_STATS_TOV 1000
4028
Jing Huang5fbe25c2010-10-18 17:17:23 -07004029/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004030 * Fetch port statistics (FCQoS or FCoE).
4031 */
4032bfa_status_t
Krishna Gudipati37ea0552011-07-20 17:02:11 -07004033bfa_fcport_get_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004034{
4035 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4036
Krishna Gudipati6894f012012-09-21 17:26:31 -07004037 if (!bfa_iocfc_is_operational(bfa) ||
4038 !fcport->stats_dma_ready)
4039 return BFA_STATUS_IOC_NON_OP;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07004040
4041 if (!list_empty(&fcport->statsclr_pending_q))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004042 return BFA_STATUS_DEVBUSY;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004043
Krishna Gudipati37ea0552011-07-20 17:02:11 -07004044 if (list_empty(&fcport->stats_pending_q)) {
4045 list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
4046 bfa_fcport_send_stats_get(fcport);
4047 bfa_timer_start(bfa, &fcport->timer,
4048 bfa_fcport_stats_get_timeout,
4049 fcport, BFA_FCPORT_STATS_TOV);
4050 } else
4051 list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004052
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004053 return BFA_STATUS_OK;
4054}
4055
Jing Huang5fbe25c2010-10-18 17:17:23 -07004056/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004057 * Reset port statistics (FCQoS or FCoE).
4058 */
4059bfa_status_t
Krishna Gudipati37ea0552011-07-20 17:02:11 -07004060bfa_fcport_clear_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004061{
4062 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4063
Krishna Gudipati6894f012012-09-21 17:26:31 -07004064 if (!bfa_iocfc_is_operational(bfa) ||
4065 !fcport->stats_dma_ready)
4066 return BFA_STATUS_IOC_NON_OP;
4067
Krishna Gudipati37ea0552011-07-20 17:02:11 -07004068 if (!list_empty(&fcport->stats_pending_q))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004069 return BFA_STATUS_DEVBUSY;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004070
Krishna Gudipati37ea0552011-07-20 17:02:11 -07004071 if (list_empty(&fcport->statsclr_pending_q)) {
4072 list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
4073 bfa_fcport_send_stats_clear(fcport);
4074 bfa_timer_start(bfa, &fcport->timer,
4075 bfa_fcport_stats_clr_timeout,
4076 fcport, BFA_FCPORT_STATS_TOV);
4077 } else
4078 list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004079
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004080 return BFA_STATUS_OK;
4081}
4082
Jing Huang5fbe25c2010-10-18 17:17:23 -07004083/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004084 * Fetch port attributes.
4085 */
4086bfa_boolean_t
4087bfa_fcport_is_disabled(struct bfa_s *bfa)
4088{
4089 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4090
4091 return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
4092 BFA_PORT_ST_DISABLED;
4093
4094}
4095
4096bfa_boolean_t
Krishna Gudipatie3535462012-09-21 17:26:07 -07004097bfa_fcport_is_dport(struct bfa_s *bfa)
4098{
4099 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4100
4101 return (bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
4102 BFA_PORT_ST_DPORT);
4103}
4104
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07004105bfa_boolean_t
4106bfa_fcport_is_ddport(struct bfa_s *bfa)
4107{
4108 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4109
4110 return (bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
4111 BFA_PORT_ST_DDPORT);
4112}
4113
Krishna Gudipati6894f012012-09-21 17:26:31 -07004114bfa_status_t
4115bfa_fcport_set_qos_bw(struct bfa_s *bfa, struct bfa_qos_bw_s *qos_bw)
4116{
4117 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4118 enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
4119
4120 bfa_trc(bfa, ioc_type);
4121
4122 if ((qos_bw->high == 0) || (qos_bw->med == 0) || (qos_bw->low == 0))
4123 return BFA_STATUS_QOS_BW_INVALID;
4124
4125 if ((qos_bw->high + qos_bw->med + qos_bw->low) != 100)
4126 return BFA_STATUS_QOS_BW_INVALID;
4127
4128 if ((qos_bw->med > qos_bw->high) || (qos_bw->low > qos_bw->med) ||
4129 (qos_bw->low > qos_bw->high))
4130 return BFA_STATUS_QOS_BW_INVALID;
4131
4132 if ((ioc_type == BFA_IOC_TYPE_FC) &&
4133 (fcport->cfg.topology != BFA_PORT_TOPOLOGY_LOOP))
4134 fcport->cfg.qos_bw = *qos_bw;
4135
4136 return BFA_STATUS_OK;
4137}
4138
Krishna Gudipatie3535462012-09-21 17:26:07 -07004139bfa_boolean_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004140bfa_fcport_is_ratelim(struct bfa_s *bfa)
4141{
4142 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4143
4144 return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
4145
4146}
4147
Jing Huang5fbe25c2010-10-18 17:17:23 -07004148/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07004149 * Enable/Disable FAA feature in port config
4150 */
4151void
4152bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state)
4153{
4154 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4155
4156 bfa_trc(bfa, state);
4157 fcport->cfg.faa_state = state;
4158}
4159
4160/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004161 * Get default minimum ratelim speed
4162 */
4163enum bfa_port_speed
4164bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
4165{
4166 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4167
4168 bfa_trc(bfa, fcport->cfg.trl_def_speed);
4169 return fcport->cfg.trl_def_speed;
4170
4171}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004172
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004173void
4174bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
4175 bfa_boolean_t link_e2e_beacon)
4176{
4177 struct bfa_s *bfa = dev;
4178 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4179
4180 bfa_trc(bfa, beacon);
4181 bfa_trc(bfa, link_e2e_beacon);
4182 bfa_trc(bfa, fcport->beacon);
4183 bfa_trc(bfa, fcport->link_e2e_beacon);
4184
4185 fcport->beacon = beacon;
4186 fcport->link_e2e_beacon = link_e2e_beacon;
4187}
4188
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004189bfa_boolean_t
4190bfa_fcport_is_linkup(struct bfa_s *bfa)
4191{
4192 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4193
4194 return (!fcport->cfg.trunked &&
4195 bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
4196 (fcport->cfg.trunked &&
4197 fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
4198}
4199
4200bfa_boolean_t
4201bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
4202{
4203 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4204
4205 return fcport->cfg.qos_enabled;
4206}
4207
Krishna Gudipatibe540a92011-06-13 15:53:04 -07004208bfa_boolean_t
4209bfa_fcport_is_trunk_enabled(struct bfa_s *bfa)
4210{
4211 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4212
4213 return fcport->cfg.trunked;
4214}
4215
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07004216bfa_status_t
4217bfa_fcport_cfg_bbcr(struct bfa_s *bfa, bfa_boolean_t on_off, u8 bb_scn)
4218{
4219 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4220
4221 bfa_trc(bfa, on_off);
4222
4223 if (bfa_ioc_get_type(&fcport->bfa->ioc) != BFA_IOC_TYPE_FC)
4224 return BFA_STATUS_BBCR_FC_ONLY;
4225
4226 if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type) &&
4227 (bfa->ioc.attr->card_type != BFA_MFG_TYPE_CHINOOK))
4228 return BFA_STATUS_CMD_NOTSUPP_MEZZ;
4229
4230 if (on_off) {
4231 if (fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP)
4232 return BFA_STATUS_TOPOLOGY_LOOP;
4233
4234 if (fcport->cfg.qos_enabled)
4235 return BFA_STATUS_ERROR_QOS_ENABLED;
4236
4237 if (fcport->cfg.trunked)
4238 return BFA_STATUS_TRUNK_ENABLED;
4239
4240 if ((fcport->cfg.speed != BFA_PORT_SPEED_AUTO) &&
4241 (fcport->cfg.speed < bfa_ioc_speed_sup(&bfa->ioc)))
4242 return BFA_STATUS_ERR_BBCR_SPEED_UNSUPPORT;
4243
4244 if (bfa_ioc_speed_sup(&bfa->ioc) < BFA_PORT_SPEED_8GBPS)
4245 return BFA_STATUS_FEATURE_NOT_SUPPORTED;
4246
4247 if (fcport->cfg.bb_cr_enabled) {
4248 if (bb_scn != fcport->cfg.bb_scn)
4249 return BFA_STATUS_BBCR_CFG_NO_CHANGE;
4250 else
4251 return BFA_STATUS_NO_CHANGE;
4252 }
4253
4254 if ((bb_scn == 0) || (bb_scn > BFA_BB_SCN_MAX))
4255 bb_scn = BFA_BB_SCN_DEF;
4256
4257 fcport->cfg.bb_cr_enabled = on_off;
4258 fcport->cfg.bb_scn = bb_scn;
4259 } else {
4260 if (!fcport->cfg.bb_cr_enabled)
4261 return BFA_STATUS_NO_CHANGE;
4262
4263 fcport->cfg.bb_cr_enabled = on_off;
4264 fcport->cfg.bb_scn = 0;
4265 }
4266
4267 return BFA_STATUS_OK;
4268}
4269
4270bfa_status_t
4271bfa_fcport_get_bbcr_attr(struct bfa_s *bfa,
4272 struct bfa_bbcr_attr_s *bbcr_attr)
4273{
4274 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4275
4276 if (bfa_ioc_get_type(&fcport->bfa->ioc) != BFA_IOC_TYPE_FC)
4277 return BFA_STATUS_BBCR_FC_ONLY;
4278
4279 if (fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP)
4280 return BFA_STATUS_TOPOLOGY_LOOP;
4281
4282 *bbcr_attr = fcport->bbcr_attr;
4283
4284 return BFA_STATUS_OK;
4285}
4286
Krishna Gudipatie3535462012-09-21 17:26:07 -07004287void
4288bfa_fcport_dportenable(struct bfa_s *bfa)
4289{
4290 /*
4291 * Assume caller check for port is in disable state
4292 */
4293 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DPORTENABLE);
4294 bfa_port_set_dportenabled(&bfa->modules.port, BFA_TRUE);
4295}
4296
4297void
4298bfa_fcport_dportdisable(struct bfa_s *bfa)
4299{
4300 /*
4301 * Assume caller check for port is in disable state
4302 */
4303 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DPORTDISABLE);
4304 bfa_port_set_dportenabled(&bfa->modules.port, BFA_FALSE);
4305}
4306
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07004307void
4308bfa_fcport_ddportenable(struct bfa_s *bfa)
4309{
4310 /*
4311 * Assume caller check for port is in disable state
4312 */
4313 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DDPORTENABLE);
4314}
4315
4316void
4317bfa_fcport_ddportdisable(struct bfa_s *bfa)
4318{
4319 /*
4320 * Assume caller check for port is in disable state
4321 */
4322 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DDPORTDISABLE);
4323}
4324
Jing Huang5fbe25c2010-10-18 17:17:23 -07004325/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004326 * Rport State machine functions
4327 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07004328/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004329 * Beginning state, only online event expected.
4330 */
4331static void
4332bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
4333{
4334 bfa_trc(rp->bfa, rp->rport_tag);
4335 bfa_trc(rp->bfa, event);
4336
4337 switch (event) {
4338 case BFA_RPORT_SM_CREATE:
4339 bfa_stats(rp, sm_un_cr);
4340 bfa_sm_set_state(rp, bfa_rport_sm_created);
4341 break;
4342
4343 default:
4344 bfa_stats(rp, sm_un_unexp);
4345 bfa_sm_fault(rp->bfa, event);
4346 }
4347}
4348
4349static void
4350bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
4351{
4352 bfa_trc(rp->bfa, rp->rport_tag);
4353 bfa_trc(rp->bfa, event);
4354
4355 switch (event) {
4356 case BFA_RPORT_SM_ONLINE:
4357 bfa_stats(rp, sm_cr_on);
4358 if (bfa_rport_send_fwcreate(rp))
4359 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4360 else
4361 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4362 break;
4363
4364 case BFA_RPORT_SM_DELETE:
4365 bfa_stats(rp, sm_cr_del);
4366 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4367 bfa_rport_free(rp);
4368 break;
4369
4370 case BFA_RPORT_SM_HWFAIL:
4371 bfa_stats(rp, sm_cr_hwf);
4372 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4373 break;
4374
4375 default:
4376 bfa_stats(rp, sm_cr_unexp);
4377 bfa_sm_fault(rp->bfa, event);
4378 }
4379}
4380
Jing Huang5fbe25c2010-10-18 17:17:23 -07004381/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004382 * Waiting for rport create response from firmware.
4383 */
4384static void
4385bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
4386{
4387 bfa_trc(rp->bfa, rp->rport_tag);
4388 bfa_trc(rp->bfa, event);
4389
4390 switch (event) {
4391 case BFA_RPORT_SM_FWRSP:
4392 bfa_stats(rp, sm_fwc_rsp);
4393 bfa_sm_set_state(rp, bfa_rport_sm_online);
4394 bfa_rport_online_cb(rp);
4395 break;
4396
4397 case BFA_RPORT_SM_DELETE:
4398 bfa_stats(rp, sm_fwc_del);
4399 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4400 break;
4401
4402 case BFA_RPORT_SM_OFFLINE:
4403 bfa_stats(rp, sm_fwc_off);
4404 bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
4405 break;
4406
4407 case BFA_RPORT_SM_HWFAIL:
4408 bfa_stats(rp, sm_fwc_hwf);
4409 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4410 break;
4411
4412 default:
4413 bfa_stats(rp, sm_fwc_unexp);
4414 bfa_sm_fault(rp->bfa, event);
4415 }
4416}
4417
Jing Huang5fbe25c2010-10-18 17:17:23 -07004418/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004419 * Request queue is full, awaiting queue resume to send create request.
4420 */
4421static void
4422bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4423{
4424 bfa_trc(rp->bfa, rp->rport_tag);
4425 bfa_trc(rp->bfa, event);
4426
4427 switch (event) {
4428 case BFA_RPORT_SM_QRESUME:
4429 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4430 bfa_rport_send_fwcreate(rp);
4431 break;
4432
4433 case BFA_RPORT_SM_DELETE:
4434 bfa_stats(rp, sm_fwc_del);
4435 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4436 bfa_reqq_wcancel(&rp->reqq_wait);
4437 bfa_rport_free(rp);
4438 break;
4439
4440 case BFA_RPORT_SM_OFFLINE:
4441 bfa_stats(rp, sm_fwc_off);
4442 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4443 bfa_reqq_wcancel(&rp->reqq_wait);
4444 bfa_rport_offline_cb(rp);
4445 break;
4446
4447 case BFA_RPORT_SM_HWFAIL:
4448 bfa_stats(rp, sm_fwc_hwf);
4449 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4450 bfa_reqq_wcancel(&rp->reqq_wait);
4451 break;
4452
4453 default:
4454 bfa_stats(rp, sm_fwc_unexp);
4455 bfa_sm_fault(rp->bfa, event);
4456 }
4457}
4458
Jing Huang5fbe25c2010-10-18 17:17:23 -07004459/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004460 * Online state - normal parking state.
4461 */
4462static void
4463bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
4464{
4465 struct bfi_rport_qos_scn_s *qos_scn;
4466
4467 bfa_trc(rp->bfa, rp->rport_tag);
4468 bfa_trc(rp->bfa, event);
4469
4470 switch (event) {
4471 case BFA_RPORT_SM_OFFLINE:
4472 bfa_stats(rp, sm_on_off);
4473 if (bfa_rport_send_fwdelete(rp))
4474 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4475 else
4476 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4477 break;
4478
4479 case BFA_RPORT_SM_DELETE:
4480 bfa_stats(rp, sm_on_del);
4481 if (bfa_rport_send_fwdelete(rp))
4482 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4483 else
4484 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4485 break;
4486
4487 case BFA_RPORT_SM_HWFAIL:
4488 bfa_stats(rp, sm_on_hwf);
4489 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4490 break;
4491
4492 case BFA_RPORT_SM_SET_SPEED:
4493 bfa_rport_send_fwspeed(rp);
4494 break;
4495
4496 case BFA_RPORT_SM_QOS_SCN:
4497 qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
4498 rp->qos_attr = qos_scn->new_qos_attr;
4499 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
4500 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
4501 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
4502 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
4503
4504 qos_scn->old_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004505 be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004506 qos_scn->new_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004507 be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004508
4509 if (qos_scn->old_qos_attr.qos_flow_id !=
4510 qos_scn->new_qos_attr.qos_flow_id)
4511 bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
4512 qos_scn->old_qos_attr,
4513 qos_scn->new_qos_attr);
4514 if (qos_scn->old_qos_attr.qos_priority !=
4515 qos_scn->new_qos_attr.qos_priority)
4516 bfa_cb_rport_qos_scn_prio(rp->rport_drv,
4517 qos_scn->old_qos_attr,
4518 qos_scn->new_qos_attr);
4519 break;
4520
4521 default:
4522 bfa_stats(rp, sm_on_unexp);
4523 bfa_sm_fault(rp->bfa, event);
4524 }
4525}
4526
Jing Huang5fbe25c2010-10-18 17:17:23 -07004527/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004528 * Firmware rport is being deleted - awaiting f/w response.
4529 */
4530static void
4531bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
4532{
4533 bfa_trc(rp->bfa, rp->rport_tag);
4534 bfa_trc(rp->bfa, event);
4535
4536 switch (event) {
4537 case BFA_RPORT_SM_FWRSP:
4538 bfa_stats(rp, sm_fwd_rsp);
4539 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4540 bfa_rport_offline_cb(rp);
4541 break;
4542
4543 case BFA_RPORT_SM_DELETE:
4544 bfa_stats(rp, sm_fwd_del);
4545 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4546 break;
4547
4548 case BFA_RPORT_SM_HWFAIL:
4549 bfa_stats(rp, sm_fwd_hwf);
4550 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4551 bfa_rport_offline_cb(rp);
4552 break;
4553
4554 default:
4555 bfa_stats(rp, sm_fwd_unexp);
4556 bfa_sm_fault(rp->bfa, event);
4557 }
4558}
4559
4560static void
4561bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4562{
4563 bfa_trc(rp->bfa, rp->rport_tag);
4564 bfa_trc(rp->bfa, event);
4565
4566 switch (event) {
4567 case BFA_RPORT_SM_QRESUME:
4568 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4569 bfa_rport_send_fwdelete(rp);
4570 break;
4571
4572 case BFA_RPORT_SM_DELETE:
4573 bfa_stats(rp, sm_fwd_del);
4574 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4575 break;
4576
4577 case BFA_RPORT_SM_HWFAIL:
4578 bfa_stats(rp, sm_fwd_hwf);
4579 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4580 bfa_reqq_wcancel(&rp->reqq_wait);
4581 bfa_rport_offline_cb(rp);
4582 break;
4583
4584 default:
4585 bfa_stats(rp, sm_fwd_unexp);
4586 bfa_sm_fault(rp->bfa, event);
4587 }
4588}
4589
Jing Huang5fbe25c2010-10-18 17:17:23 -07004590/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004591 * Offline state.
4592 */
4593static void
4594bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
4595{
4596 bfa_trc(rp->bfa, rp->rport_tag);
4597 bfa_trc(rp->bfa, event);
4598
4599 switch (event) {
4600 case BFA_RPORT_SM_DELETE:
4601 bfa_stats(rp, sm_off_del);
4602 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4603 bfa_rport_free(rp);
4604 break;
4605
4606 case BFA_RPORT_SM_ONLINE:
4607 bfa_stats(rp, sm_off_on);
4608 if (bfa_rport_send_fwcreate(rp))
4609 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4610 else
4611 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4612 break;
4613
4614 case BFA_RPORT_SM_HWFAIL:
4615 bfa_stats(rp, sm_off_hwf);
4616 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4617 break;
4618
Krishna Gudipati61ba4392012-08-22 19:52:58 -07004619 case BFA_RPORT_SM_OFFLINE:
4620 bfa_rport_offline_cb(rp);
4621 break;
4622
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004623 default:
4624 bfa_stats(rp, sm_off_unexp);
4625 bfa_sm_fault(rp->bfa, event);
4626 }
4627}
4628
Jing Huang5fbe25c2010-10-18 17:17:23 -07004629/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004630 * Rport is deleted, waiting for firmware response to delete.
4631 */
4632static void
4633bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
4634{
4635 bfa_trc(rp->bfa, rp->rport_tag);
4636 bfa_trc(rp->bfa, event);
4637
4638 switch (event) {
4639 case BFA_RPORT_SM_FWRSP:
4640 bfa_stats(rp, sm_del_fwrsp);
4641 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4642 bfa_rport_free(rp);
4643 break;
4644
4645 case BFA_RPORT_SM_HWFAIL:
4646 bfa_stats(rp, sm_del_hwf);
4647 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4648 bfa_rport_free(rp);
4649 break;
4650
4651 default:
4652 bfa_sm_fault(rp->bfa, event);
4653 }
4654}
4655
4656static void
4657bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4658{
4659 bfa_trc(rp->bfa, rp->rport_tag);
4660 bfa_trc(rp->bfa, event);
4661
4662 switch (event) {
4663 case BFA_RPORT_SM_QRESUME:
4664 bfa_stats(rp, sm_del_fwrsp);
4665 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4666 bfa_rport_send_fwdelete(rp);
4667 break;
4668
4669 case BFA_RPORT_SM_HWFAIL:
4670 bfa_stats(rp, sm_del_hwf);
4671 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4672 bfa_reqq_wcancel(&rp->reqq_wait);
4673 bfa_rport_free(rp);
4674 break;
4675
4676 default:
4677 bfa_sm_fault(rp->bfa, event);
4678 }
4679}
4680
Jing Huang5fbe25c2010-10-18 17:17:23 -07004681/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004682 * Waiting for rport create response from firmware. A delete is pending.
4683 */
4684static void
4685bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
4686 enum bfa_rport_event event)
4687{
4688 bfa_trc(rp->bfa, rp->rport_tag);
4689 bfa_trc(rp->bfa, event);
4690
4691 switch (event) {
4692 case BFA_RPORT_SM_FWRSP:
4693 bfa_stats(rp, sm_delp_fwrsp);
4694 if (bfa_rport_send_fwdelete(rp))
4695 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4696 else
4697 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4698 break;
4699
4700 case BFA_RPORT_SM_HWFAIL:
4701 bfa_stats(rp, sm_delp_hwf);
4702 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4703 bfa_rport_free(rp);
4704 break;
4705
4706 default:
4707 bfa_stats(rp, sm_delp_unexp);
4708 bfa_sm_fault(rp->bfa, event);
4709 }
4710}
4711
Jing Huang5fbe25c2010-10-18 17:17:23 -07004712/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004713 * Waiting for rport create response from firmware. Rport offline is pending.
4714 */
4715static void
4716bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
4717 enum bfa_rport_event event)
4718{
4719 bfa_trc(rp->bfa, rp->rport_tag);
4720 bfa_trc(rp->bfa, event);
4721
4722 switch (event) {
4723 case BFA_RPORT_SM_FWRSP:
4724 bfa_stats(rp, sm_offp_fwrsp);
4725 if (bfa_rport_send_fwdelete(rp))
4726 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4727 else
4728 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4729 break;
4730
4731 case BFA_RPORT_SM_DELETE:
4732 bfa_stats(rp, sm_offp_del);
4733 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4734 break;
4735
4736 case BFA_RPORT_SM_HWFAIL:
4737 bfa_stats(rp, sm_offp_hwf);
4738 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07004739 bfa_rport_offline_cb(rp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004740 break;
4741
4742 default:
4743 bfa_stats(rp, sm_offp_unexp);
4744 bfa_sm_fault(rp->bfa, event);
4745 }
4746}
4747
Jing Huang5fbe25c2010-10-18 17:17:23 -07004748/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004749 * IOC h/w failed.
4750 */
4751static void
4752bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
4753{
4754 bfa_trc(rp->bfa, rp->rport_tag);
4755 bfa_trc(rp->bfa, event);
4756
4757 switch (event) {
4758 case BFA_RPORT_SM_OFFLINE:
4759 bfa_stats(rp, sm_iocd_off);
4760 bfa_rport_offline_cb(rp);
4761 break;
4762
4763 case BFA_RPORT_SM_DELETE:
4764 bfa_stats(rp, sm_iocd_del);
4765 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4766 bfa_rport_free(rp);
4767 break;
4768
4769 case BFA_RPORT_SM_ONLINE:
4770 bfa_stats(rp, sm_iocd_on);
4771 if (bfa_rport_send_fwcreate(rp))
4772 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4773 else
4774 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4775 break;
4776
4777 case BFA_RPORT_SM_HWFAIL:
4778 break;
4779
4780 default:
4781 bfa_stats(rp, sm_iocd_unexp);
4782 bfa_sm_fault(rp->bfa, event);
4783 }
4784}
4785
4786
4787
Jing Huang5fbe25c2010-10-18 17:17:23 -07004788/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004789 * bfa_rport_private BFA rport private functions
4790 */
4791
4792static void
4793__bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
4794{
4795 struct bfa_rport_s *rp = cbarg;
4796
4797 if (complete)
4798 bfa_cb_rport_online(rp->rport_drv);
4799}
4800
4801static void
4802__bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
4803{
4804 struct bfa_rport_s *rp = cbarg;
4805
4806 if (complete)
4807 bfa_cb_rport_offline(rp->rport_drv);
4808}
4809
4810static void
4811bfa_rport_qresume(void *cbarg)
4812{
4813 struct bfa_rport_s *rp = cbarg;
4814
4815 bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
4816}
4817
Christoph Hellwigc7c35242017-04-13 10:02:56 +02004818void
Krishna Gudipati45070252011-06-24 20:24:29 -07004819bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
4820 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004821{
Krishna Gudipati45070252011-06-24 20:24:29 -07004822 struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa);
4823
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004824 if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
4825 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
4826
Krishna Gudipati45070252011-06-24 20:24:29 -07004827 /* kva memory */
4828 bfa_mem_kva_setup(minfo, rport_kva,
4829 cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004830}
4831
Christoph Hellwigc7c35242017-04-13 10:02:56 +02004832void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004833bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07004834 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004835{
4836 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4837 struct bfa_rport_s *rp;
4838 u16 i;
4839
4840 INIT_LIST_HEAD(&mod->rp_free_q);
4841 INIT_LIST_HEAD(&mod->rp_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004842 INIT_LIST_HEAD(&mod->rp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004843
Krishna Gudipati45070252011-06-24 20:24:29 -07004844 rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004845 mod->rps_list = rp;
4846 mod->num_rports = cfg->fwcfg.num_rports;
4847
Jing Huangd4b671c2010-12-26 21:46:35 -08004848 WARN_ON(!mod->num_rports ||
4849 (mod->num_rports & (mod->num_rports - 1)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004850
4851 for (i = 0; i < mod->num_rports; i++, rp++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004852 memset(rp, 0, sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004853 rp->bfa = bfa;
4854 rp->rport_tag = i;
4855 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4856
Jing Huang5fbe25c2010-10-18 17:17:23 -07004857 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004858 * - is unused
4859 */
4860 if (i)
4861 list_add_tail(&rp->qe, &mod->rp_free_q);
4862
4863 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
4864 }
4865
Jing Huang5fbe25c2010-10-18 17:17:23 -07004866 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004867 * consume memory
4868 */
Krishna Gudipati45070252011-06-24 20:24:29 -07004869 bfa_mem_kva_curp(mod) = (u8 *) rp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004870}
4871
Christoph Hellwigc7c35242017-04-13 10:02:56 +02004872void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004873bfa_rport_iocdisable(struct bfa_s *bfa)
4874{
4875 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4876 struct bfa_rport_s *rport;
4877 struct list_head *qe, *qen;
4878
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004879 /* Enqueue unused rport resources to free_q */
4880 list_splice_tail_init(&mod->rp_unused_q, &mod->rp_free_q);
4881
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004882 list_for_each_safe(qe, qen, &mod->rp_active_q) {
4883 rport = (struct bfa_rport_s *) qe;
4884 bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
4885 }
4886}
4887
4888static struct bfa_rport_s *
4889bfa_rport_alloc(struct bfa_rport_mod_s *mod)
4890{
4891 struct bfa_rport_s *rport;
4892
4893 bfa_q_deq(&mod->rp_free_q, &rport);
4894 if (rport)
4895 list_add_tail(&rport->qe, &mod->rp_active_q);
4896
4897 return rport;
4898}
4899
4900static void
4901bfa_rport_free(struct bfa_rport_s *rport)
4902{
4903 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
4904
Jing Huangd4b671c2010-12-26 21:46:35 -08004905 WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004906 list_del(&rport->qe);
4907 list_add_tail(&rport->qe, &mod->rp_free_q);
4908}
4909
4910static bfa_boolean_t
4911bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4912{
4913 struct bfi_rport_create_req_s *m;
4914
Jing Huang5fbe25c2010-10-18 17:17:23 -07004915 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004916 * check for room in queue to send request now
4917 */
4918 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4919 if (!m) {
4920 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4921 return BFA_FALSE;
4922 }
4923
4924 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004925 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004926 m->bfa_handle = rp->rport_tag;
Jing Huangba816ea2010-10-18 17:10:50 -07004927 m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004928 m->pid = rp->rport_info.pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004929 m->lp_fwtag = bfa_lps_get_fwtag(rp->bfa, (u8)rp->rport_info.lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004930 m->local_pid = rp->rport_info.local_pid;
4931 m->fc_class = rp->rport_info.fc_class;
4932 m->vf_en = rp->rport_info.vf_en;
4933 m->vf_id = rp->rport_info.vf_id;
4934 m->cisc = rp->rport_info.cisc;
4935
Jing Huang5fbe25c2010-10-18 17:17:23 -07004936 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004937 * queue I/O message to firmware
4938 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004939 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004940 return BFA_TRUE;
4941}
4942
4943static bfa_boolean_t
4944bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4945{
4946 struct bfi_rport_delete_req_s *m;
4947
Jing Huang5fbe25c2010-10-18 17:17:23 -07004948 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004949 * check for room in queue to send request now
4950 */
4951 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4952 if (!m) {
4953 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4954 return BFA_FALSE;
4955 }
4956
4957 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004958 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004959 m->fw_handle = rp->fw_handle;
4960
Jing Huang5fbe25c2010-10-18 17:17:23 -07004961 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004962 * queue I/O message to firmware
4963 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004964 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004965 return BFA_TRUE;
4966}
4967
4968static bfa_boolean_t
4969bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4970{
4971 struct bfa_rport_speed_req_s *m;
4972
Jing Huang5fbe25c2010-10-18 17:17:23 -07004973 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004974 * check for room in queue to send request now
4975 */
4976 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4977 if (!m) {
4978 bfa_trc(rp->bfa, rp->rport_info.speed);
4979 return BFA_FALSE;
4980 }
4981
4982 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004983 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004984 m->fw_handle = rp->fw_handle;
4985 m->speed = (u8)rp->rport_info.speed;
4986
Jing Huang5fbe25c2010-10-18 17:17:23 -07004987 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004988 * queue I/O message to firmware
4989 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004990 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004991 return BFA_TRUE;
4992}
4993
4994
4995
Jing Huang5fbe25c2010-10-18 17:17:23 -07004996/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004997 * bfa_rport_public
4998 */
4999
Jing Huang5fbe25c2010-10-18 17:17:23 -07005000/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005001 * Rport interrupt processing.
5002 */
5003void
5004bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
5005{
5006 union bfi_rport_i2h_msg_u msg;
5007 struct bfa_rport_s *rp;
5008
5009 bfa_trc(bfa, m->mhdr.msg_id);
5010
5011 msg.msg = m;
5012
5013 switch (m->mhdr.msg_id) {
5014 case BFI_RPORT_I2H_CREATE_RSP:
5015 rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
5016 rp->fw_handle = msg.create_rsp->fw_handle;
5017 rp->qos_attr = msg.create_rsp->qos_attr;
Krishna Gudipati83763d52011-07-20 17:04:03 -07005018 bfa_rport_set_lunmask(bfa, rp);
Jing Huangd4b671c2010-12-26 21:46:35 -08005019 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005020 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
5021 break;
5022
5023 case BFI_RPORT_I2H_DELETE_RSP:
5024 rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08005025 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
Krishna Gudipati83763d52011-07-20 17:04:03 -07005026 bfa_rport_unset_lunmask(bfa, rp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005027 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
5028 break;
5029
5030 case BFI_RPORT_I2H_QOS_SCN:
5031 rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
5032 rp->event_arg.fw_msg = msg.qos_scn_evt;
5033 bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
5034 break;
5035
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07005036 case BFI_RPORT_I2H_LIP_SCN_ONLINE:
5037 bfa_fcport_update_loop_info(BFA_FCPORT_MOD(bfa),
5038 &msg.lip_scn->loop_info);
5039 bfa_cb_rport_scn_online(bfa);
5040 break;
5041
5042 case BFI_RPORT_I2H_LIP_SCN_OFFLINE:
5043 bfa_cb_rport_scn_offline(bfa);
5044 break;
5045
5046 case BFI_RPORT_I2H_NO_DEV:
5047 rp = BFA_RPORT_FROM_TAG(bfa, msg.lip_scn->bfa_handle);
5048 bfa_cb_rport_scn_no_dev(rp->rport_drv);
5049 break;
5050
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005051 default:
5052 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08005053 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005054 }
5055}
5056
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005057void
5058bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw)
5059{
5060 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
5061 struct list_head *qe;
5062 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005063
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005064 for (i = 0; i < (mod->num_rports - num_rport_fw); i++) {
5065 bfa_q_deq_tail(&mod->rp_free_q, &qe);
5066 list_add_tail(qe, &mod->rp_unused_q);
5067 }
5068}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005069
Jing Huang5fbe25c2010-10-18 17:17:23 -07005070/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005071 * bfa_rport_api
5072 */
5073
5074struct bfa_rport_s *
5075bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
5076{
5077 struct bfa_rport_s *rp;
5078
5079 rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
5080
5081 if (rp == NULL)
5082 return NULL;
5083
5084 rp->bfa = bfa;
5085 rp->rport_drv = rport_drv;
Maggie Zhangf7f738122010-12-09 19:08:43 -08005086 memset(&rp->stats, 0, sizeof(rp->stats));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005087
Jing Huangd4b671c2010-12-26 21:46:35 -08005088 WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005089 bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
5090
5091 return rp;
5092}
5093
5094void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005095bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
5096{
Jing Huangd4b671c2010-12-26 21:46:35 -08005097 WARN_ON(rport_info->max_frmsz == 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005098
Jing Huang5fbe25c2010-10-18 17:17:23 -07005099 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005100 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
5101 * responses. Default to minimum size.
5102 */
5103 if (rport_info->max_frmsz == 0) {
5104 bfa_trc(rport->bfa, rport->rport_tag);
5105 rport_info->max_frmsz = FC_MIN_PDUSZ;
5106 }
5107
Jing Huang6a18b162010-10-18 17:08:54 -07005108 rport->rport_info = *rport_info;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005109 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
5110}
5111
5112void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005113bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
5114{
Jing Huangd4b671c2010-12-26 21:46:35 -08005115 WARN_ON(speed == 0);
5116 WARN_ON(speed == BFA_PORT_SPEED_AUTO);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005117
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005118 if (rport) {
5119 rport->rport_info.speed = speed;
5120 bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
5121 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005122}
5123
Krishna Gudipati83763d52011-07-20 17:04:03 -07005124/* Set Rport LUN Mask */
5125void
5126bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
5127{
5128 struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
5129 wwn_t lp_wwn, rp_wwn;
5130 u8 lp_tag = (u8)rp->rport_info.lp_tag;
5131
5132 rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
5133 lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
5134
5135 BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
5136 rp->lun_mask = BFA_TRUE;
5137 bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn, rp->rport_tag, lp_tag);
5138}
5139
5140/* Unset Rport LUN mask */
5141void
5142bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
5143{
5144 struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
5145 wwn_t lp_wwn, rp_wwn;
5146
5147 rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
5148 lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
5149
5150 BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
5151 rp->lun_mask = BFA_FALSE;
5152 bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn,
5153 BFA_RPORT_TAG_INVALID, BFA_LP_TAG_INVALID);
5154}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005155
Jing Huang5fbe25c2010-10-18 17:17:23 -07005156/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005157 * SGPG related functions
5158 */
5159
Jing Huang5fbe25c2010-10-18 17:17:23 -07005160/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005161 * Compute and return memory needed by FCP(im) module.
5162 */
Christoph Hellwigc7c35242017-04-13 10:02:56 +02005163void
Krishna Gudipati45070252011-06-24 20:24:29 -07005164bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
5165 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005166{
Krishna Gudipati45070252011-06-24 20:24:29 -07005167 struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa);
5168 struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa);
5169 struct bfa_mem_dma_s *seg_ptr;
5170 u16 nsegs, idx, per_seg_sgpg, num_sgpg;
5171 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
5172
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005173 if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
5174 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
Krishna Gudipati45070252011-06-24 20:24:29 -07005175 else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX)
5176 cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005177
Krishna Gudipati45070252011-06-24 20:24:29 -07005178 num_sgpg = cfg->drvcfg.num_sgpgs;
5179
5180 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
5181 per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz);
5182
5183 bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) {
5184 if (num_sgpg >= per_seg_sgpg) {
5185 num_sgpg -= per_seg_sgpg;
5186 bfa_mem_dma_setup(minfo, seg_ptr,
5187 per_seg_sgpg * sgpg_sz);
5188 } else
5189 bfa_mem_dma_setup(minfo, seg_ptr,
5190 num_sgpg * sgpg_sz);
5191 }
5192
5193 /* kva memory */
5194 bfa_mem_kva_setup(minfo, sgpg_kva,
5195 cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005196}
5197
Christoph Hellwigc7c35242017-04-13 10:02:56 +02005198void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005199bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07005200 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005201{
5202 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005203 struct bfa_sgpg_s *hsgpg;
5204 struct bfi_sgpg_s *sgpg;
5205 u64 align_len;
Krishna Gudipati45070252011-06-24 20:24:29 -07005206 struct bfa_mem_dma_s *seg_ptr;
5207 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
5208 u16 i, idx, nsegs, per_seg_sgpg, num_sgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005209
5210 union {
5211 u64 pa;
5212 union bfi_addr_u addr;
5213 } sgpg_pa, sgpg_pa_tmp;
5214
5215 INIT_LIST_HEAD(&mod->sgpg_q);
5216 INIT_LIST_HEAD(&mod->sgpg_wait_q);
5217
5218 bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
5219
Krishna Gudipati45070252011-06-24 20:24:29 -07005220 mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005221
Krishna Gudipati45070252011-06-24 20:24:29 -07005222 num_sgpg = cfg->drvcfg.num_sgpgs;
5223 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005224
Krishna Gudipati45070252011-06-24 20:24:29 -07005225 /* dma/kva mem claim */
5226 hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005227
Krishna Gudipati45070252011-06-24 20:24:29 -07005228 bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005229
Krishna Gudipati45070252011-06-24 20:24:29 -07005230 if (!bfa_mem_dma_virt(seg_ptr))
5231 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005232
Krishna Gudipati45070252011-06-24 20:24:29 -07005233 align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) -
5234 bfa_mem_dma_phys(seg_ptr);
5235
5236 sgpg = (struct bfi_sgpg_s *)
5237 (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len);
5238 sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len;
5239 WARN_ON(sgpg_pa.pa & (sgpg_sz - 1));
5240
5241 per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz;
5242
5243 for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) {
5244 memset(hsgpg, 0, sizeof(*hsgpg));
5245 memset(sgpg, 0, sizeof(*sgpg));
5246
5247 hsgpg->sgpg = sgpg;
5248 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
5249 hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
5250 list_add_tail(&hsgpg->qe, &mod->sgpg_q);
5251
5252 sgpg++;
5253 hsgpg++;
5254 sgpg_pa.pa += sgpg_sz;
5255 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005256 }
5257
Krishna Gudipati45070252011-06-24 20:24:29 -07005258 bfa_mem_kva_curp(mod) = (u8 *) hsgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005259}
5260
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005261bfa_status_t
5262bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
5263{
5264 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5265 struct bfa_sgpg_s *hsgpg;
5266 int i;
5267
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005268 if (mod->free_sgpgs < nsgpgs)
5269 return BFA_STATUS_ENOMEM;
5270
5271 for (i = 0; i < nsgpgs; i++) {
5272 bfa_q_deq(&mod->sgpg_q, &hsgpg);
Jing Huangd4b671c2010-12-26 21:46:35 -08005273 WARN_ON(!hsgpg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005274 list_add_tail(&hsgpg->qe, sgpg_q);
5275 }
5276
5277 mod->free_sgpgs -= nsgpgs;
5278 return BFA_STATUS_OK;
5279}
5280
5281void
5282bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
5283{
5284 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5285 struct bfa_sgpg_wqe_s *wqe;
5286
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005287 mod->free_sgpgs += nsgpg;
Jing Huangd4b671c2010-12-26 21:46:35 -08005288 WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005289
5290 list_splice_tail_init(sgpg_q, &mod->sgpg_q);
5291
5292 if (list_empty(&mod->sgpg_wait_q))
5293 return;
5294
Jing Huang5fbe25c2010-10-18 17:17:23 -07005295 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005296 * satisfy as many waiting requests as possible
5297 */
5298 do {
5299 wqe = bfa_q_first(&mod->sgpg_wait_q);
5300 if (mod->free_sgpgs < wqe->nsgpg)
5301 nsgpg = mod->free_sgpgs;
5302 else
5303 nsgpg = wqe->nsgpg;
5304 bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
5305 wqe->nsgpg -= nsgpg;
5306 if (wqe->nsgpg == 0) {
5307 list_del(&wqe->qe);
5308 wqe->cbfn(wqe->cbarg);
5309 }
5310 } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
5311}
5312
5313void
5314bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
5315{
5316 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5317
Jing Huangd4b671c2010-12-26 21:46:35 -08005318 WARN_ON(nsgpg <= 0);
5319 WARN_ON(nsgpg <= mod->free_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005320
5321 wqe->nsgpg_total = wqe->nsgpg = nsgpg;
5322
Jing Huang5fbe25c2010-10-18 17:17:23 -07005323 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005324 * allocate any left to this one first
5325 */
5326 if (mod->free_sgpgs) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07005327 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005328 * no one else is waiting for SGPG
5329 */
Jing Huangd4b671c2010-12-26 21:46:35 -08005330 WARN_ON(!list_empty(&mod->sgpg_wait_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005331 list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
5332 wqe->nsgpg -= mod->free_sgpgs;
5333 mod->free_sgpgs = 0;
5334 }
5335
5336 list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
5337}
5338
5339void
5340bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
5341{
5342 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5343
Jing Huangd4b671c2010-12-26 21:46:35 -08005344 WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005345 list_del(&wqe->qe);
5346
5347 if (wqe->nsgpg_total != wqe->nsgpg)
5348 bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
5349 wqe->nsgpg_total - wqe->nsgpg);
5350}
5351
5352void
5353bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
5354 void *cbarg)
5355{
5356 INIT_LIST_HEAD(&wqe->sgpg_q);
5357 wqe->cbfn = cbfn;
5358 wqe->cbarg = cbarg;
5359}
5360
Jing Huang5fbe25c2010-10-18 17:17:23 -07005361/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005362 * UF related functions
5363 */
5364/*
5365 *****************************************************************************
5366 * Internal functions
5367 *****************************************************************************
5368 */
5369static void
5370__bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
5371{
5372 struct bfa_uf_s *uf = cbarg;
5373 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
5374
5375 if (complete)
5376 ufm->ufrecv(ufm->cbarg, uf);
5377}
5378
5379static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005380claim_uf_post_msgs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005381{
5382 struct bfi_uf_buf_post_s *uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005383 u16 i;
5384 u16 buf_len;
5385
Krishna Gudipati45070252011-06-24 20:24:29 -07005386 ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005387 uf_bp_msg = ufm->uf_buf_posts;
5388
5389 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
5390 i++, uf_bp_msg++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005391 memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005392
5393 uf_bp_msg->buf_tag = i;
5394 buf_len = sizeof(struct bfa_uf_buf_s);
Jing Huangba816ea2010-10-18 17:10:50 -07005395 uf_bp_msg->buf_len = cpu_to_be16(buf_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005396 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005397 bfa_fn_lpu(ufm->bfa));
Krishna Gudipati85ce9282011-06-13 15:39:36 -07005398 bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005399 }
5400
Jing Huang5fbe25c2010-10-18 17:17:23 -07005401 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005402 * advance pointer beyond consumed memory
5403 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005404 bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005405}
5406
5407static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005408claim_ufs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005409{
5410 u16 i;
5411 struct bfa_uf_s *uf;
5412
5413 /*
5414 * Claim block of memory for UF list
5415 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005416 ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005417
5418 /*
5419 * Initialize UFs and queue it in UF free queue
5420 */
5421 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005422 memset(uf, 0, sizeof(struct bfa_uf_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005423 uf->bfa = ufm->bfa;
5424 uf->uf_tag = i;
Krishna Gudipati45070252011-06-24 20:24:29 -07005425 uf->pb_len = BFA_PER_UF_DMA_SZ;
5426 uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005427 uf->buf_pa = ufm_pbs_pa(ufm, i);
5428 list_add_tail(&uf->qe, &ufm->uf_free_q);
5429 }
5430
Jing Huang5fbe25c2010-10-18 17:17:23 -07005431 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005432 * advance memory pointer
5433 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005434 bfa_mem_kva_curp(ufm) = (u8 *) uf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005435}
5436
5437static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005438uf_mem_claim(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005439{
Krishna Gudipati45070252011-06-24 20:24:29 -07005440 claim_ufs(ufm);
5441 claim_uf_post_msgs(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005442}
5443
Christoph Hellwigc7c35242017-04-13 10:02:56 +02005444void
Krishna Gudipati45070252011-06-24 20:24:29 -07005445bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
5446 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005447{
Krishna Gudipati45070252011-06-24 20:24:29 -07005448 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5449 struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa);
5450 u32 num_ufs = cfg->fwcfg.num_uf_bufs;
5451 struct bfa_mem_dma_s *seg_ptr;
5452 u16 nsegs, idx, per_seg_uf = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005453
Krishna Gudipati45070252011-06-24 20:24:29 -07005454 nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ);
5455 per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005456
Krishna Gudipati45070252011-06-24 20:24:29 -07005457 bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) {
5458 if (num_ufs >= per_seg_uf) {
5459 num_ufs -= per_seg_uf;
5460 bfa_mem_dma_setup(minfo, seg_ptr,
5461 per_seg_uf * BFA_PER_UF_DMA_SZ);
5462 } else
5463 bfa_mem_dma_setup(minfo, seg_ptr,
5464 num_ufs * BFA_PER_UF_DMA_SZ);
5465 }
5466
5467 /* kva memory */
5468 bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs *
5469 (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005470}
5471
Christoph Hellwigc7c35242017-04-13 10:02:56 +02005472void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005473bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07005474 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005475{
5476 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5477
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005478 ufm->bfa = bfa;
5479 ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
5480 INIT_LIST_HEAD(&ufm->uf_free_q);
5481 INIT_LIST_HEAD(&ufm->uf_posted_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005482 INIT_LIST_HEAD(&ufm->uf_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005483
Krishna Gudipati45070252011-06-24 20:24:29 -07005484 uf_mem_claim(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005485}
5486
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005487static struct bfa_uf_s *
5488bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
5489{
5490 struct bfa_uf_s *uf;
5491
5492 bfa_q_deq(&uf_mod->uf_free_q, &uf);
5493 return uf;
5494}
5495
5496static void
5497bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
5498{
5499 list_add_tail(&uf->qe, &uf_mod->uf_free_q);
5500}
5501
5502static bfa_status_t
5503bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
5504{
5505 struct bfi_uf_buf_post_s *uf_post_msg;
5506
5507 uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
5508 if (!uf_post_msg)
5509 return BFA_STATUS_FAILED;
5510
Jing Huang6a18b162010-10-18 17:08:54 -07005511 memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005512 sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005513 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP, uf_post_msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005514
5515 bfa_trc(ufm->bfa, uf->uf_tag);
5516
5517 list_add_tail(&uf->qe, &ufm->uf_posted_q);
5518 return BFA_STATUS_OK;
5519}
5520
5521static void
5522bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
5523{
5524 struct bfa_uf_s *uf;
5525
5526 while ((uf = bfa_uf_get(uf_mod)) != NULL) {
5527 if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
5528 break;
5529 }
5530}
5531
5532static void
5533uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
5534{
5535 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5536 u16 uf_tag = m->buf_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005537 struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
Krishna Gudipati45070252011-06-24 20:24:29 -07005538 struct bfa_uf_buf_s *uf_buf;
5539 uint8_t *buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005540 struct fchs_s *fchs;
5541
Krishna Gudipati45070252011-06-24 20:24:29 -07005542 uf_buf = (struct bfa_uf_buf_s *)
5543 bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len);
5544 buf = &uf_buf->d[0];
5545
Jing Huangba816ea2010-10-18 17:10:50 -07005546 m->frm_len = be16_to_cpu(m->frm_len);
5547 m->xfr_len = be16_to_cpu(m->xfr_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005548
5549 fchs = (struct fchs_s *)uf_buf;
5550
5551 list_del(&uf->qe); /* dequeue from posted queue */
5552
5553 uf->data_ptr = buf;
5554 uf->data_len = m->xfr_len;
5555
Jing Huangd4b671c2010-12-26 21:46:35 -08005556 WARN_ON(uf->data_len < sizeof(struct fchs_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005557
5558 if (uf->data_len == sizeof(struct fchs_s)) {
5559 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
5560 uf->data_len, (struct fchs_s *)buf);
5561 } else {
5562 u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
5563 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
5564 BFA_PL_EID_RX, uf->data_len,
5565 (struct fchs_s *)buf, pld_w0);
5566 }
5567
5568 if (bfa->fcs)
5569 __bfa_cb_uf_recv(uf, BFA_TRUE);
5570 else
5571 bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
5572}
5573
Christoph Hellwigc7c35242017-04-13 10:02:56 +02005574void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005575bfa_uf_iocdisable(struct bfa_s *bfa)
5576{
5577 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5578 struct bfa_uf_s *uf;
5579 struct list_head *qe, *qen;
5580
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005581 /* Enqueue unused uf resources to free_q */
5582 list_splice_tail_init(&ufm->uf_unused_q, &ufm->uf_free_q);
5583
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005584 list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
5585 uf = (struct bfa_uf_s *) qe;
5586 list_del(&uf->qe);
5587 bfa_uf_put(ufm, uf);
5588 }
5589}
5590
Christoph Hellwigc7c35242017-04-13 10:02:56 +02005591void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005592bfa_uf_start(struct bfa_s *bfa)
5593{
5594 bfa_uf_post_all(BFA_UF_MOD(bfa));
5595}
5596
Jing Huang5fbe25c2010-10-18 17:17:23 -07005597/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005598 * Register handler for all unsolicted receive frames.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005599 *
5600 * @param[in] bfa BFA instance
5601 * @param[in] ufrecv receive handler function
5602 * @param[in] cbarg receive handler arg
5603 */
5604void
5605bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
5606{
5607 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5608
5609 ufm->ufrecv = ufrecv;
5610 ufm->cbarg = cbarg;
5611}
5612
Jing Huang5fbe25c2010-10-18 17:17:23 -07005613/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005614 * Free an unsolicited frame back to BFA.
5615 *
5616 * @param[in] uf unsolicited frame to be freed
5617 *
5618 * @return None
5619 */
5620void
5621bfa_uf_free(struct bfa_uf_s *uf)
5622{
5623 bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
5624 bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
5625}
5626
5627
5628
Jing Huang5fbe25c2010-10-18 17:17:23 -07005629/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005630 * uf_pub BFA uf module public functions
5631 */
5632void
5633bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5634{
5635 bfa_trc(bfa, msg->mhdr.msg_id);
5636
5637 switch (msg->mhdr.msg_id) {
5638 case BFI_UF_I2H_FRM_RCVD:
5639 uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
5640 break;
5641
5642 default:
5643 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08005644 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005645 }
5646}
5647
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005648void
5649bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw)
5650{
5651 struct bfa_uf_mod_s *mod = BFA_UF_MOD(bfa);
5652 struct list_head *qe;
5653 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005654
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005655 for (i = 0; i < (mod->num_ufs - num_uf_fw); i++) {
5656 bfa_q_deq_tail(&mod->uf_free_q, &qe);
5657 list_add_tail(qe, &mod->uf_unused_q);
5658 }
5659}
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005660
5661/*
Krishna Gudipatie3535462012-09-21 17:26:07 -07005662 * Dport forward declaration
5663 */
5664
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07005665enum bfa_dport_test_state_e {
5666 BFA_DPORT_ST_DISABLED = 0, /*!< dport is disabled */
5667 BFA_DPORT_ST_INP = 1, /*!< test in progress */
5668 BFA_DPORT_ST_COMP = 2, /*!< test complete successfully */
5669 BFA_DPORT_ST_NO_SFP = 3, /*!< sfp is not present */
5670 BFA_DPORT_ST_NOTSTART = 4, /*!< test not start dport is enabled */
5671};
5672
Krishna Gudipatie3535462012-09-21 17:26:07 -07005673/*
5674 * BFA DPORT state machine events
5675 */
5676enum bfa_dport_sm_event {
5677 BFA_DPORT_SM_ENABLE = 1, /* dport enable event */
5678 BFA_DPORT_SM_DISABLE = 2, /* dport disable event */
5679 BFA_DPORT_SM_FWRSP = 3, /* fw enable/disable rsp */
5680 BFA_DPORT_SM_QRESUME = 4, /* CQ space available */
5681 BFA_DPORT_SM_HWFAIL = 5, /* IOC h/w failure */
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07005682 BFA_DPORT_SM_START = 6, /* re-start dport test */
5683 BFA_DPORT_SM_REQFAIL = 7, /* request failure */
5684 BFA_DPORT_SM_SCN = 8, /* state change notify frm fw */
Krishna Gudipatie3535462012-09-21 17:26:07 -07005685};
5686
5687static void bfa_dport_sm_disabled(struct bfa_dport_s *dport,
5688 enum bfa_dport_sm_event event);
5689static void bfa_dport_sm_enabling_qwait(struct bfa_dport_s *dport,
5690 enum bfa_dport_sm_event event);
5691static void bfa_dport_sm_enabling(struct bfa_dport_s *dport,
5692 enum bfa_dport_sm_event event);
5693static void bfa_dport_sm_enabled(struct bfa_dport_s *dport,
5694 enum bfa_dport_sm_event event);
5695static void bfa_dport_sm_disabling_qwait(struct bfa_dport_s *dport,
5696 enum bfa_dport_sm_event event);
5697static void bfa_dport_sm_disabling(struct bfa_dport_s *dport,
5698 enum bfa_dport_sm_event event);
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07005699static void bfa_dport_sm_starting_qwait(struct bfa_dport_s *dport,
5700 enum bfa_dport_sm_event event);
5701static void bfa_dport_sm_starting(struct bfa_dport_s *dport,
5702 enum bfa_dport_sm_event event);
5703static void bfa_dport_sm_dynamic_disabling(struct bfa_dport_s *dport,
5704 enum bfa_dport_sm_event event);
5705static void bfa_dport_sm_dynamic_disabling_qwait(struct bfa_dport_s *dport,
5706 enum bfa_dport_sm_event event);
Krishna Gudipatie3535462012-09-21 17:26:07 -07005707static void bfa_dport_qresume(void *cbarg);
5708static void bfa_dport_req_comp(struct bfa_dport_s *dport,
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07005709 struct bfi_diag_dport_rsp_s *msg);
5710static void bfa_dport_scn(struct bfa_dport_s *dport,
5711 struct bfi_diag_dport_scn_s *msg);
Krishna Gudipatie3535462012-09-21 17:26:07 -07005712
5713/*
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005714 * BFA fcdiag module
5715 */
5716#define BFA_DIAG_QTEST_TOV 1000 /* msec */
5717
5718/*
5719 * Set port status to busy
5720 */
5721static void
5722bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s *fcdiag)
5723{
5724 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fcdiag->bfa);
5725
5726 if (fcdiag->lb.lock)
5727 fcport->diag_busy = BFA_TRUE;
5728 else
5729 fcport->diag_busy = BFA_FALSE;
5730}
5731
Christoph Hellwigc7c35242017-04-13 10:02:56 +02005732void
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005733bfa_fcdiag_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
5734 struct bfa_pcidev_s *pcidev)
5735{
5736 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
Krishna Gudipatie3535462012-09-21 17:26:07 -07005737 struct bfa_dport_s *dport = &fcdiag->dport;
5738
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005739 fcdiag->bfa = bfa;
5740 fcdiag->trcmod = bfa->trcmod;
5741 /* The common DIAG attach bfa_diag_attach() will do all memory claim */
Krishna Gudipatie3535462012-09-21 17:26:07 -07005742 dport->bfa = bfa;
5743 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
5744 bfa_reqq_winit(&dport->reqq_wait, bfa_dport_qresume, dport);
5745 dport->cbfn = NULL;
5746 dport->cbarg = NULL;
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07005747 dport->test_state = BFA_DPORT_ST_DISABLED;
5748 memset(&dport->result, 0, sizeof(struct bfa_diag_dport_result_s));
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005749}
5750
Christoph Hellwigc7c35242017-04-13 10:02:56 +02005751void
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005752bfa_fcdiag_iocdisable(struct bfa_s *bfa)
5753{
5754 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
Krishna Gudipatie3535462012-09-21 17:26:07 -07005755 struct bfa_dport_s *dport = &fcdiag->dport;
5756
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005757 bfa_trc(fcdiag, fcdiag->lb.lock);
5758 if (fcdiag->lb.lock) {
5759 fcdiag->lb.status = BFA_STATUS_IOC_FAILURE;
5760 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5761 fcdiag->lb.lock = 0;
5762 bfa_fcdiag_set_busy_status(fcdiag);
5763 }
Krishna Gudipatie3535462012-09-21 17:26:07 -07005764
5765 bfa_sm_send_event(dport, BFA_DPORT_SM_HWFAIL);
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005766}
5767
5768static void
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005769bfa_fcdiag_queuetest_timeout(void *cbarg)
5770{
5771 struct bfa_fcdiag_s *fcdiag = cbarg;
5772 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5773
5774 bfa_trc(fcdiag, fcdiag->qtest.all);
5775 bfa_trc(fcdiag, fcdiag->qtest.count);
5776
5777 fcdiag->qtest.timer_active = 0;
5778
5779 res->status = BFA_STATUS_ETIMER;
5780 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5781 if (fcdiag->qtest.all)
5782 res->queue = fcdiag->qtest.all;
5783
5784 bfa_trc(fcdiag, BFA_STATUS_ETIMER);
5785 fcdiag->qtest.status = BFA_STATUS_ETIMER;
5786 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5787 fcdiag->qtest.lock = 0;
5788}
5789
5790static bfa_status_t
5791bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s *fcdiag)
5792{
5793 u32 i;
5794 struct bfi_diag_qtest_req_s *req;
5795
5796 req = bfa_reqq_next(fcdiag->bfa, fcdiag->qtest.queue);
5797 if (!req)
5798 return BFA_STATUS_DEVBUSY;
5799
5800 /* build host command */
5801 bfi_h2i_set(req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_QTEST,
5802 bfa_fn_lpu(fcdiag->bfa));
5803
5804 for (i = 0; i < BFI_LMSG_PL_WSZ; i++)
5805 req->data[i] = QTEST_PAT_DEFAULT;
5806
5807 bfa_trc(fcdiag, fcdiag->qtest.queue);
5808 /* ring door bell */
5809 bfa_reqq_produce(fcdiag->bfa, fcdiag->qtest.queue, req->mh);
5810 return BFA_STATUS_OK;
5811}
5812
5813static void
5814bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s *fcdiag,
5815 bfi_diag_qtest_rsp_t *rsp)
5816{
5817 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5818 bfa_status_t status = BFA_STATUS_OK;
5819 int i;
5820
5821 /* Check timer, should still be active */
5822 if (!fcdiag->qtest.timer_active) {
5823 bfa_trc(fcdiag, fcdiag->qtest.timer_active);
5824 return;
5825 }
5826
5827 /* update count */
5828 fcdiag->qtest.count--;
5829
5830 /* Check result */
5831 for (i = 0; i < BFI_LMSG_PL_WSZ; i++) {
5832 if (rsp->data[i] != ~(QTEST_PAT_DEFAULT)) {
5833 res->status = BFA_STATUS_DATACORRUPTED;
5834 break;
5835 }
5836 }
5837
5838 if (res->status == BFA_STATUS_OK) {
5839 if (fcdiag->qtest.count > 0) {
5840 status = bfa_fcdiag_queuetest_send(fcdiag);
5841 if (status == BFA_STATUS_OK)
5842 return;
5843 else
5844 res->status = status;
5845 } else if (fcdiag->qtest.all > 0 &&
5846 fcdiag->qtest.queue < (BFI_IOC_MAX_CQS - 1)) {
5847 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
5848 fcdiag->qtest.queue++;
5849 status = bfa_fcdiag_queuetest_send(fcdiag);
5850 if (status == BFA_STATUS_OK)
5851 return;
5852 else
5853 res->status = status;
5854 }
5855 }
5856
5857 /* Stop timer when we comp all queue */
5858 if (fcdiag->qtest.timer_active) {
5859 bfa_timer_stop(&fcdiag->qtest.timer);
5860 fcdiag->qtest.timer_active = 0;
5861 }
5862 res->queue = fcdiag->qtest.queue;
5863 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5864 bfa_trc(fcdiag, res->count);
5865 bfa_trc(fcdiag, res->status);
5866 fcdiag->qtest.status = res->status;
5867 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5868 fcdiag->qtest.lock = 0;
5869}
5870
5871static void
5872bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s *fcdiag,
5873 struct bfi_diag_lb_rsp_s *rsp)
5874{
5875 struct bfa_diag_loopback_result_s *res = fcdiag->lb.result;
5876
5877 res->numtxmfrm = be32_to_cpu(rsp->res.numtxmfrm);
5878 res->numosffrm = be32_to_cpu(rsp->res.numosffrm);
5879 res->numrcvfrm = be32_to_cpu(rsp->res.numrcvfrm);
5880 res->badfrminf = be32_to_cpu(rsp->res.badfrminf);
5881 res->badfrmnum = be32_to_cpu(rsp->res.badfrmnum);
5882 res->status = rsp->res.status;
5883 fcdiag->lb.status = rsp->res.status;
5884 bfa_trc(fcdiag, fcdiag->lb.status);
5885 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5886 fcdiag->lb.lock = 0;
5887 bfa_fcdiag_set_busy_status(fcdiag);
5888}
5889
5890static bfa_status_t
5891bfa_fcdiag_loopback_send(struct bfa_fcdiag_s *fcdiag,
5892 struct bfa_diag_loopback_s *loopback)
5893{
5894 struct bfi_diag_lb_req_s *lb_req;
5895
5896 lb_req = bfa_reqq_next(fcdiag->bfa, BFA_REQQ_DIAG);
5897 if (!lb_req)
5898 return BFA_STATUS_DEVBUSY;
5899
5900 /* build host command */
5901 bfi_h2i_set(lb_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LOOPBACK,
5902 bfa_fn_lpu(fcdiag->bfa));
5903
5904 lb_req->lb_mode = loopback->lb_mode;
5905 lb_req->speed = loopback->speed;
5906 lb_req->loopcnt = loopback->loopcnt;
5907 lb_req->pattern = loopback->pattern;
5908
5909 /* ring door bell */
5910 bfa_reqq_produce(fcdiag->bfa, BFA_REQQ_DIAG, lb_req->mh);
5911
5912 bfa_trc(fcdiag, loopback->lb_mode);
5913 bfa_trc(fcdiag, loopback->speed);
5914 bfa_trc(fcdiag, loopback->loopcnt);
5915 bfa_trc(fcdiag, loopback->pattern);
5916 return BFA_STATUS_OK;
5917}
5918
5919/*
5920 * cpe/rme intr handler
5921 */
5922void
5923bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5924{
5925 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5926
5927 switch (msg->mhdr.msg_id) {
5928 case BFI_DIAG_I2H_LOOPBACK:
5929 bfa_fcdiag_loopback_comp(fcdiag,
5930 (struct bfi_diag_lb_rsp_s *) msg);
5931 break;
5932 case BFI_DIAG_I2H_QTEST:
5933 bfa_fcdiag_queuetest_comp(fcdiag, (bfi_diag_qtest_rsp_t *)msg);
5934 break;
Krishna Gudipatie3535462012-09-21 17:26:07 -07005935 case BFI_DIAG_I2H_DPORT:
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07005936 bfa_dport_req_comp(&fcdiag->dport,
5937 (struct bfi_diag_dport_rsp_s *)msg);
5938 break;
5939 case BFI_DIAG_I2H_DPORT_SCN:
5940 bfa_dport_scn(&fcdiag->dport,
5941 (struct bfi_diag_dport_scn_s *)msg);
Krishna Gudipatie3535462012-09-21 17:26:07 -07005942 break;
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005943 default:
5944 bfa_trc(fcdiag, msg->mhdr.msg_id);
5945 WARN_ON(1);
5946 }
5947}
5948
5949/*
5950 * Loopback test
5951 *
5952 * @param[in] *bfa - bfa data struct
5953 * @param[in] opmode - port operation mode
5954 * @param[in] speed - port speed
5955 * @param[in] lpcnt - loop count
5956 * @param[in] pat - pattern to build packet
5957 * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
5958 * @param[in] cbfn - callback function
5959 * @param[in] cbarg - callback functioin arg
5960 *
5961 * @param[out]
5962 */
5963bfa_status_t
5964bfa_fcdiag_loopback(struct bfa_s *bfa, enum bfa_port_opmode opmode,
5965 enum bfa_port_speed speed, u32 lpcnt, u32 pat,
5966 struct bfa_diag_loopback_result_s *result, bfa_cb_diag_t cbfn,
5967 void *cbarg)
5968{
5969 struct bfa_diag_loopback_s loopback;
5970 struct bfa_port_attr_s attr;
5971 bfa_status_t status;
5972 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5973
5974 if (!bfa_iocfc_is_operational(bfa))
5975 return BFA_STATUS_IOC_NON_OP;
5976
5977 /* if port is PBC disabled, return error */
5978 if (bfa_fcport_is_pbcdisabled(bfa)) {
5979 bfa_trc(fcdiag, BFA_STATUS_PBC);
5980 return BFA_STATUS_PBC;
5981 }
5982
5983 if (bfa_fcport_is_disabled(bfa) == BFA_FALSE) {
5984 bfa_trc(fcdiag, opmode);
5985 return BFA_STATUS_PORT_NOT_DISABLED;
5986 }
5987
Krishna Gudipatifb778b02011-07-20 17:01:07 -07005988 /*
5989 * Check if input speed is supported by the port mode
5990 */
5991 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
5992 if (!(speed == BFA_PORT_SPEED_1GBPS ||
5993 speed == BFA_PORT_SPEED_2GBPS ||
5994 speed == BFA_PORT_SPEED_4GBPS ||
5995 speed == BFA_PORT_SPEED_8GBPS ||
5996 speed == BFA_PORT_SPEED_16GBPS ||
5997 speed == BFA_PORT_SPEED_AUTO)) {
5998 bfa_trc(fcdiag, speed);
5999 return BFA_STATUS_UNSUPP_SPEED;
6000 }
6001 bfa_fcport_get_attr(bfa, &attr);
6002 bfa_trc(fcdiag, attr.speed_supported);
6003 if (speed > attr.speed_supported)
6004 return BFA_STATUS_UNSUPP_SPEED;
6005 } else {
6006 if (speed != BFA_PORT_SPEED_10GBPS) {
6007 bfa_trc(fcdiag, speed);
6008 return BFA_STATUS_UNSUPP_SPEED;
6009 }
6010 }
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07006011
Krishna Gudipatie3535462012-09-21 17:26:07 -07006012 /*
6013 * For CT2, 1G is not supported
6014 */
6015 if ((speed == BFA_PORT_SPEED_1GBPS) &&
6016 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id))) {
6017 bfa_trc(fcdiag, speed);
6018 return BFA_STATUS_UNSUPP_SPEED;
6019 }
6020
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07006021 /* For Mezz card, port speed entered needs to be checked */
6022 if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) {
6023 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07006024 if (!(speed == BFA_PORT_SPEED_1GBPS ||
6025 speed == BFA_PORT_SPEED_2GBPS ||
6026 speed == BFA_PORT_SPEED_4GBPS ||
6027 speed == BFA_PORT_SPEED_8GBPS ||
6028 speed == BFA_PORT_SPEED_16GBPS ||
6029 speed == BFA_PORT_SPEED_AUTO))
6030 return BFA_STATUS_UNSUPP_SPEED;
6031 } else {
6032 if (speed != BFA_PORT_SPEED_10GBPS)
6033 return BFA_STATUS_UNSUPP_SPEED;
6034 }
6035 }
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006036 /* check to see if fcport is dport */
6037 if (bfa_fcport_is_dport(bfa)) {
6038 bfa_trc(fcdiag, fcdiag->lb.lock);
6039 return BFA_STATUS_DPORT_ENABLED;
6040 }
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07006041 /* check to see if there is another destructive diag cmd running */
6042 if (fcdiag->lb.lock) {
6043 bfa_trc(fcdiag, fcdiag->lb.lock);
6044 return BFA_STATUS_DEVBUSY;
6045 }
6046
6047 fcdiag->lb.lock = 1;
6048 loopback.lb_mode = opmode;
6049 loopback.speed = speed;
6050 loopback.loopcnt = lpcnt;
6051 loopback.pattern = pat;
6052 fcdiag->lb.result = result;
6053 fcdiag->lb.cbfn = cbfn;
6054 fcdiag->lb.cbarg = cbarg;
6055 memset(result, 0, sizeof(struct bfa_diag_loopback_result_s));
6056 bfa_fcdiag_set_busy_status(fcdiag);
6057
6058 /* Send msg to fw */
6059 status = bfa_fcdiag_loopback_send(fcdiag, &loopback);
6060 return status;
6061}
6062
6063/*
6064 * DIAG queue test command
6065 *
6066 * @param[in] *bfa - bfa data struct
6067 * @param[in] force - 1: don't do ioc op checking
6068 * @param[in] queue - queue no. to test
6069 * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
6070 * @param[in] cbfn - callback function
6071 * @param[in] *cbarg - callback functioin arg
6072 *
6073 * @param[out]
6074 */
6075bfa_status_t
6076bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 force, u32 queue,
6077 struct bfa_diag_qtest_result_s *result, bfa_cb_diag_t cbfn,
6078 void *cbarg)
6079{
6080 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
6081 bfa_status_t status;
6082 bfa_trc(fcdiag, force);
6083 bfa_trc(fcdiag, queue);
6084
6085 if (!force && !bfa_iocfc_is_operational(bfa))
6086 return BFA_STATUS_IOC_NON_OP;
6087
6088 /* check to see if there is another destructive diag cmd running */
6089 if (fcdiag->qtest.lock) {
6090 bfa_trc(fcdiag, fcdiag->qtest.lock);
6091 return BFA_STATUS_DEVBUSY;
6092 }
6093
6094 /* Initialization */
6095 fcdiag->qtest.lock = 1;
6096 fcdiag->qtest.cbfn = cbfn;
6097 fcdiag->qtest.cbarg = cbarg;
6098 fcdiag->qtest.result = result;
6099 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
6100
6101 /* Init test results */
6102 fcdiag->qtest.result->status = BFA_STATUS_OK;
6103 fcdiag->qtest.result->count = 0;
6104
6105 /* send */
6106 if (queue < BFI_IOC_MAX_CQS) {
6107 fcdiag->qtest.result->queue = (u8)queue;
6108 fcdiag->qtest.queue = (u8)queue;
6109 fcdiag->qtest.all = 0;
6110 } else {
6111 fcdiag->qtest.result->queue = 0;
6112 fcdiag->qtest.queue = 0;
6113 fcdiag->qtest.all = 1;
6114 }
6115 status = bfa_fcdiag_queuetest_send(fcdiag);
6116
6117 /* Start a timer */
6118 if (status == BFA_STATUS_OK) {
6119 bfa_timer_start(bfa, &fcdiag->qtest.timer,
6120 bfa_fcdiag_queuetest_timeout, fcdiag,
6121 BFA_DIAG_QTEST_TOV);
6122 fcdiag->qtest.timer_active = 1;
6123 }
6124 return status;
6125}
6126
6127/*
6128 * DIAG PLB is running
6129 *
6130 * @param[in] *bfa - bfa data struct
6131 *
6132 * @param[out]
6133 */
6134bfa_status_t
6135bfa_fcdiag_lb_is_running(struct bfa_s *bfa)
6136{
6137 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
6138 return fcdiag->lb.lock ? BFA_STATUS_DIAG_BUSY : BFA_STATUS_OK;
6139}
Krishna Gudipatie3535462012-09-21 17:26:07 -07006140
6141/*
6142 * D-port
6143 */
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006144#define bfa_dport_result_start(__dport, __mode) do { \
6145 (__dport)->result.start_time = bfa_get_log_time(); \
6146 (__dport)->result.status = DPORT_TEST_ST_INPRG; \
6147 (__dport)->result.mode = (__mode); \
6148 (__dport)->result.rp_pwwn = (__dport)->rp_pwwn; \
6149 (__dport)->result.rp_nwwn = (__dport)->rp_nwwn; \
6150 (__dport)->result.lpcnt = (__dport)->lpcnt; \
6151} while (0)
6152
Krishna Gudipatie3535462012-09-21 17:26:07 -07006153static bfa_boolean_t bfa_dport_send_req(struct bfa_dport_s *dport,
6154 enum bfi_dport_req req);
6155static void
6156bfa_cb_fcdiag_dport(struct bfa_dport_s *dport, bfa_status_t bfa_status)
6157{
6158 if (dport->cbfn != NULL) {
6159 dport->cbfn(dport->cbarg, bfa_status);
6160 dport->cbfn = NULL;
6161 dport->cbarg = NULL;
6162 }
6163}
6164
6165static void
6166bfa_dport_sm_disabled(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
6167{
6168 bfa_trc(dport->bfa, event);
6169
6170 switch (event) {
6171 case BFA_DPORT_SM_ENABLE:
6172 bfa_fcport_dportenable(dport->bfa);
6173 if (bfa_dport_send_req(dport, BFI_DPORT_ENABLE))
6174 bfa_sm_set_state(dport, bfa_dport_sm_enabling);
6175 else
6176 bfa_sm_set_state(dport, bfa_dport_sm_enabling_qwait);
6177 break;
6178
6179 case BFA_DPORT_SM_DISABLE:
6180 /* Already disabled */
6181 break;
6182
6183 case BFA_DPORT_SM_HWFAIL:
6184 /* ignore */
6185 break;
6186
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006187 case BFA_DPORT_SM_SCN:
6188 if (dport->i2hmsg.scn.state == BFI_DPORT_SCN_DDPORT_ENABLE) {
6189 bfa_fcport_ddportenable(dport->bfa);
6190 dport->dynamic = BFA_TRUE;
6191 dport->test_state = BFA_DPORT_ST_NOTSTART;
6192 bfa_sm_set_state(dport, bfa_dport_sm_enabled);
6193 } else {
6194 bfa_trc(dport->bfa, dport->i2hmsg.scn.state);
6195 WARN_ON(1);
6196 }
6197 break;
6198
Krishna Gudipatie3535462012-09-21 17:26:07 -07006199 default:
6200 bfa_sm_fault(dport->bfa, event);
6201 }
6202}
6203
6204static void
6205bfa_dport_sm_enabling_qwait(struct bfa_dport_s *dport,
6206 enum bfa_dport_sm_event event)
6207{
6208 bfa_trc(dport->bfa, event);
6209
6210 switch (event) {
6211 case BFA_DPORT_SM_QRESUME:
6212 bfa_sm_set_state(dport, bfa_dport_sm_enabling);
6213 bfa_dport_send_req(dport, BFI_DPORT_ENABLE);
6214 break;
6215
6216 case BFA_DPORT_SM_HWFAIL:
6217 bfa_reqq_wcancel(&dport->reqq_wait);
6218 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6219 bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
6220 break;
6221
6222 default:
6223 bfa_sm_fault(dport->bfa, event);
6224 }
6225}
6226
6227static void
6228bfa_dport_sm_enabling(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
6229{
6230 bfa_trc(dport->bfa, event);
6231
6232 switch (event) {
6233 case BFA_DPORT_SM_FWRSP:
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006234 memset(&dport->result, 0,
6235 sizeof(struct bfa_diag_dport_result_s));
6236 if (dport->i2hmsg.rsp.status == BFA_STATUS_DPORT_INV_SFP) {
6237 dport->test_state = BFA_DPORT_ST_NO_SFP;
6238 } else {
6239 dport->test_state = BFA_DPORT_ST_INP;
6240 bfa_dport_result_start(dport, BFA_DPORT_OPMODE_AUTO);
6241 }
Krishna Gudipatie3535462012-09-21 17:26:07 -07006242 bfa_sm_set_state(dport, bfa_dport_sm_enabled);
6243 break;
6244
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006245 case BFA_DPORT_SM_REQFAIL:
6246 dport->test_state = BFA_DPORT_ST_DISABLED;
6247 bfa_fcport_dportdisable(dport->bfa);
6248 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6249 break;
6250
Krishna Gudipatie3535462012-09-21 17:26:07 -07006251 case BFA_DPORT_SM_HWFAIL:
6252 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6253 bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
6254 break;
6255
6256 default:
6257 bfa_sm_fault(dport->bfa, event);
6258 }
6259}
6260
6261static void
6262bfa_dport_sm_enabled(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
6263{
6264 bfa_trc(dport->bfa, event);
6265
6266 switch (event) {
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006267 case BFA_DPORT_SM_START:
6268 if (bfa_dport_send_req(dport, BFI_DPORT_START))
6269 bfa_sm_set_state(dport, bfa_dport_sm_starting);
6270 else
6271 bfa_sm_set_state(dport, bfa_dport_sm_starting_qwait);
Krishna Gudipatie3535462012-09-21 17:26:07 -07006272 break;
6273
6274 case BFA_DPORT_SM_DISABLE:
6275 bfa_fcport_dportdisable(dport->bfa);
6276 if (bfa_dport_send_req(dport, BFI_DPORT_DISABLE))
6277 bfa_sm_set_state(dport, bfa_dport_sm_disabling);
6278 else
6279 bfa_sm_set_state(dport, bfa_dport_sm_disabling_qwait);
6280 break;
6281
6282 case BFA_DPORT_SM_HWFAIL:
6283 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6284 break;
6285
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006286 case BFA_DPORT_SM_SCN:
6287 switch (dport->i2hmsg.scn.state) {
6288 case BFI_DPORT_SCN_TESTCOMP:
6289 dport->test_state = BFA_DPORT_ST_COMP;
6290 break;
6291
6292 case BFI_DPORT_SCN_TESTSTART:
6293 dport->test_state = BFA_DPORT_ST_INP;
6294 break;
6295
6296 case BFI_DPORT_SCN_TESTSKIP:
6297 case BFI_DPORT_SCN_SUBTESTSTART:
6298 /* no state change */
6299 break;
6300
6301 case BFI_DPORT_SCN_SFP_REMOVED:
6302 dport->test_state = BFA_DPORT_ST_NO_SFP;
6303 break;
6304
6305 case BFI_DPORT_SCN_DDPORT_DISABLE:
6306 bfa_fcport_ddportdisable(dport->bfa);
6307
6308 if (bfa_dport_send_req(dport, BFI_DPORT_DYN_DISABLE))
6309 bfa_sm_set_state(dport,
6310 bfa_dport_sm_dynamic_disabling);
6311 else
6312 bfa_sm_set_state(dport,
6313 bfa_dport_sm_dynamic_disabling_qwait);
6314 break;
6315
6316 case BFI_DPORT_SCN_FCPORT_DISABLE:
6317 bfa_fcport_ddportdisable(dport->bfa);
6318
6319 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6320 dport->dynamic = BFA_FALSE;
6321 break;
6322
6323 default:
6324 bfa_trc(dport->bfa, dport->i2hmsg.scn.state);
6325 bfa_sm_fault(dport->bfa, event);
6326 }
6327 break;
Krishna Gudipatie3535462012-09-21 17:26:07 -07006328 default:
6329 bfa_sm_fault(dport->bfa, event);
6330 }
6331}
6332
6333static void
6334bfa_dport_sm_disabling_qwait(struct bfa_dport_s *dport,
6335 enum bfa_dport_sm_event event)
6336{
6337 bfa_trc(dport->bfa, event);
6338
6339 switch (event) {
6340 case BFA_DPORT_SM_QRESUME:
6341 bfa_sm_set_state(dport, bfa_dport_sm_disabling);
6342 bfa_dport_send_req(dport, BFI_DPORT_DISABLE);
6343 break;
6344
6345 case BFA_DPORT_SM_HWFAIL:
6346 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6347 bfa_reqq_wcancel(&dport->reqq_wait);
6348 bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
6349 break;
6350
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006351 case BFA_DPORT_SM_SCN:
6352 /* ignore */
6353 break;
6354
Krishna Gudipatie3535462012-09-21 17:26:07 -07006355 default:
6356 bfa_sm_fault(dport->bfa, event);
6357 }
6358}
6359
6360static void
6361bfa_dport_sm_disabling(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
6362{
6363 bfa_trc(dport->bfa, event);
6364
6365 switch (event) {
6366 case BFA_DPORT_SM_FWRSP:
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006367 dport->test_state = BFA_DPORT_ST_DISABLED;
Krishna Gudipatie3535462012-09-21 17:26:07 -07006368 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6369 break;
6370
6371 case BFA_DPORT_SM_HWFAIL:
6372 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6373 bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
6374 break;
6375
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006376 case BFA_DPORT_SM_SCN:
6377 /* no state change */
6378 break;
6379
6380 default:
6381 bfa_sm_fault(dport->bfa, event);
6382 }
6383}
6384
6385static void
6386bfa_dport_sm_starting_qwait(struct bfa_dport_s *dport,
6387 enum bfa_dport_sm_event event)
6388{
6389 bfa_trc(dport->bfa, event);
6390
6391 switch (event) {
6392 case BFA_DPORT_SM_QRESUME:
6393 bfa_sm_set_state(dport, bfa_dport_sm_starting);
6394 bfa_dport_send_req(dport, BFI_DPORT_START);
6395 break;
6396
6397 case BFA_DPORT_SM_HWFAIL:
6398 bfa_reqq_wcancel(&dport->reqq_wait);
6399 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6400 bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
6401 break;
6402
6403 default:
6404 bfa_sm_fault(dport->bfa, event);
6405 }
6406}
6407
6408static void
6409bfa_dport_sm_starting(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
6410{
6411 bfa_trc(dport->bfa, event);
6412
6413 switch (event) {
6414 case BFA_DPORT_SM_FWRSP:
6415 memset(&dport->result, 0,
6416 sizeof(struct bfa_diag_dport_result_s));
6417 if (dport->i2hmsg.rsp.status == BFA_STATUS_DPORT_INV_SFP) {
6418 dport->test_state = BFA_DPORT_ST_NO_SFP;
6419 } else {
6420 dport->test_state = BFA_DPORT_ST_INP;
6421 bfa_dport_result_start(dport, BFA_DPORT_OPMODE_MANU);
6422 }
6423 /* fall thru */
6424
6425 case BFA_DPORT_SM_REQFAIL:
6426 bfa_sm_set_state(dport, bfa_dport_sm_enabled);
6427 break;
6428
6429 case BFA_DPORT_SM_HWFAIL:
6430 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6431 bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
6432 break;
6433
6434 default:
6435 bfa_sm_fault(dport->bfa, event);
6436 }
6437}
6438
6439static void
6440bfa_dport_sm_dynamic_disabling(struct bfa_dport_s *dport,
6441 enum bfa_dport_sm_event event)
6442{
6443 bfa_trc(dport->bfa, event);
6444
6445 switch (event) {
6446 case BFA_DPORT_SM_SCN:
6447 switch (dport->i2hmsg.scn.state) {
6448 case BFI_DPORT_SCN_DDPORT_DISABLED:
6449 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6450 dport->dynamic = BFA_FALSE;
6451 bfa_fcport_enable(dport->bfa);
6452 break;
6453
6454 default:
6455 bfa_trc(dport->bfa, dport->i2hmsg.scn.state);
6456 bfa_sm_fault(dport->bfa, event);
6457
6458 }
6459 break;
6460
6461 case BFA_DPORT_SM_HWFAIL:
6462 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6463 bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
6464 break;
6465
Krishna Gudipatie3535462012-09-21 17:26:07 -07006466 default:
6467 bfa_sm_fault(dport->bfa, event);
6468 }
6469}
6470
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006471static void
6472bfa_dport_sm_dynamic_disabling_qwait(struct bfa_dport_s *dport,
6473 enum bfa_dport_sm_event event)
6474{
6475 bfa_trc(dport->bfa, event);
6476
6477 switch (event) {
6478 case BFA_DPORT_SM_QRESUME:
6479 bfa_sm_set_state(dport, bfa_dport_sm_dynamic_disabling);
6480 bfa_dport_send_req(dport, BFI_DPORT_DYN_DISABLE);
6481 break;
6482
6483 case BFA_DPORT_SM_HWFAIL:
6484 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6485 bfa_reqq_wcancel(&dport->reqq_wait);
6486 bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
6487 break;
6488
6489 case BFA_DPORT_SM_SCN:
6490 /* ignore */
6491 break;
6492
6493 default:
6494 bfa_sm_fault(dport->bfa, event);
6495 }
6496}
Krishna Gudipatie3535462012-09-21 17:26:07 -07006497
6498static bfa_boolean_t
6499bfa_dport_send_req(struct bfa_dport_s *dport, enum bfi_dport_req req)
6500{
6501 struct bfi_diag_dport_req_s *m;
6502
6503 /*
Krishna Gudipatie3535462012-09-21 17:26:07 -07006504 * check for room in queue to send request now
6505 */
6506 m = bfa_reqq_next(dport->bfa, BFA_REQQ_DIAG);
6507 if (!m) {
6508 bfa_reqq_wait(dport->bfa, BFA_REQQ_PORT, &dport->reqq_wait);
6509 return BFA_FALSE;
6510 }
6511
6512 bfi_h2i_set(m->mh, BFI_MC_DIAG, BFI_DIAG_H2I_DPORT,
6513 bfa_fn_lpu(dport->bfa));
6514 m->req = req;
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006515 if ((req == BFI_DPORT_ENABLE) || (req == BFI_DPORT_START)) {
6516 m->lpcnt = cpu_to_be32(dport->lpcnt);
6517 m->payload = cpu_to_be32(dport->payload);
6518 }
Krishna Gudipatie3535462012-09-21 17:26:07 -07006519
6520 /*
6521 * queue I/O message to firmware
6522 */
6523 bfa_reqq_produce(dport->bfa, BFA_REQQ_DIAG, m->mh);
6524
6525 return BFA_TRUE;
6526}
6527
6528static void
6529bfa_dport_qresume(void *cbarg)
6530{
6531 struct bfa_dport_s *dport = cbarg;
6532
6533 bfa_sm_send_event(dport, BFA_DPORT_SM_QRESUME);
6534}
6535
6536static void
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006537bfa_dport_req_comp(struct bfa_dport_s *dport, struct bfi_diag_dport_rsp_s *msg)
Krishna Gudipatie3535462012-09-21 17:26:07 -07006538{
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006539 msg->status = cpu_to_be32(msg->status);
6540 dport->i2hmsg.rsp.status = msg->status;
6541 dport->rp_pwwn = msg->pwwn;
6542 dport->rp_nwwn = msg->nwwn;
6543
6544 if ((msg->status == BFA_STATUS_OK) ||
6545 (msg->status == BFA_STATUS_DPORT_NO_SFP)) {
6546 bfa_trc(dport->bfa, msg->status);
6547 bfa_trc(dport->bfa, dport->rp_pwwn);
6548 bfa_trc(dport->bfa, dport->rp_nwwn);
6549 bfa_sm_send_event(dport, BFA_DPORT_SM_FWRSP);
6550
6551 } else {
6552 bfa_trc(dport->bfa, msg->status);
6553 bfa_sm_send_event(dport, BFA_DPORT_SM_REQFAIL);
6554 }
Krishna Gudipatie3535462012-09-21 17:26:07 -07006555 bfa_cb_fcdiag_dport(dport, msg->status);
6556}
6557
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006558static bfa_boolean_t
6559bfa_dport_is_sending_req(struct bfa_dport_s *dport)
6560{
6561 if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) ||
6562 bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait) ||
6563 bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) ||
6564 bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait) ||
6565 bfa_sm_cmp_state(dport, bfa_dport_sm_starting) ||
6566 bfa_sm_cmp_state(dport, bfa_dport_sm_starting_qwait)) {
6567 return BFA_TRUE;
6568 } else {
6569 return BFA_FALSE;
6570 }
6571}
6572
6573static void
6574bfa_dport_scn(struct bfa_dport_s *dport, struct bfi_diag_dport_scn_s *msg)
6575{
6576 int i;
6577 uint8_t subtesttype;
6578
6579 bfa_trc(dport->bfa, msg->state);
6580 dport->i2hmsg.scn.state = msg->state;
6581
6582 switch (dport->i2hmsg.scn.state) {
6583 case BFI_DPORT_SCN_TESTCOMP:
6584 dport->result.end_time = bfa_get_log_time();
6585 bfa_trc(dport->bfa, dport->result.end_time);
6586
6587 dport->result.status = msg->info.testcomp.status;
6588 bfa_trc(dport->bfa, dport->result.status);
6589
6590 dport->result.roundtrip_latency =
6591 cpu_to_be32(msg->info.testcomp.latency);
6592 dport->result.est_cable_distance =
6593 cpu_to_be32(msg->info.testcomp.distance);
6594 dport->result.buffer_required =
6595 be16_to_cpu(msg->info.testcomp.numbuffer);
6596
6597 dport->result.frmsz = be16_to_cpu(msg->info.testcomp.frm_sz);
6598 dport->result.speed = msg->info.testcomp.speed;
6599
6600 bfa_trc(dport->bfa, dport->result.roundtrip_latency);
6601 bfa_trc(dport->bfa, dport->result.est_cable_distance);
6602 bfa_trc(dport->bfa, dport->result.buffer_required);
6603 bfa_trc(dport->bfa, dport->result.frmsz);
6604 bfa_trc(dport->bfa, dport->result.speed);
6605
6606 for (i = DPORT_TEST_ELOOP; i < DPORT_TEST_MAX; i++) {
6607 dport->result.subtest[i].status =
6608 msg->info.testcomp.subtest_status[i];
6609 bfa_trc(dport->bfa, dport->result.subtest[i].status);
6610 }
6611 break;
6612
6613 case BFI_DPORT_SCN_TESTSKIP:
6614 case BFI_DPORT_SCN_DDPORT_ENABLE:
6615 memset(&dport->result, 0,
6616 sizeof(struct bfa_diag_dport_result_s));
6617 break;
6618
6619 case BFI_DPORT_SCN_TESTSTART:
6620 memset(&dport->result, 0,
6621 sizeof(struct bfa_diag_dport_result_s));
6622 dport->rp_pwwn = msg->info.teststart.pwwn;
6623 dport->rp_nwwn = msg->info.teststart.nwwn;
6624 dport->lpcnt = cpu_to_be32(msg->info.teststart.numfrm);
Vijaya Mohan Guvva2ec331a2013-11-21 01:37:47 -08006625 bfa_dport_result_start(dport, msg->info.teststart.mode);
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006626 break;
6627
6628 case BFI_DPORT_SCN_SUBTESTSTART:
6629 subtesttype = msg->info.teststart.type;
6630 dport->result.subtest[subtesttype].start_time =
6631 bfa_get_log_time();
6632 dport->result.subtest[subtesttype].status =
6633 DPORT_TEST_ST_INPRG;
6634
6635 bfa_trc(dport->bfa, subtesttype);
6636 bfa_trc(dport->bfa,
6637 dport->result.subtest[subtesttype].start_time);
6638 break;
6639
6640 case BFI_DPORT_SCN_SFP_REMOVED:
6641 case BFI_DPORT_SCN_DDPORT_DISABLED:
6642 case BFI_DPORT_SCN_DDPORT_DISABLE:
6643 case BFI_DPORT_SCN_FCPORT_DISABLE:
6644 dport->result.status = DPORT_TEST_ST_IDLE;
6645 break;
6646
6647 default:
6648 bfa_sm_fault(dport->bfa, msg->state);
6649 }
6650
6651 bfa_sm_send_event(dport, BFA_DPORT_SM_SCN);
6652}
6653
Krishna Gudipatie3535462012-09-21 17:26:07 -07006654/*
6655 * Dport enable
6656 *
6657 * @param[in] *bfa - bfa data struct
6658 */
6659bfa_status_t
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006660bfa_dport_enable(struct bfa_s *bfa, u32 lpcnt, u32 pat,
6661 bfa_cb_diag_t cbfn, void *cbarg)
Krishna Gudipatie3535462012-09-21 17:26:07 -07006662{
6663 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
6664 struct bfa_dport_s *dport = &fcdiag->dport;
6665
6666 /*
6667 * Dport is not support in MEZZ card
6668 */
6669 if (bfa_mfg_is_mezz(dport->bfa->ioc.attr->card_type)) {
6670 bfa_trc(dport->bfa, BFA_STATUS_PBC);
6671 return BFA_STATUS_CMD_NOTSUPP_MEZZ;
6672 }
6673
6674 /*
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006675 * Dport is supported in CT2 or above
6676 */
6677 if (!(bfa_asic_id_ct2(dport->bfa->ioc.pcidev.device_id))) {
6678 bfa_trc(dport->bfa, dport->bfa->ioc.pcidev.device_id);
6679 return BFA_STATUS_FEATURE_NOT_SUPPORTED;
6680 }
6681
6682 /*
Krishna Gudipatie3535462012-09-21 17:26:07 -07006683 * Check to see if IOC is down
6684 */
6685 if (!bfa_iocfc_is_operational(bfa))
6686 return BFA_STATUS_IOC_NON_OP;
6687
6688 /* if port is PBC disabled, return error */
6689 if (bfa_fcport_is_pbcdisabled(bfa)) {
6690 bfa_trc(dport->bfa, BFA_STATUS_PBC);
6691 return BFA_STATUS_PBC;
6692 }
6693
6694 /*
6695 * Check if port mode is FC port
6696 */
6697 if (bfa_ioc_get_type(&bfa->ioc) != BFA_IOC_TYPE_FC) {
6698 bfa_trc(dport->bfa, bfa_ioc_get_type(&bfa->ioc));
6699 return BFA_STATUS_CMD_NOTSUPP_CNA;
6700 }
6701
6702 /*
6703 * Check if port is in LOOP mode
6704 */
6705 if ((bfa_fcport_get_cfg_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) ||
6706 (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)) {
6707 bfa_trc(dport->bfa, 0);
6708 return BFA_STATUS_TOPOLOGY_LOOP;
6709 }
6710
6711 /*
6712 * Check if port is TRUNK mode
6713 */
6714 if (bfa_fcport_is_trunk_enabled(bfa)) {
6715 bfa_trc(dport->bfa, 0);
6716 return BFA_STATUS_ERROR_TRUNK_ENABLED;
6717 }
6718
6719 /*
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006720 * Check if diag loopback is running
6721 */
6722 if (bfa_fcdiag_lb_is_running(bfa)) {
6723 bfa_trc(dport->bfa, 0);
6724 return BFA_STATUS_DIAG_BUSY;
6725 }
6726
6727 /*
Krishna Gudipatie3535462012-09-21 17:26:07 -07006728 * Check to see if port is disable or in dport state
6729 */
6730 if ((bfa_fcport_is_disabled(bfa) == BFA_FALSE) &&
6731 (bfa_fcport_is_dport(bfa) == BFA_FALSE)) {
6732 bfa_trc(dport->bfa, 0);
6733 return BFA_STATUS_PORT_NOT_DISABLED;
6734 }
6735
6736 /*
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006737 * Check if dport is in dynamic mode
6738 */
6739 if (dport->dynamic)
6740 return BFA_STATUS_DDPORT_ERR;
6741
6742 /*
Krishna Gudipatie3535462012-09-21 17:26:07 -07006743 * Check if dport is busy
6744 */
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006745 if (bfa_dport_is_sending_req(dport))
Krishna Gudipatie3535462012-09-21 17:26:07 -07006746 return BFA_STATUS_DEVBUSY;
Krishna Gudipatie3535462012-09-21 17:26:07 -07006747
6748 /*
6749 * Check if dport is already enabled
6750 */
6751 if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabled)) {
6752 bfa_trc(dport->bfa, 0);
6753 return BFA_STATUS_DPORT_ENABLED;
6754 }
6755
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006756 bfa_trc(dport->bfa, lpcnt);
6757 bfa_trc(dport->bfa, pat);
6758 dport->lpcnt = (lpcnt) ? lpcnt : DPORT_ENABLE_LOOPCNT_DEFAULT;
6759 dport->payload = (pat) ? pat : LB_PATTERN_DEFAULT;
Krishna Gudipatie3535462012-09-21 17:26:07 -07006760 dport->cbfn = cbfn;
6761 dport->cbarg = cbarg;
6762
6763 bfa_sm_send_event(dport, BFA_DPORT_SM_ENABLE);
6764 return BFA_STATUS_OK;
6765}
6766
6767/*
6768 * Dport disable
6769 *
6770 * @param[in] *bfa - bfa data struct
6771 */
6772bfa_status_t
6773bfa_dport_disable(struct bfa_s *bfa, bfa_cb_diag_t cbfn, void *cbarg)
6774{
6775 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
6776 struct bfa_dport_s *dport = &fcdiag->dport;
6777
6778 if (bfa_ioc_is_disabled(&bfa->ioc))
6779 return BFA_STATUS_IOC_DISABLED;
6780
6781 /* if port is PBC disabled, return error */
6782 if (bfa_fcport_is_pbcdisabled(bfa)) {
6783 bfa_trc(dport->bfa, BFA_STATUS_PBC);
6784 return BFA_STATUS_PBC;
6785 }
6786
6787 /*
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006788 * Check if dport is in dynamic mode
6789 */
6790 if (dport->dynamic) {
6791 return BFA_STATUS_DDPORT_ERR;
6792 }
6793
6794 /*
Krishna Gudipatie3535462012-09-21 17:26:07 -07006795 * Check to see if port is disable or in dport state
6796 */
6797 if ((bfa_fcport_is_disabled(bfa) == BFA_FALSE) &&
6798 (bfa_fcport_is_dport(bfa) == BFA_FALSE)) {
6799 bfa_trc(dport->bfa, 0);
6800 return BFA_STATUS_PORT_NOT_DISABLED;
6801 }
6802
6803 /*
6804 * Check if dport is busy
6805 */
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006806 if (bfa_dport_is_sending_req(dport))
Krishna Gudipatie3535462012-09-21 17:26:07 -07006807 return BFA_STATUS_DEVBUSY;
6808
6809 /*
6810 * Check if dport is already disabled
6811 */
6812 if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabled)) {
6813 bfa_trc(dport->bfa, 0);
6814 return BFA_STATUS_DPORT_DISABLED;
6815 }
6816
6817 dport->cbfn = cbfn;
6818 dport->cbarg = cbarg;
6819
6820 bfa_sm_send_event(dport, BFA_DPORT_SM_DISABLE);
6821 return BFA_STATUS_OK;
6822}
6823
6824/*
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006825 * Dport start -- restart dport test
Krishna Gudipatie3535462012-09-21 17:26:07 -07006826 *
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006827 * @param[in] *bfa - bfa data struct
Krishna Gudipatie3535462012-09-21 17:26:07 -07006828 */
Krishna Gudipatie3535462012-09-21 17:26:07 -07006829bfa_status_t
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006830bfa_dport_start(struct bfa_s *bfa, u32 lpcnt, u32 pat,
6831 bfa_cb_diag_t cbfn, void *cbarg)
Krishna Gudipatie3535462012-09-21 17:26:07 -07006832{
6833 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
6834 struct bfa_dport_s *dport = &fcdiag->dport;
6835
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006836 /*
6837 * Check to see if IOC is down
6838 */
6839 if (!bfa_iocfc_is_operational(bfa))
6840 return BFA_STATUS_IOC_NON_OP;
6841
6842 /*
6843 * Check if dport is in dynamic mode
6844 */
6845 if (dport->dynamic)
6846 return BFA_STATUS_DDPORT_ERR;
6847
6848 /*
6849 * Check if dport is busy
6850 */
6851 if (bfa_dport_is_sending_req(dport))
6852 return BFA_STATUS_DEVBUSY;
6853
6854 /*
6855 * Check if dport is in enabled state.
6856 * Test can only be restart when previous test has completed
6857 */
6858 if (!bfa_sm_cmp_state(dport, bfa_dport_sm_enabled)) {
6859 bfa_trc(dport->bfa, 0);
6860 return BFA_STATUS_DPORT_DISABLED;
6861
6862 } else {
6863 if (dport->test_state == BFA_DPORT_ST_NO_SFP)
6864 return BFA_STATUS_DPORT_INV_SFP;
6865
6866 if (dport->test_state == BFA_DPORT_ST_INP)
6867 return BFA_STATUS_DEVBUSY;
6868
6869 WARN_ON(dport->test_state != BFA_DPORT_ST_COMP);
Krishna Gudipatie3535462012-09-21 17:26:07 -07006870 }
Vijaya Mohan Guvva1a898a72013-05-13 02:33:21 -07006871
6872 bfa_trc(dport->bfa, lpcnt);
6873 bfa_trc(dport->bfa, pat);
6874
6875 dport->lpcnt = (lpcnt) ? lpcnt : DPORT_ENABLE_LOOPCNT_DEFAULT;
6876 dport->payload = (pat) ? pat : LB_PATTERN_DEFAULT;
6877
6878 dport->cbfn = cbfn;
6879 dport->cbarg = cbarg;
6880
6881 bfa_sm_send_event(dport, BFA_DPORT_SM_START);
6882 return BFA_STATUS_OK;
6883}
6884
6885/*
6886 * Dport show -- return dport test result
6887 *
6888 * @param[in] *bfa - bfa data struct
6889 */
6890bfa_status_t
6891bfa_dport_show(struct bfa_s *bfa, struct bfa_diag_dport_result_s *result)
6892{
6893 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
6894 struct bfa_dport_s *dport = &fcdiag->dport;
6895
6896 /*
6897 * Check to see if IOC is down
6898 */
6899 if (!bfa_iocfc_is_operational(bfa))
6900 return BFA_STATUS_IOC_NON_OP;
6901
6902 /*
6903 * Check if dport is busy
6904 */
6905 if (bfa_dport_is_sending_req(dport))
6906 return BFA_STATUS_DEVBUSY;
6907
6908 /*
6909 * Check if dport is in enabled state.
6910 */
6911 if (!bfa_sm_cmp_state(dport, bfa_dport_sm_enabled)) {
6912 bfa_trc(dport->bfa, 0);
6913 return BFA_STATUS_DPORT_DISABLED;
6914
6915 }
6916
6917 /*
6918 * Check if there is SFP
6919 */
6920 if (dport->test_state == BFA_DPORT_ST_NO_SFP)
6921 return BFA_STATUS_DPORT_INV_SFP;
6922
6923 memcpy(result, &dport->result, sizeof(struct bfa_diag_dport_result_s));
6924
Krishna Gudipatie3535462012-09-21 17:26:07 -07006925 return BFA_STATUS_OK;
6926}