blob: 46e8cdd31db9ba93cf94a632184b421254d735de [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) {
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07001937 case BFI_LPS_I2H_LOGIN_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001938 bfa_lps_login_rsp(bfa, msg.login_rsp);
1939 break;
1940
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07001941 case BFI_LPS_I2H_LOGOUT_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001942 bfa_lps_logout_rsp(bfa, msg.logout_rsp);
1943 break;
1944
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07001945 case BFI_LPS_I2H_CVL_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001946 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
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003311 if (bfa_fcport_is_pbcdisabled(bfa))
3312 bfa->modules.port.pbc_disabled = BFA_TRUE;
3313
Jing Huangd4b671c2010-12-26 21:46:35 -08003314 WARN_ON(!fcport->cfg.maxfrsize);
3315 WARN_ON(!fcport->cfg.rx_bbcredit);
3316 WARN_ON(!fcport->speed_sup);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003317}
3318
Jing Huang5fbe25c2010-10-18 17:17:23 -07003319/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003320 * Firmware message handler.
3321 */
3322void
3323bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
3324{
3325 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3326 union bfi_fcport_i2h_msg_u i2hmsg;
3327
3328 i2hmsg.msg = msg;
3329 fcport->event_arg.i2hmsg = i2hmsg;
3330
3331 bfa_trc(bfa, msg->mhdr.msg_id);
3332 bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
3333
3334 switch (msg->mhdr.msg_id) {
3335 case BFI_FCPORT_I2H_ENABLE_RSP:
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003336 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
3337
3338 if (fcport->use_flash_cfg) {
3339 fcport->cfg = i2hmsg.penable_rsp->port_cfg;
3340 fcport->cfg.maxfrsize =
3341 cpu_to_be16(fcport->cfg.maxfrsize);
3342 fcport->cfg.path_tov =
3343 cpu_to_be16(fcport->cfg.path_tov);
3344 fcport->cfg.q_depth =
3345 cpu_to_be16(fcport->cfg.q_depth);
3346
3347 if (fcport->cfg.trunked)
3348 fcport->trunk.attr.state =
3349 BFA_TRUNK_OFFLINE;
3350 else
3351 fcport->trunk.attr.state =
3352 BFA_TRUNK_DISABLED;
3353 fcport->use_flash_cfg = BFA_FALSE;
3354 }
3355
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003356 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003357 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003358 break;
3359
3360 case BFI_FCPORT_I2H_DISABLE_RSP:
3361 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
3362 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
3363 break;
3364
3365 case BFI_FCPORT_I2H_EVENT:
3366 if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
3367 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
3368 else
3369 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
3370 break;
3371
3372 case BFI_FCPORT_I2H_TRUNK_SCN:
3373 bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
3374 break;
3375
3376 case BFI_FCPORT_I2H_STATS_GET_RSP:
3377 /*
3378 * check for timer pop before processing the rsp
3379 */
3380 if (fcport->stats_busy == BFA_FALSE ||
3381 fcport->stats_status == BFA_STATUS_ETIMER)
3382 break;
3383
3384 bfa_timer_stop(&fcport->timer);
3385 fcport->stats_status = i2hmsg.pstatsget_rsp->status;
3386 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3387 __bfa_cb_fcport_stats_get, fcport);
3388 break;
3389
3390 case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
3391 /*
3392 * check for timer pop before processing the rsp
3393 */
3394 if (fcport->stats_busy == BFA_FALSE ||
3395 fcport->stats_status == BFA_STATUS_ETIMER)
3396 break;
3397
3398 bfa_timer_stop(&fcport->timer);
3399 fcport->stats_status = BFA_STATUS_OK;
3400 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3401 __bfa_cb_fcport_stats_clr, fcport);
3402 break;
3403
3404 case BFI_FCPORT_I2H_ENABLE_AEN:
3405 bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
3406 break;
3407
3408 case BFI_FCPORT_I2H_DISABLE_AEN:
3409 bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
3410 break;
3411
3412 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08003413 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003414 break;
3415 }
3416}
3417
Jing Huang5fbe25c2010-10-18 17:17:23 -07003418/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003419 * Registered callback for port events.
3420 */
3421void
3422bfa_fcport_event_register(struct bfa_s *bfa,
3423 void (*cbfn) (void *cbarg,
3424 enum bfa_port_linkstate event),
3425 void *cbarg)
3426{
3427 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3428
3429 fcport->event_cbfn = cbfn;
3430 fcport->event_cbarg = cbarg;
3431}
3432
3433bfa_status_t
3434bfa_fcport_enable(struct bfa_s *bfa)
3435{
3436 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3437
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003438 if (bfa_fcport_is_pbcdisabled(bfa))
3439 return BFA_STATUS_PBC;
3440
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003441 if (bfa_ioc_is_disabled(&bfa->ioc))
3442 return BFA_STATUS_IOC_DISABLED;
3443
3444 if (fcport->diag_busy)
3445 return BFA_STATUS_DIAG_BUSY;
3446
3447 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
3448 return BFA_STATUS_OK;
3449}
3450
3451bfa_status_t
3452bfa_fcport_disable(struct bfa_s *bfa)
3453{
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003454 if (bfa_fcport_is_pbcdisabled(bfa))
3455 return BFA_STATUS_PBC;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003456
3457 if (bfa_ioc_is_disabled(&bfa->ioc))
3458 return BFA_STATUS_IOC_DISABLED;
3459
3460 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
3461 return BFA_STATUS_OK;
3462}
3463
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003464/* If PBC is disabled on port, return error */
3465bfa_status_t
3466bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
3467{
3468 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3469 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
3470 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
3471
3472 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
3473 bfa_trc(bfa, fcport->pwwn);
3474 return BFA_STATUS_PBC;
3475 }
3476 return BFA_STATUS_OK;
3477}
3478
Jing Huang5fbe25c2010-10-18 17:17:23 -07003479/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003480 * Configure port speed.
3481 */
3482bfa_status_t
3483bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3484{
3485 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3486
3487 bfa_trc(bfa, speed);
3488
3489 if (fcport->cfg.trunked == BFA_TRUE)
3490 return BFA_STATUS_TRUNK_ENABLED;
3491 if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
3492 bfa_trc(bfa, fcport->speed_sup);
3493 return BFA_STATUS_UNSUPP_SPEED;
3494 }
3495
3496 fcport->cfg.speed = speed;
3497
3498 return BFA_STATUS_OK;
3499}
3500
Jing Huang5fbe25c2010-10-18 17:17:23 -07003501/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003502 * Get current speed.
3503 */
3504enum bfa_port_speed
3505bfa_fcport_get_speed(struct bfa_s *bfa)
3506{
3507 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3508
3509 return fcport->speed;
3510}
3511
Jing Huang5fbe25c2010-10-18 17:17:23 -07003512/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003513 * Configure port topology.
3514 */
3515bfa_status_t
3516bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
3517{
3518 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3519
3520 bfa_trc(bfa, topology);
3521 bfa_trc(bfa, fcport->cfg.topology);
3522
3523 switch (topology) {
3524 case BFA_PORT_TOPOLOGY_P2P:
3525 case BFA_PORT_TOPOLOGY_LOOP:
3526 case BFA_PORT_TOPOLOGY_AUTO:
3527 break;
3528
3529 default:
3530 return BFA_STATUS_EINVAL;
3531 }
3532
3533 fcport->cfg.topology = topology;
3534 return BFA_STATUS_OK;
3535}
3536
Jing Huang5fbe25c2010-10-18 17:17:23 -07003537/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003538 * Get current topology.
3539 */
3540enum bfa_port_topology
3541bfa_fcport_get_topology(struct bfa_s *bfa)
3542{
3543 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3544
3545 return fcport->topology;
3546}
3547
3548bfa_status_t
3549bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
3550{
3551 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3552
3553 bfa_trc(bfa, alpa);
3554 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3555 bfa_trc(bfa, fcport->cfg.hardalpa);
3556
3557 fcport->cfg.cfg_hardalpa = BFA_TRUE;
3558 fcport->cfg.hardalpa = alpa;
3559
3560 return BFA_STATUS_OK;
3561}
3562
3563bfa_status_t
3564bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
3565{
3566 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3567
3568 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3569 bfa_trc(bfa, fcport->cfg.hardalpa);
3570
3571 fcport->cfg.cfg_hardalpa = BFA_FALSE;
3572 return BFA_STATUS_OK;
3573}
3574
3575bfa_boolean_t
3576bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
3577{
3578 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3579
3580 *alpa = fcport->cfg.hardalpa;
3581 return fcport->cfg.cfg_hardalpa;
3582}
3583
3584u8
3585bfa_fcport_get_myalpa(struct bfa_s *bfa)
3586{
3587 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3588
3589 return fcport->myalpa;
3590}
3591
3592bfa_status_t
3593bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
3594{
3595 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3596
3597 bfa_trc(bfa, maxfrsize);
3598 bfa_trc(bfa, fcport->cfg.maxfrsize);
3599
3600 /* with in range */
3601 if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
3602 return BFA_STATUS_INVLD_DFSZ;
3603
3604 /* power of 2, if not the max frame size of 2112 */
3605 if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
3606 return BFA_STATUS_INVLD_DFSZ;
3607
3608 fcport->cfg.maxfrsize = maxfrsize;
3609 return BFA_STATUS_OK;
3610}
3611
3612u16
3613bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
3614{
3615 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3616
3617 return fcport->cfg.maxfrsize;
3618}
3619
3620u8
3621bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
3622{
3623 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3624
3625 return fcport->cfg.rx_bbcredit;
3626}
3627
3628void
3629bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
3630{
3631 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3632
3633 fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
3634 bfa_fcport_send_txcredit(fcport);
3635}
3636
Jing Huang5fbe25c2010-10-18 17:17:23 -07003637/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003638 * Get port attributes.
3639 */
3640
3641wwn_t
3642bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
3643{
3644 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3645 if (node)
3646 return fcport->nwwn;
3647 else
3648 return fcport->pwwn;
3649}
3650
3651void
3652bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3653{
3654 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3655
Jing Huang6a18b162010-10-18 17:08:54 -07003656 memset(attr, 0, sizeof(struct bfa_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003657
3658 attr->nwwn = fcport->nwwn;
3659 attr->pwwn = fcport->pwwn;
3660
Maggie Zhangf7f738122010-12-09 19:08:43 -08003661 attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
3662 attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003663
Jing Huang6a18b162010-10-18 17:08:54 -07003664 memcpy(&attr->pport_cfg, &fcport->cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003665 sizeof(struct bfa_port_cfg_s));
3666 /* speed attributes */
3667 attr->pport_cfg.speed = fcport->cfg.speed;
3668 attr->speed_supported = fcport->speed_sup;
3669 attr->speed = fcport->speed;
3670 attr->cos_supported = FC_CLASS_3;
3671
3672 /* topology attributes */
3673 attr->pport_cfg.topology = fcport->cfg.topology;
3674 attr->topology = fcport->topology;
3675 attr->pport_cfg.trunked = fcport->cfg.trunked;
3676
3677 /* beacon attributes */
3678 attr->beacon = fcport->beacon;
3679 attr->link_e2e_beacon = fcport->link_e2e_beacon;
Maggie Zhangf7f738122010-12-09 19:08:43 -08003680 attr->plog_enabled = (bfa_boolean_t)fcport->bfa->plog->plog_enabled;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003681 attr->io_profile = bfa_fcpim_get_io_profile(fcport->bfa);
3682
3683 attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
3684 attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
3685 attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003686
3687 /* PBC Disabled State */
3688 if (bfa_fcport_is_pbcdisabled(bfa))
3689 attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
3690 else {
3691 if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
3692 attr->port_state = BFA_PORT_ST_IOCDIS;
3693 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
3694 attr->port_state = BFA_PORT_ST_FWMISMATCH;
3695 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003696
3697 /* FCoE vlan */
3698 attr->fcoe_vlan = fcport->fcoe_vlan;
3699}
3700
3701#define BFA_FCPORT_STATS_TOV 1000
3702
Jing Huang5fbe25c2010-10-18 17:17:23 -07003703/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003704 * Fetch port statistics (FCQoS or FCoE).
3705 */
3706bfa_status_t
3707bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
3708 bfa_cb_port_t cbfn, void *cbarg)
3709{
3710 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3711
3712 if (fcport->stats_busy) {
3713 bfa_trc(bfa, fcport->stats_busy);
3714 return BFA_STATUS_DEVBUSY;
3715 }
3716
3717 fcport->stats_busy = BFA_TRUE;
3718 fcport->stats_ret = stats;
3719 fcport->stats_cbfn = cbfn;
3720 fcport->stats_cbarg = cbarg;
3721
3722 bfa_fcport_send_stats_get(fcport);
3723
3724 bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_get_timeout,
3725 fcport, BFA_FCPORT_STATS_TOV);
3726 return BFA_STATUS_OK;
3727}
3728
Jing Huang5fbe25c2010-10-18 17:17:23 -07003729/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003730 * Reset port statistics (FCQoS or FCoE).
3731 */
3732bfa_status_t
3733bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_port_t cbfn, void *cbarg)
3734{
3735 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3736
3737 if (fcport->stats_busy) {
3738 bfa_trc(bfa, fcport->stats_busy);
3739 return BFA_STATUS_DEVBUSY;
3740 }
3741
3742 fcport->stats_busy = BFA_TRUE;
3743 fcport->stats_cbfn = cbfn;
3744 fcport->stats_cbarg = cbarg;
3745
3746 bfa_fcport_send_stats_clear(fcport);
3747
3748 bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_clr_timeout,
3749 fcport, BFA_FCPORT_STATS_TOV);
3750 return BFA_STATUS_OK;
3751}
3752
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003753
Jing Huang5fbe25c2010-10-18 17:17:23 -07003754/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003755 * Fetch port attributes.
3756 */
3757bfa_boolean_t
3758bfa_fcport_is_disabled(struct bfa_s *bfa)
3759{
3760 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3761
3762 return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
3763 BFA_PORT_ST_DISABLED;
3764
3765}
3766
3767bfa_boolean_t
3768bfa_fcport_is_ratelim(struct bfa_s *bfa)
3769{
3770 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3771
3772 return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
3773
3774}
3775
Jing Huang5fbe25c2010-10-18 17:17:23 -07003776/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003777 * Get default minimum ratelim speed
3778 */
3779enum bfa_port_speed
3780bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
3781{
3782 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3783
3784 bfa_trc(bfa, fcport->cfg.trl_def_speed);
3785 return fcport->cfg.trl_def_speed;
3786
3787}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003788
3789bfa_boolean_t
3790bfa_fcport_is_linkup(struct bfa_s *bfa)
3791{
3792 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3793
3794 return (!fcport->cfg.trunked &&
3795 bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
3796 (fcport->cfg.trunked &&
3797 fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
3798}
3799
3800bfa_boolean_t
3801bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
3802{
3803 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3804
3805 return fcport->cfg.qos_enabled;
3806}
3807
Jing Huang5fbe25c2010-10-18 17:17:23 -07003808/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003809 * Rport State machine functions
3810 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07003811/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003812 * Beginning state, only online event expected.
3813 */
3814static void
3815bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
3816{
3817 bfa_trc(rp->bfa, rp->rport_tag);
3818 bfa_trc(rp->bfa, event);
3819
3820 switch (event) {
3821 case BFA_RPORT_SM_CREATE:
3822 bfa_stats(rp, sm_un_cr);
3823 bfa_sm_set_state(rp, bfa_rport_sm_created);
3824 break;
3825
3826 default:
3827 bfa_stats(rp, sm_un_unexp);
3828 bfa_sm_fault(rp->bfa, event);
3829 }
3830}
3831
3832static void
3833bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
3834{
3835 bfa_trc(rp->bfa, rp->rport_tag);
3836 bfa_trc(rp->bfa, event);
3837
3838 switch (event) {
3839 case BFA_RPORT_SM_ONLINE:
3840 bfa_stats(rp, sm_cr_on);
3841 if (bfa_rport_send_fwcreate(rp))
3842 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
3843 else
3844 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
3845 break;
3846
3847 case BFA_RPORT_SM_DELETE:
3848 bfa_stats(rp, sm_cr_del);
3849 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
3850 bfa_rport_free(rp);
3851 break;
3852
3853 case BFA_RPORT_SM_HWFAIL:
3854 bfa_stats(rp, sm_cr_hwf);
3855 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3856 break;
3857
3858 default:
3859 bfa_stats(rp, sm_cr_unexp);
3860 bfa_sm_fault(rp->bfa, event);
3861 }
3862}
3863
Jing Huang5fbe25c2010-10-18 17:17:23 -07003864/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003865 * Waiting for rport create response from firmware.
3866 */
3867static void
3868bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
3869{
3870 bfa_trc(rp->bfa, rp->rport_tag);
3871 bfa_trc(rp->bfa, event);
3872
3873 switch (event) {
3874 case BFA_RPORT_SM_FWRSP:
3875 bfa_stats(rp, sm_fwc_rsp);
3876 bfa_sm_set_state(rp, bfa_rport_sm_online);
3877 bfa_rport_online_cb(rp);
3878 break;
3879
3880 case BFA_RPORT_SM_DELETE:
3881 bfa_stats(rp, sm_fwc_del);
3882 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
3883 break;
3884
3885 case BFA_RPORT_SM_OFFLINE:
3886 bfa_stats(rp, sm_fwc_off);
3887 bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
3888 break;
3889
3890 case BFA_RPORT_SM_HWFAIL:
3891 bfa_stats(rp, sm_fwc_hwf);
3892 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3893 break;
3894
3895 default:
3896 bfa_stats(rp, sm_fwc_unexp);
3897 bfa_sm_fault(rp->bfa, event);
3898 }
3899}
3900
Jing Huang5fbe25c2010-10-18 17:17:23 -07003901/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003902 * Request queue is full, awaiting queue resume to send create request.
3903 */
3904static void
3905bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
3906{
3907 bfa_trc(rp->bfa, rp->rport_tag);
3908 bfa_trc(rp->bfa, event);
3909
3910 switch (event) {
3911 case BFA_RPORT_SM_QRESUME:
3912 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
3913 bfa_rport_send_fwcreate(rp);
3914 break;
3915
3916 case BFA_RPORT_SM_DELETE:
3917 bfa_stats(rp, sm_fwc_del);
3918 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
3919 bfa_reqq_wcancel(&rp->reqq_wait);
3920 bfa_rport_free(rp);
3921 break;
3922
3923 case BFA_RPORT_SM_OFFLINE:
3924 bfa_stats(rp, sm_fwc_off);
3925 bfa_sm_set_state(rp, bfa_rport_sm_offline);
3926 bfa_reqq_wcancel(&rp->reqq_wait);
3927 bfa_rport_offline_cb(rp);
3928 break;
3929
3930 case BFA_RPORT_SM_HWFAIL:
3931 bfa_stats(rp, sm_fwc_hwf);
3932 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3933 bfa_reqq_wcancel(&rp->reqq_wait);
3934 break;
3935
3936 default:
3937 bfa_stats(rp, sm_fwc_unexp);
3938 bfa_sm_fault(rp->bfa, event);
3939 }
3940}
3941
Jing Huang5fbe25c2010-10-18 17:17:23 -07003942/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003943 * Online state - normal parking state.
3944 */
3945static void
3946bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
3947{
3948 struct bfi_rport_qos_scn_s *qos_scn;
3949
3950 bfa_trc(rp->bfa, rp->rport_tag);
3951 bfa_trc(rp->bfa, event);
3952
3953 switch (event) {
3954 case BFA_RPORT_SM_OFFLINE:
3955 bfa_stats(rp, sm_on_off);
3956 if (bfa_rport_send_fwdelete(rp))
3957 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
3958 else
3959 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
3960 break;
3961
3962 case BFA_RPORT_SM_DELETE:
3963 bfa_stats(rp, sm_on_del);
3964 if (bfa_rport_send_fwdelete(rp))
3965 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
3966 else
3967 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
3968 break;
3969
3970 case BFA_RPORT_SM_HWFAIL:
3971 bfa_stats(rp, sm_on_hwf);
3972 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
3973 break;
3974
3975 case BFA_RPORT_SM_SET_SPEED:
3976 bfa_rport_send_fwspeed(rp);
3977 break;
3978
3979 case BFA_RPORT_SM_QOS_SCN:
3980 qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
3981 rp->qos_attr = qos_scn->new_qos_attr;
3982 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
3983 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
3984 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
3985 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
3986
3987 qos_scn->old_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07003988 be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003989 qos_scn->new_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07003990 be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003991
3992 if (qos_scn->old_qos_attr.qos_flow_id !=
3993 qos_scn->new_qos_attr.qos_flow_id)
3994 bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
3995 qos_scn->old_qos_attr,
3996 qos_scn->new_qos_attr);
3997 if (qos_scn->old_qos_attr.qos_priority !=
3998 qos_scn->new_qos_attr.qos_priority)
3999 bfa_cb_rport_qos_scn_prio(rp->rport_drv,
4000 qos_scn->old_qos_attr,
4001 qos_scn->new_qos_attr);
4002 break;
4003
4004 default:
4005 bfa_stats(rp, sm_on_unexp);
4006 bfa_sm_fault(rp->bfa, event);
4007 }
4008}
4009
Jing Huang5fbe25c2010-10-18 17:17:23 -07004010/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004011 * Firmware rport is being deleted - awaiting f/w response.
4012 */
4013static void
4014bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
4015{
4016 bfa_trc(rp->bfa, rp->rport_tag);
4017 bfa_trc(rp->bfa, event);
4018
4019 switch (event) {
4020 case BFA_RPORT_SM_FWRSP:
4021 bfa_stats(rp, sm_fwd_rsp);
4022 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4023 bfa_rport_offline_cb(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);
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_rport_offline_cb(rp);
4035 break;
4036
4037 default:
4038 bfa_stats(rp, sm_fwd_unexp);
4039 bfa_sm_fault(rp->bfa, event);
4040 }
4041}
4042
4043static void
4044bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4045{
4046 bfa_trc(rp->bfa, rp->rport_tag);
4047 bfa_trc(rp->bfa, event);
4048
4049 switch (event) {
4050 case BFA_RPORT_SM_QRESUME:
4051 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4052 bfa_rport_send_fwdelete(rp);
4053 break;
4054
4055 case BFA_RPORT_SM_DELETE:
4056 bfa_stats(rp, sm_fwd_del);
4057 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4058 break;
4059
4060 case BFA_RPORT_SM_HWFAIL:
4061 bfa_stats(rp, sm_fwd_hwf);
4062 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4063 bfa_reqq_wcancel(&rp->reqq_wait);
4064 bfa_rport_offline_cb(rp);
4065 break;
4066
4067 default:
4068 bfa_stats(rp, sm_fwd_unexp);
4069 bfa_sm_fault(rp->bfa, event);
4070 }
4071}
4072
Jing Huang5fbe25c2010-10-18 17:17:23 -07004073/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004074 * Offline state.
4075 */
4076static void
4077bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
4078{
4079 bfa_trc(rp->bfa, rp->rport_tag);
4080 bfa_trc(rp->bfa, event);
4081
4082 switch (event) {
4083 case BFA_RPORT_SM_DELETE:
4084 bfa_stats(rp, sm_off_del);
4085 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4086 bfa_rport_free(rp);
4087 break;
4088
4089 case BFA_RPORT_SM_ONLINE:
4090 bfa_stats(rp, sm_off_on);
4091 if (bfa_rport_send_fwcreate(rp))
4092 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4093 else
4094 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4095 break;
4096
4097 case BFA_RPORT_SM_HWFAIL:
4098 bfa_stats(rp, sm_off_hwf);
4099 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4100 break;
4101
4102 default:
4103 bfa_stats(rp, sm_off_unexp);
4104 bfa_sm_fault(rp->bfa, event);
4105 }
4106}
4107
Jing Huang5fbe25c2010-10-18 17:17:23 -07004108/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004109 * Rport is deleted, waiting for firmware response to delete.
4110 */
4111static void
4112bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
4113{
4114 bfa_trc(rp->bfa, rp->rport_tag);
4115 bfa_trc(rp->bfa, event);
4116
4117 switch (event) {
4118 case BFA_RPORT_SM_FWRSP:
4119 bfa_stats(rp, sm_del_fwrsp);
4120 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4121 bfa_rport_free(rp);
4122 break;
4123
4124 case BFA_RPORT_SM_HWFAIL:
4125 bfa_stats(rp, sm_del_hwf);
4126 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4127 bfa_rport_free(rp);
4128 break;
4129
4130 default:
4131 bfa_sm_fault(rp->bfa, event);
4132 }
4133}
4134
4135static void
4136bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, 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_QRESUME:
4143 bfa_stats(rp, sm_del_fwrsp);
4144 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4145 bfa_rport_send_fwdelete(rp);
4146 break;
4147
4148 case BFA_RPORT_SM_HWFAIL:
4149 bfa_stats(rp, sm_del_hwf);
4150 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4151 bfa_reqq_wcancel(&rp->reqq_wait);
4152 bfa_rport_free(rp);
4153 break;
4154
4155 default:
4156 bfa_sm_fault(rp->bfa, event);
4157 }
4158}
4159
Jing Huang5fbe25c2010-10-18 17:17:23 -07004160/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004161 * Waiting for rport create response from firmware. A delete is pending.
4162 */
4163static void
4164bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
4165 enum bfa_rport_event event)
4166{
4167 bfa_trc(rp->bfa, rp->rport_tag);
4168 bfa_trc(rp->bfa, event);
4169
4170 switch (event) {
4171 case BFA_RPORT_SM_FWRSP:
4172 bfa_stats(rp, sm_delp_fwrsp);
4173 if (bfa_rport_send_fwdelete(rp))
4174 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4175 else
4176 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4177 break;
4178
4179 case BFA_RPORT_SM_HWFAIL:
4180 bfa_stats(rp, sm_delp_hwf);
4181 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4182 bfa_rport_free(rp);
4183 break;
4184
4185 default:
4186 bfa_stats(rp, sm_delp_unexp);
4187 bfa_sm_fault(rp->bfa, event);
4188 }
4189}
4190
Jing Huang5fbe25c2010-10-18 17:17:23 -07004191/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004192 * Waiting for rport create response from firmware. Rport offline is pending.
4193 */
4194static void
4195bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
4196 enum bfa_rport_event event)
4197{
4198 bfa_trc(rp->bfa, rp->rport_tag);
4199 bfa_trc(rp->bfa, event);
4200
4201 switch (event) {
4202 case BFA_RPORT_SM_FWRSP:
4203 bfa_stats(rp, sm_offp_fwrsp);
4204 if (bfa_rport_send_fwdelete(rp))
4205 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4206 else
4207 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4208 break;
4209
4210 case BFA_RPORT_SM_DELETE:
4211 bfa_stats(rp, sm_offp_del);
4212 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4213 break;
4214
4215 case BFA_RPORT_SM_HWFAIL:
4216 bfa_stats(rp, sm_offp_hwf);
4217 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4218 break;
4219
4220 default:
4221 bfa_stats(rp, sm_offp_unexp);
4222 bfa_sm_fault(rp->bfa, event);
4223 }
4224}
4225
Jing Huang5fbe25c2010-10-18 17:17:23 -07004226/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004227 * IOC h/w failed.
4228 */
4229static void
4230bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
4231{
4232 bfa_trc(rp->bfa, rp->rport_tag);
4233 bfa_trc(rp->bfa, event);
4234
4235 switch (event) {
4236 case BFA_RPORT_SM_OFFLINE:
4237 bfa_stats(rp, sm_iocd_off);
4238 bfa_rport_offline_cb(rp);
4239 break;
4240
4241 case BFA_RPORT_SM_DELETE:
4242 bfa_stats(rp, sm_iocd_del);
4243 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4244 bfa_rport_free(rp);
4245 break;
4246
4247 case BFA_RPORT_SM_ONLINE:
4248 bfa_stats(rp, sm_iocd_on);
4249 if (bfa_rport_send_fwcreate(rp))
4250 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4251 else
4252 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4253 break;
4254
4255 case BFA_RPORT_SM_HWFAIL:
4256 break;
4257
4258 default:
4259 bfa_stats(rp, sm_iocd_unexp);
4260 bfa_sm_fault(rp->bfa, event);
4261 }
4262}
4263
4264
4265
Jing Huang5fbe25c2010-10-18 17:17:23 -07004266/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004267 * bfa_rport_private BFA rport private functions
4268 */
4269
4270static void
4271__bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
4272{
4273 struct bfa_rport_s *rp = cbarg;
4274
4275 if (complete)
4276 bfa_cb_rport_online(rp->rport_drv);
4277}
4278
4279static void
4280__bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
4281{
4282 struct bfa_rport_s *rp = cbarg;
4283
4284 if (complete)
4285 bfa_cb_rport_offline(rp->rport_drv);
4286}
4287
4288static void
4289bfa_rport_qresume(void *cbarg)
4290{
4291 struct bfa_rport_s *rp = cbarg;
4292
4293 bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
4294}
4295
4296static void
4297bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
4298 u32 *dm_len)
4299{
4300 if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
4301 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
4302
4303 *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s);
4304}
4305
4306static void
4307bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4308 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
4309{
4310 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4311 struct bfa_rport_s *rp;
4312 u16 i;
4313
4314 INIT_LIST_HEAD(&mod->rp_free_q);
4315 INIT_LIST_HEAD(&mod->rp_active_q);
4316
4317 rp = (struct bfa_rport_s *) bfa_meminfo_kva(meminfo);
4318 mod->rps_list = rp;
4319 mod->num_rports = cfg->fwcfg.num_rports;
4320
Jing Huangd4b671c2010-12-26 21:46:35 -08004321 WARN_ON(!mod->num_rports ||
4322 (mod->num_rports & (mod->num_rports - 1)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004323
4324 for (i = 0; i < mod->num_rports; i++, rp++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004325 memset(rp, 0, sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004326 rp->bfa = bfa;
4327 rp->rport_tag = i;
4328 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4329
Jing Huang5fbe25c2010-10-18 17:17:23 -07004330 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004331 * - is unused
4332 */
4333 if (i)
4334 list_add_tail(&rp->qe, &mod->rp_free_q);
4335
4336 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
4337 }
4338
Jing Huang5fbe25c2010-10-18 17:17:23 -07004339 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004340 * consume memory
4341 */
4342 bfa_meminfo_kva(meminfo) = (u8 *) rp;
4343}
4344
4345static void
4346bfa_rport_detach(struct bfa_s *bfa)
4347{
4348}
4349
4350static void
4351bfa_rport_start(struct bfa_s *bfa)
4352{
4353}
4354
4355static void
4356bfa_rport_stop(struct bfa_s *bfa)
4357{
4358}
4359
4360static void
4361bfa_rport_iocdisable(struct bfa_s *bfa)
4362{
4363 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4364 struct bfa_rport_s *rport;
4365 struct list_head *qe, *qen;
4366
4367 list_for_each_safe(qe, qen, &mod->rp_active_q) {
4368 rport = (struct bfa_rport_s *) qe;
4369 bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
4370 }
4371}
4372
4373static struct bfa_rport_s *
4374bfa_rport_alloc(struct bfa_rport_mod_s *mod)
4375{
4376 struct bfa_rport_s *rport;
4377
4378 bfa_q_deq(&mod->rp_free_q, &rport);
4379 if (rport)
4380 list_add_tail(&rport->qe, &mod->rp_active_q);
4381
4382 return rport;
4383}
4384
4385static void
4386bfa_rport_free(struct bfa_rport_s *rport)
4387{
4388 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
4389
Jing Huangd4b671c2010-12-26 21:46:35 -08004390 WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004391 list_del(&rport->qe);
4392 list_add_tail(&rport->qe, &mod->rp_free_q);
4393}
4394
4395static bfa_boolean_t
4396bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4397{
4398 struct bfi_rport_create_req_s *m;
4399
Jing Huang5fbe25c2010-10-18 17:17:23 -07004400 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004401 * check for room in queue to send request now
4402 */
4403 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4404 if (!m) {
4405 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4406 return BFA_FALSE;
4407 }
4408
4409 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
4410 bfa_lpuid(rp->bfa));
4411 m->bfa_handle = rp->rport_tag;
Jing Huangba816ea2010-10-18 17:10:50 -07004412 m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004413 m->pid = rp->rport_info.pid;
4414 m->lp_tag = rp->rport_info.lp_tag;
4415 m->local_pid = rp->rport_info.local_pid;
4416 m->fc_class = rp->rport_info.fc_class;
4417 m->vf_en = rp->rport_info.vf_en;
4418 m->vf_id = rp->rport_info.vf_id;
4419 m->cisc = rp->rport_info.cisc;
4420
Jing Huang5fbe25c2010-10-18 17:17:23 -07004421 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004422 * queue I/O message to firmware
4423 */
4424 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
4425 return BFA_TRUE;
4426}
4427
4428static bfa_boolean_t
4429bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4430{
4431 struct bfi_rport_delete_req_s *m;
4432
Jing Huang5fbe25c2010-10-18 17:17:23 -07004433 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004434 * check for room in queue to send request now
4435 */
4436 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4437 if (!m) {
4438 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4439 return BFA_FALSE;
4440 }
4441
4442 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
4443 bfa_lpuid(rp->bfa));
4444 m->fw_handle = rp->fw_handle;
4445
Jing Huang5fbe25c2010-10-18 17:17:23 -07004446 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004447 * queue I/O message to firmware
4448 */
4449 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
4450 return BFA_TRUE;
4451}
4452
4453static bfa_boolean_t
4454bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4455{
4456 struct bfa_rport_speed_req_s *m;
4457
Jing Huang5fbe25c2010-10-18 17:17:23 -07004458 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004459 * check for room in queue to send request now
4460 */
4461 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4462 if (!m) {
4463 bfa_trc(rp->bfa, rp->rport_info.speed);
4464 return BFA_FALSE;
4465 }
4466
4467 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
4468 bfa_lpuid(rp->bfa));
4469 m->fw_handle = rp->fw_handle;
4470 m->speed = (u8)rp->rport_info.speed;
4471
Jing Huang5fbe25c2010-10-18 17:17:23 -07004472 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004473 * queue I/O message to firmware
4474 */
4475 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
4476 return BFA_TRUE;
4477}
4478
4479
4480
Jing Huang5fbe25c2010-10-18 17:17:23 -07004481/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004482 * bfa_rport_public
4483 */
4484
Jing Huang5fbe25c2010-10-18 17:17:23 -07004485/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004486 * Rport interrupt processing.
4487 */
4488void
4489bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
4490{
4491 union bfi_rport_i2h_msg_u msg;
4492 struct bfa_rport_s *rp;
4493
4494 bfa_trc(bfa, m->mhdr.msg_id);
4495
4496 msg.msg = m;
4497
4498 switch (m->mhdr.msg_id) {
4499 case BFI_RPORT_I2H_CREATE_RSP:
4500 rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
4501 rp->fw_handle = msg.create_rsp->fw_handle;
4502 rp->qos_attr = msg.create_rsp->qos_attr;
Jing Huangd4b671c2010-12-26 21:46:35 -08004503 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004504 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4505 break;
4506
4507 case BFI_RPORT_I2H_DELETE_RSP:
4508 rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08004509 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004510 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4511 break;
4512
4513 case BFI_RPORT_I2H_QOS_SCN:
4514 rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
4515 rp->event_arg.fw_msg = msg.qos_scn_evt;
4516 bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
4517 break;
4518
4519 default:
4520 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08004521 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004522 }
4523}
4524
4525
4526
Jing Huang5fbe25c2010-10-18 17:17:23 -07004527/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004528 * bfa_rport_api
4529 */
4530
4531struct bfa_rport_s *
4532bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
4533{
4534 struct bfa_rport_s *rp;
4535
4536 rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
4537
4538 if (rp == NULL)
4539 return NULL;
4540
4541 rp->bfa = bfa;
4542 rp->rport_drv = rport_drv;
Maggie Zhangf7f738122010-12-09 19:08:43 -08004543 memset(&rp->stats, 0, sizeof(rp->stats));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004544
Jing Huangd4b671c2010-12-26 21:46:35 -08004545 WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004546 bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
4547
4548 return rp;
4549}
4550
4551void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004552bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
4553{
Jing Huangd4b671c2010-12-26 21:46:35 -08004554 WARN_ON(rport_info->max_frmsz == 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004555
Jing Huang5fbe25c2010-10-18 17:17:23 -07004556 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004557 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
4558 * responses. Default to minimum size.
4559 */
4560 if (rport_info->max_frmsz == 0) {
4561 bfa_trc(rport->bfa, rport->rport_tag);
4562 rport_info->max_frmsz = FC_MIN_PDUSZ;
4563 }
4564
Jing Huang6a18b162010-10-18 17:08:54 -07004565 rport->rport_info = *rport_info;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004566 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
4567}
4568
4569void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004570bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
4571{
Jing Huangd4b671c2010-12-26 21:46:35 -08004572 WARN_ON(speed == 0);
4573 WARN_ON(speed == BFA_PORT_SPEED_AUTO);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004574
4575 rport->rport_info.speed = speed;
4576 bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
4577}
4578
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004579
Jing Huang5fbe25c2010-10-18 17:17:23 -07004580/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004581 * SGPG related functions
4582 */
4583
Jing Huang5fbe25c2010-10-18 17:17:23 -07004584/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004585 * Compute and return memory needed by FCP(im) module.
4586 */
4587static void
4588bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
4589 u32 *dm_len)
4590{
4591 if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
4592 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
4593
4594 *km_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfa_sgpg_s);
4595 *dm_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfi_sgpg_s);
4596}
4597
4598
4599static void
4600bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4601 struct bfa_meminfo_s *minfo, struct bfa_pcidev_s *pcidev)
4602{
4603 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4604 int i;
4605 struct bfa_sgpg_s *hsgpg;
4606 struct bfi_sgpg_s *sgpg;
4607 u64 align_len;
4608
4609 union {
4610 u64 pa;
4611 union bfi_addr_u addr;
4612 } sgpg_pa, sgpg_pa_tmp;
4613
4614 INIT_LIST_HEAD(&mod->sgpg_q);
4615 INIT_LIST_HEAD(&mod->sgpg_wait_q);
4616
4617 bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
4618
4619 mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
4620 mod->sgpg_arr_pa = bfa_meminfo_dma_phys(minfo);
4621 align_len = (BFA_SGPG_ROUNDUP(mod->sgpg_arr_pa) - mod->sgpg_arr_pa);
4622 mod->sgpg_arr_pa += align_len;
4623 mod->hsgpg_arr = (struct bfa_sgpg_s *) (bfa_meminfo_kva(minfo) +
4624 align_len);
4625 mod->sgpg_arr = (struct bfi_sgpg_s *) (bfa_meminfo_dma_virt(minfo) +
4626 align_len);
4627
4628 hsgpg = mod->hsgpg_arr;
4629 sgpg = mod->sgpg_arr;
4630 sgpg_pa.pa = mod->sgpg_arr_pa;
4631 mod->free_sgpgs = mod->num_sgpgs;
4632
Jing Huangd4b671c2010-12-26 21:46:35 -08004633 WARN_ON(sgpg_pa.pa & (sizeof(struct bfi_sgpg_s) - 1));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004634
4635 for (i = 0; i < mod->num_sgpgs; i++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004636 memset(hsgpg, 0, sizeof(*hsgpg));
4637 memset(sgpg, 0, sizeof(*sgpg));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004638
4639 hsgpg->sgpg = sgpg;
4640 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
4641 hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
4642 list_add_tail(&hsgpg->qe, &mod->sgpg_q);
4643
4644 hsgpg++;
4645 sgpg++;
4646 sgpg_pa.pa += sizeof(struct bfi_sgpg_s);
4647 }
4648
4649 bfa_meminfo_kva(minfo) = (u8 *) hsgpg;
4650 bfa_meminfo_dma_virt(minfo) = (u8 *) sgpg;
4651 bfa_meminfo_dma_phys(minfo) = sgpg_pa.pa;
4652}
4653
4654static void
4655bfa_sgpg_detach(struct bfa_s *bfa)
4656{
4657}
4658
4659static void
4660bfa_sgpg_start(struct bfa_s *bfa)
4661{
4662}
4663
4664static void
4665bfa_sgpg_stop(struct bfa_s *bfa)
4666{
4667}
4668
4669static void
4670bfa_sgpg_iocdisable(struct bfa_s *bfa)
4671{
4672}
4673
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004674bfa_status_t
4675bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
4676{
4677 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4678 struct bfa_sgpg_s *hsgpg;
4679 int i;
4680
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004681 if (mod->free_sgpgs < nsgpgs)
4682 return BFA_STATUS_ENOMEM;
4683
4684 for (i = 0; i < nsgpgs; i++) {
4685 bfa_q_deq(&mod->sgpg_q, &hsgpg);
Jing Huangd4b671c2010-12-26 21:46:35 -08004686 WARN_ON(!hsgpg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004687 list_add_tail(&hsgpg->qe, sgpg_q);
4688 }
4689
4690 mod->free_sgpgs -= nsgpgs;
4691 return BFA_STATUS_OK;
4692}
4693
4694void
4695bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
4696{
4697 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4698 struct bfa_sgpg_wqe_s *wqe;
4699
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004700 mod->free_sgpgs += nsgpg;
Jing Huangd4b671c2010-12-26 21:46:35 -08004701 WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004702
4703 list_splice_tail_init(sgpg_q, &mod->sgpg_q);
4704
4705 if (list_empty(&mod->sgpg_wait_q))
4706 return;
4707
Jing Huang5fbe25c2010-10-18 17:17:23 -07004708 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004709 * satisfy as many waiting requests as possible
4710 */
4711 do {
4712 wqe = bfa_q_first(&mod->sgpg_wait_q);
4713 if (mod->free_sgpgs < wqe->nsgpg)
4714 nsgpg = mod->free_sgpgs;
4715 else
4716 nsgpg = wqe->nsgpg;
4717 bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
4718 wqe->nsgpg -= nsgpg;
4719 if (wqe->nsgpg == 0) {
4720 list_del(&wqe->qe);
4721 wqe->cbfn(wqe->cbarg);
4722 }
4723 } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
4724}
4725
4726void
4727bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
4728{
4729 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4730
Jing Huangd4b671c2010-12-26 21:46:35 -08004731 WARN_ON(nsgpg <= 0);
4732 WARN_ON(nsgpg <= mod->free_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004733
4734 wqe->nsgpg_total = wqe->nsgpg = nsgpg;
4735
Jing Huang5fbe25c2010-10-18 17:17:23 -07004736 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004737 * allocate any left to this one first
4738 */
4739 if (mod->free_sgpgs) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07004740 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004741 * no one else is waiting for SGPG
4742 */
Jing Huangd4b671c2010-12-26 21:46:35 -08004743 WARN_ON(!list_empty(&mod->sgpg_wait_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004744 list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
4745 wqe->nsgpg -= mod->free_sgpgs;
4746 mod->free_sgpgs = 0;
4747 }
4748
4749 list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
4750}
4751
4752void
4753bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
4754{
4755 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4756
Jing Huangd4b671c2010-12-26 21:46:35 -08004757 WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004758 list_del(&wqe->qe);
4759
4760 if (wqe->nsgpg_total != wqe->nsgpg)
4761 bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
4762 wqe->nsgpg_total - wqe->nsgpg);
4763}
4764
4765void
4766bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
4767 void *cbarg)
4768{
4769 INIT_LIST_HEAD(&wqe->sgpg_q);
4770 wqe->cbfn = cbfn;
4771 wqe->cbarg = cbarg;
4772}
4773
Jing Huang5fbe25c2010-10-18 17:17:23 -07004774/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004775 * UF related functions
4776 */
4777/*
4778 *****************************************************************************
4779 * Internal functions
4780 *****************************************************************************
4781 */
4782static void
4783__bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
4784{
4785 struct bfa_uf_s *uf = cbarg;
4786 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
4787
4788 if (complete)
4789 ufm->ufrecv(ufm->cbarg, uf);
4790}
4791
4792static void
4793claim_uf_pbs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4794{
4795 u32 uf_pb_tot_sz;
4796
4797 ufm->uf_pbs_kva = (struct bfa_uf_buf_s *) bfa_meminfo_dma_virt(mi);
4798 ufm->uf_pbs_pa = bfa_meminfo_dma_phys(mi);
4799 uf_pb_tot_sz = BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * ufm->num_ufs),
4800 BFA_DMA_ALIGN_SZ);
4801
4802 bfa_meminfo_dma_virt(mi) += uf_pb_tot_sz;
4803 bfa_meminfo_dma_phys(mi) += uf_pb_tot_sz;
4804
Jing Huang6a18b162010-10-18 17:08:54 -07004805 memset((void *)ufm->uf_pbs_kva, 0, uf_pb_tot_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004806}
4807
4808static void
4809claim_uf_post_msgs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4810{
4811 struct bfi_uf_buf_post_s *uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004812 u16 i;
4813 u16 buf_len;
4814
4815 ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_meminfo_kva(mi);
4816 uf_bp_msg = ufm->uf_buf_posts;
4817
4818 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
4819 i++, uf_bp_msg++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004820 memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004821
4822 uf_bp_msg->buf_tag = i;
4823 buf_len = sizeof(struct bfa_uf_buf_s);
Jing Huangba816ea2010-10-18 17:10:50 -07004824 uf_bp_msg->buf_len = cpu_to_be16(buf_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004825 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
4826 bfa_lpuid(ufm->bfa));
Krishna Gudipati85ce9282011-06-13 15:39:36 -07004827 bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004828 }
4829
Jing Huang5fbe25c2010-10-18 17:17:23 -07004830 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004831 * advance pointer beyond consumed memory
4832 */
4833 bfa_meminfo_kva(mi) = (u8 *) uf_bp_msg;
4834}
4835
4836static void
4837claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4838{
4839 u16 i;
4840 struct bfa_uf_s *uf;
4841
4842 /*
4843 * Claim block of memory for UF list
4844 */
4845 ufm->uf_list = (struct bfa_uf_s *) bfa_meminfo_kva(mi);
4846
4847 /*
4848 * Initialize UFs and queue it in UF free queue
4849 */
4850 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004851 memset(uf, 0, sizeof(struct bfa_uf_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004852 uf->bfa = ufm->bfa;
4853 uf->uf_tag = i;
4854 uf->pb_len = sizeof(struct bfa_uf_buf_s);
4855 uf->buf_kva = (void *)&ufm->uf_pbs_kva[i];
4856 uf->buf_pa = ufm_pbs_pa(ufm, i);
4857 list_add_tail(&uf->qe, &ufm->uf_free_q);
4858 }
4859
Jing Huang5fbe25c2010-10-18 17:17:23 -07004860 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004861 * advance memory pointer
4862 */
4863 bfa_meminfo_kva(mi) = (u8 *) uf;
4864}
4865
4866static void
4867uf_mem_claim(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
4868{
4869 claim_uf_pbs(ufm, mi);
4870 claim_ufs(ufm, mi);
4871 claim_uf_post_msgs(ufm, mi);
4872}
4873
4874static void
4875bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, u32 *dm_len)
4876{
4877 u32 num_ufs = cfg->fwcfg.num_uf_bufs;
4878
4879 /*
4880 * dma-able memory for UF posted bufs
4881 */
4882 *dm_len += BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * num_ufs),
4883 BFA_DMA_ALIGN_SZ);
4884
4885 /*
4886 * kernel Virtual memory for UFs and UF buf post msg copies
4887 */
4888 *ndm_len += sizeof(struct bfa_uf_s) * num_ufs;
4889 *ndm_len += sizeof(struct bfi_uf_buf_post_s) * num_ufs;
4890}
4891
4892static void
4893bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4894 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
4895{
4896 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
4897
Jing Huang6a18b162010-10-18 17:08:54 -07004898 memset(ufm, 0, sizeof(struct bfa_uf_mod_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004899 ufm->bfa = bfa;
4900 ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
4901 INIT_LIST_HEAD(&ufm->uf_free_q);
4902 INIT_LIST_HEAD(&ufm->uf_posted_q);
4903
4904 uf_mem_claim(ufm, meminfo);
4905}
4906
4907static void
4908bfa_uf_detach(struct bfa_s *bfa)
4909{
4910}
4911
4912static struct bfa_uf_s *
4913bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
4914{
4915 struct bfa_uf_s *uf;
4916
4917 bfa_q_deq(&uf_mod->uf_free_q, &uf);
4918 return uf;
4919}
4920
4921static void
4922bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
4923{
4924 list_add_tail(&uf->qe, &uf_mod->uf_free_q);
4925}
4926
4927static bfa_status_t
4928bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
4929{
4930 struct bfi_uf_buf_post_s *uf_post_msg;
4931
4932 uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
4933 if (!uf_post_msg)
4934 return BFA_STATUS_FAILED;
4935
Jing Huang6a18b162010-10-18 17:08:54 -07004936 memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004937 sizeof(struct bfi_uf_buf_post_s));
4938 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP);
4939
4940 bfa_trc(ufm->bfa, uf->uf_tag);
4941
4942 list_add_tail(&uf->qe, &ufm->uf_posted_q);
4943 return BFA_STATUS_OK;
4944}
4945
4946static void
4947bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
4948{
4949 struct bfa_uf_s *uf;
4950
4951 while ((uf = bfa_uf_get(uf_mod)) != NULL) {
4952 if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
4953 break;
4954 }
4955}
4956
4957static void
4958uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
4959{
4960 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
4961 u16 uf_tag = m->buf_tag;
4962 struct bfa_uf_buf_s *uf_buf = &ufm->uf_pbs_kva[uf_tag];
4963 struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
4964 u8 *buf = &uf_buf->d[0];
4965 struct fchs_s *fchs;
4966
Jing Huangba816ea2010-10-18 17:10:50 -07004967 m->frm_len = be16_to_cpu(m->frm_len);
4968 m->xfr_len = be16_to_cpu(m->xfr_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004969
4970 fchs = (struct fchs_s *)uf_buf;
4971
4972 list_del(&uf->qe); /* dequeue from posted queue */
4973
4974 uf->data_ptr = buf;
4975 uf->data_len = m->xfr_len;
4976
Jing Huangd4b671c2010-12-26 21:46:35 -08004977 WARN_ON(uf->data_len < sizeof(struct fchs_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004978
4979 if (uf->data_len == sizeof(struct fchs_s)) {
4980 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
4981 uf->data_len, (struct fchs_s *)buf);
4982 } else {
4983 u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
4984 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
4985 BFA_PL_EID_RX, uf->data_len,
4986 (struct fchs_s *)buf, pld_w0);
4987 }
4988
4989 if (bfa->fcs)
4990 __bfa_cb_uf_recv(uf, BFA_TRUE);
4991 else
4992 bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
4993}
4994
4995static void
4996bfa_uf_stop(struct bfa_s *bfa)
4997{
4998}
4999
5000static void
5001bfa_uf_iocdisable(struct bfa_s *bfa)
5002{
5003 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5004 struct bfa_uf_s *uf;
5005 struct list_head *qe, *qen;
5006
5007 list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
5008 uf = (struct bfa_uf_s *) qe;
5009 list_del(&uf->qe);
5010 bfa_uf_put(ufm, uf);
5011 }
5012}
5013
5014static void
5015bfa_uf_start(struct bfa_s *bfa)
5016{
5017 bfa_uf_post_all(BFA_UF_MOD(bfa));
5018}
5019
Jing Huang5fbe25c2010-10-18 17:17:23 -07005020/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005021 * Register handler for all unsolicted receive frames.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005022 *
5023 * @param[in] bfa BFA instance
5024 * @param[in] ufrecv receive handler function
5025 * @param[in] cbarg receive handler arg
5026 */
5027void
5028bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
5029{
5030 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5031
5032 ufm->ufrecv = ufrecv;
5033 ufm->cbarg = cbarg;
5034}
5035
Jing Huang5fbe25c2010-10-18 17:17:23 -07005036/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005037 * Free an unsolicited frame back to BFA.
5038 *
5039 * @param[in] uf unsolicited frame to be freed
5040 *
5041 * @return None
5042 */
5043void
5044bfa_uf_free(struct bfa_uf_s *uf)
5045{
5046 bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
5047 bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
5048}
5049
5050
5051
Jing Huang5fbe25c2010-10-18 17:17:23 -07005052/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005053 * uf_pub BFA uf module public functions
5054 */
5055void
5056bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5057{
5058 bfa_trc(bfa, msg->mhdr.msg_id);
5059
5060 switch (msg->mhdr.msg_id) {
5061 case BFI_UF_I2H_FRM_RCVD:
5062 uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
5063 break;
5064
5065 default:
5066 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08005067 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005068 }
5069}
5070
5071