blob: 6583b2d94f6426bb6777e4d8bf76334734d1f47c [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 */
70};
71
Jing Huang5fbe25c2010-10-18 17:17:23 -070072/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070073 * BFA port link notification state machine events
74 */
75
76enum bfa_fcport_ln_sm_event {
77 BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
78 BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
79 BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
80};
81
Jing Huang5fbe25c2010-10-18 17:17:23 -070082/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070083 * RPORT related definitions
84 */
85#define bfa_rport_offline_cb(__rp) do { \
86 if ((__rp)->bfa->fcs) \
87 bfa_cb_rport_offline((__rp)->rport_drv); \
88 else { \
89 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
90 __bfa_cb_rport_offline, (__rp)); \
91 } \
92} while (0)
93
94#define bfa_rport_online_cb(__rp) do { \
95 if ((__rp)->bfa->fcs) \
96 bfa_cb_rport_online((__rp)->rport_drv); \
97 else { \
98 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
99 __bfa_cb_rport_online, (__rp)); \
100 } \
101} while (0)
102
Jing Huang5fbe25c2010-10-18 17:17:23 -0700103/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700104 * forward declarations FCXP related functions
105 */
106static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete);
107static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
108 struct bfi_fcxp_send_rsp_s *fcxp_rsp);
109static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen,
110 struct bfa_fcxp_s *fcxp, struct fchs_s *fchs);
111static void bfa_fcxp_qresume(void *cbarg);
112static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp,
113 struct bfi_fcxp_send_req_s *send_req);
114
Jing Huang5fbe25c2010-10-18 17:17:23 -0700115/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700116 * forward declarations for LPS functions
117 */
Krishna Gudipati45070252011-06-24 20:24:29 -0700118static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg,
119 struct bfa_meminfo_s *minfo, struct bfa_s *bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700120static void bfa_lps_attach(struct bfa_s *bfa, void *bfad,
121 struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700122 struct bfa_pcidev_s *pcidev);
123static void bfa_lps_detach(struct bfa_s *bfa);
124static void bfa_lps_start(struct bfa_s *bfa);
125static void bfa_lps_stop(struct bfa_s *bfa);
126static void bfa_lps_iocdisable(struct bfa_s *bfa);
127static void bfa_lps_login_rsp(struct bfa_s *bfa,
128 struct bfi_lps_login_rsp_s *rsp);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700129static void bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130static void bfa_lps_logout_rsp(struct bfa_s *bfa,
131 struct bfi_lps_logout_rsp_s *rsp);
132static void bfa_lps_reqq_resume(void *lps_arg);
133static void bfa_lps_free(struct bfa_lps_s *lps);
134static void bfa_lps_send_login(struct bfa_lps_s *lps);
135static void bfa_lps_send_logout(struct bfa_lps_s *lps);
Krishna Gudipatib7044952010-12-13 16:17:42 -0800136static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700137static void bfa_lps_login_comp(struct bfa_lps_s *lps);
138static void bfa_lps_logout_comp(struct bfa_lps_s *lps);
139static void bfa_lps_cvl_event(struct bfa_lps_s *lps);
140
Jing Huang5fbe25c2010-10-18 17:17:23 -0700141/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700142 * forward declaration for LPS state machine
143 */
144static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event);
145static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event);
146static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event
147 event);
148static void bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event);
Krishna Gudipatib7044952010-12-13 16:17:42 -0800149static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps,
150 enum bfa_lps_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700151static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event);
152static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event
153 event);
154
Jing Huang5fbe25c2010-10-18 17:17:23 -0700155/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700156 * forward declaration for FC Port functions
157 */
158static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
159static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
160static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
161static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
162static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
163static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
164static void bfa_fcport_scn(struct bfa_fcport_s *fcport,
165 enum bfa_port_linkstate event, bfa_boolean_t trunk);
166static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
167 enum bfa_port_linkstate event);
168static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
169static void bfa_fcport_stats_get_timeout(void *cbarg);
170static void bfa_fcport_stats_clr_timeout(void *cbarg);
171static void bfa_trunk_iocdisable(struct bfa_s *bfa);
172
Jing Huang5fbe25c2010-10-18 17:17:23 -0700173/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700174 * forward declaration for FC PORT state machine
175 */
176static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
177 enum bfa_fcport_sm_event event);
178static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
179 enum bfa_fcport_sm_event event);
180static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
181 enum bfa_fcport_sm_event event);
182static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
183 enum bfa_fcport_sm_event event);
184static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
185 enum bfa_fcport_sm_event event);
186static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
187 enum bfa_fcport_sm_event event);
188static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
189 enum bfa_fcport_sm_event event);
190static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
191 enum bfa_fcport_sm_event event);
192static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
193 enum bfa_fcport_sm_event event);
194static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
195 enum bfa_fcport_sm_event event);
196static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
197 enum bfa_fcport_sm_event event);
198static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
199 enum bfa_fcport_sm_event event);
200
201static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
202 enum bfa_fcport_ln_sm_event event);
203static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
204 enum bfa_fcport_ln_sm_event event);
205static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
206 enum bfa_fcport_ln_sm_event event);
207static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
208 enum bfa_fcport_ln_sm_event event);
209static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
210 enum bfa_fcport_ln_sm_event event);
211static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
212 enum bfa_fcport_ln_sm_event event);
213static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
214 enum bfa_fcport_ln_sm_event event);
215
216static struct bfa_sm_table_s hal_port_sm_table[] = {
217 {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT},
218 {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT},
219 {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING},
220 {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN},
221 {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP},
222 {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT},
223 {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT},
224 {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING},
225 {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED},
226 {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED},
227 {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN},
228 {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN},
229};
230
231
Jing Huang5fbe25c2010-10-18 17:17:23 -0700232/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700233 * forward declaration for RPORT related functions
234 */
235static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod);
236static void bfa_rport_free(struct bfa_rport_s *rport);
237static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp);
238static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp);
239static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp);
240static void __bfa_cb_rport_online(void *cbarg,
241 bfa_boolean_t complete);
242static void __bfa_cb_rport_offline(void *cbarg,
243 bfa_boolean_t complete);
244
Jing Huang5fbe25c2010-10-18 17:17:23 -0700245/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700246 * forward declaration for RPORT state machine
247 */
248static void bfa_rport_sm_uninit(struct bfa_rport_s *rp,
249 enum bfa_rport_event event);
250static void bfa_rport_sm_created(struct bfa_rport_s *rp,
251 enum bfa_rport_event event);
252static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp,
253 enum bfa_rport_event event);
254static void bfa_rport_sm_online(struct bfa_rport_s *rp,
255 enum bfa_rport_event event);
256static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp,
257 enum bfa_rport_event event);
258static void bfa_rport_sm_offline(struct bfa_rport_s *rp,
259 enum bfa_rport_event event);
260static void bfa_rport_sm_deleting(struct bfa_rport_s *rp,
261 enum bfa_rport_event event);
262static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
263 enum bfa_rport_event event);
264static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
265 enum bfa_rport_event event);
266static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp,
267 enum bfa_rport_event event);
268static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp,
269 enum bfa_rport_event event);
270static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp,
271 enum bfa_rport_event event);
272static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp,
273 enum bfa_rport_event event);
274
Jing Huang5fbe25c2010-10-18 17:17:23 -0700275/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700276 * PLOG related definitions
277 */
278static int
279plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
280{
281 if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
282 (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
283 return 1;
284
285 if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
286 (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
287 return 1;
288
289 return 0;
290}
291
Maggie Zhangf16a1752010-12-09 19:12:32 -0800292static u64
293bfa_get_log_time(void)
294{
295 u64 system_time = 0;
296 struct timeval tv;
297 do_gettimeofday(&tv);
298
299 /* We are interested in seconds only. */
300 system_time = tv.tv_sec;
301 return system_time;
302}
303
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700304static void
305bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
306{
307 u16 tail;
308 struct bfa_plog_rec_s *pl_recp;
309
310 if (plog->plog_enabled == 0)
311 return;
312
313 if (plkd_validate_logrec(pl_rec)) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800314 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700315 return;
316 }
317
318 tail = plog->tail;
319
320 pl_recp = &(plog->plog_recs[tail]);
321
Jing Huang6a18b162010-10-18 17:08:54 -0700322 memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700323
Maggie Zhangf16a1752010-12-09 19:12:32 -0800324 pl_recp->tv = bfa_get_log_time();
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700325 BFA_PL_LOG_REC_INCR(plog->tail);
326
327 if (plog->head == plog->tail)
328 BFA_PL_LOG_REC_INCR(plog->head);
329}
330
331void
332bfa_plog_init(struct bfa_plog_s *plog)
333{
Jing Huang6a18b162010-10-18 17:08:54 -0700334 memset((char *)plog, 0, sizeof(struct bfa_plog_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700335
Jing Huang6a18b162010-10-18 17:08:54 -0700336 memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700337 plog->head = plog->tail = 0;
338 plog->plog_enabled = 1;
339}
340
341void
342bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
343 enum bfa_plog_eid event,
344 u16 misc, char *log_str)
345{
346 struct bfa_plog_rec_s lp;
347
348 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700349 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700350 lp.mid = mid;
351 lp.eid = event;
352 lp.log_type = BFA_PL_LOG_TYPE_STRING;
353 lp.misc = misc;
354 strncpy(lp.log_entry.string_log, log_str,
355 BFA_PL_STRING_LOG_SZ - 1);
356 lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
357 bfa_plog_add(plog, &lp);
358 }
359}
360
361void
362bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
363 enum bfa_plog_eid event,
364 u16 misc, u32 *intarr, u32 num_ints)
365{
366 struct bfa_plog_rec_s lp;
367 u32 i;
368
369 if (num_ints > BFA_PL_INT_LOG_SZ)
370 num_ints = BFA_PL_INT_LOG_SZ;
371
372 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700373 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700374 lp.mid = mid;
375 lp.eid = event;
376 lp.log_type = BFA_PL_LOG_TYPE_INT;
377 lp.misc = misc;
378
379 for (i = 0; i < num_ints; i++)
Jing Huang6a18b162010-10-18 17:08:54 -0700380 lp.log_entry.int_log[i] = intarr[i];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700381
382 lp.log_num_ints = (u8) num_ints;
383
384 bfa_plog_add(plog, &lp);
385 }
386}
387
388void
389bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
390 enum bfa_plog_eid event,
391 u16 misc, struct fchs_s *fchdr)
392{
393 struct bfa_plog_rec_s lp;
394 u32 *tmp_int = (u32 *) fchdr;
395 u32 ints[BFA_PL_INT_LOG_SZ];
396
397 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700398 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700399
400 ints[0] = tmp_int[0];
401 ints[1] = tmp_int[1];
402 ints[2] = tmp_int[4];
403
404 bfa_plog_intarr(plog, mid, event, misc, ints, 3);
405 }
406}
407
408void
409bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
410 enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
411 u32 pld_w0)
412{
413 struct bfa_plog_rec_s lp;
414 u32 *tmp_int = (u32 *) fchdr;
415 u32 ints[BFA_PL_INT_LOG_SZ];
416
417 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700418 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700419
420 ints[0] = tmp_int[0];
421 ints[1] = tmp_int[1];
422 ints[2] = tmp_int[4];
423 ints[3] = pld_w0;
424
425 bfa_plog_intarr(plog, mid, event, misc, ints, 4);
426 }
427}
428
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700429
Jing Huang5fbe25c2010-10-18 17:17:23 -0700430/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700431 * fcxp_pvt BFA FCXP private functions
432 */
433
434static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700435claim_fcxps_mem(struct bfa_fcxp_mod_s *mod)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700436{
437 u16 i;
438 struct bfa_fcxp_s *fcxp;
439
Krishna Gudipati45070252011-06-24 20:24:29 -0700440 fcxp = (struct bfa_fcxp_s *) bfa_mem_kva_curp(mod);
Jing Huang6a18b162010-10-18 17:08:54 -0700441 memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700442
443 INIT_LIST_HEAD(&mod->fcxp_free_q);
444 INIT_LIST_HEAD(&mod->fcxp_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700445 INIT_LIST_HEAD(&mod->fcxp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700446
447 mod->fcxp_list = fcxp;
448
449 for (i = 0; i < mod->num_fcxps; i++) {
450 fcxp->fcxp_mod = mod;
451 fcxp->fcxp_tag = i;
452
453 list_add_tail(&fcxp->qe, &mod->fcxp_free_q);
454 bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp);
455 fcxp->reqq_waiting = BFA_FALSE;
456
457 fcxp = fcxp + 1;
458 }
459
Krishna Gudipati45070252011-06-24 20:24:29 -0700460 bfa_mem_kva_curp(mod) = (void *)fcxp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700461}
462
463static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700464bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
465 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700466{
Krishna Gudipati45070252011-06-24 20:24:29 -0700467 struct bfa_fcxp_mod_s *fcxp_mod = BFA_FCXP_MOD(bfa);
468 struct bfa_mem_kva_s *fcxp_kva = BFA_MEM_FCXP_KVA(bfa);
469 struct bfa_mem_dma_s *seg_ptr;
470 u16 nsegs, idx, per_seg_fcxp;
471 u16 num_fcxps = cfg->fwcfg.num_fcxp_reqs;
472 u32 per_fcxp_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700473
Krishna Gudipati45070252011-06-24 20:24:29 -0700474 if (num_fcxps == 0)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700475 return;
476
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700477 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -0700478 per_fcxp_sz = 2 * BFA_FCXP_MAX_IBUF_SZ;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700479 else
Krishna Gudipati45070252011-06-24 20:24:29 -0700480 per_fcxp_sz = BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700481
Krishna Gudipati45070252011-06-24 20:24:29 -0700482 /* dma memory */
483 nsegs = BFI_MEM_DMA_NSEGS(num_fcxps, per_fcxp_sz);
484 per_seg_fcxp = BFI_MEM_NREQS_SEG(per_fcxp_sz);
485
486 bfa_mem_dma_seg_iter(fcxp_mod, seg_ptr, nsegs, idx) {
487 if (num_fcxps >= per_seg_fcxp) {
488 num_fcxps -= per_seg_fcxp;
489 bfa_mem_dma_setup(minfo, seg_ptr,
490 per_seg_fcxp * per_fcxp_sz);
491 } else
492 bfa_mem_dma_setup(minfo, seg_ptr,
493 num_fcxps * per_fcxp_sz);
494 }
495
496 /* kva memory */
497 bfa_mem_kva_setup(minfo, fcxp_kva,
498 cfg->fwcfg.num_fcxp_reqs * sizeof(struct bfa_fcxp_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700499}
500
501static void
502bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -0700503 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700504{
505 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
506
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700507 mod->bfa = bfa;
508 mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
509
Jing Huang5fbe25c2010-10-18 17:17:23 -0700510 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700511 * Initialize FCXP request and response payload sizes.
512 */
513 mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
514 if (!cfg->drvcfg.min_cfg)
515 mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ;
516
517 INIT_LIST_HEAD(&mod->wait_q);
518
Krishna Gudipati45070252011-06-24 20:24:29 -0700519 claim_fcxps_mem(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700520}
521
522static void
523bfa_fcxp_detach(struct bfa_s *bfa)
524{
525}
526
527static void
528bfa_fcxp_start(struct bfa_s *bfa)
529{
530}
531
532static void
533bfa_fcxp_stop(struct bfa_s *bfa)
534{
535}
536
537static void
538bfa_fcxp_iocdisable(struct bfa_s *bfa)
539{
540 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
541 struct bfa_fcxp_s *fcxp;
542 struct list_head *qe, *qen;
543
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700544 /* Enqueue unused fcxp resources to free_q */
545 list_splice_tail_init(&mod->fcxp_unused_q, &mod->fcxp_free_q);
546
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700547 list_for_each_safe(qe, qen, &mod->fcxp_active_q) {
548 fcxp = (struct bfa_fcxp_s *) qe;
549 if (fcxp->caller == NULL) {
550 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
551 BFA_STATUS_IOC_FAILURE, 0, 0, NULL);
552 bfa_fcxp_free(fcxp);
553 } else {
554 fcxp->rsp_status = BFA_STATUS_IOC_FAILURE;
555 bfa_cb_queue(bfa, &fcxp->hcb_qe,
556 __bfa_fcxp_send_cbfn, fcxp);
557 }
558 }
559}
560
561static struct bfa_fcxp_s *
562bfa_fcxp_get(struct bfa_fcxp_mod_s *fm)
563{
564 struct bfa_fcxp_s *fcxp;
565
566 bfa_q_deq(&fm->fcxp_free_q, &fcxp);
567
568 if (fcxp)
569 list_add_tail(&fcxp->qe, &fm->fcxp_active_q);
570
571 return fcxp;
572}
573
574static void
575bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
576 struct bfa_s *bfa,
577 u8 *use_ibuf,
578 u32 *nr_sgles,
579 bfa_fcxp_get_sgaddr_t *r_sga_cbfn,
580 bfa_fcxp_get_sglen_t *r_sglen_cbfn,
581 struct list_head *r_sgpg_q,
582 int n_sgles,
583 bfa_fcxp_get_sgaddr_t sga_cbfn,
584 bfa_fcxp_get_sglen_t sglen_cbfn)
585{
586
Jing Huangd4b671c2010-12-26 21:46:35 -0800587 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700588
589 bfa_trc(bfa, fcxp->fcxp_tag);
590
591 if (n_sgles == 0) {
592 *use_ibuf = 1;
593 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800594 WARN_ON(*sga_cbfn == NULL);
595 WARN_ON(*sglen_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700596
597 *use_ibuf = 0;
598 *r_sga_cbfn = sga_cbfn;
599 *r_sglen_cbfn = sglen_cbfn;
600
601 *nr_sgles = n_sgles;
602
603 /*
604 * alloc required sgpgs
605 */
606 if (n_sgles > BFI_SGE_INLINE)
Jing Huangd4b671c2010-12-26 21:46:35 -0800607 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700608 }
609
610}
611
612static void
613bfa_fcxp_init(struct bfa_fcxp_s *fcxp,
614 void *caller, struct bfa_s *bfa, int nreq_sgles,
615 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
616 bfa_fcxp_get_sglen_t req_sglen_cbfn,
617 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
618 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
619{
620
Jing Huangd4b671c2010-12-26 21:46:35 -0800621 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700622
623 bfa_trc(bfa, fcxp->fcxp_tag);
624
625 fcxp->caller = caller;
626
627 bfa_fcxp_init_reqrsp(fcxp, bfa,
628 &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn,
629 &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q,
630 nreq_sgles, req_sga_cbfn, req_sglen_cbfn);
631
632 bfa_fcxp_init_reqrsp(fcxp, bfa,
633 &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn,
634 &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q,
635 nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn);
636
637}
638
639static void
640bfa_fcxp_put(struct bfa_fcxp_s *fcxp)
641{
642 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
643 struct bfa_fcxp_wqe_s *wqe;
644
645 bfa_q_deq(&mod->wait_q, &wqe);
646 if (wqe) {
647 bfa_trc(mod->bfa, fcxp->fcxp_tag);
648
649 bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles,
650 wqe->nrsp_sgles, wqe->req_sga_cbfn,
651 wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn,
652 wqe->rsp_sglen_cbfn);
653
654 wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp);
655 return;
656 }
657
Jing Huangd4b671c2010-12-26 21:46:35 -0800658 WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700659 list_del(&fcxp->qe);
660 list_add_tail(&fcxp->qe, &mod->fcxp_free_q);
661}
662
663static void
664bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
665 bfa_status_t req_status, u32 rsp_len,
666 u32 resid_len, struct fchs_s *rsp_fchs)
667{
668 /* discarded fcxp completion */
669}
670
671static void
672__bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete)
673{
674 struct bfa_fcxp_s *fcxp = cbarg;
675
676 if (complete) {
677 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
678 fcxp->rsp_status, fcxp->rsp_len,
679 fcxp->residue_len, &fcxp->rsp_fchs);
680 } else {
681 bfa_fcxp_free(fcxp);
682 }
683}
684
685static void
686hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
687{
688 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
689 struct bfa_fcxp_s *fcxp;
Jing Huangba816ea2010-10-18 17:10:50 -0700690 u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700691
692 bfa_trc(bfa, fcxp_tag);
693
Jing Huangba816ea2010-10-18 17:10:50 -0700694 fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700695
Jing Huang5fbe25c2010-10-18 17:17:23 -0700696 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700697 * @todo f/w should not set residue to non-0 when everything
698 * is received.
699 */
700 if (fcxp_rsp->req_status == BFA_STATUS_OK)
701 fcxp_rsp->residue_len = 0;
702 else
Jing Huangba816ea2010-10-18 17:10:50 -0700703 fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700704
705 fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
706
Jing Huangd4b671c2010-12-26 21:46:35 -0800707 WARN_ON(fcxp->send_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700708
709 hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp);
710
711 if (fcxp->send_cbfn != NULL) {
712 bfa_trc(mod->bfa, (NULL == fcxp->caller));
713 if (fcxp->caller == NULL) {
714 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
715 fcxp_rsp->req_status, fcxp_rsp->rsp_len,
716 fcxp_rsp->residue_len, &fcxp_rsp->fchs);
717 /*
718 * fcxp automatically freed on return from the callback
719 */
720 bfa_fcxp_free(fcxp);
721 } else {
722 fcxp->rsp_status = fcxp_rsp->req_status;
723 fcxp->rsp_len = fcxp_rsp->rsp_len;
724 fcxp->residue_len = fcxp_rsp->residue_len;
725 fcxp->rsp_fchs = fcxp_rsp->fchs;
726
727 bfa_cb_queue(bfa, &fcxp->hcb_qe,
728 __bfa_fcxp_send_cbfn, fcxp);
729 }
730 } else {
731 bfa_trc(bfa, (NULL == fcxp->send_cbfn));
732 }
733}
734
735static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700736hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp,
737 struct fchs_s *fchs)
738{
739 /*
740 * TODO: TX ox_id
741 */
742 if (reqlen > 0) {
743 if (fcxp->use_ireqbuf) {
744 u32 pld_w0 =
745 *((u32 *) BFA_FCXP_REQ_PLD(fcxp));
746
747 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
748 BFA_PL_EID_TX,
749 reqlen + sizeof(struct fchs_s), fchs,
750 pld_w0);
751 } else {
752 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
753 BFA_PL_EID_TX,
754 reqlen + sizeof(struct fchs_s),
755 fchs);
756 }
757 } else {
758 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX,
759 reqlen + sizeof(struct fchs_s), fchs);
760 }
761}
762
763static void
764hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
765 struct bfi_fcxp_send_rsp_s *fcxp_rsp)
766{
767 if (fcxp_rsp->rsp_len > 0) {
768 if (fcxp->use_irspbuf) {
769 u32 pld_w0 =
770 *((u32 *) BFA_FCXP_RSP_PLD(fcxp));
771
772 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
773 BFA_PL_EID_RX,
774 (u16) fcxp_rsp->rsp_len,
775 &fcxp_rsp->fchs, pld_w0);
776 } else {
777 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
778 BFA_PL_EID_RX,
779 (u16) fcxp_rsp->rsp_len,
780 &fcxp_rsp->fchs);
781 }
782 } else {
783 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX,
784 (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs);
785 }
786}
787
Jing Huang5fbe25c2010-10-18 17:17:23 -0700788/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700789 * Handler to resume sending fcxp when space in available in cpe queue.
790 */
791static void
792bfa_fcxp_qresume(void *cbarg)
793{
794 struct bfa_fcxp_s *fcxp = cbarg;
795 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
796 struct bfi_fcxp_send_req_s *send_req;
797
798 fcxp->reqq_waiting = BFA_FALSE;
799 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
800 bfa_fcxp_queue(fcxp, send_req);
801}
802
Jing Huang5fbe25c2010-10-18 17:17:23 -0700803/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700804 * Queue fcxp send request to foimrware.
805 */
806static void
807bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
808{
809 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
810 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
811 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
812 struct bfa_rport_s *rport = reqi->bfa_rport;
813
814 bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700815 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700816
Jing Huangba816ea2010-10-18 17:10:50 -0700817 send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700818 if (rport) {
819 send_req->rport_fw_hndl = rport->fw_handle;
Jing Huangba816ea2010-10-18 17:10:50 -0700820 send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700821 if (send_req->max_frmsz == 0)
Jing Huangba816ea2010-10-18 17:10:50 -0700822 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700823 } else {
824 send_req->rport_fw_hndl = 0;
Jing Huangba816ea2010-10-18 17:10:50 -0700825 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700826 }
827
Jing Huangba816ea2010-10-18 17:10:50 -0700828 send_req->vf_id = cpu_to_be16(reqi->vf_id);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700829 send_req->lp_fwtag = bfa_lps_get_fwtag(bfa, reqi->lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700830 send_req->class = reqi->class;
831 send_req->rsp_timeout = rspi->rsp_timeout;
832 send_req->cts = reqi->cts;
833 send_req->fchs = reqi->fchs;
834
Jing Huangba816ea2010-10-18 17:10:50 -0700835 send_req->req_len = cpu_to_be32(reqi->req_tot_len);
836 send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700837
838 /*
839 * setup req sgles
840 */
841 if (fcxp->use_ireqbuf == 1) {
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700842 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700843 BFA_FCXP_REQ_PLD_PA(fcxp));
844 } else {
845 if (fcxp->nreq_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800846 WARN_ON(fcxp->nreq_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700847 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
848 fcxp->req_sga_cbfn(fcxp->caller, 0));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700849 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800850 WARN_ON(reqi->req_tot_len != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700851 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700852 }
853 }
854
855 /*
856 * setup rsp sgles
857 */
858 if (fcxp->use_irspbuf == 1) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800859 WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700860
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700861 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700862 BFA_FCXP_RSP_PLD_PA(fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700863 } else {
864 if (fcxp->nrsp_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800865 WARN_ON(fcxp->nrsp_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700866 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
867 fcxp->rsp_sga_cbfn(fcxp->caller, 0));
868
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700869 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800870 WARN_ON(rspi->rsp_maxlen != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700871 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700872 }
873 }
874
875 hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs);
876
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700877 bfa_reqq_produce(bfa, BFA_REQQ_FCXP, send_req->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700878
879 bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP));
880 bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
881}
882
Jing Huang5fbe25c2010-10-18 17:17:23 -0700883/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700884 * Allocate an FCXP instance to send a response or to send a request
885 * that has a response. Request/response buffers are allocated by caller.
886 *
887 * @param[in] bfa BFA bfa instance
888 * @param[in] nreq_sgles Number of SG elements required for request
889 * buffer. 0, if fcxp internal buffers are used.
890 * Use bfa_fcxp_get_reqbuf() to get the
891 * internal req buffer.
892 * @param[in] req_sgles SG elements describing request buffer. Will be
893 * copied in by BFA and hence can be freed on
894 * return from this function.
895 * @param[in] get_req_sga function ptr to be called to get a request SG
896 * Address (given the sge index).
897 * @param[in] get_req_sglen function ptr to be called to get a request SG
898 * len (given the sge index).
899 * @param[in] get_rsp_sga function ptr to be called to get a response SG
900 * Address (given the sge index).
901 * @param[in] get_rsp_sglen function ptr to be called to get a response SG
902 * len (given the sge index).
903 *
904 * @return FCXP instance. NULL on failure.
905 */
906struct bfa_fcxp_s *
907bfa_fcxp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
908 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
909 bfa_fcxp_get_sglen_t req_sglen_cbfn,
910 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
911 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
912{
913 struct bfa_fcxp_s *fcxp = NULL;
914
Jing Huangd4b671c2010-12-26 21:46:35 -0800915 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700916
917 fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa));
918 if (fcxp == NULL)
919 return NULL;
920
921 bfa_trc(bfa, fcxp->fcxp_tag);
922
923 bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn,
924 req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn);
925
926 return fcxp;
927}
928
Jing Huang5fbe25c2010-10-18 17:17:23 -0700929/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700930 * Get the internal request buffer pointer
931 *
932 * @param[in] fcxp BFA fcxp pointer
933 *
934 * @return pointer to the internal request buffer
935 */
936void *
937bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp)
938{
939 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
940 void *reqbuf;
941
Jing Huangd4b671c2010-12-26 21:46:35 -0800942 WARN_ON(fcxp->use_ireqbuf != 1);
Krishna Gudipati45070252011-06-24 20:24:29 -0700943 reqbuf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
944 mod->req_pld_sz + mod->rsp_pld_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700945 return reqbuf;
946}
947
948u32
949bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
950{
951 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
952
953 return mod->req_pld_sz;
954}
955
Jing Huang5fbe25c2010-10-18 17:17:23 -0700956/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700957 * Get the internal response buffer pointer
958 *
959 * @param[in] fcxp BFA fcxp pointer
960 *
961 * @return pointer to the internal request buffer
962 */
963void *
964bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
965{
966 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
Krishna Gudipati45070252011-06-24 20:24:29 -0700967 void *fcxp_buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700968
Jing Huangd4b671c2010-12-26 21:46:35 -0800969 WARN_ON(fcxp->use_irspbuf != 1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700970
Krishna Gudipati45070252011-06-24 20:24:29 -0700971 fcxp_buf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
972 mod->req_pld_sz + mod->rsp_pld_sz);
973
974 /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
975 return ((u8 *) fcxp_buf) + mod->req_pld_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700976}
977
Jing Huang5fbe25c2010-10-18 17:17:23 -0700978/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800979 * Free the BFA FCXP
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700980 *
981 * @param[in] fcxp BFA fcxp pointer
982 *
983 * @return void
984 */
985void
986bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
987{
988 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
989
Jing Huangd4b671c2010-12-26 21:46:35 -0800990 WARN_ON(fcxp == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700991 bfa_trc(mod->bfa, fcxp->fcxp_tag);
992 bfa_fcxp_put(fcxp);
993}
994
Jing Huang5fbe25c2010-10-18 17:17:23 -0700995/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700996 * Send a FCXP request
997 *
998 * @param[in] fcxp BFA fcxp pointer
999 * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
1000 * @param[in] vf_id virtual Fabric ID
1001 * @param[in] lp_tag lport tag
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001002 * @param[in] cts use Continuous sequence
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001003 * @param[in] cos fc Class of Service
1004 * @param[in] reqlen request length, does not include FCHS length
1005 * @param[in] fchs fc Header Pointer. The header content will be copied
1006 * in by BFA.
1007 *
1008 * @param[in] cbfn call back function to be called on receiving
1009 * the response
1010 * @param[in] cbarg arg for cbfn
1011 * @param[in] rsp_timeout
1012 * response timeout
1013 *
1014 * @return bfa_status_t
1015 */
1016void
1017bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
1018 u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos,
1019 u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn,
1020 void *cbarg, u32 rsp_maxlen, u8 rsp_timeout)
1021{
1022 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
1023 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
1024 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
1025 struct bfi_fcxp_send_req_s *send_req;
1026
1027 bfa_trc(bfa, fcxp->fcxp_tag);
1028
Jing Huang5fbe25c2010-10-18 17:17:23 -07001029 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001030 * setup request/response info
1031 */
1032 reqi->bfa_rport = rport;
1033 reqi->vf_id = vf_id;
1034 reqi->lp_tag = lp_tag;
1035 reqi->class = cos;
1036 rspi->rsp_timeout = rsp_timeout;
1037 reqi->cts = cts;
1038 reqi->fchs = *fchs;
1039 reqi->req_tot_len = reqlen;
1040 rspi->rsp_maxlen = rsp_maxlen;
1041 fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
1042 fcxp->send_cbarg = cbarg;
1043
Jing Huang5fbe25c2010-10-18 17:17:23 -07001044 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001045 * If no room in CPE queue, wait for space in request queue
1046 */
1047 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
1048 if (!send_req) {
1049 bfa_trc(bfa, fcxp->fcxp_tag);
1050 fcxp->reqq_waiting = BFA_TRUE;
1051 bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe);
1052 return;
1053 }
1054
1055 bfa_fcxp_queue(fcxp, send_req);
1056}
1057
Jing Huang5fbe25c2010-10-18 17:17:23 -07001058/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001059 * Abort a BFA FCXP
1060 *
1061 * @param[in] fcxp BFA fcxp pointer
1062 *
1063 * @return void
1064 */
1065bfa_status_t
1066bfa_fcxp_abort(struct bfa_fcxp_s *fcxp)
1067{
1068 bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag);
Jing Huangd4b671c2010-12-26 21:46:35 -08001069 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001070 return BFA_STATUS_OK;
1071}
1072
1073void
1074bfa_fcxp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
1075 bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg,
1076 void *caller, int nreq_sgles,
1077 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
1078 bfa_fcxp_get_sglen_t req_sglen_cbfn,
1079 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
1080 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
1081{
1082 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1083
Jing Huangd4b671c2010-12-26 21:46:35 -08001084 WARN_ON(!list_empty(&mod->fcxp_free_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001085
1086 wqe->alloc_cbfn = alloc_cbfn;
1087 wqe->alloc_cbarg = alloc_cbarg;
1088 wqe->caller = caller;
1089 wqe->bfa = bfa;
1090 wqe->nreq_sgles = nreq_sgles;
1091 wqe->nrsp_sgles = nrsp_sgles;
1092 wqe->req_sga_cbfn = req_sga_cbfn;
1093 wqe->req_sglen_cbfn = req_sglen_cbfn;
1094 wqe->rsp_sga_cbfn = rsp_sga_cbfn;
1095 wqe->rsp_sglen_cbfn = rsp_sglen_cbfn;
1096
1097 list_add_tail(&wqe->qe, &mod->wait_q);
1098}
1099
1100void
1101bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
1102{
1103 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1104
Jing Huangd4b671c2010-12-26 21:46:35 -08001105 WARN_ON(!bfa_q_is_on_q(&mod->wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001106 list_del(&wqe->qe);
1107}
1108
1109void
1110bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
1111{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001112 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001113 * If waiting for room in request queue, cancel reqq wait
1114 * and free fcxp.
1115 */
1116 if (fcxp->reqq_waiting) {
1117 fcxp->reqq_waiting = BFA_FALSE;
1118 bfa_reqq_wcancel(&fcxp->reqq_wqe);
1119 bfa_fcxp_free(fcxp);
1120 return;
1121 }
1122
1123 fcxp->send_cbfn = bfa_fcxp_null_comp;
1124}
1125
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001126void
1127bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
1128{
1129 switch (msg->mhdr.msg_id) {
1130 case BFI_FCXP_I2H_SEND_RSP:
1131 hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg);
1132 break;
1133
1134 default:
1135 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001136 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001137 }
1138}
1139
1140u32
1141bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
1142{
1143 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1144
1145 return mod->rsp_pld_sz;
1146}
1147
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001148void
1149bfa_fcxp_res_recfg(struct bfa_s *bfa, u16 num_fcxp_fw)
1150{
1151 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1152 struct list_head *qe;
1153 int i;
1154
1155 for (i = 0; i < (mod->num_fcxps - num_fcxp_fw); i++) {
1156 bfa_q_deq_tail(&mod->fcxp_free_q, &qe);
1157 list_add_tail(qe, &mod->fcxp_unused_q);
1158 }
1159}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001160
Jing Huang5fbe25c2010-10-18 17:17:23 -07001161/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001162 * BFA LPS state machine functions
1163 */
1164
Jing Huang5fbe25c2010-10-18 17:17:23 -07001165/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001166 * Init state -- no login
1167 */
1168static void
1169bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
1170{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001171 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001172 bfa_trc(lps->bfa, event);
1173
1174 switch (event) {
1175 case BFA_LPS_SM_LOGIN:
1176 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1177 bfa_sm_set_state(lps, bfa_lps_sm_loginwait);
1178 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1179 } else {
1180 bfa_sm_set_state(lps, bfa_lps_sm_login);
1181 bfa_lps_send_login(lps);
1182 }
1183
1184 if (lps->fdisc)
1185 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1186 BFA_PL_EID_LOGIN, 0, "FDISC Request");
1187 else
1188 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1189 BFA_PL_EID_LOGIN, 0, "FLOGI Request");
1190 break;
1191
1192 case BFA_LPS_SM_LOGOUT:
1193 bfa_lps_logout_comp(lps);
1194 break;
1195
1196 case BFA_LPS_SM_DELETE:
1197 bfa_lps_free(lps);
1198 break;
1199
1200 case BFA_LPS_SM_RX_CVL:
1201 case BFA_LPS_SM_OFFLINE:
1202 break;
1203
1204 case BFA_LPS_SM_FWRSP:
1205 /*
1206 * Could happen when fabric detects loopback and discards
1207 * the lps request. Fw will eventually sent out the timeout
1208 * Just ignore
1209 */
1210 break;
1211
1212 default:
1213 bfa_sm_fault(lps->bfa, event);
1214 }
1215}
1216
Jing Huang5fbe25c2010-10-18 17:17:23 -07001217/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001218 * login is in progress -- awaiting response from firmware
1219 */
1220static void
1221bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
1222{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001223 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001224 bfa_trc(lps->bfa, event);
1225
1226 switch (event) {
1227 case BFA_LPS_SM_FWRSP:
1228 if (lps->status == BFA_STATUS_OK) {
1229 bfa_sm_set_state(lps, bfa_lps_sm_online);
1230 if (lps->fdisc)
1231 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1232 BFA_PL_EID_LOGIN, 0, "FDISC Accept");
1233 else
1234 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1235 BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
Krishna Gudipatib7044952010-12-13 16:17:42 -08001236 /* If N2N, send the assigned PID to FW */
1237 bfa_trc(lps->bfa, lps->fport);
1238 bfa_trc(lps->bfa, lps->lp_pid);
1239
1240 if (!lps->fport && lps->lp_pid)
1241 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001242 } else {
1243 bfa_sm_set_state(lps, bfa_lps_sm_init);
1244 if (lps->fdisc)
1245 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1246 BFA_PL_EID_LOGIN, 0,
1247 "FDISC Fail (RJT or timeout)");
1248 else
1249 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1250 BFA_PL_EID_LOGIN, 0,
1251 "FLOGI Fail (RJT or timeout)");
1252 }
1253 bfa_lps_login_comp(lps);
1254 break;
1255
1256 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001257 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001258 bfa_sm_set_state(lps, bfa_lps_sm_init);
1259 break;
1260
Krishna Gudipatib7044952010-12-13 16:17:42 -08001261 case BFA_LPS_SM_SET_N2N_PID:
1262 bfa_trc(lps->bfa, lps->fport);
1263 bfa_trc(lps->bfa, lps->lp_pid);
1264 break;
1265
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001266 default:
1267 bfa_sm_fault(lps->bfa, event);
1268 }
1269}
1270
Jing Huang5fbe25c2010-10-18 17:17:23 -07001271/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001272 * login pending - awaiting space in request queue
1273 */
1274static void
1275bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1276{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001277 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001278 bfa_trc(lps->bfa, event);
1279
1280 switch (event) {
1281 case BFA_LPS_SM_RESUME:
1282 bfa_sm_set_state(lps, bfa_lps_sm_login);
Krishna Gudipatiff179e02012-03-13 17:40:31 -07001283 bfa_lps_send_login(lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001284 break;
1285
1286 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001287 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001288 bfa_sm_set_state(lps, bfa_lps_sm_init);
1289 bfa_reqq_wcancel(&lps->wqe);
1290 break;
1291
1292 case BFA_LPS_SM_RX_CVL:
1293 /*
1294 * Login was not even sent out; so when getting out
1295 * of this state, it will appear like a login retry
1296 * after Clear virtual link
1297 */
1298 break;
1299
1300 default:
1301 bfa_sm_fault(lps->bfa, event);
1302 }
1303}
1304
Jing Huang5fbe25c2010-10-18 17:17:23 -07001305/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001306 * login complete
1307 */
1308static void
1309bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
1310{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001311 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001312 bfa_trc(lps->bfa, event);
1313
1314 switch (event) {
1315 case BFA_LPS_SM_LOGOUT:
1316 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1317 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1318 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1319 } else {
1320 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1321 bfa_lps_send_logout(lps);
1322 }
1323 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1324 BFA_PL_EID_LOGO, 0, "Logout");
1325 break;
1326
1327 case BFA_LPS_SM_RX_CVL:
1328 bfa_sm_set_state(lps, bfa_lps_sm_init);
1329
1330 /* Let the vport module know about this event */
1331 bfa_lps_cvl_event(lps);
1332 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1333 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1334 break;
1335
Krishna Gudipatib7044952010-12-13 16:17:42 -08001336 case BFA_LPS_SM_SET_N2N_PID:
1337 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1338 bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
1339 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1340 } else
1341 bfa_lps_send_set_n2n_pid(lps);
1342 break;
1343
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001344 case BFA_LPS_SM_OFFLINE:
1345 case BFA_LPS_SM_DELETE:
1346 bfa_sm_set_state(lps, bfa_lps_sm_init);
1347 break;
1348
1349 default:
1350 bfa_sm_fault(lps->bfa, event);
1351 }
1352}
1353
Jing Huang8f4bfad2010-12-26 21:50:10 -08001354/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001355 * login complete
1356 */
1357static void
1358bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1359{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001360 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001361 bfa_trc(lps->bfa, event);
1362
1363 switch (event) {
1364 case BFA_LPS_SM_RESUME:
1365 bfa_sm_set_state(lps, bfa_lps_sm_online);
1366 bfa_lps_send_set_n2n_pid(lps);
1367 break;
1368
1369 case BFA_LPS_SM_LOGOUT:
1370 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1371 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1372 BFA_PL_EID_LOGO, 0, "Logout");
1373 break;
1374
1375 case BFA_LPS_SM_RX_CVL:
1376 bfa_sm_set_state(lps, bfa_lps_sm_init);
1377 bfa_reqq_wcancel(&lps->wqe);
1378
1379 /* Let the vport module know about this event */
1380 bfa_lps_cvl_event(lps);
1381 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1382 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1383 break;
1384
1385 case BFA_LPS_SM_OFFLINE:
1386 case BFA_LPS_SM_DELETE:
1387 bfa_sm_set_state(lps, bfa_lps_sm_init);
1388 bfa_reqq_wcancel(&lps->wqe);
1389 break;
1390
1391 default:
1392 bfa_sm_fault(lps->bfa, event);
1393 }
1394}
1395
Jing Huang5fbe25c2010-10-18 17:17:23 -07001396/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001397 * logout in progress - awaiting firmware response
1398 */
1399static void
1400bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
1401{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001402 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001403 bfa_trc(lps->bfa, event);
1404
1405 switch (event) {
1406 case BFA_LPS_SM_FWRSP:
1407 bfa_sm_set_state(lps, bfa_lps_sm_init);
1408 bfa_lps_logout_comp(lps);
1409 break;
1410
1411 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001412 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001413 bfa_sm_set_state(lps, bfa_lps_sm_init);
1414 break;
1415
1416 default:
1417 bfa_sm_fault(lps->bfa, event);
1418 }
1419}
1420
Jing Huang5fbe25c2010-10-18 17:17:23 -07001421/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001422 * logout pending -- awaiting space in request queue
1423 */
1424static void
1425bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1426{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001427 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001428 bfa_trc(lps->bfa, event);
1429
1430 switch (event) {
1431 case BFA_LPS_SM_RESUME:
1432 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1433 bfa_lps_send_logout(lps);
1434 break;
1435
1436 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001437 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001438 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
1447
1448
Jing Huang5fbe25c2010-10-18 17:17:23 -07001449/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001450 * lps_pvt BFA LPS private functions
1451 */
1452
Jing Huang5fbe25c2010-10-18 17:17:23 -07001453/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001454 * return memory requirement
1455 */
1456static void
Krishna Gudipati45070252011-06-24 20:24:29 -07001457bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
1458 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001459{
Krishna Gudipati45070252011-06-24 20:24:29 -07001460 struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa);
1461
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001462 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -07001463 bfa_mem_kva_setup(minfo, lps_kva,
1464 sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001465 else
Krishna Gudipati45070252011-06-24 20:24:29 -07001466 bfa_mem_kva_setup(minfo, lps_kva,
1467 sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001468}
1469
Jing Huang5fbe25c2010-10-18 17:17:23 -07001470/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001471 * bfa module attach at initialization time
1472 */
1473static void
1474bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07001475 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001476{
1477 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1478 struct bfa_lps_s *lps;
1479 int i;
1480
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001481 mod->num_lps = BFA_LPS_MAX_LPORTS;
1482 if (cfg->drvcfg.min_cfg)
1483 mod->num_lps = BFA_LPS_MIN_LPORTS;
1484 else
1485 mod->num_lps = BFA_LPS_MAX_LPORTS;
Krishna Gudipati45070252011-06-24 20:24:29 -07001486 mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001487
Krishna Gudipati45070252011-06-24 20:24:29 -07001488 bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001489
1490 INIT_LIST_HEAD(&mod->lps_free_q);
1491 INIT_LIST_HEAD(&mod->lps_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001492 INIT_LIST_HEAD(&mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001493
1494 for (i = 0; i < mod->num_lps; i++, lps++) {
1495 lps->bfa = bfa;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001496 lps->bfa_tag = (u8) i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001497 lps->reqq = BFA_REQQ_LPS;
1498 bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
1499 list_add_tail(&lps->qe, &mod->lps_free_q);
1500 }
1501}
1502
1503static void
1504bfa_lps_detach(struct bfa_s *bfa)
1505{
1506}
1507
1508static void
1509bfa_lps_start(struct bfa_s *bfa)
1510{
1511}
1512
1513static void
1514bfa_lps_stop(struct bfa_s *bfa)
1515{
1516}
1517
Jing Huang5fbe25c2010-10-18 17:17:23 -07001518/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001519 * IOC in disabled state -- consider all lps offline
1520 */
1521static void
1522bfa_lps_iocdisable(struct bfa_s *bfa)
1523{
1524 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1525 struct bfa_lps_s *lps;
1526 struct list_head *qe, *qen;
1527
1528 list_for_each_safe(qe, qen, &mod->lps_active_q) {
1529 lps = (struct bfa_lps_s *) qe;
1530 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1531 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001532 list_for_each_safe(qe, qen, &mod->lps_login_q) {
1533 lps = (struct bfa_lps_s *) qe;
1534 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1535 }
1536 list_splice_tail_init(&mod->lps_login_q, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001537}
1538
Jing Huang5fbe25c2010-10-18 17:17:23 -07001539/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001540 * Firmware login response
1541 */
1542static void
1543bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
1544{
1545 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1546 struct bfa_lps_s *lps;
1547
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001548 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1549 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001550
1551 lps->status = rsp->status;
1552 switch (rsp->status) {
1553 case BFA_STATUS_OK:
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001554 lps->fw_tag = rsp->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001555 lps->fport = rsp->f_port;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001556 if (lps->fport)
1557 lps->lp_pid = rsp->lp_pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001558 lps->npiv_en = rsp->npiv_en;
Jing Huangba816ea2010-10-18 17:10:50 -07001559 lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001560 lps->pr_pwwn = rsp->port_name;
1561 lps->pr_nwwn = rsp->node_name;
1562 lps->auth_req = rsp->auth_req;
1563 lps->lp_mac = rsp->lp_mac;
1564 lps->brcd_switch = rsp->brcd_switch;
1565 lps->fcf_mac = rsp->fcf_mac;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001566 lps->pr_bbscn = rsp->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001567
1568 break;
1569
1570 case BFA_STATUS_FABRIC_RJT:
1571 lps->lsrjt_rsn = rsp->lsrjt_rsn;
1572 lps->lsrjt_expl = rsp->lsrjt_expl;
1573
1574 break;
1575
1576 case BFA_STATUS_EPROTOCOL:
1577 lps->ext_status = rsp->ext_status;
1578
1579 break;
1580
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001581 case BFA_STATUS_VPORT_MAX:
Krishna Gudipatiff179e02012-03-13 17:40:31 -07001582 if (rsp->ext_status)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001583 bfa_lps_no_res(lps, rsp->ext_status);
1584 break;
1585
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001586 default:
1587 /* Nothing to do with other status */
1588 break;
1589 }
1590
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001591 list_del(&lps->qe);
1592 list_add_tail(&lps->qe, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001593 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1594}
1595
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001596static void
1597bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count)
1598{
1599 struct bfa_s *bfa = first_lps->bfa;
1600 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1601 struct list_head *qe, *qe_next;
1602 struct bfa_lps_s *lps;
1603
1604 bfa_trc(bfa, count);
1605
1606 qe = bfa_q_next(first_lps);
1607
1608 while (count && qe) {
1609 qe_next = bfa_q_next(qe);
1610 lps = (struct bfa_lps_s *)qe;
1611 bfa_trc(bfa, lps->bfa_tag);
1612 lps->status = first_lps->status;
1613 list_del(&lps->qe);
1614 list_add_tail(&lps->qe, &mod->lps_active_q);
1615 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1616 qe = qe_next;
1617 count--;
1618 }
1619}
1620
Jing Huang5fbe25c2010-10-18 17:17:23 -07001621/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001622 * Firmware logout response
1623 */
1624static void
1625bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
1626{
1627 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1628 struct bfa_lps_s *lps;
1629
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001630 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1631 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001632
1633 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1634}
1635
Jing Huang5fbe25c2010-10-18 17:17:23 -07001636/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001637 * Firmware received a Clear virtual link request (for FCoE)
1638 */
1639static void
1640bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
1641{
1642 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1643 struct bfa_lps_s *lps;
1644
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001645 lps = BFA_LPS_FROM_TAG(mod, cvl->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001646
1647 bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
1648}
1649
Jing Huang5fbe25c2010-10-18 17:17:23 -07001650/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001651 * Space is available in request queue, resume queueing request to firmware.
1652 */
1653static void
1654bfa_lps_reqq_resume(void *lps_arg)
1655{
1656 struct bfa_lps_s *lps = lps_arg;
1657
1658 bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
1659}
1660
Jing Huang5fbe25c2010-10-18 17:17:23 -07001661/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001662 * lps is freed -- triggered by vport delete
1663 */
1664static void
1665bfa_lps_free(struct bfa_lps_s *lps)
1666{
1667 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
1668
1669 lps->lp_pid = 0;
1670 list_del(&lps->qe);
1671 list_add_tail(&lps->qe, &mod->lps_free_q);
1672}
1673
Jing Huang5fbe25c2010-10-18 17:17:23 -07001674/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001675 * send login request to firmware
1676 */
1677static void
1678bfa_lps_send_login(struct bfa_lps_s *lps)
1679{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001680 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001681 struct bfi_lps_login_req_s *m;
1682
1683 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001684 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001685
1686 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001687 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001688
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001689 m->bfa_tag = lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001690 m->alpa = lps->alpa;
Jing Huangba816ea2010-10-18 17:10:50 -07001691 m->pdu_size = cpu_to_be16(lps->pdusz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001692 m->pwwn = lps->pwwn;
1693 m->nwwn = lps->nwwn;
1694 m->fdisc = lps->fdisc;
1695 m->auth_en = lps->auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001696 m->bb_scn = lps->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001697
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001698 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
1699 list_del(&lps->qe);
1700 list_add_tail(&lps->qe, &mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001701}
1702
Jing Huang5fbe25c2010-10-18 17:17:23 -07001703/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001704 * send logout request to firmware
1705 */
1706static void
1707bfa_lps_send_logout(struct bfa_lps_s *lps)
1708{
1709 struct bfi_lps_logout_req_s *m;
1710
1711 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001712 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001713
1714 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001715 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001716
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001717 m->fw_tag = lps->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001718 m->port_name = lps->pwwn;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001719 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001720}
1721
Jing Huang8f4bfad2010-12-26 21:50:10 -08001722/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001723 * send n2n pid set request to firmware
1724 */
1725static void
1726bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
1727{
1728 struct bfi_lps_n2n_pid_req_s *m;
1729
1730 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001731 WARN_ON(!m);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001732
1733 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001734 bfa_fn_lpu(lps->bfa));
Krishna Gudipatib7044952010-12-13 16:17:42 -08001735
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001736 m->fw_tag = lps->fw_tag;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001737 m->lp_pid = lps->lp_pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001738 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001739}
1740
Jing Huang5fbe25c2010-10-18 17:17:23 -07001741/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001742 * Indirect login completion handler for non-fcs
1743 */
1744static void
1745bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
1746{
1747 struct bfa_lps_s *lps = arg;
1748
1749 if (!complete)
1750 return;
1751
1752 if (lps->fdisc)
1753 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1754 else
1755 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1756}
1757
Jing Huang5fbe25c2010-10-18 17:17:23 -07001758/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001759 * Login completion handler -- direct call for fcs, queue for others
1760 */
1761static void
1762bfa_lps_login_comp(struct bfa_lps_s *lps)
1763{
1764 if (!lps->bfa->fcs) {
1765 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
1766 lps);
1767 return;
1768 }
1769
1770 if (lps->fdisc)
1771 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1772 else
1773 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1774}
1775
Jing Huang5fbe25c2010-10-18 17:17:23 -07001776/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001777 * Indirect logout completion handler for non-fcs
1778 */
1779static void
1780bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
1781{
1782 struct bfa_lps_s *lps = arg;
1783
1784 if (!complete)
1785 return;
1786
1787 if (lps->fdisc)
1788 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1789}
1790
Jing Huang5fbe25c2010-10-18 17:17:23 -07001791/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001792 * Logout completion handler -- direct call for fcs, queue for others
1793 */
1794static void
1795bfa_lps_logout_comp(struct bfa_lps_s *lps)
1796{
1797 if (!lps->bfa->fcs) {
1798 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
1799 lps);
1800 return;
1801 }
1802 if (lps->fdisc)
1803 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1804}
1805
Jing Huang5fbe25c2010-10-18 17:17:23 -07001806/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001807 * Clear virtual link completion handler for non-fcs
1808 */
1809static void
1810bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
1811{
1812 struct bfa_lps_s *lps = arg;
1813
1814 if (!complete)
1815 return;
1816
1817 /* Clear virtual link to base port will result in link down */
1818 if (lps->fdisc)
1819 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1820}
1821
Jing Huang5fbe25c2010-10-18 17:17:23 -07001822/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001823 * Received Clear virtual link event --direct call for fcs,
1824 * queue for others
1825 */
1826static void
1827bfa_lps_cvl_event(struct bfa_lps_s *lps)
1828{
1829 if (!lps->bfa->fcs) {
1830 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
1831 lps);
1832 return;
1833 }
1834
1835 /* Clear virtual link to base port will result in link down */
1836 if (lps->fdisc)
1837 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1838}
1839
1840
1841
Jing Huang5fbe25c2010-10-18 17:17:23 -07001842/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001843 * lps_public BFA LPS public functions
1844 */
1845
1846u32
1847bfa_lps_get_max_vport(struct bfa_s *bfa)
1848{
1849 if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
1850 return BFA_LPS_MAX_VPORTS_SUPP_CT;
1851 else
1852 return BFA_LPS_MAX_VPORTS_SUPP_CB;
1853}
1854
Jing Huang5fbe25c2010-10-18 17:17:23 -07001855/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001856 * Allocate a lport srvice tag.
1857 */
1858struct bfa_lps_s *
1859bfa_lps_alloc(struct bfa_s *bfa)
1860{
1861 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1862 struct bfa_lps_s *lps = NULL;
1863
1864 bfa_q_deq(&mod->lps_free_q, &lps);
1865
1866 if (lps == NULL)
1867 return NULL;
1868
1869 list_add_tail(&lps->qe, &mod->lps_active_q);
1870
1871 bfa_sm_set_state(lps, bfa_lps_sm_init);
1872 return lps;
1873}
1874
Jing Huang5fbe25c2010-10-18 17:17:23 -07001875/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001876 * Free lport service tag. This can be called anytime after an alloc.
1877 * No need to wait for any pending login/logout completions.
1878 */
1879void
1880bfa_lps_delete(struct bfa_lps_s *lps)
1881{
1882 bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
1883}
1884
Jing Huang5fbe25c2010-10-18 17:17:23 -07001885/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001886 * Initiate a lport login.
1887 */
1888void
1889bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001890 wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en, uint8_t bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001891{
1892 lps->uarg = uarg;
1893 lps->alpa = alpa;
1894 lps->pdusz = pdusz;
1895 lps->pwwn = pwwn;
1896 lps->nwwn = nwwn;
1897 lps->fdisc = BFA_FALSE;
1898 lps->auth_en = auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001899 lps->bb_scn = bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001900 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1901}
1902
Jing Huang5fbe25c2010-10-18 17:17:23 -07001903/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001904 * Initiate a lport fdisc login.
1905 */
1906void
1907bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
1908 wwn_t nwwn)
1909{
1910 lps->uarg = uarg;
1911 lps->alpa = 0;
1912 lps->pdusz = pdusz;
1913 lps->pwwn = pwwn;
1914 lps->nwwn = nwwn;
1915 lps->fdisc = BFA_TRUE;
1916 lps->auth_en = BFA_FALSE;
1917 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1918}
1919
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001920
Jing Huang5fbe25c2010-10-18 17:17:23 -07001921/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001922 * Initiate a lport FDSIC logout.
1923 */
1924void
1925bfa_lps_fdisclogo(struct bfa_lps_s *lps)
1926{
1927 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
1928}
1929
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001930u8
1931bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag)
1932{
1933 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1934
1935 return BFA_LPS_FROM_TAG(mod, lp_tag)->fw_tag;
1936}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001937
Jing Huang5fbe25c2010-10-18 17:17:23 -07001938/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001939 * Return lport services tag given the pid
1940 */
1941u8
1942bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
1943{
1944 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1945 struct bfa_lps_s *lps;
1946 int i;
1947
1948 for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
1949 if (lps->lp_pid == pid)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001950 return lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001951 }
1952
1953 /* Return base port tag anyway */
1954 return 0;
1955}
1956
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001957
Jing Huang5fbe25c2010-10-18 17:17:23 -07001958/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001959 * return port id assigned to the base lport
1960 */
1961u32
1962bfa_lps_get_base_pid(struct bfa_s *bfa)
1963{
1964 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1965
1966 return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
1967}
1968
Jing Huang8f4bfad2010-12-26 21:50:10 -08001969/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001970 * Set PID in case of n2n (which is assigned during PLOGI)
1971 */
1972void
1973bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
1974{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001975 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001976 bfa_trc(lps->bfa, n2n_pid);
1977
1978 lps->lp_pid = n2n_pid;
1979 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
1980}
1981
Jing Huang5fbe25c2010-10-18 17:17:23 -07001982/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001983 * LPS firmware message class handler.
1984 */
1985void
1986bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
1987{
1988 union bfi_lps_i2h_msg_u msg;
1989
1990 bfa_trc(bfa, m->mhdr.msg_id);
1991 msg.msg = m;
1992
1993 switch (m->mhdr.msg_id) {
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07001994 case BFI_LPS_I2H_LOGIN_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001995 bfa_lps_login_rsp(bfa, msg.login_rsp);
1996 break;
1997
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07001998 case BFI_LPS_I2H_LOGOUT_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001999 bfa_lps_logout_rsp(bfa, msg.logout_rsp);
2000 break;
2001
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002002 case BFI_LPS_I2H_CVL_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002003 bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
2004 break;
2005
2006 default:
2007 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08002008 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002009 }
2010}
2011
Krishna Gudipati7826f302011-07-20 16:59:13 -07002012static void
2013bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
2014{
2015 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2016 struct bfa_aen_entry_s *aen_entry;
2017
2018 bfad_get_aen_entry(bfad, aen_entry);
2019 if (!aen_entry)
2020 return;
2021
2022 aen_entry->aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
2023 aen_entry->aen_data.port.pwwn = fcport->pwwn;
2024
2025 /* Send the AEN notification */
2026 bfad_im_post_vendor_event(aen_entry, bfad, ++fcport->bfa->bfa_aen_seq,
2027 BFA_AEN_CAT_PORT, event);
2028}
2029
Jing Huang5fbe25c2010-10-18 17:17:23 -07002030/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002031 * FC PORT state machine functions
2032 */
2033static void
2034bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
2035 enum bfa_fcport_sm_event event)
2036{
2037 bfa_trc(fcport->bfa, event);
2038
2039 switch (event) {
2040 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002041 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002042 * Start event after IOC is configured and BFA is started.
2043 */
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08002044 fcport->use_flash_cfg = BFA_TRUE;
2045
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002046 if (bfa_fcport_send_enable(fcport)) {
2047 bfa_trc(fcport->bfa, BFA_TRUE);
2048 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2049 } else {
2050 bfa_trc(fcport->bfa, BFA_FALSE);
2051 bfa_sm_set_state(fcport,
2052 bfa_fcport_sm_enabling_qwait);
2053 }
2054 break;
2055
2056 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002057 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002058 * Port is persistently configured to be in enabled state. Do
2059 * not change state. Port enabling is done when START event is
2060 * received.
2061 */
2062 break;
2063
2064 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002065 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002066 * If a port is persistently configured to be disabled, the
2067 * first event will a port disable request.
2068 */
2069 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2070 break;
2071
2072 case BFA_FCPORT_SM_HWFAIL:
2073 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2074 break;
2075
2076 default:
2077 bfa_sm_fault(fcport->bfa, event);
2078 }
2079}
2080
2081static void
2082bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
2083 enum bfa_fcport_sm_event event)
2084{
2085 char pwwn_buf[BFA_STRING_32];
2086 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2087 bfa_trc(fcport->bfa, event);
2088
2089 switch (event) {
2090 case BFA_FCPORT_SM_QRESUME:
2091 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2092 bfa_fcport_send_enable(fcport);
2093 break;
2094
2095 case BFA_FCPORT_SM_STOP:
2096 bfa_reqq_wcancel(&fcport->reqq_wait);
2097 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2098 break;
2099
2100 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002101 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002102 * Already enable is in progress.
2103 */
2104 break;
2105
2106 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002107 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002108 * Just send disable request to firmware when room becomes
2109 * available in request queue.
2110 */
2111 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2112 bfa_reqq_wcancel(&fcport->reqq_wait);
2113 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2114 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2115 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002116 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002117 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002118 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002119 break;
2120
2121 case BFA_FCPORT_SM_LINKUP:
2122 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002123 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002124 * Possible to get link events when doing back-to-back
2125 * enable/disables.
2126 */
2127 break;
2128
2129 case BFA_FCPORT_SM_HWFAIL:
2130 bfa_reqq_wcancel(&fcport->reqq_wait);
2131 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2132 break;
2133
2134 default:
2135 bfa_sm_fault(fcport->bfa, event);
2136 }
2137}
2138
2139static void
2140bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
2141 enum bfa_fcport_sm_event event)
2142{
2143 char pwwn_buf[BFA_STRING_32];
2144 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2145 bfa_trc(fcport->bfa, event);
2146
2147 switch (event) {
2148 case BFA_FCPORT_SM_FWRSP:
2149 case BFA_FCPORT_SM_LINKDOWN:
2150 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2151 break;
2152
2153 case BFA_FCPORT_SM_LINKUP:
2154 bfa_fcport_update_linkinfo(fcport);
2155 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
2156
Jing Huangd4b671c2010-12-26 21:46:35 -08002157 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002158 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2159 break;
2160
2161 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002162 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002163 * Already being enabled.
2164 */
2165 break;
2166
2167 case BFA_FCPORT_SM_DISABLE:
2168 if (bfa_fcport_send_disable(fcport))
2169 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2170 else
2171 bfa_sm_set_state(fcport,
2172 bfa_fcport_sm_disabling_qwait);
2173
2174 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2175 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2176 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002177 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002178 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002179 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002180 break;
2181
2182 case BFA_FCPORT_SM_STOP:
2183 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2184 break;
2185
2186 case BFA_FCPORT_SM_HWFAIL:
2187 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2188 break;
2189
2190 default:
2191 bfa_sm_fault(fcport->bfa, event);
2192 }
2193}
2194
2195static void
2196bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
2197 enum bfa_fcport_sm_event event)
2198{
2199 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2200 char pwwn_buf[BFA_STRING_32];
2201 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2202
2203 bfa_trc(fcport->bfa, event);
2204
2205 switch (event) {
2206 case BFA_FCPORT_SM_LINKUP:
2207 bfa_fcport_update_linkinfo(fcport);
2208 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
Jing Huangd4b671c2010-12-26 21:46:35 -08002209 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002210 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2211 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
2212 if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
2213
2214 bfa_trc(fcport->bfa,
2215 pevent->link_state.vc_fcf.fcf.fipenabled);
2216 bfa_trc(fcport->bfa,
2217 pevent->link_state.vc_fcf.fcf.fipfailed);
2218
2219 if (pevent->link_state.vc_fcf.fcf.fipfailed)
2220 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2221 BFA_PL_EID_FIP_FCF_DISC, 0,
2222 "FIP FCF Discovery Failed");
2223 else
2224 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2225 BFA_PL_EID_FIP_FCF_DISC, 0,
2226 "FIP FCF Discovered");
2227 }
2228
2229 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2230 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002231 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002232 "Base port online: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002233 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002234
2235 /* If QoS is enabled and it is not online, send AEN */
2236 if (fcport->cfg.qos_enabled &&
2237 fcport->qos_attr.state != BFA_QOS_ONLINE)
2238 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002239 break;
2240
2241 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002242 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002243 * Possible to get link down event.
2244 */
2245 break;
2246
2247 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002248 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002249 * Already enabled.
2250 */
2251 break;
2252
2253 case BFA_FCPORT_SM_DISABLE:
2254 if (bfa_fcport_send_disable(fcport))
2255 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2256 else
2257 bfa_sm_set_state(fcport,
2258 bfa_fcport_sm_disabling_qwait);
2259
2260 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2261 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2262 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002263 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002264 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002265 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002266 break;
2267
2268 case BFA_FCPORT_SM_STOP:
2269 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2270 break;
2271
2272 case BFA_FCPORT_SM_HWFAIL:
2273 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2274 break;
2275
2276 default:
2277 bfa_sm_fault(fcport->bfa, event);
2278 }
2279}
2280
2281static void
2282bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
2283 enum bfa_fcport_sm_event event)
2284{
2285 char pwwn_buf[BFA_STRING_32];
2286 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2287
2288 bfa_trc(fcport->bfa, event);
2289
2290 switch (event) {
2291 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002292 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002293 * Already enabled.
2294 */
2295 break;
2296
2297 case BFA_FCPORT_SM_DISABLE:
2298 if (bfa_fcport_send_disable(fcport))
2299 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2300 else
2301 bfa_sm_set_state(fcport,
2302 bfa_fcport_sm_disabling_qwait);
2303
2304 bfa_fcport_reset_linkinfo(fcport);
2305 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2306 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2307 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2308 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002309 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002310 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002311 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
Jing Huang88166242010-12-09 17:11:53 -08002312 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002313 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002314 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002315 break;
2316
2317 case BFA_FCPORT_SM_LINKDOWN:
2318 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2319 bfa_fcport_reset_linkinfo(fcport);
2320 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2321 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2322 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
2323 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002324 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002325 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002326 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002327 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2328 } else {
Jing Huang88166242010-12-09 17:11:53 -08002329 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002330 "Base port (WWN = %s) "
2331 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002332 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2333 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002334 break;
2335
2336 case BFA_FCPORT_SM_STOP:
2337 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2338 bfa_fcport_reset_linkinfo(fcport);
2339 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002340 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002341 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002342 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002343 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2344 } else {
Jing Huang88166242010-12-09 17:11:53 -08002345 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002346 "Base port (WWN = %s) "
2347 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002348 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2349 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002350 break;
2351
2352 case BFA_FCPORT_SM_HWFAIL:
2353 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2354 bfa_fcport_reset_linkinfo(fcport);
2355 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2356 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002357 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002358 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002359 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002360 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2361 } else {
Jing Huang88166242010-12-09 17:11:53 -08002362 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002363 "Base port (WWN = %s) "
2364 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002365 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2366 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002367 break;
2368
2369 default:
2370 bfa_sm_fault(fcport->bfa, event);
2371 }
2372}
2373
2374static void
2375bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
2376 enum bfa_fcport_sm_event event)
2377{
2378 bfa_trc(fcport->bfa, event);
2379
2380 switch (event) {
2381 case BFA_FCPORT_SM_QRESUME:
2382 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2383 bfa_fcport_send_disable(fcport);
2384 break;
2385
2386 case BFA_FCPORT_SM_STOP:
2387 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2388 bfa_reqq_wcancel(&fcport->reqq_wait);
2389 break;
2390
2391 case BFA_FCPORT_SM_ENABLE:
2392 bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
2393 break;
2394
2395 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002396 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002397 * Already being disabled.
2398 */
2399 break;
2400
2401 case BFA_FCPORT_SM_LINKUP:
2402 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002403 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002404 * Possible to get link events when doing back-to-back
2405 * enable/disables.
2406 */
2407 break;
2408
2409 case BFA_FCPORT_SM_HWFAIL:
2410 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2411 bfa_reqq_wcancel(&fcport->reqq_wait);
2412 break;
2413
2414 default:
2415 bfa_sm_fault(fcport->bfa, event);
2416 }
2417}
2418
2419static void
2420bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
2421 enum bfa_fcport_sm_event event)
2422{
2423 bfa_trc(fcport->bfa, event);
2424
2425 switch (event) {
2426 case BFA_FCPORT_SM_QRESUME:
2427 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2428 bfa_fcport_send_disable(fcport);
2429 if (bfa_fcport_send_enable(fcport))
2430 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2431 else
2432 bfa_sm_set_state(fcport,
2433 bfa_fcport_sm_enabling_qwait);
2434 break;
2435
2436 case BFA_FCPORT_SM_STOP:
2437 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2438 bfa_reqq_wcancel(&fcport->reqq_wait);
2439 break;
2440
2441 case BFA_FCPORT_SM_ENABLE:
2442 break;
2443
2444 case BFA_FCPORT_SM_DISABLE:
2445 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
2446 break;
2447
2448 case BFA_FCPORT_SM_LINKUP:
2449 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002450 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002451 * Possible to get link events when doing back-to-back
2452 * enable/disables.
2453 */
2454 break;
2455
2456 case BFA_FCPORT_SM_HWFAIL:
2457 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2458 bfa_reqq_wcancel(&fcport->reqq_wait);
2459 break;
2460
2461 default:
2462 bfa_sm_fault(fcport->bfa, event);
2463 }
2464}
2465
2466static void
2467bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
2468 enum bfa_fcport_sm_event event)
2469{
2470 char pwwn_buf[BFA_STRING_32];
2471 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2472 bfa_trc(fcport->bfa, event);
2473
2474 switch (event) {
2475 case BFA_FCPORT_SM_FWRSP:
2476 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2477 break;
2478
2479 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002480 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002481 * Already being disabled.
2482 */
2483 break;
2484
2485 case BFA_FCPORT_SM_ENABLE:
2486 if (bfa_fcport_send_enable(fcport))
2487 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2488 else
2489 bfa_sm_set_state(fcport,
2490 bfa_fcport_sm_enabling_qwait);
2491
2492 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2493 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2494 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002495 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002496 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002497 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002498 break;
2499
2500 case BFA_FCPORT_SM_STOP:
2501 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2502 break;
2503
2504 case BFA_FCPORT_SM_LINKUP:
2505 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002506 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002507 * Possible to get link events when doing back-to-back
2508 * enable/disables.
2509 */
2510 break;
2511
2512 case BFA_FCPORT_SM_HWFAIL:
2513 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2514 break;
2515
2516 default:
2517 bfa_sm_fault(fcport->bfa, event);
2518 }
2519}
2520
2521static void
2522bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
2523 enum bfa_fcport_sm_event event)
2524{
2525 char pwwn_buf[BFA_STRING_32];
2526 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2527 bfa_trc(fcport->bfa, event);
2528
2529 switch (event) {
2530 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002531 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002532 * Ignore start event for a port that is disabled.
2533 */
2534 break;
2535
2536 case BFA_FCPORT_SM_STOP:
2537 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2538 break;
2539
2540 case BFA_FCPORT_SM_ENABLE:
2541 if (bfa_fcport_send_enable(fcport))
2542 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2543 else
2544 bfa_sm_set_state(fcport,
2545 bfa_fcport_sm_enabling_qwait);
2546
2547 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2548 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2549 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002550 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002551 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002552 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002553 break;
2554
2555 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002556 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002557 * Already disabled.
2558 */
2559 break;
2560
2561 case BFA_FCPORT_SM_HWFAIL:
2562 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2563 break;
2564
2565 default:
2566 bfa_sm_fault(fcport->bfa, event);
2567 }
2568}
2569
2570static void
2571bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
2572 enum bfa_fcport_sm_event event)
2573{
2574 bfa_trc(fcport->bfa, event);
2575
2576 switch (event) {
2577 case BFA_FCPORT_SM_START:
2578 if (bfa_fcport_send_enable(fcport))
2579 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2580 else
2581 bfa_sm_set_state(fcport,
2582 bfa_fcport_sm_enabling_qwait);
2583 break;
2584
2585 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002586 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002587 * Ignore all other events.
2588 */
2589 ;
2590 }
2591}
2592
Jing Huang5fbe25c2010-10-18 17:17:23 -07002593/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002594 * Port is enabled. IOC is down/failed.
2595 */
2596static void
2597bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
2598 enum bfa_fcport_sm_event event)
2599{
2600 bfa_trc(fcport->bfa, event);
2601
2602 switch (event) {
2603 case BFA_FCPORT_SM_START:
2604 if (bfa_fcport_send_enable(fcport))
2605 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2606 else
2607 bfa_sm_set_state(fcport,
2608 bfa_fcport_sm_enabling_qwait);
2609 break;
2610
2611 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002612 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002613 * Ignore all events.
2614 */
2615 ;
2616 }
2617}
2618
Jing Huang5fbe25c2010-10-18 17:17:23 -07002619/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002620 * Port is disabled. IOC is down/failed.
2621 */
2622static void
2623bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
2624 enum bfa_fcport_sm_event event)
2625{
2626 bfa_trc(fcport->bfa, event);
2627
2628 switch (event) {
2629 case BFA_FCPORT_SM_START:
2630 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2631 break;
2632
2633 case BFA_FCPORT_SM_ENABLE:
2634 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2635 break;
2636
2637 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002638 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002639 * Ignore all events.
2640 */
2641 ;
2642 }
2643}
2644
Jing Huang5fbe25c2010-10-18 17:17:23 -07002645/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002646 * Link state is down
2647 */
2648static void
2649bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
2650 enum bfa_fcport_ln_sm_event event)
2651{
2652 bfa_trc(ln->fcport->bfa, event);
2653
2654 switch (event) {
2655 case BFA_FCPORT_LN_SM_LINKUP:
2656 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2657 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2658 break;
2659
2660 default:
2661 bfa_sm_fault(ln->fcport->bfa, event);
2662 }
2663}
2664
Jing Huang5fbe25c2010-10-18 17:17:23 -07002665/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002666 * Link state is waiting for down notification
2667 */
2668static void
2669bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
2670 enum bfa_fcport_ln_sm_event event)
2671{
2672 bfa_trc(ln->fcport->bfa, event);
2673
2674 switch (event) {
2675 case BFA_FCPORT_LN_SM_LINKUP:
2676 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2677 break;
2678
2679 case BFA_FCPORT_LN_SM_NOTIFICATION:
2680 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2681 break;
2682
2683 default:
2684 bfa_sm_fault(ln->fcport->bfa, event);
2685 }
2686}
2687
Jing Huang5fbe25c2010-10-18 17:17:23 -07002688/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002689 * Link state is waiting for down notification and there is a pending up
2690 */
2691static void
2692bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
2693 enum bfa_fcport_ln_sm_event event)
2694{
2695 bfa_trc(ln->fcport->bfa, event);
2696
2697 switch (event) {
2698 case BFA_FCPORT_LN_SM_LINKDOWN:
2699 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2700 break;
2701
2702 case BFA_FCPORT_LN_SM_NOTIFICATION:
2703 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2704 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2705 break;
2706
2707 default:
2708 bfa_sm_fault(ln->fcport->bfa, event);
2709 }
2710}
2711
Jing Huang5fbe25c2010-10-18 17:17:23 -07002712/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002713 * Link state is up
2714 */
2715static void
2716bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
2717 enum bfa_fcport_ln_sm_event event)
2718{
2719 bfa_trc(ln->fcport->bfa, event);
2720
2721 switch (event) {
2722 case BFA_FCPORT_LN_SM_LINKDOWN:
2723 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2724 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2725 break;
2726
2727 default:
2728 bfa_sm_fault(ln->fcport->bfa, event);
2729 }
2730}
2731
Jing Huang5fbe25c2010-10-18 17:17:23 -07002732/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002733 * Link state is waiting for up notification
2734 */
2735static void
2736bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
2737 enum bfa_fcport_ln_sm_event event)
2738{
2739 bfa_trc(ln->fcport->bfa, event);
2740
2741 switch (event) {
2742 case BFA_FCPORT_LN_SM_LINKDOWN:
2743 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2744 break;
2745
2746 case BFA_FCPORT_LN_SM_NOTIFICATION:
2747 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
2748 break;
2749
2750 default:
2751 bfa_sm_fault(ln->fcport->bfa, event);
2752 }
2753}
2754
Jing Huang5fbe25c2010-10-18 17:17:23 -07002755/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002756 * Link state is waiting for up notification and there is a pending down
2757 */
2758static void
2759bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
2760 enum bfa_fcport_ln_sm_event event)
2761{
2762 bfa_trc(ln->fcport->bfa, event);
2763
2764 switch (event) {
2765 case BFA_FCPORT_LN_SM_LINKUP:
2766 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
2767 break;
2768
2769 case BFA_FCPORT_LN_SM_NOTIFICATION:
2770 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2771 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2772 break;
2773
2774 default:
2775 bfa_sm_fault(ln->fcport->bfa, event);
2776 }
2777}
2778
Jing Huang5fbe25c2010-10-18 17:17:23 -07002779/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002780 * Link state is waiting for up notification and there are pending down and up
2781 */
2782static void
2783bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
2784 enum bfa_fcport_ln_sm_event event)
2785{
2786 bfa_trc(ln->fcport->bfa, event);
2787
2788 switch (event) {
2789 case BFA_FCPORT_LN_SM_LINKDOWN:
2790 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2791 break;
2792
2793 case BFA_FCPORT_LN_SM_NOTIFICATION:
2794 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2795 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2796 break;
2797
2798 default:
2799 bfa_sm_fault(ln->fcport->bfa, event);
2800 }
2801}
2802
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002803static void
2804__bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
2805{
2806 struct bfa_fcport_ln_s *ln = cbarg;
2807
2808 if (complete)
2809 ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
2810 else
2811 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2812}
2813
Jing Huang5fbe25c2010-10-18 17:17:23 -07002814/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002815 * Send SCN notification to upper layers.
2816 * trunk - false if caller is fcport to ignore fcport event in trunked mode
2817 */
2818static void
2819bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
2820 bfa_boolean_t trunk)
2821{
2822 if (fcport->cfg.trunked && !trunk)
2823 return;
2824
2825 switch (event) {
2826 case BFA_PORT_LINKUP:
2827 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
2828 break;
2829 case BFA_PORT_LINKDOWN:
2830 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
2831 break;
2832 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08002833 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002834 }
2835}
2836
2837static void
2838bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
2839{
2840 struct bfa_fcport_s *fcport = ln->fcport;
2841
2842 if (fcport->bfa->fcs) {
2843 fcport->event_cbfn(fcport->event_cbarg, event);
2844 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2845 } else {
2846 ln->ln_event = event;
2847 bfa_cb_queue(fcport->bfa, &ln->ln_qe,
2848 __bfa_cb_fcport_event, ln);
2849 }
2850}
2851
2852#define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
2853 BFA_CACHELINE_SZ))
2854
2855static void
Krishna Gudipati45070252011-06-24 20:24:29 -07002856bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
2857 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002858{
Krishna Gudipati45070252011-06-24 20:24:29 -07002859 struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa);
2860
2861 bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002862}
2863
2864static void
2865bfa_fcport_qresume(void *cbarg)
2866{
2867 struct bfa_fcport_s *fcport = cbarg;
2868
2869 bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
2870}
2871
2872static void
Krishna Gudipati45070252011-06-24 20:24:29 -07002873bfa_fcport_mem_claim(struct bfa_fcport_s *fcport)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002874{
Krishna Gudipati45070252011-06-24 20:24:29 -07002875 struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002876
Krishna Gudipati45070252011-06-24 20:24:29 -07002877 fcport->stats_kva = bfa_mem_dma_virt(fcport_dma);
2878 fcport->stats_pa = bfa_mem_dma_phys(fcport_dma);
2879 fcport->stats = (union bfa_fcport_stats_u *)
2880 bfa_mem_dma_virt(fcport_dma);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002881}
2882
Jing Huang5fbe25c2010-10-18 17:17:23 -07002883/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002884 * Memory initialization.
2885 */
2886static void
2887bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07002888 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002889{
2890 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2891 struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
2892 struct bfa_fcport_ln_s *ln = &fcport->ln;
Maggie Zhangf16a1752010-12-09 19:12:32 -08002893 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002894
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002895 fcport->bfa = bfa;
2896 ln->fcport = fcport;
2897
Krishna Gudipati45070252011-06-24 20:24:29 -07002898 bfa_fcport_mem_claim(fcport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002899
2900 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
2901 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2902
Jing Huang5fbe25c2010-10-18 17:17:23 -07002903 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002904 * initialize time stamp for stats reset
2905 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08002906 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002907 fcport->stats_reset_time = tv.tv_sec;
2908
Jing Huang5fbe25c2010-10-18 17:17:23 -07002909 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002910 * initialize and set default configuration
2911 */
2912 port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
2913 port_cfg->speed = BFA_PORT_SPEED_AUTO;
2914 port_cfg->trunked = BFA_FALSE;
2915 port_cfg->maxfrsize = 0;
2916
2917 port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
2918
Krishna Gudipati37ea0552011-07-20 17:02:11 -07002919 INIT_LIST_HEAD(&fcport->stats_pending_q);
2920 INIT_LIST_HEAD(&fcport->statsclr_pending_q);
2921
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002922 bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
2923}
2924
2925static void
2926bfa_fcport_detach(struct bfa_s *bfa)
2927{
2928}
2929
Jing Huang5fbe25c2010-10-18 17:17:23 -07002930/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002931 * Called when IOC is ready.
2932 */
2933static void
2934bfa_fcport_start(struct bfa_s *bfa)
2935{
2936 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
2937}
2938
Jing Huang5fbe25c2010-10-18 17:17:23 -07002939/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002940 * Called before IOC is stopped.
2941 */
2942static void
2943bfa_fcport_stop(struct bfa_s *bfa)
2944{
2945 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
2946 bfa_trunk_iocdisable(bfa);
2947}
2948
Jing Huang5fbe25c2010-10-18 17:17:23 -07002949/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002950 * Called when IOC failure is detected.
2951 */
2952static void
2953bfa_fcport_iocdisable(struct bfa_s *bfa)
2954{
2955 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2956
2957 bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
2958 bfa_trunk_iocdisable(bfa);
2959}
2960
2961static void
2962bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
2963{
2964 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2965 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
2966
2967 fcport->speed = pevent->link_state.speed;
2968 fcport->topology = pevent->link_state.topology;
2969
2970 if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)
2971 fcport->myalpa = 0;
2972
2973 /* QoS Details */
Jing Huang6a18b162010-10-18 17:08:54 -07002974 fcport->qos_attr = pevent->link_state.qos_attr;
2975 fcport->qos_vc_attr = pevent->link_state.vc_fcf.qos_vc_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002976
Jing Huang5fbe25c2010-10-18 17:17:23 -07002977 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002978 * update trunk state if applicable
2979 */
2980 if (!fcport->cfg.trunked)
2981 trunk->attr.state = BFA_TRUNK_DISABLED;
2982
2983 /* update FCoE specific */
Jing Huangba816ea2010-10-18 17:10:50 -07002984 fcport->fcoe_vlan = be16_to_cpu(pevent->link_state.vc_fcf.fcf.vlan);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002985
2986 bfa_trc(fcport->bfa, fcport->speed);
2987 bfa_trc(fcport->bfa, fcport->topology);
2988}
2989
2990static void
2991bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
2992{
2993 fcport->speed = BFA_PORT_SPEED_UNKNOWN;
2994 fcport->topology = BFA_PORT_TOPOLOGY_NONE;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07002995 fcport->bbsc_op_state = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002996}
2997
Jing Huang5fbe25c2010-10-18 17:17:23 -07002998/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002999 * Send port enable message to firmware.
3000 */
3001static bfa_boolean_t
3002bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
3003{
3004 struct bfi_fcport_enable_req_s *m;
3005
Jing Huang5fbe25c2010-10-18 17:17:23 -07003006 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003007 * Increment message tag before queue check, so that responses to old
3008 * requests are discarded.
3009 */
3010 fcport->msgtag++;
3011
Jing Huang5fbe25c2010-10-18 17:17:23 -07003012 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003013 * check for room in queue to send request now
3014 */
3015 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3016 if (!m) {
3017 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3018 &fcport->reqq_wait);
3019 return BFA_FALSE;
3020 }
3021
3022 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003023 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003024 m->nwwn = fcport->nwwn;
3025 m->pwwn = fcport->pwwn;
3026 m->port_cfg = fcport->cfg;
3027 m->msgtag = fcport->msgtag;
Jing Huangba816ea2010-10-18 17:10:50 -07003028 m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003029 m->use_flash_cfg = fcport->use_flash_cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003030 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
3031 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
3032 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
3033
Jing Huang5fbe25c2010-10-18 17:17:23 -07003034 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003035 * queue I/O message to firmware
3036 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003037 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003038 return BFA_TRUE;
3039}
3040
Jing Huang5fbe25c2010-10-18 17:17:23 -07003041/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003042 * Send port disable message to firmware.
3043 */
3044static bfa_boolean_t
3045bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
3046{
3047 struct bfi_fcport_req_s *m;
3048
Jing Huang5fbe25c2010-10-18 17:17:23 -07003049 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003050 * Increment message tag before queue check, so that responses to old
3051 * requests are discarded.
3052 */
3053 fcport->msgtag++;
3054
Jing Huang5fbe25c2010-10-18 17:17:23 -07003055 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003056 * check for room in queue to send request now
3057 */
3058 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3059 if (!m) {
3060 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3061 &fcport->reqq_wait);
3062 return BFA_FALSE;
3063 }
3064
3065 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003066 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003067 m->msgtag = fcport->msgtag;
3068
Jing Huang5fbe25c2010-10-18 17:17:23 -07003069 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003070 * queue I/O message to firmware
3071 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003072 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003073
3074 return BFA_TRUE;
3075}
3076
3077static void
3078bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
3079{
Maggie Zhangf7f738122010-12-09 19:08:43 -08003080 fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
3081 fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003082
3083 bfa_trc(fcport->bfa, fcport->pwwn);
3084 bfa_trc(fcport->bfa, fcport->nwwn);
3085}
3086
3087static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003088bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
3089 struct bfa_qos_stats_s *s)
3090{
3091 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003092 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003093 int i;
3094
3095 /* Now swap the 32 bit fields */
3096 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
Jing Huangba816ea2010-10-18 17:10:50 -07003097 dip[i] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003098}
3099
3100static void
3101bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
3102 struct bfa_fcoe_stats_s *s)
3103{
3104 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003105 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003106 int i;
3107
3108 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
3109 i = i + 2) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003110#ifdef __BIG_ENDIAN
Jing Huangba816ea2010-10-18 17:10:50 -07003111 dip[i] = be32_to_cpu(sip[i]);
3112 dip[i + 1] = be32_to_cpu(sip[i + 1]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003113#else
Jing Huangba816ea2010-10-18 17:10:50 -07003114 dip[i] = be32_to_cpu(sip[i + 1]);
3115 dip[i + 1] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003116#endif
3117 }
3118}
3119
3120static void
3121__bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
3122{
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003123 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *)cbarg;
3124 struct bfa_cb_pending_q_s *cb;
3125 struct list_head *qe, *qen;
3126 union bfa_fcport_stats_u *ret;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003127
3128 if (complete) {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003129 struct timeval tv;
3130 if (fcport->stats_status == BFA_STATUS_OK)
3131 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003132
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003133 list_for_each_safe(qe, qen, &fcport->stats_pending_q) {
3134 bfa_q_deq(&fcport->stats_pending_q, &qe);
3135 cb = (struct bfa_cb_pending_q_s *)qe;
3136 if (fcport->stats_status == BFA_STATUS_OK) {
3137 ret = (union bfa_fcport_stats_u *)cb->data;
3138 /* Swap FC QoS or FCoE stats */
3139 if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
3140 bfa_fcport_qos_stats_swap(&ret->fcqos,
3141 &fcport->stats->fcqos);
3142 else {
3143 bfa_fcport_fcoe_stats_swap(&ret->fcoe,
3144 &fcport->stats->fcoe);
3145 ret->fcoe.secs_reset =
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003146 tv.tv_sec - fcport->stats_reset_time;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003147 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003148 }
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003149 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
3150 fcport->stats_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003151 }
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003152 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003153 } else {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003154 INIT_LIST_HEAD(&fcport->stats_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003155 fcport->stats_status = BFA_STATUS_OK;
3156 }
3157}
3158
3159static void
3160bfa_fcport_stats_get_timeout(void *cbarg)
3161{
3162 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3163
3164 bfa_trc(fcport->bfa, fcport->stats_qfull);
3165
3166 if (fcport->stats_qfull) {
3167 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3168 fcport->stats_qfull = BFA_FALSE;
3169 }
3170
3171 fcport->stats_status = BFA_STATUS_ETIMER;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003172 __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003173}
3174
3175static void
3176bfa_fcport_send_stats_get(void *cbarg)
3177{
3178 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3179 struct bfi_fcport_req_s *msg;
3180
3181 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3182
3183 if (!msg) {
3184 fcport->stats_qfull = BFA_TRUE;
3185 bfa_reqq_winit(&fcport->stats_reqq_wait,
3186 bfa_fcport_send_stats_get, fcport);
3187 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3188 &fcport->stats_reqq_wait);
3189 return;
3190 }
3191 fcport->stats_qfull = BFA_FALSE;
3192
Jing Huang6a18b162010-10-18 17:08:54 -07003193 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003194 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003195 bfa_fn_lpu(fcport->bfa));
3196 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003197}
3198
3199static void
3200__bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
3201{
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003202 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3203 struct bfa_cb_pending_q_s *cb;
3204 struct list_head *qe, *qen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003205
3206 if (complete) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003207 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003208
Jing Huang5fbe25c2010-10-18 17:17:23 -07003209 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003210 * re-initialize time stamp for stats reset
3211 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08003212 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003213 fcport->stats_reset_time = tv.tv_sec;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003214 list_for_each_safe(qe, qen, &fcport->statsclr_pending_q) {
3215 bfa_q_deq(&fcport->statsclr_pending_q, &qe);
3216 cb = (struct bfa_cb_pending_q_s *)qe;
3217 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
3218 fcport->stats_status);
3219 }
3220 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003221 } else {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003222 INIT_LIST_HEAD(&fcport->statsclr_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003223 fcport->stats_status = BFA_STATUS_OK;
3224 }
3225}
3226
3227static void
3228bfa_fcport_stats_clr_timeout(void *cbarg)
3229{
3230 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3231
3232 bfa_trc(fcport->bfa, fcport->stats_qfull);
3233
3234 if (fcport->stats_qfull) {
3235 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3236 fcport->stats_qfull = BFA_FALSE;
3237 }
3238
3239 fcport->stats_status = BFA_STATUS_ETIMER;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003240 __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003241}
3242
3243static void
3244bfa_fcport_send_stats_clear(void *cbarg)
3245{
3246 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3247 struct bfi_fcport_req_s *msg;
3248
3249 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3250
3251 if (!msg) {
3252 fcport->stats_qfull = BFA_TRUE;
3253 bfa_reqq_winit(&fcport->stats_reqq_wait,
3254 bfa_fcport_send_stats_clear, fcport);
3255 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3256 &fcport->stats_reqq_wait);
3257 return;
3258 }
3259 fcport->stats_qfull = BFA_FALSE;
3260
Jing Huang6a18b162010-10-18 17:08:54 -07003261 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003262 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003263 bfa_fn_lpu(fcport->bfa));
3264 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003265}
3266
Jing Huang5fbe25c2010-10-18 17:17:23 -07003267/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003268 * Handle trunk SCN event from firmware.
3269 */
3270static void
3271bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3272{
3273 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3274 struct bfi_fcport_trunk_link_s *tlink;
3275 struct bfa_trunk_link_attr_s *lattr;
3276 enum bfa_trunk_state state_prev;
3277 int i;
3278 int link_bm = 0;
3279
3280 bfa_trc(fcport->bfa, fcport->cfg.trunked);
Jing Huangd4b671c2010-12-26 21:46:35 -08003281 WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
3282 scn->trunk_state != BFA_TRUNK_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003283
3284 bfa_trc(fcport->bfa, trunk->attr.state);
3285 bfa_trc(fcport->bfa, scn->trunk_state);
3286 bfa_trc(fcport->bfa, scn->trunk_speed);
3287
Jing Huang5fbe25c2010-10-18 17:17:23 -07003288 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003289 * Save off new state for trunk attribute query
3290 */
3291 state_prev = trunk->attr.state;
3292 if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
3293 trunk->attr.state = scn->trunk_state;
3294 trunk->attr.speed = scn->trunk_speed;
3295 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3296 lattr = &trunk->attr.link_attr[i];
3297 tlink = &scn->tlink[i];
3298
3299 lattr->link_state = tlink->state;
3300 lattr->trunk_wwn = tlink->trunk_wwn;
3301 lattr->fctl = tlink->fctl;
3302 lattr->speed = tlink->speed;
Jing Huangba816ea2010-10-18 17:10:50 -07003303 lattr->deskew = be32_to_cpu(tlink->deskew);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003304
3305 if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
3306 fcport->speed = tlink->speed;
3307 fcport->topology = BFA_PORT_TOPOLOGY_P2P;
3308 link_bm |= 1 << i;
3309 }
3310
3311 bfa_trc(fcport->bfa, lattr->link_state);
3312 bfa_trc(fcport->bfa, lattr->trunk_wwn);
3313 bfa_trc(fcport->bfa, lattr->fctl);
3314 bfa_trc(fcport->bfa, lattr->speed);
3315 bfa_trc(fcport->bfa, lattr->deskew);
3316 }
3317
3318 switch (link_bm) {
3319 case 3:
3320 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3321 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
3322 break;
3323 case 2:
3324 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3325 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
3326 break;
3327 case 1:
3328 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3329 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
3330 break;
3331 default:
3332 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3333 BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
3334 }
3335
Jing Huang5fbe25c2010-10-18 17:17:23 -07003336 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003337 * Notify upper layers if trunk state changed.
3338 */
3339 if ((state_prev != trunk->attr.state) ||
3340 (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
3341 bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
3342 BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
3343 }
3344}
3345
3346static void
3347bfa_trunk_iocdisable(struct bfa_s *bfa)
3348{
3349 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3350 int i = 0;
3351
Jing Huang5fbe25c2010-10-18 17:17:23 -07003352 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003353 * In trunked mode, notify upper layers that link is down
3354 */
3355 if (fcport->cfg.trunked) {
3356 if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
3357 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
3358
3359 fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
3360 fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
3361 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3362 fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
3363 fcport->trunk.attr.link_attr[i].fctl =
3364 BFA_TRUNK_LINK_FCTL_NORMAL;
3365 fcport->trunk.attr.link_attr[i].link_state =
3366 BFA_TRUNK_LINK_STATE_DN_LINKDN;
3367 fcport->trunk.attr.link_attr[i].speed =
3368 BFA_PORT_SPEED_UNKNOWN;
3369 fcport->trunk.attr.link_attr[i].deskew = 0;
3370 }
3371 }
3372}
3373
Jing Huang5fbe25c2010-10-18 17:17:23 -07003374/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003375 * Called to initialize port attributes
3376 */
3377void
3378bfa_fcport_init(struct bfa_s *bfa)
3379{
3380 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3381
Jing Huang5fbe25c2010-10-18 17:17:23 -07003382 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003383 * Initialize port attributes from IOC hardware data.
3384 */
3385 bfa_fcport_set_wwns(fcport);
3386 if (fcport->cfg.maxfrsize == 0)
3387 fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
3388 fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
3389 fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
3390
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003391 if (bfa_fcport_is_pbcdisabled(bfa))
3392 bfa->modules.port.pbc_disabled = BFA_TRUE;
3393
Jing Huangd4b671c2010-12-26 21:46:35 -08003394 WARN_ON(!fcport->cfg.maxfrsize);
3395 WARN_ON(!fcport->cfg.rx_bbcredit);
3396 WARN_ON(!fcport->speed_sup);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003397}
3398
Jing Huang5fbe25c2010-10-18 17:17:23 -07003399/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003400 * Firmware message handler.
3401 */
3402void
3403bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
3404{
3405 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3406 union bfi_fcport_i2h_msg_u i2hmsg;
3407
3408 i2hmsg.msg = msg;
3409 fcport->event_arg.i2hmsg = i2hmsg;
3410
3411 bfa_trc(bfa, msg->mhdr.msg_id);
3412 bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
3413
3414 switch (msg->mhdr.msg_id) {
3415 case BFI_FCPORT_I2H_ENABLE_RSP:
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003416 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
3417
3418 if (fcport->use_flash_cfg) {
3419 fcport->cfg = i2hmsg.penable_rsp->port_cfg;
3420 fcport->cfg.maxfrsize =
3421 cpu_to_be16(fcport->cfg.maxfrsize);
3422 fcport->cfg.path_tov =
3423 cpu_to_be16(fcport->cfg.path_tov);
3424 fcport->cfg.q_depth =
3425 cpu_to_be16(fcport->cfg.q_depth);
3426
3427 if (fcport->cfg.trunked)
3428 fcport->trunk.attr.state =
3429 BFA_TRUNK_OFFLINE;
3430 else
3431 fcport->trunk.attr.state =
3432 BFA_TRUNK_DISABLED;
3433 fcport->use_flash_cfg = BFA_FALSE;
3434 }
3435
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07003436 if (fcport->cfg.qos_enabled)
3437 fcport->qos_attr.state = BFA_QOS_OFFLINE;
3438 else
3439 fcport->qos_attr.state = BFA_QOS_DISABLED;
3440
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003441 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003442 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003443 break;
3444
3445 case BFI_FCPORT_I2H_DISABLE_RSP:
3446 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
3447 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
3448 break;
3449
3450 case BFI_FCPORT_I2H_EVENT:
3451 if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
3452 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
3453 else
3454 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
3455 break;
3456
3457 case BFI_FCPORT_I2H_TRUNK_SCN:
3458 bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
3459 break;
3460
3461 case BFI_FCPORT_I2H_STATS_GET_RSP:
3462 /*
3463 * check for timer pop before processing the rsp
3464 */
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003465 if (list_empty(&fcport->stats_pending_q) ||
3466 (fcport->stats_status == BFA_STATUS_ETIMER))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003467 break;
3468
3469 bfa_timer_stop(&fcport->timer);
3470 fcport->stats_status = i2hmsg.pstatsget_rsp->status;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003471 __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003472 break;
3473
3474 case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
3475 /*
3476 * check for timer pop before processing the rsp
3477 */
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003478 if (list_empty(&fcport->statsclr_pending_q) ||
3479 (fcport->stats_status == BFA_STATUS_ETIMER))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003480 break;
3481
3482 bfa_timer_stop(&fcport->timer);
3483 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003484 __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003485 break;
3486
3487 case BFI_FCPORT_I2H_ENABLE_AEN:
3488 bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
3489 break;
3490
3491 case BFI_FCPORT_I2H_DISABLE_AEN:
3492 bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
3493 break;
3494
3495 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08003496 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003497 break;
3498 }
3499}
3500
Jing Huang5fbe25c2010-10-18 17:17:23 -07003501/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003502 * Registered callback for port events.
3503 */
3504void
3505bfa_fcport_event_register(struct bfa_s *bfa,
3506 void (*cbfn) (void *cbarg,
3507 enum bfa_port_linkstate event),
3508 void *cbarg)
3509{
3510 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3511
3512 fcport->event_cbfn = cbfn;
3513 fcport->event_cbarg = cbarg;
3514}
3515
3516bfa_status_t
3517bfa_fcport_enable(struct bfa_s *bfa)
3518{
3519 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3520
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003521 if (bfa_fcport_is_pbcdisabled(bfa))
3522 return BFA_STATUS_PBC;
3523
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003524 if (bfa_ioc_is_disabled(&bfa->ioc))
3525 return BFA_STATUS_IOC_DISABLED;
3526
3527 if (fcport->diag_busy)
3528 return BFA_STATUS_DIAG_BUSY;
3529
3530 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
3531 return BFA_STATUS_OK;
3532}
3533
3534bfa_status_t
3535bfa_fcport_disable(struct bfa_s *bfa)
3536{
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003537 if (bfa_fcport_is_pbcdisabled(bfa))
3538 return BFA_STATUS_PBC;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003539
3540 if (bfa_ioc_is_disabled(&bfa->ioc))
3541 return BFA_STATUS_IOC_DISABLED;
3542
3543 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
3544 return BFA_STATUS_OK;
3545}
3546
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003547/* If PBC is disabled on port, return error */
3548bfa_status_t
3549bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
3550{
3551 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3552 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
3553 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
3554
3555 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
3556 bfa_trc(bfa, fcport->pwwn);
3557 return BFA_STATUS_PBC;
3558 }
3559 return BFA_STATUS_OK;
3560}
3561
Jing Huang5fbe25c2010-10-18 17:17:23 -07003562/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003563 * Configure port speed.
3564 */
3565bfa_status_t
3566bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3567{
3568 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3569
3570 bfa_trc(bfa, speed);
3571
3572 if (fcport->cfg.trunked == BFA_TRUE)
3573 return BFA_STATUS_TRUNK_ENABLED;
3574 if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
3575 bfa_trc(bfa, fcport->speed_sup);
3576 return BFA_STATUS_UNSUPP_SPEED;
3577 }
3578
Krishna Gudipatia7141342011-06-24 20:23:19 -07003579 /* For Mezz card, port speed entered needs to be checked */
3580 if (bfa_mfg_is_mezz(fcport->bfa->ioc.attr->card_type)) {
3581 if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
3582 /* For CT2, 1G is not supported */
3583 if ((speed == BFA_PORT_SPEED_1GBPS) &&
3584 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
3585 return BFA_STATUS_UNSUPP_SPEED;
3586
3587 /* Already checked for Auto Speed and Max Speed supp */
3588 if (!(speed == BFA_PORT_SPEED_1GBPS ||
3589 speed == BFA_PORT_SPEED_2GBPS ||
3590 speed == BFA_PORT_SPEED_4GBPS ||
3591 speed == BFA_PORT_SPEED_8GBPS ||
3592 speed == BFA_PORT_SPEED_16GBPS ||
3593 speed == BFA_PORT_SPEED_AUTO))
3594 return BFA_STATUS_UNSUPP_SPEED;
3595 } else {
3596 if (speed != BFA_PORT_SPEED_10GBPS)
3597 return BFA_STATUS_UNSUPP_SPEED;
3598 }
3599 }
3600
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003601 fcport->cfg.speed = speed;
3602
3603 return BFA_STATUS_OK;
3604}
3605
Jing Huang5fbe25c2010-10-18 17:17:23 -07003606/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003607 * Get current speed.
3608 */
3609enum bfa_port_speed
3610bfa_fcport_get_speed(struct bfa_s *bfa)
3611{
3612 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3613
3614 return fcport->speed;
3615}
3616
Jing Huang5fbe25c2010-10-18 17:17:23 -07003617/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003618 * Configure port topology.
3619 */
3620bfa_status_t
3621bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
3622{
3623 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3624
3625 bfa_trc(bfa, topology);
3626 bfa_trc(bfa, fcport->cfg.topology);
3627
3628 switch (topology) {
3629 case BFA_PORT_TOPOLOGY_P2P:
3630 case BFA_PORT_TOPOLOGY_LOOP:
3631 case BFA_PORT_TOPOLOGY_AUTO:
3632 break;
3633
3634 default:
3635 return BFA_STATUS_EINVAL;
3636 }
3637
3638 fcport->cfg.topology = topology;
3639 return BFA_STATUS_OK;
3640}
3641
Jing Huang5fbe25c2010-10-18 17:17:23 -07003642/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003643 * Get current topology.
3644 */
3645enum bfa_port_topology
3646bfa_fcport_get_topology(struct bfa_s *bfa)
3647{
3648 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3649
3650 return fcport->topology;
3651}
3652
3653bfa_status_t
3654bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
3655{
3656 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3657
3658 bfa_trc(bfa, alpa);
3659 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3660 bfa_trc(bfa, fcport->cfg.hardalpa);
3661
3662 fcport->cfg.cfg_hardalpa = BFA_TRUE;
3663 fcport->cfg.hardalpa = alpa;
3664
3665 return BFA_STATUS_OK;
3666}
3667
3668bfa_status_t
3669bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
3670{
3671 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3672
3673 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3674 bfa_trc(bfa, fcport->cfg.hardalpa);
3675
3676 fcport->cfg.cfg_hardalpa = BFA_FALSE;
3677 return BFA_STATUS_OK;
3678}
3679
3680bfa_boolean_t
3681bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
3682{
3683 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3684
3685 *alpa = fcport->cfg.hardalpa;
3686 return fcport->cfg.cfg_hardalpa;
3687}
3688
3689u8
3690bfa_fcport_get_myalpa(struct bfa_s *bfa)
3691{
3692 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3693
3694 return fcport->myalpa;
3695}
3696
3697bfa_status_t
3698bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
3699{
3700 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3701
3702 bfa_trc(bfa, maxfrsize);
3703 bfa_trc(bfa, fcport->cfg.maxfrsize);
3704
3705 /* with in range */
3706 if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
3707 return BFA_STATUS_INVLD_DFSZ;
3708
3709 /* power of 2, if not the max frame size of 2112 */
3710 if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
3711 return BFA_STATUS_INVLD_DFSZ;
3712
3713 fcport->cfg.maxfrsize = maxfrsize;
3714 return BFA_STATUS_OK;
3715}
3716
3717u16
3718bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
3719{
3720 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3721
3722 return fcport->cfg.maxfrsize;
3723}
3724
3725u8
3726bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
3727{
3728 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3729
3730 return fcport->cfg.rx_bbcredit;
3731}
3732
3733void
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003734bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit, u8 bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003735{
3736 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3737
3738 fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003739 fcport->cfg.bb_scn = bb_scn;
3740 if (bb_scn)
3741 fcport->bbsc_op_state = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003742}
3743
Jing Huang5fbe25c2010-10-18 17:17:23 -07003744/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003745 * Get port attributes.
3746 */
3747
3748wwn_t
3749bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
3750{
3751 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3752 if (node)
3753 return fcport->nwwn;
3754 else
3755 return fcport->pwwn;
3756}
3757
3758void
3759bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3760{
3761 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3762
Jing Huang6a18b162010-10-18 17:08:54 -07003763 memset(attr, 0, sizeof(struct bfa_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003764
3765 attr->nwwn = fcport->nwwn;
3766 attr->pwwn = fcport->pwwn;
3767
Maggie Zhangf7f738122010-12-09 19:08:43 -08003768 attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
3769 attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003770
Jing Huang6a18b162010-10-18 17:08:54 -07003771 memcpy(&attr->pport_cfg, &fcport->cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003772 sizeof(struct bfa_port_cfg_s));
3773 /* speed attributes */
3774 attr->pport_cfg.speed = fcport->cfg.speed;
3775 attr->speed_supported = fcport->speed_sup;
3776 attr->speed = fcport->speed;
3777 attr->cos_supported = FC_CLASS_3;
3778
3779 /* topology attributes */
3780 attr->pport_cfg.topology = fcport->cfg.topology;
3781 attr->topology = fcport->topology;
3782 attr->pport_cfg.trunked = fcport->cfg.trunked;
3783
3784 /* beacon attributes */
3785 attr->beacon = fcport->beacon;
3786 attr->link_e2e_beacon = fcport->link_e2e_beacon;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003787
3788 attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
3789 attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
3790 attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003791 attr->bbsc_op_status = fcport->bbsc_op_state;
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003792
3793 /* PBC Disabled State */
3794 if (bfa_fcport_is_pbcdisabled(bfa))
3795 attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
3796 else {
3797 if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
3798 attr->port_state = BFA_PORT_ST_IOCDIS;
3799 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
3800 attr->port_state = BFA_PORT_ST_FWMISMATCH;
3801 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003802
3803 /* FCoE vlan */
3804 attr->fcoe_vlan = fcport->fcoe_vlan;
3805}
3806
3807#define BFA_FCPORT_STATS_TOV 1000
3808
Jing Huang5fbe25c2010-10-18 17:17:23 -07003809/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003810 * Fetch port statistics (FCQoS or FCoE).
3811 */
3812bfa_status_t
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003813bfa_fcport_get_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003814{
3815 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3816
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003817 if (bfa_ioc_is_disabled(&bfa->ioc))
3818 return BFA_STATUS_IOC_DISABLED;
3819
3820 if (!list_empty(&fcport->statsclr_pending_q))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003821 return BFA_STATUS_DEVBUSY;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003822
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003823 if (list_empty(&fcport->stats_pending_q)) {
3824 list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
3825 bfa_fcport_send_stats_get(fcport);
3826 bfa_timer_start(bfa, &fcport->timer,
3827 bfa_fcport_stats_get_timeout,
3828 fcport, BFA_FCPORT_STATS_TOV);
3829 } else
3830 list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003831
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003832 return BFA_STATUS_OK;
3833}
3834
Jing Huang5fbe25c2010-10-18 17:17:23 -07003835/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003836 * Reset port statistics (FCQoS or FCoE).
3837 */
3838bfa_status_t
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003839bfa_fcport_clear_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003840{
3841 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3842
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003843 if (!list_empty(&fcport->stats_pending_q))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003844 return BFA_STATUS_DEVBUSY;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003845
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003846 if (list_empty(&fcport->statsclr_pending_q)) {
3847 list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
3848 bfa_fcport_send_stats_clear(fcport);
3849 bfa_timer_start(bfa, &fcport->timer,
3850 bfa_fcport_stats_clr_timeout,
3851 fcport, BFA_FCPORT_STATS_TOV);
3852 } else
3853 list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003854
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003855 return BFA_STATUS_OK;
3856}
3857
Jing Huang5fbe25c2010-10-18 17:17:23 -07003858/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003859 * Fetch port attributes.
3860 */
3861bfa_boolean_t
3862bfa_fcport_is_disabled(struct bfa_s *bfa)
3863{
3864 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3865
3866 return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
3867 BFA_PORT_ST_DISABLED;
3868
3869}
3870
3871bfa_boolean_t
3872bfa_fcport_is_ratelim(struct bfa_s *bfa)
3873{
3874 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3875
3876 return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
3877
3878}
3879
Jing Huang5fbe25c2010-10-18 17:17:23 -07003880/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07003881 * Enable/Disable FAA feature in port config
3882 */
3883void
3884bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state)
3885{
3886 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3887
3888 bfa_trc(bfa, state);
3889 fcport->cfg.faa_state = state;
3890}
3891
3892/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003893 * Get default minimum ratelim speed
3894 */
3895enum bfa_port_speed
3896bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
3897{
3898 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3899
3900 bfa_trc(bfa, fcport->cfg.trl_def_speed);
3901 return fcport->cfg.trl_def_speed;
3902
3903}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003904
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07003905void
3906bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
3907 bfa_boolean_t link_e2e_beacon)
3908{
3909 struct bfa_s *bfa = dev;
3910 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3911
3912 bfa_trc(bfa, beacon);
3913 bfa_trc(bfa, link_e2e_beacon);
3914 bfa_trc(bfa, fcport->beacon);
3915 bfa_trc(bfa, fcport->link_e2e_beacon);
3916
3917 fcport->beacon = beacon;
3918 fcport->link_e2e_beacon = link_e2e_beacon;
3919}
3920
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003921bfa_boolean_t
3922bfa_fcport_is_linkup(struct bfa_s *bfa)
3923{
3924 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3925
3926 return (!fcport->cfg.trunked &&
3927 bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
3928 (fcport->cfg.trunked &&
3929 fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
3930}
3931
3932bfa_boolean_t
3933bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
3934{
3935 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3936
3937 return fcport->cfg.qos_enabled;
3938}
3939
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003940bfa_boolean_t
3941bfa_fcport_is_trunk_enabled(struct bfa_s *bfa)
3942{
3943 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3944
3945 return fcport->cfg.trunked;
3946}
3947
Jing Huang5fbe25c2010-10-18 17:17:23 -07003948/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003949 * Rport State machine functions
3950 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07003951/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003952 * Beginning state, only online event expected.
3953 */
3954static void
3955bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
3956{
3957 bfa_trc(rp->bfa, rp->rport_tag);
3958 bfa_trc(rp->bfa, event);
3959
3960 switch (event) {
3961 case BFA_RPORT_SM_CREATE:
3962 bfa_stats(rp, sm_un_cr);
3963 bfa_sm_set_state(rp, bfa_rport_sm_created);
3964 break;
3965
3966 default:
3967 bfa_stats(rp, sm_un_unexp);
3968 bfa_sm_fault(rp->bfa, event);
3969 }
3970}
3971
3972static void
3973bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
3974{
3975 bfa_trc(rp->bfa, rp->rport_tag);
3976 bfa_trc(rp->bfa, event);
3977
3978 switch (event) {
3979 case BFA_RPORT_SM_ONLINE:
3980 bfa_stats(rp, sm_cr_on);
3981 if (bfa_rport_send_fwcreate(rp))
3982 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
3983 else
3984 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
3985 break;
3986
3987 case BFA_RPORT_SM_DELETE:
3988 bfa_stats(rp, sm_cr_del);
3989 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
3990 bfa_rport_free(rp);
3991 break;
3992
3993 case BFA_RPORT_SM_HWFAIL:
3994 bfa_stats(rp, sm_cr_hwf);
3995 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3996 break;
3997
3998 default:
3999 bfa_stats(rp, sm_cr_unexp);
4000 bfa_sm_fault(rp->bfa, event);
4001 }
4002}
4003
Jing Huang5fbe25c2010-10-18 17:17:23 -07004004/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004005 * Waiting for rport create response from firmware.
4006 */
4007static void
4008bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
4009{
4010 bfa_trc(rp->bfa, rp->rport_tag);
4011 bfa_trc(rp->bfa, event);
4012
4013 switch (event) {
4014 case BFA_RPORT_SM_FWRSP:
4015 bfa_stats(rp, sm_fwc_rsp);
4016 bfa_sm_set_state(rp, bfa_rport_sm_online);
4017 bfa_rport_online_cb(rp);
4018 break;
4019
4020 case BFA_RPORT_SM_DELETE:
4021 bfa_stats(rp, sm_fwc_del);
4022 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4023 break;
4024
4025 case BFA_RPORT_SM_OFFLINE:
4026 bfa_stats(rp, sm_fwc_off);
4027 bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
4028 break;
4029
4030 case BFA_RPORT_SM_HWFAIL:
4031 bfa_stats(rp, sm_fwc_hwf);
4032 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4033 break;
4034
4035 default:
4036 bfa_stats(rp, sm_fwc_unexp);
4037 bfa_sm_fault(rp->bfa, event);
4038 }
4039}
4040
Jing Huang5fbe25c2010-10-18 17:17:23 -07004041/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004042 * Request queue is full, awaiting queue resume to send create request.
4043 */
4044static void
4045bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4046{
4047 bfa_trc(rp->bfa, rp->rport_tag);
4048 bfa_trc(rp->bfa, event);
4049
4050 switch (event) {
4051 case BFA_RPORT_SM_QRESUME:
4052 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4053 bfa_rport_send_fwcreate(rp);
4054 break;
4055
4056 case BFA_RPORT_SM_DELETE:
4057 bfa_stats(rp, sm_fwc_del);
4058 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4059 bfa_reqq_wcancel(&rp->reqq_wait);
4060 bfa_rport_free(rp);
4061 break;
4062
4063 case BFA_RPORT_SM_OFFLINE:
4064 bfa_stats(rp, sm_fwc_off);
4065 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4066 bfa_reqq_wcancel(&rp->reqq_wait);
4067 bfa_rport_offline_cb(rp);
4068 break;
4069
4070 case BFA_RPORT_SM_HWFAIL:
4071 bfa_stats(rp, sm_fwc_hwf);
4072 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4073 bfa_reqq_wcancel(&rp->reqq_wait);
4074 break;
4075
4076 default:
4077 bfa_stats(rp, sm_fwc_unexp);
4078 bfa_sm_fault(rp->bfa, event);
4079 }
4080}
4081
Jing Huang5fbe25c2010-10-18 17:17:23 -07004082/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004083 * Online state - normal parking state.
4084 */
4085static void
4086bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
4087{
4088 struct bfi_rport_qos_scn_s *qos_scn;
4089
4090 bfa_trc(rp->bfa, rp->rport_tag);
4091 bfa_trc(rp->bfa, event);
4092
4093 switch (event) {
4094 case BFA_RPORT_SM_OFFLINE:
4095 bfa_stats(rp, sm_on_off);
4096 if (bfa_rport_send_fwdelete(rp))
4097 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4098 else
4099 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4100 break;
4101
4102 case BFA_RPORT_SM_DELETE:
4103 bfa_stats(rp, sm_on_del);
4104 if (bfa_rport_send_fwdelete(rp))
4105 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4106 else
4107 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4108 break;
4109
4110 case BFA_RPORT_SM_HWFAIL:
4111 bfa_stats(rp, sm_on_hwf);
4112 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4113 break;
4114
4115 case BFA_RPORT_SM_SET_SPEED:
4116 bfa_rport_send_fwspeed(rp);
4117 break;
4118
4119 case BFA_RPORT_SM_QOS_SCN:
4120 qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
4121 rp->qos_attr = qos_scn->new_qos_attr;
4122 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
4123 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
4124 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
4125 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
4126
4127 qos_scn->old_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004128 be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004129 qos_scn->new_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004130 be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004131
4132 if (qos_scn->old_qos_attr.qos_flow_id !=
4133 qos_scn->new_qos_attr.qos_flow_id)
4134 bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
4135 qos_scn->old_qos_attr,
4136 qos_scn->new_qos_attr);
4137 if (qos_scn->old_qos_attr.qos_priority !=
4138 qos_scn->new_qos_attr.qos_priority)
4139 bfa_cb_rport_qos_scn_prio(rp->rport_drv,
4140 qos_scn->old_qos_attr,
4141 qos_scn->new_qos_attr);
4142 break;
4143
4144 default:
4145 bfa_stats(rp, sm_on_unexp);
4146 bfa_sm_fault(rp->bfa, event);
4147 }
4148}
4149
Jing Huang5fbe25c2010-10-18 17:17:23 -07004150/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004151 * Firmware rport is being deleted - awaiting f/w response.
4152 */
4153static void
4154bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
4155{
4156 bfa_trc(rp->bfa, rp->rport_tag);
4157 bfa_trc(rp->bfa, event);
4158
4159 switch (event) {
4160 case BFA_RPORT_SM_FWRSP:
4161 bfa_stats(rp, sm_fwd_rsp);
4162 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4163 bfa_rport_offline_cb(rp);
4164 break;
4165
4166 case BFA_RPORT_SM_DELETE:
4167 bfa_stats(rp, sm_fwd_del);
4168 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4169 break;
4170
4171 case BFA_RPORT_SM_HWFAIL:
4172 bfa_stats(rp, sm_fwd_hwf);
4173 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4174 bfa_rport_offline_cb(rp);
4175 break;
4176
4177 default:
4178 bfa_stats(rp, sm_fwd_unexp);
4179 bfa_sm_fault(rp->bfa, event);
4180 }
4181}
4182
4183static void
4184bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4185{
4186 bfa_trc(rp->bfa, rp->rport_tag);
4187 bfa_trc(rp->bfa, event);
4188
4189 switch (event) {
4190 case BFA_RPORT_SM_QRESUME:
4191 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4192 bfa_rport_send_fwdelete(rp);
4193 break;
4194
4195 case BFA_RPORT_SM_DELETE:
4196 bfa_stats(rp, sm_fwd_del);
4197 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4198 break;
4199
4200 case BFA_RPORT_SM_HWFAIL:
4201 bfa_stats(rp, sm_fwd_hwf);
4202 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4203 bfa_reqq_wcancel(&rp->reqq_wait);
4204 bfa_rport_offline_cb(rp);
4205 break;
4206
4207 default:
4208 bfa_stats(rp, sm_fwd_unexp);
4209 bfa_sm_fault(rp->bfa, event);
4210 }
4211}
4212
Jing Huang5fbe25c2010-10-18 17:17:23 -07004213/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004214 * Offline state.
4215 */
4216static void
4217bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
4218{
4219 bfa_trc(rp->bfa, rp->rport_tag);
4220 bfa_trc(rp->bfa, event);
4221
4222 switch (event) {
4223 case BFA_RPORT_SM_DELETE:
4224 bfa_stats(rp, sm_off_del);
4225 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4226 bfa_rport_free(rp);
4227 break;
4228
4229 case BFA_RPORT_SM_ONLINE:
4230 bfa_stats(rp, sm_off_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_HWFAIL:
4238 bfa_stats(rp, sm_off_hwf);
4239 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4240 break;
4241
4242 default:
4243 bfa_stats(rp, sm_off_unexp);
4244 bfa_sm_fault(rp->bfa, event);
4245 }
4246}
4247
Jing Huang5fbe25c2010-10-18 17:17:23 -07004248/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004249 * Rport is deleted, waiting for firmware response to delete.
4250 */
4251static void
4252bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
4253{
4254 bfa_trc(rp->bfa, rp->rport_tag);
4255 bfa_trc(rp->bfa, event);
4256
4257 switch (event) {
4258 case BFA_RPORT_SM_FWRSP:
4259 bfa_stats(rp, sm_del_fwrsp);
4260 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4261 bfa_rport_free(rp);
4262 break;
4263
4264 case BFA_RPORT_SM_HWFAIL:
4265 bfa_stats(rp, sm_del_hwf);
4266 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4267 bfa_rport_free(rp);
4268 break;
4269
4270 default:
4271 bfa_sm_fault(rp->bfa, event);
4272 }
4273}
4274
4275static void
4276bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4277{
4278 bfa_trc(rp->bfa, rp->rport_tag);
4279 bfa_trc(rp->bfa, event);
4280
4281 switch (event) {
4282 case BFA_RPORT_SM_QRESUME:
4283 bfa_stats(rp, sm_del_fwrsp);
4284 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4285 bfa_rport_send_fwdelete(rp);
4286 break;
4287
4288 case BFA_RPORT_SM_HWFAIL:
4289 bfa_stats(rp, sm_del_hwf);
4290 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4291 bfa_reqq_wcancel(&rp->reqq_wait);
4292 bfa_rport_free(rp);
4293 break;
4294
4295 default:
4296 bfa_sm_fault(rp->bfa, event);
4297 }
4298}
4299
Jing Huang5fbe25c2010-10-18 17:17:23 -07004300/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004301 * Waiting for rport create response from firmware. A delete is pending.
4302 */
4303static void
4304bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
4305 enum bfa_rport_event event)
4306{
4307 bfa_trc(rp->bfa, rp->rport_tag);
4308 bfa_trc(rp->bfa, event);
4309
4310 switch (event) {
4311 case BFA_RPORT_SM_FWRSP:
4312 bfa_stats(rp, sm_delp_fwrsp);
4313 if (bfa_rport_send_fwdelete(rp))
4314 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4315 else
4316 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4317 break;
4318
4319 case BFA_RPORT_SM_HWFAIL:
4320 bfa_stats(rp, sm_delp_hwf);
4321 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4322 bfa_rport_free(rp);
4323 break;
4324
4325 default:
4326 bfa_stats(rp, sm_delp_unexp);
4327 bfa_sm_fault(rp->bfa, event);
4328 }
4329}
4330
Jing Huang5fbe25c2010-10-18 17:17:23 -07004331/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004332 * Waiting for rport create response from firmware. Rport offline is pending.
4333 */
4334static void
4335bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
4336 enum bfa_rport_event event)
4337{
4338 bfa_trc(rp->bfa, rp->rport_tag);
4339 bfa_trc(rp->bfa, event);
4340
4341 switch (event) {
4342 case BFA_RPORT_SM_FWRSP:
4343 bfa_stats(rp, sm_offp_fwrsp);
4344 if (bfa_rport_send_fwdelete(rp))
4345 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4346 else
4347 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4348 break;
4349
4350 case BFA_RPORT_SM_DELETE:
4351 bfa_stats(rp, sm_offp_del);
4352 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4353 break;
4354
4355 case BFA_RPORT_SM_HWFAIL:
4356 bfa_stats(rp, sm_offp_hwf);
4357 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4358 break;
4359
4360 default:
4361 bfa_stats(rp, sm_offp_unexp);
4362 bfa_sm_fault(rp->bfa, event);
4363 }
4364}
4365
Jing Huang5fbe25c2010-10-18 17:17:23 -07004366/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004367 * IOC h/w failed.
4368 */
4369static void
4370bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
4371{
4372 bfa_trc(rp->bfa, rp->rport_tag);
4373 bfa_trc(rp->bfa, event);
4374
4375 switch (event) {
4376 case BFA_RPORT_SM_OFFLINE:
4377 bfa_stats(rp, sm_iocd_off);
4378 bfa_rport_offline_cb(rp);
4379 break;
4380
4381 case BFA_RPORT_SM_DELETE:
4382 bfa_stats(rp, sm_iocd_del);
4383 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4384 bfa_rport_free(rp);
4385 break;
4386
4387 case BFA_RPORT_SM_ONLINE:
4388 bfa_stats(rp, sm_iocd_on);
4389 if (bfa_rport_send_fwcreate(rp))
4390 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4391 else
4392 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4393 break;
4394
4395 case BFA_RPORT_SM_HWFAIL:
4396 break;
4397
4398 default:
4399 bfa_stats(rp, sm_iocd_unexp);
4400 bfa_sm_fault(rp->bfa, event);
4401 }
4402}
4403
4404
4405
Jing Huang5fbe25c2010-10-18 17:17:23 -07004406/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004407 * bfa_rport_private BFA rport private functions
4408 */
4409
4410static void
4411__bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
4412{
4413 struct bfa_rport_s *rp = cbarg;
4414
4415 if (complete)
4416 bfa_cb_rport_online(rp->rport_drv);
4417}
4418
4419static void
4420__bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
4421{
4422 struct bfa_rport_s *rp = cbarg;
4423
4424 if (complete)
4425 bfa_cb_rport_offline(rp->rport_drv);
4426}
4427
4428static void
4429bfa_rport_qresume(void *cbarg)
4430{
4431 struct bfa_rport_s *rp = cbarg;
4432
4433 bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
4434}
4435
4436static void
Krishna Gudipati45070252011-06-24 20:24:29 -07004437bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
4438 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004439{
Krishna Gudipati45070252011-06-24 20:24:29 -07004440 struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa);
4441
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004442 if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
4443 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
4444
Krishna Gudipati45070252011-06-24 20:24:29 -07004445 /* kva memory */
4446 bfa_mem_kva_setup(minfo, rport_kva,
4447 cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004448}
4449
4450static void
4451bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07004452 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004453{
4454 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4455 struct bfa_rport_s *rp;
4456 u16 i;
4457
4458 INIT_LIST_HEAD(&mod->rp_free_q);
4459 INIT_LIST_HEAD(&mod->rp_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004460 INIT_LIST_HEAD(&mod->rp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004461
Krishna Gudipati45070252011-06-24 20:24:29 -07004462 rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004463 mod->rps_list = rp;
4464 mod->num_rports = cfg->fwcfg.num_rports;
4465
Jing Huangd4b671c2010-12-26 21:46:35 -08004466 WARN_ON(!mod->num_rports ||
4467 (mod->num_rports & (mod->num_rports - 1)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004468
4469 for (i = 0; i < mod->num_rports; i++, rp++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004470 memset(rp, 0, sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004471 rp->bfa = bfa;
4472 rp->rport_tag = i;
4473 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4474
Jing Huang5fbe25c2010-10-18 17:17:23 -07004475 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004476 * - is unused
4477 */
4478 if (i)
4479 list_add_tail(&rp->qe, &mod->rp_free_q);
4480
4481 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
4482 }
4483
Jing Huang5fbe25c2010-10-18 17:17:23 -07004484 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004485 * consume memory
4486 */
Krishna Gudipati45070252011-06-24 20:24:29 -07004487 bfa_mem_kva_curp(mod) = (u8 *) rp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004488}
4489
4490static void
4491bfa_rport_detach(struct bfa_s *bfa)
4492{
4493}
4494
4495static void
4496bfa_rport_start(struct bfa_s *bfa)
4497{
4498}
4499
4500static void
4501bfa_rport_stop(struct bfa_s *bfa)
4502{
4503}
4504
4505static void
4506bfa_rport_iocdisable(struct bfa_s *bfa)
4507{
4508 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4509 struct bfa_rport_s *rport;
4510 struct list_head *qe, *qen;
4511
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004512 /* Enqueue unused rport resources to free_q */
4513 list_splice_tail_init(&mod->rp_unused_q, &mod->rp_free_q);
4514
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004515 list_for_each_safe(qe, qen, &mod->rp_active_q) {
4516 rport = (struct bfa_rport_s *) qe;
4517 bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
4518 }
4519}
4520
4521static struct bfa_rport_s *
4522bfa_rport_alloc(struct bfa_rport_mod_s *mod)
4523{
4524 struct bfa_rport_s *rport;
4525
4526 bfa_q_deq(&mod->rp_free_q, &rport);
4527 if (rport)
4528 list_add_tail(&rport->qe, &mod->rp_active_q);
4529
4530 return rport;
4531}
4532
4533static void
4534bfa_rport_free(struct bfa_rport_s *rport)
4535{
4536 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
4537
Jing Huangd4b671c2010-12-26 21:46:35 -08004538 WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004539 list_del(&rport->qe);
4540 list_add_tail(&rport->qe, &mod->rp_free_q);
4541}
4542
4543static bfa_boolean_t
4544bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4545{
4546 struct bfi_rport_create_req_s *m;
4547
Jing Huang5fbe25c2010-10-18 17:17:23 -07004548 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004549 * check for room in queue to send request now
4550 */
4551 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4552 if (!m) {
4553 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4554 return BFA_FALSE;
4555 }
4556
4557 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004558 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004559 m->bfa_handle = rp->rport_tag;
Jing Huangba816ea2010-10-18 17:10:50 -07004560 m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004561 m->pid = rp->rport_info.pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004562 m->lp_fwtag = bfa_lps_get_fwtag(rp->bfa, (u8)rp->rport_info.lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004563 m->local_pid = rp->rport_info.local_pid;
4564 m->fc_class = rp->rport_info.fc_class;
4565 m->vf_en = rp->rport_info.vf_en;
4566 m->vf_id = rp->rport_info.vf_id;
4567 m->cisc = rp->rport_info.cisc;
4568
Jing Huang5fbe25c2010-10-18 17:17:23 -07004569 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004570 * queue I/O message to firmware
4571 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004572 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004573 return BFA_TRUE;
4574}
4575
4576static bfa_boolean_t
4577bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4578{
4579 struct bfi_rport_delete_req_s *m;
4580
Jing Huang5fbe25c2010-10-18 17:17:23 -07004581 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004582 * check for room in queue to send request now
4583 */
4584 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4585 if (!m) {
4586 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4587 return BFA_FALSE;
4588 }
4589
4590 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004591 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004592 m->fw_handle = rp->fw_handle;
4593
Jing Huang5fbe25c2010-10-18 17:17:23 -07004594 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004595 * queue I/O message to firmware
4596 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004597 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004598 return BFA_TRUE;
4599}
4600
4601static bfa_boolean_t
4602bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4603{
4604 struct bfa_rport_speed_req_s *m;
4605
Jing Huang5fbe25c2010-10-18 17:17:23 -07004606 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004607 * check for room in queue to send request now
4608 */
4609 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4610 if (!m) {
4611 bfa_trc(rp->bfa, rp->rport_info.speed);
4612 return BFA_FALSE;
4613 }
4614
4615 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004616 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004617 m->fw_handle = rp->fw_handle;
4618 m->speed = (u8)rp->rport_info.speed;
4619
Jing Huang5fbe25c2010-10-18 17:17:23 -07004620 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004621 * queue I/O message to firmware
4622 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004623 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004624 return BFA_TRUE;
4625}
4626
4627
4628
Jing Huang5fbe25c2010-10-18 17:17:23 -07004629/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004630 * bfa_rport_public
4631 */
4632
Jing Huang5fbe25c2010-10-18 17:17:23 -07004633/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004634 * Rport interrupt processing.
4635 */
4636void
4637bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
4638{
4639 union bfi_rport_i2h_msg_u msg;
4640 struct bfa_rport_s *rp;
4641
4642 bfa_trc(bfa, m->mhdr.msg_id);
4643
4644 msg.msg = m;
4645
4646 switch (m->mhdr.msg_id) {
4647 case BFI_RPORT_I2H_CREATE_RSP:
4648 rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
4649 rp->fw_handle = msg.create_rsp->fw_handle;
4650 rp->qos_attr = msg.create_rsp->qos_attr;
Krishna Gudipati83763d52011-07-20 17:04:03 -07004651 bfa_rport_set_lunmask(bfa, rp);
Jing Huangd4b671c2010-12-26 21:46:35 -08004652 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004653 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4654 break;
4655
4656 case BFI_RPORT_I2H_DELETE_RSP:
4657 rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08004658 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
Krishna Gudipati83763d52011-07-20 17:04:03 -07004659 bfa_rport_unset_lunmask(bfa, rp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004660 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4661 break;
4662
4663 case BFI_RPORT_I2H_QOS_SCN:
4664 rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
4665 rp->event_arg.fw_msg = msg.qos_scn_evt;
4666 bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
4667 break;
4668
4669 default:
4670 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08004671 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004672 }
4673}
4674
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004675void
4676bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw)
4677{
4678 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4679 struct list_head *qe;
4680 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004681
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004682 for (i = 0; i < (mod->num_rports - num_rport_fw); i++) {
4683 bfa_q_deq_tail(&mod->rp_free_q, &qe);
4684 list_add_tail(qe, &mod->rp_unused_q);
4685 }
4686}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004687
Jing Huang5fbe25c2010-10-18 17:17:23 -07004688/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004689 * bfa_rport_api
4690 */
4691
4692struct bfa_rport_s *
4693bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
4694{
4695 struct bfa_rport_s *rp;
4696
4697 rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
4698
4699 if (rp == NULL)
4700 return NULL;
4701
4702 rp->bfa = bfa;
4703 rp->rport_drv = rport_drv;
Maggie Zhangf7f738122010-12-09 19:08:43 -08004704 memset(&rp->stats, 0, sizeof(rp->stats));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004705
Jing Huangd4b671c2010-12-26 21:46:35 -08004706 WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004707 bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
4708
4709 return rp;
4710}
4711
4712void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004713bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
4714{
Jing Huangd4b671c2010-12-26 21:46:35 -08004715 WARN_ON(rport_info->max_frmsz == 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004716
Jing Huang5fbe25c2010-10-18 17:17:23 -07004717 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004718 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
4719 * responses. Default to minimum size.
4720 */
4721 if (rport_info->max_frmsz == 0) {
4722 bfa_trc(rport->bfa, rport->rport_tag);
4723 rport_info->max_frmsz = FC_MIN_PDUSZ;
4724 }
4725
Jing Huang6a18b162010-10-18 17:08:54 -07004726 rport->rport_info = *rport_info;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004727 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
4728}
4729
4730void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004731bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
4732{
Jing Huangd4b671c2010-12-26 21:46:35 -08004733 WARN_ON(speed == 0);
4734 WARN_ON(speed == BFA_PORT_SPEED_AUTO);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004735
4736 rport->rport_info.speed = speed;
4737 bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
4738}
4739
Krishna Gudipati83763d52011-07-20 17:04:03 -07004740/* Set Rport LUN Mask */
4741void
4742bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
4743{
4744 struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
4745 wwn_t lp_wwn, rp_wwn;
4746 u8 lp_tag = (u8)rp->rport_info.lp_tag;
4747
4748 rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
4749 lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
4750
4751 BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
4752 rp->lun_mask = BFA_TRUE;
4753 bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn, rp->rport_tag, lp_tag);
4754}
4755
4756/* Unset Rport LUN mask */
4757void
4758bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
4759{
4760 struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
4761 wwn_t lp_wwn, rp_wwn;
4762
4763 rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
4764 lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
4765
4766 BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
4767 rp->lun_mask = BFA_FALSE;
4768 bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn,
4769 BFA_RPORT_TAG_INVALID, BFA_LP_TAG_INVALID);
4770}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004771
Jing Huang5fbe25c2010-10-18 17:17:23 -07004772/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004773 * SGPG related functions
4774 */
4775
Jing Huang5fbe25c2010-10-18 17:17:23 -07004776/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004777 * Compute and return memory needed by FCP(im) module.
4778 */
4779static void
Krishna Gudipati45070252011-06-24 20:24:29 -07004780bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
4781 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004782{
Krishna Gudipati45070252011-06-24 20:24:29 -07004783 struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa);
4784 struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa);
4785 struct bfa_mem_dma_s *seg_ptr;
4786 u16 nsegs, idx, per_seg_sgpg, num_sgpg;
4787 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
4788
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004789 if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
4790 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
Krishna Gudipati45070252011-06-24 20:24:29 -07004791 else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX)
4792 cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004793
Krishna Gudipati45070252011-06-24 20:24:29 -07004794 num_sgpg = cfg->drvcfg.num_sgpgs;
4795
4796 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
4797 per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz);
4798
4799 bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) {
4800 if (num_sgpg >= per_seg_sgpg) {
4801 num_sgpg -= per_seg_sgpg;
4802 bfa_mem_dma_setup(minfo, seg_ptr,
4803 per_seg_sgpg * sgpg_sz);
4804 } else
4805 bfa_mem_dma_setup(minfo, seg_ptr,
4806 num_sgpg * sgpg_sz);
4807 }
4808
4809 /* kva memory */
4810 bfa_mem_kva_setup(minfo, sgpg_kva,
4811 cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004812}
4813
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004814static void
4815bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07004816 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004817{
4818 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004819 struct bfa_sgpg_s *hsgpg;
4820 struct bfi_sgpg_s *sgpg;
4821 u64 align_len;
Krishna Gudipati45070252011-06-24 20:24:29 -07004822 struct bfa_mem_dma_s *seg_ptr;
4823 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
4824 u16 i, idx, nsegs, per_seg_sgpg, num_sgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004825
4826 union {
4827 u64 pa;
4828 union bfi_addr_u addr;
4829 } sgpg_pa, sgpg_pa_tmp;
4830
4831 INIT_LIST_HEAD(&mod->sgpg_q);
4832 INIT_LIST_HEAD(&mod->sgpg_wait_q);
4833
4834 bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
4835
Krishna Gudipati45070252011-06-24 20:24:29 -07004836 mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004837
Krishna Gudipati45070252011-06-24 20:24:29 -07004838 num_sgpg = cfg->drvcfg.num_sgpgs;
4839 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004840
Krishna Gudipati45070252011-06-24 20:24:29 -07004841 /* dma/kva mem claim */
4842 hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004843
Krishna Gudipati45070252011-06-24 20:24:29 -07004844 bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004845
Krishna Gudipati45070252011-06-24 20:24:29 -07004846 if (!bfa_mem_dma_virt(seg_ptr))
4847 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004848
Krishna Gudipati45070252011-06-24 20:24:29 -07004849 align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) -
4850 bfa_mem_dma_phys(seg_ptr);
4851
4852 sgpg = (struct bfi_sgpg_s *)
4853 (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len);
4854 sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len;
4855 WARN_ON(sgpg_pa.pa & (sgpg_sz - 1));
4856
4857 per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz;
4858
4859 for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) {
4860 memset(hsgpg, 0, sizeof(*hsgpg));
4861 memset(sgpg, 0, sizeof(*sgpg));
4862
4863 hsgpg->sgpg = sgpg;
4864 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
4865 hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
4866 list_add_tail(&hsgpg->qe, &mod->sgpg_q);
4867
4868 sgpg++;
4869 hsgpg++;
4870 sgpg_pa.pa += sgpg_sz;
4871 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004872 }
4873
Krishna Gudipati45070252011-06-24 20:24:29 -07004874 bfa_mem_kva_curp(mod) = (u8 *) hsgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004875}
4876
4877static void
4878bfa_sgpg_detach(struct bfa_s *bfa)
4879{
4880}
4881
4882static void
4883bfa_sgpg_start(struct bfa_s *bfa)
4884{
4885}
4886
4887static void
4888bfa_sgpg_stop(struct bfa_s *bfa)
4889{
4890}
4891
4892static void
4893bfa_sgpg_iocdisable(struct bfa_s *bfa)
4894{
4895}
4896
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004897bfa_status_t
4898bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
4899{
4900 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4901 struct bfa_sgpg_s *hsgpg;
4902 int i;
4903
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004904 if (mod->free_sgpgs < nsgpgs)
4905 return BFA_STATUS_ENOMEM;
4906
4907 for (i = 0; i < nsgpgs; i++) {
4908 bfa_q_deq(&mod->sgpg_q, &hsgpg);
Jing Huangd4b671c2010-12-26 21:46:35 -08004909 WARN_ON(!hsgpg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004910 list_add_tail(&hsgpg->qe, sgpg_q);
4911 }
4912
4913 mod->free_sgpgs -= nsgpgs;
4914 return BFA_STATUS_OK;
4915}
4916
4917void
4918bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
4919{
4920 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4921 struct bfa_sgpg_wqe_s *wqe;
4922
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004923 mod->free_sgpgs += nsgpg;
Jing Huangd4b671c2010-12-26 21:46:35 -08004924 WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004925
4926 list_splice_tail_init(sgpg_q, &mod->sgpg_q);
4927
4928 if (list_empty(&mod->sgpg_wait_q))
4929 return;
4930
Jing Huang5fbe25c2010-10-18 17:17:23 -07004931 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004932 * satisfy as many waiting requests as possible
4933 */
4934 do {
4935 wqe = bfa_q_first(&mod->sgpg_wait_q);
4936 if (mod->free_sgpgs < wqe->nsgpg)
4937 nsgpg = mod->free_sgpgs;
4938 else
4939 nsgpg = wqe->nsgpg;
4940 bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
4941 wqe->nsgpg -= nsgpg;
4942 if (wqe->nsgpg == 0) {
4943 list_del(&wqe->qe);
4944 wqe->cbfn(wqe->cbarg);
4945 }
4946 } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
4947}
4948
4949void
4950bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
4951{
4952 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4953
Jing Huangd4b671c2010-12-26 21:46:35 -08004954 WARN_ON(nsgpg <= 0);
4955 WARN_ON(nsgpg <= mod->free_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004956
4957 wqe->nsgpg_total = wqe->nsgpg = nsgpg;
4958
Jing Huang5fbe25c2010-10-18 17:17:23 -07004959 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004960 * allocate any left to this one first
4961 */
4962 if (mod->free_sgpgs) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07004963 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004964 * no one else is waiting for SGPG
4965 */
Jing Huangd4b671c2010-12-26 21:46:35 -08004966 WARN_ON(!list_empty(&mod->sgpg_wait_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004967 list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
4968 wqe->nsgpg -= mod->free_sgpgs;
4969 mod->free_sgpgs = 0;
4970 }
4971
4972 list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
4973}
4974
4975void
4976bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
4977{
4978 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4979
Jing Huangd4b671c2010-12-26 21:46:35 -08004980 WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004981 list_del(&wqe->qe);
4982
4983 if (wqe->nsgpg_total != wqe->nsgpg)
4984 bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
4985 wqe->nsgpg_total - wqe->nsgpg);
4986}
4987
4988void
4989bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
4990 void *cbarg)
4991{
4992 INIT_LIST_HEAD(&wqe->sgpg_q);
4993 wqe->cbfn = cbfn;
4994 wqe->cbarg = cbarg;
4995}
4996
Jing Huang5fbe25c2010-10-18 17:17:23 -07004997/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004998 * UF related functions
4999 */
5000/*
5001 *****************************************************************************
5002 * Internal functions
5003 *****************************************************************************
5004 */
5005static void
5006__bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
5007{
5008 struct bfa_uf_s *uf = cbarg;
5009 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
5010
5011 if (complete)
5012 ufm->ufrecv(ufm->cbarg, uf);
5013}
5014
5015static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005016claim_uf_post_msgs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005017{
5018 struct bfi_uf_buf_post_s *uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005019 u16 i;
5020 u16 buf_len;
5021
Krishna Gudipati45070252011-06-24 20:24:29 -07005022 ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005023 uf_bp_msg = ufm->uf_buf_posts;
5024
5025 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
5026 i++, uf_bp_msg++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005027 memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005028
5029 uf_bp_msg->buf_tag = i;
5030 buf_len = sizeof(struct bfa_uf_buf_s);
Jing Huangba816ea2010-10-18 17:10:50 -07005031 uf_bp_msg->buf_len = cpu_to_be16(buf_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005032 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005033 bfa_fn_lpu(ufm->bfa));
Krishna Gudipati85ce9282011-06-13 15:39:36 -07005034 bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005035 }
5036
Jing Huang5fbe25c2010-10-18 17:17:23 -07005037 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005038 * advance pointer beyond consumed memory
5039 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005040 bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005041}
5042
5043static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005044claim_ufs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005045{
5046 u16 i;
5047 struct bfa_uf_s *uf;
5048
5049 /*
5050 * Claim block of memory for UF list
5051 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005052 ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005053
5054 /*
5055 * Initialize UFs and queue it in UF free queue
5056 */
5057 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005058 memset(uf, 0, sizeof(struct bfa_uf_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005059 uf->bfa = ufm->bfa;
5060 uf->uf_tag = i;
Krishna Gudipati45070252011-06-24 20:24:29 -07005061 uf->pb_len = BFA_PER_UF_DMA_SZ;
5062 uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005063 uf->buf_pa = ufm_pbs_pa(ufm, i);
5064 list_add_tail(&uf->qe, &ufm->uf_free_q);
5065 }
5066
Jing Huang5fbe25c2010-10-18 17:17:23 -07005067 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005068 * advance memory pointer
5069 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005070 bfa_mem_kva_curp(ufm) = (u8 *) uf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005071}
5072
5073static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005074uf_mem_claim(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005075{
Krishna Gudipati45070252011-06-24 20:24:29 -07005076 claim_ufs(ufm);
5077 claim_uf_post_msgs(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005078}
5079
5080static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005081bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
5082 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005083{
Krishna Gudipati45070252011-06-24 20:24:29 -07005084 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5085 struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa);
5086 u32 num_ufs = cfg->fwcfg.num_uf_bufs;
5087 struct bfa_mem_dma_s *seg_ptr;
5088 u16 nsegs, idx, per_seg_uf = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005089
Krishna Gudipati45070252011-06-24 20:24:29 -07005090 nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ);
5091 per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005092
Krishna Gudipati45070252011-06-24 20:24:29 -07005093 bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) {
5094 if (num_ufs >= per_seg_uf) {
5095 num_ufs -= per_seg_uf;
5096 bfa_mem_dma_setup(minfo, seg_ptr,
5097 per_seg_uf * BFA_PER_UF_DMA_SZ);
5098 } else
5099 bfa_mem_dma_setup(minfo, seg_ptr,
5100 num_ufs * BFA_PER_UF_DMA_SZ);
5101 }
5102
5103 /* kva memory */
5104 bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs *
5105 (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005106}
5107
5108static void
5109bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07005110 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005111{
5112 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5113
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005114 ufm->bfa = bfa;
5115 ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
5116 INIT_LIST_HEAD(&ufm->uf_free_q);
5117 INIT_LIST_HEAD(&ufm->uf_posted_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005118 INIT_LIST_HEAD(&ufm->uf_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005119
Krishna Gudipati45070252011-06-24 20:24:29 -07005120 uf_mem_claim(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005121}
5122
5123static void
5124bfa_uf_detach(struct bfa_s *bfa)
5125{
5126}
5127
5128static struct bfa_uf_s *
5129bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
5130{
5131 struct bfa_uf_s *uf;
5132
5133 bfa_q_deq(&uf_mod->uf_free_q, &uf);
5134 return uf;
5135}
5136
5137static void
5138bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
5139{
5140 list_add_tail(&uf->qe, &uf_mod->uf_free_q);
5141}
5142
5143static bfa_status_t
5144bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
5145{
5146 struct bfi_uf_buf_post_s *uf_post_msg;
5147
5148 uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
5149 if (!uf_post_msg)
5150 return BFA_STATUS_FAILED;
5151
Jing Huang6a18b162010-10-18 17:08:54 -07005152 memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005153 sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005154 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP, uf_post_msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005155
5156 bfa_trc(ufm->bfa, uf->uf_tag);
5157
5158 list_add_tail(&uf->qe, &ufm->uf_posted_q);
5159 return BFA_STATUS_OK;
5160}
5161
5162static void
5163bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
5164{
5165 struct bfa_uf_s *uf;
5166
5167 while ((uf = bfa_uf_get(uf_mod)) != NULL) {
5168 if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
5169 break;
5170 }
5171}
5172
5173static void
5174uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
5175{
5176 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5177 u16 uf_tag = m->buf_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005178 struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
Krishna Gudipati45070252011-06-24 20:24:29 -07005179 struct bfa_uf_buf_s *uf_buf;
5180 uint8_t *buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005181 struct fchs_s *fchs;
5182
Krishna Gudipati45070252011-06-24 20:24:29 -07005183 uf_buf = (struct bfa_uf_buf_s *)
5184 bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len);
5185 buf = &uf_buf->d[0];
5186
Jing Huangba816ea2010-10-18 17:10:50 -07005187 m->frm_len = be16_to_cpu(m->frm_len);
5188 m->xfr_len = be16_to_cpu(m->xfr_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005189
5190 fchs = (struct fchs_s *)uf_buf;
5191
5192 list_del(&uf->qe); /* dequeue from posted queue */
5193
5194 uf->data_ptr = buf;
5195 uf->data_len = m->xfr_len;
5196
Jing Huangd4b671c2010-12-26 21:46:35 -08005197 WARN_ON(uf->data_len < sizeof(struct fchs_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005198
5199 if (uf->data_len == sizeof(struct fchs_s)) {
5200 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
5201 uf->data_len, (struct fchs_s *)buf);
5202 } else {
5203 u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
5204 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
5205 BFA_PL_EID_RX, uf->data_len,
5206 (struct fchs_s *)buf, pld_w0);
5207 }
5208
5209 if (bfa->fcs)
5210 __bfa_cb_uf_recv(uf, BFA_TRUE);
5211 else
5212 bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
5213}
5214
5215static void
5216bfa_uf_stop(struct bfa_s *bfa)
5217{
5218}
5219
5220static void
5221bfa_uf_iocdisable(struct bfa_s *bfa)
5222{
5223 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5224 struct bfa_uf_s *uf;
5225 struct list_head *qe, *qen;
5226
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005227 /* Enqueue unused uf resources to free_q */
5228 list_splice_tail_init(&ufm->uf_unused_q, &ufm->uf_free_q);
5229
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005230 list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
5231 uf = (struct bfa_uf_s *) qe;
5232 list_del(&uf->qe);
5233 bfa_uf_put(ufm, uf);
5234 }
5235}
5236
5237static void
5238bfa_uf_start(struct bfa_s *bfa)
5239{
5240 bfa_uf_post_all(BFA_UF_MOD(bfa));
5241}
5242
Jing Huang5fbe25c2010-10-18 17:17:23 -07005243/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005244 * Register handler for all unsolicted receive frames.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005245 *
5246 * @param[in] bfa BFA instance
5247 * @param[in] ufrecv receive handler function
5248 * @param[in] cbarg receive handler arg
5249 */
5250void
5251bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
5252{
5253 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5254
5255 ufm->ufrecv = ufrecv;
5256 ufm->cbarg = cbarg;
5257}
5258
Jing Huang5fbe25c2010-10-18 17:17:23 -07005259/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005260 * Free an unsolicited frame back to BFA.
5261 *
5262 * @param[in] uf unsolicited frame to be freed
5263 *
5264 * @return None
5265 */
5266void
5267bfa_uf_free(struct bfa_uf_s *uf)
5268{
5269 bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
5270 bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
5271}
5272
5273
5274
Jing Huang5fbe25c2010-10-18 17:17:23 -07005275/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005276 * uf_pub BFA uf module public functions
5277 */
5278void
5279bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5280{
5281 bfa_trc(bfa, msg->mhdr.msg_id);
5282
5283 switch (msg->mhdr.msg_id) {
5284 case BFI_UF_I2H_FRM_RCVD:
5285 uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
5286 break;
5287
5288 default:
5289 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08005290 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005291 }
5292}
5293
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005294void
5295bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw)
5296{
5297 struct bfa_uf_mod_s *mod = BFA_UF_MOD(bfa);
5298 struct list_head *qe;
5299 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005300
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005301 for (i = 0; i < (mod->num_ufs - num_uf_fw); i++) {
5302 bfa_q_deq_tail(&mod->uf_free_q, &qe);
5303 list_add_tail(qe, &mod->uf_unused_q);
5304 }
5305}
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005306
5307/*
5308 * BFA fcdiag module
5309 */
5310#define BFA_DIAG_QTEST_TOV 1000 /* msec */
5311
5312/*
5313 * Set port status to busy
5314 */
5315static void
5316bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s *fcdiag)
5317{
5318 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fcdiag->bfa);
5319
5320 if (fcdiag->lb.lock)
5321 fcport->diag_busy = BFA_TRUE;
5322 else
5323 fcport->diag_busy = BFA_FALSE;
5324}
5325
5326static void
5327bfa_fcdiag_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
5328 struct bfa_s *bfa)
5329{
5330}
5331
5332static void
5333bfa_fcdiag_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
5334 struct bfa_pcidev_s *pcidev)
5335{
5336 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5337 fcdiag->bfa = bfa;
5338 fcdiag->trcmod = bfa->trcmod;
5339 /* The common DIAG attach bfa_diag_attach() will do all memory claim */
5340}
5341
5342static void
5343bfa_fcdiag_iocdisable(struct bfa_s *bfa)
5344{
5345 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5346 bfa_trc(fcdiag, fcdiag->lb.lock);
5347 if (fcdiag->lb.lock) {
5348 fcdiag->lb.status = BFA_STATUS_IOC_FAILURE;
5349 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5350 fcdiag->lb.lock = 0;
5351 bfa_fcdiag_set_busy_status(fcdiag);
5352 }
5353}
5354
5355static void
5356bfa_fcdiag_detach(struct bfa_s *bfa)
5357{
5358}
5359
5360static void
5361bfa_fcdiag_start(struct bfa_s *bfa)
5362{
5363}
5364
5365static void
5366bfa_fcdiag_stop(struct bfa_s *bfa)
5367{
5368}
5369
5370static void
5371bfa_fcdiag_queuetest_timeout(void *cbarg)
5372{
5373 struct bfa_fcdiag_s *fcdiag = cbarg;
5374 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5375
5376 bfa_trc(fcdiag, fcdiag->qtest.all);
5377 bfa_trc(fcdiag, fcdiag->qtest.count);
5378
5379 fcdiag->qtest.timer_active = 0;
5380
5381 res->status = BFA_STATUS_ETIMER;
5382 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5383 if (fcdiag->qtest.all)
5384 res->queue = fcdiag->qtest.all;
5385
5386 bfa_trc(fcdiag, BFA_STATUS_ETIMER);
5387 fcdiag->qtest.status = BFA_STATUS_ETIMER;
5388 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5389 fcdiag->qtest.lock = 0;
5390}
5391
5392static bfa_status_t
5393bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s *fcdiag)
5394{
5395 u32 i;
5396 struct bfi_diag_qtest_req_s *req;
5397
5398 req = bfa_reqq_next(fcdiag->bfa, fcdiag->qtest.queue);
5399 if (!req)
5400 return BFA_STATUS_DEVBUSY;
5401
5402 /* build host command */
5403 bfi_h2i_set(req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_QTEST,
5404 bfa_fn_lpu(fcdiag->bfa));
5405
5406 for (i = 0; i < BFI_LMSG_PL_WSZ; i++)
5407 req->data[i] = QTEST_PAT_DEFAULT;
5408
5409 bfa_trc(fcdiag, fcdiag->qtest.queue);
5410 /* ring door bell */
5411 bfa_reqq_produce(fcdiag->bfa, fcdiag->qtest.queue, req->mh);
5412 return BFA_STATUS_OK;
5413}
5414
5415static void
5416bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s *fcdiag,
5417 bfi_diag_qtest_rsp_t *rsp)
5418{
5419 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5420 bfa_status_t status = BFA_STATUS_OK;
5421 int i;
5422
5423 /* Check timer, should still be active */
5424 if (!fcdiag->qtest.timer_active) {
5425 bfa_trc(fcdiag, fcdiag->qtest.timer_active);
5426 return;
5427 }
5428
5429 /* update count */
5430 fcdiag->qtest.count--;
5431
5432 /* Check result */
5433 for (i = 0; i < BFI_LMSG_PL_WSZ; i++) {
5434 if (rsp->data[i] != ~(QTEST_PAT_DEFAULT)) {
5435 res->status = BFA_STATUS_DATACORRUPTED;
5436 break;
5437 }
5438 }
5439
5440 if (res->status == BFA_STATUS_OK) {
5441 if (fcdiag->qtest.count > 0) {
5442 status = bfa_fcdiag_queuetest_send(fcdiag);
5443 if (status == BFA_STATUS_OK)
5444 return;
5445 else
5446 res->status = status;
5447 } else if (fcdiag->qtest.all > 0 &&
5448 fcdiag->qtest.queue < (BFI_IOC_MAX_CQS - 1)) {
5449 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
5450 fcdiag->qtest.queue++;
5451 status = bfa_fcdiag_queuetest_send(fcdiag);
5452 if (status == BFA_STATUS_OK)
5453 return;
5454 else
5455 res->status = status;
5456 }
5457 }
5458
5459 /* Stop timer when we comp all queue */
5460 if (fcdiag->qtest.timer_active) {
5461 bfa_timer_stop(&fcdiag->qtest.timer);
5462 fcdiag->qtest.timer_active = 0;
5463 }
5464 res->queue = fcdiag->qtest.queue;
5465 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5466 bfa_trc(fcdiag, res->count);
5467 bfa_trc(fcdiag, res->status);
5468 fcdiag->qtest.status = res->status;
5469 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5470 fcdiag->qtest.lock = 0;
5471}
5472
5473static void
5474bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s *fcdiag,
5475 struct bfi_diag_lb_rsp_s *rsp)
5476{
5477 struct bfa_diag_loopback_result_s *res = fcdiag->lb.result;
5478
5479 res->numtxmfrm = be32_to_cpu(rsp->res.numtxmfrm);
5480 res->numosffrm = be32_to_cpu(rsp->res.numosffrm);
5481 res->numrcvfrm = be32_to_cpu(rsp->res.numrcvfrm);
5482 res->badfrminf = be32_to_cpu(rsp->res.badfrminf);
5483 res->badfrmnum = be32_to_cpu(rsp->res.badfrmnum);
5484 res->status = rsp->res.status;
5485 fcdiag->lb.status = rsp->res.status;
5486 bfa_trc(fcdiag, fcdiag->lb.status);
5487 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5488 fcdiag->lb.lock = 0;
5489 bfa_fcdiag_set_busy_status(fcdiag);
5490}
5491
5492static bfa_status_t
5493bfa_fcdiag_loopback_send(struct bfa_fcdiag_s *fcdiag,
5494 struct bfa_diag_loopback_s *loopback)
5495{
5496 struct bfi_diag_lb_req_s *lb_req;
5497
5498 lb_req = bfa_reqq_next(fcdiag->bfa, BFA_REQQ_DIAG);
5499 if (!lb_req)
5500 return BFA_STATUS_DEVBUSY;
5501
5502 /* build host command */
5503 bfi_h2i_set(lb_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LOOPBACK,
5504 bfa_fn_lpu(fcdiag->bfa));
5505
5506 lb_req->lb_mode = loopback->lb_mode;
5507 lb_req->speed = loopback->speed;
5508 lb_req->loopcnt = loopback->loopcnt;
5509 lb_req->pattern = loopback->pattern;
5510
5511 /* ring door bell */
5512 bfa_reqq_produce(fcdiag->bfa, BFA_REQQ_DIAG, lb_req->mh);
5513
5514 bfa_trc(fcdiag, loopback->lb_mode);
5515 bfa_trc(fcdiag, loopback->speed);
5516 bfa_trc(fcdiag, loopback->loopcnt);
5517 bfa_trc(fcdiag, loopback->pattern);
5518 return BFA_STATUS_OK;
5519}
5520
5521/*
5522 * cpe/rme intr handler
5523 */
5524void
5525bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5526{
5527 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5528
5529 switch (msg->mhdr.msg_id) {
5530 case BFI_DIAG_I2H_LOOPBACK:
5531 bfa_fcdiag_loopback_comp(fcdiag,
5532 (struct bfi_diag_lb_rsp_s *) msg);
5533 break;
5534 case BFI_DIAG_I2H_QTEST:
5535 bfa_fcdiag_queuetest_comp(fcdiag, (bfi_diag_qtest_rsp_t *)msg);
5536 break;
5537 default:
5538 bfa_trc(fcdiag, msg->mhdr.msg_id);
5539 WARN_ON(1);
5540 }
5541}
5542
5543/*
5544 * Loopback test
5545 *
5546 * @param[in] *bfa - bfa data struct
5547 * @param[in] opmode - port operation mode
5548 * @param[in] speed - port speed
5549 * @param[in] lpcnt - loop count
5550 * @param[in] pat - pattern to build packet
5551 * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
5552 * @param[in] cbfn - callback function
5553 * @param[in] cbarg - callback functioin arg
5554 *
5555 * @param[out]
5556 */
5557bfa_status_t
5558bfa_fcdiag_loopback(struct bfa_s *bfa, enum bfa_port_opmode opmode,
5559 enum bfa_port_speed speed, u32 lpcnt, u32 pat,
5560 struct bfa_diag_loopback_result_s *result, bfa_cb_diag_t cbfn,
5561 void *cbarg)
5562{
5563 struct bfa_diag_loopback_s loopback;
5564 struct bfa_port_attr_s attr;
5565 bfa_status_t status;
5566 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5567
5568 if (!bfa_iocfc_is_operational(bfa))
5569 return BFA_STATUS_IOC_NON_OP;
5570
5571 /* if port is PBC disabled, return error */
5572 if (bfa_fcport_is_pbcdisabled(bfa)) {
5573 bfa_trc(fcdiag, BFA_STATUS_PBC);
5574 return BFA_STATUS_PBC;
5575 }
5576
5577 if (bfa_fcport_is_disabled(bfa) == BFA_FALSE) {
5578 bfa_trc(fcdiag, opmode);
5579 return BFA_STATUS_PORT_NOT_DISABLED;
5580 }
5581
Krishna Gudipatifb778b02011-07-20 17:01:07 -07005582 /*
5583 * Check if input speed is supported by the port mode
5584 */
5585 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
5586 if (!(speed == BFA_PORT_SPEED_1GBPS ||
5587 speed == BFA_PORT_SPEED_2GBPS ||
5588 speed == BFA_PORT_SPEED_4GBPS ||
5589 speed == BFA_PORT_SPEED_8GBPS ||
5590 speed == BFA_PORT_SPEED_16GBPS ||
5591 speed == BFA_PORT_SPEED_AUTO)) {
5592 bfa_trc(fcdiag, speed);
5593 return BFA_STATUS_UNSUPP_SPEED;
5594 }
5595 bfa_fcport_get_attr(bfa, &attr);
5596 bfa_trc(fcdiag, attr.speed_supported);
5597 if (speed > attr.speed_supported)
5598 return BFA_STATUS_UNSUPP_SPEED;
5599 } else {
5600 if (speed != BFA_PORT_SPEED_10GBPS) {
5601 bfa_trc(fcdiag, speed);
5602 return BFA_STATUS_UNSUPP_SPEED;
5603 }
5604 }
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005605
5606 /* For Mezz card, port speed entered needs to be checked */
5607 if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) {
5608 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
5609 if ((speed == BFA_PORT_SPEED_1GBPS) &&
5610 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
5611 return BFA_STATUS_UNSUPP_SPEED;
5612 if (!(speed == BFA_PORT_SPEED_1GBPS ||
5613 speed == BFA_PORT_SPEED_2GBPS ||
5614 speed == BFA_PORT_SPEED_4GBPS ||
5615 speed == BFA_PORT_SPEED_8GBPS ||
5616 speed == BFA_PORT_SPEED_16GBPS ||
5617 speed == BFA_PORT_SPEED_AUTO))
5618 return BFA_STATUS_UNSUPP_SPEED;
5619 } else {
5620 if (speed != BFA_PORT_SPEED_10GBPS)
5621 return BFA_STATUS_UNSUPP_SPEED;
5622 }
5623 }
5624
5625 /* check to see if there is another destructive diag cmd running */
5626 if (fcdiag->lb.lock) {
5627 bfa_trc(fcdiag, fcdiag->lb.lock);
5628 return BFA_STATUS_DEVBUSY;
5629 }
5630
5631 fcdiag->lb.lock = 1;
5632 loopback.lb_mode = opmode;
5633 loopback.speed = speed;
5634 loopback.loopcnt = lpcnt;
5635 loopback.pattern = pat;
5636 fcdiag->lb.result = result;
5637 fcdiag->lb.cbfn = cbfn;
5638 fcdiag->lb.cbarg = cbarg;
5639 memset(result, 0, sizeof(struct bfa_diag_loopback_result_s));
5640 bfa_fcdiag_set_busy_status(fcdiag);
5641
5642 /* Send msg to fw */
5643 status = bfa_fcdiag_loopback_send(fcdiag, &loopback);
5644 return status;
5645}
5646
5647/*
5648 * DIAG queue test command
5649 *
5650 * @param[in] *bfa - bfa data struct
5651 * @param[in] force - 1: don't do ioc op checking
5652 * @param[in] queue - queue no. to test
5653 * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
5654 * @param[in] cbfn - callback function
5655 * @param[in] *cbarg - callback functioin arg
5656 *
5657 * @param[out]
5658 */
5659bfa_status_t
5660bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 force, u32 queue,
5661 struct bfa_diag_qtest_result_s *result, bfa_cb_diag_t cbfn,
5662 void *cbarg)
5663{
5664 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5665 bfa_status_t status;
5666 bfa_trc(fcdiag, force);
5667 bfa_trc(fcdiag, queue);
5668
5669 if (!force && !bfa_iocfc_is_operational(bfa))
5670 return BFA_STATUS_IOC_NON_OP;
5671
5672 /* check to see if there is another destructive diag cmd running */
5673 if (fcdiag->qtest.lock) {
5674 bfa_trc(fcdiag, fcdiag->qtest.lock);
5675 return BFA_STATUS_DEVBUSY;
5676 }
5677
5678 /* Initialization */
5679 fcdiag->qtest.lock = 1;
5680 fcdiag->qtest.cbfn = cbfn;
5681 fcdiag->qtest.cbarg = cbarg;
5682 fcdiag->qtest.result = result;
5683 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
5684
5685 /* Init test results */
5686 fcdiag->qtest.result->status = BFA_STATUS_OK;
5687 fcdiag->qtest.result->count = 0;
5688
5689 /* send */
5690 if (queue < BFI_IOC_MAX_CQS) {
5691 fcdiag->qtest.result->queue = (u8)queue;
5692 fcdiag->qtest.queue = (u8)queue;
5693 fcdiag->qtest.all = 0;
5694 } else {
5695 fcdiag->qtest.result->queue = 0;
5696 fcdiag->qtest.queue = 0;
5697 fcdiag->qtest.all = 1;
5698 }
5699 status = bfa_fcdiag_queuetest_send(fcdiag);
5700
5701 /* Start a timer */
5702 if (status == BFA_STATUS_OK) {
5703 bfa_timer_start(bfa, &fcdiag->qtest.timer,
5704 bfa_fcdiag_queuetest_timeout, fcdiag,
5705 BFA_DIAG_QTEST_TOV);
5706 fcdiag->qtest.timer_active = 1;
5707 }
5708 return status;
5709}
5710
5711/*
5712 * DIAG PLB is running
5713 *
5714 * @param[in] *bfa - bfa data struct
5715 *
5716 * @param[out]
5717 */
5718bfa_status_t
5719bfa_fcdiag_lb_is_running(struct bfa_s *bfa)
5720{
5721 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5722 return fcdiag->lb.lock ? BFA_STATUS_DIAG_BUSY : BFA_STATUS_OK;
5723}