blob: 76867b5577fa4b1ed2278f78016f5b511fbcf961 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
2 * Copyright (c) 2005-2009 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
18#include <bfa.h>
19#include <bfa_svc.h>
20#include <bfi/bfi_pport.h>
Jing Huang3e98cc02010-07-08 19:52:46 -070021#include <bfi/bfi_pbc.h>
Jing Huang7725ccf2009-09-23 17:46:15 -070022#include <cs/bfa_debug.h>
23#include <aen/bfa_aen.h>
24#include <cs/bfa_plog.h>
25#include <aen/bfa_aen_port.h>
26
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -080027BFA_TRC_FILE(HAL, FCPORT);
28BFA_MODULE(fcport);
Jing Huang7725ccf2009-09-23 17:46:15 -070029
Jing Huang7725ccf2009-09-23 17:46:15 -070030/*
31 * The port is considered disabled if corresponding physical port or IOC are
32 * disabled explicitly
33 */
34#define BFA_PORT_IS_DISABLED(bfa) \
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -080035 ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
Jing Huang7725ccf2009-09-23 17:46:15 -070036 (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
37
38/*
39 * forward declarations
40 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -080041static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
42static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
43static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
44static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
45static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
46static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
47static void bfa_fcport_callback(struct bfa_fcport_s *fcport,
48 enum bfa_pport_linkstate event);
49static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
50 enum bfa_pport_linkstate event);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -080051static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
Krishna Gudipatica8b4322010-03-05 19:38:07 -080052static void bfa_fcport_stats_get_timeout(void *cbarg);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -080053static void bfa_fcport_stats_clr_timeout(void *cbarg);
54
Jing Huang7725ccf2009-09-23 17:46:15 -070055/**
56 * bfa_pport_private
57 */
58
59/**
60 * BFA port state machine events
61 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -080062enum bfa_fcport_sm_event {
63 BFA_FCPORT_SM_START = 1, /* start port state machine */
64 BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
65 BFA_FCPORT_SM_ENABLE = 3, /* enable port */
66 BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
67 BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
68 BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
69 BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
70 BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
71 BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
Jing Huang7725ccf2009-09-23 17:46:15 -070072};
73
Krishna Gudipati9693e7d2010-03-05 19:36:30 -080074/**
75 * BFA port link notification state machine events
76 */
77
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -080078enum bfa_fcport_ln_sm_event {
79 BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
80 BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
81 BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
Krishna Gudipati9693e7d2010-03-05 19:36:30 -080082};
83
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -080084static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
85 enum bfa_fcport_sm_event event);
86static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
87 enum bfa_fcport_sm_event event);
88static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
89 enum bfa_fcport_sm_event event);
90static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
91 enum bfa_fcport_sm_event event);
92static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
93 enum bfa_fcport_sm_event event);
94static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
95 enum bfa_fcport_sm_event event);
96static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
97 enum bfa_fcport_sm_event event);
98static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
99 enum bfa_fcport_sm_event event);
100static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
101 enum bfa_fcport_sm_event event);
102static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
103 enum bfa_fcport_sm_event event);
104static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
105 enum bfa_fcport_sm_event event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700106
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800107static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
108 enum bfa_fcport_ln_sm_event event);
109static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
110 enum bfa_fcport_ln_sm_event event);
111static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
112 enum bfa_fcport_ln_sm_event event);
113static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
114 enum bfa_fcport_ln_sm_event event);
115static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
116 enum bfa_fcport_ln_sm_event event);
117static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
118 enum bfa_fcport_ln_sm_event event);
119static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
120 enum bfa_fcport_ln_sm_event event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800121
Jing Huang7725ccf2009-09-23 17:46:15 -0700122static struct bfa_sm_table_s hal_pport_sm_table[] = {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800123 {BFA_SM(bfa_fcport_sm_uninit), BFA_PPORT_ST_UNINIT},
124 {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PPORT_ST_ENABLING_QWAIT},
125 {BFA_SM(bfa_fcport_sm_enabling), BFA_PPORT_ST_ENABLING},
126 {BFA_SM(bfa_fcport_sm_linkdown), BFA_PPORT_ST_LINKDOWN},
127 {BFA_SM(bfa_fcport_sm_linkup), BFA_PPORT_ST_LINKUP},
128 {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PPORT_ST_DISABLING_QWAIT},
129 {BFA_SM(bfa_fcport_sm_disabling), BFA_PPORT_ST_DISABLING},
130 {BFA_SM(bfa_fcport_sm_disabled), BFA_PPORT_ST_DISABLED},
131 {BFA_SM(bfa_fcport_sm_stopped), BFA_PPORT_ST_STOPPED},
132 {BFA_SM(bfa_fcport_sm_iocdown), BFA_PPORT_ST_IOCDOWN},
133 {BFA_SM(bfa_fcport_sm_iocfail), BFA_PPORT_ST_IOCDOWN},
Jing Huang7725ccf2009-09-23 17:46:15 -0700134};
135
136static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800137bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700138{
139 union bfa_aen_data_u aen_data;
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800140 struct bfa_log_mod_s *logmod = fcport->bfa->logm;
141 wwn_t pwwn = fcport->pwwn;
Jing Huang7725ccf2009-09-23 17:46:15 -0700142 char pwwn_ptr[BFA_STRING_32];
Jing Huang7725ccf2009-09-23 17:46:15 -0700143
Krishna Gudipati2993cc72010-03-05 19:36:47 -0800144 memset(&aen_data, 0, sizeof(aen_data));
Jing Huang7725ccf2009-09-23 17:46:15 -0700145 wwn2str(pwwn_ptr, pwwn);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800146 bfa_log(logmod, BFA_LOG_CREATE_ID(BFA_AEN_CAT_PORT, event), pwwn_ptr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700147
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800148 aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -0700149 aen_data.port.pwwn = pwwn;
150}
151
152static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800153bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
154 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700155{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800156 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700157
158 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800159 case BFA_FCPORT_SM_START:
Jing Huang7725ccf2009-09-23 17:46:15 -0700160 /**
161 * Start event after IOC is configured and BFA is started.
162 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800163 if (bfa_fcport_send_enable(fcport))
164 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700165 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800166 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling_qwait);
Jing Huang7725ccf2009-09-23 17:46:15 -0700167 break;
168
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800169 case BFA_FCPORT_SM_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700170 /**
171 * Port is persistently configured to be in enabled state. Do
172 * not change state. Port enabling is done when START event is
173 * received.
174 */
175 break;
176
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800177 case BFA_FCPORT_SM_DISABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700178 /**
179 * If a port is persistently configured to be disabled, the
180 * first event will a port disable request.
181 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800182 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -0700183 break;
184
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800185 case BFA_FCPORT_SM_HWFAIL:
186 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
Jing Huang7725ccf2009-09-23 17:46:15 -0700187 break;
188
189 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800190 bfa_sm_fault(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700191 }
192}
193
194static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800195bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
196 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700197{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800198 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700199
200 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800201 case BFA_FCPORT_SM_QRESUME:
202 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
203 bfa_fcport_send_enable(fcport);
Jing Huang7725ccf2009-09-23 17:46:15 -0700204 break;
205
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800206 case BFA_FCPORT_SM_STOP:
207 bfa_reqq_wcancel(&fcport->reqq_wait);
208 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
Jing Huang7725ccf2009-09-23 17:46:15 -0700209 break;
210
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800211 case BFA_FCPORT_SM_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700212 /**
213 * Already enable is in progress.
214 */
215 break;
216
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800217 case BFA_FCPORT_SM_DISABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700218 /**
219 * Just send disable request to firmware when room becomes
220 * available in request queue.
221 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800222 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
223 bfa_reqq_wcancel(&fcport->reqq_wait);
224 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
Jing Huang7725ccf2009-09-23 17:46:15 -0700225 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800226 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700227 break;
228
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800229 case BFA_FCPORT_SM_LINKUP:
230 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang7725ccf2009-09-23 17:46:15 -0700231 /**
232 * Possible to get link events when doing back-to-back
233 * enable/disables.
234 */
235 break;
236
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800237 case BFA_FCPORT_SM_HWFAIL:
238 bfa_reqq_wcancel(&fcport->reqq_wait);
239 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
Jing Huang7725ccf2009-09-23 17:46:15 -0700240 break;
241
242 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800243 bfa_sm_fault(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700244 }
245}
246
247static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800248bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
249 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700250{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800251 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700252
253 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800254 case BFA_FCPORT_SM_FWRSP:
255 case BFA_FCPORT_SM_LINKDOWN:
256 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
Jing Huang7725ccf2009-09-23 17:46:15 -0700257 break;
258
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800259 case BFA_FCPORT_SM_LINKUP:
260 bfa_fcport_update_linkinfo(fcport);
261 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
Jing Huang7725ccf2009-09-23 17:46:15 -0700262
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800263 bfa_assert(fcport->event_cbfn);
264 bfa_fcport_callback(fcport, BFA_PPORT_LINKUP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700265 break;
266
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800267 case BFA_FCPORT_SM_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700268 /**
269 * Already being enabled.
270 */
271 break;
272
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800273 case BFA_FCPORT_SM_DISABLE:
274 if (bfa_fcport_send_disable(fcport))
275 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700276 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800277 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
Jing Huang7725ccf2009-09-23 17:46:15 -0700278
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800279 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
Jing Huang7725ccf2009-09-23 17:46:15 -0700280 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800281 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700282 break;
283
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800284 case BFA_FCPORT_SM_STOP:
285 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
Jing Huang7725ccf2009-09-23 17:46:15 -0700286 break;
287
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800288 case BFA_FCPORT_SM_HWFAIL:
289 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
Jing Huang7725ccf2009-09-23 17:46:15 -0700290 break;
291
292 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800293 bfa_sm_fault(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700294 }
295}
296
297static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800298bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
299 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700300{
Krishna Gudipatica8b4322010-03-05 19:38:07 -0800301 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800302 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700303
304 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800305 case BFA_FCPORT_SM_LINKUP:
306 bfa_fcport_update_linkinfo(fcport);
307 bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
308 bfa_assert(fcport->event_cbfn);
309 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
Jing Huang7725ccf2009-09-23 17:46:15 -0700310 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
Krishna Gudipatif58e9eb2010-03-05 19:37:45 -0800311
312 if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
313
Jing Huangdb954c02010-07-08 19:58:01 -0700314 bfa_trc(fcport->bfa,
315 pevent->link_state.vc_fcf.fcf.fipenabled);
316 bfa_trc(fcport->bfa,
317 pevent->link_state.vc_fcf.fcf.fipfailed);
Krishna Gudipatif58e9eb2010-03-05 19:37:45 -0800318
Jing Huangdb954c02010-07-08 19:58:01 -0700319 if (pevent->link_state.vc_fcf.fcf.fipfailed)
Krishna Gudipatif58e9eb2010-03-05 19:37:45 -0800320 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
321 BFA_PL_EID_FIP_FCF_DISC, 0,
322 "FIP FCF Discovery Failed");
323 else
324 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
325 BFA_PL_EID_FIP_FCF_DISC, 0,
326 "FIP FCF Discovered");
327 }
328
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800329 bfa_fcport_callback(fcport, BFA_PPORT_LINKUP);
330 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700331 /**
332 * If QoS is enabled and it is not online,
333 * Send a separate event.
334 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800335 if ((fcport->cfg.qos_enabled)
336 && (bfa_os_ntohl(fcport->qos_attr.state) != BFA_QOS_ONLINE))
337 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG);
Jing Huang7725ccf2009-09-23 17:46:15 -0700338
339 break;
340
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800341 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang7725ccf2009-09-23 17:46:15 -0700342 /**
343 * Possible to get link down event.
344 */
345 break;
346
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800347 case BFA_FCPORT_SM_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700348 /**
349 * Already enabled.
350 */
351 break;
352
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800353 case BFA_FCPORT_SM_DISABLE:
354 if (bfa_fcport_send_disable(fcport))
355 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700356 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800357 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
Jing Huang7725ccf2009-09-23 17:46:15 -0700358
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800359 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
Jing Huang7725ccf2009-09-23 17:46:15 -0700360 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800361 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700362 break;
363
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800364 case BFA_FCPORT_SM_STOP:
365 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
Jing Huang7725ccf2009-09-23 17:46:15 -0700366 break;
367
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800368 case BFA_FCPORT_SM_HWFAIL:
369 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
Jing Huang7725ccf2009-09-23 17:46:15 -0700370 break;
371
372 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800373 bfa_sm_fault(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700374 }
375}
376
377static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800378bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
379 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700380{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800381 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700382
383 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800384 case BFA_FCPORT_SM_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700385 /**
386 * Already enabled.
387 */
388 break;
389
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800390 case BFA_FCPORT_SM_DISABLE:
391 if (bfa_fcport_send_disable(fcport))
392 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700393 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800394 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
Jing Huang7725ccf2009-09-23 17:46:15 -0700395
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800396 bfa_fcport_reset_linkinfo(fcport);
397 bfa_fcport_callback(fcport, BFA_PPORT_LINKDOWN);
398 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
Jing Huang7725ccf2009-09-23 17:46:15 -0700399 BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800400 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
401 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700402 break;
403
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800404 case BFA_FCPORT_SM_LINKDOWN:
405 bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
406 bfa_fcport_reset_linkinfo(fcport);
407 bfa_fcport_callback(fcport, BFA_PPORT_LINKDOWN);
408 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
Jing Huang7725ccf2009-09-23 17:46:15 -0700409 BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800410 if (BFA_PORT_IS_DISABLED(fcport->bfa))
411 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700412 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800413 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
Jing Huang7725ccf2009-09-23 17:46:15 -0700414 break;
415
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800416 case BFA_FCPORT_SM_STOP:
417 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
418 bfa_fcport_reset_linkinfo(fcport);
419 if (BFA_PORT_IS_DISABLED(fcport->bfa))
420 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700421 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800422 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
Jing Huang7725ccf2009-09-23 17:46:15 -0700423 break;
424
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800425 case BFA_FCPORT_SM_HWFAIL:
426 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
427 bfa_fcport_reset_linkinfo(fcport);
428 bfa_fcport_callback(fcport, BFA_PPORT_LINKDOWN);
429 if (BFA_PORT_IS_DISABLED(fcport->bfa))
430 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700431 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800432 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
Jing Huang7725ccf2009-09-23 17:46:15 -0700433 break;
434
435 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800436 bfa_sm_fault(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700437 }
438}
439
440static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800441bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
442 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700443{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800444 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700445
446 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800447 case BFA_FCPORT_SM_QRESUME:
448 bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
449 bfa_fcport_send_disable(fcport);
Jing Huang7725ccf2009-09-23 17:46:15 -0700450 break;
451
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800452 case BFA_FCPORT_SM_STOP:
453 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
454 bfa_reqq_wcancel(&fcport->reqq_wait);
Jing Huang7725ccf2009-09-23 17:46:15 -0700455 break;
456
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800457 case BFA_FCPORT_SM_DISABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700458 /**
459 * Already being disabled.
460 */
461 break;
462
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800463 case BFA_FCPORT_SM_LINKUP:
464 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang7725ccf2009-09-23 17:46:15 -0700465 /**
466 * Possible to get link events when doing back-to-back
467 * enable/disables.
468 */
469 break;
470
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800471 case BFA_FCPORT_SM_HWFAIL:
472 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
473 bfa_reqq_wcancel(&fcport->reqq_wait);
Jing Huang7725ccf2009-09-23 17:46:15 -0700474 break;
475
476 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800477 bfa_sm_fault(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700478 }
479}
480
481static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800482bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
483 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700484{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800485 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700486
487 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800488 case BFA_FCPORT_SM_FWRSP:
489 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -0700490 break;
491
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800492 case BFA_FCPORT_SM_DISABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700493 /**
494 * Already being disabled.
495 */
496 break;
497
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800498 case BFA_FCPORT_SM_ENABLE:
499 if (bfa_fcport_send_enable(fcport))
500 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700501 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800502 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling_qwait);
Jing Huang7725ccf2009-09-23 17:46:15 -0700503
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800504 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
Jing Huang7725ccf2009-09-23 17:46:15 -0700505 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800506 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700507 break;
508
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800509 case BFA_FCPORT_SM_STOP:
510 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
Jing Huang7725ccf2009-09-23 17:46:15 -0700511 break;
512
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800513 case BFA_FCPORT_SM_LINKUP:
514 case BFA_FCPORT_SM_LINKDOWN:
Jing Huang7725ccf2009-09-23 17:46:15 -0700515 /**
516 * Possible to get link events when doing back-to-back
517 * enable/disables.
518 */
519 break;
520
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800521 case BFA_FCPORT_SM_HWFAIL:
522 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
Jing Huang7725ccf2009-09-23 17:46:15 -0700523 break;
524
525 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800526 bfa_sm_fault(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700527 }
528}
529
530static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800531bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
532 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700533{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800534 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700535
536 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800537 case BFA_FCPORT_SM_START:
Jing Huang7725ccf2009-09-23 17:46:15 -0700538 /**
539 * Ignore start event for a port that is disabled.
540 */
541 break;
542
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800543 case BFA_FCPORT_SM_STOP:
544 bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
Jing Huang7725ccf2009-09-23 17:46:15 -0700545 break;
546
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800547 case BFA_FCPORT_SM_ENABLE:
548 if (bfa_fcport_send_enable(fcport))
549 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700550 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800551 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling_qwait);
Jing Huang7725ccf2009-09-23 17:46:15 -0700552
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800553 bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
Jing Huang7725ccf2009-09-23 17:46:15 -0700554 BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800555 bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700556 break;
557
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800558 case BFA_FCPORT_SM_DISABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700559 /**
560 * Already disabled.
561 */
562 break;
563
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800564 case BFA_FCPORT_SM_HWFAIL:
565 bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
Jing Huang7725ccf2009-09-23 17:46:15 -0700566 break;
567
568 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800569 bfa_sm_fault(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700570 }
571}
572
573static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800574bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
575 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700576{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800577 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700578
579 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800580 case BFA_FCPORT_SM_START:
581 if (bfa_fcport_send_enable(fcport))
582 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700583 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800584 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling_qwait);
Jing Huang7725ccf2009-09-23 17:46:15 -0700585 break;
586
587 default:
588 /**
589 * Ignore all other events.
590 */
591 ;
592 }
593}
594
595/**
596 * Port is enabled. IOC is down/failed.
597 */
598static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800599bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
600 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700601{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800602 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700603
604 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800605 case BFA_FCPORT_SM_START:
606 if (bfa_fcport_send_enable(fcport))
607 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700608 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800609 bfa_sm_set_state(fcport, bfa_fcport_sm_enabling_qwait);
Jing Huang7725ccf2009-09-23 17:46:15 -0700610 break;
611
612 default:
613 /**
614 * Ignore all events.
615 */
616 ;
617 }
618}
619
620/**
621 * Port is disabled. IOC is down/failed.
622 */
623static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800624bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
625 enum bfa_fcport_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700626{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800627 bfa_trc(fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700628
629 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800630 case BFA_FCPORT_SM_START:
631 bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -0700632 break;
633
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800634 case BFA_FCPORT_SM_ENABLE:
635 bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
Jing Huang7725ccf2009-09-23 17:46:15 -0700636 break;
637
638 default:
639 /**
640 * Ignore all events.
641 */
642 ;
643 }
644}
645
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800646/**
647 * Link state is down
648 */
649static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800650bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
651 enum bfa_fcport_ln_sm_event event)
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800652{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800653 bfa_trc(ln->fcport->bfa, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700654
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800655 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800656 case BFA_FCPORT_LN_SM_LINKUP:
657 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
658 bfa_fcport_queue_cb(ln, BFA_PPORT_LINKUP);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800659 break;
660
661 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800662 bfa_sm_fault(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800663 }
664}
665
666/**
667 * Link state is waiting for down notification
668 */
669static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800670bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
671 enum bfa_fcport_ln_sm_event event)
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800672{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800673 bfa_trc(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800674
675 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800676 case BFA_FCPORT_LN_SM_LINKUP:
677 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800678 break;
679
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800680 case BFA_FCPORT_LN_SM_NOTIFICATION:
681 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800682 break;
683
684 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800685 bfa_sm_fault(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800686 }
687}
688
689/**
690 * Link state is waiting for down notification and there is a pending up
691 */
692static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800693bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
694 enum bfa_fcport_ln_sm_event event)
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800695{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800696 bfa_trc(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800697
698 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800699 case BFA_FCPORT_LN_SM_LINKDOWN:
700 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800701 break;
702
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800703 case BFA_FCPORT_LN_SM_NOTIFICATION:
704 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
705 bfa_fcport_queue_cb(ln, BFA_PPORT_LINKUP);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800706 break;
707
708 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800709 bfa_sm_fault(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800710 }
711}
712
713/**
714 * Link state is up
715 */
716static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800717bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
718 enum bfa_fcport_ln_sm_event event)
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800719{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800720 bfa_trc(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800721
722 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800723 case BFA_FCPORT_LN_SM_LINKDOWN:
724 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
725 bfa_fcport_queue_cb(ln, BFA_PPORT_LINKDOWN);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800726 break;
727
728 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800729 bfa_sm_fault(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800730 }
731}
732
733/**
734 * Link state is waiting for up notification
735 */
736static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800737bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
738 enum bfa_fcport_ln_sm_event event)
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800739{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800740 bfa_trc(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800741
742 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800743 case BFA_FCPORT_LN_SM_LINKDOWN:
744 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800745 break;
746
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800747 case BFA_FCPORT_LN_SM_NOTIFICATION:
748 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800749 break;
750
751 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800752 bfa_sm_fault(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800753 }
754}
755
756/**
757 * Link state is waiting for up notification and there is a pending down
758 */
759static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800760bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
761 enum bfa_fcport_ln_sm_event event)
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800762{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800763 bfa_trc(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800764
765 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800766 case BFA_FCPORT_LN_SM_LINKUP:
767 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800768 break;
769
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800770 case BFA_FCPORT_LN_SM_NOTIFICATION:
771 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
772 bfa_fcport_queue_cb(ln, BFA_PPORT_LINKDOWN);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800773 break;
774
775 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800776 bfa_sm_fault(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800777 }
778}
779
780/**
781 * Link state is waiting for up notification and there are pending down and up
782 */
783static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800784bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
785 enum bfa_fcport_ln_sm_event event)
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800786{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800787 bfa_trc(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800788
789 switch (event) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800790 case BFA_FCPORT_LN_SM_LINKDOWN:
791 bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800792 break;
793
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800794 case BFA_FCPORT_LN_SM_NOTIFICATION:
795 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
796 bfa_fcport_queue_cb(ln, BFA_PPORT_LINKDOWN);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800797 break;
798
799 default:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800800 bfa_sm_fault(ln->fcport->bfa, event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800801 }
802}
Jing Huang7725ccf2009-09-23 17:46:15 -0700803
804/**
805 * bfa_pport_private
806 */
807
808static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800809__bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
Jing Huang7725ccf2009-09-23 17:46:15 -0700810{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800811 struct bfa_fcport_ln_s *ln = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700812
813 if (complete)
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800814 ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
Krishna Gudipati9693e7d2010-03-05 19:36:30 -0800815 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800816 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
Jing Huang7725ccf2009-09-23 17:46:15 -0700817}
818
Krishna Gudipatica8b4322010-03-05 19:38:07 -0800819static void
820bfa_fcport_callback(struct bfa_fcport_s *fcport, enum bfa_pport_linkstate event)
821{
822 if (fcport->bfa->fcs) {
823 fcport->event_cbfn(fcport->event_cbarg, event);
824 return;
825 }
826
827 switch (event) {
828 case BFA_PPORT_LINKUP:
829 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
830 break;
831 case BFA_PPORT_LINKDOWN:
832 bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
833 break;
834 default:
835 bfa_assert(0);
836 }
837}
838
839static void
840bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_pport_linkstate event)
841{
842 ln->ln_event = event;
843 bfa_cb_queue(ln->fcport->bfa, &ln->ln_qe, __bfa_cb_fcport_event, ln);
844}
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800845
846#define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
Jing Huang7725ccf2009-09-23 17:46:15 -0700847 BFA_CACHELINE_SZ))
848
849static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800850bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
Jing Huang7725ccf2009-09-23 17:46:15 -0700851 u32 *dm_len)
852{
Krishna Gudipatica8b4322010-03-05 19:38:07 -0800853 *dm_len += FCPORT_STATS_DMA_SZ;
Jing Huang7725ccf2009-09-23 17:46:15 -0700854}
855
856static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800857bfa_fcport_qresume(void *cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -0700858{
Krishna Gudipatid1c61f82010-03-05 19:38:44 -0800859 struct bfa_fcport_s *fcport = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700860
Krishna Gudipatid1c61f82010-03-05 19:38:44 -0800861 bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
Jing Huang7725ccf2009-09-23 17:46:15 -0700862}
863
864static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800865bfa_fcport_mem_claim(struct bfa_fcport_s *fcport, struct bfa_meminfo_s *meminfo)
Jing Huang7725ccf2009-09-23 17:46:15 -0700866{
867 u8 *dm_kva;
868 u64 dm_pa;
869
870 dm_kva = bfa_meminfo_dma_virt(meminfo);
871 dm_pa = bfa_meminfo_dma_phys(meminfo);
872
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800873 fcport->stats_kva = dm_kva;
874 fcport->stats_pa = dm_pa;
Krishna Gudipatica8b4322010-03-05 19:38:07 -0800875 fcport->stats = (union bfa_fcport_stats_u *)dm_kva;
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800876
877 dm_kva += FCPORT_STATS_DMA_SZ;
878 dm_pa += FCPORT_STATS_DMA_SZ;
879
Jing Huang7725ccf2009-09-23 17:46:15 -0700880 bfa_meminfo_dma_virt(meminfo) = dm_kva;
881 bfa_meminfo_dma_phys(meminfo) = dm_pa;
882}
883
884/**
885 * Memory initialization.
886 */
887static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800888bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Jing Huang7725ccf2009-09-23 17:46:15 -0700889 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
890{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800891 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
892 struct bfa_pport_cfg_s *port_cfg = &fcport->cfg;
893 struct bfa_fcport_ln_s *ln = &fcport->ln;
Jing Huangb85d0452010-07-08 19:48:49 -0700894 struct bfa_timeval_s tv;
Jing Huang7725ccf2009-09-23 17:46:15 -0700895
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800896 bfa_os_memset(fcport, 0, sizeof(struct bfa_fcport_s));
897 fcport->bfa = bfa;
898 ln->fcport = fcport;
Jing Huang7725ccf2009-09-23 17:46:15 -0700899
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800900 bfa_fcport_mem_claim(fcport, meminfo);
Jing Huang7725ccf2009-09-23 17:46:15 -0700901
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800902 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
903 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
Jing Huang7725ccf2009-09-23 17:46:15 -0700904
905 /**
Jing Huangb85d0452010-07-08 19:48:49 -0700906 * initialize time stamp for stats reset
907 */
908 bfa_os_gettimeofday(&tv);
909 fcport->stats_reset_time = tv.tv_sec;
910
911 /**
Jing Huang7725ccf2009-09-23 17:46:15 -0700912 * initialize and set default configuration
913 */
914 port_cfg->topology = BFA_PPORT_TOPOLOGY_P2P;
915 port_cfg->speed = BFA_PPORT_SPEED_AUTO;
916 port_cfg->trunked = BFA_FALSE;
917 port_cfg->maxfrsize = 0;
918
919 port_cfg->trl_def_speed = BFA_PPORT_SPEED_1GBPS;
920
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800921 bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
Jing Huang7725ccf2009-09-23 17:46:15 -0700922}
923
924static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800925bfa_fcport_detach(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -0700926{
927}
928
929/**
930 * Called when IOC is ready.
931 */
932static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800933bfa_fcport_start(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -0700934{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800935 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
Jing Huang7725ccf2009-09-23 17:46:15 -0700936}
937
938/**
939 * Called before IOC is stopped.
940 */
941static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800942bfa_fcport_stop(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -0700943{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800944 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700945}
946
947/**
948 * Called when IOC failure is detected.
949 */
950static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800951bfa_fcport_iocdisable(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -0700952{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800953 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_HWFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700954}
955
956static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800957bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700958{
Krishna Gudipatica8b4322010-03-05 19:38:07 -0800959 struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
Jing Huang7725ccf2009-09-23 17:46:15 -0700960
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800961 fcport->speed = pevent->link_state.speed;
962 fcport->topology = pevent->link_state.topology;
Jing Huang7725ccf2009-09-23 17:46:15 -0700963
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800964 if (fcport->topology == BFA_PPORT_TOPOLOGY_LOOP)
Jing Huangdb954c02010-07-08 19:58:01 -0700965 fcport->myalpa = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -0700966
967 /*
968 * QoS Details
969 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800970 bfa_os_assign(fcport->qos_attr, pevent->link_state.qos_attr);
Jing Huangdb954c02010-07-08 19:58:01 -0700971 bfa_os_assign(fcport->qos_vc_attr,
972 pevent->link_state.vc_fcf.qos_vc_attr);
973
Jing Huang7725ccf2009-09-23 17:46:15 -0700974
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800975 bfa_trc(fcport->bfa, fcport->speed);
976 bfa_trc(fcport->bfa, fcport->topology);
Jing Huang7725ccf2009-09-23 17:46:15 -0700977}
978
979static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800980bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700981{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800982 fcport->speed = BFA_PPORT_SPEED_UNKNOWN;
983 fcport->topology = BFA_PPORT_TOPOLOGY_NONE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700984}
985
986/**
987 * Send port enable message to firmware.
988 */
989static bfa_boolean_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800990bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
Jing Huang7725ccf2009-09-23 17:46:15 -0700991{
Krishna Gudipatica8b4322010-03-05 19:38:07 -0800992 struct bfi_fcport_enable_req_s *m;
Jing Huang7725ccf2009-09-23 17:46:15 -0700993
994 /**
995 * Increment message tag before queue check, so that responses to old
996 * requests are discarded.
997 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -0800998 fcport->msgtag++;
Jing Huang7725ccf2009-09-23 17:46:15 -0700999
1000 /**
1001 * check for room in queue to send request now
1002 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001003 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
Jing Huang7725ccf2009-09-23 17:46:15 -07001004 if (!m) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001005 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
1006 &fcport->reqq_wait);
Jing Huang7725ccf2009-09-23 17:46:15 -07001007 return BFA_FALSE;
1008 }
1009
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001010 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
1011 bfa_lpuid(fcport->bfa));
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001012 m->nwwn = fcport->nwwn;
1013 m->pwwn = fcport->pwwn;
1014 m->port_cfg = fcport->cfg;
1015 m->msgtag = fcport->msgtag;
1016 m->port_cfg.maxfrsize = bfa_os_htons(fcport->cfg.maxfrsize);
1017 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001018 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
1019 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
Jing Huang7725ccf2009-09-23 17:46:15 -07001020
1021 /**
1022 * queue I/O message to firmware
1023 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001024 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
Jing Huang7725ccf2009-09-23 17:46:15 -07001025 return BFA_TRUE;
1026}
1027
1028/**
1029 * Send port disable message to firmware.
1030 */
1031static bfa_boolean_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001032bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
Jing Huang7725ccf2009-09-23 17:46:15 -07001033{
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001034 struct bfi_fcport_req_s *m;
Jing Huang7725ccf2009-09-23 17:46:15 -07001035
1036 /**
1037 * Increment message tag before queue check, so that responses to old
1038 * requests are discarded.
1039 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001040 fcport->msgtag++;
Jing Huang7725ccf2009-09-23 17:46:15 -07001041
1042 /**
1043 * check for room in queue to send request now
1044 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001045 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
Jing Huang7725ccf2009-09-23 17:46:15 -07001046 if (!m) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001047 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
1048 &fcport->reqq_wait);
Jing Huang7725ccf2009-09-23 17:46:15 -07001049 return BFA_FALSE;
1050 }
1051
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001052 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
1053 bfa_lpuid(fcport->bfa));
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001054 m->msgtag = fcport->msgtag;
Jing Huang7725ccf2009-09-23 17:46:15 -07001055
1056 /**
1057 * queue I/O message to firmware
1058 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001059 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
Jing Huang7725ccf2009-09-23 17:46:15 -07001060
1061 return BFA_TRUE;
1062}
1063
1064static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001065bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
Jing Huang7725ccf2009-09-23 17:46:15 -07001066{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001067 fcport->pwwn = bfa_ioc_get_pwwn(&fcport->bfa->ioc);
1068 fcport->nwwn = bfa_ioc_get_nwwn(&fcport->bfa->ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001069
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001070 bfa_trc(fcport->bfa, fcport->pwwn);
1071 bfa_trc(fcport->bfa, fcport->nwwn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001072}
1073
1074static void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001075bfa_fcport_send_txcredit(void *port_cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001076{
1077
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001078 struct bfa_fcport_s *fcport = port_cbarg;
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001079 struct bfi_fcport_set_svc_params_req_s *m;
Jing Huang7725ccf2009-09-23 17:46:15 -07001080
1081 /**
1082 * check for room in queue to send request now
1083 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001084 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
Jing Huang7725ccf2009-09-23 17:46:15 -07001085 if (!m) {
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001086 bfa_trc(fcport->bfa, fcport->cfg.tx_bbcredit);
Jing Huang7725ccf2009-09-23 17:46:15 -07001087 return;
1088 }
1089
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001090 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ,
1091 bfa_lpuid(fcport->bfa));
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001092 m->tx_bbcredit = bfa_os_htons((u16) fcport->cfg.tx_bbcredit);
Jing Huang7725ccf2009-09-23 17:46:15 -07001093
1094 /**
1095 * queue I/O message to firmware
1096 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001097 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
Jing Huang7725ccf2009-09-23 17:46:15 -07001098}
1099
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001100static void
1101bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
1102 struct bfa_qos_stats_s *s)
1103{
1104 u32 *dip = (u32 *) d;
1105 u32 *sip = (u32 *) s;
1106 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001107
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001108 /* Now swap the 32 bit fields */
1109 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
1110 dip[i] = bfa_os_ntohl(sip[i]);
1111}
1112
1113static void
1114bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
1115 struct bfa_fcoe_stats_s *s)
1116{
1117 u32 *dip = (u32 *) d;
1118 u32 *sip = (u32 *) s;
1119 int i;
1120
1121 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
1122 i = i + 2) {
1123#ifdef __BIGENDIAN
1124 dip[i] = bfa_os_ntohl(sip[i]);
1125 dip[i + 1] = bfa_os_ntohl(sip[i + 1]);
1126#else
1127 dip[i] = bfa_os_ntohl(sip[i + 1]);
1128 dip[i + 1] = bfa_os_ntohl(sip[i]);
1129#endif
1130 }
1131}
1132
1133static void
1134__bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
1135{
1136 struct bfa_fcport_s *fcport = cbarg;
1137
1138 if (complete) {
1139 if (fcport->stats_status == BFA_STATUS_OK) {
Jing Huangb85d0452010-07-08 19:48:49 -07001140 struct bfa_timeval_s tv;
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001141
1142 /* Swap FC QoS or FCoE stats */
Jing Huangb85d0452010-07-08 19:48:49 -07001143 if (bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001144 bfa_fcport_qos_stats_swap(
1145 &fcport->stats_ret->fcqos,
1146 &fcport->stats->fcqos);
Jing Huangb85d0452010-07-08 19:48:49 -07001147 } else {
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001148 bfa_fcport_fcoe_stats_swap(
1149 &fcport->stats_ret->fcoe,
1150 &fcport->stats->fcoe);
Jing Huangb85d0452010-07-08 19:48:49 -07001151
1152 bfa_os_gettimeofday(&tv);
1153 fcport->stats_ret->fcoe.secs_reset =
1154 tv.tv_sec - fcport->stats_reset_time;
1155 }
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001156 }
1157 fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
1158 } else {
1159 fcport->stats_busy = BFA_FALSE;
1160 fcport->stats_status = BFA_STATUS_OK;
1161 }
1162}
1163
1164static void
1165bfa_fcport_stats_get_timeout(void *cbarg)
1166{
1167 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
1168
1169 bfa_trc(fcport->bfa, fcport->stats_qfull);
1170
1171 if (fcport->stats_qfull) {
1172 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
1173 fcport->stats_qfull = BFA_FALSE;
1174 }
1175
1176 fcport->stats_status = BFA_STATUS_ETIMER;
1177 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, __bfa_cb_fcport_stats_get,
1178 fcport);
1179}
1180
1181static void
1182bfa_fcport_send_stats_get(void *cbarg)
1183{
1184 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
1185 struct bfi_fcport_req_s *msg;
1186
1187 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
1188
1189 if (!msg) {
1190 fcport->stats_qfull = BFA_TRUE;
1191 bfa_reqq_winit(&fcport->stats_reqq_wait,
1192 bfa_fcport_send_stats_get, fcport);
1193 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
1194 &fcport->stats_reqq_wait);
1195 return;
1196 }
1197 fcport->stats_qfull = BFA_FALSE;
1198
1199 bfa_os_memset(msg, 0, sizeof(struct bfi_fcport_req_s));
1200 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
1201 bfa_lpuid(fcport->bfa));
1202 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
1203}
1204
1205static void
1206__bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
1207{
1208 struct bfa_fcport_s *fcport = cbarg;
1209
1210 if (complete) {
Jing Huangb85d0452010-07-08 19:48:49 -07001211 struct bfa_timeval_s tv;
1212
1213 /**
1214 * re-initialize time stamp for stats reset
1215 */
1216 bfa_os_gettimeofday(&tv);
1217 fcport->stats_reset_time = tv.tv_sec;
1218
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001219 fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
1220 } else {
1221 fcport->stats_busy = BFA_FALSE;
1222 fcport->stats_status = BFA_STATUS_OK;
1223 }
1224}
1225
1226static void
1227bfa_fcport_stats_clr_timeout(void *cbarg)
1228{
1229 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
1230
1231 bfa_trc(fcport->bfa, fcport->stats_qfull);
1232
1233 if (fcport->stats_qfull) {
1234 bfa_reqq_wcancel(&fcport->stats_reqq_wait);
1235 fcport->stats_qfull = BFA_FALSE;
1236 }
1237
1238 fcport->stats_status = BFA_STATUS_ETIMER;
1239 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
1240 __bfa_cb_fcport_stats_clr, fcport);
1241}
1242
1243static void
1244bfa_fcport_send_stats_clear(void *cbarg)
1245{
1246 struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
1247 struct bfi_fcport_req_s *msg;
1248
1249 msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
1250
1251 if (!msg) {
1252 fcport->stats_qfull = BFA_TRUE;
1253 bfa_reqq_winit(&fcport->stats_reqq_wait,
1254 bfa_fcport_send_stats_clear, fcport);
1255 bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
1256 &fcport->stats_reqq_wait);
1257 return;
1258 }
1259 fcport->stats_qfull = BFA_FALSE;
1260
1261 bfa_os_memset(msg, 0, sizeof(struct bfi_fcport_req_s));
1262 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
1263 bfa_lpuid(fcport->bfa));
1264 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
1265}
Jing Huang7725ccf2009-09-23 17:46:15 -07001266
1267/**
1268 * bfa_pport_public
1269 */
1270
1271/**
Jing Huanged969322010-07-08 19:45:56 -07001272 * Called to initialize port attributes
1273 */
1274void
1275bfa_fcport_init(struct bfa_s *bfa)
1276{
1277 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
1278
1279 /**
1280 * Initialize port attributes from IOC hardware data.
1281 */
1282 bfa_fcport_set_wwns(fcport);
1283 if (fcport->cfg.maxfrsize == 0)
1284 fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
1285 fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
1286 fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
1287
1288 bfa_assert(fcport->cfg.maxfrsize);
1289 bfa_assert(fcport->cfg.rx_bbcredit);
1290 bfa_assert(fcport->speed_sup);
1291}
1292
1293
1294/**
Jing Huang7725ccf2009-09-23 17:46:15 -07001295 * Firmware message handler.
1296 */
1297void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001298bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001299{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001300 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001301 union bfi_fcport_i2h_msg_u i2hmsg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001302
1303 i2hmsg.msg = msg;
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001304 fcport->event_arg.i2hmsg = i2hmsg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001305
1306 switch (msg->mhdr.msg_id) {
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001307 case BFI_FCPORT_I2H_ENABLE_RSP:
1308 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001309 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Jing Huang7725ccf2009-09-23 17:46:15 -07001310 break;
1311
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001312 case BFI_FCPORT_I2H_DISABLE_RSP:
Roel Kluin6de61f92010-08-10 18:01:23 -07001313 if (fcport->msgtag == i2hmsg.pdisable_rsp->msgtag)
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001314 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
Jing Huang7725ccf2009-09-23 17:46:15 -07001315 break;
1316
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001317 case BFI_FCPORT_I2H_EVENT:
Jing Huang7725ccf2009-09-23 17:46:15 -07001318 switch (i2hmsg.event->link_state.linkstate) {
1319 case BFA_PPORT_LINKUP:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001320 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
Jing Huang7725ccf2009-09-23 17:46:15 -07001321 break;
1322 case BFA_PPORT_LINKDOWN:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001323 bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
Jing Huang7725ccf2009-09-23 17:46:15 -07001324 break;
1325 case BFA_PPORT_TRUNK_LINKDOWN:
1326 /** todo: event notification */
1327 break;
1328 }
1329 break;
1330
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001331 case BFI_FCPORT_I2H_STATS_GET_RSP:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001332 /*
1333 * check for timer pop before processing the rsp
1334 */
1335 if (fcport->stats_busy == BFA_FALSE ||
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001336 fcport->stats_status == BFA_STATUS_ETIMER)
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001337 break;
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001338
1339 bfa_timer_stop(&fcport->timer);
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001340 fcport->stats_status = i2hmsg.pstatsget_rsp->status;
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001341 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001342 __bfa_cb_fcport_stats_get, fcport);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001343 break;
1344
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001345 case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001346 /*
1347 * check for timer pop before processing the rsp
1348 */
1349 if (fcport->stats_busy == BFA_FALSE ||
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001350 fcport->stats_status == BFA_STATUS_ETIMER)
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001351 break;
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001352
1353 bfa_timer_stop(&fcport->timer);
1354 fcport->stats_status = BFA_STATUS_OK;
1355 bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
1356 __bfa_cb_fcport_stats_clr, fcport);
Jing Huang7725ccf2009-09-23 17:46:15 -07001357 break;
1358
1359 default:
1360 bfa_assert(0);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001361 break;
Jing Huang7725ccf2009-09-23 17:46:15 -07001362 }
1363}
1364
Jing Huang7725ccf2009-09-23 17:46:15 -07001365/**
1366 * bfa_pport_api
1367 */
1368
1369/**
1370 * Registered callback for port events.
1371 */
1372void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001373bfa_fcport_event_register(struct bfa_s *bfa,
Jing Huang7725ccf2009-09-23 17:46:15 -07001374 void (*cbfn) (void *cbarg, bfa_pport_event_t event),
1375 void *cbarg)
1376{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001377 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001378
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001379 fcport->event_cbfn = cbfn;
1380 fcport->event_cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001381}
1382
1383bfa_status_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001384bfa_fcport_enable(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001385{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001386 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang3e98cc02010-07-08 19:52:46 -07001387 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1388 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1389
1390 /* if port is PBC disabled, return error */
1391 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
1392 bfa_trc(bfa, fcport->pwwn);
1393 return BFA_STATUS_PBC;
1394 }
Jing Huang7725ccf2009-09-23 17:46:15 -07001395
Jing Huangba834582010-07-08 20:00:24 -07001396 if (bfa_ioc_is_disabled(&bfa->ioc))
1397 return BFA_STATUS_IOC_DISABLED;
1398
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001399 if (fcport->diag_busy)
Jing Huangf8ceafd2009-09-25 12:29:54 -07001400 return BFA_STATUS_DIAG_BUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -07001401 else if (bfa_sm_cmp_state
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001402 (BFA_FCPORT_MOD(bfa), bfa_fcport_sm_disabling_qwait))
Jing Huangf8ceafd2009-09-25 12:29:54 -07001403 return BFA_STATUS_DEVBUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -07001404
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001405 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001406 return BFA_STATUS_OK;
1407}
1408
1409bfa_status_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001410bfa_fcport_disable(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001411{
Jing Huang3e98cc02010-07-08 19:52:46 -07001412 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
1413 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1414 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1415
1416 /* if port is PBC disabled, return error */
1417 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
1418 bfa_trc(bfa, fcport->pwwn);
1419 return BFA_STATUS_PBC;
1420 }
1421
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001422 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001423 return BFA_STATUS_OK;
1424}
1425
1426/**
1427 * Configure port speed.
1428 */
1429bfa_status_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001430bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_pport_speed speed)
Jing Huang7725ccf2009-09-23 17:46:15 -07001431{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001432 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001433
1434 bfa_trc(bfa, speed);
1435
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001436 if ((speed != BFA_PPORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
1437 bfa_trc(bfa, fcport->speed_sup);
Jing Huang7725ccf2009-09-23 17:46:15 -07001438 return BFA_STATUS_UNSUPP_SPEED;
1439 }
1440
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001441 fcport->cfg.speed = speed;
Jing Huang7725ccf2009-09-23 17:46:15 -07001442
Jing Huangf8ceafd2009-09-25 12:29:54 -07001443 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -07001444}
1445
1446/**
1447 * Get current speed.
1448 */
1449enum bfa_pport_speed
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001450bfa_fcport_get_speed(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001451{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001452 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001453
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001454 return fcport->speed;
Jing Huang7725ccf2009-09-23 17:46:15 -07001455}
1456
1457/**
1458 * Configure port topology.
1459 */
1460bfa_status_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001461bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_pport_topology topology)
Jing Huang7725ccf2009-09-23 17:46:15 -07001462{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001463 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001464
1465 bfa_trc(bfa, topology);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001466 bfa_trc(bfa, fcport->cfg.topology);
Jing Huang7725ccf2009-09-23 17:46:15 -07001467
1468 switch (topology) {
1469 case BFA_PPORT_TOPOLOGY_P2P:
1470 case BFA_PPORT_TOPOLOGY_LOOP:
1471 case BFA_PPORT_TOPOLOGY_AUTO:
1472 break;
1473
1474 default:
1475 return BFA_STATUS_EINVAL;
1476 }
1477
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001478 fcport->cfg.topology = topology;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001479 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -07001480}
1481
1482/**
1483 * Get current topology.
1484 */
1485enum bfa_pport_topology
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001486bfa_fcport_get_topology(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001487{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001488 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001489
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001490 return fcport->topology;
Jing Huang7725ccf2009-09-23 17:46:15 -07001491}
1492
1493bfa_status_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001494bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001495{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001496 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001497
1498 bfa_trc(bfa, alpa);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001499 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
1500 bfa_trc(bfa, fcport->cfg.hardalpa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001501
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001502 fcport->cfg.cfg_hardalpa = BFA_TRUE;
1503 fcport->cfg.hardalpa = alpa;
Jing Huang7725ccf2009-09-23 17:46:15 -07001504
Jing Huangf8ceafd2009-09-25 12:29:54 -07001505 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -07001506}
1507
1508bfa_status_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001509bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001510{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001511 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001512
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001513 bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
1514 bfa_trc(bfa, fcport->cfg.hardalpa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001515
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001516 fcport->cfg.cfg_hardalpa = BFA_FALSE;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001517 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -07001518}
1519
1520bfa_boolean_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001521bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001522{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001523 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001524
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001525 *alpa = fcport->cfg.hardalpa;
1526 return fcport->cfg.cfg_hardalpa;
Jing Huang7725ccf2009-09-23 17:46:15 -07001527}
1528
1529u8
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001530bfa_fcport_get_myalpa(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001531{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001532 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001533
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001534 return fcport->myalpa;
Jing Huang7725ccf2009-09-23 17:46:15 -07001535}
1536
1537bfa_status_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001538bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
Jing Huang7725ccf2009-09-23 17:46:15 -07001539{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001540 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001541
1542 bfa_trc(bfa, maxfrsize);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001543 bfa_trc(bfa, fcport->cfg.maxfrsize);
Jing Huang7725ccf2009-09-23 17:46:15 -07001544
1545 /*
1546 * with in range
1547 */
1548 if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
Jing Huangf8ceafd2009-09-25 12:29:54 -07001549 return BFA_STATUS_INVLD_DFSZ;
Jing Huang7725ccf2009-09-23 17:46:15 -07001550
1551 /*
1552 * power of 2, if not the max frame size of 2112
1553 */
1554 if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
Jing Huangf8ceafd2009-09-25 12:29:54 -07001555 return BFA_STATUS_INVLD_DFSZ;
Jing Huang7725ccf2009-09-23 17:46:15 -07001556
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001557 fcport->cfg.maxfrsize = maxfrsize;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001558 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -07001559}
1560
1561u16
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001562bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001563{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001564 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001565
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001566 return fcport->cfg.maxfrsize;
Jing Huang7725ccf2009-09-23 17:46:15 -07001567}
1568
1569u32
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001570bfa_fcport_mypid(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001571{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001572 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001573
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001574 return fcport->mypid;
Jing Huang7725ccf2009-09-23 17:46:15 -07001575}
1576
1577u8
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001578bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001579{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001580 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001581
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001582 return fcport->cfg.rx_bbcredit;
Jing Huang7725ccf2009-09-23 17:46:15 -07001583}
1584
1585void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001586bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
Jing Huang7725ccf2009-09-23 17:46:15 -07001587{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001588 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001589
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001590 fcport->cfg.tx_bbcredit = (u8) tx_bbcredit;
1591 bfa_fcport_send_txcredit(fcport);
Jing Huang7725ccf2009-09-23 17:46:15 -07001592}
1593
1594/**
1595 * Get port attributes.
1596 */
1597
1598wwn_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001599bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
Jing Huang7725ccf2009-09-23 17:46:15 -07001600{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001601 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001602 if (node)
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001603 return fcport->nwwn;
Jing Huang7725ccf2009-09-23 17:46:15 -07001604 else
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001605 return fcport->pwwn;
Jing Huang7725ccf2009-09-23 17:46:15 -07001606}
1607
1608void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001609bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_pport_attr_s *attr)
Jing Huang7725ccf2009-09-23 17:46:15 -07001610{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001611 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang3e98cc02010-07-08 19:52:46 -07001612 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1613 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
Jing Huang7725ccf2009-09-23 17:46:15 -07001614
1615 bfa_os_memset(attr, 0, sizeof(struct bfa_pport_attr_s));
1616
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001617 attr->nwwn = fcport->nwwn;
1618 attr->pwwn = fcport->pwwn;
Jing Huang7725ccf2009-09-23 17:46:15 -07001619
Jing Huang15b64a82010-07-08 19:48:12 -07001620 attr->factorypwwn = bfa_ioc_get_mfg_pwwn(&bfa->ioc);
1621 attr->factorynwwn = bfa_ioc_get_mfg_nwwn(&bfa->ioc);
1622
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001623 bfa_os_memcpy(&attr->pport_cfg, &fcport->cfg,
Jing Huang7725ccf2009-09-23 17:46:15 -07001624 sizeof(struct bfa_pport_cfg_s));
1625 /*
1626 * speed attributes
1627 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001628 attr->pport_cfg.speed = fcport->cfg.speed;
1629 attr->speed_supported = fcport->speed_sup;
1630 attr->speed = fcport->speed;
Jing Huang7725ccf2009-09-23 17:46:15 -07001631 attr->cos_supported = FC_CLASS_3;
1632
1633 /*
1634 * topology attributes
1635 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001636 attr->pport_cfg.topology = fcport->cfg.topology;
1637 attr->topology = fcport->topology;
Jing Huang7725ccf2009-09-23 17:46:15 -07001638
1639 /*
1640 * beacon attributes
1641 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001642 attr->beacon = fcport->beacon;
1643 attr->link_e2e_beacon = fcport->link_e2e_beacon;
1644 attr->plog_enabled = bfa_plog_get_setting(fcport->bfa->plog);
Jing Huang7725ccf2009-09-23 17:46:15 -07001645
1646 attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
1647 attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
Jing Huang3e98cc02010-07-08 19:52:46 -07001648
1649 /* PBC Disabled State */
1650 if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED)
1651 attr->port_state = BFA_PPORT_ST_PREBOOT_DISABLED;
1652 else {
1653 attr->port_state = bfa_sm_to_state(
1654 hal_pport_sm_table, fcport->sm);
1655 if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
1656 attr->port_state = BFA_PPORT_ST_IOCDIS;
1657 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
1658 attr->port_state = BFA_PPORT_ST_FWMISMATCH;
1659 }
Jing Huang7725ccf2009-09-23 17:46:15 -07001660}
1661
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001662#define BFA_FCPORT_STATS_TOV 1000
Jing Huang7725ccf2009-09-23 17:46:15 -07001663
1664/**
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001665 * Fetch port attributes (FCQoS or FCoE).
Jing Huang7725ccf2009-09-23 17:46:15 -07001666 */
1667bfa_status_t
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001668bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
Jing Huang7725ccf2009-09-23 17:46:15 -07001669 bfa_cb_pport_t cbfn, void *cbarg)
1670{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001671 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001672
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001673 if (fcport->stats_busy) {
1674 bfa_trc(bfa, fcport->stats_busy);
Jing Huangf8ceafd2009-09-25 12:29:54 -07001675 return BFA_STATUS_DEVBUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -07001676 }
1677
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001678 fcport->stats_busy = BFA_TRUE;
1679 fcport->stats_ret = stats;
1680 fcport->stats_cbfn = cbfn;
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001681 fcport->stats_cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001682
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001683 bfa_fcport_send_stats_get(fcport);
Jing Huang7725ccf2009-09-23 17:46:15 -07001684
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001685 bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_get_timeout,
1686 fcport, BFA_FCPORT_STATS_TOV);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001687 return BFA_STATUS_OK;
1688}
1689
1690/**
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001691 * Reset port statistics (FCQoS or FCoE).
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001692 */
1693bfa_status_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001694bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001695{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001696 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
1697
1698 if (fcport->stats_busy) {
1699 bfa_trc(bfa, fcport->stats_busy);
1700 return BFA_STATUS_DEVBUSY;
1701 }
1702
1703 fcport->stats_busy = BFA_TRUE;
1704 fcport->stats_cbfn = cbfn;
1705 fcport->stats_cbarg = cbarg;
1706
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001707 bfa_fcport_send_stats_clear(fcport);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001708
1709 bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_clr_timeout,
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001710 fcport, BFA_FCPORT_STATS_TOV);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001711 return BFA_STATUS_OK;
1712}
1713
Krishna Gudipatica8b4322010-03-05 19:38:07 -08001714/**
1715 * Fetch FCQoS port statistics
1716 */
1717bfa_status_t
1718bfa_fcport_get_qos_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
1719 bfa_cb_pport_t cbfn, void *cbarg)
1720{
1721 /* Meaningful only for FC mode */
1722 bfa_assert(bfa_ioc_get_fcmode(&bfa->ioc));
1723
1724 return bfa_fcport_get_stats(bfa, stats, cbfn, cbarg);
1725}
1726
1727/**
1728 * Reset FCoE port statistics
1729 */
1730bfa_status_t
1731bfa_fcport_clear_qos_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
1732{
1733 /* Meaningful only for FC mode */
1734 bfa_assert(bfa_ioc_get_fcmode(&bfa->ioc));
1735
1736 return bfa_fcport_clear_stats(bfa, cbfn, cbarg);
1737}
1738
1739/**
1740 * Fetch FCQoS port statistics
1741 */
1742bfa_status_t
1743bfa_fcport_get_fcoe_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
1744 bfa_cb_pport_t cbfn, void *cbarg)
1745{
1746 /* Meaningful only for FCoE mode */
1747 bfa_assert(!bfa_ioc_get_fcmode(&bfa->ioc));
1748
1749 return bfa_fcport_get_stats(bfa, stats, cbfn, cbarg);
1750}
1751
1752/**
1753 * Reset FCoE port statistics
1754 */
1755bfa_status_t
1756bfa_fcport_clear_fcoe_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
1757{
1758 /* Meaningful only for FCoE mode */
1759 bfa_assert(!bfa_ioc_get_fcmode(&bfa->ioc));
1760
1761 return bfa_fcport_clear_stats(bfa, cbfn, cbarg);
1762}
1763
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001764bfa_status_t
1765bfa_fcport_trunk_enable(struct bfa_s *bfa, u8 bitmap)
1766{
1767 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001768
1769 bfa_trc(bfa, bitmap);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001770 bfa_trc(bfa, fcport->cfg.trunked);
1771 bfa_trc(bfa, fcport->cfg.trunk_ports);
Jing Huang7725ccf2009-09-23 17:46:15 -07001772
1773 if (!bitmap || (bitmap & (bitmap - 1)))
1774 return BFA_STATUS_EINVAL;
1775
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001776 fcport->cfg.trunked = BFA_TRUE;
1777 fcport->cfg.trunk_ports = bitmap;
Jing Huang7725ccf2009-09-23 17:46:15 -07001778
1779 return BFA_STATUS_OK;
1780}
1781
1782void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001783bfa_fcport_qos_get_attr(struct bfa_s *bfa, struct bfa_qos_attr_s *qos_attr)
Jing Huang7725ccf2009-09-23 17:46:15 -07001784{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001785 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001786
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001787 qos_attr->state = bfa_os_ntohl(fcport->qos_attr.state);
1788 qos_attr->total_bb_cr = bfa_os_ntohl(fcport->qos_attr.total_bb_cr);
Jing Huang7725ccf2009-09-23 17:46:15 -07001789}
1790
1791void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001792bfa_fcport_qos_get_vc_attr(struct bfa_s *bfa,
Jing Huang7725ccf2009-09-23 17:46:15 -07001793 struct bfa_qos_vc_attr_s *qos_vc_attr)
1794{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001795 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
1796 struct bfa_qos_vc_attr_s *bfa_vc_attr = &fcport->qos_vc_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001797 u32 i = 0;
1798
1799 qos_vc_attr->total_vc_count = bfa_os_ntohs(bfa_vc_attr->total_vc_count);
1800 qos_vc_attr->shared_credit = bfa_os_ntohs(bfa_vc_attr->shared_credit);
1801 qos_vc_attr->elp_opmode_flags =
1802 bfa_os_ntohl(bfa_vc_attr->elp_opmode_flags);
1803
1804 /*
1805 * Individual VC info
1806 */
1807 while (i < qos_vc_attr->total_vc_count) {
1808 qos_vc_attr->vc_info[i].vc_credit =
1809 bfa_vc_attr->vc_info[i].vc_credit;
1810 qos_vc_attr->vc_info[i].borrow_credit =
1811 bfa_vc_attr->vc_info[i].borrow_credit;
1812 qos_vc_attr->vc_info[i].priority =
1813 bfa_vc_attr->vc_info[i].priority;
1814 ++i;
1815 }
1816}
1817
1818/**
Jing Huang7725ccf2009-09-23 17:46:15 -07001819 * Fetch port attributes.
1820 */
1821bfa_status_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001822bfa_fcport_trunk_disable(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001823{
Jing Huangf8ceafd2009-09-25 12:29:54 -07001824 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -07001825}
1826
1827bfa_boolean_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001828bfa_fcport_trunk_query(struct bfa_s *bfa, u32 *bitmap)
Jing Huang7725ccf2009-09-23 17:46:15 -07001829{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001830 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001831
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001832 *bitmap = fcport->cfg.trunk_ports;
1833 return fcport->cfg.trunked;
Jing Huang7725ccf2009-09-23 17:46:15 -07001834}
1835
1836bfa_boolean_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001837bfa_fcport_is_disabled(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001838{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001839 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001840
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001841 return bfa_sm_to_state(hal_pport_sm_table, fcport->sm) ==
Jing Huangf8ceafd2009-09-25 12:29:54 -07001842 BFA_PPORT_ST_DISABLED;
Jing Huang7725ccf2009-09-23 17:46:15 -07001843
1844}
1845
1846bfa_boolean_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001847bfa_fcport_is_ratelim(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001848{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001849 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001850
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001851 return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001852
1853}
1854
1855void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001856bfa_fcport_cfg_qos(struct bfa_s *bfa, bfa_boolean_t on_off)
Jing Huang7725ccf2009-09-23 17:46:15 -07001857{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001858 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08001859 enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001860
1861 bfa_trc(bfa, on_off);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001862 bfa_trc(bfa, fcport->cfg.qos_enabled);
Jing Huang7725ccf2009-09-23 17:46:15 -07001863
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08001864 bfa_trc(bfa, ioc_type);
1865
Jing Huang36d345a2010-07-08 19:57:33 -07001866 if (ioc_type == BFA_IOC_TYPE_FC) {
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08001867 fcport->cfg.qos_enabled = on_off;
Jing Huang36d345a2010-07-08 19:57:33 -07001868 /**
1869 * Notify fcpim of the change in QoS state
1870 */
1871 bfa_fcpim_update_ioredirect(bfa);
1872 }
Jing Huang7725ccf2009-09-23 17:46:15 -07001873}
1874
1875void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001876bfa_fcport_cfg_ratelim(struct bfa_s *bfa, bfa_boolean_t on_off)
Jing Huang7725ccf2009-09-23 17:46:15 -07001877{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001878 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001879
1880 bfa_trc(bfa, on_off);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001881 bfa_trc(bfa, fcport->cfg.ratelimit);
Jing Huang7725ccf2009-09-23 17:46:15 -07001882
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001883 fcport->cfg.ratelimit = on_off;
1884 if (fcport->cfg.trl_def_speed == BFA_PPORT_SPEED_UNKNOWN)
1885 fcport->cfg.trl_def_speed = BFA_PPORT_SPEED_1GBPS;
Jing Huang7725ccf2009-09-23 17:46:15 -07001886}
1887
1888/**
1889 * Configure default minimum ratelim speed
1890 */
1891bfa_status_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001892bfa_fcport_cfg_ratelim_speed(struct bfa_s *bfa, enum bfa_pport_speed speed)
Jing Huang7725ccf2009-09-23 17:46:15 -07001893{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001894 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001895
1896 bfa_trc(bfa, speed);
1897
1898 /*
1899 * Auto and speeds greater than the supported speed, are invalid
1900 */
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001901 if ((speed == BFA_PPORT_SPEED_AUTO) || (speed > fcport->speed_sup)) {
1902 bfa_trc(bfa, fcport->speed_sup);
Jing Huang7725ccf2009-09-23 17:46:15 -07001903 return BFA_STATUS_UNSUPP_SPEED;
1904 }
1905
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001906 fcport->cfg.trl_def_speed = speed;
Jing Huang7725ccf2009-09-23 17:46:15 -07001907
Jing Huangf8ceafd2009-09-25 12:29:54 -07001908 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -07001909}
1910
1911/**
1912 * Get default minimum ratelim speed
1913 */
1914enum bfa_pport_speed
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001915bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001916{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001917 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001918
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001919 bfa_trc(bfa, fcport->cfg.trl_def_speed);
1920 return fcport->cfg.trl_def_speed;
Jing Huang7725ccf2009-09-23 17:46:15 -07001921
1922}
1923
1924void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001925bfa_fcport_busy(struct bfa_s *bfa, bfa_boolean_t status)
Jing Huang7725ccf2009-09-23 17:46:15 -07001926{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001927 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001928
1929 bfa_trc(bfa, status);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001930 bfa_trc(bfa, fcport->diag_busy);
Jing Huang7725ccf2009-09-23 17:46:15 -07001931
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001932 fcport->diag_busy = status;
Jing Huang7725ccf2009-09-23 17:46:15 -07001933}
1934
1935void
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001936bfa_fcport_beacon(struct bfa_s *bfa, bfa_boolean_t beacon,
Jing Huang7725ccf2009-09-23 17:46:15 -07001937 bfa_boolean_t link_e2e_beacon)
1938{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001939 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001940
1941 bfa_trc(bfa, beacon);
1942 bfa_trc(bfa, link_e2e_beacon);
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001943 bfa_trc(bfa, fcport->beacon);
1944 bfa_trc(bfa, fcport->link_e2e_beacon);
Jing Huang7725ccf2009-09-23 17:46:15 -07001945
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001946 fcport->beacon = beacon;
1947 fcport->link_e2e_beacon = link_e2e_beacon;
Jing Huang7725ccf2009-09-23 17:46:15 -07001948}
1949
1950bfa_boolean_t
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001951bfa_fcport_is_linkup(struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001952{
Krishna Gudipati1c8a4c32010-03-05 19:37:37 -08001953 return bfa_sm_cmp_state(BFA_FCPORT_MOD(bfa), bfa_fcport_sm_linkup);
Jing Huang7725ccf2009-09-23 17:46:15 -07001954}
1955
Jing Huang36d345a2010-07-08 19:57:33 -07001956bfa_boolean_t
1957bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
1958{
1959 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001960
Jing Huang36d345a2010-07-08 19:57:33 -07001961 return fcport->cfg.qos_enabled;
1962}