blob: d1674c6058ed34ac72baafe2a576af70a5de700e [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:
1260 bfa_sm_set_state(lps, bfa_lps_sm_init);
1261 break;
1262
Krishna Gudipatib7044952010-12-13 16:17:42 -08001263 case BFA_LPS_SM_SET_N2N_PID:
1264 bfa_trc(lps->bfa, lps->fport);
1265 bfa_trc(lps->bfa, lps->lp_pid);
1266 break;
1267
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001268 default:
1269 bfa_sm_fault(lps->bfa, event);
1270 }
1271}
1272
Jing Huang5fbe25c2010-10-18 17:17:23 -07001273/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001274 * login pending - awaiting space in request queue
1275 */
1276static void
1277bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1278{
1279 bfa_trc(lps->bfa, lps->lp_tag);
1280 bfa_trc(lps->bfa, event);
1281
1282 switch (event) {
1283 case BFA_LPS_SM_RESUME:
1284 bfa_sm_set_state(lps, bfa_lps_sm_login);
1285 break;
1286
1287 case BFA_LPS_SM_OFFLINE:
1288 bfa_sm_set_state(lps, bfa_lps_sm_init);
1289 bfa_reqq_wcancel(&lps->wqe);
1290 break;
1291
1292 case BFA_LPS_SM_RX_CVL:
1293 /*
1294 * Login was not even sent out; so when getting out
1295 * of this state, it will appear like a login retry
1296 * after Clear virtual link
1297 */
1298 break;
1299
1300 default:
1301 bfa_sm_fault(lps->bfa, event);
1302 }
1303}
1304
Jing Huang5fbe25c2010-10-18 17:17:23 -07001305/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001306 * login complete
1307 */
1308static void
1309bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
1310{
1311 bfa_trc(lps->bfa, lps->lp_tag);
1312 bfa_trc(lps->bfa, event);
1313
1314 switch (event) {
1315 case BFA_LPS_SM_LOGOUT:
1316 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1317 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1318 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1319 } else {
1320 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1321 bfa_lps_send_logout(lps);
1322 }
1323 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1324 BFA_PL_EID_LOGO, 0, "Logout");
1325 break;
1326
1327 case BFA_LPS_SM_RX_CVL:
1328 bfa_sm_set_state(lps, bfa_lps_sm_init);
1329
1330 /* Let the vport module know about this event */
1331 bfa_lps_cvl_event(lps);
1332 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1333 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1334 break;
1335
Krishna Gudipatib7044952010-12-13 16:17:42 -08001336 case BFA_LPS_SM_SET_N2N_PID:
1337 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1338 bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
1339 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1340 } else
1341 bfa_lps_send_set_n2n_pid(lps);
1342 break;
1343
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001344 case BFA_LPS_SM_OFFLINE:
1345 case BFA_LPS_SM_DELETE:
1346 bfa_sm_set_state(lps, bfa_lps_sm_init);
1347 break;
1348
1349 default:
1350 bfa_sm_fault(lps->bfa, event);
1351 }
1352}
1353
Jing Huang8f4bfad2010-12-26 21:50:10 -08001354/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001355 * login complete
1356 */
1357static void
1358bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1359{
1360 bfa_trc(lps->bfa, lps->lp_tag);
1361 bfa_trc(lps->bfa, event);
1362
1363 switch (event) {
1364 case BFA_LPS_SM_RESUME:
1365 bfa_sm_set_state(lps, bfa_lps_sm_online);
1366 bfa_lps_send_set_n2n_pid(lps);
1367 break;
1368
1369 case BFA_LPS_SM_LOGOUT:
1370 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1371 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1372 BFA_PL_EID_LOGO, 0, "Logout");
1373 break;
1374
1375 case BFA_LPS_SM_RX_CVL:
1376 bfa_sm_set_state(lps, bfa_lps_sm_init);
1377 bfa_reqq_wcancel(&lps->wqe);
1378
1379 /* Let the vport module know about this event */
1380 bfa_lps_cvl_event(lps);
1381 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1382 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1383 break;
1384
1385 case BFA_LPS_SM_OFFLINE:
1386 case BFA_LPS_SM_DELETE:
1387 bfa_sm_set_state(lps, bfa_lps_sm_init);
1388 bfa_reqq_wcancel(&lps->wqe);
1389 break;
1390
1391 default:
1392 bfa_sm_fault(lps->bfa, event);
1393 }
1394}
1395
Jing Huang5fbe25c2010-10-18 17:17:23 -07001396/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001397 * logout in progress - awaiting firmware response
1398 */
1399static void
1400bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
1401{
1402 bfa_trc(lps->bfa, lps->lp_tag);
1403 bfa_trc(lps->bfa, event);
1404
1405 switch (event) {
1406 case BFA_LPS_SM_FWRSP:
1407 bfa_sm_set_state(lps, bfa_lps_sm_init);
1408 bfa_lps_logout_comp(lps);
1409 break;
1410
1411 case BFA_LPS_SM_OFFLINE:
1412 bfa_sm_set_state(lps, bfa_lps_sm_init);
1413 break;
1414
1415 default:
1416 bfa_sm_fault(lps->bfa, event);
1417 }
1418}
1419
Jing Huang5fbe25c2010-10-18 17:17:23 -07001420/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001421 * logout pending -- awaiting space in request queue
1422 */
1423static void
1424bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1425{
1426 bfa_trc(lps->bfa, lps->lp_tag);
1427 bfa_trc(lps->bfa, event);
1428
1429 switch (event) {
1430 case BFA_LPS_SM_RESUME:
1431 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1432 bfa_lps_send_logout(lps);
1433 break;
1434
1435 case BFA_LPS_SM_OFFLINE:
1436 bfa_sm_set_state(lps, bfa_lps_sm_init);
1437 bfa_reqq_wcancel(&lps->wqe);
1438 break;
1439
1440 default:
1441 bfa_sm_fault(lps->bfa, event);
1442 }
1443}
1444
1445
1446
Jing Huang5fbe25c2010-10-18 17:17:23 -07001447/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001448 * lps_pvt BFA LPS private functions
1449 */
1450
Jing Huang5fbe25c2010-10-18 17:17:23 -07001451/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001452 * return memory requirement
1453 */
1454static void
1455bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
1456 u32 *dm_len)
1457{
1458 if (cfg->drvcfg.min_cfg)
1459 *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS;
1460 else
1461 *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS;
1462}
1463
Jing Huang5fbe25c2010-10-18 17:17:23 -07001464/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001465 * bfa module attach at initialization time
1466 */
1467static void
1468bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1469 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
1470{
1471 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1472 struct bfa_lps_s *lps;
1473 int i;
1474
Jing Huang6a18b162010-10-18 17:08:54 -07001475 memset(mod, 0, sizeof(struct bfa_lps_mod_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001476 mod->num_lps = BFA_LPS_MAX_LPORTS;
1477 if (cfg->drvcfg.min_cfg)
1478 mod->num_lps = BFA_LPS_MIN_LPORTS;
1479 else
1480 mod->num_lps = BFA_LPS_MAX_LPORTS;
1481 mod->lps_arr = lps = (struct bfa_lps_s *) bfa_meminfo_kva(meminfo);
1482
1483 bfa_meminfo_kva(meminfo) += mod->num_lps * sizeof(struct bfa_lps_s);
1484
1485 INIT_LIST_HEAD(&mod->lps_free_q);
1486 INIT_LIST_HEAD(&mod->lps_active_q);
1487
1488 for (i = 0; i < mod->num_lps; i++, lps++) {
1489 lps->bfa = bfa;
1490 lps->lp_tag = (u8) i;
1491 lps->reqq = BFA_REQQ_LPS;
1492 bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
1493 list_add_tail(&lps->qe, &mod->lps_free_q);
1494 }
1495}
1496
1497static void
1498bfa_lps_detach(struct bfa_s *bfa)
1499{
1500}
1501
1502static void
1503bfa_lps_start(struct bfa_s *bfa)
1504{
1505}
1506
1507static void
1508bfa_lps_stop(struct bfa_s *bfa)
1509{
1510}
1511
Jing Huang5fbe25c2010-10-18 17:17:23 -07001512/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001513 * IOC in disabled state -- consider all lps offline
1514 */
1515static void
1516bfa_lps_iocdisable(struct bfa_s *bfa)
1517{
1518 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1519 struct bfa_lps_s *lps;
1520 struct list_head *qe, *qen;
1521
1522 list_for_each_safe(qe, qen, &mod->lps_active_q) {
1523 lps = (struct bfa_lps_s *) qe;
1524 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1525 }
1526}
1527
Jing Huang5fbe25c2010-10-18 17:17:23 -07001528/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001529 * Firmware login response
1530 */
1531static void
1532bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
1533{
1534 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1535 struct bfa_lps_s *lps;
1536
Jing Huangd4b671c2010-12-26 21:46:35 -08001537 WARN_ON(rsp->lp_tag >= mod->num_lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001538 lps = BFA_LPS_FROM_TAG(mod, rsp->lp_tag);
1539
1540 lps->status = rsp->status;
1541 switch (rsp->status) {
1542 case BFA_STATUS_OK:
1543 lps->fport = rsp->f_port;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001544 if (lps->fport)
1545 lps->lp_pid = rsp->lp_pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001546 lps->npiv_en = rsp->npiv_en;
Jing Huangba816ea2010-10-18 17:10:50 -07001547 lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001548 lps->pr_pwwn = rsp->port_name;
1549 lps->pr_nwwn = rsp->node_name;
1550 lps->auth_req = rsp->auth_req;
1551 lps->lp_mac = rsp->lp_mac;
1552 lps->brcd_switch = rsp->brcd_switch;
1553 lps->fcf_mac = rsp->fcf_mac;
1554
1555 break;
1556
1557 case BFA_STATUS_FABRIC_RJT:
1558 lps->lsrjt_rsn = rsp->lsrjt_rsn;
1559 lps->lsrjt_expl = rsp->lsrjt_expl;
1560
1561 break;
1562
1563 case BFA_STATUS_EPROTOCOL:
1564 lps->ext_status = rsp->ext_status;
1565
1566 break;
1567
1568 default:
1569 /* Nothing to do with other status */
1570 break;
1571 }
1572
1573 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1574}
1575
Jing Huang5fbe25c2010-10-18 17:17:23 -07001576/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001577 * Firmware logout response
1578 */
1579static void
1580bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
1581{
1582 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1583 struct bfa_lps_s *lps;
1584
Jing Huangd4b671c2010-12-26 21:46:35 -08001585 WARN_ON(rsp->lp_tag >= mod->num_lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001586 lps = BFA_LPS_FROM_TAG(mod, rsp->lp_tag);
1587
1588 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1589}
1590
Jing Huang5fbe25c2010-10-18 17:17:23 -07001591/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001592 * Firmware received a Clear virtual link request (for FCoE)
1593 */
1594static void
1595bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
1596{
1597 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1598 struct bfa_lps_s *lps;
1599
1600 lps = BFA_LPS_FROM_TAG(mod, cvl->lp_tag);
1601
1602 bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
1603}
1604
Jing Huang5fbe25c2010-10-18 17:17:23 -07001605/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001606 * Space is available in request queue, resume queueing request to firmware.
1607 */
1608static void
1609bfa_lps_reqq_resume(void *lps_arg)
1610{
1611 struct bfa_lps_s *lps = lps_arg;
1612
1613 bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
1614}
1615
Jing Huang5fbe25c2010-10-18 17:17:23 -07001616/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001617 * lps is freed -- triggered by vport delete
1618 */
1619static void
1620bfa_lps_free(struct bfa_lps_s *lps)
1621{
1622 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
1623
1624 lps->lp_pid = 0;
1625 list_del(&lps->qe);
1626 list_add_tail(&lps->qe, &mod->lps_free_q);
1627}
1628
Jing Huang5fbe25c2010-10-18 17:17:23 -07001629/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001630 * send login request to firmware
1631 */
1632static void
1633bfa_lps_send_login(struct bfa_lps_s *lps)
1634{
1635 struct bfi_lps_login_req_s *m;
1636
1637 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001638 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001639
1640 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
1641 bfa_lpuid(lps->bfa));
1642
1643 m->lp_tag = lps->lp_tag;
1644 m->alpa = lps->alpa;
Jing Huangba816ea2010-10-18 17:10:50 -07001645 m->pdu_size = cpu_to_be16(lps->pdusz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001646 m->pwwn = lps->pwwn;
1647 m->nwwn = lps->nwwn;
1648 m->fdisc = lps->fdisc;
1649 m->auth_en = lps->auth_en;
1650
1651 bfa_reqq_produce(lps->bfa, lps->reqq);
1652}
1653
Jing Huang5fbe25c2010-10-18 17:17:23 -07001654/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001655 * send logout request to firmware
1656 */
1657static void
1658bfa_lps_send_logout(struct bfa_lps_s *lps)
1659{
1660 struct bfi_lps_logout_req_s *m;
1661
1662 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001663 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001664
1665 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
1666 bfa_lpuid(lps->bfa));
1667
1668 m->lp_tag = lps->lp_tag;
1669 m->port_name = lps->pwwn;
1670 bfa_reqq_produce(lps->bfa, lps->reqq);
1671}
1672
Jing Huang8f4bfad2010-12-26 21:50:10 -08001673/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001674 * send n2n pid set request to firmware
1675 */
1676static void
1677bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
1678{
1679 struct bfi_lps_n2n_pid_req_s *m;
1680
1681 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001682 WARN_ON(!m);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001683
1684 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
1685 bfa_lpuid(lps->bfa));
1686
1687 m->lp_tag = lps->lp_tag;
1688 m->lp_pid = lps->lp_pid;
1689 bfa_reqq_produce(lps->bfa, lps->reqq);
1690}
1691
Jing Huang5fbe25c2010-10-18 17:17:23 -07001692/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001693 * Indirect login completion handler for non-fcs
1694 */
1695static void
1696bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
1697{
1698 struct bfa_lps_s *lps = arg;
1699
1700 if (!complete)
1701 return;
1702
1703 if (lps->fdisc)
1704 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1705 else
1706 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1707}
1708
Jing Huang5fbe25c2010-10-18 17:17:23 -07001709/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001710 * Login completion handler -- direct call for fcs, queue for others
1711 */
1712static void
1713bfa_lps_login_comp(struct bfa_lps_s *lps)
1714{
1715 if (!lps->bfa->fcs) {
1716 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
1717 lps);
1718 return;
1719 }
1720
1721 if (lps->fdisc)
1722 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1723 else
1724 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1725}
1726
Jing Huang5fbe25c2010-10-18 17:17:23 -07001727/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001728 * Indirect logout completion handler for non-fcs
1729 */
1730static void
1731bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
1732{
1733 struct bfa_lps_s *lps = arg;
1734
1735 if (!complete)
1736 return;
1737
1738 if (lps->fdisc)
1739 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1740}
1741
Jing Huang5fbe25c2010-10-18 17:17:23 -07001742/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001743 * Logout completion handler -- direct call for fcs, queue for others
1744 */
1745static void
1746bfa_lps_logout_comp(struct bfa_lps_s *lps)
1747{
1748 if (!lps->bfa->fcs) {
1749 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
1750 lps);
1751 return;
1752 }
1753 if (lps->fdisc)
1754 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1755}
1756
Jing Huang5fbe25c2010-10-18 17:17:23 -07001757/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001758 * Clear virtual link completion handler for non-fcs
1759 */
1760static void
1761bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
1762{
1763 struct bfa_lps_s *lps = arg;
1764
1765 if (!complete)
1766 return;
1767
1768 /* Clear virtual link to base port will result in link down */
1769 if (lps->fdisc)
1770 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1771}
1772
Jing Huang5fbe25c2010-10-18 17:17:23 -07001773/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001774 * Received Clear virtual link event --direct call for fcs,
1775 * queue for others
1776 */
1777static void
1778bfa_lps_cvl_event(struct bfa_lps_s *lps)
1779{
1780 if (!lps->bfa->fcs) {
1781 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
1782 lps);
1783 return;
1784 }
1785
1786 /* Clear virtual link to base port will result in link down */
1787 if (lps->fdisc)
1788 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1789}
1790
1791
1792
Jing Huang5fbe25c2010-10-18 17:17:23 -07001793/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001794 * lps_public BFA LPS public functions
1795 */
1796
1797u32
1798bfa_lps_get_max_vport(struct bfa_s *bfa)
1799{
1800 if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
1801 return BFA_LPS_MAX_VPORTS_SUPP_CT;
1802 else
1803 return BFA_LPS_MAX_VPORTS_SUPP_CB;
1804}
1805
Jing Huang5fbe25c2010-10-18 17:17:23 -07001806/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001807 * Allocate a lport srvice tag.
1808 */
1809struct bfa_lps_s *
1810bfa_lps_alloc(struct bfa_s *bfa)
1811{
1812 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1813 struct bfa_lps_s *lps = NULL;
1814
1815 bfa_q_deq(&mod->lps_free_q, &lps);
1816
1817 if (lps == NULL)
1818 return NULL;
1819
1820 list_add_tail(&lps->qe, &mod->lps_active_q);
1821
1822 bfa_sm_set_state(lps, bfa_lps_sm_init);
1823 return lps;
1824}
1825
Jing Huang5fbe25c2010-10-18 17:17:23 -07001826/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001827 * Free lport service tag. This can be called anytime after an alloc.
1828 * No need to wait for any pending login/logout completions.
1829 */
1830void
1831bfa_lps_delete(struct bfa_lps_s *lps)
1832{
1833 bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
1834}
1835
Jing Huang5fbe25c2010-10-18 17:17:23 -07001836/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001837 * Initiate a lport login.
1838 */
1839void
1840bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
1841 wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en)
1842{
1843 lps->uarg = uarg;
1844 lps->alpa = alpa;
1845 lps->pdusz = pdusz;
1846 lps->pwwn = pwwn;
1847 lps->nwwn = nwwn;
1848 lps->fdisc = BFA_FALSE;
1849 lps->auth_en = auth_en;
1850 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1851}
1852
Jing Huang5fbe25c2010-10-18 17:17:23 -07001853/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001854 * Initiate a lport fdisc login.
1855 */
1856void
1857bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
1858 wwn_t nwwn)
1859{
1860 lps->uarg = uarg;
1861 lps->alpa = 0;
1862 lps->pdusz = pdusz;
1863 lps->pwwn = pwwn;
1864 lps->nwwn = nwwn;
1865 lps->fdisc = BFA_TRUE;
1866 lps->auth_en = BFA_FALSE;
1867 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1868}
1869
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001870
Jing Huang5fbe25c2010-10-18 17:17:23 -07001871/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001872 * Initiate a lport FDSIC logout.
1873 */
1874void
1875bfa_lps_fdisclogo(struct bfa_lps_s *lps)
1876{
1877 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
1878}
1879
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001880
Jing Huang5fbe25c2010-10-18 17:17:23 -07001881/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001882 * Return lport services tag given the pid
1883 */
1884u8
1885bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
1886{
1887 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1888 struct bfa_lps_s *lps;
1889 int i;
1890
1891 for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
1892 if (lps->lp_pid == pid)
1893 return lps->lp_tag;
1894 }
1895
1896 /* Return base port tag anyway */
1897 return 0;
1898}
1899
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001900
Jing Huang5fbe25c2010-10-18 17:17:23 -07001901/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001902 * return port id assigned to the base lport
1903 */
1904u32
1905bfa_lps_get_base_pid(struct bfa_s *bfa)
1906{
1907 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1908
1909 return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
1910}
1911
Jing Huang8f4bfad2010-12-26 21:50:10 -08001912/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001913 * Set PID in case of n2n (which is assigned during PLOGI)
1914 */
1915void
1916bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
1917{
1918 bfa_trc(lps->bfa, lps->lp_tag);
1919 bfa_trc(lps->bfa, n2n_pid);
1920
1921 lps->lp_pid = n2n_pid;
1922 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
1923}
1924
Jing Huang5fbe25c2010-10-18 17:17:23 -07001925/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001926 * LPS firmware message class handler.
1927 */
1928void
1929bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
1930{
1931 union bfi_lps_i2h_msg_u msg;
1932
1933 bfa_trc(bfa, m->mhdr.msg_id);
1934 msg.msg = m;
1935
1936 switch (m->mhdr.msg_id) {
1937 case BFI_LPS_H2I_LOGIN_RSP:
1938 bfa_lps_login_rsp(bfa, msg.login_rsp);
1939 break;
1940
1941 case BFI_LPS_H2I_LOGOUT_RSP:
1942 bfa_lps_logout_rsp(bfa, msg.logout_rsp);
1943 break;
1944
1945 case BFI_LPS_H2I_CVL_EVENT:
1946 bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
1947 break;
1948
1949 default:
1950 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001951 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001952 }
1953}
1954
Jing Huang5fbe25c2010-10-18 17:17:23 -07001955/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001956 * FC PORT state machine functions
1957 */
1958static void
1959bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
1960 enum bfa_fcport_sm_event event)
1961{
1962 bfa_trc(fcport->bfa, event);
1963
1964 switch (event) {
1965 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001966 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001967 * Start event after IOC is configured and BFA is started.
1968 */
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08001969 fcport->use_flash_cfg = BFA_TRUE;
1970
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001971 if (bfa_fcport_send_enable(fcport)) {
1972 bfa_trc(fcport->bfa, BFA_TRUE);
1973 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
1974 } else {
1975 bfa_trc(fcport->bfa, BFA_FALSE);
1976 bfa_sm_set_state(fcport,
1977 bfa_fcport_sm_enabling_qwait);
1978 }
1979 break;
1980
1981 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001982 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001983 * Port is persistently configured to be in enabled state. Do
1984 * not change state. Port enabling is done when START event is
1985 * received.
1986 */
1987 break;
1988
1989 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001990 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001991 * If a port is persistently configured to be disabled, the
1992 * first event will a port disable request.
1993 */
1994 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
1995 break;
1996
1997 case BFA_FCPORT_SM_HWFAIL:
1998 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
1999 break;
2000
2001 default:
2002 bfa_sm_fault(fcport->bfa, event);
2003 }
2004}
2005
2006static void
2007bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
2008 enum bfa_fcport_sm_event event)
2009{
2010 char pwwn_buf[BFA_STRING_32];
2011 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2012 bfa_trc(fcport->bfa, event);
2013
2014 switch (event) {
2015 case BFA_FCPORT_SM_QRESUME:
2016 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2017 bfa_fcport_send_enable(fcport);
2018 break;
2019
2020 case BFA_FCPORT_SM_STOP:
2021 bfa_reqq_wcancel(&fcport->reqq_wait);
2022 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2023 break;
2024
2025 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002026 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002027 * Already enable is in progress.
2028 */
2029 break;
2030
2031 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002032 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002033 * Just send disable request to firmware when room becomes
2034 * available in request queue.
2035 */
2036 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2037 bfa_reqq_wcancel(&fcport->reqq_wait);
2038 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2039 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2040 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002041 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002042 "Base port disabled: WWN = %s\n", pwwn_buf);
2043 break;
2044
2045 case BFA_FCPORT_SM_LINKUP:
2046 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002047 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002048 * Possible to get link events when doing back-to-back
2049 * enable/disables.
2050 */
2051 break;
2052
2053 case BFA_FCPORT_SM_HWFAIL:
2054 bfa_reqq_wcancel(&fcport->reqq_wait);
2055 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2056 break;
2057
2058 default:
2059 bfa_sm_fault(fcport->bfa, event);
2060 }
2061}
2062
2063static void
2064bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
2065 enum bfa_fcport_sm_event event)
2066{
2067 char pwwn_buf[BFA_STRING_32];
2068 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2069 bfa_trc(fcport->bfa, event);
2070
2071 switch (event) {
2072 case BFA_FCPORT_SM_FWRSP:
2073 case BFA_FCPORT_SM_LINKDOWN:
2074 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2075 break;
2076
2077 case BFA_FCPORT_SM_LINKUP:
2078 bfa_fcport_update_linkinfo(fcport);
2079 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
2080
Jing Huangd4b671c2010-12-26 21:46:35 -08002081 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002082 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2083 break;
2084
2085 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002086 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002087 * Already being enabled.
2088 */
2089 break;
2090
2091 case BFA_FCPORT_SM_DISABLE:
2092 if (bfa_fcport_send_disable(fcport))
2093 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2094 else
2095 bfa_sm_set_state(fcport,
2096 bfa_fcport_sm_disabling_qwait);
2097
2098 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2099 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2100 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002101 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002102 "Base port disabled: WWN = %s\n", pwwn_buf);
2103 break;
2104
2105 case BFA_FCPORT_SM_STOP:
2106 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2107 break;
2108
2109 case BFA_FCPORT_SM_HWFAIL:
2110 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2111 break;
2112
2113 default:
2114 bfa_sm_fault(fcport->bfa, event);
2115 }
2116}
2117
2118static void
2119bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
2120 enum bfa_fcport_sm_event event)
2121{
2122 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2123 char pwwn_buf[BFA_STRING_32];
2124 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2125
2126 bfa_trc(fcport->bfa, event);
2127
2128 switch (event) {
2129 case BFA_FCPORT_SM_LINKUP:
2130 bfa_fcport_update_linkinfo(fcport);
2131 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
Jing Huangd4b671c2010-12-26 21:46:35 -08002132 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002133 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2134 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
2135 if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
2136
2137 bfa_trc(fcport->bfa,
2138 pevent->link_state.vc_fcf.fcf.fipenabled);
2139 bfa_trc(fcport->bfa,
2140 pevent->link_state.vc_fcf.fcf.fipfailed);
2141
2142 if (pevent->link_state.vc_fcf.fcf.fipfailed)
2143 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2144 BFA_PL_EID_FIP_FCF_DISC, 0,
2145 "FIP FCF Discovery Failed");
2146 else
2147 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2148 BFA_PL_EID_FIP_FCF_DISC, 0,
2149 "FIP FCF Discovered");
2150 }
2151
2152 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2153 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002154 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002155 "Base port online: WWN = %s\n", pwwn_buf);
2156 break;
2157
2158 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002159 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002160 * Possible to get link down event.
2161 */
2162 break;
2163
2164 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002165 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002166 * Already enabled.
2167 */
2168 break;
2169
2170 case BFA_FCPORT_SM_DISABLE:
2171 if (bfa_fcport_send_disable(fcport))
2172 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2173 else
2174 bfa_sm_set_state(fcport,
2175 bfa_fcport_sm_disabling_qwait);
2176
2177 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2178 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2179 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002180 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002181 "Base port disabled: WWN = %s\n", pwwn_buf);
2182 break;
2183
2184 case BFA_FCPORT_SM_STOP:
2185 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2186 break;
2187
2188 case BFA_FCPORT_SM_HWFAIL:
2189 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2190 break;
2191
2192 default:
2193 bfa_sm_fault(fcport->bfa, event);
2194 }
2195}
2196
2197static void
2198bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
2199 enum bfa_fcport_sm_event event)
2200{
2201 char pwwn_buf[BFA_STRING_32];
2202 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2203
2204 bfa_trc(fcport->bfa, event);
2205
2206 switch (event) {
2207 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002208 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002209 * Already enabled.
2210 */
2211 break;
2212
2213 case BFA_FCPORT_SM_DISABLE:
2214 if (bfa_fcport_send_disable(fcport))
2215 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2216 else
2217 bfa_sm_set_state(fcport,
2218 bfa_fcport_sm_disabling_qwait);
2219
2220 bfa_fcport_reset_linkinfo(fcport);
2221 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2222 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2223 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2224 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002225 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002226 "Base port offline: WWN = %s\n", pwwn_buf);
Jing Huang88166242010-12-09 17:11:53 -08002227 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002228 "Base port disabled: WWN = %s\n", pwwn_buf);
2229 break;
2230
2231 case BFA_FCPORT_SM_LINKDOWN:
2232 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2233 bfa_fcport_reset_linkinfo(fcport);
2234 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2235 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2236 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
2237 wwn2str(pwwn_buf, fcport->pwwn);
2238 if (BFA_PORT_IS_DISABLED(fcport->bfa))
Jing Huang88166242010-12-09 17:11:53 -08002239 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002240 "Base port offline: WWN = %s\n", pwwn_buf);
2241 else
Jing Huang88166242010-12-09 17:11:53 -08002242 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002243 "Base port (WWN = %s) "
2244 "lost fabric connectivity\n", pwwn_buf);
2245 break;
2246
2247 case BFA_FCPORT_SM_STOP:
2248 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2249 bfa_fcport_reset_linkinfo(fcport);
2250 wwn2str(pwwn_buf, fcport->pwwn);
2251 if (BFA_PORT_IS_DISABLED(fcport->bfa))
Jing Huang88166242010-12-09 17:11:53 -08002252 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002253 "Base port offline: WWN = %s\n", pwwn_buf);
2254 else
Jing Huang88166242010-12-09 17:11:53 -08002255 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002256 "Base port (WWN = %s) "
2257 "lost fabric connectivity\n", pwwn_buf);
2258 break;
2259
2260 case BFA_FCPORT_SM_HWFAIL:
2261 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2262 bfa_fcport_reset_linkinfo(fcport);
2263 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2264 wwn2str(pwwn_buf, fcport->pwwn);
2265 if (BFA_PORT_IS_DISABLED(fcport->bfa))
Jing Huang88166242010-12-09 17:11:53 -08002266 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002267 "Base port offline: WWN = %s\n", pwwn_buf);
2268 else
Jing Huang88166242010-12-09 17:11:53 -08002269 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002270 "Base port (WWN = %s) "
2271 "lost fabric connectivity\n", pwwn_buf);
2272 break;
2273
2274 default:
2275 bfa_sm_fault(fcport->bfa, event);
2276 }
2277}
2278
2279static void
2280bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
2281 enum bfa_fcport_sm_event event)
2282{
2283 bfa_trc(fcport->bfa, event);
2284
2285 switch (event) {
2286 case BFA_FCPORT_SM_QRESUME:
2287 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2288 bfa_fcport_send_disable(fcport);
2289 break;
2290
2291 case BFA_FCPORT_SM_STOP:
2292 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2293 bfa_reqq_wcancel(&fcport->reqq_wait);
2294 break;
2295
2296 case BFA_FCPORT_SM_ENABLE:
2297 bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
2298 break;
2299
2300 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002301 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002302 * Already being disabled.
2303 */
2304 break;
2305
2306 case BFA_FCPORT_SM_LINKUP:
2307 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002308 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002309 * Possible to get link events when doing back-to-back
2310 * enable/disables.
2311 */
2312 break;
2313
2314 case BFA_FCPORT_SM_HWFAIL:
2315 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2316 bfa_reqq_wcancel(&fcport->reqq_wait);
2317 break;
2318
2319 default:
2320 bfa_sm_fault(fcport->bfa, event);
2321 }
2322}
2323
2324static void
2325bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
2326 enum bfa_fcport_sm_event event)
2327{
2328 bfa_trc(fcport->bfa, event);
2329
2330 switch (event) {
2331 case BFA_FCPORT_SM_QRESUME:
2332 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2333 bfa_fcport_send_disable(fcport);
2334 if (bfa_fcport_send_enable(fcport))
2335 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2336 else
2337 bfa_sm_set_state(fcport,
2338 bfa_fcport_sm_enabling_qwait);
2339 break;
2340
2341 case BFA_FCPORT_SM_STOP:
2342 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2343 bfa_reqq_wcancel(&fcport->reqq_wait);
2344 break;
2345
2346 case BFA_FCPORT_SM_ENABLE:
2347 break;
2348
2349 case BFA_FCPORT_SM_DISABLE:
2350 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
2351 break;
2352
2353 case BFA_FCPORT_SM_LINKUP:
2354 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002355 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002356 * Possible to get link events when doing back-to-back
2357 * enable/disables.
2358 */
2359 break;
2360
2361 case BFA_FCPORT_SM_HWFAIL:
2362 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2363 bfa_reqq_wcancel(&fcport->reqq_wait);
2364 break;
2365
2366 default:
2367 bfa_sm_fault(fcport->bfa, event);
2368 }
2369}
2370
2371static void
2372bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
2373 enum bfa_fcport_sm_event event)
2374{
2375 char pwwn_buf[BFA_STRING_32];
2376 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2377 bfa_trc(fcport->bfa, event);
2378
2379 switch (event) {
2380 case BFA_FCPORT_SM_FWRSP:
2381 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2382 break;
2383
2384 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002385 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002386 * Already being disabled.
2387 */
2388 break;
2389
2390 case BFA_FCPORT_SM_ENABLE:
2391 if (bfa_fcport_send_enable(fcport))
2392 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2393 else
2394 bfa_sm_set_state(fcport,
2395 bfa_fcport_sm_enabling_qwait);
2396
2397 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2398 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2399 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002400 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002401 "Base port enabled: WWN = %s\n", pwwn_buf);
2402 break;
2403
2404 case BFA_FCPORT_SM_STOP:
2405 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2406 break;
2407
2408 case BFA_FCPORT_SM_LINKUP:
2409 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002410 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002411 * Possible to get link events when doing back-to-back
2412 * enable/disables.
2413 */
2414 break;
2415
2416 case BFA_FCPORT_SM_HWFAIL:
2417 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2418 break;
2419
2420 default:
2421 bfa_sm_fault(fcport->bfa, event);
2422 }
2423}
2424
2425static void
2426bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
2427 enum bfa_fcport_sm_event event)
2428{
2429 char pwwn_buf[BFA_STRING_32];
2430 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2431 bfa_trc(fcport->bfa, event);
2432
2433 switch (event) {
2434 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002435 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002436 * Ignore start event for a port that is disabled.
2437 */
2438 break;
2439
2440 case BFA_FCPORT_SM_STOP:
2441 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2442 break;
2443
2444 case BFA_FCPORT_SM_ENABLE:
2445 if (bfa_fcport_send_enable(fcport))
2446 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2447 else
2448 bfa_sm_set_state(fcport,
2449 bfa_fcport_sm_enabling_qwait);
2450
2451 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2452 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2453 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002454 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002455 "Base port enabled: WWN = %s\n", pwwn_buf);
2456 break;
2457
2458 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002459 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002460 * Already disabled.
2461 */
2462 break;
2463
2464 case BFA_FCPORT_SM_HWFAIL:
2465 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2466 break;
2467
2468 default:
2469 bfa_sm_fault(fcport->bfa, event);
2470 }
2471}
2472
2473static void
2474bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
2475 enum bfa_fcport_sm_event event)
2476{
2477 bfa_trc(fcport->bfa, event);
2478
2479 switch (event) {
2480 case BFA_FCPORT_SM_START:
2481 if (bfa_fcport_send_enable(fcport))
2482 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2483 else
2484 bfa_sm_set_state(fcport,
2485 bfa_fcport_sm_enabling_qwait);
2486 break;
2487
2488 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002489 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002490 * Ignore all other events.
2491 */
2492 ;
2493 }
2494}
2495
Jing Huang5fbe25c2010-10-18 17:17:23 -07002496/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002497 * Port is enabled. IOC is down/failed.
2498 */
2499static void
2500bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
2501 enum bfa_fcport_sm_event event)
2502{
2503 bfa_trc(fcport->bfa, event);
2504
2505 switch (event) {
2506 case BFA_FCPORT_SM_START:
2507 if (bfa_fcport_send_enable(fcport))
2508 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2509 else
2510 bfa_sm_set_state(fcport,
2511 bfa_fcport_sm_enabling_qwait);
2512 break;
2513
2514 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002515 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002516 * Ignore all events.
2517 */
2518 ;
2519 }
2520}
2521
Jing Huang5fbe25c2010-10-18 17:17:23 -07002522/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002523 * Port is disabled. IOC is down/failed.
2524 */
2525static void
2526bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
2527 enum bfa_fcport_sm_event event)
2528{
2529 bfa_trc(fcport->bfa, event);
2530
2531 switch (event) {
2532 case BFA_FCPORT_SM_START:
2533 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2534 break;
2535
2536 case BFA_FCPORT_SM_ENABLE:
2537 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2538 break;
2539
2540 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002541 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002542 * Ignore all events.
2543 */
2544 ;
2545 }
2546}
2547
Jing Huang5fbe25c2010-10-18 17:17:23 -07002548/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002549 * Link state is down
2550 */
2551static void
2552bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
2553 enum bfa_fcport_ln_sm_event event)
2554{
2555 bfa_trc(ln->fcport->bfa, event);
2556
2557 switch (event) {
2558 case BFA_FCPORT_LN_SM_LINKUP:
2559 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2560 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2561 break;
2562
2563 default:
2564 bfa_sm_fault(ln->fcport->bfa, event);
2565 }
2566}
2567
Jing Huang5fbe25c2010-10-18 17:17:23 -07002568/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002569 * Link state is waiting for down notification
2570 */
2571static void
2572bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
2573 enum bfa_fcport_ln_sm_event event)
2574{
2575 bfa_trc(ln->fcport->bfa, event);
2576
2577 switch (event) {
2578 case BFA_FCPORT_LN_SM_LINKUP:
2579 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2580 break;
2581
2582 case BFA_FCPORT_LN_SM_NOTIFICATION:
2583 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2584 break;
2585
2586 default:
2587 bfa_sm_fault(ln->fcport->bfa, event);
2588 }
2589}
2590
Jing Huang5fbe25c2010-10-18 17:17:23 -07002591/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002592 * Link state is waiting for down notification and there is a pending up
2593 */
2594static void
2595bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
2596 enum bfa_fcport_ln_sm_event event)
2597{
2598 bfa_trc(ln->fcport->bfa, event);
2599
2600 switch (event) {
2601 case BFA_FCPORT_LN_SM_LINKDOWN:
2602 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2603 break;
2604
2605 case BFA_FCPORT_LN_SM_NOTIFICATION:
2606 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2607 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2608 break;
2609
2610 default:
2611 bfa_sm_fault(ln->fcport->bfa, event);
2612 }
2613}
2614
Jing Huang5fbe25c2010-10-18 17:17:23 -07002615/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002616 * Link state is up
2617 */
2618static void
2619bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
2620 enum bfa_fcport_ln_sm_event event)
2621{
2622 bfa_trc(ln->fcport->bfa, event);
2623
2624 switch (event) {
2625 case BFA_FCPORT_LN_SM_LINKDOWN:
2626 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2627 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2628 break;
2629
2630 default:
2631 bfa_sm_fault(ln->fcport->bfa, event);
2632 }
2633}
2634
Jing Huang5fbe25c2010-10-18 17:17:23 -07002635/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002636 * Link state is waiting for up notification
2637 */
2638static void
2639bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
2640 enum bfa_fcport_ln_sm_event event)
2641{
2642 bfa_trc(ln->fcport->bfa, event);
2643
2644 switch (event) {
2645 case BFA_FCPORT_LN_SM_LINKDOWN:
2646 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2647 break;
2648
2649 case BFA_FCPORT_LN_SM_NOTIFICATION:
2650 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
2651 break;
2652
2653 default:
2654 bfa_sm_fault(ln->fcport->bfa, event);
2655 }
2656}
2657
Jing Huang5fbe25c2010-10-18 17:17:23 -07002658/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002659 * Link state is waiting for up notification and there is a pending down
2660 */
2661static void
2662bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
2663 enum bfa_fcport_ln_sm_event event)
2664{
2665 bfa_trc(ln->fcport->bfa, event);
2666
2667 switch (event) {
2668 case BFA_FCPORT_LN_SM_LINKUP:
2669 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
2670 break;
2671
2672 case BFA_FCPORT_LN_SM_NOTIFICATION:
2673 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2674 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2675 break;
2676
2677 default:
2678 bfa_sm_fault(ln->fcport->bfa, event);
2679 }
2680}
2681
Jing Huang5fbe25c2010-10-18 17:17:23 -07002682/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002683 * Link state is waiting for up notification and there are pending down and up
2684 */
2685static void
2686bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
2687 enum bfa_fcport_ln_sm_event event)
2688{
2689 bfa_trc(ln->fcport->bfa, event);
2690
2691 switch (event) {
2692 case BFA_FCPORT_LN_SM_LINKDOWN:
2693 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2694 break;
2695
2696 case BFA_FCPORT_LN_SM_NOTIFICATION:
2697 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2698 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2699 break;
2700
2701 default:
2702 bfa_sm_fault(ln->fcport->bfa, event);
2703 }
2704}
2705
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002706static void
2707__bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
2708{
2709 struct bfa_fcport_ln_s *ln = cbarg;
2710
2711 if (complete)
2712 ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
2713 else
2714 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2715}
2716
Jing Huang5fbe25c2010-10-18 17:17:23 -07002717/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002718 * Send SCN notification to upper layers.
2719 * trunk - false if caller is fcport to ignore fcport event in trunked mode
2720 */
2721static void
2722bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
2723 bfa_boolean_t trunk)
2724{
2725 if (fcport->cfg.trunked && !trunk)
2726 return;
2727
2728 switch (event) {
2729 case BFA_PORT_LINKUP:
2730 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
2731 break;
2732 case BFA_PORT_LINKDOWN:
2733 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
2734 break;
2735 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08002736 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002737 }
2738}
2739
2740static void
2741bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
2742{
2743 struct bfa_fcport_s *fcport = ln->fcport;
2744
2745 if (fcport->bfa->fcs) {
2746 fcport->event_cbfn(fcport->event_cbarg, event);
2747 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2748 } else {
2749 ln->ln_event = event;
2750 bfa_cb_queue(fcport->bfa, &ln->ln_qe,
2751 __bfa_cb_fcport_event, ln);
2752 }
2753}
2754
2755#define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
2756 BFA_CACHELINE_SZ))
2757
2758static void
2759bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
2760 u32 *dm_len)
2761{
2762 *dm_len += FCPORT_STATS_DMA_SZ;
2763}
2764
2765static void
2766bfa_fcport_qresume(void *cbarg)
2767{
2768 struct bfa_fcport_s *fcport = cbarg;
2769
2770 bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
2771}
2772
2773static void
2774bfa_fcport_mem_claim(struct bfa_fcport_s *fcport, struct bfa_meminfo_s *meminfo)
2775{
2776 u8 *dm_kva;
2777 u64 dm_pa;
2778
2779 dm_kva = bfa_meminfo_dma_virt(meminfo);
2780 dm_pa = bfa_meminfo_dma_phys(meminfo);
2781
2782 fcport->stats_kva = dm_kva;
2783 fcport->stats_pa = dm_pa;
2784 fcport->stats = (union bfa_fcport_stats_u *) dm_kva;
2785
2786 dm_kva += FCPORT_STATS_DMA_SZ;
2787 dm_pa += FCPORT_STATS_DMA_SZ;
2788
2789 bfa_meminfo_dma_virt(meminfo) = dm_kva;
2790 bfa_meminfo_dma_phys(meminfo) = dm_pa;
2791}
2792
Jing Huang5fbe25c2010-10-18 17:17:23 -07002793/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002794 * Memory initialization.
2795 */
2796static void
2797bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
2798 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
2799{
2800 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2801 struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
2802 struct bfa_fcport_ln_s *ln = &fcport->ln;
Maggie Zhangf16a1752010-12-09 19:12:32 -08002803 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002804
Jing Huang6a18b162010-10-18 17:08:54 -07002805 memset(fcport, 0, sizeof(struct bfa_fcport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002806 fcport->bfa = bfa;
2807 ln->fcport = fcport;
2808
2809 bfa_fcport_mem_claim(fcport, meminfo);
2810
2811 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
2812 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2813
Jing Huang5fbe25c2010-10-18 17:17:23 -07002814 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002815 * initialize time stamp for stats reset
2816 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08002817 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002818 fcport->stats_reset_time = tv.tv_sec;
2819
Jing Huang5fbe25c2010-10-18 17:17:23 -07002820 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002821 * initialize and set default configuration
2822 */
2823 port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
2824 port_cfg->speed = BFA_PORT_SPEED_AUTO;
2825 port_cfg->trunked = BFA_FALSE;
2826 port_cfg->maxfrsize = 0;
2827
2828 port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
2829
2830 bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
2831}
2832
2833static void
2834bfa_fcport_detach(struct bfa_s *bfa)
2835{
2836}
2837
Jing Huang5fbe25c2010-10-18 17:17:23 -07002838/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002839 * Called when IOC is ready.
2840 */
2841static void
2842bfa_fcport_start(struct bfa_s *bfa)
2843{
2844 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
2845}
2846
Jing Huang5fbe25c2010-10-18 17:17:23 -07002847/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002848 * Called before IOC is stopped.
2849 */
2850static void
2851bfa_fcport_stop(struct bfa_s *bfa)
2852{
2853 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
2854 bfa_trunk_iocdisable(bfa);
2855}
2856
Jing Huang5fbe25c2010-10-18 17:17:23 -07002857/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002858 * Called when IOC failure is detected.
2859 */
2860static void
2861bfa_fcport_iocdisable(struct bfa_s *bfa)
2862{
2863 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2864
2865 bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
2866 bfa_trunk_iocdisable(bfa);
2867}
2868
2869static void
2870bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
2871{
2872 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2873 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
2874
2875 fcport->speed = pevent->link_state.speed;
2876 fcport->topology = pevent->link_state.topology;
2877
2878 if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)
2879 fcport->myalpa = 0;
2880
2881 /* QoS Details */
Jing Huang6a18b162010-10-18 17:08:54 -07002882 fcport->qos_attr = pevent->link_state.qos_attr;
2883 fcport->qos_vc_attr = pevent->link_state.vc_fcf.qos_vc_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002884
Jing Huang5fbe25c2010-10-18 17:17:23 -07002885 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002886 * update trunk state if applicable
2887 */
2888 if (!fcport->cfg.trunked)
2889 trunk->attr.state = BFA_TRUNK_DISABLED;
2890
2891 /* update FCoE specific */
Jing Huangba816ea2010-10-18 17:10:50 -07002892 fcport->fcoe_vlan = be16_to_cpu(pevent->link_state.vc_fcf.fcf.vlan);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002893
2894 bfa_trc(fcport->bfa, fcport->speed);
2895 bfa_trc(fcport->bfa, fcport->topology);
2896}
2897
2898static void
2899bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
2900{
2901 fcport->speed = BFA_PORT_SPEED_UNKNOWN;
2902 fcport->topology = BFA_PORT_TOPOLOGY_NONE;
2903}
2904
Jing Huang5fbe25c2010-10-18 17:17:23 -07002905/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002906 * Send port enable message to firmware.
2907 */
2908static bfa_boolean_t
2909bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
2910{
2911 struct bfi_fcport_enable_req_s *m;
2912
Jing Huang5fbe25c2010-10-18 17:17:23 -07002913 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002914 * Increment message tag before queue check, so that responses to old
2915 * requests are discarded.
2916 */
2917 fcport->msgtag++;
2918
Jing Huang5fbe25c2010-10-18 17:17:23 -07002919 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002920 * check for room in queue to send request now
2921 */
2922 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
2923 if (!m) {
2924 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
2925 &fcport->reqq_wait);
2926 return BFA_FALSE;
2927 }
2928
2929 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
2930 bfa_lpuid(fcport->bfa));
2931 m->nwwn = fcport->nwwn;
2932 m->pwwn = fcport->pwwn;
2933 m->port_cfg = fcport->cfg;
2934 m->msgtag = fcport->msgtag;
Jing Huangba816ea2010-10-18 17:10:50 -07002935 m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08002936 m->use_flash_cfg = fcport->use_flash_cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002937 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
2938 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
2939 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
2940
Jing Huang5fbe25c2010-10-18 17:17:23 -07002941 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002942 * queue I/O message to firmware
2943 */
2944 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
2945 return BFA_TRUE;
2946}
2947
Jing Huang5fbe25c2010-10-18 17:17:23 -07002948/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002949 * Send port disable message to firmware.
2950 */
2951static bfa_boolean_t
2952bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
2953{
2954 struct bfi_fcport_req_s *m;
2955
Jing Huang5fbe25c2010-10-18 17:17:23 -07002956 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002957 * Increment message tag before queue check, so that responses to old
2958 * requests are discarded.
2959 */
2960 fcport->msgtag++;
2961
Jing Huang5fbe25c2010-10-18 17:17:23 -07002962 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002963 * check for room in queue to send request now
2964 */
2965 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
2966 if (!m) {
2967 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
2968 &fcport->reqq_wait);
2969 return BFA_FALSE;
2970 }
2971
2972 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
2973 bfa_lpuid(fcport->bfa));
2974 m->msgtag = fcport->msgtag;
2975
Jing Huang5fbe25c2010-10-18 17:17:23 -07002976 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002977 * queue I/O message to firmware
2978 */
2979 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
2980
2981 return BFA_TRUE;
2982}
2983
2984static void
2985bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
2986{
Maggie Zhangf7f738122010-12-09 19:08:43 -08002987 fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
2988 fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002989
2990 bfa_trc(fcport->bfa, fcport->pwwn);
2991 bfa_trc(fcport->bfa, fcport->nwwn);
2992}
2993
2994static void
2995bfa_fcport_send_txcredit(void *port_cbarg)
2996{
2997
2998 struct bfa_fcport_s *fcport = port_cbarg;
2999 struct bfi_fcport_set_svc_params_req_s *m;
3000
Jing Huang5fbe25c2010-10-18 17:17:23 -07003001 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003002 * check for room in queue to send request now
3003 */
3004 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3005 if (!m) {
3006 bfa_trc(fcport->bfa, fcport->cfg.tx_bbcredit);
3007 return;
3008 }
3009
3010 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ,
3011 bfa_lpuid(fcport->bfa));
Jing Huangba816ea2010-10-18 17:10:50 -07003012 m->tx_bbcredit = cpu_to_be16((u16)fcport->cfg.tx_bbcredit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003013
Jing Huang5fbe25c2010-10-18 17:17:23 -07003014 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003015 * queue I/O message to firmware
3016 */
3017 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
3018}
3019
3020static void
3021bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
3022 struct bfa_qos_stats_s *s)
3023{
3024 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003025 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003026 int i;
3027
3028 /* Now swap the 32 bit fields */
3029 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
Jing Huangba816ea2010-10-18 17:10:50 -07003030 dip[i] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003031}
3032
3033static void
3034bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
3035 struct bfa_fcoe_stats_s *s)
3036{
3037 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003038 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003039 int i;
3040
3041 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
3042 i = i + 2) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003043#ifdef __BIG_ENDIAN
Jing Huangba816ea2010-10-18 17:10:50 -07003044 dip[i] = be32_to_cpu(sip[i]);
3045 dip[i + 1] = be32_to_cpu(sip[i + 1]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003046#else
Jing Huangba816ea2010-10-18 17:10:50 -07003047 dip[i] = be32_to_cpu(sip[i + 1]);
3048 dip[i + 1] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003049#endif
3050 }
3051}
3052
3053static void
3054__bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
3055{
3056 struct bfa_fcport_s *fcport = cbarg;
3057
3058 if (complete) {
3059 if (fcport->stats_status == BFA_STATUS_OK) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003060 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003061
3062 /* Swap FC QoS or FCoE stats */
3063 if (bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
3064 bfa_fcport_qos_stats_swap(
3065 &fcport->stats_ret->fcqos,
3066 &fcport->stats->fcqos);
3067 } else {
3068 bfa_fcport_fcoe_stats_swap(
3069 &fcport->stats_ret->fcoe,
3070 &fcport->stats->fcoe);
3071
Maggie Zhangf16a1752010-12-09 19:12:32 -08003072 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003073 fcport->stats_ret->fcoe.secs_reset =
3074 tv.tv_sec - fcport->stats_reset_time;
3075 }
3076 }
3077 fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
3078 } else {
3079 fcport->stats_busy = BFA_FALSE;
3080 fcport->stats_status = BFA_STATUS_OK;
3081 }
3082}
3083
3084static void
3085bfa_fcport_stats_get_timeout(void *cbarg)
3086{
3087 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3088
3089 bfa_trc(fcport->bfa, fcport->stats_qfull);
3090
3091 if (fcport->stats_qfull) {
3092 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3093 fcport->stats_qfull = BFA_FALSE;
3094 }
3095
3096 fcport->stats_status = BFA_STATUS_ETIMER;
3097 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, __bfa_cb_fcport_stats_get,
3098 fcport);
3099}
3100
3101static void
3102bfa_fcport_send_stats_get(void *cbarg)
3103{
3104 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3105 struct bfi_fcport_req_s *msg;
3106
3107 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3108
3109 if (!msg) {
3110 fcport->stats_qfull = BFA_TRUE;
3111 bfa_reqq_winit(&fcport->stats_reqq_wait,
3112 bfa_fcport_send_stats_get, fcport);
3113 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3114 &fcport->stats_reqq_wait);
3115 return;
3116 }
3117 fcport->stats_qfull = BFA_FALSE;
3118
Jing Huang6a18b162010-10-18 17:08:54 -07003119 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003120 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
3121 bfa_lpuid(fcport->bfa));
3122 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
3123}
3124
3125static void
3126__bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
3127{
3128 struct bfa_fcport_s *fcport = cbarg;
3129
3130 if (complete) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003131 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003132
Jing Huang5fbe25c2010-10-18 17:17:23 -07003133 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003134 * re-initialize time stamp for stats reset
3135 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08003136 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003137 fcport->stats_reset_time = tv.tv_sec;
3138
3139 fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
3140 } else {
3141 fcport->stats_busy = BFA_FALSE;
3142 fcport->stats_status = BFA_STATUS_OK;
3143 }
3144}
3145
3146static void
3147bfa_fcport_stats_clr_timeout(void *cbarg)
3148{
3149 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3150
3151 bfa_trc(fcport->bfa, fcport->stats_qfull);
3152
3153 if (fcport->stats_qfull) {
3154 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3155 fcport->stats_qfull = BFA_FALSE;
3156 }
3157
3158 fcport->stats_status = BFA_STATUS_ETIMER;
3159 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3160 __bfa_cb_fcport_stats_clr, fcport);
3161}
3162
3163static void
3164bfa_fcport_send_stats_clear(void *cbarg)
3165{
3166 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3167 struct bfi_fcport_req_s *msg;
3168
3169 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3170
3171 if (!msg) {
3172 fcport->stats_qfull = BFA_TRUE;
3173 bfa_reqq_winit(&fcport->stats_reqq_wait,
3174 bfa_fcport_send_stats_clear, fcport);
3175 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3176 &fcport->stats_reqq_wait);
3177 return;
3178 }
3179 fcport->stats_qfull = BFA_FALSE;
3180
Jing Huang6a18b162010-10-18 17:08:54 -07003181 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003182 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
3183 bfa_lpuid(fcport->bfa));
3184 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
3185}
3186
Jing Huang5fbe25c2010-10-18 17:17:23 -07003187/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003188 * Handle trunk SCN event from firmware.
3189 */
3190static void
3191bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3192{
3193 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3194 struct bfi_fcport_trunk_link_s *tlink;
3195 struct bfa_trunk_link_attr_s *lattr;
3196 enum bfa_trunk_state state_prev;
3197 int i;
3198 int link_bm = 0;
3199
3200 bfa_trc(fcport->bfa, fcport->cfg.trunked);
Jing Huangd4b671c2010-12-26 21:46:35 -08003201 WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
3202 scn->trunk_state != BFA_TRUNK_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003203
3204 bfa_trc(fcport->bfa, trunk->attr.state);
3205 bfa_trc(fcport->bfa, scn->trunk_state);
3206 bfa_trc(fcport->bfa, scn->trunk_speed);
3207
Jing Huang5fbe25c2010-10-18 17:17:23 -07003208 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003209 * Save off new state for trunk attribute query
3210 */
3211 state_prev = trunk->attr.state;
3212 if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
3213 trunk->attr.state = scn->trunk_state;
3214 trunk->attr.speed = scn->trunk_speed;
3215 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3216 lattr = &trunk->attr.link_attr[i];
3217 tlink = &scn->tlink[i];
3218
3219 lattr->link_state = tlink->state;
3220 lattr->trunk_wwn = tlink->trunk_wwn;
3221 lattr->fctl = tlink->fctl;
3222 lattr->speed = tlink->speed;
Jing Huangba816ea2010-10-18 17:10:50 -07003223 lattr->deskew = be32_to_cpu(tlink->deskew);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003224
3225 if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
3226 fcport->speed = tlink->speed;
3227 fcport->topology = BFA_PORT_TOPOLOGY_P2P;
3228 link_bm |= 1 << i;
3229 }
3230
3231 bfa_trc(fcport->bfa, lattr->link_state);
3232 bfa_trc(fcport->bfa, lattr->trunk_wwn);
3233 bfa_trc(fcport->bfa, lattr->fctl);
3234 bfa_trc(fcport->bfa, lattr->speed);
3235 bfa_trc(fcport->bfa, lattr->deskew);
3236 }
3237
3238 switch (link_bm) {
3239 case 3:
3240 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3241 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
3242 break;
3243 case 2:
3244 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3245 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
3246 break;
3247 case 1:
3248 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3249 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
3250 break;
3251 default:
3252 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3253 BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
3254 }
3255
Jing Huang5fbe25c2010-10-18 17:17:23 -07003256 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003257 * Notify upper layers if trunk state changed.
3258 */
3259 if ((state_prev != trunk->attr.state) ||
3260 (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
3261 bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
3262 BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
3263 }
3264}
3265
3266static void
3267bfa_trunk_iocdisable(struct bfa_s *bfa)
3268{
3269 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3270 int i = 0;
3271
Jing Huang5fbe25c2010-10-18 17:17:23 -07003272 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003273 * In trunked mode, notify upper layers that link is down
3274 */
3275 if (fcport->cfg.trunked) {
3276 if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
3277 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
3278
3279 fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
3280 fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
3281 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3282 fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
3283 fcport->trunk.attr.link_attr[i].fctl =
3284 BFA_TRUNK_LINK_FCTL_NORMAL;
3285 fcport->trunk.attr.link_attr[i].link_state =
3286 BFA_TRUNK_LINK_STATE_DN_LINKDN;
3287 fcport->trunk.attr.link_attr[i].speed =
3288 BFA_PORT_SPEED_UNKNOWN;
3289 fcport->trunk.attr.link_attr[i].deskew = 0;
3290 }
3291 }
3292}
3293
Jing Huang5fbe25c2010-10-18 17:17:23 -07003294/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003295 * Called to initialize port attributes
3296 */
3297void
3298bfa_fcport_init(struct bfa_s *bfa)
3299{
3300 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3301
Jing Huang5fbe25c2010-10-18 17:17:23 -07003302 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003303 * Initialize port attributes from IOC hardware data.
3304 */
3305 bfa_fcport_set_wwns(fcport);
3306 if (fcport->cfg.maxfrsize == 0)
3307 fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
3308 fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
3309 fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
3310
Jing Huangd4b671c2010-12-26 21:46:35 -08003311 WARN_ON(!fcport->cfg.maxfrsize);
3312 WARN_ON(!fcport->cfg.rx_bbcredit);
3313 WARN_ON(!fcport->speed_sup);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003314}
3315
Jing Huang5fbe25c2010-10-18 17:17:23 -07003316/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003317 * Firmware message handler.
3318 */
3319void
3320bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
3321{
3322 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3323 union bfi_fcport_i2h_msg_u i2hmsg;
3324
3325 i2hmsg.msg = msg;
3326 fcport->event_arg.i2hmsg = i2hmsg;
3327
3328 bfa_trc(bfa, msg->mhdr.msg_id);
3329 bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
3330
3331 switch (msg->mhdr.msg_id) {
3332 case BFI_FCPORT_I2H_ENABLE_RSP:
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003333 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
3334
3335 if (fcport->use_flash_cfg) {
3336 fcport->cfg = i2hmsg.penable_rsp->port_cfg;
3337 fcport->cfg.maxfrsize =
3338 cpu_to_be16(fcport->cfg.maxfrsize);
3339 fcport->cfg.path_tov =
3340 cpu_to_be16(fcport->cfg.path_tov);
3341 fcport->cfg.q_depth =
3342 cpu_to_be16(fcport->cfg.q_depth);
3343
3344 if (fcport->cfg.trunked)
3345 fcport->trunk.attr.state =
3346 BFA_TRUNK_OFFLINE;
3347 else
3348 fcport->trunk.attr.state =
3349 BFA_TRUNK_DISABLED;
3350 fcport->use_flash_cfg = BFA_FALSE;
3351 }
3352
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003353 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003354 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003355 break;
3356
3357 case BFI_FCPORT_I2H_DISABLE_RSP:
3358 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
3359 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
3360 break;
3361
3362 case BFI_FCPORT_I2H_EVENT:
3363 if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
3364 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
3365 else
3366 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
3367 break;
3368
3369 case BFI_FCPORT_I2H_TRUNK_SCN:
3370 bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
3371 break;
3372
3373 case BFI_FCPORT_I2H_STATS_GET_RSP:
3374 /*
3375 * check for timer pop before processing the rsp
3376 */
3377 if (fcport->stats_busy == BFA_FALSE ||
3378 fcport->stats_status == BFA_STATUS_ETIMER)
3379 break;
3380
3381 bfa_timer_stop(&fcport->timer);
3382 fcport->stats_status = i2hmsg.pstatsget_rsp->status;
3383 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3384 __bfa_cb_fcport_stats_get, fcport);
3385 break;
3386
3387 case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
3388 /*
3389 * check for timer pop before processing the rsp
3390 */
3391 if (fcport->stats_busy == BFA_FALSE ||
3392 fcport->stats_status == BFA_STATUS_ETIMER)
3393 break;
3394
3395 bfa_timer_stop(&fcport->timer);
3396 fcport->stats_status = BFA_STATUS_OK;
3397 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3398 __bfa_cb_fcport_stats_clr, fcport);
3399 break;
3400
3401 case BFI_FCPORT_I2H_ENABLE_AEN:
3402 bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
3403 break;
3404
3405 case BFI_FCPORT_I2H_DISABLE_AEN:
3406 bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
3407 break;
3408
3409 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08003410 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003411 break;
3412 }
3413}
3414
Jing Huang5fbe25c2010-10-18 17:17:23 -07003415/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003416 * Registered callback for port events.
3417 */
3418void
3419bfa_fcport_event_register(struct bfa_s *bfa,
3420 void (*cbfn) (void *cbarg,
3421 enum bfa_port_linkstate event),
3422 void *cbarg)
3423{
3424 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3425
3426 fcport->event_cbfn = cbfn;
3427 fcport->event_cbarg = cbarg;
3428}
3429
3430bfa_status_t
3431bfa_fcport_enable(struct bfa_s *bfa)
3432{
3433 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3434
3435 if (bfa_ioc_is_disabled(&bfa->ioc))
3436 return BFA_STATUS_IOC_DISABLED;
3437
3438 if (fcport->diag_busy)
3439 return BFA_STATUS_DIAG_BUSY;
3440
3441 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
3442 return BFA_STATUS_OK;
3443}
3444
3445bfa_status_t
3446bfa_fcport_disable(struct bfa_s *bfa)
3447{
3448
3449 if (bfa_ioc_is_disabled(&bfa->ioc))
3450 return BFA_STATUS_IOC_DISABLED;
3451
3452 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
3453 return BFA_STATUS_OK;
3454}
3455
Jing Huang5fbe25c2010-10-18 17:17:23 -07003456/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003457 * Configure port speed.
3458 */
3459bfa_status_t
3460bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3461{
3462 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3463
3464 bfa_trc(bfa, speed);
3465
3466 if (fcport->cfg.trunked == BFA_TRUE)
3467 return BFA_STATUS_TRUNK_ENABLED;
3468 if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
3469 bfa_trc(bfa, fcport->speed_sup);
3470 return BFA_STATUS_UNSUPP_SPEED;
3471 }
3472
3473 fcport->cfg.speed = speed;
3474
3475 return BFA_STATUS_OK;
3476}
3477
Jing Huang5fbe25c2010-10-18 17:17:23 -07003478/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003479 * Get current speed.
3480 */
3481enum bfa_port_speed
3482bfa_fcport_get_speed(struct bfa_s *bfa)
3483{
3484 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3485
3486 return fcport->speed;
3487}
3488
Jing Huang5fbe25c2010-10-18 17:17:23 -07003489/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003490 * Configure port topology.
3491 */
3492bfa_status_t
3493bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
3494{
3495 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3496
3497 bfa_trc(bfa, topology);
3498 bfa_trc(bfa, fcport->cfg.topology);
3499
3500 switch (topology) {
3501 case BFA_PORT_TOPOLOGY_P2P:
3502 case BFA_PORT_TOPOLOGY_LOOP:
3503 case BFA_PORT_TOPOLOGY_AUTO:
3504 break;
3505
3506 default:
3507 return BFA_STATUS_EINVAL;
3508 }
3509
3510 fcport->cfg.topology = topology;
3511 return BFA_STATUS_OK;
3512}
3513
Jing Huang5fbe25c2010-10-18 17:17:23 -07003514/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003515 * Get current topology.
3516 */
3517enum bfa_port_topology
3518bfa_fcport_get_topology(struct bfa_s *bfa)
3519{
3520 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3521
3522 return fcport->topology;
3523}
3524
3525bfa_status_t
3526bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
3527{
3528 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3529
3530 bfa_trc(bfa, alpa);
3531 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3532 bfa_trc(bfa, fcport->cfg.hardalpa);
3533
3534 fcport->cfg.cfg_hardalpa = BFA_TRUE;
3535 fcport->cfg.hardalpa = alpa;
3536
3537 return BFA_STATUS_OK;
3538}
3539
3540bfa_status_t
3541bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
3542{
3543 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3544
3545 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3546 bfa_trc(bfa, fcport->cfg.hardalpa);
3547
3548 fcport->cfg.cfg_hardalpa = BFA_FALSE;
3549 return BFA_STATUS_OK;
3550}
3551
3552bfa_boolean_t
3553bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
3554{
3555 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3556
3557 *alpa = fcport->cfg.hardalpa;
3558 return fcport->cfg.cfg_hardalpa;
3559}
3560
3561u8
3562bfa_fcport_get_myalpa(struct bfa_s *bfa)
3563{
3564 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3565
3566 return fcport->myalpa;
3567}
3568
3569bfa_status_t
3570bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
3571{
3572 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3573
3574 bfa_trc(bfa, maxfrsize);
3575 bfa_trc(bfa, fcport->cfg.maxfrsize);
3576
3577 /* with in range */
3578 if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
3579 return BFA_STATUS_INVLD_DFSZ;
3580
3581 /* power of 2, if not the max frame size of 2112 */
3582 if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
3583 return BFA_STATUS_INVLD_DFSZ;
3584
3585 fcport->cfg.maxfrsize = maxfrsize;
3586 return BFA_STATUS_OK;
3587}
3588
3589u16
3590bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
3591{
3592 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3593
3594 return fcport->cfg.maxfrsize;
3595}
3596
3597u8
3598bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
3599{
3600 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3601
3602 return fcport->cfg.rx_bbcredit;
3603}
3604
3605void
3606bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
3607{
3608 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3609
3610 fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
3611 bfa_fcport_send_txcredit(fcport);
3612}
3613
Jing Huang5fbe25c2010-10-18 17:17:23 -07003614/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003615 * Get port attributes.
3616 */
3617
3618wwn_t
3619bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
3620{
3621 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3622 if (node)
3623 return fcport->nwwn;
3624 else
3625 return fcport->pwwn;
3626}
3627
3628void
3629bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3630{
3631 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3632
Jing Huang6a18b162010-10-18 17:08:54 -07003633 memset(attr, 0, sizeof(struct bfa_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003634
3635 attr->nwwn = fcport->nwwn;
3636 attr->pwwn = fcport->pwwn;
3637
Maggie Zhangf7f738122010-12-09 19:08:43 -08003638 attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
3639 attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003640
Jing Huang6a18b162010-10-18 17:08:54 -07003641 memcpy(&attr->pport_cfg, &fcport->cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003642 sizeof(struct bfa_port_cfg_s));
3643 /* speed attributes */
3644 attr->pport_cfg.speed = fcport->cfg.speed;
3645 attr->speed_supported = fcport->speed_sup;
3646 attr->speed = fcport->speed;
3647 attr->cos_supported = FC_CLASS_3;
3648
3649 /* topology attributes */
3650 attr->pport_cfg.topology = fcport->cfg.topology;
3651 attr->topology = fcport->topology;
3652 attr->pport_cfg.trunked = fcport->cfg.trunked;
3653
3654 /* beacon attributes */
3655 attr->beacon = fcport->beacon;
3656 attr->link_e2e_beacon = fcport->link_e2e_beacon;
Maggie Zhangf7f738122010-12-09 19:08:43 -08003657 attr->plog_enabled = (bfa_boolean_t)fcport->bfa->plog->plog_enabled;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003658 attr->io_profile = bfa_fcpim_get_io_profile(fcport->bfa);
3659
3660 attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
3661 attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
3662 attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
3663 if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
3664 attr->port_state = BFA_PORT_ST_IOCDIS;
3665 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
3666 attr->port_state = BFA_PORT_ST_FWMISMATCH;
3667
3668 /* FCoE vlan */
3669 attr->fcoe_vlan = fcport->fcoe_vlan;
3670}
3671
3672#define BFA_FCPORT_STATS_TOV 1000
3673
Jing Huang5fbe25c2010-10-18 17:17:23 -07003674/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003675 * Fetch port statistics (FCQoS or FCoE).
3676 */
3677bfa_status_t
3678bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
3679 bfa_cb_port_t cbfn, void *cbarg)
3680{
3681 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3682
3683 if (fcport->stats_busy) {
3684 bfa_trc(bfa, fcport->stats_busy);
3685 return BFA_STATUS_DEVBUSY;
3686 }
3687
3688 fcport->stats_busy = BFA_TRUE;
3689 fcport->stats_ret = stats;
3690 fcport->stats_cbfn = cbfn;
3691 fcport->stats_cbarg = cbarg;
3692
3693 bfa_fcport_send_stats_get(fcport);
3694
3695 bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_get_timeout,
3696 fcport, BFA_FCPORT_STATS_TOV);
3697 return BFA_STATUS_OK;
3698}
3699
Jing Huang5fbe25c2010-10-18 17:17:23 -07003700/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003701 * Reset port statistics (FCQoS or FCoE).
3702 */
3703bfa_status_t
3704bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_port_t cbfn, void *cbarg)
3705{
3706 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3707
3708 if (fcport->stats_busy) {
3709 bfa_trc(bfa, fcport->stats_busy);
3710 return BFA_STATUS_DEVBUSY;
3711 }
3712
3713 fcport->stats_busy = BFA_TRUE;
3714 fcport->stats_cbfn = cbfn;
3715 fcport->stats_cbarg = cbarg;
3716
3717 bfa_fcport_send_stats_clear(fcport);
3718
3719 bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_clr_timeout,
3720 fcport, BFA_FCPORT_STATS_TOV);
3721 return BFA_STATUS_OK;
3722}
3723
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003724
Jing Huang5fbe25c2010-10-18 17:17:23 -07003725/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003726 * Fetch port attributes.
3727 */
3728bfa_boolean_t
3729bfa_fcport_is_disabled(struct bfa_s *bfa)
3730{
3731 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3732
3733 return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
3734 BFA_PORT_ST_DISABLED;
3735
3736}
3737
3738bfa_boolean_t
3739bfa_fcport_is_ratelim(struct bfa_s *bfa)
3740{
3741 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3742
3743 return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
3744
3745}
3746
Jing Huang5fbe25c2010-10-18 17:17:23 -07003747/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003748 * Get default minimum ratelim speed
3749 */
3750enum bfa_port_speed
3751bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
3752{
3753 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3754
3755 bfa_trc(bfa, fcport->cfg.trl_def_speed);
3756 return fcport->cfg.trl_def_speed;
3757
3758}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003759
3760bfa_boolean_t
3761bfa_fcport_is_linkup(struct bfa_s *bfa)
3762{
3763 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3764
3765 return (!fcport->cfg.trunked &&
3766 bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
3767 (fcport->cfg.trunked &&
3768 fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
3769}
3770
3771bfa_boolean_t
3772bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
3773{
3774 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3775
3776 return fcport->cfg.qos_enabled;
3777}
3778
Jing Huang5fbe25c2010-10-18 17:17:23 -07003779/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003780 * Rport State machine functions
3781 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07003782/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003783 * Beginning state, only online event expected.
3784 */
3785static void
3786bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
3787{
3788 bfa_trc(rp->bfa, rp->rport_tag);
3789 bfa_trc(rp->bfa, event);
3790
3791 switch (event) {
3792 case BFA_RPORT_SM_CREATE:
3793 bfa_stats(rp, sm_un_cr);
3794 bfa_sm_set_state(rp, bfa_rport_sm_created);
3795 break;
3796
3797 default:
3798 bfa_stats(rp, sm_un_unexp);
3799 bfa_sm_fault(rp->bfa, event);
3800 }
3801}
3802
3803static void
3804bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
3805{
3806 bfa_trc(rp->bfa, rp->rport_tag);
3807 bfa_trc(rp->bfa, event);
3808
3809 switch (event) {
3810 case BFA_RPORT_SM_ONLINE:
3811 bfa_stats(rp, sm_cr_on);
3812 if (bfa_rport_send_fwcreate(rp))
3813 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
3814 else
3815 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
3816 break;
3817
3818 case BFA_RPORT_SM_DELETE:
3819 bfa_stats(rp, sm_cr_del);
3820 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
3821 bfa_rport_free(rp);
3822 break;
3823
3824 case BFA_RPORT_SM_HWFAIL:
3825 bfa_stats(rp, sm_cr_hwf);
3826 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3827 break;
3828
3829 default:
3830 bfa_stats(rp, sm_cr_unexp);
3831 bfa_sm_fault(rp->bfa, event);
3832 }
3833}
3834
Jing Huang5fbe25c2010-10-18 17:17:23 -07003835/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003836 * Waiting for rport create response from firmware.
3837 */
3838static void
3839bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
3840{
3841 bfa_trc(rp->bfa, rp->rport_tag);
3842 bfa_trc(rp->bfa, event);
3843
3844 switch (event) {
3845 case BFA_RPORT_SM_FWRSP:
3846 bfa_stats(rp, sm_fwc_rsp);
3847 bfa_sm_set_state(rp, bfa_rport_sm_online);
3848 bfa_rport_online_cb(rp);
3849 break;
3850
3851 case BFA_RPORT_SM_DELETE:
3852 bfa_stats(rp, sm_fwc_del);
3853 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
3854 break;
3855
3856 case BFA_RPORT_SM_OFFLINE:
3857 bfa_stats(rp, sm_fwc_off);
3858 bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
3859 break;
3860
3861 case BFA_RPORT_SM_HWFAIL:
3862 bfa_stats(rp, sm_fwc_hwf);
3863 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3864 break;
3865
3866 default:
3867 bfa_stats(rp, sm_fwc_unexp);
3868 bfa_sm_fault(rp->bfa, event);
3869 }
3870}
3871
Jing Huang5fbe25c2010-10-18 17:17:23 -07003872/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003873 * Request queue is full, awaiting queue resume to send create request.
3874 */
3875static void
3876bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
3877{
3878 bfa_trc(rp->bfa, rp->rport_tag);
3879 bfa_trc(rp->bfa, event);
3880
3881 switch (event) {
3882 case BFA_RPORT_SM_QRESUME:
3883 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
3884 bfa_rport_send_fwcreate(rp);
3885 break;
3886
3887 case BFA_RPORT_SM_DELETE:
3888 bfa_stats(rp, sm_fwc_del);
3889 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
3890 bfa_reqq_wcancel(&rp->reqq_wait);
3891 bfa_rport_free(rp);
3892 break;
3893
3894 case BFA_RPORT_SM_OFFLINE:
3895 bfa_stats(rp, sm_fwc_off);
3896 bfa_sm_set_state(rp, bfa_rport_sm_offline);
3897 bfa_reqq_wcancel(&rp->reqq_wait);
3898 bfa_rport_offline_cb(rp);
3899 break;
3900
3901 case BFA_RPORT_SM_HWFAIL:
3902 bfa_stats(rp, sm_fwc_hwf);
3903 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3904 bfa_reqq_wcancel(&rp->reqq_wait);
3905 break;
3906
3907 default:
3908 bfa_stats(rp, sm_fwc_unexp);
3909 bfa_sm_fault(rp->bfa, event);
3910 }
3911}
3912
Jing Huang5fbe25c2010-10-18 17:17:23 -07003913/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003914 * Online state - normal parking state.
3915 */
3916static void
3917bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
3918{
3919 struct bfi_rport_qos_scn_s *qos_scn;
3920
3921 bfa_trc(rp->bfa, rp->rport_tag);
3922 bfa_trc(rp->bfa, event);
3923
3924 switch (event) {
3925 case BFA_RPORT_SM_OFFLINE:
3926 bfa_stats(rp, sm_on_off);
3927 if (bfa_rport_send_fwdelete(rp))
3928 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
3929 else
3930 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
3931 break;
3932
3933 case BFA_RPORT_SM_DELETE:
3934 bfa_stats(rp, sm_on_del);
3935 if (bfa_rport_send_fwdelete(rp))
3936 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
3937 else
3938 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
3939 break;
3940
3941 case BFA_RPORT_SM_HWFAIL:
3942 bfa_stats(rp, sm_on_hwf);
3943 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3944 break;
3945
3946 case BFA_RPORT_SM_SET_SPEED:
3947 bfa_rport_send_fwspeed(rp);
3948 break;
3949
3950 case BFA_RPORT_SM_QOS_SCN:
3951 qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
3952 rp->qos_attr = qos_scn->new_qos_attr;
3953 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
3954 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
3955 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
3956 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
3957
3958 qos_scn->old_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07003959 be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003960 qos_scn->new_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07003961 be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003962
3963 if (qos_scn->old_qos_attr.qos_flow_id !=
3964 qos_scn->new_qos_attr.qos_flow_id)
3965 bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
3966 qos_scn->old_qos_attr,
3967 qos_scn->new_qos_attr);
3968 if (qos_scn->old_qos_attr.qos_priority !=
3969 qos_scn->new_qos_attr.qos_priority)
3970 bfa_cb_rport_qos_scn_prio(rp->rport_drv,
3971 qos_scn->old_qos_attr,
3972 qos_scn->new_qos_attr);
3973 break;
3974
3975 default:
3976 bfa_stats(rp, sm_on_unexp);
3977 bfa_sm_fault(rp->bfa, event);
3978 }
3979}
3980
Jing Huang5fbe25c2010-10-18 17:17:23 -07003981/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003982 * Firmware rport is being deleted - awaiting f/w response.
3983 */
3984static void
3985bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
3986{
3987 bfa_trc(rp->bfa, rp->rport_tag);
3988 bfa_trc(rp->bfa, event);
3989
3990 switch (event) {
3991 case BFA_RPORT_SM_FWRSP:
3992 bfa_stats(rp, sm_fwd_rsp);
3993 bfa_sm_set_state(rp, bfa_rport_sm_offline);
3994 bfa_rport_offline_cb(rp);
3995 break;
3996
3997 case BFA_RPORT_SM_DELETE:
3998 bfa_stats(rp, sm_fwd_del);
3999 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4000 break;
4001
4002 case BFA_RPORT_SM_HWFAIL:
4003 bfa_stats(rp, sm_fwd_hwf);
4004 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4005 bfa_rport_offline_cb(rp);
4006 break;
4007
4008 default:
4009 bfa_stats(rp, sm_fwd_unexp);
4010 bfa_sm_fault(rp->bfa, event);
4011 }
4012}
4013
4014static void
4015bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4016{
4017 bfa_trc(rp->bfa, rp->rport_tag);
4018 bfa_trc(rp->bfa, event);
4019
4020 switch (event) {
4021 case BFA_RPORT_SM_QRESUME:
4022 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4023 bfa_rport_send_fwdelete(rp);
4024 break;
4025
4026 case BFA_RPORT_SM_DELETE:
4027 bfa_stats(rp, sm_fwd_del);
4028 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4029 break;
4030
4031 case BFA_RPORT_SM_HWFAIL:
4032 bfa_stats(rp, sm_fwd_hwf);
4033 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4034 bfa_reqq_wcancel(&rp->reqq_wait);
4035 bfa_rport_offline_cb(rp);
4036 break;
4037
4038 default:
4039 bfa_stats(rp, sm_fwd_unexp);
4040 bfa_sm_fault(rp->bfa, event);
4041 }
4042}
4043
Jing Huang5fbe25c2010-10-18 17:17:23 -07004044/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004045 * Offline state.
4046 */
4047static void
4048bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
4049{
4050 bfa_trc(rp->bfa, rp->rport_tag);
4051 bfa_trc(rp->bfa, event);
4052
4053 switch (event) {
4054 case BFA_RPORT_SM_DELETE:
4055 bfa_stats(rp, sm_off_del);
4056 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4057 bfa_rport_free(rp);
4058 break;
4059
4060 case BFA_RPORT_SM_ONLINE:
4061 bfa_stats(rp, sm_off_on);
4062 if (bfa_rport_send_fwcreate(rp))
4063 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4064 else
4065 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4066 break;
4067
4068 case BFA_RPORT_SM_HWFAIL:
4069 bfa_stats(rp, sm_off_hwf);
4070 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4071 break;
4072
4073 default:
4074 bfa_stats(rp, sm_off_unexp);
4075 bfa_sm_fault(rp->bfa, event);
4076 }
4077}
4078
Jing Huang5fbe25c2010-10-18 17:17:23 -07004079/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004080 * Rport is deleted, waiting for firmware response to delete.
4081 */
4082static void
4083bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
4084{
4085 bfa_trc(rp->bfa, rp->rport_tag);
4086 bfa_trc(rp->bfa, event);
4087
4088 switch (event) {
4089 case BFA_RPORT_SM_FWRSP:
4090 bfa_stats(rp, sm_del_fwrsp);
4091 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4092 bfa_rport_free(rp);
4093 break;
4094
4095 case BFA_RPORT_SM_HWFAIL:
4096 bfa_stats(rp, sm_del_hwf);
4097 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4098 bfa_rport_free(rp);
4099 break;
4100
4101 default:
4102 bfa_sm_fault(rp->bfa, event);
4103 }
4104}
4105
4106static void
4107bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4108{
4109 bfa_trc(rp->bfa, rp->rport_tag);
4110 bfa_trc(rp->bfa, event);
4111
4112 switch (event) {
4113 case BFA_RPORT_SM_QRESUME:
4114 bfa_stats(rp, sm_del_fwrsp);
4115 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4116 bfa_rport_send_fwdelete(rp);
4117 break;
4118
4119 case BFA_RPORT_SM_HWFAIL:
4120 bfa_stats(rp, sm_del_hwf);
4121 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4122 bfa_reqq_wcancel(&rp->reqq_wait);
4123 bfa_rport_free(rp);
4124 break;
4125
4126 default:
4127 bfa_sm_fault(rp->bfa, event);
4128 }
4129}
4130
Jing Huang5fbe25c2010-10-18 17:17:23 -07004131/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004132 * Waiting for rport create response from firmware. A delete is pending.
4133 */
4134static void
4135bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
4136 enum bfa_rport_event event)
4137{
4138 bfa_trc(rp->bfa, rp->rport_tag);
4139 bfa_trc(rp->bfa, event);
4140
4141 switch (event) {
4142 case BFA_RPORT_SM_FWRSP:
4143 bfa_stats(rp, sm_delp_fwrsp);
4144 if (bfa_rport_send_fwdelete(rp))
4145 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4146 else
4147 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4148 break;
4149
4150 case BFA_RPORT_SM_HWFAIL:
4151 bfa_stats(rp, sm_delp_hwf);
4152 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4153 bfa_rport_free(rp);
4154 break;
4155
4156 default:
4157 bfa_stats(rp, sm_delp_unexp);
4158 bfa_sm_fault(rp->bfa, event);
4159 }
4160}
4161
Jing Huang5fbe25c2010-10-18 17:17:23 -07004162/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004163 * Waiting for rport create response from firmware. Rport offline is pending.
4164 */
4165static void
4166bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
4167 enum bfa_rport_event event)
4168{
4169 bfa_trc(rp->bfa, rp->rport_tag);
4170 bfa_trc(rp->bfa, event);
4171
4172 switch (event) {
4173 case BFA_RPORT_SM_FWRSP:
4174 bfa_stats(rp, sm_offp_fwrsp);
4175 if (bfa_rport_send_fwdelete(rp))
4176 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4177 else
4178 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4179 break;
4180
4181 case BFA_RPORT_SM_DELETE:
4182 bfa_stats(rp, sm_offp_del);
4183 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4184 break;
4185
4186 case BFA_RPORT_SM_HWFAIL:
4187 bfa_stats(rp, sm_offp_hwf);
4188 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4189 break;
4190
4191 default:
4192 bfa_stats(rp, sm_offp_unexp);
4193 bfa_sm_fault(rp->bfa, event);
4194 }
4195}
4196
Jing Huang5fbe25c2010-10-18 17:17:23 -07004197/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004198 * IOC h/w failed.
4199 */
4200static void
4201bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
4202{
4203 bfa_trc(rp->bfa, rp->rport_tag);
4204 bfa_trc(rp->bfa, event);
4205
4206 switch (event) {
4207 case BFA_RPORT_SM_OFFLINE:
4208 bfa_stats(rp, sm_iocd_off);
4209 bfa_rport_offline_cb(rp);
4210 break;
4211
4212 case BFA_RPORT_SM_DELETE:
4213 bfa_stats(rp, sm_iocd_del);
4214 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4215 bfa_rport_free(rp);
4216 break;
4217
4218 case BFA_RPORT_SM_ONLINE:
4219 bfa_stats(rp, sm_iocd_on);
4220 if (bfa_rport_send_fwcreate(rp))
4221 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4222 else
4223 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4224 break;
4225
4226 case BFA_RPORT_SM_HWFAIL:
4227 break;
4228
4229 default:
4230 bfa_stats(rp, sm_iocd_unexp);
4231 bfa_sm_fault(rp->bfa, event);
4232 }
4233}
4234
4235
4236
Jing Huang5fbe25c2010-10-18 17:17:23 -07004237/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004238 * bfa_rport_private BFA rport private functions
4239 */
4240
4241static void
4242__bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
4243{
4244 struct bfa_rport_s *rp = cbarg;
4245
4246 if (complete)
4247 bfa_cb_rport_online(rp->rport_drv);
4248}
4249
4250static void
4251__bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
4252{
4253 struct bfa_rport_s *rp = cbarg;
4254
4255 if (complete)
4256 bfa_cb_rport_offline(rp->rport_drv);
4257}
4258
4259static void
4260bfa_rport_qresume(void *cbarg)
4261{
4262 struct bfa_rport_s *rp = cbarg;
4263
4264 bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
4265}
4266
4267static void
4268bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
4269 u32 *dm_len)
4270{
4271 if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
4272 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
4273
4274 *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s);
4275}
4276
4277static void
4278bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4279 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
4280{
4281 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4282 struct bfa_rport_s *rp;
4283 u16 i;
4284
4285 INIT_LIST_HEAD(&mod->rp_free_q);
4286 INIT_LIST_HEAD(&mod->rp_active_q);
4287
4288 rp = (struct bfa_rport_s *) bfa_meminfo_kva(meminfo);
4289 mod->rps_list = rp;
4290 mod->num_rports = cfg->fwcfg.num_rports;
4291
Jing Huangd4b671c2010-12-26 21:46:35 -08004292 WARN_ON(!mod->num_rports ||
4293 (mod->num_rports & (mod->num_rports - 1)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004294
4295 for (i = 0; i < mod->num_rports; i++, rp++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004296 memset(rp, 0, sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004297 rp->bfa = bfa;
4298 rp->rport_tag = i;
4299 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4300
Jing Huang5fbe25c2010-10-18 17:17:23 -07004301 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004302 * - is unused
4303 */
4304 if (i)
4305 list_add_tail(&rp->qe, &mod->rp_free_q);
4306
4307 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
4308 }
4309
Jing Huang5fbe25c2010-10-18 17:17:23 -07004310 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004311 * consume memory
4312 */
4313 bfa_meminfo_kva(meminfo) = (u8 *) rp;
4314}
4315
4316static void
4317bfa_rport_detach(struct bfa_s *bfa)
4318{
4319}
4320
4321static void
4322bfa_rport_start(struct bfa_s *bfa)
4323{
4324}
4325
4326static void
4327bfa_rport_stop(struct bfa_s *bfa)
4328{
4329}
4330
4331static void
4332bfa_rport_iocdisable(struct bfa_s *bfa)
4333{
4334 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4335 struct bfa_rport_s *rport;
4336 struct list_head *qe, *qen;
4337
4338 list_for_each_safe(qe, qen, &mod->rp_active_q) {
4339 rport = (struct bfa_rport_s *) qe;
4340 bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
4341 }
4342}
4343
4344static struct bfa_rport_s *
4345bfa_rport_alloc(struct bfa_rport_mod_s *mod)
4346{
4347 struct bfa_rport_s *rport;
4348
4349 bfa_q_deq(&mod->rp_free_q, &rport);
4350 if (rport)
4351 list_add_tail(&rport->qe, &mod->rp_active_q);
4352
4353 return rport;
4354}
4355
4356static void
4357bfa_rport_free(struct bfa_rport_s *rport)
4358{
4359 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
4360
Jing Huangd4b671c2010-12-26 21:46:35 -08004361 WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004362 list_del(&rport->qe);
4363 list_add_tail(&rport->qe, &mod->rp_free_q);
4364}
4365
4366static bfa_boolean_t
4367bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4368{
4369 struct bfi_rport_create_req_s *m;
4370
Jing Huang5fbe25c2010-10-18 17:17:23 -07004371 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004372 * check for room in queue to send request now
4373 */
4374 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4375 if (!m) {
4376 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4377 return BFA_FALSE;
4378 }
4379
4380 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
4381 bfa_lpuid(rp->bfa));
4382 m->bfa_handle = rp->rport_tag;
Jing Huangba816ea2010-10-18 17:10:50 -07004383 m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004384 m->pid = rp->rport_info.pid;
4385 m->lp_tag = rp->rport_info.lp_tag;
4386 m->local_pid = rp->rport_info.local_pid;
4387 m->fc_class = rp->rport_info.fc_class;
4388 m->vf_en = rp->rport_info.vf_en;
4389 m->vf_id = rp->rport_info.vf_id;
4390 m->cisc = rp->rport_info.cisc;
4391
Jing Huang5fbe25c2010-10-18 17:17:23 -07004392 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004393 * queue I/O message to firmware
4394 */
4395 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
4396 return BFA_TRUE;
4397}
4398
4399static bfa_boolean_t
4400bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4401{
4402 struct bfi_rport_delete_req_s *m;
4403
Jing Huang5fbe25c2010-10-18 17:17:23 -07004404 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004405 * check for room in queue to send request now
4406 */
4407 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4408 if (!m) {
4409 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4410 return BFA_FALSE;
4411 }
4412
4413 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
4414 bfa_lpuid(rp->bfa));
4415 m->fw_handle = rp->fw_handle;
4416
Jing Huang5fbe25c2010-10-18 17:17:23 -07004417 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004418 * queue I/O message to firmware
4419 */
4420 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
4421 return BFA_TRUE;
4422}
4423
4424static bfa_boolean_t
4425bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4426{
4427 struct bfa_rport_speed_req_s *m;
4428
Jing Huang5fbe25c2010-10-18 17:17:23 -07004429 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004430 * check for room in queue to send request now
4431 */
4432 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4433 if (!m) {
4434 bfa_trc(rp->bfa, rp->rport_info.speed);
4435 return BFA_FALSE;
4436 }
4437
4438 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
4439 bfa_lpuid(rp->bfa));
4440 m->fw_handle = rp->fw_handle;
4441 m->speed = (u8)rp->rport_info.speed;
4442
Jing Huang5fbe25c2010-10-18 17:17:23 -07004443 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004444 * queue I/O message to firmware
4445 */
4446 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
4447 return BFA_TRUE;
4448}
4449
4450
4451
Jing Huang5fbe25c2010-10-18 17:17:23 -07004452/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004453 * bfa_rport_public
4454 */
4455
Jing Huang5fbe25c2010-10-18 17:17:23 -07004456/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004457 * Rport interrupt processing.
4458 */
4459void
4460bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
4461{
4462 union bfi_rport_i2h_msg_u msg;
4463 struct bfa_rport_s *rp;
4464
4465 bfa_trc(bfa, m->mhdr.msg_id);
4466
4467 msg.msg = m;
4468
4469 switch (m->mhdr.msg_id) {
4470 case BFI_RPORT_I2H_CREATE_RSP:
4471 rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
4472 rp->fw_handle = msg.create_rsp->fw_handle;
4473 rp->qos_attr = msg.create_rsp->qos_attr;
Jing Huangd4b671c2010-12-26 21:46:35 -08004474 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004475 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4476 break;
4477
4478 case BFI_RPORT_I2H_DELETE_RSP:
4479 rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08004480 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004481 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4482 break;
4483
4484 case BFI_RPORT_I2H_QOS_SCN:
4485 rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
4486 rp->event_arg.fw_msg = msg.qos_scn_evt;
4487 bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
4488 break;
4489
4490 default:
4491 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08004492 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004493 }
4494}
4495
4496
4497
Jing Huang5fbe25c2010-10-18 17:17:23 -07004498/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004499 * bfa_rport_api
4500 */
4501
4502struct bfa_rport_s *
4503bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
4504{
4505 struct bfa_rport_s *rp;
4506
4507 rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
4508
4509 if (rp == NULL)
4510 return NULL;
4511
4512 rp->bfa = bfa;
4513 rp->rport_drv = rport_drv;
Maggie Zhangf7f738122010-12-09 19:08:43 -08004514 memset(&rp->stats, 0, sizeof(rp->stats));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004515
Jing Huangd4b671c2010-12-26 21:46:35 -08004516 WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004517 bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
4518
4519 return rp;
4520}
4521
4522void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004523bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
4524{
Jing Huangd4b671c2010-12-26 21:46:35 -08004525 WARN_ON(rport_info->max_frmsz == 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004526
Jing Huang5fbe25c2010-10-18 17:17:23 -07004527 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004528 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
4529 * responses. Default to minimum size.
4530 */
4531 if (rport_info->max_frmsz == 0) {
4532 bfa_trc(rport->bfa, rport->rport_tag);
4533 rport_info->max_frmsz = FC_MIN_PDUSZ;
4534 }
4535
Jing Huang6a18b162010-10-18 17:08:54 -07004536 rport->rport_info = *rport_info;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004537 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
4538}
4539
4540void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004541bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
4542{
Jing Huangd4b671c2010-12-26 21:46:35 -08004543 WARN_ON(speed == 0);
4544 WARN_ON(speed == BFA_PORT_SPEED_AUTO);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004545
4546 rport->rport_info.speed = speed;
4547 bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
4548}
4549
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004550
Jing Huang5fbe25c2010-10-18 17:17:23 -07004551/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004552 * SGPG related functions
4553 */
4554
Jing Huang5fbe25c2010-10-18 17:17:23 -07004555/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004556 * Compute and return memory needed by FCP(im) module.
4557 */
4558static void
4559bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
4560 u32 *dm_len)
4561{
4562 if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
4563 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
4564
4565 *km_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfa_sgpg_s);
4566 *dm_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfi_sgpg_s);
4567}
4568
4569
4570static void
4571bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4572 struct bfa_meminfo_s *minfo, struct bfa_pcidev_s *pcidev)
4573{
4574 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4575 int i;
4576 struct bfa_sgpg_s *hsgpg;
4577 struct bfi_sgpg_s *sgpg;
4578 u64 align_len;
4579
4580 union {
4581 u64 pa;
4582 union bfi_addr_u addr;
4583 } sgpg_pa, sgpg_pa_tmp;
4584
4585 INIT_LIST_HEAD(&mod->sgpg_q);
4586 INIT_LIST_HEAD(&mod->sgpg_wait_q);
4587
4588 bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
4589
4590 mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
4591 mod->sgpg_arr_pa = bfa_meminfo_dma_phys(minfo);
4592 align_len = (BFA_SGPG_ROUNDUP(mod->sgpg_arr_pa) - mod->sgpg_arr_pa);
4593 mod->sgpg_arr_pa += align_len;
4594 mod->hsgpg_arr = (struct bfa_sgpg_s *) (bfa_meminfo_kva(minfo) +
4595 align_len);
4596 mod->sgpg_arr = (struct bfi_sgpg_s *) (bfa_meminfo_dma_virt(minfo) +
4597 align_len);
4598
4599 hsgpg = mod->hsgpg_arr;
4600 sgpg = mod->sgpg_arr;
4601 sgpg_pa.pa = mod->sgpg_arr_pa;
4602 mod->free_sgpgs = mod->num_sgpgs;
4603
Jing Huangd4b671c2010-12-26 21:46:35 -08004604 WARN_ON(sgpg_pa.pa & (sizeof(struct bfi_sgpg_s) - 1));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004605
4606 for (i = 0; i < mod->num_sgpgs; i++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004607 memset(hsgpg, 0, sizeof(*hsgpg));
4608 memset(sgpg, 0, sizeof(*sgpg));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004609
4610 hsgpg->sgpg = sgpg;
4611 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
4612 hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
4613 list_add_tail(&hsgpg->qe, &mod->sgpg_q);
4614
4615 hsgpg++;
4616 sgpg++;
4617 sgpg_pa.pa += sizeof(struct bfi_sgpg_s);
4618 }
4619
4620 bfa_meminfo_kva(minfo) = (u8 *) hsgpg;
4621 bfa_meminfo_dma_virt(minfo) = (u8 *) sgpg;
4622 bfa_meminfo_dma_phys(minfo) = sgpg_pa.pa;
4623}
4624
4625static void
4626bfa_sgpg_detach(struct bfa_s *bfa)
4627{
4628}
4629
4630static void
4631bfa_sgpg_start(struct bfa_s *bfa)
4632{
4633}
4634
4635static void
4636bfa_sgpg_stop(struct bfa_s *bfa)
4637{
4638}
4639
4640static void
4641bfa_sgpg_iocdisable(struct bfa_s *bfa)
4642{
4643}
4644
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004645bfa_status_t
4646bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
4647{
4648 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4649 struct bfa_sgpg_s *hsgpg;
4650 int i;
4651
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004652 if (mod->free_sgpgs < nsgpgs)
4653 return BFA_STATUS_ENOMEM;
4654
4655 for (i = 0; i < nsgpgs; i++) {
4656 bfa_q_deq(&mod->sgpg_q, &hsgpg);
Jing Huangd4b671c2010-12-26 21:46:35 -08004657 WARN_ON(!hsgpg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004658 list_add_tail(&hsgpg->qe, sgpg_q);
4659 }
4660
4661 mod->free_sgpgs -= nsgpgs;
4662 return BFA_STATUS_OK;
4663}
4664
4665void
4666bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
4667{
4668 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4669 struct bfa_sgpg_wqe_s *wqe;
4670
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004671 mod->free_sgpgs += nsgpg;
Jing Huangd4b671c2010-12-26 21:46:35 -08004672 WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004673
4674 list_splice_tail_init(sgpg_q, &mod->sgpg_q);
4675
4676 if (list_empty(&mod->sgpg_wait_q))
4677 return;
4678
Jing Huang5fbe25c2010-10-18 17:17:23 -07004679 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004680 * satisfy as many waiting requests as possible
4681 */
4682 do {
4683 wqe = bfa_q_first(&mod->sgpg_wait_q);
4684 if (mod->free_sgpgs < wqe->nsgpg)
4685 nsgpg = mod->free_sgpgs;
4686 else
4687 nsgpg = wqe->nsgpg;
4688 bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
4689 wqe->nsgpg -= nsgpg;
4690 if (wqe->nsgpg == 0) {
4691 list_del(&wqe->qe);
4692 wqe->cbfn(wqe->cbarg);
4693 }
4694 } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
4695}
4696
4697void
4698bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
4699{
4700 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4701
Jing Huangd4b671c2010-12-26 21:46:35 -08004702 WARN_ON(nsgpg <= 0);
4703 WARN_ON(nsgpg <= mod->free_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004704
4705 wqe->nsgpg_total = wqe->nsgpg = nsgpg;
4706
Jing Huang5fbe25c2010-10-18 17:17:23 -07004707 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004708 * allocate any left to this one first
4709 */
4710 if (mod->free_sgpgs) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07004711 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004712 * no one else is waiting for SGPG
4713 */
Jing Huangd4b671c2010-12-26 21:46:35 -08004714 WARN_ON(!list_empty(&mod->sgpg_wait_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004715 list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
4716 wqe->nsgpg -= mod->free_sgpgs;
4717 mod->free_sgpgs = 0;
4718 }
4719
4720 list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
4721}
4722
4723void
4724bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
4725{
4726 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4727
Jing Huangd4b671c2010-12-26 21:46:35 -08004728 WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004729 list_del(&wqe->qe);
4730
4731 if (wqe->nsgpg_total != wqe->nsgpg)
4732 bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
4733 wqe->nsgpg_total - wqe->nsgpg);
4734}
4735
4736void
4737bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
4738 void *cbarg)
4739{
4740 INIT_LIST_HEAD(&wqe->sgpg_q);
4741 wqe->cbfn = cbfn;
4742 wqe->cbarg = cbarg;
4743}
4744
Jing Huang5fbe25c2010-10-18 17:17:23 -07004745/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004746 * UF related functions
4747 */
4748/*
4749 *****************************************************************************
4750 * Internal functions
4751 *****************************************************************************
4752 */
4753static void
4754__bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
4755{
4756 struct bfa_uf_s *uf = cbarg;
4757 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
4758
4759 if (complete)
4760 ufm->ufrecv(ufm->cbarg, uf);
4761}
4762
4763static void
4764claim_uf_pbs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4765{
4766 u32 uf_pb_tot_sz;
4767
4768 ufm->uf_pbs_kva = (struct bfa_uf_buf_s *) bfa_meminfo_dma_virt(mi);
4769 ufm->uf_pbs_pa = bfa_meminfo_dma_phys(mi);
4770 uf_pb_tot_sz = BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * ufm->num_ufs),
4771 BFA_DMA_ALIGN_SZ);
4772
4773 bfa_meminfo_dma_virt(mi) += uf_pb_tot_sz;
4774 bfa_meminfo_dma_phys(mi) += uf_pb_tot_sz;
4775
Jing Huang6a18b162010-10-18 17:08:54 -07004776 memset((void *)ufm->uf_pbs_kva, 0, uf_pb_tot_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004777}
4778
4779static void
4780claim_uf_post_msgs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4781{
4782 struct bfi_uf_buf_post_s *uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004783 u16 i;
4784 u16 buf_len;
4785
4786 ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_meminfo_kva(mi);
4787 uf_bp_msg = ufm->uf_buf_posts;
4788
4789 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
4790 i++, uf_bp_msg++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004791 memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004792
4793 uf_bp_msg->buf_tag = i;
4794 buf_len = sizeof(struct bfa_uf_buf_s);
Jing Huangba816ea2010-10-18 17:10:50 -07004795 uf_bp_msg->buf_len = cpu_to_be16(buf_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004796 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
4797 bfa_lpuid(ufm->bfa));
Krishna Gudipati85ce9282011-06-13 15:39:36 -07004798 bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004799 }
4800
Jing Huang5fbe25c2010-10-18 17:17:23 -07004801 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004802 * advance pointer beyond consumed memory
4803 */
4804 bfa_meminfo_kva(mi) = (u8 *) uf_bp_msg;
4805}
4806
4807static void
4808claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4809{
4810 u16 i;
4811 struct bfa_uf_s *uf;
4812
4813 /*
4814 * Claim block of memory for UF list
4815 */
4816 ufm->uf_list = (struct bfa_uf_s *) bfa_meminfo_kva(mi);
4817
4818 /*
4819 * Initialize UFs and queue it in UF free queue
4820 */
4821 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004822 memset(uf, 0, sizeof(struct bfa_uf_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004823 uf->bfa = ufm->bfa;
4824 uf->uf_tag = i;
4825 uf->pb_len = sizeof(struct bfa_uf_buf_s);
4826 uf->buf_kva = (void *)&ufm->uf_pbs_kva[i];
4827 uf->buf_pa = ufm_pbs_pa(ufm, i);
4828 list_add_tail(&uf->qe, &ufm->uf_free_q);
4829 }
4830
Jing Huang5fbe25c2010-10-18 17:17:23 -07004831 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004832 * advance memory pointer
4833 */
4834 bfa_meminfo_kva(mi) = (u8 *) uf;
4835}
4836
4837static void
4838uf_mem_claim(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4839{
4840 claim_uf_pbs(ufm, mi);
4841 claim_ufs(ufm, mi);
4842 claim_uf_post_msgs(ufm, mi);
4843}
4844
4845static void
4846bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, u32 *dm_len)
4847{
4848 u32 num_ufs = cfg->fwcfg.num_uf_bufs;
4849
4850 /*
4851 * dma-able memory for UF posted bufs
4852 */
4853 *dm_len += BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * num_ufs),
4854 BFA_DMA_ALIGN_SZ);
4855
4856 /*
4857 * kernel Virtual memory for UFs and UF buf post msg copies
4858 */
4859 *ndm_len += sizeof(struct bfa_uf_s) * num_ufs;
4860 *ndm_len += sizeof(struct bfi_uf_buf_post_s) * num_ufs;
4861}
4862
4863static void
4864bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4865 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
4866{
4867 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
4868
Jing Huang6a18b162010-10-18 17:08:54 -07004869 memset(ufm, 0, sizeof(struct bfa_uf_mod_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004870 ufm->bfa = bfa;
4871 ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
4872 INIT_LIST_HEAD(&ufm->uf_free_q);
4873 INIT_LIST_HEAD(&ufm->uf_posted_q);
4874
4875 uf_mem_claim(ufm, meminfo);
4876}
4877
4878static void
4879bfa_uf_detach(struct bfa_s *bfa)
4880{
4881}
4882
4883static struct bfa_uf_s *
4884bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
4885{
4886 struct bfa_uf_s *uf;
4887
4888 bfa_q_deq(&uf_mod->uf_free_q, &uf);
4889 return uf;
4890}
4891
4892static void
4893bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
4894{
4895 list_add_tail(&uf->qe, &uf_mod->uf_free_q);
4896}
4897
4898static bfa_status_t
4899bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
4900{
4901 struct bfi_uf_buf_post_s *uf_post_msg;
4902
4903 uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
4904 if (!uf_post_msg)
4905 return BFA_STATUS_FAILED;
4906
Jing Huang6a18b162010-10-18 17:08:54 -07004907 memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004908 sizeof(struct bfi_uf_buf_post_s));
4909 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP);
4910
4911 bfa_trc(ufm->bfa, uf->uf_tag);
4912
4913 list_add_tail(&uf->qe, &ufm->uf_posted_q);
4914 return BFA_STATUS_OK;
4915}
4916
4917static void
4918bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
4919{
4920 struct bfa_uf_s *uf;
4921
4922 while ((uf = bfa_uf_get(uf_mod)) != NULL) {
4923 if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
4924 break;
4925 }
4926}
4927
4928static void
4929uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
4930{
4931 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
4932 u16 uf_tag = m->buf_tag;
4933 struct bfa_uf_buf_s *uf_buf = &ufm->uf_pbs_kva[uf_tag];
4934 struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
4935 u8 *buf = &uf_buf->d[0];
4936 struct fchs_s *fchs;
4937
Jing Huangba816ea2010-10-18 17:10:50 -07004938 m->frm_len = be16_to_cpu(m->frm_len);
4939 m->xfr_len = be16_to_cpu(m->xfr_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004940
4941 fchs = (struct fchs_s *)uf_buf;
4942
4943 list_del(&uf->qe); /* dequeue from posted queue */
4944
4945 uf->data_ptr = buf;
4946 uf->data_len = m->xfr_len;
4947
Jing Huangd4b671c2010-12-26 21:46:35 -08004948 WARN_ON(uf->data_len < sizeof(struct fchs_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004949
4950 if (uf->data_len == sizeof(struct fchs_s)) {
4951 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
4952 uf->data_len, (struct fchs_s *)buf);
4953 } else {
4954 u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
4955 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
4956 BFA_PL_EID_RX, uf->data_len,
4957 (struct fchs_s *)buf, pld_w0);
4958 }
4959
4960 if (bfa->fcs)
4961 __bfa_cb_uf_recv(uf, BFA_TRUE);
4962 else
4963 bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
4964}
4965
4966static void
4967bfa_uf_stop(struct bfa_s *bfa)
4968{
4969}
4970
4971static void
4972bfa_uf_iocdisable(struct bfa_s *bfa)
4973{
4974 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
4975 struct bfa_uf_s *uf;
4976 struct list_head *qe, *qen;
4977
4978 list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
4979 uf = (struct bfa_uf_s *) qe;
4980 list_del(&uf->qe);
4981 bfa_uf_put(ufm, uf);
4982 }
4983}
4984
4985static void
4986bfa_uf_start(struct bfa_s *bfa)
4987{
4988 bfa_uf_post_all(BFA_UF_MOD(bfa));
4989}
4990
Jing Huang5fbe25c2010-10-18 17:17:23 -07004991/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004992 * Register handler for all unsolicted receive frames.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004993 *
4994 * @param[in] bfa BFA instance
4995 * @param[in] ufrecv receive handler function
4996 * @param[in] cbarg receive handler arg
4997 */
4998void
4999bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
5000{
5001 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5002
5003 ufm->ufrecv = ufrecv;
5004 ufm->cbarg = cbarg;
5005}
5006
Jing Huang5fbe25c2010-10-18 17:17:23 -07005007/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005008 * Free an unsolicited frame back to BFA.
5009 *
5010 * @param[in] uf unsolicited frame to be freed
5011 *
5012 * @return None
5013 */
5014void
5015bfa_uf_free(struct bfa_uf_s *uf)
5016{
5017 bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
5018 bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
5019}
5020
5021
5022
Jing Huang5fbe25c2010-10-18 17:17:23 -07005023/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005024 * uf_pub BFA uf module public functions
5025 */
5026void
5027bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5028{
5029 bfa_trc(bfa, msg->mhdr.msg_id);
5030
5031 switch (msg->mhdr.msg_id) {
5032 case BFI_UF_I2H_FRM_RCVD:
5033 uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
5034 break;
5035
5036 default:
5037 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08005038 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005039 }
5040}
5041
5042