blob: 309ab2ad3ce95bdeba02930338e5cf9048e0464e [file] [log] [blame]
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001/*
2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
Maggie Zhangf16a1752010-12-09 19:12:32 -080018#include "bfad_drv.h"
Krishna Gudipati7826f302011-07-20 16:59:13 -070019#include "bfad_im.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070020#include "bfa_plog.h"
21#include "bfa_cs.h"
22#include "bfa_modules.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070023
24BFA_TRC_FILE(HAL, FCXP);
Krishna Gudipati3d7fc662011-06-24 20:28:17 -070025BFA_MODULE(fcdiag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070026BFA_MODULE(fcxp);
27BFA_MODULE(sgpg);
28BFA_MODULE(lps);
29BFA_MODULE(fcport);
30BFA_MODULE(rport);
31BFA_MODULE(uf);
32
Jing Huang5fbe25c2010-10-18 17:17:23 -070033/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070034 * LPS related definitions
35 */
36#define BFA_LPS_MIN_LPORTS (1)
37#define BFA_LPS_MAX_LPORTS (256)
38
39/*
40 * Maximum Vports supported per physical port or vf.
41 */
42#define BFA_LPS_MAX_VPORTS_SUPP_CB 255
43#define BFA_LPS_MAX_VPORTS_SUPP_CT 190
44
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070045
Jing Huang5fbe25c2010-10-18 17:17:23 -070046/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070047 * FC PORT related definitions
48 */
49/*
50 * The port is considered disabled if corresponding physical port or IOC are
51 * disabled explicitly
52 */
53#define BFA_PORT_IS_DISABLED(bfa) \
54 ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
55 (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
56
Jing Huang5fbe25c2010-10-18 17:17:23 -070057/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070058 * BFA port state machine events
59 */
60enum bfa_fcport_sm_event {
61 BFA_FCPORT_SM_START = 1, /* start port state machine */
62 BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
63 BFA_FCPORT_SM_ENABLE = 3, /* enable port */
64 BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
65 BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
66 BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
67 BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
68 BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
69 BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
Krishna Gudipatie3535462012-09-21 17:26:07 -070070 BFA_FCPORT_SM_DPORTENABLE = 10, /* enable dport */
71 BFA_FCPORT_SM_DPORTDISABLE = 11,/* disable dport */
Krishna Gudipati04ea6572012-09-21 17:26:18 -070072 BFA_FCPORT_SM_FAA_MISCONFIG = 12, /* FAA misconfiguratin */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070073};
74
Jing Huang5fbe25c2010-10-18 17:17:23 -070075/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070076 * BFA port link notification state machine events
77 */
78
79enum bfa_fcport_ln_sm_event {
80 BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
81 BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
82 BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
83};
84
Jing Huang5fbe25c2010-10-18 17:17:23 -070085/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070086 * RPORT related definitions
87 */
88#define bfa_rport_offline_cb(__rp) do { \
89 if ((__rp)->bfa->fcs) \
90 bfa_cb_rport_offline((__rp)->rport_drv); \
91 else { \
92 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
93 __bfa_cb_rport_offline, (__rp)); \
94 } \
95} while (0)
96
97#define bfa_rport_online_cb(__rp) do { \
98 if ((__rp)->bfa->fcs) \
99 bfa_cb_rport_online((__rp)->rport_drv); \
100 else { \
101 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
102 __bfa_cb_rport_online, (__rp)); \
103 } \
104} while (0)
105
Jing Huang5fbe25c2010-10-18 17:17:23 -0700106/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700107 * forward declarations FCXP related functions
108 */
109static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete);
110static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
111 struct bfi_fcxp_send_rsp_s *fcxp_rsp);
112static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen,
113 struct bfa_fcxp_s *fcxp, struct fchs_s *fchs);
114static void bfa_fcxp_qresume(void *cbarg);
115static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp,
116 struct bfi_fcxp_send_req_s *send_req);
117
Jing Huang5fbe25c2010-10-18 17:17:23 -0700118/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700119 * forward declarations for LPS functions
120 */
Krishna Gudipati45070252011-06-24 20:24:29 -0700121static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg,
122 struct bfa_meminfo_s *minfo, struct bfa_s *bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700123static void bfa_lps_attach(struct bfa_s *bfa, void *bfad,
124 struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700125 struct bfa_pcidev_s *pcidev);
126static void bfa_lps_detach(struct bfa_s *bfa);
127static void bfa_lps_start(struct bfa_s *bfa);
128static void bfa_lps_stop(struct bfa_s *bfa);
129static void bfa_lps_iocdisable(struct bfa_s *bfa);
130static void bfa_lps_login_rsp(struct bfa_s *bfa,
131 struct bfi_lps_login_rsp_s *rsp);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700132static void bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700133static void bfa_lps_logout_rsp(struct bfa_s *bfa,
134 struct bfi_lps_logout_rsp_s *rsp);
135static void bfa_lps_reqq_resume(void *lps_arg);
136static void bfa_lps_free(struct bfa_lps_s *lps);
137static void bfa_lps_send_login(struct bfa_lps_s *lps);
138static void bfa_lps_send_logout(struct bfa_lps_s *lps);
Krishna Gudipatib7044952010-12-13 16:17:42 -0800139static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700140static void bfa_lps_login_comp(struct bfa_lps_s *lps);
141static void bfa_lps_logout_comp(struct bfa_lps_s *lps);
142static void bfa_lps_cvl_event(struct bfa_lps_s *lps);
143
Jing Huang5fbe25c2010-10-18 17:17:23 -0700144/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700145 * forward declaration for LPS state machine
146 */
147static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event);
148static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event);
149static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event
150 event);
151static void bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event);
Krishna Gudipatib7044952010-12-13 16:17:42 -0800152static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps,
153 enum bfa_lps_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700154static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event);
155static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event
156 event);
157
Jing Huang5fbe25c2010-10-18 17:17:23 -0700158/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700159 * forward declaration for FC Port functions
160 */
161static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
162static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
163static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
164static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
165static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
166static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
167static void bfa_fcport_scn(struct bfa_fcport_s *fcport,
168 enum bfa_port_linkstate event, bfa_boolean_t trunk);
169static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
170 enum bfa_port_linkstate event);
171static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
172static void bfa_fcport_stats_get_timeout(void *cbarg);
173static void bfa_fcport_stats_clr_timeout(void *cbarg);
174static void bfa_trunk_iocdisable(struct bfa_s *bfa);
175
Jing Huang5fbe25c2010-10-18 17:17:23 -0700176/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700177 * forward declaration for FC PORT state machine
178 */
179static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
180 enum bfa_fcport_sm_event event);
181static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
182 enum bfa_fcport_sm_event event);
183static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
184 enum bfa_fcport_sm_event event);
185static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
186 enum bfa_fcport_sm_event event);
187static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
188 enum bfa_fcport_sm_event event);
189static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
190 enum bfa_fcport_sm_event event);
191static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
192 enum bfa_fcport_sm_event event);
193static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
194 enum bfa_fcport_sm_event event);
195static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
196 enum bfa_fcport_sm_event event);
197static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
198 enum bfa_fcport_sm_event event);
199static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
200 enum bfa_fcport_sm_event event);
201static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
202 enum bfa_fcport_sm_event event);
Krishna Gudipatie3535462012-09-21 17:26:07 -0700203static void bfa_fcport_sm_dport(struct bfa_fcport_s *fcport,
204 enum bfa_fcport_sm_event event);
Krishna Gudipati04ea6572012-09-21 17:26:18 -0700205static void bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s *fcport,
206 enum bfa_fcport_sm_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700207
208static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
209 enum bfa_fcport_ln_sm_event event);
210static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
211 enum bfa_fcport_ln_sm_event event);
212static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
213 enum bfa_fcport_ln_sm_event event);
214static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
215 enum bfa_fcport_ln_sm_event event);
216static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
217 enum bfa_fcport_ln_sm_event event);
218static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
219 enum bfa_fcport_ln_sm_event event);
220static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
221 enum bfa_fcport_ln_sm_event event);
222
223static struct bfa_sm_table_s hal_port_sm_table[] = {
224 {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT},
225 {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT},
226 {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING},
227 {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN},
228 {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP},
229 {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT},
230 {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT},
231 {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING},
232 {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED},
233 {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED},
234 {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN},
235 {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN},
Krishna Gudipatie3535462012-09-21 17:26:07 -0700236 {BFA_SM(bfa_fcport_sm_dport), BFA_PORT_ST_DPORT},
Krishna Gudipati04ea6572012-09-21 17:26:18 -0700237 {BFA_SM(bfa_fcport_sm_faa_misconfig), BFA_PORT_ST_FAA_MISCONFIG},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700238};
239
240
Jing Huang5fbe25c2010-10-18 17:17:23 -0700241/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700242 * forward declaration for RPORT related functions
243 */
244static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod);
245static void bfa_rport_free(struct bfa_rport_s *rport);
246static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp);
247static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp);
248static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp);
249static void __bfa_cb_rport_online(void *cbarg,
250 bfa_boolean_t complete);
251static void __bfa_cb_rport_offline(void *cbarg,
252 bfa_boolean_t complete);
253
Jing Huang5fbe25c2010-10-18 17:17:23 -0700254/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700255 * forward declaration for RPORT state machine
256 */
257static void bfa_rport_sm_uninit(struct bfa_rport_s *rp,
258 enum bfa_rport_event event);
259static void bfa_rport_sm_created(struct bfa_rport_s *rp,
260 enum bfa_rport_event event);
261static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp,
262 enum bfa_rport_event event);
263static void bfa_rport_sm_online(struct bfa_rport_s *rp,
264 enum bfa_rport_event event);
265static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp,
266 enum bfa_rport_event event);
267static void bfa_rport_sm_offline(struct bfa_rport_s *rp,
268 enum bfa_rport_event event);
269static void bfa_rport_sm_deleting(struct bfa_rport_s *rp,
270 enum bfa_rport_event event);
271static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
272 enum bfa_rport_event event);
273static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
274 enum bfa_rport_event event);
275static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp,
276 enum bfa_rport_event event);
277static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp,
278 enum bfa_rport_event event);
279static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp,
280 enum bfa_rport_event event);
281static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp,
282 enum bfa_rport_event event);
283
Jing Huang5fbe25c2010-10-18 17:17:23 -0700284/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700285 * PLOG related definitions
286 */
287static int
288plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
289{
290 if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
291 (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
292 return 1;
293
294 if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
295 (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
296 return 1;
297
298 return 0;
299}
300
Maggie Zhangf16a1752010-12-09 19:12:32 -0800301static u64
302bfa_get_log_time(void)
303{
304 u64 system_time = 0;
305 struct timeval tv;
306 do_gettimeofday(&tv);
307
308 /* We are interested in seconds only. */
309 system_time = tv.tv_sec;
310 return system_time;
311}
312
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700313static void
314bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
315{
316 u16 tail;
317 struct bfa_plog_rec_s *pl_recp;
318
319 if (plog->plog_enabled == 0)
320 return;
321
322 if (plkd_validate_logrec(pl_rec)) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800323 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700324 return;
325 }
326
327 tail = plog->tail;
328
329 pl_recp = &(plog->plog_recs[tail]);
330
Jing Huang6a18b162010-10-18 17:08:54 -0700331 memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700332
Maggie Zhangf16a1752010-12-09 19:12:32 -0800333 pl_recp->tv = bfa_get_log_time();
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700334 BFA_PL_LOG_REC_INCR(plog->tail);
335
336 if (plog->head == plog->tail)
337 BFA_PL_LOG_REC_INCR(plog->head);
338}
339
340void
341bfa_plog_init(struct bfa_plog_s *plog)
342{
Jing Huang6a18b162010-10-18 17:08:54 -0700343 memset((char *)plog, 0, sizeof(struct bfa_plog_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700344
Jing Huang6a18b162010-10-18 17:08:54 -0700345 memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700346 plog->head = plog->tail = 0;
347 plog->plog_enabled = 1;
348}
349
350void
351bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
352 enum bfa_plog_eid event,
353 u16 misc, char *log_str)
354{
355 struct bfa_plog_rec_s lp;
356
357 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700358 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700359 lp.mid = mid;
360 lp.eid = event;
361 lp.log_type = BFA_PL_LOG_TYPE_STRING;
362 lp.misc = misc;
363 strncpy(lp.log_entry.string_log, log_str,
364 BFA_PL_STRING_LOG_SZ - 1);
365 lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
366 bfa_plog_add(plog, &lp);
367 }
368}
369
370void
371bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
372 enum bfa_plog_eid event,
373 u16 misc, u32 *intarr, u32 num_ints)
374{
375 struct bfa_plog_rec_s lp;
376 u32 i;
377
378 if (num_ints > BFA_PL_INT_LOG_SZ)
379 num_ints = BFA_PL_INT_LOG_SZ;
380
381 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700382 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700383 lp.mid = mid;
384 lp.eid = event;
385 lp.log_type = BFA_PL_LOG_TYPE_INT;
386 lp.misc = misc;
387
388 for (i = 0; i < num_ints; i++)
Jing Huang6a18b162010-10-18 17:08:54 -0700389 lp.log_entry.int_log[i] = intarr[i];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700390
391 lp.log_num_ints = (u8) num_ints;
392
393 bfa_plog_add(plog, &lp);
394 }
395}
396
397void
398bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
399 enum bfa_plog_eid event,
400 u16 misc, struct fchs_s *fchdr)
401{
402 struct bfa_plog_rec_s lp;
403 u32 *tmp_int = (u32 *) fchdr;
404 u32 ints[BFA_PL_INT_LOG_SZ];
405
406 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700407 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700408
409 ints[0] = tmp_int[0];
410 ints[1] = tmp_int[1];
411 ints[2] = tmp_int[4];
412
413 bfa_plog_intarr(plog, mid, event, misc, ints, 3);
414 }
415}
416
417void
418bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
419 enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
420 u32 pld_w0)
421{
422 struct bfa_plog_rec_s lp;
423 u32 *tmp_int = (u32 *) fchdr;
424 u32 ints[BFA_PL_INT_LOG_SZ];
425
426 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700427 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700428
429 ints[0] = tmp_int[0];
430 ints[1] = tmp_int[1];
431 ints[2] = tmp_int[4];
432 ints[3] = pld_w0;
433
434 bfa_plog_intarr(plog, mid, event, misc, ints, 4);
435 }
436}
437
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700438
Jing Huang5fbe25c2010-10-18 17:17:23 -0700439/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700440 * fcxp_pvt BFA FCXP private functions
441 */
442
443static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700444claim_fcxps_mem(struct bfa_fcxp_mod_s *mod)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700445{
446 u16 i;
447 struct bfa_fcxp_s *fcxp;
448
Krishna Gudipati45070252011-06-24 20:24:29 -0700449 fcxp = (struct bfa_fcxp_s *) bfa_mem_kva_curp(mod);
Jing Huang6a18b162010-10-18 17:08:54 -0700450 memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700451
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700452 INIT_LIST_HEAD(&mod->fcxp_req_free_q);
453 INIT_LIST_HEAD(&mod->fcxp_rsp_free_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700454 INIT_LIST_HEAD(&mod->fcxp_active_q);
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700455 INIT_LIST_HEAD(&mod->fcxp_req_unused_q);
456 INIT_LIST_HEAD(&mod->fcxp_rsp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700457
458 mod->fcxp_list = fcxp;
459
460 for (i = 0; i < mod->num_fcxps; i++) {
461 fcxp->fcxp_mod = mod;
462 fcxp->fcxp_tag = i;
463
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700464 if (i < (mod->num_fcxps / 2)) {
465 list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q);
466 fcxp->req_rsp = BFA_TRUE;
467 } else {
468 list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q);
469 fcxp->req_rsp = BFA_FALSE;
470 }
471
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700472 bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp);
473 fcxp->reqq_waiting = BFA_FALSE;
474
475 fcxp = fcxp + 1;
476 }
477
Krishna Gudipati45070252011-06-24 20:24:29 -0700478 bfa_mem_kva_curp(mod) = (void *)fcxp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700479}
480
481static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700482bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
483 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700484{
Krishna Gudipati45070252011-06-24 20:24:29 -0700485 struct bfa_fcxp_mod_s *fcxp_mod = BFA_FCXP_MOD(bfa);
486 struct bfa_mem_kva_s *fcxp_kva = BFA_MEM_FCXP_KVA(bfa);
487 struct bfa_mem_dma_s *seg_ptr;
488 u16 nsegs, idx, per_seg_fcxp;
489 u16 num_fcxps = cfg->fwcfg.num_fcxp_reqs;
490 u32 per_fcxp_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700491
Krishna Gudipati45070252011-06-24 20:24:29 -0700492 if (num_fcxps == 0)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700493 return;
494
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700495 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -0700496 per_fcxp_sz = 2 * BFA_FCXP_MAX_IBUF_SZ;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700497 else
Krishna Gudipati45070252011-06-24 20:24:29 -0700498 per_fcxp_sz = BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700499
Krishna Gudipati45070252011-06-24 20:24:29 -0700500 /* dma memory */
501 nsegs = BFI_MEM_DMA_NSEGS(num_fcxps, per_fcxp_sz);
502 per_seg_fcxp = BFI_MEM_NREQS_SEG(per_fcxp_sz);
503
504 bfa_mem_dma_seg_iter(fcxp_mod, seg_ptr, nsegs, idx) {
505 if (num_fcxps >= per_seg_fcxp) {
506 num_fcxps -= per_seg_fcxp;
507 bfa_mem_dma_setup(minfo, seg_ptr,
508 per_seg_fcxp * per_fcxp_sz);
509 } else
510 bfa_mem_dma_setup(minfo, seg_ptr,
511 num_fcxps * per_fcxp_sz);
512 }
513
514 /* kva memory */
515 bfa_mem_kva_setup(minfo, fcxp_kva,
516 cfg->fwcfg.num_fcxp_reqs * sizeof(struct bfa_fcxp_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700517}
518
519static void
520bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -0700521 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700522{
523 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
524
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700525 mod->bfa = bfa;
526 mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
527
Jing Huang5fbe25c2010-10-18 17:17:23 -0700528 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700529 * Initialize FCXP request and response payload sizes.
530 */
531 mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
532 if (!cfg->drvcfg.min_cfg)
533 mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ;
534
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700535 INIT_LIST_HEAD(&mod->req_wait_q);
536 INIT_LIST_HEAD(&mod->rsp_wait_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700537
Krishna Gudipati45070252011-06-24 20:24:29 -0700538 claim_fcxps_mem(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700539}
540
541static void
542bfa_fcxp_detach(struct bfa_s *bfa)
543{
544}
545
546static void
547bfa_fcxp_start(struct bfa_s *bfa)
548{
549}
550
551static void
552bfa_fcxp_stop(struct bfa_s *bfa)
553{
554}
555
556static void
557bfa_fcxp_iocdisable(struct bfa_s *bfa)
558{
559 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
560 struct bfa_fcxp_s *fcxp;
561 struct list_head *qe, *qen;
562
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700563 /* Enqueue unused fcxp resources to free_q */
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700564 list_splice_tail_init(&mod->fcxp_req_unused_q, &mod->fcxp_req_free_q);
565 list_splice_tail_init(&mod->fcxp_rsp_unused_q, &mod->fcxp_rsp_free_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700566
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700567 list_for_each_safe(qe, qen, &mod->fcxp_active_q) {
568 fcxp = (struct bfa_fcxp_s *) qe;
569 if (fcxp->caller == NULL) {
570 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
571 BFA_STATUS_IOC_FAILURE, 0, 0, NULL);
572 bfa_fcxp_free(fcxp);
573 } else {
574 fcxp->rsp_status = BFA_STATUS_IOC_FAILURE;
575 bfa_cb_queue(bfa, &fcxp->hcb_qe,
576 __bfa_fcxp_send_cbfn, fcxp);
577 }
578 }
579}
580
581static struct bfa_fcxp_s *
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700582bfa_fcxp_get(struct bfa_fcxp_mod_s *fm, bfa_boolean_t req)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700583{
584 struct bfa_fcxp_s *fcxp;
585
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700586 if (req)
587 bfa_q_deq(&fm->fcxp_req_free_q, &fcxp);
588 else
589 bfa_q_deq(&fm->fcxp_rsp_free_q, &fcxp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700590
591 if (fcxp)
592 list_add_tail(&fcxp->qe, &fm->fcxp_active_q);
593
594 return fcxp;
595}
596
597static void
598bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
599 struct bfa_s *bfa,
600 u8 *use_ibuf,
601 u32 *nr_sgles,
602 bfa_fcxp_get_sgaddr_t *r_sga_cbfn,
603 bfa_fcxp_get_sglen_t *r_sglen_cbfn,
604 struct list_head *r_sgpg_q,
605 int n_sgles,
606 bfa_fcxp_get_sgaddr_t sga_cbfn,
607 bfa_fcxp_get_sglen_t sglen_cbfn)
608{
609
Jing Huangd4b671c2010-12-26 21:46:35 -0800610 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700611
612 bfa_trc(bfa, fcxp->fcxp_tag);
613
614 if (n_sgles == 0) {
615 *use_ibuf = 1;
616 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800617 WARN_ON(*sga_cbfn == NULL);
618 WARN_ON(*sglen_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700619
620 *use_ibuf = 0;
621 *r_sga_cbfn = sga_cbfn;
622 *r_sglen_cbfn = sglen_cbfn;
623
624 *nr_sgles = n_sgles;
625
626 /*
627 * alloc required sgpgs
628 */
629 if (n_sgles > BFI_SGE_INLINE)
Jing Huangd4b671c2010-12-26 21:46:35 -0800630 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700631 }
632
633}
634
635static void
636bfa_fcxp_init(struct bfa_fcxp_s *fcxp,
637 void *caller, struct bfa_s *bfa, int nreq_sgles,
638 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
639 bfa_fcxp_get_sglen_t req_sglen_cbfn,
640 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
641 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
642{
643
Jing Huangd4b671c2010-12-26 21:46:35 -0800644 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700645
646 bfa_trc(bfa, fcxp->fcxp_tag);
647
648 fcxp->caller = caller;
649
650 bfa_fcxp_init_reqrsp(fcxp, bfa,
651 &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn,
652 &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q,
653 nreq_sgles, req_sga_cbfn, req_sglen_cbfn);
654
655 bfa_fcxp_init_reqrsp(fcxp, bfa,
656 &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn,
657 &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q,
658 nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn);
659
660}
661
662static void
663bfa_fcxp_put(struct bfa_fcxp_s *fcxp)
664{
665 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
666 struct bfa_fcxp_wqe_s *wqe;
667
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700668 if (fcxp->req_rsp)
669 bfa_q_deq(&mod->req_wait_q, &wqe);
670 else
671 bfa_q_deq(&mod->rsp_wait_q, &wqe);
672
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700673 if (wqe) {
674 bfa_trc(mod->bfa, fcxp->fcxp_tag);
675
676 bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles,
677 wqe->nrsp_sgles, wqe->req_sga_cbfn,
678 wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn,
679 wqe->rsp_sglen_cbfn);
680
681 wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp);
682 return;
683 }
684
Jing Huangd4b671c2010-12-26 21:46:35 -0800685 WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700686 list_del(&fcxp->qe);
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700687
688 if (fcxp->req_rsp)
689 list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q);
690 else
691 list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700692}
693
694static void
695bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
696 bfa_status_t req_status, u32 rsp_len,
697 u32 resid_len, struct fchs_s *rsp_fchs)
698{
699 /* discarded fcxp completion */
700}
701
702static void
703__bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete)
704{
705 struct bfa_fcxp_s *fcxp = cbarg;
706
707 if (complete) {
708 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
709 fcxp->rsp_status, fcxp->rsp_len,
710 fcxp->residue_len, &fcxp->rsp_fchs);
711 } else {
712 bfa_fcxp_free(fcxp);
713 }
714}
715
716static void
717hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
718{
719 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
720 struct bfa_fcxp_s *fcxp;
Jing Huangba816ea2010-10-18 17:10:50 -0700721 u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700722
723 bfa_trc(bfa, fcxp_tag);
724
Jing Huangba816ea2010-10-18 17:10:50 -0700725 fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700726
Jing Huang5fbe25c2010-10-18 17:17:23 -0700727 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700728 * @todo f/w should not set residue to non-0 when everything
729 * is received.
730 */
731 if (fcxp_rsp->req_status == BFA_STATUS_OK)
732 fcxp_rsp->residue_len = 0;
733 else
Jing Huangba816ea2010-10-18 17:10:50 -0700734 fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700735
736 fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
737
Jing Huangd4b671c2010-12-26 21:46:35 -0800738 WARN_ON(fcxp->send_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700739
740 hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp);
741
742 if (fcxp->send_cbfn != NULL) {
743 bfa_trc(mod->bfa, (NULL == fcxp->caller));
744 if (fcxp->caller == NULL) {
745 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
746 fcxp_rsp->req_status, fcxp_rsp->rsp_len,
747 fcxp_rsp->residue_len, &fcxp_rsp->fchs);
748 /*
749 * fcxp automatically freed on return from the callback
750 */
751 bfa_fcxp_free(fcxp);
752 } else {
753 fcxp->rsp_status = fcxp_rsp->req_status;
754 fcxp->rsp_len = fcxp_rsp->rsp_len;
755 fcxp->residue_len = fcxp_rsp->residue_len;
756 fcxp->rsp_fchs = fcxp_rsp->fchs;
757
758 bfa_cb_queue(bfa, &fcxp->hcb_qe,
759 __bfa_fcxp_send_cbfn, fcxp);
760 }
761 } else {
762 bfa_trc(bfa, (NULL == fcxp->send_cbfn));
763 }
764}
765
766static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700767hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp,
768 struct fchs_s *fchs)
769{
770 /*
771 * TODO: TX ox_id
772 */
773 if (reqlen > 0) {
774 if (fcxp->use_ireqbuf) {
775 u32 pld_w0 =
776 *((u32 *) BFA_FCXP_REQ_PLD(fcxp));
777
778 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
779 BFA_PL_EID_TX,
780 reqlen + sizeof(struct fchs_s), fchs,
781 pld_w0);
782 } else {
783 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
784 BFA_PL_EID_TX,
785 reqlen + sizeof(struct fchs_s),
786 fchs);
787 }
788 } else {
789 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX,
790 reqlen + sizeof(struct fchs_s), fchs);
791 }
792}
793
794static void
795hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
796 struct bfi_fcxp_send_rsp_s *fcxp_rsp)
797{
798 if (fcxp_rsp->rsp_len > 0) {
799 if (fcxp->use_irspbuf) {
800 u32 pld_w0 =
801 *((u32 *) BFA_FCXP_RSP_PLD(fcxp));
802
803 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
804 BFA_PL_EID_RX,
805 (u16) fcxp_rsp->rsp_len,
806 &fcxp_rsp->fchs, pld_w0);
807 } else {
808 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
809 BFA_PL_EID_RX,
810 (u16) fcxp_rsp->rsp_len,
811 &fcxp_rsp->fchs);
812 }
813 } else {
814 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX,
815 (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs);
816 }
817}
818
Jing Huang5fbe25c2010-10-18 17:17:23 -0700819/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700820 * Handler to resume sending fcxp when space in available in cpe queue.
821 */
822static void
823bfa_fcxp_qresume(void *cbarg)
824{
825 struct bfa_fcxp_s *fcxp = cbarg;
826 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
827 struct bfi_fcxp_send_req_s *send_req;
828
829 fcxp->reqq_waiting = BFA_FALSE;
830 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
831 bfa_fcxp_queue(fcxp, send_req);
832}
833
Jing Huang5fbe25c2010-10-18 17:17:23 -0700834/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700835 * Queue fcxp send request to foimrware.
836 */
837static void
838bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
839{
840 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
841 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
842 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
843 struct bfa_rport_s *rport = reqi->bfa_rport;
844
845 bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700846 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700847
Jing Huangba816ea2010-10-18 17:10:50 -0700848 send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700849 if (rport) {
850 send_req->rport_fw_hndl = rport->fw_handle;
Jing Huangba816ea2010-10-18 17:10:50 -0700851 send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700852 if (send_req->max_frmsz == 0)
Jing Huangba816ea2010-10-18 17:10:50 -0700853 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700854 } else {
855 send_req->rport_fw_hndl = 0;
Jing Huangba816ea2010-10-18 17:10:50 -0700856 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700857 }
858
Jing Huangba816ea2010-10-18 17:10:50 -0700859 send_req->vf_id = cpu_to_be16(reqi->vf_id);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700860 send_req->lp_fwtag = bfa_lps_get_fwtag(bfa, reqi->lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700861 send_req->class = reqi->class;
862 send_req->rsp_timeout = rspi->rsp_timeout;
863 send_req->cts = reqi->cts;
864 send_req->fchs = reqi->fchs;
865
Jing Huangba816ea2010-10-18 17:10:50 -0700866 send_req->req_len = cpu_to_be32(reqi->req_tot_len);
867 send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700868
869 /*
870 * setup req sgles
871 */
872 if (fcxp->use_ireqbuf == 1) {
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700873 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700874 BFA_FCXP_REQ_PLD_PA(fcxp));
875 } else {
876 if (fcxp->nreq_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800877 WARN_ON(fcxp->nreq_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700878 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
879 fcxp->req_sga_cbfn(fcxp->caller, 0));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700880 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800881 WARN_ON(reqi->req_tot_len != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700882 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700883 }
884 }
885
886 /*
887 * setup rsp sgles
888 */
889 if (fcxp->use_irspbuf == 1) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800890 WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700891
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700892 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700893 BFA_FCXP_RSP_PLD_PA(fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700894 } else {
895 if (fcxp->nrsp_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800896 WARN_ON(fcxp->nrsp_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700897 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
898 fcxp->rsp_sga_cbfn(fcxp->caller, 0));
899
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700900 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800901 WARN_ON(rspi->rsp_maxlen != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700902 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700903 }
904 }
905
906 hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs);
907
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700908 bfa_reqq_produce(bfa, BFA_REQQ_FCXP, send_req->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700909
910 bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP));
911 bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
912}
913
Jing Huang5fbe25c2010-10-18 17:17:23 -0700914/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700915 * Allocate an FCXP instance to send a response or to send a request
916 * that has a response. Request/response buffers are allocated by caller.
917 *
918 * @param[in] bfa BFA bfa instance
919 * @param[in] nreq_sgles Number of SG elements required for request
920 * buffer. 0, if fcxp internal buffers are used.
921 * Use bfa_fcxp_get_reqbuf() to get the
922 * internal req buffer.
923 * @param[in] req_sgles SG elements describing request buffer. Will be
924 * copied in by BFA and hence can be freed on
925 * return from this function.
926 * @param[in] get_req_sga function ptr to be called to get a request SG
927 * Address (given the sge index).
928 * @param[in] get_req_sglen function ptr to be called to get a request SG
929 * len (given the sge index).
930 * @param[in] get_rsp_sga function ptr to be called to get a response SG
931 * Address (given the sge index).
932 * @param[in] get_rsp_sglen function ptr to be called to get a response SG
933 * len (given the sge index).
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700934 * @param[in] req Allocated FCXP is used to send req or rsp?
935 * request - BFA_TRUE, response - BFA_FALSE
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700936 *
937 * @return FCXP instance. NULL on failure.
938 */
939struct bfa_fcxp_s *
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700940bfa_fcxp_req_rsp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
941 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
942 bfa_fcxp_get_sglen_t req_sglen_cbfn,
943 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
944 bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700945{
946 struct bfa_fcxp_s *fcxp = NULL;
947
Jing Huangd4b671c2010-12-26 21:46:35 -0800948 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700949
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700950 fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa), req);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700951 if (fcxp == NULL)
952 return NULL;
953
954 bfa_trc(bfa, fcxp->fcxp_tag);
955
956 bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn,
957 req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn);
958
959 return fcxp;
960}
961
Jing Huang5fbe25c2010-10-18 17:17:23 -0700962/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700963 * Get the internal request buffer pointer
964 *
965 * @param[in] fcxp BFA fcxp pointer
966 *
967 * @return pointer to the internal request buffer
968 */
969void *
970bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp)
971{
972 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
973 void *reqbuf;
974
Jing Huangd4b671c2010-12-26 21:46:35 -0800975 WARN_ON(fcxp->use_ireqbuf != 1);
Krishna Gudipati45070252011-06-24 20:24:29 -0700976 reqbuf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
977 mod->req_pld_sz + mod->rsp_pld_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700978 return reqbuf;
979}
980
981u32
982bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
983{
984 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
985
986 return mod->req_pld_sz;
987}
988
Jing Huang5fbe25c2010-10-18 17:17:23 -0700989/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700990 * Get the internal response buffer pointer
991 *
992 * @param[in] fcxp BFA fcxp pointer
993 *
994 * @return pointer to the internal request buffer
995 */
996void *
997bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
998{
999 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
Krishna Gudipati45070252011-06-24 20:24:29 -07001000 void *fcxp_buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001001
Jing Huangd4b671c2010-12-26 21:46:35 -08001002 WARN_ON(fcxp->use_irspbuf != 1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001003
Krishna Gudipati45070252011-06-24 20:24:29 -07001004 fcxp_buf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
1005 mod->req_pld_sz + mod->rsp_pld_sz);
1006
1007 /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
1008 return ((u8 *) fcxp_buf) + mod->req_pld_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001009}
1010
Jing Huang5fbe25c2010-10-18 17:17:23 -07001011/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001012 * Free the BFA FCXP
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001013 *
1014 * @param[in] fcxp BFA fcxp pointer
1015 *
1016 * @return void
1017 */
1018void
1019bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
1020{
1021 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
1022
Jing Huangd4b671c2010-12-26 21:46:35 -08001023 WARN_ON(fcxp == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001024 bfa_trc(mod->bfa, fcxp->fcxp_tag);
1025 bfa_fcxp_put(fcxp);
1026}
1027
Jing Huang5fbe25c2010-10-18 17:17:23 -07001028/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001029 * Send a FCXP request
1030 *
1031 * @param[in] fcxp BFA fcxp pointer
1032 * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
1033 * @param[in] vf_id virtual Fabric ID
1034 * @param[in] lp_tag lport tag
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001035 * @param[in] cts use Continuous sequence
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001036 * @param[in] cos fc Class of Service
1037 * @param[in] reqlen request length, does not include FCHS length
1038 * @param[in] fchs fc Header Pointer. The header content will be copied
1039 * in by BFA.
1040 *
1041 * @param[in] cbfn call back function to be called on receiving
1042 * the response
1043 * @param[in] cbarg arg for cbfn
1044 * @param[in] rsp_timeout
1045 * response timeout
1046 *
1047 * @return bfa_status_t
1048 */
1049void
1050bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
1051 u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos,
1052 u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn,
1053 void *cbarg, u32 rsp_maxlen, u8 rsp_timeout)
1054{
1055 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
1056 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
1057 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
1058 struct bfi_fcxp_send_req_s *send_req;
1059
1060 bfa_trc(bfa, fcxp->fcxp_tag);
1061
Jing Huang5fbe25c2010-10-18 17:17:23 -07001062 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001063 * setup request/response info
1064 */
1065 reqi->bfa_rport = rport;
1066 reqi->vf_id = vf_id;
1067 reqi->lp_tag = lp_tag;
1068 reqi->class = cos;
1069 rspi->rsp_timeout = rsp_timeout;
1070 reqi->cts = cts;
1071 reqi->fchs = *fchs;
1072 reqi->req_tot_len = reqlen;
1073 rspi->rsp_maxlen = rsp_maxlen;
1074 fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
1075 fcxp->send_cbarg = cbarg;
1076
Jing Huang5fbe25c2010-10-18 17:17:23 -07001077 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001078 * If no room in CPE queue, wait for space in request queue
1079 */
1080 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
1081 if (!send_req) {
1082 bfa_trc(bfa, fcxp->fcxp_tag);
1083 fcxp->reqq_waiting = BFA_TRUE;
1084 bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe);
1085 return;
1086 }
1087
1088 bfa_fcxp_queue(fcxp, send_req);
1089}
1090
Jing Huang5fbe25c2010-10-18 17:17:23 -07001091/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001092 * Abort a BFA FCXP
1093 *
1094 * @param[in] fcxp BFA fcxp pointer
1095 *
1096 * @return void
1097 */
1098bfa_status_t
1099bfa_fcxp_abort(struct bfa_fcxp_s *fcxp)
1100{
1101 bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag);
Jing Huangd4b671c2010-12-26 21:46:35 -08001102 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001103 return BFA_STATUS_OK;
1104}
1105
1106void
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001107bfa_fcxp_req_rsp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001108 bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg,
1109 void *caller, int nreq_sgles,
1110 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
1111 bfa_fcxp_get_sglen_t req_sglen_cbfn,
1112 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001113 bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001114{
1115 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1116
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001117 if (req)
1118 WARN_ON(!list_empty(&mod->fcxp_req_free_q));
1119 else
1120 WARN_ON(!list_empty(&mod->fcxp_rsp_free_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001121
1122 wqe->alloc_cbfn = alloc_cbfn;
1123 wqe->alloc_cbarg = alloc_cbarg;
1124 wqe->caller = caller;
1125 wqe->bfa = bfa;
1126 wqe->nreq_sgles = nreq_sgles;
1127 wqe->nrsp_sgles = nrsp_sgles;
1128 wqe->req_sga_cbfn = req_sga_cbfn;
1129 wqe->req_sglen_cbfn = req_sglen_cbfn;
1130 wqe->rsp_sga_cbfn = rsp_sga_cbfn;
1131 wqe->rsp_sglen_cbfn = rsp_sglen_cbfn;
1132
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001133 if (req)
1134 list_add_tail(&wqe->qe, &mod->req_wait_q);
1135 else
1136 list_add_tail(&wqe->qe, &mod->rsp_wait_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001137}
1138
1139void
1140bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
1141{
1142 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1143
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001144 WARN_ON(!bfa_q_is_on_q(&mod->req_wait_q, wqe) ||
1145 !bfa_q_is_on_q(&mod->rsp_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001146 list_del(&wqe->qe);
1147}
1148
1149void
1150bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
1151{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001152 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001153 * If waiting for room in request queue, cancel reqq wait
1154 * and free fcxp.
1155 */
1156 if (fcxp->reqq_waiting) {
1157 fcxp->reqq_waiting = BFA_FALSE;
1158 bfa_reqq_wcancel(&fcxp->reqq_wqe);
1159 bfa_fcxp_free(fcxp);
1160 return;
1161 }
1162
1163 fcxp->send_cbfn = bfa_fcxp_null_comp;
1164}
1165
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001166void
1167bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
1168{
1169 switch (msg->mhdr.msg_id) {
1170 case BFI_FCXP_I2H_SEND_RSP:
1171 hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg);
1172 break;
1173
1174 default:
1175 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001176 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001177 }
1178}
1179
1180u32
1181bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
1182{
1183 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1184
1185 return mod->rsp_pld_sz;
1186}
1187
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001188void
1189bfa_fcxp_res_recfg(struct bfa_s *bfa, u16 num_fcxp_fw)
1190{
1191 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1192 struct list_head *qe;
1193 int i;
1194
1195 for (i = 0; i < (mod->num_fcxps - num_fcxp_fw); i++) {
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001196 if (i < ((mod->num_fcxps - num_fcxp_fw) / 2)) {
1197 bfa_q_deq_tail(&mod->fcxp_req_free_q, &qe);
1198 list_add_tail(qe, &mod->fcxp_req_unused_q);
1199 } else {
1200 bfa_q_deq_tail(&mod->fcxp_rsp_free_q, &qe);
1201 list_add_tail(qe, &mod->fcxp_rsp_unused_q);
1202 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001203 }
1204}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001205
Jing Huang5fbe25c2010-10-18 17:17:23 -07001206/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001207 * BFA LPS state machine functions
1208 */
1209
Jing Huang5fbe25c2010-10-18 17:17:23 -07001210/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001211 * Init state -- no login
1212 */
1213static void
1214bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
1215{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001216 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001217 bfa_trc(lps->bfa, event);
1218
1219 switch (event) {
1220 case BFA_LPS_SM_LOGIN:
1221 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1222 bfa_sm_set_state(lps, bfa_lps_sm_loginwait);
1223 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1224 } else {
1225 bfa_sm_set_state(lps, bfa_lps_sm_login);
1226 bfa_lps_send_login(lps);
1227 }
1228
1229 if (lps->fdisc)
1230 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1231 BFA_PL_EID_LOGIN, 0, "FDISC Request");
1232 else
1233 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1234 BFA_PL_EID_LOGIN, 0, "FLOGI Request");
1235 break;
1236
1237 case BFA_LPS_SM_LOGOUT:
1238 bfa_lps_logout_comp(lps);
1239 break;
1240
1241 case BFA_LPS_SM_DELETE:
1242 bfa_lps_free(lps);
1243 break;
1244
1245 case BFA_LPS_SM_RX_CVL:
1246 case BFA_LPS_SM_OFFLINE:
1247 break;
1248
1249 case BFA_LPS_SM_FWRSP:
1250 /*
1251 * Could happen when fabric detects loopback and discards
1252 * the lps request. Fw will eventually sent out the timeout
1253 * Just ignore
1254 */
1255 break;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07001256 case BFA_LPS_SM_SET_N2N_PID:
1257 /*
1258 * When topology is set to loop, bfa_lps_set_n2n_pid() sends
1259 * this event. Ignore this event.
1260 */
1261 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001262
1263 default:
1264 bfa_sm_fault(lps->bfa, event);
1265 }
1266}
1267
Jing Huang5fbe25c2010-10-18 17:17:23 -07001268/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001269 * login is in progress -- awaiting response from firmware
1270 */
1271static void
1272bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
1273{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001274 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001275 bfa_trc(lps->bfa, event);
1276
1277 switch (event) {
1278 case BFA_LPS_SM_FWRSP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07001279 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001280 if (lps->status == BFA_STATUS_OK) {
1281 bfa_sm_set_state(lps, bfa_lps_sm_online);
1282 if (lps->fdisc)
1283 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1284 BFA_PL_EID_LOGIN, 0, "FDISC Accept");
1285 else
1286 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1287 BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
Krishna Gudipatib7044952010-12-13 16:17:42 -08001288 /* If N2N, send the assigned PID to FW */
1289 bfa_trc(lps->bfa, lps->fport);
1290 bfa_trc(lps->bfa, lps->lp_pid);
1291
1292 if (!lps->fport && lps->lp_pid)
1293 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001294 } else {
1295 bfa_sm_set_state(lps, bfa_lps_sm_init);
1296 if (lps->fdisc)
1297 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1298 BFA_PL_EID_LOGIN, 0,
1299 "FDISC Fail (RJT or timeout)");
1300 else
1301 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1302 BFA_PL_EID_LOGIN, 0,
1303 "FLOGI Fail (RJT or timeout)");
1304 }
1305 bfa_lps_login_comp(lps);
1306 break;
1307
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001308 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001309 bfa_sm_set_state(lps, bfa_lps_sm_init);
1310 break;
1311
Krishna Gudipatib7044952010-12-13 16:17:42 -08001312 case BFA_LPS_SM_SET_N2N_PID:
1313 bfa_trc(lps->bfa, lps->fport);
1314 bfa_trc(lps->bfa, lps->lp_pid);
1315 break;
1316
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001317 default:
1318 bfa_sm_fault(lps->bfa, event);
1319 }
1320}
1321
Jing Huang5fbe25c2010-10-18 17:17:23 -07001322/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001323 * login pending - awaiting space in request queue
1324 */
1325static void
1326bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1327{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001328 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001329 bfa_trc(lps->bfa, event);
1330
1331 switch (event) {
1332 case BFA_LPS_SM_RESUME:
1333 bfa_sm_set_state(lps, bfa_lps_sm_login);
Krishna Gudipatiff179e02012-03-13 17:40:31 -07001334 bfa_lps_send_login(lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001335 break;
1336
1337 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001338 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001339 bfa_sm_set_state(lps, bfa_lps_sm_init);
1340 bfa_reqq_wcancel(&lps->wqe);
1341 break;
1342
1343 case BFA_LPS_SM_RX_CVL:
1344 /*
1345 * Login was not even sent out; so when getting out
1346 * of this state, it will appear like a login retry
1347 * after Clear virtual link
1348 */
1349 break;
1350
1351 default:
1352 bfa_sm_fault(lps->bfa, event);
1353 }
1354}
1355
Jing Huang5fbe25c2010-10-18 17:17:23 -07001356/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001357 * login complete
1358 */
1359static void
1360bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
1361{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001362 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001363 bfa_trc(lps->bfa, event);
1364
1365 switch (event) {
1366 case BFA_LPS_SM_LOGOUT:
1367 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1368 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1369 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1370 } else {
1371 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1372 bfa_lps_send_logout(lps);
1373 }
1374 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1375 BFA_PL_EID_LOGO, 0, "Logout");
1376 break;
1377
1378 case BFA_LPS_SM_RX_CVL:
1379 bfa_sm_set_state(lps, bfa_lps_sm_init);
1380
1381 /* Let the vport module know about this event */
1382 bfa_lps_cvl_event(lps);
1383 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1384 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1385 break;
1386
Krishna Gudipatib7044952010-12-13 16:17:42 -08001387 case BFA_LPS_SM_SET_N2N_PID:
1388 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1389 bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
1390 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1391 } else
1392 bfa_lps_send_set_n2n_pid(lps);
1393 break;
1394
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001395 case BFA_LPS_SM_OFFLINE:
1396 case BFA_LPS_SM_DELETE:
1397 bfa_sm_set_state(lps, bfa_lps_sm_init);
1398 break;
1399
1400 default:
1401 bfa_sm_fault(lps->bfa, event);
1402 }
1403}
1404
Jing Huang8f4bfad2010-12-26 21:50:10 -08001405/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001406 * login complete
1407 */
1408static void
1409bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1410{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001411 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001412 bfa_trc(lps->bfa, event);
1413
1414 switch (event) {
1415 case BFA_LPS_SM_RESUME:
1416 bfa_sm_set_state(lps, bfa_lps_sm_online);
1417 bfa_lps_send_set_n2n_pid(lps);
1418 break;
1419
1420 case BFA_LPS_SM_LOGOUT:
1421 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1422 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1423 BFA_PL_EID_LOGO, 0, "Logout");
1424 break;
1425
1426 case BFA_LPS_SM_RX_CVL:
1427 bfa_sm_set_state(lps, bfa_lps_sm_init);
1428 bfa_reqq_wcancel(&lps->wqe);
1429
1430 /* Let the vport module know about this event */
1431 bfa_lps_cvl_event(lps);
1432 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1433 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1434 break;
1435
1436 case BFA_LPS_SM_OFFLINE:
1437 case BFA_LPS_SM_DELETE:
1438 bfa_sm_set_state(lps, bfa_lps_sm_init);
1439 bfa_reqq_wcancel(&lps->wqe);
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 in progress - awaiting firmware response
1449 */
1450static void
1451bfa_lps_sm_logout(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_FWRSP:
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001458 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001459 bfa_sm_set_state(lps, bfa_lps_sm_init);
1460 bfa_lps_logout_comp(lps);
1461 break;
1462
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 break;
1466
1467 default:
1468 bfa_sm_fault(lps->bfa, event);
1469 }
1470}
1471
Jing Huang5fbe25c2010-10-18 17:17:23 -07001472/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001473 * logout pending -- awaiting space in request queue
1474 */
1475static void
1476bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1477{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001478 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001479 bfa_trc(lps->bfa, event);
1480
1481 switch (event) {
1482 case BFA_LPS_SM_RESUME:
1483 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1484 bfa_lps_send_logout(lps);
1485 break;
1486
1487 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001488 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001489 bfa_sm_set_state(lps, bfa_lps_sm_init);
1490 bfa_reqq_wcancel(&lps->wqe);
1491 break;
1492
1493 default:
1494 bfa_sm_fault(lps->bfa, event);
1495 }
1496}
1497
1498
1499
Jing Huang5fbe25c2010-10-18 17:17:23 -07001500/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001501 * lps_pvt BFA LPS private functions
1502 */
1503
Jing Huang5fbe25c2010-10-18 17:17:23 -07001504/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001505 * return memory requirement
1506 */
1507static void
Krishna Gudipati45070252011-06-24 20:24:29 -07001508bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
1509 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001510{
Krishna Gudipati45070252011-06-24 20:24:29 -07001511 struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa);
1512
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001513 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -07001514 bfa_mem_kva_setup(minfo, lps_kva,
1515 sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001516 else
Krishna Gudipati45070252011-06-24 20:24:29 -07001517 bfa_mem_kva_setup(minfo, lps_kva,
1518 sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001519}
1520
Jing Huang5fbe25c2010-10-18 17:17:23 -07001521/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001522 * bfa module attach at initialization time
1523 */
1524static void
1525bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07001526 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001527{
1528 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1529 struct bfa_lps_s *lps;
1530 int i;
1531
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001532 mod->num_lps = BFA_LPS_MAX_LPORTS;
1533 if (cfg->drvcfg.min_cfg)
1534 mod->num_lps = BFA_LPS_MIN_LPORTS;
1535 else
1536 mod->num_lps = BFA_LPS_MAX_LPORTS;
Krishna Gudipati45070252011-06-24 20:24:29 -07001537 mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001538
Krishna Gudipati45070252011-06-24 20:24:29 -07001539 bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001540
1541 INIT_LIST_HEAD(&mod->lps_free_q);
1542 INIT_LIST_HEAD(&mod->lps_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001543 INIT_LIST_HEAD(&mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001544
1545 for (i = 0; i < mod->num_lps; i++, lps++) {
1546 lps->bfa = bfa;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001547 lps->bfa_tag = (u8) i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001548 lps->reqq = BFA_REQQ_LPS;
1549 bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
1550 list_add_tail(&lps->qe, &mod->lps_free_q);
1551 }
1552}
1553
1554static void
1555bfa_lps_detach(struct bfa_s *bfa)
1556{
1557}
1558
1559static void
1560bfa_lps_start(struct bfa_s *bfa)
1561{
1562}
1563
1564static void
1565bfa_lps_stop(struct bfa_s *bfa)
1566{
1567}
1568
Jing Huang5fbe25c2010-10-18 17:17:23 -07001569/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001570 * IOC in disabled state -- consider all lps offline
1571 */
1572static void
1573bfa_lps_iocdisable(struct bfa_s *bfa)
1574{
1575 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1576 struct bfa_lps_s *lps;
1577 struct list_head *qe, *qen;
1578
1579 list_for_each_safe(qe, qen, &mod->lps_active_q) {
1580 lps = (struct bfa_lps_s *) qe;
1581 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1582 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001583 list_for_each_safe(qe, qen, &mod->lps_login_q) {
1584 lps = (struct bfa_lps_s *) qe;
1585 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1586 }
1587 list_splice_tail_init(&mod->lps_login_q, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001588}
1589
Jing Huang5fbe25c2010-10-18 17:17:23 -07001590/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001591 * Firmware login response
1592 */
1593static void
1594bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
1595{
1596 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1597 struct bfa_lps_s *lps;
1598
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001599 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1600 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001601
1602 lps->status = rsp->status;
1603 switch (rsp->status) {
1604 case BFA_STATUS_OK:
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001605 lps->fw_tag = rsp->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001606 lps->fport = rsp->f_port;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001607 if (lps->fport)
1608 lps->lp_pid = rsp->lp_pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001609 lps->npiv_en = rsp->npiv_en;
Jing Huangba816ea2010-10-18 17:10:50 -07001610 lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001611 lps->pr_pwwn = rsp->port_name;
1612 lps->pr_nwwn = rsp->node_name;
1613 lps->auth_req = rsp->auth_req;
1614 lps->lp_mac = rsp->lp_mac;
1615 lps->brcd_switch = rsp->brcd_switch;
1616 lps->fcf_mac = rsp->fcf_mac;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001617 lps->pr_bbscn = rsp->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001618
1619 break;
1620
1621 case BFA_STATUS_FABRIC_RJT:
1622 lps->lsrjt_rsn = rsp->lsrjt_rsn;
1623 lps->lsrjt_expl = rsp->lsrjt_expl;
1624
1625 break;
1626
1627 case BFA_STATUS_EPROTOCOL:
1628 lps->ext_status = rsp->ext_status;
1629
1630 break;
1631
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001632 case BFA_STATUS_VPORT_MAX:
Krishna Gudipatiff179e02012-03-13 17:40:31 -07001633 if (rsp->ext_status)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001634 bfa_lps_no_res(lps, rsp->ext_status);
1635 break;
1636
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001637 default:
1638 /* Nothing to do with other status */
1639 break;
1640 }
1641
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001642 list_del(&lps->qe);
1643 list_add_tail(&lps->qe, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001644 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1645}
1646
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001647static void
1648bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count)
1649{
1650 struct bfa_s *bfa = first_lps->bfa;
1651 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1652 struct list_head *qe, *qe_next;
1653 struct bfa_lps_s *lps;
1654
1655 bfa_trc(bfa, count);
1656
1657 qe = bfa_q_next(first_lps);
1658
1659 while (count && qe) {
1660 qe_next = bfa_q_next(qe);
1661 lps = (struct bfa_lps_s *)qe;
1662 bfa_trc(bfa, lps->bfa_tag);
1663 lps->status = first_lps->status;
1664 list_del(&lps->qe);
1665 list_add_tail(&lps->qe, &mod->lps_active_q);
1666 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1667 qe = qe_next;
1668 count--;
1669 }
1670}
1671
Jing Huang5fbe25c2010-10-18 17:17:23 -07001672/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001673 * Firmware logout response
1674 */
1675static void
1676bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
1677{
1678 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1679 struct bfa_lps_s *lps;
1680
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001681 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1682 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001683
1684 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1685}
1686
Jing Huang5fbe25c2010-10-18 17:17:23 -07001687/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001688 * Firmware received a Clear virtual link request (for FCoE)
1689 */
1690static void
1691bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
1692{
1693 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1694 struct bfa_lps_s *lps;
1695
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001696 lps = BFA_LPS_FROM_TAG(mod, cvl->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001697
1698 bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
1699}
1700
Jing Huang5fbe25c2010-10-18 17:17:23 -07001701/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001702 * Space is available in request queue, resume queueing request to firmware.
1703 */
1704static void
1705bfa_lps_reqq_resume(void *lps_arg)
1706{
1707 struct bfa_lps_s *lps = lps_arg;
1708
1709 bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
1710}
1711
Jing Huang5fbe25c2010-10-18 17:17:23 -07001712/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001713 * lps is freed -- triggered by vport delete
1714 */
1715static void
1716bfa_lps_free(struct bfa_lps_s *lps)
1717{
1718 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
1719
1720 lps->lp_pid = 0;
1721 list_del(&lps->qe);
1722 list_add_tail(&lps->qe, &mod->lps_free_q);
1723}
1724
Jing Huang5fbe25c2010-10-18 17:17:23 -07001725/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001726 * send login request to firmware
1727 */
1728static void
1729bfa_lps_send_login(struct bfa_lps_s *lps)
1730{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001731 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001732 struct bfi_lps_login_req_s *m;
1733
1734 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001735 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001736
1737 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001738 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001739
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001740 m->bfa_tag = lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001741 m->alpa = lps->alpa;
Jing Huangba816ea2010-10-18 17:10:50 -07001742 m->pdu_size = cpu_to_be16(lps->pdusz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001743 m->pwwn = lps->pwwn;
1744 m->nwwn = lps->nwwn;
1745 m->fdisc = lps->fdisc;
1746 m->auth_en = lps->auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001747 m->bb_scn = lps->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001748
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001749 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
1750 list_del(&lps->qe);
1751 list_add_tail(&lps->qe, &mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001752}
1753
Jing Huang5fbe25c2010-10-18 17:17:23 -07001754/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001755 * send logout request to firmware
1756 */
1757static void
1758bfa_lps_send_logout(struct bfa_lps_s *lps)
1759{
1760 struct bfi_lps_logout_req_s *m;
1761
1762 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001763 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001764
1765 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001766 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001767
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001768 m->fw_tag = lps->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001769 m->port_name = lps->pwwn;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001770 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001771}
1772
Jing Huang8f4bfad2010-12-26 21:50:10 -08001773/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001774 * send n2n pid set request to firmware
1775 */
1776static void
1777bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
1778{
1779 struct bfi_lps_n2n_pid_req_s *m;
1780
1781 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001782 WARN_ON(!m);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001783
1784 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001785 bfa_fn_lpu(lps->bfa));
Krishna Gudipatib7044952010-12-13 16:17:42 -08001786
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001787 m->fw_tag = lps->fw_tag;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001788 m->lp_pid = lps->lp_pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001789 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001790}
1791
Jing Huang5fbe25c2010-10-18 17:17:23 -07001792/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001793 * Indirect login completion handler for non-fcs
1794 */
1795static void
1796bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
1797{
1798 struct bfa_lps_s *lps = arg;
1799
1800 if (!complete)
1801 return;
1802
1803 if (lps->fdisc)
1804 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1805 else
1806 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1807}
1808
Jing Huang5fbe25c2010-10-18 17:17:23 -07001809/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001810 * Login completion handler -- direct call for fcs, queue for others
1811 */
1812static void
1813bfa_lps_login_comp(struct bfa_lps_s *lps)
1814{
1815 if (!lps->bfa->fcs) {
1816 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
1817 lps);
1818 return;
1819 }
1820
1821 if (lps->fdisc)
1822 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1823 else
1824 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1825}
1826
Jing Huang5fbe25c2010-10-18 17:17:23 -07001827/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001828 * Indirect logout completion handler for non-fcs
1829 */
1830static void
1831bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
1832{
1833 struct bfa_lps_s *lps = arg;
1834
1835 if (!complete)
1836 return;
1837
1838 if (lps->fdisc)
1839 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001840 else
1841 bfa_cb_lps_flogo_comp(lps->bfa->bfad, lps->uarg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001842}
1843
Jing Huang5fbe25c2010-10-18 17:17:23 -07001844/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001845 * Logout completion handler -- direct call for fcs, queue for others
1846 */
1847static void
1848bfa_lps_logout_comp(struct bfa_lps_s *lps)
1849{
1850 if (!lps->bfa->fcs) {
1851 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
1852 lps);
1853 return;
1854 }
1855 if (lps->fdisc)
1856 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1857}
1858
Jing Huang5fbe25c2010-10-18 17:17:23 -07001859/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001860 * Clear virtual link completion handler for non-fcs
1861 */
1862static void
1863bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
1864{
1865 struct bfa_lps_s *lps = arg;
1866
1867 if (!complete)
1868 return;
1869
1870 /* Clear virtual link to base port will result in link down */
1871 if (lps->fdisc)
1872 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1873}
1874
Jing Huang5fbe25c2010-10-18 17:17:23 -07001875/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001876 * Received Clear virtual link event --direct call for fcs,
1877 * queue for others
1878 */
1879static void
1880bfa_lps_cvl_event(struct bfa_lps_s *lps)
1881{
1882 if (!lps->bfa->fcs) {
1883 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
1884 lps);
1885 return;
1886 }
1887
1888 /* Clear virtual link to base port will result in link down */
1889 if (lps->fdisc)
1890 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1891}
1892
1893
1894
Jing Huang5fbe25c2010-10-18 17:17:23 -07001895/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001896 * lps_public BFA LPS public functions
1897 */
1898
1899u32
1900bfa_lps_get_max_vport(struct bfa_s *bfa)
1901{
1902 if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
1903 return BFA_LPS_MAX_VPORTS_SUPP_CT;
1904 else
1905 return BFA_LPS_MAX_VPORTS_SUPP_CB;
1906}
1907
Jing Huang5fbe25c2010-10-18 17:17:23 -07001908/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001909 * Allocate a lport srvice tag.
1910 */
1911struct bfa_lps_s *
1912bfa_lps_alloc(struct bfa_s *bfa)
1913{
1914 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1915 struct bfa_lps_s *lps = NULL;
1916
1917 bfa_q_deq(&mod->lps_free_q, &lps);
1918
1919 if (lps == NULL)
1920 return NULL;
1921
1922 list_add_tail(&lps->qe, &mod->lps_active_q);
1923
1924 bfa_sm_set_state(lps, bfa_lps_sm_init);
1925 return lps;
1926}
1927
Jing Huang5fbe25c2010-10-18 17:17:23 -07001928/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001929 * Free lport service tag. This can be called anytime after an alloc.
1930 * No need to wait for any pending login/logout completions.
1931 */
1932void
1933bfa_lps_delete(struct bfa_lps_s *lps)
1934{
1935 bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
1936}
1937
Jing Huang5fbe25c2010-10-18 17:17:23 -07001938/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001939 * Initiate a lport login.
1940 */
1941void
1942bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001943 wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en, uint8_t bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001944{
1945 lps->uarg = uarg;
1946 lps->alpa = alpa;
1947 lps->pdusz = pdusz;
1948 lps->pwwn = pwwn;
1949 lps->nwwn = nwwn;
1950 lps->fdisc = BFA_FALSE;
1951 lps->auth_en = auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001952 lps->bb_scn = bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001953 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1954}
1955
Jing Huang5fbe25c2010-10-18 17:17:23 -07001956/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001957 * Initiate a lport fdisc login.
1958 */
1959void
1960bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
1961 wwn_t nwwn)
1962{
1963 lps->uarg = uarg;
1964 lps->alpa = 0;
1965 lps->pdusz = pdusz;
1966 lps->pwwn = pwwn;
1967 lps->nwwn = nwwn;
1968 lps->fdisc = BFA_TRUE;
1969 lps->auth_en = BFA_FALSE;
1970 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1971}
1972
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001973
Jing Huang5fbe25c2010-10-18 17:17:23 -07001974/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001975 * Initiate a lport FDSIC logout.
1976 */
1977void
1978bfa_lps_fdisclogo(struct bfa_lps_s *lps)
1979{
1980 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
1981}
1982
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001983u8
1984bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag)
1985{
1986 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1987
1988 return BFA_LPS_FROM_TAG(mod, lp_tag)->fw_tag;
1989}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001990
Jing Huang5fbe25c2010-10-18 17:17:23 -07001991/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001992 * Return lport services tag given the pid
1993 */
1994u8
1995bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
1996{
1997 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1998 struct bfa_lps_s *lps;
1999 int i;
2000
2001 for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
2002 if (lps->lp_pid == pid)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002003 return lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002004 }
2005
2006 /* Return base port tag anyway */
2007 return 0;
2008}
2009
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002010
Jing Huang5fbe25c2010-10-18 17:17:23 -07002011/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002012 * return port id assigned to the base lport
2013 */
2014u32
2015bfa_lps_get_base_pid(struct bfa_s *bfa)
2016{
2017 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
2018
2019 return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
2020}
2021
Jing Huang8f4bfad2010-12-26 21:50:10 -08002022/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08002023 * Set PID in case of n2n (which is assigned during PLOGI)
2024 */
2025void
2026bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
2027{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002028 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08002029 bfa_trc(lps->bfa, n2n_pid);
2030
2031 lps->lp_pid = n2n_pid;
2032 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
2033}
2034
Jing Huang5fbe25c2010-10-18 17:17:23 -07002035/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002036 * LPS firmware message class handler.
2037 */
2038void
2039bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2040{
2041 union bfi_lps_i2h_msg_u msg;
2042
2043 bfa_trc(bfa, m->mhdr.msg_id);
2044 msg.msg = m;
2045
2046 switch (m->mhdr.msg_id) {
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002047 case BFI_LPS_I2H_LOGIN_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002048 bfa_lps_login_rsp(bfa, msg.login_rsp);
2049 break;
2050
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002051 case BFI_LPS_I2H_LOGOUT_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002052 bfa_lps_logout_rsp(bfa, msg.logout_rsp);
2053 break;
2054
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002055 case BFI_LPS_I2H_CVL_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002056 bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
2057 break;
2058
2059 default:
2060 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08002061 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002062 }
2063}
2064
Krishna Gudipati7826f302011-07-20 16:59:13 -07002065static void
2066bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
2067{
2068 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2069 struct bfa_aen_entry_s *aen_entry;
2070
2071 bfad_get_aen_entry(bfad, aen_entry);
2072 if (!aen_entry)
2073 return;
2074
2075 aen_entry->aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
2076 aen_entry->aen_data.port.pwwn = fcport->pwwn;
2077
2078 /* Send the AEN notification */
2079 bfad_im_post_vendor_event(aen_entry, bfad, ++fcport->bfa->bfa_aen_seq,
2080 BFA_AEN_CAT_PORT, event);
2081}
2082
Jing Huang5fbe25c2010-10-18 17:17:23 -07002083/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002084 * FC PORT state machine functions
2085 */
2086static void
2087bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
2088 enum bfa_fcport_sm_event event)
2089{
2090 bfa_trc(fcport->bfa, event);
2091
2092 switch (event) {
2093 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002094 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002095 * Start event after IOC is configured and BFA is started.
2096 */
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08002097 fcport->use_flash_cfg = BFA_TRUE;
2098
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002099 if (bfa_fcport_send_enable(fcport)) {
2100 bfa_trc(fcport->bfa, BFA_TRUE);
2101 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2102 } else {
2103 bfa_trc(fcport->bfa, BFA_FALSE);
2104 bfa_sm_set_state(fcport,
2105 bfa_fcport_sm_enabling_qwait);
2106 }
2107 break;
2108
2109 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002110 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002111 * Port is persistently configured to be in enabled state. Do
2112 * not change state. Port enabling is done when START event is
2113 * received.
2114 */
2115 break;
2116
2117 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002118 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002119 * If a port is persistently configured to be disabled, the
2120 * first event will a port disable request.
2121 */
2122 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2123 break;
2124
2125 case BFA_FCPORT_SM_HWFAIL:
2126 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2127 break;
2128
2129 default:
2130 bfa_sm_fault(fcport->bfa, event);
2131 }
2132}
2133
2134static void
2135bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
2136 enum bfa_fcport_sm_event event)
2137{
2138 char pwwn_buf[BFA_STRING_32];
2139 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2140 bfa_trc(fcport->bfa, event);
2141
2142 switch (event) {
2143 case BFA_FCPORT_SM_QRESUME:
2144 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2145 bfa_fcport_send_enable(fcport);
2146 break;
2147
2148 case BFA_FCPORT_SM_STOP:
2149 bfa_reqq_wcancel(&fcport->reqq_wait);
2150 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2151 break;
2152
2153 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002154 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002155 * Already enable is in progress.
2156 */
2157 break;
2158
2159 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002160 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002161 * Just send disable request to firmware when room becomes
2162 * available in request queue.
2163 */
2164 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2165 bfa_reqq_wcancel(&fcport->reqq_wait);
2166 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2167 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2168 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002169 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002170 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002171 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002172 break;
2173
2174 case BFA_FCPORT_SM_LINKUP:
2175 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002176 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002177 * Possible to get link events when doing back-to-back
2178 * enable/disables.
2179 */
2180 break;
2181
2182 case BFA_FCPORT_SM_HWFAIL:
2183 bfa_reqq_wcancel(&fcport->reqq_wait);
2184 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2185 break;
2186
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002187 case BFA_FCPORT_SM_FAA_MISCONFIG:
2188 bfa_fcport_reset_linkinfo(fcport);
2189 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2190 bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
2191 break;
2192
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002193 default:
2194 bfa_sm_fault(fcport->bfa, event);
2195 }
2196}
2197
2198static void
2199bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
2200 enum bfa_fcport_sm_event event)
2201{
2202 char pwwn_buf[BFA_STRING_32];
2203 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2204 bfa_trc(fcport->bfa, event);
2205
2206 switch (event) {
2207 case BFA_FCPORT_SM_FWRSP:
2208 case BFA_FCPORT_SM_LINKDOWN:
2209 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2210 break;
2211
2212 case BFA_FCPORT_SM_LINKUP:
2213 bfa_fcport_update_linkinfo(fcport);
2214 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
2215
Jing Huangd4b671c2010-12-26 21:46:35 -08002216 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002217 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2218 break;
2219
2220 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002221 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002222 * Already being enabled.
2223 */
2224 break;
2225
2226 case BFA_FCPORT_SM_DISABLE:
2227 if (bfa_fcport_send_disable(fcport))
2228 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2229 else
2230 bfa_sm_set_state(fcport,
2231 bfa_fcport_sm_disabling_qwait);
2232
2233 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2234 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2235 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002236 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002237 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002238 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002239 break;
2240
2241 case BFA_FCPORT_SM_STOP:
2242 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2243 break;
2244
2245 case BFA_FCPORT_SM_HWFAIL:
2246 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2247 break;
2248
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002249 case BFA_FCPORT_SM_FAA_MISCONFIG:
2250 bfa_fcport_reset_linkinfo(fcport);
2251 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2252 bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
2253 break;
2254
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002255 default:
2256 bfa_sm_fault(fcport->bfa, event);
2257 }
2258}
2259
2260static void
2261bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
2262 enum bfa_fcport_sm_event event)
2263{
2264 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2265 char pwwn_buf[BFA_STRING_32];
2266 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2267
2268 bfa_trc(fcport->bfa, event);
2269
2270 switch (event) {
2271 case BFA_FCPORT_SM_LINKUP:
2272 bfa_fcport_update_linkinfo(fcport);
2273 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
Jing Huangd4b671c2010-12-26 21:46:35 -08002274 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002275 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2276 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
2277 if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
2278
2279 bfa_trc(fcport->bfa,
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002280 pevent->link_state.attr.vc_fcf.fcf.fipenabled);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002281 bfa_trc(fcport->bfa,
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002282 pevent->link_state.attr.vc_fcf.fcf.fipfailed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002283
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002284 if (pevent->link_state.attr.vc_fcf.fcf.fipfailed)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002285 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2286 BFA_PL_EID_FIP_FCF_DISC, 0,
2287 "FIP FCF Discovery Failed");
2288 else
2289 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2290 BFA_PL_EID_FIP_FCF_DISC, 0,
2291 "FIP FCF Discovered");
2292 }
2293
2294 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2295 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002296 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002297 "Base port online: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002298 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002299
2300 /* If QoS is enabled and it is not online, send AEN */
2301 if (fcport->cfg.qos_enabled &&
2302 fcport->qos_attr.state != BFA_QOS_ONLINE)
2303 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002304 break;
2305
2306 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002307 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002308 * Possible to get link down event.
2309 */
2310 break;
2311
2312 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002313 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002314 * Already enabled.
2315 */
2316 break;
2317
2318 case BFA_FCPORT_SM_DISABLE:
2319 if (bfa_fcport_send_disable(fcport))
2320 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2321 else
2322 bfa_sm_set_state(fcport,
2323 bfa_fcport_sm_disabling_qwait);
2324
2325 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2326 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2327 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002328 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002329 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002330 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002331 break;
2332
2333 case BFA_FCPORT_SM_STOP:
2334 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2335 break;
2336
2337 case BFA_FCPORT_SM_HWFAIL:
2338 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2339 break;
2340
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002341 case BFA_FCPORT_SM_FAA_MISCONFIG:
2342 bfa_fcport_reset_linkinfo(fcport);
2343 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2344 bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
2345 break;
2346
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002347 default:
2348 bfa_sm_fault(fcport->bfa, event);
2349 }
2350}
2351
2352static void
2353bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
2354 enum bfa_fcport_sm_event event)
2355{
2356 char pwwn_buf[BFA_STRING_32];
2357 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2358
2359 bfa_trc(fcport->bfa, event);
2360
2361 switch (event) {
2362 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002363 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002364 * Already enabled.
2365 */
2366 break;
2367
2368 case BFA_FCPORT_SM_DISABLE:
2369 if (bfa_fcport_send_disable(fcport))
2370 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2371 else
2372 bfa_sm_set_state(fcport,
2373 bfa_fcport_sm_disabling_qwait);
2374
2375 bfa_fcport_reset_linkinfo(fcport);
2376 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2377 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2378 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2379 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002380 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002381 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002382 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
Jing Huang88166242010-12-09 17:11:53 -08002383 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002384 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002385 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002386 break;
2387
2388 case BFA_FCPORT_SM_LINKDOWN:
2389 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2390 bfa_fcport_reset_linkinfo(fcport);
2391 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2392 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2393 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
2394 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002395 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002396 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002397 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002398 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2399 } else {
Jing Huang88166242010-12-09 17:11:53 -08002400 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002401 "Base port (WWN = %s) "
2402 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002403 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2404 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002405 break;
2406
2407 case BFA_FCPORT_SM_STOP:
2408 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2409 bfa_fcport_reset_linkinfo(fcport);
2410 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002411 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002412 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002413 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002414 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2415 } else {
Jing Huang88166242010-12-09 17:11:53 -08002416 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002417 "Base port (WWN = %s) "
2418 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002419 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2420 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002421 break;
2422
2423 case BFA_FCPORT_SM_HWFAIL:
2424 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2425 bfa_fcport_reset_linkinfo(fcport);
2426 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2427 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002428 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002429 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002430 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002431 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2432 } else {
Jing Huang88166242010-12-09 17:11:53 -08002433 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002434 "Base port (WWN = %s) "
2435 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002436 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2437 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002438 break;
2439
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002440 case BFA_FCPORT_SM_FAA_MISCONFIG:
2441 bfa_fcport_reset_linkinfo(fcport);
2442 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2443 bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
2444 break;
2445
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002446 default:
2447 bfa_sm_fault(fcport->bfa, event);
2448 }
2449}
2450
2451static void
2452bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
2453 enum bfa_fcport_sm_event event)
2454{
2455 bfa_trc(fcport->bfa, event);
2456
2457 switch (event) {
2458 case BFA_FCPORT_SM_QRESUME:
2459 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2460 bfa_fcport_send_disable(fcport);
2461 break;
2462
2463 case BFA_FCPORT_SM_STOP:
2464 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2465 bfa_reqq_wcancel(&fcport->reqq_wait);
2466 break;
2467
2468 case BFA_FCPORT_SM_ENABLE:
2469 bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
2470 break;
2471
2472 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002473 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002474 * Already being disabled.
2475 */
2476 break;
2477
2478 case BFA_FCPORT_SM_LINKUP:
2479 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002480 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002481 * Possible to get link events when doing back-to-back
2482 * enable/disables.
2483 */
2484 break;
2485
2486 case BFA_FCPORT_SM_HWFAIL:
2487 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2488 bfa_reqq_wcancel(&fcport->reqq_wait);
2489 break;
2490
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002491 case BFA_FCPORT_SM_FAA_MISCONFIG:
2492 bfa_fcport_reset_linkinfo(fcport);
2493 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2494 bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
2495 break;
2496
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002497 default:
2498 bfa_sm_fault(fcport->bfa, event);
2499 }
2500}
2501
2502static void
2503bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
2504 enum bfa_fcport_sm_event event)
2505{
2506 bfa_trc(fcport->bfa, event);
2507
2508 switch (event) {
2509 case BFA_FCPORT_SM_QRESUME:
2510 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2511 bfa_fcport_send_disable(fcport);
2512 if (bfa_fcport_send_enable(fcport))
2513 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2514 else
2515 bfa_sm_set_state(fcport,
2516 bfa_fcport_sm_enabling_qwait);
2517 break;
2518
2519 case BFA_FCPORT_SM_STOP:
2520 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2521 bfa_reqq_wcancel(&fcport->reqq_wait);
2522 break;
2523
2524 case BFA_FCPORT_SM_ENABLE:
2525 break;
2526
2527 case BFA_FCPORT_SM_DISABLE:
2528 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
2529 break;
2530
2531 case BFA_FCPORT_SM_LINKUP:
2532 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002533 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002534 * Possible to get link events when doing back-to-back
2535 * enable/disables.
2536 */
2537 break;
2538
2539 case BFA_FCPORT_SM_HWFAIL:
2540 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2541 bfa_reqq_wcancel(&fcport->reqq_wait);
2542 break;
2543
2544 default:
2545 bfa_sm_fault(fcport->bfa, event);
2546 }
2547}
2548
2549static void
2550bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
2551 enum bfa_fcport_sm_event event)
2552{
2553 char pwwn_buf[BFA_STRING_32];
2554 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2555 bfa_trc(fcport->bfa, event);
2556
2557 switch (event) {
2558 case BFA_FCPORT_SM_FWRSP:
2559 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2560 break;
2561
2562 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002563 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002564 * Already being disabled.
2565 */
2566 break;
2567
2568 case BFA_FCPORT_SM_ENABLE:
2569 if (bfa_fcport_send_enable(fcport))
2570 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2571 else
2572 bfa_sm_set_state(fcport,
2573 bfa_fcport_sm_enabling_qwait);
2574
2575 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2576 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2577 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002578 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002579 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002580 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002581 break;
2582
2583 case BFA_FCPORT_SM_STOP:
2584 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2585 break;
2586
2587 case BFA_FCPORT_SM_LINKUP:
2588 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002589 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002590 * Possible to get link events when doing back-to-back
2591 * enable/disables.
2592 */
2593 break;
2594
2595 case BFA_FCPORT_SM_HWFAIL:
2596 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2597 break;
2598
2599 default:
2600 bfa_sm_fault(fcport->bfa, event);
2601 }
2602}
2603
2604static void
2605bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
2606 enum bfa_fcport_sm_event event)
2607{
2608 char pwwn_buf[BFA_STRING_32];
2609 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2610 bfa_trc(fcport->bfa, event);
2611
2612 switch (event) {
2613 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002614 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002615 * Ignore start event for a port that is disabled.
2616 */
2617 break;
2618
2619 case BFA_FCPORT_SM_STOP:
2620 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2621 break;
2622
2623 case BFA_FCPORT_SM_ENABLE:
2624 if (bfa_fcport_send_enable(fcport))
2625 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2626 else
2627 bfa_sm_set_state(fcport,
2628 bfa_fcport_sm_enabling_qwait);
2629
2630 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2631 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2632 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002633 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002634 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002635 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002636 break;
2637
2638 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002639 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002640 * Already disabled.
2641 */
2642 break;
2643
2644 case BFA_FCPORT_SM_HWFAIL:
2645 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2646 break;
2647
Krishna Gudipatie3535462012-09-21 17:26:07 -07002648 case BFA_FCPORT_SM_DPORTENABLE:
2649 bfa_sm_set_state(fcport, bfa_fcport_sm_dport);
2650 break;
2651
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002652 default:
2653 bfa_sm_fault(fcport->bfa, event);
2654 }
2655}
2656
2657static void
2658bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
2659 enum bfa_fcport_sm_event event)
2660{
2661 bfa_trc(fcport->bfa, event);
2662
2663 switch (event) {
2664 case BFA_FCPORT_SM_START:
2665 if (bfa_fcport_send_enable(fcport))
2666 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2667 else
2668 bfa_sm_set_state(fcport,
2669 bfa_fcport_sm_enabling_qwait);
2670 break;
2671
2672 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002673 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002674 * Ignore all other events.
2675 */
2676 ;
2677 }
2678}
2679
Jing Huang5fbe25c2010-10-18 17:17:23 -07002680/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002681 * Port is enabled. IOC is down/failed.
2682 */
2683static void
2684bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
2685 enum bfa_fcport_sm_event event)
2686{
2687 bfa_trc(fcport->bfa, event);
2688
2689 switch (event) {
2690 case BFA_FCPORT_SM_START:
2691 if (bfa_fcport_send_enable(fcport))
2692 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2693 else
2694 bfa_sm_set_state(fcport,
2695 bfa_fcport_sm_enabling_qwait);
2696 break;
2697
2698 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002699 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002700 * Ignore all events.
2701 */
2702 ;
2703 }
2704}
2705
Jing Huang5fbe25c2010-10-18 17:17:23 -07002706/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002707 * Port is disabled. IOC is down/failed.
2708 */
2709static void
2710bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
2711 enum bfa_fcport_sm_event event)
2712{
2713 bfa_trc(fcport->bfa, event);
2714
2715 switch (event) {
2716 case BFA_FCPORT_SM_START:
2717 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2718 break;
2719
2720 case BFA_FCPORT_SM_ENABLE:
2721 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2722 break;
2723
2724 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002725 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002726 * Ignore all events.
2727 */
2728 ;
2729 }
2730}
2731
Krishna Gudipatie3535462012-09-21 17:26:07 -07002732static void
2733bfa_fcport_sm_dport(struct bfa_fcport_s *fcport, enum bfa_fcport_sm_event event)
2734{
2735 bfa_trc(fcport->bfa, event);
2736
2737 switch (event) {
2738 case BFA_FCPORT_SM_DPORTENABLE:
2739 case BFA_FCPORT_SM_DISABLE:
2740 case BFA_FCPORT_SM_ENABLE:
2741 case BFA_FCPORT_SM_START:
2742 /*
2743 * Ignore event for a port that is dport
2744 */
2745 break;
2746
2747 case BFA_FCPORT_SM_STOP:
2748 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2749 break;
2750
2751 case BFA_FCPORT_SM_HWFAIL:
2752 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2753 break;
2754
2755 case BFA_FCPORT_SM_DPORTDISABLE:
2756 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2757 break;
2758
2759 default:
2760 bfa_sm_fault(fcport->bfa, event);
2761 }
2762}
2763
Krishna Gudipati04ea6572012-09-21 17:26:18 -07002764static void
2765bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s *fcport,
2766 enum bfa_fcport_sm_event event)
2767{
2768 bfa_trc(fcport->bfa, event);
2769
2770 switch (event) {
2771 case BFA_FCPORT_SM_DPORTENABLE:
2772 case BFA_FCPORT_SM_ENABLE:
2773 case BFA_FCPORT_SM_START:
2774 /*
2775 * Ignore event for a port as there is FAA misconfig
2776 */
2777 break;
2778
2779 case BFA_FCPORT_SM_DISABLE:
2780 if (bfa_fcport_send_disable(fcport))
2781 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2782 else
2783 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
2784
2785 bfa_fcport_reset_linkinfo(fcport);
2786 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2787 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2788 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2789 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
2790 break;
2791
2792 case BFA_FCPORT_SM_STOP:
2793 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2794 break;
2795
2796 case BFA_FCPORT_SM_HWFAIL:
2797 bfa_fcport_reset_linkinfo(fcport);
2798 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2799 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2800 break;
2801
2802 default:
2803 bfa_sm_fault(fcport->bfa, event);
2804 }
2805}
2806
Jing Huang5fbe25c2010-10-18 17:17:23 -07002807/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002808 * Link state is down
2809 */
2810static void
2811bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
2812 enum bfa_fcport_ln_sm_event event)
2813{
2814 bfa_trc(ln->fcport->bfa, event);
2815
2816 switch (event) {
2817 case BFA_FCPORT_LN_SM_LINKUP:
2818 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2819 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2820 break;
2821
2822 default:
2823 bfa_sm_fault(ln->fcport->bfa, event);
2824 }
2825}
2826
Jing Huang5fbe25c2010-10-18 17:17:23 -07002827/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002828 * Link state is waiting for down notification
2829 */
2830static void
2831bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
2832 enum bfa_fcport_ln_sm_event event)
2833{
2834 bfa_trc(ln->fcport->bfa, event);
2835
2836 switch (event) {
2837 case BFA_FCPORT_LN_SM_LINKUP:
2838 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2839 break;
2840
2841 case BFA_FCPORT_LN_SM_NOTIFICATION:
2842 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2843 break;
2844
2845 default:
2846 bfa_sm_fault(ln->fcport->bfa, event);
2847 }
2848}
2849
Jing Huang5fbe25c2010-10-18 17:17:23 -07002850/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002851 * Link state is waiting for down notification and there is a pending up
2852 */
2853static void
2854bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
2855 enum bfa_fcport_ln_sm_event event)
2856{
2857 bfa_trc(ln->fcport->bfa, event);
2858
2859 switch (event) {
2860 case BFA_FCPORT_LN_SM_LINKDOWN:
2861 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2862 break;
2863
2864 case BFA_FCPORT_LN_SM_NOTIFICATION:
2865 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2866 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2867 break;
2868
2869 default:
2870 bfa_sm_fault(ln->fcport->bfa, event);
2871 }
2872}
2873
Jing Huang5fbe25c2010-10-18 17:17:23 -07002874/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002875 * Link state is up
2876 */
2877static void
2878bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
2879 enum bfa_fcport_ln_sm_event event)
2880{
2881 bfa_trc(ln->fcport->bfa, event);
2882
2883 switch (event) {
2884 case BFA_FCPORT_LN_SM_LINKDOWN:
2885 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2886 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2887 break;
2888
2889 default:
2890 bfa_sm_fault(ln->fcport->bfa, event);
2891 }
2892}
2893
Jing Huang5fbe25c2010-10-18 17:17:23 -07002894/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002895 * Link state is waiting for up notification
2896 */
2897static void
2898bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
2899 enum bfa_fcport_ln_sm_event event)
2900{
2901 bfa_trc(ln->fcport->bfa, event);
2902
2903 switch (event) {
2904 case BFA_FCPORT_LN_SM_LINKDOWN:
2905 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2906 break;
2907
2908 case BFA_FCPORT_LN_SM_NOTIFICATION:
2909 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
2910 break;
2911
2912 default:
2913 bfa_sm_fault(ln->fcport->bfa, event);
2914 }
2915}
2916
Jing Huang5fbe25c2010-10-18 17:17:23 -07002917/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002918 * Link state is waiting for up notification and there is a pending down
2919 */
2920static void
2921bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
2922 enum bfa_fcport_ln_sm_event event)
2923{
2924 bfa_trc(ln->fcport->bfa, event);
2925
2926 switch (event) {
2927 case BFA_FCPORT_LN_SM_LINKUP:
2928 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
2929 break;
2930
2931 case BFA_FCPORT_LN_SM_NOTIFICATION:
2932 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2933 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2934 break;
2935
2936 default:
2937 bfa_sm_fault(ln->fcport->bfa, event);
2938 }
2939}
2940
Jing Huang5fbe25c2010-10-18 17:17:23 -07002941/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002942 * Link state is waiting for up notification and there are pending down and up
2943 */
2944static void
2945bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
2946 enum bfa_fcport_ln_sm_event event)
2947{
2948 bfa_trc(ln->fcport->bfa, event);
2949
2950 switch (event) {
2951 case BFA_FCPORT_LN_SM_LINKDOWN:
2952 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2953 break;
2954
2955 case BFA_FCPORT_LN_SM_NOTIFICATION:
2956 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2957 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2958 break;
2959
2960 default:
2961 bfa_sm_fault(ln->fcport->bfa, event);
2962 }
2963}
2964
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002965static void
2966__bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
2967{
2968 struct bfa_fcport_ln_s *ln = cbarg;
2969
2970 if (complete)
2971 ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
2972 else
2973 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2974}
2975
Jing Huang5fbe25c2010-10-18 17:17:23 -07002976/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002977 * Send SCN notification to upper layers.
2978 * trunk - false if caller is fcport to ignore fcport event in trunked mode
2979 */
2980static void
2981bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
2982 bfa_boolean_t trunk)
2983{
2984 if (fcport->cfg.trunked && !trunk)
2985 return;
2986
2987 switch (event) {
2988 case BFA_PORT_LINKUP:
2989 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
2990 break;
2991 case BFA_PORT_LINKDOWN:
2992 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
2993 break;
2994 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08002995 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002996 }
2997}
2998
2999static void
3000bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
3001{
3002 struct bfa_fcport_s *fcport = ln->fcport;
3003
3004 if (fcport->bfa->fcs) {
3005 fcport->event_cbfn(fcport->event_cbarg, event);
3006 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
3007 } else {
3008 ln->ln_event = event;
3009 bfa_cb_queue(fcport->bfa, &ln->ln_qe,
3010 __bfa_cb_fcport_event, ln);
3011 }
3012}
3013
3014#define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
3015 BFA_CACHELINE_SZ))
3016
3017static void
Krishna Gudipati45070252011-06-24 20:24:29 -07003018bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
3019 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003020{
Krishna Gudipati45070252011-06-24 20:24:29 -07003021 struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa);
3022
3023 bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003024}
3025
3026static void
3027bfa_fcport_qresume(void *cbarg)
3028{
3029 struct bfa_fcport_s *fcport = cbarg;
3030
3031 bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
3032}
3033
3034static void
Krishna Gudipati45070252011-06-24 20:24:29 -07003035bfa_fcport_mem_claim(struct bfa_fcport_s *fcport)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003036{
Krishna Gudipati45070252011-06-24 20:24:29 -07003037 struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003038
Krishna Gudipati45070252011-06-24 20:24:29 -07003039 fcport->stats_kva = bfa_mem_dma_virt(fcport_dma);
3040 fcport->stats_pa = bfa_mem_dma_phys(fcport_dma);
3041 fcport->stats = (union bfa_fcport_stats_u *)
3042 bfa_mem_dma_virt(fcport_dma);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003043}
3044
Jing Huang5fbe25c2010-10-18 17:17:23 -07003045/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003046 * Memory initialization.
3047 */
3048static void
3049bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07003050 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003051{
3052 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3053 struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
3054 struct bfa_fcport_ln_s *ln = &fcport->ln;
Maggie Zhangf16a1752010-12-09 19:12:32 -08003055 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003056
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003057 fcport->bfa = bfa;
3058 ln->fcport = fcport;
3059
Krishna Gudipati45070252011-06-24 20:24:29 -07003060 bfa_fcport_mem_claim(fcport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003061
3062 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
3063 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
3064
Jing Huang5fbe25c2010-10-18 17:17:23 -07003065 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003066 * initialize time stamp for stats reset
3067 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08003068 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003069 fcport->stats_reset_time = tv.tv_sec;
3070
Jing Huang5fbe25c2010-10-18 17:17:23 -07003071 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003072 * initialize and set default configuration
3073 */
3074 port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
3075 port_cfg->speed = BFA_PORT_SPEED_AUTO;
3076 port_cfg->trunked = BFA_FALSE;
3077 port_cfg->maxfrsize = 0;
3078
3079 port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
3080
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003081 INIT_LIST_HEAD(&fcport->stats_pending_q);
3082 INIT_LIST_HEAD(&fcport->statsclr_pending_q);
3083
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003084 bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
3085}
3086
3087static void
3088bfa_fcport_detach(struct bfa_s *bfa)
3089{
3090}
3091
Jing Huang5fbe25c2010-10-18 17:17:23 -07003092/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003093 * Called when IOC is ready.
3094 */
3095static void
3096bfa_fcport_start(struct bfa_s *bfa)
3097{
3098 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
3099}
3100
Jing Huang5fbe25c2010-10-18 17:17:23 -07003101/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003102 * Called before IOC is stopped.
3103 */
3104static void
3105bfa_fcport_stop(struct bfa_s *bfa)
3106{
3107 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
3108 bfa_trunk_iocdisable(bfa);
3109}
3110
Jing Huang5fbe25c2010-10-18 17:17:23 -07003111/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003112 * Called when IOC failure is detected.
3113 */
3114static void
3115bfa_fcport_iocdisable(struct bfa_s *bfa)
3116{
3117 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3118
3119 bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
3120 bfa_trunk_iocdisable(bfa);
3121}
3122
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003123/*
3124 * Update loop info in fcport for SCN online
3125 */
3126static void
3127bfa_fcport_update_loop_info(struct bfa_fcport_s *fcport,
3128 struct bfa_fcport_loop_info_s *loop_info)
3129{
3130 fcport->myalpa = loop_info->myalpa;
3131 fcport->alpabm_valid =
3132 loop_info->alpabm_val;
3133 memcpy(fcport->alpabm.alpa_bm,
3134 loop_info->alpabm.alpa_bm,
3135 sizeof(struct fc_alpabm_s));
3136}
3137
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003138static void
3139bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
3140{
3141 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
3142 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3143
3144 fcport->speed = pevent->link_state.speed;
3145 fcport->topology = pevent->link_state.topology;
3146
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003147 if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP) {
3148 bfa_fcport_update_loop_info(fcport,
3149 &pevent->link_state.attr.loop_info);
3150 return;
3151 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003152
3153 /* QoS Details */
Jing Huang6a18b162010-10-18 17:08:54 -07003154 fcport->qos_attr = pevent->link_state.qos_attr;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003155 fcport->qos_vc_attr = pevent->link_state.attr.vc_fcf.qos_vc_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003156
Jing Huang5fbe25c2010-10-18 17:17:23 -07003157 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003158 * update trunk state if applicable
3159 */
3160 if (!fcport->cfg.trunked)
3161 trunk->attr.state = BFA_TRUNK_DISABLED;
3162
3163 /* update FCoE specific */
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003164 fcport->fcoe_vlan =
3165 be16_to_cpu(pevent->link_state.attr.vc_fcf.fcf.vlan);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003166
3167 bfa_trc(fcport->bfa, fcport->speed);
3168 bfa_trc(fcport->bfa, fcport->topology);
3169}
3170
3171static void
3172bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
3173{
3174 fcport->speed = BFA_PORT_SPEED_UNKNOWN;
3175 fcport->topology = BFA_PORT_TOPOLOGY_NONE;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003176 fcport->bbsc_op_state = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003177}
3178
Jing Huang5fbe25c2010-10-18 17:17:23 -07003179/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003180 * Send port enable message to firmware.
3181 */
3182static bfa_boolean_t
3183bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
3184{
3185 struct bfi_fcport_enable_req_s *m;
3186
Jing Huang5fbe25c2010-10-18 17:17:23 -07003187 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003188 * Increment message tag before queue check, so that responses to old
3189 * requests are discarded.
3190 */
3191 fcport->msgtag++;
3192
Jing Huang5fbe25c2010-10-18 17:17:23 -07003193 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003194 * check for room in queue to send request now
3195 */
3196 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3197 if (!m) {
3198 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3199 &fcport->reqq_wait);
3200 return BFA_FALSE;
3201 }
3202
3203 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003204 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003205 m->nwwn = fcport->nwwn;
3206 m->pwwn = fcport->pwwn;
3207 m->port_cfg = fcport->cfg;
3208 m->msgtag = fcport->msgtag;
Jing Huangba816ea2010-10-18 17:10:50 -07003209 m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003210 m->use_flash_cfg = fcport->use_flash_cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003211 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
3212 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
3213 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
3214
Jing Huang5fbe25c2010-10-18 17:17:23 -07003215 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003216 * queue I/O message to firmware
3217 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003218 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003219 return BFA_TRUE;
3220}
3221
Jing Huang5fbe25c2010-10-18 17:17:23 -07003222/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003223 * Send port disable message to firmware.
3224 */
3225static bfa_boolean_t
3226bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
3227{
3228 struct bfi_fcport_req_s *m;
3229
Jing Huang5fbe25c2010-10-18 17:17:23 -07003230 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003231 * Increment message tag before queue check, so that responses to old
3232 * requests are discarded.
3233 */
3234 fcport->msgtag++;
3235
Jing Huang5fbe25c2010-10-18 17:17:23 -07003236 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003237 * check for room in queue to send request now
3238 */
3239 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3240 if (!m) {
3241 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3242 &fcport->reqq_wait);
3243 return BFA_FALSE;
3244 }
3245
3246 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003247 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003248 m->msgtag = fcport->msgtag;
3249
Jing Huang5fbe25c2010-10-18 17:17:23 -07003250 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003251 * queue I/O message to firmware
3252 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003253 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003254
3255 return BFA_TRUE;
3256}
3257
3258static void
3259bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
3260{
Maggie Zhangf7f738122010-12-09 19:08:43 -08003261 fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
3262 fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003263
3264 bfa_trc(fcport->bfa, fcport->pwwn);
3265 bfa_trc(fcport->bfa, fcport->nwwn);
3266}
3267
3268static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003269bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
3270 struct bfa_qos_stats_s *s)
3271{
3272 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003273 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003274 int i;
3275
3276 /* Now swap the 32 bit fields */
3277 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
Jing Huangba816ea2010-10-18 17:10:50 -07003278 dip[i] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003279}
3280
3281static void
3282bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
3283 struct bfa_fcoe_stats_s *s)
3284{
3285 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003286 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003287 int i;
3288
3289 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
3290 i = i + 2) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003291#ifdef __BIG_ENDIAN
Jing Huangba816ea2010-10-18 17:10:50 -07003292 dip[i] = be32_to_cpu(sip[i]);
3293 dip[i + 1] = be32_to_cpu(sip[i + 1]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003294#else
Jing Huangba816ea2010-10-18 17:10:50 -07003295 dip[i] = be32_to_cpu(sip[i + 1]);
3296 dip[i + 1] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003297#endif
3298 }
3299}
3300
3301static void
3302__bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
3303{
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003304 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *)cbarg;
3305 struct bfa_cb_pending_q_s *cb;
3306 struct list_head *qe, *qen;
3307 union bfa_fcport_stats_u *ret;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003308
3309 if (complete) {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003310 struct timeval tv;
3311 if (fcport->stats_status == BFA_STATUS_OK)
3312 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003313
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003314 list_for_each_safe(qe, qen, &fcport->stats_pending_q) {
3315 bfa_q_deq(&fcport->stats_pending_q, &qe);
3316 cb = (struct bfa_cb_pending_q_s *)qe;
3317 if (fcport->stats_status == BFA_STATUS_OK) {
3318 ret = (union bfa_fcport_stats_u *)cb->data;
3319 /* Swap FC QoS or FCoE stats */
3320 if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
3321 bfa_fcport_qos_stats_swap(&ret->fcqos,
3322 &fcport->stats->fcqos);
3323 else {
3324 bfa_fcport_fcoe_stats_swap(&ret->fcoe,
3325 &fcport->stats->fcoe);
3326 ret->fcoe.secs_reset =
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003327 tv.tv_sec - fcport->stats_reset_time;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003328 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003329 }
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003330 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
3331 fcport->stats_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003332 }
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003333 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003334 } else {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003335 INIT_LIST_HEAD(&fcport->stats_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003336 fcport->stats_status = BFA_STATUS_OK;
3337 }
3338}
3339
3340static void
3341bfa_fcport_stats_get_timeout(void *cbarg)
3342{
3343 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3344
3345 bfa_trc(fcport->bfa, fcport->stats_qfull);
3346
3347 if (fcport->stats_qfull) {
3348 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3349 fcport->stats_qfull = BFA_FALSE;
3350 }
3351
3352 fcport->stats_status = BFA_STATUS_ETIMER;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003353 __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003354}
3355
3356static void
3357bfa_fcport_send_stats_get(void *cbarg)
3358{
3359 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3360 struct bfi_fcport_req_s *msg;
3361
3362 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3363
3364 if (!msg) {
3365 fcport->stats_qfull = BFA_TRUE;
3366 bfa_reqq_winit(&fcport->stats_reqq_wait,
3367 bfa_fcport_send_stats_get, fcport);
3368 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3369 &fcport->stats_reqq_wait);
3370 return;
3371 }
3372 fcport->stats_qfull = BFA_FALSE;
3373
Jing Huang6a18b162010-10-18 17:08:54 -07003374 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003375 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003376 bfa_fn_lpu(fcport->bfa));
3377 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003378}
3379
3380static void
3381__bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
3382{
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003383 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3384 struct bfa_cb_pending_q_s *cb;
3385 struct list_head *qe, *qen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003386
3387 if (complete) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003388 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003389
Jing Huang5fbe25c2010-10-18 17:17:23 -07003390 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003391 * re-initialize time stamp for stats reset
3392 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08003393 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003394 fcport->stats_reset_time = tv.tv_sec;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003395 list_for_each_safe(qe, qen, &fcport->statsclr_pending_q) {
3396 bfa_q_deq(&fcport->statsclr_pending_q, &qe);
3397 cb = (struct bfa_cb_pending_q_s *)qe;
3398 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
3399 fcport->stats_status);
3400 }
3401 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003402 } else {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003403 INIT_LIST_HEAD(&fcport->statsclr_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003404 fcport->stats_status = BFA_STATUS_OK;
3405 }
3406}
3407
3408static void
3409bfa_fcport_stats_clr_timeout(void *cbarg)
3410{
3411 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3412
3413 bfa_trc(fcport->bfa, fcport->stats_qfull);
3414
3415 if (fcport->stats_qfull) {
3416 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3417 fcport->stats_qfull = BFA_FALSE;
3418 }
3419
3420 fcport->stats_status = BFA_STATUS_ETIMER;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003421 __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003422}
3423
3424static void
3425bfa_fcport_send_stats_clear(void *cbarg)
3426{
3427 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3428 struct bfi_fcport_req_s *msg;
3429
3430 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3431
3432 if (!msg) {
3433 fcport->stats_qfull = BFA_TRUE;
3434 bfa_reqq_winit(&fcport->stats_reqq_wait,
3435 bfa_fcport_send_stats_clear, fcport);
3436 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3437 &fcport->stats_reqq_wait);
3438 return;
3439 }
3440 fcport->stats_qfull = BFA_FALSE;
3441
Jing Huang6a18b162010-10-18 17:08:54 -07003442 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003443 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003444 bfa_fn_lpu(fcport->bfa));
3445 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003446}
3447
Jing Huang5fbe25c2010-10-18 17:17:23 -07003448/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003449 * Handle trunk SCN event from firmware.
3450 */
3451static void
3452bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3453{
3454 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3455 struct bfi_fcport_trunk_link_s *tlink;
3456 struct bfa_trunk_link_attr_s *lattr;
3457 enum bfa_trunk_state state_prev;
3458 int i;
3459 int link_bm = 0;
3460
3461 bfa_trc(fcport->bfa, fcport->cfg.trunked);
Jing Huangd4b671c2010-12-26 21:46:35 -08003462 WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
3463 scn->trunk_state != BFA_TRUNK_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003464
3465 bfa_trc(fcport->bfa, trunk->attr.state);
3466 bfa_trc(fcport->bfa, scn->trunk_state);
3467 bfa_trc(fcport->bfa, scn->trunk_speed);
3468
Jing Huang5fbe25c2010-10-18 17:17:23 -07003469 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003470 * Save off new state for trunk attribute query
3471 */
3472 state_prev = trunk->attr.state;
3473 if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
3474 trunk->attr.state = scn->trunk_state;
3475 trunk->attr.speed = scn->trunk_speed;
3476 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3477 lattr = &trunk->attr.link_attr[i];
3478 tlink = &scn->tlink[i];
3479
3480 lattr->link_state = tlink->state;
3481 lattr->trunk_wwn = tlink->trunk_wwn;
3482 lattr->fctl = tlink->fctl;
3483 lattr->speed = tlink->speed;
Jing Huangba816ea2010-10-18 17:10:50 -07003484 lattr->deskew = be32_to_cpu(tlink->deskew);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003485
3486 if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
3487 fcport->speed = tlink->speed;
3488 fcport->topology = BFA_PORT_TOPOLOGY_P2P;
3489 link_bm |= 1 << i;
3490 }
3491
3492 bfa_trc(fcport->bfa, lattr->link_state);
3493 bfa_trc(fcport->bfa, lattr->trunk_wwn);
3494 bfa_trc(fcport->bfa, lattr->fctl);
3495 bfa_trc(fcport->bfa, lattr->speed);
3496 bfa_trc(fcport->bfa, lattr->deskew);
3497 }
3498
3499 switch (link_bm) {
3500 case 3:
3501 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3502 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
3503 break;
3504 case 2:
3505 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3506 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
3507 break;
3508 case 1:
3509 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3510 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
3511 break;
3512 default:
3513 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3514 BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
3515 }
3516
Jing Huang5fbe25c2010-10-18 17:17:23 -07003517 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003518 * Notify upper layers if trunk state changed.
3519 */
3520 if ((state_prev != trunk->attr.state) ||
3521 (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
3522 bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
3523 BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
3524 }
3525}
3526
3527static void
3528bfa_trunk_iocdisable(struct bfa_s *bfa)
3529{
3530 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3531 int i = 0;
3532
Jing Huang5fbe25c2010-10-18 17:17:23 -07003533 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003534 * In trunked mode, notify upper layers that link is down
3535 */
3536 if (fcport->cfg.trunked) {
3537 if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
3538 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
3539
3540 fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
3541 fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
3542 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3543 fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
3544 fcport->trunk.attr.link_attr[i].fctl =
3545 BFA_TRUNK_LINK_FCTL_NORMAL;
3546 fcport->trunk.attr.link_attr[i].link_state =
3547 BFA_TRUNK_LINK_STATE_DN_LINKDN;
3548 fcport->trunk.attr.link_attr[i].speed =
3549 BFA_PORT_SPEED_UNKNOWN;
3550 fcport->trunk.attr.link_attr[i].deskew = 0;
3551 }
3552 }
3553}
3554
Jing Huang5fbe25c2010-10-18 17:17:23 -07003555/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003556 * Called to initialize port attributes
3557 */
3558void
3559bfa_fcport_init(struct bfa_s *bfa)
3560{
3561 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3562
Jing Huang5fbe25c2010-10-18 17:17:23 -07003563 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003564 * Initialize port attributes from IOC hardware data.
3565 */
3566 bfa_fcport_set_wwns(fcport);
3567 if (fcport->cfg.maxfrsize == 0)
3568 fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
3569 fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
3570 fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
3571
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003572 if (bfa_fcport_is_pbcdisabled(bfa))
3573 bfa->modules.port.pbc_disabled = BFA_TRUE;
3574
Jing Huangd4b671c2010-12-26 21:46:35 -08003575 WARN_ON(!fcport->cfg.maxfrsize);
3576 WARN_ON(!fcport->cfg.rx_bbcredit);
3577 WARN_ON(!fcport->speed_sup);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003578}
3579
Jing Huang5fbe25c2010-10-18 17:17:23 -07003580/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003581 * Firmware message handler.
3582 */
3583void
3584bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
3585{
3586 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3587 union bfi_fcport_i2h_msg_u i2hmsg;
3588
3589 i2hmsg.msg = msg;
3590 fcport->event_arg.i2hmsg = i2hmsg;
3591
3592 bfa_trc(bfa, msg->mhdr.msg_id);
3593 bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
3594
3595 switch (msg->mhdr.msg_id) {
3596 case BFI_FCPORT_I2H_ENABLE_RSP:
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003597 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
3598
3599 if (fcport->use_flash_cfg) {
3600 fcport->cfg = i2hmsg.penable_rsp->port_cfg;
3601 fcport->cfg.maxfrsize =
3602 cpu_to_be16(fcport->cfg.maxfrsize);
3603 fcport->cfg.path_tov =
3604 cpu_to_be16(fcport->cfg.path_tov);
3605 fcport->cfg.q_depth =
3606 cpu_to_be16(fcport->cfg.q_depth);
3607
3608 if (fcport->cfg.trunked)
3609 fcport->trunk.attr.state =
3610 BFA_TRUNK_OFFLINE;
3611 else
3612 fcport->trunk.attr.state =
3613 BFA_TRUNK_DISABLED;
3614 fcport->use_flash_cfg = BFA_FALSE;
3615 }
3616
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07003617 if (fcport->cfg.qos_enabled)
3618 fcport->qos_attr.state = BFA_QOS_OFFLINE;
3619 else
3620 fcport->qos_attr.state = BFA_QOS_DISABLED;
3621
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003622 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003623 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003624 break;
3625
3626 case BFI_FCPORT_I2H_DISABLE_RSP:
3627 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
3628 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
3629 break;
3630
3631 case BFI_FCPORT_I2H_EVENT:
3632 if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
3633 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
Krishna Gudipati04ea6572012-09-21 17:26:18 -07003634 else {
3635 if (i2hmsg.event->link_state.linkstate_rsn ==
3636 BFA_PORT_LINKSTATE_RSN_FAA_MISCONFIG)
3637 bfa_sm_send_event(fcport,
3638 BFA_FCPORT_SM_FAA_MISCONFIG);
3639 else
3640 bfa_sm_send_event(fcport,
3641 BFA_FCPORT_SM_LINKDOWN);
3642 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003643 break;
3644
3645 case BFI_FCPORT_I2H_TRUNK_SCN:
3646 bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
3647 break;
3648
3649 case BFI_FCPORT_I2H_STATS_GET_RSP:
3650 /*
3651 * check for timer pop before processing the rsp
3652 */
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003653 if (list_empty(&fcport->stats_pending_q) ||
3654 (fcport->stats_status == BFA_STATUS_ETIMER))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003655 break;
3656
3657 bfa_timer_stop(&fcport->timer);
3658 fcport->stats_status = i2hmsg.pstatsget_rsp->status;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003659 __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003660 break;
3661
3662 case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
3663 /*
3664 * check for timer pop before processing the rsp
3665 */
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003666 if (list_empty(&fcport->statsclr_pending_q) ||
3667 (fcport->stats_status == BFA_STATUS_ETIMER))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003668 break;
3669
3670 bfa_timer_stop(&fcport->timer);
3671 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003672 __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003673 break;
3674
3675 case BFI_FCPORT_I2H_ENABLE_AEN:
3676 bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
3677 break;
3678
3679 case BFI_FCPORT_I2H_DISABLE_AEN:
3680 bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
3681 break;
3682
3683 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08003684 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003685 break;
3686 }
3687}
3688
Jing Huang5fbe25c2010-10-18 17:17:23 -07003689/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003690 * Registered callback for port events.
3691 */
3692void
3693bfa_fcport_event_register(struct bfa_s *bfa,
3694 void (*cbfn) (void *cbarg,
3695 enum bfa_port_linkstate event),
3696 void *cbarg)
3697{
3698 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3699
3700 fcport->event_cbfn = cbfn;
3701 fcport->event_cbarg = cbarg;
3702}
3703
3704bfa_status_t
3705bfa_fcport_enable(struct bfa_s *bfa)
3706{
3707 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3708
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003709 if (bfa_fcport_is_pbcdisabled(bfa))
3710 return BFA_STATUS_PBC;
3711
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003712 if (bfa_ioc_is_disabled(&bfa->ioc))
3713 return BFA_STATUS_IOC_DISABLED;
3714
3715 if (fcport->diag_busy)
3716 return BFA_STATUS_DIAG_BUSY;
3717
3718 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
3719 return BFA_STATUS_OK;
3720}
3721
3722bfa_status_t
3723bfa_fcport_disable(struct bfa_s *bfa)
3724{
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003725 if (bfa_fcport_is_pbcdisabled(bfa))
3726 return BFA_STATUS_PBC;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003727
3728 if (bfa_ioc_is_disabled(&bfa->ioc))
3729 return BFA_STATUS_IOC_DISABLED;
3730
3731 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
3732 return BFA_STATUS_OK;
3733}
3734
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003735/* If PBC is disabled on port, return error */
3736bfa_status_t
3737bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
3738{
3739 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3740 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
3741 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
3742
3743 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
3744 bfa_trc(bfa, fcport->pwwn);
3745 return BFA_STATUS_PBC;
3746 }
3747 return BFA_STATUS_OK;
3748}
3749
Jing Huang5fbe25c2010-10-18 17:17:23 -07003750/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003751 * Configure port speed.
3752 */
3753bfa_status_t
3754bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3755{
3756 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3757
3758 bfa_trc(bfa, speed);
3759
3760 if (fcport->cfg.trunked == BFA_TRUE)
3761 return BFA_STATUS_TRUNK_ENABLED;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003762 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
3763 (speed == BFA_PORT_SPEED_16GBPS))
3764 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003765 if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
3766 bfa_trc(bfa, fcport->speed_sup);
3767 return BFA_STATUS_UNSUPP_SPEED;
3768 }
3769
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07003770 /* Port speed entered needs to be checked */
3771 if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
3772 /* For CT2, 1G is not supported */
3773 if ((speed == BFA_PORT_SPEED_1GBPS) &&
3774 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
3775 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia7141342011-06-24 20:23:19 -07003776
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07003777 /* Already checked for Auto Speed and Max Speed supp */
3778 if (!(speed == BFA_PORT_SPEED_1GBPS ||
3779 speed == BFA_PORT_SPEED_2GBPS ||
3780 speed == BFA_PORT_SPEED_4GBPS ||
3781 speed == BFA_PORT_SPEED_8GBPS ||
3782 speed == BFA_PORT_SPEED_16GBPS ||
3783 speed == BFA_PORT_SPEED_AUTO))
3784 return BFA_STATUS_UNSUPP_SPEED;
3785 } else {
3786 if (speed != BFA_PORT_SPEED_10GBPS)
3787 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia7141342011-06-24 20:23:19 -07003788 }
3789
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003790 fcport->cfg.speed = speed;
3791
3792 return BFA_STATUS_OK;
3793}
3794
Jing Huang5fbe25c2010-10-18 17:17:23 -07003795/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003796 * Get current speed.
3797 */
3798enum bfa_port_speed
3799bfa_fcport_get_speed(struct bfa_s *bfa)
3800{
3801 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3802
3803 return fcport->speed;
3804}
3805
Jing Huang5fbe25c2010-10-18 17:17:23 -07003806/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003807 * Configure port topology.
3808 */
3809bfa_status_t
3810bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
3811{
3812 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3813
3814 bfa_trc(bfa, topology);
3815 bfa_trc(bfa, fcport->cfg.topology);
3816
3817 switch (topology) {
3818 case BFA_PORT_TOPOLOGY_P2P:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003819 break;
3820
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003821 case BFA_PORT_TOPOLOGY_LOOP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003822 if ((bfa_fcport_is_qos_enabled(bfa) != BFA_FALSE) ||
3823 (fcport->qos_attr.state != BFA_QOS_DISABLED))
3824 return BFA_STATUS_ERROR_QOS_ENABLED;
3825 if (fcport->cfg.ratelimit != BFA_FALSE)
3826 return BFA_STATUS_ERROR_TRL_ENABLED;
3827 if ((bfa_fcport_is_trunk_enabled(bfa) != BFA_FALSE) ||
3828 (fcport->trunk.attr.state != BFA_TRUNK_DISABLED))
3829 return BFA_STATUS_ERROR_TRUNK_ENABLED;
3830 if ((bfa_fcport_get_speed(bfa) == BFA_PORT_SPEED_16GBPS) ||
3831 (fcport->cfg.speed == BFA_PORT_SPEED_16GBPS))
3832 return BFA_STATUS_UNSUPP_SPEED;
3833 if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type))
3834 return BFA_STATUS_LOOP_UNSUPP_MEZZ;
Krishna Gudipatie3535462012-09-21 17:26:07 -07003835 if (bfa_fcport_is_dport(bfa) != BFA_FALSE)
3836 return BFA_STATUS_DPORT_ERR;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003837 break;
3838
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003839 case BFA_PORT_TOPOLOGY_AUTO:
3840 break;
3841
3842 default:
3843 return BFA_STATUS_EINVAL;
3844 }
3845
3846 fcport->cfg.topology = topology;
3847 return BFA_STATUS_OK;
3848}
3849
Jing Huang5fbe25c2010-10-18 17:17:23 -07003850/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003851 * Get current topology.
3852 */
3853enum bfa_port_topology
3854bfa_fcport_get_topology(struct bfa_s *bfa)
3855{
3856 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3857
3858 return fcport->topology;
3859}
3860
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003861/**
3862 * Get config topology.
3863 */
3864enum bfa_port_topology
3865bfa_fcport_get_cfg_topology(struct bfa_s *bfa)
3866{
3867 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3868
3869 return fcport->cfg.topology;
3870}
3871
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003872bfa_status_t
3873bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
3874{
3875 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3876
3877 bfa_trc(bfa, alpa);
3878 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3879 bfa_trc(bfa, fcport->cfg.hardalpa);
3880
3881 fcport->cfg.cfg_hardalpa = BFA_TRUE;
3882 fcport->cfg.hardalpa = alpa;
3883
3884 return BFA_STATUS_OK;
3885}
3886
3887bfa_status_t
3888bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
3889{
3890 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3891
3892 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3893 bfa_trc(bfa, fcport->cfg.hardalpa);
3894
3895 fcport->cfg.cfg_hardalpa = BFA_FALSE;
3896 return BFA_STATUS_OK;
3897}
3898
3899bfa_boolean_t
3900bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
3901{
3902 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3903
3904 *alpa = fcport->cfg.hardalpa;
3905 return fcport->cfg.cfg_hardalpa;
3906}
3907
3908u8
3909bfa_fcport_get_myalpa(struct bfa_s *bfa)
3910{
3911 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3912
3913 return fcport->myalpa;
3914}
3915
3916bfa_status_t
3917bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
3918{
3919 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3920
3921 bfa_trc(bfa, maxfrsize);
3922 bfa_trc(bfa, fcport->cfg.maxfrsize);
3923
3924 /* with in range */
3925 if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
3926 return BFA_STATUS_INVLD_DFSZ;
3927
3928 /* power of 2, if not the max frame size of 2112 */
3929 if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
3930 return BFA_STATUS_INVLD_DFSZ;
3931
3932 fcport->cfg.maxfrsize = maxfrsize;
3933 return BFA_STATUS_OK;
3934}
3935
3936u16
3937bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
3938{
3939 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3940
3941 return fcport->cfg.maxfrsize;
3942}
3943
3944u8
3945bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
3946{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003947 if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP)
3948 return (BFA_FCPORT_MOD(bfa))->cfg.rx_bbcredit;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003949
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003950 else
3951 return 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003952}
3953
3954void
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003955bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit, u8 bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003956{
3957 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3958
3959 fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003960 fcport->cfg.bb_scn = bb_scn;
3961 if (bb_scn)
3962 fcport->bbsc_op_state = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003963}
3964
Jing Huang5fbe25c2010-10-18 17:17:23 -07003965/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003966 * Get port attributes.
3967 */
3968
3969wwn_t
3970bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
3971{
3972 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3973 if (node)
3974 return fcport->nwwn;
3975 else
3976 return fcport->pwwn;
3977}
3978
3979void
3980bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3981{
3982 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3983
Jing Huang6a18b162010-10-18 17:08:54 -07003984 memset(attr, 0, sizeof(struct bfa_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003985
3986 attr->nwwn = fcport->nwwn;
3987 attr->pwwn = fcport->pwwn;
3988
Maggie Zhangf7f738122010-12-09 19:08:43 -08003989 attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
3990 attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003991
Jing Huang6a18b162010-10-18 17:08:54 -07003992 memcpy(&attr->pport_cfg, &fcport->cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003993 sizeof(struct bfa_port_cfg_s));
3994 /* speed attributes */
3995 attr->pport_cfg.speed = fcport->cfg.speed;
3996 attr->speed_supported = fcport->speed_sup;
3997 attr->speed = fcport->speed;
3998 attr->cos_supported = FC_CLASS_3;
3999
4000 /* topology attributes */
4001 attr->pport_cfg.topology = fcport->cfg.topology;
4002 attr->topology = fcport->topology;
4003 attr->pport_cfg.trunked = fcport->cfg.trunked;
4004
4005 /* beacon attributes */
4006 attr->beacon = fcport->beacon;
4007 attr->link_e2e_beacon = fcport->link_e2e_beacon;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004008
4009 attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
4010 attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
4011 attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07004012 attr->bbsc_op_status = fcport->bbsc_op_state;
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07004013
4014 /* PBC Disabled State */
4015 if (bfa_fcport_is_pbcdisabled(bfa))
4016 attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
4017 else {
4018 if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
4019 attr->port_state = BFA_PORT_ST_IOCDIS;
4020 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
4021 attr->port_state = BFA_PORT_ST_FWMISMATCH;
4022 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004023
4024 /* FCoE vlan */
4025 attr->fcoe_vlan = fcport->fcoe_vlan;
4026}
4027
4028#define BFA_FCPORT_STATS_TOV 1000
4029
Jing Huang5fbe25c2010-10-18 17:17:23 -07004030/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004031 * Fetch port statistics (FCQoS or FCoE).
4032 */
4033bfa_status_t
Krishna Gudipati37ea0552011-07-20 17:02:11 -07004034bfa_fcport_get_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004035{
4036 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4037
Krishna Gudipati37ea0552011-07-20 17:02:11 -07004038 if (bfa_ioc_is_disabled(&bfa->ioc))
4039 return BFA_STATUS_IOC_DISABLED;
4040
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 Gudipati37ea0552011-07-20 17:02:11 -07004064 if (!list_empty(&fcport->stats_pending_q))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004065 return BFA_STATUS_DEVBUSY;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004066
Krishna Gudipati37ea0552011-07-20 17:02:11 -07004067 if (list_empty(&fcport->statsclr_pending_q)) {
4068 list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
4069 bfa_fcport_send_stats_clear(fcport);
4070 bfa_timer_start(bfa, &fcport->timer,
4071 bfa_fcport_stats_clr_timeout,
4072 fcport, BFA_FCPORT_STATS_TOV);
4073 } else
4074 list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004075
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004076 return BFA_STATUS_OK;
4077}
4078
Jing Huang5fbe25c2010-10-18 17:17:23 -07004079/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004080 * Fetch port attributes.
4081 */
4082bfa_boolean_t
4083bfa_fcport_is_disabled(struct bfa_s *bfa)
4084{
4085 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4086
4087 return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
4088 BFA_PORT_ST_DISABLED;
4089
4090}
4091
4092bfa_boolean_t
Krishna Gudipatie3535462012-09-21 17:26:07 -07004093bfa_fcport_is_dport(struct bfa_s *bfa)
4094{
4095 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4096
4097 return (bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
4098 BFA_PORT_ST_DPORT);
4099}
4100
4101bfa_boolean_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004102bfa_fcport_is_ratelim(struct bfa_s *bfa)
4103{
4104 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4105
4106 return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
4107
4108}
4109
Jing Huang5fbe25c2010-10-18 17:17:23 -07004110/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07004111 * Enable/Disable FAA feature in port config
4112 */
4113void
4114bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state)
4115{
4116 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4117
4118 bfa_trc(bfa, state);
4119 fcport->cfg.faa_state = state;
4120}
4121
4122/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004123 * Get default minimum ratelim speed
4124 */
4125enum bfa_port_speed
4126bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
4127{
4128 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4129
4130 bfa_trc(bfa, fcport->cfg.trl_def_speed);
4131 return fcport->cfg.trl_def_speed;
4132
4133}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004134
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004135void
4136bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
4137 bfa_boolean_t link_e2e_beacon)
4138{
4139 struct bfa_s *bfa = dev;
4140 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4141
4142 bfa_trc(bfa, beacon);
4143 bfa_trc(bfa, link_e2e_beacon);
4144 bfa_trc(bfa, fcport->beacon);
4145 bfa_trc(bfa, fcport->link_e2e_beacon);
4146
4147 fcport->beacon = beacon;
4148 fcport->link_e2e_beacon = link_e2e_beacon;
4149}
4150
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004151bfa_boolean_t
4152bfa_fcport_is_linkup(struct bfa_s *bfa)
4153{
4154 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4155
4156 return (!fcport->cfg.trunked &&
4157 bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
4158 (fcport->cfg.trunked &&
4159 fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
4160}
4161
4162bfa_boolean_t
4163bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
4164{
4165 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4166
4167 return fcport->cfg.qos_enabled;
4168}
4169
Krishna Gudipatibe540a92011-06-13 15:53:04 -07004170bfa_boolean_t
4171bfa_fcport_is_trunk_enabled(struct bfa_s *bfa)
4172{
4173 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4174
4175 return fcport->cfg.trunked;
4176}
4177
Krishna Gudipatie3535462012-09-21 17:26:07 -07004178void
4179bfa_fcport_dportenable(struct bfa_s *bfa)
4180{
4181 /*
4182 * Assume caller check for port is in disable state
4183 */
4184 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DPORTENABLE);
4185 bfa_port_set_dportenabled(&bfa->modules.port, BFA_TRUE);
4186}
4187
4188void
4189bfa_fcport_dportdisable(struct bfa_s *bfa)
4190{
4191 /*
4192 * Assume caller check for port is in disable state
4193 */
4194 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DPORTDISABLE);
4195 bfa_port_set_dportenabled(&bfa->modules.port, BFA_FALSE);
4196}
4197
Jing Huang5fbe25c2010-10-18 17:17:23 -07004198/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004199 * Rport State machine functions
4200 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07004201/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004202 * Beginning state, only online event expected.
4203 */
4204static void
4205bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
4206{
4207 bfa_trc(rp->bfa, rp->rport_tag);
4208 bfa_trc(rp->bfa, event);
4209
4210 switch (event) {
4211 case BFA_RPORT_SM_CREATE:
4212 bfa_stats(rp, sm_un_cr);
4213 bfa_sm_set_state(rp, bfa_rport_sm_created);
4214 break;
4215
4216 default:
4217 bfa_stats(rp, sm_un_unexp);
4218 bfa_sm_fault(rp->bfa, event);
4219 }
4220}
4221
4222static void
4223bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
4224{
4225 bfa_trc(rp->bfa, rp->rport_tag);
4226 bfa_trc(rp->bfa, event);
4227
4228 switch (event) {
4229 case BFA_RPORT_SM_ONLINE:
4230 bfa_stats(rp, sm_cr_on);
4231 if (bfa_rport_send_fwcreate(rp))
4232 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4233 else
4234 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4235 break;
4236
4237 case BFA_RPORT_SM_DELETE:
4238 bfa_stats(rp, sm_cr_del);
4239 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4240 bfa_rport_free(rp);
4241 break;
4242
4243 case BFA_RPORT_SM_HWFAIL:
4244 bfa_stats(rp, sm_cr_hwf);
4245 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4246 break;
4247
4248 default:
4249 bfa_stats(rp, sm_cr_unexp);
4250 bfa_sm_fault(rp->bfa, event);
4251 }
4252}
4253
Jing Huang5fbe25c2010-10-18 17:17:23 -07004254/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004255 * Waiting for rport create response from firmware.
4256 */
4257static void
4258bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
4259{
4260 bfa_trc(rp->bfa, rp->rport_tag);
4261 bfa_trc(rp->bfa, event);
4262
4263 switch (event) {
4264 case BFA_RPORT_SM_FWRSP:
4265 bfa_stats(rp, sm_fwc_rsp);
4266 bfa_sm_set_state(rp, bfa_rport_sm_online);
4267 bfa_rport_online_cb(rp);
4268 break;
4269
4270 case BFA_RPORT_SM_DELETE:
4271 bfa_stats(rp, sm_fwc_del);
4272 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4273 break;
4274
4275 case BFA_RPORT_SM_OFFLINE:
4276 bfa_stats(rp, sm_fwc_off);
4277 bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
4278 break;
4279
4280 case BFA_RPORT_SM_HWFAIL:
4281 bfa_stats(rp, sm_fwc_hwf);
4282 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4283 break;
4284
4285 default:
4286 bfa_stats(rp, sm_fwc_unexp);
4287 bfa_sm_fault(rp->bfa, event);
4288 }
4289}
4290
Jing Huang5fbe25c2010-10-18 17:17:23 -07004291/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004292 * Request queue is full, awaiting queue resume to send create request.
4293 */
4294static void
4295bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4296{
4297 bfa_trc(rp->bfa, rp->rport_tag);
4298 bfa_trc(rp->bfa, event);
4299
4300 switch (event) {
4301 case BFA_RPORT_SM_QRESUME:
4302 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4303 bfa_rport_send_fwcreate(rp);
4304 break;
4305
4306 case BFA_RPORT_SM_DELETE:
4307 bfa_stats(rp, sm_fwc_del);
4308 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4309 bfa_reqq_wcancel(&rp->reqq_wait);
4310 bfa_rport_free(rp);
4311 break;
4312
4313 case BFA_RPORT_SM_OFFLINE:
4314 bfa_stats(rp, sm_fwc_off);
4315 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4316 bfa_reqq_wcancel(&rp->reqq_wait);
4317 bfa_rport_offline_cb(rp);
4318 break;
4319
4320 case BFA_RPORT_SM_HWFAIL:
4321 bfa_stats(rp, sm_fwc_hwf);
4322 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4323 bfa_reqq_wcancel(&rp->reqq_wait);
4324 break;
4325
4326 default:
4327 bfa_stats(rp, sm_fwc_unexp);
4328 bfa_sm_fault(rp->bfa, event);
4329 }
4330}
4331
Jing Huang5fbe25c2010-10-18 17:17:23 -07004332/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004333 * Online state - normal parking state.
4334 */
4335static void
4336bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
4337{
4338 struct bfi_rport_qos_scn_s *qos_scn;
4339
4340 bfa_trc(rp->bfa, rp->rport_tag);
4341 bfa_trc(rp->bfa, event);
4342
4343 switch (event) {
4344 case BFA_RPORT_SM_OFFLINE:
4345 bfa_stats(rp, sm_on_off);
4346 if (bfa_rport_send_fwdelete(rp))
4347 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4348 else
4349 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4350 break;
4351
4352 case BFA_RPORT_SM_DELETE:
4353 bfa_stats(rp, sm_on_del);
4354 if (bfa_rport_send_fwdelete(rp))
4355 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4356 else
4357 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4358 break;
4359
4360 case BFA_RPORT_SM_HWFAIL:
4361 bfa_stats(rp, sm_on_hwf);
4362 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4363 break;
4364
4365 case BFA_RPORT_SM_SET_SPEED:
4366 bfa_rport_send_fwspeed(rp);
4367 break;
4368
4369 case BFA_RPORT_SM_QOS_SCN:
4370 qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
4371 rp->qos_attr = qos_scn->new_qos_attr;
4372 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
4373 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
4374 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
4375 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
4376
4377 qos_scn->old_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004378 be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004379 qos_scn->new_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004380 be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004381
4382 if (qos_scn->old_qos_attr.qos_flow_id !=
4383 qos_scn->new_qos_attr.qos_flow_id)
4384 bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
4385 qos_scn->old_qos_attr,
4386 qos_scn->new_qos_attr);
4387 if (qos_scn->old_qos_attr.qos_priority !=
4388 qos_scn->new_qos_attr.qos_priority)
4389 bfa_cb_rport_qos_scn_prio(rp->rport_drv,
4390 qos_scn->old_qos_attr,
4391 qos_scn->new_qos_attr);
4392 break;
4393
4394 default:
4395 bfa_stats(rp, sm_on_unexp);
4396 bfa_sm_fault(rp->bfa, event);
4397 }
4398}
4399
Jing Huang5fbe25c2010-10-18 17:17:23 -07004400/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004401 * Firmware rport is being deleted - awaiting f/w response.
4402 */
4403static void
4404bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
4405{
4406 bfa_trc(rp->bfa, rp->rport_tag);
4407 bfa_trc(rp->bfa, event);
4408
4409 switch (event) {
4410 case BFA_RPORT_SM_FWRSP:
4411 bfa_stats(rp, sm_fwd_rsp);
4412 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4413 bfa_rport_offline_cb(rp);
4414 break;
4415
4416 case BFA_RPORT_SM_DELETE:
4417 bfa_stats(rp, sm_fwd_del);
4418 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4419 break;
4420
4421 case BFA_RPORT_SM_HWFAIL:
4422 bfa_stats(rp, sm_fwd_hwf);
4423 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4424 bfa_rport_offline_cb(rp);
4425 break;
4426
4427 default:
4428 bfa_stats(rp, sm_fwd_unexp);
4429 bfa_sm_fault(rp->bfa, event);
4430 }
4431}
4432
4433static void
4434bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4435{
4436 bfa_trc(rp->bfa, rp->rport_tag);
4437 bfa_trc(rp->bfa, event);
4438
4439 switch (event) {
4440 case BFA_RPORT_SM_QRESUME:
4441 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4442 bfa_rport_send_fwdelete(rp);
4443 break;
4444
4445 case BFA_RPORT_SM_DELETE:
4446 bfa_stats(rp, sm_fwd_del);
4447 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4448 break;
4449
4450 case BFA_RPORT_SM_HWFAIL:
4451 bfa_stats(rp, sm_fwd_hwf);
4452 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4453 bfa_reqq_wcancel(&rp->reqq_wait);
4454 bfa_rport_offline_cb(rp);
4455 break;
4456
4457 default:
4458 bfa_stats(rp, sm_fwd_unexp);
4459 bfa_sm_fault(rp->bfa, event);
4460 }
4461}
4462
Jing Huang5fbe25c2010-10-18 17:17:23 -07004463/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004464 * Offline state.
4465 */
4466static void
4467bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
4468{
4469 bfa_trc(rp->bfa, rp->rport_tag);
4470 bfa_trc(rp->bfa, event);
4471
4472 switch (event) {
4473 case BFA_RPORT_SM_DELETE:
4474 bfa_stats(rp, sm_off_del);
4475 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4476 bfa_rport_free(rp);
4477 break;
4478
4479 case BFA_RPORT_SM_ONLINE:
4480 bfa_stats(rp, sm_off_on);
4481 if (bfa_rport_send_fwcreate(rp))
4482 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4483 else
4484 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4485 break;
4486
4487 case BFA_RPORT_SM_HWFAIL:
4488 bfa_stats(rp, sm_off_hwf);
4489 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4490 break;
4491
Krishna Gudipati61ba4392012-08-22 19:52:58 -07004492 case BFA_RPORT_SM_OFFLINE:
4493 bfa_rport_offline_cb(rp);
4494 break;
4495
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004496 default:
4497 bfa_stats(rp, sm_off_unexp);
4498 bfa_sm_fault(rp->bfa, event);
4499 }
4500}
4501
Jing Huang5fbe25c2010-10-18 17:17:23 -07004502/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004503 * Rport is deleted, waiting for firmware response to delete.
4504 */
4505static void
4506bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
4507{
4508 bfa_trc(rp->bfa, rp->rport_tag);
4509 bfa_trc(rp->bfa, event);
4510
4511 switch (event) {
4512 case BFA_RPORT_SM_FWRSP:
4513 bfa_stats(rp, sm_del_fwrsp);
4514 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4515 bfa_rport_free(rp);
4516 break;
4517
4518 case BFA_RPORT_SM_HWFAIL:
4519 bfa_stats(rp, sm_del_hwf);
4520 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4521 bfa_rport_free(rp);
4522 break;
4523
4524 default:
4525 bfa_sm_fault(rp->bfa, event);
4526 }
4527}
4528
4529static void
4530bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4531{
4532 bfa_trc(rp->bfa, rp->rport_tag);
4533 bfa_trc(rp->bfa, event);
4534
4535 switch (event) {
4536 case BFA_RPORT_SM_QRESUME:
4537 bfa_stats(rp, sm_del_fwrsp);
4538 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4539 bfa_rport_send_fwdelete(rp);
4540 break;
4541
4542 case BFA_RPORT_SM_HWFAIL:
4543 bfa_stats(rp, sm_del_hwf);
4544 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4545 bfa_reqq_wcancel(&rp->reqq_wait);
4546 bfa_rport_free(rp);
4547 break;
4548
4549 default:
4550 bfa_sm_fault(rp->bfa, event);
4551 }
4552}
4553
Jing Huang5fbe25c2010-10-18 17:17:23 -07004554/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004555 * Waiting for rport create response from firmware. A delete is pending.
4556 */
4557static void
4558bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
4559 enum bfa_rport_event event)
4560{
4561 bfa_trc(rp->bfa, rp->rport_tag);
4562 bfa_trc(rp->bfa, event);
4563
4564 switch (event) {
4565 case BFA_RPORT_SM_FWRSP:
4566 bfa_stats(rp, sm_delp_fwrsp);
4567 if (bfa_rport_send_fwdelete(rp))
4568 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4569 else
4570 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4571 break;
4572
4573 case BFA_RPORT_SM_HWFAIL:
4574 bfa_stats(rp, sm_delp_hwf);
4575 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4576 bfa_rport_free(rp);
4577 break;
4578
4579 default:
4580 bfa_stats(rp, sm_delp_unexp);
4581 bfa_sm_fault(rp->bfa, event);
4582 }
4583}
4584
Jing Huang5fbe25c2010-10-18 17:17:23 -07004585/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004586 * Waiting for rport create response from firmware. Rport offline is pending.
4587 */
4588static void
4589bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
4590 enum bfa_rport_event event)
4591{
4592 bfa_trc(rp->bfa, rp->rport_tag);
4593 bfa_trc(rp->bfa, event);
4594
4595 switch (event) {
4596 case BFA_RPORT_SM_FWRSP:
4597 bfa_stats(rp, sm_offp_fwrsp);
4598 if (bfa_rport_send_fwdelete(rp))
4599 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4600 else
4601 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4602 break;
4603
4604 case BFA_RPORT_SM_DELETE:
4605 bfa_stats(rp, sm_offp_del);
4606 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4607 break;
4608
4609 case BFA_RPORT_SM_HWFAIL:
4610 bfa_stats(rp, sm_offp_hwf);
4611 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07004612 bfa_rport_offline_cb(rp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004613 break;
4614
4615 default:
4616 bfa_stats(rp, sm_offp_unexp);
4617 bfa_sm_fault(rp->bfa, event);
4618 }
4619}
4620
Jing Huang5fbe25c2010-10-18 17:17:23 -07004621/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004622 * IOC h/w failed.
4623 */
4624static void
4625bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
4626{
4627 bfa_trc(rp->bfa, rp->rport_tag);
4628 bfa_trc(rp->bfa, event);
4629
4630 switch (event) {
4631 case BFA_RPORT_SM_OFFLINE:
4632 bfa_stats(rp, sm_iocd_off);
4633 bfa_rport_offline_cb(rp);
4634 break;
4635
4636 case BFA_RPORT_SM_DELETE:
4637 bfa_stats(rp, sm_iocd_del);
4638 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4639 bfa_rport_free(rp);
4640 break;
4641
4642 case BFA_RPORT_SM_ONLINE:
4643 bfa_stats(rp, sm_iocd_on);
4644 if (bfa_rport_send_fwcreate(rp))
4645 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4646 else
4647 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4648 break;
4649
4650 case BFA_RPORT_SM_HWFAIL:
4651 break;
4652
4653 default:
4654 bfa_stats(rp, sm_iocd_unexp);
4655 bfa_sm_fault(rp->bfa, event);
4656 }
4657}
4658
4659
4660
Jing Huang5fbe25c2010-10-18 17:17:23 -07004661/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004662 * bfa_rport_private BFA rport private functions
4663 */
4664
4665static void
4666__bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
4667{
4668 struct bfa_rport_s *rp = cbarg;
4669
4670 if (complete)
4671 bfa_cb_rport_online(rp->rport_drv);
4672}
4673
4674static void
4675__bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
4676{
4677 struct bfa_rport_s *rp = cbarg;
4678
4679 if (complete)
4680 bfa_cb_rport_offline(rp->rport_drv);
4681}
4682
4683static void
4684bfa_rport_qresume(void *cbarg)
4685{
4686 struct bfa_rport_s *rp = cbarg;
4687
4688 bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
4689}
4690
4691static void
Krishna Gudipati45070252011-06-24 20:24:29 -07004692bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
4693 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004694{
Krishna Gudipati45070252011-06-24 20:24:29 -07004695 struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa);
4696
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004697 if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
4698 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
4699
Krishna Gudipati45070252011-06-24 20:24:29 -07004700 /* kva memory */
4701 bfa_mem_kva_setup(minfo, rport_kva,
4702 cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004703}
4704
4705static void
4706bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07004707 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004708{
4709 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4710 struct bfa_rport_s *rp;
4711 u16 i;
4712
4713 INIT_LIST_HEAD(&mod->rp_free_q);
4714 INIT_LIST_HEAD(&mod->rp_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004715 INIT_LIST_HEAD(&mod->rp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004716
Krishna Gudipati45070252011-06-24 20:24:29 -07004717 rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004718 mod->rps_list = rp;
4719 mod->num_rports = cfg->fwcfg.num_rports;
4720
Jing Huangd4b671c2010-12-26 21:46:35 -08004721 WARN_ON(!mod->num_rports ||
4722 (mod->num_rports & (mod->num_rports - 1)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004723
4724 for (i = 0; i < mod->num_rports; i++, rp++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004725 memset(rp, 0, sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004726 rp->bfa = bfa;
4727 rp->rport_tag = i;
4728 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4729
Jing Huang5fbe25c2010-10-18 17:17:23 -07004730 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004731 * - is unused
4732 */
4733 if (i)
4734 list_add_tail(&rp->qe, &mod->rp_free_q);
4735
4736 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
4737 }
4738
Jing Huang5fbe25c2010-10-18 17:17:23 -07004739 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004740 * consume memory
4741 */
Krishna Gudipati45070252011-06-24 20:24:29 -07004742 bfa_mem_kva_curp(mod) = (u8 *) rp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004743}
4744
4745static void
4746bfa_rport_detach(struct bfa_s *bfa)
4747{
4748}
4749
4750static void
4751bfa_rport_start(struct bfa_s *bfa)
4752{
4753}
4754
4755static void
4756bfa_rport_stop(struct bfa_s *bfa)
4757{
4758}
4759
4760static void
4761bfa_rport_iocdisable(struct bfa_s *bfa)
4762{
4763 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4764 struct bfa_rport_s *rport;
4765 struct list_head *qe, *qen;
4766
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004767 /* Enqueue unused rport resources to free_q */
4768 list_splice_tail_init(&mod->rp_unused_q, &mod->rp_free_q);
4769
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004770 list_for_each_safe(qe, qen, &mod->rp_active_q) {
4771 rport = (struct bfa_rport_s *) qe;
4772 bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
4773 }
4774}
4775
4776static struct bfa_rport_s *
4777bfa_rport_alloc(struct bfa_rport_mod_s *mod)
4778{
4779 struct bfa_rport_s *rport;
4780
4781 bfa_q_deq(&mod->rp_free_q, &rport);
4782 if (rport)
4783 list_add_tail(&rport->qe, &mod->rp_active_q);
4784
4785 return rport;
4786}
4787
4788static void
4789bfa_rport_free(struct bfa_rport_s *rport)
4790{
4791 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
4792
Jing Huangd4b671c2010-12-26 21:46:35 -08004793 WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004794 list_del(&rport->qe);
4795 list_add_tail(&rport->qe, &mod->rp_free_q);
4796}
4797
4798static bfa_boolean_t
4799bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4800{
4801 struct bfi_rport_create_req_s *m;
4802
Jing Huang5fbe25c2010-10-18 17:17:23 -07004803 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004804 * check for room in queue to send request now
4805 */
4806 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4807 if (!m) {
4808 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4809 return BFA_FALSE;
4810 }
4811
4812 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004813 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004814 m->bfa_handle = rp->rport_tag;
Jing Huangba816ea2010-10-18 17:10:50 -07004815 m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004816 m->pid = rp->rport_info.pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004817 m->lp_fwtag = bfa_lps_get_fwtag(rp->bfa, (u8)rp->rport_info.lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004818 m->local_pid = rp->rport_info.local_pid;
4819 m->fc_class = rp->rport_info.fc_class;
4820 m->vf_en = rp->rport_info.vf_en;
4821 m->vf_id = rp->rport_info.vf_id;
4822 m->cisc = rp->rport_info.cisc;
4823
Jing Huang5fbe25c2010-10-18 17:17:23 -07004824 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004825 * queue I/O message to firmware
4826 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004827 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004828 return BFA_TRUE;
4829}
4830
4831static bfa_boolean_t
4832bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4833{
4834 struct bfi_rport_delete_req_s *m;
4835
Jing Huang5fbe25c2010-10-18 17:17:23 -07004836 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004837 * check for room in queue to send request now
4838 */
4839 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4840 if (!m) {
4841 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4842 return BFA_FALSE;
4843 }
4844
4845 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004846 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004847 m->fw_handle = rp->fw_handle;
4848
Jing Huang5fbe25c2010-10-18 17:17:23 -07004849 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004850 * queue I/O message to firmware
4851 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004852 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004853 return BFA_TRUE;
4854}
4855
4856static bfa_boolean_t
4857bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4858{
4859 struct bfa_rport_speed_req_s *m;
4860
Jing Huang5fbe25c2010-10-18 17:17:23 -07004861 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004862 * check for room in queue to send request now
4863 */
4864 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4865 if (!m) {
4866 bfa_trc(rp->bfa, rp->rport_info.speed);
4867 return BFA_FALSE;
4868 }
4869
4870 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004871 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004872 m->fw_handle = rp->fw_handle;
4873 m->speed = (u8)rp->rport_info.speed;
4874
Jing Huang5fbe25c2010-10-18 17:17:23 -07004875 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004876 * queue I/O message to firmware
4877 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004878 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004879 return BFA_TRUE;
4880}
4881
4882
4883
Jing Huang5fbe25c2010-10-18 17:17:23 -07004884/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004885 * bfa_rport_public
4886 */
4887
Jing Huang5fbe25c2010-10-18 17:17:23 -07004888/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004889 * Rport interrupt processing.
4890 */
4891void
4892bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
4893{
4894 union bfi_rport_i2h_msg_u msg;
4895 struct bfa_rport_s *rp;
4896
4897 bfa_trc(bfa, m->mhdr.msg_id);
4898
4899 msg.msg = m;
4900
4901 switch (m->mhdr.msg_id) {
4902 case BFI_RPORT_I2H_CREATE_RSP:
4903 rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
4904 rp->fw_handle = msg.create_rsp->fw_handle;
4905 rp->qos_attr = msg.create_rsp->qos_attr;
Krishna Gudipati83763d52011-07-20 17:04:03 -07004906 bfa_rport_set_lunmask(bfa, rp);
Jing Huangd4b671c2010-12-26 21:46:35 -08004907 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004908 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4909 break;
4910
4911 case BFI_RPORT_I2H_DELETE_RSP:
4912 rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08004913 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
Krishna Gudipati83763d52011-07-20 17:04:03 -07004914 bfa_rport_unset_lunmask(bfa, rp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004915 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4916 break;
4917
4918 case BFI_RPORT_I2H_QOS_SCN:
4919 rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
4920 rp->event_arg.fw_msg = msg.qos_scn_evt;
4921 bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
4922 break;
4923
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07004924 case BFI_RPORT_I2H_LIP_SCN_ONLINE:
4925 bfa_fcport_update_loop_info(BFA_FCPORT_MOD(bfa),
4926 &msg.lip_scn->loop_info);
4927 bfa_cb_rport_scn_online(bfa);
4928 break;
4929
4930 case BFI_RPORT_I2H_LIP_SCN_OFFLINE:
4931 bfa_cb_rport_scn_offline(bfa);
4932 break;
4933
4934 case BFI_RPORT_I2H_NO_DEV:
4935 rp = BFA_RPORT_FROM_TAG(bfa, msg.lip_scn->bfa_handle);
4936 bfa_cb_rport_scn_no_dev(rp->rport_drv);
4937 break;
4938
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004939 default:
4940 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08004941 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004942 }
4943}
4944
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004945void
4946bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw)
4947{
4948 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4949 struct list_head *qe;
4950 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004951
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004952 for (i = 0; i < (mod->num_rports - num_rport_fw); i++) {
4953 bfa_q_deq_tail(&mod->rp_free_q, &qe);
4954 list_add_tail(qe, &mod->rp_unused_q);
4955 }
4956}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004957
Jing Huang5fbe25c2010-10-18 17:17:23 -07004958/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004959 * bfa_rport_api
4960 */
4961
4962struct bfa_rport_s *
4963bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
4964{
4965 struct bfa_rport_s *rp;
4966
4967 rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
4968
4969 if (rp == NULL)
4970 return NULL;
4971
4972 rp->bfa = bfa;
4973 rp->rport_drv = rport_drv;
Maggie Zhangf7f738122010-12-09 19:08:43 -08004974 memset(&rp->stats, 0, sizeof(rp->stats));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004975
Jing Huangd4b671c2010-12-26 21:46:35 -08004976 WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004977 bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
4978
4979 return rp;
4980}
4981
4982void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004983bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
4984{
Jing Huangd4b671c2010-12-26 21:46:35 -08004985 WARN_ON(rport_info->max_frmsz == 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004986
Jing Huang5fbe25c2010-10-18 17:17:23 -07004987 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004988 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
4989 * responses. Default to minimum size.
4990 */
4991 if (rport_info->max_frmsz == 0) {
4992 bfa_trc(rport->bfa, rport->rport_tag);
4993 rport_info->max_frmsz = FC_MIN_PDUSZ;
4994 }
4995
Jing Huang6a18b162010-10-18 17:08:54 -07004996 rport->rport_info = *rport_info;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004997 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
4998}
4999
5000void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005001bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
5002{
Jing Huangd4b671c2010-12-26 21:46:35 -08005003 WARN_ON(speed == 0);
5004 WARN_ON(speed == BFA_PORT_SPEED_AUTO);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005005
Krishna Gudipati61ba4392012-08-22 19:52:58 -07005006 if (rport) {
5007 rport->rport_info.speed = speed;
5008 bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
5009 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005010}
5011
Krishna Gudipati83763d52011-07-20 17:04:03 -07005012/* Set Rport LUN Mask */
5013void
5014bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
5015{
5016 struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
5017 wwn_t lp_wwn, rp_wwn;
5018 u8 lp_tag = (u8)rp->rport_info.lp_tag;
5019
5020 rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
5021 lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
5022
5023 BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
5024 rp->lun_mask = BFA_TRUE;
5025 bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn, rp->rport_tag, lp_tag);
5026}
5027
5028/* Unset Rport LUN mask */
5029void
5030bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
5031{
5032 struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
5033 wwn_t lp_wwn, rp_wwn;
5034
5035 rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
5036 lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
5037
5038 BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
5039 rp->lun_mask = BFA_FALSE;
5040 bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn,
5041 BFA_RPORT_TAG_INVALID, BFA_LP_TAG_INVALID);
5042}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005043
Jing Huang5fbe25c2010-10-18 17:17:23 -07005044/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005045 * SGPG related functions
5046 */
5047
Jing Huang5fbe25c2010-10-18 17:17:23 -07005048/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005049 * Compute and return memory needed by FCP(im) module.
5050 */
5051static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005052bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
5053 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005054{
Krishna Gudipati45070252011-06-24 20:24:29 -07005055 struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa);
5056 struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa);
5057 struct bfa_mem_dma_s *seg_ptr;
5058 u16 nsegs, idx, per_seg_sgpg, num_sgpg;
5059 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
5060
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005061 if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
5062 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
Krishna Gudipati45070252011-06-24 20:24:29 -07005063 else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX)
5064 cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005065
Krishna Gudipati45070252011-06-24 20:24:29 -07005066 num_sgpg = cfg->drvcfg.num_sgpgs;
5067
5068 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
5069 per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz);
5070
5071 bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) {
5072 if (num_sgpg >= per_seg_sgpg) {
5073 num_sgpg -= per_seg_sgpg;
5074 bfa_mem_dma_setup(minfo, seg_ptr,
5075 per_seg_sgpg * sgpg_sz);
5076 } else
5077 bfa_mem_dma_setup(minfo, seg_ptr,
5078 num_sgpg * sgpg_sz);
5079 }
5080
5081 /* kva memory */
5082 bfa_mem_kva_setup(minfo, sgpg_kva,
5083 cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005084}
5085
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005086static void
5087bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07005088 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005089{
5090 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005091 struct bfa_sgpg_s *hsgpg;
5092 struct bfi_sgpg_s *sgpg;
5093 u64 align_len;
Krishna Gudipati45070252011-06-24 20:24:29 -07005094 struct bfa_mem_dma_s *seg_ptr;
5095 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
5096 u16 i, idx, nsegs, per_seg_sgpg, num_sgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005097
5098 union {
5099 u64 pa;
5100 union bfi_addr_u addr;
5101 } sgpg_pa, sgpg_pa_tmp;
5102
5103 INIT_LIST_HEAD(&mod->sgpg_q);
5104 INIT_LIST_HEAD(&mod->sgpg_wait_q);
5105
5106 bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
5107
Krishna Gudipati45070252011-06-24 20:24:29 -07005108 mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005109
Krishna Gudipati45070252011-06-24 20:24:29 -07005110 num_sgpg = cfg->drvcfg.num_sgpgs;
5111 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005112
Krishna Gudipati45070252011-06-24 20:24:29 -07005113 /* dma/kva mem claim */
5114 hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005115
Krishna Gudipati45070252011-06-24 20:24:29 -07005116 bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005117
Krishna Gudipati45070252011-06-24 20:24:29 -07005118 if (!bfa_mem_dma_virt(seg_ptr))
5119 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005120
Krishna Gudipati45070252011-06-24 20:24:29 -07005121 align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) -
5122 bfa_mem_dma_phys(seg_ptr);
5123
5124 sgpg = (struct bfi_sgpg_s *)
5125 (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len);
5126 sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len;
5127 WARN_ON(sgpg_pa.pa & (sgpg_sz - 1));
5128
5129 per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz;
5130
5131 for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) {
5132 memset(hsgpg, 0, sizeof(*hsgpg));
5133 memset(sgpg, 0, sizeof(*sgpg));
5134
5135 hsgpg->sgpg = sgpg;
5136 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
5137 hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
5138 list_add_tail(&hsgpg->qe, &mod->sgpg_q);
5139
5140 sgpg++;
5141 hsgpg++;
5142 sgpg_pa.pa += sgpg_sz;
5143 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005144 }
5145
Krishna Gudipati45070252011-06-24 20:24:29 -07005146 bfa_mem_kva_curp(mod) = (u8 *) hsgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005147}
5148
5149static void
5150bfa_sgpg_detach(struct bfa_s *bfa)
5151{
5152}
5153
5154static void
5155bfa_sgpg_start(struct bfa_s *bfa)
5156{
5157}
5158
5159static void
5160bfa_sgpg_stop(struct bfa_s *bfa)
5161{
5162}
5163
5164static void
5165bfa_sgpg_iocdisable(struct bfa_s *bfa)
5166{
5167}
5168
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005169bfa_status_t
5170bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
5171{
5172 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5173 struct bfa_sgpg_s *hsgpg;
5174 int i;
5175
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005176 if (mod->free_sgpgs < nsgpgs)
5177 return BFA_STATUS_ENOMEM;
5178
5179 for (i = 0; i < nsgpgs; i++) {
5180 bfa_q_deq(&mod->sgpg_q, &hsgpg);
Jing Huangd4b671c2010-12-26 21:46:35 -08005181 WARN_ON(!hsgpg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005182 list_add_tail(&hsgpg->qe, sgpg_q);
5183 }
5184
5185 mod->free_sgpgs -= nsgpgs;
5186 return BFA_STATUS_OK;
5187}
5188
5189void
5190bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
5191{
5192 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5193 struct bfa_sgpg_wqe_s *wqe;
5194
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005195 mod->free_sgpgs += nsgpg;
Jing Huangd4b671c2010-12-26 21:46:35 -08005196 WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005197
5198 list_splice_tail_init(sgpg_q, &mod->sgpg_q);
5199
5200 if (list_empty(&mod->sgpg_wait_q))
5201 return;
5202
Jing Huang5fbe25c2010-10-18 17:17:23 -07005203 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005204 * satisfy as many waiting requests as possible
5205 */
5206 do {
5207 wqe = bfa_q_first(&mod->sgpg_wait_q);
5208 if (mod->free_sgpgs < wqe->nsgpg)
5209 nsgpg = mod->free_sgpgs;
5210 else
5211 nsgpg = wqe->nsgpg;
5212 bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
5213 wqe->nsgpg -= nsgpg;
5214 if (wqe->nsgpg == 0) {
5215 list_del(&wqe->qe);
5216 wqe->cbfn(wqe->cbarg);
5217 }
5218 } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
5219}
5220
5221void
5222bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
5223{
5224 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5225
Jing Huangd4b671c2010-12-26 21:46:35 -08005226 WARN_ON(nsgpg <= 0);
5227 WARN_ON(nsgpg <= mod->free_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005228
5229 wqe->nsgpg_total = wqe->nsgpg = nsgpg;
5230
Jing Huang5fbe25c2010-10-18 17:17:23 -07005231 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005232 * allocate any left to this one first
5233 */
5234 if (mod->free_sgpgs) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07005235 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005236 * no one else is waiting for SGPG
5237 */
Jing Huangd4b671c2010-12-26 21:46:35 -08005238 WARN_ON(!list_empty(&mod->sgpg_wait_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005239 list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
5240 wqe->nsgpg -= mod->free_sgpgs;
5241 mod->free_sgpgs = 0;
5242 }
5243
5244 list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
5245}
5246
5247void
5248bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
5249{
5250 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5251
Jing Huangd4b671c2010-12-26 21:46:35 -08005252 WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005253 list_del(&wqe->qe);
5254
5255 if (wqe->nsgpg_total != wqe->nsgpg)
5256 bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
5257 wqe->nsgpg_total - wqe->nsgpg);
5258}
5259
5260void
5261bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
5262 void *cbarg)
5263{
5264 INIT_LIST_HEAD(&wqe->sgpg_q);
5265 wqe->cbfn = cbfn;
5266 wqe->cbarg = cbarg;
5267}
5268
Jing Huang5fbe25c2010-10-18 17:17:23 -07005269/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005270 * UF related functions
5271 */
5272/*
5273 *****************************************************************************
5274 * Internal functions
5275 *****************************************************************************
5276 */
5277static void
5278__bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
5279{
5280 struct bfa_uf_s *uf = cbarg;
5281 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
5282
5283 if (complete)
5284 ufm->ufrecv(ufm->cbarg, uf);
5285}
5286
5287static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005288claim_uf_post_msgs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005289{
5290 struct bfi_uf_buf_post_s *uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005291 u16 i;
5292 u16 buf_len;
5293
Krishna Gudipati45070252011-06-24 20:24:29 -07005294 ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005295 uf_bp_msg = ufm->uf_buf_posts;
5296
5297 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
5298 i++, uf_bp_msg++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005299 memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005300
5301 uf_bp_msg->buf_tag = i;
5302 buf_len = sizeof(struct bfa_uf_buf_s);
Jing Huangba816ea2010-10-18 17:10:50 -07005303 uf_bp_msg->buf_len = cpu_to_be16(buf_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005304 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005305 bfa_fn_lpu(ufm->bfa));
Krishna Gudipati85ce9282011-06-13 15:39:36 -07005306 bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005307 }
5308
Jing Huang5fbe25c2010-10-18 17:17:23 -07005309 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005310 * advance pointer beyond consumed memory
5311 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005312 bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005313}
5314
5315static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005316claim_ufs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005317{
5318 u16 i;
5319 struct bfa_uf_s *uf;
5320
5321 /*
5322 * Claim block of memory for UF list
5323 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005324 ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005325
5326 /*
5327 * Initialize UFs and queue it in UF free queue
5328 */
5329 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005330 memset(uf, 0, sizeof(struct bfa_uf_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005331 uf->bfa = ufm->bfa;
5332 uf->uf_tag = i;
Krishna Gudipati45070252011-06-24 20:24:29 -07005333 uf->pb_len = BFA_PER_UF_DMA_SZ;
5334 uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005335 uf->buf_pa = ufm_pbs_pa(ufm, i);
5336 list_add_tail(&uf->qe, &ufm->uf_free_q);
5337 }
5338
Jing Huang5fbe25c2010-10-18 17:17:23 -07005339 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005340 * advance memory pointer
5341 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005342 bfa_mem_kva_curp(ufm) = (u8 *) uf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005343}
5344
5345static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005346uf_mem_claim(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005347{
Krishna Gudipati45070252011-06-24 20:24:29 -07005348 claim_ufs(ufm);
5349 claim_uf_post_msgs(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005350}
5351
5352static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005353bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
5354 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005355{
Krishna Gudipati45070252011-06-24 20:24:29 -07005356 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5357 struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa);
5358 u32 num_ufs = cfg->fwcfg.num_uf_bufs;
5359 struct bfa_mem_dma_s *seg_ptr;
5360 u16 nsegs, idx, per_seg_uf = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005361
Krishna Gudipati45070252011-06-24 20:24:29 -07005362 nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ);
5363 per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005364
Krishna Gudipati45070252011-06-24 20:24:29 -07005365 bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) {
5366 if (num_ufs >= per_seg_uf) {
5367 num_ufs -= per_seg_uf;
5368 bfa_mem_dma_setup(minfo, seg_ptr,
5369 per_seg_uf * BFA_PER_UF_DMA_SZ);
5370 } else
5371 bfa_mem_dma_setup(minfo, seg_ptr,
5372 num_ufs * BFA_PER_UF_DMA_SZ);
5373 }
5374
5375 /* kva memory */
5376 bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs *
5377 (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005378}
5379
5380static void
5381bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07005382 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005383{
5384 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5385
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005386 ufm->bfa = bfa;
5387 ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
5388 INIT_LIST_HEAD(&ufm->uf_free_q);
5389 INIT_LIST_HEAD(&ufm->uf_posted_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005390 INIT_LIST_HEAD(&ufm->uf_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005391
Krishna Gudipati45070252011-06-24 20:24:29 -07005392 uf_mem_claim(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005393}
5394
5395static void
5396bfa_uf_detach(struct bfa_s *bfa)
5397{
5398}
5399
5400static struct bfa_uf_s *
5401bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
5402{
5403 struct bfa_uf_s *uf;
5404
5405 bfa_q_deq(&uf_mod->uf_free_q, &uf);
5406 return uf;
5407}
5408
5409static void
5410bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
5411{
5412 list_add_tail(&uf->qe, &uf_mod->uf_free_q);
5413}
5414
5415static bfa_status_t
5416bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
5417{
5418 struct bfi_uf_buf_post_s *uf_post_msg;
5419
5420 uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
5421 if (!uf_post_msg)
5422 return BFA_STATUS_FAILED;
5423
Jing Huang6a18b162010-10-18 17:08:54 -07005424 memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005425 sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005426 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP, uf_post_msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005427
5428 bfa_trc(ufm->bfa, uf->uf_tag);
5429
5430 list_add_tail(&uf->qe, &ufm->uf_posted_q);
5431 return BFA_STATUS_OK;
5432}
5433
5434static void
5435bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
5436{
5437 struct bfa_uf_s *uf;
5438
5439 while ((uf = bfa_uf_get(uf_mod)) != NULL) {
5440 if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
5441 break;
5442 }
5443}
5444
5445static void
5446uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
5447{
5448 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5449 u16 uf_tag = m->buf_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005450 struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
Krishna Gudipati45070252011-06-24 20:24:29 -07005451 struct bfa_uf_buf_s *uf_buf;
5452 uint8_t *buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005453 struct fchs_s *fchs;
5454
Krishna Gudipati45070252011-06-24 20:24:29 -07005455 uf_buf = (struct bfa_uf_buf_s *)
5456 bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len);
5457 buf = &uf_buf->d[0];
5458
Jing Huangba816ea2010-10-18 17:10:50 -07005459 m->frm_len = be16_to_cpu(m->frm_len);
5460 m->xfr_len = be16_to_cpu(m->xfr_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005461
5462 fchs = (struct fchs_s *)uf_buf;
5463
5464 list_del(&uf->qe); /* dequeue from posted queue */
5465
5466 uf->data_ptr = buf;
5467 uf->data_len = m->xfr_len;
5468
Jing Huangd4b671c2010-12-26 21:46:35 -08005469 WARN_ON(uf->data_len < sizeof(struct fchs_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005470
5471 if (uf->data_len == sizeof(struct fchs_s)) {
5472 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
5473 uf->data_len, (struct fchs_s *)buf);
5474 } else {
5475 u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
5476 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
5477 BFA_PL_EID_RX, uf->data_len,
5478 (struct fchs_s *)buf, pld_w0);
5479 }
5480
5481 if (bfa->fcs)
5482 __bfa_cb_uf_recv(uf, BFA_TRUE);
5483 else
5484 bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
5485}
5486
5487static void
5488bfa_uf_stop(struct bfa_s *bfa)
5489{
5490}
5491
5492static void
5493bfa_uf_iocdisable(struct bfa_s *bfa)
5494{
5495 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5496 struct bfa_uf_s *uf;
5497 struct list_head *qe, *qen;
5498
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005499 /* Enqueue unused uf resources to free_q */
5500 list_splice_tail_init(&ufm->uf_unused_q, &ufm->uf_free_q);
5501
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005502 list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
5503 uf = (struct bfa_uf_s *) qe;
5504 list_del(&uf->qe);
5505 bfa_uf_put(ufm, uf);
5506 }
5507}
5508
5509static void
5510bfa_uf_start(struct bfa_s *bfa)
5511{
5512 bfa_uf_post_all(BFA_UF_MOD(bfa));
5513}
5514
Jing Huang5fbe25c2010-10-18 17:17:23 -07005515/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005516 * Register handler for all unsolicted receive frames.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005517 *
5518 * @param[in] bfa BFA instance
5519 * @param[in] ufrecv receive handler function
5520 * @param[in] cbarg receive handler arg
5521 */
5522void
5523bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
5524{
5525 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5526
5527 ufm->ufrecv = ufrecv;
5528 ufm->cbarg = cbarg;
5529}
5530
Jing Huang5fbe25c2010-10-18 17:17:23 -07005531/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005532 * Free an unsolicited frame back to BFA.
5533 *
5534 * @param[in] uf unsolicited frame to be freed
5535 *
5536 * @return None
5537 */
5538void
5539bfa_uf_free(struct bfa_uf_s *uf)
5540{
5541 bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
5542 bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
5543}
5544
5545
5546
Jing Huang5fbe25c2010-10-18 17:17:23 -07005547/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005548 * uf_pub BFA uf module public functions
5549 */
5550void
5551bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5552{
5553 bfa_trc(bfa, msg->mhdr.msg_id);
5554
5555 switch (msg->mhdr.msg_id) {
5556 case BFI_UF_I2H_FRM_RCVD:
5557 uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
5558 break;
5559
5560 default:
5561 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08005562 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005563 }
5564}
5565
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005566void
5567bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw)
5568{
5569 struct bfa_uf_mod_s *mod = BFA_UF_MOD(bfa);
5570 struct list_head *qe;
5571 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005572
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005573 for (i = 0; i < (mod->num_ufs - num_uf_fw); i++) {
5574 bfa_q_deq_tail(&mod->uf_free_q, &qe);
5575 list_add_tail(qe, &mod->uf_unused_q);
5576 }
5577}
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005578
5579/*
Krishna Gudipatie3535462012-09-21 17:26:07 -07005580 * Dport forward declaration
5581 */
5582
5583/*
5584 * BFA DPORT state machine events
5585 */
5586enum bfa_dport_sm_event {
5587 BFA_DPORT_SM_ENABLE = 1, /* dport enable event */
5588 BFA_DPORT_SM_DISABLE = 2, /* dport disable event */
5589 BFA_DPORT_SM_FWRSP = 3, /* fw enable/disable rsp */
5590 BFA_DPORT_SM_QRESUME = 4, /* CQ space available */
5591 BFA_DPORT_SM_HWFAIL = 5, /* IOC h/w failure */
5592};
5593
5594static void bfa_dport_sm_disabled(struct bfa_dport_s *dport,
5595 enum bfa_dport_sm_event event);
5596static void bfa_dport_sm_enabling_qwait(struct bfa_dport_s *dport,
5597 enum bfa_dport_sm_event event);
5598static void bfa_dport_sm_enabling(struct bfa_dport_s *dport,
5599 enum bfa_dport_sm_event event);
5600static void bfa_dport_sm_enabled(struct bfa_dport_s *dport,
5601 enum bfa_dport_sm_event event);
5602static void bfa_dport_sm_disabling_qwait(struct bfa_dport_s *dport,
5603 enum bfa_dport_sm_event event);
5604static void bfa_dport_sm_disabling(struct bfa_dport_s *dport,
5605 enum bfa_dport_sm_event event);
5606static void bfa_dport_qresume(void *cbarg);
5607static void bfa_dport_req_comp(struct bfa_dport_s *dport,
5608 bfi_diag_dport_rsp_t *msg);
5609
5610/*
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005611 * BFA fcdiag module
5612 */
5613#define BFA_DIAG_QTEST_TOV 1000 /* msec */
5614
5615/*
5616 * Set port status to busy
5617 */
5618static void
5619bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s *fcdiag)
5620{
5621 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fcdiag->bfa);
5622
5623 if (fcdiag->lb.lock)
5624 fcport->diag_busy = BFA_TRUE;
5625 else
5626 fcport->diag_busy = BFA_FALSE;
5627}
5628
5629static void
5630bfa_fcdiag_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
5631 struct bfa_s *bfa)
5632{
5633}
5634
5635static void
5636bfa_fcdiag_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
5637 struct bfa_pcidev_s *pcidev)
5638{
5639 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
Krishna Gudipatie3535462012-09-21 17:26:07 -07005640 struct bfa_dport_s *dport = &fcdiag->dport;
5641
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005642 fcdiag->bfa = bfa;
5643 fcdiag->trcmod = bfa->trcmod;
5644 /* The common DIAG attach bfa_diag_attach() will do all memory claim */
Krishna Gudipatie3535462012-09-21 17:26:07 -07005645 dport->bfa = bfa;
5646 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
5647 bfa_reqq_winit(&dport->reqq_wait, bfa_dport_qresume, dport);
5648 dport->cbfn = NULL;
5649 dport->cbarg = NULL;
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005650}
5651
5652static void
5653bfa_fcdiag_iocdisable(struct bfa_s *bfa)
5654{
5655 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
Krishna Gudipatie3535462012-09-21 17:26:07 -07005656 struct bfa_dport_s *dport = &fcdiag->dport;
5657
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005658 bfa_trc(fcdiag, fcdiag->lb.lock);
5659 if (fcdiag->lb.lock) {
5660 fcdiag->lb.status = BFA_STATUS_IOC_FAILURE;
5661 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5662 fcdiag->lb.lock = 0;
5663 bfa_fcdiag_set_busy_status(fcdiag);
5664 }
Krishna Gudipatie3535462012-09-21 17:26:07 -07005665
5666 bfa_sm_send_event(dport, BFA_DPORT_SM_HWFAIL);
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005667}
5668
5669static void
5670bfa_fcdiag_detach(struct bfa_s *bfa)
5671{
5672}
5673
5674static void
5675bfa_fcdiag_start(struct bfa_s *bfa)
5676{
5677}
5678
5679static void
5680bfa_fcdiag_stop(struct bfa_s *bfa)
5681{
5682}
5683
5684static void
5685bfa_fcdiag_queuetest_timeout(void *cbarg)
5686{
5687 struct bfa_fcdiag_s *fcdiag = cbarg;
5688 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5689
5690 bfa_trc(fcdiag, fcdiag->qtest.all);
5691 bfa_trc(fcdiag, fcdiag->qtest.count);
5692
5693 fcdiag->qtest.timer_active = 0;
5694
5695 res->status = BFA_STATUS_ETIMER;
5696 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5697 if (fcdiag->qtest.all)
5698 res->queue = fcdiag->qtest.all;
5699
5700 bfa_trc(fcdiag, BFA_STATUS_ETIMER);
5701 fcdiag->qtest.status = BFA_STATUS_ETIMER;
5702 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5703 fcdiag->qtest.lock = 0;
5704}
5705
5706static bfa_status_t
5707bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s *fcdiag)
5708{
5709 u32 i;
5710 struct bfi_diag_qtest_req_s *req;
5711
5712 req = bfa_reqq_next(fcdiag->bfa, fcdiag->qtest.queue);
5713 if (!req)
5714 return BFA_STATUS_DEVBUSY;
5715
5716 /* build host command */
5717 bfi_h2i_set(req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_QTEST,
5718 bfa_fn_lpu(fcdiag->bfa));
5719
5720 for (i = 0; i < BFI_LMSG_PL_WSZ; i++)
5721 req->data[i] = QTEST_PAT_DEFAULT;
5722
5723 bfa_trc(fcdiag, fcdiag->qtest.queue);
5724 /* ring door bell */
5725 bfa_reqq_produce(fcdiag->bfa, fcdiag->qtest.queue, req->mh);
5726 return BFA_STATUS_OK;
5727}
5728
5729static void
5730bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s *fcdiag,
5731 bfi_diag_qtest_rsp_t *rsp)
5732{
5733 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5734 bfa_status_t status = BFA_STATUS_OK;
5735 int i;
5736
5737 /* Check timer, should still be active */
5738 if (!fcdiag->qtest.timer_active) {
5739 bfa_trc(fcdiag, fcdiag->qtest.timer_active);
5740 return;
5741 }
5742
5743 /* update count */
5744 fcdiag->qtest.count--;
5745
5746 /* Check result */
5747 for (i = 0; i < BFI_LMSG_PL_WSZ; i++) {
5748 if (rsp->data[i] != ~(QTEST_PAT_DEFAULT)) {
5749 res->status = BFA_STATUS_DATACORRUPTED;
5750 break;
5751 }
5752 }
5753
5754 if (res->status == BFA_STATUS_OK) {
5755 if (fcdiag->qtest.count > 0) {
5756 status = bfa_fcdiag_queuetest_send(fcdiag);
5757 if (status == BFA_STATUS_OK)
5758 return;
5759 else
5760 res->status = status;
5761 } else if (fcdiag->qtest.all > 0 &&
5762 fcdiag->qtest.queue < (BFI_IOC_MAX_CQS - 1)) {
5763 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
5764 fcdiag->qtest.queue++;
5765 status = bfa_fcdiag_queuetest_send(fcdiag);
5766 if (status == BFA_STATUS_OK)
5767 return;
5768 else
5769 res->status = status;
5770 }
5771 }
5772
5773 /* Stop timer when we comp all queue */
5774 if (fcdiag->qtest.timer_active) {
5775 bfa_timer_stop(&fcdiag->qtest.timer);
5776 fcdiag->qtest.timer_active = 0;
5777 }
5778 res->queue = fcdiag->qtest.queue;
5779 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5780 bfa_trc(fcdiag, res->count);
5781 bfa_trc(fcdiag, res->status);
5782 fcdiag->qtest.status = res->status;
5783 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5784 fcdiag->qtest.lock = 0;
5785}
5786
5787static void
5788bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s *fcdiag,
5789 struct bfi_diag_lb_rsp_s *rsp)
5790{
5791 struct bfa_diag_loopback_result_s *res = fcdiag->lb.result;
5792
5793 res->numtxmfrm = be32_to_cpu(rsp->res.numtxmfrm);
5794 res->numosffrm = be32_to_cpu(rsp->res.numosffrm);
5795 res->numrcvfrm = be32_to_cpu(rsp->res.numrcvfrm);
5796 res->badfrminf = be32_to_cpu(rsp->res.badfrminf);
5797 res->badfrmnum = be32_to_cpu(rsp->res.badfrmnum);
5798 res->status = rsp->res.status;
5799 fcdiag->lb.status = rsp->res.status;
5800 bfa_trc(fcdiag, fcdiag->lb.status);
5801 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5802 fcdiag->lb.lock = 0;
5803 bfa_fcdiag_set_busy_status(fcdiag);
5804}
5805
5806static bfa_status_t
5807bfa_fcdiag_loopback_send(struct bfa_fcdiag_s *fcdiag,
5808 struct bfa_diag_loopback_s *loopback)
5809{
5810 struct bfi_diag_lb_req_s *lb_req;
5811
5812 lb_req = bfa_reqq_next(fcdiag->bfa, BFA_REQQ_DIAG);
5813 if (!lb_req)
5814 return BFA_STATUS_DEVBUSY;
5815
5816 /* build host command */
5817 bfi_h2i_set(lb_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LOOPBACK,
5818 bfa_fn_lpu(fcdiag->bfa));
5819
5820 lb_req->lb_mode = loopback->lb_mode;
5821 lb_req->speed = loopback->speed;
5822 lb_req->loopcnt = loopback->loopcnt;
5823 lb_req->pattern = loopback->pattern;
5824
5825 /* ring door bell */
5826 bfa_reqq_produce(fcdiag->bfa, BFA_REQQ_DIAG, lb_req->mh);
5827
5828 bfa_trc(fcdiag, loopback->lb_mode);
5829 bfa_trc(fcdiag, loopback->speed);
5830 bfa_trc(fcdiag, loopback->loopcnt);
5831 bfa_trc(fcdiag, loopback->pattern);
5832 return BFA_STATUS_OK;
5833}
5834
5835/*
5836 * cpe/rme intr handler
5837 */
5838void
5839bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5840{
5841 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5842
5843 switch (msg->mhdr.msg_id) {
5844 case BFI_DIAG_I2H_LOOPBACK:
5845 bfa_fcdiag_loopback_comp(fcdiag,
5846 (struct bfi_diag_lb_rsp_s *) msg);
5847 break;
5848 case BFI_DIAG_I2H_QTEST:
5849 bfa_fcdiag_queuetest_comp(fcdiag, (bfi_diag_qtest_rsp_t *)msg);
5850 break;
Krishna Gudipatie3535462012-09-21 17:26:07 -07005851 case BFI_DIAG_I2H_DPORT:
5852 bfa_dport_req_comp(&fcdiag->dport, (bfi_diag_dport_rsp_t *)msg);
5853 break;
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005854 default:
5855 bfa_trc(fcdiag, msg->mhdr.msg_id);
5856 WARN_ON(1);
5857 }
5858}
5859
5860/*
5861 * Loopback test
5862 *
5863 * @param[in] *bfa - bfa data struct
5864 * @param[in] opmode - port operation mode
5865 * @param[in] speed - port speed
5866 * @param[in] lpcnt - loop count
5867 * @param[in] pat - pattern to build packet
5868 * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
5869 * @param[in] cbfn - callback function
5870 * @param[in] cbarg - callback functioin arg
5871 *
5872 * @param[out]
5873 */
5874bfa_status_t
5875bfa_fcdiag_loopback(struct bfa_s *bfa, enum bfa_port_opmode opmode,
5876 enum bfa_port_speed speed, u32 lpcnt, u32 pat,
5877 struct bfa_diag_loopback_result_s *result, bfa_cb_diag_t cbfn,
5878 void *cbarg)
5879{
5880 struct bfa_diag_loopback_s loopback;
5881 struct bfa_port_attr_s attr;
5882 bfa_status_t status;
5883 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5884
5885 if (!bfa_iocfc_is_operational(bfa))
5886 return BFA_STATUS_IOC_NON_OP;
5887
5888 /* if port is PBC disabled, return error */
5889 if (bfa_fcport_is_pbcdisabled(bfa)) {
5890 bfa_trc(fcdiag, BFA_STATUS_PBC);
5891 return BFA_STATUS_PBC;
5892 }
5893
5894 if (bfa_fcport_is_disabled(bfa) == BFA_FALSE) {
5895 bfa_trc(fcdiag, opmode);
5896 return BFA_STATUS_PORT_NOT_DISABLED;
5897 }
5898
Krishna Gudipatifb778b02011-07-20 17:01:07 -07005899 /*
5900 * Check if input speed is supported by the port mode
5901 */
5902 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
5903 if (!(speed == BFA_PORT_SPEED_1GBPS ||
5904 speed == BFA_PORT_SPEED_2GBPS ||
5905 speed == BFA_PORT_SPEED_4GBPS ||
5906 speed == BFA_PORT_SPEED_8GBPS ||
5907 speed == BFA_PORT_SPEED_16GBPS ||
5908 speed == BFA_PORT_SPEED_AUTO)) {
5909 bfa_trc(fcdiag, speed);
5910 return BFA_STATUS_UNSUPP_SPEED;
5911 }
5912 bfa_fcport_get_attr(bfa, &attr);
5913 bfa_trc(fcdiag, attr.speed_supported);
5914 if (speed > attr.speed_supported)
5915 return BFA_STATUS_UNSUPP_SPEED;
5916 } else {
5917 if (speed != BFA_PORT_SPEED_10GBPS) {
5918 bfa_trc(fcdiag, speed);
5919 return BFA_STATUS_UNSUPP_SPEED;
5920 }
5921 }
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005922
Krishna Gudipatie3535462012-09-21 17:26:07 -07005923 /*
5924 * For CT2, 1G is not supported
5925 */
5926 if ((speed == BFA_PORT_SPEED_1GBPS) &&
5927 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id))) {
5928 bfa_trc(fcdiag, speed);
5929 return BFA_STATUS_UNSUPP_SPEED;
5930 }
5931
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005932 /* For Mezz card, port speed entered needs to be checked */
5933 if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) {
5934 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005935 if (!(speed == BFA_PORT_SPEED_1GBPS ||
5936 speed == BFA_PORT_SPEED_2GBPS ||
5937 speed == BFA_PORT_SPEED_4GBPS ||
5938 speed == BFA_PORT_SPEED_8GBPS ||
5939 speed == BFA_PORT_SPEED_16GBPS ||
5940 speed == BFA_PORT_SPEED_AUTO))
5941 return BFA_STATUS_UNSUPP_SPEED;
5942 } else {
5943 if (speed != BFA_PORT_SPEED_10GBPS)
5944 return BFA_STATUS_UNSUPP_SPEED;
5945 }
5946 }
5947
5948 /* check to see if there is another destructive diag cmd running */
5949 if (fcdiag->lb.lock) {
5950 bfa_trc(fcdiag, fcdiag->lb.lock);
5951 return BFA_STATUS_DEVBUSY;
5952 }
5953
5954 fcdiag->lb.lock = 1;
5955 loopback.lb_mode = opmode;
5956 loopback.speed = speed;
5957 loopback.loopcnt = lpcnt;
5958 loopback.pattern = pat;
5959 fcdiag->lb.result = result;
5960 fcdiag->lb.cbfn = cbfn;
5961 fcdiag->lb.cbarg = cbarg;
5962 memset(result, 0, sizeof(struct bfa_diag_loopback_result_s));
5963 bfa_fcdiag_set_busy_status(fcdiag);
5964
5965 /* Send msg to fw */
5966 status = bfa_fcdiag_loopback_send(fcdiag, &loopback);
5967 return status;
5968}
5969
5970/*
5971 * DIAG queue test command
5972 *
5973 * @param[in] *bfa - bfa data struct
5974 * @param[in] force - 1: don't do ioc op checking
5975 * @param[in] queue - queue no. to test
5976 * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
5977 * @param[in] cbfn - callback function
5978 * @param[in] *cbarg - callback functioin arg
5979 *
5980 * @param[out]
5981 */
5982bfa_status_t
5983bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 force, u32 queue,
5984 struct bfa_diag_qtest_result_s *result, bfa_cb_diag_t cbfn,
5985 void *cbarg)
5986{
5987 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5988 bfa_status_t status;
5989 bfa_trc(fcdiag, force);
5990 bfa_trc(fcdiag, queue);
5991
5992 if (!force && !bfa_iocfc_is_operational(bfa))
5993 return BFA_STATUS_IOC_NON_OP;
5994
5995 /* check to see if there is another destructive diag cmd running */
5996 if (fcdiag->qtest.lock) {
5997 bfa_trc(fcdiag, fcdiag->qtest.lock);
5998 return BFA_STATUS_DEVBUSY;
5999 }
6000
6001 /* Initialization */
6002 fcdiag->qtest.lock = 1;
6003 fcdiag->qtest.cbfn = cbfn;
6004 fcdiag->qtest.cbarg = cbarg;
6005 fcdiag->qtest.result = result;
6006 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
6007
6008 /* Init test results */
6009 fcdiag->qtest.result->status = BFA_STATUS_OK;
6010 fcdiag->qtest.result->count = 0;
6011
6012 /* send */
6013 if (queue < BFI_IOC_MAX_CQS) {
6014 fcdiag->qtest.result->queue = (u8)queue;
6015 fcdiag->qtest.queue = (u8)queue;
6016 fcdiag->qtest.all = 0;
6017 } else {
6018 fcdiag->qtest.result->queue = 0;
6019 fcdiag->qtest.queue = 0;
6020 fcdiag->qtest.all = 1;
6021 }
6022 status = bfa_fcdiag_queuetest_send(fcdiag);
6023
6024 /* Start a timer */
6025 if (status == BFA_STATUS_OK) {
6026 bfa_timer_start(bfa, &fcdiag->qtest.timer,
6027 bfa_fcdiag_queuetest_timeout, fcdiag,
6028 BFA_DIAG_QTEST_TOV);
6029 fcdiag->qtest.timer_active = 1;
6030 }
6031 return status;
6032}
6033
6034/*
6035 * DIAG PLB is running
6036 *
6037 * @param[in] *bfa - bfa data struct
6038 *
6039 * @param[out]
6040 */
6041bfa_status_t
6042bfa_fcdiag_lb_is_running(struct bfa_s *bfa)
6043{
6044 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
6045 return fcdiag->lb.lock ? BFA_STATUS_DIAG_BUSY : BFA_STATUS_OK;
6046}
Krishna Gudipatie3535462012-09-21 17:26:07 -07006047
6048/*
6049 * D-port
6050 */
6051static bfa_boolean_t bfa_dport_send_req(struct bfa_dport_s *dport,
6052 enum bfi_dport_req req);
6053static void
6054bfa_cb_fcdiag_dport(struct bfa_dport_s *dport, bfa_status_t bfa_status)
6055{
6056 if (dport->cbfn != NULL) {
6057 dport->cbfn(dport->cbarg, bfa_status);
6058 dport->cbfn = NULL;
6059 dport->cbarg = NULL;
6060 }
6061}
6062
6063static void
6064bfa_dport_sm_disabled(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
6065{
6066 bfa_trc(dport->bfa, event);
6067
6068 switch (event) {
6069 case BFA_DPORT_SM_ENABLE:
6070 bfa_fcport_dportenable(dport->bfa);
6071 if (bfa_dport_send_req(dport, BFI_DPORT_ENABLE))
6072 bfa_sm_set_state(dport, bfa_dport_sm_enabling);
6073 else
6074 bfa_sm_set_state(dport, bfa_dport_sm_enabling_qwait);
6075 break;
6076
6077 case BFA_DPORT_SM_DISABLE:
6078 /* Already disabled */
6079 break;
6080
6081 case BFA_DPORT_SM_HWFAIL:
6082 /* ignore */
6083 break;
6084
6085 default:
6086 bfa_sm_fault(dport->bfa, event);
6087 }
6088}
6089
6090static void
6091bfa_dport_sm_enabling_qwait(struct bfa_dport_s *dport,
6092 enum bfa_dport_sm_event event)
6093{
6094 bfa_trc(dport->bfa, event);
6095
6096 switch (event) {
6097 case BFA_DPORT_SM_QRESUME:
6098 bfa_sm_set_state(dport, bfa_dport_sm_enabling);
6099 bfa_dport_send_req(dport, BFI_DPORT_ENABLE);
6100 break;
6101
6102 case BFA_DPORT_SM_HWFAIL:
6103 bfa_reqq_wcancel(&dport->reqq_wait);
6104 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6105 bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
6106 break;
6107
6108 default:
6109 bfa_sm_fault(dport->bfa, event);
6110 }
6111}
6112
6113static void
6114bfa_dport_sm_enabling(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
6115{
6116 bfa_trc(dport->bfa, event);
6117
6118 switch (event) {
6119 case BFA_DPORT_SM_FWRSP:
6120 bfa_sm_set_state(dport, bfa_dport_sm_enabled);
6121 break;
6122
6123 case BFA_DPORT_SM_HWFAIL:
6124 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6125 bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
6126 break;
6127
6128 default:
6129 bfa_sm_fault(dport->bfa, event);
6130 }
6131}
6132
6133static void
6134bfa_dport_sm_enabled(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
6135{
6136 bfa_trc(dport->bfa, event);
6137
6138 switch (event) {
6139 case BFA_DPORT_SM_ENABLE:
6140 /* Already enabled */
6141 break;
6142
6143 case BFA_DPORT_SM_DISABLE:
6144 bfa_fcport_dportdisable(dport->bfa);
6145 if (bfa_dport_send_req(dport, BFI_DPORT_DISABLE))
6146 bfa_sm_set_state(dport, bfa_dport_sm_disabling);
6147 else
6148 bfa_sm_set_state(dport, bfa_dport_sm_disabling_qwait);
6149 break;
6150
6151 case BFA_DPORT_SM_HWFAIL:
6152 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6153 break;
6154
6155 default:
6156 bfa_sm_fault(dport->bfa, event);
6157 }
6158}
6159
6160static void
6161bfa_dport_sm_disabling_qwait(struct bfa_dport_s *dport,
6162 enum bfa_dport_sm_event event)
6163{
6164 bfa_trc(dport->bfa, event);
6165
6166 switch (event) {
6167 case BFA_DPORT_SM_QRESUME:
6168 bfa_sm_set_state(dport, bfa_dport_sm_disabling);
6169 bfa_dport_send_req(dport, BFI_DPORT_DISABLE);
6170 break;
6171
6172 case BFA_DPORT_SM_HWFAIL:
6173 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6174 bfa_reqq_wcancel(&dport->reqq_wait);
6175 bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
6176 break;
6177
6178 default:
6179 bfa_sm_fault(dport->bfa, event);
6180 }
6181}
6182
6183static void
6184bfa_dport_sm_disabling(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
6185{
6186 bfa_trc(dport->bfa, event);
6187
6188 switch (event) {
6189 case BFA_DPORT_SM_FWRSP:
6190 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6191 break;
6192
6193 case BFA_DPORT_SM_HWFAIL:
6194 bfa_sm_set_state(dport, bfa_dport_sm_disabled);
6195 bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
6196 break;
6197
6198 default:
6199 bfa_sm_fault(dport->bfa, event);
6200 }
6201}
6202
6203
6204static bfa_boolean_t
6205bfa_dport_send_req(struct bfa_dport_s *dport, enum bfi_dport_req req)
6206{
6207 struct bfi_diag_dport_req_s *m;
6208
6209 /*
6210 * Increment message tag before queue check, so that responses to old
6211 * requests are discarded.
6212 */
6213 dport->msgtag++;
6214
6215 /*
6216 * check for room in queue to send request now
6217 */
6218 m = bfa_reqq_next(dport->bfa, BFA_REQQ_DIAG);
6219 if (!m) {
6220 bfa_reqq_wait(dport->bfa, BFA_REQQ_PORT, &dport->reqq_wait);
6221 return BFA_FALSE;
6222 }
6223
6224 bfi_h2i_set(m->mh, BFI_MC_DIAG, BFI_DIAG_H2I_DPORT,
6225 bfa_fn_lpu(dport->bfa));
6226 m->req = req;
6227 m->msgtag = dport->msgtag;
6228
6229 /*
6230 * queue I/O message to firmware
6231 */
6232 bfa_reqq_produce(dport->bfa, BFA_REQQ_DIAG, m->mh);
6233
6234 return BFA_TRUE;
6235}
6236
6237static void
6238bfa_dport_qresume(void *cbarg)
6239{
6240 struct bfa_dport_s *dport = cbarg;
6241
6242 bfa_sm_send_event(dport, BFA_DPORT_SM_QRESUME);
6243}
6244
6245static void
6246bfa_dport_req_comp(struct bfa_dport_s *dport, bfi_diag_dport_rsp_t *msg)
6247{
6248 bfa_sm_send_event(dport, BFA_DPORT_SM_FWRSP);
6249 bfa_cb_fcdiag_dport(dport, msg->status);
6250}
6251
6252/*
6253 * Dport enable
6254 *
6255 * @param[in] *bfa - bfa data struct
6256 */
6257bfa_status_t
6258bfa_dport_enable(struct bfa_s *bfa, bfa_cb_diag_t cbfn, void *cbarg)
6259{
6260 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
6261 struct bfa_dport_s *dport = &fcdiag->dport;
6262
6263 /*
6264 * Dport is not support in MEZZ card
6265 */
6266 if (bfa_mfg_is_mezz(dport->bfa->ioc.attr->card_type)) {
6267 bfa_trc(dport->bfa, BFA_STATUS_PBC);
6268 return BFA_STATUS_CMD_NOTSUPP_MEZZ;
6269 }
6270
6271 /*
6272 * Check to see if IOC is down
6273 */
6274 if (!bfa_iocfc_is_operational(bfa))
6275 return BFA_STATUS_IOC_NON_OP;
6276
6277 /* if port is PBC disabled, return error */
6278 if (bfa_fcport_is_pbcdisabled(bfa)) {
6279 bfa_trc(dport->bfa, BFA_STATUS_PBC);
6280 return BFA_STATUS_PBC;
6281 }
6282
6283 /*
6284 * Check if port mode is FC port
6285 */
6286 if (bfa_ioc_get_type(&bfa->ioc) != BFA_IOC_TYPE_FC) {
6287 bfa_trc(dport->bfa, bfa_ioc_get_type(&bfa->ioc));
6288 return BFA_STATUS_CMD_NOTSUPP_CNA;
6289 }
6290
6291 /*
6292 * Check if port is in LOOP mode
6293 */
6294 if ((bfa_fcport_get_cfg_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) ||
6295 (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)) {
6296 bfa_trc(dport->bfa, 0);
6297 return BFA_STATUS_TOPOLOGY_LOOP;
6298 }
6299
6300 /*
6301 * Check if port is TRUNK mode
6302 */
6303 if (bfa_fcport_is_trunk_enabled(bfa)) {
6304 bfa_trc(dport->bfa, 0);
6305 return BFA_STATUS_ERROR_TRUNK_ENABLED;
6306 }
6307
6308 /*
6309 * Check to see if port is disable or in dport state
6310 */
6311 if ((bfa_fcport_is_disabled(bfa) == BFA_FALSE) &&
6312 (bfa_fcport_is_dport(bfa) == BFA_FALSE)) {
6313 bfa_trc(dport->bfa, 0);
6314 return BFA_STATUS_PORT_NOT_DISABLED;
6315 }
6316
6317 /*
6318 * Check if dport is busy
6319 */
6320 if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) ||
6321 bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait) ||
6322 bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) ||
6323 bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait)) {
6324 return BFA_STATUS_DEVBUSY;
6325 }
6326
6327 /*
6328 * Check if dport is already enabled
6329 */
6330 if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabled)) {
6331 bfa_trc(dport->bfa, 0);
6332 return BFA_STATUS_DPORT_ENABLED;
6333 }
6334
6335 dport->cbfn = cbfn;
6336 dport->cbarg = cbarg;
6337
6338 bfa_sm_send_event(dport, BFA_DPORT_SM_ENABLE);
6339 return BFA_STATUS_OK;
6340}
6341
6342/*
6343 * Dport disable
6344 *
6345 * @param[in] *bfa - bfa data struct
6346 */
6347bfa_status_t
6348bfa_dport_disable(struct bfa_s *bfa, bfa_cb_diag_t cbfn, void *cbarg)
6349{
6350 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
6351 struct bfa_dport_s *dport = &fcdiag->dport;
6352
6353 if (bfa_ioc_is_disabled(&bfa->ioc))
6354 return BFA_STATUS_IOC_DISABLED;
6355
6356 /* if port is PBC disabled, return error */
6357 if (bfa_fcport_is_pbcdisabled(bfa)) {
6358 bfa_trc(dport->bfa, BFA_STATUS_PBC);
6359 return BFA_STATUS_PBC;
6360 }
6361
6362 /*
6363 * Check to see if port is disable or in dport state
6364 */
6365 if ((bfa_fcport_is_disabled(bfa) == BFA_FALSE) &&
6366 (bfa_fcport_is_dport(bfa) == BFA_FALSE)) {
6367 bfa_trc(dport->bfa, 0);
6368 return BFA_STATUS_PORT_NOT_DISABLED;
6369 }
6370
6371 /*
6372 * Check if dport is busy
6373 */
6374 if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) ||
6375 bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait) ||
6376 bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) ||
6377 bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait))
6378 return BFA_STATUS_DEVBUSY;
6379
6380 /*
6381 * Check if dport is already disabled
6382 */
6383 if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabled)) {
6384 bfa_trc(dport->bfa, 0);
6385 return BFA_STATUS_DPORT_DISABLED;
6386 }
6387
6388 dport->cbfn = cbfn;
6389 dport->cbarg = cbarg;
6390
6391 bfa_sm_send_event(dport, BFA_DPORT_SM_DISABLE);
6392 return BFA_STATUS_OK;
6393}
6394
6395/*
6396 * Get D-port state
6397 *
6398 * @param[in] *bfa - bfa data struct
6399 */
6400
6401bfa_status_t
6402bfa_dport_get_state(struct bfa_s *bfa, enum bfa_dport_state *state)
6403{
6404 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
6405 struct bfa_dport_s *dport = &fcdiag->dport;
6406
6407 if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabled))
6408 *state = BFA_DPORT_ST_ENABLED;
6409 else if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) ||
6410 bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait))
6411 *state = BFA_DPORT_ST_ENABLING;
6412 else if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabled))
6413 *state = BFA_DPORT_ST_DISABLED;
6414 else if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) ||
6415 bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait))
6416 *state = BFA_DPORT_ST_DISABLING;
6417 else {
6418 bfa_trc(dport->bfa, BFA_STATUS_EINVAL);
6419 return BFA_STATUS_EINVAL;
6420 }
6421 return BFA_STATUS_OK;
6422}