blob: fcad11629f103fa3c0442f70838853257cb77af0 [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
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700443 INIT_LIST_HEAD(&mod->fcxp_req_free_q);
444 INIT_LIST_HEAD(&mod->fcxp_rsp_free_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700445 INIT_LIST_HEAD(&mod->fcxp_active_q);
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700446 INIT_LIST_HEAD(&mod->fcxp_req_unused_q);
447 INIT_LIST_HEAD(&mod->fcxp_rsp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700448
449 mod->fcxp_list = fcxp;
450
451 for (i = 0; i < mod->num_fcxps; i++) {
452 fcxp->fcxp_mod = mod;
453 fcxp->fcxp_tag = i;
454
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700455 if (i < (mod->num_fcxps / 2)) {
456 list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q);
457 fcxp->req_rsp = BFA_TRUE;
458 } else {
459 list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q);
460 fcxp->req_rsp = BFA_FALSE;
461 }
462
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700463 bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp);
464 fcxp->reqq_waiting = BFA_FALSE;
465
466 fcxp = fcxp + 1;
467 }
468
Krishna Gudipati45070252011-06-24 20:24:29 -0700469 bfa_mem_kva_curp(mod) = (void *)fcxp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700470}
471
472static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700473bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
474 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700475{
Krishna Gudipati45070252011-06-24 20:24:29 -0700476 struct bfa_fcxp_mod_s *fcxp_mod = BFA_FCXP_MOD(bfa);
477 struct bfa_mem_kva_s *fcxp_kva = BFA_MEM_FCXP_KVA(bfa);
478 struct bfa_mem_dma_s *seg_ptr;
479 u16 nsegs, idx, per_seg_fcxp;
480 u16 num_fcxps = cfg->fwcfg.num_fcxp_reqs;
481 u32 per_fcxp_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700482
Krishna Gudipati45070252011-06-24 20:24:29 -0700483 if (num_fcxps == 0)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700484 return;
485
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700486 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -0700487 per_fcxp_sz = 2 * BFA_FCXP_MAX_IBUF_SZ;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700488 else
Krishna Gudipati45070252011-06-24 20:24:29 -0700489 per_fcxp_sz = BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700490
Krishna Gudipati45070252011-06-24 20:24:29 -0700491 /* dma memory */
492 nsegs = BFI_MEM_DMA_NSEGS(num_fcxps, per_fcxp_sz);
493 per_seg_fcxp = BFI_MEM_NREQS_SEG(per_fcxp_sz);
494
495 bfa_mem_dma_seg_iter(fcxp_mod, seg_ptr, nsegs, idx) {
496 if (num_fcxps >= per_seg_fcxp) {
497 num_fcxps -= per_seg_fcxp;
498 bfa_mem_dma_setup(minfo, seg_ptr,
499 per_seg_fcxp * per_fcxp_sz);
500 } else
501 bfa_mem_dma_setup(minfo, seg_ptr,
502 num_fcxps * per_fcxp_sz);
503 }
504
505 /* kva memory */
506 bfa_mem_kva_setup(minfo, fcxp_kva,
507 cfg->fwcfg.num_fcxp_reqs * sizeof(struct bfa_fcxp_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700508}
509
510static void
511bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -0700512 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700513{
514 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
515
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700516 mod->bfa = bfa;
517 mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
518
Jing Huang5fbe25c2010-10-18 17:17:23 -0700519 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700520 * Initialize FCXP request and response payload sizes.
521 */
522 mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
523 if (!cfg->drvcfg.min_cfg)
524 mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ;
525
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700526 INIT_LIST_HEAD(&mod->req_wait_q);
527 INIT_LIST_HEAD(&mod->rsp_wait_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700528
Krishna Gudipati45070252011-06-24 20:24:29 -0700529 claim_fcxps_mem(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700530}
531
532static void
533bfa_fcxp_detach(struct bfa_s *bfa)
534{
535}
536
537static void
538bfa_fcxp_start(struct bfa_s *bfa)
539{
540}
541
542static void
543bfa_fcxp_stop(struct bfa_s *bfa)
544{
545}
546
547static void
548bfa_fcxp_iocdisable(struct bfa_s *bfa)
549{
550 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
551 struct bfa_fcxp_s *fcxp;
552 struct list_head *qe, *qen;
553
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700554 /* Enqueue unused fcxp resources to free_q */
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700555 list_splice_tail_init(&mod->fcxp_req_unused_q, &mod->fcxp_req_free_q);
556 list_splice_tail_init(&mod->fcxp_rsp_unused_q, &mod->fcxp_rsp_free_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700557
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700558 list_for_each_safe(qe, qen, &mod->fcxp_active_q) {
559 fcxp = (struct bfa_fcxp_s *) qe;
560 if (fcxp->caller == NULL) {
561 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
562 BFA_STATUS_IOC_FAILURE, 0, 0, NULL);
563 bfa_fcxp_free(fcxp);
564 } else {
565 fcxp->rsp_status = BFA_STATUS_IOC_FAILURE;
566 bfa_cb_queue(bfa, &fcxp->hcb_qe,
567 __bfa_fcxp_send_cbfn, fcxp);
568 }
569 }
570}
571
572static struct bfa_fcxp_s *
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700573bfa_fcxp_get(struct bfa_fcxp_mod_s *fm, bfa_boolean_t req)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700574{
575 struct bfa_fcxp_s *fcxp;
576
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700577 if (req)
578 bfa_q_deq(&fm->fcxp_req_free_q, &fcxp);
579 else
580 bfa_q_deq(&fm->fcxp_rsp_free_q, &fcxp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700581
582 if (fcxp)
583 list_add_tail(&fcxp->qe, &fm->fcxp_active_q);
584
585 return fcxp;
586}
587
588static void
589bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
590 struct bfa_s *bfa,
591 u8 *use_ibuf,
592 u32 *nr_sgles,
593 bfa_fcxp_get_sgaddr_t *r_sga_cbfn,
594 bfa_fcxp_get_sglen_t *r_sglen_cbfn,
595 struct list_head *r_sgpg_q,
596 int n_sgles,
597 bfa_fcxp_get_sgaddr_t sga_cbfn,
598 bfa_fcxp_get_sglen_t sglen_cbfn)
599{
600
Jing Huangd4b671c2010-12-26 21:46:35 -0800601 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700602
603 bfa_trc(bfa, fcxp->fcxp_tag);
604
605 if (n_sgles == 0) {
606 *use_ibuf = 1;
607 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800608 WARN_ON(*sga_cbfn == NULL);
609 WARN_ON(*sglen_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700610
611 *use_ibuf = 0;
612 *r_sga_cbfn = sga_cbfn;
613 *r_sglen_cbfn = sglen_cbfn;
614
615 *nr_sgles = n_sgles;
616
617 /*
618 * alloc required sgpgs
619 */
620 if (n_sgles > BFI_SGE_INLINE)
Jing Huangd4b671c2010-12-26 21:46:35 -0800621 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700622 }
623
624}
625
626static void
627bfa_fcxp_init(struct bfa_fcxp_s *fcxp,
628 void *caller, struct bfa_s *bfa, int nreq_sgles,
629 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
630 bfa_fcxp_get_sglen_t req_sglen_cbfn,
631 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
632 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
633{
634
Jing Huangd4b671c2010-12-26 21:46:35 -0800635 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700636
637 bfa_trc(bfa, fcxp->fcxp_tag);
638
639 fcxp->caller = caller;
640
641 bfa_fcxp_init_reqrsp(fcxp, bfa,
642 &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn,
643 &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q,
644 nreq_sgles, req_sga_cbfn, req_sglen_cbfn);
645
646 bfa_fcxp_init_reqrsp(fcxp, bfa,
647 &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn,
648 &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q,
649 nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn);
650
651}
652
653static void
654bfa_fcxp_put(struct bfa_fcxp_s *fcxp)
655{
656 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
657 struct bfa_fcxp_wqe_s *wqe;
658
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700659 if (fcxp->req_rsp)
660 bfa_q_deq(&mod->req_wait_q, &wqe);
661 else
662 bfa_q_deq(&mod->rsp_wait_q, &wqe);
663
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700664 if (wqe) {
665 bfa_trc(mod->bfa, fcxp->fcxp_tag);
666
667 bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles,
668 wqe->nrsp_sgles, wqe->req_sga_cbfn,
669 wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn,
670 wqe->rsp_sglen_cbfn);
671
672 wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp);
673 return;
674 }
675
Jing Huangd4b671c2010-12-26 21:46:35 -0800676 WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700677 list_del(&fcxp->qe);
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700678
679 if (fcxp->req_rsp)
680 list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q);
681 else
682 list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700683}
684
685static void
686bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
687 bfa_status_t req_status, u32 rsp_len,
688 u32 resid_len, struct fchs_s *rsp_fchs)
689{
690 /* discarded fcxp completion */
691}
692
693static void
694__bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete)
695{
696 struct bfa_fcxp_s *fcxp = cbarg;
697
698 if (complete) {
699 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
700 fcxp->rsp_status, fcxp->rsp_len,
701 fcxp->residue_len, &fcxp->rsp_fchs);
702 } else {
703 bfa_fcxp_free(fcxp);
704 }
705}
706
707static void
708hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
709{
710 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
711 struct bfa_fcxp_s *fcxp;
Jing Huangba816ea2010-10-18 17:10:50 -0700712 u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700713
714 bfa_trc(bfa, fcxp_tag);
715
Jing Huangba816ea2010-10-18 17:10:50 -0700716 fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700717
Jing Huang5fbe25c2010-10-18 17:17:23 -0700718 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700719 * @todo f/w should not set residue to non-0 when everything
720 * is received.
721 */
722 if (fcxp_rsp->req_status == BFA_STATUS_OK)
723 fcxp_rsp->residue_len = 0;
724 else
Jing Huangba816ea2010-10-18 17:10:50 -0700725 fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700726
727 fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
728
Jing Huangd4b671c2010-12-26 21:46:35 -0800729 WARN_ON(fcxp->send_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700730
731 hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp);
732
733 if (fcxp->send_cbfn != NULL) {
734 bfa_trc(mod->bfa, (NULL == fcxp->caller));
735 if (fcxp->caller == NULL) {
736 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
737 fcxp_rsp->req_status, fcxp_rsp->rsp_len,
738 fcxp_rsp->residue_len, &fcxp_rsp->fchs);
739 /*
740 * fcxp automatically freed on return from the callback
741 */
742 bfa_fcxp_free(fcxp);
743 } else {
744 fcxp->rsp_status = fcxp_rsp->req_status;
745 fcxp->rsp_len = fcxp_rsp->rsp_len;
746 fcxp->residue_len = fcxp_rsp->residue_len;
747 fcxp->rsp_fchs = fcxp_rsp->fchs;
748
749 bfa_cb_queue(bfa, &fcxp->hcb_qe,
750 __bfa_fcxp_send_cbfn, fcxp);
751 }
752 } else {
753 bfa_trc(bfa, (NULL == fcxp->send_cbfn));
754 }
755}
756
757static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700758hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp,
759 struct fchs_s *fchs)
760{
761 /*
762 * TODO: TX ox_id
763 */
764 if (reqlen > 0) {
765 if (fcxp->use_ireqbuf) {
766 u32 pld_w0 =
767 *((u32 *) BFA_FCXP_REQ_PLD(fcxp));
768
769 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
770 BFA_PL_EID_TX,
771 reqlen + sizeof(struct fchs_s), fchs,
772 pld_w0);
773 } else {
774 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
775 BFA_PL_EID_TX,
776 reqlen + sizeof(struct fchs_s),
777 fchs);
778 }
779 } else {
780 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX,
781 reqlen + sizeof(struct fchs_s), fchs);
782 }
783}
784
785static void
786hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
787 struct bfi_fcxp_send_rsp_s *fcxp_rsp)
788{
789 if (fcxp_rsp->rsp_len > 0) {
790 if (fcxp->use_irspbuf) {
791 u32 pld_w0 =
792 *((u32 *) BFA_FCXP_RSP_PLD(fcxp));
793
794 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
795 BFA_PL_EID_RX,
796 (u16) fcxp_rsp->rsp_len,
797 &fcxp_rsp->fchs, pld_w0);
798 } else {
799 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
800 BFA_PL_EID_RX,
801 (u16) fcxp_rsp->rsp_len,
802 &fcxp_rsp->fchs);
803 }
804 } else {
805 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX,
806 (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs);
807 }
808}
809
Jing Huang5fbe25c2010-10-18 17:17:23 -0700810/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700811 * Handler to resume sending fcxp when space in available in cpe queue.
812 */
813static void
814bfa_fcxp_qresume(void *cbarg)
815{
816 struct bfa_fcxp_s *fcxp = cbarg;
817 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
818 struct bfi_fcxp_send_req_s *send_req;
819
820 fcxp->reqq_waiting = BFA_FALSE;
821 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
822 bfa_fcxp_queue(fcxp, send_req);
823}
824
Jing Huang5fbe25c2010-10-18 17:17:23 -0700825/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700826 * Queue fcxp send request to foimrware.
827 */
828static void
829bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
830{
831 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
832 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
833 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
834 struct bfa_rport_s *rport = reqi->bfa_rport;
835
836 bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700837 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700838
Jing Huangba816ea2010-10-18 17:10:50 -0700839 send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700840 if (rport) {
841 send_req->rport_fw_hndl = rport->fw_handle;
Jing Huangba816ea2010-10-18 17:10:50 -0700842 send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700843 if (send_req->max_frmsz == 0)
Jing Huangba816ea2010-10-18 17:10:50 -0700844 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700845 } else {
846 send_req->rport_fw_hndl = 0;
Jing Huangba816ea2010-10-18 17:10:50 -0700847 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700848 }
849
Jing Huangba816ea2010-10-18 17:10:50 -0700850 send_req->vf_id = cpu_to_be16(reqi->vf_id);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700851 send_req->lp_fwtag = bfa_lps_get_fwtag(bfa, reqi->lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700852 send_req->class = reqi->class;
853 send_req->rsp_timeout = rspi->rsp_timeout;
854 send_req->cts = reqi->cts;
855 send_req->fchs = reqi->fchs;
856
Jing Huangba816ea2010-10-18 17:10:50 -0700857 send_req->req_len = cpu_to_be32(reqi->req_tot_len);
858 send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700859
860 /*
861 * setup req sgles
862 */
863 if (fcxp->use_ireqbuf == 1) {
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700864 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700865 BFA_FCXP_REQ_PLD_PA(fcxp));
866 } else {
867 if (fcxp->nreq_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800868 WARN_ON(fcxp->nreq_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700869 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
870 fcxp->req_sga_cbfn(fcxp->caller, 0));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700871 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800872 WARN_ON(reqi->req_tot_len != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700873 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700874 }
875 }
876
877 /*
878 * setup rsp sgles
879 */
880 if (fcxp->use_irspbuf == 1) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800881 WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700882
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700883 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700884 BFA_FCXP_RSP_PLD_PA(fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700885 } else {
886 if (fcxp->nrsp_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800887 WARN_ON(fcxp->nrsp_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700888 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
889 fcxp->rsp_sga_cbfn(fcxp->caller, 0));
890
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700891 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800892 WARN_ON(rspi->rsp_maxlen != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700893 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700894 }
895 }
896
897 hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs);
898
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700899 bfa_reqq_produce(bfa, BFA_REQQ_FCXP, send_req->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700900
901 bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP));
902 bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
903}
904
Jing Huang5fbe25c2010-10-18 17:17:23 -0700905/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700906 * Allocate an FCXP instance to send a response or to send a request
907 * that has a response. Request/response buffers are allocated by caller.
908 *
909 * @param[in] bfa BFA bfa instance
910 * @param[in] nreq_sgles Number of SG elements required for request
911 * buffer. 0, if fcxp internal buffers are used.
912 * Use bfa_fcxp_get_reqbuf() to get the
913 * internal req buffer.
914 * @param[in] req_sgles SG elements describing request buffer. Will be
915 * copied in by BFA and hence can be freed on
916 * return from this function.
917 * @param[in] get_req_sga function ptr to be called to get a request SG
918 * Address (given the sge index).
919 * @param[in] get_req_sglen function ptr to be called to get a request SG
920 * len (given the sge index).
921 * @param[in] get_rsp_sga function ptr to be called to get a response SG
922 * Address (given the sge index).
923 * @param[in] get_rsp_sglen function ptr to be called to get a response SG
924 * len (given the sge index).
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700925 * @param[in] req Allocated FCXP is used to send req or rsp?
926 * request - BFA_TRUE, response - BFA_FALSE
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700927 *
928 * @return FCXP instance. NULL on failure.
929 */
930struct bfa_fcxp_s *
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700931bfa_fcxp_req_rsp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
932 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
933 bfa_fcxp_get_sglen_t req_sglen_cbfn,
934 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
935 bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700936{
937 struct bfa_fcxp_s *fcxp = NULL;
938
Jing Huangd4b671c2010-12-26 21:46:35 -0800939 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700940
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700941 fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa), req);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700942 if (fcxp == NULL)
943 return NULL;
944
945 bfa_trc(bfa, fcxp->fcxp_tag);
946
947 bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn,
948 req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn);
949
950 return fcxp;
951}
952
Jing Huang5fbe25c2010-10-18 17:17:23 -0700953/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700954 * Get the internal request buffer pointer
955 *
956 * @param[in] fcxp BFA fcxp pointer
957 *
958 * @return pointer to the internal request buffer
959 */
960void *
961bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp)
962{
963 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
964 void *reqbuf;
965
Jing Huangd4b671c2010-12-26 21:46:35 -0800966 WARN_ON(fcxp->use_ireqbuf != 1);
Krishna Gudipati45070252011-06-24 20:24:29 -0700967 reqbuf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
968 mod->req_pld_sz + mod->rsp_pld_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700969 return reqbuf;
970}
971
972u32
973bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
974{
975 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
976
977 return mod->req_pld_sz;
978}
979
Jing Huang5fbe25c2010-10-18 17:17:23 -0700980/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700981 * Get the internal response buffer pointer
982 *
983 * @param[in] fcxp BFA fcxp pointer
984 *
985 * @return pointer to the internal request buffer
986 */
987void *
988bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
989{
990 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
Krishna Gudipati45070252011-06-24 20:24:29 -0700991 void *fcxp_buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700992
Jing Huangd4b671c2010-12-26 21:46:35 -0800993 WARN_ON(fcxp->use_irspbuf != 1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700994
Krishna Gudipati45070252011-06-24 20:24:29 -0700995 fcxp_buf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
996 mod->req_pld_sz + mod->rsp_pld_sz);
997
998 /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
999 return ((u8 *) fcxp_buf) + mod->req_pld_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001000}
1001
Jing Huang5fbe25c2010-10-18 17:17:23 -07001002/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001003 * Free the BFA FCXP
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001004 *
1005 * @param[in] fcxp BFA fcxp pointer
1006 *
1007 * @return void
1008 */
1009void
1010bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
1011{
1012 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
1013
Jing Huangd4b671c2010-12-26 21:46:35 -08001014 WARN_ON(fcxp == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001015 bfa_trc(mod->bfa, fcxp->fcxp_tag);
1016 bfa_fcxp_put(fcxp);
1017}
1018
Jing Huang5fbe25c2010-10-18 17:17:23 -07001019/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001020 * Send a FCXP request
1021 *
1022 * @param[in] fcxp BFA fcxp pointer
1023 * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
1024 * @param[in] vf_id virtual Fabric ID
1025 * @param[in] lp_tag lport tag
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001026 * @param[in] cts use Continuous sequence
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001027 * @param[in] cos fc Class of Service
1028 * @param[in] reqlen request length, does not include FCHS length
1029 * @param[in] fchs fc Header Pointer. The header content will be copied
1030 * in by BFA.
1031 *
1032 * @param[in] cbfn call back function to be called on receiving
1033 * the response
1034 * @param[in] cbarg arg for cbfn
1035 * @param[in] rsp_timeout
1036 * response timeout
1037 *
1038 * @return bfa_status_t
1039 */
1040void
1041bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
1042 u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos,
1043 u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn,
1044 void *cbarg, u32 rsp_maxlen, u8 rsp_timeout)
1045{
1046 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
1047 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
1048 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
1049 struct bfi_fcxp_send_req_s *send_req;
1050
1051 bfa_trc(bfa, fcxp->fcxp_tag);
1052
Jing Huang5fbe25c2010-10-18 17:17:23 -07001053 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001054 * setup request/response info
1055 */
1056 reqi->bfa_rport = rport;
1057 reqi->vf_id = vf_id;
1058 reqi->lp_tag = lp_tag;
1059 reqi->class = cos;
1060 rspi->rsp_timeout = rsp_timeout;
1061 reqi->cts = cts;
1062 reqi->fchs = *fchs;
1063 reqi->req_tot_len = reqlen;
1064 rspi->rsp_maxlen = rsp_maxlen;
1065 fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
1066 fcxp->send_cbarg = cbarg;
1067
Jing Huang5fbe25c2010-10-18 17:17:23 -07001068 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001069 * If no room in CPE queue, wait for space in request queue
1070 */
1071 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
1072 if (!send_req) {
1073 bfa_trc(bfa, fcxp->fcxp_tag);
1074 fcxp->reqq_waiting = BFA_TRUE;
1075 bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe);
1076 return;
1077 }
1078
1079 bfa_fcxp_queue(fcxp, send_req);
1080}
1081
Jing Huang5fbe25c2010-10-18 17:17:23 -07001082/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001083 * Abort a BFA FCXP
1084 *
1085 * @param[in] fcxp BFA fcxp pointer
1086 *
1087 * @return void
1088 */
1089bfa_status_t
1090bfa_fcxp_abort(struct bfa_fcxp_s *fcxp)
1091{
1092 bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag);
Jing Huangd4b671c2010-12-26 21:46:35 -08001093 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001094 return BFA_STATUS_OK;
1095}
1096
1097void
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001098bfa_fcxp_req_rsp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001099 bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg,
1100 void *caller, int nreq_sgles,
1101 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
1102 bfa_fcxp_get_sglen_t req_sglen_cbfn,
1103 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001104 bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001105{
1106 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1107
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001108 if (req)
1109 WARN_ON(!list_empty(&mod->fcxp_req_free_q));
1110 else
1111 WARN_ON(!list_empty(&mod->fcxp_rsp_free_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001112
1113 wqe->alloc_cbfn = alloc_cbfn;
1114 wqe->alloc_cbarg = alloc_cbarg;
1115 wqe->caller = caller;
1116 wqe->bfa = bfa;
1117 wqe->nreq_sgles = nreq_sgles;
1118 wqe->nrsp_sgles = nrsp_sgles;
1119 wqe->req_sga_cbfn = req_sga_cbfn;
1120 wqe->req_sglen_cbfn = req_sglen_cbfn;
1121 wqe->rsp_sga_cbfn = rsp_sga_cbfn;
1122 wqe->rsp_sglen_cbfn = rsp_sglen_cbfn;
1123
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001124 if (req)
1125 list_add_tail(&wqe->qe, &mod->req_wait_q);
1126 else
1127 list_add_tail(&wqe->qe, &mod->rsp_wait_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001128}
1129
1130void
1131bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
1132{
1133 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1134
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001135 WARN_ON(!bfa_q_is_on_q(&mod->req_wait_q, wqe) ||
1136 !bfa_q_is_on_q(&mod->rsp_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001137 list_del(&wqe->qe);
1138}
1139
1140void
1141bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
1142{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001143 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001144 * If waiting for room in request queue, cancel reqq wait
1145 * and free fcxp.
1146 */
1147 if (fcxp->reqq_waiting) {
1148 fcxp->reqq_waiting = BFA_FALSE;
1149 bfa_reqq_wcancel(&fcxp->reqq_wqe);
1150 bfa_fcxp_free(fcxp);
1151 return;
1152 }
1153
1154 fcxp->send_cbfn = bfa_fcxp_null_comp;
1155}
1156
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001157void
1158bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
1159{
1160 switch (msg->mhdr.msg_id) {
1161 case BFI_FCXP_I2H_SEND_RSP:
1162 hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg);
1163 break;
1164
1165 default:
1166 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001167 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001168 }
1169}
1170
1171u32
1172bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
1173{
1174 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1175
1176 return mod->rsp_pld_sz;
1177}
1178
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001179void
1180bfa_fcxp_res_recfg(struct bfa_s *bfa, u16 num_fcxp_fw)
1181{
1182 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1183 struct list_head *qe;
1184 int i;
1185
1186 for (i = 0; i < (mod->num_fcxps - num_fcxp_fw); i++) {
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001187 if (i < ((mod->num_fcxps - num_fcxp_fw) / 2)) {
1188 bfa_q_deq_tail(&mod->fcxp_req_free_q, &qe);
1189 list_add_tail(qe, &mod->fcxp_req_unused_q);
1190 } else {
1191 bfa_q_deq_tail(&mod->fcxp_rsp_free_q, &qe);
1192 list_add_tail(qe, &mod->fcxp_rsp_unused_q);
1193 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001194 }
1195}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001196
Jing Huang5fbe25c2010-10-18 17:17:23 -07001197/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001198 * BFA LPS state machine functions
1199 */
1200
Jing Huang5fbe25c2010-10-18 17:17:23 -07001201/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001202 * Init state -- no login
1203 */
1204static void
1205bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
1206{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001207 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001208 bfa_trc(lps->bfa, event);
1209
1210 switch (event) {
1211 case BFA_LPS_SM_LOGIN:
1212 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1213 bfa_sm_set_state(lps, bfa_lps_sm_loginwait);
1214 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1215 } else {
1216 bfa_sm_set_state(lps, bfa_lps_sm_login);
1217 bfa_lps_send_login(lps);
1218 }
1219
1220 if (lps->fdisc)
1221 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1222 BFA_PL_EID_LOGIN, 0, "FDISC Request");
1223 else
1224 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1225 BFA_PL_EID_LOGIN, 0, "FLOGI Request");
1226 break;
1227
1228 case BFA_LPS_SM_LOGOUT:
1229 bfa_lps_logout_comp(lps);
1230 break;
1231
1232 case BFA_LPS_SM_DELETE:
1233 bfa_lps_free(lps);
1234 break;
1235
1236 case BFA_LPS_SM_RX_CVL:
1237 case BFA_LPS_SM_OFFLINE:
1238 break;
1239
1240 case BFA_LPS_SM_FWRSP:
1241 /*
1242 * Could happen when fabric detects loopback and discards
1243 * the lps request. Fw will eventually sent out the timeout
1244 * Just ignore
1245 */
1246 break;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07001247 case BFA_LPS_SM_SET_N2N_PID:
1248 /*
1249 * When topology is set to loop, bfa_lps_set_n2n_pid() sends
1250 * this event. Ignore this event.
1251 */
1252 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001253
1254 default:
1255 bfa_sm_fault(lps->bfa, event);
1256 }
1257}
1258
Jing Huang5fbe25c2010-10-18 17:17:23 -07001259/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001260 * login is in progress -- awaiting response from firmware
1261 */
1262static void
1263bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
1264{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001265 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001266 bfa_trc(lps->bfa, event);
1267
1268 switch (event) {
1269 case BFA_LPS_SM_FWRSP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07001270 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001271 if (lps->status == BFA_STATUS_OK) {
1272 bfa_sm_set_state(lps, bfa_lps_sm_online);
1273 if (lps->fdisc)
1274 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1275 BFA_PL_EID_LOGIN, 0, "FDISC Accept");
1276 else
1277 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1278 BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
Krishna Gudipatib7044952010-12-13 16:17:42 -08001279 /* If N2N, send the assigned PID to FW */
1280 bfa_trc(lps->bfa, lps->fport);
1281 bfa_trc(lps->bfa, lps->lp_pid);
1282
1283 if (!lps->fport && lps->lp_pid)
1284 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001285 } else {
1286 bfa_sm_set_state(lps, bfa_lps_sm_init);
1287 if (lps->fdisc)
1288 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1289 BFA_PL_EID_LOGIN, 0,
1290 "FDISC Fail (RJT or timeout)");
1291 else
1292 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1293 BFA_PL_EID_LOGIN, 0,
1294 "FLOGI Fail (RJT or timeout)");
1295 }
1296 bfa_lps_login_comp(lps);
1297 break;
1298
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001299 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001300 bfa_sm_set_state(lps, bfa_lps_sm_init);
1301 break;
1302
Krishna Gudipatib7044952010-12-13 16:17:42 -08001303 case BFA_LPS_SM_SET_N2N_PID:
1304 bfa_trc(lps->bfa, lps->fport);
1305 bfa_trc(lps->bfa, lps->lp_pid);
1306 break;
1307
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001308 default:
1309 bfa_sm_fault(lps->bfa, event);
1310 }
1311}
1312
Jing Huang5fbe25c2010-10-18 17:17:23 -07001313/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001314 * login pending - awaiting space in request queue
1315 */
1316static void
1317bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1318{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001319 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001320 bfa_trc(lps->bfa, event);
1321
1322 switch (event) {
1323 case BFA_LPS_SM_RESUME:
1324 bfa_sm_set_state(lps, bfa_lps_sm_login);
Krishna Gudipatiff179e02012-03-13 17:40:31 -07001325 bfa_lps_send_login(lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001326 break;
1327
1328 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001329 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001330 bfa_sm_set_state(lps, bfa_lps_sm_init);
1331 bfa_reqq_wcancel(&lps->wqe);
1332 break;
1333
1334 case BFA_LPS_SM_RX_CVL:
1335 /*
1336 * Login was not even sent out; so when getting out
1337 * of this state, it will appear like a login retry
1338 * after Clear virtual link
1339 */
1340 break;
1341
1342 default:
1343 bfa_sm_fault(lps->bfa, event);
1344 }
1345}
1346
Jing Huang5fbe25c2010-10-18 17:17:23 -07001347/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001348 * login complete
1349 */
1350static void
1351bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
1352{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001353 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001354 bfa_trc(lps->bfa, event);
1355
1356 switch (event) {
1357 case BFA_LPS_SM_LOGOUT:
1358 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1359 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1360 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1361 } else {
1362 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1363 bfa_lps_send_logout(lps);
1364 }
1365 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1366 BFA_PL_EID_LOGO, 0, "Logout");
1367 break;
1368
1369 case BFA_LPS_SM_RX_CVL:
1370 bfa_sm_set_state(lps, bfa_lps_sm_init);
1371
1372 /* Let the vport module know about this event */
1373 bfa_lps_cvl_event(lps);
1374 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1375 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1376 break;
1377
Krishna Gudipatib7044952010-12-13 16:17:42 -08001378 case BFA_LPS_SM_SET_N2N_PID:
1379 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1380 bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
1381 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1382 } else
1383 bfa_lps_send_set_n2n_pid(lps);
1384 break;
1385
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001386 case BFA_LPS_SM_OFFLINE:
1387 case BFA_LPS_SM_DELETE:
1388 bfa_sm_set_state(lps, bfa_lps_sm_init);
1389 break;
1390
1391 default:
1392 bfa_sm_fault(lps->bfa, event);
1393 }
1394}
1395
Jing Huang8f4bfad2010-12-26 21:50:10 -08001396/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001397 * login complete
1398 */
1399static void
1400bfa_lps_sm_online_n2n_pid_wait(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 Gudipatib7044952010-12-13 16:17:42 -08001403 bfa_trc(lps->bfa, event);
1404
1405 switch (event) {
1406 case BFA_LPS_SM_RESUME:
1407 bfa_sm_set_state(lps, bfa_lps_sm_online);
1408 bfa_lps_send_set_n2n_pid(lps);
1409 break;
1410
1411 case BFA_LPS_SM_LOGOUT:
1412 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1413 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1414 BFA_PL_EID_LOGO, 0, "Logout");
1415 break;
1416
1417 case BFA_LPS_SM_RX_CVL:
1418 bfa_sm_set_state(lps, bfa_lps_sm_init);
1419 bfa_reqq_wcancel(&lps->wqe);
1420
1421 /* Let the vport module know about this event */
1422 bfa_lps_cvl_event(lps);
1423 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1424 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1425 break;
1426
1427 case BFA_LPS_SM_OFFLINE:
1428 case BFA_LPS_SM_DELETE:
1429 bfa_sm_set_state(lps, bfa_lps_sm_init);
1430 bfa_reqq_wcancel(&lps->wqe);
1431 break;
1432
1433 default:
1434 bfa_sm_fault(lps->bfa, event);
1435 }
1436}
1437
Jing Huang5fbe25c2010-10-18 17:17:23 -07001438/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001439 * logout in progress - awaiting firmware response
1440 */
1441static void
1442bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
1443{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001444 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001445 bfa_trc(lps->bfa, event);
1446
1447 switch (event) {
1448 case BFA_LPS_SM_FWRSP:
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001449 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001450 bfa_sm_set_state(lps, bfa_lps_sm_init);
1451 bfa_lps_logout_comp(lps);
1452 break;
1453
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001454 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001455 bfa_sm_set_state(lps, bfa_lps_sm_init);
1456 break;
1457
1458 default:
1459 bfa_sm_fault(lps->bfa, event);
1460 }
1461}
1462
Jing Huang5fbe25c2010-10-18 17:17:23 -07001463/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001464 * logout pending -- awaiting space in request queue
1465 */
1466static void
1467bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1468{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001469 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001470 bfa_trc(lps->bfa, event);
1471
1472 switch (event) {
1473 case BFA_LPS_SM_RESUME:
1474 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1475 bfa_lps_send_logout(lps);
1476 break;
1477
1478 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001479 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001480 bfa_sm_set_state(lps, bfa_lps_sm_init);
1481 bfa_reqq_wcancel(&lps->wqe);
1482 break;
1483
1484 default:
1485 bfa_sm_fault(lps->bfa, event);
1486 }
1487}
1488
1489
1490
Jing Huang5fbe25c2010-10-18 17:17:23 -07001491/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001492 * lps_pvt BFA LPS private functions
1493 */
1494
Jing Huang5fbe25c2010-10-18 17:17:23 -07001495/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001496 * return memory requirement
1497 */
1498static void
Krishna Gudipati45070252011-06-24 20:24:29 -07001499bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
1500 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001501{
Krishna Gudipati45070252011-06-24 20:24:29 -07001502 struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa);
1503
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001504 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -07001505 bfa_mem_kva_setup(minfo, lps_kva,
1506 sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001507 else
Krishna Gudipati45070252011-06-24 20:24:29 -07001508 bfa_mem_kva_setup(minfo, lps_kva,
1509 sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001510}
1511
Jing Huang5fbe25c2010-10-18 17:17:23 -07001512/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001513 * bfa module attach at initialization time
1514 */
1515static void
1516bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07001517 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001518{
1519 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1520 struct bfa_lps_s *lps;
1521 int i;
1522
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001523 mod->num_lps = BFA_LPS_MAX_LPORTS;
1524 if (cfg->drvcfg.min_cfg)
1525 mod->num_lps = BFA_LPS_MIN_LPORTS;
1526 else
1527 mod->num_lps = BFA_LPS_MAX_LPORTS;
Krishna Gudipati45070252011-06-24 20:24:29 -07001528 mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001529
Krishna Gudipati45070252011-06-24 20:24:29 -07001530 bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001531
1532 INIT_LIST_HEAD(&mod->lps_free_q);
1533 INIT_LIST_HEAD(&mod->lps_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001534 INIT_LIST_HEAD(&mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001535
1536 for (i = 0; i < mod->num_lps; i++, lps++) {
1537 lps->bfa = bfa;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001538 lps->bfa_tag = (u8) i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001539 lps->reqq = BFA_REQQ_LPS;
1540 bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
1541 list_add_tail(&lps->qe, &mod->lps_free_q);
1542 }
1543}
1544
1545static void
1546bfa_lps_detach(struct bfa_s *bfa)
1547{
1548}
1549
1550static void
1551bfa_lps_start(struct bfa_s *bfa)
1552{
1553}
1554
1555static void
1556bfa_lps_stop(struct bfa_s *bfa)
1557{
1558}
1559
Jing Huang5fbe25c2010-10-18 17:17:23 -07001560/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001561 * IOC in disabled state -- consider all lps offline
1562 */
1563static void
1564bfa_lps_iocdisable(struct bfa_s *bfa)
1565{
1566 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1567 struct bfa_lps_s *lps;
1568 struct list_head *qe, *qen;
1569
1570 list_for_each_safe(qe, qen, &mod->lps_active_q) {
1571 lps = (struct bfa_lps_s *) qe;
1572 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1573 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001574 list_for_each_safe(qe, qen, &mod->lps_login_q) {
1575 lps = (struct bfa_lps_s *) qe;
1576 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1577 }
1578 list_splice_tail_init(&mod->lps_login_q, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001579}
1580
Jing Huang5fbe25c2010-10-18 17:17:23 -07001581/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001582 * Firmware login response
1583 */
1584static void
1585bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
1586{
1587 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1588 struct bfa_lps_s *lps;
1589
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001590 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1591 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001592
1593 lps->status = rsp->status;
1594 switch (rsp->status) {
1595 case BFA_STATUS_OK:
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001596 lps->fw_tag = rsp->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001597 lps->fport = rsp->f_port;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001598 if (lps->fport)
1599 lps->lp_pid = rsp->lp_pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001600 lps->npiv_en = rsp->npiv_en;
Jing Huangba816ea2010-10-18 17:10:50 -07001601 lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001602 lps->pr_pwwn = rsp->port_name;
1603 lps->pr_nwwn = rsp->node_name;
1604 lps->auth_req = rsp->auth_req;
1605 lps->lp_mac = rsp->lp_mac;
1606 lps->brcd_switch = rsp->brcd_switch;
1607 lps->fcf_mac = rsp->fcf_mac;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001608 lps->pr_bbscn = rsp->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001609
1610 break;
1611
1612 case BFA_STATUS_FABRIC_RJT:
1613 lps->lsrjt_rsn = rsp->lsrjt_rsn;
1614 lps->lsrjt_expl = rsp->lsrjt_expl;
1615
1616 break;
1617
1618 case BFA_STATUS_EPROTOCOL:
1619 lps->ext_status = rsp->ext_status;
1620
1621 break;
1622
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001623 case BFA_STATUS_VPORT_MAX:
Krishna Gudipatiff179e02012-03-13 17:40:31 -07001624 if (rsp->ext_status)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001625 bfa_lps_no_res(lps, rsp->ext_status);
1626 break;
1627
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001628 default:
1629 /* Nothing to do with other status */
1630 break;
1631 }
1632
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001633 list_del(&lps->qe);
1634 list_add_tail(&lps->qe, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001635 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1636}
1637
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001638static void
1639bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count)
1640{
1641 struct bfa_s *bfa = first_lps->bfa;
1642 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1643 struct list_head *qe, *qe_next;
1644 struct bfa_lps_s *lps;
1645
1646 bfa_trc(bfa, count);
1647
1648 qe = bfa_q_next(first_lps);
1649
1650 while (count && qe) {
1651 qe_next = bfa_q_next(qe);
1652 lps = (struct bfa_lps_s *)qe;
1653 bfa_trc(bfa, lps->bfa_tag);
1654 lps->status = first_lps->status;
1655 list_del(&lps->qe);
1656 list_add_tail(&lps->qe, &mod->lps_active_q);
1657 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1658 qe = qe_next;
1659 count--;
1660 }
1661}
1662
Jing Huang5fbe25c2010-10-18 17:17:23 -07001663/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001664 * Firmware logout response
1665 */
1666static void
1667bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
1668{
1669 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1670 struct bfa_lps_s *lps;
1671
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001672 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1673 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001674
1675 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1676}
1677
Jing Huang5fbe25c2010-10-18 17:17:23 -07001678/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001679 * Firmware received a Clear virtual link request (for FCoE)
1680 */
1681static void
1682bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
1683{
1684 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1685 struct bfa_lps_s *lps;
1686
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001687 lps = BFA_LPS_FROM_TAG(mod, cvl->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001688
1689 bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
1690}
1691
Jing Huang5fbe25c2010-10-18 17:17:23 -07001692/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001693 * Space is available in request queue, resume queueing request to firmware.
1694 */
1695static void
1696bfa_lps_reqq_resume(void *lps_arg)
1697{
1698 struct bfa_lps_s *lps = lps_arg;
1699
1700 bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
1701}
1702
Jing Huang5fbe25c2010-10-18 17:17:23 -07001703/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001704 * lps is freed -- triggered by vport delete
1705 */
1706static void
1707bfa_lps_free(struct bfa_lps_s *lps)
1708{
1709 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
1710
1711 lps->lp_pid = 0;
1712 list_del(&lps->qe);
1713 list_add_tail(&lps->qe, &mod->lps_free_q);
1714}
1715
Jing Huang5fbe25c2010-10-18 17:17:23 -07001716/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001717 * send login request to firmware
1718 */
1719static void
1720bfa_lps_send_login(struct bfa_lps_s *lps)
1721{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001722 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001723 struct bfi_lps_login_req_s *m;
1724
1725 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001726 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001727
1728 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001729 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001730
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001731 m->bfa_tag = lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001732 m->alpa = lps->alpa;
Jing Huangba816ea2010-10-18 17:10:50 -07001733 m->pdu_size = cpu_to_be16(lps->pdusz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001734 m->pwwn = lps->pwwn;
1735 m->nwwn = lps->nwwn;
1736 m->fdisc = lps->fdisc;
1737 m->auth_en = lps->auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001738 m->bb_scn = lps->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001739
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001740 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
1741 list_del(&lps->qe);
1742 list_add_tail(&lps->qe, &mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001743}
1744
Jing Huang5fbe25c2010-10-18 17:17:23 -07001745/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001746 * send logout request to firmware
1747 */
1748static void
1749bfa_lps_send_logout(struct bfa_lps_s *lps)
1750{
1751 struct bfi_lps_logout_req_s *m;
1752
1753 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001754 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001755
1756 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001757 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001758
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001759 m->fw_tag = lps->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001760 m->port_name = lps->pwwn;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001761 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001762}
1763
Jing Huang8f4bfad2010-12-26 21:50:10 -08001764/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001765 * send n2n pid set request to firmware
1766 */
1767static void
1768bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
1769{
1770 struct bfi_lps_n2n_pid_req_s *m;
1771
1772 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001773 WARN_ON(!m);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001774
1775 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001776 bfa_fn_lpu(lps->bfa));
Krishna Gudipatib7044952010-12-13 16:17:42 -08001777
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001778 m->fw_tag = lps->fw_tag;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001779 m->lp_pid = lps->lp_pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001780 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001781}
1782
Jing Huang5fbe25c2010-10-18 17:17:23 -07001783/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001784 * Indirect login completion handler for non-fcs
1785 */
1786static void
1787bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
1788{
1789 struct bfa_lps_s *lps = arg;
1790
1791 if (!complete)
1792 return;
1793
1794 if (lps->fdisc)
1795 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1796 else
1797 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1798}
1799
Jing Huang5fbe25c2010-10-18 17:17:23 -07001800/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001801 * Login completion handler -- direct call for fcs, queue for others
1802 */
1803static void
1804bfa_lps_login_comp(struct bfa_lps_s *lps)
1805{
1806 if (!lps->bfa->fcs) {
1807 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
1808 lps);
1809 return;
1810 }
1811
1812 if (lps->fdisc)
1813 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1814 else
1815 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1816}
1817
Jing Huang5fbe25c2010-10-18 17:17:23 -07001818/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001819 * Indirect logout completion handler for non-fcs
1820 */
1821static void
1822bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
1823{
1824 struct bfa_lps_s *lps = arg;
1825
1826 if (!complete)
1827 return;
1828
1829 if (lps->fdisc)
1830 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001831 else
1832 bfa_cb_lps_flogo_comp(lps->bfa->bfad, lps->uarg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001833}
1834
Jing Huang5fbe25c2010-10-18 17:17:23 -07001835/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001836 * Logout completion handler -- direct call for fcs, queue for others
1837 */
1838static void
1839bfa_lps_logout_comp(struct bfa_lps_s *lps)
1840{
1841 if (!lps->bfa->fcs) {
1842 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
1843 lps);
1844 return;
1845 }
1846 if (lps->fdisc)
1847 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1848}
1849
Jing Huang5fbe25c2010-10-18 17:17:23 -07001850/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001851 * Clear virtual link completion handler for non-fcs
1852 */
1853static void
1854bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
1855{
1856 struct bfa_lps_s *lps = arg;
1857
1858 if (!complete)
1859 return;
1860
1861 /* Clear virtual link to base port will result in link down */
1862 if (lps->fdisc)
1863 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1864}
1865
Jing Huang5fbe25c2010-10-18 17:17:23 -07001866/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001867 * Received Clear virtual link event --direct call for fcs,
1868 * queue for others
1869 */
1870static void
1871bfa_lps_cvl_event(struct bfa_lps_s *lps)
1872{
1873 if (!lps->bfa->fcs) {
1874 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
1875 lps);
1876 return;
1877 }
1878
1879 /* Clear virtual link to base port will result in link down */
1880 if (lps->fdisc)
1881 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1882}
1883
1884
1885
Jing Huang5fbe25c2010-10-18 17:17:23 -07001886/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001887 * lps_public BFA LPS public functions
1888 */
1889
1890u32
1891bfa_lps_get_max_vport(struct bfa_s *bfa)
1892{
1893 if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
1894 return BFA_LPS_MAX_VPORTS_SUPP_CT;
1895 else
1896 return BFA_LPS_MAX_VPORTS_SUPP_CB;
1897}
1898
Jing Huang5fbe25c2010-10-18 17:17:23 -07001899/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001900 * Allocate a lport srvice tag.
1901 */
1902struct bfa_lps_s *
1903bfa_lps_alloc(struct bfa_s *bfa)
1904{
1905 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1906 struct bfa_lps_s *lps = NULL;
1907
1908 bfa_q_deq(&mod->lps_free_q, &lps);
1909
1910 if (lps == NULL)
1911 return NULL;
1912
1913 list_add_tail(&lps->qe, &mod->lps_active_q);
1914
1915 bfa_sm_set_state(lps, bfa_lps_sm_init);
1916 return lps;
1917}
1918
Jing Huang5fbe25c2010-10-18 17:17:23 -07001919/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001920 * Free lport service tag. This can be called anytime after an alloc.
1921 * No need to wait for any pending login/logout completions.
1922 */
1923void
1924bfa_lps_delete(struct bfa_lps_s *lps)
1925{
1926 bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
1927}
1928
Jing Huang5fbe25c2010-10-18 17:17:23 -07001929/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001930 * Initiate a lport login.
1931 */
1932void
1933bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001934 wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en, uint8_t bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001935{
1936 lps->uarg = uarg;
1937 lps->alpa = alpa;
1938 lps->pdusz = pdusz;
1939 lps->pwwn = pwwn;
1940 lps->nwwn = nwwn;
1941 lps->fdisc = BFA_FALSE;
1942 lps->auth_en = auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001943 lps->bb_scn = bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001944 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1945}
1946
Jing Huang5fbe25c2010-10-18 17:17:23 -07001947/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001948 * Initiate a lport fdisc login.
1949 */
1950void
1951bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
1952 wwn_t nwwn)
1953{
1954 lps->uarg = uarg;
1955 lps->alpa = 0;
1956 lps->pdusz = pdusz;
1957 lps->pwwn = pwwn;
1958 lps->nwwn = nwwn;
1959 lps->fdisc = BFA_TRUE;
1960 lps->auth_en = BFA_FALSE;
1961 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1962}
1963
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001964
Jing Huang5fbe25c2010-10-18 17:17:23 -07001965/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001966 * Initiate a lport FDSIC logout.
1967 */
1968void
1969bfa_lps_fdisclogo(struct bfa_lps_s *lps)
1970{
1971 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
1972}
1973
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001974u8
1975bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag)
1976{
1977 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1978
1979 return BFA_LPS_FROM_TAG(mod, lp_tag)->fw_tag;
1980}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001981
Jing Huang5fbe25c2010-10-18 17:17:23 -07001982/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001983 * Return lport services tag given the pid
1984 */
1985u8
1986bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
1987{
1988 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1989 struct bfa_lps_s *lps;
1990 int i;
1991
1992 for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
1993 if (lps->lp_pid == pid)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001994 return lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001995 }
1996
1997 /* Return base port tag anyway */
1998 return 0;
1999}
2000
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002001
Jing Huang5fbe25c2010-10-18 17:17:23 -07002002/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002003 * return port id assigned to the base lport
2004 */
2005u32
2006bfa_lps_get_base_pid(struct bfa_s *bfa)
2007{
2008 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
2009
2010 return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
2011}
2012
Jing Huang8f4bfad2010-12-26 21:50:10 -08002013/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08002014 * Set PID in case of n2n (which is assigned during PLOGI)
2015 */
2016void
2017bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
2018{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002019 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08002020 bfa_trc(lps->bfa, n2n_pid);
2021
2022 lps->lp_pid = n2n_pid;
2023 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
2024}
2025
Jing Huang5fbe25c2010-10-18 17:17:23 -07002026/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002027 * LPS firmware message class handler.
2028 */
2029void
2030bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2031{
2032 union bfi_lps_i2h_msg_u msg;
2033
2034 bfa_trc(bfa, m->mhdr.msg_id);
2035 msg.msg = m;
2036
2037 switch (m->mhdr.msg_id) {
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002038 case BFI_LPS_I2H_LOGIN_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002039 bfa_lps_login_rsp(bfa, msg.login_rsp);
2040 break;
2041
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002042 case BFI_LPS_I2H_LOGOUT_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002043 bfa_lps_logout_rsp(bfa, msg.logout_rsp);
2044 break;
2045
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002046 case BFI_LPS_I2H_CVL_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002047 bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
2048 break;
2049
2050 default:
2051 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08002052 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002053 }
2054}
2055
Krishna Gudipati7826f302011-07-20 16:59:13 -07002056static void
2057bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
2058{
2059 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2060 struct bfa_aen_entry_s *aen_entry;
2061
2062 bfad_get_aen_entry(bfad, aen_entry);
2063 if (!aen_entry)
2064 return;
2065
2066 aen_entry->aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
2067 aen_entry->aen_data.port.pwwn = fcport->pwwn;
2068
2069 /* Send the AEN notification */
2070 bfad_im_post_vendor_event(aen_entry, bfad, ++fcport->bfa->bfa_aen_seq,
2071 BFA_AEN_CAT_PORT, event);
2072}
2073
Jing Huang5fbe25c2010-10-18 17:17:23 -07002074/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002075 * FC PORT state machine functions
2076 */
2077static void
2078bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
2079 enum bfa_fcport_sm_event event)
2080{
2081 bfa_trc(fcport->bfa, event);
2082
2083 switch (event) {
2084 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002085 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002086 * Start event after IOC is configured and BFA is started.
2087 */
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08002088 fcport->use_flash_cfg = BFA_TRUE;
2089
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002090 if (bfa_fcport_send_enable(fcport)) {
2091 bfa_trc(fcport->bfa, BFA_TRUE);
2092 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2093 } else {
2094 bfa_trc(fcport->bfa, BFA_FALSE);
2095 bfa_sm_set_state(fcport,
2096 bfa_fcport_sm_enabling_qwait);
2097 }
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 * Port is persistently configured to be in enabled state. Do
2103 * not change state. Port enabling is done when START event is
2104 * received.
2105 */
2106 break;
2107
2108 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002109 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002110 * If a port is persistently configured to be disabled, the
2111 * first event will a port disable request.
2112 */
2113 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2114 break;
2115
2116 case BFA_FCPORT_SM_HWFAIL:
2117 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2118 break;
2119
2120 default:
2121 bfa_sm_fault(fcport->bfa, event);
2122 }
2123}
2124
2125static void
2126bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
2127 enum bfa_fcport_sm_event event)
2128{
2129 char pwwn_buf[BFA_STRING_32];
2130 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2131 bfa_trc(fcport->bfa, event);
2132
2133 switch (event) {
2134 case BFA_FCPORT_SM_QRESUME:
2135 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2136 bfa_fcport_send_enable(fcport);
2137 break;
2138
2139 case BFA_FCPORT_SM_STOP:
2140 bfa_reqq_wcancel(&fcport->reqq_wait);
2141 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2142 break;
2143
2144 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002145 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002146 * Already enable is in progress.
2147 */
2148 break;
2149
2150 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002151 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002152 * Just send disable request to firmware when room becomes
2153 * available in request queue.
2154 */
2155 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2156 bfa_reqq_wcancel(&fcport->reqq_wait);
2157 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2158 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2159 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002160 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002161 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002162 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002163 break;
2164
2165 case BFA_FCPORT_SM_LINKUP:
2166 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002167 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002168 * Possible to get link events when doing back-to-back
2169 * enable/disables.
2170 */
2171 break;
2172
2173 case BFA_FCPORT_SM_HWFAIL:
2174 bfa_reqq_wcancel(&fcport->reqq_wait);
2175 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2176 break;
2177
2178 default:
2179 bfa_sm_fault(fcport->bfa, event);
2180 }
2181}
2182
2183static void
2184bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
2185 enum bfa_fcport_sm_event event)
2186{
2187 char pwwn_buf[BFA_STRING_32];
2188 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2189 bfa_trc(fcport->bfa, event);
2190
2191 switch (event) {
2192 case BFA_FCPORT_SM_FWRSP:
2193 case BFA_FCPORT_SM_LINKDOWN:
2194 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2195 break;
2196
2197 case BFA_FCPORT_SM_LINKUP:
2198 bfa_fcport_update_linkinfo(fcport);
2199 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
2200
Jing Huangd4b671c2010-12-26 21:46:35 -08002201 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002202 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2203 break;
2204
2205 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002206 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002207 * Already being enabled.
2208 */
2209 break;
2210
2211 case BFA_FCPORT_SM_DISABLE:
2212 if (bfa_fcport_send_disable(fcport))
2213 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2214 else
2215 bfa_sm_set_state(fcport,
2216 bfa_fcport_sm_disabling_qwait);
2217
2218 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2219 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2220 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002221 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002222 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002223 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002224 break;
2225
2226 case BFA_FCPORT_SM_STOP:
2227 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2228 break;
2229
2230 case BFA_FCPORT_SM_HWFAIL:
2231 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2232 break;
2233
2234 default:
2235 bfa_sm_fault(fcport->bfa, event);
2236 }
2237}
2238
2239static void
2240bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
2241 enum bfa_fcport_sm_event event)
2242{
2243 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2244 char pwwn_buf[BFA_STRING_32];
2245 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2246
2247 bfa_trc(fcport->bfa, event);
2248
2249 switch (event) {
2250 case BFA_FCPORT_SM_LINKUP:
2251 bfa_fcport_update_linkinfo(fcport);
2252 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
Jing Huangd4b671c2010-12-26 21:46:35 -08002253 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002254 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2255 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
2256 if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
2257
2258 bfa_trc(fcport->bfa,
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002259 pevent->link_state.attr.vc_fcf.fcf.fipenabled);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002260 bfa_trc(fcport->bfa,
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002261 pevent->link_state.attr.vc_fcf.fcf.fipfailed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002262
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002263 if (pevent->link_state.attr.vc_fcf.fcf.fipfailed)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002264 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2265 BFA_PL_EID_FIP_FCF_DISC, 0,
2266 "FIP FCF Discovery Failed");
2267 else
2268 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2269 BFA_PL_EID_FIP_FCF_DISC, 0,
2270 "FIP FCF Discovered");
2271 }
2272
2273 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2274 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002275 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002276 "Base port online: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002277 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002278
2279 /* If QoS is enabled and it is not online, send AEN */
2280 if (fcport->cfg.qos_enabled &&
2281 fcport->qos_attr.state != BFA_QOS_ONLINE)
2282 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002283 break;
2284
2285 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002286 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002287 * Possible to get link down event.
2288 */
2289 break;
2290
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_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2305 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2306 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002307 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002308 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002309 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002310 break;
2311
2312 case BFA_FCPORT_SM_STOP:
2313 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2314 break;
2315
2316 case BFA_FCPORT_SM_HWFAIL:
2317 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2318 break;
2319
2320 default:
2321 bfa_sm_fault(fcport->bfa, event);
2322 }
2323}
2324
2325static void
2326bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
2327 enum bfa_fcport_sm_event event)
2328{
2329 char pwwn_buf[BFA_STRING_32];
2330 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2331
2332 bfa_trc(fcport->bfa, event);
2333
2334 switch (event) {
2335 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002336 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002337 * Already enabled.
2338 */
2339 break;
2340
2341 case BFA_FCPORT_SM_DISABLE:
2342 if (bfa_fcport_send_disable(fcport))
2343 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2344 else
2345 bfa_sm_set_state(fcport,
2346 bfa_fcport_sm_disabling_qwait);
2347
2348 bfa_fcport_reset_linkinfo(fcport);
2349 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2350 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2351 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2352 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002353 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002354 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002355 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
Jing Huang88166242010-12-09 17:11:53 -08002356 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002357 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002358 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002359 break;
2360
2361 case BFA_FCPORT_SM_LINKDOWN:
2362 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2363 bfa_fcport_reset_linkinfo(fcport);
2364 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2365 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2366 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
2367 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002368 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002369 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002370 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002371 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2372 } else {
Jing Huang88166242010-12-09 17:11:53 -08002373 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002374 "Base port (WWN = %s) "
2375 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002376 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2377 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002378 break;
2379
2380 case BFA_FCPORT_SM_STOP:
2381 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2382 bfa_fcport_reset_linkinfo(fcport);
2383 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002384 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002385 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002386 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002387 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2388 } else {
Jing Huang88166242010-12-09 17:11:53 -08002389 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002390 "Base port (WWN = %s) "
2391 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002392 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2393 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002394 break;
2395
2396 case BFA_FCPORT_SM_HWFAIL:
2397 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2398 bfa_fcport_reset_linkinfo(fcport);
2399 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2400 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002401 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002402 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002403 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002404 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2405 } else {
Jing Huang88166242010-12-09 17:11:53 -08002406 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002407 "Base port (WWN = %s) "
2408 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002409 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2410 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002411 break;
2412
2413 default:
2414 bfa_sm_fault(fcport->bfa, event);
2415 }
2416}
2417
2418static void
2419bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
2420 enum bfa_fcport_sm_event event)
2421{
2422 bfa_trc(fcport->bfa, event);
2423
2424 switch (event) {
2425 case BFA_FCPORT_SM_QRESUME:
2426 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2427 bfa_fcport_send_disable(fcport);
2428 break;
2429
2430 case BFA_FCPORT_SM_STOP:
2431 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2432 bfa_reqq_wcancel(&fcport->reqq_wait);
2433 break;
2434
2435 case BFA_FCPORT_SM_ENABLE:
2436 bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
2437 break;
2438
2439 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002440 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002441 * Already being disabled.
2442 */
2443 break;
2444
2445 case BFA_FCPORT_SM_LINKUP:
2446 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002447 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002448 * Possible to get link events when doing back-to-back
2449 * enable/disables.
2450 */
2451 break;
2452
2453 case BFA_FCPORT_SM_HWFAIL:
2454 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2455 bfa_reqq_wcancel(&fcport->reqq_wait);
2456 break;
2457
2458 default:
2459 bfa_sm_fault(fcport->bfa, event);
2460 }
2461}
2462
2463static void
2464bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
2465 enum bfa_fcport_sm_event event)
2466{
2467 bfa_trc(fcport->bfa, event);
2468
2469 switch (event) {
2470 case BFA_FCPORT_SM_QRESUME:
2471 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2472 bfa_fcport_send_disable(fcport);
2473 if (bfa_fcport_send_enable(fcport))
2474 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2475 else
2476 bfa_sm_set_state(fcport,
2477 bfa_fcport_sm_enabling_qwait);
2478 break;
2479
2480 case BFA_FCPORT_SM_STOP:
2481 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2482 bfa_reqq_wcancel(&fcport->reqq_wait);
2483 break;
2484
2485 case BFA_FCPORT_SM_ENABLE:
2486 break;
2487
2488 case BFA_FCPORT_SM_DISABLE:
2489 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
2490 break;
2491
2492 case BFA_FCPORT_SM_LINKUP:
2493 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002494 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002495 * Possible to get link events when doing back-to-back
2496 * enable/disables.
2497 */
2498 break;
2499
2500 case BFA_FCPORT_SM_HWFAIL:
2501 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2502 bfa_reqq_wcancel(&fcport->reqq_wait);
2503 break;
2504
2505 default:
2506 bfa_sm_fault(fcport->bfa, event);
2507 }
2508}
2509
2510static void
2511bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
2512 enum bfa_fcport_sm_event event)
2513{
2514 char pwwn_buf[BFA_STRING_32];
2515 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2516 bfa_trc(fcport->bfa, event);
2517
2518 switch (event) {
2519 case BFA_FCPORT_SM_FWRSP:
2520 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2521 break;
2522
2523 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002524 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002525 * Already being disabled.
2526 */
2527 break;
2528
2529 case BFA_FCPORT_SM_ENABLE:
2530 if (bfa_fcport_send_enable(fcport))
2531 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2532 else
2533 bfa_sm_set_state(fcport,
2534 bfa_fcport_sm_enabling_qwait);
2535
2536 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2537 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2538 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002539 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002540 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002541 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002542 break;
2543
2544 case BFA_FCPORT_SM_STOP:
2545 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2546 break;
2547
2548 case BFA_FCPORT_SM_LINKUP:
2549 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002550 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002551 * Possible to get link events when doing back-to-back
2552 * enable/disables.
2553 */
2554 break;
2555
2556 case BFA_FCPORT_SM_HWFAIL:
2557 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2558 break;
2559
2560 default:
2561 bfa_sm_fault(fcport->bfa, event);
2562 }
2563}
2564
2565static void
2566bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
2567 enum bfa_fcport_sm_event event)
2568{
2569 char pwwn_buf[BFA_STRING_32];
2570 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2571 bfa_trc(fcport->bfa, event);
2572
2573 switch (event) {
2574 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002575 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002576 * Ignore start event for a port that is disabled.
2577 */
2578 break;
2579
2580 case BFA_FCPORT_SM_STOP:
2581 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2582 break;
2583
2584 case BFA_FCPORT_SM_ENABLE:
2585 if (bfa_fcport_send_enable(fcport))
2586 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2587 else
2588 bfa_sm_set_state(fcport,
2589 bfa_fcport_sm_enabling_qwait);
2590
2591 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2592 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2593 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002594 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002595 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002596 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002597 break;
2598
2599 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002600 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002601 * Already disabled.
2602 */
2603 break;
2604
2605 case BFA_FCPORT_SM_HWFAIL:
2606 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2607 break;
2608
2609 default:
2610 bfa_sm_fault(fcport->bfa, event);
2611 }
2612}
2613
2614static void
2615bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
2616 enum bfa_fcport_sm_event event)
2617{
2618 bfa_trc(fcport->bfa, event);
2619
2620 switch (event) {
2621 case BFA_FCPORT_SM_START:
2622 if (bfa_fcport_send_enable(fcport))
2623 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2624 else
2625 bfa_sm_set_state(fcport,
2626 bfa_fcport_sm_enabling_qwait);
2627 break;
2628
2629 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002630 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002631 * Ignore all other events.
2632 */
2633 ;
2634 }
2635}
2636
Jing Huang5fbe25c2010-10-18 17:17:23 -07002637/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002638 * Port is enabled. IOC is down/failed.
2639 */
2640static void
2641bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
2642 enum bfa_fcport_sm_event event)
2643{
2644 bfa_trc(fcport->bfa, event);
2645
2646 switch (event) {
2647 case BFA_FCPORT_SM_START:
2648 if (bfa_fcport_send_enable(fcport))
2649 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2650 else
2651 bfa_sm_set_state(fcport,
2652 bfa_fcport_sm_enabling_qwait);
2653 break;
2654
2655 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002656 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002657 * Ignore all events.
2658 */
2659 ;
2660 }
2661}
2662
Jing Huang5fbe25c2010-10-18 17:17:23 -07002663/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002664 * Port is disabled. IOC is down/failed.
2665 */
2666static void
2667bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
2668 enum bfa_fcport_sm_event event)
2669{
2670 bfa_trc(fcport->bfa, event);
2671
2672 switch (event) {
2673 case BFA_FCPORT_SM_START:
2674 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2675 break;
2676
2677 case BFA_FCPORT_SM_ENABLE:
2678 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2679 break;
2680
2681 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002682 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002683 * Ignore all events.
2684 */
2685 ;
2686 }
2687}
2688
Jing Huang5fbe25c2010-10-18 17:17:23 -07002689/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002690 * Link state is down
2691 */
2692static void
2693bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
2694 enum bfa_fcport_ln_sm_event event)
2695{
2696 bfa_trc(ln->fcport->bfa, event);
2697
2698 switch (event) {
2699 case BFA_FCPORT_LN_SM_LINKUP:
2700 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2701 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2702 break;
2703
2704 default:
2705 bfa_sm_fault(ln->fcport->bfa, event);
2706 }
2707}
2708
Jing Huang5fbe25c2010-10-18 17:17:23 -07002709/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002710 * Link state is waiting for down notification
2711 */
2712static void
2713bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
2714 enum bfa_fcport_ln_sm_event event)
2715{
2716 bfa_trc(ln->fcport->bfa, event);
2717
2718 switch (event) {
2719 case BFA_FCPORT_LN_SM_LINKUP:
2720 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2721 break;
2722
2723 case BFA_FCPORT_LN_SM_NOTIFICATION:
2724 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
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 down notification and there is a pending up
2734 */
2735static void
2736bfa_fcport_ln_sm_dn_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_dn_nf);
2744 break;
2745
2746 case BFA_FCPORT_LN_SM_NOTIFICATION:
2747 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2748 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2749 break;
2750
2751 default:
2752 bfa_sm_fault(ln->fcport->bfa, event);
2753 }
2754}
2755
Jing Huang5fbe25c2010-10-18 17:17:23 -07002756/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002757 * Link state is up
2758 */
2759static void
2760bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
2761 enum bfa_fcport_ln_sm_event event)
2762{
2763 bfa_trc(ln->fcport->bfa, event);
2764
2765 switch (event) {
2766 case BFA_FCPORT_LN_SM_LINKDOWN:
2767 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2768 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2769 break;
2770
2771 default:
2772 bfa_sm_fault(ln->fcport->bfa, event);
2773 }
2774}
2775
Jing Huang5fbe25c2010-10-18 17:17:23 -07002776/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002777 * Link state is waiting for up notification
2778 */
2779static void
2780bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
2781 enum bfa_fcport_ln_sm_event event)
2782{
2783 bfa_trc(ln->fcport->bfa, event);
2784
2785 switch (event) {
2786 case BFA_FCPORT_LN_SM_LINKDOWN:
2787 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2788 break;
2789
2790 case BFA_FCPORT_LN_SM_NOTIFICATION:
2791 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
2792 break;
2793
2794 default:
2795 bfa_sm_fault(ln->fcport->bfa, event);
2796 }
2797}
2798
Jing Huang5fbe25c2010-10-18 17:17:23 -07002799/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002800 * Link state is waiting for up notification and there is a pending down
2801 */
2802static void
2803bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
2804 enum bfa_fcport_ln_sm_event event)
2805{
2806 bfa_trc(ln->fcport->bfa, event);
2807
2808 switch (event) {
2809 case BFA_FCPORT_LN_SM_LINKUP:
2810 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
2811 break;
2812
2813 case BFA_FCPORT_LN_SM_NOTIFICATION:
2814 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2815 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2816 break;
2817
2818 default:
2819 bfa_sm_fault(ln->fcport->bfa, event);
2820 }
2821}
2822
Jing Huang5fbe25c2010-10-18 17:17:23 -07002823/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002824 * Link state is waiting for up notification and there are pending down and up
2825 */
2826static void
2827bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
2828 enum bfa_fcport_ln_sm_event event)
2829{
2830 bfa_trc(ln->fcport->bfa, event);
2831
2832 switch (event) {
2833 case BFA_FCPORT_LN_SM_LINKDOWN:
2834 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2835 break;
2836
2837 case BFA_FCPORT_LN_SM_NOTIFICATION:
2838 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2839 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2840 break;
2841
2842 default:
2843 bfa_sm_fault(ln->fcport->bfa, event);
2844 }
2845}
2846
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002847static void
2848__bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
2849{
2850 struct bfa_fcport_ln_s *ln = cbarg;
2851
2852 if (complete)
2853 ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
2854 else
2855 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2856}
2857
Jing Huang5fbe25c2010-10-18 17:17:23 -07002858/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002859 * Send SCN notification to upper layers.
2860 * trunk - false if caller is fcport to ignore fcport event in trunked mode
2861 */
2862static void
2863bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
2864 bfa_boolean_t trunk)
2865{
2866 if (fcport->cfg.trunked && !trunk)
2867 return;
2868
2869 switch (event) {
2870 case BFA_PORT_LINKUP:
2871 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
2872 break;
2873 case BFA_PORT_LINKDOWN:
2874 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
2875 break;
2876 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08002877 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002878 }
2879}
2880
2881static void
2882bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
2883{
2884 struct bfa_fcport_s *fcport = ln->fcport;
2885
2886 if (fcport->bfa->fcs) {
2887 fcport->event_cbfn(fcport->event_cbarg, event);
2888 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2889 } else {
2890 ln->ln_event = event;
2891 bfa_cb_queue(fcport->bfa, &ln->ln_qe,
2892 __bfa_cb_fcport_event, ln);
2893 }
2894}
2895
2896#define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
2897 BFA_CACHELINE_SZ))
2898
2899static void
Krishna Gudipati45070252011-06-24 20:24:29 -07002900bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
2901 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002902{
Krishna Gudipati45070252011-06-24 20:24:29 -07002903 struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa);
2904
2905 bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002906}
2907
2908static void
2909bfa_fcport_qresume(void *cbarg)
2910{
2911 struct bfa_fcport_s *fcport = cbarg;
2912
2913 bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
2914}
2915
2916static void
Krishna Gudipati45070252011-06-24 20:24:29 -07002917bfa_fcport_mem_claim(struct bfa_fcport_s *fcport)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002918{
Krishna Gudipati45070252011-06-24 20:24:29 -07002919 struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002920
Krishna Gudipati45070252011-06-24 20:24:29 -07002921 fcport->stats_kva = bfa_mem_dma_virt(fcport_dma);
2922 fcport->stats_pa = bfa_mem_dma_phys(fcport_dma);
2923 fcport->stats = (union bfa_fcport_stats_u *)
2924 bfa_mem_dma_virt(fcport_dma);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002925}
2926
Jing Huang5fbe25c2010-10-18 17:17:23 -07002927/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002928 * Memory initialization.
2929 */
2930static void
2931bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07002932 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002933{
2934 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2935 struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
2936 struct bfa_fcport_ln_s *ln = &fcport->ln;
Maggie Zhangf16a1752010-12-09 19:12:32 -08002937 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002938
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002939 fcport->bfa = bfa;
2940 ln->fcport = fcport;
2941
Krishna Gudipati45070252011-06-24 20:24:29 -07002942 bfa_fcport_mem_claim(fcport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002943
2944 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
2945 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2946
Jing Huang5fbe25c2010-10-18 17:17:23 -07002947 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002948 * initialize time stamp for stats reset
2949 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08002950 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002951 fcport->stats_reset_time = tv.tv_sec;
2952
Jing Huang5fbe25c2010-10-18 17:17:23 -07002953 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002954 * initialize and set default configuration
2955 */
2956 port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
2957 port_cfg->speed = BFA_PORT_SPEED_AUTO;
2958 port_cfg->trunked = BFA_FALSE;
2959 port_cfg->maxfrsize = 0;
2960
2961 port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
2962
Krishna Gudipati37ea0552011-07-20 17:02:11 -07002963 INIT_LIST_HEAD(&fcport->stats_pending_q);
2964 INIT_LIST_HEAD(&fcport->statsclr_pending_q);
2965
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002966 bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
2967}
2968
2969static void
2970bfa_fcport_detach(struct bfa_s *bfa)
2971{
2972}
2973
Jing Huang5fbe25c2010-10-18 17:17:23 -07002974/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002975 * Called when IOC is ready.
2976 */
2977static void
2978bfa_fcport_start(struct bfa_s *bfa)
2979{
2980 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
2981}
2982
Jing Huang5fbe25c2010-10-18 17:17:23 -07002983/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002984 * Called before IOC is stopped.
2985 */
2986static void
2987bfa_fcport_stop(struct bfa_s *bfa)
2988{
2989 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
2990 bfa_trunk_iocdisable(bfa);
2991}
2992
Jing Huang5fbe25c2010-10-18 17:17:23 -07002993/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002994 * Called when IOC failure is detected.
2995 */
2996static void
2997bfa_fcport_iocdisable(struct bfa_s *bfa)
2998{
2999 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3000
3001 bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
3002 bfa_trunk_iocdisable(bfa);
3003}
3004
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003005/*
3006 * Update loop info in fcport for SCN online
3007 */
3008static void
3009bfa_fcport_update_loop_info(struct bfa_fcport_s *fcport,
3010 struct bfa_fcport_loop_info_s *loop_info)
3011{
3012 fcport->myalpa = loop_info->myalpa;
3013 fcport->alpabm_valid =
3014 loop_info->alpabm_val;
3015 memcpy(fcport->alpabm.alpa_bm,
3016 loop_info->alpabm.alpa_bm,
3017 sizeof(struct fc_alpabm_s));
3018}
3019
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003020static void
3021bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
3022{
3023 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
3024 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3025
3026 fcport->speed = pevent->link_state.speed;
3027 fcport->topology = pevent->link_state.topology;
3028
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003029 if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP) {
3030 bfa_fcport_update_loop_info(fcport,
3031 &pevent->link_state.attr.loop_info);
3032 return;
3033 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003034
3035 /* QoS Details */
Jing Huang6a18b162010-10-18 17:08:54 -07003036 fcport->qos_attr = pevent->link_state.qos_attr;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003037 fcport->qos_vc_attr = pevent->link_state.attr.vc_fcf.qos_vc_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003038
Jing Huang5fbe25c2010-10-18 17:17:23 -07003039 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003040 * update trunk state if applicable
3041 */
3042 if (!fcport->cfg.trunked)
3043 trunk->attr.state = BFA_TRUNK_DISABLED;
3044
3045 /* update FCoE specific */
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003046 fcport->fcoe_vlan =
3047 be16_to_cpu(pevent->link_state.attr.vc_fcf.fcf.vlan);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003048
3049 bfa_trc(fcport->bfa, fcport->speed);
3050 bfa_trc(fcport->bfa, fcport->topology);
3051}
3052
3053static void
3054bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
3055{
3056 fcport->speed = BFA_PORT_SPEED_UNKNOWN;
3057 fcport->topology = BFA_PORT_TOPOLOGY_NONE;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003058 fcport->bbsc_op_state = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003059}
3060
Jing Huang5fbe25c2010-10-18 17:17:23 -07003061/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003062 * Send port enable message to firmware.
3063 */
3064static bfa_boolean_t
3065bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
3066{
3067 struct bfi_fcport_enable_req_s *m;
3068
Jing Huang5fbe25c2010-10-18 17:17:23 -07003069 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003070 * Increment message tag before queue check, so that responses to old
3071 * requests are discarded.
3072 */
3073 fcport->msgtag++;
3074
Jing Huang5fbe25c2010-10-18 17:17:23 -07003075 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003076 * check for room in queue to send request now
3077 */
3078 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3079 if (!m) {
3080 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3081 &fcport->reqq_wait);
3082 return BFA_FALSE;
3083 }
3084
3085 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003086 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003087 m->nwwn = fcport->nwwn;
3088 m->pwwn = fcport->pwwn;
3089 m->port_cfg = fcport->cfg;
3090 m->msgtag = fcport->msgtag;
Jing Huangba816ea2010-10-18 17:10:50 -07003091 m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003092 m->use_flash_cfg = fcport->use_flash_cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003093 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
3094 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
3095 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
3096
Jing Huang5fbe25c2010-10-18 17:17:23 -07003097 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003098 * queue I/O message to firmware
3099 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003100 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003101 return BFA_TRUE;
3102}
3103
Jing Huang5fbe25c2010-10-18 17:17:23 -07003104/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003105 * Send port disable message to firmware.
3106 */
3107static bfa_boolean_t
3108bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
3109{
3110 struct bfi_fcport_req_s *m;
3111
Jing Huang5fbe25c2010-10-18 17:17:23 -07003112 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003113 * Increment message tag before queue check, so that responses to old
3114 * requests are discarded.
3115 */
3116 fcport->msgtag++;
3117
Jing Huang5fbe25c2010-10-18 17:17:23 -07003118 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003119 * check for room in queue to send request now
3120 */
3121 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3122 if (!m) {
3123 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3124 &fcport->reqq_wait);
3125 return BFA_FALSE;
3126 }
3127
3128 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003129 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003130 m->msgtag = fcport->msgtag;
3131
Jing Huang5fbe25c2010-10-18 17:17:23 -07003132 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003133 * queue I/O message to firmware
3134 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003135 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003136
3137 return BFA_TRUE;
3138}
3139
3140static void
3141bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
3142{
Maggie Zhangf7f738122010-12-09 19:08:43 -08003143 fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
3144 fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003145
3146 bfa_trc(fcport->bfa, fcport->pwwn);
3147 bfa_trc(fcport->bfa, fcport->nwwn);
3148}
3149
3150static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003151bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
3152 struct bfa_qos_stats_s *s)
3153{
3154 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003155 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003156 int i;
3157
3158 /* Now swap the 32 bit fields */
3159 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
Jing Huangba816ea2010-10-18 17:10:50 -07003160 dip[i] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003161}
3162
3163static void
3164bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
3165 struct bfa_fcoe_stats_s *s)
3166{
3167 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003168 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003169 int i;
3170
3171 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
3172 i = i + 2) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003173#ifdef __BIG_ENDIAN
Jing Huangba816ea2010-10-18 17:10:50 -07003174 dip[i] = be32_to_cpu(sip[i]);
3175 dip[i + 1] = be32_to_cpu(sip[i + 1]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003176#else
Jing Huangba816ea2010-10-18 17:10:50 -07003177 dip[i] = be32_to_cpu(sip[i + 1]);
3178 dip[i + 1] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003179#endif
3180 }
3181}
3182
3183static void
3184__bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
3185{
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003186 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *)cbarg;
3187 struct bfa_cb_pending_q_s *cb;
3188 struct list_head *qe, *qen;
3189 union bfa_fcport_stats_u *ret;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003190
3191 if (complete) {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003192 struct timeval tv;
3193 if (fcport->stats_status == BFA_STATUS_OK)
3194 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003195
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003196 list_for_each_safe(qe, qen, &fcport->stats_pending_q) {
3197 bfa_q_deq(&fcport->stats_pending_q, &qe);
3198 cb = (struct bfa_cb_pending_q_s *)qe;
3199 if (fcport->stats_status == BFA_STATUS_OK) {
3200 ret = (union bfa_fcport_stats_u *)cb->data;
3201 /* Swap FC QoS or FCoE stats */
3202 if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
3203 bfa_fcport_qos_stats_swap(&ret->fcqos,
3204 &fcport->stats->fcqos);
3205 else {
3206 bfa_fcport_fcoe_stats_swap(&ret->fcoe,
3207 &fcport->stats->fcoe);
3208 ret->fcoe.secs_reset =
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003209 tv.tv_sec - fcport->stats_reset_time;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003210 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003211 }
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003212 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
3213 fcport->stats_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003214 }
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003215 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003216 } else {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003217 INIT_LIST_HEAD(&fcport->stats_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003218 fcport->stats_status = BFA_STATUS_OK;
3219 }
3220}
3221
3222static void
3223bfa_fcport_stats_get_timeout(void *cbarg)
3224{
3225 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3226
3227 bfa_trc(fcport->bfa, fcport->stats_qfull);
3228
3229 if (fcport->stats_qfull) {
3230 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3231 fcport->stats_qfull = BFA_FALSE;
3232 }
3233
3234 fcport->stats_status = BFA_STATUS_ETIMER;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003235 __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003236}
3237
3238static void
3239bfa_fcport_send_stats_get(void *cbarg)
3240{
3241 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3242 struct bfi_fcport_req_s *msg;
3243
3244 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3245
3246 if (!msg) {
3247 fcport->stats_qfull = BFA_TRUE;
3248 bfa_reqq_winit(&fcport->stats_reqq_wait,
3249 bfa_fcport_send_stats_get, fcport);
3250 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3251 &fcport->stats_reqq_wait);
3252 return;
3253 }
3254 fcport->stats_qfull = BFA_FALSE;
3255
Jing Huang6a18b162010-10-18 17:08:54 -07003256 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003257 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003258 bfa_fn_lpu(fcport->bfa));
3259 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003260}
3261
3262static void
3263__bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
3264{
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003265 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3266 struct bfa_cb_pending_q_s *cb;
3267 struct list_head *qe, *qen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003268
3269 if (complete) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003270 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003271
Jing Huang5fbe25c2010-10-18 17:17:23 -07003272 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003273 * re-initialize time stamp for stats reset
3274 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08003275 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003276 fcport->stats_reset_time = tv.tv_sec;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003277 list_for_each_safe(qe, qen, &fcport->statsclr_pending_q) {
3278 bfa_q_deq(&fcport->statsclr_pending_q, &qe);
3279 cb = (struct bfa_cb_pending_q_s *)qe;
3280 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
3281 fcport->stats_status);
3282 }
3283 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003284 } else {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003285 INIT_LIST_HEAD(&fcport->statsclr_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003286 fcport->stats_status = BFA_STATUS_OK;
3287 }
3288}
3289
3290static void
3291bfa_fcport_stats_clr_timeout(void *cbarg)
3292{
3293 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3294
3295 bfa_trc(fcport->bfa, fcport->stats_qfull);
3296
3297 if (fcport->stats_qfull) {
3298 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3299 fcport->stats_qfull = BFA_FALSE;
3300 }
3301
3302 fcport->stats_status = BFA_STATUS_ETIMER;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003303 __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003304}
3305
3306static void
3307bfa_fcport_send_stats_clear(void *cbarg)
3308{
3309 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3310 struct bfi_fcport_req_s *msg;
3311
3312 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3313
3314 if (!msg) {
3315 fcport->stats_qfull = BFA_TRUE;
3316 bfa_reqq_winit(&fcport->stats_reqq_wait,
3317 bfa_fcport_send_stats_clear, fcport);
3318 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3319 &fcport->stats_reqq_wait);
3320 return;
3321 }
3322 fcport->stats_qfull = BFA_FALSE;
3323
Jing Huang6a18b162010-10-18 17:08:54 -07003324 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003325 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003326 bfa_fn_lpu(fcport->bfa));
3327 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003328}
3329
Jing Huang5fbe25c2010-10-18 17:17:23 -07003330/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003331 * Handle trunk SCN event from firmware.
3332 */
3333static void
3334bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3335{
3336 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3337 struct bfi_fcport_trunk_link_s *tlink;
3338 struct bfa_trunk_link_attr_s *lattr;
3339 enum bfa_trunk_state state_prev;
3340 int i;
3341 int link_bm = 0;
3342
3343 bfa_trc(fcport->bfa, fcport->cfg.trunked);
Jing Huangd4b671c2010-12-26 21:46:35 -08003344 WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
3345 scn->trunk_state != BFA_TRUNK_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003346
3347 bfa_trc(fcport->bfa, trunk->attr.state);
3348 bfa_trc(fcport->bfa, scn->trunk_state);
3349 bfa_trc(fcport->bfa, scn->trunk_speed);
3350
Jing Huang5fbe25c2010-10-18 17:17:23 -07003351 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003352 * Save off new state for trunk attribute query
3353 */
3354 state_prev = trunk->attr.state;
3355 if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
3356 trunk->attr.state = scn->trunk_state;
3357 trunk->attr.speed = scn->trunk_speed;
3358 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3359 lattr = &trunk->attr.link_attr[i];
3360 tlink = &scn->tlink[i];
3361
3362 lattr->link_state = tlink->state;
3363 lattr->trunk_wwn = tlink->trunk_wwn;
3364 lattr->fctl = tlink->fctl;
3365 lattr->speed = tlink->speed;
Jing Huangba816ea2010-10-18 17:10:50 -07003366 lattr->deskew = be32_to_cpu(tlink->deskew);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003367
3368 if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
3369 fcport->speed = tlink->speed;
3370 fcport->topology = BFA_PORT_TOPOLOGY_P2P;
3371 link_bm |= 1 << i;
3372 }
3373
3374 bfa_trc(fcport->bfa, lattr->link_state);
3375 bfa_trc(fcport->bfa, lattr->trunk_wwn);
3376 bfa_trc(fcport->bfa, lattr->fctl);
3377 bfa_trc(fcport->bfa, lattr->speed);
3378 bfa_trc(fcport->bfa, lattr->deskew);
3379 }
3380
3381 switch (link_bm) {
3382 case 3:
3383 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3384 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
3385 break;
3386 case 2:
3387 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3388 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
3389 break;
3390 case 1:
3391 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3392 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
3393 break;
3394 default:
3395 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3396 BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
3397 }
3398
Jing Huang5fbe25c2010-10-18 17:17:23 -07003399 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003400 * Notify upper layers if trunk state changed.
3401 */
3402 if ((state_prev != trunk->attr.state) ||
3403 (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
3404 bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
3405 BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
3406 }
3407}
3408
3409static void
3410bfa_trunk_iocdisable(struct bfa_s *bfa)
3411{
3412 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3413 int i = 0;
3414
Jing Huang5fbe25c2010-10-18 17:17:23 -07003415 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003416 * In trunked mode, notify upper layers that link is down
3417 */
3418 if (fcport->cfg.trunked) {
3419 if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
3420 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
3421
3422 fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
3423 fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
3424 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3425 fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
3426 fcport->trunk.attr.link_attr[i].fctl =
3427 BFA_TRUNK_LINK_FCTL_NORMAL;
3428 fcport->trunk.attr.link_attr[i].link_state =
3429 BFA_TRUNK_LINK_STATE_DN_LINKDN;
3430 fcport->trunk.attr.link_attr[i].speed =
3431 BFA_PORT_SPEED_UNKNOWN;
3432 fcport->trunk.attr.link_attr[i].deskew = 0;
3433 }
3434 }
3435}
3436
Jing Huang5fbe25c2010-10-18 17:17:23 -07003437/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003438 * Called to initialize port attributes
3439 */
3440void
3441bfa_fcport_init(struct bfa_s *bfa)
3442{
3443 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3444
Jing Huang5fbe25c2010-10-18 17:17:23 -07003445 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003446 * Initialize port attributes from IOC hardware data.
3447 */
3448 bfa_fcport_set_wwns(fcport);
3449 if (fcport->cfg.maxfrsize == 0)
3450 fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
3451 fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
3452 fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
3453
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003454 if (bfa_fcport_is_pbcdisabled(bfa))
3455 bfa->modules.port.pbc_disabled = BFA_TRUE;
3456
Jing Huangd4b671c2010-12-26 21:46:35 -08003457 WARN_ON(!fcport->cfg.maxfrsize);
3458 WARN_ON(!fcport->cfg.rx_bbcredit);
3459 WARN_ON(!fcport->speed_sup);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003460}
3461
Jing Huang5fbe25c2010-10-18 17:17:23 -07003462/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003463 * Firmware message handler.
3464 */
3465void
3466bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
3467{
3468 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3469 union bfi_fcport_i2h_msg_u i2hmsg;
3470
3471 i2hmsg.msg = msg;
3472 fcport->event_arg.i2hmsg = i2hmsg;
3473
3474 bfa_trc(bfa, msg->mhdr.msg_id);
3475 bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
3476
3477 switch (msg->mhdr.msg_id) {
3478 case BFI_FCPORT_I2H_ENABLE_RSP:
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003479 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
3480
3481 if (fcport->use_flash_cfg) {
3482 fcport->cfg = i2hmsg.penable_rsp->port_cfg;
3483 fcport->cfg.maxfrsize =
3484 cpu_to_be16(fcport->cfg.maxfrsize);
3485 fcport->cfg.path_tov =
3486 cpu_to_be16(fcport->cfg.path_tov);
3487 fcport->cfg.q_depth =
3488 cpu_to_be16(fcport->cfg.q_depth);
3489
3490 if (fcport->cfg.trunked)
3491 fcport->trunk.attr.state =
3492 BFA_TRUNK_OFFLINE;
3493 else
3494 fcport->trunk.attr.state =
3495 BFA_TRUNK_DISABLED;
3496 fcport->use_flash_cfg = BFA_FALSE;
3497 }
3498
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07003499 if (fcport->cfg.qos_enabled)
3500 fcport->qos_attr.state = BFA_QOS_OFFLINE;
3501 else
3502 fcport->qos_attr.state = BFA_QOS_DISABLED;
3503
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003504 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003505 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003506 break;
3507
3508 case BFI_FCPORT_I2H_DISABLE_RSP:
3509 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
3510 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
3511 break;
3512
3513 case BFI_FCPORT_I2H_EVENT:
3514 if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
3515 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
3516 else
3517 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
3518 break;
3519
3520 case BFI_FCPORT_I2H_TRUNK_SCN:
3521 bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
3522 break;
3523
3524 case BFI_FCPORT_I2H_STATS_GET_RSP:
3525 /*
3526 * check for timer pop before processing the rsp
3527 */
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003528 if (list_empty(&fcport->stats_pending_q) ||
3529 (fcport->stats_status == BFA_STATUS_ETIMER))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003530 break;
3531
3532 bfa_timer_stop(&fcport->timer);
3533 fcport->stats_status = i2hmsg.pstatsget_rsp->status;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003534 __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003535 break;
3536
3537 case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
3538 /*
3539 * check for timer pop before processing the rsp
3540 */
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003541 if (list_empty(&fcport->statsclr_pending_q) ||
3542 (fcport->stats_status == BFA_STATUS_ETIMER))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003543 break;
3544
3545 bfa_timer_stop(&fcport->timer);
3546 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003547 __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003548 break;
3549
3550 case BFI_FCPORT_I2H_ENABLE_AEN:
3551 bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
3552 break;
3553
3554 case BFI_FCPORT_I2H_DISABLE_AEN:
3555 bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
3556 break;
3557
3558 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08003559 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003560 break;
3561 }
3562}
3563
Jing Huang5fbe25c2010-10-18 17:17:23 -07003564/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003565 * Registered callback for port events.
3566 */
3567void
3568bfa_fcport_event_register(struct bfa_s *bfa,
3569 void (*cbfn) (void *cbarg,
3570 enum bfa_port_linkstate event),
3571 void *cbarg)
3572{
3573 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3574
3575 fcport->event_cbfn = cbfn;
3576 fcport->event_cbarg = cbarg;
3577}
3578
3579bfa_status_t
3580bfa_fcport_enable(struct bfa_s *bfa)
3581{
3582 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3583
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003584 if (bfa_fcport_is_pbcdisabled(bfa))
3585 return BFA_STATUS_PBC;
3586
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003587 if (bfa_ioc_is_disabled(&bfa->ioc))
3588 return BFA_STATUS_IOC_DISABLED;
3589
3590 if (fcport->diag_busy)
3591 return BFA_STATUS_DIAG_BUSY;
3592
3593 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
3594 return BFA_STATUS_OK;
3595}
3596
3597bfa_status_t
3598bfa_fcport_disable(struct bfa_s *bfa)
3599{
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003600 if (bfa_fcport_is_pbcdisabled(bfa))
3601 return BFA_STATUS_PBC;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003602
3603 if (bfa_ioc_is_disabled(&bfa->ioc))
3604 return BFA_STATUS_IOC_DISABLED;
3605
3606 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
3607 return BFA_STATUS_OK;
3608}
3609
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003610/* If PBC is disabled on port, return error */
3611bfa_status_t
3612bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
3613{
3614 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3615 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
3616 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
3617
3618 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
3619 bfa_trc(bfa, fcport->pwwn);
3620 return BFA_STATUS_PBC;
3621 }
3622 return BFA_STATUS_OK;
3623}
3624
Jing Huang5fbe25c2010-10-18 17:17:23 -07003625/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003626 * Configure port speed.
3627 */
3628bfa_status_t
3629bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3630{
3631 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3632
3633 bfa_trc(bfa, speed);
3634
3635 if (fcport->cfg.trunked == BFA_TRUE)
3636 return BFA_STATUS_TRUNK_ENABLED;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003637 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
3638 (speed == BFA_PORT_SPEED_16GBPS))
3639 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003640 if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
3641 bfa_trc(bfa, fcport->speed_sup);
3642 return BFA_STATUS_UNSUPP_SPEED;
3643 }
3644
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07003645 /* Port speed entered needs to be checked */
3646 if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
3647 /* For CT2, 1G is not supported */
3648 if ((speed == BFA_PORT_SPEED_1GBPS) &&
3649 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
3650 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia7141342011-06-24 20:23:19 -07003651
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07003652 /* Already checked for Auto Speed and Max Speed supp */
3653 if (!(speed == BFA_PORT_SPEED_1GBPS ||
3654 speed == BFA_PORT_SPEED_2GBPS ||
3655 speed == BFA_PORT_SPEED_4GBPS ||
3656 speed == BFA_PORT_SPEED_8GBPS ||
3657 speed == BFA_PORT_SPEED_16GBPS ||
3658 speed == BFA_PORT_SPEED_AUTO))
3659 return BFA_STATUS_UNSUPP_SPEED;
3660 } else {
3661 if (speed != BFA_PORT_SPEED_10GBPS)
3662 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia7141342011-06-24 20:23:19 -07003663 }
3664
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003665 fcport->cfg.speed = speed;
3666
3667 return BFA_STATUS_OK;
3668}
3669
Jing Huang5fbe25c2010-10-18 17:17:23 -07003670/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003671 * Get current speed.
3672 */
3673enum bfa_port_speed
3674bfa_fcport_get_speed(struct bfa_s *bfa)
3675{
3676 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3677
3678 return fcport->speed;
3679}
3680
Jing Huang5fbe25c2010-10-18 17:17:23 -07003681/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003682 * Configure port topology.
3683 */
3684bfa_status_t
3685bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
3686{
3687 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3688
3689 bfa_trc(bfa, topology);
3690 bfa_trc(bfa, fcport->cfg.topology);
3691
3692 switch (topology) {
3693 case BFA_PORT_TOPOLOGY_P2P:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003694 break;
3695
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003696 case BFA_PORT_TOPOLOGY_LOOP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003697 if ((bfa_fcport_is_qos_enabled(bfa) != BFA_FALSE) ||
3698 (fcport->qos_attr.state != BFA_QOS_DISABLED))
3699 return BFA_STATUS_ERROR_QOS_ENABLED;
3700 if (fcport->cfg.ratelimit != BFA_FALSE)
3701 return BFA_STATUS_ERROR_TRL_ENABLED;
3702 if ((bfa_fcport_is_trunk_enabled(bfa) != BFA_FALSE) ||
3703 (fcport->trunk.attr.state != BFA_TRUNK_DISABLED))
3704 return BFA_STATUS_ERROR_TRUNK_ENABLED;
3705 if ((bfa_fcport_get_speed(bfa) == BFA_PORT_SPEED_16GBPS) ||
3706 (fcport->cfg.speed == BFA_PORT_SPEED_16GBPS))
3707 return BFA_STATUS_UNSUPP_SPEED;
3708 if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type))
3709 return BFA_STATUS_LOOP_UNSUPP_MEZZ;
3710 break;
3711
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003712 case BFA_PORT_TOPOLOGY_AUTO:
3713 break;
3714
3715 default:
3716 return BFA_STATUS_EINVAL;
3717 }
3718
3719 fcport->cfg.topology = topology;
3720 return BFA_STATUS_OK;
3721}
3722
Jing Huang5fbe25c2010-10-18 17:17:23 -07003723/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003724 * Get current topology.
3725 */
3726enum bfa_port_topology
3727bfa_fcport_get_topology(struct bfa_s *bfa)
3728{
3729 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3730
3731 return fcport->topology;
3732}
3733
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003734/**
3735 * Get config topology.
3736 */
3737enum bfa_port_topology
3738bfa_fcport_get_cfg_topology(struct bfa_s *bfa)
3739{
3740 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3741
3742 return fcport->cfg.topology;
3743}
3744
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003745bfa_status_t
3746bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
3747{
3748 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3749
3750 bfa_trc(bfa, alpa);
3751 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3752 bfa_trc(bfa, fcport->cfg.hardalpa);
3753
3754 fcport->cfg.cfg_hardalpa = BFA_TRUE;
3755 fcport->cfg.hardalpa = alpa;
3756
3757 return BFA_STATUS_OK;
3758}
3759
3760bfa_status_t
3761bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
3762{
3763 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3764
3765 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3766 bfa_trc(bfa, fcport->cfg.hardalpa);
3767
3768 fcport->cfg.cfg_hardalpa = BFA_FALSE;
3769 return BFA_STATUS_OK;
3770}
3771
3772bfa_boolean_t
3773bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
3774{
3775 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3776
3777 *alpa = fcport->cfg.hardalpa;
3778 return fcport->cfg.cfg_hardalpa;
3779}
3780
3781u8
3782bfa_fcport_get_myalpa(struct bfa_s *bfa)
3783{
3784 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3785
3786 return fcport->myalpa;
3787}
3788
3789bfa_status_t
3790bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
3791{
3792 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3793
3794 bfa_trc(bfa, maxfrsize);
3795 bfa_trc(bfa, fcport->cfg.maxfrsize);
3796
3797 /* with in range */
3798 if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
3799 return BFA_STATUS_INVLD_DFSZ;
3800
3801 /* power of 2, if not the max frame size of 2112 */
3802 if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
3803 return BFA_STATUS_INVLD_DFSZ;
3804
3805 fcport->cfg.maxfrsize = maxfrsize;
3806 return BFA_STATUS_OK;
3807}
3808
3809u16
3810bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
3811{
3812 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3813
3814 return fcport->cfg.maxfrsize;
3815}
3816
3817u8
3818bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
3819{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003820 if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP)
3821 return (BFA_FCPORT_MOD(bfa))->cfg.rx_bbcredit;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003822
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07003823 else
3824 return 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003825}
3826
3827void
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003828bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit, u8 bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003829{
3830 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3831
3832 fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003833 fcport->cfg.bb_scn = bb_scn;
3834 if (bb_scn)
3835 fcport->bbsc_op_state = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003836}
3837
Jing Huang5fbe25c2010-10-18 17:17:23 -07003838/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003839 * Get port attributes.
3840 */
3841
3842wwn_t
3843bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
3844{
3845 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3846 if (node)
3847 return fcport->nwwn;
3848 else
3849 return fcport->pwwn;
3850}
3851
3852void
3853bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3854{
3855 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3856
Jing Huang6a18b162010-10-18 17:08:54 -07003857 memset(attr, 0, sizeof(struct bfa_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003858
3859 attr->nwwn = fcport->nwwn;
3860 attr->pwwn = fcport->pwwn;
3861
Maggie Zhangf7f738122010-12-09 19:08:43 -08003862 attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
3863 attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003864
Jing Huang6a18b162010-10-18 17:08:54 -07003865 memcpy(&attr->pport_cfg, &fcport->cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003866 sizeof(struct bfa_port_cfg_s));
3867 /* speed attributes */
3868 attr->pport_cfg.speed = fcport->cfg.speed;
3869 attr->speed_supported = fcport->speed_sup;
3870 attr->speed = fcport->speed;
3871 attr->cos_supported = FC_CLASS_3;
3872
3873 /* topology attributes */
3874 attr->pport_cfg.topology = fcport->cfg.topology;
3875 attr->topology = fcport->topology;
3876 attr->pport_cfg.trunked = fcport->cfg.trunked;
3877
3878 /* beacon attributes */
3879 attr->beacon = fcport->beacon;
3880 attr->link_e2e_beacon = fcport->link_e2e_beacon;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003881
3882 attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
3883 attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
3884 attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003885 attr->bbsc_op_status = fcport->bbsc_op_state;
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003886
3887 /* PBC Disabled State */
3888 if (bfa_fcport_is_pbcdisabled(bfa))
3889 attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
3890 else {
3891 if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
3892 attr->port_state = BFA_PORT_ST_IOCDIS;
3893 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
3894 attr->port_state = BFA_PORT_ST_FWMISMATCH;
3895 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003896
3897 /* FCoE vlan */
3898 attr->fcoe_vlan = fcport->fcoe_vlan;
3899}
3900
3901#define BFA_FCPORT_STATS_TOV 1000
3902
Jing Huang5fbe25c2010-10-18 17:17:23 -07003903/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003904 * Fetch port statistics (FCQoS or FCoE).
3905 */
3906bfa_status_t
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003907bfa_fcport_get_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003908{
3909 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3910
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003911 if (bfa_ioc_is_disabled(&bfa->ioc))
3912 return BFA_STATUS_IOC_DISABLED;
3913
3914 if (!list_empty(&fcport->statsclr_pending_q))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003915 return BFA_STATUS_DEVBUSY;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003916
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003917 if (list_empty(&fcport->stats_pending_q)) {
3918 list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
3919 bfa_fcport_send_stats_get(fcport);
3920 bfa_timer_start(bfa, &fcport->timer,
3921 bfa_fcport_stats_get_timeout,
3922 fcport, BFA_FCPORT_STATS_TOV);
3923 } else
3924 list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003925
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003926 return BFA_STATUS_OK;
3927}
3928
Jing Huang5fbe25c2010-10-18 17:17:23 -07003929/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003930 * Reset port statistics (FCQoS or FCoE).
3931 */
3932bfa_status_t
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003933bfa_fcport_clear_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003934{
3935 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3936
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003937 if (!list_empty(&fcport->stats_pending_q))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003938 return BFA_STATUS_DEVBUSY;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003939
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003940 if (list_empty(&fcport->statsclr_pending_q)) {
3941 list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
3942 bfa_fcport_send_stats_clear(fcport);
3943 bfa_timer_start(bfa, &fcport->timer,
3944 bfa_fcport_stats_clr_timeout,
3945 fcport, BFA_FCPORT_STATS_TOV);
3946 } else
3947 list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003948
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003949 return BFA_STATUS_OK;
3950}
3951
Jing Huang5fbe25c2010-10-18 17:17:23 -07003952/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003953 * Fetch port attributes.
3954 */
3955bfa_boolean_t
3956bfa_fcport_is_disabled(struct bfa_s *bfa)
3957{
3958 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3959
3960 return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
3961 BFA_PORT_ST_DISABLED;
3962
3963}
3964
3965bfa_boolean_t
3966bfa_fcport_is_ratelim(struct bfa_s *bfa)
3967{
3968 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3969
3970 return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
3971
3972}
3973
Jing Huang5fbe25c2010-10-18 17:17:23 -07003974/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07003975 * Enable/Disable FAA feature in port config
3976 */
3977void
3978bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state)
3979{
3980 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3981
3982 bfa_trc(bfa, state);
3983 fcport->cfg.faa_state = state;
3984}
3985
3986/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003987 * Get default minimum ratelim speed
3988 */
3989enum bfa_port_speed
3990bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
3991{
3992 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3993
3994 bfa_trc(bfa, fcport->cfg.trl_def_speed);
3995 return fcport->cfg.trl_def_speed;
3996
3997}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003998
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07003999void
4000bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
4001 bfa_boolean_t link_e2e_beacon)
4002{
4003 struct bfa_s *bfa = dev;
4004 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4005
4006 bfa_trc(bfa, beacon);
4007 bfa_trc(bfa, link_e2e_beacon);
4008 bfa_trc(bfa, fcport->beacon);
4009 bfa_trc(bfa, fcport->link_e2e_beacon);
4010
4011 fcport->beacon = beacon;
4012 fcport->link_e2e_beacon = link_e2e_beacon;
4013}
4014
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004015bfa_boolean_t
4016bfa_fcport_is_linkup(struct bfa_s *bfa)
4017{
4018 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4019
4020 return (!fcport->cfg.trunked &&
4021 bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
4022 (fcport->cfg.trunked &&
4023 fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
4024}
4025
4026bfa_boolean_t
4027bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
4028{
4029 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4030
4031 return fcport->cfg.qos_enabled;
4032}
4033
Krishna Gudipatibe540a92011-06-13 15:53:04 -07004034bfa_boolean_t
4035bfa_fcport_is_trunk_enabled(struct bfa_s *bfa)
4036{
4037 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
4038
4039 return fcport->cfg.trunked;
4040}
4041
Jing Huang5fbe25c2010-10-18 17:17:23 -07004042/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004043 * Rport State machine functions
4044 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07004045/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004046 * Beginning state, only online event expected.
4047 */
4048static void
4049bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
4050{
4051 bfa_trc(rp->bfa, rp->rport_tag);
4052 bfa_trc(rp->bfa, event);
4053
4054 switch (event) {
4055 case BFA_RPORT_SM_CREATE:
4056 bfa_stats(rp, sm_un_cr);
4057 bfa_sm_set_state(rp, bfa_rport_sm_created);
4058 break;
4059
4060 default:
4061 bfa_stats(rp, sm_un_unexp);
4062 bfa_sm_fault(rp->bfa, event);
4063 }
4064}
4065
4066static void
4067bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
4068{
4069 bfa_trc(rp->bfa, rp->rport_tag);
4070 bfa_trc(rp->bfa, event);
4071
4072 switch (event) {
4073 case BFA_RPORT_SM_ONLINE:
4074 bfa_stats(rp, sm_cr_on);
4075 if (bfa_rport_send_fwcreate(rp))
4076 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4077 else
4078 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4079 break;
4080
4081 case BFA_RPORT_SM_DELETE:
4082 bfa_stats(rp, sm_cr_del);
4083 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4084 bfa_rport_free(rp);
4085 break;
4086
4087 case BFA_RPORT_SM_HWFAIL:
4088 bfa_stats(rp, sm_cr_hwf);
4089 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4090 break;
4091
4092 default:
4093 bfa_stats(rp, sm_cr_unexp);
4094 bfa_sm_fault(rp->bfa, event);
4095 }
4096}
4097
Jing Huang5fbe25c2010-10-18 17:17:23 -07004098/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004099 * Waiting for rport create response from firmware.
4100 */
4101static void
4102bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
4103{
4104 bfa_trc(rp->bfa, rp->rport_tag);
4105 bfa_trc(rp->bfa, event);
4106
4107 switch (event) {
4108 case BFA_RPORT_SM_FWRSP:
4109 bfa_stats(rp, sm_fwc_rsp);
4110 bfa_sm_set_state(rp, bfa_rport_sm_online);
4111 bfa_rport_online_cb(rp);
4112 break;
4113
4114 case BFA_RPORT_SM_DELETE:
4115 bfa_stats(rp, sm_fwc_del);
4116 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4117 break;
4118
4119 case BFA_RPORT_SM_OFFLINE:
4120 bfa_stats(rp, sm_fwc_off);
4121 bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
4122 break;
4123
4124 case BFA_RPORT_SM_HWFAIL:
4125 bfa_stats(rp, sm_fwc_hwf);
4126 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4127 break;
4128
4129 default:
4130 bfa_stats(rp, sm_fwc_unexp);
4131 bfa_sm_fault(rp->bfa, event);
4132 }
4133}
4134
Jing Huang5fbe25c2010-10-18 17:17:23 -07004135/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004136 * Request queue is full, awaiting queue resume to send create request.
4137 */
4138static void
4139bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4140{
4141 bfa_trc(rp->bfa, rp->rport_tag);
4142 bfa_trc(rp->bfa, event);
4143
4144 switch (event) {
4145 case BFA_RPORT_SM_QRESUME:
4146 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4147 bfa_rport_send_fwcreate(rp);
4148 break;
4149
4150 case BFA_RPORT_SM_DELETE:
4151 bfa_stats(rp, sm_fwc_del);
4152 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4153 bfa_reqq_wcancel(&rp->reqq_wait);
4154 bfa_rport_free(rp);
4155 break;
4156
4157 case BFA_RPORT_SM_OFFLINE:
4158 bfa_stats(rp, sm_fwc_off);
4159 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4160 bfa_reqq_wcancel(&rp->reqq_wait);
4161 bfa_rport_offline_cb(rp);
4162 break;
4163
4164 case BFA_RPORT_SM_HWFAIL:
4165 bfa_stats(rp, sm_fwc_hwf);
4166 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4167 bfa_reqq_wcancel(&rp->reqq_wait);
4168 break;
4169
4170 default:
4171 bfa_stats(rp, sm_fwc_unexp);
4172 bfa_sm_fault(rp->bfa, event);
4173 }
4174}
4175
Jing Huang5fbe25c2010-10-18 17:17:23 -07004176/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004177 * Online state - normal parking state.
4178 */
4179static void
4180bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
4181{
4182 struct bfi_rport_qos_scn_s *qos_scn;
4183
4184 bfa_trc(rp->bfa, rp->rport_tag);
4185 bfa_trc(rp->bfa, event);
4186
4187 switch (event) {
4188 case BFA_RPORT_SM_OFFLINE:
4189 bfa_stats(rp, sm_on_off);
4190 if (bfa_rport_send_fwdelete(rp))
4191 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4192 else
4193 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4194 break;
4195
4196 case BFA_RPORT_SM_DELETE:
4197 bfa_stats(rp, sm_on_del);
4198 if (bfa_rport_send_fwdelete(rp))
4199 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4200 else
4201 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4202 break;
4203
4204 case BFA_RPORT_SM_HWFAIL:
4205 bfa_stats(rp, sm_on_hwf);
4206 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4207 break;
4208
4209 case BFA_RPORT_SM_SET_SPEED:
4210 bfa_rport_send_fwspeed(rp);
4211 break;
4212
4213 case BFA_RPORT_SM_QOS_SCN:
4214 qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
4215 rp->qos_attr = qos_scn->new_qos_attr;
4216 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
4217 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
4218 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
4219 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
4220
4221 qos_scn->old_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004222 be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004223 qos_scn->new_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004224 be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004225
4226 if (qos_scn->old_qos_attr.qos_flow_id !=
4227 qos_scn->new_qos_attr.qos_flow_id)
4228 bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
4229 qos_scn->old_qos_attr,
4230 qos_scn->new_qos_attr);
4231 if (qos_scn->old_qos_attr.qos_priority !=
4232 qos_scn->new_qos_attr.qos_priority)
4233 bfa_cb_rport_qos_scn_prio(rp->rport_drv,
4234 qos_scn->old_qos_attr,
4235 qos_scn->new_qos_attr);
4236 break;
4237
4238 default:
4239 bfa_stats(rp, sm_on_unexp);
4240 bfa_sm_fault(rp->bfa, event);
4241 }
4242}
4243
Jing Huang5fbe25c2010-10-18 17:17:23 -07004244/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004245 * Firmware rport is being deleted - awaiting f/w response.
4246 */
4247static void
4248bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
4249{
4250 bfa_trc(rp->bfa, rp->rport_tag);
4251 bfa_trc(rp->bfa, event);
4252
4253 switch (event) {
4254 case BFA_RPORT_SM_FWRSP:
4255 bfa_stats(rp, sm_fwd_rsp);
4256 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4257 bfa_rport_offline_cb(rp);
4258 break;
4259
4260 case BFA_RPORT_SM_DELETE:
4261 bfa_stats(rp, sm_fwd_del);
4262 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4263 break;
4264
4265 case BFA_RPORT_SM_HWFAIL:
4266 bfa_stats(rp, sm_fwd_hwf);
4267 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4268 bfa_rport_offline_cb(rp);
4269 break;
4270
4271 default:
4272 bfa_stats(rp, sm_fwd_unexp);
4273 bfa_sm_fault(rp->bfa, event);
4274 }
4275}
4276
4277static void
4278bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4279{
4280 bfa_trc(rp->bfa, rp->rport_tag);
4281 bfa_trc(rp->bfa, event);
4282
4283 switch (event) {
4284 case BFA_RPORT_SM_QRESUME:
4285 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4286 bfa_rport_send_fwdelete(rp);
4287 break;
4288
4289 case BFA_RPORT_SM_DELETE:
4290 bfa_stats(rp, sm_fwd_del);
4291 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4292 break;
4293
4294 case BFA_RPORT_SM_HWFAIL:
4295 bfa_stats(rp, sm_fwd_hwf);
4296 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4297 bfa_reqq_wcancel(&rp->reqq_wait);
4298 bfa_rport_offline_cb(rp);
4299 break;
4300
4301 default:
4302 bfa_stats(rp, sm_fwd_unexp);
4303 bfa_sm_fault(rp->bfa, event);
4304 }
4305}
4306
Jing Huang5fbe25c2010-10-18 17:17:23 -07004307/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004308 * Offline state.
4309 */
4310static void
4311bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
4312{
4313 bfa_trc(rp->bfa, rp->rport_tag);
4314 bfa_trc(rp->bfa, event);
4315
4316 switch (event) {
4317 case BFA_RPORT_SM_DELETE:
4318 bfa_stats(rp, sm_off_del);
4319 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4320 bfa_rport_free(rp);
4321 break;
4322
4323 case BFA_RPORT_SM_ONLINE:
4324 bfa_stats(rp, sm_off_on);
4325 if (bfa_rport_send_fwcreate(rp))
4326 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4327 else
4328 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4329 break;
4330
4331 case BFA_RPORT_SM_HWFAIL:
4332 bfa_stats(rp, sm_off_hwf);
4333 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4334 break;
4335
Krishna Gudipati61ba4392012-08-22 19:52:58 -07004336 case BFA_RPORT_SM_OFFLINE:
4337 bfa_rport_offline_cb(rp);
4338 break;
4339
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004340 default:
4341 bfa_stats(rp, sm_off_unexp);
4342 bfa_sm_fault(rp->bfa, event);
4343 }
4344}
4345
Jing Huang5fbe25c2010-10-18 17:17:23 -07004346/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004347 * Rport is deleted, waiting for firmware response to delete.
4348 */
4349static void
4350bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
4351{
4352 bfa_trc(rp->bfa, rp->rport_tag);
4353 bfa_trc(rp->bfa, event);
4354
4355 switch (event) {
4356 case BFA_RPORT_SM_FWRSP:
4357 bfa_stats(rp, sm_del_fwrsp);
4358 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4359 bfa_rport_free(rp);
4360 break;
4361
4362 case BFA_RPORT_SM_HWFAIL:
4363 bfa_stats(rp, sm_del_hwf);
4364 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4365 bfa_rport_free(rp);
4366 break;
4367
4368 default:
4369 bfa_sm_fault(rp->bfa, event);
4370 }
4371}
4372
4373static void
4374bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4375{
4376 bfa_trc(rp->bfa, rp->rport_tag);
4377 bfa_trc(rp->bfa, event);
4378
4379 switch (event) {
4380 case BFA_RPORT_SM_QRESUME:
4381 bfa_stats(rp, sm_del_fwrsp);
4382 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4383 bfa_rport_send_fwdelete(rp);
4384 break;
4385
4386 case BFA_RPORT_SM_HWFAIL:
4387 bfa_stats(rp, sm_del_hwf);
4388 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4389 bfa_reqq_wcancel(&rp->reqq_wait);
4390 bfa_rport_free(rp);
4391 break;
4392
4393 default:
4394 bfa_sm_fault(rp->bfa, event);
4395 }
4396}
4397
Jing Huang5fbe25c2010-10-18 17:17:23 -07004398/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004399 * Waiting for rport create response from firmware. A delete is pending.
4400 */
4401static void
4402bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
4403 enum bfa_rport_event event)
4404{
4405 bfa_trc(rp->bfa, rp->rport_tag);
4406 bfa_trc(rp->bfa, event);
4407
4408 switch (event) {
4409 case BFA_RPORT_SM_FWRSP:
4410 bfa_stats(rp, sm_delp_fwrsp);
4411 if (bfa_rport_send_fwdelete(rp))
4412 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4413 else
4414 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4415 break;
4416
4417 case BFA_RPORT_SM_HWFAIL:
4418 bfa_stats(rp, sm_delp_hwf);
4419 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4420 bfa_rport_free(rp);
4421 break;
4422
4423 default:
4424 bfa_stats(rp, sm_delp_unexp);
4425 bfa_sm_fault(rp->bfa, event);
4426 }
4427}
4428
Jing Huang5fbe25c2010-10-18 17:17:23 -07004429/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004430 * Waiting for rport create response from firmware. Rport offline is pending.
4431 */
4432static void
4433bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
4434 enum bfa_rport_event event)
4435{
4436 bfa_trc(rp->bfa, rp->rport_tag);
4437 bfa_trc(rp->bfa, event);
4438
4439 switch (event) {
4440 case BFA_RPORT_SM_FWRSP:
4441 bfa_stats(rp, sm_offp_fwrsp);
4442 if (bfa_rport_send_fwdelete(rp))
4443 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4444 else
4445 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4446 break;
4447
4448 case BFA_RPORT_SM_DELETE:
4449 bfa_stats(rp, sm_offp_del);
4450 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4451 break;
4452
4453 case BFA_RPORT_SM_HWFAIL:
4454 bfa_stats(rp, sm_offp_hwf);
4455 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07004456 bfa_rport_offline_cb(rp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004457 break;
4458
4459 default:
4460 bfa_stats(rp, sm_offp_unexp);
4461 bfa_sm_fault(rp->bfa, event);
4462 }
4463}
4464
Jing Huang5fbe25c2010-10-18 17:17:23 -07004465/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004466 * IOC h/w failed.
4467 */
4468static void
4469bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
4470{
4471 bfa_trc(rp->bfa, rp->rport_tag);
4472 bfa_trc(rp->bfa, event);
4473
4474 switch (event) {
4475 case BFA_RPORT_SM_OFFLINE:
4476 bfa_stats(rp, sm_iocd_off);
4477 bfa_rport_offline_cb(rp);
4478 break;
4479
4480 case BFA_RPORT_SM_DELETE:
4481 bfa_stats(rp, sm_iocd_del);
4482 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4483 bfa_rport_free(rp);
4484 break;
4485
4486 case BFA_RPORT_SM_ONLINE:
4487 bfa_stats(rp, sm_iocd_on);
4488 if (bfa_rport_send_fwcreate(rp))
4489 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4490 else
4491 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4492 break;
4493
4494 case BFA_RPORT_SM_HWFAIL:
4495 break;
4496
4497 default:
4498 bfa_stats(rp, sm_iocd_unexp);
4499 bfa_sm_fault(rp->bfa, event);
4500 }
4501}
4502
4503
4504
Jing Huang5fbe25c2010-10-18 17:17:23 -07004505/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004506 * bfa_rport_private BFA rport private functions
4507 */
4508
4509static void
4510__bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
4511{
4512 struct bfa_rport_s *rp = cbarg;
4513
4514 if (complete)
4515 bfa_cb_rport_online(rp->rport_drv);
4516}
4517
4518static void
4519__bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
4520{
4521 struct bfa_rport_s *rp = cbarg;
4522
4523 if (complete)
4524 bfa_cb_rport_offline(rp->rport_drv);
4525}
4526
4527static void
4528bfa_rport_qresume(void *cbarg)
4529{
4530 struct bfa_rport_s *rp = cbarg;
4531
4532 bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
4533}
4534
4535static void
Krishna Gudipati45070252011-06-24 20:24:29 -07004536bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
4537 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004538{
Krishna Gudipati45070252011-06-24 20:24:29 -07004539 struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa);
4540
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004541 if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
4542 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
4543
Krishna Gudipati45070252011-06-24 20:24:29 -07004544 /* kva memory */
4545 bfa_mem_kva_setup(minfo, rport_kva,
4546 cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004547}
4548
4549static void
4550bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07004551 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004552{
4553 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4554 struct bfa_rport_s *rp;
4555 u16 i;
4556
4557 INIT_LIST_HEAD(&mod->rp_free_q);
4558 INIT_LIST_HEAD(&mod->rp_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004559 INIT_LIST_HEAD(&mod->rp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004560
Krishna Gudipati45070252011-06-24 20:24:29 -07004561 rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004562 mod->rps_list = rp;
4563 mod->num_rports = cfg->fwcfg.num_rports;
4564
Jing Huangd4b671c2010-12-26 21:46:35 -08004565 WARN_ON(!mod->num_rports ||
4566 (mod->num_rports & (mod->num_rports - 1)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004567
4568 for (i = 0; i < mod->num_rports; i++, rp++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004569 memset(rp, 0, sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004570 rp->bfa = bfa;
4571 rp->rport_tag = i;
4572 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4573
Jing Huang5fbe25c2010-10-18 17:17:23 -07004574 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004575 * - is unused
4576 */
4577 if (i)
4578 list_add_tail(&rp->qe, &mod->rp_free_q);
4579
4580 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
4581 }
4582
Jing Huang5fbe25c2010-10-18 17:17:23 -07004583 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004584 * consume memory
4585 */
Krishna Gudipati45070252011-06-24 20:24:29 -07004586 bfa_mem_kva_curp(mod) = (u8 *) rp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004587}
4588
4589static void
4590bfa_rport_detach(struct bfa_s *bfa)
4591{
4592}
4593
4594static void
4595bfa_rport_start(struct bfa_s *bfa)
4596{
4597}
4598
4599static void
4600bfa_rport_stop(struct bfa_s *bfa)
4601{
4602}
4603
4604static void
4605bfa_rport_iocdisable(struct bfa_s *bfa)
4606{
4607 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4608 struct bfa_rport_s *rport;
4609 struct list_head *qe, *qen;
4610
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004611 /* Enqueue unused rport resources to free_q */
4612 list_splice_tail_init(&mod->rp_unused_q, &mod->rp_free_q);
4613
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004614 list_for_each_safe(qe, qen, &mod->rp_active_q) {
4615 rport = (struct bfa_rport_s *) qe;
4616 bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
4617 }
4618}
4619
4620static struct bfa_rport_s *
4621bfa_rport_alloc(struct bfa_rport_mod_s *mod)
4622{
4623 struct bfa_rport_s *rport;
4624
4625 bfa_q_deq(&mod->rp_free_q, &rport);
4626 if (rport)
4627 list_add_tail(&rport->qe, &mod->rp_active_q);
4628
4629 return rport;
4630}
4631
4632static void
4633bfa_rport_free(struct bfa_rport_s *rport)
4634{
4635 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
4636
Jing Huangd4b671c2010-12-26 21:46:35 -08004637 WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004638 list_del(&rport->qe);
4639 list_add_tail(&rport->qe, &mod->rp_free_q);
4640}
4641
4642static bfa_boolean_t
4643bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4644{
4645 struct bfi_rport_create_req_s *m;
4646
Jing Huang5fbe25c2010-10-18 17:17:23 -07004647 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004648 * check for room in queue to send request now
4649 */
4650 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4651 if (!m) {
4652 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4653 return BFA_FALSE;
4654 }
4655
4656 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004657 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004658 m->bfa_handle = rp->rport_tag;
Jing Huangba816ea2010-10-18 17:10:50 -07004659 m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004660 m->pid = rp->rport_info.pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004661 m->lp_fwtag = bfa_lps_get_fwtag(rp->bfa, (u8)rp->rport_info.lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004662 m->local_pid = rp->rport_info.local_pid;
4663 m->fc_class = rp->rport_info.fc_class;
4664 m->vf_en = rp->rport_info.vf_en;
4665 m->vf_id = rp->rport_info.vf_id;
4666 m->cisc = rp->rport_info.cisc;
4667
Jing Huang5fbe25c2010-10-18 17:17:23 -07004668 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004669 * queue I/O message to firmware
4670 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004671 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004672 return BFA_TRUE;
4673}
4674
4675static bfa_boolean_t
4676bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4677{
4678 struct bfi_rport_delete_req_s *m;
4679
Jing Huang5fbe25c2010-10-18 17:17:23 -07004680 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004681 * check for room in queue to send request now
4682 */
4683 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4684 if (!m) {
4685 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4686 return BFA_FALSE;
4687 }
4688
4689 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004690 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004691 m->fw_handle = rp->fw_handle;
4692
Jing Huang5fbe25c2010-10-18 17:17:23 -07004693 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004694 * queue I/O message to firmware
4695 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004696 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004697 return BFA_TRUE;
4698}
4699
4700static bfa_boolean_t
4701bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4702{
4703 struct bfa_rport_speed_req_s *m;
4704
Jing Huang5fbe25c2010-10-18 17:17:23 -07004705 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004706 * check for room in queue to send request now
4707 */
4708 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4709 if (!m) {
4710 bfa_trc(rp->bfa, rp->rport_info.speed);
4711 return BFA_FALSE;
4712 }
4713
4714 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004715 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004716 m->fw_handle = rp->fw_handle;
4717 m->speed = (u8)rp->rport_info.speed;
4718
Jing Huang5fbe25c2010-10-18 17:17:23 -07004719 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004720 * queue I/O message to firmware
4721 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004722 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004723 return BFA_TRUE;
4724}
4725
4726
4727
Jing Huang5fbe25c2010-10-18 17:17:23 -07004728/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004729 * bfa_rport_public
4730 */
4731
Jing Huang5fbe25c2010-10-18 17:17:23 -07004732/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004733 * Rport interrupt processing.
4734 */
4735void
4736bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
4737{
4738 union bfi_rport_i2h_msg_u msg;
4739 struct bfa_rport_s *rp;
4740
4741 bfa_trc(bfa, m->mhdr.msg_id);
4742
4743 msg.msg = m;
4744
4745 switch (m->mhdr.msg_id) {
4746 case BFI_RPORT_I2H_CREATE_RSP:
4747 rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
4748 rp->fw_handle = msg.create_rsp->fw_handle;
4749 rp->qos_attr = msg.create_rsp->qos_attr;
Krishna Gudipati83763d52011-07-20 17:04:03 -07004750 bfa_rport_set_lunmask(bfa, rp);
Jing Huangd4b671c2010-12-26 21:46:35 -08004751 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004752 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4753 break;
4754
4755 case BFI_RPORT_I2H_DELETE_RSP:
4756 rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08004757 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
Krishna Gudipati83763d52011-07-20 17:04:03 -07004758 bfa_rport_unset_lunmask(bfa, rp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004759 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4760 break;
4761
4762 case BFI_RPORT_I2H_QOS_SCN:
4763 rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
4764 rp->event_arg.fw_msg = msg.qos_scn_evt;
4765 bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
4766 break;
4767
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07004768 case BFI_RPORT_I2H_LIP_SCN_ONLINE:
4769 bfa_fcport_update_loop_info(BFA_FCPORT_MOD(bfa),
4770 &msg.lip_scn->loop_info);
4771 bfa_cb_rport_scn_online(bfa);
4772 break;
4773
4774 case BFI_RPORT_I2H_LIP_SCN_OFFLINE:
4775 bfa_cb_rport_scn_offline(bfa);
4776 break;
4777
4778 case BFI_RPORT_I2H_NO_DEV:
4779 rp = BFA_RPORT_FROM_TAG(bfa, msg.lip_scn->bfa_handle);
4780 bfa_cb_rport_scn_no_dev(rp->rport_drv);
4781 break;
4782
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004783 default:
4784 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08004785 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004786 }
4787}
4788
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004789void
4790bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw)
4791{
4792 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4793 struct list_head *qe;
4794 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004795
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004796 for (i = 0; i < (mod->num_rports - num_rport_fw); i++) {
4797 bfa_q_deq_tail(&mod->rp_free_q, &qe);
4798 list_add_tail(qe, &mod->rp_unused_q);
4799 }
4800}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004801
Jing Huang5fbe25c2010-10-18 17:17:23 -07004802/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004803 * bfa_rport_api
4804 */
4805
4806struct bfa_rport_s *
4807bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
4808{
4809 struct bfa_rport_s *rp;
4810
4811 rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
4812
4813 if (rp == NULL)
4814 return NULL;
4815
4816 rp->bfa = bfa;
4817 rp->rport_drv = rport_drv;
Maggie Zhangf7f738122010-12-09 19:08:43 -08004818 memset(&rp->stats, 0, sizeof(rp->stats));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004819
Jing Huangd4b671c2010-12-26 21:46:35 -08004820 WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004821 bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
4822
4823 return rp;
4824}
4825
4826void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004827bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
4828{
Jing Huangd4b671c2010-12-26 21:46:35 -08004829 WARN_ON(rport_info->max_frmsz == 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004830
Jing Huang5fbe25c2010-10-18 17:17:23 -07004831 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004832 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
4833 * responses. Default to minimum size.
4834 */
4835 if (rport_info->max_frmsz == 0) {
4836 bfa_trc(rport->bfa, rport->rport_tag);
4837 rport_info->max_frmsz = FC_MIN_PDUSZ;
4838 }
4839
Jing Huang6a18b162010-10-18 17:08:54 -07004840 rport->rport_info = *rport_info;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004841 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
4842}
4843
4844void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004845bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
4846{
Jing Huangd4b671c2010-12-26 21:46:35 -08004847 WARN_ON(speed == 0);
4848 WARN_ON(speed == BFA_PORT_SPEED_AUTO);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004849
Krishna Gudipati61ba4392012-08-22 19:52:58 -07004850 if (rport) {
4851 rport->rport_info.speed = speed;
4852 bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
4853 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004854}
4855
Krishna Gudipati83763d52011-07-20 17:04:03 -07004856/* Set Rport LUN Mask */
4857void
4858bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
4859{
4860 struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
4861 wwn_t lp_wwn, rp_wwn;
4862 u8 lp_tag = (u8)rp->rport_info.lp_tag;
4863
4864 rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
4865 lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
4866
4867 BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
4868 rp->lun_mask = BFA_TRUE;
4869 bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn, rp->rport_tag, lp_tag);
4870}
4871
4872/* Unset Rport LUN mask */
4873void
4874bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
4875{
4876 struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
4877 wwn_t lp_wwn, rp_wwn;
4878
4879 rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
4880 lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
4881
4882 BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
4883 rp->lun_mask = BFA_FALSE;
4884 bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn,
4885 BFA_RPORT_TAG_INVALID, BFA_LP_TAG_INVALID);
4886}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004887
Jing Huang5fbe25c2010-10-18 17:17:23 -07004888/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004889 * SGPG related functions
4890 */
4891
Jing Huang5fbe25c2010-10-18 17:17:23 -07004892/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004893 * Compute and return memory needed by FCP(im) module.
4894 */
4895static void
Krishna Gudipati45070252011-06-24 20:24:29 -07004896bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
4897 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004898{
Krishna Gudipati45070252011-06-24 20:24:29 -07004899 struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa);
4900 struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa);
4901 struct bfa_mem_dma_s *seg_ptr;
4902 u16 nsegs, idx, per_seg_sgpg, num_sgpg;
4903 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
4904
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004905 if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
4906 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
Krishna Gudipati45070252011-06-24 20:24:29 -07004907 else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX)
4908 cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004909
Krishna Gudipati45070252011-06-24 20:24:29 -07004910 num_sgpg = cfg->drvcfg.num_sgpgs;
4911
4912 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
4913 per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz);
4914
4915 bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) {
4916 if (num_sgpg >= per_seg_sgpg) {
4917 num_sgpg -= per_seg_sgpg;
4918 bfa_mem_dma_setup(minfo, seg_ptr,
4919 per_seg_sgpg * sgpg_sz);
4920 } else
4921 bfa_mem_dma_setup(minfo, seg_ptr,
4922 num_sgpg * sgpg_sz);
4923 }
4924
4925 /* kva memory */
4926 bfa_mem_kva_setup(minfo, sgpg_kva,
4927 cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004928}
4929
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004930static void
4931bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07004932 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004933{
4934 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004935 struct bfa_sgpg_s *hsgpg;
4936 struct bfi_sgpg_s *sgpg;
4937 u64 align_len;
Krishna Gudipati45070252011-06-24 20:24:29 -07004938 struct bfa_mem_dma_s *seg_ptr;
4939 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
4940 u16 i, idx, nsegs, per_seg_sgpg, num_sgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004941
4942 union {
4943 u64 pa;
4944 union bfi_addr_u addr;
4945 } sgpg_pa, sgpg_pa_tmp;
4946
4947 INIT_LIST_HEAD(&mod->sgpg_q);
4948 INIT_LIST_HEAD(&mod->sgpg_wait_q);
4949
4950 bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
4951
Krishna Gudipati45070252011-06-24 20:24:29 -07004952 mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004953
Krishna Gudipati45070252011-06-24 20:24:29 -07004954 num_sgpg = cfg->drvcfg.num_sgpgs;
4955 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004956
Krishna Gudipati45070252011-06-24 20:24:29 -07004957 /* dma/kva mem claim */
4958 hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004959
Krishna Gudipati45070252011-06-24 20:24:29 -07004960 bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004961
Krishna Gudipati45070252011-06-24 20:24:29 -07004962 if (!bfa_mem_dma_virt(seg_ptr))
4963 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004964
Krishna Gudipati45070252011-06-24 20:24:29 -07004965 align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) -
4966 bfa_mem_dma_phys(seg_ptr);
4967
4968 sgpg = (struct bfi_sgpg_s *)
4969 (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len);
4970 sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len;
4971 WARN_ON(sgpg_pa.pa & (sgpg_sz - 1));
4972
4973 per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz;
4974
4975 for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) {
4976 memset(hsgpg, 0, sizeof(*hsgpg));
4977 memset(sgpg, 0, sizeof(*sgpg));
4978
4979 hsgpg->sgpg = sgpg;
4980 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
4981 hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
4982 list_add_tail(&hsgpg->qe, &mod->sgpg_q);
4983
4984 sgpg++;
4985 hsgpg++;
4986 sgpg_pa.pa += sgpg_sz;
4987 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004988 }
4989
Krishna Gudipati45070252011-06-24 20:24:29 -07004990 bfa_mem_kva_curp(mod) = (u8 *) hsgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004991}
4992
4993static void
4994bfa_sgpg_detach(struct bfa_s *bfa)
4995{
4996}
4997
4998static void
4999bfa_sgpg_start(struct bfa_s *bfa)
5000{
5001}
5002
5003static void
5004bfa_sgpg_stop(struct bfa_s *bfa)
5005{
5006}
5007
5008static void
5009bfa_sgpg_iocdisable(struct bfa_s *bfa)
5010{
5011}
5012
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005013bfa_status_t
5014bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
5015{
5016 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5017 struct bfa_sgpg_s *hsgpg;
5018 int i;
5019
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005020 if (mod->free_sgpgs < nsgpgs)
5021 return BFA_STATUS_ENOMEM;
5022
5023 for (i = 0; i < nsgpgs; i++) {
5024 bfa_q_deq(&mod->sgpg_q, &hsgpg);
Jing Huangd4b671c2010-12-26 21:46:35 -08005025 WARN_ON(!hsgpg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005026 list_add_tail(&hsgpg->qe, sgpg_q);
5027 }
5028
5029 mod->free_sgpgs -= nsgpgs;
5030 return BFA_STATUS_OK;
5031}
5032
5033void
5034bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
5035{
5036 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5037 struct bfa_sgpg_wqe_s *wqe;
5038
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005039 mod->free_sgpgs += nsgpg;
Jing Huangd4b671c2010-12-26 21:46:35 -08005040 WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005041
5042 list_splice_tail_init(sgpg_q, &mod->sgpg_q);
5043
5044 if (list_empty(&mod->sgpg_wait_q))
5045 return;
5046
Jing Huang5fbe25c2010-10-18 17:17:23 -07005047 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005048 * satisfy as many waiting requests as possible
5049 */
5050 do {
5051 wqe = bfa_q_first(&mod->sgpg_wait_q);
5052 if (mod->free_sgpgs < wqe->nsgpg)
5053 nsgpg = mod->free_sgpgs;
5054 else
5055 nsgpg = wqe->nsgpg;
5056 bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
5057 wqe->nsgpg -= nsgpg;
5058 if (wqe->nsgpg == 0) {
5059 list_del(&wqe->qe);
5060 wqe->cbfn(wqe->cbarg);
5061 }
5062 } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
5063}
5064
5065void
5066bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
5067{
5068 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5069
Jing Huangd4b671c2010-12-26 21:46:35 -08005070 WARN_ON(nsgpg <= 0);
5071 WARN_ON(nsgpg <= mod->free_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005072
5073 wqe->nsgpg_total = wqe->nsgpg = nsgpg;
5074
Jing Huang5fbe25c2010-10-18 17:17:23 -07005075 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005076 * allocate any left to this one first
5077 */
5078 if (mod->free_sgpgs) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07005079 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005080 * no one else is waiting for SGPG
5081 */
Jing Huangd4b671c2010-12-26 21:46:35 -08005082 WARN_ON(!list_empty(&mod->sgpg_wait_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005083 list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
5084 wqe->nsgpg -= mod->free_sgpgs;
5085 mod->free_sgpgs = 0;
5086 }
5087
5088 list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
5089}
5090
5091void
5092bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
5093{
5094 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5095
Jing Huangd4b671c2010-12-26 21:46:35 -08005096 WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005097 list_del(&wqe->qe);
5098
5099 if (wqe->nsgpg_total != wqe->nsgpg)
5100 bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
5101 wqe->nsgpg_total - wqe->nsgpg);
5102}
5103
5104void
5105bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
5106 void *cbarg)
5107{
5108 INIT_LIST_HEAD(&wqe->sgpg_q);
5109 wqe->cbfn = cbfn;
5110 wqe->cbarg = cbarg;
5111}
5112
Jing Huang5fbe25c2010-10-18 17:17:23 -07005113/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005114 * UF related functions
5115 */
5116/*
5117 *****************************************************************************
5118 * Internal functions
5119 *****************************************************************************
5120 */
5121static void
5122__bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
5123{
5124 struct bfa_uf_s *uf = cbarg;
5125 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
5126
5127 if (complete)
5128 ufm->ufrecv(ufm->cbarg, uf);
5129}
5130
5131static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005132claim_uf_post_msgs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005133{
5134 struct bfi_uf_buf_post_s *uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005135 u16 i;
5136 u16 buf_len;
5137
Krishna Gudipati45070252011-06-24 20:24:29 -07005138 ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005139 uf_bp_msg = ufm->uf_buf_posts;
5140
5141 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
5142 i++, uf_bp_msg++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005143 memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005144
5145 uf_bp_msg->buf_tag = i;
5146 buf_len = sizeof(struct bfa_uf_buf_s);
Jing Huangba816ea2010-10-18 17:10:50 -07005147 uf_bp_msg->buf_len = cpu_to_be16(buf_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005148 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005149 bfa_fn_lpu(ufm->bfa));
Krishna Gudipati85ce9282011-06-13 15:39:36 -07005150 bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005151 }
5152
Jing Huang5fbe25c2010-10-18 17:17:23 -07005153 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005154 * advance pointer beyond consumed memory
5155 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005156 bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005157}
5158
5159static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005160claim_ufs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005161{
5162 u16 i;
5163 struct bfa_uf_s *uf;
5164
5165 /*
5166 * Claim block of memory for UF list
5167 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005168 ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005169
5170 /*
5171 * Initialize UFs and queue it in UF free queue
5172 */
5173 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005174 memset(uf, 0, sizeof(struct bfa_uf_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005175 uf->bfa = ufm->bfa;
5176 uf->uf_tag = i;
Krishna Gudipati45070252011-06-24 20:24:29 -07005177 uf->pb_len = BFA_PER_UF_DMA_SZ;
5178 uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005179 uf->buf_pa = ufm_pbs_pa(ufm, i);
5180 list_add_tail(&uf->qe, &ufm->uf_free_q);
5181 }
5182
Jing Huang5fbe25c2010-10-18 17:17:23 -07005183 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005184 * advance memory pointer
5185 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005186 bfa_mem_kva_curp(ufm) = (u8 *) uf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005187}
5188
5189static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005190uf_mem_claim(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005191{
Krishna Gudipati45070252011-06-24 20:24:29 -07005192 claim_ufs(ufm);
5193 claim_uf_post_msgs(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005194}
5195
5196static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005197bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
5198 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005199{
Krishna Gudipati45070252011-06-24 20:24:29 -07005200 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5201 struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa);
5202 u32 num_ufs = cfg->fwcfg.num_uf_bufs;
5203 struct bfa_mem_dma_s *seg_ptr;
5204 u16 nsegs, idx, per_seg_uf = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005205
Krishna Gudipati45070252011-06-24 20:24:29 -07005206 nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ);
5207 per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005208
Krishna Gudipati45070252011-06-24 20:24:29 -07005209 bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) {
5210 if (num_ufs >= per_seg_uf) {
5211 num_ufs -= per_seg_uf;
5212 bfa_mem_dma_setup(minfo, seg_ptr,
5213 per_seg_uf * BFA_PER_UF_DMA_SZ);
5214 } else
5215 bfa_mem_dma_setup(minfo, seg_ptr,
5216 num_ufs * BFA_PER_UF_DMA_SZ);
5217 }
5218
5219 /* kva memory */
5220 bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs *
5221 (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005222}
5223
5224static void
5225bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07005226 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005227{
5228 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5229
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005230 ufm->bfa = bfa;
5231 ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
5232 INIT_LIST_HEAD(&ufm->uf_free_q);
5233 INIT_LIST_HEAD(&ufm->uf_posted_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005234 INIT_LIST_HEAD(&ufm->uf_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005235
Krishna Gudipati45070252011-06-24 20:24:29 -07005236 uf_mem_claim(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005237}
5238
5239static void
5240bfa_uf_detach(struct bfa_s *bfa)
5241{
5242}
5243
5244static struct bfa_uf_s *
5245bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
5246{
5247 struct bfa_uf_s *uf;
5248
5249 bfa_q_deq(&uf_mod->uf_free_q, &uf);
5250 return uf;
5251}
5252
5253static void
5254bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
5255{
5256 list_add_tail(&uf->qe, &uf_mod->uf_free_q);
5257}
5258
5259static bfa_status_t
5260bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
5261{
5262 struct bfi_uf_buf_post_s *uf_post_msg;
5263
5264 uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
5265 if (!uf_post_msg)
5266 return BFA_STATUS_FAILED;
5267
Jing Huang6a18b162010-10-18 17:08:54 -07005268 memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005269 sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005270 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP, uf_post_msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005271
5272 bfa_trc(ufm->bfa, uf->uf_tag);
5273
5274 list_add_tail(&uf->qe, &ufm->uf_posted_q);
5275 return BFA_STATUS_OK;
5276}
5277
5278static void
5279bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
5280{
5281 struct bfa_uf_s *uf;
5282
5283 while ((uf = bfa_uf_get(uf_mod)) != NULL) {
5284 if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
5285 break;
5286 }
5287}
5288
5289static void
5290uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
5291{
5292 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5293 u16 uf_tag = m->buf_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005294 struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
Krishna Gudipati45070252011-06-24 20:24:29 -07005295 struct bfa_uf_buf_s *uf_buf;
5296 uint8_t *buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005297 struct fchs_s *fchs;
5298
Krishna Gudipati45070252011-06-24 20:24:29 -07005299 uf_buf = (struct bfa_uf_buf_s *)
5300 bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len);
5301 buf = &uf_buf->d[0];
5302
Jing Huangba816ea2010-10-18 17:10:50 -07005303 m->frm_len = be16_to_cpu(m->frm_len);
5304 m->xfr_len = be16_to_cpu(m->xfr_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005305
5306 fchs = (struct fchs_s *)uf_buf;
5307
5308 list_del(&uf->qe); /* dequeue from posted queue */
5309
5310 uf->data_ptr = buf;
5311 uf->data_len = m->xfr_len;
5312
Jing Huangd4b671c2010-12-26 21:46:35 -08005313 WARN_ON(uf->data_len < sizeof(struct fchs_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005314
5315 if (uf->data_len == sizeof(struct fchs_s)) {
5316 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
5317 uf->data_len, (struct fchs_s *)buf);
5318 } else {
5319 u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
5320 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
5321 BFA_PL_EID_RX, uf->data_len,
5322 (struct fchs_s *)buf, pld_w0);
5323 }
5324
5325 if (bfa->fcs)
5326 __bfa_cb_uf_recv(uf, BFA_TRUE);
5327 else
5328 bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
5329}
5330
5331static void
5332bfa_uf_stop(struct bfa_s *bfa)
5333{
5334}
5335
5336static void
5337bfa_uf_iocdisable(struct bfa_s *bfa)
5338{
5339 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5340 struct bfa_uf_s *uf;
5341 struct list_head *qe, *qen;
5342
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005343 /* Enqueue unused uf resources to free_q */
5344 list_splice_tail_init(&ufm->uf_unused_q, &ufm->uf_free_q);
5345
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005346 list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
5347 uf = (struct bfa_uf_s *) qe;
5348 list_del(&uf->qe);
5349 bfa_uf_put(ufm, uf);
5350 }
5351}
5352
5353static void
5354bfa_uf_start(struct bfa_s *bfa)
5355{
5356 bfa_uf_post_all(BFA_UF_MOD(bfa));
5357}
5358
Jing Huang5fbe25c2010-10-18 17:17:23 -07005359/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005360 * Register handler for all unsolicted receive frames.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005361 *
5362 * @param[in] bfa BFA instance
5363 * @param[in] ufrecv receive handler function
5364 * @param[in] cbarg receive handler arg
5365 */
5366void
5367bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
5368{
5369 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5370
5371 ufm->ufrecv = ufrecv;
5372 ufm->cbarg = cbarg;
5373}
5374
Jing Huang5fbe25c2010-10-18 17:17:23 -07005375/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005376 * Free an unsolicited frame back to BFA.
5377 *
5378 * @param[in] uf unsolicited frame to be freed
5379 *
5380 * @return None
5381 */
5382void
5383bfa_uf_free(struct bfa_uf_s *uf)
5384{
5385 bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
5386 bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
5387}
5388
5389
5390
Jing Huang5fbe25c2010-10-18 17:17:23 -07005391/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005392 * uf_pub BFA uf module public functions
5393 */
5394void
5395bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5396{
5397 bfa_trc(bfa, msg->mhdr.msg_id);
5398
5399 switch (msg->mhdr.msg_id) {
5400 case BFI_UF_I2H_FRM_RCVD:
5401 uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
5402 break;
5403
5404 default:
5405 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08005406 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005407 }
5408}
5409
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005410void
5411bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw)
5412{
5413 struct bfa_uf_mod_s *mod = BFA_UF_MOD(bfa);
5414 struct list_head *qe;
5415 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005416
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005417 for (i = 0; i < (mod->num_ufs - num_uf_fw); i++) {
5418 bfa_q_deq_tail(&mod->uf_free_q, &qe);
5419 list_add_tail(qe, &mod->uf_unused_q);
5420 }
5421}
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005422
5423/*
5424 * BFA fcdiag module
5425 */
5426#define BFA_DIAG_QTEST_TOV 1000 /* msec */
5427
5428/*
5429 * Set port status to busy
5430 */
5431static void
5432bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s *fcdiag)
5433{
5434 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fcdiag->bfa);
5435
5436 if (fcdiag->lb.lock)
5437 fcport->diag_busy = BFA_TRUE;
5438 else
5439 fcport->diag_busy = BFA_FALSE;
5440}
5441
5442static void
5443bfa_fcdiag_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
5444 struct bfa_s *bfa)
5445{
5446}
5447
5448static void
5449bfa_fcdiag_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
5450 struct bfa_pcidev_s *pcidev)
5451{
5452 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5453 fcdiag->bfa = bfa;
5454 fcdiag->trcmod = bfa->trcmod;
5455 /* The common DIAG attach bfa_diag_attach() will do all memory claim */
5456}
5457
5458static void
5459bfa_fcdiag_iocdisable(struct bfa_s *bfa)
5460{
5461 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5462 bfa_trc(fcdiag, fcdiag->lb.lock);
5463 if (fcdiag->lb.lock) {
5464 fcdiag->lb.status = BFA_STATUS_IOC_FAILURE;
5465 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5466 fcdiag->lb.lock = 0;
5467 bfa_fcdiag_set_busy_status(fcdiag);
5468 }
5469}
5470
5471static void
5472bfa_fcdiag_detach(struct bfa_s *bfa)
5473{
5474}
5475
5476static void
5477bfa_fcdiag_start(struct bfa_s *bfa)
5478{
5479}
5480
5481static void
5482bfa_fcdiag_stop(struct bfa_s *bfa)
5483{
5484}
5485
5486static void
5487bfa_fcdiag_queuetest_timeout(void *cbarg)
5488{
5489 struct bfa_fcdiag_s *fcdiag = cbarg;
5490 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5491
5492 bfa_trc(fcdiag, fcdiag->qtest.all);
5493 bfa_trc(fcdiag, fcdiag->qtest.count);
5494
5495 fcdiag->qtest.timer_active = 0;
5496
5497 res->status = BFA_STATUS_ETIMER;
5498 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5499 if (fcdiag->qtest.all)
5500 res->queue = fcdiag->qtest.all;
5501
5502 bfa_trc(fcdiag, BFA_STATUS_ETIMER);
5503 fcdiag->qtest.status = BFA_STATUS_ETIMER;
5504 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5505 fcdiag->qtest.lock = 0;
5506}
5507
5508static bfa_status_t
5509bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s *fcdiag)
5510{
5511 u32 i;
5512 struct bfi_diag_qtest_req_s *req;
5513
5514 req = bfa_reqq_next(fcdiag->bfa, fcdiag->qtest.queue);
5515 if (!req)
5516 return BFA_STATUS_DEVBUSY;
5517
5518 /* build host command */
5519 bfi_h2i_set(req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_QTEST,
5520 bfa_fn_lpu(fcdiag->bfa));
5521
5522 for (i = 0; i < BFI_LMSG_PL_WSZ; i++)
5523 req->data[i] = QTEST_PAT_DEFAULT;
5524
5525 bfa_trc(fcdiag, fcdiag->qtest.queue);
5526 /* ring door bell */
5527 bfa_reqq_produce(fcdiag->bfa, fcdiag->qtest.queue, req->mh);
5528 return BFA_STATUS_OK;
5529}
5530
5531static void
5532bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s *fcdiag,
5533 bfi_diag_qtest_rsp_t *rsp)
5534{
5535 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5536 bfa_status_t status = BFA_STATUS_OK;
5537 int i;
5538
5539 /* Check timer, should still be active */
5540 if (!fcdiag->qtest.timer_active) {
5541 bfa_trc(fcdiag, fcdiag->qtest.timer_active);
5542 return;
5543 }
5544
5545 /* update count */
5546 fcdiag->qtest.count--;
5547
5548 /* Check result */
5549 for (i = 0; i < BFI_LMSG_PL_WSZ; i++) {
5550 if (rsp->data[i] != ~(QTEST_PAT_DEFAULT)) {
5551 res->status = BFA_STATUS_DATACORRUPTED;
5552 break;
5553 }
5554 }
5555
5556 if (res->status == BFA_STATUS_OK) {
5557 if (fcdiag->qtest.count > 0) {
5558 status = bfa_fcdiag_queuetest_send(fcdiag);
5559 if (status == BFA_STATUS_OK)
5560 return;
5561 else
5562 res->status = status;
5563 } else if (fcdiag->qtest.all > 0 &&
5564 fcdiag->qtest.queue < (BFI_IOC_MAX_CQS - 1)) {
5565 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
5566 fcdiag->qtest.queue++;
5567 status = bfa_fcdiag_queuetest_send(fcdiag);
5568 if (status == BFA_STATUS_OK)
5569 return;
5570 else
5571 res->status = status;
5572 }
5573 }
5574
5575 /* Stop timer when we comp all queue */
5576 if (fcdiag->qtest.timer_active) {
5577 bfa_timer_stop(&fcdiag->qtest.timer);
5578 fcdiag->qtest.timer_active = 0;
5579 }
5580 res->queue = fcdiag->qtest.queue;
5581 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5582 bfa_trc(fcdiag, res->count);
5583 bfa_trc(fcdiag, res->status);
5584 fcdiag->qtest.status = res->status;
5585 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5586 fcdiag->qtest.lock = 0;
5587}
5588
5589static void
5590bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s *fcdiag,
5591 struct bfi_diag_lb_rsp_s *rsp)
5592{
5593 struct bfa_diag_loopback_result_s *res = fcdiag->lb.result;
5594
5595 res->numtxmfrm = be32_to_cpu(rsp->res.numtxmfrm);
5596 res->numosffrm = be32_to_cpu(rsp->res.numosffrm);
5597 res->numrcvfrm = be32_to_cpu(rsp->res.numrcvfrm);
5598 res->badfrminf = be32_to_cpu(rsp->res.badfrminf);
5599 res->badfrmnum = be32_to_cpu(rsp->res.badfrmnum);
5600 res->status = rsp->res.status;
5601 fcdiag->lb.status = rsp->res.status;
5602 bfa_trc(fcdiag, fcdiag->lb.status);
5603 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5604 fcdiag->lb.lock = 0;
5605 bfa_fcdiag_set_busy_status(fcdiag);
5606}
5607
5608static bfa_status_t
5609bfa_fcdiag_loopback_send(struct bfa_fcdiag_s *fcdiag,
5610 struct bfa_diag_loopback_s *loopback)
5611{
5612 struct bfi_diag_lb_req_s *lb_req;
5613
5614 lb_req = bfa_reqq_next(fcdiag->bfa, BFA_REQQ_DIAG);
5615 if (!lb_req)
5616 return BFA_STATUS_DEVBUSY;
5617
5618 /* build host command */
5619 bfi_h2i_set(lb_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LOOPBACK,
5620 bfa_fn_lpu(fcdiag->bfa));
5621
5622 lb_req->lb_mode = loopback->lb_mode;
5623 lb_req->speed = loopback->speed;
5624 lb_req->loopcnt = loopback->loopcnt;
5625 lb_req->pattern = loopback->pattern;
5626
5627 /* ring door bell */
5628 bfa_reqq_produce(fcdiag->bfa, BFA_REQQ_DIAG, lb_req->mh);
5629
5630 bfa_trc(fcdiag, loopback->lb_mode);
5631 bfa_trc(fcdiag, loopback->speed);
5632 bfa_trc(fcdiag, loopback->loopcnt);
5633 bfa_trc(fcdiag, loopback->pattern);
5634 return BFA_STATUS_OK;
5635}
5636
5637/*
5638 * cpe/rme intr handler
5639 */
5640void
5641bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5642{
5643 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5644
5645 switch (msg->mhdr.msg_id) {
5646 case BFI_DIAG_I2H_LOOPBACK:
5647 bfa_fcdiag_loopback_comp(fcdiag,
5648 (struct bfi_diag_lb_rsp_s *) msg);
5649 break;
5650 case BFI_DIAG_I2H_QTEST:
5651 bfa_fcdiag_queuetest_comp(fcdiag, (bfi_diag_qtest_rsp_t *)msg);
5652 break;
5653 default:
5654 bfa_trc(fcdiag, msg->mhdr.msg_id);
5655 WARN_ON(1);
5656 }
5657}
5658
5659/*
5660 * Loopback test
5661 *
5662 * @param[in] *bfa - bfa data struct
5663 * @param[in] opmode - port operation mode
5664 * @param[in] speed - port speed
5665 * @param[in] lpcnt - loop count
5666 * @param[in] pat - pattern to build packet
5667 * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
5668 * @param[in] cbfn - callback function
5669 * @param[in] cbarg - callback functioin arg
5670 *
5671 * @param[out]
5672 */
5673bfa_status_t
5674bfa_fcdiag_loopback(struct bfa_s *bfa, enum bfa_port_opmode opmode,
5675 enum bfa_port_speed speed, u32 lpcnt, u32 pat,
5676 struct bfa_diag_loopback_result_s *result, bfa_cb_diag_t cbfn,
5677 void *cbarg)
5678{
5679 struct bfa_diag_loopback_s loopback;
5680 struct bfa_port_attr_s attr;
5681 bfa_status_t status;
5682 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5683
5684 if (!bfa_iocfc_is_operational(bfa))
5685 return BFA_STATUS_IOC_NON_OP;
5686
5687 /* if port is PBC disabled, return error */
5688 if (bfa_fcport_is_pbcdisabled(bfa)) {
5689 bfa_trc(fcdiag, BFA_STATUS_PBC);
5690 return BFA_STATUS_PBC;
5691 }
5692
5693 if (bfa_fcport_is_disabled(bfa) == BFA_FALSE) {
5694 bfa_trc(fcdiag, opmode);
5695 return BFA_STATUS_PORT_NOT_DISABLED;
5696 }
5697
Krishna Gudipatifb778b02011-07-20 17:01:07 -07005698 /*
5699 * Check if input speed is supported by the port mode
5700 */
5701 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
5702 if (!(speed == BFA_PORT_SPEED_1GBPS ||
5703 speed == BFA_PORT_SPEED_2GBPS ||
5704 speed == BFA_PORT_SPEED_4GBPS ||
5705 speed == BFA_PORT_SPEED_8GBPS ||
5706 speed == BFA_PORT_SPEED_16GBPS ||
5707 speed == BFA_PORT_SPEED_AUTO)) {
5708 bfa_trc(fcdiag, speed);
5709 return BFA_STATUS_UNSUPP_SPEED;
5710 }
5711 bfa_fcport_get_attr(bfa, &attr);
5712 bfa_trc(fcdiag, attr.speed_supported);
5713 if (speed > attr.speed_supported)
5714 return BFA_STATUS_UNSUPP_SPEED;
5715 } else {
5716 if (speed != BFA_PORT_SPEED_10GBPS) {
5717 bfa_trc(fcdiag, speed);
5718 return BFA_STATUS_UNSUPP_SPEED;
5719 }
5720 }
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005721
5722 /* For Mezz card, port speed entered needs to be checked */
5723 if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) {
5724 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
5725 if ((speed == BFA_PORT_SPEED_1GBPS) &&
5726 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
5727 return BFA_STATUS_UNSUPP_SPEED;
5728 if (!(speed == BFA_PORT_SPEED_1GBPS ||
5729 speed == BFA_PORT_SPEED_2GBPS ||
5730 speed == BFA_PORT_SPEED_4GBPS ||
5731 speed == BFA_PORT_SPEED_8GBPS ||
5732 speed == BFA_PORT_SPEED_16GBPS ||
5733 speed == BFA_PORT_SPEED_AUTO))
5734 return BFA_STATUS_UNSUPP_SPEED;
5735 } else {
5736 if (speed != BFA_PORT_SPEED_10GBPS)
5737 return BFA_STATUS_UNSUPP_SPEED;
5738 }
5739 }
5740
5741 /* check to see if there is another destructive diag cmd running */
5742 if (fcdiag->lb.lock) {
5743 bfa_trc(fcdiag, fcdiag->lb.lock);
5744 return BFA_STATUS_DEVBUSY;
5745 }
5746
5747 fcdiag->lb.lock = 1;
5748 loopback.lb_mode = opmode;
5749 loopback.speed = speed;
5750 loopback.loopcnt = lpcnt;
5751 loopback.pattern = pat;
5752 fcdiag->lb.result = result;
5753 fcdiag->lb.cbfn = cbfn;
5754 fcdiag->lb.cbarg = cbarg;
5755 memset(result, 0, sizeof(struct bfa_diag_loopback_result_s));
5756 bfa_fcdiag_set_busy_status(fcdiag);
5757
5758 /* Send msg to fw */
5759 status = bfa_fcdiag_loopback_send(fcdiag, &loopback);
5760 return status;
5761}
5762
5763/*
5764 * DIAG queue test command
5765 *
5766 * @param[in] *bfa - bfa data struct
5767 * @param[in] force - 1: don't do ioc op checking
5768 * @param[in] queue - queue no. to test
5769 * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
5770 * @param[in] cbfn - callback function
5771 * @param[in] *cbarg - callback functioin arg
5772 *
5773 * @param[out]
5774 */
5775bfa_status_t
5776bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 force, u32 queue,
5777 struct bfa_diag_qtest_result_s *result, bfa_cb_diag_t cbfn,
5778 void *cbarg)
5779{
5780 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5781 bfa_status_t status;
5782 bfa_trc(fcdiag, force);
5783 bfa_trc(fcdiag, queue);
5784
5785 if (!force && !bfa_iocfc_is_operational(bfa))
5786 return BFA_STATUS_IOC_NON_OP;
5787
5788 /* check to see if there is another destructive diag cmd running */
5789 if (fcdiag->qtest.lock) {
5790 bfa_trc(fcdiag, fcdiag->qtest.lock);
5791 return BFA_STATUS_DEVBUSY;
5792 }
5793
5794 /* Initialization */
5795 fcdiag->qtest.lock = 1;
5796 fcdiag->qtest.cbfn = cbfn;
5797 fcdiag->qtest.cbarg = cbarg;
5798 fcdiag->qtest.result = result;
5799 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
5800
5801 /* Init test results */
5802 fcdiag->qtest.result->status = BFA_STATUS_OK;
5803 fcdiag->qtest.result->count = 0;
5804
5805 /* send */
5806 if (queue < BFI_IOC_MAX_CQS) {
5807 fcdiag->qtest.result->queue = (u8)queue;
5808 fcdiag->qtest.queue = (u8)queue;
5809 fcdiag->qtest.all = 0;
5810 } else {
5811 fcdiag->qtest.result->queue = 0;
5812 fcdiag->qtest.queue = 0;
5813 fcdiag->qtest.all = 1;
5814 }
5815 status = bfa_fcdiag_queuetest_send(fcdiag);
5816
5817 /* Start a timer */
5818 if (status == BFA_STATUS_OK) {
5819 bfa_timer_start(bfa, &fcdiag->qtest.timer,
5820 bfa_fcdiag_queuetest_timeout, fcdiag,
5821 BFA_DIAG_QTEST_TOV);
5822 fcdiag->qtest.timer_active = 1;
5823 }
5824 return status;
5825}
5826
5827/*
5828 * DIAG PLB is running
5829 *
5830 * @param[in] *bfa - bfa data struct
5831 *
5832 * @param[out]
5833 */
5834bfa_status_t
5835bfa_fcdiag_lb_is_running(struct bfa_s *bfa)
5836{
5837 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5838 return fcdiag->lb.lock ? BFA_STATUS_DIAG_BUSY : BFA_STATUS_OK;
5839}