blob: fe99ce20ec28c9fc4aa685e517ba993694f693b6 [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 Gudipatia36c61f2010-09-15 11:50:55 -070019#include "bfa_plog.h"
20#include "bfa_cs.h"
21#include "bfa_modules.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070022
23BFA_TRC_FILE(HAL, FCXP);
24BFA_MODULE(fcxp);
25BFA_MODULE(sgpg);
26BFA_MODULE(lps);
27BFA_MODULE(fcport);
28BFA_MODULE(rport);
29BFA_MODULE(uf);
30
Jing Huang5fbe25c2010-10-18 17:17:23 -070031/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070032 * LPS related definitions
33 */
34#define BFA_LPS_MIN_LPORTS (1)
35#define BFA_LPS_MAX_LPORTS (256)
36
37/*
38 * Maximum Vports supported per physical port or vf.
39 */
40#define BFA_LPS_MAX_VPORTS_SUPP_CB 255
41#define BFA_LPS_MAX_VPORTS_SUPP_CT 190
42
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070043
Jing Huang5fbe25c2010-10-18 17:17:23 -070044/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070045 * FC PORT related definitions
46 */
47/*
48 * The port is considered disabled if corresponding physical port or IOC are
49 * disabled explicitly
50 */
51#define BFA_PORT_IS_DISABLED(bfa) \
52 ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
53 (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
54
Jing Huang5fbe25c2010-10-18 17:17:23 -070055/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070056 * BFA port state machine events
57 */
58enum bfa_fcport_sm_event {
59 BFA_FCPORT_SM_START = 1, /* start port state machine */
60 BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
61 BFA_FCPORT_SM_ENABLE = 3, /* enable port */
62 BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
63 BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
64 BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
65 BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
66 BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
67 BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
68};
69
Jing Huang5fbe25c2010-10-18 17:17:23 -070070/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070071 * BFA port link notification state machine events
72 */
73
74enum bfa_fcport_ln_sm_event {
75 BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
76 BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
77 BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
78};
79
Jing Huang5fbe25c2010-10-18 17:17:23 -070080/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070081 * RPORT related definitions
82 */
83#define bfa_rport_offline_cb(__rp) do { \
84 if ((__rp)->bfa->fcs) \
85 bfa_cb_rport_offline((__rp)->rport_drv); \
86 else { \
87 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
88 __bfa_cb_rport_offline, (__rp)); \
89 } \
90} while (0)
91
92#define bfa_rport_online_cb(__rp) do { \
93 if ((__rp)->bfa->fcs) \
94 bfa_cb_rport_online((__rp)->rport_drv); \
95 else { \
96 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
97 __bfa_cb_rport_online, (__rp)); \
98 } \
99} while (0)
100
Jing Huang5fbe25c2010-10-18 17:17:23 -0700101/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700102 * forward declarations FCXP related functions
103 */
104static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete);
105static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
106 struct bfi_fcxp_send_rsp_s *fcxp_rsp);
107static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen,
108 struct bfa_fcxp_s *fcxp, struct fchs_s *fchs);
109static void bfa_fcxp_qresume(void *cbarg);
110static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp,
111 struct bfi_fcxp_send_req_s *send_req);
112
Jing Huang5fbe25c2010-10-18 17:17:23 -0700113/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700114 * forward declarations for LPS functions
115 */
116static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
117 u32 *dm_len);
118static void bfa_lps_attach(struct bfa_s *bfa, void *bfad,
119 struct bfa_iocfc_cfg_s *cfg,
120 struct bfa_meminfo_s *meminfo,
121 struct bfa_pcidev_s *pcidev);
122static void bfa_lps_detach(struct bfa_s *bfa);
123static void bfa_lps_start(struct bfa_s *bfa);
124static void bfa_lps_stop(struct bfa_s *bfa);
125static void bfa_lps_iocdisable(struct bfa_s *bfa);
126static void bfa_lps_login_rsp(struct bfa_s *bfa,
127 struct bfi_lps_login_rsp_s *rsp);
128static void bfa_lps_logout_rsp(struct bfa_s *bfa,
129 struct bfi_lps_logout_rsp_s *rsp);
130static void bfa_lps_reqq_resume(void *lps_arg);
131static void bfa_lps_free(struct bfa_lps_s *lps);
132static void bfa_lps_send_login(struct bfa_lps_s *lps);
133static void bfa_lps_send_logout(struct bfa_lps_s *lps);
Krishna Gudipatib7044952010-12-13 16:17:42 -0800134static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700135static void bfa_lps_login_comp(struct bfa_lps_s *lps);
136static void bfa_lps_logout_comp(struct bfa_lps_s *lps);
137static void bfa_lps_cvl_event(struct bfa_lps_s *lps);
138
Jing Huang5fbe25c2010-10-18 17:17:23 -0700139/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700140 * forward declaration for LPS state machine
141 */
142static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event);
143static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event);
144static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event
145 event);
146static void bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event);
Krishna Gudipatib7044952010-12-13 16:17:42 -0800147static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps,
148 enum bfa_lps_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700149static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event);
150static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event
151 event);
152
Jing Huang5fbe25c2010-10-18 17:17:23 -0700153/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700154 * forward declaration for FC Port functions
155 */
156static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
157static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
158static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
159static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
160static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
161static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
162static void bfa_fcport_scn(struct bfa_fcport_s *fcport,
163 enum bfa_port_linkstate event, bfa_boolean_t trunk);
164static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
165 enum bfa_port_linkstate event);
166static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
167static void bfa_fcport_stats_get_timeout(void *cbarg);
168static void bfa_fcport_stats_clr_timeout(void *cbarg);
169static void bfa_trunk_iocdisable(struct bfa_s *bfa);
170
Jing Huang5fbe25c2010-10-18 17:17:23 -0700171/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700172 * forward declaration for FC PORT state machine
173 */
174static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
175 enum bfa_fcport_sm_event event);
176static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
177 enum bfa_fcport_sm_event event);
178static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
179 enum bfa_fcport_sm_event event);
180static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
181 enum bfa_fcport_sm_event event);
182static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
183 enum bfa_fcport_sm_event event);
184static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
185 enum bfa_fcport_sm_event event);
186static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
187 enum bfa_fcport_sm_event event);
188static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
189 enum bfa_fcport_sm_event event);
190static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
191 enum bfa_fcport_sm_event event);
192static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
193 enum bfa_fcport_sm_event event);
194static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
195 enum bfa_fcport_sm_event event);
196static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
197 enum bfa_fcport_sm_event event);
198
199static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
200 enum bfa_fcport_ln_sm_event event);
201static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
202 enum bfa_fcport_ln_sm_event event);
203static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
204 enum bfa_fcport_ln_sm_event event);
205static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
206 enum bfa_fcport_ln_sm_event event);
207static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
208 enum bfa_fcport_ln_sm_event event);
209static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
210 enum bfa_fcport_ln_sm_event event);
211static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
212 enum bfa_fcport_ln_sm_event event);
213
214static struct bfa_sm_table_s hal_port_sm_table[] = {
215 {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT},
216 {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT},
217 {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING},
218 {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN},
219 {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP},
220 {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT},
221 {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT},
222 {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING},
223 {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED},
224 {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED},
225 {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN},
226 {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN},
227};
228
229
Jing Huang5fbe25c2010-10-18 17:17:23 -0700230/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700231 * forward declaration for RPORT related functions
232 */
233static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod);
234static void bfa_rport_free(struct bfa_rport_s *rport);
235static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp);
236static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp);
237static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp);
238static void __bfa_cb_rport_online(void *cbarg,
239 bfa_boolean_t complete);
240static void __bfa_cb_rport_offline(void *cbarg,
241 bfa_boolean_t complete);
242
Jing Huang5fbe25c2010-10-18 17:17:23 -0700243/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700244 * forward declaration for RPORT state machine
245 */
246static void bfa_rport_sm_uninit(struct bfa_rport_s *rp,
247 enum bfa_rport_event event);
248static void bfa_rport_sm_created(struct bfa_rport_s *rp,
249 enum bfa_rport_event event);
250static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp,
251 enum bfa_rport_event event);
252static void bfa_rport_sm_online(struct bfa_rport_s *rp,
253 enum bfa_rport_event event);
254static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp,
255 enum bfa_rport_event event);
256static void bfa_rport_sm_offline(struct bfa_rport_s *rp,
257 enum bfa_rport_event event);
258static void bfa_rport_sm_deleting(struct bfa_rport_s *rp,
259 enum bfa_rport_event event);
260static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
261 enum bfa_rport_event event);
262static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
263 enum bfa_rport_event event);
264static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp,
265 enum bfa_rport_event event);
266static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp,
267 enum bfa_rport_event event);
268static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp,
269 enum bfa_rport_event event);
270static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp,
271 enum bfa_rport_event event);
272
Jing Huang5fbe25c2010-10-18 17:17:23 -0700273/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700274 * PLOG related definitions
275 */
276static int
277plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
278{
279 if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
280 (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
281 return 1;
282
283 if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
284 (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
285 return 1;
286
287 return 0;
288}
289
Maggie Zhangf16a1752010-12-09 19:12:32 -0800290static u64
291bfa_get_log_time(void)
292{
293 u64 system_time = 0;
294 struct timeval tv;
295 do_gettimeofday(&tv);
296
297 /* We are interested in seconds only. */
298 system_time = tv.tv_sec;
299 return system_time;
300}
301
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700302static void
303bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
304{
305 u16 tail;
306 struct bfa_plog_rec_s *pl_recp;
307
308 if (plog->plog_enabled == 0)
309 return;
310
311 if (plkd_validate_logrec(pl_rec)) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800312 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700313 return;
314 }
315
316 tail = plog->tail;
317
318 pl_recp = &(plog->plog_recs[tail]);
319
Jing Huang6a18b162010-10-18 17:08:54 -0700320 memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700321
Maggie Zhangf16a1752010-12-09 19:12:32 -0800322 pl_recp->tv = bfa_get_log_time();
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700323 BFA_PL_LOG_REC_INCR(plog->tail);
324
325 if (plog->head == plog->tail)
326 BFA_PL_LOG_REC_INCR(plog->head);
327}
328
329void
330bfa_plog_init(struct bfa_plog_s *plog)
331{
Jing Huang6a18b162010-10-18 17:08:54 -0700332 memset((char *)plog, 0, sizeof(struct bfa_plog_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700333
Jing Huang6a18b162010-10-18 17:08:54 -0700334 memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700335 plog->head = plog->tail = 0;
336 plog->plog_enabled = 1;
337}
338
339void
340bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
341 enum bfa_plog_eid event,
342 u16 misc, char *log_str)
343{
344 struct bfa_plog_rec_s lp;
345
346 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700347 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700348 lp.mid = mid;
349 lp.eid = event;
350 lp.log_type = BFA_PL_LOG_TYPE_STRING;
351 lp.misc = misc;
352 strncpy(lp.log_entry.string_log, log_str,
353 BFA_PL_STRING_LOG_SZ - 1);
354 lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
355 bfa_plog_add(plog, &lp);
356 }
357}
358
359void
360bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
361 enum bfa_plog_eid event,
362 u16 misc, u32 *intarr, u32 num_ints)
363{
364 struct bfa_plog_rec_s lp;
365 u32 i;
366
367 if (num_ints > BFA_PL_INT_LOG_SZ)
368 num_ints = BFA_PL_INT_LOG_SZ;
369
370 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700371 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700372 lp.mid = mid;
373 lp.eid = event;
374 lp.log_type = BFA_PL_LOG_TYPE_INT;
375 lp.misc = misc;
376
377 for (i = 0; i < num_ints; i++)
Jing Huang6a18b162010-10-18 17:08:54 -0700378 lp.log_entry.int_log[i] = intarr[i];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700379
380 lp.log_num_ints = (u8) num_ints;
381
382 bfa_plog_add(plog, &lp);
383 }
384}
385
386void
387bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
388 enum bfa_plog_eid event,
389 u16 misc, struct fchs_s *fchdr)
390{
391 struct bfa_plog_rec_s lp;
392 u32 *tmp_int = (u32 *) fchdr;
393 u32 ints[BFA_PL_INT_LOG_SZ];
394
395 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700396 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700397
398 ints[0] = tmp_int[0];
399 ints[1] = tmp_int[1];
400 ints[2] = tmp_int[4];
401
402 bfa_plog_intarr(plog, mid, event, misc, ints, 3);
403 }
404}
405
406void
407bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
408 enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
409 u32 pld_w0)
410{
411 struct bfa_plog_rec_s lp;
412 u32 *tmp_int = (u32 *) fchdr;
413 u32 ints[BFA_PL_INT_LOG_SZ];
414
415 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700416 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700417
418 ints[0] = tmp_int[0];
419 ints[1] = tmp_int[1];
420 ints[2] = tmp_int[4];
421 ints[3] = pld_w0;
422
423 bfa_plog_intarr(plog, mid, event, misc, ints, 4);
424 }
425}
426
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700427
Jing Huang5fbe25c2010-10-18 17:17:23 -0700428/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700429 * fcxp_pvt BFA FCXP private functions
430 */
431
432static void
433claim_fcxp_req_rsp_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi)
434{
435 u8 *dm_kva = NULL;
436 u64 dm_pa;
437 u32 buf_pool_sz;
438
439 dm_kva = bfa_meminfo_dma_virt(mi);
440 dm_pa = bfa_meminfo_dma_phys(mi);
441
442 buf_pool_sz = mod->req_pld_sz * mod->num_fcxps;
443
444 /*
445 * Initialize the fcxp req payload list
446 */
447 mod->req_pld_list_kva = dm_kva;
448 mod->req_pld_list_pa = dm_pa;
449 dm_kva += buf_pool_sz;
450 dm_pa += buf_pool_sz;
Jing Huang6a18b162010-10-18 17:08:54 -0700451 memset(mod->req_pld_list_kva, 0, buf_pool_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700452
453 /*
454 * Initialize the fcxp rsp payload list
455 */
456 buf_pool_sz = mod->rsp_pld_sz * mod->num_fcxps;
457 mod->rsp_pld_list_kva = dm_kva;
458 mod->rsp_pld_list_pa = dm_pa;
459 dm_kva += buf_pool_sz;
460 dm_pa += buf_pool_sz;
Jing Huang6a18b162010-10-18 17:08:54 -0700461 memset(mod->rsp_pld_list_kva, 0, buf_pool_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700462
463 bfa_meminfo_dma_virt(mi) = dm_kva;
464 bfa_meminfo_dma_phys(mi) = dm_pa;
465}
466
467static void
468claim_fcxps_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi)
469{
470 u16 i;
471 struct bfa_fcxp_s *fcxp;
472
473 fcxp = (struct bfa_fcxp_s *) bfa_meminfo_kva(mi);
Jing Huang6a18b162010-10-18 17:08:54 -0700474 memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700475
476 INIT_LIST_HEAD(&mod->fcxp_free_q);
477 INIT_LIST_HEAD(&mod->fcxp_active_q);
478
479 mod->fcxp_list = fcxp;
480
481 for (i = 0; i < mod->num_fcxps; i++) {
482 fcxp->fcxp_mod = mod;
483 fcxp->fcxp_tag = i;
484
485 list_add_tail(&fcxp->qe, &mod->fcxp_free_q);
486 bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp);
487 fcxp->reqq_waiting = BFA_FALSE;
488
489 fcxp = fcxp + 1;
490 }
491
492 bfa_meminfo_kva(mi) = (void *)fcxp;
493}
494
495static void
496bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
497 u32 *dm_len)
498{
499 u16 num_fcxp_reqs = cfg->fwcfg.num_fcxp_reqs;
500
501 if (num_fcxp_reqs == 0)
502 return;
503
504 /*
505 * Account for req/rsp payload
506 */
507 *dm_len += BFA_FCXP_MAX_IBUF_SZ * num_fcxp_reqs;
508 if (cfg->drvcfg.min_cfg)
509 *dm_len += BFA_FCXP_MAX_IBUF_SZ * num_fcxp_reqs;
510 else
511 *dm_len += BFA_FCXP_MAX_LBUF_SZ * num_fcxp_reqs;
512
513 /*
514 * Account for fcxp structs
515 */
516 *ndm_len += sizeof(struct bfa_fcxp_s) * num_fcxp_reqs;
517}
518
519static void
520bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
521 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
522{
523 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
524
Jing Huang6a18b162010-10-18 17:08:54 -0700525 memset(mod, 0, sizeof(struct bfa_fcxp_mod_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700526 mod->bfa = bfa;
527 mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
528
Jing Huang5fbe25c2010-10-18 17:17:23 -0700529 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700530 * Initialize FCXP request and response payload sizes.
531 */
532 mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
533 if (!cfg->drvcfg.min_cfg)
534 mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ;
535
536 INIT_LIST_HEAD(&mod->wait_q);
537
538 claim_fcxp_req_rsp_mem(mod, meminfo);
539 claim_fcxps_mem(mod, meminfo);
540}
541
542static void
543bfa_fcxp_detach(struct bfa_s *bfa)
544{
545}
546
547static void
548bfa_fcxp_start(struct bfa_s *bfa)
549{
550}
551
552static void
553bfa_fcxp_stop(struct bfa_s *bfa)
554{
555}
556
557static void
558bfa_fcxp_iocdisable(struct bfa_s *bfa)
559{
560 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
561 struct bfa_fcxp_s *fcxp;
562 struct list_head *qe, *qen;
563
564 list_for_each_safe(qe, qen, &mod->fcxp_active_q) {
565 fcxp = (struct bfa_fcxp_s *) qe;
566 if (fcxp->caller == NULL) {
567 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
568 BFA_STATUS_IOC_FAILURE, 0, 0, NULL);
569 bfa_fcxp_free(fcxp);
570 } else {
571 fcxp->rsp_status = BFA_STATUS_IOC_FAILURE;
572 bfa_cb_queue(bfa, &fcxp->hcb_qe,
573 __bfa_fcxp_send_cbfn, fcxp);
574 }
575 }
576}
577
578static struct bfa_fcxp_s *
579bfa_fcxp_get(struct bfa_fcxp_mod_s *fm)
580{
581 struct bfa_fcxp_s *fcxp;
582
583 bfa_q_deq(&fm->fcxp_free_q, &fcxp);
584
585 if (fcxp)
586 list_add_tail(&fcxp->qe, &fm->fcxp_active_q);
587
588 return fcxp;
589}
590
591static void
592bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
593 struct bfa_s *bfa,
594 u8 *use_ibuf,
595 u32 *nr_sgles,
596 bfa_fcxp_get_sgaddr_t *r_sga_cbfn,
597 bfa_fcxp_get_sglen_t *r_sglen_cbfn,
598 struct list_head *r_sgpg_q,
599 int n_sgles,
600 bfa_fcxp_get_sgaddr_t sga_cbfn,
601 bfa_fcxp_get_sglen_t sglen_cbfn)
602{
603
Jing Huangd4b671c2010-12-26 21:46:35 -0800604 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700605
606 bfa_trc(bfa, fcxp->fcxp_tag);
607
608 if (n_sgles == 0) {
609 *use_ibuf = 1;
610 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800611 WARN_ON(*sga_cbfn == NULL);
612 WARN_ON(*sglen_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700613
614 *use_ibuf = 0;
615 *r_sga_cbfn = sga_cbfn;
616 *r_sglen_cbfn = sglen_cbfn;
617
618 *nr_sgles = n_sgles;
619
620 /*
621 * alloc required sgpgs
622 */
623 if (n_sgles > BFI_SGE_INLINE)
Jing Huangd4b671c2010-12-26 21:46:35 -0800624 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700625 }
626
627}
628
629static void
630bfa_fcxp_init(struct bfa_fcxp_s *fcxp,
631 void *caller, struct bfa_s *bfa, int nreq_sgles,
632 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
633 bfa_fcxp_get_sglen_t req_sglen_cbfn,
634 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
635 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
636{
637
Jing Huangd4b671c2010-12-26 21:46:35 -0800638 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700639
640 bfa_trc(bfa, fcxp->fcxp_tag);
641
642 fcxp->caller = caller;
643
644 bfa_fcxp_init_reqrsp(fcxp, bfa,
645 &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn,
646 &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q,
647 nreq_sgles, req_sga_cbfn, req_sglen_cbfn);
648
649 bfa_fcxp_init_reqrsp(fcxp, bfa,
650 &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn,
651 &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q,
652 nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn);
653
654}
655
656static void
657bfa_fcxp_put(struct bfa_fcxp_s *fcxp)
658{
659 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
660 struct bfa_fcxp_wqe_s *wqe;
661
662 bfa_q_deq(&mod->wait_q, &wqe);
663 if (wqe) {
664 bfa_trc(mod->bfa, fcxp->fcxp_tag);
665
666 bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles,
667 wqe->nrsp_sgles, wqe->req_sga_cbfn,
668 wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn,
669 wqe->rsp_sglen_cbfn);
670
671 wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp);
672 return;
673 }
674
Jing Huangd4b671c2010-12-26 21:46:35 -0800675 WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700676 list_del(&fcxp->qe);
677 list_add_tail(&fcxp->qe, &mod->fcxp_free_q);
678}
679
680static void
681bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
682 bfa_status_t req_status, u32 rsp_len,
683 u32 resid_len, struct fchs_s *rsp_fchs)
684{
685 /* discarded fcxp completion */
686}
687
688static void
689__bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete)
690{
691 struct bfa_fcxp_s *fcxp = cbarg;
692
693 if (complete) {
694 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
695 fcxp->rsp_status, fcxp->rsp_len,
696 fcxp->residue_len, &fcxp->rsp_fchs);
697 } else {
698 bfa_fcxp_free(fcxp);
699 }
700}
701
702static void
703hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
704{
705 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
706 struct bfa_fcxp_s *fcxp;
Jing Huangba816ea2010-10-18 17:10:50 -0700707 u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700708
709 bfa_trc(bfa, fcxp_tag);
710
Jing Huangba816ea2010-10-18 17:10:50 -0700711 fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700712
Jing Huang5fbe25c2010-10-18 17:17:23 -0700713 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700714 * @todo f/w should not set residue to non-0 when everything
715 * is received.
716 */
717 if (fcxp_rsp->req_status == BFA_STATUS_OK)
718 fcxp_rsp->residue_len = 0;
719 else
Jing Huangba816ea2010-10-18 17:10:50 -0700720 fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700721
722 fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
723
Jing Huangd4b671c2010-12-26 21:46:35 -0800724 WARN_ON(fcxp->send_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700725
726 hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp);
727
728 if (fcxp->send_cbfn != NULL) {
729 bfa_trc(mod->bfa, (NULL == fcxp->caller));
730 if (fcxp->caller == NULL) {
731 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
732 fcxp_rsp->req_status, fcxp_rsp->rsp_len,
733 fcxp_rsp->residue_len, &fcxp_rsp->fchs);
734 /*
735 * fcxp automatically freed on return from the callback
736 */
737 bfa_fcxp_free(fcxp);
738 } else {
739 fcxp->rsp_status = fcxp_rsp->req_status;
740 fcxp->rsp_len = fcxp_rsp->rsp_len;
741 fcxp->residue_len = fcxp_rsp->residue_len;
742 fcxp->rsp_fchs = fcxp_rsp->fchs;
743
744 bfa_cb_queue(bfa, &fcxp->hcb_qe,
745 __bfa_fcxp_send_cbfn, fcxp);
746 }
747 } else {
748 bfa_trc(bfa, (NULL == fcxp->send_cbfn));
749 }
750}
751
752static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700753hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp,
754 struct fchs_s *fchs)
755{
756 /*
757 * TODO: TX ox_id
758 */
759 if (reqlen > 0) {
760 if (fcxp->use_ireqbuf) {
761 u32 pld_w0 =
762 *((u32 *) BFA_FCXP_REQ_PLD(fcxp));
763
764 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
765 BFA_PL_EID_TX,
766 reqlen + sizeof(struct fchs_s), fchs,
767 pld_w0);
768 } else {
769 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
770 BFA_PL_EID_TX,
771 reqlen + sizeof(struct fchs_s),
772 fchs);
773 }
774 } else {
775 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX,
776 reqlen + sizeof(struct fchs_s), fchs);
777 }
778}
779
780static void
781hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
782 struct bfi_fcxp_send_rsp_s *fcxp_rsp)
783{
784 if (fcxp_rsp->rsp_len > 0) {
785 if (fcxp->use_irspbuf) {
786 u32 pld_w0 =
787 *((u32 *) BFA_FCXP_RSP_PLD(fcxp));
788
789 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
790 BFA_PL_EID_RX,
791 (u16) fcxp_rsp->rsp_len,
792 &fcxp_rsp->fchs, pld_w0);
793 } else {
794 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
795 BFA_PL_EID_RX,
796 (u16) fcxp_rsp->rsp_len,
797 &fcxp_rsp->fchs);
798 }
799 } else {
800 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX,
801 (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs);
802 }
803}
804
Jing Huang5fbe25c2010-10-18 17:17:23 -0700805/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700806 * Handler to resume sending fcxp when space in available in cpe queue.
807 */
808static void
809bfa_fcxp_qresume(void *cbarg)
810{
811 struct bfa_fcxp_s *fcxp = cbarg;
812 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
813 struct bfi_fcxp_send_req_s *send_req;
814
815 fcxp->reqq_waiting = BFA_FALSE;
816 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
817 bfa_fcxp_queue(fcxp, send_req);
818}
819
Jing Huang5fbe25c2010-10-18 17:17:23 -0700820/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700821 * Queue fcxp send request to foimrware.
822 */
823static void
824bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
825{
826 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
827 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
828 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
829 struct bfa_rport_s *rport = reqi->bfa_rport;
830
831 bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
832 bfa_lpuid(bfa));
833
Jing Huangba816ea2010-10-18 17:10:50 -0700834 send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700835 if (rport) {
836 send_req->rport_fw_hndl = rport->fw_handle;
Jing Huangba816ea2010-10-18 17:10:50 -0700837 send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700838 if (send_req->max_frmsz == 0)
Jing Huangba816ea2010-10-18 17:10:50 -0700839 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700840 } else {
841 send_req->rport_fw_hndl = 0;
Jing Huangba816ea2010-10-18 17:10:50 -0700842 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700843 }
844
Jing Huangba816ea2010-10-18 17:10:50 -0700845 send_req->vf_id = cpu_to_be16(reqi->vf_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700846 send_req->lp_tag = reqi->lp_tag;
847 send_req->class = reqi->class;
848 send_req->rsp_timeout = rspi->rsp_timeout;
849 send_req->cts = reqi->cts;
850 send_req->fchs = reqi->fchs;
851
Jing Huangba816ea2010-10-18 17:10:50 -0700852 send_req->req_len = cpu_to_be32(reqi->req_tot_len);
853 send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700854
855 /*
856 * setup req sgles
857 */
858 if (fcxp->use_ireqbuf == 1) {
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700859 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700860 BFA_FCXP_REQ_PLD_PA(fcxp));
861 } else {
862 if (fcxp->nreq_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800863 WARN_ON(fcxp->nreq_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700864 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
865 fcxp->req_sga_cbfn(fcxp->caller, 0));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700866 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800867 WARN_ON(reqi->req_tot_len != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700868 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700869 }
870 }
871
872 /*
873 * setup rsp sgles
874 */
875 if (fcxp->use_irspbuf == 1) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800876 WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700877
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700878 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700879 BFA_FCXP_RSP_PLD_PA(fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700880 } else {
881 if (fcxp->nrsp_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800882 WARN_ON(fcxp->nrsp_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700883 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
884 fcxp->rsp_sga_cbfn(fcxp->caller, 0));
885
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700886 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800887 WARN_ON(rspi->rsp_maxlen != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700888 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700889 }
890 }
891
892 hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs);
893
894 bfa_reqq_produce(bfa, BFA_REQQ_FCXP);
895
896 bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP));
897 bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
898}
899
Jing Huang5fbe25c2010-10-18 17:17:23 -0700900/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700901 * Allocate an FCXP instance to send a response or to send a request
902 * that has a response. Request/response buffers are allocated by caller.
903 *
904 * @param[in] bfa BFA bfa instance
905 * @param[in] nreq_sgles Number of SG elements required for request
906 * buffer. 0, if fcxp internal buffers are used.
907 * Use bfa_fcxp_get_reqbuf() to get the
908 * internal req buffer.
909 * @param[in] req_sgles SG elements describing request buffer. Will be
910 * copied in by BFA and hence can be freed on
911 * return from this function.
912 * @param[in] get_req_sga function ptr to be called to get a request SG
913 * Address (given the sge index).
914 * @param[in] get_req_sglen function ptr to be called to get a request SG
915 * len (given the sge index).
916 * @param[in] get_rsp_sga function ptr to be called to get a response SG
917 * Address (given the sge index).
918 * @param[in] get_rsp_sglen function ptr to be called to get a response SG
919 * len (given the sge index).
920 *
921 * @return FCXP instance. NULL on failure.
922 */
923struct bfa_fcxp_s *
924bfa_fcxp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
925 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
926 bfa_fcxp_get_sglen_t req_sglen_cbfn,
927 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
928 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
929{
930 struct bfa_fcxp_s *fcxp = NULL;
931
Jing Huangd4b671c2010-12-26 21:46:35 -0800932 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700933
934 fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa));
935 if (fcxp == NULL)
936 return NULL;
937
938 bfa_trc(bfa, fcxp->fcxp_tag);
939
940 bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn,
941 req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn);
942
943 return fcxp;
944}
945
Jing Huang5fbe25c2010-10-18 17:17:23 -0700946/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700947 * Get the internal request buffer pointer
948 *
949 * @param[in] fcxp BFA fcxp pointer
950 *
951 * @return pointer to the internal request buffer
952 */
953void *
954bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp)
955{
956 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
957 void *reqbuf;
958
Jing Huangd4b671c2010-12-26 21:46:35 -0800959 WARN_ON(fcxp->use_ireqbuf != 1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700960 reqbuf = ((u8 *)mod->req_pld_list_kva) +
961 fcxp->fcxp_tag * mod->req_pld_sz;
962 return reqbuf;
963}
964
965u32
966bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
967{
968 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
969
970 return mod->req_pld_sz;
971}
972
Jing Huang5fbe25c2010-10-18 17:17:23 -0700973/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700974 * Get the internal response buffer pointer
975 *
976 * @param[in] fcxp BFA fcxp pointer
977 *
978 * @return pointer to the internal request buffer
979 */
980void *
981bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
982{
983 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
984 void *rspbuf;
985
Jing Huangd4b671c2010-12-26 21:46:35 -0800986 WARN_ON(fcxp->use_irspbuf != 1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700987
988 rspbuf = ((u8 *)mod->rsp_pld_list_kva) +
989 fcxp->fcxp_tag * mod->rsp_pld_sz;
990 return rspbuf;
991}
992
Jing Huang5fbe25c2010-10-18 17:17:23 -0700993/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800994 * Free the BFA FCXP
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700995 *
996 * @param[in] fcxp BFA fcxp pointer
997 *
998 * @return void
999 */
1000void
1001bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
1002{
1003 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
1004
Jing Huangd4b671c2010-12-26 21:46:35 -08001005 WARN_ON(fcxp == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001006 bfa_trc(mod->bfa, fcxp->fcxp_tag);
1007 bfa_fcxp_put(fcxp);
1008}
1009
Jing Huang5fbe25c2010-10-18 17:17:23 -07001010/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001011 * Send a FCXP request
1012 *
1013 * @param[in] fcxp BFA fcxp pointer
1014 * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
1015 * @param[in] vf_id virtual Fabric ID
1016 * @param[in] lp_tag lport tag
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001017 * @param[in] cts use Continuous sequence
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001018 * @param[in] cos fc Class of Service
1019 * @param[in] reqlen request length, does not include FCHS length
1020 * @param[in] fchs fc Header Pointer. The header content will be copied
1021 * in by BFA.
1022 *
1023 * @param[in] cbfn call back function to be called on receiving
1024 * the response
1025 * @param[in] cbarg arg for cbfn
1026 * @param[in] rsp_timeout
1027 * response timeout
1028 *
1029 * @return bfa_status_t
1030 */
1031void
1032bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
1033 u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos,
1034 u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn,
1035 void *cbarg, u32 rsp_maxlen, u8 rsp_timeout)
1036{
1037 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
1038 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
1039 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
1040 struct bfi_fcxp_send_req_s *send_req;
1041
1042 bfa_trc(bfa, fcxp->fcxp_tag);
1043
Jing Huang5fbe25c2010-10-18 17:17:23 -07001044 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001045 * setup request/response info
1046 */
1047 reqi->bfa_rport = rport;
1048 reqi->vf_id = vf_id;
1049 reqi->lp_tag = lp_tag;
1050 reqi->class = cos;
1051 rspi->rsp_timeout = rsp_timeout;
1052 reqi->cts = cts;
1053 reqi->fchs = *fchs;
1054 reqi->req_tot_len = reqlen;
1055 rspi->rsp_maxlen = rsp_maxlen;
1056 fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
1057 fcxp->send_cbarg = cbarg;
1058
Jing Huang5fbe25c2010-10-18 17:17:23 -07001059 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001060 * If no room in CPE queue, wait for space in request queue
1061 */
1062 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
1063 if (!send_req) {
1064 bfa_trc(bfa, fcxp->fcxp_tag);
1065 fcxp->reqq_waiting = BFA_TRUE;
1066 bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe);
1067 return;
1068 }
1069
1070 bfa_fcxp_queue(fcxp, send_req);
1071}
1072
Jing Huang5fbe25c2010-10-18 17:17:23 -07001073/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001074 * Abort a BFA FCXP
1075 *
1076 * @param[in] fcxp BFA fcxp pointer
1077 *
1078 * @return void
1079 */
1080bfa_status_t
1081bfa_fcxp_abort(struct bfa_fcxp_s *fcxp)
1082{
1083 bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag);
Jing Huangd4b671c2010-12-26 21:46:35 -08001084 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001085 return BFA_STATUS_OK;
1086}
1087
1088void
1089bfa_fcxp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
1090 bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg,
1091 void *caller, int nreq_sgles,
1092 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
1093 bfa_fcxp_get_sglen_t req_sglen_cbfn,
1094 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
1095 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
1096{
1097 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1098
Jing Huangd4b671c2010-12-26 21:46:35 -08001099 WARN_ON(!list_empty(&mod->fcxp_free_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001100
1101 wqe->alloc_cbfn = alloc_cbfn;
1102 wqe->alloc_cbarg = alloc_cbarg;
1103 wqe->caller = caller;
1104 wqe->bfa = bfa;
1105 wqe->nreq_sgles = nreq_sgles;
1106 wqe->nrsp_sgles = nrsp_sgles;
1107 wqe->req_sga_cbfn = req_sga_cbfn;
1108 wqe->req_sglen_cbfn = req_sglen_cbfn;
1109 wqe->rsp_sga_cbfn = rsp_sga_cbfn;
1110 wqe->rsp_sglen_cbfn = rsp_sglen_cbfn;
1111
1112 list_add_tail(&wqe->qe, &mod->wait_q);
1113}
1114
1115void
1116bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
1117{
1118 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1119
Jing Huangd4b671c2010-12-26 21:46:35 -08001120 WARN_ON(!bfa_q_is_on_q(&mod->wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001121 list_del(&wqe->qe);
1122}
1123
1124void
1125bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
1126{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001127 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001128 * If waiting for room in request queue, cancel reqq wait
1129 * and free fcxp.
1130 */
1131 if (fcxp->reqq_waiting) {
1132 fcxp->reqq_waiting = BFA_FALSE;
1133 bfa_reqq_wcancel(&fcxp->reqq_wqe);
1134 bfa_fcxp_free(fcxp);
1135 return;
1136 }
1137
1138 fcxp->send_cbfn = bfa_fcxp_null_comp;
1139}
1140
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001141void
1142bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
1143{
1144 switch (msg->mhdr.msg_id) {
1145 case BFI_FCXP_I2H_SEND_RSP:
1146 hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg);
1147 break;
1148
1149 default:
1150 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001151 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001152 }
1153}
1154
1155u32
1156bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
1157{
1158 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1159
1160 return mod->rsp_pld_sz;
1161}
1162
1163
Jing Huang5fbe25c2010-10-18 17:17:23 -07001164/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001165 * BFA LPS state machine functions
1166 */
1167
Jing Huang5fbe25c2010-10-18 17:17:23 -07001168/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001169 * Init state -- no login
1170 */
1171static void
1172bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
1173{
1174 bfa_trc(lps->bfa, lps->lp_tag);
1175 bfa_trc(lps->bfa, event);
1176
1177 switch (event) {
1178 case BFA_LPS_SM_LOGIN:
1179 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1180 bfa_sm_set_state(lps, bfa_lps_sm_loginwait);
1181 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1182 } else {
1183 bfa_sm_set_state(lps, bfa_lps_sm_login);
1184 bfa_lps_send_login(lps);
1185 }
1186
1187 if (lps->fdisc)
1188 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1189 BFA_PL_EID_LOGIN, 0, "FDISC Request");
1190 else
1191 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1192 BFA_PL_EID_LOGIN, 0, "FLOGI Request");
1193 break;
1194
1195 case BFA_LPS_SM_LOGOUT:
1196 bfa_lps_logout_comp(lps);
1197 break;
1198
1199 case BFA_LPS_SM_DELETE:
1200 bfa_lps_free(lps);
1201 break;
1202
1203 case BFA_LPS_SM_RX_CVL:
1204 case BFA_LPS_SM_OFFLINE:
1205 break;
1206
1207 case BFA_LPS_SM_FWRSP:
1208 /*
1209 * Could happen when fabric detects loopback and discards
1210 * the lps request. Fw will eventually sent out the timeout
1211 * Just ignore
1212 */
1213 break;
1214
1215 default:
1216 bfa_sm_fault(lps->bfa, event);
1217 }
1218}
1219
Jing Huang5fbe25c2010-10-18 17:17:23 -07001220/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001221 * login is in progress -- awaiting response from firmware
1222 */
1223static void
1224bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
1225{
1226 bfa_trc(lps->bfa, lps->lp_tag);
1227 bfa_trc(lps->bfa, event);
1228
1229 switch (event) {
1230 case BFA_LPS_SM_FWRSP:
1231 if (lps->status == BFA_STATUS_OK) {
1232 bfa_sm_set_state(lps, bfa_lps_sm_online);
1233 if (lps->fdisc)
1234 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1235 BFA_PL_EID_LOGIN, 0, "FDISC Accept");
1236 else
1237 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1238 BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
Krishna Gudipatib7044952010-12-13 16:17:42 -08001239 /* If N2N, send the assigned PID to FW */
1240 bfa_trc(lps->bfa, lps->fport);
1241 bfa_trc(lps->bfa, lps->lp_pid);
1242
1243 if (!lps->fport && lps->lp_pid)
1244 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001245 } else {
1246 bfa_sm_set_state(lps, bfa_lps_sm_init);
1247 if (lps->fdisc)
1248 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1249 BFA_PL_EID_LOGIN, 0,
1250 "FDISC Fail (RJT or timeout)");
1251 else
1252 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1253 BFA_PL_EID_LOGIN, 0,
1254 "FLOGI Fail (RJT or timeout)");
1255 }
1256 bfa_lps_login_comp(lps);
1257 break;
1258
1259 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001260 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001261 bfa_sm_set_state(lps, bfa_lps_sm_init);
1262 break;
1263
Krishna Gudipatib7044952010-12-13 16:17:42 -08001264 case BFA_LPS_SM_SET_N2N_PID:
1265 bfa_trc(lps->bfa, lps->fport);
1266 bfa_trc(lps->bfa, lps->lp_pid);
1267 break;
1268
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001269 default:
1270 bfa_sm_fault(lps->bfa, event);
1271 }
1272}
1273
Jing Huang5fbe25c2010-10-18 17:17:23 -07001274/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001275 * login pending - awaiting space in request queue
1276 */
1277static void
1278bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1279{
1280 bfa_trc(lps->bfa, lps->lp_tag);
1281 bfa_trc(lps->bfa, event);
1282
1283 switch (event) {
1284 case BFA_LPS_SM_RESUME:
1285 bfa_sm_set_state(lps, bfa_lps_sm_login);
1286 break;
1287
1288 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001289 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001290 bfa_sm_set_state(lps, bfa_lps_sm_init);
1291 bfa_reqq_wcancel(&lps->wqe);
1292 break;
1293
1294 case BFA_LPS_SM_RX_CVL:
1295 /*
1296 * Login was not even sent out; so when getting out
1297 * of this state, it will appear like a login retry
1298 * after Clear virtual link
1299 */
1300 break;
1301
1302 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 complete
1309 */
1310static void
1311bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
1312{
1313 bfa_trc(lps->bfa, lps->lp_tag);
1314 bfa_trc(lps->bfa, event);
1315
1316 switch (event) {
1317 case BFA_LPS_SM_LOGOUT:
1318 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1319 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1320 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1321 } else {
1322 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1323 bfa_lps_send_logout(lps);
1324 }
1325 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1326 BFA_PL_EID_LOGO, 0, "Logout");
1327 break;
1328
1329 case BFA_LPS_SM_RX_CVL:
1330 bfa_sm_set_state(lps, bfa_lps_sm_init);
1331
1332 /* Let the vport module know about this event */
1333 bfa_lps_cvl_event(lps);
1334 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1335 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1336 break;
1337
Krishna Gudipatib7044952010-12-13 16:17:42 -08001338 case BFA_LPS_SM_SET_N2N_PID:
1339 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1340 bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
1341 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1342 } else
1343 bfa_lps_send_set_n2n_pid(lps);
1344 break;
1345
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001346 case BFA_LPS_SM_OFFLINE:
1347 case BFA_LPS_SM_DELETE:
1348 bfa_sm_set_state(lps, bfa_lps_sm_init);
1349 break;
1350
1351 default:
1352 bfa_sm_fault(lps->bfa, event);
1353 }
1354}
1355
Jing Huang8f4bfad2010-12-26 21:50:10 -08001356/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001357 * login complete
1358 */
1359static void
1360bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1361{
1362 bfa_trc(lps->bfa, lps->lp_tag);
1363 bfa_trc(lps->bfa, event);
1364
1365 switch (event) {
1366 case BFA_LPS_SM_RESUME:
1367 bfa_sm_set_state(lps, bfa_lps_sm_online);
1368 bfa_lps_send_set_n2n_pid(lps);
1369 break;
1370
1371 case BFA_LPS_SM_LOGOUT:
1372 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1373 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1374 BFA_PL_EID_LOGO, 0, "Logout");
1375 break;
1376
1377 case BFA_LPS_SM_RX_CVL:
1378 bfa_sm_set_state(lps, bfa_lps_sm_init);
1379 bfa_reqq_wcancel(&lps->wqe);
1380
1381 /* Let the vport module know about this event */
1382 bfa_lps_cvl_event(lps);
1383 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1384 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1385 break;
1386
1387 case BFA_LPS_SM_OFFLINE:
1388 case BFA_LPS_SM_DELETE:
1389 bfa_sm_set_state(lps, bfa_lps_sm_init);
1390 bfa_reqq_wcancel(&lps->wqe);
1391 break;
1392
1393 default:
1394 bfa_sm_fault(lps->bfa, event);
1395 }
1396}
1397
Jing Huang5fbe25c2010-10-18 17:17:23 -07001398/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001399 * logout in progress - awaiting firmware response
1400 */
1401static void
1402bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
1403{
1404 bfa_trc(lps->bfa, lps->lp_tag);
1405 bfa_trc(lps->bfa, event);
1406
1407 switch (event) {
1408 case BFA_LPS_SM_FWRSP:
1409 bfa_sm_set_state(lps, bfa_lps_sm_init);
1410 bfa_lps_logout_comp(lps);
1411 break;
1412
1413 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001414 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001415 bfa_sm_set_state(lps, bfa_lps_sm_init);
1416 break;
1417
1418 default:
1419 bfa_sm_fault(lps->bfa, event);
1420 }
1421}
1422
Jing Huang5fbe25c2010-10-18 17:17:23 -07001423/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001424 * logout pending -- awaiting space in request queue
1425 */
1426static void
1427bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1428{
1429 bfa_trc(lps->bfa, lps->lp_tag);
1430 bfa_trc(lps->bfa, event);
1431
1432 switch (event) {
1433 case BFA_LPS_SM_RESUME:
1434 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1435 bfa_lps_send_logout(lps);
1436 break;
1437
1438 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001439 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001440 bfa_sm_set_state(lps, bfa_lps_sm_init);
1441 bfa_reqq_wcancel(&lps->wqe);
1442 break;
1443
1444 default:
1445 bfa_sm_fault(lps->bfa, event);
1446 }
1447}
1448
1449
1450
Jing Huang5fbe25c2010-10-18 17:17:23 -07001451/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001452 * lps_pvt BFA LPS private functions
1453 */
1454
Jing Huang5fbe25c2010-10-18 17:17:23 -07001455/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001456 * return memory requirement
1457 */
1458static void
1459bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
1460 u32 *dm_len)
1461{
1462 if (cfg->drvcfg.min_cfg)
1463 *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS;
1464 else
1465 *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS;
1466}
1467
Jing Huang5fbe25c2010-10-18 17:17:23 -07001468/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001469 * bfa module attach at initialization time
1470 */
1471static void
1472bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1473 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
1474{
1475 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1476 struct bfa_lps_s *lps;
1477 int i;
1478
Jing Huang6a18b162010-10-18 17:08:54 -07001479 memset(mod, 0, sizeof(struct bfa_lps_mod_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001480 mod->num_lps = BFA_LPS_MAX_LPORTS;
1481 if (cfg->drvcfg.min_cfg)
1482 mod->num_lps = BFA_LPS_MIN_LPORTS;
1483 else
1484 mod->num_lps = BFA_LPS_MAX_LPORTS;
1485 mod->lps_arr = lps = (struct bfa_lps_s *) bfa_meminfo_kva(meminfo);
1486
1487 bfa_meminfo_kva(meminfo) += mod->num_lps * sizeof(struct bfa_lps_s);
1488
1489 INIT_LIST_HEAD(&mod->lps_free_q);
1490 INIT_LIST_HEAD(&mod->lps_active_q);
1491
1492 for (i = 0; i < mod->num_lps; i++, lps++) {
1493 lps->bfa = bfa;
1494 lps->lp_tag = (u8) i;
1495 lps->reqq = BFA_REQQ_LPS;
1496 bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
1497 list_add_tail(&lps->qe, &mod->lps_free_q);
1498 }
1499}
1500
1501static void
1502bfa_lps_detach(struct bfa_s *bfa)
1503{
1504}
1505
1506static void
1507bfa_lps_start(struct bfa_s *bfa)
1508{
1509}
1510
1511static void
1512bfa_lps_stop(struct bfa_s *bfa)
1513{
1514}
1515
Jing Huang5fbe25c2010-10-18 17:17:23 -07001516/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001517 * IOC in disabled state -- consider all lps offline
1518 */
1519static void
1520bfa_lps_iocdisable(struct bfa_s *bfa)
1521{
1522 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1523 struct bfa_lps_s *lps;
1524 struct list_head *qe, *qen;
1525
1526 list_for_each_safe(qe, qen, &mod->lps_active_q) {
1527 lps = (struct bfa_lps_s *) qe;
1528 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1529 }
1530}
1531
Jing Huang5fbe25c2010-10-18 17:17:23 -07001532/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001533 * Firmware login response
1534 */
1535static void
1536bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
1537{
1538 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1539 struct bfa_lps_s *lps;
1540
Jing Huangd4b671c2010-12-26 21:46:35 -08001541 WARN_ON(rsp->lp_tag >= mod->num_lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001542 lps = BFA_LPS_FROM_TAG(mod, rsp->lp_tag);
1543
1544 lps->status = rsp->status;
1545 switch (rsp->status) {
1546 case BFA_STATUS_OK:
1547 lps->fport = rsp->f_port;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001548 if (lps->fport)
1549 lps->lp_pid = rsp->lp_pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001550 lps->npiv_en = rsp->npiv_en;
Jing Huangba816ea2010-10-18 17:10:50 -07001551 lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001552 lps->pr_pwwn = rsp->port_name;
1553 lps->pr_nwwn = rsp->node_name;
1554 lps->auth_req = rsp->auth_req;
1555 lps->lp_mac = rsp->lp_mac;
1556 lps->brcd_switch = rsp->brcd_switch;
1557 lps->fcf_mac = rsp->fcf_mac;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001558 lps->pr_bbscn = rsp->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001559
1560 break;
1561
1562 case BFA_STATUS_FABRIC_RJT:
1563 lps->lsrjt_rsn = rsp->lsrjt_rsn;
1564 lps->lsrjt_expl = rsp->lsrjt_expl;
1565
1566 break;
1567
1568 case BFA_STATUS_EPROTOCOL:
1569 lps->ext_status = rsp->ext_status;
1570
1571 break;
1572
1573 default:
1574 /* Nothing to do with other status */
1575 break;
1576 }
1577
1578 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1579}
1580
Jing Huang5fbe25c2010-10-18 17:17:23 -07001581/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001582 * Firmware logout response
1583 */
1584static void
1585bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
1586{
1587 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1588 struct bfa_lps_s *lps;
1589
Jing Huangd4b671c2010-12-26 21:46:35 -08001590 WARN_ON(rsp->lp_tag >= mod->num_lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001591 lps = BFA_LPS_FROM_TAG(mod, rsp->lp_tag);
1592
1593 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1594}
1595
Jing Huang5fbe25c2010-10-18 17:17:23 -07001596/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001597 * Firmware received a Clear virtual link request (for FCoE)
1598 */
1599static void
1600bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
1601{
1602 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1603 struct bfa_lps_s *lps;
1604
1605 lps = BFA_LPS_FROM_TAG(mod, cvl->lp_tag);
1606
1607 bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
1608}
1609
Jing Huang5fbe25c2010-10-18 17:17:23 -07001610/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001611 * Space is available in request queue, resume queueing request to firmware.
1612 */
1613static void
1614bfa_lps_reqq_resume(void *lps_arg)
1615{
1616 struct bfa_lps_s *lps = lps_arg;
1617
1618 bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
1619}
1620
Jing Huang5fbe25c2010-10-18 17:17:23 -07001621/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001622 * lps is freed -- triggered by vport delete
1623 */
1624static void
1625bfa_lps_free(struct bfa_lps_s *lps)
1626{
1627 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
1628
1629 lps->lp_pid = 0;
1630 list_del(&lps->qe);
1631 list_add_tail(&lps->qe, &mod->lps_free_q);
1632}
1633
Jing Huang5fbe25c2010-10-18 17:17:23 -07001634/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001635 * send login request to firmware
1636 */
1637static void
1638bfa_lps_send_login(struct bfa_lps_s *lps)
1639{
1640 struct bfi_lps_login_req_s *m;
1641
1642 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001643 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001644
1645 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
1646 bfa_lpuid(lps->bfa));
1647
1648 m->lp_tag = lps->lp_tag;
1649 m->alpa = lps->alpa;
Jing Huangba816ea2010-10-18 17:10:50 -07001650 m->pdu_size = cpu_to_be16(lps->pdusz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001651 m->pwwn = lps->pwwn;
1652 m->nwwn = lps->nwwn;
1653 m->fdisc = lps->fdisc;
1654 m->auth_en = lps->auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001655 m->bb_scn = lps->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001656
1657 bfa_reqq_produce(lps->bfa, lps->reqq);
1658}
1659
Jing Huang5fbe25c2010-10-18 17:17:23 -07001660/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001661 * send logout request to firmware
1662 */
1663static void
1664bfa_lps_send_logout(struct bfa_lps_s *lps)
1665{
1666 struct bfi_lps_logout_req_s *m;
1667
1668 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001669 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001670
1671 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
1672 bfa_lpuid(lps->bfa));
1673
1674 m->lp_tag = lps->lp_tag;
1675 m->port_name = lps->pwwn;
1676 bfa_reqq_produce(lps->bfa, lps->reqq);
1677}
1678
Jing Huang8f4bfad2010-12-26 21:50:10 -08001679/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001680 * send n2n pid set request to firmware
1681 */
1682static void
1683bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
1684{
1685 struct bfi_lps_n2n_pid_req_s *m;
1686
1687 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001688 WARN_ON(!m);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001689
1690 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
1691 bfa_lpuid(lps->bfa));
1692
1693 m->lp_tag = lps->lp_tag;
1694 m->lp_pid = lps->lp_pid;
1695 bfa_reqq_produce(lps->bfa, lps->reqq);
1696}
1697
Jing Huang5fbe25c2010-10-18 17:17:23 -07001698/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001699 * Indirect login completion handler for non-fcs
1700 */
1701static void
1702bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
1703{
1704 struct bfa_lps_s *lps = arg;
1705
1706 if (!complete)
1707 return;
1708
1709 if (lps->fdisc)
1710 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1711 else
1712 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1713}
1714
Jing Huang5fbe25c2010-10-18 17:17:23 -07001715/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001716 * Login completion handler -- direct call for fcs, queue for others
1717 */
1718static void
1719bfa_lps_login_comp(struct bfa_lps_s *lps)
1720{
1721 if (!lps->bfa->fcs) {
1722 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
1723 lps);
1724 return;
1725 }
1726
1727 if (lps->fdisc)
1728 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1729 else
1730 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1731}
1732
Jing Huang5fbe25c2010-10-18 17:17:23 -07001733/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001734 * Indirect logout completion handler for non-fcs
1735 */
1736static void
1737bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
1738{
1739 struct bfa_lps_s *lps = arg;
1740
1741 if (!complete)
1742 return;
1743
1744 if (lps->fdisc)
1745 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1746}
1747
Jing Huang5fbe25c2010-10-18 17:17:23 -07001748/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001749 * Logout completion handler -- direct call for fcs, queue for others
1750 */
1751static void
1752bfa_lps_logout_comp(struct bfa_lps_s *lps)
1753{
1754 if (!lps->bfa->fcs) {
1755 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
1756 lps);
1757 return;
1758 }
1759 if (lps->fdisc)
1760 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1761}
1762
Jing Huang5fbe25c2010-10-18 17:17:23 -07001763/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001764 * Clear virtual link completion handler for non-fcs
1765 */
1766static void
1767bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
1768{
1769 struct bfa_lps_s *lps = arg;
1770
1771 if (!complete)
1772 return;
1773
1774 /* Clear virtual link to base port will result in link down */
1775 if (lps->fdisc)
1776 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1777}
1778
Jing Huang5fbe25c2010-10-18 17:17:23 -07001779/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001780 * Received Clear virtual link event --direct call for fcs,
1781 * queue for others
1782 */
1783static void
1784bfa_lps_cvl_event(struct bfa_lps_s *lps)
1785{
1786 if (!lps->bfa->fcs) {
1787 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
1788 lps);
1789 return;
1790 }
1791
1792 /* Clear virtual link to base port will result in link down */
1793 if (lps->fdisc)
1794 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1795}
1796
1797
1798
Jing Huang5fbe25c2010-10-18 17:17:23 -07001799/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001800 * lps_public BFA LPS public functions
1801 */
1802
1803u32
1804bfa_lps_get_max_vport(struct bfa_s *bfa)
1805{
1806 if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
1807 return BFA_LPS_MAX_VPORTS_SUPP_CT;
1808 else
1809 return BFA_LPS_MAX_VPORTS_SUPP_CB;
1810}
1811
Jing Huang5fbe25c2010-10-18 17:17:23 -07001812/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001813 * Allocate a lport srvice tag.
1814 */
1815struct bfa_lps_s *
1816bfa_lps_alloc(struct bfa_s *bfa)
1817{
1818 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1819 struct bfa_lps_s *lps = NULL;
1820
1821 bfa_q_deq(&mod->lps_free_q, &lps);
1822
1823 if (lps == NULL)
1824 return NULL;
1825
1826 list_add_tail(&lps->qe, &mod->lps_active_q);
1827
1828 bfa_sm_set_state(lps, bfa_lps_sm_init);
1829 return lps;
1830}
1831
Jing Huang5fbe25c2010-10-18 17:17:23 -07001832/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001833 * Free lport service tag. This can be called anytime after an alloc.
1834 * No need to wait for any pending login/logout completions.
1835 */
1836void
1837bfa_lps_delete(struct bfa_lps_s *lps)
1838{
1839 bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
1840}
1841
Jing Huang5fbe25c2010-10-18 17:17:23 -07001842/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001843 * Initiate a lport login.
1844 */
1845void
1846bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001847 wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en, uint8_t bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001848{
1849 lps->uarg = uarg;
1850 lps->alpa = alpa;
1851 lps->pdusz = pdusz;
1852 lps->pwwn = pwwn;
1853 lps->nwwn = nwwn;
1854 lps->fdisc = BFA_FALSE;
1855 lps->auth_en = auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001856 lps->bb_scn = bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001857 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1858}
1859
Jing Huang5fbe25c2010-10-18 17:17:23 -07001860/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001861 * Initiate a lport fdisc login.
1862 */
1863void
1864bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
1865 wwn_t nwwn)
1866{
1867 lps->uarg = uarg;
1868 lps->alpa = 0;
1869 lps->pdusz = pdusz;
1870 lps->pwwn = pwwn;
1871 lps->nwwn = nwwn;
1872 lps->fdisc = BFA_TRUE;
1873 lps->auth_en = BFA_FALSE;
1874 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1875}
1876
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001877
Jing Huang5fbe25c2010-10-18 17:17:23 -07001878/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001879 * Initiate a lport FDSIC logout.
1880 */
1881void
1882bfa_lps_fdisclogo(struct bfa_lps_s *lps)
1883{
1884 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
1885}
1886
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001887
Jing Huang5fbe25c2010-10-18 17:17:23 -07001888/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001889 * Return lport services tag given the pid
1890 */
1891u8
1892bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
1893{
1894 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1895 struct bfa_lps_s *lps;
1896 int i;
1897
1898 for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
1899 if (lps->lp_pid == pid)
1900 return lps->lp_tag;
1901 }
1902
1903 /* Return base port tag anyway */
1904 return 0;
1905}
1906
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001907
Jing Huang5fbe25c2010-10-18 17:17:23 -07001908/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001909 * return port id assigned to the base lport
1910 */
1911u32
1912bfa_lps_get_base_pid(struct bfa_s *bfa)
1913{
1914 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1915
1916 return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
1917}
1918
Jing Huang8f4bfad2010-12-26 21:50:10 -08001919/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001920 * Set PID in case of n2n (which is assigned during PLOGI)
1921 */
1922void
1923bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
1924{
1925 bfa_trc(lps->bfa, lps->lp_tag);
1926 bfa_trc(lps->bfa, n2n_pid);
1927
1928 lps->lp_pid = n2n_pid;
1929 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
1930}
1931
Jing Huang5fbe25c2010-10-18 17:17:23 -07001932/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001933 * LPS firmware message class handler.
1934 */
1935void
1936bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
1937{
1938 union bfi_lps_i2h_msg_u msg;
1939
1940 bfa_trc(bfa, m->mhdr.msg_id);
1941 msg.msg = m;
1942
1943 switch (m->mhdr.msg_id) {
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07001944 case BFI_LPS_I2H_LOGIN_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001945 bfa_lps_login_rsp(bfa, msg.login_rsp);
1946 break;
1947
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07001948 case BFI_LPS_I2H_LOGOUT_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001949 bfa_lps_logout_rsp(bfa, msg.logout_rsp);
1950 break;
1951
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07001952 case BFI_LPS_I2H_CVL_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001953 bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
1954 break;
1955
1956 default:
1957 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001958 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001959 }
1960}
1961
Jing Huang5fbe25c2010-10-18 17:17:23 -07001962/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001963 * FC PORT state machine functions
1964 */
1965static void
1966bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
1967 enum bfa_fcport_sm_event event)
1968{
1969 bfa_trc(fcport->bfa, event);
1970
1971 switch (event) {
1972 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001973 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001974 * Start event after IOC is configured and BFA is started.
1975 */
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08001976 fcport->use_flash_cfg = BFA_TRUE;
1977
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001978 if (bfa_fcport_send_enable(fcport)) {
1979 bfa_trc(fcport->bfa, BFA_TRUE);
1980 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
1981 } else {
1982 bfa_trc(fcport->bfa, BFA_FALSE);
1983 bfa_sm_set_state(fcport,
1984 bfa_fcport_sm_enabling_qwait);
1985 }
1986 break;
1987
1988 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001989 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001990 * Port is persistently configured to be in enabled state. Do
1991 * not change state. Port enabling is done when START event is
1992 * received.
1993 */
1994 break;
1995
1996 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001997 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001998 * If a port is persistently configured to be disabled, the
1999 * first event will a port disable request.
2000 */
2001 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2002 break;
2003
2004 case BFA_FCPORT_SM_HWFAIL:
2005 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2006 break;
2007
2008 default:
2009 bfa_sm_fault(fcport->bfa, event);
2010 }
2011}
2012
2013static void
2014bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
2015 enum bfa_fcport_sm_event event)
2016{
2017 char pwwn_buf[BFA_STRING_32];
2018 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2019 bfa_trc(fcport->bfa, event);
2020
2021 switch (event) {
2022 case BFA_FCPORT_SM_QRESUME:
2023 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2024 bfa_fcport_send_enable(fcport);
2025 break;
2026
2027 case BFA_FCPORT_SM_STOP:
2028 bfa_reqq_wcancel(&fcport->reqq_wait);
2029 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2030 break;
2031
2032 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002033 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002034 * Already enable is in progress.
2035 */
2036 break;
2037
2038 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002039 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002040 * Just send disable request to firmware when room becomes
2041 * available in request queue.
2042 */
2043 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2044 bfa_reqq_wcancel(&fcport->reqq_wait);
2045 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2046 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2047 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002048 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002049 "Base port disabled: WWN = %s\n", pwwn_buf);
2050 break;
2051
2052 case BFA_FCPORT_SM_LINKUP:
2053 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002054 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002055 * Possible to get link events when doing back-to-back
2056 * enable/disables.
2057 */
2058 break;
2059
2060 case BFA_FCPORT_SM_HWFAIL:
2061 bfa_reqq_wcancel(&fcport->reqq_wait);
2062 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2063 break;
2064
2065 default:
2066 bfa_sm_fault(fcport->bfa, event);
2067 }
2068}
2069
2070static void
2071bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
2072 enum bfa_fcport_sm_event event)
2073{
2074 char pwwn_buf[BFA_STRING_32];
2075 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2076 bfa_trc(fcport->bfa, event);
2077
2078 switch (event) {
2079 case BFA_FCPORT_SM_FWRSP:
2080 case BFA_FCPORT_SM_LINKDOWN:
2081 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2082 break;
2083
2084 case BFA_FCPORT_SM_LINKUP:
2085 bfa_fcport_update_linkinfo(fcport);
2086 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
2087
Jing Huangd4b671c2010-12-26 21:46:35 -08002088 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002089 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
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 * Already being enabled.
2095 */
2096 break;
2097
2098 case BFA_FCPORT_SM_DISABLE:
2099 if (bfa_fcport_send_disable(fcport))
2100 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2101 else
2102 bfa_sm_set_state(fcport,
2103 bfa_fcport_sm_disabling_qwait);
2104
2105 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2106 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2107 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002108 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002109 "Base port disabled: WWN = %s\n", pwwn_buf);
2110 break;
2111
2112 case BFA_FCPORT_SM_STOP:
2113 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2114 break;
2115
2116 case BFA_FCPORT_SM_HWFAIL:
2117 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2118 break;
2119
2120 default:
2121 bfa_sm_fault(fcport->bfa, event);
2122 }
2123}
2124
2125static void
2126bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
2127 enum bfa_fcport_sm_event event)
2128{
2129 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2130 char pwwn_buf[BFA_STRING_32];
2131 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2132
2133 bfa_trc(fcport->bfa, event);
2134
2135 switch (event) {
2136 case BFA_FCPORT_SM_LINKUP:
2137 bfa_fcport_update_linkinfo(fcport);
2138 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
Jing Huangd4b671c2010-12-26 21:46:35 -08002139 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002140 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2141 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
2142 if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
2143
2144 bfa_trc(fcport->bfa,
2145 pevent->link_state.vc_fcf.fcf.fipenabled);
2146 bfa_trc(fcport->bfa,
2147 pevent->link_state.vc_fcf.fcf.fipfailed);
2148
2149 if (pevent->link_state.vc_fcf.fcf.fipfailed)
2150 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2151 BFA_PL_EID_FIP_FCF_DISC, 0,
2152 "FIP FCF Discovery Failed");
2153 else
2154 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2155 BFA_PL_EID_FIP_FCF_DISC, 0,
2156 "FIP FCF Discovered");
2157 }
2158
2159 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2160 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002161 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002162 "Base port online: WWN = %s\n", pwwn_buf);
2163 break;
2164
2165 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002166 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002167 * Possible to get link down event.
2168 */
2169 break;
2170
2171 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002172 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002173 * Already enabled.
2174 */
2175 break;
2176
2177 case BFA_FCPORT_SM_DISABLE:
2178 if (bfa_fcport_send_disable(fcport))
2179 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2180 else
2181 bfa_sm_set_state(fcport,
2182 bfa_fcport_sm_disabling_qwait);
2183
2184 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2185 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2186 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002187 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002188 "Base port disabled: WWN = %s\n", pwwn_buf);
2189 break;
2190
2191 case BFA_FCPORT_SM_STOP:
2192 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2193 break;
2194
2195 case BFA_FCPORT_SM_HWFAIL:
2196 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2197 break;
2198
2199 default:
2200 bfa_sm_fault(fcport->bfa, event);
2201 }
2202}
2203
2204static void
2205bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
2206 enum bfa_fcport_sm_event event)
2207{
2208 char pwwn_buf[BFA_STRING_32];
2209 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2210
2211 bfa_trc(fcport->bfa, event);
2212
2213 switch (event) {
2214 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002215 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002216 * Already enabled.
2217 */
2218 break;
2219
2220 case BFA_FCPORT_SM_DISABLE:
2221 if (bfa_fcport_send_disable(fcport))
2222 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2223 else
2224 bfa_sm_set_state(fcport,
2225 bfa_fcport_sm_disabling_qwait);
2226
2227 bfa_fcport_reset_linkinfo(fcport);
2228 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2229 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2230 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2231 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002232 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002233 "Base port offline: WWN = %s\n", pwwn_buf);
Jing Huang88166242010-12-09 17:11:53 -08002234 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002235 "Base port disabled: WWN = %s\n", pwwn_buf);
2236 break;
2237
2238 case BFA_FCPORT_SM_LINKDOWN:
2239 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2240 bfa_fcport_reset_linkinfo(fcport);
2241 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2242 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2243 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
2244 wwn2str(pwwn_buf, fcport->pwwn);
2245 if (BFA_PORT_IS_DISABLED(fcport->bfa))
Jing Huang88166242010-12-09 17:11:53 -08002246 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002247 "Base port offline: WWN = %s\n", pwwn_buf);
2248 else
Jing Huang88166242010-12-09 17:11:53 -08002249 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002250 "Base port (WWN = %s) "
2251 "lost fabric connectivity\n", pwwn_buf);
2252 break;
2253
2254 case BFA_FCPORT_SM_STOP:
2255 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2256 bfa_fcport_reset_linkinfo(fcport);
2257 wwn2str(pwwn_buf, fcport->pwwn);
2258 if (BFA_PORT_IS_DISABLED(fcport->bfa))
Jing Huang88166242010-12-09 17:11:53 -08002259 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002260 "Base port offline: WWN = %s\n", pwwn_buf);
2261 else
Jing Huang88166242010-12-09 17:11:53 -08002262 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002263 "Base port (WWN = %s) "
2264 "lost fabric connectivity\n", pwwn_buf);
2265 break;
2266
2267 case BFA_FCPORT_SM_HWFAIL:
2268 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2269 bfa_fcport_reset_linkinfo(fcport);
2270 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2271 wwn2str(pwwn_buf, fcport->pwwn);
2272 if (BFA_PORT_IS_DISABLED(fcport->bfa))
Jing Huang88166242010-12-09 17:11:53 -08002273 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002274 "Base port offline: WWN = %s\n", pwwn_buf);
2275 else
Jing Huang88166242010-12-09 17:11:53 -08002276 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002277 "Base port (WWN = %s) "
2278 "lost fabric connectivity\n", pwwn_buf);
2279 break;
2280
2281 default:
2282 bfa_sm_fault(fcport->bfa, event);
2283 }
2284}
2285
2286static void
2287bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
2288 enum bfa_fcport_sm_event event)
2289{
2290 bfa_trc(fcport->bfa, event);
2291
2292 switch (event) {
2293 case BFA_FCPORT_SM_QRESUME:
2294 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2295 bfa_fcport_send_disable(fcport);
2296 break;
2297
2298 case BFA_FCPORT_SM_STOP:
2299 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2300 bfa_reqq_wcancel(&fcport->reqq_wait);
2301 break;
2302
2303 case BFA_FCPORT_SM_ENABLE:
2304 bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
2305 break;
2306
2307 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002308 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002309 * Already being disabled.
2310 */
2311 break;
2312
2313 case BFA_FCPORT_SM_LINKUP:
2314 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002315 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002316 * Possible to get link events when doing back-to-back
2317 * enable/disables.
2318 */
2319 break;
2320
2321 case BFA_FCPORT_SM_HWFAIL:
2322 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2323 bfa_reqq_wcancel(&fcport->reqq_wait);
2324 break;
2325
2326 default:
2327 bfa_sm_fault(fcport->bfa, event);
2328 }
2329}
2330
2331static void
2332bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
2333 enum bfa_fcport_sm_event event)
2334{
2335 bfa_trc(fcport->bfa, event);
2336
2337 switch (event) {
2338 case BFA_FCPORT_SM_QRESUME:
2339 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2340 bfa_fcport_send_disable(fcport);
2341 if (bfa_fcport_send_enable(fcport))
2342 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2343 else
2344 bfa_sm_set_state(fcport,
2345 bfa_fcport_sm_enabling_qwait);
2346 break;
2347
2348 case BFA_FCPORT_SM_STOP:
2349 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2350 bfa_reqq_wcancel(&fcport->reqq_wait);
2351 break;
2352
2353 case BFA_FCPORT_SM_ENABLE:
2354 break;
2355
2356 case BFA_FCPORT_SM_DISABLE:
2357 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
2358 break;
2359
2360 case BFA_FCPORT_SM_LINKUP:
2361 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002362 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002363 * Possible to get link events when doing back-to-back
2364 * enable/disables.
2365 */
2366 break;
2367
2368 case BFA_FCPORT_SM_HWFAIL:
2369 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2370 bfa_reqq_wcancel(&fcport->reqq_wait);
2371 break;
2372
2373 default:
2374 bfa_sm_fault(fcport->bfa, event);
2375 }
2376}
2377
2378static void
2379bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
2380 enum bfa_fcport_sm_event event)
2381{
2382 char pwwn_buf[BFA_STRING_32];
2383 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2384 bfa_trc(fcport->bfa, event);
2385
2386 switch (event) {
2387 case BFA_FCPORT_SM_FWRSP:
2388 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2389 break;
2390
2391 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002392 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002393 * Already being disabled.
2394 */
2395 break;
2396
2397 case BFA_FCPORT_SM_ENABLE:
2398 if (bfa_fcport_send_enable(fcport))
2399 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2400 else
2401 bfa_sm_set_state(fcport,
2402 bfa_fcport_sm_enabling_qwait);
2403
2404 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2405 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2406 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002407 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002408 "Base port enabled: WWN = %s\n", pwwn_buf);
2409 break;
2410
2411 case BFA_FCPORT_SM_STOP:
2412 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2413 break;
2414
2415 case BFA_FCPORT_SM_LINKUP:
2416 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002417 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002418 * Possible to get link events when doing back-to-back
2419 * enable/disables.
2420 */
2421 break;
2422
2423 case BFA_FCPORT_SM_HWFAIL:
2424 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2425 break;
2426
2427 default:
2428 bfa_sm_fault(fcport->bfa, event);
2429 }
2430}
2431
2432static void
2433bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
2434 enum bfa_fcport_sm_event event)
2435{
2436 char pwwn_buf[BFA_STRING_32];
2437 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2438 bfa_trc(fcport->bfa, event);
2439
2440 switch (event) {
2441 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002442 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002443 * Ignore start event for a port that is disabled.
2444 */
2445 break;
2446
2447 case BFA_FCPORT_SM_STOP:
2448 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2449 break;
2450
2451 case BFA_FCPORT_SM_ENABLE:
2452 if (bfa_fcport_send_enable(fcport))
2453 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2454 else
2455 bfa_sm_set_state(fcport,
2456 bfa_fcport_sm_enabling_qwait);
2457
2458 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2459 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2460 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002461 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002462 "Base port enabled: WWN = %s\n", pwwn_buf);
2463 break;
2464
2465 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002466 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002467 * Already disabled.
2468 */
2469 break;
2470
2471 case BFA_FCPORT_SM_HWFAIL:
2472 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2473 break;
2474
2475 default:
2476 bfa_sm_fault(fcport->bfa, event);
2477 }
2478}
2479
2480static void
2481bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
2482 enum bfa_fcport_sm_event event)
2483{
2484 bfa_trc(fcport->bfa, event);
2485
2486 switch (event) {
2487 case BFA_FCPORT_SM_START:
2488 if (bfa_fcport_send_enable(fcport))
2489 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2490 else
2491 bfa_sm_set_state(fcport,
2492 bfa_fcport_sm_enabling_qwait);
2493 break;
2494
2495 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002496 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002497 * Ignore all other events.
2498 */
2499 ;
2500 }
2501}
2502
Jing Huang5fbe25c2010-10-18 17:17:23 -07002503/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002504 * Port is enabled. IOC is down/failed.
2505 */
2506static void
2507bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
2508 enum bfa_fcport_sm_event event)
2509{
2510 bfa_trc(fcport->bfa, event);
2511
2512 switch (event) {
2513 case BFA_FCPORT_SM_START:
2514 if (bfa_fcport_send_enable(fcport))
2515 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2516 else
2517 bfa_sm_set_state(fcport,
2518 bfa_fcport_sm_enabling_qwait);
2519 break;
2520
2521 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002522 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002523 * Ignore all events.
2524 */
2525 ;
2526 }
2527}
2528
Jing Huang5fbe25c2010-10-18 17:17:23 -07002529/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002530 * Port is disabled. IOC is down/failed.
2531 */
2532static void
2533bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
2534 enum bfa_fcport_sm_event event)
2535{
2536 bfa_trc(fcport->bfa, event);
2537
2538 switch (event) {
2539 case BFA_FCPORT_SM_START:
2540 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2541 break;
2542
2543 case BFA_FCPORT_SM_ENABLE:
2544 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2545 break;
2546
2547 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002548 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002549 * Ignore all events.
2550 */
2551 ;
2552 }
2553}
2554
Jing Huang5fbe25c2010-10-18 17:17:23 -07002555/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002556 * Link state is down
2557 */
2558static void
2559bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
2560 enum bfa_fcport_ln_sm_event event)
2561{
2562 bfa_trc(ln->fcport->bfa, event);
2563
2564 switch (event) {
2565 case BFA_FCPORT_LN_SM_LINKUP:
2566 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2567 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2568 break;
2569
2570 default:
2571 bfa_sm_fault(ln->fcport->bfa, event);
2572 }
2573}
2574
Jing Huang5fbe25c2010-10-18 17:17:23 -07002575/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002576 * Link state is waiting for down notification
2577 */
2578static void
2579bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
2580 enum bfa_fcport_ln_sm_event event)
2581{
2582 bfa_trc(ln->fcport->bfa, event);
2583
2584 switch (event) {
2585 case BFA_FCPORT_LN_SM_LINKUP:
2586 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2587 break;
2588
2589 case BFA_FCPORT_LN_SM_NOTIFICATION:
2590 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2591 break;
2592
2593 default:
2594 bfa_sm_fault(ln->fcport->bfa, event);
2595 }
2596}
2597
Jing Huang5fbe25c2010-10-18 17:17:23 -07002598/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002599 * Link state is waiting for down notification and there is a pending up
2600 */
2601static void
2602bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
2603 enum bfa_fcport_ln_sm_event event)
2604{
2605 bfa_trc(ln->fcport->bfa, event);
2606
2607 switch (event) {
2608 case BFA_FCPORT_LN_SM_LINKDOWN:
2609 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2610 break;
2611
2612 case BFA_FCPORT_LN_SM_NOTIFICATION:
2613 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2614 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2615 break;
2616
2617 default:
2618 bfa_sm_fault(ln->fcport->bfa, event);
2619 }
2620}
2621
Jing Huang5fbe25c2010-10-18 17:17:23 -07002622/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002623 * Link state is up
2624 */
2625static void
2626bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
2627 enum bfa_fcport_ln_sm_event event)
2628{
2629 bfa_trc(ln->fcport->bfa, event);
2630
2631 switch (event) {
2632 case BFA_FCPORT_LN_SM_LINKDOWN:
2633 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2634 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2635 break;
2636
2637 default:
2638 bfa_sm_fault(ln->fcport->bfa, event);
2639 }
2640}
2641
Jing Huang5fbe25c2010-10-18 17:17:23 -07002642/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002643 * Link state is waiting for up notification
2644 */
2645static void
2646bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
2647 enum bfa_fcport_ln_sm_event event)
2648{
2649 bfa_trc(ln->fcport->bfa, event);
2650
2651 switch (event) {
2652 case BFA_FCPORT_LN_SM_LINKDOWN:
2653 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2654 break;
2655
2656 case BFA_FCPORT_LN_SM_NOTIFICATION:
2657 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
2658 break;
2659
2660 default:
2661 bfa_sm_fault(ln->fcport->bfa, event);
2662 }
2663}
2664
Jing Huang5fbe25c2010-10-18 17:17:23 -07002665/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002666 * Link state is waiting for up notification and there is a pending down
2667 */
2668static void
2669bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
2670 enum bfa_fcport_ln_sm_event event)
2671{
2672 bfa_trc(ln->fcport->bfa, event);
2673
2674 switch (event) {
2675 case BFA_FCPORT_LN_SM_LINKUP:
2676 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
2677 break;
2678
2679 case BFA_FCPORT_LN_SM_NOTIFICATION:
2680 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2681 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2682 break;
2683
2684 default:
2685 bfa_sm_fault(ln->fcport->bfa, event);
2686 }
2687}
2688
Jing Huang5fbe25c2010-10-18 17:17:23 -07002689/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002690 * Link state is waiting for up notification and there are pending down and up
2691 */
2692static void
2693bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
2694 enum bfa_fcport_ln_sm_event event)
2695{
2696 bfa_trc(ln->fcport->bfa, event);
2697
2698 switch (event) {
2699 case BFA_FCPORT_LN_SM_LINKDOWN:
2700 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2701 break;
2702
2703 case BFA_FCPORT_LN_SM_NOTIFICATION:
2704 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2705 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2706 break;
2707
2708 default:
2709 bfa_sm_fault(ln->fcport->bfa, event);
2710 }
2711}
2712
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002713static void
2714__bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
2715{
2716 struct bfa_fcport_ln_s *ln = cbarg;
2717
2718 if (complete)
2719 ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
2720 else
2721 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2722}
2723
Jing Huang5fbe25c2010-10-18 17:17:23 -07002724/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002725 * Send SCN notification to upper layers.
2726 * trunk - false if caller is fcport to ignore fcport event in trunked mode
2727 */
2728static void
2729bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
2730 bfa_boolean_t trunk)
2731{
2732 if (fcport->cfg.trunked && !trunk)
2733 return;
2734
2735 switch (event) {
2736 case BFA_PORT_LINKUP:
2737 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
2738 break;
2739 case BFA_PORT_LINKDOWN:
2740 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
2741 break;
2742 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08002743 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002744 }
2745}
2746
2747static void
2748bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
2749{
2750 struct bfa_fcport_s *fcport = ln->fcport;
2751
2752 if (fcport->bfa->fcs) {
2753 fcport->event_cbfn(fcport->event_cbarg, event);
2754 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2755 } else {
2756 ln->ln_event = event;
2757 bfa_cb_queue(fcport->bfa, &ln->ln_qe,
2758 __bfa_cb_fcport_event, ln);
2759 }
2760}
2761
2762#define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
2763 BFA_CACHELINE_SZ))
2764
2765static void
2766bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
2767 u32 *dm_len)
2768{
2769 *dm_len += FCPORT_STATS_DMA_SZ;
2770}
2771
2772static void
2773bfa_fcport_qresume(void *cbarg)
2774{
2775 struct bfa_fcport_s *fcport = cbarg;
2776
2777 bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
2778}
2779
2780static void
2781bfa_fcport_mem_claim(struct bfa_fcport_s *fcport, struct bfa_meminfo_s *meminfo)
2782{
2783 u8 *dm_kva;
2784 u64 dm_pa;
2785
2786 dm_kva = bfa_meminfo_dma_virt(meminfo);
2787 dm_pa = bfa_meminfo_dma_phys(meminfo);
2788
2789 fcport->stats_kva = dm_kva;
2790 fcport->stats_pa = dm_pa;
2791 fcport->stats = (union bfa_fcport_stats_u *) dm_kva;
2792
2793 dm_kva += FCPORT_STATS_DMA_SZ;
2794 dm_pa += FCPORT_STATS_DMA_SZ;
2795
2796 bfa_meminfo_dma_virt(meminfo) = dm_kva;
2797 bfa_meminfo_dma_phys(meminfo) = dm_pa;
2798}
2799
Jing Huang5fbe25c2010-10-18 17:17:23 -07002800/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002801 * Memory initialization.
2802 */
2803static void
2804bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
2805 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
2806{
2807 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2808 struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
2809 struct bfa_fcport_ln_s *ln = &fcport->ln;
Maggie Zhangf16a1752010-12-09 19:12:32 -08002810 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002811
Jing Huang6a18b162010-10-18 17:08:54 -07002812 memset(fcport, 0, sizeof(struct bfa_fcport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002813 fcport->bfa = bfa;
2814 ln->fcport = fcport;
2815
2816 bfa_fcport_mem_claim(fcport, meminfo);
2817
2818 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
2819 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2820
Jing Huang5fbe25c2010-10-18 17:17:23 -07002821 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002822 * initialize time stamp for stats reset
2823 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08002824 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002825 fcport->stats_reset_time = tv.tv_sec;
2826
Jing Huang5fbe25c2010-10-18 17:17:23 -07002827 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002828 * initialize and set default configuration
2829 */
2830 port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
2831 port_cfg->speed = BFA_PORT_SPEED_AUTO;
2832 port_cfg->trunked = BFA_FALSE;
2833 port_cfg->maxfrsize = 0;
2834
2835 port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
2836
2837 bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
2838}
2839
2840static void
2841bfa_fcport_detach(struct bfa_s *bfa)
2842{
2843}
2844
Jing Huang5fbe25c2010-10-18 17:17:23 -07002845/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002846 * Called when IOC is ready.
2847 */
2848static void
2849bfa_fcport_start(struct bfa_s *bfa)
2850{
2851 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
2852}
2853
Jing Huang5fbe25c2010-10-18 17:17:23 -07002854/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002855 * Called before IOC is stopped.
2856 */
2857static void
2858bfa_fcport_stop(struct bfa_s *bfa)
2859{
2860 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
2861 bfa_trunk_iocdisable(bfa);
2862}
2863
Jing Huang5fbe25c2010-10-18 17:17:23 -07002864/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002865 * Called when IOC failure is detected.
2866 */
2867static void
2868bfa_fcport_iocdisable(struct bfa_s *bfa)
2869{
2870 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2871
2872 bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
2873 bfa_trunk_iocdisable(bfa);
2874}
2875
2876static void
2877bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
2878{
2879 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2880 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
2881
2882 fcport->speed = pevent->link_state.speed;
2883 fcport->topology = pevent->link_state.topology;
2884
2885 if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)
2886 fcport->myalpa = 0;
2887
2888 /* QoS Details */
Jing Huang6a18b162010-10-18 17:08:54 -07002889 fcport->qos_attr = pevent->link_state.qos_attr;
2890 fcport->qos_vc_attr = pevent->link_state.vc_fcf.qos_vc_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002891
Jing Huang5fbe25c2010-10-18 17:17:23 -07002892 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002893 * update trunk state if applicable
2894 */
2895 if (!fcport->cfg.trunked)
2896 trunk->attr.state = BFA_TRUNK_DISABLED;
2897
2898 /* update FCoE specific */
Jing Huangba816ea2010-10-18 17:10:50 -07002899 fcport->fcoe_vlan = be16_to_cpu(pevent->link_state.vc_fcf.fcf.vlan);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002900
2901 bfa_trc(fcport->bfa, fcport->speed);
2902 bfa_trc(fcport->bfa, fcport->topology);
2903}
2904
2905static void
2906bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
2907{
2908 fcport->speed = BFA_PORT_SPEED_UNKNOWN;
2909 fcport->topology = BFA_PORT_TOPOLOGY_NONE;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07002910 fcport->bbsc_op_state = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002911}
2912
Jing Huang5fbe25c2010-10-18 17:17:23 -07002913/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002914 * Send port enable message to firmware.
2915 */
2916static bfa_boolean_t
2917bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
2918{
2919 struct bfi_fcport_enable_req_s *m;
2920
Jing Huang5fbe25c2010-10-18 17:17:23 -07002921 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002922 * Increment message tag before queue check, so that responses to old
2923 * requests are discarded.
2924 */
2925 fcport->msgtag++;
2926
Jing Huang5fbe25c2010-10-18 17:17:23 -07002927 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002928 * check for room in queue to send request now
2929 */
2930 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
2931 if (!m) {
2932 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
2933 &fcport->reqq_wait);
2934 return BFA_FALSE;
2935 }
2936
2937 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
2938 bfa_lpuid(fcport->bfa));
2939 m->nwwn = fcport->nwwn;
2940 m->pwwn = fcport->pwwn;
2941 m->port_cfg = fcport->cfg;
2942 m->msgtag = fcport->msgtag;
Jing Huangba816ea2010-10-18 17:10:50 -07002943 m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08002944 m->use_flash_cfg = fcport->use_flash_cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002945 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
2946 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
2947 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
2948
Jing Huang5fbe25c2010-10-18 17:17:23 -07002949 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002950 * queue I/O message to firmware
2951 */
2952 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
2953 return BFA_TRUE;
2954}
2955
Jing Huang5fbe25c2010-10-18 17:17:23 -07002956/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002957 * Send port disable message to firmware.
2958 */
2959static bfa_boolean_t
2960bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
2961{
2962 struct bfi_fcport_req_s *m;
2963
Jing Huang5fbe25c2010-10-18 17:17:23 -07002964 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002965 * Increment message tag before queue check, so that responses to old
2966 * requests are discarded.
2967 */
2968 fcport->msgtag++;
2969
Jing Huang5fbe25c2010-10-18 17:17:23 -07002970 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002971 * check for room in queue to send request now
2972 */
2973 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
2974 if (!m) {
2975 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
2976 &fcport->reqq_wait);
2977 return BFA_FALSE;
2978 }
2979
2980 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
2981 bfa_lpuid(fcport->bfa));
2982 m->msgtag = fcport->msgtag;
2983
Jing Huang5fbe25c2010-10-18 17:17:23 -07002984 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002985 * queue I/O message to firmware
2986 */
2987 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
2988
2989 return BFA_TRUE;
2990}
2991
2992static void
2993bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
2994{
Maggie Zhangf7f73812010-12-09 19:08:43 -08002995 fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
2996 fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002997
2998 bfa_trc(fcport->bfa, fcport->pwwn);
2999 bfa_trc(fcport->bfa, fcport->nwwn);
3000}
3001
3002static void
3003bfa_fcport_send_txcredit(void *port_cbarg)
3004{
3005
3006 struct bfa_fcport_s *fcport = port_cbarg;
3007 struct bfi_fcport_set_svc_params_req_s *m;
3008
Jing Huang5fbe25c2010-10-18 17:17:23 -07003009 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003010 * check for room in queue to send request now
3011 */
3012 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3013 if (!m) {
3014 bfa_trc(fcport->bfa, fcport->cfg.tx_bbcredit);
3015 return;
3016 }
3017
3018 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ,
3019 bfa_lpuid(fcport->bfa));
Jing Huangba816ea2010-10-18 17:10:50 -07003020 m->tx_bbcredit = cpu_to_be16((u16)fcport->cfg.tx_bbcredit);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003021 m->bb_scn = fcport->cfg.bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003022
Jing Huang5fbe25c2010-10-18 17:17:23 -07003023 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003024 * queue I/O message to firmware
3025 */
3026 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
3027}
3028
3029static void
3030bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
3031 struct bfa_qos_stats_s *s)
3032{
3033 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003034 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003035 int i;
3036
3037 /* Now swap the 32 bit fields */
3038 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
Jing Huangba816ea2010-10-18 17:10:50 -07003039 dip[i] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003040}
3041
3042static void
3043bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
3044 struct bfa_fcoe_stats_s *s)
3045{
3046 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003047 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003048 int i;
3049
3050 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
3051 i = i + 2) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003052#ifdef __BIG_ENDIAN
Jing Huangba816ea2010-10-18 17:10:50 -07003053 dip[i] = be32_to_cpu(sip[i]);
3054 dip[i + 1] = be32_to_cpu(sip[i + 1]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003055#else
Jing Huangba816ea2010-10-18 17:10:50 -07003056 dip[i] = be32_to_cpu(sip[i + 1]);
3057 dip[i + 1] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003058#endif
3059 }
3060}
3061
3062static void
3063__bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
3064{
3065 struct bfa_fcport_s *fcport = cbarg;
3066
3067 if (complete) {
3068 if (fcport->stats_status == BFA_STATUS_OK) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003069 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003070
3071 /* Swap FC QoS or FCoE stats */
3072 if (bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
3073 bfa_fcport_qos_stats_swap(
3074 &fcport->stats_ret->fcqos,
3075 &fcport->stats->fcqos);
3076 } else {
3077 bfa_fcport_fcoe_stats_swap(
3078 &fcport->stats_ret->fcoe,
3079 &fcport->stats->fcoe);
3080
Maggie Zhangf16a1752010-12-09 19:12:32 -08003081 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003082 fcport->stats_ret->fcoe.secs_reset =
3083 tv.tv_sec - fcport->stats_reset_time;
3084 }
3085 }
3086 fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
3087 } else {
3088 fcport->stats_busy = BFA_FALSE;
3089 fcport->stats_status = BFA_STATUS_OK;
3090 }
3091}
3092
3093static void
3094bfa_fcport_stats_get_timeout(void *cbarg)
3095{
3096 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3097
3098 bfa_trc(fcport->bfa, fcport->stats_qfull);
3099
3100 if (fcport->stats_qfull) {
3101 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3102 fcport->stats_qfull = BFA_FALSE;
3103 }
3104
3105 fcport->stats_status = BFA_STATUS_ETIMER;
3106 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, __bfa_cb_fcport_stats_get,
3107 fcport);
3108}
3109
3110static void
3111bfa_fcport_send_stats_get(void *cbarg)
3112{
3113 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3114 struct bfi_fcport_req_s *msg;
3115
3116 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3117
3118 if (!msg) {
3119 fcport->stats_qfull = BFA_TRUE;
3120 bfa_reqq_winit(&fcport->stats_reqq_wait,
3121 bfa_fcport_send_stats_get, fcport);
3122 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3123 &fcport->stats_reqq_wait);
3124 return;
3125 }
3126 fcport->stats_qfull = BFA_FALSE;
3127
Jing Huang6a18b162010-10-18 17:08:54 -07003128 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003129 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
3130 bfa_lpuid(fcport->bfa));
3131 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
3132}
3133
3134static void
3135__bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
3136{
3137 struct bfa_fcport_s *fcport = cbarg;
3138
3139 if (complete) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003140 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003141
Jing Huang5fbe25c2010-10-18 17:17:23 -07003142 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003143 * re-initialize time stamp for stats reset
3144 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08003145 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003146 fcport->stats_reset_time = tv.tv_sec;
3147
3148 fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
3149 } else {
3150 fcport->stats_busy = BFA_FALSE;
3151 fcport->stats_status = BFA_STATUS_OK;
3152 }
3153}
3154
3155static void
3156bfa_fcport_stats_clr_timeout(void *cbarg)
3157{
3158 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3159
3160 bfa_trc(fcport->bfa, fcport->stats_qfull);
3161
3162 if (fcport->stats_qfull) {
3163 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3164 fcport->stats_qfull = BFA_FALSE;
3165 }
3166
3167 fcport->stats_status = BFA_STATUS_ETIMER;
3168 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3169 __bfa_cb_fcport_stats_clr, fcport);
3170}
3171
3172static void
3173bfa_fcport_send_stats_clear(void *cbarg)
3174{
3175 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3176 struct bfi_fcport_req_s *msg;
3177
3178 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3179
3180 if (!msg) {
3181 fcport->stats_qfull = BFA_TRUE;
3182 bfa_reqq_winit(&fcport->stats_reqq_wait,
3183 bfa_fcport_send_stats_clear, fcport);
3184 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3185 &fcport->stats_reqq_wait);
3186 return;
3187 }
3188 fcport->stats_qfull = BFA_FALSE;
3189
Jing Huang6a18b162010-10-18 17:08:54 -07003190 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003191 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
3192 bfa_lpuid(fcport->bfa));
3193 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
3194}
3195
Jing Huang5fbe25c2010-10-18 17:17:23 -07003196/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003197 * Handle trunk SCN event from firmware.
3198 */
3199static void
3200bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3201{
3202 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3203 struct bfi_fcport_trunk_link_s *tlink;
3204 struct bfa_trunk_link_attr_s *lattr;
3205 enum bfa_trunk_state state_prev;
3206 int i;
3207 int link_bm = 0;
3208
3209 bfa_trc(fcport->bfa, fcport->cfg.trunked);
Jing Huangd4b671c2010-12-26 21:46:35 -08003210 WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
3211 scn->trunk_state != BFA_TRUNK_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003212
3213 bfa_trc(fcport->bfa, trunk->attr.state);
3214 bfa_trc(fcport->bfa, scn->trunk_state);
3215 bfa_trc(fcport->bfa, scn->trunk_speed);
3216
Jing Huang5fbe25c2010-10-18 17:17:23 -07003217 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003218 * Save off new state for trunk attribute query
3219 */
3220 state_prev = trunk->attr.state;
3221 if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
3222 trunk->attr.state = scn->trunk_state;
3223 trunk->attr.speed = scn->trunk_speed;
3224 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3225 lattr = &trunk->attr.link_attr[i];
3226 tlink = &scn->tlink[i];
3227
3228 lattr->link_state = tlink->state;
3229 lattr->trunk_wwn = tlink->trunk_wwn;
3230 lattr->fctl = tlink->fctl;
3231 lattr->speed = tlink->speed;
Jing Huangba816ea2010-10-18 17:10:50 -07003232 lattr->deskew = be32_to_cpu(tlink->deskew);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003233
3234 if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
3235 fcport->speed = tlink->speed;
3236 fcport->topology = BFA_PORT_TOPOLOGY_P2P;
3237 link_bm |= 1 << i;
3238 }
3239
3240 bfa_trc(fcport->bfa, lattr->link_state);
3241 bfa_trc(fcport->bfa, lattr->trunk_wwn);
3242 bfa_trc(fcport->bfa, lattr->fctl);
3243 bfa_trc(fcport->bfa, lattr->speed);
3244 bfa_trc(fcport->bfa, lattr->deskew);
3245 }
3246
3247 switch (link_bm) {
3248 case 3:
3249 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3250 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
3251 break;
3252 case 2:
3253 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3254 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
3255 break;
3256 case 1:
3257 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3258 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
3259 break;
3260 default:
3261 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3262 BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
3263 }
3264
Jing Huang5fbe25c2010-10-18 17:17:23 -07003265 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003266 * Notify upper layers if trunk state changed.
3267 */
3268 if ((state_prev != trunk->attr.state) ||
3269 (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
3270 bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
3271 BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
3272 }
3273}
3274
3275static void
3276bfa_trunk_iocdisable(struct bfa_s *bfa)
3277{
3278 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3279 int i = 0;
3280
Jing Huang5fbe25c2010-10-18 17:17:23 -07003281 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003282 * In trunked mode, notify upper layers that link is down
3283 */
3284 if (fcport->cfg.trunked) {
3285 if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
3286 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
3287
3288 fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
3289 fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
3290 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3291 fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
3292 fcport->trunk.attr.link_attr[i].fctl =
3293 BFA_TRUNK_LINK_FCTL_NORMAL;
3294 fcport->trunk.attr.link_attr[i].link_state =
3295 BFA_TRUNK_LINK_STATE_DN_LINKDN;
3296 fcport->trunk.attr.link_attr[i].speed =
3297 BFA_PORT_SPEED_UNKNOWN;
3298 fcport->trunk.attr.link_attr[i].deskew = 0;
3299 }
3300 }
3301}
3302
Jing Huang5fbe25c2010-10-18 17:17:23 -07003303/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003304 * Called to initialize port attributes
3305 */
3306void
3307bfa_fcport_init(struct bfa_s *bfa)
3308{
3309 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3310
Jing Huang5fbe25c2010-10-18 17:17:23 -07003311 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003312 * Initialize port attributes from IOC hardware data.
3313 */
3314 bfa_fcport_set_wwns(fcport);
3315 if (fcport->cfg.maxfrsize == 0)
3316 fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
3317 fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
3318 fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
3319
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003320 if (bfa_fcport_is_pbcdisabled(bfa))
3321 bfa->modules.port.pbc_disabled = BFA_TRUE;
3322
Jing Huangd4b671c2010-12-26 21:46:35 -08003323 WARN_ON(!fcport->cfg.maxfrsize);
3324 WARN_ON(!fcport->cfg.rx_bbcredit);
3325 WARN_ON(!fcport->speed_sup);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003326}
3327
Jing Huang5fbe25c2010-10-18 17:17:23 -07003328/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003329 * Firmware message handler.
3330 */
3331void
3332bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
3333{
3334 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3335 union bfi_fcport_i2h_msg_u i2hmsg;
3336
3337 i2hmsg.msg = msg;
3338 fcport->event_arg.i2hmsg = i2hmsg;
3339
3340 bfa_trc(bfa, msg->mhdr.msg_id);
3341 bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
3342
3343 switch (msg->mhdr.msg_id) {
3344 case BFI_FCPORT_I2H_ENABLE_RSP:
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003345 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
3346
3347 if (fcport->use_flash_cfg) {
3348 fcport->cfg = i2hmsg.penable_rsp->port_cfg;
3349 fcport->cfg.maxfrsize =
3350 cpu_to_be16(fcport->cfg.maxfrsize);
3351 fcport->cfg.path_tov =
3352 cpu_to_be16(fcport->cfg.path_tov);
3353 fcport->cfg.q_depth =
3354 cpu_to_be16(fcport->cfg.q_depth);
3355
3356 if (fcport->cfg.trunked)
3357 fcport->trunk.attr.state =
3358 BFA_TRUNK_OFFLINE;
3359 else
3360 fcport->trunk.attr.state =
3361 BFA_TRUNK_DISABLED;
3362 fcport->use_flash_cfg = BFA_FALSE;
3363 }
3364
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003365 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003366 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003367 break;
3368
3369 case BFI_FCPORT_I2H_DISABLE_RSP:
3370 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
3371 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
3372 break;
3373
3374 case BFI_FCPORT_I2H_EVENT:
3375 if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
3376 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
3377 else
3378 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
3379 break;
3380
3381 case BFI_FCPORT_I2H_TRUNK_SCN:
3382 bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
3383 break;
3384
3385 case BFI_FCPORT_I2H_STATS_GET_RSP:
3386 /*
3387 * check for timer pop before processing the rsp
3388 */
3389 if (fcport->stats_busy == BFA_FALSE ||
3390 fcport->stats_status == BFA_STATUS_ETIMER)
3391 break;
3392
3393 bfa_timer_stop(&fcport->timer);
3394 fcport->stats_status = i2hmsg.pstatsget_rsp->status;
3395 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3396 __bfa_cb_fcport_stats_get, fcport);
3397 break;
3398
3399 case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
3400 /*
3401 * check for timer pop before processing the rsp
3402 */
3403 if (fcport->stats_busy == BFA_FALSE ||
3404 fcport->stats_status == BFA_STATUS_ETIMER)
3405 break;
3406
3407 bfa_timer_stop(&fcport->timer);
3408 fcport->stats_status = BFA_STATUS_OK;
3409 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3410 __bfa_cb_fcport_stats_clr, fcport);
3411 break;
3412
3413 case BFI_FCPORT_I2H_ENABLE_AEN:
3414 bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
3415 break;
3416
3417 case BFI_FCPORT_I2H_DISABLE_AEN:
3418 bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
3419 break;
3420
3421 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08003422 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003423 break;
3424 }
3425}
3426
Jing Huang5fbe25c2010-10-18 17:17:23 -07003427/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003428 * Registered callback for port events.
3429 */
3430void
3431bfa_fcport_event_register(struct bfa_s *bfa,
3432 void (*cbfn) (void *cbarg,
3433 enum bfa_port_linkstate event),
3434 void *cbarg)
3435{
3436 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3437
3438 fcport->event_cbfn = cbfn;
3439 fcport->event_cbarg = cbarg;
3440}
3441
3442bfa_status_t
3443bfa_fcport_enable(struct bfa_s *bfa)
3444{
3445 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3446
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003447 if (bfa_fcport_is_pbcdisabled(bfa))
3448 return BFA_STATUS_PBC;
3449
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003450 if (bfa_ioc_is_disabled(&bfa->ioc))
3451 return BFA_STATUS_IOC_DISABLED;
3452
3453 if (fcport->diag_busy)
3454 return BFA_STATUS_DIAG_BUSY;
3455
3456 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
3457 return BFA_STATUS_OK;
3458}
3459
3460bfa_status_t
3461bfa_fcport_disable(struct bfa_s *bfa)
3462{
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003463 if (bfa_fcport_is_pbcdisabled(bfa))
3464 return BFA_STATUS_PBC;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003465
3466 if (bfa_ioc_is_disabled(&bfa->ioc))
3467 return BFA_STATUS_IOC_DISABLED;
3468
3469 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
3470 return BFA_STATUS_OK;
3471}
3472
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003473/* If PBC is disabled on port, return error */
3474bfa_status_t
3475bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
3476{
3477 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3478 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
3479 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
3480
3481 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
3482 bfa_trc(bfa, fcport->pwwn);
3483 return BFA_STATUS_PBC;
3484 }
3485 return BFA_STATUS_OK;
3486}
3487
Jing Huang5fbe25c2010-10-18 17:17:23 -07003488/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003489 * Configure port speed.
3490 */
3491bfa_status_t
3492bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3493{
3494 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3495
3496 bfa_trc(bfa, speed);
3497
3498 if (fcport->cfg.trunked == BFA_TRUE)
3499 return BFA_STATUS_TRUNK_ENABLED;
3500 if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
3501 bfa_trc(bfa, fcport->speed_sup);
3502 return BFA_STATUS_UNSUPP_SPEED;
3503 }
3504
Krishna Gudipatia7141342011-06-24 20:23:19 -07003505 /* For Mezz card, port speed entered needs to be checked */
3506 if (bfa_mfg_is_mezz(fcport->bfa->ioc.attr->card_type)) {
3507 if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
3508 /* For CT2, 1G is not supported */
3509 if ((speed == BFA_PORT_SPEED_1GBPS) &&
3510 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
3511 return BFA_STATUS_UNSUPP_SPEED;
3512
3513 /* Already checked for Auto Speed and Max Speed supp */
3514 if (!(speed == BFA_PORT_SPEED_1GBPS ||
3515 speed == BFA_PORT_SPEED_2GBPS ||
3516 speed == BFA_PORT_SPEED_4GBPS ||
3517 speed == BFA_PORT_SPEED_8GBPS ||
3518 speed == BFA_PORT_SPEED_16GBPS ||
3519 speed == BFA_PORT_SPEED_AUTO))
3520 return BFA_STATUS_UNSUPP_SPEED;
3521 } else {
3522 if (speed != BFA_PORT_SPEED_10GBPS)
3523 return BFA_STATUS_UNSUPP_SPEED;
3524 }
3525 }
3526
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003527 fcport->cfg.speed = speed;
3528
3529 return BFA_STATUS_OK;
3530}
3531
Jing Huang5fbe25c2010-10-18 17:17:23 -07003532/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003533 * Get current speed.
3534 */
3535enum bfa_port_speed
3536bfa_fcport_get_speed(struct bfa_s *bfa)
3537{
3538 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3539
3540 return fcport->speed;
3541}
3542
Jing Huang5fbe25c2010-10-18 17:17:23 -07003543/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003544 * Configure port topology.
3545 */
3546bfa_status_t
3547bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
3548{
3549 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3550
3551 bfa_trc(bfa, topology);
3552 bfa_trc(bfa, fcport->cfg.topology);
3553
3554 switch (topology) {
3555 case BFA_PORT_TOPOLOGY_P2P:
3556 case BFA_PORT_TOPOLOGY_LOOP:
3557 case BFA_PORT_TOPOLOGY_AUTO:
3558 break;
3559
3560 default:
3561 return BFA_STATUS_EINVAL;
3562 }
3563
3564 fcport->cfg.topology = topology;
3565 return BFA_STATUS_OK;
3566}
3567
Jing Huang5fbe25c2010-10-18 17:17:23 -07003568/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003569 * Get current topology.
3570 */
3571enum bfa_port_topology
3572bfa_fcport_get_topology(struct bfa_s *bfa)
3573{
3574 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3575
3576 return fcport->topology;
3577}
3578
3579bfa_status_t
3580bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
3581{
3582 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3583
3584 bfa_trc(bfa, alpa);
3585 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3586 bfa_trc(bfa, fcport->cfg.hardalpa);
3587
3588 fcport->cfg.cfg_hardalpa = BFA_TRUE;
3589 fcport->cfg.hardalpa = alpa;
3590
3591 return BFA_STATUS_OK;
3592}
3593
3594bfa_status_t
3595bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
3596{
3597 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3598
3599 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3600 bfa_trc(bfa, fcport->cfg.hardalpa);
3601
3602 fcport->cfg.cfg_hardalpa = BFA_FALSE;
3603 return BFA_STATUS_OK;
3604}
3605
3606bfa_boolean_t
3607bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
3608{
3609 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3610
3611 *alpa = fcport->cfg.hardalpa;
3612 return fcport->cfg.cfg_hardalpa;
3613}
3614
3615u8
3616bfa_fcport_get_myalpa(struct bfa_s *bfa)
3617{
3618 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3619
3620 return fcport->myalpa;
3621}
3622
3623bfa_status_t
3624bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
3625{
3626 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3627
3628 bfa_trc(bfa, maxfrsize);
3629 bfa_trc(bfa, fcport->cfg.maxfrsize);
3630
3631 /* with in range */
3632 if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
3633 return BFA_STATUS_INVLD_DFSZ;
3634
3635 /* power of 2, if not the max frame size of 2112 */
3636 if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
3637 return BFA_STATUS_INVLD_DFSZ;
3638
3639 fcport->cfg.maxfrsize = maxfrsize;
3640 return BFA_STATUS_OK;
3641}
3642
3643u16
3644bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
3645{
3646 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3647
3648 return fcport->cfg.maxfrsize;
3649}
3650
3651u8
3652bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
3653{
3654 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3655
3656 return fcport->cfg.rx_bbcredit;
3657}
3658
3659void
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003660bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit, u8 bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003661{
3662 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3663
3664 fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003665 fcport->cfg.bb_scn = bb_scn;
3666 if (bb_scn)
3667 fcport->bbsc_op_state = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003668 bfa_fcport_send_txcredit(fcport);
3669}
3670
Jing Huang5fbe25c2010-10-18 17:17:23 -07003671/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003672 * Get port attributes.
3673 */
3674
3675wwn_t
3676bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
3677{
3678 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3679 if (node)
3680 return fcport->nwwn;
3681 else
3682 return fcport->pwwn;
3683}
3684
3685void
3686bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3687{
3688 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3689
Jing Huang6a18b162010-10-18 17:08:54 -07003690 memset(attr, 0, sizeof(struct bfa_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003691
3692 attr->nwwn = fcport->nwwn;
3693 attr->pwwn = fcport->pwwn;
3694
Maggie Zhangf7f73812010-12-09 19:08:43 -08003695 attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
3696 attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003697
Jing Huang6a18b162010-10-18 17:08:54 -07003698 memcpy(&attr->pport_cfg, &fcport->cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003699 sizeof(struct bfa_port_cfg_s));
3700 /* speed attributes */
3701 attr->pport_cfg.speed = fcport->cfg.speed;
3702 attr->speed_supported = fcport->speed_sup;
3703 attr->speed = fcport->speed;
3704 attr->cos_supported = FC_CLASS_3;
3705
3706 /* topology attributes */
3707 attr->pport_cfg.topology = fcport->cfg.topology;
3708 attr->topology = fcport->topology;
3709 attr->pport_cfg.trunked = fcport->cfg.trunked;
3710
3711 /* beacon attributes */
3712 attr->beacon = fcport->beacon;
3713 attr->link_e2e_beacon = fcport->link_e2e_beacon;
Maggie Zhangf7f73812010-12-09 19:08:43 -08003714 attr->plog_enabled = (bfa_boolean_t)fcport->bfa->plog->plog_enabled;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003715 attr->io_profile = bfa_fcpim_get_io_profile(fcport->bfa);
3716
3717 attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
3718 attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
3719 attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003720 attr->bbsc_op_status = fcport->bbsc_op_state;
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003721
3722 /* PBC Disabled State */
3723 if (bfa_fcport_is_pbcdisabled(bfa))
3724 attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
3725 else {
3726 if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
3727 attr->port_state = BFA_PORT_ST_IOCDIS;
3728 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
3729 attr->port_state = BFA_PORT_ST_FWMISMATCH;
Krishna Gudipatia7141342011-06-24 20:23:19 -07003730 else if (bfa_ioc_is_acq_addr(&fcport->bfa->ioc))
3731 attr->port_state = BFA_PORT_ST_ACQ_ADDR;
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003732 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003733
3734 /* FCoE vlan */
3735 attr->fcoe_vlan = fcport->fcoe_vlan;
3736}
3737
3738#define BFA_FCPORT_STATS_TOV 1000
3739
Jing Huang5fbe25c2010-10-18 17:17:23 -07003740/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003741 * Fetch port statistics (FCQoS or FCoE).
3742 */
3743bfa_status_t
3744bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
3745 bfa_cb_port_t cbfn, void *cbarg)
3746{
3747 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3748
3749 if (fcport->stats_busy) {
3750 bfa_trc(bfa, fcport->stats_busy);
3751 return BFA_STATUS_DEVBUSY;
3752 }
3753
3754 fcport->stats_busy = BFA_TRUE;
3755 fcport->stats_ret = stats;
3756 fcport->stats_cbfn = cbfn;
3757 fcport->stats_cbarg = cbarg;
3758
3759 bfa_fcport_send_stats_get(fcport);
3760
3761 bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_get_timeout,
3762 fcport, BFA_FCPORT_STATS_TOV);
3763 return BFA_STATUS_OK;
3764}
3765
Jing Huang5fbe25c2010-10-18 17:17:23 -07003766/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003767 * Reset port statistics (FCQoS or FCoE).
3768 */
3769bfa_status_t
3770bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_port_t cbfn, void *cbarg)
3771{
3772 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3773
3774 if (fcport->stats_busy) {
3775 bfa_trc(bfa, fcport->stats_busy);
3776 return BFA_STATUS_DEVBUSY;
3777 }
3778
3779 fcport->stats_busy = BFA_TRUE;
3780 fcport->stats_cbfn = cbfn;
3781 fcport->stats_cbarg = cbarg;
3782
3783 bfa_fcport_send_stats_clear(fcport);
3784
3785 bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_clr_timeout,
3786 fcport, BFA_FCPORT_STATS_TOV);
3787 return BFA_STATUS_OK;
3788}
3789
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003790
Jing Huang5fbe25c2010-10-18 17:17:23 -07003791/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003792 * Fetch port attributes.
3793 */
3794bfa_boolean_t
3795bfa_fcport_is_disabled(struct bfa_s *bfa)
3796{
3797 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3798
3799 return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
3800 BFA_PORT_ST_DISABLED;
3801
3802}
3803
3804bfa_boolean_t
3805bfa_fcport_is_ratelim(struct bfa_s *bfa)
3806{
3807 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3808
3809 return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
3810
3811}
3812
Jing Huang5fbe25c2010-10-18 17:17:23 -07003813/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07003814 * Enable/Disable FAA feature in port config
3815 */
3816void
3817bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state)
3818{
3819 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3820
3821 bfa_trc(bfa, state);
3822 fcport->cfg.faa_state = state;
3823}
3824
3825/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003826 * Get default minimum ratelim speed
3827 */
3828enum bfa_port_speed
3829bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
3830{
3831 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3832
3833 bfa_trc(bfa, fcport->cfg.trl_def_speed);
3834 return fcport->cfg.trl_def_speed;
3835
3836}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003837
3838bfa_boolean_t
3839bfa_fcport_is_linkup(struct bfa_s *bfa)
3840{
3841 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3842
3843 return (!fcport->cfg.trunked &&
3844 bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
3845 (fcport->cfg.trunked &&
3846 fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
3847}
3848
3849bfa_boolean_t
3850bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
3851{
3852 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3853
3854 return fcport->cfg.qos_enabled;
3855}
3856
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003857bfa_boolean_t
3858bfa_fcport_is_trunk_enabled(struct bfa_s *bfa)
3859{
3860 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3861
3862 return fcport->cfg.trunked;
3863}
3864
Jing Huang5fbe25c2010-10-18 17:17:23 -07003865/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003866 * Rport State machine functions
3867 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07003868/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003869 * Beginning state, only online event expected.
3870 */
3871static void
3872bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
3873{
3874 bfa_trc(rp->bfa, rp->rport_tag);
3875 bfa_trc(rp->bfa, event);
3876
3877 switch (event) {
3878 case BFA_RPORT_SM_CREATE:
3879 bfa_stats(rp, sm_un_cr);
3880 bfa_sm_set_state(rp, bfa_rport_sm_created);
3881 break;
3882
3883 default:
3884 bfa_stats(rp, sm_un_unexp);
3885 bfa_sm_fault(rp->bfa, event);
3886 }
3887}
3888
3889static void
3890bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
3891{
3892 bfa_trc(rp->bfa, rp->rport_tag);
3893 bfa_trc(rp->bfa, event);
3894
3895 switch (event) {
3896 case BFA_RPORT_SM_ONLINE:
3897 bfa_stats(rp, sm_cr_on);
3898 if (bfa_rport_send_fwcreate(rp))
3899 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
3900 else
3901 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
3902 break;
3903
3904 case BFA_RPORT_SM_DELETE:
3905 bfa_stats(rp, sm_cr_del);
3906 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
3907 bfa_rport_free(rp);
3908 break;
3909
3910 case BFA_RPORT_SM_HWFAIL:
3911 bfa_stats(rp, sm_cr_hwf);
3912 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3913 break;
3914
3915 default:
3916 bfa_stats(rp, sm_cr_unexp);
3917 bfa_sm_fault(rp->bfa, event);
3918 }
3919}
3920
Jing Huang5fbe25c2010-10-18 17:17:23 -07003921/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003922 * Waiting for rport create response from firmware.
3923 */
3924static void
3925bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
3926{
3927 bfa_trc(rp->bfa, rp->rport_tag);
3928 bfa_trc(rp->bfa, event);
3929
3930 switch (event) {
3931 case BFA_RPORT_SM_FWRSP:
3932 bfa_stats(rp, sm_fwc_rsp);
3933 bfa_sm_set_state(rp, bfa_rport_sm_online);
3934 bfa_rport_online_cb(rp);
3935 break;
3936
3937 case BFA_RPORT_SM_DELETE:
3938 bfa_stats(rp, sm_fwc_del);
3939 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
3940 break;
3941
3942 case BFA_RPORT_SM_OFFLINE:
3943 bfa_stats(rp, sm_fwc_off);
3944 bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
3945 break;
3946
3947 case BFA_RPORT_SM_HWFAIL:
3948 bfa_stats(rp, sm_fwc_hwf);
3949 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3950 break;
3951
3952 default:
3953 bfa_stats(rp, sm_fwc_unexp);
3954 bfa_sm_fault(rp->bfa, event);
3955 }
3956}
3957
Jing Huang5fbe25c2010-10-18 17:17:23 -07003958/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003959 * Request queue is full, awaiting queue resume to send create request.
3960 */
3961static void
3962bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
3963{
3964 bfa_trc(rp->bfa, rp->rport_tag);
3965 bfa_trc(rp->bfa, event);
3966
3967 switch (event) {
3968 case BFA_RPORT_SM_QRESUME:
3969 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
3970 bfa_rport_send_fwcreate(rp);
3971 break;
3972
3973 case BFA_RPORT_SM_DELETE:
3974 bfa_stats(rp, sm_fwc_del);
3975 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
3976 bfa_reqq_wcancel(&rp->reqq_wait);
3977 bfa_rport_free(rp);
3978 break;
3979
3980 case BFA_RPORT_SM_OFFLINE:
3981 bfa_stats(rp, sm_fwc_off);
3982 bfa_sm_set_state(rp, bfa_rport_sm_offline);
3983 bfa_reqq_wcancel(&rp->reqq_wait);
3984 bfa_rport_offline_cb(rp);
3985 break;
3986
3987 case BFA_RPORT_SM_HWFAIL:
3988 bfa_stats(rp, sm_fwc_hwf);
3989 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3990 bfa_reqq_wcancel(&rp->reqq_wait);
3991 break;
3992
3993 default:
3994 bfa_stats(rp, sm_fwc_unexp);
3995 bfa_sm_fault(rp->bfa, event);
3996 }
3997}
3998
Jing Huang5fbe25c2010-10-18 17:17:23 -07003999/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004000 * Online state - normal parking state.
4001 */
4002static void
4003bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
4004{
4005 struct bfi_rport_qos_scn_s *qos_scn;
4006
4007 bfa_trc(rp->bfa, rp->rport_tag);
4008 bfa_trc(rp->bfa, event);
4009
4010 switch (event) {
4011 case BFA_RPORT_SM_OFFLINE:
4012 bfa_stats(rp, sm_on_off);
4013 if (bfa_rport_send_fwdelete(rp))
4014 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4015 else
4016 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4017 break;
4018
4019 case BFA_RPORT_SM_DELETE:
4020 bfa_stats(rp, sm_on_del);
4021 if (bfa_rport_send_fwdelete(rp))
4022 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4023 else
4024 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4025 break;
4026
4027 case BFA_RPORT_SM_HWFAIL:
4028 bfa_stats(rp, sm_on_hwf);
4029 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4030 break;
4031
4032 case BFA_RPORT_SM_SET_SPEED:
4033 bfa_rport_send_fwspeed(rp);
4034 break;
4035
4036 case BFA_RPORT_SM_QOS_SCN:
4037 qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
4038 rp->qos_attr = qos_scn->new_qos_attr;
4039 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
4040 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
4041 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
4042 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
4043
4044 qos_scn->old_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004045 be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004046 qos_scn->new_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004047 be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004048
4049 if (qos_scn->old_qos_attr.qos_flow_id !=
4050 qos_scn->new_qos_attr.qos_flow_id)
4051 bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
4052 qos_scn->old_qos_attr,
4053 qos_scn->new_qos_attr);
4054 if (qos_scn->old_qos_attr.qos_priority !=
4055 qos_scn->new_qos_attr.qos_priority)
4056 bfa_cb_rport_qos_scn_prio(rp->rport_drv,
4057 qos_scn->old_qos_attr,
4058 qos_scn->new_qos_attr);
4059 break;
4060
4061 default:
4062 bfa_stats(rp, sm_on_unexp);
4063 bfa_sm_fault(rp->bfa, event);
4064 }
4065}
4066
Jing Huang5fbe25c2010-10-18 17:17:23 -07004067/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004068 * Firmware rport is being deleted - awaiting f/w response.
4069 */
4070static void
4071bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
4072{
4073 bfa_trc(rp->bfa, rp->rport_tag);
4074 bfa_trc(rp->bfa, event);
4075
4076 switch (event) {
4077 case BFA_RPORT_SM_FWRSP:
4078 bfa_stats(rp, sm_fwd_rsp);
4079 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4080 bfa_rport_offline_cb(rp);
4081 break;
4082
4083 case BFA_RPORT_SM_DELETE:
4084 bfa_stats(rp, sm_fwd_del);
4085 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4086 break;
4087
4088 case BFA_RPORT_SM_HWFAIL:
4089 bfa_stats(rp, sm_fwd_hwf);
4090 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4091 bfa_rport_offline_cb(rp);
4092 break;
4093
4094 default:
4095 bfa_stats(rp, sm_fwd_unexp);
4096 bfa_sm_fault(rp->bfa, event);
4097 }
4098}
4099
4100static void
4101bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4102{
4103 bfa_trc(rp->bfa, rp->rport_tag);
4104 bfa_trc(rp->bfa, event);
4105
4106 switch (event) {
4107 case BFA_RPORT_SM_QRESUME:
4108 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4109 bfa_rport_send_fwdelete(rp);
4110 break;
4111
4112 case BFA_RPORT_SM_DELETE:
4113 bfa_stats(rp, sm_fwd_del);
4114 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4115 break;
4116
4117 case BFA_RPORT_SM_HWFAIL:
4118 bfa_stats(rp, sm_fwd_hwf);
4119 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4120 bfa_reqq_wcancel(&rp->reqq_wait);
4121 bfa_rport_offline_cb(rp);
4122 break;
4123
4124 default:
4125 bfa_stats(rp, sm_fwd_unexp);
4126 bfa_sm_fault(rp->bfa, event);
4127 }
4128}
4129
Jing Huang5fbe25c2010-10-18 17:17:23 -07004130/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004131 * Offline state.
4132 */
4133static void
4134bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
4135{
4136 bfa_trc(rp->bfa, rp->rport_tag);
4137 bfa_trc(rp->bfa, event);
4138
4139 switch (event) {
4140 case BFA_RPORT_SM_DELETE:
4141 bfa_stats(rp, sm_off_del);
4142 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4143 bfa_rport_free(rp);
4144 break;
4145
4146 case BFA_RPORT_SM_ONLINE:
4147 bfa_stats(rp, sm_off_on);
4148 if (bfa_rport_send_fwcreate(rp))
4149 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4150 else
4151 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4152 break;
4153
4154 case BFA_RPORT_SM_HWFAIL:
4155 bfa_stats(rp, sm_off_hwf);
4156 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4157 break;
4158
4159 default:
4160 bfa_stats(rp, sm_off_unexp);
4161 bfa_sm_fault(rp->bfa, event);
4162 }
4163}
4164
Jing Huang5fbe25c2010-10-18 17:17:23 -07004165/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004166 * Rport is deleted, waiting for firmware response to delete.
4167 */
4168static void
4169bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
4170{
4171 bfa_trc(rp->bfa, rp->rport_tag);
4172 bfa_trc(rp->bfa, event);
4173
4174 switch (event) {
4175 case BFA_RPORT_SM_FWRSP:
4176 bfa_stats(rp, sm_del_fwrsp);
4177 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4178 bfa_rport_free(rp);
4179 break;
4180
4181 case BFA_RPORT_SM_HWFAIL:
4182 bfa_stats(rp, sm_del_hwf);
4183 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4184 bfa_rport_free(rp);
4185 break;
4186
4187 default:
4188 bfa_sm_fault(rp->bfa, event);
4189 }
4190}
4191
4192static void
4193bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4194{
4195 bfa_trc(rp->bfa, rp->rport_tag);
4196 bfa_trc(rp->bfa, event);
4197
4198 switch (event) {
4199 case BFA_RPORT_SM_QRESUME:
4200 bfa_stats(rp, sm_del_fwrsp);
4201 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4202 bfa_rport_send_fwdelete(rp);
4203 break;
4204
4205 case BFA_RPORT_SM_HWFAIL:
4206 bfa_stats(rp, sm_del_hwf);
4207 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4208 bfa_reqq_wcancel(&rp->reqq_wait);
4209 bfa_rport_free(rp);
4210 break;
4211
4212 default:
4213 bfa_sm_fault(rp->bfa, event);
4214 }
4215}
4216
Jing Huang5fbe25c2010-10-18 17:17:23 -07004217/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004218 * Waiting for rport create response from firmware. A delete is pending.
4219 */
4220static void
4221bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
4222 enum bfa_rport_event event)
4223{
4224 bfa_trc(rp->bfa, rp->rport_tag);
4225 bfa_trc(rp->bfa, event);
4226
4227 switch (event) {
4228 case BFA_RPORT_SM_FWRSP:
4229 bfa_stats(rp, sm_delp_fwrsp);
4230 if (bfa_rport_send_fwdelete(rp))
4231 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4232 else
4233 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4234 break;
4235
4236 case BFA_RPORT_SM_HWFAIL:
4237 bfa_stats(rp, sm_delp_hwf);
4238 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4239 bfa_rport_free(rp);
4240 break;
4241
4242 default:
4243 bfa_stats(rp, sm_delp_unexp);
4244 bfa_sm_fault(rp->bfa, event);
4245 }
4246}
4247
Jing Huang5fbe25c2010-10-18 17:17:23 -07004248/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004249 * Waiting for rport create response from firmware. Rport offline is pending.
4250 */
4251static void
4252bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
4253 enum bfa_rport_event event)
4254{
4255 bfa_trc(rp->bfa, rp->rport_tag);
4256 bfa_trc(rp->bfa, event);
4257
4258 switch (event) {
4259 case BFA_RPORT_SM_FWRSP:
4260 bfa_stats(rp, sm_offp_fwrsp);
4261 if (bfa_rport_send_fwdelete(rp))
4262 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4263 else
4264 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4265 break;
4266
4267 case BFA_RPORT_SM_DELETE:
4268 bfa_stats(rp, sm_offp_del);
4269 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4270 break;
4271
4272 case BFA_RPORT_SM_HWFAIL:
4273 bfa_stats(rp, sm_offp_hwf);
4274 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4275 break;
4276
4277 default:
4278 bfa_stats(rp, sm_offp_unexp);
4279 bfa_sm_fault(rp->bfa, event);
4280 }
4281}
4282
Jing Huang5fbe25c2010-10-18 17:17:23 -07004283/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004284 * IOC h/w failed.
4285 */
4286static void
4287bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
4288{
4289 bfa_trc(rp->bfa, rp->rport_tag);
4290 bfa_trc(rp->bfa, event);
4291
4292 switch (event) {
4293 case BFA_RPORT_SM_OFFLINE:
4294 bfa_stats(rp, sm_iocd_off);
4295 bfa_rport_offline_cb(rp);
4296 break;
4297
4298 case BFA_RPORT_SM_DELETE:
4299 bfa_stats(rp, sm_iocd_del);
4300 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4301 bfa_rport_free(rp);
4302 break;
4303
4304 case BFA_RPORT_SM_ONLINE:
4305 bfa_stats(rp, sm_iocd_on);
4306 if (bfa_rport_send_fwcreate(rp))
4307 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4308 else
4309 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4310 break;
4311
4312 case BFA_RPORT_SM_HWFAIL:
4313 break;
4314
4315 default:
4316 bfa_stats(rp, sm_iocd_unexp);
4317 bfa_sm_fault(rp->bfa, event);
4318 }
4319}
4320
4321
4322
Jing Huang5fbe25c2010-10-18 17:17:23 -07004323/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004324 * bfa_rport_private BFA rport private functions
4325 */
4326
4327static void
4328__bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
4329{
4330 struct bfa_rport_s *rp = cbarg;
4331
4332 if (complete)
4333 bfa_cb_rport_online(rp->rport_drv);
4334}
4335
4336static void
4337__bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
4338{
4339 struct bfa_rport_s *rp = cbarg;
4340
4341 if (complete)
4342 bfa_cb_rport_offline(rp->rport_drv);
4343}
4344
4345static void
4346bfa_rport_qresume(void *cbarg)
4347{
4348 struct bfa_rport_s *rp = cbarg;
4349
4350 bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
4351}
4352
4353static void
4354bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
4355 u32 *dm_len)
4356{
4357 if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
4358 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
4359
4360 *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s);
4361}
4362
4363static void
4364bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4365 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
4366{
4367 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4368 struct bfa_rport_s *rp;
4369 u16 i;
4370
4371 INIT_LIST_HEAD(&mod->rp_free_q);
4372 INIT_LIST_HEAD(&mod->rp_active_q);
4373
4374 rp = (struct bfa_rport_s *) bfa_meminfo_kva(meminfo);
4375 mod->rps_list = rp;
4376 mod->num_rports = cfg->fwcfg.num_rports;
4377
Jing Huangd4b671c2010-12-26 21:46:35 -08004378 WARN_ON(!mod->num_rports ||
4379 (mod->num_rports & (mod->num_rports - 1)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004380
4381 for (i = 0; i < mod->num_rports; i++, rp++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004382 memset(rp, 0, sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004383 rp->bfa = bfa;
4384 rp->rport_tag = i;
4385 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4386
Jing Huang5fbe25c2010-10-18 17:17:23 -07004387 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004388 * - is unused
4389 */
4390 if (i)
4391 list_add_tail(&rp->qe, &mod->rp_free_q);
4392
4393 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
4394 }
4395
Jing Huang5fbe25c2010-10-18 17:17:23 -07004396 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004397 * consume memory
4398 */
4399 bfa_meminfo_kva(meminfo) = (u8 *) rp;
4400}
4401
4402static void
4403bfa_rport_detach(struct bfa_s *bfa)
4404{
4405}
4406
4407static void
4408bfa_rport_start(struct bfa_s *bfa)
4409{
4410}
4411
4412static void
4413bfa_rport_stop(struct bfa_s *bfa)
4414{
4415}
4416
4417static void
4418bfa_rport_iocdisable(struct bfa_s *bfa)
4419{
4420 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4421 struct bfa_rport_s *rport;
4422 struct list_head *qe, *qen;
4423
4424 list_for_each_safe(qe, qen, &mod->rp_active_q) {
4425 rport = (struct bfa_rport_s *) qe;
4426 bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
4427 }
4428}
4429
4430static struct bfa_rport_s *
4431bfa_rport_alloc(struct bfa_rport_mod_s *mod)
4432{
4433 struct bfa_rport_s *rport;
4434
4435 bfa_q_deq(&mod->rp_free_q, &rport);
4436 if (rport)
4437 list_add_tail(&rport->qe, &mod->rp_active_q);
4438
4439 return rport;
4440}
4441
4442static void
4443bfa_rport_free(struct bfa_rport_s *rport)
4444{
4445 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
4446
Jing Huangd4b671c2010-12-26 21:46:35 -08004447 WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004448 list_del(&rport->qe);
4449 list_add_tail(&rport->qe, &mod->rp_free_q);
4450}
4451
4452static bfa_boolean_t
4453bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4454{
4455 struct bfi_rport_create_req_s *m;
4456
Jing Huang5fbe25c2010-10-18 17:17:23 -07004457 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004458 * check for room in queue to send request now
4459 */
4460 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4461 if (!m) {
4462 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4463 return BFA_FALSE;
4464 }
4465
4466 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
4467 bfa_lpuid(rp->bfa));
4468 m->bfa_handle = rp->rport_tag;
Jing Huangba816ea2010-10-18 17:10:50 -07004469 m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004470 m->pid = rp->rport_info.pid;
4471 m->lp_tag = rp->rport_info.lp_tag;
4472 m->local_pid = rp->rport_info.local_pid;
4473 m->fc_class = rp->rport_info.fc_class;
4474 m->vf_en = rp->rport_info.vf_en;
4475 m->vf_id = rp->rport_info.vf_id;
4476 m->cisc = rp->rport_info.cisc;
4477
Jing Huang5fbe25c2010-10-18 17:17:23 -07004478 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004479 * queue I/O message to firmware
4480 */
4481 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
4482 return BFA_TRUE;
4483}
4484
4485static bfa_boolean_t
4486bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4487{
4488 struct bfi_rport_delete_req_s *m;
4489
Jing Huang5fbe25c2010-10-18 17:17:23 -07004490 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004491 * check for room in queue to send request now
4492 */
4493 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4494 if (!m) {
4495 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4496 return BFA_FALSE;
4497 }
4498
4499 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
4500 bfa_lpuid(rp->bfa));
4501 m->fw_handle = rp->fw_handle;
4502
Jing Huang5fbe25c2010-10-18 17:17:23 -07004503 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004504 * queue I/O message to firmware
4505 */
4506 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
4507 return BFA_TRUE;
4508}
4509
4510static bfa_boolean_t
4511bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4512{
4513 struct bfa_rport_speed_req_s *m;
4514
Jing Huang5fbe25c2010-10-18 17:17:23 -07004515 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004516 * check for room in queue to send request now
4517 */
4518 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4519 if (!m) {
4520 bfa_trc(rp->bfa, rp->rport_info.speed);
4521 return BFA_FALSE;
4522 }
4523
4524 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
4525 bfa_lpuid(rp->bfa));
4526 m->fw_handle = rp->fw_handle;
4527 m->speed = (u8)rp->rport_info.speed;
4528
Jing Huang5fbe25c2010-10-18 17:17:23 -07004529 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004530 * queue I/O message to firmware
4531 */
4532 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
4533 return BFA_TRUE;
4534}
4535
4536
4537
Jing Huang5fbe25c2010-10-18 17:17:23 -07004538/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004539 * bfa_rport_public
4540 */
4541
Jing Huang5fbe25c2010-10-18 17:17:23 -07004542/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004543 * Rport interrupt processing.
4544 */
4545void
4546bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
4547{
4548 union bfi_rport_i2h_msg_u msg;
4549 struct bfa_rport_s *rp;
4550
4551 bfa_trc(bfa, m->mhdr.msg_id);
4552
4553 msg.msg = m;
4554
4555 switch (m->mhdr.msg_id) {
4556 case BFI_RPORT_I2H_CREATE_RSP:
4557 rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
4558 rp->fw_handle = msg.create_rsp->fw_handle;
4559 rp->qos_attr = msg.create_rsp->qos_attr;
Jing Huangd4b671c2010-12-26 21:46:35 -08004560 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004561 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4562 break;
4563
4564 case BFI_RPORT_I2H_DELETE_RSP:
4565 rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08004566 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004567 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4568 break;
4569
4570 case BFI_RPORT_I2H_QOS_SCN:
4571 rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
4572 rp->event_arg.fw_msg = msg.qos_scn_evt;
4573 bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
4574 break;
4575
4576 default:
4577 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08004578 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004579 }
4580}
4581
4582
4583
Jing Huang5fbe25c2010-10-18 17:17:23 -07004584/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004585 * bfa_rport_api
4586 */
4587
4588struct bfa_rport_s *
4589bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
4590{
4591 struct bfa_rport_s *rp;
4592
4593 rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
4594
4595 if (rp == NULL)
4596 return NULL;
4597
4598 rp->bfa = bfa;
4599 rp->rport_drv = rport_drv;
Maggie Zhangf7f73812010-12-09 19:08:43 -08004600 memset(&rp->stats, 0, sizeof(rp->stats));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004601
Jing Huangd4b671c2010-12-26 21:46:35 -08004602 WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004603 bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
4604
4605 return rp;
4606}
4607
4608void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004609bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
4610{
Jing Huangd4b671c2010-12-26 21:46:35 -08004611 WARN_ON(rport_info->max_frmsz == 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004612
Jing Huang5fbe25c2010-10-18 17:17:23 -07004613 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004614 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
4615 * responses. Default to minimum size.
4616 */
4617 if (rport_info->max_frmsz == 0) {
4618 bfa_trc(rport->bfa, rport->rport_tag);
4619 rport_info->max_frmsz = FC_MIN_PDUSZ;
4620 }
4621
Jing Huang6a18b162010-10-18 17:08:54 -07004622 rport->rport_info = *rport_info;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004623 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
4624}
4625
4626void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004627bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
4628{
Jing Huangd4b671c2010-12-26 21:46:35 -08004629 WARN_ON(speed == 0);
4630 WARN_ON(speed == BFA_PORT_SPEED_AUTO);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004631
4632 rport->rport_info.speed = speed;
4633 bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
4634}
4635
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004636
Jing Huang5fbe25c2010-10-18 17:17:23 -07004637/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004638 * SGPG related functions
4639 */
4640
Jing Huang5fbe25c2010-10-18 17:17:23 -07004641/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004642 * Compute and return memory needed by FCP(im) module.
4643 */
4644static void
4645bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
4646 u32 *dm_len)
4647{
4648 if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
4649 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
4650
4651 *km_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfa_sgpg_s);
4652 *dm_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfi_sgpg_s);
4653}
4654
4655
4656static void
4657bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4658 struct bfa_meminfo_s *minfo, struct bfa_pcidev_s *pcidev)
4659{
4660 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4661 int i;
4662 struct bfa_sgpg_s *hsgpg;
4663 struct bfi_sgpg_s *sgpg;
4664 u64 align_len;
4665
4666 union {
4667 u64 pa;
4668 union bfi_addr_u addr;
4669 } sgpg_pa, sgpg_pa_tmp;
4670
4671 INIT_LIST_HEAD(&mod->sgpg_q);
4672 INIT_LIST_HEAD(&mod->sgpg_wait_q);
4673
4674 bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
4675
4676 mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
4677 mod->sgpg_arr_pa = bfa_meminfo_dma_phys(minfo);
4678 align_len = (BFA_SGPG_ROUNDUP(mod->sgpg_arr_pa) - mod->sgpg_arr_pa);
4679 mod->sgpg_arr_pa += align_len;
4680 mod->hsgpg_arr = (struct bfa_sgpg_s *) (bfa_meminfo_kva(minfo) +
4681 align_len);
4682 mod->sgpg_arr = (struct bfi_sgpg_s *) (bfa_meminfo_dma_virt(minfo) +
4683 align_len);
4684
4685 hsgpg = mod->hsgpg_arr;
4686 sgpg = mod->sgpg_arr;
4687 sgpg_pa.pa = mod->sgpg_arr_pa;
4688 mod->free_sgpgs = mod->num_sgpgs;
4689
Jing Huangd4b671c2010-12-26 21:46:35 -08004690 WARN_ON(sgpg_pa.pa & (sizeof(struct bfi_sgpg_s) - 1));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004691
4692 for (i = 0; i < mod->num_sgpgs; i++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004693 memset(hsgpg, 0, sizeof(*hsgpg));
4694 memset(sgpg, 0, sizeof(*sgpg));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004695
4696 hsgpg->sgpg = sgpg;
4697 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
4698 hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
4699 list_add_tail(&hsgpg->qe, &mod->sgpg_q);
4700
4701 hsgpg++;
4702 sgpg++;
4703 sgpg_pa.pa += sizeof(struct bfi_sgpg_s);
4704 }
4705
4706 bfa_meminfo_kva(minfo) = (u8 *) hsgpg;
4707 bfa_meminfo_dma_virt(minfo) = (u8 *) sgpg;
4708 bfa_meminfo_dma_phys(minfo) = sgpg_pa.pa;
4709}
4710
4711static void
4712bfa_sgpg_detach(struct bfa_s *bfa)
4713{
4714}
4715
4716static void
4717bfa_sgpg_start(struct bfa_s *bfa)
4718{
4719}
4720
4721static void
4722bfa_sgpg_stop(struct bfa_s *bfa)
4723{
4724}
4725
4726static void
4727bfa_sgpg_iocdisable(struct bfa_s *bfa)
4728{
4729}
4730
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004731bfa_status_t
4732bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
4733{
4734 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4735 struct bfa_sgpg_s *hsgpg;
4736 int i;
4737
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004738 if (mod->free_sgpgs < nsgpgs)
4739 return BFA_STATUS_ENOMEM;
4740
4741 for (i = 0; i < nsgpgs; i++) {
4742 bfa_q_deq(&mod->sgpg_q, &hsgpg);
Jing Huangd4b671c2010-12-26 21:46:35 -08004743 WARN_ON(!hsgpg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004744 list_add_tail(&hsgpg->qe, sgpg_q);
4745 }
4746
4747 mod->free_sgpgs -= nsgpgs;
4748 return BFA_STATUS_OK;
4749}
4750
4751void
4752bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
4753{
4754 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4755 struct bfa_sgpg_wqe_s *wqe;
4756
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004757 mod->free_sgpgs += nsgpg;
Jing Huangd4b671c2010-12-26 21:46:35 -08004758 WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004759
4760 list_splice_tail_init(sgpg_q, &mod->sgpg_q);
4761
4762 if (list_empty(&mod->sgpg_wait_q))
4763 return;
4764
Jing Huang5fbe25c2010-10-18 17:17:23 -07004765 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004766 * satisfy as many waiting requests as possible
4767 */
4768 do {
4769 wqe = bfa_q_first(&mod->sgpg_wait_q);
4770 if (mod->free_sgpgs < wqe->nsgpg)
4771 nsgpg = mod->free_sgpgs;
4772 else
4773 nsgpg = wqe->nsgpg;
4774 bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
4775 wqe->nsgpg -= nsgpg;
4776 if (wqe->nsgpg == 0) {
4777 list_del(&wqe->qe);
4778 wqe->cbfn(wqe->cbarg);
4779 }
4780 } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
4781}
4782
4783void
4784bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
4785{
4786 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4787
Jing Huangd4b671c2010-12-26 21:46:35 -08004788 WARN_ON(nsgpg <= 0);
4789 WARN_ON(nsgpg <= mod->free_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004790
4791 wqe->nsgpg_total = wqe->nsgpg = nsgpg;
4792
Jing Huang5fbe25c2010-10-18 17:17:23 -07004793 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004794 * allocate any left to this one first
4795 */
4796 if (mod->free_sgpgs) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07004797 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004798 * no one else is waiting for SGPG
4799 */
Jing Huangd4b671c2010-12-26 21:46:35 -08004800 WARN_ON(!list_empty(&mod->sgpg_wait_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004801 list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
4802 wqe->nsgpg -= mod->free_sgpgs;
4803 mod->free_sgpgs = 0;
4804 }
4805
4806 list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
4807}
4808
4809void
4810bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
4811{
4812 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4813
Jing Huangd4b671c2010-12-26 21:46:35 -08004814 WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004815 list_del(&wqe->qe);
4816
4817 if (wqe->nsgpg_total != wqe->nsgpg)
4818 bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
4819 wqe->nsgpg_total - wqe->nsgpg);
4820}
4821
4822void
4823bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
4824 void *cbarg)
4825{
4826 INIT_LIST_HEAD(&wqe->sgpg_q);
4827 wqe->cbfn = cbfn;
4828 wqe->cbarg = cbarg;
4829}
4830
Jing Huang5fbe25c2010-10-18 17:17:23 -07004831/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004832 * UF related functions
4833 */
4834/*
4835 *****************************************************************************
4836 * Internal functions
4837 *****************************************************************************
4838 */
4839static void
4840__bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
4841{
4842 struct bfa_uf_s *uf = cbarg;
4843 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
4844
4845 if (complete)
4846 ufm->ufrecv(ufm->cbarg, uf);
4847}
4848
4849static void
4850claim_uf_pbs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4851{
4852 u32 uf_pb_tot_sz;
4853
4854 ufm->uf_pbs_kva = (struct bfa_uf_buf_s *) bfa_meminfo_dma_virt(mi);
4855 ufm->uf_pbs_pa = bfa_meminfo_dma_phys(mi);
4856 uf_pb_tot_sz = BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * ufm->num_ufs),
4857 BFA_DMA_ALIGN_SZ);
4858
4859 bfa_meminfo_dma_virt(mi) += uf_pb_tot_sz;
4860 bfa_meminfo_dma_phys(mi) += uf_pb_tot_sz;
4861
Jing Huang6a18b162010-10-18 17:08:54 -07004862 memset((void *)ufm->uf_pbs_kva, 0, uf_pb_tot_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004863}
4864
4865static void
4866claim_uf_post_msgs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4867{
4868 struct bfi_uf_buf_post_s *uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004869 u16 i;
4870 u16 buf_len;
4871
4872 ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_meminfo_kva(mi);
4873 uf_bp_msg = ufm->uf_buf_posts;
4874
4875 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
4876 i++, uf_bp_msg++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004877 memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004878
4879 uf_bp_msg->buf_tag = i;
4880 buf_len = sizeof(struct bfa_uf_buf_s);
Jing Huangba816ea2010-10-18 17:10:50 -07004881 uf_bp_msg->buf_len = cpu_to_be16(buf_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004882 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
4883 bfa_lpuid(ufm->bfa));
Krishna Gudipati85ce9282011-06-13 15:39:36 -07004884 bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004885 }
4886
Jing Huang5fbe25c2010-10-18 17:17:23 -07004887 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004888 * advance pointer beyond consumed memory
4889 */
4890 bfa_meminfo_kva(mi) = (u8 *) uf_bp_msg;
4891}
4892
4893static void
4894claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4895{
4896 u16 i;
4897 struct bfa_uf_s *uf;
4898
4899 /*
4900 * Claim block of memory for UF list
4901 */
4902 ufm->uf_list = (struct bfa_uf_s *) bfa_meminfo_kva(mi);
4903
4904 /*
4905 * Initialize UFs and queue it in UF free queue
4906 */
4907 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004908 memset(uf, 0, sizeof(struct bfa_uf_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004909 uf->bfa = ufm->bfa;
4910 uf->uf_tag = i;
4911 uf->pb_len = sizeof(struct bfa_uf_buf_s);
4912 uf->buf_kva = (void *)&ufm->uf_pbs_kva[i];
4913 uf->buf_pa = ufm_pbs_pa(ufm, i);
4914 list_add_tail(&uf->qe, &ufm->uf_free_q);
4915 }
4916
Jing Huang5fbe25c2010-10-18 17:17:23 -07004917 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004918 * advance memory pointer
4919 */
4920 bfa_meminfo_kva(mi) = (u8 *) uf;
4921}
4922
4923static void
4924uf_mem_claim(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4925{
4926 claim_uf_pbs(ufm, mi);
4927 claim_ufs(ufm, mi);
4928 claim_uf_post_msgs(ufm, mi);
4929}
4930
4931static void
4932bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, u32 *dm_len)
4933{
4934 u32 num_ufs = cfg->fwcfg.num_uf_bufs;
4935
4936 /*
4937 * dma-able memory for UF posted bufs
4938 */
4939 *dm_len += BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * num_ufs),
4940 BFA_DMA_ALIGN_SZ);
4941
4942 /*
4943 * kernel Virtual memory for UFs and UF buf post msg copies
4944 */
4945 *ndm_len += sizeof(struct bfa_uf_s) * num_ufs;
4946 *ndm_len += sizeof(struct bfi_uf_buf_post_s) * num_ufs;
4947}
4948
4949static void
4950bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4951 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
4952{
4953 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
4954
Jing Huang6a18b162010-10-18 17:08:54 -07004955 memset(ufm, 0, sizeof(struct bfa_uf_mod_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004956 ufm->bfa = bfa;
4957 ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
4958 INIT_LIST_HEAD(&ufm->uf_free_q);
4959 INIT_LIST_HEAD(&ufm->uf_posted_q);
4960
4961 uf_mem_claim(ufm, meminfo);
4962}
4963
4964static void
4965bfa_uf_detach(struct bfa_s *bfa)
4966{
4967}
4968
4969static struct bfa_uf_s *
4970bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
4971{
4972 struct bfa_uf_s *uf;
4973
4974 bfa_q_deq(&uf_mod->uf_free_q, &uf);
4975 return uf;
4976}
4977
4978static void
4979bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
4980{
4981 list_add_tail(&uf->qe, &uf_mod->uf_free_q);
4982}
4983
4984static bfa_status_t
4985bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
4986{
4987 struct bfi_uf_buf_post_s *uf_post_msg;
4988
4989 uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
4990 if (!uf_post_msg)
4991 return BFA_STATUS_FAILED;
4992
Jing Huang6a18b162010-10-18 17:08:54 -07004993 memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004994 sizeof(struct bfi_uf_buf_post_s));
4995 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP);
4996
4997 bfa_trc(ufm->bfa, uf->uf_tag);
4998
4999 list_add_tail(&uf->qe, &ufm->uf_posted_q);
5000 return BFA_STATUS_OK;
5001}
5002
5003static void
5004bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
5005{
5006 struct bfa_uf_s *uf;
5007
5008 while ((uf = bfa_uf_get(uf_mod)) != NULL) {
5009 if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
5010 break;
5011 }
5012}
5013
5014static void
5015uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
5016{
5017 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5018 u16 uf_tag = m->buf_tag;
5019 struct bfa_uf_buf_s *uf_buf = &ufm->uf_pbs_kva[uf_tag];
5020 struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
5021 u8 *buf = &uf_buf->d[0];
5022 struct fchs_s *fchs;
5023
Jing Huangba816ea2010-10-18 17:10:50 -07005024 m->frm_len = be16_to_cpu(m->frm_len);
5025 m->xfr_len = be16_to_cpu(m->xfr_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005026
5027 fchs = (struct fchs_s *)uf_buf;
5028
5029 list_del(&uf->qe); /* dequeue from posted queue */
5030
5031 uf->data_ptr = buf;
5032 uf->data_len = m->xfr_len;
5033
Jing Huangd4b671c2010-12-26 21:46:35 -08005034 WARN_ON(uf->data_len < sizeof(struct fchs_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005035
5036 if (uf->data_len == sizeof(struct fchs_s)) {
5037 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
5038 uf->data_len, (struct fchs_s *)buf);
5039 } else {
5040 u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
5041 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
5042 BFA_PL_EID_RX, uf->data_len,
5043 (struct fchs_s *)buf, pld_w0);
5044 }
5045
5046 if (bfa->fcs)
5047 __bfa_cb_uf_recv(uf, BFA_TRUE);
5048 else
5049 bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
5050}
5051
5052static void
5053bfa_uf_stop(struct bfa_s *bfa)
5054{
5055}
5056
5057static void
5058bfa_uf_iocdisable(struct bfa_s *bfa)
5059{
5060 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5061 struct bfa_uf_s *uf;
5062 struct list_head *qe, *qen;
5063
5064 list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
5065 uf = (struct bfa_uf_s *) qe;
5066 list_del(&uf->qe);
5067 bfa_uf_put(ufm, uf);
5068 }
5069}
5070
5071static void
5072bfa_uf_start(struct bfa_s *bfa)
5073{
5074 bfa_uf_post_all(BFA_UF_MOD(bfa));
5075}
5076
Jing Huang5fbe25c2010-10-18 17:17:23 -07005077/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005078 * Register handler for all unsolicted receive frames.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005079 *
5080 * @param[in] bfa BFA instance
5081 * @param[in] ufrecv receive handler function
5082 * @param[in] cbarg receive handler arg
5083 */
5084void
5085bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
5086{
5087 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5088
5089 ufm->ufrecv = ufrecv;
5090 ufm->cbarg = cbarg;
5091}
5092
Jing Huang5fbe25c2010-10-18 17:17:23 -07005093/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005094 * Free an unsolicited frame back to BFA.
5095 *
5096 * @param[in] uf unsolicited frame to be freed
5097 *
5098 * @return None
5099 */
5100void
5101bfa_uf_free(struct bfa_uf_s *uf)
5102{
5103 bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
5104 bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
5105}
5106
5107
5108
Jing Huang5fbe25c2010-10-18 17:17:23 -07005109/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005110 * uf_pub BFA uf module public functions
5111 */
5112void
5113bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5114{
5115 bfa_trc(bfa, msg->mhdr.msg_id);
5116
5117 switch (msg->mhdr.msg_id) {
5118 case BFI_UF_I2H_FRM_RCVD:
5119 uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
5120 break;
5121
5122 default:
5123 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08005124 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005125 }
5126}
5127
5128