blob: 136f5f922cd3ecc7e2bb1fd808a46473e78e728a [file] [log] [blame]
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001/*
2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
Maggie Zhangf16a1752010-12-09 19:12:32 -080018#include "bfad_drv.h"
Krishna Gudipati7826f302011-07-20 16:59:13 -070019#include "bfad_im.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070020#include "bfa_plog.h"
21#include "bfa_cs.h"
22#include "bfa_modules.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070023
24BFA_TRC_FILE(HAL, FCXP);
Krishna Gudipati3d7fc662011-06-24 20:28:17 -070025BFA_MODULE(fcdiag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070026BFA_MODULE(fcxp);
27BFA_MODULE(sgpg);
28BFA_MODULE(lps);
29BFA_MODULE(fcport);
30BFA_MODULE(rport);
31BFA_MODULE(uf);
32
Jing Huang5fbe25c2010-10-18 17:17:23 -070033/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070034 * LPS related definitions
35 */
36#define BFA_LPS_MIN_LPORTS (1)
37#define BFA_LPS_MAX_LPORTS (256)
38
39/*
40 * Maximum Vports supported per physical port or vf.
41 */
42#define BFA_LPS_MAX_VPORTS_SUPP_CB 255
43#define BFA_LPS_MAX_VPORTS_SUPP_CT 190
44
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070045
Jing Huang5fbe25c2010-10-18 17:17:23 -070046/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070047 * FC PORT related definitions
48 */
49/*
50 * The port is considered disabled if corresponding physical port or IOC are
51 * disabled explicitly
52 */
53#define BFA_PORT_IS_DISABLED(bfa) \
54 ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
55 (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
56
Jing Huang5fbe25c2010-10-18 17:17:23 -070057/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070058 * BFA port state machine events
59 */
60enum bfa_fcport_sm_event {
61 BFA_FCPORT_SM_START = 1, /* start port state machine */
62 BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
63 BFA_FCPORT_SM_ENABLE = 3, /* enable port */
64 BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
65 BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
66 BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
67 BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
68 BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
69 BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
70};
71
Jing Huang5fbe25c2010-10-18 17:17:23 -070072/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070073 * BFA port link notification state machine events
74 */
75
76enum bfa_fcport_ln_sm_event {
77 BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
78 BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
79 BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
80};
81
Jing Huang5fbe25c2010-10-18 17:17:23 -070082/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070083 * RPORT related definitions
84 */
85#define bfa_rport_offline_cb(__rp) do { \
86 if ((__rp)->bfa->fcs) \
87 bfa_cb_rport_offline((__rp)->rport_drv); \
88 else { \
89 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
90 __bfa_cb_rport_offline, (__rp)); \
91 } \
92} while (0)
93
94#define bfa_rport_online_cb(__rp) do { \
95 if ((__rp)->bfa->fcs) \
96 bfa_cb_rport_online((__rp)->rport_drv); \
97 else { \
98 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
99 __bfa_cb_rport_online, (__rp)); \
100 } \
101} while (0)
102
Jing Huang5fbe25c2010-10-18 17:17:23 -0700103/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700104 * forward declarations FCXP related functions
105 */
106static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete);
107static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
108 struct bfi_fcxp_send_rsp_s *fcxp_rsp);
109static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen,
110 struct bfa_fcxp_s *fcxp, struct fchs_s *fchs);
111static void bfa_fcxp_qresume(void *cbarg);
112static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp,
113 struct bfi_fcxp_send_req_s *send_req);
114
Jing Huang5fbe25c2010-10-18 17:17:23 -0700115/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700116 * forward declarations for LPS functions
117 */
Krishna Gudipati45070252011-06-24 20:24:29 -0700118static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg,
119 struct bfa_meminfo_s *minfo, struct bfa_s *bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700120static void bfa_lps_attach(struct bfa_s *bfa, void *bfad,
121 struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700122 struct bfa_pcidev_s *pcidev);
123static void bfa_lps_detach(struct bfa_s *bfa);
124static void bfa_lps_start(struct bfa_s *bfa);
125static void bfa_lps_stop(struct bfa_s *bfa);
126static void bfa_lps_iocdisable(struct bfa_s *bfa);
127static void bfa_lps_login_rsp(struct bfa_s *bfa,
128 struct bfi_lps_login_rsp_s *rsp);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700129static void bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130static void bfa_lps_logout_rsp(struct bfa_s *bfa,
131 struct bfi_lps_logout_rsp_s *rsp);
132static void bfa_lps_reqq_resume(void *lps_arg);
133static void bfa_lps_free(struct bfa_lps_s *lps);
134static void bfa_lps_send_login(struct bfa_lps_s *lps);
135static void bfa_lps_send_logout(struct bfa_lps_s *lps);
Krishna Gudipatib7044952010-12-13 16:17:42 -0800136static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700137static void bfa_lps_login_comp(struct bfa_lps_s *lps);
138static void bfa_lps_logout_comp(struct bfa_lps_s *lps);
139static void bfa_lps_cvl_event(struct bfa_lps_s *lps);
140
Jing Huang5fbe25c2010-10-18 17:17:23 -0700141/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700142 * forward declaration for LPS state machine
143 */
144static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event);
145static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event);
146static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event
147 event);
148static void bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event);
Krishna Gudipatib7044952010-12-13 16:17:42 -0800149static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps,
150 enum bfa_lps_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700151static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event);
152static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event
153 event);
154
Jing Huang5fbe25c2010-10-18 17:17:23 -0700155/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700156 * forward declaration for FC Port functions
157 */
158static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
159static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
160static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
161static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
162static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
163static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
164static void bfa_fcport_scn(struct bfa_fcport_s *fcport,
165 enum bfa_port_linkstate event, bfa_boolean_t trunk);
166static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
167 enum bfa_port_linkstate event);
168static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
169static void bfa_fcport_stats_get_timeout(void *cbarg);
170static void bfa_fcport_stats_clr_timeout(void *cbarg);
171static void bfa_trunk_iocdisable(struct bfa_s *bfa);
172
Jing Huang5fbe25c2010-10-18 17:17:23 -0700173/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700174 * forward declaration for FC PORT state machine
175 */
176static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
177 enum bfa_fcport_sm_event event);
178static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
179 enum bfa_fcport_sm_event event);
180static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
181 enum bfa_fcport_sm_event event);
182static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
183 enum bfa_fcport_sm_event event);
184static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
185 enum bfa_fcport_sm_event event);
186static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
187 enum bfa_fcport_sm_event event);
188static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
189 enum bfa_fcport_sm_event event);
190static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
191 enum bfa_fcport_sm_event event);
192static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
193 enum bfa_fcport_sm_event event);
194static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
195 enum bfa_fcport_sm_event event);
196static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
197 enum bfa_fcport_sm_event event);
198static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
199 enum bfa_fcport_sm_event event);
200
201static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
202 enum bfa_fcport_ln_sm_event event);
203static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
204 enum bfa_fcport_ln_sm_event event);
205static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
206 enum bfa_fcport_ln_sm_event event);
207static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
208 enum bfa_fcport_ln_sm_event event);
209static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
210 enum bfa_fcport_ln_sm_event event);
211static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
212 enum bfa_fcport_ln_sm_event event);
213static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
214 enum bfa_fcport_ln_sm_event event);
215
216static struct bfa_sm_table_s hal_port_sm_table[] = {
217 {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT},
218 {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT},
219 {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING},
220 {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN},
221 {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP},
222 {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT},
223 {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT},
224 {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING},
225 {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED},
226 {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED},
227 {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN},
228 {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN},
229};
230
231
Jing Huang5fbe25c2010-10-18 17:17:23 -0700232/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700233 * forward declaration for RPORT related functions
234 */
235static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod);
236static void bfa_rport_free(struct bfa_rport_s *rport);
237static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp);
238static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp);
239static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp);
240static void __bfa_cb_rport_online(void *cbarg,
241 bfa_boolean_t complete);
242static void __bfa_cb_rport_offline(void *cbarg,
243 bfa_boolean_t complete);
244
Jing Huang5fbe25c2010-10-18 17:17:23 -0700245/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700246 * forward declaration for RPORT state machine
247 */
248static void bfa_rport_sm_uninit(struct bfa_rport_s *rp,
249 enum bfa_rport_event event);
250static void bfa_rport_sm_created(struct bfa_rport_s *rp,
251 enum bfa_rport_event event);
252static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp,
253 enum bfa_rport_event event);
254static void bfa_rport_sm_online(struct bfa_rport_s *rp,
255 enum bfa_rport_event event);
256static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp,
257 enum bfa_rport_event event);
258static void bfa_rport_sm_offline(struct bfa_rport_s *rp,
259 enum bfa_rport_event event);
260static void bfa_rport_sm_deleting(struct bfa_rport_s *rp,
261 enum bfa_rport_event event);
262static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
263 enum bfa_rport_event event);
264static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
265 enum bfa_rport_event event);
266static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp,
267 enum bfa_rport_event event);
268static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp,
269 enum bfa_rport_event event);
270static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp,
271 enum bfa_rport_event event);
272static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp,
273 enum bfa_rport_event event);
274
Jing Huang5fbe25c2010-10-18 17:17:23 -0700275/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700276 * PLOG related definitions
277 */
278static int
279plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
280{
281 if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
282 (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
283 return 1;
284
285 if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
286 (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
287 return 1;
288
289 return 0;
290}
291
Maggie Zhangf16a1752010-12-09 19:12:32 -0800292static u64
293bfa_get_log_time(void)
294{
295 u64 system_time = 0;
296 struct timeval tv;
297 do_gettimeofday(&tv);
298
299 /* We are interested in seconds only. */
300 system_time = tv.tv_sec;
301 return system_time;
302}
303
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700304static void
305bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
306{
307 u16 tail;
308 struct bfa_plog_rec_s *pl_recp;
309
310 if (plog->plog_enabled == 0)
311 return;
312
313 if (plkd_validate_logrec(pl_rec)) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800314 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700315 return;
316 }
317
318 tail = plog->tail;
319
320 pl_recp = &(plog->plog_recs[tail]);
321
Jing Huang6a18b162010-10-18 17:08:54 -0700322 memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700323
Maggie Zhangf16a1752010-12-09 19:12:32 -0800324 pl_recp->tv = bfa_get_log_time();
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700325 BFA_PL_LOG_REC_INCR(plog->tail);
326
327 if (plog->head == plog->tail)
328 BFA_PL_LOG_REC_INCR(plog->head);
329}
330
331void
332bfa_plog_init(struct bfa_plog_s *plog)
333{
Jing Huang6a18b162010-10-18 17:08:54 -0700334 memset((char *)plog, 0, sizeof(struct bfa_plog_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700335
Jing Huang6a18b162010-10-18 17:08:54 -0700336 memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700337 plog->head = plog->tail = 0;
338 plog->plog_enabled = 1;
339}
340
341void
342bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
343 enum bfa_plog_eid event,
344 u16 misc, char *log_str)
345{
346 struct bfa_plog_rec_s lp;
347
348 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700349 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700350 lp.mid = mid;
351 lp.eid = event;
352 lp.log_type = BFA_PL_LOG_TYPE_STRING;
353 lp.misc = misc;
354 strncpy(lp.log_entry.string_log, log_str,
355 BFA_PL_STRING_LOG_SZ - 1);
356 lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
357 bfa_plog_add(plog, &lp);
358 }
359}
360
361void
362bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
363 enum bfa_plog_eid event,
364 u16 misc, u32 *intarr, u32 num_ints)
365{
366 struct bfa_plog_rec_s lp;
367 u32 i;
368
369 if (num_ints > BFA_PL_INT_LOG_SZ)
370 num_ints = BFA_PL_INT_LOG_SZ;
371
372 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700373 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700374 lp.mid = mid;
375 lp.eid = event;
376 lp.log_type = BFA_PL_LOG_TYPE_INT;
377 lp.misc = misc;
378
379 for (i = 0; i < num_ints; i++)
Jing Huang6a18b162010-10-18 17:08:54 -0700380 lp.log_entry.int_log[i] = intarr[i];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700381
382 lp.log_num_ints = (u8) num_ints;
383
384 bfa_plog_add(plog, &lp);
385 }
386}
387
388void
389bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
390 enum bfa_plog_eid event,
391 u16 misc, struct fchs_s *fchdr)
392{
393 struct bfa_plog_rec_s lp;
394 u32 *tmp_int = (u32 *) fchdr;
395 u32 ints[BFA_PL_INT_LOG_SZ];
396
397 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700398 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700399
400 ints[0] = tmp_int[0];
401 ints[1] = tmp_int[1];
402 ints[2] = tmp_int[4];
403
404 bfa_plog_intarr(plog, mid, event, misc, ints, 3);
405 }
406}
407
408void
409bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
410 enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
411 u32 pld_w0)
412{
413 struct bfa_plog_rec_s lp;
414 u32 *tmp_int = (u32 *) fchdr;
415 u32 ints[BFA_PL_INT_LOG_SZ];
416
417 if (plog->plog_enabled) {
Jing Huang6a18b162010-10-18 17:08:54 -0700418 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700419
420 ints[0] = tmp_int[0];
421 ints[1] = tmp_int[1];
422 ints[2] = tmp_int[4];
423 ints[3] = pld_w0;
424
425 bfa_plog_intarr(plog, mid, event, misc, ints, 4);
426 }
427}
428
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700429
Jing Huang5fbe25c2010-10-18 17:17:23 -0700430/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700431 * fcxp_pvt BFA FCXP private functions
432 */
433
434static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700435claim_fcxps_mem(struct bfa_fcxp_mod_s *mod)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700436{
437 u16 i;
438 struct bfa_fcxp_s *fcxp;
439
Krishna Gudipati45070252011-06-24 20:24:29 -0700440 fcxp = (struct bfa_fcxp_s *) bfa_mem_kva_curp(mod);
Jing Huang6a18b162010-10-18 17:08:54 -0700441 memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700442
443 INIT_LIST_HEAD(&mod->fcxp_free_q);
444 INIT_LIST_HEAD(&mod->fcxp_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700445 INIT_LIST_HEAD(&mod->fcxp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700446
447 mod->fcxp_list = fcxp;
448
449 for (i = 0; i < mod->num_fcxps; i++) {
450 fcxp->fcxp_mod = mod;
451 fcxp->fcxp_tag = i;
452
453 list_add_tail(&fcxp->qe, &mod->fcxp_free_q);
454 bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp);
455 fcxp->reqq_waiting = BFA_FALSE;
456
457 fcxp = fcxp + 1;
458 }
459
Krishna Gudipati45070252011-06-24 20:24:29 -0700460 bfa_mem_kva_curp(mod) = (void *)fcxp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700461}
462
463static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700464bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
465 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700466{
Krishna Gudipati45070252011-06-24 20:24:29 -0700467 struct bfa_fcxp_mod_s *fcxp_mod = BFA_FCXP_MOD(bfa);
468 struct bfa_mem_kva_s *fcxp_kva = BFA_MEM_FCXP_KVA(bfa);
469 struct bfa_mem_dma_s *seg_ptr;
470 u16 nsegs, idx, per_seg_fcxp;
471 u16 num_fcxps = cfg->fwcfg.num_fcxp_reqs;
472 u32 per_fcxp_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700473
Krishna Gudipati45070252011-06-24 20:24:29 -0700474 if (num_fcxps == 0)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700475 return;
476
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700477 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -0700478 per_fcxp_sz = 2 * BFA_FCXP_MAX_IBUF_SZ;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700479 else
Krishna Gudipati45070252011-06-24 20:24:29 -0700480 per_fcxp_sz = BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700481
Krishna Gudipati45070252011-06-24 20:24:29 -0700482 /* dma memory */
483 nsegs = BFI_MEM_DMA_NSEGS(num_fcxps, per_fcxp_sz);
484 per_seg_fcxp = BFI_MEM_NREQS_SEG(per_fcxp_sz);
485
486 bfa_mem_dma_seg_iter(fcxp_mod, seg_ptr, nsegs, idx) {
487 if (num_fcxps >= per_seg_fcxp) {
488 num_fcxps -= per_seg_fcxp;
489 bfa_mem_dma_setup(minfo, seg_ptr,
490 per_seg_fcxp * per_fcxp_sz);
491 } else
492 bfa_mem_dma_setup(minfo, seg_ptr,
493 num_fcxps * per_fcxp_sz);
494 }
495
496 /* kva memory */
497 bfa_mem_kva_setup(minfo, fcxp_kva,
498 cfg->fwcfg.num_fcxp_reqs * sizeof(struct bfa_fcxp_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700499}
500
501static void
502bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -0700503 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700504{
505 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
506
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700507 mod->bfa = bfa;
508 mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
509
Jing Huang5fbe25c2010-10-18 17:17:23 -0700510 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700511 * Initialize FCXP request and response payload sizes.
512 */
513 mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
514 if (!cfg->drvcfg.min_cfg)
515 mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ;
516
517 INIT_LIST_HEAD(&mod->wait_q);
518
Krishna Gudipati45070252011-06-24 20:24:29 -0700519 claim_fcxps_mem(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700520}
521
522static void
523bfa_fcxp_detach(struct bfa_s *bfa)
524{
525}
526
527static void
528bfa_fcxp_start(struct bfa_s *bfa)
529{
530}
531
532static void
533bfa_fcxp_stop(struct bfa_s *bfa)
534{
535}
536
537static void
538bfa_fcxp_iocdisable(struct bfa_s *bfa)
539{
540 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
541 struct bfa_fcxp_s *fcxp;
542 struct list_head *qe, *qen;
543
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700544 /* Enqueue unused fcxp resources to free_q */
545 list_splice_tail_init(&mod->fcxp_unused_q, &mod->fcxp_free_q);
546
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700547 list_for_each_safe(qe, qen, &mod->fcxp_active_q) {
548 fcxp = (struct bfa_fcxp_s *) qe;
549 if (fcxp->caller == NULL) {
550 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
551 BFA_STATUS_IOC_FAILURE, 0, 0, NULL);
552 bfa_fcxp_free(fcxp);
553 } else {
554 fcxp->rsp_status = BFA_STATUS_IOC_FAILURE;
555 bfa_cb_queue(bfa, &fcxp->hcb_qe,
556 __bfa_fcxp_send_cbfn, fcxp);
557 }
558 }
559}
560
561static struct bfa_fcxp_s *
562bfa_fcxp_get(struct bfa_fcxp_mod_s *fm)
563{
564 struct bfa_fcxp_s *fcxp;
565
566 bfa_q_deq(&fm->fcxp_free_q, &fcxp);
567
568 if (fcxp)
569 list_add_tail(&fcxp->qe, &fm->fcxp_active_q);
570
571 return fcxp;
572}
573
574static void
575bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
576 struct bfa_s *bfa,
577 u8 *use_ibuf,
578 u32 *nr_sgles,
579 bfa_fcxp_get_sgaddr_t *r_sga_cbfn,
580 bfa_fcxp_get_sglen_t *r_sglen_cbfn,
581 struct list_head *r_sgpg_q,
582 int n_sgles,
583 bfa_fcxp_get_sgaddr_t sga_cbfn,
584 bfa_fcxp_get_sglen_t sglen_cbfn)
585{
586
Jing Huangd4b671c2010-12-26 21:46:35 -0800587 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700588
589 bfa_trc(bfa, fcxp->fcxp_tag);
590
591 if (n_sgles == 0) {
592 *use_ibuf = 1;
593 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800594 WARN_ON(*sga_cbfn == NULL);
595 WARN_ON(*sglen_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700596
597 *use_ibuf = 0;
598 *r_sga_cbfn = sga_cbfn;
599 *r_sglen_cbfn = sglen_cbfn;
600
601 *nr_sgles = n_sgles;
602
603 /*
604 * alloc required sgpgs
605 */
606 if (n_sgles > BFI_SGE_INLINE)
Jing Huangd4b671c2010-12-26 21:46:35 -0800607 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700608 }
609
610}
611
612static void
613bfa_fcxp_init(struct bfa_fcxp_s *fcxp,
614 void *caller, struct bfa_s *bfa, int nreq_sgles,
615 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
616 bfa_fcxp_get_sglen_t req_sglen_cbfn,
617 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
618 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
619{
620
Jing Huangd4b671c2010-12-26 21:46:35 -0800621 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700622
623 bfa_trc(bfa, fcxp->fcxp_tag);
624
625 fcxp->caller = caller;
626
627 bfa_fcxp_init_reqrsp(fcxp, bfa,
628 &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn,
629 &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q,
630 nreq_sgles, req_sga_cbfn, req_sglen_cbfn);
631
632 bfa_fcxp_init_reqrsp(fcxp, bfa,
633 &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn,
634 &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q,
635 nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn);
636
637}
638
639static void
640bfa_fcxp_put(struct bfa_fcxp_s *fcxp)
641{
642 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
643 struct bfa_fcxp_wqe_s *wqe;
644
645 bfa_q_deq(&mod->wait_q, &wqe);
646 if (wqe) {
647 bfa_trc(mod->bfa, fcxp->fcxp_tag);
648
649 bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles,
650 wqe->nrsp_sgles, wqe->req_sga_cbfn,
651 wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn,
652 wqe->rsp_sglen_cbfn);
653
654 wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp);
655 return;
656 }
657
Jing Huangd4b671c2010-12-26 21:46:35 -0800658 WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700659 list_del(&fcxp->qe);
660 list_add_tail(&fcxp->qe, &mod->fcxp_free_q);
661}
662
663static void
664bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
665 bfa_status_t req_status, u32 rsp_len,
666 u32 resid_len, struct fchs_s *rsp_fchs)
667{
668 /* discarded fcxp completion */
669}
670
671static void
672__bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete)
673{
674 struct bfa_fcxp_s *fcxp = cbarg;
675
676 if (complete) {
677 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
678 fcxp->rsp_status, fcxp->rsp_len,
679 fcxp->residue_len, &fcxp->rsp_fchs);
680 } else {
681 bfa_fcxp_free(fcxp);
682 }
683}
684
685static void
686hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
687{
688 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
689 struct bfa_fcxp_s *fcxp;
Jing Huangba816ea2010-10-18 17:10:50 -0700690 u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700691
692 bfa_trc(bfa, fcxp_tag);
693
Jing Huangba816ea2010-10-18 17:10:50 -0700694 fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700695
Jing Huang5fbe25c2010-10-18 17:17:23 -0700696 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700697 * @todo f/w should not set residue to non-0 when everything
698 * is received.
699 */
700 if (fcxp_rsp->req_status == BFA_STATUS_OK)
701 fcxp_rsp->residue_len = 0;
702 else
Jing Huangba816ea2010-10-18 17:10:50 -0700703 fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700704
705 fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
706
Jing Huangd4b671c2010-12-26 21:46:35 -0800707 WARN_ON(fcxp->send_cbfn == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700708
709 hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp);
710
711 if (fcxp->send_cbfn != NULL) {
712 bfa_trc(mod->bfa, (NULL == fcxp->caller));
713 if (fcxp->caller == NULL) {
714 fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
715 fcxp_rsp->req_status, fcxp_rsp->rsp_len,
716 fcxp_rsp->residue_len, &fcxp_rsp->fchs);
717 /*
718 * fcxp automatically freed on return from the callback
719 */
720 bfa_fcxp_free(fcxp);
721 } else {
722 fcxp->rsp_status = fcxp_rsp->req_status;
723 fcxp->rsp_len = fcxp_rsp->rsp_len;
724 fcxp->residue_len = fcxp_rsp->residue_len;
725 fcxp->rsp_fchs = fcxp_rsp->fchs;
726
727 bfa_cb_queue(bfa, &fcxp->hcb_qe,
728 __bfa_fcxp_send_cbfn, fcxp);
729 }
730 } else {
731 bfa_trc(bfa, (NULL == fcxp->send_cbfn));
732 }
733}
734
735static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700736hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp,
737 struct fchs_s *fchs)
738{
739 /*
740 * TODO: TX ox_id
741 */
742 if (reqlen > 0) {
743 if (fcxp->use_ireqbuf) {
744 u32 pld_w0 =
745 *((u32 *) BFA_FCXP_REQ_PLD(fcxp));
746
747 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
748 BFA_PL_EID_TX,
749 reqlen + sizeof(struct fchs_s), fchs,
750 pld_w0);
751 } else {
752 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
753 BFA_PL_EID_TX,
754 reqlen + sizeof(struct fchs_s),
755 fchs);
756 }
757 } else {
758 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX,
759 reqlen + sizeof(struct fchs_s), fchs);
760 }
761}
762
763static void
764hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
765 struct bfi_fcxp_send_rsp_s *fcxp_rsp)
766{
767 if (fcxp_rsp->rsp_len > 0) {
768 if (fcxp->use_irspbuf) {
769 u32 pld_w0 =
770 *((u32 *) BFA_FCXP_RSP_PLD(fcxp));
771
772 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
773 BFA_PL_EID_RX,
774 (u16) fcxp_rsp->rsp_len,
775 &fcxp_rsp->fchs, pld_w0);
776 } else {
777 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
778 BFA_PL_EID_RX,
779 (u16) fcxp_rsp->rsp_len,
780 &fcxp_rsp->fchs);
781 }
782 } else {
783 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX,
784 (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs);
785 }
786}
787
Jing Huang5fbe25c2010-10-18 17:17:23 -0700788/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700789 * Handler to resume sending fcxp when space in available in cpe queue.
790 */
791static void
792bfa_fcxp_qresume(void *cbarg)
793{
794 struct bfa_fcxp_s *fcxp = cbarg;
795 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
796 struct bfi_fcxp_send_req_s *send_req;
797
798 fcxp->reqq_waiting = BFA_FALSE;
799 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
800 bfa_fcxp_queue(fcxp, send_req);
801}
802
Jing Huang5fbe25c2010-10-18 17:17:23 -0700803/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700804 * Queue fcxp send request to foimrware.
805 */
806static void
807bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
808{
809 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
810 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
811 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
812 struct bfa_rport_s *rport = reqi->bfa_rport;
813
814 bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700815 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700816
Jing Huangba816ea2010-10-18 17:10:50 -0700817 send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700818 if (rport) {
819 send_req->rport_fw_hndl = rport->fw_handle;
Jing Huangba816ea2010-10-18 17:10:50 -0700820 send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700821 if (send_req->max_frmsz == 0)
Jing Huangba816ea2010-10-18 17:10:50 -0700822 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700823 } else {
824 send_req->rport_fw_hndl = 0;
Jing Huangba816ea2010-10-18 17:10:50 -0700825 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700826 }
827
Jing Huangba816ea2010-10-18 17:10:50 -0700828 send_req->vf_id = cpu_to_be16(reqi->vf_id);
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700829 send_req->lp_fwtag = bfa_lps_get_fwtag(bfa, reqi->lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700830 send_req->class = reqi->class;
831 send_req->rsp_timeout = rspi->rsp_timeout;
832 send_req->cts = reqi->cts;
833 send_req->fchs = reqi->fchs;
834
Jing Huangba816ea2010-10-18 17:10:50 -0700835 send_req->req_len = cpu_to_be32(reqi->req_tot_len);
836 send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700837
838 /*
839 * setup req sgles
840 */
841 if (fcxp->use_ireqbuf == 1) {
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700842 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700843 BFA_FCXP_REQ_PLD_PA(fcxp));
844 } else {
845 if (fcxp->nreq_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800846 WARN_ON(fcxp->nreq_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700847 bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
848 fcxp->req_sga_cbfn(fcxp->caller, 0));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700849 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800850 WARN_ON(reqi->req_tot_len != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700851 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700852 }
853 }
854
855 /*
856 * setup rsp sgles
857 */
858 if (fcxp->use_irspbuf == 1) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800859 WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700860
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700861 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700862 BFA_FCXP_RSP_PLD_PA(fcxp));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700863 } else {
864 if (fcxp->nrsp_sgles > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -0800865 WARN_ON(fcxp->nrsp_sgles != 1);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700866 bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
867 fcxp->rsp_sga_cbfn(fcxp->caller, 0));
868
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700869 } else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800870 WARN_ON(rspi->rsp_maxlen != 0);
Krishna Gudipati85ce9282011-06-13 15:39:36 -0700871 bfa_alen_set(&send_req->rsp_alen, 0, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700872 }
873 }
874
875 hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs);
876
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700877 bfa_reqq_produce(bfa, BFA_REQQ_FCXP, send_req->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700878
879 bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP));
880 bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
881}
882
Jing Huang5fbe25c2010-10-18 17:17:23 -0700883/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700884 * Allocate an FCXP instance to send a response or to send a request
885 * that has a response. Request/response buffers are allocated by caller.
886 *
887 * @param[in] bfa BFA bfa instance
888 * @param[in] nreq_sgles Number of SG elements required for request
889 * buffer. 0, if fcxp internal buffers are used.
890 * Use bfa_fcxp_get_reqbuf() to get the
891 * internal req buffer.
892 * @param[in] req_sgles SG elements describing request buffer. Will be
893 * copied in by BFA and hence can be freed on
894 * return from this function.
895 * @param[in] get_req_sga function ptr to be called to get a request SG
896 * Address (given the sge index).
897 * @param[in] get_req_sglen function ptr to be called to get a request SG
898 * len (given the sge index).
899 * @param[in] get_rsp_sga function ptr to be called to get a response SG
900 * Address (given the sge index).
901 * @param[in] get_rsp_sglen function ptr to be called to get a response SG
902 * len (given the sge index).
903 *
904 * @return FCXP instance. NULL on failure.
905 */
906struct bfa_fcxp_s *
907bfa_fcxp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
908 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
909 bfa_fcxp_get_sglen_t req_sglen_cbfn,
910 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
911 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
912{
913 struct bfa_fcxp_s *fcxp = NULL;
914
Jing Huangd4b671c2010-12-26 21:46:35 -0800915 WARN_ON(bfa == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700916
917 fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa));
918 if (fcxp == NULL)
919 return NULL;
920
921 bfa_trc(bfa, fcxp->fcxp_tag);
922
923 bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn,
924 req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn);
925
926 return fcxp;
927}
928
Jing Huang5fbe25c2010-10-18 17:17:23 -0700929/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700930 * Get the internal request buffer pointer
931 *
932 * @param[in] fcxp BFA fcxp pointer
933 *
934 * @return pointer to the internal request buffer
935 */
936void *
937bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp)
938{
939 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
940 void *reqbuf;
941
Jing Huangd4b671c2010-12-26 21:46:35 -0800942 WARN_ON(fcxp->use_ireqbuf != 1);
Krishna Gudipati45070252011-06-24 20:24:29 -0700943 reqbuf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
944 mod->req_pld_sz + mod->rsp_pld_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700945 return reqbuf;
946}
947
948u32
949bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
950{
951 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
952
953 return mod->req_pld_sz;
954}
955
Jing Huang5fbe25c2010-10-18 17:17:23 -0700956/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700957 * Get the internal response buffer pointer
958 *
959 * @param[in] fcxp BFA fcxp pointer
960 *
961 * @return pointer to the internal request buffer
962 */
963void *
964bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
965{
966 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
Krishna Gudipati45070252011-06-24 20:24:29 -0700967 void *fcxp_buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700968
Jing Huangd4b671c2010-12-26 21:46:35 -0800969 WARN_ON(fcxp->use_irspbuf != 1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700970
Krishna Gudipati45070252011-06-24 20:24:29 -0700971 fcxp_buf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
972 mod->req_pld_sz + mod->rsp_pld_sz);
973
974 /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
975 return ((u8 *) fcxp_buf) + mod->req_pld_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700976}
977
Jing Huang5fbe25c2010-10-18 17:17:23 -0700978/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800979 * Free the BFA FCXP
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700980 *
981 * @param[in] fcxp BFA fcxp pointer
982 *
983 * @return void
984 */
985void
986bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
987{
988 struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
989
Jing Huangd4b671c2010-12-26 21:46:35 -0800990 WARN_ON(fcxp == NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700991 bfa_trc(mod->bfa, fcxp->fcxp_tag);
992 bfa_fcxp_put(fcxp);
993}
994
Jing Huang5fbe25c2010-10-18 17:17:23 -0700995/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700996 * Send a FCXP request
997 *
998 * @param[in] fcxp BFA fcxp pointer
999 * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
1000 * @param[in] vf_id virtual Fabric ID
1001 * @param[in] lp_tag lport tag
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001002 * @param[in] cts use Continuous sequence
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001003 * @param[in] cos fc Class of Service
1004 * @param[in] reqlen request length, does not include FCHS length
1005 * @param[in] fchs fc Header Pointer. The header content will be copied
1006 * in by BFA.
1007 *
1008 * @param[in] cbfn call back function to be called on receiving
1009 * the response
1010 * @param[in] cbarg arg for cbfn
1011 * @param[in] rsp_timeout
1012 * response timeout
1013 *
1014 * @return bfa_status_t
1015 */
1016void
1017bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
1018 u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos,
1019 u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn,
1020 void *cbarg, u32 rsp_maxlen, u8 rsp_timeout)
1021{
1022 struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
1023 struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
1024 struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
1025 struct bfi_fcxp_send_req_s *send_req;
1026
1027 bfa_trc(bfa, fcxp->fcxp_tag);
1028
Jing Huang5fbe25c2010-10-18 17:17:23 -07001029 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001030 * setup request/response info
1031 */
1032 reqi->bfa_rport = rport;
1033 reqi->vf_id = vf_id;
1034 reqi->lp_tag = lp_tag;
1035 reqi->class = cos;
1036 rspi->rsp_timeout = rsp_timeout;
1037 reqi->cts = cts;
1038 reqi->fchs = *fchs;
1039 reqi->req_tot_len = reqlen;
1040 rspi->rsp_maxlen = rsp_maxlen;
1041 fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
1042 fcxp->send_cbarg = cbarg;
1043
Jing Huang5fbe25c2010-10-18 17:17:23 -07001044 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001045 * If no room in CPE queue, wait for space in request queue
1046 */
1047 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
1048 if (!send_req) {
1049 bfa_trc(bfa, fcxp->fcxp_tag);
1050 fcxp->reqq_waiting = BFA_TRUE;
1051 bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe);
1052 return;
1053 }
1054
1055 bfa_fcxp_queue(fcxp, send_req);
1056}
1057
Jing Huang5fbe25c2010-10-18 17:17:23 -07001058/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001059 * Abort a BFA FCXP
1060 *
1061 * @param[in] fcxp BFA fcxp pointer
1062 *
1063 * @return void
1064 */
1065bfa_status_t
1066bfa_fcxp_abort(struct bfa_fcxp_s *fcxp)
1067{
1068 bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag);
Jing Huangd4b671c2010-12-26 21:46:35 -08001069 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001070 return BFA_STATUS_OK;
1071}
1072
1073void
1074bfa_fcxp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
1075 bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg,
1076 void *caller, int nreq_sgles,
1077 int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
1078 bfa_fcxp_get_sglen_t req_sglen_cbfn,
1079 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
1080 bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
1081{
1082 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1083
Jing Huangd4b671c2010-12-26 21:46:35 -08001084 WARN_ON(!list_empty(&mod->fcxp_free_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001085
1086 wqe->alloc_cbfn = alloc_cbfn;
1087 wqe->alloc_cbarg = alloc_cbarg;
1088 wqe->caller = caller;
1089 wqe->bfa = bfa;
1090 wqe->nreq_sgles = nreq_sgles;
1091 wqe->nrsp_sgles = nrsp_sgles;
1092 wqe->req_sga_cbfn = req_sga_cbfn;
1093 wqe->req_sglen_cbfn = req_sglen_cbfn;
1094 wqe->rsp_sga_cbfn = rsp_sga_cbfn;
1095 wqe->rsp_sglen_cbfn = rsp_sglen_cbfn;
1096
1097 list_add_tail(&wqe->qe, &mod->wait_q);
1098}
1099
1100void
1101bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
1102{
1103 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1104
Jing Huangd4b671c2010-12-26 21:46:35 -08001105 WARN_ON(!bfa_q_is_on_q(&mod->wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001106 list_del(&wqe->qe);
1107}
1108
1109void
1110bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
1111{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001112 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001113 * If waiting for room in request queue, cancel reqq wait
1114 * and free fcxp.
1115 */
1116 if (fcxp->reqq_waiting) {
1117 fcxp->reqq_waiting = BFA_FALSE;
1118 bfa_reqq_wcancel(&fcxp->reqq_wqe);
1119 bfa_fcxp_free(fcxp);
1120 return;
1121 }
1122
1123 fcxp->send_cbfn = bfa_fcxp_null_comp;
1124}
1125
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001126void
1127bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
1128{
1129 switch (msg->mhdr.msg_id) {
1130 case BFI_FCXP_I2H_SEND_RSP:
1131 hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg);
1132 break;
1133
1134 default:
1135 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001136 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001137 }
1138}
1139
1140u32
1141bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
1142{
1143 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1144
1145 return mod->rsp_pld_sz;
1146}
1147
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001148void
1149bfa_fcxp_res_recfg(struct bfa_s *bfa, u16 num_fcxp_fw)
1150{
1151 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
1152 struct list_head *qe;
1153 int i;
1154
1155 for (i = 0; i < (mod->num_fcxps - num_fcxp_fw); i++) {
1156 bfa_q_deq_tail(&mod->fcxp_free_q, &qe);
1157 list_add_tail(qe, &mod->fcxp_unused_q);
1158 }
1159}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001160
Jing Huang5fbe25c2010-10-18 17:17:23 -07001161/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001162 * BFA LPS state machine functions
1163 */
1164
Jing Huang5fbe25c2010-10-18 17:17:23 -07001165/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001166 * Init state -- no login
1167 */
1168static void
1169bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
1170{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001171 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001172 bfa_trc(lps->bfa, event);
1173
1174 switch (event) {
1175 case BFA_LPS_SM_LOGIN:
1176 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1177 bfa_sm_set_state(lps, bfa_lps_sm_loginwait);
1178 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1179 } else {
1180 bfa_sm_set_state(lps, bfa_lps_sm_login);
1181 bfa_lps_send_login(lps);
1182 }
1183
1184 if (lps->fdisc)
1185 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1186 BFA_PL_EID_LOGIN, 0, "FDISC Request");
1187 else
1188 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1189 BFA_PL_EID_LOGIN, 0, "FLOGI Request");
1190 break;
1191
1192 case BFA_LPS_SM_LOGOUT:
1193 bfa_lps_logout_comp(lps);
1194 break;
1195
1196 case BFA_LPS_SM_DELETE:
1197 bfa_lps_free(lps);
1198 break;
1199
1200 case BFA_LPS_SM_RX_CVL:
1201 case BFA_LPS_SM_OFFLINE:
1202 break;
1203
1204 case BFA_LPS_SM_FWRSP:
1205 /*
1206 * Could happen when fabric detects loopback and discards
1207 * the lps request. Fw will eventually sent out the timeout
1208 * Just ignore
1209 */
1210 break;
1211
1212 default:
1213 bfa_sm_fault(lps->bfa, event);
1214 }
1215}
1216
Jing Huang5fbe25c2010-10-18 17:17:23 -07001217/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001218 * login is in progress -- awaiting response from firmware
1219 */
1220static void
1221bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
1222{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001223 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001224 bfa_trc(lps->bfa, event);
1225
1226 switch (event) {
1227 case BFA_LPS_SM_FWRSP:
1228 if (lps->status == BFA_STATUS_OK) {
1229 bfa_sm_set_state(lps, bfa_lps_sm_online);
1230 if (lps->fdisc)
1231 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1232 BFA_PL_EID_LOGIN, 0, "FDISC Accept");
1233 else
1234 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1235 BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
Krishna Gudipatib7044952010-12-13 16:17:42 -08001236 /* If N2N, send the assigned PID to FW */
1237 bfa_trc(lps->bfa, lps->fport);
1238 bfa_trc(lps->bfa, lps->lp_pid);
1239
1240 if (!lps->fport && lps->lp_pid)
1241 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001242 } else {
1243 bfa_sm_set_state(lps, bfa_lps_sm_init);
1244 if (lps->fdisc)
1245 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1246 BFA_PL_EID_LOGIN, 0,
1247 "FDISC Fail (RJT or timeout)");
1248 else
1249 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1250 BFA_PL_EID_LOGIN, 0,
1251 "FLOGI Fail (RJT or timeout)");
1252 }
1253 bfa_lps_login_comp(lps);
1254 break;
1255
1256 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001257 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001258 bfa_sm_set_state(lps, bfa_lps_sm_init);
1259 break;
1260
Krishna Gudipatib7044952010-12-13 16:17:42 -08001261 case BFA_LPS_SM_SET_N2N_PID:
1262 bfa_trc(lps->bfa, lps->fport);
1263 bfa_trc(lps->bfa, lps->lp_pid);
1264 break;
1265
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001266 default:
1267 bfa_sm_fault(lps->bfa, event);
1268 }
1269}
1270
Jing Huang5fbe25c2010-10-18 17:17:23 -07001271/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001272 * login pending - awaiting space in request queue
1273 */
1274static void
1275bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1276{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001277 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001278 bfa_trc(lps->bfa, event);
1279
1280 switch (event) {
1281 case BFA_LPS_SM_RESUME:
1282 bfa_sm_set_state(lps, bfa_lps_sm_login);
1283 break;
1284
1285 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001286 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001287 bfa_sm_set_state(lps, bfa_lps_sm_init);
1288 bfa_reqq_wcancel(&lps->wqe);
1289 break;
1290
1291 case BFA_LPS_SM_RX_CVL:
1292 /*
1293 * Login was not even sent out; so when getting out
1294 * of this state, it will appear like a login retry
1295 * after Clear virtual link
1296 */
1297 break;
1298
1299 default:
1300 bfa_sm_fault(lps->bfa, event);
1301 }
1302}
1303
Jing Huang5fbe25c2010-10-18 17:17:23 -07001304/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001305 * login complete
1306 */
1307static void
1308bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
1309{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001310 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001311 bfa_trc(lps->bfa, event);
1312
1313 switch (event) {
1314 case BFA_LPS_SM_LOGOUT:
1315 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1316 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1317 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1318 } else {
1319 bfa_sm_set_state(lps, bfa_lps_sm_logout);
1320 bfa_lps_send_logout(lps);
1321 }
1322 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1323 BFA_PL_EID_LOGO, 0, "Logout");
1324 break;
1325
1326 case BFA_LPS_SM_RX_CVL:
1327 bfa_sm_set_state(lps, bfa_lps_sm_init);
1328
1329 /* Let the vport module know about this event */
1330 bfa_lps_cvl_event(lps);
1331 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1332 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1333 break;
1334
Krishna Gudipatib7044952010-12-13 16:17:42 -08001335 case BFA_LPS_SM_SET_N2N_PID:
1336 if (bfa_reqq_full(lps->bfa, lps->reqq)) {
1337 bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
1338 bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
1339 } else
1340 bfa_lps_send_set_n2n_pid(lps);
1341 break;
1342
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001343 case BFA_LPS_SM_OFFLINE:
1344 case BFA_LPS_SM_DELETE:
1345 bfa_sm_set_state(lps, bfa_lps_sm_init);
1346 break;
1347
1348 default:
1349 bfa_sm_fault(lps->bfa, event);
1350 }
1351}
1352
Jing Huang8f4bfad2010-12-26 21:50:10 -08001353/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001354 * login complete
1355 */
1356static void
1357bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1358{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001359 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001360 bfa_trc(lps->bfa, event);
1361
1362 switch (event) {
1363 case BFA_LPS_SM_RESUME:
1364 bfa_sm_set_state(lps, bfa_lps_sm_online);
1365 bfa_lps_send_set_n2n_pid(lps);
1366 break;
1367
1368 case BFA_LPS_SM_LOGOUT:
1369 bfa_sm_set_state(lps, bfa_lps_sm_logowait);
1370 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1371 BFA_PL_EID_LOGO, 0, "Logout");
1372 break;
1373
1374 case BFA_LPS_SM_RX_CVL:
1375 bfa_sm_set_state(lps, bfa_lps_sm_init);
1376 bfa_reqq_wcancel(&lps->wqe);
1377
1378 /* Let the vport module know about this event */
1379 bfa_lps_cvl_event(lps);
1380 bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
1381 BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
1382 break;
1383
1384 case BFA_LPS_SM_OFFLINE:
1385 case BFA_LPS_SM_DELETE:
1386 bfa_sm_set_state(lps, bfa_lps_sm_init);
1387 bfa_reqq_wcancel(&lps->wqe);
1388 break;
1389
1390 default:
1391 bfa_sm_fault(lps->bfa, event);
1392 }
1393}
1394
Jing Huang5fbe25c2010-10-18 17:17:23 -07001395/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001396 * logout in progress - awaiting firmware response
1397 */
1398static void
1399bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
1400{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001401 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001402 bfa_trc(lps->bfa, event);
1403
1404 switch (event) {
1405 case BFA_LPS_SM_FWRSP:
1406 bfa_sm_set_state(lps, bfa_lps_sm_init);
1407 bfa_lps_logout_comp(lps);
1408 break;
1409
1410 case BFA_LPS_SM_OFFLINE:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001411 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001412 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{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001426 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001427 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:
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001436 case BFA_LPS_SM_DELETE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001437 bfa_sm_set_state(lps, bfa_lps_sm_init);
1438 bfa_reqq_wcancel(&lps->wqe);
1439 break;
1440
1441 default:
1442 bfa_sm_fault(lps->bfa, event);
1443 }
1444}
1445
1446
1447
Jing Huang5fbe25c2010-10-18 17:17:23 -07001448/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001449 * lps_pvt BFA LPS private functions
1450 */
1451
Jing Huang5fbe25c2010-10-18 17:17:23 -07001452/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001453 * return memory requirement
1454 */
1455static void
Krishna Gudipati45070252011-06-24 20:24:29 -07001456bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
1457 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001458{
Krishna Gudipati45070252011-06-24 20:24:29 -07001459 struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa);
1460
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001461 if (cfg->drvcfg.min_cfg)
Krishna Gudipati45070252011-06-24 20:24:29 -07001462 bfa_mem_kva_setup(minfo, lps_kva,
1463 sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001464 else
Krishna Gudipati45070252011-06-24 20:24:29 -07001465 bfa_mem_kva_setup(minfo, lps_kva,
1466 sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001467}
1468
Jing Huang5fbe25c2010-10-18 17:17:23 -07001469/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001470 * bfa module attach at initialization time
1471 */
1472static void
1473bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07001474 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001475{
1476 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1477 struct bfa_lps_s *lps;
1478 int i;
1479
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001480 mod->num_lps = BFA_LPS_MAX_LPORTS;
1481 if (cfg->drvcfg.min_cfg)
1482 mod->num_lps = BFA_LPS_MIN_LPORTS;
1483 else
1484 mod->num_lps = BFA_LPS_MAX_LPORTS;
Krishna Gudipati45070252011-06-24 20:24:29 -07001485 mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001486
Krishna Gudipati45070252011-06-24 20:24:29 -07001487 bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001488
1489 INIT_LIST_HEAD(&mod->lps_free_q);
1490 INIT_LIST_HEAD(&mod->lps_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001491 INIT_LIST_HEAD(&mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001492
1493 for (i = 0; i < mod->num_lps; i++, lps++) {
1494 lps->bfa = bfa;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001495 lps->bfa_tag = (u8) i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001496 lps->reqq = BFA_REQQ_LPS;
1497 bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
1498 list_add_tail(&lps->qe, &mod->lps_free_q);
1499 }
1500}
1501
1502static void
1503bfa_lps_detach(struct bfa_s *bfa)
1504{
1505}
1506
1507static void
1508bfa_lps_start(struct bfa_s *bfa)
1509{
1510}
1511
1512static void
1513bfa_lps_stop(struct bfa_s *bfa)
1514{
1515}
1516
Jing Huang5fbe25c2010-10-18 17:17:23 -07001517/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001518 * IOC in disabled state -- consider all lps offline
1519 */
1520static void
1521bfa_lps_iocdisable(struct bfa_s *bfa)
1522{
1523 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1524 struct bfa_lps_s *lps;
1525 struct list_head *qe, *qen;
1526
1527 list_for_each_safe(qe, qen, &mod->lps_active_q) {
1528 lps = (struct bfa_lps_s *) qe;
1529 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1530 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001531 list_for_each_safe(qe, qen, &mod->lps_login_q) {
1532 lps = (struct bfa_lps_s *) qe;
1533 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1534 }
1535 list_splice_tail_init(&mod->lps_login_q, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001536}
1537
Jing Huang5fbe25c2010-10-18 17:17:23 -07001538/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001539 * Firmware login response
1540 */
1541static void
1542bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
1543{
1544 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1545 struct bfa_lps_s *lps;
1546
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001547 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1548 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001549
1550 lps->status = rsp->status;
1551 switch (rsp->status) {
1552 case BFA_STATUS_OK:
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001553 lps->fw_tag = rsp->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001554 lps->fport = rsp->f_port;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001555 if (lps->fport)
1556 lps->lp_pid = rsp->lp_pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001557 lps->npiv_en = rsp->npiv_en;
Jing Huangba816ea2010-10-18 17:10:50 -07001558 lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001559 lps->pr_pwwn = rsp->port_name;
1560 lps->pr_nwwn = rsp->node_name;
1561 lps->auth_req = rsp->auth_req;
1562 lps->lp_mac = rsp->lp_mac;
1563 lps->brcd_switch = rsp->brcd_switch;
1564 lps->fcf_mac = rsp->fcf_mac;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001565 lps->pr_bbscn = rsp->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001566
1567 break;
1568
1569 case BFA_STATUS_FABRIC_RJT:
1570 lps->lsrjt_rsn = rsp->lsrjt_rsn;
1571 lps->lsrjt_expl = rsp->lsrjt_expl;
1572
1573 break;
1574
1575 case BFA_STATUS_EPROTOCOL:
1576 lps->ext_status = rsp->ext_status;
1577
1578 break;
1579
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001580 case BFA_STATUS_VPORT_MAX:
1581 if (!rsp->ext_status)
1582 bfa_lps_no_res(lps, rsp->ext_status);
1583 break;
1584
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001585 default:
1586 /* Nothing to do with other status */
1587 break;
1588 }
1589
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001590 list_del(&lps->qe);
1591 list_add_tail(&lps->qe, &mod->lps_active_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001592 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1593}
1594
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001595static void
1596bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count)
1597{
1598 struct bfa_s *bfa = first_lps->bfa;
1599 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1600 struct list_head *qe, *qe_next;
1601 struct bfa_lps_s *lps;
1602
1603 bfa_trc(bfa, count);
1604
1605 qe = bfa_q_next(first_lps);
1606
1607 while (count && qe) {
1608 qe_next = bfa_q_next(qe);
1609 lps = (struct bfa_lps_s *)qe;
1610 bfa_trc(bfa, lps->bfa_tag);
1611 lps->status = first_lps->status;
1612 list_del(&lps->qe);
1613 list_add_tail(&lps->qe, &mod->lps_active_q);
1614 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1615 qe = qe_next;
1616 count--;
1617 }
1618}
1619
Jing Huang5fbe25c2010-10-18 17:17:23 -07001620/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001621 * Firmware logout response
1622 */
1623static void
1624bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
1625{
1626 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1627 struct bfa_lps_s *lps;
1628
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001629 WARN_ON(rsp->bfa_tag >= mod->num_lps);
1630 lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001631
1632 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1633}
1634
Jing Huang5fbe25c2010-10-18 17:17:23 -07001635/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001636 * Firmware received a Clear virtual link request (for FCoE)
1637 */
1638static void
1639bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
1640{
1641 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1642 struct bfa_lps_s *lps;
1643
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001644 lps = BFA_LPS_FROM_TAG(mod, cvl->bfa_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001645
1646 bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
1647}
1648
Jing Huang5fbe25c2010-10-18 17:17:23 -07001649/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001650 * Space is available in request queue, resume queueing request to firmware.
1651 */
1652static void
1653bfa_lps_reqq_resume(void *lps_arg)
1654{
1655 struct bfa_lps_s *lps = lps_arg;
1656
1657 bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
1658}
1659
Jing Huang5fbe25c2010-10-18 17:17:23 -07001660/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001661 * lps is freed -- triggered by vport delete
1662 */
1663static void
1664bfa_lps_free(struct bfa_lps_s *lps)
1665{
1666 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
1667
1668 lps->lp_pid = 0;
1669 list_del(&lps->qe);
1670 list_add_tail(&lps->qe, &mod->lps_free_q);
1671}
1672
Jing Huang5fbe25c2010-10-18 17:17:23 -07001673/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001674 * send login request to firmware
1675 */
1676static void
1677bfa_lps_send_login(struct bfa_lps_s *lps)
1678{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001679 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001680 struct bfi_lps_login_req_s *m;
1681
1682 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001683 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001684
1685 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001686 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001687
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001688 m->bfa_tag = lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001689 m->alpa = lps->alpa;
Jing Huangba816ea2010-10-18 17:10:50 -07001690 m->pdu_size = cpu_to_be16(lps->pdusz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001691 m->pwwn = lps->pwwn;
1692 m->nwwn = lps->nwwn;
1693 m->fdisc = lps->fdisc;
1694 m->auth_en = lps->auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001695 m->bb_scn = lps->bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001696
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001697 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
1698 list_del(&lps->qe);
1699 list_add_tail(&lps->qe, &mod->lps_login_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001700}
1701
Jing Huang5fbe25c2010-10-18 17:17:23 -07001702/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001703 * send logout request to firmware
1704 */
1705static void
1706bfa_lps_send_logout(struct bfa_lps_s *lps)
1707{
1708 struct bfi_lps_logout_req_s *m;
1709
1710 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001711 WARN_ON(!m);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001712
1713 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001714 bfa_fn_lpu(lps->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001715
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001716 m->fw_tag = lps->fw_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001717 m->port_name = lps->pwwn;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001718 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001719}
1720
Jing Huang8f4bfad2010-12-26 21:50:10 -08001721/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001722 * send n2n pid set request to firmware
1723 */
1724static void
1725bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
1726{
1727 struct bfi_lps_n2n_pid_req_s *m;
1728
1729 m = bfa_reqq_next(lps->bfa, lps->reqq);
Jing Huangd4b671c2010-12-26 21:46:35 -08001730 WARN_ON(!m);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001731
1732 bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001733 bfa_fn_lpu(lps->bfa));
Krishna Gudipatib7044952010-12-13 16:17:42 -08001734
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001735 m->fw_tag = lps->fw_tag;
Krishna Gudipatib7044952010-12-13 16:17:42 -08001736 m->lp_pid = lps->lp_pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001737 bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001738}
1739
Jing Huang5fbe25c2010-10-18 17:17:23 -07001740/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001741 * Indirect login completion handler for non-fcs
1742 */
1743static void
1744bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
1745{
1746 struct bfa_lps_s *lps = arg;
1747
1748 if (!complete)
1749 return;
1750
1751 if (lps->fdisc)
1752 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1753 else
1754 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1755}
1756
Jing Huang5fbe25c2010-10-18 17:17:23 -07001757/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001758 * Login completion handler -- direct call for fcs, queue for others
1759 */
1760static void
1761bfa_lps_login_comp(struct bfa_lps_s *lps)
1762{
1763 if (!lps->bfa->fcs) {
1764 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
1765 lps);
1766 return;
1767 }
1768
1769 if (lps->fdisc)
1770 bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
1771 else
1772 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1773}
1774
Jing Huang5fbe25c2010-10-18 17:17:23 -07001775/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001776 * Indirect logout completion handler for non-fcs
1777 */
1778static void
1779bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
1780{
1781 struct bfa_lps_s *lps = arg;
1782
1783 if (!complete)
1784 return;
1785
1786 if (lps->fdisc)
1787 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1788}
1789
Jing Huang5fbe25c2010-10-18 17:17:23 -07001790/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001791 * Logout completion handler -- direct call for fcs, queue for others
1792 */
1793static void
1794bfa_lps_logout_comp(struct bfa_lps_s *lps)
1795{
1796 if (!lps->bfa->fcs) {
1797 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
1798 lps);
1799 return;
1800 }
1801 if (lps->fdisc)
1802 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1803}
1804
Jing Huang5fbe25c2010-10-18 17:17:23 -07001805/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001806 * Clear virtual link completion handler for non-fcs
1807 */
1808static void
1809bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
1810{
1811 struct bfa_lps_s *lps = arg;
1812
1813 if (!complete)
1814 return;
1815
1816 /* Clear virtual link to base port will result in link down */
1817 if (lps->fdisc)
1818 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1819}
1820
Jing Huang5fbe25c2010-10-18 17:17:23 -07001821/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001822 * Received Clear virtual link event --direct call for fcs,
1823 * queue for others
1824 */
1825static void
1826bfa_lps_cvl_event(struct bfa_lps_s *lps)
1827{
1828 if (!lps->bfa->fcs) {
1829 bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
1830 lps);
1831 return;
1832 }
1833
1834 /* Clear virtual link to base port will result in link down */
1835 if (lps->fdisc)
1836 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1837}
1838
1839
1840
Jing Huang5fbe25c2010-10-18 17:17:23 -07001841/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001842 * lps_public BFA LPS public functions
1843 */
1844
1845u32
1846bfa_lps_get_max_vport(struct bfa_s *bfa)
1847{
1848 if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
1849 return BFA_LPS_MAX_VPORTS_SUPP_CT;
1850 else
1851 return BFA_LPS_MAX_VPORTS_SUPP_CB;
1852}
1853
Jing Huang5fbe25c2010-10-18 17:17:23 -07001854/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001855 * Allocate a lport srvice tag.
1856 */
1857struct bfa_lps_s *
1858bfa_lps_alloc(struct bfa_s *bfa)
1859{
1860 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1861 struct bfa_lps_s *lps = NULL;
1862
1863 bfa_q_deq(&mod->lps_free_q, &lps);
1864
1865 if (lps == NULL)
1866 return NULL;
1867
1868 list_add_tail(&lps->qe, &mod->lps_active_q);
1869
1870 bfa_sm_set_state(lps, bfa_lps_sm_init);
1871 return lps;
1872}
1873
Jing Huang5fbe25c2010-10-18 17:17:23 -07001874/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001875 * Free lport service tag. This can be called anytime after an alloc.
1876 * No need to wait for any pending login/logout completions.
1877 */
1878void
1879bfa_lps_delete(struct bfa_lps_s *lps)
1880{
1881 bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
1882}
1883
Jing Huang5fbe25c2010-10-18 17:17:23 -07001884/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001885 * Initiate a lport login.
1886 */
1887void
1888bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001889 wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en, uint8_t bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001890{
1891 lps->uarg = uarg;
1892 lps->alpa = alpa;
1893 lps->pdusz = pdusz;
1894 lps->pwwn = pwwn;
1895 lps->nwwn = nwwn;
1896 lps->fdisc = BFA_FALSE;
1897 lps->auth_en = auth_en;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001898 lps->bb_scn = bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001899 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1900}
1901
Jing Huang5fbe25c2010-10-18 17:17:23 -07001902/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001903 * Initiate a lport fdisc login.
1904 */
1905void
1906bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
1907 wwn_t nwwn)
1908{
1909 lps->uarg = uarg;
1910 lps->alpa = 0;
1911 lps->pdusz = pdusz;
1912 lps->pwwn = pwwn;
1913 lps->nwwn = nwwn;
1914 lps->fdisc = BFA_TRUE;
1915 lps->auth_en = BFA_FALSE;
1916 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1917}
1918
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001919
Jing Huang5fbe25c2010-10-18 17:17:23 -07001920/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001921 * Initiate a lport FDSIC logout.
1922 */
1923void
1924bfa_lps_fdisclogo(struct bfa_lps_s *lps)
1925{
1926 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
1927}
1928
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001929u8
1930bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag)
1931{
1932 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1933
1934 return BFA_LPS_FROM_TAG(mod, lp_tag)->fw_tag;
1935}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001936
Jing Huang5fbe25c2010-10-18 17:17:23 -07001937/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001938 * Return lport services tag given the pid
1939 */
1940u8
1941bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
1942{
1943 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1944 struct bfa_lps_s *lps;
1945 int i;
1946
1947 for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
1948 if (lps->lp_pid == pid)
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001949 return lps->bfa_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001950 }
1951
1952 /* Return base port tag anyway */
1953 return 0;
1954}
1955
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001956
Jing Huang5fbe25c2010-10-18 17:17:23 -07001957/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001958 * return port id assigned to the base lport
1959 */
1960u32
1961bfa_lps_get_base_pid(struct bfa_s *bfa)
1962{
1963 struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
1964
1965 return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
1966}
1967
Jing Huang8f4bfad2010-12-26 21:50:10 -08001968/*
Krishna Gudipatib7044952010-12-13 16:17:42 -08001969 * Set PID in case of n2n (which is assigned during PLOGI)
1970 */
1971void
1972bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
1973{
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001974 bfa_trc(lps->bfa, lps->bfa_tag);
Krishna Gudipatib7044952010-12-13 16:17:42 -08001975 bfa_trc(lps->bfa, n2n_pid);
1976
1977 lps->lp_pid = n2n_pid;
1978 bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
1979}
1980
Jing Huang5fbe25c2010-10-18 17:17:23 -07001981/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001982 * LPS firmware message class handler.
1983 */
1984void
1985bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
1986{
1987 union bfi_lps_i2h_msg_u msg;
1988
1989 bfa_trc(bfa, m->mhdr.msg_id);
1990 msg.msg = m;
1991
1992 switch (m->mhdr.msg_id) {
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07001993 case BFI_LPS_I2H_LOGIN_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001994 bfa_lps_login_rsp(bfa, msg.login_rsp);
1995 break;
1996
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07001997 case BFI_LPS_I2H_LOGOUT_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001998 bfa_lps_logout_rsp(bfa, msg.logout_rsp);
1999 break;
2000
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07002001 case BFI_LPS_I2H_CVL_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002002 bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
2003 break;
2004
2005 default:
2006 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08002007 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002008 }
2009}
2010
Krishna Gudipati7826f302011-07-20 16:59:13 -07002011static void
2012bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
2013{
2014 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2015 struct bfa_aen_entry_s *aen_entry;
2016
2017 bfad_get_aen_entry(bfad, aen_entry);
2018 if (!aen_entry)
2019 return;
2020
2021 aen_entry->aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
2022 aen_entry->aen_data.port.pwwn = fcport->pwwn;
2023
2024 /* Send the AEN notification */
2025 bfad_im_post_vendor_event(aen_entry, bfad, ++fcport->bfa->bfa_aen_seq,
2026 BFA_AEN_CAT_PORT, event);
2027}
2028
Jing Huang5fbe25c2010-10-18 17:17:23 -07002029/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002030 * FC PORT state machine functions
2031 */
2032static void
2033bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
2034 enum bfa_fcport_sm_event event)
2035{
2036 bfa_trc(fcport->bfa, event);
2037
2038 switch (event) {
2039 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002040 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002041 * Start event after IOC is configured and BFA is started.
2042 */
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08002043 fcport->use_flash_cfg = BFA_TRUE;
2044
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002045 if (bfa_fcport_send_enable(fcport)) {
2046 bfa_trc(fcport->bfa, BFA_TRUE);
2047 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2048 } else {
2049 bfa_trc(fcport->bfa, BFA_FALSE);
2050 bfa_sm_set_state(fcport,
2051 bfa_fcport_sm_enabling_qwait);
2052 }
2053 break;
2054
2055 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002056 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002057 * Port is persistently configured to be in enabled state. Do
2058 * not change state. Port enabling is done when START event is
2059 * received.
2060 */
2061 break;
2062
2063 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002064 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002065 * If a port is persistently configured to be disabled, the
2066 * first event will a port disable request.
2067 */
2068 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2069 break;
2070
2071 case BFA_FCPORT_SM_HWFAIL:
2072 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2073 break;
2074
2075 default:
2076 bfa_sm_fault(fcport->bfa, event);
2077 }
2078}
2079
2080static void
2081bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
2082 enum bfa_fcport_sm_event event)
2083{
2084 char pwwn_buf[BFA_STRING_32];
2085 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2086 bfa_trc(fcport->bfa, event);
2087
2088 switch (event) {
2089 case BFA_FCPORT_SM_QRESUME:
2090 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2091 bfa_fcport_send_enable(fcport);
2092 break;
2093
2094 case BFA_FCPORT_SM_STOP:
2095 bfa_reqq_wcancel(&fcport->reqq_wait);
2096 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2097 break;
2098
2099 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002100 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002101 * Already enable is in progress.
2102 */
2103 break;
2104
2105 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002106 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002107 * Just send disable request to firmware when room becomes
2108 * available in request queue.
2109 */
2110 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2111 bfa_reqq_wcancel(&fcport->reqq_wait);
2112 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2113 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2114 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002115 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002116 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002117 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002118 break;
2119
2120 case BFA_FCPORT_SM_LINKUP:
2121 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002122 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002123 * Possible to get link events when doing back-to-back
2124 * enable/disables.
2125 */
2126 break;
2127
2128 case BFA_FCPORT_SM_HWFAIL:
2129 bfa_reqq_wcancel(&fcport->reqq_wait);
2130 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2131 break;
2132
2133 default:
2134 bfa_sm_fault(fcport->bfa, event);
2135 }
2136}
2137
2138static void
2139bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
2140 enum bfa_fcport_sm_event event)
2141{
2142 char pwwn_buf[BFA_STRING_32];
2143 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2144 bfa_trc(fcport->bfa, event);
2145
2146 switch (event) {
2147 case BFA_FCPORT_SM_FWRSP:
2148 case BFA_FCPORT_SM_LINKDOWN:
2149 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2150 break;
2151
2152 case BFA_FCPORT_SM_LINKUP:
2153 bfa_fcport_update_linkinfo(fcport);
2154 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
2155
Jing Huangd4b671c2010-12-26 21:46:35 -08002156 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002157 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2158 break;
2159
2160 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002161 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002162 * Already being enabled.
2163 */
2164 break;
2165
2166 case BFA_FCPORT_SM_DISABLE:
2167 if (bfa_fcport_send_disable(fcport))
2168 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2169 else
2170 bfa_sm_set_state(fcport,
2171 bfa_fcport_sm_disabling_qwait);
2172
2173 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2174 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2175 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002176 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002177 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002178 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002179 break;
2180
2181 case BFA_FCPORT_SM_STOP:
2182 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2183 break;
2184
2185 case BFA_FCPORT_SM_HWFAIL:
2186 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2187 break;
2188
2189 default:
2190 bfa_sm_fault(fcport->bfa, event);
2191 }
2192}
2193
2194static void
2195bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
2196 enum bfa_fcport_sm_event event)
2197{
2198 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2199 char pwwn_buf[BFA_STRING_32];
2200 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2201
2202 bfa_trc(fcport->bfa, event);
2203
2204 switch (event) {
2205 case BFA_FCPORT_SM_LINKUP:
2206 bfa_fcport_update_linkinfo(fcport);
2207 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
Jing Huangd4b671c2010-12-26 21:46:35 -08002208 WARN_ON(!fcport->event_cbfn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002209 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2210 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
2211 if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
2212
2213 bfa_trc(fcport->bfa,
2214 pevent->link_state.vc_fcf.fcf.fipenabled);
2215 bfa_trc(fcport->bfa,
2216 pevent->link_state.vc_fcf.fcf.fipfailed);
2217
2218 if (pevent->link_state.vc_fcf.fcf.fipfailed)
2219 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2220 BFA_PL_EID_FIP_FCF_DISC, 0,
2221 "FIP FCF Discovery Failed");
2222 else
2223 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2224 BFA_PL_EID_FIP_FCF_DISC, 0,
2225 "FIP FCF Discovered");
2226 }
2227
2228 bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
2229 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002230 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002231 "Base port online: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002232 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002233 break;
2234
2235 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002236 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002237 * Possible to get link down event.
2238 */
2239 break;
2240
2241 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002242 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002243 * Already enabled.
2244 */
2245 break;
2246
2247 case BFA_FCPORT_SM_DISABLE:
2248 if (bfa_fcport_send_disable(fcport))
2249 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2250 else
2251 bfa_sm_set_state(fcport,
2252 bfa_fcport_sm_disabling_qwait);
2253
2254 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2255 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2256 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002257 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002258 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002259 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002260 break;
2261
2262 case BFA_FCPORT_SM_STOP:
2263 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2264 break;
2265
2266 case BFA_FCPORT_SM_HWFAIL:
2267 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2268 break;
2269
2270 default:
2271 bfa_sm_fault(fcport->bfa, event);
2272 }
2273}
2274
2275static void
2276bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
2277 enum bfa_fcport_sm_event event)
2278{
2279 char pwwn_buf[BFA_STRING_32];
2280 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2281
2282 bfa_trc(fcport->bfa, event);
2283
2284 switch (event) {
2285 case BFA_FCPORT_SM_ENABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002286 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002287 * Already enabled.
2288 */
2289 break;
2290
2291 case BFA_FCPORT_SM_DISABLE:
2292 if (bfa_fcport_send_disable(fcport))
2293 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2294 else
2295 bfa_sm_set_state(fcport,
2296 bfa_fcport_sm_disabling_qwait);
2297
2298 bfa_fcport_reset_linkinfo(fcport);
2299 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2300 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2301 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
2302 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002303 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002304 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002305 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
Jing Huang88166242010-12-09 17:11:53 -08002306 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002307 "Base port disabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002308 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002309 break;
2310
2311 case BFA_FCPORT_SM_LINKDOWN:
2312 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
2313 bfa_fcport_reset_linkinfo(fcport);
2314 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2315 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2316 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
2317 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002318 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002319 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002320 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002321 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2322 } else {
Jing Huang88166242010-12-09 17:11:53 -08002323 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002324 "Base port (WWN = %s) "
2325 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002326 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2327 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002328 break;
2329
2330 case BFA_FCPORT_SM_STOP:
2331 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2332 bfa_fcport_reset_linkinfo(fcport);
2333 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002334 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002335 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002336 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002337 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2338 } else {
Jing Huang88166242010-12-09 17:11:53 -08002339 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002340 "Base port (WWN = %s) "
2341 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002342 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2343 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002344 break;
2345
2346 case BFA_FCPORT_SM_HWFAIL:
2347 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2348 bfa_fcport_reset_linkinfo(fcport);
2349 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
2350 wwn2str(pwwn_buf, fcport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002351 if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
Jing Huang88166242010-12-09 17:11:53 -08002352 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002353 "Base port offline: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002354 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
2355 } else {
Jing Huang88166242010-12-09 17:11:53 -08002356 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002357 "Base port (WWN = %s) "
2358 "lost fabric connectivity\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002359 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
2360 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002361 break;
2362
2363 default:
2364 bfa_sm_fault(fcport->bfa, event);
2365 }
2366}
2367
2368static void
2369bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
2370 enum bfa_fcport_sm_event event)
2371{
2372 bfa_trc(fcport->bfa, event);
2373
2374 switch (event) {
2375 case BFA_FCPORT_SM_QRESUME:
2376 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2377 bfa_fcport_send_disable(fcport);
2378 break;
2379
2380 case BFA_FCPORT_SM_STOP:
2381 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2382 bfa_reqq_wcancel(&fcport->reqq_wait);
2383 break;
2384
2385 case BFA_FCPORT_SM_ENABLE:
2386 bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
2387 break;
2388
2389 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002390 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002391 * Already being disabled.
2392 */
2393 break;
2394
2395 case BFA_FCPORT_SM_LINKUP:
2396 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002397 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002398 * Possible to get link events when doing back-to-back
2399 * enable/disables.
2400 */
2401 break;
2402
2403 case BFA_FCPORT_SM_HWFAIL:
2404 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2405 bfa_reqq_wcancel(&fcport->reqq_wait);
2406 break;
2407
2408 default:
2409 bfa_sm_fault(fcport->bfa, event);
2410 }
2411}
2412
2413static void
2414bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
2415 enum bfa_fcport_sm_event event)
2416{
2417 bfa_trc(fcport->bfa, event);
2418
2419 switch (event) {
2420 case BFA_FCPORT_SM_QRESUME:
2421 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
2422 bfa_fcport_send_disable(fcport);
2423 if (bfa_fcport_send_enable(fcport))
2424 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2425 else
2426 bfa_sm_set_state(fcport,
2427 bfa_fcport_sm_enabling_qwait);
2428 break;
2429
2430 case BFA_FCPORT_SM_STOP:
2431 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2432 bfa_reqq_wcancel(&fcport->reqq_wait);
2433 break;
2434
2435 case BFA_FCPORT_SM_ENABLE:
2436 break;
2437
2438 case BFA_FCPORT_SM_DISABLE:
2439 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
2440 break;
2441
2442 case BFA_FCPORT_SM_LINKUP:
2443 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002444 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002445 * Possible to get link events when doing back-to-back
2446 * enable/disables.
2447 */
2448 break;
2449
2450 case BFA_FCPORT_SM_HWFAIL:
2451 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2452 bfa_reqq_wcancel(&fcport->reqq_wait);
2453 break;
2454
2455 default:
2456 bfa_sm_fault(fcport->bfa, event);
2457 }
2458}
2459
2460static void
2461bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
2462 enum bfa_fcport_sm_event event)
2463{
2464 char pwwn_buf[BFA_STRING_32];
2465 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2466 bfa_trc(fcport->bfa, event);
2467
2468 switch (event) {
2469 case BFA_FCPORT_SM_FWRSP:
2470 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2471 break;
2472
2473 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002474 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002475 * Already being disabled.
2476 */
2477 break;
2478
2479 case BFA_FCPORT_SM_ENABLE:
2480 if (bfa_fcport_send_enable(fcport))
2481 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2482 else
2483 bfa_sm_set_state(fcport,
2484 bfa_fcport_sm_enabling_qwait);
2485
2486 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2487 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2488 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002489 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002490 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002491 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002492 break;
2493
2494 case BFA_FCPORT_SM_STOP:
2495 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2496 break;
2497
2498 case BFA_FCPORT_SM_LINKUP:
2499 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002500 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002501 * Possible to get link events when doing back-to-back
2502 * enable/disables.
2503 */
2504 break;
2505
2506 case BFA_FCPORT_SM_HWFAIL:
2507 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2508 break;
2509
2510 default:
2511 bfa_sm_fault(fcport->bfa, event);
2512 }
2513}
2514
2515static void
2516bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
2517 enum bfa_fcport_sm_event event)
2518{
2519 char pwwn_buf[BFA_STRING_32];
2520 struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
2521 bfa_trc(fcport->bfa, event);
2522
2523 switch (event) {
2524 case BFA_FCPORT_SM_START:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002525 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002526 * Ignore start event for a port that is disabled.
2527 */
2528 break;
2529
2530 case BFA_FCPORT_SM_STOP:
2531 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
2532 break;
2533
2534 case BFA_FCPORT_SM_ENABLE:
2535 if (bfa_fcport_send_enable(fcport))
2536 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2537 else
2538 bfa_sm_set_state(fcport,
2539 bfa_fcport_sm_enabling_qwait);
2540
2541 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
2542 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
2543 wwn2str(pwwn_buf, fcport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -08002544 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002545 "Base port enabled: WWN = %s\n", pwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002546 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002547 break;
2548
2549 case BFA_FCPORT_SM_DISABLE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002550 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002551 * Already disabled.
2552 */
2553 break;
2554
2555 case BFA_FCPORT_SM_HWFAIL:
2556 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
2557 break;
2558
2559 default:
2560 bfa_sm_fault(fcport->bfa, event);
2561 }
2562}
2563
2564static void
2565bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
2566 enum bfa_fcport_sm_event event)
2567{
2568 bfa_trc(fcport->bfa, event);
2569
2570 switch (event) {
2571 case BFA_FCPORT_SM_START:
2572 if (bfa_fcport_send_enable(fcport))
2573 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2574 else
2575 bfa_sm_set_state(fcport,
2576 bfa_fcport_sm_enabling_qwait);
2577 break;
2578
2579 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002580 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002581 * Ignore all other events.
2582 */
2583 ;
2584 }
2585}
2586
Jing Huang5fbe25c2010-10-18 17:17:23 -07002587/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002588 * Port is enabled. IOC is down/failed.
2589 */
2590static void
2591bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
2592 enum bfa_fcport_sm_event event)
2593{
2594 bfa_trc(fcport->bfa, event);
2595
2596 switch (event) {
2597 case BFA_FCPORT_SM_START:
2598 if (bfa_fcport_send_enable(fcport))
2599 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
2600 else
2601 bfa_sm_set_state(fcport,
2602 bfa_fcport_sm_enabling_qwait);
2603 break;
2604
2605 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002606 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002607 * Ignore all events.
2608 */
2609 ;
2610 }
2611}
2612
Jing Huang5fbe25c2010-10-18 17:17:23 -07002613/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002614 * Port is disabled. IOC is down/failed.
2615 */
2616static void
2617bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
2618 enum bfa_fcport_sm_event event)
2619{
2620 bfa_trc(fcport->bfa, event);
2621
2622 switch (event) {
2623 case BFA_FCPORT_SM_START:
2624 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
2625 break;
2626
2627 case BFA_FCPORT_SM_ENABLE:
2628 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
2629 break;
2630
2631 default:
Jing Huang5fbe25c2010-10-18 17:17:23 -07002632 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002633 * Ignore all events.
2634 */
2635 ;
2636 }
2637}
2638
Jing Huang5fbe25c2010-10-18 17:17:23 -07002639/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002640 * Link state is down
2641 */
2642static void
2643bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
2644 enum bfa_fcport_ln_sm_event event)
2645{
2646 bfa_trc(ln->fcport->bfa, event);
2647
2648 switch (event) {
2649 case BFA_FCPORT_LN_SM_LINKUP:
2650 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2651 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2652 break;
2653
2654 default:
2655 bfa_sm_fault(ln->fcport->bfa, event);
2656 }
2657}
2658
Jing Huang5fbe25c2010-10-18 17:17:23 -07002659/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002660 * Link state is waiting for down notification
2661 */
2662static void
2663bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
2664 enum bfa_fcport_ln_sm_event event)
2665{
2666 bfa_trc(ln->fcport->bfa, event);
2667
2668 switch (event) {
2669 case BFA_FCPORT_LN_SM_LINKUP:
2670 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2671 break;
2672
2673 case BFA_FCPORT_LN_SM_NOTIFICATION:
2674 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
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 down notification and there is a pending up
2684 */
2685static void
2686bfa_fcport_ln_sm_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_dn_nf);
2694 break;
2695
2696 case BFA_FCPORT_LN_SM_NOTIFICATION:
2697 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
2698 bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
2699 break;
2700
2701 default:
2702 bfa_sm_fault(ln->fcport->bfa, event);
2703 }
2704}
2705
Jing Huang5fbe25c2010-10-18 17:17:23 -07002706/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002707 * Link state is up
2708 */
2709static void
2710bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
2711 enum bfa_fcport_ln_sm_event event)
2712{
2713 bfa_trc(ln->fcport->bfa, event);
2714
2715 switch (event) {
2716 case BFA_FCPORT_LN_SM_LINKDOWN:
2717 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2718 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2719 break;
2720
2721 default:
2722 bfa_sm_fault(ln->fcport->bfa, event);
2723 }
2724}
2725
Jing Huang5fbe25c2010-10-18 17:17:23 -07002726/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002727 * Link state is waiting for up notification
2728 */
2729static void
2730bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
2731 enum bfa_fcport_ln_sm_event event)
2732{
2733 bfa_trc(ln->fcport->bfa, event);
2734
2735 switch (event) {
2736 case BFA_FCPORT_LN_SM_LINKDOWN:
2737 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2738 break;
2739
2740 case BFA_FCPORT_LN_SM_NOTIFICATION:
2741 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
2742 break;
2743
2744 default:
2745 bfa_sm_fault(ln->fcport->bfa, event);
2746 }
2747}
2748
Jing Huang5fbe25c2010-10-18 17:17:23 -07002749/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002750 * Link state is waiting for up notification and there is a pending down
2751 */
2752static void
2753bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
2754 enum bfa_fcport_ln_sm_event event)
2755{
2756 bfa_trc(ln->fcport->bfa, event);
2757
2758 switch (event) {
2759 case BFA_FCPORT_LN_SM_LINKUP:
2760 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
2761 break;
2762
2763 case BFA_FCPORT_LN_SM_NOTIFICATION:
2764 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
2765 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2766 break;
2767
2768 default:
2769 bfa_sm_fault(ln->fcport->bfa, event);
2770 }
2771}
2772
Jing Huang5fbe25c2010-10-18 17:17:23 -07002773/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002774 * Link state is waiting for up notification and there are pending down and up
2775 */
2776static void
2777bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
2778 enum bfa_fcport_ln_sm_event event)
2779{
2780 bfa_trc(ln->fcport->bfa, event);
2781
2782 switch (event) {
2783 case BFA_FCPORT_LN_SM_LINKDOWN:
2784 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
2785 break;
2786
2787 case BFA_FCPORT_LN_SM_NOTIFICATION:
2788 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
2789 bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
2790 break;
2791
2792 default:
2793 bfa_sm_fault(ln->fcport->bfa, event);
2794 }
2795}
2796
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002797static void
2798__bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
2799{
2800 struct bfa_fcport_ln_s *ln = cbarg;
2801
2802 if (complete)
2803 ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
2804 else
2805 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2806}
2807
Jing Huang5fbe25c2010-10-18 17:17:23 -07002808/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002809 * Send SCN notification to upper layers.
2810 * trunk - false if caller is fcport to ignore fcport event in trunked mode
2811 */
2812static void
2813bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
2814 bfa_boolean_t trunk)
2815{
2816 if (fcport->cfg.trunked && !trunk)
2817 return;
2818
2819 switch (event) {
2820 case BFA_PORT_LINKUP:
2821 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
2822 break;
2823 case BFA_PORT_LINKDOWN:
2824 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
2825 break;
2826 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08002827 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002828 }
2829}
2830
2831static void
2832bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
2833{
2834 struct bfa_fcport_s *fcport = ln->fcport;
2835
2836 if (fcport->bfa->fcs) {
2837 fcport->event_cbfn(fcport->event_cbarg, event);
2838 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2839 } else {
2840 ln->ln_event = event;
2841 bfa_cb_queue(fcport->bfa, &ln->ln_qe,
2842 __bfa_cb_fcport_event, ln);
2843 }
2844}
2845
2846#define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
2847 BFA_CACHELINE_SZ))
2848
2849static void
Krishna Gudipati45070252011-06-24 20:24:29 -07002850bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
2851 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002852{
Krishna Gudipati45070252011-06-24 20:24:29 -07002853 struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa);
2854
2855 bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002856}
2857
2858static void
2859bfa_fcport_qresume(void *cbarg)
2860{
2861 struct bfa_fcport_s *fcport = cbarg;
2862
2863 bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
2864}
2865
2866static void
Krishna Gudipati45070252011-06-24 20:24:29 -07002867bfa_fcport_mem_claim(struct bfa_fcport_s *fcport)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002868{
Krishna Gudipati45070252011-06-24 20:24:29 -07002869 struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002870
Krishna Gudipati45070252011-06-24 20:24:29 -07002871 fcport->stats_kva = bfa_mem_dma_virt(fcport_dma);
2872 fcport->stats_pa = bfa_mem_dma_phys(fcport_dma);
2873 fcport->stats = (union bfa_fcport_stats_u *)
2874 bfa_mem_dma_virt(fcport_dma);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002875}
2876
Jing Huang5fbe25c2010-10-18 17:17:23 -07002877/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002878 * Memory initialization.
2879 */
2880static void
2881bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07002882 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002883{
2884 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2885 struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
2886 struct bfa_fcport_ln_s *ln = &fcport->ln;
Maggie Zhangf16a1752010-12-09 19:12:32 -08002887 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002888
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002889 fcport->bfa = bfa;
2890 ln->fcport = fcport;
2891
Krishna Gudipati45070252011-06-24 20:24:29 -07002892 bfa_fcport_mem_claim(fcport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002893
2894 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
2895 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2896
Jing Huang5fbe25c2010-10-18 17:17:23 -07002897 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002898 * initialize time stamp for stats reset
2899 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08002900 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002901 fcport->stats_reset_time = tv.tv_sec;
2902
Jing Huang5fbe25c2010-10-18 17:17:23 -07002903 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002904 * initialize and set default configuration
2905 */
2906 port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
2907 port_cfg->speed = BFA_PORT_SPEED_AUTO;
2908 port_cfg->trunked = BFA_FALSE;
2909 port_cfg->maxfrsize = 0;
2910
2911 port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
2912
2913 bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
2914}
2915
2916static void
2917bfa_fcport_detach(struct bfa_s *bfa)
2918{
2919}
2920
Jing Huang5fbe25c2010-10-18 17:17:23 -07002921/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002922 * Called when IOC is ready.
2923 */
2924static void
2925bfa_fcport_start(struct bfa_s *bfa)
2926{
2927 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
2928}
2929
Jing Huang5fbe25c2010-10-18 17:17:23 -07002930/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002931 * Called before IOC is stopped.
2932 */
2933static void
2934bfa_fcport_stop(struct bfa_s *bfa)
2935{
2936 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
2937 bfa_trunk_iocdisable(bfa);
2938}
2939
Jing Huang5fbe25c2010-10-18 17:17:23 -07002940/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002941 * Called when IOC failure is detected.
2942 */
2943static void
2944bfa_fcport_iocdisable(struct bfa_s *bfa)
2945{
2946 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
2947
2948 bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
2949 bfa_trunk_iocdisable(bfa);
2950}
2951
2952static void
2953bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
2954{
2955 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
2956 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
2957
2958 fcport->speed = pevent->link_state.speed;
2959 fcport->topology = pevent->link_state.topology;
2960
2961 if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)
2962 fcport->myalpa = 0;
2963
2964 /* QoS Details */
Jing Huang6a18b162010-10-18 17:08:54 -07002965 fcport->qos_attr = pevent->link_state.qos_attr;
2966 fcport->qos_vc_attr = pevent->link_state.vc_fcf.qos_vc_attr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002967
Jing Huang5fbe25c2010-10-18 17:17:23 -07002968 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002969 * update trunk state if applicable
2970 */
2971 if (!fcport->cfg.trunked)
2972 trunk->attr.state = BFA_TRUNK_DISABLED;
2973
2974 /* update FCoE specific */
Jing Huangba816ea2010-10-18 17:10:50 -07002975 fcport->fcoe_vlan = be16_to_cpu(pevent->link_state.vc_fcf.fcf.vlan);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002976
2977 bfa_trc(fcport->bfa, fcport->speed);
2978 bfa_trc(fcport->bfa, fcport->topology);
2979}
2980
2981static void
2982bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
2983{
2984 fcport->speed = BFA_PORT_SPEED_UNKNOWN;
2985 fcport->topology = BFA_PORT_TOPOLOGY_NONE;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07002986 fcport->bbsc_op_state = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002987}
2988
Jing Huang5fbe25c2010-10-18 17:17:23 -07002989/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002990 * Send port enable message to firmware.
2991 */
2992static bfa_boolean_t
2993bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
2994{
2995 struct bfi_fcport_enable_req_s *m;
2996
Jing Huang5fbe25c2010-10-18 17:17:23 -07002997 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002998 * Increment message tag before queue check, so that responses to old
2999 * requests are discarded.
3000 */
3001 fcport->msgtag++;
3002
Jing Huang5fbe25c2010-10-18 17:17:23 -07003003 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003004 * check for room in queue to send request now
3005 */
3006 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3007 if (!m) {
3008 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3009 &fcport->reqq_wait);
3010 return BFA_FALSE;
3011 }
3012
3013 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003014 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003015 m->nwwn = fcport->nwwn;
3016 m->pwwn = fcport->pwwn;
3017 m->port_cfg = fcport->cfg;
3018 m->msgtag = fcport->msgtag;
Jing Huangba816ea2010-10-18 17:10:50 -07003019 m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003020 m->use_flash_cfg = fcport->use_flash_cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003021 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
3022 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
3023 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
3024
Jing Huang5fbe25c2010-10-18 17:17:23 -07003025 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003026 * queue I/O message to firmware
3027 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003028 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003029 return BFA_TRUE;
3030}
3031
Jing Huang5fbe25c2010-10-18 17:17:23 -07003032/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003033 * Send port disable message to firmware.
3034 */
3035static bfa_boolean_t
3036bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
3037{
3038 struct bfi_fcport_req_s *m;
3039
Jing Huang5fbe25c2010-10-18 17:17:23 -07003040 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003041 * Increment message tag before queue check, so that responses to old
3042 * requests are discarded.
3043 */
3044 fcport->msgtag++;
3045
Jing Huang5fbe25c2010-10-18 17:17:23 -07003046 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003047 * check for room in queue to send request now
3048 */
3049 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3050 if (!m) {
3051 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3052 &fcport->reqq_wait);
3053 return BFA_FALSE;
3054 }
3055
3056 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003057 bfa_fn_lpu(fcport->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003058 m->msgtag = fcport->msgtag;
3059
Jing Huang5fbe25c2010-10-18 17:17:23 -07003060 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003061 * queue I/O message to firmware
3062 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003063 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003064
3065 return BFA_TRUE;
3066}
3067
3068static void
3069bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
3070{
Maggie Zhangf7f738122010-12-09 19:08:43 -08003071 fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
3072 fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003073
3074 bfa_trc(fcport->bfa, fcport->pwwn);
3075 bfa_trc(fcport->bfa, fcport->nwwn);
3076}
3077
3078static void
3079bfa_fcport_send_txcredit(void *port_cbarg)
3080{
3081
3082 struct bfa_fcport_s *fcport = port_cbarg;
3083 struct bfi_fcport_set_svc_params_req_s *m;
3084
Jing Huang5fbe25c2010-10-18 17:17:23 -07003085 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003086 * check for room in queue to send request now
3087 */
3088 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3089 if (!m) {
3090 bfa_trc(fcport->bfa, fcport->cfg.tx_bbcredit);
3091 return;
3092 }
3093
3094 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003095 bfa_fn_lpu(fcport->bfa));
Jing Huangba816ea2010-10-18 17:10:50 -07003096 m->tx_bbcredit = cpu_to_be16((u16)fcport->cfg.tx_bbcredit);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003097 m->bb_scn = fcport->cfg.bb_scn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003098
Jing Huang5fbe25c2010-10-18 17:17:23 -07003099 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003100 * queue I/O message to firmware
3101 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003102 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003103}
3104
3105static void
3106bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
3107 struct bfa_qos_stats_s *s)
3108{
3109 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003110 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003111 int i;
3112
3113 /* Now swap the 32 bit fields */
3114 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
Jing Huangba816ea2010-10-18 17:10:50 -07003115 dip[i] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003116}
3117
3118static void
3119bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
3120 struct bfa_fcoe_stats_s *s)
3121{
3122 u32 *dip = (u32 *) d;
Maggie50444a32010-11-29 18:26:32 -08003123 __be32 *sip = (__be32 *) s;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003124 int i;
3125
3126 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
3127 i = i + 2) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003128#ifdef __BIG_ENDIAN
Jing Huangba816ea2010-10-18 17:10:50 -07003129 dip[i] = be32_to_cpu(sip[i]);
3130 dip[i + 1] = be32_to_cpu(sip[i + 1]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003131#else
Jing Huangba816ea2010-10-18 17:10:50 -07003132 dip[i] = be32_to_cpu(sip[i + 1]);
3133 dip[i + 1] = be32_to_cpu(sip[i]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003134#endif
3135 }
3136}
3137
3138static void
3139__bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
3140{
3141 struct bfa_fcport_s *fcport = cbarg;
3142
3143 if (complete) {
3144 if (fcport->stats_status == BFA_STATUS_OK) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003145 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003146
3147 /* Swap FC QoS or FCoE stats */
3148 if (bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
3149 bfa_fcport_qos_stats_swap(
3150 &fcport->stats_ret->fcqos,
3151 &fcport->stats->fcqos);
3152 } else {
3153 bfa_fcport_fcoe_stats_swap(
3154 &fcport->stats_ret->fcoe,
3155 &fcport->stats->fcoe);
3156
Maggie Zhangf16a1752010-12-09 19:12:32 -08003157 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003158 fcport->stats_ret->fcoe.secs_reset =
3159 tv.tv_sec - fcport->stats_reset_time;
3160 }
3161 }
3162 fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
3163 } else {
3164 fcport->stats_busy = BFA_FALSE;
3165 fcport->stats_status = BFA_STATUS_OK;
3166 }
3167}
3168
3169static void
3170bfa_fcport_stats_get_timeout(void *cbarg)
3171{
3172 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3173
3174 bfa_trc(fcport->bfa, fcport->stats_qfull);
3175
3176 if (fcport->stats_qfull) {
3177 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3178 fcport->stats_qfull = BFA_FALSE;
3179 }
3180
3181 fcport->stats_status = BFA_STATUS_ETIMER;
3182 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, __bfa_cb_fcport_stats_get,
3183 fcport);
3184}
3185
3186static void
3187bfa_fcport_send_stats_get(void *cbarg)
3188{
3189 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3190 struct bfi_fcport_req_s *msg;
3191
3192 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3193
3194 if (!msg) {
3195 fcport->stats_qfull = BFA_TRUE;
3196 bfa_reqq_winit(&fcport->stats_reqq_wait,
3197 bfa_fcport_send_stats_get, fcport);
3198 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3199 &fcport->stats_reqq_wait);
3200 return;
3201 }
3202 fcport->stats_qfull = BFA_FALSE;
3203
Jing Huang6a18b162010-10-18 17:08:54 -07003204 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003205 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003206 bfa_fn_lpu(fcport->bfa));
3207 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003208}
3209
3210static void
3211__bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
3212{
3213 struct bfa_fcport_s *fcport = cbarg;
3214
3215 if (complete) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08003216 struct timeval tv;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003217
Jing Huang5fbe25c2010-10-18 17:17:23 -07003218 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003219 * re-initialize time stamp for stats reset
3220 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08003221 do_gettimeofday(&tv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003222 fcport->stats_reset_time = tv.tv_sec;
3223
3224 fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
3225 } else {
3226 fcport->stats_busy = BFA_FALSE;
3227 fcport->stats_status = BFA_STATUS_OK;
3228 }
3229}
3230
3231static void
3232bfa_fcport_stats_clr_timeout(void *cbarg)
3233{
3234 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3235
3236 bfa_trc(fcport->bfa, fcport->stats_qfull);
3237
3238 if (fcport->stats_qfull) {
3239 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
3240 fcport->stats_qfull = BFA_FALSE;
3241 }
3242
3243 fcport->stats_status = BFA_STATUS_ETIMER;
3244 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3245 __bfa_cb_fcport_stats_clr, fcport);
3246}
3247
3248static void
3249bfa_fcport_send_stats_clear(void *cbarg)
3250{
3251 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
3252 struct bfi_fcport_req_s *msg;
3253
3254 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3255
3256 if (!msg) {
3257 fcport->stats_qfull = BFA_TRUE;
3258 bfa_reqq_winit(&fcport->stats_reqq_wait,
3259 bfa_fcport_send_stats_clear, fcport);
3260 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
3261 &fcport->stats_reqq_wait);
3262 return;
3263 }
3264 fcport->stats_qfull = BFA_FALSE;
3265
Jing Huang6a18b162010-10-18 17:08:54 -07003266 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003267 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003268 bfa_fn_lpu(fcport->bfa));
3269 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003270}
3271
Jing Huang5fbe25c2010-10-18 17:17:23 -07003272/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003273 * Handle trunk SCN event from firmware.
3274 */
3275static void
3276bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3277{
3278 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
3279 struct bfi_fcport_trunk_link_s *tlink;
3280 struct bfa_trunk_link_attr_s *lattr;
3281 enum bfa_trunk_state state_prev;
3282 int i;
3283 int link_bm = 0;
3284
3285 bfa_trc(fcport->bfa, fcport->cfg.trunked);
Jing Huangd4b671c2010-12-26 21:46:35 -08003286 WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
3287 scn->trunk_state != BFA_TRUNK_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003288
3289 bfa_trc(fcport->bfa, trunk->attr.state);
3290 bfa_trc(fcport->bfa, scn->trunk_state);
3291 bfa_trc(fcport->bfa, scn->trunk_speed);
3292
Jing Huang5fbe25c2010-10-18 17:17:23 -07003293 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003294 * Save off new state for trunk attribute query
3295 */
3296 state_prev = trunk->attr.state;
3297 if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
3298 trunk->attr.state = scn->trunk_state;
3299 trunk->attr.speed = scn->trunk_speed;
3300 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3301 lattr = &trunk->attr.link_attr[i];
3302 tlink = &scn->tlink[i];
3303
3304 lattr->link_state = tlink->state;
3305 lattr->trunk_wwn = tlink->trunk_wwn;
3306 lattr->fctl = tlink->fctl;
3307 lattr->speed = tlink->speed;
Jing Huangba816ea2010-10-18 17:10:50 -07003308 lattr->deskew = be32_to_cpu(tlink->deskew);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003309
3310 if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
3311 fcport->speed = tlink->speed;
3312 fcport->topology = BFA_PORT_TOPOLOGY_P2P;
3313 link_bm |= 1 << i;
3314 }
3315
3316 bfa_trc(fcport->bfa, lattr->link_state);
3317 bfa_trc(fcport->bfa, lattr->trunk_wwn);
3318 bfa_trc(fcport->bfa, lattr->fctl);
3319 bfa_trc(fcport->bfa, lattr->speed);
3320 bfa_trc(fcport->bfa, lattr->deskew);
3321 }
3322
3323 switch (link_bm) {
3324 case 3:
3325 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3326 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
3327 break;
3328 case 2:
3329 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3330 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
3331 break;
3332 case 1:
3333 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3334 BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
3335 break;
3336 default:
3337 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
3338 BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
3339 }
3340
Jing Huang5fbe25c2010-10-18 17:17:23 -07003341 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003342 * Notify upper layers if trunk state changed.
3343 */
3344 if ((state_prev != trunk->attr.state) ||
3345 (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
3346 bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
3347 BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
3348 }
3349}
3350
3351static void
3352bfa_trunk_iocdisable(struct bfa_s *bfa)
3353{
3354 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3355 int i = 0;
3356
Jing Huang5fbe25c2010-10-18 17:17:23 -07003357 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003358 * In trunked mode, notify upper layers that link is down
3359 */
3360 if (fcport->cfg.trunked) {
3361 if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
3362 bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
3363
3364 fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
3365 fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
3366 for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
3367 fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
3368 fcport->trunk.attr.link_attr[i].fctl =
3369 BFA_TRUNK_LINK_FCTL_NORMAL;
3370 fcport->trunk.attr.link_attr[i].link_state =
3371 BFA_TRUNK_LINK_STATE_DN_LINKDN;
3372 fcport->trunk.attr.link_attr[i].speed =
3373 BFA_PORT_SPEED_UNKNOWN;
3374 fcport->trunk.attr.link_attr[i].deskew = 0;
3375 }
3376 }
3377}
3378
Jing Huang5fbe25c2010-10-18 17:17:23 -07003379/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003380 * Called to initialize port attributes
3381 */
3382void
3383bfa_fcport_init(struct bfa_s *bfa)
3384{
3385 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3386
Jing Huang5fbe25c2010-10-18 17:17:23 -07003387 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003388 * Initialize port attributes from IOC hardware data.
3389 */
3390 bfa_fcport_set_wwns(fcport);
3391 if (fcport->cfg.maxfrsize == 0)
3392 fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
3393 fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
3394 fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
3395
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003396 if (bfa_fcport_is_pbcdisabled(bfa))
3397 bfa->modules.port.pbc_disabled = BFA_TRUE;
3398
Jing Huangd4b671c2010-12-26 21:46:35 -08003399 WARN_ON(!fcport->cfg.maxfrsize);
3400 WARN_ON(!fcport->cfg.rx_bbcredit);
3401 WARN_ON(!fcport->speed_sup);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003402}
3403
Jing Huang5fbe25c2010-10-18 17:17:23 -07003404/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003405 * Firmware message handler.
3406 */
3407void
3408bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
3409{
3410 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3411 union bfi_fcport_i2h_msg_u i2hmsg;
3412
3413 i2hmsg.msg = msg;
3414 fcport->event_arg.i2hmsg = i2hmsg;
3415
3416 bfa_trc(bfa, msg->mhdr.msg_id);
3417 bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
3418
3419 switch (msg->mhdr.msg_id) {
3420 case BFI_FCPORT_I2H_ENABLE_RSP:
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003421 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
3422
3423 if (fcport->use_flash_cfg) {
3424 fcport->cfg = i2hmsg.penable_rsp->port_cfg;
3425 fcport->cfg.maxfrsize =
3426 cpu_to_be16(fcport->cfg.maxfrsize);
3427 fcport->cfg.path_tov =
3428 cpu_to_be16(fcport->cfg.path_tov);
3429 fcport->cfg.q_depth =
3430 cpu_to_be16(fcport->cfg.q_depth);
3431
3432 if (fcport->cfg.trunked)
3433 fcport->trunk.attr.state =
3434 BFA_TRUNK_OFFLINE;
3435 else
3436 fcport->trunk.attr.state =
3437 BFA_TRUNK_DISABLED;
3438 fcport->use_flash_cfg = BFA_FALSE;
3439 }
3440
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003441 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Krishna Gudipatif3a060c2010-12-13 16:16:50 -08003442 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003443 break;
3444
3445 case BFI_FCPORT_I2H_DISABLE_RSP:
3446 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
3447 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
3448 break;
3449
3450 case BFI_FCPORT_I2H_EVENT:
3451 if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
3452 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
3453 else
3454 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
3455 break;
3456
3457 case BFI_FCPORT_I2H_TRUNK_SCN:
3458 bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
3459 break;
3460
3461 case BFI_FCPORT_I2H_STATS_GET_RSP:
3462 /*
3463 * check for timer pop before processing the rsp
3464 */
3465 if (fcport->stats_busy == BFA_FALSE ||
3466 fcport->stats_status == BFA_STATUS_ETIMER)
3467 break;
3468
3469 bfa_timer_stop(&fcport->timer);
3470 fcport->stats_status = i2hmsg.pstatsget_rsp->status;
3471 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3472 __bfa_cb_fcport_stats_get, fcport);
3473 break;
3474
3475 case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
3476 /*
3477 * check for timer pop before processing the rsp
3478 */
3479 if (fcport->stats_busy == BFA_FALSE ||
3480 fcport->stats_status == BFA_STATUS_ETIMER)
3481 break;
3482
3483 bfa_timer_stop(&fcport->timer);
3484 fcport->stats_status = BFA_STATUS_OK;
3485 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
3486 __bfa_cb_fcport_stats_clr, fcport);
3487 break;
3488
3489 case BFI_FCPORT_I2H_ENABLE_AEN:
3490 bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
3491 break;
3492
3493 case BFI_FCPORT_I2H_DISABLE_AEN:
3494 bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
3495 break;
3496
3497 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08003498 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003499 break;
3500 }
3501}
3502
Jing Huang5fbe25c2010-10-18 17:17:23 -07003503/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003504 * Registered callback for port events.
3505 */
3506void
3507bfa_fcport_event_register(struct bfa_s *bfa,
3508 void (*cbfn) (void *cbarg,
3509 enum bfa_port_linkstate event),
3510 void *cbarg)
3511{
3512 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3513
3514 fcport->event_cbfn = cbfn;
3515 fcport->event_cbarg = cbarg;
3516}
3517
3518bfa_status_t
3519bfa_fcport_enable(struct bfa_s *bfa)
3520{
3521 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3522
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003523 if (bfa_fcport_is_pbcdisabled(bfa))
3524 return BFA_STATUS_PBC;
3525
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003526 if (bfa_ioc_is_disabled(&bfa->ioc))
3527 return BFA_STATUS_IOC_DISABLED;
3528
3529 if (fcport->diag_busy)
3530 return BFA_STATUS_DIAG_BUSY;
3531
3532 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
3533 return BFA_STATUS_OK;
3534}
3535
3536bfa_status_t
3537bfa_fcport_disable(struct bfa_s *bfa)
3538{
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003539 if (bfa_fcport_is_pbcdisabled(bfa))
3540 return BFA_STATUS_PBC;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003541
3542 if (bfa_ioc_is_disabled(&bfa->ioc))
3543 return BFA_STATUS_IOC_DISABLED;
3544
3545 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
3546 return BFA_STATUS_OK;
3547}
3548
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003549/* If PBC is disabled on port, return error */
3550bfa_status_t
3551bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
3552{
3553 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3554 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
3555 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
3556
3557 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
3558 bfa_trc(bfa, fcport->pwwn);
3559 return BFA_STATUS_PBC;
3560 }
3561 return BFA_STATUS_OK;
3562}
3563
Jing Huang5fbe25c2010-10-18 17:17:23 -07003564/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003565 * Configure port speed.
3566 */
3567bfa_status_t
3568bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3569{
3570 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3571
3572 bfa_trc(bfa, speed);
3573
3574 if (fcport->cfg.trunked == BFA_TRUE)
3575 return BFA_STATUS_TRUNK_ENABLED;
3576 if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
3577 bfa_trc(bfa, fcport->speed_sup);
3578 return BFA_STATUS_UNSUPP_SPEED;
3579 }
3580
Krishna Gudipatia7141342011-06-24 20:23:19 -07003581 /* For Mezz card, port speed entered needs to be checked */
3582 if (bfa_mfg_is_mezz(fcport->bfa->ioc.attr->card_type)) {
3583 if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
3584 /* For CT2, 1G is not supported */
3585 if ((speed == BFA_PORT_SPEED_1GBPS) &&
3586 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
3587 return BFA_STATUS_UNSUPP_SPEED;
3588
3589 /* Already checked for Auto Speed and Max Speed supp */
3590 if (!(speed == BFA_PORT_SPEED_1GBPS ||
3591 speed == BFA_PORT_SPEED_2GBPS ||
3592 speed == BFA_PORT_SPEED_4GBPS ||
3593 speed == BFA_PORT_SPEED_8GBPS ||
3594 speed == BFA_PORT_SPEED_16GBPS ||
3595 speed == BFA_PORT_SPEED_AUTO))
3596 return BFA_STATUS_UNSUPP_SPEED;
3597 } else {
3598 if (speed != BFA_PORT_SPEED_10GBPS)
3599 return BFA_STATUS_UNSUPP_SPEED;
3600 }
3601 }
3602
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003603 fcport->cfg.speed = speed;
3604
3605 return BFA_STATUS_OK;
3606}
3607
Jing Huang5fbe25c2010-10-18 17:17:23 -07003608/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003609 * Get current speed.
3610 */
3611enum bfa_port_speed
3612bfa_fcport_get_speed(struct bfa_s *bfa)
3613{
3614 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3615
3616 return fcport->speed;
3617}
3618
Jing Huang5fbe25c2010-10-18 17:17:23 -07003619/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003620 * Configure port topology.
3621 */
3622bfa_status_t
3623bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
3624{
3625 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3626
3627 bfa_trc(bfa, topology);
3628 bfa_trc(bfa, fcport->cfg.topology);
3629
3630 switch (topology) {
3631 case BFA_PORT_TOPOLOGY_P2P:
3632 case BFA_PORT_TOPOLOGY_LOOP:
3633 case BFA_PORT_TOPOLOGY_AUTO:
3634 break;
3635
3636 default:
3637 return BFA_STATUS_EINVAL;
3638 }
3639
3640 fcport->cfg.topology = topology;
3641 return BFA_STATUS_OK;
3642}
3643
Jing Huang5fbe25c2010-10-18 17:17:23 -07003644/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003645 * Get current topology.
3646 */
3647enum bfa_port_topology
3648bfa_fcport_get_topology(struct bfa_s *bfa)
3649{
3650 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3651
3652 return fcport->topology;
3653}
3654
3655bfa_status_t
3656bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
3657{
3658 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3659
3660 bfa_trc(bfa, alpa);
3661 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3662 bfa_trc(bfa, fcport->cfg.hardalpa);
3663
3664 fcport->cfg.cfg_hardalpa = BFA_TRUE;
3665 fcport->cfg.hardalpa = alpa;
3666
3667 return BFA_STATUS_OK;
3668}
3669
3670bfa_status_t
3671bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
3672{
3673 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3674
3675 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
3676 bfa_trc(bfa, fcport->cfg.hardalpa);
3677
3678 fcport->cfg.cfg_hardalpa = BFA_FALSE;
3679 return BFA_STATUS_OK;
3680}
3681
3682bfa_boolean_t
3683bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
3684{
3685 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3686
3687 *alpa = fcport->cfg.hardalpa;
3688 return fcport->cfg.cfg_hardalpa;
3689}
3690
3691u8
3692bfa_fcport_get_myalpa(struct bfa_s *bfa)
3693{
3694 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3695
3696 return fcport->myalpa;
3697}
3698
3699bfa_status_t
3700bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
3701{
3702 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3703
3704 bfa_trc(bfa, maxfrsize);
3705 bfa_trc(bfa, fcport->cfg.maxfrsize);
3706
3707 /* with in range */
3708 if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
3709 return BFA_STATUS_INVLD_DFSZ;
3710
3711 /* power of 2, if not the max frame size of 2112 */
3712 if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
3713 return BFA_STATUS_INVLD_DFSZ;
3714
3715 fcport->cfg.maxfrsize = maxfrsize;
3716 return BFA_STATUS_OK;
3717}
3718
3719u16
3720bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
3721{
3722 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3723
3724 return fcport->cfg.maxfrsize;
3725}
3726
3727u8
3728bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
3729{
3730 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3731
3732 return fcport->cfg.rx_bbcredit;
3733}
3734
3735void
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003736bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit, u8 bb_scn)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003737{
3738 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3739
3740 fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003741 fcport->cfg.bb_scn = bb_scn;
3742 if (bb_scn)
3743 fcport->bbsc_op_state = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003744 bfa_fcport_send_txcredit(fcport);
3745}
3746
Jing Huang5fbe25c2010-10-18 17:17:23 -07003747/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003748 * Get port attributes.
3749 */
3750
3751wwn_t
3752bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
3753{
3754 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3755 if (node)
3756 return fcport->nwwn;
3757 else
3758 return fcport->pwwn;
3759}
3760
3761void
3762bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3763{
3764 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3765
Jing Huang6a18b162010-10-18 17:08:54 -07003766 memset(attr, 0, sizeof(struct bfa_port_attr_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003767
3768 attr->nwwn = fcport->nwwn;
3769 attr->pwwn = fcport->pwwn;
3770
Maggie Zhangf7f738122010-12-09 19:08:43 -08003771 attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
3772 attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003773
Jing Huang6a18b162010-10-18 17:08:54 -07003774 memcpy(&attr->pport_cfg, &fcport->cfg,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003775 sizeof(struct bfa_port_cfg_s));
3776 /* speed attributes */
3777 attr->pport_cfg.speed = fcport->cfg.speed;
3778 attr->speed_supported = fcport->speed_sup;
3779 attr->speed = fcport->speed;
3780 attr->cos_supported = FC_CLASS_3;
3781
3782 /* topology attributes */
3783 attr->pport_cfg.topology = fcport->cfg.topology;
3784 attr->topology = fcport->topology;
3785 attr->pport_cfg.trunked = fcport->cfg.trunked;
3786
3787 /* beacon attributes */
3788 attr->beacon = fcport->beacon;
3789 attr->link_e2e_beacon = fcport->link_e2e_beacon;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003790
3791 attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
3792 attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
3793 attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003794 attr->bbsc_op_status = fcport->bbsc_op_state;
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003795
3796 /* PBC Disabled State */
3797 if (bfa_fcport_is_pbcdisabled(bfa))
3798 attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
3799 else {
3800 if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
3801 attr->port_state = BFA_PORT_ST_IOCDIS;
3802 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
3803 attr->port_state = BFA_PORT_ST_FWMISMATCH;
Krishna Gudipatia7141342011-06-24 20:23:19 -07003804 else if (bfa_ioc_is_acq_addr(&fcport->bfa->ioc))
3805 attr->port_state = BFA_PORT_ST_ACQ_ADDR;
Krishna Gudipati43ffdf42011-06-13 15:46:21 -07003806 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003807
3808 /* FCoE vlan */
3809 attr->fcoe_vlan = fcport->fcoe_vlan;
3810}
3811
3812#define BFA_FCPORT_STATS_TOV 1000
3813
Jing Huang5fbe25c2010-10-18 17:17:23 -07003814/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003815 * Fetch port statistics (FCQoS or FCoE).
3816 */
3817bfa_status_t
3818bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
3819 bfa_cb_port_t cbfn, void *cbarg)
3820{
3821 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3822
3823 if (fcport->stats_busy) {
3824 bfa_trc(bfa, fcport->stats_busy);
3825 return BFA_STATUS_DEVBUSY;
3826 }
3827
3828 fcport->stats_busy = BFA_TRUE;
3829 fcport->stats_ret = stats;
3830 fcport->stats_cbfn = cbfn;
3831 fcport->stats_cbarg = cbarg;
3832
3833 bfa_fcport_send_stats_get(fcport);
3834
3835 bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_get_timeout,
3836 fcport, BFA_FCPORT_STATS_TOV);
3837 return BFA_STATUS_OK;
3838}
3839
Jing Huang5fbe25c2010-10-18 17:17:23 -07003840/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003841 * Reset port statistics (FCQoS or FCoE).
3842 */
3843bfa_status_t
3844bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_port_t cbfn, void *cbarg)
3845{
3846 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3847
3848 if (fcport->stats_busy) {
3849 bfa_trc(bfa, fcport->stats_busy);
3850 return BFA_STATUS_DEVBUSY;
3851 }
3852
3853 fcport->stats_busy = BFA_TRUE;
3854 fcport->stats_cbfn = cbfn;
3855 fcport->stats_cbarg = cbarg;
3856
3857 bfa_fcport_send_stats_clear(fcport);
3858
3859 bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_clr_timeout,
3860 fcport, BFA_FCPORT_STATS_TOV);
3861 return BFA_STATUS_OK;
3862}
3863
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003864
Jing Huang5fbe25c2010-10-18 17:17:23 -07003865/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003866 * Fetch port attributes.
3867 */
3868bfa_boolean_t
3869bfa_fcport_is_disabled(struct bfa_s *bfa)
3870{
3871 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3872
3873 return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
3874 BFA_PORT_ST_DISABLED;
3875
3876}
3877
3878bfa_boolean_t
3879bfa_fcport_is_ratelim(struct bfa_s *bfa)
3880{
3881 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3882
3883 return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
3884
3885}
3886
Jing Huang5fbe25c2010-10-18 17:17:23 -07003887/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07003888 * Enable/Disable FAA feature in port config
3889 */
3890void
3891bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state)
3892{
3893 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3894
3895 bfa_trc(bfa, state);
3896 fcport->cfg.faa_state = state;
3897}
3898
3899/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003900 * Get default minimum ratelim speed
3901 */
3902enum bfa_port_speed
3903bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
3904{
3905 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3906
3907 bfa_trc(bfa, fcport->cfg.trl_def_speed);
3908 return fcport->cfg.trl_def_speed;
3909
3910}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003911
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07003912void
3913bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
3914 bfa_boolean_t link_e2e_beacon)
3915{
3916 struct bfa_s *bfa = dev;
3917 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3918
3919 bfa_trc(bfa, beacon);
3920 bfa_trc(bfa, link_e2e_beacon);
3921 bfa_trc(bfa, fcport->beacon);
3922 bfa_trc(bfa, fcport->link_e2e_beacon);
3923
3924 fcport->beacon = beacon;
3925 fcport->link_e2e_beacon = link_e2e_beacon;
3926}
3927
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003928bfa_boolean_t
3929bfa_fcport_is_linkup(struct bfa_s *bfa)
3930{
3931 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3932
3933 return (!fcport->cfg.trunked &&
3934 bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
3935 (fcport->cfg.trunked &&
3936 fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
3937}
3938
3939bfa_boolean_t
3940bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
3941{
3942 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3943
3944 return fcport->cfg.qos_enabled;
3945}
3946
Krishna Gudipatibe540a92011-06-13 15:53:04 -07003947bfa_boolean_t
3948bfa_fcport_is_trunk_enabled(struct bfa_s *bfa)
3949{
3950 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3951
3952 return fcport->cfg.trunked;
3953}
3954
Jing Huang5fbe25c2010-10-18 17:17:23 -07003955/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003956 * Rport State machine functions
3957 */
Jing Huang5fbe25c2010-10-18 17:17:23 -07003958/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003959 * Beginning state, only online event expected.
3960 */
3961static void
3962bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
3963{
3964 bfa_trc(rp->bfa, rp->rport_tag);
3965 bfa_trc(rp->bfa, event);
3966
3967 switch (event) {
3968 case BFA_RPORT_SM_CREATE:
3969 bfa_stats(rp, sm_un_cr);
3970 bfa_sm_set_state(rp, bfa_rport_sm_created);
3971 break;
3972
3973 default:
3974 bfa_stats(rp, sm_un_unexp);
3975 bfa_sm_fault(rp->bfa, event);
3976 }
3977}
3978
3979static void
3980bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
3981{
3982 bfa_trc(rp->bfa, rp->rport_tag);
3983 bfa_trc(rp->bfa, event);
3984
3985 switch (event) {
3986 case BFA_RPORT_SM_ONLINE:
3987 bfa_stats(rp, sm_cr_on);
3988 if (bfa_rport_send_fwcreate(rp))
3989 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
3990 else
3991 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
3992 break;
3993
3994 case BFA_RPORT_SM_DELETE:
3995 bfa_stats(rp, sm_cr_del);
3996 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
3997 bfa_rport_free(rp);
3998 break;
3999
4000 case BFA_RPORT_SM_HWFAIL:
4001 bfa_stats(rp, sm_cr_hwf);
4002 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4003 break;
4004
4005 default:
4006 bfa_stats(rp, sm_cr_unexp);
4007 bfa_sm_fault(rp->bfa, event);
4008 }
4009}
4010
Jing Huang5fbe25c2010-10-18 17:17:23 -07004011/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004012 * Waiting for rport create response from firmware.
4013 */
4014static void
4015bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
4016{
4017 bfa_trc(rp->bfa, rp->rport_tag);
4018 bfa_trc(rp->bfa, event);
4019
4020 switch (event) {
4021 case BFA_RPORT_SM_FWRSP:
4022 bfa_stats(rp, sm_fwc_rsp);
4023 bfa_sm_set_state(rp, bfa_rport_sm_online);
4024 bfa_rport_online_cb(rp);
4025 break;
4026
4027 case BFA_RPORT_SM_DELETE:
4028 bfa_stats(rp, sm_fwc_del);
4029 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4030 break;
4031
4032 case BFA_RPORT_SM_OFFLINE:
4033 bfa_stats(rp, sm_fwc_off);
4034 bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
4035 break;
4036
4037 case BFA_RPORT_SM_HWFAIL:
4038 bfa_stats(rp, sm_fwc_hwf);
4039 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4040 break;
4041
4042 default:
4043 bfa_stats(rp, sm_fwc_unexp);
4044 bfa_sm_fault(rp->bfa, event);
4045 }
4046}
4047
Jing Huang5fbe25c2010-10-18 17:17:23 -07004048/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004049 * Request queue is full, awaiting queue resume to send create request.
4050 */
4051static void
4052bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4053{
4054 bfa_trc(rp->bfa, rp->rport_tag);
4055 bfa_trc(rp->bfa, event);
4056
4057 switch (event) {
4058 case BFA_RPORT_SM_QRESUME:
4059 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4060 bfa_rport_send_fwcreate(rp);
4061 break;
4062
4063 case BFA_RPORT_SM_DELETE:
4064 bfa_stats(rp, sm_fwc_del);
4065 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4066 bfa_reqq_wcancel(&rp->reqq_wait);
4067 bfa_rport_free(rp);
4068 break;
4069
4070 case BFA_RPORT_SM_OFFLINE:
4071 bfa_stats(rp, sm_fwc_off);
4072 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4073 bfa_reqq_wcancel(&rp->reqq_wait);
4074 bfa_rport_offline_cb(rp);
4075 break;
4076
4077 case BFA_RPORT_SM_HWFAIL:
4078 bfa_stats(rp, sm_fwc_hwf);
4079 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4080 bfa_reqq_wcancel(&rp->reqq_wait);
4081 break;
4082
4083 default:
4084 bfa_stats(rp, sm_fwc_unexp);
4085 bfa_sm_fault(rp->bfa, event);
4086 }
4087}
4088
Jing Huang5fbe25c2010-10-18 17:17:23 -07004089/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004090 * Online state - normal parking state.
4091 */
4092static void
4093bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
4094{
4095 struct bfi_rport_qos_scn_s *qos_scn;
4096
4097 bfa_trc(rp->bfa, rp->rport_tag);
4098 bfa_trc(rp->bfa, event);
4099
4100 switch (event) {
4101 case BFA_RPORT_SM_OFFLINE:
4102 bfa_stats(rp, sm_on_off);
4103 if (bfa_rport_send_fwdelete(rp))
4104 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4105 else
4106 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4107 break;
4108
4109 case BFA_RPORT_SM_DELETE:
4110 bfa_stats(rp, sm_on_del);
4111 if (bfa_rport_send_fwdelete(rp))
4112 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4113 else
4114 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4115 break;
4116
4117 case BFA_RPORT_SM_HWFAIL:
4118 bfa_stats(rp, sm_on_hwf);
4119 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4120 break;
4121
4122 case BFA_RPORT_SM_SET_SPEED:
4123 bfa_rport_send_fwspeed(rp);
4124 break;
4125
4126 case BFA_RPORT_SM_QOS_SCN:
4127 qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
4128 rp->qos_attr = qos_scn->new_qos_attr;
4129 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
4130 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
4131 bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
4132 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
4133
4134 qos_scn->old_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004135 be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004136 qos_scn->new_qos_attr.qos_flow_id =
Jing Huangba816ea2010-10-18 17:10:50 -07004137 be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004138
4139 if (qos_scn->old_qos_attr.qos_flow_id !=
4140 qos_scn->new_qos_attr.qos_flow_id)
4141 bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
4142 qos_scn->old_qos_attr,
4143 qos_scn->new_qos_attr);
4144 if (qos_scn->old_qos_attr.qos_priority !=
4145 qos_scn->new_qos_attr.qos_priority)
4146 bfa_cb_rport_qos_scn_prio(rp->rport_drv,
4147 qos_scn->old_qos_attr,
4148 qos_scn->new_qos_attr);
4149 break;
4150
4151 default:
4152 bfa_stats(rp, sm_on_unexp);
4153 bfa_sm_fault(rp->bfa, event);
4154 }
4155}
4156
Jing Huang5fbe25c2010-10-18 17:17:23 -07004157/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004158 * Firmware rport is being deleted - awaiting f/w response.
4159 */
4160static void
4161bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
4162{
4163 bfa_trc(rp->bfa, rp->rport_tag);
4164 bfa_trc(rp->bfa, event);
4165
4166 switch (event) {
4167 case BFA_RPORT_SM_FWRSP:
4168 bfa_stats(rp, sm_fwd_rsp);
4169 bfa_sm_set_state(rp, bfa_rport_sm_offline);
4170 bfa_rport_offline_cb(rp);
4171 break;
4172
4173 case BFA_RPORT_SM_DELETE:
4174 bfa_stats(rp, sm_fwd_del);
4175 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4176 break;
4177
4178 case BFA_RPORT_SM_HWFAIL:
4179 bfa_stats(rp, sm_fwd_hwf);
4180 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4181 bfa_rport_offline_cb(rp);
4182 break;
4183
4184 default:
4185 bfa_stats(rp, sm_fwd_unexp);
4186 bfa_sm_fault(rp->bfa, event);
4187 }
4188}
4189
4190static void
4191bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4192{
4193 bfa_trc(rp->bfa, rp->rport_tag);
4194 bfa_trc(rp->bfa, event);
4195
4196 switch (event) {
4197 case BFA_RPORT_SM_QRESUME:
4198 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4199 bfa_rport_send_fwdelete(rp);
4200 break;
4201
4202 case BFA_RPORT_SM_DELETE:
4203 bfa_stats(rp, sm_fwd_del);
4204 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4205 break;
4206
4207 case BFA_RPORT_SM_HWFAIL:
4208 bfa_stats(rp, sm_fwd_hwf);
4209 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4210 bfa_reqq_wcancel(&rp->reqq_wait);
4211 bfa_rport_offline_cb(rp);
4212 break;
4213
4214 default:
4215 bfa_stats(rp, sm_fwd_unexp);
4216 bfa_sm_fault(rp->bfa, event);
4217 }
4218}
4219
Jing Huang5fbe25c2010-10-18 17:17:23 -07004220/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004221 * Offline state.
4222 */
4223static void
4224bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
4225{
4226 bfa_trc(rp->bfa, rp->rport_tag);
4227 bfa_trc(rp->bfa, event);
4228
4229 switch (event) {
4230 case BFA_RPORT_SM_DELETE:
4231 bfa_stats(rp, sm_off_del);
4232 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4233 bfa_rport_free(rp);
4234 break;
4235
4236 case BFA_RPORT_SM_ONLINE:
4237 bfa_stats(rp, sm_off_on);
4238 if (bfa_rport_send_fwcreate(rp))
4239 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4240 else
4241 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4242 break;
4243
4244 case BFA_RPORT_SM_HWFAIL:
4245 bfa_stats(rp, sm_off_hwf);
4246 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4247 break;
4248
4249 default:
4250 bfa_stats(rp, sm_off_unexp);
4251 bfa_sm_fault(rp->bfa, event);
4252 }
4253}
4254
Jing Huang5fbe25c2010-10-18 17:17:23 -07004255/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004256 * Rport is deleted, waiting for firmware response to delete.
4257 */
4258static void
4259bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
4260{
4261 bfa_trc(rp->bfa, rp->rport_tag);
4262 bfa_trc(rp->bfa, event);
4263
4264 switch (event) {
4265 case BFA_RPORT_SM_FWRSP:
4266 bfa_stats(rp, sm_del_fwrsp);
4267 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4268 bfa_rport_free(rp);
4269 break;
4270
4271 case BFA_RPORT_SM_HWFAIL:
4272 bfa_stats(rp, sm_del_hwf);
4273 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4274 bfa_rport_free(rp);
4275 break;
4276
4277 default:
4278 bfa_sm_fault(rp->bfa, event);
4279 }
4280}
4281
4282static void
4283bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4284{
4285 bfa_trc(rp->bfa, rp->rport_tag);
4286 bfa_trc(rp->bfa, event);
4287
4288 switch (event) {
4289 case BFA_RPORT_SM_QRESUME:
4290 bfa_stats(rp, sm_del_fwrsp);
4291 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4292 bfa_rport_send_fwdelete(rp);
4293 break;
4294
4295 case BFA_RPORT_SM_HWFAIL:
4296 bfa_stats(rp, sm_del_hwf);
4297 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4298 bfa_reqq_wcancel(&rp->reqq_wait);
4299 bfa_rport_free(rp);
4300 break;
4301
4302 default:
4303 bfa_sm_fault(rp->bfa, event);
4304 }
4305}
4306
Jing Huang5fbe25c2010-10-18 17:17:23 -07004307/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004308 * Waiting for rport create response from firmware. A delete is pending.
4309 */
4310static void
4311bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
4312 enum bfa_rport_event event)
4313{
4314 bfa_trc(rp->bfa, rp->rport_tag);
4315 bfa_trc(rp->bfa, event);
4316
4317 switch (event) {
4318 case BFA_RPORT_SM_FWRSP:
4319 bfa_stats(rp, sm_delp_fwrsp);
4320 if (bfa_rport_send_fwdelete(rp))
4321 bfa_sm_set_state(rp, bfa_rport_sm_deleting);
4322 else
4323 bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
4324 break;
4325
4326 case BFA_RPORT_SM_HWFAIL:
4327 bfa_stats(rp, sm_delp_hwf);
4328 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4329 bfa_rport_free(rp);
4330 break;
4331
4332 default:
4333 bfa_stats(rp, sm_delp_unexp);
4334 bfa_sm_fault(rp->bfa, event);
4335 }
4336}
4337
Jing Huang5fbe25c2010-10-18 17:17:23 -07004338/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004339 * Waiting for rport create response from firmware. Rport offline is pending.
4340 */
4341static void
4342bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
4343 enum bfa_rport_event event)
4344{
4345 bfa_trc(rp->bfa, rp->rport_tag);
4346 bfa_trc(rp->bfa, event);
4347
4348 switch (event) {
4349 case BFA_RPORT_SM_FWRSP:
4350 bfa_stats(rp, sm_offp_fwrsp);
4351 if (bfa_rport_send_fwdelete(rp))
4352 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
4353 else
4354 bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
4355 break;
4356
4357 case BFA_RPORT_SM_DELETE:
4358 bfa_stats(rp, sm_offp_del);
4359 bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
4360 break;
4361
4362 case BFA_RPORT_SM_HWFAIL:
4363 bfa_stats(rp, sm_offp_hwf);
4364 bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
4365 break;
4366
4367 default:
4368 bfa_stats(rp, sm_offp_unexp);
4369 bfa_sm_fault(rp->bfa, event);
4370 }
4371}
4372
Jing Huang5fbe25c2010-10-18 17:17:23 -07004373/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004374 * IOC h/w failed.
4375 */
4376static void
4377bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
4378{
4379 bfa_trc(rp->bfa, rp->rport_tag);
4380 bfa_trc(rp->bfa, event);
4381
4382 switch (event) {
4383 case BFA_RPORT_SM_OFFLINE:
4384 bfa_stats(rp, sm_iocd_off);
4385 bfa_rport_offline_cb(rp);
4386 break;
4387
4388 case BFA_RPORT_SM_DELETE:
4389 bfa_stats(rp, sm_iocd_del);
4390 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4391 bfa_rport_free(rp);
4392 break;
4393
4394 case BFA_RPORT_SM_ONLINE:
4395 bfa_stats(rp, sm_iocd_on);
4396 if (bfa_rport_send_fwcreate(rp))
4397 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
4398 else
4399 bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
4400 break;
4401
4402 case BFA_RPORT_SM_HWFAIL:
4403 break;
4404
4405 default:
4406 bfa_stats(rp, sm_iocd_unexp);
4407 bfa_sm_fault(rp->bfa, event);
4408 }
4409}
4410
4411
4412
Jing Huang5fbe25c2010-10-18 17:17:23 -07004413/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004414 * bfa_rport_private BFA rport private functions
4415 */
4416
4417static void
4418__bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
4419{
4420 struct bfa_rport_s *rp = cbarg;
4421
4422 if (complete)
4423 bfa_cb_rport_online(rp->rport_drv);
4424}
4425
4426static void
4427__bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
4428{
4429 struct bfa_rport_s *rp = cbarg;
4430
4431 if (complete)
4432 bfa_cb_rport_offline(rp->rport_drv);
4433}
4434
4435static void
4436bfa_rport_qresume(void *cbarg)
4437{
4438 struct bfa_rport_s *rp = cbarg;
4439
4440 bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
4441}
4442
4443static void
Krishna Gudipati45070252011-06-24 20:24:29 -07004444bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
4445 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004446{
Krishna Gudipati45070252011-06-24 20:24:29 -07004447 struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa);
4448
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004449 if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
4450 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
4451
Krishna Gudipati45070252011-06-24 20:24:29 -07004452 /* kva memory */
4453 bfa_mem_kva_setup(minfo, rport_kva,
4454 cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004455}
4456
4457static void
4458bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07004459 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004460{
4461 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4462 struct bfa_rport_s *rp;
4463 u16 i;
4464
4465 INIT_LIST_HEAD(&mod->rp_free_q);
4466 INIT_LIST_HEAD(&mod->rp_active_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004467 INIT_LIST_HEAD(&mod->rp_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004468
Krishna Gudipati45070252011-06-24 20:24:29 -07004469 rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004470 mod->rps_list = rp;
4471 mod->num_rports = cfg->fwcfg.num_rports;
4472
Jing Huangd4b671c2010-12-26 21:46:35 -08004473 WARN_ON(!mod->num_rports ||
4474 (mod->num_rports & (mod->num_rports - 1)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004475
4476 for (i = 0; i < mod->num_rports; i++, rp++) {
Jing Huang6a18b162010-10-18 17:08:54 -07004477 memset(rp, 0, sizeof(struct bfa_rport_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004478 rp->bfa = bfa;
4479 rp->rport_tag = i;
4480 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4481
Jing Huang5fbe25c2010-10-18 17:17:23 -07004482 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004483 * - is unused
4484 */
4485 if (i)
4486 list_add_tail(&rp->qe, &mod->rp_free_q);
4487
4488 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
4489 }
4490
Jing Huang5fbe25c2010-10-18 17:17:23 -07004491 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004492 * consume memory
4493 */
Krishna Gudipati45070252011-06-24 20:24:29 -07004494 bfa_mem_kva_curp(mod) = (u8 *) rp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004495}
4496
4497static void
4498bfa_rport_detach(struct bfa_s *bfa)
4499{
4500}
4501
4502static void
4503bfa_rport_start(struct bfa_s *bfa)
4504{
4505}
4506
4507static void
4508bfa_rport_stop(struct bfa_s *bfa)
4509{
4510}
4511
4512static void
4513bfa_rport_iocdisable(struct bfa_s *bfa)
4514{
4515 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4516 struct bfa_rport_s *rport;
4517 struct list_head *qe, *qen;
4518
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004519 /* Enqueue unused rport resources to free_q */
4520 list_splice_tail_init(&mod->rp_unused_q, &mod->rp_free_q);
4521
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004522 list_for_each_safe(qe, qen, &mod->rp_active_q) {
4523 rport = (struct bfa_rport_s *) qe;
4524 bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
4525 }
4526}
4527
4528static struct bfa_rport_s *
4529bfa_rport_alloc(struct bfa_rport_mod_s *mod)
4530{
4531 struct bfa_rport_s *rport;
4532
4533 bfa_q_deq(&mod->rp_free_q, &rport);
4534 if (rport)
4535 list_add_tail(&rport->qe, &mod->rp_active_q);
4536
4537 return rport;
4538}
4539
4540static void
4541bfa_rport_free(struct bfa_rport_s *rport)
4542{
4543 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
4544
Jing Huangd4b671c2010-12-26 21:46:35 -08004545 WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004546 list_del(&rport->qe);
4547 list_add_tail(&rport->qe, &mod->rp_free_q);
4548}
4549
4550static bfa_boolean_t
4551bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4552{
4553 struct bfi_rport_create_req_s *m;
4554
Jing Huang5fbe25c2010-10-18 17:17:23 -07004555 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004556 * check for room in queue to send request now
4557 */
4558 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4559 if (!m) {
4560 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4561 return BFA_FALSE;
4562 }
4563
4564 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004565 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004566 m->bfa_handle = rp->rport_tag;
Jing Huangba816ea2010-10-18 17:10:50 -07004567 m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004568 m->pid = rp->rport_info.pid;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004569 m->lp_fwtag = bfa_lps_get_fwtag(rp->bfa, (u8)rp->rport_info.lp_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004570 m->local_pid = rp->rport_info.local_pid;
4571 m->fc_class = rp->rport_info.fc_class;
4572 m->vf_en = rp->rport_info.vf_en;
4573 m->vf_id = rp->rport_info.vf_id;
4574 m->cisc = rp->rport_info.cisc;
4575
Jing Huang5fbe25c2010-10-18 17:17:23 -07004576 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004577 * queue I/O message to firmware
4578 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004579 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004580 return BFA_TRUE;
4581}
4582
4583static bfa_boolean_t
4584bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4585{
4586 struct bfi_rport_delete_req_s *m;
4587
Jing Huang5fbe25c2010-10-18 17:17:23 -07004588 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004589 * check for room in queue to send request now
4590 */
4591 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4592 if (!m) {
4593 bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
4594 return BFA_FALSE;
4595 }
4596
4597 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004598 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004599 m->fw_handle = rp->fw_handle;
4600
Jing Huang5fbe25c2010-10-18 17:17:23 -07004601 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004602 * queue I/O message to firmware
4603 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004604 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004605 return BFA_TRUE;
4606}
4607
4608static bfa_boolean_t
4609bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4610{
4611 struct bfa_rport_speed_req_s *m;
4612
Jing Huang5fbe25c2010-10-18 17:17:23 -07004613 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004614 * check for room in queue to send request now
4615 */
4616 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
4617 if (!m) {
4618 bfa_trc(rp->bfa, rp->rport_info.speed);
4619 return BFA_FALSE;
4620 }
4621
4622 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004623 bfa_fn_lpu(rp->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004624 m->fw_handle = rp->fw_handle;
4625 m->speed = (u8)rp->rport_info.speed;
4626
Jing Huang5fbe25c2010-10-18 17:17:23 -07004627 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004628 * queue I/O message to firmware
4629 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004630 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004631 return BFA_TRUE;
4632}
4633
4634
4635
Jing Huang5fbe25c2010-10-18 17:17:23 -07004636/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004637 * bfa_rport_public
4638 */
4639
Jing Huang5fbe25c2010-10-18 17:17:23 -07004640/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004641 * Rport interrupt processing.
4642 */
4643void
4644bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
4645{
4646 union bfi_rport_i2h_msg_u msg;
4647 struct bfa_rport_s *rp;
4648
4649 bfa_trc(bfa, m->mhdr.msg_id);
4650
4651 msg.msg = m;
4652
4653 switch (m->mhdr.msg_id) {
4654 case BFI_RPORT_I2H_CREATE_RSP:
4655 rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
4656 rp->fw_handle = msg.create_rsp->fw_handle;
4657 rp->qos_attr = msg.create_rsp->qos_attr;
Jing Huangd4b671c2010-12-26 21:46:35 -08004658 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004659 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4660 break;
4661
4662 case BFI_RPORT_I2H_DELETE_RSP:
4663 rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08004664 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004665 bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
4666 break;
4667
4668 case BFI_RPORT_I2H_QOS_SCN:
4669 rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
4670 rp->event_arg.fw_msg = msg.qos_scn_evt;
4671 bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
4672 break;
4673
4674 default:
4675 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08004676 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004677 }
4678}
4679
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004680void
4681bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw)
4682{
4683 struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
4684 struct list_head *qe;
4685 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004686
Krishna Gudipati3fd45982011-06-24 20:24:08 -07004687 for (i = 0; i < (mod->num_rports - num_rport_fw); i++) {
4688 bfa_q_deq_tail(&mod->rp_free_q, &qe);
4689 list_add_tail(qe, &mod->rp_unused_q);
4690 }
4691}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004692
Jing Huang5fbe25c2010-10-18 17:17:23 -07004693/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004694 * bfa_rport_api
4695 */
4696
4697struct bfa_rport_s *
4698bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
4699{
4700 struct bfa_rport_s *rp;
4701
4702 rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
4703
4704 if (rp == NULL)
4705 return NULL;
4706
4707 rp->bfa = bfa;
4708 rp->rport_drv = rport_drv;
Maggie Zhangf7f738122010-12-09 19:08:43 -08004709 memset(&rp->stats, 0, sizeof(rp->stats));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004710
Jing Huangd4b671c2010-12-26 21:46:35 -08004711 WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004712 bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
4713
4714 return rp;
4715}
4716
4717void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004718bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
4719{
Jing Huangd4b671c2010-12-26 21:46:35 -08004720 WARN_ON(rport_info->max_frmsz == 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004721
Jing Huang5fbe25c2010-10-18 17:17:23 -07004722 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004723 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
4724 * responses. Default to minimum size.
4725 */
4726 if (rport_info->max_frmsz == 0) {
4727 bfa_trc(rport->bfa, rport->rport_tag);
4728 rport_info->max_frmsz = FC_MIN_PDUSZ;
4729 }
4730
Jing Huang6a18b162010-10-18 17:08:54 -07004731 rport->rport_info = *rport_info;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004732 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
4733}
4734
4735void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004736bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
4737{
Jing Huangd4b671c2010-12-26 21:46:35 -08004738 WARN_ON(speed == 0);
4739 WARN_ON(speed == BFA_PORT_SPEED_AUTO);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004740
4741 rport->rport_info.speed = speed;
4742 bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
4743}
4744
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004745
Jing Huang5fbe25c2010-10-18 17:17:23 -07004746/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004747 * SGPG related functions
4748 */
4749
Jing Huang5fbe25c2010-10-18 17:17:23 -07004750/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004751 * Compute and return memory needed by FCP(im) module.
4752 */
4753static void
Krishna Gudipati45070252011-06-24 20:24:29 -07004754bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
4755 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004756{
Krishna Gudipati45070252011-06-24 20:24:29 -07004757 struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa);
4758 struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa);
4759 struct bfa_mem_dma_s *seg_ptr;
4760 u16 nsegs, idx, per_seg_sgpg, num_sgpg;
4761 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
4762
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004763 if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
4764 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
Krishna Gudipati45070252011-06-24 20:24:29 -07004765 else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX)
4766 cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004767
Krishna Gudipati45070252011-06-24 20:24:29 -07004768 num_sgpg = cfg->drvcfg.num_sgpgs;
4769
4770 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
4771 per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz);
4772
4773 bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) {
4774 if (num_sgpg >= per_seg_sgpg) {
4775 num_sgpg -= per_seg_sgpg;
4776 bfa_mem_dma_setup(minfo, seg_ptr,
4777 per_seg_sgpg * sgpg_sz);
4778 } else
4779 bfa_mem_dma_setup(minfo, seg_ptr,
4780 num_sgpg * sgpg_sz);
4781 }
4782
4783 /* kva memory */
4784 bfa_mem_kva_setup(minfo, sgpg_kva,
4785 cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004786}
4787
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004788static void
4789bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07004790 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004791{
4792 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004793 struct bfa_sgpg_s *hsgpg;
4794 struct bfi_sgpg_s *sgpg;
4795 u64 align_len;
Krishna Gudipati45070252011-06-24 20:24:29 -07004796 struct bfa_mem_dma_s *seg_ptr;
4797 u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
4798 u16 i, idx, nsegs, per_seg_sgpg, num_sgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004799
4800 union {
4801 u64 pa;
4802 union bfi_addr_u addr;
4803 } sgpg_pa, sgpg_pa_tmp;
4804
4805 INIT_LIST_HEAD(&mod->sgpg_q);
4806 INIT_LIST_HEAD(&mod->sgpg_wait_q);
4807
4808 bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
4809
Krishna Gudipati45070252011-06-24 20:24:29 -07004810 mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004811
Krishna Gudipati45070252011-06-24 20:24:29 -07004812 num_sgpg = cfg->drvcfg.num_sgpgs;
4813 nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004814
Krishna Gudipati45070252011-06-24 20:24:29 -07004815 /* dma/kva mem claim */
4816 hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004817
Krishna Gudipati45070252011-06-24 20:24:29 -07004818 bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004819
Krishna Gudipati45070252011-06-24 20:24:29 -07004820 if (!bfa_mem_dma_virt(seg_ptr))
4821 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004822
Krishna Gudipati45070252011-06-24 20:24:29 -07004823 align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) -
4824 bfa_mem_dma_phys(seg_ptr);
4825
4826 sgpg = (struct bfi_sgpg_s *)
4827 (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len);
4828 sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len;
4829 WARN_ON(sgpg_pa.pa & (sgpg_sz - 1));
4830
4831 per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz;
4832
4833 for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) {
4834 memset(hsgpg, 0, sizeof(*hsgpg));
4835 memset(sgpg, 0, sizeof(*sgpg));
4836
4837 hsgpg->sgpg = sgpg;
4838 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
4839 hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
4840 list_add_tail(&hsgpg->qe, &mod->sgpg_q);
4841
4842 sgpg++;
4843 hsgpg++;
4844 sgpg_pa.pa += sgpg_sz;
4845 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004846 }
4847
Krishna Gudipati45070252011-06-24 20:24:29 -07004848 bfa_mem_kva_curp(mod) = (u8 *) hsgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004849}
4850
4851static void
4852bfa_sgpg_detach(struct bfa_s *bfa)
4853{
4854}
4855
4856static void
4857bfa_sgpg_start(struct bfa_s *bfa)
4858{
4859}
4860
4861static void
4862bfa_sgpg_stop(struct bfa_s *bfa)
4863{
4864}
4865
4866static void
4867bfa_sgpg_iocdisable(struct bfa_s *bfa)
4868{
4869}
4870
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004871bfa_status_t
4872bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
4873{
4874 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4875 struct bfa_sgpg_s *hsgpg;
4876 int i;
4877
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004878 if (mod->free_sgpgs < nsgpgs)
4879 return BFA_STATUS_ENOMEM;
4880
4881 for (i = 0; i < nsgpgs; i++) {
4882 bfa_q_deq(&mod->sgpg_q, &hsgpg);
Jing Huangd4b671c2010-12-26 21:46:35 -08004883 WARN_ON(!hsgpg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004884 list_add_tail(&hsgpg->qe, sgpg_q);
4885 }
4886
4887 mod->free_sgpgs -= nsgpgs;
4888 return BFA_STATUS_OK;
4889}
4890
4891void
4892bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
4893{
4894 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4895 struct bfa_sgpg_wqe_s *wqe;
4896
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004897 mod->free_sgpgs += nsgpg;
Jing Huangd4b671c2010-12-26 21:46:35 -08004898 WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004899
4900 list_splice_tail_init(sgpg_q, &mod->sgpg_q);
4901
4902 if (list_empty(&mod->sgpg_wait_q))
4903 return;
4904
Jing Huang5fbe25c2010-10-18 17:17:23 -07004905 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004906 * satisfy as many waiting requests as possible
4907 */
4908 do {
4909 wqe = bfa_q_first(&mod->sgpg_wait_q);
4910 if (mod->free_sgpgs < wqe->nsgpg)
4911 nsgpg = mod->free_sgpgs;
4912 else
4913 nsgpg = wqe->nsgpg;
4914 bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
4915 wqe->nsgpg -= nsgpg;
4916 if (wqe->nsgpg == 0) {
4917 list_del(&wqe->qe);
4918 wqe->cbfn(wqe->cbarg);
4919 }
4920 } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
4921}
4922
4923void
4924bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
4925{
4926 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4927
Jing Huangd4b671c2010-12-26 21:46:35 -08004928 WARN_ON(nsgpg <= 0);
4929 WARN_ON(nsgpg <= mod->free_sgpgs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004930
4931 wqe->nsgpg_total = wqe->nsgpg = nsgpg;
4932
Jing Huang5fbe25c2010-10-18 17:17:23 -07004933 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004934 * allocate any left to this one first
4935 */
4936 if (mod->free_sgpgs) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07004937 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004938 * no one else is waiting for SGPG
4939 */
Jing Huangd4b671c2010-12-26 21:46:35 -08004940 WARN_ON(!list_empty(&mod->sgpg_wait_q));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004941 list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
4942 wqe->nsgpg -= mod->free_sgpgs;
4943 mod->free_sgpgs = 0;
4944 }
4945
4946 list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
4947}
4948
4949void
4950bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
4951{
4952 struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
4953
Jing Huangd4b671c2010-12-26 21:46:35 -08004954 WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004955 list_del(&wqe->qe);
4956
4957 if (wqe->nsgpg_total != wqe->nsgpg)
4958 bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
4959 wqe->nsgpg_total - wqe->nsgpg);
4960}
4961
4962void
4963bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
4964 void *cbarg)
4965{
4966 INIT_LIST_HEAD(&wqe->sgpg_q);
4967 wqe->cbfn = cbfn;
4968 wqe->cbarg = cbarg;
4969}
4970
Jing Huang5fbe25c2010-10-18 17:17:23 -07004971/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004972 * UF related functions
4973 */
4974/*
4975 *****************************************************************************
4976 * Internal functions
4977 *****************************************************************************
4978 */
4979static void
4980__bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
4981{
4982 struct bfa_uf_s *uf = cbarg;
4983 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
4984
4985 if (complete)
4986 ufm->ufrecv(ufm->cbarg, uf);
4987}
4988
4989static void
Krishna Gudipati45070252011-06-24 20:24:29 -07004990claim_uf_post_msgs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004991{
4992 struct bfi_uf_buf_post_s *uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004993 u16 i;
4994 u16 buf_len;
4995
Krishna Gudipati45070252011-06-24 20:24:29 -07004996 ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004997 uf_bp_msg = ufm->uf_buf_posts;
4998
4999 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
5000 i++, uf_bp_msg++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005001 memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005002
5003 uf_bp_msg->buf_tag = i;
5004 buf_len = sizeof(struct bfa_uf_buf_s);
Jing Huangba816ea2010-10-18 17:10:50 -07005005 uf_bp_msg->buf_len = cpu_to_be16(buf_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005006 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005007 bfa_fn_lpu(ufm->bfa));
Krishna Gudipati85ce9282011-06-13 15:39:36 -07005008 bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005009 }
5010
Jing Huang5fbe25c2010-10-18 17:17:23 -07005011 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005012 * advance pointer beyond consumed memory
5013 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005014 bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005015}
5016
5017static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005018claim_ufs(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005019{
5020 u16 i;
5021 struct bfa_uf_s *uf;
5022
5023 /*
5024 * Claim block of memory for UF list
5025 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005026 ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005027
5028 /*
5029 * Initialize UFs and queue it in UF free queue
5030 */
5031 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
Jing Huang6a18b162010-10-18 17:08:54 -07005032 memset(uf, 0, sizeof(struct bfa_uf_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005033 uf->bfa = ufm->bfa;
5034 uf->uf_tag = i;
Krishna Gudipati45070252011-06-24 20:24:29 -07005035 uf->pb_len = BFA_PER_UF_DMA_SZ;
5036 uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005037 uf->buf_pa = ufm_pbs_pa(ufm, i);
5038 list_add_tail(&uf->qe, &ufm->uf_free_q);
5039 }
5040
Jing Huang5fbe25c2010-10-18 17:17:23 -07005041 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005042 * advance memory pointer
5043 */
Krishna Gudipati45070252011-06-24 20:24:29 -07005044 bfa_mem_kva_curp(ufm) = (u8 *) uf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005045}
5046
5047static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005048uf_mem_claim(struct bfa_uf_mod_s *ufm)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005049{
Krishna Gudipati45070252011-06-24 20:24:29 -07005050 claim_ufs(ufm);
5051 claim_uf_post_msgs(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005052}
5053
5054static void
Krishna Gudipati45070252011-06-24 20:24:29 -07005055bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
5056 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005057{
Krishna Gudipati45070252011-06-24 20:24:29 -07005058 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5059 struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa);
5060 u32 num_ufs = cfg->fwcfg.num_uf_bufs;
5061 struct bfa_mem_dma_s *seg_ptr;
5062 u16 nsegs, idx, per_seg_uf = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005063
Krishna Gudipati45070252011-06-24 20:24:29 -07005064 nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ);
5065 per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005066
Krishna Gudipati45070252011-06-24 20:24:29 -07005067 bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) {
5068 if (num_ufs >= per_seg_uf) {
5069 num_ufs -= per_seg_uf;
5070 bfa_mem_dma_setup(minfo, seg_ptr,
5071 per_seg_uf * BFA_PER_UF_DMA_SZ);
5072 } else
5073 bfa_mem_dma_setup(minfo, seg_ptr,
5074 num_ufs * BFA_PER_UF_DMA_SZ);
5075 }
5076
5077 /* kva memory */
5078 bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs *
5079 (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s)));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005080}
5081
5082static void
5083bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07005084 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005085{
5086 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5087
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005088 ufm->bfa = bfa;
5089 ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
5090 INIT_LIST_HEAD(&ufm->uf_free_q);
5091 INIT_LIST_HEAD(&ufm->uf_posted_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005092 INIT_LIST_HEAD(&ufm->uf_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005093
Krishna Gudipati45070252011-06-24 20:24:29 -07005094 uf_mem_claim(ufm);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005095}
5096
5097static void
5098bfa_uf_detach(struct bfa_s *bfa)
5099{
5100}
5101
5102static struct bfa_uf_s *
5103bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
5104{
5105 struct bfa_uf_s *uf;
5106
5107 bfa_q_deq(&uf_mod->uf_free_q, &uf);
5108 return uf;
5109}
5110
5111static void
5112bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
5113{
5114 list_add_tail(&uf->qe, &uf_mod->uf_free_q);
5115}
5116
5117static bfa_status_t
5118bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
5119{
5120 struct bfi_uf_buf_post_s *uf_post_msg;
5121
5122 uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
5123 if (!uf_post_msg)
5124 return BFA_STATUS_FAILED;
5125
Jing Huang6a18b162010-10-18 17:08:54 -07005126 memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005127 sizeof(struct bfi_uf_buf_post_s));
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005128 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP, uf_post_msg->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005129
5130 bfa_trc(ufm->bfa, uf->uf_tag);
5131
5132 list_add_tail(&uf->qe, &ufm->uf_posted_q);
5133 return BFA_STATUS_OK;
5134}
5135
5136static void
5137bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
5138{
5139 struct bfa_uf_s *uf;
5140
5141 while ((uf = bfa_uf_get(uf_mod)) != NULL) {
5142 if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
5143 break;
5144 }
5145}
5146
5147static void
5148uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
5149{
5150 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5151 u16 uf_tag = m->buf_tag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005152 struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
Krishna Gudipati45070252011-06-24 20:24:29 -07005153 struct bfa_uf_buf_s *uf_buf;
5154 uint8_t *buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005155 struct fchs_s *fchs;
5156
Krishna Gudipati45070252011-06-24 20:24:29 -07005157 uf_buf = (struct bfa_uf_buf_s *)
5158 bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len);
5159 buf = &uf_buf->d[0];
5160
Jing Huangba816ea2010-10-18 17:10:50 -07005161 m->frm_len = be16_to_cpu(m->frm_len);
5162 m->xfr_len = be16_to_cpu(m->xfr_len);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005163
5164 fchs = (struct fchs_s *)uf_buf;
5165
5166 list_del(&uf->qe); /* dequeue from posted queue */
5167
5168 uf->data_ptr = buf;
5169 uf->data_len = m->xfr_len;
5170
Jing Huangd4b671c2010-12-26 21:46:35 -08005171 WARN_ON(uf->data_len < sizeof(struct fchs_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005172
5173 if (uf->data_len == sizeof(struct fchs_s)) {
5174 bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
5175 uf->data_len, (struct fchs_s *)buf);
5176 } else {
5177 u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
5178 bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
5179 BFA_PL_EID_RX, uf->data_len,
5180 (struct fchs_s *)buf, pld_w0);
5181 }
5182
5183 if (bfa->fcs)
5184 __bfa_cb_uf_recv(uf, BFA_TRUE);
5185 else
5186 bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
5187}
5188
5189static void
5190bfa_uf_stop(struct bfa_s *bfa)
5191{
5192}
5193
5194static void
5195bfa_uf_iocdisable(struct bfa_s *bfa)
5196{
5197 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5198 struct bfa_uf_s *uf;
5199 struct list_head *qe, *qen;
5200
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005201 /* Enqueue unused uf resources to free_q */
5202 list_splice_tail_init(&ufm->uf_unused_q, &ufm->uf_free_q);
5203
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005204 list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
5205 uf = (struct bfa_uf_s *) qe;
5206 list_del(&uf->qe);
5207 bfa_uf_put(ufm, uf);
5208 }
5209}
5210
5211static void
5212bfa_uf_start(struct bfa_s *bfa)
5213{
5214 bfa_uf_post_all(BFA_UF_MOD(bfa));
5215}
5216
Jing Huang5fbe25c2010-10-18 17:17:23 -07005217/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005218 * Register handler for all unsolicted receive frames.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005219 *
5220 * @param[in] bfa BFA instance
5221 * @param[in] ufrecv receive handler function
5222 * @param[in] cbarg receive handler arg
5223 */
5224void
5225bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
5226{
5227 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5228
5229 ufm->ufrecv = ufrecv;
5230 ufm->cbarg = cbarg;
5231}
5232
Jing Huang5fbe25c2010-10-18 17:17:23 -07005233/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005234 * Free an unsolicited frame back to BFA.
5235 *
5236 * @param[in] uf unsolicited frame to be freed
5237 *
5238 * @return None
5239 */
5240void
5241bfa_uf_free(struct bfa_uf_s *uf)
5242{
5243 bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
5244 bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
5245}
5246
5247
5248
Jing Huang5fbe25c2010-10-18 17:17:23 -07005249/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005250 * uf_pub BFA uf module public functions
5251 */
5252void
5253bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5254{
5255 bfa_trc(bfa, msg->mhdr.msg_id);
5256
5257 switch (msg->mhdr.msg_id) {
5258 case BFI_UF_I2H_FRM_RCVD:
5259 uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
5260 break;
5261
5262 default:
5263 bfa_trc(bfa, msg->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08005264 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005265 }
5266}
5267
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005268void
5269bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw)
5270{
5271 struct bfa_uf_mod_s *mod = BFA_UF_MOD(bfa);
5272 struct list_head *qe;
5273 int i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005274
Krishna Gudipati3fd45982011-06-24 20:24:08 -07005275 for (i = 0; i < (mod->num_ufs - num_uf_fw); i++) {
5276 bfa_q_deq_tail(&mod->uf_free_q, &qe);
5277 list_add_tail(qe, &mod->uf_unused_q);
5278 }
5279}
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07005280
5281/*
5282 * BFA fcdiag module
5283 */
5284#define BFA_DIAG_QTEST_TOV 1000 /* msec */
5285
5286/*
5287 * Set port status to busy
5288 */
5289static void
5290bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s *fcdiag)
5291{
5292 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fcdiag->bfa);
5293
5294 if (fcdiag->lb.lock)
5295 fcport->diag_busy = BFA_TRUE;
5296 else
5297 fcport->diag_busy = BFA_FALSE;
5298}
5299
5300static void
5301bfa_fcdiag_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
5302 struct bfa_s *bfa)
5303{
5304}
5305
5306static void
5307bfa_fcdiag_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
5308 struct bfa_pcidev_s *pcidev)
5309{
5310 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5311 fcdiag->bfa = bfa;
5312 fcdiag->trcmod = bfa->trcmod;
5313 /* The common DIAG attach bfa_diag_attach() will do all memory claim */
5314}
5315
5316static void
5317bfa_fcdiag_iocdisable(struct bfa_s *bfa)
5318{
5319 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5320 bfa_trc(fcdiag, fcdiag->lb.lock);
5321 if (fcdiag->lb.lock) {
5322 fcdiag->lb.status = BFA_STATUS_IOC_FAILURE;
5323 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5324 fcdiag->lb.lock = 0;
5325 bfa_fcdiag_set_busy_status(fcdiag);
5326 }
5327}
5328
5329static void
5330bfa_fcdiag_detach(struct bfa_s *bfa)
5331{
5332}
5333
5334static void
5335bfa_fcdiag_start(struct bfa_s *bfa)
5336{
5337}
5338
5339static void
5340bfa_fcdiag_stop(struct bfa_s *bfa)
5341{
5342}
5343
5344static void
5345bfa_fcdiag_queuetest_timeout(void *cbarg)
5346{
5347 struct bfa_fcdiag_s *fcdiag = cbarg;
5348 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5349
5350 bfa_trc(fcdiag, fcdiag->qtest.all);
5351 bfa_trc(fcdiag, fcdiag->qtest.count);
5352
5353 fcdiag->qtest.timer_active = 0;
5354
5355 res->status = BFA_STATUS_ETIMER;
5356 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5357 if (fcdiag->qtest.all)
5358 res->queue = fcdiag->qtest.all;
5359
5360 bfa_trc(fcdiag, BFA_STATUS_ETIMER);
5361 fcdiag->qtest.status = BFA_STATUS_ETIMER;
5362 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5363 fcdiag->qtest.lock = 0;
5364}
5365
5366static bfa_status_t
5367bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s *fcdiag)
5368{
5369 u32 i;
5370 struct bfi_diag_qtest_req_s *req;
5371
5372 req = bfa_reqq_next(fcdiag->bfa, fcdiag->qtest.queue);
5373 if (!req)
5374 return BFA_STATUS_DEVBUSY;
5375
5376 /* build host command */
5377 bfi_h2i_set(req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_QTEST,
5378 bfa_fn_lpu(fcdiag->bfa));
5379
5380 for (i = 0; i < BFI_LMSG_PL_WSZ; i++)
5381 req->data[i] = QTEST_PAT_DEFAULT;
5382
5383 bfa_trc(fcdiag, fcdiag->qtest.queue);
5384 /* ring door bell */
5385 bfa_reqq_produce(fcdiag->bfa, fcdiag->qtest.queue, req->mh);
5386 return BFA_STATUS_OK;
5387}
5388
5389static void
5390bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s *fcdiag,
5391 bfi_diag_qtest_rsp_t *rsp)
5392{
5393 struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
5394 bfa_status_t status = BFA_STATUS_OK;
5395 int i;
5396
5397 /* Check timer, should still be active */
5398 if (!fcdiag->qtest.timer_active) {
5399 bfa_trc(fcdiag, fcdiag->qtest.timer_active);
5400 return;
5401 }
5402
5403 /* update count */
5404 fcdiag->qtest.count--;
5405
5406 /* Check result */
5407 for (i = 0; i < BFI_LMSG_PL_WSZ; i++) {
5408 if (rsp->data[i] != ~(QTEST_PAT_DEFAULT)) {
5409 res->status = BFA_STATUS_DATACORRUPTED;
5410 break;
5411 }
5412 }
5413
5414 if (res->status == BFA_STATUS_OK) {
5415 if (fcdiag->qtest.count > 0) {
5416 status = bfa_fcdiag_queuetest_send(fcdiag);
5417 if (status == BFA_STATUS_OK)
5418 return;
5419 else
5420 res->status = status;
5421 } else if (fcdiag->qtest.all > 0 &&
5422 fcdiag->qtest.queue < (BFI_IOC_MAX_CQS - 1)) {
5423 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
5424 fcdiag->qtest.queue++;
5425 status = bfa_fcdiag_queuetest_send(fcdiag);
5426 if (status == BFA_STATUS_OK)
5427 return;
5428 else
5429 res->status = status;
5430 }
5431 }
5432
5433 /* Stop timer when we comp all queue */
5434 if (fcdiag->qtest.timer_active) {
5435 bfa_timer_stop(&fcdiag->qtest.timer);
5436 fcdiag->qtest.timer_active = 0;
5437 }
5438 res->queue = fcdiag->qtest.queue;
5439 res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
5440 bfa_trc(fcdiag, res->count);
5441 bfa_trc(fcdiag, res->status);
5442 fcdiag->qtest.status = res->status;
5443 fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
5444 fcdiag->qtest.lock = 0;
5445}
5446
5447static void
5448bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s *fcdiag,
5449 struct bfi_diag_lb_rsp_s *rsp)
5450{
5451 struct bfa_diag_loopback_result_s *res = fcdiag->lb.result;
5452
5453 res->numtxmfrm = be32_to_cpu(rsp->res.numtxmfrm);
5454 res->numosffrm = be32_to_cpu(rsp->res.numosffrm);
5455 res->numrcvfrm = be32_to_cpu(rsp->res.numrcvfrm);
5456 res->badfrminf = be32_to_cpu(rsp->res.badfrminf);
5457 res->badfrmnum = be32_to_cpu(rsp->res.badfrmnum);
5458 res->status = rsp->res.status;
5459 fcdiag->lb.status = rsp->res.status;
5460 bfa_trc(fcdiag, fcdiag->lb.status);
5461 fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
5462 fcdiag->lb.lock = 0;
5463 bfa_fcdiag_set_busy_status(fcdiag);
5464}
5465
5466static bfa_status_t
5467bfa_fcdiag_loopback_send(struct bfa_fcdiag_s *fcdiag,
5468 struct bfa_diag_loopback_s *loopback)
5469{
5470 struct bfi_diag_lb_req_s *lb_req;
5471
5472 lb_req = bfa_reqq_next(fcdiag->bfa, BFA_REQQ_DIAG);
5473 if (!lb_req)
5474 return BFA_STATUS_DEVBUSY;
5475
5476 /* build host command */
5477 bfi_h2i_set(lb_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LOOPBACK,
5478 bfa_fn_lpu(fcdiag->bfa));
5479
5480 lb_req->lb_mode = loopback->lb_mode;
5481 lb_req->speed = loopback->speed;
5482 lb_req->loopcnt = loopback->loopcnt;
5483 lb_req->pattern = loopback->pattern;
5484
5485 /* ring door bell */
5486 bfa_reqq_produce(fcdiag->bfa, BFA_REQQ_DIAG, lb_req->mh);
5487
5488 bfa_trc(fcdiag, loopback->lb_mode);
5489 bfa_trc(fcdiag, loopback->speed);
5490 bfa_trc(fcdiag, loopback->loopcnt);
5491 bfa_trc(fcdiag, loopback->pattern);
5492 return BFA_STATUS_OK;
5493}
5494
5495/*
5496 * cpe/rme intr handler
5497 */
5498void
5499bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg)
5500{
5501 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5502
5503 switch (msg->mhdr.msg_id) {
5504 case BFI_DIAG_I2H_LOOPBACK:
5505 bfa_fcdiag_loopback_comp(fcdiag,
5506 (struct bfi_diag_lb_rsp_s *) msg);
5507 break;
5508 case BFI_DIAG_I2H_QTEST:
5509 bfa_fcdiag_queuetest_comp(fcdiag, (bfi_diag_qtest_rsp_t *)msg);
5510 break;
5511 default:
5512 bfa_trc(fcdiag, msg->mhdr.msg_id);
5513 WARN_ON(1);
5514 }
5515}
5516
5517/*
5518 * Loopback test
5519 *
5520 * @param[in] *bfa - bfa data struct
5521 * @param[in] opmode - port operation mode
5522 * @param[in] speed - port speed
5523 * @param[in] lpcnt - loop count
5524 * @param[in] pat - pattern to build packet
5525 * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
5526 * @param[in] cbfn - callback function
5527 * @param[in] cbarg - callback functioin arg
5528 *
5529 * @param[out]
5530 */
5531bfa_status_t
5532bfa_fcdiag_loopback(struct bfa_s *bfa, enum bfa_port_opmode opmode,
5533 enum bfa_port_speed speed, u32 lpcnt, u32 pat,
5534 struct bfa_diag_loopback_result_s *result, bfa_cb_diag_t cbfn,
5535 void *cbarg)
5536{
5537 struct bfa_diag_loopback_s loopback;
5538 struct bfa_port_attr_s attr;
5539 bfa_status_t status;
5540 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5541
5542 if (!bfa_iocfc_is_operational(bfa))
5543 return BFA_STATUS_IOC_NON_OP;
5544
5545 /* if port is PBC disabled, return error */
5546 if (bfa_fcport_is_pbcdisabled(bfa)) {
5547 bfa_trc(fcdiag, BFA_STATUS_PBC);
5548 return BFA_STATUS_PBC;
5549 }
5550
5551 if (bfa_fcport_is_disabled(bfa) == BFA_FALSE) {
5552 bfa_trc(fcdiag, opmode);
5553 return BFA_STATUS_PORT_NOT_DISABLED;
5554 }
5555
5556 /* Check if the speed is supported */
5557 bfa_fcport_get_attr(bfa, &attr);
5558 bfa_trc(fcdiag, attr.speed_supported);
5559 if (speed > attr.speed_supported)
5560 return BFA_STATUS_UNSUPP_SPEED;
5561
5562 /* For Mezz card, port speed entered needs to be checked */
5563 if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) {
5564 if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
5565 if ((speed == BFA_PORT_SPEED_1GBPS) &&
5566 (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
5567 return BFA_STATUS_UNSUPP_SPEED;
5568 if (!(speed == BFA_PORT_SPEED_1GBPS ||
5569 speed == BFA_PORT_SPEED_2GBPS ||
5570 speed == BFA_PORT_SPEED_4GBPS ||
5571 speed == BFA_PORT_SPEED_8GBPS ||
5572 speed == BFA_PORT_SPEED_16GBPS ||
5573 speed == BFA_PORT_SPEED_AUTO))
5574 return BFA_STATUS_UNSUPP_SPEED;
5575 } else {
5576 if (speed != BFA_PORT_SPEED_10GBPS)
5577 return BFA_STATUS_UNSUPP_SPEED;
5578 }
5579 }
5580
5581 /* check to see if there is another destructive diag cmd running */
5582 if (fcdiag->lb.lock) {
5583 bfa_trc(fcdiag, fcdiag->lb.lock);
5584 return BFA_STATUS_DEVBUSY;
5585 }
5586
5587 fcdiag->lb.lock = 1;
5588 loopback.lb_mode = opmode;
5589 loopback.speed = speed;
5590 loopback.loopcnt = lpcnt;
5591 loopback.pattern = pat;
5592 fcdiag->lb.result = result;
5593 fcdiag->lb.cbfn = cbfn;
5594 fcdiag->lb.cbarg = cbarg;
5595 memset(result, 0, sizeof(struct bfa_diag_loopback_result_s));
5596 bfa_fcdiag_set_busy_status(fcdiag);
5597
5598 /* Send msg to fw */
5599 status = bfa_fcdiag_loopback_send(fcdiag, &loopback);
5600 return status;
5601}
5602
5603/*
5604 * DIAG queue test command
5605 *
5606 * @param[in] *bfa - bfa data struct
5607 * @param[in] force - 1: don't do ioc op checking
5608 * @param[in] queue - queue no. to test
5609 * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
5610 * @param[in] cbfn - callback function
5611 * @param[in] *cbarg - callback functioin arg
5612 *
5613 * @param[out]
5614 */
5615bfa_status_t
5616bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 force, u32 queue,
5617 struct bfa_diag_qtest_result_s *result, bfa_cb_diag_t cbfn,
5618 void *cbarg)
5619{
5620 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5621 bfa_status_t status;
5622 bfa_trc(fcdiag, force);
5623 bfa_trc(fcdiag, queue);
5624
5625 if (!force && !bfa_iocfc_is_operational(bfa))
5626 return BFA_STATUS_IOC_NON_OP;
5627
5628 /* check to see if there is another destructive diag cmd running */
5629 if (fcdiag->qtest.lock) {
5630 bfa_trc(fcdiag, fcdiag->qtest.lock);
5631 return BFA_STATUS_DEVBUSY;
5632 }
5633
5634 /* Initialization */
5635 fcdiag->qtest.lock = 1;
5636 fcdiag->qtest.cbfn = cbfn;
5637 fcdiag->qtest.cbarg = cbarg;
5638 fcdiag->qtest.result = result;
5639 fcdiag->qtest.count = QTEST_CNT_DEFAULT;
5640
5641 /* Init test results */
5642 fcdiag->qtest.result->status = BFA_STATUS_OK;
5643 fcdiag->qtest.result->count = 0;
5644
5645 /* send */
5646 if (queue < BFI_IOC_MAX_CQS) {
5647 fcdiag->qtest.result->queue = (u8)queue;
5648 fcdiag->qtest.queue = (u8)queue;
5649 fcdiag->qtest.all = 0;
5650 } else {
5651 fcdiag->qtest.result->queue = 0;
5652 fcdiag->qtest.queue = 0;
5653 fcdiag->qtest.all = 1;
5654 }
5655 status = bfa_fcdiag_queuetest_send(fcdiag);
5656
5657 /* Start a timer */
5658 if (status == BFA_STATUS_OK) {
5659 bfa_timer_start(bfa, &fcdiag->qtest.timer,
5660 bfa_fcdiag_queuetest_timeout, fcdiag,
5661 BFA_DIAG_QTEST_TOV);
5662 fcdiag->qtest.timer_active = 1;
5663 }
5664 return status;
5665}
5666
5667/*
5668 * DIAG PLB is running
5669 *
5670 * @param[in] *bfa - bfa data struct
5671 *
5672 * @param[out]
5673 */
5674bfa_status_t
5675bfa_fcdiag_lb_is_running(struct bfa_s *bfa)
5676{
5677 struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
5678 return fcdiag->lb.lock ? BFA_STATUS_DIAG_BUSY : BFA_STATUS_OK;
5679}