blob: 849eac95caed38acf293861a61d09bbd03df29b5 [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;
1247
1248 default:
1249 bfa_sm_fault(lps->bfa, event);
1250 }
1251}
1252
Jing Huang5fbe25c2010-10-18 17:17:23 -07001253/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001254 * login is in progress -- awaiting response from firmware
1255 */
1256static void
1257bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
1258{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001259 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001260 bfa_trc(lps->bfa, event);
1261
1262 switch (event) {
1263 case BFA_LPS_SM_FWRSP:
1264 if (lps->status == BFA_STATUS_OK) {
1265 bfa_sm_set_state(lps, bfa_lps_sm_online);
1266 if (lps->fdisc)
1267 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1268 BFA_PL_EID_LOGIN, 0, "FDISC Accept");
1269 else
1270 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1271 BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
Krishna Gudipatib7044952010-12-13 16:17:42 -08001272 /* If N2N, send the assigned PID to FW */
1273 bfa_trc(lps->bfa, lps->fport);
1274 bfa_trc(lps->bfa, lps->lp_pid);
1275
1276 if (!lps->fport && lps->lp_pid)
1277 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001278 } else {
1279 bfa_sm_set_state(lps, bfa_lps_sm_init);
1280 if (lps->fdisc)
1281 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1282 BFA_PL_EID_LOGIN, 0,
1283 "FDISC Fail (RJT or timeout)");
1284 else
1285 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1286 BFA_PL_EID_LOGIN, 0,
1287 "FLOGI Fail (RJT or timeout)");
1288 }
1289 bfa_lps_login_comp(lps);
1290 break;
1291
1292 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001293 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001294 bfa_sm_set_state(lps, bfa_lps_sm_init);
1295 break;
1296
Krishna Gudipatib7044952010-12-13 16:17:42 -08001297 case BFA_LPS_SM_SET_N2N_PID:
1298 bfa_trc(lps->bfa, lps->fport);
1299 bfa_trc(lps->bfa, lps->lp_pid);
1300 break;
1301
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001302 default:
1303 bfa_sm_fault(lps->bfa, event);
1304 }
1305}
1306
Jing Huang5fbe25c2010-10-18 17:17:23 -07001307/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001308 * login pending - awaiting space in request queue
1309 */
1310static void
1311bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1312{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001313 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001314 bfa_trc(lps->bfa, event);
1315
1316 switch (event) {
1317 case BFA_LPS_SM_RESUME:
1318 bfa_sm_set_state(lps, bfa_lps_sm_login);
Krishna Gudipatiff179e02012-03-13 17:40:31 -07001319 bfa_lps_send_login(lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001320 break;
1321
1322 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001323 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001324 bfa_sm_set_state(lps, bfa_lps_sm_init);
1325 bfa_reqq_wcancel(&lps->wqe);
1326 break;
1327
1328 case BFA_LPS_SM_RX_CVL:
1329 /*
1330 * Login was not even sent out; so when getting out
1331 * of this state, it will appear like a login retry
1332 * after Clear virtual link
1333 */
1334 break;
1335
1336 default:
1337 bfa_sm_fault(lps->bfa, event);
1338 }
1339}
1340
Jing Huang5fbe25c2010-10-18 17:17:23 -07001341/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001342 * login complete
1343 */
1344static void
1345bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
1346{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001347 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001348 bfa_trc(lps->bfa, event);
1349
1350 switch (event) {
1351 case BFA_LPS_SM_LOGOUT:
1352 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1353 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1354 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1355 } else {
1356 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1357 bfa_lps_send_logout(lps);
1358 }
1359 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1360 BFA_PL_EID_LOGO, 0, "Logout");
1361 break;
1362
1363 case BFA_LPS_SM_RX_CVL:
1364 bfa_sm_set_state(lps, bfa_lps_sm_init);
1365
1366 /* Let the vport module know about this event */
1367 bfa_lps_cvl_event(lps);
1368 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1369 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1370 break;
1371
Krishna Gudipatib7044952010-12-13 16:17:42 -08001372 case BFA_LPS_SM_SET_N2N_PID:
1373 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1374 bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
1375 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1376 } else
1377 bfa_lps_send_set_n2n_pid(lps);
1378 break;
1379
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001380 case BFA_LPS_SM_OFFLINE:
1381 case BFA_LPS_SM_DELETE:
1382 bfa_sm_set_state(lps, bfa_lps_sm_init);
1383 break;
1384
1385 default:
1386 bfa_sm_fault(lps->bfa, event);
1387 }
1388}
1389
Jing Huang8f4bfad2010-12-26 21:50:10 -08001390/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001391 * login complete
1392 */
1393static void
1394bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1395{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001396 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001397 bfa_trc(lps->bfa, event);
1398
1399 switch (event) {
1400 case BFA_LPS_SM_RESUME:
1401 bfa_sm_set_state(lps, bfa_lps_sm_online);
1402 bfa_lps_send_set_n2n_pid(lps);
1403 break;
1404
1405 case BFA_LPS_SM_LOGOUT:
1406 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1407 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1408 BFA_PL_EID_LOGO, 0, "Logout");
1409 break;
1410
1411 case BFA_LPS_SM_RX_CVL:
1412 bfa_sm_set_state(lps, bfa_lps_sm_init);
1413 bfa_reqq_wcancel(&lps->wqe);
1414
1415 /* Let the vport module know about this event */
1416 bfa_lps_cvl_event(lps);
1417 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1418 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1419 break;
1420
1421 case BFA_LPS_SM_OFFLINE:
1422 case BFA_LPS_SM_DELETE:
1423 bfa_sm_set_state(lps, bfa_lps_sm_init);
1424 bfa_reqq_wcancel(&lps->wqe);
1425 break;
1426
1427 default:
1428 bfa_sm_fault(lps->bfa, event);
1429 }
1430}
1431
Jing Huang5fbe25c2010-10-18 17:17:23 -07001432/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001433 * logout in progress - awaiting firmware response
1434 */
1435static void
1436bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
1437{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001438 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001439 bfa_trc(lps->bfa, event);
1440
1441 switch (event) {
1442 case BFA_LPS_SM_FWRSP:
1443 bfa_sm_set_state(lps, bfa_lps_sm_init);
1444 bfa_lps_logout_comp(lps);
1445 break;
1446
1447 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001448 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001449 bfa_sm_set_state(lps, bfa_lps_sm_init);
1450 break;
1451
1452 default:
1453 bfa_sm_fault(lps->bfa, event);
1454 }
1455}
1456
Jing Huang5fbe25c2010-10-18 17:17:23 -07001457/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001458 * logout pending -- awaiting space in request queue
1459 */
1460static void
1461bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1462{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001463 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001464 bfa_trc(lps->bfa, event);
1465
1466 switch (event) {
1467 case BFA_LPS_SM_RESUME:
1468 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1469 bfa_lps_send_logout(lps);
1470 break;
1471
1472 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001473 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001474 bfa_sm_set_state(lps, bfa_lps_sm_init);
1475 bfa_reqq_wcancel(&lps->wqe);
1476 break;
1477
1478 default:
1479 bfa_sm_fault(lps->bfa, event);
1480 }
1481}
1482
1483
1484
Jing Huang5fbe25c2010-10-18 17:17:23 -07001485/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001486 * lps_pvt BFA LPS private functions
1487 */
1488
Jing Huang5fbe25c2010-10-18 17:17:23 -07001489/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001490 * return memory requirement
1491 */
1492static void
Krishna Gudipati45070252011-06-24 20:24:29 -07001493bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
1494 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001495{
Krishna Gudipati45070252011-06-24 20:24:29 -07001496 struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa);
1497
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001498 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -07001499 bfa_mem_kva_setup(minfo, lps_kva,
1500 sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001501 else
Krishna Gudipati45070252011-06-24 20:24:29 -07001502 bfa_mem_kva_setup(minfo, lps_kva,
1503 sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001504}
1505
Jing Huang5fbe25c2010-10-18 17:17:23 -07001506/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001507 * bfa module attach at initialization time
1508 */
1509static void
1510bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07001511 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001512{
1513 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1514 struct bfa_lps_s *lps;
1515 int i;
1516
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001517 mod->num_lps = BFA_LPS_MAX_LPORTS;
1518 if (cfg->drvcfg.min_cfg)
1519 mod->num_lps = BFA_LPS_MIN_LPORTS;
1520 else
1521 mod->num_lps = BFA_LPS_MAX_LPORTS;
Krishna Gudipati45070252011-06-24 20:24:29 -07001522 mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001523
Krishna Gudipati45070252011-06-24 20:24:29 -07001524 bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001525
1526 INIT_LIST_HEAD(&mod->lps_free_q);
1527 INIT_LIST_HEAD(&mod->lps_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001528 INIT_LIST_HEAD(&mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001529
1530 for (i = 0; i < mod->num_lps; i++, lps++) {
1531 lps->bfa = bfa;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001532 lps->bfa_tag = (u8) i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001533 lps->reqq = BFA_REQQ_LPS;
1534 bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
1535 list_add_tail(&lps->qe, &mod->lps_free_q);
1536 }
1537}
1538
1539static void
1540bfa_lps_detach(struct bfa_s *bfa)
1541{
1542}
1543
1544static void
1545bfa_lps_start(struct bfa_s *bfa)
1546{
1547}
1548
1549static void
1550bfa_lps_stop(struct bfa_s *bfa)
1551{
1552}
1553
Jing Huang5fbe25c2010-10-18 17:17:23 -07001554/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001555 * IOC in disabled state -- consider all lps offline
1556 */
1557static void
1558bfa_lps_iocdisable(struct bfa_s *bfa)
1559{
1560 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1561 struct bfa_lps_s *lps;
1562 struct list_head *qe, *qen;
1563
1564 list_for_each_safe(qe, qen, &mod->lps_active_q) {
1565 lps = (struct bfa_lps_s *) qe;
1566 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1567 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001568 list_for_each_safe(qe, qen, &mod->lps_login_q) {
1569 lps = (struct bfa_lps_s *) qe;
1570 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1571 }
1572 list_splice_tail_init(&mod->lps_login_q, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001573}
1574
Jing Huang5fbe25c2010-10-18 17:17:23 -07001575/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001576 * Firmware login response
1577 */
1578static void
1579bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
1580{
1581 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1582 struct bfa_lps_s *lps;
1583
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001584 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1585 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001586
1587 lps->status = rsp->status;
1588 switch (rsp->status) {
1589 case BFA_STATUS_OK:
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001590 lps->fw_tag = rsp->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001591 lps->fport = rsp->f_port;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001592 if (lps->fport)
1593 lps->lp_pid = rsp->lp_pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001594 lps->npiv_en = rsp->npiv_en;
Jing Huangba816ea2010-10-18 17:10:50 -07001595 lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001596 lps->pr_pwwn = rsp->port_name;
1597 lps->pr_nwwn = rsp->node_name;
1598 lps->auth_req = rsp->auth_req;
1599 lps->lp_mac = rsp->lp_mac;
1600 lps->brcd_switch = rsp->brcd_switch;
1601 lps->fcf_mac = rsp->fcf_mac;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001602 lps->pr_bbscn = rsp->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001603
1604 break;
1605
1606 case BFA_STATUS_FABRIC_RJT:
1607 lps->lsrjt_rsn = rsp->lsrjt_rsn;
1608 lps->lsrjt_expl = rsp->lsrjt_expl;
1609
1610 break;
1611
1612 case BFA_STATUS_EPROTOCOL:
1613 lps->ext_status = rsp->ext_status;
1614
1615 break;
1616
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001617 case BFA_STATUS_VPORT_MAX:
Krishna Gudipatiff179e02012-03-13 17:40:31 -07001618 if (rsp->ext_status)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001619 bfa_lps_no_res(lps, rsp->ext_status);
1620 break;
1621
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001622 default:
1623 /* Nothing to do with other status */
1624 break;
1625 }
1626
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001627 list_del(&lps->qe);
1628 list_add_tail(&lps->qe, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001629 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1630}
1631
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001632static void
1633bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count)
1634{
1635 struct bfa_s *bfa = first_lps->bfa;
1636 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1637 struct list_head *qe, *qe_next;
1638 struct bfa_lps_s *lps;
1639
1640 bfa_trc(bfa, count);
1641
1642 qe = bfa_q_next(first_lps);
1643
1644 while (count && qe) {
1645 qe_next = bfa_q_next(qe);
1646 lps = (struct bfa_lps_s *)qe;
1647 bfa_trc(bfa, lps->bfa_tag);
1648 lps->status = first_lps->status;
1649 list_del(&lps->qe);
1650 list_add_tail(&lps->qe, &mod->lps_active_q);
1651 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1652 qe = qe_next;
1653 count--;
1654 }
1655}
1656
Jing Huang5fbe25c2010-10-18 17:17:23 -07001657/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001658 * Firmware logout response
1659 */
1660static void
1661bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
1662{
1663 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1664 struct bfa_lps_s *lps;
1665
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001666 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1667 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001668
1669 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1670}
1671
Jing Huang5fbe25c2010-10-18 17:17:23 -07001672/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001673 * Firmware received a Clear virtual link request (for FCoE)
1674 */
1675static void
1676bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
1677{
1678 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1679 struct bfa_lps_s *lps;
1680
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001681 lps = BFA_LPS_FROM_TAG(mod, cvl->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001682
1683 bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
1684}
1685
Jing Huang5fbe25c2010-10-18 17:17:23 -07001686/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001687 * Space is available in request queue, resume queueing request to firmware.
1688 */
1689static void
1690bfa_lps_reqq_resume(void *lps_arg)
1691{
1692 struct bfa_lps_s *lps = lps_arg;
1693
1694 bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
1695}
1696
Jing Huang5fbe25c2010-10-18 17:17:23 -07001697/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001698 * lps is freed -- triggered by vport delete
1699 */
1700static void
1701bfa_lps_free(struct bfa_lps_s *lps)
1702{
1703 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
1704
1705 lps->lp_pid = 0;
1706 list_del(&lps->qe);
1707 list_add_tail(&lps->qe, &mod->lps_free_q);
1708}
1709
Jing Huang5fbe25c2010-10-18 17:17:23 -07001710/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001711 * send login request to firmware
1712 */
1713static void
1714bfa_lps_send_login(struct bfa_lps_s *lps)
1715{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001716 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001717 struct bfi_lps_login_req_s *m;
1718
1719 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001720 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001721
1722 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001723 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001724
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001725 m->bfa_tag = lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001726 m->alpa = lps->alpa;
Jing Huangba816ea2010-10-18 17:10:50 -07001727 m->pdu_size = cpu_to_be16(lps->pdusz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001728 m->pwwn = lps->pwwn;
1729 m->nwwn = lps->nwwn;
1730 m->fdisc = lps->fdisc;
1731 m->auth_en = lps->auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001732 m->bb_scn = lps->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001733
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001734 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
1735 list_del(&lps->qe);
1736 list_add_tail(&lps->qe, &mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001737}
1738
Jing Huang5fbe25c2010-10-18 17:17:23 -07001739/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001740 * send logout request to firmware
1741 */
1742static void
1743bfa_lps_send_logout(struct bfa_lps_s *lps)
1744{
1745 struct bfi_lps_logout_req_s *m;
1746
1747 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001748 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001749
1750 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001751 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001752
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001753 m->fw_tag = lps->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001754 m->port_name = lps->pwwn;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001755 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001756}
1757
Jing Huang8f4bfad2010-12-26 21:50:10 -08001758/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001759 * send n2n pid set request to firmware
1760 */
1761static void
1762bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
1763{
1764 struct bfi_lps_n2n_pid_req_s *m;
1765
1766 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001767 WARN_ON(!m);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001768
1769 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001770 bfa_fn_lpu(lps->bfa));
Krishna Gudipatib7044952010-12-13 16:17:42 -08001771
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001772 m->fw_tag = lps->fw_tag;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001773 m->lp_pid = lps->lp_pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001774 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001775}
1776
Jing Huang5fbe25c2010-10-18 17:17:23 -07001777/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001778 * Indirect login completion handler for non-fcs
1779 */
1780static void
1781bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
1782{
1783 struct bfa_lps_s *lps = arg;
1784
1785 if (!complete)
1786 return;
1787
1788 if (lps->fdisc)
1789 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1790 else
1791 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1792}
1793
Jing Huang5fbe25c2010-10-18 17:17:23 -07001794/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001795 * Login completion handler -- direct call for fcs, queue for others
1796 */
1797static void
1798bfa_lps_login_comp(struct bfa_lps_s *lps)
1799{
1800 if (!lps->bfa->fcs) {
1801 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
1802 lps);
1803 return;
1804 }
1805
1806 if (lps->fdisc)
1807 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1808 else
1809 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1810}
1811
Jing Huang5fbe25c2010-10-18 17:17:23 -07001812/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001813 * Indirect logout completion handler for non-fcs
1814 */
1815static void
1816bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
1817{
1818 struct bfa_lps_s *lps = arg;
1819
1820 if (!complete)
1821 return;
1822
1823 if (lps->fdisc)
1824 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1825}
1826
Jing Huang5fbe25c2010-10-18 17:17:23 -07001827/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001828 * Logout completion handler -- direct call for fcs, queue for others
1829 */
1830static void
1831bfa_lps_logout_comp(struct bfa_lps_s *lps)
1832{
1833 if (!lps->bfa->fcs) {
1834 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
1835 lps);
1836 return;
1837 }
1838 if (lps->fdisc)
1839 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1840}
1841
Jing Huang5fbe25c2010-10-18 17:17:23 -07001842/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001843 * Clear virtual link completion handler for non-fcs
1844 */
1845static void
1846bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
1847{
1848 struct bfa_lps_s *lps = arg;
1849
1850 if (!complete)
1851 return;
1852
1853 /* Clear virtual link to base port will result in link down */
1854 if (lps->fdisc)
1855 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1856}
1857
Jing Huang5fbe25c2010-10-18 17:17:23 -07001858/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001859 * Received Clear virtual link event --direct call for fcs,
1860 * queue for others
1861 */
1862static void
1863bfa_lps_cvl_event(struct bfa_lps_s *lps)
1864{
1865 if (!lps->bfa->fcs) {
1866 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
1867 lps);
1868 return;
1869 }
1870
1871 /* Clear virtual link to base port will result in link down */
1872 if (lps->fdisc)
1873 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1874}
1875
1876
1877
Jing Huang5fbe25c2010-10-18 17:17:23 -07001878/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001879 * lps_public BFA LPS public functions
1880 */
1881
1882u32
1883bfa_lps_get_max_vport(struct bfa_s *bfa)
1884{
1885 if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
1886 return BFA_LPS_MAX_VPORTS_SUPP_CT;
1887 else
1888 return BFA_LPS_MAX_VPORTS_SUPP_CB;
1889}
1890
Jing Huang5fbe25c2010-10-18 17:17:23 -07001891/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001892 * Allocate a lport srvice tag.
1893 */
1894struct bfa_lps_s *
1895bfa_lps_alloc(struct bfa_s *bfa)
1896{
1897 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1898 struct bfa_lps_s *lps = NULL;
1899
1900 bfa_q_deq(&mod->lps_free_q, &lps);
1901
1902 if (lps == NULL)
1903 return NULL;
1904
1905 list_add_tail(&lps->qe, &mod->lps_active_q);
1906
1907 bfa_sm_set_state(lps, bfa_lps_sm_init);
1908 return lps;
1909}
1910
Jing Huang5fbe25c2010-10-18 17:17:23 -07001911/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001912 * Free lport service tag. This can be called anytime after an alloc.
1913 * No need to wait for any pending login/logout completions.
1914 */
1915void
1916bfa_lps_delete(struct bfa_lps_s *lps)
1917{
1918 bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
1919}
1920
Jing Huang5fbe25c2010-10-18 17:17:23 -07001921/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001922 * Initiate a lport login.
1923 */
1924void
1925bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001926 wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en, uint8_t bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001927{
1928 lps->uarg = uarg;
1929 lps->alpa = alpa;
1930 lps->pdusz = pdusz;
1931 lps->pwwn = pwwn;
1932 lps->nwwn = nwwn;
1933 lps->fdisc = BFA_FALSE;
1934 lps->auth_en = auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001935 lps->bb_scn = bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001936 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1937}
1938
Jing Huang5fbe25c2010-10-18 17:17:23 -07001939/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001940 * Initiate a lport fdisc login.
1941 */
1942void
1943bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
1944 wwn_t nwwn)
1945{
1946 lps->uarg = uarg;
1947 lps->alpa = 0;
1948 lps->pdusz = pdusz;
1949 lps->pwwn = pwwn;
1950 lps->nwwn = nwwn;
1951 lps->fdisc = BFA_TRUE;
1952 lps->auth_en = BFA_FALSE;
1953 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1954}
1955
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001956
Jing Huang5fbe25c2010-10-18 17:17:23 -07001957/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001958 * Initiate a lport FDSIC logout.
1959 */
1960void
1961bfa_lps_fdisclogo(struct bfa_lps_s *lps)
1962{
1963 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
1964}
1965
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001966u8
1967bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag)
1968{
1969 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1970
1971 return BFA_LPS_FROM_TAG(mod, lp_tag)->fw_tag;
1972}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001973
Jing Huang5fbe25c2010-10-18 17:17:23 -07001974/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001975 * Return lport services tag given the pid
1976 */
1977u8
1978bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
1979{
1980 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1981 struct bfa_lps_s *lps;
1982 int i;
1983
1984 for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
1985 if (lps->lp_pid == pid)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001986 return lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001987 }
1988
1989 /* Return base port tag anyway */
1990 return 0;
1991}
1992
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001993
Jing Huang5fbe25c2010-10-18 17:17:23 -07001994/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001995 * return port id assigned to the base lport
1996 */
1997u32
1998bfa_lps_get_base_pid(struct bfa_s *bfa)
1999{
2000 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
2001
2002 return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
2003}
2004
Jing Huang8f4bfad2010-12-26 21:50:10 -08002005/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08002006 * Set PID in case of n2n (which is assigned during PLOGI)
2007 */
2008void
2009bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
2010{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002011 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08002012 bfa_trc(lps->bfa, n2n_pid);
2013
2014 lps->lp_pid = n2n_pid;
2015 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
2016}
2017
Jing Huang5fbe25c2010-10-18 17:17:23 -07002018/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002019 * LPS firmware message class handler.
2020 */
2021void
2022bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2023{
2024 union bfi_lps_i2h_msg_u msg;
2025
2026 bfa_trc(bfa, m->mhdr.msg_id);
2027 msg.msg = m;
2028
2029 switch (m->mhdr.msg_id) {
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002030 case BFI_LPS_I2H_LOGIN_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002031 bfa_lps_login_rsp(bfa, msg.login_rsp);
2032 break;
2033
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002034 case BFI_LPS_I2H_LOGOUT_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002035 bfa_lps_logout_rsp(bfa, msg.logout_rsp);
2036 break;
2037
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002038 case BFI_LPS_I2H_CVL_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002039 bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
2040 break;
2041
2042 default:
2043 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08002044 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002045 }
2046}
2047
Krishna Gudipati7826f302011-07-20 16:59:13 -07002048static void
2049bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
2050{
2051 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2052 struct bfa_aen_entry_s *aen_entry;
2053
2054 bfad_get_aen_entry(bfad, aen_entry);
2055 if (!aen_entry)
2056 return;
2057
2058 aen_entry->aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
2059 aen_entry->aen_data.port.pwwn = fcport->pwwn;
2060
2061 /* Send the AEN notification */
2062 bfad_im_post_vendor_event(aen_entry, bfad, ++fcport->bfa->bfa_aen_seq,
2063 BFA_AEN_CAT_PORT, event);
2064}
2065
Jing Huang5fbe25c2010-10-18 17:17:23 -07002066/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002067 * FC PORT state machine functions
2068 */
2069static void
2070bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
2071 enum bfa_fcport_sm_event event)
2072{
2073 bfa_trc(fcport->bfa, event);
2074
2075 switch (event) {
2076 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002077 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002078 * Start event after IOC is configured and BFA is started.
2079 */
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08002080 fcport->use_flash_cfg = BFA_TRUE;
2081
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002082 if (bfa_fcport_send_enable(fcport)) {
2083 bfa_trc(fcport->bfa, BFA_TRUE);
2084 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2085 } else {
2086 bfa_trc(fcport->bfa, BFA_FALSE);
2087 bfa_sm_set_state(fcport,
2088 bfa_fcport_sm_enabling_qwait);
2089 }
2090 break;
2091
2092 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002093 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002094 * Port is persistently configured to be in enabled state. Do
2095 * not change state. Port enabling is done when START event is
2096 * received.
2097 */
2098 break;
2099
2100 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002101 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002102 * If a port is persistently configured to be disabled, the
2103 * first event will a port disable request.
2104 */
2105 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2106 break;
2107
2108 case BFA_FCPORT_SM_HWFAIL:
2109 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2110 break;
2111
2112 default:
2113 bfa_sm_fault(fcport->bfa, event);
2114 }
2115}
2116
2117static void
2118bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
2119 enum bfa_fcport_sm_event event)
2120{
2121 char pwwn_buf[BFA_STRING_32];
2122 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2123 bfa_trc(fcport->bfa, event);
2124
2125 switch (event) {
2126 case BFA_FCPORT_SM_QRESUME:
2127 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2128 bfa_fcport_send_enable(fcport);
2129 break;
2130
2131 case BFA_FCPORT_SM_STOP:
2132 bfa_reqq_wcancel(&fcport->reqq_wait);
2133 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2134 break;
2135
2136 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002137 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002138 * Already enable is in progress.
2139 */
2140 break;
2141
2142 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002143 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002144 * Just send disable request to firmware when room becomes
2145 * available in request queue.
2146 */
2147 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2148 bfa_reqq_wcancel(&fcport->reqq_wait);
2149 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2150 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2151 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002152 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002153 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002154 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002155 break;
2156
2157 case BFA_FCPORT_SM_LINKUP:
2158 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002159 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002160 * Possible to get link events when doing back-to-back
2161 * enable/disables.
2162 */
2163 break;
2164
2165 case BFA_FCPORT_SM_HWFAIL:
2166 bfa_reqq_wcancel(&fcport->reqq_wait);
2167 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2168 break;
2169
2170 default:
2171 bfa_sm_fault(fcport->bfa, event);
2172 }
2173}
2174
2175static void
2176bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
2177 enum bfa_fcport_sm_event event)
2178{
2179 char pwwn_buf[BFA_STRING_32];
2180 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2181 bfa_trc(fcport->bfa, event);
2182
2183 switch (event) {
2184 case BFA_FCPORT_SM_FWRSP:
2185 case BFA_FCPORT_SM_LINKDOWN:
2186 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2187 break;
2188
2189 case BFA_FCPORT_SM_LINKUP:
2190 bfa_fcport_update_linkinfo(fcport);
2191 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
2192
Jing Huangd4b671c2010-12-26 21:46:35 -08002193 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002194 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2195 break;
2196
2197 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002198 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002199 * Already being enabled.
2200 */
2201 break;
2202
2203 case BFA_FCPORT_SM_DISABLE:
2204 if (bfa_fcport_send_disable(fcport))
2205 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2206 else
2207 bfa_sm_set_state(fcport,
2208 bfa_fcport_sm_disabling_qwait);
2209
2210 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2211 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2212 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002213 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002214 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002215 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002216 break;
2217
2218 case BFA_FCPORT_SM_STOP:
2219 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2220 break;
2221
2222 case BFA_FCPORT_SM_HWFAIL:
2223 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2224 break;
2225
2226 default:
2227 bfa_sm_fault(fcport->bfa, event);
2228 }
2229}
2230
2231static void
2232bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
2233 enum bfa_fcport_sm_event event)
2234{
2235 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2236 char pwwn_buf[BFA_STRING_32];
2237 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2238
2239 bfa_trc(fcport->bfa, event);
2240
2241 switch (event) {
2242 case BFA_FCPORT_SM_LINKUP:
2243 bfa_fcport_update_linkinfo(fcport);
2244 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
Jing Huangd4b671c2010-12-26 21:46:35 -08002245 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002246 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2247 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
2248 if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
2249
2250 bfa_trc(fcport->bfa,
2251 pevent->link_state.vc_fcf.fcf.fipenabled);
2252 bfa_trc(fcport->bfa,
2253 pevent->link_state.vc_fcf.fcf.fipfailed);
2254
2255 if (pevent->link_state.vc_fcf.fcf.fipfailed)
2256 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2257 BFA_PL_EID_FIP_FCF_DISC, 0,
2258 "FIP FCF Discovery Failed");
2259 else
2260 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2261 BFA_PL_EID_FIP_FCF_DISC, 0,
2262 "FIP FCF Discovered");
2263 }
2264
2265 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2266 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002267 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002268 "Base port online: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002269 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002270
2271 /* If QoS is enabled and it is not online, send AEN */
2272 if (fcport->cfg.qos_enabled &&
2273 fcport->qos_attr.state != BFA_QOS_ONLINE)
2274 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002275 break;
2276
2277 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002278 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002279 * Possible to get link down event.
2280 */
2281 break;
2282
2283 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002284 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002285 * Already enabled.
2286 */
2287 break;
2288
2289 case BFA_FCPORT_SM_DISABLE:
2290 if (bfa_fcport_send_disable(fcport))
2291 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2292 else
2293 bfa_sm_set_state(fcport,
2294 bfa_fcport_sm_disabling_qwait);
2295
2296 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2297 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2298 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002299 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002300 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002301 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002302 break;
2303
2304 case BFA_FCPORT_SM_STOP:
2305 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2306 break;
2307
2308 case BFA_FCPORT_SM_HWFAIL:
2309 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2310 break;
2311
2312 default:
2313 bfa_sm_fault(fcport->bfa, event);
2314 }
2315}
2316
2317static void
2318bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
2319 enum bfa_fcport_sm_event event)
2320{
2321 char pwwn_buf[BFA_STRING_32];
2322 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2323
2324 bfa_trc(fcport->bfa, event);
2325
2326 switch (event) {
2327 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002328 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002329 * Already enabled.
2330 */
2331 break;
2332
2333 case BFA_FCPORT_SM_DISABLE:
2334 if (bfa_fcport_send_disable(fcport))
2335 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2336 else
2337 bfa_sm_set_state(fcport,
2338 bfa_fcport_sm_disabling_qwait);
2339
2340 bfa_fcport_reset_linkinfo(fcport);
2341 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2342 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2343 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2344 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002345 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002346 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002347 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
Jing Huang88166242010-12-09 17:11:53 -08002348 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002349 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002350 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002351 break;
2352
2353 case BFA_FCPORT_SM_LINKDOWN:
2354 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2355 bfa_fcport_reset_linkinfo(fcport);
2356 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2357 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2358 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
2359 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002360 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002361 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002362 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002363 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2364 } else {
Jing Huang88166242010-12-09 17:11:53 -08002365 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002366 "Base port (WWN = %s) "
2367 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002368 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2369 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002370 break;
2371
2372 case BFA_FCPORT_SM_STOP:
2373 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2374 bfa_fcport_reset_linkinfo(fcport);
2375 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002376 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002377 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002378 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002379 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2380 } else {
Jing Huang88166242010-12-09 17:11:53 -08002381 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002382 "Base port (WWN = %s) "
2383 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002384 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2385 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002386 break;
2387
2388 case BFA_FCPORT_SM_HWFAIL:
2389 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2390 bfa_fcport_reset_linkinfo(fcport);
2391 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2392 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002393 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002394 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002395 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002396 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2397 } else {
Jing Huang88166242010-12-09 17:11:53 -08002398 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002399 "Base port (WWN = %s) "
2400 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002401 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2402 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002403 break;
2404
2405 default:
2406 bfa_sm_fault(fcport->bfa, event);
2407 }
2408}
2409
2410static void
2411bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
2412 enum bfa_fcport_sm_event event)
2413{
2414 bfa_trc(fcport->bfa, event);
2415
2416 switch (event) {
2417 case BFA_FCPORT_SM_QRESUME:
2418 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2419 bfa_fcport_send_disable(fcport);
2420 break;
2421
2422 case BFA_FCPORT_SM_STOP:
2423 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2424 bfa_reqq_wcancel(&fcport->reqq_wait);
2425 break;
2426
2427 case BFA_FCPORT_SM_ENABLE:
2428 bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
2429 break;
2430
2431 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002432 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002433 * Already being disabled.
2434 */
2435 break;
2436
2437 case BFA_FCPORT_SM_LINKUP:
2438 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002439 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002440 * Possible to get link events when doing back-to-back
2441 * enable/disables.
2442 */
2443 break;
2444
2445 case BFA_FCPORT_SM_HWFAIL:
2446 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2447 bfa_reqq_wcancel(&fcport->reqq_wait);
2448 break;
2449
2450 default:
2451 bfa_sm_fault(fcport->bfa, event);
2452 }
2453}
2454
2455static void
2456bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
2457 enum bfa_fcport_sm_event event)
2458{
2459 bfa_trc(fcport->bfa, event);
2460
2461 switch (event) {
2462 case BFA_FCPORT_SM_QRESUME:
2463 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2464 bfa_fcport_send_disable(fcport);
2465 if (bfa_fcport_send_enable(fcport))
2466 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2467 else
2468 bfa_sm_set_state(fcport,
2469 bfa_fcport_sm_enabling_qwait);
2470 break;
2471
2472 case BFA_FCPORT_SM_STOP:
2473 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2474 bfa_reqq_wcancel(&fcport->reqq_wait);
2475 break;
2476
2477 case BFA_FCPORT_SM_ENABLE:
2478 break;
2479
2480 case BFA_FCPORT_SM_DISABLE:
2481 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
2482 break;
2483
2484 case BFA_FCPORT_SM_LINKUP:
2485 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002486 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002487 * Possible to get link events when doing back-to-back
2488 * enable/disables.
2489 */
2490 break;
2491
2492 case BFA_FCPORT_SM_HWFAIL:
2493 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2494 bfa_reqq_wcancel(&fcport->reqq_wait);
2495 break;
2496
2497 default:
2498 bfa_sm_fault(fcport->bfa, event);
2499 }
2500}
2501
2502static void
2503bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
2504 enum bfa_fcport_sm_event event)
2505{
2506 char pwwn_buf[BFA_STRING_32];
2507 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2508 bfa_trc(fcport->bfa, event);
2509
2510 switch (event) {
2511 case BFA_FCPORT_SM_FWRSP:
2512 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2513 break;
2514
2515 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002516 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002517 * Already being disabled.
2518 */
2519 break;
2520
2521 case BFA_FCPORT_SM_ENABLE:
2522 if (bfa_fcport_send_enable(fcport))
2523 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2524 else
2525 bfa_sm_set_state(fcport,
2526 bfa_fcport_sm_enabling_qwait);
2527
2528 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2529 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2530 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002531 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002532 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002533 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002534 break;
2535
2536 case BFA_FCPORT_SM_STOP:
2537 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2538 break;
2539
2540 case BFA_FCPORT_SM_LINKUP:
2541 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002542 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002543 * Possible to get link events when doing back-to-back
2544 * enable/disables.
2545 */
2546 break;
2547
2548 case BFA_FCPORT_SM_HWFAIL:
2549 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2550 break;
2551
2552 default:
2553 bfa_sm_fault(fcport->bfa, event);
2554 }
2555}
2556
2557static void
2558bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
2559 enum bfa_fcport_sm_event event)
2560{
2561 char pwwn_buf[BFA_STRING_32];
2562 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2563 bfa_trc(fcport->bfa, event);
2564
2565 switch (event) {
2566 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002567 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002568 * Ignore start event for a port that is disabled.
2569 */
2570 break;
2571
2572 case BFA_FCPORT_SM_STOP:
2573 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2574 break;
2575
2576 case BFA_FCPORT_SM_ENABLE:
2577 if (bfa_fcport_send_enable(fcport))
2578 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2579 else
2580 bfa_sm_set_state(fcport,
2581 bfa_fcport_sm_enabling_qwait);
2582
2583 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2584 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2585 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002586 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002587 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002588 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002589 break;
2590
2591 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002592 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002593 * Already disabled.
2594 */
2595 break;
2596
2597 case BFA_FCPORT_SM_HWFAIL:
2598 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2599 break;
2600
2601 default:
2602 bfa_sm_fault(fcport->bfa, event);
2603 }
2604}
2605
2606static void
2607bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
2608 enum bfa_fcport_sm_event event)
2609{
2610 bfa_trc(fcport->bfa, event);
2611
2612 switch (event) {
2613 case BFA_FCPORT_SM_START:
2614 if (bfa_fcport_send_enable(fcport))
2615 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2616 else
2617 bfa_sm_set_state(fcport,
2618 bfa_fcport_sm_enabling_qwait);
2619 break;
2620
2621 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002622 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002623 * Ignore all other events.
2624 */
2625 ;
2626 }
2627}
2628
Jing Huang5fbe25c2010-10-18 17:17:23 -07002629/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002630 * Port is enabled. IOC is down/failed.
2631 */
2632static void
2633bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
2634 enum bfa_fcport_sm_event event)
2635{
2636 bfa_trc(fcport->bfa, event);
2637
2638 switch (event) {
2639 case BFA_FCPORT_SM_START:
2640 if (bfa_fcport_send_enable(fcport))
2641 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2642 else
2643 bfa_sm_set_state(fcport,
2644 bfa_fcport_sm_enabling_qwait);
2645 break;
2646
2647 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002648 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002649 * Ignore all events.
2650 */
2651 ;
2652 }
2653}
2654
Jing Huang5fbe25c2010-10-18 17:17:23 -07002655/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002656 * Port is disabled. IOC is down/failed.
2657 */
2658static void
2659bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
2660 enum bfa_fcport_sm_event event)
2661{
2662 bfa_trc(fcport->bfa, event);
2663
2664 switch (event) {
2665 case BFA_FCPORT_SM_START:
2666 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2667 break;
2668
2669 case BFA_FCPORT_SM_ENABLE:
2670 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2671 break;
2672
2673 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002674 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002675 * Ignore all events.
2676 */
2677 ;
2678 }
2679}
2680
Jing Huang5fbe25c2010-10-18 17:17:23 -07002681/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002682 * Link state is down
2683 */
2684static void
2685bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
2686 enum bfa_fcport_ln_sm_event event)
2687{
2688 bfa_trc(ln->fcport->bfa, event);
2689
2690 switch (event) {
2691 case BFA_FCPORT_LN_SM_LINKUP:
2692 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2693 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2694 break;
2695
2696 default:
2697 bfa_sm_fault(ln->fcport->bfa, event);
2698 }
2699}
2700
Jing Huang5fbe25c2010-10-18 17:17:23 -07002701/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002702 * Link state is waiting for down notification
2703 */
2704static void
2705bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
2706 enum bfa_fcport_ln_sm_event event)
2707{
2708 bfa_trc(ln->fcport->bfa, event);
2709
2710 switch (event) {
2711 case BFA_FCPORT_LN_SM_LINKUP:
2712 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2713 break;
2714
2715 case BFA_FCPORT_LN_SM_NOTIFICATION:
2716 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2717 break;
2718
2719 default:
2720 bfa_sm_fault(ln->fcport->bfa, event);
2721 }
2722}
2723
Jing Huang5fbe25c2010-10-18 17:17:23 -07002724/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002725 * Link state is waiting for down notification and there is a pending up
2726 */
2727static void
2728bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
2729 enum bfa_fcport_ln_sm_event event)
2730{
2731 bfa_trc(ln->fcport->bfa, event);
2732
2733 switch (event) {
2734 case BFA_FCPORT_LN_SM_LINKDOWN:
2735 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2736 break;
2737
2738 case BFA_FCPORT_LN_SM_NOTIFICATION:
2739 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2740 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2741 break;
2742
2743 default:
2744 bfa_sm_fault(ln->fcport->bfa, event);
2745 }
2746}
2747
Jing Huang5fbe25c2010-10-18 17:17:23 -07002748/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002749 * Link state is up
2750 */
2751static void
2752bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
2753 enum bfa_fcport_ln_sm_event event)
2754{
2755 bfa_trc(ln->fcport->bfa, event);
2756
2757 switch (event) {
2758 case BFA_FCPORT_LN_SM_LINKDOWN:
2759 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2760 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2761 break;
2762
2763 default:
2764 bfa_sm_fault(ln->fcport->bfa, event);
2765 }
2766}
2767
Jing Huang5fbe25c2010-10-18 17:17:23 -07002768/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002769 * Link state is waiting for up notification
2770 */
2771static void
2772bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
2773 enum bfa_fcport_ln_sm_event event)
2774{
2775 bfa_trc(ln->fcport->bfa, event);
2776
2777 switch (event) {
2778 case BFA_FCPORT_LN_SM_LINKDOWN:
2779 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2780 break;
2781
2782 case BFA_FCPORT_LN_SM_NOTIFICATION:
2783 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
2784 break;
2785
2786 default:
2787 bfa_sm_fault(ln->fcport->bfa, event);
2788 }
2789}
2790
Jing Huang5fbe25c2010-10-18 17:17:23 -07002791/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002792 * Link state is waiting for up notification and there is a pending down
2793 */
2794static void
2795bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
2796 enum bfa_fcport_ln_sm_event event)
2797{
2798 bfa_trc(ln->fcport->bfa, event);
2799
2800 switch (event) {
2801 case BFA_FCPORT_LN_SM_LINKUP:
2802 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
2803 break;
2804
2805 case BFA_FCPORT_LN_SM_NOTIFICATION:
2806 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2807 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2808 break;
2809
2810 default:
2811 bfa_sm_fault(ln->fcport->bfa, event);
2812 }
2813}
2814
Jing Huang5fbe25c2010-10-18 17:17:23 -07002815/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002816 * Link state is waiting for up notification and there are pending down and up
2817 */
2818static void
2819bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
2820 enum bfa_fcport_ln_sm_event event)
2821{
2822 bfa_trc(ln->fcport->bfa, event);
2823
2824 switch (event) {
2825 case BFA_FCPORT_LN_SM_LINKDOWN:
2826 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2827 break;
2828
2829 case BFA_FCPORT_LN_SM_NOTIFICATION:
2830 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2831 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2832 break;
2833
2834 default:
2835 bfa_sm_fault(ln->fcport->bfa, event);
2836 }
2837}
2838
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002839static void
2840__bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
2841{
2842 struct bfa_fcport_ln_s *ln = cbarg;
2843
2844 if (complete)
2845 ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
2846 else
2847 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2848}
2849
Jing Huang5fbe25c2010-10-18 17:17:23 -07002850/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002851 * Send SCN notification to upper layers.
2852 * trunk - false if caller is fcport to ignore fcport event in trunked mode
2853 */
2854static void
2855bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
2856 bfa_boolean_t trunk)
2857{
2858 if (fcport->cfg.trunked && !trunk)
2859 return;
2860
2861 switch (event) {
2862 case BFA_PORT_LINKUP:
2863 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
2864 break;
2865 case BFA_PORT_LINKDOWN:
2866 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
2867 break;
2868 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08002869 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002870 }
2871}
2872
2873static void
2874bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
2875{
2876 struct bfa_fcport_s *fcport = ln->fcport;
2877
2878 if (fcport->bfa->fcs) {
2879 fcport->event_cbfn(fcport->event_cbarg, event);
2880 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2881 } else {
2882 ln->ln_event = event;
2883 bfa_cb_queue(fcport->bfa, &ln->ln_qe,
2884 __bfa_cb_fcport_event, ln);
2885 }
2886}
2887
2888#define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
2889 BFA_CACHELINE_SZ))
2890
2891static void
Krishna Gudipati45070252011-06-24 20:24:29 -07002892bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
2893 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002894{
Krishna Gudipati45070252011-06-24 20:24:29 -07002895 struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa);
2896
2897 bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002898}
2899
2900static void
2901bfa_fcport_qresume(void *cbarg)
2902{
2903 struct bfa_fcport_s *fcport = cbarg;
2904
2905 bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
2906}
2907
2908static void
Krishna Gudipati45070252011-06-24 20:24:29 -07002909bfa_fcport_mem_claim(struct bfa_fcport_s *fcport)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002910{
Krishna Gudipati45070252011-06-24 20:24:29 -07002911 struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002912
Krishna Gudipati45070252011-06-24 20:24:29 -07002913 fcport->stats_kva = bfa_mem_dma_virt(fcport_dma);
2914 fcport->stats_pa = bfa_mem_dma_phys(fcport_dma);
2915 fcport->stats = (union bfa_fcport_stats_u *)
2916 bfa_mem_dma_virt(fcport_dma);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002917}
2918
Jing Huang5fbe25c2010-10-18 17:17:23 -07002919/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002920 * Memory initialization.
2921 */
2922static void
2923bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07002924 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002925{
2926 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2927 struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
2928 struct bfa_fcport_ln_s *ln = &fcport->ln;
Maggie Zhangf16a1752010-12-09 19:12:32 -08002929 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002930
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002931 fcport->bfa = bfa;
2932 ln->fcport = fcport;
2933
Krishna Gudipati45070252011-06-24 20:24:29 -07002934 bfa_fcport_mem_claim(fcport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002935
2936 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
2937 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2938
Jing Huang5fbe25c2010-10-18 17:17:23 -07002939 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002940 * initialize time stamp for stats reset
2941 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08002942 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002943 fcport->stats_reset_time = tv.tv_sec;
2944
Jing Huang5fbe25c2010-10-18 17:17:23 -07002945 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002946 * initialize and set default configuration
2947 */
2948 port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
2949 port_cfg->speed = BFA_PORT_SPEED_AUTO;
2950 port_cfg->trunked = BFA_FALSE;
2951 port_cfg->maxfrsize = 0;
2952
2953 port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
2954
Krishna Gudipati37ea0552011-07-20 17:02:11 -07002955 INIT_LIST_HEAD(&fcport->stats_pending_q);
2956 INIT_LIST_HEAD(&fcport->statsclr_pending_q);
2957
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002958 bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
2959}
2960
2961static void
2962bfa_fcport_detach(struct bfa_s *bfa)
2963{
2964}
2965
Jing Huang5fbe25c2010-10-18 17:17:23 -07002966/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002967 * Called when IOC is ready.
2968 */
2969static void
2970bfa_fcport_start(struct bfa_s *bfa)
2971{
2972 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
2973}
2974
Jing Huang5fbe25c2010-10-18 17:17:23 -07002975/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002976 * Called before IOC is stopped.
2977 */
2978static void
2979bfa_fcport_stop(struct bfa_s *bfa)
2980{
2981 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
2982 bfa_trunk_iocdisable(bfa);
2983}
2984
Jing Huang5fbe25c2010-10-18 17:17:23 -07002985/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002986 * Called when IOC failure is detected.
2987 */
2988static void
2989bfa_fcport_iocdisable(struct bfa_s *bfa)
2990{
2991 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2992
2993 bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
2994 bfa_trunk_iocdisable(bfa);
2995}
2996
2997static void
2998bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
2999{
3000 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
3001 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3002
3003 fcport->speed = pevent->link_state.speed;
3004 fcport->topology = pevent->link_state.topology;
3005
3006 if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)
3007 fcport->myalpa = 0;
3008
3009 /* QoS Details */
Jing Huang6a18b162010-10-18 17:08:54 -07003010 fcport->qos_attr = pevent->link_state.qos_attr;
3011 fcport->qos_vc_attr = pevent->link_state.vc_fcf.qos_vc_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003012
Jing Huang5fbe25c2010-10-18 17:17:23 -07003013 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003014 * update trunk state if applicable
3015 */
3016 if (!fcport->cfg.trunked)
3017 trunk->attr.state = BFA_TRUNK_DISABLED;
3018
3019 /* update FCoE specific */
Jing Huangba816ea2010-10-18 17:10:50 -07003020 fcport->fcoe_vlan = be16_to_cpu(pevent->link_state.vc_fcf.fcf.vlan);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003021
3022 bfa_trc(fcport->bfa, fcport->speed);
3023 bfa_trc(fcport->bfa, fcport->topology);
3024}
3025
3026static void
3027bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
3028{
3029 fcport->speed = BFA_PORT_SPEED_UNKNOWN;
3030 fcport->topology = BFA_PORT_TOPOLOGY_NONE;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003031 fcport->bbsc_op_state = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003032}
3033
Jing Huang5fbe25c2010-10-18 17:17:23 -07003034/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003035 * Send port enable message to firmware.
3036 */
3037static bfa_boolean_t
3038bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
3039{
3040 struct bfi_fcport_enable_req_s *m;
3041
Jing Huang5fbe25c2010-10-18 17:17:23 -07003042 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003043 * Increment message tag before queue check, so that responses to old
3044 * requests are discarded.
3045 */
3046 fcport->msgtag++;
3047
Jing Huang5fbe25c2010-10-18 17:17:23 -07003048 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003049 * check for room in queue to send request now
3050 */
3051 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3052 if (!m) {
3053 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3054 &fcport->reqq_wait);
3055 return BFA_FALSE;
3056 }
3057
3058 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003059 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003060 m->nwwn = fcport->nwwn;
3061 m->pwwn = fcport->pwwn;
3062 m->port_cfg = fcport->cfg;
3063 m->msgtag = fcport->msgtag;
Jing Huangba816ea2010-10-18 17:10:50 -07003064 m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003065 m->use_flash_cfg = fcport->use_flash_cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003066 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
3067 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
3068 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
3069
Jing Huang5fbe25c2010-10-18 17:17:23 -07003070 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003071 * queue I/O message to firmware
3072 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003073 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003074 return BFA_TRUE;
3075}
3076
Jing Huang5fbe25c2010-10-18 17:17:23 -07003077/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003078 * Send port disable message to firmware.
3079 */
3080static bfa_boolean_t
3081bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
3082{
3083 struct bfi_fcport_req_s *m;
3084
Jing Huang5fbe25c2010-10-18 17:17:23 -07003085 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003086 * Increment message tag before queue check, so that responses to old
3087 * requests are discarded.
3088 */
3089 fcport->msgtag++;
3090
Jing Huang5fbe25c2010-10-18 17:17:23 -07003091 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003092 * check for room in queue to send request now
3093 */
3094 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3095 if (!m) {
3096 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3097 &fcport->reqq_wait);
3098 return BFA_FALSE;
3099 }
3100
3101 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003102 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003103 m->msgtag = fcport->msgtag;
3104
Jing Huang5fbe25c2010-10-18 17:17:23 -07003105 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003106 * queue I/O message to firmware
3107 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003108 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003109
3110 return BFA_TRUE;
3111}
3112
3113static void
3114bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
3115{
Maggie Zhangf7f738122010-12-09 19:08:43 -08003116 fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
3117 fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003118
3119 bfa_trc(fcport->bfa, fcport->pwwn);
3120 bfa_trc(fcport->bfa, fcport->nwwn);
3121}
3122
3123static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003124bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
3125 struct bfa_qos_stats_s *s)
3126{
3127 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003128 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003129 int i;
3130
3131 /* Now swap the 32 bit fields */
3132 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
Jing Huangba816ea2010-10-18 17:10:50 -07003133 dip[i] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003134}
3135
3136static void
3137bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
3138 struct bfa_fcoe_stats_s *s)
3139{
3140 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003141 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003142 int i;
3143
3144 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
3145 i = i + 2) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003146#ifdef __BIG_ENDIAN
Jing Huangba816ea2010-10-18 17:10:50 -07003147 dip[i] = be32_to_cpu(sip[i]);
3148 dip[i + 1] = be32_to_cpu(sip[i + 1]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003149#else
Jing Huangba816ea2010-10-18 17:10:50 -07003150 dip[i] = be32_to_cpu(sip[i + 1]);
3151 dip[i + 1] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003152#endif
3153 }
3154}
3155
3156static void
3157__bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
3158{
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003159 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *)cbarg;
3160 struct bfa_cb_pending_q_s *cb;
3161 struct list_head *qe, *qen;
3162 union bfa_fcport_stats_u *ret;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003163
3164 if (complete) {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003165 struct timeval tv;
3166 if (fcport->stats_status == BFA_STATUS_OK)
3167 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003168
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003169 list_for_each_safe(qe, qen, &fcport->stats_pending_q) {
3170 bfa_q_deq(&fcport->stats_pending_q, &qe);
3171 cb = (struct bfa_cb_pending_q_s *)qe;
3172 if (fcport->stats_status == BFA_STATUS_OK) {
3173 ret = (union bfa_fcport_stats_u *)cb->data;
3174 /* Swap FC QoS or FCoE stats */
3175 if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
3176 bfa_fcport_qos_stats_swap(&ret->fcqos,
3177 &fcport->stats->fcqos);
3178 else {
3179 bfa_fcport_fcoe_stats_swap(&ret->fcoe,
3180 &fcport->stats->fcoe);
3181 ret->fcoe.secs_reset =
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003182 tv.tv_sec - fcport->stats_reset_time;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003183 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003184 }
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003185 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
3186 fcport->stats_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003187 }
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003188 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003189 } else {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003190 INIT_LIST_HEAD(&fcport->stats_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003191 fcport->stats_status = BFA_STATUS_OK;
3192 }
3193}
3194
3195static void
3196bfa_fcport_stats_get_timeout(void *cbarg)
3197{
3198 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3199
3200 bfa_trc(fcport->bfa, fcport->stats_qfull);
3201
3202 if (fcport->stats_qfull) {
3203 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3204 fcport->stats_qfull = BFA_FALSE;
3205 }
3206
3207 fcport->stats_status = BFA_STATUS_ETIMER;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003208 __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003209}
3210
3211static void
3212bfa_fcport_send_stats_get(void *cbarg)
3213{
3214 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3215 struct bfi_fcport_req_s *msg;
3216
3217 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3218
3219 if (!msg) {
3220 fcport->stats_qfull = BFA_TRUE;
3221 bfa_reqq_winit(&fcport->stats_reqq_wait,
3222 bfa_fcport_send_stats_get, fcport);
3223 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3224 &fcport->stats_reqq_wait);
3225 return;
3226 }
3227 fcport->stats_qfull = BFA_FALSE;
3228
Jing Huang6a18b162010-10-18 17:08:54 -07003229 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003230 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003231 bfa_fn_lpu(fcport->bfa));
3232 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003233}
3234
3235static void
3236__bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
3237{
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003238 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3239 struct bfa_cb_pending_q_s *cb;
3240 struct list_head *qe, *qen;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003241
3242 if (complete) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003243 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003244
Jing Huang5fbe25c2010-10-18 17:17:23 -07003245 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003246 * re-initialize time stamp for stats reset
3247 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08003248 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003249 fcport->stats_reset_time = tv.tv_sec;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003250 list_for_each_safe(qe, qen, &fcport->statsclr_pending_q) {
3251 bfa_q_deq(&fcport->statsclr_pending_q, &qe);
3252 cb = (struct bfa_cb_pending_q_s *)qe;
3253 bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
3254 fcport->stats_status);
3255 }
3256 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003257 } else {
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003258 INIT_LIST_HEAD(&fcport->statsclr_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003259 fcport->stats_status = BFA_STATUS_OK;
3260 }
3261}
3262
3263static void
3264bfa_fcport_stats_clr_timeout(void *cbarg)
3265{
3266 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3267
3268 bfa_trc(fcport->bfa, fcport->stats_qfull);
3269
3270 if (fcport->stats_qfull) {
3271 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3272 fcport->stats_qfull = BFA_FALSE;
3273 }
3274
3275 fcport->stats_status = BFA_STATUS_ETIMER;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003276 __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003277}
3278
3279static void
3280bfa_fcport_send_stats_clear(void *cbarg)
3281{
3282 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3283 struct bfi_fcport_req_s *msg;
3284
3285 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3286
3287 if (!msg) {
3288 fcport->stats_qfull = BFA_TRUE;
3289 bfa_reqq_winit(&fcport->stats_reqq_wait,
3290 bfa_fcport_send_stats_clear, fcport);
3291 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3292 &fcport->stats_reqq_wait);
3293 return;
3294 }
3295 fcport->stats_qfull = BFA_FALSE;
3296
Jing Huang6a18b162010-10-18 17:08:54 -07003297 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003298 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003299 bfa_fn_lpu(fcport->bfa));
3300 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003301}
3302
Jing Huang5fbe25c2010-10-18 17:17:23 -07003303/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003304 * Handle trunk SCN event from firmware.
3305 */
3306static void
3307bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3308{
3309 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3310 struct bfi_fcport_trunk_link_s *tlink;
3311 struct bfa_trunk_link_attr_s *lattr;
3312 enum bfa_trunk_state state_prev;
3313 int i;
3314 int link_bm = 0;
3315
3316 bfa_trc(fcport->bfa, fcport->cfg.trunked);
Jing Huangd4b671c2010-12-26 21:46:35 -08003317 WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
3318 scn->trunk_state != BFA_TRUNK_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003319
3320 bfa_trc(fcport->bfa, trunk->attr.state);
3321 bfa_trc(fcport->bfa, scn->trunk_state);
3322 bfa_trc(fcport->bfa, scn->trunk_speed);
3323
Jing Huang5fbe25c2010-10-18 17:17:23 -07003324 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003325 * Save off new state for trunk attribute query
3326 */
3327 state_prev = trunk->attr.state;
3328 if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
3329 trunk->attr.state = scn->trunk_state;
3330 trunk->attr.speed = scn->trunk_speed;
3331 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3332 lattr = &trunk->attr.link_attr[i];
3333 tlink = &scn->tlink[i];
3334
3335 lattr->link_state = tlink->state;
3336 lattr->trunk_wwn = tlink->trunk_wwn;
3337 lattr->fctl = tlink->fctl;
3338 lattr->speed = tlink->speed;
Jing Huangba816ea2010-10-18 17:10:50 -07003339 lattr->deskew = be32_to_cpu(tlink->deskew);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003340
3341 if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
3342 fcport->speed = tlink->speed;
3343 fcport->topology = BFA_PORT_TOPOLOGY_P2P;
3344 link_bm |= 1 << i;
3345 }
3346
3347 bfa_trc(fcport->bfa, lattr->link_state);
3348 bfa_trc(fcport->bfa, lattr->trunk_wwn);
3349 bfa_trc(fcport->bfa, lattr->fctl);
3350 bfa_trc(fcport->bfa, lattr->speed);
3351 bfa_trc(fcport->bfa, lattr->deskew);
3352 }
3353
3354 switch (link_bm) {
3355 case 3:
3356 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3357 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
3358 break;
3359 case 2:
3360 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3361 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
3362 break;
3363 case 1:
3364 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3365 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
3366 break;
3367 default:
3368 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3369 BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
3370 }
3371
Jing Huang5fbe25c2010-10-18 17:17:23 -07003372 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003373 * Notify upper layers if trunk state changed.
3374 */
3375 if ((state_prev != trunk->attr.state) ||
3376 (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
3377 bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
3378 BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
3379 }
3380}
3381
3382static void
3383bfa_trunk_iocdisable(struct bfa_s *bfa)
3384{
3385 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3386 int i = 0;
3387
Jing Huang5fbe25c2010-10-18 17:17:23 -07003388 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003389 * In trunked mode, notify upper layers that link is down
3390 */
3391 if (fcport->cfg.trunked) {
3392 if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
3393 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
3394
3395 fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
3396 fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
3397 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3398 fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
3399 fcport->trunk.attr.link_attr[i].fctl =
3400 BFA_TRUNK_LINK_FCTL_NORMAL;
3401 fcport->trunk.attr.link_attr[i].link_state =
3402 BFA_TRUNK_LINK_STATE_DN_LINKDN;
3403 fcport->trunk.attr.link_attr[i].speed =
3404 BFA_PORT_SPEED_UNKNOWN;
3405 fcport->trunk.attr.link_attr[i].deskew = 0;
3406 }
3407 }
3408}
3409
Jing Huang5fbe25c2010-10-18 17:17:23 -07003410/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003411 * Called to initialize port attributes
3412 */
3413void
3414bfa_fcport_init(struct bfa_s *bfa)
3415{
3416 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3417
Jing Huang5fbe25c2010-10-18 17:17:23 -07003418 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003419 * Initialize port attributes from IOC hardware data.
3420 */
3421 bfa_fcport_set_wwns(fcport);
3422 if (fcport->cfg.maxfrsize == 0)
3423 fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
3424 fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
3425 fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
3426
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003427 if (bfa_fcport_is_pbcdisabled(bfa))
3428 bfa->modules.port.pbc_disabled = BFA_TRUE;
3429
Jing Huangd4b671c2010-12-26 21:46:35 -08003430 WARN_ON(!fcport->cfg.maxfrsize);
3431 WARN_ON(!fcport->cfg.rx_bbcredit);
3432 WARN_ON(!fcport->speed_sup);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003433}
3434
Jing Huang5fbe25c2010-10-18 17:17:23 -07003435/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003436 * Firmware message handler.
3437 */
3438void
3439bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
3440{
3441 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3442 union bfi_fcport_i2h_msg_u i2hmsg;
3443
3444 i2hmsg.msg = msg;
3445 fcport->event_arg.i2hmsg = i2hmsg;
3446
3447 bfa_trc(bfa, msg->mhdr.msg_id);
3448 bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
3449
3450 switch (msg->mhdr.msg_id) {
3451 case BFI_FCPORT_I2H_ENABLE_RSP:
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003452 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
3453
3454 if (fcport->use_flash_cfg) {
3455 fcport->cfg = i2hmsg.penable_rsp->port_cfg;
3456 fcport->cfg.maxfrsize =
3457 cpu_to_be16(fcport->cfg.maxfrsize);
3458 fcport->cfg.path_tov =
3459 cpu_to_be16(fcport->cfg.path_tov);
3460 fcport->cfg.q_depth =
3461 cpu_to_be16(fcport->cfg.q_depth);
3462
3463 if (fcport->cfg.trunked)
3464 fcport->trunk.attr.state =
3465 BFA_TRUNK_OFFLINE;
3466 else
3467 fcport->trunk.attr.state =
3468 BFA_TRUNK_DISABLED;
3469 fcport->use_flash_cfg = BFA_FALSE;
3470 }
3471
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07003472 if (fcport->cfg.qos_enabled)
3473 fcport->qos_attr.state = BFA_QOS_OFFLINE;
3474 else
3475 fcport->qos_attr.state = BFA_QOS_DISABLED;
3476
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003477 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003478 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003479 break;
3480
3481 case BFI_FCPORT_I2H_DISABLE_RSP:
3482 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
3483 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
3484 break;
3485
3486 case BFI_FCPORT_I2H_EVENT:
3487 if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
3488 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
3489 else
3490 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
3491 break;
3492
3493 case BFI_FCPORT_I2H_TRUNK_SCN:
3494 bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
3495 break;
3496
3497 case BFI_FCPORT_I2H_STATS_GET_RSP:
3498 /*
3499 * check for timer pop before processing the rsp
3500 */
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003501 if (list_empty(&fcport->stats_pending_q) ||
3502 (fcport->stats_status == BFA_STATUS_ETIMER))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003503 break;
3504
3505 bfa_timer_stop(&fcport->timer);
3506 fcport->stats_status = i2hmsg.pstatsget_rsp->status;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003507 __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003508 break;
3509
3510 case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
3511 /*
3512 * check for timer pop before processing the rsp
3513 */
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003514 if (list_empty(&fcport->statsclr_pending_q) ||
3515 (fcport->stats_status == BFA_STATUS_ETIMER))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003516 break;
3517
3518 bfa_timer_stop(&fcport->timer);
3519 fcport->stats_status = BFA_STATUS_OK;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003520 __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003521 break;
3522
3523 case BFI_FCPORT_I2H_ENABLE_AEN:
3524 bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
3525 break;
3526
3527 case BFI_FCPORT_I2H_DISABLE_AEN:
3528 bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
3529 break;
3530
3531 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08003532 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003533 break;
3534 }
3535}
3536
Jing Huang5fbe25c2010-10-18 17:17:23 -07003537/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003538 * Registered callback for port events.
3539 */
3540void
3541bfa_fcport_event_register(struct bfa_s *bfa,
3542 void (*cbfn) (void *cbarg,
3543 enum bfa_port_linkstate event),
3544 void *cbarg)
3545{
3546 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3547
3548 fcport->event_cbfn = cbfn;
3549 fcport->event_cbarg = cbarg;
3550}
3551
3552bfa_status_t
3553bfa_fcport_enable(struct bfa_s *bfa)
3554{
3555 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3556
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003557 if (bfa_fcport_is_pbcdisabled(bfa))
3558 return BFA_STATUS_PBC;
3559
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003560 if (bfa_ioc_is_disabled(&bfa->ioc))
3561 return BFA_STATUS_IOC_DISABLED;
3562
3563 if (fcport->diag_busy)
3564 return BFA_STATUS_DIAG_BUSY;
3565
3566 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
3567 return BFA_STATUS_OK;
3568}
3569
3570bfa_status_t
3571bfa_fcport_disable(struct bfa_s *bfa)
3572{
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003573 if (bfa_fcport_is_pbcdisabled(bfa))
3574 return BFA_STATUS_PBC;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003575
3576 if (bfa_ioc_is_disabled(&bfa->ioc))
3577 return BFA_STATUS_IOC_DISABLED;
3578
3579 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
3580 return BFA_STATUS_OK;
3581}
3582
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003583/* If PBC is disabled on port, return error */
3584bfa_status_t
3585bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
3586{
3587 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3588 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
3589 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
3590
3591 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
3592 bfa_trc(bfa, fcport->pwwn);
3593 return BFA_STATUS_PBC;
3594 }
3595 return BFA_STATUS_OK;
3596}
3597
Jing Huang5fbe25c2010-10-18 17:17:23 -07003598/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003599 * Configure port speed.
3600 */
3601bfa_status_t
3602bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3603{
3604 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3605
3606 bfa_trc(bfa, speed);
3607
3608 if (fcport->cfg.trunked == BFA_TRUE)
3609 return BFA_STATUS_TRUNK_ENABLED;
3610 if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
3611 bfa_trc(bfa, fcport->speed_sup);
3612 return BFA_STATUS_UNSUPP_SPEED;
3613 }
3614
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07003615 /* Port speed entered needs to be checked */
3616 if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
3617 /* For CT2, 1G is not supported */
3618 if ((speed == BFA_PORT_SPEED_1GBPS) &&
3619 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
3620 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia7141342011-06-24 20:23:19 -07003621
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07003622 /* Already checked for Auto Speed and Max Speed supp */
3623 if (!(speed == BFA_PORT_SPEED_1GBPS ||
3624 speed == BFA_PORT_SPEED_2GBPS ||
3625 speed == BFA_PORT_SPEED_4GBPS ||
3626 speed == BFA_PORT_SPEED_8GBPS ||
3627 speed == BFA_PORT_SPEED_16GBPS ||
3628 speed == BFA_PORT_SPEED_AUTO))
3629 return BFA_STATUS_UNSUPP_SPEED;
3630 } else {
3631 if (speed != BFA_PORT_SPEED_10GBPS)
3632 return BFA_STATUS_UNSUPP_SPEED;
Krishna Gudipatia7141342011-06-24 20:23:19 -07003633 }
3634
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003635 fcport->cfg.speed = speed;
3636
3637 return BFA_STATUS_OK;
3638}
3639
Jing Huang5fbe25c2010-10-18 17:17:23 -07003640/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003641 * Get current speed.
3642 */
3643enum bfa_port_speed
3644bfa_fcport_get_speed(struct bfa_s *bfa)
3645{
3646 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3647
3648 return fcport->speed;
3649}
3650
Jing Huang5fbe25c2010-10-18 17:17:23 -07003651/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003652 * Configure port topology.
3653 */
3654bfa_status_t
3655bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
3656{
3657 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3658
3659 bfa_trc(bfa, topology);
3660 bfa_trc(bfa, fcport->cfg.topology);
3661
3662 switch (topology) {
3663 case BFA_PORT_TOPOLOGY_P2P:
3664 case BFA_PORT_TOPOLOGY_LOOP:
3665 case BFA_PORT_TOPOLOGY_AUTO:
3666 break;
3667
3668 default:
3669 return BFA_STATUS_EINVAL;
3670 }
3671
3672 fcport->cfg.topology = topology;
3673 return BFA_STATUS_OK;
3674}
3675
Jing Huang5fbe25c2010-10-18 17:17:23 -07003676/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003677 * Get current topology.
3678 */
3679enum bfa_port_topology
3680bfa_fcport_get_topology(struct bfa_s *bfa)
3681{
3682 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3683
3684 return fcport->topology;
3685}
3686
3687bfa_status_t
3688bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
3689{
3690 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3691
3692 bfa_trc(bfa, alpa);
3693 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3694 bfa_trc(bfa, fcport->cfg.hardalpa);
3695
3696 fcport->cfg.cfg_hardalpa = BFA_TRUE;
3697 fcport->cfg.hardalpa = alpa;
3698
3699 return BFA_STATUS_OK;
3700}
3701
3702bfa_status_t
3703bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
3704{
3705 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3706
3707 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3708 bfa_trc(bfa, fcport->cfg.hardalpa);
3709
3710 fcport->cfg.cfg_hardalpa = BFA_FALSE;
3711 return BFA_STATUS_OK;
3712}
3713
3714bfa_boolean_t
3715bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
3716{
3717 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3718
3719 *alpa = fcport->cfg.hardalpa;
3720 return fcport->cfg.cfg_hardalpa;
3721}
3722
3723u8
3724bfa_fcport_get_myalpa(struct bfa_s *bfa)
3725{
3726 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3727
3728 return fcport->myalpa;
3729}
3730
3731bfa_status_t
3732bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
3733{
3734 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3735
3736 bfa_trc(bfa, maxfrsize);
3737 bfa_trc(bfa, fcport->cfg.maxfrsize);
3738
3739 /* with in range */
3740 if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
3741 return BFA_STATUS_INVLD_DFSZ;
3742
3743 /* power of 2, if not the max frame size of 2112 */
3744 if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
3745 return BFA_STATUS_INVLD_DFSZ;
3746
3747 fcport->cfg.maxfrsize = maxfrsize;
3748 return BFA_STATUS_OK;
3749}
3750
3751u16
3752bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
3753{
3754 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3755
3756 return fcport->cfg.maxfrsize;
3757}
3758
3759u8
3760bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
3761{
3762 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3763
3764 return fcport->cfg.rx_bbcredit;
3765}
3766
3767void
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003768bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit, u8 bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003769{
3770 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3771
3772 fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003773 fcport->cfg.bb_scn = bb_scn;
3774 if (bb_scn)
3775 fcport->bbsc_op_state = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003776}
3777
Jing Huang5fbe25c2010-10-18 17:17:23 -07003778/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003779 * Get port attributes.
3780 */
3781
3782wwn_t
3783bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
3784{
3785 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3786 if (node)
3787 return fcport->nwwn;
3788 else
3789 return fcport->pwwn;
3790}
3791
3792void
3793bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3794{
3795 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3796
Jing Huang6a18b162010-10-18 17:08:54 -07003797 memset(attr, 0, sizeof(struct bfa_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003798
3799 attr->nwwn = fcport->nwwn;
3800 attr->pwwn = fcport->pwwn;
3801
Maggie Zhangf7f738122010-12-09 19:08:43 -08003802 attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
3803 attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003804
Jing Huang6a18b162010-10-18 17:08:54 -07003805 memcpy(&attr->pport_cfg, &fcport->cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003806 sizeof(struct bfa_port_cfg_s));
3807 /* speed attributes */
3808 attr->pport_cfg.speed = fcport->cfg.speed;
3809 attr->speed_supported = fcport->speed_sup;
3810 attr->speed = fcport->speed;
3811 attr->cos_supported = FC_CLASS_3;
3812
3813 /* topology attributes */
3814 attr->pport_cfg.topology = fcport->cfg.topology;
3815 attr->topology = fcport->topology;
3816 attr->pport_cfg.trunked = fcport->cfg.trunked;
3817
3818 /* beacon attributes */
3819 attr->beacon = fcport->beacon;
3820 attr->link_e2e_beacon = fcport->link_e2e_beacon;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003821
3822 attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
3823 attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
3824 attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003825 attr->bbsc_op_status = fcport->bbsc_op_state;
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003826
3827 /* PBC Disabled State */
3828 if (bfa_fcport_is_pbcdisabled(bfa))
3829 attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
3830 else {
3831 if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
3832 attr->port_state = BFA_PORT_ST_IOCDIS;
3833 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
3834 attr->port_state = BFA_PORT_ST_FWMISMATCH;
3835 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003836
3837 /* FCoE vlan */
3838 attr->fcoe_vlan = fcport->fcoe_vlan;
3839}
3840
3841#define BFA_FCPORT_STATS_TOV 1000
3842
Jing Huang5fbe25c2010-10-18 17:17:23 -07003843/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003844 * Fetch port statistics (FCQoS or FCoE).
3845 */
3846bfa_status_t
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003847bfa_fcport_get_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003848{
3849 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3850
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003851 if (bfa_ioc_is_disabled(&bfa->ioc))
3852 return BFA_STATUS_IOC_DISABLED;
3853
3854 if (!list_empty(&fcport->statsclr_pending_q))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003855 return BFA_STATUS_DEVBUSY;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003856
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003857 if (list_empty(&fcport->stats_pending_q)) {
3858 list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
3859 bfa_fcport_send_stats_get(fcport);
3860 bfa_timer_start(bfa, &fcport->timer,
3861 bfa_fcport_stats_get_timeout,
3862 fcport, BFA_FCPORT_STATS_TOV);
3863 } else
3864 list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003865
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003866 return BFA_STATUS_OK;
3867}
3868
Jing Huang5fbe25c2010-10-18 17:17:23 -07003869/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003870 * Reset port statistics (FCQoS or FCoE).
3871 */
3872bfa_status_t
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003873bfa_fcport_clear_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003874{
3875 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3876
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003877 if (!list_empty(&fcport->stats_pending_q))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003878 return BFA_STATUS_DEVBUSY;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003879
Krishna Gudipati37ea0552011-07-20 17:02:11 -07003880 if (list_empty(&fcport->statsclr_pending_q)) {
3881 list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
3882 bfa_fcport_send_stats_clear(fcport);
3883 bfa_timer_start(bfa, &fcport->timer,
3884 bfa_fcport_stats_clr_timeout,
3885 fcport, BFA_FCPORT_STATS_TOV);
3886 } else
3887 list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003888
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003889 return BFA_STATUS_OK;
3890}
3891
Jing Huang5fbe25c2010-10-18 17:17:23 -07003892/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003893 * Fetch port attributes.
3894 */
3895bfa_boolean_t
3896bfa_fcport_is_disabled(struct bfa_s *bfa)
3897{
3898 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3899
3900 return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
3901 BFA_PORT_ST_DISABLED;
3902
3903}
3904
3905bfa_boolean_t
3906bfa_fcport_is_ratelim(struct bfa_s *bfa)
3907{
3908 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3909
3910 return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
3911
3912}
3913
Jing Huang5fbe25c2010-10-18 17:17:23 -07003914/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07003915 * Enable/Disable FAA feature in port config
3916 */
3917void
3918bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state)
3919{
3920 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3921
3922 bfa_trc(bfa, state);
3923 fcport->cfg.faa_state = state;
3924}
3925
3926/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003927 * Get default minimum ratelim speed
3928 */
3929enum bfa_port_speed
3930bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
3931{
3932 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3933
3934 bfa_trc(bfa, fcport->cfg.trl_def_speed);
3935 return fcport->cfg.trl_def_speed;
3936
3937}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003938
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07003939void
3940bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
3941 bfa_boolean_t link_e2e_beacon)
3942{
3943 struct bfa_s *bfa = dev;
3944 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3945
3946 bfa_trc(bfa, beacon);
3947 bfa_trc(bfa, link_e2e_beacon);
3948 bfa_trc(bfa, fcport->beacon);
3949 bfa_trc(bfa, fcport->link_e2e_beacon);
3950
3951 fcport->beacon = beacon;
3952 fcport->link_e2e_beacon = link_e2e_beacon;
3953}
3954
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003955bfa_boolean_t
3956bfa_fcport_is_linkup(struct bfa_s *bfa)
3957{
3958 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3959
3960 return (!fcport->cfg.trunked &&
3961 bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
3962 (fcport->cfg.trunked &&
3963 fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
3964}
3965
3966bfa_boolean_t
3967bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
3968{
3969 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3970
3971 return fcport->cfg.qos_enabled;
3972}
3973
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003974bfa_boolean_t
3975bfa_fcport_is_trunk_enabled(struct bfa_s *bfa)
3976{
3977 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3978
3979 return fcport->cfg.trunked;
3980}
3981
Jing Huang5fbe25c2010-10-18 17:17:23 -07003982/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003983 * Rport State machine functions
3984 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07003985/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003986 * Beginning state, only online event expected.
3987 */
3988static void
3989bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
3990{
3991 bfa_trc(rp->bfa, rp->rport_tag);
3992 bfa_trc(rp->bfa, event);
3993
3994 switch (event) {
3995 case BFA_RPORT_SM_CREATE:
3996 bfa_stats(rp, sm_un_cr);
3997 bfa_sm_set_state(rp, bfa_rport_sm_created);
3998 break;
3999
4000 default:
4001 bfa_stats(rp, sm_un_unexp);
4002 bfa_sm_fault(rp->bfa, event);
4003 }
4004}
4005
4006static void
4007bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
4008{
4009 bfa_trc(rp->bfa, rp->rport_tag);
4010 bfa_trc(rp->bfa, event);
4011
4012 switch (event) {
4013 case BFA_RPORT_SM_ONLINE:
4014 bfa_stats(rp, sm_cr_on);
4015 if (bfa_rport_send_fwcreate(rp))
4016 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4017 else
4018 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4019 break;
4020
4021 case BFA_RPORT_SM_DELETE:
4022 bfa_stats(rp, sm_cr_del);
4023 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4024 bfa_rport_free(rp);
4025 break;
4026
4027 case BFA_RPORT_SM_HWFAIL:
4028 bfa_stats(rp, sm_cr_hwf);
4029 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4030 break;
4031
4032 default:
4033 bfa_stats(rp, sm_cr_unexp);
4034 bfa_sm_fault(rp->bfa, event);
4035 }
4036}
4037
Jing Huang5fbe25c2010-10-18 17:17:23 -07004038/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004039 * Waiting for rport create response from firmware.
4040 */
4041static void
4042bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
4043{
4044 bfa_trc(rp->bfa, rp->rport_tag);
4045 bfa_trc(rp->bfa, event);
4046
4047 switch (event) {
4048 case BFA_RPORT_SM_FWRSP:
4049 bfa_stats(rp, sm_fwc_rsp);
4050 bfa_sm_set_state(rp, bfa_rport_sm_online);
4051 bfa_rport_online_cb(rp);
4052 break;
4053
4054 case BFA_RPORT_SM_DELETE:
4055 bfa_stats(rp, sm_fwc_del);
4056 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4057 break;
4058
4059 case BFA_RPORT_SM_OFFLINE:
4060 bfa_stats(rp, sm_fwc_off);
4061 bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
4062 break;
4063
4064 case BFA_RPORT_SM_HWFAIL:
4065 bfa_stats(rp, sm_fwc_hwf);
4066 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4067 break;
4068
4069 default:
4070 bfa_stats(rp, sm_fwc_unexp);
4071 bfa_sm_fault(rp->bfa, event);
4072 }
4073}
4074
Jing Huang5fbe25c2010-10-18 17:17:23 -07004075/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004076 * Request queue is full, awaiting queue resume to send create request.
4077 */
4078static void
4079bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4080{
4081 bfa_trc(rp->bfa, rp->rport_tag);
4082 bfa_trc(rp->bfa, event);
4083
4084 switch (event) {
4085 case BFA_RPORT_SM_QRESUME:
4086 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4087 bfa_rport_send_fwcreate(rp);
4088 break;
4089
4090 case BFA_RPORT_SM_DELETE:
4091 bfa_stats(rp, sm_fwc_del);
4092 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4093 bfa_reqq_wcancel(&rp->reqq_wait);
4094 bfa_rport_free(rp);
4095 break;
4096
4097 case BFA_RPORT_SM_OFFLINE:
4098 bfa_stats(rp, sm_fwc_off);
4099 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4100 bfa_reqq_wcancel(&rp->reqq_wait);
4101 bfa_rport_offline_cb(rp);
4102 break;
4103
4104 case BFA_RPORT_SM_HWFAIL:
4105 bfa_stats(rp, sm_fwc_hwf);
4106 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4107 bfa_reqq_wcancel(&rp->reqq_wait);
4108 break;
4109
4110 default:
4111 bfa_stats(rp, sm_fwc_unexp);
4112 bfa_sm_fault(rp->bfa, event);
4113 }
4114}
4115
Jing Huang5fbe25c2010-10-18 17:17:23 -07004116/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004117 * Online state - normal parking state.
4118 */
4119static void
4120bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
4121{
4122 struct bfi_rport_qos_scn_s *qos_scn;
4123
4124 bfa_trc(rp->bfa, rp->rport_tag);
4125 bfa_trc(rp->bfa, event);
4126
4127 switch (event) {
4128 case BFA_RPORT_SM_OFFLINE:
4129 bfa_stats(rp, sm_on_off);
4130 if (bfa_rport_send_fwdelete(rp))
4131 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4132 else
4133 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4134 break;
4135
4136 case BFA_RPORT_SM_DELETE:
4137 bfa_stats(rp, sm_on_del);
4138 if (bfa_rport_send_fwdelete(rp))
4139 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4140 else
4141 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4142 break;
4143
4144 case BFA_RPORT_SM_HWFAIL:
4145 bfa_stats(rp, sm_on_hwf);
4146 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4147 break;
4148
4149 case BFA_RPORT_SM_SET_SPEED:
4150 bfa_rport_send_fwspeed(rp);
4151 break;
4152
4153 case BFA_RPORT_SM_QOS_SCN:
4154 qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
4155 rp->qos_attr = qos_scn->new_qos_attr;
4156 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
4157 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
4158 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
4159 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
4160
4161 qos_scn->old_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004162 be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004163 qos_scn->new_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004164 be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004165
4166 if (qos_scn->old_qos_attr.qos_flow_id !=
4167 qos_scn->new_qos_attr.qos_flow_id)
4168 bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
4169 qos_scn->old_qos_attr,
4170 qos_scn->new_qos_attr);
4171 if (qos_scn->old_qos_attr.qos_priority !=
4172 qos_scn->new_qos_attr.qos_priority)
4173 bfa_cb_rport_qos_scn_prio(rp->rport_drv,
4174 qos_scn->old_qos_attr,
4175 qos_scn->new_qos_attr);
4176 break;
4177
4178 default:
4179 bfa_stats(rp, sm_on_unexp);
4180 bfa_sm_fault(rp->bfa, event);
4181 }
4182}
4183
Jing Huang5fbe25c2010-10-18 17:17:23 -07004184/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004185 * Firmware rport is being deleted - awaiting f/w response.
4186 */
4187static void
4188bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
4189{
4190 bfa_trc(rp->bfa, rp->rport_tag);
4191 bfa_trc(rp->bfa, event);
4192
4193 switch (event) {
4194 case BFA_RPORT_SM_FWRSP:
4195 bfa_stats(rp, sm_fwd_rsp);
4196 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4197 bfa_rport_offline_cb(rp);
4198 break;
4199
4200 case BFA_RPORT_SM_DELETE:
4201 bfa_stats(rp, sm_fwd_del);
4202 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4203 break;
4204
4205 case BFA_RPORT_SM_HWFAIL:
4206 bfa_stats(rp, sm_fwd_hwf);
4207 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4208 bfa_rport_offline_cb(rp);
4209 break;
4210
4211 default:
4212 bfa_stats(rp, sm_fwd_unexp);
4213 bfa_sm_fault(rp->bfa, event);
4214 }
4215}
4216
4217static void
4218bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4219{
4220 bfa_trc(rp->bfa, rp->rport_tag);
4221 bfa_trc(rp->bfa, event);
4222
4223 switch (event) {
4224 case BFA_RPORT_SM_QRESUME:
4225 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4226 bfa_rport_send_fwdelete(rp);
4227 break;
4228
4229 case BFA_RPORT_SM_DELETE:
4230 bfa_stats(rp, sm_fwd_del);
4231 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4232 break;
4233
4234 case BFA_RPORT_SM_HWFAIL:
4235 bfa_stats(rp, sm_fwd_hwf);
4236 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4237 bfa_reqq_wcancel(&rp->reqq_wait);
4238 bfa_rport_offline_cb(rp);
4239 break;
4240
4241 default:
4242 bfa_stats(rp, sm_fwd_unexp);
4243 bfa_sm_fault(rp->bfa, event);
4244 }
4245}
4246
Jing Huang5fbe25c2010-10-18 17:17:23 -07004247/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004248 * Offline state.
4249 */
4250static void
4251bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
4252{
4253 bfa_trc(rp->bfa, rp->rport_tag);
4254 bfa_trc(rp->bfa, event);
4255
4256 switch (event) {
4257 case BFA_RPORT_SM_DELETE:
4258 bfa_stats(rp, sm_off_del);
4259 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4260 bfa_rport_free(rp);
4261 break;
4262
4263 case BFA_RPORT_SM_ONLINE:
4264 bfa_stats(rp, sm_off_on);
4265 if (bfa_rport_send_fwcreate(rp))
4266 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4267 else
4268 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4269 break;
4270
4271 case BFA_RPORT_SM_HWFAIL:
4272 bfa_stats(rp, sm_off_hwf);
4273 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4274 break;
4275
4276 default:
4277 bfa_stats(rp, sm_off_unexp);
4278 bfa_sm_fault(rp->bfa, event);
4279 }
4280}
4281
Jing Huang5fbe25c2010-10-18 17:17:23 -07004282/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004283 * Rport is deleted, waiting for firmware response to delete.
4284 */
4285static void
4286bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
4287{
4288 bfa_trc(rp->bfa, rp->rport_tag);
4289 bfa_trc(rp->bfa, event);
4290
4291 switch (event) {
4292 case BFA_RPORT_SM_FWRSP:
4293 bfa_stats(rp, sm_del_fwrsp);
4294 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4295 bfa_rport_free(rp);
4296 break;
4297
4298 case BFA_RPORT_SM_HWFAIL:
4299 bfa_stats(rp, sm_del_hwf);
4300 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4301 bfa_rport_free(rp);
4302 break;
4303
4304 default:
4305 bfa_sm_fault(rp->bfa, event);
4306 }
4307}
4308
4309static void
4310bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4311{
4312 bfa_trc(rp->bfa, rp->rport_tag);
4313 bfa_trc(rp->bfa, event);
4314
4315 switch (event) {
4316 case BFA_RPORT_SM_QRESUME:
4317 bfa_stats(rp, sm_del_fwrsp);
4318 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4319 bfa_rport_send_fwdelete(rp);
4320 break;
4321
4322 case BFA_RPORT_SM_HWFAIL:
4323 bfa_stats(rp, sm_del_hwf);
4324 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4325 bfa_reqq_wcancel(&rp->reqq_wait);
4326 bfa_rport_free(rp);
4327 break;
4328
4329 default:
4330 bfa_sm_fault(rp->bfa, event);
4331 }
4332}
4333
Jing Huang5fbe25c2010-10-18 17:17:23 -07004334/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004335 * Waiting for rport create response from firmware. A delete is pending.
4336 */
4337static void
4338bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
4339 enum bfa_rport_event event)
4340{
4341 bfa_trc(rp->bfa, rp->rport_tag);
4342 bfa_trc(rp->bfa, event);
4343
4344 switch (event) {
4345 case BFA_RPORT_SM_FWRSP:
4346 bfa_stats(rp, sm_delp_fwrsp);
4347 if (bfa_rport_send_fwdelete(rp))
4348 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4349 else
4350 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4351 break;
4352
4353 case BFA_RPORT_SM_HWFAIL:
4354 bfa_stats(rp, sm_delp_hwf);
4355 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4356 bfa_rport_free(rp);
4357 break;
4358
4359 default:
4360 bfa_stats(rp, sm_delp_unexp);
4361 bfa_sm_fault(rp->bfa, event);
4362 }
4363}
4364
Jing Huang5fbe25c2010-10-18 17:17:23 -07004365/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004366 * Waiting for rport create response from firmware. Rport offline is pending.
4367 */
4368static void
4369bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
4370 enum bfa_rport_event event)
4371{
4372 bfa_trc(rp->bfa, rp->rport_tag);
4373 bfa_trc(rp->bfa, event);
4374
4375 switch (event) {
4376 case BFA_RPORT_SM_FWRSP:
4377 bfa_stats(rp, sm_offp_fwrsp);
4378 if (bfa_rport_send_fwdelete(rp))
4379 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4380 else
4381 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4382 break;
4383
4384 case BFA_RPORT_SM_DELETE:
4385 bfa_stats(rp, sm_offp_del);
4386 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4387 break;
4388
4389 case BFA_RPORT_SM_HWFAIL:
4390 bfa_stats(rp, sm_offp_hwf);
4391 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4392 break;
4393
4394 default:
4395 bfa_stats(rp, sm_offp_unexp);
4396 bfa_sm_fault(rp->bfa, event);
4397 }
4398}
4399
Jing Huang5fbe25c2010-10-18 17:17:23 -07004400/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004401 * IOC h/w failed.
4402 */
4403static void
4404bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
4405{
4406 bfa_trc(rp->bfa, rp->rport_tag);
4407 bfa_trc(rp->bfa, event);
4408
4409 switch (event) {
4410 case BFA_RPORT_SM_OFFLINE:
4411 bfa_stats(rp, sm_iocd_off);
4412 bfa_rport_offline_cb(rp);
4413 break;
4414
4415 case BFA_RPORT_SM_DELETE:
4416 bfa_stats(rp, sm_iocd_del);
4417 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4418 bfa_rport_free(rp);
4419 break;
4420
4421 case BFA_RPORT_SM_ONLINE:
4422 bfa_stats(rp, sm_iocd_on);
4423 if (bfa_rport_send_fwcreate(rp))
4424 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4425 else
4426 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4427 break;
4428
4429 case BFA_RPORT_SM_HWFAIL:
4430 break;
4431
4432 default:
4433 bfa_stats(rp, sm_iocd_unexp);
4434 bfa_sm_fault(rp->bfa, event);
4435 }
4436}
4437
4438
4439
Jing Huang5fbe25c2010-10-18 17:17:23 -07004440/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004441 * bfa_rport_private BFA rport private functions
4442 */
4443
4444static void
4445__bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
4446{
4447 struct bfa_rport_s *rp = cbarg;
4448
4449 if (complete)
4450 bfa_cb_rport_online(rp->rport_drv);
4451}
4452
4453static void
4454__bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
4455{
4456 struct bfa_rport_s *rp = cbarg;
4457
4458 if (complete)
4459 bfa_cb_rport_offline(rp->rport_drv);
4460}
4461
4462static void
4463bfa_rport_qresume(void *cbarg)
4464{
4465 struct bfa_rport_s *rp = cbarg;
4466
4467 bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
4468}
4469
4470static void
Krishna Gudipati45070252011-06-24 20:24:29 -07004471bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
4472 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004473{
Krishna Gudipati45070252011-06-24 20:24:29 -07004474 struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa);
4475
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004476 if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
4477 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
4478
Krishna Gudipati45070252011-06-24 20:24:29 -07004479 /* kva memory */
4480 bfa_mem_kva_setup(minfo, rport_kva,
4481 cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004482}
4483
4484static void
4485bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07004486 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004487{
4488 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4489 struct bfa_rport_s *rp;
4490 u16 i;
4491
4492 INIT_LIST_HEAD(&mod->rp_free_q);
4493 INIT_LIST_HEAD(&mod->rp_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004494 INIT_LIST_HEAD(&mod->rp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004495
Krishna Gudipati45070252011-06-24 20:24:29 -07004496 rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004497 mod->rps_list = rp;
4498 mod->num_rports = cfg->fwcfg.num_rports;
4499
Jing Huangd4b671c2010-12-26 21:46:35 -08004500 WARN_ON(!mod->num_rports ||
4501 (mod->num_rports & (mod->num_rports - 1)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004502
4503 for (i = 0; i < mod->num_rports; i++, rp++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004504 memset(rp, 0, sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004505 rp->bfa = bfa;
4506 rp->rport_tag = i;
4507 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4508
Jing Huang5fbe25c2010-10-18 17:17:23 -07004509 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004510 * - is unused
4511 */
4512 if (i)
4513 list_add_tail(&rp->qe, &mod->rp_free_q);
4514
4515 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
4516 }
4517
Jing Huang5fbe25c2010-10-18 17:17:23 -07004518 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004519 * consume memory
4520 */
Krishna Gudipati45070252011-06-24 20:24:29 -07004521 bfa_mem_kva_curp(mod) = (u8 *) rp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004522}
4523
4524static void
4525bfa_rport_detach(struct bfa_s *bfa)
4526{
4527}
4528
4529static void
4530bfa_rport_start(struct bfa_s *bfa)
4531{
4532}
4533
4534static void
4535bfa_rport_stop(struct bfa_s *bfa)
4536{
4537}
4538
4539static void
4540bfa_rport_iocdisable(struct bfa_s *bfa)
4541{
4542 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4543 struct bfa_rport_s *rport;
4544 struct list_head *qe, *qen;
4545
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004546 /* Enqueue unused rport resources to free_q */
4547 list_splice_tail_init(&mod->rp_unused_q, &mod->rp_free_q);
4548
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004549 list_for_each_safe(qe, qen, &mod->rp_active_q) {
4550 rport = (struct bfa_rport_s *) qe;
4551 bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
4552 }
4553}
4554
4555static struct bfa_rport_s *
4556bfa_rport_alloc(struct bfa_rport_mod_s *mod)
4557{
4558 struct bfa_rport_s *rport;
4559
4560 bfa_q_deq(&mod->rp_free_q, &rport);
4561 if (rport)
4562 list_add_tail(&rport->qe, &mod->rp_active_q);
4563
4564 return rport;
4565}
4566
4567static void
4568bfa_rport_free(struct bfa_rport_s *rport)
4569{
4570 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
4571
Jing Huangd4b671c2010-12-26 21:46:35 -08004572 WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004573 list_del(&rport->qe);
4574 list_add_tail(&rport->qe, &mod->rp_free_q);
4575}
4576
4577static bfa_boolean_t
4578bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4579{
4580 struct bfi_rport_create_req_s *m;
4581
Jing Huang5fbe25c2010-10-18 17:17:23 -07004582 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004583 * check for room in queue to send request now
4584 */
4585 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4586 if (!m) {
4587 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4588 return BFA_FALSE;
4589 }
4590
4591 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004592 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004593 m->bfa_handle = rp->rport_tag;
Jing Huangba816ea2010-10-18 17:10:50 -07004594 m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004595 m->pid = rp->rport_info.pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004596 m->lp_fwtag = bfa_lps_get_fwtag(rp->bfa, (u8)rp->rport_info.lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004597 m->local_pid = rp->rport_info.local_pid;
4598 m->fc_class = rp->rport_info.fc_class;
4599 m->vf_en = rp->rport_info.vf_en;
4600 m->vf_id = rp->rport_info.vf_id;
4601 m->cisc = rp->rport_info.cisc;
4602
Jing Huang5fbe25c2010-10-18 17:17:23 -07004603 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004604 * queue I/O message to firmware
4605 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004606 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004607 return BFA_TRUE;
4608}
4609
4610static bfa_boolean_t
4611bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4612{
4613 struct bfi_rport_delete_req_s *m;
4614
Jing Huang5fbe25c2010-10-18 17:17:23 -07004615 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004616 * check for room in queue to send request now
4617 */
4618 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4619 if (!m) {
4620 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4621 return BFA_FALSE;
4622 }
4623
4624 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004625 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004626 m->fw_handle = rp->fw_handle;
4627
Jing Huang5fbe25c2010-10-18 17:17:23 -07004628 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004629 * queue I/O message to firmware
4630 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004631 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004632 return BFA_TRUE;
4633}
4634
4635static bfa_boolean_t
4636bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4637{
4638 struct bfa_rport_speed_req_s *m;
4639
Jing Huang5fbe25c2010-10-18 17:17:23 -07004640 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004641 * check for room in queue to send request now
4642 */
4643 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4644 if (!m) {
4645 bfa_trc(rp->bfa, rp->rport_info.speed);
4646 return BFA_FALSE;
4647 }
4648
4649 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004650 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004651 m->fw_handle = rp->fw_handle;
4652 m->speed = (u8)rp->rport_info.speed;
4653
Jing Huang5fbe25c2010-10-18 17:17:23 -07004654 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004655 * queue I/O message to firmware
4656 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004657 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004658 return BFA_TRUE;
4659}
4660
4661
4662
Jing Huang5fbe25c2010-10-18 17:17:23 -07004663/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004664 * bfa_rport_public
4665 */
4666
Jing Huang5fbe25c2010-10-18 17:17:23 -07004667/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004668 * Rport interrupt processing.
4669 */
4670void
4671bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
4672{
4673 union bfi_rport_i2h_msg_u msg;
4674 struct bfa_rport_s *rp;
4675
4676 bfa_trc(bfa, m->mhdr.msg_id);
4677
4678 msg.msg = m;
4679
4680 switch (m->mhdr.msg_id) {
4681 case BFI_RPORT_I2H_CREATE_RSP:
4682 rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
4683 rp->fw_handle = msg.create_rsp->fw_handle;
4684 rp->qos_attr = msg.create_rsp->qos_attr;
Krishna Gudipati83763d52011-07-20 17:04:03 -07004685 bfa_rport_set_lunmask(bfa, rp);
Jing Huangd4b671c2010-12-26 21:46:35 -08004686 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004687 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4688 break;
4689
4690 case BFI_RPORT_I2H_DELETE_RSP:
4691 rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08004692 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
Krishna Gudipati83763d52011-07-20 17:04:03 -07004693 bfa_rport_unset_lunmask(bfa, rp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004694 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4695 break;
4696
4697 case BFI_RPORT_I2H_QOS_SCN:
4698 rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
4699 rp->event_arg.fw_msg = msg.qos_scn_evt;
4700 bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
4701 break;
4702
4703 default:
4704 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08004705 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004706 }
4707}
4708
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004709void
4710bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw)
4711{
4712 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4713 struct list_head *qe;
4714 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004715
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004716 for (i = 0; i < (mod->num_rports - num_rport_fw); i++) {
4717 bfa_q_deq_tail(&mod->rp_free_q, &qe);
4718 list_add_tail(qe, &mod->rp_unused_q);
4719 }
4720}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004721
Jing Huang5fbe25c2010-10-18 17:17:23 -07004722/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004723 * bfa_rport_api
4724 */
4725
4726struct bfa_rport_s *
4727bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
4728{
4729 struct bfa_rport_s *rp;
4730
4731 rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
4732
4733 if (rp == NULL)
4734 return NULL;
4735
4736 rp->bfa = bfa;
4737 rp->rport_drv = rport_drv;
Maggie Zhangf7f738122010-12-09 19:08:43 -08004738 memset(&rp->stats, 0, sizeof(rp->stats));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004739
Jing Huangd4b671c2010-12-26 21:46:35 -08004740 WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004741 bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
4742
4743 return rp;
4744}
4745
4746void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004747bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
4748{
Jing Huangd4b671c2010-12-26 21:46:35 -08004749 WARN_ON(rport_info->max_frmsz == 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004750
Jing Huang5fbe25c2010-10-18 17:17:23 -07004751 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004752 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
4753 * responses. Default to minimum size.
4754 */
4755 if (rport_info->max_frmsz == 0) {
4756 bfa_trc(rport->bfa, rport->rport_tag);
4757 rport_info->max_frmsz = FC_MIN_PDUSZ;
4758 }
4759
Jing Huang6a18b162010-10-18 17:08:54 -07004760 rport->rport_info = *rport_info;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004761 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
4762}
4763
4764void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004765bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
4766{
Jing Huangd4b671c2010-12-26 21:46:35 -08004767 WARN_ON(speed == 0);
4768 WARN_ON(speed == BFA_PORT_SPEED_AUTO);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004769
4770 rport->rport_info.speed = speed;
4771 bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
4772}
4773
Krishna Gudipati83763d52011-07-20 17:04:03 -07004774/* Set Rport LUN Mask */
4775void
4776bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
4777{
4778 struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
4779 wwn_t lp_wwn, rp_wwn;
4780 u8 lp_tag = (u8)rp->rport_info.lp_tag;
4781
4782 rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
4783 lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
4784
4785 BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
4786 rp->lun_mask = BFA_TRUE;
4787 bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn, rp->rport_tag, lp_tag);
4788}
4789
4790/* Unset Rport LUN mask */
4791void
4792bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
4793{
4794 struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
4795 wwn_t lp_wwn, rp_wwn;
4796
4797 rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
4798 lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
4799
4800 BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
4801 rp->lun_mask = BFA_FALSE;
4802 bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn,
4803 BFA_RPORT_TAG_INVALID, BFA_LP_TAG_INVALID);
4804}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004805
Jing Huang5fbe25c2010-10-18 17:17:23 -07004806/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004807 * SGPG related functions
4808 */
4809
Jing Huang5fbe25c2010-10-18 17:17:23 -07004810/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004811 * Compute and return memory needed by FCP(im) module.
4812 */
4813static void
Krishna Gudipati45070252011-06-24 20:24:29 -07004814bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
4815 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004816{
Krishna Gudipati45070252011-06-24 20:24:29 -07004817 struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa);
4818 struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa);
4819 struct bfa_mem_dma_s *seg_ptr;
4820 u16 nsegs, idx, per_seg_sgpg, num_sgpg;
4821 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
4822
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004823 if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
4824 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
Krishna Gudipati45070252011-06-24 20:24:29 -07004825 else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX)
4826 cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004827
Krishna Gudipati45070252011-06-24 20:24:29 -07004828 num_sgpg = cfg->drvcfg.num_sgpgs;
4829
4830 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
4831 per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz);
4832
4833 bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) {
4834 if (num_sgpg >= per_seg_sgpg) {
4835 num_sgpg -= per_seg_sgpg;
4836 bfa_mem_dma_setup(minfo, seg_ptr,
4837 per_seg_sgpg * sgpg_sz);
4838 } else
4839 bfa_mem_dma_setup(minfo, seg_ptr,
4840 num_sgpg * sgpg_sz);
4841 }
4842
4843 /* kva memory */
4844 bfa_mem_kva_setup(minfo, sgpg_kva,
4845 cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004846}
4847
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004848static void
4849bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07004850 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004851{
4852 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004853 struct bfa_sgpg_s *hsgpg;
4854 struct bfi_sgpg_s *sgpg;
4855 u64 align_len;
Krishna Gudipati45070252011-06-24 20:24:29 -07004856 struct bfa_mem_dma_s *seg_ptr;
4857 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
4858 u16 i, idx, nsegs, per_seg_sgpg, num_sgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004859
4860 union {
4861 u64 pa;
4862 union bfi_addr_u addr;
4863 } sgpg_pa, sgpg_pa_tmp;
4864
4865 INIT_LIST_HEAD(&mod->sgpg_q);
4866 INIT_LIST_HEAD(&mod->sgpg_wait_q);
4867
4868 bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
4869
Krishna Gudipati45070252011-06-24 20:24:29 -07004870 mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004871
Krishna Gudipati45070252011-06-24 20:24:29 -07004872 num_sgpg = cfg->drvcfg.num_sgpgs;
4873 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004874
Krishna Gudipati45070252011-06-24 20:24:29 -07004875 /* dma/kva mem claim */
4876 hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004877
Krishna Gudipati45070252011-06-24 20:24:29 -07004878 bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004879
Krishna Gudipati45070252011-06-24 20:24:29 -07004880 if (!bfa_mem_dma_virt(seg_ptr))
4881 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004882
Krishna Gudipati45070252011-06-24 20:24:29 -07004883 align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) -
4884 bfa_mem_dma_phys(seg_ptr);
4885
4886 sgpg = (struct bfi_sgpg_s *)
4887 (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len);
4888 sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len;
4889 WARN_ON(sgpg_pa.pa & (sgpg_sz - 1));
4890
4891 per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz;
4892
4893 for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) {
4894 memset(hsgpg, 0, sizeof(*hsgpg));
4895 memset(sgpg, 0, sizeof(*sgpg));
4896
4897 hsgpg->sgpg = sgpg;
4898 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
4899 hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
4900 list_add_tail(&hsgpg->qe, &mod->sgpg_q);
4901
4902 sgpg++;
4903 hsgpg++;
4904 sgpg_pa.pa += sgpg_sz;
4905 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004906 }
4907
Krishna Gudipati45070252011-06-24 20:24:29 -07004908 bfa_mem_kva_curp(mod) = (u8 *) hsgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004909}
4910
4911static void
4912bfa_sgpg_detach(struct bfa_s *bfa)
4913{
4914}
4915
4916static void
4917bfa_sgpg_start(struct bfa_s *bfa)
4918{
4919}
4920
4921static void
4922bfa_sgpg_stop(struct bfa_s *bfa)
4923{
4924}
4925
4926static void
4927bfa_sgpg_iocdisable(struct bfa_s *bfa)
4928{
4929}
4930
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004931bfa_status_t
4932bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
4933{
4934 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4935 struct bfa_sgpg_s *hsgpg;
4936 int i;
4937
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004938 if (mod->free_sgpgs < nsgpgs)
4939 return BFA_STATUS_ENOMEM;
4940
4941 for (i = 0; i < nsgpgs; i++) {
4942 bfa_q_deq(&mod->sgpg_q, &hsgpg);
Jing Huangd4b671c2010-12-26 21:46:35 -08004943 WARN_ON(!hsgpg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004944 list_add_tail(&hsgpg->qe, sgpg_q);
4945 }
4946
4947 mod->free_sgpgs -= nsgpgs;
4948 return BFA_STATUS_OK;
4949}
4950
4951void
4952bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
4953{
4954 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4955 struct bfa_sgpg_wqe_s *wqe;
4956
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004957 mod->free_sgpgs += nsgpg;
Jing Huangd4b671c2010-12-26 21:46:35 -08004958 WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004959
4960 list_splice_tail_init(sgpg_q, &mod->sgpg_q);
4961
4962 if (list_empty(&mod->sgpg_wait_q))
4963 return;
4964
Jing Huang5fbe25c2010-10-18 17:17:23 -07004965 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004966 * satisfy as many waiting requests as possible
4967 */
4968 do {
4969 wqe = bfa_q_first(&mod->sgpg_wait_q);
4970 if (mod->free_sgpgs < wqe->nsgpg)
4971 nsgpg = mod->free_sgpgs;
4972 else
4973 nsgpg = wqe->nsgpg;
4974 bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
4975 wqe->nsgpg -= nsgpg;
4976 if (wqe->nsgpg == 0) {
4977 list_del(&wqe->qe);
4978 wqe->cbfn(wqe->cbarg);
4979 }
4980 } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
4981}
4982
4983void
4984bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
4985{
4986 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4987
Jing Huangd4b671c2010-12-26 21:46:35 -08004988 WARN_ON(nsgpg <= 0);
4989 WARN_ON(nsgpg <= mod->free_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004990
4991 wqe->nsgpg_total = wqe->nsgpg = nsgpg;
4992
Jing Huang5fbe25c2010-10-18 17:17:23 -07004993 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004994 * allocate any left to this one first
4995 */
4996 if (mod->free_sgpgs) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07004997 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004998 * no one else is waiting for SGPG
4999 */
Jing Huangd4b671c2010-12-26 21:46:35 -08005000 WARN_ON(!list_empty(&mod->sgpg_wait_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005001 list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
5002 wqe->nsgpg -= mod->free_sgpgs;
5003 mod->free_sgpgs = 0;
5004 }
5005
5006 list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
5007}
5008
5009void
5010bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
5011{
5012 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
5013
Jing Huangd4b671c2010-12-26 21:46:35 -08005014 WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005015 list_del(&wqe->qe);
5016
5017 if (wqe->nsgpg_total != wqe->nsgpg)
5018 bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
5019 wqe->nsgpg_total - wqe->nsgpg);
5020}
5021
5022void
5023bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
5024 void *cbarg)
5025{
5026 INIT_LIST_HEAD(&wqe->sgpg_q);
5027 wqe->cbfn = cbfn;
5028 wqe->cbarg = cbarg;
5029}
5030
Jing Huang5fbe25c2010-10-18 17:17:23 -07005031/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005032 * UF related functions
5033 */
5034/*
5035 *****************************************************************************
5036 * Internal functions
5037 *****************************************************************************
5038 */
5039static void
5040__bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
5041{
5042 struct bfa_uf_s *uf = cbarg;
5043 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
5044
5045 if (complete)
5046 ufm->ufrecv(ufm->cbarg, uf);
5047}
5048
5049static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005050claim_uf_post_msgs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005051{
5052 struct bfi_uf_buf_post_s *uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005053 u16 i;
5054 u16 buf_len;
5055
Krishna Gudipati45070252011-06-24 20:24:29 -07005056 ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005057 uf_bp_msg = ufm->uf_buf_posts;
5058
5059 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
5060 i++, uf_bp_msg++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005061 memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005062
5063 uf_bp_msg->buf_tag = i;
5064 buf_len = sizeof(struct bfa_uf_buf_s);
Jing Huangba816ea2010-10-18 17:10:50 -07005065 uf_bp_msg->buf_len = cpu_to_be16(buf_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005066 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005067 bfa_fn_lpu(ufm->bfa));
Krishna Gudipati85ce9282011-06-13 15:39:36 -07005068 bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005069 }
5070
Jing Huang5fbe25c2010-10-18 17:17:23 -07005071 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005072 * advance pointer beyond consumed memory
5073 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005074 bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005075}
5076
5077static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005078claim_ufs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005079{
5080 u16 i;
5081 struct bfa_uf_s *uf;
5082
5083 /*
5084 * Claim block of memory for UF list
5085 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005086 ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005087
5088 /*
5089 * Initialize UFs and queue it in UF free queue
5090 */
5091 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005092 memset(uf, 0, sizeof(struct bfa_uf_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005093 uf->bfa = ufm->bfa;
5094 uf->uf_tag = i;
Krishna Gudipati45070252011-06-24 20:24:29 -07005095 uf->pb_len = BFA_PER_UF_DMA_SZ;
5096 uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005097 uf->buf_pa = ufm_pbs_pa(ufm, i);
5098 list_add_tail(&uf->qe, &ufm->uf_free_q);
5099 }
5100
Jing Huang5fbe25c2010-10-18 17:17:23 -07005101 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005102 * advance memory pointer
5103 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005104 bfa_mem_kva_curp(ufm) = (u8 *) uf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005105}
5106
5107static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005108uf_mem_claim(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005109{
Krishna Gudipati45070252011-06-24 20:24:29 -07005110 claim_ufs(ufm);
5111 claim_uf_post_msgs(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005112}
5113
5114static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005115bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
5116 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005117{
Krishna Gudipati45070252011-06-24 20:24:29 -07005118 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5119 struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa);
5120 u32 num_ufs = cfg->fwcfg.num_uf_bufs;
5121 struct bfa_mem_dma_s *seg_ptr;
5122 u16 nsegs, idx, per_seg_uf = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005123
Krishna Gudipati45070252011-06-24 20:24:29 -07005124 nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ);
5125 per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005126
Krishna Gudipati45070252011-06-24 20:24:29 -07005127 bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) {
5128 if (num_ufs >= per_seg_uf) {
5129 num_ufs -= per_seg_uf;
5130 bfa_mem_dma_setup(minfo, seg_ptr,
5131 per_seg_uf * BFA_PER_UF_DMA_SZ);
5132 } else
5133 bfa_mem_dma_setup(minfo, seg_ptr,
5134 num_ufs * BFA_PER_UF_DMA_SZ);
5135 }
5136
5137 /* kva memory */
5138 bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs *
5139 (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005140}
5141
5142static void
5143bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07005144 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005145{
5146 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5147
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005148 ufm->bfa = bfa;
5149 ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
5150 INIT_LIST_HEAD(&ufm->uf_free_q);
5151 INIT_LIST_HEAD(&ufm->uf_posted_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005152 INIT_LIST_HEAD(&ufm->uf_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005153
Krishna Gudipati45070252011-06-24 20:24:29 -07005154 uf_mem_claim(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005155}
5156
5157static void
5158bfa_uf_detach(struct bfa_s *bfa)
5159{
5160}
5161
5162static struct bfa_uf_s *
5163bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
5164{
5165 struct bfa_uf_s *uf;
5166
5167 bfa_q_deq(&uf_mod->uf_free_q, &uf);
5168 return uf;
5169}
5170
5171static void
5172bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
5173{
5174 list_add_tail(&uf->qe, &uf_mod->uf_free_q);
5175}
5176
5177static bfa_status_t
5178bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
5179{
5180 struct bfi_uf_buf_post_s *uf_post_msg;
5181
5182 uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
5183 if (!uf_post_msg)
5184 return BFA_STATUS_FAILED;
5185
Jing Huang6a18b162010-10-18 17:08:54 -07005186 memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005187 sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005188 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP, uf_post_msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005189
5190 bfa_trc(ufm->bfa, uf->uf_tag);
5191
5192 list_add_tail(&uf->qe, &ufm->uf_posted_q);
5193 return BFA_STATUS_OK;
5194}
5195
5196static void
5197bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
5198{
5199 struct bfa_uf_s *uf;
5200
5201 while ((uf = bfa_uf_get(uf_mod)) != NULL) {
5202 if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
5203 break;
5204 }
5205}
5206
5207static void
5208uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
5209{
5210 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5211 u16 uf_tag = m->buf_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005212 struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
Krishna Gudipati45070252011-06-24 20:24:29 -07005213 struct bfa_uf_buf_s *uf_buf;
5214 uint8_t *buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005215 struct fchs_s *fchs;
5216
Krishna Gudipati45070252011-06-24 20:24:29 -07005217 uf_buf = (struct bfa_uf_buf_s *)
5218 bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len);
5219 buf = &uf_buf->d[0];
5220
Jing Huangba816ea2010-10-18 17:10:50 -07005221 m->frm_len = be16_to_cpu(m->frm_len);
5222 m->xfr_len = be16_to_cpu(m->xfr_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005223
5224 fchs = (struct fchs_s *)uf_buf;
5225
5226 list_del(&uf->qe); /* dequeue from posted queue */
5227
5228 uf->data_ptr = buf;
5229 uf->data_len = m->xfr_len;
5230
Jing Huangd4b671c2010-12-26 21:46:35 -08005231 WARN_ON(uf->data_len < sizeof(struct fchs_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005232
5233 if (uf->data_len == sizeof(struct fchs_s)) {
5234 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
5235 uf->data_len, (struct fchs_s *)buf);
5236 } else {
5237 u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
5238 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
5239 BFA_PL_EID_RX, uf->data_len,
5240 (struct fchs_s *)buf, pld_w0);
5241 }
5242
5243 if (bfa->fcs)
5244 __bfa_cb_uf_recv(uf, BFA_TRUE);
5245 else
5246 bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
5247}
5248
5249static void
5250bfa_uf_stop(struct bfa_s *bfa)
5251{
5252}
5253
5254static void
5255bfa_uf_iocdisable(struct bfa_s *bfa)
5256{
5257 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5258 struct bfa_uf_s *uf;
5259 struct list_head *qe, *qen;
5260
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005261 /* Enqueue unused uf resources to free_q */
5262 list_splice_tail_init(&ufm->uf_unused_q, &ufm->uf_free_q);
5263
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005264 list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
5265 uf = (struct bfa_uf_s *) qe;
5266 list_del(&uf->qe);
5267 bfa_uf_put(ufm, uf);
5268 }
5269}
5270
5271static void
5272bfa_uf_start(struct bfa_s *bfa)
5273{
5274 bfa_uf_post_all(BFA_UF_MOD(bfa));
5275}
5276
Jing Huang5fbe25c2010-10-18 17:17:23 -07005277/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005278 * Register handler for all unsolicted receive frames.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005279 *
5280 * @param[in] bfa BFA instance
5281 * @param[in] ufrecv receive handler function
5282 * @param[in] cbarg receive handler arg
5283 */
5284void
5285bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
5286{
5287 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5288
5289 ufm->ufrecv = ufrecv;
5290 ufm->cbarg = cbarg;
5291}
5292
Jing Huang5fbe25c2010-10-18 17:17:23 -07005293/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005294 * Free an unsolicited frame back to BFA.
5295 *
5296 * @param[in] uf unsolicited frame to be freed
5297 *
5298 * @return None
5299 */
5300void
5301bfa_uf_free(struct bfa_uf_s *uf)
5302{
5303 bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
5304 bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
5305}
5306
5307
5308
Jing Huang5fbe25c2010-10-18 17:17:23 -07005309/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005310 * uf_pub BFA uf module public functions
5311 */
5312void
5313bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5314{
5315 bfa_trc(bfa, msg->mhdr.msg_id);
5316
5317 switch (msg->mhdr.msg_id) {
5318 case BFI_UF_I2H_FRM_RCVD:
5319 uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
5320 break;
5321
5322 default:
5323 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08005324 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005325 }
5326}
5327
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005328void
5329bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw)
5330{
5331 struct bfa_uf_mod_s *mod = BFA_UF_MOD(bfa);
5332 struct list_head *qe;
5333 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005334
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005335 for (i = 0; i < (mod->num_ufs - num_uf_fw); i++) {
5336 bfa_q_deq_tail(&mod->uf_free_q, &qe);
5337 list_add_tail(qe, &mod->uf_unused_q);
5338 }
5339}
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005340
5341/*
5342 * BFA fcdiag module
5343 */
5344#define BFA_DIAG_QTEST_TOV 1000 /* msec */
5345
5346/*
5347 * Set port status to busy
5348 */
5349static void
5350bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s *fcdiag)
5351{
5352 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fcdiag->bfa);
5353
5354 if (fcdiag->lb.lock)
5355 fcport->diag_busy = BFA_TRUE;
5356 else
5357 fcport->diag_busy = BFA_FALSE;
5358}
5359
5360static void
5361bfa_fcdiag_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
5362 struct bfa_s *bfa)
5363{
5364}
5365
5366static void
5367bfa_fcdiag_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
5368 struct bfa_pcidev_s *pcidev)
5369{
5370 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5371 fcdiag->bfa = bfa;
5372 fcdiag->trcmod = bfa->trcmod;
5373 /* The common DIAG attach bfa_diag_attach() will do all memory claim */
5374}
5375
5376static void
5377bfa_fcdiag_iocdisable(struct bfa_s *bfa)
5378{
5379 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5380 bfa_trc(fcdiag, fcdiag->lb.lock);
5381 if (fcdiag->lb.lock) {
5382 fcdiag->lb.status = BFA_STATUS_IOC_FAILURE;
5383 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5384 fcdiag->lb.lock = 0;
5385 bfa_fcdiag_set_busy_status(fcdiag);
5386 }
5387}
5388
5389static void
5390bfa_fcdiag_detach(struct bfa_s *bfa)
5391{
5392}
5393
5394static void
5395bfa_fcdiag_start(struct bfa_s *bfa)
5396{
5397}
5398
5399static void
5400bfa_fcdiag_stop(struct bfa_s *bfa)
5401{
5402}
5403
5404static void
5405bfa_fcdiag_queuetest_timeout(void *cbarg)
5406{
5407 struct bfa_fcdiag_s *fcdiag = cbarg;
5408 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5409
5410 bfa_trc(fcdiag, fcdiag->qtest.all);
5411 bfa_trc(fcdiag, fcdiag->qtest.count);
5412
5413 fcdiag->qtest.timer_active = 0;
5414
5415 res->status = BFA_STATUS_ETIMER;
5416 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5417 if (fcdiag->qtest.all)
5418 res->queue = fcdiag->qtest.all;
5419
5420 bfa_trc(fcdiag, BFA_STATUS_ETIMER);
5421 fcdiag->qtest.status = BFA_STATUS_ETIMER;
5422 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5423 fcdiag->qtest.lock = 0;
5424}
5425
5426static bfa_status_t
5427bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s *fcdiag)
5428{
5429 u32 i;
5430 struct bfi_diag_qtest_req_s *req;
5431
5432 req = bfa_reqq_next(fcdiag->bfa, fcdiag->qtest.queue);
5433 if (!req)
5434 return BFA_STATUS_DEVBUSY;
5435
5436 /* build host command */
5437 bfi_h2i_set(req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_QTEST,
5438 bfa_fn_lpu(fcdiag->bfa));
5439
5440 for (i = 0; i < BFI_LMSG_PL_WSZ; i++)
5441 req->data[i] = QTEST_PAT_DEFAULT;
5442
5443 bfa_trc(fcdiag, fcdiag->qtest.queue);
5444 /* ring door bell */
5445 bfa_reqq_produce(fcdiag->bfa, fcdiag->qtest.queue, req->mh);
5446 return BFA_STATUS_OK;
5447}
5448
5449static void
5450bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s *fcdiag,
5451 bfi_diag_qtest_rsp_t *rsp)
5452{
5453 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5454 bfa_status_t status = BFA_STATUS_OK;
5455 int i;
5456
5457 /* Check timer, should still be active */
5458 if (!fcdiag->qtest.timer_active) {
5459 bfa_trc(fcdiag, fcdiag->qtest.timer_active);
5460 return;
5461 }
5462
5463 /* update count */
5464 fcdiag->qtest.count--;
5465
5466 /* Check result */
5467 for (i = 0; i < BFI_LMSG_PL_WSZ; i++) {
5468 if (rsp->data[i] != ~(QTEST_PAT_DEFAULT)) {
5469 res->status = BFA_STATUS_DATACORRUPTED;
5470 break;
5471 }
5472 }
5473
5474 if (res->status == BFA_STATUS_OK) {
5475 if (fcdiag->qtest.count > 0) {
5476 status = bfa_fcdiag_queuetest_send(fcdiag);
5477 if (status == BFA_STATUS_OK)
5478 return;
5479 else
5480 res->status = status;
5481 } else if (fcdiag->qtest.all > 0 &&
5482 fcdiag->qtest.queue < (BFI_IOC_MAX_CQS - 1)) {
5483 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
5484 fcdiag->qtest.queue++;
5485 status = bfa_fcdiag_queuetest_send(fcdiag);
5486 if (status == BFA_STATUS_OK)
5487 return;
5488 else
5489 res->status = status;
5490 }
5491 }
5492
5493 /* Stop timer when we comp all queue */
5494 if (fcdiag->qtest.timer_active) {
5495 bfa_timer_stop(&fcdiag->qtest.timer);
5496 fcdiag->qtest.timer_active = 0;
5497 }
5498 res->queue = fcdiag->qtest.queue;
5499 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5500 bfa_trc(fcdiag, res->count);
5501 bfa_trc(fcdiag, res->status);
5502 fcdiag->qtest.status = res->status;
5503 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5504 fcdiag->qtest.lock = 0;
5505}
5506
5507static void
5508bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s *fcdiag,
5509 struct bfi_diag_lb_rsp_s *rsp)
5510{
5511 struct bfa_diag_loopback_result_s *res = fcdiag->lb.result;
5512
5513 res->numtxmfrm = be32_to_cpu(rsp->res.numtxmfrm);
5514 res->numosffrm = be32_to_cpu(rsp->res.numosffrm);
5515 res->numrcvfrm = be32_to_cpu(rsp->res.numrcvfrm);
5516 res->badfrminf = be32_to_cpu(rsp->res.badfrminf);
5517 res->badfrmnum = be32_to_cpu(rsp->res.badfrmnum);
5518 res->status = rsp->res.status;
5519 fcdiag->lb.status = rsp->res.status;
5520 bfa_trc(fcdiag, fcdiag->lb.status);
5521 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5522 fcdiag->lb.lock = 0;
5523 bfa_fcdiag_set_busy_status(fcdiag);
5524}
5525
5526static bfa_status_t
5527bfa_fcdiag_loopback_send(struct bfa_fcdiag_s *fcdiag,
5528 struct bfa_diag_loopback_s *loopback)
5529{
5530 struct bfi_diag_lb_req_s *lb_req;
5531
5532 lb_req = bfa_reqq_next(fcdiag->bfa, BFA_REQQ_DIAG);
5533 if (!lb_req)
5534 return BFA_STATUS_DEVBUSY;
5535
5536 /* build host command */
5537 bfi_h2i_set(lb_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LOOPBACK,
5538 bfa_fn_lpu(fcdiag->bfa));
5539
5540 lb_req->lb_mode = loopback->lb_mode;
5541 lb_req->speed = loopback->speed;
5542 lb_req->loopcnt = loopback->loopcnt;
5543 lb_req->pattern = loopback->pattern;
5544
5545 /* ring door bell */
5546 bfa_reqq_produce(fcdiag->bfa, BFA_REQQ_DIAG, lb_req->mh);
5547
5548 bfa_trc(fcdiag, loopback->lb_mode);
5549 bfa_trc(fcdiag, loopback->speed);
5550 bfa_trc(fcdiag, loopback->loopcnt);
5551 bfa_trc(fcdiag, loopback->pattern);
5552 return BFA_STATUS_OK;
5553}
5554
5555/*
5556 * cpe/rme intr handler
5557 */
5558void
5559bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5560{
5561 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5562
5563 switch (msg->mhdr.msg_id) {
5564 case BFI_DIAG_I2H_LOOPBACK:
5565 bfa_fcdiag_loopback_comp(fcdiag,
5566 (struct bfi_diag_lb_rsp_s *) msg);
5567 break;
5568 case BFI_DIAG_I2H_QTEST:
5569 bfa_fcdiag_queuetest_comp(fcdiag, (bfi_diag_qtest_rsp_t *)msg);
5570 break;
5571 default:
5572 bfa_trc(fcdiag, msg->mhdr.msg_id);
5573 WARN_ON(1);
5574 }
5575}
5576
5577/*
5578 * Loopback test
5579 *
5580 * @param[in] *bfa - bfa data struct
5581 * @param[in] opmode - port operation mode
5582 * @param[in] speed - port speed
5583 * @param[in] lpcnt - loop count
5584 * @param[in] pat - pattern to build packet
5585 * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
5586 * @param[in] cbfn - callback function
5587 * @param[in] cbarg - callback functioin arg
5588 *
5589 * @param[out]
5590 */
5591bfa_status_t
5592bfa_fcdiag_loopback(struct bfa_s *bfa, enum bfa_port_opmode opmode,
5593 enum bfa_port_speed speed, u32 lpcnt, u32 pat,
5594 struct bfa_diag_loopback_result_s *result, bfa_cb_diag_t cbfn,
5595 void *cbarg)
5596{
5597 struct bfa_diag_loopback_s loopback;
5598 struct bfa_port_attr_s attr;
5599 bfa_status_t status;
5600 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5601
5602 if (!bfa_iocfc_is_operational(bfa))
5603 return BFA_STATUS_IOC_NON_OP;
5604
5605 /* if port is PBC disabled, return error */
5606 if (bfa_fcport_is_pbcdisabled(bfa)) {
5607 bfa_trc(fcdiag, BFA_STATUS_PBC);
5608 return BFA_STATUS_PBC;
5609 }
5610
5611 if (bfa_fcport_is_disabled(bfa) == BFA_FALSE) {
5612 bfa_trc(fcdiag, opmode);
5613 return BFA_STATUS_PORT_NOT_DISABLED;
5614 }
5615
Krishna Gudipatifb778b02011-07-20 17:01:07 -07005616 /*
5617 * Check if input speed is supported by the port mode
5618 */
5619 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
5620 if (!(speed == BFA_PORT_SPEED_1GBPS ||
5621 speed == BFA_PORT_SPEED_2GBPS ||
5622 speed == BFA_PORT_SPEED_4GBPS ||
5623 speed == BFA_PORT_SPEED_8GBPS ||
5624 speed == BFA_PORT_SPEED_16GBPS ||
5625 speed == BFA_PORT_SPEED_AUTO)) {
5626 bfa_trc(fcdiag, speed);
5627 return BFA_STATUS_UNSUPP_SPEED;
5628 }
5629 bfa_fcport_get_attr(bfa, &attr);
5630 bfa_trc(fcdiag, attr.speed_supported);
5631 if (speed > attr.speed_supported)
5632 return BFA_STATUS_UNSUPP_SPEED;
5633 } else {
5634 if (speed != BFA_PORT_SPEED_10GBPS) {
5635 bfa_trc(fcdiag, speed);
5636 return BFA_STATUS_UNSUPP_SPEED;
5637 }
5638 }
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005639
5640 /* For Mezz card, port speed entered needs to be checked */
5641 if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) {
5642 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
5643 if ((speed == BFA_PORT_SPEED_1GBPS) &&
5644 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
5645 return BFA_STATUS_UNSUPP_SPEED;
5646 if (!(speed == BFA_PORT_SPEED_1GBPS ||
5647 speed == BFA_PORT_SPEED_2GBPS ||
5648 speed == BFA_PORT_SPEED_4GBPS ||
5649 speed == BFA_PORT_SPEED_8GBPS ||
5650 speed == BFA_PORT_SPEED_16GBPS ||
5651 speed == BFA_PORT_SPEED_AUTO))
5652 return BFA_STATUS_UNSUPP_SPEED;
5653 } else {
5654 if (speed != BFA_PORT_SPEED_10GBPS)
5655 return BFA_STATUS_UNSUPP_SPEED;
5656 }
5657 }
5658
5659 /* check to see if there is another destructive diag cmd running */
5660 if (fcdiag->lb.lock) {
5661 bfa_trc(fcdiag, fcdiag->lb.lock);
5662 return BFA_STATUS_DEVBUSY;
5663 }
5664
5665 fcdiag->lb.lock = 1;
5666 loopback.lb_mode = opmode;
5667 loopback.speed = speed;
5668 loopback.loopcnt = lpcnt;
5669 loopback.pattern = pat;
5670 fcdiag->lb.result = result;
5671 fcdiag->lb.cbfn = cbfn;
5672 fcdiag->lb.cbarg = cbarg;
5673 memset(result, 0, sizeof(struct bfa_diag_loopback_result_s));
5674 bfa_fcdiag_set_busy_status(fcdiag);
5675
5676 /* Send msg to fw */
5677 status = bfa_fcdiag_loopback_send(fcdiag, &loopback);
5678 return status;
5679}
5680
5681/*
5682 * DIAG queue test command
5683 *
5684 * @param[in] *bfa - bfa data struct
5685 * @param[in] force - 1: don't do ioc op checking
5686 * @param[in] queue - queue no. to test
5687 * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
5688 * @param[in] cbfn - callback function
5689 * @param[in] *cbarg - callback functioin arg
5690 *
5691 * @param[out]
5692 */
5693bfa_status_t
5694bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 force, u32 queue,
5695 struct bfa_diag_qtest_result_s *result, bfa_cb_diag_t cbfn,
5696 void *cbarg)
5697{
5698 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5699 bfa_status_t status;
5700 bfa_trc(fcdiag, force);
5701 bfa_trc(fcdiag, queue);
5702
5703 if (!force && !bfa_iocfc_is_operational(bfa))
5704 return BFA_STATUS_IOC_NON_OP;
5705
5706 /* check to see if there is another destructive diag cmd running */
5707 if (fcdiag->qtest.lock) {
5708 bfa_trc(fcdiag, fcdiag->qtest.lock);
5709 return BFA_STATUS_DEVBUSY;
5710 }
5711
5712 /* Initialization */
5713 fcdiag->qtest.lock = 1;
5714 fcdiag->qtest.cbfn = cbfn;
5715 fcdiag->qtest.cbarg = cbarg;
5716 fcdiag->qtest.result = result;
5717 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
5718
5719 /* Init test results */
5720 fcdiag->qtest.result->status = BFA_STATUS_OK;
5721 fcdiag->qtest.result->count = 0;
5722
5723 /* send */
5724 if (queue < BFI_IOC_MAX_CQS) {
5725 fcdiag->qtest.result->queue = (u8)queue;
5726 fcdiag->qtest.queue = (u8)queue;
5727 fcdiag->qtest.all = 0;
5728 } else {
5729 fcdiag->qtest.result->queue = 0;
5730 fcdiag->qtest.queue = 0;
5731 fcdiag->qtest.all = 1;
5732 }
5733 status = bfa_fcdiag_queuetest_send(fcdiag);
5734
5735 /* Start a timer */
5736 if (status == BFA_STATUS_OK) {
5737 bfa_timer_start(bfa, &fcdiag->qtest.timer,
5738 bfa_fcdiag_queuetest_timeout, fcdiag,
5739 BFA_DIAG_QTEST_TOV);
5740 fcdiag->qtest.timer_active = 1;
5741 }
5742 return status;
5743}
5744
5745/*
5746 * DIAG PLB is running
5747 *
5748 * @param[in] *bfa - bfa data struct
5749 *
5750 * @param[out]
5751 */
5752bfa_status_t
5753bfa_fcdiag_lb_is_running(struct bfa_s *bfa)
5754{
5755 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5756 return fcdiag->lb.lock ? BFA_STATUS_DIAG_BUSY : BFA_STATUS_OK;
5757}